4. 関係計算と関係代数の歴史
論理の代数的定式化は G. Boole に始まる (1847).
集合演算の代数式としての De-Morgan の公式 (1864) .
述語論理に代わる代数の定式化の試み, Peirce 1870.
関係代数の公理化と表現可能性の考察
Tarski 1941, Lyndon 1950, McKenzie 1966.
関係の圏論的考察
MacLane 1961, Puppe 1962, Kawahara 1973.
代数から圏へ (Homogeneous to heterogeneous)
Allegories(寓圏)(Freyd 1990), Dedekind 圏 (Oliver 1980).
点公理と Dedekind 圏の公理化
Furusawa 2015.
† R. D. Maddux, The origin of relation algebras in the development and
axiomaization of the calculus of relations, 1991.
† R. Hirsh, I. Hodkinson, Relation algebras by games, 2002.
† G. Schmidt, Relational Mathematics, 2010.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 4 / 31
5. 関係計算の計算機科学への応用
プログラム理論 (プログラム検証)
The weakest prespecifiacion (Hoare 1987),
Categorical assertion semantics in toposes (Kawahara 1992),
Automated verification of relational while-programs (Berghammer 2014),
Semigroup with if–then–else and halting programs (Jackson 2009).
オートマトン理論, グラフ変換系 (計算モデル)
Applications of relational calculus to computer mathematics (Kawahara
1988),
Relational graph rewritings, (Mizoguchi 1995).
関係データベース, 形式概念解析 (データモデル)
Relational aspects of relational database dependencies, (Okuma 2000),
Formal concepts in Dedekind categories, (Ishida 2008).
† 14th International Conference on Relational and Algebraic Methods in
Computer Science (RAMiCS),
http://mathcs.chapman.edu/ramics2014/
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 5 / 31
6. ブール代数 (1)
B を集合とし, ϕ ∈ B, ∇ ∈ B, ⊔ : B × B → B, − : B → B に対して,
B = (B, ϕ, ∇, ⊔, −) を考えとき, 任意の元 a, b, c ∈ B に対して, 以下の公理
を満たすときに, B をブール代数という.
(a ⊔ b) ⊔ c = a ⊔ (b ⊔ c)
a ⊔ b = b ⊔ a
a ⊔ a = a
−(−b) = b
b ⊔ (−b) = ∇
−∇ = ϕ
a ⊓ (b ⊔ c) = (a ⊓ b) ⊔ (a ⊓ c)
where x ⊓ y = −((−x) ⊔ (−y)).
ϕ ⊔ a = a
※ a ⊑ b を a ⊔ b = b で定め, a − b を a ⊔ (−b) で定める.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 6 / 31
7. ブール代数 (2)
集合 X の部分集合全体を 2X とし, 集合 X の部分集合 A,B に対して,
A ⊔ B を和集合, −A を補集合 (−A = X − A) とするとき,
F(X) = (2X, ϕ, X, ⊔, −) はブール代数になる.
定理 (ストーンの表現定理 (1936))
Boole 代数の公理系を満たす代数系 B はある集合 X の部分集合によって
作られる Boole 代数 F(X) と同型である.
命題
有限個の元を持つ Boole 代数は, ある有限集合の部分集合全体からなる
Boole 代数と同型である. 従って, 有限の Boole 代数はある自然数 n と 1
対 1 対応し, ブール代数の元の数は 2n である.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 7 / 31
8. 関係代数 (1)
R を集合とし, ϕ, ∇, id ∈ R, ⊔ : R × R → R, · : R × R → R, − : R → R,
( )♯ : R → R に対して, R = (R, ⊔, −, ϕ, ∇, id,♯ , ·) を考える. 任意の元
a, b, c ∈ B に対して, 以下の公理を満たすときに, R を関係代数という.
(R, ⊔, −, ϕ, ∇) はブール代数である.
(R, ·, id) は id を単位元とする半群で
ある.
(a · b) · c = a · (b · c)
a · id = id · a = a
以下の 3 つの条件は同値である.
(a · b) ⊓ c = ϕ
(a♯
· c) ⊓ b = ϕ
a ⊓ (c · b♯
) = ϕ
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 8 / 31
9. 関係代数 (2)
集合 X に対して, X × X の部分集合全体を 2X×X とし, 集合 X × X の部分
集合 A,B に対して,
A · B = {(x, y) | ∃u, (x, u) ∈ A ∧ (u, y) ∈ B}
idX = {(x, x) | x ∈ X}
A♯
= {(y, x) | (x, y) ∈ A}
とするとき, F(X × X) = (2X×X, ⊔, −, ϕ, X × X, idX, ( )♯, ·) は関係代数に
なる.
例
関係 A ∈ 2X×X に対して, 式 A · A ⊆ A が, 推移律
(a, b) ∈ A ∧ (b, c) ∈ A ⇒ (a, c) ∈ A
を表す. 集合論の論理式で表現される性質を関係演算の計算式で表現し,
数式処理で証明することが出来る.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 9 / 31
11. McKenzie 代数
A = {id, x, y, y♯} として, A ∪ {ϕ, ∇} で生成される (すなわち, 任意の元は
A ∪ {ϕ, ∇} の元の有限個の和 (⊔) である) 関係代数で, 最小元を ϕ, 最大元
を ∇ とする.
x = x♯, id♯
= id
For any α ∈ A, ϕ ⊏ α ⊏ ∇ and α ⊓ α = α.
For any α, β ∈ A, if α β then α ⊓ β = ϕ.
連接 (·) 演算表を以下で定義する.
· id x y y♯
id id x y y♯
x x id ⊔ y ⊔ y♯ x ⊔ y x ⊔ y♯
y y x ⊔ y y ∇
y♯ y♯ x ⊔ y♯ ∇ y♯
このとき, A で生成される関係代数が唯一定まる. この関係代数を
McKenzie 代数と呼ぶ.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 11 / 31
12. 関係代数の表現不可能性
予想
関係代数はある集合 X の直積集合の部分集合によって作られる関係代数
F(X × X) と同型である.
定理 (McKenzie 1970)
McKenzie 代数は (D2) を満たさない. 実際, a = c = d = f = g = x,
b = y, e = y♯ とすると, (D2) が成立しない. すなわち, 予想は成立しない.
上記の定理の証明は代入して規則に従い (D2) を計算することにより示さ
れる.
※関係代数の表現不可能性を最初に示したのは Lyndon 1950 である.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 12 / 31
14. Dedekind 圏 (関係計算の圏)(2)
※ 記号の定義を以下に整理しておく.
(1) A relation α of a set A into another set B is a subset of the Cartesian
product A × B and denoted by α : A ⇁ B.
(2) The inverse relation α♯ : B ⇁ A of α is a relation such that
(b, a) ∈ α♯ if and only if (a, b) ∈ α.
(3) The composite αβ : A ⇁ C of α : A ⇁ B followed by β : B ⇁ C is
a relation such that (a, c) ∈ αβ if and only if there exists b ∈ B with
(a, b) ∈ α and (b, c) ∈ β.
(4) As a relation of a set A into a set B is a subset of A × B, the inclusion
relation, union, intersection and difference of them are available as
usual and denoted by ⊑, ⊔, ⊓ and −, respectively.
(5) The identity relation idA : A ⇁ A is a relation with
idA = {(a, a) ∈ A × A|a ∈ A}.
(6) The empty relation ϕ ⊆ A × B is denoted by 0AB. The entire set
A × B is called the universal relation and denoted by ∇AB.
(7) The one point set {∗} is denoted by I. We note that ∇II = idI.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 14 / 31
16. Dedekind 圏の公理と補題の Coq による実装 (2)
A, B を eqType として, A から B への関係の型を (Rel A B) と書き,
A → B → Prop として定義する. 以下に関係の表記についてまとめる.
数式 Coq Notation
逆関係 α♯ (inverse_relation α) (α #)
合成関係 αβ (composite α β) (α・β)
恒等関係 idA (identity_relation A) (Id A)
空関係 ϕAB (empty_relation A B) (φ A B)
全関係 ∇AB (universal_relation A B) (∇ A B)
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 16 / 31
17. 写像の性質の関係式による定義 (1)
関係が関数 (total function) であること, 単射 (injection) であること, 全射
(surjection) であることなどは論理式ではなく, 全て関係式で定式化され
ます.
定義
Let α : A ⇁ B be a relation.
(1) α is total, if idA ⊑ αα♯.
(2) α is univalent, if α♯α ⊑ idB.
(3) A univalent relation is also called as a partial function.
(4) α is (total) function, if α is total and univalent.
(3) A (total) function α : A ⇁ B is surjection, if α♯α = idB.
(4) A (total) function α : A ⇁ B is injection, if αα♯ = idA.
(5) A (total) function is bijection, if it is surjection and injection.
Note. We use letters f, g, h, · · · for (total) functions. For a function,
surjection and injection, we use an arrow symbol →, ↠ and ↣.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 17 / 31
18. 写像の性質の関係式による定義 (2)
Definition total_id {A B : eqType} (alpha : Rel A B) :=
(Id A) ≡ (alpha ・ (alpha #)).
Definition univalent_id {A B : eqType} (alpha : Rel A B) :=
((alpha #) ・ alpha) ≡ (Id B).
Definition total_r {A B : eqType} (alpha : Rel A B) :=
(Id A) ⊆ (alpha ・ (alpha #)).
Definition univalent_r {A B : eqType} (alpha : Rel A B) :=
((alpha #) ・ alpha) ⊆ (Id B).
Definition function_r {A B : eqType} (alpha : Rel A B) :=
(total_r alpha) / (univalent_r alpha).
Definition surjection_r {A B : eqType} (alpha : Rel A B) :=
(function_r alpha) / (total_r (alpha #)).
Definition injection_r {A B : eqType} (alpha : Rel A B) :=
(function_r alpha) / (univalent_r (alpha #)).
Definition bijection_r {A B : eqType} (alpha : Rel A B) :=
(surjection_r alpha) / (injection_r alpha).
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 18 / 31
19. 単射の合成は単射である (論理式で定式化)
命題
f : X → Y, g : Y → Z が単射のとき, f · g : X → Z は単射である.
(∀x, x′ ∈ X, ∀y ∈ Y, (x, y) ∈ f ∧ (x′, y) ∈ f ⇒ x = x′)
∧ (∀y, y′ ∈ Y, ∀z ∈ Z, (y, z) ∈ g ∧ (y′, z) ∈ g ⇒ y = y′)
⇒ (∀x, x′ ∈ X, ∀z ∈ Z, ((x, z) ∈ f · g) ∧ ((x′, z) ∈ f · g))
⇒ x = x′
ここで,
(x, z) ∈ f · g ⇔ ∃y ∈ Y, (x, y) ∈ f ∧ (y, z) ∈ g
(x′
, z) ∈ f · g ⇔ ∃y′
∈ Y, (x′
, y′
) ∈ f ∧ (y′
, z) ∈ g
※ 補題を準備しておけば良いかもしれないが, 自動証明への道筋が明ら
かでない.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 19 / 31
20. 単射の合成は単射である (論理式で定式化)(2)
Theorem injection_composite_set
{X Y Z : eqType} {f : Rel X Y} {g : Rel Y Z}:
(forall (x x’ : X)(y : Y), f x y / f x’ y - x = x’) /
(forall (y y’ : Y)(z : Z), g y z / g y’ z - y = y’) -
(forall (x x’ : X)(z : Z),
(exists y : Y, f x y / g y z) / (exists y’ : Y, f x’ y’ / g y’ z) - x = x’).
Proof.
intuition.
move:H2.
elim = y H4.
apply (H0 x x’ y).
split.
apply (proj1 H4).
move:H3.
elim =y’ H5.
have: y=y’.
apply (H1 y y’ z).
apply (conj (proj2 H4) (proj2 H5)).
move = H6.
rewrite -H6 in H5.
apply (proj1 H5).
Qed.
※ 少し面倒だが, 手動で証明を与えることは出来る.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 20 / 31
21. 単射の合成は単射である (関係式で定式化)
命題
f : X → Y, g : Y → Z が単射のとき, f · g : X → Z は単射である.
( f · f♯
⊑ idX) ∧ (g · g♯
⊑ idY) ⇒ ((f · g) · ( f · g)♯
⊑ idX)
( f · g) · ( f · g)♯
= ( f · g) · (g♯ · f♯) (∵ (α · β)♯ = β♯ · α♯)
= f · (g · g♯) · f♯ (∵ 結合法則)
⊑ f · idY · f♯ (∵ 仮定 g · g♯ ⊑ idY)
= f · f♯ (∵ idYは単位元)
⊑ idX (∵ 仮定 f · f♯ ⊑ idX)
全ての性質が関係式で定式化されており, 証明は式変形のみで行える.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 21 / 31
22. 単射の合成は単射である (関係式で定式化)(2)
Theorem injection_composite_rel_tactic
{X Y Z : eqType} {f : Rel X Y} {g : Rel Y Z}:
(f ・ (f #)) ⊆ Id X / (g ・ (g #)) ⊆ Id Y -
((f ・ g) ・ ((f ・ g) #)) ⊆ Id X.
Proof.
Rel_simpl2.
Qed.
※ この例の場合は, 式変形は全て自動 (Tactic) で証明出来た.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 22 / 31
23. 基本的な補題たち
Lemma composite_include_left
{A B C : eqType} {b : Rel B C} {a a’ : Rel A B}: (a ⊆ a’) - ((a ・ b) ⊆ (a’ ・ b)).
Lemma composite_include_left_a_id
{A B : eqType} {b : Rel A B} {a : Rel A A}: (a ⊆ Id A) - ((a ・ b) ⊆ b).
Lemma composite_include_left_id_a
{A B : eqType} {b : Rel A B} {a : Rel A A}: (Id A ⊆ a) - (b ⊆ (a ・ b)).
Lemma composite_include_right
{A B C : eqType} {b b’ : Rel B C} {a : Rel A B}: (b ⊆ b’) - ((a ・ b) ⊆ (a ・ b’)).
Lemma composite_include_right_b_id
{A B : eqType} {b : Rel B B} {a : Rel A B}: (b ⊆ Id B) - ((a ・ b) ⊆ a).
Lemma composite_include_right_id_b
{A B : eqType} {b : Rel B B} {a : Rel A B}: (Id B ⊆ b) - (a ⊆ (a ・ b)).
Lemma composite_include_left_right
{A B C D : eqType} {b b’ : Rel B C} {a : Rel A B} {c : Rel C D}:
(b ⊆ b’) - ((a ・ (b ・ c)) ⊆ (a ・ (b’ ・ c))).
Lemma composite_include_left_right_b_id
{A B C : eqType} {b : Rel B B} {a : Rel A B} {c : Rel B C}:
(b ⊆ Id B) - ((a ・ (b ・ c)) ⊆ (a ・ c)).
Lemma composite_include_left_right_id_b
{A B C : eqType} {b : Rel B B} {a : Rel A B} {c : Rel B C}:
(Id B ⊆ b) - ((a ・ c) ⊆ (a ・ (b ・ c))).
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 23 / 31
28. 参考文献 I
R. Berghammer, P. H¨ofner, and I. Stucke.
Automated verification of relational while-programs.
In P. H¨ofner, P. Jipsen, W. Kahl, and M. E. M¨uller, editors, Relational and Algebraic Methods in
Computer Science (RAMiCS’14), volume 8428 of Lecture Notes in Computer Sciences, pages
173–190, 2014.
Peter J. Freyd and Andre Scedrov.
Categories, allegories, volume 39 of North-Holland mathematical library.
North-Holland, Amsterdam, 1990.
Hitoshi Furusawa and Yasuo Kawahara.
Point axioms and related conditions in dedekind categories.
Journal of Logical and Algebraic Methods in Programming, 84:359–376, 2015.
Robin Hirsh and Ian Hodkinson.
Relation algebras by games, volume 147 of Studies in Logic and Foundations.
North-Holland, Amsterdam, 2002.
C. A. R. Hoare and HE Jifeng.
The weakest prespecification.
Information processing letter, 24:127–132., 1987.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 28 / 31
29. 参考文献 II
T. Ishida, K. Honda, and Y. Kawahara.
Formal concepts in Dedekind categories.
In R. Berghammer, B. M¨oller, and G. Struth, editors, Relations and Kleene Algebras in Computer
Science, volume 4988 of Lecture Notes in Computer Science, pages 221–233, 2008.
Marcel Jackson and Tim Stokes.
Semigroup with if–then–else and halting programs.
International Journal of Algebra and Computation, 19(7):937–961, 2009.
Y. Kawahara.
Applications of relational calculus to computer mathematics.
Bull. Inform. Cybernet., 23:67–78, 1988.
Y. Kawahara and Y. Mizoguchi.
Categorical assertion semantics in toposes.
Advances in Software Science and Technology, 4:137–150, 1992.
Saunder Mac Lane.
Categories for the working mathematicians.
Springer-Verlag, 1971.
R. C. Lyndon.
The representation of relational algebras.
Annuals of Mathematics, 51:707–729, 1950.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 29 / 31
30. 参考文献 III
Roger D. Maddux.
The origin of relation algebras in the development and axiomatization of the calculus of relations.
Studia Logica: An International Journal for Symbolic Logic, 50:421–455, 1991.
Ralph N. McKenzie, George F. McNulty, and Walter F. Tylor.
Algebras, lattices, varieties.
The Wadsworth Books/Cole mathematics series. Wadsworth Books, 1987.
Y. Mizoguchi and Y. Kawahara.
Relational graph rewritings.
Theoret. Comput. Sci., 141:311–328, 1995.
A. De Morgan.
On the syllogism: IV, and on the logic of relations.
Transactions of the Cambridge Philosophcal Society, pages 331–358, 1966.
H. Okuma and Y. Kawahara.
Relational aspects of relational database dependencies.
Bull. Inform. Cybernet., pages 91–104, 2000.
J. P. Oliver and D. Serrato.
Cat´egories de dedekind morphismes dans les cat´egories de Shr¨oder.
C. R. Acad. Sci. Paris, 290:939–941, 1980.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 30 / 31
31. 参考文献 IV
C. S. Peirce.
Note B: the logic of relatives, volume iviii+vi+203, pages 187–203.
John Benjamins Publishing Co., Amsterdam and Philadelphia., 1983.
G. Schmidt.
Relational Mathematics.
Cambridge University Press, 2010.
Marshall H. Stone.
The theory of representations of Boolean algebras.
Transactions of American Mathematical Society, 40, 1936.
A. Tarski.
On the calculus of relations.
Journal of Symbolic Logic, 6:73–89, 1941.
溝口佳寛 (九大 IMI) Coq 関係計算ライブラリ 数式処理学会 2015/6/6 31 / 31