| author | wenzelm | 
| Sun, 27 Feb 2000 15:22:14 +0100 | |
| changeset 8302 | da404f79c1fc | 
| parent 7064 | b053e0ab9f60 | 
| child 8555 | 17325ee838ab | 
| 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 | ||
| 5069 | 7 | Goal "mono(%X. {Zero_Rep} Un (Suc_Rep``X))";
 | 
| 2608 | 8 | by (REPEAT (ares_tac [monoI, subset_refl, image_mono, Un_mono] 1)); | 
| 9 | qed "Nat_fun_mono"; | |
| 10 | ||
| 11 | val Nat_unfold = Nat_fun_mono RS (Nat_def RS def_lfp_Tarski); | |
| 12 | ||
| 13 | (* Zero is a natural number -- this also justifies the type definition*) | |
| 5069 | 14 | Goal "Zero_Rep: Nat"; | 
| 2608 | 15 | by (stac Nat_unfold 1); | 
| 16 | by (rtac (singletonI RS UnI1) 1); | |
| 17 | qed "Zero_RepI"; | |
| 18 | ||
| 5316 | 19 | Goal "i: Nat ==> Suc_Rep(i) : Nat"; | 
| 2608 | 20 | by (stac Nat_unfold 1); | 
| 21 | by (rtac (imageI RS UnI2) 1); | |
| 5316 | 22 | by (assume_tac 1); | 
| 2608 | 23 | qed "Suc_RepI"; | 
| 24 | ||
| 25 | (*** Induction ***) | |
| 26 | ||
| 5316 | 27 | val major::prems = Goal | 
| 2608 | 28 | "[| i: Nat; P(Zero_Rep); \ | 
| 29 | \ !!j. [| j: Nat; P(j) |] ==> P(Suc_Rep(j)) |] ==> P(i)"; | |
| 30 | by (rtac ([Nat_def, Nat_fun_mono, major] MRS def_induct) 1); | |
| 4089 | 31 | by (blast_tac (claset() addIs prems) 1); | 
| 2608 | 32 | qed "Nat_induct"; | 
| 33 | ||
| 5316 | 34 | val prems = Goalw [Zero_def,Suc_def] | 
| 2608 | 35 | "[| P(0); \ | 
| 3040 
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
 nipkow parents: 
3023diff
changeset | 36 | \ !!n. P(n) ==> P(Suc(n)) |] ==> P(n)"; | 
| 2608 | 37 | by (rtac (Rep_Nat_inverse RS subst) 1); (*types force good instantiation*) | 
| 38 | by (rtac (Rep_Nat RS Nat_induct) 1); | |
| 39 | by (REPEAT (ares_tac prems 1 | |
| 40 | ORELSE eresolve_tac [Abs_Nat_inverse RS subst] 1)); | |
| 41 | qed "nat_induct"; | |
| 42 | ||
| 43 | (*Perform induction on n. *) | |
| 5187 
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
 berghofe parents: 
5148diff
changeset | 44 | fun nat_ind_tac a i = | 
| 
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
 berghofe parents: 
5148diff
changeset | 45 |   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: 
3023diff
changeset | 46 | |
| 2608 | 47 | (*A special form of induction for reasoning about m<n and m-n*) | 
| 5316 | 48 | val prems = Goal | 
| 2608 | 49 | "[| !!x. P x 0; \ | 
| 50 | \ !!y. P 0 (Suc y); \ | |
| 51 | \ !!x y. [| P x y |] ==> P (Suc x) (Suc y) \ | |
| 52 | \ |] ==> P m n"; | |
| 53 | by (res_inst_tac [("x","m")] spec 1);
 | |
