src/HOL/Arith.ML
 author nipkow Thu Jun 22 12:44:29 1995 +0200 (1995-06-22) changeset 1152 b6e1e74695f6 parent 972 e61b058d58d2 child 1198 23be92d5bf4d permissions -rw-r--r--
 clasohm@923 ` 1` ```(* Title: HOL/Arith.ML ``` clasohm@923 ` 2` ``` ID: \$Id\$ ``` clasohm@923 ` 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; ``` clasohm@923 ` 17` clasohm@923 ` 18` ```(** Difference **) ``` clasohm@923 ` 19` clasohm@923 ` 20` ```val diff_0 = diff_def RS def_nat_rec_0; ``` clasohm@923 ` 21` clasohm@923 ` 22` ```qed_goalw "diff_0_eq_0" Arith.thy [diff_def, pred_def] ``` clasohm@923 ` 23` ``` "0 - n = 0" ``` clasohm@923 ` 24` ``` (fn _ => [nat_ind_tac "n" 1, ALLGOALS(asm_simp_tac nat_ss)]); ``` clasohm@923 ` 25` clasohm@923 ` 26` ```(*Must simplify BEFORE the induction!! (Else we get a critical pair) ``` clasohm@923 ` 27` ``` Suc(m) - Suc(n) rewrites to pred(Suc(m) - n) *) ``` clasohm@923 ` 28` ```qed_goalw "diff_Suc_Suc" Arith.thy [diff_def, pred_def] ``` clasohm@923 ` 29` ``` "Suc(m) - Suc(n) = m - n" ``` clasohm@923 ` 30` ``` (fn _ => ``` clasohm@923 ` 31` ``` [simp_tac nat_ss 1, nat_ind_tac "n" 1, ALLGOALS(asm_simp_tac nat_ss)]); ``` clasohm@923 ` 32` clasohm@923 ` 33` ```(*** Simplification over add, mult, diff ***) ``` clasohm@923 ` 34` clasohm@923 ` 35` ```val arith_simps = ``` clasohm@923 ` 36` ``` [pred_0, pred_Suc, add_0, add_Suc, mult_0, mult_Suc, ``` clasohm@923 ` 37` ``` diff_0, diff_0_eq_0, diff_Suc_Suc]; ``` clasohm@923 ` 38` clasohm@923 ` 39` ```val arith_ss = nat_ss addsimps arith_simps; ``` clasohm@923 ` 40` clasohm@923 ` 41` ```(**** Inductive properties of the operators ****) ``` clasohm@923 ` 42` clasohm@923 ` 43` ```(*** Addition ***) ``` clasohm@923 ` 44` clasohm@923 ` 45` ```qed_goal "add_0_right" Arith.thy "m + 0 = m" ``` clasohm@923 ` 46` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS(asm_simp_tac arith_ss)]); ``` clasohm@923 ` 47` clasohm@923 ` 48` ```qed_goal "add_Suc_right" Arith.thy "m + Suc(n) = Suc(m+n)" ``` clasohm@923 ` 49` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS(asm_simp_tac arith_ss)]); ``` clasohm@923 ` 50` clasohm@923 ` 51` ```val arith_ss = arith_ss addsimps [add_0_right,add_Suc_right]; ``` clasohm@923 ` 52` clasohm@923 ` 53` ```(*Associative law for addition*) ``` clasohm@923 ` 54` ```qed_goal "add_assoc" Arith.thy "(m + n) + k = m + ((n + k)::nat)" ``` clasohm@923 ` 55` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS(asm_simp_tac arith_ss)]); ``` clasohm@923 ` 56` clasohm@923 ` 57` ```(*Commutative law for addition*) ``` clasohm@923 ` 58` ```qed_goal "add_commute" Arith.thy "m + n = n + (m::nat)" ``` clasohm@923 ` 59` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS(asm_simp_tac arith_ss)]); ``` clasohm@923 ` 60` clasohm@923 ` 61` ```qed_goal "add_left_commute" Arith.thy "x+(y+z)=y+((x+z)::nat)" ``` clasohm@923 ` 62` ``` (fn _ => [rtac (add_commute RS trans) 1, rtac (add_assoc RS trans) 1, ``` clasohm@923 ` 63` ``` rtac (add_commute RS arg_cong) 1]); ``` clasohm@923 ` 64` clasohm@923 ` 65` ```(*Addition is an AC-operator*) ``` clasohm@923 ` 66` ```val add_ac = [add_assoc, add_commute, add_left_commute]; ``` clasohm@923 ` 67` clasohm@923 ` 68` ```goal Arith.thy "!!k::nat. (k + m = k + n) = (m=n)"; ``` clasohm@923 ` 69` ```by (nat_ind_tac "k" 1); ``` clasohm@923 ` 70` ```by (simp_tac arith_ss 1); ``` clasohm@923 ` 71` ```by (asm_simp_tac arith_ss 1); ``` clasohm@923 ` 72` ```qed "add_left_cancel"; ``` clasohm@923 ` 73` clasohm@923 ` 74` ```goal Arith.thy "!!k::nat. (m + k = n + k) = (m=n)"; ``` clasohm@923 ` 75` ```by (nat_ind_tac "k" 1); ``` clasohm@923 ` 76` ```by (simp_tac arith_ss 1); ``` clasohm@923 ` 77` ```by (asm_simp_tac arith_ss 1); ``` clasohm@923 ` 78` ```qed "add_right_cancel"; ``` clasohm@923 ` 79` clasohm@923 ` 80` ```goal Arith.thy "!!k::nat. (k + m <= k + n) = (m<=n)"; ``` clasohm@923 ` 81` ```by (nat_ind_tac "k" 1); ``` clasohm@923 ` 82` ```by (simp_tac arith_ss 1); ``` clasohm@923 ` 83` ```by (asm_simp_tac (arith_ss addsimps [Suc_le_mono]) 1); ``` clasohm@923 ` 84` ```qed "add_left_cancel_le"; ``` clasohm@923 ` 85` clasohm@923 ` 86` ```goal Arith.thy "!!k::nat. (k + m < k + n) = (m [nat_ind_tac "m" 1, ALLGOALS(asm_simp_tac arith_ss)]); ``` clasohm@923 ` 97` clasohm@923 ` 98` ```(*right Sucessor law for multiplication*) ``` clasohm@923 ` 99` ```qed_goal "mult_Suc_right" Arith.thy "m * Suc(n) = m + (m * n)" ``` clasohm@923 ` 100` ``` (fn _ => [nat_ind_tac "m" 1, ``` clasohm@923 ` 101` ``` ALLGOALS(asm_simp_tac (arith_ss addsimps add_ac))]); ``` clasohm@923 ` 102` clasohm@923 ` 103` ```val arith_ss = arith_ss addsimps [mult_0_right,mult_Suc_right]; ``` clasohm@923 ` 104` clasohm@923 ` 105` ```(*Commutative law for multiplication*) ``` clasohm@923 ` 106` ```qed_goal "mult_commute" Arith.thy "m * n = n * (m::nat)" ``` clasohm@923 ` 107` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS (asm_simp_tac arith_ss)]); ``` clasohm@923 ` 108` clasohm@923 ` 109` ```(*addition distributes over multiplication*) ``` clasohm@923 ` 110` ```qed_goal "add_mult_distrib" Arith.thy "(m + n)*k = (m*k) + ((n*k)::nat)" ``` clasohm@923 ` 111` ``` (fn _ => [nat_ind_tac "m" 1, ``` clasohm@923 ` 112` ``` ALLGOALS(asm_simp_tac (arith_ss addsimps add_ac))]); ``` clasohm@923 ` 113` clasohm@923 ` 114` ```qed_goal "add_mult_distrib2" Arith.thy "k*(m + n) = (k*m) + ((k*n)::nat)" ``` clasohm@923 ` 115` ``` (fn _ => [nat_ind_tac "m" 1, ``` clasohm@923 ` 116` ``` ALLGOALS(asm_simp_tac (arith_ss addsimps add_ac))]); ``` clasohm@923 ` 117` clasohm@923 ` 118` ```val arith_ss = arith_ss addsimps [add_mult_distrib,add_mult_distrib2]; ``` clasohm@923 ` 119` clasohm@923 ` 120` ```(*Associative law for multiplication*) ``` clasohm@923 ` 121` ```qed_goal "mult_assoc" Arith.thy "(m * n) * k = m * ((n * k)::nat)" ``` clasohm@923 ` 122` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS(asm_simp_tac arith_ss)]); ``` clasohm@923 ` 123` clasohm@923 ` 124` ```qed_goal "mult_left_commute" Arith.thy "x*(y*z) = y*((x*z)::nat)" ``` clasohm@923 ` 125` ``` (fn _ => [rtac trans 1, rtac mult_commute 1, rtac trans 1, ``` clasohm@923 ` 126` ``` rtac mult_assoc 1, rtac (mult_commute RS arg_cong) 1]); ``` clasohm@923 ` 127` clasohm@923 ` 128` ```val mult_ac = [mult_assoc,mult_commute,mult_left_commute]; ``` clasohm@923 ` 129` clasohm@923 ` 130` ```(*** Difference ***) ``` clasohm@923 ` 131` clasohm@923 ` 132` ```qed_goal "diff_self_eq_0" Arith.thy "m - m = 0" ``` clasohm@923 ` 133` ``` (fn _ => [nat_ind_tac "m" 1, ALLGOALS(asm_simp_tac arith_ss)]); ``` clasohm@923 ` 134` clasohm@923 ` 135` ```(*Addition is the inverse of subtraction: if n<=m then n+(m-n) = m. *) ``` clasohm@923 ` 136` ```val [prem] = goal Arith.thy "[| ~ m n+(m-n) = (m::nat)"; ``` clasohm@923 ` 137` ```by (rtac (prem RS rev_mp) 1); ``` clasohm@923 ` 138` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@923 ` 139` ```by (ALLGOALS(asm_simp_tac arith_ss)); ``` clasohm@923 ` 140` ```qed "add_diff_inverse"; ``` clasohm@923 ` 141` clasohm@923 ` 142` clasohm@923 ` 143` ```(*** Remainder ***) ``` clasohm@923 ` 144` clasohm@923 ` 145` ```goal Arith.thy "m - n < Suc(m)"; ``` clasohm@923 ` 146` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@923 ` 147` ```by (etac less_SucE 3); ``` clasohm@923 ` 148` ```by (ALLGOALS(asm_simp_tac arith_ss)); ``` clasohm@923 ` 149` ```qed "diff_less_Suc"; ``` clasohm@923 ` 150` clasohm@923 ` 151` ```goal Arith.thy "!!m::nat. m - n <= m"; ``` clasohm@923 ` 152` ```by (res_inst_tac [("m","m"), ("n","n")] diff_induct 1); ``` clasohm@923 ` 153` ```by (ALLGOALS (asm_simp_tac arith_ss)); ``` clasohm@923 ` 154` ```by (etac le_trans 1); ``` clasohm@923 ` 155` ```by (simp_tac (HOL_ss addsimps [le_eq_less_or_eq, lessI]) 1); ``` clasohm@923 ` 156` ```qed "diff_le_self"; ``` clasohm@923 ` 157` clasohm@923 ` 158` ```goal Arith.thy "!!n::nat. (n+m) - n = m"; ``` clasohm@923 ` 159` ```by (nat_ind_tac "n" 1); ``` clasohm@923 ` 160` ```by (ALLGOALS (asm_simp_tac arith_ss)); ``` clasohm@923 ` 161` ```qed "diff_add_inverse"; ``` clasohm@923 ` 162` clasohm@923 ` 163` ```goal Arith.thy "!!n::nat. n - (n+m) = 0"; ``` clasohm@923 ` 164` ```by (nat_ind_tac "n" 1); ``` clasohm@923 ` 165` ```by (ALLGOALS (asm_simp_tac arith_ss)); ``` clasohm@923 ` 166` ```qed "diff_add_0"; ``` clasohm@923 ` 167` clasohm@923 ` 168` ```(*In ordinary notation: if 0 m - n < m"; ``` clasohm@923 ` 170` ```by (subgoal_tac "0 ~ m m - n < m" 1); ``` clasohm@923 ` 171` ```by (fast_tac HOL_cs 1); ``` clasohm@923 ` 172` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@923 ` 173` ```by (ALLGOALS(asm_simp_tac(arith_ss addsimps [diff_less_Suc]))); ``` clasohm@923 ` 174` ```qed "div_termination"; ``` clasohm@923 ` 175` clasohm@923 ` 176` ```val wf_less_trans = wf_pred_nat RS wf_trancl RSN (2, def_wfrec RS trans); ``` clasohm@923 ` 177` clasohm@972 ` 178` ```goalw Nat.thy [less_def] "(m,n) : pred_nat^+ = (m m mod n = m"; ``` clasohm@923 ` 183` ```by (rtac (mod_def RS wf_less_trans) 1); ``` clasohm@923 ` 184` ```by(asm_simp_tac HOL_ss 1); ``` clasohm@923 ` 185` ```qed "mod_less"; ``` clasohm@923 ` 186` clasohm@923 ` 187` ```goal Arith.thy "!!m. [| 0 m mod n = (m-n) mod n"; ``` clasohm@923 ` 188` ```by (rtac (mod_def RS wf_less_trans) 1); ``` clasohm@923 ` 189` ```by(asm_simp_tac (nat_ss addsimps [div_termination, cut_apply, less_eq]) 1); ``` clasohm@923 ` 190` ```qed "mod_geq"; ``` clasohm@923 ` 191` clasohm@923 ` 192` clasohm@923 ` 193` ```(*** Quotient ***) ``` clasohm@923 ` 194` clasohm@923 ` 195` ```goal Arith.thy "!!m. m m div n = 0"; ``` clasohm@923 ` 196` ```by (rtac (div_def RS wf_less_trans) 1); ``` clasohm@923 ` 197` ```by(asm_simp_tac nat_ss 1); ``` clasohm@923 ` 198` ```qed "div_less"; ``` clasohm@923 ` 199` clasohm@923 ` 200` ```goal Arith.thy "!!M. [| 0 m div n = Suc((m-n) div n)"; ``` clasohm@923 ` 201` ```by (rtac (div_def RS wf_less_trans) 1); ``` clasohm@923 ` 202` ```by(asm_simp_tac (nat_ss addsimps [div_termination, cut_apply, less_eq]) 1); ``` clasohm@923 ` 203` ```qed "div_geq"; ``` clasohm@923 ` 204` clasohm@923 ` 205` ```(*Main Result about quotient and remainder.*) ``` clasohm@923 ` 206` ```goal Arith.thy "!!m. 0 (m div n)*n + m mod n = m"; ``` clasohm@923 ` 207` ```by (res_inst_tac [("n","m")] less_induct 1); ``` clasohm@923 ` 208` ```by (rename_tac "k" 1); (*Variable name used in line below*) ``` clasohm@923 ` 209` ```by (case_tac "k m-n = 0"; ``` clasohm@923 ` 219` ```by (rtac (prem RS rev_mp) 1); ``` clasohm@923 ` 220` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@923 ` 221` ```by (ALLGOALS (asm_simp_tac arith_ss)); ``` clasohm@923 ` 222` ```qed "less_imp_diff_is_0"; ``` clasohm@923 ` 223` clasohm@923 ` 224` ```val prems = goal Arith.thy "m-n = 0 --> n-m = 0 --> m=n"; ``` clasohm@923 ` 225` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@923 ` 226` ```by (REPEAT(simp_tac arith_ss 1 THEN TRY(atac 1))); ``` clasohm@923 ` 227` ```qed "diffs0_imp_equal_lemma"; ``` clasohm@923 ` 228` clasohm@923 ` 229` ```(* [| m-n = 0; n-m = 0 |] ==> m=n *) ``` clasohm@923 ` 230` ```bind_thm ("diffs0_imp_equal", (diffs0_imp_equal_lemma RS mp RS mp)); ``` clasohm@923 ` 231` clasohm@923 ` 232` ```val [prem] = goal Arith.thy "m 0 Suc(m)-n = Suc(m-n)"; ``` clasohm@923 ` 239` ```by (rtac (prem RS rev_mp) 1); ``` clasohm@923 ` 240` ```by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); ``` clasohm@923 ` 241` ```by (ALLGOALS(asm_simp_tac arith_ss)); ``` clasohm@923 ` 242` ```qed "Suc_diff_n"; ``` clasohm@923 ` 243` clasohm@965 ` 244` ```goal Arith.thy "Suc(m)-n = (if m (!n. P(Suc(n))--> P(n)) --> P(k-i)"; ``` clasohm@923 ` 250` ```by (res_inst_tac [("m","k"),("n","i")] diff_induct 1); ``` clasohm@923 ` 251` ```by (ALLGOALS (strip_tac THEN' simp_tac arith_ss THEN' TRY o fast_tac HOL_cs)); ``` clasohm@923 ` 252` ```qed "zero_induct_lemma"; ``` clasohm@923 ` 253` clasohm@923 ` 254` ```val prems = goal Arith.thy "[| P(k); !!n. P(Suc(n)) ==> P(n) |] ==> P(0)"; ``` clasohm@923 ` 255` ```by (rtac (diff_self_eq_0 RS subst) 1); ``` clasohm@923 ` 256` ```by (rtac (zero_induct_lemma RS mp RS mp) 1); ``` clasohm@923 ` 257` ```by (REPEAT (ares_tac ([impI,allI]@prems) 1)); ``` clasohm@923 ` 258` ```qed "zero_induct"; ``` clasohm@923 ` 259` clasohm@923 ` 260` ```(*13 July 1992: loaded in 105.7s*) ``` clasohm@923 ` 261` clasohm@923 ` 262` ```(**** Additional theorems about "less than" ****) ``` clasohm@923 ` 263` clasohm@923 ` 264` ```goal Arith.thy "!!m. m (? k. n=Suc(m+k))"; ``` clasohm@923 ` 265` ```by (nat_ind_tac "n" 1); ``` clasohm@923 ` 266` ```by (ALLGOALS(simp_tac arith_ss)); ``` clasohm@923 ` 267` ```by (REPEAT_FIRST (ares_tac [conjI, impI])); ``` clasohm@923 ` 268` ```by (res_inst_tac [("x","0")] exI 2); ``` clasohm@923 ` 269` ```by (simp_tac arith_ss 2); ``` clasohm@923 ` 270` ```by (safe_tac HOL_cs); ``` clasohm@923 ` 271` ```by (res_inst_tac [("x","Suc(k)")] exI 1); ``` clasohm@923 ` 272` ```by (simp_tac arith_ss 1); ``` clasohm@923 ` 273` ```val less_eq_Suc_add_lemma = result(); ``` clasohm@923 ` 274` clasohm@923 ` 275` ```(*"m ? k. n = Suc(m+k)"*) ``` clasohm@923 ` 276` ```bind_thm ("less_eq_Suc_add", less_eq_Suc_add_lemma RS mp); ``` clasohm@923 ` 277` clasohm@923 ` 278` clasohm@923 ` 279` ```goal Arith.thy "n <= ((m + n)::nat)"; ``` clasohm@923 ` 280` ```by (nat_ind_tac "m" 1); ``` clasohm@923 ` 281` ```by (ALLGOALS(simp_tac arith_ss)); ``` clasohm@923 ` 282` ```by (etac le_trans 1); ``` clasohm@923 ` 283` ```by (rtac (lessI RS less_imp_le) 1); ``` clasohm@923 ` 284` ```qed "le_add2"; ``` clasohm@923 ` 285` clasohm@923 ` 286` ```goal Arith.thy "n <= ((n + m)::nat)"; ``` clasohm@923 ` 287` ```by (simp_tac (arith_ss addsimps add_ac) 1); ``` clasohm@923 ` 288` ```by (rtac le_add2 1); ``` clasohm@923 ` 289` ```qed "le_add1"; ``` clasohm@923 ` 290` clasohm@923 ` 291` ```bind_thm ("less_add_Suc1", (lessI RS (le_add1 RS le_less_trans))); ``` clasohm@923 ` 292` ```bind_thm ("less_add_Suc2", (lessI RS (le_add2 RS le_less_trans))); ``` clasohm@923 ` 293` clasohm@923 ` 294` ```(*"i <= j ==> i <= j+m"*) ``` clasohm@923 ` 295` ```bind_thm ("trans_le_add1", le_add1 RSN (2,le_trans)); ``` clasohm@923 ` 296` clasohm@923 ` 297` ```(*"i <= j ==> i <= m+j"*) ``` clasohm@923 ` 298` ```bind_thm ("trans_le_add2", le_add2 RSN (2,le_trans)); ``` clasohm@923 ` 299` clasohm@923 ` 300` ```(*"i < j ==> i < j+m"*) ``` clasohm@923 ` 301` ```bind_thm ("trans_less_add1", le_add1 RSN (2,less_le_trans)); ``` clasohm@923 ` 302` clasohm@923 ` 303` ```(*"i < j ==> i < m+j"*) ``` clasohm@923 ` 304` ```bind_thm ("trans_less_add2", le_add2 RSN (2,less_le_trans)); ``` clasohm@923 ` 305` nipkow@1152 ` 306` ```goal Arith.thy "!!i. i+j < (k::nat) ==> i m <= n+k"; ``` clasohm@923 ` 314` ```by (eresolve_tac [le_trans] 1); ``` clasohm@923 ` 315` ```by (resolve_tac [le_add1] 1); ``` clasohm@923 ` 316` ```qed "le_imp_add_le"; ``` clasohm@923 ` 317` clasohm@923 ` 318` ```goal Arith.thy "!!k::nat. m < n ==> m < n+k"; ``` clasohm@923 ` 319` ```by (eresolve_tac [less_le_trans] 1); ``` clasohm@923 ` 320` ```by (resolve_tac [le_add1] 1); ``` clasohm@923 ` 321` ```qed "less_imp_add_less"; ``` clasohm@923 ` 322` clasohm@923 ` 323` ```goal Arith.thy "m+k<=n --> m<=(n::nat)"; ``` clasohm@923 ` 324` ```by (nat_ind_tac "k" 1); ``` clasohm@923 ` 325` ```by (ALLGOALS (asm_simp_tac arith_ss)); ``` clasohm@923 ` 326` ```by (fast_tac (HOL_cs addDs [Suc_leD]) 1); ``` clasohm@923 ` 327` ```val add_leD1_lemma = result(); ``` clasohm@923 ` 328` ```bind_thm ("add_leD1", add_leD1_lemma RS mp);; ``` clasohm@923 ` 329` clasohm@923 ` 330` ```goal Arith.thy "!!k l::nat. [| k m i + k < j + k"; ``` clasohm@923 ` 345` ```by (nat_ind_tac "k" 1); ``` clasohm@923 ` 346` ```by (ALLGOALS (asm_simp_tac arith_ss)); ``` clasohm@923 ` 347` ```qed "add_less_mono1"; ``` clasohm@923 ` 348` clasohm@923 ` 349` ```(*strict, in both arguments*) ``` clasohm@923 ` 350` ```goal Arith.thy "!!i j k::nat. [|i < j; k < l|] ==> i + k < j + l"; ``` clasohm@923 ` 351` ```by (rtac (add_less_mono1 RS less_trans) 1); ``` clasohm@923 ` 352` ```by (REPEAT (etac asm_rl 1)); ``` clasohm@923 ` 353` ```by (nat_ind_tac "j" 1); ``` clasohm@923 ` 354` ```by (ALLGOALS(asm_simp_tac arith_ss)); ``` clasohm@923 ` 355` ```qed "add_less_mono"; ``` clasohm@923 ` 356` clasohm@923 ` 357` ```(*A [clumsy] way of lifting < monotonicity to <= monotonicity *) ``` clasohm@923 ` 358` ```val [lt_mono,le] = goal Arith.thy ``` clasohm@923 ` 359` ``` "[| !!i j::nat. i f(i) < f(j); \ ``` clasohm@923 ` 360` ```\ i <= j \ ``` clasohm@923 ` 361` ```\ |] ==> f(i) <= (f(j)::nat)"; ``` clasohm@923 ` 362` ```by (cut_facts_tac [le] 1); ``` clasohm@923 ` 363` ```by (asm_full_simp_tac (HOL_ss addsimps [le_eq_less_or_eq]) 1); ``` clasohm@923 ` 364` ```by (fast_tac (HOL_cs addSIs [lt_mono]) 1); ``` clasohm@923 ` 365` ```qed "less_mono_imp_le_mono"; ``` clasohm@923 ` 366` clasohm@923 ` 367` ```(*non-strict, in 1st argument*) ``` clasohm@923 ` 368` ```goal Arith.thy "!!i j k::nat. i<=j ==> i + k <= j + k"; ``` clasohm@923 ` 369` ```by (res_inst_tac [("f", "%j.j+k")] less_mono_imp_le_mono 1); ``` clasohm@923 ` 370` ```by (eresolve_tac [add_less_mono1] 1); ``` clasohm@923 ` 371` ```by (assume_tac 1); ``` clasohm@923 ` 372` ```qed "add_le_mono1"; ``` clasohm@923 ` 373` clasohm@923 ` 374` ```(*non-strict, in both arguments*) ``` clasohm@923 ` 375` ```goal Arith.thy "!!k l::nat. [|i<=j; k<=l |] ==> i + k <= j + l"; ``` clasohm@923 ` 376` ```by (etac (add_le_mono1 RS le_trans) 1); ``` clasohm@923 ` 377` ```by (simp_tac (HOL_ss addsimps [add_commute]) 1); ``` clasohm@923 ` 378` ```(*j moves to the end because it is free while k, l are bound*) ``` clasohm@923 ` 379` ```by (eresolve_tac [add_le_mono1] 1); ``` clasohm@923 ` 380` ```qed "add_le_mono"; ```