author | wenzelm |
Wed, 12 Mar 2025 11:39:00 +0100 | |
changeset 82265 | 4b875a4c83b0 |
parent 82080 | 0aa2d1c132b2 |
child 82518 | da14e77a48b2 |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Number_Theory/Cong.thy |
66380 | 2 |
Author: Christophe Tabacznyj |
3 |
Author: Lawrence C. Paulson |
|
4 |
Author: Amine Chaieb |
|
5 |
Author: Thomas M. Rasmussen |
|
6 |
Author: Jeremy Avigad |
|
31719 | 7 |
|
8 |
Defines congruence (notation: [x = y] (mod z)) for natural numbers and |
|
9 |
integers. |
|
10 |
||
11 |
This file combines and revises a number of prior developments. |
|
12 |
||
13 |
The original theories "GCD" and "Primes" were by Christophe Tabacznyj |
|
58623 | 14 |
and Lawrence C. Paulson, based on @{cite davenport92}. They introduced |
31719 | 15 |
gcd, lcm, and prime for the natural numbers. |
16 |
||
17 |
The original theory "IntPrimes" was by Thomas M. Rasmussen, and |
|
18 |
extended gcd, lcm, primes to the integers. Amine Chaieb provided |
|
19 |
another extension of the notions to the integers, and added a number |
|
44872 | 20 |
of results to "Primes" and "GCD". |
31719 | 21 |
|
22 |
The original theory, "IntPrimes", by Thomas M. Rasmussen, defined and |
|
23 |
developed the congruence relations on the integers. The notion was |
|
33718 | 24 |
extended to the natural numbers by Chaieb. Jeremy Avigad combined |
31719 | 25 |
these, revised and tidied them, made the development uniform for the |
26 |
natural numbers and the integers, and added a number of new theorems. |
|
27 |
*) |
|
28 |
||
60526 | 29 |
section \<open>Congruence\<close> |
31719 | 30 |
|
31 |
theory Cong |
|
66453
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents:
66380
diff
changeset
|
32 |
imports "HOL-Computational_Algebra.Primes" |
31719 | 33 |
begin |
34 |
||
66888 | 35 |
subsection \<open>Generic congruences\<close> |
36 |
||
37 |
context unique_euclidean_semiring |
|
31719 | 38 |
begin |
39 |
||
81142 | 40 |
definition cong :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" |
41 |
(\<open>(\<open>indent=1 notation=\<open>mixfix cong\<close>\<close>[_ = _] '(' mod _'))\<close>) |
|
42 |
where "[b = c] (mod a) \<longleftrightarrow> b mod a = c mod a" |
|
66888 | 43 |
|
81142 | 44 |
abbreviation notcong :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" |
45 |
(\<open>(\<open>indent=1 notation=\<open>mixfix notcong\<close>\<close>[_ \<noteq> _] '(' mod _'))\<close>) |
|
46 |
where "[b \<noteq> c] (mod a) \<equiv> \<not> cong b c a" |
|
66888 | 47 |
|
48 |
lemma cong_refl [simp]: |
|
49 |
"[b = b] (mod a)" |
|
50 |
by (simp add: cong_def) |
|
51 |
||
52 |
lemma cong_sym: |
|
53 |
"[b = c] (mod a) \<Longrightarrow> [c = b] (mod a)" |
|
54 |
by (simp add: cong_def) |
|
55 |
||
56 |
lemma cong_sym_eq: |
|
57 |
"[b = c] (mod a) \<longleftrightarrow> [c = b] (mod a)" |
|
58 |
by (auto simp add: cong_def) |
|
59 |
||
60 |
lemma cong_trans [trans]: |
|
61 |
"[b = c] (mod a) \<Longrightarrow> [c = d] (mod a) \<Longrightarrow> [b = d] (mod a)" |
|
62 |
by (simp add: cong_def) |
|
63 |
||
67085 | 64 |
lemma cong_mult_self_right: |
65 |
"[b * a = 0] (mod a)" |
|
66 |
by (simp add: cong_def) |
|
67 |
||
68 |
lemma cong_mult_self_left: |
|
69 |
"[a * b = 0] (mod a)" |
|
70 |
by (simp add: cong_def) |
|
71 |
||
72 |
lemma cong_mod_left [simp]: |
|
73 |
"[b mod a = c] (mod a) \<longleftrightarrow> [b = c] (mod a)" |
|
74 |
by (simp add: cong_def) |
|
75 |
||
76 |
lemma cong_mod_right [simp]: |
|
77 |
"[b = c mod a] (mod a) \<longleftrightarrow> [b = c] (mod a)" |
|
78 |
by (simp add: cong_def) |
|
79 |
||
80 |
lemma cong_0 [simp, presburger]: |
|
81 |
"[b = c] (mod 0) \<longleftrightarrow> b = c" |
|
82 |
by (simp add: cong_def) |
|
83 |
||
84 |
lemma cong_1 [simp, presburger]: |
|
85 |
"[b = c] (mod 1)" |
|
86 |
by (simp add: cong_def) |
|
87 |
||
88 |
lemma cong_dvd_iff: |
|
89 |
"a dvd b \<longleftrightarrow> a dvd c" if "[b = c] (mod a)" |
|
90 |
using that by (auto simp: cong_def dvd_eq_mod_eq_0) |
|
91 |
||
92 |
lemma cong_0_iff: "[b = 0] (mod a) \<longleftrightarrow> a dvd b" |
|
93 |
by (simp add: cong_def dvd_eq_mod_eq_0) |
|
94 |
||
66888 | 95 |
lemma cong_add: |
96 |
"[b = c] (mod a) \<Longrightarrow> [d = e] (mod a) \<Longrightarrow> [b + d = c + e] (mod a)" |
|
97 |
by (auto simp add: cong_def intro: mod_add_cong) |
|
98 |
||
99 |
lemma cong_mult: |
|
100 |
"[b = c] (mod a) \<Longrightarrow> [d = e] (mod a) \<Longrightarrow> [b * d = c * e] (mod a)" |
|
101 |
by (auto simp add: cong_def intro: mod_mult_cong) |
|
102 |
||
67085 | 103 |
lemma cong_scalar_right: |
104 |
"[b = c] (mod a) \<Longrightarrow> [b * d = c * d] (mod a)" |
|
105 |
by (simp add: cong_mult) |
|
106 |
||
107 |
lemma cong_scalar_left: |
|
108 |
"[b = c] (mod a) \<Longrightarrow> [d * b = d * c] (mod a)" |
|
109 |
by (simp add: cong_mult) |
|
110 |
||
66888 | 111 |
lemma cong_pow: |
112 |
"[b = c] (mod a) \<Longrightarrow> [b ^ n = c ^ n] (mod a)" |
|
113 |
by (simp add: cong_def power_mod [symmetric, of b n a] power_mod [symmetric, of c n a]) |
|
114 |
||
115 |
lemma cong_sum: |
|
116 |
"[sum f A = sum g A] (mod a)" if "\<And>x. x \<in> A \<Longrightarrow> [f x = g x] (mod a)" |
|
117 |
using that by (induct A rule: infinite_finite_induct) (auto intro: cong_add) |
|
118 |
||
119 |
lemma cong_prod: |
|
120 |
"[prod f A = prod g A] (mod a)" if "(\<And>x. x \<in> A \<Longrightarrow> [f x = g x] (mod a))" |
|
121 |
using that by (induct A rule: infinite_finite_induct) (auto intro: cong_mult) |
|
122 |
||
123 |
lemma mod_mult_cong_right: |
|
124 |
"[c mod (a * b) = d] (mod a) \<longleftrightarrow> [c = d] (mod a)" |
|
125 |
by (simp add: cong_def mod_mod_cancel mod_add_left_eq) |
|
126 |
||
127 |
lemma mod_mult_cong_left: |
|
128 |
"[c mod (b * a) = d] (mod a) \<longleftrightarrow> [c = d] (mod a)" |
|
129 |
using mod_mult_cong_right [of c a b d] by (simp add: ac_simps) |
|
130 |
||
131 |
end |
|
132 |
||
133 |
context unique_euclidean_ring |
|
134 |
begin |
|
135 |
||
136 |
lemma cong_diff: |
|
137 |
"[b = c] (mod a) \<Longrightarrow> [d = e] (mod a) \<Longrightarrow> [b - d = c - e] (mod a)" |
|
138 |
by (auto simp add: cong_def intro: mod_diff_cong) |
|
139 |
||
140 |
lemma cong_diff_iff_cong_0: |
|
141 |
"[b - c = 0] (mod a) \<longleftrightarrow> [b = c] (mod a)" (is "?P \<longleftrightarrow> ?Q") |
|
142 |
proof |
|
143 |
assume ?P |
|
144 |
then have "[b - c + c = 0 + c] (mod a)" |
|
145 |
by (rule cong_add) simp |
|
146 |
then show ?Q |
|
147 |
by simp |
|
148 |
next |
|
149 |
assume ?Q |
|
150 |
with cong_diff [of b c a c c] show ?P |
|
151 |
by simp |
|
152 |
qed |
|
153 |
||
154 |
lemma cong_minus_minus_iff: |
|
155 |
"[- b = - c] (mod a) \<longleftrightarrow> [b = c] (mod a)" |
|
156 |
using cong_diff_iff_cong_0 [of b c a] cong_diff_iff_cong_0 [of "- b" "- c" a] |
|
157 |
by (simp add: cong_0_iff dvd_diff_commute) |
|
158 |
||
67115 | 159 |
lemma cong_modulus_minus_iff [iff]: |
67087 | 160 |
"[b = c] (mod - a) \<longleftrightarrow> [b = c] (mod a)" |
66888 | 161 |
using cong_diff_iff_cong_0 [of b c a] cong_diff_iff_cong_0 [of b c " -a"] |
162 |
by (simp add: cong_0_iff) |
|
31719 | 163 |
|
67087 | 164 |
lemma cong_iff_dvd_diff: |
165 |
"[a = b] (mod m) \<longleftrightarrow> m dvd (a - b)" |
|
166 |
by (simp add: cong_0_iff [symmetric] cong_diff_iff_cong_0) |
|
167 |
||
168 |
lemma cong_iff_lin: |
|
169 |
"[a = b] (mod m) \<longleftrightarrow> (\<exists>k. b = a + m * k)" (is "?P \<longleftrightarrow> ?Q") |
|
170 |
proof - |
|
171 |
have "?P \<longleftrightarrow> m dvd b - a" |
|
172 |
by (simp add: cong_iff_dvd_diff dvd_diff_commute) |
|
173 |
also have "\<dots> \<longleftrightarrow> ?Q" |
|
174 |
by (auto simp add: algebra_simps elim!: dvdE) |
|
175 |
finally show ?thesis |
|
176 |
by simp |
|
177 |
qed |
|
178 |
||
67115 | 179 |
lemma cong_add_lcancel: |
180 |
"[a + x = a + y] (mod n) \<longleftrightarrow> [x = y] (mod n)" |
|
181 |
by (simp add: cong_iff_lin algebra_simps) |
|
182 |
||
183 |
lemma cong_add_rcancel: |
|
184 |
"[x + a = y + a] (mod n) \<longleftrightarrow> [x = y] (mod n)" |
|
185 |
by (simp add: cong_iff_lin algebra_simps) |
|
186 |
||
187 |
lemma cong_add_lcancel_0: |
|
188 |
"[a + x = a] (mod n) \<longleftrightarrow> [x = 0] (mod n)" |
|
189 |
using cong_add_lcancel [of a x 0 n] by simp |
|
190 |
||
191 |
lemma cong_add_rcancel_0: |
|
192 |
"[x + a = a] (mod n) \<longleftrightarrow> [x = 0] (mod n)" |
|
193 |
using cong_add_rcancel [of x a 0 n] by simp |
|
194 |
||
195 |
lemma cong_dvd_modulus: |
|
196 |
"[x = y] (mod n)" if "[x = y] (mod m)" and "n dvd m" |
|
197 |
using that by (auto intro: dvd_trans simp add: cong_iff_dvd_diff) |
|
198 |
||
199 |
lemma cong_modulus_mult: |
|
200 |
"[x = y] (mod m)" if "[x = y] (mod m * n)" |
|
201 |
using that by (simp add: cong_iff_dvd_diff) (rule dvd_mult_left) |
|
202 |
||
31719 | 203 |
end |
204 |
||
67115 | 205 |
lemma cong_abs [simp]: |
206 |
"[x = y] (mod \<bar>m\<bar>) \<longleftrightarrow> [x = y] (mod m)" |
|
207 |
for x y :: "'a :: {unique_euclidean_ring, linordered_idom}" |
|
208 |
by (simp add: cong_iff_dvd_diff) |
|
209 |
||
210 |
lemma cong_square: |
|
211 |
"prime p \<Longrightarrow> 0 < a \<Longrightarrow> [a * a = 1] (mod p) \<Longrightarrow> [a = 1] (mod p) \<or> [a = - 1] (mod p)" |
|
212 |
for a p :: "'a :: {normalization_semidom, linordered_idom, unique_euclidean_ring}" |
|
213 |
by (auto simp add: cong_iff_dvd_diff square_diff_one_factored dest: prime_dvd_multD) |
|
214 |
||
215 |
lemma cong_mult_rcancel: |
|
216 |
"[a * k = b * k] (mod m) \<longleftrightarrow> [a = b] (mod m)" |
|
217 |
if "coprime k m" for a k m :: "'a::{unique_euclidean_ring, ring_gcd}" |
|
218 |
using that by (auto simp add: cong_iff_dvd_diff left_diff_distrib [symmetric] ac_simps coprime_dvd_mult_right_iff) |
|
219 |
||
220 |
lemma cong_mult_lcancel: |
|
221 |
"[k * a = k * b] (mod m) = [a = b] (mod m)" |
|
222 |
if "coprime k m" for a k m :: "'a::{unique_euclidean_ring, ring_gcd}" |
|
223 |
using that cong_mult_rcancel [of k m a b] by (simp add: ac_simps) |
|
224 |
||
225 |
lemma coprime_cong_mult: |
|
226 |
"[a = b] (mod m) \<Longrightarrow> [a = b] (mod n) \<Longrightarrow> coprime m n \<Longrightarrow> [a = b] (mod m * n)" |
|
227 |
for a b :: "'a :: {unique_euclidean_ring, semiring_gcd}" |
|
228 |
by (simp add: cong_iff_dvd_diff divides_mult) |
|
229 |
||
230 |
lemma cong_gcd_eq: |
|
231 |
"gcd a m = gcd b m" if "[a = b] (mod m)" |
|
232 |
for a b :: "'a :: {unique_euclidean_semiring, euclidean_semiring_gcd}" |
|
233 |
proof (cases "m = 0") |
|
234 |
case True |
|
235 |
with that show ?thesis |
|
236 |
by simp |
|
237 |
next |
|
238 |
case False |
|
239 |
moreover have "gcd (a mod m) m = gcd (b mod m) m" |
|
240 |
using that by (simp add: cong_def) |
|
241 |
ultimately show ?thesis |
|
242 |
by simp |
|
243 |
qed |
|
244 |
||
245 |
lemma cong_imp_coprime: |
|
246 |
"[a = b] (mod m) \<Longrightarrow> coprime a m \<Longrightarrow> coprime b m" |
|
247 |
for a b :: "'a :: {unique_euclidean_semiring, euclidean_semiring_gcd}" |
|
248 |
by (auto simp add: coprime_iff_gcd_eq_1 dest: cong_gcd_eq) |
|
249 |
||
250 |
lemma cong_cong_prod_coprime: |
|
251 |
"[x = y] (mod (\<Prod>i\<in>A. m i))" if |
|
252 |
"(\<forall>i\<in>A. [x = y] (mod m i))" |
|
253 |
"(\<forall>i\<in>A. (\<forall>j\<in>A. i \<noteq> j \<longrightarrow> coprime (m i) (m j)))" |
|
254 |
for x y :: "'a :: {unique_euclidean_ring, semiring_gcd}" |
|
255 |
using that by (induct A rule: infinite_finite_induct) |
|
256 |
(auto intro!: coprime_cong_mult prod_coprime_right) |
|
257 |
||
66380 | 258 |
|
69597 | 259 |
subsection \<open>Congruences on \<^typ>\<open>nat\<close> and \<^typ>\<open>int\<close>\<close> |
31719 | 260 |
|
66888 | 261 |
lemma cong_int_iff: |
262 |
"[int m = int q] (mod int n) \<longleftrightarrow> [m = q] (mod n)" |
|
263 |
by (simp add: cong_def of_nat_mod [symmetric]) |
|
264 |
||
265 |
lemma cong_Suc_0 [simp, presburger]: |
|
266 |
"[m = n] (mod Suc 0)" |
|
267 |
using cong_1 [of m n] by simp |
|
31719 | 268 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
269 |
lemma cong_diff_nat: |
66888 | 270 |
"[a - c = b - d] (mod m)" if "[a = b] (mod m)" "[c = d] (mod m)" |
66954 | 271 |
and "a \<ge> c" "b \<ge> d" for a b c d m :: nat |
272 |
proof - |
|
273 |
have "[c + (a - c) = d + (b - d)] (mod m)" |
|
274 |
using that by simp |
|
275 |
with \<open>[c = d] (mod m)\<close> have "[c + (a - c) = c + (b - d)] (mod m)" |
|
276 |
using mod_add_cong by (auto simp add: cong_def) fastforce |
|
277 |
then show ?thesis |
|
278 |
by (simp add: cong_def nat_mod_eq_iff) |
|
279 |
qed |
|
31719 | 280 |
|
66888 | 281 |
lemma cong_diff_iff_cong_0_nat: |
66954 | 282 |
"[a - b = 0] (mod m) \<longleftrightarrow> [a = b] (mod m)" if "a \<ge> b" for a b :: nat |
76224
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
283 |
using that by (simp add: cong_0_iff) (simp add: cong_def mod_eq_dvd_iff_nat) |
31719 | 284 |
|
66954 | 285 |
lemma cong_diff_iff_cong_0_nat': |
286 |
"[nat \<bar>int a - int b\<bar> = 0] (mod m) \<longleftrightarrow> [a = b] (mod m)" |
|
287 |
proof (cases "b \<le> a") |
|
288 |
case True |
|
289 |
then show ?thesis |
|
290 |
by (simp add: nat_diff_distrib' cong_diff_iff_cong_0_nat [of b a m]) |
|
291 |
next |
|
292 |
case False |
|
293 |
then have "a \<le> b" |
|
294 |
by simp |
|
295 |
then show ?thesis |
|
296 |
by (simp add: nat_diff_distrib' cong_diff_iff_cong_0_nat [of a b m]) |
|
297 |
(auto simp add: cong_def) |
|
298 |
qed |
|
299 |
||
300 |
lemma cong_altdef_nat: |
|
301 |
"a \<ge> b \<Longrightarrow> [a = b] (mod m) \<longleftrightarrow> m dvd (a - b)" |
|
66380 | 302 |
for a b :: nat |
66888 | 303 |
by (simp add: cong_0_iff [symmetric] cong_diff_iff_cong_0_nat) |
31719 | 304 |
|
66954 | 305 |
lemma cong_altdef_nat': |
306 |
"[a = b] (mod m) \<longleftrightarrow> m dvd nat \<bar>int a - int b\<bar>" |
|
67085 | 307 |
using cong_diff_iff_cong_0_nat' [of a b m] |
308 |
by (simp only: cong_0_iff [symmetric]) |
|
66954 | 309 |
|
310 |
lemma cong_mult_rcancel_nat: |
|
311 |
"[a * k = b * k] (mod m) \<longleftrightarrow> [a = b] (mod m)" |
|
312 |
if "coprime k m" for a k m :: nat |
|
313 |
proof - |
|
314 |
have "[a * k = b * k] (mod m) \<longleftrightarrow> m dvd nat \<bar>int (a * k) - int (b * k)\<bar>" |
|
315 |
by (simp add: cong_altdef_nat') |
|
316 |
also have "\<dots> \<longleftrightarrow> m dvd nat \<bar>(int a - int b) * int k\<bar>" |
|
317 |
by (simp add: algebra_simps) |
|
318 |
also have "\<dots> \<longleftrightarrow> m dvd nat \<bar>int a - int b\<bar> * k" |
|
319 |
by (simp add: abs_mult nat_times_as_int) |
|
320 |
also have "\<dots> \<longleftrightarrow> m dvd nat \<bar>int a - int b\<bar>" |
|
67051 | 321 |
by (rule coprime_dvd_mult_left_iff) (use \<open>coprime k m\<close> in \<open>simp add: ac_simps\<close>) |
66954 | 322 |
also have "\<dots> \<longleftrightarrow> [a = b] (mod m)" |
323 |
by (simp add: cong_altdef_nat') |
|
324 |
finally show ?thesis . |
|
325 |
qed |
|
31719 | 326 |
|
66954 | 327 |
lemma cong_mult_lcancel_nat: |
328 |
"[k * a = k * b] (mod m) = [a = b] (mod m)" |
|
329 |
if "coprime k m" for a k m :: nat |
|
330 |
using that by (simp add: cong_mult_rcancel_nat ac_simps) |
|
31719 | 331 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
332 |
lemma coprime_cong_mult_nat: |
66380 | 333 |
"[a = b] (mod m) \<Longrightarrow> [a = b] (mod n) \<Longrightarrow> coprime m n \<Longrightarrow> [a = b] (mod m * n)" |
334 |
for a b :: nat |
|
66954 | 335 |
by (simp add: cong_altdef_nat' divides_mult) |
31719 | 336 |
|
66380 | 337 |
lemma cong_less_imp_eq_nat: "0 \<le> a \<Longrightarrow> a < m \<Longrightarrow> 0 \<le> b \<Longrightarrow> b < m \<Longrightarrow> [a = b] (mod m) \<Longrightarrow> a = b" |
338 |
for a b :: nat |
|
66888 | 339 |
by (auto simp add: cong_def) |
31719 | 340 |
|
66380 | 341 |
lemma cong_less_imp_eq_int: "0 \<le> a \<Longrightarrow> a < m \<Longrightarrow> 0 \<le> b \<Longrightarrow> b < m \<Longrightarrow> [a = b] (mod m) \<Longrightarrow> a = b" |
342 |
for a b :: int |
|
66888 | 343 |
by (auto simp add: cong_def) |
31719 | 344 |
|
66380 | 345 |
lemma cong_less_unique_nat: "0 < m \<Longrightarrow> (\<exists>!b. 0 \<le> b \<and> b < m \<and> [a = b] (mod m))" |
346 |
for a m :: nat |
|
76231 | 347 |
by (auto simp: cong_def) (metis mod_mod_trivial mod_less_divisor) |
31719 | 348 |
|
66380 | 349 |
lemma cong_less_unique_int: "0 < m \<Longrightarrow> (\<exists>!b. 0 \<le> b \<and> b < m \<and> [a = b] (mod m))" |
350 |
for a m :: int |
|
76231 | 351 |
by (auto simp add: cong_def) (metis mod_mod_trivial pos_mod_bound pos_mod_sign) |
31719 | 352 |
|
76224
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
353 |
lemma cong_iff_lin_nat: "[a = b] (mod m) \<longleftrightarrow> (\<exists>k1 k2. b + k1 * m = a + k2 * m)" |
66380 | 354 |
for a b :: nat |
76224
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
355 |
apply (auto simp add: cong_def nat_mod_eq_iff) |
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
356 |
apply (metis mult.commute) |
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
357 |
apply (metis mult.commute) |
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
358 |
done |
31719 | 359 |
|
66380 | 360 |
lemma cong_cong_mod_nat: "[a = b] (mod m) \<longleftrightarrow> [a mod m = b mod m] (mod m)" |
361 |
for a b :: nat |
|
66888 | 362 |
by simp |
31719 | 363 |
|
66380 | 364 |
lemma cong_cong_mod_int: "[a = b] (mod m) \<longleftrightarrow> [a mod m = b mod m] (mod m)" |
365 |
for a b :: int |
|
66888 | 366 |
by simp |
31719 | 367 |
|
66380 | 368 |
lemma cong_add_lcancel_nat: "[a + x = a + y] (mod n) \<longleftrightarrow> [x = y] (mod n)" |
369 |
for a x y :: nat |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
370 |
by (simp add: cong_iff_lin_nat) |
31719 | 371 |
|
66380 | 372 |
lemma cong_add_rcancel_nat: "[x + a = y + a] (mod n) \<longleftrightarrow> [x = y] (mod n)" |
373 |
for a x y :: nat |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
374 |
by (simp add: cong_iff_lin_nat) |
31719 | 375 |
|
66380 | 376 |
lemma cong_add_lcancel_0_nat: "[a + x = a] (mod n) \<longleftrightarrow> [x = 0] (mod n)" |
377 |
for a x :: nat |
|
67085 | 378 |
using cong_add_lcancel_nat [of a x 0 n] by simp |
31719 | 379 |
|
66380 | 380 |
lemma cong_add_rcancel_0_nat: "[x + a = a] (mod n) \<longleftrightarrow> [x = 0] (mod n)" |
381 |
for a x :: nat |
|
67085 | 382 |
using cong_add_rcancel_nat [of x a 0 n] by simp |
66380 | 383 |
|
384 |
lemma cong_dvd_modulus_nat: "[x = y] (mod m) \<Longrightarrow> n dvd m \<Longrightarrow> [x = y] (mod n)" |
|
385 |
for x y :: nat |
|
76224
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
386 |
by (auto simp add: cong_altdef_nat') |
31719 | 387 |
|
66380 | 388 |
lemma cong_to_1_nat: |
389 |
fixes a :: nat |
|
390 |
assumes "[a = 1] (mod n)" |
|
391 |
shows "n dvd (a - 1)" |
|
392 |
proof (cases "a = 0") |
|
393 |
case True |
|
394 |
then show ?thesis by force |
|
395 |
next |
|
396 |
case False |
|
397 |
with assms show ?thesis by (metis cong_altdef_nat leI less_one) |
|
398 |
qed |
|
399 |
||
400 |
lemma cong_0_1_nat': "[0 = Suc 0] (mod n) \<longleftrightarrow> n = Suc 0" |
|
66888 | 401 |
by (auto simp: cong_def) |
66380 | 402 |
|
403 |
lemma cong_0_1_nat: "[0 = 1] (mod n) \<longleftrightarrow> n = 1" |
|
404 |
for n :: nat |
|
66888 | 405 |
by (auto simp: cong_def) |
66380 | 406 |
|
407 |
lemma cong_0_1_int: "[0 = 1] (mod n) \<longleftrightarrow> n = 1 \<or> n = - 1" |
|
408 |
for n :: int |
|
66888 | 409 |
by (auto simp: cong_def zmult_eq_1_iff) |
66380 | 410 |
|
411 |
lemma cong_to_1'_nat: "[a = 1] (mod n) \<longleftrightarrow> a = 0 \<and> n = 1 \<or> (\<exists>m. a = 1 + m * n)" |
|
412 |
for a :: nat |
|
413 |
by (metis add.right_neutral cong_0_1_nat cong_iff_lin_nat cong_to_1_nat |
|
414 |
dvd_div_mult_self leI le_add_diff_inverse less_one mult_eq_if) |
|
415 |
||
416 |
lemma cong_le_nat: "y \<le> x \<Longrightarrow> [x = y] (mod n) \<longleftrightarrow> (\<exists>q. x = q * n + y)" |
|
417 |
for x y :: nat |
|
76224
64e8d4afcf10
moved relevant theorems from theory Divides to theory Euclidean_Division
haftmann
parents:
71546
diff
changeset
|
418 |
by (auto simp add: cong_altdef_nat le_imp_diff_is_add) |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
419 |
|
66380 | 420 |
lemma cong_solve_nat: |
421 |
fixes a :: nat |
|
422 |
shows "\<exists>x. [a * x = gcd a n] (mod n)" |
|
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
423 |
proof (cases "a = 0 \<or> n = 0") |
66380 | 424 |
case True |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
425 |
then show ?thesis |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
426 |
by (force simp add: cong_0_iff cong_sym) |
66380 | 427 |
next |
428 |
case False |
|
429 |
then show ?thesis |
|
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
430 |
using bezout_nat [of a n] |
66888 | 431 |
by auto (metis cong_add_rcancel_0_nat cong_mult_self_left) |
66380 | 432 |
qed |
433 |
||
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
434 |
lemma cong_solve_int: |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
435 |
fixes a :: int |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
436 |
shows "\<exists>x. [a * x = gcd a n] (mod n)" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
437 |
by (metis bezout_int cong_iff_lin mult.commute) |
31719 | 438 |
|
44872 | 439 |
lemma cong_solve_dvd_nat: |
66380 | 440 |
fixes a :: nat |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
441 |
assumes "gcd a n dvd d" |
66380 | 442 |
shows "\<exists>x. [a * x = d] (mod n)" |
31719 | 443 |
proof - |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
444 |
from cong_solve_nat [of a] obtain x where "[a * x = gcd a n](mod n)" |
31719 | 445 |
by auto |
44872 | 446 |
then have "[(d div gcd a n) * (a * x) = (d div gcd a n) * gcd a n] (mod n)" |
66888 | 447 |
using cong_scalar_left by blast |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
448 |
also from assms have "(d div gcd a n) * gcd a n = d" |
31719 | 449 |
by (rule dvd_div_mult_self) |
450 |
also have "(d div gcd a n) * (a * x) = a * (d div gcd a n * x)" |
|
451 |
by auto |
|
452 |
finally show ?thesis |
|
453 |
by auto |
|
454 |
qed |
|
455 |
||
44872 | 456 |
lemma cong_solve_dvd_int: |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
457 |
fixes a::int |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
458 |
assumes b: "gcd a n dvd d" |
66380 | 459 |
shows "\<exists>x. [a * x = d] (mod n)" |
31719 | 460 |
proof - |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
461 |
from cong_solve_int [of a] obtain x where "[a * x = gcd a n](mod n)" |
31719 | 462 |
by auto |
44872 | 463 |
then have "[(d div gcd a n) * (a * x) = (d div gcd a n) * gcd a n] (mod n)" |
66888 | 464 |
using cong_scalar_left by blast |
31719 | 465 |
also from b have "(d div gcd a n) * gcd a n = d" |
466 |
by (rule dvd_div_mult_self) |
|
467 |
also have "(d div gcd a n) * (a * x) = a * (d div gcd a n * x)" |
|
468 |
by auto |
|
469 |
finally show ?thesis |
|
470 |
by auto |
|
471 |
qed |
|
472 |
||
66380 | 473 |
lemma cong_solve_coprime_nat: |
67051 | 474 |
"\<exists>x. [a * x = Suc 0] (mod n)" if "coprime a n" |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
475 |
using that cong_solve_nat [of a n] by auto |
31719 | 476 |
|
67051 | 477 |
lemma cong_solve_coprime_int: |
478 |
"\<exists>x. [a * x = 1] (mod n)" if "coprime a n" for a n x :: int |
|
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
479 |
using that cong_solve_int [of a n] by (auto simp add: zabs_def split: if_splits) |
55161 | 480 |
|
62349
7c23469b5118
cleansed junk-producing interpretations for gcd/lcm on nat altogether
haftmann
parents:
62348
diff
changeset
|
481 |
lemma coprime_iff_invertible_nat: |
67085 | 482 |
"coprime a m \<longleftrightarrow> (\<exists>x. [a * x = Suc 0] (mod m))" (is "?P \<longleftrightarrow> ?Q") |
483 |
proof |
|
484 |
assume ?P then show ?Q |
|
485 |
by (auto dest!: cong_solve_coprime_nat) |
|
486 |
next |
|
487 |
assume ?Q |
|
488 |
then obtain b where "[a * b = Suc 0] (mod m)" |
|
489 |
by blast |
|
490 |
with coprime_mod_left_iff [of m "a * b"] show ?P |
|
491 |
by (cases "m = 0 \<or> m = 1") |
|
492 |
(unfold cong_def, auto simp add: cong_def) |
|
493 |
qed |
|
66380 | 494 |
|
67051 | 495 |
lemma coprime_iff_invertible_int: |
67085 | 496 |
"coprime a m \<longleftrightarrow> (\<exists>x. [a * x = 1] (mod m))" (is "?P \<longleftrightarrow> ?Q") for m :: int |
497 |
proof |
|
498 |
assume ?P then show ?Q |
|
499 |
by (auto dest: cong_solve_coprime_int) |
|
500 |
next |
|
501 |
assume ?Q |
|
502 |
then obtain b where "[a * b = 1] (mod m)" |
|
503 |
by blast |
|
504 |
with coprime_mod_left_iff [of m "a * b"] show ?P |
|
505 |
by (cases "m = 0 \<or> m = 1") |
|
506 |
(unfold cong_def, auto simp add: zmult_eq_1_iff) |
|
507 |
qed |
|
31719 | 508 |
|
66380 | 509 |
lemma coprime_iff_invertible'_nat: |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
510 |
assumes "m > 0" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
511 |
shows "coprime a m \<longleftrightarrow> (\<exists>x. 0 \<le> x \<and> x < m \<and> [a * x = Suc 0] (mod m))" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
512 |
proof - |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
513 |
have "\<And>b. \<lbrakk>0 < m; [a * b = Suc 0] (mod m)\<rbrakk> \<Longrightarrow> \<exists>b'<m. [a * b' = Suc 0] (mod m)" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
514 |
by (metis cong_def mod_less_divisor [OF assms] mod_mult_right_eq) |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
515 |
then show ?thesis |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
516 |
using assms coprime_iff_invertible_nat by auto |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
517 |
qed |
31719 | 518 |
|
66380 | 519 |
lemma coprime_iff_invertible'_int: |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
520 |
fixes m :: int |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
521 |
assumes "m > 0" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
522 |
shows "coprime a m \<longleftrightarrow> (\<exists>x. 0 \<le> x \<and> x < m \<and> [a * x = 1] (mod m))" |
76231 | 523 |
using assms by (simp add: coprime_iff_invertible_int) |
524 |
(metis assms cong_mod_left mod_mult_right_eq pos_mod_bound pos_mod_sign) |
|
31719 | 525 |
|
66380 | 526 |
lemma cong_cong_lcm_nat: "[x = y] (mod a) \<Longrightarrow> [x = y] (mod b) \<Longrightarrow> [x = y] (mod lcm a b)" |
527 |
for x y :: nat |
|
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
528 |
by (meson cong_altdef_nat' lcm_least) |
31719 | 529 |
|
66380 | 530 |
lemma cong_cong_lcm_int: "[x = y] (mod a) \<Longrightarrow> [x = y] (mod b) \<Longrightarrow> [x = y] (mod lcm a b)" |
531 |
for x y :: int |
|
67115 | 532 |
by (auto simp add: cong_iff_dvd_diff lcm_least) |
31719 | 533 |
|
66888 | 534 |
lemma cong_cong_prod_coprime_nat: |
535 |
"[x = y] (mod (\<Prod>i\<in>A. m i))" if |
|
67115 | 536 |
"(\<forall>i\<in>A. [x = y] (mod m i))" |
66888 | 537 |
"(\<forall>i\<in>A. (\<forall>j\<in>A. i \<noteq> j \<longrightarrow> coprime (m i) (m j)))" |
67115 | 538 |
for x y :: nat |
539 |
using that by (induct A rule: infinite_finite_induct) |
|
540 |
(auto intro!: coprime_cong_mult_nat prod_coprime_right) |
|
31719 | 541 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
542 |
lemma binary_chinese_remainder_nat: |
66380 | 543 |
fixes m1 m2 :: nat |
544 |
assumes a: "coprime m1 m2" |
|
545 |
shows "\<exists>x. [x = u1] (mod m1) \<and> [x = u2] (mod m2)" |
|
31719 | 546 |
proof - |
67086 | 547 |
have "\<exists>b1 b2. [b1 = 1] (mod m1) \<and> [b1 = 0] (mod m2) \<and> [b2 = 0] (mod m1) \<and> [b2 = 1] (mod m2)" |
548 |
proof - |
|
549 |
from cong_solve_coprime_nat [OF a] obtain x1 where 1: "[m1 * x1 = 1] (mod m2)" |
|
550 |
by auto |
|
551 |
from a have b: "coprime m2 m1" |
|
552 |
by (simp add: ac_simps) |
|
553 |
from cong_solve_coprime_nat [OF b] obtain x2 where 2: "[m2 * x2 = 1] (mod m1)" |
|
554 |
by auto |
|
555 |
have "[m1 * x1 = 0] (mod m1)" |
|
556 |
by (simp add: cong_mult_self_left) |
|
557 |
moreover have "[m2 * x2 = 0] (mod m2)" |
|
558 |
by (simp add: cong_mult_self_left) |
|
559 |
ultimately show ?thesis |
|
560 |
using 1 2 by blast |
|
561 |
qed |
|
562 |
then obtain b1 b2 |
|
66380 | 563 |
where "[b1 = 1] (mod m1)" and "[b1 = 0] (mod m2)" |
564 |
and "[b2 = 0] (mod m1)" and "[b2 = 1] (mod m2)" |
|
31719 | 565 |
by blast |
566 |
let ?x = "u1 * b1 + u2 * b2" |
|
567 |
have "[?x = u1 * 1 + u2 * 0] (mod m1)" |
|
66888 | 568 |
using \<open>[b1 = 1] (mod m1)\<close> \<open>[b2 = 0] (mod m1)\<close> cong_add cong_scalar_left by blast |
44872 | 569 |
then have "[?x = u1] (mod m1)" by simp |
31719 | 570 |
have "[?x = u1 * 0 + u2 * 1] (mod m2)" |
66888 | 571 |
using \<open>[b1 = 0] (mod m2)\<close> \<open>[b2 = 1] (mod m2)\<close> cong_add cong_scalar_left by blast |
66380 | 572 |
then have "[?x = u2] (mod m2)" |
573 |
by simp |
|
574 |
with \<open>[?x = u1] (mod m1)\<close> show ?thesis |
|
575 |
by blast |
|
31719 | 576 |
qed |
577 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
578 |
lemma binary_chinese_remainder_int: |
66380 | 579 |
fixes m1 m2 :: int |
580 |
assumes a: "coprime m1 m2" |
|
581 |
shows "\<exists>x. [x = u1] (mod m1) \<and> [x = u2] (mod m2)" |
|
31719 | 582 |
proof - |
67086 | 583 |
have "\<exists>b1 b2. [b1 = 1] (mod m1) \<and> [b1 = 0] (mod m2) \<and> [b2 = 0] (mod m1) \<and> [b2 = 1] (mod m2)" |
584 |
proof - |
|
585 |
from cong_solve_coprime_int [OF a] obtain x1 where 1: "[m1 * x1 = 1] (mod m2)" |
|
586 |
by auto |
|
587 |
from a have b: "coprime m2 m1" |
|
588 |
by (simp add: ac_simps) |
|
589 |
from cong_solve_coprime_int [OF b] obtain x2 where 2: "[m2 * x2 = 1] (mod m1)" |
|
590 |
by auto |
|
591 |
have "[m1 * x1 = 0] (mod m1)" |
|
592 |
by (simp add: cong_mult_self_left) |
|
593 |
moreover have "[m2 * x2 = 0] (mod m2)" |
|
594 |
by (simp add: cong_mult_self_left) |
|
595 |
ultimately show ?thesis |
|
596 |
using 1 2 by blast |
|
597 |
qed |
|
598 |
then obtain b1 b2 |
|
66380 | 599 |
where "[b1 = 1] (mod m1)" and "[b1 = 0] (mod m2)" |
600 |
and "[b2 = 0] (mod m1)" and "[b2 = 1] (mod m2)" |
|
31719 | 601 |
by blast |
602 |
let ?x = "u1 * b1 + u2 * b2" |
|
603 |
have "[?x = u1 * 1 + u2 * 0] (mod m1)" |
|
66888 | 604 |
using \<open>[b1 = 1] (mod m1)\<close> \<open>[b2 = 0] (mod m1)\<close> cong_add cong_scalar_left by blast |
44872 | 605 |
then have "[?x = u1] (mod m1)" by simp |
31719 | 606 |
have "[?x = u1 * 0 + u2 * 1] (mod m2)" |
66888 | 607 |
using \<open>[b1 = 0] (mod m2)\<close> \<open>[b2 = 1] (mod m2)\<close> cong_add cong_scalar_left by blast |
44872 | 608 |
then have "[?x = u2] (mod m2)" by simp |
66380 | 609 |
with \<open>[?x = u1] (mod m1)\<close> show ?thesis |
610 |
by blast |
|
31719 | 611 |
qed |
612 |
||
66380 | 613 |
lemma cong_modulus_mult_nat: "[x = y] (mod m * n) \<Longrightarrow> [x = y] (mod m)" |
614 |
for x y :: nat |
|
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
615 |
by (metis cong_def mod_mult_cong_right) |
31719 | 616 |
|
66380 | 617 |
lemma cong_less_modulus_unique_nat: "[x = y] (mod m) \<Longrightarrow> x < m \<Longrightarrow> y < m \<Longrightarrow> x = y" |
618 |
for x y :: nat |
|
66888 | 619 |
by (simp add: cong_def) |
31719 | 620 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
621 |
lemma binary_chinese_remainder_unique_nat: |
66380 | 622 |
fixes m1 m2 :: nat |
623 |
assumes a: "coprime m1 m2" |
|
44872 | 624 |
and nz: "m1 \<noteq> 0" "m2 \<noteq> 0" |
63901 | 625 |
shows "\<exists>!x. x < m1 * m2 \<and> [x = u1] (mod m1) \<and> [x = u2] (mod m2)" |
31719 | 626 |
proof - |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
627 |
obtain y where y1: "[y = u1] (mod m1)" and y2: "[y = u2] (mod m2)" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
628 |
using binary_chinese_remainder_nat [OF a] by blast |
31719 | 629 |
let ?x = "y mod (m1 * m2)" |
630 |
from nz have less: "?x < m1 * m2" |
|
44872 | 631 |
by auto |
66380 | 632 |
have 1: "[?x = u1] (mod m1)" |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
633 |
using y1 mod_mult_cong_right by blast |
66380 | 634 |
have 2: "[?x = u2] (mod m2)" |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
635 |
using y2 mod_mult_cong_left by blast |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
636 |
have "z = ?x" if "z < m1 * m2" "[z = u1] (mod m1)" "[z = u2] (mod m2)" for z |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
637 |
proof - |
31719 | 638 |
have "[?x = z] (mod m1)" |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
639 |
by (metis "1" cong_def that(2)) |
31719 | 640 |
moreover have "[?x = z] (mod m2)" |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
641 |
by (metis "2" cong_def that(3)) |
31719 | 642 |
ultimately have "[?x = z] (mod m1 * m2)" |
66888 | 643 |
using a by (auto intro: coprime_cong_mult_nat simp add: mod_mult_cong_left mod_mult_cong_right) |
60526 | 644 |
with \<open>z < m1 * m2\<close> \<open>?x < m1 * m2\<close> show "z = ?x" |
67085 | 645 |
by (auto simp add: cong_def) |
44872 | 646 |
qed |
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
647 |
with less 1 2 show ?thesis |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
648 |
by blast |
31719 | 649 |
qed |
650 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
651 |
lemma chinese_remainder_nat: |
44872 | 652 |
fixes A :: "'a set" |
653 |
and m :: "'a \<Rightarrow> nat" |
|
654 |
and u :: "'a \<Rightarrow> nat" |
|
655 |
assumes fin: "finite A" |
|
66380 | 656 |
and cop: "\<forall>i \<in> A. \<forall>j \<in> A. i \<noteq> j \<longrightarrow> coprime (m i) (m j)" |
657 |
shows "\<exists>x. \<forall>i \<in> A. [x = u i] (mod m i)" |
|
31719 | 658 |
proof - |
67086 | 659 |
have "\<exists>b. (\<forall>i \<in> A. [b i = 1] (mod m i) \<and> [b i = 0] (mod (\<Prod>j \<in> A - {i}. m j)))" |
660 |
proof (rule finite_set_choice, rule fin, rule ballI) |
|
661 |
fix i |
|
662 |
assume "i \<in> A" |
|
663 |
with cop have "coprime (\<Prod>j \<in> A - {i}. m j) (m i)" |
|
664 |
by (intro prod_coprime_left) auto |
|
665 |
then have "\<exists>x. [(\<Prod>j \<in> A - {i}. m j) * x = Suc 0] (mod m i)" |
|
666 |
by (elim cong_solve_coprime_nat) |
|
667 |
then obtain x where "[(\<Prod>j \<in> A - {i}. m j) * x = 1] (mod m i)" |
|
668 |
by auto |
|
669 |
moreover have "[(\<Prod>j \<in> A - {i}. m j) * x = 0] (mod (\<Prod>j \<in> A - {i}. m j))" |
|
670 |
by (simp add: cong_0_iff) |
|
671 |
ultimately show "\<exists>a. [a = 1] (mod m i) \<and> [a = 0] (mod prod m (A - {i}))" |
|
672 |
by blast |
|
673 |
qed |
|
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
674 |
then obtain b where b: "\<And>i. i \<in> A \<Longrightarrow> [b i = 1] (mod m i) \<and> [b i = 0] (mod (\<Prod>j \<in> A - {i}. m j))" |
31719 | 675 |
by blast |
61954 | 676 |
let ?x = "\<Sum>i\<in>A. (u i) * (b i)" |
66380 | 677 |
show ?thesis |
31719 | 678 |
proof (rule exI, clarify) |
679 |
fix i |
|
66380 | 680 |
assume a: "i \<in> A" |
44872 | 681 |
show "[?x = u i] (mod m i)" |
31719 | 682 |
proof - |
66380 | 683 |
from fin a have "?x = (\<Sum>j \<in> {i}. u j * b j) + (\<Sum>j \<in> A - {i}. u j * b j)" |
684 |
by (subst sum.union_disjoint [symmetric]) (auto intro: sum.cong) |
|
61954 | 685 |
then have "[?x = u i * b i + (\<Sum>j \<in> A - {i}. u j * b j)] (mod m i)" |
31719 | 686 |
by auto |
61954 | 687 |
also have "[u i * b i + (\<Sum>j \<in> A - {i}. u j * b j) = |
688 |
u i * 1 + (\<Sum>j \<in> A - {i}. u j * 0)] (mod m i)" |
|
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
689 |
proof (intro cong_add cong_scalar_left cong_sum) |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
690 |
show "[b i = 1] (mod m i)" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
691 |
using a b by blast |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
692 |
show "[b x = 0] (mod m i)" if "x \<in> A - {i}" for x |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
693 |
proof - |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
694 |
have "x \<in> A" "x \<noteq> i" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
695 |
using that by auto |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
696 |
then show ?thesis |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
697 |
using a b [OF \<open>x \<in> A\<close>] cong_dvd_modulus_nat fin by blast |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
698 |
qed |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
699 |
qed |
31719 | 700 |
finally show ?thesis |
701 |
by simp |
|
702 |
qed |
|
703 |
qed |
|
704 |
qed |
|
705 |
||
68707
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
706 |
lemma coprime_cong_prod_nat: "[x = y] (mod (\<Prod>i\<in>A. m i))" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
707 |
if "\<And>i j. \<lbrakk>i \<in> A; j \<in> A; i \<noteq> j\<rbrakk> \<Longrightarrow> coprime (m i) (m j)" |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
708 |
and "\<And>i. i \<in> A \<Longrightarrow> [x = y] (mod m i)" for x y :: nat |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
709 |
using that |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
710 |
proof (induct A rule: infinite_finite_induct) |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
711 |
case (insert x A) |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
712 |
then show ?case |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
713 |
by simp (metis coprime_cong_mult_nat prod_coprime_right) |
5b269897df9d
de-applying and removal of obsolete aliases
paulson <lp15@cam.ac.uk>
parents:
67115
diff
changeset
|
714 |
qed auto |
31719 | 715 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31792
diff
changeset
|
716 |
lemma chinese_remainder_unique_nat: |
44872 | 717 |
fixes A :: "'a set" |
718 |
and m :: "'a \<Rightarrow> nat" |
|
719 |
and u :: "'a \<Rightarrow> nat" |
|
720 |
assumes fin: "finite A" |
|
61954 | 721 |
and nz: "\<forall>i\<in>A. m i \<noteq> 0" |
66380 | 722 |
and cop: "\<forall>i\<in>A. \<forall>j\<in>A. i \<noteq> j \<longrightarrow> coprime (m i) (m j)" |
63901 | 723 |
shows "\<exists>!x. x < (\<Prod>i\<in>A. m i) \<and> (\<forall>i\<in>A. [x = u i] (mod m i))" |
31719 | 724 |
proof - |
44872 | 725 |
from chinese_remainder_nat [OF fin cop] |
66380 | 726 |
obtain y where one: "(\<forall>i\<in>A. [y = u i] (mod m i))" |
31719 | 727 |
by blast |
61954 | 728 |
let ?x = "y mod (\<Prod>i\<in>A. m i)" |
729 |
from fin nz have prodnz: "(\<Prod>i\<in>A. m i) \<noteq> 0" |
|
31719 | 730 |
by auto |
61954 | 731 |
then have less: "?x < (\<Prod>i\<in>A. m i)" |
31719 | 732 |
by auto |
66380 | 733 |
have cong: "\<forall>i\<in>A. [?x = u i] (mod m i)" |
67085 | 734 |
using fin one |
735 |
by (auto simp add: cong_def dvd_prod_eqI mod_mod_cancel) |
|
66380 | 736 |
have unique: "\<forall>z. z < (\<Prod>i\<in>A. m i) \<and> (\<forall>i\<in>A. [z = u i] (mod m i)) \<longrightarrow> z = ?x" |
737 |
proof clarify |
|
31719 | 738 |
fix z |
61954 | 739 |
assume zless: "z < (\<Prod>i\<in>A. m i)" |
66380 | 740 |
assume zcong: "(\<forall>i\<in>A. [z = u i] (mod m i))" |
741 |
have "\<forall>i\<in>A. [?x = z] (mod m i)" |
|
67085 | 742 |
using cong zcong by (auto simp add: cong_def) |
61954 | 743 |
with fin cop have "[?x = z] (mod (\<Prod>i\<in>A. m i))" |
67085 | 744 |
by (intro coprime_cong_prod_nat) auto |
31719 | 745 |
with zless less show "z = ?x" |
67085 | 746 |
by (auto simp add: cong_def) |
44872 | 747 |
qed |
66380 | 748 |
from less cong unique show ?thesis |
749 |
by blast |
|
31719 | 750 |
qed |
751 |
||
80084
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
752 |
lemma (in semiring_1_cancel) of_nat_eq_iff_cong_CHAR: |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
753 |
"of_nat x = (of_nat y :: 'a) \<longleftrightarrow> [x = y] (mod CHAR('a))" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
754 |
proof (induction x y rule: linorder_wlog) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
755 |
case (le x y) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
756 |
define z where "z = y - x" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
757 |
have [simp]: "y = x + z" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
758 |
using le by (auto simp: z_def) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
759 |
have "(CHAR('a) dvd z) = [x = x + z] (mod CHAR('a))" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
760 |
by (metis \<open>y = x + z\<close> cong_def le mod_eq_dvd_iff_nat z_def) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
761 |
thus ?case |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
762 |
by (simp add: of_nat_eq_0_iff_char_dvd) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
763 |
qed (simp add: eq_commute cong_sym_eq) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
764 |
|
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
765 |
lemma (in ring_1) of_int_eq_iff_cong_CHAR: |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
766 |
"of_int x = (of_int y :: 'a) \<longleftrightarrow> [x = y] (mod int CHAR('a))" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
767 |
proof - |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
768 |
have "of_int x = (of_int y :: 'a) \<longleftrightarrow> of_int (x - y) = (0 :: 'a)" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
769 |
by auto |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
770 |
also have "\<dots> \<longleftrightarrow> (int CHAR('a) dvd x - y)" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
771 |
by (rule of_int_eq_0_iff_char_dvd) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
772 |
also have "\<dots> \<longleftrightarrow> [x = y] (mod int CHAR('a))" |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
773 |
by (simp add: cong_iff_dvd_diff) |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
774 |
finally show ?thesis . |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
775 |
qed |
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
76231
diff
changeset
|
776 |
|
82080
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
777 |
text \<open>Thanks to Manuel Eberl\<close> |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
778 |
lemma prime_cong_4_nat_cases [consumes 1, case_names 2 cong_1 cong_3]: |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
779 |
assumes "prime (p :: nat)" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
780 |
obtains "p = 2" | "[p = 1] (mod 4)" | "[p = 3] (mod 4)" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
781 |
proof - |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
782 |
have "[p = 2] (mod 4) \<longleftrightarrow> p = 2" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
783 |
proof |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
784 |
assume "[p = 2] (mod 4)" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
785 |
hence "p mod 4 = 2" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
786 |
by (auto simp: cong_def) |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
787 |
hence "even p" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
788 |
by (simp add: even_even_mod_4_iff) |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
789 |
with assms show "p = 2" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
790 |
unfolding prime_nat_iff by force |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
791 |
qed auto |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
792 |
moreover have "[p \<noteq> 0] (mod 4)" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
793 |
proof |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
794 |
assume "[p = 0] (mod 4)" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
795 |
hence "4 dvd p" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
796 |
by (auto simp: cong_0_iff) |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
797 |
with assms have "p = 4" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
798 |
by (subst (asm) prime_nat_iff) auto |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
799 |
thus False |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
800 |
using assms by simp |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
801 |
qed |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
802 |
ultimately consider "[p = 3] (mod 4)" | "[p = 1] (mod 4)" | "p = 2" |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
803 |
by (fastforce simp: cong_def) |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
804 |
thus ?thesis |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
805 |
using that by metis |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
806 |
qed |
0aa2d1c132b2
A couple of theorems proved by Manuel Eberl from his AFP entry Sum_Of_Squares_Count
paulson <lp15@cam.ac.uk>
parents:
81142
diff
changeset
|
807 |
|
31719 | 808 |
end |