Beispiel #1
0
 def testRingZM(self):
     r = PolyRing( GF(17), "(t,x)", Order.INVLEX );
     self.assertEqual(str(r),'PolyRing(GFI(17),"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 + 16 * t**2 * x**3 + 10 * x**3 + 9 * t**4 * x**2 + 10 * t**2 * x**2 + 4 * x**2 + 3 * t**6 * x + t**4 * x + 11 * x + 2 * t**8 + 13 * t**6 + 13 * t**4 + 6 * t**2 + 3 )');
#
# jython examples for jas.
# $Id$
#

from java.lang import System

from jas import PolyRing, ZM, GF, QQ
from jas import terminate, startLog

# polynomial examples: absolute factorization over Z_p

#r = PolyRing(GF(19),"x",PolyRing.lex );
#r = PolyRing(GF(23),"x",PolyRing.lex );
r = PolyRing(GF(1152921504606846883), "(x)", PolyRing.lex)
print "Ring: " + str(r)
print

#[one,x] = r.gens();

#f = x**4 - 1;
#f = x**3 + 1;
f = x**3 - x - 1

print "f = ", f
print

startLog()

t = System.currentTimeMillis()
#G = r.squarefreeFactors(f);
# $Id$
#

import sys

from java.lang import System

from jas import Ring, PolyRing, QQ, ZM, GF, RF, AN
from jas import terminate, startLog, noThreads

# polynomial examples: ideal radical decomposition, modified from example 8.16 in GB book

# noThreads(); # must be called very early

prime = 5
cf = GF(prime)
#cf = QQ();

ca = PolyRing(cf, "a", PolyRing.lex)
#print "ca = " + str(ca);
[ea, aa] = ca.gens()
print "ea   = " + str(ea)
print "aa   = " + str(aa)
print

#!#roota = aa**prime + 2;
roota = aa**2 + 2
print "roota = " + str(roota)
Q3a = AN(roota, field=True)
print "Q3a   = " + str(Q3a.factory())
import sys;

from jas import SolvableRing, SolvPolyRing, PolyRing, SolvableIdeal
from jas import QQ, ZZ, GF, RF, startLog, terminate 

startLog();

# solvable module example

#mod=17; 
mod=32003; 
#mod=536870909; 
#mod=1152921504606846883;

coeff = GF(mod)
#coeff = QQ()

p = PolyRing( 
        RF(PolyRing(coeff,"b1,c1",PolyRing.lex)), 
        "E,D1,D2,D3",PolyRing.grad);
print "PolyRing: " + str(p);
print;

relations = [
 ( D3 ), ( D1 ), ( D1 * D3 -      c1 * E + b1      * E ),
 ( D3 ), ( D2 ), ( D2 * D3 -           E +           E ),
 ( D2 ), ( D1 ), ( D1 * D2 -      c1 * E + b1      * E )
];

print "relations: = " + str([ str(f) for f in relations ]);
#
# jython examples for jas.
# $Id$
#

from java.lang import System

from jas import Ring, PolyRing, QQ, ZM, GF
from jas import terminate, startLog

# polynomial examples: ideal radical decomposition, dim > 0, char p separable

r = PolyRing(GF(5), "x,y,z", PolyRing.lex)
print "Ring: " + str(r)
print

#automatic: [one,x,y,z] = r.gens();

#f1 = (x**2 - 5)**2;
#f1 = (y**10 - x**5)**3;
f2 = y**6 + 2 * x * y**4 + 3 * x**2 * y**2 + 4 * x**3
f2 = f2**5
f3 = z**10 - x**5

f4 = (y**2 - x)**3

#print "f1 = ", f1;
print "f2 = ", f2
print "f3 = ", f3
#print "f4 = ", f4;
print
## 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, ZM, GF
from jas import startLog, terminate

# Hawes & Gibson example 2
# modular rational function coefficients, token parsing

