24333

1 
(*


2 
ID: $Id$


3 
Author: Jeremy Dawson, NICTA


4 


5 
useful numerical lemmas


6 
*)


7 


8 
theory Num_Lemmas imports Parity begin


9 


10 
lemma contentsI: "y = {x} ==> contents y = x"


11 
unfolding contents_def by auto


12 


13 
lemma prod_case_split: "prod_case = split"


14 
by (rule ext)+ auto


15 


16 
lemmas split_split = prod.split [unfolded prod_case_split]


17 
lemmas split_split_asm = prod.split_asm [unfolded prod_case_split]


18 
lemmas "split.splits" = split_split split_split_asm


19 


20 
lemmas funpow_0 = funpow.simps(1)


21 
lemmas funpow_Suc = funpow.simps(2)


22 


23 
lemma nonemptyE: "S ~= {} ==> (!!x. x : S ==> R) ==> R"


24 
apply (erule contrapos_np)


25 
apply (rule equals0I)


26 
apply auto


27 
done


28 


29 
lemma int_number_of: "number_of (y::int) = y"


30 
by (simp add: number_of_eq)


31 


32 
lemma gt_or_eq_0: "0 < y \<or> 0 = (y::nat)" by auto


33 


34 
constdefs


35 
mod_alt :: "'a => 'a => 'a :: Divides.div"


36 
"mod_alt n m == n mod m"


37 


38 
 "alternative way of defining @{text bin_last}, @{text bin_rest}"


39 
bin_rl :: "int => int * bit"


40 
"bin_rl w == SOME (r, l). w = r BIT l"


41 


42 
declare iszero_0 [iff]


43 


44 
lemmas xtr1 = xtrans(1)


45 
lemmas xtr2 = xtrans(2)


46 
lemmas xtr3 = xtrans(3)


47 
lemmas xtr4 = xtrans(4)


48 
lemmas xtr5 = xtrans(5)


49 
lemmas xtr6 = xtrans(6)


50 
lemmas xtr7 = xtrans(7)


51 
lemmas xtr8 = xtrans(8)


52 


53 
lemma Min_ne_Pls [iff]:


54 
"Numeral.Min ~= Numeral.Pls"


55 
unfolding Min_def Pls_def by auto


56 


57 
lemmas Pls_ne_Min [iff] = Min_ne_Pls [symmetric]


58 


59 
lemmas PlsMin_defs [intro!] =


60 
Pls_def Min_def Pls_def [symmetric] Min_def [symmetric]


61 


62 
lemmas PlsMin_simps [simp] = PlsMin_defs [THEN Eq_TrueI]


63 


64 
lemma number_of_False_cong:


65 
"False ==> number_of x = number_of y"


66 
by auto


67 


68 
lemmas nat_simps = diff_add_inverse2 diff_add_inverse


69 
lemmas nat_iffs = le_add1 le_add2


70 


71 
lemma sum_imp_diff: "j = k + i ==> j  i = (k :: nat)"


72 
by (clarsimp simp add: nat_simps)


73 


74 
lemma nobm1:


75 
"0 < (number_of w :: nat) ==>


76 
number_of w  (1 :: nat) = number_of (Numeral.pred w)"


77 
apply (unfold nat_number_of_def One_nat_def nat_1 [symmetric] pred_def)


78 
apply (simp add: number_of_eq nat_diff_distrib [symmetric])


79 
done


80 


81 
lemma of_int_power:


82 
"of_int (a ^ n) = (of_int a ^ n :: 'a :: {recpower, comm_ring_1})"


83 
by (induct n) (auto simp add: power_Suc)


84 


85 
lemma zless2: "0 < (2 :: int)"


86 
by auto


87 


88 
lemmas zless2p [simp] = zless2 [THEN zero_less_power]


89 
lemmas zle2p [simp] = zless2p [THEN order_less_imp_le]


90 


91 
lemmas pos_mod_sign2 = zless2 [THEN pos_mod_sign [where b = "2::int"]]


