src/FOL/ex/Natural_Numbers.thy
author wenzelm
Fri Oct 12 12:06:23 2001 +0200 (2001-10-12)
changeset 11726 2b2a45abe876
parent 11696 233362cfecc7
child 11789 da81334357ba
permissions -rw-r--r--
tuned;
     1 (*  Title:      FOL/ex/Natural_Numbers.thy
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Munich
     4 
     5 Theory of the natural numbers: Peano's axioms, primitive recursion.
     6 (Modernized version of Larry Paulson's theory "Nat".)
     7 *)
     8 
     9 theory Natural_Numbers = FOL:
    10 
    11 typedecl nat
    12 arities nat :: "term"
    13 
    14 consts
    15   Zero :: nat    ("0")
    16   Suc :: "nat => nat"
    17   rec :: "[nat, 'a, [nat, 'a] => 'a] => 'a"
    18 
    19 axioms
    20   induct [case_names Zero Suc, induct type: nat]:
    21     "P(0) ==> (!!x. P(x) ==> P(Suc(x))) ==> P(n)"
    22   Suc_inject: "Suc(m) = Suc(n) ==> m = n"
    23   Suc_neq_0: "Suc(m) = 0 ==> R"
    24   rec_0: "rec(0, a, f) = a"
    25   rec_Suc: "rec(Suc(m), a, f) = f(m, rec(m, a, f))"
    26 
    27 lemma Suc_n_not_n: "Suc(k) \<noteq> k"
    28 proof (induct k)
    29   show "Suc(0) \<noteq> 0"
    30   proof
    31     assume "Suc(0) = 0"
    32     thus False by (rule Suc_neq_0)
    33   qed
    34   fix n assume hyp: "Suc(n) \<noteq> n"
    35   show "Suc(Suc(n)) \<noteq> Suc(n)"
    36   proof
    37     assume "Suc(Suc(n)) = Suc(n)"
    38     hence "Suc(n) = n" by (rule Suc_inject)
    39     with hyp show False by contradiction
    40   qed
    41 qed
    42 
    43 
    44 constdefs
    45   add :: "[nat, nat] => nat"    (infixl "+" 60)
    46   "m + n == rec(m, n, \<lambda>x y. Suc(y))"
    47 
    48 lemma add_0 [simp]: "0 + n = n"
    49   by (unfold add_def) (rule rec_0)
    50 
    51 lemma add_Suc [simp]: "Suc(m) + n = Suc(m + n)"
    52   by (unfold add_def) (rule rec_Suc)
    53 
    54 lemma add_assoc: "(k + m) + n = k + (m + n)"
    55   by (induct k) simp_all
    56 
    57 lemma add_0_right: "m + 0 = m"
    58   by (induct m) simp_all
    59 
    60 lemma add_Suc_right: "m + Suc(n) = Suc(m + n)"
    61   by (induct m) simp_all
    62 
    63 lemma "(!!n. f(Suc(n)) = Suc(f(n))) ==> f(i + j) = i + f(j)"
    64 proof -
    65   assume "!!n. f(Suc(n)) = Suc(f(n))"
    66   thus ?thesis by (induct i) simp_all
    67 qed
    68 
    69 end