#r = Ring( "ModFunc 17 (a, c, b) (y2, y1, z1, z2, x) G" );
r = PolyRing( PolyRing(GF(17),"a, c, b",PolyRing.lex), "y2, y1, z1, z2, x", PolyRing.grad );
print "Ring: " + str(r);
print;

ps = """
(
 ( x + 2 y1 z1 + { 3 a } y1^2 + 5 y1^4 + { 2 c } y1 ),
 ( x + 2 y2 z2 + { 3 a } y2^2 + 5 y2^4 + { 2 c } y2 ), 
 ( 2 z2 + { 6 a } y2 + 20 y2^3 + { 2 c } ), 
 ( 3 z1^2 + y1^2 + { b } ), 
 ( 3 z2^2 + y2^2 + { b } ) 
) 
""";

f = r.ideal( ps );
print "Ideal: " + str(f);
Beispiel #7
0
#
# jython examples for jas.
# $Id$
#

from java.lang import System

from jas import GF, PolyRing
from jas import terminate, startLog

# polynomial examples: factorization over Z_p

#r = Ring( "Mod 1152921504606846883 (x) L" );
#r = Ring( "Mod 19 (x) L" );
r = PolyRing( GF(19), "x", PolyRing.lex );
print "Ring: " + str(r);
print;

#[one,x] = r.gens();

#f = x**15 - 1;
#f = x * ( x + 1 )**2 * ( x**2 + x + 1 )**3;
#f = x**6 - 3 * x**5 + x**4 - 3 * x**3 - x**2 - 3 * x+ 1;
#f = x**(3*11*11) + 3 * x**(2*11*11) - x**(11*11);
#f = x**(3*11*11*11) + 3 * x**(2*11*11*11) - x**(11*11*11);
#f = (x**2+1)*(x-3)*(x-5)**3;
#f = x**4 + 1;
#f = x**12 + x**9 + x**6 + x**3 + 1;
#f = x**24 - 1;
#f = x**20 - 1;
#f = x**22 - 1;
Beispiel #8
0
#
# jython examples for jas.
# $Id$
#

import sys

from java.lang import System

from jas import Ring, PolyRing
from jas import ZM, QQ, AN, RF, GF
from jas import terminate, startLog

# polynomial examples: factorization over Z_p(sqrt(2))(x)(sqrt(x))[y]

