author | bulwahn |
Sat, 31 Oct 2009 10:02:37 +0100 | |
changeset 33376 | 5cb663aa48ee |
parent 33340 | a165b97f3658 |
permissions | -rw-r--r-- |
23164 | 1 |
(* Title: HOL/IntDiv.thy |
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
3 |
Copyright 1999 University of Cambridge |
|
4 |
*) |
|
5 |
||
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
6 |
header{* The Division Operators div and mod *} |
23164 | 7 |
|
8 |
theory IntDiv |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
9 |
imports Int Divides FunDef |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
10 |
uses |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
11 |
"~~/src/Provers/Arith/assoc_fold.ML" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
12 |
"~~/src/Provers/Arith/cancel_numerals.ML" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
13 |
"~~/src/Provers/Arith/combine_numerals.ML" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
14 |
"~~/src/Provers/Arith/cancel_numeral_factor.ML" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
15 |
"~~/src/Provers/Arith/extract_common_term.ML" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
16 |
("Tools/numeral_simprocs.ML") |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
17 |
("Tools/nat_numeral_simprocs.ML") |
23164 | 18 |
begin |
19 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
20 |
definition divmod_int_rel :: "int \<Rightarrow> int \<Rightarrow> int \<times> int \<Rightarrow> bool" where |
23164 | 21 |
--{*definition of quotient and remainder*} |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
22 |
[code]: "divmod_int_rel a b = (\<lambda>(q, r). a = b * q + r \<and> |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
23 |
(if 0 < b then 0 \<le> r \<and> r < b else b < r \<and> r \<le> 0))" |
23164 | 24 |
|
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
25 |
definition adjust :: "int \<Rightarrow> int \<times> int \<Rightarrow> int \<times> int" where |
23164 | 26 |
--{*for the division algorithm*} |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
27 |
[code]: "adjust b = (\<lambda>(q, r). if 0 \<le> r - b then (2 * q + 1, r - b) |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
28 |
else (2 * q, r))" |
23164 | 29 |
|
30 |
text{*algorithm for the case @{text "a\<ge>0, b>0"}*} |
|
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
31 |
function posDivAlg :: "int \<Rightarrow> int \<Rightarrow> int \<times> int" where |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
32 |
"posDivAlg a b = (if a < b \<or> b \<le> 0 then (0, a) |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
33 |
else adjust b (posDivAlg a (2 * b)))" |
23164 | 34 |
by auto |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
35 |
termination by (relation "measure (\<lambda>(a, b). nat (a - b + 1))") |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
36 |
(auto simp add: mult_2) |
23164 | 37 |
|
38 |
text{*algorithm for the case @{text "a<0, b>0"}*} |
|
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
39 |
function negDivAlg :: "int \<Rightarrow> int \<Rightarrow> int \<times> int" where |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
40 |
"negDivAlg a b = (if 0 \<le>a + b \<or> b \<le> 0 then (-1, a + b) |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
41 |
else adjust b (negDivAlg a (2 * b)))" |
23164 | 42 |
by auto |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
43 |
termination by (relation "measure (\<lambda>(a, b). nat (- a - b))") |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
44 |
(auto simp add: mult_2) |
23164 | 45 |
|
46 |
text{*algorithm for the general case @{term "b\<noteq>0"}*} |
|
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
47 |
definition negateSnd :: "int \<times> int \<Rightarrow> int \<times> int" where |
32069
6d28bbd33e2c
prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents:
31998
diff
changeset
|
48 |
[code_unfold]: "negateSnd = apsnd uminus" |
23164 | 49 |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
50 |
definition divmod_int :: "int \<Rightarrow> int \<Rightarrow> int \<times> int" where |
23164 | 51 |
--{*The full division algorithm considers all possible signs for a, b |
52 |
including the special case @{text "a=0, b<0"} because |
|
53 |
@{term negDivAlg} requires @{term "a<0"}.*} |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
54 |
"divmod_int a b = (if 0 \<le> a then if 0 \<le> b then posDivAlg a b |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
55 |
else if a = 0 then (0, 0) |
23164 | 56 |
else negateSnd (negDivAlg (-a) (-b)) |
57 |
else |
|
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
58 |
if 0 < b then negDivAlg a b |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
59 |
else negateSnd (posDivAlg (-a) (-b)))" |
23164 | 60 |
|
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
61 |
instantiation int :: Divides.div |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
62 |
begin |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
63 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
64 |
definition |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
65 |
"a div b = fst (divmod_int a b)" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
66 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
67 |
definition |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
68 |
"a mod b = snd (divmod_int a b)" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
69 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
70 |
instance .. |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
71 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25134
diff
changeset
|
72 |
end |
23164 | 73 |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
74 |
lemma divmod_int_mod_div: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
75 |
"divmod_int p q = (p div q, p mod q)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
76 |
by (auto simp add: div_int_def mod_int_def) |
23164 | 77 |
|
78 |
text{* |
|
79 |
Here is the division algorithm in ML: |
|
80 |
||
81 |
\begin{verbatim} |
|
82 |
fun posDivAlg (a,b) = |
|
83 |
if a<b then (0,a) |
|
84 |
else let val (q,r) = posDivAlg(a, 2*b) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
85 |
in if 0\<le>r-b then (2*q+1, r-b) else (2*q, r) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
86 |
end |
23164 | 87 |
|
88 |
fun negDivAlg (a,b) = |
|
89 |
if 0\<le>a+b then (~1,a+b) |
|
90 |
else let val (q,r) = negDivAlg(a, 2*b) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
91 |
in if 0\<le>r-b then (2*q+1, r-b) else (2*q, r) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
92 |
end; |
23164 | 93 |
|
94 |
fun negateSnd (q,r:int) = (q,~r); |
|
95 |
||
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
96 |
fun divmod (a,b) = if 0\<le>a then |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
97 |
if b>0 then posDivAlg (a,b) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
98 |
else if a=0 then (0,0) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
99 |
else negateSnd (negDivAlg (~a,~b)) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
100 |
else |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
101 |
if 0<b then negDivAlg (a,b) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
102 |
else negateSnd (posDivAlg (~a,~b)); |
23164 | 103 |
\end{verbatim} |
104 |
*} |
|
105 |
||
106 |
||
107 |
||
108 |
subsection{*Uniqueness and Monotonicity of Quotients and Remainders*} |
|
109 |
||
110 |
lemma unique_quotient_lemma: |
|
111 |
"[| b*q' + r' \<le> b*q + r; 0 \<le> r'; r' < b; r < b |] |
|
112 |
==> q' \<le> (q::int)" |
|
113 |
apply (subgoal_tac "r' + b * (q'-q) \<le> r") |
|
114 |
prefer 2 apply (simp add: right_diff_distrib) |
|
115 |
apply (subgoal_tac "0 < b * (1 + q - q') ") |
|
116 |
apply (erule_tac [2] order_le_less_trans) |
|
117 |
prefer 2 apply (simp add: right_diff_distrib right_distrib) |
|
118 |
apply (subgoal_tac "b * q' < b * (1 + q) ") |
|
119 |
prefer 2 apply (simp add: right_diff_distrib right_distrib) |
|
120 |
apply (simp add: mult_less_cancel_left) |
|
121 |
done |
|
122 |
||
123 |
lemma unique_quotient_lemma_neg: |
|
124 |
"[| b*q' + r' \<le> b*q + r; r \<le> 0; b < r; b < r' |] |
|
125 |
==> q \<le> (q'::int)" |
|
126 |
by (rule_tac b = "-b" and r = "-r'" and r' = "-r" in unique_quotient_lemma, |
|
127 |
auto) |
|
128 |
||
129 |
lemma unique_quotient: |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
130 |
"[| divmod_int_rel a b (q, r); divmod_int_rel a b (q', r'); b \<noteq> 0 |] |
23164 | 131 |
==> q = q'" |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
132 |
apply (simp add: divmod_int_rel_def linorder_neq_iff split: split_if_asm) |
23164 | 133 |
apply (blast intro: order_antisym |
134 |
dest: order_eq_refl [THEN unique_quotient_lemma] |
|
135 |
order_eq_refl [THEN unique_quotient_lemma_neg] sym)+ |
|
136 |
done |
|
137 |
||
138 |
||
139 |
lemma unique_remainder: |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
140 |
"[| divmod_int_rel a b (q, r); divmod_int_rel a b (q', r'); b \<noteq> 0 |] |
23164 | 141 |
==> r = r'" |
142 |
apply (subgoal_tac "q = q'") |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
143 |
apply (simp add: divmod_int_rel_def) |
23164 | 144 |
apply (blast intro: unique_quotient) |
145 |
done |
|
146 |
||
147 |
||
148 |
subsection{*Correctness of @{term posDivAlg}, the Algorithm for Non-Negative Dividends*} |
|
149 |
||
150 |
text{*And positive divisors*} |
|
151 |
||
152 |
lemma adjust_eq [simp]: |
|
153 |
"adjust b (q,r) = |
|
154 |
(let diff = r-b in |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32553
diff
changeset
|
155 |
if 0 \<le> diff then (2*q + 1, diff) |
23164 | 156 |
else (2*q, r))" |
157 |
by (simp add: Let_def adjust_def) |
|
158 |
||
159 |
declare posDivAlg.simps [simp del] |
|
160 |
||
161 |
text{*use with a simproc to avoid repeatedly proving the premise*} |
|
162 |
lemma posDivAlg_eqn: |
|
163 |
"0 < b ==> |
|
164 |
posDivAlg a b = (if a<b then (0,a) else adjust b (posDivAlg a (2*b)))" |
|
165 |
by (rule posDivAlg.simps [THEN trans], simp) |
|
166 |
||
167 |
text{*Correctness of @{term posDivAlg}: it computes quotients correctly*} |
|
168 |
theorem posDivAlg_correct: |
|
169 |
assumes "0 \<le> a" and "0 < b" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
170 |
shows "divmod_int_rel a b (posDivAlg a b)" |
23164 | 171 |
using prems apply (induct a b rule: posDivAlg.induct) |
172 |
apply auto |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
173 |
apply (simp add: divmod_int_rel_def) |
23164 | 174 |
apply (subst posDivAlg_eqn, simp add: right_distrib) |
175 |
apply (case_tac "a < b") |
|
176 |
apply simp_all |
|
177 |
apply (erule splitE) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
178 |
apply (auto simp add: right_distrib Let_def mult_ac mult_2_right) |
23164 | 179 |
done |
180 |
||
181 |
||
182 |
subsection{*Correctness of @{term negDivAlg}, the Algorithm for Negative Dividends*} |
|
183 |
||
184 |
text{*And positive divisors*} |
|
185 |
||
186 |
declare negDivAlg.simps [simp del] |
|
187 |
||
188 |
text{*use with a simproc to avoid repeatedly proving the premise*} |
|
189 |
lemma negDivAlg_eqn: |
|
190 |
"0 < b ==> |
|
191 |
negDivAlg a b = |
|
192 |
(if 0\<le>a+b then (-1,a+b) else adjust b (negDivAlg a (2*b)))" |
|
193 |
by (rule negDivAlg.simps [THEN trans], simp) |
|
194 |
||
195 |
(*Correctness of negDivAlg: it computes quotients correctly |
|
196 |
It doesn't work if a=0 because the 0/b equals 0, not -1*) |
|
197 |
lemma negDivAlg_correct: |
|
198 |
assumes "a < 0" and "b > 0" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
199 |
shows "divmod_int_rel a b (negDivAlg a b)" |
23164 | 200 |
using prems apply (induct a b rule: negDivAlg.induct) |
201 |
apply (auto simp add: linorder_not_le) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
202 |
apply (simp add: divmod_int_rel_def) |
23164 | 203 |
apply (subst negDivAlg_eqn, assumption) |
204 |
apply (case_tac "a + b < (0\<Colon>int)") |
|
205 |
apply simp_all |
|
206 |
apply (erule splitE) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
207 |
apply (auto simp add: right_distrib Let_def mult_ac mult_2_right) |
23164 | 208 |
done |
209 |
||
210 |
||
211 |
subsection{*Existence Shown by Proving the Division Algorithm to be Correct*} |
|
212 |
||
213 |
(*the case a=0*) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
214 |
lemma divmod_int_rel_0: "b \<noteq> 0 ==> divmod_int_rel 0 b (0, 0)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
215 |
by (auto simp add: divmod_int_rel_def linorder_neq_iff) |
23164 | 216 |
|
217 |
lemma posDivAlg_0 [simp]: "posDivAlg 0 b = (0, 0)" |
|
218 |
by (subst posDivAlg.simps, auto) |
|
219 |
||
220 |
lemma negDivAlg_minus1 [simp]: "negDivAlg -1 b = (-1, b - 1)" |
|
221 |
by (subst negDivAlg.simps, auto) |
|
222 |
||
223 |
lemma negateSnd_eq [simp]: "negateSnd(q,r) = (q,-r)" |
|
224 |
by (simp add: negateSnd_def) |
|
225 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
226 |
lemma divmod_int_rel_neg: "divmod_int_rel (-a) (-b) qr ==> divmod_int_rel a b (negateSnd qr)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
227 |
by (auto simp add: split_ifs divmod_int_rel_def) |
23164 | 228 |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
229 |
lemma divmod_int_correct: "b \<noteq> 0 ==> divmod_int_rel a b (divmod_int a b)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
230 |
by (force simp add: linorder_neq_iff divmod_int_rel_0 divmod_int_def divmod_int_rel_neg |
23164 | 231 |
posDivAlg_correct negDivAlg_correct) |
232 |
||
233 |
text{*Arbitrary definitions for division by zero. Useful to simplify |
|
234 |
certain equations.*} |
|
235 |
||
236 |
lemma DIVISION_BY_ZERO [simp]: "a div (0::int) = 0 & a mod (0::int) = a" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
237 |
by (simp add: div_int_def mod_int_def divmod_int_def posDivAlg.simps) |
23164 | 238 |
|
239 |
||
240 |
text{*Basic laws about division and remainder*} |
|
241 |
||
242 |
lemma zmod_zdiv_equality: "(a::int) = b * (a div b) + (a mod b)" |
|
243 |
apply (case_tac "b = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
244 |
apply (cut_tac a = a and b = b in divmod_int_correct) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
245 |
apply (auto simp add: divmod_int_rel_def div_int_def mod_int_def) |
23164 | 246 |
done |
247 |
||
248 |
lemma zdiv_zmod_equality: "(b * (a div b) + (a mod b)) + k = (a::int)+k" |
|
249 |
by(simp add: zmod_zdiv_equality[symmetric]) |
|
250 |
||
251 |
lemma zdiv_zmod_equality2: "((a div b) * b + (a mod b)) + k = (a::int)+k" |
|
252 |
by(simp add: mult_commute zmod_zdiv_equality[symmetric]) |
|
253 |
||
254 |
text {* Tool setup *} |
|
255 |
||
26480 | 256 |
ML {* |
30934 | 257 |
local |
23164 | 258 |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
259 |
fun mk_number T n = HOLogic.number_of_const T $ HOLogic.mk_numeral n; |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
260 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
261 |
fun find_first_numeral past (t::terms) = |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
262 |
((snd (HOLogic.dest_number t), rev past @ terms) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
263 |
handle TERM _ => find_first_numeral (t::past) terms) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
264 |
| find_first_numeral past [] = raise TERM("find_first_numeral", []); |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
265 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
266 |
val mk_plus = HOLogic.mk_binop @{const_name HOL.plus}; |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
267 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
268 |
fun mk_minus t = |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
269 |
let val T = Term.fastype_of t |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
270 |
in Const (@{const_name HOL.uminus}, T --> T) $ t end; |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
271 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
272 |
(*Thus mk_sum[t] yields t+0; longer sums don't have a trailing zero*) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
273 |
fun mk_sum T [] = mk_number T 0 |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
274 |
| mk_sum T [t,u] = mk_plus (t, u) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
275 |
| mk_sum T (t :: ts) = mk_plus (t, mk_sum T ts); |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
276 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
277 |
(*this version ALWAYS includes a trailing zero*) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
278 |
fun long_mk_sum T [] = mk_number T 0 |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
279 |
| long_mk_sum T (t :: ts) = mk_plus (t, mk_sum T ts); |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
280 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
281 |
val dest_plus = HOLogic.dest_bin @{const_name HOL.plus} Term.dummyT; |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
282 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
283 |
(*decompose additions AND subtractions as a sum*) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
284 |
fun dest_summing (pos, Const (@{const_name HOL.plus}, _) $ t $ u, ts) = |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
285 |
dest_summing (pos, t, dest_summing (pos, u, ts)) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
286 |
| dest_summing (pos, Const (@{const_name HOL.minus}, _) $ t $ u, ts) = |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
287 |
dest_summing (pos, t, dest_summing (not pos, u, ts)) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
288 |
| dest_summing (pos, t, ts) = |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
289 |
if pos then t::ts else mk_minus t :: ts; |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
290 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
291 |
fun dest_sum t = dest_summing (true, t, []); |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
292 |
|
30934 | 293 |
structure CancelDivMod = CancelDivModFun(struct |
294 |
||
295 |
val div_name = @{const_name div}; |
|
296 |
val mod_name = @{const_name mod}; |
|
23164 | 297 |
val mk_binop = HOLogic.mk_binop; |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
298 |
val mk_sum = mk_sum HOLogic.intT; |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
299 |
val dest_sum = dest_sum; |
30934 | 300 |
|
301 |
val div_mod_eqs = map mk_meta_eq [@{thm zdiv_zmod_equality}, @{thm zdiv_zmod_equality2}]; |
|
302 |
||
23164 | 303 |
val trans = trans; |
30934 | 304 |
|
305 |
val prove_eq_sums = Arith_Data.prove_conv2 all_tac (Arith_Data.simp_all_tac |
|
306 |
(@{thm diff_minus} :: @{thms add_0s} @ @{thms add_ac})) |
|
307 |
||
23164 | 308 |
end) |
309 |
||
310 |
in |
|
311 |
||
32010 | 312 |
val cancel_div_mod_int_proc = Simplifier.simproc @{theory} |
30934 | 313 |
"cancel_zdiv_zmod" ["(k::int) + l"] (K CancelDivMod.proc); |
23164 | 314 |
|
30934 | 315 |
val _ = Addsimprocs [cancel_div_mod_int_proc]; |
23164 | 316 |
|
30934 | 317 |
end |
23164 | 318 |
*} |
319 |
||
320 |
lemma pos_mod_conj : "(0::int) < b ==> 0 \<le> a mod b & a mod b < b" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
321 |
apply (cut_tac a = a and b = b in divmod_int_correct) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
322 |
apply (auto simp add: divmod_int_rel_def mod_int_def) |
23164 | 323 |
done |
324 |
||
325 |
lemmas pos_mod_sign [simp] = pos_mod_conj [THEN conjunct1, standard] |
|
326 |
and pos_mod_bound [simp] = pos_mod_conj [THEN conjunct2, standard] |
|
327 |
||
328 |
lemma neg_mod_conj : "b < (0::int) ==> a mod b \<le> 0 & b < a mod b" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
329 |
apply (cut_tac a = a and b = b in divmod_int_correct) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
330 |
apply (auto simp add: divmod_int_rel_def div_int_def mod_int_def) |
23164 | 331 |
done |
332 |
||
333 |
lemmas neg_mod_sign [simp] = neg_mod_conj [THEN conjunct1, standard] |
|
334 |
and neg_mod_bound [simp] = neg_mod_conj [THEN conjunct2, standard] |
|
335 |
||
336 |
||
337 |
||
338 |
subsection{*General Properties of div and mod*} |
|
339 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
340 |
lemma divmod_int_rel_div_mod: "b \<noteq> 0 ==> divmod_int_rel a b (a div b, a mod b)" |
23164 | 341 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
342 |
apply (force simp add: divmod_int_rel_def linorder_neq_iff) |
23164 | 343 |
done |
344 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
345 |
lemma divmod_int_rel_div: "[| divmod_int_rel a b (q, r); b \<noteq> 0 |] ==> a div b = q" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
346 |
by (simp add: divmod_int_rel_div_mod [THEN unique_quotient]) |
23164 | 347 |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
348 |
lemma divmod_int_rel_mod: "[| divmod_int_rel a b (q, r); b \<noteq> 0 |] ==> a mod b = r" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
349 |
by (simp add: divmod_int_rel_div_mod [THEN unique_remainder]) |
23164 | 350 |
|
351 |
lemma div_pos_pos_trivial: "[| (0::int) \<le> a; a < b |] ==> a div b = 0" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
352 |
apply (rule divmod_int_rel_div) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
353 |
apply (auto simp add: divmod_int_rel_def) |
23164 | 354 |
done |
355 |
||
356 |
lemma div_neg_neg_trivial: "[| a \<le> (0::int); b < a |] ==> a div b = 0" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
357 |
apply (rule divmod_int_rel_div) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
358 |
apply (auto simp add: divmod_int_rel_def) |
23164 | 359 |
done |
360 |
||
361 |
lemma div_pos_neg_trivial: "[| (0::int) < a; a+b \<le> 0 |] ==> a div b = -1" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
362 |
apply (rule divmod_int_rel_div) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
363 |
apply (auto simp add: divmod_int_rel_def) |
23164 | 364 |
done |
365 |
||
366 |
(*There is no div_neg_pos_trivial because 0 div b = 0 would supersede it*) |
|
367 |
||
368 |
lemma mod_pos_pos_trivial: "[| (0::int) \<le> a; a < b |] ==> a mod b = a" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
369 |
apply (rule_tac q = 0 in divmod_int_rel_mod) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
370 |
apply (auto simp add: divmod_int_rel_def) |
23164 | 371 |
done |
372 |
||
373 |
lemma mod_neg_neg_trivial: "[| a \<le> (0::int); b < a |] ==> a mod b = a" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
374 |
apply (rule_tac q = 0 in divmod_int_rel_mod) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
375 |
apply (auto simp add: divmod_int_rel_def) |
23164 | 376 |
done |
377 |
||
378 |
lemma mod_pos_neg_trivial: "[| (0::int) < a; a+b \<le> 0 |] ==> a mod b = a+b" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
379 |
apply (rule_tac q = "-1" in divmod_int_rel_mod) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
380 |
apply (auto simp add: divmod_int_rel_def) |
23164 | 381 |
done |
382 |
||
383 |
text{*There is no @{text mod_neg_pos_trivial}.*} |
|
384 |
||
385 |
||
386 |
(*Simpler laws such as -a div b = -(a div b) FAIL, but see just below*) |
|
387 |
lemma zdiv_zminus_zminus [simp]: "(-a) div (-b) = a div (b::int)" |
|
388 |
apply (case_tac "b = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
389 |
apply (simp add: divmod_int_rel_div_mod [THEN divmod_int_rel_neg, simplified, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
390 |
THEN divmod_int_rel_div, THEN sym]) |
23164 | 391 |
|
392 |
done |
|
393 |
||
394 |
(*Simpler laws such as -a mod b = -(a mod b) FAIL, but see just below*) |
|
395 |
lemma zmod_zminus_zminus [simp]: "(-a) mod (-b) = - (a mod (b::int))" |
|
396 |
apply (case_tac "b = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
397 |
apply (subst divmod_int_rel_div_mod [THEN divmod_int_rel_neg, simplified, THEN divmod_int_rel_mod], |
23164 | 398 |
auto) |
399 |
done |
|
400 |
||
401 |
||
402 |
subsection{*Laws for div and mod with Unary Minus*} |
|
403 |
||
404 |
lemma zminus1_lemma: |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
405 |
"divmod_int_rel a b (q, r) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
406 |
==> divmod_int_rel (-a) b (if r=0 then -q else -q - 1, |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
407 |
if r=0 then 0 else b-r)" |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
408 |
by (force simp add: split_ifs divmod_int_rel_def linorder_neq_iff right_diff_distrib) |
23164 | 409 |
|
410 |
||
411 |
lemma zdiv_zminus1_eq_if: |
|
412 |
"b \<noteq> (0::int) |
|
413 |
==> (-a) div b = |
|
414 |
(if a mod b = 0 then - (a div b) else - (a div b) - 1)" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
415 |
by (blast intro: divmod_int_rel_div_mod [THEN zminus1_lemma, THEN divmod_int_rel_div]) |
23164 | 416 |
|
417 |
lemma zmod_zminus1_eq_if: |
|
418 |
"(-a::int) mod b = (if a mod b = 0 then 0 else b - (a mod b))" |
|
419 |
apply (case_tac "b = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
420 |
apply (blast intro: divmod_int_rel_div_mod [THEN zminus1_lemma, THEN divmod_int_rel_mod]) |
23164 | 421 |
done |
422 |
||
29936 | 423 |
lemma zmod_zminus1_not_zero: |
424 |
fixes k l :: int |
|
425 |
shows "- k mod l \<noteq> 0 \<Longrightarrow> k mod l \<noteq> 0" |
|
426 |
unfolding zmod_zminus1_eq_if by auto |
|
427 |
||
23164 | 428 |
lemma zdiv_zminus2: "a div (-b) = (-a::int) div b" |
429 |
by (cut_tac a = "-a" in zdiv_zminus_zminus, auto) |
|
430 |
||
431 |
lemma zmod_zminus2: "a mod (-b) = - ((-a::int) mod b)" |
|
432 |
by (cut_tac a = "-a" and b = b in zmod_zminus_zminus, auto) |
|
433 |
||
434 |
lemma zdiv_zminus2_eq_if: |
|
435 |
"b \<noteq> (0::int) |
|
436 |
==> a div (-b) = |
|
437 |
(if a mod b = 0 then - (a div b) else - (a div b) - 1)" |
|
438 |
by (simp add: zdiv_zminus1_eq_if zdiv_zminus2) |
|
439 |
||
440 |
lemma zmod_zminus2_eq_if: |
|
441 |
"a mod (-b::int) = (if a mod b = 0 then 0 else (a mod b) - b)" |
|
442 |
by (simp add: zmod_zminus1_eq_if zmod_zminus2) |
|
443 |
||
29936 | 444 |
lemma zmod_zminus2_not_zero: |
445 |
fixes k l :: int |
|
446 |
shows "k mod - l \<noteq> 0 \<Longrightarrow> k mod l \<noteq> 0" |
|
447 |
unfolding zmod_zminus2_eq_if by auto |
|
448 |
||
23164 | 449 |
|
450 |
subsection{*Division of a Number by Itself*} |
|
451 |
||
452 |
lemma self_quotient_aux1: "[| (0::int) < a; a = r + a*q; r < a |] ==> 1 \<le> q" |
|
453 |
apply (subgoal_tac "0 < a*q") |
|
454 |
apply (simp add: zero_less_mult_iff, arith) |
|
455 |
done |
|
456 |
||
457 |
lemma self_quotient_aux2: "[| (0::int) < a; a = r + a*q; 0 \<le> r |] ==> q \<le> 1" |
|
458 |
apply (subgoal_tac "0 \<le> a* (1-q) ") |
|
459 |
apply (simp add: zero_le_mult_iff) |
|
460 |
apply (simp add: right_diff_distrib) |
|
461 |
done |
|
462 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
463 |
lemma self_quotient: "[| divmod_int_rel a a (q, r); a \<noteq> (0::int) |] ==> q = 1" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
464 |
apply (simp add: split_ifs divmod_int_rel_def linorder_neq_iff) |
23164 | 465 |
apply (rule order_antisym, safe, simp_all) |
466 |
apply (rule_tac [3] a = "-a" and r = "-r" in self_quotient_aux1) |
|
467 |
apply (rule_tac a = "-a" and r = "-r" in self_quotient_aux2) |
|
468 |
apply (force intro: self_quotient_aux1 self_quotient_aux2 simp add: add_commute)+ |
|
469 |
done |
|
470 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
471 |
lemma self_remainder: "[| divmod_int_rel a a (q, r); a \<noteq> (0::int) |] ==> r = 0" |
23164 | 472 |
apply (frule self_quotient, assumption) |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
473 |
apply (simp add: divmod_int_rel_def) |
23164 | 474 |
done |
475 |
||
476 |
lemma zdiv_self [simp]: "a \<noteq> 0 ==> a div a = (1::int)" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
477 |
by (simp add: divmod_int_rel_div_mod [THEN self_quotient]) |
23164 | 478 |
|
479 |
(*Here we have 0 mod 0 = 0, also assumed by Knuth (who puts m mod 0 = 0) *) |
|
480 |
lemma zmod_self [simp]: "a mod a = (0::int)" |
|
481 |
apply (case_tac "a = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
482 |
apply (simp add: divmod_int_rel_div_mod [THEN self_remainder]) |
23164 | 483 |
done |
484 |
||
485 |
||
486 |
subsection{*Computation of Division and Remainder*} |
|
487 |
||
488 |
lemma zdiv_zero [simp]: "(0::int) div b = 0" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
489 |
by (simp add: div_int_def divmod_int_def) |
23164 | 490 |
|
491 |
lemma div_eq_minus1: "(0::int) < b ==> -1 div b = -1" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
492 |
by (simp add: div_int_def divmod_int_def) |
23164 | 493 |
|
494 |
lemma zmod_zero [simp]: "(0::int) mod b = 0" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
495 |
by (simp add: mod_int_def divmod_int_def) |
23164 | 496 |
|
497 |
lemma zmod_minus1: "(0::int) < b ==> -1 mod b = b - 1" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
498 |
by (simp add: mod_int_def divmod_int_def) |
23164 | 499 |
|
500 |
text{*a positive, b positive *} |
|
501 |
||
502 |
lemma div_pos_pos: "[| 0 < a; 0 \<le> b |] ==> a div b = fst (posDivAlg a b)" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
503 |
by (simp add: div_int_def divmod_int_def) |
23164 | 504 |
|
505 |
lemma mod_pos_pos: "[| 0 < a; 0 \<le> b |] ==> a mod b = snd (posDivAlg a b)" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
506 |
by (simp add: mod_int_def divmod_int_def) |
23164 | 507 |
|
508 |
text{*a negative, b positive *} |
|
509 |
||
510 |
lemma div_neg_pos: "[| a < 0; 0 < b |] ==> a div b = fst (negDivAlg a b)" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
511 |
by (simp add: div_int_def divmod_int_def) |
23164 | 512 |
|
513 |
lemma mod_neg_pos: "[| a < 0; 0 < b |] ==> a mod b = snd (negDivAlg a b)" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
514 |
by (simp add: mod_int_def divmod_int_def) |
23164 | 515 |
|
516 |
text{*a positive, b negative *} |
|
517 |
||
518 |
lemma div_pos_neg: |
|
519 |
"[| 0 < a; b < 0 |] ==> a div b = fst (negateSnd (negDivAlg (-a) (-b)))" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
520 |
by (simp add: div_int_def divmod_int_def) |
23164 | 521 |
|
522 |
lemma mod_pos_neg: |
|
523 |
"[| 0 < a; b < 0 |] ==> a mod b = snd (negateSnd (negDivAlg (-a) (-b)))" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
524 |
by (simp add: mod_int_def divmod_int_def) |
23164 | 525 |
|
526 |
text{*a negative, b negative *} |
|
527 |
||
528 |
lemma div_neg_neg: |
|
529 |
"[| a < 0; b \<le> 0 |] ==> a div b = fst (negateSnd (posDivAlg (-a) (-b)))" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
530 |
by (simp add: div_int_def divmod_int_def) |
23164 | 531 |
|
532 |
lemma mod_neg_neg: |
|
533 |
"[| a < 0; b \<le> 0 |] ==> a mod b = snd (negateSnd (posDivAlg (-a) (-b)))" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
534 |
by (simp add: mod_int_def divmod_int_def) |
23164 | 535 |
|
536 |
text {*Simplify expresions in which div and mod combine numerical constants*} |
|
537 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
538 |
lemma divmod_int_relI: |
24481 | 539 |
"\<lbrakk>a == b * q + r; if 0 < b then 0 \<le> r \<and> r < b else b < r \<and> r \<le> 0\<rbrakk> |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
540 |
\<Longrightarrow> divmod_int_rel a b (q, r)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
541 |
unfolding divmod_int_rel_def by simp |
24481 | 542 |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
543 |
lemmas divmod_int_rel_div_eq = divmod_int_relI [THEN divmod_int_rel_div, THEN eq_reflection] |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
544 |
lemmas divmod_int_rel_mod_eq = divmod_int_relI [THEN divmod_int_rel_mod, THEN eq_reflection] |
24481 | 545 |
lemmas arithmetic_simps = |
546 |
arith_simps |
|
547 |
add_special |
|
548 |
OrderedGroup.add_0_left |
|
549 |
OrderedGroup.add_0_right |
|
550 |
mult_zero_left |
|
551 |
mult_zero_right |
|
552 |
mult_1_left |
|
553 |
mult_1_right |
|
554 |
||
555 |
(* simprocs adapted from HOL/ex/Binary.thy *) |
|
556 |
ML {* |
|
557 |
local |
|
30517 | 558 |
val mk_number = HOLogic.mk_number HOLogic.intT; |
559 |
fun mk_cert u k l = @{term "plus :: int \<Rightarrow> int \<Rightarrow> int"} $ |
|
560 |
(@{term "times :: int \<Rightarrow> int \<Rightarrow> int"} $ u $ mk_number k) $ |
|
561 |
mk_number l; |
|
562 |
fun prove ctxt prop = Goal.prove ctxt [] [] prop |
|
563 |
(K (ALLGOALS (full_simp_tac (HOL_basic_ss addsimps @{thms arithmetic_simps})))); |
|
24481 | 564 |
fun binary_proc proc ss ct = |
565 |
(case Thm.term_of ct of |
|
566 |
_ $ t $ u => |
|
567 |
(case try (pairself (`(snd o HOLogic.dest_number))) (t, u) of |
|
568 |
SOME args => proc (Simplifier.the_context ss) args |
|
569 |
| NONE => NONE) |
|
570 |
| _ => NONE); |
|
571 |
in |
|
30517 | 572 |
fun divmod_proc rule = binary_proc (fn ctxt => fn ((m, t), (n, u)) => |
573 |
if n = 0 then NONE |
|
574 |
else let val (k, l) = Integer.div_mod m n; |
|
575 |
in SOME (rule OF [prove ctxt (Logic.mk_equals (t, mk_cert u k l))]) end); |
|
576 |
end |
|
24481 | 577 |
*} |
578 |
||
579 |
simproc_setup binary_int_div ("number_of m div number_of n :: int") = |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
580 |
{* K (divmod_proc (@{thm divmod_int_rel_div_eq})) *} |
24481 | 581 |
|
582 |
simproc_setup binary_int_mod ("number_of m mod number_of n :: int") = |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
583 |
{* K (divmod_proc (@{thm divmod_int_rel_mod_eq})) *} |
24481 | 584 |
|
23164 | 585 |
lemmas posDivAlg_eqn_number_of [simp] = |
586 |
posDivAlg_eqn [of "number_of v" "number_of w", standard] |
|
587 |
||
588 |
lemmas negDivAlg_eqn_number_of [simp] = |
|
589 |
negDivAlg_eqn [of "number_of v" "number_of w", standard] |
|
590 |
||
591 |
||
592 |
text{*Special-case simplification *} |
|
593 |
||
594 |
lemma zmod_minus1_right [simp]: "a mod (-1::int) = 0" |
|
595 |
apply (cut_tac a = a and b = "-1" in neg_mod_sign) |
|
596 |
apply (cut_tac [2] a = a and b = "-1" in neg_mod_bound) |
|
597 |
apply (auto simp del: neg_mod_sign neg_mod_bound) |
|
598 |
done |
|
599 |
||
600 |
lemma zdiv_minus1_right [simp]: "a div (-1::int) = -a" |
|
601 |
by (cut_tac a = a and b = "-1" in zmod_zdiv_equality, auto) |
|
602 |
||
603 |
(** The last remaining special cases for constant arithmetic: |
|
604 |
1 div z and 1 mod z **) |
|
605 |
||
606 |
lemmas div_pos_pos_1_number_of [simp] = |
|
607 |
div_pos_pos [OF int_0_less_1, of "number_of w", standard] |
|
608 |
||
609 |
lemmas div_pos_neg_1_number_of [simp] = |
|
610 |
div_pos_neg [OF int_0_less_1, of "number_of w", standard] |
|
611 |
||
612 |
lemmas mod_pos_pos_1_number_of [simp] = |
|
613 |
mod_pos_pos [OF int_0_less_1, of "number_of w", standard] |
|
614 |
||
615 |
lemmas mod_pos_neg_1_number_of [simp] = |
|
616 |
mod_pos_neg [OF int_0_less_1, of "number_of w", standard] |
|
617 |
||
618 |
||
619 |
lemmas posDivAlg_eqn_1_number_of [simp] = |
|
620 |
posDivAlg_eqn [of concl: 1 "number_of w", standard] |
|
621 |
||
622 |
lemmas negDivAlg_eqn_1_number_of [simp] = |
|
623 |
negDivAlg_eqn [of concl: 1 "number_of w", standard] |
|
624 |
||
625 |
||
626 |
||
627 |
subsection{*Monotonicity in the First Argument (Dividend)*} |
|
628 |
||
629 |
lemma zdiv_mono1: "[| a \<le> a'; 0 < (b::int) |] ==> a div b \<le> a' div b" |
|
630 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
|
631 |
apply (cut_tac a = a' and b = b in zmod_zdiv_equality) |
|
632 |
apply (rule unique_quotient_lemma) |
|
633 |
apply (erule subst) |
|
634 |
apply (erule subst, simp_all) |
|
635 |
done |
|
636 |
||
637 |
lemma zdiv_mono1_neg: "[| a \<le> a'; (b::int) < 0 |] ==> a' div b \<le> a div b" |
|
638 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
|
639 |
apply (cut_tac a = a' and b = b in zmod_zdiv_equality) |
|
640 |
apply (rule unique_quotient_lemma_neg) |
|
641 |
apply (erule subst) |
|
642 |
apply (erule subst, simp_all) |
|
643 |
done |
|
644 |
||
645 |
||
646 |
subsection{*Monotonicity in the Second Argument (Divisor)*} |
|
647 |
||
648 |
lemma q_pos_lemma: |
|
649 |
"[| 0 \<le> b'*q' + r'; r' < b'; 0 < b' |] ==> 0 \<le> (q'::int)" |
|
650 |
apply (subgoal_tac "0 < b'* (q' + 1) ") |
|
651 |
apply (simp add: zero_less_mult_iff) |
|
652 |
apply (simp add: right_distrib) |
|
653 |
done |
|
654 |
||
655 |
lemma zdiv_mono2_lemma: |
|
656 |
"[| b*q + r = b'*q' + r'; 0 \<le> b'*q' + r'; |
|
657 |
r' < b'; 0 \<le> r; 0 < b'; b' \<le> b |] |
|
658 |
==> q \<le> (q'::int)" |
|
659 |
apply (frule q_pos_lemma, assumption+) |
|
660 |
apply (subgoal_tac "b*q < b* (q' + 1) ") |
|
661 |
apply (simp add: mult_less_cancel_left) |
|
662 |
apply (subgoal_tac "b*q = r' - r + b'*q'") |
|
663 |
prefer 2 apply simp |
|
664 |
apply (simp (no_asm_simp) add: right_distrib) |
|
665 |
apply (subst add_commute, rule zadd_zless_mono, arith) |
|
666 |
apply (rule mult_right_mono, auto) |
|
667 |
done |
|
668 |
||
669 |
lemma zdiv_mono2: |
|
670 |
"[| (0::int) \<le> a; 0 < b'; b' \<le> b |] ==> a div b \<le> a div b'" |
|
671 |
apply (subgoal_tac "b \<noteq> 0") |
|
672 |
prefer 2 apply arith |
|
673 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
|
674 |
apply (cut_tac a = a and b = b' in zmod_zdiv_equality) |
|
675 |
apply (rule zdiv_mono2_lemma) |
|
676 |
apply (erule subst) |
|
677 |
apply (erule subst, simp_all) |
|
678 |
done |
|
679 |
||
680 |
lemma q_neg_lemma: |
|
681 |
"[| b'*q' + r' < 0; 0 \<le> r'; 0 < b' |] ==> q' \<le> (0::int)" |
|
682 |
apply (subgoal_tac "b'*q' < 0") |
|
683 |
apply (simp add: mult_less_0_iff, arith) |
|
684 |
done |
|
685 |
||
686 |
lemma zdiv_mono2_neg_lemma: |
|
687 |
"[| b*q + r = b'*q' + r'; b'*q' + r' < 0; |
|
688 |
r < b; 0 \<le> r'; 0 < b'; b' \<le> b |] |
|
689 |
==> q' \<le> (q::int)" |
|
690 |
apply (frule q_neg_lemma, assumption+) |
|
691 |
apply (subgoal_tac "b*q' < b* (q + 1) ") |
|
692 |
apply (simp add: mult_less_cancel_left) |
|
693 |
apply (simp add: right_distrib) |
|
694 |
apply (subgoal_tac "b*q' \<le> b'*q'") |
|
695 |
prefer 2 apply (simp add: mult_right_mono_neg, arith) |
|
696 |
done |
|
697 |
||
698 |
lemma zdiv_mono2_neg: |
|
699 |
"[| a < (0::int); 0 < b'; b' \<le> b |] ==> a div b' \<le> a div b" |
|
700 |
apply (cut_tac a = a and b = b in zmod_zdiv_equality) |
|
701 |
apply (cut_tac a = a and b = b' in zmod_zdiv_equality) |
|
702 |
apply (rule zdiv_mono2_neg_lemma) |
|
703 |
apply (erule subst) |
|
704 |
apply (erule subst, simp_all) |
|
705 |
done |
|
706 |
||
25942 | 707 |
|
23164 | 708 |
subsection{*More Algebraic Laws for div and mod*} |
709 |
||
710 |
text{*proving (a*b) div c = a * (b div c) + a * (b mod c) *} |
|
711 |
||
712 |
lemma zmult1_lemma: |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
713 |
"[| divmod_int_rel b c (q, r); c \<noteq> 0 |] |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
714 |
==> divmod_int_rel (a * b) c (a*q + a*r div c, a*r mod c)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
715 |
by (auto simp add: split_ifs divmod_int_rel_def linorder_neq_iff right_distrib mult_ac) |
23164 | 716 |
|
717 |
lemma zdiv_zmult1_eq: "(a*b) div c = a*(b div c) + a*(b mod c) div (c::int)" |
|
718 |
apply (case_tac "c = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
719 |
apply (blast intro: divmod_int_rel_div_mod [THEN zmult1_lemma, THEN divmod_int_rel_div]) |
23164 | 720 |
done |
721 |
||
722 |
lemma zmod_zmult1_eq: "(a*b) mod c = a*(b mod c) mod (c::int)" |
|
723 |
apply (case_tac "c = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
724 |
apply (blast intro: divmod_int_rel_div_mod [THEN zmult1_lemma, THEN divmod_int_rel_mod]) |
23164 | 725 |
done |
726 |
||
29403
fe17df4e4ab3
generalize some div/mod lemmas; remove type-specific proofs
huffman
parents:
29045
diff
changeset
|
727 |
lemma zmod_zdiv_trivial: "(a mod b) div b = (0::int)" |
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
728 |
apply (case_tac "b = 0", simp) |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
729 |
apply (auto simp add: linorder_neq_iff div_pos_pos_trivial div_neg_neg_trivial) |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
730 |
done |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
731 |
|
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
732 |
text{*proving (a+b) div c = a div c + b div c + ((a mod c + b mod c) div c) *} |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
733 |
|
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
734 |
lemma zadd1_lemma: |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
735 |
"[| divmod_int_rel a c (aq, ar); divmod_int_rel b c (bq, br); c \<noteq> 0 |] |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
736 |
==> divmod_int_rel (a+b) c (aq + bq + (ar+br) div c, (ar+br) mod c)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
737 |
by (force simp add: split_ifs divmod_int_rel_def linorder_neq_iff right_distrib) |
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
738 |
|
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
739 |
(*NOT suitable for rewriting: the RHS has an instance of the LHS*) |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
740 |
lemma zdiv_zadd1_eq: |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
741 |
"(a+b) div (c::int) = a div c + b div c + ((a mod c + b mod c) div c)" |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
742 |
apply (case_tac "c = 0", simp) |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
743 |
apply (blast intro: zadd1_lemma [OF divmod_int_rel_div_mod divmod_int_rel_div_mod] divmod_int_rel_div) |
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
744 |
done |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
745 |
|
29405
98ab21b14f09
add class ring_div; generalize mod/diff/minus proofs for class ring_div
huffman
parents:
29404
diff
changeset
|
746 |
instance int :: ring_div |
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
747 |
proof |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
748 |
fix a b c :: int |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
749 |
assume not0: "b \<noteq> 0" |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
750 |
show "(a + c * b) div b = c + a div b" |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
751 |
unfolding zdiv_zadd1_eq [of a "c * b"] using not0 |
30181 | 752 |
by (simp add: zmod_zmult1_eq zmod_zdiv_trivial zdiv_zmult1_eq) |
30930 | 753 |
next |
754 |
fix a b c :: int |
|
755 |
assume "a \<noteq> 0" |
|
756 |
then show "(a * b) div (a * c) = b div c" |
|
757 |
proof (cases "b \<noteq> 0 \<and> c \<noteq> 0") |
|
758 |
case False then show ?thesis by auto |
|
759 |
next |
|
760 |
case True then have "b \<noteq> 0" and "c \<noteq> 0" by auto |
|
761 |
with `a \<noteq> 0` |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
762 |
have "\<And>q r. divmod_int_rel b c (q, r) \<Longrightarrow> divmod_int_rel (a * b) (a * c) (q, a * r)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
763 |
apply (auto simp add: divmod_int_rel_def) |
30930 | 764 |
apply (auto simp add: algebra_simps) |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
765 |
apply (auto simp add: zero_less_mult_iff zero_le_mult_iff mult_le_0_iff mult_commute [of a] mult_less_cancel_right) |
30930 | 766 |
done |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
767 |
moreover with `c \<noteq> 0` divmod_int_rel_div_mod have "divmod_int_rel b c (b div c, b mod c)" by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
768 |
ultimately have "divmod_int_rel (a * b) (a * c) (b div c, a * (b mod c))" . |
30930 | 769 |
moreover from `a \<noteq> 0` `c \<noteq> 0` have "a * c \<noteq> 0" by simp |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
770 |
ultimately show ?thesis by (rule divmod_int_rel_div) |
30930 | 771 |
qed |
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26507
diff
changeset
|
772 |
qed auto |
25942 | 773 |
|
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
774 |
lemma posDivAlg_div_mod: |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
775 |
assumes "k \<ge> 0" |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
776 |
and "l \<ge> 0" |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
777 |
shows "posDivAlg k l = (k div l, k mod l)" |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
778 |
proof (cases "l = 0") |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
779 |
case True then show ?thesis by (simp add: posDivAlg.simps) |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
780 |
next |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
781 |
case False with assms posDivAlg_correct |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
782 |
have "divmod_int_rel k l (fst (posDivAlg k l), snd (posDivAlg k l))" |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
783 |
by simp |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
784 |
from divmod_int_rel_div [OF this `l \<noteq> 0`] divmod_int_rel_mod [OF this `l \<noteq> 0`] |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
785 |
show ?thesis by simp |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
786 |
qed |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
787 |
|
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
788 |
lemma negDivAlg_div_mod: |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
789 |
assumes "k < 0" |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
790 |
and "l > 0" |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
791 |
shows "negDivAlg k l = (k div l, k mod l)" |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
792 |
proof - |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
793 |
from assms have "l \<noteq> 0" by simp |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
794 |
from assms negDivAlg_correct |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
795 |
have "divmod_int_rel k l (fst (negDivAlg k l), snd (negDivAlg k l))" |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
796 |
by simp |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
797 |
from divmod_int_rel_div [OF this `l \<noteq> 0`] divmod_int_rel_mod [OF this `l \<noteq> 0`] |
29651
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
798 |
show ?thesis by simp |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
799 |
qed |
16a19466bf81
slightly adapted towards more uniformity with div/mod on nat
haftmann
parents:
29410
diff
changeset
|
800 |
|
23164 | 801 |
lemma zmod_eq_0_iff: "(m mod d = 0) = (EX q::int. m = d*q)" |
29403
fe17df4e4ab3
generalize some div/mod lemmas; remove type-specific proofs
huffman
parents:
29045
diff
changeset
|
802 |
by (simp add: dvd_eq_mod_eq_0 [symmetric] dvd_def) |
23164 | 803 |
|
29403
fe17df4e4ab3
generalize some div/mod lemmas; remove type-specific proofs
huffman
parents:
29045
diff
changeset
|
804 |
(* REVISIT: should this be generalized to all semiring_div types? *) |
23164 | 805 |
lemmas zmod_eq_0D [dest!] = zmod_eq_0_iff [THEN iffD1] |
806 |
||
23983 | 807 |
|
23164 | 808 |
subsection{*Proving @{term "a div (b*c) = (a div b) div c"} *} |
809 |
||
810 |
(*The condition c>0 seems necessary. Consider that 7 div ~6 = ~2 but |
|
811 |
7 div 2 div ~3 = 3 div ~3 = ~1. The subcase (a div b) mod c = 0 seems |
|
812 |
to cause particular problems.*) |
|
813 |
||
814 |
text{*first, four lemmas to bound the remainder for the cases b<0 and b>0 *} |
|
815 |
||
816 |
lemma zmult2_lemma_aux1: "[| (0::int) < c; b < r; r \<le> 0 |] ==> b*c < b*(q mod c) + r" |
|
817 |
apply (subgoal_tac "b * (c - q mod c) < r * 1") |
|
29667 | 818 |
apply (simp add: algebra_simps) |
23164 | 819 |
apply (rule order_le_less_trans) |
29667 | 820 |
apply (erule_tac [2] mult_strict_right_mono) |
821 |
apply (rule mult_left_mono_neg) |
|
822 |
using add1_zle_eq[of "q mod c"]apply(simp add: algebra_simps pos_mod_bound) |
|
823 |
apply (simp) |
|
824 |
apply (simp) |
|
23164 | 825 |
done |
826 |
||
827 |
lemma zmult2_lemma_aux2: |
|
828 |
"[| (0::int) < c; b < r; r \<le> 0 |] ==> b * (q mod c) + r \<le> 0" |
|
829 |
apply (subgoal_tac "b * (q mod c) \<le> 0") |
|
830 |
apply arith |
|
831 |
apply (simp add: mult_le_0_iff) |
|
832 |
done |
|
833 |
||
834 |
lemma zmult2_lemma_aux3: "[| (0::int) < c; 0 \<le> r; r < b |] ==> 0 \<le> b * (q mod c) + r" |
|
835 |
apply (subgoal_tac "0 \<le> b * (q mod c) ") |
|
836 |
apply arith |
|
837 |
apply (simp add: zero_le_mult_iff) |
|
838 |
done |
|
839 |
||
840 |
lemma zmult2_lemma_aux4: "[| (0::int) < c; 0 \<le> r; r < b |] ==> b * (q mod c) + r < b * c" |
|
841 |
apply (subgoal_tac "r * 1 < b * (c - q mod c) ") |
|
29667 | 842 |
apply (simp add: right_diff_distrib) |
23164 | 843 |
apply (rule order_less_le_trans) |
29667 | 844 |
apply (erule mult_strict_right_mono) |
845 |
apply (rule_tac [2] mult_left_mono) |
|
846 |
apply simp |
|
847 |
using add1_zle_eq[of "q mod c"] apply (simp add: algebra_simps pos_mod_bound) |
|
848 |
apply simp |
|
23164 | 849 |
done |
850 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
851 |
lemma zmult2_lemma: "[| divmod_int_rel a b (q, r); b \<noteq> 0; 0 < c |] |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
852 |
==> divmod_int_rel a (b * c) (q div c, b*(q mod c) + r)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
853 |
by (auto simp add: mult_ac divmod_int_rel_def linorder_neq_iff |
23164 | 854 |
zero_less_mult_iff right_distrib [symmetric] |
855 |
zmult2_lemma_aux1 zmult2_lemma_aux2 zmult2_lemma_aux3 zmult2_lemma_aux4) |
|
856 |
||
857 |
lemma zdiv_zmult2_eq: "(0::int) < c ==> a div (b*c) = (a div b) div c" |
|
858 |
apply (case_tac "b = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
859 |
apply (force simp add: divmod_int_rel_div_mod [THEN zmult2_lemma, THEN divmod_int_rel_div]) |
23164 | 860 |
done |
861 |
||
862 |
lemma zmod_zmult2_eq: |
|
863 |
"(0::int) < c ==> a mod (b*c) = b*(a div b mod c) + a mod b" |
|
864 |
apply (case_tac "b = 0", simp) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
865 |
apply (force simp add: divmod_int_rel_div_mod [THEN zmult2_lemma, THEN divmod_int_rel_mod]) |
23164 | 866 |
done |
867 |
||
868 |
||
869 |
subsection {*Splitting Rules for div and mod*} |
|
870 |
||
871 |
text{*The proofs of the two lemmas below are essentially identical*} |
|
872 |
||
873 |
lemma split_pos_lemma: |
|
874 |
"0<k ==> |
|
875 |
P(n div k :: int)(n mod k) = (\<forall>i j. 0\<le>j & j<k & n = k*i + j --> P i j)" |
|
876 |
apply (rule iffI, clarify) |
|
877 |
apply (erule_tac P="P ?x ?y" in rev_mp) |
|
29948 | 878 |
apply (subst mod_add_eq) |
23164 | 879 |
apply (subst zdiv_zadd1_eq) |
880 |
apply (simp add: div_pos_pos_trivial mod_pos_pos_trivial) |
|
881 |
txt{*converse direction*} |
|
882 |
apply (drule_tac x = "n div k" in spec) |
|
883 |
apply (drule_tac x = "n mod k" in spec, simp) |
|
884 |
done |
|
885 |
||
886 |
lemma split_neg_lemma: |
|
887 |
"k<0 ==> |
|
888 |
P(n div k :: int)(n mod k) = (\<forall>i j. k<j & j\<le>0 & n = k*i + j --> P i j)" |
|
889 |
apply (rule iffI, clarify) |
|
890 |
apply (erule_tac P="P ?x ?y" in rev_mp) |
|
29948 | 891 |
apply (subst mod_add_eq) |
23164 | 892 |
apply (subst zdiv_zadd1_eq) |
893 |
apply (simp add: div_neg_neg_trivial mod_neg_neg_trivial) |
|
894 |
txt{*converse direction*} |
|
895 |
apply (drule_tac x = "n div k" in spec) |
|
896 |
apply (drule_tac x = "n mod k" in spec, simp) |
|
897 |
done |
|
898 |
||
899 |
lemma split_zdiv: |
|
900 |
"P(n div k :: int) = |
|
901 |
((k = 0 --> P 0) & |
|
902 |
(0<k --> (\<forall>i j. 0\<le>j & j<k & n = k*i + j --> P i)) & |
|
903 |
(k<0 --> (\<forall>i j. k<j & j\<le>0 & n = k*i + j --> P i)))" |
|
904 |
apply (case_tac "k=0", simp) |
|
905 |
apply (simp only: linorder_neq_iff) |
|
906 |
apply (erule disjE) |
|
907 |
apply (simp_all add: split_pos_lemma [of concl: "%x y. P x"] |
|
908 |
split_neg_lemma [of concl: "%x y. P x"]) |
|
909 |
done |
|
910 |
||
911 |
lemma split_zmod: |
|
912 |
"P(n mod k :: int) = |
|
913 |
((k = 0 --> P n) & |
|
914 |
(0<k --> (\<forall>i j. 0\<le>j & j<k & n = k*i + j --> P j)) & |
|
915 |
(k<0 --> (\<forall>i j. k<j & j\<le>0 & n = k*i + j --> P j)))" |
|
916 |
apply (case_tac "k=0", simp) |
|
917 |
apply (simp only: linorder_neq_iff) |
|
918 |
apply (erule disjE) |
|
919 |
apply (simp_all add: split_pos_lemma [of concl: "%x y. P y"] |
|
920 |
split_neg_lemma [of concl: "%x y. P y"]) |
|
921 |
done |
|
922 |
||
923 |
(* Enable arith to deal with div 2 and mod 2: *) |
|
924 |
declare split_zdiv [of _ _ "number_of k", simplified, standard, arith_split] |
|
925 |
declare split_zmod [of _ _ "number_of k", simplified, standard, arith_split] |
|
926 |
||
927 |
||
928 |
subsection{*Speeding up the Division Algorithm with Shifting*} |
|
929 |
||
930 |
text{*computing div by shifting *} |
|
931 |
||
932 |
lemma pos_zdiv_mult_2: "(0::int) \<le> a ==> (1 + 2*b) div (2*a) = b div a" |
|
933 |
proof cases |
|
934 |
assume "a=0" |
|
935 |
thus ?thesis by simp |
|
936 |
next |
|
937 |
assume "a\<noteq>0" and le_a: "0\<le>a" |
|
938 |
hence a_pos: "1 \<le> a" by arith |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30517
diff
changeset
|
939 |
hence one_less_a2: "1 < 2 * a" by arith |
23164 | 940 |
hence le_2a: "2 * (1 + b mod a) \<le> 2 * a" |
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30517
diff
changeset
|
941 |
unfolding mult_le_cancel_left |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30517
diff
changeset
|
942 |
by (simp add: add1_zle_eq add_commute [of 1]) |
23164 | 943 |
with a_pos have "0 \<le> b mod a" by simp |
944 |
hence le_addm: "0 \<le> 1 mod (2*a) + 2*(b mod a)" |
|
945 |
by (simp add: mod_pos_pos_trivial one_less_a2) |
|
946 |
with le_2a |
|
947 |
have "(1 mod (2*a) + 2*(b mod a)) div (2*a) = 0" |
|
948 |
by (simp add: div_pos_pos_trivial le_addm mod_pos_pos_trivial one_less_a2 |
|
949 |
right_distrib) |
|
950 |
thus ?thesis |
|
951 |
by (subst zdiv_zadd1_eq, |
|
30930 | 952 |
simp add: mod_mult_mult1 one_less_a2 |
23164 | 953 |
div_pos_pos_trivial) |
954 |
qed |
|
955 |
||
956 |
lemma neg_zdiv_mult_2: "a \<le> (0::int) ==> (1 + 2*b) div (2*a) = (b+1) div a" |
|
957 |
apply (subgoal_tac " (1 + 2* (-b - 1)) div (2 * (-a)) = (-b - 1) div (-a) ") |
|
958 |
apply (rule_tac [2] pos_zdiv_mult_2) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
959 |
apply (auto simp add: right_diff_distrib) |
23164 | 960 |
apply (subgoal_tac " (-1 - (2 * b)) = - (1 + (2 * b))") |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
961 |
apply (simp only: zdiv_zminus_zminus diff_minus minus_add_distrib [symmetric]) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
962 |
apply (simp_all add: algebra_simps) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
963 |
apply (simp only: ab_diff_minus minus_add_distrib [symmetric] number_of_Min zdiv_zminus_zminus) |
23164 | 964 |
done |
965 |
||
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
966 |
lemma zdiv_number_of_Bit0 [simp]: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
967 |
"number_of (Int.Bit0 v) div number_of (Int.Bit0 w) = |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
968 |
number_of v div (number_of w :: int)" |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
969 |
by (simp only: number_of_eq numeral_simps) (simp add: mult_2 [symmetric]) |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
970 |
|
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
971 |
lemma zdiv_number_of_Bit1 [simp]: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
972 |
"number_of (Int.Bit1 v) div number_of (Int.Bit0 w) = |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
973 |
(if (0::int) \<le> number_of w |
23164 | 974 |
then number_of v div (number_of w) |
975 |
else (number_of v + (1::int)) div (number_of w))" |
|
976 |
apply (simp only: number_of_eq numeral_simps UNIV_I split: split_if) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
977 |
apply (simp add: pos_zdiv_mult_2 neg_zdiv_mult_2 add_ac mult_2 [symmetric]) |
23164 | 978 |
done |
979 |
||
980 |
||
981 |
subsection{*Computing mod by Shifting (proofs resemble those for div)*} |
|
982 |
||
983 |
lemma pos_zmod_mult_2: |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
984 |
fixes a b :: int |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
985 |
assumes "0 \<le> a" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
986 |
shows "(1 + 2 * b) mod (2 * a) = 1 + 2 * (b mod a)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
987 |
proof (cases "0 < a") |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
988 |
case False with assms show ?thesis by simp |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
989 |
next |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
990 |
case True |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
991 |
then have "b mod a < a" by (rule pos_mod_bound) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
992 |
then have "1 + b mod a \<le> a" by simp |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
993 |
then have A: "2 * (1 + b mod a) \<le> 2 * a" by simp |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
994 |
from `0 < a` have "0 \<le> b mod a" by (rule pos_mod_sign) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
995 |
then have B: "0 \<le> 1 + 2 * (b mod a)" by simp |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
996 |
have "((1\<Colon>int) mod ((2\<Colon>int) * a) + (2\<Colon>int) * b mod ((2\<Colon>int) * a)) mod ((2\<Colon>int) * a) = (1\<Colon>int) + (2\<Colon>int) * (b mod a)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
997 |
using `0 < a` and A |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
998 |
by (auto simp add: mod_mult_mult1 mod_pos_pos_trivial ring_distribs intro!: mod_pos_pos_trivial B) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
999 |
then show ?thesis by (subst mod_add_eq) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1000 |
qed |
23164 | 1001 |
|
1002 |
lemma neg_zmod_mult_2: |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1003 |
fixes a b :: int |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1004 |
assumes "a \<le> 0" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1005 |
shows "(1 + 2 * b) mod (2 * a) = 2 * ((b + 1) mod a) - 1" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1006 |
proof - |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1007 |
from assms have "0 \<le> - a" by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1008 |
then have "(1 + 2 * (- b - 1)) mod (2 * (- a)) = 1 + 2 * ((- b - 1) mod (- a))" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1009 |
by (rule pos_zmod_mult_2) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1010 |
then show ?thesis by (simp add: zmod_zminus2 algebra_simps) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1011 |
(simp add: diff_minus add_ac) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1012 |
qed |
23164 | 1013 |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1014 |
lemma zmod_number_of_Bit0 [simp]: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1015 |
"number_of (Int.Bit0 v) mod number_of (Int.Bit0 w) = |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1016 |
(2::int) * (number_of v mod number_of w)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1017 |
apply (simp only: number_of_eq numeral_simps) |
30930 | 1018 |
apply (simp add: mod_mult_mult1 pos_zmod_mult_2 |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1019 |
neg_zmod_mult_2 add_ac mult_2 [symmetric]) |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1020 |
done |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1021 |
|
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1022 |
lemma zmod_number_of_Bit1 [simp]: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1023 |
"number_of (Int.Bit1 v) mod number_of (Int.Bit0 w) = |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1024 |
(if (0::int) \<le> number_of w |
23164 | 1025 |
then 2 * (number_of v mod number_of w) + 1 |
1026 |
else 2 * ((number_of v + (1::int)) mod number_of w) - 1)" |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25961
diff
changeset
|
1027 |
apply (simp only: number_of_eq numeral_simps) |
30930 | 1028 |
apply (simp add: mod_mult_mult1 pos_zmod_mult_2 |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1029 |
neg_zmod_mult_2 add_ac mult_2 [symmetric]) |
23164 | 1030 |
done |
1031 |
||
1032 |
||
1033 |
subsection{*Quotients of Signs*} |
|
1034 |
||
1035 |
lemma div_neg_pos_less0: "[| a < (0::int); 0 < b |] ==> a div b < 0" |
|
1036 |
apply (subgoal_tac "a div b \<le> -1", force) |
|
1037 |
apply (rule order_trans) |
|
1038 |
apply (rule_tac a' = "-1" in zdiv_mono1) |
|
29948 | 1039 |
apply (auto simp add: div_eq_minus1) |
23164 | 1040 |
done |
1041 |
||
30323 | 1042 |
lemma div_nonneg_neg_le0: "[| (0::int) \<le> a; b < 0 |] ==> a div b \<le> 0" |
23164 | 1043 |
by (drule zdiv_mono1_neg, auto) |
1044 |
||
30323 | 1045 |
lemma div_nonpos_pos_le0: "[| (a::int) \<le> 0; b > 0 |] ==> a div b \<le> 0" |
1046 |
by (drule zdiv_mono1, auto) |
|
1047 |
||
23164 | 1048 |
lemma pos_imp_zdiv_nonneg_iff: "(0::int) < b ==> (0 \<le> a div b) = (0 \<le> a)" |
1049 |
apply auto |
|
1050 |
apply (drule_tac [2] zdiv_mono1) |
|
1051 |
apply (auto simp add: linorder_neq_iff) |
|
1052 |
apply (simp (no_asm_use) add: linorder_not_less [symmetric]) |
|
1053 |
apply (blast intro: div_neg_pos_less0) |
|
1054 |
done |
|
1055 |
||
1056 |
lemma neg_imp_zdiv_nonneg_iff: |
|
1057 |
"b < (0::int) ==> (0 \<le> a div b) = (a \<le> (0::int))" |
|
1058 |
apply (subst zdiv_zminus_zminus [symmetric]) |
|
1059 |
apply (subst pos_imp_zdiv_nonneg_iff, auto) |
|
1060 |
done |
|
1061 |
||
1062 |
(*But not (a div b \<le> 0 iff a\<le>0); consider a=1, b=2 when a div b = 0.*) |
|
1063 |
lemma pos_imp_zdiv_neg_iff: "(0::int) < b ==> (a div b < 0) = (a < 0)" |
|
1064 |
by (simp add: linorder_not_le [symmetric] pos_imp_zdiv_nonneg_iff) |
|
1065 |
||
1066 |
(*Again the law fails for \<le>: consider a = -1, b = -2 when a div b = 0*) |
|
1067 |
lemma neg_imp_zdiv_neg_iff: "b < (0::int) ==> (a div b < 0) = (0 < a)" |
|
1068 |
by (simp add: linorder_not_le [symmetric] neg_imp_zdiv_nonneg_iff) |
|
1069 |
||
1070 |
||
1071 |
subsection {* The Divides Relation *} |
|
1072 |
||
1073 |
lemmas zdvd_iff_zmod_eq_0_number_of [simp] = |
|
30042 | 1074 |
dvd_eq_mod_eq_0 [of "number_of x::int" "number_of y::int", standard] |
23164 | 1075 |
|
1076 |
lemma zdvd_zmod: "f dvd m ==> f dvd (n::int) ==> f dvd m mod n" |
|
31662
57f7ef0dba8e
generalize lemmas dvd_mod and dvd_mod_iff to class semiring_div
huffman
parents:
31068
diff
changeset
|
1077 |
by (rule dvd_mod) (* TODO: remove *) |
23164 | 1078 |
|
1079 |
lemma zdvd_zmod_imp_zdvd: "k dvd m mod n ==> k dvd n ==> k dvd (m::int)" |
|
31662
57f7ef0dba8e
generalize lemmas dvd_mod and dvd_mod_iff to class semiring_div
huffman
parents:
31068
diff
changeset
|
1080 |
by (rule dvd_mod_imp_dvd) (* TODO: remove *) |
23164 | 1081 |
|
1082 |
lemma zmult_div_cancel: "(n::int) * (m div n) = m - (m mod n)" |
|
1083 |
using zmod_zdiv_equality[where a="m" and b="n"] |
|
29667 | 1084 |
by (simp add: algebra_simps) |
23164 | 1085 |
|
1086 |
lemma zpower_zmod: "((x::int) mod m)^y mod m = x^y mod m" |
|
1087 |
apply (induct "y", auto) |
|
1088 |
apply (rule zmod_zmult1_eq [THEN trans]) |
|
1089 |
apply (simp (no_asm_simp)) |
|
29948 | 1090 |
apply (rule mod_mult_eq [symmetric]) |
23164 | 1091 |
done |
1092 |
||
23365 | 1093 |
lemma zdiv_int: "int (a div b) = (int a) div (int b)" |
23164 | 1094 |
apply (subst split_div, auto) |
1095 |
apply (subst split_zdiv, auto) |
|
23365 | 1096 |
apply (rule_tac a="int (b * i) + int j" and b="int b" and r="int j" and r'=ja in IntDiv.unique_quotient) |
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1097 |
apply (auto simp add: IntDiv.divmod_int_rel_def of_nat_mult) |
23164 | 1098 |
done |
1099 |
||
1100 |
lemma zmod_int: "int (a mod b) = (int a) mod (int b)" |
|
23365 | 1101 |
apply (subst split_mod, auto) |
1102 |
apply (subst split_zmod, auto) |
|
1103 |
apply (rule_tac a="int (b * i) + int j" and b="int b" and q="int i" and q'=ia |
|
1104 |
in unique_remainder) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1105 |
apply (auto simp add: IntDiv.divmod_int_rel_def of_nat_mult) |
23365 | 1106 |
done |
23164 | 1107 |
|
30180 | 1108 |
lemma abs_div: "(y::int) dvd x \<Longrightarrow> abs (x div y) = abs x div abs y" |
1109 |
by (unfold dvd_def, cases "y=0", auto simp add: abs_mult) |
|
1110 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1111 |
lemma zdvd_mult_div_cancel:"(n::int) dvd m \<Longrightarrow> n * (m div n) = m" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1112 |
apply (subgoal_tac "m mod n = 0") |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1113 |
apply (simp add: zmult_div_cancel) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1114 |
apply (simp only: dvd_eq_mod_eq_0) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1115 |
done |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1116 |
|
23164 | 1117 |
text{*Suggested by Matthias Daum*} |
1118 |
lemma int_power_div_base: |
|
1119 |
"\<lbrakk>0 < m; 0 < k\<rbrakk> \<Longrightarrow> k ^ m div k = (k::int) ^ (m - Suc 0)" |
|
30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
30042
diff
changeset
|
1120 |
apply (subgoal_tac "k ^ m = k ^ ((m - Suc 0) + Suc 0)") |
23164 | 1121 |
apply (erule ssubst) |
1122 |
apply (simp only: power_add) |
|
1123 |
apply simp_all |
|
1124 |
done |
|
1125 |
||
23853 | 1126 |
text {* by Brian Huffman *} |
1127 |
lemma zminus_zmod: "- ((x::int) mod m) mod m = - x mod m" |
|
29405
98ab21b14f09
add class ring_div; generalize mod/diff/minus proofs for class ring_div
huffman
parents:
29404
diff
changeset
|
1128 |
by (rule mod_minus_eq [symmetric]) |
23853 | 1129 |
|
1130 |
lemma zdiff_zmod_left: "(x mod m - y) mod m = (x - y) mod (m::int)" |
|
29405
98ab21b14f09
add class ring_div; generalize mod/diff/minus proofs for class ring_div
huffman
parents:
29404
diff
changeset
|
1131 |
by (rule mod_diff_left_eq [symmetric]) |
23853 | 1132 |
|
1133 |
lemma zdiff_zmod_right: "(x - y mod m) mod m = (x - y) mod (m::int)" |
|
29405
98ab21b14f09
add class ring_div; generalize mod/diff/minus proofs for class ring_div
huffman
parents:
29404
diff
changeset
|
1134 |
by (rule mod_diff_right_eq [symmetric]) |
23853 | 1135 |
|
1136 |
lemmas zmod_simps = |
|
30034 | 1137 |
mod_add_left_eq [symmetric] |
1138 |
mod_add_right_eq [symmetric] |
|
30930 | 1139 |
zmod_zmult1_eq [symmetric] |
1140 |
mod_mult_left_eq [symmetric] |
|
1141 |
zpower_zmod |
|
23853 | 1142 |
zminus_zmod zdiff_zmod_left zdiff_zmod_right |
1143 |
||
29045
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1144 |
text {* Distributive laws for function @{text nat}. *} |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1145 |
|
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1146 |
lemma nat_div_distrib: "0 \<le> x \<Longrightarrow> nat (x div y) = nat x div nat y" |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1147 |
apply (rule linorder_cases [of y 0]) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1148 |
apply (simp add: div_nonneg_neg_le0) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1149 |
apply simp |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1150 |
apply (simp add: nat_eq_iff pos_imp_zdiv_nonneg_iff zdiv_int) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1151 |
done |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1152 |
|
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1153 |
(*Fails if y<0: the LHS collapses to (nat z) but the RHS doesn't*) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1154 |
lemma nat_mod_distrib: |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1155 |
"\<lbrakk>0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> nat (x mod y) = nat x mod nat y" |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1156 |
apply (case_tac "y = 0", simp add: DIVISION_BY_ZERO) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1157 |
apply (simp add: nat_eq_iff zmod_int) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1158 |
done |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1159 |
|
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1160 |
text{*Suggested by Matthias Daum*} |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1161 |
lemma int_div_less_self: "\<lbrakk>0 < x; 1 < k\<rbrakk> \<Longrightarrow> x div k < (x::int)" |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1162 |
apply (subgoal_tac "nat x div nat k < nat x") |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1163 |
apply (simp (asm_lr) add: nat_div_distrib [symmetric]) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1164 |
apply (rule Divides.div_less_dividend, simp_all) |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1165 |
done |
3c8f48333731
move nat_{div,mod}_distrib from NatBin to IntDiv, simplified proofs
huffman
parents:
28562
diff
changeset
|
1166 |
|
23853 | 1167 |
text {* code generator setup *} |
23164 | 1168 |
|
26507 | 1169 |
context ring_1 |
1170 |
begin |
|
1171 |
||
28562 | 1172 |
lemma of_int_num [code]: |
26507 | 1173 |
"of_int k = (if k = 0 then 0 else if k < 0 then |
1174 |
- of_int (- k) else let |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1175 |
(l, m) = divmod_int k 2; |
26507 | 1176 |
l' = of_int l |
1177 |
in if m = 0 then l' + l' else l' + l' + 1)" |
|
1178 |
proof - |
|
1179 |
have aux1: "k mod (2\<Colon>int) \<noteq> (0\<Colon>int) \<Longrightarrow> |
|
1180 |
of_int k = of_int (k div 2 * 2 + 1)" |
|
1181 |
proof - |
|
1182 |
have "k mod 2 < 2" by (auto intro: pos_mod_bound) |
|
1183 |
moreover have "0 \<le> k mod 2" by (auto intro: pos_mod_sign) |
|
1184 |
moreover assume "k mod 2 \<noteq> 0" |
|
1185 |
ultimately have "k mod 2 = 1" by arith |
|
1186 |
moreover have "of_int k = of_int (k div 2 * 2 + k mod 2)" by simp |
|
1187 |
ultimately show ?thesis by auto |
|
1188 |
qed |
|
1189 |
have aux2: "\<And>x. of_int 2 * x = x + x" |
|
1190 |
proof - |
|
1191 |
fix x |
|
1192 |
have int2: "(2::int) = 1 + 1" by arith |
|
1193 |
show "of_int 2 * x = x + x" |
|
1194 |
unfolding int2 of_int_add left_distrib by simp |
|
1195 |
qed |
|
1196 |
have aux3: "\<And>x. x * of_int 2 = x + x" |
|
1197 |
proof - |
|
1198 |
fix x |
|
1199 |
have int2: "(2::int) = 1 + 1" by arith |
|
1200 |
show "x * of_int 2 = x + x" |
|
1201 |
unfolding int2 of_int_add right_distrib by simp |
|
1202 |
qed |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1203 |
from aux1 show ?thesis by (auto simp add: divmod_int_mod_div Let_def aux2 aux3) |
26507 | 1204 |
qed |
1205 |
||
1206 |
end |
|
1207 |
||
27667
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1208 |
lemma zmod_eq_dvd_iff: "(x::int) mod n = y mod n \<longleftrightarrow> n dvd x - y" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1209 |
proof |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1210 |
assume H: "x mod n = y mod n" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1211 |
hence "x mod n - y mod n = 0" by simp |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1212 |
hence "(x mod n - y mod n) mod n = 0" by simp |
30034 | 1213 |
hence "(x - y) mod n = 0" by (simp add: mod_diff_eq[symmetric]) |
30042 | 1214 |
thus "n dvd x - y" by (simp add: dvd_eq_mod_eq_0) |
27667
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1215 |
next |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1216 |
assume H: "n dvd x - y" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1217 |
then obtain k where k: "x-y = n*k" unfolding dvd_def by blast |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1218 |
hence "x = n*k + y" by simp |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1219 |
hence "x mod n = (n*k + y) mod n" by simp |
30034 | 1220 |
thus "x mod n = y mod n" by (simp add: mod_add_left_eq) |
27667
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1221 |
qed |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1222 |
|
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1223 |
lemma nat_mod_eq_lemma: assumes xyn: "(x::nat) mod n = y mod n" and xy:"y \<le> x" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1224 |
shows "\<exists>q. x = y + n * q" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1225 |
proof- |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1226 |
from xy have th: "int x - int y = int (x - y)" by simp |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1227 |
from xyn have "int x mod int n = int y mod int n" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1228 |
by (simp add: zmod_int[symmetric]) |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1229 |
hence "int n dvd int x - int y" by (simp only: zmod_eq_dvd_iff[symmetric]) |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1230 |
hence "n dvd x - y" by (simp add: th zdvd_int) |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1231 |
then show ?thesis using xy unfolding dvd_def apply clarsimp apply (rule_tac x="k" in exI) by arith |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1232 |
qed |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1233 |
|
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1234 |
lemma nat_mod_eq_iff: "(x::nat) mod n = y mod n \<longleftrightarrow> (\<exists>q1 q2. x + n * q1 = y + n * q2)" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1235 |
(is "?lhs = ?rhs") |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1236 |
proof |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1237 |
assume H: "x mod n = y mod n" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1238 |
{assume xy: "x \<le> y" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1239 |
from H have th: "y mod n = x mod n" by simp |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1240 |
from nat_mod_eq_lemma[OF th xy] have ?rhs |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1241 |
apply clarify apply (rule_tac x="q" in exI) by (rule exI[where x="0"], simp)} |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1242 |
moreover |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1243 |
{assume xy: "y \<le> x" |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1244 |
from nat_mod_eq_lemma[OF H xy] have ?rhs |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1245 |
apply clarify apply (rule_tac x="0" in exI) by (rule_tac x="q" in exI, simp)} |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1246 |
ultimately show ?rhs using linear[of x y] by blast |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1247 |
next |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1248 |
assume ?rhs then obtain q1 q2 where q12: "x + n * q1 = y + n * q2" by blast |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1249 |
hence "(x + n * q1) mod n = (y + n * q2) mod n" by simp |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1250 |
thus ?lhs by simp |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1251 |
qed |
62500b980749
Added theorems zmod_eq_dvd_iff and nat_mod_eq_iff previously in Pocklington.thy --- relevant for algebra
chaieb
parents:
27651
diff
changeset
|
1252 |
|
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1253 |
lemma div_nat_number_of [simp]: |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1254 |
"(number_of v :: nat) div number_of v' = |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1255 |
(if neg (number_of v :: int) then 0 |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1256 |
else nat (number_of v div number_of v'))" |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1257 |
unfolding nat_number_of_def number_of_is_id neg_def |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1258 |
by (simp add: nat_div_distrib) |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1259 |
|
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1260 |
lemma one_div_nat_number_of [simp]: |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1261 |
"Suc 0 div number_of v' = nat (1 div number_of v')" |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1262 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1263 |
|
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1264 |
lemma mod_nat_number_of [simp]: |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1265 |
"(number_of v :: nat) mod number_of v' = |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1266 |
(if neg (number_of v :: int) then 0 |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1267 |
else if neg (number_of v' :: int) then number_of v |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1268 |
else nat (number_of v mod number_of v'))" |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1269 |
unfolding nat_number_of_def number_of_is_id neg_def |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1270 |
by (simp add: nat_mod_distrib) |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1271 |
|
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1272 |
lemma one_mod_nat_number_of [simp]: |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1273 |
"Suc 0 mod number_of v' = |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1274 |
(if neg (number_of v' :: int) then Suc 0 |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1275 |
else nat (1 mod number_of v'))" |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1276 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1277 |
|
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1278 |
lemmas dvd_eq_mod_eq_0_number_of = |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1279 |
dvd_eq_mod_eq_0 [of "number_of x" "number_of y", standard] |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1280 |
|
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1281 |
declare dvd_eq_mod_eq_0_number_of [simp] |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32960
diff
changeset
|
1282 |
|
29936 | 1283 |
|
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1284 |
subsection {* Transfer setup *} |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1285 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1286 |
lemma transfer_nat_int_functions: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1287 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) div (nat y) = nat (x div y)" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1288 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) mod (nat y) = nat (x mod y)" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1289 |
by (auto simp add: nat_div_distrib nat_mod_distrib) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1290 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1291 |
lemma transfer_nat_int_function_closures: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1292 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x div y >= 0" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1293 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x mod y >= 0" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1294 |
apply (cases "y = 0") |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1295 |
apply (auto simp add: pos_imp_zdiv_nonneg_iff) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1296 |
apply (cases "y = 0") |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1297 |
apply auto |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1298 |
done |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1299 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1300 |
declare TransferMorphism_nat_int[transfer add return: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1301 |
transfer_nat_int_functions |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1302 |
transfer_nat_int_function_closures |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1303 |
] |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1304 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1305 |
lemma transfer_int_nat_functions: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1306 |
"(int x) div (int y) = int (x div y)" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1307 |
"(int x) mod (int y) = int (x mod y)" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1308 |
by (auto simp add: zdiv_int zmod_int) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1309 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1310 |
lemma transfer_int_nat_function_closures: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1311 |
"is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (x div y)" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1312 |
"is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (x mod y)" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1313 |
by (simp_all only: is_nat_def transfer_nat_int_function_closures) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1314 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1315 |
declare TransferMorphism_int_nat[transfer add return: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1316 |
transfer_int_nat_functions |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1317 |
transfer_int_nat_function_closures |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1318 |
] |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1319 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33296
diff
changeset
|
1320 |
|
29936 | 1321 |
subsection {* Code generation *} |
1322 |
||
1323 |
definition pdivmod :: "int \<Rightarrow> int \<Rightarrow> int \<times> int" where |
|
1324 |
"pdivmod k l = (\<bar>k\<bar> div \<bar>l\<bar>, \<bar>k\<bar> mod \<bar>l\<bar>)" |
|
1325 |
||
1326 |
lemma pdivmod_posDivAlg [code]: |
|
1327 |
"pdivmod k l = (if l = 0 then (0, \<bar>k\<bar>) else posDivAlg \<bar>k\<bar> \<bar>l\<bar>)" |
|
1328 |
by (subst posDivAlg_div_mod) (simp_all add: pdivmod_def) |
|
1329 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1330 |
lemma divmod_int_pdivmod: "divmod_int k l = (if k = 0 then (0, 0) else if l = 0 then (0, k) else |
29936 | 1331 |
apsnd ((op *) (sgn l)) (if 0 < l \<and> 0 \<le> k \<or> l < 0 \<and> k < 0 |
1332 |
then pdivmod k l |
|
1333 |
else (let (r, s) = pdivmod k l in |
|
1334 |
if s = 0 then (- r, 0) else (- r - 1, \<bar>l\<bar> - s))))" |
|
1335 |
proof - |
|
1336 |
have aux: "\<And>q::int. - k = l * q \<longleftrightarrow> k = l * - q" by auto |
|
1337 |
show ?thesis |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1338 |
by (simp add: divmod_int_mod_div pdivmod_def) |
29936 | 1339 |
(auto simp add: aux not_less not_le zdiv_zminus1_eq_if |
1340 |
zmod_zminus1_eq_if zdiv_zminus2_eq_if zmod_zminus2_eq_if) |
|
1341 |
qed |
|
1342 |
||
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1343 |
lemma divmod_int_code [code]: "divmod_int k l = (if k = 0 then (0, 0) else if l = 0 then (0, k) else |
29936 | 1344 |
apsnd ((op *) (sgn l)) (if sgn k = sgn l |
1345 |
then pdivmod k l |
|
1346 |
else (let (r, s) = pdivmod k l in |
|
1347 |
if s = 0 then (- r, 0) else (- r - 1, \<bar>l\<bar> - s))))" |
|
1348 |
proof - |
|
1349 |
have "k \<noteq> 0 \<Longrightarrow> l \<noteq> 0 \<Longrightarrow> 0 < l \<and> 0 \<le> k \<or> l < 0 \<and> k < 0 \<longleftrightarrow> sgn k = sgn l" |
|
1350 |
by (auto simp add: not_less sgn_if) |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1351 |
then show ?thesis by (simp add: divmod_int_pdivmod) |
29936 | 1352 |
qed |
1353 |
||
23164 | 1354 |
code_modulename SML |
1355 |
IntDiv Integer |
|
1356 |
||
1357 |
code_modulename OCaml |
|
1358 |
IntDiv Integer |
|
1359 |
||
1360 |
code_modulename Haskell |
|
24195 | 1361 |
IntDiv Integer |
23164 | 1362 |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1363 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1364 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1365 |
subsection {* Proof Tools setup; Combination and Cancellation Simprocs *} |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1366 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1367 |
declare split_div[of _ _ "number_of k", standard, arith_split] |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1368 |
declare split_mod[of _ _ "number_of k", standard, arith_split] |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1369 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1370 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1371 |
subsubsection{*For @{text combine_numerals}*} |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1372 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1373 |
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1374 |
by (simp add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1375 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1376 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1377 |
subsubsection{*For @{text cancel_numerals}*} |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1378 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1379 |
lemma nat_diff_add_eq1: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1380 |
"j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1381 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1382 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1383 |
lemma nat_diff_add_eq2: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1384 |
"i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1385 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1386 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1387 |
lemma nat_eq_add_iff1: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1388 |
"j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1389 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1390 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1391 |
lemma nat_eq_add_iff2: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1392 |
"i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1393 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1394 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1395 |
lemma nat_less_add_iff1: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1396 |
"j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1397 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1398 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1399 |
lemma nat_less_add_iff2: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1400 |
"i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1401 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1402 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1403 |
lemma nat_le_add_iff1: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1404 |
"j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1405 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1406 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1407 |
lemma nat_le_add_iff2: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1408 |
"i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1409 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1410 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1411 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1412 |
subsubsection{*For @{text cancel_numeral_factors} *} |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1413 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1414 |
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1415 |
by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1416 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1417 |
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1418 |
by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1419 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1420 |
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1421 |
by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1422 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1423 |
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1424 |
by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1425 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1426 |
lemma nat_mult_dvd_cancel_disj[simp]: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1427 |
"(k*m) dvd (k*n) = (k=0 | m dvd (n::nat))" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1428 |
by(auto simp: dvd_eq_mod_eq_0 mod_mult_distrib2[symmetric]) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1429 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1430 |
lemma nat_mult_dvd_cancel1: "0 < k \<Longrightarrow> (k*m) dvd (k*n::nat) = (m dvd n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1431 |
by(auto) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1432 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1433 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1434 |
subsubsection{*For @{text cancel_factor} *} |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1435 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1436 |
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1437 |
by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1438 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1439 |
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1440 |
by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1441 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1442 |
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1443 |
by auto |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1444 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1445 |
lemma nat_mult_div_cancel_disj[simp]: |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1446 |
"(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1447 |
by (simp add: nat_mult_div_cancel1) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1448 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1449 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1450 |
use "Tools/numeral_simprocs.ML" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1451 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1452 |
use "Tools/nat_numeral_simprocs.ML" |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1453 |
|
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1454 |
declaration {* |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1455 |
K (Lin_Arith.add_simps (@{thms neg_simps} @ [@{thm Suc_nat_number_of}, @{thm int_nat_number_of}]) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1456 |
#> Lin_Arith.add_simps (@{thms ring_distribs} @ [@{thm Let_number_of}, @{thm Let_0}, @{thm Let_1}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1457 |
@{thm nat_0}, @{thm nat_1}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1458 |
@{thm add_nat_number_of}, @{thm diff_nat_number_of}, @{thm mult_nat_number_of}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1459 |
@{thm eq_nat_number_of}, @{thm less_nat_number_of}, @{thm le_number_of_eq_not_less}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1460 |
@{thm le_Suc_number_of}, @{thm le_number_of_Suc}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1461 |
@{thm less_Suc_number_of}, @{thm less_number_of_Suc}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1462 |
@{thm Suc_eq_number_of}, @{thm eq_number_of_Suc}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1463 |
@{thm mult_Suc}, @{thm mult_Suc_right}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1464 |
@{thm add_Suc}, @{thm add_Suc_right}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1465 |
@{thm eq_number_of_0}, @{thm eq_0_number_of}, @{thm less_0_number_of}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1466 |
@{thm of_int_number_of_eq}, @{thm of_nat_number_of_eq}, @{thm nat_number_of}, |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1467 |
@{thm if_True}, @{thm if_False}]) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1468 |
#> Lin_Arith.add_simprocs (Numeral_Simprocs.assoc_fold_simproc |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1469 |
:: Numeral_Simprocs.combine_numerals |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1470 |
:: Numeral_Simprocs.cancel_numerals) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1471 |
#> Lin_Arith.add_simprocs (Nat_Numeral_Simprocs.combine_numerals :: Nat_Numeral_Simprocs.cancel_numerals)) |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1472 |
*} |
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
1473 |
|
23164 | 1474 |
end |