1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#
# jython examples for jas.
# $Id$
#
import sys;
from java.lang import System
from jas import PolyRing, QQ, DD, CR
from jas import terminate, startLog
# polynomial examples: complex roots over Q
#r = Ring( "Rat(x) L" );
#r = Ring( "Q(x) L" );
r = PolyRing( CR(QQ()), "x", PolyRing.lex );
print "Ring: " + str(r);
print;
#automatic: [one,I,x] = r.gens();
print "one = ", one;
print "I = ", I;
print "x = ", x;
print;
f1 = x**3 - 2;
f2 = ( x - I ) * ( x + I ) * ( x - 2 * I ) * ( x + (1,2) * I );
f3 = ( x**3 - 2 * I );
#f = f1 * f2 * f3;
#f = f1 * f2;
#f = f1 * f3;
#f = f2 * f3;
f = f2;
print "f = ", f;
print;
startLog();
t = System.currentTimeMillis();
#R = r.complexRoots(f);
R = f.complexRoots();
t = System.currentTimeMillis() - t;
#print "R = ", [ a.elem.ring for a in R ];
print "R = ", [ a.elem.ring.getRoot() for a in R ];
print "complex roots time =", t, "milliseconds";
print
#terminate();
#sys.exit();
#eps = QQ(1,10) ** (DD().elem.DEFAULT_PRECISION-3); # not too big
eps = QQ(1,10) ** 10;
print "eps = ", eps;
t = System.currentTimeMillis();
R = r.complexRoots(f,eps);
t = System.currentTimeMillis() - t;
#print "R = ", [ str(a) for a in R ];
print "R = ", [ a.elem.decimalMagnitude() for a in R ];
print "complex root refinement time =", t, "milliseconds";
print
#startLog();
terminate();
|