algebra 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +21 -0
- data/README-ja.txt +60 -0
- data/README.md +61 -0
- data/Rakefile +43 -0
- data/algebra.gemspec +33 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc-ja/README-ja.html +69 -0
- data/doc-ja/README-ja.rd +60 -0
- data/doc-ja/README.html +0 -0
- data/doc-ja/README.rd +0 -0
- data/doc-ja/algebra-ja.html +66 -0
- data/doc-ja/algebra-ja.rd +60 -0
- data/doc-ja/algebraic-equation-ja.html +36 -0
- data/doc-ja/algebraic-equation-ja.rd +26 -0
- data/doc-ja/algebraic-extension-field-ja.html +122 -0
- data/doc-ja/algebraic-extension-field-ja.rd +118 -0
- data/doc-ja/algebraic-parser-ja.html +87 -0
- data/doc-ja/algebraic-parser-ja.rd +95 -0
- data/doc-ja/changes.html +161 -0
- data/doc-ja/changes.rd +119 -0
- data/doc-ja/elementary-divisor-ja.html +56 -0
- data/doc-ja/elementary-divisor-ja.rd +45 -0
- data/doc-ja/euclidian-ring-ja.html +78 -0
- data/doc-ja/euclidian-ring-ja.rd +69 -0
- data/doc-ja/finite-group-ja.html +285 -0
- data/doc-ja/finite-group-ja.rd +276 -0
- data/doc-ja/finite-map-ja.html +224 -0
- data/doc-ja/finite-map-ja.rd +227 -0
- data/doc-ja/finite-set-ja.html +393 -0
- data/doc-ja/finite-set-ja.rd +408 -0
- data/doc-ja/index-ja.html +113 -0
- data/doc-ja/index-ja.rd +112 -0
- data/doc-ja/jordan-form-ja.html +106 -0
- data/doc-ja/jordan-form-ja.rd +99 -0
- data/doc-ja/localized-ring-ja.html +121 -0
- data/doc-ja/localized-ring-ja.rd +131 -0
- data/doc-ja/m-polynomial-ja.html +542 -0
- data/doc-ja/m-polynomial-ja.rd +596 -0
- data/doc-ja/matrix-algebra-ja.html +686 -0
- data/doc-ja/matrix-algebra-ja.rd +727 -0
- data/doc-ja/matrix-algebra-triplet-ja.html +124 -0
- data/doc-ja/matrix-algebra-triplet-ja.rd +129 -0
- data/doc-ja/permutation-group-ja.html +159 -0
- data/doc-ja/permutation-group-ja.rd +151 -0
- data/doc-ja/polynomial-converter-ja.html +64 -0
- data/doc-ja/polynomial-converter-ja.rd +54 -0
- data/doc-ja/polynomial-ja.html +446 -0
- data/doc-ja/polynomial-ja.rd +473 -0
- data/doc-ja/residue-class-ring-ja.html +112 -0
- data/doc-ja/residue-class-ring-ja.rd +113 -0
- data/doc-ja/sample-algebraic-equation01.rb.v.rd +11 -0
- data/doc-ja/sample-algebraic-equation02.rb.v.rd +11 -0
- data/doc-ja/sample-algebraic-root01.rb.v.rd +20 -0
- data/doc-ja/sample-algebraicfield01.rb.v.rd +26 -0
- data/doc-ja/sample-algebraicfield02.rb.v.rd +15 -0
- data/doc-ja/sample-cayleyhamilton01.rb.v.rd +14 -0
- data/doc-ja/sample-diagonalization01.rb.v.rd +48 -0
- data/doc-ja/sample-divmod01.rb.v.rd +17 -0
- data/doc-ja/sample-elementary-divisor01.rb.v.rd +48 -0
- data/doc-ja/sample-factorize01.rb.v.rd +11 -0
- data/doc-ja/sample-factorize02.rb.v.rd +13 -0
- data/doc-ja/sample-factorize03.rb.v.rd +14 -0
- data/doc-ja/sample-factorize04.rb.v.rd +14 -0
- data/doc-ja/sample-factorize05.rb.v.rd +53 -0
- data/doc-ja/sample-galois-group01.rb.v.rd +27 -0
- data/doc-ja/sample-gaussian-elimination01.rb.v.rd +19 -0
- data/doc-ja/sample-geometry01.rb.v.rd +33 -0
- data/doc-ja/sample-geometry02.rb.v.rd +34 -0
- data/doc-ja/sample-geometry03.rb.v.rd +45 -0
- data/doc-ja/sample-geometry04.rb.v.rd +33 -0
- data/doc-ja/sample-geometry07.rb.v.rd +62 -0
- data/doc-ja/sample-groebner01.rb.v.rd +13 -0
- data/doc-ja/sample-groebner02.rb.v.rd +18 -0
- data/doc-ja/sample-groebner03.rb.v.rd +19 -0
- data/doc-ja/sample-group01.rb.v.rd +21 -0
- data/doc-ja/sample-jordan-form01.rb.v.rd +56 -0
- data/doc-ja/sample-jordanform01.rb.v.rd +55 -0
- data/doc-ja/sample-lagrange-multiplier01.rb.v.rd +35 -0
- data/doc-ja/sample-m-factorize01.rb.v.rd +15 -0
- data/doc-ja/sample-m-factorize02.rb.v.rd +12 -0
- data/doc-ja/sample-m-polynomial01.rb.v.rd +10 -0
- data/doc-ja/sample-map01.rb.v.rd +9 -0
- data/doc-ja/sample-polynomial01.rb.v.rd +9 -0
- data/doc-ja/sample-polynomial02.rb.v.rd +11 -0
- data/doc-ja/sample-primefield01.rb.v.rd +13 -0
- data/doc-ja/sample-quotientfield01.rb.v.rd +11 -0
- data/doc-ja/sample-quotientfield02.rb.v.rd +18 -0
- data/doc-ja/sample-quotientfield03.rb.v.rd +16 -0
- data/doc-ja/sample-quotientfield04.rb.v.rd +16 -0
- data/doc-ja/sample-set01.rb.v.rd +18 -0
- data/doc-ja/sample-splitting-field01.rb.v.rd +19 -0
- data/doc-ja/samples-ja.html +885 -0
- data/doc-ja/samples-ja.rd +221 -0
- data/doc-ja/style.css +85 -0
- data/doc-ja/todo.html +20 -0
- data/doc-ja/todo.rd +9 -0
- data/lib/algebra.rb +36 -0
- data/lib/algebra/algebraic-equation.rb +56 -0
- data/lib/algebra/algebraic-extension-field.rb +135 -0
- data/lib/algebra/algebraic-parser.rb +160 -0
- data/lib/algebra/algebraic-system.rb +224 -0
- data/lib/algebra/annihilate.rb +52 -0
- data/lib/algebra/array-supplement.rb +53 -0
- data/lib/algebra/auto-require.rb +84 -0
- data/lib/algebra/chinese-rem-th.rb +135 -0
- data/lib/algebra/combinatorial.rb +145 -0
- data/lib/algebra/elementary-divisor.rb +193 -0
- data/lib/algebra/euclidian-ring.rb +161 -0
- data/lib/algebra/factors.rb +305 -0
- data/lib/algebra/finite-group.rb +374 -0
- data/lib/algebra/finite-map.rb +201 -0
- data/lib/algebra/finite-set.rb +456 -0
- data/lib/algebra/galois-group.rb +129 -0
- data/lib/algebra/gaussian-elimination.rb +385 -0
- data/lib/algebra/groebner-basis-coeff.rb +228 -0
- data/lib/algebra/groebner-basis.rb +197 -0
- data/lib/algebra/import-module-single-thread.rb +86 -0
- data/lib/algebra/import-module.rb +491 -0
- data/lib/algebra/jordan-form.rb +114 -0
- data/lib/algebra/linear-algebra.rb +143 -0
- data/lib/algebra/localized-ring.rb +294 -0
- data/lib/algebra/m-index.rb +282 -0
- data/lib/algebra/m-polynomial-factor-int.rb +186 -0
- data/lib/algebra/m-polynomial-factor-zp.rb +114 -0
- data/lib/algebra/m-polynomial-factor.rb +315 -0
- data/lib/algebra/m-polynomial-gcd.rb +40 -0
- data/lib/algebra/m-polynomial.rb +875 -0
- data/lib/algebra/matrix-algebra-triplet.rb +292 -0
- data/lib/algebra/matrix-algebra.rb +929 -0
- data/lib/algebra/numeric-supplement.rb +123 -0
- data/lib/algebra/permutation-group.rb +257 -0
- data/lib/algebra/polynomial-converter.rb +193 -0
- data/lib/algebra/polynomial-factor-alg.rb +148 -0
- data/lib/algebra/polynomial-factor-int.rb +252 -0
- data/lib/algebra/polynomial-factor-zp.rb +165 -0
- data/lib/algebra/polynomial-factor.rb +140 -0
- data/lib/algebra/polynomial.rb +592 -0
- data/lib/algebra/powers.rb +31 -0
- data/lib/algebra/prime-gen.rb +32 -0
- data/lib/algebra/rational.rb +81 -0
- data/lib/algebra/residue-class-ring.rb +219 -0
- data/lib/algebra/sets-system.rb +43 -0
- data/lib/algebra/splitting-field.rb +103 -0
- data/lib/algebra/version.rb +3 -0
- data/sample/Makefile +10 -0
- data/sample/do-testscripts.rb +100 -0
- data/sample/sample-algebraic-equation01.rb +6 -0
- data/sample/sample-algebraic-equation02.rb +6 -0
- data/sample/sample-algebraic-root01.rb +15 -0
- data/sample/sample-algebraicfield01.rb +21 -0
- data/sample/sample-algebraicfield02.rb +10 -0
- data/sample/sample-cayleyhamilton01.rb +9 -0
- data/sample/sample-diagonalization01.rb +43 -0
- data/sample/sample-divmod01.rb +12 -0
- data/sample/sample-elementary-divisor01.rb +43 -0
- data/sample/sample-factorize01.rb +6 -0
- data/sample/sample-factorize02.rb +8 -0
- data/sample/sample-factorize03.rb +9 -0
- data/sample/sample-factorize04.rb +9 -0
- data/sample/sample-factorize05.rb +48 -0
- data/sample/sample-galois-group01.rb +22 -0
- data/sample/sample-gaussian-elimination01.rb +14 -0
- data/sample/sample-geometry01.rb +28 -0
- data/sample/sample-geometry02.rb +29 -0
- data/sample/sample-geometry03.rb +40 -0
- data/sample/sample-geometry04.rb +28 -0
- data/sample/sample-geometry07.rb +58 -0
- data/sample/sample-groebner01.rb +8 -0
- data/sample/sample-groebner02.rb +13 -0
- data/sample/sample-groebner03.rb +14 -0
- data/sample/sample-group01.rb +16 -0
- data/sample/sample-jordan-form01.rb +51 -0
- data/sample/sample-lagrange-multiplier01.rb +30 -0
- data/sample/sample-m-factorize01.rb +10 -0
- data/sample/sample-m-factorize02.rb +7 -0
- data/sample/sample-m-polynomial01.rb +5 -0
- data/sample/sample-map01.rb +4 -0
- data/sample/sample-polynomial01.rb +4 -0
- data/sample/sample-polynomial02.rb +6 -0
- data/sample/sample-primefield01.rb +8 -0
- data/sample/sample-quotientfield01.rb +6 -0
- data/sample/sample-quotientfield02.rb +13 -0
- data/sample/sample-quotientfield03.rb +11 -0
- data/sample/sample-quotientfield04.rb +11 -0
- data/sample/sample-set01.rb +13 -0
- data/sample/sample-splitting-field01.rb +14 -0
- data/sample/test-00-cayley-hamilton.rb +76 -0
- data/sample/test-00-groebner-basis.rb +274 -0
- data/sample/test-00-polynomial-factor-alg.rb +89 -0
- data/sample/test-00.list +4 -0
- data/sample/time-trial.rb +65 -0
- metadata +373 -0
data/sample/Makefile
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
ENV["RUBYLIB"] ||= ""
|
3
|
+
ENV["RUBYLIB"] = "tests:../lib:" + ENV["RUBYLIB"]
|
4
|
+
|
5
|
+
SKIPED = []
|
6
|
+
def skip(s)
|
7
|
+
SKIPED.push s
|
8
|
+
end
|
9
|
+
|
10
|
+
def allow(script)
|
11
|
+
# slow
|
12
|
+
if !ENV["TESTS"] || ENV["TESTS"].empty?
|
13
|
+
case script
|
14
|
+
when /^sample-factorize04\.rb$/ ; skip(script); return false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# little slow
|
19
|
+
if ENV["TESTF"] && !ENV["TESTF"].empty?
|
20
|
+
case script
|
21
|
+
when /\bsample-factorize05\.rb$/; skip(script); return false
|
22
|
+
when /\bsample-jordan-form\.rb$/; skip(script); return false
|
23
|
+
when /\bsample-jordan-form01\.rb$/; skip(script); return false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# 1.8.0 BUG
|
28
|
+
if ENV["TEST8"] && !ENV["TEST8"].empty?
|
29
|
+
case script
|
30
|
+
when /\bsample-m-factorize01\.rb$/; skip(script); return false
|
31
|
+
when /\bsample-galois-group01\.rb$/; skip(script); return false
|
32
|
+
when /\btest-algebraic-equation\.rb$/; skip(script); return false
|
33
|
+
when /\btest-jordan-form\.rb$/; skip(script); return false
|
34
|
+
when /\btest-splitting-field\.rb$/; skip(script); return false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
$SUDDEN_DETH = true
|
41
|
+
|
42
|
+
def mktitle(head, ch = "#", ch0 = ch)
|
43
|
+
title = ch0 + " #{head} " + ch0
|
44
|
+
f = ""
|
45
|
+
f << ch * (title.size/ch.size) << "\n"
|
46
|
+
f << ch0 << " " * (title.size-ch0.size*2) << ch0 << "\n"
|
47
|
+
f << title << "\n"
|
48
|
+
f << ch0 << " " * (title.size-ch0.size*2) << ch0 << "\n"
|
49
|
+
f << ch * (title.size/ch.size) << "\n"
|
50
|
+
f
|
51
|
+
end
|
52
|
+
|
53
|
+
def testscript(fname)
|
54
|
+
script = File.basename(fname)
|
55
|
+
command = "ruby" + " " + fname
|
56
|
+
# print mktitle("TEST of '#{script}'")
|
57
|
+
r = system(command)
|
58
|
+
# if r
|
59
|
+
# print mktitle("TEST SUCCEEDED. '#{script}'", "*", "|")
|
60
|
+
# puts
|
61
|
+
# else
|
62
|
+
# print mktitle("TEST FAILED. '#{script}'", "X")
|
63
|
+
# puts
|
64
|
+
# if $SUDDEN_DETH
|
65
|
+
# puts "\007"
|
66
|
+
# exit(255)
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
end
|
70
|
+
|
71
|
+
starttime = Time.new
|
72
|
+
ARGV.each do |fname|
|
73
|
+
script = File.basename(fname)
|
74
|
+
dir = File.dirname(fname)
|
75
|
+
if script =~ /^test-.*.list$/
|
76
|
+
open(fname) do |f|
|
77
|
+
f.each do |line|
|
78
|
+
next if line =~ /^#/ || line =~ /^\s*$/
|
79
|
+
x = dir + "/" + line.chomp
|
80
|
+
testscript(x)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
elsif script =~ /^test-00-.*\.rb$/
|
84
|
+
#testscript(fname)
|
85
|
+
elsif script =~ /^test-.*\.rb$/ && allow(script)
|
86
|
+
testscript(fname)
|
87
|
+
elsif script =~ /^sample-.*\.rb$/ && allow(script)
|
88
|
+
testscript(fname)
|
89
|
+
else
|
90
|
+
puts "SKIP: #{fname}"
|
91
|
+
next
|
92
|
+
end
|
93
|
+
end
|
94
|
+
spendtime = Time.now - starttime
|
95
|
+
puts
|
96
|
+
SKIPED.each do |s|
|
97
|
+
puts "SKIPED: #{s}."
|
98
|
+
end
|
99
|
+
puts "\007"; sleep 0.2; puts "\007"
|
100
|
+
print mktitle(" ALL TEST SUCCEEDED. (#{spendtime} sec.) ", "o", "|")
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "algebra"
|
2
|
+
|
3
|
+
R2, r2, r2_ = Root(Rational, 2) # r2 = sqrt(2), -sqrt(2)
|
4
|
+
p r2 #=> sqrt(2)
|
5
|
+
R3, r3, r3_ = Root(R2, 3) # r3 = sqrt(3), -sqrt(3)
|
6
|
+
p r3 #=> sqrt(3)
|
7
|
+
R6, r6, r6_ = Root(R3, 6) # R6 = R3, r6 = sqrt(6), -sqrt(6)
|
8
|
+
p r6 #=> -r2r3
|
9
|
+
p( (r6 + r2)*(r6 - r2) ) #=> 4
|
10
|
+
|
11
|
+
F, a, b = QuadraticExtensionField(Rational){|x| x**2 - x - 1}
|
12
|
+
# fibonacci numbers
|
13
|
+
(0..100).each do |n|
|
14
|
+
puts( (a**n - b**n)/(a - b) )
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "algebra"
|
2
|
+
|
3
|
+
Px = Polynomial(Rational, "x")
|
4
|
+
x = Px.var
|
5
|
+
F = ResidueClassRing(Px, x**2 + x + 1)
|
6
|
+
x = F[x]
|
7
|
+
p( (x + 1)**100 )
|
8
|
+
#=> -x - 1
|
9
|
+
p( (x-1)** 3 / (x**2 - 1) )
|
10
|
+
#=> -3x - 3
|
11
|
+
|
12
|
+
G = Polynomial(F, "y")
|
13
|
+
y = G.var
|
14
|
+
p( (x + y + 1)** 7 )
|
15
|
+
#=> y^7 + (7x + 7)y^6 + 8xy^5 + 4y^4 + (4x + 4)y^3 + 5xy^2 + 7y + x + 1
|
16
|
+
|
17
|
+
H = ResidueClassRing(G, y**5 + x*y + 1)
|
18
|
+
y = H[y]
|
19
|
+
p( 1/(x + y + 1)**7 )
|
20
|
+
#=> (1798/3x + 1825/9)y^4 + (-74x + 5176/9)y^3 +
|
21
|
+
# (-6886/9x - 5917/9)y^2 + (1826/3x - 3101/9)y + 2146/9x + 4702/9
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "algebra"
|
2
|
+
M = SquareMatrix(Rational, 3)
|
3
|
+
a = M[[1,-1,-1], [-1,1,-1], [2,1,-1]]
|
4
|
+
puts "A = "; a.display; puts
|
5
|
+
#A =
|
6
|
+
# 1, -1, -1
|
7
|
+
# -1, 1, -1
|
8
|
+
# 2, 1, -1
|
9
|
+
|
10
|
+
e = a.diagonalize
|
11
|
+
|
12
|
+
puts "Charactoristic Poly.: #{e.chpoly} => #{e.facts}";puts
|
13
|
+
#Charactoristic Poly.: t^3 - t^2 + t - 6 => (t - 2)(t^2 + t + 3)
|
14
|
+
|
15
|
+
puts "Algebraic Numbers:"
|
16
|
+
e.roots.each do |po, rs|
|
17
|
+
puts "#{rs.join(', ')} : roots of #{po} == 0"
|
18
|
+
end; puts
|
19
|
+
#Algebraic Numbers:
|
20
|
+
#a, -a - 1 : roots of t^2 + t + 3 == 0
|
21
|
+
|
22
|
+
puts "EigenSpaces: "
|
23
|
+
e.evalues.uniq.each do |ev|
|
24
|
+
puts "W_{#{ev}} = <#{e.espaces[ev].map { |e| e.to_s }.join(', ')}>"
|
25
|
+
end; puts
|
26
|
+
#EigenSpaces:
|
27
|
+
#W_{2} = <[4, -5, 1]>
|
28
|
+
#W_{a} = <[1/3a + 1/3, 1/3a + 1/3, 1]>
|
29
|
+
#W_{-a - 1} = <[-1/3a, -1/3a, 1]>
|
30
|
+
|
31
|
+
puts "Trans. Matrix:"
|
32
|
+
puts "P ="
|
33
|
+
e.tmatrix.display; puts
|
34
|
+
puts "P^-1 * A * P = "; (e.tmatrix.inverse * a * e.tmatrix).display; puts
|
35
|
+
#P =
|
36
|
+
# 4, 1/3a + 1/3, -1/3a
|
37
|
+
# -5, 1/3a + 1/3, -1/3a
|
38
|
+
# 1, 1, 1
|
39
|
+
#
|
40
|
+
#P^-1 * A * P =
|
41
|
+
# 2, 0, 0
|
42
|
+
# 0, a, 0
|
43
|
+
# 0, 0, -a - 1
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "algebra"
|
2
|
+
P = MPolynomial(Rational)
|
3
|
+
x, y, z = P.vars("xyz")
|
4
|
+
f = x**2*y + x*y**2 + y*2 + z**3
|
5
|
+
g = x*y-z**3
|
6
|
+
h = y*2-6*z
|
7
|
+
|
8
|
+
P.set_ord(:lex) # lex, grlex, grevlex
|
9
|
+
puts "(#{f}).divmod([#{g}, #{h}]) =>", "#{f.divmod(g, h).inspect}"
|
10
|
+
#=> (x^2y + xy^2 + 2y + z^3).divmod([xy - z^3, 2y - 6z]) =>
|
11
|
+
# [[x + y, 1/2z^3 + 1], xz^3 + 3z^4 + z^3 + 6z]
|
12
|
+
# = [[Quotient1,Quotient2], Remainder]
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "algebra"
|
2
|
+
|
3
|
+
M = SquareMatrix(Rational, 4)
|
4
|
+
a = M[
|
5
|
+
[2, 0, 0, 0],
|
6
|
+
[0, 2, 0, 0],
|
7
|
+
[0, 0, 2, 0],
|
8
|
+
[5, 0, 0, 2]
|
9
|
+
]
|
10
|
+
P = Polynomial(Rational, "x")
|
11
|
+
MP = SquareMatrix(P, 4)
|
12
|
+
|
13
|
+
ac = a._char_matrix(MP)
|
14
|
+
ac.display; puts #=>
|
15
|
+
#x - 2, 0, 0, 0
|
16
|
+
# 0, x - 2, 0, 0
|
17
|
+
# 0, 0, x - 2, 0
|
18
|
+
# -5, 0, 0, x - 2
|
19
|
+
|
20
|
+
p ac.elementary_divisor #=> [1, x - 2, x - 2, x^2 - 4x + 4]
|
21
|
+
|
22
|
+
require "algebra/matrix-algebra-triplet"
|
23
|
+
at = ac.to_triplet.e_diagonalize
|
24
|
+
|
25
|
+
at.body.display; puts #=>
|
26
|
+
# 1, 0, 0, 0
|
27
|
+
# 0, x - 2, 0, 0
|
28
|
+
# 0, 0, x - 2, 0
|
29
|
+
# 0, 0, 0, x^2 - 4x + 4
|
30
|
+
|
31
|
+
at.left.display; puts #=>
|
32
|
+
# 0, 0, 0, -1/5
|
33
|
+
# 0, 1, 0, 0
|
34
|
+
# 0, 0, 1, 0
|
35
|
+
# 5, 0, 0, x - 2
|
36
|
+
|
37
|
+
at.right.display; puts #=>
|
38
|
+
# 1, 0, 0, 1/5x - 2/5
|
39
|
+
# 0, 1, 0, 0
|
40
|
+
# 0, 0, 1, 0
|
41
|
+
# 0, 0, 0, 1
|
42
|
+
|
43
|
+
p at.left * ac * at.right == at.body #=> true
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "algebra"
|
2
|
+
|
3
|
+
A = AlgebraicExtensionField(Rational, "a") {|a| a**2 - 2}
|
4
|
+
B = AlgebraicExtensionField(A, "b"){|b| b**2 + 1}
|
5
|
+
P = Polynomial(B, "x")
|
6
|
+
x = P.var
|
7
|
+
f = x**4 + 1
|
8
|
+
p f.factorize
|
9
|
+
#=> (x - 1/2ab - 1/2a)(x + 1/2ab - 1/2a)(x + 1/2ab + 1/2a)(x - 1/2ab + 1/2a)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "algebra"
|
2
|
+
|
3
|
+
def show(f, mod = 0)
|
4
|
+
if mod > 0
|
5
|
+
zp = ResidueClassRing(Integer, mod)
|
6
|
+
pzp = Polynomial(zp, f.variable)
|
7
|
+
f = f.convert_to(pzp)
|
8
|
+
end
|
9
|
+
fact = f.factorize
|
10
|
+
printf "mod %2d: %-15s => %s\n", mod, f, fact
|
11
|
+
end
|
12
|
+
|
13
|
+
Px = Polynomial(Integer, "x")
|
14
|
+
x = Px.var
|
15
|
+
f = x**4 + 10*x**2 + 1
|
16
|
+
#f = x**4 - 10*x**2 + 1
|
17
|
+
show(f)
|
18
|
+
Primes.new.each do |mod|
|
19
|
+
break if mod > 100
|
20
|
+
show(f, mod)
|
21
|
+
end
|
22
|
+
|
23
|
+
#mod 0: x^4 + 10x^2 + 1 => x^4 + 10x^2 + 1
|
24
|
+
#mod 2: x^4 + 1 => (x + 1)^4
|
25
|
+
#mod 3: x^4 + x^2 + 1 => (x + 2)^2(x + 1)^2
|
26
|
+
#mod 5: x^4 + 1 => (x^2 + 3)(x^2 + 2)
|
27
|
+
#mod 7: x^4 + 3x^2 + 1 => (x^2 + 4x + 6)(x^2 + 3x + 6)
|
28
|
+
#mod 11: x^4 - x^2 + 1 => (x^2 + 5x + 1)(x^2 + 6x + 1)
|
29
|
+
#mod 13: x^4 + 10x^2 + 1 => (x^2 - x + 12)(x^2 + x + 12)
|
30
|
+
#mod 17: x^4 + 10x^2 + 1 => (x^2 + 3x + 1)(x^2 + 14x + 1)
|
31
|
+
#mod 19: x^4 + 10x^2 + 1 => (x + 17)(x + 10)(x + 9)(x + 2)
|
32
|
+
#mod 23: x^4 + 10x^2 + 1 => (x^2 + 6)(x^2 + 4)
|
33
|
+
#mod 29: x^4 + 10x^2 + 1 => (x^2 + 21)(x^2 + 18)
|
34
|
+
#mod 31: x^4 + 10x^2 + 1 => (x^2 + 22x + 30)(x^2 + 9x + 30)
|
35
|
+
#mod 37: x^4 + 10x^2 + 1 => (x^2 + 32x + 36)(x^2 + 5x + 36)
|
36
|
+
#mod 41: x^4 + 10x^2 + 1 => (x^2 + 19x + 1)(x^2 + 22x + 1)
|
37
|
+
#mod 43: x^4 + 10x^2 + 1 => (x + 40)(x + 29)(x + 14)(x + 3)
|
38
|
+
#mod 47: x^4 + 10x^2 + 1 => (x^2 + 32)(x^2 + 25)
|
39
|
+
#mod 53: x^4 + 10x^2 + 1 => (x^2 + 41)(x^2 + 22)
|
40
|
+
#mod 59: x^4 + 10x^2 + 1 => (x^2 + 13x + 1)(x^2 + 46x + 1)
|
41
|
+
#mod 61: x^4 + 10x^2 + 1 => (x^2 + 54x + 60)(x^2 + 7x + 60)
|
42
|
+
#mod 67: x^4 + 10x^2 + 1 => (x + 55)(x + 39)(x + 28)(x + 12)
|
43
|
+
#mod 71: x^4 + 10x^2 + 1 => (x^2 + 43)(x^2 + 38)
|
44
|
+
#mod 73: x^4 + 10x^2 + 1 => (x + 68)(x + 44)(x + 29)(x + 5)
|
45
|
+
#mod 79: x^4 + 10x^2 + 1 => (x^2 + 64x + 78)(x^2 + 15x + 78)
|
46
|
+
#mod 83: x^4 + 10x^2 + 1 => (x^2 + 18x + 1)(x^2 + 65x + 1)
|
47
|
+
#mod 89: x^4 + 10x^2 + 1 => (x^2 + 9x + 1)(x^2 + 80x + 1)
|
48
|
+
#mod 97: x^4 + 10x^2 + 1 => (x + 88)(x + 54)(x + 43)(x + 9)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "algebra/rational"
|
2
|
+
require "algebra/polynomial"
|
3
|
+
|
4
|
+
P = Algebra.Polynomial(Rational, "x")
|
5
|
+
x = P.var
|
6
|
+
|
7
|
+
(x**3 - 3*x + 1).galois_group.each do |g|
|
8
|
+
p g
|
9
|
+
end
|
10
|
+
#=> [0, 1, 2]
|
11
|
+
# [1, 2, 0]
|
12
|
+
# [2, 0, 1]]
|
13
|
+
|
14
|
+
(x**3 - x + 1).galois_group.each do |g|
|
15
|
+
p g
|
16
|
+
end
|
17
|
+
#=> [0, 1, 2]
|
18
|
+
# [1, 0, 2]
|
19
|
+
# [2, 0, 1]
|
20
|
+
# [0, 2, 1]
|
21
|
+
# [1, 2, 0]
|
22
|
+
# [2, 1, 0]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "algebra"
|
2
|
+
M = MatrixAlgebra(Rational, 5, 4)
|
3
|
+
a = M.matrix{|i, j| i + j}
|
4
|
+
a.display #=>
|
5
|
+
#[0, 1, 2, 3]
|
6
|
+
#[1, 2, 3, 4]
|
7
|
+
#[2, 3, 4, 5]
|
8
|
+
#[3, 4, 5, 6]
|
9
|
+
#[4, 5, 6, 7]
|
10
|
+
a.kernel_basis.each do |v|
|
11
|
+
puts "a * #{v} = #{a * v}"
|
12
|
+
#=> a * [1, -2, 1, 0] = [0, 0, 0, 0, 0]
|
13
|
+
#=> a * [2, -3, 0, 1] = [0, 0, 0, 0, 0]
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'algebra'
|
2
|
+
R = MPolynomial(Rational)
|
3
|
+
x,y,a1,a2,b1,b2,c1,c2 = R.vars('xya1a2b1b2c1c2')
|
4
|
+
|
5
|
+
V = Vector(R, 2)
|
6
|
+
X, A, B, C = V[x,y], V[a1,a2], V[b1,b2], V[c1,c2]
|
7
|
+
|
8
|
+
D = (B + C) /2
|
9
|
+
E = (C + A) /2
|
10
|
+
F = (A + B) /2
|
11
|
+
|
12
|
+
def line(p1, p2, p3)
|
13
|
+
SquareMatrix.det([[1, *p1], [1, *p2], [1, *p3]])
|
14
|
+
end
|
15
|
+
|
16
|
+
l1 = line(X, A, D)
|
17
|
+
l2 = line(X, B, E)
|
18
|
+
l3 = line(X, C, F)
|
19
|
+
s = line(A, B, C)
|
20
|
+
|
21
|
+
g = Groebner.basis [l1, l2, l3, s-1] #s-1 means non degeneracy
|
22
|
+
|
23
|
+
g.each_with_index do |f, i|
|
24
|
+
p f
|
25
|
+
end
|
26
|
+
#x - 1/3a1 - 1/3b1 - 1/3c1
|
27
|
+
#y - 1/3a2 - 1/3b2 - 1/3c2
|
28
|
+
#a1b2 - a1c2 - a2b1 + a2c1 + b1c2 - b2c1 - 1
|