def __constructJasObject(self): #from types import StringType from jas import PolyRing, ZZ # set up the polynomial ring (Jas syntax) if 'hasParameters' in self.__dict__ and self.hasParameters != '': #K = 'K.<%s> = PolynomialRing(ZZ)' % self.hasParameters #R = K + '; R.<%s> = PolynomialRing(K)' % self.hasVariables K = PolyRing(ZZ(), str(self.hasParameters)) R = PolyRing(K, str(self.hasVariables)) gens = '%s,%s' % (self.hasParameters, self.hasVariables) else: #R = 'R.<%s> = PolynomialRing(ZZ)' % (self.hasVariables) R = PolyRing(ZZ(), str(self.hasVariables)) gens = str(self.hasVariables) # translate Jas syntax to pure Python and execute #exec(preparse(R)) Rg = "(one," + gens + ") = R.gens();" #print str(R) exec(str(Rg)) # safe here since R did evaluate #print "R = " + str(R) self.jasRing = R # avoid XSS: check if polynomials are clean from edu.jas.poly import GenPolynomialTokenizer vs = GenPolynomialTokenizer.expressionVariables(str(gens)) vs = sorted(vs) #print "vs = " + str(vs) vsb = set() [ vsb.update(GenPolynomialTokenizer.expressionVariables(str(s))) for s in self.basis ] vsb = sorted(list(vsb)) #print "vsb = " + str(vsb) if vs != vsb: raise ValueError("invalid variables: expected " + str(vs) + ", got " + str(vsb)) # construct polynomials in the constructed ring from # the polynomial expressions self.jasBasis = [] for ps in self.basis: #print "ps = " + str(ps) ps = str(ps) ps = ps.replace('^', '**') #exec(preparse("symbdata_ideal = %s" % ps)) #exec("symbdata_poly = %s" % ps) pol = eval(ps) self.jasBasis.append(pol)
def testRingZZ(self): r = PolyRing( ZZ(), "(t,x)", Order.INVLEX ); self.assertEqual(str(r),'PolyRing(ZZ(),"t,x",Order.INVLEX)'); [one,x,t] = r.gens(); self.assertTrue(one.isONE()); self.assertTrue(len(x)==1); self.assertTrue(len(t)==1); # f = 11 * x**4 - 13 * t * x**2 - 11 * x**2 + 2 * t**2 + 11 * t; f = f**2 + f + 3; #print "f = " + str(f); self.assertEqual(str(f),'( 4 * x**4 - 52 * t**2 * x**3 + 44 * x**3 + 213 * t**4 * x**2 - 330 * t**2 * x**2 + 123 * x**2 - 286 * t**6 * x + 528 * t**4 * x - 255 * t**2 * x + 11 * x + 121 * t**8 - 242 * t**6 + 132 * t**4 - 11 * t**2 + 3 )');
# jython examples for jas. # $Id$ # import sys; from jas import PolyRing, ZZ from jas import startLog # chebyshev polynomial example # T(0) = 1 # T(1) = x # T(n) = 2 * x * T(n-1) - T(n-2) #r = Ring( "Z(x) L" ); r = PolyRing(ZZ(), "(x)", PolyRing.lex ); print "Ring: " + str(r); print; # sage like: with generators for the polynomial ring #is automatic: [one,x] = r.gens(); x2 = 2 * x; N = 10; T = [one,x]; for n in range(2,N+1): t = x2 * T[n-1] - T[n-2]; T.append( t ); for n in range(0,N+1):
# # jython examples for jas. # $Id$ # import sys from jas import PolyRing, ZZ, Order, Ideal from jas import startLog, terminate # sicora, e-gb example r = PolyRing(ZZ(), "t", Order.INVLEX) print "Ring: " + str(r) print f1 = 2 * t + 1 f2 = t**2 + 1 F = r.ideal("", [f1, f2]) print "Ideal: " + str(F) print E = F.eGB() print "seq e-GB:", E print "is e-GB:", E.iseGB() print f = t**3 n = E.eReduction(f) print "e-Reduction = " + str(n)
# $Id$ # from java.lang import System from jas import PolyRing, ZZ, GF, QQ from jas import terminate, startLog # polynomial examples: multivariate factorization #r = Ring( "Mod 1152921504606846883 (x,y,z) L" ); #r = Ring( "Rat(x,y,z) L" ); #r = Ring( "C(x,y,z) L" ); #r = Ring( "Mod 3 (x,y,z) L" ); #r = Ring( "Z(x,y,z) L" ); r = PolyRing(ZZ(), "x,y,z", PolyRing.lex) print "Ring: " + str(r) print #[one,x,y,z] = r.gens(); #f = z * ( y + 1 )**2 * ( x**2 + x + 1 )**3; #f = z * ( y + 1 ) * ( x**2 + x + 1 ); #f = ( y + 1 ) * ( x**2 + x + 1 ); #f = ( y + z**2 ) * ( x**2 + x + 1 ); #f = x**4 * y + x**3 + z + x + z**2 + y * z**2; ## f = x**3 + ( ( y + 2 ) * z + 2 * y + 1 ) * x**2 \ ## + ( ( y + 2 ) * z**2 + ( y**2 + 2 * y + 1 ) * z + 2 * y**2 + y ) * x \ ## + ( y + 1 ) * z**3 + ( y + 1 ) * z**2 + ( y**3 + y**2 ) * z + y**3 + y**2;
# # jython examples for jas. # $Id$ # import sys from jas import PolyRing, Ideal, ZZ from jas import startLog, terminate # tuzun, e-gb example r = PolyRing(ZZ(), "(t)") print "Ring: " + str(r) #automatic: [one,t] = r.gens(); print "one: " + str(one) print "t: " + str(t) print f1 = 2 * t + 1 f2 = t**2 + 1 F = [f1, f2] I = r.ideal(list=F) print "Ideal: " + str(I) print #startLog(); G = I.eGB()
# # jython examples for jas. # $Id$ # import sys from jas import Ring, PolyRing, RF, ZZ from jas import terminate # Raksanyi & Walter example # rational function coefficients #r = Ring( "RatFunc(a1, a2, a3, a4) (x1, x2, x3, x4) G" ); r = PolyRing(RF(PolyRing(ZZ(), "a1, a2, a3, a4", PolyRing.lex)), "x1, x2, x3, x4", PolyRing.grad) print "Ring: " + str(r) print ps = """ ( ( x4 - { a4 - a2 } ), ( x1 + x2 + x3 + x4 - { a1 + a3 + a4 } ), ( x1 x3 + x1 x4 + x2 x3 + x3 x4 - { a1 a4 + a1 a3 + a3 a4 } ), ( x1 x3 x4 - { a1 a3 a4 } ) ) """ f = r.ideal(ps) print "Ideal: " + str(f) print
# $Id$ # import sys; from jas import Ring, PolyRing, SolvPolyRing from jas import Ideal from jas import Module, SubModule, SolvableModule, SolvableSubModule from jas import startLog from jas import terminate from jas import ZZ, QQ, ZM, GF, DD, CC, Quat, Oct, AN, RealN, RF, RC, LC, RR, PS, MPS, Vec, Mat from edu.jas.arith import BigDecimal print "------- ZZ = BigInteger ------------"; z1 = ZZ(12345678901234567890); print "z1 = " + str(z1); z2 = z1**2 + 12345678901234567890; print "z2 = " + str(z2); print; print "------- QQ = BigRational ------------"; r1 = QQ(1,12345678901234567890); print "r1 = " + str(r1**3); r2 = r1**2 + (1,12345678901234567890); print "r2 = " + str(r2); print; print "------- ZM = ModInteger ------------";
# # jython examples for jas. # $Id$ # import sys from jas import PolyRing, ZZ from jas import startLog, terminate # hermite polynomial example # H(0) = 1 # H(1) = 2 * x # H(n) = 2 * x * H(n-1) - 2 * (n-1) * H(n-2) r = PolyRing(ZZ(), "x", PolyRing.lex) print "Ring: " + str(r) print # sage like: with generators for the polynomial ring #auto: [one,x] = r.gens(); x2 = 2 * x N = 10 H = [one, x2] for n in range(2, N + 1): h = x2 * H[n - 1] - 2 * (n - 1) * H[n - 2] H.append(h) for n in range(0, N + 1):
# # jython examples for jas. # $Id$ # import sys from jas import PolyRing, ZZ from jas import startLog # pppj 2006 paper examples #r = Ring( "Z(x1,x2,x3) L" ); r = PolyRing(ZZ(), "x1,x2,x3", PolyRing.lex) print "Ring: " + str(r) print #unused: ps = """ ( ( 3 x1^2 x3^4 + 7 x2^5 - 61 ) ) """ f = 3 * x1**2 * x3**4 + 7 * x2**5 - 61 print "f = " + str(f) print #id = r.ideal( ps ); id = r.ideal("", [f]) print "Ideal: " + str(id)
# # jython examples for jas. # $Id$ # from java.lang import System from jas import QQ, ZZ, GF, ZM from jas import terminate, startLog # integer examples: gcd r = ZZ(); #r = QQ(); # = GF(19); # = ZM(19*61); print "Ring: " + str(r); print; a = r.random(251); b = r.random(171); c = abs(r.random(211)); #c = 1; #a = 0; print "a = ", a; print "b = ", b; print "c = ", c; print;
# jython examples for jas. # $Id$ # import sys from jas import ZZ, Ring, PolyRing from jas import ParamIdeal from jas import startLog from jas import terminate # 2 univariate polynomials of degree 2 example for comprehensive GB # integral/rational function coefficients #r = Ring( "IntFunc(a3, b3, a2, b2, a1, b1, a0, b0) (x) L" ); r = PolyRing(PolyRing(ZZ(), "(a3, b3, a2, b2, a1, b1, a0, b0)", PolyRing.lex), "(x)", PolyRing.lex) print "Ring: " + str(r) print ps = """ ( ( { a3 } x^3 + { a2 } x^2 + { a1 } x + { a0 } ), ( { b3 } x^3 + { b2 } x^2 + { b1 } x + { b0 } ) ) """ p1 = a3 * x**3 + a2 * x**2 + a1 * x + a0 p2 = b3 * x**3 + b2 * x**2 + b1 * x + b0 #f = r.paramideal( ps );
# jython examples for jas. # $Id$ # from java.lang import System from java.lang import Integer from jas import PolyRing, SolvPolyRing, ZZ, QQ, GF, ZM # sparse polynomial powers #r = Ring( "Mod 1152921504606846883 (x,y,z) G" ); #r = Ring( "Rat(x,y,z) G" ); #r = Ring( "C(x,y,z) G" ); #r = Ring( "Z(x,y,z) L" ); r = PolyRing(ZZ(), "(x,y,z)", PolyRing.lex) #r = SolvPolyRing( ZZ(), "(x,y,z)", PolyRing.lex ); print "Ring: " + str(r) print ps = """ ( ( 1 + x^2147483647 + y^2147483647 + z^2147483647 ) ( 1 + x + y + z ) ( 10000000001 + 10000000001 x + 10000000001 y + 10000000001 z ) ) """ f = r.ideal(ps) print "Ideal: " + str(f)
from jas import terminate, startLog # polynomial examples: ideal prime decomposition # TRANSACTIONS OF THE AMERICAN MATHEMATICAL SOCIETY # Volume 296, Number 2. August 1986 # ON THE DEPTH OF THE SYMMETRIC ALGEBRA # J. HERZOG M. E. ROSSI AND G. VALLA #r = PolyRing(QQ(),"x,t,z,y",PolyRing.lex); #r = PolyRing(QQ(),"x,y,t,z",PolyRing.lex); #r = EF(QQ()).extend("x").polynomial("y,z,t").build(); #,PolyRing.lex); #c = PolyRing(QQ(),"t,y",PolyRing.lex); #c = PolyRing(ZM(32003,0,True),"t",PolyRing.lex); #c = PolyRing.new(GF(32003),"t",PolyRing.lex); c = PolyRing(ZZ(), "t", PolyRing.lex) r = PolyRing(RF(c), "z,y,x", PolyRing.lex) print "Ring: " + str(r) print #automatic: [one,t,z,y,x] = r.gens(); print "one = ", one print "x = ", x print "y = ", y print "z = ", z print "t = ", t f1 = x**3 - y**7 f2 = x**2 * y - x * t**3 - z**6 f3 = z**2 - t**3 #f3 = z**19 - t**23;
import sys from jas import Ring, PolyRing, QQ, ZZ, Order, Scripting from jas import startLog, terminate # examples: from Mathematica # check("GroebnerBasis({x^2 + y^2 + z^2 - 1, x - z + 2, z^2 - x*y}, # {x, y, z})", # "{12-28*z+27*z^2-12*z^3+3*z^4, -6+4*y+11*z-6*z^2+3*z^3, 2+x-z}"); Scripting.setCAS(Scripting.CAS.Math) #Scripting.setCAS(Scripting.CAS.Sage); #Scripting.setCAS(Scripting.CAS.Singular); r = PolyRing(ZZ(), "x,y,z", Order.Lexicographic) print "Ring: " + str(r) print ff = [x**2 + y**2 + z**2 - 1, x - z + 2, z**2 - x * y] F = r.ideal("", ff) print "F = " + str(F) print #startLog(); G = F.GB() print "G = " + str(G) print print "Ma: " + str(
# # jython examples for jas. # $Id$ # #import sys; from jas import Ring, PolyRing from jas import ZZ from jas import startLog # e-gb and d-gb example to compare with hermit normal form r = PolyRing( ZZ(), "x4,x3,x2,x1", PolyRing.lex ); print "Ring: " + str(r); print; #is automatic: [one,x4,x3,x2,x1] = r.gens(); f1 = x1 + 2 * x2 + 3 * x3 + 4 * x4 + 3; f2 = 3 * x2 + 2 * x3 + x4 + 2; f3 = 3 * x3 + 5 * x4 + 1; f4 = 5 * x4 + 4; L = [f1,f2,f3,f4]; #print "L = ", str(L); f = r.ideal( list=L ); print "Ideal: " + str(f); print;
## 2 z_2+6ay_2+20 y_2^3+2c \& ## 3 z_1^2+y_1^2+b \& ## 3z_2^2+y_2^2+b \& ## \end{Equations} ## \end{PossoExample} #from java.lang import System from jas import WordRing, WordPolyRing, WordPolyIdeal, PolyRing, SolvPolyRing, RingElem from jas import terminate, startLog from jas import QQ, ZZ, GF, ZM, WRC # Hawes & Gibson example 2 # rational function coefficients r = WordPolyRing(PolyRing(ZZ(), "a, c, b", PolyRing.lex), "y2, y1, z1, z2, x") print "Ring: " + str(r) print one, a, c, b, y2, y1, z1, z2, x = r.gens() p1 = x + 2 * y1 * z1 + 3 * a * y1**2 + 5 * y1**4 + 2 * c * y1 p2 = x + 2 * y2 * z2 + 3 * a * y2**2 + 5 * y2**4 + 2 * c * y2 p3 = 2 * z2 + 6 * a * y2 + 20 * y2**3 + 2 * c p4 = 3 * z1**2 + y1**2 + b p5 = 3 * z2**2 + y2**2 + b F = [p1, p2, p3, p4, p5] # make all variables commute cm = [RingElem(q) for q in r.ring.commute()]
## 2 z_2+6ay_2+20 y_2^3+2c \& ## 3 z_1^2+y_1^2+b \& ## 3z_2^2+y_2^2+b \& ## \end{Equations} ## \end{PossoExample} #from java.lang import System from jas import WordRing, WordPolyRing, WordPolyIdeal, PolyRing, SolvPolyRing, RingElem from jas import terminate, startLog from jas import QQ, ZZ, GF, ZM, WRC # Hawes & Gibson example 2 # rational function coefficients r = SolvPolyRing( PolyRing(ZZ(),"a, c, b",PolyRing.lex), "y2, y1, z1, z2, x",PolyRing.grad); print "Ring: " + str(r); print; one,a,c,b,y2,y1,z1,z2,x = r.gens(); p1 = x + 2 * y1 * z1 + 3 * a * y1**2 + 5 * y1**4 + 2 * c * y1; p2 = x + 2 * y2 * z2 + 3 * a * y2**2 + 5 * y2**4 + 2 * c * y2; p3 = 2 * z2 + 6 * a * y2 + 20 * y2**3 + 2 * c; p4 = 3 * z1**2 + y1**2 + b; p5 = 3 * z2**2 + y2**2 + b; F = [p1,p2,p3,p4,p5]; g = r.ideal( "", F ); print "Ideal: " + str(g);
## 2 z_2+6ay_2+20 y_2^3+2c \& ## 3 z_1^2+y_1^2+b \& ## 3z_2^2+y_2^2+b \& ## \end{Equations} ## \end{PossoExample} import sys from jas import Ring, PolyRing, RF, ZZ from jas import startLog, terminate # Hawes & Gibson example 2 # rational function coefficients #r = Ring( "RatFunc(a, c, b) (y2, y1, z1, z2, x) G" ); r = PolyRing(RF(PolyRing(ZZ(), "a, c, b", PolyRing.lex)), "y2, y1, z1, z2, x", PolyRing.grad) print "Ring: " + str(r) print [one, a, c, b, y2, y1, z1, z2, x] = r.gens() p1 = x + 2 * y1 * z1 + 3 * a * y1**2 + 5 * y1**4 + 2 * c * y1 p2 = x + 2 * y2 * z2 + 3 * a * y2**2 + 5 * y2**4 + 2 * c * y2 p3 = 2 * z2 + 6 * a * y2 + 20 * y2**3 + 2 * c p4 = 3 * z1**2 + y1**2 + b p5 = 3 * z2**2 + y2**2 + b p6 = ((p5 / a) / b) / c print "p6 = ", p6
#r = Ring( "Z(B,S,T,Z,P,W) L" ); #r = Ring( "Q(B,S,T,Z,P,W) L" ); #print "Ring: " + str(r); #print; #r = PolyRing(ZZ(),"B,S,T,Z,P,W",PolyRing.lex); #r = PolyRing(QQ(),"B,S,T,Z,P,W",PolyRing.lex); #r = PolyRing(CC(),"B,S,T,Z,P,W",PolyRing.lex); #r = PolyRing(DD(),"B,S,T,Z,P,W",PolyRing.lex); #r = PolyRing(ZM(19),"B,S,T,Z,P,W",PolyRing.lex); #r = PolyRing(ZM(1152921504606846883),"B,S,T,Z,P,W",PolyRing.lex); # 2^60-93 #rc = PolyRing(ZZ(),"e,f",PolyRing.lex); #rc = PolyRing(QQ(),"e,f",PolyRing.lex); #r = PolyRing(rc,"B,S,T,Z,P,W",PolyRing.lex); rqc = PolyRing(ZZ(), "e,f", PolyRing.lex) print "Q-Ring: " + str(rqc) print "rqc.gens() = ", [str(f) for f in rqc.gens()] print [pone, pe, pf] = rqc.gens() r = PolyRing(RF(rqc), "B,S,T,Z,P,W", PolyRing.lex) print "Ring: " + str(r) print # sage like: with generators for the polynomial ring print "r.gens() = ", [str(f) for f in r.gens()] print [one, e, f, B, S, T, Z, P, W] = r.gens() #[one,B,S,T,Z,P,W] = r.gens(); #[one,I,B,S,T,Z,P,W] = r.gens();
import sys from jas import PolyRing from jas import ZZ from jas import QQ from jas import CC from jas import ZM from jas import RF from jas import startLog from jas import terminate # example for rational and complex numbers # # zn = ZZ(7) print "zn:", zn print "zn^2:", zn * zn print x = 10000000000000000000000000000000000000000000000000 rn = QQ(2 * x, 4 * x) print "rn:", rn print "rn^2:", rn * rn print rn = QQ((6, 4)) print "rn:", rn print "rn^2:", rn * rn print "1/rn: " + str(1 / rn) print
# $Id$ # import sys; from jas import ZZ, Ring, PolyRing from jas import ParamIdeal from jas import startLog from jas import terminate # 2 univariate polynomials of degree 2 example for comprehensive GB # integral/rational function coefficients #r = Ring( "IntFunc(a2, a1, a0, b2, b1, b0) (x) L" ); r = PolyRing( PolyRing(ZZ(),"(a2, a1, a0, b2, b1, b0)",PolyRing.lex),"(x)", PolyRing.lex ); print "Ring: " + str(r); print; ps = """ ( ( { a2 } x^2 + { a1 } x + { a0 } ), ( { b2 } x^2 + { b1 } x + { b0 } ) ) """; p1 = a2 * x**2 + a1 * x + a0; p2 = b2 * x**2 + b1 * x + b0; #f = r.paramideal( ps ); f = r.paramideal( "", [p1,p2] );
print p = r.random(3, 6, 4) print "p = " + str(p) print pp = p**5 print "#pp = " + str(len(pp)) print "p == pp: " + str(p == pp) print "pp == pp: " + str(pp == pp) print "pp-pp == 0: " + str(pp - pp == 0) print #exit(0); ri = WordPolyRing(ZZ(), "x,y") print "WordPolyRing: " + str(ri) print [one, x, y] = ri.gens() print "one = " + str(one) print "x = " + str(x) print "y = " + str(y) print f1 = x * y - 10 f2 = y * x + x + y print "f1 = " + str(f1) print "f2 = " + str(f2) print
# jython examples for jas. # $Id$ # import sys from jas import ZZ, Ring, PolyRing from jas import ParamIdeal from jas import startLog from jas import terminate # simple example for comprehensive GB # integral/rational function coefficients #r = Ring( "IntFunc(u,v) (x,y) L" ); r = PolyRing(PolyRing(ZZ(), "(u,v)", PolyRing.lex), "(x,y)", PolyRing.lex) print "Ring: " + str(r) print ps = """ ( ( { v } x y + x ), ( { u } y^2 + x^2 ) ) """ p1 = v * x * y + x p2 = u * y**2 + x**2 #f = r.paramideal( ps ); f = r.paramideal("", [p1, p2])