286 apply (unfold diff_int_def) |
286 apply (unfold diff_int_def) |
287 apply (rule trans [OF _ zmod_zadd_right_eq [symmetric]]) |
287 apply (rule trans [OF _ zmod_zadd_right_eq [symmetric]]) |
288 apply (simp add : zmod_uminus zmod_zadd_right_eq [symmetric]) |
288 apply (simp add : zmod_uminus zmod_zadd_right_eq [symmetric]) |
289 done |
289 done |
290 |
290 |
291 lemmas zmod_zsub_left_eq = |
291 lemma zmod_zsub_left_eq: "((a::int) - b) mod c = (a mod c - b) mod c" |
292 zmod_zadd_left_eq [where b = "- ?b", simplified diff_int_def [symmetric]] |
292 by (rule zmod_zadd_left_eq [where b = "- b", simplified diff_int_def [symmetric]]) |
293 |
293 |
294 lemma zmod_zsub_self [simp]: |
294 lemma zmod_zsub_self [simp]: |
295 "((b :: int) - a) mod a = b mod a" |
295 "((b :: int) - a) mod a = b mod a" |
296 by (simp add: zmod_zsub_right_eq) |
296 by (simp add: zmod_zsub_right_eq) |
297 |
297 |
298 lemma zmod_zmult1_eq_rev: |
298 lemma zmod_zmult1_eq_rev: |
376 lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a" |
376 lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a" |
377 apply (cases "a < n") |
377 apply (cases "a < n") |
378 apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a]) |
378 apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a]) |
379 done |
379 done |
380 |
380 |
381 lemmas int_mod_le' = int_mod_le [where a = "?b - ?n", simplified] |
381 lemma int_mod_le': "0 <= b - n ==> 0 < (n :: int) ==> b mod n <= b - n" |
|
382 by (rule int_mod_le [where a = "b - n" and n = n, simplified]) |
382 |
383 |
383 lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n" |
384 lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n" |
384 apply (cases "0 <= a") |
385 apply (cases "0 <= a") |
385 apply (drule (1) mod_pos_pos_trivial) |
386 apply (drule (1) mod_pos_pos_trivial) |
386 apply simp |
387 apply simp |
387 apply (rule order_trans [OF _ pos_mod_sign]) |
388 apply (rule order_trans [OF _ pos_mod_sign]) |
388 apply simp |
389 apply simp |
389 apply assumption |
390 apply assumption |
390 done |
391 done |
391 |
392 |
392 lemmas int_mod_ge' = int_mod_ge [where a = "?b + ?n", simplified] |
393 lemma int_mod_ge': "b < 0 ==> 0 < (n :: int) ==> b + n <= b mod n" |
|
394 by (rule int_mod_ge [where a = "b + n" and n = n, simplified]) |
393 |
395 |
394 lemma mod_add_if_z: |
396 lemma mod_add_if_z: |
395 "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> |
397 "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> |
396 (x + y) mod z = (if x + y < z then x + y else x + y - z)" |
398 (x + y) mod z = (if x + y < z then x + y else x + y - z)" |
397 by (auto intro: int_mod_eq) |
399 by (auto intro: int_mod_eq) |