| 54 | by (nat_ind_tac "n" 1); | |
| 55 | by (rtac allI 2); | |
| 56 | by (nat_ind_tac "x" 2); | |
| 57 | by (REPEAT (ares_tac (prems@[allI]) 1 ORELSE etac spec 1)); | |
| 58 | qed "diff_induct"; | |
| 59 | ||
| 60 | (*** Isomorphisms: Abs_Nat and Rep_Nat ***) | |
| 61 | ||
| 62 | (*We can't take these properties as axioms, or take Abs_Nat==Inv(Rep_Nat), | |
| 63 | since we assume the isomorphism equations will one day be given by Isabelle*) | |
| 64 | ||
| 5069 | 65 | Goal "inj(Rep_Nat)"; | 
| 2608 | 66 | by (rtac inj_inverseI 1); | 
| 67 | by (rtac Rep_Nat_inverse 1); | |
| 68 | qed "inj_Rep_Nat"; | |
| 69 | ||
| 5069 | 70 | Goal "inj_on Abs_Nat Nat"; | 
| 4830 | 71 | by (rtac inj_on_inverseI 1); | 
| 2608 | 72 | by (etac Abs_Nat_inverse 1); | 
| 4830 | 73 | qed "inj_on_Abs_Nat"; | 
| 2608 | 74 | |
| 75 | (*** Distinctness of constructors ***) | |
| 76 | ||
| 5069 | 77 | Goalw [Zero_def,Suc_def] "Suc(m) ~= 0"; | 
| 4830 | 78 | by (rtac (inj_on_Abs_Nat RS inj_on_contraD) 1); | 
| 2608 | 79 | by (rtac Suc_Rep_not_Zero_Rep 1); | 
| 80 | by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI, Zero_RepI] 1)); | |
| 81 | qed "Suc_not_Zero"; | |
| 82 | ||
| 83 | bind_thm ("Zero_not_Suc", Suc_not_Zero RS not_sym);
 | |
| 84 | ||
| 85 | AddIffs [Suc_not_Zero,Zero_not_Suc]; | |
| 86 | ||
| 87 | bind_thm ("Suc_neq_Zero", (Suc_not_Zero RS notE));
 | |
| 88 | val Zero_neq_Suc = sym RS Suc_neq_Zero; | |
| 89 | ||
| 90 | (** Injectiveness of Suc **) | |
| 91 | ||
| 5069 | 92 | Goalw [Suc_def] "inj(Suc)"; | 
| 2608 | 93 | by (rtac injI 1); | 
| 4830 | 94 | by (dtac (inj_on_Abs_Nat RS inj_onD) 1); | 
| 2608 | 95 | by (REPEAT (resolve_tac [Rep_Nat, Suc_RepI] 1)); | 
| 96 | by (dtac (inj_Suc_Rep RS injD) 1); | |
| 97 | by (etac (inj_Rep_Nat RS injD) 1); | |
| 98 | qed "inj_Suc"; | |
| 99 | ||
| 100 | val Suc_inject = inj_Suc RS injD; | |
| 101 | ||
| 5069 | 102 | Goal "(Suc(m)=Suc(n)) = (m=n)"; | 
| 2608 | 103 | by (EVERY1 [rtac iffI, etac Suc_inject, etac arg_cong]); | 
| 104 | qed "Suc_Suc_eq"; | |
| 105 | ||
| 106 | AddIffs [Suc_Suc_eq]; | |
| 107 | ||
| 5069 | 108 | Goal "n ~= Suc(n)"; | 
| 2608 | 109 | by (nat_ind_tac "n" 1); | 
| 110 | by (ALLGOALS Asm_simp_tac); | |
| 111 | qed "n_not_Suc_n"; | |
| 112 | ||
| 113 | bind_thm ("Suc_n_not_n", n_not_Suc_n RS not_sym);
 | |
