2024-11-17 18:33:14 -08:00
|
|
|
|
-- False
|
|
|
|
|
|
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def false : ★ := forall (A : ★), A;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- no introduction rule
|
|
|
|
|
|
|
|
|
|
|
|
-- elimination rule
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def false_elim (A : ★) (contra : false) : A := contra A;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
2024-12-08 19:37:56 -08:00
|
|
|
|
-- True
|
|
|
|
|
|
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def true : ★ := forall (A : ★), A -> A;
|
2024-12-08 19:37:56 -08:00
|
|
|
|
|
2024-12-11 14:12:56 -08:00
|
|
|
|
def true_intro : true := [A : ★][x : A] x;
|
2024-12-08 19:37:56 -08:00
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
2024-11-17 18:33:14 -08:00
|
|
|
|
-- Negation
|
|
|
|
|
|
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def not (A : ★) : ★ := A -> false;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- introduction rule (kinda just the definition)
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def not_intro (A : ★) (h : A -> false) : not A := h;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- elimination rule
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def not_elim (A B : ★) (a : A) (na : not A) : B := na a B;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- can introduce double negation (can't eliminate it as that isn't constructive)
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def double_neg_intro (A : ★) (a : A) : not (not A) :=
|
2024-11-17 18:33:14 -08:00
|
|
|
|
fun (notA : not A) => notA a;
|
|
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
-- Conjunction
|
|
|
|
|
|
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def ∧ (A B : ★) : ★ := A × B;
|
2024-12-10 20:31:53 -08:00
|
|
|
|
infixl 10 ∧;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- introduction rule
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def and_intro (A B : ★) (a : A) (b : B) : A ∧ B := (a, b);
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- left elimination rule
|
2025-01-24 00:57:13 -08:00
|
|
|
|
def and_elim_l (A B : ★) (ab : A ∧ B) : A := π₁ ab;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- right elimination rule
|
2025-01-24 00:57:13 -08:00
|
|
|
|
def and_elim_r (A B : ★) (ab : A ∧ B) : B := π₂ ab;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
-- Disjunction
|
|
|
|
|
|
|
|
|
|
|
|
-- 2nd order disjunction
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def ∨ (A B : ★) : ★ := forall (C : ★), (A -> C) -> (B -> C) -> C;
|
2024-12-10 20:31:53 -08:00
|
|
|
|
infixl 5 ∨;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- left introduction rule
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def or_intro_l (A B : ★) (a : A) : A ∨ B :=
|
2025-01-24 14:59:06 -08:00
|
|
|
|
fun (C : ★) (ha : A -> C) (hb : B -> C) => ha a;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- right introduction rule
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def or_intro_r (A B : ★) (b : B) : A ∨ B :=
|
2025-01-24 14:59:06 -08:00
|
|
|
|
fun (C : ★) (ha : A -> C) (hb : B -> C) => hb b;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- elimination rule (kinda just the definition)
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def or_elim (A B C : ★) (ab : A ∨ B) (ha : A -> C) (hb : B -> C) : C :=
|
2024-11-17 18:33:14 -08:00
|
|
|
|
ab C ha hb;
|
|
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
-- Existential
|
|
|
|
|
|
|
|
|
|
|
|
-- 2nd order existential
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def exists (A : ★) (P : A -> ★) : ★ := forall (C : ★), (forall (x : A), P x -> C) -> C;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- introduction rule
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def exists_intro (A : ★) (P : A -> ★) (a : A) (h : P a) : exists A P :=
|
|
|
|
|
|
fun (C : ★) (g : forall (x : A), P x -> C) => g a h;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- elimination rule (kinda just the definition)
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def exists_elim (A B : ★) (P : A -> ★) (ex_a : exists A P) (h : forall (a : A), P a -> B) : B :=
|
2024-11-17 18:33:14 -08:00
|
|
|
|
ex_a B h;
|
|
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
-- Universal
|
|
|
|
|
|
|
|
|
|
|
|
-- 2nd order universal (just ∏, including it for completeness)
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def all (A : ★) (P : A -> ★) : ★ := forall (a : A), P a;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- introduction rule
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def all_intro (A : ★) (P : A -> ★) (h : forall (a : A), P a) : all A P := h;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- elimination rule
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def all_elim (A : ★) (P : A -> ★) (h_all : all A P) (a : A) : P a := h_all a;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
-- Equality
|
|
|
|
|
|
|
|
|
|
|
|
-- 2nd order Leibniz equality
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def eq (A : ★) (x y : A) := forall (P : A -> ★), P x -> P y;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- equality is reflexive
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def eq_refl (A : ★) (x : A) : eq A x x := fun (P : A -> ★) (Hx : P x) => Hx;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- equality is symmetric
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def eq_sym (A : ★) (x y : A) (Hxy : eq A x y) : eq A y x := fun (P : A -> ★) (Hy : P y) =>
|
|
|
|
|
|
Hxy (fun (z : A) => P z -> P x) (fun (Hx : P x) => Hx) Hy;
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- equality is transitive
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def eq_trans (A : ★) (x y z : A) (Hxy : eq A x y) (Hyz : eq A y z) : eq A x z := fun (P : A -> ★) (Hx : P x) =>
|
2024-11-17 18:33:14 -08:00
|
|
|
|
Hyz P (Hxy P Hx);
|
|
|
|
|
|
|
2024-11-20 07:37:57 -08:00
|
|
|
|
-- equality is a universal congruence
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def eq_cong (A B : ★) (x y : A) (f : A -> B) (H : eq A x y) : eq B (f x) (f y) :=
|
|
|
|
|
|
fun (P : B -> ★) (Hfx : P (f x)) =>
|
2024-11-20 07:37:57 -08:00
|
|
|
|
H (fun (a : A) => P (f a)) Hfx;
|
|
|
|
|
|
|
2024-11-17 18:33:14 -08:00
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
2024-12-08 19:37:56 -08:00
|
|
|
|
|
|
|
|
|
|
-- unique existence
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def exists_uniq (A : ★) (P : A -> ★) : ★ :=
|
|
|
|
|
|
exists A (fun (x : A) => P x ∧ (forall (y : A), P y -> eq A x y));
|
2024-12-08 19:37:56 -08:00
|
|
|
|
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def exists_uniq_elim (A B : ★) (P : A -> ★) (ex_a : exists_uniq A P) (h : forall (a : A), P a -> (forall (y : A), P y -> eq A a y) -> B) : B :=
|
|
|
|
|
|
exists_elim A B (fun (x : A) => P x ∧ (forall (y : A), P y -> eq A x y)) ex_a
|
|
|
|
|
|
(fun (a : A) (h2 : P a ∧ (forall (y : A), P y -> eq A a y)) =>
|
|
|
|
|
|
h a (and_elim_l (P a) (forall (y : A), P y -> eq A a y) h2)
|
|
|
|
|
|
(and_elim_r (P a) (forall (y : A), P y -> eq A a y) h2));
|
2024-12-08 19:37:56 -08:00
|
|
|
|
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def exists_uniq_t (A : ★) : ★ :=
|
2024-12-08 20:17:34 -08:00
|
|
|
|
exists A (fun (x : A) => forall (y : A), eq A x y);
|
|
|
|
|
|
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def exists_uniq_t_elim (A B : ★) (ex_a : exists_uniq_t A) (h : forall (a : A), (forall (y : A), eq A a y) -> B) : B :=
|
2024-12-08 20:17:34 -08:00
|
|
|
|
exists_elim A B (fun (x : A) => forall (y : A), eq A x y) ex_a (fun (a : A) (h2 : forall (y : A), eq A a y) => h a h2);
|
|
|
|
|
|
|
2024-12-08 19:37:56 -08:00
|
|
|
|
-- --------------------------------------------------------------------------------------------------------------
|
2024-11-17 18:33:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- Some logic theorems
|
|
|
|
|
|
|
2024-12-06 13:36:14 -08:00
|
|
|
|
section Theorems
|
|
|
|
|
|
|
2024-12-10 20:31:53 -08:00
|
|
|
|
variable (A B C : ★);
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- ~(A ∨ B) => ~A ∧ ~B
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def de_morgan1 (h : not (A ∨ B)) : not A ∧ not B :=
|
2025-01-24 14:59:06 -08:00
|
|
|
|
( [a : A] h (or_intro_l A B a)
|
|
|
|
|
|
, [b : B] h (or_intro_r A B b));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- ~A ∧ ~B => ~(A ∨ B)
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def de_morgan2 (h : not A ∧ not B) : not (A ∨ B) :=
|
|
|
|
|
|
fun (contra : A ∨ B) =>
|
2025-01-24 00:57:13 -08:00
|
|
|
|
or_elim A B false contra (π₁ h) (π₂ h);
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- ~A ∨ ~B => ~(A ∧ B)
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def de_morgan3 (h : not A ∨ not B) : not (A ∧ B) :=
|
|
|
|
|
|
fun (contra : A ∧ B) =>
|
2024-12-06 13:36:14 -08:00
|
|
|
|
or_elim (not A) (not B) false h
|
2025-01-24 00:57:13 -08:00
|
|
|
|
(fun (na : not A) => na (π₁ contra))
|
|
|
|
|
|
(fun (nb : not B) => nb (π₂ contra));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- the last one (~(A ∧ B) => ~A ∨ ~B) is not possible constructively
|
|
|
|
|
|
|
|
|
|
|
|
-- A ∧ B => B ∧ A
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def and_comm (h : A ∧ B) : B ∧ A := (π₂ h, π₁ h);
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- A ∨ B => B ∨ A
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def or_comm (h : A ∨ B) : B ∨ A :=
|
|
|
|
|
|
or_elim A B (B ∨ A) h
|
2024-12-11 14:12:56 -08:00
|
|
|
|
([a : A] or_intro_r B A a)
|
|
|
|
|
|
([b : B] or_intro_l B A b);
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- A ∧ (B ∧ C) => (A ∧ B) ∧ C
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def and_assoc_l (h : A ∧ (B ∧ C)) : (A ∧ B) ∧ C :=
|
2025-01-24 14:59:06 -08:00
|
|
|
|
((π₁ h, π₁ (π₂ h)), π₂ (π₂ h));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- (A ∧ B) ∧ C => A ∧ (B ∧ C)
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def and_assoc_r (h : (A ∧ B) ∧ C) : A ∧ (B ∧ C) :=
|
2025-01-24 14:59:06 -08:00
|
|
|
|
(π₁ (π₁ h), (π₂ (π₁ h), π₂ h));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- A ∨ (B ∨ C) => (A ∨ B) ∨ C
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def or_assoc_l (h : A ∨ (B ∨ C)) : (A ∨ B) ∨ C :=
|
|
|
|
|
|
or_elim A (B ∨ C) (A ∨ B ∨ C) h
|
|
|
|
|
|
(fun (a : A) => or_intro_l (A ∨ B) C (or_intro_l A B a))
|
|
|
|
|
|
(fun (g : B ∨ C) =>
|
|
|
|
|
|
or_elim B C (A ∨ B ∨ C) g
|
|
|
|
|
|
(fun (b : B) => or_intro_l (A ∨ B) C (or_intro_r A B b))
|
|
|
|
|
|
(fun (c : C) => or_intro_r (A ∨ B) C c));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- (A ∨ B) ∨ C => A ∨ (B ∨ C)
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def or_assoc_r (h : (A ∨ B) ∨ C) : A ∨ (B ∨ C) :=
|
|
|
|
|
|
or_elim (A ∨ B) C (A ∨ (B ∨ C)) h
|
|
|
|
|
|
(fun (g : A ∨ B) =>
|
|
|
|
|
|
or_elim A B (A ∨ (B ∨ C)) g
|
|
|
|
|
|
(fun (a : A) => or_intro_l A (B ∨ C) a)
|
|
|
|
|
|
(fun (b : B) => or_intro_r A (B ∨ C) (or_intro_l B C b)))
|
|
|
|
|
|
(fun (c : C) => or_intro_r A (B ∨ C) (or_intro_r B C c));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- A ∧ (B ∨ C) => A ∧ B ∨ A ∧ C
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def and_distrib_l_or (h : A ∧ (B ∨ C)) : A ∧ B ∨ A ∧ C :=
|
2025-01-24 00:57:13 -08:00
|
|
|
|
or_elim B C (A ∧ B ∨ A ∧ C) (π₂ h)
|
2025-01-24 14:59:06 -08:00
|
|
|
|
(fun (b : B) => or_intro_l (A ∧ B) (A ∧ C) (π₁ h, b))
|
|
|
|
|
|
(fun (c : C) => or_intro_r (A ∧ B) (A ∧ C) (π₁ h, c));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- A ∧ B ∨ A ∧ C => A ∧ (B ∨ C)
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def and_factor_l_or (h : A ∧ B ∨ A ∧ C) : A ∧ (B ∨ C) :=
|
|
|
|
|
|
or_elim (A ∧ B) (A ∧ C) (A ∧ (B ∨ C)) h
|
2025-01-24 14:59:06 -08:00
|
|
|
|
(fun (ab : A ∧ B) => (π₁ ab, or_intro_l B C (π₂ ab)))
|
|
|
|
|
|
(fun (ac : A ∧ C) => (π₁ ac, or_intro_r B C (π₂ ac)));
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- Thanks Quinn!
|
|
|
|
|
|
-- A ∨ B => ~B => A
|
2024-12-10 20:31:53 -08:00
|
|
|
|
def disj_syllog (nb : not B) (hor : A ∨ B) : A :=
|
2024-12-11 14:12:56 -08:00
|
|
|
|
or_elim A B A hor ([a : A] a) ([b : B] nb b A);
|
2024-12-06 13:36:14 -08:00
|
|
|
|
|
|
|
|
|
|
-- (A => B) => ~B => ~A
|
2025-01-24 14:59:06 -08:00
|
|
|
|
def contrapositive (f : A -> B) (nb : not B) : not A :=
|
2024-12-06 13:36:14 -08:00
|
|
|
|
fun (a : A) => nb (f a);
|
|
|
|
|
|
|
|
|
|
|
|
end Theorems
|