@@ -6,9 +6,24 @@ Authors: Chris Hughes
6
6
import data.nat.modeq
7
7
import tactic.ring
8
8
9
+ /-!
10
+
11
+ # Congruences modulo an integer
12
+
13
+ This file defines the equivalence relation `a ≡ b [ZMOD n]` on the integers, similarly to how
14
+ `data.nat.modeq` defines them for the natural numbers. The notation is short for `modeq a b n`,
15
+ which is defined to be `a % n = b % n` for integer `a b n`.
16
+
17
+ ## Tags
18
+
19
+ modeq, congruence, mod, MOD, modulo, integers
20
+
21
+ -/
22
+
9
23
namespace int
10
24
11
25
/-- `a ≡ b [ZMOD n]` when `a % n = b % n`. -/
26
+ @[derive decidable]
12
27
def modeq (n a b : ℤ) := a % n = b % n
13
28
14
29
notation a ` ≡ `:50 b ` [ZMOD `:50 n `]`:0 := modeq n a b
@@ -25,8 +40,6 @@ variables {n m a b c d : ℤ}
25
40
lemma coe_nat_modeq_iff {a b n : ℕ} : a ≡ b [ZMOD n] ↔ a ≡ b [MOD n] :=
26
41
by unfold modeq nat.modeq; rw ← int.coe_nat_eq_coe_nat_iff; simp [int.coe_nat_mod]
27
42
28
- instance : decidable (a ≡ b [ZMOD n]) := by unfold modeq; apply_instance
29
-
30
43
theorem modeq_zero_iff : a ≡ 0 [ZMOD n] ↔ n ∣ a :=
31
44
by rw [modeq, zero_mod, dvd_iff_mod_eq_zero]
32
45
@@ -106,10 +119,9 @@ calc a + n*c ≡ b + n*c [ZMOD n] : int.modeq.modeq_add ha (int.modeq.refl _)
106
119
(int.modeq.modeq_zero_iff.2 (dvd_mul_right _ _))
107
120
... ≡ b [ZMOD n] : by simp
108
121
109
- open nat
110
- lemma mod_coprime {a b : ℕ} (hab : coprime a b) : ∃ y : ℤ, a * y ≡ 1 [ZMOD b] :=
122
+ lemma mod_coprime {a b : ℕ} (hab : nat.coprime a b) : ∃ y : ℤ, a * y ≡ 1 [ZMOD b] :=
111
123
⟨ nat.gcd_a a b,
112
- have hgcd : nat.gcd a b = 1 , from coprime.gcd_eq_one hab,
124
+ have hgcd : nat.gcd a b = 1 , from nat. coprime.gcd_eq_one hab,
113
125
calc
114
126
↑a * nat.gcd_a a b ≡ ↑a * nat.gcd_a a b + ↑b * nat.gcd_b a b [ZMOD ↑b] : int.modeq.symm $
115
127
modeq_add_fac _ $ int.modeq.refl _
0 commit comments