3115

1 
(* Title: FOL/ex/Nat.thy

0

2 
ID: $Id$

1473

3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory

0

4 
Copyright 1992 University of Cambridge


5 
*)


6 

17245

7 
header {* Theory of the natural numbers: Peano's axioms, primitive recursion *}


8 


9 
theory Nat


10 
imports FOL


11 
begin


12 


13 
typedecl nat


14 
arities nat :: "term"


15 


16 
consts


17 
0 :: nat ("0")


18 
Suc :: "nat => nat"


19 
rec :: "[nat, 'a, [nat,'a]=>'a] => 'a"


20 
add :: "[nat, nat] => nat" (infixl "+" 60)


21 


22 
axioms


23 
induct: "[ P(0); !!x. P(x) ==> P(Suc(x)) ] ==> P(n)"


24 
Suc_inject: "Suc(m)=Suc(n) ==> m=n"


25 
Suc_neq_0: "Suc(m)=0 ==> R"


26 
rec_0: "rec(0,a,f) = a"


27 
rec_Suc: "rec(Suc(m), a, f) = f(m, rec(m,a,f))"

19819

28 


29 
defs

17245

30 
add_def: "m+n == rec(m, n, %x y. Suc(y))"


31 

19819

32 


33 
subsection {* Proofs about the natural numbers *}


34 


35 
lemma Suc_n_not_n: "Suc(k) ~= k"


36 
apply (rule_tac n = k in induct)


37 
apply (rule notI)


38 
apply (erule Suc_neq_0)


39 
apply (rule notI)


40 
apply (erule notE)


41 
apply (erule Suc_inject)


42 
done


43 


44 
lemma "(k+m)+n = k+(m+n)"


45 
apply (rule induct)


46 
back


47 
back


48 
back


49 
back


50 
back


51 
back


52 
oops


53 


54 
lemma add_0 [simp]: "0+n = n"


55 
apply (unfold add_def)


56 
apply (rule rec_0)


57 
done


58 


59 
lemma add_Suc [simp]: "Suc(m)+n = Suc(m+n)"


60 
apply (unfold add_def)


61 
apply (rule rec_Suc)


62 
done


63 


64 
lemma add_assoc: "(k+m)+n = k+(m+n)"


65 
apply (rule_tac n = k in induct)


66 
apply simp


67 
apply simp


68 
done


69 


70 
lemma add_0_right: "m+0 = m"


71 
apply (rule_tac n = m in induct)


72 
apply simp


73 
apply simp


74 
done


75 


76 
lemma add_Suc_right: "m+Suc(n) = Suc(m+n)"


77 
apply (rule_tac n = m in induct)


78 
apply simp_all


79 
done


80 


81 
lemma


82 
assumes prem: "!!n. f(Suc(n)) = Suc(f(n))"


83 
shows "f(i+j) = i+f(j)"


84 
apply (rule_tac n = i in induct)


85 
apply simp


86 
apply (simp add: prem)


87 
done

17245

88 

0

89 
end