| 114 | ||
| 5187 
55f07169cf5f
Removed nat_case, nat_rec, and natE (now provided by datatype
 berghofe parents: 
5148diff
changeset | 115 | (*** Basic properties of "less than" ***) | 
| 2608 | 116 | |
| 5069 | 117 | Goalw [wf_def, pred_nat_def] "wf(pred_nat)"; | 
| 3718 | 118 | by (Clarify_tac 1); | 
| 2608 | 119 | by (nat_ind_tac "x" 1); | 
| 3236 | 120 | by (ALLGOALS Blast_tac); | 
| 2608 | 121 | qed "wf_pred_nat"; | 
| 122 | ||
| 3378 | 123 | (*Used in TFL/post.sml*) | 
| 5069 | 124 | Goalw [less_def] "(m,n) : pred_nat^+ = (m<n)"; | 
| 3378 | 125 | by (rtac refl 1); | 
| 126 | qed "less_eq"; | |
| 127 | ||
| 2608 | 128 | (** Introduction properties **) | 
| 129 | ||
| 5316 | 130 | Goalw [less_def] "[| i<j; j<k |] ==> i<(k::nat)"; | 
| 2608 | 131 | by (rtac (trans_trancl RS transD) 1); | 
| 5316 | 132 | by (assume_tac 1); | 
| 133 | by (assume_tac 1); | |
| 2608 | 134 | qed "less_trans"; | 
| 135 | ||
| 5069 | 136 | Goalw [less_def, pred_nat_def] "n < Suc(n)"; | 
| 4089 | 137 | by (simp_tac (simpset() addsimps [r_into_trancl]) 1); | 
| 2608 | 138 | qed "lessI"; | 
| 139 | AddIffs [lessI]; | |
| 140 | ||
| 141 | (* i<j ==> i<Suc(j) *) | |
| 142 | bind_thm("less_SucI", lessI RSN (2, less_trans));
 | |
| 143 | Addsimps [less_SucI]; | |
| 144 | ||
| 5069 | 145 | Goal "0 < Suc(n)"; | 
| 2608 | 146 | by (nat_ind_tac "n" 1); | 
| 147 | by (rtac lessI 1); | |
| 148 | by (etac less_trans 1); | |
| 149 | by (rtac lessI 1); | |
| 150 | qed "zero_less_Suc"; | |
| 151 | AddIffs [zero_less_Suc]; | |
| 152 | ||
| 153 | (** Elimination properties **) | |
| 154 | ||
| 5316 | 155 | Goalw [less_def] "n<m ==> ~ m<(n::nat)"; | 
| 156 | by (blast_tac (claset() addIs [wf_pred_nat, wf_trancl RS wf_asym])1); | |
| 2608 | 157 | qed "less_not_sym"; | 
| 158 | ||
| 5474 
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
 paulson parents: 
5354diff
changeset | 159 | (* [| n<m; ~P ==> m<n |] ==> P *) | 
| 
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
 paulson parents: 
5354diff
changeset | 160 | bind_thm ("less_asym", less_not_sym RS swap);
 | 
| 2608 | 161 | |
| 5069 | 162 | Goalw [less_def] "~ n<(n::nat)"; | 
| 2608 | 163 | by (rtac notI 1); | 
| 164 | by (etac (wf_pred_nat RS wf_trancl RS wf_irrefl) 1); | |
| 165 | qed "less_not_refl"; | |
| 166 | ||
| 167 | (* n<n ==> R *) | |
| 168 | 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: 
5354diff
changeset | 169 | AddSEs [less_irrefl]; | 
| 2608 | 170 | |
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 171 | Goal "n<m ==> m ~= (n::nat)"; | 
| 5474 
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
 paulson parents: 
5354diff
changeset | 172 | by (Blast_tac 1); | 
| 2608 | 173 | qed "less_not_refl2"; | 
| 174 | ||
| 5354 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 175 | (* s < t ==> s ~= t *) | 
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 176 | bind_thm ("less_not_refl3", less_not_refl2 RS not_sym);
 | 
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 177 | |
| 2608 | 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: 
3457diff
changeset | 215 | qed "less_one"; | 
| 
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
 nipkow parents: 
3457diff
changeset | 216 | AddIffs [less_one]; | 
| 
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
 nipkow parents: 
3457diff
changeset | 217 | |
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 218 | Goal "m<n ==> Suc(m) < Suc(n)"; | 
| 2608 | 219 | by (etac rev_mp 1); | 
| 220 | by (nat_ind_tac "n" 1); | |
| 5474 
a2109bb8ce2b
well-formed asym rules; also adds less_irrefl, le_refl since order_refl
 paulson parents: 
5354diff
changeset | 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); | 
| 5500 | 235 | by (Blast_tac 1); | 
| 4737 | 236 | qed "nat_neq_iff"; | 
| 237 | ||
| 7030 | 238 | val [major,eqCase,lessCase] = Goal | 
| 239 | "[| (m::nat)<n ==> P n m; m=n ==> P n m; n<m ==> P n m |] ==> P n m"; | |
| 240 | by (rtac (less_linear RS disjE) 1); | |
| 241 | by (etac disjE 2); | |
| 242 | by (etac lessCase 1); | |
| 243 | by (etac (sym RS eqCase) 1); | |
| 244 | by (etac major 1); | |
| 245 | qed "nat_less_cases"; | |
| 2608 | 246 | |
| 4745 | 247 | |
| 248 | (** Inductive (?) properties **) | |
| 249 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 250 | Goal "[| m<n; Suc m ~= n |] ==> Suc(m) < n"; | 
| 4745 | 251 | by (full_simp_tac (simpset() addsimps [nat_neq_iff]) 1); | 
| 252 | by (blast_tac (claset() addSEs [less_irrefl, less_SucE] addEs [less_asym]) 1); | |
| 253 | qed "Suc_lessI"; | |
| 254 | ||
| 5316 | 255 | Goal "Suc(m) < n ==> m<n"; | 
| 256 | by (etac rev_mp 1); | |
| 4745 | 257 | by (nat_ind_tac "n" 1); | 
| 258 | by (ALLGOALS (fast_tac (claset() addSIs [lessI RS less_SucI] | |
| 259 | addEs [less_trans, lessE]))); | |
| 260 | qed "Suc_lessD"; | |
| 261 | ||
| 5316 | 262 | val [major,minor] = Goal | 
| 4745 | 263 | "[| Suc(i)<k; !!j. [| i<j; k=Suc(j) |] ==> P \ | 
| 264 | \ |] ==> P"; | |
| 265 | by (rtac (major RS lessE) 1); | |
| 266 | by (etac (lessI RS minor) 1); | |
| 267 | by (etac (Suc_lessD RS minor) 1); | |
| 268 | by (assume_tac 1); | |
| 269 | qed "Suc_lessE"; | |
| 270 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 271 | Goal "Suc(m) < Suc(n) ==> m<n"; | 
| 4745 | 272 | by (blast_tac (claset() addEs [lessE, make_elim Suc_lessD]) 1); | 
| 273 | qed "Suc_less_SucD"; | |
| 274 | ||
| 275 | ||
| 5069 | 276 | Goal "(Suc(m) < Suc(n)) = (m<n)"; | 
| 4745 | 277 | by (EVERY1 [rtac iffI, etac Suc_less_SucD, etac Suc_mono]); | 
| 278 | qed "Suc_less_eq"; | |
| 279 | Addsimps [Suc_less_eq]; | |
| 280 | ||
| 6109 | 281 | (*Goal "~(Suc(n) < n)"; | 
| 4745 | 282 | by (blast_tac (claset() addEs [Suc_lessD RS less_irrefl]) 1); | 
| 283 | qed "not_Suc_n_less_n"; | |
| 6109 | 284 | Addsimps [not_Suc_n_less_n];*) | 
| 4745 | 285 | |
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 286 | Goal "i<j ==> j<k --> Suc i < k"; | 
| 4745 | 287 | by (nat_ind_tac "k" 1); | 
| 288 | by (ALLGOALS (asm_simp_tac (simpset()))); | |
| 289 | by (asm_simp_tac (simpset() addsimps [less_Suc_eq]) 1); | |
| 290 | by (blast_tac (claset() addDs [Suc_lessD]) 1); | |
| 291 | qed_spec_mp "less_trans_Suc"; | |
| 292 | ||
| 2608 | 293 | (*Can be used with less_Suc_eq to get n=m | n<m *) | 
| 5069 | 294 | Goal "(~ m < n) = (n < Suc(m))"; | 
| 2608 | 295 | by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
 | 
