class JAS::Ring

Represents a JAS polynomial ring: GenPolynomialRing.

Methods to create ideals and ideals with parametric coefficients.

Attributes

auto_inject[RW]

inject variables into environment

auto_lowervar[RW]

avoid capital letter variables

engine[R]

the Java factoy object, gcd engine, sqf engine, factorization engine

factor[R]

the Java factoy object, gcd engine, sqf engine, factorization engine

ring[R]

the Java factoy object, gcd engine, sqf engine, factorization engine

sqf[R]

the Java factoy object, gcd engine, sqf engine, factorization engine

Public Class Methods

getEngineFactor(r) click to toggle source

Get the polynomial factorization engine implementation.

r is the given polynomial ring.

     # File examples/jas.rb
1725 def Ring.getEngineFactor(r)
1726     if r.is_a? RingElem
1727         r = r.elem;
1728     end
1729     if not r.is_a? GenPolynomialRing
1730        return nil;
1731     end
1732     begin 
1733        i = FactorFactory.getImplementation(r.coFac);
1734     rescue => e
1735        i = nil
1736     end
1737     #puts "factor engine: #{i}";
1738     return i;
1739 end
getEngineGcd(r) click to toggle source

Get the polynomial gcd engine implementation.

r is the given polynomial ring.

     # File examples/jas.rb
1682 def Ring.getEngineGcd(r)
1683     if r.is_a? RingElem
1684         r = r.elem;
1685     end
1686     if not r.is_a? GenPolynomialRing
1687        return nil;
1688     end
1689     begin
1690        i = GCDFactory.getProxy(r.coFac);
1691        #i = GCDFactory.getImplementation(r.coFac);
1692     rescue => e
1693        i = nil
1694     end
1695     #puts "gcd engine: #{i}";
1696     return i;
1697 end
getEngineSqf(r) click to toggle source

Get the polynomial squarefree engine implementation.

r is the given polynomial ring.

     # File examples/jas.rb
1704 def Ring.getEngineSqf(r)
1705     if r.is_a? RingElem
1706         r = r.elem;
1707     end
1708     if not r.is_a? GenPolynomialRing
1709        return nil;
1710     end
1711     begin 
1712        i = SquarefreeFactory.getImplementation(r.coFac);
1713     rescue => e
1714        i = nil
1715     end
1716     #puts "sqf engine: #{i}";
1717     return i;
1718 end
new(ringstr="",ring=nil) click to toggle source

Ring constructor.

ringstr string representation to be parsed. ring JAS ring object.

     # File examples/jas.rb
1649 def initialize(ringstr="",ring=nil)
1650     if ring == nil
1651        sr = StringReader.new( ringstr );
1652        tok = RingFactoryTokenizer.new(sr);
1653        pfac = tok.nextPolynomialRing();
1654        #tok = GenPolynomialTokenizer.new(sr);
1655        #@pset = tok.nextPolynomialSet();
1656        @ring = pfac;
1657     else
1658        if ring.is_a? Ring
1659           @ring = ring.ring
1660        else 
1661           @ring = ring;
1662        end
1663     end
1664     # parameter ",fast=false" not possible w/o keyword params
1665     #if fast == true
1666     #   return
1667     #end
1668     @engine = Ring.getEngineGcd(@ring);
1669     @sqf = Ring.getEngineSqf(@ring);
1670     @factor = Ring.getEngineFactor(@ring);
1671     variable_generators()
1672     if self.class.auto_inject or self.class.superclass.auto_inject # sic!
1673        inject_variables();
1674     end
1675 end

Public Instance Methods

==(other) click to toggle source

Test if two rings are equal.

     # File examples/jas.rb
1791 def ==(other)
1792     if not other.is_a? Ring
1793        return false;
1794     end
1795     return @ring.equals(other.ring);
1796 end
CRT(polystr="", list=nil, rem=nil) click to toggle source

Chinese remainder theorem.

     # File examples/jas.rb
