Skip to content

Commit 515b108

Browse files
committed
refactor(Data/ZMod): move coe_int_isUnit_iff_isCoprime to ZMod.Units (#38340)
Move `ZMod.coe_int_isUnit_iff_isCoprime` from `Mathlib.Data.ZMod.Coprime` to `Mathlib.Data.ZMod.Units`, where it more naturally belongs as a statement about units in `ZMod`. The proof is rewritten to only use tools available in `Mathlib.Data.ZMod.Units`, avoiding the dependency on `Mathlib.Algebra.EuclideanDomain.Int`. This is motivated by the desire to use `coe_int_isUnit_iff_isCoprime` without the overhead of importing `Mathlib.Data.ZMod.Coprime` (see #38339 for a use case).
1 parent 72a0444 commit 515b108

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

Mathlib/Data/ZMod/Coprime.lean

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Authors: Michael Stoll
55
-/
66
module
77

8-
public import Mathlib.Algebra.EuclideanDomain.Int
98
public import Mathlib.Data.Nat.Prime.Int
109
public import Mathlib.Data.ZMod.Basic
1110
public import Mathlib.RingTheory.Int.Basic
@@ -24,12 +23,6 @@ assert_not_exists TwoSidedIdeal
2423

2524
namespace ZMod
2625

27-
set_option backward.isDefEq.respectTransparency false in
28-
theorem coe_int_isUnit_iff_isCoprime (n : ℤ) (m : ℕ) :
29-
IsUnit (n : ZMod m) ↔ IsCoprime (m : ℤ) n := by
30-
rw [Int.isCoprime_iff_nat_coprime, Nat.coprime_comm, ← isUnit_iff_coprime, Associated.isUnit_iff]
31-
simpa only [eq_intCast, Int.cast_natCast] using (Int.associated_natAbs _).map (Int.castRingHom _)
32-
3326
/-- If `p` is a prime and `a` is an integer, then `a : ZMod p` is zero if and only if
3427
`gcd a p ≠ 1`. -/
3528
theorem eq_zero_iff_gcd_ne_one {a : ℤ} {p : ℕ} [pp : Fact p.Prime] :

Mathlib/Data/ZMod/Units.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,17 @@ theorem isUnit_inv {m : ℕ} {n : ℤ} (h : IsUnit (n : ZMod m)) :
153153
rw [isUnit_iff_exists]
154154
exact ⟨n, inv_mul_of_unit _ h, mul_inv_of_unit _ h⟩
155155

156+
theorem coe_int_isUnit_iff_isCoprime (n : ℤ) (m : ℕ) :
157+
IsUnit (n : ZMod m) ↔ IsCoprime (m : ℤ) n := by
158+
refine ⟨fun h ↦ ?_, fun h ↦ ⟨unitOfIsCoprime n (isCoprime_comm.mp h), by simp⟩⟩
159+
obtain rfl | hm := eq_or_ne m 0
160+
· rw [Nat.cast_zero, isCoprime_zero_left]
161+
exact_mod_cast h
162+
· have : NeZero m := ⟨hm⟩
163+
obtain ⟨u, hu⟩ := h
164+
have h_coprime := val_coe_unit_coprime u
165+
rw [hu, Nat.coprime_iff_gcd_eq_one, ← Int.gcd_natCast_natCast,
166+
val_intCast, Int.gcd_emod] at h_coprime
167+
rwa [isCoprime_comm, Int.isCoprime_iff_gcd_eq_one]
168+
156169
end ZMod

0 commit comments

Comments
 (0)