File: roots_complex.rb

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 (61 lines) | stat: -rw-r--r-- 1,225 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
53
54
55
56
57
58
59
60
61
#
# jruby examples for jas.
# $Id$
#

require "examples/jas"

# polynomial examples: complex roots over Q

r = PolyRing.new(CR(QQ()),"x",PolyRing.lex);
puts "Ring: " + str(r);
puts;

one,I,x = r.gens();
puts "one = " + one.to_s;
puts "I   = " + I.to_s;
puts "x   = " + x.to_s;
puts;


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;

puts "f = " + f.to_s;
puts;

startLog();

t = System.currentTimeMillis();
#rr = r.complexRoots(f);
rr = f.complexRoots();
t = System.currentTimeMillis() - t;
#puts "rr = " + str(rr);
puts "rr = " + str(rr.map{ |a| str(a.elem.ring.getRoot()) }.join(",\n ")); 
puts "complex roots time = " + str(t) + " milliseconds";
puts

#eps = QQ(1,10) ** (BigDecimal::DEFAULT_PRECISION-3);
eps = QQ(1,10) ** 10;
puts "eps = " + str(eps);

t = System.currentTimeMillis();
#rr = r.complexRoots(f,eps);
rr = f.complexRoots(eps);
t = System.currentTimeMillis() - t;
#puts "rr = ", [ str(r) for r in rr ];
puts "rr = " + str(rr.map{ |a| str(a.elem.decimalMagnitude()) }.join(",\n ")); 
puts "complex roots refinement time = " + str(t) + " milliseconds";
puts

#startLog();
terminate();