2091 def CRT(polystr="", list=nil, rem=nil)
2092     if list == nil
2093        sr = StringReader.new( polystr );
2094        tok = GenPolynomialTokenizer.new(@ring,sr);
2095        @list = tok.nextPolynomialList();
2096     else
2097        @list = rbarray2arraylist(list,nil,rec=2);
2098     end
2099     if rem == nil
2100        raise ArgumentError, "No remainders given."
2101     else
2102        @remlist = rbarray2arraylist(rem,nil,rec=1);
2103     end
2104     #puts "list = " + str(@list);
2105     #puts "remlist = " + str(@remlist);
2106     #puts
2107     h = PolyGBUtil.chineseRemainderTheorem(@list, @remlist);
2108     if h != nil
2109        h = RingElem.new(h);
2110     end
2111     return h;
2112 end
CRTinterpol(polystr="", list=nil, rem=nil) click to toggle source

Chinese remainder theorem, interpolation.

     # File examples/jas.rb
2117 def CRTinterpol(polystr="", list=nil, rem=nil)
2118     if list == nil
2119        sr = StringReader.new( polystr );
2120        tok = GenPolynomialTokenizer.new(@ring,sr);
2121        @list = tok.nextPolynomialList();
2122     else
2123        @list = rbarray2arraylist(list,nil,rec=2);
2124     end
2125     if rem == nil
2126        raise ArgumentError, "No remeinders given."
2127     else
2128        @remlist = rbarray2arraylist(rem,nil,rec=1);
2129     end
2130     #puts "ring = " + str(@ring.toScript());
2131     #puts "list = " + str(@list);
2132     #puts "remlist = " + str(@remlist);
2133     #puts
2134     h = PolyGBUtil.CRTInterpolation(@ring, @list, @remlist);
2135     if h != nil
2136        h = RingElem.new(h);
2137     end
2138     return h;
2139 end
algebraicRoots(a,eps=nil) click to toggle source

Compute algebraic real and complex roots of univariate polynomial.

     # File examples/jas.rb
2001 def algebraicRoots(a,eps=nil)
2002     if not a.is_a? RingElem
2003         a = RingElem.new(a);
2004     end
2005     return a.algebraicRoots(eps);
2006 end
complexRoots(a,eps=nil) click to toggle source

Compute complex roots of univariate polynomial.

     # File examples/jas.rb
1991 def complexRoots(a,eps=nil)
1992     if not a.is_a? RingElem
1993         a = RingElem.new(a);
1994     end
1995     return a.complexRoots(eps);
1996 end
decimalRoots(a,eps=nil) click to toggle source

Compute deximal approximation of algebraic real and complex roots.

     # File examples/jas.rb
2021 def decimalRoots(a,eps=nil)
2022     if not a.is_a? RingElem
2023         a = RingElem.new(a);
2024     end
2025     return a.decimalRoots(eps);
2026 end
element(poly) click to toggle source

Create an element from a string or an object.

     # File examples/jas.rb
1857 def element(poly)
1858     if not poly.is_a? String 
1859        begin
1860           if @ring == poly.ring 
1861              return RingElem.new(poly);
1862           end
1863        rescue => e
1864           # pass
1865        end
1866        poly = str(poly);
1867     end
1868     i = SimIdeal.new( self, "( " + poly + " )" );
1869     list = i.pset.list;
1870     if list.size > 0
1871        return RingElem.new( list[0] );
1872     end
1873 end
factors(a) click to toggle source

Compute irreducible factorization for modular, integer, rational number and algebriac number coefficients.

     # File examples/jas.rb
1928 def factors(a)
1929     if a.is_a? RingElem
1930         a = a.elem;
1931     else
1932         a = element( a );
1933         a = a.elem;
1934     end
1935     begin
1936         cf = @ring.coFac;
1937         if cf.is_a? GenPolynomialRing
1938             e = @factor.recursiveFactors( a );
1939         else
1940             e = @factor.factors( a );
1941         end
1942         ll = {};
1943         for a in e.keySet()
1944             i = e.get(a);
1945             ll[ RingElem.new( a ) ] = i;
1946         end
1947         return ll;
1948     rescue => e
1949         puts "error " + str(e)
1950         return nil
1951     end
1952 end
factorsAbsolute(a) click to toggle source

