src/HOL/Arith.ML
 author nipkow Fri Oct 16 17:32:06 1998 +0200 (1998-10-16) changeset 5654 8b872d546b9e parent 5604 cd17004d09e1 child 5758 27a2b36efd95 permissions -rw-r--r--
Installed trans_tac in solver of simpset().
1 (*  Title:      HOL/Arith.ML
2     ID:         \$Id\$
3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
4     Copyright   1998  University of Cambridge
7 Some from the Hoare example from Norbert Galm
8 *)
10 (*** Basic rewrite rules for the arithmetic operators ***)
13 (** Difference **)
15 qed_goal "diff_0_eq_0" thy
16     "0 - n = 0"
17  (fn _ => [induct_tac "n" 1,  ALLGOALS Asm_simp_tac]);
19 (*Must simplify BEFORE the induction!  (Else we get a critical pair)
20   Suc(m) - Suc(n)   rewrites to   pred(Suc(m) - n)  *)
21 qed_goal "diff_Suc_Suc" thy
22     "Suc(m) - Suc(n) = m - n"
23  (fn _ =>
24   [Simp_tac 1, induct_tac "n" 1, ALLGOALS Asm_simp_tac]);
28 (* Could be (and is, below) generalized in various ways;
29    However, none of the generalizations are currently in the simpset,
30    and I dread to think what happens if I put them in *)
31 Goal "0 < n ==> Suc(n-1) = n";
32 by (asm_simp_tac (simpset() addsplits [nat.split]) 1);
33 qed "Suc_pred";
36 Delsimps [diff_Suc];
39 (**** Inductive properties of the operators ****)
43 qed_goal "add_0_right" thy "m + 0 = m"
44  (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
46 qed_goal "add_Suc_right" thy "m + Suc(n) = Suc(m+n)"
47  (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
52 qed_goal "add_assoc" thy "(m + n) + k = m + ((n + k)::nat)"
53  (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
56 qed_goal "add_commute" thy "m + n = n + (m::nat)"
57  (fn _ =>  [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
60  (fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1,
61            rtac (add_commute RS arg_cong) 1]);
66 Goal "(k + m = k + n) = (m=(n::nat))";
67 by (induct_tac "k" 1);
68 by (Simp_tac 1);
69 by (Asm_simp_tac 1);
72 Goal "(m + k = n + k) = (m=(n::nat))";
73 by (induct_tac "k" 1);
74 by (Simp_tac 1);
75 by (Asm_simp_tac 1);
78 Goal "(k + m <= k + n) = (m<=(n::nat))";
79 by (induct_tac "k" 1);
80 by (Simp_tac 1);
81 by (Asm_simp_tac 1);
84 Goal "(k + m < k + n) = (m<(n::nat))";
85 by (induct_tac "k" 1);
86 by (Simp_tac 1);
87 by (Asm_simp_tac 1);
93 (** Reasoning about m+0=0, etc. **)
95 Goal "(m+n = 0) = (m=0 & n=0)";
96 by (exhaust_tac "m" 1);
97 by (Auto_tac);
101 Goal "(0 = m+n) = (m=0 & n=0)";
102 by (exhaust_tac "m" 1);
103 by (Auto_tac);
107 Goal "(m+n=1) = (m=1 & n=0 | m=0 & n=1)";
108 by(exhaust_tac "m" 1);
109 by(Auto_tac);
112 Goal "(1=m+n) = (m=1 & n=0 | m=0 & n=1)";
113 by(exhaust_tac "m" 1);
114 by(Auto_tac);
117 Goal "(0<m+n) = (0<m | 0<n)";
118 by (simp_tac (simpset() delsimps [neq0_conv] addsimps [neq0_conv RS sym]) 1);
122 (* FIXME: really needed?? *)
123 Goal "((m+n)-1 = 0) = (m=0 & n-1 = 0 | m-1 = 0 & n=0)";
124 by (exhaust_tac "m" 1);
125 by (ALLGOALS (fast_tac (claset() addss (simpset()))));
129 (* Could be generalized, eg to "k<n ==> m+(n-(Suc k)) = (m+n)-(Suc k)" *)
130 Goal "0<n ==> m + (n-1) = (m+n)-1";
131 by (exhaust_tac "m" 1);
132 by (ALLGOALS (asm_simp_tac (simpset() addsimps [diff_Suc]
137 Goal "m + n = m ==> n = 0";
138 by (dtac (add_0_right RS ssubst) 1);
147 Goal "m<n --> (? k. n=Suc(m+k))";
148 by (induct_tac "n" 1);
149 by (ALLGOALS (simp_tac (simpset() addsimps [order_le_less])));
150 by (blast_tac (claset() addSEs [less_SucE]
154 Goal "n <= ((m + n)::nat)";
155 by (induct_tac "m" 1);
156 by (ALLGOALS Simp_tac);
159 Goal "n <= ((n + m)::nat)";
167 Goal "(m<n) = (? k. n=Suc(m+k))";
172 (*"i <= j ==> i <= j+m"*)
175 (*"i <= j ==> i <= m+j"*)
178 (*"i < j ==> i < j+m"*)
181 (*"i < j ==> i < m+j"*)
184 Goal "i+j < (k::nat) --> i<k";
185 by (induct_tac "j" 1);
186 by (ALLGOALS Asm_simp_tac);
189 Goal "~ (i+j < (i::nat))";
190 by (rtac notI 1);
191 by (etac (add_lessD1 RS less_irrefl) 1);
194 Goal "~ (j+i < (i::nat))";
199 Goal "m+k<=n --> m<=(n::nat)";
200 by (induct_tac "k" 1);
201 by (ALLGOALS (asm_simp_tac (simpset() addsimps le_simps)));
204 Goal "m+k<=n ==> k<=(n::nat)";
209 Goal "m+k<=n ==> m<=n & k<=(n::nat)";
211 bind_thm ("add_leE", result() RS conjE);
213 (*needs !!k for add_ac to work*)
214 Goal "!!k:: nat. [| k<l;  m+l = k+n |] ==> m<n";
215 by (auto_tac (claset(),
222 (*** Monotonicity of Addition ***)
224 (*strict, in 1st argument*)
225 Goal "i < j ==> i + k < j + (k::nat)";
226 by (induct_tac "k" 1);
227 by (ALLGOALS Asm_simp_tac);
230 (*strict, in both arguments*)
231 Goal "[|i < j; k < l|] ==> i + k < j + (l::nat)";
232 by (rtac (add_less_mono1 RS less_trans) 1);
233 by (REPEAT (assume_tac 1));
234 by (induct_tac "j" 1);
235 by (ALLGOALS Asm_simp_tac);
238 (*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
239 val [lt_mono,le] = Goal
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 [order_le_less]) 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 "i<=j ==> i + k <= j + (k::nat)";
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 "[|i<=j;  k<=l |] ==> i + k <= j + (l::nat)";
257 by (etac (add_le_mono1 RS le_trans) 1);
262 (*** Multiplication ***)
264 (*right annihilation in product*)
265 qed_goal "mult_0_right" thy "m * 0 = 0"
266  (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
268 (*right successor law for multiplication*)
269 qed_goal "mult_Suc_right" thy  "m * Suc(n) = m + (m * n)"
270  (fn _ => [induct_tac "m" 1,
275 Goal "1 * n = n";
276 by (Asm_simp_tac 1);
277 qed "mult_1";
279 Goal "n * 1 = n";
280 by (Asm_simp_tac 1);
281 qed "mult_1_right";
283 (*Commutative law for multiplication*)
284 qed_goal "mult_commute" thy "m * n = n * (m::nat)"
285  (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
288 qed_goal "add_mult_distrib" thy "(m + n)*k = (m*k) + ((n*k)::nat)"
289  (fn _ => [induct_tac "m" 1,
292 qed_goal "add_mult_distrib2" thy "k*(m + n) = (k*m) + ((k*n)::nat)"
293  (fn _ => [induct_tac "m" 1,
296 (*Associative law for multiplication*)
297 qed_goal "mult_assoc" thy "(m * n) * k = m * ((n * k)::nat)"
298   (fn _ => [induct_tac "m" 1,
301 qed_goal "mult_left_commute" thy "x*(y*z) = y*((x*z)::nat)"
302  (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
303            rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
305 val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
307 Goal "(m*n = 0) = (m=0 | n=0)";
308 by (induct_tac "m" 1);
309 by (induct_tac "n" 2);
310 by (ALLGOALS Asm_simp_tac);
311 qed "mult_is_0";
314 Goal "m <= m*(m::nat)";
315 by (induct_tac "m" 1);
317 by (etac (le_add2 RSN (2,le_trans)) 1);
318 qed "le_square";
321 (*** Difference ***)
324 qed_goal "diff_self_eq_0" thy "m - m = 0"
325  (fn _ => [induct_tac "m" 1, ALLGOALS Asm_simp_tac]);
328 (*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
329 Goal "~ m<n --> n+(m-n) = (m::nat)";
330 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
331 by (ALLGOALS Asm_simp_tac);
334 Goal "n<=m ==> n+(m-n) = (m::nat)";
338 Goal "n<=m ==> (m-n)+n = (m::nat)";
345 (*** More results about difference ***)
347 Goal "n <= m ==> Suc(m)-n = Suc(m-n)";
348 by (etac rev_mp 1);
349 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
350 by (ALLGOALS Asm_simp_tac);
351 qed "Suc_diff_le";
353 Goal "n<=(l::nat) --> Suc l - n + m = Suc (l - n + m)";
354 by (res_inst_tac [("m","n"),("n","l")] diff_induct 1);
355 by (ALLGOALS Asm_simp_tac);
358 Goal "m - n < Suc(m)";
359 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
360 by (etac less_SucE 3);
361 by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq])));
362 qed "diff_less_Suc";
364 Goal "m - n <= (m::nat)";
365 by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
366 by (ALLGOALS Asm_simp_tac);
367 qed "diff_le_self";
370 (* j<k ==> j-n < k *)
371 bind_thm ("less_imp_diff_less", diff_le_self RS le_less_trans);
373 Goal "!!i::nat. i-j-k = i - (j+k)";
374 by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
375 by (ALLGOALS Asm_simp_tac);
376 qed "diff_diff_left";
378 Goal "(Suc m - n) - Suc k = m - n - k";
379 by (simp_tac (simpset() addsimps [diff_diff_left]) 1);
380 qed "Suc_diff_diff";
383 Goal "0<n ==> n - Suc i < n";
384 by (exhaust_tac "n" 1);
385 by Safe_tac;
386 by (asm_simp_tac (simpset() addsimps le_simps) 1);
387 qed "diff_Suc_less";
390 Goal "i<n ==> n - Suc i < n - i";
391 by (exhaust_tac "n" 1);
392 by (auto_tac (claset(),
394 qed "diff_Suc_less_diff";
396 (*This and the next few suggested by Florian Kammueller*)
397 Goal "!!i::nat. i-j-k = i-k-j";
399 qed "diff_commute";
401 Goal "k<=j --> j<=i --> i - (j - k) = i - j + (k::nat)";
402 by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
403 by (ALLGOALS Asm_simp_tac);
404 by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1);
405 qed_spec_mp "diff_diff_right";
407 Goal "k <= (j::nat) --> (i + j) - k = i + (j - k)";
408 by (res_inst_tac [("m","j"),("n","k")] diff_induct 1);
409 by (ALLGOALS Asm_simp_tac);
412 Goal "k <= (j::nat) --> (j + i) - k = i + (j - k)";
416 Goal "(n+m) - n = (m::nat)";
417 by (induct_tac "n" 1);
418 by (ALLGOALS Asm_simp_tac);
422 Goal "(m+n) - n = (m::nat)";
427 Goal "i <= (j::nat) ==> (j-i=k) = (j=k+i)";
428 by Safe_tac;
429 by (ALLGOALS Asm_simp_tac);
432 Goal "(m-n = 0) = (m <= n)";
433 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
434 by (ALLGOALS Asm_simp_tac);
435 qed "diff_is_0_eq";
438 Goal "m-n = 0  -->  n-m = 0  -->  m=n";
439 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
440 by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
441 qed_spec_mp "diffs0_imp_equal";
443 Goal "(0<n-m) = (m<n)";
444 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
445 by (ALLGOALS Asm_simp_tac);
446 qed "zero_less_diff";
449 Goal "i < j  ==> ? k. 0<k & i+k = j";
450 by (res_inst_tac [("x","j - i")] exI 1);
454 Goal "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
455 by (simp_tac (simpset() addsimps [leI, Suc_le_eq, Suc_diff_le]) 1);
456 qed "if_Suc_diff_le";
458 Goal "Suc(m)-n <= Suc(m-n)";
459 by (simp_tac (simpset() addsimps [if_Suc_diff_le]) 1);
460 qed "diff_Suc_le_Suc_diff";
462 Goal "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
463 by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
464 by (ALLGOALS (Clarify_tac THEN' Simp_tac THEN' TRY o Blast_tac));
465 qed "zero_induct_lemma";
467 val prems = Goal "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
468 by (rtac (diff_self_eq_0 RS subst) 1);
469 by (rtac (zero_induct_lemma RS mp RS mp) 1);
470 by (REPEAT (ares_tac ([impI,allI]@prems) 1));
471 qed "zero_induct";
473 Goal "(k+m) - (k+n) = m - (n::nat)";
474 by (induct_tac "k" 1);
475 by (ALLGOALS Asm_simp_tac);
476 qed "diff_cancel";
479 Goal "(m+k) - (n+k) = m - (n::nat)";
482 qed "diff_cancel2";
485 (*From Clemens Ballarin, proof by lcp*)
486 Goal "[| k<=n; n<=m |] ==> (m-k) - (n-k) = m-(n::nat)";
487 by (REPEAT (etac rev_mp 1));
488 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
489 by (ALLGOALS Asm_simp_tac);
490 (*a confluence problem*)
491 by (asm_simp_tac (simpset() addsimps [Suc_diff_le, le_Suc_eq]) 1);
492 qed "diff_right_cancel";
494 Goal "n - (n+m) = 0";
495 by (induct_tac "n" 1);
496 by (ALLGOALS Asm_simp_tac);
501 (** Difference distributes over multiplication **)
503 Goal "!!m::nat. (m - n) * k = (m * k) - (n * k)";
504 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
505 by (ALLGOALS Asm_simp_tac);
506 qed "diff_mult_distrib" ;
508 Goal "!!m::nat. k * (m - n) = (k * m) - (k * n)";
509 val mult_commute_k = read_instantiate [("m","k")] mult_commute;
510 by (simp_tac (simpset() addsimps [diff_mult_distrib, mult_commute_k]) 1);
511 qed "diff_mult_distrib2" ;
512 (*NOT added as rewrites, since sometimes they are used from right-to-left*)
515 (*** Monotonicity of Multiplication ***)
517 Goal "i <= (j::nat) ==> i*k<=j*k";
518 by (induct_tac "k" 1);
520 qed "mult_le_mono1";
522 (*<=monotonicity, BOTH arguments*)
523 Goal "[| i <= (j::nat); k <= l |] ==> i*k <= j*l";
524 by (etac (mult_le_mono1 RS le_trans) 1);
525 by (rtac le_trans 1);
526 by (stac mult_commute 2);
527 by (etac mult_le_mono1 2);
528 by (simp_tac (simpset() addsimps [mult_commute]) 1);
529 qed "mult_le_mono";
531 (*strict, in 1st argument; proof is by induction on k>0*)
532 Goal "[| i<j; 0<k |] ==> k*i < k*j";
533 by (eres_inst_tac [("m1","0")] (less_eq_Suc_add RS exE) 1);
534 by (Asm_simp_tac 1);
535 by (induct_tac "x" 1);
537 qed "mult_less_mono2";
539 Goal "[| i<j; 0<k |] ==> i*k < j*k";
540 by (dtac mult_less_mono2 1);
541 by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [mult_commute])));
542 qed "mult_less_mono1";
544 Goal "(0 < m*n) = (0<m & 0<n)";
545 by (induct_tac "m" 1);
546 by (induct_tac "n" 2);
547 by (ALLGOALS Asm_simp_tac);
548 qed "zero_less_mult_iff";
551 Goal "(m*n = 1) = (m=1 & n=1)";
552 by (induct_tac "m" 1);
553 by (Simp_tac 1);
554 by (induct_tac "n" 1);
555 by (Simp_tac 1);
556 by (fast_tac (claset() addss simpset()) 1);
557 qed "mult_eq_1_iff";
560 Goal "0<k ==> (m*k < n*k) = (m<n)";
561 by (safe_tac (claset() addSIs [mult_less_mono1]));
562 by (cut_facts_tac [less_linear] 1);
564 qed "mult_less_cancel2";
566 Goal "0<k ==> (k*m < k*n) = (m<n)";
567 by (dtac mult_less_cancel2 1);
568 by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1);
569 qed "mult_less_cancel1";
572 Goal "(Suc k * m < Suc k * n) = (m < n)";
573 by (rtac mult_less_cancel1 1);
574 by (Simp_tac 1);
575 qed "Suc_mult_less_cancel1";
577 Goalw [le_def] "(Suc k * m <= Suc k * n) = (m <= n)";
578 by (simp_tac (simpset_of HOL.thy) 1);
579 by (rtac Suc_mult_less_cancel1 1);
580 qed "Suc_mult_le_cancel1";
582 Goal "0<k ==> (m*k = n*k) = (m=n)";
583 by (cut_facts_tac [less_linear] 1);
584 by Safe_tac;
585 by (assume_tac 2);
586 by (ALLGOALS (dtac mult_less_mono1 THEN' assume_tac));
587 by (ALLGOALS Asm_full_simp_tac);
588 qed "mult_cancel2";
590 Goal "0<k ==> (k*m = k*n) = (m=n)";
591 by (dtac mult_cancel2 1);
592 by (asm_full_simp_tac (simpset() addsimps [mult_commute]) 1);
593 qed "mult_cancel1";
596 Goal "(Suc k * m = Suc k * n) = (m = n)";
597 by (rtac mult_cancel1 1);
598 by (Simp_tac 1);
599 qed "Suc_mult_cancel1";
602 (** Lemma for gcd **)
604 Goal "m = m*n ==> n=1 | m=0";
605 by (dtac sym 1);
606 by (rtac disjCI 1);
607 by (rtac nat_less_cases 1 THEN assume_tac 2);
610 qed "mult_eq_self_implies_10";
613 (*** Subtraction laws -- mostly from Clemens Ballarin ***)
615 Goal "[| a < (b::nat); c <= a |] ==> a-c < b-c";
616 by (subgoal_tac "c+(a-c) < c+(b-c)" 1);
617 by (Full_simp_tac 1);
618 by (subgoal_tac "c <= b" 1);
619 by (blast_tac (claset() addIs [less_imp_le, le_trans]) 2);
620 by (Asm_simp_tac 1);
621 qed "diff_less_mono";
623 Goal "a+b < (c::nat) ==> a < c-b";
624 by (dtac diff_less_mono 1);
626 by (Asm_full_simp_tac 1);
629 Goal "(i < j-k) = (i+k < (j::nat))";
630 by (rtac iffI 1);
631  by (case_tac "k <= j" 1);
633   by (dres_inst_tac [("k","k")] add_less_mono1 1);
634   by (Asm_full_simp_tac 1);
635  by (rotate_tac 1 1);
636  by (asm_full_simp_tac (simpset() addSolver cut_trans_tac) 1);
638 qed "less_diff_conv";
640 Goal "(j-k <= (i::nat)) = (j <= i+k)";
641 by (simp_tac (simpset() addsimps [less_diff_conv, le_def]) 1);
642 qed "le_diff_conv";
644 Goal "k <= j ==> (i <= j-k) = (i+k <= (j::nat))";
645 by (asm_full_simp_tac
646     (simpset() delsimps [less_Suc_eq_le]
647                addsimps [less_Suc_eq_le RS sym, less_diff_conv,
648 			 Suc_diff_le RS sym]) 1);
649 qed "le_diff_conv2";
651 Goal "Suc i <= n ==> Suc (n - Suc i) = n - i";
652 by (asm_full_simp_tac (simpset() addsimps [Suc_diff_le RS sym]) 1);
653 qed "Suc_diff_Suc";
655 Goal "i <= (n::nat) ==> n - (n - i) = i";
656 by (etac rev_mp 1);
657 by (res_inst_tac [("m","n"),("n","i")] diff_induct 1);
658 by (ALLGOALS (asm_simp_tac  (simpset() addsimps [Suc_diff_le])));
659 qed "diff_diff_cancel";
662 Goal "k <= (n::nat) ==> m <= n + m - k";
663 by (etac rev_mp 1);
664 by (res_inst_tac [("m", "k"), ("n", "n")] diff_induct 1);
665 by (Simp_tac 1);
667 by (Simp_tac 1);
670 Goal "0<k ==> j<i --> j+k-i < k";
671 by (res_inst_tac [("m","j"),("n","i")] diff_induct 1);
672 by (ALLGOALS Asm_simp_tac);
676 Goal "m-1 < n ==> m <= n";
677 by (exhaust_tac "m" 1);
678 by (auto_tac (claset(), simpset() addsimps [Suc_le_eq]));
679 qed "pred_less_imp_le";
681 Goal "j<=i ==> i - j < Suc i - j";
682 by (REPEAT (etac rev_mp 1));
683 by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
684 by Auto_tac;
685 qed "diff_less_Suc_diff";
687 Goal "i - j <= Suc i - j";
688 by (res_inst_tac [("m","i"),("n","j")] diff_induct 1);
689 by Auto_tac;
690 qed "diff_le_Suc_diff";
693 Goal "n - Suc i <= n - i";
694 by (case_tac "i<n" 1);
695 by (dtac diff_Suc_less_diff 1);
696 by (auto_tac (claset(), simpset() addsimps [less_imp_le, leI]));
697 qed "diff_Suc_le_diff";
700 Goal "0 < n ==> (m <= n-1) = (m<n)";
701 by (exhaust_tac "n" 1);
702 by (auto_tac (claset(), simpset() addsimps le_simps));
703 qed "le_pred_eq";
705 Goal "0 < n ==> (m-1 < n) = (m<=n)";
706 by (exhaust_tac "m" 1);
707 by (auto_tac (claset(), simpset() addsimps [Suc_le_eq]));
708 qed "less_pred_eq";
710 (*In ordinary notation: if 0<n and n<=m then m-n < m *)
711 Goal "[| 0<n; ~ m<n |] ==> m - n < m";
712 by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
713 by (Blast_tac 1);
714 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
716 qed "diff_less";
718 Goal "[| 0<n; n<=m |] ==> m - n < m";
719 by (asm_simp_tac (simpset() addsimps [diff_less, not_less_iff_le]) 1);
720 qed "le_diff_less";
724 (** (Anti)Monotonicity of subtraction -- by Stefan Merz **)
726 (* Monotonicity of subtraction in first argument *)
727 Goal "m <= (n::nat) --> (m-l) <= (n-l)";
728 by (induct_tac "n" 1);
729 by (Simp_tac 1);
730 by (simp_tac (simpset() addsimps [le_Suc_eq]) 1);
731 by (blast_tac (claset() addIs [diff_le_Suc_diff, le_trans]) 1);
732 qed_spec_mp "diff_le_mono";
734 Goal "m <= (n::nat) ==> (l-n) <= (l-m)";
735 by (induct_tac "l" 1);
736 by (Simp_tac 1);
737 by (case_tac "n <= na" 1);
738 by (subgoal_tac "m <= na" 1);
739 by (asm_simp_tac (simpset() addsimps [Suc_diff_le]) 1);
740 by (fast_tac (claset() addEs [le_trans]) 1);
741 by (dtac not_leE 1);
742 by (asm_simp_tac (simpset() addsimps [if_Suc_diff_le]) 1);
743 qed_spec_mp "diff_le_mono2";