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,456 @@
1
+ # Finite Set
2
+ #
3
+ # by Shin-ichiro Hara (sinara@blade.nagaokaut.ac.jp)
4
+ #
5
+ # Version 0.96 (2003.11.06)
6
+
7
+ Object.send(:remove_const, :Set)
8
+
9
+ module Algebra
10
+ class Set
11
+ include Enumerable
12
+
13
+ def self.[](*a)
14
+ new(*a)
15
+ end
16
+
17
+ def self.new_a(a)
18
+ new(*a)
19
+ end
20
+
21
+ def self.new_h(h)
22
+ new.instance_eval do
23
+ @body = h
24
+ self
25
+ end
26
+ end
27
+
28
+ def initialize(*m)
29
+ @body = {}
30
+ m.each do |x|
31
+ @body.store(x, true)
32
+ end
33
+ end
34
+ attr_accessor :body
35
+
36
+ def self.empty_set
37
+ new
38
+ end
39
+
40
+ class << self
41
+ alias phi empty_set
42
+ alias null empty_set
43
+ end
44
+
45
+ def self.singleton(x)
46
+ new(x)
47
+ end
48
+
49
+ def cast(klass = Set)
50
+ x = klass.new_h(@body)
51
+ if block_given?
52
+ x.instance_eval do
53
+ yield
54
+ end
55
+ end
56
+ x
57
+ end
58
+
59
+ def empty_set
60
+ self.class.new
61
+ end
62
+
63
+ alias phi empty_set
64
+ alias null empty_set
65
+
66
+ def singleton(x)
67
+ self.class.new(x)
68
+ end
69
+
70
+ def singleton?
71
+ size == 1
72
+ end
73
+
74
+ def size
75
+ @body.size
76
+ end
77
+
78
+ def empty?
79
+ @body.empty?
80
+ end
81
+
82
+ alias phi? empty?
83
+ alias empty_set? empty?
84
+ alias nul? empty?
85
+
86
+ def each(&b)
87
+ @body.each_key(&b)
88
+ end
89
+
90
+ def separate(&b)
91
+ self.class.new(*find_all(&b))
92
+ end
93
+
94
+ alias select_s separate
95
+ alias find_all_s separate
96
+
97
+ def map_s(&b)
98
+ self.class.new(*map(&b))
99
+ end
100
+
101
+ def pick
102
+ each do |x|
103
+ return x
104
+ end
105
+ nil
106
+ end
107
+
108
+ def shift
109
+ (x = @body.shift) && x.first
110
+ end
111
+
112
+ def dup
113
+ self.class.new(*to_a)
114
+ end
115
+
116
+ def append!(x)
117
+ @body.store(x, true)
118
+ self
119
+ end
120
+
121
+ alias push append!
122
+ alias << append!
123
+
124
+ def append(x)
125
+ dup.append!(x)
126
+ end
127
+
128
+ def concat(other)
129
+ case other
130
+ when Set
131
+ @body.update other.body
132
+ when Array
133
+ other.each do |x|
134
+ append!(x)
135
+ end
136
+ else
137
+ raise "unknown self.class #{other.class}"
138
+ end
139
+ self
140
+ end
141
+
142
+ def rehash
143
+ @body.rehash
144
+ end
145
+
146
+ def eql?(other)
147
+ subset?(other) && superset?(other)
148
+ end
149
+
150
+ alias == eql?
151
+
152
+ def hash
153
+ s = 0
154
+ @body.each_key do |k|
155
+ s ^= k.hash
156
+ end
157
+ s
158
+ end
159
+
160
+ def include?(x)
161
+ @body.include?(x)
162
+ end
163
+
164
+ alias member? include?
165
+ alias has? include?
166
+ alias contains? include?
167
+
168
+ def superset?(other) # self includes other
169
+ other.is_a?(Set) && other.all? { |x| member?(x) }
170
+ end
171
+
172
+ alias >= superset?
173
+ alias incl? superset?
174
+
175
+ def subset?(other) # self is a part of other
176
+ other.is_a?(Set) && all? { |x| other.member?(x) }
177
+ end
178
+
179
+ alias <= subset?
180
+ alias part_of? subset?
181
+
182
+ def <(other)
183
+ self <= other && size < other.size
184
+ end
185
+
186
+ def >(other)
187
+ self >= other && size > other.size
188
+ end
189
+
190
+ def union(other = nil)
191
+ if other
192
+ h = @body.dup
193
+ h.update other.body
194
+ self.class.new_h(h)
195
+ else
196
+ u = phi
197
+ each do |s|
198
+ u = u.union(s)
199
+ end
200
+ u
201
+ end
202
+ end
203
+
204
+ alias | union
205
+ alias + union
206
+ alias cup union
207
+
208
+ def difference(other)
209
+ h = @body.dup
210
+ h.delete_if { |k, _v| other.include?(k) }
211
+ self.class.new_h(h)
212
+ end
213
+
214
+ alias - difference
215
+
216
+ def intersection(other = nil)
217
+ if other
218
+ h = @body.dup
219
+ h.delete_if { |k, _v| !other.include?(k) }
220
+ self.class.new_h(h)
221
+ else
222
+ i = nil # nil is a universe?
223
+ each do |s|
224
+ i = if i.nil?
225
+ s
226
+ else
227
+ i.intersection(s)
228
+ end
229
+ end
230
+ i
231
+ end
232
+ end
233
+
234
+ alias & intersection
235
+ alias cap intersection
236
+
237
+ def each_pair
238
+ stock = []
239
+ each do |x|
240
+ stock.each do |a|
241
+ yield a, x
242
+ end
243
+ stock.push x
244
+ end
245
+ end
246
+
247
+ def each_member(n)
248
+ if n == 0
249
+ yield []
250
+ elsif n == 1 # redundant but effective
251
+ each do |x|
252
+ yield [x]
253
+ end
254
+ else
255
+ stock = self.class[]
256
+ each do |x|
257
+ stock.each_member(n - 1) do |a|
258
+ yield a + [x]
259
+ end
260
+ stock.push x
261
+ end
262
+ end
263
+ end
264
+
265
+ def each_subset
266
+ yield phi
267
+ _each_subset do |s|
268
+ yield s
269
+ end
270
+ end
271
+
272
+ def each_non_trivial_subset # each without empty set and total set
273
+ n = size
274
+ _each_subset do |x|
275
+ yield x unless x.size == n
276
+ end
277
+ end
278
+
279
+ def _each_subset
280
+ stock = phi
281
+ each do |x|
282
+ yield self.class[x]
283
+ stock._each_subset do |a|
284
+ yield a + self.class[x]
285
+ end
286
+ stock.push x
287
+ end
288
+ stock
289
+ end
290
+ protected :_each_subset
291
+
292
+ def power_set
293
+ s = phi
294
+ each_subset do |u|
295
+ s.append! u
296
+ end
297
+ s
298
+ end
299
+
300
+ def each_product(other)
301
+ each do |x|
302
+ other.each do |y|
303
+ yield [x, y]
304
+ end
305
+ end
306
+ end
307
+
308
+ def product(other, s = phi)
309
+ if block_given?
310
+ each_product(other) do |x, y|
311
+ s.append! yield(x, y)
312
+ end
313
+ else
314
+ each_product(other) do |x, y|
315
+ s.append! [x, y]
316
+ end
317
+ end
318
+ s
319
+ end
320
+
321
+ alias * product
322
+
323
+ def equiv_class(equiv = nil)
324
+ classes = Set.phi
325
+ if equiv && equiv.is_a?(Symbol) && !block_given?
326
+ each do |e|
327
+ if c = classes.find do |s|
328
+ send(equiv, s.pick, e)
329
+ end
330
+ c.push e
331
+ classes.rehash
332
+ else
333
+ classes.push singleton(e)
334
+ end
335
+ end
336
+ elsif equiv && !block_given?
337
+ each do |e|
338
+ if c = classes.find do |s|
339
+ equiv.call(s.pick, e)
340
+ end
341
+ c.push e
342
+ classes.rehash
343
+ else
344
+ classes.push singleton(e)
345
+ end
346
+ end
347
+ elsif !equiv && block_given?
348
+ each do |e|
349
+ if c = classes.find do |s|
350
+ yield(s.pick, e)
351
+ end
352
+ c.push e
353
+ classes.rehash
354
+ else
355
+ classes.push singleton(e)
356
+ end
357
+ end
358
+ else
359
+ raise "illegal call `equiv_class'"
360
+ end
361
+ classes
362
+ end
363
+
364
+ alias / equiv_class
365
+
366
+ def to_s
367
+ '{' + @body.keys.collect(&:inspect).join(', ') + '}'
368
+ end
369
+
370
+ def inspect
371
+ '{' + @body.keys.collect(&:inspect).join(', ') + '}'
372
+ end
373
+
374
+ def to_a
375
+ @body.keys
376
+ end
377
+
378
+ def to_ary
379
+ to_a
380
+ end
381
+
382
+ def sort
383
+ to_a.sort
384
+ end
385
+
386
+ def power(other)
387
+ a = Map.phi(self)
388
+ s = [a]
389
+ other.each do |x|
390
+ tmp = []
391
+ each do |y|
392
+ s.each do |m|
393
+ tmp << m.append(x, y)
394
+ end
395
+ end
396
+ s = tmp
397
+ end
398
+ self.class[*s]
399
+ end
400
+
401
+ def identity_map
402
+ a = Map.phi(self)
403
+ each do |x|
404
+ a.append!(x, x)
405
+ end
406
+ a
407
+ end
408
+
409
+ alias ** power
410
+
411
+ def surjections(other)
412
+ (self**other).separate(&:surjective?)
413
+ end
414
+
415
+ def injections0(other)
416
+ (self**other).separate(&:injective?)
417
+ end
418
+
419
+ def injections(other)
420
+ maps = Set[]
421
+ if size < other.size
422
+ phi
423
+ elsif other.empty?
424
+ maps.push Map.phi(self)
425
+ else
426
+ each do |x|
427
+ a = self - self.class[x]
428
+ o = other.dup
429
+ h = o.shift
430
+ maps.concat a.injections(other)
431
+ maps.concat a.injections(o).map_s { |m| m.append(h, x) }
432
+ end
433
+ end
434
+ maps
435
+ end
436
+
437
+ def bijections(other)
438
+ size == other.size ? injections(other) : Set[]
439
+ end
440
+ end
441
+ end
442
+
443
+ module Enumerable
444
+ unless instance_methods(true).include?('any?')
445
+ def any?
446
+ each do |x|
447
+ return true if yield(x)
448
+ end
449
+ false
450
+ end
451
+
452
+ def all?
453
+ !any? { |x| !yield(x) }
454
+ end
455
+ end
456
+ end