2014-01-16 12:37:36 +00:00
|
|
|
import macros
|
|
|
|
|
|
|
|
definition reflexive {A : TypeU} (R : A → A → Bool) := ∀ x, R x x
|
|
|
|
definition transitive {A : TypeU} (R : A → A → Bool) := ∀ x y z, R x y → R y z → R x z
|
|
|
|
definition subrelation {A : TypeU} (R1 : A → A → Bool) (R2 : A → A → Bool) := ∀ x y, R1 x y → R2 x y
|
|
|
|
infix 50 ⊆ : subrelation
|
|
|
|
|
|
|
|
-- (tcls R) is the transitive closure of relation R
|
|
|
|
-- We define it as the intersection of all transitive relations containing R
|
|
|
|
definition tcls {A : TypeU} (R : A → A → Bool) (a b : A)
|
|
|
|
:= ∀ P, (reflexive P) → (transitive P) → (R ⊆ P) → P a b
|
2014-01-16 12:52:45 +00:00
|
|
|
notation 65 _⁺ : tcls -- use superscript + as notation for transitive closure
|
2014-01-16 12:37:36 +00:00
|
|
|
|
2014-01-16 12:52:45 +00:00
|
|
|
theorem tcls_trans {A : TypeU} {R : A → A → Bool} {a b c : A} (Hab : R⁺ a b) (Hbc : R⁺ b c) : R⁺ a c
|
2014-01-16 12:37:36 +00:00
|
|
|
:= take P, assume Hrefl Htrans Hsub,
|
2014-01-16 12:52:45 +00:00
|
|
|
let Pab : P a b := Hab P Hrefl Htrans Hsub,
|
|
|
|
Pbc : P b c := Hbc P Hrefl Htrans Hsub
|
2014-01-16 12:37:36 +00:00
|
|
|
in Htrans a b c Pab Pbc
|
|
|
|
|
2014-01-16 12:52:45 +00:00
|
|
|
theorem tcls_refl {A : TypeU} (R : A → A → Bool) : ∀ a, R⁺ a a
|
2014-01-16 12:37:36 +00:00
|
|
|
:= take a P, assume Hrefl Htrans Hsub,
|
|
|
|
Hrefl a
|
|
|
|
|
2014-01-16 12:52:45 +00:00
|
|
|
theorem tcls_sub {A : TypeU} {R : A → A → Bool} {a b : A} (H : R a b) : R⁺ a b
|
2014-01-16 12:37:36 +00:00
|
|
|
:= take P, assume Hrefl Htrans Hsub,
|
|
|
|
Hsub a b H
|
|
|
|
|
2014-01-16 12:52:45 +00:00
|
|
|
theorem tcls_step {A : TypeU} {R : A → A → Bool} {a b c : A} (H1 : R a b) (H2 : R⁺ b c) : R⁺ a c
|
2014-01-16 12:37:36 +00:00
|
|
|
:= take P, assume Hrefl Htrans Hsub,
|
|
|
|
Htrans a b c (Hsub a b H1) (H2 P Hrefl Htrans Hsub)
|
|
|
|
|
2014-01-16 12:52:45 +00:00
|
|
|
theorem tcls_smallest {A : TypeU} {R : A → A → Bool} : ∀ P, (reflexive P) → (transitive P) → (R ⊆ P) → (R⁺ ⊆ P)
|
2014-01-16 12:37:36 +00:00
|
|
|
:= take P, assume Hrefl Htrans Hsub,
|
2014-01-16 12:52:45 +00:00
|
|
|
take a b, assume H : R⁺ a b,
|
2014-01-16 12:37:36 +00:00
|
|
|
have P a b : H P Hrefl Htrans Hsub
|