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
1950 def Ring.getEngineFactor(r)
1951     if r.is_a? RingElem
1952         r = r.elem;
1953     end
1954     if not r.is_a? GenPolynomialRing
1955        return nil;
1956     end
1957     begin 
1958        i = FactorFactory.getImplementation(r.coFac);
1959     rescue => e
1960        i = nil
1961     end
1962     #puts "factor engine: #{i}";
1963     return i;
1964 end
getEngineGcd(r) click to toggle source

Get the polynomial gcd engine implementation.

r is the given polynomial ring.

     # File examples/jas.rb
1907 def Ring.getEngineGcd(r)
1908     if r.is_a? RingElem
1909         r = r.elem;
1910     end
1911     if not r.is_a? GenPolynomialRing
1912        return nil;
1913     end
1914     begin
1915        i = GCDFactory.getProxy(r.coFac);
1916        #i = GCDFactory.getImplementation(r.coFac);
1917     rescue => e
1918        i = nil
1919     end
1920     #puts "gcd engine: #{i}";
1921     return i;
1922 end
getEngineSqf(r) click to toggle source

Get the polynomial squarefree engine implementation.

r is the given polynomial ring.

     # File examples/jas.rb
1929 def Ring.getEngineSqf(r)
1930     if r.is_a? RingElem
1931         r = r.elem;
1932     end
1933     if not r.is_a? GenPolynomialRing
1934        return nil;
1935     end
1936     begin 
1937        i = SquarefreeFactory.getImplementation(r.coFac);
1938     rescue => e
1939        i = nil
1940     end
1941     #puts "sqf engine: #{i}";
1942     return i;
1943 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
1872 def initialize(ringstr="",ring=nil)
1873     if ring == nil
1874        sr = StringReader.new( ringstr );
1875        tok = RingFactoryTokenizer.new(sr);
1876        pfac = tok.nextPolynomialRing();
1877        #tok = GenPolynomialTokenizer.new(sr);
1878        #@pset = tok.nextPolynomialSet();
1879        @ring = pfac;
1880     else
1881        if ring.is_a? Ring
1882           @ring = ring.ring
1883        else 
1884           @ring = ring;
1885        end
1886     end
1887     # parameter ",fast=false" not possible w/o keyword params
1888     #if fast == true
1889     #   return
1890     #end
1891     @engine = Ring.getEngineGcd(@ring);
1892     @sqf = Ring.getEngineSqf(@ring);
1893     @factor = Ring.getEngineFactor(@ring);
1894     variable_generators()
1895     #puts "self.class.auto_inject = " + self.class.auto_inject.to_s
1896     #puts "self.class.superclass.auto_inject = " + self.class.superclass.auto_inject.to_s
1897     if self.class.auto_inject or self.class.superclass.auto_inject # sic!
1898        inject_variables();
1899     end
1900 end

Public Instance Methods

==(other) click to toggle source

Test if two rings are equal.

     # File examples/jas.rb
2017 def ==(other)
2018     if not other.is_a? Ring
2019        return false;
2020     end
2021     return @ring.equals(other.ring);
2022 end
CRT(polystr="", list=nil, rem=nil) click to toggle source

Chinese remainder theorem.

     # File examples/jas.rb
2317 def CRT(polystr="", list=nil, rem=nil)
2318     if list == nil
2319        sr = StringReader.new( polystr );
2320        tok = GenPolynomialTokenizer.new(@ring,sr);
2321        @list = tok.nextPolynomialList();
2322     else
2323        @list = rbarray2arraylist(list,nil,rec=2);
2324     end
2325     if rem == nil
2326        raise ArgumentError, "No remainders given."
2327     else
2328        @remlist = rbarray2arraylist(rem,nil,rec=1);
2329     end
2330     #puts "list = " + str(@list);
2331     #puts "remlist = " + str(@remlist);
2332     #puts
2333     h = PolyGBUtil.chineseRemainderTheorem(@list, @remlist);
2334     if h != nil
2335        h = RingElem.new(h);
2336     end
2337     return h;
2338 end
CRTinterpol(polystr="", list=nil, rem=nil) click to toggle source

Chinese remainder theorem, interpolation.

     # File examples/jas.rb
2343 def CRTinterpol(polystr="", list=nil, rem=nil)
2344     if list == nil
2345        sr = StringReader.new( polystr );
2346        tok = GenPolynomialTokenizer.new(@ring,sr);
2347        @list = tok.nextPolynomialList();
2348     else
2349        @list = rbarray2arraylist(list,nil,rec=2);
2350     end
2351     if rem == nil
2352        raise ArgumentError, "No remeinders given."
2353     else
2354        @remlist = rbarray2arraylist(rem,nil,rec=1);
2355     end
2356     #puts "ring = " + str(@ring.toScript());
2357     #puts "list = " + str(@list);
2358     #puts "remlist = " + str(@remlist);
2359     #puts
2360     h = PolyGBUtil.CRTInterpolation(@ring, @list, @remlist);
2361     if h != nil
2362        h = RingElem.new(h);
2363     end
2364     return h;
2365 end
algebraicRoots(a,eps=nil) click to toggle source

