| author | wenzelm | 
| Wed, 14 Mar 2012 19:27:15 +0100 | |
| changeset 46924 | f2c60ad58374 | 
| parent 45604 | 29cf40fe8daf | 
| child 47108 | 2a1953f0d20d | 
| 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,  | 
| 45604 | 88  | 
simplified int_one_le_iff_zero_less, simplified]  | 
| 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,  | 
|
| 45604 | 101  | 
OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric]]  | 
| 24333 | 102  | 
|
| 45604 | 103  | 
lemmas zadd_diff_inverse = trans [OF diff_add_cancel [symmetric] add_commute]  | 
| 24333 | 104  | 
|
| 45604 | 105  | 
lemmas add_diff_cancel2 = add_commute [THEN diff_eq_eq [THEN iffD2]]  | 
| 24333 | 106  | 
|
107  | 
lemma zmod_uminus: "- ((a :: int) mod b) mod b = -a mod b"  | 
|
108  | 
by (simp add : zmod_zminus1_eq_if)  | 
|
| 24465 | 109  | 
|
110  | 
lemma zmod_zsub_distrib: "((a::int) - b) mod c = (a mod c - b mod c) mod c"  | 
|
111  | 
apply (unfold diff_int_def)  | 
|
| 29948 | 112  | 
apply (rule trans [OF _ mod_add_eq [symmetric]])  | 
113  | 
apply (simp add: zmod_uminus mod_add_eq [symmetric])  | 
|
| 24465 | 114  | 
done  | 
| 24333 | 115  | 
|
116  | 
lemma zmod_zsub_right_eq: "((a::int) - b) mod c = (a - b mod c) mod c"  | 
|
117  | 
apply (unfold diff_int_def)  | 
|
| 30034 | 118  | 
apply (rule trans [OF _ mod_add_right_eq [symmetric]])  | 
119  | 
apply (simp add : zmod_uminus mod_add_right_eq [symmetric])  | 
|
| 24333 | 120  | 
done  | 
121  | 
||
| 
25349
 
0d46bea01741
eliminated illegal schematic variables in where/of;
 
wenzelm 
parents: 
24465 
diff
changeset
 | 
122  | 
lemma zmod_zsub_left_eq: "((a::int) - b) mod c = (a mod c - b) mod c"  | 
| 30034 | 123  | 
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
 | 
