Skip to content

Commit 140e741

Browse files
committed
chore(CategoryTheory): process porting notes, part 2 (#28776)
Go through all the porting notes in CategoryTheory, from Limits to Monoidal. Lots of them can be fixed, others are of the format "Lean 4 does this better" and a few are more TODOs which do not really depend on the port. Co-authored-by: Anne C.A. Baanen <vierkantor@vierkantor.com>
1 parent 3b3f214 commit 140e741

37 files changed

+130
-241
lines changed

Mathlib/CategoryTheory/Limits/FilteredColimitCommutesProduct.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ theorem Types.isIso_colimitPointwiseProductToProductColimit (F : ∀ i, I i ⥤
136136
let yk' : (pointwiseProduct F).obj k :=
137137
(pointwiseProduct F).map (IsFiltered.rightToMax ky ky') yk₀'
138138
obtain rfl : y = colimit.ι (pointwiseProduct F) k yk := by
139-
simp only [k, yk, Types.Colimit.w_apply', hyk₀]
139+
simp only [k, yk, Types.Colimit.w_apply, hyk₀]
140140
obtain rfl : y' = colimit.ι (pointwiseProduct F) k yk' := by
141-
simp only [k, yk', Types.Colimit.w_apply', hyk₀']
141+
simp only [k, yk', Types.Colimit.w_apply, hyk₀']
142142
dsimp only [pointwiseProduct_obj] at yk yk'
143143
have hch : ∀ (s : α), ∃ (i' : I s) (hi' : k s ⟶ i'),
144144
(F s).map hi' (Pi.π (fun s => (F s).obj (k s)) s yk) =

Mathlib/CategoryTheory/Limits/FunctorCategory/Basic.lean

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,21 @@ instance functorCategoryHasColimitsOfShape [HasColimitsOfShape J C] :
182182
HasColimitsOfShape J (K ⥤ C) where
183183
has_colimit _ := inferInstance
184184

185-
-- Porting note: previously Lean could see through the binders and infer_instance sufficed
186185
instance functorCategoryHasLimitsOfSize [HasLimitsOfSize.{v₁, u₁} C] :
187186
HasLimitsOfSize.{v₁, u₁} (K ⥤ C) where
188-
has_limits_of_shape := fun _ _ => inferInstance
187+
has_limits_of_shape := inferInstance
189188

190-
-- Porting note: previously Lean could see through the binders and infer_instance sufficed
191189
instance functorCategoryHasColimitsOfSize [HasColimitsOfSize.{v₁, u₁} C] :
192190
HasColimitsOfSize.{v₁, u₁} (K ⥤ C) where
193-
has_colimits_of_shape := fun _ _ => inferInstance
191+
has_colimits_of_shape := inferInstance
194192

195193
instance hasLimitCompEvaluation (F : J ⥤ K ⥤ C) (k : K) [HasLimit (F.flip.obj k)] :
196194
HasLimit (F ⋙ (evaluation _ _).obj k) :=
197195
hasLimit_of_iso (F := F.flip.obj k) (Iso.refl _)
198196

199197
instance evaluation_preservesLimit (F : J ⥤ K ⥤ C) [∀ k, HasLimit (F.flip.obj k)] (k : K) :
200198
PreservesLimit F ((evaluation K C).obj k) :=
201-
-- Porting note: added a let because X was not inferred
199+
-- Porting note: added a let because X was not inferred
202200
let X : (k : K) → LimitCone (F.flip.obj k) := fun k => getLimitCone (F.flip.obj k)
203201
preservesLimit_of_preserves_limit_cone (combinedIsLimit _ X) <|
204202
IsLimit.ofIsoLimit (limit.isLimit _) (evaluateCombinedCones F X k).symm

Mathlib/CategoryTheory/Limits/Preserves/Shapes/Biproducts.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,22 @@ instance hasBiproduct_of_preserves : HasBiproduct (F.obj ∘ f) :=
259259
{ bicone := F.mapBicone (biproduct.bicone f)
260260
isBilimit := isBilimitOfPreserves _ (biproduct.isBilimit _) }
261261

262+
/-- This instance applies more often than `hasBiproduct_of_preserves`, but the discrimination
263+
tree key matches a lot more (since it does not look through lambdas). -/
264+
instance (priority := low) hasBiproduct_of_preserves' : HasBiproduct fun i => F.obj (f i) :=
265+
HasBiproduct.mk
266+
{ bicone := F.mapBicone (biproduct.bicone f)
267+
isBilimit := isBilimitOfPreserves _ (biproduct.isBilimit _) }
268+
262269
/-- If `F` preserves a biproduct, we get a definitionally nice isomorphism
263270
`F.obj (⨁ f) ≅ ⨁ (F.obj ∘ f)`. -/
264271
abbrev mapBiproduct : F.obj (⨁ f) ≅ ⨁ F.obj ∘ f :=
265272
biproduct.uniqueUpToIso _ (isBilimitOfPreserves _ (biproduct.isBilimit _))
266273

267274
theorem mapBiproduct_hom :
268-
haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f
269275
(mapBiproduct F f).hom = biproduct.lift fun j => F.map (biproduct.π f j) := rfl
270276

271277
theorem mapBiproduct_inv :
272-
haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f
273278
(mapBiproduct F f).inv = biproduct.desc fun j => F.map (biproduct.ι f j) := rfl
274279

275280
end Bicone
@@ -364,16 +369,12 @@ section Bicone
364369
variable {J : Type w₁} (f : J → C) [HasBiproduct f] [PreservesBiproduct f F] {W : C}
365370

366371
theorem biproduct.map_lift_mapBiprod (g : ∀ j, W ⟶ f j) :
367-
-- Porting note: we need haveI to tell Lean about hasBiproduct_of_preserves F f
368-
haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f
369372
F.map (biproduct.lift g) ≫ (F.mapBiproduct f).hom = biproduct.lift fun j => F.map (g j) := by
370373
ext j
371374
dsimp only [Function.comp_def]
372375
simp only [mapBiproduct_hom, Category.assoc, biproduct.lift_π, ← F.map_comp]
373376

374377
theorem biproduct.mapBiproduct_inv_map_desc (g : ∀ j, f j ⟶ W) :
375-
-- Porting note: we need haveI to tell Lean about hasBiproduct_of_preserves F f
376-
haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f
377378
(F.mapBiproduct f).inv ≫ F.map (biproduct.desc g) = biproduct.desc fun j => F.map (g j) := by
378379
ext j
379380
dsimp only [Function.comp_def]

Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,9 @@ lemma preservesPushout_symmetry : PreservesColimit (span g f) G where
232232
apply IsColimit.ofIsoColimit _ (PushoutCocone.isoMk _).symm
233233
apply PushoutCocone.isColimitOfFlip
234234
apply (isColimitMapCoconePushoutCoconeEquiv _ _).toFun
235-
· refine @isColimitOfPreserves _ _ _ _ _ _ _ _ _ ?_ ?_ -- Porting note: more TC coddling
236-
· exact PushoutCocone.flipIsColimit hc
237-
· dsimp
238-
infer_instance⟩
235+
· -- Need to unfold these to allow the `PreservesColimit` instance to be found.
236+
dsimp only [span_map_fst, span_map_snd]
237+
exact isColimitOfPreserves _ (PushoutCocone.flipIsColimit hc)⟩
239238

240239
theorem hasPushout_of_preservesPushout [HasPushout f g] : HasPushout (G.map f) (G.map g) :=
241240
⟨⟨⟨_, isColimitPushoutCoconeMapOfIsColimit G _ (pushoutIsPushout _ _)⟩⟩⟩
@@ -312,8 +311,7 @@ lemma PreservesPushout.of_iso_comparison [i : IsIso (pushoutComparison G f g)] :
312311
PreservesColimit (span f g) G := by
313312
apply preservesColimit_of_preserves_colimit_cocone (pushoutIsPushout f g)
314313
apply (isColimitMapCoconePushoutCoconeEquiv _ _).symm _
315-
-- Porting note: apply no longer creates goals for instances
316-
exact @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (span (G.map f) (G.map g))) i
314+
exact IsColimit.ofPointIso _ (i := i)
317315

318316
variable [PreservesColimit (span f g) G]
319317

Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ section
280280

281281
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
282282
CategoryTheory.Discrete.discreteCases
283-
-- Porting note: would it be okay to use this more generally?
283+
-- TODO: would it be okay to use this more generally?
284284
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq
285285

286286
/-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/

Mathlib/CategoryTheory/Limits/Shapes/Equalizers.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ open WalkingParallelPairHom
7575

7676
/-- Composition of morphisms in the indexing diagram for (co)equalizers. -/
7777
def WalkingParallelPairHom.comp :
78-
-- Porting note: changed X Y Z to implicit to match comp fields in precategory
7978
∀ {X Y Z : WalkingParallelPair} (_ : WalkingParallelPairHom X Y)
8079
(_ : WalkingParallelPairHom Y Z), WalkingParallelPairHom X Z
8180
| _, _, _, id _, h => h
@@ -372,7 +371,6 @@ theorem Fork.IsLimit.lift_ι {s t : Fork f g} (hs : IsLimit s) : hs.lift t ≫ s
372371
theorem Cofork.IsColimit.π_desc {s t : Cofork f g} (hs : IsColimit s) : s.π ≫ hs.desc t = t.π :=
373372
hs.fac _ _
374373

375-
-- Porting note: `Fork.IsLimit.lift` was added in order to ease the port
376374
/-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying
377375
`k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/
378376
def Fork.IsLimit.lift {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) :
@@ -393,7 +391,6 @@ def Fork.IsLimit.lift' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h
393391
lemma Fork.IsLimit.mono {s : Fork f g} (hs : IsLimit s) : Mono s.ι where
394392
right_cancellation _ _ h := hom_ext hs h
395393

396-
-- Porting note: `Cofork.IsColimit.desc` was added in order to ease the port
397394
/-- If `s` is a colimit cofork over `f` and `g`, then a morphism `k : Y ⟶ W` satisfying
398395
`f ≫ k = g ≫ k` induces a morphism `l : s.pt ⟶ W` such that `cofork.π s ≫ l = k`. -/
399396
def Cofork.IsColimit.desc {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W)

Mathlib/CategoryTheory/Limits/Shapes/FiniteLimits.lean

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ instance (priority := 90) hasFiniteLimits_of_hasLimitsOfSize₀ [HasLimitsOfSize
6060
HasFiniteLimits C :=
6161
hasFiniteLimits_of_hasLimitsOfSize C
6262

63+
instance (J : Type) [hJ : SmallCategory J] : Category (ULiftHom (ULift J)) :=
64+
(@ULiftHom.category (ULift J) (@uliftCategory J hJ))
65+
6366
/-- We can always derive `HasFiniteLimits C` by providing limits at an
6467
arbitrary universe. -/
6568
theorem hasFiniteLimits_of_hasFiniteLimits_of_size
@@ -71,12 +74,7 @@ theorem hasFiniteLimits_of_hasFiniteLimits_of_size
7174
(@ULiftHom.category (ULift J) (@uliftCategory J hJ)) :=
7275
@ULiftHomULiftCategory.equiv J hJ
7376
apply @hasLimitsOfShape_of_equivalence (ULiftHom (ULift J))
74-
(@ULiftHom.category (ULift J) (@uliftCategory J hJ)) C _ J hJ
75-
(@Equivalence.symm J hJ (ULiftHom (ULift J))
76-
(@ULiftHom.category (ULift J) (@uliftCategory J hJ)) l) _
77-
/- Porting note: tried to factor out (@instCategoryULiftHom (ULift J) (@uliftCategory J hJ)
78-
but when doing that would then find the instance and say it was not definitionally equal to
79-
the provided one (the same thing factored out) -/
77+
(@ULiftHom.category (ULift J) (@uliftCategory J hJ)) C _ J hJ l.symm _
8078

8179
/-- A category has all finite colimits if every functor `J ⥤ C` with a `FinCategory J`
8280
instance and `J : Type` has a colimit.

Mathlib/CategoryTheory/Limits/Shapes/FiniteProducts.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class HasFiniteCoproducts : Prop where
6161
/-- `C` has all finite coproducts -/
6262
out (n : ℕ) : HasColimitsOfShape (Discrete (Fin n)) C
6363

64-
-- attribute [class] HasFiniteCoproducts Porting note: this doesn't seem necessary in Lean 4
65-
6664
instance hasColimitsOfShape_discrete [HasFiniteCoproducts C] (ι : Type w) [Finite ι] :
6765
HasColimitsOfShape (Discrete ι) C := by
6866
rcases Finite.exists_equiv_fin ι with ⟨n, ⟨e⟩⟩

Mathlib/CategoryTheory/Limits/Shapes/Images.lean

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ variable {X Y : C} (f : X ⟶ Y)
6868

6969
/-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/
7070
structure MonoFactorisation (f : X ⟶ Y) where
71-
I : C -- Porting note: violates naming conventions but can't think a better replacement
71+
I : C
7272
m : I ⟶ Y
7373
[m_mono : Mono m]
7474
e : X ⟶ I
@@ -221,7 +221,7 @@ variable (f)
221221

222222
/-- Data exhibiting that a morphism `f` has an image. -/
223223
structure ImageFactorisation (f : X ⟶ Y) where
224-
F : MonoFactorisation f -- Porting note: another violation of the naming convention
224+
F : MonoFactorisation f
225225
isImage : IsImage F
226226

227227
attribute [inherit_doc ImageFactorisation] ImageFactorisation.F ImageFactorisation.isImage
@@ -321,6 +321,18 @@ theorem IsImage.lift_ι {F : MonoFactorisation f} (hF : IsImage F) :
321321
hF.lift (Image.monoFactorisation f) ≫ image.ι f = F.m :=
322322
hF.lift_fac _
323323

324+
@[reassoc (attr := simp)]
325+
theorem image.lift_mk_factorThruImage :
326+
image.lift { I := image f, m := ι f, e := factorThruImage f } ≫ image.ι f = image.ι f :=
327+
(Image.isImage f).lift_fac _
328+
329+
@[reassoc (attr := simp)]
330+
theorem image.lift_mk_comp {C : Type u} [Category.{v} C] {X Y Z : C}
331+
(f : X ⟶ Y) (g : Y ⟶ Z) [HasImage g] [HasImage (f ≫ g)]
332+
(h : Y ⟶ image g) (H : (f ≫ h) ≫ image.ι g = f ≫ g) :
333+
image.lift { I := image g, m := ι g, e := (f ≫ h) } ≫ image.ι g = image.ι (f ≫ g) :=
334+
image.lift_fac _
335+
324336
-- TODO we could put a category structure on `MonoFactorisation f`,
325337
-- with the morphisms being `g : I ⟶ I'` commuting with the `m`s
326338
-- (they then automatically commute with the `e`s)
@@ -441,23 +453,11 @@ def image.eqToHom (h : f = f') : image f ⟶ image f' :=
441453
instance (h : f = f') : IsIso (image.eqToHom h) :=
442454
⟨⟨image.eqToHom h.symm,
443455
⟨(cancel_mono (image.ι f)).1 (by
444-
-- Porting note: added let's for used to be a simp [image.eqToHom]
445-
let F : MonoFactorisation f' :=
446-
⟨image f, image.ι f, factorThruImage f, (by cat_disch)⟩
447-
dsimp [image.eqToHom]
448-
rw [Category.id_comp,Category.assoc,image.lift_fac F]
449-
let F' : MonoFactorisation f :=
450-
⟨image f', image.ι f', factorThruImage f', (by cat_disch)⟩
451-
rw [image.lift_fac F'] ),
456+
subst h
457+
simp [image.eqToHom, Category.assoc, Category.id_comp]),
452458
(cancel_mono (image.ι f')).1 (by
453-
-- Porting note: added let's for used to be a simp [image.eqToHom]
454-
let F' : MonoFactorisation f :=
455-
⟨image f', image.ι f', factorThruImage f', (by cat_disch)⟩
456-
dsimp [image.eqToHom]
457-
rw [Category.id_comp,Category.assoc,image.lift_fac F']
458-
let F : MonoFactorisation f' :=
459-
⟨image f, image.ι f, factorThruImage f, (by cat_disch)⟩
460-
rw [image.lift_fac F])⟩⟩⟩
459+
subst h
460+
simp [image.eqToHom])⟩⟩⟩
461461

462462
/-- An equation between morphisms gives an isomorphism between the images. -/
463463
def image.eqToIso (h : f = f') : image f ≅ image f' :=
@@ -469,8 +469,8 @@ the image inclusion maps commute with `image.eqToIso`.
469469
theorem image.eq_fac [HasEqualizers C] (h : f = f') :
470470
image.ι f = (image.eqToIso h).hom ≫ image.ι f' := by
471471
apply image.ext
472-
dsimp [asIso,image.eqToIso, image.eqToHom]
473-
rw [image.lift_fac] -- Porting note: simp did not fire with this it seems
472+
subst h
473+
simp [asIso,image.eqToIso, image.eqToHom]
474474

475475
end
476476

@@ -488,8 +488,7 @@ def image.preComp [HasImage g] [HasImage (f ≫ g)] : image (f ≫ g) ⟶ image
488488
@[reassoc (attr := simp)]
489489
theorem image.preComp_ι [HasImage g] [HasImage (f ≫ g)] :
490490
image.preComp f g ≫ image.ι g = image.ι (f ≫ g) := by
491-
dsimp [image.preComp]
492-
rw [image.lift_fac] -- Porting note: also here, see image.eq_fac
491+
simp [image.preComp]
493492

494493
@[reassoc (attr := simp)]
495494
theorem image.factorThruImage_preComp [HasImage g] [HasImage (f ≫ g)] :
@@ -512,9 +511,8 @@ theorem image.preComp_comp {W : C} (h : Z ⟶ W) [HasImage (g ≫ h)] [HasImage
512511
image.preComp f (g ≫ h) ≫ image.preComp g h =
513512
image.eqToHom (Category.assoc f g h).symm ≫ image.preComp (f ≫ g) h := by
514513
apply (cancel_mono (image.ι h)).1
515-
dsimp [image.preComp, image.eqToHom]
516-
repeat (rw [Category.assoc,image.lift_fac])
517-
rw [image.lift_fac,image.lift_fac]
514+
simp only [preComp, Category.assoc, fac, lift_mk_comp, eqToHom]
515+
rw [image.lift_fac]
518516

519517
variable [HasEqualizers C]
520518

@@ -673,8 +671,6 @@ section
673671

674672
attribute [local ext] ImageMap
675673

676-
/- Porting note: ImageMap.mk.injEq has LHS simplify to True due to the next instance
677-
We make a replacement -/
678674
theorem ImageMap.map_uniq_aux {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g}
679675
(map : image f.hom ⟶ image g.hom)
680676
(map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by cat_disch)
@@ -683,11 +679,11 @@ theorem ImageMap.map_uniq_aux {f g : Arrow C} [HasImage f.hom] [HasImage g.hom]
683679
have : map ≫ image.ι g.hom = map' ≫ image.ι g.hom := by rw [map_ι,map_ι']
684680
apply (cancel_mono (image.ι g.hom)).1 this
685681

686-
-- Porting note: added to get variant on ImageMap.mk.injEq below
687682
theorem ImageMap.map_uniq {f g : Arrow C} [HasImage f.hom] [HasImage g.hom]
688683
{sq : f ⟶ g} (F G : ImageMap sq) : F.map = G.map := by
689684
apply ImageMap.map_uniq_aux _ F.map_ι _ G.map_ι
690685

686+
/-- `@[simp]`-normal form of `ImageMap.mk.injEq`. -/
691687
@[simp]
692688
theorem ImageMap.mk.injEq' {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g}
693689
(map : image f.hom ⟶ image g.hom)

Mathlib/CategoryTheory/Limits/Shapes/IsTerminal.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,7 @@ def coconeOfDiagramTerminal {X : J} (tX : IsTerminal X) (F : J ⥤ C) : Cocone F
396396
def colimitOfDiagramTerminal {X : J} (tX : IsTerminal X) (F : J ⥤ C) :
397397
IsColimit (coconeOfDiagramTerminal tX F) where
398398
desc s := s.ι.app X
399-
uniq s m w := by
400-
conv_rhs => dsimp -- Porting note: why do I need this much firepower?
401-
rw [← w X, coconeOfDiagramTerminal_ι_app, tX.hom_ext (tX.from X) (𝟙 _)]
402-
simp
399+
uniq s m w := by simp [← w X]
403400

404401
lemma IsColimit.isIso_ι_app_of_isTerminal {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c)
405402
(X : J) (hX : IsTerminal X) :

0 commit comments

Comments
 (0)