Skip to content

Commit 4ca9758

Browse files
sgouezelReemMelamed
authored andcommitted
chore: fix non-reducible diamonds around scalar multiplication in RingCon (leanprover-community#40704)
The following fails before the PR, succeeds after it. ``` example {R : Type*} [Ring R] (c : RingCon R) : (RingCon.hasZSMul c : SMul ℤ c.Quotient) = RingCon.instSMulQuotient c := by with_reducible_and_instances rfl -- fails ``` Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
1 parent 1ded3d6 commit 4ca9758

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

Mathlib/RingTheory/Congruence/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ variable [SMul α R] [IsScalarTower α R R]
5252
variable [SMul β R] [IsScalarTower β R R]
5353
variable (c : RingCon R)
5454

55-
instance : SMul α c.Quotient := inferInstanceAs (SMul α c.toCon.Quotient)
55+
instance : SMul α c.Quotient := ⟨c.smulAux (Con.smul c.toCon)⟩
5656

5757
@[simp, norm_cast]
5858
theorem coe_smul (a : α) (x : R) : (↑(a • x) : c.Quotient) = a • (x : c.Quotient) :=

Mathlib/RingTheory/Congruence/Defs.lean

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ theorem coe_one : (↑(1 : R) : c.Quotient) = 1 :=
252252

253253
end One
254254

255+
/-- A function used to define scalar actions on `RingCon.Quotient`. To make sure such actions coming
256+
from different sources are reducibly defeq, they should all go through this function. -/
257+
def smulAux [Add R] [Mul R] {α : Type*} [SMul α R]
258+
(c : RingCon R) (h : ∀ (a : α) (x y : R), c x y → c (a • x) (a • y))
259+
(a : α) (x : c.Quotient) : c.Quotient :=
260+
Quotient.map' (a • ·) (h a) x
261+
255262
section NegSubZSMul
256263

257264
variable [AddGroup R] [Mul R] (c : RingCon R)
@@ -268,7 +275,7 @@ instance : Sub c.Quotient := inferInstanceAs (Sub c.toAddCon.Quotient)
268275
theorem coe_sub (x y : R) : (↑(x - y) : c.Quotient) = x - y :=
269276
rfl
270277

271-
instance hasZSMul : SMul ℤ c.Quotient := inferInstanceAs (SMul ℤ c.toAddCon.Quotient)
278+
instance hasZSMul : SMul ℤ c.Quotient := ⟨c.smulAux (RingCon.zsmul c)⟩
272279

273280
@[simp, norm_cast]
274281
theorem coe_zsmul (z : ℤ) (x : R) : (↑(z • x) : c.Quotient) = z • (x : c.Quotient) :=
@@ -280,7 +287,7 @@ section NSMul
280287

281288
variable [AddMonoid R] [Mul R] (c : RingCon R)
282289

283-
instance hasNSMul : SMul ℕ c.Quotient := inferInstanceAs (SMul ℕ c.toAddCon.Quotient)
290+
instance hasNSMul : SMul ℕ c.Quotient := ⟨c.smulAux (RingCon.nsmul c)⟩
284291

285292
@[simp, norm_cast]
286293
theorem coe_nsmul (n : ℕ) (x : R) : (↑(n • x) : c.Quotient) = n • (x : c.Quotient) :=
@@ -353,14 +360,16 @@ instance [AddCommMagma R] [Mul R] (c : RingCon R) : AddCommMagma c.Quotient :=
353360
instance [AddCommSemigroup R] [Mul R] (c : RingCon R) : AddCommSemigroup c.Quotient :=
354361
inferInstanceAs <| AddCommSemigroup c.toAddCon.Quotient
355362

356-
instance [AddMonoid R] [Mul R] (c : RingCon R) : AddMonoid c.Quotient :=
357-
inferInstanceAs <| AddMonoid c.toAddCon.Quotient
363+
instance [AddMonoid R] [Mul R] (c : RingCon R) : AddMonoid c.Quotient where
364+
nsmul n x := n • x
365+
__ : AddMonoid c.Quotient := inferInstanceAs <| AddMonoid c.toAddCon.Quotient
358366

359367
instance [AddCommMonoid R] [Mul R] (c : RingCon R) : AddCommMonoid c.Quotient :=
360368
inferInstanceAs <| AddCommMonoid c.toAddCon.Quotient
361369

362-
instance [AddGroup R] [Mul R] (c : RingCon R) : AddGroup c.Quotient :=
363-
inferInstanceAs <| AddGroup c.toAddCon.Quotient
370+
instance [AddGroup R] [Mul R] (c : RingCon R) : AddGroup c.Quotient where
371+
zsmul n x := n • x
372+
__ : AddGroup c.Quotient := inferInstanceAs <| AddGroup c.toAddCon.Quotient
364373

365374
instance [AddCommGroup R] [Mul R] (c : RingCon R) : AddCommGroup c.Quotient :=
366375
inferInstanceAs <| AddCommGroup c.toAddCon.Quotient

0 commit comments

Comments
 (0)