src/HOL/Word/Misc_Numeric.thy
changeset 37655 f4d616d41a59
parent 37591 d3daea901123
child 37887 2ae085b07f2f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Word/Misc_Numeric.thy	Wed Jun 30 16:28:14 2010 +0200
     1.3 @@ -0,0 +1,450 @@
     1.4 +(* 
     1.5 +  Author:  Jeremy Dawson, NICTA
     1.6 +*) 
     1.7 +
     1.8 +header {* Useful Numerical Lemmas *}
     1.9 +
    1.10 +theory Misc_Numeric
    1.11 +imports Main Parity
    1.12 +begin
    1.13 +
    1.14 +lemma contentsI: "y = {x} ==> contents y = x" 
    1.15 +  unfolding contents_def by auto -- {* FIXME move *}
    1.16 +
    1.17 +lemmas split_split = prod.split
    1.18 +lemmas split_split_asm = prod.split_asm
    1.19 +lemmas split_splits = split_split split_split_asm
    1.20 +
    1.21 +lemmas funpow_0 = funpow.simps(1)
    1.22 +lemmas funpow_Suc = funpow.simps(2)
    1.23 +
    1.24 +lemma nonemptyE: "S ~= {} ==> (!!x. x : S ==> R) ==> R" by auto
    1.25 +
    1.26 +lemma gt_or_eq_0: "0 < y \<or> 0 = (y::nat)" by arith 
    1.27 +
    1.28 +declare iszero_0 [iff]
    1.29 +
    1.30 +lemmas xtr1 = xtrans(1)
    1.31 +lemmas xtr2 = xtrans(2)
    1.32 +lemmas xtr3 = xtrans(3)
    1.33 +lemmas xtr4 = xtrans(4)
    1.34 +lemmas xtr5 = xtrans(5)
    1.35 +lemmas xtr6 = xtrans(6)
    1.36 +lemmas xtr7 = xtrans(7)
    1.37 +lemmas xtr8 = xtrans(8)
    1.38 +
    1.39 +lemmas nat_simps = diff_add_inverse2 diff_add_inverse
    1.40 +lemmas nat_iffs = le_add1 le_add2
    1.41 +
    1.42 +lemma sum_imp_diff: "j = k + i ==> j - i = (k :: nat)" by arith
    1.43 +
    1.44 +lemma nobm1:
    1.45 +  "0 < (number_of w :: nat) ==> 
    1.46 +   number_of w - (1 :: nat) = number_of (Int.pred w)" 
    1.47 +  apply (unfold nat_number_of_def One_nat_def nat_1 [symmetric] pred_def)
    1.48 +  apply (simp add: number_of_eq nat_diff_distrib [symmetric])
    1.49 +  done
    1.50 +
    1.51 +lemma zless2: "0 < (2 :: int)" by arith
    1.52 +
    1.53 +lemmas zless2p [simp] = zless2 [THEN zero_less_power]
    1.54 +lemmas zle2p [simp] = zless2p [THEN order_less_imp_le]
    1.55 +
    1.56 +lemmas pos_mod_sign2 = zless2 [THEN pos_mod_sign [where b = "2::int"]]
    1.57 +lemmas pos_mod_bound2 = zless2 [THEN pos_mod_bound [where b = "2::int"]]
    1.58 +
    1.59 +-- "the inverse(s) of @{text number_of}"
    1.60 +lemma nmod2: "n mod (2::int) = 0 | n mod 2 = 1" by arith
    1.61 +
    1.62 +lemma emep1:
    1.63 +  "even n ==> even d ==> 0 <= d ==> (n + 1) mod (d :: int) = (n mod d) + 1"
    1.64 +  apply (simp add: add_commute)
    1.65 +  apply (safe dest!: even_equiv_def [THEN iffD1])
    1.66 +  apply (subst pos_zmod_mult_2)
    1.67 +   apply arith
    1.68 +  apply (simp add: mod_mult_mult1)
    1.69 + done
    1.70 +
    1.71 +lemmas eme1p = emep1 [simplified add_commute]
    1.72 +
    1.73 +lemma le_diff_eq': "(a \<le> c - b) = (b + a \<le> (c::int))" by arith
    1.74 +
    1.75 +lemma less_diff_eq': "(a < c - b) = (b + a < (c::int))" by arith
    1.76 +
    1.77 +lemma diff_le_eq': "(a - b \<le> c) = (a \<le> b + (c::int))" by arith
    1.78 +
    1.79 +lemma diff_less_eq': "(a - b < c) = (a < b + (c::int))" by arith
    1.80 +
    1.81 +lemmas m1mod2k = zless2p [THEN zmod_minus1]
    1.82 +lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1]
    1.83 +lemmas p1mod22k' = zless2p [THEN order_less_imp_le, THEN pos_zmod_mult_2]
    1.84 +lemmas z1pmod2' = zero_le_one [THEN pos_zmod_mult_2, simplified]
    1.85 +lemmas z1pdiv2' = zero_le_one [THEN pos_zdiv_mult_2, simplified]
    1.86 +
    1.87 +lemma p1mod22k:
    1.88 +  "(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + (1::int)"
    1.89 +  by (simp add: p1mod22k' add_commute)
    1.90 +
    1.91 +lemma z1pmod2:
    1.92 +  "(2 * b + 1) mod 2 = (1::int)" by arith
    1.93 +  
    1.94 +lemma z1pdiv2:
    1.95 +  "(2 * b + 1) div 2 = (b::int)" by arith
    1.96 +
    1.97 +lemmas zdiv_le_dividend = xtr3 [OF div_by_1 [symmetric] zdiv_mono2,
    1.98 +  simplified int_one_le_iff_zero_less, simplified, standard]
    1.99 +  
   1.100 +lemma axxbyy:
   1.101 +  "a + m + m = b + n + n ==> (a = 0 | a = 1) ==> (b = 0 | b = 1) ==>  
   1.102 +   a = b & m = (n :: int)" by arith
   1.103 +
   1.104 +lemma axxmod2:
   1.105 +  "(1 + x + x) mod 2 = (1 :: int) & (0 + x + x) mod 2 = (0 :: int)" by arith
   1.106 +
   1.107 +lemma axxdiv2:
   1.108 +  "(1 + x + x) div 2 = (x :: int) & (0 + x + x) div 2 = (x :: int)"  by arith
   1.109 +
   1.110 +lemmas iszero_minus = trans [THEN trans,
   1.111 +  OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric], standard]
   1.112 +
   1.113 +lemmas zadd_diff_inverse = trans [OF diff_add_cancel [symmetric] add_commute,
   1.114 +  standard]
   1.115 +
   1.116 +lemmas add_diff_cancel2 = add_commute [THEN diff_eq_eq [THEN iffD2], standard]
   1.117 +
   1.118 +lemma zmod_uminus: "- ((a :: int) mod b) mod b = -a mod b"
   1.119 +  by (simp add : zmod_zminus1_eq_if)
   1.120 +
   1.121 +lemma zmod_zsub_distrib: "((a::int) - b) mod c = (a mod c - b mod c) mod c"
   1.122 +  apply (unfold diff_int_def)
   1.123 +  apply (rule trans [OF _ mod_add_eq [symmetric]])
   1.124 +  apply (simp add: zmod_uminus mod_add_eq [symmetric])
   1.125 +  done
   1.126 +
   1.127 +lemma zmod_zsub_right_eq: "((a::int) - b) mod c = (a - b mod c) mod c"
   1.128 +  apply (unfold diff_int_def)
   1.129 +  apply (rule trans [OF _ mod_add_right_eq [symmetric]])
   1.130 +  apply (simp add : zmod_uminus mod_add_right_eq [symmetric])
   1.131 +  done
   1.132 +
   1.133 +lemma zmod_zsub_left_eq: "((a::int) - b) mod c = (a mod c - b) mod c"
   1.134 +  by (rule mod_add_left_eq [where b = "- b", simplified diff_int_def [symmetric]])
   1.135 +
   1.136 +lemma zmod_zsub_self [simp]: 
   1.137 +  "((b :: int) - a) mod a = b mod a"
   1.138 +  by (simp add: zmod_zsub_right_eq)
   1.139 +
   1.140 +lemma zmod_zmult1_eq_rev:
   1.141 +  "b * a mod c = b mod c * a mod (c::int)"
   1.142 +  apply (simp add: mult_commute)
   1.143 +  apply (subst zmod_zmult1_eq)
   1.144 +  apply simp
   1.145 +  done
   1.146 +
   1.147 +lemmas rdmods [symmetric] = zmod_uminus [symmetric]
   1.148 +  zmod_zsub_left_eq zmod_zsub_right_eq mod_add_left_eq
   1.149 +  mod_add_right_eq zmod_zmult1_eq zmod_zmult1_eq_rev
   1.150 +
   1.151 +lemma mod_plus_right:
   1.152 +  "((a + x) mod m = (b + x) mod m) = (a mod m = b mod (m :: nat))"
   1.153 +  apply (induct x)
   1.154 +   apply (simp_all add: mod_Suc)
   1.155 +  apply arith
   1.156 +  done
   1.157 +
   1.158 +lemma nat_minus_mod: "(n - n mod m) mod m = (0 :: nat)"
   1.159 +  by (induct n) (simp_all add : mod_Suc)
   1.160 +
   1.161 +lemmas nat_minus_mod_plus_right = trans [OF nat_minus_mod mod_0 [symmetric],
   1.162 +  THEN mod_plus_right [THEN iffD2], standard, simplified]
   1.163 +
   1.164 +lemmas push_mods' = mod_add_eq [standard]
   1.165 +  mod_mult_eq [standard] zmod_zsub_distrib [standard]
   1.166 +  zmod_uminus [symmetric, standard]
   1.167 +
   1.168 +lemmas push_mods = push_mods' [THEN eq_reflection, standard]
   1.169 +lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection, standard]
   1.170 +lemmas mod_simps = 
   1.171 +  mod_mult_self2_is_0 [THEN eq_reflection]
   1.172 +  mod_mult_self1_is_0 [THEN eq_reflection]
   1.173 +  mod_mod_trivial [THEN eq_reflection]
   1.174 +
   1.175 +lemma nat_mod_eq:
   1.176 +  "!!b. b < n ==> a mod n = b mod n ==> a mod n = (b :: nat)" 
   1.177 +  by (induct a) auto
   1.178 +
   1.179 +lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]
   1.180 +
   1.181 +lemma nat_mod_lem: 
   1.182 +  "(0 :: nat) < n ==> b < n = (b mod n = b)"
   1.183 +  apply safe
   1.184 +   apply (erule nat_mod_eq')
   1.185 +  apply (erule subst)
   1.186 +  apply (erule mod_less_divisor)
   1.187 +  done
   1.188 +
   1.189 +lemma mod_nat_add: 
   1.190 +  "(x :: nat) < z ==> y < z ==> 
   1.191 +   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
   1.192 +  apply (rule nat_mod_eq)
   1.193 +   apply auto
   1.194 +  apply (rule trans)
   1.195 +   apply (rule le_mod_geq)
   1.196 +   apply simp
   1.197 +  apply (rule nat_mod_eq')
   1.198 +  apply arith
   1.199 +  done
   1.200 +
   1.201 +lemma mod_nat_sub: 
   1.202 +  "(x :: nat) < z ==> (x - y) mod z = x - y"
   1.203 +  by (rule nat_mod_eq') arith
   1.204 +
   1.205 +lemma int_mod_lem: 
   1.206 +  "(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)"
   1.207 +  apply safe
   1.208 +    apply (erule (1) mod_pos_pos_trivial)
   1.209 +   apply (erule_tac [!] subst)
   1.210 +   apply auto
   1.211 +  done
   1.212 +
   1.213 +lemma int_mod_eq:
   1.214 +  "(0 :: int) <= b ==> b < n ==> a mod n = b mod n ==> a mod n = b"
   1.215 +  by clarsimp (rule mod_pos_pos_trivial)
   1.216 +
   1.217 +lemmas int_mod_eq' = refl [THEN [3] int_mod_eq]
   1.218 +
   1.219 +lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a"
   1.220 +  apply (cases "a < n")
   1.221 +   apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a])
   1.222 +  done
   1.223 +
   1.224 +lemma int_mod_le': "0 <= b - n ==> 0 < (n :: int) ==> b mod n <= b - n"
   1.225 +  by (rule int_mod_le [where a = "b - n" and n = n, simplified])
   1.226 +
   1.227 +lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n"
   1.228 +  apply (cases "0 <= a")
   1.229 +   apply (drule (1) mod_pos_pos_trivial)
   1.230 +   apply simp
   1.231 +  apply (rule order_trans [OF _ pos_mod_sign])
   1.232 +   apply simp
   1.233 +  apply assumption
   1.234 +  done
   1.235 +
   1.236 +lemma int_mod_ge': "b < 0 ==> 0 < (n :: int) ==> b + n <= b mod n"
   1.237 +  by (rule int_mod_ge [where a = "b + n" and n = n, simplified])
   1.238 +
   1.239 +lemma mod_add_if_z:
   1.240 +  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
   1.241 +   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
   1.242 +  by (auto intro: int_mod_eq)
   1.243 +
   1.244 +lemma mod_sub_if_z:
   1.245 +  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
   1.246 +   (x - y) mod z = (if y <= x then x - y else x - y + z)"
   1.247 +  by (auto intro: int_mod_eq)
   1.248 +
   1.249 +lemmas zmde = zmod_zdiv_equality [THEN diff_eq_eq [THEN iffD2], symmetric]
   1.250 +lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule]
   1.251 +
   1.252 +(* already have this for naturals, div_mult_self1/2, but not for ints *)
   1.253 +lemma zdiv_mult_self: "m ~= (0 :: int) ==> (a + m * n) div m = a div m + n"
   1.254 +  apply (rule mcl)
   1.255 +   prefer 2
   1.256 +   apply (erule asm_rl)
   1.257 +  apply (simp add: zmde ring_distribs)
   1.258 +  done
   1.259 +
   1.260 +(** Rep_Integ **)
   1.261 +lemma eqne: "equiv A r ==> X : A // r ==> X ~= {}"
   1.262 +  unfolding equiv_def refl_on_def quotient_def Image_def by auto
   1.263 +
   1.264 +lemmas Rep_Integ_ne = Integ.Rep_Integ 
   1.265 +  [THEN equiv_intrel [THEN eqne, simplified Integ_def [symmetric]], standard]
   1.266 +
   1.267 +lemmas riq = Integ.Rep_Integ [simplified Integ_def]
   1.268 +lemmas intrel_refl = refl [THEN equiv_intrel_iff [THEN iffD1], standard]
   1.269 +lemmas Rep_Integ_equiv = quotient_eq_iff
   1.270 +  [OF equiv_intrel riq riq, simplified Integ.Rep_Integ_inject, standard]
   1.271 +lemmas Rep_Integ_same = 
   1.272 +  Rep_Integ_equiv [THEN intrel_refl [THEN rev_iffD2], standard]
   1.273 +
   1.274 +lemma RI_int: "(a, 0) : Rep_Integ (int a)"
   1.275 +  unfolding int_def by auto
   1.276 +
   1.277 +lemmas RI_intrel [simp] = UNIV_I [THEN quotientI,
   1.278 +  THEN Integ.Abs_Integ_inverse [simplified Integ_def], standard]
   1.279 +
   1.280 +lemma RI_minus: "(a, b) : Rep_Integ x ==> (b, a) : Rep_Integ (- x)"
   1.281 +  apply (rule_tac z=x in eq_Abs_Integ)
   1.282 +  apply (clarsimp simp: minus)
   1.283 +  done
   1.284 +
   1.285 +lemma RI_add: 
   1.286 +  "(a, b) : Rep_Integ x ==> (c, d) : Rep_Integ y ==> 
   1.287 +   (a + c, b + d) : Rep_Integ (x + y)"
   1.288 +  apply (rule_tac z=x in eq_Abs_Integ)
   1.289 +  apply (rule_tac z=y in eq_Abs_Integ) 
   1.290 +  apply (clarsimp simp: add)
   1.291 +  done
   1.292 +
   1.293 +lemma mem_same: "a : S ==> a = b ==> b : S"
   1.294 +  by fast
   1.295 +
   1.296 +(* two alternative proofs of this *)
   1.297 +lemma RI_eq_diff': "(a, b) : Rep_Integ (int a - int b)"
   1.298 +  apply (unfold diff_def)
   1.299 +  apply (rule mem_same)
   1.300 +   apply (rule RI_minus RI_add RI_int)+
   1.301 +  apply simp
   1.302 +  done
   1.303 +
   1.304 +lemma RI_eq_diff: "((a, b) : Rep_Integ x) = (int a - int b = x)"
   1.305 +  apply safe
   1.306 +   apply (rule Rep_Integ_same)
   1.307 +    prefer 2
   1.308 +    apply (erule asm_rl)
   1.309 +   apply (rule RI_eq_diff')+
   1.310 +  done
   1.311 +
   1.312 +lemma mod_power_lem:
   1.313 +  "a > 1 ==> a ^ n mod a ^ m = (if m <= n then 0 else (a :: int) ^ n)"
   1.314 +  apply clarsimp
   1.315 +  apply safe
   1.316 +   apply (simp add: dvd_eq_mod_eq_0 [symmetric])
   1.317 +   apply (drule le_iff_add [THEN iffD1])
   1.318 +   apply (force simp: zpower_zadd_distrib)
   1.319 +  apply (rule mod_pos_pos_trivial)
   1.320 +   apply (simp)
   1.321 +  apply (rule power_strict_increasing)
   1.322 +   apply auto
   1.323 +  done
   1.324 +
   1.325 +lemma min_pm [simp]: "min a b + (a - b) = (a :: nat)" by arith
   1.326 +  
   1.327 +lemmas min_pm1 [simp] = trans [OF add_commute min_pm]
   1.328 +
   1.329 +lemma rev_min_pm [simp]: "min b a + (a - b) = (a::nat)" by arith
   1.330 +
   1.331 +lemmas rev_min_pm1 [simp] = trans [OF add_commute rev_min_pm]
   1.332 +
   1.333 +lemma pl_pl_rels: 
   1.334 +  "a + b = c + d ==> 
   1.335 +   a >= c & b <= d | a <= c & b >= (d :: nat)" by arith
   1.336 +
   1.337 +lemmas pl_pl_rels' = add_commute [THEN [2] trans, THEN pl_pl_rels]
   1.338 +
   1.339 +lemma minus_eq: "(m - k = m) = (k = 0 | m = (0 :: nat))"  by arith
   1.340 +
   1.341 +lemma pl_pl_mm: "(a :: nat) + b = c + d ==> a - c = d - b"  by arith
   1.342 +
   1.343 +lemmas pl_pl_mm' = add_commute [THEN [2] trans, THEN pl_pl_mm]
   1.344 + 
   1.345 +lemma min_minus [simp] : "min m (m - k) = (m - k :: nat)" by arith
   1.346 +  
   1.347 +lemmas min_minus' [simp] = trans [OF min_max.inf_commute min_minus]
   1.348 +
   1.349 +lemma nat_no_eq_iff: 
   1.350 +  "(number_of b :: int) >= 0 ==> (number_of c :: int) >= 0 ==> 
   1.351 +   (number_of b = (number_of c :: nat)) = (b = c)" 
   1.352 +  apply (unfold nat_number_of_def) 
   1.353 +  apply safe
   1.354 +  apply (drule (2) eq_nat_nat_iff [THEN iffD1])
   1.355 +  apply (simp add: number_of_eq)
   1.356 +  done
   1.357 +
   1.358 +lemmas dme = box_equals [OF div_mod_equality add_0_right add_0_right]
   1.359 +lemmas dtle = xtr3 [OF dme [symmetric] le_add1]
   1.360 +lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] dtle]
   1.361 +
   1.362 +lemma td_gal: 
   1.363 +  "0 < c ==> (a >= b * c) = (a div c >= (b :: nat))"
   1.364 +  apply safe
   1.365 +   apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])
   1.366 +  apply (erule th2)
   1.367 +  done
   1.368 +  
   1.369 +lemmas td_gal_lt = td_gal [simplified not_less [symmetric], simplified]
   1.370 +
   1.371 +lemma div_mult_le: "(a :: nat) div b * b <= a"
   1.372 +  apply (cases b)
   1.373 +   prefer 2
   1.374 +   apply (rule order_refl [THEN th2])
   1.375 +  apply auto
   1.376 +  done
   1.377 +
   1.378 +lemmas sdl = split_div_lemma [THEN iffD1, symmetric]
   1.379 +
   1.380 +lemma given_quot: "f > (0 :: nat) ==> (f * l + (f - 1)) div f = l"
   1.381 +  by (rule sdl, assumption) (simp (no_asm))
   1.382 +
   1.383 +lemma given_quot_alt: "f > (0 :: nat) ==> (l * f + f - Suc 0) div f = l"
   1.384 +  apply (frule given_quot)
   1.385 +  apply (rule trans)
   1.386 +   prefer 2
   1.387 +   apply (erule asm_rl)
   1.388 +  apply (rule_tac f="%n. n div f" in arg_cong)
   1.389 +  apply (simp add : mult_ac)
   1.390 +  done
   1.391 +    
   1.392 +lemma diff_mod_le: "(a::nat) < d ==> b dvd d ==> a - a mod b <= d - b"
   1.393 +  apply (unfold dvd_def)
   1.394 +  apply clarify
   1.395 +  apply (case_tac k)
   1.396 +   apply clarsimp
   1.397 +  apply clarify
   1.398 +  apply (cases "b > 0")
   1.399 +   apply (drule mult_commute [THEN xtr1])
   1.400 +   apply (frule (1) td_gal_lt [THEN iffD1])
   1.401 +   apply (clarsimp simp: le_simps)
   1.402 +   apply (rule mult_div_cancel [THEN [2] xtr4])
   1.403 +   apply (rule mult_mono)
   1.404 +      apply auto
   1.405 +  done
   1.406 +
   1.407 +lemma less_le_mult':
   1.408 +  "w * c < b * c ==> 0 \<le> c ==> (w + 1) * c \<le> b * (c::int)"
   1.409 +  apply (rule mult_right_mono)
   1.410 +   apply (rule zless_imp_add1_zle)
   1.411 +   apply (erule (1) mult_right_less_imp_less)
   1.412 +  apply assumption
   1.413 +  done
   1.414 +
   1.415 +lemmas less_le_mult = less_le_mult' [simplified left_distrib, simplified]
   1.416 +
   1.417 +lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult, 
   1.418 +  simplified left_diff_distrib, standard]
   1.419 +
   1.420 +lemma lrlem':
   1.421 +  assumes d: "(i::nat) \<le> j \<or> m < j'"
   1.422 +  assumes R1: "i * k \<le> j * k \<Longrightarrow> R"
   1.423 +  assumes R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"
   1.424 +  shows "R" using d
   1.425 +  apply safe
   1.426 +   apply (rule R1, erule mult_le_mono1)
   1.427 +  apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])
   1.428 +  done
   1.429 +
   1.430 +lemma lrlem: "(0::nat) < sc ==>
   1.431 +    (sc - n + (n + lb * n) <= m * n) = (sc + lb * n <= m * n)"
   1.432 +  apply safe
   1.433 +   apply arith
   1.434 +  apply (case_tac "sc >= n")
   1.435 +   apply arith
   1.436 +  apply (insert linorder_le_less_linear [of m lb])
   1.437 +  apply (erule_tac k=n and k'=n in lrlem')
   1.438 +   apply arith
   1.439 +  apply simp
   1.440 +  done
   1.441 +
   1.442 +lemma gen_minus: "0 < n ==> f n = f (Suc (n - 1))"
   1.443 +  by auto
   1.444 +
   1.445 +lemma mpl_lem: "j <= (i :: nat) ==> k < j ==> i - j + k < i" by arith
   1.446 +
   1.447 +lemma nonneg_mod_div:
   1.448 +  "0 <= a ==> 0 <= b ==> 0 <= (a mod b :: int) & 0 <= a div b"
   1.449 +  apply (cases "b = 0", clarsimp)
   1.450 +  apply (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])
   1.451 +  done
   1.452 +
   1.453 +end