def testRingQQ(self): r = PolyRing( QQ(), "(t,x)", Order.INVLEX ); self.assertEqual(str(r),'PolyRing(QQ(),"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, QQ, RF from jas import startLog from jas import terminate # Montes JSC 2002, 33, 183-208, example 11.4 # integral function coefficients R = PolyRing(PolyRing(QQ(), "Q2, P2, Q1, P1", PolyRing.lex), "f3, e3, f2, e2", PolyRing.lex) print "Ring: " + str(R) print #automatic: [one, Q2, P2, Q1, P1, f3, e3, f2, e2] = R.gens(); print "gens: ", [str(f) for f in R.gens()] print fp1 = 14 - 12 * e2 - 110 * f2 - 2 * e3 - 10 * f3 - P1 fp2 = 2397 - 2200 * e2 + 240 * f2 - 200 * e3 + 40 * f3 - 20 * Q1 fp3 = 16 * e2**2 - 4 * e2 * e3 - 20 * e2 * f3 + 20 * e3 * f2 + 16 * f2**2 - 4 * f2 * f3 - 12 * e2 + 110 * f2 - P2 fp4 = 2599 * e2**2 - 400 * e2 * e3 + 80 * e2 * f3 - 80 * e3 * f2 + 2599 * f2**2 - 400 * f2 * f3 - 2200 * e2 - 240 * f2 - 20 * Q2 print "fp1: " + str(fp1) print "fp2: " + str(fp2) print "fp3: " + str(fp3)
# # jython examples for jas. # $Id$ # #from java.lang import System from jas import WordRing, WordPolyRing, WordPolyIdeal from jas import terminate, startLog from jas import QQ, ZZ, GF, ZM # non-commutative polynomial examples: simple test r = WordPolyRing(QQ(), "x,y") print "WordPolyRing: " + str(r) print [one, x, y] = r.gens() print "one = " + str(one) print "x = " + str(x) print "y = " + str(y) print f1 = x * y - (1, 10) f2 = y * x + x + y print "f1 = " + str(f1) print "f2 = " + str(f2) print c1 = f1 * f2
# # jython examples for jas. # $Id$ # from java.lang import System from jas import PolyRing, QQ, ZM from jas import terminate, startLog import operator # polynomial examples: squarefree: characteristic 0 r = PolyRing(QQ(), "x, y, z", PolyRing.lex) print "Ring: " + str(r) print #automatic: [one,x,y,z] = r.gens(); a = r.random(k=2, l=3) b = r.random(k=2, l=3) c = r.random(k=1, l=3) if a.isZERO(): a = x if b.isZERO(): b = y if c.isZERO(): c = z
# # jython examples for jas. # $Id$ # import sys from jas import QQ, PolyRing from jas import startLog from jas import terminate # ideal elimination example #r = Ring( "Rat(x,y,z) G" ); r = PolyRing(QQ(), "(x,y,z)", PolyRing.grad) print "Ring: " + str(r) print ps1 = """ ( ( x^2 - 2 ), ( y^2 - 3 ), ( z^3 - x * y ) ) """ ff = [x**2 - 2, y**2 - 3, z**3 - x * y] #F1 = r.ideal( ps1 ); F1 = r.ideal("", ff) print "Ideal: " + str(F1)
# # jython examples for jas. # $Id$ # import sys from java.lang import System from jas import PolyRing, QQ, DD, AN, BigDecimal from jas import terminate, startLog # roots simplification r = PolyRing(QQ(), "I", PolyRing.lex) print "Ring: " + str(r) #print; #automatic: [one,I] = r.gens(); print "one = ", one print "I = ", I eps = QQ(1, 10)**(BigDecimal.DEFAULT_PRECISION) #-3 #eps = QQ(1,10) ** 7; #eps = nil; print "eps = " + str(eps) ip = (I**2 + 1) # I iq = AN(ip, 0, True)
## 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, QQ from jas import startLog, terminate # Hawes & Gibson example 2 # rational function coefficients #r = Ring( "IntFunc(a, c, b) (y2, y1, z1, z2, x) G" ); r = PolyRing( PolyRing(QQ(),"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( list=F ); print "Ideal: " + str(g);
# # jython examples for jas. # $Id$ # import sys from java.lang import System from jas import QQ, AN, RF, Ring, PolyRing from jas import terminate, startLog # polynomial examples: factorization over Q(sqrt(2))(x)(sqrt(x))[y] Q = PolyRing(QQ(),"w2",PolyRing.lex); print "Q = " + str(Q); [e,a] = Q.gens(); print "e = " + str(e); print "a = " + str(a); root = a**2 - 2; print "root = " + str(root); Q2 = AN(root,field=True); print "Q2 = " + str(Q2.factory()); [one,w2] = Q2.gens(); #print "one = " + str(one); #print "w2 = " + str(w2); print; Qp = PolyRing(Q2,"x",PolyRing.lex); print "Qp = " + str(Qp);
# # jython examples for jas. # $Id$ # import sys from jas import Ring, PolyRing, QQ, ZZ, RingElem from jas import startLog, terminate # GB examples #r = Ring( "Z(t,x,y,z) L" ); #r = Ring( "Mod 11(t,x,y,z) L" ); #r = Ring( "Rat(t,x,y) L" ); r = PolyRing(QQ(), "t,x,y", PolyRing.lex) #r = PolyRing( ZZ(), "t,x,y", PolyRing.lex ); print "Ring: " + str(r) print ps = """ ( ( t - x - 2 y ), ( x^4 + 4 ), ( y^4 + 4 ) ) """ # ( y^4 + 4 x y^3 - 2 y^3 - 6 x y^2 + 1 y^2 + 6 x y + 2 y - 2 x + 3 ), # ( x^2 + 1 ), # ( y^3 - 1 )
# # jython examples for jas. # $Id$ # import sys from jas import Ring, PolyRing, Ideal, PSIdeal, QQ, ZM from jas import startLog, terminate # example from CLO(UAG), 4.4 #R = PolyRing( GF(32003), "x,y,z" ); R = PolyRing(QQ(), "x,y,z") print "Ring: " + str(R) print #automatic: [one,x,y,z] = R.gens(); f1 = x**5 - x * y**6 - z**7 f2 = x * y + y**3 + z**3 f3 = x**2 + y**2 - z**2 L = [f1, f2, f3] #print "L = ", str(L); F = R.ideal(list=L) print "Ideal: " + str(F) print PR = R.powerseriesRing()
# # jython examples for jas. # $Id$ # import sys from java.lang import System from jas import Ring, RF, QQ, PolyRing from jas import terminate, startLog # elementary integration r = PolyRing(QQ(), "x", PolyRing.lex) print "r = " + str(r) rf = RF(r) print "rf = " + str(rf.factory()) [one, x] = rf.gens() print "one = " + str(one) print "x = " + str(x) print #f = 1 / ( 1 + x**2 ); #f = x**2 / ( x**2 + 1 ); #f = 1 / ( x**2 - 2 ); #f = 1 / ( x**3 - 2 ); #f = ( x + 3 ) / ( x**2- 3 * x - 40 );
# # jython examples for jas. # $Id$ # import sys; from java.lang import System from jas import Ring, PolyRing from jas import ZM, QQ, AN, RF, CR from jas import terminate, startLog # polynomial examples: complex factorization via algebraic factorization r = PolyRing( CR(QQ()), "x", PolyRing.lex ); print "Ring: " + str(r); print; [one,I,x] = r.gens(); f1 = x**3 - 2; f2 = ( x - I ) * ( x + I ); f3 = ( x**3 - 2 * I ); #f = f1**2 * f2 * f3; f = f1 * f2 * f3; #f = f1 * f2; #f = f1 * f3; #f = f2 * f3; #f = f3;
# # jython examples for jas. # $Id$ # import sys from jas import PolyRing, QQ, RF from jas import startLog from jas import terminate # Montes JSC 2002, 33, 183-208, example 5.1 # integral function coefficients r = PolyRing(PolyRing(QQ(), "a, b", PolyRing.lex), "u,z,y,x", PolyRing.lex) print "Ring: " + str(r) print #automatic: [one,a,b,u,z,y,x] = r.gens(); print "gens: ", [str(f) for f in r.gens()] print f1 = a * x + 2 * y + 3 * z + u - 6 f2 = x + 3 * y - z + 2 * u - b f3 = 3 * x - a * y + z - 2 f4 = 5 * x + 4 * y + 3 * z + 3 * u - 9 F = [f1, f2, f3, f4] print "F: ", [str(f) for f in F] print
# # jruby examples for jas. # $Id$ # import sys; from jas import SolvableRing, SolvPolyRing, PolyRing, SolvableIdeal from jas import QQ, ZZ, GF, SRF, startLog, terminate # Ore extension solvable polynomial example, Gomez-Torrecillas, 2003 pcz = PolyRing(QQ(),"x,y,z,t", PolyRing.lex); #is automatic: [one,x,y,z,t] = p.gens(); zrelations = [z, y, y * z + x, t, y, y * t + y, t, z, z * t - z ]; print "zrelations: = " + str( [ str(r) for r in zrelations ] ); print; pz = SolvPolyRing(QQ(), "x,y,z,t", PolyRing.lex, zrelations); print "SolvPolyRing: " + str(pz); print; pzq = SRF(pz); print "SolvableQuotientRing: " + str(pzq.ring.toScript); # + ", assoz: " + str(pzq::ring.isAssociative); #print "gens =" + str( [ str(r) for r in pzq.gens() ] );
# # jruby examples for jas. # $Id$ # import sys from jas import SolvableRing, SolvPolyRing, PolyRing, SolvableIdeal from jas import QQ, ZZ, GF, SRF, startLog, terminate # Iterated Ore extension solvable polynomial example, rc = PolyRing(QQ(), "x,y,z,t", PolyRing.lex) #is automatic: [one,x,y,z,t] = rc.gens(); crel = [z, y, y * z + x, t, y, y * t + y, t, z, z * t - z] print "crel: = " + str([str(r) for r in crel]) print rcs = SolvPolyRing(QQ(), "x,y,z,t", PolyRing.lex, crel) #exit(0) rm = PolyRing(rcs, "u,v,w", PolyRing.lex) #is automatic: [one,x,y,z,t,u,v,w] = rm.gens(); mrel = [v, u, u * v + x, w, v, v * w + y, w, u, u * w - z] print "mrel: = " + str([str(r) for r in mrel]) print
# $Id$ # import sys; from jas import PolyRing, ZZ, QQ, RealN, CC, ZM, RF, terminate from edu.jas.root import RealArithUtil from edu.jas.arith import ArithUtil # example for rational and real algebraic numbers # # # continued fractions: r = PolyRing(QQ(),"alpha",PolyRing.lex); print "r = " + str(r); e,a = r.gens(); print "e = " + str(e); print "a = " + str(a); sqrt2 = a**2 - 2; print "sqrt2 = " + str(sqrt2); Qs2r = RealN(sqrt2,[1,[3,2]],a-1); #Qs2r = RealN(sqrt2,[-2,-1],a+1); print "Qs2r = " + str(Qs2r.factory()) + " :: " + str(Qs2r.elem); one,alpha = Qs2r.gens(); print "one = " + str(one); print "alpha = " + str(alpha); cf = Qs2r.contFrac(20);
# # jython examples for jas. # $Id$ # import sys from jas import PolyRing, QQ, RF from jas import startLog from jas import terminate # Montes JSC 2002, 33, 183-208, example 11.2 # integral function coefficients r = PolyRing(PolyRing(QQ(), "f, e, d, c, b, a", PolyRing.lex), "y,x", PolyRing.lex) #r = PolyRing( PolyRing(QQ(),"f, e, d, c, b, a",PolyRing.grad), "y,x", PolyRing.lex ); #r = PolyRing( PolyRing(QQ(),"f, e, d, c, b, a",PolyRing.lex), "y,x", PolyRing.grad ); #r = PolyRing( PolyRing(QQ(),"e, d, c, b, f, a",PolyRing.lex), "y,x", PolyRing.grad ); print "Ring: " + str(r) print #[one,e,d,c,b,f,a,y,x] = r.gens(); #automatic: [one,f,e,d,c,b,a,y,x] = r.gens(); print "gens: ", [str(f) for f in r.gens()] print f1 = x**2 + b * y**2 + 2 * c * x * y + 2 * d * x + 2 * e * y + f f2 = x + c * y + d f3 = b * y + c * x + e
print "r6:", r6 print r7 = one / r6 print "r7:", r7 print s = psr.sin() print "s:", s print r8 = psr.gcd(y, s) print "r8:", r8 print s1 = s.evaluate(QQ(0)) print "s1:", s1 print c = psr.cos() print "c:", c print c1 = c.evaluate(QQ(0)) print "c1:", c1 print s2c2 = s * s + c * c # sin^2 + cos^2 = 1 print "s2c2:", s2c2 print
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 c = CC() print "c:", c c = c.one() print "c:", c c = CC((2, ), (3, ))
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 ------------"; m1 = ZM(19,12345678901234567890); print "m1 = " + str(m1); m2 = m1**2 + 12345678901234567890; print "m2 = " + str(m2); print; print "------- GF = ModInteger ------------";
import sys from jas import Ring, PolyRing, Ideal, QQ, ZZ, GF, ZM, CC from jas import startLog, terminate # trinks 6/7 example # QQ = rational numbers, ZZ = integers, CC = complex rational numbers, GF = finite field #QQ = QQ(); ZZ = ZZ(); CC = CC(); #r = PolyRing( GF(19),"B,S,T,Z,P,W", PolyRing.lex); #r = PolyRing( GF(1152921504606846883),"B,S,T,Z,P,W", PolyRing.lex); # 2^60-93 #r = PolyRing( GF(2**60-93),"B,S,T,Z,P,W", PolyRing.lex); #r = PolyRing( CC(),"B,S,T,Z,P,W", PolyRing.lex); #r = PolyRing( ZZ(),"B,S,T,Z,P,W", PolyRing.lex); # not for parallel r = PolyRing(QQ(), "B,S,T,Z,P,W", PolyRing.lex) print "Ring: " + str(r) print # sage like: with generators for the polynomial ring #[one,I,B,S,T,Z,P,W] = r.gens(); # is automaticaly included #[one,B,S,T,Z,P,W] = r.gens(); # is automaticaly included f1 = 45 * P + 35 * S - 165 * B - 36 f2 = 35 * P + 40 * Z + 25 * T - 27 * S f3 = 15 * W + 25 * S * P + 30 * Z - 18 * T - 165 * B**2 f4 = -9 * W + 15 * T * P + 20 * S * Z f5 = P * W + 2 * T * Z - 11 * B**3 f6 = 99 * W - 11 * B * S + 3 * B**2 f7 = 10000 * B**2 + 6600 * B + 2673
def g2(i): #print "2*QQ(i) = " + str(QQ(2)*QQ(i)) return 2*QQ(i);
# jython examples for jas. # $Id$ # import sys; from jas import PolyRing, QQ from jas import startLog, terminate # Raksanyi & Walter example # integral/rational function coefficients #r = Ring( "RatFunc(a1, a2, a3, a4) (x1, x2, x3, x4) L" ); #r = Ring( "IntFunc(a1, a2, a3, a4) (x1, x2, x3, x4) L" ); r = PolyRing( PolyRing(QQ(),"a1, a2, a3, a4",PolyRing.lex), "x1, x2, x3, x4", PolyRing.lex); 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.paramideal( ps ); print "ParamIdeal: " + str(f);
def g2(i): #print "QQ(i.0)*QQ(i.1) = " + str(QQ(i.0)*QQ(i.1)) return QQ(i.getVal(0)) * QQ(i.getVal(1));
# # jython examples for jas. # $Id$ # #from java.lang import System from jas import WordRing, WordPolyRing, WordPolyIdeal, PolyRing, SolvPolyRing from jas import terminate, startLog from jas import QQ, ZZ, GF, ZM # non-commutative polynomial examples: solvable polynomials example #r = WordPolyRing(QQ(),"a,b,e1,e2,e3"); r = WordPolyRing(QQ(), "a,b,e,f,g") print "WordPolyRing: " + str(r) print [one, a, b, e, f, g] = r.gens() print "one = " + str(one) print "a = " + str(a) print "b = " + str(b) print "e = " + str(e) print "f = " + str(f) print "g = " + str(g) print r1 = g * e - (e * g - e) r2 = g * f - (f * g - f) r3 = e * a - a * e r4 = e * b - b * e
# # jython examples for jas. # $Id$ # import sys from java.lang import System from jas import Ring, PolyRing, QQ, DD from jas import terminate, startLog # polynomial examples: real roots over Q r = PolyRing(QQ(), "I,x,y,z", PolyRing.lex) print "Ring: " + str(r) print #automatic: [one,I,x,y,z] = r.gens(); f1 = z - x - y * I f2 = I**2 + 1 #f3 = z**3 - 2; f3 = z**3 - 2 * I print "f1 = ", f1 print "f2 = ", f2 print "f3 = ", f3 print
# # jython examples for jas. # $Id$ # import sys from java.lang import System from jas import Ring, PolyRing, QQ, DD, EF from jas import terminate, startLog # polynomial examples: real root tower over Q r = EF(QQ()).realExtend("q", "q^3 - 3", "[1,2]").realExtend( "w", "w^2 - q", "[1,2]").realExtend("s", "s^5 - 2", "[1,2]").polynomial("x").build() print "Ring: " + str(r) print #automatic: [one,q,w,s,x] = r.gens(); print "one = " + str(one) print "q = " + str(q) print "w = " + str(w) print "s = " + str(s) print "x = " + str(x) print f = x**2 - w * s
# # jython examples for jas. # $Id$ # from java.lang import System from jas import SolvableRing, SolvPolyRing, PolyRing from jas import QQ, startLog, SRC, SRF # Ore extension solvable polynomial example, Gomez-Torrecillas, 2003 pcz = PolyRing(QQ(), "x,y,z") #is automatic: [one,x,y,z] = pcz.gens(); zrelations = [z, y, y * z + x] print "zrelations: = " + str([str(f) for f in zrelations]) print pz = SolvPolyRing(QQ(), "x,y,z", PolyRing.lex, zrelations) print "SolvPolyRing: " + str(pz) print pzq = SRF(pz) print "SolvableQuotientRing: " + str(pzq.ring.toScript()) # + ", assoz: " + str(pzq.ring.isAssociative()); #print "gens =" + str([ str(f) for f in pzq.ring.generators() ]); print pct = PolyRing(pzq, "t")
# jython examples for jas. # $Id$ # import sys; from java.lang import System from java.lang import Integer from jas import Ring, PolyRing from jas import terminate from jas import startLog from jas import QQ, DD # polynomial examples: complex roots over Q for zero dimensional ideal `cyclic5' r = PolyRing(QQ(),"a,b,c,d,e",PolyRing.lex); print "Ring: " + str(r); print; #is automatic: [one,a,b,c,d,e] = r.gens(); f1 = a + b + c + d + e; f2 = a*b + b*c + c*d + d*e + e*a; f3 = a*b*c + b*c*d + c*d*e + d*e*a + e*a*b; f4 = a*b*c*d + b*c*d*e + c*d*e*a + d*e*a*b + e*a*b*c; f5 = a*b*c*d*e - 1; print "f1 = ", f1; print "f2 = ", f2; print "f3 = ", f3; print "f4 = ", f4;
# # jython examples for jas. from jas import PolyRing, QQ, Module #, SubModule # module example p = PolyRing(QQ(),"u,v,l", PolyRing.lex); #r = Module( "Rat(u,v,l) L", cols=4 ); r = Module( "", p, cols=4 ); print "Module: " + str(r); print; G = r.gens(); print "gens() = ", [str(e) for e in G]; L = [ e.elem.val for e in G ] print "gens() = ", [str(e) for e in L]; M = r.submodul( list=L ); print "M = ", M; P = M.mset.getPolynomialList(); print "P = ", P.toScript(); print "M.isGB(): ", M.isGB();