92 
lemmas pos_mod_bound2 = zless2 [THEN pos_mod_bound [where b = "2::int"]]


93 


94 
 "the inverse(s) of @{text number_of}"


95 
lemma nmod2: "n mod (2::int) = 0  n mod 2 = 1"


96 
using pos_mod_sign2 [of n] pos_mod_bound2 [of n]


97 
unfolding mod_alt_def [symmetric] by auto


98 


99 
lemma emep1:


100 
"even n ==> even d ==> 0 <= d ==> (n + 1) mod (d :: int) = (n mod d) + 1"


101 
apply (simp add: add_commute)


102 
apply (safe dest!: even_equiv_def [THEN iffD1])


103 
apply (subst pos_zmod_mult_2)


104 
apply arith


105 
apply (simp add: zmod_zmult_zmult1)


106 
done


107 


108 
lemmas eme1p = emep1 [simplified add_commute]


109 


110 
lemma le_diff_eq': "(a \<le> c  b) = (b + a \<le> (c::int))"


111 
by (simp add: le_diff_eq add_commute)


112 


113 
lemma less_diff_eq': "(a < c  b) = (b + a < (c::int))"


114 
by (simp add: less_diff_eq add_commute)


115 


116 
lemma diff_le_eq': "(a  b \<le> c) = (a \<le> b + (c::int))"


117 
by (simp add: diff_le_eq add_commute)


118 


119 
lemma diff_less_eq': "(a  b < c) = (a < b + (c::int))"


120 
by (simp add: diff_less_eq add_commute)


121 


122 


123 
lemmas m1mod2k = zless2p [THEN zmod_minus1]


124 
lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1]


125 
lemmas p1mod22k' = zless2p [THEN order_less_imp_le, THEN pos_zmod_mult_2]


126 
lemmas z1pmod2' = zero_le_one [THEN pos_zmod_mult_2, simplified]


127 
lemmas z1pdiv2' = zero_le_one [THEN pos_zdiv_mult_2, simplified]


128 


129 
lemma p1mod22k:


130 
"(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + (1::int)"


