| 
17481
 | 
     1  | 
(*  Title:      Sequents/LK/Nat.thy
  | 
| 
7091
 | 
     2  | 
    ID:         $Id$
  | 
| 
 | 
     3  | 
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
  | 
| 
7095
 | 
     4  | 
    Copyright   1999  University of Cambridge
  | 
| 
7091
 | 
     5  | 
*)
  | 
| 
 | 
     6  | 
  | 
| 
17481
 | 
     7  | 
header {* Theory of the natural numbers: Peano's axioms, primitive recursion *}
 | 
| 
 | 
     8  | 
  | 
| 
 | 
     9  | 
theory Nat
  | 
| 
 | 
    10  | 
imports LK
  | 
| 
 | 
    11  | 
begin
  | 
| 
 | 
    12  | 
  | 
| 
 | 
    13  | 
typedecl nat
  | 
| 
 | 
    14  | 
arities nat :: "term"
  | 
| 
7091
 | 
    15  | 
consts  "0" :: nat      ("0")
 | 
| 
17481
 | 
    16  | 
        Suc :: "nat=>nat"
  | 
| 
 | 
    17  | 
        rec :: "[nat, 'a, [nat,'a]=>'a] => 'a"
  | 
| 
22896
 | 
    18  | 
        add :: "[nat, nat] => nat"                (infixl "+" 60)
  | 
| 
7091
 | 
    19  | 
  | 
| 
17481
 | 
    20  | 
axioms
  | 
| 
 | 
    21  | 
  induct:  "[| $H |- $E, P(0), $F;
  | 
| 
7123
 | 
    22  | 
              !!x. $H, P(x) |- $E, P(Suc(x)), $F |] ==> $H |- $E, P(n), $F"
  | 
| 
7095
 | 
    23  | 
  | 
| 
17481
 | 
    24  | 
  Suc_inject:  "|- Suc(m)=Suc(n) --> m=n"
  | 
| 
 | 
    25  | 
  Suc_neq_0:   "|- Suc(m) ~= 0"
  | 
| 
 | 
    26  | 
  rec_0:       "|- rec(0,a,f) = a"
  | 
| 
 | 
    27  | 
  rec_Suc:     "|- rec(Suc(m), a, f) = f(m, rec(m,a,f))"
  | 
| 
 | 
    28  | 
  add_def:     "m+n == rec(m, n, %x y. Suc(y))"
  | 
| 
 | 
    29  | 
  | 
| 
21426
 | 
    30  | 
  | 
| 
 | 
    31  | 
declare Suc_neq_0 [simp]
  | 
| 
 | 
    32  | 
  | 
| 
 | 
    33  | 
lemma Suc_inject_rule: "$H, $G, m = n |- $E \<Longrightarrow> $H, Suc(m) = Suc(n), $G |- $E"
  | 
| 
 | 
    34  | 
  by (rule L_of_imp [OF Suc_inject])
  | 
| 
 | 
    35  | 
  | 
| 
 | 
    36  | 
lemma Suc_n_not_n: "|- Suc(k) ~= k"
  | 
| 
 | 
    37  | 
  apply (rule_tac n = k in induct)
  | 
| 
22896
 | 
    38  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms Suc_neq_0}) 1 *})
 | 
| 
 | 
    39  | 
  apply (tactic {* fast_tac (LK_pack add_safes @{thms Suc_inject_rule}) 1 *})
 | 
| 
21426
 | 
    40  | 
  done
  | 
| 
 | 
    41  | 
  | 
| 
 | 
    42  | 
lemma add_0: "|- 0+n = n"
  | 
| 
 | 
    43  | 
  apply (unfold add_def)
  | 
| 
 | 
    44  | 
  apply (rule rec_0)
  | 
| 
 | 
    45  | 
  done
  | 
| 
 | 
    46  | 
  | 
| 
 | 
    47  | 
lemma add_Suc: "|- Suc(m)+n = Suc(m+n)"
  | 
| 
 | 
    48  | 
  apply (unfold add_def)
  | 
| 
 | 
    49  | 
  apply (rule rec_Suc)
  | 
| 
 | 
    50  | 
  done
  | 
| 
 | 
    51  | 
  | 
| 
 | 
    52  | 
declare add_0 [simp] add_Suc [simp]
  | 
| 
 | 
    53  | 
  | 
| 
 | 
    54  | 
lemma add_assoc: "|- (k+m)+n = k+(m+n)"
  | 
| 
 | 
    55  | 
  apply (rule_tac n = "k" in induct)
  | 
| 
22896
 | 
    56  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms add_0}) 1 *})
 | 
| 
 | 
    57  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms add_Suc}) 1 *})
 | 
| 
21426
 | 
    58  | 
  done
  | 
| 
 | 
    59  | 
  | 
| 
 | 
    60  | 
lemma add_0_right: "|- m+0 = m"
  | 
| 
 | 
    61  | 
  apply (rule_tac n = "m" in induct)
  | 
| 
22896
 | 
    62  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms add_0}) 1 *})
 | 
| 
 | 
    63  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms add_Suc}) 1 *})
 | 
| 
21426
 | 
    64  | 
  done
  | 
| 
 | 
    65  | 
  | 
| 
 | 
    66  | 
lemma add_Suc_right: "|- m+Suc(n) = Suc(m+n)"
  | 
| 
 | 
    67  | 
  apply (rule_tac n = "m" in induct)
  | 
| 
22896
 | 
    68  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms add_0}) 1 *})
 | 
| 
 | 
    69  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms add_Suc}) 1 *})
 | 
| 
21426
 | 
    70  | 
  done
  | 
| 
 | 
    71  | 
  | 
| 
 | 
    72  | 
lemma "(!!n. |- f(Suc(n)) = Suc(f(n))) ==> |- f(i+j) = i+f(j)"
  | 
| 
 | 
    73  | 
  apply (rule_tac n = "i" in induct)
  | 
| 
22896
 | 
    74  | 
  apply (tactic {* simp_tac (LK_ss addsimps @{thms add_0}) 1 *})
 | 
| 
 | 
    75  | 
  apply (tactic {* asm_simp_tac (LK_ss addsimps @{thms add_Suc}) 1 *})
 | 
| 
21426
 | 
    76  | 
  done
  | 
| 
17481
 | 
    77  | 
  | 
| 
7091
 | 
    78  | 
end
  |