File: squarefree.py

package info (click to toggle)
jas 2.7.200-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,732 kB
  • sloc: java: 164,370; python: 14,882; ruby: 14,509; xml: 583; makefile: 545; sh: 349
file content (52 lines) | stat: -rw-r--r-- 939 bytes parent folder | download
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
#
# 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;

f = a**2 * b**3 * c;

print "a = ", a;
print "b = ", b;
print "c = ", c;
print "f = ", f;
print;

t = System.currentTimeMillis();
#F = r.squarefreeFactors(f);
F = f.squarefreeFactors();
t = System.currentTimeMillis() - t;
print "factors:";
print ", ".join([ str(k)+"**"+str(v) for k,v in F.items() ] );
print
print "f == prod(F): " + str(f == reduce(operator.mul, [ k**v for k,v in F.items()]))
print
print "factor time =", t, "milliseconds";

startLog();
terminate();