131 
by (simp add: p1mod22k' add_commute)


132 


133 
lemma z1pmod2:


134 
"(2 * b + 1) mod 2 = (1::int)"


135 
by (simp add: z1pmod2' add_commute)


136 


137 
lemma z1pdiv2:


138 
"(2 * b + 1) div 2 = (b::int)"


139 
by (simp add: z1pdiv2' add_commute)


140 


141 
lemmas zdiv_le_dividend = xtr3 [OF zdiv_1 [symmetric] zdiv_mono2,


142 
simplified int_one_le_iff_zero_less, simplified, standard]


143 


144 
(** ways in which type Bin resembles a datatype **)


145 


146 
lemma BIT_eq: "u BIT b = v BIT c ==> u = v & b = c"


147 
apply (unfold Bit_def)


148 
apply (simp (no_asm_use) split: bit.split_asm)


149 
apply simp_all


150 
apply (drule_tac f=even in arg_cong, clarsimp)+


151 
done


152 


153 
lemmas BIT_eqE [elim!] = BIT_eq [THEN conjE, standard]


154 


155 
lemma BIT_eq_iff [simp]:


156 
"(u BIT b = v BIT c) = (u = v \<and> b = c)"


157 
by (rule iffI) auto


158 


159 
lemmas BIT_eqI [intro!] = conjI [THEN BIT_eq_iff [THEN iffD2]]


160 


161 
lemma less_Bits:


162 
"(v BIT b < w BIT c) = (v < w  v <= w & b = bit.B0 & c = bit.B1)"


163 
unfolding Bit_def by (auto split: bit.split)


164 


165 
lemma le_Bits:


166 
"(v BIT b <= w BIT c) = (v < w  v <= w & (b ~= bit.B1  c ~= bit.B0))"


167 
unfolding Bit_def by (auto split: bit.split)


168 


169 
lemma neB1E [elim!]:


170 
assumes ne: "y \<noteq> bit.B1"


171 
assumes y: "y = bit.B0 \<Longrightarrow> P"


172 
shows "P"


173 
apply (rule y)


174 
apply (cases y rule: bit.exhaust, simp)


175 
apply (simp add: ne)


176 
done


177 


178 
lemma bin_ex_rl: "EX w b. w BIT b = bin"


179 
apply (unfold Bit_def)


180 
apply (cases "even bin")


181 
apply (clarsimp simp: even_equiv_def)


182 
apply (auto simp: odd_equiv_def split: bit.split)


183 
done


184 


185 
lemma bin_exhaust:


186 
assumes Q: "\<And>x b. bin = x BIT b \<Longrightarrow> Q"


187 
shows "Q"


188 
apply (insert bin_ex_rl [of bin])


189 
apply (erule exE)+


190 
apply (rule Q)


191 
apply force


192 
done


193 


194 
lemma bin_rl_char: "(bin_rl w = (r, l)) = (r BIT l = w)"


195 
apply (unfold bin_rl_def)


196 
apply safe


197 
apply (cases w rule: bin_exhaust)


198 
apply auto


199 
done


200 


201 
lemmas bin_rl_simps [THEN bin_rl_char [THEN iffD2], standard, simp] =


202 
Pls_0_eq Min_1_eq refl


203 


204 
lemma bin_abs_lem:


205 
"bin = (w BIT b) ==> ~ bin = Numeral.Min > ~ bin = Numeral.Pls >


206 
nat (abs w) < nat (abs bin)"


207 
apply (clarsimp simp add: bin_rl_char)


208 
apply (unfold Pls_def Min_def Bit_def)


209 
apply (cases b)


210 
apply (clarsimp, arith)


211 
apply (clarsimp, arith)


212 
done


213 


214 
lemma bin_induct:


215 
assumes PPls: "P Numeral.Pls"


216 
and PMin: "P Numeral.Min"


217 
and PBit: "!!bin bit. P bin ==> P (bin BIT bit)"


218 
shows "P bin"


219 
apply (rule_tac P=P and a=bin and f1="nat o abs"


220 
in wf_measure [THEN wf_induct])


221 
apply (simp add: measure_def inv_image_def)


222 
apply (case_tac x rule: bin_exhaust)


223 
apply (frule bin_abs_lem)


224 
apply (auto simp add : PPls PMin PBit)


225 
done


226 


227 
lemma no_no [simp]: "number_of (number_of i) = i"


228 
unfolding number_of_eq by simp


229 


230 
lemma Bit_B0:


231 
"k BIT bit.B0 = k + k"


232 
by (unfold Bit_def) simp


233 


234 
lemma Bit_B1:


235 
"k BIT bit.B1 = k + k + 1"


236 
by (unfold Bit_def) simp


237 


238 
lemma Bit_B0_2t: "k BIT bit.B0 = 2 * k"


239 
by (rule trans, rule Bit_B0) simp


240 


241 
lemma Bit_B1_2t: "k BIT bit.B1 = 2 * k + 1"


242 
by (rule trans, rule Bit_B1) simp


243 


244 
lemma B_mod_2':


245 
"X = 2 ==> (w BIT bit.B1) mod X = 1 & (w BIT bit.B0) mod X = 0"


246 
apply (simp (no_asm) only: Bit_B0 Bit_B1)


247 
apply (simp add: z1pmod2)


248 
done


249 


250 
lemmas B1_mod_2 [simp] = B_mod_2' [OF refl, THEN conjunct1, standard]


251 
lemmas B0_mod_2 [simp] = B_mod_2' [OF refl, THEN conjunct2, standard]


252 


253 
lemma axxbyy:


254 
"a + m + m = b + n + n ==> (a = 0  a = 1) ==> (b = 0  b = 1) ==>


255 
a = b & m = (n :: int)"


256 
apply auto


257 
apply (drule_tac f="%n. n mod 2" in arg_cong)


258 
apply (clarsimp simp: z1pmod2)


259 
apply (drule_tac f="%n. n mod 2" in arg_cong)


260 
apply (clarsimp simp: z1pmod2)


261 
done


262 


263 
lemma axxmod2:


264 
"(1 + x + x) mod 2 = (1 :: int) & (0 + x + x) mod 2 = (0 :: int)"


265 
by simp (rule z1pmod2)


266 


267 
lemma axxdiv2:


268 
"(1 + x + x) div 2 = (x :: int) & (0 + x + x) div 2 = (x :: int)"


269 
by simp (rule z1pdiv2)


270 


271 
lemmas iszero_minus = trans [THEN trans,


272 
OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric], standard]


273 


274 
lemmas zadd_diff_inverse = trans [OF diff_add_cancel [symmetric] add_commute,


275 
standard]


276 


277 
lemmas add_diff_cancel2 = add_commute [THEN diff_eq_eq [THEN iffD2], standard]


278 


279 
lemma zmod_uminus: " ((a :: int) mod b) mod b = a mod b"


280 
by (simp add : zmod_zminus1_eq_if)


281 


282 
lemma zmod_zsub_distrib: "((a::int)  b) mod c = (a mod c  b mod c) mod c"


283 
apply (unfold diff_int_def)


284 
apply (rule trans [OF _ zmod_zadd1_eq [symmetric]])


285 
apply (simp add: zmod_uminus zmod_zadd1_eq [symmetric])


286 
done


287 


288 
lemma zmod_zsub_right_eq: "((a::int)  b) mod c = (a  b mod c) mod c"


289 
apply (unfold diff_int_def)


290 
apply (rule trans [OF _ zmod_zadd_right_eq [symmetric]])


291 
apply (simp add : zmod_uminus zmod_zadd_right_eq [symmetric])


292 
done


293 


294 
lemmas zmod_zsub_left_eq =


295 
zmod_zadd_left_eq [where b = " ?b", simplified diff_int_def [symmetric]]


296 


297 
lemma zmod_zsub_self [simp]:


298 
"((b :: int)  a) mod a = b mod a"


299 
by (simp add: zmod_zsub_right_eq)


300 


301 
lemma zmod_zmult1_eq_rev:


302 
"b * a mod c = b mod c * a mod (c::int)"


303 
apply (simp add: mult_commute)


304 
apply (subst zmod_zmult1_eq)


305 
apply simp


306 
done


307 


308 
lemmas rdmods [symmetric] = zmod_uminus [symmetric]


309 
zmod_zsub_left_eq zmod_zsub_right_eq zmod_zadd_left_eq


310 
zmod_zadd_right_eq zmod_zmult1_eq zmod_zmult1_eq_rev


311 


312 
lemma mod_plus_right:


313 
"((a + x) mod m = (b + x) mod m) = (a mod m = b mod (m :: nat))"


314 
apply (induct x)


315 
apply (simp_all add: mod_Suc)


316 
apply arith


317 
done


318 


319 
lemma nat_minus_mod: "(n  n mod m) mod m = (0 :: nat)"


320 
by (induct n) (simp_all add : mod_Suc)


321 


322 
lemmas nat_minus_mod_plus_right = trans [OF nat_minus_mod mod_0 [symmetric],


323 
THEN mod_plus_right [THEN iffD2], standard, simplified]


324 


325 
lemmas push_mods' = zmod_zadd1_eq [standard]


326 
zmod_zmult_distrib [standard] zmod_zsub_distrib [standard]


327 
zmod_uminus [symmetric, standard]


328 


329 
lemmas push_mods = push_mods' [THEN eq_reflection, standard]


330 
lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection, standard]


331 
lemmas mod_simps =


332 
zmod_zmult_self1 [THEN eq_reflection] zmod_zmult_self2 [THEN eq_reflection]


333 
mod_mod_trivial [THEN eq_reflection]


334 


335 
lemma nat_mod_eq:


336 
"!!b. b < n ==> a mod n = b mod n ==> a mod n = (b :: nat)"


337 
by (induct a) auto


338 


339 
lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]


