129 by (ALLGOALS Asm_simp_tac); |
129 by (ALLGOALS Asm_simp_tac); |
130 qed "n_not_Suc_n"; |
130 qed "n_not_Suc_n"; |
131 |
131 |
132 bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym); |
132 bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym); |
133 |
133 |
|
134 goal thy "!!n. n ~= 0 ==> EX m. n = Suc m"; |
|
135 br natE 1; |
|
136 by (REPEAT (Blast_tac 1)); |
|
137 qed "not0_implies_Suc"; |
|
138 |
|
139 |
134 (*** nat_case -- the selection operator for nat ***) |
140 (*** nat_case -- the selection operator for nat ***) |
135 |
141 |
136 goalw thy [nat_case_def] "nat_case a f 0 = a"; |
142 goalw thy [nat_case_def] "nat_case a f 0 = a"; |
137 by (blast_tac (!claset addIs [select_equality]) 1); |
143 by (blast_tac (!claset addIs [select_equality]) 1); |
138 qed "nat_case_0"; |
144 qed "nat_case_0"; |
139 |
145 |
140 goalw thy [nat_case_def] "nat_case a f (Suc k) = f(k)"; |
146 goalw thy [nat_case_def] "nat_case a f (Suc k) = f(k)"; |
141 by (blast_tac (!claset addIs [select_equality]) 1); |
147 by (blast_tac (!claset addIs [select_equality]) 1); |
142 qed "nat_case_Suc"; |
148 qed "nat_case_Suc"; |
143 |
149 |
144 (** Introduction rules for 'pred_nat' **) |
150 goalw thy [wf_def, pred_nat_def] "wf(pred_nat)"; |
145 |
|
146 goalw thy [pred_nat_def] "(n, Suc(n)) : pred_nat"; |
|
147 by (Blast_tac 1); |
|
148 qed "pred_natI"; |
|
149 |
|
150 val major::prems = goalw thy [pred_nat_def] |
|
151 "[| p : pred_nat; !!x n. [| p = (n, Suc(n)) |] ==> R \ |
|
152 \ |] ==> R"; |
|
153 by (rtac (major RS CollectE) 1); |
|
154 by (REPEAT (eresolve_tac ([asm_rl,exE]@prems) 1)); |
|
155 qed "pred_natE"; |
|
156 |
|
157 goalw thy [wf_def] "wf(pred_nat)"; |
|
158 by (strip_tac 1); |
151 by (strip_tac 1); |
159 by (nat_ind_tac "x" 1); |
152 by (nat_ind_tac "x" 1); |
160 by (blast_tac (!claset addSEs [mp, pred_natE]) 2); |
153 by (ALLGOALS Blast_tac); |
161 by (blast_tac (!claset addSEs [mp, pred_natE]) 1); |
|
162 qed "wf_pred_nat"; |
154 qed "wf_pred_nat"; |
163 |
155 |
164 |
156 |
165 (*** nat_rec -- by wf recursion on pred_nat ***) |
157 (*** nat_rec -- by wf recursion on pred_nat ***) |
166 |
158 |
183 by (simp_tac (!simpset addsimps [nat_case_0]) 1); |
175 by (simp_tac (!simpset addsimps [nat_case_0]) 1); |
184 qed "nat_rec_0"; |
176 qed "nat_rec_0"; |
185 |
177 |
186 goal thy "nat_rec c h (Suc n) = h n (nat_rec c h n)"; |
178 goal thy "nat_rec c h (Suc n) = h n (nat_rec c h n)"; |
187 by (rtac (nat_rec_unfold RS trans) 1); |
179 by (rtac (nat_rec_unfold RS trans) 1); |
188 by (simp_tac (!simpset addsimps [nat_case_Suc, pred_natI, cut_apply]) 1); |
180 by (simp_tac (!simpset addsimps [nat_case_Suc, pred_nat_def, cut_apply]) 1); |
189 qed "nat_rec_Suc"; |
181 qed "nat_rec_Suc"; |
190 |
182 |
191 (*These 2 rules ease the use of primitive recursion. NOTE USE OF == *) |
183 (*These 2 rules ease the use of primitive recursion. NOTE USE OF == *) |
192 val [rew] = goal thy |
184 val [rew] = goal thy |
193 "[| !!n. f(n) == nat_rec c h n |] ==> f(0) = c"; |
185 "[| !!n. f(n) == nat_rec c h n |] ==> f(0) = c"; |
214 by (rtac (trans_trancl RS transD) 1); |
206 by (rtac (trans_trancl RS transD) 1); |
215 by (resolve_tac prems 1); |
207 by (resolve_tac prems 1); |
216 by (resolve_tac prems 1); |
208 by (resolve_tac prems 1); |
217 qed "less_trans"; |
209 qed "less_trans"; |
218 |
210 |
219 goalw thy [less_def] "n < Suc(n)"; |
211 goalw thy [less_def, pred_nat_def] "n < Suc(n)"; |
220 by (rtac (pred_natI RS r_into_trancl) 1); |
212 by (simp_tac (!simpset addsimps [r_into_trancl]) 1); |
221 qed "lessI"; |
213 qed "lessI"; |
222 AddIffs [lessI]; |
214 AddIffs [lessI]; |
223 |
215 |
224 (* i<j ==> i<Suc(j) *) |
216 (* i<j ==> i<Suc(j) *) |
225 bind_thm("less_SucI", lessI RSN (2, less_trans)); |
217 bind_thm("less_SucI", lessI RSN (2, less_trans)); |
253 goal thy "!!m. n<m ==> m ~= (n::nat)"; |
245 goal thy "!!m. n<m ==> m ~= (n::nat)"; |
254 by (blast_tac (!claset addSEs [less_irrefl]) 1); |
246 by (blast_tac (!claset addSEs [less_irrefl]) 1); |
255 qed "less_not_refl2"; |
247 qed "less_not_refl2"; |
256 |
248 |
257 |
249 |
258 val major::prems = goalw thy [less_def] |
250 val major::prems = goalw thy [less_def, pred_nat_def] |
259 "[| i<k; k=Suc(i) ==> P; !!j. [| i<j; k=Suc(j) |] ==> P \ |
251 "[| i<k; k=Suc(i) ==> P; !!j. [| i<j; k=Suc(j) |] ==> P \ |
260 \ |] ==> P"; |
252 \ |] ==> P"; |
261 by (rtac (major RS tranclE) 1); |
253 by (rtac (major RS tranclE) 1); |
|
254 by (ALLGOALS Full_simp_tac); |
262 by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE' |
255 by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE' |
263 eresolve_tac (prems@[pred_natE, Pair_inject]))); |
256 eresolve_tac (prems@[asm_rl, Pair_inject]))); |
264 by (rtac refl 1); |
|
265 qed "lessE"; |
257 qed "lessE"; |
266 |
258 |
267 goal thy "~ n<0"; |
259 goal thy "~ n<0"; |
268 by (rtac notI 1); |
260 by (rtac notI 1); |
269 by (etac lessE 1); |
261 by (etac lessE 1); |