Skip to content

Commit a764cea

Browse files
committed
fix
1 parent 3781ef4 commit a764cea

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

Mathlib/Algebra/CharP/Basic.lean

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,9 @@ end AddMonoidWithOne
207207

208208
section CommRing
209209

210-
#adaptation_note
211-
/-- 2025-04-19 `IsCharP` has `n` as an outparam, but `CharP` does not.
212-
Remove after https://github.com/leanprover-community/mathlib4/pull/24216 is merged.
213-
-/
214-
set_option synthInstance.checkSynthOrder false in
215210
instance (α : Type*) [CommRing α] (n : ℕ) [CharP α n] : Lean.Grind.IsCharP α n where
216-
ofNat_eq_zero_iff m := by
217-
rw [CommRing.toGrindCommRing_ofNat]
218-
simpa [← Nat.dvd_iff_mod_eq_zero] using CharP.cast_eq_zero_iff α n m
211+
ofNat_ext_iff {a b} := by
212+
rw [Lean.Grind.Semiring.ofNat_eq_natCast, Lean.Grind.Semiring.ofNat_eq_natCast]
213+
exact CharP.cast_eq_iff_mod_eq α n
219214

220215
end CommRing

Mathlib/Algebra/CharP/Defs.lean

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ lemma congr {q : ℕ} (h : p = q) : CharP R q := h ▸ ‹CharP R p›
5757

5858
@[simp] lemma cast_eq_zero : (p : R) = 0 := (cast_eq_zero_iff R p p).2 dvd_rfl
5959

60+
lemma cast_eq_mod (k : ℕ) : (k : R) = (k % p : ℕ) :=
61+
have (a : ℕ) : ((p * a : ℕ) : R) = 0 := by
62+
rw [CharP.cast_eq_zero_iff R p]
63+
exact Nat.dvd_mul_right p a
64+
calc
65+
(k : R) = ↑(k % p + p * (k / p)) := by rw [Nat.mod_add_div]
66+
_ = ↑(k % p) := by simp [cast_eq_zero, this]
67+
68+
lemma cast_eq_iff_mod_eq [IsLeftCancelAdd R] : (a:R) = (b:R) ↔ a % p = b % p := by
69+
wlog hle : a ≤ b
70+
· simpa only [eq_comm] using (this _ _ (lt_of_not_ge hle).le)
71+
obtain ⟨c, rfl⟩ := Nat.le.dest hle
72+
rw [Nat.cast_add, left_eq_add, CharP.cast_eq_zero_iff R p]
73+
constructor
74+
· simp +contextual [Nat.add_mod, Nat.dvd_iff_mod_eq_zero]
75+
intro h
76+
have := Nat.sub_mod_eq_zero_of_mod_eq h.symm
77+
simpa [Nat.dvd_iff_mod_eq_zero] using this
78+
6079
-- TODO: This lemma needs to be `@[simp]` for confluence in the presence of `CharP.cast_eq_zero` and
6180
-- `Nat.cast_ofNat`, but with `no_index` on its entire LHS, it matches literally every expression so
6281
-- is too expensive. If https://github.com/leanprover/lean4/issues/2867 is fixed in a performant way, this can be made `@[simp]`.
@@ -178,11 +197,6 @@ section
178197

179198
variable [NonAssocRing R]
180199

181-
lemma cast_eq_mod (p : ℕ) [CharP R p] (k : ℕ) : (k : R) = (k % p : ℕ) :=
182-
calc
183-
(k : R) = ↑(k % p + p * (k / p)) := by rw [Nat.mod_add_div]
184-
_ = ↑(k % p) := by simp [cast_eq_zero]
185-
186200
lemma ringChar_zero_iff_CharZero : ringChar R = 0 ↔ CharZero R := by
187201
rw [ringChar.eq_iff, charP_zero_iff_charZero]
188202

0 commit comments

Comments
 (0)