340 


341 
lemma nat_mod_lem:


342 
"(0 :: nat) < n ==> b < n = (b mod n = b)"


343 
apply safe


344 
apply (erule nat_mod_eq')


345 
apply (erule subst)


346 
apply (erule mod_less_divisor)


347 
done


348 


349 
lemma mod_nat_add:


350 
"(x :: nat) < z ==> y < z ==>


351 
(x + y) mod z = (if x + y < z then x + y else x + y  z)"


352 
apply (rule nat_mod_eq)


353 
apply auto


354 
apply (rule trans)


355 
apply (rule le_mod_geq)


356 
apply simp


357 
apply (rule nat_mod_eq')


358 
apply arith


359 
done


360 


361 
lemma mod_nat_sub:


362 
"(x :: nat) < z ==> (x  y) mod z = x  y"


363 
by (rule nat_mod_eq') arith


364 


365 
lemma int_mod_lem:


366 
"(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)"


367 
apply safe


368 
apply (erule (1) mod_pos_pos_trivial)


369 
apply (erule_tac [!] subst)


370 
apply auto


371 
done


372 


373 
lemma int_mod_eq:


374 
"(0 :: int) <= b ==> b < n ==> a mod n = b mod n ==> a mod n = b"


375 
by clarsimp (rule mod_pos_pos_trivial)


376 


377 
lemmas int_mod_eq' = refl [THEN [3] int_mod_eq]


378 


379 
lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a"


380 
apply (cases "a < n")


381 
apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a])


382 
done


383 


384 
lemmas int_mod_le' = int_mod_le [where a = "?b  ?n", simplified]


385 


386 
lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n"


387 
apply (cases "0 <= a")


388 
apply (drule (1) mod_pos_pos_trivial)


389 
apply simp


390 
apply (rule order_trans [OF _ pos_mod_sign])


391 
apply simp


392 
apply assumption


393 
done


394 


395 
lemmas int_mod_ge' = int_mod_ge [where a = "?b + ?n", simplified]


396 


397 
lemma mod_add_if_z:


398 
"(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==>


399 
(x + y) mod z = (if x + y < z then x + y else x + y  z)"


400 
by (auto intro: int_mod_eq)


401 


402 
lemma mod_sub_if_z:


403 
"(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==>


404 
(x  y) mod z = (if y <= x then x  y else x  y + z)"


405 
by (auto intro: int_mod_eq)


406 


407 
lemmas zmde = zmod_zdiv_equality [THEN diff_eq_eq [THEN iffD2], symmetric]


408 
lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule]