| 296 | by (ALLGOALS Asm_simp_tac); | |
| 297 | qed "not_less_eq"; | |
| 298 | ||
| 299 | (*Complete induction, aka course-of-values induction*) | |
| 5316 | 300 | val prems = Goalw [less_def] | 
| 2608 | 301 | "[| !!n. [| ! m::nat. m<n --> P(m) |] ==> P(n) |] ==> P(n)"; | 
| 302 | by (wf_ind_tac "n" [wf_pred_nat RS wf_trancl] 1); | |
| 303 | by (eresolve_tac prems 1); | |
| 304 | qed "less_induct"; | |
| 305 | ||
| 306 | (*** Properties of <= ***) | |
| 307 | ||
| 5500 | 308 | (*Was le_eq_less_Suc, but this orientation is more useful*) | 
| 309 | Goalw [le_def] "(m < Suc n) = (m <= n)"; | |
| 310 | by (rtac (not_less_eq RS sym) 1); | |
| 311 | qed "less_Suc_eq_le"; | |
| 2608 | 312 | |
| 3343 | 313 | (* m<=n ==> m < Suc n *) | 
| 5500 | 314 | bind_thm ("le_imp_less_Suc", less_Suc_eq_le RS iffD2);
 | 
| 3343 | 315 | |
| 5069 | 316 | Goalw [le_def] "0 <= n"; | 
| 2608 | 317 | by (rtac not_less0 1); | 
| 318 | qed "le0"; | |
| 6075 | 319 | AddIffs [le0]; | 
| 2608 | 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 | |
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 331 | Goal "(m <= Suc(n)) = (m<=n | m = Suc n)"; | 
| 5500 | 332 | by (simp_tac (simpset() delsimps [less_Suc_eq_le] | 
| 333 | addsimps [less_Suc_eq_le RS sym, less_Suc_eq]) 1); | |
| 3355 | 334 | qed "le_Suc_eq"; | 
| 335 | ||
| 4614 | 336 | (* [| m <= Suc n; m <= n ==> R; m = Suc n ==> R |] ==> R *) | 
| 337 | bind_thm ("le_SucE", le_Suc_eq RS iffD1 RS disjE);
 | |