Compute algebraic real and complex roots of univariate polynomial.

     # File examples/jas.rb
2227 def algebraicRoots(a,eps=nil)
2228     if not a.is_a? RingElem
2229         a = RingElem.new(a);
2230     end
2231     return a.algebraicRoots(eps);
2232 end
complexRoots(a,eps=nil) click to toggle source

Compute complex roots of univariate polynomial.

     # File examples/jas.rb
2217 def complexRoots(a,eps=nil)
2218     if not a.is_a? RingElem
2219         a = RingElem.new(a);
2220     end
2221     return a.complexRoots(eps);
2222 end
decimalRoots(a,eps=nil) click to toggle source

Compute deximal approximation of algebraic real and complex roots.

     # File examples/jas.rb
2247 def decimalRoots(a,eps=nil)
2248     if not a.is_a? RingElem
2249         a = RingElem.new(a);
2250     end
2251     return a.decimalRoots(eps);
2252 end
element(poly) click to toggle source

Create an element from a string or an object.

     # File examples/jas.rb
2083 def element(poly)
2084     if not poly.is_a? String 
2085        begin
2086           if @ring == poly.ring 
2087              return RingElem.new(poly);
2088           end
2089        rescue => e
2090           # pass
2091        end
2092        poly = str(poly);
2093     end
2094     i = SimIdeal.new( self, "( " + poly + " )" );
2095     list = i.pset.list;
2096     if list.size > 0
2097        return RingElem.new( list[0] );
2098     end
2099 end
factors(a) click to toggle source

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

     # File examples/jas.rb
2154 def factors(a)
2155     if a.is_a? RingElem
2156         a = a.elem;
2157     else
2158         a = element( a );
2159         a = a.elem;
2160     end
2161     begin
2162         cf = @ring.coFac;
2163         if cf.is_a? GenPolynomialRing
2164             e = @factor.recursiveFactors( a );
2165         else
2166             e = @factor.factors( a );
2167         end
2168         ll = {};
2169         for a in e.keySet()
2170             i = e.get(a);
2171             ll[ RingElem.new( a ) ] = i;
2172         end
2173         return ll;
2174     rescue => e
2175         puts "error " + str(e)
2176         return nil
2177     end
2178 end
factorsAbsolute(a) click to toggle source

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

     # File examples/jas.rb
2184     def factorsAbsolute(a)
2185         if a.is_a? RingElem
2186             a = a.elem;
2187         else
2188             a = element( a );
2189             a = a.elem;
2190         end
2191         begin
2192             ll = @factor.factorsAbsolute( a );
2193 ##             ll = {};
2194 ##             for a in e.keySet()
2195 ##                 i = e.get(a);
2196 ##                 ll[ RingElem.new( a ) ] = i;
2197             return ll;
2198         rescue => e
2199             puts "error in factorsAbsolute " + str(e)
2200             return nil
2201         end
2202     end
gcd(a,b) click to toggle source

Compute the greatest common divisor of a and b.

     # File examples/jas.rb
2104 def gcd(a,b)
2105     if a.is_a? RingElem
2106         a = a.elem;
2107     else
2108         a = element( a );
2109         a = a.elem;
2110     end
2111     if b.is_a? RingElem
2112         b = b.elem;
2113     else
2114         b = element( b );
2115         b = b.elem;
2116     end
2117     cf = @ring.coFac;
2118     if cf.is_a? GenPolynomialRing
2119         e = @engine.recursiveGcd( a, b );
2120     else
2121         e = @engine.gcd( a, b );
2122     end
2123     return RingElem.new( e );
2124 end
gens() click to toggle source

Get list of generators of the polynomial ring.

     # File examples/jas.rb
2049 def gens()
2050     ll = @ring.generators();
2051     n = ll.map{ |e| RingElem.new(e) };
2052     return n;
2053 end
ideal(ringstr="",list=nil) click to toggle source

Create an ideal.

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

Inject variables for generators in top level environment.

     # File examples/jas.rb
1994 def inject_variables() 
1995     begin 
1996        require "irb/frame" # must be placed here
1997        bin = IRB::Frame.bottom(0);
1998        env = eval "self", bin;
1999        #puts "inject_gens: env1 = " + str(env)
2000        inject_gens(env)
2001        #puts "inject_gens: env2 = " + str(env)
2002     rescue => e
2003        puts "error: 'irb/frame' not found, e = " + str(e);
2004     end
2005 end
integrate(a) click to toggle source

Integrate rational function or power series.

     # File examples/jas.rb