409 


410 
(* already have this for naturals, div_mult_self1/2, but not for ints *)


411 
lemma zdiv_mult_self: "m ~= (0 :: int) ==> (a + m * n) div m = a div m + n"


412 
apply (rule mcl)


413 
prefer 2


414 
apply (erule asm_rl)


415 
apply (simp add: zmde ring_distribs)


416 
apply (simp add: push_mods)


417 
done


418 


419 
(** Rep_Integ **)


420 
lemma eqne: "equiv A r ==> X : A // r ==> X ~= {}"


421 
unfolding equiv_def refl_def quotient_def Image_def by auto


422 


423 
lemmas Rep_Integ_ne = Integ.Rep_Integ


424 
[THEN equiv_intrel [THEN eqne, simplified Integ_def [symmetric]], standard]


425 


426 
lemmas riq = Integ.Rep_Integ [simplified Integ_def]


427 
lemmas intrel_refl = refl [THEN equiv_intrel_iff [THEN iffD1], standard]


428 
lemmas Rep_Integ_equiv = quotient_eq_iff


429 
[OF equiv_intrel riq riq, simplified Integ.Rep_Integ_inject, standard]


430 
lemmas Rep_Integ_same =


431 
Rep_Integ_equiv [THEN intrel_refl [THEN rev_iffD2], standard]


432 


433 
lemma RI_int: "(a, 0) : Rep_Integ (int a)"


434 
unfolding int_def by auto


435 


