@@ -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
179198variable [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-
186200lemma ringChar_zero_iff_CharZero : ringChar R = 0 ↔ CharZero R := by
187201 rw [ringChar.eq_iff, charP_zero_iff_charZero]
188202
0 commit comments