| 338 | ||
| 5316 | 339 | Goalw [le_def] "~n<m ==> m<=(n::nat)"; | 
| 340 | by (assume_tac 1); | |
| 2608 | 341 | qed "leI"; | 
| 342 | ||
| 5316 | 343 | Goalw [le_def] "m<=n ==> ~ n < (m::nat)"; | 
| 344 | by (assume_tac 1); | |
| 2608 | 345 | qed "leD"; | 
| 346 | ||
| 347 | val leE = make_elim leD; | |
| 348 | ||
| 5069 | 349 | Goal "(~n<m) = (m<=(n::nat))"; | 
| 4089 | 350 | by (blast_tac (claset() addIs [leI] addEs [leE]) 1); | 
| 2608 | 351 | qed "not_less_iff_le"; | 
| 352 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 353 | Goalw [le_def] "~ m <= n ==> n<(m::nat)"; | 
| 2891 | 354 | by (Blast_tac 1); | 
| 2608 | 355 | qed "not_leE"; | 
| 356 | ||
| 5069 | 357 | Goalw [le_def] "(~n<=m) = (m<(n::nat))"; | 
| 4599 | 358 | by (Simp_tac 1); | 
| 359 | qed "not_le_iff_less"; | |
| 360 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 361 | Goalw [le_def] "m < n ==> Suc(m) <= n"; | 
| 4089 | 362 | by (simp_tac (simpset() addsimps [less_Suc_eq]) 1); | 
| 363 | by (blast_tac (claset() addSEs [less_irrefl,less_asym]) 1); | |
| 3343 | 364 | qed "Suc_leI"; (*formerly called lessD*) | 
| 2608 | 365 | |
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 366 | Goalw [le_def] "Suc(m) <= n ==> m <= n"; | 
| 4089 | 367 | by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1); | 
| 2608 | 368 | qed "Suc_leD"; | 
| 369 | ||
| 370 | (* stronger version of Suc_leD *) | |
| 5148 
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
 paulson parents: 
