algebra 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,727 @@
1
+ =begin
2
+ [((<index-ja|URL:index-ja.html>))]
3
+ ((<Algebra::MatrixAlgebra>))
4
+ /
5
+ ((<Algebra::Vector>))
6
+ /
7
+ ((<Algebra::Covector>))
8
+ /
9
+ ((<Algebra::SquareMatrix>))
10
+ /
11
+ ((<Algebra::GaussianElimination>))
12
+
13
+ = Algebra::MatrixAlgebra
14
+ ((*(行列クラス)*))
15
+
16
+ 行列を表現します。実際のクラスを生成するには基底環とサイズを指定して、
17
+ クラスメソッド ((<::create>)) あるいは関数 ((<Algebra::MatrixAlgebra>))()
18
+ を用います。
19
+
20
+ サブクラスとして ((<Algebra::Vector>))(縦ベクトル),
21
+ ((<Algebra::Covector>))(横ベクトル),
22
+ ((<Algebra::SquareMatrix>))(正方行列) を持ちます。
23
+
24
+ == ファイル名:
25
+ * ((|matrix-algebra.rb|))
26
+
27
+ == スーパークラス:
28
+
29
+ * ((|Object|))
30
+
31
+ == インクルードしているモジュール:
32
+
33
+ * ((<Algebra::GaussianElimination>))
34
+ * Enumerable
35
+
36
+ == 関連する関数:
37
+
38
+ --- Algebra.MatrixAlgebra(ring, m, n)
39
+ ((<::create>))(ring, m, n)と同じです。
40
+
41
+ == クラスメソッド:
42
+
43
+ --- ::create(ring, m, n)
44
+ 環 ((|ring|)) を要素とする, (({ (m, n) })) 型の行列を
45
+ 表現するクラスを生成します。
46
+
47
+ このメソッドの戻り値は ((<Algebra::MatrixAlgebra>)) クラスのサブクラス
48
+ です。このサブクラスにはクラスメソッドとして ((|ground|)) と
49
+ ((|rsize|)), ((|csize|)), ((|sizes|)) が定義され、それぞれ、
50
+ 基底となる環 ((|ring|))、行のサイズ ((|m|))、列のサイズ ((|n|))、
51
+ それらの配列 (({ [m, n] })) を返します。
52
+
53
+ 実際に行列を作るには ((<::new>)), ((<::matrix>)),
54
+ ((<::[]>)) を使います。
55
+
56
+ --- ::new(array)
57
+ ((|array|)) を配列の配列とするとき、それを要素とする行列を返します。
58
+
59
+ 例:
60
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
61
+ a = M.new([[1, 2, 3], [4, 5, 6]])
62
+ a.display
63
+ #=> [1, 2, 3]
64
+ #=> [4, 5, 6]
65
+
66
+ --- ::matrix{|i, j| ... }
67
+ ((|i|)) と ((|j|)) に行と列のインデックスを与え ... を評価した値を
68
+ (({ (i, j) })) 成分にした行列を返します。
69
+
70
+ 例:
71
+ M = Alebra.MatrixAlgebra(Integer, 2, 3)
72
+ a = M.matrix{|i, j| 10*(i + 1) + j + 1}
73
+ a.display
74
+ #=> [11, 12, 13]
75
+ #=> [21, 22, 23]
76
+
77
+ --- ::[](array1, array2, ..., arrayr)
78
+ 配列 (({array1, array2, ..., arrayr})) をそれぞれ行とする配列を返します。
79
+
80
+ 例:
81
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
82
+ a = M[[1, 2, 3], [4, 5, 6]]
83
+ a.display
84
+ #=> [1, 2, 3]
85
+ #=> [4, 5, 6]
86
+
87
+ --- ::collect_ij{|i, j| ... }
88
+ ((<::matrix>)) によく似ていますが、
89
+ 返り値は Algebra::MatrixAlgebra でなく、2重配列(Array の Array)です。
90
+
91
+ --- ::collect_row{|i| ... }
92
+ 第 i 行に ... を評価して得た配列を並べた行列を返します。
93
+
94
+ 例:
95
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
96
+ A = M.collect_row{|i| [i*10 + 11, i*10 + 12, i*10 + 13]}
97
+ A.display
98
+ #=> [11, 12, 13]
99
+ #=> [21, 22, 23]
100
+
101
+ --- ::collect_column{|j| ... }
102
+ 第 j 列に ... を評価して得た配列を並べた行列を返します。
103
+
104
+ 例:
105
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
106
+ A = M.collect_column{|j| [11 + j, 21 + j]}
107
+ A.display
108
+ #=> [11, 12, 13]
109
+ #=> [21, 22, 23]
110
+
111
+ --- ::*(otype)
112
+ 2つの行列の型を掛けた新しいクラスを返します。
113
+
114
+ 例:
115
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
116
+ N = Algebra.MatrixAlgebra(Integer, 3, 4)
117
+ L = M * N
118
+ p L.sizes #=> [3, 4]
119
+
120
+ --- ::vector_type
121
+ ((<rsize>)) と同じサイズの縦ベクトル(Vector)クラスを返します。
122
+
123
+ --- ::covector_type
124
+ ((<csize>)) と同じサイズの横ベクトル(CoVector)クラスを返します。
125
+
126
+ --- ::transpose
127
+ 転置を行った新しい行列クラスを返します。
128
+
129
+ --- ::zero
130
+ 零行列を返します。
131
+
132
+ #--- ::matrices; Matrices; end
133
+ #--- ::regulate(x)
134
+
135
+ == メソッド:
136
+ #--- dup
137
+ --- [](i, j)
138
+ (({(i, j)})) 成分を返します。
139
+
140
+ --- []=(i, j, x)
141
+ (({(i, j)})) 成分を x にします。
142
+
143
+ --- rsize
144
+ 行サイズを返します。((<::rsize>)) と同じです。
145
+
146
+ --- csize
147
+ 列サイズを返します。((<::csize>)) と同じです。
148
+
149
+ --- sizes
150
+ [((<rsize>)), ((<csize>))] の配列を返します。
151
+ ((<::sizes>)) と同じです。
152
+
153
+ --- rows
154
+ 各行を要素とする配列を返します。
155
+
156
+ 例:
157
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
158
+ a = M.new([[1, 2, 3], [4, 5, 6]])
159
+ p a.rows #=> [[1, 2, 3], [4, 5, 6]]
160
+ p a.row(1) #=> [4, 5, 6]
161
+ a.set_row(1, [40, 50, 60])
162
+ a.display #=> [1, 2, 3]
163
+ #=> [40, 50, 60]
164
+
165
+ --- row(i)
166
+ i 行目を配列として返します。
167
+
168
+ --- set_row(i, array)
169
+ i 行目を配列 array に入れ換えます。
170
+
171
+ --- columns
172
+ 各列を要素とする配列を返します。
173
+
174
+ 例:
175
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
176
+ a = M.new([[1, 2, 3], [4, 5, 6]])
177
+ p a.columns #=> [[1, 4], [2, 5], [3, 6]]
178
+ p a.column(1) #=> [2, 5]
179
+ a.set_column(1, [20, 50])
180
+ a.display #=> [1, 20, 3]
181
+ #=> [4, 50, 6]
182
+
183
+ --- column(j)
184
+ j 列目を配列として返します。
185
+
186
+ --- set_column(j, array)
187
+ j 列目を配列 array に入れ換えます。
188
+
189
+ --- each{|row| ...}
190
+ 各行を配列にして ((|row|)) に入れるイテレータです。
191
+
192
+ --- each_index{|i, j| ...}
193
+ 各添え字 (({ (i, j) })) に関するイテレータです。
194
+
195
+ --- each_i{|i| ...}
196
+ 各行の添え字 (({i})) に関するイテレータです。
197
+
198
+ --- each_j{|j| ...}
199
+ 各列の添え字 (({j})) に関するイテレータです。
200
+
201
+ --- each_row{|r| ... }
202
+ 各行を配列にして ((|r|)) に入れるイテレータです。
203
+ ((<each>)) と同じです。
204
+
205
+ --- each_column{|c| ... }
206
+ 各列を配列にして ((|c|)) に入れるイテレータです。
207
+
208
+ --- matrix{|i, j| ... }
209
+ ((<::matrix>)) と同じです。
210
+
211
+ --- collect_ij{|i, j| ... }
212
+ ((<::collect_ij>)) と同じです。
213
+
214
+ --- collect_row{|i| ... }
215
+ ((<::collect_row>)) と同じです。
216
+
217
+ --- collect_column{|j| ... }
218
+ ((<::collect_column>)) と同じです。
219
+
220
+ --- minor(i, j)
221
+ ((|i|)) 行 ((|j|)) 列を除いた小行列を返します。
222
+
223
+ --- cofactor(i, j)
224
+ ((|i|)) 行 ((|j|)) 列を除いた小行列式に (-1)**(i+j) を掛けたものを
225
+ 返します。(({minor(i, j) ** (i + j)})) と同じです。
226
+
227
+ --- cofactor_matrix
228
+ 余因子行列を返します。(({self.class.transpose.matrix{|i, j| cofactor(j, i)}})) と同じです。
229
+
230
+ --- adjoint
231
+ ((<cofactor_matrix>)) と同じです。
232
+
233
+ --- ==(other)
234
+ 等しいとき真を返します。
235
+
236
+ --- +(other)
237
+ 和を計算します。
238
+
239
+ --- -(other)
240
+ 差を計算します。
241
+
242
+ --- *(other)
243
+ 積を計算します。
244
+
245
+ 例:
246
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
247
+ N = Algebra.MatrixAlgebra(Integer, 3, 4)
248
+ L = M * N
249
+ a = M[[1, 2, 3], [4, 5, 6]]
250
+ b = N[[-3, -2, -1, 0], [1, 2, 3, 4], [5, 6, 7, 8]]
251
+ c = a * b
252
+ p c.type #=> L
253
+ c.display #=> [14, 20, 26, 32]
254
+ #=> [23, 38, 53, 68]
255
+
256
+ --- **(n)
257
+ ((|n|)) 乗を計算します。
258
+
259
+ --- /(other)
260
+ 商を計算します。
261
+
262
+ --- rank
263
+ 階数を返します。
264
+
265
+ --- dsum(other)
266
+ 直和を返します。
267
+
268
+ 例:
269
+ a = Algebra.MatrixAlgebra(Integer, 2, 3)[
270
+ [1, 2, 3],
271
+ [4, 5, 6]
272
+ ]
273
+ b = Algebra.MatrixAlgebra(Integer, 3, 2)[
274
+ [-1, -2],
275
+ [-3, -4],
276
+ [-5, -6]
277
+ ]
278
+ (a.dsum b).display #=> 1, 2, 3, 0, 0
279
+ #=> 4, 5, 6, 0, 0
280
+ #=> 0, 0, 0, -1, -2
281
+ #=> 0, 0, 0, -3, -4
282
+ #=> 0, 0, 0, -5, -6
283
+
284
+ --- convert_to(ring)
285
+ ((|self|)) の各成分を行列環 ((|ring|)) にコンバートします。
286
+
287
+ Example:
288
+ require "matrix-algebra"
289
+ require "residue-class-ring"
290
+ Z3 = Algebra.ResidueClassRing(Integer, 3)
291
+ a = Algebra.MatrixAlgebra(Integer, 2, 3)[
292
+ [1, 2, 3],
293
+ [4, 5, 6]
294
+ ]
295
+ a.convert_to(Algebra.MatrixAlgebra(Z3, 2, 3)).display
296
+ #=> 1, 2, 0
297
+ #=> 1, 2, 0
298
+
299
+ --- to_ary
300
+ ((|to_a|)) を返します。((|to_a|)) は ((|Enumerable|)) で定義されています。
301
+
302
+ --- flatten
303
+ ((|to_a.flatten|)) を返します。
304
+
305
+ --- diag
306
+ 対角成分を配列で返します。
307
+
308
+ --- transpose
309
+ 転置行列を返します。
310
+
311
+ 例:
312
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
313
+ a = M.new([[1, 2, 3], [4, 5, 6]])
314
+ Mt = M.transpose
315
+ b = a.transpose
316
+ p b.type #=> Mt
317
+ b.display #=> [1, 4]
318
+ #=> [2, 5]
319
+ #=> [3, 6]
320
+
321
+ #--- to_s
322
+
323
+ --- dup
324
+ 複製します。
325
+
326
+ 例:
327
+ M = Algebra.MatrixAlgebra(Integer, 2, 3)
328
+ a = M.new([[1, 2, 3], [4, 5, 6]])
329
+ b = a.dup
330
+ b[1, 1] = 50
331
+ a.display #=> [1, 2, 3]
332
+ #=> [4, 5, 6]
333
+ b.display #=> [1, 2, 3]
334
+ #=> [4, 50, 6]
335
+
336
+ --- display([out])
337
+ 行列を ((|out|)) に表示します。((|out|)) が省略されると ((|$stdout|))
338
+ に表示します。
339
+
340
+ #--- inspect
341
+
342
+ = Algebra::Vector
343
+ ((*(縦ベクトルクラス)*))
344
+
345
+ ベクトルのクラスです。
346
+
347
+ == スーパークラス:
348
+
349
+ * ((|Algebra::MatrixAlgebra|))
350
+
351
+ == インクルードしているモジュール:
352
+
353
+ なし
354
+
355
+ == 関連する関数:
356
+
357
+ --- Algebra.Vector(ring, n)
358
+ ((<Algebra::Vector::create>))(ring, n) と同じです。
359
+
360
+ == クラスメソッド:
361
+
362
+ --- Algebra::Vector::create(ring, n)
363
+ 環 ((|ring|)) を要素とする, ((|n|)) 次元のベクトル(縦ベクトル)
364
+ 表現するクラスを生成します。
365
+
366
+ このメソッドの戻り値は ((<Algebra::Vector>)) クラスのサブクラス
367
+ です。このサブクラスにはクラスメソッドとして ((|ground|)) と
368
+ ((|size|)) が定義され、それぞれ、基底となる環 ((|ring|))、
369
+ サイズ ((|n|)) を返します。
370
+
371
+ 実際にベクトルを作るにはクラスメソッド ((|new|)),
372
+ ((|matrix|)),
373
+ ((|[]|)) を使います。
374
+
375
+ ((<Algebra::Vector>)) は ((|n|)) 行 1 列の
376
+ ((<Algebra::MatrixAlgebra>)) と同一視されます。
377
+
378
+ --- Algebra::Vector::new(array)
379
+ ((|array|)) を配列とするとき、それを要素とす
380
+ る縦ベクトルを返します。
381
+
382
+ 例:
383
+ V = Algebra.Vector(Integer, 3)
384
+ a = V.new([1, 2, 3])
385
+ a.display
386
+ #=> [1]
387
+ #=> [2]
388
+ #=> [3]
389
+
390
+ --- Algebra::Vector::vector{|i| ... }
391
+ 第 ((|i|)) 成分を ... にしたベクトルを返します。
392
+
393
+ 例:
394
+ V = Algebra.Vector(Integer, 3)
395
+ a = V.vector{|j| j + 1}
396
+ a.display
397
+ #=> [1]
398
+ #=> [2]
399
+ #=> [3]
400
+
401
+ --- Algebra::Vector::matrix{|i, j| ... }
402
+ 第 ((|i|)) 成分を ... にしたベクトルを返します。
403
+ ((|j|)) には常に 0 が代入されます。
404
+
405
+ == メソッド:
406
+
407
+ --- size
408
+ 次元を返します。
409
+
410
+ --- to_a
411
+ 各成分を配列にして返します。
412
+
413
+ --- transpose
414
+ 横ベクトル ((<Algebra::Covector>)) に転置します。
415
+
416
+ --- inner_product(other)
417
+ ((|other|)) との内積を返します。
418
+
419
+ --- inner_product_complex(other)
420
+ ((|other|)) との内積を返します。
421
+ (({inner_product(other.conjugate)}))と同じです。
422
+
423
+ --- norm2
424
+ ノルムを返します。
425
+ (({inner_product(self)}))と同じです。
426
+
427
+ --- norm2_complex
428
+ ノルムを返します。
429
+ (({inner_product(self.conjugate)}))と同じです。
430
+
431
+
432
+ = Algebra::Covector
433
+ ((*(横ベクトルクラス)*))
434
+
435
+ ベクトルのクラスです。
436
+
437
+ == スーパークラス:
438
+ * ((|Algebra::MatrixAlgebra|))
439
+
440
+ == インクルードしているモジュール:
441
+
442
+ なし
443
+
444
+ == 関連する関数:
445
+
446
+ --- Algebra.Covector(ring, n)
447
+ ((<Algebra::Covector::create>)) (ring n)と同じです。
448
+
449
+ == クラスメソッド:
450
+
451
+ --- Algebra::Covector::create(ring, n)
452
+ 環 ((|ring|)) を要素とする, ((|n|)) 次元のベクトル(横ベクトル)
453
+ 表現するクラスを生成します。
454
+
455
+ このメソッドの戻り値は ((<Algebra::Covector>)) クラスのサブクラス
456
+ です。このサブクラスにはクラスメソッドとして ((|ground|)) と
457
+ ((|size|)) が定義され、それぞれ、基底となる環 ((|ring|))、
458
+ サイズ ((|n|)) を返します。
459
+
460
+ 実際にベクトルを作るにはクラスメソッド ((|new|)),
461
+ ((|matrix|)),
462
+ ((|[]|)) を使います。
463
+
464
+ ((<Algebra::Covector>)) は 1 行 ((|n|)) 列の ((<Algebra::MatrixAlgebra>)) と
465
+ 同一視されます。
466
+
467
+ --- Algebra::Covector::new(array)
468
+ ((|array|)) を配列とするとき、それを要素とす
469
+ る横ベクトルを返します。
470
+
471
+ 例:
472
+ V = Algebra.Covector(Integer, 3)
473
+ a = V.new([1, 2, 3])
474
+ a.display
475
+ #=> [1, 2, 3]
476
+
477
+ --- Algebra::Covector::covector{|j| ... }
478
+ 第 j 成分を ... にしたベクトルを返します。
479
+
480
+ 例:
481
+ V = Algebra.Covector(Integer, 3)
482
+ a = V.covector{|j| j + 1}
483
+ a.display
484
+ #=> [1, 2, 3]
485
+
486
+ --- Algebra::Covector::matrix{|i, j| ... }
487
+ 第 j 成分を ... にしたベクトルを返します。i には常に 0 が代入されます。
488
+
489
+ == メソッド:
490
+
491
+ --- size
492
+ 次元を返します。
493
+
494
+ --- to_a
495
+ 各成分を配列にして返します。
496
+
497
+ --- transpose
498
+ 横ベクトル ((<Algebra::Vector>)) に転置します。
499
+
500
+ --- inner_product(other)
501
+ ((|other|)) との内積を返します。
502
+
503
+ --- inner_product_complex(other)
504
+ ((|other|)) との内積を返します。
505
+ (({inner_product(other.conjugate)}))と同じです。
506
+
507
+ --- norm2
508
+ ノルムを返します。
509
+ (({inner_product(self)}))と同じです。
510
+
511
+ --- norm2_complex
512
+ ノルムを返します。
513
+ (({inner_product(self.conjugate)}))と同じです。
514
+
515
+ = Algebra::SquareMatrix
516
+ ((*(正方行列環クラス)*))
517
+
518
+ 正方行列の作る環を表現するクラスです。
519
+
520
+ == スーパークラス:
521
+
522
+ * ((|Algebra::MatrixAlgebra|))
523
+
524
+ == インクルードしているモジュール:
525
+
526
+ なし
527
+
528
+ == 関連する関数:
529
+
530
+ --- Algebra.SquareMatrix(ring, size)
531
+ ((<Algebra::SquareMatrix::create>))(ring, n) と同じです。
532
+
533
+ == クラスメソッド:
534
+
535
+ --- Algebra::SquareMatrix::create(ring, n)
536
+
537
+ 正方行列表現するクラスを生成します。
538
+
539
+ このメソッドの戻り値は
540
+ ((<Algebra::SquareMatrix>)) クラスのサブクラス
541
+ です。このサブクラスにはクラスメソッドとして
542
+ ((|ground|)) と
543
+ ((|size|)) が定義され、それぞれ、基底となる環 ((|ring|))、
544
+ サイズ ((|n|)) を返します。
545
+
546
+ SquareMatrix は ((|n|)) 行 ((|n|)) 列の Algebra::MatrixAlgebra と同一視されます。
547
+
548
+ 実際に行列を作るにはクラスメソッド ((|new|)),
549
+ ((|matrix|)),
550
+ ((|[]|)) を使います。
551
+
552
+ --- Algebra::SquareMatrix.determinant(aa)
553
+ 配列の配列 ((|aa|)) の行列式を返します。
554
+
555
+ --- Algebra::SquareMatrix.det(aa)
556
+ ((<Algebra::SquareMatrix.determinat>))と同じです。
557
+
558
+ --- Algebra::SquareMatrix::unity
559
+ 単位行列を返します。
560
+
561
+ --- Algebra::SquareMatrix::zero
562
+ 零行列を返します。
563
+
564
+ --- Algebra::SquareMatrix.const(x)
565
+ 成分が ((|x|)) のスカラー行列を返します。
566
+
567
+ #--- self.regulate(x)
568
+
569
+ == メソッド
570
+ --- size
571
+ サイズを返します。
572
+
573
+ --- const(x)
574
+ 成分が ((|x|)) のスカラー行列を返します。
575
+ #--- self.matrices
576
+ --- determinant
577
+ 行列式を返します。
578
+
579
+ --- inverse
580
+ 逆行列を返します。
581
+
582
+ --- /(other)
583
+ (({self * other.inverse})) を返します。((|other|)) がスカラーなら
584
+ 各要素を ((|other|)) で割ります。
585
+
586
+ #--- sign(a)
587
+ #--- perm
588
+
589
+ --- char_polynomial(ring)
590
+ ((|ring|)) に多項式環を与えると、特性多項式を返します。
591
+
592
+ --- char_matrix(ring)
593
+ ((|ring|)) に多項式環を与えると、特性行列を返します。
594
+
595
+ --- _char_matrix(poly_ring_matrix)
596
+ ((|poly_ring_matrix|)) に多項式成分の行列環を与えると、特性行列を返します。
597
+
598
+ = Algebra::GaussianElimination
599
+ ((*(ガウスの消去法モジュール)*))
600
+
601
+ ガウスの掃き出し法を実現するモジュールです。
602
+
603
+ == ファイル名:
604
+ ((|gaussian-elimination.rb|))
605
+
606
+ == インクルードしているモジュール:
607
+
608
+ なし
609
+
610
+ == クラスメソッド:
611
+
612
+ なし
613
+
614
+ == メソッド
615
+
616
+ --- swap_r!(i, j)
617
+ ((|i|)) 行と ((|j|)) 行を入れ換えます。
618
+
619
+ --- swap_r(i, j)
620
+ ((|i|)) 行と ((|j|)) 行を入れ換えたものを返します。
621
+
622
+ --- swap_c!(i, j)
623
+ ((|i|)) 列と ((|j|)) 列を入れ換えます。
624
+
625
+ --- swap_c(i, j)
626
+ ((|i|)) 列と ((|j|)) 列を入れ換えたものを返します。
627
+
628
+ --- multiply_r!(i, c)
629
+ ((|i|)) 行目を ((|c|)) 倍します。
630
+
631
+ --- multiply_r(i, c)
632
+ ((|i|)) 行目を ((|c|)) 倍したものを返します。
633
+
634
+ --- multiply_c!(j, c)
635
+ ((|j|)) 列目を ((|c|)) 倍します。
636
+
637
+ --- multiply_c(j, c)
638
+ ((|j|)) 列目を ((|c|)) 倍したものを返します。
639
+
640
+ --- divide_r!(i, c)
641
+ ((|i|)) 行目を ((|c|)) で割ります。
642
+
643
+ --- divide_r(i, c)
644
+ ((|i|)) 行目を ((|c|)) 割ったものを返します。
645
+
646
+ --- divide_c!(j, c)
647
+ ((|j|)) 列目を ((|c|)) で割ります。
648
+
649
+ --- divide_c(j, c)
650
+ ((|j|)) 列目を ((|c|)) 割ったものを返します。
651
+
652
+ --- mix_r!(i, j, c)
653
+ ((|i|)) 行目に ((|j|)) 行目の ((|c|)) 倍を足します。
654
+
655
+ --- mix_r(i, j, c)
656
+ ((|i|)) 行目に ((|j|)) 行目の ((|c|)) 倍を足したものを返します。
657
+
658
+ --- mix_c!(i, j, c)
659
+ ((|i|)) 列目に ((|j|)) 列目の ((|c|)) 倍を足します。
660
+
661
+ --- mix_c(i, j, c)
662
+ ((|i|)) 列目に ((|j|)) 列目の ((|c|)) 倍を足したものを返します。
663
+
664
+ --- left_eliminate!
665
+ 左からの基本変形で階段行列に変形します。
666
+
667
+ 戻り値は、変形するのに使った正方行列の積とその正方行列の
668
+ 行列式と階数の配列です。
669
+
670
+ 例:
671
+ require "matrix-algebra"
672
+ require "mathn"
673
+ class Rational < Numeric
674
+ def inspect; to_s; end
675
+ end
676
+ M = Algebra.MatrixAlgebra(Rational, 4, 3)
677
+ a = M.matrix{|i, j| i*10 + j}
678
+ b = a.dup
679
+ c, d, e = b.left_eliminate!
680
+ b.display #=> [1, 0, -1]
681
+ #=> [0, 1, 2]
682
+ #=> [0, 0, 0]
683
+ #=> [0, 0, 0]
684
+ c.display #=> [-11/10, 1/10, 0, 0]
685
+ #=> [1, 0, 0, 0]
686
+ #=> [1, -2, 1, 0]
687
+ #=> [2, -3, 0, 1]
688
+ p c*a == b#=> true
689
+ p d #=> 1/10
690
+ p e #=> 2
691
+
692
+ --- left_inverse
693
+ 左からの基本変形による一般逆行列です。
694
+
695
+ --- left_sweep
696
+ 左からの基本変形で階段行列にして返します。
697
+
698
+ --- step_matrix?
699
+ 階段行列であるとき、軸(pivot)の配列を返します。そうでないとき、nil
700
+ を返します。
701
+
702
+ --- kernel_basis
703
+ 右から掛けて零になるベクトルの空間の基底の配列を返します。
704
+ 各基底は ((<Algebra::Vector>)) の要素です。
705
+
706
+ 例:
707
+ require "matrix-algebra"
708
+ require "mathn"
709
+ M = Algebra.MatrixAlgebra(Rational, 5, 4)
710
+ a = M.matrix{|i, j| i + j}
711
+ a.display #=>
712
+ #[0, 1, 2, 3]
713
+ #[1, 2, 3, 4]
714
+ #[2, 3, 4, 5]
715
+ #[3, 4, 5, 6]
716
+ #[4, 5, 6, 7]
717
+ a.kernel_basis.each do |v|
718
+ puts "a * #{v} = #{a * v}"
719
+ #=> a * [1, -2, 1, 0] = [0, 0, 0, 0, 0]
720
+ #=> a * [2, -3, 0, 1] = [0, 0, 0, 0, 0]
721
+ end
722
+
723
+ --- determinant_by_elimination
724
+ 体上の正方行列の行列式を掃き出し法で求めます。
725
+
726
+ =end
727
+