2278 def integrate(a)
2279     if not a.is_a? RingElem
2280         a = RingElem.new(a);
2281     end
2282     return a.integrate();
2283 end
one() click to toggle source

Get the one of the polynomial ring.

     # File examples/jas.rb
2058 def one()
2059     return RingElem.new( @ring.getONE() );
2060 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
2034 def paramideal(ringstr="",list=nil,gbsys=nil)
2035     return ParamIdeal.new(self,ringstr,list,gbsys);
2036 end
powerseriesRing() click to toggle source

Get a power series ring from this ring.

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

Get a random polynomial.

     # File examples/jas.rb
2072 def random(k=5,l=7,d=3,q=0.3)
2073     r = @ring.random(k,l,d,q);
2074     if @ring.coFac.isField()
2075         r = r.monic();
2076     end
2077     return RingElem.new( r );
2078 end
realRoots(a,eps=nil) click to toggle source

Compute real roots of univariate polynomial.

     # File examples/jas.rb
2207 def realRoots(a,eps=nil)
2208     if not a.is_a? RingElem
2209         a = RingElem.new(a);
2210     end
2211     return a.realRoots(eps);
2212 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
2268 def rootReduce(a, b)
2269     if not a.is_a? RingElem
2270         a = RingElem.new(a);
2271     end
2272     return a.rootReduce(b);
2273 end
rootRefine(a,eps=nil) click to toggle source

Compute algebraic real and complex roots refinement.

     # File examples/jas.rb
2237 def rootRefine(a,eps=nil)
2238     if not a.is_a? RingElem
2239         a = RingElem.new(a);
2240     end
2241     return a.rootRefine(eps);
2242 end
rootsOfUnity(a) click to toggle source

Roots of unity of real and complex algebraic numbers.

     # File examples/jas.rb
2257 def rootsOfUnity(a)
2258     if not a.is_a? RingElem
2259         a = RingElem.new(a);
2260     end
2261     return a.rootsOfUnity();
2262 end
squarefreeFactors(a) click to toggle source

Compute squarefree factors of polynomial.

     # File examples/jas.rb
2129 def squarefreeFactors(a)
2130     if a.is_a? RingElem
2131         a = a.elem;
2132     else
2133         a = element( a );
2134         a = a.elem;
2135     end
2136     cf = @ring.coFac;
2137     if cf.is_a? GenPolynomialRing
2138         e = @sqf.recursiveSquarefreeFactors( a );
2139     else
2140         e = @sqf.squarefreeFactors( a );
2141     end
2142     ll = {};
2143     for a in e.keySet()
2144         i = e.get(a);
2145         ll[ RingElem.new( a ) ] = i;
2146     end
2147     return ll;
2148 end
subring(polystr="", list=nil) click to toggle source

Sub ring generators as Groebner base.

     # File examples/jas.rb
2288 def subring(polystr="", list=nil)
2289     if list == nil
2290        sr = StringReader.new( polystr );
2291        tok = GenPolynomialTokenizer.new(@ring,sr);
2292        @list = tok.nextPolynomialList();
2293     else
2294        @list = rbarray2arraylist(list,rec=1);
2295     end
2296     sr = PolyGBUtil.subRing(@list);
2297     srr = sr.map { |a| RingElem.new(a) }; 
2298     return srr;
2299 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
2305 def subringmember(list, a)
2306     sr = list.map { |p| p.elem }; 
2307     if a.is_a? RingElem
2308         a = a.elem;
2309     end
2310     b = PolyGBUtil.subRingMember(sr, a);
2311     return b;
2312 end
to_s() click to toggle source

Create a string representation.

     # File examples/jas.rb
2010 def to_s()
2011     return @ring.toScript();
2012 end
variable_generators() click to toggle source

Define instance variables for generators.

     # File examples/jas.rb
1969 def variable_generators() 
1970    Ring.instance_eval( "attr_accessor :generators;" )
1971    @generators = {};
1972    for i in self.gens()
1973       begin 
1974          ivs = nameFromValue(i);
1975          if ivs != nil
1976             #puts "string: #{ivs} = " + ivs.class.to_s;
1977             if @generators[ ivs ] != nil
1978                puts "redefining local variable #{ivs}";
1979             end
1980             @generators[ ivs ] = i;
1981             self.instance_eval( "def #{ivs}; @generators[ '#{ivs}' ]; end" )
1982          end
1983       rescue => e
1984          puts "ring error: #{ivs} = " + i.to_s + ", e = " + str(e);
1985          #pass
1986       end
1987    end
1988 #puts "locally defined generators: " + @generators.keys().join(", ");
1989 end
zero() click to toggle source

Get the zero of the polynomial ring.

     # File examples/jas.rb
2065 def zero()
2066     return RingElem.new( @ring.getZERO() );
2067 end