author nipkow Wed May 15 13:49:51 2002 +0200 (2002-05-15) changeset 13152 2a54f99b44b3 parent 13151 0f1c6fa846f2 child 13153 4b052946b41c
Divides.ML -> Divides_lemmas.ML
Converted Divides.thy to Isar.
 src/HOL/Divides.ML file | annotate | diff | revisions src/HOL/Divides.thy file | annotate | diff | revisions src/HOL/IsaMakefile file | annotate | diff | revisions
```     1.1 --- a/src/HOL/Divides.ML	Wed May 15 11:51:20 2002 +0200
1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,682 +0,0 @@
1.4 -(*  Title:      HOL/Divides.ML
1.5 -    ID:         \$Id\$
1.6 -    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
1.7 -    Copyright   1993  University of Cambridge
1.8 -
1.9 -The division operators div, mod and the divides relation "dvd"
1.10 -*)
1.11 -
1.12 -
1.13 -(** Less-then properties **)
1.14 -
1.15 -bind_thm ("wf_less_trans", [eq_reflection, wf_pred_nat RS wf_trancl] MRS
1.16 -                    def_wfrec RS trans);
1.17 -
1.18 -Goal "(%m. m mod n) = wfrec (trancl pred_nat) \
1.19 -\                           (%f j. if j<n | n=0 then j else f (j-n))";
1.20 -by (simp_tac (simpset() addsimps [mod_def]) 1);
1.21 -qed "mod_eq";
1.22 -
1.23 -Goal "(%m. m div n) = wfrec (trancl pred_nat) \
1.24 -\            (%f j. if j<n | n=0 then 0 else Suc (f (j-n)))";
1.25 -by (simp_tac (simpset() addsimps [div_def]) 1);
1.26 -qed "div_eq";
1.27 -
1.28 -
1.29 -(** Aribtrary definitions for division by zero.  Useful to simplify
1.30 -    certain equations **)
1.31 -
1.32 -Goal "a div 0 = (0::nat)";
1.33 -by (rtac (div_eq RS wf_less_trans) 1);
1.34 -by (Asm_simp_tac 1);
1.35 -qed "DIVISION_BY_ZERO_DIV";  (*NOT for adding to default simpset*)
1.36 -
1.37 -Goal "a mod 0 = (a::nat)";
1.38 -by (rtac (mod_eq RS wf_less_trans) 1);
1.39 -by (Asm_simp_tac 1);
1.40 -qed "DIVISION_BY_ZERO_MOD";  (*NOT for adding to default simpset*)
1.41 -
1.42 -fun div_undefined_case_tac s i =
1.43 -  case_tac s i THEN
1.44 -  Full_simp_tac (i+1) THEN
1.45 -  asm_simp_tac (simpset() addsimps [DIVISION_BY_ZERO_DIV,
1.46 -				    DIVISION_BY_ZERO_MOD]) i;
1.47 -
1.48 -(*** Remainder ***)
1.49 -
1.50 -Goal "m<n ==> m mod n = (m::nat)";
1.51 -by (rtac (mod_eq RS wf_less_trans) 1);
1.52 -by (Asm_simp_tac 1);
1.53 -qed "mod_less";
1.54 -Addsimps [mod_less];
1.55 -
1.56 -Goal "~ m < (n::nat) ==> m mod n = (m-n) mod n";
1.57 -by (div_undefined_case_tac "n=0" 1);
1.58 -by (rtac (mod_eq RS wf_less_trans) 1);
1.59 -by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1);
1.60 -qed "mod_geq";
1.61 -
1.62 -(*Avoids the ugly ~m<n above*)
1.63 -Goal "(n::nat) <= m ==> m mod n = (m-n) mod n";
1.64 -by (asm_simp_tac (simpset() addsimps [mod_geq, not_less_iff_le]) 1);
1.65 -qed "le_mod_geq";
1.66 -
1.67 -Goal "m mod (n::nat) = (if m<n then m else (m-n) mod n)";
1.68 -by (asm_simp_tac (simpset() addsimps [mod_geq]) 1);
1.69 -qed "mod_if";
1.70 -
1.71 -Goal "m mod Suc 0 = 0";
1.72 -by (induct_tac "m" 1);
1.73 -by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_geq])));
1.74 -qed "mod_1";
1.75 -Addsimps [mod_1];
1.76 -
1.77 -Goal "n mod n = (0::nat)";
1.78 -by (div_undefined_case_tac "n=0" 1);
1.79 -by (asm_simp_tac (simpset() addsimps [mod_geq]) 1);
1.80 -qed "mod_self";
1.81 -Addsimps [mod_self];
1.82 -
1.83 -Goal "(m+n) mod n = m mod (n::nat)";
1.84 -by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1);
1.85 -by (stac (mod_geq RS sym) 2);
1.86 -by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute])));
1.87 -qed "mod_add_self2";
1.88 -
1.89 -Goal "(n+m) mod n = m mod (n::nat)";
1.90 -by (asm_simp_tac (simpset() addsimps [add_commute, mod_add_self2]) 1);
1.91 -qed "mod_add_self1";
1.92 -
1.93 -Addsimps [mod_add_self1, mod_add_self2];
1.94 -
1.95 -Goal "(m + k*n) mod n = m mod (n::nat)";
1.96 -by (induct_tac "k" 1);
1.97 -by (ALLGOALS
1.98 -    (asm_simp_tac
1.99 -     (simpset() addsimps [read_instantiate [("y","n")] add_left_commute])));
1.100 -qed "mod_mult_self1";
1.101 -
1.102 -Goal "(m + n*k) mod n = m mod (n::nat)";
1.103 -by (asm_simp_tac (simpset() addsimps [mult_commute, mod_mult_self1]) 1);
1.104 -qed "mod_mult_self2";
1.105 -
1.106 -Addsimps [mod_mult_self1, mod_mult_self2];
1.107 -
1.108 -Goal "(m mod n) * (k::nat) = (m*k) mod (n*k)";
1.109 -by (div_undefined_case_tac "n=0" 1);
1.110 -by (div_undefined_case_tac "k=0" 1);
1.111 -by (induct_thm_tac nat_less_induct "m" 1);
1.112 -by (stac mod_if 1);
1.113 -by (Asm_simp_tac 1);
1.114 -by (asm_simp_tac (simpset() addsimps [mod_geq,
1.115 -				      diff_less, diff_mult_distrib]) 1);
1.116 -qed "mod_mult_distrib";
1.117 -
1.118 -Goal "(k::nat) * (m mod n) = (k*m) mod (k*n)";
1.119 -by (asm_simp_tac
1.120 -    (simpset() addsimps [read_instantiate [("m","k")] mult_commute,
1.121 -			 mod_mult_distrib]) 1);
1.122 -qed "mod_mult_distrib2";
1.123 -
1.124 -Goal "(m*n) mod n = (0::nat)";
1.125 -by (div_undefined_case_tac "n=0" 1);
1.126 -by (induct_tac "m" 1);
1.127 -by (Asm_simp_tac 1);
1.128 -by (rename_tac "k" 1);
1.129 -by (cut_inst_tac [("m","k*n"),("n","n")] mod_add_self2 1);
1.130 -by (asm_full_simp_tac (simpset() addsimps [add_commute]) 1);
1.131 -qed "mod_mult_self_is_0";
1.132 -
1.133 -Goal "(n*m) mod n = (0::nat)";
1.134 -by (simp_tac (simpset() addsimps [mult_commute, mod_mult_self_is_0]) 1);
1.135 -qed "mod_mult_self1_is_0";
1.136 -Addsimps [mod_mult_self_is_0, mod_mult_self1_is_0];
1.137 -
1.138 -
1.139 -(*** Quotient ***)
1.140 -
1.141 -Goal "m<n ==> m div n = (0::nat)";
1.142 -by (rtac (div_eq RS wf_less_trans) 1);
1.143 -by (Asm_simp_tac 1);
1.144 -qed "div_less";
1.145 -Addsimps [div_less];
1.146 -
1.147 -Goal "[| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
1.148 -by (rtac (div_eq RS wf_less_trans) 1);
1.149 -by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1);
1.150 -qed "div_geq";
1.151 -
1.152 -(*Avoids the ugly ~m<n above*)
1.153 -Goal "[| 0<n;  n<=m |] ==> m div n = Suc((m-n) div n)";
1.154 -by (asm_simp_tac (simpset() addsimps [div_geq, not_less_iff_le]) 1);
1.155 -qed "le_div_geq";
1.156 -
1.157 -Goal "0<n ==> m div n = (if m<n then 0 else Suc((m-n) div n))";
1.158 -by (asm_simp_tac (simpset() addsimps [div_geq]) 1);
1.159 -qed "div_if";
1.160 -
1.161 -
1.162 -(*Main Result about quotient and remainder.*)
1.163 -Goal "(m div n)*n + m mod n = (m::nat)";
1.164 -by (div_undefined_case_tac "n=0" 1);
1.165 -by (induct_thm_tac nat_less_induct "m" 1);
1.166 -by (stac mod_if 1);
1.167 -by (ALLGOALS (asm_simp_tac
1.168 -	      (simpset() addsimps [add_assoc, div_geq,
1.169 -				   add_diff_inverse, diff_less])));
1.170 -qed "mod_div_equality";
1.171 -
1.172 -(* a simple rearrangement of mod_div_equality: *)
1.173 -Goal "(n::nat) * (m div n) = m - (m mod n)";
1.174 -by (cut_inst_tac [("m","m"),("n","n")] mod_div_equality 1);
1.175 -by (full_simp_tac (simpset() addsimps mult_ac) 1);
1.176 -by (arith_tac 1);
1.177 -qed "mult_div_cancel";
1.178 -
1.179 -Goal "0<n ==> m mod n < (n::nat)";
1.180 -by (induct_thm_tac nat_less_induct "m" 1);
1.181 -by (case_tac "na<n" 1);
1.182 -(*case n le na*)
1.183 -by (asm_full_simp_tac (simpset() addsimps [mod_geq, diff_less]) 2);
1.184 -(*case na<n*)
1.185 -by (Asm_simp_tac 1);
1.186 -qed "mod_less_divisor";
1.187 -Addsimps [mod_less_divisor];
1.188 -
1.189 -(*** More division laws ***)
1.190 -
1.191 -Goal "0<n ==> (m*n) div n = (m::nat)";
1.192 -by (cut_inst_tac [("m", "m*n"),("n","n")] mod_div_equality 1);
1.193 -by Auto_tac;
1.194 -qed "div_mult_self_is_m";
1.195 -
1.196 -Goal "0<n ==> (n*m) div n = (m::nat)";
1.197 -by (asm_simp_tac (simpset() addsimps [mult_commute, div_mult_self_is_m]) 1);
1.198 -qed "div_mult_self1_is_m";
1.199 -Addsimps [div_mult_self_is_m, div_mult_self1_is_m];
1.200 -
1.201 -(*mod_mult_distrib2 above is the counterpart for remainder*)
1.202 -
1.203 -
1.204 -(*** Proving facts about div and mod using quorem ***)
1.205 -
1.206 -Goal "[| b*q' + r'  <= b*q + r;  0 < b;  r < b |] \
1.207 -\     ==> q' <= (q::nat)";
1.208 -by (rtac leI 1);
1.209 -by (stac less_iff_Suc_add 1);
1.210 -by (auto_tac (claset(), simpset() addsimps [add_mult_distrib2]));
1.211 -qed "unique_quotient_lemma";
1.212 -
1.213 -Goal "[| quorem ((a,b), (q,r));  quorem ((a,b), (q',r'));  0 < b |] \
1.214 -\     ==> q = q'";
1.215 -by (asm_full_simp_tac
1.216 -    (simpset() addsimps split_ifs @ [Divides.quorem_def]) 1);
1.217 -by Auto_tac;
1.218 -by (REPEAT
1.219 -    (blast_tac (claset() addIs [order_antisym]
1.220 -			 addDs [order_eq_refl RS unique_quotient_lemma,
1.221 -				sym]) 1));
1.222 -qed "unique_quotient";
1.223 -
1.224 -Goal "[| quorem ((a,b), (q,r));  quorem ((a,b), (q',r'));  0 < b |] \
1.225 -\     ==> r = r'";
1.226 -by (subgoal_tac "q = q'" 1);
1.227 -by (blast_tac (claset() addIs [unique_quotient]) 2);
1.228 -by (asm_full_simp_tac (simpset() addsimps [Divides.quorem_def]) 1);
1.229 -qed "unique_remainder";
1.230 -
1.231 -Goal "0 < b ==> quorem ((a, b), (a div b, a mod b))";
1.232 -by (cut_inst_tac [("m","a"),("n","b")] mod_div_equality 1);
1.233 -by (auto_tac
1.234 -    (claset() addEs [sym],
1.235 -     simpset() addsimps mult_ac@[Divides.quorem_def]));
1.236 -qed "quorem_div_mod";
1.237 -
1.238 -Goal "[| quorem((a,b),(q,r));  0 < b |] ==> a div b = q";
1.239 -by (asm_simp_tac (simpset() addsimps [quorem_div_mod RS unique_quotient]) 1);
1.240 -qed "quorem_div";
1.241 -
1.242 -Goal "[| quorem((a,b),(q,r));  0 < b |] ==> a mod b = r";
1.243 -by (asm_simp_tac (simpset() addsimps [quorem_div_mod RS unique_remainder]) 1);
1.244 -qed "quorem_mod";
1.245 -
1.246 -(** A dividend of zero **)
1.247 -
1.248 -Goal "0 div m = (0::nat)";
1.249 -by (div_undefined_case_tac "m=0" 1);
1.250 -by (Asm_simp_tac 1);
1.251 -qed "div_0";
1.252 -
1.253 -Goal "0 mod m = (0::nat)";
1.254 -by (div_undefined_case_tac "m=0" 1);
1.255 -by (Asm_simp_tac 1);
1.256 -qed "mod_0";
1.257 -Addsimps [div_0, mod_0];
1.258 -
1.259 -(** proving (a*b) div c = a * (b div c) + a * (b mod c) **)
1.260 -
1.261 -Goal "[| quorem((b,c),(q,r));  0 < c |] \
1.262 -\     ==> quorem ((a*b, c), (a*q + a*r div c, a*r mod c))";
1.263 -by (cut_inst_tac [("m", "a*r"), ("n","c")] mod_div_equality 1);
1.264 -by (auto_tac
1.265 -    (claset(),
1.266 -     simpset() addsimps split_ifs@mult_ac@
1.267 -                        [Divides.quorem_def, add_mult_distrib2]));
1.268 -val lemma = result();
1.269 -
1.270 -Goal "(a*b) div c = a*(b div c) + a*(b mod c) div (c::nat)";
1.271 -by (div_undefined_case_tac "c = 0" 1);
1.272 -by (blast_tac (claset() addIs [quorem_div_mod RS lemma RS quorem_div]) 1);
1.273 -qed "div_mult1_eq";
1.274 -
1.275 -Goal "(a*b) mod c = a*(b mod c) mod (c::nat)";
1.276 -by (div_undefined_case_tac "c = 0" 1);
1.277 -by (blast_tac (claset() addIs [quorem_div_mod RS lemma RS quorem_mod]) 1);
1.278 -qed "mod_mult1_eq";
1.279 -
1.280 -Goal "(a*b) mod (c::nat) = ((a mod c) * b) mod c";
1.281 -by (rtac trans 1);
1.282 -by (res_inst_tac [("s","b*a mod c")] trans 1);
1.283 -by (rtac mod_mult1_eq 2);
1.284 -by (ALLGOALS (simp_tac (simpset() addsimps [mult_commute])));
1.285 -qed "mod_mult1_eq'";
1.286 -
1.287 -Goal "(a*b) mod (c::nat) = ((a mod c) * (b mod c)) mod c";
1.288 -by (rtac (mod_mult1_eq' RS trans) 1);
1.289 -by (rtac mod_mult1_eq 1);
1.290 -qed "mod_mult_distrib_mod";
1.291 -
1.292 -(** proving (a+b) div c = a div c + b div c + ((a mod c + b mod c) div c) **)
1.293 -
1.294 -Goal "[| quorem((a,c),(aq,ar));  quorem((b,c),(bq,br));  0 < c |] \
1.295 -\     ==> quorem ((a+b, c), (aq + bq + (ar+br) div c, (ar+br) mod c))";
1.296 -by (cut_inst_tac [("m", "ar+br"), ("n","c")] mod_div_equality 1);
1.297 -by (auto_tac
1.298 -    (claset(),
1.299 -     simpset() addsimps split_ifs@mult_ac@
1.300 -                        [Divides.quorem_def, add_mult_distrib2]));
1.301 -val lemma = result();
1.302 -
1.303 -(*NOT suitable for rewriting: the RHS has an instance of the LHS*)
1.304 -Goal "(a+b) div (c::nat) = a div c + b div c + ((a mod c + b mod c) div c)";
1.305 -by (div_undefined_case_tac "c = 0" 1);
1.306 -by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod]
1.307 -			       MRS lemma RS quorem_div]) 1);
1.308 -qed "div_add1_eq";
1.309 -
1.310 -Goal "(a+b) mod (c::nat) = (a mod c + b mod c) mod c";
1.311 -by (div_undefined_case_tac "c = 0" 1);
1.312 -by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod]
1.313 -			       MRS lemma RS quorem_mod]) 1);
1.314 -qed "mod_add1_eq";
1.315 -
1.316 -
1.317 -(*** proving  a div (b*c) = (a div b) div c ***)
1.318 -
1.319 -(** first, a lemma to bound the remainder **)
1.320 -
1.321 -Goal "[| (0::nat) < c; r < b |] ==> b * (q mod c) + r < b * c";
1.322 -by (cut_inst_tac [("m","q"),("n","c")] mod_less_divisor 1);
1.323 -by (dres_inst_tac [("m","q mod c")] less_imp_Suc_add 2);
1.324 -by Auto_tac;
1.325 -by (eres_inst_tac [("P","%x. ?lhs < ?rhs x")] ssubst 1);
1.326 -by (asm_simp_tac (simpset() addsimps [add_mult_distrib2]) 1);
1.327 -val mod_lemma = result();
1.328 -
1.329 -Goal "[| quorem ((a,b), (q,r));  0 < b;  0 < c |] \
1.330 -\     ==> quorem ((a, b*c), (q div c, b*(q mod c) + r))";
1.331 -by (cut_inst_tac [("m", "q"), ("n","c")] mod_div_equality 1);
1.332 -by (auto_tac
1.333 -    (claset(),
1.334 -     simpset() addsimps mult_ac@
1.335 -                        [Divides.quorem_def, add_mult_distrib2 RS sym,
1.336 -			 mod_lemma]));
1.337 -val lemma = result();
1.338 -
1.339 -Goal "a div (b*c) = (a div b) div (c::nat)";
1.340 -by (div_undefined_case_tac "b=0" 1);
1.341 -by (div_undefined_case_tac "c=0" 1);
1.342 -by (force_tac (claset(),
1.343 -	       simpset() addsimps [quorem_div_mod RS lemma RS quorem_div]) 1);
1.344 -qed "div_mult2_eq";
1.345 -
1.346 -Goal "a mod (b*c) = b*(a div b mod c) + a mod (b::nat)";
1.347 -by (div_undefined_case_tac "b=0" 1);
1.348 -by (div_undefined_case_tac "c=0" 1);
1.349 -by (cut_inst_tac [("m", "a"), ("n","b")] mod_div_equality 1);
1.350 -by (auto_tac (claset(),
1.351 -	       simpset() addsimps [mult_commute,
1.352 -				   quorem_div_mod RS lemma RS quorem_mod]));
1.353 -qed "mod_mult2_eq";
1.354 -
1.355 -
1.356 -(*** Cancellation of common factors in "div" ***)
1.357 -
1.358 -Goal "[| (0::nat) < b;  0 < c |] ==> (c*a) div (c*b) = a div b";
1.359 -by (stac div_mult2_eq 1);
1.360 -by Auto_tac;
1.361 -val lemma1 = result();
1.362 -
1.363 -Goal "(0::nat) < c ==> (c*a) div (c*b) = a div b";
1.364 -by (div_undefined_case_tac "b = 0" 1);
1.365 -by (auto_tac
1.366 -    (claset(),
1.367 -     simpset() addsimps [read_instantiate [("x", "b")] linorder_neq_iff,
1.368 -			 lemma1, lemma2]));
1.369 -qed "div_mult_mult1";
1.370 -
1.371 -Goal "(0::nat) < c ==> (a*c) div (b*c) = a div b";
1.372 -by (dtac div_mult_mult1 1);
1.373 -by (auto_tac (claset(), simpset() addsimps [mult_commute]));
1.374 -qed "div_mult_mult2";
1.375 -
1.376 -Addsimps [div_mult_mult1, div_mult_mult2];
1.377 -
1.378 -
1.379 -(*** Distribution of factors over "mod"
1.380 -
1.381 -Could prove these as in Integ/IntDiv.ML, but we already have
1.382 -mod_mult_distrib and mod_mult_distrib2 above!
1.383 -
1.384 -Goal "(c*a) mod (c*b) = (c::nat) * (a mod b)";
1.385 -qed "mod_mult_mult1";
1.386 -
1.387 -Goal "(a*c) mod (b*c) = (a mod b) * (c::nat)";
1.388 -qed "mod_mult_mult2";
1.389 - ***)
1.390 -
1.391 -(*** Further facts about div and mod ***)
1.392 -
1.393 -Goal "m div Suc 0 = m";
1.394 -by (induct_tac "m" 1);
1.395 -by (ALLGOALS (asm_simp_tac (simpset() addsimps [div_geq])));
1.396 -qed "div_1";
1.397 -Addsimps [div_1];
1.398 -
1.399 -Goal "0<n ==> n div n = (1::nat)";
1.400 -by (asm_simp_tac (simpset() addsimps [div_geq]) 1);
1.401 -qed "div_self";
1.402 -Addsimps [div_self];
1.403 -
1.404 -Goal "0<n ==> (m+n) div n = Suc (m div n)";
1.405 -by (subgoal_tac "(n + m) div n = Suc ((n+m-n) div n)" 1);
1.406 -by (stac (div_geq RS sym) 2);
1.407 -by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute])));
1.408 -qed "div_add_self2";
1.409 -
1.410 -Goal "0<n ==> (n+m) div n = Suc (m div n)";
1.411 -by (asm_simp_tac (simpset() addsimps [add_commute, div_add_self2]) 1);
1.412 -qed "div_add_self1";
1.413 -
1.414 -Goal "!!n::nat. 0<n ==> (m + k*n) div n = k + m div n";
1.415 -by (stac div_add1_eq 1);
1.416 -by (stac div_mult1_eq 1);
1.417 -by (Asm_simp_tac 1);
1.418 -qed "div_mult_self1";
1.419 -
1.420 -Goal "0<n ==> (m + n*k) div n = k + m div (n::nat)";
1.421 -by (asm_simp_tac (simpset() addsimps [mult_commute, div_mult_self1]) 1);
1.422 -qed "div_mult_self2";
1.423 -
1.424 -Addsimps [div_mult_self1, div_mult_self2];
1.425 -
1.426 -(* Monotonicity of div in first argument *)
1.427 -Goal "ALL m::nat. m <= n --> (m div k) <= (n div k)";
1.428 -by (div_undefined_case_tac "k=0" 1);
1.429 -by (induct_thm_tac nat_less_induct "n" 1);
1.430 -by (Clarify_tac 1);
1.431 -by (case_tac "n<k" 1);
1.432 -(* 1  case n<k *)
1.433 -by (Asm_simp_tac 1);
1.434 -(* 2  case n >= k *)
1.435 -by (case_tac "m<k" 1);
1.436 -(* 2.1  case m<k *)
1.437 -by (Asm_simp_tac 1);
1.438 -(* 2.2  case m>=k *)
1.439 -by (asm_simp_tac (simpset() addsimps [div_geq, diff_less, diff_le_mono]) 1);
1.440 -qed_spec_mp "div_le_mono";
1.441 -
1.442 -(* Antimonotonicity of div in second argument *)
1.443 -Goal "!!m::nat. [| 0<m; m<=n |] ==> (k div n) <= (k div m)";
1.444 -by (subgoal_tac "0<n" 1);
1.445 - by (Asm_simp_tac 2);
1.446 -by (induct_thm_tac nat_less_induct "k" 1);
1.447 -by (rename_tac "k" 1);
1.448 -by (case_tac "k<n" 1);
1.449 - by (Asm_simp_tac 1);
1.450 -by (subgoal_tac "~(k<m)" 1);
1.451 - by (Asm_simp_tac 2);
1.452 -by (asm_simp_tac (simpset() addsimps [div_geq]) 1);
1.453 -by (subgoal_tac "(k-n) div n <= (k-m) div n" 1);
1.454 - by (REPEAT (ares_tac [div_le_mono,diff_le_mono2] 2));
1.455 -by (rtac le_trans 1);
1.456 -by (Asm_simp_tac 1);
1.457 -by (asm_simp_tac (simpset() addsimps [diff_less]) 1);
1.458 -qed "div_le_mono2";
1.459 -
1.460 -Goal "m div n <= (m::nat)";
1.461 -by (div_undefined_case_tac "n=0" 1);
1.462 -by (subgoal_tac "m div n <= m div 1" 1);
1.463 -by (Asm_full_simp_tac 1);
1.464 -by (rtac div_le_mono2 1);
1.465 -by (ALLGOALS Asm_simp_tac);
1.466 -qed "div_le_dividend";
1.467 -Addsimps [div_le_dividend];
1.468 -
1.469 -(* Similar for "less than" *)
1.470 -Goal "!!n::nat. 1<n ==> (0 < m) --> (m div n < m)";
1.471 -by (induct_thm_tac nat_less_induct "m" 1);
1.472 -by (rename_tac "m" 1);
1.473 -by (case_tac "m<n" 1);
1.474 - by (Asm_full_simp_tac 1);
1.475 -by (subgoal_tac "0<n" 1);
1.476 - by (Asm_simp_tac 2);
1.477 -by (asm_full_simp_tac (simpset() addsimps [div_geq]) 1);
1.478 -by (case_tac "n<m" 1);
1.479 - by (subgoal_tac "(m-n) div n < (m-n)" 1);
1.480 -  by (REPEAT (ares_tac [impI,less_trans_Suc] 1));
1.481 -  by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1);
1.482 - by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1);
1.483 -(* case n=m *)
1.484 -by (subgoal_tac "m=n" 1);
1.485 - by (Asm_simp_tac 2);
1.486 -by (Asm_simp_tac 1);
1.487 -qed_spec_mp "div_less_dividend";
1.488 -Addsimps [div_less_dividend];
1.489 -
1.490 -(*** Further facts about mod (mainly for the mutilated chess board ***)
1.491 -
1.492 -Goal "Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))";
1.493 -by (div_undefined_case_tac "n=0" 1);
1.494 -by (induct_thm_tac nat_less_induct "m" 1);
1.495 -by (case_tac "Suc(na)<n" 1);
1.496 -(* case Suc(na) < n *)
1.497 -by (forward_tac [lessI RS less_trans] 1
1.498 -    THEN asm_simp_tac (simpset() addsimps [less_not_refl3]) 1);
1.499 -(* case n <= Suc(na) *)
1.500 -by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, le_Suc_eq,
1.501 -					   mod_geq]) 1);
1.502 -by (auto_tac (claset(),
1.503 -	      simpset() addsimps [Suc_diff_le, diff_less, le_mod_geq]));
1.504 -qed "mod_Suc";
1.505 -
1.506 -
1.507 -(************************************************)
1.508 -(** Divides Relation                           **)
1.509 -(************************************************)
1.510 -
1.511 -Goalw [dvd_def] "n = m * k ==> m dvd n";
1.512 -by (Blast_tac 1);
1.513 -qed "dvdI";
1.514 -
1.515 -Goalw [dvd_def] "!!P. [|m dvd n;  !!k. n = m*k ==> P|] ==> P";
1.516 -by (Blast_tac 1);
1.517 -qed "dvdE";
1.518 -
1.519 -Goalw [dvd_def] "m dvd (0::nat)";
1.520 -by (blast_tac (claset() addIs [mult_0_right RS sym]) 1);
1.521 -qed "dvd_0_right";
1.522 -AddIffs [dvd_0_right];
1.523 -
1.524 -Goalw [dvd_def] "0 dvd m ==> m = (0::nat)";
1.525 -by Auto_tac;
1.526 -qed "dvd_0_left";
1.527 -
1.528 -Goal "(0 dvd (m::nat)) = (m = 0)";
1.529 -by (blast_tac (claset() addIs [dvd_0_left]) 1);
1.530 -qed "dvd_0_left_iff";
1.531 -AddIffs [dvd_0_left_iff];
1.532 -
1.533 -Goalw [dvd_def] "Suc 0 dvd k";
1.534 -by (Simp_tac 1);
1.535 -qed "dvd_1_left";
1.536 -AddIffs [dvd_1_left];
1.537 -
1.538 -Goal "(m dvd Suc 0) = (m = Suc 0)";
1.539 -by (simp_tac (simpset() addsimps [dvd_def]) 1);
1.540 -qed "dvd_1_iff_1";
1.541 -Addsimps [dvd_1_iff_1];
1.542 -
1.543 -Goalw [dvd_def] "m dvd (m::nat)";
1.544 -by (blast_tac (claset() addIs [mult_1_right RS sym]) 1);
1.545 -qed "dvd_refl";
1.546 -Addsimps [dvd_refl];
1.547 -
1.548 -Goalw [dvd_def] "[| m dvd n; n dvd p |] ==> m dvd (p::nat)";
1.549 -by (blast_tac (claset() addIs [mult_assoc] ) 1);
1.550 -qed "dvd_trans";
1.551 -
1.552 -Goalw [dvd_def] "[| m dvd n; n dvd m |] ==> m = (n::nat)";
1.553 -by (force_tac (claset() addDs [mult_eq_self_implies_10],
1.554 -	       simpset() addsimps [mult_assoc, mult_eq_1_iff]) 1);
1.555 -qed "dvd_anti_sym";
1.556 -
1.557 -Goalw [dvd_def] "[| k dvd m; k dvd n |] ==> k dvd (m+n :: nat)";
1.558 -by (blast_tac (claset() addIs [add_mult_distrib2 RS sym]) 1);
1.559 -qed "dvd_add";
1.560 -
1.561 -Goalw [dvd_def] "[| k dvd m; k dvd n |] ==> k dvd (m-n :: nat)";
1.562 -by (blast_tac (claset() addIs [diff_mult_distrib2 RS sym]) 1);
1.563 -qed "dvd_diff";
1.564 -
1.565 -Goal "[| k dvd m-n; k dvd n; n<=m |] ==> k dvd (m::nat)";
1.566 -by (etac (not_less_iff_le RS iffD2 RS add_diff_inverse RS subst) 1);
1.567 -by (blast_tac (claset() addIs [dvd_add]) 1);
1.568 -qed "dvd_diffD";
1.569 -
1.570 -Goal "[| k dvd m-n; k dvd m; n<=m |] ==> k dvd (n::nat)";
1.571 -by (dres_inst_tac [("m","m")] dvd_diff 1);
1.572 -by Auto_tac;
1.573 -qed "dvd_diffD1";
1.574 -
1.575 -Goalw [dvd_def] "k dvd n ==> k dvd (m*n :: nat)";
1.576 -by (blast_tac (claset() addIs [mult_left_commute]) 1);
1.577 -qed "dvd_mult";
1.578 -
1.579 -Goal "k dvd m ==> k dvd (m*n :: nat)";
1.580 -by (stac mult_commute 1);
1.581 -by (etac dvd_mult 1);
1.582 -qed "dvd_mult2";
1.583 -
1.584 -(* k dvd (m*k) *)
1.585 -AddIffs [dvd_refl RS dvd_mult, dvd_refl RS dvd_mult2];
1.586 -
1.587 -Goal "(k dvd n + k) = (k dvd (n::nat))";
1.588 -by (rtac iffI 1);
1.589 -by (etac dvd_add 2);
1.590 -by (rtac dvd_refl 2);
1.591 -by (subgoal_tac "n = (n+k)-k" 1);
1.592 -by  (Simp_tac 2);
1.593 -by (etac ssubst 1);
1.594 -by (etac dvd_diff 1);
1.595 -by (rtac dvd_refl 1);
1.596 -qed "dvd_reduce";
1.597 -
1.598 -Goalw [dvd_def] "!!n::nat. [| f dvd m; f dvd n |] ==> f dvd m mod n";
1.599 -by (div_undefined_case_tac "n=0" 1);
1.600 -by Auto_tac;
1.601 -by (blast_tac (claset() addIs [mod_mult_distrib2 RS sym]) 1);
1.602 -qed "dvd_mod";
1.603 -
1.604 -Goal "[| (k::nat) dvd m mod n;  k dvd n |] ==> k dvd m";
1.605 -by (subgoal_tac "k dvd (m div n)*n + m mod n" 1);
1.606 -by (asm_simp_tac (simpset() addsimps [dvd_add, dvd_mult]) 2);
1.607 -by (asm_full_simp_tac (simpset() addsimps [mod_div_equality]) 1);
1.608 -qed "dvd_mod_imp_dvd";
1.609 -
1.610 -Goal "k dvd n ==> ((k::nat) dvd m mod n) = (k dvd m)";
1.611 -by (blast_tac (claset() addIs [dvd_mod_imp_dvd, dvd_mod]) 1);
1.612 -qed "dvd_mod_iff";
1.613 -
1.614 -Goalw [dvd_def]  "!!k::nat. [| k*m dvd k*n; 0<k |] ==> m dvd n";
1.615 -by (etac exE 1);
1.616 -by (asm_full_simp_tac (simpset() addsimps mult_ac) 1);
1.617 -qed "dvd_mult_cancel";
1.618 -
1.619 -Goal "0<m ==> (m*n dvd m) = (n = (1::nat))";
1.620 -by Auto_tac;
1.621 -by (subgoal_tac "m*n dvd m*1" 1);
1.622 -by (dtac dvd_mult_cancel 1);
1.623 -by Auto_tac;
1.624 -qed "dvd_mult_cancel1";
1.625 -
1.626 -Goal "0<m ==> (n*m dvd m) = (n = (1::nat))";
1.627 -by (stac mult_commute 1);
1.628 -by (etac dvd_mult_cancel1 1);
1.629 -qed "dvd_mult_cancel2";
1.630 -
1.631 -Goalw [dvd_def] "[| i dvd m; j dvd n|] ==> i*j dvd (m*n :: nat)";
1.632 -by (Clarify_tac 1);
1.633 -by (res_inst_tac [("x","k*ka")] exI 1);
1.634 -by (asm_simp_tac (simpset() addsimps mult_ac) 1);
1.635 -qed "mult_dvd_mono";
1.636 -
1.637 -Goalw [dvd_def] "(i*j :: nat) dvd k ==> i dvd k";
1.638 -by (full_simp_tac (simpset() addsimps [mult_assoc]) 1);
1.639 -by (Blast_tac 1);
1.640 -qed "dvd_mult_left";
1.641 -
1.642 -Goalw [dvd_def] "(i*j :: nat) dvd k ==> j dvd k";
1.643 -by (Clarify_tac 1);
1.644 -by (res_inst_tac [("x","i*k")] exI 1);
1.645 -by (simp_tac (simpset() addsimps mult_ac) 1);
1.646 -qed "dvd_mult_right";
1.647 -
1.648 -Goalw [dvd_def] "[| k dvd n; 0 < n |] ==> k <= (n::nat)";
1.649 -by (Clarify_tac 1);
1.650 -by (ALLGOALS (full_simp_tac (simpset() addsimps [zero_less_mult_iff])));
1.651 -by (etac conjE 1);
1.652 -by (rtac le_trans 1);
1.653 -by (rtac (le_refl RS mult_le_mono) 2);
1.654 -by (etac Suc_leI 2);
1.655 -by (Simp_tac 1);
1.656 -qed "dvd_imp_le";
1.657 -
1.658 -Goalw [dvd_def] "!!k::nat. (k dvd n) = (n mod k = 0)";
1.659 -by (div_undefined_case_tac "k=0" 1);
1.660 -by Safe_tac;
1.661 -by (asm_simp_tac (simpset() addsimps [mult_commute]) 1);
1.662 -by (res_inst_tac [("t","n"),("n1","k")] (mod_div_equality RS subst) 1);
1.663 -by (stac mult_commute 1);
1.664 -by (Asm_simp_tac 1);
1.665 -qed "dvd_eq_mod_eq_0";
1.666 -
1.667 -Goal "n dvd m ==> n * (m div n) = (m::nat)";
1.668 -by (subgoal_tac "m mod n = 0" 1);
1.669 - by (asm_full_simp_tac (simpset() addsimps [mult_div_cancel]) 1);
1.670 -by (asm_full_simp_tac (HOL_basic_ss addsimps [dvd_eq_mod_eq_0]) 1);
1.671 -qed "dvd_mult_div_cancel";
1.672 -
1.673 -Goal "(m mod d = 0) = (EX q::nat. m = d*q)";
1.674 -by (auto_tac (claset(),
1.675 -     simpset() addsimps [dvd_eq_mod_eq_0 RS sym, dvd_def]));
1.676 -qed "mod_eq_0_iff";
1.677 -AddSDs [mod_eq_0_iff RS iffD1];
1.678 -
1.679 -(*Loses information, namely we also have r<d provided d is nonzero*)
1.680 -Goal "(m mod d = r) ==> EX q::nat. m = r + q*d";
1.681 -by (cut_inst_tac [("m","m")] mod_div_equality 1);
1.682 -by (full_simp_tac (simpset() addsimps add_ac) 1);
1.683 -by (blast_tac (claset() addIs [sym]) 1);
1.684 -qed "mod_eqD";
1.685 -
```
```     2.1 --- a/src/HOL/Divides.thy	Wed May 15 11:51:20 2002 +0200
2.2 +++ b/src/HOL/Divides.thy	Wed May 15 13:49:51 2002 +0200
2.3 @@ -6,35 +6,33 @@
2.4  The division operators div, mod and the divides relation "dvd"
2.5  *)
2.6
2.7 -Divides = NatArith +
2.8 +theory Divides = NatArith files("Divides_lemmas.ML"):
2.9
2.10  (*We use the same class for div and mod;
2.11    moreover, dvd is defined whenever multiplication is*)
2.12  axclass
2.13    div < type
2.14
2.15 -instance  nat :: div
2.16 -instance  nat :: plus_ac0 (add_commute,add_assoc,add_0)
2.17 +instance  nat :: div ..
2.18 +instance  nat :: plus_ac0
2.19 +proof qed (rule add_commute add_assoc add_0)+
2.20
2.21  consts
2.22 -  div  :: ['a::div, 'a]  => 'a          (infixl 70)
2.23 -  mod  :: ['a::div, 'a]  => 'a          (infixl 70)
2.24 -  dvd  :: ['a::times, 'a] => bool       (infixl 50)
2.25 +  div  :: "'a::div \<Rightarrow> 'a \<Rightarrow> 'a"          (infixl 70)
2.26 +  mod  :: "'a::div \<Rightarrow> 'a \<Rightarrow> 'a"          (infixl 70)
2.27 +  dvd  :: "'a::times \<Rightarrow> 'a \<Rightarrow> bool"      (infixl 50)
2.28
2.29
2.30 -(*Remainder and quotient are defined here by algorithms and later proved to
2.31 -  satisfy the traditional definition (theorem mod_div_equality)
2.32 -*)
2.33  defs
2.34
2.35 -  mod_def   "m mod n == wfrec (trancl pred_nat)
2.36 +  mod_def:   "m mod n == wfrec (trancl pred_nat)
2.37                            (%f j. if j<n | n=0 then j else f (j-n)) m"
2.38
2.39 -  div_def   "m div n == wfrec (trancl pred_nat)
2.40 +  div_def:   "m div n == wfrec (trancl pred_nat)
2.41                            (%f j. if j<n | n=0 then 0 else Suc (f (j-n))) m"
2.42
2.43  (*The definition of dvd is polymorphic!*)
2.44 -  dvd_def   "m dvd n == EX k. n = m*k"
2.45 +  dvd_def:   "m dvd n == EX k. n = m*k"
2.46
2.47  (*This definition helps prove the harder properties of div and mod.
2.48    It is copied from IntDiv.thy; should it be overloaded?*)
2.49 @@ -44,4 +42,54 @@
2.50                        a = b*q + r &
2.51                        (if 0<b then 0<=r & r<b else b<r & r <=0)"
2.52
2.53 +use "Divides_lemmas.ML"
2.54 +
2.55 +lemma mod_div_equality2: "n * (m div n) + m mod n = (m::nat)"
2.56 +apply(insert mod_div_equality[of m n])
2.57 +apply(simp only:mult_ac)
2.58 +done
2.59 +
2.60 +lemma split_div:
2.61 +assumes m: "m \<noteq> 0"
2.62 +shows "P(n div m :: nat) = (!i. !j<m. n = m*i + j \<longrightarrow> P i)"
2.63 +       (is "?P = ?Q")
2.64 +proof
2.65 +  assume P: ?P
2.66 +  show ?Q
2.67 +  proof (intro allI impI)
2.68 +    fix i j
2.69 +    assume n: "n = m*i + j" and j: "j < m"
2.70 +    show "P i"
2.71 +    proof (cases)
2.72 +      assume "i = 0"
2.73 +      with n j P show "P i" by simp
2.74 +    next
2.75 +      assume "i \<noteq> 0"
2.76 +      with n j P show "P i" by (simp add:add_ac div_mult_self1)
2.77 +    qed
2.78 +  qed
2.79 +next
2.80 +  assume Q: ?Q
2.81 +  from m Q[THEN spec,of "n div m",THEN spec, of "n mod m"]
2.82 +  show ?P by(simp add:mod_div_equality2)
2.83 +qed
2.84 +
2.85 +lemma split_mod:
2.86 +assumes m: "m \<noteq> 0"
2.87 +shows "P(n mod m :: nat) = (!i. !j<m. n = m*i + j \<longrightarrow> P j)"
2.88 +       (is "?P = ?Q")
2.89 +proof
2.90 +  assume P: ?P
2.91 +  show ?Q
2.92 +  proof (intro allI impI)
2.93 +    fix i j
2.94 +    assume "n = m*i + j" "j < m"
2.95 +    thus "P j" using m P by(simp add:add_ac mult_ac)
2.96 +  qed
2.97 +next
2.98 +  assume Q: ?Q
2.99 +  from m Q[THEN spec,of "n div m",THEN spec, of "n mod m"]
2.100 +  show ?P by(simp add:mod_div_equality2)
2.101 +qed
2.102 +
2.103  end
```
```     3.1 --- a/src/HOL/IsaMakefile	Wed May 15 11:51:20 2002 +0200
3.2 +++ b/src/HOL/IsaMakefile	Wed May 15 13:49:51 2002 +0200
3.3 @@ -79,7 +79,7 @@
3.4    \$(SRC)/Provers/splitter.ML \$(SRC)/TFL/dcterm.ML \$(SRC)/TFL/post.ML \
3.5    \$(SRC)/TFL/rules.ML \$(SRC)/TFL/tfl.ML \$(SRC)/TFL/thms.ML \$(SRC)/TFL/thry.ML \
3.6    \$(SRC)/TFL/usyntax.ML \$(SRC)/TFL/utils.ML \
3.7 -  Datatype.thy Datatype_Universe.ML Datatype_Universe.thy Divides.ML \
3.8 +  Datatype.thy Datatype_Universe.ML Datatype_Universe.thy Divides_lemmas.ML \
3.9    Divides.thy Finite_Set.ML Finite_Set.thy Fun.ML Fun.thy Gfp.ML Gfp.thy \
3.10    Hilbert_Choice.thy Hilbert_Choice_lemmas.ML HOL.ML \
3.11    HOL.thy HOL_lemmas.ML Inductive.thy Integ/Bin.ML Integ/Bin.thy \
```