Skip to content

Commit

Permalink
fix: coercions in ZMod.coe_add_eq_ite (#5981)
Browse files Browse the repository at this point in the history
The change in behaviour of coercions in mathlib4 meant that this lemma was translated incorrectly (into a much simpler statement).
  • Loading branch information
kbuzzard committed Jul 18, 2023
1 parent 69bb9bc commit 58e967b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Mathlib/Data/ZMod/Basic.lean
Expand Up @@ -266,14 +266,16 @@ theorem int_cast_cast (i : ZMod n) : ((i : ℤ) : R) = i :=
#align zmod.int_cast_cast ZMod.int_cast_cast

theorem coe_add_eq_ite {n : ℕ} (a b : ZMod n) :
(↑(a + b) : ℤ) = if (n : ℤ) ≤ a + b then a + b - n else a + b := by
cases n
· simp
simp only [Fin.val_add_eq_ite, ← Int.ofNat_add, ← Int.ofNat_succ, Int.ofNat_le]
(↑(a + b) : ℤ) = if (n : ℤ) ≤ a + b then (a : ℤ) + b - n else a + b := by
cases' n with n
· simp; rfl
change Fin (n + 1) at a b
change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
simp only [Fin.val_add_eq_ite, Int.ofNat_succ, Int.ofNat_le]
norm_cast
split_ifs with h
· norm_cast
· rw [Nat.cast_sub h]
congr
simp
· rfl
#align zmod.coe_add_eq_ite ZMod.coe_add_eq_ite

Expand Down

0 comments on commit 58e967b

Please sign in to comment.