5143diff
changeset | 371 | Goalw [le_def] "Suc m <= n ==> m < n"; | 
| 4089 | 372 | by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1); | 
| 2608 | 373 | by (cut_facts_tac [less_linear] 1); | 
| 2891 | 374 | by (Blast_tac 1); | 
| 2608 | 375 | qed "Suc_le_lessD"; | 
| 376 | ||
| 5069 | 377 | Goal "(Suc m <= n) = (m < n)"; | 
| 4089 | 378 | by (blast_tac (claset() addIs [Suc_leI, Suc_le_lessD]) 1); | 
| 2608 | 379 | qed "Suc_le_eq"; | 
| 380 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 381 | Goalw [le_def] "m <= n ==> m <= Suc n"; | 
| 4089 | 382 | by (blast_tac (claset() addDs [Suc_lessD]) 1); | 
| 2608 | 383 | qed "le_SucI"; | 
| 384 | Addsimps[le_SucI]; | |
| 385 | ||
| 6109 | 386 | (*bind_thm ("le_Suc", not_Suc_n_less_n RS leI);*)
 | 
| 2608 | 387 | |
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 388 | Goalw [le_def] "m < n ==> m <= (n::nat)"; | 
| 4089 | 389 | by (blast_tac (claset() addEs [less_asym]) 1); | 
| 2608 | 390 | qed "less_imp_le"; | 
| 391 | ||
| 5591 | 392 | (*For instance, (Suc m < Suc n) = (Suc m <= n) = (m<n) *) | 
| 393 | val le_simps = [less_imp_le, less_Suc_eq_le, Suc_le_eq]; | |
| 394 | ||
| 5354 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 395 | |
| 3343 | 396 | (** Equivalence of m<=n and m<n | m=n **) | 
| 397 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 398 | Goalw [le_def] "m <= n ==> m < n | m=(n::nat)"; | 
| 2608 | 399 | by (cut_facts_tac [less_linear] 1); | 
| 4089 | 400 | by (blast_tac (claset() addEs [less_irrefl,less_asym]) 1); | 
| 2608 | 401 | qed "le_imp_less_or_eq"; | 
| 402 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 403 | Goalw [le_def] "m<n | m=n ==> m <=(n::nat)"; | 
| 2608 | 404 | by (cut_facts_tac [less_linear] 1); | 
| 4089 | 405 | by (blast_tac (claset() addSEs [less_irrefl] addEs [less_asym]) 1); | 
| 2608 | 406 | qed "less_or_eq_imp_le"; | 
| 407 | ||
| 5069 | 408 | Goal "(m <= (n::nat)) = (m < n | m=n)"; | 
| 2608 | 409 | by (REPEAT(ares_tac [iffI,less_or_eq_imp_le,le_imp_less_or_eq] 1)); | 
| 410 | qed "le_eq_less_or_eq"; | |
| 411 | ||
| 4635 | 412 | (*Useful with Blast_tac. m=n ==> m<=n *) | 
| 413 | bind_thm ("eq_imp_le", disjI2 RS less_or_eq_imp_le);
 | |