436 
lemmas RI_intrel [simp] = UNIV_I [THEN quotientI,


437 
THEN Integ.Abs_Integ_inverse [simplified Integ_def], standard]


438 


439 
lemma RI_minus: "(a, b) : Rep_Integ x ==> (b, a) : Rep_Integ ( x)"


440 
apply (rule_tac z=x in eq_Abs_Integ)


441 
apply (clarsimp simp: minus)


442 
done


443 


444 
lemma RI_add:


445 
"(a, b) : Rep_Integ x ==> (c, d) : Rep_Integ y ==>


446 
(a + c, b + d) : Rep_Integ (x + y)"


447 
apply (rule_tac z=x in eq_Abs_Integ)


448 
apply (rule_tac z=y in eq_Abs_Integ)


449 
apply (clarsimp simp: add)


450 
done


451 


452 
lemma mem_same: "a : S ==> a = b ==> b : S"


453 
by fast


454 


455 
(* two alternative proofs of this *)


456 
lemma RI_eq_diff': "(a, b) : Rep_Integ (int a  int b)"


457 
apply (unfold diff_def)


458 
apply (rule mem_same)


459 
apply (rule RI_minus RI_add RI_int)+


460 
apply simp


461 
done


462 


463 
lemma RI_eq_diff: "((a, b) : Rep_Integ x) = (int a  int b = x)"


464 
apply safe


465 
apply (rule Rep_Integ_same)


466 
prefer 2


467 
apply (erule asm_rl)


468 
apply (rule RI_eq_diff')+


469 
done


470 


471 
lemma mod_power_lem:


472 
"a > 1 ==> a ^ n mod a ^ m = (if m <= n then 0 else (a :: int) ^ n)"


473 
apply clarsimp


474 
apply safe


475 
apply (simp add: zdvd_iff_zmod_eq_0 [symmetric])


476 
apply (drule le_iff_add [THEN iffD1])


477 
apply (force simp: zpower_zadd_distrib)


478 
apply (rule mod_pos_pos_trivial)


479 
apply (simp add: zero_le_power)


480 
apply (rule power_strict_increasing)


481 
apply auto


482 
done


483 


484 
lemma min_pm [simp]: "min a b + (a  b) = (a :: nat)"


485 
by arith


486 


487 
lemmas min_pm1 [simp] = trans [OF add_commute min_pm]


488 


489 
lemma rev_min_pm [simp]: "min b a + (a  b) = (a::nat)"


490 
by simp


491 


492 
lemmas rev_min_pm1 [simp] = trans [OF add_commute rev_min_pm]


493 


494 
lemma pl_pl_rels:


495 
"a + b = c + d ==>


496 
a >= c & b <= d  a <= c & b >= (d :: nat)"


497 
apply (cut_tac n=a and m=c in nat_le_linear)


498 
apply (safe dest!: le_iff_add [THEN iffD1])


499 
apply arith+


500 
done


501 


502 
lemmas pl_pl_rels' = add_commute [THEN [2] trans, THEN pl_pl_rels]


503 


504 
lemma minus_eq: "(m  k = m) = (k = 0  m = (0 :: nat))"


505 
by arith


506 


507 
lemma pl_pl_mm: "(a :: nat) + b = c + d ==> a  c = d  b"


508 
by arith


509 


510 
lemmas pl_pl_mm' = add_commute [THEN [2] trans, THEN pl_pl_mm]


511 


512 
lemma min_minus [simp] : "min m (m  k) = (m  k :: nat)"


513 
by arith


514 


515 
lemmas min_minus' [simp] = trans [OF min_max.inf_commute min_minus]


516 


517 
lemma nat_no_eq_iff:


518 
"(number_of b :: int) >= 0 ==> (number_of c :: int) >= 0 ==>


519 
(number_of b = (number_of c :: nat)) = (b = c)"


520 
apply (unfold nat_number_of_def)


521 
apply safe


522 
apply (drule (2) eq_nat_nat_iff [THEN iffD1])


523 
apply (simp add: number_of_eq)


524 
done


525 


526 
lemmas dme = box_equals [OF div_mod_equality add_0_right add_0_right]


527 
lemmas dtle = xtr3 [OF dme [symmetric] le_add1]


528 
lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] dtle]


