author | wenzelm |
Tue, 17 Sep 2013 17:17:55 +0200 | |
changeset 53685 | 983711bc98e0 |
parent 53062 | 3af1a6020014 |
child 54221 | 56587960e444 |
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 |
51301 | 8 |
imports Main Parity |
25592 | 9 |
begin |
24333 | 10 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
11 |
lemma zmod_zsub_self [simp]: (* FIXME move to Divides.thy *) |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
12 |
"((b :: int) - a) mod a = b mod a" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
13 |
by (simp add: mod_diff_right_eq) |
24333 | 14 |
|
24465 | 15 |
declare iszero_0 [iff] |
16 |
||
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
17 |
lemma min_pm [simp]: "min a b + (a - b) = (a :: nat)" by arith |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
18 |
|
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
19 |
lemmas min_pm1 [simp] = trans [OF add_commute min_pm] |
24333 | 20 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
21 |
lemma rev_min_pm [simp]: "min b a + (a - b) = (a::nat)" by arith |
24465 | 22 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
23 |
lemmas rev_min_pm1 [simp] = trans [OF add_commute rev_min_pm] |
24333 | 24 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
25 |
lemma min_minus [simp] : "min m (m - k) = (m - k :: nat)" by arith |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
26 |
|
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
27 |
lemmas min_minus' [simp] = trans [OF min_max.inf_commute min_minus] |
24465 | 28 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
29 |
lemma z1pmod2: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
30 |
"(2 * b + 1) mod 2 = (1::int)" by arith |
24333 | 31 |
|
32 |
lemma emep1: |
|
33 |
"even n ==> even d ==> 0 <= d ==> (n + 1) mod (d :: int) = (n mod d) + 1" |
|
34 |
apply (simp add: add_commute) |
|
35 |
apply (safe dest!: even_equiv_def [THEN iffD1]) |
|
36 |
apply (subst pos_zmod_mult_2) |
|
37 |
apply arith |
|
30943
eb3dbbe971f6
zmod_zmult_zmult1 now subsumed by mod_mult_mult1
haftmann
parents:
30445
diff
changeset
|
38 |
apply (simp add: mod_mult_mult1) |
24333 | 39 |
done |
40 |
||
41 |
lemma int_mod_lem: |
|
42 |
"(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)" |
|
43 |
apply safe |
|
44 |
apply (erule (1) mod_pos_pos_trivial) |
|
45 |
apply (erule_tac [!] subst) |
|
46 |
apply auto |
|
47 |
done |
|
48 |
||
49 |
lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n" |
|
50 |
apply (cases "0 <= a") |
|
51 |
apply (drule (1) mod_pos_pos_trivial) |
|
52 |
apply simp |
|
53 |
apply (rule order_trans [OF _ pos_mod_sign]) |
|
54 |
apply simp |
|
55 |
apply assumption |
|
56 |
done |
|
57 |
||
25349
0d46bea01741
eliminated illegal schematic variables in where/of;
wenzelm
parents:
24465
diff
changeset
|
58 |
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
|
59 |
by (rule int_mod_ge [where a = "b + n" and n = n, simplified]) |
24333 | 60 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
61 |
lemma zless2: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
62 |
"0 < (2 :: int)" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
63 |
by arith |
24465 | 64 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
65 |
lemma zless2p: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
66 |
"0 < (2 ^ n :: int)" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
67 |
by arith |
24333 | 68 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
69 |
lemma zle2p: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
70 |
"0 \<le> (2 ^ n :: int)" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
71 |
by arith |
24465 | 72 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
73 |
lemma int_mod_le': "(0::int) <= b - n ==> b mod n <= b - n" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
74 |
using zmod_le_nonneg_dividend [of "b - n" "n"] by simp |
24333 | 75 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
76 |
lemma diff_le_eq': "(a - b \<le> c) = (a \<le> b + (c::int))" by arith |
24333 | 77 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
78 |
lemma m1mod2k: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
79 |
"-1 mod 2 ^ n = (2 ^ n - 1 :: int)" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
80 |
using zless2p by (rule zmod_minus1) |
24333 | 81 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
82 |
lemma p1mod22k': |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
83 |
fixes b :: int |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
84 |
shows "(1 + 2 * b) mod (2 * 2 ^ n) = 1 + 2 * (b mod 2 ^ n)" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
85 |
using zle2p by (rule pos_zmod_mult_2) |
24465 | 86 |
|
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
87 |
lemma p1mod22k: |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
88 |
fixes b :: int |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
89 |
shows "(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + 1" |
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
90 |
by (simp add: p1mod22k' add_commute) |
24333 | 91 |
|
92 |
lemma lrlem': |
|
93 |
assumes d: "(i::nat) \<le> j \<or> m < j'" |
|
94 |
assumes R1: "i * k \<le> j * k \<Longrightarrow> R" |
|
95 |
assumes R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R" |
|
96 |
shows "R" using d |
|
97 |
apply safe |
|
98 |
apply (rule R1, erule mult_le_mono1) |
|
99 |
apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]]) |
|
100 |
done |
|
101 |
||
102 |
lemma lrlem: "(0::nat) < sc ==> |
|
103 |
(sc - n + (n + lb * n) <= m * n) = (sc + lb * n <= m * n)" |
|
104 |
apply safe |
|
105 |
apply arith |
|
106 |
apply (case_tac "sc >= n") |
|
107 |
apply arith |
|
108 |
apply (insert linorder_le_less_linear [of m lb]) |
|
109 |
apply (erule_tac k=n and k'=n in lrlem') |
|
110 |
apply arith |
|
111 |
apply simp |
|
112 |
done |
|
113 |
||
53062
3af1a6020014
some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
51301
diff
changeset
|
114 |
end |
24333 | 115 |