File: arith.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 (100 lines) | stat: -rw-r--r-- 1,504 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# jruby examples for jas.
# $Id$
#

require "examples/jas"

# example for rational and complex numbers
#
#

zn = ZZ(7);
puts "zn:   " + str(zn);
puts "zn^2: " + str(zn*zn);
puts;

x = 10000000000000000000000000000000000000000000000000;
puts "x:    " + str(x);
rn = QQ(2*x,4*x);
puts "rn:   " + str(rn);
puts "rn^2: " + str(rn*rn);
puts;

rn = QQ(6/4);
puts "rn:   " + str(rn);
puts "rn^2: " + str(rn*rn);
puts "1/rn: " + str(1/rn);
puts;


c = CC();
puts "c:   " + str(c);
c = c.one();
puts "c:   " + str(c);
c = CC(2,3);
puts "c:   " + str(c);
puts "c^5: " + str(c**5 + c.one());
puts;

c = CC( 2,rn );
puts "c:   " + str(c);
puts "1/c: " + str(1/c);
puts;

zm = ZM(19,11);
puts "zm:   " + str(zm);
puts "zm^2: " + str(zm*zm);
puts "1/zm: " + str(1/zm);
#puts "zm.ring: " + str(zm.ring.toScript());
puts;


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

# sage like: with generators for the polynomial ring
one,x,y = r.gens();
zero = r.zero();

begin
    f = RF(r);
rescue
    f = None;
end
puts "f: " + str(f);

d = x**2 + 5 * x - 6;
puts "d: " + str(d);
f = RF(r,d);
puts "f: " + str(f);

n = d*d + y + 1;
f = RF(r,d,n);
puts "f: " + str(f);
puts;

# beware not to mix expressions
f = f**2 - f;
puts "f^2-f: " + str(f);
puts;

f = f/f;
puts "f/f: " + str(f);

f = RF(r,d,one);
puts "f: " + str(f);

f = RF(r,zero);
puts "f: " + str(f);

f = RF(r,d,y); 
puts "f: " + str(f);

puts "one:  " + str(f.one());
puts "zero: " + str(f.zero());
puts;

terminate();
#sys.exit();