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
@@ -0,0 +1,13 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-factorize02.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
|
6
|
+
Z7 = ResidueClassRing(Integer, 7)
|
7
|
+
P = Polynomial(Z7, "x")
|
8
|
+
x = P.var
|
9
|
+
f = 8*x**7 - 20*x**6 + 6*x**5 - 11*x**4 + 44*x**3 - 9*x**2 - 27
|
10
|
+
p f.factorize #=> (x + 5)^2(x + 3)^2(x + 2)^3
|
11
|
+
|
12
|
+
((<_|CONTENTS>))
|
13
|
+
=end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-factorize03.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
|
6
|
+
A = AlgebraicExtensionField(Rational, "a") {|a| a**2 + a + 1}
|
7
|
+
a = A.var
|
8
|
+
P = Polynomial(A, "x")
|
9
|
+
x = P.var
|
10
|
+
f = x**4 + (2*a + 1)*x**3 + 3*a*x**2 + (-3*a - 5)*x - a + 1
|
11
|
+
p f.factorize #=> (x + a)^3(x - a + 1)
|
12
|
+
|
13
|
+
((<_|CONTENTS>))
|
14
|
+
=end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-factorize04.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
|
6
|
+
A = AlgebraicExtensionField(Rational, "a") {|a| a**2 - 2}
|
7
|
+
B = AlgebraicExtensionField(A, "b"){|b| b**2 + 1}
|
8
|
+
P = Polynomial(B, "x")
|
9
|
+
x = P.var
|
10
|
+
f = x**4 + 1
|
11
|
+
p f.factorize
|
12
|
+
#=> (x - 1/2ab - 1/2a)(x + 1/2ab - 1/2a)(x + 1/2ab + 1/2a)(x - 1/2ab + 1/2a)
|
13
|
+
((<_|CONTENTS>))
|
14
|
+
=end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-factorize05.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
|
6
|
+
def show(f, mod = 0)
|
7
|
+
if mod > 0
|
8
|
+
zp = ResidueClassRing(Integer, mod)
|
9
|
+
pzp = Polynomial(zp, f.variable)
|
10
|
+
f = f.convert_to(pzp)
|
11
|
+
end
|
12
|
+
fact = f.factorize
|
13
|
+
printf "mod %2d: %-15s => %s\n", mod, f, fact
|
14
|
+
end
|
15
|
+
|
16
|
+
Px = Polynomial(Integer, "x")
|
17
|
+
x = Px.var
|
18
|
+
f = x**4 + 10*x**2 + 1
|
19
|
+
#f = x**4 - 10*x**2 + 1
|
20
|
+
show(f)
|
21
|
+
Primes.new.each do |mod|
|
22
|
+
break if mod > 100
|
23
|
+
show(f, mod)
|
24
|
+
end
|
25
|
+
|
26
|
+
#mod 0: x^4 + 10x^2 + 1 => x^4 + 10x^2 + 1
|
27
|
+
#mod 2: x^4 + 1 => (x + 1)^4
|
28
|
+
#mod 3: x^4 + x^2 + 1 => (x + 2)^2(x + 1)^2
|
29
|
+
#mod 5: x^4 + 1 => (x^2 + 3)(x^2 + 2)
|
30
|
+
#mod 7: x^4 + 3x^2 + 1 => (x^2 + 4x + 6)(x^2 + 3x + 6)
|
31
|
+
#mod 11: x^4 - x^2 + 1 => (x^2 + 5x + 1)(x^2 + 6x + 1)
|
32
|
+
#mod 13: x^4 + 10x^2 + 1 => (x^2 - x + 12)(x^2 + x + 12)
|
33
|
+
#mod 17: x^4 + 10x^2 + 1 => (x^2 + 3x + 1)(x^2 + 14x + 1)
|
34
|
+
#mod 19: x^4 + 10x^2 + 1 => (x + 17)(x + 10)(x + 9)(x + 2)
|
35
|
+
#mod 23: x^4 + 10x^2 + 1 => (x^2 + 6)(x^2 + 4)
|
36
|
+
#mod 29: x^4 + 10x^2 + 1 => (x^2 + 21)(x^2 + 18)
|
37
|
+
#mod 31: x^4 + 10x^2 + 1 => (x^2 + 22x + 30)(x^2 + 9x + 30)
|
38
|
+
#mod 37: x^4 + 10x^2 + 1 => (x^2 + 32x + 36)(x^2 + 5x + 36)
|
39
|
+
#mod 41: x^4 + 10x^2 + 1 => (x^2 + 19x + 1)(x^2 + 22x + 1)
|
40
|
+
#mod 43: x^4 + 10x^2 + 1 => (x + 40)(x + 29)(x + 14)(x + 3)
|
41
|
+
#mod 47: x^4 + 10x^2 + 1 => (x^2 + 32)(x^2 + 25)
|
42
|
+
#mod 53: x^4 + 10x^2 + 1 => (x^2 + 41)(x^2 + 22)
|
43
|
+
#mod 59: x^4 + 10x^2 + 1 => (x^2 + 13x + 1)(x^2 + 46x + 1)
|
44
|
+
#mod 61: x^4 + 10x^2 + 1 => (x^2 + 54x + 60)(x^2 + 7x + 60)
|
45
|
+
#mod 67: x^4 + 10x^2 + 1 => (x + 55)(x + 39)(x + 28)(x + 12)
|
46
|
+
#mod 71: x^4 + 10x^2 + 1 => (x^2 + 43)(x^2 + 38)
|
47
|
+
#mod 73: x^4 + 10x^2 + 1 => (x + 68)(x + 44)(x + 29)(x + 5)
|
48
|
+
#mod 79: x^4 + 10x^2 + 1 => (x^2 + 64x + 78)(x^2 + 15x + 78)
|
49
|
+
#mod 83: x^4 + 10x^2 + 1 => (x^2 + 18x + 1)(x^2 + 65x + 1)
|
50
|
+
#mod 89: x^4 + 10x^2 + 1 => (x^2 + 9x + 1)(x^2 + 80x + 1)
|
51
|
+
#mod 97: x^4 + 10x^2 + 1 => (x + 88)(x + 54)(x + 43)(x + 9)
|
52
|
+
((<_|CONTENTS>))
|
53
|
+
=end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-galois-group01.rb
|
3
|
+
|
4
|
+
require "algebra/rational"
|
5
|
+
require "algebra/polynomial"
|
6
|
+
|
7
|
+
P = Algebra.Polynomial(Rational, "x")
|
8
|
+
x = P.var
|
9
|
+
|
10
|
+
(x**3 - 3*x + 1).galois_group.each do |g|
|
11
|
+
p g
|
12
|
+
end
|
13
|
+
#=> [0, 1, 2]
|
14
|
+
# [1, 2, 0]
|
15
|
+
# [2, 0, 1]]
|
16
|
+
|
17
|
+
(x**3 - x + 1).galois_group.each do |g|
|
18
|
+
p g
|
19
|
+
end
|
20
|
+
#=> [0, 1, 2]
|
21
|
+
# [1, 0, 2]
|
22
|
+
# [2, 0, 1]
|
23
|
+
# [0, 2, 1]
|
24
|
+
# [1, 2, 0]
|
25
|
+
# [2, 1, 0]
|
26
|
+
((<_|CONTENTS>))
|
27
|
+
=end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-gaussian-elimination01.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
M = MatrixAlgebra(Rational, 5, 4)
|
6
|
+
a = M.matrix{|i, j| i + j}
|
7
|
+
a.display #=>
|
8
|
+
#[0, 1, 2, 3]
|
9
|
+
#[1, 2, 3, 4]
|
10
|
+
#[2, 3, 4, 5]
|
11
|
+
#[3, 4, 5, 6]
|
12
|
+
#[4, 5, 6, 7]
|
13
|
+
a.kernel_basis.each do |v|
|
14
|
+
puts "a * #{v} = #{a * v}"
|
15
|
+
#=> a * [1, -2, 1, 0] = [0, 0, 0, 0, 0]
|
16
|
+
#=> a * [2, -3, 0, 1] = [0, 0, 0, 0, 0]
|
17
|
+
end
|
18
|
+
((<_|CONTENTS>))
|
19
|
+
=end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-geometry01.rb
|
3
|
+
|
4
|
+
require 'algebra'
|
5
|
+
R = MPolynomial(Rational)
|
6
|
+
x,y,a1,a2,b1,b2,c1,c2 = R.vars('xya1a2b1b2c1c2')
|
7
|
+
|
8
|
+
V = Vector(R, 2)
|
9
|
+
X, A, B, C = V[x,y], V[a1,a2], V[b1,b2], V[c1,c2]
|
10
|
+
|
11
|
+
D = (B + C) /2
|
12
|
+
E = (C + A) /2
|
13
|
+
F = (A + B) /2
|
14
|
+
|
15
|
+
def line(p1, p2, p3)
|
16
|
+
SquareMatrix.det([[1, *p1], [1, *p2], [1, *p3]])
|
17
|
+
end
|
18
|
+
|
19
|
+
l1 = line(X, A, D)
|
20
|
+
l2 = line(X, B, E)
|
21
|
+
l3 = line(X, C, F)
|
22
|
+
s = line(A, B, C)
|
23
|
+
|
24
|
+
g = Groebner.basis [l1, l2, l3, s-1] #s-1 means non degeneracy
|
25
|
+
|
26
|
+
g.each_with_index do |f, i|
|
27
|
+
p f
|
28
|
+
end
|
29
|
+
#x - 1/3a1 - 1/3b1 - 1/3c1
|
30
|
+
#y - 1/3a2 - 1/3b2 - 1/3c2
|
31
|
+
#a1b2 - a1c2 - a2b1 + a2c1 + b1c2 - b2c1 - 1
|
32
|
+
((<_|CONTENTS>))
|
33
|
+
=end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-geometry02.rb
|
3
|
+
|
4
|
+
require 'algebra'
|
5
|
+
R = MPolynomial(Rational)
|
6
|
+
x,y,a1,a2,b1,b2,c1,c2 = R.vars('xya1a2b1b2c1c2')
|
7
|
+
|
8
|
+
V = Vector(R, 2)
|
9
|
+
X, A, B, C = V[x,y], V[a1,a2], V[b1,b2], V[c1,c2]
|
10
|
+
|
11
|
+
def line(p1, p2, p3)
|
12
|
+
SquareMatrix.det([[1, *p1], [1, *p2], [1, *p3]])
|
13
|
+
end
|
14
|
+
|
15
|
+
def vline(p1, p2, p3)
|
16
|
+
(p1-p2).norm2 - (p1-p3).norm2
|
17
|
+
end
|
18
|
+
|
19
|
+
l1 = vline(X, A, B)
|
20
|
+
l2 = vline(X, B, C)
|
21
|
+
l3 = vline(X, C, A)
|
22
|
+
|
23
|
+
s = line(A, B, C)
|
24
|
+
|
25
|
+
g = Groebner.basis [l1, l2, l3, s-1] #s-1 means non degeneracy
|
26
|
+
|
27
|
+
g.each do |f|
|
28
|
+
p f
|
29
|
+
end
|
30
|
+
#x - 1/2a1a2b1 + 1/2a1a2c1 + 1/2a1b1c2 - 1/2a1c1c2 - 1/2a1 - 1/2a2^2b2 + 1/2a2^2c2 + 1/2a2b1^2 - 1/2a2b1c1 + 1/2a2b2^2 - 1/2a2c2^2 - 1/2b1^2c2 + 1/2b1c1c2 - 1/2b2^2c2 + 1/2b2c2^2 - 1/2c1
|
31
|
+
#y + 1/2a1^2b1 - 1/2a1^2c1 - 1/2a1b1^2 + 1/2a1c1^2 + 1/2a2^2b1 - 1/2a2^2c1 - 1/2a2b1b2 - 1/2a2b1c2 + 1/2a2b2c1 + 1/2a2c1c2 + 1/2b1^2c1 + 1/2b1b2c2 - 1/2b1c1^2 -1/2b2c1c2 - 1/2b2 - 1/2c2
|
32
|
+
#a1b2 - a1c2 - a2b1 + a2c1 + b1c2 - b2c1 - 1
|
33
|
+
((<_|CONTENTS>))
|
34
|
+
=end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-geometry03.rb
|
3
|
+
|
4
|
+
#incenter
|
5
|
+
puts "too heavy ... skip (#{$0})"
|
6
|
+
exit
|
7
|
+
require 'algebra'
|
8
|
+
|
9
|
+
R = MPolynomial(Rational)
|
10
|
+
x,y,a1,a2,b1,b2,c1,c2 = R.vars('xya1a2b1b2c1c2')
|
11
|
+
Q = LocalizedRing(R)
|
12
|
+
x0,y0,a10,a20,b10,b20,c10,c20 = R.vars.map{|v| Q[v]}
|
13
|
+
V = Vector(R, 2)
|
14
|
+
W = Vector(Q, 2)
|
15
|
+
X, A, B, C = V[x,y], V[a1,a2], V[b1,b2], V[c1,c2]
|
16
|
+
|
17
|
+
def bisector(p1, p2, p3)
|
18
|
+
p1,p2,p3 = [p1,p2,p3].map{|v| v.convert_to(W)}
|
19
|
+
k1 = (p1.inner_product(p2))**2/p2.norm2
|
20
|
+
k2 = (p1.inner_product(p3))**2/p3.norm2
|
21
|
+
(k1-k2).numerator
|
22
|
+
end
|
23
|
+
|
24
|
+
def line(p1, p2, p3)
|
25
|
+
SquareMatrix.det([[1, *p1], [1, *p2], [1, *p3]])
|
26
|
+
end
|
27
|
+
|
28
|
+
l1 = bisector(X-A, B-A, C-A)
|
29
|
+
p l1
|
30
|
+
l2 = bisector(X-B, C-B, A-B)
|
31
|
+
p l2
|
32
|
+
l3 = bisector(X-C, A-C, B-C)
|
33
|
+
p l3
|
34
|
+
|
35
|
+
s = line(A, B, C)
|
36
|
+
|
37
|
+
g = Groebner.basis [l1, l2, l3, s-1] #s-1 means non degeneracy
|
38
|
+
|
39
|
+
g.each do |f|
|
40
|
+
p f
|
41
|
+
end
|
42
|
+
|
43
|
+
#p g.size > 1
|
44
|
+
((<_|CONTENTS>))
|
45
|
+
=end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-geometry04.rb
|
3
|
+
|
4
|
+
require 'algebra'
|
5
|
+
|
6
|
+
R = MPolynomial(Rational)
|
7
|
+
x,y,a1,a2,b1,b2,c1,c2 = R.vars('xya1a2b1b2c1c2')
|
8
|
+
V = Vector(R, 2)
|
9
|
+
X, A, B, C = V[x,y], V[a1,a2], V[b1,b2], V[c1,c2]
|
10
|
+
|
11
|
+
def perpendicular(p0, p1, p2, p3)
|
12
|
+
(p0-p1).inner_product(p2-p3)
|
13
|
+
end
|
14
|
+
|
15
|
+
def line(p1, p2, p3)
|
16
|
+
SquareMatrix.det([[1, *p1], [1, *p2], [1, *p3]])
|
17
|
+
end
|
18
|
+
|
19
|
+
l1 = perpendicular(X, A, B, C)
|
20
|
+
l2 = perpendicular(X, B, C, A)
|
21
|
+
l3 = perpendicular(X, C, A, B)
|
22
|
+
|
23
|
+
s = line(A, B, C)
|
24
|
+
g = Groebner.basis [l1, l2, l3, s-1] #s-1 means non degeneracy
|
25
|
+
|
26
|
+
g.each do |f|
|
27
|
+
p f
|
28
|
+
end
|
29
|
+
#x + a1a2b1 - a1a2c1 - a1b1c2 + a1c1c2 + a2^2b2 - a2^2c2 - a2b1^2 + a2b1c1 - a2b2^2 + a2c2^2 + b1^2c2 - b1c1c2 - b1 + b2^2c2 - b2c2^2
|
30
|
+
#y - a1^2b1 + a1^2c1 + a1b1^2 - a1c1^2 - a2^2b1 + a2^2c1 + a2b1b2 + a2b1c2 - a2b2c1 - a2c1c2 - a2 - b1^2c1 - b1b2c2 + b1c1^2 + b2c1c2
|
31
|
+
#a1b2 - a1c2 - a2b1 + a2c1 + b1c2 - b2c1 - 1
|
32
|
+
((<_|CONTENTS>))
|
33
|
+
=end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-geometry07.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
R = MPolynomial(Rational)
|
6
|
+
m, b, a = R.vars("mba")
|
7
|
+
K = LocalizedRing(R)
|
8
|
+
a0, b0, m0 = K[a], K[b], K[m]
|
9
|
+
|
10
|
+
M = SquareMatrix(K, 3)
|
11
|
+
l0, l1, l2 = M[[0, 1, 0], [1, 1, -1], [1, 0, 0]]
|
12
|
+
m4 = M[[a0, 1, -a0], [1, b0, -b0], [m0, -1, 0]]
|
13
|
+
m40 = m4.dup; m40.set_row(0, l0)
|
14
|
+
m41 = m4.dup; m41.set_row(1, l1)
|
15
|
+
m42 = m4.dup; m42.set_row(2, l2)
|
16
|
+
|
17
|
+
def mdet(m, i)
|
18
|
+
i = i % 3
|
19
|
+
m.minor(i, 2).determinant * (-1) ** i
|
20
|
+
end
|
21
|
+
|
22
|
+
def tris(m, i)
|
23
|
+
pts = [0, 1, 2] - [i]
|
24
|
+
(m.determinant)**2 / mdet(m, pts[0]) / mdet(m, pts[1])
|
25
|
+
end
|
26
|
+
|
27
|
+
u0 = (tris(m4, 0) - tris(m40, 0)).numerator
|
28
|
+
u1 = (tris(m4, 1) - tris(m41, 1)).numerator
|
29
|
+
u2 = (tris(m4, 2) - tris(m42, 2)).numerator
|
30
|
+
|
31
|
+
puts [u0, u1, u2]
|
32
|
+
puts
|
33
|
+
|
34
|
+
[u0, u1, u2].each do |um|
|
35
|
+
p um.factorize
|
36
|
+
end
|
37
|
+
puts
|
38
|
+
|
39
|
+
x = u0 / a / (m*b+1)
|
40
|
+
y = u1 / (m+a) / (b-1)
|
41
|
+
z = u2 / (-b*a+1)
|
42
|
+
|
43
|
+
p x
|
44
|
+
p y
|
45
|
+
p z
|
46
|
+
puts
|
47
|
+
|
48
|
+
gb = Groebner.basis([x, y, z])
|
49
|
+
puts gb
|
50
|
+
puts
|
51
|
+
|
52
|
+
gb.each do |v|
|
53
|
+
p v.factorize
|
54
|
+
end
|
55
|
+
#(-1)(-mb + m + ba^3 + ba^2 - ba - a^2)
|
56
|
+
#(-1)(-ma + m + ba^2 - a^2)
|
57
|
+
#(-1)(b + a - 1)(-ba + 1)(a)
|
58
|
+
#(-1)(-ba + 1)(a)(a^2 + a - 1)
|
59
|
+
|
60
|
+
# => a = -1/2 + \sqrt{5}/2
|
61
|
+
((<_|CONTENTS>))
|
62
|
+
=end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-groebner01.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
P = MPolynomial(Rational, "xyz")
|
6
|
+
x, y, z = P.vars("xyz")
|
7
|
+
f1 = x**2 + y**2 + z**2 -1
|
8
|
+
f2 = x**2 + z**2 - y
|
9
|
+
f3 = x - z
|
10
|
+
p Groebner.basis([f1, f2, f3])
|
11
|
+
#=> [x - z, y - 2z^2, z^4 + 1/2z^2 - 1/4]
|
12
|
+
((<_|CONTENTS>))
|
13
|
+
=end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-groebner02.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
|
6
|
+
P = MPolynomial(Rational)
|
7
|
+
x, y, z = P.vars "xyz"
|
8
|
+
f1 = x**2 + y**2 + z**2 -1
|
9
|
+
f2 = x**2 + z**2 - y
|
10
|
+
f3 = x - z
|
11
|
+
|
12
|
+
coeff, basis = Groebner.basis_coeff([f1, f2, f3])
|
13
|
+
basis.each_with_index do |b, i|
|
14
|
+
p [coeff[i].inner_product([f1, f2, f3]), b]
|
15
|
+
p coeff[i].inner_product([f1, f2, f3]) == b #=> true
|
16
|
+
end
|
17
|
+
((<_|CONTENTS>))
|
18
|
+
=end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-groebner03.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
F5 = ResidueClassRing(Integer, 2)
|
6
|
+
F = AlgebraicExtensionField(F5, "a") {|a| a**3 + a + 1}
|
7
|
+
a = F.var
|
8
|
+
P = MPolynomial(F)
|
9
|
+
|
10
|
+
x, y, z = P.vars("xyz")
|
11
|
+
f1 = x + y**2 + z**2 - 1
|
12
|
+
f2 = x**2 + z**2 - y * a
|
13
|
+
f3 = x - z - a
|
14
|
+
|
15
|
+
f = x**3 + y**3 + z**3
|
16
|
+
q, r = f.divmod_s(f1, f2, f3)
|
17
|
+
p f == q.inner_product([f1, f2, f3]) + r #=> true
|
18
|
+
((<_|CONTENTS>))
|
19
|
+
=end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
=begin
|
2
|
+
# sample-group01.rb
|
3
|
+
|
4
|
+
require "algebra"
|
5
|
+
e = Permutation[0, 1, 2, 3, 4]
|
6
|
+
a = Permutation[1, 0, 3, 4, 2]
|
7
|
+
b = Permutation[0, 2, 1, 3, 4]
|
8
|
+
p a * b #=> [2, 0, 3, 4, 1]
|
9
|
+
|
10
|
+
g = Group.new(e, a, b)
|
11
|
+
g.complete!
|
12
|
+
p g == PermutationGroup.symmetric(5) #=> true
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
((<_|CONTENTS>))
|
21
|
+
=end
|