Compute absolute irreducible factorization for (modular,) rational number coefficients.

     # File examples/jas.rb
1958     def factorsAbsolute(a)
1959         if a.is_a? RingElem
1960             a = a.elem;
1961         else
1962             a = element( a );
1963             a = a.elem;
1964         end
1965         begin
1966             ll = @factor.factorsAbsolute( a );
1967 ##             ll = {};
1968 ##             for a in e.keySet()
1969 ##                 i = e.get(a);
1970 ##                 ll[ RingElem.new( a ) ] = i;
1971             return ll;
1972         rescue => e
1973             puts "error in factorsAbsolute " + str(e)
1974             return nil
1975         end
1976     end
gcd(a,b) click to toggle source

Compute the greatest common divisor of a and b.

     # File examples/jas.rb
1878 def gcd(a,b)
1879     if a.is_a? RingElem
1880         a = a.elem;
1881     else
1882         a = element( a );
1883         a = a.elem;
1884     end
1885     if b.is_a? RingElem
1886         b = b.elem;
1887     else
1888         b = element( b );
1889         b = b.elem;
1890     end
1891     cf = @ring.coFac;
1892     if cf.is_a? GenPolynomialRing
1893         e = @engine.recursiveGcd( a, b );
1894     else
1895         e = @engine.gcd( a, b );
1896     end
1897     return RingElem.new( e );
1898 end
gens() click to toggle source

Get list of generators of the polynomial ring.

     # File examples/jas.rb
1823 def gens()
1824     ll = @ring.generators();
1825     n = ll.map{ |e| RingElem.new(e) };
1826     return n;
1827 end
ideal(ringstr="",list=nil) click to toggle source

Create an ideal.

     # File examples/jas.rb
1801 def ideal(ringstr="",list=nil)
1802     return JAS::SimIdeal.new(self,ringstr,list);
1803 end
inject_variables() click to toggle source

Inject variables for generators in top level environment.

     # File examples/jas.rb
1769 def inject_variables() 
1770     begin 
1771        require "irb/frame" # must be placed here
1772        bin = IRB::Frame.bottom(0);
1773        env = eval "self", bin;
1774        #puts "env = " + str(env)
1775        inject_gens(env)
1776     rescue => e
1777        puts "error: 'irb/frame' not found, e = " + str(e);
1778     end
1779 end
integrate(a) click to toggle source

Integrate rational function or power series.

     # File examples/jas.rb
2052 def integrate(a)
2053     if not a.is_a? RingElem
2054         a = RingElem.new(a);
2055     end
2056     return a.integrate();
2057 end
one() click to toggle source

Get the one of the polynomial ring.

     # File examples/jas.rb
1832 def one()
1833     return RingElem.new( @ring.getONE() );
1834 end
paramideal(ringstr="",list=nil,gbsys=nil) click to toggle source

Create an ideal in a polynomial ring with parameter coefficients.

     # File examples/jas.rb
1808 def paramideal(ringstr="",list=nil,gbsys=nil)
1809     return ParamIdeal.new(self,ringstr,list,gbsys);
1810 end
powerseriesRing() click to toggle source

Get a power series ring from this ring.

     # File examples/jas.rb
1815 def powerseriesRing()
1816     pr = MultiVarPowerSeriesRing.new(@ring);
1817     return MultiSeriesRing.new("",nil,pr);
1818 end
random(k=5,l=7,d=3,q=0.3) click to toggle source

Get a random polynomial.

     # File examples/jas.rb
1846 def random(k=5,l=7,d=3,q=0.3)
1847     r = @ring.random(k,l,d,q);
1848     if @ring.coFac.isField()
1849         r = r.monic();
1850     end
1851     return RingElem.new( r );
1852 end
realRoots(a,eps=nil) click to toggle source

Compute real roots of univariate polynomial.

     # File examples/jas.rb
