author | huffman |
Wed, 12 Oct 2005 03:01:09 +0200 | |
changeset 17838 | 3032e90c4975 |
parent 17508 | c84af7f39a6b |
child 18648 | 22f96cd085d5 |
permissions | -rw-r--r-- |
6917 | 1 |
(* Title: HOL/IntDiv.thy |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
||
15221 | 6 |
*) |
7 |
||
8 |
||
9 |
header{*The Division Operators div and mod; the Divides Relation dvd*} |
|
10 |
||
11 |
theory IntDiv |
|
17508 | 12 |
imports SetInterval Recdef |
16417 | 13 |
uses ("IntDiv_setup.ML") |
15221 | 14 |
begin |
15 |
||
16 |
declare zless_nat_conj [simp] |
|
17 |
||
18 |
constdefs |
|
19 |
quorem :: "(int*int) * (int*int) => bool" |
|
20 |
--{*definition of quotient and remainder*} |
|
21 |
"quorem == %((a,b), (q,r)). |
|
22 |
a = b*q + r & |
|
23 |
(if 0 < b then 0\<le>r & r<b else b<r & r \<le> 0)" |
|
24 |
||
25 |
adjust :: "[int, int*int] => int*int" |
|
26 |
--{*for the division algorithm*} |
|
27 |
"adjust b == %(q,r). if 0 \<le> r-b then (2*q + 1, r-b) |
|
28 |
else (2*q, r)" |
|
29 |
||
30 |
text{*algorithm for the case @{text "a\<ge>0, b>0"}*} |
|
31 |
consts posDivAlg :: "int*int => int*int" |
|
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
32 |
recdef posDivAlg "measure (%(a,b). nat(a - b + 1))" |
15221 | 33 |
"posDivAlg (a,b) = |
34 |
(if (a<b | b\<le>0) then (0,a) |
|
35 |
else adjust b (posDivAlg(a, 2*b)))" |
|
13183 | 36 |
|
15221 | 37 |
text{*algorithm for the case @{text "a<0, b>0"}*} |
38 |
consts negDivAlg :: "int*int => int*int" |
|
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
39 |
recdef negDivAlg "measure (%(a,b). nat(- a - b))" |
15221 | 40 |
"negDivAlg (a,b) = |
41 |
(if (0\<le>a+b | b\<le>0) then (-1,a+b) |
|
42 |
else adjust b (negDivAlg(a, 2*b)))" |
|
43 |
||
44 |
text{*algorithm for the general case @{term "b\<noteq>0"}*} |
|
45 |
constdefs |
|
46 |
negateSnd :: "int*int => int*int" |
|
47 |
"negateSnd == %(q,r). (q,-r)" |
|
48 |
||
49 |
divAlg :: "int*int => int*int" |
|
50 |
--{*The full division algorithm considers all possible signs for a, b |
|
51 |
including the special case @{text "a=0, b<0"} because |
|
52 |
@{term negDivAlg} requires @{term "a<0"}.*} |
|
53 |
"divAlg == |
|
54 |
%(a,b). if 0\<le>a then |
|
55 |
if 0\<le>b then posDivAlg (a,b) |
|
56 |
else if a=0 then (0,0) |
|
57 |
else negateSnd (negDivAlg (-a,-b)) |
|
58 |
else |
|
59 |
if 0<b then negDivAlg (a,b) |
|
60 |
else negateSnd (posDivAlg (-a,-b))" |
|
61 |
||
62 |
instance |
|
63 |
int :: "Divides.div" .. --{*avoid clash with 'div' token*} |
|
64 |
||
65 |
text{*The operators are defined with reference to the algorithm, which is |
|
66 |
proved to satisfy the specification.*} |
|
67 |
defs |
|
68 |
div_def: "a div b == fst (divAlg (a,b))" |
|
69 |
mod_def: "a mod b == snd (divAlg (a,b))" |
|
70 |
||
71 |
||
72 |
text{* |
|
13183 | 73 |
Here is the division algorithm in ML: |
74 |
||
15221 | 75 |
\begin{verbatim} |
13183 | 76 |
fun posDivAlg (a,b) = |
77 |
if a<b then (0,a) |
|
78 |
else let val (q,r) = posDivAlg(a, 2*b) |
|
14288 | 79 |
in if 0\<le>r-b then (2*q+1, r-b) else (2*q, r) |
13183 | 80 |
end |
81 |
||
82 |
fun negDivAlg (a,b) = |
|
14288 | 83 |
if 0\<le>a+b then (~1,a+b) |
13183 | 84 |
else let val (q,r) = negDivAlg(a, 2*b) |
14288 | 85 |
in if 0\<le>r-b then (2*q+1, r-b) else (2*q, r) |
13183 | 86 |
end; |
87 |
||
88 |
fun negateSnd (q,r:int) = (q,~r); |
|
89 |
||
14288 | 90 |
fun divAlg (a,b) = if 0\<le>a then |
13183 | 91 |
if b>0 then posDivAlg (a,b) |
92 |
else if a=0 then (0,0) |
|
93 |
else negateSnd (negDivAlg (~a,~b)) |
|
94 |
else |
|
95 |
if 0<b then negDivAlg (a,b) |
|
96 |
else negateSnd (posDivAlg (~a,~b)); |
|
15221 | 97 |
\end{verbatim} |
98 |
*} |
|
13183 | 99 |
|
100 |
||
101 |
||
14271 | 102 |
subsection{*Uniqueness and Monotonicity of Quotients and Remainders*} |
13183 | 103 |
|
104 |
lemma unique_quotient_lemma: |
|
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16417
diff
changeset
|
105 |
"[| b*q' + r' \<le> b*q + r; 0 \<le> r'; r' < b; r < b |] |
14288 | 106 |
==> q' \<le> (q::int)" |
107 |
apply (subgoal_tac "r' + b * (q'-q) \<le> r") |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
108 |
prefer 2 apply (simp add: right_diff_distrib) |
13183 | 109 |
apply (subgoal_tac "0 < b * (1 + q - q') ") |
110 |
apply (erule_tac [2] order_le_less_trans) |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
111 |
prefer 2 apply (simp add: right_diff_distrib right_distrib) |
13183 | 112 |
apply (subgoal_tac "b * q' < b * (1 + q) ") |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
113 |
prefer 2 apply (simp add: right_diff_distrib right_distrib) |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
114 |
apply (simp add: mult_less_cancel_left) |
13183 | 115 |
done |
116 |
||
117 |
lemma unique_quotient_lemma_neg: |
|
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16417
diff
changeset
|
118 |
"[| b*q' + r' \<le> b*q + r; r \<le> 0; b < r; b < r' |] |
14288 | 119 |
==> q \<le> (q'::int)" |
13183 | 120 |
by (rule_tac b = "-b" and r = "-r'" and r' = "-r" in unique_quotient_lemma, |
121 |
auto) |
|
122 |
||
123 |
lemma unique_quotient: |
|
15221 | 124 |
"[| quorem ((a,b), (q,r)); quorem ((a,b), (q',r')); b \<noteq> 0 |] |
13183 | 125 |
==> q = q'" |
126 |
apply (simp add: quorem_def linorder_neq_iff split: split_if_asm) |
|
127 |
apply (blast intro: order_antisym |
|
128 |
dest: order_eq_refl [THEN unique_quotient_lemma] |
|
129 |
order_eq_refl [THEN unique_quotient_lemma_neg] sym)+ |
|
130 |
done |
|
131 |
||
132 |
||
133 |
lemma unique_remainder: |
|
15221 | 134 |
"[| quorem ((a,b), (q,r)); quorem ((a,b), (q',r')); b \<noteq> 0 |] |
13183 | 135 |
==> r = r'" |
136 |
apply (subgoal_tac "q = q'") |
|
137 |
apply (simp add: quorem_def) |
|
138 |
apply (blast intro: unique_quotient) |
|
139 |
done |
|
140 |
||
141 |
||
15221 | 142 |
subsection{*Correctness of @{term posDivAlg}, the Algorithm for Non-Negative Dividends*} |
14271 | 143 |
|
144 |
text{*And positive divisors*} |
|
13183 | 145 |
|
146 |
lemma adjust_eq [simp]: |
|
147 |
"adjust b (q,r) = |
|
148 |
(let diff = r-b in |
|
14288 | 149 |
if 0 \<le> diff then (2*q + 1, diff) |
13183 | 150 |
else (2*q, r))" |
151 |
by (simp add: Let_def adjust_def) |
|
152 |
||
153 |
declare posDivAlg.simps [simp del] |
|
154 |
||
15221 | 155 |
text{*use with a simproc to avoid repeatedly proving the premise*} |
13183 | 156 |
lemma posDivAlg_eqn: |
157 |
"0 < b ==> |
|
158 |
posDivAlg (a,b) = (if a<b then (0,a) else adjust b (posDivAlg(a, 2*b)))" |
|
159 |
by (rule posDivAlg.simps [THEN trans], simp) |
|
160 |
||
15221 | 161 |
text{*Correctness of @{term posDivAlg}: it computes quotients correctly*} |
162 |
theorem posDivAlg_correct [rule_format]: |
|
14288 | 163 |
"0 \<le> a --> 0 < b --> quorem ((a, b), posDivAlg (a, b))" |
13183 | 164 |
apply (induct_tac a b rule: posDivAlg.induct, auto) |
165 |
apply (simp_all add: quorem_def) |
|
166 |
(*base case: a<b*) |
|
167 |
apply (simp add: posDivAlg_eqn) |
|
168 |
(*main argument*) |
|
169 |
apply (subst posDivAlg_eqn, simp_all) |
|
170 |
apply (erule splitE) |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
171 |
apply (auto simp add: right_distrib Let_def) |
13183 | 172 |
done |
173 |
||
174 |
||
15221 | 175 |
subsection{*Correctness of @{term negDivAlg}, the Algorithm for Negative Dividends*} |
14271 | 176 |
|
177 |
text{*And positive divisors*} |
|
13183 | 178 |
|
179 |
declare negDivAlg.simps [simp del] |
|
180 |
||
15221 | 181 |
text{*use with a simproc to avoid repeatedly proving the premise*} |
13183 | 182 |
lemma negDivAlg_eqn: |
183 |
"0 < b ==> |
|
184 |
negDivAlg (a,b) = |
|
14288 | 185 |
(if 0\<le>a+b then (-1,a+b) else adjust b (negDivAlg(a, 2*b)))" |
13183 | 186 |
by (rule negDivAlg.simps [THEN trans], simp) |
187 |
||
188 |
(*Correctness of negDivAlg: it computes quotients correctly |
|
189 |
It doesn't work if a=0 because the 0/b equals 0, not -1*) |
|
190 |
lemma negDivAlg_correct [rule_format]: |
|
191 |
"a < 0 --> 0 < b --> quorem ((a, b), negDivAlg (a, b))" |
|
192 |
apply (induct_tac a b rule: negDivAlg.induct, auto) |
|
193 |
apply (simp_all add: quorem_def) |
|
14288 | 194 |
(*base case: 0\<le>a+b*) |
13183 | 195 |
apply (simp add: negDivAlg_eqn) |
196 |
(*main argument*) |
|
197 |
apply (subst negDivAlg_eqn, assumption) |
|
198 |
apply (erule splitE) |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
199 |
apply (auto simp add: right_distrib Let_def) |
13183 | 200 |
done |
201 |
||
202 |
||
14271 | 203 |
subsection{*Existence Shown by Proving the Division Algorithm to be Correct*} |
13183 | 204 |
|
205 |
(*the case a=0*) |
|
15221 | 206 |
lemma quorem_0: "b \<noteq> 0 ==> quorem ((0,b), (0,0))" |
13183 | 207 |
by (auto simp add: quorem_def linorder_neq_iff) |
208 |
||
209 |
lemma posDivAlg_0 [simp]: "posDivAlg (0, b) = (0, 0)" |
|
210 |
by (subst posDivAlg.simps, auto) |
|
211 |
||
212 |
lemma negDivAlg_minus1 [simp]: "negDivAlg (-1, b) = (-1, b - 1)" |
|
213 |
by (subst negDivAlg.simps, auto) |
|
214 |
||
215 |
lemma negateSnd_eq [simp]: "negateSnd(q,r) = (q,-r)" |
|
15221 | 216 |
by (simp add: negateSnd_def) |
13183 | 217 |
|
218 |
lemma quorem_neg: "quorem ((-a,-b), qr) ==> quorem ((a,b), negateSnd qr)" |
|
219 |
by (auto simp add: split_ifs quorem_def) |
|
220 |
||
15221 | 221 |
lemma divAlg_correct: "b \<noteq> 0 ==> quorem ((a,b), divAlg(a,b))" |
13183 | 222 |
by (force simp add: linorder_neq_iff quorem_0 divAlg_def quorem_neg |
223 |
posDivAlg_correct negDivAlg_correct) |
|
224 |
||
15221 | 225 |
text{*Arbitrary definitions for division by zero. Useful to simplify |
226 |
certain equations.*} |
|
13183 | 227 |
|
14271 | 228 |
lemma DIVISION_BY_ZERO [simp]: "a div (0::int) = 0 & a mod (0::int) = a" |
229 |
by (simp add: div_def mod_def divAlg_def posDivAlg.simps) |
|
13183 | 230 |
|
15221 | 231 |
|
232 |
text{*Basic laws about division and remainder*} |
|
13183 | 233 |
|
234 |
lemma zmod_zdiv_equality: "(a::int) = b * (a div b) + (a mod b)" |
|
15013 | 235 |
apply (case_tac "b = 0", simp) |
13183 | 236 |
apply (cut_tac a = a and b = b in divAlg_correct) |
237 |
apply (auto simp add: quorem_def div_def mod_def) |
|
238 |
done |
|
239 |
||
13517 | 240 |
lemma zdiv_zmod_equality: "(b * (a div b) + (a mod b)) + k = (a::int)+k" |
241 |
by(simp add: zmod_zdiv_equality[symmetric]) |
|
242 |
||
243 |
lemma zdiv_zmod_equality2: "((a div b) * b + (a mod b)) + k = (a::int)+k" |
|
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
244 |
by(simp add: mult_commute zmod_zdiv_equality[symmetric]) |
13517 | 245 |
|
246 |
use "IntDiv_setup.ML" |
|
247 |
||
14288 | 248 |
lemma pos_mod_conj : "(0::int) < b ==> 0 \<le> a mod b & a mod b < b" |
13183 | 249 |
apply (cut_tac a = a and b = b in divAlg_correct) |
250 |
apply (auto simp add: quorem_def mod_def) |
|
251 |
done |
|
252 |
||
13788 | 253 |
lemmas pos_mod_sign[simp] = pos_mod_conj [THEN conjunct1, standard] |
254 |
and pos_mod_bound[simp] = pos_mod_conj [THEN conjunct2, standard] |
|
13183 | 255 |
|
14288 | 256 |
lemma neg_mod_conj : "b < (0::int) ==> a mod b \<le> 0 & b < a mod b" |
13183 | 257 |
apply (cut_tac a = a and b = b in divAlg_correct) |
258 |
apply (auto simp add: quorem_def div_def mod_def) |
|
259 |
done |
|
260 |
||
13788 | 261 |
lemmas neg_mod_sign[simp] = neg_mod_conj [THEN conjunct1, standard] |
262 |
and neg_mod_bound[simp] = neg_mod_conj [THEN conjunct2, standard] |
|
13183 | 263 |
|
264 |
||
13260 | 265 |
|
15221 | 266 |
subsection{*General Properties of div and mod*} |
13183 | 267 |
|
15221 | 268 |
lemma quorem_div_mod: "b \<noteq> 0 ==> quorem ((a, b), (a div b, a mod b))" |
13183 | 269 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
13788 | 270 |
apply (force simp add: quorem_def linorder_neq_iff) |
13183 | 271 |
done |
272 |
||
15221 | 273 |
lemma quorem_div: "[| quorem((a,b),(q,r)); b \<noteq> 0 |] ==> a div b = q" |
13183 | 274 |
by (simp add: quorem_div_mod [THEN unique_quotient]) |
275 |
||
15221 | 276 |
lemma quorem_mod: "[| quorem((a,b),(q,r)); b \<noteq> 0 |] ==> a mod b = r" |
13183 | 277 |
by (simp add: quorem_div_mod [THEN unique_remainder]) |
278 |
||
14288 | 279 |
lemma div_pos_pos_trivial: "[| (0::int) \<le> a; a < b |] ==> a div b = 0" |
13183 | 280 |
apply (rule quorem_div) |
281 |
apply (auto simp add: quorem_def) |
|
282 |
done |
|
283 |
||
14288 | 284 |
lemma div_neg_neg_trivial: "[| a \<le> (0::int); b < a |] ==> a div b = 0" |
13183 | 285 |
apply (rule quorem_div) |
286 |
apply (auto simp add: quorem_def) |
|
287 |
done |
|
288 |
||
14288 | 289 |
lemma div_pos_neg_trivial: "[| (0::int) < a; a+b \<le> 0 |] ==> a div b = -1" |
13183 | 290 |
apply (rule quorem_div) |
291 |
apply (auto simp add: quorem_def) |
|
292 |
done |
|
293 |
||
294 |
(*There is no div_neg_pos_trivial because 0 div b = 0 would supersede it*) |
|
295 |
||
14288 | 296 |
lemma mod_pos_pos_trivial: "[| (0::int) \<le> a; a < b |] ==> a mod b = a" |
13183 | 297 |
apply (rule_tac q = 0 in quorem_mod) |
298 |
apply (auto simp add: quorem_def) |
|
299 |
done |
|
300 |
||
14288 | 301 |
lemma mod_neg_neg_trivial: "[| a \<le> (0::int); b < a |] ==> a mod b = a" |
13183 | 302 |
apply (rule_tac q = 0 in quorem_mod) |
303 |
apply (auto simp add: quorem_def) |
|
304 |
done |
|
305 |
||
14288 | 306 |
lemma mod_pos_neg_trivial: "[| (0::int) < a; a+b \<le> 0 |] ==> a mod b = a+b" |
13183 | 307 |
apply (rule_tac q = "-1" in quorem_mod) |
308 |
apply (auto simp add: quorem_def) |
|
309 |
done |
|
310 |
||
15221 | 311 |
text{*There is no @{text mod_neg_pos_trivial}.*} |
13183 | 312 |
|
313 |
||
314 |
(*Simpler laws such as -a div b = -(a div b) FAIL, but see just below*) |
|
315 |
lemma zdiv_zminus_zminus [simp]: "(-a) div (-b) = a div (b::int)" |
|
15013 | 316 |
apply (case_tac "b = 0", simp) |
13183 | 317 |
apply (simp add: quorem_div_mod [THEN quorem_neg, simplified, |
318 |
THEN quorem_div, THEN sym]) |
|
319 |
||
320 |
done |
|
321 |
||
322 |
(*Simpler laws such as -a mod b = -(a mod b) FAIL, but see just below*) |
|
323 |
lemma zmod_zminus_zminus [simp]: "(-a) mod (-b) = - (a mod (b::int))" |
|
15013 | 324 |
apply (case_tac "b = 0", simp) |
13183 | 325 |
apply (subst quorem_div_mod [THEN quorem_neg, simplified, THEN quorem_mod], |
326 |
auto) |
|
327 |
done |
|
328 |
||
15221 | 329 |
|
330 |
subsection{*Laws for div and mod with Unary Minus*} |
|
13183 | 331 |
|
332 |
lemma zminus1_lemma: |
|
333 |
"quorem((a,b),(q,r)) |
|
334 |
==> quorem ((-a,b), (if r=0 then -q else -q - 1), |
|
335 |
(if r=0 then 0 else b-r))" |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
336 |
by (force simp add: split_ifs quorem_def linorder_neq_iff right_diff_distrib) |
13183 | 337 |
|
338 |
||
339 |
lemma zdiv_zminus1_eq_if: |
|
15221 | 340 |
"b \<noteq> (0::int) |
13183 | 341 |
==> (-a) div b = |
342 |
(if a mod b = 0 then - (a div b) else - (a div b) - 1)" |
|
343 |
by (blast intro: quorem_div_mod [THEN zminus1_lemma, THEN quorem_div]) |
|
344 |
||
345 |
lemma zmod_zminus1_eq_if: |
|
346 |
"(-a::int) mod b = (if a mod b = 0 then 0 else b - (a mod b))" |
|
15013 | 347 |
apply (case_tac "b = 0", simp) |
13183 | 348 |
apply (blast intro: quorem_div_mod [THEN zminus1_lemma, THEN quorem_mod]) |
349 |
done |
|
350 |
||
351 |
lemma zdiv_zminus2: "a div (-b) = (-a::int) div b" |
|
352 |
by (cut_tac a = "-a" in zdiv_zminus_zminus, auto) |
|
353 |
||
354 |
lemma zmod_zminus2: "a mod (-b) = - ((-a::int) mod b)" |
|
355 |
by (cut_tac a = "-a" and b = b in zmod_zminus_zminus, auto) |
|
356 |
||
357 |
lemma zdiv_zminus2_eq_if: |
|
15221 | 358 |
"b \<noteq> (0::int) |
13183 | 359 |
==> a div (-b) = |
360 |
(if a mod b = 0 then - (a div b) else - (a div b) - 1)" |
|
361 |
by (simp add: zdiv_zminus1_eq_if zdiv_zminus2) |
|
362 |
||
363 |
lemma zmod_zminus2_eq_if: |
|
364 |
"a mod (-b::int) = (if a mod b = 0 then 0 else (a mod b) - b)" |
|
365 |
by (simp add: zmod_zminus1_eq_if zmod_zminus2) |
|
366 |
||
367 |
||
14271 | 368 |
subsection{*Division of a Number by Itself*} |
13183 | 369 |
|
14288 | 370 |
lemma self_quotient_aux1: "[| (0::int) < a; a = r + a*q; r < a |] ==> 1 \<le> q" |
13183 | 371 |
apply (subgoal_tac "0 < a*q") |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
372 |
apply (simp add: zero_less_mult_iff, arith) |
13183 | 373 |
done |
374 |
||
14288 | 375 |
lemma self_quotient_aux2: "[| (0::int) < a; a = r + a*q; 0 \<le> r |] ==> q \<le> 1" |
376 |
apply (subgoal_tac "0 \<le> a* (1-q) ") |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
377 |
apply (simp add: zero_le_mult_iff) |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
378 |
apply (simp add: right_diff_distrib) |
13183 | 379 |
done |
380 |
||
15221 | 381 |
lemma self_quotient: "[| quorem((a,a),(q,r)); a \<noteq> (0::int) |] ==> q = 1" |
13183 | 382 |
apply (simp add: split_ifs quorem_def linorder_neq_iff) |
15221 | 383 |
apply (rule order_antisym, safe, simp_all) |
13524 | 384 |
apply (rule_tac [3] a = "-a" and r = "-r" in self_quotient_aux1) |
385 |
apply (rule_tac a = "-a" and r = "-r" in self_quotient_aux2) |
|
15221 | 386 |
apply (force intro: self_quotient_aux1 self_quotient_aux2 simp add: add_commute)+ |
13183 | 387 |
done |
388 |
||
15221 | 389 |
lemma self_remainder: "[| quorem((a,a),(q,r)); a \<noteq> (0::int) |] ==> r = 0" |
13183 | 390 |
apply (frule self_quotient, assumption) |
391 |
apply (simp add: quorem_def) |
|
392 |
done |
|
393 |
||
15221 | 394 |
lemma zdiv_self [simp]: "a \<noteq> 0 ==> a div a = (1::int)" |
13183 | 395 |
by (simp add: quorem_div_mod [THEN self_quotient]) |
396 |
||
397 |
(*Here we have 0 mod 0 = 0, also assumed by Knuth (who puts m mod 0 = 0) *) |
|
398 |
lemma zmod_self [simp]: "a mod a = (0::int)" |
|
15013 | 399 |
apply (case_tac "a = 0", simp) |
13183 | 400 |
apply (simp add: quorem_div_mod [THEN self_remainder]) |
401 |
done |
|
402 |
||
403 |
||
14271 | 404 |
subsection{*Computation of Division and Remainder*} |
13183 | 405 |
|
406 |
lemma zdiv_zero [simp]: "(0::int) div b = 0" |
|
407 |
by (simp add: div_def divAlg_def) |
|
408 |
||
409 |
lemma div_eq_minus1: "(0::int) < b ==> -1 div b = -1" |
|
410 |
by (simp add: div_def divAlg_def) |
|
411 |
||
412 |
lemma zmod_zero [simp]: "(0::int) mod b = 0" |
|
413 |
by (simp add: mod_def divAlg_def) |
|
414 |
||
415 |
lemma zdiv_minus1: "(0::int) < b ==> -1 div b = -1" |
|
416 |
by (simp add: div_def divAlg_def) |
|
417 |
||
418 |
lemma zmod_minus1: "(0::int) < b ==> -1 mod b = b - 1" |
|
419 |
by (simp add: mod_def divAlg_def) |
|
420 |
||
15221 | 421 |
text{*a positive, b positive *} |
13183 | 422 |
|
14288 | 423 |
lemma div_pos_pos: "[| 0 < a; 0 \<le> b |] ==> a div b = fst (posDivAlg(a,b))" |
13183 | 424 |
by (simp add: div_def divAlg_def) |
425 |
||
14288 | 426 |
lemma mod_pos_pos: "[| 0 < a; 0 \<le> b |] ==> a mod b = snd (posDivAlg(a,b))" |
13183 | 427 |
by (simp add: mod_def divAlg_def) |
428 |
||
15221 | 429 |
text{*a negative, b positive *} |
13183 | 430 |
|
431 |
lemma div_neg_pos: "[| a < 0; 0 < b |] ==> a div b = fst (negDivAlg(a,b))" |
|
432 |
by (simp add: div_def divAlg_def) |
|
433 |
||
434 |
lemma mod_neg_pos: "[| a < 0; 0 < b |] ==> a mod b = snd (negDivAlg(a,b))" |
|
435 |
by (simp add: mod_def divAlg_def) |
|
436 |
||
15221 | 437 |
text{*a positive, b negative *} |
13183 | 438 |
|
439 |
lemma div_pos_neg: |
|
440 |
"[| 0 < a; b < 0 |] ==> a div b = fst (negateSnd(negDivAlg(-a,-b)))" |
|
441 |
by (simp add: div_def divAlg_def) |
|
442 |
||
443 |
lemma mod_pos_neg: |
|
444 |
"[| 0 < a; b < 0 |] ==> a mod b = snd (negateSnd(negDivAlg(-a,-b)))" |
|
445 |
by (simp add: mod_def divAlg_def) |
|
446 |
||
15221 | 447 |
text{*a negative, b negative *} |
13183 | 448 |
|
449 |
lemma div_neg_neg: |
|
14288 | 450 |
"[| a < 0; b \<le> 0 |] ==> a div b = fst (negateSnd(posDivAlg(-a,-b)))" |
13183 | 451 |
by (simp add: div_def divAlg_def) |
452 |
||
453 |
lemma mod_neg_neg: |
|
14288 | 454 |
"[| a < 0; b \<le> 0 |] ==> a mod b = snd (negateSnd(posDivAlg(-a,-b)))" |
13183 | 455 |
by (simp add: mod_def divAlg_def) |
456 |
||
457 |
text {*Simplify expresions in which div and mod combine numerical constants*} |
|
458 |
||
17085 | 459 |
lemmas div_pos_pos_number_of = |
460 |
div_pos_pos [of "number_of v" "number_of w", standard] |
|
461 |
declare div_pos_pos_number_of [simp] |
|
462 |
||
463 |
lemmas div_neg_pos_number_of = |
|
464 |
div_neg_pos [of "number_of v" "number_of w", standard] |
|
465 |
declare div_neg_pos_number_of [simp] |
|
466 |
||
467 |
lemmas div_pos_neg_number_of = |
|
468 |
div_pos_neg [of "number_of v" "number_of w", standard] |
|
469 |
declare div_pos_neg_number_of [simp] |
|
470 |
||
471 |
lemmas div_neg_neg_number_of = |
|
472 |
div_neg_neg [of "number_of v" "number_of w", standard] |
|
473 |
declare div_neg_neg_number_of [simp] |
|
474 |
||
475 |
||
476 |
lemmas mod_pos_pos_number_of = |
|
477 |
mod_pos_pos [of "number_of v" "number_of w", standard] |
|
478 |
declare mod_pos_pos_number_of [simp] |
|
13183 | 479 |
|
17085 | 480 |
lemmas mod_neg_pos_number_of = |
481 |
mod_neg_pos [of "number_of v" "number_of w", standard] |
|
482 |
declare mod_neg_pos_number_of [simp] |
|
483 |
||
484 |
lemmas mod_pos_neg_number_of = |
|
485 |
mod_pos_neg [of "number_of v" "number_of w", standard] |
|
486 |
declare mod_pos_neg_number_of [simp] |
|
13183 | 487 |
|
17085 | 488 |
lemmas mod_neg_neg_number_of = |
489 |
mod_neg_neg [of "number_of v" "number_of w", standard] |
|
490 |
declare mod_neg_neg_number_of [simp] |
|
491 |
||
492 |
||
493 |
lemmas posDivAlg_eqn_number_of = |
|
494 |
posDivAlg_eqn [of "number_of v" "number_of w", standard] |
|
495 |
declare posDivAlg_eqn_number_of [simp] |
|
496 |
||
497 |
lemmas negDivAlg_eqn_number_of = |
|
498 |
negDivAlg_eqn [of "number_of v" "number_of w", standard] |
|
499 |
declare negDivAlg_eqn_number_of [simp] |
|
500 |
||
13183 | 501 |
|
502 |
||
15221 | 503 |
text{*Special-case simplification *} |
13183 | 504 |
|
505 |
lemma zmod_1 [simp]: "a mod (1::int) = 0" |
|
506 |
apply (cut_tac a = a and b = 1 in pos_mod_sign) |
|
13788 | 507 |
apply (cut_tac [2] a = a and b = 1 in pos_mod_bound) |
508 |
apply (auto simp del:pos_mod_bound pos_mod_sign) |
|
509 |
done |
|
13183 | 510 |
|
511 |
lemma zdiv_1 [simp]: "a div (1::int) = a" |
|
512 |
by (cut_tac a = a and b = 1 in zmod_zdiv_equality, auto) |
|
513 |
||
514 |
lemma zmod_minus1_right [simp]: "a mod (-1::int) = 0" |
|
515 |
apply (cut_tac a = a and b = "-1" in neg_mod_sign) |
|
13788 | 516 |
apply (cut_tac [2] a = a and b = "-1" in neg_mod_bound) |
517 |
apply (auto simp del: neg_mod_sign neg_mod_bound) |
|
13183 | 518 |
done |
519 |
||
520 |
lemma zdiv_minus1_right [simp]: "a div (-1::int) = -a" |
|
521 |
by (cut_tac a = a and b = "-1" in zmod_zdiv_equality, auto) |
|
522 |
||
523 |
(** The last remaining special cases for constant arithmetic: |
|
524 |
1 div z and 1 mod z **) |
|
525 |
||
17085 | 526 |
lemmas div_pos_pos_1_number_of = |
527 |
div_pos_pos [OF int_0_less_1, of "number_of w", standard] |
|
528 |
declare div_pos_pos_1_number_of [simp] |
|
529 |
||
530 |
lemmas div_pos_neg_1_number_of = |
|
531 |
div_pos_neg [OF int_0_less_1, of "number_of w", standard] |
|
532 |
declare div_pos_neg_1_number_of [simp] |
|
533 |
||
534 |
lemmas mod_pos_pos_1_number_of = |
|
535 |
mod_pos_pos [OF int_0_less_1, of "number_of w", standard] |
|
536 |
declare mod_pos_pos_1_number_of [simp] |
|
13183 | 537 |
|
17085 | 538 |
lemmas mod_pos_neg_1_number_of = |
539 |
mod_pos_neg [OF int_0_less_1, of "number_of w", standard] |
|
540 |
declare mod_pos_neg_1_number_of [simp] |
|
541 |
||
542 |
||
543 |
lemmas posDivAlg_eqn_1_number_of = |
|
544 |
posDivAlg_eqn [of concl: 1 "number_of w", standard] |
|
545 |
declare posDivAlg_eqn_1_number_of [simp] |
|
546 |
||
547 |
lemmas negDivAlg_eqn_1_number_of = |
|
548 |
negDivAlg_eqn [of concl: 1 "number_of w", standard] |
|
549 |
declare negDivAlg_eqn_1_number_of [simp] |
|
550 |
||
13183 | 551 |
|
552 |
||
14271 | 553 |
subsection{*Monotonicity in the First Argument (Dividend)*} |
13183 | 554 |
|
14288 | 555 |
lemma zdiv_mono1: "[| a \<le> a'; 0 < (b::int) |] ==> a div b \<le> a' div b" |
13183 | 556 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
557 |
apply (cut_tac a = a' and b = b in zmod_zdiv_equality) |
|
558 |
apply (rule unique_quotient_lemma) |
|
559 |
apply (erule subst) |
|
15221 | 560 |
apply (erule subst, simp_all) |
13183 | 561 |
done |
562 |
||
14288 | 563 |
lemma zdiv_mono1_neg: "[| a \<le> a'; (b::int) < 0 |] ==> a' div b \<le> a div b" |
13183 | 564 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
565 |
apply (cut_tac a = a' and b = b in zmod_zdiv_equality) |
|
566 |
apply (rule unique_quotient_lemma_neg) |
|
567 |
apply (erule subst) |
|
15221 | 568 |
apply (erule subst, simp_all) |
13183 | 569 |
done |
6917 | 570 |
|
571 |
||
14271 | 572 |
subsection{*Monotonicity in the Second Argument (Divisor)*} |
13183 | 573 |
|
574 |
lemma q_pos_lemma: |
|
14288 | 575 |
"[| 0 \<le> b'*q' + r'; r' < b'; 0 < b' |] ==> 0 \<le> (q'::int)" |
13183 | 576 |
apply (subgoal_tac "0 < b'* (q' + 1) ") |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
577 |
apply (simp add: zero_less_mult_iff) |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
578 |
apply (simp add: right_distrib) |
13183 | 579 |
done |
580 |
||
581 |
lemma zdiv_mono2_lemma: |
|
14288 | 582 |
"[| b*q + r = b'*q' + r'; 0 \<le> b'*q' + r'; |
583 |
r' < b'; 0 \<le> r; 0 < b'; b' \<le> b |] |
|
584 |
==> q \<le> (q'::int)" |
|
13183 | 585 |
apply (frule q_pos_lemma, assumption+) |
586 |
apply (subgoal_tac "b*q < b* (q' + 1) ") |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
587 |
apply (simp add: mult_less_cancel_left) |
13183 | 588 |
apply (subgoal_tac "b*q = r' - r + b'*q'") |
589 |
prefer 2 apply simp |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
590 |
apply (simp (no_asm_simp) add: right_distrib) |
15221 | 591 |
apply (subst add_commute, rule zadd_zless_mono, arith) |
14378
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14353
diff
changeset
|
592 |
apply (rule mult_right_mono, auto) |
13183 | 593 |
done |
594 |
||
595 |
lemma zdiv_mono2: |
|
14288 | 596 |
"[| (0::int) \<le> a; 0 < b'; b' \<le> b |] ==> a div b \<le> a div b'" |
15221 | 597 |
apply (subgoal_tac "b \<noteq> 0") |
13183 | 598 |
prefer 2 apply arith |
599 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
|
600 |
apply (cut_tac a = a and b = b' in zmod_zdiv_equality) |
|
601 |
apply (rule zdiv_mono2_lemma) |
|
602 |
apply (erule subst) |
|
15221 | 603 |
apply (erule subst, simp_all) |
13183 | 604 |
done |
605 |
||
606 |
lemma q_neg_lemma: |
|
14288 | 607 |
"[| b'*q' + r' < 0; 0 \<le> r'; 0 < b' |] ==> q' \<le> (0::int)" |
13183 | 608 |
apply (subgoal_tac "b'*q' < 0") |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
609 |
apply (simp add: mult_less_0_iff, arith) |
13183 | 610 |
done |
611 |
||
612 |
lemma zdiv_mono2_neg_lemma: |
|
613 |
"[| b*q + r = b'*q' + r'; b'*q' + r' < 0; |
|
14288 | 614 |
r < b; 0 \<le> r'; 0 < b'; b' \<le> b |] |
615 |
==> q' \<le> (q::int)" |
|
13183 | 616 |
apply (frule q_neg_lemma, assumption+) |
617 |
apply (subgoal_tac "b*q' < b* (q + 1) ") |
|
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
618 |
apply (simp add: mult_less_cancel_left) |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
619 |
apply (simp add: right_distrib) |
14288 | 620 |
apply (subgoal_tac "b*q' \<le> b'*q'") |
15221 | 621 |
prefer 2 apply (simp add: mult_right_mono_neg, arith) |
13183 | 622 |
done |
623 |
||
624 |
lemma zdiv_mono2_neg: |
|
14288 | 625 |
"[| a < (0::int); 0 < b'; b' \<le> b |] ==> a div b' \<le> a div b" |
13183 | 626 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
627 |
apply (cut_tac a = a and b = b' in zmod_zdiv_equality) |
|
628 |
apply (rule zdiv_mono2_neg_lemma) |
|
629 |
apply (erule subst) |
|
15221 | 630 |
apply (erule subst, simp_all) |
13183 | 631 |
done |
632 |
||
14271 | 633 |
subsection{*More Algebraic Laws for div and mod*} |
13183 | 634 |
|
15221 | 635 |
text{*proving (a*b) div c = a * (b div c) + a * (b mod c) *} |
13183 | 636 |
|
637 |
lemma zmult1_lemma: |
|
15221 | 638 |
"[| quorem((b,c),(q,r)); c \<noteq> 0 |] |
13183 | 639 |
==> quorem ((a*b, c), (a*q + a*r div c, a*r mod c))" |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
640 |
by (force simp add: split_ifs quorem_def linorder_neq_iff right_distrib) |
13183 | 641 |
|
642 |
lemma zdiv_zmult1_eq: "(a*b) div c = a*(b div c) + a*(b mod c) div (c::int)" |
|
15013 | 643 |
apply (case_tac "c = 0", simp) |
13183 | 644 |
apply (blast intro: quorem_div_mod [THEN zmult1_lemma, THEN quorem_div]) |
645 |
done |
|
646 |
||
647 |
lemma zmod_zmult1_eq: "(a*b) mod c = a*(b mod c) mod (c::int)" |
|
15013 | 648 |
apply (case_tac "c = 0", simp) |
13183 | 649 |
apply (blast intro: quorem_div_mod [THEN zmult1_lemma, THEN quorem_mod]) |
650 |
done |
|
651 |
||
652 |
lemma zmod_zmult1_eq': "(a*b) mod (c::int) = ((a mod c) * b) mod c" |
|
653 |
apply (rule trans) |
|
654 |
apply (rule_tac s = "b*a mod c" in trans) |
|
655 |
apply (rule_tac [2] zmod_zmult1_eq) |
|
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
656 |
apply (simp_all add: mult_commute) |
13183 | 657 |
done |
658 |
||
659 |
lemma zmod_zmult_distrib: "(a*b) mod (c::int) = ((a mod c) * (b mod c)) mod c" |
|
660 |
apply (rule zmod_zmult1_eq' [THEN trans]) |
|
661 |
apply (rule zmod_zmult1_eq) |
|
662 |
done |
|
663 |
||
15221 | 664 |
lemma zdiv_zmult_self1 [simp]: "b \<noteq> (0::int) ==> (a*b) div b = a" |
13183 | 665 |
by (simp add: zdiv_zmult1_eq) |
666 |
||
15221 | 667 |
lemma zdiv_zmult_self2 [simp]: "b \<noteq> (0::int) ==> (b*a) div b = a" |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
668 |
by (subst mult_commute, erule zdiv_zmult_self1) |
13183 | 669 |
|
670 |
lemma zmod_zmult_self1 [simp]: "(a*b) mod b = (0::int)" |
|
671 |
by (simp add: zmod_zmult1_eq) |
|
672 |
||
673 |
lemma zmod_zmult_self2 [simp]: "(b*a) mod b = (0::int)" |
|
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
674 |
by (simp add: mult_commute zmod_zmult1_eq) |
13183 | 675 |
|
676 |
lemma zmod_eq_0_iff: "(m mod d = 0) = (EX q::int. m = d*q)" |
|
13517 | 677 |
proof |
678 |
assume "m mod d = 0" |
|
14473 | 679 |
with zmod_zdiv_equality[of m d] show "EX q::int. m = d*q" by auto |
13517 | 680 |
next |
681 |
assume "EX q::int. m = d*q" |
|
682 |
thus "m mod d = 0" by auto |
|
683 |
qed |
|
13183 | 684 |
|
17084
fb0a80aef0be
classical rules must have names for ATP integration
paulson
parents:
16733
diff
changeset
|
685 |
lemmas zmod_eq_0D = zmod_eq_0_iff [THEN iffD1] |
fb0a80aef0be
classical rules must have names for ATP integration
paulson
parents:
16733
diff
changeset
|
686 |
declare zmod_eq_0D [dest!] |
13183 | 687 |
|
15221 | 688 |
text{*proving (a+b) div c = a div c + b div c + ((a mod c + b mod c) div c) *} |
13183 | 689 |
|
690 |
lemma zadd1_lemma: |
|
15221 | 691 |
"[| quorem((a,c),(aq,ar)); quorem((b,c),(bq,br)); c \<noteq> 0 |] |
13183 | 692 |
==> quorem ((a+b, c), (aq + bq + (ar+br) div c, (ar+br) mod c))" |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
693 |
by (force simp add: split_ifs quorem_def linorder_neq_iff right_distrib) |
13183 | 694 |
|
695 |
(*NOT suitable for rewriting: the RHS has an instance of the LHS*) |
|
696 |
lemma zdiv_zadd1_eq: |
|
697 |
"(a+b) div (c::int) = a div c + b div c + ((a mod c + b mod c) div c)" |
|
15013 | 698 |
apply (case_tac "c = 0", simp) |
13183 | 699 |
apply (blast intro: zadd1_lemma [OF quorem_div_mod quorem_div_mod] quorem_div) |
700 |
done |
|
701 |
||
702 |
lemma zmod_zadd1_eq: "(a+b) mod (c::int) = (a mod c + b mod c) mod c" |
|
15013 | 703 |
apply (case_tac "c = 0", simp) |
13183 | 704 |
apply (blast intro: zadd1_lemma [OF quorem_div_mod quorem_div_mod] quorem_mod) |
705 |
done |
|
706 |
||
707 |
lemma mod_div_trivial [simp]: "(a mod b) div b = (0::int)" |
|
15013 | 708 |
apply (case_tac "b = 0", simp) |
13788 | 709 |
apply (auto simp add: linorder_neq_iff div_pos_pos_trivial div_neg_neg_trivial) |
13183 | 710 |
done |
711 |
||
712 |
lemma mod_mod_trivial [simp]: "(a mod b) mod b = a mod (b::int)" |
|
15013 | 713 |
apply (case_tac "b = 0", simp) |
13788 | 714 |
apply (force simp add: linorder_neq_iff mod_pos_pos_trivial mod_neg_neg_trivial) |
13183 | 715 |
done |
716 |
||
717 |
lemma zmod_zadd_left_eq: "(a+b) mod (c::int) = ((a mod c) + b) mod c" |
|
718 |
apply (rule trans [symmetric]) |
|
719 |
apply (rule zmod_zadd1_eq, simp) |
|
720 |
apply (rule zmod_zadd1_eq [symmetric]) |
|
721 |
done |
|
722 |
||
723 |
lemma zmod_zadd_right_eq: "(a+b) mod (c::int) = (a + (b mod c)) mod c" |
|
724 |
apply (rule trans [symmetric]) |
|
725 |
apply (rule zmod_zadd1_eq, simp) |
|
726 |
apply (rule zmod_zadd1_eq [symmetric]) |
|
727 |
done |
|
728 |
||
15221 | 729 |
lemma zdiv_zadd_self1[simp]: "a \<noteq> (0::int) ==> (a+b) div a = b div a + 1" |
13183 | 730 |
by (simp add: zdiv_zadd1_eq) |
731 |
||
15221 | 732 |
lemma zdiv_zadd_self2[simp]: "a \<noteq> (0::int) ==> (b+a) div a = b div a + 1" |
13183 | 733 |
by (simp add: zdiv_zadd1_eq) |
734 |
||
735 |
lemma zmod_zadd_self1[simp]: "(a+b) mod a = b mod (a::int)" |
|
15013 | 736 |
apply (case_tac "a = 0", simp) |
13183 | 737 |
apply (simp add: zmod_zadd1_eq) |
738 |
done |
|
739 |
||
740 |
lemma zmod_zadd_self2[simp]: "(b+a) mod a = b mod (a::int)" |
|
15013 | 741 |
apply (case_tac "a = 0", simp) |
13183 | 742 |
apply (simp add: zmod_zadd1_eq) |
743 |
done |
|
744 |
||
745 |
||
14271 | 746 |
subsection{*Proving @{term "a div (b*c) = (a div b) div c"} *} |
13183 | 747 |
|
748 |
(*The condition c>0 seems necessary. Consider that 7 div ~6 = ~2 but |
|
749 |
7 div 2 div ~3 = 3 div ~3 = ~1. The subcase (a div b) mod c = 0 seems |
|
750 |
to cause particular problems.*) |
|
751 |
||
15221 | 752 |
text{*first, four lemmas to bound the remainder for the cases b<0 and b>0 *} |
13183 | 753 |
|
14288 | 754 |
lemma zmult2_lemma_aux1: "[| (0::int) < c; b < r; r \<le> 0 |] ==> b*c < b*(q mod c) + r" |
13183 | 755 |
apply (subgoal_tac "b * (c - q mod c) < r * 1") |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
756 |
apply (simp add: right_diff_distrib) |
13183 | 757 |
apply (rule order_le_less_trans) |
14378
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14353
diff
changeset
|
758 |
apply (erule_tac [2] mult_strict_right_mono) |
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14353
diff
changeset
|
759 |
apply (rule mult_left_mono_neg) |
15221 | 760 |
apply (auto simp add: compare_rls add_commute [of 1] |
13183 | 761 |
add1_zle_eq pos_mod_bound) |
762 |
done |
|
763 |
||
15221 | 764 |
lemma zmult2_lemma_aux2: |
765 |
"[| (0::int) < c; b < r; r \<le> 0 |] ==> b * (q mod c) + r \<le> 0" |
|
14288 | 766 |
apply (subgoal_tac "b * (q mod c) \<le> 0") |
13183 | 767 |
apply arith |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
768 |
apply (simp add: mult_le_0_iff) |
13183 | 769 |
done |
770 |
||
14288 | 771 |
lemma zmult2_lemma_aux3: "[| (0::int) < c; 0 \<le> r; r < b |] ==> 0 \<le> b * (q mod c) + r" |
772 |
apply (subgoal_tac "0 \<le> b * (q mod c) ") |
|
13183 | 773 |
apply arith |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
774 |
apply (simp add: zero_le_mult_iff) |
13183 | 775 |
done |
776 |
||
14288 | 777 |
lemma zmult2_lemma_aux4: "[| (0::int) < c; 0 \<le> r; r < b |] ==> b * (q mod c) + r < b * c" |
13183 | 778 |
apply (subgoal_tac "r * 1 < b * (c - q mod c) ") |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
779 |
apply (simp add: right_diff_distrib) |
13183 | 780 |
apply (rule order_less_le_trans) |
14378
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14353
diff
changeset
|
781 |
apply (erule mult_strict_right_mono) |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
782 |
apply (rule_tac [2] mult_left_mono) |
15221 | 783 |
apply (auto simp add: compare_rls add_commute [of 1] |
13183 | 784 |
add1_zle_eq pos_mod_bound) |
785 |
done |
|
786 |
||
15221 | 787 |
lemma zmult2_lemma: "[| quorem ((a,b), (q,r)); b \<noteq> 0; 0 < c |] |
13183 | 788 |
==> quorem ((a, b*c), (q div c, b*(q mod c) + r))" |
14271 | 789 |
by (auto simp add: mult_ac quorem_def linorder_neq_iff |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
790 |
zero_less_mult_iff right_distrib [symmetric] |
13524 | 791 |
zmult2_lemma_aux1 zmult2_lemma_aux2 zmult2_lemma_aux3 zmult2_lemma_aux4) |
13183 | 792 |
|
793 |
lemma zdiv_zmult2_eq: "(0::int) < c ==> a div (b*c) = (a div b) div c" |
|
15013 | 794 |
apply (case_tac "b = 0", simp) |
13183 | 795 |
apply (force simp add: quorem_div_mod [THEN zmult2_lemma, THEN quorem_div]) |
796 |
done |
|
797 |
||
798 |
lemma zmod_zmult2_eq: |
|
799 |
"(0::int) < c ==> a mod (b*c) = b*(a div b mod c) + a mod b" |
|
15013 | 800 |
apply (case_tac "b = 0", simp) |
13183 | 801 |
apply (force simp add: quorem_div_mod [THEN zmult2_lemma, THEN quorem_mod]) |
802 |
done |
|
803 |
||
804 |
||
14271 | 805 |
subsection{*Cancellation of Common Factors in div*} |
13183 | 806 |
|
15221 | 807 |
lemma zdiv_zmult_zmult1_aux1: |
808 |
"[| (0::int) < b; c \<noteq> 0 |] ==> (c*a) div (c*b) = a div b" |
|
13183 | 809 |
by (subst zdiv_zmult2_eq, auto) |
810 |
||
15221 | 811 |
lemma zdiv_zmult_zmult1_aux2: |
812 |
"[| b < (0::int); c \<noteq> 0 |] ==> (c*a) div (c*b) = a div b" |
|
13183 | 813 |
apply (subgoal_tac " (c * (-a)) div (c * (-b)) = (-a) div (-b) ") |
13524 | 814 |
apply (rule_tac [2] zdiv_zmult_zmult1_aux1, auto) |
13183 | 815 |
done |
816 |
||
15221 | 817 |
lemma zdiv_zmult_zmult1: "c \<noteq> (0::int) ==> (c*a) div (c*b) = a div b" |
15013 | 818 |
apply (case_tac "b = 0", simp) |
13524 | 819 |
apply (auto simp add: linorder_neq_iff zdiv_zmult_zmult1_aux1 zdiv_zmult_zmult1_aux2) |
13183 | 820 |
done |
821 |
||
15221 | 822 |
lemma zdiv_zmult_zmult2: "c \<noteq> (0::int) ==> (a*c) div (b*c) = a div b" |
13183 | 823 |
apply (drule zdiv_zmult_zmult1) |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
824 |
apply (auto simp add: mult_commute) |
13183 | 825 |
done |
826 |
||
827 |
||
828 |
||
14271 | 829 |
subsection{*Distribution of Factors over mod*} |
13183 | 830 |
|
15221 | 831 |
lemma zmod_zmult_zmult1_aux1: |
832 |
"[| (0::int) < b; c \<noteq> 0 |] ==> (c*a) mod (c*b) = c * (a mod b)" |
|
13183 | 833 |
by (subst zmod_zmult2_eq, auto) |
834 |
||
15221 | 835 |
lemma zmod_zmult_zmult1_aux2: |
836 |
"[| b < (0::int); c \<noteq> 0 |] ==> (c*a) mod (c*b) = c * (a mod b)" |
|
13183 | 837 |
apply (subgoal_tac " (c * (-a)) mod (c * (-b)) = c * ((-a) mod (-b))") |
13524 | 838 |
apply (rule_tac [2] zmod_zmult_zmult1_aux1, auto) |
13183 | 839 |
done |
840 |
||
841 |
lemma zmod_zmult_zmult1: "(c*a) mod (c*b) = (c::int) * (a mod b)" |
|
15013 | 842 |
apply (case_tac "b = 0", simp) |
843 |
apply (case_tac "c = 0", simp) |
|
13524 | 844 |
apply (auto simp add: linorder_neq_iff zmod_zmult_zmult1_aux1 zmod_zmult_zmult1_aux2) |
13183 | 845 |
done |
846 |
||
847 |
lemma zmod_zmult_zmult2: "(a*c) mod (b*c) = (a mod b) * (c::int)" |
|
848 |
apply (cut_tac c = c in zmod_zmult_zmult1) |
|
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
849 |
apply (auto simp add: mult_commute) |
13183 | 850 |
done |
851 |
||
852 |
||
14271 | 853 |
subsection {*Splitting Rules for div and mod*} |
13260 | 854 |
|
855 |
text{*The proofs of the two lemmas below are essentially identical*} |
|
856 |
||
857 |
lemma split_pos_lemma: |
|
858 |
"0<k ==> |
|
14288 | 859 |
P(n div k :: int)(n mod k) = (\<forall>i j. 0\<le>j & j<k & n = k*i + j --> P i j)" |
15221 | 860 |
apply (rule iffI, clarify) |
13260 | 861 |
apply (erule_tac P="P ?x ?y" in rev_mp) |
862 |
apply (subst zmod_zadd1_eq) |
|
863 |
apply (subst zdiv_zadd1_eq) |
|
864 |
apply (simp add: div_pos_pos_trivial mod_pos_pos_trivial) |
|
865 |
txt{*converse direction*} |
|
866 |
apply (drule_tac x = "n div k" in spec) |
|
15221 | 867 |
apply (drule_tac x = "n mod k" in spec, simp) |
13260 | 868 |
done |
869 |
||
870 |
lemma split_neg_lemma: |
|
871 |
"k<0 ==> |
|
14288 | 872 |
P(n div k :: int)(n mod k) = (\<forall>i j. k<j & j\<le>0 & n = k*i + j --> P i j)" |
15221 | 873 |
apply (rule iffI, clarify) |
13260 | 874 |
apply (erule_tac P="P ?x ?y" in rev_mp) |
875 |
apply (subst zmod_zadd1_eq) |
|
876 |
apply (subst zdiv_zadd1_eq) |
|
877 |
apply (simp add: div_neg_neg_trivial mod_neg_neg_trivial) |
|
878 |
txt{*converse direction*} |
|
879 |
apply (drule_tac x = "n div k" in spec) |
|
15221 | 880 |
apply (drule_tac x = "n mod k" in spec, simp) |
13260 | 881 |
done |
882 |
||
883 |
lemma split_zdiv: |
|
884 |
"P(n div k :: int) = |
|
885 |
((k = 0 --> P 0) & |
|
14288 | 886 |
(0<k --> (\<forall>i j. 0\<le>j & j<k & n = k*i + j --> P i)) & |
887 |
(k<0 --> (\<forall>i j. k<j & j\<le>0 & n = k*i + j --> P i)))" |
|
15221 | 888 |
apply (case_tac "k=0", simp) |
13260 | 889 |
apply (simp only: linorder_neq_iff) |
890 |
apply (erule disjE) |
|
891 |
apply (simp_all add: split_pos_lemma [of concl: "%x y. P x"] |
|
892 |
split_neg_lemma [of concl: "%x y. P x"]) |
|
893 |
done |
|
894 |
||
895 |
lemma split_zmod: |
|
896 |
"P(n mod k :: int) = |
|
897 |
((k = 0 --> P n) & |
|
14288 | 898 |
(0<k --> (\<forall>i j. 0\<le>j & j<k & n = k*i + j --> P j)) & |
899 |
(k<0 --> (\<forall>i j. k<j & j\<le>0 & n = k*i + j --> P j)))" |
|
15221 | 900 |
apply (case_tac "k=0", simp) |
13260 | 901 |
apply (simp only: linorder_neq_iff) |
902 |
apply (erule disjE) |
|
903 |
apply (simp_all add: split_pos_lemma [of concl: "%x y. P y"] |
|
904 |
split_neg_lemma [of concl: "%x y. P y"]) |
|
905 |
done |
|
906 |
||
907 |
(* Enable arith to deal with div 2 and mod 2: *) |
|
13266
2a6ad4357d72
modified Larry's changes to make div/mod a numeral work in arith.
nipkow
parents:
13260
diff
changeset
|
908 |
declare split_zdiv [of _ _ "number_of k", simplified, standard, arith_split] |
2a6ad4357d72
modified Larry's changes to make div/mod a numeral work in arith.
nipkow
parents:
13260
diff
changeset
|
909 |
declare split_zmod [of _ _ "number_of k", simplified, standard, arith_split] |
13260 | 910 |
|
911 |
||
14271 | 912 |
subsection{*Speeding up the Division Algorithm with Shifting*} |
13183 | 913 |
|
15221 | 914 |
text{*computing div by shifting *} |
13183 | 915 |
|
14288 | 916 |
lemma pos_zdiv_mult_2: "(0::int) \<le> a ==> (1 + 2*b) div (2*a) = b div a" |
917 |
proof cases |
|
918 |
assume "a=0" |
|
919 |
thus ?thesis by simp |
|
920 |
next |
|
921 |
assume "a\<noteq>0" and le_a: "0\<le>a" |
|
922 |
hence a_pos: "1 \<le> a" by arith |
|
923 |
hence one_less_a2: "1 < 2*a" by arith |
|
924 |
hence le_2a: "2 * (1 + b mod a) \<le> 2 * a" |
|
15221 | 925 |
by (simp add: mult_le_cancel_left add_commute [of 1] add1_zle_eq) |
14288 | 926 |
with a_pos have "0 \<le> b mod a" by simp |
927 |
hence le_addm: "0 \<le> 1 mod (2*a) + 2*(b mod a)" |
|
928 |
by (simp add: mod_pos_pos_trivial one_less_a2) |
|
929 |
with le_2a |
|
930 |
have "(1 mod (2*a) + 2*(b mod a)) div (2*a) = 0" |
|
931 |
by (simp add: div_pos_pos_trivial le_addm mod_pos_pos_trivial one_less_a2 |
|
932 |
right_distrib) |
|
933 |
thus ?thesis |
|
934 |
by (subst zdiv_zadd1_eq, |
|
935 |
simp add: zdiv_zmult_zmult1 zmod_zmult_zmult1 one_less_a2 |
|
936 |
div_pos_pos_trivial) |
|
937 |
qed |
|
13183 | 938 |
|
14288 | 939 |
lemma neg_zdiv_mult_2: "a \<le> (0::int) ==> (1 + 2*b) div (2*a) = (b+1) div a" |
13183 | 940 |
apply (subgoal_tac " (1 + 2* (-b - 1)) div (2 * (-a)) = (-b - 1) div (-a) ") |
941 |
apply (rule_tac [2] pos_zdiv_mult_2) |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
942 |
apply (auto simp add: minus_mult_right [symmetric] right_diff_distrib) |
13183 | 943 |
apply (subgoal_tac " (-1 - (2 * b)) = - (1 + (2 * b))") |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
944 |
apply (simp only: zdiv_zminus_zminus diff_minus minus_add_distrib [symmetric], |
13183 | 945 |
simp) |
946 |
done |
|
947 |
||
948 |
||
949 |
(*Not clear why this must be proved separately; probably number_of causes |
|
950 |
simplification problems*) |
|
14288 | 951 |
lemma not_0_le_lemma: "~ 0 \<le> x ==> x \<le> (0::int)" |
13183 | 952 |
by auto |
953 |
||
954 |
lemma zdiv_number_of_BIT[simp]: |
|
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
955 |
"number_of (v BIT b) div number_of (w BIT bit.B0) = |
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
956 |
(if b=bit.B0 | (0::int) \<le> number_of w |
13183 | 957 |
then number_of v div (number_of w) |
958 |
else (number_of v + (1::int)) div (number_of w))" |
|
15013 | 959 |
apply (simp only: number_of_eq Bin_simps UNIV_I split: split_if) |
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
960 |
apply (simp add: zdiv_zmult_zmult1 pos_zdiv_mult_2 neg_zdiv_mult_2 add_ac |
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
961 |
split: bit.split) |
13183 | 962 |
done |
963 |
||
964 |
||
15013 | 965 |
subsection{*Computing mod by Shifting (proofs resemble those for div)*} |
13183 | 966 |
|
967 |
lemma pos_zmod_mult_2: |
|
14288 | 968 |
"(0::int) \<le> a ==> (1 + 2*b) mod (2*a) = 1 + 2 * (b mod a)" |
15013 | 969 |
apply (case_tac "a = 0", simp) |
13183 | 970 |
apply (subgoal_tac "1 < a * 2") |
971 |
prefer 2 apply arith |
|
14288 | 972 |
apply (subgoal_tac "2* (1 + b mod a) \<le> 2*a") |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
973 |
apply (rule_tac [2] mult_left_mono) |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
974 |
apply (auto simp add: add_commute [of 1] mult_commute add1_zle_eq |
13183 | 975 |
pos_mod_bound) |
976 |
apply (subst zmod_zadd1_eq) |
|
977 |
apply (simp add: zmod_zmult_zmult2 mod_pos_pos_trivial) |
|
978 |
apply (rule mod_pos_pos_trivial) |
|
14288 | 979 |
apply (auto simp add: mod_pos_pos_trivial left_distrib) |
15221 | 980 |
apply (subgoal_tac "0 \<le> b mod a", arith, simp) |
13183 | 981 |
done |
982 |
||
983 |
lemma neg_zmod_mult_2: |
|
14288 | 984 |
"a \<le> (0::int) ==> (1 + 2*b) mod (2*a) = 2 * ((b+1) mod a) - 1" |
13183 | 985 |
apply (subgoal_tac "(1 + 2* (-b - 1)) mod (2* (-a)) = |
986 |
1 + 2* ((-b - 1) mod (-a))") |
|
987 |
apply (rule_tac [2] pos_zmod_mult_2) |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
988 |
apply (auto simp add: minus_mult_right [symmetric] right_diff_distrib) |
13183 | 989 |
apply (subgoal_tac " (-1 - (2 * b)) = - (1 + (2 * b))") |
990 |
prefer 2 apply simp |
|
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
991 |
apply (simp only: zmod_zminus_zminus diff_minus minus_add_distrib [symmetric]) |
13183 | 992 |
done |
993 |
||
994 |
lemma zmod_number_of_BIT [simp]: |
|
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
995 |
"number_of (v BIT b) mod number_of (w BIT bit.B0) = |
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
996 |
(case b of |
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
997 |
bit.B0 => 2 * (number_of v mod number_of w) |
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
998 |
| bit.B1 => if (0::int) \<le> number_of w |
13183 | 999 |
then 2 * (number_of v mod number_of w) + 1 |
15620
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
1000 |
else 2 * ((number_of v + (1::int)) mod number_of w) - 1)" |
8ccdc8bc66a2
replaced bool by a new datatype "bit" for binary numerals
paulson
parents:
15320
diff
changeset
|
1001 |
apply (simp only: number_of_eq Bin_simps UNIV_I split: bit.split) |
15013 | 1002 |
apply (simp add: zmod_zmult_zmult1 pos_zmod_mult_2 |
1003 |
not_0_le_lemma neg_zmod_mult_2 add_ac) |
|
13183 | 1004 |
done |
1005 |
||
1006 |
||
15013 | 1007 |
subsection{*Quotients of Signs*} |
13183 | 1008 |
|
1009 |
lemma div_neg_pos_less0: "[| a < (0::int); 0 < b |] ==> a div b < 0" |
|
14288 | 1010 |
apply (subgoal_tac "a div b \<le> -1", force) |
13183 | 1011 |
apply (rule order_trans) |
1012 |
apply (rule_tac a' = "-1" in zdiv_mono1) |
|
1013 |
apply (auto simp add: zdiv_minus1) |
|
1014 |
done |
|
1015 |
||
14288 | 1016 |
lemma div_nonneg_neg_le0: "[| (0::int) \<le> a; b < 0 |] ==> a div b \<le> 0" |
13183 | 1017 |
by (drule zdiv_mono1_neg, auto) |
1018 |
||
14288 | 1019 |
lemma pos_imp_zdiv_nonneg_iff: "(0::int) < b ==> (0 \<le> a div b) = (0 \<le> a)" |
13183 | 1020 |
apply auto |
1021 |
apply (drule_tac [2] zdiv_mono1) |
|
1022 |
apply (auto simp add: linorder_neq_iff) |
|
1023 |
apply (simp (no_asm_use) add: linorder_not_less [symmetric]) |
|
1024 |
apply (blast intro: div_neg_pos_less0) |
|
1025 |
done |
|
1026 |
||
1027 |
lemma neg_imp_zdiv_nonneg_iff: |
|
14288 | 1028 |
"b < (0::int) ==> (0 \<le> a div b) = (a \<le> (0::int))" |
13183 | 1029 |
apply (subst zdiv_zminus_zminus [symmetric]) |
1030 |
apply (subst pos_imp_zdiv_nonneg_iff, auto) |
|
1031 |
done |
|
1032 |
||
14288 | 1033 |
(*But not (a div b \<le> 0 iff a\<le>0); consider a=1, b=2 when a div b = 0.*) |
13183 | 1034 |
lemma pos_imp_zdiv_neg_iff: "(0::int) < b ==> (a div b < 0) = (a < 0)" |
1035 |
by (simp add: linorder_not_le [symmetric] pos_imp_zdiv_nonneg_iff) |
|
1036 |
||
14288 | 1037 |
(*Again the law fails for \<le>: consider a = -1, b = -2 when a div b = 0*) |
13183 | 1038 |
lemma neg_imp_zdiv_neg_iff: "b < (0::int) ==> (a div b < 0) = (0 < a)" |
1039 |
by (simp add: linorder_not_le [symmetric] neg_imp_zdiv_nonneg_iff) |
|
1040 |
||
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1041 |
|
14271 | 1042 |
subsection {* The Divides Relation *} |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1043 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1044 |
lemma zdvd_iff_zmod_eq_0: "(m dvd n) = (n mod m = (0::int))" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1045 |
by(simp add:dvd_def zmod_eq_0_iff) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1046 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1047 |
lemma zdvd_0_right [iff]: "(m::int) dvd 0" |
15221 | 1048 |
by (simp add: dvd_def) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1049 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1050 |
lemma zdvd_0_left [iff]: "(0 dvd (m::int)) = (m = 0)" |
15221 | 1051 |
by (simp add: dvd_def) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1052 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1053 |
lemma zdvd_1_left [iff]: "1 dvd (m::int)" |
15221 | 1054 |
by (simp add: dvd_def) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1055 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1056 |
lemma zdvd_refl [simp]: "m dvd (m::int)" |
15221 | 1057 |
by (auto simp add: dvd_def intro: zmult_1_right [symmetric]) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1058 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1059 |
lemma zdvd_trans: "m dvd n ==> n dvd k ==> m dvd (k::int)" |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
1060 |
by (auto simp add: dvd_def intro: mult_assoc) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1061 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1062 |
lemma zdvd_zminus_iff: "(m dvd -n) = (m dvd (n::int))" |
15221 | 1063 |
apply (simp add: dvd_def, auto) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1064 |
apply (rule_tac [!] x = "-k" in exI, auto) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1065 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1066 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1067 |
lemma zdvd_zminus2_iff: "(-m dvd n) = (m dvd (n::int))" |
15221 | 1068 |
apply (simp add: dvd_def, auto) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1069 |
apply (rule_tac [!] x = "-k" in exI, auto) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1070 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1071 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1072 |
lemma zdvd_anti_sym: |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1073 |
"0 < m ==> 0 < n ==> m dvd n ==> n dvd m ==> m = (n::int)" |
15221 | 1074 |
apply (simp add: dvd_def, auto) |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
1075 |
apply (simp add: mult_assoc zero_less_mult_iff zmult_eq_1_iff) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1076 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1077 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1078 |
lemma zdvd_zadd: "k dvd m ==> k dvd n ==> k dvd (m + n :: int)" |
15221 | 1079 |
apply (simp add: dvd_def) |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
1080 |
apply (blast intro: right_distrib [symmetric]) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1081 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1082 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1083 |
lemma zdvd_zdiff: "k dvd m ==> k dvd n ==> k dvd (m - n :: int)" |
15221 | 1084 |
apply (simp add: dvd_def) |
14479
0eca4aabf371
streamlined treatment of quotients for the integers
paulson
parents:
14473
diff
changeset
|
1085 |
apply (blast intro: right_diff_distrib [symmetric]) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1086 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1087 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1088 |
lemma zdvd_zdiffD: "k dvd m - n ==> k dvd n ==> k dvd (m::int)" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1089 |
apply (subgoal_tac "m = n + (m - n)") |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1090 |
apply (erule ssubst) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1091 |
apply (blast intro: zdvd_zadd, simp) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1092 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1093 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1094 |
lemma zdvd_zmult: "k dvd (n::int) ==> k dvd m * n" |
15221 | 1095 |
apply (simp add: dvd_def) |
14271 | 1096 |
apply (blast intro: mult_left_commute) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1097 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1098 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1099 |
lemma zdvd_zmult2: "k dvd (m::int) ==> k dvd m * n" |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
1100 |
apply (subst mult_commute) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1101 |
apply (erule zdvd_zmult) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1102 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1103 |
|
17084
fb0a80aef0be
classical rules must have names for ATP integration
paulson
parents:
16733
diff
changeset
|
1104 |
lemma zdvd_triv_right [iff]: "(k::int) dvd m * k" |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1105 |
apply (rule zdvd_zmult) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1106 |
apply (rule zdvd_refl) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1107 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1108 |
|
17084
fb0a80aef0be
classical rules must have names for ATP integration
paulson
parents:
16733
diff
changeset
|
1109 |
lemma zdvd_triv_left [iff]: "(k::int) dvd k * m" |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1110 |
apply (rule zdvd_zmult2) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1111 |
apply (rule zdvd_refl) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1112 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1113 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1114 |
lemma zdvd_zmultD2: "j * k dvd n ==> j dvd (n::int)" |
15221 | 1115 |
apply (simp add: dvd_def) |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
1116 |
apply (simp add: mult_assoc, blast) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1117 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1118 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1119 |
lemma zdvd_zmultD: "j * k dvd n ==> k dvd (n::int)" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1120 |
apply (rule zdvd_zmultD2) |
15234
ec91a90c604e
simplification tweaks for better arithmetic reasoning
paulson
parents:
15221
diff
changeset
|
1121 |
apply (subst mult_commute, assumption) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1122 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1123 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1124 |
lemma zdvd_zmult_mono: "i dvd m ==> j dvd (n::int) ==> i * j dvd m * n" |
15221 | 1125 |
apply (simp add: dvd_def, clarify) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1126 |
apply (rule_tac x = "k * ka" in exI) |
14271 | 1127 |
apply (simp add: mult_ac) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1128 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1129 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1130 |
lemma zdvd_reduce: "(k dvd n + k * m) = (k dvd (n::int))" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1131 |
apply (rule iffI) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1132 |
apply (erule_tac [2] zdvd_zadd) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1133 |
apply (subgoal_tac "n = (n + k * m) - k * m") |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1134 |
apply (erule ssubst) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1135 |
apply (erule zdvd_zdiff, simp_all) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1136 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1137 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1138 |
lemma zdvd_zmod: "f dvd m ==> f dvd (n::int) ==> f dvd m mod n" |
15221 | 1139 |
apply (simp add: dvd_def) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1140 |
apply (auto simp add: zmod_zmult_zmult1) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1141 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1142 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1143 |
lemma zdvd_zmod_imp_zdvd: "k dvd m mod n ==> k dvd n ==> k dvd (m::int)" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1144 |
apply (subgoal_tac "k dvd n * (m div n) + m mod n") |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1145 |
apply (simp add: zmod_zdiv_equality [symmetric]) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1146 |
apply (simp only: zdvd_zadd zdvd_zmult2) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1147 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1148 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1149 |
lemma zdvd_not_zless: "0 < m ==> m < n ==> \<not> n dvd (m::int)" |
15221 | 1150 |
apply (simp add: dvd_def, auto) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1151 |
apply (subgoal_tac "0 < n") |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1152 |
prefer 2 |
14378
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14353
diff
changeset
|
1153 |
apply (blast intro: order_less_trans) |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1154 |
apply (simp add: zero_less_mult_iff) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1155 |
apply (subgoal_tac "n * k < n * 1") |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14378
diff
changeset
|
1156 |
apply (drule mult_less_cancel_left [THEN iffD1], auto) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1157 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1158 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1159 |
lemma int_dvd_iff: "(int m dvd z) = (m dvd nat (abs z))" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1160 |
apply (auto simp add: dvd_def nat_abs_mult_distrib) |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1161 |
apply (auto simp add: nat_eq_iff abs_if split add: split_if_asm) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1162 |
apply (rule_tac x = "-(int k)" in exI) |
16413 | 1163 |
apply (auto simp add: int_mult) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1164 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1165 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1166 |
lemma dvd_int_iff: "(z dvd int m) = (nat (abs z) dvd m)" |
16413 | 1167 |
apply (auto simp add: dvd_def abs_if int_mult) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1168 |
apply (rule_tac [3] x = "nat k" in exI) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1169 |
apply (rule_tac [2] x = "-(int k)" in exI) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1170 |
apply (rule_tac x = "nat (-k)" in exI) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1171 |
apply (cut_tac [3] k = m in int_less_0_conv) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1172 |
apply (cut_tac k = m in int_less_0_conv) |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1173 |
apply (auto simp add: zero_le_mult_iff mult_less_0_iff |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1174 |
nat_mult_distrib [symmetric] nat_eq_iff2) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1175 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1176 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1177 |
lemma nat_dvd_iff: "(nat z dvd m) = (if 0 \<le> z then (z dvd int m) else m = 0)" |
16413 | 1178 |
apply (auto simp add: dvd_def int_mult) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1179 |
apply (rule_tac x = "nat k" in exI) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1180 |
apply (cut_tac k = m in int_less_0_conv) |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1181 |
apply (auto simp add: zero_le_mult_iff mult_less_0_iff |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1182 |
nat_mult_distrib [symmetric] nat_eq_iff2) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1183 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1184 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1185 |
lemma zminus_dvd_iff [iff]: "(-z dvd w) = (z dvd (w::int))" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1186 |
apply (auto simp add: dvd_def) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1187 |
apply (rule_tac [!] x = "-k" in exI, auto) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1188 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1189 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1190 |
lemma dvd_zminus_iff [iff]: "(z dvd -w) = (z dvd (w::int))" |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1191 |
apply (auto simp add: dvd_def) |
14378
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14353
diff
changeset
|
1192 |
apply (drule minus_equation_iff [THEN iffD1]) |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1193 |
apply (rule_tac [!] x = "-k" in exI, auto) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1194 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1195 |
|
14288 | 1196 |
lemma zdvd_imp_le: "[| z dvd n; 0 < n |] ==> z \<le> (n::int)" |
13837
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1197 |
apply (rule_tac z=n in int_cases) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1198 |
apply (auto simp add: dvd_int_iff) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1199 |
apply (rule_tac z=z in int_cases) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1200 |
apply (auto simp add: dvd_imp_le) |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1201 |
done |
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1202 |
|
8dd150d36c65
Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents:
13788
diff
changeset
|
1203 |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1204 |
subsection{*Integer Powers*} |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1205 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1206 |
instance int :: power .. |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1207 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1208 |
primrec |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1209 |
"p ^ 0 = 1" |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1210 |
"p ^ (Suc n) = (p::int) * (p ^ n)" |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1211 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1212 |
|
15003 | 1213 |
instance int :: recpower |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1214 |
proof |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1215 |
fix z :: int |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1216 |
fix n :: nat |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1217 |
show "z^0 = 1" by simp |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1218 |
show "z^(Suc n) = z * (z^n)" by simp |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1219 |
qed |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1220 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1221 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1222 |
lemma zpower_zmod: "((x::int) mod m)^y mod m = x^y mod m" |
15251 | 1223 |
apply (induct "y", auto) |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1224 |
apply (rule zmod_zmult1_eq [THEN trans]) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1225 |
apply (simp (no_asm_simp)) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1226 |
apply (rule zmod_zmult_distrib [symmetric]) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1227 |
done |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1228 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1229 |
lemma zpower_zadd_distrib: "x^(y+z) = ((x^y)*(x^z)::int)" |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1230 |
by (rule Power.power_add) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1231 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1232 |
lemma zpower_zpower: "(x^y)^z = (x^(y*z)::int)" |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1233 |
by (rule Power.power_mult [symmetric]) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1234 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1235 |
lemma zero_less_zpower_abs_iff [simp]: |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1236 |
"(0 < (abs x)^n) = (x \<noteq> (0::int) | n=0)" |
15251 | 1237 |
apply (induct "n") |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1238 |
apply (auto simp add: zero_less_mult_iff) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1239 |
done |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1240 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1241 |
lemma zero_le_zpower_abs [simp]: "(0::int) <= (abs x)^n" |
15251 | 1242 |
apply (induct "n") |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1243 |
apply (auto simp add: zero_le_mult_iff) |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1244 |
done |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1245 |
|
16413 | 1246 |
lemma int_power: "int (m^n) = (int m) ^ n" |
1247 |
by (induct n, simp_all add: int_mult) |
|
1248 |
||
1249 |
text{*Compatibility binding*} |
|
1250 |
lemmas zpower_int = int_power [symmetric] |
|
15320 | 1251 |
|
15101 | 1252 |
lemma zdiv_int: "int (a div b) = (int a) div (int b)" |
1253 |
apply (subst split_div, auto) |
|
1254 |
apply (subst split_zdiv, auto) |
|
1255 |
apply (rule_tac a="int (b * i) + int j" and b="int b" and r="int j" and r'=ja in IntDiv.unique_quotient) |
|
1256 |
apply (auto simp add: IntDiv.quorem_def int_eq_of_nat) |
|
1257 |
done |
|
1258 |
||
1259 |
lemma zmod_int: "int (a mod b) = (int a) mod (int b)" |
|
1260 |
apply (subst split_mod, auto) |
|
1261 |
apply (subst split_zmod, auto) |
|
16413 | 1262 |
apply (rule_tac a="int (b * i) + int j" and b="int b" and q="int i" and q'=ia |
1263 |
in unique_remainder) |
|
15101 | 1264 |
apply (auto simp add: IntDiv.quorem_def int_eq_of_nat) |
1265 |
done |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1266 |
|
16413 | 1267 |
text{*Suggested by Matthias Daum*} |
1268 |
lemma int_power_div_base: |
|
1269 |
"\<lbrakk>0 < m; 0 < k\<rbrakk> \<Longrightarrow> k ^ m div k = (k::int) ^ (m - Suc 0)" |
|
1270 |
apply (subgoal_tac "k ^ m = k ^ ((m - 1) + 1)") |
|
1271 |
apply (erule ssubst) |
|
1272 |
apply (simp only: power_add) |
|
1273 |
apply simp_all |
|
1274 |
done |
|
1275 |
||
13183 | 1276 |
ML |
1277 |
{* |
|
1278 |
val quorem_def = thm "quorem_def"; |
|
1279 |
||
1280 |
val unique_quotient = thm "unique_quotient"; |
|
1281 |
val unique_remainder = thm "unique_remainder"; |
|
1282 |
val adjust_eq = thm "adjust_eq"; |
|
1283 |
val posDivAlg_eqn = thm "posDivAlg_eqn"; |
|
1284 |
val posDivAlg_correct = thm "posDivAlg_correct"; |
|
1285 |
val negDivAlg_eqn = thm "negDivAlg_eqn"; |
|
1286 |
val negDivAlg_correct = thm "negDivAlg_correct"; |
|
1287 |
val quorem_0 = thm "quorem_0"; |
|
1288 |
val posDivAlg_0 = thm "posDivAlg_0"; |
|
1289 |
val negDivAlg_minus1 = thm "negDivAlg_minus1"; |
|
1290 |
val negateSnd_eq = thm "negateSnd_eq"; |
|
1291 |
val quorem_neg = thm "quorem_neg"; |
|
1292 |
val divAlg_correct = thm "divAlg_correct"; |
|
1293 |
val DIVISION_BY_ZERO = thm "DIVISION_BY_ZERO"; |
|
1294 |
val zmod_zdiv_equality = thm "zmod_zdiv_equality"; |
|
1295 |
val pos_mod_conj = thm "pos_mod_conj"; |
|
1296 |
val pos_mod_sign = thm "pos_mod_sign"; |
|
1297 |
val neg_mod_conj = thm "neg_mod_conj"; |
|
1298 |
val neg_mod_sign = thm "neg_mod_sign"; |
|
1299 |
val quorem_div_mod = thm "quorem_div_mod"; |
|
1300 |
val quorem_div = thm "quorem_div"; |
|
1301 |
val quorem_mod = thm "quorem_mod"; |
|
1302 |
val div_pos_pos_trivial = thm "div_pos_pos_trivial"; |
|
1303 |
val div_neg_neg_trivial = thm "div_neg_neg_trivial"; |
|
1304 |
val div_pos_neg_trivial = thm "div_pos_neg_trivial"; |
|
1305 |
val mod_pos_pos_trivial = thm "mod_pos_pos_trivial"; |
|
1306 |
val mod_neg_neg_trivial = thm "mod_neg_neg_trivial"; |
|
1307 |
val mod_pos_neg_trivial = thm "mod_pos_neg_trivial"; |
|
1308 |
val zdiv_zminus_zminus = thm "zdiv_zminus_zminus"; |
|
1309 |
val zmod_zminus_zminus = thm "zmod_zminus_zminus"; |
|
1310 |
val zdiv_zminus1_eq_if = thm "zdiv_zminus1_eq_if"; |
|
1311 |
val zmod_zminus1_eq_if = thm "zmod_zminus1_eq_if"; |
|
1312 |
val zdiv_zminus2 = thm "zdiv_zminus2"; |
|
1313 |
val zmod_zminus2 = thm "zmod_zminus2"; |
|
1314 |
val zdiv_zminus2_eq_if = thm "zdiv_zminus2_eq_if"; |
|
1315 |
val zmod_zminus2_eq_if = thm "zmod_zminus2_eq_if"; |
|
1316 |
val self_quotient = thm "self_quotient"; |
|
1317 |
val self_remainder = thm "self_remainder"; |
|
1318 |
val zdiv_self = thm "zdiv_self"; |
|
1319 |
val zmod_self = thm "zmod_self"; |
|
1320 |
val zdiv_zero = thm "zdiv_zero"; |
|
1321 |
val div_eq_minus1 = thm "div_eq_minus1"; |
|
1322 |
val zmod_zero = thm "zmod_zero"; |
|
1323 |
val zdiv_minus1 = thm "zdiv_minus1"; |
|
1324 |
val zmod_minus1 = thm "zmod_minus1"; |
|
1325 |
val div_pos_pos = thm "div_pos_pos"; |
|
1326 |
val mod_pos_pos = thm "mod_pos_pos"; |
|
1327 |
val div_neg_pos = thm "div_neg_pos"; |
|
1328 |
val mod_neg_pos = thm "mod_neg_pos"; |
|
1329 |
val div_pos_neg = thm "div_pos_neg"; |
|
1330 |
val mod_pos_neg = thm "mod_pos_neg"; |
|
1331 |
val div_neg_neg = thm "div_neg_neg"; |
|
1332 |
val mod_neg_neg = thm "mod_neg_neg"; |
|
1333 |
val zmod_1 = thm "zmod_1"; |
|
1334 |
val zdiv_1 = thm "zdiv_1"; |
|
1335 |
val zmod_minus1_right = thm "zmod_minus1_right"; |
|
1336 |
val zdiv_minus1_right = thm "zdiv_minus1_right"; |
|
1337 |
val zdiv_mono1 = thm "zdiv_mono1"; |
|
1338 |
val zdiv_mono1_neg = thm "zdiv_mono1_neg"; |
|
1339 |
val zdiv_mono2 = thm "zdiv_mono2"; |
|
1340 |
val zdiv_mono2_neg = thm "zdiv_mono2_neg"; |
|
1341 |
val zdiv_zmult1_eq = thm "zdiv_zmult1_eq"; |
|
1342 |
val zmod_zmult1_eq = thm "zmod_zmult1_eq"; |
|
1343 |
val zmod_zmult1_eq' = thm "zmod_zmult1_eq'"; |
|
1344 |
val zmod_zmult_distrib = thm "zmod_zmult_distrib"; |
|
1345 |
val zdiv_zmult_self1 = thm "zdiv_zmult_self1"; |
|
1346 |
val zdiv_zmult_self2 = thm "zdiv_zmult_self2"; |
|
1347 |
val zmod_zmult_self1 = thm "zmod_zmult_self1"; |
|
1348 |
val zmod_zmult_self2 = thm "zmod_zmult_self2"; |
|
1349 |
val zmod_eq_0_iff = thm "zmod_eq_0_iff"; |
|
1350 |
val zdiv_zadd1_eq = thm "zdiv_zadd1_eq"; |
|
1351 |
val zmod_zadd1_eq = thm "zmod_zadd1_eq"; |
|
1352 |
val mod_div_trivial = thm "mod_div_trivial"; |
|
1353 |
val mod_mod_trivial = thm "mod_mod_trivial"; |
|
1354 |
val zmod_zadd_left_eq = thm "zmod_zadd_left_eq"; |
|
1355 |
val zmod_zadd_right_eq = thm "zmod_zadd_right_eq"; |
|
1356 |
val zdiv_zadd_self1 = thm "zdiv_zadd_self1"; |
|
1357 |
val zdiv_zadd_self2 = thm "zdiv_zadd_self2"; |
|
1358 |
val zmod_zadd_self1 = thm "zmod_zadd_self1"; |
|
1359 |
val zmod_zadd_self2 = thm "zmod_zadd_self2"; |
|
1360 |
val zdiv_zmult2_eq = thm "zdiv_zmult2_eq"; |
|
1361 |
val zmod_zmult2_eq = thm "zmod_zmult2_eq"; |
|
1362 |
val zdiv_zmult_zmult1 = thm "zdiv_zmult_zmult1"; |
|
1363 |
val zdiv_zmult_zmult2 = thm "zdiv_zmult_zmult2"; |
|
1364 |
val zmod_zmult_zmult1 = thm "zmod_zmult_zmult1"; |
|
1365 |
val zmod_zmult_zmult2 = thm "zmod_zmult_zmult2"; |
|
1366 |
val pos_zdiv_mult_2 = thm "pos_zdiv_mult_2"; |
|
1367 |
val neg_zdiv_mult_2 = thm "neg_zdiv_mult_2"; |
|
1368 |
val zdiv_number_of_BIT = thm "zdiv_number_of_BIT"; |
|
1369 |
val pos_zmod_mult_2 = thm "pos_zmod_mult_2"; |
|
1370 |
val neg_zmod_mult_2 = thm "neg_zmod_mult_2"; |
|
1371 |
val zmod_number_of_BIT = thm "zmod_number_of_BIT"; |
|
1372 |
val div_neg_pos_less0 = thm "div_neg_pos_less0"; |
|
1373 |
val div_nonneg_neg_le0 = thm "div_nonneg_neg_le0"; |
|
1374 |
val pos_imp_zdiv_nonneg_iff = thm "pos_imp_zdiv_nonneg_iff"; |
|
1375 |
val neg_imp_zdiv_nonneg_iff = thm "neg_imp_zdiv_nonneg_iff"; |
|
1376 |
val pos_imp_zdiv_neg_iff = thm "pos_imp_zdiv_neg_iff"; |
|
1377 |
val neg_imp_zdiv_neg_iff = thm "neg_imp_zdiv_neg_iff"; |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1378 |
|
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1379 |
val zpower_zmod = thm "zpower_zmod"; |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1380 |
val zpower_zadd_distrib = thm "zpower_zadd_distrib"; |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1381 |
val zpower_zpower = thm "zpower_zpower"; |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1382 |
val zero_less_zpower_abs_iff = thm "zero_less_zpower_abs_iff"; |
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14288
diff
changeset
|
1383 |
val zero_le_zpower_abs = thm "zero_le_zpower_abs"; |
15320 | 1384 |
val zpower_int = thm "zpower_int"; |
13183 | 1385 |
*} |
1386 |
||
6917 | 1387 |
end |