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,227 @@
1
+ ########################################################################
2
+ # #
3
+ # finite-map.rb #
4
+ # #
5
+ ########################################################################
6
+ =begin
7
+ [((<index-ja|URL:index-ja.html>))]
8
+ [((<finite-set-ja|URL:finite-set-ja.html>))]
9
+ ((<Algebra::Map>))
10
+
11
+ = Algebra::Map
12
+ ((*写像クラス*))
13
+
14
+ 写像を表現するクラスです。
15
+
16
+ == ファイル名:
17
+ * ((|finite-map.rb|))
18
+
19
+ == スーパークラス:
20
+ * ((|Set|))
21
+
22
+ == インクルードしているモジュール:
23
+
24
+ * ((|Powers|))
25
+
26
+ == クラスメソッド:
27
+
28
+ --- ::[]([x0 => y0, [x1 => y1, [x2 => y2, ...]]])
29
+ ((|x0|)) の時 ((|y0|)), ((|x1|)) の時 ((|y1|)), ((|x2|)) の時 ((|y2|)),..
30
+ という値を持つ写像を返します。
31
+
32
+ 例:
33
+ require "finite-map"
34
+ include Algebra
35
+ p Map[0 => 10, 1 => 11, 2 => 12] #=> {0 => 10, 1 => 11, 2 => 12}
36
+ p Map[{0 => 10, 1 => 11, 2 => 12}] #=> {0 => 10, 1 => 11, 2 => 12}
37
+ p Map.new(0 => 10, 1 => 11, 2 => 12) #=> {0 => 10, 1 => 11, 2 => 12}
38
+ p Map.new({0 => 10, 1 => 11, 2 => 12}) #=> {0 => 10, 1 => 11, 2 => 12}
39
+ p Map.new_a([0, 10, 1, 11, 2, 12]) #=> {0 => 10, 1 => 11, 2 => 12}
40
+
41
+ --- ::new([x0 => y0, [x1 => y1, [x2 => y2, ...]]])
42
+ ((|x0|)) の時 ((|y0|)), ((|x1|)) の時 ((|y1|)), ((|x2|)) の時 ((|y|)),..
43
+ という値を持つ写像を返します。((<::[]>)) と同じです。
44
+
45
+ --- ::new_a(a)
46
+ 配列 a の偶数番目を定義域の元、奇数番目を値域の元として定義される
47
+ 写像を生成します。
48
+
49
+ --- ::phi([t])
50
+ 空写像(定義域が空集合である写像)を返します。集合 ((|t|)) を
51
+ 引数にすると、それを定義域 ((<target>)) にします。
52
+
53
+ 例:
54
+ p Map.phi #=> {}
55
+ p Map.phi(Set[0, 1]) #=> {}
56
+ p Map.phi(Set[0, 1]).target #=> {0, 1}
57
+
58
+ --- ::empty_set
59
+ ((<::phi>)) のエイリアスです。
60
+
61
+ --- ::singleton(x, y)
62
+ ただ一つの元で構成される集合 (({{x}})) 上で定義された ((|y|)) という
63
+ 値を取る関数を返します。
64
+
65
+
66
+ == メソッド:
67
+
68
+ --- target=(s)
69
+ 写像の値域を ((|s|)) に設定します。((<surjective?>)) などに
70
+ 利用されます。
71
+
72
+ --- codomain=(s)
73
+ ((<target=>)) のエイリアスです。
74
+
75
+ --- target
76
+ 写像の値域を返します。
77
+
78
+ --- codomain
79
+ ((<target>)) のエイリアスです。
80
+
81
+ --- source
82
+ 写像の定義域を返します。
83
+
84
+ 例:
85
+ require "finite-map"
86
+ include Algebra
87
+ m = Map[0 => 10, 1 => 11, 2 => 12]
88
+ p m.source #=> {0, 1, 2}
89
+ p m.target #=> nil
90
+ m.target = Set[10, 11, 12, 13]
91
+ p m.target #=> {10, 11, 12, 13}
92
+
93
+ --- domain
94
+ ((<source>)) のエイリアスです。
95
+
96
+ --- phi([t])
97
+ 値域を ((|t|)) とする空の写像を返します。
98
+
99
+ --- empty_set
100
+ --- null
101
+ ((<phi>)) のエイリアスです。
102
+
103
+ --- call(x)
104
+ 写像の ((|x|)) における値を返します。
105
+
106
+ --- act
107
+ --- []
108
+ ((<call>)) のエイリアスです。
109
+
110
+ --- each
111
+ すべての (({[原像, 像]})) について繰り返すイテレータです。
112
+
113
+ 例:
114
+ require "finite-map"
115
+ include Algebra
116
+ Map[0 => 10, 1 => 11, 2 => 12].each do |x, y|
117
+ p [x, y] #=> [1, 11], [0, 10], [2, 12]
118
+ end
119
+
120
+ --- compose(other)
121
+ ((|self|)) と ((|other|)) の合成写像を返します。
122
+
123
+ 例:
124
+ require "finite-map"
125
+ include Algebra
126
+ f = Map.new(0 => 10, 1 => 11, 2 => 12)
127
+ g = Map.new(10 => 20, 11 => 21, 12 => 22)
128
+ p g * f #=> {0 => 20, 1 => 21, 2 => 22}
129
+
130
+ --- *
131
+ ((<compose>)) のエイリアスです。
132
+
133
+ --- dup
134
+ 自身の複製を返します。値域の値も返します。
135
+
136
+ --- append!(x, y)
137
+ ((|x|)) で ((|y|)) という値を取るように設定します。
138
+
139
+ 例:
140
+ require "finite-map"
141
+ include Algebra
142
+ m = Map[0 => 10, 1 => 11]
143
+ m.append!(2, 12)
144
+ p m #=> {0 => 10, 1 => 11, 2 => 12}
145
+
146
+ --- []=(x, y)
147
+ ((<append!>)) のエイリアスです。
148
+
149
+ --- append(x, y)
150
+ ((<dup>)) の後、((<append!>))(x, y) したものを返します。
151
+
152
+ --- include?(x)
153
+ ((|x|)) が定義域に含まれるとき真を返します。
154
+
155
+ --- contains?(x)
156
+ ((<include?>)) のエイリアスです。
157
+
158
+ --- member?(a)
159
+ ((|a|)) を配列 (({[x, y]})) としたとき、((|x|)) における値が
160
+ ((|y|)) となるとき、真を返します。
161
+
162
+ 例:
163
+ require "finite-map"
164
+ include Algebra
165
+ m = Map[0 => 10, 1 => 11]
166
+ p m.include?(1) #=> true
167
+ p m.member?([1, 11]) #=> true
168
+
169
+ --- has?
170
+ member? のエイリアスです。
171
+
172
+ --- image([s])
173
+ 写像の像を返します。定義域の部分集合 ((|s|)) が与えられれば、
174
+ ((|s|)) の像を返します。
175
+
176
+ --- inv_image(s)
177
+ 集合 ((|s|)) の原像を返します。
178
+
179
+ --- map_s
180
+ 写像の各 [原像, 像] のペアについて繰り返し、ブロックで得た
181
+ 値の集合を返します。
182
+
183
+ 例:
184
+ require "finite-map"
185
+ include Algebra
186
+ p Map.new(0 => 10, 1 => 11, 2 => 12).map_s{|x, y| y - 2*x}
187
+ #=> Set[10, 9, 8]
188
+
189
+ --- map_m
190
+ 写像の各 [原像, 像] のペアについて繰り返し、ブロックで得た
191
+ 値の配列で構成される写像を返します。
192
+
193
+ 例:
194
+ require "finite-map"
195
+ include Algebra
196
+ p Map.new(0 => 10, 1 => 11, 2 => 12).map_m{|x, y| [y, x]}
197
+ #=> {10 => 0, 11 => 1, 12 => 2}
198
+
199
+ --- inverse
200
+ 逆写像を返します。
201
+
202
+ --- inv_coset
203
+ 各像に逆像の集合を対応させる写像を返します。
204
+
205
+ 例:
206
+ require "finite-map"
207
+ include Algebra
208
+ m = Map[0=>0, 1=>0, 2=>2, 3=>2, 4=>0]
209
+ p m.inv_coset #=> {0=>{0, 1, 4}, 2=>{2, 3}}
210
+ m.codomain = Set[0, 1, 2, 3]
211
+ p m.inv_coset #=> {0=>{0, 1, 4}, 1=>{}, 2=>{2, 3}, 3=>{}}
212
+
213
+ --- indentity?
214
+ 恒等写像であるとき、真を返します。
215
+
216
+ --- surjective?
217
+ 全射である時、真を返します。あらかじめ ((<target>)) が指定されて
218
+ いる必要があります。
219
+
220
+ --- injective?
221
+ 単射である時、真を返します。
222
+
223
+ --- bijective?
224
+ 全単射である時、真を返します。あらかじめ ((<target>)) が指定されて
225
+ いる必要があります。
226
+
227
+ =end
@@ -0,0 +1,393 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml">
6
+ <head>
7
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
8
+ <title>doc-ja/finite-set-ja.rd</title>
9
+ <link href="style.css" type="text/css" rel="stylesheet" />
10
+ </head>
11
+ <body>
12
+ <p>[<a href="index-ja.html">index-ja</a>]
13
+ [<a href="finite-map-ja.html">finite-map-ja</a>]
14
+ <a href="#label-0">Algebra::Set</a>
15
+ /
16
+ <a href="#label-81">Enumerable</a></p>
17
+ <h1><a name="label-0" id="label-0">Algebra::Set</a></h1><!-- RDLabel: "Algebra::Set" -->
18
+ <p><em>集合のクラス</em></p>
19
+ <p>集合を表現するクラスです。2つの集合 <var>s</var>, <var>t</var> に関して、
20
+ <var>s</var> が <var>t</var> に含まれる事は <a href="#label-85">all?</a> を使って、</p>
21
+ <pre>s.all?{|x| t.member?(x)}</pre>
22
+ <p>で表現されます。</p>
23
+ <h2><a name="label-1" id="label-1">ファイル名:</a></h2><!-- RDLabel: "ファイル名:" -->
24
+ <ul>
25
+ <li><var>finite-set.rb</var></li>
26
+ </ul>
27
+ <h2><a name="label-2" id="label-2">スーパークラス:</a></h2><!-- RDLabel: "スーパークラス:" -->
28
+ <ul>
29
+ <li><var>Object</var></li>
30
+ </ul>
31
+ <h2><a name="label-3" id="label-3">インクルードしているモジュール:</a></h2><!-- RDLabel: "インクルードしているモジュール:" -->
32
+ <ul>
33
+ <li><var>Enumerable</var></li>
34
+ </ul>
35
+ <h2><a name="label-4" id="label-4">クラスメソッド:</a></h2><!-- RDLabel: "クラスメソッド:" -->
36
+ <dl>
37
+ <dt><a name="label-5" id="label-5"><code>::[[<var>obj0</var>, [<var>obj1</var>, [<var>obj2</var>, ...]]]]</code></a></dt><!-- RDLabel: "::[]" -->
38
+ <dd>
39
+ <p>引数の列から <var>Set</var> オブジェクトを生成します。</p>
40
+ <p>例: 全て {"a", [1, 2], 0} を生成する。</p>
41
+ <pre>require "finite-set"
42
+ p Algebra::Set[0, "a", [1, 2]]
43
+ p Algebra::Set.new(0, "a", [1, 2])
44
+ p Algebra::Set.new_a([0, "a", [1, 2]])
45
+ p Algebra::Set.new_h({0=&gt;true, "a"=&gt;true, [1, 2]=&gt;true})</pre></dd>
46
+ <dt><a name="label-6" id="label-6"><code>::new([<var>obj0</var>, [<var>obj1</var>, [<var>obj2</var>, ...]]])</code></a></dt><!-- RDLabel: "::new" -->
47
+ <dd>
48
+ 引数の列から <var>Set</var> オブジェクトを生成します。</dd>
49
+ <dt><a name="label-7" id="label-7"><code>::new_a(<var>a</var>)</code></a></dt><!-- RDLabel: "::new_a" -->
50
+ <dd>
51
+ 配列 <var>a</var> から <var>Set</var> オブジェクトを生成します。</dd>
52
+ <dt><a name="label-8" id="label-8"><code>::new_h(<var>h</var>)</code></a></dt><!-- RDLabel: "::new_h" -->
53
+ <dd>
54
+ <var>Hash</var> から <var>Set</var> オブジェクトを生成します。</dd>
55
+ <dt><a name="label-9" id="label-9"><code>self.empty_set</code></a></dt><!-- RDLabel: "self.empty_set" -->
56
+ <dd>
57
+ 空集合を生成する。</dd>
58
+ <dt><a name="label-10" id="label-10"><code>::phi</code></a></dt><!-- RDLabel: "::phi" -->
59
+ <dt><a name="label-11" id="label-11"><code>::null</code></a></dt><!-- RDLabel: "::null" -->
60
+ <dd>
61
+ <!-- Reference, RDLabel "::empty_set" doesn't exist --><em class="label-not-found">::empty_set</em><!-- Reference end --> のエイリアスです。</dd>
62
+ <dt><a name="label-12" id="label-12"><code>::singleton(<var>x</var>)</code></a></dt><!-- RDLabel: "::singleton" -->
63
+ <dd>
64
+ <var>x</var> 一元のみで構成される集合を生成します。</dd>
65
+ </dl>
66
+ <h2><a name="label-13" id="label-13">メソッド:</a></h2><!-- RDLabel: "メソッド:" -->
67
+ <dl>
68
+ <dt><a name="label-14" id="label-14"><code>empty_set</code></a></dt><!-- RDLabel: "empty_set" -->
69
+ <dd>
70
+ 空集合を生成する。</dd>
71
+ <dt><a name="label-15" id="label-15"><code>phi</code></a></dt><!-- RDLabel: "phi" -->
72
+ <dt><a name="label-16" id="label-16"><code>null</code></a></dt><!-- RDLabel: "null" -->
73
+ <dd>
74
+ <a href="#label-14">empty_set</a> のエイリアスです。</dd>
75
+ <dt><a name="label-17" id="label-17"><code>empty?</code></a></dt><!-- RDLabel: "empty?" -->
76
+ <dd>
77
+ 空集合であるとき真を返します。</dd>
78
+ <dt><a name="label-18" id="label-18"><code>phi?</code></a></dt><!-- RDLabel: "phi?" -->
79
+ <dt><a name="label-19" id="label-19"><code>empty_set?</code></a></dt><!-- RDLabel: "empty_set?" -->
80
+ <dt><a name="label-20" id="label-20"><code>null?</code></a></dt><!-- RDLabel: "null?" -->
81
+ <dd>
82
+ <a href="#label-17">empty?</a> のエイリアスです。</dd>
83
+ <dt><a name="label-21" id="label-21"><code>singleton(<var>x</var>)</code></a></dt><!-- RDLabel: "singleton" -->
84
+ <dd>
85
+ <var>x</var> 一元のみで構成される集合を生成します。</dd>
86
+ <dt><a name="label-22" id="label-22"><code>singleton?</code></a></dt><!-- RDLabel: "singleton?" -->
87
+ <dd>
88
+ 一元のみで構成される集合であるとき真を返します。</dd>
89
+ <dt><a name="label-23" id="label-23"><code>size</code></a></dt><!-- RDLabel: "size" -->
90
+ <dd>
91
+ 集合の大きさを返します。</dd>
92
+ <dt><a name="label-24" id="label-24"><code>each</code></a></dt><!-- RDLabel: "each" -->
93
+ <dd>
94
+ <p>集合の各要素に関して繰り返します。繰り返しの順番は不定です。</p>
95
+ <p>例: </p>
96
+ <pre>require "finite-set"
97
+ include Algebra
98
+ Set[0, 1, 2].each do |x|
99
+ p x #=&gt; 1, 0, 2
100
+ end</pre></dd>
101
+ <dt><a name="label-25" id="label-25"><code>separate</code></a></dt><!-- RDLabel: "separate" -->
102
+ <dd>
103
+ <p>集合の各要素をブロックパラメータに渡し、ブロックの値を真にする
104
+ もので構成される集合を返します。</p>
105
+ <p>例: </p>
106
+ <pre>require "finite-set"
107
+ include Algebra
108
+ p Set[0, 1, 2, 3].separate{|x| x % 2 == 0} #=&gt; {2, 0}</pre></dd>
109
+ <dt><a name="label-26" id="label-26"><code>select_s</code></a></dt><!-- RDLabel: "select_s" -->
110
+ <dt><a name="label-27" id="label-27"><code>find_all_s</code></a></dt><!-- RDLabel: "find_all_s" -->
111
+ <dd>
112
+ <a href="#label-25">separate</a> のエイリアスです。</dd>
113
+ <dt><a name="label-28" id="label-28"><code>map_s</code></a></dt><!-- RDLabel: "map_s" -->
114
+ <dd>
115
+ <p>集合の各要素をブロックパラメータに渡し、ブロックの値によって
116
+ 構成される集合を返します。</p>
117
+ <p>例: </p>
118
+ <pre>require "finite-set"
119
+ include Algebra
120
+ p Set[0, 1, 2, 3].map_s{|x| x % 2 + 1} #=&gt; {2, 1}</pre></dd>
121
+ <dt><a name="label-29" id="label-29"><code>pick</code></a></dt><!-- RDLabel: "pick" -->
122
+ <dd>
123
+ 集合の要素から一つ選んで値とします。どの要素が選ばれるかは
124
+ 不定です。空集合に対しては <var>nil</var> を返します。</dd>
125
+ <dt><a name="label-30" id="label-30"><code>shift</code></a></dt><!-- RDLabel: "shift" -->
126
+ <dd>
127
+ <p>集合の要素から一つ選んで取り出し値とします。どの要素が選ばれる
128
+ かは不定です。</p>
129
+ <p>例: </p>
130
+ <pre>require "finite-set"
131
+ include Algebra
132
+ s = Set[0, 1, 2, 3]
133
+ p s.shift #=&gt; 2
134
+ p s #=&gt; {0, 1, 3}</pre></dd>
135
+ <dt><a name="label-31" id="label-31"><code>dup</code></a></dt><!-- RDLabel: "dup" -->
136
+ <dd>
137
+ 集合の複製を返します。(内部の Hash の複製によります。)</dd>
138
+ <dt><a name="label-32" id="label-32"><code>append!(<var>x</var>)</code></a></dt><!-- RDLabel: "append!" -->
139
+ <dd>
140
+ 集合に要素 <var>x</var> を付け加えます。返り値は <var>self</var> です。</dd>
141
+ <dt><a name="label-33" id="label-33"><code>push</code></a></dt><!-- RDLabel: "push" -->
142
+ <dt><a name="label-34" id="label-34"><code>&lt;&lt;</code></a></dt><!-- RDLabel: "<<" -->
143
+ <dd>
144
+ <var>append!</var> のエイリアスです。</dd>
145
+ <dt><a name="label-35" id="label-35"><code>append(<var>x</var>)</code></a></dt><!-- RDLabel: "append" -->
146
+ <dd>
147
+ 集合に要素 <var>x</var> を付け加えた複製を返します。</dd>
148
+ <dt><a name="label-36" id="label-36"><code>concat(<var>other</var>)</code></a></dt><!-- RDLabel: "concat" -->
149
+ <dd>
150
+ 集合に別の集合 <var>other</var> の要素を付け加えます。
151
+ (<var>+</var> の破壊版です。)</dd>
152
+ <dt><a name="label-37" id="label-37"><code>rehash</code></a></dt><!-- RDLabel: "rehash" -->
153
+ <dd>
154
+ 内部の <var>Hash</var> オブジェクトを <var>rehash</var> します。</dd>
155
+ <dt><a name="label-38" id="label-38"><code>eql?(<var>other</var>)</code></a></dt><!-- RDLabel: "eql?" -->
156
+ <dd>
157
+ 集合 <var>other</var> と等しいとき、真を返します。
158
+ <code> self &gt;= other and self &lt;= other</code> と同値です。</dd>
159
+ <dt><a name="label-39" id="label-39"><code>==</code></a></dt><!-- RDLabel: "==" -->
160
+ <dd>
161
+ <a href="#label-38">eql?</a> のエイリアスです。</dd>
162
+ <dt><a name="label-40" id="label-40"><code>hash</code></a></dt><!-- RDLabel: "hash" -->
163
+ <dd>
164
+ 自身が <var>Hash</var> あるいは <var>Set</var> の要素となるときに利用される
165
+ ハッシュ値関数です。</dd>
166
+ <dt><a name="label-41" id="label-41"><code>include?(<var>x</var>)</code></a></dt><!-- RDLabel: "include?" -->
167
+ <dd>
168
+ 集合が <var>x</var> を要素としているとき、真を返します。</dd>
169
+ <dt><a name="label-42" id="label-42"><code>member?</code></a></dt><!-- RDLabel: "member?" -->
170
+ <dt><a name="label-43" id="label-43"><code>has?</code></a></dt><!-- RDLabel: "has?" -->
171
+ <dt><a name="label-44" id="label-44"><code>contains?</code></a></dt><!-- RDLabel: "contains?" -->
172
+ <dd>
173
+ <a href="#label-41">include?</a> のエイリアスです。</dd>
174
+ <dt><a name="label-45" id="label-45"><code>superset?(<var>other</var>)</code></a></dt><!-- RDLabel: "superset?" -->
175
+ <dd>
176
+ 集合が他の集合 <var>other</var> を包含するとき真を返します。
177
+ <code>other.all{|x| member?(x)}</code> と同値です。</dd>
178
+ <dt><a name="label-46" id="label-46"><code>&gt;=</code></a></dt><!-- RDLabel: ">=" -->
179
+ <dt><a name="label-47" id="label-47"><code>incl?</code></a></dt><!-- RDLabel: "incl?" -->
180
+ <dd>
181
+ <code>superset?</code> のエイリアスです。</dd>
182
+ <dt><a name="label-48" id="label-48"><code>subset?(<var>other</var>)</code></a></dt><!-- RDLabel: "subset?" -->
183
+ <dd>
184
+ 集合が他の集合 <var>other</var> の部分集合であるとき真を返します。
185
+ <code>self.all{|x| other.member?(x)}</code> と同値です。</dd>
186
+ <dt><a name="label-49" id="label-49"><code>&lt;=</code></a></dt><!-- RDLabel: "<=" -->
187
+ <dt><a name="label-50" id="label-50"><code>part_of?</code></a></dt><!-- RDLabel: "part_of?" -->
188
+ <dd>
189
+ <var>subset?</var> のエイリアスです。</dd>
190
+ <dt><a name="label-51" id="label-51"><code>&lt;(<var>other</var>)</code></a></dt><!-- RDLabel: "<" -->
191
+ <dd>
192
+ <var>self</var> が <var>other</var> の真部分集合の時真を返します。</dd>
193
+ <dt><a name="label-52" id="label-52"><code>&gt;(<var>other</var>)</code></a></dt><!-- RDLabel: ">" -->
194
+ <dd>
195
+ <var>self</var> が <var>other</var> を真に含む時真を返します。</dd>
196
+ <dt><a name="label-53" id="label-53"><code>union([<var>other</var>])</code></a></dt><!-- RDLabel: "union" -->
197
+ <dd>
198
+ <p><var>self</var> と <var>other</var> の合併集合を返します。
199
+ <var>other</var> が省略された場合、自身を集合の集合とみなし、全ての
200
+ 要素の合併を返します。</p>
201
+ <p>例:</p>
202
+ <pre>require "finite-set"
203
+ include Algebra
204
+ p Set[0, 2, 4].cup Set[1, 3] #=&gt; {0, 1, 2, 3, 4}
205
+ s = Set[*(0...15).to_a]
206
+ s2 = s.separate{|x| x % 2 == 0}
207
+ s3 = s.separate{|x| x % 3 == 0}
208
+ s5 = s.separate{|x| x % 5 == 0}
209
+ p Set[s2, s3, s5].union #=&gt; {1, 7, 11, 13}</pre></dd>
210
+ <dt><a name="label-54" id="label-54"><code>|</code></a></dt><!-- RDLabel: "|" -->
211
+ <dt><a name="label-55" id="label-55"><code>+</code></a></dt><!-- RDLabel: "+" -->
212
+ <dt><a name="label-56" id="label-56"><code>cup</code></a></dt><!-- RDLabel: "cup" -->
213
+ <dd>
214
+ <var>union</var> のエイリアスです。</dd>
215
+ <dt><a name="label-57" id="label-57"><code>intersection([<var>other</var>])</code></a></dt><!-- RDLabel: "intersection" -->
216
+ <dd>
217
+ <p><var>self</var> と <var>other</var> の交わりの集合を返します。
218
+ <var>other</var> が省略された場合、自身を集合の集合とみなし、全ての
219
+ 要素の共通部分を返します。</p>
220
+ <p>例:</p>
221
+ <pre>require "finite-set"
222
+ include Algebra
223
+ p Set[0, 2, 4].cap(Set[4, 2, 0]) #=&gt; {0, 2, 4}
224
+ s = Set[*(0..30).to_a]
225
+ s2 = s.separate{|x| x % 2 == 0}
226
+ s3 = s.separate{|x| x % 3 == 0}
227
+ s5 = s.separate{|x| x % 5 == 0}
228
+ p Set[s2, s3, s5].cap #=&gt; {0, 30}</pre></dd>
229
+ <dt><a name="label-58" id="label-58"><code>&amp;</code></a></dt><!-- RDLabel: "&" -->
230
+ <dt><a name="label-59" id="label-59"><code>cap</code></a></dt><!-- RDLabel: "cap" -->
231
+ <dd>
232
+ <var>intersection</var> のエイリアスです。</dd>
233
+ <dt><a name="label-60" id="label-60"><code>difference(<var>other</var>)</code></a></dt><!-- RDLabel: "difference" -->
234
+ <dd>
235
+ <var>self</var> から <var>other</var> に含まれる要素を取り除いたものを返します。</dd>
236
+ <dt><a name="label-61" id="label-61"><code>-</code></a></dt><!-- RDLabel: "-" -->
237
+ <dd>
238
+ <var>difference</var> のエイリアスです。</dd>
239
+ <dt><a name="label-62" id="label-62"><code>each_pair</code></a></dt><!-- RDLabel: "each_pair" -->
240
+ <dd>
241
+ <p>集合から異なる2つの要素を取り出して、ブロックパラメータに
242
+ 代入して繰り返します。</p>
243
+ <p>例: </p>
244
+ <pre>require "finite-set"
245
+ include Algebra
246
+ s = Set.phi
247
+ Set[0, 1, 2].each_pair do |x, y|
248
+ s.push [x, y]
249
+ end
250
+ p s == Set[[0, 1], [0, 2], [1, 2]] #=&gt; true</pre></dd>
251
+ <dt><a name="label-63" id="label-63"><code>each_member(<var>n</var>)</code></a></dt><!-- RDLabel: "each_member" -->
252
+ <dd>
253
+ <p>集合から異なる <var>n</var> 個の要素を取り出して、ブロックパラメータに
254
+ 代入して繰り返します。</p>
255
+ <p>例: </p>
256
+ <pre>require "finite-set"
257
+ include Algebra
258
+ s = Set.phi
259
+ Set[0, 1, 2].each_member(2) do |x, y|
260
+ s.push [x, y]
261
+ end
262
+ p s == Set[[0, 1], [0, 2], [1, 2]] #=&gt; true</pre></dd>
263
+ <dt><a name="label-64" id="label-64"><code>each_subset</code></a></dt><!-- RDLabel: "each_subset" -->
264
+ <dd>
265
+ <p>集合の全ての部分集合をブロックパラメータに代入して繰り返します。</p>
266
+ <p>例: </p>
267
+ <pre>require "finite-set"
268
+ include Algebra
269
+ s = Set.phi
270
+ Set[0, 1, 2].each_subset do |t|
271
+ s.append! t
272
+ end
273
+ p s.size = 2**3 #=&gt; true</pre></dd>
274
+ <dt><a name="label-65" id="label-65"><code>each_non_trivial_subset</code></a></dt><!-- RDLabel: "each_non_trivial_subset" -->
275
+ <dd>
276
+ 集合の空集合でない真部分集合をブロックパラメータに代入して繰り返します。</dd>
277
+ <dt><a name="label-66" id="label-66"><code>power_set</code></a></dt><!-- RDLabel: "power_set" -->
278
+ <dd>
279
+ 集合の全ての部分集合の集合を返します。</dd>
280
+ <dt><a name="label-67" id="label-67"><code>each_product(<var>other</var>)</code></a></dt><!-- RDLabel: "each_product" -->
281
+ <dd>
282
+ <var>self</var> と <var>other</var> の全ての要素 <var>x</var>, <var>y</var> に
283
+ ついて、繰り返します。</dd>
284
+ </dl>
285
+ <pre>例:
286
+ require "finite-set"
287
+ include Algebra
288
+ Set[0, 1].each_prodct(Set[0, 1]) do |x, y|
289
+ p [x, y] #=&gt; [0,0], [0,1], [1,0], [1,1]
290
+ end</pre>
291
+ <dl>
292
+ <dt><a name="label-68" id="label-68"><code>product(<var>other</var>)</code></a></dt><!-- RDLabel: "product" -->
293
+ <dd>
294
+ <p><var>self</var> と <var>other</var> の積集合を返します。積集合の各元
295
+ は配列 <code>[x, y]</code> です。ブロックが与えられた時は、ブロック
296
+ を評価した値で構成される集合を返します。</p>
297
+ <p>例: </p>
298
+ <pre>require "finite-set"
299
+ include Algebra
300
+ p Set[0, 1].product(Set[0, 1]) #=&gt; {[0,0], [0,1], [1,0], [1,1]}
301
+ p Set[0, 1].product(Set[0, 1]){|x, y| x + 2*y} #=&gt; {0, 1, 2, 3]</pre></dd>
302
+ <dt><a name="label-69" id="label-69"><code>*</code></a></dt><!-- RDLabel: "*" -->
303
+ <dd>
304
+ <a href="#label-68">product</a> のエイリアスです。</dd>
305
+ <dt><a name="label-70" id="label-70"><code>equiv_class([<var>equiv</var>])</code></a></dt><!-- RDLabel: "equiv_class" -->
306
+ <dd>
307
+ 集合を同値関係で割った商集合を返します。同値関係の与え方は次の3通りあります。
308
+ <ol>
309
+ <li><p>ブロックの評価値を真にする同値関係</p>
310
+ <pre>require "finite-set"
311
+ include Algebra
312
+ s = Set[0, 1, 2, 3, 4, 5]
313
+ p s.equiv_class{|a, b| (a - b) % 3 == 0} #=&gt; {{0, 3}, {1, 4}, {2, 5}}</pre></li>
314
+ <li><p>引数に与えられたオブジェクトに対するメソッド <var>call(x, y)</var>
315
+ の真偽値による同値関係</p>
316
+ <pre>require "finite-set"
317
+ include Algebra
318
+ o = Object.new
319
+ def o.call(x, y)
320
+ (x - y) % 3 == 0
321
+ end
322
+ s = Set[0, 1, 2, 3, 4, 5]
323
+ p s.equiv_class(o) #=&gt; {{0, 3}, {1, 4}, {2, 5}}</pre></li>
324
+ <li><p>引数に与えられた <var>Symbol</var> に応じたメソッドによる同値関係</p>
325
+ <pre>require "finite-set"
326
+ include Algebra
327
+ s = Set[0, 1, 2, 3, 4, 5]
328
+ def q(x, y)
329
+ (x - y) % 3 == 0
330
+ end
331
+ p s.equiv_class(:q) #=&gt; {{0, 3}, {1, 4}, {2, 5}}</pre></li>
332
+ </ol></dd>
333
+ <dt><a name="label-71" id="label-71"><code>/</code></a></dt><!-- RDLabel: "/" -->
334
+ <dd>
335
+ <a href="#label-70">equiv_class</a> のエイリアスです。</dd>
336
+ <dt><a name="label-72" id="label-72"><code>to_a</code></a></dt><!-- RDLabel: "to_a" -->
337
+ <dd>
338
+ 集合を配列にして返します。要素の並びの順は不定です。</dd>
339
+ <dt><a name="label-73" id="label-73"><code>to_ary</code></a></dt><!-- RDLabel: "to_ary" -->
340
+ <dd>
341
+ <a href="#label-72">to_a</a> のエイリアスです。</dd>
342
+ <dt><a name="label-74" id="label-74"><code>sort</code></a></dt><!-- RDLabel: "sort" -->
343
+ <dd>
344
+ <a href="#label-72">to_a</a> の値をソートして返します。</dd>
345
+ <dt><a name="label-75" id="label-75"><code>power(<var>other</var>)</code></a></dt><!-- RDLabel: "power" -->
346
+ <dd>
347
+ <p><var>other</var> から <var>self</var> への写像全ての集合を返します。
348
+ 写像は <a href="finite-map-ja.html">Map</a> の元として表現されます。</p>
349
+ <p>例: </p>
350
+ <pre>require "finite-map"
351
+ include Algebra
352
+ a = Set[0, 1, 2, 3]
353
+ b = Set[0, 1, 2]
354
+ s =
355
+ p( (a ** b).size ) #=&gt; 4 ** 3 = 64
356
+ p b.surjections(a).size #=&gt; S(3, 4) = 36
357
+ p a.injections(b).size #=&gt; 4P3 = 24</pre></dd>
358
+ <dt><a name="label-76" id="label-76"><code>**</code></a></dt><!-- RDLabel: "**" -->
359
+ <dd>
360
+ <a href="#label-75">power</a> のエイリアスです。</dd>
361
+ <dt><a name="label-77" id="label-77"><code>identity_map</code></a></dt><!-- RDLabel: "identity_map" -->
362
+ <dd>
363
+ 自分への恒等写像を返します。</dd>
364
+ <dt><a name="label-78" id="label-78"><code>surjections(<var>other</var>)</code></a></dt><!-- RDLabel: "surjections" -->
365
+ <dd>
366
+ <var>other</var> から <var>self</var> への全射全ての集合を返します。</dd>
367
+ <dt><a name="label-79" id="label-79"><code>injections(<var>other</var>)</code></a></dt><!-- RDLabel: "injections" -->
368
+ <dd>
369
+ <var>other</var> から <var>self</var> への単射全ての集合を返します。</dd>
370
+ <dt><a name="label-80" id="label-80"><code>bijections(<var>other</var>)</code></a></dt><!-- RDLabel: "bijections" -->
371
+ <dd>
372
+ <var>other</var> から <var>self</var> への全単射全ての集合を返します。</dd>
373
+ </dl>
374
+ <h1><a name="label-81" id="label-81">Enumerable</a></h1><!-- RDLabel: "Enumerable" -->
375
+ <h2><a name="label-82" id="label-82">ファイル名:</a></h2><!-- RDLabel: "ファイル名:" -->
376
+ <ul>
377
+ <li><var>finite-set.rb</var></li>
378
+ </ul>
379
+ <h2><a name="label-83" id="label-83">メソッド:</a></h2><!-- RDLabel: "メソッド:" -->
380
+ <dl>
381
+ <dt><a name="label-84" id="label-84"><code>any?</code></a></dt><!-- RDLabel: "any?" -->
382
+ <dd>
383
+ ブロックを真にする要素があるとき、真を返します。
384
+ <var>Enumerable#find</var> の別名です。(built-in of ruby-1.8)</dd>
385
+ <dt><a name="label-85" id="label-85"><code>all?</code></a></dt><!-- RDLabel: "all?" -->
386
+ <dd>
387
+ <p>全ての要素についてブロックが真であるとき、真を返します。</p>
388
+ <pre>!any?{|x| !yield(x)}</pre>
389
+ <p>と定義されています。(built-in of ruby-1.8)</p></dd>
390
+ </dl>
391
+
392
+ </body>
393
+ </html>