author | paulson |
Thu, 13 Aug 1998 18:14:26 +0200 | |
changeset 5316 | 7a8975451a89 |
parent 5187 | 55f07169cf5f |
child 5354 | da63d9b35caf |
permissions | -rw-r--r-- |
2608 | 1 |
(* Title: HOL/NatDef.ML |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow, Cambridge University Computer Laboratory |
|
4 |
Copyright 1991 University of Cambridge |
|
4737 | 5 |
|
6 |
Blast_tac proofs here can get PROOF FAILED of Ord theorems like order_refl |
|
7 |
and order_less_irrefl. We do not add the "nat" versions to the basic claset |
|
8 |
because the type will be promoted to type class "order". |
|
2608 | 9 |
*) |
10 |
||
5069 | 11 |
Goal "mono(%X. {Zero_Rep} Un (Suc_Rep``X))"; |
2608 | 12 |
by (REPEAT (ares_tac [monoI, subset_refl, image_mono, Un_mono] 1)); |
13 |
qed "Nat_fun_mono"; |
|
14 |
||
15 |
val Nat_unfold = Nat_fun_mono RS (Nat_def RS def_lfp_Tarski); |
|
16 |
||
17 |
(* Zero is a natural number -- this also justifies the type definition*) |
|
5069 | 18 |
Goal "Zero_Rep: Nat"; |
2608 | 19 |
by (stac Nat_unfold 1); |
20 |
by (rtac (singletonI RS UnI1) 1); |
|
21 |
qed "Zero_RepI"; |
|
22 |
||
5316 | 23 |
Goal "i: Nat ==> Suc_Rep(i) : Nat"; |
2608 | 24 |
by (stac Nat_unfold 1); |
25 |
by (rtac (imageI RS UnI2) 1); |
|
5316 | 26 |
by (assume_tac 1); |
2608 | 27 |
qed "Suc_RepI"; |
28 |
||
29 |
(*** Induction ***) |
|
30 |
||
5316 | 31 |
val major::prems = Goal |
2608 | 32 |
"[| i: Nat; P(Zero_Rep); \ |
33 |
\ !!j. [| j: Nat; P(j) |] ==> P(Suc_Rep(j)) |] ==> P(i)"; |
|
34 |
by (rtac ([Nat_def, Nat_fun_mono, major] MRS def_induct) 1); |
|
4089 | 35 |
by (blast_tac (claset() addIs prems) 1); |
2608 | 36 |
qed "Nat_induct"; |
37 |
||
5316 | 38 |
val prems = Goalw [Zero_def,Suc_def] |
2608 | 39 |
"[| P(0); \ |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3023
diff
changeset
|
40 |
\ !!n. P(n) ==> P(Suc(n)) |] ==> P(n)"; |
2608 | 41 |
by (rtac (Rep_Nat_inverse RS subst) 1); (*types force good instantiation*) |
42 |
by (rtac (Rep_Nat RS Nat_induct) 1); |
|
43 |
by (REPEAT (ares_tac prems 1 |
|
44 |
ORELSE eresolve_tac [Abs_Nat_inverse RS subst] 1)); |
|
45 |
qed "nat_induct"; |
|
46 |
||
47 |
(*Perform induction on n. *) |
|
5187
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents:
5148
diff
changeset
|
48 |
fun nat_ind_tac a i = |
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents:
5148
diff
changeset
|
49 |
res_inst_tac [("n",a)] nat_induct i THEN rename_last_tac a [""] (i+1); |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3023
diff
changeset
|
50 |
|
2608 | 51 |
(*A special form of induction for reasoning about m<n and m-n*) |
5316 | 52 |
val prems = Goal |
2608 | 53 |
"[| !!x. P x 0; \ |
54 |
\ !!y. P 0 (Suc y); \ |
|
55 |
\ !!x y. [| P x y |] ==> P (Suc x) (Suc y) \ |
|
56 |
\ |] ==> P m n"; |
|
57 |
by (res_inst_tac [("x","m")] spec 1); |
|
58 |
by (nat_ind_tac "n" 1); |
|
59 |
by (rtac allI 2); |
|
60 |
by (nat_ind_tac "x" 2); |
|
61 |
by (REPEAT (ares_tac (prems@[allI]) 1 ORELSE etac spec 1)); |
|
62 |
qed "diff_induct"; |
|
63 |
||
64 |
(*** Isomorphisms: Abs_Nat and Rep_Nat ***) |
|
65 |
||
66 |
(*We can't take these properties as axioms, or take Abs_Nat==Inv(Rep_Nat), |
|
67 |
since we assume the isomorphism equations will one day be given by Isabelle*) |
|
68 |
||
5069 | 69 |
Goal "inj(Rep_Nat)"; |
2608 | 70 |
by (rtac inj_inverseI 1); |
71 |
by (rtac Rep_Nat_inverse 1); |
|
72 |
qed "inj_Rep_Nat"; |
|
73 |
||
5069 | 74 |
Goal "inj_on Abs_Nat Nat"; |
4830 | 75 |
by (rtac inj_on_inverseI 1); |
2608 | 76 |
by (etac Abs_Nat_inverse 1); |
4830 | 77 |
qed "inj_on_Abs_Nat"; |
2608 | 78 |
|
79 |
(*** Distinctness of constructors ***) |
|
80 |
||
5069 | 81 |
Goalw [Zero_def,Suc_def] "Suc(m) ~= 0"; |
4830 | 82 |
by (rtac (inj_on_Abs_Nat RS inj_on_contraD) 1); |
2608 | 83 |
by (rtac Suc_Rep_not_Zero_Rep 1); |
84 |
by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI, Zero_RepI] 1)); |
|
85 |
qed "Suc_not_Zero"; |
|
86 |
||
87 |
bind_thm ("Zero_not_Suc", Suc_not_Zero RS not_sym); |
|
88 |
||
89 |
AddIffs [Suc_not_Zero,Zero_not_Suc]; |
|
90 |
||
91 |
bind_thm ("Suc_neq_Zero", (Suc_not_Zero RS notE)); |
|
92 |
val Zero_neq_Suc = sym RS Suc_neq_Zero; |
|
93 |
||
94 |
(** Injectiveness of Suc **) |
|
95 |
||
5069 | 96 |
Goalw [Suc_def] "inj(Suc)"; |
2608 | 97 |
by (rtac injI 1); |
4830 | 98 |
by (dtac (inj_on_Abs_Nat RS inj_onD) 1); |
2608 | 99 |
by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI] 1)); |
100 |
by (dtac (inj_Suc_Rep RS injD) 1); |
|
101 |
by (etac (inj_Rep_Nat RS injD) 1); |
|
102 |
qed "inj_Suc"; |
|
103 |
||
104 |
val Suc_inject = inj_Suc RS injD; |
|
105 |
||
5069 | 106 |
Goal "(Suc(m)=Suc(n)) = (m=n)"; |
2608 | 107 |
by (EVERY1 [rtac iffI, etac Suc_inject, etac arg_cong]); |
108 |
qed "Suc_Suc_eq"; |
|
109 |
||
110 |
AddIffs [Suc_Suc_eq]; |
|
111 |
||
5069 | 112 |
Goal "n ~= Suc(n)"; |
2608 | 113 |
by (nat_ind_tac "n" 1); |
114 |
by (ALLGOALS Asm_simp_tac); |
|
115 |
qed "n_not_Suc_n"; |
|
116 |
||
117 |
bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym); |
|
118 |
||
5187
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents:
5148
diff
changeset
|
119 |
(*** Basic properties of "less than" ***) |
2608 | 120 |
|
5069 | 121 |
Goalw [wf_def, pred_nat_def] "wf(pred_nat)"; |
3718 | 122 |
by (Clarify_tac 1); |
2608 | 123 |
by (nat_ind_tac "x" 1); |
3236 | 124 |
by (ALLGOALS Blast_tac); |
2608 | 125 |
qed "wf_pred_nat"; |
126 |
||
3378 | 127 |
(*Used in TFL/post.sml*) |
5069 | 128 |
Goalw [less_def] "(m,n) : pred_nat^+ = (m<n)"; |
3378 | 129 |
by (rtac refl 1); |
130 |
qed "less_eq"; |
|
131 |
||
2608 | 132 |
(** Introduction properties **) |
133 |
||
5316 | 134 |
Goalw [less_def] "[| i<j; j<k |] ==> i<(k::nat)"; |
2608 | 135 |
by (rtac (trans_trancl RS transD) 1); |
5316 | 136 |
by (assume_tac 1); |
137 |
by (assume_tac 1); |
|
2608 | 138 |
qed "less_trans"; |
139 |
||
5069 | 140 |
Goalw [less_def, pred_nat_def] "n < Suc(n)"; |
4089 | 141 |
by (simp_tac (simpset() addsimps [r_into_trancl]) 1); |
2608 | 142 |
qed "lessI"; |
143 |
AddIffs [lessI]; |
|
144 |
||
145 |
(* i<j ==> i<Suc(j) *) |
|
146 |
bind_thm("less_SucI", lessI RSN (2, less_trans)); |
|
147 |
Addsimps [less_SucI]; |
|
148 |
||
5069 | 149 |
Goal "0 < Suc(n)"; |
2608 | 150 |
by (nat_ind_tac "n" 1); |
151 |
by (rtac lessI 1); |
|
152 |
by (etac less_trans 1); |
|
153 |
by (rtac lessI 1); |
|
154 |
qed "zero_less_Suc"; |
|
155 |
AddIffs [zero_less_Suc]; |
|
156 |
||
157 |
(** Elimination properties **) |
|
158 |
||
5316 | 159 |
Goalw [less_def] "n<m ==> ~ m<(n::nat)"; |
160 |
by (blast_tac (claset() addIs [wf_pred_nat, wf_trancl RS wf_asym])1); |
|
2608 | 161 |
qed "less_not_sym"; |
162 |
||
163 |
(* [| n<m; m<n |] ==> R *) |
|
164 |
bind_thm ("less_asym", (less_not_sym RS notE)); |
|
165 |
||
5069 | 166 |
Goalw [less_def] "~ n<(n::nat)"; |
2608 | 167 |
by (rtac notI 1); |
168 |
by (etac (wf_pred_nat RS wf_trancl RS wf_irrefl) 1); |
|
169 |
qed "less_not_refl"; |
|
170 |
||
171 |
(* n<n ==> R *) |
|
172 |
bind_thm ("less_irrefl", (less_not_refl RS notE)); |
|
173 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
174 |
Goal "n<m ==> m ~= (n::nat)"; |
4089 | 175 |
by (blast_tac (claset() addSEs [less_irrefl]) 1); |
2608 | 176 |
qed "less_not_refl2"; |
177 |
||
178 |
||
5316 | 179 |
val major::prems = Goalw [less_def, pred_nat_def] |
2608 | 180 |
"[| i<k; k=Suc(i) ==> P; !!j. [| i<j; k=Suc(j) |] ==> P \ |
181 |
\ |] ==> P"; |
|
182 |
by (rtac (major RS tranclE) 1); |
|
3236 | 183 |
by (ALLGOALS Full_simp_tac); |
2608 | 184 |
by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE' |
3236 | 185 |
eresolve_tac (prems@[asm_rl, Pair_inject]))); |
2608 | 186 |
qed "lessE"; |
187 |
||
5069 | 188 |
Goal "~ n<0"; |
2608 | 189 |
by (rtac notI 1); |
190 |
by (etac lessE 1); |
|
191 |
by (etac Zero_neq_Suc 1); |
|
192 |
by (etac Zero_neq_Suc 1); |
|
193 |
qed "not_less0"; |
|
194 |
||
195 |
AddIffs [not_less0]; |
|
196 |
||
197 |
(* n<0 ==> R *) |
|
198 |
bind_thm ("less_zeroE", not_less0 RS notE); |
|
199 |
||
5316 | 200 |
val [major,less,eq] = Goal |
2608 | 201 |
"[| m < Suc(n); m<n ==> P; m=n ==> P |] ==> P"; |
202 |
by (rtac (major RS lessE) 1); |
|
203 |
by (rtac eq 1); |
|
2891 | 204 |
by (Blast_tac 1); |
2608 | 205 |
by (rtac less 1); |
2891 | 206 |
by (Blast_tac 1); |
2608 | 207 |
qed "less_SucE"; |
208 |
||
5069 | 209 |
Goal "(m < Suc(n)) = (m < n | m = n)"; |
4089 | 210 |
by (blast_tac (claset() addSEs [less_SucE] addIs [less_trans]) 1); |
2608 | 211 |
qed "less_Suc_eq"; |
212 |
||
5069 | 213 |
Goal "(n<1) = (n=0)"; |
4089 | 214 |
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
215 |
qed "less_one"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
216 |
AddIffs [less_one]; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
217 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
218 |
Goal "m<n ==> Suc(m) < Suc(n)"; |
2608 | 219 |
by (etac rev_mp 1); |
220 |
by (nat_ind_tac "n" 1); |
|
4089 | 221 |
by (ALLGOALS (fast_tac (claset() addEs [less_trans, lessE]))); |
2608 | 222 |
qed "Suc_mono"; |
223 |
||
224 |
(*"Less than" is a linear ordering*) |
|
5069 | 225 |
Goal "m<n | m=n | n<(m::nat)"; |
2608 | 226 |
by (nat_ind_tac "m" 1); |
227 |
by (nat_ind_tac "n" 1); |
|
228 |
by (rtac (refl RS disjI1 RS disjI2) 1); |
|
229 |
by (rtac (zero_less_Suc RS disjI1) 1); |
|
4089 | 230 |
by (blast_tac (claset() addIs [Suc_mono, less_SucI] addEs [lessE]) 1); |
2608 | 231 |
qed "less_linear"; |
232 |
||
5069 | 233 |
Goal "!!m::nat. (m ~= n) = (m<n | n<m)"; |
4737 | 234 |
by (cut_facts_tac [less_linear] 1); |
235 |
by (blast_tac (claset() addSEs [less_irrefl]) 1); |
|
236 |
qed "nat_neq_iff"; |
|
237 |
||
2608 | 238 |
qed_goal "nat_less_cases" thy |
239 |
"[| (m::nat)<n ==> P n m; m=n ==> P n m; n<m ==> P n m |] ==> P n m" |
|
2935 | 240 |
( fn [major,eqCase,lessCase] => |
2608 | 241 |
[ |
2935 | 242 |
(rtac (less_linear RS disjE) 1), |
2608 | 243 |
(etac disjE 2), |
2935 | 244 |
(etac lessCase 1), |
245 |
(etac (sym RS eqCase) 1), |
|
246 |
(etac major 1) |
|
2608 | 247 |
]); |
248 |
||
4745 | 249 |
|
250 |
(** Inductive (?) properties **) |
|
251 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
252 |
Goal "[| m<n; Suc m ~= n |] ==> Suc(m) < n"; |
4745 | 253 |
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1); |
254 |
by (blast_tac (claset() addSEs [less_irrefl, less_SucE] addEs [less_asym]) 1); |
|
255 |
qed "Suc_lessI"; |
|
256 |
||
5316 | 257 |
Goal "Suc(m) < n ==> m<n"; |
258 |
by (etac rev_mp 1); |
|
4745 | 259 |
by (nat_ind_tac "n" 1); |
260 |
by (ALLGOALS (fast_tac (claset() addSIs [lessI RS less_SucI] |
|
261 |
addEs [less_trans, lessE]))); |
|
262 |
qed "Suc_lessD"; |
|
263 |
||
5316 | 264 |
val [major,minor] = Goal |
4745 | 265 |
"[| Suc(i)<k; !!j. [| i<j; k=Suc(j) |] ==> P \ |
266 |
\ |] ==> P"; |
|
267 |
by (rtac (major RS lessE) 1); |
|
268 |
by (etac (lessI RS minor) 1); |
|
269 |
by (etac (Suc_lessD RS minor) 1); |
|
270 |
by (assume_tac 1); |
|
271 |
qed "Suc_lessE"; |
|
272 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
273 |
Goal "Suc(m) < Suc(n) ==> m<n"; |
4745 | 274 |
by (blast_tac (claset() addEs [lessE, make_elim Suc_lessD]) 1); |
275 |
qed "Suc_less_SucD"; |
|
276 |
||
277 |
||
5069 | 278 |
Goal "(Suc(m) < Suc(n)) = (m<n)"; |
4745 | 279 |
by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]); |
280 |
qed "Suc_less_eq"; |
|
281 |
Addsimps [Suc_less_eq]; |
|
282 |
||
5069 | 283 |
Goal "~(Suc(n) < n)"; |
4745 | 284 |
by (blast_tac (claset() addEs [Suc_lessD RS less_irrefl]) 1); |
285 |
qed "not_Suc_n_less_n"; |
|
286 |
Addsimps [not_Suc_n_less_n]; |
|
287 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
288 |
Goal "i<j ==> j<k --> Suc i < k"; |
4745 | 289 |
by (nat_ind_tac "k" 1); |
290 |
by (ALLGOALS (asm_simp_tac (simpset()))); |
|
291 |
by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
|
292 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
|
293 |
qed_spec_mp "less_trans_Suc"; |
|
294 |
||
2608 | 295 |
(*Can be used with less_Suc_eq to get n=m | n<m *) |
5069 | 296 |
Goal "(~ m < n) = (n < Suc(m))"; |
2608 | 297 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
298 |
by (ALLGOALS Asm_simp_tac); |
|
299 |
qed "not_less_eq"; |
|
300 |
||
301 |
(*Complete induction, aka course-of-values induction*) |
|
5316 | 302 |
val prems = Goalw [less_def] |
2608 | 303 |
"[| !!n. [| ! m::nat. m<n --> P(m) |] ==> P(n) |] ==> P(n)"; |
304 |
by (wf_ind_tac "n" [wf_pred_nat RS wf_trancl] 1); |
|
305 |
by (eresolve_tac prems 1); |
|
306 |
qed "less_induct"; |
|
307 |
||
308 |
(*** Properties of <= ***) |
|
309 |
||
5069 | 310 |
Goalw [le_def] "(m <= n) = (m < Suc n)"; |
2608 | 311 |
by (rtac not_less_eq 1); |
312 |
qed "le_eq_less_Suc"; |
|
313 |
||
3343 | 314 |
(* m<=n ==> m < Suc n *) |
315 |
bind_thm ("le_imp_less_Suc", le_eq_less_Suc RS iffD1); |
|
316 |
||
5069 | 317 |
Goalw [le_def] "0 <= n"; |
2608 | 318 |
by (rtac not_less0 1); |
319 |
qed "le0"; |
|
320 |
||
5069 | 321 |
Goalw [le_def] "~ Suc n <= n"; |
2608 | 322 |
by (Simp_tac 1); |
323 |
qed "Suc_n_not_le_n"; |
|
324 |
||
5069 | 325 |
Goalw [le_def] "(i <= 0) = (i = 0)"; |
2608 | 326 |
by (nat_ind_tac "i" 1); |
327 |
by (ALLGOALS Asm_simp_tac); |
|
328 |
qed "le_0_eq"; |
|
4614 | 329 |
AddIffs [le_0_eq]; |
2608 | 330 |
|
331 |
Addsimps [(*less_Suc_eq, makes simpset non-confluent*) le0, le_0_eq, |
|
332 |
Suc_n_not_le_n, |
|
5187
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents:
5148
diff
changeset
|
333 |
n_not_Suc_n, Suc_n_not_n]; |
2608 | 334 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
335 |
Goal "(m <= Suc(n)) = (m<=n | m = Suc n)"; |
4089 | 336 |
by (simp_tac (simpset() addsimps [le_eq_less_Suc]) 1); |
337 |
by (blast_tac (claset() addSEs [less_SucE] addIs [less_SucI]) 1); |
|
3355 | 338 |
qed "le_Suc_eq"; |
339 |
||
4614 | 340 |
(* [| m <= Suc n; m <= n ==> R; m = Suc n ==> R |] ==> R *) |
341 |
bind_thm ("le_SucE", le_Suc_eq RS iffD1 RS disjE); |
|
342 |
||
2608 | 343 |
(* |
5069 | 344 |
Goal "(Suc m < n | Suc m = n) = (m < n)"; |
2608 | 345 |
by (stac (less_Suc_eq RS sym) 1); |
346 |
by (rtac Suc_less_eq 1); |
|
347 |
qed "Suc_le_eq"; |
|
348 |
||
349 |
this could make the simpset (with less_Suc_eq added again) more confluent, |
|
350 |
but less_Suc_eq makes additional problems with terms of the form 0 < Suc (...) |
|
351 |
*) |
|
352 |
||
5316 | 353 |
Goalw [le_def] "~n<m ==> m<=(n::nat)"; |
354 |
by (assume_tac 1); |
|
2608 | 355 |
qed "leI"; |
356 |
||
5316 | 357 |
Goalw [le_def] "m<=n ==> ~ n < (m::nat)"; |
358 |
by (assume_tac 1); |
|
2608 | 359 |
qed "leD"; |
360 |
||
361 |
val leE = make_elim leD; |
|
362 |
||
5069 | 363 |
Goal "(~n<m) = (m<=(n::nat))"; |
4089 | 364 |
by (blast_tac (claset() addIs [leI] addEs [leE]) 1); |
2608 | 365 |
qed "not_less_iff_le"; |
366 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
367 |
Goalw [le_def] "~ m <= n ==> n<(m::nat)"; |
2891 | 368 |
by (Blast_tac 1); |
2608 | 369 |
qed "not_leE"; |
370 |
||
5069 | 371 |
Goalw [le_def] "(~n<=m) = (m<(n::nat))"; |
4599 | 372 |
by (Simp_tac 1); |
373 |
qed "not_le_iff_less"; |
|
374 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
375 |
Goalw [le_def] "m < n ==> Suc(m) <= n"; |
4089 | 376 |
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
377 |
by (blast_tac (claset() addSEs [less_irrefl,less_asym]) 1); |
|
3343 | 378 |
qed "Suc_leI"; (*formerly called lessD*) |
2608 | 379 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
380 |
Goalw [le_def] "Suc(m) <= n ==> m <= n"; |
4089 | 381 |
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
2608 | 382 |
qed "Suc_leD"; |
383 |
||
384 |
(* stronger version of Suc_leD *) |
|
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset
|
385 |
Goalw [le_def] "Suc m <= n ==> m < n"; |
4089 | 386 |
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
2608 | 387 |
by (cut_facts_tac [less_linear] 1); |
2891 | 388 |
by (Blast_tac 1); |
2608 | 389 |
qed "Suc_le_lessD"; |
390 |
||
5069 | 391 |
Goal "(Suc m <= n) = (m < n)"; |
4089 | 392 |
by (blast_tac (claset() addIs [Suc_leI, Suc_le_lessD]) 1); |
2608 | 393 |
qed "Suc_le_eq"; |
394 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
395 |
Goalw [le_def] "m <= n ==> m <= Suc n"; |
4089 | 396 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
2608 | 397 |
qed "le_SucI"; |
398 |
Addsimps[le_SucI]; |
|
399 |
||
400 |
bind_thm ("le_Suc", not_Suc_n_less_n RS leI); |
|
401 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
402 |
Goalw [le_def] "m < n ==> m <= (n::nat)"; |
4089 | 403 |
by (blast_tac (claset() addEs [less_asym]) 1); |
2608 | 404 |
qed "less_imp_le"; |
405 |
||
3343 | 406 |
(** Equivalence of m<=n and m<n | m=n **) |
407 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
408 |
Goalw [le_def] "m <= n ==> m < n | m=(n::nat)"; |
2608 | 409 |
by (cut_facts_tac [less_linear] 1); |
4089 | 410 |
by (blast_tac (claset() addEs [less_irrefl,less_asym]) 1); |
2608 | 411 |
qed "le_imp_less_or_eq"; |
412 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
413 |
Goalw [le_def] "m<n | m=n ==> m <=(n::nat)"; |
2608 | 414 |
by (cut_facts_tac [less_linear] 1); |
4089 | 415 |
by (blast_tac (claset() addSEs [less_irrefl] addEs [less_asym]) 1); |
2608 | 416 |
qed "less_or_eq_imp_le"; |
417 |
||
5069 | 418 |
Goal "(m <= (n::nat)) = (m < n | m=n)"; |
2608 | 419 |
by (REPEAT(ares_tac [iffI,less_or_eq_imp_le,le_imp_less_or_eq] 1)); |
420 |
qed "le_eq_less_or_eq"; |
|
421 |
||
4635 | 422 |
(*Useful with Blast_tac. m=n ==> m<=n *) |
423 |
bind_thm ("eq_imp_le", disjI2 RS less_or_eq_imp_le); |
|
424 |
||
5069 | 425 |
Goal "n <= (n::nat)"; |
4089 | 426 |
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); |
2608 | 427 |
qed "le_refl"; |
428 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
429 |
Goal "[| i <= j; j < k |] ==> i < (k::nat)"; |
4468 | 430 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
431 |
addIs [less_trans]) 1); |
|
2608 | 432 |
qed "le_less_trans"; |
433 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
434 |
Goal "[| i < j; j <= k |] ==> i < (k::nat)"; |
4468 | 435 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
436 |
addIs [less_trans]) 1); |
|
2608 | 437 |
qed "less_le_trans"; |
438 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
439 |
Goal "[| i <= j; j <= k |] ==> i <= (k::nat)"; |
4468 | 440 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
441 |
addIs [less_or_eq_imp_le, less_trans]) 1); |
|
2608 | 442 |
qed "le_trans"; |
443 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
444 |
Goal "[| m <= n; n <= m |] ==> m = (n::nat)"; |
4468 | 445 |
(*order_less_irrefl could make this proof fail*) |
446 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
|
447 |
addSEs [less_irrefl] addEs [less_asym]) 1); |
|
2608 | 448 |
qed "le_anti_sym"; |
449 |
||
5069 | 450 |
Goal "(Suc(n) <= Suc(m)) = (n <= m)"; |
4089 | 451 |
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); |
2608 | 452 |
qed "Suc_le_mono"; |
453 |
||
454 |
AddIffs [Suc_le_mono]; |
|
455 |
||
456 |
(* Axiom 'order_le_less' of class 'order': *) |
|
5069 | 457 |
Goal "(m::nat) < n = (m <= n & m ~= n)"; |
4737 | 458 |
by (simp_tac (simpset() addsimps [le_def, nat_neq_iff]) 1); |
459 |
by (blast_tac (claset() addSEs [less_asym]) 1); |
|
2608 | 460 |
qed "nat_less_le"; |
461 |
||
4640 | 462 |
(* Axiom 'linorder_linear' of class 'linorder': *) |
5069 | 463 |
Goal "(m::nat) <= n | n <= m"; |
4640 | 464 |
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); |
465 |
by (cut_facts_tac [less_linear] 1); |
|
5132 | 466 |
by (Blast_tac 1); |
4640 | 467 |
qed "nat_le_linear"; |
468 |
||
469 |
||
470 |
(** max |
|
4599 | 471 |
|
5069 | 472 |
Goalw [max_def] "!!z::nat. (z <= max x y) = (z <= x | z <= y)"; |
4686 | 473 |
by (simp_tac (simpset() addsimps [not_le_iff_less]) 1); |
4599 | 474 |
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1); |
475 |
qed "le_max_iff_disj"; |
|
476 |
||
5069 | 477 |
Goalw [max_def] "!!z::nat. (max x y <= z) = (x <= z & y <= z)"; |
4686 | 478 |
by (simp_tac (simpset() addsimps [not_le_iff_less]) 1); |
4599 | 479 |
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1); |
480 |
qed "max_le_iff_conj"; |
|
481 |
||
482 |
||
483 |
(** min **) |
|
484 |
||
5069 | 485 |
Goalw [min_def] "!!z::nat. (z <= min x y) = (z <= x & z <= y)"; |
4686 | 486 |
by (simp_tac (simpset() addsimps [not_le_iff_less]) 1); |
4599 | 487 |
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1); |
488 |
qed "le_min_iff_conj"; |
|
489 |
||
5069 | 490 |
Goalw [min_def] "!!z::nat. (min x y <= z) = (x <= z | y <= z)"; |
4686 | 491 |
by (simp_tac (simpset() addsimps [not_le_iff_less] addsplits) 1); |
4599 | 492 |
by (blast_tac (claset() addIs [less_imp_le, le_trans]) 1); |
493 |
qed "min_le_iff_disj"; |
|
4640 | 494 |
**) |
4599 | 495 |
|
2608 | 496 |
(** LEAST -- the least number operator **) |
497 |
||
5069 | 498 |
Goal "(! m::nat. P m --> n <= m) = (! m. m < n --> ~ P m)"; |
4089 | 499 |
by (blast_tac (claset() addIs [leI] addEs [leE]) 1); |
3143
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents:
3085
diff
changeset
|
500 |
val lemma = result(); |
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents:
3085
diff
changeset
|
501 |
|
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents:
3085
diff
changeset
|
502 |
(* This is an old def of Least for nat, which is derived for compatibility *) |
5069 | 503 |
Goalw [Least_def] |
3143
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents:
3085
diff
changeset
|
504 |
"(LEAST n::nat. P n) == (@n. P(n) & (ALL m. m < n --> ~P(m)))"; |
4089 | 505 |
by (simp_tac (simpset() addsimps [lemma]) 1); |
3143
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents:
3085
diff
changeset
|
506 |
qed "Least_nat_def"; |
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
nipkow
parents:
3085
diff
changeset
|
507 |
|
5316 | 508 |
val [prem1,prem2] = Goalw [Least_nat_def] |
3842 | 509 |
"[| P(k::nat); !!x. x<k ==> ~P(x) |] ==> (LEAST x. P(x)) = k"; |
2608 | 510 |
by (rtac select_equality 1); |
4089 | 511 |
by (blast_tac (claset() addSIs [prem1,prem2]) 1); |
2608 | 512 |
by (cut_facts_tac [less_linear] 1); |
4089 | 513 |
by (blast_tac (claset() addSIs [prem1] addSDs [prem2]) 1); |
2608 | 514 |
qed "Least_equality"; |
515 |
||
5316 | 516 |
Goal "P(k::nat) ==> P(LEAST x. P(x))"; |
517 |
by (etac rev_mp 1); |
|
2608 | 518 |
by (res_inst_tac [("n","k")] less_induct 1); |
519 |
by (rtac impI 1); |
|
520 |
by (rtac classical 1); |
|
521 |
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1); |
|
522 |
by (assume_tac 1); |
|
523 |
by (assume_tac 2); |
|
2891 | 524 |
by (Blast_tac 1); |
2608 | 525 |
qed "LeastI"; |
526 |
||
527 |
(*Proof is almost identical to the one above!*) |
|
5316 | 528 |
Goal "P(k::nat) ==> (LEAST x. P(x)) <= k"; |
529 |
by (etac rev_mp 1); |
|
2608 | 530 |
by (res_inst_tac [("n","k")] less_induct 1); |
531 |
by (rtac impI 1); |
|
532 |
by (rtac classical 1); |
|
533 |
by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1); |
|
534 |
by (assume_tac 1); |
|
535 |
by (rtac le_refl 2); |
|
4089 | 536 |
by (blast_tac (claset() addIs [less_imp_le,le_trans]) 1); |
2608 | 537 |
qed "Least_le"; |
538 |
||
5316 | 539 |
Goal "k < (LEAST x. P(x)) ==> ~P(k::nat)"; |
2608 | 540 |
by (rtac notI 1); |
5316 | 541 |
by (etac (rewrite_rule [le_def] Least_le RS notE) 1 THEN assume_tac 1); |
2608 | 542 |
qed "not_less_Least"; |
543 |
||
544 |
(*** Instantiation of transitivity prover ***) |
|
545 |
||
546 |
structure Less_Arith = |
|
547 |
struct |
|
548 |
val nat_leI = leI; |
|
549 |
val nat_leD = leD; |
|
550 |
val lessI = lessI; |
|
551 |
val zero_less_Suc = zero_less_Suc; |
|
552 |
val less_reflE = less_irrefl; |
|
553 |
val less_zeroE = less_zeroE; |
|
554 |
val less_incr = Suc_mono; |
|
555 |
val less_decr = Suc_less_SucD; |
|
556 |
val less_incr_rhs = Suc_mono RS Suc_lessD; |
|
557 |
val less_decr_lhs = Suc_lessD; |
|
558 |
val less_trans_Suc = less_trans_Suc; |
|
3343 | 559 |
val leI = Suc_leI RS (Suc_le_mono RS iffD1); |
2608 | 560 |
val not_lessI = leI RS leD |
561 |
val not_leI = prove_goal thy "!!m::nat. n < m ==> ~ m <= n" |
|
562 |
(fn _ => [etac swap2 1, etac leD 1]); |
|
563 |
val eqI = prove_goal thy "!!m. [| m < Suc n; n < Suc m |] ==> m=n" |
|
564 |
(fn _ => [etac less_SucE 1, |
|
4089 | 565 |
blast_tac (claset() addSDs [Suc_less_SucD] addSEs [less_irrefl] |
2891 | 566 |
addDs [less_trans_Suc]) 1, |
2935 | 567 |
assume_tac 1]); |
2608 | 568 |
val leD = le_eq_less_Suc RS iffD1; |
569 |
val not_lessD = nat_leI RS leD; |
|
570 |
val not_leD = not_leE |
|
571 |
val eqD1 = prove_goal thy "!!n. m = n ==> m < Suc n" |
|
572 |
(fn _ => [etac subst 1, rtac lessI 1]); |
|
573 |
val eqD2 = sym RS eqD1; |
|
574 |
||
575 |
fun is_zero(t) = t = Const("0",Type("nat",[])); |
|
576 |
||
577 |
fun nnb T = T = Type("fun",[Type("nat",[]), |
|
578 |
Type("fun",[Type("nat",[]), |
|
579 |
Type("bool",[])])]) |
|
580 |
||
581 |
fun decomp_Suc(Const("Suc",_)$t) = let val (a,i) = decomp_Suc t in (a,i+1) end |
|
582 |
| decomp_Suc t = (t,0); |
|
583 |
||
584 |
fun decomp2(rel,T,lhs,rhs) = |
|
585 |
if not(nnb T) then None else |
|
586 |
let val (x,i) = decomp_Suc lhs |
|
587 |
val (y,j) = decomp_Suc rhs |
|
588 |
in case rel of |
|
589 |
"op <" => Some(x,i,"<",y,j) |
|
590 |
| "op <=" => Some(x,i,"<=",y,j) |
|
591 |
| "op =" => Some(x,i,"=",y,j) |
|
592 |
| _ => None |
|
593 |
end; |
|
594 |
||
595 |
fun negate(Some(x,i,rel,y,j)) = Some(x,i,"~"^rel,y,j) |
|
596 |
| negate None = None; |
|
597 |
||
598 |
fun decomp(_$(Const(rel,T)$lhs$rhs)) = decomp2(rel,T,lhs,rhs) |
|
2718 | 599 |
| decomp(_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) = |
2608 | 600 |
negate(decomp2(rel,T,lhs,rhs)) |
601 |
| decomp _ = None |
|
602 |
||
603 |
end; |
|
604 |
||
605 |
structure Trans_Tac = Trans_Tac_Fun(Less_Arith); |
|
606 |
||
607 |
open Trans_Tac; |
|
608 |
||
609 |
(*** eliminates ~= in premises, which trans_tac cannot deal with ***) |
|
4737 | 610 |
bind_thm("nat_neqE", nat_neq_iff RS iffD1 RS disjE); |