File: gcd.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 (64 lines) | stat: -rw-r--r-- 1,049 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
62
63
64
#
# jruby examples for jas.
# $Id$
#

require "examples/jas"

# polynomial examples: gcd

#r = PolyRing.new( ZM(1152921504606846883), "(x,y,z)", PolyRing.lex );
#r = PolyRing.new( CC(), "(x,y,z)", PolyRing.lex );
#r = PolyRing.new( ZZ(), "(x,y,z)", PolyRing.lex );
r = PolyRing.new( QQ(), "x,y,z", PolyRing.lex );
puts "Ring: " + str(r);
puts;

#one,x,y,z = r.gens();

a = r.random();
b = r.random();
c = r.random().abs();
#c = 1; 
#a = 0;

puts "a = " + str(a);
puts "b = " + str(b);
puts "c = " + str(c);
puts;

ac = a * c;
bc = b * c;

puts "ac = " + str(ac);
puts "bc = " + str(bc);
puts;

#startLog();

t = System.currentTimeMillis();
#d = r.gcd(ac,bc);
d = ac.gcd(bc);
t = System.currentTimeMillis() - t;

#d = d.monic();
puts "d = " + str(d);
puts "d = " + str(d.monic());
puts;

puts "gcd time = " + str(t) + " milliseconds" ;

if r.ring.coFac.isField()
   m = d % c;
   #puts "m = " + str(m);
   #puts;
   if m.isZERO()
      puts "isGcd(c,d): true" ;
   else
      puts "isGcd(c,d): " + str(m);
   end
end
puts;

#startLog();
terminate();