Skip to content

Commit c54f94f

Browse files
Vierkantorjcommelin
andcommitted
refactor(*): get rid of (forget _).obj and (forget _).map (#21727)
This PR tries getting rid of `HasForget.forget` by searching for `\(forget .*\).(obj|map)` and removing all the occurrences where they could become `ConcreteCategory.hom`. In particular, they should no longer be written in any theorem statement. There are still a few places, generally in the middle of proving properties of the forgetful functor itself, where it was nicer to keep `HasForget`. The final step is to modify the `elementwise` attribute to produce `ConcreteCategory` lemmas, and the refactor itself is done. After that point, we should still go through and try to clean up the workarounds left behind. But that can be done at a lower priority. Co-authored-by: Johan Commelin <johan@commelin.net>
1 parent 7f06268 commit c54f94f

File tree

21 files changed

+53
-117
lines changed

21 files changed

+53
-117
lines changed

Mathlib/Algebra/Category/AlgebraCat/Limits.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ def limitCone : Cone F where
100100
def limitConeIsLimit : IsLimit (limitCone.{v, w} F) := by
101101
refine
102102
IsLimit.ofFaithful (forget (AlgebraCat R)) (Types.Small.limitConeIsLimit.{v, w} _)
103-
-- Porting note: in mathlib3 the function term
104-
-- `fun v => ⟨fun j => ((forget (AlgebraCat R)).mapCone s).π.app j v`
105-
-- was provided by unification, and the last argument `(fun s => _)` was `(fun s => rfl)`.
106103
(fun s => ofHom
107104
{ toFun := _, map_one' := ?_, map_mul' := ?_, map_zero' := ?_, map_add' := ?_,
108105
commutes' := ?_ })

Mathlib/Algebra/Category/ModuleCat/Basic.lean

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,11 @@ instance : Inhabited (ModuleCat R) :=
206206
definitional equality issues. -/
207207
lemma forget_obj {M : ModuleCat.{v} R} : (forget (ModuleCat.{v} R)).obj M = M := rfl
208208

209-
/- Not a `@[simp]` lemma since the LHS is a categorical arrow and the RHS is a plain function. -/
209+
@[simp]
210210
lemma forget_map {M N : ModuleCat.{v} R} (f : M ⟶ N) :
211211
(forget (ModuleCat.{v} R)).map f = f :=
212212
rfl
213213

214-
-- Porting note:
215-
-- One might hope these two instances would not be needed,
216-
-- as we already have `AddCommGroup M` and `Module R M`,
217-
-- but sometimes we seem to need these when rewriting by lemmas about generic concrete categories.
218-
instance {M : ModuleCat.{v} R} : AddCommGroup ((forget (ModuleCat R)).obj M) :=
219-
(inferInstance : AddCommGroup M)
220-
instance {M : ModuleCat.{v} R} : Module R ((forget (ModuleCat R)).obj M) :=
221-
(inferInstance : Module R M)
222-
223214
instance hasForgetToAddCommGroup : HasForget₂ (ModuleCat R) AddCommGrp where
224215
forget₂ :=
225216
{ obj := fun M => AddCommGrp.of M

Mathlib/Algebra/Category/ModuleCat/Presheaf.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ lemma comp_app {M₁ M₂ M₃ : PresheafOfModules R} (f : M₁ ⟶ M₂) (g : M
9797

9898
lemma naturality_apply (f : M₁ ⟶ M₂) {X Y : Cᵒᵖ} (g : X ⟶ Y) (x : M₁.obj X) :
9999
Hom.app f Y (M₁.map g x) = M₂.map g (Hom.app f X x) :=
100-
congr_fun ((forget _).congr_map (Hom.naturality f g)) x
100+
CategoryTheory.congr_fun (Hom.naturality f g) x
101101

102102
/-- Constructor for isomorphisms in the category of presheaves of modules. -/
103103
@[simps!]
@@ -190,7 +190,7 @@ def homMk (φ : M₁.presheaf ⟶ M₂.presheaf)
190190
map_smul' := hφ X }
191191
naturality := fun f ↦ by
192192
ext x
193-
exact congr_fun ((forget _).congr_map (φ.naturality f)) x
193+
exact CategoryTheory.congr_fun (φ.naturality f) x
194194

195195
instance : Zero (M₁ ⟶ M₂) where
196196
zero := { app := fun _ ↦ 0 }

Mathlib/Algebra/Category/ModuleCat/Sheaf.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,13 @@ noncomputable def homEquivOfIsLocallyBijective : (M₂ ⟶ N) ≃ (M₁ ⟶ N) w
211211
((PresheafOfModules.toPresheaf R).map ψ)
212212
simp only [← hφ, Equiv.symm_apply_apply]
213213
replace hφ : ∀ (Z : Cᵒᵖ) (x : M₁.obj Z), φ.app Z (f.app Z x) = ψ.app Z x :=
214-
fun Z x ↦ congr_fun ((forget _).congr_map (congr_app hφ Z)) x
214+
fun Z x ↦ CategoryTheory.congr_fun (congr_app hφ Z) x
215215
intro X r y
216216
apply hN.isSeparated _ _
217217
(Presheaf.imageSieve_mem J ((toPresheaf R).map f) y)
218218
rintro Y p ⟨x : M₁.obj _, hx : f.app _ x = M₂.map p.op y⟩
219219
have hφ' : ∀ (z : M₂.obj X), φ.app _ (M₂.map p.op z) =
220-
N.map p.op (φ.app _ z) := congr_fun ((forget _).congr_map (φ.naturality p.op))
220+
N.map p.op (φ.app _ z) := CategoryTheory.congr_fun (φ.naturality p.op)
221221
change N.map p.op (φ.app X (r • y)) = N.map p.op (r • φ.app X y)
222222
rw [← hφ', M₂.map_smul, ← hx, ← (f.app _).hom.map_smul, hφ, (ψ.app _).hom.map_smul,
223223
← hφ, hx, N.map_smul, hφ'])

Mathlib/Algebra/Category/ModuleCat/Sheaf/ChangeOfRings.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ noncomputable def restrictHomEquivOfIsLocallySurjective
5555
apply hM₂.isSeparated _ _ (Presheaf.imageSieve_mem J α r')
5656
rintro Y p ⟨r : R.obj _, hr⟩
5757
have hg : ∀ (z : M₁.obj X), g.app _ (M₁.map p.op z) = M₂.map p.op (g.app X z) :=
58-
fun z ↦ congr_fun ((forget _).congr_map (g.naturality p.op)) z
58+
fun z ↦ CategoryTheory.congr_fun (g.naturality p.op) z
5959
change M₂.map p.op (g.app X (r' • m)) = M₂.map p.op (r' • show M₂.obj X from g.app X m)
6060
dsimp at hg ⊢
6161
rw [← hg, M₂.map_smul, ← hg, ← hr]

Mathlib/Algebra/Category/ModuleCat/Tannaka.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def ringEquivEndForget₂ (R : Type u) [Ring R] :
3535
intro φ
3636
apply NatTrans.ext
3737
ext M (x : M)
38-
have w := congr_fun ((forget _).congr_map
39-
(φ.naturality (ModuleCat.ofHom (LinearMap.toSpanSingleton R M x)))) (1 : R)
38+
have w := CategoryTheory.congr_fun
39+
(φ.naturality (ModuleCat.ofHom (LinearMap.toSpanSingleton R M x))) (1 : R)
4040
exact w.symm.trans (congr_arg (φ.app M) (one_smul R x))
4141
map_add' := by
4242
intros

Mathlib/Algebra/Category/MonCat/FilteredColimits.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) where
294294
(F ⋙ forget MonCat)).fac ((forget MonCat).mapCocone t) j) x
295295
uniq t m h := MonCat.ext fun y => congr_fun
296296
((Types.TypeMax.colimitCoconeIsColimit (F ⋙ forget MonCat)).uniq ((forget MonCat).mapCocone t)
297-
((forget MonCat).map m)
297+
⇑(ConcreteCategory.hom m)
298298
fun j => funext fun x => ConcreteCategory.congr_hom (h j) x) y
299299

300300
@[to_additive]
@@ -370,7 +370,7 @@ def colimitCoconeIsColimit : IsColimit (colimitCocone.{v, u} F) where
370370
ConcreteCategory.coe_ext <|
371371
(Types.TypeMax.colimitCoconeIsColimit.{v, u} (F ⋙ forget CommMonCat.{max v u})).uniq
372372
((forget CommMonCat.{max v u}).mapCocone t)
373-
((forget CommMonCat.{max v u}).map m) fun j => funext fun x =>
373+
⇑(ConcreteCategory.hom m) fun j => funext fun x =>
374374
CategoryTheory.congr_fun (h j) x
375375

376376
@[to_additive forget₂AddMonPreservesFilteredColimits]

Mathlib/Algebra/Homology/ImageToKernel.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ theorem imageToKernel_arrow (w : f ≫ g = 0) :
5757
simp [imageToKernel]
5858

5959
@[simp]
60-
lemma imageToKernel_arrow_apply [HasForget V] (w : f ≫ g = 0)
61-
(x : (forget V).obj (Subobject.underlying.obj (imageSubobject f))) :
60+
lemma imageToKernel_arrow_apply {FV : V → V → Type*} {CV : V → Type*}
61+
[∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] (w : f ≫ g = 0)
62+
(x : ToType (Subobject.underlying.obj (imageSubobject f))) :
6263
(kernelSubobject g).arrow (imageToKernel f g w x) =
6364
(imageSubobject f).arrow x := by
64-
rw [← CategoryTheory.comp_apply, imageToKernel_arrow]
65+
rw [← ConcreteCategory.comp_apply, imageToKernel_arrow]
6566

6667
-- This is less useful as a `simp` lemma than it initially appears,
6768
-- as it "loses" the information the morphism factors through the image.

Mathlib/AlgebraicGeometry/Spec.lean

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ open Spec (structureSheaf)
5454
def Spec.topObj (R : CommRingCat.{u}) : TopCat :=
5555
TopCat.of (PrimeSpectrum R)
5656

57-
@[simp] theorem Spec.topObj_forget {R} : (forget TopCat).obj (Spec.topObj R) = PrimeSpectrum R :=
57+
@[simp] theorem Spec.topObj_forget {R} : ToType (Spec.topObj R) = PrimeSpectrum R :=
5858
rfl
5959

6060
/-- The induced map of a ring homomorphism on the ring spectra, as a morphism of topological spaces.
@@ -408,16 +408,11 @@ instance isLocalizedModule_toPushforwardStalkAlgHom :
408408
rw [toPushforwardStalkAlgHom_apply,
409409
← (toPushforwardStalk (CommRingCat.ofHom (algebraMap ↑R ↑S)) p).hom.map_zero,
410410
toPushforwardStalk] at hx
411-
-- Porting note: this `change` is manually rewriting `comp_apply`
412-
change _ = (TopCat.Presheaf.germ (Spec.topMap (CommRingCat.ofHom (algebraMap ↑R ↑S)) _*
413-
(structureSheaf ↑S).val) ⊤ p trivial (toOpen S ⊤ 0)) at hx
414-
rw [map_zero] at hx
415-
change (forget CommRingCat).map _ _ = (forget _).map _ _ at hx
416-
obtain ⟨U, hpU, i₁, i₂, e⟩ := TopCat.Presheaf.germ_eq _ _ _ _ _ _ hx
411+
rw [CommRingCat.comp_apply, map_zero] at hx
412+
obtain ⟨U, hpU, i₁, i₂, e⟩ := TopCat.Presheaf.germ_eq (C := CommRingCat) _ _ _ _ _ _ hx
417413
obtain ⟨_, ⟨r, rfl⟩, hpr, hrU⟩ :=
418414
PrimeSpectrum.isTopologicalBasis_basic_opens.exists_subset_of_mem_open (show p ∈ U.1 from hpU)
419415
U.2
420-
change PrimeSpectrum.basicOpen r ≤ U at hrU
421416
apply_fun (Spec.topMap (CommRingCat.ofHom (algebraMap R S)) _* (structureSheaf S).1).map
422417
(homOfLE hrU).op at e
423418
simp only [Functor.op_map, map_zero, ← CategoryTheory.comp_apply, toOpen_res] at e
@@ -429,10 +424,7 @@ instance isLocalizedModule_toPushforwardStalkAlgHom :
429424
this
430425
obtain ⟨⟨_, n, rfl⟩, e⟩ := (IsLocalization.mk'_eq_zero_iff _ _).mp this
431426
refine ⟨⟨r, hpr⟩ ^ n, ?_⟩
432-
rw [Submonoid.smul_def, Algebra.smul_def]
433-
-- Porting note: manually rewrite `Submonoid.coe_pow`
434-
change (algebraMap R S) (r ^ n) * x = 0
435-
rw [map_pow]
427+
rw [Submonoid.smul_def, Algebra.smul_def, SubmonoidClass.coe_pow, map_pow]
436428
exact e
437429

438430
end StructureSheaf

Mathlib/CategoryTheory/Action/Concrete.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,18 @@ end FintypeCat
168168

169169
section ToMulAction
170170

171-
variable {V : Type (u + 1)} [LargeCategory V] [HasForget V]
171+
variable {V : Type (u + 1)} [LargeCategory V] {FV : V → V → Type*} {CV : V → Type*}
172+
variable [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV]
172173

173174
instance instMulAction {G : MonCat.{u}} (X : Action V G) :
174-
MulAction G ((CategoryTheory.forget _).obj X) where
175-
smul g x := ((CategoryTheory.forget _).map (X.ρ g)) x
175+
MulAction G (ToType X) where
176+
smul g x := ConcreteCategory.hom (X.ρ g) x
176177
one_smul x := by
177-
show ((CategoryTheory.forget _).map (X.ρ 1)) x = x
178+
show ConcreteCategory.hom (X.ρ 1) x = x
178179
simp
179180
mul_smul g h x := by
180-
show (CategoryTheory.forget V).map (X.ρ (g * h)) x =
181-
((CategoryTheory.forget V).map (X.ρ h) ≫ (CategoryTheory.forget V).map (X.ρ g)) x
181+
show ConcreteCategory.hom (X.ρ (g * h)) x =
182+
ConcreteCategory.hom (X.ρ g) ((ConcreteCategory.hom (X.ρ h)) x)
182183
simp
183184

184185
/- Specialize `instMulAction` to assist typeclass inference. -/

0 commit comments

Comments
 (0)