author | haftmann |
Sat, 17 Sep 2011 00:40:27 +0200 | |
changeset 44946 | 64469ea43735 |
parent 44939 | 5930d35c976d |
child 45528 | 726b743855ea |
permissions | -rw-r--r-- |
24333 | 1 |
(* |
2 |
Author: Jeremy Dawson, NICTA |
|
24350 | 3 |
*) |
24333 | 4 |
|
24350 | 5 |
header {* Useful Numerical Lemmas *} |
24333 | 6 |
|
37655 | 7 |
theory Misc_Numeric |
25592 | 8 |
imports Main Parity |
9 |
begin |
|
24333 | 10 |
|
39910 | 11 |
lemma the_elemI: "y = {x} ==> the_elem y = x" |
12 |
by simp |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
26072
diff
changeset
|
13 |
|
27570 | 14 |
lemma nonemptyE: "S ~= {} ==> (!!x. x : S ==> R) ==> R" by auto |
24333 | 15 |
|
27570 | 16 |
lemma gt_or_eq_0: "0 < y \<or> 0 = (y::nat)" by arith |
24333 | 17 |
|
24465 | 18 |
declare iszero_0 [iff] |
19 |
||
24333 | 20 |
lemmas xtr1 = xtrans(1) |
21 |
lemmas xtr2 = xtrans(2) |
|
22 |
lemmas xtr3 = xtrans(3) |
|
23 |
lemmas xtr4 = xtrans(4) |
|
24 |
lemmas xtr5 = xtrans(5) |
|
25 |
lemmas xtr6 = xtrans(6) |
|
26 |
lemmas xtr7 = xtrans(7) |
|
27 |
lemmas xtr8 = xtrans(8) |
|
28 |
||
24465 | 29 |
lemmas nat_simps = diff_add_inverse2 diff_add_inverse |
30 |
lemmas nat_iffs = le_add1 le_add2 |
|
31 |
||
27570 | 32 |
lemma sum_imp_diff: "j = k + i ==> j - i = (k :: nat)" by arith |
24465 | 33 |
|
24333 | 34 |
lemma nobm1: |
35 |
"0 < (number_of w :: nat) ==> |
|
27570 | 36 |
number_of w - (1 :: nat) = number_of (Int.pred w)" |
24333 | 37 |
apply (unfold nat_number_of_def One_nat_def nat_1 [symmetric] pred_def) |
38 |
apply (simp add: number_of_eq nat_diff_distrib [symmetric]) |
|
39 |
done |
|
24465 | 40 |
|
27570 | 41 |
lemma zless2: "0 < (2 :: int)" by arith |
24333 | 42 |
|
24465 | 43 |
lemmas zless2p [simp] = zless2 [THEN zero_less_power] |
44 |
lemmas zle2p [simp] = zless2p [THEN order_less_imp_le] |
|
45 |
||
46 |
lemmas pos_mod_sign2 = zless2 [THEN pos_mod_sign [where b = "2::int"]] |
|
47 |
lemmas pos_mod_bound2 = zless2 [THEN pos_mod_bound [where b = "2::int"]] |
|
48 |
||
49 |
-- "the inverse(s) of @{text number_of}" |
|
27570 | 50 |
lemma nmod2: "n mod (2::int) = 0 | n mod 2 = 1" by arith |
24333 | 51 |
|
52 |
lemma emep1: |
|
53 |
"even n ==> even d ==> 0 <= d ==> (n + 1) mod (d :: int) = (n mod d) + 1" |
|
54 |
apply (simp add: add_commute) |
|
55 |
apply (safe dest!: even_equiv_def [THEN iffD1]) |
|
56 |
apply (subst pos_zmod_mult_2) |
|
57 |
apply arith |
|
30943
eb3dbbe971f6
zmod_zmult_zmult1 now subsumed by mod_mult_mult1
haftmann
parents:
30445
diff
changeset
|
58 |
apply (simp add: mod_mult_mult1) |
24333 | 59 |
done |
60 |
||
61 |
lemmas eme1p = emep1 [simplified add_commute] |
|
62 |
||
27570 | 63 |
lemma le_diff_eq': "(a \<le> c - b) = (b + a \<le> (c::int))" by arith |
24465 | 64 |
|
27570 | 65 |
lemma less_diff_eq': "(a < c - b) = (b + a < (c::int))" by arith |
24465 | 66 |
|
27570 | 67 |
lemma diff_le_eq': "(a - b \<le> c) = (a \<le> b + (c::int))" by arith |
24465 | 68 |
|
27570 | 69 |
lemma diff_less_eq': "(a - b < c) = (a < b + (c::int))" by arith |
24333 | 70 |
|
71 |
lemmas m1mod2k = zless2p [THEN zmod_minus1] |
|
24465 | 72 |
lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1] |
24333 | 73 |
lemmas p1mod22k' = zless2p [THEN order_less_imp_le, THEN pos_zmod_mult_2] |
24465 | 74 |
lemmas z1pmod2' = zero_le_one [THEN pos_zmod_mult_2, simplified] |
75 |
lemmas z1pdiv2' = zero_le_one [THEN pos_zdiv_mult_2, simplified] |
|
24333 | 76 |
|
77 |
lemma p1mod22k: |
|
78 |
"(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + (1::int)" |
|
79 |
by (simp add: p1mod22k' add_commute) |
|
24465 | 80 |
|
81 |
lemma z1pmod2: |
|
27570 | 82 |
"(2 * b + 1) mod 2 = (1::int)" by arith |
24465 | 83 |
|
84 |
lemma z1pdiv2: |
|
27570 | 85 |
"(2 * b + 1) div 2 = (b::int)" by arith |
24333 | 86 |
|
30031 | 87 |
lemmas zdiv_le_dividend = xtr3 [OF div_by_1 [symmetric] zdiv_mono2, |
24333 | 88 |
simplified int_one_le_iff_zero_less, simplified, standard] |
24465 | 89 |
|
90 |
lemma axxbyy: |
|
91 |
"a + m + m = b + n + n ==> (a = 0 | a = 1) ==> (b = 0 | b = 1) ==> |
|
27570 | 92 |
a = b & m = (n :: int)" by arith |
24465 | 93 |
|
94 |
lemma axxmod2: |
|
27570 | 95 |
"(1 + x + x) mod 2 = (1 :: int) & (0 + x + x) mod 2 = (0 :: int)" by arith |
24465 | 96 |
|
97 |
lemma axxdiv2: |
|
27570 | 98 |
"(1 + x + x) div 2 = (x :: int) & (0 + x + x) div 2 = (x :: int)" by arith |
24465 | 99 |
|
100 |
lemmas iszero_minus = trans [THEN trans, |
|
101 |
OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric], standard] |
|
24333 | 102 |
|
103 |
lemmas zadd_diff_inverse = trans [OF diff_add_cancel [symmetric] add_commute, |
|
104 |
standard] |
|
105 |
||
106 |
lemmas add_diff_cancel2 = add_commute [THEN diff_eq_eq [THEN iffD2], standard] |
|
107 |
||
108 |
lemma zmod_uminus: "- ((a :: int) mod b) mod b = -a mod b" |
|
109 |
by (simp add : zmod_zminus1_eq_if) |
|
24465 | 110 |
|
111 |
lemma zmod_zsub_distrib: "((a::int) - b) mod c = (a mod c - b mod c) mod c" |
|
112 |
apply (unfold diff_int_def) |
|
29948 | 113 |
apply (rule trans [OF _ mod_add_eq [symmetric]]) |
114 |
apply (simp add: zmod_uminus mod_add_eq [symmetric]) |
|
24465 | 115 |
done |
24333 | 116 |
|
117 |
lemma zmod_zsub_right_eq: "((a::int) - b) mod c = (a - b mod c) mod c" |
|
118 |
apply (unfold diff_int_def) |
|
30034 | 119 |
apply (rule trans [OF _ mod_add_right_eq [symmetric]]) |
120 |
apply (simp add : zmod_uminus mod_add_right_eq [symmetric]) |
|
24333 | 121 |
done |
122 |
||
25349
0d46bea01741
eliminated illegal schematic variables in where/of;
wenzelm
parents:
24465
diff
changeset
|
123 |
lemma zmod_zsub_left_eq: "((a::int) - b) mod c = (a mod c - b) mod c" |
30034 | 124 |
by (rule mod_add_left_eq [where b = "- b", simplified diff_int_def [symmetric]]) |
25349
0d46bea01741
eliminated illegal schematic variables in where/of;
wenzelm
parents:
24465
diff
changeset
|
125 |
|
24333 | 126 |
lemma zmod_zsub_self [simp]: |
127 |
"((b :: int) - a) mod a = b mod a" |
|
128 |
by (simp add: zmod_zsub_right_eq) |
|
129 |
||
130 |
lemma zmod_zmult1_eq_rev: |
|
131 |
"b * a mod c = b mod c * a mod (c::int)" |
|
132 |
apply (simp add: mult_commute) |
|
133 |
apply (subst zmod_zmult1_eq) |
|
134 |
apply simp |
|
135 |
done |
|
136 |
||
137 |
lemmas rdmods [symmetric] = zmod_uminus [symmetric] |
|
30034 | 138 |
zmod_zsub_left_eq zmod_zsub_right_eq mod_add_left_eq |
139 |
mod_add_right_eq zmod_zmult1_eq zmod_zmult1_eq_rev |
|
24333 | 140 |
|
141 |
lemma mod_plus_right: |
|
142 |
"((a + x) mod m = (b + x) mod m) = (a mod m = b mod (m :: nat))" |
|
143 |
apply (induct x) |
|
144 |
apply (simp_all add: mod_Suc) |
|
145 |
apply arith |
|
146 |
done |
|
147 |
||
24465 | 148 |
lemma nat_minus_mod: "(n - n mod m) mod m = (0 :: nat)" |
149 |
by (induct n) (simp_all add : mod_Suc) |
|
150 |
||
151 |
lemmas nat_minus_mod_plus_right = trans [OF nat_minus_mod mod_0 [symmetric], |
|
152 |
THEN mod_plus_right [THEN iffD2], standard, simplified] |
|
153 |
||
29948 | 154 |
lemmas push_mods' = mod_add_eq [standard] |
155 |
mod_mult_eq [standard] zmod_zsub_distrib [standard] |
|
24465 | 156 |
zmod_uminus [symmetric, standard] |
157 |
||
158 |
lemmas push_mods = push_mods' [THEN eq_reflection, standard] |
|
159 |
lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection, standard] |
|
160 |
lemmas mod_simps = |
|
30034 | 161 |
mod_mult_self2_is_0 [THEN eq_reflection] |
162 |
mod_mult_self1_is_0 [THEN eq_reflection] |
|
24465 | 163 |
mod_mod_trivial [THEN eq_reflection] |
164 |
||
24333 | 165 |
lemma nat_mod_eq: |
166 |
"!!b. b < n ==> a mod n = b mod n ==> a mod n = (b :: nat)" |
|
167 |
by (induct a) auto |
|
168 |
||
169 |
lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq] |
|
170 |
||
171 |
lemma nat_mod_lem: |
|
172 |
"(0 :: nat) < n ==> b < n = (b mod n = b)" |
|
173 |
apply safe |
|
174 |
apply (erule nat_mod_eq') |
|
175 |
apply (erule subst) |
|
176 |
apply (erule mod_less_divisor) |
|
177 |
done |
|
178 |
||
179 |
lemma mod_nat_add: |
|
180 |
"(x :: nat) < z ==> y < z ==> |
|
181 |
(x + y) mod z = (if x + y < z then x + y else x + y - z)" |
|
182 |
apply (rule nat_mod_eq) |
|
183 |
apply auto |
|
184 |
apply (rule trans) |
|
185 |
apply (rule le_mod_geq) |
|
186 |
apply simp |
|
187 |
apply (rule nat_mod_eq') |
|
188 |
apply arith |
|
189 |
done |
|
24465 | 190 |
|
191 |
lemma mod_nat_sub: |
|
192 |
"(x :: nat) < z ==> (x - y) mod z = x - y" |
|
193 |
by (rule nat_mod_eq') arith |
|
24333 | 194 |
|
195 |
lemma int_mod_lem: |
|
196 |
"(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)" |
|
197 |
apply safe |
|
198 |
apply (erule (1) mod_pos_pos_trivial) |
|
199 |
apply (erule_tac [!] subst) |
|
200 |
apply auto |
|
201 |
done |
|
202 |
||
203 |
lemma int_mod_eq: |
|
204 |
"(0 :: int) <= b ==> b < n ==> a mod n = b mod n ==> a mod n = b" |
|
205 |
by clarsimp (rule mod_pos_pos_trivial) |
|
206 |
||
207 |
lemmas int_mod_eq' = refl [THEN [3] int_mod_eq] |
|
208 |
||
209 |
lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a" |
|
210 |
apply (cases "a < n") |
|
211 |
apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a]) |
|
212 |
done |
|
213 |
||
25349
0d46bea01741
eliminated illegal schematic variables in where/of;
wenzelm
parents:
24465
diff
changeset
|
214 |
lemma int_mod_le': "0 <= b - n ==> 0 < (n :: int) ==> b mod n <= b - n" |
0d46bea01741
eliminated illegal schematic variables in where/of;
wenzelm
parents:
24465
diff
changeset
|
215 |
by (rule int_mod_le [where a = "b - n" and n = n, simplified]) |
24333 | 216 |
|
217 |
lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n" |
|
218 |
apply (cases "0 <= a") |
|
219 |
apply (drule (1) mod_pos_pos_trivial) |
|
220 |
apply simp |
|
221 |
apply (rule order_trans [OF _ pos_mod_sign]) |
|
222 |
apply simp |
|
223 |
apply assumption |
|
224 |
done |
|
225 |
||
25349
0d46bea01741
eliminated illegal schematic variables in where/of;
wenzelm
parents:
24465
diff
changeset
|
226 |
lemma int_mod_ge': "b < 0 ==> 0 < (n :: int) ==> b + n <= b mod n" |
0d46bea01741
eliminated illegal schematic variables in where/of;
wenzelm
parents:
24465
diff
changeset
|
227 |
by (rule int_mod_ge [where a = "b + n" and n = n, simplified]) |
24333 | 228 |
|
229 |
lemma mod_add_if_z: |
|
230 |
"(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> |
|
231 |
(x + y) mod z = (if x + y < z then x + y else x + y - z)" |
|
232 |
by (auto intro: int_mod_eq) |
|
233 |
||
234 |
lemma mod_sub_if_z: |
|
235 |
"(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> |
|
236 |
(x - y) mod z = (if y <= x then x - y else x - y + z)" |
|
237 |
by (auto intro: int_mod_eq) |
|
24465 | 238 |
|
239 |
lemmas zmde = zmod_zdiv_equality [THEN diff_eq_eq [THEN iffD2], symmetric] |
|
240 |
lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule] |
|
241 |
||
242 |
(* already have this for naturals, div_mult_self1/2, but not for ints *) |
|
243 |
lemma zdiv_mult_self: "m ~= (0 :: int) ==> (a + m * n) div m = a div m + n" |
|
244 |
apply (rule mcl) |
|
245 |
prefer 2 |
|
246 |
apply (erule asm_rl) |
|
247 |
apply (simp add: zmde ring_distribs) |
|
248 |
done |
|
249 |
||
250 |
(** Rep_Integ **) |
|
251 |
lemma eqne: "equiv A r ==> X : A // r ==> X ~= {}" |
|
30198 | 252 |
unfolding equiv_def refl_on_def quotient_def Image_def by auto |
24465 | 253 |
|
254 |
lemmas Rep_Integ_ne = Integ.Rep_Integ |
|
255 |
[THEN equiv_intrel [THEN eqne, simplified Integ_def [symmetric]], standard] |
|
256 |
||
257 |
lemmas riq = Integ.Rep_Integ [simplified Integ_def] |
|
258 |
lemmas intrel_refl = refl [THEN equiv_intrel_iff [THEN iffD1], standard] |
|
259 |
lemmas Rep_Integ_equiv = quotient_eq_iff |
|
260 |
[OF equiv_intrel riq riq, simplified Integ.Rep_Integ_inject, standard] |
|
261 |
lemmas Rep_Integ_same = |
|
262 |
Rep_Integ_equiv [THEN intrel_refl [THEN rev_iffD2], standard] |
|
263 |
||
264 |
lemma RI_int: "(a, 0) : Rep_Integ (int a)" |
|
265 |
unfolding int_def by auto |
|
266 |
||
267 |
lemmas RI_intrel [simp] = UNIV_I [THEN quotientI, |
|
268 |
THEN Integ.Abs_Integ_inverse [simplified Integ_def], standard] |
|
269 |
||
270 |
lemma RI_minus: "(a, b) : Rep_Integ x ==> (b, a) : Rep_Integ (- x)" |
|
271 |
apply (rule_tac z=x in eq_Abs_Integ) |
|
272 |
apply (clarsimp simp: minus) |
|
273 |
done |
|
24333 | 274 |
|
24465 | 275 |
lemma RI_add: |
276 |
"(a, b) : Rep_Integ x ==> (c, d) : Rep_Integ y ==> |
|
277 |
(a + c, b + d) : Rep_Integ (x + y)" |
|
278 |
apply (rule_tac z=x in eq_Abs_Integ) |
|
279 |
apply (rule_tac z=y in eq_Abs_Integ) |
|
280 |
apply (clarsimp simp: add) |
|
281 |
done |
|
282 |
||
283 |
lemma mem_same: "a : S ==> a = b ==> b : S" |
|
284 |
by fast |
|
285 |
||
286 |
(* two alternative proofs of this *) |
|
287 |
lemma RI_eq_diff': "(a, b) : Rep_Integ (int a - int b)" |
|
37887 | 288 |
apply (unfold diff_minus) |
24465 | 289 |
apply (rule mem_same) |
290 |
apply (rule RI_minus RI_add RI_int)+ |
|
291 |
apply simp |
|
292 |
done |
|
293 |
||
294 |
lemma RI_eq_diff: "((a, b) : Rep_Integ x) = (int a - int b = x)" |
|
295 |
apply safe |
|
296 |
apply (rule Rep_Integ_same) |
|
297 |
prefer 2 |
|
298 |
apply (erule asm_rl) |
|
299 |
apply (rule RI_eq_diff')+ |
|
300 |
done |
|
301 |
||
302 |
lemma mod_power_lem: |
|
303 |
"a > 1 ==> a ^ n mod a ^ m = (if m <= n then 0 else (a :: int) ^ n)" |
|
304 |
apply clarsimp |
|
305 |
apply safe |
|
30042 | 306 |
apply (simp add: dvd_eq_mod_eq_0 [symmetric]) |
24465 | 307 |
apply (drule le_iff_add [THEN iffD1]) |
44821 | 308 |
apply (force simp: power_add) |
24465 | 309 |
apply (rule mod_pos_pos_trivial) |
25875 | 310 |
apply (simp) |
24465 | 311 |
apply (rule power_strict_increasing) |
312 |
apply auto |
|
313 |
done |
|
24333 | 314 |
|
27570 | 315 |
lemma min_pm [simp]: "min a b + (a - b) = (a :: nat)" by arith |
24333 | 316 |
|
317 |
lemmas min_pm1 [simp] = trans [OF add_commute min_pm] |
|
318 |
||
27570 | 319 |
lemma rev_min_pm [simp]: "min b a + (a - b) = (a::nat)" by arith |
24333 | 320 |
|
321 |
lemmas rev_min_pm1 [simp] = trans [OF add_commute rev_min_pm] |
|
322 |
||
24465 | 323 |
lemma pl_pl_rels: |
324 |
"a + b = c + d ==> |
|
27570 | 325 |
a >= c & b <= d | a <= c & b >= (d :: nat)" by arith |
24465 | 326 |
|
327 |
lemmas pl_pl_rels' = add_commute [THEN [2] trans, THEN pl_pl_rels] |
|
328 |
||
27570 | 329 |
lemma minus_eq: "(m - k = m) = (k = 0 | m = (0 :: nat))" by arith |
24465 | 330 |
|
27570 | 331 |
lemma pl_pl_mm: "(a :: nat) + b = c + d ==> a - c = d - b" by arith |
24465 | 332 |
|
333 |
lemmas pl_pl_mm' = add_commute [THEN [2] trans, THEN pl_pl_mm] |
|
334 |
||
27570 | 335 |
lemma min_minus [simp] : "min m (m - k) = (m - k :: nat)" by arith |
24333 | 336 |
|
337 |
lemmas min_minus' [simp] = trans [OF min_max.inf_commute min_minus] |
|
338 |
||
24465 | 339 |
lemma nat_no_eq_iff: |
340 |
"(number_of b :: int) >= 0 ==> (number_of c :: int) >= 0 ==> |
|
27570 | 341 |
(number_of b = (number_of c :: nat)) = (b = c)" |
342 |
apply (unfold nat_number_of_def) |
|
24465 | 343 |
apply safe |
344 |
apply (drule (2) eq_nat_nat_iff [THEN iffD1]) |
|
345 |
apply (simp add: number_of_eq) |
|
346 |
done |
|
347 |
||
24333 | 348 |
lemmas dme = box_equals [OF div_mod_equality add_0_right add_0_right] |
349 |
lemmas dtle = xtr3 [OF dme [symmetric] le_add1] |
|
350 |
lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] dtle] |
|
351 |
||
352 |
lemma td_gal: |
|
353 |
"0 < c ==> (a >= b * c) = (a div c >= (b :: nat))" |
|
354 |
apply safe |
|
355 |
apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m]) |
|
356 |
apply (erule th2) |
|
357 |
done |
|
358 |
||
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25937
diff
changeset
|
359 |
lemmas td_gal_lt = td_gal [simplified not_less [symmetric], simplified] |
24333 | 360 |
|
361 |
lemma div_mult_le: "(a :: nat) div b * b <= a" |
|
362 |
apply (cases b) |
|
363 |
prefer 2 |
|
364 |
apply (rule order_refl [THEN th2]) |
|
365 |
apply auto |
|
366 |
done |
|
367 |
||
368 |
lemmas sdl = split_div_lemma [THEN iffD1, symmetric] |
|
369 |
||
370 |
lemma given_quot: "f > (0 :: nat) ==> (f * l + (f - 1)) div f = l" |
|
371 |
by (rule sdl, assumption) (simp (no_asm)) |
|
372 |
||
373 |
lemma given_quot_alt: "f > (0 :: nat) ==> (l * f + f - Suc 0) div f = l" |
|
374 |
apply (frule given_quot) |
|
375 |
apply (rule trans) |
|
376 |
prefer 2 |
|
377 |
apply (erule asm_rl) |
|
378 |
apply (rule_tac f="%n. n div f" in arg_cong) |
|
379 |
apply (simp add : mult_ac) |
|
380 |
done |
|
381 |
||
24465 | 382 |
lemma diff_mod_le: "(a::nat) < d ==> b dvd d ==> a - a mod b <= d - b" |
383 |
apply (unfold dvd_def) |
|
384 |
apply clarify |
|
385 |
apply (case_tac k) |
|
386 |
apply clarsimp |
|
387 |
apply clarify |
|
388 |
apply (cases "b > 0") |
|
389 |
apply (drule mult_commute [THEN xtr1]) |
|
390 |
apply (frule (1) td_gal_lt [THEN iffD1]) |
|
391 |
apply (clarsimp simp: le_simps) |
|
392 |
apply (rule mult_div_cancel [THEN [2] xtr4]) |
|
393 |
apply (rule mult_mono) |
|
394 |
apply auto |
|
395 |
done |
|
396 |
||
24333 | 397 |
lemma less_le_mult': |
398 |
"w * c < b * c ==> 0 \<le> c ==> (w + 1) * c \<le> b * (c::int)" |
|
399 |
apply (rule mult_right_mono) |
|
400 |
apply (rule zless_imp_add1_zle) |
|
401 |
apply (erule (1) mult_right_less_imp_less) |
|
402 |
apply assumption |
|
403 |
done |
|
404 |
||
405 |
lemmas less_le_mult = less_le_mult' [simplified left_distrib, simplified] |
|
24465 | 406 |
|
407 |
lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult, |
|
408 |
simplified left_diff_distrib, standard] |
|
24333 | 409 |
|
410 |
lemma lrlem': |
|
411 |
assumes d: "(i::nat) \<le> j \<or> m < j'" |
|
412 |
assumes R1: "i * k \<le> j * k \<Longrightarrow> R" |
|
413 |
assumes R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R" |
|
414 |
shows "R" using d |
|
415 |
apply safe |
|
416 |
apply (rule R1, erule mult_le_mono1) |
|
417 |
apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]]) |
|
418 |
done |
|
419 |
||
420 |
lemma lrlem: "(0::nat) < sc ==> |
|
421 |
(sc - n + (n + lb * n) <= m * n) = (sc + lb * n <= m * n)" |
|
422 |
apply safe |
|
423 |
apply arith |
|
424 |
apply (case_tac "sc >= n") |
|
425 |
apply arith |
|
426 |
apply (insert linorder_le_less_linear [of m lb]) |
|
427 |
apply (erule_tac k=n and k'=n in lrlem') |
|
428 |
apply arith |
|
429 |
apply simp |
|
430 |
done |
|
431 |
||
432 |
lemma gen_minus: "0 < n ==> f n = f (Suc (n - 1))" |
|
433 |
by auto |
|
434 |
||
27570 | 435 |
lemma mpl_lem: "j <= (i :: nat) ==> k < j ==> i - j + k < i" by arith |
24333 | 436 |
|
24465 | 437 |
lemma nonneg_mod_div: |
438 |
"0 <= a ==> 0 <= b ==> 0 <= (a mod b :: int) & 0 <= a div b" |
|
439 |
apply (cases "b = 0", clarsimp) |
|
440 |
apply (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2]) |
|
441 |
done |
|
24399 | 442 |
|
24333 | 443 |
end |