124  | 
|
| 24333 | 125  | 
lemma zmod_zsub_self [simp]:  | 
126  | 
"((b :: int) - a) mod a = b mod a"  | 
|
127  | 
by (simp add: zmod_zsub_right_eq)  | 
|
128  | 
||
129  | 
lemma zmod_zmult1_eq_rev:  | 
|
130  | 
"b * a mod c = b mod c * a mod (c::int)"  | 
|
131  | 
apply (simp add: mult_commute)  | 
|
132  | 
apply (subst zmod_zmult1_eq)  | 
|
133  | 
apply simp  | 
|
134  | 
done  | 
|
135  | 
||
136  | 
lemmas rdmods [symmetric] = zmod_uminus [symmetric]  | 
|
| 30034 | 137  | 
zmod_zsub_left_eq zmod_zsub_right_eq mod_add_left_eq  | 
138  | 
mod_add_right_eq zmod_zmult1_eq zmod_zmult1_eq_rev  | 
|
| 24333 | 139  | 
|
140  | 
lemma mod_plus_right:  | 
|
141  | 
"((a + x) mod m = (b + x) mod m) = (a mod m = b mod (m :: nat))"  | 
|
142  | 
apply (induct x)  | 
|
143  | 
apply (simp_all add: mod_Suc)  | 
|
144  | 
apply arith  | 
|
145  | 
done  | 
|
146  | 
||
| 24465 | 147  | 
lemma nat_minus_mod: "(n - n mod m) mod m = (0 :: nat)"  | 
148  | 
by (induct n) (simp_all add : mod_Suc)  | 
|
149  | 
||
150  | 
lemmas nat_minus_mod_plus_right = trans [OF nat_minus_mod mod_0 [symmetric],  | 
|
| 45604 | 151  | 
THEN mod_plus_right [THEN iffD2], simplified]  | 
| 24465 | 152  | 
|
| 45604 | 153  | 
lemmas push_mods' = mod_add_eq  | 
154  | 
mod_mult_eq zmod_zsub_distrib  | 
|
155  | 
zmod_uminus [symmetric]  | 
|
| 24465 | 156  | 
|
| 45604 | 157  | 
lemmas push_mods = push_mods' [THEN eq_reflection]  | 
158  | 
lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection]  | 
|
| 24465 | 159  | 
lemmas mod_simps =  | 
| 30034 | 160  | 
mod_mult_self2_is_0 [THEN eq_reflection]  | 
161  | 
mod_mult_self1_is_0 [THEN eq_reflection]  | 
|
| 24465 | 162  | 
mod_mod_trivial [THEN eq_reflection]  | 
163  | 
||
| 24333 | 164  | 
lemma nat_mod_eq:  | 
165  | 
"!!b. b < n ==> a mod n = b mod n ==> a mod n = (b :: nat)"  | 
|
166  | 
by (induct a) auto  | 
|
167  | 
||
168  | 
lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]  | 
|
169  | 
||
170  | 
lemma nat_mod_lem:  | 
|
171  | 
"(0 :: nat) < n ==> b < n = (b mod n = b)"  | 
|
172  | 
apply safe  | 
|
173  | 
apply (erule nat_mod_eq')  | 
|
174  | 
apply (erule subst)  | 
|
175  | 
apply (erule mod_less_divisor)  | 
|
176  | 
done  | 
|
177  | 
||
178  | 
lemma mod_nat_add:  | 
|
179  | 
"(x :: nat) < z ==> y < z ==>  | 
|
180  | 
(x + y) mod z = (if x + y < z then x + y else x + y - z)"  | 
|
181  | 
apply (rule nat_mod_eq)  | 
|
182  | 
apply auto  | 
|
183  | 
apply (rule trans)  | 
|
184  | 
apply (rule le_mod_geq)  | 
|
185  | 
apply simp  | 
|
186  | 
apply (rule nat_mod_eq')  | 
|
187  | 
apply arith  | 
|
188  | 
done  | 
|
| 24465 | 189  | 
|
190  | 
lemma mod_nat_sub:  | 
|
191  | 
"(x :: nat) < z ==> (x - y) mod z = x - y"  | 
|
192  | 
by (rule nat_mod_eq') arith  | 
|
| 24333 | 193  | 
|
194  | 
lemma int_mod_lem:  | 
|
195  | 
"(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)"  | 
|
196  | 
apply safe  | 
|
197  | 
apply (erule (1) mod_pos_pos_trivial)  | 
|
198  | 
apply (erule_tac [!] subst)  | 
|
199  | 
apply auto  | 
|
200  | 
done  | 
|
201  | 
||
202  | 
lemma int_mod_eq:  | 
|
203  | 
"(0 :: int) <= b ==> b < n ==> a mod n = b mod n ==> a mod n = b"  | 
|
204  | 
by clarsimp (rule mod_pos_pos_trivial)  | 
|
205  | 
||
206  | 
lemmas int_mod_eq' = refl [THEN [3] int_mod_eq]  | 
|
207  | 
||
208  | 
lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a"  | 
|
209  | 
apply (cases "a < n")  | 
|
210  | 
apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a])  | 
|
211  | 
done  | 
|
212  | 
||
| 
25349
 
0d46bea01741
eliminated illegal schematic variables in where/of;
 
wenzelm 
parents: 
24465 
diff
changeset
 | 
213  | 
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
 | 
214  | 
by (rule int_mod_le [where a = "b - n" and n = n, simplified])  | 
| 24333 | 215  | 
|
216  | 
lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n"  | 
|
217  | 
apply (cases "0 <= a")  | 
|
218  | 
apply (drule (1) mod_pos_pos_trivial)  | 
|
219  | 
apply simp  | 
|
220  | 
apply (rule order_trans [OF _ pos_mod_sign])  | 
|
221  | 
apply simp  | 
|
222  | 
apply assumption  | 
|
223  | 
done  | 
|
224  | 
||
| 
25349
 
0d46bea01741
eliminated illegal schematic variables in where/of;
 
wenzelm 
parents: 
24465 
diff
changeset
 | 
225  | 
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
 | 
226  | 
by (rule int_mod_ge [where a = "b + n" and n = n, simplified])  | 
| 24333 | 227  | 
|
228  | 
lemma mod_add_if_z:  | 
|
229  | 
"(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==>  | 
|
230  | 
(x + y) mod z = (if x + y < z then x + y else x + y - z)"  | 
|
231  | 
by (auto intro: int_mod_eq)  | 
|
232  | 
||
233  | 
lemma mod_sub_if_z:  | 
|
234  | 
"(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==>  | 
|
235  | 
(x - y) mod z = (if y <= x then x - y else x - y + z)"  | 
|
236  | 
by (auto intro: int_mod_eq)  | 
|
| 24465 | 237  | 
|
238  | 
lemmas zmde = zmod_zdiv_equality [THEN diff_eq_eq [THEN iffD2], symmetric]  | 
|
239  | 
lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule]  | 
|
240  | 
||
241  | 
(* already have this for naturals, div_mult_self1/2, but not for ints *)  | 
|
242  | 
lemma zdiv_mult_self: "m ~= (0 :: int) ==> (a + m * n) div m = a div m + n"  | 
|
243  | 
apply (rule mcl)  | 
|
244  | 
prefer 2  | 
|
245  | 
apply (erule asm_rl)  | 
|
246  | 
apply (simp add: zmde ring_distribs)  | 
|
247  | 
done  | 
|
248  | 
||
249  | 
lemma mod_power_lem:  | 
|
250  | 
"a > 1 ==> a ^ n mod a ^ m = (if m <= n then 0 else (a :: int) ^ n)"  | 
|
251  | 
apply clarsimp  | 
|
252  | 
apply safe  | 
|
| 30042 | 253  | 
apply (simp add: dvd_eq_mod_eq_0 [symmetric])  | 
| 24465 | 254  | 
apply (drule le_iff_add [THEN iffD1])  | 
| 44821 | 255  | 
apply (force simp: power_add)  | 
| 24465 | 256  | 
apply (rule mod_pos_pos_trivial)  | 
| 25875 | 257  | 
apply (simp)  | 
| 24465 | 258  | 
apply (rule power_strict_increasing)  | 
259  | 
apply auto  | 
|
260  | 
done  | 
|
| 24333 | 261  | 
|
| 27570 | 262  | 
lemma min_pm [simp]: "min a b + (a - b) = (a :: nat)" by arith  | 
| 24333 | 263  | 
|
264  | 
lemmas min_pm1 [simp] = trans [OF add_commute min_pm]  | 
|
265  | 
||
| 27570 | 266  | 
lemma rev_min_pm [simp]: "min b a + (a - b) = (a::nat)" by arith  | 
| 24333 | 267  | 
|
268  | 
lemmas rev_min_pm1 [simp] = trans [OF add_commute rev_min_pm]  | 
|
269  | 
||
| 24465 | 270  | 
lemma pl_pl_rels:  | 
271  | 
"a + b = c + d ==>  | 
|
| 27570 | 272  | 
a >= c & b <= d | a <= c & b >= (d :: nat)" by arith  | 
| 24465 | 273  | 
|
274  | 
lemmas pl_pl_rels' = add_commute [THEN [2] trans, THEN pl_pl_rels]  | 
|
275  | 
||
| 27570 | 276  | 
lemma minus_eq: "(m - k = m) = (k = 0 | m = (0 :: nat))" by arith  | 
| 24465 | 277  | 
|
| 27570 | 278  | 
lemma pl_pl_mm: "(a :: nat) + b = c + d ==> a - c = d - b" by arith  | 
| 24465 | 279  | 
|
280  | 
lemmas pl_pl_mm' = add_commute [THEN [2] trans, THEN pl_pl_mm]  | 
|
281  | 
||
| 27570 | 282  | 
lemma min_minus [simp] : "min m (m - k) = (m - k :: nat)" by arith  | 
| 24333 | 283  | 
|
284  | 
lemmas min_minus' [simp] = trans [OF min_max.inf_commute min_minus]  | 
|
285  | 
||
| 24465 | 286  | 
lemma nat_no_eq_iff:  | 
287  | 
"(number_of b :: int) >= 0 ==> (number_of c :: int) >= 0 ==>  | 
|
| 27570 | 288  | 
(number_of b = (number_of c :: nat)) = (b = c)"  | 
289  | 
apply (unfold nat_number_of_def)  | 
|
| 24465 | 290  | 
apply safe  | 
291  | 
apply (drule (2) eq_nat_nat_iff [THEN iffD1])  | 
|
292  | 
apply (simp add: number_of_eq)  | 
|
293  | 
done  | 
|
294  | 
||
| 24333 | 295  | 
lemmas dme = box_equals [OF div_mod_equality add_0_right add_0_right]  | 
296  | 
lemmas dtle = xtr3 [OF dme [symmetric] le_add1]  | 
|
297  | 
lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] dtle]  | 
|
298  | 
||
299  | 
lemma td_gal:  | 
|
300  | 
"0 < c ==> (a >= b * c) = (a div c >= (b :: nat))"  | 
|
301  | 
apply safe  | 
|
302  | 
apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])  | 
|
303  | 
apply (erule th2)  | 
|
304  | 
done  | 
|
305  | 
||
| 
26072
 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
 
