src/FOL/ex/Nat.thy
author wenzelm
Fri, 30 Apr 2010 17:18:29 +0200
changeset 36545 5c5b5c7f1157
parent 31974 e81979a703a4
child 41310 65631ca437c9
permissions -rw-r--r--
conditional warnings: explicitly observe context visibility flag, not just accidental presence of a context; map_ss: explicitly provide a temporary context, which might be required for mksimps, mkcongs etc.;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3115
24ed05500380 tuned comments;
wenzelm
parents: 1473
diff changeset
     1
(*  Title:      FOL/ex/Nat.thy
1473
e8d4606e6502 expanded tabs
clasohm
parents: 1322
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Copyright   1992  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
17245
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
     6
header {* Theory of the natural numbers: Peano's axioms, primitive recursion *}
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
     7
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
     8
theory Nat
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
     9
imports FOL
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    10
begin
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    11
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    12
typedecl nat
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    13
arities nat :: "term"
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    14
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    15
consts
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    16
  0 :: nat    ("0")
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    17
  Suc :: "nat => nat"
25989
wenzelm
parents: 19819
diff changeset
    18
  rec :: "[nat, 'a, [nat, 'a] => 'a] => 'a"
17245
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    19
  add :: "[nat, nat] => nat"    (infixl "+" 60)
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    20
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    21
axioms
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    22
  induct:      "[| P(0);  !!x. P(x) ==> P(Suc(x)) |]  ==> P(n)"
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    23
  Suc_inject:  "Suc(m)=Suc(n) ==> m=n"
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    24
  Suc_neq_0:   "Suc(m)=0      ==> R"
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    25
  rec_0:       "rec(0,a,f) = a"
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    26
  rec_Suc:     "rec(Suc(m), a, f) = f(m, rec(m,a,f))"
19819
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    27
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    28
defs
17245
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    29
  add_def:     "m+n == rec(m, n, %x y. Suc(y))"
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    30
19819
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    31
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    32
subsection {* Proofs about the natural numbers *}
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    33
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    34
lemma Suc_n_not_n: "Suc(k) ~= k"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    35
apply (rule_tac n = k in induct)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    36
apply (rule notI)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    37
apply (erule Suc_neq_0)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    38
apply (rule notI)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    39
apply (erule notE)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    40
apply (erule Suc_inject)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    41
done
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    42
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    43
lemma "(k+m)+n = k+(m+n)"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    44
apply (rule induct)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    45
back
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    46
back
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    47
back
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    48
back
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    49
back
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    50
back
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    51
oops
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    52
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    53
lemma add_0 [simp]: "0+n = n"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    54
apply (unfold add_def)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    55
apply (rule rec_0)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    56
done
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    57
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    58
lemma add_Suc [simp]: "Suc(m)+n = Suc(m+n)"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    59
apply (unfold add_def)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    60
apply (rule rec_Suc)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    61
done
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    62
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    63
lemma add_assoc: "(k+m)+n = k+(m+n)"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    64
apply (rule_tac n = k in induct)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    65
apply simp
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    66
apply simp
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    67
done
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    68
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    69
lemma add_0_right: "m+0 = m"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    70
apply (rule_tac n = m in induct)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    71
apply simp
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    72
apply simp
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    73
done
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    74
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    75
lemma add_Suc_right: "m+Suc(n) = Suc(m+n)"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    76
apply (rule_tac n = m in induct)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    77
apply simp_all
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    78
done
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    79
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    80
lemma
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    81
  assumes prem: "!!n. f(Suc(n)) = Suc(f(n))"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    82
  shows "f(i+j) = i+f(j)"
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    83
apply (rule_tac n = i in induct)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    84
apply simp
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    85
apply (simp add: prem)
14de4d05d275 removed obsolete ML files;
wenzelm
parents: 17245
diff changeset
    86
done
17245
1c519a3cca59 converted to Isar theory format;
wenzelm
parents: 3115
diff changeset
    87
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
end