@@ -36,6 +36,8 @@ open Function ZMod
3636
3737namespace ZMod
3838
39+ instance : IsDomain (ZMod 0 ) := inferInstanceAs (IsDomain ℤ)
40+
3941/-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/
4042def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n
4143 | 0 , h => (h.ne _ rfl).elim
@@ -141,6 +143,12 @@ theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 :=
141143theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1 )) = 0 := by
142144 rw [← Nat.cast_add_one, natCast_self (n + 1 )]
143145
146+ lemma natCast_pow_eq_zero_of_le (p : ℕ) {m n : ℕ} (h : n ≤ m) :
147+ (p ^ m : ZMod (p ^ n)) = 0 := by
148+ obtain ⟨q, rfl⟩ := Nat.exists_eq_add_of_le h
149+ rw [pow_add, ← Nat.cast_pow]
150+ simp
151+
144152section UniversalProperty
145153
146154variable {n : ℕ} {R : Type *}
@@ -340,6 +348,9 @@ theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k :=
340348theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k :=
341349 map_intCast (castHom h R) k
342350
351+ theorem castHom_surjective (h : m ∣ n) : Function.Surjective (castHom h (ZMod m)) :=
352+ fun a ↦ by obtain ⟨a, rfl⟩ := intCast_surjective a; exact ⟨a, map_intCast ..⟩
353+
343354end CharDvd
344355
345356section CharEq
@@ -812,6 +823,10 @@ theorem inv_mul_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a⁻¹ * a = 1 :
812823protected theorem inv_eq_of_mul_eq_one (n : ℕ) (a b : ZMod n) (h : a * b = 1 ) : a⁻¹ = b :=
813824 left_inv_eq_right_inv (inv_mul_of_unit a ⟨⟨a, b, h, mul_comm a b ▸ h⟩, rfl⟩) h
814825
826+ @[simp]
827+ theorem inv_neg_one (n : ℕ) : (-1 : ZMod n)⁻¹ = -1 :=
828+ ZMod.inv_eq_of_mul_eq_one n (-1 ) (-1 ) (by simp)
829+
815830lemma inv_mul_eq_one_of_isUnit {n : ℕ} {a : ZMod n} (ha : IsUnit a) (b : ZMod n) :
816831 a⁻¹ * b = 1 ↔ a = b := by
817832 -- ideally, this would be `ha.inv_mul_eq_one`, but `ZMod n` is not a `DivisionMonoid`...
0 commit comments