class JAS::Ring
Represents a JAS polynomial ring: GenPolynomialRing.
Methods to create ideals and ideals with parametric coefficients.
Attributes
inject variables into environment
avoid capital letter variables
the Java factoy object, gcd engine, sqf engine, factorization engine
the Java factoy object, gcd engine, sqf engine, factorization engine
the Java factoy object, gcd engine, sqf engine, factorization engine
the Java factoy object, gcd engine, sqf engine, factorization engine
Public Class Methods
Get the polynomial factorization engine implementation.
r is the given polynomial ring.
# File examples/jas.rb, line 1707 def Ring.getEngineFactor(r) if r.is_a? RingElem r = r.elem; end if not r.is_a? GenPolynomialRing return nil; end begin i = FactorFactory.getImplementation(r.coFac); rescue => e i = nil end #puts "factor engine: #{i}"; return i; end
Get the polynomial gcd engine implementation.
r is the given polynomial ring.
# File examples/jas.rb, line 1665 def Ring.getEngineGcd(r) if r.is_a? RingElem r = r.elem; end if not r.is_a? GenPolynomialRing return nil; end begin i = GCDFactory.getProxy(r.coFac); rescue => e i = nil end #puts "gcd engine: #{i}"; return i; end
Get the polynomial squarefree engine implementation.
r is the given polynomial ring.
# File examples/jas.rb, line 1686 def Ring.getEngineSqf(r) if r.is_a? RingElem r = r.elem; end if not r.is_a? GenPolynomialRing return nil; end begin i = SquarefreeFactory.getImplementation(r.coFac); rescue => e i = nil end #puts "sqf engine: #{i}"; return i; end
Ring constructor.
ringstr string representation to be parsed. ring JAS ring object.
# File examples/jas.rb, line 1632 def initialize(ringstr="",ring=nil) if ring == nil sr = StringReader.new( ringstr ); tok = RingFactoryTokenizer.new(sr); pfac = tok.nextPolynomialRing(); #tok = GenPolynomialTokenizer.new(sr); #@pset = tok.nextPolynomialSet(); @ring = pfac; else if ring.is_a? Ring @ring = ring.ring else @ring = ring; end end # parameter ",fast=false" not possible w/o keyword params #if fast == true # return #end @engine = Ring.getEngineGcd(@ring); @sqf = Ring.getEngineSqf(@ring); @factor = Ring.getEngineFactor(@ring); variable_generators() if self.class.auto_inject or self.class.superclass.auto_inject # sic! inject_variables(); end end
Public Instance Methods
Test if two rings are equal.
# File examples/jas.rb, line 1773 def ==(other) if not other.is_a? Ring return false; end return @ring.equals(other.ring); end
Compute algebraic real and complex roots of univariate polynomial.
# File examples/jas.rb, line 1977 def algebraicRoots(a,eps=nil) if not a.is_a? RingElem a = RingElem.new(a); end return a.algebraicRoots(eps); end
Compute complex roots of univariate polynomial.
# File examples/jas.rb, line 1967 def complexRoots(a,eps=nil) if not a.is_a? RingElem a = RingElem.new(a); end return a.complexRoots(eps); end
Compute deximal approximation of algebraic real and complex roots.
# File examples/jas.rb, line 1997 def decimalRoots(a,eps=nil) if not a.is_a? RingElem a = RingElem.new(a); end return a.decimalRoots(eps); end
Create an element from a string or an object.
# File examples/jas.rb, line 1839 def element(poly) if not poly.is_a? String begin if @ring == poly.ring return RingElem.new(poly); end rescue => e # pass end poly = str(poly); end i = SimIdeal.new( self, "( " + poly + " )" ); list = i.pset.list; if list.size > 0 return RingElem.new( list[0] ); end end
Compute irreducible factorization for modular, integer, rational number and algebriac number coefficients.
# File examples/jas.rb, line 1904 def factors(a) if a.is_a? RingElem a = a.elem; else a = element( a ); a = a.elem; end begin cf = @ring.coFac; if cf.is_a? GenPolynomialRing e = @factor.recursiveFactors( a ); else e = @factor.factors( a ); end ll = {}; for a in e.keySet() i = e.get(a); ll[ RingElem.new( a ) ] = i; end return ll; rescue => e puts "error " + str(e) return nil end end
Compute absolute irreducible factorization for (modular,) rational number coefficients.
# File examples/jas.rb, line 1934 def factorsAbsolute(a) if a.is_a? RingElem a = a.elem; else a = element( a ); a = a.elem; end begin ll = @factor.factorsAbsolute( a ); ## ll = {}; ## for a in e.keySet() ## i = e.get(a); ## ll[ RingElem.new( a ) ] = i; return ll; rescue => e puts "error in factorsAbsolute " + str(e) return nil end end
Compute the greatest common divisor of a and b.
# File examples/jas.rb, line 1860 def gcd(a,b) if a.is_a? RingElem a = a.elem; else a = element( a ); a = a.elem; end if b.is_a? RingElem b = b.elem; else b = element( b ); b = b.elem; end return RingElem.new( @engine.gcd(a,b) ); end
Get list of generators of the polynomial ring.
# File examples/jas.rb, line 1805 def gens() ll = @ring.generators(); n = ll.map{ |e| RingElem.new(e) }; return n; end
Create an ideal.
# File examples/jas.rb, line 1783 def ideal(ringstr="",list=nil) return JAS::SimIdeal.new(self,ringstr,list); end
Inject variables for generators in top level environment.
# File examples/jas.rb, line 1751 def inject_variables() begin require "irb/frame" # must be placed here bin = IRB::Frame.bottom(0); env = eval "self", bin; #puts "env = " + str(env) inject_gens(env) rescue => e puts "error: 'irb/frame' not found, e = " + str(e); end end
Integrate rational function or power series.
# File examples/jas.rb, line 2028 def integrate(a) if not a.is_a? RingElem a = RingElem.new(a); end return a.integrate(); end
Get the one of the polynomial ring.
# File examples/jas.rb, line 1814 def one() return RingElem.new( @ring.getONE() ); end
Create an ideal in a polynomial ring with parameter coefficients.
# File examples/jas.rb, line 1790 def paramideal(ringstr="",list=nil,gbsys=nil) return ParamIdeal.new(self,ringstr,list,gbsys); end
Get a power series ring from this ring.
# File examples/jas.rb, line 1797 def powerseriesRing() pr = MultiVarPowerSeriesRing.new(@ring); return MultiSeriesRing.new("",nil,pr); end
Get a random polynomial.
# File examples/jas.rb, line 1828 def random(k=5,l=7,d=3,q=0.3) r = @ring.random(k,l,d,q); if @ring.coFac.isField() r = r.monic(); end return RingElem.new( r ); end
Compute real roots of univariate polynomial.
# File examples/jas.rb, line 1957 def realRoots(a,eps=nil) if not a.is_a? RingElem a = RingElem.new(a); end return a.realRoots(eps); end
Root reduce of real and complex algebraic numbers. Compute an extension field with a primitive element.
# File examples/jas.rb, line 2018 def rootReduce(a, b) if not a.is_a? RingElem a = RingElem.new(a); end return a.rootReduce(b); end
Compute algebraic real and complex roots refinement.
# File examples/jas.rb, line 1987 def rootRefine(a,eps=nil) if not a.is_a? RingElem a = RingElem.new(a); end return a.rootRefine(eps); end
Roots of unity of real and complex algebraic numbers.
# File examples/jas.rb, line 2007 def rootsOfUnity(a) if not a.is_a? RingElem a = RingElem.new(a); end return a.rootsOfUnity(); end
Compute squarefree factors of polynomial.
# File examples/jas.rb, line 1879 def squarefreeFactors(a) if a.is_a? RingElem a = a.elem; else a = element( a ); a = a.elem; end cf = @ring.coFac; if cf.is_a? GenPolynomialRing e = @sqf.recursiveSquarefreeFactors( a ); else e = @sqf.squarefreeFactors( a ); end ll = {}; for a in e.keySet() i = e.get(a); ll[ RingElem.new( a ) ] = i; end return ll; end
Create a string representation.
# File examples/jas.rb, line 1766 def to_s() return @ring.toScript(); end
Define instance variables for generators.
# File examples/jas.rb, line 1726 def variable_generators() Ring.instance_eval( "attr_accessor :generators;" ) @generators = {}; for i in self.gens() begin ivs = nameFromValue(i); if ivs != nil #puts "string: #{ivs} = " + ivs.class.to_s; if @generators[ ivs ] != nil puts "redefining local variable #{ivs}"; end @generators[ ivs ] = i; self.instance_eval( "def #{ivs}; @generators[ '#{ivs}' ]; end" ) end rescue => e puts "ring error: #{ivs} = " + i.to_s + ", e = " + str(e); #pass end end #puts "locally defined generators: " + @generators.keys().join(", "); end
Get the zero of the polynomial ring.
# File examples/jas.rb, line 1821 def zero() return RingElem.new( @ring.getZERO() ); end