algebra 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.travis.yml +7 -0
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/Gemfile +7 -0
  6. data/Gemfile.lock +28 -0
  7. data/LICENSE.txt +21 -0
  8. data/README-ja.txt +60 -0
  9. data/README.md +61 -0
  10. data/Rakefile +43 -0
  11. data/algebra.gemspec +33 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/doc-ja/README-ja.html +69 -0
  15. data/doc-ja/README-ja.rd +60 -0
  16. data/doc-ja/README.html +0 -0
  17. data/doc-ja/README.rd +0 -0
  18. data/doc-ja/algebra-ja.html +66 -0
  19. data/doc-ja/algebra-ja.rd +60 -0
  20. data/doc-ja/algebraic-equation-ja.html +36 -0
  21. data/doc-ja/algebraic-equation-ja.rd +26 -0
  22. data/doc-ja/algebraic-extension-field-ja.html +122 -0
  23. data/doc-ja/algebraic-extension-field-ja.rd +118 -0
  24. data/doc-ja/algebraic-parser-ja.html +87 -0
  25. data/doc-ja/algebraic-parser-ja.rd +95 -0
  26. data/doc-ja/changes.html +161 -0
  27. data/doc-ja/changes.rd +119 -0
  28. data/doc-ja/elementary-divisor-ja.html +56 -0
  29. data/doc-ja/elementary-divisor-ja.rd +45 -0
  30. data/doc-ja/euclidian-ring-ja.html +78 -0
  31. data/doc-ja/euclidian-ring-ja.rd +69 -0
  32. data/doc-ja/finite-group-ja.html +285 -0
  33. data/doc-ja/finite-group-ja.rd +276 -0
  34. data/doc-ja/finite-map-ja.html +224 -0
  35. data/doc-ja/finite-map-ja.rd +227 -0
  36. data/doc-ja/finite-set-ja.html +393 -0
  37. data/doc-ja/finite-set-ja.rd +408 -0
  38. data/doc-ja/index-ja.html +113 -0
  39. data/doc-ja/index-ja.rd +112 -0
  40. data/doc-ja/jordan-form-ja.html +106 -0
  41. data/doc-ja/jordan-form-ja.rd +99 -0
  42. data/doc-ja/localized-ring-ja.html +121 -0
  43. data/doc-ja/localized-ring-ja.rd +131 -0
  44. data/doc-ja/m-polynomial-ja.html +542 -0
  45. data/doc-ja/m-polynomial-ja.rd +596 -0
  46. data/doc-ja/matrix-algebra-ja.html +686 -0
  47. data/doc-ja/matrix-algebra-ja.rd +727 -0
  48. data/doc-ja/matrix-algebra-triplet-ja.html +124 -0
  49. data/doc-ja/matrix-algebra-triplet-ja.rd +129 -0
  50. data/doc-ja/permutation-group-ja.html +159 -0
  51. data/doc-ja/permutation-group-ja.rd +151 -0
  52. data/doc-ja/polynomial-converter-ja.html +64 -0
  53. data/doc-ja/polynomial-converter-ja.rd +54 -0
  54. data/doc-ja/polynomial-ja.html +446 -0
  55. data/doc-ja/polynomial-ja.rd +473 -0
  56. data/doc-ja/residue-class-ring-ja.html +112 -0
  57. data/doc-ja/residue-class-ring-ja.rd +113 -0
  58. data/doc-ja/sample-algebraic-equation01.rb.v.rd +11 -0
  59. data/doc-ja/sample-algebraic-equation02.rb.v.rd +11 -0
  60. data/doc-ja/sample-algebraic-root01.rb.v.rd +20 -0
  61. data/doc-ja/sample-algebraicfield01.rb.v.rd +26 -0
  62. data/doc-ja/sample-algebraicfield02.rb.v.rd +15 -0
  63. data/doc-ja/sample-cayleyhamilton01.rb.v.rd +14 -0
  64. data/doc-ja/sample-diagonalization01.rb.v.rd +48 -0
  65. data/doc-ja/sample-divmod01.rb.v.rd +17 -0
  66. data/doc-ja/sample-elementary-divisor01.rb.v.rd +48 -0
  67. data/doc-ja/sample-factorize01.rb.v.rd +11 -0
  68. data/doc-ja/sample-factorize02.rb.v.rd +13 -0
  69. data/doc-ja/sample-factorize03.rb.v.rd +14 -0
  70. data/doc-ja/sample-factorize04.rb.v.rd +14 -0
  71. data/doc-ja/sample-factorize05.rb.v.rd +53 -0
  72. data/doc-ja/sample-galois-group01.rb.v.rd +27 -0
  73. data/doc-ja/sample-gaussian-elimination01.rb.v.rd +19 -0
  74. data/doc-ja/sample-geometry01.rb.v.rd +33 -0
  75. data/doc-ja/sample-geometry02.rb.v.rd +34 -0
  76. data/doc-ja/sample-geometry03.rb.v.rd +45 -0
  77. data/doc-ja/sample-geometry04.rb.v.rd +33 -0
  78. data/doc-ja/sample-geometry07.rb.v.rd +62 -0
  79. data/doc-ja/sample-groebner01.rb.v.rd +13 -0
  80. data/doc-ja/sample-groebner02.rb.v.rd +18 -0
  81. data/doc-ja/sample-groebner03.rb.v.rd +19 -0
  82. data/doc-ja/sample-group01.rb.v.rd +21 -0
  83. data/doc-ja/sample-jordan-form01.rb.v.rd +56 -0
  84. data/doc-ja/sample-jordanform01.rb.v.rd +55 -0
  85. data/doc-ja/sample-lagrange-multiplier01.rb.v.rd +35 -0
  86. data/doc-ja/sample-m-factorize01.rb.v.rd +15 -0
  87. data/doc-ja/sample-m-factorize02.rb.v.rd +12 -0
  88. data/doc-ja/sample-m-polynomial01.rb.v.rd +10 -0
  89. data/doc-ja/sample-map01.rb.v.rd +9 -0
  90. data/doc-ja/sample-polynomial01.rb.v.rd +9 -0
  91. data/doc-ja/sample-polynomial02.rb.v.rd +11 -0
  92. data/doc-ja/sample-primefield01.rb.v.rd +13 -0
  93. data/doc-ja/sample-quotientfield01.rb.v.rd +11 -0
  94. data/doc-ja/sample-quotientfield02.rb.v.rd +18 -0
  95. data/doc-ja/sample-quotientfield03.rb.v.rd +16 -0
  96. data/doc-ja/sample-quotientfield04.rb.v.rd +16 -0
  97. data/doc-ja/sample-set01.rb.v.rd +18 -0
  98. data/doc-ja/sample-splitting-field01.rb.v.rd +19 -0
  99. data/doc-ja/samples-ja.html +885 -0
  100. data/doc-ja/samples-ja.rd +221 -0
  101. data/doc-ja/style.css +85 -0
  102. data/doc-ja/todo.html +20 -0
  103. data/doc-ja/todo.rd +9 -0
  104. data/lib/algebra.rb +36 -0
  105. data/lib/algebra/algebraic-equation.rb +56 -0
  106. data/lib/algebra/algebraic-extension-field.rb +135 -0
  107. data/lib/algebra/algebraic-parser.rb +160 -0
  108. data/lib/algebra/algebraic-system.rb +224 -0
  109. data/lib/algebra/annihilate.rb +52 -0
  110. data/lib/algebra/array-supplement.rb +53 -0
  111. data/lib/algebra/auto-require.rb +84 -0
  112. data/lib/algebra/chinese-rem-th.rb +135 -0
  113. data/lib/algebra/combinatorial.rb +145 -0
  114. data/lib/algebra/elementary-divisor.rb +193 -0
  115. data/lib/algebra/euclidian-ring.rb +161 -0
  116. data/lib/algebra/factors.rb +305 -0
  117. data/lib/algebra/finite-group.rb +374 -0
  118. data/lib/algebra/finite-map.rb +201 -0
  119. data/lib/algebra/finite-set.rb +456 -0
  120. data/lib/algebra/galois-group.rb +129 -0
  121. data/lib/algebra/gaussian-elimination.rb +385 -0
  122. data/lib/algebra/groebner-basis-coeff.rb +228 -0
  123. data/lib/algebra/groebner-basis.rb +197 -0
  124. data/lib/algebra/import-module-single-thread.rb +86 -0
  125. data/lib/algebra/import-module.rb +491 -0
  126. data/lib/algebra/jordan-form.rb +114 -0
  127. data/lib/algebra/linear-algebra.rb +143 -0
  128. data/lib/algebra/localized-ring.rb +294 -0
  129. data/lib/algebra/m-index.rb +282 -0
  130. data/lib/algebra/m-polynomial-factor-int.rb +186 -0
  131. data/lib/algebra/m-polynomial-factor-zp.rb +114 -0
  132. data/lib/algebra/m-polynomial-factor.rb +315 -0
  133. data/lib/algebra/m-polynomial-gcd.rb +40 -0
  134. data/lib/algebra/m-polynomial.rb +875 -0
  135. data/lib/algebra/matrix-algebra-triplet.rb +292 -0
  136. data/lib/algebra/matrix-algebra.rb +929 -0
  137. data/lib/algebra/numeric-supplement.rb +123 -0
  138. data/lib/algebra/permutation-group.rb +257 -0
  139. data/lib/algebra/polynomial-converter.rb +193 -0
  140. data/lib/algebra/polynomial-factor-alg.rb +148 -0
  141. data/lib/algebra/polynomial-factor-int.rb +252 -0
  142. data/lib/algebra/polynomial-factor-zp.rb +165 -0
  143. data/lib/algebra/polynomial-factor.rb +140 -0
  144. data/lib/algebra/polynomial.rb +592 -0
  145. data/lib/algebra/powers.rb +31 -0
  146. data/lib/algebra/prime-gen.rb +32 -0
  147. data/lib/algebra/rational.rb +81 -0
  148. data/lib/algebra/residue-class-ring.rb +219 -0
  149. data/lib/algebra/sets-system.rb +43 -0
  150. data/lib/algebra/splitting-field.rb +103 -0
  151. data/lib/algebra/version.rb +3 -0
  152. data/sample/Makefile +10 -0
  153. data/sample/do-testscripts.rb +100 -0
  154. data/sample/sample-algebraic-equation01.rb +6 -0
  155. data/sample/sample-algebraic-equation02.rb +6 -0
  156. data/sample/sample-algebraic-root01.rb +15 -0
  157. data/sample/sample-algebraicfield01.rb +21 -0
  158. data/sample/sample-algebraicfield02.rb +10 -0
  159. data/sample/sample-cayleyhamilton01.rb +9 -0
  160. data/sample/sample-diagonalization01.rb +43 -0
  161. data/sample/sample-divmod01.rb +12 -0
  162. data/sample/sample-elementary-divisor01.rb +43 -0
  163. data/sample/sample-factorize01.rb +6 -0
  164. data/sample/sample-factorize02.rb +8 -0
  165. data/sample/sample-factorize03.rb +9 -0
  166. data/sample/sample-factorize04.rb +9 -0
  167. data/sample/sample-factorize05.rb +48 -0
  168. data/sample/sample-galois-group01.rb +22 -0
  169. data/sample/sample-gaussian-elimination01.rb +14 -0
  170. data/sample/sample-geometry01.rb +28 -0
  171. data/sample/sample-geometry02.rb +29 -0
  172. data/sample/sample-geometry03.rb +40 -0
  173. data/sample/sample-geometry04.rb +28 -0
  174. data/sample/sample-geometry07.rb +58 -0
  175. data/sample/sample-groebner01.rb +8 -0
  176. data/sample/sample-groebner02.rb +13 -0
  177. data/sample/sample-groebner03.rb +14 -0
  178. data/sample/sample-group01.rb +16 -0
  179. data/sample/sample-jordan-form01.rb +51 -0
  180. data/sample/sample-lagrange-multiplier01.rb +30 -0
  181. data/sample/sample-m-factorize01.rb +10 -0
  182. data/sample/sample-m-factorize02.rb +7 -0
  183. data/sample/sample-m-polynomial01.rb +5 -0
  184. data/sample/sample-map01.rb +4 -0
  185. data/sample/sample-polynomial01.rb +4 -0
  186. data/sample/sample-polynomial02.rb +6 -0
  187. data/sample/sample-primefield01.rb +8 -0
  188. data/sample/sample-quotientfield01.rb +6 -0
  189. data/sample/sample-quotientfield02.rb +13 -0
  190. data/sample/sample-quotientfield03.rb +11 -0
  191. data/sample/sample-quotientfield04.rb +11 -0
  192. data/sample/sample-set01.rb +13 -0
  193. data/sample/sample-splitting-field01.rb +14 -0
  194. data/sample/test-00-cayley-hamilton.rb +76 -0
  195. data/sample/test-00-groebner-basis.rb +274 -0
  196. data/sample/test-00-polynomial-factor-alg.rb +89 -0
  197. data/sample/test-00.list +4 -0
  198. data/sample/time-trial.rb +65 -0
  199. metadata +373 -0