| 414 | ||
| 5069 | 415 | Goal "n <= (n::nat)"; | 
| 4089 | 416 | by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); | 
| 2608 | 417 | qed "le_refl"; | 
| 418 | ||
| 5354 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 419 | |
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 420 | Goal "[| i <= j; j < k |] ==> i < (k::nat)"; | 
| 4468 | 421 | by (blast_tac (claset() addSDs [le_imp_less_or_eq] | 
| 422 | addIs [less_trans]) 1); | |
| 2608 | 423 | qed "le_less_trans"; | 
| 424 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 425 | Goal "[| i < j; j <= k |] ==> i < (k::nat)"; | 
| 4468 | 426 | by (blast_tac (claset() addSDs [le_imp_less_or_eq] | 
| 427 | addIs [less_trans]) 1); | |
| 2608 | 428 | qed "less_le_trans"; | 
| 429 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 430 | Goal "[| i <= j; j <= k |] ==> i <= (k::nat)"; | 
| 4468 | 431 | by (blast_tac (claset() addSDs [le_imp_less_or_eq] | 
| 432 | addIs [less_or_eq_imp_le, less_trans]) 1); | |
| 2608 | 433 | qed "le_trans"; | 
| 434 | ||
| 5143 
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
 paulson parents: 
5132diff
changeset | 435 | Goal "[| m <= n; n <= m |] ==> m = (n::nat)"; | 
| 4468 | 436 | (*order_less_irrefl could make this proof fail*) | 
| 437 | by (blast_tac (claset() addSDs [le_imp_less_or_eq] | |
| 438 | addSEs [less_irrefl] addEs [less_asym]) 1); | |
| 2608 | 439 | qed "le_anti_sym"; | 
| 440 | ||
| 5069 | 441 | Goal "(Suc(n) <= Suc(m)) = (n <= m)"; | 
| 5500 | 442 | by (simp_tac (simpset() addsimps le_simps) 1); | 
| 2608 | 443 | qed "Suc_le_mono"; | 
| 444 | ||
| 445 | AddIffs [Suc_le_mono]; | |
| 446 | ||
| 5500 | 447 | (* Axiom 'order_less_le' of class 'order': *) | 
| 5069 | 448 | Goal "(m::nat) < n = (m <= n & m ~= n)"; | 
| 4737 | 449 | by (simp_tac (simpset() addsimps [le_def, nat_neq_iff]) 1); | 
| 450 | by (blast_tac (claset() addSEs [less_asym]) 1); | |
| 2608 | 451 | qed "nat_less_le"; | 
| 452 | ||
| 5354 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 453 | (* [| m <= n; m ~= n |] ==> m < n *) | 
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 454 | 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: 
5316diff
changeset | 455 | |
| 4640 | 456 | (* Axiom 'linorder_linear' of class 'linorder': *) | 
| 5069 | 457 | Goal "(m::nat) <= n | n <= m"; | 
| 4640 | 458 | by (simp_tac (simpset() addsimps [le_eq_less_or_eq]) 1); | 
| 459 | by (cut_facts_tac [less_linear] 1); | |
| 5132 | 460 | by (Blast_tac 1); | 
| 4640 | 461 | qed "nat_le_linear"; | 
| 462 | ||
| 5354 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 463 | Goal "~ n < m ==> (n < Suc m) = (n = m)"; | 
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 464 | by (blast_tac (claset() addSEs [less_SucE]) 1); | 
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 465 | qed "not_less_less_Suc_eq"; | 
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 466 | |
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 467 | |
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 468 | (*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: 
5316diff
changeset | 469 | Not suitable as default simprules because they often lead to looping*) | 
| 
da63d9b35caf
new theorems; adds [le_refl, less_imp_le] as simprules
 paulson parents: 
5316diff
changeset | 470 | val not_less_simps = [not_less_less_Suc_eq, leD RS not_less_less_Suc_eq]; | 
| 4640 | 471 | |
| 2608 | 472 | (** LEAST -- the least number operator **) | 
| 473 | ||
| 5069 | 474 | Goal "(! m::nat. P m --> n <= m) = (! m. m < n --> ~ P m)"; | 
| 4089 | 475 | by (blast_tac (claset() addIs [leI] addEs [leE]) 1); | 
| 3143 
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
 nipkow parents: 
3085diff
changeset | 476 | val lemma = result(); | 
| 
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
 nipkow parents: 
3085diff
changeset | 477 | |
| 
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
 nipkow parents: 
3085diff
changeset | 478 | (* This is an old def of Least for nat, which is derived for compatibility *) | 
| 5069 | 479 | Goalw [Least_def] | 
| 3143 
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
 nipkow parents: 