Q = PolyRing(GF(5), "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)
Beispiel #9
0
 - 91/800 A46^2 U3^3 - 5887/200000 A46 U3^3 
 - 343/128000 U3^3 ) 
) 
"""

f = r.ideal(ps)
print "Ideal: " + str(f)
print

fi = f.toInteger()
print "Ideal: " + str(fi)
print
#                    "1152921504606846883"
#mf = ModIntegerRing( str(2**60-93), True );
#mf = ModIntegerRing( str(19), True );
mf = GF(2**60 - 93)
fm = fi.toModular(mf)
print "Ideal: " + str(fm)

#sys.exit();

rm = fm.GB()
#print "seq Output:", rm;
#print;

#rg = f.GB();
#print "seq Output:", rg;
#print;

#rgm = rg.toInteger().toModular(mf);
#print "seq Output:", rgm;
Beispiel #10
0
#
# jython examples for jas.
# $Id$
#

from java.lang import System

from jas import PolyRing, QQ, ZM, RF, GF
from jas import terminate, startLog

# polynomial examples: squarefree: characteristic p, infinite

r = PolyRing(RF(PolyRing(GF(5), "u, v", PolyRing.lex)), "x y z", PolyRing.lex)
print "r = " + str(r)

#automatic: [one,u,v,x,y,z] = r.gens();
print "one   = " + str(one)
print "u     = " + str(u)
print "v     = " + str(v)
print "x     = " + str(x)
print "y     = " + str(y)
print "z     = " + str(z)

print "Ring: " + str(r)
print

a = r.random(k=1, l=3)
b = r.random(k=1, l=3)
c = r.random(k=1, l=3)

if a.isZERO():
#
# jython examples for jas.
# $Id$
#

from java.lang import System

from jas import PolyRing, QQ, ZM, ZZ, GF
from jas import terminate, startLog

# polynomial examples: squarefree: characteristic 0

#r = PolyRing(PolyRing(QQ(),"u,v",PolyRing.lex),"x, y",PolyRing.lex)
#r = PolyRing(PolyRing(ZZ(),"u,v",PolyRing.lex),"x, y",PolyRing.lex)
r = PolyRing(PolyRing(GF(7), "u,v", PolyRing.lex), "x, y", PolyRing.lex)
print "Ring: " + str(r)
print

#automatic: [one,u,v,x,y] = r.gens();

a = r.random(k=1, l=3)
b = r.random(k=1, l=3)
c = r.random(k=1, l=3)

if a.isZERO():
    a = x
if b.isZERO():
    b = y
if c.isZERO():
    c = y
# $Id$
#

import sys;

from jas import QQ, GF, PolyRing
from jas import startLog

# example cyclic6, optimize term order 
# optimal is no change

#r = Ring( "Rat (x6,x5,x4,x3,x2,x1)  G" );
#r = Ring( "Mod 19 (x6,x5,x4,x3,x2,x1)  G" );
#r = Ring( "Mod 3 (x6,x5,x4,x3,x2,x1) G" );
#r = PolyRing( QQ(), "(x6,x5,x4,x3,x2,x1)", PolyRing.grad );
r = PolyRing( GF(3), "(x6,x5,x4,x3,x2,x1)", PolyRing.grad );
print "Ring: " + str(r);
print;

ps = """
(
x1 + x2 + x3 + x4 + x5 + x6,
x1*x2 + x1*x6 + x2*x3 + x3*x4 + x4*x5 + x5*x6,
x1*x2*x3 + x1*x2*x6 + x1*x5*x6 + x2*x3*x4 + x3*x4*x5 + x4*x5*x6,
x1*x2*x3*x4 + x1*x2*x3*x6 + x1*x2*x5*x6 + x1*x4*x5*x6 + x2*x3*x4*x5 + x3*x4*x5*x6,
x1*x2*x3*x4*x5 + x1*x2*x3*x4*x6 + x1*x2*x3*x5*x6 + x1*x2*x4*x5*x6 + x1*x3*x4*x5*x6 + x2*x3*x4*x5*x6,
x1*x2*x3*x4*x5*x6 - 1
)
""";

F = [ x1 + x2 + x3 + x4 + x5 + x6,
#
# jython examples for jas.
# $Id$
#

from java.lang import System

from jas import PolyRing, QQ, ZM, AN, GF
from jas import terminate, startLog

# polynomial examples: squarefree: characteristic p, finite algebraic

ar = PolyRing(GF(7), "i", PolyRing.lex)
#automatic: [one,i] = ar.gens();

# irred for 7, 11, 19
r = PolyRing(AN(i**2 + 1, field=True), "x, y, z", PolyRing.lex)
print "Ring: " + str(r)
print

#automatic: [one,i,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():
Beispiel #14
0
#
# jython examples for jas.
# $Id$
#

import sys

from java.lang import System

from jas import PolyRing, ZM, QQ, RF, GF
from jas import terminate, startLog

# polynomial examples: factorization over Z_p, with p-th root

p = 5
cr = PolyRing(GF(p), "u", PolyRing.lex)
print "Ring cr: " + str(cr)

#[one,u] = cr.gens();

fu = (u**2 + u + 1)**p
print "fu = ", fu
print

t = System.currentTimeMillis()
G = cr.squarefreeFactors(fu)
t = System.currentTimeMillis() - t
#print "G = ", G; #.toScript();
print "factor time =", t, "milliseconds"
for h, i in G.iteritems():
    print "h**i = (", h, ")**" + str(i)
# jython examples for jas.
# $Id$
#

import sys

from java.lang import System

from jas import Ring, PolyRing, QQ, ZM, RF, GF
from jas import terminate, startLog, noThreads

# polynomial examples: ideal radical decomposition, inseparable cases, dim > 0

#noThreads(); # must be called very early

cr = PolyRing(GF(5), "c", PolyRing.lex)
print "coefficient Ring: " + str(cr)
rf = RF(cr)
print "coefficient quotient Ring: " + str(rf.ring)

r = PolyRing(rf, "x,y,z", PolyRing.lex)
print "Ring: " + str(r)
print

#automatic: [one,c,x,y,z] = r.gens();
print one, c, x, y, z

#sys.exit();

#f1 = (x**2 - 5)**2;
#f1 = (y**10 - x**5)**3;
Beispiel #16
0
import sys

from jas import Ring, PolyRing, RF, ZZ, ZM, GF
from jas import startLog, terminate

#startLog();

# Lewis example
# integral function coefficients

#r = Ring( "IntFunc(a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3) (t1,t2,t3) G" );
#r = Ring( "RatFunc(a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3) (t1,t2,t3) G" );
#r = PolyRing( RF(PolyRing(ZZ(),"a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3",PolyRing.lex)), "t1,t2,t3", PolyRing.grad );
#r = PolyRing( RF(PolyRing(GF(163),"a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3",PolyRing.grad)), "t1,t2,t3", PolyRing.grad );
r = PolyRing(
    PolyRing(GF(163), "a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3",
             PolyRing.grad), "t1,t2,t3", PolyRing.grad)
#no: r = PolyRing( RF(PolyRing(GF(5),"a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3",PolyRing.grad)), "t1,t2,t3", PolyRing.grad );
print "Ring: " + str(r)
print

ps = """
(
( { a1 } * t1^2 * t2^2 + { b1 } * t1^2 + { 2 c1 } * t1 * t2 + { d1 } * t2^2 + { e1 } ),
( { a2 } * t2^2 * t3^2 + { b2 } * t2^2 + { 2 c2 } * t2 * t3 + { d2 } * t3^2 + { e2 } ),
( { a3 } * t1^2 * t3^2 + { b3 } * t1^2 + { 2 c3 } * t1 * t3 + { d3 } * t3^2 + { e3 } )
) 
"""

#a1 = e2 + s22
#+ s27
Beispiel #17
0
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 ------------";
m1 = GF(19,12345678901234567890);
print "m1 = " + str(m1);
m2 = m1**2 + 12345678901234567890;
print "m2 = " + str(m2);
print;


print "------- DD = BigDecimal ------------";
d1 = DD(12345678901234567890);
print "d1 = " + str(d1);
d2 = (1/d1)**2;
print "d2 = " + str(d2);
print;


print "------- CC = BigComplex ------------";
Beispiel #18
0
from basic_sigbased_gb import ggv_first_implementation, arris_algorithm, f5z

from staggered_linear_basis import staglinbasis

from edu.jas.gb import Cyclic

# cyclic examples

knum = 5
tnum = 2

k = Cyclic(knum)
#r = Ring( "", k.ring );
#r = PolyRing( GF(23), k.ring.vars,  Order.IGRLEX );
r = PolyRing(GF(32003), k.ring.vars, Order.IGRLEX)
#r = PolyRing( GF(536870909), k.ring.vars,  Order.IGRLEX );
#r = PolyRing( GF(4294967291), k.ring.vars,  Order.IGRLEX );
#r = PolyRing( GF(9223372036854775783), k.ring.vars,  Order.IGRLEX );
#r = PolyRing( GF(170141183460469231731687303715884105727), k.ring.vars,  Order.IGRLEX );

print "Ring: " + str(r)
print

ps = k.polyList()
#ps = k.cyclicPolys();
print "ps = " + str(ps)

f = r.ideal(ps)
print "Ideal: " + str(f)
print
#
# jython examples for jas.
# $Id$
#

from java.lang import System

from jas import PolyRing, ZM, GF
from jas import terminate, startLog

# system biology examples: GB in Z_2
# see: Informatik Spektrum, 2009, February,
# Laubenbacher, Sturmfels: Computer Algebra in der Systembiologie

r = PolyRing(GF(2),"M, B, A, L, P",PolyRing.lex);
print "PolyRing: " + str(r);
print;

#automatic: [one,M,B,A,L,P] = r.gens();

f1 = M - A;
f2 = B - M;
f3 = A - A - L * B - A * L * B;
f4 = P - M;
f5 = L - P - L - L * B - L * P - L * B * P;
## t1 = M - 1;
## t2 = B - 1;
## t3 = A - 1;
## t4 = L - 1;
## t5 = P - 1;
#
Beispiel #20
0
#
# jython examples for jas.
# $Id$
#

from jas import Ring, PolyRing, GF

# logic example from Kreutzer JdM 2008

#r = Ring( "Mod 2 (a,f,p,u) G" );
r = PolyRing(GF(2), "(a,f,p,u)", PolyRing.grad)
print "Ring: " + str(r)
print

ks = """
(
 ( a^2 - a ),
 ( f^2 - f ),
 ( p^2 - p ),
 ( u^2 - u )
)
"""

ps = """
(
 ( p f + p ),
 ( p u + p + u + 1 ),
 ( a + u + 1 ),
 ( a + p + 1 )
)
"""
print "s  = " + str(s)
print

Fi = ri.ideal(list=[f1, f2])
print "Fi = " + str(Fi)
print

#not implemented:
#Gi = Fi.GB();
#print "Gi = " + str(Gi);
#print "isGB(Gi) = " + str(Gi.isGB());
#print;

#exit(0);

rp = WordPolyRing(GF(23), "x,y")
print "WordPolyRing: " + str(rp)
print

[one, x, y] = rp.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
from java.lang import System

from jas import WordRing, WordPolyRing, WordIdeal
from jas import terminate, startLog
from jas import QQ, ZZ, GF, ZM

# non-commutative polynomial examples: C_4_1_7_X example

#r = WordPolyRing(QQ,"x4,x3,x2,x1");
#r = WordPolyRing(GF(19),"x4,x3,x2,x1");

#r = WordPolyRing(QQ(),"x1,x2,x3,x4");
#r = WordPolyRing(ZZ(),"x1,x2,x3,x4");
#r = WordPolyRing(GF(19),"x1,x2,x3,x4");
#r = WordPolyRing(GF(32003),"x1,x2,x3,x4");
r = WordPolyRing(GF(2**29 - 3), "x1,x2,x3,x4")
#r = WordPolyRing(GF(2**63-25),"x1,x2,x3,x4");
#r = WordPolyRing(GF(170141183460469231731687303715884105727),"x1,x2,x3,x4");
#r = WordPolyRing(GF(259117086013202627776246767922441530941818887553125427303974923161874019266586362086201209516800483406550695241733194177441689509238807017410377709597512042313066624082916353517952311186154862265604547691127595848775610568757931191017711408826252153849035830401185072116424747461823031471398340229288074545677907941037288235820705892351068433882986888616658650280927692080339605869308790500409503709875902119018371991620994002568935113136548829739112656797303241986517250116412703509705427773477972349821676443446668383119322540099648994051790241624056519054483690809616061625743042361721863339415852426431208737266591962061753535748892894599629195183082621860853400937932839420261866586142503251450773096274235376822938649407127700846077124211823080804139298087057504713825264571448379371125032081826126566649084251699453951887789613650248405739378594599444335231188280123660406262468609212150349937584782292237144339628858485938215738821232393687046160677362909315071),"x1,x2,x3,x4");
print "WordPolyRing: " + str(r)
print

#one,x4,x3,x2,x1 = r.gens();
one, x1, x2, x3, x4 = r.gens()
print "one = " + str(one)
print "x4 = " + str(x4)
print "x3 = " + str(x3)
print "x2 = " + str(x2)
print "x1 = " + str(x1)
print