3115
|
1 |
(* Title: FOL/ex/Nat.thy
|
1473
|
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
0
|
3 |
Copyright 1992 University of Cambridge
|
|
4 |
*)
|
|
5 |
|
17245
|
6 |
header {* Theory of the natural numbers: Peano's axioms, primitive recursion *}
|
|
7 |
|
|
8 |
theory Nat
|
|
9 |
imports FOL
|
|
10 |
begin
|
|
11 |
|
|
12 |
typedecl nat
|
|
13 |
arities nat :: "term"
|
|
14 |
|
|
15 |
consts
|
|
16 |
0 :: nat ("0")
|
|
17 |
Suc :: "nat => nat"
|
25989
|
18 |
rec :: "[nat, 'a, [nat, 'a] => 'a] => 'a"
|
17245
|
19 |
add :: "[nat, nat] => nat" (infixl "+" 60)
|
|
20 |
|
|
21 |
axioms
|
|
22 |
induct: "[| P(0); !!x. P(x) ==> P(Suc(x)) |] ==> P(n)"
|
|
23 |
Suc_inject: "Suc(m)=Suc(n) ==> m=n"
|
|
24 |
Suc_neq_0: "Suc(m)=0 ==> R"
|
|
25 |
rec_0: "rec(0,a,f) = a"
|
|
26 |
rec_Suc: "rec(Suc(m), a, f) = f(m, rec(m,a,f))"
|
19819
|
27 |
|
|
28 |
defs
|
17245
|
29 |
add_def: "m+n == rec(m, n, %x y. Suc(y))"
|
|
30 |
|
19819
|
31 |
|
|
32 |
subsection {* Proofs about the natural numbers *}
|
|
33 |
|
|
34 |
lemma Suc_n_not_n: "Suc(k) ~= k"
|
|
35 |
apply (rule_tac n = k in induct)
|
|
36 |
apply (rule notI)
|
|
37 |
apply (erule Suc_neq_0)
|
|
38 |
apply (rule notI)
|
|
39 |
apply (erule notE)
|
|
40 |
apply (erule Suc_inject)
|
|
41 |
done
|
|
42 |
|
|
43 |
lemma "(k+m)+n = k+(m+n)"
|
|
44 |
apply (rule induct)
|
|
45 |
back
|
|
46 |
back
|
|
47 |
back
|
|
48 |
back
|
|
49 |
back
|
|
50 |
back
|
|
51 |
oops
|
|
52 |
|
|
53 |
lemma add_0 [simp]: "0+n = n"
|
|
54 |
apply (unfold add_def)
|
|
55 |
apply (rule rec_0)
|
|
56 |
done
|
|
57 |
|
|
58 |
lemma add_Suc [simp]: "Suc(m)+n = Suc(m+n)"
|
|
59 |
apply (unfold add_def)
|
|
60 |
apply (rule rec_Suc)
|
|
61 |
done
|
|
62 |
|
|
63 |
lemma add_assoc: "(k+m)+n = k+(m+n)"
|
|
64 |
apply (rule_tac n = k in induct)
|
|
65 |
apply simp
|
|
66 |
apply simp
|
|
67 |
done
|
|
68 |
|
|
69 |
lemma add_0_right: "m+0 = m"
|
|
70 |
apply (rule_tac n = m in induct)
|
|
71 |
apply simp
|
|
72 |
apply simp
|
|
73 |
done
|
|
74 |
|
|
75 |
lemma add_Suc_right: "m+Suc(n) = Suc(m+n)"
|
|
76 |
apply (rule_tac n = m in induct)
|
|
77 |
apply simp_all
|
|
78 |
done
|
|
79 |
|
|
80 |
lemma
|
|
81 |
assumes prem: "!!n. f(Suc(n)) = Suc(f(n))"
|
|
82 |
shows "f(i+j) = i+f(j)"
|
|
83 |
apply (rule_tac n = i in induct)
|
|
84 |
apply simp
|
|
85 |
apply (simp add: prem)
|
|
86 |
done
|
17245
|
87 |
|
0
|
88 |
end
|