src/HOL/Arith.ML
 author paulson Wed Mar 06 12:52:11 1996 +0100 (1996-03-06) changeset 1552 6f71b5d46700 parent 1496 c443b2adaf52 child 1618 372880456b5b permissions -rw-r--r--
Ran expandshort
 clasohm@1465 ` 1` ```(* Title: HOL/Arith.ML ``` clasohm@923 ` 2` ``` ID: \$Id\$ ``` clasohm@1465 ` 3` ``` Author: Lawrence C Paulson, Cambridge University Computer Laboratory ``` clasohm@923 ` 4` ``` Copyright 1993 University of Cambridge ``` clasohm@923 ` 5` clasohm@923 ` 6` ```Proofs about elementary arithmetic: addition, multiplication, etc. ``` clasohm@923 ` 7` ```Tests definitions and simplifier. ``` clasohm@923 ` 8` ```*) ``` clasohm@923 ` 9` clasohm@923 ` 10` ```open Arith; ``` clasohm@923 ` 11` clasohm@923 ` 12` ```(*** Basic rewrite rules for the arithmetic operators ***) ``` clasohm@923 ` 13` clasohm@923 ` 14` ```val [pred_0, pred_Suc] = nat_recs pred_def; ``` clasohm@923 ` 15` ```val [add_0,add_Suc] = nat_recs add_def; ``` clasohm@923 ` 16` ```val [mult_0,mult_Suc] = nat_recs mult_def; ``` nipkow@1301 ` 17` ```Addsimps [pred_0,pred_Suc,add_0,add_Suc,mult_0,mult_Suc]; ``` nipkow@1301 ` 18` nipkow@1301 ` 19` ```(** pred **) ``` nipkow@1301 ` 20` nipkow@1301 ` 21` ```val prems = goal Arith.thy "n ~= 0 ==> Suc(pred n) = n"; ``` paulson@1552 ` 22` ```by (res_inst_tac [("n","n")] natE 1); ``` paulson@1552 ` 23` ```by (cut_facts_tac prems 1); ``` paulson@1552 ` 24` ```by (ALLGOALS Asm_full_simp_tac); ``` nipkow@1301 ` 25` ```qed "Suc_pred"; ``` nipkow@1301 ` 26` ```Addsimps [Suc_pred]; ``` clasohm@923 ` 27` clasohm@923 ` 28` ```(** Difference **) ``` clasohm@923 ` 29` clasohm@923 ` 30` ```val diff_0 = diff_def RS def_nat_rec_0; ``` clasohm@923 ` 31` clasohm@923 ` 32` ```qed_goalw "diff_0_eq_0" Arith.thy [diff_def, pred_def] ``` clasohm@923 ` 33` ``` "0 - n = 0" ``` clasohm@1264 ` 34` ``` (fn _ => [nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 35` clasohm@923 ` 36` ```(*Must simplify BEFORE the induction!! (Else we get a critical pair) ``` clasohm@923 ` 37` ``` Suc(m) - Suc(n) rewrites to pred(Suc(m) - n) *) ``` clasohm@923 ` 38` ```qed_goalw "diff_Suc_Suc" Arith.thy [diff_def, pred_def] ``` clasohm@923 ` 39` ``` "Suc(m) - Suc(n) = m - n" ``` clasohm@923 ` 40` ``` (fn _ => ``` clasohm@1264 ` 41` ``` [Simp_tac 1, nat_ind_tac "n" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 42` nipkow@1301 ` 43` ```Addsimps [diff_0, diff_0_eq_0, diff_Suc_Suc]; ``` clasohm@923 ` 44` clasohm@923 ` 45` clasohm@923 ` 46` ```(**** Inductive properties of the operators ****) ``` clasohm@923 ` 47` clasohm@923 ` 48` ```(*** Addition ***) ``` clasohm@923 ` 49` clasohm@923 ` 50` ```qed_goal "add_0_right" Arith.thy "m + 0 = m" ``` clasohm@1264 ` 51` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 52` clasohm@923 ` 53` ```qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)" ``` clasohm@1264 ` 54` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 55` clasohm@1264 ` 56` ```Addsimps [add_0_right,add_Suc_right]; ``` clasohm@923 ` 57` clasohm@923 ` 58` ```(*Associative law for addition*) ``` clasohm@923 ` 59` ```qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)" ``` clasohm@1264 ` 60` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 61` clasohm@923 ` 62` ```(*Commutative law for addition*) ``` clasohm@923 ` 63` ```qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)" ``` clasohm@1264 ` 64` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 65` clasohm@923 ` 66` ```qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)" ``` clasohm@923 ` 67` ``` (fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1, ``` clasohm@923 ` 68` ``` rtac (add_commute RS arg_cong) 1]); ``` clasohm@923 ` 69` clasohm@923 ` 70` ```(*Addition is an AC-operator*) ``` clasohm@923 ` 71` ```val add_ac = [add_assoc, add_commute, add_left_commute]; ``` clasohm@923 ` 72` clasohm@923 ` 73` ```goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)"; ``` clasohm@923 ` 74` ```by (nat_ind_tac "k" 1); ``` clasohm@1264 ` 75` ```by (Simp_tac 1); ``` clasohm@1264 ` 76` ```by (Asm_simp_tac 1); ``` clasohm@923 ` 77` ```qed "add_left_cancel"; ``` clasohm@923 ` 78` clasohm@923 ` 79` ```goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)"; ``` clasohm@923 ` 80` ```by (nat_ind_tac "k" 1); ``` clasohm@1264 ` 81` ```by (Simp_tac 1); ``` clasohm@1264 ` 82` ```by (Asm_simp_tac 1); ``` clasohm@923 ` 83` ```qed "add_right_cancel"; ``` clasohm@923 ` 84` clasohm@923 ` 85` ```goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)"; ``` clasohm@923 ` 86` ```by (nat_ind_tac "k" 1); ``` clasohm@1264 ` 87` ```by (Simp_tac 1); ``` clasohm@1264 ` 88` ```by (Asm_simp_tac 1); ``` clasohm@923 ` 89` ```qed "add_left_cancel_le"; ``` clasohm@923 ` 90` clasohm@923 ` 91` ```goal Arith.thy "!!k::nat. (k + m < k + n) = (m m + pred n = pred(m+n)"; ``` nipkow@1327 ` 107` ```by (nat_ind_tac "m" 1); ``` nipkow@1327 ` 108` ```by (ALLGOALS Asm_simp_tac); ``` nipkow@1327 ` 109` ```qed "add_pred"; ``` nipkow@1327 ` 110` ```Addsimps [add_pred]; ``` nipkow@1327 ` 111` clasohm@923 ` 112` ```(*** Multiplication ***) ``` clasohm@923 ` 113` clasohm@923 ` 114` ```(*right annihilation in product*) ``` clasohm@923 ` 115` ```qed_goal "mult_0_right" Arith.thy "m * 0 = 0" ``` clasohm@1264 ` 116` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 117` clasohm@923 ` 118` ```(*right Sucessor law for multiplication*) ``` clasohm@923 ` 119` ```qed_goal "mult_Suc_right" Arith.thy "m * Suc(n) = m + (m * n)" ``` clasohm@923 ` 120` ``` (fn _ => [nat_ind_tac "m" 1, ``` clasohm@1264 ` 121` ``` ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); ``` clasohm@923 ` 122` clasohm@1264 ` 123` ```Addsimps [mult_0_right,mult_Suc_right]; ``` clasohm@923 ` 124` clasohm@923 ` 125` ```(*Commutative law for multiplication*) ``` clasohm@923 ` 126` ```qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)" ``` clasohm@1264 ` 127` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 128` clasohm@923 ` 129` ```(*addition distributes over multiplication*) ``` clasohm@923 ` 130` ```qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)" ``` clasohm@923 ` 131` ``` (fn _ => [nat_ind_tac "m" 1, ``` clasohm@1264 ` 132` ``` ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); ``` clasohm@923 ` 133` clasohm@923 ` 134` ```qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)" ``` clasohm@923 ` 135` ``` (fn _ => [nat_ind_tac "m" 1, ``` clasohm@1264 ` 136` ``` ALLGOALS(asm_simp_tac (!simpset addsimps add_ac))]); ``` clasohm@923 ` 137` clasohm@1264 ` 138` ```Addsimps [add_mult_distrib,add_mult_distrib2]; ``` clasohm@923 ` 139` clasohm@923 ` 140` ```(*Associative law for multiplication*) ``` clasohm@923 ` 141` ```qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)" ``` clasohm@1264 ` 142` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` clasohm@923 ` 143` clasohm@923 ` 144` ```qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)" ``` clasohm@923 ` 145` ``` (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1, ``` clasohm@923 ` 146` ``` rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]); ``` clasohm@923 ` 147` clasohm@923 ` 148` ```val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; ``` clasohm@923 ` 149` clasohm@923 ` 150` ```(*** Difference ***) ``` clasohm@923 ` 151` clasohm@923 ` 152` ```qed_goal "diff_self_eq_0" Arith.thy "m - m = 0" ``` clasohm@1264 ` 153` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS Asm_simp_tac]); ``` nipkow@1496 ` 154` ```Addsimps [diff_self_eq_0]; ``` clasohm@923 ` 155` clasohm@923 ` 156` ```(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) ``` clasohm@923 ` 157` ```val [prem] = goal Arith.thy "[| ~ m n+(m-n) = (m::nat)"; ``` clasohm@923 ` 158` ```by (rtac (prem RS rev_mp) 1); ``` clasohm@923 ` 159` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@1264 ` 160` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 161` ```qed "add_diff_inverse"; ``` clasohm@923 ` 162` clasohm@923 ` 163` clasohm@923 ` 164` ```(*** Remainder ***) ``` clasohm@923 ` 165` clasohm@923 ` 166` ```goal Arith.thy "m - n < Suc(m)"; ``` clasohm@923 ` 167` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@923 ` 168` ```by (etac less_SucE 3); ``` clasohm@1264 ` 169` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 170` ```qed "diff_less_Suc"; ``` clasohm@923 ` 171` clasohm@923 ` 172` ```goal Arith.thy "!!m::nat. m - n <= m"; ``` clasohm@923 ` 173` ```by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); ``` clasohm@1264 ` 174` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 175` ```qed "diff_le_self"; ``` clasohm@923 ` 176` clasohm@923 ` 177` ```goal Arith.thy "!!n::nat. (n+m) - n = m"; ``` clasohm@923 ` 178` ```by (nat_ind_tac "n" 1); ``` clasohm@1264 ` 179` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 180` ```qed "diff_add_inverse"; ``` clasohm@923 ` 181` clasohm@923 ` 182` ```goal Arith.thy "!!n::nat. n - (n+m) = 0"; ``` clasohm@923 ` 183` ```by (nat_ind_tac "n" 1); ``` clasohm@1264 ` 184` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 185` ```qed "diff_add_0"; ``` clasohm@923 ` 186` clasohm@923 ` 187` ```(*In ordinary notation: if 0 m - n < m"; ``` clasohm@923 ` 189` ```by (subgoal_tac "0 ~ m m - n < m" 1); ``` clasohm@923 ` 190` ```by (fast_tac HOL_cs 1); ``` clasohm@923 ` 191` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@1264 ` 192` ```by (ALLGOALS(asm_simp_tac(!simpset addsimps [diff_less_Suc]))); ``` nipkow@1398 ` 193` ```qed "diff_less"; ``` clasohm@923 ` 194` clasohm@923 ` 195` ```val wf_less_trans = wf_pred_nat RS wf_trancl RSN (2, def_wfrec RS trans); ``` clasohm@923 ` 196` clasohm@972 ` 197` ```goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m m mod n = m"; ``` clasohm@1475 ` 207` ```by (rtac (mod_def1 RS wf_less_trans) 1); ``` paulson@1552 ` 208` ```by (Asm_simp_tac 1); ``` clasohm@923 ` 209` ```qed "mod_less"; ``` clasohm@923 ` 210` clasohm@923 ` 211` ```goal Arith.thy "!!m. [| 0 m mod n = (m-n) mod n"; ``` clasohm@1475 ` 212` ```by (rtac (mod_def1 RS wf_less_trans) 1); ``` paulson@1552 ` 213` ```by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1); ``` clasohm@923 ` 214` ```qed "mod_geq"; ``` clasohm@923 ` 215` clasohm@923 ` 216` clasohm@923 ` 217` ```(*** Quotient ***) ``` clasohm@923 ` 218` clasohm@1475 ` 219` ```goal Arith.thy "(%m. m div n) = wfrec (trancl pred_nat) \ ``` clasohm@1475 ` 220` ``` \ (%f j. if j m div n = 0"; ``` clasohm@1475 ` 225` ```by (rtac (div_def1 RS wf_less_trans) 1); ``` paulson@1552 ` 226` ```by (Asm_simp_tac 1); ``` clasohm@923 ` 227` ```qed "div_less"; ``` clasohm@923 ` 228` clasohm@923 ` 229` ```goal Arith.thy "!!M. [| 0 m div n = Suc((m-n) div n)"; ``` clasohm@1475 ` 230` ```by (rtac (div_def1 RS wf_less_trans) 1); ``` paulson@1552 ` 231` ```by (asm_simp_tac (!simpset addsimps [diff_less, cut_apply, less_eq]) 1); ``` clasohm@923 ` 232` ```qed "div_geq"; ``` clasohm@923 ` 233` clasohm@923 ` 234` ```(*Main Result about quotient and remainder.*) ``` clasohm@923 ` 235` ```goal Arith.thy "!!m. 0 (m div n)*n + m mod n = m"; ``` clasohm@923 ` 236` ```by (res_inst_tac [("n","m")] less_induct 1); ``` clasohm@923 ` 237` ```by (rename_tac "k" 1); (*Variable name used in line below*) ``` clasohm@923 ` 238` ```by (case_tac "k m-n = 0"; ``` clasohm@923 ` 248` ```by (rtac (prem RS rev_mp) 1); ``` clasohm@923 ` 249` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@1264 ` 250` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 251` ```qed "less_imp_diff_is_0"; ``` clasohm@923 ` 252` clasohm@923 ` 253` ```val prems = goal Arith.thy "m-n = 0 --> n-m = 0 --> m=n"; ``` clasohm@923 ` 254` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@1264 ` 255` ```by (REPEAT(Simp_tac 1 THEN TRY(atac 1))); ``` nipkow@1485 ` 256` ```qed_spec_mp "diffs0_imp_equal"; ``` clasohm@923 ` 257` clasohm@923 ` 258` ```val [prem] = goal Arith.thy "m 0 Suc(m)-n = Suc(m-n)"; ``` clasohm@923 ` 265` ```by (rtac (prem RS rev_mp) 1); ``` clasohm@923 ` 266` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@1264 ` 267` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 268` ```qed "Suc_diff_n"; ``` clasohm@923 ` 269` nipkow@1398 ` 270` ```goal Arith.thy "Suc(m)-n = (if m (!n. P(Suc(n))--> P(n)) --> P(k-i)"; ``` clasohm@923 ` 276` ```by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); ``` clasohm@1264 ` 277` ```by (ALLGOALS (strip_tac THEN' Simp_tac THEN' TRY o fast_tac HOL_cs)); ``` clasohm@923 ` 278` ```qed "zero_induct_lemma"; ``` clasohm@923 ` 279` clasohm@923 ` 280` ```val prems = goal Arith.thy "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; ``` clasohm@923 ` 281` ```by (rtac (diff_self_eq_0 RS subst) 1); ``` clasohm@923 ` 282` ```by (rtac (zero_induct_lemma RS mp RS mp) 1); ``` clasohm@923 ` 283` ```by (REPEAT (ares_tac ([impI,allI]@prems) 1)); ``` clasohm@923 ` 284` ```qed "zero_induct"; ``` clasohm@923 ` 285` clasohm@923 ` 286` ```(*13 July 1992: loaded in 105.7s*) ``` clasohm@923 ` 287` clasohm@923 ` 288` ```(**** Additional theorems about "less than" ****) ``` clasohm@923 ` 289` clasohm@923 ` 290` ```goal Arith.thy "!!m. m (? k. n=Suc(m+k))"; ``` clasohm@923 ` 291` ```by (nat_ind_tac "n" 1); ``` clasohm@1264 ` 292` ```by (ALLGOALS(Simp_tac)); ``` clasohm@923 ` 293` ```by (REPEAT_FIRST (ares_tac [conjI, impI])); ``` clasohm@923 ` 294` ```by (res_inst_tac [("x","0")] exI 2); ``` clasohm@1264 ` 295` ```by (Simp_tac 2); ``` clasohm@923 ` 296` ```by (safe_tac HOL_cs); ``` clasohm@923 ` 297` ```by (res_inst_tac [("x","Suc(k)")] exI 1); ``` clasohm@1264 ` 298` ```by (Simp_tac 1); ``` nipkow@1485 ` 299` ```qed_spec_mp "less_eq_Suc_add"; ``` clasohm@923 ` 300` clasohm@923 ` 301` ```goal Arith.thy "n <= ((m + n)::nat)"; ``` clasohm@923 ` 302` ```by (nat_ind_tac "m" 1); ``` clasohm@1264 ` 303` ```by (ALLGOALS Simp_tac); ``` clasohm@923 ` 304` ```by (etac le_trans 1); ``` clasohm@923 ` 305` ```by (rtac (lessI RS less_imp_le) 1); ``` clasohm@923 ` 306` ```qed "le_add2"; ``` clasohm@923 ` 307` clasohm@923 ` 308` ```goal Arith.thy "n <= ((n + m)::nat)"; ``` clasohm@1264 ` 309` ```by (simp_tac (!simpset addsimps add_ac) 1); ``` clasohm@923 ` 310` ```by (rtac le_add2 1); ``` clasohm@923 ` 311` ```qed "le_add1"; ``` clasohm@923 ` 312` clasohm@923 ` 313` ```bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); ``` clasohm@923 ` 314` ```bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); ``` clasohm@923 ` 315` clasohm@923 ` 316` ```(*"i <= j ==> i <= j+m"*) ``` clasohm@923 ` 317` ```bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); ``` clasohm@923 ` 318` clasohm@923 ` 319` ```(*"i <= j ==> i <= m+j"*) ``` clasohm@923 ` 320` ```bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); ``` clasohm@923 ` 321` clasohm@923 ` 322` ```(*"i < j ==> i < j+m"*) ``` clasohm@923 ` 323` ```bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); ``` clasohm@923 ` 324` clasohm@923 ` 325` ```(*"i < j ==> i < m+j"*) ``` clasohm@923 ` 326` ```bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); ``` clasohm@923 ` 327` nipkow@1152 ` 328` ```goal Arith.thy "!!i. i+j < (k::nat) ==> i m <= n+k"; ``` paulson@1552 ` 336` ```by (etac le_trans 1); ``` paulson@1552 ` 337` ```by (rtac le_add1 1); ``` clasohm@923 ` 338` ```qed "le_imp_add_le"; ``` clasohm@923 ` 339` clasohm@923 ` 340` ```goal Arith.thy "!!k::nat. m < n ==> m < n+k"; ``` paulson@1552 ` 341` ```by (etac less_le_trans 1); ``` paulson@1552 ` 342` ```by (rtac le_add1 1); ``` clasohm@923 ` 343` ```qed "less_imp_add_less"; ``` clasohm@923 ` 344` clasohm@923 ` 345` ```goal Arith.thy "m+k<=n --> m<=(n::nat)"; ``` clasohm@923 ` 346` ```by (nat_ind_tac "k" 1); ``` clasohm@1264 ` 347` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 348` ```by (fast_tac (HOL_cs addDs [Suc_leD]) 1); ``` nipkow@1485 ` 349` ```qed_spec_mp "add_leD1"; ``` clasohm@923 ` 350` clasohm@923 ` 351` ```goal Arith.thy "!!k l::nat. [| k m i + k < j + k"; ``` clasohm@923 ` 367` ```by (nat_ind_tac "k" 1); ``` clasohm@1264 ` 368` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 369` ```qed "add_less_mono1"; ``` clasohm@923 ` 370` clasohm@923 ` 371` ```(*strict, in both arguments*) ``` clasohm@923 ` 372` ```goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l"; ``` clasohm@923 ` 373` ```by (rtac (add_less_mono1 RS less_trans) 1); ``` lcp@1198 ` 374` ```by (REPEAT (assume_tac 1)); ``` clasohm@923 ` 375` ```by (nat_ind_tac "j" 1); ``` clasohm@1264 ` 376` ```by (ALLGOALS Asm_simp_tac); ``` clasohm@923 ` 377` ```qed "add_less_mono"; ``` clasohm@923 ` 378` clasohm@923 ` 379` ```(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) ``` clasohm@923 ` 380` ```val [lt_mono,le] = goal Arith.thy ``` clasohm@1465 ` 381` ``` "[| !!i j::nat. i f(i) < f(j); \ ``` clasohm@1465 ` 382` ```\ i <= j \ ``` clasohm@923 ` 383` ```\ |] ==> f(i) <= (f(j)::nat)"; ``` clasohm@923 ` 384` ```by (cut_facts_tac [le] 1); ``` clasohm@1264 ` 385` ```by (asm_full_simp_tac (!simpset addsimps [le_eq_less_or_eq]) 1); ``` clasohm@923 ` 386` ```by (fast_tac (HOL_cs addSIs [lt_mono]) 1); ``` clasohm@923 ` 387` ```qed "less_mono_imp_le_mono"; ``` clasohm@923 ` 388` clasohm@923 ` 389` ```(*non-strict, in 1st argument*) ``` clasohm@923 ` 390` ```goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k"; ``` clasohm@923 ` 391` ```by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1); ``` paulson@1552 ` 392` ```by (etac add_less_mono1 1); ``` clasohm@923 ` 393` ```by (assume_tac 1); ``` clasohm@923 ` 394` ```qed "add_le_mono1"; ``` clasohm@923 ` 395` clasohm@923 ` 396` ```(*non-strict, in both arguments*) ``` clasohm@923 ` 397` ```goal Arith.thy "!!k l::nat. [|i<=j; k<=l |] ==> i + k <= j + l"; ``` clasohm@923 ` 398` ```by (etac (add_le_mono1 RS le_trans) 1); ``` clasohm@1264 ` 399` ```by (simp_tac (!simpset addsimps [add_commute]) 1); ``` clasohm@923 ` 400` ```(*j moves to the end because it is free while k, l are bound*) ``` paulson@1552 ` 401` ```by (etac add_le_mono1 1); ``` clasohm@923 ` 402` ```qed "add_le_mono"; ```