3085diff
changeset | 480 | "(LEAST n::nat. P n) == (@n. P(n) & (ALL m. m < n --> ~P(m)))"; | 
| 4089 | 481 | by (simp_tac (simpset() addsimps [lemma]) 1); | 
| 3143 
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
 nipkow parents: 
3085diff
changeset | 482 | qed "Least_nat_def"; | 
| 
d60e49b86c6a
Modified def of Least, which, as Markus correctly complained, looked like
 nipkow parents: 
3085diff
changeset | 483 | |
| 5316 | 484 | val [prem1,prem2] = Goalw [Least_nat_def] | 
| 3842 | 485 | "[| P(k::nat); !!x. x<k ==> ~P(x) |] ==> (LEAST x. P(x)) = k"; | 
| 2608 | 486 | by (rtac select_equality 1); | 
| 4089 | 487 | by (blast_tac (claset() addSIs [prem1,prem2]) 1); | 
| 2608 | 488 | by (cut_facts_tac [less_linear] 1); | 
| 4089 | 489 | by (blast_tac (claset() addSIs [prem1] addSDs [prem2]) 1); | 
| 2608 | 490 | qed "Least_equality"; | 
| 491 | ||
| 5316 | 492 | Goal "P(k::nat) ==> P(LEAST x. P(x))"; | 
| 493 | by (etac rev_mp 1); | |
| 2608 | 494 | by (res_inst_tac [("n","k")] less_induct 1);
 | 
| 495 | by (rtac impI 1); | |
| 496 | by (rtac classical 1); | |
| 497 | by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1);
 | |
| 498 | by (assume_tac 1); | |
| 499 | by (assume_tac 2); | |
| 2891 | 500 | by (Blast_tac 1); | 
| 2608 | 501 | qed "LeastI"; | 
| 502 | ||
| 503 | (*Proof is almost identical to the one above!*) | |
| 5316 | 504 | Goal "P(k::nat) ==> (LEAST x. P(x)) <= k"; | 
| 505 | by (etac rev_mp 1); | |
| 2608 | 506 | by (res_inst_tac [("n","k")] less_induct 1);
 | 
| 507 | by (rtac impI 1); | |
| 508 | by (rtac classical 1); | |
| 509 | by (res_inst_tac [("s","n")] (Least_equality RS ssubst) 1);
 | |
| 510 | by (assume_tac 1); | |
| 511 | by (rtac le_refl 2); | |
| 4089 | 512 | by (blast_tac (claset() addIs [less_imp_le,le_trans]) 1); | 
| 2608 | 513 | qed "Least_le"; | 
| 514 | ||
| 5316 | 515 | Goal "k < (LEAST x. P(x)) ==> ~P(k::nat)"; | 
| 2608 | 516 | by (rtac notI 1); | 
| 5316 | 517 | by (etac (rewrite_rule [le_def] Least_le RS notE) 1 THEN assume_tac 1); | 
| 2608 | 518 | qed "not_less_Least"; | 
| 519 | ||
| 5983 | 520 | (* [| m ~= n; m < n ==> P; n < m ==> P |] ==> P *) | 
| 4737 | 521 | bind_thm("nat_neqE", nat_neq_iff RS iffD1 RS disjE);
 | 
| 7064 | 522 | |
| 523 | Goal "(S::nat set) ~= {} ==> ? x:S. ! y:S. x <= y";
 | |
| 524 | by (cut_facts_tac [wf_pred_nat RS wf_trancl RS (wf_eq_minimal RS iffD1)] 1); | |
| 525 | by (dres_inst_tac [("x","S")] spec 1);
 | |
| 526 | by (Asm_full_simp_tac 1); | |
| 527 | by (etac impE 1); | |
| 528 | by (Force_tac 1); | |
| 529 | by (force_tac (claset(), simpset() addsimps [less_eq,not_le_iff_less]) 1); | |
| 530 | qed "nonempty_has_least"; |