equal
deleted
inserted
replaced
152 lemma cong_minus_minus_iff: |
152 lemma cong_minus_minus_iff: |
153 "[- b = - c] (mod a) \<longleftrightarrow> [b = c] (mod a)" |
153 "[- b = - c] (mod a) \<longleftrightarrow> [b = c] (mod a)" |
154 using cong_diff_iff_cong_0 [of b c a] cong_diff_iff_cong_0 [of "- b" "- c" a] |
154 using cong_diff_iff_cong_0 [of b c a] cong_diff_iff_cong_0 [of "- b" "- c" a] |
155 by (simp add: cong_0_iff dvd_diff_commute) |
155 by (simp add: cong_0_iff dvd_diff_commute) |
156 |
156 |
157 lemma cong_modulus_minus_iff: "[b = c] (mod - a) \<longleftrightarrow> [b = c] (mod a)" |
157 lemma cong_modulus_minus_iff: |
|
158 "[b = c] (mod - a) \<longleftrightarrow> [b = c] (mod a)" |
158 using cong_diff_iff_cong_0 [of b c a] cong_diff_iff_cong_0 [of b c " -a"] |
159 using cong_diff_iff_cong_0 [of b c a] cong_diff_iff_cong_0 [of b c " -a"] |
159 by (simp add: cong_0_iff) |
160 by (simp add: cong_0_iff) |
|
161 |
|
162 lemma cong_iff_dvd_diff: |
|
163 "[a = b] (mod m) \<longleftrightarrow> m dvd (a - b)" |
|
164 by (simp add: cong_0_iff [symmetric] cong_diff_iff_cong_0) |
|
165 |
|
166 lemma cong_iff_lin: |
|
167 "[a = b] (mod m) \<longleftrightarrow> (\<exists>k. b = a + m * k)" (is "?P \<longleftrightarrow> ?Q") |
|
168 proof - |
|
169 have "?P \<longleftrightarrow> m dvd b - a" |
|
170 by (simp add: cong_iff_dvd_diff dvd_diff_commute) |
|
171 also have "\<dots> \<longleftrightarrow> ?Q" |
|
172 by (auto simp add: algebra_simps elim!: dvdE) |
|
173 finally show ?thesis |
|
174 by simp |
|
175 qed |
160 |
176 |
161 end |
177 end |
162 |
178 |
163 |
179 |
164 subsection \<open>Congruences on @{typ nat} and @{typ int}\<close> |
180 subsection \<open>Congruences on @{typ nat} and @{typ int}\<close> |
213 by (simp only: cong_0_iff [symmetric]) |
229 by (simp only: cong_0_iff [symmetric]) |
214 |
230 |
215 lemma cong_altdef_int: |
231 lemma cong_altdef_int: |
216 "[a = b] (mod m) \<longleftrightarrow> m dvd (a - b)" |
232 "[a = b] (mod m) \<longleftrightarrow> m dvd (a - b)" |
217 for a b :: int |
233 for a b :: int |
218 by (simp add: cong_0_iff [symmetric] cong_diff_iff_cong_0) |
234 by (fact cong_iff_dvd_diff) |
219 |
235 |
220 lemma cong_abs_int [simp]: "[x = y] (mod \<bar>m\<bar>) \<longleftrightarrow> [x = y] (mod m)" |
236 lemma cong_abs_int [simp]: "[x = y] (mod \<bar>m\<bar>) \<longleftrightarrow> [x = y] (mod m)" |
221 for x y :: int |
237 for x y :: int |
222 by (simp add: cong_altdef_int) |
238 by (simp add: cong_iff_dvd_diff) |
223 |
239 |
224 lemma cong_square_int: |
240 lemma cong_square_int: |
225 "prime p \<Longrightarrow> 0 < a \<Longrightarrow> [a * a = 1] (mod p) \<Longrightarrow> [a = 1] (mod p) \<or> [a = - 1] (mod p)" |
241 "prime p \<Longrightarrow> 0 < a \<Longrightarrow> [a * a = 1] (mod p) \<Longrightarrow> [a = 1] (mod p) \<or> [a = - 1] (mod p)" |
226 for a :: int |
242 for a :: int |
227 apply (simp only: cong_altdef_int) |
243 apply (simp only: cong_iff_dvd_diff) |
228 apply (subst prime_dvd_mult_eq_int [symmetric], assumption) |
244 apply (subst prime_dvd_mult_eq_int [symmetric], assumption) |
229 apply (auto simp add: field_simps) |
245 apply (auto simp add: field_simps) |
230 done |
246 done |
231 |
247 |
232 lemma cong_mult_rcancel_int: |
248 lemma cong_mult_rcancel_int: |
288 for a m :: int |
304 for a m :: int |
289 by (auto simp: cong_def) (metis mod_mod_trivial pos_mod_conj) |
305 by (auto simp: cong_def) (metis mod_mod_trivial pos_mod_conj) |
290 |
306 |
291 lemma cong_iff_lin_int: "[a = b] (mod m) \<longleftrightarrow> (\<exists>k. b = a + m * k)" |
307 lemma cong_iff_lin_int: "[a = b] (mod m) \<longleftrightarrow> (\<exists>k. b = a + m * k)" |
292 for a b :: int |
308 for a b :: int |
293 by (auto simp add: cong_altdef_int algebra_simps elim!: dvdE) |
309 by (fact cong_iff_lin) |
294 (simp add: distrib_right [symmetric] add_eq_0_iff) |
|
295 |
310 |
296 lemma cong_iff_lin_nat: "([a = b] (mod m)) \<longleftrightarrow> (\<exists>k1 k2. b + k1 * m = a + k2 * m)" |
311 lemma cong_iff_lin_nat: "([a = b] (mod m)) \<longleftrightarrow> (\<exists>k1 k2. b + k1 * m = a + k2 * m)" |
297 (is "?lhs = ?rhs") |
312 (is "?lhs = ?rhs") |
298 for a b :: nat |
313 for a b :: nat |
299 proof |
314 proof |
338 for a b :: int |
353 for a b :: int |
339 by simp |
354 by simp |
340 |
355 |
341 lemma cong_minus_int [iff]: "[a = b] (mod - m) \<longleftrightarrow> [a = b] (mod m)" |
356 lemma cong_minus_int [iff]: "[a = b] (mod - m) \<longleftrightarrow> [a = b] (mod m)" |
342 for a b :: int |
357 for a b :: int |
343 by (metis cong_iff_lin_int minus_equation_iff mult_minus_left mult_minus_right) |
358 by (fact cong_modulus_minus_iff) |
344 |
359 |
345 lemma cong_add_lcancel_nat: "[a + x = a + y] (mod n) \<longleftrightarrow> [x = y] (mod n)" |
360 lemma cong_add_lcancel_nat: "[a + x = a + y] (mod n) \<longleftrightarrow> [x = y] (mod n)" |
346 for a x y :: nat |
361 for a x y :: nat |
347 by (simp add: cong_iff_lin_nat) |
362 by (simp add: cong_iff_lin_nat) |
348 |
363 |