src/HOL/Arith.ML
 author paulson Tue May 20 11:37:57 1997 +0200 (1997-05-20) changeset 3234 503f4c8c29eb parent 2922 580647a879cf child 3293 c05f73cf3227 permissions -rw-r--r--
New theorems from Hoare/Arith2.ML
1 (*  Title:      HOL/Arith.ML
2     ID:         \$Id\$
3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
4     Copyright   1993  University of Cambridge
7 Some from the Hoare example from Norbert Galm
8 *)
10 open Arith;
12 (*** Basic rewrite rules for the arithmetic operators ***)
14 goalw Arith.thy [pred_def] "pred 0 = 0";
15 by(Simp_tac 1);
16 qed "pred_0";
18 goalw Arith.thy [pred_def] "pred(Suc n) = n";
19 by(Simp_tac 1);
20 qed "pred_Suc";
24 (** pred **)
26 val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n";
27 by (res_inst_tac [("n","n")] natE 1);
28 by (cut_facts_tac prems 1);
29 by (ALLGOALS Asm_full_simp_tac);
30 qed "Suc_pred";
33 (** Difference **)
35 qed_goalw "diff_0_eq_0" Arith.thy [pred_def]
36     "0 - n = 0"
37  (fn _ => [nat_ind_tac "n" 1,  ALLGOALS Asm_simp_tac]);
39 (*Must simplify BEFORE the induction!!  (Else we get a critical pair)
40   Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
41 qed_goalw "diff_Suc_Suc" Arith.thy [pred_def]
42     "Suc(m) - Suc(n) = m - n"
43  (fn _ =>
44   [Simp_tac 1, nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]);
49 goal Arith.thy "!!k. 0<k ==> EX j. k = Suc(j)";
50 by (etac rev_mp 1);
51 by (nat_ind_tac "k" 1);
52 by (Simp_tac 1);
53 by (Blast_tac 1);
54 val lemma = result();
56 (* [| 0 < k; !!j. [| j: nat; k = succ(j) |] ==> Q |] ==> Q *)
57 bind_thm ("zero_less_natE", lemma RS exE);
61 (**** Inductive properties of the operators ****)
65 qed_goal "add_0_right" Arith.thy "m + 0 = m"
66  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
68 qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)"
69  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
74 qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)"
75  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
78 qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)"
79  (fn _ =>  [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
82  (fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1,
83            rtac (add_commute RS arg_cong) 1]);
88 goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)";
89 by (nat_ind_tac "k" 1);
90 by (Simp_tac 1);
91 by (Asm_simp_tac 1);
94 goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)";
95 by (nat_ind_tac "k" 1);
96 by (Simp_tac 1);
97 by (Asm_simp_tac 1);
100 goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)";
101 by (nat_ind_tac "k" 1);
102 by (Simp_tac 1);
103 by (Asm_simp_tac 1);
106 goal Arith.thy "!!k::nat. (k + m < k + n) = (m<n)";
107 by (nat_ind_tac "k" 1);
108 by (Simp_tac 1);
109 by (Asm_simp_tac 1);
115 goal Arith.thy "(m+n = 0) = (m=0 & n=0)";
116 by (nat_ind_tac "m" 1);
117 by (ALLGOALS Asm_simp_tac);
121 goal Arith.thy "!!n. n ~= 0 ==> m + pred n = pred(m+n)";
122 by (nat_ind_tac "m" 1);
123 by (ALLGOALS Asm_simp_tac);
130 goal Arith.thy "? k::nat. n = n+k";
131 by (res_inst_tac [("x","0")] exI 1);
132 by (Simp_tac 1);
133 val lemma = result();
135 goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))";
136 by (nat_ind_tac "n" 1);
137 by (ALLGOALS (simp_tac (!simpset addsimps [less_Suc_eq])));
138 by (step_tac (!claset addSIs [lemma]) 1);
139 by (res_inst_tac [("x","Suc(k)")] exI 1);
140 by (Simp_tac 1);
143 goal Arith.thy "n <= ((m + n)::nat)";
144 by (nat_ind_tac "m" 1);
145 by (ALLGOALS Simp_tac);
146 by (etac le_trans 1);
147 by (rtac (lessI RS less_imp_le) 1);
150 goal Arith.thy "n <= ((n + m)::nat)";
158 (*"i <= j ==> i <= j+m"*)
161 (*"i <= j ==> i <= m+j"*)
164 (*"i < j ==> i < j+m"*)
167 (*"i < j ==> i < m+j"*)
170 goal Arith.thy "!!i. i+j < (k::nat) ==> i<k";
171 by (etac rev_mp 1);
172 by (nat_ind_tac "j" 1);
173 by (ALLGOALS Asm_simp_tac);
174 by (blast_tac (!claset addDs [Suc_lessD]) 1);
177 goal Arith.thy "!!i::nat. ~ (i+j < i)";
178 br notI 1;
179 be (add_lessD1 RS less_irrefl) 1;
182 goal Arith.thy "!!i::nat. ~ (j+i < i)";
187 goal Arith.thy "!!k::nat. m <= n ==> m <= n+k";
188 by (etac le_trans 1);
192 goal Arith.thy "!!k::nat. m < n ==> m < n+k";
193 by (etac less_le_trans 1);
197 goal Arith.thy "m+k<=n --> m<=(n::nat)";
198 by (nat_ind_tac "k" 1);
199 by (ALLGOALS Asm_simp_tac);
200 by (blast_tac (!claset addDs [Suc_leD]) 1);
203 goal Arith.thy "!!n::nat. m+k<=n ==> k<=n";
208 goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n";
210 bind_thm ("add_leE", result() RS conjE);
212 goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n";
214 by (asm_full_simp_tac
217 by (etac subst 1);
222 (*** Monotonicity of Addition ***)
224 (*strict, in 1st argument*)
225 goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k";
226 by (nat_ind_tac "k" 1);
227 by (ALLGOALS Asm_simp_tac);
230 (*strict, in both arguments*)
231 goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l";
232 by (rtac (add_less_mono1 RS less_trans) 1);
233 by (REPEAT (assume_tac 1));
234 by (nat_ind_tac "j" 1);
235 by (ALLGOALS Asm_simp_tac);
238 (*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
239 val [lt_mono,le] = goal Arith.thy
240      "[| !!i j::nat. i<j ==> f(i) < f(j);       \
241 \        i <= j                                 \
242 \     |] ==> f(i) <= (f(j)::nat)";
243 by (cut_facts_tac [le] 1);
244 by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
245 by (blast_tac (!claset addSIs [lt_mono]) 1);
246 qed "less_mono_imp_le_mono";
248 (*non-strict, in 1st argument*)
249 goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k";
250 by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1);
252 by (assume_tac 1);
255 (*non-strict, in both arguments*)
256 goal Arith.thy "!!k l::nat. [|i<=j;  k<=l |] ==> i + k <= j + l";
257 by (etac (add_le_mono1 RS le_trans) 1);
259 (*j moves to the end because it is free while k, l are bound*)
264 (*** Multiplication ***)
266 (*right annihilation in product*)
267 qed_goal "mult_0_right" Arith.thy "m * 0 = 0"
268  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
270 (*right Sucessor law for multiplication*)
271 qed_goal "mult_Suc_right" Arith.thy  "m * Suc(n) = m + (m * n)"
272  (fn _ => [nat_ind_tac "m" 1,
277 goal Arith.thy "1 * n = n";
278 by (Asm_simp_tac 1);
279 qed "mult_1";
281 goal Arith.thy "n * 1 = n";
282 by (Asm_simp_tac 1);
283 qed "mult_1_right";
285 (*Commutative law for multiplication*)
286 qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)"
287  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
290 qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)"
291  (fn _ => [nat_ind_tac "m" 1,
294 qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)"
295  (fn _ => [nat_ind_tac "m" 1,
298 (*Associative law for multiplication*)
299 qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)"
300   (fn _ => [nat_ind_tac "m" 1,
303 qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)"
304  (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
305            rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
307 val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
310 (*** Difference ***)
312 qed_goal "pred_Suc_diff" Arith.thy "pred(Suc m - n) = m - n"
313  (fn _ => [nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]);
316 qed_goal "diff_self_eq_0" Arith.thy "m - m = 0"
317  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
320 (*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
321 val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)";
322 by (rtac (prem RS rev_mp) 1);
323 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
324 by (ALLGOALS (Asm_simp_tac));
327 Delsimps  [diff_Suc];
330 (*** More results about difference ***)
332 goal Arith.thy "m - n < Suc(m)";
333 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
334 by (etac less_SucE 3);
335 by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq])));
336 qed "diff_less_Suc";
338 goal Arith.thy "!!m::nat. m - n <= m";
339 by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
340 by (ALLGOALS Asm_simp_tac);
341 qed "diff_le_self";
343 goal Arith.thy "!!n::nat. (n+m) - n = m";
344 by (nat_ind_tac "n" 1);
345 by (ALLGOALS Asm_simp_tac);
349 goal Arith.thy "!!n::nat.(m+n) - n = m";
350 by (res_inst_tac [("m1","m")] (add_commute RS ssubst) 1);
351 by (REPEAT (ares_tac [diff_add_inverse] 1));
355 val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0";
356 by (rtac (prem RS rev_mp) 1);
357 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
358 by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
359 by (ALLGOALS (Asm_simp_tac));
360 qed "less_imp_diff_is_0";
362 val prems = goal Arith.thy "m-n = 0  -->  n-m = 0  -->  m=n";
363 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
364 by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
365 qed_spec_mp "diffs0_imp_equal";
367 val [prem] = goal Arith.thy "m<n ==> 0<n-m";
368 by (rtac (prem RS rev_mp) 1);
369 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
370 by (ALLGOALS (Asm_simp_tac));
371 qed "less_imp_diff_positive";
373 val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
374 by (rtac (prem RS rev_mp) 1);
375 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
376 by (ALLGOALS (Asm_simp_tac));
377 qed "Suc_diff_n";
379 goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
380 by (simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]
381                     setloop (split_tac [expand_if])) 1);
382 qed "if_Suc_diff_n";
384 goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
385 by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
386 by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o Blast_tac));
387 qed "zero_induct_lemma";
389 val prems = goal Arith.thy "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
390 by (rtac (diff_self_eq_0 RS subst) 1);
391 by (rtac (zero_induct_lemma RS mp RS mp) 1);
392 by (REPEAT (ares_tac ([impI,allI]@prems) 1));
393 qed "zero_induct";
395 goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n";
396 by (nat_ind_tac "k" 1);
397 by (ALLGOALS Asm_simp_tac);
398 qed "diff_cancel";
401 goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n";
404 qed "diff_cancel2";
407 (*From Clemens Ballarin*)
408 goal Arith.thy "!!n::nat. [| k<=n; n<=m |] ==> (m-k) - (n-k) = m-n";
409 by (subgoal_tac "k<=n --> n<=m --> (m-k) - (n-k) = m-n" 1);
410 by (Asm_full_simp_tac 1);
411 by (nat_ind_tac "k" 1);
412 by (Simp_tac 1);
413 (* Induction step *)
414 by (subgoal_tac "Suc na <= m --> n <= m --> Suc na <= n --> \
415 \                Suc (m - Suc na) - Suc (n - Suc na) = m-n" 1);
416 by (Asm_full_simp_tac 1);
417 by (blast_tac (!claset addIs [le_trans]) 1);
418 by (auto_tac (!claset addIs [Suc_leD], !simpset delsimps [diff_Suc_Suc]));
419 by (asm_full_simp_tac (!simpset delsimps [Suc_less_eq]
420 		       addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
421 qed "diff_right_cancel";
423 goal Arith.thy "!!n::nat. n - (n+m) = 0";
424 by (nat_ind_tac "n" 1);
425 by (ALLGOALS Asm_simp_tac);
429 (** Difference distributes over multiplication **)
431 goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)";
432 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
433 by (ALLGOALS Asm_simp_tac);
434 qed "diff_mult_distrib" ;
436 goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)";
437 val mult_commute_k = read_instantiate [("m","k")] mult_commute;
438 by (simp_tac (!simpset addsimps [diff_mult_distrib, mult_commute_k]) 1);
439 qed "diff_mult_distrib2" ;
440 (*NOT added as rewrites, since sometimes they are used from right-to-left*)
443 (** Less-then properties **)
445 (*In ordinary notation: if 0<n and n<=m then m-n < m *)
446 goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m";
447 by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
448 by (Blast_tac 1);
449 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
451 qed "diff_less";
453 val wf_less_trans = [eq_reflection, wf_pred_nat RS wf_trancl] MRS
454                     def_wfrec RS trans;
456 goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)";
457 by (rtac refl 1);
458 qed "less_eq";
460 (*** Remainder ***)
462 goal Arith.thy "(%m. m mod n) = wfrec (trancl pred_nat) \
463              \                      (%f j. if j<n then j else f (j-n))";
464 by (simp_tac (!simpset addsimps [mod_def]) 1);
465 qed "mod_eq";
467 goal Arith.thy "!!m. m<n ==> m mod n = m";
468 by (rtac (mod_eq RS wf_less_trans) 1);
469 by (Asm_simp_tac 1);
470 qed "mod_less";
472 goal Arith.thy "!!m. [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n";
473 by (rtac (mod_eq RS wf_less_trans) 1);
474 by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
475 qed "mod_geq";
477 goal thy "!!n. 0<n ==> n mod n = 0";
478 by (rtac (mod_eq RS wf_less_trans) 1);
479 by (asm_simp_tac (!simpset addsimps [mod_less, diff_self_eq_0,
480 				     cut_def, less_eq]) 1);
481 qed "mod_nn_is_0";
483 goal thy "!!n. 0<n ==> (m+n) mod n = m mod n";
484 by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1);
485 by (stac (mod_geq RS sym) 2);
489 goal thy "!!n. 0<n ==> m*n mod n = 0";
490 by (nat_ind_tac "m" 1);
491 by (asm_simp_tac (!simpset addsimps [mod_less]) 1);
492 by (dres_inst_tac [("m","m*n")] mod_eq_add 1);
494 qed "mod_prod_nn_is_0";
497 (*** Quotient ***)
499 goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \
500                         \            (%f j. if j<n then 0 else Suc (f (j-n)))";
501 by (simp_tac (!simpset addsimps [div_def]) 1);
502 qed "div_eq";
504 goal Arith.thy "!!m. m<n ==> m div n = 0";
505 by (rtac (div_eq RS wf_less_trans) 1);
506 by (Asm_simp_tac 1);
507 qed "div_less";
509 goal Arith.thy "!!M. [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
510 by (rtac (div_eq RS wf_less_trans) 1);
511 by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
512 qed "div_geq";
514 (*Main Result about quotient and remainder.*)
515 goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m";
516 by (res_inst_tac [("n","m")] less_induct 1);
517 by (rename_tac "k" 1);    (*Variable name used in line below*)
518 by (case_tac "k<n" 1);
520                        [mod_less, mod_geq, div_less, div_geq,
522 qed "mod_div_equality";
525 (*** Further facts about mod (mainly for mutilated checkerboard ***)
527 goal Arith.thy
528     "!!m n. 0<n ==> \
529 \           Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))";
530 by (res_inst_tac [("n","m")] less_induct 1);
531 by (excluded_middle_tac "Suc(na)<n" 1);
532 (* case Suc(na) < n *)
533 by (forward_tac [lessI RS less_trans] 2);
534 by (asm_simp_tac (!simpset addsimps [mod_less, less_not_refl2 RS not_sym]) 2);
535 (* case n <= Suc(na) *)
536 by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, mod_geq]) 1);
537 by (etac (le_imp_less_or_eq RS disjE) 1);
538 by (asm_simp_tac (!simpset addsimps [Suc_diff_n]) 1);
539 by (asm_full_simp_tac (!simpset addsimps [not_less_eq RS sym,
540                                           diff_less, mod_geq]) 1);
541 by (asm_simp_tac (!simpset addsimps [mod_less]) 1);
542 qed "mod_Suc";
544 goal Arith.thy "!!m n. 0<n ==> m mod n < n";
545 by (res_inst_tac [("n","m")] less_induct 1);
546 by (excluded_middle_tac "na<n" 1);
547 (*case na<n*)
548 by (asm_simp_tac (!simpset addsimps [mod_less]) 2);
549 (*case n le na*)
550 by (asm_full_simp_tac (!simpset addsimps [mod_geq, diff_less]) 1);
551 qed "mod_less_divisor";
554 (** Evens and Odds **)
556 (*With less_zeroE, causes case analysis on b<2*)
559 goal thy "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)";
560 by (subgoal_tac "k mod 2 < 2" 1);
561 by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
562 by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1);
563 by (Blast_tac 1);
564 qed "mod2_cases";
566 goal thy "Suc(Suc(m)) mod 2 = m mod 2";
567 by (subgoal_tac "m mod 2 < 2" 1);
568 by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
569 by (Step_tac 1);
570 by (ALLGOALS (asm_simp_tac (!simpset addsimps [mod_Suc])));
571 qed "mod2_Suc_Suc";
574 goal thy "(m+m) mod 2 = 0";
575 by (nat_ind_tac "m" 1);
576 by (simp_tac (!simpset addsimps [mod_less]) 1);
581 Delrules [less_SucE];
584 (*** Monotonicity of Multiplication ***)
586 goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k";
587 by (nat_ind_tac "k" 1);
589 qed "mult_le_mono1";
591 (*<=monotonicity, BOTH arguments*)
592 goal Arith.thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l";
593 by (etac (mult_le_mono1 RS le_trans) 1);
594 by (rtac le_trans 1);
595 by (stac mult_commute 2);
596 by (etac mult_le_mono1 2);
597 by (simp_tac (!simpset addsimps [mult_commute]) 1);
598 qed "mult_le_mono";
600 (*strict, in 1st argument; proof is by induction on k>0*)
601 goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
602 by (etac zero_less_natE 1);
603 by (Asm_simp_tac 1);
604 by (nat_ind_tac "x" 1);
606 qed "mult_less_mono2";
608 goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> i*k < j*k";
609 bd mult_less_mono2 1;
610 by (ALLGOALS (asm_full_simp_tac (!simpset addsimps [mult_commute])));
611 qed "mult_less_mono1";
613 goal Arith.thy "(0 < m*n) = (0<m & 0<n)";
614 by (nat_ind_tac "m" 1);
615 by (nat_ind_tac "n" 2);
616 by (ALLGOALS Asm_simp_tac);
617 qed "zero_less_mult_iff";
619 goal Arith.thy "(m*n = 1) = (m=1 & n=1)";
620 by (nat_ind_tac "m" 1);
621 by (Simp_tac 1);
622 by (nat_ind_tac "n" 1);
623 by (Simp_tac 1);
624 by (fast_tac (!claset addss !simpset) 1);
625 qed "mult_eq_1_iff";
627 goal Arith.thy "!!k. 0<k ==> (m*k < n*k) = (m<n)";
628 by (safe_tac (!claset addSIs [mult_less_mono1]));
629 by (cut_facts_tac [less_linear] 1);
631 qed "mult_less_cancel2";
633 goal Arith.thy "!!k. 0<k ==> (k*m < k*n) = (m<n)";
634 bd mult_less_cancel2 1;
635 by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1);
636 qed "mult_less_cancel1";
639 goal Arith.thy "!!k. 0<k ==> (m*k = n*k) = (m=n)";
640 by (cut_facts_tac [less_linear] 1);
641 by(Step_tac 1);
642 ba 2;
643 by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac));
644 by (ALLGOALS Asm_full_simp_tac);
645 qed "mult_cancel2";
647 goal Arith.thy "!!k. 0<k ==> (k*m = k*n) = (m=n)";
648 bd mult_cancel2 1;
649 by (asm_full_simp_tac (!simpset addsimps [mult_commute]) 1);
650 qed "mult_cancel1";
654 (*** More division laws ***)
656 goal thy "!!n. 0<n ==> m*n div n = m";
657 by (cut_inst_tac [("m", "m*n")] mod_div_equality 1);
658 ba 1;
659 by (asm_full_simp_tac (!simpset addsimps [mod_prod_nn_is_0]) 1);
660 qed "div_prod_nn_is_m";
663 (*Cancellation law for division*)
664 goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) div (k*n) = m div n";
665 by (res_inst_tac [("n","m")] less_induct 1);
666 by (case_tac "na<n" 1);
667 by (asm_simp_tac (!simpset addsimps [div_less, zero_less_mult_iff,
668                                      mult_less_mono2]) 1);
669 by (subgoal_tac "~ k*na < k*n" 1);
670 by (asm_simp_tac
672                          diff_mult_distrib2 RS sym, diff_less]) 1);
673 by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le,
674                                           le_refl RS mult_le_mono]) 1);
675 qed "div_cancel";
678 goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) mod (k*n) = k * (m mod n)";
679 by (res_inst_tac [("n","m")] less_induct 1);
680 by (case_tac "na<n" 1);
681 by (asm_simp_tac (!simpset addsimps [mod_less, zero_less_mult_iff,
682                                      mult_less_mono2]) 1);
683 by (subgoal_tac "~ k*na < k*n" 1);
684 by (asm_simp_tac
686                          diff_mult_distrib2 RS sym, diff_less]) 1);
687 by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le,
688                                           le_refl RS mult_le_mono]) 1);
689 qed "mult_mod_distrib";
692 (** Lemma for gcd **)
694 goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0";
695 by (dtac sym 1);
696 by (rtac disjCI 1);
697 by (rtac nat_less_cases 1 THEN assume_tac 2);
699 by (best_tac (!claset addDs [mult_less_mono2]
701 qed "mult_eq_self_implies_10";
704 (*** Subtraction laws -- from Clemens Ballarin ***)
706 goal Arith.thy "!! a b c::nat. [| a < b; c <= a |] ==> a-c < b-c";
707 by (subgoal_tac "c+(a-c) < c+(b-c)" 1);
708 by (Asm_full_simp_tac 1);
709 by (subgoal_tac "c <= b" 1);
710 by (blast_tac (!claset addIs [less_imp_le, le_trans]) 2);
712 qed "diff_less_mono";
714 goal Arith.thy "!! a b c::nat. a+b < c ==> a < c-b";
715 bd diff_less_mono 1;
717 by (Asm_full_simp_tac 1);
720 goal Arith.thy "!! n. n <= m ==> Suc m - n = Suc (m - n)";
721 br Suc_diff_n 1;
722 by (asm_full_simp_tac (!simpset addsimps [le_eq_less_Suc]) 1);
723 qed "Suc_diff_le";
725 goal Arith.thy "!! n. Suc i <= n ==> Suc (n - Suc i) = n - i";
726 by (asm_full_simp_tac
727     (!simpset addsimps [Suc_diff_n RS sym, le_eq_less_Suc]) 1);
728 qed "Suc_diff_Suc";
730 goal Arith.thy "!! i::nat. i <= n ==> n - (n - i) = i";
731 by (subgoal_tac "(n-i) + (n - (n-i)) = (n-i) + i" 1);
732 by (Asm_full_simp_tac 1);