1981 def realRoots(a,eps=nil)
1982     if not a.is_a? RingElem
1983         a = RingElem.new(a);
1984     end
1985     return a.realRoots(eps);
1986 end
rootReduce(a, b) click to toggle source

Root reduce of real and complex algebraic numbers. Compute an extension field with a primitive element.

     # File examples/jas.rb
2042 def rootReduce(a, b)
2043     if not a.is_a? RingElem
2044         a = RingElem.new(a);
2045     end
2046     return a.rootReduce(b);
2047 end
rootRefine(a,eps=nil) click to toggle source

Compute algebraic real and complex roots refinement.

     # File examples/jas.rb
2011 def rootRefine(a,eps=nil)
2012     if not a.is_a? RingElem
2013         a = RingElem.new(a);
2014     end
2015     return a.rootRefine(eps);
2016 end
rootsOfUnity(a) click to toggle source

Roots of unity of real and complex algebraic numbers.

     # File examples/jas.rb
2031 def rootsOfUnity(a)
2032     if not a.is_a? RingElem
2033         a = RingElem.new(a);
2034     end
2035     return a.rootsOfUnity();
2036 end
squarefreeFactors(a) click to toggle source

Compute squarefree factors of polynomial.

     # File examples/jas.rb
1903 def squarefreeFactors(a)
1904     if a.is_a? RingElem
1905         a = a.elem;
1906     else
1907         a = element( a );
1908         a = a.elem;
1909     end
1910     cf = @ring.coFac;
1911     if cf.is_a? GenPolynomialRing
1912         e = @sqf.recursiveSquarefreeFactors( a );
1913     else
1914         e = @sqf.squarefreeFactors( a );
1915     end
1916     ll = {};
1917     for a in e.keySet()
1918         i = e.get(a);
1919         ll[ RingElem.new( a ) ] = i;
1920     end
1921     return ll;
1922 end
subring(polystr="", list=nil) click to toggle source

Sub ring generators as Groebner base.

     # File examples/jas.rb
2062 def subring(polystr="", list=nil)
2063     if list == nil
2064        sr = StringReader.new( polystr );
2065        tok = GenPolynomialTokenizer.new(@ring,sr);
2066        @list = tok.nextPolynomialList();
2067     else
2068        @list = rbarray2arraylist(list,rec=1);
2069     end
2070     sr = PolyGBUtil.subRing(@list);
2071     srr = sr.map { |a| RingElem.new(a) }; 
2072     return srr;
2073 end
subringmember(list, a) click to toggle source

Sub ring member test. list is a Groebner base. Test if a in K.

     # File examples/jas.rb
2079 def subringmember(list, a)
2080     sr = list.map { |p| p.elem }; 
2081     if a.is_a? RingElem
2082         a = a.elem;
2083     end
2084     b = PolyGBUtil.subRingMember(sr, a);
2085     return b;
2086 end
to_s() click to toggle source

Create a string representation.

     # File examples/jas.rb
1784 def to_s()
1785     return @ring.toScript();
1786 end
variable_generators() click to toggle source

Define instance variables for generators.

     # File examples/jas.rb
1744 def variable_generators() 
1745    Ring.instance_eval( "attr_accessor :generators;" )
1746    @generators = {};
1747    for i in self.gens()
1748       begin 
1749          ivs = nameFromValue(i);
1750          if ivs != nil
1751             #puts "string: #{ivs} = " + ivs.class.to_s;
1752             if @generators[ ivs ] != nil
1753                puts "redefining local variable #{ivs}";
1754             end
1755             @generators[ ivs ] = i;
1756             self.instance_eval( "def #{ivs}; @generators[ '#{ivs}' ]; end" )
1757          end
1758       rescue => e
1759          puts "ring error: #{ivs} = " + i.to_s + ", e = " + str(e);
1760          #pass
1761       end
1762    end
1763 #puts "locally defined generators: " + @generators.keys().join(", ");
1764 end
zero() click to toggle source

Get the zero of the polynomial ring.

     # File examples/jas.rb
1839 def zero()
1840     return RingElem.new( @ring.getZERO() );
1841 end