author | wenzelm |
Wed, 05 Dec 2001 03:13:57 +0100 | |
changeset 12378 | 86c58273f8c0 |
parent 11868 | 56db9f3a6b3e |
child 12841 | c8ec6803d1cd |
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 |
|
5 |
*) |
|
6 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
7 |
Addsimps [One_nat_def]; |
11464 | 8 |
|
11326
680ebd093cfe
Representing set for type nat is now defined via "inductive".
berghofe
parents:
11135
diff
changeset
|
9 |
val rew = rewrite_rule [symmetric Nat_def]; |
2608 | 10 |
|
11 |
(*** Induction ***) |
|
12 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
13 |
val prems = Goalw [Zero_nat_def,Suc_def] |
2608 | 14 |
"[| P(0); \ |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
3023
diff
changeset
|
15 |
\ !!n. P(n) ==> P(Suc(n)) |] ==> P(n)"; |
2608 | 16 |
by (rtac (Rep_Nat_inverse RS subst) 1); (*types force good instantiation*) |
11326
680ebd093cfe
Representing set for type nat is now defined via "inductive".
berghofe
parents:
11135
diff
changeset
|
17 |
by (rtac (Rep_Nat RS rew Nat'.induct) 1); |
2608 | 18 |
by (REPEAT (ares_tac prems 1 |
19 |
ORELSE eresolve_tac [Abs_Nat_inverse RS subst] 1)); |
|
20 |
qed "nat_induct"; |
|
21 |
||
22 |
(*Perform induction on n. *) |
|
5187
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents:
5148
diff
changeset
|
23 |
fun nat_ind_tac a i = |
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents:
5148
diff
changeset
|
24 |
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
|
25 |
|
2608 | 26 |
(*A special form of induction for reasoning about m<n and m-n*) |
5316 | 27 |
val prems = Goal |
2608 | 28 |
"[| !!x. P x 0; \ |
29 |
\ !!y. P 0 (Suc y); \ |
|
30 |
\ !!x y. [| P x y |] ==> P (Suc x) (Suc y) \ |
|
31 |
\ |] ==> P m n"; |
|
32 |
by (res_inst_tac [("x","m")] spec 1); |
|
33 |
by (nat_ind_tac "n" 1); |
|
34 |
by (rtac allI 2); |
|
35 |
by (nat_ind_tac "x" 2); |
|
36 |
by (REPEAT (ares_tac (prems@[allI]) 1 ORELSE etac spec 1)); |
|
37 |
qed "diff_induct"; |
|
38 |
||
39 |
(*** Isomorphisms: Abs_Nat and Rep_Nat ***) |
|
40 |
||
41 |
(*We can't take these properties as axioms, or take Abs_Nat==Inv(Rep_Nat), |
|
42 |
since we assume the isomorphism equations will one day be given by Isabelle*) |
|
43 |
||
5069 | 44 |
Goal "inj(Rep_Nat)"; |
2608 | 45 |
by (rtac inj_inverseI 1); |
46 |
by (rtac Rep_Nat_inverse 1); |
|
47 |
qed "inj_Rep_Nat"; |
|
48 |
||
5069 | 49 |
Goal "inj_on Abs_Nat Nat"; |
4830 | 50 |
by (rtac inj_on_inverseI 1); |
2608 | 51 |
by (etac Abs_Nat_inverse 1); |
4830 | 52 |
qed "inj_on_Abs_Nat"; |
2608 | 53 |
|
54 |
(*** Distinctness of constructors ***) |
|
55 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
56 |
Goalw [Zero_nat_def,Suc_def] "Suc(m) ~= 0"; |
4830 | 57 |
by (rtac (inj_on_Abs_Nat RS inj_on_contraD) 1); |
2608 | 58 |
by (rtac Suc_Rep_not_Zero_Rep 1); |
11326
680ebd093cfe
Representing set for type nat is now defined via "inductive".
berghofe
parents:
11135
diff
changeset
|
59 |
by (REPEAT (resolve_tac [Rep_Nat, rew Nat'.Suc_RepI, rew Nat'.Zero_RepI] 1)); |
2608 | 60 |
qed "Suc_not_Zero"; |
61 |
||
62 |
bind_thm ("Zero_not_Suc", Suc_not_Zero RS not_sym); |
|
63 |
||
64 |
AddIffs [Suc_not_Zero,Zero_not_Suc]; |
|
65 |
||
66 |
bind_thm ("Suc_neq_Zero", (Suc_not_Zero RS notE)); |
|
9108 | 67 |
bind_thm ("Zero_neq_Suc", sym RS Suc_neq_Zero); |
2608 | 68 |
|
69 |
(** Injectiveness of Suc **) |
|
70 |
||
5069 | 71 |
Goalw [Suc_def] "inj(Suc)"; |
2608 | 72 |
by (rtac injI 1); |
4830 | 73 |
by (dtac (inj_on_Abs_Nat RS inj_onD) 1); |
11326
680ebd093cfe
Representing set for type nat is now defined via "inductive".
berghofe
parents:
11135
diff
changeset
|
74 |
by (REPEAT (resolve_tac [Rep_Nat, rew Nat'.Suc_RepI] 1)); |
2608 | 75 |
by (dtac (inj_Suc_Rep RS injD) 1); |
76 |
by (etac (inj_Rep_Nat RS injD) 1); |
|
77 |
qed "inj_Suc"; |
|
78 |
||
9108 | 79 |
bind_thm ("Suc_inject", inj_Suc RS injD); |
2608 | 80 |
|
5069 | 81 |
Goal "(Suc(m)=Suc(n)) = (m=n)"; |
2608 | 82 |
by (EVERY1 [rtac iffI, etac Suc_inject, etac arg_cong]); |
83 |
qed "Suc_Suc_eq"; |
|
84 |
||
85 |
AddIffs [Suc_Suc_eq]; |
|
86 |
||
5069 | 87 |
Goal "n ~= Suc(n)"; |
2608 | 88 |
by (nat_ind_tac "n" 1); |
89 |
by (ALLGOALS Asm_simp_tac); |
|
90 |
qed "n_not_Suc_n"; |
|
91 |
||
92 |
bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym); |
|
93 |
||
11461 | 94 |
Goal "(ALL x. x = (0::nat)) = False"; |
11338 | 95 |
by Auto_tac; |
96 |
qed "nat_not_singleton"; |
|
97 |
||
5187
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
berghofe
parents:
5148
diff
changeset
|
98 |
(*** Basic properties of "less than" ***) |
2608 | 99 |
|
11135 | 100 |
Goalw [wf_def, pred_nat_def] "wf pred_nat"; |
3718 | 101 |
by (Clarify_tac 1); |
2608 | 102 |
by (nat_ind_tac "x" 1); |
3236 | 103 |
by (ALLGOALS Blast_tac); |
2608 | 104 |
qed "wf_pred_nat"; |
105 |
||
11135 | 106 |
Goalw [less_def] "wf {(x,y::nat). x<y}"; |
107 |
by (rtac (wf_pred_nat RS wf_trancl RS wf_subset) 1); |
|
108 |
by (Blast_tac 1); |
|
109 |
qed "wf_less"; |
|
110 |
||
11655 | 111 |
Goalw [less_def] "((m,n) : pred_nat^+) = (m<n)"; |
3378 | 112 |
by (rtac refl 1); |
113 |
qed "less_eq"; |
|
114 |
||
2608 | 115 |
(** Introduction properties **) |
116 |
||
5316 | 117 |
Goalw [less_def] "[| i<j; j<k |] ==> i<(k::nat)"; |
2608 | 118 |
by (rtac (trans_trancl RS transD) 1); |
5316 | 119 |
by (assume_tac 1); |
120 |
by (assume_tac 1); |
|
2608 | 121 |
qed "less_trans"; |
122 |
||
5069 | 123 |
Goalw [less_def, pred_nat_def] "n < Suc(n)"; |
4089 | 124 |
by (simp_tac (simpset() addsimps [r_into_trancl]) 1); |
2608 | 125 |
qed "lessI"; |
126 |
AddIffs [lessI]; |
|
127 |
||
128 |
(* i<j ==> i<Suc(j) *) |
|
129 |
bind_thm("less_SucI", lessI RSN (2, less_trans)); |
|
130 |
||
5069 | 131 |
Goal "0 < Suc(n)"; |
2608 | 132 |
by (nat_ind_tac "n" 1); |
133 |
by (rtac lessI 1); |
|
134 |
by (etac less_trans 1); |
|
135 |
by (rtac lessI 1); |
|
136 |
qed "zero_less_Suc"; |
|
137 |
AddIffs [zero_less_Suc]; |
|
138 |
||
139 |
(** Elimination properties **) |
|
140 |
||
5316 | 141 |
Goalw [less_def] "n<m ==> ~ m<(n::nat)"; |
142 |
by (blast_tac (claset() addIs [wf_pred_nat, wf_trancl RS wf_asym])1); |
|
2608 | 143 |
qed "less_not_sym"; |
144 |
||
5474
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents:
5354
diff
changeset
|
145 |
(* [| n<m; ~P ==> m<n |] ==> P *) |
10231 | 146 |
bind_thm ("less_asym", less_not_sym RS contrapos_np); |
2608 | 147 |
|
5069 | 148 |
Goalw [less_def] "~ n<(n::nat)"; |
9160 | 149 |
by (rtac (wf_pred_nat RS wf_trancl RS wf_not_refl) 1); |
2608 | 150 |
qed "less_not_refl"; |
151 |
||
152 |
(* n<n ==> R *) |
|
9160 | 153 |
bind_thm ("less_irrefl", less_not_refl RS notE); |
5474
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents:
5354
diff
changeset
|
154 |
AddSEs [less_irrefl]; |
2608 | 155 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
156 |
Goal "n<m ==> m ~= (n::nat)"; |
5474
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents:
5354
diff
changeset
|
157 |
by (Blast_tac 1); |
2608 | 158 |
qed "less_not_refl2"; |
159 |
||
5354
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
160 |
(* s < t ==> s ~= t *) |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
161 |
bind_thm ("less_not_refl3", less_not_refl2 RS not_sym); |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
162 |
|
2608 | 163 |
|
5316 | 164 |
val major::prems = Goalw [less_def, pred_nat_def] |
2608 | 165 |
"[| i<k; k=Suc(i) ==> P; !!j. [| i<j; k=Suc(j) |] ==> P \ |
166 |
\ |] ==> P"; |
|
167 |
by (rtac (major RS tranclE) 1); |
|
3236 | 168 |
by (ALLGOALS Full_simp_tac); |
2608 | 169 |
by (REPEAT_FIRST (bound_hyp_subst_tac ORELSE' |
3236 | 170 |
eresolve_tac (prems@[asm_rl, Pair_inject]))); |
2608 | 171 |
qed "lessE"; |
172 |
||
8942
6aad5381ba83
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8741
diff
changeset
|
173 |
Goal "~ n < (0::nat)"; |
6aad5381ba83
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8741
diff
changeset
|
174 |
by (blast_tac (claset() addEs [lessE]) 1); |
2608 | 175 |
qed "not_less0"; |
176 |
AddIffs [not_less0]; |
|
177 |
||
178 |
(* n<0 ==> R *) |
|
179 |
bind_thm ("less_zeroE", not_less0 RS notE); |
|
180 |
||
5316 | 181 |
val [major,less,eq] = Goal |
2608 | 182 |
"[| m < Suc(n); m<n ==> P; m=n ==> P |] ==> P"; |
183 |
by (rtac (major RS lessE) 1); |
|
184 |
by (rtac eq 1); |
|
2891 | 185 |
by (Blast_tac 1); |
2608 | 186 |
by (rtac less 1); |
2891 | 187 |
by (Blast_tac 1); |
2608 | 188 |
qed "less_SucE"; |
189 |
||
5069 | 190 |
Goal "(m < Suc(n)) = (m < n | m = n)"; |
4089 | 191 |
by (blast_tac (claset() addSEs [less_SucE] addIs [less_trans]) 1); |
2608 | 192 |
qed "less_Suc_eq"; |
193 |
||
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
194 |
Goal "(n < (1::nat)) = (n = 0)"; |
4089 | 195 |
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
|
196 |
qed "less_one"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
197 |
AddIffs [less_one]; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
198 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
199 |
Goal "m<n ==> Suc(m) < Suc(n)"; |
2608 | 200 |
by (etac rev_mp 1); |
201 |
by (nat_ind_tac "n" 1); |
|
5474
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
paulson
parents:
5354
diff
changeset
|
202 |
by (ALLGOALS (fast_tac (claset() addEs [less_trans, lessE]))); |
2608 | 203 |
qed "Suc_mono"; |
204 |
||
205 |
(*"Less than" is a linear ordering*) |
|
5069 | 206 |
Goal "m<n | m=n | n<(m::nat)"; |
2608 | 207 |
by (nat_ind_tac "m" 1); |
208 |
by (nat_ind_tac "n" 1); |
|
209 |
by (rtac (refl RS disjI1 RS disjI2) 1); |
|
210 |
by (rtac (zero_less_Suc RS disjI1) 1); |
|
4089 | 211 |
by (blast_tac (claset() addIs [Suc_mono, less_SucI] addEs [lessE]) 1); |
2608 | 212 |
qed "less_linear"; |
213 |
||
5069 | 214 |
Goal "!!m::nat. (m ~= n) = (m<n | n<m)"; |
4737 | 215 |
by (cut_facts_tac [less_linear] 1); |
5500 | 216 |
by (Blast_tac 1); |
4737 | 217 |
qed "nat_neq_iff"; |
218 |
||
7030 | 219 |
val [major,eqCase,lessCase] = Goal |
220 |
"[| (m::nat)<n ==> P n m; m=n ==> P n m; n<m ==> P n m |] ==> P n m"; |
|
221 |
by (rtac (less_linear RS disjE) 1); |
|
222 |
by (etac disjE 2); |
|
223 |
by (etac lessCase 1); |
|
224 |
by (etac (sym RS eqCase) 1); |
|
225 |
by (etac major 1); |
|
226 |
qed "nat_less_cases"; |
|
2608 | 227 |
|
4745 | 228 |
|
229 |
(** Inductive (?) properties **) |
|
230 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
231 |
Goal "[| m<n; Suc m ~= n |] ==> Suc(m) < n"; |
4745 | 232 |
by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1); |
233 |
by (blast_tac (claset() addSEs [less_irrefl, less_SucE] addEs [less_asym]) 1); |
|
234 |
qed "Suc_lessI"; |
|
235 |
||
5316 | 236 |
Goal "Suc(m) < n ==> m<n"; |
237 |
by (etac rev_mp 1); |
|
4745 | 238 |
by (nat_ind_tac "n" 1); |
239 |
by (ALLGOALS (fast_tac (claset() addSIs [lessI RS less_SucI] |
|
240 |
addEs [less_trans, lessE]))); |
|
241 |
qed "Suc_lessD"; |
|
242 |
||
5316 | 243 |
val [major,minor] = Goal |
4745 | 244 |
"[| Suc(i)<k; !!j. [| i<j; k=Suc(j) |] ==> P \ |
245 |
\ |] ==> P"; |
|
246 |
by (rtac (major RS lessE) 1); |
|
247 |
by (etac (lessI RS minor) 1); |
|
248 |
by (etac (Suc_lessD RS minor) 1); |
|
249 |
by (assume_tac 1); |
|
250 |
qed "Suc_lessE"; |
|
251 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
252 |
Goal "Suc(m) < Suc(n) ==> m<n"; |
4745 | 253 |
by (blast_tac (claset() addEs [lessE, make_elim Suc_lessD]) 1); |
254 |
qed "Suc_less_SucD"; |
|
255 |
||
256 |
||
5069 | 257 |
Goal "(Suc(m) < Suc(n)) = (m<n)"; |
4745 | 258 |
by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]); |
259 |
qed "Suc_less_eq"; |
|
8555
17325ee838ab
Suc_less_eq now with AddIffs. How could this have been overlooked?
paulson
parents:
7064
diff
changeset
|
260 |
AddIffs [Suc_less_eq]; |
4745 | 261 |
|
6109 | 262 |
(*Goal "~(Suc(n) < n)"; |
4745 | 263 |
by (blast_tac (claset() addEs [Suc_lessD RS less_irrefl]) 1); |
264 |
qed "not_Suc_n_less_n"; |
|
6109 | 265 |
Addsimps [not_Suc_n_less_n];*) |
4745 | 266 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
267 |
Goal "i<j ==> j<k --> Suc i < k"; |
4745 | 268 |
by (nat_ind_tac "k" 1); |
269 |
by (ALLGOALS (asm_simp_tac (simpset()))); |
|
270 |
by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
|
271 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
|
272 |
qed_spec_mp "less_trans_Suc"; |
|
273 |
||
2608 | 274 |
(*Can be used with less_Suc_eq to get n=m | n<m *) |
5069 | 275 |
Goal "(~ m < n) = (n < Suc(m))"; |
2608 | 276 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
277 |
by (ALLGOALS Asm_simp_tac); |
|
278 |
qed "not_less_eq"; |
|
279 |
||
280 |
(*Complete induction, aka course-of-values induction*) |
|
5316 | 281 |
val prems = Goalw [less_def] |
9160 | 282 |
"[| !!n. [| ALL m::nat. m<n --> P(m) |] ==> P(n) |] ==> P(n)"; |
2608 | 283 |
by (wf_ind_tac "n" [wf_pred_nat RS wf_trancl] 1); |
284 |
by (eresolve_tac prems 1); |
|
9870 | 285 |
qed "nat_less_induct"; |
2608 | 286 |
|
287 |
(*** Properties of <= ***) |
|
288 |
||
5500 | 289 |
(*Was le_eq_less_Suc, but this orientation is more useful*) |
290 |
Goalw [le_def] "(m < Suc n) = (m <= n)"; |
|
291 |
by (rtac (not_less_eq RS sym) 1); |
|
292 |
qed "less_Suc_eq_le"; |
|
2608 | 293 |
|
3343 | 294 |
(* m<=n ==> m < Suc n *) |
5500 | 295 |
bind_thm ("le_imp_less_Suc", less_Suc_eq_le RS iffD2); |
3343 | 296 |
|
8942
6aad5381ba83
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8741
diff
changeset
|
297 |
Goalw [le_def] "(0::nat) <= n"; |
2608 | 298 |
by (rtac not_less0 1); |
299 |
qed "le0"; |
|
6075 | 300 |
AddIffs [le0]; |
2608 | 301 |
|
5069 | 302 |
Goalw [le_def] "~ Suc n <= n"; |
2608 | 303 |
by (Simp_tac 1); |
304 |
qed "Suc_n_not_le_n"; |
|
305 |
||
8942
6aad5381ba83
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8741
diff
changeset
|
306 |
Goalw [le_def] "!!i::nat. (i <= 0) = (i = 0)"; |
2608 | 307 |
by (nat_ind_tac "i" 1); |
308 |
by (ALLGOALS Asm_simp_tac); |
|
309 |
qed "le_0_eq"; |
|
4614 | 310 |
AddIffs [le_0_eq]; |
2608 | 311 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
312 |
Goal "(m <= Suc(n)) = (m<=n | m = Suc n)"; |
5500 | 313 |
by (simp_tac (simpset() delsimps [less_Suc_eq_le] |
314 |
addsimps [less_Suc_eq_le RS sym, less_Suc_eq]) 1); |
|
3355 | 315 |
qed "le_Suc_eq"; |
316 |
||
4614 | 317 |
(* [| m <= Suc n; m <= n ==> R; m = Suc n ==> R |] ==> R *) |
318 |
bind_thm ("le_SucE", le_Suc_eq RS iffD1 RS disjE); |
|
319 |
||
5316 | 320 |
Goalw [le_def] "~n<m ==> m<=(n::nat)"; |
321 |
by (assume_tac 1); |
|
2608 | 322 |
qed "leI"; |
323 |
||
5316 | 324 |
Goalw [le_def] "m<=n ==> ~ n < (m::nat)"; |
325 |
by (assume_tac 1); |
|
2608 | 326 |
qed "leD"; |
327 |
||
9108 | 328 |
bind_thm ("leE", make_elim leD); |
2608 | 329 |
|
5069 | 330 |
Goal "(~n<m) = (m<=(n::nat))"; |
4089 | 331 |
by (blast_tac (claset() addIs [leI] addEs [leE]) 1); |
2608 | 332 |
qed "not_less_iff_le"; |
333 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
334 |
Goalw [le_def] "~ m <= n ==> n<(m::nat)"; |
2891 | 335 |
by (Blast_tac 1); |
2608 | 336 |
qed "not_leE"; |
337 |
||
5069 | 338 |
Goalw [le_def] "(~n<=m) = (m<(n::nat))"; |
4599 | 339 |
by (Simp_tac 1); |
340 |
qed "not_le_iff_less"; |
|
341 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
342 |
Goalw [le_def] "m < n ==> Suc(m) <= n"; |
4089 | 343 |
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
344 |
by (blast_tac (claset() addSEs [less_irrefl,less_asym]) 1); |
|
3343 | 345 |
qed "Suc_leI"; (*formerly called lessD*) |
2608 | 346 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
347 |
Goalw [le_def] "Suc(m) <= n ==> m <= n"; |
4089 | 348 |
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
2608 | 349 |
qed "Suc_leD"; |
350 |
||
351 |
(* stronger version of Suc_leD *) |
|
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset
|
352 |
Goalw [le_def] "Suc m <= n ==> m < n"; |
4089 | 353 |
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1); |
2608 | 354 |
by (cut_facts_tac [less_linear] 1); |
2891 | 355 |
by (Blast_tac 1); |
2608 | 356 |
qed "Suc_le_lessD"; |
357 |
||
5069 | 358 |
Goal "(Suc m <= n) = (m < n)"; |
4089 | 359 |
by (blast_tac (claset() addIs [Suc_leI, Suc_le_lessD]) 1); |
2608 | 360 |
qed "Suc_le_eq"; |
361 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
362 |
Goalw [le_def] "m <= n ==> m <= Suc n"; |
4089 | 363 |
by (blast_tac (claset() addDs [Suc_lessD]) 1); |
2608 | 364 |
qed "le_SucI"; |
365 |
||
6109 | 366 |
(*bind_thm ("le_Suc", not_Suc_n_less_n RS leI);*) |
2608 | 367 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
368 |
Goalw [le_def] "m < n ==> m <= (n::nat)"; |
4089 | 369 |
by (blast_tac (claset() addEs [less_asym]) 1); |
2608 | 370 |
qed "less_imp_le"; |
371 |
||
5591 | 372 |
(*For instance, (Suc m < Suc n) = (Suc m <= n) = (m<n) *) |
9108 | 373 |
bind_thms ("le_simps", [less_imp_le, less_Suc_eq_le, Suc_le_eq]); |
5591 | 374 |
|
5354
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
375 |
|
3343 | 376 |
(** Equivalence of m<=n and m<n | m=n **) |
377 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
378 |
Goalw [le_def] "m <= n ==> m < n | m=(n::nat)"; |
2608 | 379 |
by (cut_facts_tac [less_linear] 1); |
4089 | 380 |
by (blast_tac (claset() addEs [less_irrefl,less_asym]) 1); |
2608 | 381 |
qed "le_imp_less_or_eq"; |
382 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
383 |
Goalw [le_def] "m<n | m=n ==> m <=(n::nat)"; |
2608 | 384 |
by (cut_facts_tac [less_linear] 1); |
4089 | 385 |
by (blast_tac (claset() addSEs [less_irrefl] addEs [less_asym]) 1); |
2608 | 386 |
qed "less_or_eq_imp_le"; |
387 |
||
5069 | 388 |
Goal "(m <= (n::nat)) = (m < n | m=n)"; |
2608 | 389 |
by (REPEAT(ares_tac [iffI,less_or_eq_imp_le,le_imp_less_or_eq] 1)); |
390 |
qed "le_eq_less_or_eq"; |
|
391 |
||
4635 | 392 |
(*Useful with Blast_tac. m=n ==> m<=n *) |
393 |
bind_thm ("eq_imp_le", disjI2 RS less_or_eq_imp_le); |
|
394 |
||
5069 | 395 |
Goal "n <= (n::nat)"; |
4089 | 396 |
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); |
2608 | 397 |
qed "le_refl"; |
398 |
||
5354
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
399 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
400 |
Goal "[| i <= j; j < k |] ==> i < (k::nat)"; |
4468 | 401 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
402 |
addIs [less_trans]) 1); |
|
2608 | 403 |
qed "le_less_trans"; |
404 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
405 |
Goal "[| i < j; j <= k |] ==> i < (k::nat)"; |
4468 | 406 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
407 |
addIs [less_trans]) 1); |
|
2608 | 408 |
qed "less_le_trans"; |
409 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
410 |
Goal "[| i <= j; j <= k |] ==> i <= (k::nat)"; |
4468 | 411 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
412 |
addIs [less_or_eq_imp_le, less_trans]) 1); |
|
2608 | 413 |
qed "le_trans"; |
414 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset
|
415 |
Goal "[| m <= n; n <= m |] ==> m = (n::nat)"; |
4468 | 416 |
(*order_less_irrefl could make this proof fail*) |
417 |
by (blast_tac (claset() addSDs [le_imp_less_or_eq] |
|
418 |
addSEs [less_irrefl] addEs [less_asym]) 1); |
|
2608 | 419 |
qed "le_anti_sym"; |
420 |
||
5069 | 421 |
Goal "(Suc(n) <= Suc(m)) = (n <= m)"; |
5500 | 422 |
by (simp_tac (simpset() addsimps le_simps) 1); |
2608 | 423 |
qed "Suc_le_mono"; |
424 |
||
425 |
AddIffs [Suc_le_mono]; |
|
426 |
||
5500 | 427 |
(* Axiom 'order_less_le' of class 'order': *) |
11655 | 428 |
Goal "((m::nat) < n) = (m <= n & m ~= n)"; |
4737 | 429 |
by (simp_tac (simpset() addsimps [le_def, nat_neq_iff]) 1); |
430 |
by (blast_tac (claset() addSEs [less_asym]) 1); |
|
2608 | 431 |
qed "nat_less_le"; |
432 |
||
5354
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
433 |
(* [| m <= n; m ~= n |] ==> m < n *) |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
434 |
bind_thm ("le_neq_implies_less", [nat_less_le, conjI] MRS iffD2); |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
435 |
|
4640 | 436 |
(* Axiom 'linorder_linear' of class 'linorder': *) |
5069 | 437 |
Goal "(m::nat) <= n | n <= m"; |
4640 | 438 |
by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); |
439 |
by (cut_facts_tac [less_linear] 1); |
|
5132 | 440 |
by (Blast_tac 1); |
4640 | 441 |
qed "nat_le_linear"; |
442 |
||
5354
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
443 |
Goal "~ n < m ==> (n < Suc m) = (n = m)"; |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
444 |
by (blast_tac (claset() addSEs [less_SucE]) 1); |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
445 |
qed "not_less_less_Suc_eq"; |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
446 |
|
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
447 |
|
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
448 |
(*Rewrite (n < Suc m) to (n=m) if ~ n<m or m<=n hold. |
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
paulson
parents:
5316
diff
changeset
|
449 |
Not suitable as default simprules because they often lead to looping*) |
9108 | 450 |
bind_thms ("not_less_simps", [not_less_less_Suc_eq, leD RS not_less_less_Suc_eq]); |
4640 | 451 |
|
10706 | 452 |
|
11868
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11701
diff
changeset
|
453 |
(** Re-orientation of the equations 0=x and 1=x. |
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11701
diff
changeset
|
454 |
No longer added as simprules (they loop) |
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11701
diff
changeset
|
455 |
but via reorient_simproc in Bin **) |
10706 | 456 |
|
10711
a9f6994fb906
generalized the re-orientation 0f 0=... to all types
paulson
parents:
10706
diff
changeset
|
457 |
(*Polymorphic, not just for "nat"*) |
11868
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11701
diff
changeset
|
458 |
Goal "(0 = x) = (x = 0)"; |
10706 | 459 |
by Auto_tac; |
460 |
qed "zero_reorient"; |
|
461 |
||
11868
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11701
diff
changeset
|
462 |
Goal "(1 = x) = (x = 1)"; |
10706 | 463 |
by Auto_tac; |
464 |
qed "one_reorient"; |