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 1912 def Ring.getEngineFactor(r) 1913 if r.is_a? RingElem 1914 r = r.elem; 1915 end 1916 if not r.is_a? GenPolynomialRing 1917 return nil; 1918 end 1919 begin 1920 i = FactorFactory.getImplementation(r.coFac); 1921 rescue => e 1922 i = nil 1923 end 1924 #puts "factor engine: #{i}"; 1925 return i; 1926 end
Get the polynomial gcd engine implementation.
r is the given polynomial ring.
# File examples/jas.rb 1869 def Ring.getEngineGcd(r) 1870 if r.is_a? RingElem 1871 r = r.elem; 1872 end 1873 if not r.is_a? GenPolynomialRing 1874 return nil; 1875 end 1876 begin 1877 i = GCDFactory.getProxy(r.coFac); 1878 #i = GCDFactory.getImplementation(r.coFac); 1879 rescue => e 1880 i = nil 1881 end 1882 #puts "gcd engine: #{i}"; 1883 return i; 1884 end
Get the polynomial squarefree engine implementation.
r is the given polynomial ring.
# File examples/jas.rb 1891 def Ring.getEngineSqf(r) 1892 if r.is_a? RingElem 1893 r = r.elem; 1894 end 1895 if not r.is_a? GenPolynomialRing 1896 return nil; 1897 end 1898 begin 1899 i = SquarefreeFactory.getImplementation(r.coFac); 1900 rescue => e 1901 i = nil 1902 end 1903 #puts "sqf engine: #{i}"; 1904 return i; 1905 end
Ring constructor.
ringstr string representation to be parsed. ring JAS ring object.
# File examples/jas.rb 1836 def initialize(ringstr="",ring=nil) 1837 if ring == nil 1838 sr = StringReader.new( ringstr ); 1839 tok = RingFactoryTokenizer.new(sr); 1840 pfac = tok.nextPolynomialRing(); 1841 #tok = GenPolynomialTokenizer.new(sr); 1842 #@pset = tok.nextPolynomialSet(); 1843 @ring = pfac; 1844 else 1845 if ring.is_a? Ring 1846 @ring = ring.ring 1847 else 1848 @ring = ring; 1849 end 1850 end 1851 # parameter ",fast=false" not possible w/o keyword params 1852 #if fast == true 1853 # return 1854 #end 1855 @engine = Ring.getEngineGcd(@ring); 1856 @sqf = Ring.getEngineSqf(@ring); 1857 @factor = Ring.getEngineFactor(@ring); 1858 variable_generators() 1859 if self.class.auto_inject or self.class.superclass.auto_inject # sic! 1860 inject_variables(); 1861 end 1862 end
Public Instance Methods
Test if two rings are equal.
# File examples/jas.rb 1978 def ==(other) 1979 if not other.is_a? Ring 1980 return false; 1981 end 1982 return @ring.equals(other.ring); 1983 end
Chinese remainder theorem.
# File examples/jas.rb 2278 def CRT(polystr="", list=nil, rem=nil) 2279 if list == nil 2280 sr = StringReader.new( polystr ); 2281 tok = GenPolynomialTokenizer.new(@ring,sr); 2282 @list = tok.nextPolynomialList(); 2283 else 2284 @list = rbarray2arraylist(list,nil,rec=2); 2285 end 2286 if rem == nil 2287 raise ArgumentError, "No remainders given." 2288 else 2289 @remlist = rbarray2arraylist(rem,nil,rec=1); 2290 end 2291 #puts "list = " + str(@list); 2292 #puts "remlist = " + str(@remlist); 2293 #puts 2294 h = PolyGBUtil.chineseRemainderTheorem(@list, @remlist); 2295 if h != nil 2296 h = RingElem.new(h); 2297 end 2298 return h; 2299 end
Chinese remainder theorem, interpolation.
# File examples/jas.rb 2304 def CRTinterpol(polystr="", list=nil, rem=nil) 2305 if list == nil 2306 sr = StringReader.new( polystr ); 2307 tok = GenPolynomialTokenizer.new(@ring,sr); 2308 @list = tok.nextPolynomialList(); 2309 else 2310 @list = rbarray2arraylist(list,nil,rec=2); 2311 end 2312 if rem == nil 2313 raise ArgumentError, "No remeinders given." 2314 else 2315 @remlist = rbarray2arraylist(rem,nil,rec=1); 2316 end 2317 #puts "ring = " + str(@ring.toScript()); 2318 #puts "list = " + str(@list); 2319 #puts "remlist = " + str(@remlist); 2320 #puts 2321 h = PolyGBUtil.CRTInterpolation(@ring, @list, @remlist); 2322 if h != nil 2323 h = RingElem.new(h); 2324 end 2325 return h; 2326 end
Compute algebraic real and complex roots of univariate polynomial.
# File examples/jas.rb 2188 def algebraicRoots(a,eps=nil) 2189 if not a.is_a? RingElem 2190 a = RingElem.new(a); 2191 end 2192 return a.algebraicRoots(eps); 2193 end
Compute complex roots of univariate polynomial.
# File examples/jas.rb 2178 def complexRoots(a,eps=nil) 2179 if not a.is_a? RingElem 2180 a = RingElem.new(a); 2181 end 2182 return a.complexRoots(eps); 2183 end
Compute deximal approximation of algebraic real and complex roots.
# File examples/jas.rb 2208 def decimalRoots(a,eps=nil) 2209 if not a.is_a? RingElem 2210 a = RingElem.new(a); 2211 end 2212 return a.decimalRoots(eps); 2213 end
Create an element from a string or an object.
# File examples/jas.rb 2044 def element(poly) 2045 if not poly.is_a? String 2046 begin 2047 if @ring == poly.ring 2048 return RingElem.new(poly); 2049 end 2050 rescue => e 2051 # pass 2052 end 2053 poly = str(poly); 2054 end 2055 i = SimIdeal.new( self, "( " + poly + " )" ); 2056 list = i.pset.list; 2057 if list.size > 0 2058 return RingElem.new( list[0] ); 2059 end 2060 end
Compute irreducible factorization for modular, integer, rational number and algebriac number coefficients.
# File examples/jas.rb 2115 def factors(a) 2116 if a.is_a? RingElem 2117 a = a.elem; 2118 else 2119 a = element( a ); 2120 a = a.elem; 2121 end 2122 begin 2123 cf = @ring.coFac; 2124 if cf.is_a? GenPolynomialRing 2125 e = @factor.recursiveFactors( a ); 2126 else 2127 e = @factor.factors( a ); 2128 end 2129 ll = {}; 2130 for a in e.keySet() 2131 i = e.get(a); 2132 ll[ RingElem.new( a ) ] = i; 2133 end 2134 return ll; 2135 rescue => e 2136 puts "error " + str(e) 2137 return nil 2138 end 2139 end
Compute absolute irreducible factorization for (modular,) rational number coefficients.
# File examples/jas.rb 2145 def factorsAbsolute(a) 2146 if a.is_a? RingElem 2147 a = a.elem; 2148 else 2149 a = element( a ); 2150 a = a.elem; 2151 end 2152 begin 2153 ll = @factor.factorsAbsolute( a ); 2154 ## ll = {}; 2155 ## for a in e.keySet() 2156 ## i = e.get(a); 2157 ## ll[ RingElem.new( a ) ] = i; 2158 return ll; 2159 rescue => e 2160 puts "error in factorsAbsolute " + str(e) 2161 return nil 2162 end 2163 end
Compute the greatest common divisor of a and b.
# File examples/jas.rb 2065 def gcd(a,b) 2066 if a.is_a? RingElem 2067 a = a.elem; 2068 else 2069 a = element( a ); 2070 a = a.elem; 2071 end 2072 if b.is_a? RingElem 2073 b = b.elem; 2074 else 2075 b = element( b ); 2076 b = b.elem; 2077 end 2078 cf = @ring.coFac; 2079 if cf.is_a? GenPolynomialRing 2080 e = @engine.recursiveGcd( a, b ); 2081 else 2082 e = @engine.gcd( a, b ); 2083 end 2084 return RingElem.new( e ); 2085 end
Get list of generators of the polynomial ring.
# File examples/jas.rb 2010 def gens() 2011 ll = @ring.generators(); 2012 n = ll.map{ |e| RingElem.new(e) }; 2013 return n; 2014 end
Create an ideal.
# File examples/jas.rb 1988 def ideal(ringstr="",list=nil) 1989 return JAS::SimIdeal.new(self,ringstr,list); 1990 end
Inject variables for generators in top level environment.
# File examples/jas.rb 1956 def inject_variables() 1957 begin 1958 require "irb/frame" # must be placed here 1959 bin = IRB::Frame.bottom(0); 1960 env = eval "self", bin; 1961 #puts "env = " + str(env) 1962 inject_gens(env) 1963 rescue => e 1964 puts "error: 'irb/frame' not found, e = " + str(e); 1965 end 1966 end
Integrate rational function or power series.
# File examples/jas.rb 2239 def integrate(a) 2240 if not a.is_a? RingElem 2241 a = RingElem.new(a); 2242 end 2243 return a.integrate(); 2244 end
Get the one of the polynomial ring.
# File examples/jas.rb 2019 def one() 2020 return RingElem.new( @ring.getONE() ); 2021 end
Create an ideal in a polynomial ring with parameter coefficients.
# File examples/jas.rb 1995 def paramideal(ringstr="",list=nil,gbsys=nil) 1996 return ParamIdeal.new(self,ringstr,list,gbsys); 1997 end
Get a power series ring from this ring.
# File examples/jas.rb 2002 def powerseriesRing() 2003 pr = MultiVarPowerSeriesRing.new(@ring); 2004 return MultiSeriesRing.new("",nil,pr); 2005 end
Get a random polynomial.
# File examples/jas.rb 2033 def random(k=5,l=7,d=3,q=0.3) 2034 r = @ring.random(k,l,d,q); 2035 if @ring.coFac.isField() 2036 r = r.monic(); 2037 end 2038 return RingElem.new( r ); 2039 end
Compute real roots of univariate polynomial.
# File examples/jas.rb 2168 def realRoots(a,eps=nil) 2169 if not a.is_a? RingElem 2170 a = RingElem.new(a); 2171 end 2172 return a.realRoots(eps); 2173 end
Root reduce of real and complex algebraic numbers. Compute an extension field with a primitive element.
# File examples/jas.rb 2229 def rootReduce(a, b) 2230 if not a.is_a? RingElem 2231 a = RingElem.new(a); 2232 end 2233 return a.rootReduce(b); 2234 end
Compute algebraic real and complex roots refinement.
# File examples/jas.rb 2198 def rootRefine(a,eps=nil) 2199 if not a.is_a? RingElem 2200 a = RingElem.new(a); 2201 end 2202 return a.rootRefine(eps); 2203 end
Roots of unity of real and complex algebraic numbers.
# File examples/jas.rb 2218 def rootsOfUnity(a) 2219 if not a.is_a? RingElem 2220 a = RingElem.new(a); 2221 end 2222 return a.rootsOfUnity(); 2223 end
Compute squarefree factors of polynomial.
# File examples/jas.rb 2090 def squarefreeFactors(a) 2091 if a.is_a? RingElem 2092 a = a.elem; 2093 else 2094 a = element( a ); 2095 a = a.elem; 2096 end 2097 cf = @ring.coFac; 2098 if cf.is_a? GenPolynomialRing 2099 e = @sqf.recursiveSquarefreeFactors( a ); 2100 else 2101 e = @sqf.squarefreeFactors( a ); 2102 end 2103 ll = {}; 2104 for a in e.keySet() 2105 i = e.get(a); 2106 ll[ RingElem.new( a ) ] = i; 2107 end 2108 return ll; 2109 end
Sub ring generators as Groebner base.
# File examples/jas.rb 2249 def subring(polystr="", list=nil) 2250 if list == nil 2251 sr = StringReader.new( polystr ); 2252 tok = GenPolynomialTokenizer.new(@ring,sr); 2253 @list = tok.nextPolynomialList(); 2254 else 2255 @list = rbarray2arraylist(list,rec=1); 2256 end 2257 sr = PolyGBUtil.subRing(@list); 2258 srr = sr.map { |a| RingElem.new(a) }; 2259 return srr; 2260 end
Sub ring member test. list is a Groebner base. Test if a in K.
# File examples/jas.rb 2266 def subringmember(list, a) 2267 sr = list.map { |p| p.elem }; 2268 if a.is_a? RingElem 2269 a = a.elem; 2270 end 2271 b = PolyGBUtil.subRingMember(sr, a); 2272 return b; 2273 end
Create a string representation.
# File examples/jas.rb 1971 def to_s() 1972 return @ring.toScript(); 1973 end
Define instance variables for generators.
# File examples/jas.rb 1931 def variable_generators() 1932 Ring.instance_eval( "attr_accessor :generators;" ) 1933 @generators = {}; 1934 for i in self.gens() 1935 begin 1936 ivs = nameFromValue(i); 1937 if ivs != nil 1938 #puts "string: #{ivs} = " + ivs.class.to_s; 1939 if @generators[ ivs ] != nil 1940 puts "redefining local variable #{ivs}"; 1941 end 1942 @generators[ ivs ] = i; 1943 self.instance_eval( "def #{ivs}; @generators[ '#{ivs}' ]; end" ) 1944 end 1945 rescue => e 1946 puts "ring error: #{ivs} = " + i.to_s + ", e = " + str(e); 1947 #pass 1948 end 1949 end 1950 #puts "locally defined generators: " + @generators.keys().join(", "); 1951 end
Get the zero of the polynomial ring.
# File examples/jas.rb 2026 def zero() 2027 return RingElem.new( @ring.getZERO() ); 2028 end