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