src/HOL/Arith.ML
 author nipkow Tue Apr 08 10:48:42 1997 +0200 (1997-04-08) changeset 2919 953a47dc0519 parent 2682 13cdbf95ed92 child 2922 580647a879cf permissions -rw-r--r--
Dep. on Provers/nat_transitive
```     1 (*  Title:      HOL/Arith.ML
```
```     2     ID:         \$Id\$
```
```     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
```
```     4     Copyright   1993  University of Cambridge
```
```     5
```
```     6 Proofs about elementary arithmetic: addition, multiplication, etc.
```
```     7 Tests definitions and simplifier.
```
```     8 *)
```
```     9
```
```    10 open Arith;
```
```    11
```
```    12 (*** Basic rewrite rules for the arithmetic operators ***)
```
```    13
```
```    14 goalw Arith.thy [pred_def] "pred 0 = 0";
```
```    15 by(Simp_tac 1);
```
```    16 qed "pred_0";
```
```    17
```
```    18 goalw Arith.thy [pred_def] "pred(Suc n) = n";
```
```    19 by(Simp_tac 1);
```
```    20 qed "pred_Suc";
```
```    21
```
```    22 Addsimps [pred_0,pred_Suc];
```
```    23
```
```    24 (** pred **)
```
```    25
```
```    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";
```
```    31 Addsimps [Suc_pred];
```
```    32
```
```    33 (** Difference **)
```
```    34
```
```    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]);
```
```    38
```
```    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]);
```
```    45
```
```    46 Addsimps [diff_0_eq_0, diff_Suc_Suc];
```
```    47
```
```    48
```
```    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 (Fast_tac 1);
```
```    54 val lemma = result();
```
```    55
```
```    56 (* [| 0 < k; !!j. [| j: nat; k = succ(j) |] ==> Q |] ==> Q *)
```
```    57 bind_thm ("zero_less_natE", lemma RS exE);
```
```    58
```
```    59
```
```    60
```
```    61 (**** Inductive properties of the operators ****)
```
```    62
```
```    63 (*** Addition ***)
```
```    64
```
```    65 qed_goal "add_0_right" Arith.thy "m + 0 = m"
```
```    66  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
```
```    67
```
```    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]);
```
```    70
```
```    71 Addsimps [add_0_right,add_Suc_right];
```
```    72
```
```    73 (*Associative law for addition*)
```
```    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]);
```
```    76
```
```    77 (*Commutative law for addition*)
```
```    78 qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)"
```
```    79  (fn _ =>  [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
```
```    80
```
```    81 qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)"
```
```    82  (fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1,
```
```    83            rtac (add_commute RS arg_cong) 1]);
```
```    84
```
```    85 (*Addition is an AC-operator*)
```
```    86 val add_ac = [add_assoc, add_commute, add_left_commute];
```
```    87
```
```    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);
```
```    92 qed "add_left_cancel";
```
```    93
```
```    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);
```
```    98 qed "add_right_cancel";
```
```    99
```
```   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);
```
```   104 qed "add_left_cancel_le";
```
```   105
```
```   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);
```
```   110 qed "add_left_cancel_less";
```
```   111
```
```   112 Addsimps [add_left_cancel, add_right_cancel,
```
```   113           add_left_cancel_le, add_left_cancel_less];
```
```   114
```
```   115 goal Arith.thy "(m+n = 0) = (m=0 & n=0)";
```
```   116 by (nat_ind_tac "m" 1);
```
```   117 by (ALLGOALS Asm_simp_tac);
```
```   118 qed "add_is_0";
```
```   119 Addsimps [add_is_0];
```
```   120
```
```   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);
```
```   124 qed "add_pred";
```
```   125 Addsimps [add_pred];
```
```   126
```
```   127 (*** Multiplication ***)
```
```   128
```
```   129 (*right annihilation in product*)
```
```   130 qed_goal "mult_0_right" Arith.thy "m * 0 = 0"
```
```   131  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
```
```   132
```
```   133 (*right Sucessor law for multiplication*)
```
```   134 qed_goal "mult_Suc_right" Arith.thy  "m * Suc(n) = m + (m * n)"
```
```   135  (fn _ => [nat_ind_tac "m" 1,
```
```   136            ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
```
```   137
```
```   138 Addsimps [mult_0_right,mult_Suc_right];
```
```   139
```
```   140 goal Arith.thy "1 * n = n";
```
```   141 by (Asm_simp_tac 1);
```
```   142 qed "mult_1";
```
```   143
```
```   144 goal Arith.thy "n * 1 = n";
```
```   145 by (Asm_simp_tac 1);
```
```   146 qed "mult_1_right";
```
```   147
```
```   148 (*Commutative law for multiplication*)
```
```   149 qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)"
```
```   150  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
```
```   151
```
```   152 (*addition distributes over multiplication*)
```
```   153 qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)"
```
```   154  (fn _ => [nat_ind_tac "m" 1,
```
```   155            ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
```
```   156
```
```   157 qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)"
```
```   158  (fn _ => [nat_ind_tac "m" 1,
```
```   159            ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]);
```
```   160
```
```   161 (*Associative law for multiplication*)
```
```   162 qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)"
```
```   163   (fn _ => [nat_ind_tac "m" 1,
```
```   164             ALLGOALS (asm_simp_tac (!simpset addsimps [add_mult_distrib]))]);
```
```   165
```
```   166 qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)"
```
```   167  (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1,
```
```   168            rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]);
```
```   169
```
```   170 val mult_ac = [mult_assoc,mult_commute,mult_left_commute];
```
```   171
```
```   172 (*** Difference ***)
```
```   173
```
```   174 qed_goal "pred_Suc_diff" Arith.thy "pred(Suc m - n) = m - n"
```
```   175  (fn _ => [nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]);
```
```   176 Addsimps [pred_Suc_diff];
```
```   177
```
```   178 qed_goal "diff_self_eq_0" Arith.thy "m - m = 0"
```
```   179  (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]);
```
```   180 Addsimps [diff_self_eq_0];
```
```   181
```
```   182 (*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *)
```
```   183 val [prem] = goal Arith.thy "[| ~ m<n |] ==> n+(m-n) = (m::nat)";
```
```   184 by (rtac (prem RS rev_mp) 1);
```
```   185 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   186 by (ALLGOALS (Asm_simp_tac));
```
```   187 qed "add_diff_inverse";
```
```   188
```
```   189
```
```   190 (*** Remainder ***)
```
```   191
```
```   192 goal Arith.thy "m - n < Suc(m)";
```
```   193 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   194 by (etac less_SucE 3);
```
```   195 by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq])));
```
```   196 qed "diff_less_Suc";
```
```   197
```
```   198 goal Arith.thy "!!m::nat. m - n <= m";
```
```   199 by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1);
```
```   200 by (ALLGOALS Asm_simp_tac);
```
```   201 qed "diff_le_self";
```
```   202
```
```   203 goal Arith.thy "!!n::nat. (n+m) - n = m";
```
```   204 by (nat_ind_tac "n" 1);
```
```   205 by (ALLGOALS Asm_simp_tac);
```
```   206 qed "diff_add_inverse";
```
```   207
```
```   208 goal Arith.thy "!!n::nat.(m+n) - n = m";
```
```   209 by (res_inst_tac [("m1","m")] (add_commute RS ssubst) 1);
```
```   210 by (REPEAT (ares_tac [diff_add_inverse] 1));
```
```   211 qed "diff_add_inverse2";
```
```   212
```
```   213 goal Arith.thy "!!k::nat. (k+m) - (k+n) = m - n";
```
```   214 by (nat_ind_tac "k" 1);
```
```   215 by (ALLGOALS Asm_simp_tac);
```
```   216 qed "diff_cancel";
```
```   217 Addsimps [diff_cancel];
```
```   218
```
```   219 goal Arith.thy "!!m::nat. (m+k) - (n+k) = m - n";
```
```   220 val add_commute_k = read_instantiate [("n","k")] add_commute;
```
```   221 by (asm_simp_tac (!simpset addsimps ([add_commute_k])) 1);
```
```   222 qed "diff_cancel2";
```
```   223 Addsimps [diff_cancel2];
```
```   224
```
```   225 goal Arith.thy "!!n::nat. n - (n+m) = 0";
```
```   226 by (nat_ind_tac "n" 1);
```
```   227 by (ALLGOALS Asm_simp_tac);
```
```   228 qed "diff_add_0";
```
```   229 Addsimps [diff_add_0];
```
```   230
```
```   231 (** Difference distributes over multiplication **)
```
```   232
```
```   233 goal Arith.thy "!!m::nat. (m - n) * k = (m * k) - (n * k)";
```
```   234 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   235 by (ALLGOALS Asm_simp_tac);
```
```   236 qed "diff_mult_distrib" ;
```
```   237
```
```   238 goal Arith.thy "!!m::nat. k * (m - n) = (k * m) - (k * n)";
```
```   239 val mult_commute_k = read_instantiate [("m","k")] mult_commute;
```
```   240 by (simp_tac (!simpset addsimps [diff_mult_distrib, mult_commute_k]) 1);
```
```   241 qed "diff_mult_distrib2" ;
```
```   242 (*NOT added as rewrites, since sometimes they are used from right-to-left*)
```
```   243
```
```   244
```
```   245 (** Less-then properties **)
```
```   246
```
```   247 (*In ordinary notation: if 0<n and n<=m then m-n < m *)
```
```   248 goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m";
```
```   249 by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1);
```
```   250 by (Fast_tac 1);
```
```   251 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   252 by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc])));
```
```   253 qed "diff_less";
```
```   254
```
```   255 val wf_less_trans = wf_pred_nat RS wf_trancl RSN (2, def_wfrec RS trans);
```
```   256
```
```   257 goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m<n)";
```
```   258 by (rtac refl 1);
```
```   259 qed "less_eq";
```
```   260
```
```   261 goal Arith.thy "(%m. m mod n) = wfrec (trancl pred_nat) \
```
```   262              \                      (%f j. if j<n then j else f (j-n))";
```
```   263 by (simp_tac (HOL_ss addsimps [mod_def]) 1);
```
```   264 val mod_def1 = result() RS eq_reflection;
```
```   265
```
```   266 goal Arith.thy "!!m. m<n ==> m mod n = m";
```
```   267 by (rtac (mod_def1 RS wf_less_trans) 1);
```
```   268 by (Asm_simp_tac 1);
```
```   269 qed "mod_less";
```
```   270
```
```   271 goal Arith.thy "!!m. [| 0<n;  ~m<n |] ==> m mod n = (m-n) mod n";
```
```   272 by (rtac (mod_def1 RS wf_less_trans) 1);
```
```   273 by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
```
```   274 qed "mod_geq";
```
```   275
```
```   276
```
```   277 (*** Quotient ***)
```
```   278
```
```   279 goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \
```
```   280                         \            (%f j. if j<n then 0 else Suc (f (j-n)))";
```
```   281 by (simp_tac (HOL_ss addsimps [div_def]) 1);
```
```   282 val div_def1 = result() RS eq_reflection;
```
```   283
```
```   284 goal Arith.thy "!!m. m<n ==> m div n = 0";
```
```   285 by (rtac (div_def1 RS wf_less_trans) 1);
```
```   286 by (Asm_simp_tac 1);
```
```   287 qed "div_less";
```
```   288
```
```   289 goal Arith.thy "!!M. [| 0<n;  ~m<n |] ==> m div n = Suc((m-n) div n)";
```
```   290 by (rtac (div_def1 RS wf_less_trans) 1);
```
```   291 by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1);
```
```   292 qed "div_geq";
```
```   293
```
```   294 (*Main Result about quotient and remainder.*)
```
```   295 goal Arith.thy "!!m. 0<n ==> (m div n)*n + m mod n = m";
```
```   296 by (res_inst_tac [("n","m")] less_induct 1);
```
```   297 by (rename_tac "k" 1);    (*Variable name used in line below*)
```
```   298 by (case_tac "k<n" 1);
```
```   299 by (ALLGOALS (asm_simp_tac(!simpset addsimps ([add_assoc] @
```
```   300                        [mod_less, mod_geq, div_less, div_geq,
```
```   301                         add_diff_inverse, diff_less]))));
```
```   302 qed "mod_div_equality";
```
```   303
```
```   304
```
```   305 (*** More results about difference ***)
```
```   306
```
```   307 val [prem] = goal Arith.thy "m < Suc(n) ==> m-n = 0";
```
```   308 by (rtac (prem RS rev_mp) 1);
```
```   309 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   310 by (asm_simp_tac (!simpset addsimps [less_Suc_eq]) 1);
```
```   311 by (ALLGOALS (Asm_simp_tac));
```
```   312 qed "less_imp_diff_is_0";
```
```   313
```
```   314 val prems = goal Arith.thy "m-n = 0  -->  n-m = 0  -->  m=n";
```
```   315 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   316 by (REPEAT(Simp_tac 1 THEN TRY(atac 1)));
```
```   317 qed_spec_mp "diffs0_imp_equal";
```
```   318
```
```   319 val [prem] = goal Arith.thy "m<n ==> 0<n-m";
```
```   320 by (rtac (prem RS rev_mp) 1);
```
```   321 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   322 by (ALLGOALS (Asm_simp_tac));
```
```   323 qed "less_imp_diff_positive";
```
```   324
```
```   325 val [prem] = goal Arith.thy "n < Suc(m) ==> Suc(m)-n = Suc(m-n)";
```
```   326 by (rtac (prem RS rev_mp) 1);
```
```   327 by (res_inst_tac [("m","m"),("n","n")] diff_induct 1);
```
```   328 by (ALLGOALS (Asm_simp_tac));
```
```   329 qed "Suc_diff_n";
```
```   330
```
```   331 goal Arith.thy "Suc(m)-n = (if m<n then 0 else Suc(m-n))";
```
```   332 by (simp_tac (!simpset addsimps [less_imp_diff_is_0, not_less_eq, Suc_diff_n]
```
```   333                     setloop (split_tac [expand_if])) 1);
```
```   334 qed "if_Suc_diff_n";
```
```   335
```
```   336 goal Arith.thy "P(k) --> (!n. P(Suc(n))--> P(n)) --> P(k-i)";
```
```   337 by (res_inst_tac [("m","k"),("n","i")] diff_induct 1);
```
```   338 by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o Fast_tac));
```
```   339 qed "zero_induct_lemma";
```
```   340
```
```   341 val prems = goal Arith.thy "[| P(k);  !!n. P(Suc(n)) ==> P(n) |] ==> P(0)";
```
```   342 by (rtac (diff_self_eq_0 RS subst) 1);
```
```   343 by (rtac (zero_induct_lemma RS mp RS mp) 1);
```
```   344 by (REPEAT (ares_tac ([impI,allI]@prems) 1));
```
```   345 qed "zero_induct";
```
```   346
```
```   347 (*13 July 1992: loaded in 105.7s*)
```
```   348
```
```   349
```
```   350 (*** Further facts about mod (mainly for mutilated checkerboard ***)
```
```   351
```
```   352 goal Arith.thy
```
```   353     "!!m n. 0<n ==> \
```
```   354 \           Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))";
```
```   355 by (res_inst_tac [("n","m")] less_induct 1);
```
```   356 by (excluded_middle_tac "Suc(na)<n" 1);
```
```   357 (* case Suc(na) < n *)
```
```   358 by (forward_tac [lessI RS less_trans] 2);
```
```   359 by (asm_simp_tac (!simpset addsimps [mod_less, less_not_refl2 RS not_sym]) 2);
```
```   360 (* case n <= Suc(na) *)
```
```   361 by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le, mod_geq]) 1);
```
```   362 by (etac (le_imp_less_or_eq RS disjE) 1);
```
```   363 by (asm_simp_tac (!simpset addsimps [Suc_diff_n]) 1);
```
```   364 by (asm_full_simp_tac (!simpset addsimps [not_less_eq RS sym,
```
```   365                                           diff_less, mod_geq]) 1);
```
```   366 by (asm_simp_tac (!simpset addsimps [mod_less]) 1);
```
```   367 qed "mod_Suc";
```
```   368
```
```   369 goal Arith.thy "!!m n. 0<n ==> m mod n < n";
```
```   370 by (res_inst_tac [("n","m")] less_induct 1);
```
```   371 by (excluded_middle_tac "na<n" 1);
```
```   372 (*case na<n*)
```
```   373 by (asm_simp_tac (!simpset addsimps [mod_less]) 2);
```
```   374 (*case n le na*)
```
```   375 by (asm_full_simp_tac (!simpset addsimps [mod_geq, diff_less]) 1);
```
```   376 qed "mod_less_divisor";
```
```   377
```
```   378
```
```   379 (** Evens and Odds **)
```
```   380
```
```   381 (*With less_zeroE, causes case analysis on b<2*)
```
```   382 AddSEs [less_SucE];
```
```   383
```
```   384 goal thy "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)";
```
```   385 by (subgoal_tac "k mod 2 < 2" 1);
```
```   386 by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
```
```   387 by (asm_simp_tac (!simpset setloop split_tac [expand_if]) 1);
```
```   388 by (Fast_tac 1);
```
```   389 qed "mod2_cases";
```
```   390
```
```   391 goal thy "Suc(Suc(m)) mod 2 = m mod 2";
```
```   392 by (subgoal_tac "m mod 2 < 2" 1);
```
```   393 by (asm_simp_tac (!simpset addsimps [mod_less_divisor]) 2);
```
```   394 by (Step_tac 1);
```
```   395 by (ALLGOALS (asm_simp_tac (!simpset addsimps [mod_Suc])));
```
```   396 qed "mod2_Suc_Suc";
```
```   397 Addsimps [mod2_Suc_Suc];
```
```   398
```
```   399 goal thy "(m+m) mod 2 = 0";
```
```   400 by (nat_ind_tac "m" 1);
```
```   401 by (simp_tac (!simpset addsimps [mod_less]) 1);
```
```   402 by (asm_simp_tac (!simpset addsimps [mod2_Suc_Suc, add_Suc_right]) 1);
```
```   403 qed "mod2_add_self";
```
```   404 Addsimps [mod2_add_self];
```
```   405
```
```   406 Delrules [less_SucE];
```
```   407
```
```   408
```
```   409 (**** Additional theorems about "less than" ****)
```
```   410
```
```   411 goal Arith.thy "? k::nat. n = n+k";
```
```   412 by (res_inst_tac [("x","0")] exI 1);
```
```   413 by (Simp_tac 1);
```
```   414 val lemma = result();
```
```   415
```
```   416 goal Arith.thy "!!m. m<n --> (? k. n=Suc(m+k))";
```
```   417 by (nat_ind_tac "n" 1);
```
```   418 by (ALLGOALS (simp_tac (!simpset addsimps [less_Suc_eq])));
```
```   419 by (step_tac (!claset addSIs [lemma]) 1);
```
```   420 by (res_inst_tac [("x","Suc(k)")] exI 1);
```
```   421 by (Simp_tac 1);
```
```   422 qed_spec_mp "less_eq_Suc_add";
```
```   423
```
```   424 goal Arith.thy "n <= ((m + n)::nat)";
```
```   425 by (nat_ind_tac "m" 1);
```
```   426 by (ALLGOALS Simp_tac);
```
```   427 by (etac le_trans 1);
```
```   428 by (rtac (lessI RS less_imp_le) 1);
```
```   429 qed "le_add2";
```
```   430
```
```   431 goal Arith.thy "n <= ((n + m)::nat)";
```
```   432 by (simp_tac (!simpset addsimps add_ac) 1);
```
```   433 by (rtac le_add2 1);
```
```   434 qed "le_add1";
```
```   435
```
```   436 bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans)));
```
```   437 bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans)));
```
```   438
```
```   439 (*"i <= j ==> i <= j+m"*)
```
```   440 bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans));
```
```   441
```
```   442 (*"i <= j ==> i <= m+j"*)
```
```   443 bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans));
```
```   444
```
```   445 (*"i < j ==> i < j+m"*)
```
```   446 bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans));
```
```   447
```
```   448 (*"i < j ==> i < m+j"*)
```
```   449 bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans));
```
```   450
```
```   451 goal Arith.thy "!!i. i+j < (k::nat) ==> i<k";
```
```   452 by (etac rev_mp 1);
```
```   453 by (nat_ind_tac "j" 1);
```
```   454 by (ALLGOALS Asm_simp_tac);
```
```   455 by (fast_tac (!claset addDs [Suc_lessD]) 1);
```
```   456 qed "add_lessD1";
```
```   457
```
```   458 goal Arith.thy "!!k::nat. m <= n ==> m <= n+k";
```
```   459 by (etac le_trans 1);
```
```   460 by (rtac le_add1 1);
```
```   461 qed "le_imp_add_le";
```
```   462
```
```   463 goal Arith.thy "!!k::nat. m < n ==> m < n+k";
```
```   464 by (etac less_le_trans 1);
```
```   465 by (rtac le_add1 1);
```
```   466 qed "less_imp_add_less";
```
```   467
```
```   468 goal Arith.thy "m+k<=n --> m<=(n::nat)";
```
```   469 by (nat_ind_tac "k" 1);
```
```   470 by (ALLGOALS Asm_simp_tac);
```
```   471 by (fast_tac (!claset addDs [Suc_leD]) 1);
```
```   472 qed_spec_mp "add_leD1";
```
```   473
```
```   474 goal Arith.thy "!!n::nat. m+k<=n ==> k<=n";
```
```   475 by (full_simp_tac (!simpset addsimps [add_commute]) 1);
```
```   476 by (etac add_leD1 1);
```
```   477 qed_spec_mp "add_leD2";
```
```   478
```
```   479 goal Arith.thy "!!n::nat. m+k<=n ==> m<=n & k<=n";
```
```   480 by (fast_tac (!claset addDs [add_leD1, add_leD2]) 1);
```
```   481 bind_thm ("add_leE", result() RS conjE);
```
```   482
```
```   483 goal Arith.thy "!!k l::nat. [| k<l; m+l = k+n |] ==> m<n";
```
```   484 by (safe_tac (!claset addSDs [less_eq_Suc_add]));
```
```   485 by (asm_full_simp_tac
```
```   486     (!simpset delsimps [add_Suc_right]
```
```   487                 addsimps ([add_Suc_right RS sym, add_left_cancel] @add_ac)) 1);
```
```   488 by (etac subst 1);
```
```   489 by (simp_tac (!simpset addsimps [less_add_Suc1]) 1);
```
```   490 qed "less_add_eq_less";
```
```   491
```
```   492
```
```   493 (*** Monotonicity of Addition ***)
```
```   494
```
```   495 (*strict, in 1st argument*)
```
```   496 goal Arith.thy "!!i j k::nat. i < j ==> i + k < j + k";
```
```   497 by (nat_ind_tac "k" 1);
```
```   498 by (ALLGOALS Asm_simp_tac);
```
```   499 qed "add_less_mono1";
```
```   500
```
```   501 (*strict, in both arguments*)
```
```   502 goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l";
```
```   503 by (rtac (add_less_mono1 RS less_trans) 1);
```
```   504 by (REPEAT (assume_tac 1));
```
```   505 by (nat_ind_tac "j" 1);
```
```   506 by (ALLGOALS Asm_simp_tac);
```
```   507 qed "add_less_mono";
```
```   508
```
```   509 (*A [clumsy] way of lifting < monotonicity to <= monotonicity *)
```
```   510 val [lt_mono,le] = goal Arith.thy
```
```   511      "[| !!i j::nat. i<j ==> f(i) < f(j);       \
```
```   512 \        i <= j                                 \
```
```   513 \     |] ==> f(i) <= (f(j)::nat)";
```
```   514 by (cut_facts_tac [le] 1);
```
```   515 by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1);
```
```   516 by (fast_tac (!claset addSIs [lt_mono]) 1);
```
```   517 qed "less_mono_imp_le_mono";
```
```   518
```
```   519 (*non-strict, in 1st argument*)
```
```   520 goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k";
```
```   521 by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1);
```
```   522 by (etac add_less_mono1 1);
```
```   523 by (assume_tac 1);
```
```   524 qed "add_le_mono1";
```
```   525
```
```   526 (*non-strict, in both arguments*)
```
```   527 goal Arith.thy "!!k l::nat. [|i<=j;  k<=l |] ==> i + k <= j + l";
```
```   528 by (etac (add_le_mono1 RS le_trans) 1);
```
```   529 by (simp_tac (!simpset addsimps [add_commute]) 1);
```
```   530 (*j moves to the end because it is free while k, l are bound*)
```
```   531 by (etac add_le_mono1 1);
```
```   532 qed "add_le_mono";
```
```   533
```
```   534 (*** Monotonicity of Multiplication ***)
```
```   535
```
```   536 goal Arith.thy "!!i::nat. i<=j ==> i*k<=j*k";
```
```   537 by (nat_ind_tac "k" 1);
```
```   538 by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_le_mono])));
```
```   539 qed "mult_le_mono1";
```
```   540
```
```   541 (*<=monotonicity, BOTH arguments*)
```
```   542 goal Arith.thy "!!i::nat. [| i<=j; k<=l |] ==> i*k<=j*l";
```
```   543 by (etac (mult_le_mono1 RS le_trans) 1);
```
```   544 by (rtac le_trans 1);
```
```   545 by (stac mult_commute 2);
```
```   546 by (etac mult_le_mono1 2);
```
```   547 by (simp_tac (!simpset addsimps [mult_commute]) 1);
```
```   548 qed "mult_le_mono";
```
```   549
```
```   550 (*strict, in 1st argument; proof is by induction on k>0*)
```
```   551 goal Arith.thy "!!i::nat. [| i<j; 0<k |] ==> k*i < k*j";
```
```   552 by (etac zero_less_natE 1);
```
```   553 by (Asm_simp_tac 1);
```
```   554 by (nat_ind_tac "x" 1);
```
```   555 by (ALLGOALS (asm_simp_tac (!simpset addsimps [add_less_mono])));
```
```   556 qed "mult_less_mono2";
```
```   557
```
```   558 goal Arith.thy "(0 < m*n) = (0<m & 0<n)";
```
```   559 by (nat_ind_tac "m" 1);
```
```   560 by (nat_ind_tac "n" 2);
```
```   561 by (ALLGOALS Asm_simp_tac);
```
```   562 qed "zero_less_mult_iff";
```
```   563
```
```   564 goal Arith.thy "(m*n = 1) = (m=1 & n=1)";
```
```   565 by (nat_ind_tac "m" 1);
```
```   566 by (Simp_tac 1);
```
```   567 by (nat_ind_tac "n" 1);
```
```   568 by (Simp_tac 1);
```
```   569 by (fast_tac (!claset addss !simpset) 1);
```
```   570 qed "mult_eq_1_iff";
```
```   571
```
```   572 (*Cancellation law for division*)
```
```   573 goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) div (k*n) = m div n";
```
```   574 by (res_inst_tac [("n","m")] less_induct 1);
```
```   575 by (case_tac "na<n" 1);
```
```   576 by (asm_simp_tac (!simpset addsimps [div_less, zero_less_mult_iff,
```
```   577                                      mult_less_mono2]) 1);
```
```   578 by (subgoal_tac "~ k*na < k*n" 1);
```
```   579 by (asm_simp_tac
```
```   580      (!simpset addsimps [zero_less_mult_iff, div_geq,
```
```   581                          diff_mult_distrib2 RS sym, diff_less]) 1);
```
```   582 by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le,
```
```   583                                           le_refl RS mult_le_mono]) 1);
```
```   584 qed "div_cancel";
```
```   585
```
```   586 goal Arith.thy "!!k. [| 0<n; 0<k |] ==> (k*m) mod (k*n) = k * (m mod n)";
```
```   587 by (res_inst_tac [("n","m")] less_induct 1);
```
```   588 by (case_tac "na<n" 1);
```
```   589 by (asm_simp_tac (!simpset addsimps [mod_less, zero_less_mult_iff,
```
```   590                                      mult_less_mono2]) 1);
```
```   591 by (subgoal_tac "~ k*na < k*n" 1);
```
```   592 by (asm_simp_tac
```
```   593      (!simpset addsimps [zero_less_mult_iff, mod_geq,
```
```   594                          diff_mult_distrib2 RS sym, diff_less]) 1);
```
```   595 by (asm_full_simp_tac (!simpset addsimps [not_less_iff_le,
```
```   596                                           le_refl RS mult_le_mono]) 1);
```
```   597 qed "mult_mod_distrib";
```
```   598
```
```   599
```
```   600 (** Lemma for gcd **)
```
```   601
```
```   602 goal Arith.thy "!!m n. m = m*n ==> n=1 | m=0";
```
```   603 by (dtac sym 1);
```
```   604 by (rtac disjCI 1);
```
```   605 by (rtac nat_less_cases 1 THEN assume_tac 2);
```
```   606 by (fast_tac (!claset addSEs [less_SucE] addss !simpset) 1);
```
```   607 by (best_tac (!claset addDs [mult_less_mono2]
```
```   608                       addss (!simpset addsimps [zero_less_eq RS sym])) 1);
```
```   609 qed "mult_eq_self_implies_10";
```
```   610
```
```   611
```