0
|
1 |
(* Title: FOL/ex/nat2.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow
|
|
4 |
Copyright 1991 University of Cambridge
|
|
5 |
|
|
6 |
For ex/nat.thy.
|
|
7 |
Examples of simplification and induction on the natural numbers
|
|
8 |
*)
|
|
9 |
|
|
10 |
open Nat2;
|
|
11 |
|
|
12 |
val nat_rews = [pred_0, pred_succ, plus_0, plus_succ,
|
|
13 |
nat_distinct1, nat_distinct2, succ_inject,
|
|
14 |
leq_0,leq_succ_succ,leq_succ_0,
|
|
15 |
lt_0_succ,lt_succ_succ,lt_0];
|
|
16 |
|
|
17 |
val nat_ss = FOL_ss addsimps nat_rews;
|
|
18 |
|
|
19 |
val prems = goal Nat2.thy
|
|
20 |
"[| P(0); !!x. P(succ(x)) |] ==> All(P)";
|
|
21 |
by (rtac nat_ind 1);
|
|
22 |
by (REPEAT (resolve_tac (prems@[allI,impI]) 1));
|
725
|
23 |
qed "nat_exh";
|
0
|
24 |
|
|
25 |
goal Nat2.thy "~ n=succ(n)";
|
|
26 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
27 |
result();
|
|
28 |
|
|
29 |
goal Nat2.thy "~ succ(n)=n";
|
|
30 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
31 |
result();
|
|
32 |
|
|
33 |
goal Nat2.thy "~ succ(succ(n))=n";
|
|
34 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
35 |
result();
|
|
36 |
|
|
37 |
goal Nat2.thy "~ n=succ(succ(n))";
|
|
38 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
39 |
result();
|
|
40 |
|
|
41 |
goal Nat2.thy "m+0 = m";
|
|
42 |
by (IND_TAC nat_ind (simp_tac nat_ss) "m" 1);
|
725
|
43 |
qed "plus_0_right";
|
0
|
44 |
|
|
45 |
goal Nat2.thy "m+succ(n) = succ(m+n)";
|
|
46 |
by (IND_TAC nat_ind (simp_tac nat_ss) "m" 1);
|
725
|
47 |
qed "plus_succ_right";
|
0
|
48 |
|
|
49 |
goal Nat2.thy "~n=0 --> m+pred(n) = pred(m+n)";
|
|
50 |
by (IND_TAC nat_ind (simp_tac (nat_ss addsimps [plus_succ_right])) "n" 1);
|
|
51 |
result();
|
|
52 |
|
|
53 |
goal Nat2.thy "~n=0 --> succ(pred(n))=n";
|
|
54 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
55 |
result();
|
|
56 |
|
|
57 |
goal Nat2.thy "m+n=0 <-> m=0 & n=0";
|
|
58 |
by (IND_TAC nat_ind (simp_tac nat_ss) "m" 1);
|
|
59 |
result();
|
|
60 |
|
|
61 |
goal Nat2.thy "m <= n --> m <= succ(n)";
|
|
62 |
by (IND_TAC nat_ind (simp_tac nat_ss) "m" 1);
|
|
63 |
by (rtac (impI RS allI) 1);
|
|
64 |
by (ALL_IND_TAC nat_ind (simp_tac nat_ss) 1);
|
|
65 |
by (fast_tac FOL_cs 1);
|
|
66 |
val le_imp_le_succ = result() RS mp;
|
725
|
67 |
store_thm("le_imp_le_succ", le_imp_le_succ);
|
0
|
68 |
|
|
69 |
goal Nat2.thy "n<succ(n)";
|
|
70 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
71 |
result();
|
|
72 |
|
|
73 |
goal Nat2.thy "~ n<n";
|
|
74 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
75 |
result();
|
|
76 |
|
|
77 |
goal Nat2.thy "m < n --> m < succ(n)";
|
|
78 |
by (IND_TAC nat_ind (simp_tac nat_ss) "m" 1);
|
|
79 |
by (rtac (impI RS allI) 1);
|
|
80 |
by (ALL_IND_TAC nat_ind (simp_tac nat_ss) 1);
|
|
81 |
by (fast_tac FOL_cs 1);
|
|
82 |
result();
|
|
83 |
|
|
84 |
goal Nat2.thy "m <= n --> m <= n+k";
|
|
85 |
by (IND_TAC nat_ind
|
|
86 |
(simp_tac (nat_ss addsimps [plus_0_right, plus_succ_right, le_imp_le_succ]))
|
|
87 |
"k" 1);
|
|
88 |
val le_plus = result();
|
|
89 |
|
|
90 |
goal Nat2.thy "succ(m) <= n --> m <= n";
|
|
91 |
by (res_inst_tac [("x","n")]spec 1);
|
|
92 |
by (ALL_IND_TAC nat_exh (simp_tac (nat_ss addsimps [le_imp_le_succ])) 1);
|
|
93 |
val succ_le = result();
|
|
94 |
|
|
95 |
goal Nat2.thy "~m<n <-> n<=m";
|
|
96 |
by (IND_TAC nat_ind (simp_tac nat_ss) "n" 1);
|
|
97 |
by (rtac (impI RS allI) 1);
|
|
98 |
by (ALL_IND_TAC nat_ind (asm_simp_tac nat_ss) 1);
|
725
|
99 |
qed "not_less";
|
0
|
100 |
|
|
101 |
goal Nat2.thy "n<=m --> ~m<n";
|
|
102 |
by (simp_tac (nat_ss addsimps [not_less]) 1);
|
|
103 |
val le_imp_not_less = result();
|
|
104 |
|
|
105 |
goal Nat2.thy "m<n --> ~n<=m";
|
|
106 |
by (cut_facts_tac [not_less] 1 THEN fast_tac FOL_cs 1);
|
|
107 |
val not_le = result();
|
|
108 |
|
|
109 |
goal Nat2.thy "m+k<=n --> m<=n";
|
|
110 |
by (IND_TAC nat_ind (K all_tac) "k" 1);
|
|
111 |
by (simp_tac (nat_ss addsimps [plus_0_right]) 1);
|
|
112 |
by (rtac (impI RS allI) 1);
|
|
113 |
by (simp_tac (nat_ss addsimps [plus_succ_right]) 1);
|
|
114 |
by (REPEAT (resolve_tac [allI,impI] 1));
|
|
115 |
by (cut_facts_tac [succ_le] 1);
|
|
116 |
by (fast_tac FOL_cs 1);
|
|
117 |
val plus_le = result();
|
|
118 |
|
|
119 |
val prems = goal Nat2.thy "[| ~m=0; m <= n |] ==> ~n=0";
|
|
120 |
by (cut_facts_tac prems 1);
|
|
121 |
by (REPEAT (etac rev_mp 1));
|
|
122 |
by (IND_TAC nat_exh (simp_tac nat_ss) "m" 1);
|
|
123 |
by (ALL_IND_TAC nat_exh (simp_tac nat_ss) 1);
|
|
124 |
val not0 = result();
|
|
125 |
|
|
126 |
goal Nat2.thy "a<=a' & b<=b' --> a+b<=a'+b'";
|
|
127 |
by (IND_TAC nat_ind (simp_tac (nat_ss addsimps [plus_0_right,le_plus])) "b" 1);
|
|
128 |
by (resolve_tac [impI RS allI] 1);
|
|
129 |
by (resolve_tac [allI RS allI] 1);
|
|
130 |
by (ALL_IND_TAC nat_exh (asm_simp_tac (nat_ss addsimps [plus_succ_right])) 1);
|
|
131 |
val plus_le_plus = result();
|
|
132 |
|
|
133 |
goal Nat2.thy "i<=j --> j<=k --> i<=k";
|
|
134 |
by (IND_TAC nat_ind (K all_tac) "i" 1);
|
|
135 |
by (simp_tac nat_ss 1);
|
|
136 |
by (resolve_tac [impI RS allI] 1);
|
|
137 |
by (ALL_IND_TAC nat_exh (simp_tac nat_ss) 1);
|
|
138 |
by (ALL_IND_TAC nat_exh (simp_tac nat_ss) 1);
|
|
139 |
by (fast_tac FOL_cs 1);
|
|
140 |
val le_trans = result();
|
|
141 |
|
|
142 |
goal Nat2.thy "i < j --> j <=k --> i < k";
|
|
143 |
by (IND_TAC nat_ind (K all_tac) "j" 1);
|
|
144 |
by (simp_tac nat_ss 1);
|
|
145 |
by (resolve_tac [impI RS allI] 1);
|
|
146 |
by (ALL_IND_TAC nat_exh (simp_tac nat_ss) 1);
|
|
147 |
by (ALL_IND_TAC nat_exh (simp_tac nat_ss) 1);
|
|
148 |
by (ALL_IND_TAC nat_exh (simp_tac nat_ss) 1);
|
|
149 |
by (fast_tac FOL_cs 1);
|
|
150 |
val less_le_trans = result();
|
|
151 |
|
|
152 |
goal Nat2.thy "succ(i) <= j <-> i < j";
|
|
153 |
by (IND_TAC nat_ind (simp_tac nat_ss) "j" 1);
|
|
154 |
by (resolve_tac [impI RS allI] 1);
|
|
155 |
by (ALL_IND_TAC nat_exh (asm_simp_tac nat_ss) 1);
|
|
156 |
val succ_le = result();
|
|
157 |
|
|
158 |
goal Nat2.thy "i<succ(j) <-> i=j | i<j";
|
|
159 |
by (IND_TAC nat_ind (simp_tac nat_ss) "j" 1);
|
|
160 |
by (ALL_IND_TAC nat_exh (simp_tac nat_ss) 1);
|
|
161 |
by (resolve_tac [impI RS allI] 1);
|
|
162 |
by (ALL_IND_TAC nat_exh (asm_simp_tac nat_ss) 1);
|
|
163 |
val less_succ = result();
|
|
164 |
|