529 


530 
lemma td_gal:


531 
"0 < c ==> (a >= b * c) = (a div c >= (b :: nat))"


532 
apply safe


533 
apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])


534 
apply (erule th2)


535 
done


536 


537 
lemmas td_gal_lt = td_gal [simplified le_def, simplified]


538 


539 
lemma div_mult_le: "(a :: nat) div b * b <= a"


540 
apply (cases b)


541 
prefer 2


542 
apply (rule order_refl [THEN th2])


543 
apply auto


544 
done


545 


546 
lemmas sdl = split_div_lemma [THEN iffD1, symmetric]


547 


548 
lemma given_quot: "f > (0 :: nat) ==> (f * l + (f  1)) div f = l"


549 
by (rule sdl, assumption) (simp (no_asm))


550 


551 
lemma given_quot_alt: "f > (0 :: nat) ==> (l * f + f  Suc 0) div f = l"


552 
apply (frule given_quot)


553 
apply (rule trans)


554 
prefer 2


555 
apply (erule asm_rl)


556 
apply (rule_tac f="%n. n div f" in arg_cong)


557 
apply (simp add : mult_ac)


558 
done


559 


560 
lemma diff_mod_le: "(a::nat) < d ==> b dvd d ==> a  a mod b <= d  b"


561 
apply (unfold dvd_def)


562 
apply clarify


563 
apply (case_tac k)


564 
apply clarsimp


565 
apply clarify


566 
apply (cases "b > 0")


567 
apply (drule mult_commute [THEN xtr1])


568 
apply (frule (1) td_gal_lt [THEN iffD1])


569 
apply (clarsimp simp: le_simps)


570 
apply (rule mult_div_cancel [THEN [2] xtr4])


571 
apply (rule mult_mono)


572 
apply auto


573 
done


574 


575 
lemma less_le_mult':


576 
"w * c < b * c ==> 0 \<le> c ==> (w + 1) * c \<le> b * (c::int)"


577 
apply (rule mult_right_mono)


578 
apply (rule zless_imp_add1_zle)


579 
apply (erule (1) mult_right_less_imp_less)


580 
apply assumption


581 
done


582 


583 
lemmas less_le_mult = less_le_mult' [simplified left_distrib, simplified]


584 


585 
lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult,


586 
simplified left_diff_distrib, standard]


587 


588 
lemma lrlem':


589 
assumes d: "(i::nat) \<le> j \<or> m < j'"


590 
assumes R1: "i * k \<le> j * k \<Longrightarrow> R"


591 
assumes R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"


592 
shows "R" using d


593 
apply safe


594 
apply (rule R1, erule mult_le_mono1)


595 
apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])


596 
done


597 


598 
lemma lrlem: "(0::nat) < sc ==>


599 
(sc  n + (n + lb * n) <= m * n) = (sc + lb * n <= m * n)"


600 
apply safe


601 
apply arith


602 
apply (case_tac "sc >= n")


603 
apply arith


604 
apply (insert linorder_le_less_linear [of m lb])


605 
apply (erule_tac k=n and k'=n in lrlem')


606 
apply arith


607 
apply simp


608 
done


609 


610 
lemma gen_minus: "0 < n ==> f n = f (Suc (n  1))"


611 
by auto


612 


613 
lemma mpl_lem: "j <= (i :: nat) ==> k < j ==> i  j + k < i"


614 
apply (induct i, clarsimp)


615 
apply (cases j, clarsimp)


616 
apply arith


617 
done


618 


619 
lemma nonneg_mod_div:


620 
"0 <= a ==> 0 <= b ==> 0 <= (a mod b :: int) & 0 <= a div b"


621 
apply (cases "b = 0", clarsimp)


622 
apply (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])


623 
done


624 


625 
end