haftmann 
parents: 
25937 
diff
changeset
 | 
306  | 
lemmas td_gal_lt = td_gal [simplified not_less [symmetric], simplified]  | 
| 24333 | 307  | 
|
308  | 
lemma div_mult_le: "(a :: nat) div b * b <= a"  | 
|
309  | 
apply (cases b)  | 
|
310  | 
prefer 2  | 
|
311  | 
apply (rule order_refl [THEN th2])  | 
|
312  | 
apply auto  | 
|
313  | 
done  | 
|
314  | 
||
315  | 
lemmas sdl = split_div_lemma [THEN iffD1, symmetric]  | 
|
316  | 
||
317  | 
lemma given_quot: "f > (0 :: nat) ==> (f * l + (f - 1)) div f = l"  | 
|
318  | 
by (rule sdl, assumption) (simp (no_asm))  | 
|
319  | 
||
320  | 
lemma given_quot_alt: "f > (0 :: nat) ==> (l * f + f - Suc 0) div f = l"  | 
|
321  | 
apply (frule given_quot)  | 
|
322  | 
apply (rule trans)  | 
|
323  | 
prefer 2  | 
|
324  | 
apply (erule asm_rl)  | 
|
325  | 
apply (rule_tac f="%n. n div f" in arg_cong)  | 
|
326  | 
apply (simp add : mult_ac)  | 
|
327  | 
done  | 
|
328  | 
||
| 24465 | 329  | 
lemma diff_mod_le: "(a::nat) < d ==> b dvd d ==> a - a mod b <= d - b"  | 
330  | 
apply (unfold dvd_def)  | 
|
331  | 
apply clarify  | 
|
332  | 
apply (case_tac k)  | 
|
333  | 
apply clarsimp  | 
|
334  | 
apply clarify  | 
|
335  | 
apply (cases "b > 0")  | 
|
336  | 
apply (drule mult_commute [THEN xtr1])  | 
|
337  | 
apply (frule (1) td_gal_lt [THEN iffD1])  | 
|
338  | 
apply (clarsimp simp: le_simps)  | 
|
339  | 
apply (rule mult_div_cancel [THEN [2] xtr4])  | 
|
340  | 
apply (rule mult_mono)  | 
|
341  | 
apply auto  | 
|
342  | 
done  | 
|
343  | 
||
| 24333 | 344  | 
lemma less_le_mult':  | 
345  | 
"w * c < b * c ==> 0 \<le> c ==> (w + 1) * c \<le> b * (c::int)"  | 
|
346  | 
apply (rule mult_right_mono)  | 
|
347  | 
apply (rule zless_imp_add1_zle)  | 
|
348  | 
apply (erule (1) mult_right_less_imp_less)  | 
|
349  | 
apply assumption  | 
|
350  | 
done  | 
|
351  | 
||
352  | 
lemmas less_le_mult = less_le_mult' [simplified left_distrib, simplified]  | 
|
| 24465 | 353  | 
|
354  | 
lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult,  | 
|
| 45604 | 355  | 
simplified left_diff_distrib]  | 
| 24333 | 356  | 
|
357  | 
lemma lrlem':  | 
|
358  | 
assumes d: "(i::nat) \<le> j \<or> m < j'"  | 
|
359  | 
assumes R1: "i * k \<le> j * k \<Longrightarrow> R"  | 
|
360  | 
assumes R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"  | 
|
361  | 
shows "R" using d  | 
|
362  | 
apply safe  | 
|
363  | 
apply (rule R1, erule mult_le_mono1)  | 
|
364  | 
apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])  | 
|
365  | 
done  | 
|
366  | 
||
367  | 
lemma lrlem: "(0::nat) < sc ==>  | 
|
368  | 
(sc - n + (n + lb * n) <= m * n) = (sc + lb * n <= m * n)"  | 
|
369  | 
apply safe  | 
|
370  | 
apply arith  | 
|
371  | 
apply (case_tac "sc >= n")  | 
|
372  | 
apply arith  | 
|
373  | 
apply (insert linorder_le_less_linear [of m lb])  | 
|
374  | 
apply (erule_tac k=n and k'=n in lrlem')  | 
|
375  | 
apply arith  | 
|
376  | 
apply simp  | 
|
377  | 
done  | 
|
378  | 
||
379  | 
lemma gen_minus: "0 < n ==> f n = f (Suc (n - 1))"  | 
|
380  | 
by auto  | 
|
381  | 
||
| 27570 | 382  | 
lemma mpl_lem: "j <= (i :: nat) ==> k < j ==> i - j + k < i" by arith  | 
| 24333 | 383  | 
|
| 24465 | 384  | 
lemma nonneg_mod_div:  | 
385  | 
"0 <= a ==> 0 <= b ==> 0 <= (a mod b :: int) & 0 <= a div b"  | 
|
386  | 
apply (cases "b = 0", clarsimp)  | 
|
387  | 
apply (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])  | 
|
388  | 
done  | 
|
| 24399 | 389  | 
|
| 24333 | 390  | 
end  |