updated examples to new syntax

This commit is contained in:
William Ball 2024-12-01 15:29:05 -08:00
parent 9f5c308131
commit 0a57180cb1
4 changed files with 108 additions and 108 deletions

View file

@ -13,64 +13,64 @@
-- I'd always strongly recommend including the type ascriptions for theorems
-- a unary operation on a set `A` is a function `A -> A`
unop (A : *) := A -> A;
def unop (A : *) := A -> A;
-- a binary operation on a set `A` is a function `A -> A -> A`
binop (A : *) := A -> A -> A;
def binop (A : *) := A -> A -> A;
-- a binary operation is associative if ...
assoc (A : *) (op : binop A) :=
def assoc (A : *) (op : binop A) :=
forall (a b c : A), eq A (op a (op b c)) (op (op a b) c);
-- an element `e : A` is a left identity with respect to binop `op` if `∀ a, e * a = a`
id_l (A : *) (op : binop A) (e : A) :=
def id_l (A : *) (op : binop A) (e : A) :=
forall (a : A), eq A (op e a) a;
-- likewise for right identity
id_r (A : *) (op : binop A) (e : A) :=
def id_r (A : *) (op : binop A) (e : A) :=
forall (a : A), eq A (op a e) a;
-- an element is an identity element if it is both a left and right identity
id (A : *) (op : binop A) (e : A) := and (id_l A op e) (id_r A op e);
def id (A : *) (op : binop A) (e : A) := and (id_l A op e) (id_r A op e);
-- b is a left inverse for a if `b * a = e`
-- NOTE: we don't require `e` to be an identity in this definition.
-- this definition is purely for convenience's sake
inv_l (A : *) (op : binop A) (e : A) (a b : A) := eq A (op b a) e;
def inv_l (A : *) (op : binop A) (e : A) (a b : A) := eq A (op b a) e;
-- likewise for right inverse
inv_r (A : *) (op : binop A) (e : A) (a b : A) := eq A (op a b) e;
def inv_r (A : *) (op : binop A) (e : A) (a b : A) := eq A (op a b) e;
-- and full-on inverse
inv (A : *) (op : binop A) (e : A) (a b : A) := and (inv_l A op e a b) (inv_r A op e a b);
def inv (A : *) (op : binop A) (e : A) (a b : A) := and (inv_l A op e a b) (inv_r A op e a b);
-- --------------------------------------------------------------------------------------------------------------
-- | ALGEBRAIC STRUCTURES |
-- --------------------------------------------------------------------------------------------------------------
-- a set `S` with binary operation `op` is a semigroup if its operation is associative
semigroup (S : *) (op : binop S) : * := assoc S op;
def semigroup (S : *) (op : binop S) : * := assoc S op;
-- a set `M` with binary operation `op` and element `e` is a monoid
monoid (M : *) (op : binop M) (e : M) : * :=
def monoid (M : *) (op : binop M) (e : M) : * :=
and (semigroup M op) (id M op e);
-- some "getters" for `monoid` so we don't have to do a bunch of very verbose
-- and-eliminations every time we want to use something
id_lm (M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e) : id_l M op e :=
def id_lm (M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e) : id_l M op e :=
and_elim_l (id_l M op e) (id_r M op e)
(and_elim_r (semigroup M op) (id M op e) Hmonoid);
id_rm (M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e) : id_r M op e :=
def id_rm (M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e) : id_r M op e :=
and_elim_r (id_l M op e) (id_r M op e)
(and_elim_r (semigroup M op) (id M op e) Hmonoid);
assoc_m (M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e) : assoc M op :=
def assoc_m (M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e) : assoc M op :=
and_elim_l (semigroup M op) (id M op e) Hmonoid;
-- now we can prove that, for any monoid, if `a` is a left identity, then it
-- must be "the" identity
monoid_id_l_implies_identity
def monoid_id_l_implies_identity
(M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e)
(a : M) (H : id_l M op a) : eq M a e :=
-- WTS a = a * e = e
@ -86,7 +86,7 @@ monoid_id_l_implies_identity
(H e);
-- the analogous result for right identities
monoid_id_r_implies_identity
def monoid_id_r_implies_identity
(M : *) (op : binop M) (e : M) (Hmonoid : monoid M op e)
(a : M) (H : id_r M op a) : eq M a e :=
-- this time, we'll show `a = e * a = e`
@ -102,36 +102,36 @@ monoid_id_r_implies_identity
-- groups are just monoids with inverses
has_inverses (G : *) (op : binop G) (e : G) (i : unop G) : * :=
def has_inverses (G : *) (op : binop G) (e : G) (i : unop G) : * :=
forall (a : G), inv G op e a (i a);
group (G : *) (op : binop G) (e : G) (i : unop G) : * :=
def group (G : *) (op : binop G) (e : G) (i : unop G) : * :=
and (monoid G op e)
(has_inverses G op e i);
-- more "getters"
monoid_g (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : monoid G op e :=
def monoid_g (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : monoid G op e :=
and_elim_l (monoid G op e) (has_inverses G op e i) Hgroup;
assoc_g (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : assoc G op :=
def assoc_g (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : assoc G op :=
assoc_m G op e (monoid_g G op e i Hgroup);
id_lg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : id_l G op e :=
def id_lg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : id_l G op e :=
id_lm G op e (and_elim_l (monoid G op e) (has_inverses G op e i) Hgroup);
id_rg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : id_r G op e :=
def id_rg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : id_r G op e :=
id_rm G op e (and_elim_l (monoid G op e) (has_inverses G op e i) Hgroup);
inv_g (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : forall (a : G), inv G op e a (i a) :=
def inv_g (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) : forall (a : G), inv G op e a (i a) :=
and_elim_r (monoid G op e) (has_inverses G op e i) Hgroup;
inv_lg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) (a : G) : inv_l G op e a (i a) :=
def inv_lg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) (a : G) : inv_l G op e a (i a) :=
and_elim_l (inv_l G op e a (i a)) (inv_r G op e a (i a)) (inv_g G op e i Hgroup a);
inv_rg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) (a : G) : inv_r G op e a (i a) :=
def inv_rg (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) (a : G) : inv_r G op e a (i a) :=
and_elim_r (inv_l G op e a (i a)) (inv_r G op e a (i a)) (inv_g G op e i Hgroup a);
left_inv_unique (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) (a b : G) (h : inv_l G op e a b) : eq G b (i a) :=
def left_inv_unique (G : *) (op : binop G) (e : G) (i : unop G) (Hgroup : group G op e i) (a b : G) (h : inv_l G op e a b) : eq G b (i a) :=
-- b = b * e
-- = b * (a * a^-1)
-- = (b * a) * a^-1

View file

@ -2,23 +2,23 @@
-- excluded middle!
-- P ~P
em (P : *) : or (P) (not P) := axiom;
axiom em (P : *) : or (P) (not P);
-- ~~P => P
dne (P : *) (nnp : not (not P)) : P :=
def dne (P : *) (nnp : not (not P)) : P :=
or_elim P (not P) P (em P)
(fun (p : P) => p)
(fun (np : not P) => nnp np P);
-- ((P => Q) => P) => P
peirce (P Q : *) (h : (P -> Q) -> P) : P :=
def peirce (P Q : *) (h : (P -> Q) -> P) : P :=
or_elim P (not P) P (em P)
(fun (p : P) => p)
(fun (np : not P) => h (fun (p : P) => np p Q));
-- ~(A ∧ B) => ~A ~B
de_morgan4 (A B : *) (h : not (and A B)) : or (not A) (not B) :=
def de_morgan4 (A B : *) (h : not (and A B)) : or (not A) (not B) :=
or_elim A (not A) (or (not A) (not B)) (em A)
(fun (a : A) =>
or_elim B (not B) (or (not A) (not B)) (em B)

View file

@ -1,44 +1,44 @@
-- False
false : * := forall (A : *), A;
def false : * := forall (A : *), A;
-- no introduction rule
-- elimination rule
false_elim (A : *) (contra : false) : A := contra A;
def false_elim (A : *) (contra : false) : A := contra A;
-- --------------------------------------------------------------------------------------------------------------
-- Negation
not (A : *) : * := A -> false;
def not (A : *) : * := A -> false;
-- introduction rule (kinda just the definition)
not_intro (A : *) (h : A -> false) : not A := h;
def not_intro (A : *) (h : A -> false) : not A := h;
-- elimination rule
not_elim (A B : *) (a : A) (na : not A) : B := na a B;
def not_elim (A B : *) (a : A) (na : not A) : B := na a B;
-- can introduce double negation (can't eliminate it as that isn't constructive)
double_neg_intro (A : *) (a : A) : not (not A) :=
def double_neg_intro (A : *) (a : A) : not (not A) :=
fun (notA : not A) => notA a;
-- --------------------------------------------------------------------------------------------------------------
-- Conjunction
and (A B : *) : * := forall (C : *), (A -> B -> C) -> C;
def and (A B : *) : * := forall (C : *), (A -> B -> C) -> C;
-- introduction rule
and_intro (A B : *) (a : A) (b : B) : and A B :=
def and_intro (A B : *) (a : A) (b : B) : and A B :=
fun (C : *) (H : A -> B -> C) => H a b;
-- left elimination rule
and_elim_l (A B : *) (ab : and A B) : A :=
def and_elim_l (A B : *) (ab : and A B) : A :=
ab A (fun (a : A) (b : B) => a);
-- right elimination rule
and_elim_r (A B : *) (ab : and A B) : B :=
def and_elim_r (A B : *) (ab : and A B) : B :=
ab B (fun (a : A) (b : B) => b);
-- --------------------------------------------------------------------------------------------------------------
@ -46,18 +46,18 @@ and_elim_r (A B : *) (ab : and A B) : B :=
-- Disjunction
-- 2nd order disjunction
or (A B : *) : * := forall (C : *), (A -> C) -> (B -> C) -> C;
def or (A B : *) : * := forall (C : *), (A -> C) -> (B -> C) -> C;
-- left introduction rule
or_intro_l (A B : *) (a : A) : or A B :=
def or_intro_l (A B : *) (a : A) : or A B :=
fun (C : *) (ha : A -> C) (hb : B -> C) => ha a;
-- right introduction rule
or_intro_r (A B : *) (b : B) : or A B :=
def or_intro_r (A B : *) (b : B) : or A B :=
fun (C : *) (ha : A -> C) (hb : B -> C) => hb b;
-- elimination rule (kinda just the definition)
or_elim (A B C : *) (ab : or A B) (ha : A -> C) (hb : B -> C) : C :=
def or_elim (A B C : *) (ab : or A B) (ha : A -> C) (hb : B -> C) : C :=
ab C ha hb;
-- --------------------------------------------------------------------------------------------------------------
@ -65,14 +65,14 @@ or_elim (A B C : *) (ab : or A B) (ha : A -> C) (hb : B -> C) : C :=
-- Existential
-- 2nd order existential
exists (A : *) (P : A -> *) : * := forall (C : *), (forall (x : A), P x -> C) -> C;
def exists (A : *) (P : A -> *) : * := forall (C : *), (forall (x : A), P x -> C) -> C;
-- introduction rule
exists_intro (A : *) (P : A -> *) (a : A) (h : P a) : exists A P :=
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;
-- elimination rule (kinda just the definition)
exists_elim (A B : *) (P : A -> *) (ex_a : exists A P) (h : forall (a : A), P a -> B) : B :=
def exists_elim (A B : *) (P : A -> *) (ex_a : exists A P) (h : forall (a : A), P a -> B) : B :=
ex_a B h;
-- --------------------------------------------------------------------------------------------------------------
@ -80,34 +80,34 @@ exists_elim (A B : *) (P : A -> *) (ex_a : exists A P) (h : forall (a : A), P a
-- Universal
-- 2nd order universal (just ∏, including it for completeness)
all (A : *) (P : A -> *) : * := forall (a : A), P a;
def all (A : *) (P : A -> *) : * := forall (a : A), P a;
-- introduction rule
all_intro (A : *) (P : A -> *) (h : forall (a : A), P a) : all A P := h;
def all_intro (A : *) (P : A -> *) (h : forall (a : A), P a) : all A P := h;
-- elimination rule
all_elim (A : *) (P : A -> *) (h_all : all A P) (a : A) : P a := h_all a;
def all_elim (A : *) (P : A -> *) (h_all : all A P) (a : A) : P a := h_all a;
-- --------------------------------------------------------------------------------------------------------------
-- Equality
-- 2nd order Leibniz equality
eq (A : *) (x y : A) := forall (P : A -> *), P x -> P y;
def eq (A : *) (x y : A) := forall (P : A -> *), P x -> P y;
-- equality is reflexive
eq_refl (A : *) (x : A) : eq A x x := fun (P : A -> *) (Hx : P x) => Hx;
def eq_refl (A : *) (x : A) : eq A x x := fun (P : A -> *) (Hx : P x) => Hx;
-- equality is symmetric
eq_sym (A : *) (x y : A) (Hxy : eq A x y) : eq A y x := fun (P : A -> *) (Hy : P y) =>
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;
-- equality is transitive
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) =>
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) =>
Hyz P (Hxy P Hx);
-- equality is a universal congruence
eq_cong (A B : *) (x y : A) (f : A -> B) (H : eq A x y) : eq B (f x) (f y) :=
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)) =>
H (fun (a : A) => P (f a)) Hfx;
@ -116,20 +116,20 @@ eq_cong (A B : *) (x y : A) (f : A -> B) (H : eq A x y) : eq B (f x) (f y) :=
-- Some logic theorems
-- ~(A B) => ~A ∧ ~B
de_morgan1 (A B : *) (h : not (or A B)) : and (not A) (not B) :=
def de_morgan1 (A B : *) (h : not (or A B)) : and (not A) (not B) :=
and_intro (not A) (not B)
(fun (a : A) => h (or_intro_l A B a))
(fun (b : B) => h (or_intro_r A B b));
-- ~A ∧ ~B => ~(A B)
de_morgan2 (A B : *) (h : and (not A) (not B)) : not (or A B) :=
def de_morgan2 (A B : *) (h : and (not A) (not B)) : not (or A B) :=
fun (contra : or A B) =>
or_elim A B false contra
(and_elim_l (not A) (not B) h)
(and_elim_r (not A) (not B) h);
-- ~A ~B => ~(A ∧ B)
de_morgan3 (A B : *) (h : or (not A) (not B)) : not (and A B) :=
def de_morgan3 (A B : *) (h : or (not A) (not B)) : not (and A B) :=
fun (contra : and A B) =>
or_elim (not A) (not B) false h
(fun (na : not A) => na (and_elim_l A B contra))
@ -138,19 +138,19 @@ de_morgan3 (A B : *) (h : or (not A) (not B)) : not (and A B) :=
-- the last one (~(A ∧ B) => ~A ~B) is not possible constructively
-- A ∧ B => B ∧ A
and_comm (A B : *) (h : and A B) : and B A :=
def and_comm (A B : *) (h : and A B) : and B A :=
and_intro B A
(and_elim_r A B h)
(and_elim_l A B h);
-- A B => B A
or_comm (A B : *) (h : or A B) : or B A :=
def or_comm (A B : *) (h : or A B) : or B A :=
or_elim A B (or B A) h
(fun (a : A) => or_intro_r B A a)
(fun (b : B) => or_intro_l B A b);
-- A ∧ (B ∧ C) => (A ∧ B) ∧ C
and_assoc_l (A B C : *) (h : and A (and B C)) : and (and A B) C :=
def and_assoc_l (A B C : *) (h : and A (and B C)) : and (and A B) C :=
let (a := (and_elim_l A (and B C) h))
(bc := (and_elim_r A (and B C) h))
(b := (and_elim_l B C bc))
@ -160,7 +160,7 @@ and_assoc_l (A B C : *) (h : and A (and B C)) : and (and A B) C :=
end;
-- (A ∧ B) ∧ C => A ∧ (B ∧ C)
and_assoc_r (A B C : *) (h : and (and A B) C) : and A (and B C) :=
def and_assoc_r (A B C : *) (h : and (and A B) C) : and A (and B C) :=
let (ab := and_elim_l (and A B) C h)
(a := and_elim_l A B ab)
(b := and_elim_r A B ab)
@ -170,7 +170,7 @@ and_assoc_r (A B C : *) (h : and (and A B) C) : and A (and B C) :=
end;
-- A (B C) => (A B) C
or_assoc_l (A B C : *) (h : or A (or B C)) : or (or A B) C :=
def or_assoc_l (A B C : *) (h : or A (or B C)) : or (or A B) C :=
or_elim A (or B C) (or (or A B) C) h
(fun (a : A) => or_intro_l (or A B) C (or_intro_l A B a))
(fun (g : or B C) =>
@ -179,7 +179,7 @@ or_assoc_l (A B C : *) (h : or A (or B C)) : or (or A B) C :=
(fun (c : C) => or_intro_r (or A B) C c));
-- (A B) C => A (B C)
or_assoc_r (A B C : *) (h : or (or A B) C) : or A (or B C) :=
def or_assoc_r (A B C : *) (h : or (or A B) C) : or A (or B C) :=
or_elim (or A B) C (or A (or B C)) h
(fun (g : or A B) =>
or_elim A B (or A (or B C)) g
@ -188,7 +188,7 @@ or_assoc_r (A B C : *) (h : or (or A B) C) : or A (or B C) :=
(fun (c : C) => or_intro_r A (or B C) (or_intro_r B C c));
-- A ∧ (B C) => A ∧ B A ∧ C
and_distrib_l_or (A B C : *) (h : and A (or B C)) : or (and A B) (and A C) :=
def and_distrib_l_or (A B C : *) (h : and A (or B C)) : or (and A B) (and A C) :=
or_elim B C (or (and A B) (and A C)) (and_elim_r A (or B C) h)
(fun (b : B) => or_intro_l (and A B) (and A C)
(and_intro A B (and_elim_l A (or B C) h) b))
@ -196,7 +196,7 @@ and_distrib_l_or (A B C : *) (h : and A (or B C)) : or (and A B) (and A C) :=
(and_intro A C (and_elim_l A (or B C) h) c));
-- A ∧ B A ∧ C => A ∧ (B C)
and_factor_l_or (A B C : *) (h : or (and A B) (and A C)) : and A (or B C) :=
def and_factor_l_or (A B C : *) (h : or (and A B) (and A C)) : and A (or B C) :=
or_elim (and A B) (and A C) (and A (or B C)) h
(fun (ab : and A B) => and_intro A (or B C)
(and_elim_l A B ab)
@ -207,9 +207,9 @@ and_factor_l_or (A B C : *) (h : or (and A B) (and A C)) : and A (or B C) :=
-- Thanks Quinn!
-- A B => ~B => A
disj_syllog (A B : *) (nb : not B) (hor : or A B) : A :=
def disj_syllog (A B : *) (nb : not B) (hor : or A B) : A :=
or_elim A B A hor (fun (a : A) => a) (fun (b : B) => nb b A);
-- (A => B) => ~B => ~A
contrapositive (A B : *) (f : A -> B) (nb : not B) : not A :=
def contrapositive (A B : *) (f : A -> B) (nb : not B) : not A :=
fun (a : A) => nb (f a);

View file

@ -5,7 +5,7 @@
@include logic.pg
@include algebra.pg
comp (A B C : *) (g : B -> C) (f : A -> B) (x : A) : C :=
def comp (A B C : *) (g : B -> C) (f : A -> B) (x : A) : C :=
g (f x);
-- }}}
@ -24,7 +24,7 @@ comp (A B C : *) (g : B -> C) (f : A -> B) (x : A) : C :=
-- defined is a value of the asserted type. For example, we will use the axiom
-- system to assert the existence of a type of natural numbers
nat : * := axiom;
axiom nat : *;
-- As you can imagine, this can be risky. For instance, there's nothing stopping
-- us from saying
@ -47,21 +47,21 @@ nat : * := axiom;
-- (https://en.wikipedia.org/wiki/Peano_axioms).
-- axiom 1: 0 is a natural number
zero : nat := axiom;
axiom zero : nat;
-- axiom 6: For every n, S n is a natural number.
suc (n : nat) : nat := axiom;
axiom suc (n : nat) : nat;
-- axiom 7: If S n = S m, then n = m.
suc_inj : forall (n m : nat), eq nat (suc n) (suc m) -> eq nat n m := axiom;
axiom suc_inj : forall (n m : nat), eq nat (suc n) (suc m) -> eq nat n m;
-- axiom 8: No successor of any natural number is zero.
suc_nonzero : forall (n : nat), not (eq nat (suc n) zero) := axiom;
axiom suc_nonzero : forall (n : nat), not (eq nat (suc n) zero);
-- axiom 9: Induction! For any proposition P on natural numbers, if P(0) holds,
-- and if for every natural number n, P(n) ⇒ P(S n), then P holds for all n.
nat_ind : forall (P : nat -> *), P zero -> (forall (n : nat), P n -> P (suc n))
-> forall (n : nat), P n := axiom;
axiom nat_ind : forall (P : nat -> *), P zero -> (forall (n : nat), P n -> P (suc n))
-> forall (n : nat), P n;
-- }}}
@ -77,27 +77,27 @@ nat_ind : forall (P : nat -> *), P zero -> (forall (n : nat), P n -> P (suc n))
-- long and complicated really quickly.
-- Some abbreviations for common numbers.
one : nat := suc zero;
two : nat := suc one;
three : nat := suc two;
four : nat := suc three;
five : nat := suc four;
def one : nat := suc zero;
def two : nat := suc one;
def three : nat := suc two;
def four : nat := suc three;
def five : nat := suc four;
-- First, the predecessor of n is m if n = suc m.
pred (n m : nat) : * := eq nat n (suc m);
def pred (n m : nat) : * := eq nat n (suc m);
-- Our claim is a disjunction, whose first option is that n = 0.
szc_l (n : nat) := eq nat n zero;
def szc_l (n : nat) := eq nat n zero;
-- The second option is that n has a predecessor.
szc_r (n : nat) := exists nat (pred n);
def szc_r (n : nat) := exists nat (pred n);
-- So the claim we are trying to prove is that either one of the above options
-- holds for every n.
szc (n : nat) := or (szc_l n) (szc_r n);
def szc (n : nat) := or (szc_l n) (szc_r n);
-- And here's our proof!
suc_or_zero : forall (n : nat), szc n :=
def suc_or_zero : forall (n : nat), szc n :=
-- We will prove this by induction.
nat_ind szc
-- For the base case, the first option holds, i.e. 0 = 0
@ -157,30 +157,30 @@ suc_or_zero : forall (n : nat), szc n :=
-- {{{ Defining R
-- Here is condition 1 formally expressed in perga.
cond1 (A : *) (z : A) (fS : nat -> A -> A) (Q : nat -> A -> *) :=
def cond1 (A : *) (z : A) (fS : nat -> A -> A) (Q : nat -> A -> *) :=
Q zero z;
-- Likewise for condition 2.
cond2 (A : *) (z : A) (fS : nat -> A -> A) (Q : nat -> A -> *) :=
def cond2 (A : *) (z : A) (fS : nat -> A -> A) (Q : nat -> A -> *) :=
forall (n : nat) (y : A), Q n y -> Q (suc n) (fS n y);
-- From here we can define R.
rec_rel (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :=
def rec_rel (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :=
forall (Q : nat -> A -> *), cond1 A z fS Q -> cond2 A z fS Q -> Q x y;
-- }}}
-- {{{ R is total
total (A B : *) (R : A -> B -> *) := forall (a : A), exists B (R a);
def total (A B : *) (R : A -> B -> *) := forall (a : A), exists B (R a);
rec_rel_cond1 (A : *) (z : A) (fS : nat -> A -> A) : cond1 A z fS (rec_rel A z fS) :=
def rec_rel_cond1 (A : *) (z : A) (fS : nat -> A -> A) : cond1 A z fS (rec_rel A z fS) :=
fun (Q : nat -> A -> *) (h1 : cond1 A z fS Q) (h2 : cond2 A z fS Q) => h1;
rec_rel_cond2 (A : *) (z : A) (fS : nat -> A -> A) : cond2 A z fS (rec_rel A z fS) :=
def rec_rel_cond2 (A : *) (z : A) (fS : nat -> A -> A) : cond2 A z fS (rec_rel A z fS) :=
fun (n : nat) (y : A) (h : rec_rel A z fS n y)
(Q : nat -> A -> *) (h1 : cond1 A z fS Q) (h2 : cond2 A z fS Q) =>
h2 n y (h Q h1 h2);
rec_rel_total (A : *) (z : A) (fS : nat -> A -> A) : total nat A (rec_rel A z fS) :=
def rec_rel_total (A : *) (z : A) (fS : nat -> A -> A) : total nat A (rec_rel A z fS) :=
let (R := rec_rel A z fS)
(P (x : nat) := exists A (R x))
(c1 := cond1 A z fS)
@ -196,27 +196,27 @@ rec_rel_total (A : *) (z : A) (fS : nat -> A -> A) : total nat A (rec_rel A z fS
-- }}}
-- {{{ Defining R2
alt_cond1 (A : *) (z : A) (x : nat) (y : A) :=
def alt_cond1 (A : *) (z : A) (x : nat) (y : A) :=
and (eq nat x zero) (eq A y z);
cond_y2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A)
def cond_y2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A)
(x2 : nat) (y2 : A) :=
and (eq A y (fS x2 y2)) (rec_rel A z fS x2 y2);
cond_x2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) (x2 : nat) :=
def cond_x2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) (x2 : nat) :=
and (pred x x2) (exists A (cond_y2 A z fS x y x2));
alt_cond2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :=
def alt_cond2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :=
exists nat (cond_x2 A z fS x y);
rec_rel_alt (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :=
def rec_rel_alt (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :=
or (alt_cond1 A z x y) (alt_cond2 A z fS x y);
-- }}}
-- {{{ R = R2
-- {{{ R2 ⊆ R
R2_sub_R (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :
def R2_sub_R (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :
rec_rel_alt A z fS x y -> rec_rel A z fS x y :=
let (R := rec_rel A z fS)
(R2 := rec_rel_alt A z fS)
@ -257,13 +257,13 @@ R2_sub_R (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :
-- }}}
-- {{{ R ⊆ R2
R2_cond1 (A : *) (z : A) (fS : nat -> A -> A) : cond1 A z fS (rec_rel_alt A z fS) :=
def R2_cond1 (A : *) (z : A) (fS : nat -> A -> A) : cond1 A z fS (rec_rel_alt A z fS) :=
or_intro_l (alt_cond1 A z zero z) (alt_cond2 A z fS zero z)
(and_intro (eq nat zero zero) (eq A z z)
(eq_refl nat zero)
(eq_refl A z));
R2_cond2 (A : *) (z : A) (fS : nat -> A -> A) : cond2 A z fS (rec_rel_alt A z fS) :=
def R2_cond2 (A : *) (z : A) (fS : nat -> A -> A) : cond2 A z fS (rec_rel_alt A z fS) :=
let (R := rec_rel A z fS)
(R2 := rec_rel_alt A z fS)
in
@ -284,7 +284,7 @@ R2_cond2 (A : *) (z : A) (fS : nat -> A -> A) : cond2 A z fS (rec_rel_alt A z fS
end
end;
R_sub_R2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :
def R_sub_R2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :
rec_rel A z fS x y -> rec_rel_alt A z fS x y :=
let (R := rec_rel A z fS)
(R2 := rec_rel_alt A z fS)
@ -298,12 +298,12 @@ R_sub_R2 (A : *) (z : A) (fS : nat -> A -> A) (x : nat) (y : A) :
-- {{{ R2 (hence R) is functional
fl_in (A B : *) (R : A -> B -> *) (x : A) := forall (y1 y2 : B),
def fl_in (A B : *) (R : A -> B -> *) (x : A) := forall (y1 y2 : B),
R x y1 -> R x y2 -> eq B y1 y2;
fl (A B : *) (R : A -> B -> *) := forall (x : A), fl_in A B R x;
def fl (A B : *) (R : A -> B -> *) := forall (x : A), fl_in A B R x;
R2_zero (A : *) (z : A) (fS : nat -> A -> A) (y : A) :
def R2_zero (A : *) (z : A) (fS : nat -> A -> A) (y : A) :
rec_rel_alt A z fS zero y -> eq A y z :=
let (R2 := rec_rel_alt A z fS)
(ac1 := alt_cond1 A z zero y)
@ -321,7 +321,7 @@ R2_zero (A : *) (z : A) (fS : nat -> A -> A) (y : A) :
(eq A y z)))
end;
R2_suc (A : *) (z : A) (fS : nat -> A -> A) (x2 : nat) (y : A) :
def R2_suc (A : *) (z : A) (fS : nat -> A -> A) (x2 : nat) (y : A) :
rec_rel_alt A z fS (suc x2) y -> exists A (cond_y2 A z fS (suc x2) y x2) :=
let (R2 := rec_rel_alt A z fS)
(x := suc x2)
@ -347,7 +347,7 @@ R2_suc (A : *) (z : A) (fS : nat -> A -> A) (x2 : nat) (y : A) :
end))
end;
R2_functional (A : *) (z : A) (fS : nat -> A -> A) : fl nat A (rec_rel_alt A z fS) :=
def R2_functional (A : *) (z : A) (fS : nat -> A -> A) : fl nat A (rec_rel_alt A z fS) :=
let (R := rec_rel A z fS)
(R2 := rec_rel_alt A z fS)
(f_in := fl_in nat A R2)
@ -385,7 +385,7 @@ R2_functional (A : *) (z : A) (fS : nat -> A -> A) : fl nat A (rec_rel_alt A z f
-- }}}
rec_def (A : *) (z : A) (fS : nat -> A -> A) (x : nat) : A :=
def rec_def (A : *) (z : A) (fS : nat -> A -> A) (x : nat) : A :=
exists_elim A A (rec_rel A z fS x) (rec_rel_total A z fS x)
(fun (y : A) (_ : rec_rel A z fS x y) => y);