@@ -0,0 +1,123 @@
1
+ # Numeric Supplements
2
+ #
3
+ # by Shin-ichiro Hara
4
+ #
5
+ # Version 1.01 (2001.04.10)
6
+
7
+ class Numeric
8
+ def self.unity
9
+ 1
10
+ end
11
+
12
+ def self.zero
13
+ 0
14
+ end
15
+
16
+ def zero
17
+ self.class.zero
18
+ end
19
+
20
+ def unity
21
+ self.class.unity
22
+ end
23
+
24
+ def self.indeterminate(x)
25
+ eval(x)
26
+ end
27
+
28
+ def self.const(x)
29
+ x
30
+ end
31
+
32
+ def each; end
33
+
34
+ def pdivmod(other)
35
+ divmod(other)
36
+ end
37
+
38
+ def unity?
39
+ self == 1
40
+ end
41
+
42
+ def unit?
43
+ self == unity || self == -unity
44
+ end
45
+
46
+ def monomial?
47
+ true
48
+ end
49
+
50
+ def inverse
51
+ self == -1 ? -1 : 1
52
+ end
53
+
54
+ def self.field?
55
+ true
56
+ end
57
+
58
+ def self.euclidian?
59
+ true
60
+ end
61
+
62
+ def self.ufd?
63
+ true
64
+ end
65
+
66
+ def self.regulate(x)
67
+ # if x.is_a? self
68
+ if x.is_a? Numeric
69
+ x # Numeric's can be operated each other.
70
+ end
71
+ end
72
+
73
+ def regulate(x)
74
+ self.class.regulate(x)
75
+ end
76
+ private :regulate
77
+ end
78
+
79
+ class Integer < Numeric
80
+ def self.ground
81
+ self
82
+ end
83
+
84
+ def self.field?
85
+ false
86
+ end
87
+
88
+ # def self.field?; respond_to?(:from_prime_division); end #mathn loaded
89
+ def self.euclidian?
90
+ true
91
+ end
92
+
93
+ def devide?(other)
94
+ case other
95
+ when Integer
96
+ (other % self).zero?
97
+ else
98
+ # this case will occur when mathn is required
99
+ (other / self) * self == other
100
+ # raise "devide?: unkown self.class(#{other})"
101
+ end
102
+ end
103
+ end
104
+
105
+ class Float < Numeric
106
+ def self.unity
107
+ 1.0
108
+ end
109
+
110
+ def self.zero
111
+ 0.0
112
+ end
113
+ end
114
+
115
+ class Complex < Numeric
116
+ def self.unity
117
+ new(1)
118
+ end
119
+
120
+ def self.zero
121
+ new(0)
122
+ end
123
+ end
@@ -0,0 +1,257 @@
1
+ # Permutation Group
2
+ #
3
+ # by Shin-ichiro Hara
4
+ #
5
+ # Version 0.90 (2002.03.12)
6
+
7
+ require 'algebra/powers'
8
+ require 'algebra/combinatorial'
9
+ require 'algebra/finite-group'
10
+
11
+ module Algebra
12
+ class PermutationGroup < Group
13
+ def self.unit_group(d)
14
+ self[unity(d)]
15
+ end
16
+
17
+ def self.unity(n)
18
+ Permutation.unity(n)
19
+ end
20
+
21
+ def self.perm(a)
22
+ Permutation.new(a)
23
+ end
24
+
25
+ def self.symmetric(n)
26
+ s = new(unity(n))
27
+ Combinatorial.perm(n) do |x|
28
+ s << perm(x) # unity is not duplicated naturally
29
+ end
30
+ s
31
+ end
32
+
33
+ def self.alternate(n)
34
+ symmetric(n).separate { |x| x.sign > 0 } # slow two times
35
+ end
36
+
37
+ def initialize(u, *a)
38
+ @degree = u.degree
39
+ super(u, *a)
40
+ end
41
+
42
+ attr_reader :degree
43
+ end
44
+
45
+ class Permutation
46
+ include Enumerable
47
+ include Powers
48
+
49
+ def self.[](*a)
50
+ new(a)
51
+ end
52
+
53
+ def self.unity(d)
54
+ new((0...d).to_a)
55
+ end
56
+
57
+ def initialize(x)
58
+ @perm = x
59
+ end
60
+
61
+ attr_accessor :perm
62
+
63
+ def unity
64
+ self.class.unity(@perm.size)
65
+ end
66
+
67
+ def degree
68
+ @perm.size
69
+ end
70
+
71
+ alias size degree
72
+
73
+ def each(&b)
74
+ @perm.each(&b)
75
+ end
76
+
77
+ def eql?(other)
78
+ @perm.eql?(other.perm)
79
+ end
80
+
81
+ alias == eql?
82
+
83
+ def hash
84
+ @perm.hash
85
+ end
86
+
87
+ def inspect
88
+ @perm.inspect
89
+ end
90
+
91
+ def to_s
92
+ @perm.inspect
93
+ end
94
+
95
+ def [](i)
96
+ @perm[i] || i
97
+ end
98
+
99
+ alias call []
100
+
101
+ # def []=(i, x); @perm[i] = x; end
102
+
103
+ def index(i)
104
+ @perm.index(i)
105
+ end
106
+
107
+ def right_act(other) # permutation's traditional product (g*h)[x] == h[g[x]]
108
+ self.class.new(collect { |i| other[i] })
109
+ end
110
+
111
+ alias * right_act
112
+
113
+ def left_act(other)
114
+ self.class.new(other.collect { |i| self[i] })
115
+ end
116
+
117
+ # alias * left_act
118
+
119
+ def inverse
120
+ self.class.new((0...degree).collect { |i| index(i) })
121
+ end
122
+
123
+ alias inv inverse
124
+
125
+ def sign
126
+ a = perm.dup
127
+ b = inverse.perm
128
+ s = 1
129
+ (0...(degree - 1)).each do |i|
130
+ next unless (j = a[i]) != i
131
+ a[b[i]] = j
132
+ b[j] = b[i]
133
+ s = -s
134
+ end
135
+ s
136
+ end
137
+
138
+ def conjugate(g)
139
+ g * self * g.inverse
140
+ end
141
+
142
+ def decompose_cyclic
143
+ s = []
144
+ remain = (0...size).to_a
145
+ while f = remain.shift
146
+ a = [f]
147
+ i = f
148
+ loop do
149
+ j = self[i]
150
+ if j == f
151
+ s.push a if a.size > 1
152
+ break
153
+ else
154
+ remain.delete j
155
+ a.push j
156
+ i = j
157
+ end
158
+ end
159
+ end
160
+ s
161
+ end
162
+
163
+ #---------------------------- beta
164
+
165
+ # def self.load(file)
166
+ # s = Group[]
167
+ # File.foreach(file) do |line|
168
+ # g = eval(line).self
169
+ # s.set_unity g unless s.unity
170
+ # s.push g
171
+ # end
172
+ # s
173
+ # end
174
+
175
+ # def self.subgr_load(file)
176
+ # s = Set[]
177
+ # File.foreach(file) do |line|
178
+ # s.push eval(line).collect{|perm| perm.self}.Group
179
+ # end
180
+ # s
181
+ # end
182
+
183
+ # def conjugate0(g)
184
+ # to_Mapa.collect{|pr| [g[pr.first], g[pr.last]]}.Mapa.to_ParmGr
185
+ # end
186
+
187
+ # require "algebra/finite-map"
188
+
189
+ def to_map
190
+ m = Map.phi
191
+ @perm.each_with_index do |x, i|
192
+ m.append!(i, x)
193
+ end
194
+ m
195
+ end
196
+
197
+ def decompose_transposition
198
+ a = []
199
+ (0...degree).each do |i|
200
+ a << [i, self[i]]
201
+ end
202
+ r = []
203
+ loop do
204
+ a.delete_if { |i, x| i == x }
205
+ break if a.empty?
206
+ i, x = a.shift
207
+ x, j = alpha = a.assoc(x)
208
+ a.delete(alpha)
209
+ unless j == i
210
+ a.rassoc(i)[1] = j
211
+ r.unshift [i, j]
212
+ end
213
+ r.unshift [i, x]
214
+ end
215
+ r
216
+ end
217
+
218
+ def self.cyclic2perm(c, n = nil)
219
+ n = c.flatten.max + 1 unless n
220
+ a = (0...n).collect do |i|
221
+ c.each do |b|
222
+ if j = b.index(i)
223
+ i = b[(j + 1) % b.size]
224
+ end
225
+ end
226
+ i
227
+ end
228
+ new(a)
229
+ end
230
+ end
231
+ end
232
+
233
+ if $PROGRAM_NAME == __FILE__
234
+ include Algebra
235
+ a = [
236
+ [Permutation[1, 0, 2], Permutation[2, 0, 1]],
237
+ [Permutation[0, 2, 1]]
238
+ ]
239
+ PermutationGroup.generate_strong(Permutation.unity(3), *a).each do |x|
240
+ p x
241
+ end
242
+ puts
243
+
244
+ S3 = PermutationGroup.symmetric(3)
245
+ S3.each do |x|
246
+ p x
247
+ end
248
+ puts
249
+
250
+ G = PermutationGroup.generate_strong(Permutation.unity(3),
251
+ [Permutation[1, 2, 0]],
252
+ [Permutation[2, 0, 1]])
253
+ G.each do |x|
254
+ p x
255
+ end
256
+ puts
257
+ end
@@ -0,0 +1,193 @@
1
+ # String <=> Polynomial <=> MPolynomial translator
2
+ #
3
+ # by Shin-ichiro Hara
4
+ #
5
+ # Version 2.0 (2001.04.08)
6
+
7
+ require 'algebra/m-polynomial'
8
+ require 'algebra/polynomial'
9
+ require 'algebra/residue-class-ring'
10
+
11
+ module Algebra
12
+ module PolynomialConvertTo
13
+ def convert_to(other)
14
+ if other <= MPolynomial
15
+ g = self
16
+ vs = []
17
+ while g <= Polynomial
18
+ vs.push g.variable
19
+ # vs.push g.var
20
+ g = g.ground
21
+ end
22
+ MPolynomial.create(g, *vs)
23
+ else
24
+ raise "unkown self.class (#{other})"
25
+ end
26
+ end
27
+ end
28
+
29
+ module PolynomialConverter
30
+ def value_on(ring)
31
+ e = ring.zero
32
+ # x = ring.var(var)
33
+ x = ring.var(variable)
34
+ reverse_each do |c|
35
+ e = e * x + (ground <= Polynomial ? c.value_on(ring) : c)
36
+ end
37
+ e
38
+ end
39
+
40
+ def var_swap
41
+ k = Algebra.Polynomial(ground.ground, self.class.variable)
42
+ ring = Algebra.Polynomial(k, ground.variable)
43
+ e = ring.zero
44
+ x = ring.var
45
+ y = ring.ground.var
46
+ reverse_each do |c|
47
+ e = e * y + c.evaluate(x)
48
+ end
49
+ e
50
+ end
51
+ end
52
+
53
+ module MPolynomialConvertTo
54
+ def convert_to(other)
55
+ if other <= Polynomial
56
+ # Polynomial.create(ground, *(variables))
57
+ Polynomial.create(ground, *variables.reverse)
58
+ else
59
+ raise "unkown self.class (#{other})"
60
+ end
61
+ end
62
+ end
63
+
64
+ module MPolynomialConverter
65
+ def value_on(ring)
66
+ e = ring.zero
67
+ each do |idx, c|
68
+ e += value_on_idx(idx, ring, c)
69
+ end
70
+ e
71
+ end
72
+
73
+ def value_on_idx(idx, ring, c)
74
+ vars = ring.vars.reverse
75
+ # vars = ring.vars
76
+ e = ring.unity
77
+ idx.each_with_index do |n, i|
78
+ e *= vars[i]**n
79
+ end
80
+ e * c
81
+ end
82
+ end
83
+
84
+ # class ResidueClassRing
85
+ # def abs_lift(depth, mring = nil)
86
+ # unless mring
87
+ # r = self.class
88
+ # depth.times do
89
+ # r = r.ground.ground
90
+ # end
91
+ # mring = Algebra.MPolynomial(r)
92
+ # depth.times do |n|
93
+ # mring.var("x#{n}")
94
+ # end
95
+ # end
96
+ #
97
+ # s = mring.zero
98
+ # if depth > 1
99
+ # lift.each_with_index do |c, n|
100
+ # s += c.abs_lift(depth-1, mring) * mring.vars[depth-1]**n
101
+ # end
102
+ # else
103
+ # lift.each_with_index do |c, n|
104
+ # s += c * mring.vars[depth-1]**n
105
+ # end
106
+ # end
107
+ # s
108
+ # end
109
+ # end
110
+
111
+ # class Polynomial
112
+ # def abs_lift(depth)
113
+ # r = ground
114
+ # (depth-1).times do
115
+ # r = r.ground.ground
116
+ # end
117
+ # mring = Algebra.MPolynomial(r)
118
+ # depth.times do |n|
119
+ # mring.var("x#{n}")
120
+ # end
121
+ #
122
+ # s = mring.zero
123
+ # if depth > 1
124
+ # each_with_index do |c, n|
125
+ # s += c.abs_lift(depth-1, mring) * mring.vars[depth-1]**n
126
+ # end
127
+ # else
128
+ # each_with_index do |c, n|
129
+ # s += c * mring.vars[depth-1]**n
130
+ # end
131
+ # end
132
+ # s
133
+ # end
134
+ # end
135
+ end
136
+
137
+ if __FILE__ == $PROGRAM_NAME
138
+ # MPolynomial.extend Polynomial2Polynomial
139
+ # Polynomial.extend Polynomial2Polynomial
140
+
141
+ # require "algebra/auto-require"
142
+ require 'algebra/rational'
143
+ require 'algebra/algebraic-extension-field'
144
+ A = Algebra.AlgebraicExtensionField(Rational, 'a') do |a|
145
+ a**3 - 2
146
+ end
147
+ a = A.var
148
+ B = Algebra.AlgebraicExtensionField(A, 'b') do |b|
149
+ a**2 + a * b + b**2
150
+ end
151
+ b = B.var
152
+ f = (a - b + 1)**2
153
+ p f
154
+ p f.abs_lift # (2)
155
+
156
+ P = Algebra::Polynomial.create(Integer, 'x', 'y', 'z')
157
+ x, y, z = P.vars
158
+ f = x**2 + y**2 + z**2 - x * y - y * z - z * x
159
+ # Algebra::MPolynomial.instance_eval do
160
+ # p AUTO_LOAD
161
+ # end
162
+ # P.instance_eval do
163
+ # p ['try convert_to', self, AUTO_LOAD]
164
+ # end
165
+ MP = P.convert_to(Algebra::MPolynomial)
166
+ x, y, z = MP.vars
167
+ g = x**2 + y**2 + z**2 - x * y - y * z - z * x
168
+ p f = f.value_on(MP) #=> z^2 - zy - zx + y^2 - yx + x^2
169
+ p f == g #=> true
170
+
171
+ P0 = MP.convert_to(Algebra::Polynomial)
172
+ x, y, z = P0.vars
173
+ g = x**2 + y**2 + z**2 - x * y - y * z - z * x
174
+ p f = f.value_on(P0)
175
+ p f == g
176
+
177
+ Px = Algebra.Polynomial(Integer, 'x')
178
+ x = Px.var
179
+ Pxy = Algebra.Polynomial(Px, 'y')
180
+ y0 = Pxy.var
181
+
182
+ Py = Algebra.Polynomial(Integer, 'y')
183
+ y = Py.var
184
+ Pyx = Algebra.Polynomial(Py, 'x')
185
+ x0 = Pyx.var
186
+
187
+ f = y0**2 * x - y0**3 * x**2
188
+ g = y**2 * x0 - y**3 * x0**2
189
+ p f
190
+ p g
191
+ p f.var_swap
192
+ puts 'END.'
193
+ end