theory Nat imports Base begin axiomatization Nat :: \o\ and zero :: \o\ ("0") and suc :: \o \ o\ and NatInd :: \(o \ o) \ o \ (o \ o \ o) \ o \ o\ where NatF: "Nat: U i" and Nat_zero: "0: Nat" and Nat_suc: "n: Nat \ suc n: Nat" and NatE: "\ n: Nat; c\<^sub>0: C 0; \n. n: Nat \ C n: U i; \k c. \k: Nat; c: C k\ \ f k c: C (suc k) \ \ NatInd (\n. C n) c\<^sub>0 (\k c. f k c) n: C n" and Nat_comp_zero: "\ c\<^sub>0: C 0; \k c. \k: Nat; c: C k\ \ f k c: C (suc k); \n. n: Nat \ C n: U i \ \ NatInd (\n. C n) c\<^sub>0 (\k c. f k c) 0 \ c\<^sub>0" and Nat_comp_suc: "\ n: Nat; c\<^sub>0: C 0; \k c. \k: Nat; c: C k\ \ f k c: C (suc k); \n. n: Nat \ C n: U i \ \ NatInd (\n. C n) c\<^sub>0 (\k c. f k c) (suc n) \ f n (NatInd (\n. C n) c\<^sub>0 (\k c. f k c) n)" lemmas [intros] = NatF Nat_zero Nat_suc and [elims "?n"] = NatE and [comps] = Nat_comp_zero Nat_comp_suc text \Non-dependent recursion\ abbreviation "NatRec C \ NatInd (K C)" section \Basic arithmetic\ definition add (infixl "+" 120) where "m + n \ NatRec Nat n (K suc) m" lemma add_type [typechk]: assumes "m: Nat" "n: Nat" shows "m + n: Nat" unfolding add_def by typechk lemma add_rec [comps]: assumes "m: Nat" "n: Nat" shows "suc m + n \ suc (m + n)" unfolding add_def by reduce lemma zero_add [comps]: assumes "n: Nat" shows "0 + n \ n" unfolding add_def by reduce Lemma (derive) add_zero: assumes "n: Nat" shows "n + 0 = n" apply (elim n) \ by (reduce; intro) \ vars _ IH by reduce (elim IH; intro) done Lemma (derive) add_assoc: assumes "l: Nat" "m: Nat" "n: Nat" shows "l + (m + n) = (l + m) + n" apply (elim l) \ by reduce intro \ vars _ IH by reduce (elim IH; intro) done Lemma (derive) add_comm: assumes "m: Nat" "n: Nat" shows "m + n = n + m" apply (elim m) \ by (reduce; rule add_zero[sym]) \ vars m p apply (elim n) (*Should also change the `n`s in the premises!*) (*FIXME: Elimination tactic needs to do the same kind of thing as the equality tactic with pushing context premises into the statement, applying the appropriate elimination rule and then pulling back out.*) oops definition mul (infixl "*" 120) where [comps]: "m * n \ NatRec Nat 0 (K $ add n) m" end