Skip to content

Commit a7b5058

Browse files
sgouezelReemMelamed
authored andcommitted
chore: move generic SMul definition before AddMonoid or AddGroup instances to make sure they can use it (leanprover-community#40706)
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
1 parent 4ca9758 commit a7b5058

5 files changed

Lines changed: 42 additions & 25 deletions

File tree

Mathlib/Algebra/Quaternion.lean

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,14 @@ variable {S T R : Type*} [CommRing R] (r x y : R) (a b : ℍ[R])
723723

724724
instance : CoeTC R ℍ[R] := ⟨coe⟩
725725

726-
instance instRing : Ring ℍ[R] := inferInstanceAs <| Ring ℍ[R,-1,0,-1]
726+
instance [SMul S R] : SMul S ℍ[R] := inferInstanceAs <| SMul S ℍ[R,-1,0,-1]
727727

728-
instance : Inhabited ℍ[R] := inferInstanceAs <| Inhabited ℍ[R,-1,0,-1]
728+
instance instRing : Ring ℍ[R] where
729+
nsmul := letI := Quaternion.instSMul (S := ℕ) (R := R); (· • ·)
730+
zsmul := letI := Quaternion.instSMul (S := ℤ) (R := R); (· • ·)
731+
__ : Ring ℍ[R] := inferInstanceAs <| Ring ℍ[R,-1,0,-1]
729732

730-
instance [SMul S R] : SMul S ℍ[R] := inferInstanceAs <| SMul S ℍ[R,-1,0,-1]
733+
instance : Inhabited ℍ[R] := inferInstanceAs <| Inhabited ℍ[R,-1,0,-1]
731734

732735
instance [SMul S T] [SMul S R] [SMul T R] [IsScalarTower S T R] : IsScalarTower S T ℍ[R] :=
733736
inferInstanceAs <| IsScalarTower S T ℍ[R,-1,0,-1]

Mathlib/Algebra/TrivSqZeroExt/Basic.lean

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,16 @@ instance addSemigroup [AddSemigroup R] [AddSemigroup M] : AddSemigroup (tsze R M
197197
instance addZeroClass [AddZeroClass R] [AddZeroClass M] : AddZeroClass (tsze R M) :=
198198
inferInstanceAs <| AddZeroClass (R × M)
199199

200-
instance addMonoid [AddMonoid R] [AddMonoid M] : AddMonoid (tsze R M) :=
201-
inferInstanceAs <| AddMonoid (R × M)
200+
instance smul [SMul S R] [SMul S M] : SMul S (tsze R M) :=
201+
inferInstanceAs <| SMul S (R × M)
202+
203+
instance addMonoid [AddMonoid R] [AddMonoid M] : AddMonoid (tsze R M) where
204+
nsmul := letI := smul (S := ℕ) (R := R) (M := M); (· • ·)
205+
__ : AddMonoid (tsze R M) := inferInstanceAs <| AddMonoid (R × M)
202206

203-
instance addGroup [AddGroup R] [AddGroup M] : AddGroup (tsze R M) :=
204-
inferInstanceAs <| AddGroup (R × M)
207+
instance addGroup [AddGroup R] [AddGroup M] : AddGroup (tsze R M) where
208+
zsmul := letI := smul (S := ℤ) (R := R) (M := M); (· • ·)
209+
__ : AddGroup (tsze R M) := inferInstanceAs <| AddGroup (R × M)
205210

206211
instance addCommSemigroup [AddCommSemigroup R] [AddCommSemigroup M] : AddCommSemigroup (tsze R M) :=
207212
inferInstanceAs <| AddCommSemigroup (R × M)
@@ -212,9 +217,6 @@ instance addCommMonoid [AddCommMonoid R] [AddCommMonoid M] : AddCommMonoid (tsze
212217
instance addCommGroup [AddCommGroup R] [AddCommGroup M] : AddCommGroup (tsze R M) :=
213218
inferInstanceAs <| AddCommGroup (R × M)
214219

215-
instance smul [SMul S R] [SMul S M] : SMul S (tsze R M) :=
216-
inferInstanceAs <| SMul S (R × M)
217-
218220
instance isScalarTower [SMul T R] [SMul T M] [SMul S R] [SMul S M] [SMul T S]
219221
[IsScalarTower T S R] [IsScalarTower T S M] : IsScalarTower T S (tsze R M) :=
220222
inferInstanceAs <| IsScalarTower T S (R × M)

Mathlib/Analysis/CStarAlgebra/CStarMatrix.lean

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ instance instZero [Zero A] : Zero (CStarMatrix m n A) :=
141141
instance instAddZeroClass [AddZeroClass A] : AddZeroClass (CStarMatrix m n A) :=
142142
inferInstanceAs <| AddZeroClass (Matrix m n A)
143143

144-
instance instAddMonoid [AddMonoid A] : AddMonoid (CStarMatrix m n A) :=
145-
inferInstanceAs <| AddMonoid (Matrix m n A)
144+
instance instSMul [SMul R A] : SMul R (CStarMatrix m n A) :=
145+
inferInstanceAs <| SMul R (Matrix m n A)
146+
147+
instance instAddMonoid [AddMonoid A] : AddMonoid (CStarMatrix m n A) where
148+
nsmul := letI := instSMul (R := ℕ) (A := A) (m := m) (n := n); (· • · )
149+
__ : AddMonoid (CStarMatrix m n A) := inferInstanceAs <| AddMonoid (Matrix m n A)
146150

147151
instance instAddCommMonoid [AddCommMonoid A] : AddCommMonoid (CStarMatrix m n A) :=
148152
inferInstanceAs <| AddCommMonoid (Matrix m n A)
@@ -153,8 +157,9 @@ instance instNeg [Neg A] : Neg (CStarMatrix m n A) :=
153157
instance instSub [Sub A] : Sub (CStarMatrix m n A) :=
154158
inferInstanceAs <| Sub (Matrix m n A)
155159

156-
instance instAddGroup [AddGroup A] : AddGroup (CStarMatrix m n A) :=
157-
inferInstanceAs <| AddGroup (Matrix m n A)
160+
instance instAddGroup [AddGroup A] : AddGroup (CStarMatrix m n A) where
161+
zsmul := letI := instSMul (R := ℤ) (A := A) (m := m) (n := n); (· • · )
162+
__ : AddGroup (CStarMatrix m n A) := inferInstanceAs <| AddGroup (Matrix m n A)
158163

159164
instance instAddCommGroup [AddCommGroup A] : AddCommGroup (CStarMatrix m n A) :=
160165
inferInstanceAs <| AddCommGroup (Matrix m n A)
@@ -168,9 +173,6 @@ instance instSubsingleton [Subsingleton A] : Subsingleton (CStarMatrix m n A) :=
168173
instance instNontrivial [Nonempty m] [Nonempty n] [Nontrivial A] : Nontrivial (CStarMatrix m n A) :=
169174
inferInstanceAs <| Nontrivial (Matrix m n A)
170175

171-
instance instSMul [SMul R A] : SMul R (CStarMatrix m n A) :=
172-
inferInstanceAs <| SMul R (Matrix m n A)
173-
174176
instance instSMulCommClass [SMul R A] [SMul S A] [SMulCommClass R S A] :
175177
SMulCommClass R S (CStarMatrix m n A) :=
176178
inferInstanceAs <| SMulCommClass R S (Matrix m n A)

Mathlib/FieldTheory/IsAlgClosed/AlgebraicClosure.lean

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,16 @@ def AlgebraicClosure : Type u :=
129129

130130
namespace AlgebraicClosure
131131

132-
deriving instance CommRing, Inhabited for AlgebraicClosure
132+
deriving instance Inhabited for AlgebraicClosure
133133

134134
instance {S : Type*} [DistribSMul S k] [IsScalarTower S k k] : SMul S (AlgebraicClosure k) :=
135135
inferInstanceAs <| SMul S (_ ⧸ _)
136136

137+
instance : CommRing (AlgebraicClosure k) where
138+
nsmul := letI := AlgebraicClosure.instSMulOfIsScalarTower k (S := ℕ); (· • · )
139+
zsmul := letI := AlgebraicClosure.instSMulOfIsScalarTower k (S := ℤ); (· • · )
140+
__ : CommRing (AlgebraicClosure k) := inferInstanceAs <| CommRing (_ ⧸ _)
141+
137142
instance instAlgebra {R : Type*} [CommSemiring R] [Algebra R k] : Algebra R (AlgebraicClosure k) :=
138143
inferInstanceAs <| Algebra R (_ ⧸ _)
139144

Mathlib/RingTheory/AdjoinRoot.lean

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ section CommRing
6868

6969
variable [CommRing R] (f g : R[X])
7070

71-
deriving instance CommRing, Inhabited for AdjoinRoot
71+
deriving instance Inhabited for AdjoinRoot
72+
73+
instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) :=
74+
inferInstanceAs <| SMul S (_ ⧸ _)
75+
76+
instance : CommRing (AdjoinRoot f) where
77+
nsmul := letI := instSMulAdjoinRoot (S := ℕ) (R := R); (· • ·)
78+
zsmul := letI := instSMulAdjoinRoot (S := ℤ) (R := R); (· • ·)
79+
__ : CommRing (AdjoinRoot f) := inferInstanceAs <| CommRing (_ ⧸ _)
80+
81+
instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) :=
82+
inferInstanceAs <| DistribSMul S (_ ⧸ _)
7283

7384
instance : DecidableEq (AdjoinRoot f) :=
7485
Classical.decEq _
@@ -92,12 +103,6 @@ theorem induction_on {C : AdjoinRoot f → Prop} (x : AdjoinRoot f) (ih : ∀ p
92103
def of : R →+* AdjoinRoot f :=
93104
(mk f).comp C
94105

95-
instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) :=
96-
inferInstanceAs <| SMul S (_ ⧸ _)
97-
98-
instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) :=
99-
inferInstanceAs <| DistribSMul S (_ ⧸ _)
100-
101106
@[simp]
102107
theorem smul_mk [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R[X]) :
103108
a • mk f x = mk f (a • x) :=

0 commit comments

Comments
 (0)