Skip to content

Commit 15f8632

Browse files
committed
chore: avoid dsimp; infer_instance (leanprover-community#37288)
This PR cleans up a bunch of instances using `inferInstanceAs` and `deriving`. It seems that when in a `noncomputable section`, derived instances will always be `noncomputable`, while manual instances can still end up being computable. So this PR also adds some now transitively required `noncomputable` annotations.
1 parent 3c02b3a commit 15f8632

27 files changed

Lines changed: 100 additions & 179 deletions

File tree

Mathlib/Algebra/Category/ModuleCat/Basic.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,9 @@ section
539539

540540
variable {A : AddCommGrpCat} (φ : R →+* End A)
541541

542-
instance : AddCommGroup (mkOfSMul' φ) := by
543-
dsimp only [mkOfSMul']
544-
infer_instance
542+
instance : AddCommGroup (mkOfSMul' φ) :=
543+
inferInstanceAs <| AddCommGroup A
545544

546-
set_option backward.privateInPublic true in
547-
set_option backward.privateInPublic.warn false in
548545
instance : SMul R (mkOfSMul' φ) := ⟨fun r (x : A) => (show A ⟶ A from φ r) x⟩
549546

550547
@[simp]

Mathlib/Algebra/Category/MonCat/Colimits.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ instance colimitSetoid : Setoid (Prequotient F) where
118118
-/
119119
def ColimitType : Type v :=
120120
Quotient (colimitSetoid F)
121-
122-
instance : Inhabited (ColimitType F) := by
123-
dsimp [ColimitType]
124-
infer_instance
121+
deriving Inhabited
125122

126123
instance monoidColimitType : Monoid (ColimitType F) where
127124
one := Quotient.mk _ one

Mathlib/Algebra/Homology/DerivedCategory/Basic.lean

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ instance should be obtained at the beginning of the proof, using the term
5858
5959
-/
6060

61-
@[expose] public section
61+
@[expose] public noncomputable section
6262

6363
assert_not_exists TwoSidedIdeal
6464

@@ -85,13 +85,10 @@ variable [HasDerivedCategory.{w} C]
8585

8686
/-- The derived category of an abelian category. -/
8787
def DerivedCategory : Type (max u v) := HomologicalComplexUpToQuasiIso C (ComplexShape.up ℤ)
88+
deriving Category
8889

8990
namespace DerivedCategory
9091

91-
instance : Category.{w} (DerivedCategory C) := by
92-
dsimp [DerivedCategory]
93-
infer_instance
94-
9592
variable {C}
9693

9794
/-- The localization functor `CochainComplex C ℤ ⥤ DerivedCategory C`. -/
@@ -127,7 +124,7 @@ instance : Qh.IsLocalization (HomotopyCategory.subcategoryAcyclic C).trW := by
127124
rw [← HomotopyCategory.quasiIso_eq_subcategoryAcyclic_W]
128125
infer_instance
129126

130-
noncomputable instance : Preadditive (DerivedCategory C) :=
127+
instance : Preadditive (DerivedCategory C) :=
131128
Localization.preadditive Qh (HomotopyCategory.subcategoryAcyclic C).trW
132129

133130
instance : (Qh (C := C)).Additive :=
@@ -136,16 +133,16 @@ instance : (Qh (C := C)).Additive :=
136133
instance : (Q (C := C)).Additive :=
137134
Functor.additive_of_iso (quotientCompQhIso C)
138135

139-
noncomputable instance : HasZeroObject (DerivedCategory C) :=
136+
instance : HasZeroObject (DerivedCategory C) :=
140137
Q.hasZeroObject_of_additive
141138

142-
noncomputable instance : HasShift (DerivedCategory C) ℤ :=
139+
instance : HasShift (DerivedCategory C) ℤ :=
143140
HasShift.localized Qh (HomotopyCategory.subcategoryAcyclic C).trW ℤ
144141

145-
noncomputable instance : (Qh (C := C)).CommShift ℤ :=
142+
instance : (Qh (C := C)).CommShift ℤ :=
146143
Functor.CommShift.localized Qh (HomotopyCategory.subcategoryAcyclic C).trW ℤ
147144

148-
noncomputable instance : (Q (C := C)).CommShift ℤ :=
145+
instance : (Q (C := C)).CommShift ℤ :=
149146
Functor.CommShift.ofIso (quotientCompQhIso C) ℤ
150147

151148
instance : NatTrans.CommShift (quotientCompQhIso C).hom ℤ :=
@@ -156,15 +153,15 @@ instance (n : ℤ) : (shiftFunctor (DerivedCategory C) n).Additive := by
156153
Qh (HomotopyCategory.subcategoryAcyclic C).trW]
157154
exact Functor.additive_of_iso (Qh.commShiftIso n)
158155

159-
noncomputable instance : Pretriangulated (DerivedCategory C) :=
156+
instance : Pretriangulated (DerivedCategory C) :=
160157
Triangulated.Localization.pretriangulated
161158
Qh (HomotopyCategory.subcategoryAcyclic C).trW
162159

163160
instance : (Qh (C := C)).IsTriangulated :=
164161
Triangulated.Localization.isTriangulated_functor
165162
Qh (HomotopyCategory.subcategoryAcyclic C).trW
166163

167-
noncomputable instance : IsTriangulated (DerivedCategory C) :=
164+
instance : IsTriangulated (DerivedCategory C) :=
168165
Triangulated.Localization.isTriangulated
169166
Qh (HomotopyCategory.subcategoryAcyclic C).trW
170167

@@ -223,12 +220,12 @@ end
223220

224221
/-- The single functors `C ⥤ DerivedCategory C` for all `n : ℤ` along with
225222
their compatibilities with shifts. -/
226-
noncomputable def singleFunctors : SingleFunctors C (DerivedCategory C) ℤ :=
223+
def singleFunctors : SingleFunctors C (DerivedCategory C) ℤ :=
227224
(HomotopyCategory.singleFunctors C).postcomp Qh
228225

229226
/-- The shift functor `C ⥤ DerivedCategory C` which sends `X : C` to the
230227
single cochain complex with `X` sitting in degree `n : ℤ`. -/
231-
noncomputable abbrev singleFunctor (n : ℤ) := (singleFunctors C).functor n
228+
abbrev singleFunctor (n : ℤ) := (singleFunctors C).functor n
232229

233230
instance (n : ℤ) : (singleFunctor C n).Additive := by
234231
dsimp [singleFunctor, singleFunctors]
@@ -242,13 +239,13 @@ instance (n : ℤ) : (singleFunctor C n).Additive := by
242239
/-- The isomorphism
243240
`DerivedCategory.singleFunctors C ≅ (HomotopyCategory.singleFunctors C).postcomp Qh` given
244241
by the definition of `DerivedCategory.singleFunctors`. -/
245-
noncomputable def singleFunctorsPostcompQhIso :
242+
def singleFunctorsPostcompQhIso :
246243
singleFunctors C ≅ (HomotopyCategory.singleFunctors C).postcomp Qh :=
247244
Iso.refl _
248245

249246
/-- The isomorphism
250247
`DerivedCategory.singleFunctors C ≅ (CochainComplex.singleFunctors C).postcomp Q`. -/
251-
noncomputable def singleFunctorsPostcompQIso :
248+
def singleFunctorsPostcompQIso :
252249
singleFunctors C ≅ (CochainComplex.singleFunctors C).postcomp Q :=
253250
(SingleFunctors.postcompFunctor C ℤ (Qh : _ ⥤ DerivedCategory C)).mapIso
254251
(HomotopyCategory.singleFunctorsPostcompQuotientIso C) ≪≫
@@ -273,7 +270,7 @@ lemma singleFunctorsPostcompQIso_inv_hom (n : ℤ) :
273270
rfl
274271

275272
/-- The isomorphism `singleFunctor C n ≅ CochainComplex.singleFunctor C n ⋙ Q`. -/
276-
noncomputable def singleFunctorIsoCompQ (n : ℤ) :
273+
def singleFunctorIsoCompQ (n : ℤ) :
277274
singleFunctor C n ≅ CochainComplex.singleFunctor C n ⋙ Q := Iso.refl _
278275

279276
lemma isIso_Q_map_iff_quasiIso {K L : CochainComplex C ℤ} (φ : K ⟶ L) :

Mathlib/Algebra/Homology/HomotopyCategory/HomComplex.lean

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,10 @@ variable (F G)
6666
of a family of morphisms `F.X p ⟶ G.X q` whenever `p + n = q`, i.e. for all
6767
triplets in `HomComplex.Triplet n`. -/
6868
def Cochain := ∀ (T : Triplet n), F.X T.p ⟶ G.X T.q
69+
deriving AddCommGroup
6970

70-
instance : AddCommGroup (Cochain F G n) := by
71-
dsimp only [Cochain]
72-
infer_instance
73-
74-
set_option backward.isDefEq.respectTransparency false in
75-
instance : Module R (Cochain F G n) := by
76-
dsimp only [Cochain]
77-
infer_instance
71+
instance : Module R (Cochain F G n) :=
72+
inferInstanceAs <| Module R (∀ _, _)
7873

7974
namespace Cochain
8075

Mathlib/Algebra/Module/Presentation/Basic.lean

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ generators and relations.
3838
3939
-/
4040

41-
@[expose] public section
41+
@[expose] public noncomputable section
4242

4343
assert_not_exists Cardinal
4444

@@ -68,16 +68,10 @@ variable {A} (relations : Relations.{w₀, w₁} A)
6868
This is the quotient of the free `A`-module on `relations.G` by the submodule generated by
6969
the given relations. -/
7070
def Quotient := (relations.G →₀ A) ⧸ Submodule.span A (Set.range relations.relation)
71-
72-
noncomputable instance : AddCommGroup relations.Quotient := by
73-
dsimp only [Quotient]; infer_instance
74-
75-
set_option backward.isDefEq.respectTransparency false in
76-
noncomputable instance : Module A relations.Quotient := by
77-
dsimp only [Quotient]; infer_instance
71+
deriving AddCommGroup, Module A
7872

7973
/-- The canonical (surjective) linear map `(relations.G →₀ A) →ₗ[A] relations.Quotient`. -/
80-
noncomputable def toQuotient : (relations.G →₀ A) →ₗ[A] relations.Quotient := Submodule.mkQ _
74+
def toQuotient : (relations.G →₀ A) →ₗ[A] relations.Quotient := Submodule.mkQ _
8175

8276
variable {relations} in
8377
@[ext]
@@ -105,7 +99,7 @@ lemma toQuotient_relation (r : relations.R) :
10599

106100
/-- The linear map `(relations.R →₀ A) →ₗ[A] (relations.G →₀ A)` corresponding to the relations
107101
given by `relations : Relations A`. -/
108-
noncomputable def map : (relations.R →₀ A) →ₗ[A] (relations.G →₀ A) :=
102+
def map : (relations.R →₀ A) →ₗ[A] (relations.G →₀ A) :=
109103
Finsupp.linearCombination _ relations.relation
110104

111105
@[simp]
@@ -146,7 +140,7 @@ variable (solution : relations.Solution M)
146140

147141
/-- Given `relations : Relations A` and a solution in `relations.Solution M`, this is
148142
the linear map `(relations.G →₀ A) →ₗ[A] M` canonically associated to the solution. -/
149-
noncomputable def π : (relations.G →₀ A) →ₗ[A] M := Finsupp.linearCombination _ solution.var
143+
def π : (relations.G →₀ A) →ₗ[A] M := Finsupp.linearCombination _ solution.var
150144

151145
@[simp]
152146
lemma π_single (g : relations.G) :
@@ -175,7 +169,7 @@ lemma span_relation_le_ker_π :
175169

176170
/-- Given `relations : Relations A` and `solution : relations.Solution M`, this is
177171
the canonical linear map `relations.Quotient →ₗ[A] M` from the module. -/
178-
noncomputable def fromQuotient : relations.Quotient →ₗ[A] M :=
172+
def fromQuotient : relations.Quotient →ₗ[A] M :=
179173
Submodule.liftQ _ solution.π solution.span_relation_le_ker_π
180174

181175
@[simp]
@@ -222,7 +216,7 @@ for `relations.Solution M` for which the data is given as
222216
a linear map `π : (relations.G →₀ A) →ₗ[A] M`. (See also `ofπ'` for an alternate
223217
vanishing criterion.) -/
224218
@[simps -isSimp]
225-
noncomputable def ofπ : relations.Solution M where
219+
def ofπ : relations.Solution M where
226220
var g := π (Finsupp.single g 1)
227221
linearCombination_var_relation r := by
228222
have : π = Finsupp.linearCombination _ (fun g ↦ π (Finsupp.single g 1)) := by ext; simp
@@ -241,7 +235,7 @@ variable (π : (relations.G →₀ A) →ₗ[A] M) (hπ : π.comp relations.map
241235
/-- Variant of `ofπ` where the vanishing condition is expressed in terms
242236
of a composition of linear maps. -/
243237
@[simps! -isSimp]
244-
noncomputable def ofπ' : relations.Solution M :=
238+
def ofπ' : relations.Solution M :=
245239
ofπ π (fun r ↦ by
246240
simpa using DFunLike.congr_fun hπ (Finsupp.single r 1))
247241

@@ -298,7 +292,7 @@ include h
298292
/-- When `M` admits a presentation by generators and relations given
299293
by `solution : relations.Solutions M`, this is the associated linear equivalence
300294
`relations.Quotient ≃ₗ[A] M`. -/
301-
noncomputable def linearEquiv : relations.Quotient ≃ₗ[A] M := LinearEquiv.ofBijective _ h.bijective
295+
def linearEquiv : relations.Quotient ≃ₗ[A] M := LinearEquiv.ofBijective _ h.bijective
302296

303297
@[simp]
304298
lemma linearEquiv_apply (x : relations.Quotient) :
@@ -324,7 +318,7 @@ variable {N : Type v'} [AddCommGroup N] [Module A N]
324318

325319
/-- If `M` admits a presentation by generators and relations, and we have a solution of the
326320
same equations in a module `N`, then this is the canonical induced linear map `M →ₗ[A] N`. -/
327-
noncomputable def desc (s : relations.Solution N) : M →ₗ[A] N :=
321+
def desc (s : relations.Solution N) : M →ₗ[A] N :=
328322
s.fromQuotient.comp h.linearEquiv.symm.toLinearMap
329323

330324
@[simp]
@@ -358,7 +352,7 @@ lemma postcomp_injective {f f' : M →ₗ[A] N}
358352
linear maps from `M` can be (naturally) identified to the solutions of
359353
certain linear equations. -/
360354
@[simps]
361-
noncomputable def linearMapEquiv : (M →ₗ[A] N) ≃ relations.Solution N where
355+
def linearMapEquiv : (M →ₗ[A] N) ≃ relations.Solution N where
362356
toFun f := solution.postcomp f
363357
invFun s := h.desc s
364358
left_inv f := h.postcomp_injective (by simp)
@@ -370,7 +364,7 @@ variable {solution' : relations.Solution N} (h' : solution'.IsPresentation)
370364

371365
/-- Uniqueness (up to a unique linear equivalence) of the module defined
372366
by generators and relations. -/
373-
noncomputable def uniq : M ≃ₗ[A] N := LinearEquiv.ofLinear
367+
def uniq : M ≃ₗ[A] N := LinearEquiv.ofLinear
374368
(h.desc solution') (h'.desc solution)
375369
(h'.postcomp_injective (by simp))
376370
(h.postcomp_injective (by simp))
@@ -407,7 +401,7 @@ variable (relations)
407401
/-- Given `relations : Relations A`, this is the obvious solution to `relations`
408402
in the quotient `relations.Quotient`. -/
409403
@[simps!]
410-
noncomputable def ofQuotient : relations.Solution relations.Quotient :=
404+
def ofQuotient : relations.Solution relations.Quotient :=
411405
ofπ relations.toQuotient (by simp)
412406

413407
@[simp]

Mathlib/AlgebraicTopology/SimplicialObject/Basic.lean

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,8 @@ def Augmented :=
395395
Comma (𝟭 (SimplicialObject C)) (const C)
396396

397397
@[simps!]
398-
instance : Category (Augmented C) := by
399-
dsimp only [Augmented]
400-
infer_instance
398+
instance : Category (Augmented C) :=
399+
inferInstanceAs <| Category (Comma _ _)
401400

402401
variable {C}
403402

@@ -692,10 +691,7 @@ def whiskering (D : Type*) [Category* D] : (C ⥤ D) ⥤ CosimplicialObject C
692691
/-- Truncated cosimplicial objects. -/
693692
def Truncated (n : ℕ) :=
694693
SimplexCategory.Truncated n ⥤ C
695-
696-
instance {n : ℕ} : Category (Truncated C n) := by
697-
dsimp [Truncated]
698-
infer_instance
694+
deriving Category
699695

700696
variable {C}
701697

@@ -772,9 +768,8 @@ def Augmented :=
772768
Comma (const C) (𝟭 (CosimplicialObject C))
773769

774770
@[simps!]
775-
instance : Category (Augmented C) := by
776-
dsimp only [Augmented]
777-
infer_instance
771+
instance : Category (Augmented C) :=
772+
inferInstanceAs <| Category (Comma _ _)
778773

779774
variable {C}
780775

Mathlib/CategoryTheory/Action.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ from x to y is a scalar taking x to y. Due to implementation details, the object
4747
of this category is not equal to X, but is in bijection with X. -/
4848
def ActionCategory :=
4949
(actionAsFunctor M X).Elements
50-
51-
instance : Category (ActionCategory M X) := by
52-
dsimp only [ActionCategory]
53-
infer_instance
50+
deriving Category
5451

5552
namespace ActionCategory
5653

Mathlib/CategoryTheory/Action/Monoidal.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ instance FunctorCategoryEquivalence.functorMonoidal :
125125
(Action.functorCategoryEquivalence V G).symm).inverse.Monoidal
126126

127127
instance functorCategoryEquivalenceFunctorMonoidal :
128-
(functorCategoryEquivalence V G).functor.Monoidal := by
129-
dsimp only [functorCategoryEquivalence_functor]; infer_instance
128+
(functorCategoryEquivalence V G).functor.Monoidal :=
129+
inferInstanceAs FunctorCategoryEquivalence.functor.Monoidal
130130

131131
/-- Upgrading the functor `(SingleObj G ⥤ V) ⥤ Action V G` to a monoidal functor. -/
132132
instance FunctorCategoryEquivalence.inverseMonoidal :
@@ -135,8 +135,8 @@ instance FunctorCategoryEquivalence.inverseMonoidal :
135135
(Action.functorCategoryEquivalence V G).symm).functor.Monoidal
136136

137137
instance functorCategoryEquivalenceInverseMonoidal :
138-
(functorCategoryEquivalence V G).inverse.Monoidal := by
139-
dsimp only [functorCategoryEquivalence_inverse]; infer_instance
138+
(functorCategoryEquivalence V G).inverse.Monoidal :=
139+
inferInstanceAs FunctorCategoryEquivalence.inverse.Monoidal
140140

141141
@[simp]
142142
lemma FunctorCategoryEquivalence.functor_ε :

Mathlib/CategoryTheory/Linear/Basic.lean

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,8 @@ section End
7979

8080
variable {R : Type w}
8181

82-
set_option backward.isDefEq.respectTransparency false in
83-
instance [Semiring R] [Linear R C] (X : C) : Module R (End X) := by
84-
dsimp [End]
85-
infer_instance
82+
instance [Semiring R] [Linear R C] (X : C) : Module R (End X) :=
83+
inferInstanceAs <| Module R (X ⟶ X)
8684

8785
instance [CommSemiring R] [Linear R C] (X : C) : Algebra R (End X) :=
8886
Algebra.ofModule (fun _ _ _ => comp_smul _ _ _ _ _ _) fun _ _ _ => smul_comp _ _ _ _ _ _

Mathlib/CategoryTheory/Localization/Construction.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ open Localization.Construction
9696
in `W : MorphismProperty C` -/
9797
def Localization :=
9898
CategoryTheory.Quotient (Localization.Construction.relations W)
99-
100-
instance : Category (Localization W) := by
101-
dsimp only [Localization]
102-
infer_instance
99+
deriving Category
103100

104101
/-- The obvious functor `C ⥤ W.Localization` -/
105102
def Q : C ⥤ W.Localization where

0 commit comments

Comments
 (0)