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