source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/ConeCategory.lean
import Mathlib.CategoryTheory.Adjunction.Comma import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.Equivalence /-! # Limits and the category of (co)cones This file contains results that stem from the limit API. For the definition and the category instance of `Cone`, please refer to `CategoryTheory/Limits/Cones.lean`. ## Main results * The category of cones on `F : J ⥤ C` is equivalent to the category `CostructuredArrow (const J) F`. * A cone is limiting iff it is terminal in the category of cones. As a corollary, an equivalence of categories of cones preserves limiting properties. -/ namespace CategoryTheory.Limits open CategoryTheory CategoryTheory.Functor universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] {D : Type u₄} [Category.{v₄} D] /-- Given a cone `c` over `F`, we can interpret the legs of `c` as structured arrows `c.pt ⟶ F.obj -`. -/ @[simps] def Cone.toStructuredArrow {F : J ⥤ C} (c : Cone F) : J ⥤ StructuredArrow c.pt F where obj j := StructuredArrow.mk (c.π.app j) map f := StructuredArrow.homMk f /-- If `F` has a limit, then the limit projections can be interpreted as structured arrows `limit F ⟶ F.obj -`. -/ @[simps] noncomputable def limit.toStructuredArrow (F : J ⥤ C) [HasLimit F] : J ⥤ StructuredArrow (limit F) F where obj j := StructuredArrow.mk (limit.π F j) map f := StructuredArrow.homMk f /-- `Cone.toStructuredArrow` can be expressed in terms of `Functor.toStructuredArrow`. -/ def Cone.toStructuredArrowIsoToStructuredArrow {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ≅ (𝟭 J).toStructuredArrow c.pt F c.π.app (by simp) := Iso.refl _ /-- `Functor.toStructuredArrow` can be expressed in terms of `Cone.toStructuredArrow`. -/ def _root_.CategoryTheory.Functor.toStructuredArrowIsoToStructuredArrow (G : J ⥤ K) (X : C) (F : K ⥤ C) (f : (Y : J) → X ⟶ F.obj (G.obj Y)) (h : ∀ {Y Z : J} (g : Y ⟶ Z), f Y ≫ F.map (G.map g) = f Z) : G.toStructuredArrow X F f h ≅ (Cone.mk X ⟨f, by simp [h]⟩).toStructuredArrow ⋙ StructuredArrow.pre _ _ _ := Iso.refl _ /-- Interpreting the legs of a cone as a structured arrow and then forgetting the arrow again does nothing. -/ @[simps!] def Cone.toStructuredArrowCompProj {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.proj _ _ ≅ 𝟭 J := Iso.refl _ @[simp] lemma Cone.toStructuredArrow_comp_proj {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.proj _ _ = 𝟭 J := rfl /-- Interpreting the legs of a cone as a structured arrow, interpreting this arrow as an arrow over the cone point, and finally forgetting the arrow is the same as just applying the functor the cone was over. -/ @[simps!] def Cone.toStructuredArrowCompToUnderCompForget {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.toUnder _ _ ⋙ Under.forget _ ≅ F := Iso.refl _ @[simp] lemma Cone.toStructuredArrow_comp_toUnder_comp_forget {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.toUnder _ _ ⋙ Under.forget _ = F := rfl /-- A cone `c` on `F : J ⥤ C` lifts to a cone in `Over c.pt` with cone point `𝟙 c.pt`. -/ @[simps] def Cone.toUnder {F : J ⥤ C} (c : Cone F) : Cone (c.toStructuredArrow ⋙ StructuredArrow.toUnder _ _) where pt := Under.mk (𝟙 c.pt) π := { app := fun j => Under.homMk (c.π.app j) (by simp) } /-- The limit cone for `F : J ⥤ C` lifts to a cocone in `Under (limit F)` with cone point `𝟙 (limit F)`. This is automatically also a limit cone. -/ noncomputable def limit.toUnder (F : J ⥤ C) [HasLimit F] : Cone (limit.toStructuredArrow F ⋙ StructuredArrow.toUnder _ _) where pt := Under.mk (𝟙 (limit F)) π := { app := fun j => Under.homMk (limit.π F j) (by simp) } /-- `c.toUnder` is a lift of `c` under the forgetful functor. -/ @[simps!] def Cone.mapConeToUnder {F : J ⥤ C} (c : Cone F) : (Under.forget c.pt).mapCone c.toUnder ≅ c := Iso.refl _ /-- Given a diagram of `StructuredArrow X F`s, we may obtain a cone with cone point `X`. -/ @[simps!] def Cone.fromStructuredArrow (F : C ⥤ D) {X : D} (G : J ⥤ StructuredArrow X F) : Cone (G ⋙ StructuredArrow.proj X F ⋙ F) where pt := X π := { app := fun j => (G.obj j).hom } /-- Given a cone `c : Cone K` and a map `f : X ⟶ F.obj c.X`, we can construct a cone of structured arrows over `X` with `f` as the cone point. -/ @[simps] def Cone.toStructuredArrowCone {K : J ⥤ C} (c : Cone K) (F : C ⥤ D) {X : D} (f : X ⟶ F.obj c.pt) : Cone ((F.mapCone c).toStructuredArrow ⋙ StructuredArrow.map f ⋙ StructuredArrow.pre _ K F) where pt := StructuredArrow.mk f π := { app := fun j => StructuredArrow.homMk (c.π.app j) rfl } /-- Construct an object of the category `(Δ ↓ F)` from a cone on `F`. This is part of an equivalence, see `Cone.equivCostructuredArrow`. -/ @[simps] def Cone.toCostructuredArrow (F : J ⥤ C) : Cone F ⥤ CostructuredArrow (const J) F where obj c := CostructuredArrow.mk c.π map f := CostructuredArrow.homMk f.hom /-- Construct a cone on `F` from an object of the category `(Δ ↓ F)`. This is part of an equivalence, see `Cone.equivCostructuredArrow`. -/ @[simps] def Cone.fromCostructuredArrow (F : J ⥤ C) : CostructuredArrow (const J) F ⥤ Cone F where obj c := ⟨c.left, c.hom⟩ map f := { hom := f.left w := fun j => by convert congr_fun (congr_arg NatTrans.app f.w) j simp } /-- The category of cones on `F` is just the comma category `(Δ ↓ F)`, where `Δ` is the constant functor. -/ @[simps] def Cone.equivCostructuredArrow (F : J ⥤ C) : Cone F ≌ CostructuredArrow (const J) F where functor := Cone.toCostructuredArrow F inverse := Cone.fromCostructuredArrow F unitIso := NatIso.ofComponents Cones.eta counitIso := NatIso.ofComponents fun _ => (CostructuredArrow.eta _).symm /-- A cone is a limit cone iff it is terminal. -/ def Cone.isLimitEquivIsTerminal {F : J ⥤ C} (c : Cone F) : IsLimit c ≃ IsTerminal c := IsLimit.isoUniqueConeMorphism.toEquiv.trans { toFun := fun _ => IsTerminal.ofUnique _ invFun := fun h s => ⟨⟨IsTerminal.from h s⟩, fun a => IsTerminal.hom_ext h a _⟩ left_inv := by cat_disch right_inv := by cat_disch } theorem hasLimit_iff_hasTerminal_cone (F : J ⥤ C) : HasLimit F ↔ HasTerminal (Cone F) := ⟨fun _ => (Cone.isLimitEquivIsTerminal _ (limit.isLimit F)).hasTerminal, fun h => haveI : HasTerminal (Cone F) := h ⟨⟨⟨⊤_ _, (Cone.isLimitEquivIsTerminal _).symm terminalIsTerminal⟩⟩⟩⟩ theorem hasLimitsOfShape_iff_isLeftAdjoint_const : HasLimitsOfShape J C ↔ IsLeftAdjoint (const J : C ⥤ _) := calc HasLimitsOfShape J C ↔ ∀ F : J ⥤ C, HasLimit F := ⟨fun h => h.has_limit, fun h => HasLimitsOfShape.mk⟩ _ ↔ ∀ F : J ⥤ C, HasTerminal (Cone F) := forall_congr' hasLimit_iff_hasTerminal_cone _ ↔ ∀ F : J ⥤ C, HasTerminal (CostructuredArrow (const J) F) := (forall_congr' fun F => (Cone.equivCostructuredArrow F).hasTerminal_iff) _ ↔ (IsLeftAdjoint (const J : C ⥤ _)) := isLeftAdjoint_iff_hasTerminal_costructuredArrow.symm theorem IsLimit.liftConeMorphism_eq_isTerminal_from {F : J ⥤ C} {c : Cone F} (hc : IsLimit c) (s : Cone F) : hc.liftConeMorphism s = IsTerminal.from (Cone.isLimitEquivIsTerminal _ hc) _ := rfl theorem IsTerminal.from_eq_liftConeMorphism {F : J ⥤ C} {c : Cone F} (hc : IsTerminal c) (s : Cone F) : IsTerminal.from hc s = ((Cone.isLimitEquivIsTerminal _).symm hc).liftConeMorphism s := (IsLimit.liftConeMorphism_eq_isTerminal_from (c.isLimitEquivIsTerminal.symm hc) s).symm /-- If `G : Cone F ⥤ Cone F'` preserves terminal objects, it preserves limit cones. -/ noncomputable def IsLimit.ofPreservesConeTerminal {F : J ⥤ C} {F' : K ⥤ D} (G : Cone F ⥤ Cone F') [PreservesLimit (Functor.empty.{0} _) G] {c : Cone F} (hc : IsLimit c) : IsLimit (G.obj c) := (Cone.isLimitEquivIsTerminal _).symm <| (Cone.isLimitEquivIsTerminal _ hc).isTerminalObj _ _ /-- If `G : Cone F ⥤ Cone F'` reflects terminal objects, it reflects limit cones. -/ noncomputable def IsLimit.ofReflectsConeTerminal {F : J ⥤ C} {F' : K ⥤ D} (G : Cone F ⥤ Cone F') [ReflectsLimit (Functor.empty.{0} _) G] {c : Cone F} (hc : IsLimit (G.obj c)) : IsLimit c := (Cone.isLimitEquivIsTerminal _).symm <| (Cone.isLimitEquivIsTerminal _ hc).isTerminalOfObj _ _ /-- Given a cocone `c` over `F`, we can interpret the legs of `c` as costructured arrows `F.obj - ⟶ c.pt`. -/ @[simps] def Cocone.toCostructuredArrow {F : J ⥤ C} (c : Cocone F) : J ⥤ CostructuredArrow F c.pt where obj j := CostructuredArrow.mk (c.ι.app j) map f := CostructuredArrow.homMk f /-- If `F` has a colimit, then the colimit inclusions can be interpreted as costructured arrows `F.obj - ⟶ colimit F`. -/ @[simps] noncomputable def colimit.toCostructuredArrow (F : J ⥤ C) [HasColimit F] : J ⥤ CostructuredArrow F (colimit F) where obj j := CostructuredArrow.mk (colimit.ι F j) map f := CostructuredArrow.homMk f /-- `Cocone.toCostructuredArrow` can be expressed in terms of `Functor.toCostructuredArrow`. -/ def Cocone.toCostructuredArrowIsoToCostructuredArrow {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ≅ (𝟭 J).toCostructuredArrow F c.pt c.ι.app (by simp) := Iso.refl _ /-- `Functor.toCostructuredArrow` can be expressed in terms of `Cocone.toCostructuredArrow`. -/ def _root_.CategoryTheory.Functor.toCostructuredArrowIsoToCostructuredArrow (G : J ⥤ K) (F : K ⥤ C) (X : C) (f : (Y : J) → F.obj (G.obj Y) ⟶ X) (h : ∀ {Y Z : J} (g : Y ⟶ Z), F.map (G.map g) ≫ f Z = f Y) : G.toCostructuredArrow F X f h ≅ (Cocone.mk X ⟨f, by simp [h]⟩).toCostructuredArrow ⋙ CostructuredArrow.pre _ _ _ := Iso.refl _ /-- Interpreting the legs of a cocone as a costructured arrow and then forgetting the arrow again does nothing. -/ @[simps!] def Cocone.toCostructuredArrowCompProj {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.proj _ _ ≅ 𝟭 J := Iso.refl _ @[simp] lemma Cocone.toCostructuredArrow_comp_proj {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.proj _ _ = 𝟭 J := rfl /-- Interpreting the legs of a cocone as a costructured arrow, interpreting this arrow as an arrow over the cocone point, and finally forgetting the arrow is the same as just applying the functor the cocone was over. -/ @[simps!] def Cocone.toCostructuredArrowCompToOverCompForget {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.toOver _ _ ⋙ Over.forget _ ≅ F := Iso.refl _ @[simp] lemma Cocone.toCostructuredArrow_comp_toOver_comp_forget {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.toOver _ _ ⋙ Over.forget _ = F := rfl /-- A cocone `c` on `F : J ⥤ C` lifts to a cocone in `Over c.pt` with cone point `𝟙 c.pt`. -/ @[simps] def Cocone.toOver {F : J ⥤ C} (c : Cocone F) : Cocone (c.toCostructuredArrow ⋙ CostructuredArrow.toOver _ _) where pt := Over.mk (𝟙 c.pt) ι := { app := fun j => Over.homMk (c.ι.app j) (by simp) } /-- The colimit cocone for `F : J ⥤ C` lifts to a cocone in `Over (colimit F)` with cone point `𝟙 (colimit F)`. This is automatically also a colimit cocone. -/ @[simps] noncomputable def colimit.toOver (F : J ⥤ C) [HasColimit F] : Cocone (colimit.toCostructuredArrow F ⋙ CostructuredArrow.toOver _ _) where pt := Over.mk (𝟙 (colimit F)) ι := { app := fun j => Over.homMk (colimit.ι F j) (by simp) } /-- `c.toOver` is a lift of `c` under the forgetful functor. -/ @[simps!] def Cocone.mapCoconeToOver {F : J ⥤ C} (c : Cocone F) : (Over.forget c.pt).mapCocone c.toOver ≅ c := Iso.refl _ /-- Given a diagram `CostructuredArrow F X`s, we may obtain a cocone with cone point `X`. -/ @[simps!] def Cocone.fromCostructuredArrow (F : C ⥤ D) {X : D} (G : J ⥤ CostructuredArrow F X) : Cocone (G ⋙ CostructuredArrow.proj F X ⋙ F) where pt := X ι := { app := fun j => (G.obj j).hom } /-- Given a cocone `c : Cocone K` and a map `f : F.obj c.X ⟶ X`, we can construct a cocone of costructured arrows over `X` with `f` as the cone point. -/ @[simps] def Cocone.toCostructuredArrowCocone {K : J ⥤ C} (c : Cocone K) (F : C ⥤ D) {X : D} (f : F.obj c.pt ⟶ X) : Cocone ((F.mapCocone c).toCostructuredArrow ⋙ CostructuredArrow.map f ⋙ CostructuredArrow.pre _ _ _) where pt := CostructuredArrow.mk f ι := { app := fun j => CostructuredArrow.homMk (c.ι.app j) rfl } /-- Construct an object of the category `(F ↓ Δ)` from a cocone on `F`. This is part of an equivalence, see `Cocone.equivStructuredArrow`. -/ @[simps] def Cocone.toStructuredArrow (F : J ⥤ C) : Cocone F ⥤ StructuredArrow F (const J) where obj c := StructuredArrow.mk c.ι map f := StructuredArrow.homMk f.hom /-- Construct a cocone on `F` from an object of the category `(F ↓ Δ)`. This is part of an equivalence, see `Cocone.equivStructuredArrow`. -/ @[simps] def Cocone.fromStructuredArrow (F : J ⥤ C) : StructuredArrow F (const J) ⥤ Cocone F where obj c := ⟨c.right, c.hom⟩ map f := { hom := f.right w := fun j => by convert (congr_fun (congr_arg NatTrans.app f.w) j).symm simp } /-- The category of cocones on `F` is just the comma category `(F ↓ Δ)`, where `Δ` is the constant functor. -/ @[simps] def Cocone.equivStructuredArrow (F : J ⥤ C) : Cocone F ≌ StructuredArrow F (const J) where functor := Cocone.toStructuredArrow F inverse := Cocone.fromStructuredArrow F unitIso := NatIso.ofComponents Cocones.eta counitIso := NatIso.ofComponents fun _ => (StructuredArrow.eta _).symm /-- A cocone is a colimit cocone iff it is initial. -/ def Cocone.isColimitEquivIsInitial {F : J ⥤ C} (c : Cocone F) : IsColimit c ≃ IsInitial c := IsColimit.isoUniqueCoconeMorphism.toEquiv.trans { toFun := fun _ => IsInitial.ofUnique _ invFun := fun h s => ⟨⟨IsInitial.to h s⟩, fun a => IsInitial.hom_ext h a _⟩ left_inv := by cat_disch right_inv := by cat_disch } theorem hasColimit_iff_hasInitial_cocone (F : J ⥤ C) : HasColimit F ↔ HasInitial (Cocone F) := ⟨fun _ => (Cocone.isColimitEquivIsInitial _ (colimit.isColimit F)).hasInitial, fun h => haveI : HasInitial (Cocone F) := h ⟨⟨⟨⊥_ _, (Cocone.isColimitEquivIsInitial _).symm initialIsInitial⟩⟩⟩⟩ theorem hasColimitsOfShape_iff_isRightAdjoint_const : HasColimitsOfShape J C ↔ IsRightAdjoint (const J : C ⥤ _) := calc HasColimitsOfShape J C ↔ ∀ F : J ⥤ C, HasColimit F := ⟨fun h => h.has_colimit, fun h => HasColimitsOfShape.mk⟩ _ ↔ ∀ F : J ⥤ C, HasInitial (Cocone F) := forall_congr' hasColimit_iff_hasInitial_cocone _ ↔ ∀ F : J ⥤ C, HasInitial (StructuredArrow F (const J)) := (forall_congr' fun F => (Cocone.equivStructuredArrow F).hasInitial_iff) _ ↔ (IsRightAdjoint (const J : C ⥤ _)) := isRightAdjoint_iff_hasInitial_structuredArrow.symm theorem IsColimit.descCoconeMorphism_eq_isInitial_to {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (s : Cocone F) : hc.descCoconeMorphism s = IsInitial.to (Cocone.isColimitEquivIsInitial _ hc) _ := rfl theorem IsInitial.to_eq_descCoconeMorphism {F : J ⥤ C} {c : Cocone F} (hc : IsInitial c) (s : Cocone F) : IsInitial.to hc s = ((Cocone.isColimitEquivIsInitial _).symm hc).descCoconeMorphism s := (IsColimit.descCoconeMorphism_eq_isInitial_to (c.isColimitEquivIsInitial.symm hc) s).symm /-- If `G : Cocone F ⥤ Cocone F'` preserves initial objects, it preserves colimit cocones. -/ noncomputable def IsColimit.ofPreservesCoconeInitial {F : J ⥤ C} {F' : K ⥤ D} (G : Cocone F ⥤ Cocone F') [PreservesColimit (Functor.empty.{0} _) G] {c : Cocone F} (hc : IsColimit c) : IsColimit (G.obj c) := (Cocone.isColimitEquivIsInitial _).symm <| (Cocone.isColimitEquivIsInitial _ hc).isInitialObj _ _ /-- If `G : Cocone F ⥤ Cocone F'` reflects initial objects, it reflects colimit cocones. -/ noncomputable def IsColimit.ofReflectsCoconeInitial {F : J ⥤ C} {F' : K ⥤ D} (G : Cocone F ⥤ Cocone F') [ReflectsColimit (Functor.empty.{0} _) G] {c : Cocone F} (hc : IsColimit (G.obj c)) : IsColimit c := (Cocone.isColimitEquivIsInitial _).symm <| (Cocone.isColimitEquivIsInitial _ hc).isInitialOfObj _ _ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FullSubcategory.lean
import Mathlib.CategoryTheory.ObjectProperty.LimitsOfShape import Mathlib.CategoryTheory.ObjectProperty.ColimitsOfShape /-! # Limits in full subcategories If a property of objects `P` is closed under taking limits, then limits in `FullSubcategory P` can be constructed from limits in `C`. More precisely, the inclusion creates such limits. -/ noncomputable section universe w' w v v₁ v₂ u u₁ u₂ open CategoryTheory namespace CategoryTheory.Limits section variable {J : Type w} [Category.{w'} J] {C : Type u} [Category.{v} C] {P : ObjectProperty C} /-- If a `J`-shaped diagram in `FullSubcategory P` has a limit cone in `C` whose cone point lives in the full subcategory, then this defines a limit in the full subcategory. -/ def createsLimitFullSubcategoryInclusion' (F : J ⥤ P.FullSubcategory) {c : Cone (F ⋙ P.ι)} (hc : IsLimit c) (h : P c.pt) : CreatesLimit F P.ι := createsLimitOfFullyFaithfulOfIso' hc ⟨_, h⟩ (Iso.refl _) /-- If a `J`-shaped diagram in `FullSubcategory P` has a limit in `C` whose cone point lives in the full subcategory, then this defines a limit in the full subcategory. -/ def createsLimitFullSubcategoryInclusion (F : J ⥤ P.FullSubcategory) [HasLimit (F ⋙ P.ι)] (h : P (limit (F ⋙ P.ι))) : CreatesLimit F P.ι := createsLimitFullSubcategoryInclusion' F (limit.isLimit _) h /-- If a `J`-shaped diagram in `FullSubcategory P` has a colimit cocone in `C` whose cocone point lives in the full subcategory, then this defines a colimit in the full subcategory. -/ def createsColimitFullSubcategoryInclusion' (F : J ⥤ P.FullSubcategory) {c : Cocone (F ⋙ P.ι)} (hc : IsColimit c) (h : P c.pt) : CreatesColimit F P.ι := createsColimitOfFullyFaithfulOfIso' hc ⟨_, h⟩ (Iso.refl _) /-- If a `J`-shaped diagram in `FullSubcategory P` has a colimit in `C` whose cocone point lives in the full subcategory, then this defines a colimit in the full subcategory. -/ def createsColimitFullSubcategoryInclusion (F : J ⥤ P.FullSubcategory) [HasColimit (F ⋙ P.ι)] (h : P (colimit (F ⋙ P.ι))) : CreatesColimit F P.ι := createsColimitFullSubcategoryInclusion' F (colimit.isColimit _) h variable (P J) /-- If `P` is closed under limits of shape `J`, then the inclusion creates such limits. -/ def createsLimitFullSubcategoryInclusionOfClosed [P.IsClosedUnderLimitsOfShape J] (F : J ⥤ P.FullSubcategory) [HasLimit (F ⋙ P.ι)] : CreatesLimit F P.ι := createsLimitFullSubcategoryInclusion F (P.prop_limit _ fun j => (F.obj j).property) /-- If `P` is closed under limits of shape `J`, then the inclusion creates such limits. -/ instance createsLimitsOfShapeFullSubcategoryInclusion [P.IsClosedUnderLimitsOfShape J] [HasLimitsOfShape J C] : CreatesLimitsOfShape J P.ι where CreatesLimit := @fun F => createsLimitFullSubcategoryInclusionOfClosed J P F theorem hasLimit_of_closedUnderLimits [P.IsClosedUnderLimitsOfShape J] (F : J ⥤ P.FullSubcategory) [HasLimit (F ⋙ P.ι)] : HasLimit F := have : CreatesLimit F P.ι := createsLimitFullSubcategoryInclusionOfClosed J P F hasLimit_of_created F P.ι instance hasLimitsOfShape_of_closedUnderLimits [P.IsClosedUnderLimitsOfShape J] [HasLimitsOfShape J C] : HasLimitsOfShape J P.FullSubcategory := { has_limit := fun F => hasLimit_of_closedUnderLimits J P F } /-- If `P` is closed under colimits of shape `J`, then the inclusion creates such colimits. -/ def createsColimitFullSubcategoryInclusionOfClosed [P.IsClosedUnderColimitsOfShape J] (F : J ⥤ P.FullSubcategory) [HasColimit (F ⋙ P.ι)] : CreatesColimit F P.ι := createsColimitFullSubcategoryInclusion F (P.prop_colimit _ fun j => (F.obj j).property) /-- If `P` is closed under colimits of shape `J`, then the inclusion creates such colimits. -/ instance createsColimitsOfShapeFullSubcategoryInclusion [P.IsClosedUnderColimitsOfShape J] [HasColimitsOfShape J C] : CreatesColimitsOfShape J P.ι where CreatesColimit := @fun F => createsColimitFullSubcategoryInclusionOfClosed J P F theorem hasColimit_of_closedUnderColimits [P.IsClosedUnderColimitsOfShape J] (F : J ⥤ P.FullSubcategory) [HasColimit (F ⋙ P.ι)] : HasColimit F := have : CreatesColimit F P.ι := createsColimitFullSubcategoryInclusionOfClosed J P F hasColimit_of_created F P.ι instance hasColimitsOfShape_of_closedUnderColimits [P.IsClosedUnderColimitsOfShape J] [HasColimitsOfShape J C] : HasColimitsOfShape J P.FullSubcategory := { has_colimit := fun F => hasColimit_of_closedUnderColimits J P F } end variable {J : Type w} [Category.{w'} J] variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (F : C ⥤ D) /-- The essential image of a functor is closed under the limits it preserves. -/ instance [HasLimitsOfShape J C] [PreservesLimitsOfShape J F] [F.Full] [F.Faithful] : F.essImage.IsClosedUnderLimitsOfShape J := .mk' (by rintro _ ⟨G, hG⟩ exact ⟨limit (Functor.essImage.liftFunctor G F hG), ⟨IsLimit.conePointsIsoOfNatIso (isLimitOfPreserves F (limit.isLimit _)) (limit.isLimit _) (Functor.essImage.liftFunctorCompIso _ _ _)⟩⟩) /-- The essential image of a functor is closed under the colimits it preserves. -/ instance [HasColimitsOfShape J C] [PreservesColimitsOfShape J F] [F.Full] [F.Faithful] : F.essImage.IsClosedUnderColimitsOfShape J := .mk' (by rintro _ ⟨G, hG⟩ exact ⟨colimit (Functor.essImage.liftFunctor G F hG), ⟨IsColimit.coconePointsIsoOfNatIso (isColimitOfPreserves F (colimit.isColimit _)) (colimit.isColimit _) (Functor.essImage.liftFunctorCompIso _ _ _)⟩⟩) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Creates.lean
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Creating (co)limits We say that `F` creates limits of `K` if, given any limit cone `c` for `K ⋙ F` (i.e. below) we can lift it to a cone "above", and further that `F` reflects limits for `K`. -/ open CategoryTheory CategoryTheory.Limits CategoryTheory.Functor noncomputable section namespace CategoryTheory universe w' w'₁ w w₁ v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] section Creates variable {D : Type u₂} [Category.{v₂} D] variable {J : Type w} [Category.{w'} J] {K : J ⥤ C} /-- Define the lift of a cone: For a cone `c` for `K ⋙ F`, give a cone for `K` which is a lift of `c`, i.e. the image of it under `F` is (iso) to `c`. We will then use this as part of the definition of creation of limits: every limit cone has a lift. Note this definition is really only useful when `c` is a limit already. -/ structure LiftableCone (K : J ⥤ C) (F : C ⥤ D) (c : Cone (K ⋙ F)) where /-- a cone in the source category of the functor -/ liftedCone : Cone K /-- the isomorphism expressing that `liftedCone` lifts the given cone -/ validLift : F.mapCone liftedCone ≅ c /-- Define the lift of a cocone: For a cocone `c` for `K ⋙ F`, give a cocone for `K` which is a lift of `c`, i.e. the image of it under `F` is (iso) to `c`. We will then use this as part of the definition of creation of colimits: every limit cocone has a lift. Note this definition is really only useful when `c` is a colimit already. -/ structure LiftableCocone (K : J ⥤ C) (F : C ⥤ D) (c : Cocone (K ⋙ F)) where /-- a cocone in the source category of the functor -/ liftedCocone : Cocone K /-- the isomorphism expressing that `liftedCocone` lifts the given cocone -/ validLift : F.mapCocone liftedCocone ≅ c /-- Definition 3.3.1 of [Riehl]. We say that `F` creates limits of `K` if, given any limit cone `c` for `K ⋙ F` (i.e. below) we can lift it to a cone "above", and further that `F` reflects limits for `K`. If `F` reflects isomorphisms, it suffices to show only that the lifted cone is a limit - see `createsLimitOfReflectsIso`. -/ class CreatesLimit (K : J ⥤ C) (F : C ⥤ D) extends ReflectsLimit K F where /-- any limit cone can be lifted to a cone above -/ lifts : ∀ c, IsLimit c → LiftableCone K F c /-- `F` creates limits of shape `J` if `F` creates the limit of any diagram `K : J ⥤ C`. -/ class CreatesLimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where CreatesLimit : ∀ {K : J ⥤ C}, CreatesLimit K F := by infer_instance -- This should be used with explicit universe variables. /-- `F` creates limits if it creates limits of shape `J` for any `J`. -/ @[nolint checkUnivs, pp_with_univ] class CreatesLimitsOfSize (F : C ⥤ D) where CreatesLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesLimitsOfShape J F := by infer_instance /-- `F` creates small limits if it creates limits of shape `J` for any small `J`. -/ abbrev CreatesLimits (F : C ⥤ D) := CreatesLimitsOfSize.{v₂, v₂} F /-- Dual of definition 3.3.1 of [Riehl]. We say that `F` creates colimits of `K` if, given any limit cocone `c` for `K ⋙ F` (i.e. below) we can lift it to a cocone "above", and further that `F` reflects limits for `K`. If `F` reflects isomorphisms, it suffices to show only that the lifted cocone is a limit - see `createsColimitOfReflectsIso`. -/ class CreatesColimit (K : J ⥤ C) (F : C ⥤ D) extends ReflectsColimit K F where /-- any limit cocone can be lifted to a cocone above -/ lifts : ∀ c, IsColimit c → LiftableCocone K F c /-- `F` creates colimits of shape `J` if `F` creates the colimit of any diagram `K : J ⥤ C`. -/ class CreatesColimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where CreatesColimit : ∀ {K : J ⥤ C}, CreatesColimit K F := by infer_instance -- This should be used with explicit universe variables. /-- `F` creates colimits if it creates colimits of shape `J` for any small `J`. -/ @[nolint checkUnivs, pp_with_univ] class CreatesColimitsOfSize (F : C ⥤ D) where CreatesColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesColimitsOfShape J F := by infer_instance /-- `F` creates small colimits if it creates colimits of shape `J` for any small `J`. -/ abbrev CreatesColimits (F : C ⥤ D) := CreatesColimitsOfSize.{v₂, v₂} F -- see Note [lower instance priority] attribute [instance 100] CreatesLimitsOfShape.CreatesLimit CreatesLimitsOfSize.CreatesLimitsOfShape CreatesColimitsOfShape.CreatesColimit CreatesColimitsOfSize.CreatesColimitsOfShape -- see Note [lower instance priority] -- Interface to the `CreatesLimit` class. /-- `liftLimit t` is the cone for `K` given by lifting the limit `t` for `K ⋙ F`. -/ def liftLimit {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) : Cone K := (CreatesLimit.lifts c t).liftedCone /-- The lifted cone has an image isomorphic to the original cone. -/ def liftedLimitMapsToOriginal {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) : F.mapCone (liftLimit t) ≅ c := (CreatesLimit.lifts c t).validLift lemma liftedLimitMapsToOriginal_inv_map_π {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) (j : J) : (liftedLimitMapsToOriginal t).inv.hom ≫ F.map ((liftLimit t).π.app j) = c.π.app j := by rw [show F.map ((liftLimit t).π.app j) = (liftedLimitMapsToOriginal t).hom.hom ≫ c.π.app j from (by simp), ← Category.assoc, ← Cone.category_comp_hom] simp lemma liftedLimitMapsToOriginal_hom_π {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) (j : J) : (liftedLimitMapsToOriginal t).hom.hom ≫ c.π.app j = F.map ((liftLimit t).π.app j) := by rw [← liftedLimitMapsToOriginal_inv_map_π (t := t)] simp only [Functor.mapCone_pt, Functor.comp_obj, ← Category.assoc, ← Cone.category_comp_hom, Iso.hom_inv_id, Cone.category_id_hom, Category.id_comp, Functor.const_obj_obj] /-- The lifted cone is a limit. -/ def liftedLimitIsLimit {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) : IsLimit (liftLimit t) := isLimitOfReflects _ (IsLimit.ofIsoLimit t (liftedLimitMapsToOriginal t).symm) /-- If `F` creates the limit of `K` and `K ⋙ F` has a limit, then `K` has a limit. -/ theorem hasLimit_of_created (K : J ⥤ C) (F : C ⥤ D) [HasLimit (K ⋙ F)] [CreatesLimit K F] : HasLimit K := HasLimit.mk { cone := liftLimit (limit.isLimit (K ⋙ F)) isLimit := liftedLimitIsLimit _ } /-- If `F` creates limits of shape `J`, and `D` has limits of shape `J`, then `C` has limits of shape `J`. -/ theorem hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (F : C ⥤ D) [HasLimitsOfShape J D] [CreatesLimitsOfShape J F] : HasLimitsOfShape J C := ⟨fun G => hasLimit_of_created G F⟩ /-- If `F` creates limits, and `D` has all limits, then `C` has all limits. -/ theorem hasLimits_of_hasLimits_createsLimits (F : C ⥤ D) [HasLimitsOfSize.{w, w'} D] [CreatesLimitsOfSize.{w, w'} F] : HasLimitsOfSize.{w, w'} C := ⟨fun _ _ => hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape F⟩ -- Interface to the `CreatesColimit` class. /-- `liftColimit t` is the cocone for `K` given by lifting the colimit `t` for `K ⋙ F`. -/ def liftColimit {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)} (t : IsColimit c) : Cocone K := (CreatesColimit.lifts c t).liftedCocone /-- The lifted cocone has an image isomorphic to the original cocone. -/ def liftedColimitMapsToOriginal {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)} (t : IsColimit c) : F.mapCocone (liftColimit t) ≅ c := (CreatesColimit.lifts c t).validLift /-- The lifted cocone is a colimit. -/ def liftedColimitIsColimit {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)} (t : IsColimit c) : IsColimit (liftColimit t) := isColimitOfReflects _ (IsColimit.ofIsoColimit t (liftedColimitMapsToOriginal t).symm) /-- If `F` creates the limit of `K` and `K ⋙ F` has a limit, then `K` has a limit. -/ theorem hasColimit_of_created (K : J ⥤ C) (F : C ⥤ D) [HasColimit (K ⋙ F)] [CreatesColimit K F] : HasColimit K := HasColimit.mk { cocone := liftColimit (colimit.isColimit (K ⋙ F)) isColimit := liftedColimitIsColimit _ } /-- If `F` creates colimits of shape `J`, and `D` has colimits of shape `J`, then `C` has colimits of shape `J`. -/ theorem hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape (F : C ⥤ D) [HasColimitsOfShape J D] [CreatesColimitsOfShape J F] : HasColimitsOfShape J C := ⟨fun G => hasColimit_of_created G F⟩ /-- If `F` creates colimits, and `D` has all colimits, then `C` has all colimits. -/ theorem hasColimits_of_hasColimits_createsColimits (F : C ⥤ D) [HasColimitsOfSize.{w, w'} D] [CreatesColimitsOfSize.{w, w'} F] : HasColimitsOfSize.{w, w'} C := ⟨fun _ _ => hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape F⟩ instance (priority := 10) reflectsLimitsOfShapeOfCreatesLimitsOfShape (F : C ⥤ D) [CreatesLimitsOfShape J F] : ReflectsLimitsOfShape J F where instance (priority := 10) reflectsLimitsOfCreatesLimits (F : C ⥤ D) [CreatesLimitsOfSize.{w, w'} F] : ReflectsLimitsOfSize.{w, w'} F where instance (priority := 10) reflectsColimitsOfShapeOfCreatesColimitsOfShape (F : C ⥤ D) [CreatesColimitsOfShape J F] : ReflectsColimitsOfShape J F where instance (priority := 10) reflectsColimitsOfCreatesColimits (F : C ⥤ D) [CreatesColimitsOfSize.{w, w'} F] : ReflectsColimitsOfSize.{w, w'} F where /-- A helper to show a functor creates limits. In particular, if we can show that for any limit cone `c` for `K ⋙ F`, there is a lift of it which is a limit and `F` reflects isomorphisms, then `F` creates limits. Usually, `F` creating limits says that _any_ lift of `c` is a limit, but here we only need to show that our particular lift of `c` is a limit. -/ structure LiftsToLimit (K : J ⥤ C) (F : C ⥤ D) (c : Cone (K ⋙ F)) (t : IsLimit c) extends LiftableCone K F c where /-- the lifted cone is limit -/ makesLimit : IsLimit liftedCone /-- A helper to show a functor creates colimits. In particular, if we can show that for any limit cocone `c` for `K ⋙ F`, there is a lift of it which is a limit and `F` reflects isomorphisms, then `F` creates colimits. Usually, `F` creating colimits says that _any_ lift of `c` is a colimit, but here we only need to show that our particular lift of `c` is a colimit. -/ structure LiftsToColimit (K : J ⥤ C) (F : C ⥤ D) (c : Cocone (K ⋙ F)) (t : IsColimit c) extends LiftableCocone K F c where /-- the lifted cocone is colimit -/ makesColimit : IsColimit liftedCocone /-- If `F` reflects isomorphisms and we can lift any limit cone to a limit cone, then `F` creates limits. In particular here we don't need to assume that F reflects limits. -/ def createsLimitOfReflectsIso {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] (h : ∀ c t, LiftsToLimit K F c t) : CreatesLimit K F where lifts c t := (h c t).toLiftableCone toReflectsLimit := { reflects := fun {d} hd => ⟨by let d' : Cone K := (h (F.mapCone d) hd).toLiftableCone.liftedCone let i : F.mapCone d' ≅ F.mapCone d := (h (F.mapCone d) hd).toLiftableCone.validLift let hd' : IsLimit d' := (h (F.mapCone d) hd).makesLimit let f : d ⟶ d' := hd'.liftConeMorphism d have : (Cones.functoriality K F).map f = i.inv := (hd.ofIsoLimit i.symm).uniq_cone_morphism haveI : IsIso ((Cones.functoriality K F).map f) := by rw [this] infer_instance haveI : IsIso f := isIso_of_reflects_iso f (Cones.functoriality K F) exact IsLimit.ofIsoLimit hd' (asIso f).symm⟩ } /-- If `F` reflects isomorphisms and we can lift a single limit cone to a limit cone, then `F` creates limits. Note that unlike `createsLimitOfReflectsIso`, to apply this result it is necessary to know that `K ⋙ F` actually has a limit. -/ def createsLimitOfReflectsIso' {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] {c : Cone (K ⋙ F)} (hc : IsLimit c) (h : LiftsToLimit K F c hc) : CreatesLimit K F := createsLimitOfReflectsIso fun _ t => { liftedCone := h.liftedCone validLift := h.validLift ≪≫ IsLimit.uniqueUpToIso hc t makesLimit := h.makesLimit } /-- If `F` reflects isomorphisms, and we already know that the limit exists in the source and `F` preserves it, then `F` creates that limit. -/ def createsLimitOfReflectsIsomorphismsOfPreserves {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] [HasLimit K] [PreservesLimit K F] : CreatesLimit K F := createsLimitOfReflectsIso' (isLimitOfPreserves F (limit.isLimit _)) ⟨⟨_, Iso.refl _⟩, limit.isLimit _⟩ -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the limit for `K` it suffices to exhibit a lift of a limit cone for `K ⋙ F`. -/ def createsLimitOfFullyFaithfulOfLift' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cone (K ⋙ F)} (hl : IsLimit l) (c : Cone K) (i : F.mapCone c ≅ l) : CreatesLimit K F := createsLimitOfReflectsIso' hl ⟨⟨c, i⟩, isLimitOfReflects F (IsLimit.ofIsoLimit hl i.symm)⟩ -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasLimit (K ⋙ F)`, to show that `F` creates the limit for `K` it suffices to exhibit a lift of the chosen limit cone for `K ⋙ F`. -/ def createsLimitOfFullyFaithfulOfLift {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasLimit (K ⋙ F)] (c : Cone K) (i : F.mapCone c ≅ limit.cone (K ⋙ F)) : CreatesLimit K F := createsLimitOfFullyFaithfulOfLift' (limit.isLimit _) c i -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the limit for `K` it suffices to show that a limit point is in the essential image of `F`. -/ def createsLimitOfFullyFaithfulOfIso' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cone (K ⋙ F)} (hl : IsLimit l) (X : C) (i : F.obj X ≅ l.pt) : CreatesLimit K F := createsLimitOfFullyFaithfulOfLift' hl { pt := X π := { app := fun j => F.preimage (i.hom ≫ l.π.app j) naturality := fun Y Z f => F.map_injective <| by simpa using (l.w f).symm } } (Cones.ext i fun j => by simp only [Functor.map_preimage, Functor.mapCone_π_app]) -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasLimit (K ⋙ F)`, to show that `F` creates the limit for `K` it suffices to show that the chosen limit point is in the essential image of `F`. -/ def createsLimitOfFullyFaithfulOfIso {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasLimit (K ⋙ F)] (X : C) (i : F.obj X ≅ limit (K ⋙ F)) : CreatesLimit K F := createsLimitOfFullyFaithfulOfIso' (limit.isLimit _) X i /-- A fully faithful functor that preserves a limit that exists also creates the limit. -/ def createsLimitOfFullyFaithfulOfPreserves {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasLimit K] [PreservesLimit K F] : CreatesLimit K F := createsLimitOfFullyFaithfulOfLift' (isLimitOfPreserves _ (limit.isLimit K)) _ (Iso.refl _) -- see Note [lower instance priority] /-- `F` preserves the limit of `K` if it creates the limit and `K ⋙ F` has the limit. -/ instance (priority := 100) preservesLimit_of_createsLimit_and_hasLimit (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] [HasLimit (K ⋙ F)] : PreservesLimit K F where preserves t := ⟨IsLimit.ofIsoLimit (limit.isLimit _) ((liftedLimitMapsToOriginal (limit.isLimit _)).symm ≪≫ (Cones.functoriality K F).mapIso ((liftedLimitIsLimit (limit.isLimit _)).uniqueUpToIso t))⟩ -- see Note [lower instance priority] /-- `F` preserves the limit of shape `J` if it creates these limits and `D` has them. -/ instance (priority := 100) preservesLimitOfShape_of_createsLimitsOfShape_and_hasLimitsOfShape (F : C ⥤ D) [CreatesLimitsOfShape J F] [HasLimitsOfShape J D] : PreservesLimitsOfShape J F where -- see Note [lower instance priority] /-- `F` preserves limits if it creates limits and `D` has limits. -/ instance (priority := 100) preservesLimits_of_createsLimits_and_hasLimits (F : C ⥤ D) [CreatesLimitsOfSize.{w, w'} F] [HasLimitsOfSize.{w, w'} D] : PreservesLimitsOfSize.{w, w'} F where /-- If `F` reflects isomorphisms and we can lift any colimit cocone to a colimit cocone, then `F` creates colimits. In particular here we don't need to assume that F reflects colimits. -/ def createsColimitOfReflectsIso {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] (h : ∀ c t, LiftsToColimit K F c t) : CreatesColimit K F where lifts c t := (h c t).toLiftableCocone toReflectsColimit := { reflects := fun {d} hd => ⟨by let d' : Cocone K := (h (F.mapCocone d) hd).toLiftableCocone.liftedCocone let i : F.mapCocone d' ≅ F.mapCocone d := (h (F.mapCocone d) hd).toLiftableCocone.validLift let hd' : IsColimit d' := (h (F.mapCocone d) hd).makesColimit let f : d' ⟶ d := hd'.descCoconeMorphism d have : (Cocones.functoriality K F).map f = i.hom := (hd.ofIsoColimit i.symm).uniq_cocone_morphism haveI : IsIso ((Cocones.functoriality K F).map f) := by rw [this] infer_instance haveI := isIso_of_reflects_iso f (Cocones.functoriality K F) exact IsColimit.ofIsoColimit hd' (asIso f)⟩ } /-- If `F` reflects isomorphisms and we can lift a single colimit cocone to a colimit cocone, then `F` creates limits. Note that unlike `createsColimitOfReflectsIso`, to apply this result it is necessary to know that `K ⋙ F` actually has a colimit. -/ def createsColimitOfReflectsIso' {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] {c : Cocone (K ⋙ F)} (hc : IsColimit c) (h : LiftsToColimit K F c hc) : CreatesColimit K F := createsColimitOfReflectsIso fun _ t => { liftedCocone := h.liftedCocone validLift := h.validLift ≪≫ IsColimit.uniqueUpToIso hc t makesColimit := h.makesColimit } /-- If `F` reflects isomorphisms, and we already know that the colimit exists in the source and `F` preserves it, then `F` creates that colimit. -/ def createsColimitOfReflectsIsomorphismsOfPreserves {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] [HasColimit K] [PreservesColimit K F] : CreatesColimit K F := createsColimitOfReflectsIso' (isColimitOfPreserves F (colimit.isColimit _)) ⟨⟨_, Iso.refl _⟩, colimit.isColimit _⟩ -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the colimit for `K` it suffices to exhibit a lift of a colimit cocone for `K ⋙ F`. -/ def createsColimitOfFullyFaithfulOfLift' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cocone (K ⋙ F)} (hl : IsColimit l) (c : Cocone K) (i : F.mapCocone c ≅ l) : CreatesColimit K F := createsColimitOfReflectsIso' hl ⟨⟨c, i⟩, isColimitOfReflects F (IsColimit.ofIsoColimit hl i.symm)⟩ -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasColimit (K ⋙ F)`, to show that `F` creates the colimit for `K` it suffices to exhibit a lift of the chosen colimit cocone for `K ⋙ F`. -/ def createsColimitOfFullyFaithfulOfLift {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasColimit (K ⋙ F)] (c : Cocone K) (i : F.mapCocone c ≅ colimit.cocone (K ⋙ F)) : CreatesColimit K F := createsColimitOfFullyFaithfulOfLift' (colimit.isColimit _) c i -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the colimit for `K` it suffices to show that a colimit point is in the essential image of `F`. -/ def createsColimitOfFullyFaithfulOfIso' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cocone (K ⋙ F)} (hl : IsColimit l) (X : C) (i : F.obj X ≅ l.pt) : CreatesColimit K F := createsColimitOfFullyFaithfulOfLift' hl { pt := X ι := { app := fun j => F.preimage (l.ι.app j ≫ i.inv) naturality := fun Y Z f => F.map_injective <| by simpa [← cancel_mono i.hom] using l.w f } } (Cocones.ext i fun j => by simp) -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasColimit (K ⋙ F)`, to show that `F` creates the colimit for `K` it suffices to show that the chosen colimit point is in the essential image of `F`. -/ def createsColimitOfFullyFaithfulOfIso {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasColimit (K ⋙ F)] (X : C) (i : F.obj X ≅ colimit (K ⋙ F)) : CreatesColimit K F := createsColimitOfFullyFaithfulOfIso' (colimit.isColimit _) X i -- see Note [lower instance priority] /-- `F` preserves the colimit of `K` if it creates the colimit and `K ⋙ F` has the colimit. -/ instance (priority := 100) preservesColimit_of_createsColimit_and_hasColimit (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] [HasColimit (K ⋙ F)] : PreservesColimit K F where preserves t := ⟨IsColimit.ofIsoColimit (colimit.isColimit _) ((liftedColimitMapsToOriginal (colimit.isColimit _)).symm ≪≫ (Cocones.functoriality K F).mapIso ((liftedColimitIsColimit (colimit.isColimit _)).uniqueUpToIso t))⟩ -- see Note [lower instance priority] /-- `F` preserves the colimit of shape `J` if it creates these colimits and `D` has them. -/ instance (priority := 100) preservesColimitOfShape_of_createsColimitsOfShape_and_hasColimitsOfShape (F : C ⥤ D) [CreatesColimitsOfShape J F] [HasColimitsOfShape J D] : PreservesColimitsOfShape J F where -- see Note [lower instance priority] /-- `F` preserves limits if it creates limits and `D` has limits. -/ instance (priority := 100) preservesColimits_of_createsColimits_and_hasColimits (F : C ⥤ D) [CreatesColimitsOfSize.{w, w'} F] [HasColimitsOfSize.{w, w'} D] : PreservesColimitsOfSize.{w, w'} F where /-- Transfer creation of limits along a natural isomorphism in the diagram. -/ def createsLimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [CreatesLimit K₁ F] : CreatesLimit K₂ F := { reflectsLimit_of_iso_diagram F h with lifts := fun c t => let t' := (IsLimit.postcomposeInvEquiv (isoWhiskerRight h F :) c).symm t { liftedCone := (Cones.postcompose h.hom).obj (liftLimit t') validLift := Functor.mapConePostcompose F ≪≫ (Cones.postcompose (isoWhiskerRight h F).hom).mapIso (liftedLimitMapsToOriginal t') ≪≫ Cones.ext (Iso.refl _) fun j => by dsimp rw [Category.assoc, ← F.map_comp] simp } } /-- If `F` creates the limit of `K` and `F ≅ G`, then `G` creates the limit of `K`. -/ def createsLimitOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimit K F] : CreatesLimit K G where lifts c t := { liftedCone := liftLimit ((IsLimit.postcomposeInvEquiv (isoWhiskerLeft K h :) c).symm t) validLift := by refine (IsLimit.mapConeEquiv h ?_).uniqueUpToIso t apply IsLimit.ofIsoLimit _ (liftedLimitMapsToOriginal _).symm apply (IsLimit.postcomposeInvEquiv _ _).symm t } toReflectsLimit := reflectsLimit_of_natIso _ h /-- If `F` creates limits of shape `J` and `F ≅ G`, then `G` creates limits of shape `J`. -/ def createsLimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimitsOfShape J F] : CreatesLimitsOfShape J G where CreatesLimit := createsLimitOfNatIso h /-- If `F` creates limits and `F ≅ G`, then `G` creates limits. -/ def createsLimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimitsOfSize.{w, w'} F] : CreatesLimitsOfSize.{w, w'} G where CreatesLimitsOfShape := createsLimitsOfShapeOfNatIso h /-- If `F` creates limits of shape `J` and `J ≌ J'`, then `F` creates limits of shape `J'`. -/ def createsLimitsOfShapeOfEquiv {J' : Type w₁} [Category.{w'₁} J'] (e : J ≌ J') (F : C ⥤ D) [CreatesLimitsOfShape J F] : CreatesLimitsOfShape J' F where CreatesLimit {K} := { lifts c hc := by refine ⟨(Cones.whiskeringEquivalence e).inverse.obj (liftLimit (hc.whiskerEquivalence e)), ?_⟩ letI inner := (Cones.whiskeringEquivalence (F := K ⋙ F) e).inverse.mapIso (liftedLimitMapsToOriginal (K := e.functor ⋙ K) (hc.whiskerEquivalence e)) refine ?_ ≪≫ inner ≪≫ ((Cones.whiskeringEquivalence e).unitIso.app c).symm exact Cones.ext (Iso.refl _) toReflectsLimit := have := reflectsLimitsOfShape_of_equiv e F; inferInstance } /-- Transfer creation of colimits along a natural isomorphism in the diagram. -/ def createsColimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [CreatesColimit K₁ F] : CreatesColimit K₂ F := { reflectsColimit_of_iso_diagram F h with lifts := fun c t => let t' := (IsColimit.precomposeHomEquiv (isoWhiskerRight h F :) c).symm t { liftedCocone := (Cocones.precompose h.inv).obj (liftColimit t') validLift := Functor.mapCoconePrecompose F ≪≫ (Cocones.precompose (isoWhiskerRight h F).inv).mapIso (liftedColimitMapsToOriginal t') ≪≫ Cocones.ext (Iso.refl _) fun j => by dsimp rw [← F.map_comp_assoc] simp } } /-- If `F` creates the colimit of `K` and `F ≅ G`, then `G` creates the colimit of `K`. -/ def createsColimitOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimit K F] : CreatesColimit K G where lifts c t := { liftedCocone := liftColimit ((IsColimit.precomposeHomEquiv (isoWhiskerLeft K h :) c).symm t) validLift := by refine (IsColimit.mapCoconeEquiv h ?_).uniqueUpToIso t apply IsColimit.ofIsoColimit _ (liftedColimitMapsToOriginal _).symm apply (IsColimit.precomposeHomEquiv _ _).symm t } toReflectsColimit := reflectsColimit_of_natIso _ h /-- If `F` creates colimits of shape `J` and `F ≅ G`, then `G` creates colimits of shape `J`. -/ def createsColimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimitsOfShape J F] : CreatesColimitsOfShape J G where CreatesColimit := createsColimitOfNatIso h /-- If `F` creates colimits and `F ≅ G`, then `G` creates colimits. -/ def createsColimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimitsOfSize.{w, w'} F] : CreatesColimitsOfSize.{w, w'} G where CreatesColimitsOfShape := createsColimitsOfShapeOfNatIso h /-- If `F` creates colimits of shape `J` and `J ≌ J'`, then `F` creates colimits of shape `J'`. -/ def createsColimitsOfShapeOfEquiv {J' : Type w₁} [Category.{w'₁} J'] (e : J ≌ J') (F : C ⥤ D) [CreatesColimitsOfShape J F] : CreatesColimitsOfShape J' F where CreatesColimit {K} := { lifts c hc := by refine ⟨(Cocones.whiskeringEquivalence e).inverse.obj (liftColimit (hc.whiskerEquivalence e)), ?_⟩ letI inner := (Cocones.whiskeringEquivalence (F := K ⋙ F) e).inverse.mapIso (liftedColimitMapsToOriginal (K := e.functor ⋙ K) (hc.whiskerEquivalence e)) refine ?_ ≪≫ inner ≪≫ ((Cocones.whiskeringEquivalence e).unitIso.app c).symm exact Cocones.ext (Iso.refl _) toReflectsColimit := have := reflectsColimitsOfShape_of_equiv e F; inferInstance } -- For the inhabited linter later. /-- If F creates the limit of K, any cone lifts to a limit. -/ def liftsToLimitOfCreates (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] (c : Cone (K ⋙ F)) (t : IsLimit c) : LiftsToLimit K F c t where liftedCone := liftLimit t validLift := liftedLimitMapsToOriginal t makesLimit := liftedLimitIsLimit t -- For the inhabited linter later. /-- If F creates the colimit of K, any cocone lifts to a colimit. -/ def liftsToColimitOfCreates (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] (c : Cocone (K ⋙ F)) (t : IsColimit c) : LiftsToColimit K F c t where liftedCocone := liftColimit t validLift := liftedColimitMapsToOriginal t makesColimit := liftedColimitIsColimit t /-- Any cone lifts through the identity functor. -/ def idLiftsCone (c : Cone (K ⋙ 𝟭 C)) : LiftableCone K (𝟭 C) c where liftedCone := { pt := c.pt π := c.π ≫ K.rightUnitor.hom } validLift := Cones.ext (Iso.refl _) /-- The identity functor creates all limits. -/ instance idCreatesLimits : CreatesLimitsOfSize.{w, w'} (𝟭 C) where CreatesLimitsOfShape := { CreatesLimit := { lifts := fun c _ => idLiftsCone c } } /-- Any cocone lifts through the identity functor. -/ def idLiftsCocone (c : Cocone (K ⋙ 𝟭 C)) : LiftableCocone K (𝟭 C) c where liftedCocone := { pt := c.pt ι := K.rightUnitor.inv ≫ c.ι } validLift := Cocones.ext (Iso.refl _) /-- The identity functor creates all colimits. -/ instance idCreatesColimits : CreatesColimitsOfSize.{w, w'} (𝟭 C) where CreatesColimitsOfShape := { CreatesColimit := { lifts := fun c _ => idLiftsCocone c } } /-- Satisfy the inhabited linter -/ instance inhabitedLiftableCone (c : Cone (K ⋙ 𝟭 C)) : Inhabited (LiftableCone K (𝟭 C) c) := ⟨idLiftsCone c⟩ instance inhabitedLiftableCocone (c : Cocone (K ⋙ 𝟭 C)) : Inhabited (LiftableCocone K (𝟭 C) c) := ⟨idLiftsCocone c⟩ /-- Satisfy the inhabited linter -/ instance inhabitedLiftsToLimit (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] (c : Cone (K ⋙ F)) (t : IsLimit c) : Inhabited (LiftsToLimit _ _ _ t) := ⟨liftsToLimitOfCreates K F c t⟩ instance inhabitedLiftsToColimit (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] (c : Cocone (K ⋙ F)) (t : IsColimit c) : Inhabited (LiftsToColimit _ _ _ t) := ⟨liftsToColimitOfCreates K F c t⟩ section Comp variable {E : Type u₃} [ℰ : Category.{v₃} E] variable (F : C ⥤ D) (G : D ⥤ E) instance compCreatesLimit [CreatesLimit K F] [CreatesLimit (K ⋙ F) G] : CreatesLimit K (F ⋙ G) where lifts c t := by let c' : Cone ((K ⋙ F) ⋙ G) := c let t' : IsLimit c' := t exact { liftedCone := liftLimit (liftedLimitIsLimit t') validLift := (Cones.functoriality (K ⋙ F) G).mapIso (liftedLimitMapsToOriginal (liftedLimitIsLimit t')) ≪≫ liftedLimitMapsToOriginal t' } instance compCreatesLimitsOfShape [CreatesLimitsOfShape J F] [CreatesLimitsOfShape J G] : CreatesLimitsOfShape J (F ⋙ G) where CreatesLimit := inferInstance instance compCreatesLimits [CreatesLimitsOfSize.{w, w'} F] [CreatesLimitsOfSize.{w, w'} G] : CreatesLimitsOfSize.{w, w'} (F ⋙ G) where CreatesLimitsOfShape := inferInstance instance preservesLimit_comp_of_createsLimit [CreatesLimit K F] [PreservesLimit K (F ⋙ G)] : PreservesLimit (K ⋙ F) G where preserves hc := ⟨IsLimit.ofIsoLimit (isLimitOfPreserves (F ⋙ G) (liftedLimitIsLimit hc)) ((Functor.mapConeMapCone (liftLimit hc)).symm ≪≫ (Cones.functoriality _ _).mapIso (liftedLimitMapsToOriginal hc))⟩ instance compCreatesColimit [CreatesColimit K F] [CreatesColimit (K ⋙ F) G] : CreatesColimit K (F ⋙ G) where lifts c t := let c' : Cocone ((K ⋙ F) ⋙ G) := c let t' : IsColimit c' := t { liftedCocone := liftColimit (liftedColimitIsColimit t') validLift := (Cocones.functoriality (K ⋙ F) G).mapIso (liftedColimitMapsToOriginal (liftedColimitIsColimit t')) ≪≫ liftedColimitMapsToOriginal t' } instance compCreatesColimitsOfShape [CreatesColimitsOfShape J F] [CreatesColimitsOfShape J G] : CreatesColimitsOfShape J (F ⋙ G) where CreatesColimit := inferInstance instance compCreatesColimits [CreatesColimitsOfSize.{w, w'} F] [CreatesColimitsOfSize.{w, w'} G] : CreatesColimitsOfSize.{w, w'} (F ⋙ G) where CreatesColimitsOfShape := inferInstance instance preservesColimit_comp_of_createsColimit [CreatesColimit K F] [PreservesColimit K (F ⋙ G)] : PreservesColimit (K ⋙ F) G where preserves hc := ⟨IsColimit.ofIsoColimit (isColimitOfPreserves (F ⋙ G) (liftedColimitIsColimit hc)) ((Functor.mapCoconeMapCocone (liftColimit hc)).symm ≪≫ (Cocones.functoriality _ _).mapIso (liftedColimitMapsToOriginal hc))⟩ end Comp end Creates end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/ExactFunctor.lean
import Mathlib.CategoryTheory.Limits.Preserves.Finite /-! # Bundled exact functors We say that a functor `F` is left exact if it preserves finite limits, it is right exact if it preserves finite colimits, and it is exact if it is both left exact and right exact. In this file, we define the categories of bundled left exact, right exact and exact functors. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory.Limits namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] section variable (C) (D) /-- Bundled left-exact functors. -/ def LeftExactFunctor := ObjectProperty.FullSubcategory fun F : C ⥤ D => PreservesFiniteLimits F instance : Category (LeftExactFunctor C D) := ObjectProperty.FullSubcategory.category _ /-- `C ⥤ₗ D` denotes left exact functors `C ⥤ D` -/ infixr:26 " ⥤ₗ " => LeftExactFunctor /-- A left exact functor is in particular a functor. -/ def LeftExactFunctor.forget : (C ⥤ₗ D) ⥤ C ⥤ D := ObjectProperty.ι _ instance : (LeftExactFunctor.forget C D).Full := ObjectProperty.full_ι _ instance : (LeftExactFunctor.forget C D).Faithful := ObjectProperty.faithful_ι _ /-- The inclusion of left exact functors into functors is fully faithful. -/ abbrev LeftExactFunctor.fullyFaithful : (LeftExactFunctor.forget C D).FullyFaithful := ObjectProperty.fullyFaithfulι _ /-- Bundled right-exact functors. -/ def RightExactFunctor := ObjectProperty.FullSubcategory fun F : C ⥤ D => PreservesFiniteColimits F instance : Category (RightExactFunctor C D) := ObjectProperty.FullSubcategory.category _ /-- `C ⥤ᵣ D` denotes right exact functors `C ⥤ D` -/ infixr:26 " ⥤ᵣ " => RightExactFunctor /-- A right exact functor is in particular a functor. -/ def RightExactFunctor.forget : (C ⥤ᵣ D) ⥤ C ⥤ D := ObjectProperty.ι _ instance : (RightExactFunctor.forget C D).Full := ObjectProperty.full_ι _ instance : (RightExactFunctor.forget C D).Faithful := ObjectProperty.faithful_ι _ /-- The inclusion of right exact functors into functors is fully faithful. -/ abbrev RightExactFunctor.fullyFaithful : (RightExactFunctor.forget C D).FullyFaithful := ObjectProperty.fullyFaithfulι _ /-- Bundled exact functors. -/ def ExactFunctor := ObjectProperty.FullSubcategory fun F : C ⥤ D => PreservesFiniteLimits F ∧ PreservesFiniteColimits F instance : Category (ExactFunctor C D) := ObjectProperty.FullSubcategory.category _ /-- `C ⥤ₑ D` denotes exact functors `C ⥤ D` -/ infixr:26 " ⥤ₑ " => ExactFunctor /-- An exact functor is in particular a functor. -/ def ExactFunctor.forget : (C ⥤ₑ D) ⥤ C ⥤ D := ObjectProperty.ι _ instance : (ExactFunctor.forget C D).Full := ObjectProperty.full_ι _ instance : (ExactFunctor.forget C D).Faithful := ObjectProperty.faithful_ι _ /-- Turn an exact functor into a left exact functor. -/ def LeftExactFunctor.ofExact : (C ⥤ₑ D) ⥤ C ⥤ₗ D := ObjectProperty.ιOfLE (fun _ => And.left) instance : (LeftExactFunctor.ofExact C D).Full := ObjectProperty.full_ιOfLE _ instance : (LeftExactFunctor.ofExact C D).Faithful := ObjectProperty.faithful_ιOfLE _ /-- Turn an exact functor into a left exact functor. -/ def RightExactFunctor.ofExact : (C ⥤ₑ D) ⥤ C ⥤ᵣ D := ObjectProperty.ιOfLE (fun _ => And.right) instance : (RightExactFunctor.ofExact C D).Full := ObjectProperty.full_ιOfLE _ instance : (RightExactFunctor.ofExact C D).Faithful := ObjectProperty.faithful_ιOfLE _ variable {C D} @[simp] theorem LeftExactFunctor.ofExact_obj (F : C ⥤ₑ D) : (LeftExactFunctor.ofExact C D).obj F = ⟨F.1, F.2.1⟩ := rfl @[simp] theorem RightExactFunctor.ofExact_obj (F : C ⥤ₑ D) : (RightExactFunctor.ofExact C D).obj F = ⟨F.1, F.2.2⟩ := rfl @[simp] theorem LeftExactFunctor.ofExact_map {F G : C ⥤ₑ D} (α : F ⟶ G) : (LeftExactFunctor.ofExact C D).map α = α := rfl @[simp] theorem RightExactFunctor.ofExact_map {F G : C ⥤ₑ D} (α : F ⟶ G) : (RightExactFunctor.ofExact C D).map α = α := rfl @[simp] theorem LeftExactFunctor.forget_obj (F : C ⥤ₗ D) : (LeftExactFunctor.forget C D).obj F = F.1 := rfl @[simp] theorem RightExactFunctor.forget_obj (F : C ⥤ᵣ D) : (RightExactFunctor.forget C D).obj F = F.1 := rfl @[simp] theorem ExactFunctor.forget_obj (F : C ⥤ₑ D) : (ExactFunctor.forget C D).obj F = F.1 := rfl @[simp] theorem LeftExactFunctor.forget_map {F G : C ⥤ₗ D} (α : F ⟶ G) : (LeftExactFunctor.forget C D).map α = α := rfl @[simp] theorem RightExactFunctor.forget_map {F G : C ⥤ᵣ D} (α : F ⟶ G) : (RightExactFunctor.forget C D).map α = α := rfl @[simp] theorem ExactFunctor.forget_map {F G : C ⥤ₑ D} (α : F ⟶ G) : (ExactFunctor.forget C D).map α = α := rfl /-- Turn a left exact functor into an object of the category `LeftExactFunctor C D`. -/ def LeftExactFunctor.of (F : C ⥤ D) [PreservesFiniteLimits F] : C ⥤ₗ D := ⟨F, inferInstance⟩ /-- Turn a right exact functor into an object of the category `RightExactFunctor C D`. -/ def RightExactFunctor.of (F : C ⥤ D) [PreservesFiniteColimits F] : C ⥤ᵣ D := ⟨F, inferInstance⟩ /-- Turn an exact functor into an object of the category `ExactFunctor C D`. -/ def ExactFunctor.of (F : C ⥤ D) [PreservesFiniteLimits F] [PreservesFiniteColimits F] : C ⥤ₑ D := ⟨F, ⟨inferInstance, inferInstance⟩⟩ @[simp] theorem LeftExactFunctor.of_fst (F : C ⥤ D) [PreservesFiniteLimits F] : (LeftExactFunctor.of F).obj = F := rfl @[simp] theorem RightExactFunctor.of_fst (F : C ⥤ D) [PreservesFiniteColimits F] : (RightExactFunctor.of F).obj = F := rfl @[simp] theorem ExactFunctor.of_fst (F : C ⥤ D) [PreservesFiniteLimits F] [PreservesFiniteColimits F] : (ExactFunctor.of F).obj = F := rfl theorem LeftExactFunctor.forget_obj_of (F : C ⥤ D) [PreservesFiniteLimits F] : (LeftExactFunctor.forget C D).obj (LeftExactFunctor.of F) = F := rfl theorem RightExactFunctor.forget_obj_of (F : C ⥤ D) [PreservesFiniteColimits F] : (RightExactFunctor.forget C D).obj (RightExactFunctor.of F) = F := rfl theorem ExactFunctor.forget_obj_of (F : C ⥤ D) [PreservesFiniteLimits F] [PreservesFiniteColimits F] : (ExactFunctor.forget C D).obj (ExactFunctor.of F) = F := rfl noncomputable instance (F : C ⥤ₗ D) : PreservesFiniteLimits F.obj := F.property noncomputable instance (F : C ⥤ᵣ D) : PreservesFiniteColimits F.obj := F.property noncomputable instance (F : C ⥤ₑ D) : PreservesFiniteLimits F.obj := F.property.1 noncomputable instance (F : C ⥤ₑ D) : PreservesFiniteColimits F.obj := F.property.2 variable {E : Type u₃} [Category.{v₃} E] section variable (C D E) /-- Whiskering a left exact functor by a left exact functor yields a left exact functor. -/ @[simps! obj_obj obj_map map_app_app] def LeftExactFunctor.whiskeringLeft : (C ⥤ₗ D) ⥤ (D ⥤ₗ E) ⥤ (C ⥤ₗ E) where obj F := ObjectProperty.lift _ (forget _ _ ⋙ (Functor.whiskeringLeft C D E).obj F.obj) (fun G => by dsimp; exact comp_preservesFiniteLimits _ _) map {F G} η := { app := fun H => ((Functor.whiskeringLeft C D E).map η).app H.obj naturality := fun _ _ f => ((Functor.whiskeringLeft C D E).map η).naturality f } map_id X := by rw [ObjectProperty.FullSubcategory.id_def] cat_disch map_comp f g := by rw [ObjectProperty.FullSubcategory.comp_def] cat_disch /-- Whiskering a left exact functor by a left exact functor yields a left exact functor. -/ @[simps! obj_obj obj_map map_app_app] def LeftExactFunctor.whiskeringRight : (D ⥤ₗ E) ⥤ (C ⥤ₗ D) ⥤ (C ⥤ₗ E) where obj F := ObjectProperty.lift _ (forget _ _ ⋙ (Functor.whiskeringRight C D E).obj F.obj) (fun G => by dsimp; exact comp_preservesFiniteLimits _ _) map {F G} η := { app := fun H => ((Functor.whiskeringRight C D E).map η).app H.obj naturality := fun _ _ f => ((Functor.whiskeringRight C D E).map η).naturality f } /-- Whiskering a right exact functor by a right exact functor yields a right exact functor. -/ @[simps! obj_obj obj_map map_app_app] def RightExactFunctor.whiskeringLeft : (C ⥤ᵣ D) ⥤ (D ⥤ᵣ E) ⥤ (C ⥤ᵣ E) where obj F := ObjectProperty.lift _ (forget _ _ ⋙ (Functor.whiskeringLeft C D E).obj F.obj) (fun G => by dsimp; exact comp_preservesFiniteColimits _ _) map {F G} η := { app := fun H => ((Functor.whiskeringLeft C D E).map η).app H.obj naturality := fun _ _ f => ((Functor.whiskeringLeft C D E).map η).naturality f } map_id X := by rw [ObjectProperty.FullSubcategory.id_def] cat_disch map_comp f g := by rw [ObjectProperty.FullSubcategory.comp_def] cat_disch /-- Whiskering a right exact functor by a right exact functor yields a right exact functor. -/ @[simps! obj_obj obj_map map_app_app] def RightExactFunctor.whiskeringRight : (D ⥤ᵣ E) ⥤ (C ⥤ᵣ D) ⥤ (C ⥤ᵣ E) where obj F := ObjectProperty.lift _ (forget _ _ ⋙ (Functor.whiskeringRight C D E).obj F.obj) (fun G => by dsimp; exact comp_preservesFiniteColimits _ _) map {F G} η := { app := fun H => ((Functor.whiskeringRight C D E).map η).app H.obj naturality := fun _ _ f => ((Functor.whiskeringRight C D E).map η).naturality f } /-- Whiskering an exact functor by an exact functor yields an exact functor. -/ @[simps! obj_obj obj_map map_app_app] def ExactFunctor.whiskeringLeft : (C ⥤ₑ D) ⥤ (D ⥤ₑ E) ⥤ (C ⥤ₑ E) where obj F := ObjectProperty.lift _ (forget _ _ ⋙ (Functor.whiskeringLeft C D E).obj F.obj) (fun G => ⟨by dsimp; exact comp_preservesFiniteLimits _ _, by dsimp; exact comp_preservesFiniteColimits _ _⟩) map {F G} η := { app := fun H => ((Functor.whiskeringLeft C D E).map η).app H.obj naturality := fun _ _ f => ((Functor.whiskeringLeft C D E).map η).naturality f } map_id X := by rw [ObjectProperty.FullSubcategory.id_def] cat_disch map_comp f g := by rw [ObjectProperty.FullSubcategory.comp_def] cat_disch /-- Whiskering an exact functor by an exact functor yields an exact functor. -/ @[simps! obj_obj obj_map map_app_app] def ExactFunctor.whiskeringRight : (D ⥤ₑ E) ⥤ (C ⥤ₑ D) ⥤ (C ⥤ₑ E) where obj F := ObjectProperty.lift _ (forget _ _ ⋙ (Functor.whiskeringRight C D E).obj F.obj) (fun G => ⟨by dsimp; exact comp_preservesFiniteLimits _ _, by dsimp; exact comp_preservesFiniteColimits _ _⟩) map {F G} η := { app := fun H => ((Functor.whiskeringRight C D E).map η).app H.obj naturality := fun _ _ f => ((Functor.whiskeringRight C D E).map η).naturality f } end end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Set.lean
import Mathlib.CategoryTheory.Limits.Lattice import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Types.Filtered import Mathlib.CategoryTheory.Types.Set /-! # The functor from `Set X` to types preserves filtered colimits Given `X : Type u`, the functor `Set.functorToTypes : Set X ⥤ Type u` which sends `A : Set X` to its underlying type preserves filtered colimits. -/ universe w w' u open CategoryTheory Limits CompleteLattice namespace Set open CompleteLattice in instance {J : Type w} [Category.{w'} J] {X : Type u} [IsFilteredOrEmpty J] : PreservesColimitsOfShape J (functorToTypes (X := X)) where preservesColimit {F} := by apply preservesColimit_of_preserves_colimit_cocone (colimitCocone F).isColimit apply Types.FilteredColimit.isColimitOf · rintro ⟨x, hx⟩ simp only [colimitCocone_cocone_pt, iSup_eq_iUnion, mem_iUnion] at hx obtain ⟨i, hi⟩ := hx exact ⟨i, ⟨x, hi⟩, rfl⟩ · intro i j ⟨x, hx⟩ ⟨y, hy⟩ h obtain rfl : x = y := by simpa using h exact ⟨IsFiltered.max i j, IsFiltered.leftToMax i j, IsFiltered.rightToMax i j, rfl⟩ end Set
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FinallySmall.lean
import Mathlib.Logic.Small.Set import Mathlib.CategoryTheory.Filtered.Final /-! # Finally small categories A category given by `(J : Type u) [Category.{v} J]` is `w`-finally small if there exists a `FinalModel J : Type w` equipped with `[SmallCategory (FinalModel J)]` and a final functor `FinalModel J ⥤ J`. This means that if a category `C` has colimits of size `w` and `J` is `w`-finally small, then `C` has colimits of shape `J`. In this way, the notion of "finally small" can be seen of a generalization of the notion of "essentially small" for indexing categories of colimits. Dually, we have a notion of initially small category. We show that a finally small category admits a small weakly terminal set, i.e., a small set `s` of objects such that from every object there a morphism to a member of `s`. We also show that the converse holds if `J` is filtered. -/ universe w v v₁ u u₁ open CategoryTheory Functor namespace CategoryTheory section FinallySmall variable (J : Type u) [Category.{v} J] /-- A category is `FinallySmall.{w}` if there is a final functor from a `w`-small category. -/ class FinallySmall : Prop where /-- There is a final functor from a small category. -/ final_smallCategory : ∃ (S : Type w) (_ : SmallCategory S) (F : S ⥤ J), Final F /-- Constructor for `FinallySmall C` from an explicit small category witness. -/ theorem FinallySmall.mk' {J : Type u} [Category.{v} J] {S : Type w} [SmallCategory S] (F : S ⥤ J) [Final F] : FinallySmall.{w} J := ⟨S, _, F, inferInstance⟩ /-- An arbitrarily chosen small model for a finally small category. -/ def FinalModel [FinallySmall.{w} J] : Type w := Classical.choose (@FinallySmall.final_smallCategory J _ _) noncomputable instance smallCategoryFinalModel [FinallySmall.{w} J] : SmallCategory (FinalModel J) := Classical.choose (Classical.choose_spec (@FinallySmall.final_smallCategory J _ _)) /-- An arbitrarily chosen final functor `FinalModel J ⥤ J`. -/ noncomputable def fromFinalModel [FinallySmall.{w} J] : FinalModel J ⥤ J := Classical.choose (Classical.choose_spec (Classical.choose_spec (@FinallySmall.final_smallCategory J _ _))) instance final_fromFinalModel [FinallySmall.{w} J] : Final (fromFinalModel J) := Classical.choose_spec (Classical.choose_spec (Classical.choose_spec (@FinallySmall.final_smallCategory J _ _))) theorem finallySmall_of_essentiallySmall [EssentiallySmall.{w} J] : FinallySmall.{w} J := FinallySmall.mk' (equivSmallModel.{w} J).inverse variable {J} variable {K : Type u₁} [Category.{v₁} K] theorem finallySmall_of_final_of_finallySmall [FinallySmall.{w} K] (F : K ⥤ J) [Final F] : FinallySmall.{w} J := suffices Final ((fromFinalModel K) ⋙ F) from .mk' ((fromFinalModel K) ⋙ F) final_comp _ _ theorem finallySmall_of_final_of_essentiallySmall [EssentiallySmall.{w} K] (F : K ⥤ J) [Final F] : FinallySmall.{w} J := have := finallySmall_of_essentiallySmall K finallySmall_of_final_of_finallySmall F end FinallySmall section InitiallySmall variable (J : Type u) [Category.{v} J] /-- A category is `InitiallySmall.{w}` if there is an initial functor from a `w`-small category. -/ class InitiallySmall : Prop where /-- There is an initial functor from a small category. -/ initial_smallCategory : ∃ (S : Type w) (_ : SmallCategory S) (F : S ⥤ J), Initial F /-- Constructor for `InitialSmall C` from an explicit small category witness. -/ theorem InitiallySmall.mk' {J : Type u} [Category.{v} J] {S : Type w} [SmallCategory S] (F : S ⥤ J) [Initial F] : InitiallySmall.{w} J := ⟨S, _, F, inferInstance⟩ /-- An arbitrarily chosen small model for an initially small category. -/ def InitialModel [InitiallySmall.{w} J] : Type w := Classical.choose (@InitiallySmall.initial_smallCategory J _ _) noncomputable instance smallCategoryInitialModel [InitiallySmall.{w} J] : SmallCategory (InitialModel J) := Classical.choose (Classical.choose_spec (@InitiallySmall.initial_smallCategory J _ _)) /-- An arbitrarily chosen initial functor `InitialModel J ⥤ J`. -/ noncomputable def fromInitialModel [InitiallySmall.{w} J] : InitialModel J ⥤ J := Classical.choose (Classical.choose_spec (Classical.choose_spec (@InitiallySmall.initial_smallCategory J _ _))) instance initial_fromInitialModel [InitiallySmall.{w} J] : Initial (fromInitialModel J) := Classical.choose_spec (Classical.choose_spec (Classical.choose_spec (@InitiallySmall.initial_smallCategory J _ _))) theorem initiallySmall_of_essentiallySmall [EssentiallySmall.{w} J] : InitiallySmall.{w} J := InitiallySmall.mk' (equivSmallModel.{w} J).inverse variable {J} variable {K : Type u₁} [Category.{v₁} K] theorem initiallySmall_of_initial_of_initiallySmall [InitiallySmall.{w} K] (F : K ⥤ J) [Initial F] : InitiallySmall.{w} J := suffices Initial ((fromInitialModel K) ⋙ F) from .mk' ((fromInitialModel K) ⋙ F) initial_comp _ _ theorem initiallySmall_of_initial_of_essentiallySmall [EssentiallySmall.{w} K] (F : K ⥤ J) [Initial F] : InitiallySmall.{w} J := have := initiallySmall_of_essentiallySmall K initiallySmall_of_initial_of_initiallySmall F end InitiallySmall section WeaklyTerminal variable (J : Type u) [Category.{v} J] /-- The converse is true if `J` is filtered, see `finallySmall_of_small_weakly_terminal_set`. -/ theorem FinallySmall.exists_small_weakly_terminal_set [FinallySmall.{w} J] : ∃ (s : Set J) (_ : Small.{w} s), ∀ i, ∃ j ∈ s, Nonempty (i ⟶ j) := by refine ⟨Set.range (fromFinalModel J).obj, inferInstance, fun i => ?_⟩ obtain ⟨f⟩ : Nonempty (StructuredArrow i (fromFinalModel J)) := IsConnected.is_nonempty exact ⟨(fromFinalModel J).obj f.right, Set.mem_range_self _, ⟨f.hom⟩⟩ variable {J} in theorem finallySmall_of_small_weakly_terminal_set [IsFilteredOrEmpty J] (s : Set J) [Small.{v} s] (hs : ∀ i, ∃ j ∈ s, Nonempty (i ⟶ j)) : FinallySmall.{v} J := by suffices Functor.Final (ObjectProperty.ι (· ∈ s)) from finallySmall_of_final_of_essentiallySmall (ObjectProperty.ι (· ∈ s)) refine Functor.final_of_exists_of_isFiltered_of_fullyFaithful _ (fun i => ?_) obtain ⟨j, hj₁, hj₂⟩ := hs i exact ⟨⟨j, hj₁⟩, hj₂⟩ theorem finallySmall_iff_exists_small_weakly_terminal_set [IsFilteredOrEmpty J] : FinallySmall.{v} J ↔ ∃ (s : Set J) (_ : Small.{v} s), ∀ i, ∃ j ∈ s, Nonempty (i ⟶ j) := by refine ⟨fun _ => FinallySmall.exists_small_weakly_terminal_set _, fun h => ?_⟩ rcases h with ⟨s, hs, hs'⟩ exact finallySmall_of_small_weakly_terminal_set s hs' end WeaklyTerminal section WeaklyInitial variable (J : Type u) [Category.{v} J] /-- The converse is true if `J` is cofiltered, see `initiallySmall_of_small_weakly_initial_set`. -/ theorem InitiallySmall.exists_small_weakly_initial_set [InitiallySmall.{w} J] : ∃ (s : Set J) (_ : Small.{w} s), ∀ i, ∃ j ∈ s, Nonempty (j ⟶ i) := by refine ⟨Set.range (fromInitialModel J).obj, inferInstance, fun i => ?_⟩ obtain ⟨f⟩ : Nonempty (CostructuredArrow (fromInitialModel J) i) := IsConnected.is_nonempty exact ⟨(fromInitialModel J).obj f.left, Set.mem_range_self _, ⟨f.hom⟩⟩ variable {J} in theorem initiallySmall_of_small_weakly_initial_set [IsCofilteredOrEmpty J] (s : Set J) [Small.{v} s] (hs : ∀ i, ∃ j ∈ s, Nonempty (j ⟶ i)) : InitiallySmall.{v} J := by suffices Functor.Initial (ObjectProperty.ι (· ∈ s)) from initiallySmall_of_initial_of_essentiallySmall (ObjectProperty.ι (· ∈ s)) refine Functor.initial_of_exists_of_isCofiltered_of_fullyFaithful _ (fun i => ?_) obtain ⟨j, hj₁, hj₂⟩ := hs i exact ⟨⟨j, hj₁⟩, hj₂⟩ theorem initiallySmall_iff_exists_small_weakly_initial_set [IsCofilteredOrEmpty J] : InitiallySmall.{v} J ↔ ∃ (s : Set J) (_ : Small.{v} s), ∀ i, ∃ j ∈ s, Nonempty (j ⟶ i) := by refine ⟨fun _ => InitiallySmall.exists_small_weakly_initial_set _, fun h => ?_⟩ rcases h with ⟨s, hs, hs'⟩ exact initiallySmall_of_small_weakly_initial_set s hs' end WeaklyInitial namespace Limits theorem hasColimitsOfShape_of_finallySmall (J : Type u) [Category.{v} J] [FinallySmall.{w} J] (C : Type u₁) [Category.{v₁} C] [HasColimitsOfSize.{w, w} C] : HasColimitsOfShape J C := Final.hasColimitsOfShape_of_final (fromFinalModel J) theorem hasLimitsOfShape_of_initiallySmall (J : Type u) [Category.{v} J] [InitiallySmall.{w} J] (C : Type u₁) [Category.{v₁} C] [HasLimitsOfSize.{w, w} C] : HasLimitsOfShape J C := Initial.hasLimitsOfShape_of_initial (fromInitialModel J) end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/MorphismProperty.lean
import Mathlib.CategoryTheory.Limits.Comma import Mathlib.CategoryTheory.Limits.Constructions.Over.Basic import Mathlib.CategoryTheory.MorphismProperty.Comma import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.CategoryTheory.ObjectProperty.ColimitsOfShape import Mathlib.CategoryTheory.ObjectProperty.LimitsOfShape /-! # (Co)limits in subcategories of comma categories defined by morphism properties -/ namespace CategoryTheory open Limits MorphismProperty.Comma variable {T : Type*} [Category T] (P : MorphismProperty T) namespace MorphismProperty.Comma variable {A B J : Type*} [Category A] [Category B] [Category J] {L : A ⥤ T} {R : B ⥤ T} variable (D : J ⥤ P.Comma L R ⊤ ⊤) /-- If `P` is closed under limits of shape `J` in `Comma L R`, then when `D` has a limit in `Comma L R`, the forgetful functor creates this limit. -/ noncomputable def forgetCreatesLimitOfClosed [(P.commaObj L R).IsClosedUnderLimitsOfShape J] [HasLimit (D ⋙ forget L R P ⊤ ⊤)] : CreatesLimit D (forget L R P ⊤ ⊤) := createsLimitOfFullyFaithfulOfIso (⟨limit (D ⋙ forget L R P ⊤ ⊤), ObjectProperty.prop_limit (P.commaObj L R) _ fun j ↦ (D.obj j).prop⟩) (Iso.refl _) /-- If `Comma L R` has limits of shape `J` and `Comma L R` is closed under limits of shape `J`, then `forget L R P ⊤ ⊤` creates limits of shape `J`. -/ noncomputable def forgetCreatesLimitsOfShapeOfClosed [HasLimitsOfShape J (Comma L R)] [ObjectProperty.IsClosedUnderLimitsOfShape (P.commaObj L R) J] : CreatesLimitsOfShape J (forget L R P ⊤ ⊤) where CreatesLimit := forgetCreatesLimitOfClosed _ _ lemma hasLimit_of_closedUnderLimitsOfShape [(P.commaObj L R).IsClosedUnderLimitsOfShape J] [HasLimit (D ⋙ forget L R P ⊤ ⊤)] : HasLimit D := haveI : CreatesLimit D (forget L R P ⊤ ⊤) := forgetCreatesLimitOfClosed _ D hasLimit_of_created D (forget L R P ⊤ ⊤) instance hasLimitsOfShape_of_closedUnderLimitsOfShape [HasLimitsOfShape J (Comma L R)] [(P.commaObj L R).IsClosedUnderLimitsOfShape J] : HasLimitsOfShape J (P.Comma L R ⊤ ⊤) where has_limit _ := hasLimit_of_closedUnderLimitsOfShape _ _ /-- If `P` is closed under colimits of shape `J` in `Comma L R`, then when `D` has a colimit in `Comma L R`, the forgetful functor creates this colimit. -/ noncomputable def forgetCreatesColimitOfClosed [(P.commaObj L R).IsClosedUnderColimitsOfShape J] [HasColimit (D ⋙ forget L R P ⊤ ⊤)] : CreatesColimit D (forget L R P ⊤ ⊤) := createsColimitOfFullyFaithfulOfIso (⟨colimit (D ⋙ forget L R P ⊤ ⊤), (P.commaObj L R).prop_colimit _ (fun j ↦ (D.obj j).prop)⟩) (Iso.refl _) variable (J) in /-- If `Comma L R` has colimits of shape `J` and `Comma L R` is closed under colimits of shape `J`, then `forget L R P ⊤ ⊤` creates colimits of shape `J`. -/ noncomputable def forgetCreatesColimitsOfShapeOfClosed [HasColimitsOfShape J (Comma L R)] [(P.commaObj L R).IsClosedUnderColimitsOfShape J] : CreatesColimitsOfShape J (forget L R P ⊤ ⊤) where CreatesColimit := forgetCreatesColimitOfClosed _ _ lemma hasColimit_of_closedUnderColimitsOfShape [(P.commaObj L R).IsClosedUnderColimitsOfShape J] [HasColimit (D ⋙ forget L R P ⊤ ⊤)] : HasColimit D := haveI : CreatesColimit D (forget L R P ⊤ ⊤) := forgetCreatesColimitOfClosed _ D hasColimit_of_created D (forget L R P ⊤ ⊤) instance hasColimitsOfShape_of_closedUnderColimitsOfShape [HasColimitsOfShape J (Comma L R)] [(P.commaObj L R).IsClosedUnderColimitsOfShape J] : HasColimitsOfShape J (P.Comma L R ⊤ ⊤) where has_colimit _ := hasColimit_of_closedUnderColimitsOfShape _ _ end MorphismProperty.Comma section variable {A : Type*} [Category A] {L : A ⥤ T} instance CostructuredArrow.closedUnderLimitsOfShape_discrete_empty [L.Faithful] [L.Full] {Y : A} [P.ContainsIdentities] [P.RespectsIso] : (P.costructuredArrowObj L (X := L.obj Y)).IsClosedUnderLimitsOfShape (Discrete PEmpty.{1}) where limitsOfShape_le := by rintro X ⟨p⟩ let e : X ≅ CostructuredArrow.mk (𝟙 (L.obj Y)) := p.isLimit.conePointUniqueUpToIso ((IsLimit.postcomposeInvEquiv (Functor.emptyExt _ _) _).2 CostructuredArrow.mkIdTerminal) rw [MorphismProperty.costructuredArrowObj_iff, P.costructuredArrow_iso_iff e] simpa using P.id_mem (L.obj Y) end section variable {X : T} instance Over.closedUnderLimitsOfShape_discrete_empty [P.ContainsIdentities] [P.RespectsIso] : (P.overObj (X := X)).IsClosedUnderLimitsOfShape (Discrete PEmpty.{1}) := CostructuredArrow.closedUnderLimitsOfShape_discrete_empty P /-- Let `P` be stable under composition and base change. If `P` satisfies cancellation on the right, the subcategory of `Over X` defined by `P` is closed under pullbacks. Without the cancellation property, this does not in general. Consider for example `P = Function.Surjective` on `Type`. -/ instance Over.closedUnderLimitsOfShape_pullback [HasPullbacks T] [P.IsStableUnderComposition] [P.IsStableUnderBaseChange] [P.HasOfPostcompProperty P] : (P.overObj (X := X)).IsClosedUnderLimitsOfShape WalkingCospan where limitsOfShape_le := by rintro Y ⟨p⟩ have h := IsPullback.of_isLimit_cone <| Limits.isLimitOfPreserves (CategoryTheory.Over.forget X) p.isLimit rw [MorphismProperty.overObj_iff, show Y.hom = (p.π.app .left).left ≫ (p.diag.obj .left).hom by simp] apply P.comp_mem _ _ (P.of_isPullback h.flip ?_) (p.prop_diag_obj _) exact P.of_postcomp _ (p.diag.obj WalkingCospan.one).hom (p.prop_diag_obj .one) (by simpa using p.prop_diag_obj .right) end namespace MorphismProperty.Over variable (X : T) noncomputable instance [P.ContainsIdentities] [P.RespectsIso] : CreatesLimitsOfShape (Discrete PEmpty.{1}) (Over.forget P ⊤ X) := by apply (config := { allowSynthFailures := true }) forgetCreatesLimitsOfShapeOfClosed · exact inferInstanceAs (HasLimitsOfShape _ (Over X)) · apply Over.closedUnderLimitsOfShape_discrete_empty _ variable {X} in instance [P.ContainsIdentities] (Y : P.Over ⊤ X) : Unique (Y ⟶ Over.mk ⊤ (𝟙 X) (P.id_mem X)) where default := Over.homMk Y.hom uniq a := by ext · simp only [mk_left, homMk_hom, Over.homMk_left] rw [← Over.w a] simp only [mk_left, Functor.const_obj_obj, mk_hom, Category.comp_id] /-- `X ⟶ X` is the terminal object of `P.Over ⊤ X`. -/ def mkIdTerminal [P.ContainsIdentities] : IsTerminal (Over.mk ⊤ (𝟙 X) (P.id_mem X)) := IsTerminal.ofUnique _ instance [P.ContainsIdentities] : HasTerminal (P.Over ⊤ X) := let h : IsTerminal (Over.mk ⊤ (𝟙 X) (P.id_mem X)) := Over.mkIdTerminal P X h.hasTerminal /-- If `P` is stable under composition, base change and satisfies post-cancellation, `Over.forget P ⊤ X` creates pullbacks. -/ noncomputable instance createsLimitsOfShape_walkingCospan [HasPullbacks T] [P.IsStableUnderComposition] [P.IsStableUnderBaseChange] [P.HasOfPostcompProperty P] : CreatesLimitsOfShape WalkingCospan (Over.forget P ⊤ X) := by apply (config := { allowSynthFailures := true }) forgetCreatesLimitsOfShapeOfClosed · exact inferInstanceAs (HasLimitsOfShape WalkingCospan (Over X)) · apply Over.closedUnderLimitsOfShape_pullback /-- If `P` is stable under composition, base change and satisfies post-cancellation, `P.Over ⊤ X` has pullbacks -/ instance (priority := 900) hasPullbacks [HasPullbacks T] [P.IsStableUnderComposition] [P.IsStableUnderBaseChange] [P.HasOfPostcompProperty P] : HasPullbacks (P.Over ⊤ X) := by apply (config := { allowSynthFailures := true }) hasLimitsOfShape_of_closedUnderLimitsOfShape · exact inferInstanceAs (HasLimitsOfShape WalkingCospan (Over X)) · apply Over.closedUnderLimitsOfShape_pullback end MorphismProperty.Over end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Opposites.lean
import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits /-! # Limits in `C` give colimits in `Cᵒᵖ`. We construct limits and colimits in the opposite categories. -/ universe v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory open CategoryTheory.Functor open Opposite namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {J : Type u₂} [Category.{v₂} J] /-- Turn a colimit for `F : J ⥤ Cᵒᵖ` into a limit for `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps] def isLimitConeLeftOpOfCocone (F : J ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneLeftOpOfCocone c) where lift s := (hc.desc (coconeOfConeLeftOp s)).unop fac s j := Quiver.Hom.op_inj <| by simp only [coneLeftOpOfCocone_π_app, op_comp, Quiver.Hom.op_unop, IsColimit.fac, coconeOfConeLeftOp_ι_app, op_unop] uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac, coconeOfConeLeftOp_ι_app] using w (op j) /-- Turn a limit of `F : J ⥤ Cᵒᵖ` into a colimit of `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps] def isColimitCoconeLeftOpOfCone (F : J ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeLeftOpOfCone c) where desc s := (hc.lift (coneOfCoconeLeftOp s)).unop fac s j := Quiver.Hom.op_inj <| by simp only [coconeLeftOpOfCone_ι_app, op_comp, Quiver.Hom.op_unop, IsLimit.fac, coneOfCoconeLeftOp_π_app, op_unop] uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac, coneOfCoconeLeftOp_π_app] using w (op j) /-- Turn a colimit for `F : Jᵒᵖ ⥤ C` into a limit for `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeRightOpOfCocone (F : Jᵒᵖ ⥤ C) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneRightOpOfCocone c) where lift s := (hc.desc (coconeOfConeRightOp s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (unop j) /-- Turn a limit for `F : Jᵒᵖ ⥤ C` into a colimit for `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def isColimitCoconeRightOpOfCone (F : Jᵒᵖ ⥤ C) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeRightOpOfCone c) where desc s := (hc.lift (coneOfCoconeRightOp s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (unop j) /-- Turn a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a limit for `F.unop : J ⥤ C`. -/ @[simps] def isLimitConeUnopOfCocone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneUnopOfCocone c) where lift s := (hc.desc (coconeOfConeUnop s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (unop j) /-- Turn a limit of `F : Jᵒᵖ ⥤ Cᵒᵖ` into a colimit of `F.unop : J ⥤ C`. -/ @[simps] def isColimitCoconeUnopOfCone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeUnopOfCone c) where desc s := (hc.lift (coneOfCoconeUnop s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (unop j) /-- Turn a colimit for `F.leftOp : Jᵒᵖ ⥤ C` into a limit for `F : J ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeOfCoconeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cocone F.leftOp} (hc : IsColimit c) : IsLimit (coneOfCoconeLeftOp c) where lift s := (hc.desc (coconeLeftOpOfCone s)).op fac s j := Quiver.Hom.unop_inj <| by simp only [coneOfCoconeLeftOp_π_app, unop_comp, Quiver.Hom.unop_op, IsColimit.fac, coconeLeftOpOfCone_ι_app, unop_op] uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac, coneOfCoconeLeftOp_π_app] using w (unop j) /-- Turn a limit of `F.leftOp : Jᵒᵖ ⥤ C` into a colimit of `F : J ⥤ Cᵒᵖ`. -/ @[simps] def isColimitCoconeOfConeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cone F.leftOp} (hc : IsLimit c) : IsColimit (coconeOfConeLeftOp c) where desc s := (hc.lift (coneLeftOpOfCocone s)).op fac s j := Quiver.Hom.unop_inj <| by simp only [coconeOfConeLeftOp_ι_app, unop_comp, Quiver.Hom.unop_op, IsLimit.fac, coneLeftOpOfCocone_π_app, unop_op] uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac, coconeOfConeLeftOp_ι_app] using w (unop j) /-- Turn a colimit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/ @[simps] def isLimitConeOfCoconeRightOp (F : Jᵒᵖ ⥤ C) {c : Cocone F.rightOp} (hc : IsColimit c) : IsLimit (coneOfCoconeRightOp c) where lift s := (hc.desc (coconeRightOpOfCone s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (op j) /-- Turn a limit for `F.rightOp : J ⥤ Cᵒᵖ` into a colimit for `F : Jᵒᵖ ⥤ C`. -/ @[simps] def isColimitCoconeOfConeRightOp (F : Jᵒᵖ ⥤ C) {c : Cone F.rightOp} (hc : IsLimit c) : IsColimit (coconeOfConeRightOp c) where desc s := (hc.lift (coneRightOpOfCocone s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (op j) /-- Turn a colimit for `F.unop : J ⥤ C` into a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F.unop} (hc : IsColimit c) : IsLimit (coneOfCoconeUnop c) where lift s := (hc.desc (coconeUnopOfCone s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (op j) /-- Turn a limit for `F.unop : J ⥤ C` into a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def isColimitCoconeOfConeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F.unop} (hc : IsLimit c) : IsColimit (coconeOfConeUnop c) where desc s := (hc.lift (coneUnopOfCocone s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (op j) /-- Turn a limit for `F.leftOp : Jᵒᵖ ⥤ C` into a colimit for `F : J ⥤ Cᵒᵖ`. -/ @[simps!] def isColimitOfConeLeftOpOfCocone (F : J ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsLimit (coneLeftOpOfCocone c)) : IsColimit c := isColimitCoconeOfConeLeftOp F hc /-- Turn a colimit for `F.leftOp : Jᵒᵖ ⥤ C` into a limit for `F : J ⥤ Cᵒᵖ`. -/ @[simps!] def isLimitOfCoconeLeftOpOfCone (F : J ⥤ Cᵒᵖ) {c : Cone F} (hc : IsColimit (coconeLeftOpOfCone c)) : IsLimit c := isLimitConeOfCoconeLeftOp F hc /-- Turn a limit for `F.rightOp : J ⥤ Cᵒᵖ` into a colimit for `F : Jᵒᵖ ⥤ C`. -/ @[simps!] def isColimitOfConeRightOpOfCocone (F : Jᵒᵖ ⥤ C) {c : Cocone F} (hc : IsLimit (coneRightOpOfCocone c)) : IsColimit c := isColimitCoconeOfConeRightOp F hc /-- Turn a colimit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/ @[simps!] def isLimitOfCoconeRightOpOfCone (F : Jᵒᵖ ⥤ C) {c : Cone F} (hc : IsColimit (coconeRightOpOfCone c)) : IsLimit c := isLimitConeOfCoconeRightOp F hc /-- Turn a limit for `F.unop : J ⥤ C` into a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps!] def isColimitOfConeUnopOfCocone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsLimit (coneUnopOfCocone c)) : IsColimit c := isColimitCoconeOfConeUnop F hc /-- Turn a colimit for `F.unop : J ⥤ C` into a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps!] def isLimitOfCoconeUnopOfCone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F} (hc : IsColimit (coconeUnopOfCone c)) : IsLimit c := isLimitConeOfCoconeUnop F hc /-- Turn a limit for `F : J ⥤ Cᵒᵖ` into a colimit for `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps!] def isColimitOfConeOfCoconeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cocone F.leftOp} (hc : IsLimit (coneOfCoconeLeftOp c)) : IsColimit c := isColimitCoconeLeftOpOfCone F hc /-- Turn a colimit for `F : J ⥤ Cᵒᵖ` into a limit for `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps!] def isLimitOfCoconeOfConeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cone F.leftOp} (hc : IsColimit (coconeOfConeLeftOp c)) : IsLimit c := isLimitConeLeftOpOfCocone F hc /-- Turn a limit for `F : Jᵒᵖ ⥤ C` into a colimit for `F.rightOp : J ⥤ Cᵒᵖ.` -/ @[simps!] def isColimitOfConeOfCoconeRightOp (F : Jᵒᵖ ⥤ C) {c : Cocone F.rightOp} (hc : IsLimit (coneOfCoconeRightOp c)) : IsColimit c := isColimitCoconeRightOpOfCone F hc /-- Turn a colimit for `F : Jᵒᵖ ⥤ C` into a limit for `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps!] def isLimitOfCoconeOfConeRightOp (F : Jᵒᵖ ⥤ C) {c : Cone F.rightOp} (hc : IsColimit (coconeOfConeRightOp c)) : IsLimit c := isLimitConeRightOpOfCocone F hc /-- Turn a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a colimit for `F.unop : J ⥤ C`. -/ @[simps!] def isColimitOfConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F.unop} (hc : IsLimit (coneOfCoconeUnop c)) : IsColimit c := isColimitCoconeUnopOfCone F hc /-- Turn a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a limit for `F.unop : J ⥤ C`. -/ @[simps!] def isLimitOfCoconeOfConeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F.unop} (hc : IsColimit (coconeOfConeUnop c)) : IsLimit c := isLimitConeUnopOfCocone F hc /-- If `F.leftOp : Jᵒᵖ ⥤ C` has a colimit, we can construct a limit for `F : J ⥤ Cᵒᵖ`. -/ theorem hasLimit_of_hasColimit_leftOp (F : J ⥤ Cᵒᵖ) [HasColimit F.leftOp] : HasLimit F := HasLimit.mk { cone := coneOfCoconeLeftOp (colimit.cocone F.leftOp) isLimit := isLimitConeOfCoconeLeftOp _ (colimit.isColimit _) } theorem hasLimit_of_hasColimit_op (F : J ⥤ C) [HasColimit F.op] : HasLimit F := HasLimit.mk { cone := (colimit.cocone F.op).unop isLimit := (colimit.isColimit _).unop } theorem hasLimit_of_hasColimit_rightOp (F : Jᵒᵖ ⥤ C) [HasColimit F.rightOp] : HasLimit F := HasLimit.mk { cone := coneOfCoconeRightOp (colimit.cocone F.rightOp) isLimit := isLimitConeOfCoconeRightOp _ (colimit.isColimit _) } theorem hasLimit_of_hasColimit_unop (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F.unop] : HasLimit F := HasLimit.mk { cone := coneOfCoconeUnop (colimit.cocone F.unop) isLimit := isLimitConeOfCoconeUnop _ (colimit.isColimit _) } instance hasLimit_op_of_hasColimit (F : J ⥤ C) [HasColimit F] : HasLimit F.op := HasLimit.mk { cone := (colimit.cocone F).op isLimit := (colimit.isColimit _).op } instance hasLimit_leftOp_of_hasColimit (F : J ⥤ Cᵒᵖ) [HasColimit F] : HasLimit F.leftOp := HasLimit.mk { cone := coneLeftOpOfCocone (colimit.cocone F) isLimit := isLimitConeLeftOpOfCocone _ (colimit.isColimit _) } instance hasLimit_rightOp_of_hasColimit (F : Jᵒᵖ ⥤ C) [HasColimit F] : HasLimit F.rightOp := HasLimit.mk { cone := coneRightOpOfCocone (colimit.cocone F) isLimit := isLimitConeRightOpOfCocone _ (colimit.isColimit _) } instance hasLimit_unop_of_hasColimit (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] : HasLimit F.unop := HasLimit.mk { cone := coneUnopOfCocone (colimit.cocone F) isLimit := isLimitConeUnopOfCocone _ (colimit.isColimit _) } /-- The limit of `F.op` is the opposite of `colimit F`. -/ def limitOpIsoOpColimit (F : J ⥤ C) [HasColimit F] : limit F.op ≅ op (colimit F) := limit.isoLimitCone ⟨_, (colimit.isColimit _).op⟩ @[reassoc (attr := simp)] lemma limitOpIsoOpColimit_inv_comp_π (F : J ⥤ C) [HasColimit F] (j : Jᵒᵖ) : (limitOpIsoOpColimit F).inv ≫ limit.π F.op j = (colimit.ι F j.unop).op := by simp [limitOpIsoOpColimit] @[reassoc (attr := simp)] lemma limitOpIsoOpColimit_hom_comp_ι (F : J ⥤ C) [HasColimit F] (j : J) : (limitOpIsoOpColimit F).hom ≫ (colimit.ι F j).op = limit.π F.op (op j) := by simp [← Iso.eq_inv_comp] /-- The limit of `F.leftOp` is the unopposite of `colimit F`. -/ def limitLeftOpIsoUnopColimit (F : J ⥤ Cᵒᵖ) [HasColimit F] : limit F.leftOp ≅ unop (colimit F) := limit.isoLimitCone ⟨_, isLimitConeLeftOpOfCocone _ (colimit.isColimit _)⟩ @[reassoc (attr := simp)] lemma limitLeftOpIsoUnopColimit_inv_comp_π (F : J ⥤ Cᵒᵖ) [HasColimit F] (j : Jᵒᵖ) : (limitLeftOpIsoUnopColimit F).inv ≫ limit.π F.leftOp j = (colimit.ι F j.unop).unop := by simp [limitLeftOpIsoUnopColimit] @[reassoc (attr := simp)] lemma limitLeftOpIsoUnopColimit_hom_comp_ι (F : J ⥤ Cᵒᵖ) [HasColimit F] (j : J) : (limitLeftOpIsoUnopColimit F).hom ≫ (colimit.ι F j).unop = limit.π F.leftOp (op j) := by simp [← Iso.eq_inv_comp] /-- The limit of `F.rightOp` is the opposite of `colimit F`. -/ def limitRightOpIsoOpColimit (F : Jᵒᵖ ⥤ C) [HasColimit F] : limit F.rightOp ≅ op (colimit F) := limit.isoLimitCone ⟨_, isLimitConeRightOpOfCocone _ (colimit.isColimit _)⟩ @[reassoc (attr := simp)] lemma limitRightOpIsoOpColimit_inv_comp_π (F : Jᵒᵖ ⥤ C) [HasColimit F] (j : J) : (limitRightOpIsoOpColimit F).inv ≫ limit.π F.rightOp j = (colimit.ι F (op j)).op := by simp [limitRightOpIsoOpColimit] @[reassoc (attr := simp)] lemma limitRightOpIsoOpColimit_hom_comp_ι (F : Jᵒᵖ ⥤ C) [HasColimit F] (j : Jᵒᵖ) : (limitRightOpIsoOpColimit F).hom ≫ (colimit.ι F j).op = limit.π F.rightOp j.unop := by simp [← Iso.eq_inv_comp] /-- The limit of `F.unop` is the unopposite of `colimit F`. -/ def limitUnopIsoUnopColimit (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] : limit F.unop ≅ unop (colimit F) := limit.isoLimitCone ⟨_, isLimitConeUnopOfCocone _ (colimit.isColimit _)⟩ @[reassoc (attr := simp)] lemma limitUnopIsoUnopColimit_inv_comp_π (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] (j : J) : (limitUnopIsoUnopColimit F).inv ≫ limit.π F.unop j = (colimit.ι F (op j)).unop := by simp [limitUnopIsoUnopColimit] @[reassoc (attr := simp)] lemma limitUnopIsoUnopColimit_hom_comp_ι (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] (j : Jᵒᵖ) : (limitUnopIsoUnopColimit F).hom ≫ (colimit.ι F j).unop = limit.π F.unop j.unop := by simp [← Iso.eq_inv_comp] /-- If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`. -/ theorem hasLimitsOfShape_op_of_hasColimitsOfShape [HasColimitsOfShape Jᵒᵖ C] : HasLimitsOfShape J Cᵒᵖ := { has_limit := fun F => hasLimit_of_hasColimit_leftOp F } theorem hasLimitsOfShape_of_hasColimitsOfShape_op [HasColimitsOfShape Jᵒᵖ Cᵒᵖ] : HasLimitsOfShape J C := { has_limit := fun F => hasLimit_of_hasColimit_op F } attribute [local instance] hasLimitsOfShape_op_of_hasColimitsOfShape /-- If `C` has colimits, we can construct limits for `Cᵒᵖ`. -/ instance hasLimits_op_of_hasColimits [HasColimitsOfSize.{v₂, u₂} C] : HasLimitsOfSize.{v₂, u₂} Cᵒᵖ := ⟨fun _ => inferInstance⟩ theorem hasLimits_of_hasColimits_op [HasColimitsOfSize.{v₂, u₂} Cᵒᵖ] : HasLimitsOfSize.{v₂, u₂} C := { has_limits_of_shape := fun _ _ => hasLimitsOfShape_of_hasColimitsOfShape_op } /-- If `F.leftOp : Jᵒᵖ ⥤ C` has a limit, we can construct a colimit for `F : J ⥤ Cᵒᵖ`. -/ theorem hasColimit_of_hasLimit_leftOp (F : J ⥤ Cᵒᵖ) [HasLimit F.leftOp] : HasColimit F := HasColimit.mk { cocone := coconeOfConeLeftOp (limit.cone F.leftOp) isColimit := isColimitCoconeOfConeLeftOp _ (limit.isLimit _) } theorem hasColimit_of_hasLimit_op (F : J ⥤ C) [HasLimit F.op] : HasColimit F := HasColimit.mk { cocone := (limit.cone F.op).unop isColimit := (limit.isLimit _).unop } theorem hasColimit_of_hasLimit_rightOp (F : Jᵒᵖ ⥤ C) [HasLimit F.rightOp] : HasColimit F := HasColimit.mk { cocone := coconeOfConeRightOp (limit.cone F.rightOp) isColimit := isColimitCoconeOfConeRightOp _ (limit.isLimit _) } theorem hasColimit_of_hasLimit_unop (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasLimit F.unop] : HasColimit F := HasColimit.mk { cocone := coconeOfConeUnop (limit.cone F.unop) isColimit := isColimitCoconeOfConeUnop _ (limit.isLimit _) } instance hasColimit_op_of_hasLimit (F : J ⥤ C) [HasLimit F] : HasColimit F.op := HasColimit.mk { cocone := (limit.cone F).op isColimit := (limit.isLimit _).op } instance hasColimit_leftOp_of_hasLimit (F : J ⥤ Cᵒᵖ) [HasLimit F] : HasColimit F.leftOp := HasColimit.mk { cocone := coconeLeftOpOfCone (limit.cone F) isColimit := isColimitCoconeLeftOpOfCone _ (limit.isLimit _) } instance hasColimit_rightOp_of_hasLimit (F : Jᵒᵖ ⥤ C) [HasLimit F] : HasColimit F.rightOp := HasColimit.mk { cocone := coconeRightOpOfCone (limit.cone F) isColimit := isColimitCoconeRightOpOfCone _ (limit.isLimit _) } instance hasColimit_unop_of_hasLimit (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasLimit F] : HasColimit F.unop := HasColimit.mk { cocone := coconeUnopOfCone (limit.cone F) isColimit := isColimitCoconeUnopOfCone _ (limit.isLimit _) } /-- The colimit of `F.op` is the opposite of `limit F`. -/ def colimitOpIsoOpLimit (F : J ⥤ C) [HasLimit F] : colimit F.op ≅ op (limit F) := colimit.isoColimitCocone ⟨_, (limit.isLimit _).op⟩ @[reassoc (attr := simp)] lemma ι_comp_colimitOpIsoOpLimit_hom (F : J ⥤ C) [HasLimit F] (j : Jᵒᵖ) : colimit.ι F.op j ≫ (colimitOpIsoOpLimit F).hom = (limit.π F j.unop).op := by simp [colimitOpIsoOpLimit] @[reassoc (attr := simp)] lemma π_comp_colimitOpIsoOpLimit_inv (F : J ⥤ C) [HasLimit F] (j : J) : (limit.π F j).op ≫ (colimitOpIsoOpLimit F).inv = colimit.ι F.op (op j) := by simp [Iso.comp_inv_eq] /-- The colimit of `F.leftOp` is the unopposite of `limit F`. -/ def colimitLeftOpIsoUnopLimit (F : J ⥤ Cᵒᵖ) [HasLimit F] : colimit F.leftOp ≅ unop (limit F) := colimit.isoColimitCocone ⟨_, isColimitCoconeLeftOpOfCone _ (limit.isLimit _)⟩ @[reassoc (attr := simp)] lemma ι_comp_colimitLeftOpIsoUnopLimit_hom (F : J ⥤ Cᵒᵖ) [HasLimit F] (j : Jᵒᵖ) : colimit.ι F.leftOp j ≫ (colimitLeftOpIsoUnopLimit F).hom = (limit.π F j.unop).unop := by simp [colimitLeftOpIsoUnopLimit] @[reassoc (attr := simp)] lemma π_comp_colimitLeftOpIsoUnopLimit_inv (F : J ⥤ Cᵒᵖ) [HasLimit F] (j : J) : (limit.π F j).unop ≫ (colimitLeftOpIsoUnopLimit F).inv = colimit.ι F.leftOp (op j) := by simp [Iso.comp_inv_eq] /-- The colimit of `F.rightOp` is the opposite of `limit F`. -/ def colimitRightOpIsoUnopLimit (F : Jᵒᵖ ⥤ C) [HasLimit F] : colimit F.rightOp ≅ op (limit F) := colimit.isoColimitCocone ⟨_, isColimitCoconeRightOpOfCone _ (limit.isLimit _)⟩ @[reassoc (attr := simp)] lemma ι_comp_colimitRightOpIsoUnopLimit_hom (F : Jᵒᵖ ⥤ C) [HasLimit F] (j : J) : colimit.ι F.rightOp j ≫ (colimitRightOpIsoUnopLimit F).hom = (limit.π F (op j)).op := by simp [colimitRightOpIsoUnopLimit] @[reassoc (attr := simp)] lemma π_comp_colimitRightOpIsoUnopLimit_inv (F : Jᵒᵖ ⥤ C) [HasLimit F] (j : Jᵒᵖ) : (limit.π F j).op ≫ (colimitRightOpIsoUnopLimit F).inv = colimit.ι F.rightOp j.unop := by simp [Iso.comp_inv_eq] /-- The colimit of `F.unop` is the unopposite of `limit F`. -/ def colimitUnopIsoOpLimit (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasLimit F] : colimit F.unop ≅ unop (limit F) := colimit.isoColimitCocone ⟨_, isColimitCoconeUnopOfCone _ (limit.isLimit _)⟩ @[reassoc (attr := simp)] lemma ι_comp_colimitUnopIsoOpLimit_hom (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasLimit F] (j : J) : colimit.ι F.unop j ≫ (colimitUnopIsoOpLimit F).hom = (limit.π F (op j)).unop := by simp [colimitUnopIsoOpLimit] @[reassoc (attr := simp)] lemma π_comp_colimitUnopIsoOpLimit_inv (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasLimit F] (j : Jᵒᵖ) : (limit.π F j).unop ≫ (colimitUnopIsoOpLimit F).inv = colimit.ι F.unop j.unop := by simp [Iso.comp_inv_eq] /-- If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`. -/ instance hasColimitsOfShape_op_of_hasLimitsOfShape [HasLimitsOfShape Jᵒᵖ C] : HasColimitsOfShape J Cᵒᵖ where has_colimit F := hasColimit_of_hasLimit_leftOp F theorem hasColimitsOfShape_of_hasLimitsOfShape_op [HasLimitsOfShape Jᵒᵖ Cᵒᵖ] : HasColimitsOfShape J C := { has_colimit := fun F => hasColimit_of_hasLimit_op F } /-- If `C` has limits, we can construct colimits for `Cᵒᵖ`. -/ instance hasColimits_op_of_hasLimits [HasLimitsOfSize.{v₂, u₂} C] : HasColimitsOfSize.{v₂, u₂} Cᵒᵖ := ⟨fun _ => inferInstance⟩ theorem hasColimits_of_hasLimits_op [HasLimitsOfSize.{v₂, u₂} Cᵒᵖ] : HasColimitsOfSize.{v₂, u₂} C := { has_colimits_of_shape := fun _ _ => hasColimitsOfShape_of_hasLimitsOfShape_op } instance hasFiniteColimits_opposite [HasFiniteLimits C] : HasFiniteColimits Cᵒᵖ := ⟨fun _ _ _ => hasColimitsOfShape_op_of_hasLimitsOfShape⟩ instance hasFiniteLimits_opposite [HasFiniteColimits C] : HasFiniteLimits Cᵒᵖ := ⟨fun _ _ _ => hasLimitsOfShape_op_of_hasColimitsOfShape⟩ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Connected.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Connected limits A connected limit is a limit whose shape is a connected category. We show that constant functors from a connected category have a limit and a colimit. From this we deduce that a cocone `c` over a connected diagram is a colimit cocone if and only if `colimMap c.ι` is an isomorphism (where `c.ι : F ⟶ const c.pt` is the natural transformation that defines the cocone). We give examples of connected categories, and prove that the functor given by `(X × -)` preserves any connected limit. That is, any limit of shape `J` where `J` is a connected category is preserved by the functor `(X × -)`. -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits namespace CategoryTheory section Const namespace Limits variable {J : Type u₁} [Category.{v₁} J] {C : Type u₂} [Category.{v₂} C] (X : C) section variable (J) /-- The obvious cone of a constant functor. -/ @[simps] def constCone : Cone ((Functor.const J).obj X) where pt := X π := 𝟙 _ /-- The obvious cocone of a constant functor. -/ @[simps] def constCocone : Cocone ((Functor.const J).obj X) where pt := X ι := 𝟙 _ variable [IsConnected J] /-- When `J` is a connected category, the limit of a constant functor `J ⥤ C` with value `X : C` identifies to `X`. -/ def isLimitConstCone : IsLimit (constCone J X) where lift s := s.π.app (Classical.arbitrary _) fac s j := by dsimp rw [comp_id] exact constant_of_preserves_morphisms _ (fun _ _ f ↦ by simpa using s.w f) _ _ uniq s m hm := by simpa using hm (Classical.arbitrary _) /-- When `J` is a connected category, the colimit of a constant functor `J ⥤ C` with value `X : C` identifies to `X`. -/ def isColimitConstCocone : IsColimit (constCocone J X) where desc s := s.ι.app (Classical.arbitrary _) fac s j := by dsimp rw [id_comp] exact constant_of_preserves_morphisms _ (fun _ _ f ↦ by simpa using (s.w f).symm) _ _ uniq s m hm := by simpa using hm (Classical.arbitrary _) instance hasLimit_const_of_isConnected : HasLimit ((Functor.const J).obj X) := ⟨_, isLimitConstCone J X⟩ instance hasColimit_const_of_isConnected : HasColimit ((Functor.const J).obj X) := ⟨_, isColimitConstCocone J X⟩ end section variable [IsConnected J] /-- If `J` is connected, `F : J ⥤ C` and `c` is a cone on `F`, then to check that `c` is a limit it is sufficient to check that `limMap c.π` is an isomorphism. The converse is also true, see `Cone.isLimit_iff_isIso_limMap_π`. -/ def Cone.isLimitOfIsIsoLimMapπ {F : J ⥤ C} [HasLimit F] (c : Cone F) [IsIso (limMap c.π)] : IsLimit c := by refine IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext ((asIso (limMap c.π)).symm ≪≫ (limit.isLimit _).conePointUniqueUpToIso (isLimitConstCone J c.pt)) ?_) intro j simp only [limit.cone_x, Functor.const_obj_obj, limit.cone_π, Iso.trans_hom, Iso.symm_hom, asIso_inv, assoc, IsIso.eq_inv_comp, limMap_π] congr 1 simp [← Iso.inv_comp_eq_id] theorem IsLimit.isIso_limMap_π {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) : IsIso (limMap c.π) := by suffices limMap c.π = ((limit.isLimit _).conePointUniqueUpToIso (isLimitConstCone J c.pt) ≪≫ hc.conePointUniqueUpToIso (limit.isLimit _)).hom by rw [this]; infer_instance ext j simp only [limMap_π, Functor.const_obj_obj, limit.cone_x, constCone_pt, Iso.trans_hom, assoc, limit.conePointUniqueUpToIso_hom_comp] congr 1 simp [← Iso.inv_comp_eq_id] theorem Cone.isLimit_iff_isIso_limMap_π {F : J ⥤ C} [HasLimit F] (c : Cone F) : Nonempty (IsLimit c) ↔ IsIso (limMap c.π) := ⟨fun ⟨h⟩ => IsLimit.isIso_limMap_π h, fun _ => ⟨c.isLimitOfIsIsoLimMapπ⟩⟩ /-- If `J` is connected, `F : J ⥤ C` and `C` is a cocone on `F`, then to check that `c` is a colimit it is sufficient to check that `colimMap c.ι` is an isomorphism. The converse is also true, see `Cocone.isColimit_iff_isIso_colimMap_ι`. -/ def Cocone.isColimitOfIsIsoColimMapι {F : J ⥤ C} [HasColimit F] (c : Cocone F) [IsIso (colimMap c.ι)] : IsColimit c := IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (asIso (colimMap c.ι) ≪≫ (colimit.isColimit _).coconePointUniqueUpToIso (isColimitConstCocone J c.pt)) (by simp)) theorem IsColimit.isIso_colimMap_ι {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) : IsIso (colimMap c.ι) := by suffices colimMap c.ι = ((colimit.isColimit _).coconePointUniqueUpToIso hc ≪≫ (isColimitConstCocone J c.pt).coconePointUniqueUpToIso (colimit.isColimit _)).hom by rw [this]; infer_instance ext j simp only [ι_colimMap, Functor.const_obj_obj, colimit.cocone_x, Iso.trans_hom, colimit.comp_coconePointUniqueUpToIso_hom_assoc] congr 1 simp [← Iso.comp_inv_eq_id] theorem Cocone.isColimit_iff_isIso_colimMap_ι {F : J ⥤ C} [HasColimit F] (c : Cocone F) : Nonempty (IsColimit c) ↔ IsIso (colimMap c.ι) := ⟨fun ⟨h⟩ => IsColimit.isIso_colimMap_ι h, fun _ => ⟨c.isColimitOfIsIsoColimMapι⟩⟩ end end Limits end Const section Examples instance widePullbackShape_connected (J : Type v₁) : IsConnected (WidePullbackShape J) := by apply IsConnected.of_induct · introv hp t cases j · exact hp · rwa [t (WidePullbackShape.Hom.term _)] instance widePushoutShape_connected (J : Type v₁) : IsConnected (WidePushoutShape J) := by apply IsConnected.of_induct · introv hp t cases j · exact hp · rwa [← t (WidePushoutShape.Hom.init _)] instance parallelPairInhabited : Inhabited WalkingParallelPair := ⟨WalkingParallelPair.one⟩ instance parallel_pair_connected : IsConnected WalkingParallelPair := by apply IsConnected.of_induct · introv _ t cases j · rwa [t WalkingParallelPairHom.left] · assumption end Examples variable {C : Type u₂} [Category.{v₂} C] variable [HasBinaryProducts C] variable {J : Type v₂} [SmallCategory J] namespace ProdPreservesConnectedLimits /-- (Impl). The obvious natural transformation from (X × K -) to K. -/ @[simps] def γ₂ {K : J ⥤ C} (X : C) : K ⋙ prod.functor.obj X ⟶ K where app _ := Limits.prod.snd /-- (Impl). The obvious natural transformation from (X × K -) to X -/ @[simps] def γ₁ {K : J ⥤ C} (X : C) : K ⋙ prod.functor.obj X ⟶ (Functor.const J).obj X where app _ := Limits.prod.fst /-- (Impl). Given a cone for (X × K -), produce a cone for K using the natural transformation `γ₂` -/ @[simps] def forgetCone {X : C} {K : J ⥤ C} (s : Cone (K ⋙ prod.functor.obj X)) : Cone K where pt := s.pt π := s.π ≫ γ₂ X end ProdPreservesConnectedLimits open ProdPreservesConnectedLimits /-- The functor `(X × -)` preserves any connected limit. Note that this functor does not preserve the two most obvious disconnected limits - that is, `(X × -)` does not preserve products or terminal object, e.g. `(X ⨯ A) ⨯ (X ⨯ B)` is not isomorphic to `X ⨯ (A ⨯ B)` and `X ⨯ 1` is not isomorphic to `1`. -/ lemma prod_preservesConnectedLimits [IsConnected J] (X : C) : PreservesLimitsOfShape J (prod.functor.obj X) where preservesLimit {K} := { preserves := fun {c} l => ⟨{ lift := fun s => prod.lift (s.π.app (Classical.arbitrary _) ≫ Limits.prod.fst) (l.lift (forgetCone s)) fac := fun s j => by apply Limits.prod.hom_ext · erw [assoc, limMap_π, comp_id, limit.lift_π] exact (nat_trans_from_is_connected (s.π ≫ γ₁ X) j (Classical.arbitrary _)).symm · simp uniq := fun s m L => by apply Limits.prod.hom_ext · erw [limit.lift_π, ← L (Classical.arbitrary J), assoc, limMap_π, comp_id] rfl · rw [limit.lift_π] apply l.uniq (forgetCone s) intro j simp [← L j] }⟩ } end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/IsLimit.lean
import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Limits.Cones import Batteries.Tactic.Congr /-! # Limits and colimits We set up the general theory of limits and colimits in a category. In this introduction we only describe the setup for limits; it is repeated, with slightly different names, for colimits. The main structures defined in this file is * `IsLimit c`, for `c : Cone F`, `F : J ⥤ C`, expressing that `c` is a limit cone, See also `CategoryTheory.Limits.HasLimits` which further builds: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] variable {F : J ⥤ C} /-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique cone morphism to `t`. -/ @[stacks 002E] structure IsLimit (t : Cone F) where /-- There is a morphism from any cone point to `t.pt` -/ lift : ∀ s : Cone F, s.pt ⟶ t.pt /-- The map makes the triangle with the two natural transformations commute -/ fac : ∀ (s : Cone F) (j : J), lift s ≫ t.π.app j = s.π.app j := by cat_disch /-- It is the unique such map to do this -/ uniq : ∀ (s : Cone F) (m : s.pt ⟶ t.pt) (_ : ∀ j : J, m ≫ t.π.app j = s.π.app j), m = lift s := by cat_disch attribute [reassoc (attr := simp)] IsLimit.fac namespace IsLimit instance subsingleton {t : Cone F} : Subsingleton (IsLimit t) := ⟨by intro P Q; cases P; cases Q; congr; cat_disch⟩ /-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cone point of any cone over `F` to the cone point of a limit cone over `G`. -/ def map {F G : J ⥤ C} (s : Cone F) {t : Cone G} (P : IsLimit t) (α : F ⟶ G) : s.pt ⟶ t.pt := P.lift ((Cones.postcompose α).obj s) @[reassoc (attr := simp)] theorem map_π {F G : J ⥤ C} (c : Cone F) {d : Cone G} (hd : IsLimit d) (α : F ⟶ G) (j : J) : hd.map c α ≫ d.π.app j = c.π.app j ≫ α.app j := fac _ _ _ @[simp] theorem lift_self {c : Cone F} (t : IsLimit c) : t.lift c = 𝟙 c.pt := (t.uniq _ _ fun _ => id_comp _).symm -- Repackaging the definition in terms of cone morphisms. /-- The universal morphism from any other cone to a limit cone. -/ @[simps] def liftConeMorphism {t : Cone F} (h : IsLimit t) (s : Cone F) : s ⟶ t where hom := h.lift s theorem uniq_cone_morphism {s t : Cone F} (h : IsLimit t) {f f' : s ⟶ t} : f = f' := have : ∀ {g : s ⟶ t}, g = h.liftConeMorphism s := by intro g; apply ConeMorphism.ext; exact h.uniq _ _ g.w this.trans this.symm /-- Restating the definition of a limit cone in terms of the ∃! operator. -/ theorem existsUnique {t : Cone F} (h : IsLimit t) (s : Cone F) : ∃! l : s.pt ⟶ t.pt, ∀ j, l ≫ t.π.app j = s.π.app j := ⟨h.lift s, h.fac s, h.uniq s⟩ /-- Noncomputably make a limit cone from the existence of unique factorizations. -/ def ofExistsUnique {t : Cone F} (ht : ∀ s : Cone F, ∃! l : s.pt ⟶ t.pt, ∀ j, l ≫ t.π.app j = s.π.app j) : IsLimit t := by choose s hs hs' using ht exact ⟨s, hs, hs'⟩ /-- Alternative constructor for `isLimit`, providing a morphism of cones rather than a morphism between the cone points and separately the factorisation condition. -/ @[simps] def mkConeMorphism {t : Cone F} (lift : ∀ s : Cone F, s ⟶ t) (uniq : ∀ (s : Cone F) (m : s ⟶ t), m = lift s) : IsLimit t where lift s := (lift s).hom uniq s m w := have : ConeMorphism.mk m w = lift s := by apply uniq congrArg ConeMorphism.hom this /-- Limit cones on `F` are unique up to isomorphism. -/ @[simps] def uniqueUpToIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : s ≅ t where hom := Q.liftConeMorphism s inv := P.liftConeMorphism t hom_inv_id := P.uniq_cone_morphism inv_hom_id := Q.uniq_cone_morphism /-- Any cone morphism between limit cones is an isomorphism. -/ theorem hom_isIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (f : s ⟶ t) : IsIso f := ⟨⟨P.liftConeMorphism t, ⟨P.uniq_cone_morphism, Q.uniq_cone_morphism⟩⟩⟩ /-- Limits of `F` are unique up to isomorphism. -/ def conePointUniqueUpToIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : s.pt ≅ t.pt := (Cones.forget F).mapIso (uniqueUpToIso P Q) @[reassoc (attr := simp)] theorem conePointUniqueUpToIso_hom_comp {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (j : J) : (conePointUniqueUpToIso P Q).hom ≫ t.π.app j = s.π.app j := (uniqueUpToIso P Q).hom.w _ @[reassoc (attr := simp)] theorem conePointUniqueUpToIso_inv_comp {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (j : J) : (conePointUniqueUpToIso P Q).inv ≫ s.π.app j = t.π.app j := (uniqueUpToIso P Q).inv.w _ @[reassoc (attr := simp)] theorem lift_comp_conePointUniqueUpToIso_hom {r s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : P.lift r ≫ (conePointUniqueUpToIso P Q).hom = Q.lift r := Q.uniq _ _ (by simp) @[reassoc (attr := simp)] theorem lift_comp_conePointUniqueUpToIso_inv {r s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : Q.lift r ≫ (conePointUniqueUpToIso P Q).inv = P.lift r := P.uniq _ _ (by simp) /-- Transport evidence that a cone is a limit cone across an isomorphism of cones. -/ def ofIsoLimit {r t : Cone F} (P : IsLimit r) (i : r ≅ t) : IsLimit t := IsLimit.mkConeMorphism (fun s => P.liftConeMorphism s ≫ i.hom) fun s m => by rw [← i.comp_inv_eq]; apply P.uniq_cone_morphism @[simp] theorem ofIsoLimit_lift {r t : Cone F} (P : IsLimit r) (i : r ≅ t) (s) : (P.ofIsoLimit i).lift s = P.lift s ≫ i.hom.hom := rfl /-- Isomorphism of cones preserves whether or not they are limiting cones. -/ def equivIsoLimit {r t : Cone F} (i : r ≅ t) : IsLimit r ≃ IsLimit t where toFun h := h.ofIsoLimit i invFun h := h.ofIsoLimit i.symm left_inv := by cat_disch right_inv := by cat_disch @[simp] theorem equivIsoLimit_apply {r t : Cone F} (i : r ≅ t) (P : IsLimit r) : equivIsoLimit i P = P.ofIsoLimit i := rfl @[simp] theorem equivIsoLimit_symm_apply {r t : Cone F} (i : r ≅ t) (P : IsLimit t) : (equivIsoLimit i).symm P = P.ofIsoLimit i.symm := rfl /-- If the canonical morphism from a cone point to a limiting cone point is an iso, then the first cone was limiting also. -/ def ofPointIso {r t : Cone F} (P : IsLimit r) [i : IsIso (P.lift t)] : IsLimit t := ofIsoLimit P (by haveI : IsIso (P.liftConeMorphism t).hom := i haveI : IsIso (P.liftConeMorphism t) := Cones.cone_iso_of_hom_iso _ symm apply asIso (P.liftConeMorphism t)) variable {t : Cone F} theorem hom_lift (h : IsLimit t) {W : C} (m : W ⟶ t.pt) : m = h.lift { pt := W, π := { app := fun b => m ≫ t.π.app b } } := h.uniq { pt := W, π := { app := fun b => m ≫ t.π.app b } } m fun _ => rfl /-- Two morphisms into a limit are equal if their compositions with each cone morphism are equal. -/ theorem hom_ext (h : IsLimit t) {W : C} {f f' : W ⟶ t.pt} (w : ∀ j, f ≫ t.π.app j = f' ≫ t.π.app j) : f = f' := by rw [h.hom_lift f, h.hom_lift f']; congr; exact funext w /-- Given a right adjoint functor between categories of cones, the image of a limit cone is a limit cone. -/ def ofRightAdjoint {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} {left : Cone F ⥤ Cone G} {right : Cone G ⥤ Cone F} (adj : left ⊣ right) {c : Cone G} (t : IsLimit c) : IsLimit (right.obj c) := mkConeMorphism (fun s => adj.homEquiv s c (t.liftConeMorphism _)) fun _ _ => (Adjunction.eq_homEquiv_apply _ _ _).2 t.uniq_cone_morphism /-- Given two functors which have equivalent categories of cones, we can transport a limiting cone across the equivalence. -/ def ofConeEquiv {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F) {c : Cone G} : IsLimit (h.functor.obj c) ≃ IsLimit c where toFun P := ofIsoLimit (ofRightAdjoint h.toAdjunction P) (h.unitIso.symm.app c) invFun := ofRightAdjoint h.symm.toAdjunction left_inv := by cat_disch right_inv := by cat_disch @[simp] theorem ofConeEquiv_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F) {c : Cone G} (P : IsLimit (h.functor.obj c)) (s) : (ofConeEquiv h P).lift s = ((h.unitIso.hom.app s).hom ≫ (h.inverse.map (P.liftConeMorphism (h.functor.obj s))).hom) ≫ (h.unitIso.inv.app c).hom := rfl @[simp] theorem ofConeEquiv_symm_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F) {c : Cone G} (P : IsLimit c) (s) : ((ofConeEquiv h).symm P).lift s = (h.counitIso.inv.app s).hom ≫ (h.functor.map (P.liftConeMorphism (h.inverse.obj s))).hom := rfl /-- A cone postcomposed with a natural isomorphism is a limit cone if and only if the original cone is. -/ def postcomposeHomEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cone F) : IsLimit ((Cones.postcompose α.hom).obj c) ≃ IsLimit c := ofConeEquiv (Cones.postcomposeEquivalence α) /-- A cone postcomposed with the inverse of a natural isomorphism is a limit cone if and only if the original cone is. -/ def postcomposeInvEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cone G) : IsLimit ((Cones.postcompose α.inv).obj c) ≃ IsLimit c := postcomposeHomEquiv α.symm c /-- Constructing an equivalence `IsLimit c ≃ IsLimit d` from a natural isomorphism between the underlying functors, and then an isomorphism between `c` transported along this and `d`. -/ def equivOfNatIsoOfIso {F G : J ⥤ C} (α : F ≅ G) (c : Cone F) (d : Cone G) (w : (Cones.postcompose α.hom).obj c ≅ d) : IsLimit c ≃ IsLimit d := (postcomposeHomEquiv α _).symm.trans (equivIsoLimit w) /-- The cone points of two limit cones for naturally isomorphic functors are themselves isomorphic. -/ @[simps] def conePointsIsoOfNatIso {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) : s.pt ≅ t.pt where hom := Q.map s w.hom inv := P.map t w.inv hom_inv_id := P.hom_ext (by simp) inv_hom_id := Q.hom_ext (by simp) @[reassoc] theorem conePointsIsoOfNatIso_hom_comp {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) (j : J) : (conePointsIsoOfNatIso P Q w).hom ≫ t.π.app j = s.π.app j ≫ w.hom.app j := by simp @[reassoc] theorem conePointsIsoOfNatIso_inv_comp {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) (j : J) : (conePointsIsoOfNatIso P Q w).inv ≫ s.π.app j = t.π.app j ≫ w.inv.app j := by simp @[reassoc] theorem lift_comp_conePointsIsoOfNatIso_hom {F G : J ⥤ C} {r s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) : P.lift r ≫ (conePointsIsoOfNatIso P Q w).hom = Q.map r w.hom := Q.hom_ext (by simp) @[reassoc] theorem lift_comp_conePointsIsoOfNatIso_inv {F G : J ⥤ C} {r s : Cone G} {t : Cone F} (P : IsLimit t) (Q : IsLimit s) (w : F ≅ G) : Q.lift r ≫ (conePointsIsoOfNatIso P Q w).inv = P.map r w.inv := P.hom_ext (by simp) section Equivalence open CategoryTheory.Equivalence /-- If `s : Cone F` is a limit cone, so is `s` whiskered by an equivalence `e`. -/ def whiskerEquivalence {s : Cone F} (P : IsLimit s) (e : K ≌ J) : IsLimit (s.whisker e.functor) := ofRightAdjoint (Cones.whiskeringEquivalence e).symm.toAdjunction P /-- If `s : Cone F` whiskered by an equivalence `e` is a limit cone, so is `s`. -/ def ofWhiskerEquivalence {s : Cone F} (e : K ≌ J) (P : IsLimit (s.whisker e.functor)) : IsLimit s := equivIsoLimit ((Cones.whiskeringEquivalence e).unitIso.app s).symm (ofRightAdjoint (Cones.whiskeringEquivalence e).toAdjunction P) /-- Given an equivalence of diagrams `e`, `s` is a limit cone iff `s.whisker e.functor` is. -/ def whiskerEquivalenceEquiv {s : Cone F} (e : K ≌ J) : IsLimit s ≃ IsLimit (s.whisker e.functor) := ⟨fun h => h.whiskerEquivalence e, ofWhiskerEquivalence e, by cat_disch, by cat_disch⟩ /-- A limit cone extended by an isomorphism is a limit cone. -/ def extendIso {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] (hs : IsLimit s) : IsLimit (s.extend i) := IsLimit.ofIsoLimit hs (Cones.extendIso s (asIso i)).symm /-- A cone is a limit cone if its extension by an isomorphism is. -/ def ofExtendIso {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] (hs : IsLimit (s.extend i)) : IsLimit s := IsLimit.ofIsoLimit hs (Cones.extendIso s (asIso i)) /-- A cone is a limit cone iff its extension by an isomorphism is. -/ def extendIsoEquiv {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] : IsLimit s ≃ IsLimit (s.extend i) := equivOfSubsingletonOfSubsingleton (extendIso i) (ofExtendIso i) /-- We can prove two cone points `(s : Cone F).pt` and `(t : Cone G).pt` are isomorphic if * both cones are limit cones * their indexing categories are equivalent via some `e : J ≌ K`, * the triangle of functors commutes up to a natural isomorphism: `e.functor ⋙ G ≅ F`. This is the most general form of uniqueness of cone points, allowing relabelling of both the indexing category (up to equivalence) and the functor (up to natural isomorphism). -/ @[simps] def conePointsIsoOfEquivalence {F : J ⥤ C} {s : Cone F} {G : K ⥤ C} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : s.pt ≅ t.pt := let w' : e.inverse ⋙ F ≅ G := (isoWhiskerLeft e.inverse w).symm ≪≫ invFunIdAssoc e G { hom := Q.lift ((Cones.equivalenceOfReindexing e.symm w').functor.obj s) inv := P.lift ((Cones.equivalenceOfReindexing e w).functor.obj t) hom_inv_id := by apply hom_ext P; intro j dsimp [w'] simp only [Limits.Cone.whisker_π, Limits.Cones.postcompose_obj_π, fac, whiskerLeft_app, assoc, id_comp, invFunIdAssoc_hom_app, fac_assoc, NatTrans.comp_app] rw [counit_app_functor, ← Functor.comp_map] have l : NatTrans.app w.hom j = NatTrans.app w.hom ((𝟭 J).obj j) := by dsimp rw [l, w.hom.naturality] simp inv_hom_id := by apply hom_ext Q cat_disch } end Equivalence /-- The universal property of a limit cone: a wap `W ⟶ t.pt` is the same as a cone on `F` with cone point `W`. -/ @[simps apply] def homEquiv (h : IsLimit t) {W : C} : (W ⟶ t.pt) ≃ ((Functor.const J).obj W ⟶ F) where toFun f := (t.extend f).π invFun π := h.lift (Cone.mk _ π) left_inv f := h.hom_ext (by simp) right_inv π := by cat_disch @[reassoc (attr := simp)] lemma homEquiv_symm_π_app (h : IsLimit t) {W : C} (f : (const J).obj W ⟶ F) (j : J) : h.homEquiv.symm f ≫ t.π.app j = f.app j := by simp [homEquiv] lemma homEquiv_symm_naturality (h : IsLimit t) {W W' : C} (f : (const J).obj W ⟶ F) (g : W' ⟶ W) : h.homEquiv.symm ((Functor.const _).map g ≫ f) = g ≫ h.homEquiv.symm f := h.homEquiv.injective (by aesop) /-- The universal property of a limit cone: a map `W ⟶ X` is the same as a cone on `F` with cone point `W`. -/ def homIso (h : IsLimit t) (W : C) : ULift.{u₁} (W ⟶ t.pt : Type v₃) ≅ (const J).obj W ⟶ F := Equiv.toIso (Equiv.ulift.trans h.homEquiv) @[simp] theorem homIso_hom (h : IsLimit t) {W : C} (f : ULift.{u₁} (W ⟶ t.pt)) : (IsLimit.homIso h W).hom f = (t.extend f.down).π := rfl /-- The limit of `F` represents the functor taking `W` to the set of cones on `F` with cone point `W`. -/ def natIso (h : IsLimit t) : yoneda.obj t.pt ⋙ uliftFunctor.{u₁} ≅ F.cones := NatIso.ofComponents fun W => IsLimit.homIso h (unop W) /-- Another, more explicit, formulation of the universal property of a limit cone. See also `homIso`. -/ def homIso' (h : IsLimit t) (W : C) : ULift.{u₁} (W ⟶ t.pt : Type v₃) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j'} (f : j ⟶ j'), p j ≫ F.map f = p j' } := h.homIso W ≪≫ { hom := fun π => ⟨fun j => π.app j, fun f => by convert ← (π.naturality f).symm; apply id_comp⟩ inv := fun p => { app := fun j => p.1 j naturality := fun j j' f => by dsimp; rw [id_comp]; exact (p.2 f).symm } } /-- If G : C → D is a faithful functor which sends t to a limit cone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def ofFaithful {t : Cone F} {D : Type u₄} [Category.{v₄} D] (G : C ⥤ D) [G.Faithful] (ht : IsLimit (mapCone G t)) (lift : ∀ s : Cone F, s.pt ⟶ t.pt) (h : ∀ s, G.map (lift s) = ht.lift (mapCone G s)) : IsLimit t := { lift fac := fun s j => by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac uniq := fun s m w => by apply G.map_injective; rw [h] refine ht.uniq (mapCone G s) _ fun j => ?_ convert ← congrArg (fun f => G.map f) (w j) apply G.map_comp } /-- If `F` and `G` are naturally isomorphic, then `F.mapCone c` being a limit implies `G.mapCone c` is also a limit. -/ def mapConeEquiv {D : Type u₄} [Category.{v₄} D] {K : J ⥤ C} {F G : C ⥤ D} (h : F ≅ G) {c : Cone K} (t : IsLimit (mapCone F c)) : IsLimit (mapCone G c) := by apply postcomposeInvEquiv (isoWhiskerLeft K h :) (mapCone G c) _ apply t.ofIsoLimit (postcomposeWhiskerLeftMapCone h.symm c).symm /-- A cone is a limit cone exactly if there is a unique cone morphism from any other cone. -/ def isoUniqueConeMorphism {t : Cone F} : IsLimit t ≅ ∀ s, Unique (s ⟶ t) where hom h s := { default := h.liftConeMorphism s uniq := fun _ => h.uniq_cone_morphism } inv h := { lift := fun s => (h s).default.hom uniq := fun s f w => congrArg ConeMorphism.hom ((h s).uniq ⟨f, w⟩) } namespace OfNatIso variable {X : C} (h : F.cones.RepresentableBy X) /-- If `F.cones` is represented by `X`, each morphism `f : Y ⟶ X` gives a cone with cone point `Y`. -/ def coneOfHom {Y : C} (f : Y ⟶ X) : Cone F where pt := Y π := h.homEquiv f /-- If `F.cones` is represented by `X`, each cone `s` gives a morphism `s.pt ⟶ X`. -/ def homOfCone (s : Cone F) : s.pt ⟶ X := h.homEquiv.symm s.π @[simp] theorem coneOfHom_homOfCone (s : Cone F) : coneOfHom h (homOfCone h s) = s := by dsimp [coneOfHom, homOfCone] match s with | .mk s_pt s_π => congr exact h.homEquiv.apply_symm_apply s_π @[simp] theorem homOfCone_coneOfHom {Y : C} (f : Y ⟶ X) : homOfCone h (coneOfHom h f) = f := by simp [coneOfHom, homOfCone] /-- If `F.cones` is represented by `X`, the cone corresponding to the identity morphism on `X` will be a limit cone. -/ def limitCone : Cone F := coneOfHom h (𝟙 X) /-- If `F.cones` is represented by `X`, the cone corresponding to a morphism `f : Y ⟶ X` is the limit cone extended by `f`. -/ theorem coneOfHom_fac {Y : C} (f : Y ⟶ X) : coneOfHom h f = (limitCone h).extend f := by dsimp [coneOfHom, limitCone, Cone.extend] congr conv_lhs => rw [← Category.comp_id f] exact h.homEquiv_comp f (𝟙 X) /-- If `F.cones` is represented by `X`, any cone is the extension of the limit cone by the corresponding morphism. -/ theorem cone_fac (s : Cone F) : (limitCone h).extend (homOfCone h s) = s := by rw [← coneOfHom_homOfCone h s] conv_lhs => simp only [homOfCone_coneOfHom] apply (coneOfHom_fac _ _).symm end OfNatIso section open OfNatIso /-- If `F.cones` is representable, then the cone corresponding to the identity morphism on the representing object is a limit cone. -/ def ofRepresentableBy {X : C} (h : F.cones.RepresentableBy X) : IsLimit (limitCone h) where lift s := homOfCone h s fac s j := by have h := cone_fac h s cases s injection h with h₁ h₂ simp only at h₂ conv_rhs => rw [← h₂] rfl uniq s m w := by rw [← homOfCone_coneOfHom h m] congr rw [coneOfHom_fac] dsimp [Cone.extend]; cases s; congr with j; exact w j @[deprecated (since := "2025-05-09")] alias ofNatIso := ofRepresentableBy /-- Given a limit cone, `F.cones` is representable by the point of the cone. -/ def representableBy (hc : IsLimit t) : F.cones.RepresentableBy t.pt where homEquiv := hc.homEquiv homEquiv_comp {X X'} f g := NatTrans.ext <| funext fun j ↦ by simp end end IsLimit /-- A cocone `t` on `F` is a colimit cocone if each cocone on `F` admits a unique cocone morphism from `t`. -/ @[stacks 002F] structure IsColimit (t : Cocone F) where /-- `t.pt` maps to all other cocone covertices -/ desc : ∀ s : Cocone F, t.pt ⟶ s.pt /-- The map `desc` makes the diagram with the natural transformations commute -/ fac : ∀ (s : Cocone F) (j : J), t.ι.app j ≫ desc s = s.ι.app j := by cat_disch /-- `desc` is the unique such map -/ uniq : ∀ (s : Cocone F) (m : t.pt ⟶ s.pt) (_ : ∀ j : J, t.ι.app j ≫ m = s.ι.app j), m = desc s := by cat_disch attribute [reassoc (attr := simp)] IsColimit.fac namespace IsColimit instance subsingleton {t : Cocone F} : Subsingleton (IsColimit t) := ⟨by intro P Q; cases P; cases Q; congr; cat_disch⟩ /-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cocone point of a colimit cocone over `F` to the cocone point of any cocone over `G`. -/ def map {F G : J ⥤ C} {s : Cocone F} (P : IsColimit s) (t : Cocone G) (α : F ⟶ G) : s.pt ⟶ t.pt := P.desc ((Cocones.precompose α).obj t) @[reassoc (attr := simp)] theorem ι_map {F G : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (d : Cocone G) (α : F ⟶ G) (j : J) : c.ι.app j ≫ IsColimit.map hc d α = α.app j ≫ d.ι.app j := fac _ _ _ @[simp] theorem desc_self {t : Cocone F} (h : IsColimit t) : h.desc t = 𝟙 t.pt := (h.uniq _ _ fun _ => comp_id _).symm -- Repackaging the definition in terms of cocone morphisms. /-- The universal morphism from a colimit cocone to any other cocone. -/ @[simps] def descCoconeMorphism {t : Cocone F} (h : IsColimit t) (s : Cocone F) : t ⟶ s where hom := h.desc s theorem uniq_cocone_morphism {s t : Cocone F} (h : IsColimit t) {f f' : t ⟶ s} : f = f' := have : ∀ {g : t ⟶ s}, g = h.descCoconeMorphism s := by intro g; ext; exact h.uniq _ _ g.w this.trans this.symm /-- Restating the definition of a colimit cocone in terms of the ∃! operator. -/ theorem existsUnique {t : Cocone F} (h : IsColimit t) (s : Cocone F) : ∃! d : t.pt ⟶ s.pt, ∀ j, t.ι.app j ≫ d = s.ι.app j := ⟨h.desc s, h.fac s, h.uniq s⟩ /-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/ def ofExistsUnique {t : Cocone F} (ht : ∀ s : Cocone F, ∃! d : t.pt ⟶ s.pt, ∀ j, t.ι.app j ≫ d = s.ι.app j) : IsColimit t := by choose s hs hs' using ht exact ⟨s, hs, hs'⟩ /-- Alternative constructor for `IsColimit`, providing a morphism of cocones rather than a morphism between the cocone points and separately the factorisation condition. -/ @[simps] def mkCoconeMorphism {t : Cocone F} (desc : ∀ s : Cocone F, t ⟶ s) (uniq' : ∀ (s : Cocone F) (m : t ⟶ s), m = desc s) : IsColimit t where desc s := (desc s).hom uniq s m w := have : CoconeMorphism.mk m w = desc s := by apply uniq' congrArg CoconeMorphism.hom this /-- Colimit cocones on `F` are unique up to isomorphism. -/ @[simps] def uniqueUpToIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : s ≅ t where hom := P.descCoconeMorphism t inv := Q.descCoconeMorphism s hom_inv_id := P.uniq_cocone_morphism inv_hom_id := Q.uniq_cocone_morphism /-- Any cocone morphism between colimit cocones is an isomorphism. -/ theorem hom_isIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) (f : s ⟶ t) : IsIso f := ⟨⟨Q.descCoconeMorphism s, ⟨P.uniq_cocone_morphism, Q.uniq_cocone_morphism⟩⟩⟩ /-- Colimits of `F` are unique up to isomorphism. -/ def coconePointUniqueUpToIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : s.pt ≅ t.pt := (Cocones.forget F).mapIso (uniqueUpToIso P Q) @[reassoc (attr := simp)] theorem comp_coconePointUniqueUpToIso_hom {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) (j : J) : s.ι.app j ≫ (coconePointUniqueUpToIso P Q).hom = t.ι.app j := (uniqueUpToIso P Q).hom.w _ @[reassoc (attr := simp)] theorem comp_coconePointUniqueUpToIso_inv {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) (j : J) : t.ι.app j ≫ (coconePointUniqueUpToIso P Q).inv = s.ι.app j := (uniqueUpToIso P Q).inv.w _ @[reassoc (attr := simp)] theorem coconePointUniqueUpToIso_hom_desc {r s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : (coconePointUniqueUpToIso P Q).hom ≫ Q.desc r = P.desc r := P.uniq _ _ (by simp) @[reassoc (attr := simp)] theorem coconePointUniqueUpToIso_inv_desc {r s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : (coconePointUniqueUpToIso P Q).inv ≫ P.desc r = Q.desc r := Q.uniq _ _ (by simp) /-- Transport evidence that a cocone is a colimit cocone across an isomorphism of cocones. -/ def ofIsoColimit {r t : Cocone F} (P : IsColimit r) (i : r ≅ t) : IsColimit t := IsColimit.mkCoconeMorphism (fun s => i.inv ≫ P.descCoconeMorphism s) fun s m => by rw [i.eq_inv_comp]; apply P.uniq_cocone_morphism @[simp] theorem ofIsoColimit_desc {r t : Cocone F} (P : IsColimit r) (i : r ≅ t) (s) : (P.ofIsoColimit i).desc s = i.inv.hom ≫ P.desc s := rfl /-- Isomorphism of cocones preserves whether or not they are colimiting cocones. -/ def equivIsoColimit {r t : Cocone F} (i : r ≅ t) : IsColimit r ≃ IsColimit t where toFun h := h.ofIsoColimit i invFun h := h.ofIsoColimit i.symm left_inv := by cat_disch right_inv := by cat_disch @[simp] theorem equivIsoColimit_apply {r t : Cocone F} (i : r ≅ t) (P : IsColimit r) : equivIsoColimit i P = P.ofIsoColimit i := rfl @[simp] theorem equivIsoColimit_symm_apply {r t : Cocone F} (i : r ≅ t) (P : IsColimit t) : (equivIsoColimit i).symm P = P.ofIsoColimit i.symm := rfl /-- If the canonical morphism to a cocone point from a colimiting cocone point is an iso, then the first cocone was colimiting also. -/ def ofPointIso {r t : Cocone F} (P : IsColimit r) [i : IsIso (P.desc t)] : IsColimit t := ofIsoColimit P (by haveI : IsIso (P.descCoconeMorphism t).hom := i haveI : IsIso (P.descCoconeMorphism t) := Cocones.cocone_iso_of_hom_iso _ apply asIso (P.descCoconeMorphism t)) variable {t : Cocone F} theorem hom_desc (h : IsColimit t) {W : C} (m : t.pt ⟶ W) : m = h.desc { pt := W ι := { app := fun b => t.ι.app b ≫ m } } := h.uniq { pt := W ι := { app := fun b => t.ι.app b ≫ m } } m fun _ => rfl /-- Two morphisms out of a colimit are equal if their compositions with each cocone morphism are equal. -/ theorem hom_ext (h : IsColimit t) {W : C} {f f' : t.pt ⟶ W} (w : ∀ j, t.ι.app j ≫ f = t.ι.app j ≫ f') : f = f' := by rw [h.hom_desc f, h.hom_desc f']; congr; exact funext w /-- Given a left adjoint functor between categories of cocones, the image of a colimit cocone is a colimit cocone. -/ def ofLeftAdjoint {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} {left : Cocone G ⥤ Cocone F} {right : Cocone F ⥤ Cocone G} (adj : left ⊣ right) {c : Cocone G} (t : IsColimit c) : IsColimit (left.obj c) := mkCoconeMorphism (fun s => (adj.homEquiv c s).symm (t.descCoconeMorphism _)) fun _ _ => (Adjunction.homEquiv_apply_eq _ _ _).1 t.uniq_cocone_morphism /-- Given two functors which have equivalent categories of cocones, we can transport a colimiting cocone across the equivalence. -/ def ofCoconeEquiv {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cocone G ≌ Cocone F) {c : Cocone G} : IsColimit (h.functor.obj c) ≃ IsColimit c where toFun P := ofIsoColimit (ofLeftAdjoint h.symm.toAdjunction P) (h.unitIso.symm.app c) invFun := ofLeftAdjoint h.toAdjunction left_inv := by cat_disch right_inv := by cat_disch @[simp] theorem ofCoconeEquiv_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cocone G ≌ Cocone F) {c : Cocone G} (P : IsColimit (h.functor.obj c)) (s) : (ofCoconeEquiv h P).desc s = (h.unit.app c).hom ≫ (h.inverse.map (P.descCoconeMorphism (h.functor.obj s))).hom ≫ (h.unitInv.app s).hom := rfl @[simp] theorem ofCoconeEquiv_symm_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cocone G ≌ Cocone F) {c : Cocone G} (P : IsColimit c) (s) : ((ofCoconeEquiv h).symm P).desc s = (h.functor.map (P.descCoconeMorphism (h.inverse.obj s))).hom ≫ (h.counit.app s).hom := rfl /-- A cocone precomposed with a natural isomorphism is a colimit cocone if and only if the original cocone is. -/ def precomposeHomEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cocone G) : IsColimit ((Cocones.precompose α.hom).obj c) ≃ IsColimit c := ofCoconeEquiv (Cocones.precomposeEquivalence α) /-- A cocone precomposed with the inverse of a natural isomorphism is a colimit cocone if and only if the original cocone is. -/ def precomposeInvEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cocone F) : IsColimit ((Cocones.precompose α.inv).obj c) ≃ IsColimit c := precomposeHomEquiv α.symm c /-- Constructing an equivalence `is_colimit c ≃ is_colimit d` from a natural isomorphism between the underlying functors, and then an isomorphism between `c` transported along this and `d`. -/ def equivOfNatIsoOfIso {F G : J ⥤ C} (α : F ≅ G) (c : Cocone F) (d : Cocone G) (w : (Cocones.precompose α.inv).obj c ≅ d) : IsColimit c ≃ IsColimit d := (precomposeInvEquiv α _).symm.trans (equivIsoColimit w) /-- The cocone points of two colimit cocones for naturally isomorphic functors are themselves isomorphic. -/ @[simps] def coconePointsIsoOfNatIso {F G : J ⥤ C} {s : Cocone F} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) : s.pt ≅ t.pt where hom := P.map t w.hom inv := Q.map s w.inv hom_inv_id := P.hom_ext (by simp) inv_hom_id := Q.hom_ext (by simp) @[reassoc] theorem comp_coconePointsIsoOfNatIso_hom {F G : J ⥤ C} {s : Cocone F} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) (j : J) : s.ι.app j ≫ (coconePointsIsoOfNatIso P Q w).hom = w.hom.app j ≫ t.ι.app j := by simp @[reassoc] theorem comp_coconePointsIsoOfNatIso_inv {F G : J ⥤ C} {s : Cocone F} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) (j : J) : t.ι.app j ≫ (coconePointsIsoOfNatIso P Q w).inv = w.inv.app j ≫ s.ι.app j := by simp @[reassoc] theorem coconePointsIsoOfNatIso_hom_desc {F G : J ⥤ C} {s : Cocone F} {r t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) : (coconePointsIsoOfNatIso P Q w).hom ≫ Q.desc r = P.map _ w.hom := P.hom_ext (by simp) @[reassoc] theorem coconePointsIsoOfNatIso_inv_desc {F G : J ⥤ C} {s : Cocone G} {r t : Cocone F} (P : IsColimit t) (Q : IsColimit s) (w : F ≅ G) : (coconePointsIsoOfNatIso P Q w).inv ≫ P.desc r = Q.map _ w.inv := Q.hom_ext (by simp) section Equivalence open CategoryTheory.Equivalence /-- If `s : Cocone F` is a colimit cocone, so is `s` whiskered by an equivalence `e`. -/ def whiskerEquivalence {s : Cocone F} (P : IsColimit s) (e : K ≌ J) : IsColimit (s.whisker e.functor) := ofLeftAdjoint (Cocones.whiskeringEquivalence e).toAdjunction P /-- If `s : Cocone F` whiskered by an equivalence `e` is a colimit cocone, so is `s`. -/ def ofWhiskerEquivalence {s : Cocone F} (e : K ≌ J) (P : IsColimit (s.whisker e.functor)) : IsColimit s := equivIsoColimit ((Cocones.whiskeringEquivalence e).unitIso.app s).symm (ofLeftAdjoint (Cocones.whiskeringEquivalence e).symm.toAdjunction P) /-- Given an equivalence of diagrams `e`, `s` is a colimit cocone iff `s.whisker e.functor` is. -/ def whiskerEquivalenceEquiv {s : Cocone F} (e : K ≌ J) : IsColimit s ≃ IsColimit (s.whisker e.functor) := ⟨fun h => h.whiskerEquivalence e, ofWhiskerEquivalence e, by cat_disch, by cat_disch⟩ /-- A colimit cocone extended by an isomorphism is a colimit cocone. -/ def extendIso {s : Cocone F} {X : C} (i : s.pt ⟶ X) [IsIso i] (hs : IsColimit s) : IsColimit (s.extend i) := IsColimit.ofIsoColimit hs (Cocones.extendIso s (asIso i)) /-- A cocone is a colimit cocone if its extension by an isomorphism is. -/ def ofExtendIso {s : Cocone F} {X : C} (i : s.pt ⟶ X) [IsIso i] (hs : IsColimit (s.extend i)) : IsColimit s := IsColimit.ofIsoColimit hs (Cocones.extendIso s (asIso i)).symm /-- A cocone is a colimit cocone iff its extension by an isomorphism is. -/ def extendIsoEquiv {s : Cocone F} {X : C} (i : s.pt ⟶ X) [IsIso i] : IsColimit s ≃ IsColimit (s.extend i) := equivOfSubsingletonOfSubsingleton (extendIso i) (ofExtendIso i) /-- We can prove two cocone points `(s : Cocone F).pt` and `(t : Cocone G).pt` are isomorphic if * both cocones are colimit cocones * their indexing categories are equivalent via some `e : J ≌ K`, * the triangle of functors commutes up to a natural isomorphism: `e.functor ⋙ G ≅ F`. This is the most general form of uniqueness of cocone points, allowing relabelling of both the indexing category (up to equivalence) and the functor (up to natural isomorphism). -/ @[simps] def coconePointsIsoOfEquivalence {F : J ⥤ C} {s : Cocone F} {G : K ⥤ C} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : s.pt ≅ t.pt := let w' : e.inverse ⋙ F ≅ G := (isoWhiskerLeft e.inverse w).symm ≪≫ invFunIdAssoc e G { hom := P.desc ((Cocones.equivalenceOfReindexing e w).functor.obj t) inv := Q.desc ((Cocones.equivalenceOfReindexing e.symm w').functor.obj s) hom_inv_id := by apply hom_ext P; intro j dsimp [w'] simp only [Limits.Cocone.whisker_ι, fac, invFunIdAssoc_inv_app, whiskerLeft_app, assoc, comp_id, Limits.Cocones.precompose_obj_ι, fac_assoc, NatTrans.comp_app] rw [counitInv_app_functor, ← Functor.comp_map, ← w.inv.naturality_assoc] simp inv_hom_id := by apply hom_ext Q cat_disch } end Equivalence /-- The universal property of a colimit cocone: a map `X ⟶ W` is the same as a cocone on `F` with cone point `W`. -/ def homEquiv (h : IsColimit t) {W : C} : (t.pt ⟶ W) ≃ (F ⟶ (const J).obj W) where toFun f := (t.extend f).ι invFun ι := h.desc { pt := W ι } left_inv f := h.hom_ext (by simp) right_inv ι := by cat_disch @[simp] lemma homEquiv_apply (h : IsColimit t) {W : C} (f : t.pt ⟶ W) : h.homEquiv f = (t.extend f).ι := rfl @[reassoc (attr := simp)] lemma ι_app_homEquiv_symm (h : IsColimit t) {W : C} (f : F ⟶ (const J).obj W) (j : J) : t.ι.app j ≫ h.homEquiv.symm f = f.app j := by simp [homEquiv] lemma homEquiv_symm_naturality (h : IsColimit t) {W W' : C} (f : F ⟶ (const J).obj W) (g : W ⟶ W') : h.homEquiv.symm (f ≫ (Functor.const _).map g) = h.homEquiv.symm f ≫ g := h.homEquiv.injective (by aesop) /-- The universal property of a colimit cocone: a map `X ⟶ W` is the same as a cocone on `F` with cone point `W`. -/ def homIso (h : IsColimit t) (W : C) : ULift.{u₁} (t.pt ⟶ W : Type v₃) ≅ F ⟶ (const J).obj W := Equiv.toIso (Equiv.ulift.trans h.homEquiv) @[simp] theorem homIso_hom (h : IsColimit t) {W : C} (f : ULift (t.pt ⟶ W)) : (IsColimit.homIso h W).hom f = (t.extend f.down).ι := rfl /-- The colimit of `F` represents the functor taking `W` to the set of cocones on `F` with cone point `W`. -/ def natIso (h : IsColimit t) : coyoneda.obj (op t.pt) ⋙ uliftFunctor.{u₁} ≅ F.cocones := NatIso.ofComponents (IsColimit.homIso h) /-- Another, more explicit, formulation of the universal property of a colimit cocone. See also `homIso`. -/ def homIso' (h : IsColimit t) (W : C) : ULift.{u₁} (t.pt ⟶ W : Type v₃) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j' : J} (f : j ⟶ j'), F.map f ≫ p j' = p j } := h.homIso W ≪≫ { hom := fun ι => ⟨fun j => ι.app j, fun {j} {j'} f => by convert ← ι.naturality f; apply comp_id⟩ inv := fun p => { app := fun j => p.1 j naturality := fun j j' f => by dsimp; rw [comp_id]; exact p.2 f } } /-- If G : C → D is a faithful functor which sends t to a colimit cocone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def ofFaithful {t : Cocone F} {D : Type u₄} [Category.{v₄} D] (G : C ⥤ D) [G.Faithful] (ht : IsColimit (mapCocone G t)) (desc : ∀ s : Cocone F, t.pt ⟶ s.pt) (h : ∀ s, G.map (desc s) = ht.desc (mapCocone G s)) : IsColimit t := { desc fac := fun s j => by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac uniq := fun s m w => by apply G.map_injective; rw [h] refine ht.uniq (mapCocone G s) _ fun j => ?_ convert ← congrArg (fun f => G.map f) (w j) apply G.map_comp } /-- If `F` and `G` are naturally isomorphic, then `F.mapCocone c` being a colimit implies `G.mapCocone c` is also a colimit. -/ def mapCoconeEquiv {D : Type u₄} [Category.{v₄} D] {K : J ⥤ C} {F G : C ⥤ D} (h : F ≅ G) {c : Cocone K} (t : IsColimit (mapCocone F c)) : IsColimit (mapCocone G c) := by apply IsColimit.ofIsoColimit _ (precomposeWhiskerLeftMapCocone h c) apply (precomposeInvEquiv (isoWhiskerLeft K h :) _).symm t /-- A cocone is a colimit cocone exactly if there is a unique cocone morphism from any other cocone. -/ def isoUniqueCoconeMorphism {t : Cocone F} : IsColimit t ≅ ∀ s, Unique (t ⟶ s) where hom h s := { default := h.descCoconeMorphism s uniq := fun _ => h.uniq_cocone_morphism } inv h := { desc := fun s => (h s).default.hom uniq := fun s f w => congrArg CoconeMorphism.hom ((h s).uniq ⟨f, w⟩) } namespace OfNatIso variable {X : C} (h : F.cocones.CorepresentableBy X) /-- If `F.cocones` is corepresented by `X`, each morphism `f : X ⟶ Y` gives a cocone with cone point `Y`. -/ def coconeOfHom {Y : C} (f : X ⟶ Y) : Cocone F where pt := Y ι := h.homEquiv f /-- If `F.cocones` is corepresented by `X`, each cocone `s` gives a morphism `X ⟶ s.pt`. -/ def homOfCocone (s : Cocone F) : X ⟶ s.pt := h.homEquiv.symm s.ι @[simp] theorem coconeOfHom_homOfCocone (s : Cocone F) : coconeOfHom h (homOfCocone h s) = s := by dsimp [coconeOfHom, homOfCocone] match s with | .mk s_pt s_ι => congr exact h.homEquiv.apply_symm_apply s_ι @[simp] theorem homOfCocone_coconeOfHom {Y : C} (f : X ⟶ Y) : homOfCocone h (coconeOfHom h f) = f := by simp [homOfCocone, coconeOfHom] @[deprecated (since := "2025-05-13")] alias homOfCocone_cooneOfHom := homOfCocone_coconeOfHom /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to the identity morphism on `X` will be a colimit cocone. -/ def colimitCocone : Cocone F := coconeOfHom h (𝟙 X) /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to a morphism `f : Y ⟶ X` is the colimit cocone extended by `f`. -/ theorem coconeOfHom_fac {Y : C} (f : X ⟶ Y) : coconeOfHom h f = (colimitCocone h).extend f := by dsimp [coconeOfHom, colimitCocone, Cocone.extend] congr conv_lhs => rw [← Category.id_comp f] exact h.homEquiv_comp f (𝟙 X) /-- If `F.cocones` is corepresented by `X`, any cocone is the extension of the colimit cocone by the corresponding morphism. -/ theorem cocone_fac (s : Cocone F) : (colimitCocone h).extend (homOfCocone h s) = s := by rw [← coconeOfHom_homOfCocone h s] conv_lhs => simp only [homOfCocone_coconeOfHom] apply (coconeOfHom_fac _ _).symm end OfNatIso section open OfNatIso /-- If `F.cocones` is corepresentable, then the cocone corresponding to the identity morphism on the representing object is a colimit cocone. -/ def ofCorepresentableBy {X : C} (h : F.cocones.CorepresentableBy X) : IsColimit (colimitCocone h) where desc s := homOfCocone h s fac s j := by have h := cocone_fac h s cases s injection h with h₁ h₂ simp only at h₂ conv_rhs => rw [← h₂] rfl uniq s m w := by rw [← homOfCocone_coconeOfHom h m] congr rw [coconeOfHom_fac] dsimp [Cocone.extend]; cases s; congr with j; exact w j @[deprecated (since := "2025-05-09")] alias ofNatIso := ofCorepresentableBy /-- Given a colimit cocone, `F.cocones` is corepresentable by the point of the cocone. -/ def corepresentableBy (hc : IsColimit t) : F.cocones.CorepresentableBy t.pt where homEquiv := hc.homEquiv homEquiv_comp {X X'} f g := NatTrans.ext <| funext fun j ↦ by simp end end IsColimit end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/VanKampen.lean
import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts /-! # Universal colimits and van Kampen colimits ## Main definitions - `CategoryTheory.IsUniversalColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. - `CategoryTheory.IsVanKampenColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. ## References - https://ncatlab.org/nlab/show/van+Kampen+colimit - [Stephen Lack and Paweł Sobociński, Adhesive Categories][adhesive2004] -/ open CategoryTheory.Limits CategoryTheory.Functor namespace CategoryTheory universe v' u' v u variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C] variable {K : Type*} [Category K] {D : Type*} [Category D] section NatTrans /-- A natural transformation is equifibered if every commutative square of the following form is a pullback. ``` F(X) → F(Y) ↓ ↓ G(X) → G(Y) ``` -/ def NatTrans.Equifibered {F G : J ⥤ C} (α : F ⟶ G) : Prop := ∀ ⦃i j : J⦄ (f : i ⟶ j), IsPullback (F.map f) (α.app i) (α.app j) (G.map f) theorem NatTrans.equifibered_of_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] : Equifibered α := fun _ _ f => IsPullback.of_vert_isIso ⟨NatTrans.naturality _ f⟩ theorem NatTrans.Equifibered.comp {F G H : J ⥤ C} {α : F ⟶ G} {β : G ⟶ H} (hα : Equifibered α) (hβ : Equifibered β) : Equifibered (α ≫ β) := fun _ _ f => (hα f).paste_vert (hβ f) theorem NatTrans.Equifibered.whiskerRight {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : C ⥤ D) [∀ (i j : J) (f : j ⟶ i), PreservesLimit (cospan (α.app i) (G.map f)) H] : Equifibered (whiskerRight α H) := fun _ _ f => (hα f).map H theorem NatTrans.Equifibered.whiskerLeft {K : Type*} [Category K] {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : K ⥤ J) : Equifibered (whiskerLeft H α) := fun _ _ f => hα (H.map f) theorem mapPair_equifibered {F F' : Discrete WalkingPair ⥤ C} (α : F ⟶ F') : NatTrans.Equifibered α := by rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ all_goals dsimp; simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by simp only [Category.comp_id, Category.id_comp]⟩ theorem NatTrans.equifibered_of_discrete {ι : Type*} {F G : Discrete ι ⥤ C} (α : F ⟶ G) : NatTrans.Equifibered α := by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by rw [Category.id_comp, Category.comp_id]⟩ end NatTrans /-- A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. -/ def IsUniversalColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), (∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j)) → Nonempty (IsColimit c') /-- A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. TODO: Show that this is iff the functor `C ⥤ Catᵒᵖ` sending `x` to `C/x` preserves it. TODO: Show that this is iff the inclusion functor `C ⥤ Span(C)` preserves it. -/ def IsVanKampenColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), Nonempty (IsColimit c') ↔ ∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j) theorem IsVanKampenColimit.isUniversal {F : J ⥤ C} {c : Cocone F} (H : IsVanKampenColimit c) : IsUniversalColimit c := fun _ c' α f h hα => (H c' α f h hα).mpr /-- A universal colimit is a colimit. -/ noncomputable def IsUniversalColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsUniversalColimit c) : IsColimit c := by refine ((h c (𝟙 F) (𝟙 c.pt :) (by rw [Functor.map_id, Category.comp_id, Category.id_comp]) (NatTrans.equifibered_of_isIso _)) fun j => ?_).some haveI : IsIso (𝟙 c.pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by simp⟩ /-- A van Kampen colimit is a colimit. -/ noncomputable def IsVanKampenColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsVanKampenColimit c) : IsColimit c := h.isUniversal.isColimit theorem IsInitial.isVanKampenColimit [HasStrictInitialObjects C] {X : C} (h : IsInitial X) : IsVanKampenColimit (asEmptyCocone X) := by intro F' c' α f hf hα have : F' = Functor.empty C := by apply Functor.hext <;> rintro ⟨⟨⟩⟩ subst this haveI := h.isIso_to f refine ⟨by rintro _ ⟨⟨⟩⟩, fun _ => ⟨IsColimit.ofIsoColimit h (Cocones.ext (asIso f).symm <| by rintro ⟨⟨⟩⟩)⟩⟩ section Functor theorem IsUniversalColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (hc : IsUniversalColimit c) (e : c ≅ c') : IsUniversalColimit c' := by intro F' c'' α f h hα H have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j apply hc c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα intro j rw [← Category.comp_id (α.app j)] exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨by simp⟩) theorem IsVanKampenColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (H : IsVanKampenColimit c) (e : c ≅ c') : IsVanKampenColimit c' := by intro F' c'' α f h hα have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j rw [H c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα] apply forall_congr' intro j conv_lhs => rw [← Category.comp_id (α.app j)] haveI : IsIso e.inv.hom := Functor.map_isIso (Cocones.forget _) e.inv exact (IsPullback.of_vert_isIso ⟨by simp⟩).paste_vert_iff (NatTrans.congr_app h j).symm theorem IsVanKampenColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsVanKampenColimit c) : IsVanKampenColimit ((Cocones.precompose α).obj c) := by intro F' c' α' f e hα refine (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))).trans ?_ apply forall_congr' intro j simp only [Functor.const_obj_obj, NatTrans.comp_app, Cocones.precompose_obj_pt, Cocones.precompose_obj_ι] have : IsPullback (α.app j ≫ c.ι.app j) (α.app j) (𝟙 _) (c.ι.app j) := IsPullback.of_vert_isIso ⟨Category.comp_id _⟩ rw [← IsPullback.paste_vert_iff this _, Category.comp_id] exact (congr_app e j).symm theorem IsUniversalColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsUniversalColimit c) : IsUniversalColimit ((Cocones.precompose α).obj c) := by intro F' c' α' f e hα H apply (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))) intro j simp only [Functor.const_obj_obj, NatTrans.comp_app] rw [← Category.comp_id f] exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨Category.comp_id _⟩) theorem IsVanKampenColimit.precompose_isIso_iff {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} : IsVanKampenColimit ((Cocones.precompose α).obj c) ↔ IsVanKampenColimit c := ⟨fun hc ↦ IsVanKampenColimit.of_iso (IsVanKampenColimit.precompose_isIso (inv α) hc) (Cocones.ext (Iso.refl _) (by simp)), IsVanKampenColimit.precompose_isIso α⟩ theorem IsUniversalColimit.of_mapCocone (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [PreservesLimitsOfShape WalkingCospan G] [ReflectsColimitsOfShape J G] (hc : IsUniversalColimit (G.mapCocone c)) : IsUniversalColimit c := fun F' c' α f h hα H ↦ ⟨isColimitOfReflects _ (hc (G.mapCocone c') (whiskerRight α G) (G.map f) (by ext j; simpa using G.congr_map (NatTrans.congr_app h j)) (hα.whiskerRight G) (fun j ↦ (H j).map G)).some⟩ theorem IsVanKampenColimit.of_mapCocone (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [∀ (i j : J) (X : C) (f : X ⟶ F.obj j) (g : i ⟶ j), PreservesLimit (cospan f (F.map g)) G] [∀ (i : J) (X : C) (f : X ⟶ c.pt), PreservesLimit (cospan f (c.ι.app i)) G] [ReflectsLimitsOfShape WalkingCospan G] [PreservesColimitsOfShape J G] [ReflectsColimitsOfShape J G] (H : IsVanKampenColimit (G.mapCocone c)) : IsVanKampenColimit c := by intro F' c' α f h hα refine (Iff.trans ?_ (H (G.mapCocone c') (whiskerRight α G) (G.map f) (by ext j; simpa using G.congr_map (NatTrans.congr_app h j)) (hα.whiskerRight G))).trans (forall_congr' fun j => ?_) · exact ⟨fun h => ⟨isColimitOfPreserves G h.some⟩, fun h => ⟨isColimitOfReflects G h.some⟩⟩ · exact IsPullback.map_iff G (NatTrans.congr_app h.symm j) theorem IsVanKampenColimit.mapCocone_iff (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [G.IsEquivalence] : IsVanKampenColimit (G.mapCocone c) ↔ IsVanKampenColimit c := ⟨IsVanKampenColimit.of_mapCocone G, fun hc ↦ by let e : F ⋙ G ⋙ Functor.inv G ≅ F := NatIso.hcomp (Iso.refl F) G.asEquivalence.unitIso.symm apply IsVanKampenColimit.of_mapCocone G.inv apply (IsVanKampenColimit.precompose_isIso_iff e.inv).mp exact hc.of_iso (Cocones.ext (G.asEquivalence.unitIso.app c.pt) (fun j => (by simp [e])))⟩ theorem IsUniversalColimit.whiskerEquivalence {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} (hc : IsUniversalColimit c) : IsUniversalColimit (c.whisker e.functor) := by intro F' c' α f e' hα H convert hc (c'.whisker e.inverse) (whiskerLeft e.inverse α ≫ (e.invFunIdAssoc F).hom) f ?_ ((hα.whiskerLeft _).comp (NatTrans.equifibered_of_isIso _)) ?_ using 1 · exact (IsColimit.whiskerEquivalenceEquiv e.symm).nonempty_congr · convert congr_arg (whiskerLeft e.inverse) e' ext simp · intro k rw [← Category.comp_id f] refine (H (e.inverse.obj k)).paste_vert ?_ exact IsPullback.of_vert_isIso ⟨by simp⟩ theorem IsUniversalColimit.whiskerEquivalence_iff {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} : IsUniversalColimit (c.whisker e.functor) ↔ IsUniversalColimit c := ⟨fun hc ↦ ((hc.whiskerEquivalence e.symm).precompose_isIso (e.invFunIdAssoc F).inv).of_iso (Cocones.ext (Iso.refl _) (by simp)), IsUniversalColimit.whiskerEquivalence e⟩ theorem IsVanKampenColimit.whiskerEquivalence {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) : IsVanKampenColimit (c.whisker e.functor) := by intro F' c' α f e' hα convert hc (c'.whisker e.inverse) (whiskerLeft e.inverse α ≫ (e.invFunIdAssoc F).hom) f ?_ ((hα.whiskerLeft _).comp (NatTrans.equifibered_of_isIso _)) using 1 · exact (IsColimit.whiskerEquivalenceEquiv e.symm).nonempty_congr · simp only [Functor.const_obj_obj, Functor.comp_obj, Cocone.whisker_pt, Cocone.whisker_ι, whiskerLeft_app, NatTrans.comp_app, Equivalence.invFunIdAssoc_hom_app, Functor.id_obj] constructor · intro H k rw [← Category.comp_id f] refine (H (e.inverse.obj k)).paste_vert ?_ have : IsIso (𝟙 (Cocone.whisker e.functor c).pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by simp⟩ · intro H j have : α.app j = F'.map (e.unit.app _) ≫ α.app _ ≫ F.map (e.counit.app (e.functor.obj j)) := by simp [← Functor.map_comp] rw [← Category.id_comp f, this] refine IsPullback.paste_vert ?_ (H (e.functor.obj j)) exact IsPullback.of_vert_isIso ⟨by simp⟩ · ext k simpa using congr_app e' (e.inverse.obj k) theorem IsVanKampenColimit.whiskerEquivalence_iff {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} : IsVanKampenColimit (c.whisker e.functor) ↔ IsVanKampenColimit c := ⟨fun hc ↦ ((hc.whiskerEquivalence e.symm).precompose_isIso (e.invFunIdAssoc F).inv).of_iso (Cocones.ext (Iso.refl _) (by simp)), IsVanKampenColimit.whiskerEquivalence e⟩ theorem isVanKampenColimit_of_evaluation [HasPullbacks D] [HasColimitsOfShape J D] (F : J ⥤ C ⥤ D) (c : Cocone F) (hc : ∀ x : C, IsVanKampenColimit (((evaluation C D).obj x).mapCocone c)) : IsVanKampenColimit c := by intro F' c' α f e hα have := fun x => hc x (((evaluation C D).obj x).mapCocone c') (whiskerRight α _) (((evaluation C D).obj x).map f) (by ext y dsimp exact NatTrans.congr_app (NatTrans.congr_app e y) x) (hα.whiskerRight _) constructor · rintro ⟨hc'⟩ j refine ⟨⟨(NatTrans.congr_app e j).symm⟩, ⟨evaluationJointlyReflectsLimits _ ?_⟩⟩ refine fun x => (isLimitMapConePullbackConeEquiv _ _).symm ?_ exact ((this x).mp ⟨isColimitOfPreserves _ hc'⟩ _).isLimit · exact fun H => ⟨evaluationJointlyReflectsColimits _ fun x => ((this x).mpr fun j => (H j).map ((evaluation C D).obj x)).some⟩ end Functor section reflective theorem IsUniversalColimit.map_reflective {Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful] {F : J ⥤ D} {c : Cocone (F ⋙ Gr)} (H : IsUniversalColimit c) [∀ X (f : X ⟶ Gl.obj c.pt), HasPullback (Gr.map f) (adj.unit.app c.pt)] [∀ X (f : X ⟶ Gl.obj c.pt), PreservesLimit (cospan (Gr.map f) (adj.unit.app c.pt)) Gl] : IsUniversalColimit (Gl.mapCocone c) := by have := adj.rightAdjoint_preservesLimits have : PreservesColimitsOfSize.{u', v'} Gl := adj.leftAdjoint_preservesColimits intro F' c' α f h hα hc' have : HasPullback (Gl.map (Gr.map f)) (Gl.map (adj.unit.app c.pt)) := ⟨⟨_, isLimitPullbackConeMapOfIsLimit _ pullback.condition (IsPullback.of_hasPullback _ _).isLimit⟩⟩ let α' := α ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft F adj.counit ≫ F.rightUnitor.hom have hα' : NatTrans.Equifibered α' := hα.comp (NatTrans.equifibered_of_isIso _) have hadj : ∀ X, Gl.map (adj.unit.app X) = inv (adj.counit.app _) := by intro X apply IsIso.eq_inv_of_inv_hom_id exact adj.left_triangle_components _ haveI : ∀ X, IsIso (Gl.map (adj.unit.app X)) := by simp_rw [hadj] infer_instance have hα'' : ∀ j, Gl.map (Gr.map <| α'.app j) = adj.counit.app _ ≫ α.app j := by intro j rw [← cancel_mono (adj.counit.app <| F.obj j)] dsimp [α'] simp only [Category.comp_id, Adjunction.counit_naturality_assoc, Category.id_comp, Adjunction.counit_naturality, Category.assoc, Functor.map_comp] have hc'' : ∀ j, α.app j ≫ Gl.map (c.ι.app j) = c'.ι.app j ≫ f := NatTrans.congr_app h let β := isoWhiskerLeft F' (asIso adj.counit) ≪≫ F'.rightUnitor let c'' : Cocone (F' ⋙ Gr) := by refine { pt := pullback (Gr.map f) (adj.unit.app _) ι := { app := fun j ↦ pullback.lift (Gr.map <| c'.ι.app j) (Gr.map (α'.app j) ≫ c.ι.app j) ?_ naturality := ?_ } } · rw [← Gr.map_comp, ← hc''] exact (congrArg _ (Adjunction.unit_naturality _ _).symm).mpr (by simp_all) · intro i j g dsimp [α'] ext all_goals simp only [Category.comp_id, Category.id_comp, Category.assoc, ← Functor.map_comp, pullback.lift_fst, pullback.lift_snd, ← Functor.map_comp_assoc] · congr 1 exact c'.w _ · rw [α.naturality_assoc] dsimp rw [adj.counit_naturality, ← Category.assoc, Gr.map_comp_assoc] congr 1 exact c.w _ let cf : (Cocones.precompose β.hom).obj c' ⟶ Gl.mapCocone c'' := by refine { hom := pullback.lift ?_ f ?_ ≫ (PreservesPullback.iso _ _ _).inv, w := ?_ } · exact inv <| adj.counit.app c'.pt · simp [← cancel_mono (adj.counit.app <| Gl.obj c.pt)] · intro j rw [← Category.assoc, Iso.comp_inv_eq] ext all_goals simp only [c'', PreservesPullback.iso_hom_fst, PreservesPullback.iso_hom_snd, pullback.lift_fst, pullback.lift_snd, Category.assoc, Functor.mapCocone_ι_app, ← Gl.map_comp] · rw [IsIso.comp_inv_eq, adj.counit_naturality] dsimp [β] rw [Category.comp_id] · rw [Gl.map_comp, hα'', Category.assoc, hc''] dsimp [β] rw [Category.comp_id, Category.assoc] have : cf.hom ≫ (PreservesPullback.iso _ _ _).hom ≫ pullback.fst _ _ ≫ adj.counit.app _ = 𝟙 _ := by simp only [cf, IsIso.inv_hom_id, Iso.inv_hom_id_assoc, Category.assoc, pullback.lift_fst_assoc] have : IsIso cf := by apply @Cocones.cocone_iso_of_hom_iso (i := ?_) rw [← IsIso.eq_comp_inv] at this rw [this] infer_instance have ⟨Hc''⟩ := H c'' (whiskerRight α' Gr) (pullback.snd _ _) ?_ (hα'.whiskerRight Gr) ?_ · exact ⟨IsColimit.precomposeHomEquiv β c' <| (isColimitOfPreserves Gl Hc'').ofIsoColimit (asIso cf).symm⟩ · ext j dsimp [c''] simp only [pullback.lift_snd] · intro j apply IsPullback.of_right _ _ (IsPullback.of_hasPullback _ _) · dsimp [α', c''] simp only [Category.comp_id, Category.id_comp, Category.assoc, Functor.map_comp, pullback.lift_fst] rw [← Category.comp_id (Gr.map f)] refine ((hc' j).map Gr).paste_vert (IsPullback.of_vert_isIso ⟨?_⟩) rw [← adj.unit_naturality, Category.comp_id, ← Category.assoc, ← Category.id_comp (Gr.map ((Gl.mapCocone c).ι.app j))] congr 1 rw [← cancel_mono (Gr.map (adj.counit.app (F.obj j)))] dsimp simp only [Category.comp_id, Adjunction.right_triangle_components, Category.id_comp, Category.assoc] · dsimp [c''] simp only [pullback.lift_snd] theorem IsVanKampenColimit.map_reflective [HasColimitsOfShape J C] {Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful] {F : J ⥤ D} {c : Cocone (F ⋙ Gr)} (H : IsVanKampenColimit c) [∀ X (f : X ⟶ Gl.obj c.pt), HasPullback (Gr.map f) (adj.unit.app c.pt)] [∀ X (f : X ⟶ Gl.obj c.pt), PreservesLimit (cospan (Gr.map f) (adj.unit.app c.pt)) Gl] [∀ X i (f : X ⟶ c.pt), PreservesLimit (cospan f (c.ι.app i)) Gl] : IsVanKampenColimit (Gl.mapCocone c) := by have := adj.rightAdjoint_preservesLimits have : PreservesColimitsOfSize.{u', v'} Gl := adj.leftAdjoint_preservesColimits intro F' c' α f h hα refine ⟨?_, H.isUniversal.map_reflective adj c' α f h hα⟩ intro ⟨hc'⟩ j let α' := α ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft F adj.counit ≫ F.rightUnitor.hom have hα' : NatTrans.Equifibered α' := hα.comp (NatTrans.equifibered_of_isIso _) have hα'' : ∀ j, Gl.map (Gr.map <| α'.app j) = adj.counit.app _ ≫ α.app j := by intro j rw [← cancel_mono (adj.counit.app <| F.obj j)] dsimp [α'] simp only [Category.comp_id, Adjunction.counit_naturality_assoc, Category.id_comp, Adjunction.counit_naturality, Category.assoc, Functor.map_comp] let β := isoWhiskerLeft F' (asIso adj.counit) ≪≫ F'.rightUnitor let hl := (IsColimit.precomposeHomEquiv β c').symm hc' let hr := isColimitOfPreserves Gl (colimit.isColimit <| F' ⋙ Gr) have : α.app j = β.inv.app _ ≫ Gl.map (Gr.map <| α'.app j) := by rw [hα''] simp [β] rw [this] have : f = (hl.coconePointUniqueUpToIso hr).hom ≫ Gl.map (colimit.desc _ ⟨_, whiskerRight α' Gr ≫ c.2⟩) := by symm convert @IsColimit.coconePointUniqueUpToIso_hom_desc _ _ _ _ ((F' ⋙ Gr) ⋙ Gl) (Gl.mapCocone ⟨_, (whiskerRight α' Gr ≫ c.2 :)⟩) _ _ hl hr using 2 · apply hr.hom_ext intro j rw [hr.fac, Functor.mapCocone_ι_app, ← Gl.map_comp, colimit.cocone_ι, colimit.ι_desc] rfl · clear_value α' apply hl.hom_ext intro j rw [hl.fac] dsimp [β] simp only [Category.comp_id, hα'', Category.assoc, Gl.map_comp] congr 1 exact (NatTrans.congr_app h j).symm rw [this] have := ((H (colimit.cocone <| F' ⋙ Gr) (whiskerRight α' Gr) (colimit.desc _ ⟨_, whiskerRight α' Gr ≫ c.2⟩) ?_ (hα'.whiskerRight Gr)).mp ⟨(getColimitCocone <| F' ⋙ Gr).2⟩ j).map Gl · convert IsPullback.paste_vert _ this refine IsPullback.of_vert_isIso ⟨?_⟩ rw [← IsIso.inv_comp_eq, ← Category.assoc, NatIso.inv_inv_app] exact IsColimit.comp_coconePointUniqueUpToIso_hom hl hr _ · clear_value α' ext j simp end reflective section Initial theorem hasStrictInitial_of_isUniversal [HasInitial C] (H : IsUniversalColimit (BinaryCofan.mk (𝟙 (⊥_ C)) (𝟙 (⊥_ C)))) : HasStrictInitialObjects C := hasStrictInitialObjects_of_initial_is_strict (by intro A f suffices IsColimit (BinaryCofan.mk (𝟙 A) (𝟙 A)) by obtain ⟨l, h₁, h₂⟩ := Limits.BinaryCofan.IsColimit.desc' this (f ≫ initial.to A) (𝟙 A) rcases(Category.id_comp _).symm.trans h₂ with rfl exact ⟨⟨_, ((Category.id_comp _).symm.trans h₁).symm, initialIsInitial.hom_ext _ _⟩⟩ refine (H (BinaryCofan.mk (𝟙 _) (𝟙 _)) (mapPair f f) f (by ext ⟨⟨⟩⟩ <;> simp) (mapPair_equifibered _) ?_).some rintro ⟨⟨⟩⟩ <;> dsimp <;> exact IsPullback.of_horiz_isIso ⟨(Category.id_comp _).trans (Category.comp_id _).symm⟩) theorem isVanKampenColimit_of_isEmpty [HasStrictInitialObjects C] [IsEmpty J] {F : J ⥤ C} (c : Cocone F) (hc : IsColimit c) : IsVanKampenColimit c := by have : IsInitial c.pt := by have := (IsColimit.precomposeInvEquiv (Functor.uniqueFromEmpty _) _).symm (hc.whiskerEquivalence (equivalenceOfIsEmpty (Discrete PEmpty.{1}) J)) exact IsColimit.ofIsoColimit this (Cocones.ext (Iso.refl c.pt) (fun {X} ↦ isEmptyElim X)) replace this := IsInitial.isVanKampenColimit this apply (IsVanKampenColimit.whiskerEquivalence_iff (equivalenceOfIsEmpty (Discrete PEmpty.{1}) J)).mp exact (this.precompose_isIso (Functor.uniqueFromEmpty ((equivalenceOfIsEmpty (Discrete PEmpty.{1}) J).functor ⋙ F)).hom).of_iso (Cocones.ext (Iso.refl _) (by simp)) end Initial section BinaryCoproduct variable {X Y : C} theorem BinaryCofan.isVanKampen_iff (c : BinaryCofan X Y) : IsVanKampenColimit c ↔ ∀ {X' Y' : C} (c' : BinaryCofan X' Y') (αX : X' ⟶ X) (αY : Y' ⟶ Y) (f : c'.pt ⟶ c.pt) (_ : αX ≫ c.inl = c'.inl ≫ f) (_ : αY ≫ c.inr = c'.inr ≫ f), Nonempty (IsColimit c') ↔ IsPullback c'.inl αX f c.inl ∧ IsPullback c'.inr αY f c.inr := by constructor · introv H hαX hαY rw [H c' (mapPair αX αY) f (by ext ⟨⟨⟩⟩ <;> dsimp <;> assumption) (mapPair_equifibered _)] constructor · intro H exact ⟨H _, H _⟩ · rintro H ⟨⟨⟩⟩ exacts [H.1, H.2] · introv H F' hα h let X' := F'.obj ⟨WalkingPair.left⟩ let Y' := F'.obj ⟨WalkingPair.right⟩ have : F' = pair X' Y' := by apply Functor.hext · rintro ⟨⟨⟩⟩ <;> rfl · rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ <;> simp [X', Y'] clear_value X' Y' subst this change BinaryCofan X' Y' at c' rw [H c' _ _ _ (NatTrans.congr_app hα ⟨WalkingPair.left⟩) (NatTrans.congr_app hα ⟨WalkingPair.right⟩)] constructor · rintro H ⟨⟨⟩⟩ exacts [H.1, H.2] · intro H exact ⟨H _, H _⟩ theorem BinaryCofan.isVanKampen_mk {X Y : C} (c : BinaryCofan X Y) (cofans : ∀ X Y : C, BinaryCofan X Y) (colimits : ∀ X Y, IsColimit (cofans X Y)) (cones : ∀ {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z), PullbackCone f g) (limits : ∀ {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z), IsLimit (cones f g)) (h₁ : ∀ {X' Y' : C} (αX : X' ⟶ X) (αY : Y' ⟶ Y) (f : (cofans X' Y').pt ⟶ c.pt) (_ : αX ≫ c.inl = (cofans X' Y').inl ≫ f) (_ : αY ≫ c.inr = (cofans X' Y').inr ≫ f), IsPullback (cofans X' Y').inl αX f c.inl ∧ IsPullback (cofans X' Y').inr αY f c.inr) (h₂ : ∀ {Z : C} (f : Z ⟶ c.pt), IsColimit (BinaryCofan.mk (cones f c.inl).fst (cones f c.inr).fst)) : IsVanKampenColimit c := by rw [BinaryCofan.isVanKampen_iff] introv hX hY constructor · rintro ⟨h⟩ let e := h.coconePointUniqueUpToIso (colimits _ _) obtain ⟨hl, hr⟩ := h₁ αX αY (e.inv ≫ f) (by simp [e, hX]) (by simp [e, hY]) constructor · rw [← Category.id_comp αX, ← Iso.hom_inv_id_assoc e f] haveI : IsIso (𝟙 X') := inferInstance have : c'.inl ≫ e.hom = 𝟙 X' ≫ (cofans X' Y').inl := by dsimp [e] simp exact (IsPullback.of_vert_isIso ⟨this⟩).paste_vert hl · rw [← Category.id_comp αY, ← Iso.hom_inv_id_assoc e f] haveI : IsIso (𝟙 Y') := inferInstance have : c'.inr ≫ e.hom = 𝟙 Y' ≫ (cofans X' Y').inr := by dsimp [e] simp exact (IsPullback.of_vert_isIso ⟨this⟩).paste_vert hr · rintro ⟨H₁, H₂⟩ refine ⟨IsColimit.ofIsoColimit ?_ <| (isoBinaryCofanMk _).symm⟩ let e₁ : X' ≅ _ := H₁.isLimit.conePointUniqueUpToIso (limits _ _) let e₂ : Y' ≅ _ := H₂.isLimit.conePointUniqueUpToIso (limits _ _) have he₁ : c'.inl = e₁.hom ≫ (cones f c.inl).fst := by simp [e₁] have he₂ : c'.inr = e₂.hom ≫ (cones f c.inr).fst := by simp [e₂] rw [he₁, he₂] exact (BinaryCofan.mk _ _).isColimitCompRightIso e₂.hom ((BinaryCofan.mk _ _).isColimitCompLeftIso e₁.hom (h₂ f)) theorem BinaryCofan.mono_inr_of_isVanKampen [HasInitial C] {X Y : C} {c : BinaryCofan X Y} (h : IsVanKampenColimit c) : Mono c.inr := by refine PullbackCone.mono_of_isLimitMkIdId _ (IsPullback.isLimit ?_) refine (h (BinaryCofan.mk (initial.to Y) (𝟙 Y)) (mapPair (initial.to X) (𝟙 Y)) c.inr ?_ (mapPair_equifibered _)).mp ⟨?_⟩ ⟨WalkingPair.right⟩ · ext ⟨⟨⟩⟩ <;> simp · exact ((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by dsimp infer_instance)).some theorem BinaryCofan.isPullback_initial_to_of_isVanKampen [HasInitial C] {c : BinaryCofan X Y} (h : IsVanKampenColimit c) : IsPullback (initial.to _) (initial.to _) c.inl c.inr := by refine ((h (BinaryCofan.mk (initial.to Y) (𝟙 Y)) (mapPair (initial.to X) (𝟙 Y)) c.inr ?_ (mapPair_equifibered _)).mp ⟨?_⟩ ⟨WalkingPair.left⟩).flip · ext ⟨⟨⟩⟩ <;> simp · exact ((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by dsimp infer_instance)).some end BinaryCoproduct section FiniteCoproducts theorem isUniversalColimit_extendCofan {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n ↦ f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsUniversalColimit c₁) (t₂ : IsUniversalColimit c₂) [∀ {Z} (i : Z ⟶ c₂.pt), HasPullback c₂.inr i] : IsUniversalColimit (extendCofan c₁ c₂) := by intro F c α i e hα H let F' : Fin (n + 1) → C := F.obj ∘ Discrete.mk have : F = Discrete.functor F' := by apply Functor.hext · exact fun i ↦ rfl · rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp [F'] have t₁' := @t₁ (Discrete.functor (fun j ↦ F.obj ⟨j.succ⟩)) (Cofan.mk (pullback c₂.inr i) fun j ↦ pullback.lift (α.app _ ≫ c₁.inj _) (c.ι.app _) ?_) (Discrete.natTrans fun i ↦ α.app _) (pullback.fst _ _) ?_ (NatTrans.equifibered_of_discrete _) ?_ rotate_left · simpa only [Functor.const_obj_obj, pair_obj_right, Discrete.functor_obj, Category.assoc, extendCofan_pt, Functor.const_obj_obj, NatTrans.comp_app, extendCofan_ι_app, Fin.cases_succ, Functor.const_map_app] using congr_app e ⟨j.succ⟩ · ext j dsimp simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Cofan.inj] · intro j simp only [pair_obj_right, Functor.const_obj_obj, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, Discrete.natTrans_app] refine IsPullback.of_right ?_ ?_ (IsPullback.of_hasPullback (BinaryCofan.inr c₂) i).flip · simp only [Functor.const_obj_obj, pair_obj_right, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] exact H _ · simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Cofan.inj] obtain ⟨H₁⟩ := t₁' have t₂' := @t₂ (pair (F.obj ⟨0⟩) (pullback c₂.inr i)) (BinaryCofan.mk (c.ι.app ⟨0⟩) (pullback.snd _ _)) (mapPair (α.app _) (pullback.fst _ _)) i ?_ (mapPair_equifibered _) ?_ rotate_left · ext ⟨⟨⟩⟩ · simpa [mapPair] using congr_app e ⟨0⟩ · simpa using pullback.condition · rintro ⟨⟨⟩⟩ · simp only [pair_obj_right, Functor.const_obj_obj, pair_obj_left, BinaryCofan.mk_pt, BinaryCofan.ι_app_left, BinaryCofan.mk_inl, mapPair_left] exact H ⟨0⟩ · simp only [pair_obj_right, Functor.const_obj_obj, BinaryCofan.mk_pt, BinaryCofan.ι_app_right, BinaryCofan.mk_inr, mapPair_right] exact (IsPullback.of_hasPullback (BinaryCofan.inr c₂) i).flip obtain ⟨H₂⟩ := t₂' clear_value F' subst this refine ⟨IsColimit.ofIsoColimit (extendCofanIsColimit (fun i ↦ (Discrete.functor F').obj ⟨i⟩) H₁ H₂) <| Cocones.ext (Iso.refl _) ?_⟩ dsimp rintro ⟨j⟩ simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Category.comp_id] induction j using Fin.inductionOn · simp only [Fin.cases_zero] · simp only [Fin.cases_succ] theorem isVanKampenColimit_extendCofan {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n ↦ f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsVanKampenColimit c₁) (t₂ : IsVanKampenColimit c₂) [∀ {Z} (i : Z ⟶ c₂.pt), HasPullback c₂.inr i] [HasFiniteCoproducts C] : IsVanKampenColimit (extendCofan c₁ c₂) := by intro F c α i e hα refine ⟨?_, isUniversalColimit_extendCofan f t₁.isUniversal t₂.isUniversal c α i e hα⟩ intro ⟨Hc⟩ ⟨j⟩ have t₂' := (@t₂ (pair (F.obj ⟨0⟩) (∐ fun (j : Fin n) ↦ F.obj ⟨j.succ⟩)) (BinaryCofan.mk (P := c.pt) (c.ι.app _) (Sigma.desc fun b ↦ c.ι.app _)) (mapPair (α.app _) (Sigma.desc fun b ↦ α.app _ ≫ c₁.inj _)) i ?_ (mapPair_equifibered _)).mp ⟨?_⟩ rotate_left · ext ⟨⟨⟩⟩ · simpa only [pair_obj_left, Functor.const_obj_obj, pair_obj_right, Discrete.functor_obj, NatTrans.comp_app, mapPair_left, BinaryCofan.ι_app_left, BinaryCofan.mk_pt, BinaryCofan.mk_inl, Functor.const_map_app, extendCofan_pt, extendCofan_ι_app, Fin.cases_zero] using congr_app e ⟨0⟩ · dsimp ext j simpa only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, Category.assoc, extendCofan_pt, Functor.const_obj_obj, NatTrans.comp_app, extendCofan_ι_app, Fin.cases_succ, Functor.const_map_app] using congr_app e ⟨j.succ⟩ · let F' : Fin (n + 1) → C := F.obj ∘ Discrete.mk have : F = Discrete.functor F' := by apply Functor.hext · exact fun i ↦ rfl · rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp [F'] clear_value F' subst this apply BinaryCofan.IsColimit.mk _ (fun {T} f₁ f₂ ↦ Hc.desc (Cofan.mk T (Fin.cases f₁ (fun i ↦ Sigma.ι (fun (j : Fin n) ↦ (Discrete.functor F').obj ⟨j.succ⟩) _ ≫ f₂)))) · intro T f₁ f₂ simp only [Discrete.functor_obj, pair_obj_left, BinaryCofan.mk_pt, Functor.const_obj_obj, BinaryCofan.mk_inl, IsColimit.fac, Cofan.mk_pt, Cofan.mk_ι_app, Fin.cases_zero] · intro T f₁ f₂ simp only [Discrete.functor_obj, pair_obj_right, BinaryCofan.mk_pt, Functor.const_obj_obj, BinaryCofan.mk_inr] ext j simp only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, IsColimit.fac, Fin.cases_succ] · intro T f₁ f₂ f₃ m₁ m₂ simp at m₁ m₂ ⊢ refine Hc.uniq (Cofan.mk T (Fin.cases f₁ (fun i ↦ Sigma.ι (fun (j : Fin n) ↦ (Discrete.functor F').obj ⟨j.succ⟩) _ ≫ f₂))) _ ?_ intro ⟨j⟩ simp only [Discrete.functor_obj, Cofan.mk_pt, Functor.const_obj_obj, Cofan.mk_ι_app] induction j using Fin.inductionOn · simp only [Fin.cases_zero, m₁] · simp only [← m₂, colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, Fin.cases_succ] induction j using Fin.inductionOn with | zero => exact t₂' ⟨WalkingPair.left⟩ | succ j _ => have t₁' := (@t₁ (Discrete.functor (fun j ↦ F.obj ⟨j.succ⟩)) (Cofan.mk _ _) (Discrete.natTrans fun i ↦ α.app _) (Sigma.desc (fun j ↦ α.app _ ≫ c₁.inj _)) ?_ (NatTrans.equifibered_of_discrete _)).mp ⟨coproductIsCoproduct _⟩ ⟨j⟩ rotate_left · ext ⟨j⟩ dsimp rw [colimit.ι_desc] rfl simpa [Functor.const_obj_obj, Discrete.functor_obj, extendCofan_pt, extendCofan_ι_app, Fin.cases_succ, BinaryCofan.mk_pt, colimit.cocone_x, Cofan.mk_pt, Cofan.mk_ι_app, BinaryCofan.ι_app_right, BinaryCofan.mk_inr, colimit.ι_desc, Discrete.natTrans_app] using t₁'.paste_horiz (t₂' ⟨WalkingPair.right⟩) theorem isPullback_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {X : ι → C} {c : Cofan X} (hc : IsVanKampenColimit c) (i j : ι) [DecidableEq ι] : IsPullback (P := (if j = i then X i else ⊥_ C)) (if h : j = i then eqToHom (if_pos h) else eqToHom (if_neg h) ≫ initial.to (X i)) (if h : j = i then eqToHom ((if_pos h).trans (congr_arg X h.symm)) else eqToHom (if_neg h) ≫ initial.to (X j)) (Cofan.inj c i) (Cofan.inj c j) := by refine (hc (Cofan.mk (X i) (f := fun k ↦ if k = i then X i else ⊥_ C) (fun k ↦ if h : k = i then (eqToHom <| if_pos h) else (eqToHom <| if_neg h) ≫ initial.to _)) (Discrete.natTrans (fun k ↦ if h : k.1 = i then (eqToHom <| (if_pos h).trans (congr_arg X h.symm)) else (eqToHom <| if_neg h) ≫ initial.to _)) (c.inj i) ?_ (NatTrans.equifibered_of_discrete _)).mp ⟨?_⟩ ⟨j⟩ · ext ⟨k⟩ simp only [Discrete.functor_obj, Functor.const_obj_obj, NatTrans.comp_app, Discrete.natTrans_app, Cofan.mk_pt, Cofan.mk_ι_app, Functor.const_map_app] split · subst ‹k = i›; rfl · simp · refine mkCofanColimit _ (fun t ↦ (eqToHom (if_pos rfl).symm) ≫ t.inj i) ?_ ?_ · intro t j simp only [Cofan.mk_pt, cofan_mk_inj] split · subst ‹j = i›; simp · rw [Category.assoc, ← IsIso.eq_inv_comp] exact initialIsInitial.hom_ext _ _ · intro t m hm simp [← hm i] theorem isPullback_initial_to_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) (i j : Discrete ι) (hi : i ≠ j) : IsPullback (initial.to _) (initial.to _) (c.ι.app i) (c.ι.app j) := by classical let f : ι → C := F.obj ∘ Discrete.mk have : F = Discrete.functor f := Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f]) clear_value f subst this have : ∀ i, Subsingleton (⊥_ C ⟶ (Discrete.functor f).obj i) := inferInstance convert isPullback_of_cofan_isVanKampen hc i.as j.as exact (if_neg (mt Discrete.ext hi.symm)).symm theorem mono_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) (i : Discrete ι) : Mono (c.ι.app i) := by classical let f : ι → C := F.obj ∘ Discrete.mk have : F = Discrete.functor f := Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f]) clear_value f subst this refine PullbackCone.mono_of_isLimitMkIdId _ (IsPullback.isLimit ?_) nth_rw 1 [← Category.id_comp (c.ι.app i)] convert IsPullback.paste_vert _ (isPullback_of_cofan_isVanKampen hc i.as i.as) swap · exact (eqToHom (if_pos rfl).symm) · simp · exact IsPullback.of_vert_isIso ⟨by simp⟩ end FiniteCoproducts section CoproductsPullback variable {ι ι' : Type*} {S : C} variable {B : C} {X : ι → C} {a : Cofan X} (hau : IsUniversalColimit a) (f : ∀ i, X i ⟶ S) (u : a.pt ⟶ S) (v : B ⟶ S) include hau in /-- Pullbacks distribute over universal coproducts on the left: This is the isomorphism `∐ (B ×[S] Xᵢ) ≅ B ×[S] (∐ Xᵢ)`. -/ lemma IsUniversalColimit.nonempty_isColimit_of_pullbackCone_left (s : ∀ i, PullbackCone v (f i)) (hs : ∀ i, IsLimit (s i)) (t : PullbackCone v u) (ht : IsLimit t) (d : Cofan (fun i : ι ↦ (s i).pt)) (e : d.pt ≅ t.pt) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) (he₁ : ∀ i, d.inj i ≫ e.hom ≫ t.fst = (s i).fst := by cat_disch) (he₂ : ∀ i, d.inj i ≫ e.hom ≫ t.snd = (s i).snd ≫ a.inj i := by cat_disch) : Nonempty (IsColimit d) := by let iso : d ≅ (Cofan.mk _ fun i : ι ↦ PullbackCone.IsLimit.lift ht (s i).fst ((s i).snd ≫ a.inj i) (by simp [hu, (s i).condition])) := Cofan.ext e <| fun p ↦ PullbackCone.IsLimit.hom_ext ht (by simp [he₁]) (by simp [he₂]) rw [(IsColimit.equivIsoColimit iso).nonempty_congr] refine hau _ (Discrete.natTrans fun i ↦ (s i.as).snd) t.snd ?_ ?_ fun j ↦ ?_ · ext; simp [Cofan.inj] · exact NatTrans.equifibered_of_discrete _ · simp only [Discrete.functor_obj_eq_as, Cofan.mk_pt, Functor.const_obj_obj, Cofan.mk_ι_app, Discrete.natTrans_app] rw [← Cofan.inj] refine IsPullback.of_right ?_ (by simp) (IsPullback.of_isLimit ht) simpa [hu] using (IsPullback.of_isLimit (hs j.1)) section variable {P : ι → C} (q₁ : ∀ i, P i ⟶ B) (q₂ : ∀ i, P i ⟶ X i) (hP : ∀ i, IsPullback (q₁ i) (q₂ i) v (f i)) include hau hP in /-- Pullbacks distribute over universal coproducts on the left: This is the isomorphism `∐ (B ×[S] Xᵢ) ≅ B ×[S] (∐ Xᵢ)`. -/ lemma IsUniversalColimit.nonempty_isColimit_of_isPullback_left {Z : C} {p₁ : Z ⟶ B} {p₂ : Z ⟶ a.pt} (h : IsPullback p₁ p₂ v u) (d : Cofan P) (e : d.pt ≅ Z) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) (he₁ : ∀ i, d.inj i ≫ e.hom ≫ p₁ = q₁ i := by cat_disch) (he₂ : ∀ i, d.inj i ≫ e.hom ≫ p₂ = q₂ i ≫ a.inj i := by cat_disch) : Nonempty (IsColimit d) := hau.nonempty_isColimit_of_pullbackCone_left f u v (fun i ↦ (hP i).cone) (fun i ↦ (hP i).isLimit) h.cone h.isLimit d e include hau hP in /-- Pullbacks distribute over universal coproducts on the left: This is the isomorphism `∐ (B ×[S] Xᵢ) ≅ B ×[S] (∐ Xᵢ)`. -/ lemma IsUniversalColimit.isPullback_of_isColimit_left {d : Cofan P} (hd : IsColimit d) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) [HasPullback v u] : IsPullback (Cofan.IsColimit.desc hd q₁) (Cofan.IsColimit.desc hd (q₂ · ≫ a.inj _)) v u := by let c : Cofan P := Cofan.mk (pullback v u) fun i ↦ pullback.lift (q₁ i) (q₂ i ≫ a.inj i) (by simp [(hP i).w, hu]) obtain ⟨hc⟩ := hau.nonempty_isColimit_of_isPullback_left f u v q₁ q₂ hP (IsPullback.of_hasPullback _ _) c (Iso.refl _) refine (IsPullback.of_hasPullback v u).of_iso ?_ (Iso.refl _) (Iso.refl _) (Iso.refl _) ?_ ?_ (by simp) (by simp) · exact hc.coconePointUniqueUpToIso hd · refine Cofan.IsColimit.hom_ext hc _ _ fun i ↦ ?_ simpa [Cofan.inj, Cofan.IsColimit.desc] using pullback.lift_fst _ _ _ · refine Cofan.IsColimit.hom_ext hc _ _ fun i ↦ ?_ simpa [Cofan.inj, Cofan.IsColimit.desc] using pullback.lift_snd _ _ _ end include hau in /-- Pullbacks distribute over universal coproducts on the right: This is the isomorphism `∐ (Xᵢ ×[S] B) ≅ (∐ Xᵢ) ×[S] B`. -/ lemma IsUniversalColimit.nonempty_isColimit_of_pullbackCone_right (s : ∀ i, PullbackCone (f i) v) (hs : ∀ i, IsLimit (s i)) (t : PullbackCone u v) (ht : IsLimit t) (d : Cofan (fun i : ι ↦ (s i).pt)) (e : d.pt ≅ t.pt) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) (he₁ : ∀ i, d.inj i ≫ e.hom ≫ t.fst = (s i).fst ≫ a.inj i := by cat_disch) (he₂ : ∀ i, d.inj i ≫ e.hom ≫ t.snd = (s i).snd := by cat_disch) : Nonempty (IsColimit d) := by let iso : d ≅ (Cofan.mk _ fun i : ι ↦ PullbackCone.IsLimit.lift ht ((s i).fst ≫ a.inj i) ((s i).snd) (by simp [hu, (s i).condition])) := Cofan.ext e <| fun p ↦ PullbackCone.IsLimit.hom_ext ht (by simp [he₁]) (by simp [he₂]) rw [(IsColimit.equivIsoColimit iso).nonempty_congr] refine hau _ (Discrete.natTrans fun i ↦ (s i.as).fst) t.fst ?_ ?_ fun j ↦ ?_ · ext; simp [Cofan.inj] · exact NatTrans.equifibered_of_discrete _ · simp only [Discrete.functor_obj_eq_as, Cofan.mk_pt, Functor.const_obj_obj, Cofan.mk_ι_app, Discrete.natTrans_app] rw [← Cofan.inj] refine IsPullback.of_right ?_ (by simp) (IsPullback.of_isLimit ht).flip simpa [hu] using (IsPullback.of_isLimit (hs j.1)).flip section variable {P : ι → C} (q₁ : ∀ i, P i ⟶ X i) (q₂ : ∀ i, P i ⟶ B) (hP : ∀ i, IsPullback (q₁ i) (q₂ i) (f i) v) include hau hP in /-- Pullbacks distribute over universal coproducts on the right: This is the isomorphism `∐ (Xᵢ ×[S] B) ≅ (∐ Xᵢ) ×[S] B`. -/ lemma IsUniversalColimit.nonempty_isColimit_of_isPullback_right {Z : C} {p₁ : Z ⟶ a.pt} {p₂ : Z ⟶ B} (h : IsPullback p₁ p₂ u v) (d : Cofan P) (e : d.pt ≅ Z) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) (he₁ : ∀ i, d.inj i ≫ e.hom ≫ p₁ = q₁ i ≫ a.inj i := by cat_disch) (he₂ : ∀ i, d.inj i ≫ e.hom ≫ p₂ = q₂ i := by cat_disch) : Nonempty (IsColimit d) := hau.nonempty_isColimit_of_pullbackCone_right f u v (fun i ↦ (hP i).cone) (fun i ↦ (hP i).isLimit) h.cone h.isLimit d e include hau hP in /-- Pullbacks distribute over universal coproducts on the right: This is the isomorphism `∐ (Xᵢ ×[S] B) ≅ (∐ Xᵢ) ×[S] B`. -/ lemma IsUniversalColimit.isPullback_of_isColimit_right {d : Cofan P} (hd : IsColimit d) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) [HasPullback u v] : IsPullback (Cofan.IsColimit.desc hd (q₁ · ≫ a.inj _)) (Cofan.IsColimit.desc hd q₂) u v := by let c : Cofan P := Cofan.mk (pullback u v) fun i ↦ pullback.lift (q₁ i ≫ a.inj i) (q₂ i) (by simp [(hP i).w, hu]) obtain ⟨hc⟩ := hau.nonempty_isColimit_of_isPullback_right f u v q₁ q₂ hP (IsPullback.of_hasPullback _ _) c (Iso.refl _) refine (IsPullback.of_hasPullback u v).of_iso ?_ (Iso.refl _) (Iso.refl _) (Iso.refl _) ?_ ?_ (by simp) (by simp) · exact hc.coconePointUniqueUpToIso hd · refine Cofan.IsColimit.hom_ext hc _ _ fun i ↦ ?_ simpa [Cofan.inj, Cofan.IsColimit.desc] using pullback.lift_fst _ _ _ · refine Cofan.IsColimit.hom_ext hc _ _ fun i ↦ ?_ simpa [Cofan.inj, Cofan.IsColimit.desc] using pullback.lift_snd _ _ _ end variable {Y : ι' → C} {b : Cofan Y} (hbu : IsUniversalColimit b) (f : ∀ i, X i ⟶ S) (g : ∀ i, Y i ⟶ S) (u : a.pt ⟶ S) (v : b.pt ⟶ S) [∀ i, HasPullback (f i) v] include hau hbu in /-- Pullbacks distribute over universal coproducts in both arguments: This is the isomorphism `∐ (Xᵢ ×[S] Xⱼ) ≅ (∐ Xᵢ) ×[S] (∐ Xⱼ)`. -/ lemma IsUniversalColimit.nonempty_isColimit_prod_of_pullbackCone (s : ∀ (i : ι) (j : ι'), PullbackCone (f i) (g j)) (hs : ∀ i j, IsLimit (s i j)) (t : PullbackCone u v) (ht : IsLimit t) {d : Cofan (fun p : ι × ι' ↦ (s p.1 p.2).pt)} (e : d.pt ≅ t.pt) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) (hv : ∀ i, b.inj i ≫ v = g i := by cat_disch) (he₁ : ∀ i j, d.inj (i, j) ≫ e.hom ≫ t.fst = (s _ _).fst ≫ a.inj _ := by cat_disch) (he₂ : ∀ i j, d.inj (i, j) ≫ e.hom ≫ t.snd = (s _ _).snd ≫ b.inj _ := by cat_disch) : Nonempty (IsColimit d) := by let c (i : ι) : Cofan (fun j : ι' ↦ (s i j).pt) := Cofan.mk (pullback (f i) v) fun j ↦ pullback.lift (s i j).fst ((s i j).snd ≫ b.inj j) (by simp [hv, (s i j).condition]) let c' : Cofan (fun i : ι ↦ (c i).pt) := Cofan.mk t.pt fun i ↦ PullbackCone.IsLimit.lift ht (pullback.fst _ _ ≫ a.inj i) (pullback.snd _ _) (by simp [hu, pullback.condition]) let iso : d ≅ Cofan.mk c'.pt fun p : ι × ι' ↦ (c p.1).inj p.2 ≫ c'.inj _ := by refine Cofan.ext e <| fun p ↦ PullbackCone.IsLimit.hom_ext ht ?_ ?_ · simp [c', c, he₁] · simp [c', c, he₂] rw [(IsColimit.equivIsoColimit iso).nonempty_congr] refine ⟨Cofan.IsColimit.prod c (fun i ↦ Nonempty.some ?_) c' (Nonempty.some ?_)⟩ · exact hbu.nonempty_isColimit_of_pullbackCone_left _ v _ _ (hs i) (pullback.cone _ _) (pullback.isLimit _ _) _ (Iso.refl _) · exact hau.nonempty_isColimit_of_pullbackCone_right _ u _ _ (fun _ ↦ pullback.isLimit _ _) t ht _ (Iso.refl _) include hau hbu in /-- Pullbacks distribute over universal coproducts in both arguments: This is the isomorphism `∐ (Xᵢ ×[S] Xⱼ) ≅ (∐ Xᵢ) ×[S] (∐ Xⱼ)`. -/ lemma IsUniversalColimit.nonempty_isColimit_prod_of_isPullback {P : ι × ι' → C} {q₁ : ∀ i j, P (i, j) ⟶ X i} {q₂ : ∀ i j, P (i, j) ⟶ Y j} (hP : ∀ i j, IsPullback (q₁ i j) (q₂ i j) (f i) (g j)) {Z : C} {p₁ : Z ⟶ a.pt} {p₂ : Z ⟶ b.pt} (h : IsPullback p₁ p₂ u v) {d : Cofan P} (e : d.pt ≅ Z) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) (hv : ∀ i, b.inj i ≫ v = g i := by cat_disch) (he₁ : ∀ i j, d.inj (i, j) ≫ e.hom ≫ p₁ = q₁ _ _ ≫ a.inj _ := by cat_disch) (he₂ : ∀ i j, d.inj (i, j) ≫ e.hom ≫ p₂ = q₂ _ _ ≫ b.inj _ := by cat_disch) : Nonempty (IsColimit d) := IsUniversalColimit.nonempty_isColimit_prod_of_pullbackCone hau hbu f g u v (fun i j ↦ (hP i j).cone) (fun i j ↦ (hP i j).isLimit) h.cone h.isLimit e include hau hbu in lemma IsUniversalColimit.isPullback_prod_of_isColimit [HasPullback u v] {P : ι × ι' → C} {q₁ : ∀ i j, P (i, j) ⟶ X i} {q₂ : ∀ i j, P (i, j) ⟶ Y j} (hP : ∀ i j, IsPullback (q₁ i j) (q₂ i j) (f i) (g j)) (d : Cofan P) (hd : IsColimit d) (hu : ∀ i, a.inj i ≫ u = f i := by cat_disch) (hv : ∀ i, b.inj i ≫ v = g i := by cat_disch) : IsPullback (Cofan.IsColimit.desc hd (fun p ↦ q₁ p.1 p.2 ≫ a.inj _)) (Cofan.IsColimit.desc hd (fun p ↦ q₂ p.1 p.2 ≫ b.inj _)) u v := by let c : Cofan P := Cofan.mk (pullback u v) fun p ↦ pullback.lift (q₁ p.1 p.2 ≫ a.inj p.1) (q₂ p.1 p.2 ≫ b.inj _) (by simp [(hP p.1 p.2).w, hu, hv]) obtain ⟨hc⟩ := hau.nonempty_isColimit_prod_of_isPullback hbu f g u v hP (IsPullback.of_hasPullback _ _) (d := c) (Iso.refl _) refine (IsPullback.of_hasPullback u v).of_iso ?_ (Iso.refl _) (Iso.refl _) (Iso.refl _) ?_ ?_ (by simp) (by simp) · exact hc.coconePointUniqueUpToIso hd · refine Cofan.IsColimit.hom_ext hc _ _ fun i ↦ ?_ simpa [Cofan.inj, Cofan.IsColimit.desc] using pullback.lift_fst _ _ _ · refine Cofan.IsColimit.hom_ext hc _ _ fun i ↦ ?_ simpa [Cofan.inj, Cofan.IsColimit.desc] using pullback.lift_snd _ _ _ end CoproductsPullback end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Bicones.lean
import Mathlib.CategoryTheory.Limits.Cones import Mathlib.CategoryTheory.FinCategory.Basic import Mathlib.Data.Finset.Lattice.Lemmas /-! # Bicones Given a category `J`, a walking `Bicone J` is a category whose objects are the objects of `J` and two extra vertices `Bicone.left` and `Bicone.right`. The morphisms are the morphisms of `J` and `left ⟶ j`, `right ⟶ j` for each `j : J` such that `(· ⟶ j)` and `(· ⟶ k)` commutes with each `f : j ⟶ k`. Given a diagram `F : J ⥤ C` and two `Cone F`s, we can join them into a diagram `Bicone J ⥤ C` via `biconeMk`. This is used in `CategoryTheory.Functor.Flat`. -/ universe v₁ u₁ noncomputable section open CategoryTheory.Limits namespace CategoryTheory section Bicone /-- Given a category `J`, construct a walking `Bicone J` by adjoining two elements. -/ inductive Bicone (J : Type u₁) | left : Bicone J | right : Bicone J | diagram (val : J) : Bicone J deriving DecidableEq variable (J : Type u₁) instance : Inhabited (Bicone J) := ⟨Bicone.left⟩ open scoped Classical in instance finBicone [Fintype J] : Fintype (Bicone J) where elems := [Bicone.left, Bicone.right].toFinset ∪ Finset.image Bicone.diagram Fintype.elems complete j := by cases j <;> simp [Fintype.complete] variable [Category.{v₁} J] /-- The homs for a walking `Bicone J`. -/ inductive BiconeHom : Bicone J → Bicone J → Type max u₁ v₁ | left_id : BiconeHom Bicone.left Bicone.left | right_id : BiconeHom Bicone.right Bicone.right | left (j : J) : BiconeHom Bicone.left (Bicone.diagram j) | right (j : J) : BiconeHom Bicone.right (Bicone.diagram j) | diagram {j k : J} (f : j ⟶ k) : BiconeHom (Bicone.diagram j) (Bicone.diagram k) instance : Inhabited (BiconeHom J Bicone.left Bicone.left) := ⟨BiconeHom.left_id⟩ instance BiconeHom.decidableEq {j k : Bicone J} : DecidableEq (BiconeHom J j k) := fun f g => by classical cases f <;> cases g <;> simp only [diagram.injEq] <;> infer_instance @[simps] instance biconeCategoryStruct : CategoryStruct (Bicone J) where Hom := BiconeHom J id j := Bicone.casesOn j BiconeHom.left_id BiconeHom.right_id fun k => BiconeHom.diagram (𝟙 k) comp f g := by rcases f with (_ | _ | _ | _ | f) · exact g · exact g · cases g apply BiconeHom.left · cases g apply BiconeHom.right · rcases g with (_ | _ | _ | _ | g) exact BiconeHom.diagram (f ≫ g) instance biconeCategory : Category (Bicone J) where id_comp f := by cases f <;> simp comp_id f := by cases f <;> simp assoc f g h := by cases f <;> cases g <;> cases h <;> simp end Bicone section SmallCategory variable (J : Type v₁) [SmallCategory J] /-- Given a diagram `F : J ⥤ C` and two `Cone F`s, we can join them into a diagram `Bicone J ⥤ C`. -/ @[simps] def biconeMk {C : Type u₁} [Category.{v₁} C] {F : J ⥤ C} (c₁ c₂ : Cone F) : Bicone J ⥤ C where obj X := Bicone.casesOn X c₁.pt c₂.pt fun j => F.obj j map f := by rcases f with (_ | _ | _ | _ | f) · exact 𝟙 _ · exact 𝟙 _ · exact c₁.π.app _ · exact c₂.π.app _ · exact F.map f map_id X := by cases X <;> simp map_comp f g := by rcases f with (_ | _ | _ | _ | _) · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm · cases g exact (Category.id_comp _).symm.trans (c₁.π.naturality _) · cases g exact (Category.id_comp _).symm.trans (c₂.π.naturality _) · cases g apply F.map_comp open scoped Classical in instance finBiconeHom [FinCategory J] (j k : Bicone J) : Fintype (j ⟶ k) := by cases j <;> cases k · exact { elems := {BiconeHom.left_id} complete := fun f => by cases f; simp } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := {BiconeHom.left _} complete := fun f => by cases f; simp } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := {BiconeHom.right_id} complete := fun f => by cases f; simp } · exact { elems := {BiconeHom.right _} complete := fun f => by cases f; simp } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := Finset.image BiconeHom.diagram Fintype.elems complete := fun f => by rcases f with (_ | _ | _ | _ | f) simp only [Finset.mem_image] use f simpa using Fintype.complete _ } instance biconeSmallCategory : SmallCategory (Bicone J) := CategoryTheory.biconeCategory J instance biconeFinCategory [FinCategory J] : FinCategory (Bicone J) where end SmallCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Lattice.lean
import Mathlib.CategoryTheory.Category.Preorder import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.Data.Finset.Lattice.Fold /-! # Limits in lattice categories are given by infimums and supremums. -/ universe w w' u namespace CategoryTheory.Limits.CompleteLattice section Semilattice variable {α : Type u} {J : Type w} [SmallCategory J] [FinCategory J] /-- The limit cone over any functor from a finite diagram into a `SemilatticeInf` with `OrderTop`. -/ @[simps] def finiteLimitCone [SemilatticeInf α] [OrderTop α] (F : J ⥤ α) : LimitCone F where cone := { pt := Finset.univ.inf F.obj π := { app := fun _ => homOfLE (Finset.inf_le (Fintype.complete _)) } } isLimit := { lift := fun s => homOfLE (Finset.le_inf fun j _ => (s.π.app j).down.down) } /-- The colimit cocone over any functor from a finite diagram into a `SemilatticeSup` with `OrderBot`. -/ @[simps] def finiteColimitCocone [SemilatticeSup α] [OrderBot α] (F : J ⥤ α) : ColimitCocone F where cocone := { pt := Finset.univ.sup F.obj ι := { app := fun _ => homOfLE (Finset.le_sup (Fintype.complete _)) } } isColimit := { desc := fun s => homOfLE (Finset.sup_le fun j _ => (s.ι.app j).down.down) } -- see Note [lower instance priority] instance (priority := 100) hasFiniteLimits_of_semilatticeInf_orderTop [SemilatticeInf α] [OrderTop α] : HasFiniteLimits α := ⟨by intro J 𝒥₁ 𝒥₂ exact { has_limit := fun F => HasLimit.mk (finiteLimitCone F) }⟩ -- see Note [lower instance priority] instance (priority := 100) hasFiniteColimits_of_semilatticeSup_orderBot [SemilatticeSup α] [OrderBot α] : HasFiniteColimits α := ⟨by intro J 𝒥₁ 𝒥₂ exact { has_colimit := fun F => HasColimit.mk (finiteColimitCocone F) }⟩ /-- The limit of a functor from a finite diagram into a `SemilatticeInf` with `OrderTop` is the infimum of the objects in the image. -/ theorem finite_limit_eq_finset_univ_inf [SemilatticeInf α] [OrderTop α] (F : J ⥤ α) : limit F = Finset.univ.inf F.obj := (IsLimit.conePointUniqueUpToIso (limit.isLimit F) (finiteLimitCone F).isLimit).to_eq /-- The colimit of a functor from a finite diagram into a `SemilatticeSup` with `OrderBot` is the supremum of the objects in the image. -/ theorem finite_colimit_eq_finset_univ_sup [SemilatticeSup α] [OrderBot α] (F : J ⥤ α) : colimit F = Finset.univ.sup F.obj := (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (finiteColimitCocone F).isColimit).to_eq /-- A finite product in the category of a `SemilatticeInf` with `OrderTop` is the same as the infimum. -/ theorem finite_product_eq_finset_inf [SemilatticeInf α] [OrderTop α] {ι : Type u} [Fintype ι] (f : ι → α) : ∏ᶜ f = Fintype.elems.inf f := by trans · exact (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (finiteLimitCone (Discrete.functor f)).isLimit).to_eq change Finset.univ.inf (f ∘ discreteEquiv.toEmbedding) = Fintype.elems.inf f simp only [← Finset.inf_map, Finset.univ_map_equiv_to_embedding] rfl /-- A finite coproduct in the category of a `SemilatticeSup` with `OrderBot` is the same as the supremum. -/ theorem finite_coproduct_eq_finset_sup [SemilatticeSup α] [OrderBot α] {ι : Type u} [Fintype ι] (f : ι → α) : ∐ f = Fintype.elems.sup f := by trans · exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (finiteColimitCocone (Discrete.functor f)).isColimit).to_eq change Finset.univ.sup (f ∘ discreteEquiv.toEmbedding) = Fintype.elems.sup f simp only [← Finset.sup_map, Finset.univ_map_equiv_to_embedding] rfl -- see Note [lower instance priority] instance (priority := 100) [SemilatticeInf α] [OrderTop α] : HasBinaryProducts α := by have : ∀ x y : α, HasLimit (pair x y) := by letI := hasFiniteLimits_of_hasFiniteLimits_of_size.{u} α infer_instance apply hasBinaryProducts_of_hasLimit_pair /-- The binary product in the category of a `SemilatticeInf` with `OrderTop` is the same as the infimum. -/ @[simp] theorem prod_eq_inf [SemilatticeInf α] [OrderTop α] (x y : α) : Limits.prod x y = x ⊓ y := calc Limits.prod x y = limit (pair x y) := rfl _ = Finset.univ.inf (pair x y).obj := by rw [finite_limit_eq_finset_univ_inf (pair.{u} x y)] _ = x ⊓ (y ⊓ ⊤) := rfl -- Note: finset.inf is realized as a fold, hence the definitional equality _ = x ⊓ y := by rw [inf_top_eq] -- see Note [lower instance priority] instance (priority := 100) [SemilatticeSup α] [OrderBot α] : HasBinaryCoproducts α := by have : ∀ x y : α, HasColimit (pair x y) := by letI := hasFiniteColimits_of_hasFiniteColimits_of_size.{u} α infer_instance apply hasBinaryCoproducts_of_hasColimit_pair /-- The binary coproduct in the category of a `SemilatticeSup` with `OrderBot` is the same as the supremum. -/ @[simp] theorem coprod_eq_sup [SemilatticeSup α] [OrderBot α] (x y : α) : Limits.coprod x y = x ⊔ y := calc Limits.coprod x y = colimit (pair x y) := rfl _ = Finset.univ.sup (pair x y).obj := by rw [finite_colimit_eq_finset_univ_sup (pair x y)] _ = x ⊔ (y ⊔ ⊥) := rfl -- Note: Finset.sup is realized as a fold, hence the definitional equality _ = x ⊔ y := by rw [sup_bot_eq] /-- The pullback in the category of a `SemilatticeInf` with `OrderTop` is the same as the infimum over the objects. -/ @[simp] theorem pullback_eq_inf [SemilatticeInf α] [OrderTop α] {x y z : α} (f : x ⟶ z) (g : y ⟶ z) : pullback f g = x ⊓ y := calc pullback f g = limit (cospan f g) := rfl _ = Finset.univ.inf (cospan f g).obj := by rw [finite_limit_eq_finset_univ_inf] _ = z ⊓ (x ⊓ (y ⊓ ⊤)) := rfl _ = z ⊓ (x ⊓ y) := by rw [inf_top_eq] _ = x ⊓ y := inf_eq_right.mpr (inf_le_of_left_le f.le) /-- The pushout in the category of a `SemilatticeSup` with `OrderBot` is the same as the supremum over the objects. -/ @[simp] theorem pushout_eq_sup [SemilatticeSup α] [OrderBot α] (x y z : α) (f : z ⟶ x) (g : z ⟶ y) : pushout f g = x ⊔ y := calc pushout f g = colimit (span f g) := rfl _ = Finset.univ.sup (span f g).obj := by rw [finite_colimit_eq_finset_univ_sup] _ = z ⊔ (x ⊔ (y ⊔ ⊥)) := rfl _ = z ⊔ (x ⊔ y) := by rw [sup_bot_eq] _ = x ⊔ y := sup_eq_right.mpr (le_sup_of_le_left f.le) end Semilattice variable {α : Type u} [CompleteLattice α] {J : Type w} [Category.{w'} J] /-- The limit cone over any functor into a complete lattice. -/ @[simps] def limitCone (F : J ⥤ α) : LimitCone F where cone := { pt := iInf F.obj π := { app := fun _ => homOfLE (CompleteLattice.sInf_le _ _ (Set.mem_range_self _)) } } isLimit := { lift := fun s => homOfLE (CompleteLattice.le_sInf _ _ (by rintro _ ⟨j, rfl⟩; exact (s.π.app j).le)) } /-- The colimit cocone over any functor into a complete lattice. -/ @[simps] def colimitCocone (F : J ⥤ α) : ColimitCocone F where cocone := { pt := iSup F.obj ι := { app := fun _ => homOfLE (CompleteLattice.le_sSup _ _ (Set.mem_range_self _)) } } isColimit := { desc := fun s => homOfLE (CompleteLattice.sSup_le _ _ (by rintro _ ⟨j, rfl⟩; exact (s.ι.app j).le)) } -- see Note [lower instance priority] instance (priority := 100) hasLimits_of_completeLattice : HasLimitsOfSize.{w, w'} α where has_limits_of_shape _ := { has_limit := fun F => HasLimit.mk (limitCone F) } -- see Note [lower instance priority] instance (priority := 100) hasColimits_of_completeLattice : HasColimitsOfSize.{w, w'} α where has_colimits_of_shape _ := { has_colimit := fun F => HasColimit.mk (colimitCocone F) } /-- The limit of a functor into a complete lattice is the infimum of the objects in the image. -/ theorem limit_eq_iInf (F : J ⥤ α) : limit F = iInf F.obj := (IsLimit.conePointUniqueUpToIso (limit.isLimit F) (limitCone F).isLimit).to_eq /-- The colimit of a functor into a complete lattice is the supremum of the objects in the image. -/ theorem colimit_eq_iSup (F : J ⥤ α) : colimit F = iSup F.obj := (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (colimitCocone F).isColimit).to_eq end CategoryTheory.Limits.CompleteLattice
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/IsConnected.lean
import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.HomCongr /-! # Colimits of connected index categories This file proves two characterizations of connected categories by means of colimits. ## Characterization of connected categories by means of the unit-valued functor First, it is proved that a category `C` is connected if and only if `colim F` is a singleton, where `F : C ⥤ Type w` and `F.obj _ = PUnit` (for arbitrary `w`). See `isConnected_iff_colimit_constPUnitFunctor_iso_pUnit` for the proof of this characterization and `constPUnitFunctor` for the definition of the constant functor used in the statement. A formulation based on `IsColimit` instead of `colimit` is given in `isConnected_iff_isColimit_pUnitCocone`. The `if` direction is also available directly in several formulations: For connected index categories `C`, `PUnit.{w}` is a colimit of the `constPUnitFunctor`, where `w` is arbitrary. See `instHasColimitConstPUnitFunctor`, `isColimitPUnitCocone` and `colimitConstPUnitIsoPUnit`. ## Final functors preserve connectedness of categories (in both directions) `isConnected_iff_of_final` proves that the domain of a final functor is connected if and only if its codomain is connected. ## Tags unit-valued, singleton, colimit -/ universe w v u namespace CategoryTheory namespace Limits.Types variable (C : Type u) [Category.{v} C] /-- The functor mapping every object to `PUnit`. -/ def constPUnitFunctor : C ⥤ Type w := (Functor.const C).obj PUnit.{w + 1} /-- The cocone on `constPUnitFunctor` with cone point `PUnit`. -/ @[simps] def pUnitCocone : Cocone (constPUnitFunctor.{w} C) where pt := PUnit ι := { app := fun _ => id } /-- If `C` is connected, the cocone on `constPUnitFunctor` with cone point `PUnit` is a colimit cocone. -/ noncomputable def isColimitPUnitCocone [IsConnected C] : IsColimit (pUnitCocone.{w} C) where desc s := s.ι.app Classical.ofNonempty fac s j := by ext ⟨⟩ apply constant_of_preserves_morphisms (s.ι.app · PUnit.unit) intro X Y f exact congrFun (s.ι.naturality f).symm PUnit.unit uniq s m h := by ext ⟨⟩ simp [← h Classical.ofNonempty] instance instHasColimitConstPUnitFunctor [IsConnected C] : HasColimit (constPUnitFunctor.{w} C) := ⟨_, isColimitPUnitCocone _⟩ instance instSubsingletonColimitPUnit [IsPreconnected C] [HasColimit (constPUnitFunctor.{w} C)] : Subsingleton (colimit (constPUnitFunctor.{w} C)) where allEq a b := by obtain ⟨c, ⟨⟩, rfl⟩ := jointly_surjective' a obtain ⟨d, ⟨⟩, rfl⟩ := jointly_surjective' b apply constant_of_preserves_morphisms (colimit.ι (constPUnitFunctor C) · PUnit.unit) exact fun c d f => colimit_sound f rfl /-- Given a connected index category, the colimit of the constant unit-valued functor is `PUnit`. -/ noncomputable def colimitConstPUnitIsoPUnit [IsConnected C] : colimit (constPUnitFunctor.{w} C) ≅ PUnit.{w + 1} := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitPUnitCocone.{w} C) /-- Let `F` be a `Type`-valued functor. If two elements `a : F c` and `b : F d` represent the same element of `colimit F`, then `c` and `d` are related by a `Zigzag`. -/ theorem zigzag_of_eqvGen_colimitTypeRel (F : C ⥤ Type w) (c d : Σ j, F.obj j) (h : Relation.EqvGen F.ColimitTypeRel c d) : Zigzag c.1 d.1 := by induction h with | rel _ _ h => exact Zigzag.of_hom <| Exists.choose h | refl _ => exact Zigzag.refl _ | symm _ _ _ ih => exact zigzag_symmetric ih | trans _ _ _ _ _ ih₁ ih₂ => exact ih₁.trans ih₂ @[deprecated (since := "2025-06-22")] alias zigzag_of_eqvGen_quot_rel := zigzag_of_eqvGen_colimitTypeRel /-- An index category is connected iff the colimit of the constant singleton-valued functor is a singleton. -/ theorem isConnected_iff_colimit_constPUnitFunctor_iso_pUnit [HasColimit (constPUnitFunctor.{w} C)] : IsConnected C ↔ Nonempty (colimit (constPUnitFunctor.{w} C) ≅ PUnit) := by refine ⟨fun _ => ⟨colimitConstPUnitIsoPUnit.{w} C⟩, fun ⟨h⟩ => ?_⟩ have : Nonempty C := nonempty_of_nonempty_colimit <| Nonempty.map h.inv inferInstance refine zigzag_isConnected <| fun c d => ?_ refine zigzag_of_eqvGen_colimitTypeRel _ (constPUnitFunctor C) ⟨c, PUnit.unit⟩ ⟨d, PUnit.unit⟩ ?_ exact colimit_eq <| h.toEquiv.injective rfl theorem isConnected_iff_isColimit_pUnitCocone : IsConnected C ↔ Nonempty (IsColimit (pUnitCocone.{w} C)) := by refine ⟨fun inst => ⟨isColimitPUnitCocone C⟩, fun ⟨h⟩ => ?_⟩ let colimitCocone : ColimitCocone (constPUnitFunctor C) := ⟨pUnitCocone.{w} C, h⟩ have : HasColimit (constPUnitFunctor.{w} C) := ⟨⟨colimitCocone⟩⟩ simp only [isConnected_iff_colimit_constPUnitFunctor_iso_pUnit.{w} C] exact ⟨colimit.isoColimitCocone colimitCocone⟩ end Limits.Types namespace Functor open Limits.Types universe v₂ u₂ variable {C : Type u} [Category.{v} C] {D : Type u₂} [Category.{v₂} D] /-- The domain of a final functor is connected if and only if its codomain is connected. -/ theorem isConnected_iff_of_final (F : C ⥤ D) [F.Final] : IsConnected C ↔ IsConnected D := by rw [isConnected_iff_colimit_constPUnitFunctor_iso_pUnit.{max v u v₂ u₂} C, isConnected_iff_colimit_constPUnitFunctor_iso_pUnit.{max v u v₂ u₂} D] exact Equiv.nonempty_congr <| Iso.isoCongrLeft <| CategoryTheory.Functor.Final.colimitIso F <| constPUnitFunctor.{max u v u₂ v₂} D /-- The domain of an initial functor is connected if and only if its codomain is connected. -/ theorem isConnected_iff_of_initial (F : C ⥤ D) [F.Initial] : IsConnected C ↔ IsConnected D := by rw [← isConnected_op_iff_isConnected C, ← isConnected_op_iff_isConnected D] exact isConnected_iff_of_final F.op end Functor section variable (C : Type*) [Category C] /-- Prove that a category is connected by supplying an explicit initial object. -/ lemma isConnected_of_isInitial {x : C} (h : Limits.IsInitial x) : IsConnected C := by letI : Nonempty C := ⟨x⟩ apply isConnected_of_zigzag intro j₁ j₂ use [x, j₂] simp only [List.isChain_cons_cons, List.isChain_singleton, and_true, ne_eq, reduceCtorEq, not_false_eq_true, List.getLast_cons, List.cons_ne_self, List.getLast_singleton] exact ⟨Zag.symm <| Zag.of_hom <| h.to _, Zag.of_hom <| h.to _⟩ /-- Prove that a category is connected by supplying an explicit terminal object. -/ lemma isConnected_of_isTerminal {x : C} (h : Limits.IsTerminal x) : IsConnected C := by letI : Nonempty C := ⟨x⟩ apply isConnected_of_zigzag intro j₁ j₂ use [x, j₂] simp only [List.isChain_cons_cons, List.isChain_singleton, and_true, ne_eq, reduceCtorEq, not_false_eq_true, List.getLast_cons, List.cons_ne_self, List.getLast_singleton] exact ⟨Zag.of_hom <| h.from _, Zag.symm <| Zag.of_hom <| h.from _⟩ -- note : it seems making the following two as instances breaks things, so these are lemmas. lemma isConnected_of_hasInitial [Limits.HasInitial C] : IsConnected C := isConnected_of_isInitial C Limits.initialIsInitial lemma isConnected_of_hasTerminal [Limits.HasTerminal C] : IsConnected C := isConnected_of_isTerminal C Limits.terminalIsTerminal end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preorder.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.Order.Bounds.Defs /-! # (Co)limits in a preorder category We provide basic results about (co)limits in the associated category of a preordered type. - We show that a functor `F` has a (co)limit iff it has a greatest lower bound (least upper bound). - We show maximal (minimal) elements correspond to terminal (initial) objects. - We show that (co)products correspond to infima (suprema). -/ universe v u u' open CategoryTheory Limits namespace Preorder variable {C : Type u} section variable [Preorder C] variable {J : Type u'} [Category.{v} J] variable (F : J ⥤ C) /-- The cone associated to a lower bound of a functor. -/ def coneOfLowerBound {x : C} (h : x ∈ lowerBounds (Set.range F.obj)) : Cone F where pt := x π := { app i := homOfLE (h (Set.mem_range_self _)) } /-- The point of a cone is a lower bound. -/ lemma conePt_mem_lowerBounds (c : Cone F) : c.pt ∈ lowerBounds (Set.range F.obj) := by intro x ⟨i, p⟩; rw [← p]; exact (c.π.app i).le /-- If a cone is a limit, its point is a glb. -/ lemma isGLB_of_isLimit {c : Cone F} (h : IsLimit c) : IsGLB (Set.range F.obj) c.pt := ⟨(conePt_mem_lowerBounds F c), fun _ k ↦ (h.lift (coneOfLowerBound F k)).le⟩ /-- If the point of cone is a glb, the cone is a limi.t -/ def isLimitOfIsGLB (c : Cone F) (h : IsGLB (Set.range F.obj) c.pt) : IsLimit c where lift d := (h.2 (conePt_mem_lowerBounds F d)).hom /-- A functor has a limit iff there exists a glb. -/ lemma hasLimit_iff_hasGLB : HasLimit F ↔ ∃ x, IsGLB (Set.range F.obj) x := by constructor <;> intro h · let limitCone := getLimitCone F exact ⟨limitCone.cone.pt, isGLB_of_isLimit F limitCone.isLimit⟩ · obtain ⟨l, isGLB⟩ := h exact ⟨⟨⟨coneOfLowerBound F isGLB.1, isLimitOfIsGLB F _ isGLB⟩⟩⟩ /-- The cocone associated to an upper bound of a functor -/ def coconePt_mem_upperBounds {x : C} (h : x ∈ upperBounds (Set.range F.obj)) : Cocone F where pt := x ι := { app i := homOfLE (h (Set.mem_range_self _)) } /-- The point of a cocone is an upper bound. -/ lemma upperBoundOfCocone (c : Cocone F) : c.pt ∈ upperBounds (Set.range F.obj) := by intro x ⟨i, p⟩; rw [← p]; exact (c.ι.app i).le /-- If a cocone is a colimit, its point is a lub. -/ lemma isLUB_of_isColimit {c : Cocone F} (h : IsColimit c) : IsLUB (Set.range F.obj) c.pt := ⟨(upperBoundOfCocone F c), fun _ k ↦ (h.desc (coconePt_mem_upperBounds F k)).le⟩ /-- If the point of cocone is a lub, the cocone is a .colimit -/ def isColimitOfIsLUB (c : Cocone F) (h : IsLUB (Set.range F.obj) c.pt) : IsColimit c where desc d := (h.2 (upperBoundOfCocone F d)).hom /-- A functor has a colimit iff there exists a lub. -/ lemma hasColimit_iff_hasLUB : HasColimit F ↔ ∃ x, IsLUB (Set.range F.obj) x := by constructor <;> intro h · let limitCocone := getColimitCocone F exact ⟨limitCocone.cocone.pt, isLUB_of_isColimit F limitCocone.isColimit⟩ · obtain ⟨l, isLUB⟩ := h exact ⟨⟨⟨coconePt_mem_upperBounds F isLUB.1, isColimitOfIsLUB F _ isLUB⟩⟩⟩ end section variable [Preorder C] /-- A terminal object in a preorder `C` is top element for `C`. -/ def _root_.CategoryTheory.Limits.IsTerminal.orderTop {X : C} (t : IsTerminal X) : OrderTop C where top := X le_top Y := leOfHom (t.from Y) /-- A preorder with a terminal object has a greatest element. -/ noncomputable def orderTopOfHasTerminal [HasTerminal C] : OrderTop C := IsTerminal.orderTop terminalIsTerminal variable (C) in /-- If `C` is a preorder with top, then `⊤` is a terminal object. -/ def isTerminalTop [OrderTop C] : IsTerminal (⊤ : C) := IsTerminal.ofUnique _ instance (priority := low) [OrderTop C] : HasTerminal C := hasTerminal_of_unique ⊤ /-- An initial object in a preorder `C` is bottom element for `C`. -/ def _root_.CategoryTheory.Limits.IsInitial.orderBot {X : C} (t : IsInitial X) : OrderBot C where bot := X bot_le Y := leOfHom (t.to Y) /-- A preorder with an initial object has a least element. -/ noncomputable def orderBotOfHasInitial [HasInitial C] : OrderBot C := IsInitial.orderBot initialIsInitial variable (C) in /-- If `C` is a preorder with bot, then `⊥` is an initial object. -/ def isInitialBot [OrderBot C] : IsInitial (⊥ : C) := IsInitial.ofUnique _ instance (priority := low) [OrderBot C] : HasInitial C := hasInitial_of_unique ⊥ end section variable [PartialOrder C] /-- A family of limiting binary fans on a partial order induces an inf-semilattice structure on it. -/ def semilatticeInfOfIsLimitBinaryFan (c : ∀ (X Y : C), BinaryFan X Y) (h : (X Y : C) → IsLimit (c X Y)) : SemilatticeInf C where inf X Y := (c X Y).pt inf_le_left X Y := leOfHom (c X Y).fst inf_le_right X Y := leOfHom (c X Y).snd le_inf _ _ _ le_fst le_snd := leOfHom <| (h _ _).lift (BinaryFan.mk le_fst.hom le_snd.hom) variable (C) in /-- If a partial order has binary products, then it is a inf-semilattice -/ noncomputable def semilatticeInfOfHasBinaryProducts [HasBinaryProducts C] : SemilatticeInf C := semilatticeInfOfIsLimitBinaryFan (fun _ _ ↦ BinaryFan.mk prod.fst prod.snd) (fun X Y ↦ prodIsProd X Y) /-- A family of colimiting binary cofans on a partial order induces a sup-semilattice structure on it. -/ def semilatticeSupOfIsColimitBinaryCofan (c : ∀ (X Y : C), BinaryCofan X Y) (h : (X Y : C) → IsColimit (c X Y)) : SemilatticeSup C where sup X Y := (c X Y).pt le_sup_left X Y := leOfHom (c X Y).inl le_sup_right X Y := leOfHom (c X Y).inr sup_le _ _ _ le_inl le_inr := leOfHom <| (h _ _).desc (BinaryCofan.mk le_inl.hom le_inr.hom) variable (C) in /-- If a partial order has binary coproducts, then it is a sup-semilattice -/ noncomputable def semilatticeSupOfHasBinaryCoproducts [HasBinaryCoproducts C] : SemilatticeSup C := semilatticeSupOfIsColimitBinaryCofan (fun _ _ ↦ BinaryCofan.mk coprod.inl coprod.inr) (fun X Y ↦ coprodIsCoprod X Y) end section /-- The infimum of two elements in a preordered type is a binary product in the category associated to this preorder. -/ def isLimitBinaryFan [SemilatticeInf C] (X Y : C) : IsLimit (BinaryFan.mk (P := X ⊓ Y) (homOfLE inf_le_left) (homOfLE inf_le_right)) := BinaryFan.isLimitMk (fun s ↦ homOfLE (le_inf (leOfHom s.fst) (leOfHom s.snd))) (by intros; rfl) (by intros; rfl) (by intros; rfl) instance (priority := low) [SemilatticeInf C] : HasBinaryProducts C where has_limit F := by have : HasLimit (pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩)) := ⟨⟨⟨_, isLimitBinaryFan (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩)⟩⟩⟩ apply hasLimit_of_iso (diagramIsoPair F).symm /-- The supremum of two elements in a preordered type is a binary coproduct in the category associated to this preorder. -/ def isColimitBinaryCofan [SemilatticeSup C] (X Y : C) : IsColimit (BinaryCofan.mk (P := X ⊔ Y) (homOfLE le_sup_left) (homOfLE le_sup_right)) := BinaryCofan.isColimitMk (fun s ↦ homOfLE (sup_le (leOfHom s.inl) (leOfHom s.inr))) (by intros; rfl) (by intros; rfl) (by intros; rfl) instance (priority := low) [SemilatticeSup C] : HasBinaryCoproducts C where has_colimit F := by have : HasColimit (pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩)) := ⟨⟨⟨_, isColimitBinaryCofan (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩)⟩⟩⟩ apply hasColimit_of_iso (diagramIsoPair F) end end Preorder
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FilteredColimitCommutesProduct.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Filtered import Mathlib.CategoryTheory.Limits.FunctorCategory.Shapes.Products import Mathlib.CategoryTheory.Limits.Types.Filtered import Mathlib.CategoryTheory.Limits.Types.Products /-! # The IPC property Given a family of categories `I i` (`i : α`) and a family of functors `F i : I i ⥤ C`, we construct the natural morphism `colim_k (∏ᶜ s ↦ (F s).obj (k s)) ⟶ ∏ᶜ s ↦ colim_k (F s).obj (k s)`. Similarly to the study of finite limits commuting with filtered colimits, we then study sufficient conditions for this morphism to be an isomorphism. We say that `C` satisfies the `w`-IPC property if the morphism is an isomorphism as long as `α` is `w`-small and `I i` is `w`-small and filtered for all `i`. We show that * the category `Type u` satisfies the `u`-IPC property and * if `C` satisfies the `w`-IPC property, then `D ⥤ C` satisfies the `w`-IPC property. These results will be used to show that if a category `C` has products indexed by `α`, then so does the category of Ind-objects of `C`. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], 3.1.10, 3.1.11, 3.1.12. -/ universe w v v₁ v₂ u u₁ u₂ namespace CategoryTheory.Limits section variable {C : Type u} [Category.{v} C] {α : Type w} {I : α → Type u₁} [∀ i, Category.{v₁} (I i)] [HasLimitsOfShape (Discrete α) C] (F : ∀ i, I i ⥤ C) /-- Given a family of functors `I i ⥤ C` for `i : α`, we obtain a functor `(∀ i, I i) ⥤ C` which maps `k : ∀ i, I i` to `∏ᶜ fun (s : α) => (F s).obj (k s)`. -/ @[simps] noncomputable def pointwiseProduct : (∀ i, I i) ⥤ C where obj k := ∏ᶜ fun (s : α) => (F s).obj (k s) map f := Pi.map (fun s => (F s).map (f s)) variable [∀ i, HasColimitsOfShape (I i) C] [HasColimitsOfShape (∀ i, I i) C] /-- The inclusions `(F s).obj (k s) ⟶ colimit (F s)` induce a cocone on `pointwiseProduct F` with cone point `∏ᶜ (fun s : α) => colimit (F s)`. -/ @[simps] noncomputable def coconePointwiseProduct : Cocone (pointwiseProduct F) where pt := ∏ᶜ fun (s : α) => colimit (F s) ι := { app := fun k => Pi.map fun s => colimit.ι _ _ } /-- The natural morphism `colim_k (∏ᶜ s ↦ (F s).obj (k s)) ⟶ ∏ᶜ s ↦ colim_k (F s).obj (k s)`. We will say that a category has the `IPC` property if this morphism is an isomorphism as long as the indexing categories are filtered. -/ noncomputable def colimitPointwiseProductToProductColimit : colimit (pointwiseProduct F) ⟶ ∏ᶜ fun (s : α) => colimit (F s) := colimit.desc (pointwiseProduct F) (coconePointwiseProduct F) @[reassoc (attr := simp)] theorem ι_colimitPointwiseProductToProductColimit_π (k : ∀ i, I i) (s : α) : colimit.ι (pointwiseProduct F) k ≫ colimitPointwiseProductToProductColimit F ≫ Pi.π _ s = Pi.π _ s ≫ colimit.ι (F s) (k s) := by simp [colimitPointwiseProductToProductColimit] end section functorCategory variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D] {α : Type w} {I : α → Type u₂} [∀ i, Category (I i)] [HasLimitsOfShape (Discrete α) C] (F : ∀ i, I i ⥤ D ⥤ C) /-- Evaluating the pointwise product `k ↦ ∏ᶜ fun (s : α) => (F s).obj (k s)` at `d` is the same as taking the pointwise product `k ↦ ∏ᶜ fun (s : α) => ((F s).obj (k s)).obj d`. -/ @[simps!] noncomputable def pointwiseProductCompEvaluation (d : D) : pointwiseProduct F ⋙ (evaluation D C).obj d ≅ pointwiseProduct (fun s => F s ⋙ (evaluation _ _).obj d) := NatIso.ofComponents (fun k => piObjIso _ _) (fun f => Pi.hom_ext _ _ (by simp [← NatTrans.comp_app])) variable [∀ i, HasColimitsOfShape (I i) C] [HasColimitsOfShape (∀ i, I i) C] theorem colimitPointwiseProductToProductColimit_app (d : D) : (colimitPointwiseProductToProductColimit F).app d = (colimitObjIsoColimitCompEvaluation _ _).hom ≫ (HasColimit.isoOfNatIso (pointwiseProductCompEvaluation F d)).hom ≫ colimitPointwiseProductToProductColimit _ ≫ (Pi.mapIso fun _ => (colimitObjIsoColimitCompEvaluation _ _).symm).hom ≫ (piObjIso _ _).inv := by rw [← Iso.inv_comp_eq] simp only [← Category.assoc] rw [Iso.eq_comp_inv] refine Pi.hom_ext _ _ (fun s => colimit.hom_ext (fun k => ?_)) simp [← NatTrans.comp_app] end functorCategory section variable (C : Type u) [Category.{v} C] /-- A category `C` has the `w`-IPC property if the natural morphism `colim_k (∏ᶜ s ↦ (F s).obj (k s)) ⟶ ∏ᶜ s ↦ colim_k (F s).obj (k s)` is an isomorphism for any family of functors `F i : I i ⥤ C` with `I i` `w`-small and filtered for all `i`. -/ class IsIPC [HasProducts.{w} C] [HasFilteredColimitsOfSize.{w} C] : Prop where /-- `colimitPointwiseProductToProductColimit F` is always an isomorphism. -/ isIso : ∀ (α : Type w) (I : α → Type w) [∀ i, SmallCategory (I i)] [∀ i, IsFiltered (I i)] (F : ∀ i, I i ⥤ C), IsIso (colimitPointwiseProductToProductColimit F) attribute [instance] IsIPC.isIso end section types variable {α : Type u} {I : α → Type u} [∀ i, SmallCategory (I i)] [∀ i, IsFiltered (I i)] theorem Types.isIso_colimitPointwiseProductToProductColimit (F : ∀ i, I i ⥤ Type u) : IsIso (colimitPointwiseProductToProductColimit F) := by -- We follow the proof in [Kashiwara2006], Prop. 3.1.11(ii) refine (isIso_iff_bijective _).2 ⟨fun y y' hy => ?_, fun x => ?_⟩ · obtain ⟨ky, yk₀, hyk₀⟩ := Types.jointly_surjective' y obtain ⟨ky', yk₀', hyk₀'⟩ := Types.jointly_surjective' y' let k := IsFiltered.max ky ky' let yk : (pointwiseProduct F).obj k := (pointwiseProduct F).map (IsFiltered.leftToMax ky ky') yk₀ let yk' : (pointwiseProduct F).obj k := (pointwiseProduct F).map (IsFiltered.rightToMax ky ky') yk₀' obtain rfl : y = colimit.ι (pointwiseProduct F) k yk := by simp only [k, yk, Types.Colimit.w_apply, hyk₀] obtain rfl : y' = colimit.ι (pointwiseProduct F) k yk' := by simp only [k, yk', Types.Colimit.w_apply, hyk₀'] dsimp only [pointwiseProduct_obj] at yk yk' have hch : ∀ (s : α), ∃ (i' : I s) (hi' : k s ⟶ i'), (F s).map hi' (Pi.π (fun s => (F s).obj (k s)) s yk) = (F s).map hi' (Pi.π (fun s => (F s).obj (k s)) s yk') := by intro s have hy₁ := congrFun (ι_colimitPointwiseProductToProductColimit_π F k s) yk have hy₂ := congrFun (ι_colimitPointwiseProductToProductColimit_π F k s) yk' dsimp only [pointwiseProduct_obj, types_comp_apply] at hy₁ hy₂ rw [← hy, hy₁, Types.FilteredColimit.colimit_eq_iff] at hy₂ obtain ⟨i₀, f₀, g₀, h₀⟩ := hy₂ refine ⟨IsFiltered.coeq f₀ g₀, f₀ ≫ IsFiltered.coeqHom f₀ g₀, ?_⟩ conv_rhs => rw [IsFiltered.coeq_condition] simp [h₀] choose k' f hk' using hch apply Types.colimit_sound' f f exact Types.limit_ext' _ _ _ (fun ⟨s⟩ => by simpa using hk' _) · have hch : ∀ (s : α), ∃ (i : I s) (xi : (F s).obj i), colimit.ι (F s) i xi = Pi.π (fun s => colimit (F s)) s x := fun s => Types.jointly_surjective' _ choose k p hk using hch refine ⟨colimit.ι (pointwiseProduct F) k ((Types.productIso _).inv p), ?_⟩ refine Types.limit_ext' _ _ _ (fun ⟨s⟩ => ?_) have := congrFun (ι_colimitPointwiseProductToProductColimit_π F k s) ((Types.productIso _).inv p) exact this.trans (by simpa using hk _) instance : IsIPC.{u} (Type u) where isIso _ _ := Types.isIso_colimitPointwiseProductToProductColimit end types section functorCategory variable {C : Type u} [Category.{v} C] instance [HasProducts.{w} C] [HasFilteredColimitsOfSize.{w, w} C] [IsIPC.{w} C] {D : Type u₁} [Category.{v₁} D] : IsIPC.{w} (D ⥤ C) := by refine ⟨fun β I _ _ F => ?_⟩ suffices ∀ d, IsIso ((colimitPointwiseProductToProductColimit F).app d) from NatIso.isIso_of_isIso_app _ exact fun d => colimitPointwiseProductToProductColimit_app F d ▸ inferInstance end functorCategory end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Elements.lean
import Mathlib.CategoryTheory.Elements import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Preserves.Limits /-! # Limits in the category of elements We show that if `C` has limits of shape `I` and `A : C ⥤ Type w` preserves limits of shape `I`, then the category of elements of `A` has limits of shape `I` and the forgetful functor `π : A.Elements ⥤ C` creates them. -/ universe w v₁ v u₁ u namespace CategoryTheory open Limits Opposite variable {C : Type u} [Category.{v} C] namespace CategoryOfElements variable {A : C ⥤ Type w} {I : Type u₁} [Category.{v₁} I] [Small.{w} I] namespace CreatesLimitsAux variable (F : I ⥤ A.Elements) /-- (implementation) A system `(Fi, fi)_i` of elements induces an element in `lim_i A(Fi)`. -/ noncomputable def liftedConeElement' : limit ((F ⋙ π A) ⋙ A) := Types.Limit.mk _ (fun i => (F.obj i).2) (by simp) @[simp] lemma π_liftedConeElement' (i : I) : limit.π ((F ⋙ π A) ⋙ A) i (liftedConeElement' F) = (F.obj i).2 := Types.Limit.π_mk _ _ _ _ variable [HasLimitsOfShape I C] [PreservesLimitsOfShape I A] /-- (implementation) A system `(Fi, fi)_i` of elements induces an element in `A(lim_i Fi)`. -/ noncomputable def liftedConeElement : A.obj (limit (F ⋙ π A)) := (preservesLimitIso A (F ⋙ π A)).inv (liftedConeElement' F) @[simp] lemma map_lift_mapCone (c : Cone F) : A.map (limit.lift (F ⋙ π A) ((π A).mapCone c)) c.pt.snd = liftedConeElement F := by apply (preservesLimitIso A (F ⋙ π A)).toEquiv.injective ext i have h₁ := congrFun (preservesLimitIso_hom_π A (F ⋙ π A) i) (A.map (limit.lift (F ⋙ π A) ((π A).mapCone c)) c.pt.snd) have h₂ := (c.π.app i).property simp_all [← FunctorToTypes.map_comp_apply, liftedConeElement] @[simp] lemma map_π_liftedConeElement (i : I) : A.map (limit.π (F ⋙ π A) i) (liftedConeElement F) = (F.obj i).snd := by have := congrFun (preservesLimitIso_inv_π A (F ⋙ π A) i) (liftedConeElement' F) simp_all [liftedConeElement] /-- (implementation) The constructed limit cone. -/ @[simps] noncomputable def liftedCone : Cone F where pt := ⟨_, liftedConeElement F⟩ π := { app := fun i => ⟨limit.π (F ⋙ π A) i, by simp⟩ naturality := fun i i' f => by ext; simpa using (limit.w _ _).symm } /-- (implementation) The constructed limit cone is a lift of the limit cone in `C`. -/ noncomputable def isValidLift : (π A).mapCone (liftedCone F) ≅ limit.cone (F ⋙ π A) := Iso.refl _ /-- (implementation) The constructed limit cone is a limit cone. -/ noncomputable def isLimit : IsLimit (liftedCone F) where lift s := ⟨limit.lift (F ⋙ π A) ((π A).mapCone s), by simp⟩ uniq s m h := ext _ _ _ <| limit.hom_ext fun i => by simpa using congrArg Subtype.val (h i) end CreatesLimitsAux variable [HasLimitsOfShape I C] [PreservesLimitsOfShape I A] section open CreatesLimitsAux noncomputable instance (F : I ⥤ A.Elements) : CreatesLimit F (π A) := createsLimitOfReflectsIso' (limit.isLimit _) ⟨⟨liftedCone F, isValidLift F⟩, isLimit F⟩ end noncomputable instance : CreatesLimitsOfShape I (π A) where instance : HasLimitsOfShape I A.Elements := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (π A) end CategoryOfElements end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FintypeCat.lean
import Mathlib.CategoryTheory.FintypeCat import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.CategoryTheory.Limits.Types.Products import Mathlib.Data.Finite.Prod import Mathlib.Data.Finite.Sigma /-! # (Co)limits in the category of finite types We show that finite (co)limits exist in `FintypeCat` and that they are preserved by the natural inclusion `FintypeCat.incl`. -/ open CategoryTheory Limits Functor universe u namespace CategoryTheory.Limits.FintypeCat instance {J : Type} [SmallCategory J] (K : J ⥤ FintypeCat.{u}) (j : J) : Finite ((K ⋙ FintypeCat.incl.{u}).obj j) := by simp only [comp_obj, FintypeCat.incl_obj] infer_instance /-- Any functor from a finite category to Types that only involves finite objects, has a finite limit. -/ noncomputable instance finiteLimitOfFiniteDiagram {J : Type} [SmallCategory J] [FinCategory J] (K : J ⥤ Type*) [∀ j, Finite (K.obj j)] : Fintype (limit K) := by have : Fintype (sections K) := Fintype.ofFinite (sections K) exact Fintype.ofEquiv (sections K) (Types.limitEquivSections K).symm noncomputable instance inclusionCreatesFiniteLimits {J : Type} [SmallCategory J] [FinCategory J] : CreatesLimitsOfShape J FintypeCat.incl.{u} where CreatesLimit {K} := createsLimitOfFullyFaithfulOfIso (FintypeCat.of <| limit <| K ⋙ FintypeCat.incl) (Iso.refl _) /- Help typeclass inference to infer creation of finite limits for the forgtful functor. -/ noncomputable instance {J : Type} [SmallCategory J] [FinCategory J] : CreatesLimitsOfShape J (forget FintypeCat) := FintypeCat.inclusionCreatesFiniteLimits instance {J : Type} [SmallCategory J] [FinCategory J] : HasLimitsOfShape J FintypeCat.{u} where has_limit F := hasLimit_of_created F FintypeCat.incl instance hasFiniteLimits : HasFiniteLimits FintypeCat.{u} where out _ := inferInstance noncomputable instance inclusion_preservesFiniteLimits : PreservesFiniteLimits FintypeCat.incl.{u} where preservesFiniteLimits _ := preservesLimitOfShape_of_createsLimitsOfShape_and_hasLimitsOfShape FintypeCat.incl /- Help typeclass inference to infer preservation of finite limits for the forgtful functor. -/ noncomputable instance : PreservesFiniteLimits (forget FintypeCat) := FintypeCat.inclusion_preservesFiniteLimits /-- The categorical product of a finite family in `FintypeCat` is equivalent to the product as types. -/ noncomputable def productEquiv {ι : Type*} [Finite ι] (X : ι → FintypeCat.{u}) : (∏ᶜ X : FintypeCat) ≃ ∀ i, X i := letI : Fintype ι := Fintype.ofFinite _ haveI : Small.{u} ι := ⟨ULift (Fin (Fintype.card ι)), ⟨(Fintype.equivFin ι).trans Equiv.ulift.symm⟩⟩ let is₁ : FintypeCat.incl.obj (∏ᶜ fun i ↦ X i) ≅ (∏ᶜ fun i ↦ X i : Type u) := PreservesProduct.iso FintypeCat.incl (fun i ↦ X i) let is₂ : (∏ᶜ fun i ↦ X i : Type u) ≅ Shrink.{u} (∀ i, X i) := Types.Small.productIso (fun i ↦ X i) let e : (∀ i, X i) ≃ Shrink.{u} (∀ i, X i) := equivShrink _ (equivEquivIso.symm is₁).trans ((equivEquivIso.symm is₂).trans e.symm) @[simp] lemma productEquiv_apply {ι : Type*} [Finite ι] (X : ι → FintypeCat.{u}) (x : (∏ᶜ X : FintypeCat)) (i : ι) : productEquiv X x i = Pi.π X i x := by simpa [productEquiv] using (elementwise_of% piComparison_comp_π FintypeCat.incl X i) x @[simp] lemma productEquiv_symm_comp_π_apply {ι : Type*} [Finite ι] (X : ι → FintypeCat.{u}) (x : ∀ i, X i) (i : ι) : Pi.π X i ((productEquiv X).symm x) = x i := by rw [← productEquiv_apply, Equiv.apply_symm_apply] instance nonempty_pi_of_nonempty {ι : Type*} [Finite ι] (X : ι → FintypeCat.{u}) [∀ i, Nonempty (X i)] : Nonempty (∏ᶜ X : FintypeCat.{u}) := (Equiv.nonempty_congr <| productEquiv X).mpr inferInstance /-- The colimit type of a functor from a finite category to Types that only involves finite objects is finite. -/ instance finite_colimitType {J : Type} [SmallCategory J] [FinCategory J] (K : J ⥤ Type*) [∀ j, Finite (K.obj j)] : Finite K.ColimitType := Quot.finite _ /-- Any functor from a finite category to Types that only involves finite objects, has a finite colimit. -/ lemma finite_of_isColimit {J : Type} [SmallCategory J] [FinCategory J] {K : J ⥤ Type*} [∀ j, Finite (K.obj j)] {c : Cocone K} (hc : IsColimit c) : Finite c.pt := Finite.of_equiv _ ((Types.isColimit_iff_coconeTypesIsColimit c).1 ⟨hc⟩).equiv /-- Any functor from a finite category to Types that only involves finite objects, has a finite colimit. -/ noncomputable instance finiteColimitOfFiniteDiagram {J : Type} [SmallCategory J] [FinCategory J] (K : J ⥤ Type*) [∀ j, Finite (K.obj j)] : Fintype (colimit K) := by have : Finite (colimit K) := finite_of_isColimit (colimit.isColimit K) apply Fintype.ofFinite noncomputable instance inclusionCreatesFiniteColimits {J : Type} [SmallCategory J] [FinCategory J] : CreatesColimitsOfShape J FintypeCat.incl.{u} where CreatesColimit {K} := createsColimitOfFullyFaithfulOfIso (FintypeCat.of <| colimit <| K ⋙ FintypeCat.incl) (Iso.refl _) /- Help typeclass inference to infer creation of finite colimits for the forgtful functor. -/ noncomputable instance {J : Type} [SmallCategory J] [FinCategory J] : CreatesColimitsOfShape J (forget FintypeCat) := FintypeCat.inclusionCreatesFiniteColimits instance {J : Type} [SmallCategory J] [FinCategory J] : HasColimitsOfShape J FintypeCat.{u} where has_colimit F := hasColimit_of_created F FintypeCat.incl instance hasFiniteColimits : HasFiniteColimits FintypeCat.{u} where out _ := inferInstance noncomputable instance inclusion_preservesFiniteColimits : PreservesFiniteColimits FintypeCat.incl.{u} where preservesFiniteColimits _ := preservesColimitOfShape_of_createsColimitsOfShape_and_hasColimitsOfShape FintypeCat.incl /- Help typeclass inference to infer preservation of finite colimits for the forgtful functor. -/ noncomputable instance : PreservesFiniteColimits (forget FintypeCat) := FintypeCat.inclusion_preservesFiniteColimits lemma jointly_surjective {J : Type*} [Category J] [FinCategory J] (F : J ⥤ FintypeCat.{u}) (t : Cocone F) (h : IsColimit t) (x : t.pt) : ∃ j y, t.ι.app j y = x := let hs := isColimitOfPreserves FintypeCat.incl.{u} h Types.jointly_surjective (F ⋙ FintypeCat.incl) hs x end CategoryTheory.Limits.FintypeCat
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorCategory/Finite.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Functor categories have finite limits when the target category does These declarations cannot be in `Mathlib/CategoryTheory/Limits/FunctorCategory.lean` because that file shouldn't import `Mathlib/CategoryTheory/Limits/Shapes/FiniteProducts.lean`. -/ namespace CategoryTheory.Limits variable {C : Type*} [Category C] {K : Type*} [Category K] instance [HasFiniteLimits C] : HasFiniteLimits (K ⥤ C) := ⟨fun _ ↦ inferInstance⟩ instance [HasFiniteProducts C] : HasFiniteProducts (K ⥤ C) := ⟨inferInstance⟩ instance [HasFiniteColimits C] : HasFiniteColimits (K ⥤ C) := ⟨fun _ ↦ inferInstance⟩ instance [HasFiniteCoproducts C] : HasFiniteCoproducts (K ⥤ C) := ⟨inferInstance⟩ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorCategory/EpiMono.lean
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic /-! # Monomorphisms and epimorphisms in functor categories A natural transformation `f : F ⟶ G` between functors `K ⥤ C` is a mono (resp. epi) iff for all `k : K`, `f.app k` is, at least when `C` has pullbacks (resp. pushouts), see `NatTrans.mono_iff_mono_app` and `NatTrans.epi_iff_epi_app`. -/ universe v v' v'' u u' u'' namespace CategoryTheory open Limits Functor variable {K : Type u} [Category.{v} K] {C : Type u'} [Category.{v'} C] {D : Type u''} [Category.{v''} D] {F G : K ⥤ C} (f : F ⟶ G) section variable [HasPullbacks C] instance [Mono f] (k : K) : Mono (f.app k) := inferInstanceAs (Mono (((evaluation K C).obj k).map f)) lemma NatTrans.mono_iff_mono_app : Mono f ↔ ∀ (k : K), Mono (f.app k) := ⟨fun _ ↦ inferInstance, fun _ ↦ mono_of_mono_app _⟩ instance [Mono f] (H : C ⥤ D) [H.PreservesMonomorphisms] : Mono (whiskerRight f H) := by have : ∀ X, Mono ((whiskerRight f H).app X) := by intros; dsimp; infer_instance apply NatTrans.mono_of_mono_app end section variable [HasPushouts C] instance [Epi f] (k : K) : Epi (f.app k) := inferInstanceAs (Epi (((evaluation K C).obj k).map f)) lemma NatTrans.epi_iff_epi_app : Epi f ↔ ∀ (k : K), Epi (f.app k) := ⟨fun _ ↦ inferInstance, fun _ ↦ epi_of_epi_app _⟩ instance [Epi f] (H : C ⥤ D) [H.PreservesEpimorphisms] : Epi (whiskerRight f H) := by have : ∀ X, Epi ((whiskerRight f H).app X) := by intros; dsimp; infer_instance apply NatTrans.epi_of_epi_app end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorCategory/Filtered.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Filtered /-! # Functor categories have filtered colimits when the target category does These declarations cannot be in `Mathlib/CategoryTheory/Limits/FunctorCategory.lean` because that file shouldn't import `Mathlib/CategoryTheory/Limits/Filtered.lean`. -/ universe w' w v₁ v₂ u₁ u₂ namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] {K : Type u₂} [Category.{v₂} K] instance [HasFilteredColimitsOfSize.{w', w} C] : HasFilteredColimitsOfSize.{w', w} (K ⥤ C) := ⟨fun _ => inferInstance⟩ instance [HasCofilteredLimitsOfSize.{w', w} C] : HasCofilteredLimitsOfSize.{w', w} (K ⥤ C) := ⟨fun _ => inferInstance⟩ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorCategory/Basic.lean
import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Limits.Preserves.Limits /-! # (Co)limits in functor categories. We show that if `D` has limits, then the functor category `C ⥤ D` also has limits (`CategoryTheory.Limits.functorCategoryHasLimits`), and the evaluation functors preserve limits (`CategoryTheory.Limits.evaluation_preservesLimits`) (and similarly for colimits). We also show that `F : D ⥤ K ⥤ C` preserves (co)limits if it does so for each `k : K` (`CategoryTheory.Limits.preservesLimits_of_evaluation` and `CategoryTheory.Limits.preservesColimits_of_evaluation`). -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Functor -- morphism levels before object levels. See note [category theory universes]. universe w' w v₁ v₂ u₁ u₂ v v' u u' namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] @[reassoc (attr := simp)] theorem limit.lift_π_app (H : J ⥤ K ⥤ C) [HasLimit H] (c : Cone H) (j : J) (k : K) : (limit.lift H c).app k ≫ (limit.π H j).app k = (c.π.app j).app k := congr_app (limit.lift_π c j) k @[reassoc (attr := simp)] theorem colimit.ι_desc_app (H : J ⥤ K ⥤ C) [HasColimit H] (c : Cocone H) (j : J) (k : K) : (colimit.ι H j).app k ≫ (colimit.desc H c).app k = (c.ι.app j).app k := congr_app (colimit.ι_desc c j) k /-- The evaluation functors jointly reflect limits: that is, to show a cone is a limit of `F` it suffices to show that each evaluation cone is a limit. In other words, to prove a cone is limiting you can show it's pointwise limiting. -/ def evaluationJointlyReflectsLimits {F : J ⥤ K ⥤ C} (c : Cone F) (t : ∀ k : K, IsLimit (((evaluation K C).obj k).mapCone c)) : IsLimit c where lift s := { app := fun k => (t k).lift ⟨s.pt.obj k, whiskerRight s.π ((evaluation K C).obj k)⟩ naturality := fun X Y f => (t Y).hom_ext fun j => by rw [assoc, (t Y).fac _ j] simpa using ((t X).fac_assoc ⟨s.pt.obj X, whiskerRight s.π ((evaluation K C).obj X)⟩ j _).symm } fac s j := by ext k; exact (t k).fac _ j uniq s m w := by ext x exact (t x).hom_ext fun j => (congr_app (w j) x).trans ((t x).fac ⟨s.pt.obj _, whiskerRight s.π ((evaluation K C).obj _)⟩ j).symm /-- Given a functor `F` and a collection of limit cones for each diagram `X ↦ F X k`, we can stitch them together to give a cone for the diagram `F`. `combinedIsLimit` shows that the new cone is limiting, and `evalCombined` shows it is (essentially) made up of the original cones. -/ @[simps] def combineCones (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) : Cone F where pt := { obj := fun k => (c k).cone.pt map := fun {k₁} {k₂} f => (c k₂).isLimit.lift ⟨_, (c k₁).cone.π ≫ F.flip.map f⟩ map_id := fun k => (c k).isLimit.hom_ext fun j => by simp map_comp := fun {k₁} {k₂} {k₃} f₁ f₂ => (c k₃).isLimit.hom_ext fun j => by simp } π := { app := fun j => { app := fun k => (c k).cone.π.app j } naturality := fun j₁ j₂ g => by ext k; exact (c k).cone.π.naturality g } /-- The stitched together cones each project down to the original given cones (up to iso). -/ def evaluateCombinedCones (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) (k : K) : ((evaluation K C).obj k).mapCone (combineCones F c) ≅ (c k).cone := Cones.ext (Iso.refl _) /-- Stitching together limiting cones gives a limiting cone. -/ def combinedIsLimit (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) : IsLimit (combineCones F c) := evaluationJointlyReflectsLimits _ fun k => (c k).isLimit.ofIsoLimit (evaluateCombinedCones F c k).symm /-- The evaluation functors jointly reflect colimits: that is, to show a cocone is a colimit of `F` it suffices to show that each evaluation cocone is a colimit. In other words, to prove a cocone is colimiting you can show it's pointwise colimiting. -/ def evaluationJointlyReflectsColimits {F : J ⥤ K ⥤ C} (c : Cocone F) (t : ∀ k : K, IsColimit (((evaluation K C).obj k).mapCocone c)) : IsColimit c where desc s := { app := fun k => (t k).desc ⟨s.pt.obj k, whiskerRight s.ι ((evaluation K C).obj k)⟩ naturality := fun X Y f => (t X).hom_ext fun j => by rw [(t X).fac_assoc _ j] erw [← (c.ι.app j).naturality_assoc f] erw [(t Y).fac ⟨s.pt.obj _, whiskerRight s.ι _⟩ j] simp } fac s j := by ext k; exact (t k).fac _ j uniq s m w := by ext x exact (t x).hom_ext fun j => (congr_app (w j) x).trans ((t x).fac ⟨s.pt.obj _, whiskerRight s.ι ((evaluation K C).obj _)⟩ j).symm /-- Given a functor `F` and a collection of colimit cocones for each diagram `X ↦ F X k`, we can stitch them together to give a cocone for the diagram `F`. `combinedIsColimit` shows that the new cocone is colimiting, and `evalCombined` shows it is (essentially) made up of the original cocones. -/ @[simps] def combineCocones (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) : Cocone F where pt := { obj := fun k => (c k).cocone.pt map := fun {k₁} {k₂} f => (c k₁).isColimit.desc ⟨_, F.flip.map f ≫ (c k₂).cocone.ι⟩ map_id := fun k => (c k).isColimit.hom_ext fun j => by simp map_comp := fun {k₁} {k₂} {k₃} f₁ f₂ => (c k₁).isColimit.hom_ext fun j => by simp } ι := { app := fun j => { app := fun k => (c k).cocone.ι.app j } naturality := fun j₁ j₂ g => by ext k; exact (c k).cocone.ι.naturality g } /-- The stitched together cocones each project down to the original given cocones (up to iso). -/ def evaluateCombinedCocones (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) (k : K) : ((evaluation K C).obj k).mapCocone (combineCocones F c) ≅ (c k).cocone := Cocones.ext (Iso.refl _) /-- Stitching together colimiting cocones gives a colimiting cocone. -/ def combinedIsColimit (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) : IsColimit (combineCocones F c) := evaluationJointlyReflectsColimits _ fun k => (c k).isColimit.ofIsoColimit (evaluateCombinedCocones F c k).symm /-- An alternative colimit cocone in the functor category `K ⥤ C` in the case where `C` has `J`-shaped colimits, with cocone point `F.flip ⋙ colim`. -/ @[simps] noncomputable def pointwiseCocone [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) : Cocone F where pt := F.flip ⋙ colim ι := { app X := { app Y := (colimit.ι _ X : (F.flip.obj Y).obj X ⟶ _) } naturality X Y f := by ext x simp only [Functor.const_obj_obj, Functor.comp_obj, colim_obj, NatTrans.comp_app, Functor.const_obj_map, Category.comp_id] change (F.flip.obj x).map f ≫ _ = _ rw [colimit.w] } /-- `pointwiseCocone` is indeed a colimit cocone. -/ noncomputable def pointwiseIsColimit [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) : IsColimit (pointwiseCocone F) := by apply IsColimit.ofIsoColimit (combinedIsColimit _ (fun k ↦ ⟨colimit.cocone _, colimit.isColimit _⟩)) exact Cocones.ext (Iso.refl _) noncomputable section instance functorCategoryHasLimit (F : J ⥤ K ⥤ C) [∀ k, HasLimit (F.flip.obj k)] : HasLimit F := HasLimit.mk { cone := combineCones F fun _ => getLimitCone _ isLimit := combinedIsLimit _ _ } instance functorCategoryHasLimitsOfShape [HasLimitsOfShape J C] : HasLimitsOfShape J (K ⥤ C) where has_limit _ := inferInstance instance functorCategoryHasColimit (F : J ⥤ K ⥤ C) [∀ k, HasColimit (F.flip.obj k)] : HasColimit F := HasColimit.mk { cocone := combineCocones F fun _ => getColimitCocone _ isColimit := combinedIsColimit _ _ } instance functorCategoryHasColimitsOfShape [HasColimitsOfShape J C] : HasColimitsOfShape J (K ⥤ C) where has_colimit _ := inferInstance instance functorCategoryHasLimitsOfSize [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₁, u₁} (K ⥤ C) where has_limits_of_shape := inferInstance instance functorCategoryHasColimitsOfSize [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfSize.{v₁, u₁} (K ⥤ C) where has_colimits_of_shape := inferInstance instance hasLimitCompEvaluation (F : J ⥤ K ⥤ C) (k : K) [HasLimit (F.flip.obj k)] : HasLimit (F ⋙ (evaluation _ _).obj k) := hasLimit_of_iso (F := F.flip.obj k) (Iso.refl _) instance evaluation_preservesLimit (F : J ⥤ K ⥤ C) [∀ k, HasLimit (F.flip.obj k)] (k : K) : PreservesLimit F ((evaluation K C).obj k) := -- Porting note: added a let because X was not inferred let X : (k : K) → LimitCone (F.flip.obj k) := fun k => getLimitCone (F.flip.obj k) preservesLimit_of_preserves_limit_cone (combinedIsLimit _ X) <| IsLimit.ofIsoLimit (limit.isLimit _) (evaluateCombinedCones F X k).symm instance evaluation_preservesLimitsOfShape [HasLimitsOfShape J C] (k : K) : PreservesLimitsOfShape J ((evaluation K C).obj k) where preservesLimit := inferInstance /-- If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a limit, then the evaluation of that limit at `k` is the limit of the evaluations of `F.obj j` at `k`. -/ def limitObjIsoLimitCompEvaluation [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (k : K) : (limit F).obj k ≅ limit (F ⋙ (evaluation K C).obj k) := preservesLimitIso ((evaluation K C).obj k) F @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_hom_π [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (limitObjIsoLimitCompEvaluation F k).hom ≫ limit.π (F ⋙ (evaluation K C).obj k) j = (limit.π F j).app k := by dsimp [limitObjIsoLimitCompEvaluation] simp @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_inv_π_app [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (limitObjIsoLimitCompEvaluation F k).inv ≫ (limit.π F j).app k = limit.π (F ⋙ (evaluation K C).obj k) j := by dsimp [limitObjIsoLimitCompEvaluation] rw [Iso.inv_comp_eq] simp @[reassoc (attr := simp)] theorem limit_map_limitObjIsoLimitCompEvaluation_hom [HasLimitsOfShape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) : (limit F).map f ≫ (limitObjIsoLimitCompEvaluation _ _).hom = (limitObjIsoLimitCompEvaluation _ _).hom ≫ limMap (whiskerLeft _ ((evaluation _ _).map f)) := by ext simp @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_inv_limit_map [HasLimitsOfShape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) : (limitObjIsoLimitCompEvaluation _ _).inv ≫ (limit F).map f = limMap (whiskerLeft _ ((evaluation _ _).map f)) ≫ (limitObjIsoLimitCompEvaluation _ _).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, limit_map_limitObjIsoLimitCompEvaluation_hom] @[ext] theorem limit_obj_ext {H : J ⥤ K ⥤ C} [HasLimitsOfShape J C] {k : K} {W : C} {f g : W ⟶ (limit H).obj k} (w : ∀ j, f ≫ (Limits.limit.π H j).app k = g ≫ (Limits.limit.π H j).app k) : f = g := by apply (cancel_mono (limitObjIsoLimitCompEvaluation H k).hom).1 ext j simpa using w j /-- Taking a limit after whiskering by `G` is the same as using `G` and then taking a limit. -/ def limitCompWhiskeringLeftIsoCompLimit (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasLimitsOfShape J C] : limit (F ⋙ (whiskeringLeft _ _ _).obj G) ≅ G ⋙ limit F := NatIso.ofComponents (fun j => limitObjIsoLimitCompEvaluation (F ⋙ (whiskeringLeft _ _ _).obj G) j ≪≫ HasLimit.isoOfNatIso (isoWhiskerLeft F (whiskeringLeftCompEvaluation G j)) ≪≫ (limitObjIsoLimitCompEvaluation F (G.obj j)).symm) @[reassoc (attr := simp)] theorem limitCompWhiskeringLeftIsoCompLimit_hom_whiskerLeft_π (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasLimitsOfShape J C] (j : J) : (limitCompWhiskeringLeftIsoCompLimit F G).hom ≫ whiskerLeft G (limit.π F j) = limit.π (F ⋙ (whiskeringLeft _ _ _).obj G) j := by ext d simp [limitCompWhiskeringLeftIsoCompLimit] @[reassoc (attr := simp)] theorem limitCompWhiskeringLeftIsoCompLimit_inv_π (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasLimitsOfShape J C] (j : J) : (limitCompWhiskeringLeftIsoCompLimit F G).inv ≫ limit.π (F ⋙ (whiskeringLeft _ _ _).obj G) j = whiskerLeft G (limit.π F j) := by simp [Iso.inv_comp_eq] instance hasColimitCompEvaluation (F : J ⥤ K ⥤ C) (k : K) [HasColimit (F.flip.obj k)] : HasColimit (F ⋙ (evaluation _ _).obj k) := hasColimit_of_iso (F := F.flip.obj k) (Iso.refl _) instance evaluation_preservesColimit (F : J ⥤ K ⥤ C) [∀ k, HasColimit (F.flip.obj k)] (k : K) : PreservesColimit F ((evaluation K C).obj k) := -- Porting note: added a let because X was not inferred let X : (k : K) → ColimitCocone (F.flip.obj k) := fun k => getColimitCocone (F.flip.obj k) preservesColimit_of_preserves_colimit_cocone (combinedIsColimit _ X) <| IsColimit.ofIsoColimit (colimit.isColimit _) (evaluateCombinedCocones F X k).symm instance evaluation_preservesColimitsOfShape [HasColimitsOfShape J C] (k : K) : PreservesColimitsOfShape J ((evaluation K C).obj k) where preservesColimit := inferInstance /-- If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a colimit, then the evaluation of that colimit at `k` is the colimit of the evaluations of `F.obj j` at `k`. -/ def colimitObjIsoColimitCompEvaluation [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (k : K) : (colimit F).obj k ≅ colimit (F ⋙ (evaluation K C).obj k) := preservesColimitIso ((evaluation K C).obj k) F @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_ι_inv [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : colimit.ι (F ⋙ (evaluation K C).obj k) j ≫ (colimitObjIsoColimitCompEvaluation F k).inv = (colimit.ι F j).app k := by dsimp [colimitObjIsoColimitCompEvaluation] simp @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_ι_app_hom [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (colimit.ι F j).app k ≫ (colimitObjIsoColimitCompEvaluation F k).hom = colimit.ι (F ⋙ (evaluation K C).obj k) j := by dsimp [colimitObjIsoColimitCompEvaluation] rw [← Iso.eq_comp_inv] simp @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_inv_colimit_map [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) : (colimitObjIsoColimitCompEvaluation _ _).inv ≫ (colimit F).map f = colimMap (whiskerLeft _ ((evaluation _ _).map f)) ≫ (colimitObjIsoColimitCompEvaluation _ _).inv := by ext simp @[reassoc (attr := simp)] theorem colimit_map_colimitObjIsoColimitCompEvaluation_hom [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) : (colimit F).map f ≫ (colimitObjIsoColimitCompEvaluation _ _).hom = (colimitObjIsoColimitCompEvaluation _ _).hom ≫ colimMap (whiskerLeft _ ((evaluation _ _).map f)) := by rw [← Iso.inv_comp_eq, ← Category.assoc, ← Iso.eq_comp_inv, colimitObjIsoColimitCompEvaluation_inv_colimit_map] @[ext] theorem colimit_obj_ext {H : J ⥤ K ⥤ C} [HasColimitsOfShape J C] {k : K} {W : C} {f g : (colimit H).obj k ⟶ W} (w : ∀ j, (colimit.ι H j).app k ≫ f = (colimit.ι H j).app k ≫ g) : f = g := by apply (cancel_epi (colimitObjIsoColimitCompEvaluation H k).inv).1 ext j simpa using w j /-- Taking a colimit after whiskering by `G` is the same as using `G` and then taking a colimit. -/ def colimitCompWhiskeringLeftIsoCompColimit (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasColimitsOfShape J C] : colimit (F ⋙ (whiskeringLeft _ _ _).obj G) ≅ G ⋙ colimit F := NatIso.ofComponents (fun j => colimitObjIsoColimitCompEvaluation (F ⋙ (whiskeringLeft _ _ _).obj G) j ≪≫ HasColimit.isoOfNatIso (isoWhiskerLeft F (whiskeringLeftCompEvaluation G j)) ≪≫ (colimitObjIsoColimitCompEvaluation F (G.obj j)).symm) @[reassoc (attr := simp)] theorem ι_colimitCompWhiskeringLeftIsoCompColimit_hom (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasColimitsOfShape J C] (j : J) : colimit.ι (F ⋙ (whiskeringLeft _ _ _).obj G) j ≫ (colimitCompWhiskeringLeftIsoCompColimit F G).hom = whiskerLeft G (colimit.ι F j) := by ext d simp [colimitCompWhiskeringLeftIsoCompColimit] @[reassoc (attr := simp)] theorem whiskerLeft_ι_colimitCompWhiskeringLeftIsoCompColimit_inv (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasColimitsOfShape J C] (j : J) : whiskerLeft G (colimit.ι F j) ≫ (colimitCompWhiskeringLeftIsoCompColimit F G).inv = colimit.ι (F ⋙ (whiskeringLeft _ _ _).obj G) j := by simp [Iso.comp_inv_eq] instance evaluationPreservesLimits [HasLimits C] (k : K) : PreservesLimits ((evaluation K C).obj k) where preservesLimitsOfShape {_} _𝒥 := inferInstance /-- `F : D ⥤ K ⥤ C` preserves the limit of some `G : J ⥤ D` if it does for each `k : K`. -/ lemma preservesLimit_of_evaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D) (H : ∀ k : K, PreservesLimit G (F ⋙ (evaluation K C).obj k : D ⥤ C)) : PreservesLimit G F := ⟨fun {c} hc => ⟨by apply evaluationJointlyReflectsLimits intro X haveI := H X change IsLimit ((F ⋙ (evaluation K C).obj X).mapCone c) exact isLimitOfPreserves _ hc⟩⟩ /-- `F : D ⥤ K ⥤ C` preserves limits of shape `J` if it does for each `k : K`. -/ lemma preservesLimitsOfShape_of_evaluation (F : D ⥤ K ⥤ C) (J : Type*) [Category J] (_ : ∀ k : K, PreservesLimitsOfShape J (F ⋙ (evaluation K C).obj k)) : PreservesLimitsOfShape J F := ⟨fun {G} => preservesLimit_of_evaluation F G fun _ => PreservesLimitsOfShape.preservesLimit⟩ /-- `F : D ⥤ K ⥤ C` preserves all limits if it does for each `k : K`. -/ lemma preservesLimits_of_evaluation (F : D ⥤ K ⥤ C) (_ : ∀ k : K, PreservesLimitsOfSize.{w', w} (F ⋙ (evaluation K C).obj k)) : PreservesLimitsOfSize.{w', w} F := ⟨fun {L} _ => preservesLimitsOfShape_of_evaluation F L fun _ => PreservesLimitsOfSize.preservesLimitsOfShape⟩ /-- The constant functor `C ⥤ (D ⥤ C)` preserves limits. -/ instance preservesLimits_const : PreservesLimitsOfSize.{w', w} (const D : C ⥤ _) := preservesLimits_of_evaluation _ fun _ => preservesLimits_of_natIso <| Iso.symm <| constCompEvaluationObj _ _ instance evaluation_preservesColimits [HasColimits C] (k : K) : PreservesColimits ((evaluation K C).obj k) where preservesColimitsOfShape := inferInstance /-- `F : D ⥤ K ⥤ C` preserves the colimit of some `G : J ⥤ D` if it does for each `k : K`. -/ lemma preservesColimit_of_evaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D) (H : ∀ k, PreservesColimit G (F ⋙ (evaluation K C).obj k)) : PreservesColimit G F := ⟨fun {c} hc => ⟨by apply evaluationJointlyReflectsColimits intro X haveI := H X change IsColimit ((F ⋙ (evaluation K C).obj X).mapCocone c) exact isColimitOfPreserves _ hc⟩⟩ /-- `F : D ⥤ K ⥤ C` preserves all colimits of shape `J` if it does for each `k : K`. -/ lemma preservesColimitsOfShape_of_evaluation (F : D ⥤ K ⥤ C) (J : Type*) [Category J] (_ : ∀ k : K, PreservesColimitsOfShape J (F ⋙ (evaluation K C).obj k)) : PreservesColimitsOfShape J F := ⟨fun {G} => preservesColimit_of_evaluation F G fun _ => PreservesColimitsOfShape.preservesColimit⟩ /-- `F : D ⥤ K ⥤ C` preserves all colimits if it does for each `k : K`. -/ lemma preservesColimits_of_evaluation (F : D ⥤ K ⥤ C) (_ : ∀ k : K, PreservesColimitsOfSize.{w', w} (F ⋙ (evaluation K C).obj k)) : PreservesColimitsOfSize.{w', w} F := ⟨fun {L} _ => preservesColimitsOfShape_of_evaluation F L fun _ => PreservesColimitsOfSize.preservesColimitsOfShape⟩ /-- The constant functor `C ⥤ (D ⥤ C)` preserves colimits. -/ instance preservesColimits_const : PreservesColimitsOfSize.{w', w} (const D : C ⥤ _) := preservesColimits_of_evaluation _ fun _ => preservesColimits_of_natIso <| Iso.symm <| constCompEvaluationObj _ _ open CategoryTheory.prod /-- The limit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by the individual limits on objects. -/ @[simps!] def limitIsoFlipCompLim [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) : limit F ≅ F.flip ⋙ lim := NatIso.ofComponents (limitObjIsoLimitCompEvaluation F) /-- `limitIsoFlipCompLim` is natural with respect to diagrams. -/ @[simps!] def limIsoFlipCompWhiskerLim [HasLimitsOfShape J C] : lim ≅ flipFunctor J K C ⋙ (whiskeringRight _ _ _).obj lim := (NatIso.ofComponents (limitIsoFlipCompLim · |>.symm) fun {F G} η ↦ by ext k apply limit_obj_ext intro j simp [comp_evaluation, ← NatTrans.comp_app (limMap η)]).symm /-- A variant of `limitIsoFlipCompLim` where the arguments of `F` are flipped. -/ @[simps!] def limitFlipIsoCompLim [HasLimitsOfShape J C] (F : K ⥤ J ⥤ C) : limit F.flip ≅ F ⋙ lim := let f := fun k => limitObjIsoLimitCompEvaluation F.flip k ≪≫ HasLimit.isoOfNatIso (flipCompEvaluation _ _) NatIso.ofComponents f /-- `limitFlipIsoCompLim` is natural with respect to diagrams. -/ @[simps!] def limCompFlipIsoWhiskerLim [HasLimitsOfShape J C] : flipFunctor K J C ⋙ lim ≅ (whiskeringRight _ _ _).obj lim := (NatIso.ofComponents (limitFlipIsoCompLim · |>.symm) fun {F G} η ↦ by ext k apply limit_obj_ext intro j simp [comp_evaluation, ← NatTrans.comp_app (limMap _)]).symm /-- For a functor `G : J ⥤ K ⥤ C`, its limit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ lim`. Note that this does not require `K` to be small. -/ @[simps!] def limitIsoSwapCompLim [HasLimitsOfShape J C] (G : J ⥤ K ⥤ C) : limit G ≅ curry.obj (Prod.swap K J ⋙ uncurry.obj G) ⋙ lim := limitIsoFlipCompLim G ≪≫ isoWhiskerRight (flipIsoCurrySwapUncurry _) _ /-- The colimit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by the individual colimits on objects. -/ @[simps!] def colimitIsoFlipCompColim [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) : colimit F ≅ F.flip ⋙ colim := NatIso.ofComponents (colimitObjIsoColimitCompEvaluation F) /-- `colimitIsoFlipCompColim` is natural with respect to diagrams. -/ @[simps!] def colimIsoFlipCompWhiskerColim [HasColimitsOfShape J C] : colim ≅ flipFunctor J K C ⋙ (whiskeringRight _ _ _).obj colim := NatIso.ofComponents colimitIsoFlipCompColim fun {F G} η ↦ by ext k apply colimit_obj_ext intro j simp [comp_evaluation, ← NatTrans.comp_app_assoc _ (colimMap η)] /-- A variant of `colimitIsoFlipCompColim` where the arguments of `F` are flipped. -/ @[simps!] def colimitFlipIsoCompColim [HasColimitsOfShape J C] (F : K ⥤ J ⥤ C) : colimit F.flip ≅ F ⋙ colim := let f := fun _ => colimitObjIsoColimitCompEvaluation _ _ ≪≫ HasColimit.isoOfNatIso (flipCompEvaluation _ _) NatIso.ofComponents f /-- `colimitFlipIsoCompColim` is natural with respect to diagrams. -/ @[simps!] def colimCompFlipIsoWhiskerColim [HasColimitsOfShape J C] : flipFunctor K J C ⋙ colim ≅ (whiskeringRight _ _ _).obj colim := NatIso.ofComponents colimitFlipIsoCompColim fun {F G} η ↦ by ext k apply colimit_obj_ext intro j simp [comp_evaluation, ← NatTrans.comp_app_assoc _ (colimMap _)] /-- For a functor `G : J ⥤ K ⥤ C`, its colimit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ colim`. Note that this does not require `K` to be small. -/ @[simps!] def colimitIsoSwapCompColim [HasColimitsOfShape J C] (G : J ⥤ K ⥤ C) : colimit G ≅ curry.obj (Prod.swap K J ⋙ uncurry.obj G) ⋙ colim := colimitIsoFlipCompColim G ≪≫ isoWhiskerRight (flipIsoCurrySwapUncurry _) _ end end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorCategory/Shapes/Products.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products /-! # (Co)products in functor categories Given `f : α → D ⥤ C`, we prove the isomorphisms `(∏ᶜ f).obj d ≅ ∏ᶜ (fun s => (f s).obj d)` and `(∐ f).obj d ≅ ∐ (fun s => (f s).obj d)`. -/ universe w v v₁ v₂ u u₁ u₂ namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D] {α : Type w} section Product variable [HasLimitsOfShape (Discrete α) C] /-- Evaluating a product of functors amounts to taking the product of the evaluations. -/ noncomputable def piObjIso (f : α → D ⥤ C) (d : D) : (∏ᶜ f).obj d ≅ ∏ᶜ (fun s => (f s).obj d) := limitObjIsoLimitCompEvaluation (Discrete.functor f) d ≪≫ HasLimit.isoOfNatIso (Discrete.compNatIsoDiscrete _ _) @[reassoc (attr := simp)] theorem piObjIso_hom_comp_π (f : α → D ⥤ C) (d : D) (s : α) : (piObjIso f d).hom ≫ Pi.π (fun s => (f s).obj d) s = (Pi.π f s).app d := by simp [piObjIso] @[reassoc (attr := simp)] theorem piObjIso_inv_comp_π (f : α → D ⥤ C) (d : D) (s : α) : (piObjIso f d).inv ≫ (Pi.π f s).app d = Pi.π (fun s => (f s).obj d) s := by simp [piObjIso] end Product section Coproduct variable [HasColimitsOfShape (Discrete α) C] /-- Evaluating a coproduct of functors amounts to taking the coproduct of the evaluations. -/ noncomputable def sigmaObjIso (f : α → D ⥤ C) (d : D) : (∐ f).obj d ≅ ∐ (fun s => (f s).obj d) := colimitObjIsoColimitCompEvaluation (Discrete.functor f) d ≪≫ HasColimit.isoOfNatIso (Discrete.compNatIsoDiscrete _ _) @[reassoc (attr := simp)] theorem ι_comp_sigmaObjIso_hom (f : α → D ⥤ C) (d : D) (s : α) : (Sigma.ι f s).app d ≫ (sigmaObjIso f d).hom = Sigma.ι (fun s => (f s).obj d) s := by simp [sigmaObjIso] @[reassoc (attr := simp)] theorem ι_comp_sigmaObjIso_inv (f : α → D ⥤ C) (d : D) (s : α) : Sigma.ι (fun s => (f s).obj d) s ≫ (sigmaObjIso f d).inv = (Sigma.ι f s).app d := by simp [sigmaObjIso] end Coproduct end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorCategory/Shapes/Kernels.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels /-! # (Co)kernels in functor categories -/ namespace CategoryTheory.Limits universe u variable (C : Type*) [Category.{u} C] [HasZeroMorphisms C] /-- The kernel inclusion is itself a kernel in the functor category. -/ noncomputable def kerIsKernel [HasKernels C] : IsLimit (KernelFork.ofι (ker.ι C) (ker.condition C)) := evaluationJointlyReflectsLimits _ fun f ↦ (KernelFork.isLimitMapConeEquiv ..).2 <| (kernelIsKernel f.hom).ofIsoLimit <| Fork.ext <| .refl _ /-- The cokernel projection is itself a cokernel in the functor category. -/ noncomputable def cokerIsCokernel [HasCokernels C] : IsColimit (CokernelCofork.ofπ (coker.π C) (coker.condition C)) := evaluationJointlyReflectsColimits _ fun f ↦ (CokernelCofork.isColimitMapCoconeEquiv ..).2 <| (cokernelIsCokernel f.hom).ofIsoColimit <| Cofork.ext <| .refl _ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorCategory/Shapes/Pullbacks.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Pullbacks in functor categories We prove the isomorphism `(pullback f g).obj d ≅ pullback (f.app d) (g.app d)`. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {F G H : D ⥤ C} section Pullback variable [HasPullbacks C] /-- Evaluating a pullback amounts to taking the pullback of the evaluations. -/ noncomputable def pullbackObjIso (f : F ⟶ H) (g : G ⟶ H) (d : D) : (pullback f g).obj d ≅ pullback (f.app d) (g.app d) := limitObjIsoLimitCompEvaluation (cospan f g) d ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _) @[reassoc (attr := simp)] theorem pullbackObjIso_hom_comp_fst (f : F ⟶ H) (g : G ⟶ H) (d : D) : (pullbackObjIso f g d).hom ≫ pullback.fst (f.app d) (g.app d) = (pullback.fst f g).app d := by simp [pullbackObjIso] @[reassoc (attr := simp)] theorem pullbackObjIso_hom_comp_snd (f : F ⟶ H) (g : G ⟶ H) (d : D) : (pullbackObjIso f g d).hom ≫ pullback.snd (f.app d) (g.app d) = (pullback.snd f g).app d := by simp [pullbackObjIso] @[reassoc (attr := simp)] theorem pullbackObjIso_inv_comp_fst (f : F ⟶ H) (g : G ⟶ H) (d : D) : (pullbackObjIso f g d).inv ≫ (pullback.fst f g).app d = pullback.fst (f.app d) (g.app d) := by simp [pullbackObjIso] @[reassoc (attr := simp)] theorem pullbackObjIso_inv_comp_snd (f : F ⟶ H) (g : G ⟶ H) (d : D) : (pullbackObjIso f g d).inv ≫ (pullback.snd f g).app d = pullback.snd (f.app d) (g.app d) := by simp [pullbackObjIso] end Pullback section Pushout variable [HasPushouts C] /-- Evaluating a pushout amounts to taking the pushout of the evaluations. -/ noncomputable def pushoutObjIso (f : F ⟶ G) (g : F ⟶ H) (d : D) : (pushout f g).obj d ≅ pushout (f.app d) (g.app d) := colimitObjIsoColimitCompEvaluation (span f g) d ≪≫ HasColimit.isoOfNatIso (diagramIsoSpan _) @[reassoc (attr := simp)] theorem inl_comp_pushoutObjIso_hom (f : F ⟶ G) (g : F ⟶ H) (d : D) : (pushout.inl f g).app d ≫ (pushoutObjIso f g d).hom = pushout.inl (f.app d) (g.app d) := by simp [pushoutObjIso] @[reassoc (attr := simp)] theorem inr_comp_pushoutObjIso_hom (f : F ⟶ G) (g : F ⟶ H) (d : D) : (pushout.inr f g).app d ≫ (pushoutObjIso f g d).hom = pushout.inr (f.app d) (g.app d) := by simp [pushoutObjIso] @[reassoc (attr := simp)] theorem inl_comp_pushoutObjIso_inv (f : F ⟶ G) (g : F ⟶ H) (d : D) : pushout.inl (f.app d) (g.app d) ≫ (pushoutObjIso f g d).inv = (pushout.inl f g).app d := by simp [pushoutObjIso] @[reassoc (attr := simp)] theorem inr_comp_pushoutObjIso_inv (f : F ⟶ G) (g : F ⟶ H) (d : D) : pushout.inr (f.app d) (g.app d) ≫ (pushoutObjIso f g d).inv = (pushout.inr f g).app d := by simp [pushoutObjIso] end Pushout end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Shapes.lean
import Mathlib.CategoryTheory.Limits.Types.Coequalizers import Mathlib.CategoryTheory.Limits.Types.Coproducts import Mathlib.CategoryTheory.Limits.Types.Equalizers import Mathlib.CategoryTheory.Limits.Types.Multiequalizer import Mathlib.CategoryTheory.Limits.Types.Products import Mathlib.CategoryTheory.Limits.Types.Pullbacks import Mathlib.CategoryTheory.Limits.Types.Pushouts deprecated_module (since := "2025-11-04")
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Yoneda.lean
import Mathlib.CategoryTheory.Limits.Types.Limits /-! # Cones and limits In this file, we give the natural isomorphism between cones on `F` with cone point `X` and the type `lim Hom(X, F·)`, and similarly the natural isomorphism between cocones on `F` with cocone point `X` and the type `lim Hom(F·, X)`. -/ universe v u namespace CategoryTheory.Limits open Functor Opposite section variable {J C : Type*} [Category J] [Category C] /-- Sections of `F ⋙ coyoneda.obj (op X)` identify to natural transformations `(const J).obj X ⟶ F`. -/ @[simps] def compCoyonedaSectionsEquiv (F : J ⥤ C) (X : C) : (F ⋙ coyoneda.obj (op X)).sections ≃ ((const J).obj X ⟶ F) where toFun s := { app := fun j => s.val j naturality := fun j j' f => by dsimp rw [Category.id_comp] exact (s.property f).symm } invFun τ := ⟨τ.app, fun {j j'} f => by simpa using (τ.naturality f).symm⟩ /-- Sections of `F.op ⋙ yoneda.obj X` identify to natural transformations `F ⟶ (const J).obj X`. -/ @[simps] def opCompYonedaSectionsEquiv (F : J ⥤ C) (X : C) : (F.op ⋙ yoneda.obj X).sections ≃ (F ⟶ (const J).obj X) where toFun s := { app := fun j => s.val (op j) naturality := fun j j' f => by dsimp rw [Category.comp_id] exact (s.property f.op) } invFun τ := ⟨fun j => τ.app j.unop, fun {j j'} f => by simp [τ.naturality f.unop]⟩ /-- Sections of `F ⋙ yoneda.obj X` identify to natural transformations `(const J).obj X ⟶ F`. -/ @[simps] def compYonedaSectionsEquiv (F : J ⥤ Cᵒᵖ) (X : C) : (F ⋙ yoneda.obj X).sections ≃ ((const J).obj (op X) ⟶ F) where toFun s := { app := fun j => (s.val j).op naturality := fun j j' f => by dsimp rw [Category.id_comp] exact Quiver.Hom.unop_inj (s.property f).symm } invFun τ := ⟨fun j => (τ.app j).unop, fun {j j'} f => Quiver.Hom.op_inj (by simpa using (τ.naturality f).symm)⟩ end variable {J : Type v} [SmallCategory J] {C : Type u} [Category.{v} C] /-- A cone on `F` with cone point `X` is the same as an element of `lim Hom(X, F·)`. -/ @[simps!] noncomputable def limitCompCoyonedaIsoCone (F : J ⥤ C) (X : C) : limit (F ⋙ coyoneda.obj (op X)) ≅ ((const J).obj X ⟶ F) := ((Types.limitEquivSections _).trans (compCoyonedaSectionsEquiv F X)).toIso /-- A cone on `F` with cone point `X` is the same as an element of `lim Hom(X, F·)`, naturally in `X`. -/ @[simps!] noncomputable def coyonedaCompLimIsoCones (F : J ⥤ C) : coyoneda ⋙ (whiskeringLeft _ _ _).obj F ⋙ lim ≅ F.cones := NatIso.ofComponents (fun X => limitCompCoyonedaIsoCone F X.unop) variable (J) (C) in /-- A cone on `F` with cone point `X` is the same as an element of `lim Hom(X, F·)`, naturally in `F` and `X`. -/ @[simps!] noncomputable def whiskeringLimYonedaIsoCones : whiskeringLeft _ _ _ ⋙ (whiskeringRight _ _ _).obj lim ⋙ (whiskeringLeft _ _ _).obj coyoneda ≅ cones J C := NatIso.ofComponents coyonedaCompLimIsoCones /-- A cocone on `F` with cocone point `X` is the same as an element of `lim Hom(F·, X)`. -/ @[simps!] noncomputable def limitCompYonedaIsoCocone (F : J ⥤ C) (X : C) : limit (F.op ⋙ yoneda.obj X) ≅ (F ⟶ (const J).obj X) := ((Types.limitEquivSections _).trans (opCompYonedaSectionsEquiv F X)).toIso /-- A cocone on `F` with cocone point `X` is the same as an element of `lim Hom(F·, X)`, naturally in `X`. -/ @[simps!] noncomputable def yonedaCompLimIsoCocones (F : J ⥤ C) : yoneda ⋙ (whiskeringLeft _ _ _).obj F.op ⋙ lim ≅ F.cocones := NatIso.ofComponents (limitCompYonedaIsoCocone F) variable (J) (C) in /-- A cocone on `F` with cocone point `X` is the same as an element of `lim Hom(F·, X)`, naturally in `F` and `X`. -/ @[simps!] noncomputable def opHomCompWhiskeringLimYonedaIsoCocones : opHom _ _ ⋙ whiskeringLeft _ _ _ ⋙ (whiskeringRight _ _ _).obj lim ⋙ (whiskeringLeft _ _ _).obj yoneda ≅ cocones J C := NatIso.ofComponents (fun F => yonedaCompLimIsoCocones F.unop) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Pushouts.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Types.Colimits /-! # Pushouts in `Type` We describe the pushout of two maps `f : S ⟶ X₁` and `g : S ⟶ X₂` in the category of types at the quotient of `X₁ ⊕ X₂` by the equivalence relation generated by a relation. We also study the particular case when `f` is injective (in the file `CategoryTheory.Types.Monomorphisms`, it is deduced that monomorphisms are stable under cobase change in the category of types). -/ universe u namespace CategoryTheory.Limits.Types instance : HasPushouts.{u} (Type u) := hasPushouts_of_hasWidePushouts.{u} (Type u) section Pushout variable {S X₁ X₂ : Type u} (f : S ⟶ X₁) (g : S ⟶ X₂) /-- The pushout of two maps `f : S ⟶ X₁` and `g : S ⟶ X₂` is the quotient by the equivalence relation on `X₁ ⊕ X₂` generated by this relation. -/ inductive Pushout.Rel (f : S ⟶ X₁) (g : S ⟶ X₂) : X₁ ⊕ X₂ → X₁ ⊕ X₂ → Prop | inl_inr (s : S) : Pushout.Rel f g (Sum.inl (f s)) (Sum.inr (g s)) /-- Construction of the pushout in the category of types, as a quotient of `X₁ ⊕ X₂`. -/ def Pushout : Type u := _root_.Quot (Pushout.Rel f g) /-- In case `f : S ⟶ X₁` is a monomorphism, this relation is the equivalence relation generated by `Pushout.Rel f g`. -/ inductive Pushout.Rel' : X₁ ⊕ X₂ → X₁ ⊕ X₂ → Prop | refl (x : X₁ ⊕ X₂) : Rel' x x | inl_inl (x₀ y₀ : S) (h : g x₀ = g y₀) : Rel' (Sum.inl (f x₀)) (Sum.inl (f y₀)) | inl_inr (s : S) : Rel' (Sum.inl (f s)) (Sum.inr (g s)) | inr_inl (s : S) : Rel' (Sum.inr (g s)) (Sum.inl (f s)) /-- The quotient of `X₁ ⊕ X₂` by the relation `PushoutRel' f g`. -/ def Pushout' : Type u := _root_.Quot (Pushout.Rel' f g) namespace Pushout /-- The left inclusion in the constructed pushout `Pushout f g`. -/ @[simp] def inl : X₁ ⟶ Pushout f g := fun x => Quot.mk _ (Sum.inl x) /-- The right inclusion in the constructed pushout `Pushout f g`. -/ @[simp] def inr : X₂ ⟶ Pushout f g := fun x => Quot.mk _ (Sum.inr x) lemma condition : f ≫ inl f g = g ≫ inr f g := by ext x exact Quot.sound (Rel.inl_inr x) /-- The constructed pushout cocone in the category of types. -/ @[simps!] def cocone : PushoutCocone f g := PushoutCocone.mk _ _ (condition f g) /-- The cocone `cocone f g` is colimit. -/ def isColimitCocone : IsColimit (cocone f g) := PushoutCocone.IsColimit.mk _ (fun s => Quot.lift (fun x => match x with | Sum.inl x₁ => s.inl x₁ | Sum.inr x₂ => s.inr x₂) (by rintro _ _ ⟨t⟩ exact congr_fun s.condition t)) (fun _ => rfl) (fun _ => rfl) (fun s m h₁ h₂ => by ext ⟨x₁ | x₂⟩ · exact congr_fun h₁ x₁ · exact congr_fun h₂ x₂) @[simp] lemma inl_rel'_inl_iff (x₁ y₁ : X₁) : Rel' f g (Sum.inl x₁) (Sum.inl y₁) ↔ x₁ = y₁ ∨ ∃ (x₀ y₀ : S) (_ : g x₀ = g y₀), x₁ = f x₀ ∧ y₁ = f y₀ := by constructor · rintro (_ | ⟨_, _, h⟩) · exact Or.inl rfl · exact Or.inr ⟨_, _, h, rfl, rfl⟩ · rintro (rfl | ⟨_, _, h, rfl, rfl⟩) · apply Rel'.refl · exact Rel'.inl_inl _ _ h @[simp] lemma inl_rel'_inr_iff (x₁ : X₁) (x₂ : X₂) : Rel' f g (Sum.inl x₁) (Sum.inr x₂) ↔ ∃ (s : S), x₁ = f s ∧ x₂ = g s := by constructor · rintro ⟨_⟩ exact ⟨_, rfl, rfl⟩ · rintro ⟨s, rfl, rfl⟩ exact Rel'.inl_inr _ @[simp] lemma inr_rel'_inr_iff (x₂ y₂ : X₂) : Rel' f g (Sum.inr x₂) (Sum.inr y₂) ↔ x₂ = y₂ := by constructor · rintro ⟨_⟩ rfl · rintro rfl apply Rel'.refl variable {f g} lemma Rel'.symm {x y : X₁ ⊕ X₂} (h : Rel' f g x y) : Rel' f g y x := by obtain _ | ⟨_, _, h⟩ | _ | _ := h · apply Rel'.refl · exact Rel'.inl_inl _ _ h.symm · exact Rel'.inr_inl _ · exact Rel'.inl_inr _ variable (f g) lemma equivalence_rel' [Mono f] : _root_.Equivalence (Rel' f g) where refl := Rel'.refl symm h := h.symm trans := by rintro x y z (_ | ⟨_, _, h⟩ | s | _) hyz · exact hyz · obtain z₁ | z₂ := z · rw [inl_rel'_inl_iff] at hyz obtain rfl | ⟨_, _, h', h'', rfl⟩ := hyz · exact Rel'.inl_inl _ _ h · obtain rfl := (mono_iff_injective f).1 inferInstance h'' exact Rel'.inl_inl _ _ (h.trans h') · rw [inl_rel'_inr_iff] at hyz obtain ⟨s, hs, rfl⟩ := hyz obtain rfl := (mono_iff_injective f).1 inferInstance hs rw [← h] apply Rel'.inl_inr · obtain z₁ | z₂ := z · replace hyz := hyz.symm rw [inl_rel'_inr_iff] at hyz obtain ⟨s', rfl, hs'⟩ := hyz exact Rel'.inl_inl _ _ hs' · rw [inr_rel'_inr_iff] at hyz subst hyz apply Rel'.inl_inr · obtain z₁ | z₂ := z · rw [inl_rel'_inl_iff] at hyz obtain rfl | ⟨_, _, h, h', rfl⟩ := hyz · apply Rel'.inr_inl · obtain rfl := (mono_iff_injective f).1 inferInstance h' rw [h] apply Rel'.inr_inl · rw [inl_rel'_inr_iff] at hyz obtain ⟨s, hs, rfl⟩ := hyz obtain rfl := (mono_iff_injective f).1 inferInstance hs apply Rel'.refl /-- The obvious equivalence `Pushout f g ≃ Pushout' f g`. -/ def equivPushout' : Pushout f g ≃ Pushout' f g where toFun := Quot.lift (Quot.mk _) (by rintro _ _ ⟨⟩ apply Quot.sound apply Rel'.inl_inr) invFun := Quot.lift (Quot.mk _) (by rintro a b (_ | ⟨x₀, y₀, h⟩ | _ | _) · rfl · have h₀ : Rel f g _ _ := Rel.inl_inr x₀ rw [Quot.sound h₀, h] symm apply Quot.sound apply Rel.inl_inr · apply Quot.sound apply Rel.inl_inr · symm apply Quot.sound apply Rel.inl_inr) left_inv := by rintro ⟨x⟩; rfl right_inv := by rintro ⟨x⟩; rfl lemma quot_mk_eq_iff [Mono f] (a b : X₁ ⊕ X₂) : (Quot.mk _ a : Pushout f g) = Quot.mk _ b ↔ Rel' f g a b := by rw [← (equivalence_rel' f g).quot_mk_eq_iff] exact ⟨fun h => (equivPushout' f g).symm.injective h, fun h => (equivPushout' f g).injective h⟩ lemma inl_eq_inr_iff [Mono f] (x₁ : X₁) (x₂ : X₂) : (inl f g x₁ = inr f g x₂) ↔ ∃ (s : S), f s = x₁ ∧ g s = x₂ := by refine (Pushout.quot_mk_eq_iff f g (Sum.inl x₁) (Sum.inr x₂)).trans ?_ constructor · rintro ⟨⟩ exact ⟨_, rfl, rfl⟩ · rintro ⟨s, rfl, rfl⟩ apply Rel'.inl_inr instance mono_inr [Mono f] : Mono (inr f g) := by rw [mono_iff_injective] intro x₂ y₂ h simpa using (Pushout.quot_mk_eq_iff f g (Sum.inr x₂) (Sum.inr y₂)).1 h end Pushout variable {f g} lemma pushoutCocone_inl_eq_inr_imp_of_iso {c c' : PushoutCocone f g} (e : c ≅ c') (x₁ : X₁) (x₂ : X₂) (h : c.inl x₁ = c.inr x₂) : c'.inl x₁ = c'.inr x₂ := by convert congr_arg e.hom.hom h · exact congr_fun (e.hom.w WalkingSpan.left).symm x₁ · exact congr_fun (e.hom.w WalkingSpan.right).symm x₂ lemma pushoutCocone_inl_eq_inr_iff_of_iso {c c' : PushoutCocone f g} (e : c ≅ c') (x₁ : X₁) (x₂ : X₂) : c.inl x₁ = c.inr x₂ ↔ c'.inl x₁ = c'.inr x₂ := by constructor · apply pushoutCocone_inl_eq_inr_imp_of_iso e · apply pushoutCocone_inl_eq_inr_imp_of_iso e.symm lemma pushoutCocone_inl_eq_inr_iff_of_isColimit {c : PushoutCocone f g} (hc : IsColimit c) (h₁ : Function.Injective f) (x₁ : X₁) (x₂ : X₂) : c.inl x₁ = c.inr x₂ ↔ ∃ (s : S), f s = x₁ ∧ g s = x₂ := by rw [pushoutCocone_inl_eq_inr_iff_of_iso (Cocones.ext (IsColimit.coconePointUniqueUpToIso hc (Pushout.isColimitCocone f g)) (by simp))] have := (mono_iff_injective f).2 h₁ apply Pushout.inl_eq_inr_iff lemma pushoutCocone_inr_mono_of_isColimit {c : PushoutCocone f g} (hc : IsColimit c) [Mono f] : Mono c.inr := by change Mono ((Pushout.inr f g) ≫ ((Cocones.forget _).mapIso (Cocones.ext (IsColimit.coconePointUniqueUpToIso hc (Pushout.isColimitCocone f g)) (by simp))).inv) infer_instance lemma pushoutCocone_inr_injective_of_isColimit {c : PushoutCocone f g} (hc : IsColimit c) (h₁ : Function.Injective f) : Function.Injective c.inr := by rw [← mono_iff_injective] at h₁ ⊢ exact pushoutCocone_inr_mono_of_isColimit hc instance mono_inl [Mono g] : Mono (Pushout.inl f g) := pushoutCocone_inr_mono_of_isColimit (PushoutCocone.flipIsColimit (Pushout.isColimitCocone f g)) instance [Mono f] : Mono (pushout.inr f g) := (pushoutCocone_inr_mono_of_isColimit (pushoutIsPushout f g):) instance [Mono g] : Mono (pushout.inl f g) := pushoutCocone_inr_mono_of_isColimit (PushoutCocone.flipIsColimit (pushoutIsPushout f g)) end Pushout end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Products.lean
import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Products in `Type` We describe arbitrary products in the category of types, as well as binary products, and the terminal object. -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits.Types example : HasProducts.{v} (Type v) := inferInstance example [UnivLE.{v, u}] : HasProducts.{v} (Type u) := inferInstance -- This shortcut instance is required in `Mathlib/CategoryTheory/Closed/Types.lean`, -- although I don't understand why, and wish it wasn't. instance : HasProducts.{v} (Type v) := inferInstance /-- A restatement of `Types.Limit.lift_π_apply` that uses `Pi.π` and `Pi.lift`. -/ -- The increased `@[simp]` priority here results in a minor speed up in -- `Mathlib/CategoryTheory/Sites/EqualizerSheafCondition.lean`. @[simp 1001] theorem pi_lift_π_apply {β : Type v} [Small.{u} β] (f : β → Type u) {P : Type u} (s : ∀ b, P ⟶ f b) (b : β) (x : P) : (Pi.π f b : (piObj f) → f b) (@Pi.lift β _ _ f _ P s x) = s b x := congr_fun (limit.lift_π (Fan.mk P s) ⟨b⟩) x /-- A restatement of `Types.Limit.lift_π_apply` that uses `Pi.π` and `Pi.lift`, with specialized universes. -/ theorem pi_lift_π_apply' {β : Type v} (f : β → Type v) {P : Type v} (s : ∀ b, P ⟶ f b) (b : β) (x : P) : (Pi.π f b : (piObj f) → f b) (@Pi.lift β _ _ f _ P s x) = s b x := by simp /-- A restatement of `Types.Limit.map_π_apply` that uses `Pi.π` and `Pi.map`. -/ -- Not `@[simp]` since `simp` can prove it. theorem pi_map_π_apply {β : Type v} [Small.{u} β] {f g : β → Type u} (α : ∀ j, f j ⟶ g j) (b : β) (x) : (Pi.π g b : ∏ᶜ g → g b) (Pi.map α x) = α b ((Pi.π f b : ∏ᶜ f → f b) x) := Limit.map_π_apply.{v, u} _ _ _ /-- A restatement of `Types.Limit.map_π_apply` that uses `Pi.π` and `Pi.map`, with specialized universes. -/ theorem pi_map_π_apply' {β : Type v} {f g : β → Type v} (α : ∀ j, f j ⟶ g j) (b : β) (x) : (Pi.π g b : ∏ᶜ g → g b) (Pi.map α x) = α b ((Pi.π f b : ∏ᶜ f → f b) x) := by simp /-- The category of types has `PUnit` as a terminal object. -/ def terminalLimitCone : Limits.LimitCone (Functor.empty (Type u)) where -- Porting note: tidy was able to fill the structure automatically cone := { pt := PUnit π := (Functor.uniqueFromEmpty _).hom } isLimit := { lift := fun _ _ => PUnit.unit fac := fun _ => by rintro ⟨⟨⟩⟩ } /-- The terminal object in `Type u` is `PUnit`. -/ noncomputable def terminalIso : ⊤_ Type u ≅ PUnit := limit.isoLimitCone terminalLimitCone.{u, 0} /-- The terminal object in `Type u` is `PUnit`. -/ noncomputable def isTerminalPunit : IsTerminal (PUnit : Type u) := terminalIsTerminal.ofIso terminalIso noncomputable instance : Inhabited (⊤_ (Type u)) := ⟨@terminal.from (Type u) _ _ (ULift (Fin 1)) (ULift.up 0)⟩ instance : Subsingleton (⊤_ (Type u)) := ⟨fun a b => congr_fun (@Subsingleton.elim (_ ⟶ ⊤_ (Type u)) _ (fun _ => a) (fun _ => b)) (ULift.up (0 : Fin 1))⟩ noncomputable instance : Unique (⊤_ (Type u)) := Unique.mk' _ /-- A type is terminal if and only if it contains exactly one element. -/ noncomputable def isTerminalEquivUnique (X : Type u) : IsTerminal X ≃ Unique X := equivOfSubsingletonOfSubsingleton (fun h => ((Iso.toEquiv (terminalIsoIsTerminal h).symm).unique)) (fun _ => IsTerminal.ofIso terminalIsTerminal (Equiv.toIso (Equiv.ofUnique _ _))) /-- A type is terminal if and only if it is isomorphic to `PUnit`. -/ noncomputable def isTerminalEquivIsoPUnit (X : Type u) : IsTerminal X ≃ (X ≅ PUnit) := by calc IsTerminal X ≃ Unique X := isTerminalEquivUnique _ _ ≃ (X ≃ PUnit.{u + 1}) := uniqueEquivEquivUnique _ _ _ ≃ (X ≅ PUnit) := equivEquivIso open CategoryTheory.Limits.WalkingPair -- We manually generate the other projection lemmas since the simp-normal form for the legs is -- otherwise not created correctly. /-- The product type `X × Y` forms a cone for the binary product of `X` and `Y`. -/ @[simps! pt] def binaryProductCone (X Y : Type u) : BinaryFan X Y := BinaryFan.mk _root_.Prod.fst _root_.Prod.snd @[simp] theorem binaryProductCone_fst (X Y : Type u) : (binaryProductCone X Y).fst = _root_.Prod.fst := rfl @[simp] theorem binaryProductCone_snd (X Y : Type u) : (binaryProductCone X Y).snd = _root_.Prod.snd := rfl /-- The product type `X × Y` is a binary product for `X` and `Y`. -/ @[simps] def binaryProductLimit (X Y : Type u) : IsLimit (binaryProductCone X Y) where lift (s : BinaryFan X Y) x := (s.fst x, s.snd x) fac _ j := Discrete.recOn j fun j => WalkingPair.casesOn j rfl rfl uniq _ _ w := funext fun x => Prod.ext (congr_fun (w ⟨left⟩) x) (congr_fun (w ⟨right⟩) x) /-- The category of types has `X × Y`, the usual Cartesian product, as the binary product of `X` and `Y`. -/ @[simps] def binaryProductLimitCone (X Y : Type u) : Limits.LimitCone (pair X Y) := ⟨_, binaryProductLimit X Y⟩ /-- The categorical binary product in `Type u` is Cartesian product. -/ noncomputable def binaryProductIso (X Y : Type u) : Limits.prod X Y ≅ X × Y := limit.isoLimitCone (binaryProductLimitCone X Y) @[elementwise (attr := simp)] theorem binaryProductIso_hom_comp_fst (X Y : Type u) : (binaryProductIso X Y).hom ≫ _root_.Prod.fst = Limits.prod.fst := limit.isoLimitCone_hom_π (binaryProductLimitCone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryProductIso_hom_comp_snd (X Y : Type u) : (binaryProductIso X Y).hom ≫ _root_.Prod.snd = Limits.prod.snd := limit.isoLimitCone_hom_π (binaryProductLimitCone X Y) ⟨WalkingPair.right⟩ @[elementwise (attr := simp)] theorem binaryProductIso_inv_comp_fst (X Y : Type u) : (binaryProductIso X Y).inv ≫ Limits.prod.fst = _root_.Prod.fst := limit.isoLimitCone_inv_π (binaryProductLimitCone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryProductIso_inv_comp_snd (X Y : Type u) : (binaryProductIso X Y).inv ≫ Limits.prod.snd = _root_.Prod.snd := limit.isoLimitCone_inv_π (binaryProductLimitCone X Y) ⟨WalkingPair.right⟩ /-- The functor which sends `X, Y` to the product type `X × Y`. -/ @[simps] def binaryProductFunctor : Type u ⥤ Type u ⥤ Type u where obj X := { obj := fun Y => X × Y map := fun { _ Y₂} f => (binaryProductLimit X Y₂).lift (BinaryFan.mk _root_.Prod.fst (_root_.Prod.snd ≫ f)) } map {X₁ X₂} f := { app := fun Y => (binaryProductLimit X₂ Y).lift (BinaryFan.mk (_root_.Prod.fst ≫ f) _root_.Prod.snd) } /-- The product functor given by the instance `HasBinaryProducts (Type u)` is isomorphic to the explicit binary product functor given by the product type. -/ noncomputable def binaryProductIsoProd : binaryProductFunctor ≅ (prod.functor : Type u ⥤ _) := by refine NatIso.ofComponents (fun X => ?_) (fun _ => ?_) · refine NatIso.ofComponents (fun Y => ?_) (fun _ => ?_) · exact ((limit.isLimit _).conePointUniqueUpToIso (binaryProductLimit X Y)).symm · apply Limits.prod.hom_ext <;> simp <;> rfl · ext : 2 apply Limits.prod.hom_ext <;> simp <;> rfl /-- The category of types has `Π j, f j` as the product of a type family `f : J → Type max v u`. -/ def productLimitCone {J : Type v} (F : J → Type max v u) : Limits.LimitCone (Discrete.functor F) where cone := { pt := ∀ j, F j π := Discrete.natTrans (fun ⟨j⟩ f => f j) } isLimit := { lift := fun s x j => s.π.app ⟨j⟩ x uniq := fun _ _ w => funext fun x => funext fun j => (congr_fun (w ⟨j⟩) x :) } /-- The categorical product in `Type max v u` is the type-theoretic product `Π j, F j`. -/ noncomputable def productIso {J : Type v} (F : J → Type max v u) : ∏ᶜ F ≅ ∀ j, F j := limit.isoLimitCone (productLimitCone.{v, u} F) @[simp, elementwise (attr := simp)] theorem productIso_hom_comp_eval {J : Type v} (F : J → Type max v u) (j : J) : ((productIso.{v, u} F).hom ≫ fun f => f j) = Pi.π F j := rfl @[elementwise (attr := simp)] theorem productIso_inv_comp_π {J : Type v} (F : J → Type max v u) (j : J) : (productIso.{v, u} F).inv ≫ Pi.π F j = fun f => f j := limit.isoLimitCone_inv_π (productLimitCone.{v, u} F) ⟨j⟩ namespace Small variable {J : Type v} (F : J → Type u) [Small.{u} J] /-- A variant of `productLimitCone` using a `Small` hypothesis rather than a function to `Type`. -/ noncomputable def productLimitCone : Limits.LimitCone (Discrete.functor F) where cone := { pt := Shrink (∀ j, F j) π := Discrete.natTrans (fun ⟨j⟩ f => (equivShrink (∀ j, F j)).symm f j) } isLimit := have : Small.{u} (∀ j, F j) := inferInstance { lift := fun s x => (equivShrink _) (fun j => s.π.app ⟨j⟩ x) uniq := fun s m w => funext fun x => Shrink.ext <| funext fun j => by simpa using (congr_fun (w ⟨j⟩) x :) } /-- The categorical product in `Type u` indexed in `Type v` is the type-theoretic product `Π j, F j`, after shrinking back to `Type u`. -/ noncomputable def productIso : (∏ᶜ F : Type u) ≅ Shrink.{u} (∀ j, F j) := limit.isoLimitCone (productLimitCone.{v, u} F) @[elementwise (attr := simp)] theorem productIso_hom_comp_eval (j : J) : ((productIso.{v, u} F).hom ≫ fun f => (equivShrink (∀ j, F j)).symm f j) = Pi.π F j := limit.isoLimitCone_hom_π (productLimitCone.{v, u} F) ⟨j⟩ @[elementwise (attr := simp)] theorem productIso_inv_comp_π (j : J) : (productIso.{v, u} F).inv ≫ Pi.π F j = fun f => ((equivShrink (∀ j, F j)).symm f) j := limit.isoLimitCone_inv_π (productLimitCone.{v, u} F) ⟨j⟩ end Small end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Filtered.lean
import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Filtered.Basic /-! # Filtered colimits in the category of types. We give a characterisation of the equality in filtered colimits in `Type` as a lemma `CategoryTheory.Limits.Types.FilteredColimit.colimit_eq_iff`: `colimit.ι F i xi = colimit.ι F j xj ↔ ∃ k (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj`. -/ open CategoryTheory CategoryTheory.Limits universe v u w namespace CategoryTheory.Limits.Types.FilteredColimit variable {J : Type v} [Category.{w} J] (F : J ⥤ Type u) attribute [local instance] small_quot_of_hasColimit /- For filtered colimits of types, we can give an explicit description of the equivalence relation generated by the relation used to form the colimit. -/ /-- An alternative relation on `Σ j, F.obj j`, which generates the same equivalence relation as we use to define the colimit in `Type` above, but that is more convenient when working with filtered colimits. Elements in `F.obj j` and `F.obj j'` are equivalent if there is some `k : J` to the right where their images are equal. -/ protected def Rel (x y : Σ j, F.obj j) : Prop := ∃ (k : _) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2 theorem rel_of_colimitTypeRel (x y : Σ j, F.obj j) : F.ColimitTypeRel x y → FilteredColimit.Rel.{v, u} F x y := fun ⟨f, h⟩ => ⟨y.1, f, 𝟙 y.1, by rw [← h, FunctorToTypes.map_id_apply]⟩ @[deprecated (since := "2025-06-22")] alias rel_of_quot_rel := rel_of_colimitTypeRel theorem eqvGen_colimitTypeRel_of_rel (x y : Σ j, F.obj j) : FilteredColimit.Rel.{v, u} F x y → Relation.EqvGen F.ColimitTypeRel x y := fun ⟨k, f, g, h⟩ => by refine Relation.EqvGen.trans _ ⟨k, F.map f x.2⟩ _ ?_ ?_ · exact (Relation.EqvGen.rel _ _ ⟨f, rfl⟩) · exact (Relation.EqvGen.symm _ _ (Relation.EqvGen.rel _ _ ⟨g, h⟩)) @[deprecated (since := "2025-06-22")] alias eqvGen_quot_rel_of_rel := eqvGen_colimitTypeRel_of_rel /-- Recognizing filtered colimits of types. -/ noncomputable def isColimitOf (t : Cocone F) (hsurj : ∀ x : t.pt, ∃ i xi, x = t.ι.app i xi) (hinj : ∀ i j xi xj, t.ι.app i xi = t.ι.app j xj → ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj) : IsColimit t := by let α : t.pt → J := fun x => (hsurj x).choose let f : ∀ (x : t.pt), F.obj (α x) := fun x => (hsurj x).choose_spec.choose have hf : ∀ (x : t.pt), x = t.ι.app _ (f x) := fun x => (hsurj x).choose_spec.choose_spec exact { desc := fun s x => s.ι.app _ (f x) fac := fun s j => by ext y obtain ⟨k, l, g, eq⟩ := hinj _ _ _ _ (hf (t.ι.app j y)) have h := congr_fun (s.ι.naturality g) (f (t.ι.app j y)) have h' := congr_fun (s.ι.naturality l) y dsimp at h h' ⊢ rw [← h, ← eq, h'] uniq := fun s m hm => by ext x dsimp nth_rw 1 [hf x] rw [← hm, types_comp_apply] } variable [IsFilteredOrEmpty J] /-- Recognizing filtered colimits of types. The injectivity condition here is slightly easier to check as compared to `isColimitOf`. -/ noncomputable def isColimitOf' (t : Cocone F) (hsurj : ∀ x : t.pt, ∃ i xi, x = t.ι.app i xi) (hinj : ∀ i x y, t.ι.app i x = t.ι.app i y → ∃ (k : _) (f : i ⟶ k), F.map f x = F.map f y) : IsColimit t := isColimitOf _ _ hsurj (fun i j xi xj h ↦ by obtain ⟨k, g, hg⟩ := hinj (IsFiltered.max i j) (F.map (IsFiltered.leftToMax i j) xi) (F.map (IsFiltered.rightToMax i j) xj) (by simp [FunctorToTypes.naturality, h]) exact ⟨k, IsFiltered.leftToMax i j ≫ g, IsFiltered.rightToMax i j ≫ g, by simpa using hg⟩) protected theorem rel_equiv : _root_.Equivalence (FilteredColimit.Rel.{v, u} F) where refl x := ⟨x.1, 𝟙 x.1, 𝟙 x.1, rfl⟩ symm := fun ⟨k, f, g, h⟩ => ⟨k, g, f, h.symm⟩ trans {x y z} := fun ⟨k, f, g, h⟩ ⟨k', f', g', h'⟩ => let ⟨l, fl, gl, _⟩ := IsFilteredOrEmpty.cocone_objs k k' let ⟨m, n, hn⟩ := IsFilteredOrEmpty.cocone_maps (g ≫ fl) (f' ≫ gl) ⟨m, f ≫ fl ≫ n, g' ≫ gl ≫ n, calc F.map (f ≫ fl ≫ n) x.2 = F.map (fl ≫ n) (F.map f x.2) := by simp _ = F.map (fl ≫ n) (F.map g y.2) := by rw [h] _ = F.map ((g ≫ fl) ≫ n) y.2 := by simp _ = F.map ((f' ≫ gl) ≫ n) y.2 := by rw [hn] _ = F.map (gl ≫ n) (F.map f' y.2) := by simp _ = F.map (gl ≫ n) (F.map g' z.2) := by rw [h'] _ = F.map (g' ≫ gl ≫ n) z.2 := by simp⟩ protected theorem rel_eq_eqvGen_colimitTypeRel : FilteredColimit.Rel.{v, u} F = Relation.EqvGen F.ColimitTypeRel := by ext ⟨j, x⟩ ⟨j', y⟩ constructor · apply eqvGen_colimitTypeRel_of_rel · rw [← (FilteredColimit.rel_equiv F).eqvGen_iff] exact Relation.EqvGen.mono (rel_of_colimitTypeRel F) @[deprecated (since := "2025-06-22")] alias rel_eq_eqvGen_quot_rel := FilteredColimit.rel_eq_eqvGen_colimitTypeRel theorem colimit_eq_iff_aux [HasColimit F] {i j : J} {xi : F.obj i} {xj : F.obj j} : (colimitCocone F).ι.app i xi = (colimitCocone F).ι.app j xj ↔ FilteredColimit.Rel.{v, u} F ⟨i, xi⟩ ⟨j, xj⟩ := by dsimp rw [← (equivShrink _).symm.injective.eq_iff, Equiv.symm_apply_apply, Equiv.symm_apply_apply, Functor.ιColimitType_eq_iff, FilteredColimit.rel_eq_eqvGen_colimitTypeRel] theorem isColimit_eq_iff {t : Cocone F} (ht : IsColimit t) {i j : J} {xi : F.obj i} {xj : F.obj j} : t.ι.app i xi = t.ι.app j xj ↔ ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj := by have : HasColimit F := ⟨_, ht⟩ refine Iff.trans ?_ (colimit_eq_iff_aux F) rw [← (IsColimit.coconePointUniqueUpToIso ht (colimitCoconeIsColimit F)).toEquiv.injective.eq_iff] convert Iff.rfl · exact (congrFun (IsColimit.comp_coconePointUniqueUpToIso_hom ht (colimitCoconeIsColimit F) _) xi).symm · exact (congrFun (IsColimit.comp_coconePointUniqueUpToIso_hom ht (colimitCoconeIsColimit F) _) xj).symm variable {F} in theorem isColimit_eq_iff' {t : Cocone F} (ht : IsColimit t) {i : J} (x y : F.obj i) : t.ι.app i x = t.ι.app i y ↔ ∃ (j : _) (f : i ⟶ j), F.map f x = F.map f y := by rw [isColimit_eq_iff _ ht] constructor · rintro ⟨k, f, g, h⟩ refine ⟨IsFiltered.coeq f g, f ≫ IsFiltered.coeqHom f g, ?_⟩ conv_rhs => rw [IsFiltered.coeq_condition] simp only [FunctorToTypes.map_comp_apply, h] · rintro ⟨j, f, h⟩ exact ⟨j, f, f, h⟩ theorem colimit_eq_iff [HasColimit F] {i j : J} {xi : F.obj i} {xj : F.obj j} : colimit.ι F i xi = colimit.ι F j xj ↔ ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj := isColimit_eq_iff _ (colimit.isColimit F) open IsFiltered in variable {F} in lemma jointly_surjective_of_isColimit₂ {t : Cocone F} (ht : IsColimit t) (x₁ x₂ : t.pt) : ∃ (j : J) (x₁' x₂' : F.obj j), t.ι.app j x₁' = x₁ ∧ t.ι.app j x₂' = x₂ := by obtain ⟨j₁, x₁, rfl⟩ := Types.jointly_surjective_of_isColimit ht x₁ obtain ⟨j₂, x₂, rfl⟩ := Types.jointly_surjective_of_isColimit ht x₂ exact ⟨max j₁ j₂, F.map (leftToMax _ _) x₁, F.map (rightToMax _ _) x₂, congr_fun (t.w (leftToMax j₁ j₂)) x₁, congr_fun (t.w (rightToMax j₁ j₂)) x₂⟩ end CategoryTheory.Limits.Types.FilteredColimit
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/ColimitType.lean
import Mathlib.CategoryTheory.Functor.Basic import Mathlib.CategoryTheory.Types.Basic /-! # The colimit type of a functor to types Given a category `J` (with `J : Type u` and `[Category.{v} J]`) and a functor `F : J ⥤ Type w₀`, we introduce a type `F.ColimitType : Type (max u w₀)`, which satisfies a certain universal property of the colimit: it is defined as a suitable quotient of `Σ j, F.obj j`. This universal property is not expressed in a categorical way (as in general `Type (max u w₀)` is not the same as `Type u`). We also introduce a notion of cocone of `F : J ⥤ Type w₀`, this is `F.CoconeTypes`, or more precisely `Functor.CoconeTypes.{w₁} F`, which consists of a candidate colimit type for `F` which is in `Type w₁` (in case `w₁ = w₀`, we shall show this is the same as the data of `c : Cocone F` in the categorical sense). Given `c : F.CoconeTypes`, we also introduce a property `c.IsColimit` which says that the canonical map `F.ColimitType → c.pt` is a bijection, and we shall show (TODO) that when `w₁ = w₀`, it is equivalent to saying that the corresponding cocone in a categorical sense is a colimit. ## TODO * refactor `DirectedSystem` and the construction of colimits in `Type` by using `Functor.ColimitType`. * add a similar API for limits in `Type`? -/ universe w₃ w₂ w₁ w₀ w₀' v u assert_not_exists CategoryTheory.Limits.Cocone namespace CategoryTheory variable {J : Type u} [Category.{v} J] namespace Functor variable (F : J ⥤ Type w₀) /-- Given a functor `F : J ⥤ Type w₀`, this is a "cocone" of `F` where we allow the point `pt` to be in a different universe than `w`. -/ structure CoconeTypes where /-- the point of the cocone -/ pt : Type w₁ /-- a family of maps to `pt` -/ ι (j : J) : F.obj j → pt ι_naturality {j j' : J} (f : j ⟶ j') : (ι j').comp (F.map f) = ι j := by aesop namespace CoconeTypes attribute [simp] ι_naturality variable {F} @[simp] lemma ι_naturality_apply (c : CoconeTypes.{w₁} F) {j j' : J} (f : j ⟶ j') (x : F.obj j) : c.ι j' (F.map f x) = c.ι j x := congr_fun (c.ι_naturality f) x /-- Given `c : F.CoconeTypes` and a map `φ : c.pt → T`, this is the cocone for `F` obtained by postcomposition with `φ`. -/ @[simps -fullyApplied] def postcomp (c : CoconeTypes.{w₁} F) {T : Type w₂} (φ : c.pt → T) : F.CoconeTypes where pt := T ι j := φ.comp (c.ι j) /-- The cocone for `G : J ⥤ Type w₀'` that is deduced from a cocone for `F : J ⥤ Type w₀` and a natural map `G.obj j → F.obj j` for all `j : J`. -/ @[simps -fullyApplied] def precompose (c : CoconeTypes.{w₁} F) {G : J ⥤ Type w₀'} (app : ∀ j, G.obj j → F.obj j) (naturality : ∀ {j j'} (f : j ⟶ j'), app j' ∘ G.map f = F.map f ∘ app j) : CoconeTypes.{w₁} G where pt := c.pt ι j := c.ι j ∘ app j ι_naturality f := by rw [Function.comp_assoc, naturality, ← Function.comp_assoc, ι_naturality] /-- Given `F : J ⥤ w₀`, `c : F.CoconeTypes` and `G : J' ⥤ J`, this is the induced cocone in `(G ⋙ F).CoconeTypes`. -/ @[simps] def precomp (c : CoconeTypes.{w₁} F) {J' : Type*} [Category J'] (G : J' ⥤ J) : CoconeTypes.{w₁} (G ⋙ F) where pt := c.pt ι _ := c.ι _ end CoconeTypes /-- Given `F : J ⥤ Type w₀`, this is the relation `Σ j, F.obj j` which generates an equivalence relation such that the quotient identifies to the colimit type of `F`. -/ def ColimitTypeRel : (Σ j, F.obj j) → (Σ j, F.obj j) → Prop := fun p p' ↦ ∃ f : p.1 ⟶ p'.1, p'.2 = F.map f p.2 /-- The colimit type of a functor `F : J ⥤ Type w₀`. (It may not be in `Type w₀`.) -/ def ColimitType : Type (max u w₀) := Quot F.ColimitTypeRel /-- The canonical maps `F.obj j → F.ColimitType`. -/ def ιColimitType (j : J) (x : F.obj j) : F.ColimitType := Quot.mk _ ⟨j, x⟩ lemma ιColimitType_eq_iff {j j' : J} (x : F.obj j) (y : F.obj j') : F.ιColimitType j x = F.ιColimitType j' y ↔ Relation.EqvGen F.ColimitTypeRel ⟨j, x⟩ ⟨ j', y⟩ := Quot.eq lemma ιColimitType_jointly_surjective (t : F.ColimitType) : ∃ j x, F.ιColimitType j x = t := by obtain ⟨_, _⟩ := t exact ⟨_, _, rfl⟩ @[simp] lemma ιColimitType_map {j j' : J} (f : j ⟶ j') (x : F.obj j) : F.ιColimitType j' (F.map f x) = F.ιColimitType j x := (Quot.sound ⟨f, rfl⟩).symm /-- The cocone corresponding to `F.ColimitType`. -/ @[simps -fullyApplied] def coconeTypes : F.CoconeTypes where pt := F.ColimitType ι j := F.ιColimitType j /-- An heterogeneous universe version of the universal property of the colimit is satisfied by `F.ColimitType` together the maps `F.ιColimitType j`. -/ def descColimitType (c : F.CoconeTypes) : F.ColimitType → c.pt := Quot.lift (fun ⟨j, x⟩ ↦ c.ι j x) (by rintro _ _ ⟨_, _⟩; aesop) @[simp] lemma descColimitType_comp_ι (c : F.CoconeTypes) (j : J) : (F.descColimitType c).comp (F.ιColimitType j) = c.ι j := rfl @[simp] lemma descColimitType_ιColimitType_apply (c : F.CoconeTypes) (j : J) (x : F.obj j) : F.descColimitType c (F.ιColimitType j x) = c.ι j x := rfl namespace CoconeTypes variable {F} (c : CoconeTypes.{w₁} F) lemma descColimitType_surjective_iff : Function.Surjective (F.descColimitType c) ↔ ∀ (z : c.pt), ∃ (i : J) (x : F.obj i), c.ι i x = z := by constructor · intro h z obtain ⟨⟨i, x⟩, rfl⟩ := h z exact ⟨i, x, rfl⟩ · intro h z obtain ⟨i, x, rfl⟩ := h z exact ⟨F.ιColimitType i x, rfl⟩ /-- Given `F : J ⥤ Type w₀` and `c : F.CoconeTypes`, this is the property that `c` is a colimit. It is defined by saying the canonical map `F.descColimitType c : F.ColimitType → c.pt` is a bijection. -/ structure IsColimit : Prop where bijective : Function.Bijective (F.descColimitType c) namespace IsColimit variable {c} (hc : c.IsColimit) include hc /-- Given `F : J ⥤ Type w₀`, and `c : F.CoconeTypes` a cocone that is colimit, this is the equivalence `F.ColimitType ≃ c.pt`. -/ @[simps! apply] noncomputable def equiv : F.ColimitType ≃ c.pt := Equiv.ofBijective _ hc.bijective @[simp] lemma equiv_symm_ι_apply (j : J) (x : F.obj j) : hc.equiv.symm (c.ι j x) = F.ιColimitType j x := hc.equiv.injective (by simp) lemma ι_jointly_surjective (y : c.pt) : ∃ j x, c.ι j x = y := by obtain ⟨z, rfl⟩ := hc.equiv.surjective y obtain ⟨j, x, rfl⟩ := F.ιColimitType_jointly_surjective z exact ⟨j, x, rfl⟩ lemma funext {T : Type w₂} {f g : c.pt → T} (h : ∀ j, f.comp (c.ι j) = g.comp (c.ι j)) : f = g := by funext y obtain ⟨j, x, rfl⟩ := hc.ι_jointly_surjective y exact congr_fun (h j) x lemma exists_desc (c' : CoconeTypes.{w₂} F) : ∃ (f : c.pt → c'.pt), ∀ (j : J), f.comp (c.ι j) = c'.ι j := ⟨(F.descColimitType c').comp hc.equiv.symm, by aesop⟩ /-- If `F : J ⥤ Type w₀` and `c : F.CoconeTypes` is colimit, then `c` satisfies a heterogeneous universe version of the universal property of colimits. -/ noncomputable def desc (c' : CoconeTypes.{w₂} F) : c.pt → c'.pt := (hc.exists_desc c').choose @[simp] lemma fac (c' : CoconeTypes.{w₂} F) (j : J) : (hc.desc c').comp (c.ι j) = c'.ι j := (hc.exists_desc c').choose_spec j @[simp] lemma fac_apply (c' : CoconeTypes.{w₂} F) (j : J) (x : F.obj j) : hc.desc c' (c.ι j x) = c'.ι j x := congr_fun (hc.fac c' j) x lemma of_equiv {c' : CoconeTypes.{w₂} F} (e : c.pt ≃ c'.pt) (he : ∀ j x, c'.ι j x = e (c.ι j x)) : c'.IsColimit where bijective := by convert Function.Bijective.comp e.bijective hc.bijective ext y obtain ⟨j, x, rfl⟩ := F.ιColimitType_jointly_surjective y simp_all end IsColimit /-- Structure which expresses that `c : F.CoconeTypes` satisfies the universal property of the colimit of types: compatible families of maps `F.obj j → T` (where `T` is any type in a specified universe) descend in a unique way as maps `c.pt → T`. -/ structure IsColimitCore where /-- any cocone descends (in a unique way) as a map -/ desc (c' : CoconeTypes.{w₂} F) : c.pt → c'.pt fac (c' : CoconeTypes.{w₂} F) (j : J) : (desc c').comp (c.ι j) = c'.ι j := by aesop funext {T : Type w₂} {f g : c.pt → T} (h : ∀ j, f.comp (c.ι j) = g.comp (c.ι j)) : f = g namespace IsColimitCore attribute [simp] fac variable {c} @[simp] lemma fac_apply (hc : IsColimitCore.{w₂} c) (c' : CoconeTypes.{w₂} F) (j : J) (x : F.obj j) : hc.desc c' (c.ι j x) = c'.ι j x := congr_fun (hc.fac c' j) x /-- Any structure `IsColimitCore.{max w₂ w₃} c` can be lowered to `IsColimitCore.{w₂} c` -/ def down (hc : IsColimitCore.{max w₂ w₃} c) : IsColimitCore.{w₂} c where desc c' := Equiv.ulift.toFun.comp (hc.desc (c'.postcomp Equiv.ulift.{w₃}.symm)) fac c' j := by rw [Function.comp_assoc, hc.fac] rfl funext {T f g} h := by suffices Equiv.ulift.{w₃}.invFun.comp f = Equiv.ulift.invFun.comp g by ext x simpa using congr_fun this x exact hc.funext (fun j ↦ by simp [Function.comp_assoc, h]) /-- A colimit cocone for `F : J ⥤ Type w₀` induces a colimit cocone for `G : J ⥤ Type w₉'` when we have a natural equivalence `G.obj j ≃ F.obj j` for all `j : J`. -/ def precompose (hc : IsColimitCore.{w₂} c) {G : J ⥤ Type w₀'} (e : ∀ j, G.obj j ≃ F.obj j) (naturality : ∀ {j j'} (f : j ⟶ j'), e j' ∘ G.map f = F.map f ∘ e j) : IsColimitCore.{w₂} (c.precompose _ naturality) where desc c' := hc.desc (c'.precompose _ (FunctorToTypes.naturality_symm e naturality)) fac c' j := by rw [precompose_ι, ← Function.comp_assoc, hc.fac, precompose_ι, Function.comp_assoc, Equiv.symm_comp_self, Function.comp_id] funext {T f g} h := hc.funext (fun j ↦ by ext x obtain ⟨y, rfl⟩ := (e j).surjective x exact congr_fun (h j) y) end IsColimitCore variable {c} in /-- When `c : F.CoconeTypes` satisfies the property `c.IsColimit`, this is a term in `IsColimitCore.{w₂} c` for any universe `w₂`. -/ @[simps] noncomputable def IsColimit.isColimitCore (hc : c.IsColimit) : IsColimitCore.{w₂} c where desc := hc.desc funext := hc.funext lemma IsColimitCore.isColimit (hc : IsColimitCore.{max u w₀ w₁} c) : c.IsColimit where bijective := by let e : F.ColimitType ≃ c.pt := { toFun := F.descColimitType c invFun := (down.{max u w₁} hc).desc F.coconeTypes left_inv y := by obtain ⟨j, x, rfl⟩ := F.ιColimitType_jointly_surjective y simp right_inv := by have : (F.descColimitType c).comp ((down.{max u w₁} hc).desc F.coconeTypes) = id := (down.{max u w₀} hc).funext (fun j ↦ by rw [Function.id_comp, Function.comp_assoc, fac, coconeTypes_ι, descColimitType_comp_ι]) exact congr_fun this } exact e.bijective variable {c} in lemma IsColimit.precompose (hc : c.IsColimit) {G : J ⥤ Type w₀'} (e : ∀ j, G.obj j ≃ F.obj j) (naturality : ∀ {j j'} (f : j ⟶ j'), e j' ∘ G.map f = F.map f ∘ e j) : (c.precompose _ naturality).IsColimit := (hc.isColimitCore.precompose e naturality).isColimit lemma isColimit_precompose_iff {G : J ⥤ Type w₀'} (e : ∀ j, G.obj j ≃ F.obj j) (naturality : ∀ {j j'} (f : j ⟶ j'), e j' ∘ G.map f = F.map f ∘ e j) : (c.precompose _ naturality).IsColimit ↔ c.IsColimit := ⟨fun hc ↦ (hc.precompose (fun j ↦ (e j).symm) (FunctorToTypes.naturality_symm e naturality)).of_equiv (Equiv.refl _) (by simp), fun hc ↦ hc.precompose e naturality⟩ end CoconeTypes lemma isColimit_coconeTypes : F.coconeTypes.IsColimit where bijective := by convert Function.bijective_id ext y obtain ⟨j, x, rfl⟩ := F.ιColimitType_jointly_surjective y rfl end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Equalizers.lean
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Equalizers in Type The equalizer of a pair of maps `(g, h)` from `X` to `Y` is the subtype `{x : Y // g x = h x}`. -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits.Types variable {X Y Z : Type u} (f : X ⟶ Y) {g h : Y ⟶ Z} (w : f ≫ g = f ≫ h) /-- Show the given fork in `Type u` is an equalizer given that any element in the "difference kernel" comes from `X`. The converse of `unique_of_type_equalizer`. -/ noncomputable def typeEqualizerOfUnique (t : ∀ y : Y, g y = h y → ∃! x : X, f x = y) : IsLimit (Fork.ofι _ w) := Fork.IsLimit.mk' _ fun s => by refine ⟨fun i => ?_, ?_, ?_⟩ · apply Classical.choose (t (s.ι i) _) apply congr_fun s.condition i · funext i exact (Classical.choose_spec (t (s.ι i) (congr_fun s.condition i))).1 · intro m hm funext i exact (Classical.choose_spec (t (s.ι i) (congr_fun s.condition i))).2 _ (congr_fun hm i) /-- The converse of `type_equalizer_of_unique`. -/ theorem unique_of_type_equalizer (t : IsLimit (Fork.ofι _ w)) (y : Y) (hy : g y = h y) : ∃! x : X, f x = y := by let y' : PUnit ⟶ Y := fun _ => y have hy' : y' ≫ g = y' ≫ h := funext fun _ => hy refine ⟨(Fork.IsLimit.lift' t _ hy').1 ⟨⟩, congr_fun (Fork.IsLimit.lift' t y' _).2 ⟨⟩, ?_⟩ intro x' hx' suffices (fun _ : PUnit => x') = (Fork.IsLimit.lift' t y' hy').1 by rw [← this] apply Fork.IsLimit.hom_ext t funext ⟨⟩ apply hx'.trans (congr_fun (Fork.IsLimit.lift' t _ hy').2 ⟨⟩).symm theorem type_equalizer_iff_unique : Nonempty (IsLimit (Fork.ofι _ w)) ↔ ∀ y : Y, g y = h y → ∃! x : X, f x = y := ⟨fun i => unique_of_type_equalizer _ _ (Classical.choice i), fun k => ⟨typeEqualizerOfUnique f w k⟩⟩ /-- Show that the subtype `{x : Y // g x = h x}` is an equalizer for the pair `(g,h)`. -/ def equalizerLimit : Limits.LimitCone (parallelPair g h) where cone := Fork.ofι (Subtype.val : { x : Y // g x = h x } → Y) (funext Subtype.prop) isLimit := Fork.IsLimit.mk' _ fun s => ⟨fun i => ⟨s.ι i, by apply congr_fun s.condition i⟩, rfl, fun hm => funext fun x => Subtype.ext (congr_fun hm x)⟩ variable (g h) /-- The categorical equalizer in `Type u` is `{x : Y // g x = h x}`. -/ noncomputable def equalizerIso : equalizer g h ≅ { x : Y // g x = h x } := limit.isoLimitCone equalizerLimit @[elementwise (attr := simp)] theorem equalizerIso_hom_comp_subtype : (equalizerIso g h).hom ≫ Subtype.val = equalizer.ι g h := by rfl @[elementwise (attr := simp)] theorem equalizerIso_inv_comp_ι : (equalizerIso g h).inv ≫ equalizer.ι g h = Subtype.val := limit.isoLimitCone_inv_π equalizerLimit WalkingParallelPair.zero end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/ColimitTypeFiltered.lean
import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Limits.Types.ColimitType /-! # Filtered colimits of types In this file, given a functor `F : J ⥤ Type w₀` from a filtered category `J`, we compute the equivalence relation generated by `F.ColimitTypeRel` on `(j : J) × (F.obj j)`. Given `c : CoconeTypes F`, we deduce a lemma `Functor.CoconeTypes.injective_descColimitType_iff_of_isFiltered` which gives a concrete condition under which the map `F.descColimitType c : F.ColimitType → c.pt` is injective, which is an important step when proving `c.IsColimit`. -/ universe w₁ w₀ v u namespace CategoryTheory open IsFiltered variable {J : Type u} [Category.{v} J] [IsFiltered J] namespace Functor variable (F : J ⥤ Type w₀) lemma eqvGen_colimitTypeRel_iff_of_isFiltered (x y : (j : J) × (F.obj j)) : Relation.EqvGen F.ColimitTypeRel x y ↔ ∃ (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2 := by constructor · intro h induction h with | rel x y h => obtain ⟨f, h⟩ := h exact ⟨y.1, f, 𝟙 _, by simpa using h.symm⟩ | refl x => exact ⟨x.1, 𝟙 _, 𝟙 _, rfl⟩ | symm _ _ _ h => obtain ⟨k, f, g, h⟩ := h exact ⟨k, g, f, h.symm⟩ | trans x y z _ _ h h' => obtain ⟨k, f, g, h⟩ := h obtain ⟨k', f', g', h'⟩ := h' obtain ⟨l, a, b, h''⟩ := span g f' refine ⟨l, f ≫ a, g' ≫ b, ?_⟩ rw [FunctorToTypes.map_comp_apply, FunctorToTypes.map_comp_apply _ g', h, ← h', ← FunctorToTypes.map_comp_apply, ← FunctorToTypes.map_comp_apply, h''] · rintro ⟨k, f, f', h⟩ apply Relation.EqvGen.trans (y := ⟨k, F.map f' y.2⟩) · exact .rel _ _ ⟨f, by rw [← h]⟩ · exact .symm _ _ (.rel _ _ ⟨f', rfl⟩) lemma ιColimitType_eq_iff_of_isFiltered {j j' : J} (x : F.obj j) (y : F.obj j') : F.ιColimitType j x = F.ιColimitType j' y ↔ ∃ (k : J) (f : j ⟶ k) (f' : j' ⟶ k), F.map f x = F.map f' y := by rw [ιColimitType_eq_iff, eqvGen_colimitTypeRel_iff_of_isFiltered] /-- More precise variant of the lemma `ιColimitType_eq_iff_of_isFiltered` in the case both `x` and `y` and in the same type `F.obj j`. -/ lemma ιColimitType_eq_iff_of_isFiltered' {j : J} (x y : F.obj j) : F.ιColimitType j x = F.ιColimitType j y ↔ ∃ (k : J) (f : j ⟶ k), F.map f x = F.map f y := by rw [ιColimitType_eq_iff_of_isFiltered] constructor · rintro ⟨k, f, f', h⟩ refine ⟨coeq f f', f ≫ coeqHom f f', ?_⟩ nth_rw 2 [coeq_condition] simp [h] · rintro ⟨k, f, h⟩ exact ⟨k, f, f, h⟩ namespace CoconeTypes variable {F} (c : CoconeTypes.{w₁} F) lemma descColimitType_injective_iff_of_isFiltered : Function.Injective (F.descColimitType c) ↔ ∀ (j j' : J) (x : F.obj j) (x' : F.obj j'), c.ι j x = c.ι j' x' → ∃ (k : J) (f : j ⟶ k) (f' : j' ⟶ k), F.map f x = F.map f' x' := by constructor · intro h j j' x x' eq have : F.ιColimitType j x = F.ιColimitType j' x' := h eq rwa [ιColimitType_eq_iff_of_isFiltered] at this · intro h x x' eq obtain ⟨i, x, rfl⟩ := F.ιColimitType_jointly_surjective x obtain ⟨i', x', rfl⟩ := F.ιColimitType_jointly_surjective x' simp only [descColimitType_ιColimitType_apply] at eq obtain ⟨k, f, f', eq⟩ := h _ _ _ _ eq rw [← F.ιColimitType_map f x, eq, F.ιColimitType_map] /-- Variant of `descColimitType_injective_iff_of_isFiltered` where we assume both elements `x` and `x'` are in the same type `F.obj j`. -/ lemma descColimitType_injective_iff_of_isFiltered' : Function.Injective (F.descColimitType c) ↔ ∀ (j : J) (x x' : F.obj j), c.ι j x = c.ι j x' → ∃ (k : J) (f : j ⟶ k), F.map f x = F.map f x' := by rw [descColimitType_injective_iff_of_isFiltered] constructor · intro h j x x' eq obtain ⟨k, f, f', eq⟩ := h _ _ _ _ eq refine ⟨coeq f f', f ≫ coeqHom f f', ?_⟩ rw [FunctorToTypes.map_comp_apply, eq, ← FunctorToTypes.map_comp_apply, coeq_condition] · intro h j j' x x' eq obtain ⟨k, g, eq⟩ := h (max j j') (F.map (leftToMax _ _) x) (F.map (rightToMax _ _) x') (by simpa only [c.ι_naturality_apply]) exact ⟨k, leftToMax _ _ ≫ g, rightToMax _ _ ≫ g, by simp only [FunctorToTypes.map_comp_apply, eq]⟩ end CoconeTypes end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Coproducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Coproducts in `Type` If `F : J → Type max v u` (with `J : Type v`), we show that the coproduct of `F` exists in `Type max v u` and identifies to the sigma type `Σ j, F j`. Similarly, the binary coproduct of two types `X` and `Y` identifies to `X ⊕ Y`, and the initial object of `Type u` if `PEmpty`. -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits.Types /-- The category of types has `PEmpty` as an initial object. -/ def initialColimitCocone : Limits.ColimitCocone (Functor.empty (Type u)) where -- Porting note: tidy was able to fill the structure automatically cocone := { pt := PEmpty ι := (Functor.uniqueFromEmpty _).inv } isColimit := { desc := fun _ => by rintro ⟨⟩ fac := fun _ => by rintro ⟨⟨⟩⟩ uniq := fun _ _ _ => by funext x; cases x } /-- The initial object in `Type u` is `PEmpty`. -/ noncomputable def initialIso : ⊥_ Type u ≅ PEmpty := colimit.isoColimitCocone initialColimitCocone.{u, 0} /-- The initial object in `Type u` is `PEmpty`. -/ noncomputable def isInitialPunit : IsInitial (PEmpty : Type u) := initialIsInitial.ofIso initialIso /-- An object in `Type u` is initial if and only if it is empty. -/ lemma initial_iff_empty (X : Type u) : Nonempty (IsInitial X) ↔ IsEmpty X := by constructor · intro ⟨h⟩ exact Function.isEmpty (IsInitial.to h PEmpty) · intro h exact ⟨IsInitial.ofIso Types.isInitialPunit <| Equiv.toIso <| Equiv.equivOfIsEmpty PEmpty X⟩ /-- The sum type `X ⊕ Y` forms a cocone for the binary coproduct of `X` and `Y`. -/ @[simps!] def binaryCoproductCocone (X Y : Type u) : Cocone (pair X Y) := BinaryCofan.mk Sum.inl Sum.inr open CategoryTheory.Limits.WalkingPair /-- The sum type `X ⊕ Y` is a binary coproduct for `X` and `Y`. -/ @[simps] def binaryCoproductColimit (X Y : Type u) : IsColimit (binaryCoproductCocone X Y) where desc := fun s : BinaryCofan X Y => Sum.elim s.inl s.inr fac _ j := Discrete.recOn j fun j => WalkingPair.casesOn j rfl rfl uniq _ _ w := funext fun x => Sum.casesOn x (congr_fun (w ⟨left⟩)) (congr_fun (w ⟨right⟩)) /-- The category of types has `X ⊕ Y`, as the binary coproduct of `X` and `Y`. -/ def binaryCoproductColimitCocone (X Y : Type u) : Limits.ColimitCocone (pair X Y) := ⟨_, binaryCoproductColimit X Y⟩ /-- The categorical binary coproduct in `Type u` is the sum `X ⊕ Y`. -/ noncomputable def binaryCoproductIso (X Y : Type u) : Limits.coprod X Y ≅ X ⊕ Y := colimit.isoColimitCocone (binaryCoproductColimitCocone X Y) --open CategoryTheory.Type @[elementwise (attr := simp)] theorem binaryCoproductIso_inl_comp_hom (X Y : Type u) : Limits.coprod.inl ≫ (binaryCoproductIso X Y).hom = Sum.inl := colimit.isoColimitCocone_ι_hom (binaryCoproductColimitCocone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inr_comp_hom (X Y : Type u) : Limits.coprod.inr ≫ (binaryCoproductIso X Y).hom = Sum.inr := colimit.isoColimitCocone_ι_hom (binaryCoproductColimitCocone X Y) ⟨WalkingPair.right⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inl_comp_inv (X Y : Type u) : ↾(Sum.inl : X ⟶ X ⊕ Y) ≫ (binaryCoproductIso X Y).inv = Limits.coprod.inl := colimit.isoColimitCocone_ι_inv (binaryCoproductColimitCocone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inr_comp_inv (X Y : Type u) : ↾(Sum.inr : Y ⟶ X ⊕ Y) ≫ (binaryCoproductIso X Y).inv = Limits.coprod.inr := colimit.isoColimitCocone_ι_inv (binaryCoproductColimitCocone X Y) ⟨WalkingPair.right⟩ open Function (Injective) theorem binaryCofan_isColimit_iff {X Y : Type u} (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ Injective c.inl ∧ Injective c.inr ∧ IsCompl (Set.range c.inl) (Set.range c.inr) := by classical constructor · rintro ⟨h⟩ rw [← show _ = c.inl from h.comp_coconePointUniqueUpToIso_inv (binaryCoproductColimit X Y) ⟨WalkingPair.left⟩, ← show _ = c.inr from h.comp_coconePointUniqueUpToIso_inv (binaryCoproductColimit X Y) ⟨WalkingPair.right⟩] dsimp [binaryCoproductCocone] refine ⟨(h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.injective.comp Sum.inl_injective, (h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.injective.comp Sum.inr_injective, ?_⟩ rw [types_comp, Set.range_comp, ← eq_compl_iff_isCompl, types_comp, Set.range_comp _ Sum.inr] erw [← Set.image_compl_eq (h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.bijective] simp · rintro ⟨h₁, h₂, h₃⟩ have : ∀ x, x ∈ Set.range c.inl ∨ x ∈ Set.range c.inr := by rw [eq_compl_iff_isCompl.mpr h₃.symm] exact fun _ => or_not refine ⟨BinaryCofan.IsColimit.mk _ ?_ ?_ ?_ ?_⟩ · intro T f g x exact if h : x ∈ Set.range c.inl then f ((Equiv.ofInjective _ h₁).symm ⟨x, h⟩) else g ((Equiv.ofInjective _ h₂).symm ⟨x, (this x).resolve_left h⟩) · intro T f g funext x simp [h₁.eq_iff] · intro T f g funext x dsimp simp only [Set.mem_range, Equiv.ofInjective_symm_apply, dite_eq_right_iff, forall_exists_index] intro y e have : c.inr x ∈ Set.range c.inl ⊓ Set.range c.inr := ⟨⟨_, e⟩, ⟨_, rfl⟩⟩ rw [disjoint_iff.mp h₃.1] at this exact this.elim · rintro T _ _ m rfl rfl funext x dsimp split_ifs <;> exact congr_arg _ (Equiv.apply_ofInjective_symm _ ⟨_, _⟩).symm /-- Any monomorphism in `Type` is a coproduct injection. -/ noncomputable def isCoprodOfMono {X Y : Type u} (f : X ⟶ Y) [Mono f] : IsColimit (BinaryCofan.mk f (Subtype.val : ↑(Set.range f)ᶜ → Y)) := by apply Nonempty.some rw [binaryCofan_isColimit_iff] refine ⟨(mono_iff_injective f).mp inferInstance, Subtype.val_injective, ?_⟩ symm rw [← eq_compl_iff_isCompl] exact Subtype.range_val /-- The category of types has `Σ j, f j` as the coproduct of a type family `f : J → Type`. -/ def coproductColimitCocone {J : Type v} (F : J → Type max v u) : Limits.ColimitCocone (Discrete.functor F) where cocone := { pt := Σ j, F j ι := Discrete.natTrans (fun ⟨j⟩ x => ⟨j, x⟩)} isColimit := { desc := fun s x => s.ι.app ⟨x.1⟩ x.2 uniq := fun s m w => by funext ⟨j, x⟩ exact congr_fun (w ⟨j⟩) x } /-- The categorical coproduct in `Type u` is the type-theoretic coproduct `Σ j, F j`. -/ noncomputable def coproductIso {J : Type v} (F : J → Type max v u) : ∐ F ≅ Σ j, F j := colimit.isoColimitCocone (coproductColimitCocone F) @[elementwise (attr := simp)] theorem coproductIso_ι_comp_hom {J : Type v} (F : J → Type max v u) (j : J) : Sigma.ι F j ≫ (coproductIso F).hom = fun x : F j => (⟨j, x⟩ : Σ j, F j) := colimit.isoColimitCocone_ι_hom (coproductColimitCocone F) ⟨j⟩ @[elementwise (attr := simp)] theorem coproductIso_mk_comp_inv {J : Type v} (F : J → Type max v u) (j : J) : (↾fun x : F j => (⟨j, x⟩ : Σ j, F j)) ≫ (coproductIso F).inv = Sigma.ι F j := rfl end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Colimits.lean
import Mathlib.Logic.UnivLE import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Types.ColimitType /-! # Colimits in the category of types We show that the category of types has all colimits, by providing the usual concrete models. -/ universe u' v u w namespace CategoryTheory open Limits variable {J : Type v} [Category.{w} J] namespace Functor instance [Small.{u} J] (F : J ⥤ Type u) : Small.{u} (F.ColimitType) := small_of_surjective Quot.mk_surjective variable (F : J ⥤ Type u) /-- If `F : J ⥤ Type u`, then the data of a "type-theoretic" cocone of `F` with a point in `Type u` is the same as the data of a cocone (in a categorical sense). -/ @[simps] def coconeTypesEquiv : CoconeTypes.{u} F ≃ Cocone F where toFun c := { pt := c.pt ι := { app j := c.ι j } } invFun c := { pt := c.pt ι j := c.ι.app j ι_naturality := c.w } left_inv _ := rfl right_inv _ := rfl variable {F} lemma CoconeTypes.isColimit_iff (c : CoconeTypes.{u} F) : c.IsColimit ↔ Nonempty (Limits.IsColimit (F.coconeTypesEquiv c)) := by constructor · intro hc exact ⟨{ desc s := hc.desc (F.coconeTypesEquiv.symm s) fac s j := hc.fac (F.coconeTypesEquiv.symm s) j uniq s m hm := hc.funext (fun j ↦ by rw [hc.fac] exact hm j )}⟩ · rintro ⟨hc⟩ classical refine ⟨⟨fun x y h ↦ ?_, fun x ↦ ?_⟩⟩ · let f (z : F.ColimitType) : ULift.{u} Bool := ULift.up (x = z) suffices f x = f y by simpa [f] using this have : (hc.desc (F.coconeTypesEquiv (F.coconeTypes.postcomp f))).comp (F.descColimitType c) = f := by ext z obtain ⟨j, z, rfl⟩ := F.ιColimitType_jointly_surjective z exact congr_fun (hc.fac _ j) z simp only [← this, coconeTypesEquiv_apply_pt, Function.comp_apply, h] · let f₁ : c.pt ⟶ ULift.{u} Bool := fun _ => ULift.up true let f₂ : c.pt ⟶ ULift.{u} Bool := fun x => ULift.up (∃ a, F.descColimitType c a = x) suffices f₁ = f₂ by simpa [f₁, f₂] using congrFun this x refine hc.hom_ext fun j => funext fun x => ?_ simpa [f₁, f₂] using ⟨F.ιColimitType j x, by simp⟩ end Functor namespace Limits.Types theorem isColimit_iff_coconeTypesIsColimit {F : J ⥤ Type u} (c : Cocone F) : Nonempty (IsColimit c) ↔ (F.coconeTypesEquiv.symm c).IsColimit := by simp only [Functor.CoconeTypes.isColimit_iff, Equiv.apply_symm_apply] /-- (internal implementation) the colimit cocone of a functor, implemented as a quotient of a sigma type -/ noncomputable abbrev colimitCocone (F : J ⥤ Type u) [Small.{u} F.ColimitType] : Cocone F := F.coconeTypesEquiv (F.coconeTypes.postcomp (equivShrink.{u} F.ColimitType)) /-- (internal implementation) the fact that the proposed colimit cocone is the colimit -/ noncomputable def colimitCoconeIsColimit (F : J ⥤ Type u) [Small.{u} F.ColimitType] : IsColimit (colimitCocone F) := Nonempty.some ((isColimit_iff_coconeTypesIsColimit _).2 (F.isColimit_coconeTypes.of_equiv (equivShrink.{u} F.ColimitType) (by aesop))) theorem hasColimit_iff_small_colimitType (F : J ⥤ Type u) : HasColimit F ↔ Small.{u} F.ColimitType := ⟨fun _ ↦ small_of_injective ((isColimit_iff_coconeTypesIsColimit _).1 ⟨colimit.isColimit F⟩).bijective.1, fun _ ↦ ⟨_, colimitCoconeIsColimit F⟩⟩ @[deprecated (since := "2025-06-22")] alias hasColimit_iff_small_quot := hasColimit_iff_small_colimitType theorem small_colimitType_of_hasColimit (F : J ⥤ Type u) [HasColimit F] : Small.{u} F.ColimitType := (hasColimit_iff_small_colimitType F).mp inferInstance @[deprecated (since := "2025-06-22")] alias small_quot_of_hasColimit := small_colimitType_of_hasColimit instance hasColimit [Small.{u} J] (F : J ⥤ Type u) : HasColimit F := (hasColimit_iff_small_colimitType F).mpr inferInstance instance hasColimitsOfShape [Small.{u} J] : HasColimitsOfShape J (Type u) where /-- The category of types has all colimits. -/ @[stacks 002U] instance (priority := 1300) hasColimitsOfSize [UnivLE.{v, u}] : HasColimitsOfSize.{w, v} (Type u) where section instances example : HasColimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (Type max w v) := inferInstance example : HasColimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (Type max v w) := inferInstance example : HasColimitsOfSize.{0, 0, v, v + 1} (Type v) := inferInstance example : HasColimitsOfSize.{v, v, v, v + 1} (Type v) := inferInstance example [UnivLE.{v, u}] : HasColimitsOfSize.{v, v, u, u + 1} (Type u) := inferInstance end instances namespace TypeMax /-- (internal implementation) the colimit cocone of a functor, implemented as a quotient of a sigma type -/ abbrev colimitCocone (F : J ⥤ Type max v u) : Cocone F := F.coconeTypesEquiv F.coconeTypes /-- (internal implementation) the fact that the proposed colimit cocone is the colimit -/ noncomputable def colimitCoconeIsColimit (F : J ⥤ Type max v u) : IsColimit (colimitCocone F) := (F.coconeTypes.isColimit_iff.1 F.isColimit_coconeTypes).some end TypeMax variable (F : J ⥤ Type u) [HasColimit F] attribute [local instance] small_colimitType_of_hasColimit /-- The equivalence between the abstract colimit of `F` in `Type u` and the "concrete" definition as a quotient. -/ noncomputable def colimitEquivColimitType : colimit F ≃ F.ColimitType := (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (colimitCoconeIsColimit F)).toEquiv.trans (equivShrink _).symm @[simp] theorem colimitEquivColimitType_symm_apply (j : J) (x : F.obj j) : (colimitEquivColimitType F).symm (Quot.mk _ ⟨j, x⟩) = colimit.ι F j x := congrFun (IsColimit.comp_coconePointUniqueUpToIso_inv (colimit.isColimit F) _ _) x @[simp] theorem colimitEquivColimitType_apply (j : J) (x : F.obj j) : (colimitEquivColimitType F) (colimit.ι F j x) = Quot.mk _ ⟨j, x⟩ := by apply (colimitEquivColimitType F).symm.injective simp variable {F} in @[simp] theorem Colimit.w_apply {j j' : J} {x : F.obj j} (f : j ⟶ j') : colimit.ι F j' (F.map f x) = colimit.ι F j x := congr_fun (colimit.w F f) x @[simp] theorem Colimit.ι_desc_apply (s : Cocone F) (j : J) (x : F.obj j) : colimit.desc F s (colimit.ι F j x) = s.ι.app j x := congr_fun (colimit.ι_desc s j) x @[simp] theorem Colimit.ι_map_apply {F G : J ⥤ Type u} [HasColimitsOfShape J (Type u)] (α : F ⟶ G) (j : J) (x : F.obj j) : colim.map α (colimit.ι F j x) = colimit.ι G j (α.app j x) := congr_fun (colimit.ι_map α j) x -- These were variations of the aliased lemmas with different universe variables. -- It appears those are now strictly more powerful. @[deprecated (since := "2025-08-22")] alias Colimit.w_apply' := Colimit.w_apply @[deprecated (since := "2025-08-22")] alias Colimit.ι_desc_apply' := Colimit.ι_desc_apply @[deprecated (since := "2025-08-22")] alias Colimit.ι_map_apply' := Colimit.ι_map_apply variable {F} in theorem colimit_sound {j j' : J} {x : F.obj j} {x' : F.obj j'} (f : j ⟶ j') (w : F.map f x = x') : colimit.ι F j x = colimit.ι F j' x' := by rw [← w, Colimit.w_apply] variable {F} in theorem colimit_sound' {j j' : J} {x : F.obj j} {x' : F.obj j'} {j'' : J} (f : j ⟶ j'') (f' : j' ⟶ j'') (w : F.map f x = F.map f' x') : colimit.ι F j x = colimit.ι F j' x' := by rw [← colimit.w _ f, ← colimit.w _ f'] rw [types_comp_apply, types_comp_apply, w] variable {F} in theorem colimit_eq {j j' : J} {x : F.obj j} {x' : F.obj j'} (w : colimit.ι F j x = colimit.ι F j' x') : Relation.EqvGen F.ColimitTypeRel ⟨j, x⟩ ⟨j', x'⟩ := by apply Quot.eq.1 simpa using congr_arg (colimitEquivColimitType F) w theorem jointly_surjective_of_isColimit {F : J ⥤ Type u} {t : Cocone F} (h : IsColimit t) (x : t.pt) : ∃ j y, t.ι.app j y = x := by by_contra hx simp_rw [not_exists] at hx apply (_ : (fun _ ↦ ULift.up True) ≠ (⟨· ≠ x⟩)) · refine h.hom_ext fun j ↦ ?_ ext y exact (true_iff _).mpr (hx j y) · exact fun he ↦ of_eq_true (congr_arg ULift.down <| congr_fun he x).symm rfl theorem jointly_surjective (F : J ⥤ Type u) {t : Cocone F} (h : IsColimit t) (x : t.pt) : ∃ j y, t.ι.app j y = x := jointly_surjective_of_isColimit h x variable {F} in /-- A variant of `jointly_surjective` for `x : colimit F`. -/ theorem jointly_surjective' (x : colimit F) : ∃ j y, colimit.ι F j y = x := jointly_surjective F (colimit.isColimit F) x /-- If a colimit is nonempty, also its index category is nonempty. -/ theorem nonempty_of_nonempty_colimit {F : J ⥤ Type u} [HasColimit F] : Nonempty (colimit F) → Nonempty J := Nonempty.map <| Sigma.fst ∘ Quot.out ∘ (colimitEquivColimitType F).toFun @[deprecated (since := "2025-06-22")] alias Quot.Rel := Functor.ColimitTypeRel @[deprecated (since := "2025-06-22")] alias Quot := Functor.ColimitType @[deprecated (since := "2025-06-22")] alias Quot.ι := Functor.ιColimitType @[deprecated (since := "2025-06-22")] alias Quot.jointly_surjective := Functor.ιColimitType_jointly_surjective @[deprecated (since := "2025-06-22")] alias Quot.desc := Functor.descColimitType @[deprecated (since := "2025-06-22")] alias Quot.ι_desc := Functor.descColimitType_comp_ι @[deprecated (since := "2025-06-22")] alias Quot.map_ι := Functor.ιColimitType_map @[deprecated (since := "2025-06-22")] alias isColimit_iff_bijective_desc := isColimit_iff_coconeTypesIsColimit @[deprecated (since := "2025-06-22")] alias colimitEquivQuot := colimitEquivColimitType @[deprecated (since := "2025-06-22")] alias colimitEquivQuot_symm_apply := colimitEquivColimitType_symm_apply @[deprecated (since := "2025-06-22")] alias colimitEquivQuot_apply := colimitEquivColimitType_apply end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Multiequalizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Types.Limits /-! # Multiequalizers in Type Given `J : MulticospanShape` and `I : MulticospanIndex J (Type u)`, we define a type `I.sections`. When `c : Multifork I`, we show that `c` is a limit iff the canonical map `c.toSections : c.pt → I.sections` is a bijection. -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits variable {J : MulticospanShape} (I : MulticospanIndex J (Type u)) /-- Given `I : MulticospanIndex J (Type u)`, this is a type which identifies to the sections of the functor `I.multicospan`. -/ @[ext] structure MulticospanIndex.sections where /-- The data of an element in `I.left i` for each `i : J.L`. -/ val (i : J.L) : I.left i property (r : J.R) : I.fst r (val _) = I.snd r (val _) /-- The bijection `I.sections ≃ I.multicospan.sections` when `I : MulticospanIndex (Type u)` is a multiequalizer diagram in the category of types. -/ @[simps] def MulticospanIndex.sectionsEquiv : I.sections ≃ I.multicospan.sections where toFun s := { val := fun i ↦ match i with | .left i => s.val i | .right j => I.fst j (s.val _) property := by rintro _ _ (_ | _ | r) · rfl · rfl · exact (s.property r).symm } invFun s := { val := fun i ↦ s.val (.left i) property := fun r ↦ (s.property (.fst r)).trans (s.property (.snd r)).symm } right_inv s := by ext (_ | r) · rfl · exact s.property (.fst r) namespace Multifork variable {I} variable (c : Multifork I) /-- Given a multiequalizer diagram `I : MulticospanIndex (Type u)` in the category of types and `c` a multifork for `I`, this is the canonical map `c.pt → I.sections`. -/ @[simps] def toSections (x : c.pt) : I.sections where val i := c.ι i x property r := congr_fun (c.condition r) x lemma toSections_fac : I.sectionsEquiv.symm ∘ Types.sectionOfCone c = c.toSections := rfl /-- A multifork `c : Multifork I` in the category of types is limit iff the map `c.toSections : c.pt → I.sections` is a bijection. -/ lemma isLimit_types_iff : Nonempty (IsLimit c) ↔ Function.Bijective c.toSections := by rw [Types.isLimit_iff_bijective_sectionOfCone, ← toSections_fac, EquivLike.comp_bijective] namespace IsLimit variable {c} (hc : IsLimit c) /-- The bijection `I.sections ≃ c.pt` when `c : Multifork I` is a limit multifork in the category of types. -/ noncomputable def sectionsEquiv : I.sections ≃ c.pt := (Equiv.ofBijective _ (c.isLimit_types_iff.1 ⟨hc⟩)).symm @[simp] lemma sectionsEquiv_symm_apply_val (x : c.pt) (i : J.L) : ((sectionsEquiv hc).symm x).val i = c.ι i x := rfl @[simp] lemma sectionsEquiv_apply_val (s : I.sections) (i : J.L) : c.ι i (sectionsEquiv hc s) = s.val i := by obtain ⟨x, rfl⟩ := (sectionsEquiv hc).symm.surjective s simp end IsLimit end Multifork end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Limits.lean
import Mathlib.Logic.UnivLE import Mathlib.CategoryTheory.Limits.HasLimits /-! # Limits in the category of types. We show that the category of types has all limits, by providing the usual concrete models. -/ universe u' v u w namespace CategoryTheory.Limits.Types section limit_characterization variable {J : Type v} [Category.{w} J] {F : J ⥤ Type u} /-- Given a section of a functor F into `Type*`, construct a cone over F with `PUnit` as the cone point. -/ def coneOfSection {s} (hs : s ∈ F.sections) : Cone F where pt := PUnit π := { app := fun j _ ↦ s j, naturality := fun i j f ↦ by ext; exact (hs f).symm } /-- Given a cone over a functor F into `Type*` and an element in the cone point, construct a section of F. -/ def sectionOfCone (c : Cone F) (x : c.pt) : F.sections := ⟨fun j ↦ c.π.app j x, fun f ↦ congr_fun (c.π.naturality f).symm x⟩ theorem isLimit_iff (c : Cone F) : Nonempty (IsLimit c) ↔ ∀ s ∈ F.sections, ∃! x : c.pt, ∀ j, c.π.app j x = s j := by refine ⟨fun ⟨t⟩ s hs ↦ ?_, fun h ↦ ⟨?_⟩⟩ · let cs := coneOfSection hs exact ⟨t.lift cs ⟨⟩, fun j ↦ congr_fun (t.fac cs j) ⟨⟩, fun x hx ↦ congr_fun (t.uniq cs (fun _ ↦ x) fun j ↦ funext fun _ ↦ hx j) ⟨⟩⟩ · choose x hx using fun c y ↦ h _ (sectionOfCone c y).2 exact ⟨x, fun c j ↦ funext fun y ↦ (hx c y).1 j, fun c f hf ↦ funext fun y ↦ (hx c y).2 (f y) (fun j ↦ congr_fun (hf j) y)⟩ theorem isLimit_iff_bijective_sectionOfCone (c : Cone F) : Nonempty (IsLimit c) ↔ (Types.sectionOfCone c).Bijective := by simp_rw [isLimit_iff, Function.bijective_iff_existsUnique, Subtype.forall, F.sections_ext_iff, sectionOfCone] /-- The equivalence between a limiting cone of `F` in `Type u` and the "concrete" definition as the sections of `F`. -/ noncomputable def isLimitEquivSections {c : Cone F} (t : IsLimit c) : c.pt ≃ F.sections where toFun := sectionOfCone c invFun s := t.lift (coneOfSection s.2) ⟨⟩ left_inv x := (congr_fun (t.uniq (coneOfSection _) (fun _ ↦ x) fun _ ↦ rfl) ⟨⟩).symm right_inv s := Subtype.ext (funext fun j ↦ congr_fun (t.fac (coneOfSection s.2) j) ⟨⟩) @[simp] theorem isLimitEquivSections_apply {c : Cone F} (t : IsLimit c) (j : J) (x : c.pt) : (isLimitEquivSections t x : ∀ j, F.obj j) j = c.π.app j x := rfl @[simp] theorem isLimitEquivSections_symm_apply {c : Cone F} (t : IsLimit c) (x : F.sections) (j : J) : c.π.app j ((isLimitEquivSections t).symm x) = (x : ∀ j, F.obj j) j := by conv_rhs => rw [← (isLimitEquivSections t).right_inv x] rfl end limit_characterization variable {J : Type v} [Category.{w} J] /-! We now provide two distinct implementations in the category of types. The first, in the `CategoryTheory.Limits.Types.Small` namespace, assumes `Small.{u} J` and constructs `J`-indexed limits in `Type u`. The second, in the `CategoryTheory.Limits.Types.TypeMax` namespace constructs limits for functors `F : J ⥤ Type max v u`, for `J : Type v`. This construction is slightly nicer, as the limit is definitionally just `F.sections`, rather than `Shrink F.sections`, which makes an arbitrary choice of `u`-small representative. Hopefully we might be able to entirely remove the `TypeMax` constructions, but for now they are useful glue for the later parts of the library. -/ namespace Small variable (F : J ⥤ Type u) section variable [Small.{u} F.sections] /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone : Cone F where pt := Shrink F.sections π := { app := fun j u => ((equivShrink F.sections).symm u).val j naturality := fun j j' f => by funext x simp } @[ext] lemma limitCone_pt_ext {x y : (limitCone F).pt} (w : (equivShrink F.sections).symm x = (equivShrink F.sections).symm y) : x = y := by simp_all /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit : IsLimit (limitCone.{v, u} F) where lift s v := equivShrink F.sections { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by ext x j simpa using congr_fun (w j) x end end Small theorem hasLimit_iff_small_sections (F : J ⥤ Type u) : HasLimit F ↔ Small.{u} F.sections := ⟨fun _ => .mk ⟨_, ⟨(Equiv.ofBijective _ ((isLimit_iff_bijective_sectionOfCone (limit.cone F)).mp ⟨limit.isLimit _⟩)).symm⟩⟩, fun _ => ⟨_, Small.limitConeIsLimit F⟩⟩ -- TODO: If `UnivLE` works out well, we will eventually want to deprecate these -- definitions, and probably as a first step put them in namespace or otherwise rename them. section TypeMax /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone (F : J ⥤ Type max v u) : Cone F where pt := F.sections π := { app := fun j u => u.val j naturality := fun j j' f => by funext x simp } /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit (F : J ⥤ Type max v u) : IsLimit (limitCone F) where lift s v := { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by funext x apply Subtype.ext funext j exact congr_fun (w j) x end TypeMax /-! The results in this section have a `UnivLE.{v, u}` hypothesis, but as they only use the constructions from the `CategoryTheory.Limits.Types.UnivLE` namespace in their definitions (rather than their statements), we leave them in the main `CategoryTheory.Limits.Types` namespace. -/ section UnivLE open UnivLE instance hasLimit [Small.{u} J] (F : J ⥤ Type u) : HasLimit F := (hasLimit_iff_small_sections F).mpr inferInstance instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J (Type u) where /-- The category of types has all limits. More specifically, when `UnivLE.{v, u}`, the category `Type u` has all `v`-small limits. -/ @[stacks 002U] instance (priority := 1300) hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} (Type u) where has_limits_of_shape _ := { } variable (F : J ⥤ Type u) [HasLimit F] /-- The equivalence between the abstract limit of `F` in `Type max v u` and the "concrete" definition as the sections of `F`. -/ noncomputable def limitEquivSections : limit F ≃ F.sections := isLimitEquivSections (limit.isLimit F) @[simp] theorem limitEquivSections_apply (x : limit F) (j : J) : ((limitEquivSections F) x : ∀ j, F.obj j) j = limit.π F j x := rfl @[simp] theorem limitEquivSections_symm_apply (x : F.sections) (j : J) : limit.π F j ((limitEquivSections F).symm x) = (x : ∀ j, F.obj j) j := isLimitEquivSections_symm_apply _ _ _ /-- The limit of a functor `F : J ⥤ Type _` is naturally isomorphic to `F.sections`. -/ noncomputable def limNatIsoSectionsFunctor : (lim : (J ⥤ Type max u v) ⥤ _) ≅ Functor.sectionsFunctor _ := NatIso.ofComponents (fun _ ↦ (limitEquivSections _).toIso) fun f ↦ funext fun x ↦ Subtype.ext <| funext fun _ ↦ congrFun (limMap_π f _) x /-- Construct a term of `limit F : Type u` from a family of terms `x : Π j, F.obj j` which are "coherent": `∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j'`. -/ noncomputable def Limit.mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') : limit F := (limitEquivSections F).symm ⟨x, h _ _⟩ @[simp] theorem Limit.π_mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') (j) : limit.π F j (Limit.mk F x h) = x j := by dsimp [Limit.mk] simp -- PROJECT: prove this for concrete categories where the forgetful functor preserves limits @[ext] theorem limit_ext (x y : limit F) (w : ∀ j, limit.π F j x = limit.π F j y) : x = y := by apply (limitEquivSections F).injective ext j simp [w j] @[ext] theorem limit_ext' (F : J ⥤ Type v) (x y : limit F) (w : ∀ j, limit.π F j x = limit.π F j y) : x = y := limit_ext F x y w theorem limit_ext_iff' (F : J ⥤ Type v) (x y : limit F) : x = y ↔ ∀ j, limit.π F j x = limit.π F j y := ⟨fun t _ => t ▸ rfl, limit_ext' _ _ _⟩ -- TODO: are there other limits lemmas that should have `_apply` versions? -- Can we generate these like with `@[reassoc]`? -- PROJECT: prove these for any concrete category where the forgetful functor preserves limits? variable {F} in @[simp] theorem Limit.w_apply {j j' : J} {x : limit F} (f : j ⟶ j') : F.map f (limit.π F j x) = limit.π F j' x := congr_fun (limit.w F f) x @[simp] theorem Limit.lift_π_apply (s : Cone F) (j : J) (x : s.pt) : limit.π F j (limit.lift F s x) = s.π.app j x := congr_fun (limit.lift_π s j) x @[simp] theorem Limit.map_π_apply {F G : J ⥤ Type u} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) (x : limit F) : limit.π G j (limMap α x) = α.app j (limit.π F j x) := congr_fun (limMap_π α j) x -- Not `@[simp]` since `lift_w_apply` proves it. theorem Limit.w_apply' {F : J ⥤ Type v} {j j' : J} {x : limit F} (f : j ⟶ j') : F.map f (limit.π F j x) = limit.π F j' x := congr_fun (limit.w F f) x -- Not `@[simp]` since `lift_π_apply` proves it. theorem Limit.lift_π_apply' (F : J ⥤ Type v) (s : Cone F) (j : J) (x : s.pt) : limit.π F j (limit.lift F s x) = s.π.app j x := congr_fun (limit.lift_π s j) x -- Not `@[simp]` since `map_π_apply` proves it. theorem Limit.map_π_apply' {F G : J ⥤ Type v} (α : F ⟶ G) (j : J) (x : limit F) : limit.π G j (limMap α x) = α.app j (limit.π F j x) := congr_fun (limMap_π α j) x end UnivLE /-! In this section we verify that instances are available as expected. -/ section instances example : HasLimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (Type max w v) := inferInstance example : HasLimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (Type max v w) := inferInstance example : HasLimitsOfSize.{0, 0, v, v + 1} (Type v) := inferInstance example : HasLimitsOfSize.{v, v, v, v + 1} (Type v) := inferInstance example [UnivLE.{v, u}] : HasLimitsOfSize.{v, v, u, u + 1} (Type u) := inferInstance end instances end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Images.lean
import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.CategoryTheory.Limits.Shapes.Images /-! # Images in the category of types In this file, it is shown that the category of types has categorical images, and that these agree with the range of a function. -/ universe v u namespace CategoryTheory.Limits.Types variable {α β : Type u} (f : α ⟶ β) section -- implementation of `HasImage` /-- the image of a morphism in Type is just `Set.range f` -/ def Image : Type u := Set.range f instance [Inhabited α] : Inhabited (Image f) where default := ⟨f default, ⟨_, rfl⟩⟩ /-- the inclusion of `Image f` into the target -/ def Image.ι : Image f ⟶ β := Subtype.val instance : Mono (Image.ι f) := (mono_iff_injective _).2 Subtype.val_injective variable {f} /-- the universal property for the image factorisation -/ noncomputable def Image.lift (F' : MonoFactorisation f) : Image f ⟶ F'.I := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : Image f → F'.I) theorem Image.lift_fac (F' : MonoFactorisation f) : Image.lift F' ≫ F'.m = Image.ι f := by funext x change (F'.e ≫ F'.m) _ = _ rw [F'.fac, (Classical.indefiniteDescription _ x.2).2] rfl end /-- the factorisation of any morphism in Type through a mono. -/ def monoFactorisation : MonoFactorisation f where I := Image f m := Image.ι f e := Set.rangeFactorization f /-- the factorisation through a mono has the universal property of the image. -/ noncomputable def isImage : IsImage (monoFactorisation f) where lift := Image.lift lift_fac := Image.lift_fac instance : HasImage f := HasImage.mk ⟨_, isImage f⟩ instance : HasImages (Type u) where has_image := by infer_instance instance : HasImageMaps (Type u) where has_image_map {f g} st := HasImageMap.transport st (monoFactorisation f.hom) (isImage g.hom) (fun x => ⟨st.right x.1, ⟨st.left (Classical.choose x.2), by have p := st.w replace p := congr_fun p (Classical.choose x.2) simp only [Functor.id_obj, Functor.id_map, types_comp_apply] at p rw [p, Classical.choose_spec x.2]⟩⟩) rfl variable {F : ℕᵒᵖ ⥤ Type u} {c : Cone F} (hF : ∀ n, Function.Surjective (F.map (homOfLE (Nat.le_succ n)).op)) private noncomputable def limitOfSurjectionsSurjective.preimage (a : F.obj ⟨0⟩) : (n : ℕ) → F.obj ⟨n⟩ | 0 => a | n + 1 => (hF n (preimage a n)).choose include hF in open limitOfSurjectionsSurjective in /-- Auxiliary lemma. Use `limit_of_surjections_surjective` instead. -/ lemma surjective_π_app_zero_of_surjective_map_aux : Function.Surjective ((limitCone F).π.app ⟨0⟩) := by intro a refine ⟨⟨fun ⟨n⟩ ↦ preimage hF a n, ?_⟩, rfl⟩ intro ⟨n⟩ ⟨m⟩ ⟨⟨⟨(h : m ≤ n)⟩⟩⟩ induction h with | refl => erw [CategoryTheory.Functor.map_id, types_id_apply] | @step p h ih => rw [← ih] have h' : m ≤ p := h erw [CategoryTheory.Functor.map_comp (f := (homOfLE (Nat.le_succ p)).op) (g := (homOfLE h').op), types_comp_apply, (hF p _).choose_spec] rfl /-- Given surjections `⋯ ⟶ Xₙ₊₁ ⟶ Xₙ ⟶ ⋯ ⟶ X₀`, the projection map `lim Xₙ ⟶ X₀` is surjective. -/ lemma surjective_π_app_zero_of_surjective_map (hc : IsLimit c) (hF : ∀ n, Function.Surjective (F.map (homOfLE (Nat.le_succ n)).op)) : Function.Surjective (c.π.app ⟨0⟩) := by let i := hc.conePointUniqueUpToIso (limitConeIsLimit F) have : c.π.app ⟨0⟩ = i.hom ≫ (limitCone F).π.app ⟨0⟩ := by simp [i] rw [this] apply Function.Surjective.comp · exact surjective_π_app_zero_of_surjective_map_aux hF · rw [← epi_iff_surjective] infer_instance end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Multicoequalizer.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Types.Set import Mathlib.Data.Set.BooleanAlgebra import Mathlib.Order.CompleteLattice.MulticoequalizerDiagram /-! # Multicoequalizers in the category of types Given `J : MultispanShape`, `d : MultispanIndex J (Type u)` and `c : d.multispan.CoconeTypes`, we obtain a lemma `isMulticoequalizer_iff` which gives a criteria for `c` to be a colimit (i.e. a multicoequalizer): it restates in a more explicit manner the injectivity and surjectivity conditions for the map `d.multispan.descColimitType c : d.multispan.ColimitType → c.pt`. We deduce a definition `Set.isColimitOfMulticoequalizerDiagram` which shows that given `X : Type u`, a `MulticoequalizerDiagram` in `Set X` gives a multicoequalizer in the category of types. -/ universe w w' u namespace CategoryTheory.Functor.CoconeTypes open Limits lemma isMulticoequalizer_iff {J : MultispanShape.{w, w'}} {d : MultispanIndex J (Type u)} (c : d.multispan.CoconeTypes) : c.IsColimit ↔ (∀ (i₁ i₂ : J.R) (x₁ : d.right i₁) (x₂ : d.right i₂), c.ι (.right i₁) x₁ = c.ι (.right i₂) x₂ → d.multispan.ιColimitType (.right i₁) x₁ = d.multispan.ιColimitType (.right i₂) x₂) ∧ (∀ (x : c.pt), ∃ (i : J.R) (a : d.right i), c.ι (.right i) a = x) := by have (x : d.multispan.ColimitType) : ∃ (i : J.R) (a : d.right i), d.multispan.ιColimitType (.right i) a = x := by obtain ⟨(l | r), z, rfl⟩ := d.multispan.ιColimitType_jointly_surjective x · exact ⟨J.fst l, d.multispan.map (WalkingMultispan.Hom.fst l) z, by rw [ιColimitType_map]⟩ · exact ⟨r, z, by simp⟩ constructor · intro hc refine ⟨fun i₁ i₂ x₁ x₂ h ↦ ?_, ?_⟩ · simp only [← descColimitType_ιColimitType_apply] at h exact hc.bijective.1 h · intro x obtain ⟨y, rfl⟩ := hc.bijective.2 x obtain ⟨i, z, rfl⟩ := this y exact ⟨i, z, by simp⟩ · rintro ⟨h₁, h₂⟩ refine ⟨fun x₁ x₂ h ↦ ?_, fun x ↦ ?_⟩ · obtain ⟨i₁, a₁, rfl⟩ := this x₁ obtain ⟨i₂, a₂, rfl⟩ := this x₂ exact h₁ _ _ _ _ h · obtain ⟨i, y, rfl⟩ := h₂ x exact ⟨d.multispan.ιColimitType (.right i) y, rfl⟩ end CategoryTheory.Functor.CoconeTypes open CompleteLattice CategoryTheory Limits namespace CategoryTheory.Limits.Types variable {X : Type u} {ι : Type w} {A : Set X} {U : ι → Set X} {V : ι → ι → Set X} /-- Given `X : Type u`, `A : Set X`, `U : ι → Set X` and `V : ι → ι → Set X` such that `MulticoequalizerDiagram A U V` holds, then in the category of types, `A` is the multicoequalizer of the `U i`s along the `V i j`s. -/ noncomputable def isColimitOfMulticoequalizerDiagram (c : MulticoequalizerDiagram A U V) : IsColimit (c.multicofork.map Set.functorToTypes) := by let e := (c.multispanIndex.map Set.functorToTypes).multispan apply _root_.Nonempty.some rw [Types.isColimit_iff_coconeTypesIsColimit, Functor.CoconeTypes.isMulticoequalizer_iff] refine ⟨fun i₁ i₂ ⟨x₁, h₁⟩ ⟨x₂, h₂⟩ h ↦ ?_, fun ⟨x, hx⟩ ↦ ?_⟩ · dsimp at i₁ i₂ h₁ h₂ obtain rfl : x₁ = x₂ := by simpa using h have eq₁ := e.ιColimitType_map (WalkingMultispan.Hom.fst (J := .prod ι) ⟨i₁, i₂⟩) ⟨x₁, by dsimp; rw [c.min_eq]; exact ⟨h₁, h₂⟩⟩ have eq₂ := e.ιColimitType_map (WalkingMultispan.Hom.snd (J := .prod ι) ⟨i₁, i₂⟩) ⟨x₁, by dsimp; rw [c.min_eq]; exact ⟨h₁, h₂⟩⟩ dsimp [e] at eq₁ eq₂ rw [eq₁, eq₂] · simp only [MulticoequalizerDiagram.multicofork_pt, ← c.iSup_eq, Set.iSup_eq_iUnion, Set.mem_iUnion] at hx obtain ⟨i, hi⟩ := hx exact ⟨i, ⟨x, hi⟩, rfl⟩ end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Pullbacks.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Pullbacks in the category of types In `Type*`, the pullback of `f : X ⟶ Z` and `g : Y ⟶ Z` is the subtype `{ p : X × Y // f p.1 = g p.2 }` of the product. We show some additional lemmas for pullbacks in the category of types. -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits.Types -- #synth HasPullbacks.{u} (Type u) instance : HasPullbacks.{u} (Type u) := -- FIXME does not work via `inferInstance` despite `#synth HasPullbacks.{u} (Type u)` succeeding. -- https://github.com/leanprover-community/mathlib4/issues/5752 -- inferInstance hasPullbacks_of_hasWidePullbacks.{u} (Type u) variable {X Y Z : Type u} {X' Y' Z' : Type v} variable (f : X ⟶ Z) (g : Y ⟶ Z) (f' : X' ⟶ Z') (g' : Y' ⟶ Z') /-- The usual explicit pullback in the category of types, as a subtype of the product. The full `LimitCone` data is bundled as `pullbackLimitCone f g`. -/ abbrev PullbackObj : Type u := { p : X × Y // f p.1 = g p.2 } -- `PullbackObj f g` comes with a coercion to the product type `X × Y`. example (p : PullbackObj f g) : X × Y := p /-- The explicit pullback cone on `PullbackObj f g`. This is bundled with the `IsLimit` data as `pullbackLimitCone f g`. -/ abbrev pullbackCone : Limits.PullbackCone f g := PullbackCone.mk (fun p : PullbackObj f g => p.1.1) (fun p => p.1.2) (funext fun p => p.2) /-- The explicit pullback in the category of types, bundled up as a `LimitCone` for given `f` and `g`. -/ @[simps] def pullbackLimitCone (f : X ⟶ Z) (g : Y ⟶ Z) : Limits.LimitCone (cospan f g) where cone := pullbackCone f g isLimit := PullbackCone.isLimitAux _ (fun s x => ⟨⟨s.fst x, s.snd x⟩, congr_fun s.condition x⟩) (by aesop) (by aesop) fun _ _ w => funext fun x => Subtype.ext <| Prod.ext (congr_fun (w WalkingCospan.left) x) (congr_fun (w WalkingCospan.right) x) end Types namespace PullbackCone variable {X Y S : Type v} {f : X ⟶ S} {g : Y ⟶ S} {c : PullbackCone f g} namespace IsLimit variable (hc : IsLimit c) /-- A limit pullback cone in the category of types identifies to the explicit pullback. -/ noncomputable def equivPullbackObj : c.pt ≃ Types.PullbackObj f g := (IsLimit.conePointUniqueUpToIso hc (Types.pullbackLimitCone f g).isLimit).toEquiv @[simp] lemma equivPullbackObj_apply_fst (x : c.pt) : (equivPullbackObj hc x).1.1 = c.fst x := congr_fun (IsLimit.conePointUniqueUpToIso_hom_comp hc (Types.pullbackLimitCone f g).isLimit .left) x @[simp] lemma equivPullbackObj_apply_snd (x : c.pt) : (equivPullbackObj hc x).1.2 = c.snd x := congr_fun (IsLimit.conePointUniqueUpToIso_hom_comp hc (Types.pullbackLimitCone f g).isLimit .right) x @[simp] lemma equivPullbackObj_symm_apply_fst (x : Types.PullbackObj f g) : c.fst ((equivPullbackObj hc).symm x) = x.1.1 := by obtain ⟨x, rfl⟩ := (equivPullbackObj hc).surjective x simp @[simp] lemma equivPullbackObj_symm_apply_snd (x : Types.PullbackObj f g) : c.snd ((equivPullbackObj hc).symm x) = x.1.2 := by obtain ⟨x, rfl⟩ := (equivPullbackObj hc).surjective x simp include hc in lemma type_ext {x y : c.pt} (h₁ : c.fst x = c.fst y) (h₂ : c.snd x = c.snd y) : x = y := (equivPullbackObj hc).injective (by ext <;> assumption) end IsLimit variable (c) /-- Given `c : PullbackCone f g` in the category of types, this is the canonical map `c.pt → Types.PullbackObj f g`. -/ @[simps coe_fst coe_snd] def toPullbackObj (x : c.pt) : Types.PullbackObj f g := ⟨⟨c.fst x, c.snd x⟩, congr_fun c.condition x⟩ /-- A pullback cone `c` in the category of types is limit iff the map `c.toPullbackObj : c.pt → Types.PullbackObj f g` is a bijection. -/ noncomputable def isLimitEquivBijective : IsLimit c ≃ Function.Bijective c.toPullbackObj where toFun h := (IsLimit.equivPullbackObj h).bijective invFun h := IsLimit.ofIsoLimit (Types.pullbackLimitCone f g).isLimit (Iso.symm (PullbackCone.ext (Equiv.ofBijective _ h).toIso)) left_inv _ := Subsingleton.elim _ _ end PullbackCone namespace Types section Pullback open CategoryTheory.Limits.WalkingCospan variable {W X Y Z : Type u} (f : X ⟶ Z) (g : Y ⟶ Z) /-- The pullback given by the instance `HasPullbacks (Type u)` is isomorphic to the explicit pullback object given by `PullbackObj`. -/ noncomputable def pullbackIsoPullback : pullback f g ≅ PullbackObj f g := (PullbackCone.IsLimit.equivPullbackObj (pullbackIsPullback f g)).toIso @[simp] theorem pullbackIsoPullback_hom_fst (p : pullback f g) : ((pullbackIsoPullback f g).hom p : X × Y).fst = (pullback.fst f g) p := PullbackCone.IsLimit.equivPullbackObj_apply_fst (pullbackIsPullback f g) p @[simp] theorem pullbackIsoPullback_hom_snd (p : pullback f g) : ((pullbackIsoPullback f g).hom p : X × Y).snd = (pullback.snd f g) p := PullbackCone.IsLimit.equivPullbackObj_apply_snd (pullbackIsPullback f g) p @[simp] theorem pullbackIsoPullback_inv_fst_apply (x : (Types.pullbackCone f g).pt) : (pullback.fst f g) ((pullbackIsoPullback f g).inv x) = (fun p => (p.1 : X × Y).fst) x := PullbackCone.IsLimit.equivPullbackObj_symm_apply_fst (pullbackIsPullback f g) x @[simp] theorem pullbackIsoPullback_inv_snd_apply (x : (Types.pullbackCone f g).pt) : (pullback.snd f g) ((pullbackIsoPullback f g).inv x) = (fun p => (p.1 : X × Y).snd) x := PullbackCone.IsLimit.equivPullbackObj_symm_apply_snd (pullbackIsPullback f g) x @[simp] theorem pullbackIsoPullback_inv_fst : (pullbackIsoPullback f g).inv ≫ pullback.fst _ _ = fun p => (p.1 : X × Y).fst := by aesop @[simp] theorem pullbackIsoPullback_inv_snd : (pullbackIsoPullback f g).inv ≫ pullback.snd _ _ = fun p => (p.1 : X × Y).snd := by aesop end Pullback end Types end CategoryTheory.Limits namespace CategoryTheory.Limits.Types variable {P X Y Z : Type u} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} lemma range_fst_of_isPullback (h : IsPullback fst snd f g) : Set.range fst = f ⁻¹' Set.range g := by let e := h.isoPullback ≪≫ Types.pullbackIsoPullback f g have : fst = _root_.Prod.fst ∘ Subtype.val ∘ e.hom := by ext p suffices fst p = pullback.fst f g (h.isoPullback.hom p) by simpa rw [← types_comp_apply h.isoPullback.hom (pullback.fst f g), IsPullback.isoPullback_hom_fst] rw [this, Set.range_comp, Set.range_comp, Set.range_eq_univ.mpr (surjective_of_epi e.hom)] ext simp [eq_comm] lemma range_snd_of_isPullback (h : IsPullback fst snd f g) : Set.range snd = g ⁻¹' Set.range f := by rw [range_fst_of_isPullback (IsPullback.flip h)] variable (f g) @[simp] lemma range_pullbackFst : Set.range (pullback.fst f g) = f ⁻¹' Set.range g := range_fst_of_isPullback (.of_hasPullback f g) @[simp] lemma range_pullbackSnd : Set.range (pullback.snd f g) = g ⁻¹' Set.range f := range_snd_of_isPullback (.of_hasPullback f g) end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Types/Coequalizers.lean
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.Logic.Function.Coequalizer import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Coequalizers in Type The coequalizer of a pair of maps `(f, g)` from `X` to `Y` is the quotient of `Y` by `∀ x : Y, f x ~ g x` -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits.Types variable {X Y Z : Type u} (f g : X ⟶ Y) /-- Show that the quotient by the relation generated by `f(x) ~ g(x)` is a coequalizer for the pair `(f, g)`. -/ def coequalizerColimit : Limits.ColimitCocone (parallelPair f g) where cocone := Cofork.ofπ (Function.Coequalizer.mk f g) (funext fun x => Function.Coequalizer.condition f g x) isColimit := Cofork.IsColimit.mk _ (fun s ↦ Function.Coequalizer.desc f g s.π s.condition) (fun _ ↦ rfl) (fun _ _ hm ↦ funext (fun x ↦ Quot.inductionOn x (congr_fun hm))) /-- If `π : Y ⟶ Z` is an coequalizer for `(f, g)`, and `U ⊆ Y` such that `f ⁻¹' U = g ⁻¹' U`, then `π ⁻¹' (π '' U) = U`. -/ theorem coequalizer_preimage_image_eq_of_preimage_eq (π : Y ⟶ Z) (e : f ≫ π = g ≫ π) (h : IsColimit (Cofork.ofπ π e)) (U : Set Y) (H : f ⁻¹' U = g ⁻¹' U) : π ⁻¹' (π '' U) = U := by have lem : ∀ x y, Function.Coequalizer.Rel f g x y → (x ∈ U ↔ y ∈ U) := by rintro _ _ ⟨x⟩ change x ∈ f ⁻¹' U ↔ x ∈ g ⁻¹' U rw [H] have eqv : _root_.Equivalence fun x y => x ∈ U ↔ y ∈ U := by aesop (add safe constructors _root_.Equivalence) ext constructor · rw [← show _ = π from h.comp_coconePointUniqueUpToIso_inv (coequalizerColimit f g).2 WalkingParallelPair.one] rintro ⟨y, hy, e'⟩ dsimp at e' replace e' := (mono_iff_injective (h.coconePointUniqueUpToIso (coequalizerColimit f g).isColimit).inv).mp inferInstance e' exact (eqv.eqvGen_iff.mp (Relation.EqvGen.mono lem (Quot.eqvGen_exact e'))).mp hy · exact fun hx => ⟨_, hx, rfl⟩ /-- The categorical coequalizer in `Type u` is the quotient by `f g ~ g x`. -/ noncomputable def coequalizerIso : coequalizer f g ≅ Function.Coequalizer f g := colimit.isoColimitCocone (coequalizerColimit f g) @[elementwise (attr := simp)] theorem coequalizerIso_π_comp_hom : coequalizer.π f g ≫ (coequalizerIso f g).hom = Function.Coequalizer.mk f g := colimit.isoColimitCocone_ι_hom (coequalizerColimit f g) WalkingParallelPair.one @[elementwise (attr := simp)] theorem coequalizerIso_quot_comp_inv : ↾Function.Coequalizer.mk f g ≫ (coequalizerIso f g).inv = coequalizer.π f g := rfl end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/FiniteProductsOfBinaryProducts.lean
import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products /-! # Constructing finite products from binary products and terminal. If a category has binary products and a terminal object then it has finite products. If a functor preserves binary products and the terminal object then it preserves finite products. ## TODO Provide the dual results. Show the analogous results for functors which reflect or create (co)limits. -/ universe v v' u u' noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits namespace CategoryTheory variable {J : Type v} [SmallCategory J] variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v'} D] /-- Given `n+1` objects of `C`, a fan for the last `n` with point `c₁.pt` and a binary fan on `c₁.pt` and `f 0`, we can build a fan for all `n+1`. In `extendFanIsLimit` we show that if the two given fans are limits, then this fan is also a limit. -/ @[simps!] def extendFan {n : ℕ} {f : Fin (n + 1) → C} (c₁ : Fan fun i : Fin n => f i.succ) (c₂ : BinaryFan (f 0) c₁.pt) : Fan f := Fan.mk c₂.pt (by refine Fin.cases ?_ ?_ · apply c₂.fst · intro i apply c₂.snd ≫ c₁.π.app ⟨i⟩) /-- Show that if the two given fans in `extendFan` are limits, then the constructed fan is also a limit. -/ def extendFanIsLimit {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Fan fun i : Fin n => f i.succ} {c₂ : BinaryFan (f 0) c₁.pt} (t₁ : IsLimit c₁) (t₂ : IsLimit c₂) : IsLimit (extendFan c₁ c₂) where lift s := by apply (BinaryFan.IsLimit.lift' t₂ (s.π.app ⟨0⟩) _).1 apply t₁.lift ⟨_, Discrete.natTrans fun ⟨i⟩ => s.π.app ⟨i.succ⟩⟩ fac := fun s ⟨j⟩ => by refine Fin.inductionOn j ?_ ?_ · apply (BinaryFan.IsLimit.lift' t₂ _ _).2.1 · rintro i - dsimp only [extendFan_π_app] rw [Fin.cases_succ, ← assoc, (BinaryFan.IsLimit.lift' t₂ _ _).2.2, t₁.fac] rfl uniq s m w := by apply BinaryFan.IsLimit.hom_ext t₂ · rw [(BinaryFan.IsLimit.lift' t₂ _ _).2.1] apply w ⟨0⟩ · rw [(BinaryFan.IsLimit.lift' t₂ _ _).2.2] apply t₁.uniq ⟨_, _⟩ rintro ⟨j⟩ rw [assoc] dsimp only [Discrete.natTrans_app] rw [← w ⟨j.succ⟩] dsimp only [extendFan_π_app] rw [Fin.cases_succ] section variable [HasBinaryProducts C] [HasTerminal C] /-- If `C` has a terminal object and binary products, then it has a product for objects indexed by `Fin n`. This is a helper lemma for `hasFiniteProductsOfHasBinaryAndTerminal`, which is more general than this. -/ private theorem hasProduct_fin : ∀ (n : ℕ) (f : Fin n → C), HasProduct f | 0 => fun _ => letI : HasLimitsOfShape (Discrete (Fin 0)) C := hasLimitsOfShape_of_equivalence (Discrete.equivalence.{0} finZeroEquiv'.symm) inferInstance | n + 1 => fun f => haveI := hasProduct_fin n HasLimit.mk ⟨_, extendFanIsLimit f (limit.isLimit _) (limit.isLimit _)⟩ /-- If `C` has a terminal object and binary products, then it has finite products. -/ theorem hasFiniteProducts_of_has_binary_and_terminal : HasFiniteProducts C := ⟨fun n => ⟨fun K => by let that : (Discrete.functor fun n => K.obj ⟨n⟩) ≅ K := Discrete.natIso fun ⟨_⟩ => Iso.refl _ rw [← hasLimit_iff_of_iso that] apply hasProduct_fin⟩⟩ end section Preserves variable (F : C ⥤ D) variable [PreservesLimitsOfShape (Discrete WalkingPair) F] variable [PreservesLimitsOfShape (Discrete.{0} PEmpty) F] variable [HasFiniteProducts.{v} C] /-- If `F` preserves the terminal object and binary products, then it preserves products indexed by `Fin n` for any `n`. -/ lemma preservesFinOfPreservesBinaryAndTerminal : ∀ (n : ℕ) (f : Fin n → C), PreservesLimit (Discrete.functor f) F | 0 => fun f => by letI : PreservesLimitsOfShape (Discrete (Fin 0)) F := preservesLimitsOfShape_of_equiv.{0, 0} (Discrete.equivalence finZeroEquiv'.symm) _ infer_instance | n + 1 => by haveI := preservesFinOfPreservesBinaryAndTerminal n intro f apply preservesLimit_of_preserves_limit_cone (extendFanIsLimit f (limit.isLimit _) (limit.isLimit _)) _ apply (isLimitMapConeFanMkEquiv _ _ _).symm _ let this := extendFanIsLimit (fun i => F.obj (f i)) (isLimitOfHasProductOfPreservesLimit F _) (isLimitOfHasBinaryProductOfPreservesLimit F _ _) refine IsLimit.ofIsoLimit this ?_ apply Cones.ext _ _ · apply Iso.refl _ rintro ⟨j⟩ refine Fin.inductionOn j ?_ ?_ · apply (Category.id_comp _).symm · rintro i _ dsimp [extendFan_π_app, Iso.refl_hom, Fan.mk_π_app] change F.map _ ≫ _ = 𝟙 _ ≫ _ simp only [id_comp, ← F.map_comp] rfl /-- If `F` preserves the terminal object and binary products then it preserves finite products. -/ lemma Limits.PreservesFiniteProducts.of_preserves_binary_and_terminal : PreservesFiniteProducts F where preserves n := by refine ⟨fun {K} ↦ ?_⟩ let that : (Discrete.functor fun n => K.obj ⟨n⟩) ≅ K := Discrete.natIso fun ⟨i⟩ => Iso.refl _ haveI := preservesFinOfPreservesBinaryAndTerminal F n fun n => K.obj ⟨n⟩ apply preservesLimit_of_iso_diagram F that @[deprecated PreservesFiniteProducts.of_preserves_binary_and_terminal (since := "2025-04-22")] lemma preservesShape_fin_of_preserves_binary_and_terminal (n : ℕ) : PreservesLimitsOfShape (Discrete (Fin n)) F := have : PreservesFiniteProducts F := .of_preserves_binary_and_terminal _; inferInstance end Preserves /-- Given `n+1` objects of `C`, a cofan for the last `n` with point `c₁.pt` and a binary cofan on `c₁.X` and `f 0`, we can build a cofan for all `n+1`. In `extendCofanIsColimit` we show that if the two given cofans are colimits, then this cofan is also a colimit. -/ @[simps!] def extendCofan {n : ℕ} {f : Fin (n + 1) → C} (c₁ : Cofan fun i : Fin n => f i.succ) (c₂ : BinaryCofan (f 0) c₁.pt) : Cofan f := Cofan.mk c₂.pt (by refine Fin.cases ?_ ?_ · apply c₂.inl · intro i apply c₁.ι.app ⟨i⟩ ≫ c₂.inr) /-- Show that if the two given cofans in `extendCofan` are colimits, then the constructed cofan is also a colimit. -/ def extendCofanIsColimit {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n => f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsColimit c₁) (t₂ : IsColimit c₂) : IsColimit (extendCofan c₁ c₂) where desc s := by apply (BinaryCofan.IsColimit.desc' t₂ (s.ι.app ⟨0⟩) _).1 apply t₁.desc ⟨_, Discrete.natTrans fun i => s.ι.app ⟨i.as.succ⟩⟩ fac s := by rintro ⟨j⟩ refine Fin.inductionOn j ?_ ?_ · apply (BinaryCofan.IsColimit.desc' t₂ _ _).2.1 · rintro i - dsimp only [extendCofan_ι_app] rw [Fin.cases_succ, assoc, (BinaryCofan.IsColimit.desc' t₂ _ _).2.2, t₁.fac] rfl uniq s m w := by apply BinaryCofan.IsColimit.hom_ext t₂ · rw [(BinaryCofan.IsColimit.desc' t₂ _ _).2.1] apply w ⟨0⟩ · rw [(BinaryCofan.IsColimit.desc' t₂ _ _).2.2] apply t₁.uniq ⟨_, _⟩ rintro ⟨j⟩ dsimp only [Discrete.natTrans_app] rw [← w ⟨j.succ⟩] dsimp only [extendCofan_ι_app] rw [Fin.cases_succ, assoc] section variable [HasBinaryCoproducts C] [HasInitial C] /-- If `C` has an initial object and binary coproducts, then it has a coproduct for objects indexed by `Fin n`. This is a helper lemma for `hasCofiniteProductsOfHasBinaryAndTerminal`, which is more general than this. -/ private theorem hasCoproduct_fin : ∀ (n : ℕ) (f : Fin n → C), HasCoproduct f | 0 => fun _ => letI : HasColimitsOfShape (Discrete (Fin 0)) C := hasColimitsOfShape_of_equivalence (Discrete.equivalence.{0} finZeroEquiv'.symm) inferInstance | n + 1 => fun f => haveI := hasCoproduct_fin n HasColimit.mk ⟨_, extendCofanIsColimit f (colimit.isColimit _) (colimit.isColimit _)⟩ /-- If `C` has an initial object and binary coproducts, then it has finite coproducts. -/ theorem hasFiniteCoproducts_of_has_binary_and_initial : HasFiniteCoproducts C := ⟨fun n => ⟨fun K => by let that : K ≅ Discrete.functor fun n => K.obj ⟨n⟩ := Discrete.natIso fun ⟨_⟩ => Iso.refl _ rw [hasColimit_iff_of_iso that] apply hasCoproduct_fin⟩⟩ end section Preserves variable (F : C ⥤ D) variable [PreservesColimitsOfShape (Discrete WalkingPair) F] variable [PreservesColimitsOfShape (Discrete.{0} PEmpty) F] variable [HasFiniteCoproducts.{v} C] /-- If `F` preserves the initial object and binary coproducts, then it preserves products indexed by `Fin n` for any `n`. -/ lemma preserves_fin_of_preserves_binary_and_initial : ∀ (n : ℕ) (f : Fin n → C), PreservesColimit (Discrete.functor f) F | 0 => fun f => by letI : PreservesColimitsOfShape (Discrete (Fin 0)) F := preservesColimitsOfShape_of_equiv.{0, 0} (Discrete.equivalence finZeroEquiv'.symm) _ infer_instance | n + 1 => by haveI := preserves_fin_of_preserves_binary_and_initial n intro f apply preservesColimit_of_preserves_colimit_cocone (extendCofanIsColimit f (colimit.isColimit _) (colimit.isColimit _)) _ apply (isColimitMapCoconeCofanMkEquiv _ _ _).symm _ let this := extendCofanIsColimit (fun i => F.obj (f i)) (isColimitOfHasCoproductOfPreservesColimit F _) (isColimitOfHasBinaryCoproductOfPreservesColimit F _ _) refine IsColimit.ofIsoColimit this ?_ apply Cocones.ext _ _ · apply Iso.refl _ rintro ⟨j⟩ refine Fin.inductionOn j ?_ ?_ · apply Category.comp_id · rintro i _ dsimp [extendCofan_ι_app, Iso.refl_hom, Cofan.mk_ι_app] rw [comp_id, ← F.map_comp] /-- If `F` preserves the initial object and binary coproducts, then it preserves colimits of shape `Discrete (Fin n)`. -/ lemma preservesShape_fin_of_preserves_binary_and_initial (n : ℕ) : PreservesColimitsOfShape (Discrete (Fin n)) F where preservesColimit {K} := by let that : (Discrete.functor fun n => K.obj ⟨n⟩) ≅ K := Discrete.natIso fun ⟨i⟩ => Iso.refl _ haveI := preserves_fin_of_preserves_binary_and_initial F n fun n => K.obj ⟨n⟩ apply preservesColimit_of_iso_diagram F that /-- If `F` preserves the initial object and binary coproducts then it preserves finite products. -/ lemma preservesFiniteCoproductsOfPreservesBinaryAndInitial (J : Type*) [Finite J] : PreservesColimitsOfShape (Discrete J) F := let ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin J have := preservesShape_fin_of_preserves_binary_and_initial F n preservesColimitsOfShape_of_equiv (Discrete.equivalence e).symm _ end Preserves end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/EpiMono.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Pullbacks /-! # Relating monomorphisms and epimorphisms to limits and colimits If `F` preserves (resp. reflects) pullbacks, then it preserves (resp. reflects) monomorphisms. We also provide the dual version for epimorphisms. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Category Limits variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] variable (F : C ⥤ D) /-- If `F` preserves pullbacks, then it preserves monomorphisms. -/ theorem preserves_mono_of_preservesLimit {X Y : C} (f : X ⟶ Y) [PreservesLimit (cospan f f) F] [Mono f] : Mono (F.map f) := by have := isLimitPullbackConeMapOfIsLimit F _ (PullbackCone.isLimitMkIdId f) simp_rw [F.map_id] at this apply PullbackCone.mono_of_isLimitMkIdId _ this instance (priority := 100) preservesMonomorphisms_of_preservesLimitsOfShape [PreservesLimitsOfShape WalkingCospan F] : F.PreservesMonomorphisms where preserves f _ := preserves_mono_of_preservesLimit F f /-- If `F` reflects pullbacks, then it reflects monomorphisms. -/ theorem reflects_mono_of_reflectsLimit {X Y : C} (f : X ⟶ Y) [ReflectsLimit (cospan f f) F] [Mono (F.map f)] : Mono f := by have := PullbackCone.isLimitMkIdId (F.map f) simp_rw [← F.map_id] at this apply PullbackCone.mono_of_isLimitMkIdId _ (isLimitOfIsLimitPullbackConeMap F _ this) instance (priority := 100) reflectsMonomorphisms_of_reflectsLimitsOfShape [ReflectsLimitsOfShape WalkingCospan F] : F.ReflectsMonomorphisms where reflects f _ := reflects_mono_of_reflectsLimit F f /-- If `F` preserves pushouts, then it preserves epimorphisms. -/ theorem preserves_epi_of_preservesColimit {X Y : C} (f : X ⟶ Y) [PreservesColimit (span f f) F] [Epi f] : Epi (F.map f) := by have := isColimitPushoutCoconeMapOfIsColimit F _ (PushoutCocone.isColimitMkIdId f) simp_rw [F.map_id] at this apply PushoutCocone.epi_of_isColimitMkIdId _ this instance (priority := 100) preservesEpimorphisms_of_preservesColimitsOfShape [PreservesColimitsOfShape WalkingSpan F] : F.PreservesEpimorphisms where preserves f _ := preserves_epi_of_preservesColimit F f /-- If `F` reflects pushouts, then it reflects epimorphisms. -/ theorem reflects_epi_of_reflectsColimit {X Y : C} (f : X ⟶ Y) [ReflectsColimit (span f f) F] [Epi (F.map f)] : Epi f := by have := PushoutCocone.isColimitMkIdId (F.map f) simp_rw [← F.map_id] at this apply PushoutCocone.epi_of_isColimitMkIdId _ (isColimitOfIsColimitPushoutCoconeMap F _ this) instance (priority := 100) reflectsEpimorphisms_of_reflectsColimitsOfShape [ReflectsColimitsOfShape WalkingSpan F] : F.ReflectsEpimorphisms where reflects f _ := reflects_epi_of_reflectsColimit F f end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/EventuallyConstant.lean
import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Limits.HasLimits /-! # Limits of eventually constant functors If `F : J ⥤ C` is a functor from a cofiltered category, and `j : J`, we introduce a property `F.IsEventuallyConstantTo j` which says that for any `f : i ⟶ j`, the induced morphism `F.map f` is an isomorphism. Under this assumption, it is shown that `F` admits `F.obj j` as a limit (`Functor.IsEventuallyConstantTo.isLimitCone`). A typeclass `Cofiltered.IsEventuallyConstant` is also introduced, and the dual results for filtered categories and colimits are also obtained. -/ namespace CategoryTheory open Category Limits variable {J C : Type*} [Category J] [Category C] (F : J ⥤ C) namespace Functor /-- A functor `F : J ⥤ C` is eventually constant to `j : J` if for any map `f : i ⟶ j`, the induced morphism `F.map f` is an isomorphism. If `J` is cofiltered, this implies `F` has a limit. -/ def IsEventuallyConstantTo (j : J) : Prop := ∀ ⦃i : J⦄ (f : i ⟶ j), IsIso (F.map f) /-- A functor `F : J ⥤ C` is eventually constant from `i : J` if for any map `f : i ⟶ j`, the induced morphism `F.map f` is an isomorphism. If `J` is filtered, this implies `F` has a colimit. -/ def IsEventuallyConstantFrom (i : J) : Prop := ∀ ⦃j : J⦄ (f : i ⟶ j), IsIso (F.map f) namespace IsEventuallyConstantTo variable {F} {i₀ : J} (h : F.IsEventuallyConstantTo i₀) include h lemma isIso_map {i j : J} (φ : i ⟶ j) (π : j ⟶ i₀) : IsIso (F.map φ) := by have := h π have := h (φ ≫ π) exact IsIso.of_isIso_fac_right (F.map_comp φ π).symm lemma precomp {j : J} (f : j ⟶ i₀) : F.IsEventuallyConstantTo j := fun _ φ ↦ h.isIso_map φ f section variable {i j : J} (φ : i ⟶ j) (hφ : Nonempty (j ⟶ i₀)) /-- The isomorphism `F.obj i ≅ F.obj j` induced by `φ : i ⟶ j`, when `h : F.IsEventuallyConstantTo i₀` and there exists a map `j ⟶ i₀`. -/ @[simps! hom] noncomputable def isoMap : F.obj i ≅ F.obj j := have := h.isIso_map φ hφ.some asIso (F.map φ) @[reassoc (attr := simp)] lemma isoMap_hom_inv_id : F.map φ ≫ (h.isoMap φ hφ).inv = 𝟙 _ := (h.isoMap φ hφ).hom_inv_id @[reassoc (attr := simp)] lemma isoMap_inv_hom_id : (h.isoMap φ hφ).inv ≫ F.map φ = 𝟙 _ := (h.isoMap φ hφ).inv_hom_id end variable [IsCofiltered J] open IsCofiltered /-- Auxiliary definition for `IsEventuallyConstantTo.cone`. -/ noncomputable def coneπApp (j : J) : F.obj i₀ ⟶ F.obj j := (h.isoMap (minToLeft i₀ j) ⟨𝟙 _⟩).inv ≫ F.map (minToRight i₀ j) lemma coneπApp_eq (j j' : J) (α : j' ⟶ i₀) (β : j' ⟶ j) : h.coneπApp j = (h.isoMap α ⟨𝟙 _⟩).inv ≫ F.map β := by obtain ⟨s, γ, δ, h₁, h₂⟩ := IsCofiltered.bowtie (IsCofiltered.minToRight i₀ j) β (IsCofiltered.minToLeft i₀ j) α dsimp [coneπApp] rw [← cancel_epi ((h.isoMap α ⟨𝟙 _⟩).hom), isoMap_hom, isoMap_hom_inv_id_assoc, ← cancel_epi (h.isoMap δ ⟨α⟩).hom, isoMap_hom, ← F.map_comp δ β, ← h₁, F.map_comp, ← F.map_comp_assoc, ← h₂, F.map_comp_assoc, isoMap_hom_inv_id_assoc] @[simp] lemma coneπApp_eq_id : h.coneπApp i₀ = 𝟙 _ := by rw [h.coneπApp_eq i₀ i₀ (𝟙 _) (𝟙 _), h.isoMap_inv_hom_id] /-- Given `h : F.IsEventuallyConstantTo i₀`, this is the (limit) cone for `F` whose point is `F.obj i₀`. -/ @[simps] noncomputable def cone : Cone F where pt := F.obj i₀ π := { app := h.coneπApp naturality := fun j j' φ ↦ by dsimp rw [id_comp] let i := IsCofiltered.min i₀ j let α : i ⟶ i₀ := IsCofiltered.minToLeft _ _ let β : i ⟶ j := IsCofiltered.minToRight _ _ rw [h.coneπApp_eq j _ α β, assoc, h.coneπApp_eq j' _ α (β ≫ φ), map_comp] } /-- When `h : F.IsEventuallyConstantTo i₀`, the limit of `F` exists and is `F.obj i₀`. -/ noncomputable def isLimitCone : IsLimit h.cone where lift s := s.π.app i₀ fac s j := by dsimp [coneπApp] rw [← s.w (IsCofiltered.minToLeft i₀ j), ← s.w (IsCofiltered.minToRight i₀ j), assoc, isoMap_hom_inv_id_assoc] uniq s m hm := by simp only [← hm i₀, cone_π_app, coneπApp_eq_id, cone_pt, comp_id] lemma hasLimit : HasLimit F := ⟨_, h.isLimitCone⟩ lemma isIso_π_of_isLimit {c : Cone F} (hc : IsLimit c) : IsIso (c.π.app i₀) := by simp only [← IsLimit.conePointUniqueUpToIso_hom_comp hc h.isLimitCone i₀, cone_π_app, coneπApp_eq_id, cone_pt, comp_id] infer_instance /-- More general version of `isIso_π_of_isLimit`. -/ lemma isIso_π_of_isLimit' {c : Cone F} (hc : IsLimit c) (j : J) (π : j ⟶ i₀) : IsIso (c.π.app j) := (h.precomp π).isIso_π_of_isLimit hc end IsEventuallyConstantTo namespace IsEventuallyConstantFrom variable {F} {i₀ : J} (h : F.IsEventuallyConstantFrom i₀) include h lemma isIso_map {i j : J} (φ : i ⟶ j) (ι : i₀ ⟶ i) : IsIso (F.map φ) := by have := h ι have := h (ι ≫ φ) exact IsIso.of_isIso_fac_left (F.map_comp ι φ).symm lemma postcomp {j : J} (f : i₀ ⟶ j) : F.IsEventuallyConstantFrom j := fun _ φ ↦ h.isIso_map φ f section variable {i j : J} (φ : i ⟶ j) (hφ : Nonempty (i₀ ⟶ i)) /-- The isomorphism `F.obj i ≅ F.obj j` induced by `φ : i ⟶ j`, when `h : F.IsEventuallyConstantFrom i₀` and there exists a map `i₀ ⟶ i`. -/ @[simps! hom] noncomputable def isoMap : F.obj i ≅ F.obj j := have := h.isIso_map φ hφ.some asIso (F.map φ) @[reassoc (attr := simp)] lemma isoMap_hom_inv_id : F.map φ ≫ (h.isoMap φ hφ).inv = 𝟙 _ := (h.isoMap φ hφ).hom_inv_id @[reassoc (attr := simp)] lemma isoMap_inv_hom_id : (h.isoMap φ hφ).inv ≫ F.map φ = 𝟙 _ := (h.isoMap φ hφ).inv_hom_id end variable [IsFiltered J] open IsFiltered /-- Auxiliary definition for `IsEventuallyConstantFrom.cocone`. -/ noncomputable def coconeιApp (j : J) : F.obj j ⟶ F.obj i₀ := F.map (rightToMax i₀ j) ≫ (h.isoMap (leftToMax i₀ j) ⟨𝟙 _⟩).inv lemma coconeιApp_eq (j j' : J) (α : j ⟶ j') (β : i₀ ⟶ j') : h.coconeιApp j = F.map α ≫ (h.isoMap β ⟨𝟙 _⟩).inv := by obtain ⟨s, γ, δ, h₁, h₂⟩ := IsFiltered.bowtie (IsFiltered.leftToMax i₀ j) β (IsFiltered.rightToMax i₀ j) α dsimp [coconeιApp] rw [← cancel_mono ((h.isoMap β ⟨𝟙 _⟩).hom), assoc, assoc, isoMap_hom, isoMap_inv_hom_id, comp_id, ← cancel_mono (h.isoMap δ ⟨β⟩).hom, isoMap_hom, assoc, assoc, ← F.map_comp α δ, ← h₂, F.map_comp, ← F.map_comp β δ, ← h₁, F.map_comp, isoMap_inv_hom_id_assoc] @[simp] lemma coconeιApp_eq_id : h.coconeιApp i₀ = 𝟙 _ := by rw [h.coconeιApp_eq i₀ i₀ (𝟙 _) (𝟙 _), h.isoMap_hom_inv_id] /-- Given `h : F.IsEventuallyConstantFrom i₀`, this is the (limit) cocone for `F` whose point is `F.obj i₀`. -/ @[simps] noncomputable def cocone : Cocone F where pt := F.obj i₀ ι := { app := h.coconeιApp naturality := fun j j' φ ↦ by dsimp rw [comp_id] let i := IsFiltered.max i₀ j' let α : i₀ ⟶ i := IsFiltered.leftToMax _ _ let β : j' ⟶ i := IsFiltered.rightToMax _ _ rw [h.coconeιApp_eq j' _ β α, h.coconeιApp_eq j _ (φ ≫ β) α, map_comp, assoc] } /-- When `h : F.IsEventuallyConstantFrom i₀`, the colimit of `F` exists and is `F.obj i₀`. -/ noncomputable def isColimitCocone : IsColimit h.cocone where desc s := s.ι.app i₀ fac s j := by dsimp [coconeιApp] rw [← s.w (IsFiltered.rightToMax i₀ j), ← s.w (IsFiltered.leftToMax i₀ j), assoc, isoMap_inv_hom_id_assoc] uniq s m hm := by simp only [← hm i₀, cocone_ι_app, coconeιApp_eq_id, id_comp] lemma hasColimit : HasColimit F := ⟨_, h.isColimitCocone⟩ lemma isIso_ι_of_isColimit {c : Cocone F} (hc : IsColimit c) : IsIso (c.ι.app i₀) := by simp only [← IsColimit.comp_coconePointUniqueUpToIso_inv hc h.isColimitCocone i₀, cocone_ι_app, coconeιApp_eq_id, id_comp] infer_instance /-- More general version of `isIso_ι_of_isColimit`. -/ lemma isIso_ι_of_isColimit' {c : Cocone F} (hc : IsColimit c) (j : J) (ι : i₀ ⟶ j) : IsIso (c.ι.app j) := (h.postcomp ι).isIso_ι_of_isColimit hc end IsEventuallyConstantFrom end Functor namespace IsCofiltered /-- A functor `F : J ⥤ C` from a cofiltered category is eventually constant if there exists `j : J`, such that for any `f : i ⟶ j`, the induced map `F.map f` is an isomorphism. -/ class IsEventuallyConstant : Prop where exists_isEventuallyConstantTo : ∃ (j : J), F.IsEventuallyConstantTo j instance [hF : IsEventuallyConstant F] [IsCofiltered J] : HasLimit F := by obtain ⟨j, h⟩ := hF.exists_isEventuallyConstantTo exact h.hasLimit end IsCofiltered namespace IsFiltered /-- A functor `F : J ⥤ C` from a filtered category is eventually constant if there exists `i : J`, such that for any `f : i ⟶ j`, the induced map `F.map f` is an isomorphism. -/ class IsEventuallyConstant : Prop where exists_isEventuallyConstantFrom : ∃ (i : J), F.IsEventuallyConstantFrom i instance [hF : IsEventuallyConstant F] [IsFiltered J] : HasColimit F := by obtain ⟨j, h⟩ := hF.exists_isEventuallyConstantFrom exact h.hasColimit end IsFiltered end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/Filtered.lean
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Filtered import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Products /-! # Constructing colimits from finite colimits and filtered colimits We construct colimits of size `w` from finite colimits and filtered colimits of size `w`. Since `w`-sized colimits are constructed from coequalizers and `w`-sized coproducts, it suffices to construct `w`-sized coproducts from finite coproducts and `w`-sized filtered colimits. The idea is simple: to construct coproducts of shape `α`, we take the colimit of the filtered diagram of all coproducts of finite subsets of `α`. We also deduce the dual statement by invoking the original statement in `Cᵒᵖ`. -/ universe w v u noncomputable section open CategoryTheory Opposite variable {C : Type u} [Category.{v} C] {α : Type w} namespace CategoryTheory.Limits namespace CoproductsFromFiniteFiltered variable [HasFiniteCoproducts C] /-- If `C` has finite coproducts, a functor `Discrete α ⥤ C` lifts to a functor `Finset (Discrete α) ⥤ C` by taking coproducts. -/ @[simps!] def liftToFinsetObj (F : Discrete α ⥤ C) : Finset (Discrete α) ⥤ C where obj s := ∐ fun x : s => F.obj x map {_ Y} h := Sigma.desc fun y => Sigma.ι (fun (x : { x // x ∈ Y }) => F.obj x) ⟨y, h.down.down y.2⟩ /-- If `C` has finite coproducts and filtered colimits, we can construct arbitrary coproducts by taking the colimit of the diagram formed by the coproducts of finite sets over the indexing type. -/ @[simps!] def liftToFinsetColimitCocone [HasColimitsOfShape (Finset (Discrete α)) C] (F : Discrete α ⥤ C) : ColimitCocone F where cocone := { pt := colimit (liftToFinsetObj F) ι := Discrete.natTrans fun j => Sigma.ι (fun x : ({j} : Finset (Discrete α)) => F.obj x) ⟨j, by simp⟩ ≫ colimit.ι (liftToFinsetObj F) {j} } isColimit := { desc := fun s => colimit.desc (liftToFinsetObj F) { pt := s.pt ι := { app := fun _ => Sigma.desc fun x => s.ι.app x } } uniq := fun s m h => by apply colimit.hom_ext rintro t dsimp [liftToFinsetObj] apply colimit.hom_ext rintro ⟨⟨j, hj⟩⟩ convert h j using 1 · simp [← colimit.w (liftToFinsetObj F) ⟨⟨Finset.singleton_subset_iff.2 hj⟩⟩] rfl · simp } variable (C) (α) in /-- The functor taking a functor `Discrete α ⥤ C` to a functor `Finset (Discrete α) ⥤ C` by taking coproducts. -/ @[simps!] def liftToFinset : (Discrete α ⥤ C) ⥤ (Finset (Discrete α) ⥤ C) where obj := liftToFinsetObj map := fun β => { app := fun _ => Sigma.map (fun x => β.app x.val) } /-- The converse of the construction in `liftToFinsetColimitCocone`: we can form a cocone on the coproduct of `f` whose legs are the coproducts over the finite subsets of `α`. -/ @[simps!] def finiteSubcoproductsCocone (f : α → C) [HasCoproduct f] : Cocone (liftToFinsetObj (Discrete.functor f)) where pt := ∐ f ι := { app S := Sigma.desc fun s => Sigma.ι f _ } /-- The cocone `finiteSubcoproductsCocone` is a colimit cocone. -/ def isColimitFiniteSubproductsCocone (f : α → C) [HasColimitsOfShape (Finset (Discrete α)) C] [HasCoproduct f] : IsColimit (finiteSubcoproductsCocone f) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (IsColimit.coconePointUniqueUpToIso (liftToFinsetColimitCocone (Discrete.functor f)).isColimit (colimit.isColimit _) :) (by intro S simp only [liftToFinsetObj_obj, Discrete.functor_obj_eq_as, finiteSubcoproductsCocone_pt, colimit.cocone_x, Functor.const_obj_obj, colimit.cocone_ι, finiteSubcoproductsCocone_ι_app] ext j rw [← Category.assoc] convert IsColimit.comp_coconePointUniqueUpToIso_hom (liftToFinsetColimitCocone (Discrete.functor f)).isColimit (colimit.isColimit _) j · simp [← colimit.w (liftToFinsetObj _) (homOfLE (x := {j.1}) (y := S) (by simp))] · simp)) end CoproductsFromFiniteFiltered open CoproductsFromFiniteFiltered theorem hasCoproducts_of_finite_and_filtered [HasFiniteCoproducts C] [HasFilteredColimitsOfSize.{w, w} C] : HasCoproducts.{w} C := fun α => by classical exact ⟨fun F => HasColimit.mk (liftToFinsetColimitCocone F)⟩ theorem has_colimits_of_finite_and_filtered [HasFiniteColimits C] [HasFilteredColimitsOfSize.{w, w} C] : HasColimitsOfSize.{w, w} C := have : HasCoproducts.{w} C := hasCoproducts_of_finite_and_filtered has_colimits_of_hasCoequalizers_and_coproducts theorem hasProducts_of_finite_and_cofiltered [HasFiniteProducts C] [HasCofilteredLimitsOfSize.{w, w} C] : HasProducts.{w} C := have : HasCoproducts.{w} Cᵒᵖ := hasCoproducts_of_finite_and_filtered hasProducts_of_opposite theorem has_limits_of_finite_and_cofiltered [HasFiniteLimits C] [HasCofilteredLimitsOfSize.{w, w} C] : HasLimitsOfSize.{w, w} C := have : HasProducts.{w} C := hasProducts_of_finite_and_cofiltered has_limits_of_hasEqualizers_and_products namespace CoproductsFromFiniteFiltered section variable [HasFiniteCoproducts C] [HasColimitsOfShape (Finset (Discrete α)) C] [HasColimitsOfShape (Discrete α) C] /-- Helper construction for `liftToFinsetColimIso`. -/ @[reassoc] theorem liftToFinsetColimIso_aux (F : Discrete α ⥤ C) {J : Finset (Discrete α)} (j : J) : Sigma.ι (F.obj ·.val) j ≫ colimit.ι (liftToFinsetObj F) J ≫ (colimit.isoColimitCocone (liftToFinsetColimitCocone F)).inv = colimit.ι F j := by simp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] /-- The `liftToFinset` functor, precomposed with forming a colimit, is a coproduct on the original functor. -/ def liftToFinsetColimIso : liftToFinset C α ⋙ colim ≅ colim := NatIso.ofComponents (fun F => Iso.symm <| colimit.isoColimitCocone (liftToFinsetColimitCocone F)) (fun β => by simp only [Functor.comp_obj, colim_obj, Functor.comp_map, colim_map, Iso.symm_hom] ext J simp only [liftToFinset_obj_obj] ext j simp only [liftToFinset, ι_colimMap_assoc, liftToFinsetObj_obj, Discrete.functor_obj_eq_as, Discrete.natTrans_app, liftToFinsetColimIso_aux, liftToFinsetColimIso_aux_assoc, ι_colimMap]) end /-- `liftToFinset`, when composed with the evaluation functor, results in the whiskering composed with `colim`. -/ def liftToFinsetEvaluationIso [HasFiniteCoproducts C] (I : Finset (Discrete α)) : liftToFinset C α ⋙ (evaluation _ _).obj I ≅ (Functor.whiskeringLeft _ _ _).obj (Discrete.functor (·.val)) ⋙ colim (J := Discrete I) := NatIso.ofComponents (fun _ => HasColimit.isoOfNatIso (Discrete.natIso fun _ => Iso.refl _)) fun _ => by dsimp; ext; simp end CoproductsFromFiniteFiltered namespace ProductsFromFiniteCofiltered variable [HasFiniteProducts C] /-- If `C` has finite coproducts, a functor `Discrete α ⥤ C` lifts to a functor `Finset (Discrete α) ⥤ C` by taking coproducts. -/ @[simps!] def liftToFinsetObj (F : Discrete α ⥤ C) : (Finset (Discrete α))ᵒᵖ ⥤ C where obj s := ∏ᶜ (fun x : s.unop => F.obj x) map {Y _} h := Pi.lift fun y => Pi.π (fun (x : { x // x ∈ Y.unop }) => F.obj x) ⟨y, h.unop.down.down y.2⟩ /-- If `C` has finite coproducts and filtered colimits, we can construct arbitrary coproducts by taking the colimit of the diagram formed by the coproducts of finite sets over the indexing type. -/ @[simps!] def liftToFinsetLimitCone [HasLimitsOfShape (Finset (Discrete α))ᵒᵖ C] (F : Discrete α ⥤ C) : LimitCone F where cone := { pt := limit (liftToFinsetObj F) π := Discrete.natTrans fun j => limit.π (liftToFinsetObj F) ⟨{j}⟩ ≫ Pi.π _ (⟨j, by simp⟩ : ({j} : Finset (Discrete α))) } isLimit := { lift := fun s => limit.lift (liftToFinsetObj F) { pt := s.pt π := { app := fun _ => Pi.lift fun x => s.π.app x } } uniq := fun s m h => by apply limit.hom_ext rintro t dsimp [liftToFinsetObj] apply limit.hom_ext rintro ⟨⟨j, hj⟩⟩ convert h j using 1 · simp [← limit.w (liftToFinsetObj F) ⟨⟨⟨Finset.singleton_subset_iff.2 hj⟩⟩⟩] rfl · simp } /-- The converse of the construction in `liftToFinsetLimitCone`: we can form a cone on the product of `f` whose legs are the products over the finite subsets of `α`. -/ @[simps!] def finiteSubproductsCone (f : α → C) [HasProduct f] : Cone (liftToFinsetObj (Discrete.functor f)) where pt := ∏ᶜ f π := { app S := Pi.lift fun s => Pi.π f _ } /-- The cone `finiteSubproductsCone` is a limit cone. -/ def isLimitFiniteSubproductsCone (f : α → C) [HasLimitsOfShape (Finset (Discrete α))ᵒᵖ C] [HasProduct f] : IsLimit (finiteSubproductsCone f) := IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext (IsLimit.conePointUniqueUpToIso (liftToFinsetLimitCone (Discrete.functor f)).isLimit (limit.isLimit _) :) (by intro S simp only [limit.cone_x, Functor.const_obj_obj, liftToFinsetObj_obj, Discrete.functor_obj_eq_as, limit.cone_π, finiteSubproductsCone_pt, finiteSubproductsCone_π_app] ext j simp only [Discrete.functor_obj_eq_as, Category.assoc, limit.lift_π, Fan.mk_pt, Fan.mk_π_app, limit.conePointUniqueUpToIso_hom_comp, liftToFinsetLimitCone_cone_pt, Discrete.mk_as, liftToFinsetLimitCone_cone_π_app] simp [← limit.w (liftToFinsetObj _) (Quiver.Hom.op (homOfLE (x := {j.1}) (y := S.unop) (by simp)))])) variable (C) (α) /-- The functor taking a functor `Discrete α ⥤ C` to a functor `Finset (Discrete α) ⥤ C` by taking coproducts. -/ @[simps!] def liftToFinset : (Discrete α ⥤ C) ⥤ ((Finset (Discrete α))ᵒᵖ ⥤ C) where obj := liftToFinsetObj map := fun β => { app := fun _ => Pi.map (fun x => β.app x.val) } /-- The `liftToFinset` functor, precomposed with forming a colimit, is a coproduct on the original functor. -/ def liftToFinsetLimIso [HasLimitsOfShape (Finset (Discrete α))ᵒᵖ C] [HasLimitsOfShape (Discrete α) C] : liftToFinset C α ⋙ lim ≅ lim := NatIso.ofComponents (fun F => Iso.symm <| limit.isoLimitCone (liftToFinsetLimitCone F)) (fun β => by simp only [Functor.comp_obj, lim_obj, Functor.comp_map, lim_map, Iso.symm_hom] ext J simp [liftToFinset]) /-- `liftToFinset`, when composed with the evaluation functor, results in the whiskering composed with `colim`. -/ def liftToFinsetEvaluationIso (I : Finset (Discrete α)) : liftToFinset C α ⋙ (evaluation _ _).obj ⟨I⟩ ≅ (Functor.whiskeringLeft _ _ _).obj (Discrete.functor (·.val)) ⋙ lim (J := Discrete I) := NatIso.ofComponents (fun _ => HasLimit.isoOfNatIso (Discrete.natIso fun _ => Iso.refl _)) fun _ => by dsimp; ext; simp end ProductsFromFiniteCofiltered end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/LimitsOfProductsAndEqualizers.lean
import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts import Mathlib.CategoryTheory.Limits.Constructions.Equalizers import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Preserves.Creates.Finite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Creates import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Sigma /-! # Constructing limits from products and equalizers. If a category has all products, and all equalizers, then it has all limits. Similarly, if it has all finite products, and all equalizers, then it has all finite limits. If a functor preserves all products and equalizers, then it preserves all limits. Similarly, if it preserves all finite products and equalizers, then it preserves all finite limits. ## TODO Provide the dual results. Show the analogous results for functors which reflect or create (co)limits. -/ open CategoryTheory open Opposite namespace CategoryTheory.Limits universe w v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {J : Type w} [SmallCategory J] -- We hide the "implementation details" inside a namespace namespace HasLimitOfHasProductsOfHasEqualizers variable {F : J ⥤ C} {c₁ : Fan F.obj} {c₂ : Fan fun f : Σ p : J × J, p.1 ⟶ p.2 => F.obj f.1.2} (s t : c₁.pt ⟶ c₂.pt) /-- (Implementation) Given the appropriate product and equalizer cones, build the cone for `F` which is limiting if the given cones are also. -/ @[simps] def buildLimit (hs : ∀ f : Σ p : J × J, p.1 ⟶ p.2, s ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.1⟩ ≫ F.map f.2) (ht : ∀ f : Σ p : J × J, p.1 ⟶ p.2, t ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.2⟩) (i : Fork s t) : Cone F where pt := i.pt π := { app := fun _ => i.ι ≫ c₁.π.app ⟨_⟩ naturality := fun j₁ j₂ f => by dsimp rw [Category.id_comp, Category.assoc, ← hs ⟨⟨_, _⟩, f⟩, i.condition_assoc, ht] } variable (hs : ∀ f : Σ p : J × J, p.1 ⟶ p.2, s ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.1⟩ ≫ F.map f.2) (ht : ∀ f : Σ p : J × J, p.1 ⟶ p.2, t ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.2⟩) {i : Fork s t} /-- (Implementation) Show the cone constructed in `buildLimit` is limiting, provided the cones used in its construction are. -/ def buildIsLimit (t₁ : IsLimit c₁) (t₂ : IsLimit c₂) (hi : IsLimit i) : IsLimit (buildLimit s t hs ht i) where lift q := by refine hi.lift (Fork.ofι ?_ ?_) · refine t₁.lift (Fan.mk _ fun j => ?_) apply q.π.app j · apply t₂.hom_ext intro ⟨j⟩ simp [hs, ht] uniq q m w := hi.hom_ext (i.equalizer_ext (t₁.hom_ext fun j => by simpa using w j.1)) fac s j := by simp end HasLimitOfHasProductsOfHasEqualizers open HasLimitOfHasProductsOfHasEqualizers /-- Given the existence of the appropriate (possibly finite) products and equalizers, we can construct a limit cone for `F`. (This assumes the existence of all equalizers, which is technically stronger than needed.) -/ noncomputable def limitConeOfEqualizerAndProduct (F : J ⥤ C) [HasLimit (Discrete.functor F.obj)] [HasLimit (Discrete.functor fun f : Σ p : J × J, p.1 ⟶ p.2 => F.obj f.1.2)] [HasEqualizers C] : LimitCone F where cone := _ isLimit := buildIsLimit (Pi.lift fun f => limit.π (Discrete.functor F.obj) ⟨_⟩ ≫ F.map f.2) (Pi.lift fun f => limit.π (Discrete.functor F.obj) ⟨f.1.2⟩) (by simp) (by simp) (limit.isLimit _) (limit.isLimit _) (limit.isLimit _) /-- Given the existence of the appropriate (possibly finite) products and equalizers, we know a limit of `F` exists. (This assumes the existence of all equalizers, which is technically stronger than needed.) -/ theorem hasLimit_of_equalizer_and_product (F : J ⥤ C) [HasLimit (Discrete.functor F.obj)] [HasLimit (Discrete.functor fun f : Σ p : J × J, p.1 ⟶ p.2 => F.obj f.1.2)] [HasEqualizers C] : HasLimit F := HasLimit.mk (limitConeOfEqualizerAndProduct F) /-- A limit can be realised as a subobject of a product. -/ noncomputable def limitSubobjectProduct [HasLimitsOfSize.{w, w} C] (F : J ⥤ C) : limit F ⟶ ∏ᶜ fun j => F.obj j := have := hasFiniteLimits_of_hasLimitsOfSize C (limit.isoLimitCone (limitConeOfEqualizerAndProduct F)).hom ≫ equalizer.ι _ _ instance limitSubobjectProduct_mono [HasLimitsOfSize.{w, w} C] (F : J ⥤ C) : Mono (limitSubobjectProduct F) := mono_comp _ _ /-- Any category with products and equalizers has all limits. -/ @[stacks 002N] theorem has_limits_of_hasEqualizers_and_products [HasProducts.{w} C] [HasEqualizers C] : HasLimitsOfSize.{w, w} C := { has_limits_of_shape := fun _ _ => { has_limit := fun F => hasLimit_of_equalizer_and_product F } } /-- Any category with finite products and equalizers has all finite limits. -/ @[stacks 002O] theorem hasFiniteLimits_of_hasEqualizers_and_finite_products [HasFiniteProducts C] [HasEqualizers C] : HasFiniteLimits C where out _ := { has_limit := fun F => hasLimit_of_equalizer_and_product F } variable {D : Type u₂} [Category.{v₂} D] section variable [HasLimitsOfShape (Discrete J) C] [HasLimitsOfShape (Discrete (Σ p : J × J, p.1 ⟶ p.2)) C] [HasEqualizers C] variable (G : C ⥤ D) [PreservesLimitsOfShape WalkingParallelPair G] -- [PreservesFiniteProducts G] [PreservesLimitsOfShape (Discrete.{w} J) G] [PreservesLimitsOfShape (Discrete.{w} (Σ p : J × J, p.1 ⟶ p.2)) G] /-- If a functor preserves equalizers and the appropriate products, it preserves limits. -/ lemma preservesLimit_of_preservesEqualizers_and_product : PreservesLimitsOfShape J G where preservesLimit {K} := by let P := ∏ᶜ K.obj let Q := ∏ᶜ fun f : Σ p : J × J, p.fst ⟶ p.snd => K.obj f.1.2 let s : P ⟶ Q := Pi.lift fun f => limit.π (Discrete.functor K.obj) ⟨_⟩ ≫ K.map f.2 let t : P ⟶ Q := Pi.lift fun f => limit.π (Discrete.functor K.obj) ⟨f.1.2⟩ let I := equalizer s t let i : I ⟶ P := equalizer.ι s t apply preservesLimit_of_preserves_limit_cone (buildIsLimit s t (by simp [P, s]) (by simp [P, t]) (limit.isLimit _) (limit.isLimit _) (limit.isLimit _)) apply IsLimit.ofIsoLimit (buildIsLimit _ _ _ _ _ _ _) _ · exact Fan.mk _ fun j => G.map (Pi.π _ j) · exact Fan.mk (G.obj Q) fun f => G.map (Pi.π _ f) · apply G.map s · apply G.map t · intro f dsimp [P, Q, s, Fan.mk] simp only [← G.map_comp, limit.lift_π] congr · intro f dsimp [P, Q, t, Fan.mk] simp only [← G.map_comp, limit.lift_π] apply congrArg G.map dsimp · apply Fork.ofι (G.map i) rw [← G.map_comp, ← G.map_comp] apply congrArg G.map exact equalizer.condition s t · apply isLimitOfHasProductOfPreservesLimit · apply isLimitOfHasProductOfPreservesLimit · apply isLimitForkMapOfIsLimit apply equalizerIsEqualizer · refine Cones.ext (Iso.refl _) ?_ intro j; dsimp [P, Q, I, i]; simp end /-- If G preserves equalizers and finite products, it preserves finite limits. -/ lemma preservesFiniteLimits_of_preservesEqualizers_and_finiteProducts [HasEqualizers C] [HasFiniteProducts C] (G : C ⥤ D) [PreservesLimitsOfShape WalkingParallelPair G] [PreservesFiniteProducts G] : PreservesFiniteLimits G where preservesFiniteLimits := by intros apply preservesLimit_of_preservesEqualizers_and_product /-- If G preserves equalizers and products, it preserves all limits. -/ lemma preservesLimits_of_preservesEqualizers_and_products [HasEqualizers C] [HasProducts.{w} C] (G : C ⥤ D) [PreservesLimitsOfShape WalkingParallelPair G] [∀ J, PreservesLimitsOfShape (Discrete.{w} J) G] : PreservesLimitsOfSize.{w, w} G where preservesLimitsOfShape := preservesLimit_of_preservesEqualizers_and_product G section variable [HasLimitsOfShape (Discrete J) D] [HasLimitsOfShape (Discrete (Σ p : J × J, p.1 ⟶ p.2)) D] [HasEqualizers D] variable (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesLimitsOfShape WalkingParallelPair G] [CreatesLimitsOfShape (Discrete.{w} J) G] [CreatesLimitsOfShape (Discrete.{w} (Σ p : J × J, p.1 ⟶ p.2)) G] attribute [local instance] preservesLimit_of_preservesEqualizers_and_product in /-- If a functor creates equalizers and the appropriate products, it creates limits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating limits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsLimitsOfShapeOfCreatesEqualizersAndProducts : CreatesLimitsOfShape J G where CreatesLimit {K} := have : HasLimitsOfShape (Discrete J) C := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape G have : HasLimitsOfShape (Discrete (Σ p : J × J, p.1 ⟶ p.2)) C := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape G have : HasEqualizers C := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape G have : HasLimit K := hasLimit_of_equalizer_and_product K createsLimitOfReflectsIsomorphismsOfPreserves end /-- If a functor creates equalizers and finite products, it creates finite limits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating limits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsFiniteLimitsOfCreatesEqualizersAndFiniteProducts [HasEqualizers D] [HasFiniteProducts D] (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesLimitsOfShape WalkingParallelPair G] [CreatesFiniteProducts G] : CreatesFiniteLimits G where createsFiniteLimits _ _ _ := createsLimitsOfShapeOfCreatesEqualizersAndProducts G /-- If a functor creates equalizers and products, it creates limits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating limits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsLimitsOfSizeOfCreatesEqualizersAndProducts [HasEqualizers D] [HasProducts.{w} D] (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesLimitsOfShape WalkingParallelPair G] [∀ J, CreatesLimitsOfShape (Discrete.{w} J) G] : CreatesLimitsOfSize.{w, w} G where CreatesLimitsOfShape := createsLimitsOfShapeOfCreatesEqualizersAndProducts G theorem hasFiniteLimits_of_hasTerminal_and_pullbacks [HasTerminal C] [HasPullbacks C] : HasFiniteLimits C := @hasFiniteLimits_of_hasEqualizers_and_finite_products C _ (@hasFiniteProducts_of_has_binary_and_terminal C _ (hasBinaryProducts_of_hasTerminal_and_pullbacks C) inferInstance) (@hasEqualizers_of_hasPullbacks_and_binary_products C _ (hasBinaryProducts_of_hasTerminal_and_pullbacks C) inferInstance) /-- If G preserves terminal objects and pullbacks, it preserves all finite limits. -/ lemma preservesFiniteLimits_of_preservesTerminal_and_pullbacks [HasTerminal C] [HasPullbacks C] (G : C ⥤ D) [PreservesLimitsOfShape (Discrete.{0} PEmpty) G] [PreservesLimitsOfShape WalkingCospan G] : PreservesFiniteLimits G := by have : HasFiniteLimits C := hasFiniteLimits_of_hasTerminal_and_pullbacks have : PreservesLimitsOfShape (Discrete WalkingPair) G := preservesBinaryProducts_of_preservesTerminal_and_pullbacks G have : PreservesLimitsOfShape WalkingParallelPair G := preservesEqualizers_of_preservesPullbacks_and_binaryProducts G have : PreservesFiniteProducts G := .of_preserves_binary_and_terminal _ exact preservesFiniteLimits_of_preservesEqualizers_and_finiteProducts G attribute [local instance] preservesFiniteLimits_of_preservesTerminal_and_pullbacks in /-- If a functor creates terminal objects and pullbacks, it creates finite limits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating limits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsFiniteLimitsOfCreatesTerminalAndPullbacks [HasTerminal D] [HasPullbacks D] (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesLimitsOfShape (Discrete.{0} PEmpty) G] [CreatesLimitsOfShape WalkingCospan G] : CreatesFiniteLimits G where createsFiniteLimits _ _ _ := { CreatesLimit := have : HasTerminal C := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape G have : HasPullbacks C := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape G have : HasFiniteLimits C := hasFiniteLimits_of_hasTerminal_and_pullbacks createsLimitOfReflectsIsomorphismsOfPreserves } /-! We now dualize the above constructions, resorting to copy-paste. -/ -- We hide the "implementation details" inside a namespace namespace HasColimitOfHasCoproductsOfHasCoequalizers variable {F : J ⥤ C} {c₁ : Cofan fun f : Σ p : J × J, p.1 ⟶ p.2 => F.obj f.1.1} {c₂ : Cofan F.obj} (s t : c₁.pt ⟶ c₂.pt) /-- (Implementation) Given the appropriate coproduct and coequalizer cocones, build the cocone for `F` which is colimiting if the given cocones are also. -/ @[simps] def buildColimit (hs : ∀ f : Σ p : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ s = F.map f.2 ≫ c₂.ι.app ⟨f.1.2⟩) (ht : ∀ f : Σ p : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ t = c₂.ι.app ⟨f.1.1⟩) (i : Cofork s t) : Cocone F where pt := i.pt ι := { app := fun _ => c₂.ι.app ⟨_⟩ ≫ i.π naturality := fun j₁ j₂ f => by dsimp have reassoced (f : (p : J × J) × (p.fst ⟶ p.snd)) {W : C} {h : _ ⟶ W} : c₁.ι.app ⟨f⟩ ≫ s ≫ h = F.map f.snd ≫ c₂.ι.app ⟨f.fst.snd⟩ ≫ h := by simp only [← Category.assoc, eq_whisker (hs f)] rw [Category.comp_id, ← reassoced ⟨⟨_, _⟩, f⟩, i.condition, ← Category.assoc, ht] } variable (hs : ∀ f : Σ p : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ s = F.map f.2 ≫ c₂.ι.app ⟨f.1.2⟩) (ht : ∀ f : Σ p : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ t = c₂.ι.app ⟨f.1.1⟩) {i : Cofork s t} /-- (Implementation) Show the cocone constructed in `buildColimit` is colimiting, provided the cocones used in its construction are. -/ def buildIsColimit (t₁ : IsColimit c₁) (t₂ : IsColimit c₂) (hi : IsColimit i) : IsColimit (buildColimit s t hs ht i) where desc q := by refine hi.desc (Cofork.ofπ ?_ ?_) · refine t₂.desc (Cofan.mk _ fun j => ?_) apply q.ι.app j · apply t₁.hom_ext intro ⟨j⟩ have reassoced_s (f : (p : J × J) × (p.fst ⟶ p.snd)) {W : C} (h : _ ⟶ W) : c₁.ι.app ⟨f⟩ ≫ s ≫ h = F.map f.snd ≫ c₂.ι.app ⟨f.fst.snd⟩ ≫ h := by simp only [← Category.assoc] apply eq_whisker (hs f) have reassoced_t (f : (p : J × J) × (p.fst ⟶ p.snd)) {W : C} (h : _ ⟶ W) : c₁.ι.app ⟨f⟩ ≫ t ≫ h = c₂.ι.app ⟨f.fst.fst⟩ ≫ h := by simp only [← Category.assoc] apply eq_whisker (ht f) simp [reassoced_s, reassoced_t] uniq q m w := hi.hom_ext (i.coequalizer_ext (t₂.hom_ext fun j => by simpa using w j.1)) fac s j := by simp end HasColimitOfHasCoproductsOfHasCoequalizers open HasColimitOfHasCoproductsOfHasCoequalizers /-- Given the existence of the appropriate (possibly finite) coproducts and coequalizers, we can construct a colimit cocone for `F`. (This assumes the existence of all coequalizers, which is technically stronger than needed.) -/ noncomputable def colimitCoconeOfCoequalizerAndCoproduct (F : J ⥤ C) [HasColimit (Discrete.functor F.obj)] [HasColimit (Discrete.functor fun f : Σ p : J × J, p.1 ⟶ p.2 => F.obj f.1.1)] [HasCoequalizers C] : ColimitCocone F where cocone := _ isColimit := buildIsColimit (Sigma.desc fun f => F.map f.2 ≫ colimit.ι (Discrete.functor F.obj) ⟨f.1.2⟩) (Sigma.desc fun f => colimit.ι (Discrete.functor F.obj) ⟨f.1.1⟩) (by simp) (by simp) (colimit.isColimit _) (colimit.isColimit _) (colimit.isColimit _) /-- Given the existence of the appropriate (possibly finite) coproducts and coequalizers, we know a colimit of `F` exists. (This assumes the existence of all coequalizers, which is technically stronger than needed.) -/ theorem hasColimit_of_coequalizer_and_coproduct (F : J ⥤ C) [HasColimit (Discrete.functor F.obj)] [HasColimit (Discrete.functor fun f : Σ p : J × J, p.1 ⟶ p.2 => F.obj f.1.1)] [HasCoequalizers C] : HasColimit F := HasColimit.mk (colimitCoconeOfCoequalizerAndCoproduct F) /-- A colimit can be realised as a quotient of a coproduct. -/ noncomputable def colimitQuotientCoproduct [HasColimitsOfSize.{w, w} C] (F : J ⥤ C) : ∐ (fun j => F.obj j) ⟶ colimit F := have := hasFiniteColimits_of_hasColimitsOfSize C coequalizer.π _ _ ≫ (colimit.isoColimitCocone (colimitCoconeOfCoequalizerAndCoproduct F)).inv instance colimitQuotientCoproduct_epi [HasColimitsOfSize.{w, w} C] (F : J ⥤ C) : Epi (colimitQuotientCoproduct F) := epi_comp _ _ /-- Any category with coproducts and coequalizers has all colimits. -/ @[stacks 002P] theorem has_colimits_of_hasCoequalizers_and_coproducts [HasCoproducts.{w} C] [HasCoequalizers C] : HasColimitsOfSize.{w, w} C where has_colimits_of_shape := fun _ _ => { has_colimit := fun F => hasColimit_of_coequalizer_and_coproduct F } /-- Any category with finite coproducts and coequalizers has all finite colimits. -/ @[stacks 002Q] theorem hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts [HasFiniteCoproducts C] [HasCoequalizers C] : HasFiniteColimits C where out _ := { has_colimit := fun F => hasColimit_of_coequalizer_and_coproduct F } section variable [HasColimitsOfShape (Discrete.{w} J) C] [HasColimitsOfShape (Discrete.{w} (Σ p : J × J, p.1 ⟶ p.2)) C] [HasCoequalizers C] variable (G : C ⥤ D) [PreservesColimitsOfShape WalkingParallelPair G] [PreservesColimitsOfShape (Discrete.{w} J) G] [PreservesColimitsOfShape (Discrete.{w} (Σ p : J × J, p.1 ⟶ p.2)) G] /-- If a functor preserves coequalizers and the appropriate coproducts, it preserves colimits. -/ lemma preservesColimit_of_preservesCoequalizers_and_coproduct : PreservesColimitsOfShape J G where preservesColimit {K} := by let P := ∐ K.obj let Q := ∐ fun f : Σ p : J × J, p.fst ⟶ p.snd => K.obj f.1.1 let s : Q ⟶ P := Sigma.desc fun f => K.map f.2 ≫ colimit.ι (Discrete.functor K.obj) ⟨_⟩ let t : Q ⟶ P := Sigma.desc fun f => colimit.ι (Discrete.functor K.obj) ⟨f.1.1⟩ let I := coequalizer s t let i : P ⟶ I := coequalizer.π s t apply preservesColimit_of_preserves_colimit_cocone (buildIsColimit s t (by simp [P, s]) (by simp [P, t]) (colimit.isColimit _) (colimit.isColimit _) (colimit.isColimit _)) apply IsColimit.ofIsoColimit (buildIsColimit _ _ _ _ _ _ _) _ · refine Cofan.mk (G.obj Q) fun j => G.map ?_ apply Sigma.ι _ j -- fun j => G.map (Sigma.ι _ j) · exact Cofan.mk _ fun f => G.map (Sigma.ι _ f) · apply G.map s · apply G.map t · intro f dsimp [P, Q, s, Cofan.mk] simp only [← G.map_comp, colimit.ι_desc] congr · intro f dsimp [P, Q, t, Cofan.mk] simp only [← G.map_comp, colimit.ι_desc] dsimp · refine Cofork.ofπ (G.map i) ?_ rw [← G.map_comp, ← G.map_comp] apply congrArg G.map apply coequalizer.condition · apply isColimitOfHasCoproductOfPreservesColimit · apply isColimitOfHasCoproductOfPreservesColimit · apply isColimitCoforkMapOfIsColimit apply coequalizerIsCoequalizer refine Cocones.ext (Iso.refl _) ?_ intro j dsimp [P, Q, I, i] simp end /-- If G preserves coequalizers and finite coproducts, it preserves finite colimits. -/ lemma preservesFiniteColimits_of_preservesCoequalizers_and_finiteCoproducts [HasCoequalizers C] [HasFiniteCoproducts C] (G : C ⥤ D) [PreservesColimitsOfShape WalkingParallelPair G] [PreservesFiniteCoproducts G] : PreservesFiniteColimits G where preservesFiniteColimits := by intro J sJ fJ apply preservesColimit_of_preservesCoequalizers_and_coproduct /-- If G preserves coequalizers and coproducts, it preserves all colimits. -/ lemma preservesColimits_of_preservesCoequalizers_and_coproducts [HasCoequalizers C] [HasCoproducts.{w} C] (G : C ⥤ D) [PreservesColimitsOfShape WalkingParallelPair G] [∀ J, PreservesColimitsOfShape (Discrete.{w} J) G] : PreservesColimitsOfSize.{w, w} G where preservesColimitsOfShape := preservesColimit_of_preservesCoequalizers_and_coproduct G section variable [HasColimitsOfShape (Discrete J) D] [HasColimitsOfShape (Discrete (Σ p : J × J, p.1 ⟶ p.2)) D] [HasCoequalizers D] variable (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesColimitsOfShape WalkingParallelPair G] [CreatesColimitsOfShape (Discrete.{w} J) G] [CreatesColimitsOfShape (Discrete.{w} (Σ p : J × J, p.1 ⟶ p.2)) G] attribute [local instance] preservesColimit_of_preservesCoequalizers_and_coproduct in /-- If a functor creates coequalizers and the appropriate coproducts, it creates colimits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating colimits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsColimitsOfShapeOfCreatesCoequalizersAndCoproducts : CreatesColimitsOfShape J G where CreatesColimit {K} := have : HasColimitsOfShape (Discrete J) C := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape G have : HasColimitsOfShape (Discrete (Σ p : J × J, p.1 ⟶ p.2)) C := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape G have : HasCoequalizers C := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape G have : HasColimit K := hasColimit_of_coequalizer_and_coproduct K createsColimitOfReflectsIsomorphismsOfPreserves end /-- If a functor creates coequalizers and finite coproducts, it creates finite colimits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating colimits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsFiniteColimitsOfCreatesCoequalizersAndFiniteCoproducts [HasCoequalizers D] [HasFiniteCoproducts D] (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesColimitsOfShape WalkingParallelPair G] [CreatesFiniteCoproducts G] : CreatesFiniteColimits G where createsFiniteColimits _ _ _ := createsColimitsOfShapeOfCreatesCoequalizersAndCoproducts G /-- If a functor creates coequalizers and coproducts, it creates colimits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating colimits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsColimitsOfSizeOfCreatesCoequalizersAndCoproducts [HasCoequalizers D] [HasCoproducts.{w} D] (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesColimitsOfShape WalkingParallelPair G] [∀ J, CreatesColimitsOfShape (Discrete.{w} J) G] : CreatesColimitsOfSize.{w, w} G where CreatesColimitsOfShape := createsColimitsOfShapeOfCreatesCoequalizersAndCoproducts G theorem hasFiniteColimits_of_hasInitial_and_pushouts [HasInitial C] [HasPushouts C] : HasFiniteColimits C := @hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts C _ (@hasFiniteCoproducts_of_has_binary_and_initial C _ (hasBinaryCoproducts_of_hasInitial_and_pushouts C) inferInstance) (@hasCoequalizers_of_hasPushouts_and_binary_coproducts C _ (hasBinaryCoproducts_of_hasInitial_and_pushouts C) inferInstance) /-- If G preserves initial objects and pushouts, it preserves all finite colimits. -/ lemma preservesFiniteColimits_of_preservesInitial_and_pushouts [HasInitial C] [HasPushouts C] (G : C ⥤ D) [PreservesColimitsOfShape (Discrete.{0} PEmpty) G] [PreservesColimitsOfShape WalkingSpan G] : PreservesFiniteColimits G := by haveI : HasFiniteColimits C := hasFiniteColimits_of_hasInitial_and_pushouts haveI : PreservesColimitsOfShape (Discrete WalkingPair) G := preservesBinaryCoproducts_of_preservesInitial_and_pushouts G haveI : PreservesColimitsOfShape (WalkingParallelPair) G := (preservesCoequalizers_of_preservesPushouts_and_binaryCoproducts G) refine @preservesFiniteColimits_of_preservesCoequalizers_and_finiteCoproducts _ _ _ _ _ _ G _ ?_ refine ⟨fun _ ↦ ?_⟩ apply preservesFiniteCoproductsOfPreservesBinaryAndInitial G attribute [local instance] preservesFiniteColimits_of_preservesInitial_and_pushouts in /-- If a functor creates initial objects and pushouts, it creates finite colimits. We additionally require the rather strong condition that the functor reflects isomorphisms. It is unclear whether the statement remains true without this condition. There are various definitions of "creating colimits" in the literature, and whether or not the condition can be dropped seems to depend on the specific definition that is used. -/ noncomputable def createsFiniteColimitsOfCreatesInitialAndPushouts [HasInitial D] [HasPushouts D] (G : C ⥤ D) [G.ReflectsIsomorphisms] [CreatesColimitsOfShape (Discrete.{0} PEmpty) G] [CreatesColimitsOfShape WalkingSpan G] : CreatesFiniteColimits G where createsFiniteColimits _ _ _ := { CreatesColimit := have : HasInitial C := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape G have : HasPushouts C := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape G have : HasFiniteColimits C := hasFiniteColimits_of_hasInitial_and_pushouts createsColimitOfReflectsIsomorphismsOfPreserves } end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/Equalizers.lean
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts /-! # Constructing equalizers from pullbacks and binary products. If a category has pullbacks and binary products, then it has equalizers. TODO: generalize universe -/ noncomputable section universe v v' u u' open CategoryTheory CategoryTheory.Category namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v'} D] (G : C ⥤ D) -- We hide the "implementation details" inside a namespace namespace HasEqualizersOfHasPullbacksAndBinaryProducts variable [HasBinaryProducts C] [HasPullbacks C] /-- Define the equalizing object -/ abbrev constructEqualizer (F : WalkingParallelPair ⥤ C) : C := pullback (prod.lift (𝟙 _) (F.map WalkingParallelPairHom.left)) (prod.lift (𝟙 _) (F.map WalkingParallelPairHom.right)) /-- Define the equalizing morphism -/ abbrev pullbackFst (F : WalkingParallelPair ⥤ C) : constructEqualizer F ⟶ F.obj WalkingParallelPair.zero := pullback.fst _ _ theorem pullbackFst_eq_pullback_snd (F : WalkingParallelPair ⥤ C) : pullbackFst F = pullback.snd _ _ := by convert (eq_whisker pullback.condition Limits.prod.fst : (_ : constructEqualizer F ⟶ F.obj WalkingParallelPair.zero) = _) <;> simp /-- Define the equalizing cone -/ abbrev equalizerCone (F : WalkingParallelPair ⥤ C) : Cone F := Cone.ofFork (Fork.ofι (pullbackFst F) (by conv_rhs => rw [pullbackFst_eq_pullback_snd] convert (eq_whisker pullback.condition Limits.prod.snd : (_ : constructEqualizer F ⟶ F.obj WalkingParallelPair.one) = _) using 1 <;> simp)) /-- Show the equalizing cone is a limit -/ def equalizerConeIsLimit (F : WalkingParallelPair ⥤ C) : IsLimit (equalizerCone F) where lift c := pullback.lift (c.π.app _) (c.π.app _) fac := by rintro c (_ | _) <;> simp uniq := by intro c _ J have J0 := J WalkingParallelPair.zero; simp at J0 apply pullback.hom_ext · rwa [limit.lift_π] · erw [limit.lift_π, ← J0, pullbackFst_eq_pullback_snd] end HasEqualizersOfHasPullbacksAndBinaryProducts open HasEqualizersOfHasPullbacksAndBinaryProducts -- This is not an instance, as it is not always how one wants to construct equalizers! /-- Any category with pullbacks and binary products, has equalizers. -/ theorem hasEqualizers_of_hasPullbacks_and_binary_products [HasBinaryProducts C] [HasPullbacks C] : HasEqualizers C := { has_limit := fun F => HasLimit.mk { cone := equalizerCone F isLimit := equalizerConeIsLimit F } } attribute [local instance] hasPullback_of_preservesPullback /-- A functor that preserves pullbacks and binary products also presrves equalizers. -/ lemma preservesEqualizers_of_preservesPullbacks_and_binaryProducts [HasBinaryProducts C] [HasPullbacks C] [PreservesLimitsOfShape (Discrete WalkingPair) G] [PreservesLimitsOfShape WalkingCospan G] : PreservesLimitsOfShape WalkingParallelPair G := ⟨fun {K} => preservesLimit_of_preserves_limit_cone (equalizerConeIsLimit K) <| { lift := fun c => by refine pullback.lift ?_ ?_ ?_ ≫ (PreservesPullback.iso _ _ _ ).inv · exact c.π.app WalkingParallelPair.zero · exact c.π.app WalkingParallelPair.zero apply (mapIsLimitOfPreservesOfIsLimit G _ _ (prodIsProd _ _)).hom_ext rintro (_ | _) · simp only [Category.assoc, ← G.map_comp, prod.lift_fst, BinaryFan.π_app_left, BinaryFan.mk_fst] · simp only [BinaryFan.π_app_right, BinaryFan.mk_snd, Category.assoc, ← G.map_comp, prod.lift_snd] exact (c.π.naturality WalkingParallelPairHom.left).symm.trans (c.π.naturality WalkingParallelPairHom.right) fac := fun c j => by rcases j with (_ | _) <;> simp only [Category.comp_id, PreservesPullback.iso_inv_fst, Cone.ofFork_π, G.map_comp, PreservesPullback.iso_inv_fst_assoc, Functor.mapCone_π_app, eqToHom_refl, Category.assoc, Fork.ofι_π_app, pullback.lift_fst, pullback.lift_fst_assoc] exact (c.π.naturality WalkingParallelPairHom.left).symm.trans (Category.id_comp _) uniq := fun s m h => by rw [Iso.eq_comp_inv] have := h WalkingParallelPair.zero dsimp [equalizerCone] at this ext <;> simp only [PreservesPullback.iso_hom_snd, Category.assoc, PreservesPullback.iso_hom_fst, pullback.lift_fst, pullback.lift_snd, Category.comp_id, ← pullbackFst_eq_pullback_snd, ← this] }⟩ -- We hide the "implementation details" inside a namespace namespace HasCoequalizersOfHasPushoutsAndBinaryCoproducts variable [HasBinaryCoproducts C] [HasPushouts C] /-- Define the equalizing object -/ abbrev constructCoequalizer (F : WalkingParallelPair ⥤ C) : C := pushout (coprod.desc (𝟙 _) (F.map WalkingParallelPairHom.left)) (coprod.desc (𝟙 _) (F.map WalkingParallelPairHom.right)) /-- Define the equalizing morphism -/ abbrev pushoutInl (F : WalkingParallelPair ⥤ C) : F.obj WalkingParallelPair.one ⟶ constructCoequalizer F := pushout.inl _ _ theorem pushoutInl_eq_pushout_inr (F : WalkingParallelPair ⥤ C) : pushoutInl F = pushout.inr _ _ := by convert (whisker_eq Limits.coprod.inl pushout.condition : (_ : F.obj _ ⟶ constructCoequalizer _) = _) <;> simp /-- Define the equalizing cocone -/ abbrev coequalizerCocone (F : WalkingParallelPair ⥤ C) : Cocone F := Cocone.ofCofork (Cofork.ofπ (pushoutInl F) (by conv_rhs => rw [pushoutInl_eq_pushout_inr] convert (whisker_eq Limits.coprod.inr pushout.condition : (_ : F.obj _ ⟶ constructCoequalizer _) = _) using 1 <;> simp)) /-- Show the equalizing cocone is a colimit -/ def coequalizerCoconeIsColimit (F : WalkingParallelPair ⥤ C) : IsColimit (coequalizerCocone F) where desc c := pushout.desc (c.ι.app _) (c.ι.app _) fac := by rintro c (_ | _) <;> simp uniq := by intro c m J have J1 : pushoutInl F ≫ m = c.ι.app WalkingParallelPair.one := by simpa using J WalkingParallelPair.one apply pushout.hom_ext · rw [colimit.ι_desc] exact J1 · rw [colimit.ι_desc, ← pushoutInl_eq_pushout_inr] exact J1 end HasCoequalizersOfHasPushoutsAndBinaryCoproducts open HasCoequalizersOfHasPushoutsAndBinaryCoproducts -- This is not an instance, as it is not always how one wants to construct equalizers! /-- Any category with pullbacks and binary products, has equalizers. -/ theorem hasCoequalizers_of_hasPushouts_and_binary_coproducts [HasBinaryCoproducts C] [HasPushouts C] : HasCoequalizers C := { has_colimit := fun F => HasColimit.mk { cocone := coequalizerCocone F isColimit := coequalizerCoconeIsColimit F } } attribute [local instance] hasPushout_of_preservesPushout /-- A functor that preserves pushouts and binary coproducts also presrves coequalizers. -/ lemma preservesCoequalizers_of_preservesPushouts_and_binaryCoproducts [HasBinaryCoproducts C] [HasPushouts C] [PreservesColimitsOfShape (Discrete WalkingPair) G] [PreservesColimitsOfShape WalkingSpan G] : PreservesColimitsOfShape WalkingParallelPair G := ⟨fun {K} => preservesColimit_of_preserves_colimit_cocone (coequalizerCoconeIsColimit K) <| { desc := fun c => by refine (PreservesPushout.iso _ _ _).inv ≫ pushout.desc ?_ ?_ ?_ · exact c.ι.app WalkingParallelPair.one · exact c.ι.app WalkingParallelPair.one apply (mapIsColimitOfPreservesOfIsColimit G _ _ (coprodIsCoprod _ _)).hom_ext rintro (_ | _) · simp only [BinaryCofan.ι_app_left, BinaryCofan.mk_inl, ← G.map_comp_assoc, coprod.inl_desc] · simp only [BinaryCofan.ι_app_right, BinaryCofan.mk_inr, ← G.map_comp_assoc, coprod.inr_desc] exact (c.ι.naturality WalkingParallelPairHom.left).trans (c.ι.naturality WalkingParallelPairHom.right).symm fac := fun c j => by rcases j with (_ | _) <;> simp only [Functor.mapCocone_ι_app, Cocone.ofCofork_ι, Category.id_comp, eqToHom_refl, Category.assoc, Functor.map_comp, Cofork.ofπ_ι_app, pushout.inl_desc, PreservesPushout.inl_iso_inv_assoc] exact (c.ι.naturality WalkingParallelPairHom.left).trans (Category.comp_id _) uniq := fun s m h => by rw [Iso.eq_inv_comp] have := h WalkingParallelPair.one dsimp [coequalizerCocone] at this ext <;> simp only [PreservesPushout.inl_iso_hom_assoc, Category.id_comp, pushout.inl_desc, pushout.inr_desc, PreservesPushout.inr_iso_hom_assoc, ← pushoutInl_eq_pushout_inr, ← this] }⟩ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/ZeroObjects.lean
import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts /-! # Limits involving zero objects Binary products and coproducts with a zero object always exist, and pullbacks/pushouts over a zero object are products/coproducts. -/ noncomputable section open CategoryTheory variable {C : Type*} [Category C] namespace CategoryTheory.Limits variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The limit cone for the product with a zero object. -/ def binaryFanZeroLeft (X : C) : BinaryFan (0 : C) X := BinaryFan.mk 0 (𝟙 X) /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroLeftIsLimit (X : C) : IsLimit (binaryFanZeroLeft X) := BinaryFan.isLimitMk (fun s => BinaryFan.snd s) (by cat_disch) (by simp) (fun s m _ h₂ => by simpa using h₂) instance hasBinaryProduct_zero_left (X : C) : HasBinaryProduct (0 : C) X := HasLimit.mk ⟨_, binaryFanZeroLeftIsLimit X⟩ /-- A zero object is a left unit for categorical product. -/ def zeroProdIso (X : C) : (0 : C) ⨯ X ≅ X := limit.isoLimitCone ⟨_, binaryFanZeroLeftIsLimit X⟩ @[simp] theorem zeroProdIso_hom (X : C) : (zeroProdIso X).hom = prod.snd := rfl @[simp] theorem zeroProdIso_inv_snd (X : C) : (zeroProdIso X).inv ≫ prod.snd = 𝟙 X := by dsimp [zeroProdIso, binaryFanZeroLeft] simp /-- The limit cone for the product with a zero object. -/ def binaryFanZeroRight (X : C) : BinaryFan X (0 : C) := BinaryFan.mk (𝟙 X) 0 /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroRightIsLimit (X : C) : IsLimit (binaryFanZeroRight X) := BinaryFan.isLimitMk (fun s => BinaryFan.fst s) (by simp) (by cat_disch) (fun s m h₁ _ => by simpa using h₁) instance hasBinaryProduct_zero_right (X : C) : HasBinaryProduct X (0 : C) := HasLimit.mk ⟨_, binaryFanZeroRightIsLimit X⟩ /-- A zero object is a right unit for categorical product. -/ def prodZeroIso (X : C) : X ⨯ (0 : C) ≅ X := limit.isoLimitCone ⟨_, binaryFanZeroRightIsLimit X⟩ @[simp] theorem prodZeroIso_hom (X : C) : (prodZeroIso X).hom = prod.fst := rfl @[simp] theorem prodZeroIso_iso_inv_snd (X : C) : (prodZeroIso X).inv ≫ prod.fst = 𝟙 X := by dsimp [prodZeroIso, binaryFanZeroRight] simp /-- The colimit cocone for the coproduct with a zero object. -/ def binaryCofanZeroLeft (X : C) : BinaryCofan (0 : C) X := BinaryCofan.mk 0 (𝟙 X) /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binaryCofanZeroLeftIsColimit (X : C) : IsColimit (binaryCofanZeroLeft X) := BinaryCofan.isColimitMk (fun s => BinaryCofan.inr s) (by cat_disch) (by simp) (fun s m _ h₂ => by simpa using h₂) instance hasBinaryCoproduct_zero_left (X : C) : HasBinaryCoproduct (0 : C) X := HasColimit.mk ⟨_, binaryCofanZeroLeftIsColimit X⟩ /-- A zero object is a left unit for categorical coproduct. -/ def zeroCoprodIso (X : C) : (0 : C) ⨿ X ≅ X := colimit.isoColimitCocone ⟨_, binaryCofanZeroLeftIsColimit X⟩ @[simp] theorem inr_zeroCoprodIso_hom (X : C) : coprod.inr ≫ (zeroCoprodIso X).hom = 𝟙 X := by dsimp [zeroCoprodIso, binaryCofanZeroLeft] simp @[simp] theorem zeroCoprodIso_inv (X : C) : (zeroCoprodIso X).inv = coprod.inr := rfl /-- The colimit cocone for the coproduct with a zero object. -/ def binaryCofanZeroRight (X : C) : BinaryCofan X (0 : C) := BinaryCofan.mk (𝟙 X) 0 /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binaryCofanZeroRightIsColimit (X : C) : IsColimit (binaryCofanZeroRight X) := BinaryCofan.isColimitMk (fun s => BinaryCofan.inl s) (by simp) (by cat_disch) (fun s m h₁ _ => by simpa using h₁) instance hasBinaryCoproduct_zero_right (X : C) : HasBinaryCoproduct X (0 : C) := HasColimit.mk ⟨_, binaryCofanZeroRightIsColimit X⟩ /-- A zero object is a right unit for categorical coproduct. -/ def coprodZeroIso (X : C) : X ⨿ (0 : C) ≅ X := colimit.isoColimitCocone ⟨_, binaryCofanZeroRightIsColimit X⟩ @[simp] theorem inr_coprodZeroIso_hom (X : C) : coprod.inl ≫ (coprodZeroIso X).hom = 𝟙 X := by dsimp [coprodZeroIso, binaryCofanZeroRight] simp @[simp] theorem coprodZeroIso_inv (X : C) : (coprodZeroIso X).inv = coprod.inl := rfl instance hasPullback_over_zero (X Y : C) [HasBinaryProduct X Y] : HasPullback (0 : X ⟶ 0) (0 : Y ⟶ 0) := HasLimit.mk ⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩ /-- The pullback over the zero object is the product. -/ def pullbackZeroZeroIso (X Y : C) [HasBinaryProduct X Y] : pullback (0 : X ⟶ 0) (0 : Y ⟶ 0) ≅ X ⨯ Y := limit.isoLimitCone ⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩ @[simp] theorem pullbackZeroZeroIso_inv_fst (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).inv ≫ pullback.fst 0 0 = prod.fst := by dsimp [pullbackZeroZeroIso] simp @[simp] theorem pullbackZeroZeroIso_inv_snd (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).inv ≫ pullback.snd 0 0 = prod.snd := by dsimp [pullbackZeroZeroIso] simp @[simp] theorem pullbackZeroZeroIso_hom_fst (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).hom ≫ prod.fst = pullback.fst 0 0 := by simp [← Iso.eq_inv_comp] @[simp] theorem pullbackZeroZeroIso_hom_snd (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).hom ≫ prod.snd = pullback.snd 0 0 := by simp [← Iso.eq_inv_comp] instance hasPushout_over_zero (X Y : C) [HasBinaryCoproduct X Y] : HasPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) := HasColimit.mk ⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩ /-- The pushout over the zero object is the coproduct. -/ def pushoutZeroZeroIso (X Y : C) [HasBinaryCoproduct X Y] : pushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) ≅ X ⨿ Y := colimit.isoColimitCocone ⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩ @[simp] theorem inl_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] : pushout.inl _ _ ≫ (pushoutZeroZeroIso X Y).hom = coprod.inl := by dsimp [pushoutZeroZeroIso] simp @[simp] theorem inr_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] : pushout.inr _ _ ≫ (pushoutZeroZeroIso X Y).hom = coprod.inr := by dsimp [pushoutZeroZeroIso] simp @[simp] theorem inl_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] : coprod.inl ≫ (pushoutZeroZeroIso X Y).inv = pushout.inl _ _ := by simp [Iso.comp_inv_eq] @[simp] theorem inr_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] : coprod.inr ≫ (pushoutZeroZeroIso X Y).inv = pushout.inr _ _ := by simp [Iso.comp_inv_eq] end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/WeaklyInitial.lean
import Mathlib.CategoryTheory.Limits.Shapes.WideEqualizers import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Constructions related to weakly initial objects This file gives constructions related to weakly initial objects, namely: * If a category has small products and a small weakly initial set of objects, then it has a weakly initial object. * If a category has wide equalizers and a weakly initial object, then it has an initial object. These are primarily useful to show the General Adjoint Functor Theorem. -/ universe v u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] /-- If `C` has (small) products and a small weakly initial set of objects, then it has a weakly initial object. -/ theorem has_weakly_initial_of_weakly_initial_set_and_hasProducts [HasProducts.{v} C] {ι : Type v} {B : ι → C} (hB : ∀ A : C, ∃ i, Nonempty (B i ⟶ A)) : ∃ T : C, ∀ X, Nonempty (T ⟶ X) := ⟨∏ᶜ B, fun X => ⟨Pi.π _ _ ≫ (hB X).choose_spec.some⟩⟩ /-- If `C` has (small) wide equalizers and a weakly initial object, then it has an initial object. The initial object is constructed as the wide equalizer of all endomorphisms on the given weakly initial object. -/ theorem hasInitial_of_weakly_initial_and_hasWideEqualizers [HasWideEqualizers.{v} C] {T : C} (hT : ∀ X, Nonempty (T ⟶ X)) : HasInitial C := by let endos := T ⟶ T let i := wideEqualizer.ι (id : endos → endos) haveI : Nonempty endos := ⟨𝟙 _⟩ have : ∀ X : C, Unique (wideEqualizer (id : endos → endos) ⟶ X) := by intro X refine ⟨⟨i ≫ Classical.choice (hT X)⟩, fun a => ?_⟩ let E := equalizer a (i ≫ Classical.choice (hT _)) let e : E ⟶ wideEqualizer id := equalizer.ι _ _ let h : T ⟶ E := Classical.choice (hT E) have : ((i ≫ h) ≫ e) ≫ i = i ≫ 𝟙 _ := by rw [Category.assoc, Category.assoc] apply wideEqualizer.condition (id : endos → endos) (h ≫ e ≫ i) rw [Category.comp_id, cancel_mono_id i] at this haveI : IsSplitEpi e := IsSplitEpi.mk' ⟨i ≫ h, this⟩ rw [← cancel_epi e] apply equalizer.condition exact hasInitial_of_unique (wideEqualizer (id : endos → endos)) end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/BinaryProducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal /-! # Constructing binary product from pullbacks and terminal object. The product is the pullback over the terminal objects. In particular, if a category has pullbacks and a terminal object, then it has binary products. We also provide the dual. -/ universe v v' u u' open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] (F : C ⥤ D) /-- If a span is the pullback span over the terminal object, then it is a binary product. -/ def isBinaryProductOfIsTerminalIsPullback (F : Discrete WalkingPair ⥤ C) (c : Cone F) {X : C} (hX : IsTerminal X) (f : F.obj ⟨WalkingPair.left⟩ ⟶ X) (g : F.obj ⟨WalkingPair.right⟩ ⟶ X) (hc : IsLimit (PullbackCone.mk (c.π.app ⟨WalkingPair.left⟩) (c.π.app ⟨WalkingPair.right⟩ :) <| hX.hom_ext (_ ≫ f) (_ ≫ g))) : IsLimit c where lift s := hc.lift (PullbackCone.mk (s.π.app ⟨WalkingPair.left⟩) (s.π.app ⟨WalkingPair.right⟩) (hX.hom_ext _ _)) fac _ j := Discrete.casesOn j fun j => WalkingPair.casesOn j (hc.fac _ WalkingCospan.left) (hc.fac _ WalkingCospan.right) uniq s m J := by let c' := PullbackCone.mk (m ≫ c.π.app ⟨WalkingPair.left⟩) (m ≫ c.π.app ⟨WalkingPair.right⟩ :) (hX.hom_ext (_ ≫ f) (_ ≫ g)) dsimp; rw [← J, ← J] apply hc.hom_ext rintro (_ | (_ | _)) <;> simp only [PullbackCone.mk_π_app] exacts [(Category.assoc _ _ _).symm.trans (hc.fac_assoc c' WalkingCospan.left f).symm, (hc.fac c' WalkingCospan.left).symm, (hc.fac c' WalkingCospan.right).symm] /-- The pullback over the terminal object is the product -/ def isProductOfIsTerminalIsPullback {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsTerminal Z) (H₂ : IsLimit (PullbackCone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _))) : IsLimit (BinaryFan.mk h k) := by apply isBinaryProductOfIsTerminalIsPullback _ _ H₁ exact H₂ /-- The product is the pullback over the terminal object. -/ def isPullbackOfIsTerminalIsProduct {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsTerminal Z) (H₂ : IsLimit (BinaryFan.mk h k)) : IsLimit (PullbackCone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _)) := by apply PullbackCone.isLimitAux' intro s use H₂.lift (BinaryFan.mk s.fst s.snd) use H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.left⟩ use H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.right⟩ intro m h₁ h₂ apply H₂.hom_ext rintro ⟨⟨⟩⟩ · exact h₁.trans (H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.left⟩).symm · exact h₂.trans (H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.right⟩).symm /-- Any category with pullbacks and a terminal object has a limit cone for each walking pair. -/ noncomputable def limitConeOfTerminalAndPullbacks [HasTerminal C] [HasPullbacks C] (F : Discrete WalkingPair ⥤ C) : LimitCone F where cone := { pt := pullback (terminal.from (F.obj ⟨WalkingPair.left⟩)) (terminal.from (F.obj ⟨WalkingPair.right⟩)) π := Discrete.natTrans fun x => Discrete.casesOn x fun x => WalkingPair.casesOn x (pullback.fst _ _) (pullback.snd _ _) } isLimit := isBinaryProductOfIsTerminalIsPullback F _ terminalIsTerminal _ _ (pullbackIsPullback _ _) variable (C) in -- This is not an instance, as it is not always how one wants to construct binary products! /-- Any category with pullbacks and terminal object has binary products. -/ theorem hasBinaryProducts_of_hasTerminal_and_pullbacks [HasTerminal C] [HasPullbacks C] : HasBinaryProducts C := { has_limit := fun F => HasLimit.mk (limitConeOfTerminalAndPullbacks F) } /-- A functor that preserves terminal objects and pullbacks preserves binary products. -/ lemma preservesBinaryProducts_of_preservesTerminal_and_pullbacks [HasTerminal C] [HasPullbacks C] [PreservesLimitsOfShape (Discrete.{0} PEmpty) F] [PreservesLimitsOfShape WalkingCospan F] : PreservesLimitsOfShape (Discrete WalkingPair) F := ⟨fun {K} => preservesLimit_of_preserves_limit_cone (limitConeOfTerminalAndPullbacks K).2 (by apply isBinaryProductOfIsTerminalIsPullback _ _ (isLimitOfHasTerminalOfPreservesLimit F) apply isLimitOfHasPullbackOfPreservesLimit)⟩ /-- In a category with a terminal object and pullbacks, a product of objects `X` and `Y` is isomorphic to a pullback. -/ noncomputable def prodIsoPullback [HasTerminal C] [HasPullbacks C] (X Y : C) [HasBinaryProduct X Y] : X ⨯ Y ≅ pullback (terminal.from X) (terminal.from Y) := limit.isoLimitCone (limitConeOfTerminalAndPullbacks _) @[reassoc (attr := simp)] lemma prodIsoPullback_hom_fst [HasTerminal C] [HasPullbacks C] (X Y : C) [HasBinaryProduct X Y] : (prodIsoPullback X Y).hom ≫ pullback.fst _ _ = prod.fst := limit.isoLimitCone_hom_π (limitConeOfTerminalAndPullbacks _) ⟨.left⟩ @[reassoc (attr := simp)] lemma prodIsoPullback_hom_snd [HasTerminal C] [HasPullbacks C] (X Y : C) [HasBinaryProduct X Y] : (prodIsoPullback X Y).hom ≫ pullback.snd _ _ = prod.snd := limit.isoLimitCone_hom_π (limitConeOfTerminalAndPullbacks _) ⟨.right⟩ @[reassoc (attr := simp)] lemma prodIsoPullback_inv_fst [HasTerminal C] [HasPullbacks C] (X Y : C) [HasBinaryProduct X Y] : (prodIsoPullback X Y).inv ≫ prod.fst = pullback.fst _ _ := limit.isoLimitCone_inv_π (limitConeOfTerminalAndPullbacks _) ⟨.left⟩ @[reassoc (attr := simp)] lemma prodIsoPullback_inv_snd [HasTerminal C] [HasPullbacks C] (X Y : C) [HasBinaryProduct X Y] : (prodIsoPullback X Y).inv ≫ prod.snd = pullback.snd _ _ := limit.isoLimitCone_inv_π (limitConeOfTerminalAndPullbacks _) ⟨.right⟩ /-- If a cospan is the pushout cospan under the initial object, then it is a binary coproduct. -/ def isBinaryCoproductOfIsInitialIsPushout (F : Discrete WalkingPair ⥤ C) (c : Cocone F) {X : C} (hX : IsInitial X) (f : X ⟶ F.obj ⟨WalkingPair.left⟩) (g : X ⟶ F.obj ⟨WalkingPair.right⟩) (hc : IsColimit (PushoutCocone.mk (c.ι.app ⟨WalkingPair.left⟩) (c.ι.app ⟨WalkingPair.right⟩ :) <| hX.hom_ext (f ≫ _) (g ≫ _))) : IsColimit c where desc s := hc.desc (PushoutCocone.mk (s.ι.app ⟨WalkingPair.left⟩) (s.ι.app ⟨WalkingPair.right⟩) (hX.hom_ext _ _)) fac _ j := Discrete.casesOn j fun j => WalkingPair.casesOn j (hc.fac _ WalkingSpan.left) (hc.fac _ WalkingSpan.right) uniq s m J := by let c' := PushoutCocone.mk (c.ι.app ⟨WalkingPair.left⟩ ≫ m) (c.ι.app ⟨WalkingPair.right⟩ ≫ m) (hX.hom_ext (f ≫ _) (g ≫ _)) dsimp; rw [← J, ← J] apply hc.hom_ext rintro (_ | (_ | _)) <;> simp only [PushoutCocone.mk_ι_app, Category.assoc] on_goal 1 => congr 1 exacts [(hc.fac c' WalkingSpan.left).symm, (hc.fac c' WalkingSpan.left).symm, (hc.fac c' WalkingSpan.right).symm] /-- The pushout under the initial object is the coproduct -/ def isCoproductOfIsInitialIsPushout {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsInitial W) (H₂ : IsColimit (PushoutCocone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _))) : IsColimit (BinaryCofan.mk f g) := by apply isBinaryCoproductOfIsInitialIsPushout _ _ H₁ exact H₂ /-- The coproduct is the pushout under the initial object. -/ def isPushoutOfIsInitialIsCoproduct {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsInitial W) (H₂ : IsColimit (BinaryCofan.mk f g)) : IsColimit (PushoutCocone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _)) := by apply PushoutCocone.isColimitAux' intro s use H₂.desc (BinaryCofan.mk s.inl s.inr) use H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.left⟩ use H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.right⟩ intro m h₁ h₂ apply H₂.hom_ext rintro ⟨⟨⟩⟩ · exact h₁.trans (H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.left⟩).symm · exact h₂.trans (H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.right⟩).symm /-- Any category with pushouts and an initial object has a colimit cocone for each walking pair. -/ noncomputable def colimitCoconeOfInitialAndPushouts [HasInitial C] [HasPushouts C] (F : Discrete WalkingPair ⥤ C) : ColimitCocone F where cocone := { pt := pushout (initial.to (F.obj ⟨WalkingPair.left⟩)) (initial.to (F.obj ⟨WalkingPair.right⟩)) ι := Discrete.natTrans fun x => Discrete.casesOn x fun x => WalkingPair.casesOn x (pushout.inl _ _) (pushout.inr _ _) } isColimit := isBinaryCoproductOfIsInitialIsPushout F _ initialIsInitial _ _ (pushoutIsPushout _ _) variable (C) in -- This is not an instance, as it is not always how one wants to construct binary coproducts! /-- Any category with pushouts and initial object has binary coproducts. -/ theorem hasBinaryCoproducts_of_hasInitial_and_pushouts [HasInitial C] [HasPushouts C] : HasBinaryCoproducts C := { has_colimit := fun F => HasColimit.mk (colimitCoconeOfInitialAndPushouts F) } /-- A functor that preserves initial objects and pushouts preserves binary coproducts. -/ lemma preservesBinaryCoproducts_of_preservesInitial_and_pushouts [HasInitial C] [HasPushouts C] [PreservesColimitsOfShape (Discrete.{0} PEmpty) F] [PreservesColimitsOfShape WalkingSpan F] : PreservesColimitsOfShape (Discrete WalkingPair) F := ⟨fun {K} => preservesColimit_of_preserves_colimit_cocone (colimitCoconeOfInitialAndPushouts K).2 (by apply isBinaryCoproductOfIsInitialIsPushout _ _ (isColimitOfHasInitialOfPreservesColimit F) apply isColimitOfHasPushoutOfPreservesColimit)⟩ /-- In a category with an initial object and pushouts, a coproduct of objects `X` and `Y` is isomorphic to a pushout. -/ noncomputable def coprodIsoPushout [HasInitial C] [HasPushouts C] (X Y : C) [HasBinaryCoproduct X Y] : X ⨿ Y ≅ pushout (initial.to X) (initial.to Y) := colimit.isoColimitCocone (colimitCoconeOfInitialAndPushouts _) @[reassoc (attr := simp)] lemma inl_coprodIsoPushout_hom [HasInitial C] [HasPushouts C] (X Y : C) [HasBinaryCoproduct X Y] : coprod.inl ≫ (coprodIsoPushout X Y).hom = pushout.inl _ _ := colimit.isoColimitCocone_ι_hom (colimitCoconeOfInitialAndPushouts _) _ @[reassoc (attr := simp)] lemma inr_coprodIsoPushout_hom [HasInitial C] [HasPushouts C] (X Y : C) [HasBinaryCoproduct X Y] : coprod.inr ≫ (coprodIsoPushout X Y).hom = pushout.inr _ _ := colimit.isoColimitCocone_ι_hom (colimitCoconeOfInitialAndPushouts _) _ @[reassoc (attr := simp)] lemma inl_coprodIsoPushout_inv [HasInitial C] [HasPushouts C] (X Y : C) [HasBinaryCoproduct X Y] : pushout.inl _ _ ≫ (coprodIsoPushout X Y).inv = coprod.inl := colimit.isoColimitCocone_ι_inv (colimitCoconeOfInitialAndPushouts (pair X Y)) ⟨.left⟩ @[reassoc (attr := simp)] lemma inr_coprodIsoPushout_inv [HasInitial C] [HasPushouts C] (X Y : C) [HasBinaryCoproduct X Y] : pushout.inr _ _ ≫ (coprodIsoPushout X Y).inv = coprod.inr := colimit.isoColimitCocone_ι_inv (colimitCoconeOfInitialAndPushouts (pair X Y)) ⟨.right⟩
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/Pullbacks.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Constructing pullbacks from binary products and equalizers If a category as binary products and equalizers, then it has pullbacks. Also, if a category has binary coproducts and coequalizers, then it has pushouts -/ universe v u open CategoryTheory namespace CategoryTheory.Limits /-- If the product `X ⨯ Y` and the equalizer of `π₁ ≫ f` and `π₂ ≫ g` exist, then the pullback of `f` and `g` exists: It is given by composing the equalizer with the projections. -/ theorem hasLimit_cospan_of_hasLimit_pair_of_hasLimit_parallelPair {C : Type u} [𝒞 : Category.{v} C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (pair X Y)] [HasLimit (parallelPair (prod.fst ≫ f) (prod.snd ≫ g))] : HasLimit (cospan f g) := let π₁ : X ⨯ Y ⟶ X := prod.fst let π₂ : X ⨯ Y ⟶ Y := prod.snd let e := equalizer.ι (π₁ ≫ f) (π₂ ≫ g) HasLimit.mk { cone := PullbackCone.mk (e ≫ π₁) (e ≫ π₂) <| by rw [Category.assoc, equalizer.condition] simp [e] isLimit := PullbackCone.IsLimit.mk _ (fun s => equalizer.lift (prod.lift (s.π.app WalkingCospan.left) (s.π.app WalkingCospan.right)) <| by rw [← Category.assoc, limit.lift_π, ← Category.assoc, limit.lift_π] exact PullbackCone.condition _) (by simp [π₁, e]) (by simp [π₂, e]) fun s m h₁ h₂ => by ext · dsimp; simpa using h₁ · simpa using h₂ } section attribute [local instance] hasLimit_cospan_of_hasLimit_pair_of_hasLimit_parallelPair /-- If a category has all binary products and all equalizers, then it also has all pullbacks. As usual, this is not an instance, since there may be a more direct way to construct pullbacks. -/ theorem hasPullbacks_of_hasBinaryProducts_of_hasEqualizers (C : Type u) [Category.{v} C] [HasBinaryProducts C] [HasEqualizers C] : HasPullbacks C := { has_limit := fun F => hasLimit_of_iso (diagramIsoCospan F).symm } end /-- If the coproduct `Y ⨿ Z` and the coequalizer of `f ≫ ι₁` and `g ≫ ι₂` exist, then the pushout of `f` and `g` exists: It is given by composing the inclusions with the coequalizer. -/ theorem hasColimit_span_of_hasColimit_pair_of_hasColimit_parallelPair {C : Type u} [𝒞 : Category.{v} C] {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasColimit (pair Y Z)] [HasColimit (parallelPair (f ≫ coprod.inl) (g ≫ coprod.inr))] : HasColimit (span f g) := let ι₁ : Y ⟶ Y ⨿ Z := coprod.inl let ι₂ : Z ⟶ Y ⨿ Z := coprod.inr let c := coequalizer.π (f ≫ ι₁) (g ≫ ι₂) HasColimit.mk { cocone := PushoutCocone.mk (ι₁ ≫ c) (ι₂ ≫ c) <| by rw [← Category.assoc, ← Category.assoc, coequalizer.condition] isColimit := PushoutCocone.IsColimit.mk _ (fun s => coequalizer.desc (coprod.desc (s.ι.app WalkingSpan.left) (s.ι.app WalkingSpan.right)) <| by rw [Category.assoc, colimit.ι_desc, Category.assoc, colimit.ι_desc] exact PushoutCocone.condition _) (by simp [ι₁, c]) (by simp [ι₂, c]) fun s m h₁ h₂ => by ext · simpa using h₁ · simpa using h₂ } section attribute [local instance] hasColimit_span_of_hasColimit_pair_of_hasColimit_parallelPair /-- If a category has all binary coproducts and all coequalizers, then it also has all pushouts. As usual, this is not an instance, since there may be a more direct way to construct pushouts. -/ theorem hasPushouts_of_hasBinaryCoproducts_of_hasCoequalizers (C : Type u) [Category.{v} C] [HasBinaryCoproducts C] [HasCoequalizers C] : HasPushouts C := hasPushouts_of_hasColimit_span C end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/Over/Products.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Products in the over category Shows that products in the over category can be derived from wide pullbacks in the base category. The main result is `over_product_of_widePullback`, which says that if `C` has `J`-indexed wide pullbacks, then `Over B` has `J`-indexed products. Note that the binary case is done separately to ensure defeqs with the pullback in the base category. ## TODO * Generalise from arbitrary products to arbitrary limits. This is done in Toric. * Dualise to get the `Under X` results. -/ universe w v u -- morphism levels before object levels. See note [category_theory universes]. open CategoryTheory CategoryTheory.Limits variable {J : Type w} variable {C : Type u} [Category.{v} C] variable {X Y Z : C} /-! ### Binary products In this section we construct binary products in `Over X` and binary coproducts in `Under X` explicitly as the pullbacks and pushouts of binary (co)fans in the base category. For `Over X`, one could construct these binary products from the general theory of arbitrary products from the next section, i.e. ``` (Cones.postcomposeEquivalence (diagramIsoCospan _).symm).trans (Over.ConstructProducts.conesEquiv _ (pair (Over.mk f) (Over.mk g))) ``` but this gives worse defeqs. For `Under X`, there is currently no general theory of arbitrary coproducts. -/ namespace CategoryTheory.Limits section Over variable {f : Y ⟶ X} {g : Z ⟶ X} /-- Pullback cones to `X` are the same thing as binary fans in `Over X`. -/ @[simps] def pullbackConeEquivBinaryFan : PullbackCone f g ≌ BinaryFan (Over.mk f) (.mk g) where functor.obj c := .mk (Over.homMk (U := .mk (c.fst ≫ f)) (V := .mk f) c.fst rfl) (Over.homMk (U := .mk (c.fst ≫ f)) (V := .mk g) c.snd c.condition.symm) functor.map {c₁ c₂} a := { hom := Over.homMk a.hom, w := by rintro (_ | _) <;> cat_disch } inverse.obj c := PullbackCone.mk c.fst.left c.snd.left (c.fst.w.trans c.snd.w.symm) inverse.map {c₁ c₂} a := { hom := a.hom.left w := by rintro (_ | _ | _) <;> simp [← Over.comp_left_assoc, ← Over.comp_left] } unitIso := NatIso.ofComponents (fun c ↦ c.eta) (by intros; ext; simp) counitIso := NatIso.ofComponents (fun X ↦ BinaryFan.ext (Over.isoMk (Iso.refl _) (by simpa using X.fst.w.symm)) (by ext; simp) (by ext; simp)) (by intros; ext; simp [BinaryFan.ext]) functor_unitIso_comp c := by ext; simp [BinaryFan.ext] /-- A binary fan in `Over X` is a limit if its corresponding pullback cone to `X` is a limit. -/ -- `IsLimit.ofConeEquiv` isn't used here because the lift it defines is `𝟙 _ ≫ pullback.lift`. -- TODO: Define `IsLimit.copy`? @[simps!] def IsLimit.pullbackConeEquivBinaryFanFunctor {c : PullbackCone f g} (hc : IsLimit c) : IsLimit <| pullbackConeEquivBinaryFan.functor.obj c := BinaryFan.isLimitMk -- TODO: Drop `BinaryFan.IsLimit.lift'`. Instead provide the lemmas it bundles separately. -- TODO: Define `abbrev BinaryFan.IsLimit (c : BinaryFan X Y) := IsLimit c` for dot notation? (fun s ↦ Over.homMk (hc.lift <| pullbackConeEquivBinaryFan.inverse.obj s) <| by simpa using s.fst.w) (fun s ↦ Over.OverMorphism.ext (hc.fac _ _)) (fun s ↦ Over.OverMorphism.ext (hc.fac _ _)) fun s m e₁ e₂ ↦ by ext1 apply PullbackCone.IsLimit.hom_ext hc · simpa using congr(($e₁).left) · simpa using congr(($e₂).left) /-- A pullback cone to `X` is a limit if its corresponding binary fan in `Over X` is a limit. -/ -- This could also be `(IsLimit.ofConeEquiv pullbackConeEquivBinaryFan.symm).symm hc`, but possibly -- bad defeqs? def IsLimit.pullbackConeEquivBinaryFanInverse {c : BinaryFan (Over.mk f) (.mk g)} (hc : IsLimit c) : IsLimit <| pullbackConeEquivBinaryFan.inverse.obj c := PullbackCone.IsLimit.mk (c.fst.w.trans c.snd.w.symm) (fun s ↦ (hc.lift <| pullbackConeEquivBinaryFan.functor.obj s).left) (fun s ↦ by simpa only using congr($(hc.fac _ _).left)) (fun s ↦ by simpa only using congr($(hc.fac _ _).left)) <| fun s m hm₁ hm₂ ↦ by change PullbackCone f g at s have := hc.uniq (pullbackConeEquivBinaryFan.functor.obj s) (Over.homMk m <| by have := c.fst.w simp only [pair_obj_left, Over.mk_left, Functor.id_obj, pair_obj_right, Functor.const_obj_obj, Over.mk_hom, Functor.id_map, CostructuredArrow.right_eq_id, Discrete.functor_map_id, Category.comp_id] at hm₁ this simp [← hm₁, this]) (by rintro (_ | _) <;> ext <;> simpa) exact congr(($this).left) end Over section Under variable {f : X ⟶ Y} {g : X ⟶ Z} /-- Pushout cocones from `X` are the same thing as binary cofans in `Under X`. -/ @[simps] def pushoutCoconeEquivBinaryCofan : PushoutCocone f g ≌ BinaryCofan (Under.mk f) (.mk g) where functor.obj c := .mk (Under.homMk (U := .mk f) (V := .mk (f ≫ c.inl)) c.inl rfl) (Under.homMk (U := .mk g) (V := .mk (f ≫ c.inl)) c.inr c.condition.symm) functor.map {c₁ c₂} a := { hom := Under.homMk a.hom, w := by rintro (_ | _) <;> cat_disch } inverse.obj c := .mk c.inl.right c.inr.right (c.inl.w.symm.trans c.inr.w) inverse.map {c₁ c₂} a := { hom := a.hom.right w := by rintro (_ | _ | _) <;> simp [← Under.comp_right] } unitIso := NatIso.ofComponents (fun c ↦ c.eta) (fun f ↦ by ext; simp) counitIso := NatIso.ofComponents (fun X ↦ BinaryCofan.ext (Under.isoMk (.refl _) (by dsimp; simpa using X.inl.w.symm)) (by ext; simp) (by ext; simp)) (by intros; ext; simp) functor_unitIso_comp c := by ext; simp /-- A binary cofan in `Under X` is a colimit if its corresponding pushout cocone from `X` is a colimit. -/ -- `IsColimit.ofCoconeEquiv` isn't used here because the lift it defines is `pushout.desc ≫ 𝟙 _`. -- TODO: Define `IsColimit.copy`? @[simps!] def IsColimit.pushoutCoconeEquivBinaryCofanFunctor {c : PushoutCocone f g} (hc : IsColimit c) : IsColimit <| pushoutCoconeEquivBinaryCofan.functor.obj c := BinaryCofan.isColimitMk (fun s ↦ Under.homMk (hc.desc (PushoutCocone.mk s.inl.right s.inr.right (s.inl.w.symm.trans s.inr.w))) <| by simpa using s.inl.w.symm) (fun s ↦ Under.UnderMorphism.ext (hc.fac _ _)) (fun s ↦ Under.UnderMorphism.ext (hc.fac _ _)) fun s m e₁ e₂ ↦ by ext1 refine PushoutCocone.IsColimit.hom_ext hc ?_ ?_ · simpa using congr(($e₁).right) · simpa using congr(($e₂).right) /-- A pushout cocone from `X` is a colimit if its corresponding binary cofan in `Under X` is a colimit. -/ -- This could also be `(IsColimit.ofCoconeEquiv pushoutCoconeEquivBinaryCofan.symm).symm hc`, -- but possibly bad defeqs? def IsColimit.pushoutCoconeEquivBinaryCofanInverse {c : BinaryCofan (Under.mk f) (.mk g)} (hc : IsColimit c) : IsColimit <| pushoutCoconeEquivBinaryCofan.inverse.obj c := PushoutCocone.IsColimit.mk (c.inl.w.symm.trans c.inr.w) (fun s ↦ (hc.desc <| pushoutCoconeEquivBinaryCofan.functor.obj s).right) (fun s ↦ by simpa only using congr($(hc.fac _ _).right)) (fun s ↦ by simpa only using congr($(hc.fac _ _).right)) <| fun s m hm₁ hm₂ ↦ by change PushoutCocone f g at s have := hc.uniq (pushoutCoconeEquivBinaryCofan.functor.obj s) (Under.homMk m <| by have := c.inl.w simp only [pair_obj_left, Functor.const_obj_obj, Functor.id_obj, StructuredArrow.left_eq_id, Discrete.functor_map_id, Category.id_comp, Under.mk_right, Under.mk_hom, Functor.id_map, pair_obj_right] at this hm₁ simp [← hm₁, ← Category.assoc, ← this]) (by rintro (_ | _) <;> ext <;> simpa) exact congr(($this).right) end Under end Limits namespace Over section BinaryProduct variable {X : C} {Y Z : Over X} open Limits lemma isPullback_of_binaryFan_isLimit (c : BinaryFan Y Z) (hc : IsLimit c) : IsPullback c.fst.left c.snd.left Y.hom Z.hom := ⟨by simp, ⟨hc.pullbackConeEquivBinaryFanInverse⟩⟩ variable (Y Z) [HasPullback Y.hom Z.hom] [HasBinaryProduct Y Z] /-- The product of `Y` and `Z` in `Over X` is isomorphic to `Y ×ₓ Z`. -/ noncomputable def prodLeftIsoPullback : (Y ⨯ Z).left ≅ pullback Y.hom Z.hom := (Over.isPullback_of_binaryFan_isLimit _ (prodIsProd Y Z)).isoPullback @[reassoc (attr := simp)] lemma prodLeftIsoPullback_hom_fst : (prodLeftIsoPullback Y Z).hom ≫ pullback.fst _ _ = (prod.fst (X := Y)).left := IsPullback.isoPullback_hom_fst _ @[reassoc (attr := simp)] lemma prodLeftIsoPullback_hom_snd : (prodLeftIsoPullback Y Z).hom ≫ pullback.snd _ _ = (prod.snd (X := Y)).left := IsPullback.isoPullback_hom_snd _ @[reassoc (attr := simp)] lemma prodLeftIsoPullback_inv_fst : (prodLeftIsoPullback Y Z).inv ≫ (prod.fst (X := Y)).left = pullback.fst _ _ := IsPullback.isoPullback_inv_fst _ @[reassoc (attr := simp)] lemma prodLeftIsoPullback_inv_snd : (prodLeftIsoPullback Y Z).inv ≫ (prod.snd (X := Y)).left = pullback.snd _ _ := IsPullback.isoPullback_inv_snd _ end BinaryProduct /-! ### Arbitrary products In this section, we prove that `J`-indexed products in `Over X` correspond to `J`-indexed pullbacks in `C`. -/ namespace ConstructProducts /-- (Implementation) Given a product diagram in `C/B`, construct the corresponding wide pullback diagram in `C`. -/ abbrev widePullbackDiagramOfDiagramOver (B : C) {J : Type w} (F : Discrete J ⥤ Over B) : WidePullbackShape J ⥤ C := WidePullbackShape.wideCospan B (fun j => (F.obj ⟨j⟩).left) fun j => (F.obj ⟨j⟩).hom /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def conesEquivInverseObj (B : C) {J : Type w} (F : Discrete J ⥤ Over B) (c : Cone F) : Cone (widePullbackDiagramOfDiagramOver B F) where pt := c.pt.left π := { app := fun X => Option.casesOn X c.pt.hom fun j : J => (c.π.app ⟨j⟩).left -- `tidy` can do this using `case_bash`, but let's try to be a good `-T50000` citizen: naturality := fun X Y f => by dsimp; cases X <;> cases Y <;> cases f · rw [Category.id_comp, Category.comp_id] · rw [Over.w, Category.id_comp] · rw [Category.id_comp, Category.comp_id] } /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def conesEquivInverse (B : C) {J : Type w} (F : Discrete J ⥤ Over B) : Cone F ⥤ Cone (widePullbackDiagramOfDiagramOver B F) where obj := conesEquivInverseObj B F map f := { hom := f.hom.left w := fun j => by obtain - | j := j · simp · dsimp rw [← f.w ⟨j⟩] rfl } -- Porting note: this should help with the additional `naturality` proof we now have to give in -- `conesEquivFunctor`, but doesn't. -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Discrete /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def conesEquivFunctor (B : C) {J : Type w} (F : Discrete J ⥤ Over B) : Cone (widePullbackDiagramOfDiagramOver B F) ⥤ Cone F where obj c := { pt := Over.mk (c.π.app none) π := { app := fun ⟨j⟩ => Over.homMk (c.π.app (some j)) (c.w (WidePullbackShape.Hom.term j)) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10888): added proof for `naturality` naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨f⟩⟩ => by dsimp at f ⊢; cat_disch } } map f := { hom := Over.homMk f.hom } -- Porting note: unfortunately `aesop` can't cope with a `cases` rule here for the type synonym -- `WidePullbackShape`. -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] WidePullbackShape -- If this worked we could avoid the `rintro` in `conesEquivUnitIso`. /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps!] def conesEquivUnitIso (B : C) (F : Discrete J ⥤ Over B) : 𝟭 (Cone (widePullbackDiagramOfDiagramOver B F)) ≅ conesEquivFunctor B F ⋙ conesEquivInverse B F := NatIso.ofComponents fun _ => Cones.ext { hom := 𝟙 _ inv := 𝟙 _ } (by rintro (j | j) <;> cat_disch) -- TODO: Can we add `:= by aesop` to the second arguments of `NatIso.ofComponents` and -- `Cones.ext`? /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps!] def conesEquivCounitIso (B : C) (F : Discrete J ⥤ Over B) : conesEquivInverse B F ⋙ conesEquivFunctor B F ≅ 𝟭 (Cone F) := NatIso.ofComponents fun _ => Cones.ext { hom := Over.homMk (𝟙 _) inv := Over.homMk (𝟙 _) } /-- (Impl) Establish an equivalence between the category of cones for `F` and for the "grown" `F`. -/ @[simps] def conesEquiv (B : C) (F : Discrete J ⥤ Over B) : Cone (widePullbackDiagramOfDiagramOver B F) ≌ Cone F where functor := conesEquivFunctor B F inverse := conesEquivInverse B F unitIso := conesEquivUnitIso B F counitIso := conesEquivCounitIso B F /-- Use the above equivalence to prove we have a limit. -/ theorem has_over_limit_discrete_of_widePullback_limit {B : C} (F : Discrete J ⥤ Over B) [HasLimit (widePullbackDiagramOfDiagramOver B F)] : HasLimit F := HasLimit.mk { cone := _ isLimit := IsLimit.ofRightAdjoint (conesEquiv B F).symm.toAdjunction (limit.isLimit (widePullbackDiagramOfDiagramOver B F)) } /-- Given a wide pullback in `C`, construct a product in `C/B`. -/ theorem over_product_of_widePullback [HasLimitsOfShape (WidePullbackShape J) C] {B : C} : HasLimitsOfShape (Discrete J) (Over B) := { has_limit := fun F => has_over_limit_discrete_of_widePullback_limit F } /-- Given a pullback in `C`, construct a binary product in `C/B`. -/ theorem over_binaryProduct_of_pullback [HasPullbacks C] {B : C} : HasBinaryProducts (Over B) := over_product_of_widePullback /-- Given all wide pullbacks in `C`, construct products in `C/B`. -/ theorem over_products_of_widePullbacks [HasWidePullbacks.{w} C] {B : C} : HasProducts.{w} (Over B) := fun _ => over_product_of_widePullback /-- Given all finite wide pullbacks in `C`, construct finite products in `C/B`. -/ theorem over_finiteProducts_of_finiteWidePullbacks [HasFiniteWidePullbacks C] {B : C} : HasFiniteProducts (Over B) := ⟨fun _ => over_product_of_widePullback⟩ end ConstructProducts /-- Construct terminal object in the over category. This isn't an instance as it's not typically the way we want to define terminal objects. (For instance, this gives a terminal object which is different from the generic one given by `over_product_of_widePullback` above.) -/ theorem over_hasTerminal (B : C) : HasTerminal (Over B) where has_limit F := HasLimit.mk { cone := { pt := Over.mk (𝟙 _) π := { app := fun p => p.as.elim } } isLimit := { lift := fun s => Over.homMk s.pt.hom fac := fun _ j => j.as.elim uniq := fun s m _ => by simp only ext rw [Over.homMk_left _] have := m.w dsimp at this rwa [Category.comp_id, Category.comp_id] at this } } end CategoryTheory.Over
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/Over/Basic.lean
import Mathlib.CategoryTheory.Limits.Connected import Mathlib.CategoryTheory.Limits.Constructions.Over.Products import Mathlib.CategoryTheory.Limits.Constructions.Over.Connected import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Limits.Constructions.Equalizers /-! # Limits in the over category Declare instances for limits in the over category: If `C` has finite wide pullbacks, `Over B` has finite limits, and if `C` has arbitrary wide pullbacks then `Over B` has limits. -/ universe w v u -- morphism levels before object levels. See note [category_theory universes]. open CategoryTheory CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {X : C} namespace CategoryTheory.Over /-- Make sure we can derive pullbacks in `Over B`. -/ instance {B : C} [HasPullbacks C] : HasPullbacks (Over B) := inferInstance /-- Make sure we can derive equalizers in `Over B`. -/ instance {B : C} [HasEqualizers C] : HasEqualizers (Over B) := inferInstance instance hasFiniteLimits {B : C} [HasFiniteWidePullbacks C] : HasFiniteLimits (Over B) := by have := ConstructProducts.over_finiteProducts_of_finiteWidePullbacks (B := B) have := hasEqualizers_of_hasPullbacks_and_binary_products (C := Over B) apply hasFiniteLimits_of_hasEqualizers_and_finite_products instance hasLimits {B : C} [HasWidePullbacks.{w} C] : HasLimitsOfSize.{w, w} (Over B) := by have := ConstructProducts.over_binaryProduct_of_pullback (B := B) have := hasEqualizers_of_hasPullbacks_and_binary_products (C := Over B) have := ConstructProducts.over_products_of_widePullbacks (B := B) apply has_limits_of_hasEqualizers_and_products end CategoryTheory.Over
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Constructions/Over/Connected.lean
import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Filtered.Final /-! # Connected limits in the over category We show that the projection `CostructuredArrow K B ⥤ C` creates and preserves connected limits, without assuming that `C` has any limits. In particular, `CostructuredArrow K B` has any connected limit which `C` has. From this we deduce the corresponding results for the over category. -/ universe v' u' v u -- morphism levels before object levels. See note [category theory universes]. noncomputable section open CategoryTheory CategoryTheory.Limits variable {J : Type u'} [Category.{v'} J] variable {C : Type u} [Category.{v} C] {D : Type*} [Category D] {K : C ⥤ D} variable {X : C} namespace CategoryTheory.CostructuredArrow namespace CreatesConnected /-- (Implementation) Given a diagram in `CostructuredArrow K B`, produce a natural transformation from the diagram legs to the specific object. -/ @[simps] def natTransInCostructuredArrow {B : D} (F : J ⥤ CostructuredArrow K B) : F ⋙ CostructuredArrow.proj K B ⋙ K ⟶ (CategoryTheory.Functor.const J).obj B where app j := (F.obj j).hom /-- (Implementation) Given a cone in the base category, raise it to a cone in `CostructuredArrow K B`. Note this is where the connected assumption is used. -/ @[simps] def raiseCone [IsConnected J] {B : D} {F : J ⥤ CostructuredArrow K B} (c : Cone (F ⋙ CostructuredArrow.proj K B)) : Cone F where pt := CostructuredArrow.mk (K.map (c.π.app (Classical.arbitrary J)) ≫ (F.obj (Classical.arbitrary J)).hom) π.app j := CostructuredArrow.homMk (c.π.app j) <| by let z : (Functor.const J).obj (K.obj c.pt) ⟶ _ := (CategoryTheory.Functor.constComp J c.pt K).inv ≫ Functor.whiskerRight c.π K ≫ natTransInCostructuredArrow F convert (nat_trans_from_is_connected z j (Classical.arbitrary J)) <;> simp [z] π.naturality X Y f := by apply CommaMorphism.ext · simpa using (c.w f).symm · simp theorem mapCone_raiseCone [IsConnected J] {B : D} {F : J ⥤ CostructuredArrow K B} (c : Cone (F ⋙ CostructuredArrow.proj K B)) : (CostructuredArrow.proj K B).mapCone (raiseCone c) = c := by cat_disch /-- (Implementation) Show that the raised cone is a limit. -/ def isLimitRaiseCone [IsConnected J] {B : D} {F : J ⥤ CostructuredArrow K B} {c : Cone (F ⋙ CostructuredArrow.proj K B)} (t : IsLimit c) : IsLimit (raiseCone c) where lift s := CostructuredArrow.homMk (t.lift ((CostructuredArrow.proj K B).mapCone s)) <| by simp [← Functor.map_comp_assoc] uniq s m K := by ext1 apply t.hom_ext intro j simp [← K j] end CreatesConnected /-- The projection from `CostructuredArrow K B` to `C` creates any connected limit. -/ instance [IsConnected J] {B : D} : CreatesLimitsOfShape J (CostructuredArrow.proj K B) where CreatesLimit := createsLimitOfReflectsIso fun c t => { liftedCone := CreatesConnected.raiseCone c validLift := eqToIso (CreatesConnected.mapCone_raiseCone c) makesLimit := CreatesConnected.isLimitRaiseCone t } /-- The forgetful functor from `CostructuredArrow K B` preserves any connected limit. -/ instance [IsConnected J] {B : D} : PreservesLimitsOfShape J (CostructuredArrow.proj K B) where preservesLimit.preserves hc := ⟨{ lift s := (CostructuredArrow.proj K B).map (hc.lift (CreatesConnected.raiseCone s)) fac _ _ := by rw [Functor.mapCone_π_app, ← Functor.map_comp, hc.fac, CreatesConnected.raiseCone_π_app, CostructuredArrow.proj_map, CostructuredArrow.homMk_left _ _] uniq s m fac := congrArg (CostructuredArrow.proj K B).map (hc.uniq (CreatesConnected.raiseCone s) (CostructuredArrow.homMk m (by simp [← fac])) fun j => (CostructuredArrow.proj K B).map_injective (fac j)) }⟩ /-- The over category has any connected limit which the original category has. -/ instance hasLimitsOfShape_of_isConnected {B : D} [IsConnected J] [HasLimitsOfShape J C] : HasLimitsOfShape J (CostructuredArrow K B) where has_limit F := hasLimit_of_created F (CostructuredArrow.proj K B) end CostructuredArrow namespace Over /-- The forgetful functor from the over category creates any connected limit. -/ instance createsLimitsOfShapeForgetOfIsConnected [IsConnected J] {B : C} : CreatesLimitsOfShape J (forget B) := inferInstanceAs <| CreatesLimitsOfShape J (CostructuredArrow.proj _ _) @[deprecated (since := "2025-09-29")] noncomputable alias forgetCreatesConnectedLimits := createsLimitsOfShapeForgetOfIsConnected /-- The forgetful functor from the over category preserves any connected limit. -/ instance preservesLimitsOfShape_forget_of_isConnected [IsConnected J] {B : C} : PreservesLimitsOfShape J (forget B) := inferInstanceAs <| PreservesLimitsOfShape J (CostructuredArrow.proj _ _) @[deprecated (since := "2025-09-29")] alias forgetPreservesConnectedLimits := preservesLimitsOfShape_forget_of_isConnected /-- The over category has any connected limit which the original category has. -/ instance hasLimitsOfShape_of_isConnected {B : C} [IsConnected J] [HasLimitsOfShape J C] : HasLimitsOfShape J (Over B) where has_limit F := hasLimit_of_created F (forget B) /-- The functor taking a cone over `F` to a cone over `Over.post F : Over i ⥤ Over (F.obj i)`. This takes limit cones to limit cones when `J` is cofiltered. See `isLimitConePost` -/ @[simps] def conePost (F : J ⥤ C) (i : J) : Cone F ⥤ Cone (Over.post (X := i) F) where obj c := { pt := Over.mk (c.π.app i), π := { app X := Over.homMk (c.π.app X.left) } } map f := { hom := Over.homMk f.hom } /-- `conePost` is compatible with the forgetful functors on over categories. -/ @[simps!] def conePostIso (F : J ⥤ C) (i : J) : conePost F i ⋙ Cones.functoriality _ (Over.forget (F.obj i)) ≅ Cones.whiskering (Over.forget _) := .refl _ attribute [local instance] IsCofiltered.isConnected in /-- The functor taking a cone over `F` to a cone over `Over.post F : Over i ⥤ Over (F.obj i)` preserves limit cones -/ noncomputable def isLimitConePost [IsCofilteredOrEmpty J] {F : J ⥤ C} {c : Cone F} (i : J) (hc : IsLimit c) : IsLimit ((conePost F i).obj c) := isLimitOfReflects (Over.forget _) ((Functor.Initial.isLimitWhiskerEquiv (Over.forget i) c).symm hc) end CategoryTheory.Over
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Indization/IndObject.lean
import Mathlib.CategoryTheory.Limits.FinallySmall import Mathlib.CategoryTheory.Limits.Presheaf import Mathlib.CategoryTheory.Filtered.Small import Mathlib.CategoryTheory.ObjectProperty.ClosedUnderIsomorphisms import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Preserves.Presheaf /-! # Ind-objects For a presheaf `A : Cᵒᵖ ⥤ Type v` we define the type `IndObjectPresentation A` of presentations of `A` as a small filtered colimit of representable presheaves and define the predicate `IsIndObject A` asserting that there is at least one such presentation. A presheaf is an ind-object if and only if the category `CostructuredArrow yoneda A` is filtered and finally small. In this way, `CostructuredArrow yoneda A` can be thought of the universal indexing category for the representation of `A` as a small filtered colimit of representable presheaves. ## Future work There are various useful ways to understand natural transformations between ind-objects in terms of their presentations. The ind-objects form a locally `v`-small category `IndCategory C` which has numerous interesting properties. ## Implementation notes One might be tempted to introduce another universe parameter and consider being a `w`-ind-object as a property of presheaves `C ⥤ Type max v w`. This comes with significant technical hurdles. The recommended alternative is to consider ind-objects over `ULiftHom.{w} C` instead. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Chapter 6 -/ universe v v' u u' namespace CategoryTheory.Limits section NonSmall variable {C : Type u} [Category.{v} C] /-- The data that witnesses that a presheaf `A` is an ind-object. It consists of a small filtered indexing category `I`, a diagram `F : I ⥤ C` and the data for a colimit cocone on `F ⋙ yoneda : I ⥤ Cᵒᵖ ⥤ Type v` with cocone point `A`. -/ structure IndObjectPresentation (A : Cᵒᵖ ⥤ Type v) where /-- The indexing category of the filtered colimit presentation -/ I : Type v /-- The indexing category of the filtered colimit presentation -/ [ℐ : SmallCategory I] [hI : IsFiltered I] /-- The diagram of the filtered colimit presentation -/ F : I ⥤ C /-- Use `IndObjectPresentation.cocone` instead. -/ ι : F ⋙ yoneda ⟶ (Functor.const I).obj A /-- Use `IndObjectPresentation.coconeIsColimit` instead. -/ isColimit : IsColimit (Cocone.mk A ι) namespace IndObjectPresentation /-- Alternative constructor for `IndObjectPresentation` taking a cocone instead of its defining natural transformation. -/ @[simps] def ofCocone {I : Type v} [SmallCategory I] [IsFiltered I] {F : I ⥤ C} (c : Cocone (F ⋙ yoneda)) (hc : IsColimit c) : IndObjectPresentation c.pt where I := I F := F ι := c.ι isColimit := hc variable {A : Cᵒᵖ ⥤ Type v} (P : IndObjectPresentation A) instance : SmallCategory P.I := P.ℐ instance : IsFiltered P.I := P.hI /-- The (colimit) cocone with cocone point `A`. -/ @[simps pt] def cocone : Cocone (P.F ⋙ yoneda) where pt := A ι := P.ι /-- `P.cocone` is a colimit cocone. -/ def coconeIsColimit : IsColimit P.cocone := P.isColimit /-- If `A` and `B` are isomorphic, then an ind-object presentation of `A` can be extended to an ind-object presentation of `B`. -/ @[simps!] noncomputable def extend {A B : Cᵒᵖ ⥤ Type v} (P : IndObjectPresentation A) (η : A ⟶ B) [IsIso η] : IndObjectPresentation B := .ofCocone (P.cocone.extend η) (P.coconeIsColimit.extendIso (by exact η)) /-- The canonical comparison functor between the indexing category of the presentation and the comma category `CostructuredArrow yoneda A`. This functor is always final. -/ @[simps! obj_left obj_right_as obj_hom map_left] def toCostructuredArrow : P.I ⥤ CostructuredArrow yoneda A := P.cocone.toCostructuredArrow ⋙ CostructuredArrow.pre _ _ _ instance : P.toCostructuredArrow.Final := Presheaf.final_toCostructuredArrow_comp_pre _ P.coconeIsColimit /-- Representable presheaves are (trivially) ind-objects. -/ @[simps] def yoneda (X : C) : IndObjectPresentation (yoneda.obj X) where I := Discrete PUnit.{v + 1} F := Functor.fromPUnit X ι := { app := fun _ => 𝟙 _ } isColimit := { desc := fun s => s.ι.app ⟨PUnit.unit⟩ uniq := fun _ _ h => h ⟨PUnit.unit⟩ } end IndObjectPresentation /-- A presheaf is called an ind-object if it can be written as a filtered colimit of representable presheaves. -/ structure IsIndObject (A : Cᵒᵖ ⥤ Type v) : Prop where mk' :: nonempty_presentation : Nonempty (IndObjectPresentation A) theorem IsIndObject.mk {A : Cᵒᵖ ⥤ Type v} (P : IndObjectPresentation A) : IsIndObject A := ⟨⟨P⟩⟩ /-- Representable presheaves are (trivially) ind-objects. -/ theorem isIndObject_yoneda (X : C) : IsIndObject (yoneda.obj X) := .mk <| IndObjectPresentation.yoneda X namespace IsIndObject variable {A : Cᵒᵖ ⥤ Type v} theorem map {A B : Cᵒᵖ ⥤ Type v} (η : A ⟶ B) [IsIso η] : IsIndObject A → IsIndObject B | ⟨⟨P⟩⟩ => ⟨⟨P.extend η⟩⟩ theorem iff_of_iso {A B : Cᵒᵖ ⥤ Type v} (η : A ⟶ B) [IsIso η] : IsIndObject A ↔ IsIndObject B := ⟨.map η, .map (inv η)⟩ instance : ObjectProperty.IsClosedUnderIsomorphisms (IsIndObject (C := C)) where of_iso i h := h.map i.hom /-- Pick a presentation for an ind-object using choice. -/ noncomputable def presentation : IsIndObject A → IndObjectPresentation A | ⟨P⟩ => P.some theorem isFiltered (h : IsIndObject A) : IsFiltered (CostructuredArrow yoneda A) := IsFiltered.of_final h.presentation.toCostructuredArrow theorem finallySmall (h : IsIndObject A) : FinallySmall.{v} (CostructuredArrow yoneda A) := FinallySmall.mk' h.presentation.toCostructuredArrow end IsIndObject open IsFiltered.SmallFilteredIntermediate theorem isIndObject_of_isFiltered_of_finallySmall (A : Cᵒᵖ ⥤ Type v) [IsFiltered (CostructuredArrow yoneda A)] [FinallySmall.{v} (CostructuredArrow yoneda A)] : IsIndObject A := by have h₁ : (factoring (fromFinalModel (CostructuredArrow yoneda A)) ⋙ inclusion (fromFinalModel (CostructuredArrow yoneda A))).Final := Functor.final_of_natIso (factoringCompInclusion (fromFinalModel <| CostructuredArrow yoneda A)).symm have h₂ : Functor.Final (inclusion (fromFinalModel (CostructuredArrow yoneda A))) := Functor.final_of_comp_full_faithful' (factoring _) (inclusion _) let c := (Presheaf.tautologicalCocone A).whisker (inclusion (fromFinalModel (CostructuredArrow yoneda A))) let hc : IsColimit c := (Functor.Final.isColimitWhiskerEquiv _ _).symm (Presheaf.isColimitTautologicalCocone A) have hq : Nonempty (FinalModel (CostructuredArrow yoneda A)) := Nonempty.map (Functor.Final.lift (fromFinalModel (CostructuredArrow yoneda A))) IsFiltered.nonempty exact ⟨_, inclusion (fromFinalModel _) ⋙ CostructuredArrow.proj yoneda A, c.ι, hc⟩ /-- The recognition theorem for ind-objects: `A : Cᵒᵖ ⥤ Type v` is an ind-object if and only if `CostructuredArrow yoneda A` is filtered and finally `v`-small. Theorem 6.1.5 of [Kashiwara2006] -/ theorem isIndObject_iff (A : Cᵒᵖ ⥤ Type v) : IsIndObject A ↔ (IsFiltered (CostructuredArrow yoneda A) ∧ FinallySmall.{v} (CostructuredArrow yoneda A)) := ⟨fun h => ⟨h.isFiltered, h.finallySmall⟩, fun ⟨_, _⟩ => isIndObject_of_isFiltered_of_finallySmall A⟩ /-- If a limit already exists in `C`, then the limit of the image of the diagram under the Yoneda embedding is an ind-object. -/ theorem isIndObject_limit_comp_yoneda {J : Type u'} [Category.{v'} J] (F : J ⥤ C) [HasLimit F] : IsIndObject (limit (F ⋙ yoneda)) := IsIndObject.map (preservesLimitIso yoneda F).hom (isIndObject_yoneda (limit F)) end NonSmall section Small variable {C : Type u} [SmallCategory C] /-- Presheaves over a small finitely cocomplete category `C : Type u` are Ind-objects if and only if they are left-exact. -/ lemma isIndObject_iff_preservesFiniteLimits [HasFiniteColimits C] (A : Cᵒᵖ ⥤ Type u) : IsIndObject A ↔ PreservesFiniteLimits A := (isIndObject_iff A).trans <| by refine ⟨fun ⟨h₁, h₂⟩ => ?_, fun h => ⟨?_, ?_⟩⟩ · apply preservesFiniteLimits_of_isFiltered_costructuredArrow_yoneda · exact isFiltered_costructuredArrow_yoneda_of_preservesFiniteLimits A · have := essentiallySmallSelf (CostructuredArrow yoneda A) apply finallySmall_of_essentiallySmall end Small end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Indization/Category.lean
import Mathlib.CategoryTheory.Limits.Constructions.Filtered import Mathlib.CategoryTheory.Limits.FullSubcategory import Mathlib.CategoryTheory.Limits.ExactFunctor import Mathlib.CategoryTheory.Limits.Indization.Equalizers import Mathlib.CategoryTheory.Limits.Indization.LocallySmall import Mathlib.CategoryTheory.Limits.Indization.Products import Mathlib.CategoryTheory.Limits.Preserves.Presheaf /-! # The category of Ind-objects We define the `v`-category of Ind-objects of a category `C`, called `Ind C`, as well as the functors `Ind.yoneda : C ⥤ Ind C` and `Ind.inclusion C : Ind C ⥤ Cᵒᵖ ⥤ Type v`. For a small filtered category `I`, we also define `Ind.lim I : (I ⥤ C) ⥤ Ind C` and show that it preserves finite limits and finite colimits. This file will mainly collect results about ind-objects (stated in terms of `IsIndObject`) and reinterpret them in terms of `Ind C`. Adopting the theorem numbering of [Kashiwara2006], we show the following properties: Limits: * If `C` has products indexed by `α`, then `Ind C` has products indexed by `α`, and the functor `Ind C ⥤ Cᵒᵖ ⥤ Type v` creates such products (6.1.17), * if `C` has equalizers, then `Ind C` has equalizers, and the functor `Ind C ⥤ Cᵒᵖ ⥤ Type v` creates them (6.1.17) * if `C` has small limits (resp. finite limits), then `Ind C` has small limits (resp. finite limits) and the functor `Ind C ⥤ Cᵒᵖ ⥤ Type v` creates them (6.1.17), * the functor `C ⥤ Ind C` preserves small limits (6.1.17). Colimits: * `Ind C` has filtered colimits (6.1.8), and the functor `Ind C ⥤ Cᵒᵖ ⥤ Type v` preserves filtered colimits, * if `C` has coproducts indexed by a finite type `α`, then `Ind C` has coproducts indexed by `α` (6.1.18(ii)), * if `C` has finite coproducts, then `Ind C` has small coproducts (6.1.18(ii)), * if `C` has coequalizers, then `Ind C` has coequalizers (6.1.18(i)), * if `C` has finite colimits, then `Ind C` has small colimits (6.1.18(iii)). * `C ⥤ Ind C` preserves finite colimits (6.1.6), Note that: * the functor `Ind C ⥤ Cᵒᵖ ⥤ Type v` does not preserve any kind of colimit in general except for filtered colimits and * the functor `C ⥤ Ind C` preserves finite colimits, but not infinite colimits in general. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Chapter 6 -/ universe w v u namespace CategoryTheory open Limits Functor variable {C : Type u} [Category.{v} C] variable (C) in /-- The category of Ind-objects of `C`. -/ def Ind : Type (max u (v + 1)) := ShrinkHoms (ObjectProperty.FullSubcategory (IsIndObject (C := C))) noncomputable instance : Category.{v} (Ind C) := inferInstanceAs <| Category.{v} (ShrinkHoms (ObjectProperty.FullSubcategory (IsIndObject (C := C)))) variable (C) in /-- The defining properties of `Ind C` are that its morphisms live in `v` and that it is equivalent to the full subcategory of `Cᵒᵖ ⥤ Type v` containing the ind-objects. -/ noncomputable def Ind.equivalence : Ind C ≌ ObjectProperty.FullSubcategory (IsIndObject (C := C)) := (ShrinkHoms.equivalence _).symm variable (C) in /-- The canonical inclusion of ind-objects into presheaves. -/ protected noncomputable def Ind.inclusion : Ind C ⥤ Cᵒᵖ ⥤ Type v := (Ind.equivalence C).functor ⋙ ObjectProperty.ι _ instance : (Ind.inclusion C).Full := inferInstanceAs <| ((Ind.equivalence C).functor ⋙ ObjectProperty.ι _).Full instance : (Ind.inclusion C).Faithful := inferInstanceAs <| ((Ind.equivalence C).functor ⋙ ObjectProperty.ι _).Faithful /-- The functor `Ind C ⥤ Cᵒᵖ ⥤ Type v` is fully faithful. -/ protected noncomputable def Ind.inclusion.fullyFaithful : (Ind.inclusion C).FullyFaithful := .ofFullyFaithful _ /-- The inclusion of `C` into `Ind C` induced by the Yoneda embedding. -/ protected noncomputable def Ind.yoneda : C ⥤ Ind C := ObjectProperty.lift _ CategoryTheory.yoneda isIndObject_yoneda ⋙ (Ind.equivalence C).inverse instance : (Ind.yoneda (C := C)).Full := inferInstanceAs <| Functor.Full <| ObjectProperty.lift _ CategoryTheory.yoneda isIndObject_yoneda ⋙ (Ind.equivalence C).inverse instance : (Ind.yoneda (C := C)).Faithful := inferInstanceAs <| Functor.Faithful <| ObjectProperty.lift _ CategoryTheory.yoneda isIndObject_yoneda ⋙ (Ind.equivalence C).inverse /-- The functor `C ⥤ Ind C` is fully faithful. -/ protected noncomputable def Ind.yoneda.fullyFaithful : (Ind.yoneda (C := C)).FullyFaithful := .ofFullyFaithful _ /-- The composition `C ⥤ Ind C ⥤ (Cᵒᵖ ⥤ Type v)` is just the Yoneda embedding. -/ noncomputable def Ind.yonedaCompInclusion : Ind.yoneda ⋙ Ind.inclusion C ≅ CategoryTheory.yoneda := isoWhiskerLeft (ObjectProperty.lift _ _ _) (isoWhiskerRight (Ind.equivalence C).counitIso (ObjectProperty.ι _)) noncomputable instance {J : Type v} [SmallCategory J] [IsFiltered J] : ObjectProperty.IsClosedUnderColimitsOfShape (IsIndObject (C := C)) J := .mk' (by rintro _ ⟨F, hF⟩ exact isIndObject_colimit _ _ hF) noncomputable instance {J : Type v} [SmallCategory J] [IsFiltered J] : CreatesColimitsOfShape J (Ind.inclusion C) := inferInstanceAs <| CreatesColimitsOfShape J ((Ind.equivalence C).functor ⋙ ObjectProperty.ι _) instance : HasFilteredColimits (Ind C) where HasColimitsOfShape _ _ _ := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape (Ind.inclusion C) noncomputable instance {J : Type v} [HasLimitsOfShape (Discrete J) C] : ObjectProperty.IsClosedUnderLimitsOfShape (IsIndObject (C := C)) (Discrete J) := .mk' (by rintro _ ⟨F, hF⟩ exact isIndObject_limit_of_discrete_of_hasLimitsOfShape _ hF) noncomputable instance {J : Type v} [HasLimitsOfShape (Discrete J) C] : CreatesLimitsOfShape (Discrete J) (Ind.inclusion C) := inferInstanceAs <| CreatesLimitsOfShape (Discrete J) ((Ind.equivalence C).functor ⋙ ObjectProperty.ι _) instance {J : Type v} [HasLimitsOfShape (Discrete J) C] : HasLimitsOfShape (Discrete J) (Ind C) := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (Ind.inclusion C) noncomputable instance [HasLimitsOfShape WalkingParallelPair C] : CreatesLimitsOfShape WalkingParallelPair (Ind.inclusion C) := inferInstanceAs <| CreatesLimitsOfShape WalkingParallelPair ((Ind.equivalence C).functor ⋙ ObjectProperty.ι _) instance [HasLimitsOfShape WalkingParallelPair C] : HasLimitsOfShape WalkingParallelPair (Ind C) := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (Ind.inclusion C) noncomputable instance [HasFiniteLimits C] : CreatesFiniteLimits (Ind.inclusion C) := letI _ : CreatesFiniteProducts (Ind.inclusion C) := { creates _ _ := createsLimitsOfShapeOfEquiv (Discrete.equivalence Equiv.ulift) _ } createsFiniteLimitsOfCreatesEqualizersAndFiniteProducts (Ind.inclusion C) instance [HasFiniteLimits C] : HasFiniteLimits (Ind C) := hasFiniteLimits_of_hasLimitsLimits_of_createsFiniteLimits (Ind.inclusion C) noncomputable instance [HasLimits C] : CreatesLimitsOfSize.{v, v} (Ind.inclusion C) := createsLimitsOfSizeOfCreatesEqualizersAndProducts.{v, v} (Ind.inclusion C) instance [HasLimits C] : HasLimits (Ind C) := hasLimits_of_hasLimits_createsLimits (Ind.inclusion C) instance : PreservesLimits (Ind.yoneda (C := C)) := letI _ : PreservesLimitsOfSize.{v, v} (Ind.yoneda ⋙ Ind.inclusion C) := preservesLimits_of_natIso Ind.yonedaCompInclusion.symm preservesLimits_of_reflects_of_preserves Ind.yoneda (Ind.inclusion C) theorem Ind.isIndObject_inclusion_obj (X : Ind C) : IsIndObject ((Ind.inclusion C).obj X) := X.2 /-- Pick a presentation of an ind-object `X` using choice. -/ noncomputable def Ind.presentation (X : Ind C) : IndObjectPresentation ((Ind.inclusion C).obj X) := X.isIndObject_inclusion_obj.presentation /-- An ind-object `X` is the colimit (in `Ind C`!) of the filtered diagram presenting it. -/ noncomputable def Ind.colimitPresentationCompYoneda (X : Ind C) : colimit (X.presentation.F ⋙ Ind.yoneda) ≅ X := Ind.inclusion.fullyFaithful.isoEquiv.symm <| calc (Ind.inclusion C).obj (colimit (X.presentation.F ⋙ Ind.yoneda)) ≅ colimit (X.presentation.F ⋙ Ind.yoneda ⋙ Ind.inclusion C) := preservesColimitIso _ _ _ ≅ colimit (X.presentation.F ⋙ yoneda) := HasColimit.isoOfNatIso (isoWhiskerLeft X.presentation.F Ind.yonedaCompInclusion) _ ≅ (Ind.inclusion C).obj X := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) X.presentation.isColimit instance : RepresentablyCoflat (Ind.yoneda (C := C)) := by refine ⟨fun X => ?_⟩ suffices IsFiltered (CostructuredArrow yoneda ((Ind.inclusion C).obj X)) from IsFiltered.of_equivalence ((CostructuredArrow.post Ind.yoneda (Ind.inclusion C) X).asEquivalence.trans (CostructuredArrow.mapNatIso Ind.yonedaCompInclusion)).symm exact ((isIndObject_iff _).1 (Ind.isIndObject_inclusion_obj X)).1 noncomputable instance : PreservesFiniteColimits (Ind.yoneda (C := C)) := preservesFiniteColimits_of_coflat _ /-- This is the functor `(I ⥤ C) ⥤ Ind C` that sends a functor `F` to `colim (Y ∘ F)`, where `Y` is the Yoneda embedding. It is known as "ind-lim" and denoted `“colim”` in [Kashiwara2006]. -/ protected noncomputable def Ind.lim (I : Type v) [SmallCategory I] [IsFiltered I] : (I ⥤ C) ⥤ Ind C := (whiskeringRight _ _ _).obj Ind.yoneda ⋙ colim /-- Computing ind-lims in `Ind C` is the same as computing them in `Cᵒᵖ ⥤ Type v`. -/ noncomputable def Ind.limCompInclusion {I : Type v} [SmallCategory I] [IsFiltered I] : Ind.lim I ⋙ Ind.inclusion C ≅ (whiskeringRight _ _ _).obj yoneda ⋙ colim := calc Ind.lim I ⋙ Ind.inclusion C ≅ (whiskeringRight _ _ _).obj Ind.yoneda ⋙ colim ⋙ Ind.inclusion C := Functor.associator _ _ _ _ ≅ (whiskeringRight _ _ _).obj Ind.yoneda ⋙ (whiskeringRight _ _ _).obj (Ind.inclusion C) ⋙ colim := isoWhiskerLeft _ (preservesColimitNatIso _) _ ≅ ((whiskeringRight _ _ _).obj Ind.yoneda ⋙ (whiskeringRight _ _ _).obj (Ind.inclusion C)) ⋙ colim := (Functor.associator _ _ _).symm _ ≅ (whiskeringRight _ _ _).obj (Ind.yoneda ⋙ Ind.inclusion C) ⋙ colim := isoWhiskerRight (whiskeringRightObjCompIso _ _) colim _ ≅ (whiskeringRight _ _ _).obj yoneda ⋙ colim := isoWhiskerRight ((whiskeringRight _ _ _).mapIso (Ind.yonedaCompInclusion)) colim instance {α : Type w} [SmallCategory α] [FinCategory α] [HasLimitsOfShape α C] {I : Type v} [SmallCategory I] [IsFiltered I] : PreservesLimitsOfShape α (Ind.lim I : (I ⥤ C) ⥤ _) := haveI : PreservesLimitsOfShape α (Ind.lim I ⋙ Ind.inclusion C) := preservesLimitsOfShape_of_natIso Ind.limCompInclusion.symm preservesLimitsOfShape_of_reflects_of_preserves _ (Ind.inclusion C) instance {α : Type w} [SmallCategory α] [FinCategory α] [HasColimitsOfShape α C] {I : Type v} [SmallCategory I] [IsFiltered I] : PreservesColimitsOfShape α (Ind.lim I : (I ⥤ C) ⥤ _) := inferInstanceAs (PreservesColimitsOfShape α (_ ⋙ colim)) instance {α : Type v} [Finite α] [HasColimitsOfShape (Discrete α) C] : HasColimitsOfShape (Discrete α) (Ind C) := by refine ⟨fun F => ?_⟩ let I : α → Type v := fun s => (F.obj ⟨s⟩).presentation.I let G : ∀ s, I s ⥤ C := fun s => (F.obj ⟨s⟩).presentation.F let iso : Discrete.functor (fun s => Pi.eval I s ⋙ G s) ⋙ (whiskeringRight _ _ _).obj Ind.yoneda ⋙ colim ≅ F := by refine Discrete.natIso (fun s => ?_) refine (Functor.Final.colimitIso (Pi.eval I s.as) (G s.as ⋙ Ind.yoneda)) ≪≫ ?_ exact Ind.colimitPresentationCompYoneda _ -- The actual proof happens during typeclass resolution in the following line, which deduces -- ``` -- HasColimit Discrete.functor (fun s => Pi.eval I s ⋙ G s) ⋙ -- (whiskeringRight _ _ _).obj Ind.yoneda ⋙ colim -- ``` -- from the fact that finite limits commute with filtered colimits and from the fact that -- `Ind.yoneda` preserves finite colimits. exact hasColimit_of_iso iso.symm instance [HasFiniteCoproducts C] : HasCoproducts.{v} (Ind C) := have : HasFiniteCoproducts (Ind C) := ⟨fun _ => hasColimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift)⟩ hasCoproducts_of_finite_and_filtered /-- Given an `IndParallelPairPresentation f g`, we can understand the parallel pair `(f, g)` as the colimit of `(P.φ, P.ψ)` in `Ind C`. -/ noncomputable def IndParallelPairPresentation.parallelPairIsoParallelPairCompIndYoneda {A B : Ind C} {f g : A ⟶ B} (P : IndParallelPairPresentation ((Ind.inclusion _).map f) ((Ind.inclusion _).map g)) : parallelPair f g ≅ parallelPair P.φ P.ψ ⋙ Ind.lim P.I := ((whiskeringRight WalkingParallelPair _ _).obj (Ind.inclusion C)).preimageIso <| diagramIsoParallelPair _ ≪≫ P.parallelPairIsoParallelPairCompYoneda ≪≫ isoWhiskerLeft (parallelPair _ _) Ind.limCompInclusion.symm instance [HasColimitsOfShape WalkingParallelPair C] : HasColimitsOfShape WalkingParallelPair (Ind C) := by refine ⟨fun F => ?_⟩ obtain ⟨P⟩ := nonempty_indParallelPairPresentation (F.obj WalkingParallelPair.zero).2 (F.obj WalkingParallelPair.one).2 (Ind.inclusion _ |>.map <| F.map WalkingParallelPairHom.left) (Ind.inclusion _ |>.map <| F.map WalkingParallelPairHom.right) exact hasColimit_of_iso (diagramIsoParallelPair _ ≪≫ P.parallelPairIsoParallelPairCompIndYoneda) instance [HasFiniteColimits C] : HasColimits (Ind C) := has_colimits_of_hasCoequalizers_and_coproducts /-- A way to understand morphisms in `Ind C`: every morphism is induced by a natural transformation of diagrams. -/ theorem Ind.exists_nonempty_arrow_mk_iso_ind_lim {A B : Ind C} {f : A ⟶ B} : ∃ (I : Type v) (_ : SmallCategory I) (_ : IsFiltered I) (F G : I ⥤ C) (φ : F ⟶ G), Nonempty (Arrow.mk f ≅ Arrow.mk ((Ind.lim _).map φ)) := by obtain ⟨P⟩ := nonempty_indParallelPairPresentation A.2 B.2 (Ind.inclusion _ |>.map f) (Ind.inclusion _ |>.map f) refine ⟨P.I, inferInstance, inferInstance, P.F₁, P.F₂, P.φ, ⟨Arrow.isoMk ?_ ?_ ?_⟩⟩ · exact P.parallelPairIsoParallelPairCompIndYoneda.app WalkingParallelPair.zero · exact P.parallelPairIsoParallelPairCompIndYoneda.app WalkingParallelPair.one · simpa using (P.parallelPairIsoParallelPairCompIndYoneda.hom.naturality WalkingParallelPairHom.left).symm section Small variable (C : Type u) [SmallCategory C] [HasFiniteColimits C] /-- For small finitely cocomplete categories `C : Type u`, the category of Ind-objects `Ind C` is equivalent to the category of left-exact functors `Cᵒᵖ ⥤ Type u` -/ noncomputable def Ind.leftExactFunctorEquivalence : Ind C ≌ LeftExactFunctor Cᵒᵖ (Type u) := (Ind.equivalence _).trans <| ObjectProperty.fullSubcategoryCongr (by ext; apply isIndObject_iff_preservesFiniteLimits) end Small end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Indization/LocallySmall.lean
import Mathlib.CategoryTheory.Limits.Preserves.Ulift import Mathlib.CategoryTheory.Limits.IndYoneda import Mathlib.CategoryTheory.Limits.Indization.IndObject /-! # There are only `v`-many natural transformations between Ind-objects We provide the instance `LocallySmall.{v} (FullSubcategory (IsIndObject (C := C)))`, which will serve as the basis for our definition of the category of Ind-objects. ## Future work The equivalence established here serves as the basis for a well-known calculation of hom-sets of ind-objects as a limit of a colimit. -/ open CategoryTheory Limits Opposite universe v v₁ v₂ u u₁ u₂ variable {C : Type u} [Category.{v} C] namespace CategoryTheory section variable {I : Type u₁} [Category.{v₁} I] [HasColimitsOfShape I (Type v)] [HasLimitsOfShape Iᵒᵖ (Type v)] variable {J : Type u₂} [Category.{v₂} J] [HasLimitsOfShape Iᵒᵖ (Type (max u v))] variable (F : I ⥤ C) (G : Cᵒᵖ ⥤ Type v) /-- Variant of `colimitYonedaHomIsoLimitOp`: natural transformations with domain `colimit (F ⋙ yoneda)` are equivalent to a limit in a lower universe. -/ noncomputable def colimitYonedaHomEquiv : (colimit (F ⋙ yoneda) ⟶ G) ≃ limit (F.op ⋙ G) := Equiv.symm <| Equiv.ulift.symm.trans <| Equiv.symm <| Iso.toEquiv <| calc (colimit (F ⋙ yoneda) ⟶ G) ≅ limit (F.op ⋙ G ⋙ uliftFunctor.{u}) := colimitYonedaHomIsoLimitOp _ _ _ ≅ limit ((F.op ⋙ G) ⋙ uliftFunctor.{u}) := HasLimit.isoOfNatIso (Functor.associator _ _ _).symm _ ≅ uliftFunctor.{u}.obj (limit (F.op ⋙ G)) := (preservesLimitIso _ _).symm @[simp] theorem colimitYonedaHomEquiv_π_apply (η : colimit (F ⋙ yoneda) ⟶ G) (i : Iᵒᵖ) : limit.π (F.op ⋙ G) i (colimitYonedaHomEquiv F G η) = η.app (op (F.obj i.unop)) ((colimit.ι (F ⋙ yoneda) i.unop).app _ (𝟙 _)) := by simp only [Functor.comp_obj, Functor.op_obj, colimitYonedaHomEquiv, uliftFunctor_obj, Iso.trans_def, Iso.trans_assoc, Iso.toEquiv_comp, Equiv.symm_trans_apply, Equiv.symm_symm, Equiv.trans_apply, Iso.toEquiv_fun, Iso.symm_hom, Equiv.ulift_apply] have (a : _) := congrArg ULift.down (congrFun (preservesLimitIso_inv_π uliftFunctor.{u, v} (F.op ⋙ G) i) a) dsimp at this rw [this, ← types_comp_apply (HasLimit.isoOfNatIso _).hom (limit.π _ _), HasLimit.isoOfNatIso_hom_π] simp instance : Small.{v} (colimit (F ⋙ yoneda) ⟶ G) where equiv_small := ⟨_, ⟨colimitYonedaHomEquiv F G⟩⟩ end instance : LocallySmall.{v} (ObjectProperty.FullSubcategory (IsIndObject (C := C))) where hom_small X Y := by obtain ⟨⟨P⟩⟩ := X.2 obtain ⟨⟨Q⟩⟩ := Y.2 let e₁ := IsColimit.coconePointUniqueUpToIso (P.isColimit) (colimit.isColimit _) let e₂ := IsColimit.coconePointUniqueUpToIso (Q.isColimit) (colimit.isColimit _) let e₃ := Iso.homCongr e₁ e₂ dsimp only [colimit.cocone_x] at e₃ exact small_map e₃ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Indization/Products.lean
import Mathlib.CategoryTheory.Limits.FilteredColimitCommutesProduct import Mathlib.CategoryTheory.Limits.Indization.FilteredColimits /-! # Ind-objects are closed under products We show that if `C` admits products indexed by `α`, then `IsIndObject` is closed under taking products in `Cᵒᵖ ⥤ Type v` indexed by `α`. This will imply that the functor `Ind C ⥤ Cᵒᵖ ⥤ Type v` creates products indexed by `α` and that the functor `C ⥤ Ind C` preserves them. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Prop. 6.1.16(ii) -/ universe v u namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {α : Type v} theorem isIndObject_pi (h : ∀ (g : α → C), IsIndObject (∏ᶜ yoneda.obj ∘ g)) (f : α → Cᵒᵖ ⥤ Type v) (hf : ∀ a, IsIndObject (f a)) : IsIndObject (∏ᶜ f) := by let F := fun a => (hf a).presentation.F ⋙ yoneda suffices (∏ᶜ f ≅ colimit (pointwiseProduct F)) from (isIndObject_colimit _ _ (fun i => h _)).map this.inv refine Pi.mapIso (fun s => ?_) ≪≫ (asIso (colimitPointwiseProductToProductColimit F)).symm exact IsColimit.coconePointUniqueUpToIso (hf s).presentation.isColimit (colimit.isColimit _) theorem isIndObject_limit_of_discrete (h : ∀ (g : α → C), IsIndObject (∏ᶜ yoneda.obj ∘ g)) (F : Discrete α ⥤ Cᵒᵖ ⥤ Type v) (hF : ∀ a, IsIndObject (F.obj a)) : IsIndObject (limit F) := IsIndObject.map (Pi.isoLimit _).hom (isIndObject_pi h _ (fun a => hF ⟨a⟩)) theorem isIndObject_limit_of_discrete_of_hasLimitsOfShape [HasLimitsOfShape (Discrete α) C] (F : Discrete α ⥤ Cᵒᵖ ⥤ Type v) (hF : ∀ a, IsIndObject (F.obj a)) : IsIndObject (limit F) := isIndObject_limit_of_discrete (fun g => (isIndObject_limit_comp_yoneda (Discrete.functor g)).map (HasLimit.isoOfNatIso (Discrete.compNatIsoDiscrete g yoneda)).hom) F hF end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Indization/Equalizers.lean
import Mathlib.CategoryTheory.Limits.Indization.FilteredColimits import Mathlib.CategoryTheory.Limits.Indization.ParallelPair import Mathlib.CategoryTheory.ObjectProperty.LimitsOfShape /-! # Equalizers of ind-objects We show that if a category `C` has equalizers, then ind-objects are closed under equalizers. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Section 6.1 -/ universe v v' u u' namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] section variable {I : Type v} [SmallCategory I] [IsFiltered I] variable {J : Type} [SmallCategory J] [FinCategory J] variable (F : J ⥤ I ⥤ C) /-- Suppose `F : J ⥤ I ⥤ C` is a finite diagram in the functor category `I ⥤ C`, where `I` is small and filtered. If `i : I`, we can apply the Yoneda embedding to `F(·, i)` to obtain a diagram of presheaves `J ⥤ Cᵒᵖ ⥤ Type v`. Suppose that the limits of this diagram is always an ind-object. For `j : J` we can apply the Yoneda embedding to `F(j, ·)` and take colimits to obtain a finite diagram `J ⥤ Cᵒᵖ ⥤ Type v` (which is actually a diagram `J ⥤ Ind C`). The theorem states that the limit of this diagram is an ind-object. This theorem will be used to construct equalizers in the category of ind-objects. It can be interpreted as saying that ind-objects are closed under finite limits as long as the diagram we are taking the limit of comes from a diagram in a functor category `I ⥤ C`. We will show (TODO) that this is the case for any parallel pair of morphisms in `Ind C` and deduce that ind-objects are closed under equalizers. This is Proposition 6.1.16(i) in [Kashiwara2006]. -/ theorem isIndObject_limit_comp_yoneda_comp_colim (hF : ∀ i, IsIndObject (limit (F.flip.obj i ⋙ yoneda))) : IsIndObject (limit (F ⋙ (Functor.whiskeringRight _ _ _).obj yoneda ⋙ colim)) := by let G : J ⥤ I ⥤ (Cᵒᵖ ⥤ Type v) := F ⋙ (Functor.whiskeringRight _ _ _).obj yoneda apply IsIndObject.map (HasLimit.isoOfNatIso (colimitFlipIsoCompColim G)).hom apply IsIndObject.map (colimitLimitIso G).hom apply isIndObject_colimit exact fun i => IsIndObject.map (limitObjIsoLimitCompEvaluation _ _).inv (hF i) end /-- If `C` has equalizers. then ind-objects are closed under equalizers. This is Proposition 6.1.17(i) in [Kashiwara2006]. -/ instance isClosedUnderLimitsOfShape_isIndObject_walkingParallelPair [HasEqualizers C] : ObjectProperty.IsClosedUnderLimitsOfShape (IsIndObject (C := C)) WalkingParallelPair := .mk' (by rintro _ ⟨F, h⟩ obtain ⟨P⟩ := nonempty_indParallelPairPresentation (h WalkingParallelPair.zero) (h WalkingParallelPair.one) (F.map WalkingParallelPairHom.left) (F.map WalkingParallelPairHom.right) exact IsIndObject.map (HasLimit.isoOfNatIso (P.parallelPairIsoParallelPairCompYoneda.symm ≪≫ (diagramIsoParallelPair _).symm)).hom (isIndObject_limit_comp_yoneda_comp_colim (parallelPair P.φ P.ψ) (fun i => isIndObject_limit_comp_yoneda _))) @[deprecated (since := "2025-09-22")] alias closedUnderLimitsOfShape_walkingParallelPair_isIndObject := isClosedUnderLimitsOfShape_isIndObject_walkingParallelPair end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Indization/FilteredColimits.lean
import Mathlib.CategoryTheory.Comma.Presheaf.Colimit import Mathlib.CategoryTheory.Limits.Filtered import Mathlib.CategoryTheory.Limits.FilteredColimitCommutesFiniteLimit import Mathlib.CategoryTheory.Limits.FunctorToTypes import Mathlib.CategoryTheory.Limits.Indization.IndObject import Mathlib.Logic.Small.Set /-! # Ind-objects are closed under filtered colimits We show that if `F : I ⥤ Cᵒᵖ ⥤ Type v` is a functor such that `I` is small and filtered and `F.obj i` is an ind-object for all `i`, then `colimit F` is also an ind-object. Our proof is a slight variant of the proof given in Kashiwara-Schapira. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Theorem 6.1.8 -/ universe v u namespace CategoryTheory.Limits open CategoryTheory CategoryTheory.CostructuredArrow CategoryTheory.Functor variable {C : Type u} [Category.{v} C] namespace IndizationClosedUnderFilteredColimitsAux variable {I : Type v} [SmallCategory I] (F : I ⥤ Cᵒᵖ ⥤ Type v) section Interchange /-! We start by stating the key interchange property `exists_nonempty_limit_obj_of_isColimit`. It consists of pulling out a colimit out of a hom functor and interchanging a filtered colimit with a finite limit. -/ variable {J : Type v} [SmallCategory J] [FinCategory J] variable (G : J ⥤ CostructuredArrow yoneda (colimit F)) -- We introduce notation for the functor `J ⥤ Over (colimit F)` induced by `G`. local notation "𝒢" => Functor.op G ⋙ Functor.op (toOver yoneda (colimit F)) variable {K : Type v} [SmallCategory K] (H : K ⥤ Over (colimit F)) /-- (implementation) Pulling out a colimit out of a hom functor is one half of the key lemma. Note that all of the heavy lifting actually happens in `CostructuredArrow.toOverCompYonedaColimit` and `yonedaYonedaColimit`. -/ noncomputable def compYonedaColimitIsoColimitCompYoneda : 𝒢 ⋙ yoneda.obj (colimit H) ≅ colimit (H ⋙ yoneda ⋙ (whiskeringLeft _ _ _).obj 𝒢) := calc 𝒢 ⋙ yoneda.obj (colimit H) ≅ 𝒢 ⋙ colimit (H ⋙ yoneda) := isoWhiskerLeft G.op (toOverCompYonedaColimit H) _ ≅ 𝒢 ⋙ (H ⋙ yoneda).flip ⋙ colim := isoWhiskerLeft _ (colimitIsoFlipCompColim _) _ ≅ (H ⋙ yoneda ⋙ (whiskeringLeft _ _ _).obj 𝒢).flip ⋙ colim := Iso.refl _ _ ≅ colimit (H ⋙ yoneda ⋙ (whiskeringLeft _ _ _).obj 𝒢) := (colimitIsoFlipCompColim _).symm theorem exists_nonempty_limit_obj_of_colimit [IsFiltered K] (h : Nonempty <| limit <| 𝒢 ⋙ yoneda.obj (colimit H)) : ∃ k, Nonempty <| limit <| 𝒢 ⋙ yoneda.obj (H.obj k) := by obtain ⟨t⟩ := h let t₂ := limMap (compYonedaColimitIsoColimitCompYoneda F G H).hom t let t₃ := (colimitLimitIso (H ⋙ yoneda ⋙ (whiskeringLeft _ _ _).obj 𝒢).flip).inv t₂ obtain ⟨k, y, -⟩ := Types.jointly_surjective'.{v, max u v} t₃ refine ⟨k, ⟨?_⟩⟩ let z := (limitObjIsoLimitCompEvaluation (H ⋙ yoneda ⋙ (whiskeringLeft _ _ _).obj 𝒢).flip k).hom y let y := flipCompEvaluation (H ⋙ yoneda ⋙ (whiskeringLeft _ _ _).obj 𝒢) k exact (lim.mapIso y).hom z theorem exists_nonempty_limit_obj_of_isColimit [IsFiltered K] {c : Cocone H} (hc : IsColimit c) (T : Over (colimit F)) (hT : c.pt ≅ T) (h : Nonempty <| limit <| 𝒢 ⋙ yoneda.obj T) : ∃ k, Nonempty <| limit <| 𝒢 ⋙ yoneda.obj (H.obj k) := by refine exists_nonempty_limit_obj_of_colimit F G H ?_ suffices T ≅ colimit H from Nonempty.map (lim.map (whiskerLeft 𝒢 (yoneda.map this.hom))) h refine hT.symm ≪≫ IsColimit.coconePointUniqueUpToIso hc (colimit.isColimit _) end Interchange theorem isFiltered [IsFiltered I] (hF : ∀ i, IsIndObject (F.obj i)) : IsFiltered (CostructuredArrow yoneda (colimit F)) := by -- It suffices to show that for any functor `G : J ⥤ CostructuredArrow yoneda (colimit F)` with -- `J` finite there is some `X` such that the set -- `lim Hom_{CostructuredArrow yoneda (colimit F)}(G·, X)` is nonempty. refine IsFiltered.iff_nonempty_limit.mpr (fun {J _ _} G => ?_) -- We begin by remarking that `lim Hom_{Over (colimit F)}(yG·, 𝟙 (colimit F))` is nonempty, -- simply because `𝟙 (colimit F)` is the terminal object. Here `y` is the functor -- `CostructuredArrow yoneda (colimit F) ⥤ Over (colimit F)` induced by `yoneda`. have h₁ : Nonempty (limit (G.op ⋙ (CostructuredArrow.toOver _ _).op ⋙ yoneda.obj (Over.mk (𝟙 (colimit F))))) := ⟨Types.Limit.mk _ (fun j => Over.mkIdTerminal.from _) (by simp)⟩ -- `𝟙 (colimit F)` is the colimit of the diagram in `Over (colimit F)` given by the arrows of -- the form `Fi ⟶ colimit F`. Thus, pulling the colimit out of the hom functor and commuting -- the finite limit with the filtered colimit, we obtain -- `lim_j Hom_{Over (colimit F)}(yGj, 𝟙 (colimit F)) ≅` -- `colim_i lim_j Hom_{Over (colimit F)}(yGj, colimit.ι F i)`, and so we find `i` such that -- the limit is non-empty. obtain ⟨i, hi⟩ := exists_nonempty_limit_obj_of_isColimit F G _ (colimit.isColimitToOver F) _ (Iso.refl _) h₁ -- `F.obj i` is a small filtered colimit of representables, say of the functor `H : K ⥤ C`, so -- `𝟙 (F.obj i)` is the colimit of the arrows of the form `yHk ⟶ Fi` in `Over Fi`. -- Then `colimit.ι F i` is the colimit of the arrows of the form -- `H.obj F ⟶ F.obj i ⟶ colimit F` in `Over (colimit F)`. obtain ⟨⟨P⟩⟩ := hF i let hc : IsColimit ((Over.map (colimit.ι F i)).mapCocone P.cocone.toOver) := isColimitOfPreserves (Over.map _) (Over.isColimitToOver P.coconeIsColimit) -- Again, we pull the colimit out of the hom functor and commute limit and colimit to obtain -- `lim_j Hom_{Over (colimit F)}(yGj, colimit.ι F i) ≅` -- `colim_k lim_j Hom_{Over (colimit F)}(yGj, yHk)`, and so we find `k` such that the limit -- is non-empty. obtain ⟨k, hk⟩ : ∃ k, Nonempty (limit (G.op ⋙ (CostructuredArrow.toOver yoneda (colimit F)).op ⋙ yoneda.obj ((CostructuredArrow.toOver yoneda (colimit F)).obj <| (CostructuredArrow.pre P.F yoneda (colimit F)).obj <| (map (colimit.ι F i)).obj <| mk _))) := exists_nonempty_limit_obj_of_isColimit F G _ hc _ (Iso.refl _) hi have htO : (CostructuredArrow.toOver yoneda (colimit F)).FullyFaithful := .ofFullyFaithful _ -- Since the inclusion `y : CostructuredArrow yoneda (colimit F) ⥤ Over (colimit F)` is fully -- faithful, `lim_j Hom_{Over (colimit F)}(yGj, yHk) ≅` -- `lim_j Hom_{CostructuredArrow yoneda (colimit F)}(Gj, Hk)` and so `Hk` is the object we're -- looking for. let q := fun X => isoWhiskerLeft _ (uliftYonedaIsoYoneda.symm.app _) ≪≫ htO.homNatIso X obtain ⟨t'⟩ := Nonempty.map (limMap (isoWhiskerLeft G.op (q _)).hom) hk exact ⟨_, ⟨((preservesLimitIso uliftFunctor.{max u v, v} _).inv t').down⟩⟩ end IndizationClosedUnderFilteredColimitsAux theorem isIndObject_colimit (I : Type v) [SmallCategory I] [IsFiltered I] (F : I ⥤ Cᵒᵖ ⥤ Type v) (hF : ∀ i, IsIndObject (F.obj i)) : IsIndObject (colimit F) := by have : IsFiltered (CostructuredArrow yoneda (colimit F)) := IndizationClosedUnderFilteredColimitsAux.isFiltered F hF refine (isIndObject_iff _).mpr ⟨this, ?_⟩ -- It remains to show that `CostructuredArrow yoneda (colimit F)` is finally small. Because we -- have already shown it is filtered, it suffices to exhibit a small weakly terminal set. For this -- we use that all the `CostructuredArrow yoneda (F.obj i)` have small weakly terminal sets. have : ∀ i, ∃ (s : Set (CostructuredArrow yoneda (F.obj i))) (_ : Small.{v} s), ∀ i, ∃ j ∈ s, Nonempty (i ⟶ j) := fun i => (hF i).finallySmall.exists_small_weakly_terminal_set choose s hs j hjs hj using this refine finallySmall_of_small_weakly_terminal_set (⋃ i, (map (colimit.ι F i)).obj '' (s i)) (fun A => ?_) obtain ⟨i, y, hy⟩ := FunctorToTypes.jointly_surjective'.{v, v} F _ (yonedaEquiv A.hom) let y' : CostructuredArrow yoneda (F.obj i) := mk (yonedaEquiv.symm y) obtain ⟨x⟩ := hj _ y' refine ⟨(map (colimit.ι F i)).obj (j i y'), ?_, ⟨?_⟩⟩ · simp only [Set.mem_iUnion, Set.mem_image] exact ⟨i, j i y', hjs _ _, rfl⟩ · refine ?_ ≫ (map (colimit.ι F i)).map x refine homMk (𝟙 A.left) (yonedaEquiv.injective ?_) simp [-EmbeddingLike.apply_eq_iff_eq, hy, yonedaEquiv_comp, y'] end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Indization/ParallelPair.lean
import Mathlib.CategoryTheory.Comma.Final import Mathlib.CategoryTheory.Limits.Indization.IndObject /-! # Parallel pairs of natural transformations between ind-objects We show that if `A` and `B` are ind-objects and `f` and `g` are natural transformations between `A` and `B`, then there is a small filtered category `I` such that `A`, `B`, `f` and `g` are commonly presented by diagrams and natural transformations in `I ⥤ C`. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Proposition 6.1.15 (though our proof is more direct). -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Limits Functor variable {C : Type u₁} [Category.{v₁} C] /-- Structure containing data exhibiting two parallel natural transformations `f` and `g` between presheaves `A` and `B` as induced by a natural transformation in a functor category exhibiting `A` and `B` as ind-objects. -/ structure IndParallelPairPresentation {A B : Cᵒᵖ ⥤ Type v₁} (f g : A ⟶ B) where /-- The indexing category. -/ I : Type v₁ /-- Category instance on the indexing category. -/ [ℐ : SmallCategory I] [hI : IsFiltered I] /-- The diagram presenting `A`. -/ F₁ : I ⥤ C /-- The diagram presenting `B`. -/ F₂ : I ⥤ C /-- The cocone on `F₁` with apex `A`. -/ ι₁ : F₁ ⋙ yoneda ⟶ (Functor.const I).obj A /-- The cocone on `F₁` with apex `A` is a colimit cocone. -/ isColimit₁ : IsColimit (Cocone.mk A ι₁) /-- The cocone on `F₂` with apex `B`. -/ ι₂ : F₂ ⋙ yoneda ⟶ (Functor.const I).obj B /-- The cocone on `F₂` with apex `B` is a colimit cocone. -/ isColimit₂ : IsColimit (Cocone.mk B ι₂) /-- The natural transformation presenting `f`. -/ φ : F₁ ⟶ F₂ /-- The natural transformation presenting `g`. -/ ψ : F₁ ⟶ F₂ /-- `f` is in fact presented by `φ`. -/ hf : f = IsColimit.map isColimit₁ (Cocone.mk B ι₂) (whiskerRight φ yoneda) /-- `g` is in fact presented by `ψ`. -/ hg : g = IsColimit.map isColimit₁ (Cocone.mk B ι₂) (whiskerRight ψ yoneda) instance {A B : Cᵒᵖ ⥤ Type v₁} {f g : A ⟶ B} (P : IndParallelPairPresentation f g) : SmallCategory P.I := P.ℐ instance {A B : Cᵒᵖ ⥤ Type v₁} {f g : A ⟶ B} (P : IndParallelPairPresentation f g) : IsFiltered P.I := P.hI namespace NonemptyParallelPairPresentationAux variable {A B : Cᵒᵖ ⥤ Type v₁} (f g : A ⟶ B) (P₁ : IndObjectPresentation A) (P₂ : IndObjectPresentation B) /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev K : Type v₁ := Comma ((P₁.toCostructuredArrow ⋙ CostructuredArrow.map f).prod' (P₁.toCostructuredArrow ⋙ CostructuredArrow.map g)) (P₂.toCostructuredArrow.prod' P₂.toCostructuredArrow) /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev F₁ : K f g P₁ P₂ ⥤ C := Comma.fst _ _ ⋙ P₁.F /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev F₂ : K f g P₁ P₂ ⥤ C := Comma.snd _ _ ⋙ P₂.F /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev ι₁ : F₁ f g P₁ P₂ ⋙ yoneda ⟶ (Functor.const (K f g P₁ P₂)).obj A := whiskerLeft (Comma.fst _ _) P₁.ι /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ noncomputable abbrev isColimit₁ : IsColimit (Cocone.mk A (ι₁ f g P₁ P₂)) := (Functor.Final.isColimitWhiskerEquiv _ _).symm P₁.isColimit /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev ι₂ : F₂ f g P₁ P₂ ⋙ yoneda ⟶ (Functor.const (K f g P₁ P₂)).obj B := whiskerLeft (Comma.snd _ _) P₂.ι /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ noncomputable abbrev isColimit₂ : IsColimit (Cocone.mk B (ι₂ f g P₁ P₂)) := (Functor.Final.isColimitWhiskerEquiv _ _).symm P₂.isColimit /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ def ϕ : F₁ f g P₁ P₂ ⟶ F₂ f g P₁ P₂ where app h := h.hom.1.left naturality _ _ h := by have := h.w simp only [Functor.prod'_obj, Functor.comp_obj, prod_Hom, Functor.prod'_map, Functor.comp_map, prod_comp, Prod.mk.injEq, CostructuredArrow.hom_eq_iff, CostructuredArrow.map_obj_left, IndObjectPresentation.toCostructuredArrow_obj_left, CostructuredArrow.comp_left, CostructuredArrow.map_map_left, IndObjectPresentation.toCostructuredArrow_map_left] at this exact this.1 theorem hf : f = IsColimit.map (isColimit₁ f g P₁ P₂) (Cocone.mk B (ι₂ f g P₁ P₂)) (whiskerRight (ϕ f g P₁ P₂) yoneda) := by refine (isColimit₁ f g P₁ P₂).hom_ext (fun i => ?_) rw [IsColimit.ι_map] simpa using i.hom.1.w.symm /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ def ψ : F₁ f g P₁ P₂ ⟶ F₂ f g P₁ P₂ where app h := h.hom.2.left naturality _ _ h := by have := h.w simp only [Functor.prod'_obj, Functor.comp_obj, prod_Hom, Functor.prod'_map, Functor.comp_map, prod_comp, Prod.mk.injEq, CostructuredArrow.hom_eq_iff, CostructuredArrow.map_obj_left, IndObjectPresentation.toCostructuredArrow_obj_left, CostructuredArrow.comp_left, CostructuredArrow.map_map_left, IndObjectPresentation.toCostructuredArrow_map_left] at this exact this.2 theorem hg : g = IsColimit.map (isColimit₁ f g P₁ P₂) (Cocone.mk B (ι₂ f g P₁ P₂)) (whiskerRight (ψ f g P₁ P₂) yoneda) := by refine (isColimit₁ f g P₁ P₂).hom_ext (fun i => ?_) rw [IsColimit.ι_map] simpa using i.hom.2.w.symm attribute [local instance] Comma.isFiltered_of_final in /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ noncomputable def presentation : IndParallelPairPresentation f g where I := K f g P₁ P₂ F₁ := F₁ f g P₁ P₂ F₂ := F₂ f g P₁ P₂ ι₁ := ι₁ f g P₁ P₂ isColimit₁ := isColimit₁ f g P₁ P₂ ι₂ := ι₂ f g P₁ P₂ isColimit₂ := isColimit₂ f g P₁ P₂ φ := ϕ f g P₁ P₂ ψ := ψ f g P₁ P₂ hf := hf f g P₁ P₂ hg := hg f g P₁ P₂ end NonemptyParallelPairPresentationAux theorem nonempty_indParallelPairPresentation {A B : Cᵒᵖ ⥤ Type v₁} (hA : IsIndObject A) (hB : IsIndObject B) (f g : A ⟶ B) : Nonempty (IndParallelPairPresentation f g) := ⟨NonemptyParallelPairPresentationAux.presentation f g hA.presentation hB.presentation⟩ namespace IndParallelPairPresentation /-- Given an `IndParallelPairPresentation f g`, we can understand the parallel pair `(f, g)` as the colimit of `(P.φ, P.ψ)` in `Cᵒᵖ ⥤ Type v`. -/ noncomputable def parallelPairIsoParallelPairCompYoneda {A B : Cᵒᵖ ⥤ Type v₁} {f g : A ⟶ B} (P : IndParallelPairPresentation f g) : parallelPair f g ≅ parallelPair P.φ P.ψ ⋙ (whiskeringRight _ _ _).obj yoneda ⋙ colim := parallelPair.ext (P.isColimit₁.coconePointUniqueUpToIso (colimit.isColimit _)) (P.isColimit₂.coconePointUniqueUpToIso (colimit.isColimit _)) (P.isColimit₁.hom_ext (fun j => by simp [P.hf, P.isColimit₁.ι_map_assoc, P.isColimit₁.comp_coconePointUniqueUpToIso_hom_assoc, P.isColimit₂.comp_coconePointUniqueUpToIso_hom])) (P.isColimit₁.hom_ext (fun j => by simp [P.hg, P.isColimit₁.ι_map_assoc, P.isColimit₁.comp_coconePointUniqueUpToIso_hom_assoc, P.isColimit₂.comp_coconePointUniqueUpToIso_hom])) end IndParallelPairPresentation end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Biproducts and binary biproducts We introduce the notion of (finite) biproducts. Binary biproducts are defined in `CategoryTheory.Limits.Shapes.BinaryBiproducts`. These are slightly unusual relative to the other shapes in the library, as they are simultaneously limits and colimits. (Zero objects are similar; they are "biterminal".) For results about biproducts in preadditive categories see `CategoryTheory.Preadditive.Biproducts`. For biproducts indexed by a `Fintype J`, a `bicone` consists of a cone point `X` and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`, such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. ## Notation As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for a binary biproduct. We introduce `⨁ f` for the indexed biproduct. ## Implementation notes Prior to https://github.com/leanprover-community/mathlib3/pull/14046, `HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type. As this had no pay-off (everything about limits is non-constructive in mathlib), and occasional cost (constructing decidability instances appropriate for constructions involving the indexing type), we made everything classical. -/ noncomputable section universe w w' v u open CategoryTheory Functor namespace CategoryTheory.Limits variable {J : Type w} universe uC' uC uD' uD variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] open scoped Classical in /-- A `c : Bicone F` is: * an object `c.pt` and * morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`, * such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. -/ structure Bicone (F : J → C) where pt : C π : ∀ j, pt ⟶ F j ι : ∀ j, F j ⟶ pt ι_π : ∀ j j', ι j ≫ π j' = if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π @[reassoc (attr := simp)] theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by simpa using B.ι_π j j @[reassoc (attr := simp)] theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by simpa [h] using B.ι_π j j' variable {F : J → C} /-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points which commutes with the cone and cocone legs. -/ structure BiconeMorphism {F : J → C} (A B : Bicone F) where /-- A morphism between the two vertex objects of the bicones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wπ : ∀ j : J, hom ≫ B.π j = A.π j := by cat_disch /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by cat_disch attribute [reassoc (attr := simp)] BiconeMorphism.wι BiconeMorphism.wπ /-- The category of bicones on a given diagram. -/ @[simps] instance Bicone.category : Category (Bicone F) where Hom A B := BiconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } /- We do not want `simps` automatically generate the lemma for simplifying the `Hom` field of -- a category. So we need to write the `ext` lemma in terms of the categorical morphism, rather than the underlying structure. -/ @[ext] theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Bicones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt) (wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by cat_disch) (wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by cat_disch) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv wι := fun j => φ.comp_inv_eq.mpr (wι j).symm wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm } variable (F) in /-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/ @[simps] def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] : Bicone F ⥤ Bicone (G.obj ∘ F) where obj A := { pt := G.obj A.pt π := fun j => G.map (A.π j) ι := fun j => G.map (A.ι j) ι_π := fun i j => (Functor.map_comp _ _ _).symm.trans <| by rw [A.ι_π] cat_disch } map f := { hom := G.map f.hom wπ := fun j => by simp [-BiconeMorphism.wπ, ← f.wπ j] wι := fun j => by simp [-BiconeMorphism.wι, ← f.wι j] } variable (G : C ⥤ D) instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom wι := fun j => G.map_injective (by simpa using t.wι j) wπ := fun j => G.map_injective (by simpa using t.wπ j) }, by cat_disch⟩ instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] : (functoriality F G).Faithful where map_injective {_X} {_Y} f g h := BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h end Bicones namespace Bicone attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- Extract the cone from a bicone. -/ def toConeFunctor : Bicone F ⥤ Cone (Discrete.functor F) where obj B := { pt := B.pt, π := { app := fun j => B.π j.as } } map {_ _} F := { hom := F.hom, w := fun _ => F.wπ _ } /-- A shorthand for `toConeFunctor.obj` -/ abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B -- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`. @[simp] theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl @[simp] theorem toCone_π_app (B : Bicone F) (j : Discrete J) : B.toCone.π.app j = B.π j.as := rfl theorem toCone_π_app_mk (B : Bicone F) (j : J) : B.toCone.π.app ⟨j⟩ = B.π j := rfl @[simp] theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.π j := rfl /-- Extract the cocone from a bicone. -/ def toCoconeFunctor : Bicone F ⥤ Cocone (Discrete.functor F) where obj B := { pt := B.pt, ι := { app := fun j => B.ι j.as } } map {_ _} F := { hom := F.hom, w := fun _ => F.wι _ } /-- A shorthand for `toCoconeFunctor.obj` -/ abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B @[simp] theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl @[simp] theorem toCocone_ι_app (B : Bicone F) (j : Discrete J) : B.toCocone.ι.app j = B.ι j.as := rfl @[simp] theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ι j := rfl theorem toCocone_ι_app_mk (B : Bicone F) (j : J) : B.toCocone.ι.app ⟨j⟩ = B.ι j := rfl open scoped Classical in /-- We can turn any limit cone over a discrete collection of objects into a bicone. -/ @[simps] def ofLimitCone {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where pt := t.pt π j := t.π.app ⟨j⟩ ι j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) ι_π j j' := by simp open scoped Classical in theorem ι_of_isLimit {f : J → C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) : t.ι j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] open scoped Classical in /-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/ @[simps] def ofColimitCocone {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : Bicone f where pt := t.pt π j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) ι j := t.ι.app ⟨j⟩ ι_π j j' := by simp open scoped Classical in theorem π_of_isColimit {f : J → C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) : t.π j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] /-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/ structure IsBilimit {F : J → C} (B : Bicone F) where isLimit : IsLimit B.toCone isColimit : IsColimit B.toCocone attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit attribute [simp] IsBilimit.mk.injEq attribute [local ext] Bicone.IsBilimit instance subsingleton_isBilimit {f : J → C} {c : Bicone f} : Subsingleton c.IsBilimit := ⟨fun _ _ => Bicone.IsBilimit.ext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩ section Whisker variable {K : Type w'} /-- Whisker a bicone with an equivalence between the indexing types. -/ @[simps] def whisker {f : J → C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where pt := c.pt π k := c.π (g k) ι k := c.ι (g k) ι_π k k' := by simp only [c.ι_π] split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto /-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cone and postcomposing with a suitable isomorphism. -/ def whiskerToCone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCone ≅ (Cones.postcompose (Discrete.functorComp f g).inv).obj (c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cones.ext (Iso.refl _) (by simp) /-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cocone and precomposing with a suitable isomorphism. -/ def whiskerToCocone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCocone ≅ (Cocones.precompose (Discrete.functorComp f g).hom).obj (c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cocones.ext (Iso.refl _) (by simp) /-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/ noncomputable def whiskerIsBilimitIff {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).IsBilimit ≃ c.IsBilimit := by refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩ · let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g) let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this · let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g) let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this · apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _ exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g) · apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _ exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g) end Whisker end Bicone /-- A bicone over `F : J → C`, which is both a limit cone and a colimit cocone. -/ structure LimitBicone (F : J → C) where bicone : Bicone F isBilimit : bicone.IsBilimit attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit /-- `HasBiproduct F` expresses the mere existence of a bicone which is simultaneously a limit and a colimit of the diagram `F`. -/ class HasBiproduct (F : J → C) : Prop where mk' :: exists_biproduct : Nonempty (LimitBicone F) attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct theorem HasBiproduct.mk {F : J → C} (d : LimitBicone F) : HasBiproduct F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/ def getBiproductData (F : J → C) [HasBiproduct F] : LimitBicone F := Classical.choice HasBiproduct.exists_biproduct /-- A bicone for `F` which is both a limit cone and a colimit cocone. -/ def biproduct.bicone (F : J → C) [HasBiproduct F] : Bicone F := (getBiproductData F).bicone /-- `biproduct.bicone F` is a bilimit bicone. -/ def biproduct.isBilimit (F : J → C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit := (getBiproductData F).isBilimit /-- `biproduct.bicone F` is a limit cone. -/ def biproduct.isLimit (F : J → C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone := (getBiproductData F).isBilimit.isLimit /-- `biproduct.bicone F` is a colimit cocone. -/ def biproduct.isColimit (F : J → C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone := (getBiproductData F).isBilimit.isColimit instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F := HasLimit.mk { cone := (biproduct.bicone F).toCone isLimit := biproduct.isLimit F } instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F := HasColimit.mk { cocone := (biproduct.bicone F).toCocone isColimit := biproduct.isColimit F } variable (J C) /-- `C` has biproducts of shape `J` if we have a limit and a colimit, with the same cone points, of every function `F : J → C`. -/ class HasBiproductsOfShape : Prop where has_biproduct : ∀ F : J → C, HasBiproduct F attribute [instance 100] HasBiproductsOfShape.has_biproduct /-- A category `HasFiniteBiproducts` if it has a biproduct for every finite family of objects in `C` indexed by a finite type. -/ class HasFiniteBiproducts : Prop where out : ∀ n, HasBiproductsOfShape (Fin n) C attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out variable {J} theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) : HasBiproductsOfShape J C := ⟨fun F => let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm) let ⟨c, hc⟩ := h HasBiproduct.mk <| by simpa only [Function.comp_def, e.symm_apply_apply] using LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩ instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] : HasBiproductsOfShape J C := by rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩ haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n exact hasBiproductsOfShape_of_equiv C e instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteProducts C where out _ := ⟨fun _ => hasLimit_of_iso Discrete.natIsoFunctor.symm⟩ instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteCoproducts C where out _ := ⟨fun _ => hasColimit_of_iso Discrete.natIsoFunctor⟩ instance (priority := 100) hasProductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] : HasProductsOfShape J C where has_limit _ := hasLimit_of_iso Discrete.natIsoFunctor.symm instance (priority := 100) hasCoproductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] : HasCoproductsOfShape J C where has_colimit _ := hasColimit_of_iso Discrete.natIsoFunctor variable {C} /-- The isomorphism between the specified limit and the specified colimit for a functor with a bilimit. -/ def biproductIso (F : J → C) [HasBiproduct F] : Limits.piObj F ≅ Limits.sigmaObj F := (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <| IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _) variable {J : Type w} {K : Type*} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] /-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will just use general facts about limits and colimits.) -/ abbrev biproduct (f : J → C) [HasBiproduct f] : C := (biproduct.bicone f).pt @[inherit_doc biproduct] notation "⨁ " f:20 => biproduct f /-- The projection onto a summand of a biproduct. -/ abbrev biproduct.π (f : J → C) [HasBiproduct f] (b : J) : ⨁ f ⟶ f b := (biproduct.bicone f).π b @[simp] theorem biproduct.bicone_π (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).π b = biproduct.π f b := rfl /-- The inclusion into a summand of a biproduct. -/ abbrev biproduct.ι (f : J → C) [HasBiproduct f] (b : J) : f b ⟶ ⨁ f := (biproduct.bicone f).ι b @[simp] theorem biproduct.bicone_ι (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).ι b = biproduct.ι f b := rfl /-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument. This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/ @[reassoc] theorem biproduct.ι_π [DecidableEq J] (f : J → C) [HasBiproduct f] (j j' : J) : biproduct.ι f j ≫ biproduct.π f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by convert (biproduct.bicone f).ι_π j j' @[reassoc] -- Not `simp` because `simp` can prove this theorem biproduct.ι_π_self (f : J → C) [HasBiproduct f] (j : J) : biproduct.ι f j ≫ biproduct.π f j = 𝟙 _ := by simp @[reassoc] theorem biproduct.ι_π_ne (f : J → C) [HasBiproduct f] {j j' : J} (h : j ≠ j') : biproduct.ι f j ≫ biproduct.π f j' = 0 := by simp [h] @[reassoc (attr := simp)] theorem biproduct.eqToHom_comp_ι (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : eqToHom (by simp [w]) ≫ biproduct.ι f j' = biproduct.ι f j := by cases w simp -- TODO?: simp can prove this using `eqToHom_naturality` -- but `eqToHom_naturality` applies less easily than this lemma @[reassoc] theorem biproduct.π_comp_eqToHom (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : biproduct.π f j ≫ eqToHom (by simp [w]) = biproduct.π f j' := by simp [*] /-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/ abbrev biproduct.lift {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ⨁ f := (biproduct.isLimit f).lift (Fan.mk P p) /-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/ abbrev biproduct.desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ⨁ f ⟶ P := (biproduct.isColimit f).desc (Cofan.mk P p) @[reassoc (attr := simp)] theorem biproduct.lift_π {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) (j : J) : biproduct.lift p ≫ biproduct.π f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩ @[reassoc (attr := simp)] theorem biproduct.ι_desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) (j : J) : biproduct.ι f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩ /-- Given a collection of maps between corresponding summands of a pair of biproducts indexed by the same type, we obtain a map between the biproducts. -/ abbrev biproduct.map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g) (Discrete.natTrans (fun j => p j.as)) /-- An alternative to `biproduct.map` constructed via colimits. This construction only exists in order to show it is equal to `biproduct.map`. -/ abbrev biproduct.map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) -- We put this at slightly higher priority than `biproduct.hom_ext'`, -- to get the matrix indices in the "right" order. @[ext 1001] theorem biproduct.hom_ext {f : J → C} [HasBiproduct f] {Z : C} (g h : Z ⟶ ⨁ f) (w : ∀ j, g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h := (biproduct.isLimit f).hom_ext fun j => w j.as @[ext] theorem biproduct.hom_ext' {f : J → C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟶ Z) (w : ∀ j, biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h := (biproduct.isColimit f).hom_ext fun j => w j.as /-- The canonical isomorphism between the chosen biproduct and the chosen product. -/ def biproduct.isoProduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∏ᶜ f := IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _) @[simp] theorem biproduct.isoProduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).hom = Pi.lift (biproduct.π f) := limit.hom_ext fun j => by simp [biproduct.isoProduct] @[simp] theorem biproduct.isoProduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).inv = biproduct.lift (Pi.π f) := biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq] /-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/ def biproduct.isoCoproduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∐ f := IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _) @[simp] theorem biproduct.isoCoproduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ι f) := colimit.hom_ext fun j => by simp [biproduct.isoCoproduct] @[simp] theorem biproduct.isoCoproduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ι f) := biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv] /-- If a category has biproducts of a shape `J`, its `colim` and `lim` functor on diagrams over `J` are isomorphic. -/ @[simps!] def HasBiproductsOfShape.colimIsoLim [HasBiproductsOfShape J C] : colim (J := Discrete J) (C := C) ≅ lim := NatIso.ofComponents (fun F => (Sigma.isoColimit F).symm ≪≫ (biproduct.isoCoproduct _).symm ≪≫ biproduct.isoProduct _ ≪≫ Pi.isoLimit F) fun η => colimit.hom_ext fun ⟨i⟩ => limit.hom_ext fun ⟨j⟩ => by classical by_cases h : i = j <;> simp_all [Sigma.isoColimit, Pi.isoLimit, biproduct.ι_π, biproduct.ι_π_assoc] theorem biproduct.map_eq_map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : biproduct.map p = biproduct.map' p := by classical ext dsimp simp only [Discrete.natTrans_app, Limits.IsColimit.ι_map_assoc, Limits.IsLimit.map_π, ← Bicone.toCone_π_app_mk, ← Bicone.toCocone_ι_app_mk] dsimp rw [biproduct.ι_π_assoc, biproduct.ι_π] split_ifs with h · subst h; simp · simp @[reassoc (attr := simp)] theorem biproduct.map_π {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.map p ≫ biproduct.π g j = biproduct.π f j ≫ p j := Limits.IsLimit.map_π _ _ _ (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.ι_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.ι f j ≫ biproduct.map p = p j ≫ biproduct.ι g j := by rw [biproduct.map_eq_map'] apply Limits.IsColimit.ι_map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.map_desc {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) {P : C} (k : ∀ j, g j ⟶ P) : biproduct.map p ≫ biproduct.desc k = biproduct.desc fun j => p j ≫ k j := by ext; simp @[reassoc (attr := simp)] theorem biproduct.lift_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] {P : C} (k : ∀ j, P ⟶ f j) (p : ∀ j, f j ⟶ g j) : biproduct.lift k ≫ biproduct.map p = biproduct.lift fun j => k j ≫ p j := by ext; simp /-- Given a collection of isomorphisms between corresponding summands of a pair of biproducts indexed by the same type, we obtain an isomorphism between the biproducts. -/ @[simps] def biproduct.mapIso {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ≅ g b) : ⨁ f ≅ ⨁ g where hom := biproduct.map fun b => (p b).hom inv := biproduct.map fun b => (p b).inv instance biproduct.map_epi {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Epi (p j)] : Epi (biproduct.map p) := by classical have : biproduct.map p = (biproduct.isoCoproduct _).hom ≫ Sigma.map p ≫ (biproduct.isoCoproduct _).inv := by ext simp only [map_π, isoCoproduct_hom, isoCoproduct_inv, Category.assoc, ι_desc_assoc, ι_colimMap_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app, colimit.ι_desc_assoc, Cofan.mk_pt, Cofan.mk_ι_app, ι_π, ι_π_assoc] split all_goals simp_all rw [this] infer_instance instance Pi.map_epi {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Epi (p j)] : Epi (Pi.map p) := by rw [show Pi.map p = (biproduct.isoProduct _).inv ≫ biproduct.map p ≫ (biproduct.isoProduct _).hom by aesop] infer_instance instance biproduct.map_mono {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Mono (p j)] : Mono (biproduct.map p) := by rw [show biproduct.map p = (biproduct.isoProduct _).hom ≫ Pi.map p ≫ (biproduct.isoProduct _).inv by aesop] infer_instance instance Sigma.map_mono {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Mono (p j)] : Mono (Sigma.map p) := by rw [show Sigma.map p = (biproduct.isoCoproduct _).inv ≫ biproduct.map p ≫ (biproduct.isoCoproduct _).hom by aesop] infer_instance /-- Two biproducts which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. Unfortunately there are two natural ways to define each direction of this isomorphism (because it is true for both products and coproducts separately). We give the alternative definitions as lemmas below. -/ @[simps] def biproduct.whiskerEquiv {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : ⨁ f ≅ ⨁ g where hom := biproduct.desc fun j => (w j).inv ≫ biproduct.ι g (e j) inv := biproduct.desc fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom ≫ biproduct.ι f _ lemma biproduct.whiskerEquiv_hom_eq_lift {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).hom = biproduct.lift fun k => biproduct.π f (e.symm k) ≫ (w _).inv ≫ eqToHom (by simp) := by simp only [whiskerEquiv_hom] ext k j by_cases h : k = e j · subst h simp · simp only [ι_desc_assoc, Category.assoc, lift_π] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] · simp · rintro rfl simp at h · exact Ne.symm h lemma biproduct.whiskerEquiv_inv_eq_lift {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).inv = biproduct.lift fun j => biproduct.π g (e j) ≫ (w j).hom := by simp only [whiskerEquiv_inv] ext j k by_cases h : k = e j · subst h simp only [ι_desc_assoc, ← eqToHom_iso_hom_naturality_assoc w (e.symm_apply_apply j).symm, Equiv.symm_apply_apply, eqToHom_comp_ι, Category.assoc, bicone_ι_π_self, Category.comp_id, lift_π, bicone_ι_π_self_assoc] · simp only [ι_desc_assoc, Category.assoc, lift_π] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] · simp · exact h · rintro rfl simp at h attribute [local simp] Sigma.forall in instance {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : HasBiproduct fun p : Σ i, f i => g p.1 p.2 where exists_biproduct := Nonempty.intro { bicone := { pt := ⨁ fun i => ⨁ g i ι := fun X => biproduct.ι (g X.1) X.2 ≫ biproduct.ι (fun i => ⨁ g i) X.1 π := fun X => biproduct.π (fun i => ⨁ g i) X.1 ≫ biproduct.π (g X.1) X.2 ι_π := fun ⟨j, x⟩ ⟨j', y⟩ => by split_ifs with h · obtain ⟨rfl, rfl⟩ := h simp · simp only [Sigma.mk.inj_iff, not_and] at h by_cases w : j = j' · cases w simp only [heq_eq_eq, forall_true_left] at h simp [biproduct.ι_π_ne _ h] · simp [biproduct.ι_π_ne_assoc _ w] } isBilimit := { isLimit := mkFanLimit _ (fun s => biproduct.lift fun b => biproduct.lift fun c => s.proj ⟨b, c⟩) isColimit := mkCofanColimit _ (fun s => biproduct.desc fun b => biproduct.desc fun c => s.inj ⟨b, c⟩) } } /-- An iterated biproduct is a biproduct over a sigma type. -/ @[simps] def biproductBiproductIso {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : (⨁ fun i => ⨁ g i) ≅ (⨁ fun p : Σ i, f i => g p.1 p.2) where hom := biproduct.lift fun ⟨i, x⟩ => biproduct.π _ i ≫ biproduct.π _ x inv := biproduct.lift fun i => biproduct.lift fun x => biproduct.π _ (⟨i, x⟩ : Σ i, f i) section πKernel section variable (f : J → C) [HasBiproduct f] variable (p : J → Prop) [HasBiproduct (Subtype.restrict p f)] /-- The canonical morphism from the biproduct over a restricted index type to the biproduct of the full index type. -/ def biproduct.fromSubtype : ⨁ Subtype.restrict p f ⟶ ⨁ f := biproduct.desc fun j => biproduct.ι _ j.val /-- The canonical morphism from a biproduct to the biproduct over a restriction of its index type. -/ def biproduct.toSubtype : ⨁ f ⟶ ⨁ Subtype.restrict p f := biproduct.lift fun _ => biproduct.π _ _ @[reassoc (attr := simp)] theorem biproduct.fromSubtype_π [DecidablePred p] (j : J) : biproduct.fromSubtype f p ≫ biproduct.π f j = if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := by classical ext i; dsimp rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π] by_cases h : p j · rw [dif_pos h, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] · rw [dif_neg h, dif_neg (show (i : J) ≠ j from fun h₂ => h (h₂ ▸ i.2)), comp_zero] theorem biproduct.fromSubtype_eq_lift [DecidablePred p] : biproduct.fromSubtype f p = biproduct.lift fun j => if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext _ _ (by simp) @[reassoc] -- Not `@[simp]` because `simp` can prove this theorem biproduct.fromSubtype_π_subtype (j : Subtype p) : biproduct.fromSubtype f p ≫ biproduct.π f j = biproduct.π (Subtype.restrict p f) j := by classical ext rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] @[reassoc (attr := simp)] theorem biproduct.toSubtype_π (j : Subtype p) : biproduct.toSubtype f p ≫ biproduct.π (Subtype.restrict p f) j = biproduct.π f j := biproduct.lift_π _ _ @[reassoc (attr := simp)] theorem biproduct.ι_toSubtype [DecidablePred p] (j : J) : biproduct.ι f j ≫ biproduct.toSubtype f p = if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := by classical ext i rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π] by_cases h : p j · rw [dif_pos h, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] · rw [dif_neg h, dif_neg (show j ≠ i from fun h₂ => h (h₂.symm ▸ i.2)), zero_comp] theorem biproduct.toSubtype_eq_desc [DecidablePred p] : biproduct.toSubtype f p = biproduct.desc fun j => if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext' _ _ (by simp) @[reassoc] theorem biproduct.ι_toSubtype_subtype (j : Subtype p) : biproduct.ι f j ≫ biproduct.toSubtype f p = biproduct.ι (Subtype.restrict p f) j := by classical ext rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] @[reassoc (attr := simp)] theorem biproduct.ι_fromSubtype (j : Subtype p) : biproduct.ι (Subtype.restrict p f) j ≫ biproduct.fromSubtype f p = biproduct.ι f j := biproduct.ι_desc _ _ @[reassoc (attr := simp)] theorem biproduct.fromSubtype_toSubtype : biproduct.fromSubtype f p ≫ biproduct.toSubtype f p = 𝟙 (⨁ Subtype.restrict p f) := by refine biproduct.hom_ext _ _ fun j => ?_ rw [Category.assoc, biproduct.toSubtype_π, biproduct.fromSubtype_π_subtype, Category.id_comp] @[reassoc (attr := simp)] theorem biproduct.toSubtype_fromSubtype [DecidablePred p] : biproduct.toSubtype f p ≫ biproduct.fromSubtype f p = biproduct.map fun j => if p j then 𝟙 (f j) else 0 := by ext1 i by_cases h : p i · simp [h] · simp [h] end section variable (f : J → C) (i : J) [HasBiproduct f] [HasBiproduct (Subtype.restrict (fun j => j ≠ i) f)] open scoped Classical in /-- The kernel of `biproduct.π f i` is the inclusion from the biproduct which omits `i` from the index set `J` into the biproduct over `J`. -/ def biproduct.isLimitFromSubtype : IsLimit (KernelFork.ofι (biproduct.fromSubtype f fun j => j ≠ i) (by simp) : KernelFork (biproduct.π f i)) := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ biproduct.toSubtype _ _, by apply biproduct.hom_ext; intro j rw [KernelFork.ι_ofι, Category.assoc, Category.assoc, biproduct.toSubtype_fromSubtype_assoc, biproduct.map_π] rcases Classical.em (i = j) with (rfl | h) · rw [if_neg (Classical.not_not.2 rfl), comp_zero, comp_zero, KernelFork.condition] · rw [if_pos (Ne.symm h), Category.comp_id], by intro m hm rw [← hm, KernelFork.ι_ofι, Category.assoc, biproduct.fromSubtype_toSubtype] exact (Category.comp_id _).symm⟩ instance : HasKernel (biproduct.π f i) := HasLimit.mk ⟨_, biproduct.isLimitFromSubtype f i⟩ /-- The kernel of `biproduct.π f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/ @[simps!] def kernelBiproductπIso : kernel (biproduct.π f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f := limit.isoLimitCone ⟨_, biproduct.isLimitFromSubtype f i⟩ open scoped Classical in /-- The cokernel of `biproduct.ι f i` is the projection from the biproduct over the index set `J` onto the biproduct omitting `i`. -/ def biproduct.isColimitToSubtype : IsColimit (CokernelCofork.ofπ (biproduct.toSubtype f fun j => j ≠ i) (by simp) : CokernelCofork (biproduct.ι f i)) := Cofork.IsColimit.mk' _ fun s => ⟨biproduct.fromSubtype _ _ ≫ s.π, by apply biproduct.hom_ext'; intro j rw [CokernelCofork.π_ofπ, biproduct.toSubtype_fromSubtype_assoc, biproduct.ι_map_assoc] rcases Classical.em (i = j) with (rfl | h) · rw [if_neg (Classical.not_not.2 rfl), zero_comp, CokernelCofork.condition] · rw [if_pos (Ne.symm h), Category.id_comp], by intro m hm rw [← hm, CokernelCofork.π_ofπ, ← Category.assoc, biproduct.fromSubtype_toSubtype] exact (Category.id_comp _).symm⟩ instance : HasCokernel (biproduct.ι f i) := HasColimit.mk ⟨_, biproduct.isColimitToSubtype f i⟩ /-- The cokernel of `biproduct.ι f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/ @[simps!] def cokernelBiproductιIso : cokernel (biproduct.ι f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f := colimit.isoColimitCocone ⟨_, biproduct.isColimitToSubtype f i⟩ end section -- Per https://github.com/leanprover-community/mathlib3/pull/15067, we only allow indexing in `Type 0` here. variable {K : Type} [Finite K] [HasFiniteBiproducts C] (f : K → C) /-- The limit cone exhibiting `⨁ Subtype.restrict pᶜ f` as the kernel of `biproduct.toSubtype f p` -/ @[simps] def kernelForkBiproductToSubtype (p : Set K) : LimitCone (parallelPair (biproduct.toSubtype f p) 0) where cone := KernelFork.ofι (biproduct.fromSubtype f pᶜ) (by classical ext j k simp only [Category.assoc, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] rw [dif_neg k.2] simp only [zero_comp]) isLimit := KernelFork.IsLimit.ofι _ _ (fun {_} g _ => g ≫ biproduct.toSubtype f pᶜ) (by classical intro W' g' w ext j simp only [Category.assoc, biproduct.toSubtype_fromSubtype, Pi.compl_apply, biproduct.map_π] split_ifs with h · simp · replace w := w =≫ biproduct.π _ ⟨j, not_not.mp h⟩ simpa using w.symm) (by cat_disch) instance (p : Set K) : HasKernel (biproduct.toSubtype f p) := HasLimit.mk (kernelForkBiproductToSubtype f p) /-- The kernel of `biproduct.toSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/ @[simps!] def kernelBiproductToSubtypeIso (p : Set K) : kernel (biproduct.toSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f := limit.isoLimitCone (kernelForkBiproductToSubtype f p) /-- The colimit cocone exhibiting `⨁ Subtype.restrict pᶜ f` as the cokernel of `biproduct.fromSubtype f p` -/ @[simps] def cokernelCoforkBiproductFromSubtype (p : Set K) : ColimitCocone (parallelPair (biproduct.fromSubtype f p) 0) where cocone := CokernelCofork.ofπ (biproduct.toSubtype f pᶜ) (by classical ext j k simp only [Category.assoc, Pi.compl_apply, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] rw [dif_neg] · simp only [zero_comp] · exact not_not.mpr k.2) isColimit := CokernelCofork.IsColimit.ofπ _ _ (fun {_} g _ => biproduct.fromSubtype f pᶜ ≫ g) (by classical intro W g' w ext j simp only [biproduct.toSubtype_fromSubtype_assoc, Pi.compl_apply, biproduct.ι_map_assoc] split_ifs with h · simp · replace w := biproduct.ι _ (⟨j, not_not.mp h⟩ : p) ≫= w simpa using w.symm) (by cat_disch) instance (p : Set K) : HasCokernel (biproduct.fromSubtype f p) := HasColimit.mk (cokernelCoforkBiproductFromSubtype f p) /-- The cokernel of `biproduct.fromSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/ @[simps!] def cokernelBiproductFromSubtypeIso (p : Set K) : cokernel (biproduct.fromSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f := colimit.isoColimitCocone (cokernelCoforkBiproductFromSubtype f p) end end πKernel section FiniteBiproducts variable {J : Type} [Finite J] {K : Type} [Finite K] {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasFiniteBiproducts C] {f : J → C} {g : K → C} /-- Convert a (dependently typed) matrix to a morphism of biproducts. -/ def biproduct.matrix (m : ∀ j k, f j ⟶ g k) : ⨁ f ⟶ ⨁ g := biproduct.desc fun j => biproduct.lift fun k => m j k @[reassoc (attr := simp)] theorem biproduct.matrix_π (m : ∀ j k, f j ⟶ g k) (k : K) : biproduct.matrix m ≫ biproduct.π g k = biproduct.desc fun j => m j k := by ext simp [biproduct.matrix] @[reassoc (attr := simp)] theorem biproduct.ι_matrix (m : ∀ j k, f j ⟶ g k) (j : J) : biproduct.ι f j ≫ biproduct.matrix m = biproduct.lift fun k => m j k := by simp [biproduct.matrix] /-- Extract the matrix components from a morphism of biproducts. -/ def biproduct.components (m : ⨁ f ⟶ ⨁ g) (j : J) (k : K) : f j ⟶ g k := biproduct.ι f j ≫ m ≫ biproduct.π g k @[simp] theorem biproduct.matrix_components (m : ∀ j k, f j ⟶ g k) (j : J) (k : K) : biproduct.components (biproduct.matrix m) j k = m j k := by simp [biproduct.components] @[simp] theorem biproduct.components_matrix (m : ⨁ f ⟶ ⨁ g) : (biproduct.matrix fun j k => biproduct.components m j k) = m := by ext simp [biproduct.components] /-- Morphisms between direct sums are matrices. -/ @[simps] def biproduct.matrixEquiv : (⨁ f ⟶ ⨁ g) ≃ ∀ j k, f j ⟶ g k where toFun := biproduct.components invFun := biproduct.matrix left_inv := biproduct.components_matrix right_inv m := by ext apply biproduct.matrix_components end FiniteBiproducts variable {J : Type w} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] instance biproduct.ι_mono (f : J → C) [HasBiproduct f] (b : J) : IsSplitMono (biproduct.ι f b) := by classical exact IsSplitMono.mk' { retraction := biproduct.desc <| Pi.single b (𝟙 (f b)) } instance biproduct.π_epi (f : J → C) [HasBiproduct f] (b : J) : IsSplitEpi (biproduct.π f b) := by classical exact IsSplitEpi.mk' { section_ := biproduct.lift <| Pi.single b (𝟙 (f b)) } /-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/ theorem biproduct.conePointUniqueUpToIso_hom (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).hom = biproduct.lift b.π := rfl /-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/ theorem biproduct.conePointUniqueUpToIso_inv (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).inv = biproduct.desc b.ι := by classical refine biproduct.hom_ext' _ _ fun j => hb.isLimit.hom_ext fun j' => ?_ rw [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp, Bicone.toCone_π_app, biproduct.bicone_π, biproduct.ι_desc, biproduct.ι_π, b.toCone_π_app, b.ι_π] /-- Biproducts are unique up to isomorphism. This already follows because bilimits are limits, but in the case of biproducts we can give an isomorphism with particularly nice definitional properties, namely that `biproduct.lift b.π` and `biproduct.desc b.ι` are inverses of each other. -/ @[simps] def biproduct.uniqueUpToIso (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : b.pt ≅ ⨁ f where hom := biproduct.lift b.π inv := biproduct.desc b.ι hom_inv_id := by rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.hom_inv_id] inv_hom_id := by rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.inv_hom_id] variable (C) -- see Note [lower instance priority] /-- A category with finite biproducts has a zero object. -/ instance (priority := 100) hasZeroObject_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasZeroObject C := by refine ⟨⟨biproduct Empty.elim, fun X => ⟨⟨⟨0⟩, ?_⟩⟩, fun X => ⟨⟨⟨0⟩, ?_⟩⟩⟩⟩ · intro a; apply biproduct.hom_ext'; simp · intro a; apply biproduct.hom_ext; simp section variable {C} attribute [local simp] eq_iff_true_of_subsingleton in /-- The limit bicone for the biproduct over an index type with exactly one term. -/ @[simps] def limitBiconeOfUnique [Unique J] (f : J → C) : LimitBicone f where bicone := { pt := f default π := fun j => eqToHom (by congr; rw [← Unique.uniq] ) ι := fun j => eqToHom (by congr; rw [← Unique.uniq] ) } isBilimit := { isLimit := (limitConeOfUnique f).isLimit isColimit := (colimitCoconeOfUnique f).isColimit } instance (priority := 100) hasBiproduct_unique [Subsingleton J] [Nonempty J] (f : J → C) : HasBiproduct f := let ⟨_⟩ := nonempty_unique J; .mk (limitBiconeOfUnique f) /-- A biproduct over an index type with exactly one term is just the object over that term. -/ @[simps!] def biproductUniqueIso [Unique J] (f : J → C) : ⨁ f ≅ f default := (biproduct.uniqueUpToIso _ (limitBiconeOfUnique f).isBilimit).symm end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/FunctorToTypes.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.CategoryTheory.Limits.Types.Colimits /-! # Binary (co)products of type-valued functors Defines an explicit construction of binary products and coproducts of type-valued functors. Also defines isomorphisms to the categorical product and coproduct, respectively. -/ open CategoryTheory.Limits universe w v u namespace CategoryTheory.FunctorToTypes variable {C : Type u} [Category.{v} C] variable (F G : C ⥤ Type w) section prod /-- `prod F G` is the explicit binary product of type-valued functors `F` and `G`. -/ def prod : C ⥤ Type w where obj a := F.obj a × G.obj a map f a := (F.map f a.1, G.map f a.2) variable {F G} /-- The first projection of `prod F G`, onto `F`. -/ @[simps] def prod.fst : prod F G ⟶ F where app _ a := a.1 /-- The second projection of `prod F G`, onto `G`. -/ @[simps] def prod.snd : prod F G ⟶ G where app _ a := a.2 /-- Given natural transformations `F ⟶ F₁` and `F ⟶ F₂`, construct a natural transformation `F ⟶ prod F₁ F₂`. -/ @[simps] def prod.lift {F₁ F₂ : C ⥤ Type w} (τ₁ : F ⟶ F₁) (τ₂ : F ⟶ F₂) : F ⟶ prod F₁ F₂ where app x y := ⟨τ₁.app x y, τ₂.app x y⟩ naturality _ _ _ := by ext a simp only [types_comp_apply, FunctorToTypes.naturality] aesop @[simp] lemma prod.lift_fst {F₁ F₂ : C ⥤ Type w} (τ₁ : F ⟶ F₁) (τ₂ : F ⟶ F₂) : prod.lift τ₁ τ₂ ≫ prod.fst = τ₁ := rfl @[simp] lemma prod.lift_snd {F₁ F₂ : C ⥤ Type w} (τ₁ : F ⟶ F₁) (τ₂ : F ⟶ F₂) : prod.lift τ₁ τ₂ ≫ prod.snd = τ₂ := rfl variable (F G) /-- The binary fan whose point is `prod F G`. -/ @[simps!] def binaryProductCone : BinaryFan F G := BinaryFan.mk prod.fst prod.snd /-- `prod F G` is a limit cone. -/ @[simps] def binaryProductLimit : IsLimit (binaryProductCone F G) where lift (s : BinaryFan F G) := prod.lift s.fst s.snd fac _ := fun ⟨j⟩ ↦ WalkingPair.casesOn j rfl rfl uniq _ _ h := by simp only [← h ⟨WalkingPair.right⟩, ← h ⟨WalkingPair.left⟩] congr /-- `prod F G` is a binary product for `F` and `G`. -/ def binaryProductLimitCone : Limits.LimitCone (pair F G) := ⟨_, binaryProductLimit F G⟩ /-- The categorical binary product of type-valued functors is `prod F G`. -/ noncomputable def binaryProductIso : F ⨯ G ≅ prod F G := limit.isoLimitCone (binaryProductLimitCone F G) @[simp] lemma binaryProductIso_hom_comp_fst : (binaryProductIso F G).hom ≫ prod.fst = Limits.prod.fst := rfl @[simp] lemma binaryProductIso_hom_comp_snd : (binaryProductIso F G).hom ≫ prod.snd = Limits.prod.snd := rfl @[simp] lemma binaryProductIso_inv_comp_fst : (binaryProductIso F G).inv ≫ Limits.prod.fst = prod.fst := by simp [binaryProductIso, binaryProductLimitCone] @[simp] lemma binaryProductIso_inv_comp_fst_apply (a : C) (z : (prod F G).obj a) : (Limits.prod.fst (X := F)).app a ((binaryProductIso F G).inv.app a z) = z.1 := congr_fun (congr_app (binaryProductIso_inv_comp_fst F G) a) z @[simp] lemma binaryProductIso_inv_comp_snd : (binaryProductIso F G).inv ≫ Limits.prod.snd = prod.snd := by simp [binaryProductIso, binaryProductLimitCone] @[simp] lemma binaryProductIso_inv_comp_snd_apply (a : C) (z : (prod F G).obj a) : (Limits.prod.snd (X := F)).app a ((binaryProductIso F G).inv.app a z) = z.2 := congr_fun (congr_app (binaryProductIso_inv_comp_snd F G) a) z variable {F G} /-- Construct an element of `(F ⨯ G).obj a` from an element of `F.obj a` and an element of `G.obj a`. -/ noncomputable def prodMk {a : C} (x : F.obj a) (y : G.obj a) : (F ⨯ G).obj a := ((binaryProductIso F G).inv).app a ⟨x, y⟩ @[simp] lemma prodMk_fst {a : C} (x : F.obj a) (y : G.obj a) : (Limits.prod.fst (X := F)).app a (prodMk x y) = x := by simp only [prodMk, binaryProductIso_inv_comp_fst_apply] @[simp] lemma prodMk_snd {a : C} (x : F.obj a) (y : G.obj a) : (Limits.prod.snd (X := F)).app a (prodMk x y) = y := by simp only [prodMk, binaryProductIso_inv_comp_snd_apply] @[ext] lemma prod_ext {a : C} (z w : (prod F G).obj a) (h1 : z.1 = w.1) (h2 : z.2 = w.2) : z = w := Prod.ext h1 h2 variable (F G) /-- `(F ⨯ G).obj a` is in bijection with the product of `F.obj a` and `G.obj a`. -/ @[simps] noncomputable def binaryProductEquiv (a : C) : (F ⨯ G).obj a ≃ (F.obj a) × (G.obj a) where toFun z := ⟨((binaryProductIso F G).hom.app a z).1, ((binaryProductIso F G).hom.app a z).2⟩ invFun z := prodMk z.1 z.2 left_inv _ := by simp [prodMk] right_inv _ := by simp [prodMk] @[ext] lemma prod_ext' (a : C) (z w : (F ⨯ G).obj a) (h1 : (Limits.prod.fst (X := F)).app a z = (Limits.prod.fst (X := F)).app a w) (h2 : (Limits.prod.snd (X := F)).app a z = (Limits.prod.snd (X := F)).app a w) : z = w := by apply Equiv.injective (binaryProductEquiv F G a) aesop end prod section coprod /-- `coprod F G` is the explicit binary coproduct of type-valued functors `F` and `G`. -/ def coprod : C ⥤ Type w where obj a := F.obj a ⊕ G.obj a map f x := by cases x with | inl x => exact .inl (F.map f x) | inr x => exact .inr (G.map f x) variable {F G} /-- The left inclusion of `F` into `coprod F G`. -/ @[simps] def coprod.inl : F ⟶ coprod F G where app _ x := .inl x /-- The right inclusion of `G` into `coprod F G`. -/ @[simps] def coprod.inr : G ⟶ coprod F G where app _ x := .inr x /-- Given natural transformations `F₁ ⟶ F` and `F₂ ⟶ F`, construct a natural transformation `coprod F₁ F₂ ⟶ F`. -/ @[simps] def coprod.desc {F₁ F₂ : C ⥤ Type w} (τ₁ : F₁ ⟶ F) (τ₂ : F₂ ⟶ F) : coprod F₁ F₂ ⟶ F where app a x := by cases x with | inl x => exact τ₁.app a x | inr x => exact τ₂.app a x naturality _ _ _ := by ext x cases x with | _ => simp only [coprod, types_comp_apply, FunctorToTypes.naturality] @[simp] lemma coprod.desc_inl {F₁ F₂ : C ⥤ Type w} (τ₁ : F₁ ⟶ F) (τ₂ : F₂ ⟶ F) : coprod.inl ≫ coprod.desc τ₁ τ₂ = τ₁ := rfl @[simp] lemma coprod.desc_inr {F₁ F₂ : C ⥤ Type w} (τ₁ : F₁ ⟶ F) (τ₂ : F₂ ⟶ F) : coprod.inr ≫ coprod.desc τ₁ τ₂ = τ₂ := rfl variable (F G) /-- The binary cofan whose point is `coprod F G`. -/ @[simps!] def binaryCoproductCocone : BinaryCofan F G := BinaryCofan.mk coprod.inl coprod.inr /-- `coprod F G` is a colimit cocone. -/ @[simps] def binaryCoproductColimit : IsColimit (binaryCoproductCocone F G) where desc (s : BinaryCofan F G) := coprod.desc s.inl s.inr fac _ := fun ⟨j⟩ ↦ WalkingPair.casesOn j rfl rfl uniq _ _ h := by ext _ x cases x with | _ => simp [← h ⟨WalkingPair.right⟩, ← h ⟨WalkingPair.left⟩] /-- `coprod F G` is a binary coproduct for `F` and `G`. -/ def binaryCoproductColimitCocone : Limits.ColimitCocone (pair F G) := ⟨_, binaryCoproductColimit F G⟩ /-- The categorical binary coproduct of type-valued functors is `coprod F G`. -/ noncomputable def binaryCoproductIso : F ⨿ G ≅ coprod F G := colimit.isoColimitCocone (binaryCoproductColimitCocone F G) @[simp] lemma inl_comp_binaryCoproductIso_hom : Limits.coprod.inl ≫ (binaryCoproductIso F G).hom = coprod.inl := by simp only [binaryCoproductIso] aesop @[simp] lemma inl_comp_binaryCoproductIso_hom_apply (a : C) (x : F.obj a) : (binaryCoproductIso F G).hom.app a ((Limits.coprod.inl (X := F)).app a x) = .inl x := congr_fun (congr_app (inl_comp_binaryCoproductIso_hom F G) a) x @[simp] lemma inr_comp_binaryCoproductIso_hom : Limits.coprod.inr ≫ (binaryCoproductIso F G).hom = coprod.inr := by simp [binaryCoproductIso] aesop @[simp] lemma inr_comp_binaryCoproductIso_hom_apply (a : C) (x : G.obj a) : (binaryCoproductIso F G).hom.app a ((Limits.coprod.inr (X := F)).app a x) = .inr x := congr_fun (congr_app (inr_comp_binaryCoproductIso_hom F G) a) x @[simp] lemma inl_comp_binaryCoproductIso_inv : coprod.inl ≫ (binaryCoproductIso F G).inv = (Limits.coprod.inl (X := F)) := rfl @[simp] lemma inl_comp_binaryCoproductIso_inv_apply (a : C) (x : F.obj a) : (binaryCoproductIso F G).inv.app a (.inl x) = (Limits.coprod.inl (X := F)).app a x := rfl @[simp] lemma inr_comp_binaryCoproductIso_inv : coprod.inr ≫ (binaryCoproductIso F G).inv = (Limits.coprod.inr (X := F)) := rfl @[simp] lemma inr_comp_binaryCoproductIso_inv_apply (a : C) (x : G.obj a) : (binaryCoproductIso F G).inv.app a (.inr x) = (Limits.coprod.inr (X := F)).app a x := rfl variable {F G} /-- Construct an element of `(F ⨿ G).obj a` from an element of `F.obj a` -/ noncomputable abbrev coprodInl {a : C} (x : F.obj a) : (F ⨿ G).obj a := (binaryCoproductIso F G).inv.app a (.inl x) /-- Construct an element of `(F ⨿ G).obj a` from an element of `G.obj a` -/ noncomputable abbrev coprodInr {a : C} (x : G.obj a) : (F ⨿ G).obj a := (binaryCoproductIso F G).inv.app a (.inr x) variable (F G) /-- `(F ⨿ G).obj a` is in bijection with disjoint union of `F.obj a` and `G.obj a`. -/ @[simps] noncomputable def binaryCoproductEquiv (a : C) : (F ⨿ G).obj a ≃ (F.obj a) ⊕ (G.obj a) where toFun z := (binaryCoproductIso F G).hom.app a z invFun z := (binaryCoproductIso F G).inv.app a z left_inv _ := by simp only [hom_inv_id_app_apply] right_inv _ := by simp only [inv_hom_id_app_apply] end coprod end CategoryTheory.FunctorToTypes
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/IsTerminal.lean
import Mathlib.CategoryTheory.PEmpty import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Category.Preorder /-! # Initial and terminal objects in a category. In this file we define the predicates `IsTerminal` and `IsInitial` as well as the class `InitialMonoClass`. The classes `HasTerminal` and `HasInitial` and the associated notations for terminal and initial objects are defined in `Terminal.lean`. ## References * [Stacks: Initial and final objects](https://stacks.math.columbia.edu/tag/002B) -/ assert_not_exists CategoryTheory.Limits.HasLimit noncomputable section universe w w' v v₁ v₂ u u₁ u₂ open CategoryTheory namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] /-- Construct a cone for the empty diagram given an object. -/ @[simps] def asEmptyCone (X : C) : Cone (Functor.empty.{0} C) := { pt := X π := { app := by cat_disch } } /-- Construct a cocone for the empty diagram given an object. -/ @[simps] def asEmptyCocone (X : C) : Cocone (Functor.empty.{0} C) := { pt := X ι := { app := by cat_disch } } /-- `X` is terminal if the cone it induces on the empty diagram is limiting. -/ abbrev IsTerminal (X : C) := IsLimit (asEmptyCone X) /-- `X` is initial if the cocone it induces on the empty diagram is colimiting. -/ abbrev IsInitial (X : C) := IsColimit (asEmptyCocone X) /-- An object `Y` is terminal iff for every `X` there is a unique morphism `X ⟶ Y`. -/ def isTerminalEquivUnique (F : Discrete.{0} PEmpty.{1} ⥤ C) (Y : C) : IsLimit (⟨Y, by cat_disch, by simp⟩ : Cone F) ≃ ∀ X : C, Unique (X ⟶ Y) where toFun t X := { default := t.lift ⟨X, ⟨by cat_disch, by simp⟩⟩ uniq := fun f => t.uniq ⟨X, ⟨by cat_disch, by simp⟩⟩ f (by simp) } invFun u := { lift := fun s => (u s.pt).default uniq := fun s _ _ => (u s.pt).2 _ } left_inv := by dsimp [Function.LeftInverse]; intro x; simp only [eq_iff_true_of_subsingleton] right_inv := by dsimp [Function.RightInverse,Function.LeftInverse] subsingleton /-- An object `Y` is terminal if for every `X` there is a unique morphism `X ⟶ Y` (as an instance). -/ def IsTerminal.ofUnique (Y : C) [h : ∀ X : C, Unique (X ⟶ Y)] : IsTerminal Y where lift s := (h s.pt).default fac := fun _ ⟨j⟩ => j.elim /-- An object `Y` is terminal if for every `X` there is a unique morphism `X ⟶ Y` (as explicit arguments). -/ def IsTerminal.ofUniqueHom {Y : C} (h : ∀ X : C, X ⟶ Y) (uniq : ∀ (X : C) (m : X ⟶ Y), m = h X) : IsTerminal Y := have : ∀ X : C, Unique (X ⟶ Y) := fun X ↦ ⟨⟨h X⟩, uniq X⟩ IsTerminal.ofUnique Y /-- If `α` is a preorder with top, then `⊤` is a terminal object. -/ def isTerminalTop {α : Type*} [Preorder α] [OrderTop α] : IsTerminal (⊤ : α) := IsTerminal.ofUnique _ /-- Transport a term of type `IsTerminal` across an isomorphism. -/ def IsTerminal.ofIso {Y Z : C} (hY : IsTerminal Y) (i : Y ≅ Z) : IsTerminal Z := IsLimit.ofIsoLimit hY { hom := { hom := i.hom } inv := { hom := i.inv } } /-- If `X` and `Y` are isomorphic, then `X` is terminal iff `Y` is. -/ def IsTerminal.equivOfIso {X Y : C} (e : X ≅ Y) : IsTerminal X ≃ IsTerminal Y where toFun h := IsTerminal.ofIso h e invFun h := IsTerminal.ofIso h e.symm left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- An object `X` is initial iff for every `Y` there is a unique morphism `X ⟶ Y`. -/ def isInitialEquivUnique (F : Discrete.{0} PEmpty.{1} ⥤ C) (X : C) : IsColimit (⟨X, ⟨by cat_disch, by simp⟩⟩ : Cocone F) ≃ ∀ Y : C, Unique (X ⟶ Y) where toFun t X := { default := t.desc ⟨X, ⟨by cat_disch, by simp⟩⟩ uniq := fun f => t.uniq ⟨X, ⟨by cat_disch, by simp⟩⟩ f (by simp) } invFun u := { desc := fun s => (u s.pt).default uniq := fun s _ _ => (u s.pt).2 _ } left_inv := by dsimp [Function.LeftInverse]; intro; simp only [eq_iff_true_of_subsingleton] right_inv := by #adaptation_note /-- 19-07-2025 grind stopped working -/ intro x; dsimp /-- An object `X` is initial if for every `Y` there is a unique morphism `X ⟶ Y` (as an instance). -/ def IsInitial.ofUnique (X : C) [h : ∀ Y : C, Unique (X ⟶ Y)] : IsInitial X where desc s := (h s.pt).default fac := fun _ ⟨j⟩ => j.elim /-- An object `X` is initial if for every `Y` there is a unique morphism `X ⟶ Y` (as explicit arguments). -/ def IsInitial.ofUniqueHom {X : C} (h : ∀ Y : C, X ⟶ Y) (uniq : ∀ (Y : C) (m : X ⟶ Y), m = h Y) : IsInitial X := have : ∀ Y : C, Unique (X ⟶ Y) := fun Y ↦ ⟨⟨h Y⟩, uniq Y⟩ IsInitial.ofUnique X /-- If `α` is a preorder with bot, then `⊥` is an initial object. -/ def isInitialBot {α : Type*} [Preorder α] [OrderBot α] : IsInitial (⊥ : α) := IsInitial.ofUnique _ /-- Transport a term of type `is_initial` across an isomorphism. -/ def IsInitial.ofIso {X Y : C} (hX : IsInitial X) (i : X ≅ Y) : IsInitial Y := IsColimit.ofIsoColimit hX { hom := { hom := i.hom } inv := { hom := i.inv } } /-- If `X` and `Y` are isomorphic, then `X` is initial iff `Y` is. -/ def IsInitial.equivOfIso {X Y : C} (e : X ≅ Y) : IsInitial X ≃ IsInitial Y where toFun h := IsInitial.ofIso h e invFun h := IsInitial.ofIso h e.symm left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- Give the morphism to a terminal object from any other. -/ def IsTerminal.from {X : C} (t : IsTerminal X) (Y : C) : Y ⟶ X := t.lift (asEmptyCone Y) /-- Any two morphisms to a terminal object are equal. -/ theorem IsTerminal.hom_ext {X Y : C} (t : IsTerminal X) (f g : Y ⟶ X) : f = g := IsLimit.hom_ext t (by simp) @[simp] theorem IsTerminal.comp_from {Z : C} (t : IsTerminal Z) {X Y : C} (f : X ⟶ Y) : f ≫ t.from Y = t.from X := t.hom_ext _ _ @[simp] theorem IsTerminal.from_self {X : C} (t : IsTerminal X) : t.from X = 𝟙 X := t.hom_ext _ _ /-- Give the morphism from an initial object to any other. -/ def IsInitial.to {X : C} (t : IsInitial X) (Y : C) : X ⟶ Y := t.desc (asEmptyCocone Y) /-- Any two morphisms from an initial object are equal. -/ theorem IsInitial.hom_ext {X Y : C} (t : IsInitial X) (f g : X ⟶ Y) : f = g := IsColimit.hom_ext t (by simp) @[simp] theorem IsInitial.to_comp {X : C} (t : IsInitial X) {Y Z : C} (f : Y ⟶ Z) : t.to Y ≫ f = t.to Z := t.hom_ext _ _ @[simp] theorem IsInitial.to_self {X : C} (t : IsInitial X) : t.to X = 𝟙 X := t.hom_ext _ _ /-- Any morphism from a terminal object is split mono. -/ theorem IsTerminal.isSplitMono_from {X Y : C} (t : IsTerminal X) (f : X ⟶ Y) : IsSplitMono f := IsSplitMono.mk' ⟨t.from _, t.hom_ext _ _⟩ /-- Any morphism to an initial object is split epi. -/ theorem IsInitial.isSplitEpi_to {X Y : C} (t : IsInitial X) (f : Y ⟶ X) : IsSplitEpi f := IsSplitEpi.mk' ⟨t.to _, t.hom_ext _ _⟩ /-- Any morphism from a terminal object is mono. -/ theorem IsTerminal.mono_from {X Y : C} (t : IsTerminal X) (f : X ⟶ Y) : Mono f := by haveI := t.isSplitMono_from f; infer_instance /-- Any morphism to an initial object is epi. -/ theorem IsInitial.epi_to {X Y : C} (t : IsInitial X) (f : Y ⟶ X) : Epi f := by haveI := t.isSplitEpi_to f; infer_instance /-- If `T` and `T'` are terminal, they are isomorphic. -/ @[simps] def IsTerminal.uniqueUpToIso {T T' : C} (hT : IsTerminal T) (hT' : IsTerminal T') : T ≅ T' where hom := hT'.from _ inv := hT.from _ /-- If `I` and `I'` are initial, they are isomorphic. -/ @[simps] def IsInitial.uniqueUpToIso {I I' : C} (hI : IsInitial I) (hI' : IsInitial I') : I ≅ I' where hom := hI.to _ inv := hI'.to _ variable (C) section Univ variable (X : C) {F₁ : Discrete.{w} PEmpty ⥤ C} {F₂ : Discrete.{w'} PEmpty ⥤ C} /-- Being terminal is independent of the empty diagram, its universe, and the cone over it, as long as the cone points are isomorphic. -/ def isLimitChangeEmptyCone {c₁ : Cone F₁} (hl : IsLimit c₁) (c₂ : Cone F₂) (hi : c₁.pt ≅ c₂.pt) : IsLimit c₂ where lift c := hl.lift ⟨c.pt, by cat_disch, by simp⟩ ≫ hi.hom uniq c f _ := by dsimp rw [← hl.uniq _ (f ≫ hi.inv) _] · simp only [Category.assoc, Iso.inv_hom_id, Category.comp_id] · simp /-- Replacing an empty cone in `IsLimit` by another with the same cone point is an equivalence. -/ def isLimitEmptyConeEquiv (c₁ : Cone F₁) (c₂ : Cone F₂) (h : c₁.pt ≅ c₂.pt) : IsLimit c₁ ≃ IsLimit c₂ where toFun hl := isLimitChangeEmptyCone C hl c₂ h invFun hl := isLimitChangeEmptyCone C hl c₁ h.symm left_inv := by dsimp [Function.LeftInverse]; intro; simp only [eq_iff_true_of_subsingleton] right_inv := by dsimp [Function.LeftInverse,Function.RightInverse]; intro simp only [eq_iff_true_of_subsingleton] /-- If `F` is an empty diagram, then a cone over `F` is limiting iff the cone point is terminal. -/ noncomputable def isLimitEquivIsTerminalOfIsEmpty {J : Type*} [Category J] [IsEmpty J] {F : J ⥤ C} (c : Cone F) : IsLimit c ≃ IsTerminal c.pt := (IsLimit.whiskerEquivalenceEquiv (equivalenceOfIsEmpty (Discrete PEmpty.{1}) _)).trans (isLimitEmptyConeEquiv _ _ _ (.refl _)) /-- Being initial is independent of the empty diagram, its universe, and the cocone over it, as long as the cocone points are isomorphic. -/ def isColimitChangeEmptyCocone {c₁ : Cocone F₁} (hl : IsColimit c₁) (c₂ : Cocone F₂) (hi : c₁.pt ≅ c₂.pt) : IsColimit c₂ where desc c := hi.inv ≫ hl.desc ⟨c.pt, by cat_disch, by simp⟩ uniq c f _ := by dsimp rw [← hl.uniq _ (hi.hom ≫ f) _] · simp only [Iso.inv_hom_id_assoc] · simp /-- Replacing an empty cocone in `IsColimit` by another with the same cocone point is an equivalence. -/ def isColimitEmptyCoconeEquiv (c₁ : Cocone F₁) (c₂ : Cocone F₂) (h : c₁.pt ≅ c₂.pt) : IsColimit c₁ ≃ IsColimit c₂ where toFun hl := isColimitChangeEmptyCocone C hl c₂ h invFun hl := isColimitChangeEmptyCocone C hl c₁ h.symm left_inv := by dsimp [Function.LeftInverse]; intro; simp only [eq_iff_true_of_subsingleton] right_inv := by dsimp [Function.LeftInverse,Function.RightInverse]; intro simp only [eq_iff_true_of_subsingleton] /-- If `F` is an empty diagram, then a cocone over `F` is colimiting iff the cocone point is initial. -/ noncomputable def isColimitEquivIsInitialOfIsEmpty {J : Type*} [Category J] [IsEmpty J] {F : J ⥤ C} (c : Cocone F) : IsColimit c ≃ IsInitial c.pt := (IsColimit.whiskerEquivalenceEquiv (equivalenceOfIsEmpty (Discrete PEmpty.{1}) _)).trans (isColimitEmptyCoconeEquiv _ _ _ (.refl _)) end Univ section variable {C} /-- An initial object is terminal in the opposite category. -/ def terminalOpOfInitial {X : C} (t : IsInitial X) : IsTerminal (Opposite.op X) where lift s := (t.to s.pt.unop).op uniq _ _ _ := Quiver.Hom.unop_inj (t.hom_ext _ _) /-- An initial object in the opposite category is terminal in the original category. -/ def terminalUnopOfInitial {X : Cᵒᵖ} (t : IsInitial X) : IsTerminal X.unop where lift s := (t.to (Opposite.op s.pt)).unop uniq _ _ _ := Quiver.Hom.op_inj (t.hom_ext _ _) /-- A terminal object is initial in the opposite category. -/ def initialOpOfTerminal {X : C} (t : IsTerminal X) : IsInitial (Opposite.op X) where desc s := (t.from s.pt.unop).op uniq _ _ _ := Quiver.Hom.unop_inj (t.hom_ext _ _) /-- A terminal object in the opposite category is initial in the original category. -/ def initialUnopOfTerminal {X : Cᵒᵖ} (t : IsTerminal X) : IsInitial X.unop where desc s := (t.from (Opposite.op s.pt)).unop uniq _ _ _ := Quiver.Hom.op_inj (t.hom_ext _ _) /-- A category is an `InitialMonoClass` if the canonical morphism of an initial object is a monomorphism. In practice, this is most useful when given an arbitrary morphism out of the chosen initial object, see `initial.mono_from`. Given a terminal object, this is equivalent to the assumption that the unique morphism from initial to terminal is a monomorphism, which is the second of Freyd's axioms for an AT category. TODO: This is a condition satisfied by categories with zero objects and morphisms. -/ class InitialMonoClass (C : Type u₁) [Category.{v₁} C] : Prop where /-- The map from the (any as stated) initial object to any other object is a monomorphism -/ isInitial_mono_from : ∀ {I} (X : C) (hI : IsInitial I), Mono (hI.to X) theorem IsInitial.mono_from [InitialMonoClass C] {I} {X : C} (hI : IsInitial I) (f : I ⟶ X) : Mono f := by rw [hI.hom_ext f (hI.to X)] apply InitialMonoClass.isInitial_mono_from /-- To show a category is an `InitialMonoClass` it suffices to give an initial object such that every morphism out of it is a monomorphism. -/ theorem InitialMonoClass.of_isInitial {I : C} (hI : IsInitial I) (h : ∀ X, Mono (hI.to X)) : InitialMonoClass C where isInitial_mono_from {I'} X hI' := by rw [hI'.hom_ext (hI'.to X) ((hI'.uniqueUpToIso hI).hom ≫ hI.to X)] apply mono_comp /-- To show a category is an `InitialMonoClass` it suffices to show the unique morphism from an initial object to a terminal object is a monomorphism. -/ theorem InitialMonoClass.of_isTerminal {I T : C} (hI : IsInitial I) (hT : IsTerminal T) (_ : Mono (hI.to T)) : InitialMonoClass C := InitialMonoClass.of_isInitial hI fun X => mono_of_mono_fac (hI.hom_ext (_ ≫ hT.from X) (hI.to T)) section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) end Comparison variable {J : Type u} [Category.{v} J] /-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cone for `J`. In `limitOfDiagramInitial` we show it is a limit cone. -/ @[simps] def coneOfDiagramInitial {X : J} (tX : IsInitial X) (F : J ⥤ C) : Cone F where pt := F.obj X π := { app := fun j => F.map (tX.to j) naturality := fun j j' k => by dsimp rw [← F.map_comp, Category.id_comp, tX.hom_ext (tX.to j ≫ k) (tX.to j')] } /-- From a functor `F : J ⥤ C`, given an initial object of `J`, show the cone `coneOfDiagramInitial` is a limit. -/ def limitOfDiagramInitial {X : J} (tX : IsInitial X) (F : J ⥤ C) : IsLimit (coneOfDiagramInitial tX F) where lift s := s.π.app X uniq s m w := by conv_lhs => dsimp simp_rw [← w X, coneOfDiagramInitial_π_app, tX.hom_ext (tX.to X) (𝟙 _)] simp /-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cone for `J`, provided that the morphisms in the diagram are isomorphisms. In `limitOfDiagramTerminal` we show it is a limit cone. -/ @[simps] def coneOfDiagramTerminal {X : J} (hX : IsTerminal X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : Cone F where pt := F.obj X π := { app := fun _ => inv (F.map (hX.from _)) naturality := by intro i j f dsimp simp only [IsIso.eq_inv_comp, IsIso.comp_inv_eq, Category.id_comp, ← F.map_comp, hX.hom_ext (hX.from i) (f ≫ hX.from j)] } /-- From a functor `F : J ⥤ C`, given a terminal object of `J` and that the morphisms in the diagram are isomorphisms, show the cone `coneOfDiagramTerminal` is a limit. -/ def limitOfDiagramTerminal {X : J} (hX : IsTerminal X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsLimit (coneOfDiagramTerminal hX F) where lift S := S.π.app _ /-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cocone for `J`. In `colimitOfDiagramTerminal` we show it is a colimit cocone. -/ @[simps] def coconeOfDiagramTerminal {X : J} (tX : IsTerminal X) (F : J ⥤ C) : Cocone F where pt := F.obj X ι := { app := fun j => F.map (tX.from j) naturality := fun j j' k => by dsimp rw [← F.map_comp, Category.comp_id, tX.hom_ext (k ≫ tX.from j') (tX.from j)] } /-- From a functor `F : J ⥤ C`, given a terminal object of `J`, show the cocone `coconeOfDiagramTerminal` is a colimit. -/ def colimitOfDiagramTerminal {X : J} (tX : IsTerminal X) (F : J ⥤ C) : IsColimit (coconeOfDiagramTerminal tX F) where desc s := s.ι.app X uniq s m w := by simp [← w X] lemma IsColimit.isIso_ι_app_of_isTerminal {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (X : J) (hX : IsTerminal X) : IsIso (c.ι.app X) := by change IsIso (coconePointUniqueUpToIso (colimitOfDiagramTerminal hX F) hc).hom infer_instance /-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cocone for `J`, provided that the morphisms in the diagram are isomorphisms. In `colimitOfDiagramInitial` we show it is a colimit cocone. -/ @[simps] def coconeOfDiagramInitial {X : J} (hX : IsInitial X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : Cocone F where pt := F.obj X ι := { app := fun _ => inv (F.map (hX.to _)) naturality := by intro i j f dsimp simp only [IsIso.eq_inv_comp, IsIso.comp_inv_eq, Category.comp_id, ← F.map_comp, hX.hom_ext (hX.to i ≫ f) (hX.to j)] } /-- From a functor `F : J ⥤ C`, given an initial object of `J` and that the morphisms in the diagram are isomorphisms, show the cone `coconeOfDiagramInitial` is a colimit. -/ def colimitOfDiagramInitial {X : J} (hX : IsInitial X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsColimit (coconeOfDiagramInitial hX F) where desc S := S.ι.app _ lemma IsLimit.isIso_π_app_of_isInitial {F : J ⥤ C} {c : Cone F} (hc : IsLimit c) (X : J) (hX : IsInitial X) : IsIso (c.π.app X) := by change IsIso (conePointUniqueUpToIso hc (limitOfDiagramInitial hX F)).hom infer_instance /-- Any morphism between terminal objects is an isomorphism. -/ lemma isIso_of_isTerminal {X Y : C} (hX : IsTerminal X) (hY : IsTerminal Y) (f : X ⟶ Y) : IsIso f := by refine ⟨⟨IsTerminal.from hX Y, ?_⟩⟩ simp only [IsTerminal.comp_from, IsTerminal.from_self, true_and] apply IsTerminal.hom_ext hY /-- Any morphism between initial objects is an isomorphism. -/ lemma isIso_of_isInitial {X Y : C} (hX : IsInitial X) (hY : IsInitial Y) (f : X ⟶ Y) : IsIso f := by refine ⟨⟨IsInitial.to hY X, ?_⟩⟩ simp only [IsInitial.to_comp, IsInitial.to_self, and_true] apply IsInitial.hom_ext hX end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/StrictInitial.lean
import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # Strict initial objects This file sets up the basic theory of strict initial objects: initial objects where every morphism to it is an isomorphism. This generalises a property of the empty set in the category of sets: namely that the only function to the empty set is from itself. We say `C` has strict initial objects if every initial object is strict, i.e. given any morphism `f : A ⟶ I` where `I` is initial, then `f` is an isomorphism. Strictly speaking, this says that *any* initial object must be strict, rather than that strict initial objects exist, which turns out to be a more useful notion to formalise. If the binary product of `X` with a strict initial object exists, it is also initial. To show a category `C` with an initial object has strict initial objects, the most convenient way is to show any morphism to the (chosen) initial object is an isomorphism and use `hasStrictInitialObjects_of_initial_is_strict`. The dual notion (strict terminal objects) occurs much less frequently in practice so is ignored. ## TODO * Construct examples of this: `Type*`, `TopCat`, `Groupoid`, simplicial types, posets. * Construct the bottom element of the subobject lattice given strict initials. * Show Cartesian closed categories have strict initials ## References * https://ncatlab.org/nlab/show/strict+initial+object -/ universe v u namespace CategoryTheory namespace Limits open Category variable (C : Type u) [Category.{v} C] section StrictInitial /-- We say `C` has strict initial objects if every initial object is strict, i.e. given any morphism `f : A ⟶ I` where `I` is initial, then `f` is an isomorphism. Strictly speaking, this says that *any* initial object must be strict, rather than that strict initial objects exist. -/ class HasStrictInitialObjects : Prop where out : ∀ {I A : C} (f : A ⟶ I), IsInitial I → IsIso f variable {C} section variable [HasStrictInitialObjects C] {I : C} theorem IsInitial.isIso_to (hI : IsInitial I) {A : C} (f : A ⟶ I) : IsIso f := HasStrictInitialObjects.out f hI theorem IsInitial.strict_hom_ext (hI : IsInitial I) {A : C} (f g : A ⟶ I) : f = g := by haveI := hI.isIso_to f haveI := hI.isIso_to g exact eq_of_inv_eq_inv (hI.hom_ext (inv f) (inv g)) theorem IsInitial.subsingleton_to (hI : IsInitial I) {A : C} : Subsingleton (A ⟶ I) := ⟨hI.strict_hom_ext⟩ /-- If `X ⟶ Y` with `Y` being a strict initial object, then `X` is also an initial object. -/ noncomputable def IsInitial.ofStrict {X Y : C} (f : X ⟶ Y) (hY : IsInitial Y) : IsInitial X := letI := hY.isIso_to f hY.ofIso (asIso f).symm instance (priority := 100) initial_mono_of_strict_initial_objects : InitialMonoClass C where isInitial_mono_from := fun _ hI => { right_cancellation := fun _ _ _ => hI.strict_hom_ext _ _ } /-- If `I` is initial, then `X ⨯ I` is isomorphic to it. -/ @[simps! hom] noncomputable def mulIsInitial (X : C) [HasBinaryProduct X I] (hI : IsInitial I) : X ⨯ I ≅ I := by have := hI.isIso_to (prod.snd : X ⨯ I ⟶ I) exact asIso prod.snd @[simp] theorem mulIsInitial_inv (X : C) [HasBinaryProduct X I] (hI : IsInitial I) : (mulIsInitial X hI).inv = hI.to _ := hI.hom_ext _ _ /-- If `I` is initial, then `I ⨯ X` is isomorphic to it. -/ @[simps! hom] noncomputable def isInitialMul (X : C) [HasBinaryProduct I X] (hI : IsInitial I) : I ⨯ X ≅ I := by have := hI.isIso_to (prod.fst : I ⨯ X ⟶ I) exact asIso prod.fst @[simp] theorem isInitialMul_inv (X : C) [HasBinaryProduct I X] (hI : IsInitial I) : (isInitialMul X hI).inv = hI.to _ := hI.hom_ext _ _ variable [HasInitial C] instance initial_isIso_to {A : C} (f : A ⟶ ⊥_ C) : IsIso f := initialIsInitial.isIso_to _ @[ext] theorem initial.strict_hom_ext {A : C} (f g : A ⟶ ⊥_ C) : f = g := initialIsInitial.strict_hom_ext _ _ theorem initial.subsingleton_to {A : C} : Subsingleton (A ⟶ ⊥_ C) := initialIsInitial.subsingleton_to /-- The product of `X` with an initial object in a category with strict initial objects is itself initial. This is the generalisation of the fact that `X × Empty ≃ Empty` for types (or `n * 0 = 0`). -/ @[simps! hom] noncomputable def mulInitial (X : C) [HasBinaryProduct X (⊥_ C)] : X ⨯ ⊥_ C ≅ ⊥_ C := mulIsInitial _ initialIsInitial @[simp] theorem mulInitial_inv (X : C) [HasBinaryProduct X (⊥_ C)] : (mulInitial X).inv = initial.to _ := Subsingleton.elim _ _ /-- The product of `X` with an initial object in a category with strict initial objects is itself initial. This is the generalisation of the fact that `Empty × X ≃ Empty` for types (or `0 * n = 0`). -/ @[simps! hom] noncomputable def initialMul (X : C) [HasBinaryProduct (⊥_ C) X] : (⊥_ C) ⨯ X ≅ ⊥_ C := isInitialMul _ initialIsInitial @[simp] theorem initialMul_inv (X : C) [HasBinaryProduct (⊥_ C) X] : (initialMul X).inv = initial.to _ := Subsingleton.elim _ _ end /-- If `C` has an initial object such that every morphism *to* it is an isomorphism, then `C` has strict initial objects. -/ theorem hasStrictInitialObjects_of_initial_is_strict [HasInitial C] (h : ∀ (A) (f : A ⟶ ⊥_ C), IsIso f) : HasStrictInitialObjects C := { out := fun {I A} f hI => haveI := h A (f ≫ hI.to _) ⟨⟨hI.to _ ≫ inv (f ≫ hI.to (⊥_ C)), by rw [← assoc, IsIso.hom_inv_id], hI.hom_ext _ _⟩⟩ } end StrictInitial section StrictTerminal /-- We say `C` has strict terminal objects if every terminal object is strict, i.e. given any morphism `f : I ⟶ A` where `I` is terminal, then `f` is an isomorphism. Strictly speaking, this says that *any* terminal object must be strict, rather than that strict terminal objects exist. -/ class HasStrictTerminalObjects : Prop where out : ∀ {I A : C} (f : I ⟶ A), IsTerminal I → IsIso f variable {C} section variable [HasStrictTerminalObjects C] {I : C} theorem IsTerminal.isIso_from (hI : IsTerminal I) {A : C} (f : I ⟶ A) : IsIso f := HasStrictTerminalObjects.out f hI theorem IsTerminal.strict_hom_ext (hI : IsTerminal I) {A : C} (f g : I ⟶ A) : f = g := by haveI := hI.isIso_from f haveI := hI.isIso_from g exact eq_of_inv_eq_inv (hI.hom_ext (inv f) (inv g)) /-- If `X ⟶ Y` with `Y` being a strict terminal object, then `X` is also an terminal object. -/ noncomputable def IsTerminal.ofStrict {X Y : C} (f : X ⟶ Y) (hY : IsTerminal X) : IsTerminal Y := letI := hY.isIso_from f hY.ofIso (asIso f) theorem IsTerminal.subsingleton_to (hI : IsTerminal I) {A : C} : Subsingleton (I ⟶ A) := ⟨hI.strict_hom_ext⟩ variable {J : Type v} [SmallCategory J] /-- If all but one object in a diagram is strict terminal, then the limit is isomorphic to the said object via `limit.π`. -/ theorem limit_π_isIso_of_is_strict_terminal (F : J ⥤ C) [HasLimit F] (i : J) (H : ∀ (j) (_ : j ≠ i), IsTerminal (F.obj j)) [Subsingleton (i ⟶ i)] : IsIso (limit.π F i) := by classical refine ⟨⟨limit.lift _ ⟨_, ⟨?_, ?_⟩⟩, ?_, ?_⟩⟩ · exact fun j => dite (j = i) (fun h => eqToHom (by cases h; rfl)) fun h => (H _ h).from _ · intro j k f split_ifs with h h_1 h_1 · cases h cases h_1 obtain rfl : f = 𝟙 _ := Subsingleton.elim _ _ simp · cases h haveI : IsIso (F.map f) := (H _ h_1).isIso_from _ rw [← IsIso.comp_inv_eq] apply (H _ h_1).hom_ext · cases h_1 apply (H _ h).hom_ext · apply (H _ h).hom_ext · ext rw [assoc, limit.lift_π] dsimp only split_ifs with h · cases h rw [id_comp, eqToHom_refl] exact comp_id _ · apply (H _ h).hom_ext · simp variable [HasTerminal C] instance terminal_isIso_from {A : C} (f : ⊤_ C ⟶ A) : IsIso f := terminalIsTerminal.isIso_from _ @[ext] theorem terminal.strict_hom_ext {A : C} (f g : ⊤_ C ⟶ A) : f = g := terminalIsTerminal.strict_hom_ext _ _ theorem terminal.subsingleton_to {A : C} : Subsingleton (⊤_ C ⟶ A) := terminalIsTerminal.subsingleton_to end /-- If `C` has an object such that every morphism *from* it is an isomorphism, then `C` has strict terminal objects. -/ theorem hasStrictTerminalObjects_of_terminal_is_strict (I : C) (h : ∀ (A) (f : I ⟶ A), IsIso f) : HasStrictTerminalObjects C := { out := fun {I' A} f hI' => haveI := h A (hI'.from _ ≫ f) ⟨⟨inv (hI'.from I ≫ f) ≫ hI'.from I, hI'.hom_ext _ _, by rw [assoc, IsIso.inv_hom_id]⟩⟩ } end StrictTerminal end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Reflexive.lean
import Mathlib.CategoryTheory.Limits.ConeCategory import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.KernelPair /-! # Reflexive coequalizers This file deals with reflexive pairs, which are pairs of morphisms with a common section. A reflexive coequalizer is a coequalizer of such a pair. These kind of coequalizers often enjoy nicer properties than general coequalizers, and feature heavily in some versions of the monadicity theorem. We also give some examples of reflexive pairs: for an adjunction `F ⊣ G` with counit `ε`, the pair `(FGε_B, ε_FGB)` is reflexive. If a pair `f,g` is a kernel pair for some morphism, then it is reflexive. ## Main definitions * `IsReflexivePair` is the predicate that f and g have a common section. * `WalkingReflexivePair` is the diagram indexing pairs with a common section. * A `reflexiveCofork` is a cocone on a diagram indexed by `WalkingReflexivePair`. * `WalkingReflexivePair.inclusionWalkingReflexivePair` is the inclustion functor from `WalkingParallelPair` to `WalkingReflexivePair`. It acts on reflexive pairs as forgetting the common section. * `HasReflexiveCoequalizers` is the predicate that a category has all colimits of reflexive pairs. * `reflexiveCoequalizerIsoCoequalizer`: an isomorphism promoting the coequalizer of a reflexive pair to the colimit of a diagram out of the walking reflexive pair. ## Main statements * `IsKernelPair.isReflexivePair`: A kernel pair is a reflexive pair * `WalkingParallelPair.inclusionWalkingReflexivePair_final`: The inclusion functor is final. * `hasReflexiveCoequalizers_iff`: A category has coequalizers of reflexive pairs if and only iff it has all colimits of shape `WalkingReflexivePair`. ## TODO * If `C` has binary coproducts and reflexive coequalizers, then it has all coequalizers. * If `T` is a monad on cocomplete category `C`, then `Algebra T` is cocomplete iff it has reflexive coequalizers. * If `C` is locally Cartesian closed and has reflexive coequalizers, then it has images: in fact regular epi (and hence strong epi) images. * Bundle the reflexive pairs of kernel pairs and of adjunction as functors out of the walking reflexive pair. -/ namespace CategoryTheory universe v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {D : Type u₂} [Category.{v₂} D] variable {A B : C} {f g : A ⟶ B} /-- The pair `f g : A ⟶ B` is reflexive if there is a morphism `B ⟶ A` which is a section for both. -/ class IsReflexivePair (f g : A ⟶ B) : Prop where common_section' : ∃ s : B ⟶ A, s ≫ f = 𝟙 B ∧ s ≫ g = 𝟙 B theorem IsReflexivePair.common_section (f g : A ⟶ B) [IsReflexivePair f g] : ∃ s : B ⟶ A, s ≫ f = 𝟙 B ∧ s ≫ g = 𝟙 B := IsReflexivePair.common_section' /-- The pair `f g : A ⟶ B` is coreflexive if there is a morphism `B ⟶ A` which is a retraction for both. -/ class IsCoreflexivePair (f g : A ⟶ B) : Prop where common_retraction' : ∃ s : B ⟶ A, f ≫ s = 𝟙 A ∧ g ≫ s = 𝟙 A theorem IsCoreflexivePair.common_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] : ∃ s : B ⟶ A, f ≫ s = 𝟙 A ∧ g ≫ s = 𝟙 A := IsCoreflexivePair.common_retraction' theorem IsReflexivePair.mk' (s : B ⟶ A) (sf : s ≫ f = 𝟙 B) (sg : s ≫ g = 𝟙 B) : IsReflexivePair f g := ⟨⟨s, sf, sg⟩⟩ theorem IsCoreflexivePair.mk' (s : B ⟶ A) (fs : f ≫ s = 𝟙 A) (gs : g ≫ s = 𝟙 A) : IsCoreflexivePair f g := ⟨⟨s, fs, gs⟩⟩ /-- Get the common section for a reflexive pair. -/ noncomputable def commonSection (f g : A ⟶ B) [IsReflexivePair f g] : B ⟶ A := (IsReflexivePair.common_section f g).choose @[reassoc (attr := simp)] theorem section_comp_left (f g : A ⟶ B) [IsReflexivePair f g] : commonSection f g ≫ f = 𝟙 B := (IsReflexivePair.common_section f g).choose_spec.1 @[reassoc (attr := simp)] theorem section_comp_right (f g : A ⟶ B) [IsReflexivePair f g] : commonSection f g ≫ g = 𝟙 B := (IsReflexivePair.common_section f g).choose_spec.2 /-- Get the common retraction for a coreflexive pair. -/ noncomputable def commonRetraction (f g : A ⟶ B) [IsCoreflexivePair f g] : B ⟶ A := (IsCoreflexivePair.common_retraction f g).choose @[reassoc (attr := simp)] theorem left_comp_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] : f ≫ commonRetraction f g = 𝟙 A := (IsCoreflexivePair.common_retraction f g).choose_spec.1 @[reassoc (attr := simp)] theorem right_comp_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] : g ≫ commonRetraction f g = 𝟙 A := (IsCoreflexivePair.common_retraction f g).choose_spec.2 /-- If `f,g` is a kernel pair for some morphism `q`, then it is reflexive. -/ theorem IsKernelPair.isReflexivePair {R : C} {f g : R ⟶ A} {q : A ⟶ B} (h : IsKernelPair q f g) : IsReflexivePair f g := IsReflexivePair.mk' _ (h.lift' _ _ rfl).2.1 (h.lift' _ _ _).2.2 -- This shouldn't be an instance as it would instantly loop. /-- If `f,g` is reflexive, then `g,f` is reflexive. -/ theorem IsReflexivePair.swap [IsReflexivePair f g] : IsReflexivePair g f := IsReflexivePair.mk' _ (section_comp_right f g) (section_comp_left f g) -- This shouldn't be an instance as it would instantly loop. /-- If `f,g` is coreflexive, then `g,f` is coreflexive. -/ theorem IsCoreflexivePair.swap [IsCoreflexivePair f g] : IsCoreflexivePair g f := IsCoreflexivePair.mk' _ (right_comp_retraction f g) (left_comp_retraction f g) variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) /-- For an adjunction `F ⊣ G` with counit `ε`, the pair `(FGε_B, ε_FGB)` is reflexive. -/ instance (B : D) : IsReflexivePair (F.map (G.map (adj.counit.app B))) (adj.counit.app (F.obj (G.obj B))) := IsReflexivePair.mk' (F.map (adj.unit.app (G.obj B))) (by rw [← F.map_comp, adj.right_triangle_components] apply F.map_id) (adj.left_triangle_components _) namespace Limits variable (C) /-- `C` has reflexive coequalizers if it has coequalizers for every reflexive pair. -/ class HasReflexiveCoequalizers : Prop where has_coeq : ∀ ⦃A B : C⦄ (f g : A ⟶ B) [IsReflexivePair f g], HasCoequalizer f g /-- `C` has coreflexive equalizers if it has equalizers for every coreflexive pair. -/ class HasCoreflexiveEqualizers : Prop where has_eq : ∀ ⦃A B : C⦄ (f g : A ⟶ B) [IsCoreflexivePair f g], HasEqualizer f g attribute [instance 1] HasReflexiveCoequalizers.has_coeq attribute [instance 1] HasCoreflexiveEqualizers.has_eq theorem hasCoequalizer_of_common_section [HasReflexiveCoequalizers C] {A B : C} {f g : A ⟶ B} (r : B ⟶ A) (rf : r ≫ f = 𝟙 _) (rg : r ≫ g = 𝟙 _) : HasCoequalizer f g := by letI := IsReflexivePair.mk' r rf rg infer_instance theorem hasEqualizer_of_common_retraction [HasCoreflexiveEqualizers C] {A B : C} {f g : A ⟶ B} (r : B ⟶ A) (fr : f ≫ r = 𝟙 _) (gr : g ≫ r = 𝟙 _) : HasEqualizer f g := by letI := IsCoreflexivePair.mk' r fr gr infer_instance /-- If `C` has coequalizers, then it has reflexive coequalizers. -/ instance (priority := 100) hasReflexiveCoequalizers_of_hasCoequalizers [HasCoequalizers C] : HasReflexiveCoequalizers C where has_coeq A B f g _ := by infer_instance /-- If `C` has equalizers, then it has coreflexive equalizers. -/ instance (priority := 100) hasCoreflexiveEqualizers_of_hasEqualizers [HasEqualizers C] : HasCoreflexiveEqualizers C where has_eq A B f g _ := by infer_instance end Limits end CategoryTheory namespace CategoryTheory universe v v₂ u u₂ namespace Limits /-- The type of objects for the diagram indexing reflexive (co)equalizers -/ inductive WalkingReflexivePair : Type where | zero | one deriving DecidableEq, Inhabited open WalkingReflexivePair namespace WalkingReflexivePair -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type of morphisms for the diagram indexing reflexive (co)equalizers -/ inductive Hom : (WalkingReflexivePair → WalkingReflexivePair → Type) | left : Hom one zero | right : Hom one zero | reflexion : Hom zero one | leftCompReflexion : Hom one one | rightCompReflexion : Hom one one | id (X : WalkingReflexivePair) : Hom X X deriving DecidableEq /-- Composition of morphisms in the diagram indexing reflexive (co)equalizers -/ def Hom.comp : ∀ { X Y Z : WalkingReflexivePair } (_ : Hom X Y) (_ : Hom Y Z), Hom X Z | _, _, _, id _, h => h | _, _, _, h, id _ => h | _, _, _, reflexion, left => id zero | _, _, _, reflexion, right => id zero | _, _, _, reflexion, rightCompReflexion => reflexion | _, _, _, reflexion, leftCompReflexion => reflexion | _, _, _, left, reflexion => leftCompReflexion | _, _, _, right, reflexion => rightCompReflexion | _, _, _, rightCompReflexion, rightCompReflexion => rightCompReflexion | _, _, _, rightCompReflexion, leftCompReflexion => rightCompReflexion | _, _, _, rightCompReflexion, right => right | _, _, _, rightCompReflexion, left => right | _, _, _, leftCompReflexion, left => left | _, _, _, leftCompReflexion, right => left | _, _, _, leftCompReflexion, rightCompReflexion => leftCompReflexion | _, _, _, leftCompReflexion, leftCompReflexion => leftCompReflexion instance category : SmallCategory WalkingReflexivePair where Hom := Hom id := Hom.id comp := Hom.comp comp_id := by intro _ _ f; cases f <;> rfl id_comp := by intro _ _ f; cases f <;> rfl assoc := by intro _ _ _ _ f g h; cases f <;> cases g <;> cases h <;> rfl open Hom @[simp] lemma Hom.id_eq (X : WalkingReflexivePair) : Hom.id X = 𝟙 X := rfl @[reassoc (attr := simp)] lemma reflexion_comp_left : reflexion ≫ left = 𝟙 zero := rfl @[reassoc (attr := simp)] lemma reflexion_comp_right : reflexion ≫ right = 𝟙 zero := rfl @[simp] lemma leftCompReflexion_eq : leftCompReflexion = (left ≫ reflexion : one ⟶ one) := rfl @[simp] lemma rightCompReflexion_eq : rightCompReflexion = (right ≫ reflexion : one ⟶ one) := rfl section FunctorsOutOfWalkingReflexivePair variable {C : Type u} [Category.{v} C] @[reassoc (attr := simp)] lemma map_reflexion_comp_map_left (F : WalkingReflexivePair ⥤ C) : F.map reflexion ≫ F.map left = 𝟙 (F.obj zero) := by rw [← F.map_comp, reflexion_comp_left, F.map_id] @[reassoc (attr := simp)] lemma map_reflexion_comp_map_right (F : WalkingReflexivePair ⥤ C) : F.map reflexion ≫ F.map right = 𝟙 (F.obj zero) := by rw [← F.map_comp, reflexion_comp_right, F.map_id] end FunctorsOutOfWalkingReflexivePair end WalkingReflexivePair namespace WalkingParallelPair /-- The inclusion functor forgetting the common section -/ @[simps!] def inclusionWalkingReflexivePair : WalkingParallelPair ⥤ WalkingReflexivePair where obj := fun x => match x with | one => WalkingReflexivePair.zero | zero => WalkingReflexivePair.one map := fun f => match f with | .left => WalkingReflexivePair.Hom.left | .right => WalkingReflexivePair.Hom.right | .id _ => WalkingReflexivePair.Hom.id _ map_comp := by intro _ _ _ f g; cases f <;> cases g <;> rfl variable {C : Type u} [Category.{v} C] instance (X : WalkingReflexivePair) : Nonempty (StructuredArrow X inclusionWalkingReflexivePair) := by cases X with | zero => exact ⟨StructuredArrow.mk (Y := one) (𝟙 _)⟩ | one => exact ⟨StructuredArrow.mk (Y := zero) (𝟙 _)⟩ open WalkingReflexivePair.Hom in instance (X : WalkingReflexivePair) : IsConnected (StructuredArrow X inclusionWalkingReflexivePair) := by cases X with | zero => refine IsConnected.of_induct (j₀ := StructuredArrow.mk (Y := one) (𝟙 _)) ?_ rintro p h₁ h₂ ⟨⟨⟨⟩⟩, (_ | _), ⟨_⟩⟩ · exact (h₂ (StructuredArrow.homMk .left)).2 h₁ · exact h₁ | one => refine IsConnected.of_induct (j₀ := StructuredArrow.mk (Y := zero) (𝟙 _)) (fun p h₁ h₂ ↦ ?_) have hₗ : StructuredArrow.mk left ∈ p := (h₂ (StructuredArrow.homMk .left)).1 h₁ have hᵣ : StructuredArrow.mk right ∈ p := (h₂ (StructuredArrow.homMk .right)).1 h₁ rintro ⟨⟨⟨⟩⟩, (_ | _), ⟨_⟩⟩ · exact (h₂ (StructuredArrow.homMk .left)).2 hₗ · exact (h₂ (StructuredArrow.homMk .right)).2 hᵣ all_goals assumption /-- The inclusion functor is a final functor -/ instance inclusionWalkingReflexivePair_final : Functor.Final inclusionWalkingReflexivePair where out := inferInstance end WalkingParallelPair end Limits namespace Limits open WalkingReflexivePair variable {C : Type u} [Category.{v} C] variable {A B : C} /-- Bundle the data of a parallel pair along with a common section as a functor out of the walking reflexive pair -/ def reflexivePair (f g : A ⟶ B) (s : B ⟶ A) (sl : s ≫ f = 𝟙 B := by cat_disch) (sr : s ≫ g = 𝟙 B := by cat_disch) : (WalkingReflexivePair ⥤ C) where obj x := match x with | zero => B | one => A map h := match h with | .id _ => 𝟙 _ | .left => f | .right => g | .reflexion => s | .rightCompReflexion => g ≫ s | .leftCompReflexion => f ≫ s map_comp := by rintro _ _ _ ⟨⟩ g <;> cases g <;> simp only [Category.id_comp, Category.comp_id, Category.assoc, sl, sr, reassoc_of% sl, reassoc_of% sr] <;> rfl section variable {A B : C} variable (f g : A ⟶ B) (s : B ⟶ A) {sl : s ≫ f = 𝟙 B} {sr : s ≫ g = 𝟙 B} @[simp] lemma reflexivePair_obj_zero : (reflexivePair f g s sl sr).obj zero = B := rfl @[simp] lemma reflexivePair_obj_one : (reflexivePair f g s sl sr).obj one = A := rfl @[simp] lemma reflexivePair_map_right : (reflexivePair f g s sl sr).map .left = f := rfl @[simp] lemma reflexivePair_map_left : (reflexivePair f g s sl sr).map .right = g := rfl @[simp] lemma reflexivePair_map_reflexion : (reflexivePair f g s sl sr).map .reflexion = s := rfl end /-- (Noncomputably) bundle the data of a reflexive pair as a functor out of the walking reflexive pair -/ noncomputable def ofIsReflexivePair (f g : A ⟶ B) [IsReflexivePair f g] : WalkingReflexivePair ⥤ C := reflexivePair f g (commonSection f g) @[simp] lemma ofIsReflexivePair_map_left (f g : A ⟶ B) [IsReflexivePair f g] : (ofIsReflexivePair f g).map .left = f := rfl @[simp] lemma ofIsReflexivePair_map_right (f g : A ⟶ B) [IsReflexivePair f g] : (ofIsReflexivePair f g).map .right = g := rfl /-- The natural isomorphism between the diagram obtained by forgetting the reflexion of `ofIsReflexivePair f g` and the original parallel pair. -/ noncomputable def inclusionWalkingReflexivePairOfIsReflexivePairIso (f g : A ⟶ B) [IsReflexivePair f g] : WalkingParallelPair.inclusionWalkingReflexivePair ⋙ (ofIsReflexivePair f g) ≅ parallelPair f g := diagramIsoParallelPair _ end Limits namespace Limits variable {C : Type u} [Category.{v} C] namespace reflexivePair open WalkingReflexivePair WalkingReflexivePair.Hom section section NatTrans variable {F G : WalkingReflexivePair ⥤ C} (e₀ : F.obj zero ⟶ G.obj zero) (e₁ : F.obj one ⟶ G.obj one) (h₁ : F.map left ≫ e₀ = e₁ ≫ G.map left := by cat_disch) (h₂ : F.map right ≫ e₀ = e₁ ≫ G.map right := by cat_disch) (h₃ : F.map reflexion ≫ e₁ = e₀ ≫ G.map reflexion := by cat_disch) /-- A constructor for natural transformations between functors from `WalkingReflexivePair`. -/ def mkNatTrans : F ⟶ G where app := fun x ↦ match x with | zero => e₀ | one => e₁ naturality _ _ f := by cases f all_goals dsimp simp only [Functor.map_id, Category.id_comp, Category.comp_id, Functor.map_comp, h₁, h₂, h₃, reassoc_of% h₁, reassoc_of% h₂, Category.assoc] @[simp] lemma mkNatTrans_app_zero : (mkNatTrans e₀ e₁ h₁ h₂ h₃).app zero = e₀ := rfl @[simp] lemma mkNatTrans_app_one : (mkNatTrans e₀ e₁ h₁ h₂ h₃).app one = e₁ := rfl end NatTrans section NatIso variable {F G : WalkingReflexivePair ⥤ C} /-- Constructor for natural isomorphisms between functors out of `WalkingReflexivePair`. -/ @[simps!] def mkNatIso (e₀ : F.obj zero ≅ G.obj zero) (e₁ : F.obj one ≅ G.obj one) (h₁ : F.map left ≫ e₀.hom = e₁.hom ≫ G.map left := by cat_disch) (h₂ : F.map right ≫ e₀.hom = e₁.hom ≫ G.map right := by cat_disch) (h₃ : F.map reflexion ≫ e₁.hom = e₀.hom ≫ G.map reflexion := by cat_disch) : F ≅ G where hom := mkNatTrans e₀.hom e₁.hom inv := mkNatTrans e₀.inv e₁.inv (by rw [← cancel_epi e₁.hom, e₁.hom_inv_id_assoc, ← reassoc_of% h₁, e₀.hom_inv_id, Category.comp_id]) (by rw [← cancel_epi e₁.hom, e₁.hom_inv_id_assoc, ← reassoc_of% h₂, e₀.hom_inv_id, Category.comp_id]) (by rw [← cancel_epi e₀.hom, e₀.hom_inv_id_assoc, ← reassoc_of% h₃, e₁.hom_inv_id, Category.comp_id]) hom_inv_id := by ext x; cases x <;> simp inv_hom_id := by ext x; cases x <;> simp variable (F) /-- Every functor out of `WalkingReflexivePair` is isomorphic to the `reflexivePair` given by its components -/ @[simps!] def diagramIsoReflexivePair : F ≅ reflexivePair (F.map left) (F.map right) (F.map reflexion) := mkNatIso (Iso.refl _) (Iso.refl _) end NatIso /-- A `reflexivePair` composed with a functor is isomorphic to the `reflexivePair` obtained by applying the functor at each map. -/ @[simps!] def compRightIso {D : Type u₂} [Category.{v₂} D] {A B : C} (f g : A ⟶ B) (s : B ⟶ A) (sl : s ≫ f = 𝟙 B) (sr : s ≫ g = 𝟙 B) (F : C ⥤ D) : (reflexivePair f g s sl sr) ⋙ F ≅ reflexivePair (F.map f) (F.map g) (F.map s) (by simp only [← Functor.map_comp, sl, Functor.map_id]) (by simp only [← Functor.map_comp, sr, Functor.map_id]) := mkNatIso (Iso.refl _) (Iso.refl _) lemma whiskerRightMkNatTrans {F G : WalkingReflexivePair ⥤ C} (e₀ : F.obj zero ⟶ G.obj zero) (e₁ : F.obj one ⟶ G.obj one) {h₁ : F.map left ≫ e₀ = e₁ ≫ G.map left} {h₂ : F.map right ≫ e₀ = e₁ ≫ G.map right} {h₃ : F.map reflexion ≫ e₁ = e₀ ≫ G.map reflexion} {D : Type u₂} [Category.{v₂} D] (H : C ⥤ D) : Functor.whiskerRight (mkNatTrans e₀ e₁ : F ⟶ G) H = mkNatTrans (H.map e₀) (H.map e₁) (by simp only [Functor.comp_obj, Functor.comp_map, ← Functor.map_comp, h₁]) (by simp only [Functor.comp_obj, Functor.comp_map, ← Functor.map_comp, h₂]) (by simp only [Functor.comp_obj, Functor.comp_map, ← Functor.map_comp, h₃]) := by ext x; cases x <;> simp end /-- Any functor out of the WalkingReflexivePair yields a reflexive pair -/ instance to_isReflexivePair {F : WalkingReflexivePair ⥤ C} : IsReflexivePair (F.map .left) (F.map .right) := ⟨F.map .reflexion, map_reflexion_comp_map_left F, map_reflexion_comp_map_right F⟩ end reflexivePair /-- A `ReflexiveCofork` is a cocone over a `WalkingReflexivePair`-shaped diagram. -/ abbrev ReflexiveCofork (F : WalkingReflexivePair ⥤ C) := Cocone F namespace ReflexiveCofork open WalkingReflexivePair WalkingReflexivePair.Hom variable {F : WalkingReflexivePair ⥤ C} /-- The tail morphism of a reflexive cofork. -/ abbrev π (G : ReflexiveCofork F) : F.obj zero ⟶ G.pt := G.ι.app zero /-- Constructor for `ReflexiveCofork` -/ @[simps pt] def mk {X : C} (π : F.obj zero ⟶ X) (h : F.map left ≫ π = F.map right ≫ π) : ReflexiveCofork F where pt := X ι := reflexivePair.mkNatTrans π (F.map left ≫ π) @[simp] lemma mk_π {X : C} (π : F.obj zero ⟶ X) (h : F.map left ≫ π = F.map right ≫ π) : (mk π h).π = π := rfl lemma condition (G : ReflexiveCofork F) : F.map left ≫ G.π = F.map right ≫ G.π := by rw [Cocone.w G left, Cocone.w G right] @[simp] lemma app_one_eq_π (G : ReflexiveCofork F) : G.ι.app zero = G.π := rfl /-- The underlying `Cofork` of a `ReflexiveCofork`. -/ abbrev toCofork (G : ReflexiveCofork F) : Cofork (F.map left) (F.map right) := Cofork.ofπ G.π (by simp) end ReflexiveCofork noncomputable section open WalkingReflexivePair WalkingReflexivePair.Hom variable (F : WalkingReflexivePair ⥤ C) /-- Forgetting the reflexion yields an equivalence between cocones over a bundled reflexive pair and coforks on the underlying parallel pair. -/ @[simps! functor_obj_pt inverse_obj_pt] def reflexiveCoforkEquivCofork : ReflexiveCofork F ≌ Cofork (F.map left) (F.map right) := (Functor.Final.coconesEquiv _ F).symm.trans (Cocones.precomposeEquivalence (diagramIsoParallelPair (WalkingParallelPair.inclusionWalkingReflexivePair ⋙ F))).symm @[simp] lemma reflexiveCoforkEquivCofork_functor_obj_π (G : ReflexiveCofork F) : ((reflexiveCoforkEquivCofork F).functor.obj G).π = G.π := by dsimp [reflexiveCoforkEquivCofork] rw [ReflexiveCofork.π, Cofork.π] simp @[simp] lemma reflexiveCoforkEquivCofork_inverse_obj_π (G : Cofork (F.map left) (F.map right)) : ((reflexiveCoforkEquivCofork F).inverse.obj G).π = G.π := by dsimp only [reflexiveCoforkEquivCofork, Equivalence.symm, Equivalence.trans, ReflexiveCofork.π, Cocones.precomposeEquivalence, Cocones.precompose, Functor.comp, Functor.Final.coconesEquiv] rw [Functor.Final.extendCocone_obj_ι_app' (Y := .one) (f := 𝟙 zero)] simp /-- The equivalence between reflexive coforks and coforks sends a reflexive cofork to its underlying cofork. -/ def reflexiveCoforkEquivCoforkObjIso (G : ReflexiveCofork F) : (reflexiveCoforkEquivCofork F).functor.obj G ≅ G.toCofork := Cofork.ext (Iso.refl _) (by simp [reflexiveCoforkEquivCofork, Cofork.π]) lemma hasReflexiveCoequalizer_iff_hasCoequalizer : HasColimit F ↔ HasCoequalizer (F.map left) (F.map right) := by simpa only [hasColimit_iff_hasInitial_cocone] using Equivalence.hasInitial_iff (reflexiveCoforkEquivCofork F) instance reflexivePair_hasColimit_of_hasCoequalizer [h : HasCoequalizer (F.map left) (F.map right)] : HasColimit F := hasReflexiveCoequalizer_iff_hasCoequalizer _|>.mpr h /-- A reflexive cofork is a colimit cocone if and only if the underlying cofork is. -/ def ReflexiveCofork.isColimitEquiv (G : ReflexiveCofork F) : IsColimit (G.toCofork) ≃ IsColimit G := IsColimit.equivIsoColimit (reflexiveCoforkEquivCoforkObjIso F G).symm|>.trans <| (IsColimit.precomposeHomEquiv (diagramIsoParallelPair _).symm (G.whisker _)).trans <| Functor.Final.isColimitWhiskerEquiv _ _ section variable [HasCoequalizer (F.map left) (F.map right)] /-- The colimit of a functor out of the walking reflexive pair is the same as the colimit of the underlying parallel pair. -/ def reflexiveCoequalizerIsoCoequalizer : colimit F ≅ coequalizer (F.map left) (F.map right) := ((ReflexiveCofork.isColimitEquiv _ _).symm (colimit.isColimit F)).coconePointUniqueUpToIso (colimit.isColimit _) @[reassoc (attr := simp)] lemma ι_reflexiveCoequalizerIsoCoequalizer_hom : colimit.ι F zero ≫ (reflexiveCoequalizerIsoCoequalizer F).hom = coequalizer.π (F.map left) (F.map right) := IsColimit.comp_coconePointUniqueUpToIso_hom ((ReflexiveCofork.isColimitEquiv F _).symm _) _ WalkingParallelPair.one @[reassoc (attr := simp)] lemma π_reflexiveCoequalizerIsoCoequalizer_inv : coequalizer.π _ _ ≫ (reflexiveCoequalizerIsoCoequalizer F).inv = colimit.ι F _ := by rw [reflexiveCoequalizerIsoCoequalizer] simp only [colimit.comp_coconePointUniqueUpToIso_inv, Cofork.ofπ_pt, colimit.cocone_x, Cofork.ofπ_ι_app, colimit.cocone_ι] end variable {A B : C} {f g : A ⟶ B} [IsReflexivePair f g] [h : HasCoequalizer f g] instance ofIsReflexivePair_hasColimit_of_hasCoequalizer : HasColimit (ofIsReflexivePair f g) := hasReflexiveCoequalizer_iff_hasCoequalizer _|>.mpr h /-- The coequalizer of a reflexive pair can be promoted to the colimit of a diagram out of the walking reflexive pair -/ def colimitOfIsReflexivePairIsoCoequalizer : colimit (ofIsReflexivePair f g) ≅ coequalizer f g := @reflexiveCoequalizerIsoCoequalizer _ _ (ofIsReflexivePair f g) h @[reassoc (attr := simp)] lemma ι_colimitOfIsReflexivePairIsoCoequalizer_hom : colimit.ι (ofIsReflexivePair f g) zero ≫ colimitOfIsReflexivePairIsoCoequalizer.hom = coequalizer.π f g := @ι_reflexiveCoequalizerIsoCoequalizer_hom _ _ _ h @[reassoc (attr := simp)] lemma π_colimitOfIsReflexivePairIsoCoequalizer_inv : coequalizer.π f g ≫ colimitOfIsReflexivePairIsoCoequalizer.inv = colimit.ι (ofIsReflexivePair f g) zero := @π_reflexiveCoequalizerIsoCoequalizer_inv _ _ (ofIsReflexivePair f g) h end end Limits namespace Limits open WalkingReflexivePair variable {C : Type u} [Category.{v} C] /-- A category has coequalizers of reflexive pairs if and only if it has all colimits indexed by the walking reflexive pair. -/ theorem hasReflexiveCoequalizers_iff : HasColimitsOfShape WalkingReflexivePair C ↔ HasReflexiveCoequalizers C := ⟨fun _ ↦ ⟨fun _ _ f g _ ↦ (hasReflexiveCoequalizer_iff_hasCoequalizer (reflexivePair f g (commonSection f g))).1 inferInstance⟩, fun _ ↦ ⟨inferInstance⟩⟩ end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/SequentialProduct.lean
import Mathlib.CategoryTheory.Functor.OfSequence import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts import Mathlib.CategoryTheory.Limits.Shapes.Countable import Mathlib.CategoryTheory.Limits.Shapes.PiProd import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.Order.Interval.Finset.Nat /-! # ℕ-indexed products as sequential limits Given sequences `M N : ℕ → C` of objects with morphisms `f n : M n ⟶ N n` for all `n`, this file exhibits `∏ M` as the limit of the tower ``` ⋯ → ∏_{n < m + 1} M n × ∏_{n ≥ m + 1} N n → ∏_{n < m} M n × ∏_{n ≥ m} N n → ⋯ → ∏ N ``` Further, we prove that the transition maps in this tower are epimorphisms, in the case when each `f n` is an epimorphism and `C` has finite biproducts. -/ namespace CategoryTheory.Limits.SequentialProduct variable {C : Type*} {M N : ℕ → C} lemma functorObj_eq_pos {n m : ℕ} (h : m < n) : (fun i ↦ if _ : i < n then M i else N i) m = M m := dif_pos h lemma functorObj_eq_neg {n m : ℕ} (h : ¬(m < n)) : (fun i ↦ if _ : i < n then M i else N i) m = N m := dif_neg h variable [Category C] (f : ∀ n, M n ⟶ N n) [HasProductsOfShape ℕ C] variable (M N) in /-- The product of the `m` first objects of `M` and the rest of the rest of `N` -/ noncomputable def functorObj : ℕ → C := fun n ↦ ∏ᶜ (fun m ↦ if _ : m < n then M m else N m) /-- The projection map from `functorObj M N n` to `M m`, when `m < n` -/ noncomputable def functorObjProj_pos (n m : ℕ) (h : m < n) : functorObj M N n ⟶ M m := Pi.π (fun m ↦ if _ : m < n then M m else N m) m ≫ eqToHom (functorObj_eq_pos (by cutsat)) /-- The projection map from `functorObj M N n` to `N m`, when `m ≥ n` -/ noncomputable def functorObjProj_neg (n m : ℕ) (h : ¬(m < n)) : functorObj M N n ⟶ N m := Pi.π (fun m ↦ if _ : m < n then M m else N m) m ≫ eqToHom (functorObj_eq_neg (by cutsat)) /-- The transition maps in the sequential limit of products -/ noncomputable def functorMap : ∀ n, functorObj M N (n + 1) ⟶ functorObj M N n := by intro n refine Limits.Pi.map fun m ↦ if h : m < n then eqToHom ?_ else if h' : m < n + 1 then eqToHom ?_ ≫ f m ≫ eqToHom ?_ else eqToHom ?_ all_goals split_ifs; try rfl; try cutsat lemma functorMap_commSq_succ (n : ℕ) : (Functor.ofOpSequence (functorMap f)).map (homOfLE (by cutsat : n ≤ n + 1)).op ≫ Pi.π _ n ≫ eqToHom (functorObj_eq_neg (by cutsat : ¬(n < n))) = (Pi.π (fun i ↦ if _ : i < (n + 1) then M i else N i) n) ≫ eqToHom (functorObj_eq_pos (by cutsat)) ≫ f n := by simp [functorMap] lemma functorMap_commSq_aux {n m k : ℕ} (h : n ≤ m) (hh : ¬(k < m)) : (Functor.ofOpSequence (functorMap f)).map (homOfLE h).op ≫ Pi.π _ k ≫ eqToHom (functorObj_eq_neg (by cutsat : ¬(k < n))) = (Pi.π (fun i ↦ if _ : i < m then M i else N i) k) ≫ eqToHom (functorObj_eq_neg hh) := by induction h using Nat.leRec with | refl => simp | @le_succ_of_le m h ih => specialize ih (by cutsat) have : homOfLE (by cutsat : n ≤ m + 1) = homOfLE (by cutsat : n ≤ m) ≫ homOfLE (by cutsat : m ≤ m + 1) := by simp rw [this, op_comp, Functor.map_comp] slice_lhs 2 4 => rw [ih] simp only [Functor.ofOpSequence_obj, homOfLE_leOfHom, Functor.ofOpSequence_map_homOfLE_succ, functorMap, dite_eq_ite, limMap_π_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app] split_ifs simp [dif_neg (by cutsat : ¬(k < m))] lemma functorMap_commSq {n m : ℕ} (h : ¬(m < n)) : (Functor.ofOpSequence (functorMap f)).map (homOfLE (by cutsat : n ≤ m + 1)).op ≫ Pi.π _ m ≫ eqToHom (functorObj_eq_neg (by cutsat : ¬(m < n))) = (Pi.π (fun i ↦ if _ : i < m + 1 then M i else N i) m) ≫ eqToHom (functorObj_eq_pos (by cutsat)) ≫ f m := by cases m with | zero => have : n = 0 := by omega subst this simp [functorMap] | succ m => rw [← functorMap_commSq_succ f (m + 1)] simp only [Functor.ofOpSequence_obj, homOfLE_leOfHom, dite_eq_ite, Functor.ofOpSequence_map_homOfLE_succ] have : homOfLE (by cutsat : n ≤ m + 1 + 1) = homOfLE (by cutsat : n ≤ m + 1) ≫ homOfLE (by cutsat : m + 1 ≤ m + 1 + 1) := by simp rw [this, op_comp, Functor.map_comp] simp only [Functor.ofOpSequence_obj, homOfLE_leOfHom, Functor.ofOpSequence_map_homOfLE_succ, Category.assoc] congr 1 exact functorMap_commSq_aux f (by cutsat) (by cutsat) /-- The cone over the tower ``` ⋯ → ∏_{n < m} M n × ∏_{n ≥ m} N n → ⋯ → ∏ N ``` with cone point `∏ M`. This is a limit cone, see `CategoryTheory.Limits.SequentialProduct.isLimit`. -/ noncomputable def cone : Cone (Functor.ofOpSequence (functorMap f)) where pt := ∏ᶜ M π := by refine NatTrans.ofOpSequence (fun n ↦ Limits.Pi.map fun m ↦ if h : m < n then eqToHom (functorObj_eq_pos h).symm else f m ≫ eqToHom (functorObj_eq_neg h).symm) (fun n ↦ ?_) apply Limits.Pi.hom_ext intro m simp only [Functor.const_obj_obj, Functor.ofOpSequence_obj, homOfLE_leOfHom, Functor.const_obj_map, Category.id_comp, limMap_π, Discrete.functor_obj_eq_as, Discrete.natTrans_app, Functor.ofOpSequence_map_homOfLE_succ, functorMap, Category.assoc, limMap_π_assoc] split · simp [dif_pos (by omega : m < n + 1)] · split all_goals simp lemma cone_π_app (n : ℕ) : (cone f).π.app ⟨n⟩ = Limits.Pi.map fun m ↦ if h : m < n then eqToHom (functorObj_eq_pos h).symm else f m ≫ eqToHom (functorObj_eq_neg h).symm := rfl @[reassoc] lemma cone_π_app_comp_Pi_π_pos (m n : ℕ) (h : n < m) : (cone f).π.app ⟨m⟩ ≫ Pi.π (fun i ↦ if _ : i < m then M i else N i) n = Pi.π _ n ≫ eqToHom (functorObj_eq_pos h).symm := by simp only [Functor.const_obj_obj, dite_eq_ite, Functor.ofOpSequence_obj, cone_π_app, limMap_π, Discrete.functor_obj_eq_as, Discrete.natTrans_app] rw [dif_pos h] @[reassoc] lemma cone_π_app_comp_Pi_π_neg (m n : ℕ) (h : ¬(n < m)) : (cone f).π.app ⟨m⟩ ≫ Pi.π _ n = Pi.π _ n ≫ f n ≫ eqToHom (functorObj_eq_neg h).symm := by simp only [Functor.const_obj_obj, dite_eq_ite, Functor.ofOpSequence_obj, cone_π_app, limMap_π, Discrete.functor_obj_eq_as, Discrete.natTrans_app] rw [dif_neg h] /-- The cone over the tower ``` ⋯ → ∏_{n < m} M n × ∏_{n ≥ m} N n → ⋯ → ∏ N ``` with cone point `∏ M` is indeed a limit cone. -/ noncomputable def isLimit : IsLimit (cone f) where lift s := Pi.lift fun m ↦ s.π.app ⟨m + 1⟩ ≫ Pi.π (fun i ↦ if _ : i < m + 1 then M i else N i) m ≫ eqToHom (dif_pos (by omega : m < m + 1)) fac s := by intro ⟨n⟩ apply Pi.hom_ext intro m by_cases h : m < n · simp only [Category.assoc, cone_π_app_comp_Pi_π_pos f _ _ h] simp only [dite_eq_ite, Functor.ofOpSequence_obj, limit.lift_π_assoc, Fan.mk_pt, Discrete.functor_obj_eq_as, Fan.mk_π_app, Category.assoc, eqToHom_trans] have hh : m + 1 ≤ n := by omega rw [← s.w (homOfLE hh).op] simp only [Functor.const_obj_obj, Functor.ofOpSequence_obj, homOfLE_leOfHom, Category.assoc] congr induction hh using Nat.leRec with | refl => simp | @le_succ_of_le n hh ih => have : homOfLE (Nat.le_succ_of_le hh) = homOfLE hh ≫ homOfLE (Nat.le_succ n) := by simp rw [this, op_comp, Functor.map_comp] simp only [Functor.ofOpSequence_obj, Nat.succ_eq_add_one, homOfLE_leOfHom, Functor.ofOpSequence_map_homOfLE_succ, Category.assoc] have h₁ : (if _ : m < m + 1 then M m else N m) = if _ : m < n then M m else N m := by rw [dif_pos (by omega), dif_pos (by omega)] have h₂ : (if _ : m < n then M m else N m) = if _ : m < n + 1 then M m else N m := by rw [dif_pos h, dif_pos (by omega)] rw [← eqToHom_trans h₁ h₂] slice_lhs 2 4 => rw [ih (by omega)] simp only [functorMap, dite_eq_ite, Pi.π, limMap_π_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app] split_ifs rw [dif_pos (by omega)] simp · simp only [Category.assoc] rw [cone_π_app_comp_Pi_π_neg f _ _ h] simp only [dite_eq_ite, Functor.ofOpSequence_obj, limit.lift_π_assoc, Fan.mk_pt, Discrete.functor_obj_eq_as, Fan.mk_π_app, Category.assoc] slice_lhs 2 4 => erw [← functorMap_commSq f h] simp uniq s m h := by apply Pi.hom_ext intro n simp only [Functor.ofOpSequence_obj, dite_eq_ite, limit.lift_π, Fan.mk_pt, Fan.mk_π_app, ← h ⟨n + 1⟩, Category.assoc] slice_rhs 2 3 => erw [cone_π_app_comp_Pi_π_pos f (n + 1) _ (by omega)] simp section variable [HasZeroMorphisms C] [HasFiniteBiproducts C] [HasCountableProducts C] [∀ n, Epi (f n)] attribute [local instance] hasBinaryBiproducts_of_finite_biproducts lemma functorMap_epi (n : ℕ) : Epi (functorMap f n) := by rw [functorMap, Pi.map_eq_prod_map (P := fun m : ℕ ↦ m < n + 1)] apply (config := { allowSynthFailures := true }) epi_comp apply (config := { allowSynthFailures := true }) epi_comp apply (config := { allowSynthFailures := true }) prod.map_epi · apply (config := { allowSynthFailures := true }) Pi.map_epi intro ⟨_, _⟩ split all_goals infer_instance · apply (config := { allowSynthFailures := true }) IsIso.epi_of_iso apply (config := { allowSynthFailures := true }) Pi.map_isIso intro ⟨_, _⟩ split all_goals infer_instance end end CategoryTheory.Limits.SequentialProduct
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/StrongEpi.lean
import Mathlib.CategoryTheory.Balanced import Mathlib.CategoryTheory.LiftingProperties.Basic /-! # Strong epimorphisms In this file, we define strong epimorphisms. A strong epimorphism is an epimorphism `f` which has the (unique) left lifting property with respect to monomorphisms. Similarly, a strong monomorphisms in a monomorphism which has the (unique) right lifting property with respect to epimorphisms. ## Main results Besides the definition, we show that * the composition of two strong epimorphisms is a strong epimorphism, * if `f ≫ g` is a strong epimorphism, then so is `g`, * if `f` is both a strong epimorphism and a monomorphism, then it is an isomorphism We also define classes `StrongMonoCategory` and `StrongEpiCategory` for categories in which every monomorphism or epimorphism is strong, and deduce that these categories are balanced. ## TODO Show that the dual of a strong epimorphism is a strong monomorphism, and vice versa. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] variable {P Q : C} /-- A strong epimorphism `f` is an epimorphism which has the left lifting property with respect to monomorphisms. -/ class StrongEpi (f : P ⟶ Q) : Prop where /-- The epimorphism condition on `f` -/ epi : Epi f /-- The left lifting property with respect to all monomorphism -/ llp : ∀ ⦃X Y : C⦄ (z : X ⟶ Y) [Mono z], HasLiftingProperty f z theorem StrongEpi.mk' {f : P ⟶ Q} [Epi f] (hf : ∀ (X Y : C) (z : X ⟶ Y) (_ : Mono z) (u : P ⟶ X) (v : Q ⟶ Y) (sq : CommSq u f z v), sq.HasLift) : StrongEpi f := { epi := inferInstance llp := fun {X Y} z hz => ⟨fun {u v} sq => hf X Y z hz u v sq⟩ } /-- A strong monomorphism `f` is a monomorphism which has the right lifting property with respect to epimorphisms. -/ class StrongMono (f : P ⟶ Q) : Prop where /-- The monomorphism condition on `f` -/ mono : Mono f /-- The right lifting property with respect to all epimorphisms -/ rlp : ∀ ⦃X Y : C⦄ (z : X ⟶ Y) [Epi z], HasLiftingProperty z f theorem StrongMono.mk' {f : P ⟶ Q} [Mono f] (hf : ∀ (X Y : C) (z : X ⟶ Y) (_ : Epi z) (u : X ⟶ P) (v : Y ⟶ Q) (sq : CommSq u z f v), sq.HasLift) : StrongMono f where mono := inferInstance rlp := fun {X Y} z hz => ⟨fun {u v} sq => hf X Y z hz u v sq⟩ attribute [instance 100] StrongEpi.llp attribute [instance 100] StrongMono.rlp instance (priority := 100) epi_of_strongEpi (f : P ⟶ Q) [StrongEpi f] : Epi f := StrongEpi.epi instance (priority := 100) mono_of_strongMono (f : P ⟶ Q) [StrongMono f] : Mono f := StrongMono.mono section variable {R : C} (f : P ⟶ Q) (g : Q ⟶ R) /-- The composition of two strong epimorphisms is a strong epimorphism. -/ theorem strongEpi_comp [StrongEpi f] [StrongEpi g] : StrongEpi (f ≫ g) := { epi := epi_comp _ _ llp := by intros infer_instance } /-- The composition of two strong monomorphisms is a strong monomorphism. -/ theorem strongMono_comp [StrongMono f] [StrongMono g] : StrongMono (f ≫ g) := { mono := mono_comp _ _ rlp := by intros infer_instance } /-- If `f ≫ g` is a strong epimorphism, then so is `g`. -/ theorem strongEpi_of_strongEpi [StrongEpi (f ≫ g)] : StrongEpi g := { epi := epi_of_epi f g llp := fun {X Y} z _ => by constructor intro u v sq have h₀ : (f ≫ u) ≫ z = (f ≫ g) ≫ v := by simp only [Category.assoc, sq.w] exact CommSq.HasLift.mk' ⟨(CommSq.mk h₀).lift, by simp only [← cancel_mono z, Category.assoc, CommSq.fac_right, sq.w], by simp⟩ } /-- If `f ≫ g` is a strong monomorphism, then so is `f`. -/ theorem strongMono_of_strongMono [StrongMono (f ≫ g)] : StrongMono f := { mono := mono_of_mono f g rlp := fun {X Y} z => by intros constructor intro u v sq have h₀ : u ≫ f ≫ g = z ≫ v ≫ g := by rw [← Category.assoc, eq_whisker sq.w, Category.assoc] exact CommSq.HasLift.mk' ⟨(CommSq.mk h₀).lift, by simp, by simp [← cancel_epi z, sq.w]⟩ } /-- An isomorphism is in particular a strong epimorphism. -/ instance (priority := 100) strongEpi_of_isIso [IsIso f] : StrongEpi f where epi := by infer_instance llp {_ _} _ := HasLiftingProperty.of_left_iso _ _ /-- An isomorphism is in particular a strong monomorphism. -/ instance (priority := 100) strongMono_of_isIso [IsIso f] : StrongMono f where mono := by infer_instance rlp {_ _} _ := HasLiftingProperty.of_right_iso _ _ theorem StrongEpi.of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) [h : StrongEpi f] : StrongEpi g := { epi := by rw [Arrow.iso_w' e] infer_instance llp := fun {X Y} z => by intro apply HasLiftingProperty.of_arrow_iso_left e z } theorem StrongMono.of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) [h : StrongMono f] : StrongMono g := { mono := by rw [Arrow.iso_w' e] infer_instance rlp := fun {X Y} z => by intro apply HasLiftingProperty.of_arrow_iso_right z e } theorem StrongEpi.iff_of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) : StrongEpi f ↔ StrongEpi g := by constructor <;> intro exacts [StrongEpi.of_arrow_iso e, StrongEpi.of_arrow_iso e.symm] theorem StrongMono.iff_of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) : StrongMono f ↔ StrongMono g := by constructor <;> intro exacts [StrongMono.of_arrow_iso e, StrongMono.of_arrow_iso e.symm] end /-- A strong epimorphism that is a monomorphism is an isomorphism. -/ theorem isIso_of_mono_of_strongEpi (f : P ⟶ Q) [Mono f] [StrongEpi f] : IsIso f := ⟨⟨(CommSq.mk (show 𝟙 P ≫ f = f ≫ 𝟙 Q by simp)).lift, by simp⟩⟩ /-- A strong monomorphism that is an epimorphism is an isomorphism. -/ theorem isIso_of_epi_of_strongMono (f : P ⟶ Q) [Epi f] [StrongMono f] : IsIso f := ⟨⟨(CommSq.mk (show 𝟙 P ≫ f = f ≫ 𝟙 Q by simp)).lift, by simp⟩⟩ section variable (C) /-- A strong epi category is a category in which every epimorphism is strong. -/ class StrongEpiCategory : Prop where /-- A strong epi category is a category in which every epimorphism is strong. -/ strongEpi_of_epi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], StrongEpi f /-- A strong mono category is a category in which every monomorphism is strong. -/ class StrongMonoCategory : Prop where /-- A strong mono category is a category in which every monomorphism is strong. -/ strongMono_of_mono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], StrongMono f end theorem strongEpi_of_epi [StrongEpiCategory C] (f : P ⟶ Q) [Epi f] : StrongEpi f := StrongEpiCategory.strongEpi_of_epi _ theorem strongMono_of_mono [StrongMonoCategory C] (f : P ⟶ Q) [Mono f] : StrongMono f := StrongMonoCategory.strongMono_of_mono _ section attribute [local instance] strongEpi_of_epi instance (priority := 100) balanced_of_strongEpiCategory [StrongEpiCategory C] : Balanced C where isIso_of_mono_of_epi _ _ _ := isIso_of_mono_of_strongEpi _ end section attribute [local instance] strongMono_of_mono instance (priority := 100) balanced_of_strongMonoCategory [StrongMonoCategory C] : Balanced C where isIso_of_mono_of_epi _ _ _ := isIso_of_epi_of_strongMono _ end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/PiProd.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Products /-! # A product as a binary product We write a product indexed by `I` as a binary product of the products indexed by a subset of `I` and its complement. -/ namespace CategoryTheory.Limits variable {C I : Type*} [Category C] {X Y : I → C} (f : (i : I) → X i ⟶ Y i) (P : I → Prop) [HasProduct X] [HasProduct Y] [HasProduct (fun (i : {x : I // P x}) ↦ X i.val)] [HasProduct (fun (i : {x : I // ¬ P x}) ↦ X i.val)] [HasProduct (fun (i : {x : I // P x}) ↦ Y i.val)] [HasProduct (fun (i : {x : I // ¬ P x}) ↦ Y i.val)] variable (X) in /-- The projection maps of a product to the products indexed by a subset and its complement, as a binary fan. -/ noncomputable def Pi.binaryFanOfProp : BinaryFan (∏ᶜ (fun (i : {x : I // P x}) ↦ X i.val)) (∏ᶜ (fun (i : {x : I // ¬ P x}) ↦ X i.val)) := BinaryFan.mk (P := ∏ᶜ X) (Pi.map' Subtype.val fun _ ↦ 𝟙 _) (Pi.map' Subtype.val fun _ ↦ 𝟙 _) variable (X) in /-- A product indexed by `I` is a binary product of the products indexed by a subset of `I` and its complement. -/ noncomputable def Pi.binaryFanOfPropIsLimit [∀ i, Decidable (P i)] : IsLimit (Pi.binaryFanOfProp X P) := BinaryFan.isLimitMk (fun s ↦ Pi.lift fun b ↦ if h : P b then s.π.app ⟨WalkingPair.left⟩ ≫ Pi.π (fun (i : {x : I // P x}) ↦ X i.val) ⟨b, h⟩ else s.π.app ⟨WalkingPair.right⟩ ≫ Pi.π (fun (i : {x : I // ¬ P x}) ↦ X i.val) ⟨b, h⟩) (by aesop) (by aesop) (fun _ _ h₁ h₂ ↦ Pi.hom_ext _ _ fun b ↦ by by_cases h : P b · simp [← h₁, dif_pos h] · simp [← h₂, dif_neg h]) lemma hasBinaryProduct_of_products : HasBinaryProduct (∏ᶜ (fun (i : {x : I // P x}) ↦ X i.val)) (∏ᶜ (fun (i : {x : I // ¬ P x}) ↦ X i.val)) := by classical exact ⟨Pi.binaryFanOfProp X P, Pi.binaryFanOfPropIsLimit X P⟩ attribute [local instance] hasBinaryProduct_of_products lemma Pi.map_eq_prod_map [∀ i, Decidable (P i)] : Pi.map f = ((Pi.binaryFanOfPropIsLimit X P).conePointUniqueUpToIso (prodIsProd _ _)).hom ≫ prod.map (Pi.map (fun (i : {x : I // P x}) ↦ f i.val)) (Pi.map (fun (i : {x : I // ¬ P x}) ↦ f i.val)) ≫ ((Pi.binaryFanOfPropIsLimit Y P).conePointUniqueUpToIso (prodIsProd _ _)).inv := by rw [← Category.assoc, Iso.eq_comp_inv] dsimp only [IsLimit.conePointUniqueUpToIso, binaryFanOfProp, prodIsProd] apply prod.hom_ext all_goals cat_disch end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Diagonal.lean
import Mathlib.CategoryTheory.Comma.Over.Pullback import Mathlib.CategoryTheory.Limits.Shapes.KernelPair import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Assoc /-! # The diagonal object of a morphism. We provide various API and isomorphisms considering the diagonal object `Δ_{Y/X} := pullback f f` of a morphism `f : X ⟶ Y`. -/ open CategoryTheory noncomputable section namespace CategoryTheory.Limits variable {C : Type*} [Category C] {X Y Z : C} namespace pullback section Diagonal variable (f : X ⟶ Y) [HasPullback f f] /-- The diagonal object of a morphism `f : X ⟶ Y` is `Δ_{X/Y} := pullback f f`. -/ abbrev diagonalObj : C := pullback f f /-- The diagonal morphism `X ⟶ Δ_{X/Y}` for a morphism `f : X ⟶ Y`. -/ def diagonal : X ⟶ diagonalObj f := pullback.lift (𝟙 _) (𝟙 _) rfl @[reassoc (attr := simp)] theorem diagonal_fst : diagonal f ≫ pullback.fst _ _ = 𝟙 _ := pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem diagonal_snd : diagonal f ≫ pullback.snd _ _ = 𝟙 _ := pullback.lift_snd _ _ _ instance : IsSplitMono (diagonal f) := ⟨⟨⟨pullback.fst _ _, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.fst f f) := ⟨⟨⟨diagonal f, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.snd f f) := ⟨⟨⟨diagonal f, diagonal_snd f⟩⟩⟩ instance [Mono f] : IsIso (diagonal f) := by rw [(IsIso.inv_eq_of_inv_hom_id (diagonal_fst f)).symm] infer_instance lemma isIso_diagonal_iff : IsIso (diagonal f) ↔ Mono f := ⟨fun H ↦ ⟨fun _ _ e ↦ by rw [← lift_fst _ _ e, (cancel_epi (g := fst f f) (h := snd f f) (diagonal f)).mp (by simp), lift_snd]⟩, fun _ ↦ inferInstance⟩ /-- The two projections `Δ_{X/Y} ⟶ X` form a kernel pair for `f : X ⟶ Y`. -/ theorem diagonal_isKernelPair : IsKernelPair f (pullback.fst f f) (pullback.snd f f) := IsPullback.of_hasPullback f f end Diagonal end pullback variable [HasPullbacks C] open pullback section variable {U V₁ V₂ : C} (f : X ⟶ Y) (i : U ⟶ Y) variable (i₁ : V₁ ⟶ pullback f i) (i₂ : V₂ ⟶ pullback f i) @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_fst_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (i₂ ≫ snd f i) f f (i₁ ≫ fst f i) (i₂ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ fst _ _ ≫ i₁ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_fst f, pullback.condition_assoc, pullback.lift_fst] @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_snd_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (i₂ ≫ snd f i) f f (i₁ ≫ fst f i) (i₂ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ snd _ _ ≫ i₂ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_snd f, pullback.condition_assoc, pullback.lift_snd] variable [HasPullback i₁ i₂] /-- The underlying map of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.hom : pullback (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) ⟶ pullback i₁ i₂ := pullback.lift (pullback.snd _ _ ≫ pullback.fst _ _) (pullback.snd _ _ ≫ pullback.snd _ _) (by ext · simp only [Category.assoc, pullback_diagonal_map_snd_fst_fst, pullback_diagonal_map_snd_snd_fst] · simp only [Category.assoc, condition]) /-- The underlying inverse of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.inv : pullback i₁ i₂ ⟶ pullback (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) := pullback.lift (pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _) (pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (pullback.snd _ _) (Category.id_comp _).symm (Category.id_comp _).symm) (by ext · simp only [Category.assoc, diagonal_fst, Category.comp_id, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, limit.lift_π_assoc, cospan_left] · simp only [condition_assoc, Category.assoc, diagonal_snd, Category.comp_id, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, limit.lift_π_assoc, cospan_right]) /-- This iso witnesses the fact that given `f : X ⟶ Y`, `i : U ⟶ Y`, and `i₁ : V₁ ⟶ X ×[Y] U`, `i₂ : V₂ ⟶ X ×[Y] U`, the diagram ``` V₁ ×[X ×[Y] U] V₂ ⟶ V₁ ×[U] V₂ | | | | ↓ ↓ X ⟶ X ×[Y] X ``` is a pullback square. Also see `pullback_fst_map_snd_isPullback`. -/ def pullbackDiagonalMapIso : pullback (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) ≅ pullback i₁ i₂ where hom := pullbackDiagonalMapIso.hom f i i₁ i₂ inv := pullbackDiagonalMapIso.inv f i i₁ i₂ @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.hom_fst : (pullbackDiagonalMapIso f i i₁ i₂).hom ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by delta pullbackDiagonalMapIso simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.hom_snd : (pullbackDiagonalMapIso f i i₁ i₂).hom ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta pullbackDiagonalMapIso simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.inv_fst : (pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.fst _ _ = pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _ := by delta pullbackDiagonalMapIso simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.inv_snd_fst : (pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := by delta pullbackDiagonalMapIso simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.inv_snd_snd : (pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := by delta pullbackDiagonalMapIso simp theorem pullback_fst_map_snd_isPullback : IsPullback (fst _ _ ≫ i₁ ≫ fst _ _) (map i₁ i₂ (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) _ _ _ (Category.id_comp _).symm (Category.id_comp _).symm) (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp [condition]) (by simp [condition])) := IsPullback.of_iso_pullback ⟨by ext <;> simp [condition_assoc]⟩ (pullbackDiagonalMapIso f i i₁ i₂).symm (pullbackDiagonalMapIso.inv_fst f i i₁ i₂) (by cat_disch) end section variable {S T : C} (f : X ⟶ T) (g : Y ⟶ T) (i : T ⟶ S) variable [HasPullback i i] [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] variable [HasPullback (diagonal i) (pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _))] /-- This iso witnesses the fact that given `f : X ⟶ T`, `g : Y ⟶ T`, and `i : T ⟶ S`, the diagram ``` X ×ₜ Y ⟶ X ×ₛ Y | | | | ↓ ↓ T ⟶ T ×ₛ T ``` is a pullback square. Also see `pullback_map_diagonal_isPullback`. -/ def pullbackDiagonalMapIdIso : pullback (diagonal i) (pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _)) ≅ pullback f g := by refine ?_ ≪≫ pullbackDiagonalMapIso i (𝟙 _) (f ≫ inv (pullback.fst _ _)) (g ≫ inv (pullback.fst _ _)) ≪≫ ?_ · refine @asIso _ _ _ _ (pullback.map _ _ _ _ (𝟙 T) ((pullback.congrHom ?_ ?_).hom) (𝟙 _) ?_ ?_) ?_ · rw [← Category.comp_id (pullback.snd ..), ← condition, Category.assoc, IsIso.inv_hom_id_assoc] · rw [← Category.comp_id (pullback.snd ..), ← condition, Category.assoc, IsIso.inv_hom_id_assoc] · rw [Category.comp_id, Category.id_comp] · ext <;> simp · infer_instance · refine @asIso _ _ _ _ (pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (pullback.fst _ _) ?_ ?_) ?_ · rw [Category.assoc, IsIso.inv_hom_id, Category.comp_id, Category.id_comp] · rw [Category.assoc, IsIso.inv_hom_id, Category.comp_id, Category.id_comp] · infer_instance @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_hom_fst : (pullbackDiagonalMapIdIso f g i).hom ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by delta pullbackDiagonalMapIdIso simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_hom_snd : (pullbackDiagonalMapIdIso f g i).hom ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta pullbackDiagonalMapIdIso simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_inv_fst : (pullbackDiagonalMapIdIso f g i).inv ≫ pullback.fst _ _ = pullback.fst _ _ ≫ f := by rw [Iso.inv_comp_eq, ← Category.comp_id (pullback.fst _ _), ← diagonal_fst i, pullback.condition_assoc] simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_inv_snd_fst : (pullbackDiagonalMapIdIso f g i).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := by rw [Iso.inv_comp_eq] simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_inv_snd_snd : (pullbackDiagonalMapIdIso f g i).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := by rw [Iso.inv_comp_eq] simp theorem pullback.diagonal_comp (f : X ⟶ Y) (g : Y ⟶ Z) : diagonal (f ≫ g) = diagonal f ≫ (pullbackDiagonalMapIdIso f f g).inv ≫ pullback.snd _ _ := by ext <;> simp @[reassoc] lemma pullback.comp_diagonal (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ pullback.diagonal g = pullback.diagonal (f ≫ g) ≫ pullback.map (f ≫ g) (f ≫ g) g g f f (𝟙 Z) (by simp) (by simp) := by ext <;> simp theorem pullback_map_diagonal_isPullback : IsPullback (pullback.fst _ _ ≫ f) (pullback.map f g (f ≫ i) (g ≫ i) _ _ i (Category.id_comp _).symm (Category.id_comp _).symm) (diagonal i) (pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _)) := by apply IsPullback.of_iso_pullback _ (pullbackDiagonalMapIdIso f g i).symm · simp · ext <;> simp · constructor ext <;> simp [condition] /-- The diagonal object of `X ×[Z] Y ⟶ X` is isomorphic to `Δ_{Y/Z} ×[Z] X`. -/ def diagonalObjPullbackFstIso {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : diagonalObj (pullback.fst f g) ≅ pullback (pullback.snd _ _ ≫ g : diagonalObj g ⟶ Z) f := pullbackRightPullbackFstIso _ _ _ ≪≫ pullback.congrHom pullback.condition rfl ≪≫ pullbackAssoc _ _ _ _ ≪≫ pullbackSymmetry _ _ ≪≫ pullback.congrHom pullback.condition rfl @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_hom_fst_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).hom ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_hom_fst_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).hom ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_hom_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).hom ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_fst_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_fst_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_snd_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_snd_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp theorem diagonal_pullback_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : diagonal (pullback.fst f g) = (pullbackSymmetry _ _).hom ≫ ((Over.pullback f).map (Over.homMk (diagonal g) : Over.mk g ⟶ Over.mk (pullback.snd _ _ ≫ g))).left ≫ (diagonalObjPullbackFstIso f g).inv := by ext <;> simp /-- Informally, this is a special case of `pullback_map_diagonal_isPullback` for `T = X`. -/ lemma pullback_lift_diagonal_isPullback (g : Y ⟶ X) (f : X ⟶ S) : IsPullback g (pullback.lift (𝟙 Y) g (by simp)) (diagonal f) (pullback.map (g ≫ f) f f f g (𝟙 X) (𝟙 S) (by simp) (by simp)) := by let i : pullback (g ≫ f) f ≅ pullback (g ≫ f) (𝟙 X ≫ f) := congrHom rfl (by simp) let e : pullback (diagonal f) (map (g ≫ f) f f f g (𝟙 X) (𝟙 S) (by simp) (by simp)) ≅ pullback (diagonal f) (map (g ≫ f) (𝟙 X ≫ f) f f g (𝟙 X) (𝟙 S) (by simp) (by simp)) := (asIso (map _ _ _ _ (𝟙 _) i.inv (𝟙 _) (by simp) (by ext <;> simp [i]))).symm apply IsPullback.of_iso_pullback _ (e ≪≫ pullbackDiagonalMapIdIso (T := X) (S := S) g (𝟙 X) f ≪≫ asIso (pullback.fst _ _)).symm · simp [e] · ext <;> simp [e, i] · constructor ext <;> simp end /-- Given the following diagram with `S ⟶ S'` a monomorphism, ``` X ⟶ X' ↘ ↘ S ⟶ S' ↗ ↗ Y ⟶ Y' ``` This iso witnesses the fact that ``` X ×[S] Y ⟶ (X' ×[S'] Y') ×[Y'] Y | | | | ↓ ↓ (X' ×[S'] Y') ×[X'] X ⟶ X' ×[S'] Y' ``` is a pullback square. The diagonal map of this square is `pullback.map`. Also see `pullback_lift_map_is_pullback`. -/ @[simps] def pullbackFstFstIso {X Y S X' Y' S' : C} (f : X ⟶ S) (g : Y ⟶ S) (f' : X' ⟶ S') (g' : Y' ⟶ S') (i₁ : X ⟶ X') (i₂ : Y ⟶ Y') (i₃ : S ⟶ S') (e₁ : f ≫ i₃ = i₁ ≫ f') (e₂ : g ≫ i₃ = i₂ ≫ g') [Mono i₃] : pullback (pullback.fst _ _ : pullback (pullback.fst _ _ : pullback f' g' ⟶ _) i₁ ⟶ _) (pullback.fst _ _ : pullback (pullback.snd _ _ : pullback f' g' ⟶ _) i₂ ⟶ _) ≅ pullback f g where hom := pullback.lift (pullback.fst _ _ ≫ pullback.snd _ _) (pullback.snd _ _ ≫ pullback.snd _ _) (by rw [← cancel_mono i₃, Category.assoc, Category.assoc, Category.assoc, Category.assoc, e₁, e₂, ← pullback.condition_assoc, pullback.condition_assoc, pullback.condition, pullback.condition_assoc]) inv := pullback.lift (pullback.lift (pullback.map _ _ _ _ _ _ _ e₁ e₂) (pullback.fst _ _) (pullback.lift_fst ..)) (pullback.lift (pullback.map _ _ _ _ _ _ _ e₁ e₂) (pullback.snd _ _) (pullback.lift_snd ..)) (by rw [pullback.lift_fst, pullback.lift_fst]) hom_inv_id := by -- We could use `ext` here to immediately descend to the leaf goals, -- but it only obscures the structure. apply pullback.hom_ext · apply pullback.hom_ext · apply pullback.hom_ext · simp only [Category.assoc, lift_fst, lift_fst_assoc, Category.id_comp] rw [condition] · simp [Category.assoc, condition] · simp only [Category.assoc, lift_snd, lift_fst, Category.id_comp] · apply pullback.hom_ext · apply pullback.hom_ext · simp only [Category.assoc, lift_snd_assoc, lift_fst_assoc, lift_fst, Category.id_comp] rw [← condition_assoc, condition] · simp only [Category.assoc, lift_snd, lift_fst_assoc, lift_snd_assoc, Category.id_comp] rw [condition] · simp only [Category.assoc, lift_snd, Category.id_comp] inv_hom_id := by apply pullback.hom_ext · simp only [Category.assoc, lift_fst, lift_fst_assoc, lift_snd, Category.id_comp] · simp only [Category.assoc, lift_snd, lift_snd_assoc, Category.id_comp] theorem pullback_map_eq_pullbackFstFstIso_inv {X Y S X' Y' S' : C} (f : X ⟶ S) (g : Y ⟶ S) (f' : X' ⟶ S') (g' : Y' ⟶ S') (i₁ : X ⟶ X') (i₂ : Y ⟶ Y') (i₃ : S ⟶ S') (e₁ : f ≫ i₃ = i₁ ≫ f') (e₂ : g ≫ i₃ = i₂ ≫ g') [Mono i₃] : pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂ = (pullbackFstFstIso f g f' g' i₁ i₂ i₃ e₁ e₂).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ := by simp only [pullbackFstFstIso_inv, lift_snd_assoc, lift_fst] theorem pullback_lift_map_isPullback {X Y S X' Y' S' : C} (f : X ⟶ S) (g : Y ⟶ S) (f' : X' ⟶ S') (g' : Y' ⟶ S') (i₁ : X ⟶ X') (i₂ : Y ⟶ Y') (i₃ : S ⟶ S') (e₁ : f ≫ i₃ = i₁ ≫ f') (e₂ : g ≫ i₃ = i₂ ≫ g') [Mono i₃] : IsPullback (pullback.lift (pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂) (fst _ _) (lift_fst _ _ _)) (pullback.lift (pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂) (snd _ _) (lift_snd _ _ _)) (pullback.fst _ _) (pullback.fst _ _) := IsPullback.of_iso_pullback ⟨by rw [lift_fst, lift_fst]⟩ (pullbackFstFstIso f g f' g' i₁ i₂ i₃ e₁ e₂).symm (by simp) (by simp) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Products.lean
import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Discrete.Basic /-! # Categorical (co)products This file defines (co)products as special cases of (co)limits. A product is the categorical generalization of the object `Π i, f i` where `f : ι → C`. It is a limit cone over the diagram formed by `f`, implemented by converting `f` into a functor `Discrete ι ⥤ C`. A coproduct is the dual concept. ## Main definitions * a `Fan` is a cone over a discrete category * `Fan.mk` constructs a fan from an indexed collection of maps * a `Pi` is a `limit (Discrete.functor f)` Each of these has a dual. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. -/ noncomputable section universe w w' w₂ w₃ v v₂ u u₂ open CategoryTheory namespace CategoryTheory.Limits variable {β : Type w} {α : Type w₂} {γ : Type w₃} variable {C : Type u} [Category.{v} C] -- We don't need an analogue of `Pair` (for binary products), `ParallelPair` (for equalizers), -- or `(Co)span`, since we already have `Discrete.functor`. /-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/ abbrev Fan (f : β → C) := Cone (Discrete.functor f) /-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/ abbrev Cofan (f : β → C) := Cocone (Discrete.functor f) /-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/ @[simps! pt π_app] def Fan.mk {f : β → C} (P : C) (p : ∀ b, P ⟶ f b) : Fan f where pt := P π := Discrete.natTrans (fun X => p X.as) /-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/ @[simps! pt ι_app] def Cofan.mk {f : β → C} (P : C) (p : ∀ b, f b ⟶ P) : Cofan f where pt := P ι := Discrete.natTrans (fun X => p X.as) /-- Get the `j`th "projection" in the fan. (Note that the initial letter of `proj` matches the greek letter in `Cone.π`.) -/ def Fan.proj {f : β → C} (p : Fan f) (j : β) : p.pt ⟶ f j := p.π.app (Discrete.mk j) /-- Get the `j`th "injection" in the cofan. (Note that the initial letter of `inj` matches the greek letter in `Cocone.ι`.) -/ def Cofan.inj {f : β → C} (p : Cofan f) (j : β) : f j ⟶ p.pt := p.ι.app (Discrete.mk j) @[simp] theorem fan_mk_proj {f : β → C} (P : C) (p : ∀ b, P ⟶ f b) : (Fan.mk P p).proj = p := rfl @[simp] theorem cofan_mk_inj {f : β → C} (P : C) (p : ∀ b, f b ⟶ P) : (Cofan.mk P p).inj = p := rfl /-- An abbreviation for `HasLimit (Discrete.functor f)`. -/ abbrev HasProduct (f : β → C) := HasLimit (Discrete.functor f) /-- An abbreviation for `HasColimit (Discrete.functor f)`. -/ abbrev HasCoproduct (f : β → C) := HasColimit (Discrete.functor f) lemma hasCoproduct_of_equiv_of_iso (f : α → C) (g : β → C) [HasCoproduct f] (e : β ≃ α) (iso : ∀ j, g j ≅ f (e j)) : HasCoproduct g := by have α : Discrete.functor g ≅ (Discrete.equivalence e).functor ⋙ Discrete.functor f := Discrete.natIso (fun ⟨j⟩ => iso j) exact hasColimit_of_iso α lemma hasProduct_of_equiv_of_iso (f : α → C) (g : β → C) [HasProduct f] (e : β ≃ α) (iso : ∀ j, g j ≅ f (e j)) : HasProduct g := by have α : Discrete.functor g ≅ (Discrete.equivalence e).functor ⋙ Discrete.functor f := Discrete.natIso (fun ⟨j⟩ => iso j) exact hasLimit_of_iso α.symm /-- Make a fan `f` into a limit fan by providing `lift`, `fac`, and `uniq` -- just a convenience lemma to avoid having to go through `Discrete` -/ @[simps] def mkFanLimit {f : β → C} (t : Fan f) (lift : ∀ s : Fan f, s.pt ⟶ t.pt) (fac : ∀ (s : Fan f) (j : β), lift s ≫ t.proj j = s.proj j := by cat_disch) (uniq : ∀ (s : Fan f) (m : s.pt ⟶ t.pt) (_ : ∀ j : β, m ≫ t.proj j = s.proj j), m = lift s := by cat_disch) : IsLimit t := { lift } /-- Constructor for morphisms to the point of a limit fan. -/ def Fan.IsLimit.desc {F : β → C} {c : Fan F} (hc : IsLimit c) {A : C} (f : ∀ i, A ⟶ F i) : A ⟶ c.pt := hc.lift (Fan.mk A f) @[reassoc (attr := simp)] lemma Fan.IsLimit.fac {F : β → C} {c : Fan F} (hc : IsLimit c) {A : C} (f : ∀ i, A ⟶ F i) (i : β) : Fan.IsLimit.desc hc f ≫ c.proj i = f i := hc.fac (Fan.mk A f) ⟨i⟩ @[reassoc (attr := simp)] lemma Fan.IsLimit.lift_proj {X : β → C} {c : Fan X} (d : Fan X) (hc : IsLimit c) (i : β) : hc.lift d ≫ c.proj i = d.proj i := hc.fac _ _ lemma Fan.IsLimit.hom_ext {I : Type*} {F : I → C} {c : Fan F} (hc : IsLimit c) {A : C} (f g : A ⟶ c.pt) (h : ∀ i, f ≫ c.proj i = g ≫ c.proj i) : f = g := hc.hom_ext (fun ⟨i⟩ => h i) /-- Make a cofan `f` into a colimit cofan by providing `desc`, `fac`, and `uniq` -- just a convenience lemma to avoid having to go through `Discrete` -/ @[simps] def mkCofanColimit {f : β → C} (s : Cofan f) (desc : ∀ t : Cofan f, s.pt ⟶ t.pt) (fac : ∀ (t : Cofan f) (j : β), s.inj j ≫ desc t = t.inj j := by cat_disch) (uniq : ∀ (t : Cofan f) (m : s.pt ⟶ t.pt) (_ : ∀ j : β, s.inj j ≫ m = t.inj j), m = desc t := by cat_disch) : IsColimit s := { desc } /-- Constructor for morphisms from the point of a colimit cofan. -/ def Cofan.IsColimit.desc {F : β → C} {c : Cofan F} (hc : IsColimit c) {A : C} (f : ∀ i, F i ⟶ A) : c.pt ⟶ A := hc.desc (Cofan.mk A f) @[reassoc (attr := simp)] lemma Cofan.IsColimit.fac {F : β → C} {c : Cofan F} (hc : IsColimit c) {A : C} (f : ∀ i, F i ⟶ A) (i : β) : c.inj i ≫ Cofan.IsColimit.desc hc f = f i := hc.fac (Cofan.mk A f) ⟨i⟩ @[reassoc (attr := simp)] lemma Cofan.IsColimit.inj_desc {X : β → C} {c : Cofan X} (d : Cofan X) (hc : IsColimit c) (i : β) : c.inj i ≫ hc.desc d = d.inj i := hc.fac _ _ lemma Cofan.IsColimit.hom_ext {I : Type*} {F : I → C} {c : Cofan F} (hc : IsColimit c) {A : C} (f g : c.pt ⟶ A) (h : ∀ i, c.inj i ≫ f = c.inj i ≫ g) : f = g := hc.hom_ext (fun ⟨i⟩ => h i) section variable (C) /-- An abbreviation for `HasLimitsOfShape (Discrete f)`. -/ abbrev HasProductsOfShape (β : Type v) := HasLimitsOfShape.{v} (Discrete β) /-- An abbreviation for `HasColimitsOfShape (Discrete f)`. -/ abbrev HasCoproductsOfShape (β : Type v) := HasColimitsOfShape.{v} (Discrete β) end /-- `piObj f` computes the product of a family of elements `f`. (It is defined as an abbreviation for `limit (Discrete.functor f)`, so for most facts about `piObj f`, you will just use general facts about limits.) -/ abbrev piObj (f : β → C) [HasProduct f] := limit (Discrete.functor f) /-- `sigmaObj f` computes the coproduct of a family of elements `f`. (It is defined as an abbreviation for `colimit (Discrete.functor f)`, so for most facts about `sigmaObj f`, you will just use general facts about colimits.) -/ abbrev sigmaObj (f : β → C) [HasCoproduct f] := colimit (Discrete.functor f) /-- notation for categorical products. We need `ᶜ` to avoid conflict with `Finset.prod`. -/ notation "∏ᶜ " f:60 => piObj f /-- notation for categorical coproducts -/ notation "∐ " f:60 => sigmaObj f /-- The `b`-th projection from the pi object over `f` has the form `∏ᶜ f ⟶ f b`. -/ abbrev Pi.π (f : β → C) [HasProduct f] (b : β) : ∏ᶜ f ⟶ f b := limit.π (Discrete.functor f) (Discrete.mk b) /-- The `b`-th inclusion into the sigma object over `f` has the form `f b ⟶ ∐ f`. -/ abbrev Sigma.ι (f : β → C) [HasCoproduct f] (b : β) : f b ⟶ ∐ f := colimit.ι (Discrete.functor f) (Discrete.mk b) /-- Without this lemma, `limit.hom_ext` would be applied, but the goal would involve terms in `Discrete β` rather than `β` itself. -/ @[ext 1050] lemma Pi.hom_ext {f : β → C} [HasProduct f] {X : C} (g₁ g₂ : X ⟶ ∏ᶜ f) (h : ∀ (b : β), g₁ ≫ Pi.π f b = g₂ ≫ Pi.π f b) : g₁ = g₂ := limit.hom_ext (fun ⟨j⟩ => h j) /-- Without this lemma, `limit.hom_ext` would be applied, but the goal would involve terms in `Discrete β` rather than `β` itself. -/ @[ext 1050] lemma Sigma.hom_ext {f : β → C} [HasCoproduct f] {X : C} (g₁ g₂ : ∐ f ⟶ X) (h : ∀ (b : β), Sigma.ι f b ≫ g₁ = Sigma.ι f b ≫ g₂) : g₁ = g₂ := colimit.hom_ext (fun ⟨j⟩ => h j) /-- The fan constructed of the projections from the product is limiting. -/ def productIsProduct (f : β → C) [HasProduct f] : IsLimit (Fan.mk _ (Pi.π f)) := IsLimit.ofIsoLimit (limit.isLimit (Discrete.functor f)) (Cones.ext (Iso.refl _)) /-- The cofan constructed of the inclusions from the coproduct is colimiting. -/ def coproductIsCoproduct (f : β → C) [HasCoproduct f] : IsColimit (Cofan.mk _ (Sigma.ι f)) := IsColimit.ofIsoColimit (colimit.isColimit (Discrete.functor f)) (Cocones.ext (Iso.refl _)) -- TODO?: simp can prove this using `eqToHom_naturality` -- but `eqToHom_naturality` applies less easily than this lemma @[reassoc] theorem Pi.π_comp_eqToHom {J : Type*} (f : J → C) [HasProduct f] {j j' : J} (w : j = j') : Pi.π f j ≫ eqToHom (by simp [w]) = Pi.π f j' := by simp [*] @[reassoc (attr := simp)] theorem Sigma.eqToHom_comp_ι {J : Type*} (f : J → C) [HasCoproduct f] {j j' : J} (w : j = j') : eqToHom (by simp [w]) ≫ Sigma.ι f j' = Sigma.ι f j := by cases w simp /-- A collection of morphisms `P ⟶ f b` induces a morphism `P ⟶ ∏ᶜ f`. -/ abbrev Pi.lift {f : β → C} [HasProduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ∏ᶜ f := limit.lift _ (Fan.mk P p) @[reassoc] theorem Pi.lift_π {β : Type w} {f : β → C} [HasProduct f] {P : C} (p : ∀ b, P ⟶ f b) (b : β) : Pi.lift p ≫ Pi.π f b = p b := by simp only [limit.lift_π, Fan.mk_pt, Fan.mk_π_app] /-- A version of `Cones.ext` for `Fan`s. -/ @[simps!] def Fan.ext {f : β → C} {c₁ c₂ : Fan f} (e : c₁.pt ≅ c₂.pt) (w : ∀ (b : β), c₁.proj b = e.hom ≫ c₂.proj b := by cat_disch) : c₁ ≅ c₂ := Cones.ext e (fun ⟨j⟩ => w j) /-- A collection of morphisms `f b ⟶ P` induces a morphism `∐ f ⟶ P`. -/ abbrev Sigma.desc {f : β → C} [HasCoproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ∐ f ⟶ P := colimit.desc _ (Cofan.mk P p) @[reassoc] theorem Sigma.ι_desc {β : Type w} {f : β → C} [HasCoproduct f] {P : C} (p : ∀ b, f b ⟶ P) (b : β) : Sigma.ι f b ≫ Sigma.desc p = p b := by simp only [colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] instance {f : β → C} [HasCoproduct f] : IsIso (Sigma.desc (fun a ↦ Sigma.ι f a)) := by convert IsIso.id _ ext simp /-- A version of `Cocones.ext` for `Cofan`s. -/ @[simps!] def Cofan.ext {f : β → C} {c₁ c₂ : Cofan f} (e : c₁.pt ≅ c₂.pt) (w : ∀ (b : β), c₁.inj b ≫ e.hom = c₂.inj b := by cat_disch) : c₁ ≅ c₂ := Cocones.ext e (fun ⟨j⟩ => w j) /-- A cofan `c` on `f` such that the induced map `∐ f ⟶ c.pt` is an iso, is a coproduct. -/ def Cofan.isColimitOfIsIsoSigmaDesc {f : β → C} [HasCoproduct f] (c : Cofan f) [hc : IsIso (Sigma.desc c.inj)] : IsColimit c := IsColimit.ofIsoColimit (colimit.isColimit (Discrete.functor f)) (Cofan.ext (@asIso _ _ _ _ _ hc) (fun _ => colimit.ι_desc _ _)) lemma Cofan.isColimit_iff_isIso_sigmaDesc {f : β → C} [HasCoproduct f] (c : Cofan f) : IsIso (Sigma.desc c.inj) ↔ Nonempty (IsColimit c) := by refine ⟨fun h ↦ ⟨isColimitOfIsIsoSigmaDesc c⟩, fun ⟨hc⟩ ↦ ?_⟩ have : IsIso (((coproductIsCoproduct f).coconePointUniqueUpToIso hc).hom ≫ hc.desc c) := by simp; infer_instance convert this ext simp only [colimit.ι_desc, mk_pt, mk_ι_app, IsColimit.coconePointUniqueUpToIso, coproductIsCoproduct, colimit.cocone_x, Functor.mapIso_hom, IsColimit.uniqueUpToIso_hom, Cocones.forget_map, IsColimit.descCoconeMorphism_hom, IsColimit.ofIsoColimit_desc, Cocones.ext_inv_hom, Iso.refl_inv, colimit.isColimit_desc, Category.id_comp, IsColimit.desc_self, Category.comp_id] rfl /-- A coproduct of coproducts is a coproduct -/ def Cofan.isColimitTrans {X : α → C} (c : Cofan X) (hc : IsColimit c) {β : α → Type*} {Y : (a : α) → β a → C} (π : (a : α) → (b : β a) → Y a b ⟶ X a) (hs : ∀ a, IsColimit (Cofan.mk (X a) (π a))) : IsColimit (Cofan.mk (f := fun ⟨a,b⟩ => Y a b) c.pt (fun (⟨a, b⟩ : Σ a, _) ↦ π a b ≫ c.inj a)) := by refine mkCofanColimit _ ?_ ?_ ?_ · exact fun t ↦ hc.desc (Cofan.mk _ fun a ↦ (hs a).desc (Cofan.mk t.pt (fun b ↦ t.inj ⟨a, b⟩))) · intro t ⟨a, b⟩ simp only [mk_pt, cofan_mk_inj, Category.assoc] erw [hc.fac, (hs a).fac] rfl · intro t m h refine hc.hom_ext fun ⟨a⟩ ↦ (hs a).hom_ext fun ⟨b⟩ ↦ ?_ erw [hc.fac, (hs a).fac] simpa using h ⟨a, b⟩ /-- Construct a morphism between categorical products (indexed by the same type) from a family of morphisms between the factors. -/ abbrev Pi.map {f g : β → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b) : ∏ᶜ f ⟶ ∏ᶜ g := limMap (Discrete.natTrans fun X => p X.as) @[simp] lemma Pi.map_id {f : α → C} [HasProduct f] : Pi.map (fun a => 𝟙 (f a)) = 𝟙 (∏ᶜ f) := by ext; simp lemma Pi.map_comp_map {f g h : α → C} [HasProduct f] [HasProduct g] [HasProduct h] (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (a : α), g a ⟶ h a) : Pi.map q ≫ Pi.map q' = Pi.map (fun a => q a ≫ q' a) := by ext; simp instance Pi.map_mono {f g : β → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b) [∀ i, Mono (p i)] : Mono <| Pi.map p := @Limits.limMap_mono _ _ _ _ (Discrete.functor f) (Discrete.functor g) _ _ (Discrete.natTrans fun X => p X.as) (by dsimp; infer_instance) /-- Construct a morphism between categorical products from a family of morphisms between the factors. -/ def Pi.map' {f : α → C} {g : β → C} [HasProduct f] [HasProduct g] (p : β → α) (q : ∀ (b : β), f (p b) ⟶ g b) : ∏ᶜ f ⟶ ∏ᶜ g := Pi.lift (fun a => Pi.π _ _ ≫ q a) @[reassoc (attr := simp)] lemma Pi.map'_comp_π {f : α → C} {g : β → C} [HasProduct f] [HasProduct g] (p : β → α) (q : ∀ (b : β), f (p b) ⟶ g b) (b : β) : Pi.map' p q ≫ Pi.π g b = Pi.π f (p b) ≫ q b := limit.lift_π _ _ lemma Pi.map'_id_id {f : α → C} [HasProduct f] : Pi.map' id (fun a => 𝟙 (f a)) = 𝟙 (∏ᶜ f) := by ext; simp @[simp] lemma Pi.map'_id {f g : α → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b) : Pi.map' id p = Pi.map p := rfl lemma Pi.map'_comp_map' {f : α → C} {g : β → C} {h : γ → C} [HasProduct f] [HasProduct g] [HasProduct h] (p : β → α) (p' : γ → β) (q : ∀ (b : β), f (p b) ⟶ g b) (q' : ∀ (c : γ), g (p' c) ⟶ h c) : Pi.map' p q ≫ Pi.map' p' q' = Pi.map' (p ∘ p') (fun c => q (p' c) ≫ q' c) := by ext; simp lemma Pi.map'_comp_map {f : α → C} {g h : β → C} [HasProduct f] [HasProduct g] [HasProduct h] (p : β → α) (q : ∀ (b : β), f (p b) ⟶ g b) (q' : ∀ (b : β), g b ⟶ h b) : Pi.map' p q ≫ Pi.map q' = Pi.map' p (fun b => q b ≫ q' b) := by ext; simp lemma Pi.map_comp_map' {f g : α → C} {h : β → C} [HasProduct f] [HasProduct g] [HasProduct h] (p : β → α) (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (b : β), g (p b) ⟶ h b) : Pi.map q ≫ Pi.map' p q' = Pi.map' p (fun b => q (p b) ≫ q' b) := by ext; simp lemma Pi.map'_eq {f : α → C} {g : β → C} [HasProduct f] [HasProduct g] {p p' : β → α} {q : ∀ (b : β), f (p b) ⟶ g b} {q' : ∀ (b : β), f (p' b) ⟶ g b} (hp : p = p') (hq : ∀ (b : β), eqToHom (hp ▸ rfl) ≫ q b = q' b) : Pi.map' p q = Pi.map' p' q' := by cat_disch /-- Construct an isomorphism between categorical products (indexed by the same type) from a family of isomorphisms between the factors. -/ abbrev Pi.mapIso {f g : β → C} [HasProductsOfShape β C] (p : ∀ b, f b ≅ g b) : ∏ᶜ f ≅ ∏ᶜ g := lim.mapIso (Discrete.natIso fun X => p X.as) instance Pi.map_isIso {f g : β → C} [HasProductsOfShape β C] (p : ∀ b, f b ⟶ g b) [∀ b, IsIso <| p b] : IsIso <| Pi.map p := inferInstanceAs (IsIso (Pi.mapIso (fun b ↦ asIso (p b))).hom) section /- In this section, we provide some API for products when we are given a functor `Discrete α ⥤ C` instead of a map `α → C`. -/ variable (X : Discrete α ⥤ C) [HasProduct (fun j => X.obj (Discrete.mk j))] /-- A limit cone for `X : Discrete α ⥤ C` that is given by `∏ᶜ (fun j => X.obj (Discrete.mk j))`. -/ @[simps] def Pi.cone : Cone X where pt := ∏ᶜ (fun j => X.obj (Discrete.mk j)) π := Discrete.natTrans (fun _ => Pi.π _ _) /-- The cone `Pi.cone X` is a limit cone. -/ def productIsProduct' : IsLimit (Pi.cone X) where lift s := Pi.lift (fun j => s.π.app ⟨j⟩) fac s := by simp uniq s m hm := by dsimp ext simp only [limit.lift_π, Fan.mk_pt, Fan.mk_π_app] apply hm variable [HasLimit X] /-- The isomorphism `∏ᶜ (fun j => X.obj (Discrete.mk j)) ≅ limit X`. -/ def Pi.isoLimit : ∏ᶜ (fun j => X.obj (Discrete.mk j)) ≅ limit X := IsLimit.conePointUniqueUpToIso (productIsProduct' X) (limit.isLimit X) @[reassoc (attr := simp)] lemma Pi.isoLimit_inv_π (j : α) : (Pi.isoLimit X).inv ≫ Pi.π _ j = limit.π _ (Discrete.mk j) := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ @[reassoc (attr := simp)] lemma Pi.isoLimit_hom_π (j : α) : (Pi.isoLimit X).hom ≫ limit.π _ (Discrete.mk j) = Pi.π _ j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ end /-- Construct a morphism between categorical coproducts (indexed by the same type) from a family of morphisms between the factors. -/ abbrev Sigma.map {f g : β → C} [HasCoproduct f] [HasCoproduct g] (p : ∀ b, f b ⟶ g b) : ∐ f ⟶ ∐ g := colimMap (Discrete.natTrans fun X => p X.as) @[simp] lemma Sigma.map_id {f : α → C} [HasCoproduct f] : Sigma.map (fun a => 𝟙 (f a)) = 𝟙 (∐ f) := by ext; simp lemma Sigma.map_comp_map {f g h : α → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (a : α), g a ⟶ h a) : Sigma.map q ≫ Sigma.map q' = Sigma.map (fun a => q a ≫ q' a) := by ext; simp instance Sigma.map_epi {f g : β → C} [HasCoproduct f] [HasCoproduct g] (p : ∀ b, f b ⟶ g b) [∀ i, Epi (p i)] : Epi <| Sigma.map p := @Limits.colimMap_epi _ _ _ _ (Discrete.functor f) (Discrete.functor g) _ _ (Discrete.natTrans fun X => p X.as) (by dsimp; infer_instance) /-- Construct a morphism between categorical coproducts from a family of morphisms between the factors. -/ def Sigma.map' {f : α → C} {g : β → C} [HasCoproduct f] [HasCoproduct g] (p : α → β) (q : ∀ (a : α), f a ⟶ g (p a)) : ∐ f ⟶ ∐ g := Sigma.desc (fun a => q a ≫ Sigma.ι _ _) @[reassoc (attr := simp)] lemma Sigma.ι_comp_map' {f : α → C} {g : β → C} [HasCoproduct f] [HasCoproduct g] (p : α → β) (q : ∀ (a : α), f a ⟶ g (p a)) (a : α) : Sigma.ι f a ≫ Sigma.map' p q = q a ≫ Sigma.ι g (p a) := colimit.ι_desc _ _ lemma Sigma.map'_id_id {f : α → C} [HasCoproduct f] : Sigma.map' id (fun a => 𝟙 (f a)) = 𝟙 (∐ f) := by ext; simp @[simp] lemma Sigma.map'_id {f g : α → C} [HasCoproduct f] [HasCoproduct g] (p : ∀ b, f b ⟶ g b) : Sigma.map' id p = Sigma.map p := rfl lemma Sigma.map'_comp_map' {f : α → C} {g : β → C} {h : γ → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (p : α → β) (p' : β → γ) (q : ∀ (a : α), f a ⟶ g (p a)) (q' : ∀ (b : β), g b ⟶ h (p' b)) : Sigma.map' p q ≫ Sigma.map' p' q' = Sigma.map' (p' ∘ p) (fun a => q a ≫ q' (p a)) := by ext; simp lemma Sigma.map'_comp_map {f : α → C} {g h : β → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (p : α → β) (q : ∀ (a : α), f a ⟶ g (p a)) (q' : ∀ (b : β), g b ⟶ h b) : Sigma.map' p q ≫ Sigma.map q' = Sigma.map' p (fun a => q a ≫ q' (p a)) := by ext; simp lemma Sigma.map_comp_map' {f g : α → C} {h : β → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (p : α → β) (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (a : α), g a ⟶ h (p a)) : Sigma.map q ≫ Sigma.map' p q' = Sigma.map' p (fun a => q a ≫ q' a) := by ext; simp lemma Sigma.map'_eq {f : α → C} {g : β → C} [HasCoproduct f] [HasCoproduct g] {p p' : α → β} {q : ∀ (a : α), f a ⟶ g (p a)} {q' : ∀ (a : α), f a ⟶ g (p' a)} (hp : p = p') (hq : ∀ (a : α), q a ≫ eqToHom (hp ▸ rfl) = q' a) : Sigma.map' p q = Sigma.map' p' q' := by cat_disch /-- Construct an isomorphism between categorical coproducts (indexed by the same type) from a family of isomorphisms between the factors. -/ abbrev Sigma.mapIso {f g : β → C} [HasCoproductsOfShape β C] (p : ∀ b, f b ≅ g b) : ∐ f ≅ ∐ g := colim.mapIso (Discrete.natIso fun X => p X.as) instance Sigma.map_isIso {f g : β → C} [HasCoproductsOfShape β C] (p : ∀ b, f b ⟶ g b) [∀ b, IsIso <| p b] : IsIso (Sigma.map p) := inferInstanceAs (IsIso (Sigma.mapIso (fun b ↦ asIso (p b))).hom) section /- In this section, we provide some API for coproducts when we are given a functor `Discrete α ⥤ C` instead of a map `α → C`. -/ variable (X : Discrete α ⥤ C) [HasCoproduct (fun j => X.obj (Discrete.mk j))] /-- A colimit cocone for `X : Discrete α ⥤ C` that is given by `∐ (fun j => X.obj (Discrete.mk j))`. -/ @[simps] def Sigma.cocone : Cocone X where pt := ∐ (fun j => X.obj (Discrete.mk j)) ι := Discrete.natTrans (fun _ => Sigma.ι (fun j ↦ X.obj ⟨j⟩) _) /-- The cocone `Sigma.cocone X` is a colimit cocone. -/ def coproductIsCoproduct' : IsColimit (Sigma.cocone X) where desc s := Sigma.desc (fun j => s.ι.app ⟨j⟩) fac s := by simp uniq s m hm := by dsimp ext simp only [colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] apply hm variable [HasColimit X] /-- The isomorphism `∐ (fun j => X.obj (Discrete.mk j)) ≅ colimit X`. -/ def Sigma.isoColimit : ∐ (fun j => X.obj (Discrete.mk j)) ≅ colimit X := IsColimit.coconePointUniqueUpToIso (coproductIsCoproduct' X) (colimit.isColimit X) @[reassoc (attr := simp)] lemma Sigma.ι_isoColimit_hom (j : α) : Sigma.ι _ j ≫ (Sigma.isoColimit X).hom = colimit.ι _ (Discrete.mk j) := IsColimit.comp_coconePointUniqueUpToIso_hom (coproductIsCoproduct' X) _ _ @[reassoc (attr := simp)] lemma Sigma.ι_isoColimit_inv (j : α) : colimit.ι _ ⟨j⟩ ≫ (Sigma.isoColimit X).inv = Sigma.ι (fun j ↦ X.obj ⟨j⟩) _ := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _ end /-- Two products which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. -/ @[simps] def Pi.whiskerEquiv {J K : Type*} {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasProduct f] [HasProduct g] : ∏ᶜ f ≅ ∏ᶜ g where hom := Pi.map' e.symm fun k => (w (e.symm k)).inv ≫ eqToHom (by simp) inv := Pi.map' e fun j => (w j).hom /-- Two coproducts which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. -/ @[simps] def Sigma.whiskerEquiv {J K : Type*} {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasCoproduct f] [HasCoproduct g] : ∐ f ≅ ∐ g where hom := Sigma.map' e fun j => (w j).inv inv := Sigma.map' e.symm fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom instance {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasProduct (g i)] [HasProduct fun i => ∏ᶜ g i] : HasProduct fun p : Σ i, f i => g p.1 p.2 where exists_limit := Nonempty.intro { cone := Fan.mk (∏ᶜ fun i => ∏ᶜ g i) (fun X => Pi.π (fun i => ∏ᶜ g i) X.1 ≫ Pi.π (g X.1) X.2) isLimit := mkFanLimit _ (fun s => Pi.lift fun b => Pi.lift fun c => s.proj ⟨b, c⟩) (by simp) (by intro s (m : _ ⟶ (∏ᶜ fun i ↦ ∏ᶜ g i)) w; aesop (add norm simp Sigma.forall)) } /-- An iterated product is a product over a sigma type. -/ @[simps] def piPiIso {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasProduct (g i)] [HasProduct fun i => ∏ᶜ g i] : (∏ᶜ fun i => ∏ᶜ g i) ≅ (∏ᶜ fun p : Σ i, f i => g p.1 p.2) where hom := Pi.lift fun ⟨i, x⟩ => Pi.π _ i ≫ Pi.π _ x inv := Pi.lift fun i => Pi.lift fun x => Pi.π _ (⟨i, x⟩ : Σ i, f i) instance {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasCoproduct (g i)] [HasCoproduct fun i => ∐ g i] : HasCoproduct fun p : Σ i, f i => g p.1 p.2 where exists_colimit := Nonempty.intro { cocone := Cofan.mk (∐ fun i => ∐ g i) (fun X => Sigma.ι (g X.1) X.2 ≫ Sigma.ι (fun i => ∐ g i) X.1) isColimit := mkCofanColimit _ (fun s => Sigma.desc fun b => Sigma.desc fun c => s.inj ⟨b, c⟩) (by simp) (by intro s (m : (∐ fun i ↦ ∐ g i) ⟶ _) w; aesop_cat (add norm simp Sigma.forall)) } /-- An iterated coproduct is a coproduct over a sigma type. -/ @[simps] def sigmaSigmaIso {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasCoproduct (g i)] [HasCoproduct fun i => ∐ g i] : (∐ fun i => ∐ g i) ≅ (∐ fun p : Σ i, f i => g p.1 p.2) where hom := Sigma.desc fun i => Sigma.desc fun x => Sigma.ι (fun p : Σ i, f i => g p.1 p.2) ⟨i, x⟩ inv := Sigma.desc fun ⟨i, x⟩ => Sigma.ι (g i) x ≫ Sigma.ι (fun i => ∐ g i) i section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) variable (f : β → C) /-- The comparison morphism for the product of `f`. This is an iso iff `G` preserves the product of `f`, see `PreservesProduct.ofIsoComparison`. -/ def piComparison [HasProduct f] [HasProduct fun b => G.obj (f b)] : G.obj (∏ᶜ f) ⟶ ∏ᶜ fun b => G.obj (f b) := Pi.lift fun b => G.map (Pi.π f b) @[reassoc (attr := simp)] theorem piComparison_comp_π [HasProduct f] [HasProduct fun b => G.obj (f b)] (b : β) : piComparison G f ≫ Pi.π _ b = G.map (Pi.π f b) := limit.lift_π _ (Discrete.mk b) @[reassoc (attr := simp)] theorem map_lift_piComparison [HasProduct f] [HasProduct fun b => G.obj (f b)] (P : C) (g : ∀ j, P ⟶ f j) : G.map (Pi.lift g) ≫ piComparison G f = Pi.lift fun j => G.map (g j) := by ext j simp only [Category.assoc, piComparison_comp_π, ← G.map_comp, limit.lift_π, Fan.mk_pt, Fan.mk_π_app] /-- The comparison morphism for the coproduct of `f`. This is an iso iff `G` preserves the coproduct of `f`, see `PreservesCoproduct.ofIsoComparison`. -/ def sigmaComparison [HasCoproduct f] [HasCoproduct fun b => G.obj (f b)] : ∐ (fun b => G.obj (f b)) ⟶ G.obj (∐ f) := Sigma.desc fun b => G.map (Sigma.ι f b) @[reassoc (attr := simp)] theorem ι_comp_sigmaComparison [HasCoproduct f] [HasCoproduct fun b => G.obj (f b)] (b : β) : Sigma.ι _ b ≫ sigmaComparison G f = G.map (Sigma.ι f b) := colimit.ι_desc _ (Discrete.mk b) @[reassoc (attr := simp)] theorem sigmaComparison_map_desc [HasCoproduct f] [HasCoproduct fun b => G.obj (f b)] (P : C) (g : ∀ j, f j ⟶ P) : sigmaComparison G f ≫ G.map (Sigma.desc g) = Sigma.desc fun j => G.map (g j) := by ext j simp only [ι_comp_sigmaComparison_assoc, ← G.map_comp, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] end Comparison variable (C) /-- An abbreviation for `Π J, HasLimitsOfShape (Discrete J) C` -/ abbrev HasProducts := ∀ J : Type w, HasLimitsOfShape (Discrete J) C /-- An abbreviation for `Π J, HasColimitsOfShape (Discrete J) C` -/ abbrev HasCoproducts := ∀ J : Type w, HasColimitsOfShape (Discrete J) C variable {C} lemma hasProducts_shrink [HasProducts.{max w w'} C] : HasProducts.{w} C := fun J => hasLimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift : Discrete (ULift.{w'} J) ≌ _) lemma hasCoproducts_shrink [HasCoproducts.{max w w'} C] : HasCoproducts.{w} C := fun J => hasColimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift : Discrete (ULift.{w'} J) ≌ _) theorem has_smallest_products_of_hasProducts [HasProducts.{w} C] : HasProducts.{0} C := hasProducts_shrink theorem has_smallest_coproducts_of_hasCoproducts [HasCoproducts.{w} C] : HasCoproducts.{0} C := hasCoproducts_shrink theorem hasProducts_of_limit_fans (lf : ∀ {J : Type w} (f : J → C), Fan f) (lf_isLimit : ∀ {J : Type w} (f : J → C), IsLimit (lf f)) : HasProducts.{w} C := fun _ : Type w => { has_limit := fun F => HasLimit.mk ⟨(Cones.postcompose Discrete.natIsoFunctor.inv).obj (lf fun j => F.obj ⟨j⟩), (IsLimit.postcomposeInvEquiv _ _).symm (lf_isLimit _)⟩ } theorem hasCoproducts_of_colimit_cofans (cf : ∀ {J : Type w} (f : J → C), Cofan f) (cf_isColimit : ∀ {J : Type w} (f : J → C), IsColimit (cf f)) : HasCoproducts.{w} C := fun _ : Type w => { has_colimit := fun F => HasColimit.mk ⟨(Cocones.precompose Discrete.natIsoFunctor.hom).obj (cf fun j => F.obj ⟨j⟩), (IsColimit.precomposeHomEquiv _ _).symm (cf_isColimit _)⟩ } instance (priority := 100) hasProductsOfShape_of_hasProducts [HasProducts.{w} C] (J : Type w) : HasProductsOfShape J C := inferInstance instance (priority := 100) hasCoproductsOfShape_of_hasCoproducts [HasCoproducts.{w} C] (J : Type w) : HasCoproductsOfShape J C := inferInstance open Opposite in /-- The functor sending `(X, n)` to the product of copies of `X` indexed by `n`. -/ @[simps] def piConst [Limits.HasProducts.{w} C] : C ⥤ Type wᵒᵖ ⥤ C where obj X := { obj n := ∏ᶜ fun _ : (unop n) ↦ X, map f := Limits.Pi.map' f.unop fun _ ↦ 𝟙 _ } map f := { app n := Limits.Pi.map fun _ ↦ f } /-- `n ↦ ∏ₙ X` is left adjoint to `Hom(-, X)`. -/ def piConstAdj [Limits.HasProducts.{v} C] (X : C) : (piConst.obj X).rightOp ⊣ yoneda.obj X where unit := { app n i := Limits.Pi.π (fun _ : n ↦ X) i } counit := { app Y := (Limits.Pi.lift id).op, naturality _ _ _ := by apply Quiver.Hom.unop_inj; cat_disch } left_triangle_components _ := by apply Quiver.Hom.unop_inj; cat_disch /-- The functor sending `(X, n)` to the coproduct of copies of `X` indexed by `n`. -/ @[simps] def sigmaConst [Limits.HasCoproducts.{w} C] : C ⥤ Type w ⥤ C where obj X := { obj n := ∐ fun _ : n ↦ X, map f := Limits.Sigma.map' f fun _ ↦ 𝟙 _ } map f := { app n := Limits.Sigma.map fun _ ↦ f } /-- `n ↦ ∐ₙ X` is left adjoint to `Hom(X, -)`. -/ def sigmaConstAdj [Limits.HasCoproducts.{v} C] (X : C) : sigmaConst.obj X ⊣ coyoneda.obj (Opposite.op X) where unit := { app n i := Limits.Sigma.ι (fun _ : n ↦ X) i } counit := { app Y := Limits.Sigma.desc id } /-! (Co)products over a type with a unique term. -/ section Unique /-- The limit cone for the product over an index type with exactly one term. -/ @[simps] def limitConeOfUnique [Unique β] (f : β → C) : LimitCone (Discrete.functor f) where cone := { pt := f default π := Discrete.natTrans (fun ⟨j⟩ => eqToHom (by dsimp congr subsingleton)) } isLimit := { lift := fun s => s.π.app default fac := fun s j => by have h := Subsingleton.elim j default subst h simp uniq := fun s m w => by specialize w default simpa using w } instance (priority := 100) hasProduct_unique [Nonempty β] [Subsingleton β] (f : β → C) : HasProduct f := let ⟨_⟩ := nonempty_unique β; HasLimit.mk (limitConeOfUnique f) /-- A product over an index type with exactly one term is just the object over that term. -/ @[simps!] def productUniqueIso [Unique β] (f : β → C) : ∏ᶜ f ≅ f default := IsLimit.conePointUniqueUpToIso (limit.isLimit _) (limitConeOfUnique f).isLimit /-- The colimit cocone for the coproduct over an index type with exactly one term. -/ @[simps] def colimitCoconeOfUnique [Unique β] (f : β → C) : ColimitCocone (Discrete.functor f) where cocone := { pt := f default ι := Discrete.natTrans (fun ⟨j⟩ => eqToHom (by dsimp congr subsingleton)) } isColimit := { desc := fun s => s.ι.app default fac := fun s j => by have h := Subsingleton.elim j default subst h apply Category.id_comp uniq := fun s m w => by specialize w default simp_all } instance (priority := 100) hasCoproduct_unique [Nonempty β] [Subsingleton β] (f : β → C) : HasCoproduct f := let ⟨_⟩ := nonempty_unique β; HasColimit.mk (colimitCoconeOfUnique f) /-- A coproduct over an index type with exactly one term is just the object over that term. -/ @[simps!] def coproductUniqueIso [Unique β] (f : β → C) : ∐ f ≅ f default := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (colimitCoconeOfUnique f).isColimit end Unique section Reindex variable {γ : Type w'} (ε : β ≃ γ) (f : γ → C) section variable [HasProduct f] [HasProduct (f ∘ ε)] /-- Reindex a categorical product via an equivalence of the index types. -/ def Pi.reindex : piObj (f ∘ ε) ≅ piObj f := HasLimit.isoOfEquivalence (Discrete.equivalence ε) (Discrete.natIso fun _ => Iso.refl _) @[reassoc (attr := simp)] theorem Pi.reindex_hom_π (b : β) : (Pi.reindex ε f).hom ≫ Pi.π f (ε b) = Pi.π (f ∘ ε) b := by dsimp [Pi.reindex] simp only [HasLimit.isoOfEquivalence_hom_π, Discrete.equivalence_inverse, Discrete.functor_obj, Function.comp_apply, Functor.id_obj, Discrete.equivalence_functor, Functor.comp_obj, Discrete.natIso_inv_app, Iso.refl_inv, Category.id_comp] exact limit.w (Discrete.functor (f ∘ ε)) (Discrete.eqToHom' (ε.symm_apply_apply b)) @[reassoc (attr := simp)] theorem Pi.reindex_inv_π (b : β) : (Pi.reindex ε f).inv ≫ Pi.π (f ∘ ε) b = Pi.π f (ε b) := by simp [Iso.inv_comp_eq] end section variable [HasCoproduct f] [HasCoproduct (f ∘ ε)] /-- Reindex a categorical coproduct via an equivalence of the index types. -/ def Sigma.reindex : sigmaObj (f ∘ ε) ≅ sigmaObj f := HasColimit.isoOfEquivalence (Discrete.equivalence ε) (Discrete.natIso fun _ => Iso.refl _) @[reassoc (attr := simp)] theorem Sigma.ι_reindex_hom (b : β) : Sigma.ι (f ∘ ε) b ≫ (Sigma.reindex ε f).hom = Sigma.ι f (ε b) := by dsimp [Sigma.reindex] simp only [HasColimit.isoOfEquivalence_hom_π, Functor.id_obj, Discrete.functor_obj, Function.comp_apply, Discrete.equivalence_functor, Discrete.equivalence_inverse, Functor.comp_obj, Discrete.natIso_inv_app, Iso.refl_inv, Category.id_comp] have h := colimit.w (Discrete.functor f) (Discrete.eqToHom' (ε.apply_symm_apply (ε b))) simp only [Discrete.functor_obj] at h erw [← h, eqToHom_map, eqToHom_map, eqToHom_trans_assoc] all_goals { simp } @[reassoc (attr := simp)] theorem Sigma.ι_reindex_inv (b : β) : Sigma.ι f (ε b) ≫ (Sigma.reindex ε f).inv = Sigma.ι (f ∘ ε) b := by simp [Iso.comp_inv_eq] end end Reindex section variable {J : Type u₂} [Category.{v₂} J] (F : J ⥤ C) instance [HasLimit F] [HasProduct F.obj] : Mono (Pi.lift (limit.π F)) where right_cancellation _ _ h := by refine limit.hom_ext fun j => ?_ simpa using h =≫ Pi.π _ j instance [HasColimit F] [HasCoproduct F.obj] : Epi (Sigma.desc (colimit.ι F)) where left_cancellation _ _ h := by refine colimit.hom_ext fun j => ?_ simpa using Sigma.ι _ j ≫= h end section Fubini variable {ι ι' : Type*} {X : ι → ι' → C} /-- A product over products is a product indexed by a product. -/ def Fan.IsLimit.prod (c : ∀ i : ι, Fan (fun j : ι' ↦ X i j)) (hc : ∀ i : ι, IsLimit (c i)) (c' : Fan (fun i : ι ↦ (c i).pt)) (hc' : IsLimit c') : (IsLimit <| Fan.mk c'.pt fun p : ι × ι' ↦ c'.proj _ ≫ (c p.1).proj p.2) := by refine mkFanLimit _ (fun t ↦ ?_) ?_ fun t m hm ↦ ?_ · exact Fan.IsLimit.desc hc' fun i ↦ Fan.IsLimit.desc (hc i) fun j ↦ t.proj (i, j) · simp · refine Fan.IsLimit.hom_ext hc' _ _ fun i ↦ ?_ exact Fan.IsLimit.hom_ext (hc i) _ _ fun j ↦ (by simpa using hm (i, j)) /-- A coproduct over coproducts is a coproduct indexed by a product. -/ def Cofan.IsColimit.prod (c : ∀ i : ι, Cofan (fun j : ι' ↦ X i j)) (hc : ∀ i : ι, IsColimit (c i)) (c' : Cofan (fun i : ι ↦ (c i).pt)) (hc' : IsColimit c') : (IsColimit <| Cofan.mk c'.pt fun p : ι × ι' ↦ (c p.1).inj p.2 ≫ c'.inj _) := by refine mkCofanColimit _ (fun t ↦ ?_) ?_ fun t m hm ↦ ?_ · exact Cofan.IsColimit.desc hc' fun i ↦ Cofan.IsColimit.desc (hc i) fun j ↦ t.inj (i, j) · simp · refine Cofan.IsColimit.hom_ext hc' _ _ fun i ↦ ?_ exact Cofan.IsColimit.hom_ext (hc i) _ _ fun j ↦ (by simpa using hm (i, j)) end Fubini end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/RegularMono.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.Lean.Expr.Basic /-! # Definitions and basic properties of regular monomorphisms and epimorphisms. A regular monomorphism is a morphism that is the equalizer of some parallel pair. We give the constructions * `IsSplitMono → RegularMono` and * `RegularMono → Mono` as well as the dual constructions for regular epimorphisms. Additionally, we give the construction * `RegularEpi ⟶ StrongEpi`. We also define classes `IsRegularMonoCategory` and `IsRegularEpiCategory` for categories in which every monomorphism or epimorphism is regular, and deduce that these categories are `StrongMonoCategory`s resp. `StrongEpiCategory`s. -/ noncomputable section namespace CategoryTheory open CategoryTheory.Limits universe v₁ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] variable {X Y : C} /-- A regular monomorphism is a morphism which is the equalizer of some parallel pair. -/ class RegularMono (f : X ⟶ Y) where /-- An object in `C` -/ Z : C /-- A map from the codomain of `f` to `Z` -/ left : Y ⟶ Z /-- Another map from the codomain of `f` to `Z` -/ right : Y ⟶ Z /-- `f` equalizes the two maps -/ w : f ≫ left = f ≫ right := by cat_disch /-- `f` is the equalizer of the two maps -/ isLimit : IsLimit (Fork.ofι f w) attribute [reassoc] RegularMono.w /-- Every regular monomorphism is a monomorphism. -/ instance (priority := 100) RegularMono.mono (f : X ⟶ Y) [RegularMono f] : Mono f := mono_of_isLimit_fork RegularMono.isLimit instance equalizerRegular (g h : X ⟶ Y) [HasLimit (parallelPair g h)] : RegularMono (equalizer.ι g h) where Z := Y left := g right := h w := equalizer.condition g h isLimit := Fork.IsLimit.mk _ (fun s => limit.lift _ s) (by simp) fun s m w => by apply equalizer.hom_ext simp [← w] /-- Every split monomorphism is a regular monomorphism. -/ instance (priority := 100) RegularMono.ofIsSplitMono (f : X ⟶ Y) [IsSplitMono f] : RegularMono f where Z := Y left := 𝟙 Y right := retraction f ≫ f isLimit := isSplitMonoEqualizes f /-- If `f` is a regular mono, then any map `k : W ⟶ Y` equalizing `RegularMono.left` and `RegularMono.right` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def RegularMono.lift' {W : C} (f : X ⟶ Y) [RegularMono f] (k : W ⟶ Y) (h : k ≫ (RegularMono.left : Y ⟶ @RegularMono.Z _ _ _ _ f _) = k ≫ RegularMono.right) : { l : W ⟶ X // l ≫ f = k } := Fork.IsLimit.lift' RegularMono.isLimit _ h /-- The second leg of a pullback cone is a regular monomorphism if the right component is too. See also `Pullback.sndOfMono` for the basic monomorphism version, and `regularOfIsPullbackFstOfRegular` for the flipped version. -/ def regularOfIsPullbackSndOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [hr : RegularMono h] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : RegularMono g where Z := hr.Z left := k ≫ hr.left right := k ≫ hr.right w := by repeat (rw [← Category.assoc, ← eq_whisker comm]) simp only [Category.assoc, hr.w] isLimit := by apply Fork.IsLimit.mk' _ _ intro s have l₁ : (Fork.ι s ≫ k) ≫ RegularMono.left = (Fork.ι s ≫ k) ≫ hr.right := by rw [Category.assoc, s.condition, Category.assoc] obtain ⟨l, hl⟩ := Fork.IsLimit.lift' hr.isLimit _ l₁ obtain ⟨p, _, hp₂⟩ := PullbackCone.IsLimit.lift' t _ _ hl refine ⟨p, hp₂, ?_⟩ intro m w have z : m ≫ g = p ≫ g := w.trans hp₂.symm apply t.hom_ext apply (PullbackCone.mk f g comm).equalizer_ext · erw [← cancel_mono h, Category.assoc, Category.assoc, comm] simp only [← Category.assoc, eq_whisker z] · exact z /-- The first leg of a pullback cone is a regular monomorphism if the left component is too. See also `Pullback.fstOfMono` for the basic monomorphism version, and `regularOfIsPullbackSndOfRegular` for the flipped version. -/ def regularOfIsPullbackFstOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [RegularMono k] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : RegularMono f := regularOfIsPullbackSndOfRegular comm.symm (PullbackCone.flipIsLimit t) instance (priority := 100) strongMono_of_regularMono (f : X ⟶ Y) [RegularMono f] : StrongMono f := StrongMono.mk' (by intro A B z hz u v sq have : v ≫ (RegularMono.left : Y ⟶ RegularMono.Z f) = v ≫ RegularMono.right := by apply (cancel_epi z).1 repeat (rw [← Category.assoc, ← eq_whisker sq.w]) simp only [Category.assoc, RegularMono.w] obtain ⟨t, ht⟩ := RegularMono.lift' _ _ this refine CommSq.HasLift.mk' ⟨t, (cancel_mono f).1 ?_, ht⟩ simp only [Category.assoc, ht, sq.w]) /-- A regular monomorphism is an isomorphism if it is an epimorphism. -/ theorem isIso_of_regularMono_of_epi (f : X ⟶ Y) [RegularMono f] [Epi f] : IsIso f := isIso_of_epi_of_strongMono _ section variable (C) /-- A regular mono category is a category in which every monomorphism is regular. -/ class IsRegularMonoCategory : Prop where /-- Every monomorphism is a regular monomorphism -/ regularMonoOfMono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], Nonempty (RegularMono f) end /-- In a category in which every monomorphism is regular, we can express every monomorphism as an equalizer. This is not an instance because it would create an instance loop. -/ def regularMonoOfMono [IsRegularMonoCategory C] (f : X ⟶ Y) [Mono f] : RegularMono f := (IsRegularMonoCategory.regularMonoOfMono _).some instance (priority := 100) regularMonoCategoryOfSplitMonoCategory [SplitMonoCategory C] : IsRegularMonoCategory C where regularMonoOfMono f _ := ⟨by haveI := isSplitMono_of_mono f infer_instance⟩ instance (priority := 100) strongMonoCategory_of_regularMonoCategory [IsRegularMonoCategory C] : StrongMonoCategory C where strongMono_of_mono f _ := by haveI := regularMonoOfMono f infer_instance /-- A regular epimorphism is a morphism which is the coequalizer of some parallel pair. -/ class RegularEpi (f : X ⟶ Y) where /-- An object from `C` -/ W : C /-- Two maps to the domain of `f` -/ (left right : W ⟶ X) /-- `f` coequalizes the two maps -/ w : left ≫ f = right ≫ f := by cat_disch /-- `f` is the coequalizer -/ isColimit : IsColimit (Cofork.ofπ f w) attribute [reassoc] RegularEpi.w /-- Every regular epimorphism is an epimorphism. -/ instance (priority := 100) RegularEpi.epi (f : X ⟶ Y) [RegularEpi f] : Epi f := epi_of_isColimit_cofork RegularEpi.isColimit instance coequalizerRegular (g h : X ⟶ Y) [HasColimit (parallelPair g h)] : RegularEpi (coequalizer.π g h) where W := X left := g right := h w := coequalizer.condition g h isColimit := Cofork.IsColimit.mk _ (fun s => colimit.desc _ s) (by simp) fun s m w => by apply coequalizer.hom_ext simp [← w] /-- A morphism which is a coequalizer for its kernel pair is a regular epi. -/ noncomputable def regularEpiOfKernelPair {B X : C} (f : X ⟶ B) [HasPullback f f] (hc : IsColimit (Cofork.ofπ f pullback.condition)) : RegularEpi f where W := pullback f f left := pullback.fst f f right := pullback.snd f f w := pullback.condition isColimit := hc /-- Every split epimorphism is a regular epimorphism. -/ instance (priority := 100) RegularEpi.ofSplitEpi (f : X ⟶ Y) [IsSplitEpi f] : RegularEpi f where W := X left := 𝟙 X right := f ≫ section_ f isColimit := isSplitEpiCoequalizes f /-- If `f` is a regular epi, then every morphism `k : X ⟶ W` coequalizing `RegularEpi.left` and `RegularEpi.right` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def RegularEpi.desc' {W : C} (f : X ⟶ Y) [RegularEpi f] (k : X ⟶ W) (h : (RegularEpi.left : RegularEpi.W f ⟶ X) ≫ k = RegularEpi.right ≫ k) : { l : Y ⟶ W // f ≫ l = k } := Cofork.IsColimit.desc' RegularEpi.isColimit _ h /-- The second leg of a pushout cocone is a regular epimorphism if the right component is too. See also `Pushout.sndOfEpi` for the basic epimorphism version, and `regularOfIsPushoutFstOfRegular` for the flipped version. -/ def regularOfIsPushoutSndOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [gr : RegularEpi g] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : RegularEpi h where W := gr.W left := gr.left ≫ f right := gr.right ≫ f w := by rw [Category.assoc, Category.assoc, comm]; simp only [← Category.assoc, eq_whisker gr.w] isColimit := by apply Cofork.IsColimit.mk' _ _ intro s have l₁ : gr.left ≫ f ≫ s.π = gr.right ≫ f ≫ s.π := by rw [← Category.assoc, ← Category.assoc, s.condition] obtain ⟨l, hl⟩ := Cofork.IsColimit.desc' gr.isColimit (f ≫ Cofork.π s) l₁ obtain ⟨p, hp₁, _⟩ := PushoutCocone.IsColimit.desc' t _ _ hl.symm refine ⟨p, hp₁, ?_⟩ intro m w have z := w.trans hp₁.symm apply t.hom_ext apply (PushoutCocone.mk _ _ comm).coequalizer_ext · exact z · erw [← cancel_epi g, ← Category.assoc, ← eq_whisker comm] erw [← Category.assoc, ← eq_whisker comm] dsimp at z; simp only [Category.assoc, z] /-- The first leg of a pushout cocone is a regular epimorphism if the left component is too. See also `Pushout.fstOfEpi` for the basic epimorphism version, and `regularOfIsPushoutSndOfRegular` for the flipped version. -/ def regularOfIsPushoutFstOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [RegularEpi f] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : RegularEpi k := regularOfIsPushoutSndOfRegular comm.symm (PushoutCocone.flipIsColimit t) instance (priority := 100) strongEpi_of_regularEpi (f : X ⟶ Y) [RegularEpi f] : StrongEpi f := StrongEpi.mk' (by intro A B z hz u v sq have : (RegularEpi.left : RegularEpi.W f ⟶ X) ≫ u = RegularEpi.right ≫ u := by apply (cancel_mono z).1 simp only [Category.assoc, sq.w, RegularEpi.w_assoc] obtain ⟨t, ht⟩ := RegularEpi.desc' f u this exact CommSq.HasLift.mk' ⟨t, ht, (cancel_epi f).1 (by simp only [← Category.assoc, ht, ← sq.w])⟩) /-- A regular epimorphism is an isomorphism if it is a monomorphism. -/ theorem isIso_of_regularEpi_of_mono (f : X ⟶ Y) [RegularEpi f] [Mono f] : IsIso f := isIso_of_mono_of_strongEpi _ section variable (C) /-- A regular epi category is a category in which every epimorphism is regular. -/ class IsRegularEpiCategory : Prop where /-- Everyone epimorphism is a regular epimorphism -/ regularEpiOfEpi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], Nonempty (RegularEpi f) end /-- In a category in which every epimorphism is regular, we can express every epimorphism as a coequalizer. This is not an instance because it would create an instance loop. -/ def regularEpiOfEpi [IsRegularEpiCategory C] (f : X ⟶ Y) [Epi f] : RegularEpi f := (IsRegularEpiCategory.regularEpiOfEpi _).some instance (priority := 100) regularEpiCategoryOfSplitEpiCategory [SplitEpiCategory C] : IsRegularEpiCategory C where regularEpiOfEpi f _ := ⟨by haveI := isSplitEpi_of_epi f infer_instance⟩ instance (priority := 100) strongEpiCategory_of_regularEpiCategory [IsRegularEpiCategory C] : StrongEpiCategory C where strongEpi_of_epi f _ := by haveI := regularEpiOfEpi f infer_instance end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Terminal.lean
import Mathlib.CategoryTheory.Limits.Shapes.IsTerminal import Mathlib.CategoryTheory.Limits.HasLimits /-! # Initial and terminal objects in a category. ## References * [Stacks: Initial and final objects](https://stacks.math.columbia.edu/tag/002B) -/ noncomputable section universe w w' v v₁ v₂ u u₁ u₂ open CategoryTheory namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable (C) /-- A category has a terminal object if it has a limit over the empty diagram. Use `hasTerminal_of_unique` to construct instances. -/ abbrev HasTerminal := HasLimitsOfShape (Discrete.{0} PEmpty) C /-- A category has an initial object if it has a colimit over the empty diagram. Use `hasInitial_of_unique` to construct instances. -/ abbrev HasInitial := HasColimitsOfShape (Discrete.{0} PEmpty) C section Univ variable (X : C) {F₁ : Discrete.{w} PEmpty ⥤ C} {F₂ : Discrete.{w'} PEmpty ⥤ C} theorem hasTerminalChangeDiagram (h : HasLimit F₁) : HasLimit F₂ := ⟨⟨⟨⟨limit F₁, by cat_disch, by simp⟩, isLimitChangeEmptyCone C (limit.isLimit F₁) _ (eqToIso rfl)⟩⟩⟩ theorem hasTerminalChangeUniverse [h : HasLimitsOfShape (Discrete.{w} PEmpty) C] : HasLimitsOfShape (Discrete.{w'} PEmpty) C where has_limit _ := hasTerminalChangeDiagram C (h.1 (Functor.empty C)) theorem hasInitialChangeDiagram (h : HasColimit F₁) : HasColimit F₂ := ⟨⟨⟨⟨colimit F₁, by cat_disch, by simp⟩, isColimitChangeEmptyCocone C (colimit.isColimit F₁) _ (eqToIso rfl)⟩⟩⟩ theorem hasInitialChangeUniverse [h : HasColimitsOfShape (Discrete.{w} PEmpty) C] : HasColimitsOfShape (Discrete.{w'} PEmpty) C where has_colimit _ := hasInitialChangeDiagram C (h.1 (Functor.empty C)) end Univ /-- An arbitrary choice of terminal object, if one exists. You can use the notation `⊤_ C`. This object is characterized by having a unique morphism from any object. -/ abbrev terminal [HasTerminal C] : C := limit (Functor.empty.{0} C) /-- An arbitrary choice of initial object, if one exists. You can use the notation `⊥_ C`. This object is characterized by having a unique morphism to any object. -/ abbrev initial [HasInitial C] : C := colimit (Functor.empty.{0} C) /-- Notation for the terminal object in `C` -/ notation "⊤_ " C:20 => terminal C /-- Notation for the initial object in `C` -/ notation "⊥_ " C:20 => initial C section variable {C} /-- We can more explicitly show that a category has a terminal object by specifying the object, and showing there is a unique morphism to it from any other object. -/ theorem hasTerminal_of_unique (X : C) [∀ Y, Nonempty (Y ⟶ X)] [∀ Y, Subsingleton (Y ⟶ X)] : HasTerminal C where has_limit F := .mk ⟨_, (isTerminalEquivUnique F X).invFun fun _ ↦ ⟨Classical.inhabited_of_nonempty', (Subsingleton.elim · _)⟩⟩ theorem IsTerminal.hasTerminal {X : C} (h : IsTerminal X) : HasTerminal C := { has_limit := fun F => HasLimit.mk ⟨⟨X, by cat_disch, by simp⟩, isLimitChangeEmptyCone _ h _ (Iso.refl _)⟩ } /-- We can more explicitly show that a category has an initial object by specifying the object, and showing there is a unique morphism from it to any other object. -/ theorem hasInitial_of_unique (X : C) [∀ Y, Nonempty (X ⟶ Y)] [∀ Y, Subsingleton (X ⟶ Y)] : HasInitial C where has_colimit F := .mk ⟨_, (isInitialEquivUnique F X).invFun fun _ ↦ ⟨Classical.inhabited_of_nonempty', (Subsingleton.elim · _)⟩⟩ theorem IsInitial.hasInitial {X : C} (h : IsInitial X) : HasInitial C where has_colimit F := HasColimit.mk ⟨⟨X, by cat_disch, by simp⟩, isColimitChangeEmptyCocone _ h _ (Iso.refl _)⟩ /-- The map from an object to the terminal object. -/ abbrev terminal.from [HasTerminal C] (P : C) : P ⟶ ⊤_ C := limit.lift (Functor.empty C) (asEmptyCone P) /-- The map to an object from the initial object. -/ abbrev initial.to [HasInitial C] (P : C) : ⊥_ C ⟶ P := colimit.desc (Functor.empty C) (asEmptyCocone P) /-- A terminal object is terminal. -/ def terminalIsTerminal [HasTerminal C] : IsTerminal (⊤_ C) where lift _ := terminal.from _ /-- An initial object is initial. -/ def initialIsInitial [HasInitial C] : IsInitial (⊥_ C) where desc _ := initial.to _ instance uniqueToTerminal [HasTerminal C] (P : C) : Unique (P ⟶ ⊤_ C) := isTerminalEquivUnique _ (⊤_ C) terminalIsTerminal P instance uniqueFromInitial [HasInitial C] (P : C) : Unique (⊥_ C ⟶ P) := isInitialEquivUnique _ (⊥_ C) initialIsInitial P @[ext] theorem terminal.hom_ext [HasTerminal C] {P : C} (f g : P ⟶ ⊤_ C) : f = g := by ext ⟨⟨⟩⟩ @[ext] theorem initial.hom_ext [HasInitial C] {P : C} (f g : ⊥_ C ⟶ P) : f = g := by ext ⟨⟨⟩⟩ @[reassoc (attr := simp)] theorem terminal.comp_from [HasTerminal C] {P Q : C} (f : P ⟶ Q) : f ≫ terminal.from Q = terminal.from P := by simp [eq_iff_true_of_subsingleton] -- `initial.to_comp_assoc` does not need the `simp` attribute. @[simp, reassoc] theorem initial.to_comp [HasInitial C] {P Q : C} (f : P ⟶ Q) : initial.to P ≫ f = initial.to Q := by simp [eq_iff_true_of_subsingleton] /-- The (unique) isomorphism between the chosen initial object and any other initial object. -/ @[simps!] def initialIsoIsInitial [HasInitial C] {P : C} (t : IsInitial P) : ⊥_ C ≅ P := initialIsInitial.uniqueUpToIso t /-- The (unique) isomorphism between the chosen terminal object and any other terminal object. -/ @[simps!] def terminalIsoIsTerminal [HasTerminal C] {P : C} (t : IsTerminal P) : ⊤_ C ≅ P := terminalIsTerminal.uniqueUpToIso t /-- Any morphism from a terminal object is split mono. -/ instance terminal.isSplitMono_from {Y : C} [HasTerminal C] (f : ⊤_ C ⟶ Y) : IsSplitMono f := IsTerminal.isSplitMono_from terminalIsTerminal _ /-- Any morphism to an initial object is split epi. -/ instance initial.isSplitEpi_to {Y : C} [HasInitial C] (f : Y ⟶ ⊥_ C) : IsSplitEpi f := IsInitial.isSplitEpi_to initialIsInitial _ instance hasInitial_op_of_hasTerminal [HasTerminal C] : HasInitial Cᵒᵖ := (initialOpOfTerminal terminalIsTerminal).hasInitial instance hasTerminal_op_of_hasInitial [HasInitial C] : HasTerminal Cᵒᵖ := (terminalOpOfInitial initialIsInitial).hasTerminal theorem hasTerminal_of_hasInitial_op [HasInitial Cᵒᵖ] : HasTerminal C := (terminalUnopOfInitial initialIsInitial).hasTerminal theorem hasInitial_of_hasTerminal_op [HasTerminal Cᵒᵖ] : HasInitial C := (initialUnopOfTerminal terminalIsTerminal).hasInitial instance {J : Type*} [Category J] {C : Type*} [Category C] [HasTerminal C] : HasLimit ((CategoryTheory.Functor.const J).obj (⊤_ C)) := HasLimit.mk { cone := { pt := ⊤_ C π := { app := fun _ => terminal.from _ } } isLimit := { lift := fun _ => terminal.from _ } } /-- The limit of the constant `⊤_ C` functor is `⊤_ C`. -/ @[simps hom] def limitConstTerminal {J : Type*} [Category J] {C : Type*} [Category C] [HasTerminal C] : limit ((CategoryTheory.Functor.const J).obj (⊤_ C)) ≅ ⊤_ C where hom := terminal.from _ inv := limit.lift ((CategoryTheory.Functor.const J).obj (⊤_ C)) { pt := ⊤_ C π := { app := fun _ => terminal.from _ } } @[reassoc (attr := simp)] theorem limitConstTerminal_inv_π {J : Type*} [Category J] {C : Type*} [Category C] [HasTerminal C] {j : J} : limitConstTerminal.inv ≫ limit.π ((CategoryTheory.Functor.const J).obj (⊤_ C)) j = terminal.from _ := by cat_disch instance {J : Type*} [Category J] {C : Type*} [Category C] [HasInitial C] : HasColimit ((CategoryTheory.Functor.const J).obj (⊥_ C)) := HasColimit.mk { cocone := { pt := ⊥_ C ι := { app := fun _ => initial.to _ } } isColimit := { desc := fun _ => initial.to _ } } /-- The colimit of the constant `⊥_ C` functor is `⊥_ C`. -/ @[simps inv] def colimitConstInitial {J : Type*} [Category J] {C : Type*} [Category C] [HasInitial C] : colimit ((CategoryTheory.Functor.const J).obj (⊥_ C)) ≅ ⊥_ C where hom := colimit.desc ((CategoryTheory.Functor.const J).obj (⊥_ C)) { pt := ⊥_ C ι := { app := fun _ => initial.to _ } } inv := initial.to _ @[reassoc (attr := simp)] theorem ι_colimitConstInitial_hom {J : Type*} [Category J] {C : Type*} [Category C] [HasInitial C] {j : J} : colimit.ι ((CategoryTheory.Functor.const J).obj (⊥_ C)) j ≫ colimitConstInitial.hom = initial.to _ := by cat_disch instance (priority := 100) initial.mono_from [HasInitial C] [InitialMonoClass C] (X : C) (f : ⊥_ C ⟶ X) : Mono f := initialIsInitial.mono_from f /-- To show a category is an `InitialMonoClass` it suffices to show every morphism out of the initial object is a monomorphism. -/ theorem InitialMonoClass.of_initial [HasInitial C] (h : ∀ X : C, Mono (initial.to X)) : InitialMonoClass C := InitialMonoClass.of_isInitial initialIsInitial h /-- To show a category is an `InitialMonoClass` it suffices to show the unique morphism from the initial object to a terminal object is a monomorphism. -/ theorem InitialMonoClass.of_terminal [HasInitial C] [HasTerminal C] (h : Mono (initial.to (⊤_ C))) : InitialMonoClass C := InitialMonoClass.of_isTerminal initialIsInitial terminalIsTerminal h section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) /-- The comparison morphism from the image of a terminal object to the terminal object in the target category. This is an isomorphism iff `G` preserves terminal objects, see `CategoryTheory.Limits.PreservesTerminal.ofIsoComparison`. -/ def terminalComparison [HasTerminal C] [HasTerminal D] : G.obj (⊤_ C) ⟶ ⊤_ D := terminal.from _ -- TODO: Show this is an isomorphism if and only if `G` preserves initial objects. /-- The comparison morphism from the initial object in the target category to the image of the initial object. -/ def initialComparison [HasInitial C] [HasInitial D] : ⊥_ D ⟶ G.obj (⊥_ C) := initial.to _ end Comparison variable {J : Type u} [Category.{v} J] instance hasLimit_of_domain_hasInitial [HasInitial J] {F : J ⥤ C} : HasLimit F := HasLimit.mk { cone := _, isLimit := limitOfDiagramInitial (initialIsInitial) F } -- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has an initial object then the image of it is isomorphic to the limit of `F`. -/ abbrev limitOfInitial (F : J ⥤ C) [HasInitial J] : limit F ≅ F.obj (⊥_ J) := IsLimit.conePointUniqueUpToIso (limit.isLimit _) (limitOfDiagramInitial initialIsInitial F) instance hasLimit_of_domain_hasTerminal [HasTerminal J] {F : J ⥤ C} [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : HasLimit F := HasLimit.mk { cone := _, isLimit := limitOfDiagramTerminal (terminalIsTerminal) F } -- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has a terminal object and all the morphisms in the diagram are isomorphisms, then the image of the terminal object is isomorphic to the limit of `F`. -/ abbrev limitOfTerminal (F : J ⥤ C) [HasTerminal J] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : limit F ≅ F.obj (⊤_ J) := IsLimit.conePointUniqueUpToIso (limit.isLimit _) (limitOfDiagramTerminal terminalIsTerminal F) instance hasColimit_of_domain_hasTerminal [HasTerminal J] {F : J ⥤ C} : HasColimit F := HasColimit.mk { cocone := _, isColimit := colimitOfDiagramTerminal (terminalIsTerminal) F } -- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has a terminal object then the image of it is isomorphic to the colimit of `F`. -/ abbrev colimitOfTerminal (F : J ⥤ C) [HasTerminal J] : colimit F ≅ F.obj (⊤_ J) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (colimitOfDiagramTerminal terminalIsTerminal F) instance hasColimit_of_domain_hasInitial [HasInitial J] {F : J ⥤ C} [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : HasColimit F := HasColimit.mk { cocone := _, isColimit := colimitOfDiagramInitial (initialIsInitial) F } -- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has an initial object and all the morphisms in the diagram are isomorphisms, then the image of the initial object is isomorphic to the colimit of `F`. -/ abbrev colimitOfInitial (F : J ⥤ C) [HasInitial J] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : colimit F ≅ F.obj (⊥_ J) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (colimitOfDiagramInitial initialIsInitial _) /-- If `j` is initial in the index category, then the map `limit.π F j` is an isomorphism. -/ theorem isIso_π_of_isInitial {j : J} (I : IsInitial j) (F : J ⥤ C) [HasLimit F] : IsIso (limit.π F j) := ⟨⟨limit.lift _ (coneOfDiagramInitial I F), ⟨by ext; simp, by simp⟩⟩⟩ instance isIso_π_initial [HasInitial J] (F : J ⥤ C) : IsIso (limit.π F (⊥_ J)) := isIso_π_of_isInitial initialIsInitial F theorem isIso_π_of_isTerminal {j : J} (I : IsTerminal j) (F : J ⥤ C) [HasLimit F] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (limit.π F j) := ⟨⟨limit.lift _ (coneOfDiagramTerminal I F), by ext; simp, by simp⟩⟩ instance isIso_π_terminal [HasTerminal J] (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (limit.π F (⊤_ J)) := isIso_π_of_isTerminal terminalIsTerminal F /-- If `j` is terminal in the index category, then the map `colimit.ι F j` is an isomorphism. -/ theorem isIso_ι_of_isTerminal {j : J} (I : IsTerminal j) (F : J ⥤ C) [HasColimit F] : IsIso (colimit.ι F j) := ⟨⟨colimit.desc _ (coconeOfDiagramTerminal I F), ⟨by simp, by ext; simp⟩⟩⟩ instance isIso_ι_terminal [HasTerminal J] (F : J ⥤ C) : IsIso (colimit.ι F (⊤_ J)) := isIso_ι_of_isTerminal terminalIsTerminal F theorem isIso_ι_of_isInitial {j : J} (I : IsInitial j) (F : J ⥤ C) [HasColimit F] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (colimit.ι F j) := ⟨⟨colimit.desc _ (coconeOfDiagramInitial I F), by refine ⟨?_, by ext; simp⟩ dsimp; simp only [colimit.ι_desc, coconeOfDiagramInitial_pt, coconeOfDiagramInitial_ι_app, Functor.const_obj_obj, IsInitial.to_self, Functor.map_id] dsimp [inv]; simp only [Category.id_comp, Category.comp_id, and_self] apply @Classical.choose_spec _ (fun x => x = 𝟙 F.obj j) _ ⟩⟩ instance isIso_ι_initial [HasInitial J] (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (colimit.ι F (⊥_ J)) := isIso_ι_of_isInitial initialIsInitial F end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/SplitCoequalizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers /-! # Split coequalizers We define what it means for a triple of morphisms `f g : X ⟶ Y`, `π : Y ⟶ Z` to be a split coequalizer: there is a section `s` of `π` and a section `t` of `g`, which additionally satisfy `t ≫ f = π ≫ s`. In addition, we show that every split coequalizer is a coequalizer (`CategoryTheory.IsSplitCoequalizer.isCoequalizer`) and absolute (`CategoryTheory.IsSplitCoequalizer.map`) A pair `f g : X ⟶ Y` has a split coequalizer if there is a `Z` and `π : Y ⟶ Z` making `f,g,π` a split coequalizer. A pair `f g : X ⟶ Y` has a `G`-split coequalizer if `G f, G g` has a split coequalizer. These definitions and constructions are useful in particular for the monadicity theorems. This file has been adapted to `Mathlib/CategoryTheory/Limits/Shapes/SplitEqualizer.lean`. Please try to keep them in sync. -/ namespace CategoryTheory universe v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {X Y : C} (f g : X ⟶ Y) /-- A split coequalizer diagram consists of morphisms f π X ⇉ Y → Z g satisfying `f ≫ π = g ≫ π` together with morphisms t s X ← Y ← Z satisfying `s ≫ π = 𝟙 Z`, `t ≫ g = 𝟙 Y` and `t ≫ f = π ≫ s`. The name "coequalizer" is appropriate, since any split coequalizer is a coequalizer, see `CategoryTheory.IsSplitCoequalizer.isCoequalizer`. Split coequalizers are also absolute, since a functor preserves all the structure above. -/ structure IsSplitCoequalizer {Z : C} (π : Y ⟶ Z) where /-- A map from the coequalizer to `Y` -/ rightSection : Z ⟶ Y /-- A map in the opposite direction to `f` and `g` -/ leftSection : Y ⟶ X /-- Composition of `π` with `f` and with `g` agree -/ condition : f ≫ π = g ≫ π := by cat_disch /-- `rightSection` splits `π` -/ rightSection_π : rightSection ≫ π = 𝟙 Z := by cat_disch /-- `leftSection` splits `g` -/ leftSection_bottom : leftSection ≫ g = 𝟙 Y := by cat_disch /-- `leftSection` composed with `f` is `pi` composed with `rightSection` -/ leftSection_top : leftSection ≫ f = π ≫ rightSection := by cat_disch instance {X : C} : Inhabited (IsSplitCoequalizer (𝟙 X) (𝟙 X) (𝟙 X)) where default := { rightSection := 𝟙 X, leftSection := 𝟙 X } open IsSplitCoequalizer attribute [reassoc] condition attribute [reassoc (attr := simp)] rightSection_π leftSection_bottom leftSection_top variable {f g} /-- Split coequalizers are absolute: they are preserved by any functor. -/ @[simps] def IsSplitCoequalizer.map {Z : C} {π : Y ⟶ Z} (q : IsSplitCoequalizer f g π) (F : C ⥤ D) : IsSplitCoequalizer (F.map f) (F.map g) (F.map π) where rightSection := F.map q.rightSection leftSection := F.map q.leftSection condition := by rw [← F.map_comp, q.condition, F.map_comp] rightSection_π := by rw [← F.map_comp, q.rightSection_π, F.map_id] leftSection_bottom := by rw [← F.map_comp, q.leftSection_bottom, F.map_id] leftSection_top := by rw [← F.map_comp, q.leftSection_top, F.map_comp] section open Limits /-- A split coequalizer clearly induces a cofork. -/ @[simps! pt] def IsSplitCoequalizer.asCofork {Z : C} {h : Y ⟶ Z} (t : IsSplitCoequalizer f g h) : Cofork f g := Cofork.ofπ h t.condition @[simp] theorem IsSplitCoequalizer.asCofork_π {Z : C} {h : Y ⟶ Z} (t : IsSplitCoequalizer f g h) : t.asCofork.π = h := rfl /-- The cofork induced by a split coequalizer is a coequalizer, justifying the name. In some cases it is more convenient to show a given cofork is a coequalizer by showing it is split. -/ def IsSplitCoequalizer.isCoequalizer {Z : C} {h : Y ⟶ Z} (t : IsSplitCoequalizer f g h) : IsColimit t.asCofork := Cofork.IsColimit.mk' _ fun s => ⟨t.rightSection ≫ s.π, by dsimp rw [← t.leftSection_top_assoc, s.condition, t.leftSection_bottom_assoc], fun hm => by simp [← hm]⟩ end variable (f g) /-- The pair `f,g` is a split pair if there is an `h : Y ⟶ Z` so that `f, g, h` forms a split coequalizer in `C`. -/ class HasSplitCoequalizer : Prop where /-- There is some split coequalizer -/ splittable : ∃ (Z : C) (h : Y ⟶ Z), Nonempty (IsSplitCoequalizer f g h) /-- The pair `f,g` is a `G`-split pair if there is an `h : G Y ⟶ Z` so that `G f, G g, h` forms a split coequalizer in `D`. -/ abbrev Functor.IsSplitPair : Prop := HasSplitCoequalizer (G.map f) (G.map g) /-- Get the coequalizer object from the typeclass `IsSplitPair`. -/ noncomputable def HasSplitCoequalizer.coequalizerOfSplit [HasSplitCoequalizer f g] : C := (splittable (f := f) (g := g)).choose /-- Get the coequalizer morphism from the typeclass `IsSplitPair`. -/ noncomputable def HasSplitCoequalizer.coequalizerπ [HasSplitCoequalizer f g] : Y ⟶ HasSplitCoequalizer.coequalizerOfSplit f g := (splittable (f := f) (g := g)).choose_spec.choose /-- The coequalizer morphism `coequalizeπ` gives a split coequalizer on `f,g`. -/ noncomputable def HasSplitCoequalizer.isSplitCoequalizer [HasSplitCoequalizer f g] : IsSplitCoequalizer f g (HasSplitCoequalizer.coequalizerπ f g) := Classical.choice (splittable (f := f) (g := g)).choose_spec.choose_spec /-- If `f, g` is split, then `G f, G g` is split. -/ instance map_is_split_pair [HasSplitCoequalizer f g] : HasSplitCoequalizer (G.map f) (G.map g) where splittable := ⟨_, _, ⟨IsSplitCoequalizer.map (HasSplitCoequalizer.isSplitCoequalizer f g) _⟩⟩ namespace Limits /-- If a pair has a split coequalizer, it has a coequalizer. -/ instance (priority := 1) hasCoequalizer_of_hasSplitCoequalizer [HasSplitCoequalizer f g] : HasCoequalizer f g := HasColimit.mk ⟨_, (HasSplitCoequalizer.isSplitCoequalizer f g).isCoequalizer⟩ end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/ZeroMorphisms.lean
import Mathlib.Algebra.Notation.Pi.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.IsomorphismClasses import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects /-! # Zero morphisms and zero objects A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra structure, not merely a property.) A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object. ## References * https://en.wikipedia.org/wiki/Zero_morphism * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe w v v' u u' open CategoryTheory open CategoryTheory.Category namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] variable (D : Type u') [Category.{v'} D] /-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. -/ class HasZeroMorphisms where /-- Every morphism space has zero -/ [zero : ∀ X Y : C, Zero (X ⟶ Y)] /-- `f` composed with `0` is `0` -/ comp_zero : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := by cat_disch /-- `0` composed with `f` is `0` -/ zero_comp : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := by cat_disch attribute [instance] HasZeroMorphisms.zero variable {C} @[simp] theorem comp_zero [HasZeroMorphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} : f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := HasZeroMorphisms.comp_zero f Z @[simp] theorem zero_comp [HasZeroMorphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} : (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := HasZeroMorphisms.zero_comp X f instance hasZeroMorphismsPEmpty : HasZeroMorphisms (Discrete PEmpty) where zero := by cat_disch instance hasZeroMorphismsPUnit : HasZeroMorphisms (Discrete PUnit) where zero X Y := by repeat (constructor) namespace HasZeroMorphisms /-- This lemma will be immediately superseded by `ext`, below. -/ private theorem ext_aux (I J : HasZeroMorphisms C) (w : ∀ X Y : C, (I.zero X Y).zero = (J.zero X Y).zero) : I = J := by have : I.zero = J.zero := by funext X Y specialize w X Y apply congrArg Zero.mk w cases I; cases J congr · apply proof_irrel_heq · apply proof_irrel_heq /-- If you're tempted to use this lemma "in the wild", you should probably carefully consider whether you've made a mistake in allowing two instances of `HasZeroMorphisms` to exist at all. See, particularly, the note on `zeroMorphismsOfZeroObject` below. -/ theorem ext (I J : HasZeroMorphisms C) : I = J := by apply ext_aux intro X Y have : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (I.zero X Y).zero := by apply I.zero_comp X (J.zero Y Y).zero have that : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (J.zero X Y).zero := by apply J.comp_zero (I.zero X Y).zero Y rw [← this, ← that] instance : Subsingleton (HasZeroMorphisms C) := ⟨ext⟩ end HasZeroMorphisms open Opposite HasZeroMorphisms instance hasZeroMorphismsOpposite [HasZeroMorphisms C] : HasZeroMorphisms Cᵒᵖ where zero X Y := ⟨(0 : unop Y ⟶ unop X).op⟩ comp_zero f Z := congr_arg Quiver.Hom.op (HasZeroMorphisms.zero_comp (unop Z) f.unop) zero_comp X {Y Z} (f : Y ⟶ Z) := congrArg Quiver.Hom.op (HasZeroMorphisms.comp_zero f.unop (unop X)) section variable [HasZeroMorphisms C] @[simp] lemma op_zero (X Y : C) : (0 : X ⟶ Y).op = 0 := rfl @[simp] lemma unop_zero (X Y : Cᵒᵖ) : (0 : X ⟶ Y).unop = 0 := rfl theorem zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [Mono g] (h : f ≫ g = 0) : f = 0 := by rw [← zero_comp, cancel_mono] at h exact h theorem zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [Epi f] (h : f ≫ g = 0) : g = 0 := by rw [← comp_zero, cancel_epi] at h exact h theorem eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : image.ι f = 0) : f = 0 := by rw [← image.fac f, w, HasZeroMorphisms.comp_zero] theorem nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : f ≠ 0) : image.ι f ≠ 0 := fun h => w (eq_zero_of_image_eq_zero h) end section variable [HasZeroMorphisms D] instance : HasZeroMorphisms (C ⥤ D) where zero F G := ⟨{ app := fun _ => 0 }⟩ comp_zero := fun η H => by ext X; dsimp; apply comp_zero zero_comp := fun F {G H} η => by ext X; dsimp; apply zero_comp @[simp] theorem zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl end namespace IsZero variable [HasZeroMorphisms C] theorem eq_zero_of_src {X Y : C} (o : IsZero X) (f : X ⟶ Y) : f = 0 := o.eq_of_src _ _ theorem eq_zero_of_tgt {X Y : C} (o : IsZero Y) (f : X ⟶ Y) : f = 0 := o.eq_of_tgt _ _ theorem iff_id_eq_zero (X : C) : IsZero X ↔ 𝟙 X = 0 := ⟨fun h => h.eq_of_src _ _, fun h => ⟨fun Y => ⟨⟨⟨0⟩, fun f => by rw [← id_comp f, ← id_comp (0 : X ⟶ Y), h, zero_comp, zero_comp]; simp only⟩⟩, fun Y => ⟨⟨⟨0⟩, fun f => by rw [← comp_id f, ← comp_id (0 : Y ⟶ X), h, comp_zero, comp_zero]; simp only ⟩⟩⟩⟩ theorem of_mono_zero (X Y : C) [Mono (0 : X ⟶ Y)] : IsZero X := (iff_id_eq_zero X).mpr ((cancel_mono (0 : X ⟶ Y)).1 (by simp)) theorem of_epi_zero (X Y : C) [Epi (0 : X ⟶ Y)] : IsZero Y := (iff_id_eq_zero Y).mpr ((cancel_epi (0 : X ⟶ Y)).1 (by simp)) theorem of_mono_eq_zero {X Y : C} (f : X ⟶ Y) [Mono f] (h : f = 0) : IsZero X := by subst h apply of_mono_zero X Y theorem of_epi_eq_zero {X Y : C} (f : X ⟶ Y) [Epi f] (h : f = 0) : IsZero Y := by subst h apply of_epi_zero X Y theorem iff_isSplitMono_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsZero X ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.id_comp f, h, zero_comp] · intro h rw [← IsSplitMono.id f] simp only [h, zero_comp] theorem iff_isSplitEpi_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsZero Y ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.comp_id f, h, comp_zero] · intro h rw [← IsSplitEpi.id f] simp [h] theorem of_mono {X Y : C} (f : X ⟶ Y) [Mono f] (i : IsZero Y) : IsZero X := by have hf := i.eq_zero_of_tgt f subst hf exact IsZero.of_mono_zero X Y theorem of_epi {X Y : C} (f : X ⟶ Y) [Epi f] (i : IsZero X) : IsZero Y := by have hf := i.eq_zero_of_src f subst hf exact IsZero.of_epi_zero X Y end IsZero /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `HasZeroMorphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def IsZero.hasZeroMorphisms {O : C} (hO : IsZero O) : HasZeroMorphisms C where zero X Y := { zero := hO.from_ X ≫ hO.to_ Y } zero_comp X {Y Z} f := by change (hO.from_ X ≫ hO.to_ Y) ≫ f = hO.from_ X ≫ hO.to_ Z rw [Category.assoc] congr apply hO.eq_of_src comp_zero {X Y} f Z := by change f ≫ (hO.from_ Y ≫ hO.to_ Z) = hO.from_ X ≫ hO.to_ Z rw [← Category.assoc] congr apply hO.eq_of_tgt namespace HasZeroObject variable [HasZeroObject C] open ZeroObject /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `has_zero_morphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def zeroMorphismsOfZeroObject : HasZeroMorphisms C where zero X _ := { zero := (default : X ⟶ 0) ≫ default } zero_comp X {Y Z} f := by change ((default : X ⟶ 0) ≫ default) ≫ f = (default : X ⟶ 0) ≫ default rw [Category.assoc] congr simp only [eq_iff_true_of_subsingleton] comp_zero {X Y} f Z := by change f ≫ (default : Y ⟶ 0) ≫ default = (default : X ⟶ 0) ≫ default rw [← Category.assoc] congr simp only [eq_iff_true_of_subsingleton] section HasZeroMorphisms variable [HasZeroMorphisms C] @[simp] theorem zeroIsoIsInitial_hom {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).hom = 0 := by ext @[simp] theorem zeroIsoIsInitial_inv {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).inv = 0 := by ext @[simp] theorem zeroIsoIsTerminal_hom {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).hom = 0 := by ext @[simp] theorem zeroIsoIsTerminal_inv {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).inv = 0 := by ext @[simp] theorem zeroIsoInitial_hom [HasInitial C] : zeroIsoInitial.hom = (0 : 0 ⟶ ⊥_ C) := by ext @[simp] theorem zeroIsoInitial_inv [HasInitial C] : zeroIsoInitial.inv = (0 : ⊥_ C ⟶ 0) := by ext @[simp] theorem zeroIsoTerminal_hom [HasTerminal C] : zeroIsoTerminal.hom = (0 : 0 ⟶ ⊤_ C) := by ext @[simp] theorem zeroIsoTerminal_inv [HasTerminal C] : zeroIsoTerminal.inv = (0 : ⊤_ C ⟶ 0) := by ext end HasZeroMorphisms open ZeroObject instance {B : Type*} [Category B] : HasZeroObject (B ⥤ C) := (((CategoryTheory.Functor.const B).obj (0 : C)).isZero fun _ => isZero_zero _).hasZeroObject end HasZeroObject open ZeroObject variable {D} @[simp] theorem IsZero.map [HasZeroObject D] [HasZeroMorphisms D] {F : C ⥤ D} (hF : IsZero F) {X Y : C} (f : X ⟶ Y) : F.map f = 0 := (hF.obj _).eq_of_src _ _ @[simp] theorem _root_.CategoryTheory.Functor.zero_obj [HasZeroObject D] (X : C) : IsZero ((0 : C ⥤ D).obj X) := (isZero_zero _).obj _ @[simp] theorem _root_.CategoryTheory.zero_map [HasZeroObject D] [HasZeroMorphisms D] {X Y : C} (f : X ⟶ Y) : (0 : C ⥤ D).map f = 0 := (isZero_zero _).map _ section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject @[simp] theorem id_zero : 𝟙 (0 : C) = (0 : (0 : C) ⟶ 0) := by apply HasZeroObject.from_zero_ext -- This can't be a `simp` lemma because the left-hand side would be a metavariable. /-- An arrow ending in the zero object is zero -/ theorem zero_of_to_zero {X : C} (f : X ⟶ 0) : f = 0 := by ext theorem zero_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : f = 0 := by have h : f = f ≫ i.hom ≫ 𝟙 0 ≫ i.inv := by simp only [Iso.hom_inv_id, id_comp, comp_id] simpa using h /-- An arrow starting at the zero object is zero -/ theorem zero_of_from_zero {X : C} (f : 0 ⟶ X) : f = 0 := by ext theorem zero_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : f = 0 := by have h : f = i.hom ≫ 𝟙 0 ≫ i.inv ≫ f := by simp only [Iso.hom_inv_id_assoc, id_comp] simpa using h theorem zero_of_source_iso_zero' {X Y : C} (f : X ⟶ Y) (i : IsIsomorphic X 0) : f = 0 := zero_of_source_iso_zero f (Nonempty.some i) theorem zero_of_target_iso_zero' {X Y : C} (f : X ⟶ Y) (i : IsIsomorphic Y 0) : f = 0 := zero_of_target_iso_zero f (Nonempty.some i) theorem mono_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : Mono f := ⟨fun {Z} g h _ => by rw [zero_of_target_iso_zero g i, zero_of_target_iso_zero h i]⟩ theorem epi_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : Epi f := ⟨fun {Z} g h _ => by rw [zero_of_source_iso_zero g i, zero_of_source_iso_zero h i]⟩ /-- An object `X` has `𝟙 X = 0` if and only if it is isomorphic to the zero object. Because `X ≅ 0` contains data (even if a subsingleton), we express this `↔` as an `≃`. -/ def idZeroEquivIsoZero (X : C) : 𝟙 X = 0 ≃ (X ≅ 0) where toFun h := { hom := 0 inv := 0 } invFun i := zero_of_target_iso_zero (𝟙 X) i left_inv := by cat_disch right_inv := by cat_disch @[simp] theorem idZeroEquivIsoZero_apply_hom (X : C) (h : 𝟙 X = 0) : ((idZeroEquivIsoZero X) h).hom = 0 := rfl @[simp] theorem idZeroEquivIsoZero_apply_inv (X : C) (h : 𝟙 X = 0) : ((idZeroEquivIsoZero X) h).inv = 0 := rfl /-- If `0 : X ⟶ Y` is a monomorphism, then `X ≅ 0`. -/ @[simps] def isoZeroOfMonoZero {X Y : C} (_ : Mono (0 : X ⟶ Y)) : X ≅ 0 where hom := 0 inv := 0 hom_inv_id := (cancel_mono (0 : X ⟶ Y)).mp (by simp) /-- If `0 : X ⟶ Y` is an epimorphism, then `Y ≅ 0`. -/ @[simps] def isoZeroOfEpiZero {X Y : C} (_ : Epi (0 : X ⟶ Y)) : Y ≅ 0 where hom := 0 inv := 0 hom_inv_id := (cancel_epi (0 : X ⟶ Y)).mp (by simp) /-- If a monomorphism out of `X` is zero, then `X ≅ 0`. -/ def isoZeroOfMonoEqZero {X Y : C} {f : X ⟶ Y} [Mono f] (h : f = 0) : X ≅ 0 := by subst h apply isoZeroOfMonoZero ‹_› /-- If an epimorphism in to `Y` is zero, then `Y ≅ 0`. -/ def isoZeroOfEpiEqZero {X Y : C} {f : X ⟶ Y} [Epi f] (h : f = 0) : Y ≅ 0 := by subst h apply isoZeroOfEpiZero ‹_› /-- If an object `X` is isomorphic to 0, there's no need to use choice to construct an explicit isomorphism: the zero morphism suffices. -/ def isoOfIsIsomorphicZero {X : C} (P : IsIsomorphic X 0) : X ≅ 0 where hom := 0 inv := 0 hom_inv_id := by have P := P.some rw [← P.hom_inv_id, ← Category.id_comp P.inv] apply Eq.symm simp only [id_comp, Iso.hom_inv_id, comp_zero] apply (idZeroEquivIsoZero X).invFun P inv_hom_id := by simp end section IsIso variable [HasZeroMorphisms C] /-- A zero morphism `0 : X ⟶ Y` is an isomorphism if and only if the identities on both `X` and `Y` are zero. -/ def isIsoZeroEquiv (X Y : C) : IsIso (0 : X ⟶ Y) ≃ 𝟙 X = 0 ∧ 𝟙 Y = 0 where toFun := by intro i rw [← IsIso.hom_inv_id (0 : X ⟶ Y)] rw [← IsIso.inv_hom_id (0 : X ⟶ Y)] simp only [comp_zero,and_self,zero_comp] invFun h := ⟨⟨(0 : Y ⟶ X), by cat_disch⟩⟩ left_inv := by cat_disch right_inv := by cat_disch /-- A zero morphism `0 : X ⟶ X` is an isomorphism if and only if the identity on `X` is zero. -/ def isIsoZeroSelfEquiv (X : C) : IsIso (0 : X ⟶ X) ≃ 𝟙 X = 0 := by simpa using isIsoZeroEquiv X X variable [HasZeroObject C] open ZeroObject /-- A zero morphism `0 : X ⟶ Y` is an isomorphism if and only if `X` and `Y` are isomorphic to the zero object. -/ def isIsoZeroEquivIsoZero (X Y : C) : IsIso (0 : X ⟶ Y) ≃ (X ≅ 0) × (Y ≅ 0) := by -- This is lame, because `Prod` can't cope with `Prop`, so we can't use `Equiv.prodCongr`. refine (isIsoZeroEquiv X Y).trans ?_ symm fconstructor · rintro ⟨eX, eY⟩ fconstructor · exact (idZeroEquivIsoZero X).symm eX · exact (idZeroEquivIsoZero Y).symm eY · rintro ⟨hX, hY⟩ fconstructor · exact (idZeroEquivIsoZero X) hX · exact (idZeroEquivIsoZero Y) hY · cat_disch · cat_disch /-- A zero morphism `0 : X ⟶ Y` is an isomorphism if and only if `X` and `Y` are zero objects. -/ lemma isIsoZero_iff_source_target_isZero (X Y : C) : IsIso (0 : X ⟶ Y) ↔ IsZero X ∧ IsZero Y := by constructor · intro h let h' := isIsoZeroEquivIsoZero _ _ h exact ⟨(isZero_zero _).of_iso h'.1, (isZero_zero _).of_iso h'.2⟩ · intro ⟨hX, hY⟩ exact (isIsoZeroEquivIsoZero _ _).symm ⟨hX.isoZero, hY.isoZero⟩ theorem isIso_of_source_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) (j : Y ≅ 0) : IsIso f := by rw [zero_of_source_iso_zero f i] exact (isIsoZeroEquivIsoZero _ _).invFun ⟨i, j⟩ /-- A zero morphism `0 : X ⟶ X` is an isomorphism if and only if `X` is isomorphic to the zero object. -/ def isIsoZeroSelfEquivIsoZero (X : C) : IsIso (0 : X ⟶ X) ≃ (X ≅ 0) := (isIsoZeroEquivIsoZero X X).trans subsingletonProdSelfEquiv end IsIso /-- If there are zero morphisms, any initial object is a zero object. -/ theorem hasZeroObject_of_hasInitial_object [HasZeroMorphisms C] [HasInitial C] : HasZeroObject C := by refine ⟨⟨⊥_ C, fun X => ⟨⟨⟨0⟩, by cat_disch⟩⟩, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩⟩⟩ calc f = f ≫ 𝟙 _ := (Category.comp_id _).symm _ = f ≫ 0 := by congr!; subsingleton _ = 0 := HasZeroMorphisms.comp_zero _ _ /-- If there are zero morphisms, any terminal object is a zero object. -/ theorem hasZeroObject_of_hasTerminal_object [HasZeroMorphisms C] [HasTerminal C] : HasZeroObject C := by refine ⟨⟨⊤_ C, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨0⟩, by cat_disch⟩⟩⟩⟩ calc f = 𝟙 _ ≫ f := (Category.id_comp _).symm _ = 0 ≫ f := by congr!; subsingleton _ = 0 := zero_comp section Image variable [HasZeroMorphisms C] theorem image_ι_comp_eq_zero {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [HasImage f] [Epi (factorThruImage f)] (h : f ≫ g = 0) : image.ι f ≫ g = 0 := zero_of_epi_comp (factorThruImage f) <| by simp [h] theorem comp_factorThruImage_eq_zero {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [HasImage g] (h : f ≫ g = 0) : f ≫ factorThruImage g = 0 := zero_of_comp_mono (image.ι g) <| by simp [h] variable [HasZeroObject C] open ZeroObject /-- The zero morphism has a `MonoFactorisation` through the zero object. -/ @[simps] def monoFactorisationZero (X Y : C) : MonoFactorisation (0 : X ⟶ Y) where I := 0 m := 0 e := 0 /-- The factorisation through the zero object is an image factorisation. -/ def imageFactorisationZero (X Y : C) : ImageFactorisation (0 : X ⟶ Y) where F := monoFactorisationZero X Y isImage := { lift := fun _ => 0 } instance hasImage_zero {X Y : C} : HasImage (0 : X ⟶ Y) := HasImage.mk <| imageFactorisationZero _ _ /-- The image of a zero morphism is the zero object. -/ def imageZero {X Y : C} : image (0 : X ⟶ Y) ≅ 0 := IsImage.isoExt (Image.isImage (0 : X ⟶ Y)) (imageFactorisationZero X Y).isImage /-- The image of a morphism which is equal to zero is the zero object. -/ def imageZero' {X Y : C} {f : X ⟶ Y} (h : f = 0) [HasImage f] : image f ≅ 0 := image.eqToIso h ≪≫ imageZero @[simp] theorem image.ι_zero {X Y : C} [HasImage (0 : X ⟶ Y)] : image.ι (0 : X ⟶ Y) = 0 := by rw [← image.lift_fac (monoFactorisationZero X Y)] simp /-- If we know `f = 0`, it requires a little work to conclude `image.ι f = 0`, because `f = g` only implies `image f ≅ image g`. -/ @[simp] theorem image.ι_zero' [HasEqualizers C] {X Y : C} {f : X ⟶ Y} (h : f = 0) [HasImage f] : image.ι f = 0 := by rw [image.eq_fac h] simp end Image /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance isSplitMono_sigma_ι {β : Type u'} [HasZeroMorphisms C] (f : β → C) [HasColimit (Discrete.functor f)] (b : β) : IsSplitMono (Sigma.ι f b) := by classical exact IsSplitMono.mk' { retraction := Sigma.desc <| Pi.single b (𝟙 _) } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance isSplitEpi_pi_π {β : Type u'} [HasZeroMorphisms C] (f : β → C) [HasLimit (Discrete.functor f)] (b : β) : IsSplitEpi (Pi.π f b) := by classical exact IsSplitEpi.mk' { section_ := Pi.lift <| Pi.single b (𝟙 _) } /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance isSplitMono_coprod_inl [HasZeroMorphisms C] {X Y : C} [HasColimit (pair X Y)] : IsSplitMono (coprod.inl : X ⟶ X ⨿ Y) := IsSplitMono.mk' { retraction := coprod.desc (𝟙 X) 0 } /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance isSplitMono_coprod_inr [HasZeroMorphisms C] {X Y : C} [HasColimit (pair X Y)] : IsSplitMono (coprod.inr : Y ⟶ X ⨿ Y) := IsSplitMono.mk' { retraction := coprod.desc 0 (𝟙 Y) } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance isSplitEpi_prod_fst [HasZeroMorphisms C] {X Y : C} [HasLimit (pair X Y)] : IsSplitEpi (prod.fst : X ⨯ Y ⟶ X) := IsSplitEpi.mk' { section_ := prod.lift (𝟙 X) 0 } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance isSplitEpi_prod_snd [HasZeroMorphisms C] {X Y : C} [HasLimit (pair X Y)] : IsSplitEpi (prod.snd : X ⨯ Y ⟶ Y) := IsSplitEpi.mk' { section_ := prod.lift 0 (𝟙 Y) } section variable [HasZeroMorphisms C] [HasZeroObject C] {F : D ⥤ C} /-- If a functor `F` is zero, then any cone for `F` with a zero point is limit. -/ def IsLimit.ofIsZero (c : Cone F) (hF : IsZero F) (hc : IsZero c.pt) : IsLimit c where lift _ := 0 fac _ j := (F.isZero_iff.1 hF j).eq_of_tgt _ _ uniq _ _ _ := hc.eq_of_tgt _ _ /-- If a functor `F` is zero, then any cocone for `F` with a zero point is colimit. -/ def IsColimit.ofIsZero (c : Cocone F) (hF : IsZero F) (hc : IsZero c.pt) : IsColimit c where desc _ := 0 fac _ j := (F.isZero_iff.1 hF j).eq_of_src _ _ uniq _ _ _ := hc.eq_of_src _ _ lemma IsLimit.isZero_pt {c : Cone F} (hc : IsLimit c) (hF : IsZero F) : IsZero c.pt := (isZero_zero C).of_iso (IsLimit.conePointUniqueUpToIso hc (IsLimit.ofIsZero (Cone.mk 0 0) hF (isZero_zero C))) lemma IsColimit.isZero_pt {c : Cocone F} (hc : IsColimit c) (hF : IsZero F) : IsZero c.pt := (isZero_zero C).of_iso (IsColimit.coconePointUniqueUpToIso hc (IsColimit.ofIsZero (Cocone.mk 0 0) hF (isZero_zero C))) end section variable [HasZeroMorphisms C] lemma IsTerminal.isZero {X : C} (hX : IsTerminal X) : IsZero X := by rw [IsZero.iff_id_eq_zero] apply hX.hom_ext lemma IsInitial.isZero {X : C} (hX : IsInitial X) : IsZero X := by rw [IsZero.iff_id_eq_zero] apply hX.hom_ext end section PiIota variable [HasZeroMorphisms C] {β : Type w} [DecidableEq β] (f : β → C) [HasProduct f] /-- In the presence of 0-morphism we can define an inclusion morphism into any product. -/ def Pi.ι (b : β) : f b ⟶ ∏ᶜ f := Pi.lift (Function.update (fun _ ↦ 0) b (𝟙 _)) @[reassoc (attr := simp)] lemma Pi.ι_π_eq_id (b : β) : Pi.ι f b ≫ Pi.π f b = 𝟙 _ := by simp [Pi.ι] @[reassoc] lemma Pi.ι_π_of_ne {b c : β} (h : b ≠ c) : Pi.ι f b ≫ Pi.π f c = 0 := by simp [Pi.ι, Function.update_of_ne h.symm] @[reassoc] lemma Pi.ι_π (b c : β) : Pi.ι f b ≫ Pi.π f c = if h : b = c then eqToHom (congrArg f h) else 0 := by split_ifs with h · subst h; simp · simp [Pi.ι_π_of_ne f h] instance (b : β) : Mono (Pi.ι f b) where right_cancellation _ _ e := by simpa using congrArg (· ≫ Pi.π f b) e end PiIota section SigmaPi variable [HasZeroMorphisms C] {β : Type w} [DecidableEq β] (f : β → C) [HasCoproduct f] /-- In the presence of 0-morphisms we can define a projection morphism from any coproduct. -/ def Sigma.π (b : β) : ∐ f ⟶ f b := Limits.Sigma.desc (Function.update (fun _ ↦ 0) b (𝟙 _)) @[reassoc (attr := simp)] lemma Sigma.ι_π_eq_id (b : β) : Sigma.ι f b ≫ Sigma.π f b = 𝟙 _ := by simp [Sigma.π] @[reassoc] lemma Sigma.ι_π_of_ne {b c : β} (h : b ≠ c) : Sigma.ι f b ≫ Sigma.π f c = 0 := by simp [Sigma.π, Function.update_of_ne h] @[reassoc] theorem Sigma.ι_π (b c : β) : Sigma.ι f b ≫ Sigma.π f c = if h : b = c then eqToHom (congrArg f h) else 0 := by split_ifs with h · subst h; simp · simp [Sigma.ι_π_of_ne f h] instance (b : β) : Epi (Sigma.π f b) where left_cancellation _ _ e := by simpa using congrArg (Sigma.ι f b ≫ ·) e end SigmaPi section ProdInlInr variable [HasZeroMorphisms C] (X Y : C) [HasBinaryProduct X Y] /-- If a category `C` has 0-morphisms, there is a canonical inclusion from the first component `X` into any product of objects `X ⨯ Y`. -/ def prod.inl : X ⟶ X ⨯ Y := prod.lift (𝟙 _) 0 /-- If a category `C` has 0-morphisms, there is a canonical inclusion from the second component `Y` into any product of objects `X ⨯ Y`. -/ def prod.inr : Y ⟶ X ⨯ Y := prod.lift 0 (𝟙 _) @[reassoc (attr := simp)] lemma prod.inl_fst : prod.inl X Y ≫ prod.fst = 𝟙 X := by simp [prod.inl] @[reassoc (attr := simp)] lemma prod.inl_snd : prod.inl X Y ≫ prod.snd = 0 := by simp [prod.inl] @[reassoc (attr := simp)] lemma prod.inr_fst : prod.inr X Y ≫ prod.fst = 0 := by simp [prod.inr] @[reassoc (attr := simp)] lemma prod.inr_snd : prod.inr X Y ≫ prod.snd = 𝟙 Y := by simp [prod.inr] instance : Mono (prod.inl X Y) where right_cancellation _ _ e := by simpa using congrArg (· ≫ prod.fst) e instance : Mono (prod.inr X Y) where right_cancellation _ _ e := by simpa using congrArg (· ≫ prod.snd) e end ProdInlInr section CoprodFstSnd variable [HasZeroMorphisms C] (X Y : C) [HasBinaryCoproduct X Y] /-- If a category `C` has 0-morphisms, there is a canonical projection from a coproduct `X ⨿ Y` to its first component `X`. -/ def coprod.fst : X ⨿ Y ⟶ X := coprod.desc (𝟙 _) 0 /-- If a category `C` has 0-morphisms, there is a canonical projection from a coproduct `X ⨿ Y` to its second component `Y`. -/ def coprod.snd : X ⨿ Y ⟶ Y := coprod.desc 0 (𝟙 _) @[reassoc (attr := simp)] lemma coprod.inl_fst : coprod.inl ≫ coprod.fst X Y = 𝟙 X := by simp [coprod.fst] @[reassoc (attr := simp)] lemma coprod.inr_fst : coprod.inr ≫ coprod.fst X Y = 0 := by simp [coprod.fst] @[reassoc (attr := simp)] lemma coprod.inl_snd : coprod.inl ≫ coprod.snd X Y = 0 := by simp [coprod.snd] @[reassoc (attr := simp)] lemma coprod.inr_snd : coprod.inr ≫ coprod.snd X Y = 𝟙 Y := by simp [coprod.snd] instance : Epi (coprod.fst X Y) where left_cancellation _ _ e := by simpa using congrArg (coprod.inl ≫ ·) e instance : Epi (coprod.snd X Y) where left_cancellation _ _ e := by simpa using congrArg (coprod.inr ≫ ·) e end CoprodFstSnd end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Equalizers.lean
import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.HasLimits /-! # Equalizers and coequalizers This file defines (co)equalizers as special cases of (co)limits. An equalizer is the categorical generalization of the subobject {a ∈ A | f(a) = g(a)} known from abelian groups or modules. It is a limit cone over the diagram formed by `f` and `g`. A coequalizer is the dual concept. ## Main definitions * `WalkingParallelPair` is the indexing category used for (co)equalizer_diagrams * `parallelPair` is a functor from `WalkingParallelPair` to our category `C`. * a `fork` is a cone over a parallel pair. * there is really only one interesting morphism in a fork: the arrow from the vertex of the fork to the domain of f and g. It is called `fork.ι`. * an `equalizer` is now just a `limit (parallelPair f g)` Each of these has a dual. ## Main statements * `equalizer.ι_mono` states that every equalizer map is a monomorphism * `isIso_limit_cone_parallelPair_of_self` states that the identity on the domain of `f` is an equalizer of `f` and `f`. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ section open CategoryTheory Opposite namespace CategoryTheory.Limits universe v v₂ u u₂ /-- The type of objects for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPair : Type | zero | one deriving DecidableEq, Inhabited open WalkingParallelPair -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type family of morphisms for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPairHom : WalkingParallelPair → WalkingParallelPair → Type | left : WalkingParallelPairHom zero one | right : WalkingParallelPairHom zero one | id (X : WalkingParallelPair) : WalkingParallelPairHom X X deriving DecidableEq /-- Satisfying the inhabited linter -/ instance : Inhabited (WalkingParallelPairHom zero one) where default := WalkingParallelPairHom.left open WalkingParallelPairHom /-- Composition of morphisms in the indexing diagram for (co)equalizers. -/ def WalkingParallelPairHom.comp : ∀ {X Y Z : WalkingParallelPair} (_ : WalkingParallelPairHom X Y) (_ : WalkingParallelPairHom Y Z), WalkingParallelPairHom X Z | _, _, _, id _, h => h | _, _, _, left, id one => left | _, _, _, right, id one => right theorem WalkingParallelPairHom.id_comp {X Y : WalkingParallelPair} (g : WalkingParallelPairHom X Y) : comp (id X) g = g := rfl theorem WalkingParallelPairHom.comp_id {X Y : WalkingParallelPair} (f : WalkingParallelPairHom X Y) : comp f (id Y) = f := by cases f <;> rfl theorem WalkingParallelPairHom.assoc {X Y Z W : WalkingParallelPair} (f : WalkingParallelPairHom X Y) (g : WalkingParallelPairHom Y Z) (h : WalkingParallelPairHom Z W) : comp (comp f g) h = comp f (comp g h) := by cases f <;> cases g <;> cases h <;> rfl instance walkingParallelPairHomCategory : SmallCategory WalkingParallelPair where Hom := WalkingParallelPairHom id := id comp := comp comp_id := comp_id id_comp := id_comp assoc := assoc @[simp] theorem walkingParallelPairHom_id (X : WalkingParallelPair) : WalkingParallelPairHom.id X = 𝟙 X := rfl /-- The functor `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ def walkingParallelPairOp : WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ where obj x := op <| by cases x; exacts [one, zero] map f := by cases f <;> apply Quiver.Hom.op exacts [left, right, WalkingParallelPairHom.id _] map_comp := by rintro _ _ _ (_ | _ | _) g <;> cases g <;> rfl @[simp] theorem walkingParallelPairOp_zero : walkingParallelPairOp.obj zero = op one := rfl @[simp] theorem walkingParallelPairOp_one : walkingParallelPairOp.obj one = op zero := rfl @[simp] theorem walkingParallelPairOp_left : walkingParallelPairOp.map left = @Quiver.Hom.op _ _ zero one left := rfl @[simp] theorem walkingParallelPairOp_right : walkingParallelPairOp.map right = @Quiver.Hom.op _ _ zero one right := rfl /-- The equivalence `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ @[simps functor inverse] def walkingParallelPairOpEquiv : WalkingParallelPair ≌ WalkingParallelPairᵒᵖ where functor := walkingParallelPairOp inverse := walkingParallelPairOp.leftOp unitIso := NatIso.ofComponents (fun j => eqToIso (by cases j <;> rfl)) (by rintro _ _ (_ | _ | _) <;> simp) counitIso := NatIso.ofComponents (fun j => eqToIso (by induction j with | _ X cases X <;> rfl)) (fun {i} {j} f => by induction i with | _ i induction j with | _ j let g := f.unop have : f = g.op := rfl rw [this] cases i <;> cases j <;> cases g <;> rfl) functor_unitIso_comp := fun j => by cases j <;> rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_zero : walkingParallelPairOpEquiv.unitIso.app zero = Iso.refl zero := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_one : walkingParallelPairOpEquiv.unitIso.app one = Iso.refl one := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_zero : walkingParallelPairOpEquiv.counitIso.app (op zero) = Iso.refl (op zero) := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_one : walkingParallelPairOpEquiv.counitIso.app (op one) = Iso.refl (op one) := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_hom_app_zero : walkingParallelPairOpEquiv.unitIso.hom.app zero = 𝟙 zero := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_hom_app_one : walkingParallelPairOpEquiv.unitIso.hom.app one = 𝟙 one := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_inv_app_zero : walkingParallelPairOpEquiv.unitIso.inv.app zero = 𝟙 zero := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_inv_app_one : walkingParallelPairOpEquiv.unitIso.inv.app one = 𝟙 one := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_hom_app_op_zero : walkingParallelPairOpEquiv.counitIso.hom.app (op zero) = 𝟙 (op zero) := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_hom_app_op_one : walkingParallelPairOpEquiv.counitIso.hom.app (op one) = 𝟙 (op one) := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_inv_app_op_zero : walkingParallelPairOpEquiv.counitIso.inv.app (op zero) = 𝟙 (op zero) := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_inv_app_op_one : walkingParallelPairOpEquiv.counitIso.inv.app (op one) = 𝟙 (op one) := rfl variable {C : Type u} [Category.{v} C] variable {X Y : C} /-- `parallelPair f g` is the diagram in `C` consisting of the two morphisms `f` and `g` with common domain and codomain. -/ def parallelPair (f g : X ⟶ Y) : WalkingParallelPair ⥤ C where obj x := match x with | zero => X | one => Y map h := match h with | WalkingParallelPairHom.id _ => 𝟙 _ | left => f | right => g -- `sorry` can cope with this, but it's too slow: map_comp := by rintro _ _ _ ⟨⟩ g <;> cases g <;> simp @[simp] theorem parallelPair_obj_zero (f g : X ⟶ Y) : (parallelPair f g).obj zero = X := rfl @[simp] theorem parallelPair_obj_one (f g : X ⟶ Y) : (parallelPair f g).obj one = Y := rfl @[simp] theorem parallelPair_map_left (f g : X ⟶ Y) : (parallelPair f g).map left = f := rfl @[simp] theorem parallelPair_map_right (f g : X ⟶ Y) : (parallelPair f g).map right = g := rfl @[simp] theorem parallelPair_functor_obj {F : WalkingParallelPair ⥤ C} (j : WalkingParallelPair) : (parallelPair (F.map left) (F.map right)).obj j = F.obj j := by cases j <;> rfl /-- Every functor indexing a (co)equalizer is naturally isomorphic (actually, equal) to a `parallelPair` -/ @[simps!] def diagramIsoParallelPair (F : WalkingParallelPair ⥤ C) : F ≅ parallelPair (F.map left) (F.map right) := NatIso.ofComponents (fun j => eqToIso <| by cases j <;> rfl) (by rintro _ _ (_ | _ | _) <;> simp) /-- Construct a morphism between parallel pairs. -/ def parallelPairHom {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : parallelPair f g ⟶ parallelPair f' g' where app j := match j with | zero => p | one => q naturality := by rintro _ _ ⟨⟩ <;> simp [wf,wg] @[simp] theorem parallelPairHom_app_zero {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app zero = p := rfl @[simp] theorem parallelPairHom_app_one {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app one = q := rfl /-- Construct a natural isomorphism between functors out of the walking parallel pair from its components. -/ @[simps!] def parallelPair.ext {F G : WalkingParallelPair ⥤ C} (zero : F.obj zero ≅ G.obj zero) (one : F.obj one ≅ G.obj one) (left : F.map left ≫ one.hom = zero.hom ≫ G.map left) (right : F.map right ≫ one.hom = zero.hom ≫ G.map right) : F ≅ G := NatIso.ofComponents (by rintro ⟨j⟩ exacts [zero, one]) (by rintro _ _ ⟨_⟩ <;> simp [left, right]) /-- Construct a natural isomorphism between `parallelPair f g` and `parallelPair f' g'` given equalities `f = f'` and `g = g'`. -/ @[simps!] def parallelPair.eqOfHomEq {f g f' g' : X ⟶ Y} (hf : f = f') (hg : g = g') : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simp [hf]) (by simp [hg]) /-- A fork on `f` and `g` is just a `Cone (parallelPair f g)`. -/ abbrev Fork (f g : X ⟶ Y) := Cone (parallelPair f g) /-- A cofork on `f` and `g` is just a `Cocone (parallelPair f g)`. -/ abbrev Cofork (f g : X ⟶ Y) := Cocone (parallelPair f g) variable {f g : X ⟶ Y} /-- A fork `t` on the parallel pair `f g : X ⟶ Y` consists of two morphisms `t.π.app zero : t.pt ⟶ X` and `t.π.app one : t.pt ⟶ Y`. Of these, only the first one is interesting, and we give it the shorter name `Fork.ι t`. -/ def Fork.ι (t : Fork f g) := t.π.app zero @[simp] theorem Fork.app_zero_eq_ι (t : Fork f g) : t.π.app zero = t.ι := rfl /-- A cofork `t` on the parallelPair `f g : X ⟶ Y` consists of two morphisms `t.ι.app zero : X ⟶ t.pt` and `t.ι.app one : Y ⟶ t.pt`. Of these, only the second one is interesting, and we give it the shorter name `Cofork.π t`. -/ def Cofork.π (t : Cofork f g) := t.ι.app one @[simp] theorem Cofork.app_one_eq_π (t : Cofork f g) : t.ι.app one = t.π := rfl @[simp] theorem Fork.app_one_eq_ι_comp_left (s : Fork f g) : s.π.app one = s.ι ≫ f := by rw [← s.app_zero_eq_ι, ← s.w left, parallelPair_map_left] @[reassoc] theorem Fork.app_one_eq_ι_comp_right (s : Fork f g) : s.π.app one = s.ι ≫ g := by rw [← s.app_zero_eq_ι, ← s.w right, parallelPair_map_right] @[simp] theorem Cofork.app_zero_eq_comp_π_left (s : Cofork f g) : s.ι.app zero = f ≫ s.π := by rw [← s.app_one_eq_π, ← s.w left, parallelPair_map_left] @[reassoc] theorem Cofork.app_zero_eq_comp_π_right (s : Cofork f g) : s.ι.app zero = g ≫ s.π := by rw [← s.app_one_eq_π, ← s.w right, parallelPair_map_right] /-- A fork on `f g : X ⟶ Y` is determined by the morphism `ι : P ⟶ X` satisfying `ι ≫ f = ι ≫ g`. -/ @[simps] def Fork.ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : Fork f g where pt := P π := { app := fun X => by cases X · exact ι · exact ι ≫ f naturality := fun {X} {Y} f => by cases X <;> cases Y <;> cases f <;> simp; assumption } /-- A cofork on `f g : X ⟶ Y` is determined by the morphism `π : Y ⟶ P` satisfying `f ≫ π = g ≫ π`. -/ @[simps] def Cofork.ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : Cofork f g where pt := P ι := { app := fun X => WalkingParallelPair.casesOn X (f ≫ π) π naturality := fun i j f => by cases f <;> simp [w] } @[simp] theorem Fork.ι_ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : (Fork.ofι ι w).ι = ι := rfl @[simp] theorem Cofork.π_ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : (Cofork.ofπ π w).π = π := rfl @[reassoc (attr := simp)] theorem Fork.condition (t : Fork f g) : t.ι ≫ f = t.ι ≫ g := by rw [← t.app_one_eq_ι_comp_left, ← t.app_one_eq_ι_comp_right] @[reassoc (attr := simp)] theorem Cofork.condition (t : Cofork f g) : f ≫ t.π = g ≫ t.π := by rw [← t.app_zero_eq_comp_π_left, ← t.app_zero_eq_comp_π_right] /-- To check whether two maps are equalized by both maps of a fork, it suffices to check it for the first map -/ theorem Fork.equalizer_ext (s : Fork f g) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelPair, k ≫ s.π.app j = l ≫ s.π.app j | zero => h | one => by have : k ≫ ι s ≫ f = l ≫ ι s ≫ f := by simp only [← Category.assoc]; exact congrArg (· ≫ f) h rw [s.app_one_eq_ι_comp_left, this] /-- To check whether two maps are coequalized by both maps of a cofork, it suffices to check it for the second map -/ theorem Cofork.coequalizer_ext (s : Cofork f g) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : ∀ j : WalkingParallelPair, s.ι.app j ≫ k = s.ι.app j ≫ l | zero => by simp only [s.app_zero_eq_comp_π_left, Category.assoc, h] | one => h theorem Fork.IsLimit.hom_ext {s : Fork f g} (hs : IsLimit s) {W : C} {k l : W ⟶ s.pt} (h : k ≫ Fork.ι s = l ≫ Fork.ι s) : k = l := hs.hom_ext <| Fork.equalizer_ext _ h theorem Cofork.IsColimit.hom_ext {s : Cofork f g} (hs : IsColimit s) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : k = l := hs.hom_ext <| Cofork.coequalizer_ext _ h @[reassoc (attr := simp)] theorem Fork.IsLimit.lift_ι {s t : Fork f g} (hs : IsLimit s) : hs.lift t ≫ s.ι = t.ι := hs.fac _ _ @[reassoc (attr := simp)] theorem Cofork.IsColimit.π_desc {s t : Cofork f g} (hs : IsColimit s) : s.π ≫ hs.desc t = t.π := hs.fac _ _ /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/ def Fork.IsLimit.lift {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : W ⟶ s.pt := hs.lift (Fork.ofι _ h) @[reassoc (attr := simp)] lemma Fork.IsLimit.lift_ι' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : Fork.IsLimit.lift hs k h ≫ Fork.ι s = k := hs.fac _ _ /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/ def Fork.IsLimit.lift' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : { l : W ⟶ s.pt // l ≫ Fork.ι s = k } := ⟨Fork.IsLimit.lift hs k h, by simp⟩ lemma Fork.IsLimit.mono {s : Fork f g} (hs : IsLimit s) : Mono s.ι where right_cancellation _ _ h := hom_ext hs h /-- If `s` is a colimit cofork over `f` and `g`, then a morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : s.pt ⟶ W` such that `cofork.π s ≫ l = k`. -/ def Cofork.IsColimit.desc {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : s.pt ⟶ W := hs.desc (Cofork.ofπ _ h) @[reassoc (attr := simp)] lemma Cofork.IsColimit.π_desc' {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : Cofork.π s ≫ Cofork.IsColimit.desc hs k h = k := hs.fac _ _ /-- If `s` is a colimit cofork over `f` and `g`, then a morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : s.pt ⟶ W` such that `cofork.π s ≫ l = k`. -/ def Cofork.IsColimit.desc' {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : { l : s.pt ⟶ W // Cofork.π s ≫ l = k } := ⟨Cofork.IsColimit.desc hs k h, by simp⟩ lemma Cofork.IsColimit.epi {s : Cofork f g} (hs : IsColimit s) : Epi s.π where left_cancellation _ _ h := hom_ext hs h theorem Fork.IsLimit.existsUnique {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : ∃! l : W ⟶ s.pt, l ≫ Fork.ι s = k := ⟨hs.lift <| Fork.ofι _ h, hs.fac _ _, fun _ hm => Fork.IsLimit.hom_ext hs <| hm.symm ▸ (hs.fac (Fork.ofι _ h) WalkingParallelPair.zero).symm⟩ theorem Cofork.IsColimit.existsUnique {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : ∃! d : s.pt ⟶ W, Cofork.π s ≫ d = k := ⟨hs.desc <| Cofork.ofπ _ h, hs.fac _ _, fun _ hm => Cofork.IsColimit.hom_ext hs <| hm.symm ▸ (hs.fac (Cofork.ofπ _ h) WalkingParallelPair.one).symm⟩ /-- This is a slightly more convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ @[simps] def Fork.IsLimit.mk (t : Fork f g) (lift : ∀ s : Fork f g, s.pt ⟶ t.pt) (fac : ∀ s : Fork f g, lift s ≫ Fork.ι t = Fork.ι s) (uniq : ∀ (s : Fork f g) (m : s.pt ⟶ t.pt) (_ : m ≫ t.ι = s.ι), m = lift s) : IsLimit t := { lift fac := fun s j => WalkingParallelPair.casesOn j (fac s) <| by erw [← s.w left, ← t.w left, ← Category.assoc, fac]; rfl uniq := fun s m j => by aesop} /-- This is another convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Fork.IsLimit.mk' {X Y : C} {f g : X ⟶ Y} (t : Fork f g) (create : ∀ s : Fork f g, { l // l ≫ t.ι = s.ι ∧ ∀ {m}, m ≫ t.ι = s.ι → m = l }) : IsLimit t := Fork.IsLimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 w /-- This is a slightly more convenient method to verify that a cofork is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def Cofork.IsColimit.mk (t : Cofork f g) (desc : ∀ s : Cofork f g, t.pt ⟶ s.pt) (fac : ∀ s : Cofork f g, Cofork.π t ≫ desc s = Cofork.π s) (uniq : ∀ (s : Cofork f g) (m : t.pt ⟶ s.pt) (_ : t.π ≫ m = s.π), m = desc s) : IsColimit t := { desc fac := fun s j => WalkingParallelPair.casesOn j (by simp_all) (fac s) uniq := by aesop } /-- This is another convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Cofork.IsColimit.mk' {X Y : C} {f g : X ⟶ Y} (t : Cofork f g) (create : ∀ s : Cofork f g, { l : t.pt ⟶ s.pt // t.π ≫ l = s.π ∧ ∀ {m}, t.π ≫ m = s.π → m = l }) : IsColimit t := Cofork.IsColimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 w /-- Noncomputably make a limit cone from the existence of unique factorizations. -/ noncomputable def Fork.IsLimit.ofExistsUnique {t : Fork f g} (hs : ∀ s : Fork f g, ∃! l : s.pt ⟶ t.pt, l ≫ Fork.ι t = Fork.ι s) : IsLimit t := by choose d hd hd' using hs exact Fork.IsLimit.mk _ d hd fun s m hm => hd' _ _ hm /-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/ noncomputable def Cofork.IsColimit.ofExistsUnique {t : Cofork f g} (hs : ∀ s : Cofork f g, ∃! d : t.pt ⟶ s.pt, Cofork.π t ≫ d = Cofork.π s) : IsColimit t := by choose d hd hd' using hs exact Cofork.IsColimit.mk _ d hd fun s m hm => hd' _ _ hm /-- Given a limit cone for the pair `f g : X ⟶ Y`, for any `Z`, morphisms from `Z` to its point are in bijection with morphisms `h : Z ⟶ X` such that `h ≫ f = h ≫ g`. Further, this bijection is natural in `Z`: see `Fork.IsLimit.homIso_natural`. This is a special case of `IsLimit.homIso'`, often useful to construct adjunctions. -/ @[simps] def Fork.IsLimit.homIso {X Y : C} {f g : X ⟶ Y} {t : Fork f g} (ht : IsLimit t) (Z : C) : (Z ⟶ t.pt) ≃ { h : Z ⟶ X // h ≫ f = h ≫ g } where toFun k := ⟨k ≫ t.ι, by simp only [Category.assoc, t.condition]⟩ invFun h := (Fork.IsLimit.lift' ht _ h.prop).1 left_inv _ := Fork.IsLimit.hom_ext ht (Fork.IsLimit.lift' _ _ _).prop right_inv _ := Subtype.ext (Fork.IsLimit.lift' ht _ _).prop /-- The bijection of `Fork.IsLimit.homIso` is natural in `Z`. -/ theorem Fork.IsLimit.homIso_natural {X Y : C} {f g : X ⟶ Y} {t : Fork f g} (ht : IsLimit t) {Z Z' : C} (q : Z' ⟶ Z) (k : Z ⟶ t.pt) : (Fork.IsLimit.homIso ht _ (q ≫ k) : Z' ⟶ X) = q ≫ (Fork.IsLimit.homIso ht _ k : Z ⟶ X) := Category.assoc _ _ _ /-- Given a colimit cocone for the pair `f g : X ⟶ Y`, for any `Z`, morphisms from the cocone point to `Z` are in bijection with morphisms `h : Y ⟶ Z` such that `f ≫ h = g ≫ h`. Further, this bijection is natural in `Z`: see `Cofork.IsColimit.homIso_natural`. This is a special case of `IsColimit.homIso'`, often useful to construct adjunctions. -/ @[simps] def Cofork.IsColimit.homIso {X Y : C} {f g : X ⟶ Y} {t : Cofork f g} (ht : IsColimit t) (Z : C) : (t.pt ⟶ Z) ≃ { h : Y ⟶ Z // f ≫ h = g ≫ h } where toFun k := ⟨t.π ≫ k, by simp only [← Category.assoc, t.condition]⟩ invFun h := (Cofork.IsColimit.desc' ht _ h.prop).1 left_inv _ := Cofork.IsColimit.hom_ext ht (Cofork.IsColimit.desc' _ _ _).prop right_inv _ := Subtype.ext (Cofork.IsColimit.desc' ht _ _).prop /-- The bijection of `Cofork.IsColimit.homIso` is natural in `Z`. -/ theorem Cofork.IsColimit.homIso_natural {X Y : C} {f g : X ⟶ Y} {t : Cofork f g} {Z Z' : C} (q : Z ⟶ Z') (ht : IsColimit t) (k : t.pt ⟶ Z) : (Cofork.IsColimit.homIso ht _ (k ≫ q) : Y ⟶ Z') = (Cofork.IsColimit.homIso ht _ k : Y ⟶ Z) ≫ q := (Category.assoc _ _ _).symm /-- This is a helper construction that can be useful when verifying that a category has all equalizers. Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)`, and a fork on `F.map left` and `F.map right`, we get a cone on `F`. If you're thinking about using this, have a look at `hasEqualizers_of_hasLimit_parallelPair`, which you may find to be an easier way of achieving your goal. -/ def Cone.ofFork {F : WalkingParallelPair ⥤ C} (t : Fork (F.map left) (F.map right)) : Cone F where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by simp) naturality := by rintro _ _ (_ | _ | _) <;> simp [t.condition]} /-- This is a helper construction that can be useful when verifying that a category has all coequalizers. Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)`, and a cofork on `F.map left` and `F.map right`, we get a cocone on `F`. If you're thinking about using this, have a look at `hasCoequalizers_of_hasColimit_parallelPair`, which you may find to be an easier way of achieving your goal. -/ def Cocone.ofCofork {F : WalkingParallelPair ⥤ C} (t : Cofork (F.map left) (F.map right)) : Cocone F where pt := t.pt ι := { app := fun X => eqToHom (by simp) ≫ t.ι.app X naturality := by rintro _ _ (_ | _ | _) <;> simp [t.condition]} @[simp] theorem Cone.ofFork_π {F : WalkingParallelPair ⥤ C} (t : Fork (F.map left) (F.map right)) (j) : (Cone.ofFork t).π.app j = t.π.app j ≫ eqToHom (by simp) := rfl @[simp] theorem Cocone.ofCofork_ι {F : WalkingParallelPair ⥤ C} (t : Cofork (F.map left) (F.map right)) (j) : (Cocone.ofCofork t).ι.app j = eqToHom (by simp) ≫ t.ι.app j := rfl /-- Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)` and a cone on `F`, we get a fork on `F.map left` and `F.map right`. -/ def Fork.ofCone {F : WalkingParallelPair ⥤ C} (t : Cone F) : Fork (F.map left) (F.map right) where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by simp) naturality := by rintro _ _ (_ | _ | _) <;> simp} /-- Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)` and a cocone on `F`, we get a cofork on `F.map left` and `F.map right`. -/ def Cofork.ofCocone {F : WalkingParallelPair ⥤ C} (t : Cocone F) : Cofork (F.map left) (F.map right) where pt := t.pt ι := { app := fun X => eqToHom (by simp) ≫ t.ι.app X naturality := by rintro _ _ (_ | _ | _) <;> simp} @[simp] theorem Fork.ofCone_π {F : WalkingParallelPair ⥤ C} (t : Cone F) (j) : (Fork.ofCone t).π.app j = t.π.app j ≫ eqToHom (by simp) := rfl @[simp] theorem Cofork.ofCocone_ι {F : WalkingParallelPair ⥤ C} (t : Cocone F) (j) : (Cofork.ofCocone t).ι.app j = eqToHom (by simp) ≫ t.ι.app j := rfl @[simp] theorem Fork.ι_postcompose {f' g' : X ⟶ Y} {α : parallelPair f g ⟶ parallelPair f' g'} {c : Fork f g} : Fork.ι ((Cones.postcompose α).obj c) = c.ι ≫ α.app _ := rfl @[simp] theorem Cofork.π_precompose {f' g' : X ⟶ Y} {α : parallelPair f g ⟶ parallelPair f' g'} {c : Cofork f' g'} : Cofork.π ((Cocones.precompose α).obj c) = α.app _ ≫ c.π := rfl /-- Helper function for constructing morphisms between equalizer forks. -/ @[simps] def Fork.mkHom {s t : Fork f g} (k : s.pt ⟶ t.pt) (w : k ≫ t.ι = s.ι) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · exact w · simp only [Fork.app_one_eq_ι_comp_left,← Category.assoc] congr /-- To construct an isomorphism between forks, it suffices to give an isomorphism between the cone points and check that it commutes with the `ι` morphisms. -/ @[simps] def Fork.ext {s t : Fork f g} (i : s.pt ≅ t.pt) (w : i.hom ≫ t.ι = s.ι := by cat_disch) : s ≅ t where hom := Fork.mkHom i.hom w inv := Fork.mkHom i.inv (by rw [← w, Iso.inv_hom_id_assoc]) /-- Two forks of the form `ofι` are isomorphic whenever their `ι`'s are equal. -/ def ForkOfι.ext {P : C} {ι ι' : P ⟶ X} (w : ι ≫ f = ι ≫ g) (w' : ι' ≫ f = ι' ≫ g) (h : ι = ι') : Fork.ofι ι w ≅ Fork.ofι ι' w' := Fork.ext (Iso.refl _) (by simp [h]) /-- Every fork is isomorphic to one of the form `Fork.of_ι _ _`. -/ def Fork.isoForkOfι (c : Fork f g) : c ≅ Fork.ofι c.ι c.condition := Fork.ext (by simp only [Fork.ofι_pt, Functor.const_obj_obj]; rfl) (by simp) /-- Given two forks with isomorphic components in such a way that the natural diagrams commute, then one is a limit if and only if the other one is. -/ def Fork.isLimitEquivOfIsos {X Y : C} {f g : X ⟶ Y} {X' Y' : C} (c : Fork f g) {f' g' : X' ⟶ Y'} (c' : Fork f' g') (e₀ : X ≅ X') (e₁ : Y ≅ Y') (e : c.pt ≅ c'.pt) (comm₁ : e₀.hom ≫ f' = f ≫ e₁.hom := by cat_disch) (comm₂ : e₀.hom ≫ g' = g ≫ e₁.hom := by cat_disch) (comm₃ : e.hom ≫ c'.ι = c.ι ≫ e₀.hom := by cat_disch) : IsLimit c ≃ IsLimit c' := let i : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext e₀ e₁ comm₁.symm comm₂.symm IsLimit.equivOfNatIsoOfIso i c c' (Fork.ext e comm₃) /-- Given two forks with isomorphic components in such a way that the natural diagrams commute, then if one is a limit, then the other one is as well. -/ def Fork.isLimitOfIsos {X' Y' : C} (c : Fork f g) (hc : IsLimit c) {f' g' : X' ⟶ Y'} (c' : Fork f' g') (e₀ : X ≅ X') (e₁ : Y ≅ Y') (e : c.pt ≅ c'.pt) (comm₁ : e₀.hom ≫ f' = f ≫ e₁.hom := by cat_disch) (comm₂ : e₀.hom ≫ g' = g ≫ e₁.hom := by cat_disch) (comm₃ : e.hom ≫ c'.ι = c.ι ≫ e₀.hom := by cat_disch) : IsLimit c' := (Fork.isLimitEquivOfIsos c c' e₀ e₁ e) hc /-- Helper function for constructing morphisms between coequalizer coforks. -/ @[simps] def Cofork.mkHom {s t : Cofork f g} (k : s.pt ⟶ t.pt) (w : s.π ≫ k = t.π) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · simp [Cofork.app_zero_eq_comp_π_left, w] · exact w @[reassoc (attr := simp)] theorem Fork.hom_comp_ι {s t : Fork f g} (f : s ⟶ t) : f.hom ≫ t.ι = s.ι := by cases s; cases t; cases f; aesop @[reassoc (attr := simp)] theorem Fork.π_comp_hom {s t : Cofork f g} (f : s ⟶ t) : s.π ≫ f.hom = t.π := by cases s; cases t; cases f; aesop /-- To construct an isomorphism between coforks, it suffices to give an isomorphism between the cocone points and check that it commutes with the `π` morphisms. -/ @[simps] def Cofork.ext {s t : Cofork f g} (i : s.pt ≅ t.pt) (w : s.π ≫ i.hom = t.π := by cat_disch) : s ≅ t where hom := Cofork.mkHom i.hom w inv := Cofork.mkHom i.inv (by rw [Iso.comp_inv_eq, w]) /-- Two coforks of the form `ofπ` are isomorphic whenever their `π`'s are equal. -/ def CoforkOfπ.ext {P : C} {π π' : Y ⟶ P} (w : f ≫ π = g ≫ π) (w' : f ≫ π' = g ≫ π') (h : π = π') : Cofork.ofπ π w ≅ Cofork.ofπ π' w' := Cofork.ext (Iso.refl _) (by simp [h]) /-- Every cofork is isomorphic to one of the form `Cofork.ofπ _ _`. -/ def Cofork.isoCoforkOfπ (c : Cofork f g) : c ≅ Cofork.ofπ c.π c.condition := Cofork.ext (by simp only [Cofork.ofπ_pt, Functor.const_obj_obj]; rfl) (by simp) /-- Given two coforks with isomorphic components in such a way that the natural diagrams commute, then one is a colimit if and only if the other one is. -/ def Cofork.isColimitEquivOfIsos {X Y : C} {f g : X ⟶ Y} {X' Y' : C} (c : Cofork f g) {f' g' : X' ⟶ Y'} (c' : Cofork f' g') (e₀ : X ≅ X') (e₁ : Y ≅ Y') (e : c.pt ≅ c'.pt) (comm₁ : e₀.hom ≫ f' = f ≫ e₁.hom := by cat_disch) (comm₂ : e₀.hom ≫ g' = g ≫ e₁.hom := by cat_disch) (comm₃ : e₁.inv ≫ c.π ≫ e.hom = c'.π := by cat_disch) : IsColimit c ≃ IsColimit c' := let i : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext e₀ e₁ comm₁.symm comm₂.symm IsColimit.equivOfNatIsoOfIso i c c' (Cofork.ext e (by rw [← comm₃, ← Category.assoc]; rfl)) /-- Given two coforks with isomorphic components in such a way that the natural diagrams commute, then if one is a colimit, then the other one is as well. -/ def Cofork.isColimitOfIsos {X' Y' : C} (c : Cofork f g) (hc : IsColimit c) {f' g' : X' ⟶ Y'} (c' : Cofork f' g') (e₀ : X ≅ X') (e₁ : Y ≅ Y') (e : c.pt ≅ c'.pt) (comm₁ : e₀.hom ≫ f' = f ≫ e₁.hom := by cat_disch) (comm₂ : e₀.hom ≫ g' = g ≫ e₁.hom := by cat_disch) (comm₃ : e₁.inv ≫ c.π ≫ e.hom = c'.π := by cat_disch) : IsColimit c' := (Cofork.isColimitEquivOfIsos c c' e₀ e₁ e) hc variable (f g) section /-- Two parallel morphisms `f` and `g` have an equalizer if the diagram `parallelPair f g` has a limit. -/ abbrev HasEqualizer := HasLimit (parallelPair f g) variable [HasEqualizer f g] /-- If an equalizer of `f` and `g` exists, we can access an arbitrary choice of such by saying `equalizer f g`. -/ noncomputable abbrev equalizer : C := limit (parallelPair f g) /-- If an equalizer of `f` and `g` exists, we can access the inclusion `equalizer f g ⟶ X` by saying `equalizer.ι f g`. -/ noncomputable abbrev equalizer.ι : equalizer f g ⟶ X := limit.π (parallelPair f g) zero /-- An equalizer cone for a parallel pair `f` and `g` -/ noncomputable abbrev equalizer.fork : Fork f g := limit.cone (parallelPair f g) @[simp] theorem equalizer.fork_ι : (equalizer.fork f g).ι = equalizer.ι f g := rfl @[simp] theorem equalizer.fork_π_app_zero : (equalizer.fork f g).π.app zero = equalizer.ι f g := rfl @[reassoc] theorem equalizer.condition : equalizer.ι f g ≫ f = equalizer.ι f g ≫ g := Fork.condition <| limit.cone <| parallelPair f g /-- The equalizer built from `equalizer.ι f g` is limiting. -/ noncomputable def equalizerIsEqualizer : IsLimit (Fork.ofι (equalizer.ι f g) (equalizer.condition f g)) := IsLimit.ofIsoLimit (limit.isLimit _) (Fork.ext (Iso.refl _) (by simp)) variable {f g} /-- A morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` factors through the equalizer of `f` and `g` via `equalizer.lift : W ⟶ equalizer f g`. -/ noncomputable abbrev equalizer.lift {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : W ⟶ equalizer f g := limit.lift (parallelPair f g) (Fork.ofι k h) @[reassoc] theorem equalizer.lift_ι {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : equalizer.lift k h ≫ equalizer.ι f g = k := limit.lift_π _ _ /-- A morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ equalizer f g` satisfying `l ≫ equalizer.ι f g = k`. -/ noncomputable def equalizer.lift' {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : { l : W ⟶ equalizer f g // l ≫ equalizer.ι f g = k } := ⟨equalizer.lift k h, equalizer.lift_ι _ _⟩ /-- Two maps into an equalizer are equal if they are equal when composed with the equalizer map. -/ @[ext] theorem equalizer.hom_ext {W : C} {k l : W ⟶ equalizer f g} (h : k ≫ equalizer.ι f g = l ≫ equalizer.ι f g) : k = l := Fork.IsLimit.hom_ext (limit.isLimit _) h theorem equalizer.existsUnique {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : ∃! l : W ⟶ equalizer f g, l ≫ equalizer.ι f g = k := Fork.IsLimit.existsUnique (limit.isLimit _) _ h /-- An equalizer morphism is a monomorphism -/ instance equalizer.ι_mono : Mono (equalizer.ι f g) where right_cancellation _ _ w := equalizer.hom_ext w end section variable {f g} /-- The equalizer morphism in any limit cone is a monomorphism. -/ theorem mono_of_isLimit_fork {c : Fork f g} (i : IsLimit c) : Mono (Fork.ι c) := { right_cancellation := fun _ _ w => Fork.IsLimit.hom_ext i w } end section variable {f g} /-- The identity determines a cone on the equalizer diagram of `f` and `g` if `f = g`. -/ def idFork (h : f = g) : Fork f g := Fork.ofι (𝟙 X) <| h ▸ rfl /-- The identity on `X` is an equalizer of `(f, g)`, if `f = g`. -/ def isLimitIdFork (h : f = g) : IsLimit (idFork h) := Fork.IsLimit.mk _ (fun s => Fork.ι s) (fun _ => Category.comp_id _) fun s m h => by convert h exact (Category.comp_id _).symm /-- Every equalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_eq (h₀ : f = g) {c : Fork f g} (h : IsLimit c) : IsIso c.ι := Iso.isIso_hom <| IsLimit.conePointUniqueUpToIso h <| isLimitIdFork h₀ /-- The equalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem equalizer.ι_of_eq [HasEqualizer f g] (h : f = g) : IsIso (equalizer.ι f g) := isIso_limit_cone_parallelPair_of_eq h <| limit.isLimit _ /-- Every equalizer of `(f, f)` is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_self {c : Fork f f} (h : IsLimit c) : IsIso c.ι := isIso_limit_cone_parallelPair_of_eq rfl h /-- An equalizer that is an epimorphism is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_epi {c : Fork f g} (h : IsLimit c) [Epi c.ι] : IsIso c.ι := isIso_limit_cone_parallelPair_of_eq ((cancel_epi _).1 (Fork.condition c)) h /-- Two morphisms are equal if there is a fork whose inclusion is epi. -/ theorem eq_of_epi_fork_ι (t : Fork f g) [Epi (Fork.ι t)] : f = g := (cancel_epi (Fork.ι t)).1 <| Fork.condition t /-- If the equalizer of two morphisms is an epimorphism, then the two morphisms are equal. -/ theorem eq_of_epi_equalizer [HasEqualizer f g] [Epi (equalizer.ι f g)] : f = g := (cancel_epi (equalizer.ι f g)).1 <| equalizer.condition _ _ end instance hasEqualizer_of_self : HasEqualizer f f := HasLimit.mk { cone := idFork rfl isLimit := isLimitIdFork rfl } /-- The equalizer inclusion for `(f, f)` is an isomorphism. -/ instance equalizer.ι_of_self : IsIso (equalizer.ι f f) := equalizer.ι_of_eq rfl /-- The equalizer of a morphism with itself is isomorphic to the source. -/ noncomputable def equalizer.isoSourceOfSelf : equalizer f f ≅ X := asIso (equalizer.ι f f) @[simp] theorem equalizer.isoSourceOfSelf_hom : (equalizer.isoSourceOfSelf f).hom = equalizer.ι f f := rfl @[simp] theorem equalizer.isoSourceOfSelf_inv : (equalizer.isoSourceOfSelf f).inv = equalizer.lift (𝟙 X) (by simp) := by ext simp [equalizer.isoSourceOfSelf] section /-- Two parallel morphisms `f` and `g` have a coequalizer if the diagram `parallelPair f g` has a colimit. -/ abbrev HasCoequalizer := HasColimit (parallelPair f g) variable [HasCoequalizer f g] /-- If a coequalizer of `f` and `g` exists, we can access an arbitrary choice of such by saying `coequalizer f g`. -/ noncomputable abbrev coequalizer : C := colimit (parallelPair f g) /-- If a coequalizer of `f` and `g` exists, we can access the corresponding projection by saying `coequalizer.π f g`. -/ noncomputable abbrev coequalizer.π : Y ⟶ coequalizer f g := colimit.ι (parallelPair f g) one /-- An arbitrary choice of coequalizer cocone for a parallel pair `f` and `g`. -/ noncomputable abbrev coequalizer.cofork : Cofork f g := colimit.cocone (parallelPair f g) @[simp] theorem coequalizer.cofork_π : (coequalizer.cofork f g).π = coequalizer.π f g := rfl theorem coequalizer.cofork_ι_app_one : (coequalizer.cofork f g).ι.app one = coequalizer.π f g := rfl @[reassoc] theorem coequalizer.condition : f ≫ coequalizer.π f g = g ≫ coequalizer.π f g := Cofork.condition <| colimit.cocone <| parallelPair f g /-- The cofork built from `coequalizer.π f g` is colimiting. -/ noncomputable def coequalizerIsCoequalizer : IsColimit (Cofork.ofπ (coequalizer.π f g) (coequalizer.condition f g)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cofork.ext (Iso.refl _) (by simp)) variable {f g} /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` factors through the coequalizer of `f` and `g` via `coequalizer.desc : coequalizer f g ⟶ W`. -/ noncomputable abbrev coequalizer.desc {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : coequalizer f g ⟶ W := colimit.desc (parallelPair f g) (Cofork.ofπ k h) @[reassoc] theorem coequalizer.π_desc {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : coequalizer.π f g ≫ coequalizer.desc k h = k := colimit.ι_desc _ _ theorem coequalizer.π_colimMap_desc {X' Y' Z : C} (f' g' : X' ⟶ Y') [HasCoequalizer f' g'] (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') (h : Y' ⟶ Z) (wh : f' ≫ h = g' ≫ h) : coequalizer.π f g ≫ colimMap (parallelPairHom f g f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := by rw [ι_colimMap_assoc, parallelPairHom_app_one, coequalizer.π_desc] /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : coequalizer f g ⟶ W` satisfying `coequalizer.π ≫ g = l`. -/ noncomputable def coequalizer.desc' {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : { l : coequalizer f g ⟶ W // coequalizer.π f g ≫ l = k } := ⟨coequalizer.desc k h, coequalizer.π_desc _ _⟩ /-- Two maps from a coequalizer are equal if they are equal when composed with the coequalizer map -/ @[ext] theorem coequalizer.hom_ext {W : C} {k l : coequalizer f g ⟶ W} (h : coequalizer.π f g ≫ k = coequalizer.π f g ≫ l) : k = l := Cofork.IsColimit.hom_ext (colimit.isColimit _) h theorem coequalizer.existsUnique {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : ∃! d : coequalizer f g ⟶ W, coequalizer.π f g ≫ d = k := Cofork.IsColimit.existsUnique (colimit.isColimit _) _ h /-- A coequalizer morphism is an epimorphism -/ instance coequalizer.π_epi : Epi (coequalizer.π f g) where left_cancellation _ _ w := coequalizer.hom_ext w end section variable {f g} /-- The coequalizer morphism in any colimit cocone is an epimorphism. -/ theorem epi_of_isColimit_cofork {c : Cofork f g} (i : IsColimit c) : Epi c.π := { left_cancellation := fun _ _ w => Cofork.IsColimit.hom_ext i w } end section variable {f g} /-- The identity determines a cocone on the coequalizer diagram of `f` and `g`, if `f = g`. -/ def idCofork (h : f = g) : Cofork f g := Cofork.ofπ (𝟙 Y) <| h ▸ rfl /-- The identity on `Y` is a coequalizer of `(f, g)`, where `f = g`. -/ def isColimitIdCofork (h : f = g) : IsColimit (idCofork h) := Cofork.IsColimit.mk _ (fun s => Cofork.π s) (fun _ => Category.id_comp _) fun s m h => by convert h exact (Category.id_comp _).symm /-- Every coequalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem isIso_colimit_cocone_parallelPair_of_eq (h₀ : f = g) {c : Cofork f g} (h : IsColimit c) : IsIso c.π := Iso.isIso_hom <| IsColimit.coconePointUniqueUpToIso (isColimitIdCofork h₀) h /-- The coequalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem coequalizer.π_of_eq [HasCoequalizer f g] (h : f = g) : IsIso (coequalizer.π f g) := isIso_colimit_cocone_parallelPair_of_eq h <| colimit.isColimit _ /-- Every coequalizer of `(f, f)` is an isomorphism. -/ theorem isIso_colimit_cocone_parallelPair_of_self {c : Cofork f f} (h : IsColimit c) : IsIso c.π := isIso_colimit_cocone_parallelPair_of_eq rfl h /-- A coequalizer that is a monomorphism is an isomorphism. -/ theorem isIso_limit_cocone_parallelPair_of_epi {c : Cofork f g} (h : IsColimit c) [Mono c.π] : IsIso c.π := isIso_colimit_cocone_parallelPair_of_eq ((cancel_mono _).1 (Cofork.condition c)) h /-- Two morphisms are equal if there is a cofork whose projection is mono. -/ theorem eq_of_mono_cofork_π (t : Cofork f g) [Mono (Cofork.π t)] : f = g := (cancel_mono (Cofork.π t)).1 <| Cofork.condition t /-- If the coequalizer of two morphisms is a monomorphism, then the two morphisms are equal. -/ theorem eq_of_mono_coequalizer [HasCoequalizer f g] [Mono (coequalizer.π f g)] : f = g := (cancel_mono (coequalizer.π f g)).1 <| coequalizer.condition _ _ end instance hasCoequalizer_of_self : HasCoequalizer f f := HasColimit.mk { cocone := idCofork rfl isColimit := isColimitIdCofork rfl } /-- The coequalizer projection for `(f, f)` is an isomorphism. -/ instance coequalizer.π_of_self : IsIso (coequalizer.π f f) := coequalizer.π_of_eq rfl /-- The coequalizer of a morphism with itself is isomorphic to the target. -/ noncomputable def coequalizer.isoTargetOfSelf : coequalizer f f ≅ Y := (asIso (coequalizer.π f f)).symm @[simp] theorem coequalizer.isoTargetOfSelf_hom : (coequalizer.isoTargetOfSelf f).hom = coequalizer.desc (𝟙 Y) (by simp) := by ext simp [coequalizer.isoTargetOfSelf] @[simp] theorem coequalizer.isoTargetOfSelf_inv : (coequalizer.isoTargetOfSelf f).inv = coequalizer.π f f := rfl section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) /-- The comparison morphism for the equalizer of `f,g`. This is an isomorphism iff `G` preserves the equalizer of `f,g`; see `CategoryTheory/Limits/Preserves/Shapes/Equalizers.lean` -/ noncomputable def equalizerComparison [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] : G.obj (equalizer f g) ⟶ equalizer (G.map f) (G.map g) := equalizer.lift (G.map (equalizer.ι _ _)) (by simp only [← G.map_comp]; rw [equalizer.condition]) @[reassoc (attr := simp)] theorem equalizerComparison_comp_π [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] : equalizerComparison f g G ≫ equalizer.ι (G.map f) (G.map g) = G.map (equalizer.ι f g) := equalizer.lift_ι _ _ @[reassoc (attr := simp)] theorem map_lift_equalizerComparison [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] {Z : C} {h : Z ⟶ X} (w : h ≫ f = h ≫ g) : G.map (equalizer.lift h w) ≫ equalizerComparison f g G = equalizer.lift (G.map h) (by simp only [← G.map_comp, w]) := by apply equalizer.hom_ext simp [← G.map_comp] /-- The comparison morphism for the coequalizer of `f,g`. -/ noncomputable def coequalizerComparison [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] : coequalizer (G.map f) (G.map g) ⟶ G.obj (coequalizer f g) := coequalizer.desc (G.map (coequalizer.π _ _)) (by simp only [← G.map_comp]; rw [coequalizer.condition]) @[reassoc (attr := simp)] theorem ι_comp_coequalizerComparison [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] : coequalizer.π _ _ ≫ coequalizerComparison f g G = G.map (coequalizer.π _ _) := coequalizer.π_desc _ _ @[reassoc (attr := simp)] theorem coequalizerComparison_map_desc [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] {Z : C} {h : Y ⟶ Z} (w : f ≫ h = g ≫ h) : coequalizerComparison f g G ≫ G.map (coequalizer.desc h w) = coequalizer.desc (G.map h) (by simp only [← G.map_comp, w]) := by apply coequalizer.hom_ext simp [← G.map_comp] end Comparison variable (C) /-- A category `HasEqualizers` if it has all limits of shape `WalkingParallelPair`, i.e. if it has an equalizer for every parallel pair of morphisms. -/ abbrev HasEqualizers := HasLimitsOfShape WalkingParallelPair C /-- A category `HasCoequalizers` if it has all colimits of shape `WalkingParallelPair`, i.e. if it has a coequalizer for every parallel pair of morphisms. -/ abbrev HasCoequalizers := HasColimitsOfShape WalkingParallelPair C /-- If `C` has all limits of diagrams `parallelPair f g`, then it has all equalizers -/ theorem hasEqualizers_of_hasLimit_parallelPair [∀ {X Y : C} {f g : X ⟶ Y}, HasLimit (parallelPair f g)] : HasEqualizers C := { has_limit := fun F => hasLimit_of_iso (diagramIsoParallelPair F).symm } /-- If `C` has all colimits of diagrams `parallelPair f g`, then it has all coequalizers -/ theorem hasCoequalizers_of_hasColimit_parallelPair [∀ {X Y : C} {f g : X ⟶ Y}, HasColimit (parallelPair f g)] : HasCoequalizers C := { has_colimit := fun F => hasColimit_of_iso (diagramIsoParallelPair F) } section -- In this section we show that a split mono `f` equalizes `(retraction f ≫ f)` and `(𝟙 Y)`. variable {C} [IsSplitMono f] /-- A split mono `f` equalizes `(retraction f ≫ f)` and `(𝟙 Y)`. Here we build the cone, and show in `isSplitMonoEqualizes` that it is a limit cone. -/ @[simps (rhsMd := default)] noncomputable def coneOfIsSplitMono : Fork (𝟙 Y) (retraction f ≫ f) := Fork.ofι f (by simp) @[simp] theorem coneOfIsSplitMono_ι : (coneOfIsSplitMono f).ι = f := rfl /-- A split mono `f` equalizes `(retraction f ≫ f)` and `(𝟙 Y)`. -/ noncomputable def isSplitMonoEqualizes {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsLimit (coneOfIsSplitMono f) := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ retraction f, by dsimp rw [Category.assoc, ← s.condition] apply Category.comp_id, fun hm => by simp [← hm]⟩ end /-- We show that the converse to `isSplitMonoEqualizes` is true: Whenever `f` equalizes `(r ≫ f)` and `(𝟙 Y)`, then `r` is a retraction of `f`. -/ def splitMonoOfEqualizer {X Y : C} {f : X ⟶ Y} {r : Y ⟶ X} (hr : f ≫ r ≫ f = f) (h : IsLimit (Fork.ofι f (hr.trans (Category.comp_id _).symm : f ≫ r ≫ f = f ≫ 𝟙 Y))) : SplitMono f where retraction := r id := Fork.IsLimit.hom_ext h ((Category.assoc _ _ _).trans <| hr.trans (Category.id_comp _).symm) variable {C f g} /-- The fork obtained by postcomposing an equalizer fork with a monomorphism is an equalizer. -/ def isEqualizerCompMono {c : Fork f g} (i : IsLimit c) {Z : C} (h : Y ⟶ Z) [hm : Mono h] : have : Fork.ι c ≫ f ≫ h = Fork.ι c ≫ g ≫ h := by simp only [← Category.assoc] exact congrArg (· ≫ h) c.condition IsLimit (Fork.ofι c.ι (by simp [this]) : Fork (f ≫ h) (g ≫ h)) := Fork.IsLimit.mk' _ fun s => let s' : Fork f g := Fork.ofι s.ι (by apply hm.right_cancellation; simp [s.condition]) let l := Fork.IsLimit.lift' i s'.ι s'.condition ⟨l.1, l.2, fun hm => by apply Fork.IsLimit.hom_ext i; rw [Fork.ι_ofι] at hm; rw [hm]; exact l.2.symm⟩ variable (C f g) @[instance] theorem hasEqualizer_comp_mono [HasEqualizer f g] {Z : C} (h : Y ⟶ Z) [Mono h] : HasEqualizer (f ≫ h) (g ≫ h) := ⟨⟨{ cone := _ isLimit := isEqualizerCompMono (limit.isLimit _) h }⟩⟩ /-- An equalizer of an idempotent morphism and the identity is split mono. -/ @[simps] def splitMonoOfIdempotentOfIsLimitFork {X : C} {f : X ⟶ X} (hf : f ≫ f = f) {c : Fork (𝟙 X) f} (i : IsLimit c) : SplitMono c.ι where retraction := i.lift (Fork.ofι f (by simp [hf])) id := by letI := mono_of_isLimit_fork i rw [← cancel_mono_id c.ι, Category.assoc, Fork.IsLimit.lift_ι, Fork.ι_ofι, ← c.condition] exact Category.comp_id c.ι /-- The equalizer of an idempotent morphism and the identity is split mono. -/ noncomputable def splitMonoOfIdempotentEqualizer {X : C} {f : X ⟶ X} (hf : f ≫ f = f) [HasEqualizer (𝟙 X) f] : SplitMono (equalizer.ι (𝟙 X) f) := splitMonoOfIdempotentOfIsLimitFork _ hf (limit.isLimit _) section -- In this section we show that a split epi `f` coequalizes `(f ≫ section_ f)` and `(𝟙 X)`. variable {C} [IsSplitEpi f] /-- A split epi `f` coequalizes `(f ≫ section_ f)` and `(𝟙 X)`. Here we build the cocone, and show in `isSplitEpiCoequalizes` that it is a colimit cocone. -/ @[simps (rhsMd := default)] noncomputable def coconeOfIsSplitEpi : Cofork (𝟙 X) (f ≫ section_ f) := Cofork.ofπ f (by simp) @[simp] theorem coconeOfIsSplitEpi_π : (coconeOfIsSplitEpi f).π = f := rfl /-- A split epi `f` coequalizes `(f ≫ section_ f)` and `(𝟙 X)`. -/ noncomputable def isSplitEpiCoequalizes {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsColimit (coconeOfIsSplitEpi f) := Cofork.IsColimit.mk' _ fun s => ⟨section_ f ≫ s.π, by dsimp rw [← Category.assoc, ← s.condition, Category.id_comp], fun hm => by simp [← hm]⟩ end /-- We show that the converse to `isSplitEpiEqualizes` is true: Whenever `f` coequalizes `(f ≫ s)` and `(𝟙 X)`, then `s` is a section of `f`. -/ def splitEpiOfCoequalizer {X Y : C} {f : X ⟶ Y} {s : Y ⟶ X} (hs : f ≫ s ≫ f = f) (h : IsColimit (Cofork.ofπ f ((Category.assoc _ _ _).trans <| hs.trans (Category.id_comp f).symm : (f ≫ s) ≫ f = 𝟙 X ≫ f))) : SplitEpi f where section_ := s id := Cofork.IsColimit.hom_ext h (hs.trans (Category.comp_id _).symm) variable {C f g} /-- The cofork obtained by precomposing a coequalizer cofork with an epimorphism is a coequalizer. -/ def isCoequalizerEpiComp {c : Cofork f g} (i : IsColimit c) {W : C} (h : W ⟶ X) [hm : Epi h] : have : (h ≫ f) ≫ Cofork.π c = (h ≫ g) ≫ Cofork.π c := by simp only [Category.assoc] exact congrArg (h ≫ ·) c.condition IsColimit (Cofork.ofπ c.π (this) : Cofork (h ≫ f) (h ≫ g)) := Cofork.IsColimit.mk' _ fun s => let s' : Cofork f g := Cofork.ofπ s.π (by apply hm.left_cancellation; simp_rw [← Category.assoc, s.condition]) let l := Cofork.IsColimit.desc' i s'.π s'.condition ⟨l.1, l.2, fun hm => by apply Cofork.IsColimit.hom_ext i; rw [Cofork.π_ofπ] at hm; rw [hm]; exact l.2.symm⟩ theorem hasCoequalizer_epi_comp [HasCoequalizer f g] {W : C} (h : W ⟶ X) [Epi h] : HasCoequalizer (h ≫ f) (h ≫ g) := ⟨⟨{ cocone := _ isColimit := isCoequalizerEpiComp (colimit.isColimit _) h }⟩⟩ variable (C f g) /-- A coequalizer of an idempotent morphism and the identity is split epi. -/ @[simps] def splitEpiOfIdempotentOfIsColimitCofork {X : C} {f : X ⟶ X} (hf : f ≫ f = f) {c : Cofork (𝟙 X) f} (i : IsColimit c) : SplitEpi c.π where section_ := i.desc (Cofork.ofπ f (by simp [hf])) id := by letI := epi_of_isColimit_cofork i rw [← cancel_epi_id c.π, ← Category.assoc, Cofork.IsColimit.π_desc, Cofork.π_ofπ, ← c.condition] exact Category.id_comp _ /-- The coequalizer of an idempotent morphism and the identity is split epi. -/ noncomputable def splitEpiOfIdempotentCoequalizer {X : C} {f : X ⟶ X} (hf : f ≫ f = f) [HasCoequalizer (𝟙 X) f] : SplitEpi (coequalizer.π (𝟙 X) f) := splitEpiOfIdempotentOfIsColimitCofork _ hf (colimit.isColimit _) end CategoryTheory.Limits end
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/WidePullbacks.lean
import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Thin /-! # Wide pullbacks We define the category `WidePullbackShape`, (resp. `WidePushoutShape`) which is the category obtained from a discrete category of type `J` by adjoining a terminal (resp. initial) element. Limits of this shape are wide pullbacks (pushouts). The convenience method `wideCospan` (`wideSpan`) constructs a functor from this category, hitting the given morphisms. We use `WidePullbackShape` to define ordinary pullbacks (pushouts) by using `J := WalkingPair`, which allows easy proofs of some related lemmas. Furthermore, wide pullbacks are used to show the existence of limits in the slice category. Namely, if `C` has wide pullbacks then `C/B` has limits for any object `B` in `C`. Typeclasses `HasWidePullbacks` and `HasFiniteWidePullbacks` assert the existence of wide pullbacks and finite wide pullbacks. -/ universe w w' v u open CategoryTheory CategoryTheory.Limits Opposite namespace CategoryTheory.Limits variable (J : Type w) /-- A wide pullback shape for any type `J` can be written simply as `Option J`. -/ def WidePullbackShape := Option J instance : Inhabited (WidePullbackShape J) where default := none /-- A wide pushout shape for any type `J` can be written simply as `Option J`. -/ def WidePushoutShape := Option J instance : Inhabited (WidePushoutShape J) where default := none namespace WidePullbackShape variable {J} -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type of arrows for the shape indexing a wide pullback. -/ inductive Hom : WidePullbackShape J → WidePullbackShape J → Type w | id : ∀ X, Hom X X | term : ∀ j : J, Hom (some j) none deriving DecidableEq -- See https://github.com/leanprover/lean4/issues/10295 attribute [nolint unusedArguments] instDecidableEqHom.decEq instance struct : CategoryStruct (WidePullbackShape J) where Hom := Hom id j := Hom.id j comp f g := by cases f · exact g cases g apply Hom.term _ instance Hom.inhabited : Inhabited (Hom (none : WidePullbackShape J) none) := ⟨Hom.id (none : WidePullbackShape J)⟩ open Lean Elab Tactic /- Pointing note: experimenting with manual scoping of aesop tactics. Attempted to define aesop rule directing on `WidePushoutOut` and it didn't take for some reason -/ /-- An aesop tactic for bulk cases on morphisms in `WidePushoutShape` -/ def evalCasesBash : TacticM Unit := do evalTactic (← `(tactic| casesm* WidePullbackShape _, (_ : WidePullbackShape _) ⟶ (_ : WidePullbackShape _))) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] evalCasesBash instance subsingleton_hom : Quiver.IsThin (WidePullbackShape J) := fun _ _ => by constructor intro a b casesm* WidePullbackShape _, (_ : WidePullbackShape _) ⟶ (_ : WidePullbackShape _) · rfl · rfl · rfl instance category : SmallCategory (WidePullbackShape J) := thin_category @[simp] theorem hom_id (X : WidePullbackShape J) : Hom.id X = 𝟙 X := rfl variable {C : Type u} [Category.{v} C] /-- Construct a functor out of the wide pullback shape given a J-indexed collection of arrows to a fixed object. -/ @[simps] def wideCospan (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) : WidePullbackShape J ⥤ C where obj j := Option.casesOn j B objs map f := by obtain - | j := f · apply 𝟙 _ · exact arrows j /-- Every diagram is naturally isomorphic (actually, equal) to a `wideCospan` -/ def diagramIsoWideCospan (F : WidePullbackShape J ⥤ C) : F ≅ wideCospan (F.obj none) (fun j => F.obj (some j)) fun j => F.map (Hom.term j) := NatIso.ofComponents fun j => eqToIso <| by cat_disch /-- Construct a cone over a wide cospan. -/ @[simps] def mkCone {F : WidePullbackShape J ⥤ C} {X : C} (f : X ⟶ F.obj none) (π : ∀ j, X ⟶ F.obj (some j)) (w : ∀ j, π j ≫ F.map (Hom.term j) = f) : Cone F := { pt := X π := { app := fun j => match j with | none => f | some j => π j naturality := fun j j' f => by cases j <;> cases j' <;> cases f <;> simp [w] } } /-- Wide pullback diagrams of equivalent index types are equivalent. -/ def equivalenceOfEquiv (J' : Type w') (h : J ≃ J') : WidePullbackShape J ≌ WidePullbackShape J' where functor := wideCospan none (fun j => some (h j)) fun j => Hom.term (h j) inverse := wideCospan none (fun j => some (h.invFun j)) fun j => Hom.term (h.invFun j) unitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) counitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) attribute [local instance] uliftCategory in /-- Lifting universe and morphism levels preserves wide pullback diagrams. -/ def uliftEquivalence : ULiftHom.{w'} (ULift.{w'} (WidePullbackShape J)) ≌ WidePullbackShape (ULift J) := (ULiftHomULiftCategory.equiv.{w', w', w, w} (WidePullbackShape J)).symm.trans (equivalenceOfEquiv _ (Equiv.ulift.{w', w}.symm : J ≃ ULift.{w'} J)) end WidePullbackShape namespace WidePushoutShape variable {J} -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type of arrows for the shape indexing a wide pushout. -/ inductive Hom : WidePushoutShape J → WidePushoutShape J → Type w | id : ∀ X, Hom X X | init : ∀ j : J, Hom none (some j) deriving DecidableEq -- See https://github.com/leanprover/lean4/issues/10295 attribute [nolint unusedArguments] instDecidableEqHom.decEq instance struct : CategoryStruct (WidePushoutShape J) where Hom := Hom id j := Hom.id j comp f g := by cases f · exact g cases g apply Hom.init _ instance Hom.inhabited : Inhabited (Hom (none : WidePushoutShape J) none) := ⟨Hom.id (none : WidePushoutShape J)⟩ open Lean Elab Tactic -- Pointing note: experimenting with manual scoping of aesop tactics; only this worked /-- An aesop tactic for bulk cases on morphisms in `WidePushoutShape` -/ def evalCasesBash' : TacticM Unit := do evalTactic (← `(tactic| casesm* WidePushoutShape _, (_ : WidePushoutShape _) ⟶ (_ : WidePushoutShape _))) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] evalCasesBash' instance subsingleton_hom : Quiver.IsThin (WidePushoutShape J) := fun _ _ => by constructor intro a b casesm* WidePushoutShape _, (_ : WidePushoutShape _) ⟶ (_ : WidePushoutShape _) repeat rfl instance category : SmallCategory (WidePushoutShape J) := thin_category @[simp] theorem hom_id (X : WidePushoutShape J) : Hom.id X = 𝟙 X := rfl variable {C : Type u} [Category.{v} C] /-- Construct a functor out of the wide pushout shape given a J-indexed collection of arrows from a fixed object. -/ @[simps] def wideSpan (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) : WidePushoutShape J ⥤ C where obj j := Option.casesOn j B objs map f := by obtain - | j := f · apply 𝟙 _ · exact arrows j map_comp := fun f g => by cases f · simp only [hom_id, Category.id_comp]; congr · cases g simp only [hom_id, Category.comp_id]; congr /-- Every diagram is naturally isomorphic (actually, equal) to a `wideSpan` -/ def diagramIsoWideSpan (F : WidePushoutShape J ⥤ C) : F ≅ wideSpan (F.obj none) (fun j => F.obj (some j)) fun j => F.map (Hom.init j) := NatIso.ofComponents fun j => eqToIso <| by cases j; repeat rfl /-- Construct a cocone over a wide span. -/ @[simps] def mkCocone {F : WidePushoutShape J ⥤ C} {X : C} (f : F.obj none ⟶ X) (ι : ∀ j, F.obj (some j) ⟶ X) (w : ∀ j, F.map (Hom.init j) ≫ ι j = f) : Cocone F := { pt := X ι := { app := fun j => match j with | none => f | some j => ι j naturality := fun j j' f => by cases j <;> cases j' <;> cases f <;> simp [w] } } /-- Wide pushout diagrams of equivalent index types are equivalent. -/ def equivalenceOfEquiv (J' : Type w') (h : J ≃ J') : WidePushoutShape J ≌ WidePushoutShape J' where functor := wideSpan none (fun j => some (h j)) fun j => Hom.init (h j) inverse := wideSpan none (fun j => some (h.invFun j)) fun j => Hom.init (h.invFun j) unitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) counitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) attribute [local instance] uliftCategory in /-- Lifting universe and morphism levels preserves wide pushout diagrams. -/ def uliftEquivalence : ULiftHom.{w'} (ULift.{w'} (WidePushoutShape J)) ≌ WidePushoutShape (ULift J) := (ULiftHomULiftCategory.equiv.{w', w', w, w} (WidePushoutShape J)).symm.trans (equivalenceOfEquiv _ (Equiv.ulift.{w', w}.symm : J ≃ ULift.{w'} J)) end WidePushoutShape variable (C : Type u) [Category.{v} C] /-- A category `HasWidePullbacks` if it has all limits of shape `WidePullbackShape J`, i.e. if it has a wide pullback for every collection of morphisms with the same codomain. -/ abbrev HasWidePullbacks : Prop := ∀ J : Type w, HasLimitsOfShape (WidePullbackShape J) C /-- A category `HasWidePushouts` if it has all colimits of shape `WidePushoutShape J`, i.e. if it has a wide pushout for every collection of morphisms with the same domain. -/ abbrev HasWidePushouts : Prop := ∀ J : Type w, HasColimitsOfShape (WidePushoutShape J) C variable {C J} /-- `HasWidePullback B objs arrows` means that `wideCospan B objs arrows` has a limit. -/ abbrev HasWidePullback (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) : Prop := HasLimit (WidePullbackShape.wideCospan B objs arrows) /-- `HasWidePushout B objs arrows` means that `wideSpan B objs arrows` has a colimit. -/ abbrev HasWidePushout (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) : Prop := HasColimit (WidePushoutShape.wideSpan B objs arrows) /-- A choice of wide pullback. -/ noncomputable abbrev widePullback (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) [HasWidePullback B objs arrows] : C := limit (WidePullbackShape.wideCospan B objs arrows) /-- A choice of wide pushout. -/ noncomputable abbrev widePushout (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) [HasWidePushout B objs arrows] : C := colimit (WidePushoutShape.wideSpan B objs arrows) namespace WidePullback variable {C : Type u} [Category.{v} C] {B : C} {objs : J → C} (arrows : ∀ j : J, objs j ⟶ B) variable [HasWidePullback B objs arrows] /-- The `j`-th projection from the pullback. -/ noncomputable abbrev π (j : J) : widePullback _ _ arrows ⟶ objs j := limit.π (WidePullbackShape.wideCospan _ _ _) (Option.some j) /-- The unique map to the base from the pullback. -/ noncomputable abbrev base : widePullback _ _ arrows ⟶ B := limit.π (WidePullbackShape.wideCospan _ _ _) Option.none @[reassoc (attr := simp)] theorem π_arrow (j : J) : π arrows j ≫ arrows _ = base arrows := by apply limit.w (WidePullbackShape.wideCospan _ _ _) (WidePullbackShape.Hom.term j) variable {arrows} in /-- Lift a collection of morphisms to a morphism to the pullback. -/ noncomputable abbrev lift {X : C} (f : X ⟶ B) (fs : ∀ j : J, X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) : X ⟶ widePullback _ _ arrows := limit.lift (WidePullbackShape.wideCospan _ _ _) (WidePullbackShape.mkCone f fs <| w) variable {X : C} (f : X ⟶ B) (fs : ∀ j : J, X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) @[reassoc] theorem lift_π (j : J) : lift f fs w ≫ π arrows j = fs _ := by simp only [limit.lift_π, WidePullbackShape.mkCone_pt, WidePullbackShape.mkCone_π_app] @[reassoc] theorem lift_base : lift f fs w ≫ base arrows = f := by simp only [limit.lift_π, WidePullbackShape.mkCone_pt, WidePullbackShape.mkCone_π_app] theorem eq_lift_of_comp_eq (g : X ⟶ widePullback _ _ arrows) : (∀ j : J, g ≫ π arrows j = fs j) → g ≫ base arrows = f → g = lift f fs w := by intro h1 h2 apply (limit.isLimit (WidePullbackShape.wideCospan B objs arrows)).uniq (WidePullbackShape.mkCone f fs <| w) rintro (_ | _) · apply h2 · apply h1 theorem hom_eq_lift (g : X ⟶ widePullback _ _ arrows) : g = lift (g ≫ base arrows) (fun j => g ≫ π arrows j) (by simp) := by aesop @[ext 1100] theorem hom_ext (g1 g2 : X ⟶ widePullback _ _ arrows) : (∀ j : J, g1 ≫ π arrows j = g2 ≫ π arrows j) → g1 ≫ base arrows = g2 ≫ base arrows → g1 = g2 := by intro h1 h2 apply limit.hom_ext rintro (_ | _) · apply h2 · apply h1 end WidePullback namespace WidePushout variable {C : Type u} [Category.{v} C] {B : C} {objs : J → C} (arrows : ∀ j : J, B ⟶ objs j) variable [HasWidePushout B objs arrows] /-- The `j`-th inclusion to the pushout. -/ noncomputable abbrev ι (j : J) : objs j ⟶ widePushout _ _ arrows := colimit.ι (WidePushoutShape.wideSpan _ _ _) (Option.some j) /-- The unique map from the head to the pushout. -/ noncomputable abbrev head : B ⟶ widePushout B objs arrows := colimit.ι (WidePushoutShape.wideSpan _ _ _) Option.none @[reassoc, simp] theorem arrow_ι (j : J) : arrows j ≫ ι arrows j = head arrows := by apply colimit.w (WidePushoutShape.wideSpan _ _ _) (WidePushoutShape.Hom.init j) variable {arrows} in /-- Descend a collection of morphisms to a morphism from the pushout. -/ noncomputable abbrev desc {X : C} (f : B ⟶ X) (fs : ∀ j : J, objs j ⟶ X) (w : ∀ j, arrows j ≫ fs j = f) : widePushout _ _ arrows ⟶ X := colimit.desc (WidePushoutShape.wideSpan B objs arrows) (WidePushoutShape.mkCocone f fs <| w) variable {X : C} (f : B ⟶ X) (fs : ∀ j : J, objs j ⟶ X) (w : ∀ j, arrows j ≫ fs j = f) @[reassoc] theorem ι_desc (j : J) : ι arrows j ≫ desc f fs w = fs _ := by simp only [colimit.ι_desc, WidePushoutShape.mkCocone_pt, WidePushoutShape.mkCocone_ι_app] @[reassoc] theorem head_desc : head arrows ≫ desc f fs w = f := by simp only [colimit.ι_desc, WidePushoutShape.mkCocone_pt, WidePushoutShape.mkCocone_ι_app] theorem eq_desc_of_comp_eq (g : widePushout _ _ arrows ⟶ X) : (∀ j : J, ι arrows j ≫ g = fs j) → head arrows ≫ g = f → g = desc f fs w := by intro h1 h2 apply (colimit.isColimit (WidePushoutShape.wideSpan B objs arrows)).uniq (WidePushoutShape.mkCocone f fs <| w) rintro (_ | _) · apply h2 · apply h1 theorem hom_eq_desc (g : widePushout _ _ arrows ⟶ X) : g = desc (head arrows ≫ g) (fun j => ι arrows j ≫ g) fun j => by rw [← Category.assoc] simp := by cat_disch @[ext 1100] theorem hom_ext (g1 g2 : widePushout _ _ arrows ⟶ X) : (∀ j : J, ι arrows j ≫ g1 = ι arrows j ≫ g2) → head arrows ≫ g1 = head arrows ≫ g2 → g1 = g2 := by intro h1 h2 apply colimit.hom_ext rintro (_ | _) · apply h2 · apply h1 end WidePushout variable (J) /-- The action on morphisms of the obvious functor `WidePullbackShape_op : WidePullbackShape J ⥤ (WidePushoutShape J)ᵒᵖ` -/ def widePullbackShapeOpMap : ∀ X Y : WidePullbackShape J, (X ⟶ Y) → ((op X : (WidePushoutShape J)ᵒᵖ) ⟶ (op Y : (WidePushoutShape J)ᵒᵖ)) | _, _, WidePullbackShape.Hom.id X => Quiver.Hom.op (WidePushoutShape.Hom.id _) | _, _, WidePullbackShape.Hom.term _ => Quiver.Hom.op (WidePushoutShape.Hom.init _) /-- The obvious functor `WidePullbackShape J ⥤ (WidePushoutShape J)ᵒᵖ` -/ @[simps] def widePullbackShapeOp : WidePullbackShape J ⥤ (WidePushoutShape J)ᵒᵖ where obj X := op X map {X₁} {X₂} := widePullbackShapeOpMap J X₁ X₂ /-- The action on morphisms of the obvious functor `widePushoutShapeOp : WidePushoutShape J ⥤ (WidePullbackShape J)ᵒᵖ` -/ def widePushoutShapeOpMap : ∀ X Y : WidePushoutShape J, (X ⟶ Y) → ((op X : (WidePullbackShape J)ᵒᵖ) ⟶ (op Y : (WidePullbackShape J)ᵒᵖ)) | _, _, WidePushoutShape.Hom.id X => Quiver.Hom.op (WidePullbackShape.Hom.id _) | _, _, WidePushoutShape.Hom.init _ => Quiver.Hom.op (WidePullbackShape.Hom.term _) /-- The obvious functor `WidePushoutShape J ⥤ (WidePullbackShape J)ᵒᵖ` -/ @[simps] def widePushoutShapeOp : WidePushoutShape J ⥤ (WidePullbackShape J)ᵒᵖ where obj X := op X map := fun {X} {Y} => widePushoutShapeOpMap J X Y /-- The obvious functor `(WidePullbackShape J)ᵒᵖ ⥤ WidePushoutShape J` -/ @[simps!] def widePullbackShapeUnop : (WidePullbackShape J)ᵒᵖ ⥤ WidePushoutShape J := (widePullbackShapeOp J).leftOp /-- The obvious functor `(WidePushoutShape J)ᵒᵖ ⥤ WidePullbackShape J` -/ @[simps!] def widePushoutShapeUnop : (WidePushoutShape J)ᵒᵖ ⥤ WidePullbackShape J := (widePushoutShapeOp J).leftOp /-- The inverse of the unit isomorphism of the equivalence `widePushoutShapeOpEquiv : (WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J` -/ def widePushoutShapeOpUnop : widePushoutShapeUnop J ⋙ widePullbackShapeOp J ≅ 𝟭 _ := NatIso.ofComponents fun _ => Iso.refl _ /-- The counit isomorphism of the equivalence `widePullbackShapeOpEquiv : (WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J` -/ def widePushoutShapeUnopOp : widePushoutShapeOp J ⋙ widePullbackShapeUnop J ≅ 𝟭 _ := NatIso.ofComponents fun _ => Iso.refl _ /-- The inverse of the unit isomorphism of the equivalence `widePullbackShapeOpEquiv : (WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J` -/ def widePullbackShapeOpUnop : widePullbackShapeUnop J ⋙ widePushoutShapeOp J ≅ 𝟭 _ := NatIso.ofComponents fun _ => Iso.refl _ /-- The counit isomorphism of the equivalence `widePushoutShapeOpEquiv : (WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J` -/ def widePullbackShapeUnopOp : widePullbackShapeOp J ⋙ widePushoutShapeUnop J ≅ 𝟭 _ := NatIso.ofComponents fun _ => Iso.refl _ /-- The duality equivalence `(WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J` -/ @[simps] def widePushoutShapeOpEquiv : (WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J where functor := widePushoutShapeUnop J inverse := widePullbackShapeOp J unitIso := (widePushoutShapeOpUnop J).symm counitIso := widePullbackShapeUnopOp J /-- The duality equivalence `(WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J` -/ @[simps] def widePullbackShapeOpEquiv : (WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J where functor := widePullbackShapeUnop J inverse := widePushoutShapeOp J unitIso := (widePullbackShapeOpUnop J).symm counitIso := widePushoutShapeUnopOp J /-- If a category has wide pushouts on a higher universe level it also has wide pushouts on a lower universe level. -/ theorem hasWidePushouts_shrink [HasWidePushouts.{max w w'} C] : HasWidePushouts.{w} C := fun _ => hasColimitsOfShape_of_equivalence (WidePushoutShape.equivalenceOfEquiv _ Equiv.ulift.{w'}) /-- If a category has wide pullbacks on a higher universe level it also has wide pullbacks on a lower universe level. -/ theorem hasWidePullbacks_shrink [HasWidePullbacks.{max w w'} C] : HasWidePullbacks.{w} C := fun _ => hasLimitsOfShape_of_equivalence (WidePullbackShape.equivalenceOfEquiv _ Equiv.ulift.{w'}) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/End.lean
import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer /-! # Ends and coends In this file, given a functor `F : Jᵒᵖ ⥤ J ⥤ C`, we define its end `end_ F`, which is a suitable multiequalizer of the objects `(F.obj (op j)).obj j` for all `j : J`. For this shape of limits, cones are named wedges: the corresponding type is `Wedge F`. We also introduce `coend F` as multicoequalizers of `(F.obj (op j)).obj j` for all `j : J`. In this cases, cocones are named cowedges. ## References * https://ncatlab.org/nlab/show/end -/ universe v v' u u' namespace CategoryTheory open Opposite namespace Limits variable {J : Type u} [Category.{v} J] {C : Type u'} [Category.{v'} C] (F : Jᵒᵖ ⥤ J ⥤ C) variable (J) in /-- The shape of multiequalizer diagrams involved in the definition of ends. -/ @[simps] def multicospanShapeEnd : MulticospanShape where L := J R := Arrow J fst f := f.left snd f := f.right variable (J) in /-- The shape of multicoequalizer diagrams involved in the definition of coends. -/ @[simps] def multispanShapeCoend : MultispanShape where L := Arrow J R := J fst f := f.left snd f := f.right /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the multicospan index which shall be used to define the end of `F`. -/ @[simps] def multicospanIndexEnd : MulticospanIndex (multicospanShapeEnd J) C where left j := (F.obj (op j)).obj j right f := (F.obj (op f.left)).obj f.right fst f := (F.obj (op f.left)).map f.hom snd f := (F.map f.hom.op).app f.right /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the multispan used to define the coend of `F`. -/ @[simps] def multispanIndexCoend : MultispanIndex (multispanShapeCoend J) C where left f := (F.obj (op f.right)).obj f.left right j := (F.obj (op j)).obj j fst f := (F.map f.hom.op).app f.left snd f := (F.obj (op f.right)).map f.hom /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, a wedge for `F` is a type of cones (specifically the type of multiforks for `multicospanIndexEnd F`): the point of universal of these wedges shall be the end of `F`. -/ abbrev Wedge := Multifork (multicospanIndexEnd F) namespace Wedge variable {F} /-- A variant of `CategoryTheory.Limits.Cones.ext` specialized to produce isomorphisms of wedges. -/ @[simps!] def ext {W₁ W₂ : Wedge F} (e : W₁.pt ≅ W₂.pt) (he : ∀ j : J, W₁.ι j = e.hom ≫ W₂.ι j := by cat_disch) : W₁ ≅ W₂ := Cones.ext e (fun j => match j with | .left _ => he _ | .right f => by simpa using (he f.left) =≫ _) section Constructor variable (pt : C) (π : ∀ (j : J), pt ⟶ (F.obj (op j)).obj j) (hπ : ∀ ⦃i j : J⦄ (f : i ⟶ j), π i ≫ (F.obj (op i)).map f = π j ≫ (F.map f.op).app j) /-- Constructor for wedges. -/ @[simps! pt] abbrev mk : Wedge F := Multifork.ofι _ pt π (fun f ↦ hπ f.hom) @[simp] lemma mk_ι (j : J) : (mk pt π hπ).ι j = π j := rfl end Constructor @[reassoc] lemma condition (c : Wedge F) {i j : J} (f : i ⟶ j) : c.ι i ≫ (F.obj (op i)).map f = c.ι j ≫ (F.map f.op).app j := Multifork.condition c (Arrow.mk f) namespace IsLimit variable {c : Wedge F} (hc : IsLimit c) lemma hom_ext (hc : IsLimit c) {X : C} {f g : X ⟶ c.pt} (h : ∀ j, f ≫ c.ι j = g ≫ c.ι j) : f = g := Multifork.IsLimit.hom_ext hc h /-- Construct a morphism to the end from its universal property. -/ def lift (hc : IsLimit c) {X : C} (f : ∀ j, X ⟶ (F.obj (op j)).obj j) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), f i ≫ (F.obj (op i)).map g = f j ≫ (F.map g.op).app j) : X ⟶ c.pt := Multifork.IsLimit.lift hc f (fun _ ↦ hf _) @[reassoc (attr := simp)] lemma lift_ι (hc : IsLimit c) {X : C} (f : ∀ j, X ⟶ (F.obj (op j)).obj j) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), f i ≫ (F.obj (op i)).map g = f j ≫ (F.map g.op).app j) (j : J) : lift hc f hf ≫ c.ι j = f j := by apply IsLimit.fac end IsLimit end Wedge /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, a cowedge for `F` is a type of cocones (specifically the type of multicoforks for `multispanIndexCoend F`): the point of a universal cowedge is the coend of `F`. -/ abbrev Cowedge := Multicofork (multispanIndexCoend F) namespace Cowedge variable {F} /-- A variant of `CategoryTheory.Limits.Cocones.ext` specialized to produce isomorphisms of cowedges. -/ @[simps!] def ext {W₁ W₂ : Cowedge F} (e : W₁.pt ≅ W₂.pt) (he : ∀ j : J, W₁.π j ≫ e.hom = W₂.π j := by cat_disch) : W₁ ≅ W₂ := Cocones.ext e (fun j => match j with | .right _ => he _ | .left f => by simpa using _ ≫= (he f.left)) section Constructor variable (pt : C) (ι : ∀ (j : J), (F.obj (op j)).obj j ⟶ pt) (hι : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f.op).app i ≫ ι i = (F.obj (op j)).map f ≫ ι j) /-- Constructor for cowedges. -/ @[simps! pt] abbrev mk : Cowedge F := Multicofork.ofπ _ pt ι (fun f ↦ hι f.hom) @[simp] lemma mk_π (j : J) : (mk pt ι hι).π j = ι j := rfl end Constructor @[reassoc] lemma condition (c : Cowedge F) {i j : J} (f : i ⟶ j) : (F.map f.op).app i ≫ c.π i = (F.obj (op j)).map f ≫ c.π j := Multicofork.condition c (Arrow.mk f) namespace IsColimit variable {c : Cowedge F} (hc : IsColimit c) lemma hom_ext (hc : IsColimit c) {X : C} {f g : c.pt ⟶ X} (h : ∀ j, c.π j ≫ f = c.π j ≫ g) : f = g := Multicofork.IsColimit.hom_ext hc h /-- Construct a morphism from the coend using its universal property. -/ def desc (hc : IsColimit c) {X : C} (f : ∀ j, (F.obj (op j)).obj j ⟶ X) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), (F.map g.op).app i ≫ f i = (F.obj (op j)).map g ≫ f j) : c.pt ⟶ X := Multicofork.IsColimit.desc hc f (fun _ ↦ hf _) @[reassoc (attr := simp)] lemma π_desc (hc : IsColimit c) {X : C} (f : ∀ j, (F.obj (op j)).obj j ⟶ X) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), (F.map g.op).app i ≫ f i = (F.obj (op j)).map g ≫ f j) (j : J) : c.π j ≫ desc hc f hf = f j := by apply IsColimit.fac end IsColimit end Cowedge section End /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this property asserts the existence of the end of `F`. -/ abbrev HasEnd := HasMultiequalizer (multicospanIndexEnd F) variable [HasEnd F] /-- The end of a functor `F : Jᵒᵖ ⥤ J ⥤ C`. -/ noncomputable def end_ : C := multiequalizer (multicospanIndexEnd F) /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the projection `end_ F ⟶ (F.obj (op j)).obj j` for any `j : J`. -/ noncomputable def end_.π (j : J) : end_ F ⟶ (F.obj (op j)).obj j := Multiequalizer.ι _ _ @[reassoc] lemma end_.condition {i j : J} (f : i ⟶ j) : π F i ≫ (F.obj (op i)).map f = π F j ≫ (F.map f.op).app j := by apply Wedge.condition variable {F} @[ext] lemma end_.hom_ext {X : C} {f g : X ⟶ end_ F} (h : ∀ j, f ≫ end_.π F j = g ≫ end_.π F j) : f = g := Multiequalizer.hom_ext _ _ _ (fun _ ↦ h _) @[deprecated (since := "2025-06-06")] alias _root_.CategoryTheory.Limits.hom_ext := end_.hom_ext section variable {X : C} (f : ∀ j, X ⟶ (F.obj (op j)).obj j) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), f i ≫ (F.obj (op i)).map g = f j ≫ (F.map g.op).app j) /-- Constructor for morphisms to the end of a functor. -/ noncomputable def end_.lift : X ⟶ end_ F := Wedge.IsLimit.lift (limit.isLimit _) f hf @[reassoc (attr := simp)] lemma end_.lift_π (j : J) : lift f hf ≫ π F j = f j := by apply IsLimit.fac variable {F' : Jᵒᵖ ⥤ J ⥤ C} [HasEnd F'] (f : F ⟶ F') /-- A natural transformation of functors F ⟶ F' induces a map end_ F ⟶ end_ F'. -/ noncomputable def end_.map : end_ F ⟶ end_ F' := end_.lift (fun x ↦ end_.π _ _ ≫ (f.app (op x)).app x) (fun j j' φ ↦ by have e := (f.app (op j)).naturality φ simp only [Category.assoc] rw [← e, reassoc_of% end_.condition F φ] simp) @[reassoc (attr := simp)] lemma end_.map_π (j : J) : end_.map f ≫ end_.π F' j = end_.π _ _ ≫ (f.app (op j)).app j := by simp [end_.map] @[reassoc (attr := simp)] lemma end_.map_comp {F'' : Jᵒᵖ ⥤ J ⥤ C} [HasEnd F''] (g : F' ⟶ F'') : end_.map f ≫ end_.map g = end_.map (f ≫ g) := by cat_disch @[simp] lemma end_.map_id : end_.map (𝟙 F) = 𝟙 _ := by cat_disch end variable (J C) in /-- If all bifunctors `Jᵒᵖ ⥤ J ⥤ C` have an end, then the construction `F ↦ end_ F` defines a functor `(Jᵒᵖ ⥤ J ⥤ C) ⥤ C`. -/ @[simps] noncomputable def endFunctor [∀ (F : Jᵒᵖ ⥤ J ⥤ C), HasEnd F] : (Jᵒᵖ ⥤ J ⥤ C) ⥤ C where obj F := end_ F map f := end_.map f end End section Coend /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this property asserts the existence of the coend of `F`. -/ abbrev HasCoend := HasMulticoequalizer (multispanIndexCoend F) variable [HasCoend F] /-- The end of a functor `F : Jᵒᵖ ⥤ J ⥤ C`. -/ noncomputable def coend : C := multicoequalizer (multispanIndexCoend F) /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the inclusion `(F.obj (op j)).obj j ⟶ coend F` for any `j : J`. -/ noncomputable def coend.ι (j : J) : (F.obj (op j)).obj j ⟶ coend F := Multicoequalizer.π (multispanIndexCoend F) _ @[reassoc] lemma coend.condition {i j : J} (f : i ⟶ j) : (F.map f.op).app i ≫ ι F i = (F.obj (op j)).map f ≫ ι F j := by apply Cowedge.condition variable {F} @[ext] lemma coend.hom_ext {X : C} {f g : coend F ⟶ X} (h : ∀ j, coend.ι F j ≫ f = coend.ι F j ≫ g) : f = g := Multicoequalizer.hom_ext _ _ _ (fun _ ↦ h _) section variable {X : C} (f : ∀ j, (F.obj (op j)).obj j ⟶ X) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), (F.map g.op).app i ≫ f i = (F.obj (op j)).map g ≫ f j) /-- Constructor for morphisms to the coend of a functor. -/ noncomputable def coend.desc : coend F ⟶ X := Cowedge.IsColimit.desc (colimit.isColimit _) f hf @[reassoc (attr := simp)] lemma coend.ι_desc (j : J) : ι F j ≫ desc f hf = f j := by apply IsColimit.fac variable {F' : Jᵒᵖ ⥤ J ⥤ C} [HasCoend F'] (f : F ⟶ F') /-- A natural transformation of functors F ⟶ F' induces a map coend F ⟶ coend F'. -/ noncomputable def coend.map : coend F ⟶ coend F' := coend.desc (fun x ↦ (f.app (op x)).app x ≫ coend.ι _ _ ) (fun j j' φ ↦ by simp [coend.condition]) @[reassoc (attr := simp)] lemma coend.ι_map (j : J) : coend.ι _ _ ≫ coend.map f = (f.app (op j)).app j ≫ coend.ι _ _ := by simp [coend.map] @[reassoc (attr := simp)] lemma coend.map_comp {F'' : Jᵒᵖ ⥤ J ⥤ C} [HasCoend F''] (g : F' ⟶ F'') : coend.map f ≫ coend.map g = coend.map (f ≫ g) := by cat_disch @[simp] lemma coend.map_id : coend.map (𝟙 F) = 𝟙 _ := by cat_disch end variable (J C) in /-- If all bifunctors `Jᵒᵖ ⥤ J ⥤ C` have a coend, then the construction `F ↦ coend F` defines a functor `(Jᵒᵖ ⥤ J ⥤ C) ⥤ C`. -/ @[simps] noncomputable def coendFunctor [∀ (F : Jᵒᵖ ⥤ J ⥤ C), HasCoend F] : (Jᵒᵖ ⥤ J ⥤ C) ⥤ C where obj F := coend F map f := coend.map f end Coend end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/BinaryBiproducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Biproducts /-! # Binary biproducts We introduce the notion of binary biproducts. These are slightly unusual relative to the other shapes in the library, as they are simultaneously limits and colimits. (Zero objects are similar; they are "biterminal".) For results about biproducts in preadditive categories see `CategoryTheory.Preadditive.Biproducts`. In a category with zero morphisms, we model the (binary) biproduct of `P Q : C` using a `BinaryBicone`, which has a cone point `X`, and morphisms `fst : X ⟶ P`, `snd : X ⟶ Q`, `inl : P ⟶ X` and `inr : X ⟶ Q`, such that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q`. Such a `BinaryBicone` is a biproduct if the cone is a limit cone, and the cocone is a colimit cocone. -/ noncomputable section universe w w' v u open CategoryTheory Functor namespace CategoryTheory.Limits variable {J : Type w} universe uC' uC uD' uD variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] /-- A binary bicone for a pair of objects `P Q : C` consists of the cone point `X`, maps from `X` to both `P` and `Q`, and maps from both `P` and `Q` to `X`, so that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q` -/ structure BinaryBicone (P Q : C) where pt : C fst : pt ⟶ P snd : pt ⟶ Q inl : P ⟶ pt inr : Q ⟶ pt inl_fst : inl ≫ fst = 𝟙 P := by aesop inl_snd : inl ≫ snd = 0 := by aesop inr_fst : inr ≫ fst = 0 := by aesop inr_snd : inr ≫ snd = 𝟙 Q := by aesop attribute [inherit_doc BinaryBicone] BinaryBicone.pt BinaryBicone.fst BinaryBicone.snd BinaryBicone.inl BinaryBicone.inr BinaryBicone.inl_fst BinaryBicone.inl_snd BinaryBicone.inr_fst BinaryBicone.inr_snd attribute [reassoc (attr := simp)] BinaryBicone.inl_fst BinaryBicone.inl_snd BinaryBicone.inr_fst BinaryBicone.inr_snd /-- A binary bicone morphism between two binary bicones for the same diagram is a morphism of the binary bicone points which commutes with the cone and cocone legs. -/ structure BinaryBiconeMorphism {P Q : C} (A B : BinaryBicone P Q) where /-- A morphism between the two vertex objects of the bicones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wfst : hom ≫ B.fst = A.fst := by cat_disch /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wsnd : hom ≫ B.snd = A.snd := by cat_disch /-- The triangle consisting of the two natural transformations and `hom` commutes -/ winl : A.inl ≫ hom = B.inl := by cat_disch /-- The triangle consisting of the two natural transformations and `hom` commutes -/ winr : A.inr ≫ hom = B.inr := by cat_disch attribute [reassoc (attr := simp)] BinaryBiconeMorphism.wfst BinaryBiconeMorphism.wsnd attribute [reassoc (attr := simp)] BinaryBiconeMorphism.winl BinaryBiconeMorphism.winr /-- The category of binary bicones on a given diagram. -/ @[simps] instance BinaryBicone.category {P Q : C} : Category (BinaryBicone P Q) where Hom A B := BinaryBiconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } /- We do not want `simps` automatically generate the lemma for simplifying the `Hom` field of -- a category. So we need to write the `ext` lemma in terms of the categorical morphism, rather than the underlying structure. -/ @[ext] theorem BinaryBiconeMorphism.ext {P Q : C} {c c' : BinaryBicone P Q} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace BinaryBicones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {P Q : C} {c c' : BinaryBicone P Q} (φ : c.pt ≅ c'.pt) (winl : c.inl ≫ φ.hom = c'.inl := by cat_disch) (winr : c.inr ≫ φ.hom = c'.inr := by cat_disch) (wfst : φ.hom ≫ c'.fst = c.fst := by cat_disch) (wsnd : φ.hom ≫ c'.snd = c.snd := by cat_disch) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv wfst := φ.inv_comp_eq.mpr wfst.symm wsnd := φ.inv_comp_eq.mpr wsnd.symm winl := φ.comp_inv_eq.mpr winl.symm winr := φ.comp_inv_eq.mpr winr.symm } variable (P Q : C) (F : C ⥤ D) [Functor.PreservesZeroMorphisms F] /-- A functor `F : C ⥤ D` sends binary bicones for `P` and `Q` to binary bicones for `G.obj P` and `G.obj Q` functorially. -/ @[simps] def functoriality : BinaryBicone P Q ⥤ BinaryBicone (F.obj P) (F.obj Q) where obj A := { pt := F.obj A.pt fst := F.map A.fst snd := F.map A.snd inl := F.map A.inl inr := F.map A.inr inl_fst := by rw [← F.map_comp, A.inl_fst, F.map_id] inl_snd := by rw [← F.map_comp, A.inl_snd, F.map_zero] inr_fst := by rw [← F.map_comp, A.inr_fst, F.map_zero] inr_snd := by rw [← F.map_comp, A.inr_snd, F.map_id] } map f := { hom := F.map f.hom wfst := by simp [-BinaryBiconeMorphism.wfst, ← f.wfst] wsnd := by simp [-BinaryBiconeMorphism.wsnd, ← f.wsnd] winl := by simp [-BinaryBiconeMorphism.winl, ← f.winl] winr := by simp [-BinaryBiconeMorphism.winr, ← f.winr] } instance functoriality_full [F.Full] [F.Faithful] : (functoriality P Q F).Full where map_surjective t := ⟨{ hom := F.preimage t.hom winl := F.map_injective (by simpa using t.winl) winr := F.map_injective (by simpa using t.winr) wfst := F.map_injective (by simpa using t.wfst) wsnd := F.map_injective (by simpa using t.wsnd) }, by cat_disch⟩ instance functoriality_faithful [F.Faithful] : (functoriality P Q F).Faithful where map_injective {_X} {_Y} f g h := BinaryBiconeMorphism.ext f g <| F.map_injective <| congr_arg BinaryBiconeMorphism.hom h end BinaryBicones namespace BinaryBicone variable {P Q : C} /-- Extract the cone from a binary bicone. -/ def toCone (c : BinaryBicone P Q) : Cone (pair P Q) := BinaryFan.mk c.fst c.snd @[simp] theorem toCone_pt (c : BinaryBicone P Q) : c.toCone.pt = c.pt := rfl @[simp] theorem toCone_π_app_left (c : BinaryBicone P Q) : c.toCone.π.app ⟨WalkingPair.left⟩ = c.fst := rfl @[simp] theorem toCone_π_app_right (c : BinaryBicone P Q) : c.toCone.π.app ⟨WalkingPair.right⟩ = c.snd := rfl @[simp] theorem binary_fan_fst_toCone (c : BinaryBicone P Q) : BinaryFan.fst c.toCone = c.fst := rfl @[simp] theorem binary_fan_snd_toCone (c : BinaryBicone P Q) : BinaryFan.snd c.toCone = c.snd := rfl /-- Extract the cocone from a binary bicone. -/ def toCocone (c : BinaryBicone P Q) : Cocone (pair P Q) := BinaryCofan.mk c.inl c.inr @[simp] theorem toCocone_pt (c : BinaryBicone P Q) : c.toCocone.pt = c.pt := rfl @[simp] theorem toCocone_ι_app_left (c : BinaryBicone P Q) : c.toCocone.ι.app ⟨WalkingPair.left⟩ = c.inl := rfl @[simp] theorem toCocone_ι_app_right (c : BinaryBicone P Q) : c.toCocone.ι.app ⟨WalkingPair.right⟩ = c.inr := rfl @[simp] theorem binary_cofan_inl_toCocone (c : BinaryBicone P Q) : BinaryCofan.inl c.toCocone = c.inl := rfl @[simp] theorem binary_cofan_inr_toCocone (c : BinaryBicone P Q) : BinaryCofan.inr c.toCocone = c.inr := rfl instance (c : BinaryBicone P Q) : IsSplitMono c.inl := IsSplitMono.mk' { retraction := c.fst id := c.inl_fst } instance (c : BinaryBicone P Q) : IsSplitMono c.inr := IsSplitMono.mk' { retraction := c.snd id := c.inr_snd } instance (c : BinaryBicone P Q) : IsSplitEpi c.fst := IsSplitEpi.mk' { section_ := c.inl id := c.inl_fst } instance (c : BinaryBicone P Q) : IsSplitEpi c.snd := IsSplitEpi.mk' { section_ := c.inr id := c.inr_snd } /-- Convert a `BinaryBicone` into a `Bicone` over a pair. -/ @[simps] def toBiconeFunctor {X Y : C} : BinaryBicone X Y ⥤ Bicone (pairFunction X Y) where obj b := { pt := b.pt π := fun j => WalkingPair.casesOn j b.fst b.snd ι := fun j => WalkingPair.casesOn j b.inl b.inr ι_π := fun j j' => by rcases j with ⟨⟩ <;> rcases j' with ⟨⟩ <;> simp } map f := { hom := f.hom wπ := fun i => WalkingPair.casesOn i f.wfst f.wsnd wι := fun i => WalkingPair.casesOn i f.winl f.winr } /-- A shorthand for `toBiconeFunctor.obj` -/ abbrev toBicone {X Y : C} (b : BinaryBicone X Y) : Bicone (pairFunction X Y) := toBiconeFunctor.obj b /-- A binary bicone is a limit cone if and only if the corresponding bicone is a limit cone. -/ def toBiconeIsLimit {X Y : C} (b : BinaryBicone X Y) : IsLimit b.toBicone.toCone ≃ IsLimit b.toCone := IsLimit.equivIsoLimit <| Cones.ext (Iso.refl _) fun ⟨as⟩ => by cases as <;> simp /-- A binary bicone is a colimit cocone if and only if the corresponding bicone is a colimit cocone. -/ def toBiconeIsColimit {X Y : C} (b : BinaryBicone X Y) : IsColimit b.toBicone.toCocone ≃ IsColimit b.toCocone := IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) fun ⟨as⟩ => by cases as <;> simp end BinaryBicone namespace Bicone /-- Convert a `Bicone` over a function on `WalkingPair` to a BinaryBicone. -/ @[simps] def toBinaryBiconeFunctor {X Y : C} : Bicone (pairFunction X Y) ⥤ BinaryBicone X Y where obj b := { pt := b.pt fst := b.π WalkingPair.left snd := b.π WalkingPair.right inl := b.ι WalkingPair.left inr := b.ι WalkingPair.right inl_fst := by simp inr_fst := by simp inl_snd := by simp inr_snd := by simp } map f := { hom := f.hom } /-- A shorthand for `toBinaryBiconeFunctor.obj` -/ abbrev toBinaryBicone {X Y : C} (b : Bicone (pairFunction X Y)) : BinaryBicone X Y := toBinaryBiconeFunctor.obj b /-- A bicone over a pair is a limit cone if and only if the corresponding binary bicone is a limit cone. -/ def toBinaryBiconeIsLimit {X Y : C} (b : Bicone (pairFunction X Y)) : IsLimit b.toBinaryBicone.toCone ≃ IsLimit b.toCone := IsLimit.equivIsoLimit <| Cones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp /-- A bicone over a pair is a colimit cocone if and only if the corresponding binary bicone is a colimit cocone. -/ def toBinaryBiconeIsColimit {X Y : C} (b : Bicone (pairFunction X Y)) : IsColimit b.toBinaryBicone.toCocone ≃ IsColimit b.toCocone := IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp end Bicone /-- Structure witnessing that a binary bicone is a limit cone and a limit cocone. -/ structure BinaryBicone.IsBilimit {P Q : C} (b : BinaryBicone P Q) where isLimit : IsLimit b.toCone isColimit : IsColimit b.toCocone attribute [inherit_doc BinaryBicone.IsBilimit] BinaryBicone.IsBilimit.isLimit BinaryBicone.IsBilimit.isColimit /-- A binary bicone is a bilimit bicone if and only if the corresponding bicone is a bilimit. -/ def BinaryBicone.toBiconeIsBilimit {X Y : C} (b : BinaryBicone X Y) : b.toBicone.IsBilimit ≃ b.IsBilimit where toFun h := ⟨b.toBiconeIsLimit h.isLimit, b.toBiconeIsColimit h.isColimit⟩ invFun h := ⟨b.toBiconeIsLimit.symm h.isLimit, b.toBiconeIsColimit.symm h.isColimit⟩ left_inv := fun ⟨h, h'⟩ => by dsimp only; simp right_inv := fun ⟨h, h'⟩ => by dsimp only; simp /-- A bicone over a pair is a bilimit bicone if and only if the corresponding binary bicone is a bilimit. -/ def Bicone.toBinaryBiconeIsBilimit {X Y : C} (b : Bicone (pairFunction X Y)) : b.toBinaryBicone.IsBilimit ≃ b.IsBilimit where toFun h := ⟨b.toBinaryBiconeIsLimit h.isLimit, b.toBinaryBiconeIsColimit h.isColimit⟩ invFun h := ⟨b.toBinaryBiconeIsLimit.symm h.isLimit, b.toBinaryBiconeIsColimit.symm h.isColimit⟩ left_inv := fun ⟨h, h'⟩ => by dsimp only; simp right_inv := fun ⟨h, h'⟩ => by dsimp only; simp /-- A bicone over `P Q : C`, which is both a limit cone and a colimit cocone. -/ structure BinaryBiproductData (P Q : C) where bicone : BinaryBicone P Q isBilimit : bicone.IsBilimit attribute [inherit_doc BinaryBiproductData] BinaryBiproductData.bicone BinaryBiproductData.isBilimit /-- `HasBinaryBiproduct P Q` expresses the mere existence of a bicone which is simultaneously a limit and a colimit of the diagram `pair P Q`. -/ class HasBinaryBiproduct (P Q : C) : Prop where mk' :: exists_binary_biproduct : Nonempty (BinaryBiproductData P Q) attribute [inherit_doc HasBinaryBiproduct] HasBinaryBiproduct.exists_binary_biproduct theorem HasBinaryBiproduct.mk {P Q : C} (d : BinaryBiproductData P Q) : HasBinaryBiproduct P Q := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `BinaryBiproductData F` from `HasBinaryBiproduct F`. -/ def getBinaryBiproductData (P Q : C) [HasBinaryBiproduct P Q] : BinaryBiproductData P Q := Classical.choice HasBinaryBiproduct.exists_binary_biproduct /-- A bicone for `P Q` which is both a limit cone and a colimit cocone. -/ def BinaryBiproduct.bicone (P Q : C) [HasBinaryBiproduct P Q] : BinaryBicone P Q := (getBinaryBiproductData P Q).bicone /-- `BinaryBiproduct.bicone P Q` is a limit bicone. -/ def BinaryBiproduct.isBilimit (P Q : C) [HasBinaryBiproduct P Q] : (BinaryBiproduct.bicone P Q).IsBilimit := (getBinaryBiproductData P Q).isBilimit /-- `BinaryBiproduct.bicone P Q` is a limit cone. -/ def BinaryBiproduct.isLimit (P Q : C) [HasBinaryBiproduct P Q] : IsLimit (BinaryBiproduct.bicone P Q).toCone := (getBinaryBiproductData P Q).isBilimit.isLimit /-- `BinaryBiproduct.bicone P Q` is a colimit cocone. -/ def BinaryBiproduct.isColimit (P Q : C) [HasBinaryBiproduct P Q] : IsColimit (BinaryBiproduct.bicone P Q).toCocone := (getBinaryBiproductData P Q).isBilimit.isColimit section variable (C) /-- `HasBinaryBiproducts C` represents the existence of a bicone which is simultaneously a limit and a colimit of the diagram `pair P Q`, for every `P Q : C`. -/ class HasBinaryBiproducts : Prop where has_binary_biproduct : ∀ P Q : C, HasBinaryBiproduct P Q attribute [instance 100] HasBinaryBiproducts.has_binary_biproduct /-- A category with finite biproducts has binary biproducts. This is not an instance as typically in concrete categories there will be an alternative construction with nicer definitional properties. -/ theorem hasBinaryBiproducts_of_finite_biproducts [HasFiniteBiproducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun P Q => HasBinaryBiproduct.mk { bicone := (biproduct.bicone (pairFunction P Q)).toBinaryBicone isBilimit := (Bicone.toBinaryBiconeIsBilimit _).symm (biproduct.isBilimit _) } } end variable {P Q : C} instance HasBinaryBiproduct.hasLimit_pair [HasBinaryBiproduct P Q] : HasLimit (pair P Q) := HasLimit.mk ⟨_, BinaryBiproduct.isLimit P Q⟩ instance HasBinaryBiproduct.hasColimit_pair [HasBinaryBiproduct P Q] : HasColimit (pair P Q) := HasColimit.mk ⟨_, BinaryBiproduct.isColimit P Q⟩ instance (priority := 100) hasBinaryProducts_of_hasBinaryBiproducts [HasBinaryBiproducts C] : HasBinaryProducts C where has_limit F := hasLimit_of_iso (diagramIsoPair F).symm instance (priority := 100) hasBinaryCoproducts_of_hasBinaryBiproducts [HasBinaryBiproducts C] : HasBinaryCoproducts C where has_colimit F := hasColimit_of_iso (diagramIsoPair F) /-- The isomorphism between the specified binary product and the specified binary coproduct for a pair for a binary biproduct. -/ def biprodIso (X Y : C) [HasBinaryBiproduct X Y] : Limits.prod X Y ≅ Limits.coprod X Y := (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (BinaryBiproduct.isLimit X Y)).trans <| IsColimit.coconePointUniqueUpToIso (BinaryBiproduct.isColimit X Y) (colimit.isColimit _) /-- An arbitrary choice of biproduct of a pair of objects. -/ abbrev biprod (X Y : C) [HasBinaryBiproduct X Y] := (BinaryBiproduct.bicone X Y).pt @[inherit_doc biprod] notation:20 X " ⊞ " Y:20 => biprod X Y /-- The projection onto the first summand of a binary biproduct. -/ abbrev biprod.fst {X Y : C} [HasBinaryBiproduct X Y] : X ⊞ Y ⟶ X := (BinaryBiproduct.bicone X Y).fst /-- The projection onto the second summand of a binary biproduct. -/ abbrev biprod.snd {X Y : C} [HasBinaryBiproduct X Y] : X ⊞ Y ⟶ Y := (BinaryBiproduct.bicone X Y).snd /-- The inclusion into the first summand of a binary biproduct. -/ abbrev biprod.inl {X Y : C} [HasBinaryBiproduct X Y] : X ⟶ X ⊞ Y := (BinaryBiproduct.bicone X Y).inl /-- The inclusion into the second summand of a binary biproduct. -/ abbrev biprod.inr {X Y : C} [HasBinaryBiproduct X Y] : Y ⟶ X ⊞ Y := (BinaryBiproduct.bicone X Y).inr section variable {X Y : C} [HasBinaryBiproduct X Y] @[simp] theorem BinaryBiproduct.bicone_fst : (BinaryBiproduct.bicone X Y).fst = biprod.fst := rfl @[simp] theorem BinaryBiproduct.bicone_snd : (BinaryBiproduct.bicone X Y).snd = biprod.snd := rfl @[simp] theorem BinaryBiproduct.bicone_inl : (BinaryBiproduct.bicone X Y).inl = biprod.inl := rfl @[simp] theorem BinaryBiproduct.bicone_inr : (BinaryBiproduct.bicone X Y).inr = biprod.inr := rfl end @[reassoc] theorem biprod.inl_fst {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inl : X ⟶ X ⊞ Y) ≫ (biprod.fst : X ⊞ Y ⟶ X) = 𝟙 X := (BinaryBiproduct.bicone X Y).inl_fst @[reassoc] theorem biprod.inl_snd {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inl : X ⟶ X ⊞ Y) ≫ (biprod.snd : X ⊞ Y ⟶ Y) = 0 := (BinaryBiproduct.bicone X Y).inl_snd @[reassoc] theorem biprod.inr_fst {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inr : Y ⟶ X ⊞ Y) ≫ (biprod.fst : X ⊞ Y ⟶ X) = 0 := (BinaryBiproduct.bicone X Y).inr_fst @[reassoc] theorem biprod.inr_snd {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inr : Y ⟶ X ⊞ Y) ≫ (biprod.snd : X ⊞ Y ⟶ Y) = 𝟙 Y := (BinaryBiproduct.bicone X Y).inr_snd /-- Given a pair of maps into the summands of a binary biproduct, we obtain a map into the binary biproduct. -/ abbrev biprod.lift {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⊞ Y := (BinaryBiproduct.isLimit X Y).lift (BinaryFan.mk f g) /-- Given a pair of maps out of the summands of a binary biproduct, we obtain a map out of the binary biproduct. -/ abbrev biprod.desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⊞ Y ⟶ W := (BinaryBiproduct.isColimit X Y).desc (BinaryCofan.mk f g) @[reassoc (attr := simp)] theorem biprod.lift_fst {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : biprod.lift f g ≫ biprod.fst = f := (BinaryBiproduct.isLimit X Y).fac _ ⟨WalkingPair.left⟩ @[reassoc (attr := simp)] theorem biprod.lift_snd {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : biprod.lift f g ≫ biprod.snd = g := (BinaryBiproduct.isLimit X Y).fac _ ⟨WalkingPair.right⟩ @[reassoc (attr := simp)] theorem biprod.inl_desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : biprod.inl ≫ biprod.desc f g = f := (BinaryBiproduct.isColimit X Y).fac _ ⟨WalkingPair.left⟩ @[reassoc (attr := simp)] theorem biprod.inr_desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : biprod.inr ≫ biprod.desc f g = g := (BinaryBiproduct.isColimit X Y).fac _ ⟨WalkingPair.right⟩ instance biprod.mono_lift_of_mono_left {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (biprod.lift f g) := mono_of_mono_fac <| biprod.lift_fst _ _ instance biprod.mono_lift_of_mono_right {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (biprod.lift f g) := mono_of_mono_fac <| biprod.lift_snd _ _ instance biprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (biprod.desc f g) := epi_of_epi_fac <| biprod.inl_desc _ _ instance biprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (biprod.desc f g) := epi_of_epi_fac <| biprod.inr_desc _ _ /-- Given a pair of maps between the summands of a pair of binary biproducts, we obtain a map between the binary biproducts. -/ abbrev biprod.map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z := IsLimit.map (BinaryBiproduct.bicone W X).toCone (BinaryBiproduct.isLimit Y Z) (@mapPair _ _ (pair W X) (pair Y Z) f g) /-- An alternative to `biprod.map` constructed via colimits. This construction only exists in order to show it is equal to `biprod.map`. -/ abbrev biprod.map' {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z := IsColimit.map (BinaryBiproduct.isColimit W X) (BinaryBiproduct.bicone Y Z).toCocone (@mapPair _ _ (pair W X) (pair Y Z) f g) @[ext] theorem biprod.hom_ext {X Y Z : C} [HasBinaryBiproduct X Y] (f g : Z ⟶ X ⊞ Y) (h₀ : f ≫ biprod.fst = g ≫ biprod.fst) (h₁ : f ≫ biprod.snd = g ≫ biprod.snd) : f = g := BinaryFan.IsLimit.hom_ext (BinaryBiproduct.isLimit X Y) h₀ h₁ @[ext] theorem biprod.hom_ext' {X Y Z : C} [HasBinaryBiproduct X Y] (f g : X ⊞ Y ⟶ Z) (h₀ : biprod.inl ≫ f = biprod.inl ≫ g) (h₁ : biprod.inr ≫ f = biprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (BinaryBiproduct.isColimit X Y) h₀ h₁ /-- The canonical isomorphism between the chosen biproduct and the chosen product. -/ def biprod.isoProd (X Y : C) [HasBinaryBiproduct X Y] : X ⊞ Y ≅ X ⨯ Y := IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit X Y) (limit.isLimit _) @[simp] theorem biprod.isoProd_hom {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoProd X Y).hom = prod.lift biprod.fst biprod.snd := by ext <;> simp [biprod.isoProd] @[simp] theorem biprod.isoProd_inv {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoProd X Y).inv = biprod.lift prod.fst prod.snd := by ext <;> simp [Iso.inv_comp_eq] /-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/ def biprod.isoCoprod (X Y : C) [HasBinaryBiproduct X Y] : X ⊞ Y ≅ X ⨿ Y := IsColimit.coconePointUniqueUpToIso (BinaryBiproduct.isColimit X Y) (colimit.isColimit _) @[simp] theorem biprod.isoCoprod_inv {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoCoprod X Y).inv = coprod.desc biprod.inl biprod.inr := by ext <;> simp [biprod.isoCoprod] @[simp] theorem biprod_isoCoprod_hom {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoCoprod X Y).hom = biprod.desc coprod.inl coprod.inr := by ext <;> simp [← Iso.eq_comp_inv] theorem biprod.map_eq_map' {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.map f g = biprod.map' f g := by ext · simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBicone.toCocone_ι_app_left] simp · simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBicone.toCocone_ι_app_left] simp · simp only [mapPair_right, IsColimit.ι_map, IsLimit.map_π, Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBicone.toCocone_ι_app_right] simp · simp only [mapPair_right, IsColimit.ι_map, IsLimit.map_π, Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBicone.toCocone_ι_app_right] simp instance biprod.inl_mono {X Y : C} [HasBinaryBiproduct X Y] : IsSplitMono (biprod.inl : X ⟶ X ⊞ Y) := IsSplitMono.mk' { retraction := biprod.fst } instance biprod.inr_mono {X Y : C} [HasBinaryBiproduct X Y] : IsSplitMono (biprod.inr : Y ⟶ X ⊞ Y) := IsSplitMono.mk' { retraction := biprod.snd } instance biprod.fst_epi {X Y : C} [HasBinaryBiproduct X Y] : IsSplitEpi (biprod.fst : X ⊞ Y ⟶ X) := IsSplitEpi.mk' { section_ := biprod.inl } instance biprod.snd_epi {X Y : C} [HasBinaryBiproduct X Y] : IsSplitEpi (biprod.snd : X ⊞ Y ⟶ Y) := IsSplitEpi.mk' { section_ := biprod.inr } @[reassoc (attr := simp)] theorem biprod.map_fst {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.map f g ≫ biprod.fst = biprod.fst ≫ f := IsLimit.map_π _ _ _ (⟨WalkingPair.left⟩ : Discrete WalkingPair) @[reassoc (attr := simp)] theorem biprod.map_snd {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.map f g ≫ biprod.snd = biprod.snd ≫ g := IsLimit.map_π _ _ _ (⟨WalkingPair.right⟩ : Discrete WalkingPair) -- Because `biprod.map` is defined in terms of `lim` rather than `colim`, -- we need to provide additional `simp` lemmas. @[reassoc (attr := simp)] theorem biprod.inl_map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.inl ≫ biprod.map f g = f ≫ biprod.inl := by rw [biprod.map_eq_map'] exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.left⟩ @[reassoc (attr := simp)] theorem biprod.inr_map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.inr ≫ biprod.map f g = g ≫ biprod.inr := by rw [biprod.map_eq_map'] exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.right⟩ /-- Given a pair of isomorphisms between the summands of a pair of binary biproducts, we obtain an isomorphism between the binary biproducts. -/ @[simps] def biprod.mapIso {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⊞ X ≅ Y ⊞ Z where hom := biprod.map f.hom g.hom inv := biprod.map f.inv g.inv /-- Auxiliary lemma for `biprod.uniqueUpToIso`. -/ theorem biprod.conePointUniqueUpToIso_hom (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit _ _)).hom = biprod.lift b.fst b.snd := rfl /-- Auxiliary lemma for `biprod.uniqueUpToIso`. -/ theorem biprod.conePointUniqueUpToIso_inv (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit _ _)).inv = biprod.desc b.inl b.inr := by refine biprod.hom_ext' _ _ (hb.isLimit.hom_ext fun j => ?_) (hb.isLimit.hom_ext fun j => ?_) all_goals simp only [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp] rcases j with ⟨⟨⟩⟩ all_goals simp /-- Binary biproducts are unique up to isomorphism. This already follows because bilimits are limits, but in the case of biproducts we can give an isomorphism with particularly nice definitional properties, namely that `biprod.lift b.fst b.snd` and `biprod.desc b.inl b.inr` are inverses of each other. -/ @[simps] def biprod.uniqueUpToIso (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y} (hb : b.IsBilimit) : b.pt ≅ X ⊞ Y where hom := biprod.lift b.fst b.snd inv := biprod.desc b.inl b.inr hom_inv_id := by rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ← biprod.conePointUniqueUpToIso_inv X Y hb, Iso.hom_inv_id] inv_hom_id := by rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ← biprod.conePointUniqueUpToIso_inv X Y hb, Iso.inv_hom_id] -- There are three further variations, -- about `IsIso biprod.inr`, `IsIso biprod.fst` and `IsIso biprod.snd`, -- but any one suffices to prove `indecomposable_of_simple` -- and they are likely not separately useful. theorem biprod.isIso_inl_iff_id_eq_fst_comp_inl (X Y : C) [HasBinaryBiproduct X Y] : IsIso (biprod.inl : X ⟶ X ⊞ Y) ↔ 𝟙 (X ⊞ Y) = biprod.fst ≫ biprod.inl := by constructor · intro h have := (cancel_epi (inv biprod.inl : X ⊞ Y ⟶ X)).2 <| @biprod.inl_fst _ _ _ X Y _ rw [IsIso.inv_hom_id_assoc, Category.comp_id] at this rw [this, IsIso.inv_hom_id] · intro h exact ⟨⟨biprod.fst, biprod.inl_fst, h.symm⟩⟩ instance biprod.map_epi {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f] [Epi g] [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] : Epi (biprod.map f g) := by rw [show biprod.map f g = (biprod.isoCoprod _ _).hom ≫ coprod.map f g ≫ (biprod.isoCoprod _ _).inv by aesop] infer_instance instance prod.map_epi {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f] [Epi g] [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] : Epi (prod.map f g) := by rw [show prod.map f g = (biprod.isoProd _ _).inv ≫ biprod.map f g ≫ (biprod.isoProd _ _).hom by simp] infer_instance instance biprod.map_mono {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] : Mono (biprod.map f g) := by rw [show biprod.map f g = (biprod.isoProd _ _).hom ≫ prod.map f g ≫ (biprod.isoProd _ _).inv by aesop] infer_instance instance coprod.map_mono {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] : Mono (coprod.map f g) := by rw [show coprod.map f g = (biprod.isoCoprod _ _).inv ≫ biprod.map f g ≫ (biprod.isoCoprod _ _).hom by simp] infer_instance section BiprodKernel section BinaryBicone variable {X Y : C} (c : BinaryBicone X Y) /-- A kernel fork for the kernel of `BinaryBicone.fst`. It consists of the morphism `BinaryBicone.inr`. -/ def BinaryBicone.fstKernelFork : KernelFork c.fst := KernelFork.ofι c.inr c.inr_fst @[simp] theorem BinaryBicone.fstKernelFork_ι : (BinaryBicone.fstKernelFork c).ι = c.inr := rfl /-- A kernel fork for the kernel of `BinaryBicone.snd`. It consists of the morphism `BinaryBicone.inl`. -/ def BinaryBicone.sndKernelFork : KernelFork c.snd := KernelFork.ofι c.inl c.inl_snd @[simp] theorem BinaryBicone.sndKernelFork_ι : (BinaryBicone.sndKernelFork c).ι = c.inl := rfl /-- A cokernel cofork for the cokernel of `BinaryBicone.inl`. It consists of the morphism `BinaryBicone.snd`. -/ def BinaryBicone.inlCokernelCofork : CokernelCofork c.inl := CokernelCofork.ofπ c.snd c.inl_snd @[simp] theorem BinaryBicone.inlCokernelCofork_π : (BinaryBicone.inlCokernelCofork c).π = c.snd := rfl /-- A cokernel cofork for the cokernel of `BinaryBicone.inr`. It consists of the morphism `BinaryBicone.fst`. -/ def BinaryBicone.inrCokernelCofork : CokernelCofork c.inr := CokernelCofork.ofπ c.fst c.inr_fst @[simp] theorem BinaryBicone.inrCokernelCofork_π : (BinaryBicone.inrCokernelCofork c).π = c.fst := rfl variable {c} /-- The fork defined in `BinaryBicone.fstKernelFork` is indeed a kernel. -/ def BinaryBicone.isLimitFstKernelFork (i : IsLimit c.toCone) : IsLimit c.fstKernelFork := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ c.snd, by apply BinaryFan.IsLimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ /-- The fork defined in `BinaryBicone.sndKernelFork` is indeed a kernel. -/ def BinaryBicone.isLimitSndKernelFork (i : IsLimit c.toCone) : IsLimit c.sndKernelFork := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ c.fst, by apply BinaryFan.IsLimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ /-- The cofork defined in `BinaryBicone.inlCokernelCofork` is indeed a cokernel. -/ def BinaryBicone.isColimitInlCokernelCofork (i : IsColimit c.toCocone) : IsColimit c.inlCokernelCofork := Cofork.IsColimit.mk' _ fun s => ⟨c.inr ≫ s.π, by apply BinaryCofan.IsColimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ /-- The cofork defined in `BinaryBicone.inrCokernelCofork` is indeed a cokernel. -/ def BinaryBicone.isColimitInrCokernelCofork (i : IsColimit c.toCocone) : IsColimit c.inrCokernelCofork := Cofork.IsColimit.mk' _ fun s => ⟨c.inl ≫ s.π, by apply BinaryCofan.IsColimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ end BinaryBicone section HasBinaryBiproduct variable (X Y : C) [HasBinaryBiproduct X Y] /-- A kernel fork for the kernel of `biprod.fst`. It consists of the morphism `biprod.inr`. -/ def biprod.fstKernelFork : KernelFork (biprod.fst : X ⊞ Y ⟶ X) := BinaryBicone.fstKernelFork _ @[simp] theorem biprod.fstKernelFork_ι : Fork.ι (biprod.fstKernelFork X Y) = (biprod.inr : Y ⟶ X ⊞ Y) := rfl /-- The fork `biprod.fstKernelFork` is indeed a limit. -/ def biprod.isKernelFstKernelFork : IsLimit (biprod.fstKernelFork X Y) := BinaryBicone.isLimitFstKernelFork (BinaryBiproduct.isLimit _ _) /-- A kernel fork for the kernel of `biprod.snd`. It consists of the morphism `biprod.inl`. -/ def biprod.sndKernelFork : KernelFork (biprod.snd : X ⊞ Y ⟶ Y) := BinaryBicone.sndKernelFork _ @[simp] theorem biprod.sndKernelFork_ι : Fork.ι (biprod.sndKernelFork X Y) = (biprod.inl : X ⟶ X ⊞ Y) := rfl /-- The fork `biprod.sndKernelFork` is indeed a limit. -/ def biprod.isKernelSndKernelFork : IsLimit (biprod.sndKernelFork X Y) := BinaryBicone.isLimitSndKernelFork (BinaryBiproduct.isLimit _ _) /-- A cokernel cofork for the cokernel of `biprod.inl`. It consists of the morphism `biprod.snd`. -/ def biprod.inlCokernelCofork : CokernelCofork (biprod.inl : X ⟶ X ⊞ Y) := BinaryBicone.inlCokernelCofork _ @[simp] theorem biprod.inlCokernelCofork_π : Cofork.π (biprod.inlCokernelCofork X Y) = biprod.snd := rfl /-- The cofork `biprod.inlCokernelFork` is indeed a colimit. -/ def biprod.isCokernelInlCokernelFork : IsColimit (biprod.inlCokernelCofork X Y) := BinaryBicone.isColimitInlCokernelCofork (BinaryBiproduct.isColimit _ _) /-- A cokernel cofork for the cokernel of `biprod.inr`. It consists of the morphism `biprod.fst`. -/ def biprod.inrCokernelCofork : CokernelCofork (biprod.inr : Y ⟶ X ⊞ Y) := BinaryBicone.inrCokernelCofork _ @[simp] theorem biprod.inrCokernelCofork_π : Cofork.π (biprod.inrCokernelCofork X Y) = biprod.fst := rfl /-- The cofork `biprod.inrCokernelFork` is indeed a colimit. -/ def biprod.isCokernelInrCokernelFork : IsColimit (biprod.inrCokernelCofork X Y) := BinaryBicone.isColimitInrCokernelCofork (BinaryBiproduct.isColimit _ _) end HasBinaryBiproduct variable {X Y : C} [HasBinaryBiproduct X Y] instance : HasKernel (biprod.fst : X ⊞ Y ⟶ X) := HasLimit.mk ⟨_, biprod.isKernelFstKernelFork X Y⟩ /-- The kernel of `biprod.fst : X ⊞ Y ⟶ X` is `Y`. -/ @[simps!] def kernelBiprodFstIso : kernel (biprod.fst : X ⊞ Y ⟶ X) ≅ Y := limit.isoLimitCone ⟨_, biprod.isKernelFstKernelFork X Y⟩ instance : HasKernel (biprod.snd : X ⊞ Y ⟶ Y) := HasLimit.mk ⟨_, biprod.isKernelSndKernelFork X Y⟩ /-- The kernel of `biprod.snd : X ⊞ Y ⟶ Y` is `X`. -/ @[simps!] def kernelBiprodSndIso : kernel (biprod.snd : X ⊞ Y ⟶ Y) ≅ X := limit.isoLimitCone ⟨_, biprod.isKernelSndKernelFork X Y⟩ instance : HasCokernel (biprod.inl : X ⟶ X ⊞ Y) := HasColimit.mk ⟨_, biprod.isCokernelInlCokernelFork X Y⟩ /-- The cokernel of `biprod.inl : X ⟶ X ⊞ Y` is `Y`. -/ @[simps!] def cokernelBiprodInlIso : cokernel (biprod.inl : X ⟶ X ⊞ Y) ≅ Y := colimit.isoColimitCocone ⟨_, biprod.isCokernelInlCokernelFork X Y⟩ instance : HasCokernel (biprod.inr : Y ⟶ X ⊞ Y) := HasColimit.mk ⟨_, biprod.isCokernelInrCokernelFork X Y⟩ /-- The cokernel of `biprod.inr : Y ⟶ X ⊞ Y` is `X`. -/ @[simps!] def cokernelBiprodInrIso : cokernel (biprod.inr : Y ⟶ X ⊞ Y) ≅ X := colimit.isoColimitCocone ⟨_, biprod.isCokernelInrCokernelFork X Y⟩ end BiprodKernel section IsZero /-- If `Y` is a zero object, `X ≅ X ⊞ Y` for any `X`. -/ @[simps!] def isoBiprodZero {X Y : C} [HasBinaryBiproduct X Y] (hY : IsZero Y) : X ≅ X ⊞ Y where hom := biprod.inl inv := biprod.fst inv_hom_id := by apply CategoryTheory.Limits.biprod.hom_ext <;> simp only [Category.assoc, biprod.inl_fst, Category.comp_id, Category.id_comp, biprod.inl_snd, comp_zero] apply hY.eq_of_tgt /-- If `X` is a zero object, `Y ≅ X ⊞ Y` for any `Y`. -/ @[simps] def isoZeroBiprod {X Y : C} [HasBinaryBiproduct X Y] (hY : IsZero X) : Y ≅ X ⊞ Y where hom := biprod.inr inv := biprod.snd inv_hom_id := by apply CategoryTheory.Limits.biprod.hom_ext <;> simp only [Category.assoc, biprod.inr_snd, Category.comp_id, Category.id_comp, biprod.inr_fst, comp_zero] apply hY.eq_of_tgt @[simp] lemma biprod_isZero_iff (A B : C) [HasBinaryBiproduct A B] : IsZero (biprod A B) ↔ IsZero A ∧ IsZero B := by constructor · intro h simp only [IsZero.iff_id_eq_zero] at h ⊢ simp only [show 𝟙 A = biprod.inl ≫ 𝟙 (A ⊞ B) ≫ biprod.fst by simp, show 𝟙 B = biprod.inr ≫ 𝟙 (A ⊞ B) ≫ biprod.snd by simp, h, zero_comp, comp_zero, and_self] · rintro ⟨hA, hB⟩ rw [IsZero.iff_id_eq_zero] apply biprod.hom_ext · apply hA.eq_of_tgt · apply hB.eq_of_tgt end IsZero section variable [HasBinaryBiproducts C] /-- The braiding isomorphism which swaps a binary biproduct. -/ @[simps] def biprod.braiding (P Q : C) : P ⊞ Q ≅ Q ⊞ P where hom := biprod.lift biprod.snd biprod.fst inv := biprod.lift biprod.snd biprod.fst /-- An alternative formula for the braiding isomorphism which swaps a binary biproduct, using the fact that the biproduct is a coproduct. -/ @[simps] def biprod.braiding' (P Q : C) : P ⊞ Q ≅ Q ⊞ P where hom := biprod.desc biprod.inr biprod.inl inv := biprod.desc biprod.inr biprod.inl theorem biprod.braiding'_eq_braiding {P Q : C} : biprod.braiding' P Q = biprod.braiding P Q := by cat_disch /-- The braiding isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem biprod.braid_natural {W X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ W) : biprod.map f g ≫ (biprod.braiding _ _).hom = (biprod.braiding _ _).hom ≫ biprod.map g f := by cat_disch @[reassoc] theorem biprod.braiding_map_braiding {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) : (biprod.braiding X W).hom ≫ biprod.map f g ≫ (biprod.braiding Y Z).hom = biprod.map g f := by cat_disch @[reassoc (attr := simp)] theorem biprod.symmetry' (P Q : C) : biprod.lift biprod.snd biprod.fst ≫ biprod.lift biprod.snd biprod.fst = 𝟙 (P ⊞ Q) := by cat_disch /-- The braiding isomorphism is symmetric. -/ @[reassoc] theorem biprod.symmetry (P Q : C) : (biprod.braiding P Q).hom ≫ (biprod.braiding Q P).hom = 𝟙 _ := by simp /-- The associator isomorphism which associates a binary biproduct. -/ @[simps] def biprod.associator (P Q R : C) : (P ⊞ Q) ⊞ R ≅ P ⊞ (Q ⊞ R) where hom := biprod.lift (biprod.fst ≫ biprod.fst) (biprod.lift (biprod.fst ≫ biprod.snd) biprod.snd) inv := biprod.lift (biprod.lift biprod.fst (biprod.snd ≫ biprod.fst)) (biprod.snd ≫ biprod.snd) /-- The associator isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem biprod.associator_natural {U V W X Y Z : C} (f : U ⟶ X) (g : V ⟶ Y) (h : W ⟶ Z) : biprod.map (biprod.map f g) h ≫ (biprod.associator _ _ _).hom = (biprod.associator _ _ _).hom ≫ biprod.map f (biprod.map g h) := by cat_disch /-- The associator isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem biprod.associator_inv_natural {U V W X Y Z : C} (f : U ⟶ X) (g : V ⟶ Y) (h : W ⟶ Z) : biprod.map f (biprod.map g h) ≫ (biprod.associator _ _ _).inv = (biprod.associator _ _ _).inv ≫ biprod.map (biprod.map f g) h := by cat_disch end end Limits open CategoryTheory.Limits -- TODO: -- If someone is interested, they could provide the constructions: -- HasBinaryBiproducts ↔ HasFiniteBiproducts variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasBinaryBiproducts C] /-- An object is indecomposable if it cannot be written as the biproduct of two nonzero objects. -/ def Indecomposable (X : C) : Prop := ¬IsZero X ∧ ∀ Y Z, (X ≅ Y ⊞ Z) → IsZero Y ∨ IsZero Z /-- If ``` (f 0) (0 g) ``` is invertible, then `f` is invertible. -/ theorem isIso_left_of_isIso_biprod_map {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [IsIso (biprod.map f g)] : IsIso f := ⟨⟨biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst, ⟨by have t := congrArg (fun p : W ⊞ X ⟶ W ⊞ X => biprod.inl ≫ p ≫ biprod.fst) (IsIso.hom_inv_id (biprod.map f g)) simp only [Category.id_comp, Category.assoc, biprod.inl_map_assoc] at t simp [t], by have t := congrArg (fun p : Y ⊞ Z ⟶ Y ⊞ Z => biprod.inl ≫ p ≫ biprod.fst) (IsIso.inv_hom_id (biprod.map f g)) simp only [Category.id_comp, Category.assoc, biprod.map_fst] at t simp only [Category.assoc] simp [t]⟩⟩⟩ /-- If ``` (f 0) (0 g) ``` is invertible, then `g` is invertible. -/ theorem isIso_right_of_isIso_biprod_map {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [IsIso (biprod.map f g)] : IsIso g := letI : IsIso (biprod.map g f) := by rw [← biprod.braiding_map_braiding] infer_instance isIso_left_of_isIso_biprod_map g f end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Kernels.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero /-! # Kernels and cokernels In a category with zero morphisms, the kernel of a morphism `f : X ⟶ Y` is the equalizer of `f` and `0 : X ⟶ Y`. (Similarly the cokernel is the coequalizer.) The basic definitions are * `kernel : (X ⟶ Y) → C` * `kernel.ι : kernel f ⟶ X` * `kernel.condition : kernel.ι f ≫ f = 0` and * `kernel.lift (k : W ⟶ X) (h : k ≫ f = 0) : W ⟶ kernel f` (as well as the dual versions) ## Main statements Besides the definition and lifts, we prove * `kernel.ιZeroIsIso`: a kernel map of a zero morphism is an isomorphism * `kernel.eq_zero_of_epi_kernel`: if `kernel.ι f` is an epimorphism, then `f = 0` * `kernel.ofMono`: the kernel of a monomorphism is the zero object * `kernel.liftMono`: the lift of a monomorphism `k : W ⟶ X` such that `k ≫ f = 0` is still a monomorphism * `kernel.isLimitConeZeroCone`: if our category has a zero object, then the map from the zero object is a kernel map of any monomorphism * `kernel.ιOfZero`: `kernel.ι (0 : X ⟶ Y)` is an isomorphism and the corresponding dual statements. ## Future work * TODO: connect this with existing work in the group theory and ring theory libraries. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v v₂ u u' u₂ open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable [HasZeroMorphisms C] /-- A morphism `f` has a kernel if the functor `ParallelPair f 0` has a limit. -/ abbrev HasKernel {X Y : C} (f : X ⟶ Y) : Prop := HasLimit (parallelPair f 0) /-- A morphism `f` has a cokernel if the functor `ParallelPair f 0` has a colimit. -/ abbrev HasCokernel {X Y : C} (f : X ⟶ Y) : Prop := HasColimit (parallelPair f 0) variable {X Y : C} (f : X ⟶ Y) section /-- A kernel fork is just a fork where the second morphism is a zero morphism. -/ abbrev KernelFork := Fork f 0 variable {f} @[reassoc (attr := simp)] theorem KernelFork.condition (s : KernelFork f) : Fork.ι s ≫ f = 0 := by rw [Fork.condition, HasZeroMorphisms.comp_zero] theorem KernelFork.app_one (s : KernelFork f) : s.π.app one = 0 := by simp /-- A morphism `ι` satisfying `ι ≫ f = 0` determines a kernel fork over `f`. -/ abbrev KernelFork.ofι {Z : C} (ι : Z ⟶ X) (w : ι ≫ f = 0) : KernelFork f := Fork.ofι ι <| by rw [w, HasZeroMorphisms.comp_zero] @[simp] theorem KernelFork.ι_ofι {X Y P : C} (f : X ⟶ Y) (ι : P ⟶ X) (w : ι ≫ f = 0) : Fork.ι (KernelFork.ofι ι w) = ι := rfl section attribute [local aesop safe cases] WalkingParallelPair WalkingParallelPairHom /-- Every kernel fork `s` is isomorphic (actually, equal) to `fork.ofι (fork.ι s) _`. -/ def isoOfι (s : Fork f 0) : s ≅ Fork.ofι (Fork.ι s) (Fork.condition s) := Cones.ext (Iso.refl _) <| by aesop /-- If `ι = ι'`, then `fork.ofι ι _` and `fork.ofι ι' _` are isomorphic. -/ def ofιCongr {P : C} {ι ι' : P ⟶ X} {w : ι ≫ f = 0} (h : ι = ι') : KernelFork.ofι ι w ≅ KernelFork.ofι ι' (by rw [← h, w]) := Cones.ext (Iso.refl _) /-- If `F` is an equivalence, then applying `F` to a diagram indexing a (co)kernel of `f` yields the diagram indexing the (co)kernel of `F.map f`. -/ def compNatIso {D : Type u'} [Category.{v} D] [HasZeroMorphisms D] (F : C ⥤ D) [F.IsEquivalence] : parallelPair f 0 ⋙ F ≅ parallelPair (F.map f) 0 := let app (j : WalkingParallelPair) : (parallelPair f 0 ⋙ F).obj j ≅ (parallelPair (F.map f) 0).obj j := match j with | zero => Iso.refl _ | one => Iso.refl _ NatIso.ofComponents app <| by rintro ⟨i⟩ ⟨j⟩ <;> rintro (g | g) <;> aesop end /-- If `s` is a limit kernel fork and `k : W ⟶ X` satisfies `k ≫ f = 0`, then there is some `l : W ⟶ s.X` such that `l ≫ fork.ι s = k`. -/ def KernelFork.IsLimit.lift' {s : KernelFork f} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : { l : W ⟶ s.pt // l ≫ Fork.ι s = k } := ⟨hs.lift <| KernelFork.ofι _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a kernel fork is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : KernelFork f) (lift : ∀ s : KernelFork f, s.pt ⟶ t.pt) (fac : ∀ s : KernelFork f, lift s ≫ t.ι = s.ι) (uniq : ∀ (s : KernelFork f) (m : s.pt ⟶ t.pt) (_ : m ≫ t.ι = s.ι), m = lift s) : IsLimit t := { lift fac := fun s j => by cases j · exact fac s · simp uniq := fun s m w => uniq s m (w Limits.WalkingParallelPair.zero) } /-- This is a more convenient formulation to show that a `KernelFork` constructed using `KernelFork.ofι` is a limit cone. -/ def KernelFork.IsLimit.ofι {W : C} (g : W ⟶ X) (eq : g ≫ f = 0) (lift : ∀ {W' : C} (g' : W' ⟶ X) (_ : g' ≫ f = 0), W' ⟶ W) (fac : ∀ {W' : C} (g' : W' ⟶ X) (eq' : g' ≫ f = 0), lift g' eq' ≫ g = g') (uniq : ∀ {W' : C} (g' : W' ⟶ X) (eq' : g' ≫ f = 0) (m : W' ⟶ W) (_ : m ≫ g = g'), m = lift g' eq') : IsLimit (KernelFork.ofι g eq) := isLimitAux _ (fun s => lift s.ι s.condition) (fun s => fac s.ι s.condition) fun s => uniq s.ι s.condition /-- This is a more convenient formulation to show that a `KernelFork` of the form `KernelFork.ofι i _` is a limit cone when we know that `i` is a monomorphism. -/ def KernelFork.IsLimit.ofι' {X Y K : C} {f : X ⟶ Y} (i : K ⟶ X) (w : i ≫ f = 0) (h : ∀ {A : C} (k : A ⟶ X) (_ : k ≫ f = 0), { l : A ⟶ K // l ≫ i = k}) [hi : Mono i] : IsLimit (KernelFork.ofι i w) := ofι _ _ (fun {_} k hk => (h k hk).1) (fun {_} k hk => (h k hk).2) (fun {A} k hk m hm => by rw [← cancel_mono i, (h k hk).2, hm]) /-- Every kernel of `f` induces a kernel of `f ≫ g` if `g` is mono. -/ def isKernelCompMono {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟶ Z) [hg : Mono g] {h : X ⟶ Z} (hh : h = f ≫ g) : IsLimit (KernelFork.ofι c.ι (by simp [hh]) : KernelFork h) := Fork.IsLimit.mk' _ fun s => let s' : KernelFork f := Fork.ofι s.ι (by rw [← cancel_mono g]; simp [← hh, s.condition]) let l := KernelFork.IsLimit.lift' i s'.ι s'.condition ⟨l.1, l.2, fun hm => by apply Fork.IsLimit.hom_ext i; rw [Fork.ι_ofι] at hm; rw [hm]; exact l.2.symm⟩ theorem isKernelCompMono_lift {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟶ Z) [hg : Mono g] {h : X ⟶ Z} (hh : h = f ≫ g) (s : KernelFork h) : (isKernelCompMono i g hh).lift s = i.lift (Fork.ofι s.ι (by rw [← cancel_mono g, Category.assoc, ← hh] simp)) := rfl /-- Every kernel of `f ≫ g` is also a kernel of `f`, as long as `c.ι ≫ f` vanishes. -/ def isKernelOfComp {W : C} (g : Y ⟶ W) (h : X ⟶ W) {c : KernelFork h} (i : IsLimit c) (hf : c.ι ≫ f = 0) (hfg : f ≫ g = h) : IsLimit (KernelFork.ofι c.ι hf) := Fork.IsLimit.mk _ (fun s => i.lift (KernelFork.ofι s.ι (by simp [← hfg]))) (fun s => by simp only [KernelFork.ι_ofι, Fork.IsLimit.lift_ι]) fun s m h => by apply Fork.IsLimit.hom_ext i; simpa using h /-- `X` identifies to the kernel of a zero map `X ⟶ Y`. -/ def KernelFork.IsLimit.ofId {X Y : C} (f : X ⟶ Y) (hf : f = 0) : IsLimit (KernelFork.ofι (𝟙 X) (show 𝟙 X ≫ f = 0 by rw [hf, comp_zero])) := KernelFork.IsLimit.ofι _ _ (fun x _ => x) (fun _ _ => Category.comp_id _) (fun _ _ _ hb => by simp only [← hb, Category.comp_id]) /-- Any zero object identifies to the kernel of a given monomorphisms. -/ def KernelFork.IsLimit.ofMonoOfIsZero {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hf : Mono f) (h : IsZero c.pt) : IsLimit c := isLimitAux _ (fun _ => 0) (fun s => by rw [zero_comp, ← cancel_mono f, zero_comp, s.condition]) (fun _ _ _ => h.eq_of_tgt _ _) lemma KernelFork.IsLimit.isIso_ι {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hc : IsLimit c) (hf : f = 0) : IsIso c.ι := isIso_limit_cone_parallelPair_of_eq hf hc /-- If `c` is a limit kernel fork for `g : X ⟶ Y`, `e : X ≅ X'` and `g' : X' ⟶ Y` is a morphism, then there is a limit kernel fork for `g'` with the same point as `c` if for any morphism `φ : W ⟶ X`, there is an equivalence `φ ≫ g = 0 ↔ φ ≫ e.hom ≫ g' = 0`. -/ def KernelFork.isLimitOfIsLimitOfIff {X Y : C} {g : X ⟶ Y} {c : KernelFork g} (hc : IsLimit c) {X' Y' : C} (g' : X' ⟶ Y') (e : X ≅ X') (iff : ∀ ⦃W : C⦄ (φ : W ⟶ X), φ ≫ g = 0 ↔ φ ≫ e.hom ≫ g' = 0) : IsLimit (KernelFork.ofι (f := g') (c.ι ≫ e.hom) (by simp [← iff])) := KernelFork.IsLimit.ofι _ _ (fun s hs ↦ hc.lift (KernelFork.ofι (ι := s ≫ e.inv) (by rw [iff, Category.assoc, Iso.inv_hom_id_assoc, hs]))) (fun s hs ↦ by simp) (fun s hs m hm ↦ Fork.IsLimit.hom_ext hc (by simpa [← cancel_mono e.hom] using hm)) /-- If `c` is a limit kernel fork for `g : X ⟶ Y`, and `g' : X ⟶ Y'` is a another morphism, then there is a limit kernel fork for `g'` with the same point as `c` if for any morphism `φ : W ⟶ X`, there is an equivalence `φ ≫ g = 0 ↔ φ ≫ g' = 0`. -/ def KernelFork.isLimitOfIsLimitOfIff' {X Y : C} {g : X ⟶ Y} {c : KernelFork g} (hc : IsLimit c) {Y' : C} (g' : X ⟶ Y') (iff : ∀ ⦃W : C⦄ (φ : W ⟶ X), φ ≫ g = 0 ↔ φ ≫ g' = 0) : IsLimit (KernelFork.ofι (f := g') c.ι (by simp [← iff])) := IsLimit.ofIsoLimit (isLimitOfIsLimitOfIff hc g' (Iso.refl _) (by simpa using iff)) (Fork.ext (Iso.refl _)) lemma KernelFork.IsLimit.isZero_of_mono {X Y : C} {f : X ⟶ Y} {c : KernelFork f} (hc : IsLimit c) [Mono f] : IsZero c.pt := by have := Fork.IsLimit.mono hc rw [IsZero.iff_id_eq_zero, ← cancel_mono c.ι, ← cancel_mono f, Category.assoc, Category.assoc, c.condition, comp_zero, zero_comp] end namespace KernelFork variable {f} {X' Y' : C} {f' : X' ⟶ Y'} /-- The morphism between points of kernel forks induced by a morphism in the category of arrows. -/ def mapOfIsLimit (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (φ : Arrow.mk f ⟶ Arrow.mk f') : kf.pt ⟶ kf'.pt := hf'.lift (KernelFork.ofι (kf.ι ≫ φ.left) (by simp)) @[reassoc (attr := simp)] lemma mapOfIsLimit_ι (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (φ : Arrow.mk f ⟶ Arrow.mk f') : kf.mapOfIsLimit hf' φ ≫ kf'.ι = kf.ι ≫ φ.left := hf'.fac _ _ /-- The isomorphism between points of limit kernel forks induced by an isomorphism in the category of arrows. -/ @[simps] def mapIsoOfIsLimit {kf : KernelFork f} {kf' : KernelFork f'} (hf : IsLimit kf) (hf' : IsLimit kf') (φ : Arrow.mk f ≅ Arrow.mk f') : kf.pt ≅ kf'.pt where hom := kf.mapOfIsLimit hf' φ.hom inv := kf'.mapOfIsLimit hf φ.inv hom_inv_id := Fork.IsLimit.hom_ext hf (by simp) inv_hom_id := Fork.IsLimit.hom_ext hf' (by simp) end KernelFork section variable [HasKernel f] /-- The kernel of a morphism, expressed as the equalizer with the 0 morphism. -/ abbrev kernel (f : X ⟶ Y) [HasKernel f] : C := equalizer f 0 /-- The map from `kernel f` into the source of `f`. -/ abbrev kernel.ι : kernel f ⟶ X := equalizer.ι f 0 @[simp] theorem equalizer_as_kernel : equalizer.ι f 0 = kernel.ι f := rfl @[reassoc (attr := simp)] theorem kernel.condition : kernel.ι f ≫ f = 0 := KernelFork.condition _ /-- The kernel built from `kernel.ι f` is limiting. -/ def kernelIsKernel : IsLimit (Fork.ofι (kernel.ι f) ((kernel.condition f).trans comp_zero.symm)) := IsLimit.ofIsoLimit (limit.isLimit _) (Fork.ext (Iso.refl _) (by simp)) /-- Given any morphism `k : W ⟶ X` satisfying `k ≫ f = 0`, `k` factors through `kernel.ι f` via `kernel.lift : W ⟶ kernel f`. -/ abbrev kernel.lift {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : W ⟶ kernel f := (kernelIsKernel f).lift (KernelFork.ofι k h) @[reassoc (attr := simp)] theorem kernel.lift_ι {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : kernel.lift f k h ≫ kernel.ι f = k := (kernelIsKernel f).fac (KernelFork.ofι k h) WalkingParallelPair.zero @[simp] theorem kernel.lift_zero {W : C} {h} : kernel.lift f (0 : W ⟶ X) h = 0 := by ext; simp instance kernel.lift_mono {W : C} (k : W ⟶ X) (h : k ≫ f = 0) [Mono k] : Mono (kernel.lift f k h) := ⟨fun {Z} g g' w => by replace w := w =≫ kernel.ι f simp only [Category.assoc, kernel.lift_ι] at w exact (cancel_mono k).1 w⟩ /-- Any morphism `k : W ⟶ X` satisfying `k ≫ f = 0` induces a morphism `l : W ⟶ kernel f` such that `l ≫ kernel.ι f = k`. -/ def kernel.lift' {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : { l : W ⟶ kernel f // l ≫ kernel.ι f = k } := ⟨kernel.lift f k h, kernel.lift_ι _ _ _⟩ /-- A commuting square induces a morphism of kernels. -/ abbrev kernel.map {X' Y' : C} (f' : X' ⟶ Y') [HasKernel f'] (p : X ⟶ X') (q : Y ⟶ Y') (w : f ≫ q = p ≫ f') : kernel f ⟶ kernel f' := kernel.lift f' (kernel.ι f ≫ p) (by simp [← w]) @[simp] lemma kernel.map_id {X Y : C} (f : X ⟶ Y) [HasKernel f] (q : Y ⟶ Y) (w : f ≫ q = 𝟙 _ ≫ f) : kernel.map f f (𝟙 _) q w = 𝟙 _ := by cat_disch /-- Given a commutative diagram ``` X --f--> Y --g--> Z | | | | | | v v v X' -f'-> Y' -g'-> Z' ``` with horizontal arrows composing to zero, then we obtain a commutative square ``` X ---> kernel g | | | | kernel.map | | v v X' --> kernel g' ``` -/ theorem kernel.lift_map {X Y Z X' Y' Z' : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasKernel g] (w : f ≫ g = 0) (f' : X' ⟶ Y') (g' : Y' ⟶ Z') [HasKernel g'] (w' : f' ≫ g' = 0) (p : X ⟶ X') (q : Y ⟶ Y') (r : Z ⟶ Z') (h₁ : f ≫ q = p ≫ f') (h₂ : g ≫ r = q ≫ g') : kernel.lift g f w ≫ kernel.map g g' q r h₂ = p ≫ kernel.lift g' f' w' := by ext; simp [h₁] @[simp] lemma kernel.map_zero {X Y X' Y' : C} (f : X ⟶ Y) (f' : X' ⟶ Y') [HasKernel f] [HasKernel f'] (q : Y ⟶ Y') (w : f ≫ q = 0 ≫ f') : kernel.map f f' 0 q w = 0 := by cat_disch /-- A commuting square of isomorphisms induces an isomorphism of kernels. -/ @[simps] def kernel.mapIso {X' Y' : C} (f' : X' ⟶ Y') [HasKernel f'] (p : X ≅ X') (q : Y ≅ Y') (w : f ≫ q.hom = p.hom ≫ f') : kernel f ≅ kernel f' where hom := kernel.map f f' p.hom q.hom w inv := kernel.map f' f p.inv q.inv (by refine (cancel_mono q.hom).1 ?_ simp [w]) /-- Every kernel of the zero morphism is an isomorphism -/ instance kernel.ι_zero_isIso : IsIso (kernel.ι (0 : X ⟶ Y)) := equalizer.ι_of_self _ theorem eq_zero_of_epi_kernel [Epi (kernel.ι f)] : f = 0 := (cancel_epi (kernel.ι f)).1 (by simp) /-- The kernel of a zero morphism is isomorphic to the source. -/ def kernelZeroIsoSource : kernel (0 : X ⟶ Y) ≅ X := equalizer.isoSourceOfSelf 0 @[simp] theorem kernelZeroIsoSource_hom : kernelZeroIsoSource.hom = kernel.ι (0 : X ⟶ Y) := rfl @[simp] theorem kernelZeroIsoSource_inv : kernelZeroIsoSource.inv = kernel.lift (0 : X ⟶ Y) (𝟙 X) (by simp) := by ext simp [kernelZeroIsoSource] /-- If two morphisms are known to be equal, then their kernels are isomorphic. -/ def kernelIsoOfEq {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : kernel f ≅ kernel g := HasLimit.isoOfNatIso (by rw [h]) @[simp] theorem kernelIsoOfEq_refl {h : f = f} : kernelIsoOfEq h = Iso.refl (kernel f) := by ext simp [kernelIsoOfEq] @[reassoc (attr := simp)] theorem kernelIsoOfEq_hom_comp_ι {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).hom ≫ kernel.ι g = kernel.ι f := by subst h; simp @[reassoc (attr := simp)] theorem kernelIsoOfEq_inv_comp_ι {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).inv ≫ kernel.ι _ = kernel.ι _ := by subst h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_hom {Z} {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟶ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).hom = kernel.lift _ e (by simp [← h, he]) := by subst h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_inv {Z} {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟶ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).inv = kernel.lift _ e (by simp [h, he]) := by cases h; simp @[simp] theorem kernelIsoOfEq_trans {f g h : X ⟶ Y} [HasKernel f] [HasKernel g] [HasKernel h] (w₁ : f = g) (w₂ : g = h) : kernelIsoOfEq w₁ ≪≫ kernelIsoOfEq w₂ = kernelIsoOfEq (w₁.trans w₂) := by cases w₁; simp variable {f} theorem kernel_not_epi_of_nonzero (w : f ≠ 0) : ¬Epi (kernel.ι f) := fun _ => w (eq_zero_of_epi_kernel f) theorem kernel_not_iso_of_nonzero (w : f ≠ 0) : IsIso (kernel.ι f) → False := fun _ => kernel_not_epi_of_nonzero w inferInstance instance hasKernel_comp_mono {X Y Z : C} (f : X ⟶ Y) [HasKernel f] (g : Y ⟶ Z) [Mono g] : HasKernel (f ≫ g) := ⟨⟨{ cone := _ isLimit := isKernelCompMono (limit.isLimit _) g rfl }⟩⟩ /-- When `g` is a monomorphism, the kernel of `f ≫ g` is isomorphic to the kernel of `f`. -/ @[simps] def kernelCompMono {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasKernel f] [Mono g] : kernel (f ≫ g) ≅ kernel f where hom := kernel.lift _ (kernel.ι _) (by rw [← cancel_mono g] simp) inv := kernel.lift _ (kernel.ι _) (by simp) instance hasKernel_iso_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [HasKernel g] : HasKernel (f ≫ g) where exists_limit := ⟨{ cone := KernelFork.ofι (kernel.ι g ≫ inv f) (by simp) isLimit := isLimitAux _ (fun s => kernel.lift _ (s.ι ≫ f) (by simp)) (by simp) fun s (m : _ ⟶ kernel _) w => by simp_rw [← w] apply equalizer.hom_ext simp }⟩ /-- When `f` is an isomorphism, the kernel of `f ≫ g` is isomorphic to the kernel of `g`. -/ @[simps] def kernelIsIsoComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [HasKernel g] : kernel (f ≫ g) ≅ kernel g where hom := kernel.lift _ (kernel.ι _ ≫ f) (by simp) inv := kernel.lift _ (kernel.ι _ ≫ inv f) (by simp) /-- Equal maps have isomorphic kernels. -/ @[simps] def kernel.congr {X Y : C} (f g : X ⟶ Y) [HasKernel f] [HasKernel g] (h : f = g) : kernel f ≅ kernel g where hom := kernel.lift _ (kernel.ι f) (by simp [← h]) inv := kernel.lift _ (kernel.ι g) (by simp [h]) lemma isZero_kernel_of_mono {X Y : C} (f : X ⟶ Y) [Mono f] [HasKernel f] : IsZero (kernel f) := KernelFork.IsLimit.isZero_of_mono (c := KernelFork.ofι _ (kernel.condition f)) (kernelIsKernel f) end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The morphism from the zero object determines a cone on a kernel diagram -/ def kernel.zeroKernelFork : KernelFork f where pt := 0 π := { app := fun _ => 0 } /-- The map from the zero object is a kernel of a monomorphism -/ def kernel.isLimitConeZeroCone [Mono f] : IsLimit (kernel.zeroKernelFork f) := Fork.IsLimit.mk _ (fun _ => 0) (fun s => by rw [zero_comp] refine (zero_of_comp_mono f ?_).symm exact KernelFork.condition _) fun _ _ _ => zero_of_to_zero _ /-- The kernel of a monomorphism is isomorphic to the zero object -/ def kernel.ofMono [HasKernel f] [Mono f] : kernel f ≅ 0 := Functor.mapIso (Cones.forget _) <| IsLimit.uniqueUpToIso (limit.isLimit (parallelPair f 0)) (kernel.isLimitConeZeroCone f) /-- The kernel morphism of a monomorphism is a zero morphism -/ theorem kernel.ι_of_mono [HasKernel f] [Mono f] : kernel.ι f = 0 := zero_of_source_iso_zero _ (kernel.ofMono f) /-- If `g ≫ f = 0` implies `g = 0` for all `g`, then `0 : 0 ⟶ X` is a kernel of `f`. -/ def zeroKernelOfCancelZero {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Z ⟶ X) (_ : g ≫ f = 0), g = 0) : IsLimit (KernelFork.ofι (0 : 0 ⟶ X) (show 0 ≫ f = 0 by simp)) := Fork.IsLimit.mk _ (fun _ => 0) (fun s => by rw [hf _ _ (KernelFork.condition s), zero_comp]) fun s m _ => by dsimp; apply HasZeroObject.to_zero_ext end HasZeroObject section Transport /-- If `i` is an isomorphism such that `l ≫ i.hom = f`, any kernel of `f` is a kernel of `l`. -/ def IsKernel.ofCompIso {Z : C} (l : X ⟶ Z) (i : Z ≅ Y) (h : l ≫ i.hom = f) {s : KernelFork f} (hs : IsLimit s) : IsLimit (KernelFork.ofι (Fork.ι s) <| show Fork.ι s ≫ l = 0 by simp [← i.comp_inv_eq.2 h.symm]) := Fork.IsLimit.mk _ (fun s => hs.lift <| KernelFork.ofι (Fork.ι s) <| by simp [← h]) (fun s => by simp) fun s m h => by apply Fork.IsLimit.hom_ext hs simpa using h /-- If `i` is an isomorphism such that `l ≫ i.hom = f`, the kernel of `f` is a kernel of `l`. -/ def kernel.ofCompIso [HasKernel f] {Z : C} (l : X ⟶ Z) (i : Z ≅ Y) (h : l ≫ i.hom = f) : IsLimit (KernelFork.ofι (kernel.ι f) <| show kernel.ι f ≫ l = 0 by simp [← i.comp_inv_eq.2 h.symm]) := IsKernel.ofCompIso f l i h <| limit.isLimit _ /-- If `s` is any limit kernel cone over `f` and if `i` is an isomorphism such that `i.hom ≫ s.ι = l`, then `l` is a kernel of `f`. -/ def IsKernel.isoKernel {Z : C} (l : Z ⟶ X) {s : KernelFork f} (hs : IsLimit s) (i : Z ≅ s.pt) (h : i.hom ≫ Fork.ι s = l) : IsLimit (KernelFork.ofι l <| show l ≫ f = 0 by simp [← h]) := IsLimit.ofIsoLimit hs <| Cones.ext i.symm fun j => by cases j · exact (Iso.eq_inv_comp i).2 h · dsimp; rw [← h]; simp /-- If `i` is an isomorphism such that `i.hom ≫ kernel.ι f = l`, then `l` is a kernel of `f`. -/ def kernel.isoKernel [HasKernel f] {Z : C} (l : Z ⟶ X) (i : Z ≅ kernel f) (h : i.hom ≫ kernel.ι f = l) : IsLimit (@KernelFork.ofι _ _ _ _ _ f _ l <| by simp [← h]) := IsKernel.isoKernel f l (limit.isLimit _) i h end Transport section variable (X Y) /-- The kernel morphism of a zero morphism is an isomorphism -/ theorem kernel.ι_of_zero : IsIso (kernel.ι (0 : X ⟶ Y)) := equalizer.ι_of_self _ end section /-- A cokernel cofork is just a cofork where the second morphism is a zero morphism. -/ abbrev CokernelCofork := Cofork f 0 variable {f} @[reassoc (attr := simp)] theorem CokernelCofork.condition (s : CokernelCofork f) : f ≫ s.π = 0 := by rw [Cofork.condition, zero_comp] theorem CokernelCofork.π_eq_zero (s : CokernelCofork f) : s.ι.app zero = 0 := by simp /-- A morphism `π` satisfying `f ≫ π = 0` determines a cokernel cofork on `f`. -/ abbrev CokernelCofork.ofπ {Z : C} (π : Y ⟶ Z) (w : f ≫ π = 0) : CokernelCofork f := Cofork.ofπ π <| by rw [w, zero_comp] @[simp] theorem CokernelCofork.π_ofπ {X Y P : C} (f : X ⟶ Y) (π : Y ⟶ P) (w : f ≫ π = 0) : Cofork.π (CokernelCofork.ofπ π w) = π := rfl /-- Every cokernel cofork `s` is isomorphic (actually, equal) to `cofork.ofπ (cofork.π s) _`. -/ def isoOfπ (s : Cofork f 0) : s ≅ Cofork.ofπ (Cofork.π s) (Cofork.condition s) := Cocones.ext (Iso.refl _) fun j => by cases j <;> cat_disch /-- If `π = π'`, then `CokernelCofork.of_π π _` and `CokernelCofork.of_π π' _` are isomorphic. -/ def ofπCongr {P : C} {π π' : Y ⟶ P} {w : f ≫ π = 0} (h : π = π') : CokernelCofork.ofπ π w ≅ CokernelCofork.ofπ π' (by rw [← h, w]) := Cocones.ext (Iso.refl _) fun j => by cases j <;> cat_disch /-- If `s` is a colimit cokernel cofork, then every `k : Y ⟶ W` satisfying `f ≫ k = 0` induces `l : s.X ⟶ W` such that `cofork.π s ≫ l = k`. -/ def CokernelCofork.IsColimit.desc' {s : CokernelCofork f} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : { l : s.pt ⟶ W // Cofork.π s ≫ l = k } := ⟨hs.desc <| CokernelCofork.ofπ _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a cokernel cofork is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def isColimitAux (t : CokernelCofork f) (desc : ∀ s : CokernelCofork f, t.pt ⟶ s.pt) (fac : ∀ s : CokernelCofork f, t.π ≫ desc s = s.π) (uniq : ∀ (s : CokernelCofork f) (m : t.pt ⟶ s.pt) (_ : t.π ≫ m = s.π), m = desc s) : IsColimit t := { desc fac := fun s j => by cases j · simp · exact fac s uniq := fun s m w => uniq s m (w Limits.WalkingParallelPair.one) } /-- This is a more convenient formulation to show that a `CokernelCofork` constructed using `CokernelCofork.ofπ` is a limit cone. -/ def CokernelCofork.IsColimit.ofπ {Z : C} (g : Y ⟶ Z) (eq : f ≫ g = 0) (desc : ∀ {Z' : C} (g' : Y ⟶ Z') (_ : f ≫ g' = 0), Z ⟶ Z') (fac : ∀ {Z' : C} (g' : Y ⟶ Z') (eq' : f ≫ g' = 0), g ≫ desc g' eq' = g') (uniq : ∀ {Z' : C} (g' : Y ⟶ Z') (eq' : f ≫ g' = 0) (m : Z ⟶ Z') (_ : g ≫ m = g'), m = desc g' eq') : IsColimit (CokernelCofork.ofπ g eq) := isColimitAux _ (fun s => desc s.π s.condition) (fun s => fac s.π s.condition) fun s => uniq s.π s.condition /-- This is a more convenient formulation to show that a `CokernelCofork` of the form `CokernelCofork.ofπ p _` is a colimit cocone when we know that `p` is an epimorphism. -/ def CokernelCofork.IsColimit.ofπ' {X Y Q : C} {f : X ⟶ Y} (p : Y ⟶ Q) (w : f ≫ p = 0) (h : ∀ {A : C} (k : Y ⟶ A) (_ : f ≫ k = 0), { l : Q ⟶ A // p ≫ l = k}) [hp : Epi p] : IsColimit (CokernelCofork.ofπ p w) := ofπ _ _ (fun {_} k hk => (h k hk).1) (fun {_} k hk => (h k hk).2) (fun {A} k hk m hm => by rw [← cancel_epi p, (h k hk).2, hm]) /-- Every cokernel of `f` induces a cokernel of `g ≫ f` if `g` is epi. -/ def isCokernelEpiComp {c : CokernelCofork f} (i : IsColimit c) {W} (g : W ⟶ X) [hg : Epi g] {h : W ⟶ Y} (hh : h = g ≫ f) : IsColimit (CokernelCofork.ofπ c.π (by rw [hh]; simp) : CokernelCofork h) := Cofork.IsColimit.mk' _ fun s => let s' : CokernelCofork f := Cofork.ofπ s.π (by apply hg.left_cancellation rw [← Category.assoc, ← hh, s.condition] simp) let l := CokernelCofork.IsColimit.desc' i s'.π s'.condition ⟨l.1, l.2, fun hm => by apply Cofork.IsColimit.hom_ext i; rw [Cofork.π_ofπ] at hm; rw [hm]; exact l.2.symm⟩ @[simp] theorem isCokernelEpiComp_desc {c : CokernelCofork f} (i : IsColimit c) {W} (g : W ⟶ X) [hg : Epi g] {h : W ⟶ Y} (hh : h = g ≫ f) (s : CokernelCofork h) : (isCokernelEpiComp i g hh).desc s = i.desc (Cofork.ofπ s.π (by rw [← cancel_epi g, ← Category.assoc, ← hh] simp)) := rfl /-- Every cokernel of `g ≫ f` is also a cokernel of `f`, as long as `f ≫ c.π` vanishes. -/ def isCokernelOfComp {W : C} (g : W ⟶ X) (h : W ⟶ Y) {c : CokernelCofork h} (i : IsColimit c) (hf : f ≫ c.π = 0) (hfg : g ≫ f = h) : IsColimit (CokernelCofork.ofπ c.π hf) := Cofork.IsColimit.mk _ (fun s => i.desc (CokernelCofork.ofπ s.π (by simp [← hfg]))) (fun s => by simp only [CokernelCofork.π_ofπ, Cofork.IsColimit.π_desc]) fun s m h => by apply Cofork.IsColimit.hom_ext i simpa using h /-- `Y` identifies to the cokernel of a zero map `X ⟶ Y`. -/ def CokernelCofork.IsColimit.ofId {X Y : C} (f : X ⟶ Y) (hf : f = 0) : IsColimit (CokernelCofork.ofπ (𝟙 Y) (show f ≫ 𝟙 Y = 0 by rw [hf, zero_comp])) := CokernelCofork.IsColimit.ofπ _ _ (fun x _ => x) (fun _ _ => Category.id_comp _) (fun _ _ _ hb => by simp only [← hb, Category.id_comp]) /-- Any zero object identifies to the cokernel of a given epimorphisms. -/ def CokernelCofork.IsColimit.ofEpiOfIsZero {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (hf : Epi f) (h : IsZero c.pt) : IsColimit c := isColimitAux _ (fun _ => 0) (fun s => by rw [comp_zero, ← cancel_epi f, comp_zero, s.condition]) (fun _ _ _ => h.eq_of_src _ _) lemma CokernelCofork.IsColimit.isIso_π {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (hc : IsColimit c) (hf : f = 0) : IsIso c.π := isIso_colimit_cocone_parallelPair_of_eq hf hc /-- If `c` is a colimit cokernel cofork for `f : X ⟶ Y`, `e : Y ≅ Y'` and `f' : X' ⟶ Y` is a morphism, then there is a colimit cokernel cofork for `f'` with the same point as `c` if for any morphism `φ : Y ⟶ W`, there is an equivalence `f ≫ φ = 0 ↔ f' ≫ e.hom ≫ φ = 0`. -/ def CokernelCofork.isColimitOfIsColimitOfIff {X Y : C} {f : X ⟶ Y} {c : CokernelCofork f} (hc : IsColimit c) {X' Y' : C} (f' : X' ⟶ Y') (e : Y' ≅ Y) (iff : ∀ ⦃W : C⦄ (φ : Y ⟶ W), f ≫ φ = 0 ↔ f' ≫ e.hom ≫ φ = 0) : IsColimit (CokernelCofork.ofπ (f := f') (e.hom ≫ c.π) (by simp [← iff])) := CokernelCofork.IsColimit.ofπ _ _ (fun s hs ↦ hc.desc (CokernelCofork.ofπ (π := e.inv ≫ s) (by rw [iff, e.hom_inv_id_assoc, hs]))) (fun s hs ↦ by simp) (fun s hs m hm ↦ Cofork.IsColimit.hom_ext hc (by simpa [← cancel_epi e.hom] using hm)) /-- If `c` is a colimit cokernel cofork for `f : X ⟶ Y`, and `f' : X' ⟶ Y` is another morphism, then there is a colimit cokernel cofork for `f'` with the same point as `c` if for any morphism `φ : Y ⟶ W`, there is an equivalence `f ≫ φ = 0 ↔ f' ≫ φ = 0`. -/ def CokernelCofork.isColimitOfIsColimitOfIff' {X Y : C} {f : X ⟶ Y} {c : CokernelCofork f} (hc : IsColimit c) {X' : C} (f' : X' ⟶ Y) (iff : ∀ ⦃W : C⦄ (φ : Y ⟶ W), f ≫ φ = 0 ↔ f' ≫ φ = 0) : IsColimit (CokernelCofork.ofπ (f := f') c.π (by simp [← iff])) := IsColimit.ofIsoColimit (isColimitOfIsColimitOfIff hc f' (Iso.refl _) (by simpa using iff)) (Cofork.ext (Iso.refl _)) lemma CokernelCofork.IsColimit.isZero_of_epi {X Y : C} {f : X ⟶ Y} {c : CokernelCofork f} (hc : IsColimit c) [Epi f] : IsZero c.pt := by have := Cofork.IsColimit.epi hc rw [IsZero.iff_id_eq_zero, ← cancel_epi c.π, ← cancel_epi f, c.condition_assoc, comp_zero, comp_zero, zero_comp] end namespace CokernelCofork variable {f} {X' Y' : C} {f' : X' ⟶ Y'} /-- The morphism between points of cokernel coforks induced by a morphism in the category of arrows. -/ def mapOfIsColimit {cc : CokernelCofork f} (hf : IsColimit cc) (cc' : CokernelCofork f') (φ : Arrow.mk f ⟶ Arrow.mk f') : cc.pt ⟶ cc'.pt := hf.desc (CokernelCofork.ofπ (φ.right ≫ cc'.π) (by erw [← Arrow.w_assoc φ, condition, comp_zero])) @[reassoc (attr := simp)] lemma π_mapOfIsColimit {cc : CokernelCofork f} (hf : IsColimit cc) (cc' : CokernelCofork f') (φ : Arrow.mk f ⟶ Arrow.mk f') : cc.π ≫ mapOfIsColimit hf cc' φ = φ.right ≫ cc'.π := hf.fac _ _ /-- The isomorphism between points of limit cokernel coforks induced by an isomorphism in the category of arrows. -/ @[simps] def mapIsoOfIsColimit {cc : CokernelCofork f} {cc' : CokernelCofork f'} (hf : IsColimit cc) (hf' : IsColimit cc') (φ : Arrow.mk f ≅ Arrow.mk f') : cc.pt ≅ cc'.pt where hom := mapOfIsColimit hf cc' φ.hom inv := mapOfIsColimit hf' cc φ.inv hom_inv_id := Cofork.IsColimit.hom_ext hf (by simp) inv_hom_id := Cofork.IsColimit.hom_ext hf' (by simp) end CokernelCofork section variable [HasCokernel f] /-- The cokernel of a morphism, expressed as the coequalizer with the 0 morphism. -/ abbrev cokernel : C := coequalizer f 0 /-- The map from the target of `f` to `cokernel f`. -/ abbrev cokernel.π : Y ⟶ cokernel f := coequalizer.π f 0 @[simp] theorem coequalizer_as_cokernel : coequalizer.π f 0 = cokernel.π f := rfl @[reassoc (attr := simp)] theorem cokernel.condition : f ≫ cokernel.π f = 0 := CokernelCofork.condition _ /-- The cokernel built from `cokernel.π f` is colimiting. -/ def cokernelIsCokernel : IsColimit (Cofork.ofπ (cokernel.π f) ((cokernel.condition f).trans zero_comp.symm)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cofork.ext (Iso.refl _)) /-- Given any morphism `k : Y ⟶ W` such that `f ≫ k = 0`, `k` factors through `cokernel.π f` via `cokernel.desc : cokernel f ⟶ W`. -/ abbrev cokernel.desc {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : cokernel f ⟶ W := (cokernelIsCokernel f).desc (CokernelCofork.ofπ k h) @[reassoc (attr := simp)] theorem cokernel.π_desc {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : cokernel.π f ≫ cokernel.desc f k h = k := (cokernelIsCokernel f).fac (CokernelCofork.ofπ k h) WalkingParallelPair.one @[reassoc (attr := simp)] lemma colimit_ι_zero_cokernel_desc {C : Type*} [Category C] [HasZeroMorphisms C] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : f ≫ g = 0) [HasCokernel f] : colimit.ι (parallelPair f 0) WalkingParallelPair.zero ≫ cokernel.desc f g h = 0 := by rw [(colimit.w (parallelPair f 0) WalkingParallelPairHom.left).symm] simp @[simp] theorem cokernel.desc_zero {W : C} {h} : cokernel.desc f (0 : Y ⟶ W) h = 0 := by ext; simp instance cokernel.desc_epi {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) [Epi k] : Epi (cokernel.desc f k h) := ⟨fun {Z} g g' w => by replace w := cokernel.π f ≫= w simp only [cokernel.π_desc_assoc] at w exact (cancel_epi k).1 w⟩ /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = 0` induces `l : cokernel f ⟶ W` such that `cokernel.π f ≫ l = k`. -/ def cokernel.desc' {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : { l : cokernel f ⟶ W // cokernel.π f ≫ l = k } := ⟨cokernel.desc f k h, cokernel.π_desc _ _ _⟩ /-- A commuting square induces a morphism of cokernels. -/ abbrev cokernel.map {X' Y' : C} (f' : X' ⟶ Y') [HasCokernel f'] (p : X ⟶ X') (q : Y ⟶ Y') (w : f ≫ q = p ≫ f') : cokernel f ⟶ cokernel f' := cokernel.desc f (q ≫ cokernel.π f') (by have : f ≫ q ≫ π f' = p ≫ f' ≫ π f' := by simp only [← Category.assoc] apply congrArg (· ≫ π f') w simp [this]) @[simp] lemma cokernel.map_id {X Y : C} (f : X ⟶ Y) [HasCokernel f] (q : X ⟶ X) (w : f ≫ 𝟙 _ = q ≫ f) : cokernel.map f f q (𝟙 _) w = 𝟙 _ := by cat_disch /-- Given a commutative diagram ``` X --f--> Y --g--> Z | | | | | | v v v X' -f'-> Y' -g'-> Z' ``` with horizontal arrows composing to zero, then we obtain a commutative square ``` cokernel f ---> Z | | | cokernel.map | | | v v cokernel f' --> Z' ``` -/ theorem cokernel.map_desc {X Y Z X' Y' Z' : C} (f : X ⟶ Y) [HasCokernel f] (g : Y ⟶ Z) (w : f ≫ g = 0) (f' : X' ⟶ Y') [HasCokernel f'] (g' : Y' ⟶ Z') (w' : f' ≫ g' = 0) (p : X ⟶ X') (q : Y ⟶ Y') (r : Z ⟶ Z') (h₁ : f ≫ q = p ≫ f') (h₂ : g ≫ r = q ≫ g') : cokernel.map f f' p q h₁ ≫ cokernel.desc f' g' w' = cokernel.desc f g w ≫ r := by ext; simp [h₂] @[simp] lemma cokernel.map_zero {X Y X' Y' : C} (f : X ⟶ Y) (f' : X' ⟶ Y') [HasCokernel f] [HasCokernel f'] (q : X ⟶ X') (w : f ≫ 0 = q ≫ f') : cokernel.map f f' q 0 w = 0 := by cat_disch /-- A commuting square of isomorphisms induces an isomorphism of cokernels. -/ @[simps] def cokernel.mapIso {X' Y' : C} (f' : X' ⟶ Y') [HasCokernel f'] (p : X ≅ X') (q : Y ≅ Y') (w : f ≫ q.hom = p.hom ≫ f') : cokernel f ≅ cokernel f' where hom := cokernel.map f f' p.hom q.hom w inv := cokernel.map f' f p.inv q.inv (by refine (cancel_mono q.hom).1 ?_ simp [w]) /-- The cokernel of the zero morphism is an isomorphism -/ instance cokernel.π_zero_isIso : IsIso (cokernel.π (0 : X ⟶ Y)) := coequalizer.π_of_self _ theorem eq_zero_of_mono_cokernel [Mono (cokernel.π f)] : f = 0 := (cancel_mono (cokernel.π f)).1 (by simp) /-- The cokernel of a zero morphism is isomorphic to the target. -/ def cokernelZeroIsoTarget : cokernel (0 : X ⟶ Y) ≅ Y := coequalizer.isoTargetOfSelf 0 @[simp] theorem cokernelZeroIsoTarget_hom : cokernelZeroIsoTarget.hom = cokernel.desc (0 : X ⟶ Y) (𝟙 Y) (by simp) := by ext; simp [cokernelZeroIsoTarget] @[simp] theorem cokernelZeroIsoTarget_inv : cokernelZeroIsoTarget.inv = cokernel.π (0 : X ⟶ Y) := rfl /-- If two morphisms are known to be equal, then their cokernels are isomorphic. -/ def cokernelIsoOfEq {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel f ≅ cokernel g := HasColimit.isoOfNatIso (by simp [h]; rfl) @[simp] theorem cokernelIsoOfEq_refl {h : f = f} : cokernelIsoOfEq h = Iso.refl (cokernel f) := by ext; simp [cokernelIsoOfEq] @[reassoc (attr := simp)] theorem π_comp_cokernelIsoOfEq_hom {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel.π f ≫ (cokernelIsoOfEq h).hom = cokernel.π g := by cases h; simp @[reassoc (attr := simp)] theorem π_comp_cokernelIsoOfEq_inv {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel.π _ ≫ (cokernelIsoOfEq h).inv = cokernel.π _ := by cases h; simp @[reassoc (attr := simp)] theorem cokernelIsoOfEq_hom_comp_desc {Z} {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) (e : Y ⟶ Z) (he) : (cokernelIsoOfEq h).hom ≫ cokernel.desc _ e he = cokernel.desc _ e (by simp [h, he]) := by cases h; simp @[reassoc (attr := simp)] theorem cokernelIsoOfEq_inv_comp_desc {Z} {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) (e : Y ⟶ Z) (he) : (cokernelIsoOfEq h).inv ≫ cokernel.desc _ e he = cokernel.desc _ e (by simp [← h, he]) := by cases h; simp @[simp] theorem cokernelIsoOfEq_trans {f g h : X ⟶ Y} [HasCokernel f] [HasCokernel g] [HasCokernel h] (w₁ : f = g) (w₂ : g = h) : cokernelIsoOfEq w₁ ≪≫ cokernelIsoOfEq w₂ = cokernelIsoOfEq (w₁.trans w₂) := by cases w₁; simp variable {f} theorem cokernel_not_mono_of_nonzero (w : f ≠ 0) : ¬Mono (cokernel.π f) := fun _ => w (eq_zero_of_mono_cokernel f) theorem cokernel_not_iso_of_nonzero (w : f ≠ 0) : IsIso (cokernel.π f) → False := fun _ => cokernel_not_mono_of_nonzero w inferInstance -- TODO the remainder of this section has obvious generalizations to `HasCoequalizer f g`. instance hasCokernel_comp_iso {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasCokernel f] [IsIso g] : HasCokernel (f ≫ g) where exists_colimit := ⟨{ cocone := CokernelCofork.ofπ (inv g ≫ cokernel.π f) (by simp) isColimit := isColimitAux _ (fun s => cokernel.desc _ (g ≫ s.π) (by rw [← Category.assoc, CokernelCofork.condition])) (by simp) fun s (m : cokernel _ ⟶ _) w => by simp_rw [← w] apply coequalizer.hom_ext simp }⟩ /-- When `g` is an isomorphism, the cokernel of `f ≫ g` is isomorphic to the cokernel of `f`. -/ @[simps] def cokernelCompIsIso {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasCokernel f] [IsIso g] : cokernel (f ≫ g) ≅ cokernel f where hom := cokernel.desc _ (inv g ≫ cokernel.π f) (by simp) inv := cokernel.desc _ (g ≫ cokernel.π (f ≫ g)) (by rw [← Category.assoc, cokernel.condition]) instance hasCokernel_epi_comp {X Y : C} (f : X ⟶ Y) [HasCokernel f] {W} (g : W ⟶ X) [Epi g] : HasCokernel (g ≫ f) := ⟨⟨{ cocone := _ isColimit := isCokernelEpiComp (colimit.isColimit _) g rfl }⟩⟩ /-- When `f` is an epimorphism, the cokernel of `f ≫ g` is isomorphic to the cokernel of `g`. -/ @[simps] def cokernelEpiComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [Epi f] [HasCokernel g] : cokernel (f ≫ g) ≅ cokernel g where hom := cokernel.desc _ (cokernel.π g) (by simp) inv := cokernel.desc _ (cokernel.π (f ≫ g)) (by rw [← cancel_epi f, ← Category.assoc] simp) /-- Equal maps have isomorphic cokernels. -/ @[simps] def cokernel.congr {X Y : C} (f g : X ⟶ Y) [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel f ≅ cokernel g where hom := cokernel.desc _ (cokernel.π g) (by simp [h]) inv := cokernel.desc _ (cokernel.π f) (by simp [← h]) lemma isZero_cokernel_of_epi {X Y : C} (f : X ⟶ Y) [Epi f] [HasCokernel f] : IsZero (cokernel f) := CokernelCofork.IsColimit.isZero_of_epi (c := CokernelCofork.ofπ _ (cokernel.condition f)) (cokernelIsCokernel f) end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The morphism to the zero object determines a cocone on a cokernel diagram -/ def cokernel.zeroCokernelCofork : CokernelCofork f where pt := 0 ι := { app := fun _ => 0 } /-- The morphism to the zero object is a cokernel of an epimorphism -/ def cokernel.isColimitCoconeZeroCocone [Epi f] : IsColimit (cokernel.zeroCokernelCofork f) := Cofork.IsColimit.mk _ (fun _ => 0) (fun s => by erw [zero_comp] refine (zero_of_epi_comp f ?_).symm exact CokernelCofork.condition _) fun _ _ _ => zero_of_from_zero _ /-- The cokernel of an epimorphism is isomorphic to the zero object -/ def cokernel.ofEpi [HasCokernel f] [Epi f] : cokernel f ≅ 0 := Functor.mapIso (Cocones.forget _) <| IsColimit.uniqueUpToIso (colimit.isColimit (parallelPair f 0)) (cokernel.isColimitCoconeZeroCocone f) /-- The cokernel morphism of an epimorphism is a zero morphism -/ theorem cokernel.π_of_epi [HasCokernel f] [Epi f] : cokernel.π f = 0 := zero_of_target_iso_zero _ (cokernel.ofEpi f) end HasZeroObject section MonoFactorisation variable {f} @[simp] theorem MonoFactorisation.kernel_ι_comp [HasKernel f] (F : MonoFactorisation f) : kernel.ι f ≫ F.e = 0 := by rw [← cancel_mono F.m, zero_comp, Category.assoc, F.fac, kernel.condition] end MonoFactorisation section HasImage /-- The cokernel of the image inclusion of a morphism `f` is isomorphic to the cokernel of `f`. (This result requires that the factorisation through the image is an epimorphism. This holds in any category with equalizers.) -/ @[simps] def cokernelImageι {X Y : C} (f : X ⟶ Y) [HasImage f] [HasCokernel (image.ι f)] [HasCokernel f] [Epi (factorThruImage f)] : cokernel (image.ι f) ≅ cokernel f where hom := cokernel.desc _ (cokernel.π f) (by have w := cokernel.condition f conv at w => lhs congr rw [← image.fac f] rw [← HasZeroMorphisms.comp_zero (Limits.factorThruImage f), Category.assoc, cancel_epi] at w exact w) inv := cokernel.desc _ (cokernel.π _) (by conv => lhs congr rw [← image.fac f] rw [Category.assoc, cokernel.condition, HasZeroMorphisms.comp_zero]) section variable (f : X ⟶ Y) [HasKernel f] [HasImage f] [HasKernel (factorThruImage f)] /-- The kernel of the morphism `X ⟶ image f` is just the kernel of `f`. -/ def kernelFactorThruImage : kernel (factorThruImage f) ≅ kernel f := (kernelCompMono (factorThruImage f) (image.ι f)).symm ≪≫ (kernel.congr _ _ (by simp)) @[reassoc (attr := simp)] theorem kernelFactorThruImage_hom_comp_ι : (kernelFactorThruImage f).hom ≫ kernel.ι f = kernel.ι (factorThruImage f) := by simp [kernelFactorThruImage] @[reassoc (attr := simp)] theorem kernelFactorThruImage_inv_comp_ι : (kernelFactorThruImage f).inv ≫ kernel.ι (factorThruImage f) = kernel.ι f := by simp [kernelFactorThruImage] end end HasImage section variable (X Y) /-- The cokernel of a zero morphism is an isomorphism -/ theorem cokernel.π_of_zero : IsIso (cokernel.π (0 : X ⟶ Y)) := coequalizer.π_of_self _ end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The kernel of the cokernel of an epimorphism is an isomorphism -/ instance kernel.of_cokernel_of_epi [HasCokernel f] [HasKernel (cokernel.π f)] [Epi f] : IsIso (kernel.ι (cokernel.π f)) := equalizer.ι_of_eq <| cokernel.π_of_epi f /-- The cokernel of the kernel of a monomorphism is an isomorphism -/ instance cokernel.of_kernel_of_mono [HasKernel f] [HasCokernel (kernel.ι f)] [Mono f] : IsIso (cokernel.π (kernel.ι f)) := coequalizer.π_of_eq <| kernel.ι_of_mono f /-- If `f ≫ g = 0` implies `g = 0` for all `g`, then `0 : Y ⟶ 0` is a cokernel of `f`. -/ def zeroCokernelOfZeroCancel {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Y ⟶ Z) (_ : f ≫ g = 0), g = 0) : IsColimit (CokernelCofork.ofπ (0 : Y ⟶ 0) (show f ≫ 0 = 0 by simp)) := Cofork.IsColimit.mk _ (fun _ => 0) (fun s => by rw [hf _ _ (CokernelCofork.condition s), comp_zero]) fun s m _ => by apply HasZeroObject.from_zero_ext end HasZeroObject section Transport /-- If `i` is an isomorphism such that `i.hom ≫ l = f`, then any cokernel of `f` is a cokernel of `l`. -/ def IsCokernel.ofIsoComp {Z : C} (l : Z ⟶ Y) (i : X ≅ Z) (h : i.hom ≫ l = f) {s : CokernelCofork f} (hs : IsColimit s) : IsColimit (CokernelCofork.ofπ (Cofork.π s) <| show l ≫ Cofork.π s = 0 by simp [i.eq_inv_comp.2 h]) := Cofork.IsColimit.mk _ (fun s => hs.desc <| CokernelCofork.ofπ (Cofork.π s) <| by simp [← h]) (fun s => by simp) fun s m h => by apply Cofork.IsColimit.hom_ext hs simpa using h /-- If `i` is an isomorphism such that `i.hom ≫ l = f`, then the cokernel of `f` is a cokernel of `l`. -/ def cokernel.ofIsoComp [HasCokernel f] {Z : C} (l : Z ⟶ Y) (i : X ≅ Z) (h : i.hom ≫ l = f) : IsColimit (CokernelCofork.ofπ (cokernel.π f) <| show l ≫ cokernel.π f = 0 by simp [i.eq_inv_comp.2 h]) := IsCokernel.ofIsoComp f l i h <| colimit.isColimit _ /-- If `s` is any colimit cokernel cocone over `f` and `i` is an isomorphism such that `s.π ≫ i.hom = l`, then `l` is a cokernel of `f`. -/ def IsCokernel.cokernelIso {Z : C} (l : Y ⟶ Z) {s : CokernelCofork f} (hs : IsColimit s) (i : s.pt ≅ Z) (h : Cofork.π s ≫ i.hom = l) : IsColimit (CokernelCofork.ofπ l <| show f ≫ l = 0 by simp [← h]) := IsColimit.ofIsoColimit hs <| Cocones.ext i fun j => by cases j · dsimp; rw [← h]; simp · exact h /-- If `i` is an isomorphism such that `cokernel.π f ≫ i.hom = l`, then `l` is a cokernel of `f`. -/ def cokernel.cokernelIso [HasCokernel f] {Z : C} (l : Y ⟶ Z) (i : cokernel f ≅ Z) (h : cokernel.π f ≫ i.hom = l) : IsColimit (@CokernelCofork.ofπ _ _ _ _ _ f _ l <| by simp [← h]) := IsCokernel.cokernelIso f l (colimit.isColimit _) i h end Transport section Comparison variable {D : Type u₂} [Category.{v₂} D] [HasZeroMorphisms D] variable (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] /-- The comparison morphism for the kernel of `f`. This is an isomorphism iff `G` preserves the kernel of `f`; see `CategoryTheory/Limits/Preserves/Shapes/Kernels.lean` -/ def kernelComparison [HasKernel f] [HasKernel (G.map f)] : G.obj (kernel f) ⟶ kernel (G.map f) := kernel.lift _ (G.map (kernel.ι f)) (by simp only [← G.map_comp, kernel.condition, Functor.map_zero]) @[reassoc (attr := simp)] theorem kernelComparison_comp_ι [HasKernel f] [HasKernel (G.map f)] : kernelComparison f G ≫ kernel.ι (G.map f) = G.map (kernel.ι f) := kernel.lift_ι _ _ _ @[reassoc (attr := simp)] theorem map_lift_kernelComparison [HasKernel f] [HasKernel (G.map f)] {Z : C} {h : Z ⟶ X} (w : h ≫ f = 0) : G.map (kernel.lift _ h w) ≫ kernelComparison f G = kernel.lift _ (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) := by ext; simp [← G.map_comp] @[reassoc] theorem kernelComparison_comp_kernel_map {X' Y' : C} [HasKernel f] [HasKernel (G.map f)] (g : X' ⟶ Y') [HasKernel g] [HasKernel (G.map g)] (p : X ⟶ X') (q : Y ⟶ Y') (hpq : f ≫ q = p ≫ g) : kernelComparison f G ≫ kernel.map (G.map f) (G.map g) (G.map p) (G.map q) (by rw [← G.map_comp, hpq, G.map_comp]) = G.map (kernel.map f g p q hpq) ≫ kernelComparison g G := kernel.lift_map _ _ (by rw [← G.map_comp, kernel.condition, G.map_zero]) _ _ (by rw [← G.map_comp, kernel.condition, G.map_zero]) _ _ _ (by simp only [← G.map_comp]; exact G.congr_map (kernel.lift_ι _ _ _).symm) _ /-- The comparison morphism for the cokernel of `f`. -/ def cokernelComparison [HasCokernel f] [HasCokernel (G.map f)] : cokernel (G.map f) ⟶ G.obj (cokernel f) := cokernel.desc _ (G.map (coequalizer.π _ _)) (by simp only [← G.map_comp, cokernel.condition, Functor.map_zero]) @[reassoc (attr := simp)] theorem π_comp_cokernelComparison [HasCokernel f] [HasCokernel (G.map f)] : cokernel.π (G.map f) ≫ cokernelComparison f G = G.map (cokernel.π _) := cokernel.π_desc _ _ _ @[reassoc (attr := simp)] theorem cokernelComparison_map_desc [HasCokernel f] [HasCokernel (G.map f)] {Z : C} {h : Y ⟶ Z} (w : f ≫ h = 0) : cokernelComparison f G ≫ G.map (cokernel.desc _ h w) = cokernel.desc _ (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) := by ext; simp [← G.map_comp] @[reassoc] theorem cokernel_map_comp_cokernelComparison {X' Y' : C} [HasCokernel f] [HasCokernel (G.map f)] (g : X' ⟶ Y') [HasCokernel g] [HasCokernel (G.map g)] (p : X ⟶ X') (q : Y ⟶ Y') (hpq : f ≫ q = p ≫ g) : cokernel.map (G.map f) (G.map g) (G.map p) (G.map q) (by rw [← G.map_comp, hpq, G.map_comp]) ≫ cokernelComparison _ G = cokernelComparison _ G ≫ G.map (cokernel.map f g p q hpq) := cokernel.map_desc _ _ (by rw [← G.map_comp, cokernel.condition, G.map_zero]) _ _ (by rw [← G.map_comp, cokernel.condition, G.map_zero]) _ _ _ _ (by simp only [← G.map_comp]; exact G.congr_map (cokernel.π_desc _ _ _)) end Comparison end CategoryTheory.Limits namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] variable [HasZeroMorphisms C] /-- `HasKernels` represents the existence of kernels for every morphism. -/ class HasKernels : Prop where has_limit : ∀ {X Y : C} (f : X ⟶ Y), HasKernel f := by infer_instance /-- `HasCokernels` represents the existence of cokernels for every morphism. -/ class HasCokernels : Prop where has_colimit : ∀ {X Y : C} (f : X ⟶ Y), HasCokernel f := by infer_instance attribute [instance 100] HasKernels.has_limit HasCokernels.has_colimit instance (priority := 100) hasKernels_of_hasEqualizers [HasEqualizers C] : HasKernels C where instance (priority := 100) hasCokernels_of_hasCoequalizers [HasCoequalizers C] : HasCokernels C where section HasKernels variable [HasKernels C] /-- The kernel of an arrow is natural. -/ @[simps] noncomputable def ker : Arrow C ⥤ C where obj f := kernel f.hom map {f g} u := kernel.lift _ (kernel.ι _ ≫ u.left) (by simp) /-- The kernel inclusion is natural. -/ @[simps] def ker.ι : ker (C := C) ⟶ Arrow.leftFunc where app f := kernel.ι _ @[reassoc (attr := simp)] lemma ker.condition : ι C ≫ Arrow.leftToRight = 0 := by cat_disch end HasKernels section HasCokernels variable [HasCokernels C] /-- The cokernel of an arrow is natural. -/ @[simps] noncomputable def coker : Arrow C ⥤ C where obj f := cokernel f.hom map {f g} u := cokernel.desc _ (u.right ≫ cokernel.π _) (by simp [← Arrow.w_assoc u]) /-- The cokernel projection is natural. -/ @[simps] def coker.π : Arrow.rightFunc ⟶ coker (C := C) where app f := cokernel.π _ @[reassoc (attr := simp)] lemma coker.condition : Arrow.leftToRight ≫ π C = 0 := by cat_disch end HasCokernels end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/KernelPair.lean
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.RegularMono /-! # Kernel pairs This file defines what it means for a parallel pair of morphisms `a b : R ⟶ X` to be the kernel pair for a morphism `f`. Some properties of kernel pairs are given, namely allowing one to transfer between the kernel pair of `f₁ ≫ f₂` to the kernel pair of `f₁`. It is also proved that if `f` is a coequalizer of some pair, and `a`,`b` is a kernel pair for `f` then it is a coequalizer of `a`,`b`. ## Implementation The definition is essentially just a wrapper for `IsLimit (PullbackCone.mk _ _ _)`, but the constructions given here are useful, yet awkward to present in that language, so a basic API is developed here. ## TODO - Internal equivalence relations (or congruences) and the fact that every kernel pair induces one, and the converse in an effective regular category (WIP by b-mehta). -/ universe v u u₂ namespace CategoryTheory open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {R X Y Z : C} (f : X ⟶ Y) (a b : R ⟶ X) /-- `IsKernelPair f a b` expresses that `(a, b)` is a kernel pair for `f`, i.e. `a ≫ f = b ≫ f` and the square R → X ↓ ↓ X → Y is a pullback square. This is just an abbreviation for `IsPullback a b f f`. -/ abbrev IsKernelPair := IsPullback a b f f namespace IsKernelPair /-- The data expressing that `(a, b)` is a kernel pair is subsingleton. -/ instance : Subsingleton (IsKernelPair f a b) := ⟨fun P Q => by constructor⟩ /-- If `f` is a monomorphism, then `(𝟙 _, 𝟙 _)` is a kernel pair for `f`. -/ theorem id_of_mono [Mono f] : IsKernelPair f (𝟙 _) (𝟙 _) := ⟨⟨rfl⟩, ⟨PullbackCone.isLimitMkIdId _⟩⟩ instance [Mono f] : Inhabited (IsKernelPair f (𝟙 _) (𝟙 _)) := ⟨id_of_mono f⟩ variable {f a b} /-- Given a pair of morphisms `p`, `q` to `X` which factor through `f`, they factor through any kernel pair of `f`. -/ noncomputable def lift {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : S ⟶ R := PullbackCone.IsLimit.lift k.isLimit _ _ w @[reassoc (attr := simp)] lemma lift_fst {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : k.lift p q w ≫ a = p := PullbackCone.IsLimit.lift_fst _ _ _ _ @[reassoc (attr := simp)] lemma lift_snd {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : k.lift p q w ≫ b = q := PullbackCone.IsLimit.lift_snd _ _ _ _ /-- Given a pair of morphisms `p`, `q` to `X` which factor through `f`, they factor through any kernel pair of `f`. -/ noncomputable def lift' {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : { t : S ⟶ R // t ≫ a = p ∧ t ≫ b = q } := ⟨k.lift p q w, by simp⟩ /-- If `(a,b)` is a kernel pair for `f₁ ≫ f₂` and `a ≫ f₁ = b ≫ f₁`, then `(a,b)` is a kernel pair for just `f₁`. That is, to show that `(a,b)` is a kernel pair for `f₁` it suffices to only show the square commutes, rather than to additionally show it's a pullback. -/ theorem cancel_right {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} (comm : a ≫ f₁ = b ≫ f₁) (big_k : IsKernelPair (f₁ ≫ f₂) a b) : IsKernelPair f₁ a b := { w := comm isLimit' := ⟨PullbackCone.isLimitAux' _ fun s => by let s' : PullbackCone (f₁ ≫ f₂) (f₁ ≫ f₂) := PullbackCone.mk s.fst s.snd (s.condition_assoc _) refine ⟨big_k.isLimit.lift s', big_k.isLimit.fac _ WalkingCospan.left, big_k.isLimit.fac _ WalkingCospan.right, fun m₁ m₂ => ?_⟩ apply big_k.isLimit.hom_ext refine (PullbackCone.mk a b ?_ : PullbackCone (f₁ ≫ f₂) _).equalizer_ext ?_ ?_ · apply reassoc_of% comm · apply m₁.trans (big_k.isLimit.fac s' WalkingCospan.left).symm · apply m₂.trans (big_k.isLimit.fac s' WalkingCospan.right).symm⟩ } /-- If `(a,b)` is a kernel pair for `f₁ ≫ f₂` and `f₂` is mono, then `(a,b)` is a kernel pair for just `f₁`. The converse of `comp_of_mono`. -/ theorem cancel_right_of_mono {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} [Mono f₂] (big_k : IsKernelPair (f₁ ≫ f₂) a b) : IsKernelPair f₁ a b := cancel_right (by rw [← cancel_mono f₂, assoc, assoc, big_k.w]) big_k /-- If `(a,b)` is a kernel pair for `f₁` and `f₂` is mono, then `(a,b)` is a kernel pair for `f₁ ≫ f₂`. The converse of `cancel_right_of_mono`. -/ theorem comp_of_mono {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} [Mono f₂] (small_k : IsKernelPair f₁ a b) : IsKernelPair (f₁ ≫ f₂) a b := { w := by rw [small_k.w_assoc] isLimit' := ⟨by refine PullbackCone.isLimitAux _ (fun s => small_k.lift s.fst s.snd (by rw [← cancel_mono f₂, assoc, s.condition, assoc])) (by simp) (by simp) ?_ intro s m hm apply small_k.isLimit.hom_ext apply PullbackCone.equalizer_ext small_k.cone _ _ · exact (hm WalkingCospan.left).trans (by simp) · exact (hm WalkingCospan.right).trans (by simp)⟩ } /-- If `(a,b)` is the kernel pair of `f`, and `f` is a coequalizer morphism for some parallel pair, then `f` is a coequalizer morphism of `a` and `b`. -/ def toCoequalizer (k : IsKernelPair f a b) [r : RegularEpi f] : IsColimit (Cofork.ofπ f k.w) := by let t := k.isLimit.lift (PullbackCone.mk _ _ r.w) have ht : t ≫ a = r.left := k.isLimit.fac _ WalkingCospan.left have kt : t ≫ b = r.right := k.isLimit.fac _ WalkingCospan.right refine Cofork.IsColimit.mk _ (fun s => Cofork.IsColimit.desc r.isColimit s.π (by rw [← ht, assoc, s.condition, reassoc_of% kt])) (fun s => ?_) (fun s m w => ?_) · apply Cofork.IsColimit.π_desc' r.isColimit · apply Cofork.IsColimit.hom_ext r.isColimit exact w.trans (Cofork.IsColimit.π_desc' r.isColimit _ _).symm /-- If `a₁ a₂ : A ⟶ Y` is a kernel pair for `g : Y ⟶ Z`, then `a₁ ×[Z] X` and `a₂ ×[Z] X` (`A ×[Z] X ⟶ Y ×[Z] X`) is a kernel pair for `Y ×[Z] X ⟶ X`. -/ protected theorem pullback {X Y Z A : C} {g : Y ⟶ Z} {a₁ a₂ : A ⟶ Y} (h : IsKernelPair g a₁ a₂) (f : X ⟶ Z) [HasPullback f g] [HasPullback f (a₁ ≫ g)] : IsKernelPair (pullback.fst f g) (pullback.map f _ f _ (𝟙 X) a₁ (𝟙 Z) (by simp) <| Category.comp_id _) (pullback.map _ _ _ _ (𝟙 X) a₂ (𝟙 Z) (by simp) <| (Category.comp_id _).trans h.1.1) := by refine ⟨⟨by rw [pullback.lift_fst, pullback.lift_fst]⟩, ⟨PullbackCone.isLimitAux _ (fun s => pullback.lift (s.fst ≫ pullback.fst _ _) (h.lift (s.fst ≫ pullback.snd _ _) (s.snd ≫ pullback.snd _ _) ?_ ) ?_) (fun s => ?_) (fun s => ?_) (fun s (m : _ ⟶ pullback f (a₁ ≫ g)) hm => ?_)⟩⟩ · simp_rw [Category.assoc, ← pullback.condition, ← Category.assoc, s.condition] · simp only [assoc, lift_fst_assoc, pullback.condition] · ext <;> simp · ext · simp [s.condition] · simp · apply pullback.hom_ext · simpa using hm WalkingCospan.left =≫ pullback.fst f g · apply PullbackCone.IsLimit.hom_ext h.isLimit · simpa using hm WalkingCospan.left =≫ pullback.snd f g · simpa using hm WalkingCospan.right =≫ pullback.snd f g theorem mono_of_isIso_fst (h : IsKernelPair f a b) [IsIso a] : Mono f := by obtain ⟨l, h₁, h₂⟩ := Limits.PullbackCone.IsLimit.lift' h.isLimit (𝟙 _) (𝟙 _) (by simp) rw [IsPullback.cone_fst, ← IsIso.eq_comp_inv, Category.id_comp] at h₁ rw [h₁, IsIso.inv_comp_eq, Category.comp_id] at h₂ constructor intro Z g₁ g₂ e obtain ⟨l', rfl, rfl⟩ := Limits.PullbackCone.IsLimit.lift' h.isLimit _ _ e rw [IsPullback.cone_fst, h₂] theorem isIso_of_mono (h : IsKernelPair f a b) [Mono f] : IsIso a := by rw [← show _ = a from (Category.comp_id _).symm.trans ((IsKernelPair.id_of_mono f).isLimit.conePointUniqueUpToIso_inv_comp h.isLimit WalkingCospan.left)] infer_instance theorem of_isIso_of_mono [IsIso a] [Mono f] : IsKernelPair f a a := by change IsPullback _ _ _ _ convert (IsPullback.of_horiz_isIso ⟨(rfl : a ≫ 𝟙 X = _ )⟩).paste_vert (IsKernelPair.id_of_mono f) all_goals { simp } end IsKernelPair end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/ZeroObjects.lean
import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Zero objects A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object; see `CategoryTheory.Limits.Shapes.ZeroMorphisms`. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v u v' u' open CategoryTheory open CategoryTheory.Category variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v'} D] namespace CategoryTheory namespace Limits /-- An object `X` in a category is a *zero object* if for every object `Y` there is a unique morphism `to : X → Y` and a unique morphism `from : Y → X`. This is a characteristic predicate for `has_zero_object`. -/ structure IsZero (X : C) : Prop where /-- there are unique morphisms to the object -/ unique_to : ∀ Y, Nonempty (Unique (X ⟶ Y)) /-- there are unique morphisms from the object -/ unique_from : ∀ Y, Nonempty (Unique (Y ⟶ X)) namespace IsZero variable {X Y : C} /-- If `h : IsZero X`, then `h.to_ Y` is a choice of unique morphism `X → Y`. `to` is a reserved word, it was replaced by `to_` -/ protected def to_ (h : IsZero X) (Y : C) : X ⟶ Y := @default _ <| (h.unique_to Y).some.toInhabited theorem eq_to (h : IsZero X) (f : X ⟶ Y) : f = h.to_ Y := @Unique.eq_default _ (id _) _ theorem to_eq (h : IsZero X) (f : X ⟶ Y) : h.to_ Y = f := (h.eq_to f).symm /-- If `h : is_zero X`, then `h.from_ Y` is a choice of unique morphism `Y → X`. `from` is a reserved word, it was replaced by `from_` -/ protected def from_ (h : IsZero X) (Y : C) : Y ⟶ X := @default _ <| (h.unique_from Y).some.toInhabited theorem eq_from (h : IsZero X) (f : Y ⟶ X) : f = h.from_ Y := @Unique.eq_default _ (id _) _ theorem from_eq (h : IsZero X) (f : Y ⟶ X) : h.from_ Y = f := (h.eq_from f).symm theorem eq_of_src (hX : IsZero X) (f g : X ⟶ Y) : f = g := (hX.eq_to f).trans (hX.eq_to g).symm theorem eq_of_tgt (hX : IsZero X) (f g : Y ⟶ X) : f = g := (hX.eq_from f).trans (hX.eq_from g).symm lemma epi (h : IsZero X) {Y : C} (f : Y ⟶ X) : Epi f where left_cancellation _ _ _ := h.eq_of_src _ _ lemma mono (h : IsZero X) {Y : C} (f : X ⟶ Y) : Mono f where right_cancellation _ _ _ := h.eq_of_tgt _ _ /-- Any two zero objects are isomorphic. -/ def iso (hX : IsZero X) (hY : IsZero Y) : X ≅ Y where hom := hX.to_ Y inv := hX.from_ Y hom_inv_id := hX.eq_of_src _ _ inv_hom_id := hY.eq_of_src _ _ /-- A zero object is in particular initial. -/ protected def isInitial (hX : IsZero X) : IsInitial X := @IsInitial.ofUnique _ _ X fun Y => (hX.unique_to Y).some /-- A zero object is in particular terminal. -/ protected def isTerminal (hX : IsZero X) : IsTerminal X := @IsTerminal.ofUnique _ _ X fun Y => (hX.unique_from Y).some /-- The (unique) isomorphism between any initial object and the zero object. -/ def isoIsInitial (hX : IsZero X) (hY : IsInitial Y) : X ≅ Y := IsInitial.uniqueUpToIso hX.isInitial hY /-- The (unique) isomorphism between any terminal object and the zero object. -/ def isoIsTerminal (hX : IsZero X) (hY : IsTerminal Y) : X ≅ Y := IsTerminal.uniqueUpToIso hX.isTerminal hY theorem of_iso (hY : IsZero Y) (e : X ≅ Y) : IsZero X := by refine ⟨fun Z => ⟨⟨⟨e.hom ≫ hY.to_ Z⟩, fun f => ?_⟩⟩, fun Z => ⟨⟨⟨hY.from_ Z ≫ e.inv⟩, fun f => ?_⟩⟩⟩ · rw [← cancel_epi e.inv] apply hY.eq_of_src · rw [← cancel_mono e.hom] apply hY.eq_of_tgt theorem op (h : IsZero X) : IsZero (Opposite.op X) := ⟨fun Y => ⟨⟨⟨(h.from_ (Opposite.unop Y)).op⟩, fun _ => Quiver.Hom.unop_inj (h.eq_of_tgt _ _)⟩⟩, fun Y => ⟨⟨⟨(h.to_ (Opposite.unop Y)).op⟩, fun _ => Quiver.Hom.unop_inj (h.eq_of_src _ _)⟩⟩⟩ theorem unop {X : Cᵒᵖ} (h : IsZero X) : IsZero (Opposite.unop X) := ⟨fun Y => ⟨⟨⟨(h.from_ (Opposite.op Y)).unop⟩, fun _ => Quiver.Hom.op_inj (h.eq_of_tgt _ _)⟩⟩, fun Y => ⟨⟨⟨(h.to_ (Opposite.op Y)).unop⟩, fun _ => Quiver.Hom.op_inj (h.eq_of_src _ _)⟩⟩⟩ end IsZero end Limits open CategoryTheory.Limits theorem Iso.isZero_iff {X Y : C} (e : X ≅ Y) : IsZero X ↔ IsZero Y := ⟨fun h => h.of_iso e.symm, fun h => h.of_iso e⟩ theorem Functor.isZero (F : C ⥤ D) (hF : ∀ X, IsZero (F.obj X)) : IsZero F := by constructor <;> intro G <;> refine ⟨⟨⟨?_⟩, ?_⟩⟩ · refine { app := fun X => (hF _).to_ _ naturality := ?_ } intros exact (hF _).eq_of_src _ _ · intro f ext apply (hF _).eq_of_src _ _ · refine { app := fun X => (hF _).from_ _ naturality := ?_ } intros exact (hF _).eq_of_tgt _ _ · intro f ext apply (hF _).eq_of_tgt _ _ namespace Limits variable (C) /-- A category "has a zero object" if it has an object which is both initial and terminal. -/ class HasZeroObject : Prop where /-- there exists a zero object -/ zero : ∃ X : C, IsZero X instance hasZeroObject_pUnit : HasZeroObject (Discrete PUnit) where zero := ⟨⟨⟨⟩⟩, { unique_to := fun ⟨⟨⟩⟩ => ⟨{ default := 𝟙 _, uniq := by subsingleton }⟩ unique_from := fun ⟨⟨⟩⟩ => ⟨{ default := 𝟙 _, uniq := by subsingleton }⟩}⟩ section variable [HasZeroObject C] /-- Construct a `Zero C` for a category with a zero object. This cannot be a global instance as it will trigger for every `Zero C` typeclass search. -/ protected def HasZeroObject.zero' : Zero C where zero := HasZeroObject.zero.choose scoped[ZeroObject] attribute [instance] CategoryTheory.Limits.HasZeroObject.zero' open ZeroObject theorem isZero_zero : IsZero (0 : C) := HasZeroObject.zero.choose_spec instance hasZeroObject_op : HasZeroObject Cᵒᵖ := ⟨⟨Opposite.op 0, IsZero.op (isZero_zero C)⟩⟩ end open ZeroObject theorem hasZeroObject_unop [HasZeroObject Cᵒᵖ] : HasZeroObject C := ⟨⟨Opposite.unop 0, IsZero.unop (isZero_zero Cᵒᵖ)⟩⟩ variable {C} theorem IsZero.hasZeroObject {X : C} (hX : IsZero X) : HasZeroObject C := ⟨⟨X, hX⟩⟩ /-- Every zero object is isomorphic to *the* zero object. -/ def IsZero.isoZero [HasZeroObject C] {X : C} (hX : IsZero X) : X ≅ 0 := hX.iso (isZero_zero C) theorem IsZero.obj [HasZeroObject D] {F : C ⥤ D} (hF : IsZero F) (X : C) : IsZero (F.obj X) := by let G : C ⥤ D := (CategoryTheory.Functor.const C).obj 0 have hG : IsZero G := Functor.isZero _ fun _ => isZero_zero _ let e : F ≅ G := hF.iso hG exact (isZero_zero _).of_iso (e.app X) namespace HasZeroObject variable [HasZeroObject C] /-- There is a unique morphism from the zero object to any object `X`. -/ protected def uniqueTo (X : C) : Unique (0 ⟶ X) := ((isZero_zero C).unique_to X).some /-- There is a unique morphism from any object `X` to the zero object. -/ protected def uniqueFrom (X : C) : Unique (X ⟶ 0) := ((isZero_zero C).unique_from X).some scoped[ZeroObject] attribute [instance] CategoryTheory.Limits.HasZeroObject.uniqueTo scoped[ZeroObject] attribute [instance] CategoryTheory.Limits.HasZeroObject.uniqueFrom @[ext] theorem to_zero_ext {X : C} (f g : X ⟶ 0) : f = g := (isZero_zero C).eq_of_tgt _ _ @[ext] theorem from_zero_ext {X : C} (f g : 0 ⟶ X) : f = g := (isZero_zero C).eq_of_src _ _ instance (X : C) : Subsingleton (X ≅ 0) := ⟨fun f g => by ext⟩ instance {X : C} (f : 0 ⟶ X) : Mono f where right_cancellation g h _ := by ext instance {X : C} (f : X ⟶ 0) : Epi f where left_cancellation g h _ := by ext instance zero_to_zero_isIso (f : (0 : C) ⟶ 0) : IsIso f := by convert show IsIso (𝟙 (0 : C)) by infer_instance subsingleton /-- A zero object is in particular initial. -/ def zeroIsInitial : IsInitial (0 : C) := (isZero_zero C).isInitial /-- A zero object is in particular terminal. -/ def zeroIsTerminal : IsTerminal (0 : C) := (isZero_zero C).isTerminal /-- A zero object is in particular initial. -/ instance (priority := 10) hasInitial : HasInitial C := hasInitial_of_unique 0 /-- A zero object is in particular terminal. -/ instance (priority := 10) hasTerminal : HasTerminal C := hasTerminal_of_unique 0 /-- The (unique) isomorphism between any initial object and the zero object. -/ def zeroIsoIsInitial {X : C} (t : IsInitial X) : 0 ≅ X := zeroIsInitial.uniqueUpToIso t /-- The (unique) isomorphism between any terminal object and the zero object. -/ def zeroIsoIsTerminal {X : C} (t : IsTerminal X) : 0 ≅ X := zeroIsTerminal.uniqueUpToIso t /-- The (unique) isomorphism between the chosen initial object and the chosen zero object. -/ def zeroIsoInitial [HasInitial C] : 0 ≅ ⊥_ C := zeroIsInitial.uniqueUpToIso initialIsInitial /-- The (unique) isomorphism between the chosen terminal object and the chosen zero object. -/ def zeroIsoTerminal [HasTerminal C] : 0 ≅ ⊤_ C := zeroIsTerminal.uniqueUpToIso terminalIsTerminal instance (priority := 100) initialMonoClass : InitialMonoClass C := InitialMonoClass.of_isInitial zeroIsInitial fun X => by infer_instance end HasZeroObject end Limits open CategoryTheory.Limits open ZeroObject theorem Functor.isZero_iff [HasZeroObject D] (F : C ⥤ D) : IsZero F ↔ ∀ X, IsZero (F.obj X) := ⟨fun hF X => hF.obj X, Functor.isZero _⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/MultiequalizerPullback.lean
import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Multicoequalizers that are pushouts In this file, we show that a multicoequalizer for `I : MultispanIndex (.ofLinearOrder ι) C` is also a pushout when `ι` has exactly two elements. -/ namespace CategoryTheory.Limits.Multicofork.IsColimit variable {C : Type*} [Category C] {J : MultispanShape} [Unique J.L] {I : MultispanIndex J C} (c : Multicofork I) (h : {J.fst default, J.snd default} = Set.univ) (h' : J.fst default ≠ J.snd default) namespace isPushout variable (s : PushoutCocone (I.fst default) (I.snd default)) open Classical in /-- Given a multispan shape `J` which is essentially `.ofLinearOrder ι` (where `ι` has exactly two elements), this is the multicofork deduced from a pushout cocone. -/ noncomputable def multicofork : Multicofork I := Multicofork.ofπ _ s.pt (fun k ↦ if hk : k = J.fst default then eqToHom (by simp [hk]) ≫ s.inl else eqToHom (by obtain rfl : k = J.snd default := by have := h.symm.le (Set.mem_univ k) simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at this tauto rfl) ≫ s.inr) (by rw [Unique.forall_iff] simpa [h'.symm] using s.condition) @[simp] lemma multicofork_π_eq_inl : (multicofork h h' s).π (J.fst default) = s.inl := by dsimp only [multicofork, ofπ, π] rw [dif_pos rfl, eqToHom_refl, Category.id_comp] @[simp] lemma multicofork_π_eq_inr : (multicofork h h' s).π (J.snd default) = s.inr := by dsimp only [multicofork, ofπ, π] rw [dif_neg h'.symm, eqToHom_refl, Category.id_comp] end isPushout include h h' in /-- A multicoequalizer for `I : MultispanIndex J C` is also a pushout when `J` is essentially `.ofLinearOrder ι` where `ι` contains exactly two elements. -/ lemma isPushout (hc : IsColimit c) : IsPushout (I.fst default) (I.snd default) (c.π (J.fst default)) (c.π (J.snd default)) where w := c.condition _ isColimit' := ⟨PushoutCocone.IsColimit.mk _ (fun s ↦ hc.desc (isPushout.multicofork h h' s)) (fun s ↦ by simpa using hc.fac (isPushout.multicofork h h' s) (.right (J.fst default))) (fun s ↦ by simpa using hc.fac (isPushout.multicofork h h' s) (.right (J.snd default))) (fun s m h₁ h₂ ↦ by apply Multicofork.IsColimit.hom_ext hc intro k have := h.symm.le (Set.mem_univ k) simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at this obtain rfl | rfl := this · simpa [h₁] using (hc.fac (isPushout.multicofork h h' s) (.right (J.fst default))).symm · simpa [h₂] using (hc.fac (isPushout.multicofork h h' s) (.right (J.snd default))).symm)⟩ end CategoryTheory.Limits.Multicofork.IsColimit
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/SingleObj.lean
import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.CategoryTheory.SingleObj import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Defs /-! # (Co)limits of functors out of `SingleObj M` We characterise (co)limits of shape `SingleObj M`. Currently only in the category of types. ## Main results * `SingleObj.Types.limitEquivFixedPoints`: The limit of `J : SingleObj G ⥤ Type u` is the fixed points of `J.obj (SingleObj.star G)` under the induced action. * `SingleObj.Types.colimitEquivQuotient`: The colimit of `J : SingleObj G ⥤ Type u` is the quotient of `J.obj (SingleObj.star G)` by the induced action. -/ assert_not_exists MonoidWithZero universe u v namespace CategoryTheory namespace Limits namespace SingleObj variable {M G : Type v} [Monoid M] [Group G] /-- The induced `G`-action on the target of `J : SingleObj G ⥤ Type u`. -/ instance (J : SingleObj M ⥤ Type u) : MulAction M (J.obj (SingleObj.star M)) where smul g x := J.map g x one_smul x := by change J.map (𝟙 _) x = x simp only [FunctorToTypes.map_id_apply] mul_smul g h x := by change J.map (g * h) x = (J.map h ≫ J.map g) x rw [← SingleObj.comp_as_mul] · simp only [FunctorToTypes.map_comp_apply, types_comp_apply] rfl section Limits variable (J : SingleObj M ⥤ Type u) /-- The equivalence between sections of `J : SingleObj M ⥤ Type u` and fixed points of the induced action on `J.obj (SingleObj.star M)`. -/ @[simps] def Types.sections.equivFixedPoints : J.sections ≃ MulAction.fixedPoints M (J.obj (SingleObj.star M)) where toFun s := ⟨s.val _, s.property⟩ invFun p := ⟨fun _ ↦ p.val, p.property⟩ /-- The limit of `J : SingleObj M ⥤ Type u` is equivalent to the fixed points of the induced action on `J.obj (SingleObj.star M)`. -/ @[simps!] noncomputable def Types.limitEquivFixedPoints : limit J ≃ MulAction.fixedPoints M (J.obj (SingleObj.star M)) := (Types.limitEquivSections J).trans (Types.sections.equivFixedPoints J) end Limits section Colimits variable {G : Type v} [Group G] (J : SingleObj G ⥤ Type u) /-- The relation used to construct colimits in types for `J : SingleObj G ⥤ Type u` is equivalent to the `MulAction.orbitRel` equivalence relation on `J.obj (SingleObj.star G)`. -/ lemma colimitTypeRel_iff_orbitRel (x y : J.obj (SingleObj.star G)) : J.ColimitTypeRel ⟨SingleObj.star G, x⟩ ⟨SingleObj.star G, y⟩ ↔ MulAction.orbitRel G (J.obj (SingleObj.star G)) x y := by conv => rhs; rw [Setoid.comm'] change (∃ g : G, y = g • x) ↔ (∃ g : G, g • x = y) grind @[deprecated (since := "2025-06-22")] alias Types.Quot.Rel.iff_orbitRel := colimitTypeRel_iff_orbitRel /-- The explicit quotient construction of the colimit of `J : SingleObj G ⥤ Type u` is equivalent to the quotient of `J.obj (SingleObj.star G)` by the induced action. -/ @[simps] def colimitTypeRelEquivOrbitRelQuotient : J.ColimitType ≃ MulAction.orbitRel.Quotient G (J.obj (SingleObj.star G)) where toFun := Quot.lift (fun p => ⟦p.2⟧) <| fun a b h => Quotient.sound <| (colimitTypeRel_iff_orbitRel J a.2 b.2).mp h invFun := Quot.lift (fun x => Quot.mk _ ⟨SingleObj.star G, x⟩) <| fun a b h => Quot.sound <| (colimitTypeRel_iff_orbitRel J a b).mpr h left_inv := fun x => Quot.inductionOn x (fun _ ↦ rfl) right_inv := fun x => Quot.inductionOn x (fun _ ↦ rfl) @[deprecated (since := "2025-06-22")] alias Types.Quot.equivOrbitRelQuotient := colimitTypeRelEquivOrbitRelQuotient /-- The colimit of `J : SingleObj G ⥤ Type u` is equivalent to the quotient of `J.obj (SingleObj.star G)` by the induced action. -/ @[simps!] noncomputable def Types.colimitEquivQuotient : colimit J ≃ MulAction.orbitRel.Quotient G (J.obj (SingleObj.star G)) := (Types.colimitEquivColimitType J).trans (colimitTypeRelEquivOrbitRelQuotient J) end Colimits end SingleObj end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/FiniteLimits.lean
import Mathlib.CategoryTheory.FinCategory.AsType import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.Data.Fintype.Option /-! # Categories with finite limits. A typeclass for categories with all finite (co)limits. -/ universe w' w v' u' v u noncomputable section open CategoryTheory namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] -- We can't just made this an `abbreviation` -- because of https://github.com/leanprover-community/lean/issues/429 /-- A category has all finite limits if every functor `J ⥤ C` with a `FinCategory J` instance and `J : Type` has a limit. This is often called 'finitely complete'. -/ class HasFiniteLimits : Prop where /-- `C` has all limits over any type `J` whose objects and morphisms lie in the same universe and which has `FinType` objects and morphisms -/ out (J : Type) [𝒥 : SmallCategory J] [@FinCategory J 𝒥] : @HasLimitsOfShape J 𝒥 C _ instance (priority := 100) hasLimitsOfShape_of_hasFiniteLimits [HasFiniteLimits C] (J : Type w) [SmallCategory J] [FinCategory J] : HasLimitsOfShape J C := by apply @hasLimitsOfShape_of_equivalence _ _ _ _ _ _ (FinCategory.equivAsType J) ?_ apply HasFiniteLimits.out lemma hasFiniteLimits_of_hasLimitsOfSize [HasLimitsOfSize.{v', u'} C] : HasFiniteLimits C where out := fun J hJ hJ' => haveI := hasLimitsOfSizeShrink.{0, 0} C let F := @FinCategory.equivAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ' @hasLimitsOfShape_of_equivalence (@FinCategory.AsType J (@FinCategory.fintypeObj J hJ hJ')) (@FinCategory.categoryAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ') _ _ J hJ F _ /-- If `C` has all limits, it has finite limits. -/ instance (priority := 100) hasFiniteLimits_of_hasLimits [HasLimits C] : HasFiniteLimits C := hasFiniteLimits_of_hasLimitsOfSize C instance (priority := 90) hasFiniteLimits_of_hasLimitsOfSize₀ [HasLimitsOfSize.{0, 0} C] : HasFiniteLimits C := hasFiniteLimits_of_hasLimitsOfSize C instance (J : Type) [hJ : SmallCategory J] : Category (ULiftHom (ULift J)) := (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) /-- We can always derive `HasFiniteLimits C` by providing limits at an arbitrary universe. -/ theorem hasFiniteLimits_of_hasFiniteLimits_of_size (h : ∀ (J : Type w) {𝒥 : SmallCategory J} (_ : @FinCategory J 𝒥), HasLimitsOfShape J C) : HasFiniteLimits C where out := fun J hJ hhJ => by haveI := h (ULiftHom.{w} (ULift.{w} J)) <| @CategoryTheory.finCategoryUlift J hJ hhJ have l : @Equivalence J (ULiftHom (ULift J)) hJ (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) := @ULiftHomULiftCategory.equiv J hJ apply @hasLimitsOfShape_of_equivalence (ULiftHom (ULift J)) (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) C _ J hJ l.symm _ /-- A category has all finite colimits if every functor `J ⥤ C` with a `FinCategory J` instance and `J : Type` has a colimit. This is often called 'finitely cocomplete'. -/ class HasFiniteColimits : Prop where /-- `C` has all colimits over any type `J` whose objects and morphisms lie in the same universe and which has `Fintype` objects and morphisms -/ out (J : Type) [𝒥 : SmallCategory J] [@FinCategory J 𝒥] : @HasColimitsOfShape J 𝒥 C _ -- See note [instance argument order] instance (priority := 100) hasColimitsOfShape_of_hasFiniteColimits [HasFiniteColimits C] (J : Type w) [SmallCategory J] [FinCategory J] : HasColimitsOfShape J C := by refine @hasColimitsOfShape_of_equivalence _ _ _ _ _ _ (FinCategory.equivAsType J) ?_ apply HasFiniteColimits.out lemma hasFiniteColimits_of_hasColimitsOfSize [HasColimitsOfSize.{v', u'} C] : HasFiniteColimits C where out := fun J hJ hJ' => haveI := hasColimitsOfSizeShrink.{0, 0} C let F := @FinCategory.equivAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ' @hasColimitsOfShape_of_equivalence (@FinCategory.AsType J (@FinCategory.fintypeObj J hJ hJ')) (@FinCategory.categoryAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ') _ _ J hJ F _ instance (priority := 100) hasFiniteColimits_of_hasColimits [HasColimits C] : HasFiniteColimits C := hasFiniteColimits_of_hasColimitsOfSize C instance (priority := 90) hasFiniteColimits_of_hasColimitsOfSize₀ [HasColimitsOfSize.{0, 0} C] : HasFiniteColimits C := hasFiniteColimits_of_hasColimitsOfSize C /-- We can always derive `HasFiniteColimits C` by providing colimits at an arbitrary universe. -/ theorem hasFiniteColimits_of_hasFiniteColimits_of_size (h : ∀ (J : Type w) {𝒥 : SmallCategory J} (_ : @FinCategory J 𝒥), HasColimitsOfShape J C) : HasFiniteColimits C where out := fun J hJ hhJ => by haveI := h (ULiftHom.{w} (ULift.{w} J)) <| @CategoryTheory.finCategoryUlift J hJ hhJ have l : @Equivalence J (ULiftHom (ULift J)) hJ (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) := @ULiftHomULiftCategory.equiv J hJ apply @hasColimitsOfShape_of_equivalence (ULiftHom (ULift J)) (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) C _ J hJ (@Equivalence.symm J hJ (ULiftHom (ULift J)) (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) l) _ section open WalkingParallelPair WalkingParallelPairHom instance fintypeWalkingParallelPair : Fintype WalkingParallelPair where elems := [WalkingParallelPair.zero, WalkingParallelPair.one].toFinset complete x := by cases x <;> simp attribute [local aesop safe cases] WalkingParallelPair WalkingParallelPairHom instance instFintypeWalkingParallelPairHom (j j' : WalkingParallelPair) : Fintype (WalkingParallelPairHom j j') where elems := WalkingParallelPair.recOn j (WalkingParallelPair.recOn j' [WalkingParallelPairHom.id zero].toFinset [left, right].toFinset) (WalkingParallelPair.recOn j' ∅ [WalkingParallelPairHom.id one].toFinset) complete := by aesop end instance : FinCategory WalkingParallelPair where fintypeObj := fintypeWalkingParallelPair fintypeHom := instFintypeWalkingParallelPairHom /-- Equalizers are finite limits, so if `C` has all finite limits, it also has all equalizers -/ example [HasFiniteLimits C] : HasEqualizers C := by infer_instance /-- Coequalizers are finite colimits, of if `C` has all finite colimits, it also has all coequalizers -/ example [HasFiniteColimits C] : HasCoequalizers C := by infer_instance variable {J : Type v} -- Porting note: we would like to write something like: -- attribute [local aesop safe cases] WidePullbackShape WidePushoutShape -- But aesop can't add a `cases` attribute to type synonyms. namespace WidePullbackShape instance fintypeObj [Fintype J] : Fintype (WidePullbackShape J) := inferInstanceAs <| Fintype (Option _) instance fintypeHom (j j' : WidePullbackShape J) : Fintype (j ⟶ j') where elems := by obtain - | j' := j' · obtain - | j := j · exact {Hom.id none} · exact {Hom.term j} · by_cases h : some j' = j · rw [h] exact {Hom.id j} · exact ∅ complete := by rintro (_ | _) · cases j <;> simp · simp end WidePullbackShape namespace WidePushoutShape instance fintypeObj [Fintype J] : Fintype (WidePushoutShape J) := inferInstanceAs <| Fintype (Option _) instance fintypeHom (j j' : WidePushoutShape J) : Fintype (j ⟶ j') where elems := by obtain - | j := j · obtain - | j' := j' · exact {Hom.id none} · exact {Hom.init j'} · by_cases h : some j = j' · rw [h] exact {Hom.id j'} · exact ∅ complete := by rintro (_ | _) · cases j <;> simp · simp end WidePushoutShape instance finCategoryWidePullback [Fintype J] : FinCategory (WidePullbackShape J) where fintypeHom := WidePullbackShape.fintypeHom instance finCategoryWidePushout [Fintype J] : FinCategory (WidePushoutShape J) where fintypeHom := WidePushoutShape.fintypeHom -- We can't just made this an `abbreviation` -- because of https://github.com/leanprover-community/lean/issues/429 /-- A category `HasFiniteWidePullbacks` if it has all limits of shape `WidePullbackShape J` for finite `J`, i.e. if it has a wide pullback for every finite collection of morphisms with the same codomain. -/ class HasFiniteWidePullbacks : Prop where /-- `C` has all wide pullbacks for any Finite `J` -/ out (J : Type) [Finite J] : HasLimitsOfShape (WidePullbackShape J) C instance hasLimitsOfShape_widePullbackShape (J : Type) [Finite J] [HasFiniteWidePullbacks C] : HasLimitsOfShape (WidePullbackShape J) C := by haveI := @HasFiniteWidePullbacks.out C _ _ J infer_instance /-- A category `HasFiniteWidePushouts` if it has all colimits of shape `WidePushoutShape J` for finite `J`, i.e. if it has a wide pushout for every finite collection of morphisms with the same domain. -/ class HasFiniteWidePushouts : Prop where /-- `C` has all wide pushouts for any Finite `J` -/ out (J : Type) [Finite J] : HasColimitsOfShape (WidePushoutShape J) C instance hasColimitsOfShape_widePushoutShape (J : Type) [Finite J] [HasFiniteWidePushouts C] : HasColimitsOfShape (WidePushoutShape J) C := by haveI := @HasFiniteWidePushouts.out C _ _ J infer_instance /-- Finite wide pullbacks are finite limits, so if `C` has all finite limits, it also has finite wide pullbacks -/ instance (priority := 900) hasFiniteWidePullbacks_of_hasFiniteLimits [HasFiniteLimits C] : HasFiniteWidePullbacks C := ⟨fun J _ => by cases nonempty_fintype J; exact HasFiniteLimits.out _⟩ /-- Finite wide pushouts are finite colimits, so if `C` has all finite colimits, it also has finite wide pushouts -/ instance (priority := 900) hasFiniteWidePushouts_of_has_finite_limits [HasFiniteColimits C] : HasFiniteWidePushouts C := ⟨fun J _ => by cases nonempty_fintype J; exact HasFiniteColimits.out _⟩ instance fintypeWalkingPair : Fintype WalkingPair where elems := {WalkingPair.left, WalkingPair.right} complete x := by cases x <;> simp /-- Pullbacks are finite limits, so if `C` has all finite limits, it also has all pullbacks -/ example [HasFiniteWidePullbacks C] : HasPullbacks C := by infer_instance /-- Pushouts are finite colimits, so if `C` has all finite colimits, it also has all pushouts -/ example [HasFiniteWidePushouts C] : HasPushouts C := by infer_instance end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Grothendieck.lean
import Mathlib.CategoryTheory.Grothendieck import Mathlib.CategoryTheory.Limits.HasLimits /-! # (Co)limits on the (strict) Grothendieck Construction * Shows that if a functor `G : Grothendieck F ⥤ H`, with `F : C ⥤ Cat`, has a colimit, and every fiber of `G` has a colimit, then so does the fiberwise colimit functor `C ⥤ H`. * Vice versa, if a each fiber of `G` has a colimit and the fiberwise colimit functor has a colimit, then `G` has a colimit. * Shows that colimits of functors on the Grothendieck construction are colimits of "fibered colimits", i.e. of applying the colimit to each fiber of the functor. * Derives `HasColimitsOfShape (Grothendieck F) H` with `F : C ⥤ Cat` from the presence of colimits on each fiber shape `F.obj X` and on the base category `C`. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Functor namespace Limits variable {C : Type u₁} [Category.{v₁} C] variable {F : C ⥤ Cat} variable {H : Type u₂} [Category.{v₂} H] variable (G : Grothendieck F ⥤ H) noncomputable section variable [∀ {X Y : C} (f : X ⟶ Y), HasColimit (F.map f ⋙ Grothendieck.ι F Y ⋙ G)] @[local instance] lemma hasColimit_ι_comp : ∀ X, HasColimit (Grothendieck.ι F X ⋙ G) := fun X => hasColimit_of_iso (F := F.map (𝟙 _) ⋙ Grothendieck.ι F X ⋙ G) <| (leftUnitor (Grothendieck.ι F X ⋙ G)).symm ≪≫ (isoWhiskerRight (eqToIso (F.map_id X).symm) (Grothendieck.ι F X ⋙ G)) /-- A functor taking a colimit on each fiber of a functor `G : Grothendieck F ⥤ H`. -/ @[simps] def fiberwiseColimit : C ⥤ H where obj X := colimit (Grothendieck.ι F X ⋙ G) map {X Y} f := colimMap (whiskerRight (Grothendieck.ιNatTrans f) G ≫ (associator _ _ _).hom) ≫ colimit.pre (Grothendieck.ι F Y ⋙ G) (F.map f) map_id X := by ext d simp only [Functor.comp_obj, Grothendieck.ιNatTrans, Grothendieck.ι_obj, ι_colimMap_assoc, NatTrans.comp_app, whiskerRight_app, Functor.associator_hom_app, Category.comp_id, colimit.ι_pre] conv_rhs => rw [← colimit.eqToHom_comp_ι (Grothendieck.ι F X ⋙ G) (j := (F.map (𝟙 X)).obj d) (by simp)] rw [← eqToHom_map G (by simp), Grothendieck.eqToHom_eq] rfl map_comp {X Y Z} f g := by ext d simp only [Functor.comp_obj, Grothendieck.ιNatTrans, ι_colimMap_assoc, NatTrans.comp_app, whiskerRight_app, Functor.associator_hom_app, Category.comp_id, colimit.ι_pre, Category.assoc, colimit.ι_pre_assoc] rw [← Category.assoc, ← G.map_comp] conv_rhs => rw [← colimit.eqToHom_comp_ι (Grothendieck.ι F Z ⋙ G) (j := (F.map (f ≫ g)).obj d) (by simp)] rw [← Category.assoc, ← eqToHom_map G (by simp), ← G.map_comp, Grothendieck.eqToHom_eq] congr 2 fapply Grothendieck.ext · simp only [eqToHom_refl, Category.assoc, Grothendieck.comp_base, Category.comp_id] · simp only [Grothendieck.ι_obj, eqToHom_refl, Grothendieck.comp_base, Category.comp_id, Grothendieck.comp_fiber, Functor.map_id] conv_rhs => enter [2, 1]; rw [eqToHom_map (F.map (𝟙 Z))] conv_rhs => rw [eqToHom_trans, eqToHom_trans] variable (H) (F) in /-- Similar to `colimit` and `colim`, taking fiberwise colimits is a functor `(Grothendieck F ⥤ H) ⥤ (C ⥤ H)` between functor categories. -/ @[simps] def fiberwiseColim [∀ c, HasColimitsOfShape (F.obj c) H] : (Grothendieck F ⥤ H) ⥤ (C ⥤ H) where obj G := fiberwiseColimit G map α := { app := fun c => colim.map (whiskerLeft _ α) naturality := fun c₁ c₂ f => by apply colimit.hom_ext; simp } map_id G := by ext; simp; apply Functor.map_id colim map_comp α β := by ext; simp; apply Functor.map_comp colim /-- Every functor `G : Grothendieck F ⥤ H` induces a natural transformation from `G` to the composition of the forgetful functor on `Grothendieck F` with the fiberwise colimit on `G`. -/ @[simps] def natTransIntoForgetCompFiberwiseColimit : G ⟶ Grothendieck.forget F ⋙ fiberwiseColimit G where app X := colimit.ι (Grothendieck.ι F X.base ⋙ G) X.fiber naturality _ _ f := by simp only [Functor.comp_obj, Grothendieck.forget_obj, fiberwiseColimit_obj, Functor.comp_map, Grothendieck.forget_map, fiberwiseColimit_map, ι_colimMap_assoc, Grothendieck.ι_obj, NatTrans.comp_app, whiskerRight_app, Functor.associator_hom_app, Category.comp_id, colimit.ι_pre] rw [← colimit.w (Grothendieck.ι F _ ⋙ G) f.fiber] simp only [← Category.assoc, Functor.comp_obj, Functor.comp_map, ← G.map_comp] congr 2 apply Grothendieck.ext <;> simp variable {G} in /-- A cocone on a functor `G : Grothendieck F ⥤ H` induces a cocone on the fiberwise colimit on `G`. -/ @[simps] def coconeFiberwiseColimitOfCocone (c : Cocone G) : Cocone (fiberwiseColimit G) where pt := c.pt ι := { app := fun X => colimit.desc _ (c.whisker (Grothendieck.ι F X)), naturality := fun _ _ f => by dsimp; ext; simp } variable {G} in /-- If `c` is a colimit cocone on `G : Grothendieck F ⥤ H`, then the induced cocone on the fiberwise colimit on `G` is a colimit cocone, too. -/ def isColimitCoconeFiberwiseColimitOfCocone {c : Cocone G} (hc : IsColimit c) : IsColimit (coconeFiberwiseColimitOfCocone c) where desc s := hc.desc <| Cocone.mk s.pt <| natTransIntoForgetCompFiberwiseColimit G ≫ whiskerLeft (Grothendieck.forget F) s.ι fac s c := by dsimp; ext; simp uniq s m hm := hc.hom_ext fun X => by have := hm X.base simp only [Functor.const_obj_obj, IsColimit.fac, NatTrans.comp_app, Functor.comp_obj, Grothendieck.forget_obj, natTransIntoForgetCompFiberwiseColimit_app, whiskerLeft_app] simp only [coconeFiberwiseColimitOfCocone_pt, Functor.const_obj_obj, coconeFiberwiseColimitOfCocone_ι_app] at this simp [← this] lemma hasColimit_fiberwiseColimit [HasColimit G] : HasColimit (fiberwiseColimit G) where exists_colimit := ⟨⟨_, isColimitCoconeFiberwiseColimitOfCocone (colimit.isColimit _)⟩⟩ variable {G} /-- For a functor `G : Grothendieck F ⥤ H`, every cocone over `fiberwiseColimit G` induces a cocone over `G` itself. -/ @[simps] def coconeOfCoconeFiberwiseColimit (c : Cocone (fiberwiseColimit G)) : Cocone G where pt := c.pt ι := { app := fun X => colimit.ι (Grothendieck.ι F X.base ⋙ G) X.fiber ≫ c.ι.app X.base naturality := fun {X Y} ⟨f, g⟩ => by simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.comp_id] rw [← Category.assoc, ← c.w f, ← Category.assoc] simp only [fiberwiseColimit_obj, fiberwiseColimit_map, ι_colimMap_assoc, Functor.comp_obj, Grothendieck.ι_obj, NatTrans.comp_app, whiskerRight_app, Functor.associator_hom_app, Category.comp_id, colimit.ι_pre] rw [← colimit.w _ g, ← Category.assoc, Functor.comp_map, ← G.map_comp] congr <;> simp } /-- If a cocone `c` over a functor `G : Grothendieck F ⥤ H` is a colimit, than the induced cocone `coconeOfFiberwiseCocone G c` -/ def isColimitCoconeOfFiberwiseCocone {c : Cocone (fiberwiseColimit G)} (hc : IsColimit c) : IsColimit (coconeOfCoconeFiberwiseColimit c) where desc s := hc.desc <| Cocone.mk s.pt <| { app := fun X => colimit.desc (Grothendieck.ι F X ⋙ G) (s.whisker _) } uniq s m hm := hc.hom_ext <| fun X => by simp only [fiberwiseColimit_obj, Functor.const_obj_obj, IsColimit.fac] simp only [coconeOfCoconeFiberwiseColimit_pt, Functor.const_obj_obj, coconeOfCoconeFiberwiseColimit_ι_app, Category.assoc] at hm ext d simp [hm ⟨X, d⟩] variable [HasColimit (fiberwiseColimit G)] variable (G) /-- We can infer that a functor `G : Grothendieck F ⥤ H`, with `F : C ⥤ Cat`, has a colimit from the fact that each of its fibers has a colimit and that these fiberwise colimits, as a functor `C ⥤ H` have a colimit. -/ @[local instance] lemma hasColimit_of_hasColimit_fiberwiseColimit_of_hasColimit : HasColimit G where exists_colimit := ⟨⟨_, isColimitCoconeOfFiberwiseCocone (colimit.isColimit _)⟩⟩ /-- For every functor `G` on the Grothendieck construction `Grothendieck F`, if `G` has a colimit and every fiber of `G` has a colimit, then taking this colimit is isomorphic to first taking the fiberwise colimit and then the colimit of the resulting functor. -/ def colimitFiberwiseColimitIso : colimit (fiberwiseColimit G) ≅ colimit G := IsColimit.coconePointUniqueUpToIso (colimit.isColimit (fiberwiseColimit G)) (isColimitCoconeFiberwiseColimitOfCocone (colimit.isColimit _)) @[reassoc (attr := simp)] lemma ι_colimitFiberwiseColimitIso_hom (X : C) (d : F.obj X) : colimit.ι (Grothendieck.ι F X ⋙ G) d ≫ colimit.ι (fiberwiseColimit G) X ≫ (colimitFiberwiseColimitIso G).hom = colimit.ι G ⟨X, d⟩ := by simp [colimitFiberwiseColimitIso] @[reassoc (attr := simp)] lemma ι_colimitFiberwiseColimitIso_inv (X : Grothendieck F) : colimit.ι G X ≫ (colimitFiberwiseColimitIso G).inv = colimit.ι (Grothendieck.ι F X.base ⋙ G) X.fiber ≫ colimit.ι (fiberwiseColimit G) X.base := by rw [Iso.comp_inv_eq] simp end @[instance] theorem hasColimitsOfShape_grothendieck [∀ X, HasColimitsOfShape (F.obj X) H] [HasColimitsOfShape C H] : HasColimitsOfShape (Grothendieck F) H where has_colimit _ := hasColimit_of_hasColimit_fiberwiseColimit_of_hasColimit _ noncomputable section FiberwiseColim variable [∀ (c : C), HasColimitsOfShape (↑(F.obj c)) H] [HasColimitsOfShape C H] /-- The isomorphism `colimitFiberwiseColimitIso` induces an isomorphism of functors `(J ⥤ C) ⥤ C` between `fiberwiseColim F H ⋙ colim` and `colim`. -/ @[simps!] def fiberwiseColimCompColimIso : fiberwiseColim F H ⋙ colim ≅ colim := NatIso.ofComponents (fun G => colimitFiberwiseColimitIso G) fun _ => by (iterate 2 apply colimit.hom_ext; intro); simp /-- Composing `fiberwiseColim F H` with the evaluation functor `(evaluation C H).obj c` is naturally isomorphic to precomposing the Grothendieck inclusion `Grothendieck.ι` to `colim`. -/ @[simps!] def fiberwiseColimCompEvaluationIso (c : C) : fiberwiseColim F H ⋙ (evaluation C H).obj c ≅ (whiskeringLeft _ _ _).obj (Grothendieck.ι F c) ⋙ colim := Iso.refl _ end FiberwiseColim end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Connected.lean
import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks /-! # Connected shapes In this file we prove that various shapes are connected. -/ namespace CategoryTheory open Limits instance {J} : IsConnected (WidePullbackShape J) := by apply IsConnected.of_constant_of_preserves_morphisms intro α F H suffices ∀ i, F i = F none from fun j j' ↦ (this j).trans (this j').symm rintro ⟨⟩ exacts [rfl, H (.term _)] instance {J} : IsConnected (WidePushoutShape J) := by apply IsConnected.of_constant_of_preserves_morphisms intro α F H suffices ∀ i, F i = F none from fun j j' ↦ (this j).trans (this j').symm rintro ⟨⟩ exacts [rfl, (H (.init _)).symm] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/SplitEqualizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers /-! # Split Equalizers We define what it means for a triple of morphisms `f g : X ⟶ Y`, `ι : W ⟶ X` to be a split equalizer: there is a retraction `r` of `ι` and a retraction `t` of `g`, which additionally satisfy `t ≫ f = r ≫ ι`. In addition, we show that every split equalizer is an equalizer (`CategoryTheory.IsSplitEqualizer.isEqualizer`) and absolute (`CategoryTheory.IsSplitEqualizer.map`) A pair `f g : X ⟶ Y` has a split equalizer if there is a `W` and `ι : W ⟶ X` making `f,g,ι` a split equalizer. A pair `f g : X ⟶ Y` has a `G`-split equalizer if `G f, G g` has a split equalizer. These definitions and constructions are useful in particular for the comonadicity theorems. This file was adapted from `Mathlib/CategoryTheory/Limits/Shapes/SplitCoequalizer.lean`. Please try to keep them in sync. -/ namespace CategoryTheory universe v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {X Y : C} (f g : X ⟶ Y) /-- A split equalizer diagram consists of morphisms ``` ι f W → X ⇉ Y g ``` satisfying `ι ≫ f = ι ≫ g` together with morphisms ``` r t W ← X ← Y ``` satisfying `ι ≫ r = 𝟙 W`, `g ≫ t = 𝟙 X` and `f ≫ t = r ≫ ι`. The name "equalizer" is appropriate, since any split equalizer is a equalizer, see `CategoryTheory.IsSplitEqualizer.isEqualizer`. Split equalizers are also absolute, since a functor preserves all the structure above. -/ structure IsSplitEqualizer {W : C} (ι : W ⟶ X) where /-- A map from `X` to the equalizer -/ leftRetraction : X ⟶ W /-- A map in the opposite direction to `f` and `g` -/ rightRetraction : Y ⟶ X /-- Composition of `ι` with `f` and with `g` agree -/ condition : ι ≫ f = ι ≫ g := by cat_disch /-- `leftRetraction` splits `ι` -/ ι_leftRetraction : ι ≫ leftRetraction = 𝟙 W := by cat_disch /-- `rightRetraction` splits `g` -/ bottom_rightRetraction : g ≫ rightRetraction = 𝟙 X := by cat_disch /-- `f` composed with `rightRetraction` is `leftRetraction` composed with `ι` -/ top_rightRetraction : f ≫ rightRetraction = leftRetraction ≫ ι := by cat_disch instance {X : C} : Inhabited (IsSplitEqualizer (𝟙 X) (𝟙 X) (𝟙 X)) where default := { leftRetraction := 𝟙 X, rightRetraction := 𝟙 X } open IsSplitEqualizer attribute [reassoc] condition attribute [reassoc (attr := simp)] ι_leftRetraction bottom_rightRetraction top_rightRetraction variable {f g} /-- Split equalizers are absolute: they are preserved by any functor. -/ @[simps] def IsSplitEqualizer.map {W : C} {ι : W ⟶ X} (q : IsSplitEqualizer f g ι) (F : C ⥤ D) : IsSplitEqualizer (F.map f) (F.map g) (F.map ι) where leftRetraction := F.map q.leftRetraction rightRetraction := F.map q.rightRetraction condition := by rw [← F.map_comp, q.condition, F.map_comp] ι_leftRetraction := by rw [← F.map_comp, q.ι_leftRetraction, F.map_id] bottom_rightRetraction := by rw [← F.map_comp, q.bottom_rightRetraction, F.map_id] top_rightRetraction := by rw [← F.map_comp, q.top_rightRetraction, F.map_comp] section open Limits /-- A split equalizer clearly induces a fork. -/ @[simps! pt] def IsSplitEqualizer.asFork {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) : Fork f g := Fork.ofι h t.condition @[simp] theorem IsSplitEqualizer.asFork_ι {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) : t.asFork.ι = h := rfl /-- The fork induced by a split equalizer is an equalizer, justifying the name. In some cases it is more convenient to show a given fork is an equalizer by showing it is split. -/ def IsSplitEqualizer.isEqualizer {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) : IsLimit t.asFork := Fork.IsLimit.mk' _ fun s => ⟨ s.ι ≫ t.leftRetraction, by simp [- top_rightRetraction, ← t.top_rightRetraction, s.condition_assoc], fun hm => by simp [← hm] ⟩ end variable (f g) /-- The pair `f,g` is a cosplit pair if there is an `h : W ⟶ X` so that `f, g, h` forms a split equalizer in `C`. -/ class HasSplitEqualizer : Prop where /-- There is some split equalizer -/ splittable : ∃ (W : C) (h : W ⟶ X), Nonempty (IsSplitEqualizer f g h) /-- The pair `f,g` is a `G`-cosplit pair if there is an `h : W ⟶ G X` so that `G f, G g, h` forms a split equalizer in `D`. -/ abbrev Functor.IsCosplitPair : Prop := HasSplitEqualizer (G.map f) (G.map g) /-- Get the equalizer object from the typeclass `IsCosplitPair`. -/ noncomputable def HasSplitEqualizer.equalizerOfSplit [HasSplitEqualizer f g] : C := (splittable (f := f) (g := g)).choose /-- Get the equalizer morphism from the typeclass `IsCosplitPair`. -/ noncomputable def HasSplitEqualizer.equalizerι [HasSplitEqualizer f g] : HasSplitEqualizer.equalizerOfSplit f g ⟶ X := (splittable (f := f) (g := g)).choose_spec.choose /-- The equalizer morphism `equalizerι` gives a split equalizer on `f,g`. -/ noncomputable def HasSplitEqualizer.isSplitEqualizer [HasSplitEqualizer f g] : IsSplitEqualizer f g (HasSplitEqualizer.equalizerι f g) := Classical.choice (splittable (f := f) (g := g)).choose_spec.choose_spec /-- If `f, g` is cosplit, then `G f, G g` is cosplit. -/ instance map_is_cosplit_pair [HasSplitEqualizer f g] : HasSplitEqualizer (G.map f) (G.map g) where splittable := ⟨_, _, ⟨IsSplitEqualizer.map (HasSplitEqualizer.isSplitEqualizer f g) _⟩⟩ namespace Limits /-- If a pair has a split equalizer, it has a equalizer. -/ instance (priority := 1) hasEqualizer_of_hasSplitEqualizer [HasSplitEqualizer f g] : HasEqualizer f g := HasLimit.mk ⟨_, (HasSplitEqualizer.isSplitEqualizer f g).isEqualizer⟩ end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Multiequalizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.ConeCategory /-! # Multi-(co)equalizers A *multiequalizer* is an equalizer of two morphisms between two products. Since both products and equalizers are limits, such an object is again a limit. This file provides the diagram whose limit is indeed such an object. In fact, it is well-known that any limit can be obtained as a multiequalizer. The dual construction (multicoequalizers) is also provided. ## Projects Prove that a multiequalizer can be identified with an equalizer between products (and analogously for multicoequalizers). Prove that the limit of any diagram is a multiequalizer (and similarly for colimits). -/ namespace CategoryTheory.Limits universe w w' v u /-- The shape of a multiequalizer diagram. It involves two types `L` and `R`, and two maps `R → L`. -/ @[nolint checkUnivs] structure MulticospanShape where /-- the left type -/ L : Type w /-- the right type -/ R : Type w' /-- the first map `R → L` -/ fst : R → L /-- the second map `R → L` -/ snd : R → L /-- Given a type `ι`, this is the shape of multiequalizer diagrams corresponding to situations where we want to equalize two families of maps `U i ⟶ V ⟨i, j⟩` and `U j ⟶ V ⟨i, j⟩` with `i : ι` and `j : ι`. -/ @[simps] def MulticospanShape.prod (ι : Type w) : MulticospanShape where L := ι R := ι × ι fst := _root_.Prod.fst snd := _root_.Prod.snd /-- The shape of a multicoequalizer diagram. It involves two types `L` and `R`, and two maps `L → R`. -/ @[nolint checkUnivs] structure MultispanShape where /-- the left type -/ L : Type w /-- the right type -/ R : Type w' /-- the first map `L → R` -/ fst : L → R /-- the second map `L → R` -/ snd : L → R /-- Given a type `ι`, this is the shape of multicoequalizer diagrams corresponding to situations where we want to coequalize two families of maps `V ⟨i, j⟩ ⟶ U i` and `V ⟨i, j⟩ ⟶ U j` with `i : ι` and `j : ι`. -/ @[simps] def MultispanShape.prod (ι : Type w) : MultispanShape where L := ι × ι R := ι fst := _root_.Prod.fst snd := _root_.Prod.snd /-- Given a linearly ordered type `ι`, this is the shape of multicoequalizer diagrams corresponding to situations where we want to coequalize two families of maps `V ⟨i, j⟩ ⟶ U i` and `V ⟨i, j⟩ ⟶ U j` with `i < j`. -/ @[simps] def MultispanShape.ofLinearOrder (ι : Type w) [LinearOrder ι] : MultispanShape where L := {x : ι × ι | x.1 < x.2} R := ι fst x := x.1.1 snd x := x.1.2 /-- The type underlying the multiequalizer diagram. -/ inductive WalkingMulticospan (J : MulticospanShape.{w, w'}) : Type max w w' | left : J.L → WalkingMulticospan J | right : J.R → WalkingMulticospan J /-- The type underlying the multicoequalizer diagram. -/ inductive WalkingMultispan (J : MultispanShape.{w, w'}) : Type max w w' | left : J.L → WalkingMultispan J | right : J.R → WalkingMultispan J namespace WalkingMulticospan variable {J : MulticospanShape.{w, w'}} instance [Inhabited J.L] : Inhabited (WalkingMulticospan J) := ⟨left default⟩ -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- Morphisms for `WalkingMulticospan`. -/ inductive Hom : ∀ _ _ : WalkingMulticospan J, Type max w w' | id (A) : Hom A A | fst (b) : Hom (left (J.fst b)) (right b) | snd (b) : Hom (left (J.snd b)) (right b) instance {a : WalkingMulticospan J} : Inhabited (Hom a a) := ⟨Hom.id _⟩ /-- Composition of morphisms for `WalkingMulticospan`. -/ def Hom.comp : ∀ {A B C : WalkingMulticospan J} (_ : Hom A B) (_ : Hom B C), Hom A C | _, _, _, Hom.id X, f => f | _, _, _, Hom.fst b, Hom.id _ => Hom.fst b | _, _, _, Hom.snd b, Hom.id _ => Hom.snd b instance : SmallCategory (WalkingMulticospan J) where Hom := Hom id := Hom.id comp := Hom.comp id_comp := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl comp_id := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl assoc := by rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl @[simp] lemma Hom.id_eq_id (X : WalkingMulticospan J) : Hom.id X = 𝟙 X := rfl @[simp] lemma Hom.comp_eq_comp {X Y Z : WalkingMulticospan J} (f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl end WalkingMulticospan namespace WalkingMultispan variable {J : MultispanShape.{w, w'}} instance [Inhabited J.L] : Inhabited (WalkingMultispan J) := ⟨left default⟩ -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- Morphisms for `WalkingMultispan`. -/ inductive Hom : ∀ _ _ : WalkingMultispan J, Type max w w' | id (A) : Hom A A | fst (a) : Hom (left a) (right (J.fst a)) | snd (a) : Hom (left a) (right (J.snd a)) instance {a : WalkingMultispan J} : Inhabited (Hom a a) := ⟨Hom.id _⟩ /-- Composition of morphisms for `WalkingMultispan`. -/ def Hom.comp : ∀ {A B C : WalkingMultispan J} (_ : Hom A B) (_ : Hom B C), Hom A C | _, _, _, Hom.id X, f => f | _, _, _, Hom.fst a, Hom.id _ => Hom.fst a | _, _, _, Hom.snd a, Hom.id _ => Hom.snd a instance : SmallCategory (WalkingMultispan J) where Hom := Hom id := Hom.id comp := Hom.comp id_comp := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl comp_id := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl assoc := by rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl @[simp] lemma Hom.id_eq_id (X : WalkingMultispan J) : Hom.id X = 𝟙 X := rfl @[simp] lemma Hom.comp_eq_comp {X Y Z : WalkingMultispan J} (f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl variable (J) in /-- The bijection `WalkingMultispan J ≃ J.L ⊕ J.R`. -/ def equiv : WalkingMultispan J ≃ J.L ⊕ J.R where toFun x := match x with | left a => Sum.inl a | right b => Sum.inr b invFun := Sum.elim left right left_inv := by rintro (_ | _) <;> rfl right_inv := by rintro (_ | _) <;> rfl variable (J) in /-- The bijection `Arrow (WalkingMultispan J) ≃ WalkingMultispan J ⊕ J.R ⊕ J.R`. -/ def arrowEquiv : Arrow (WalkingMultispan J) ≃ WalkingMultispan J ⊕ J.L ⊕ J.L where toFun f := match f.hom with | .id x => Sum.inl x | .fst a => Sum.inr (Sum.inl a) | .snd a => Sum.inr (Sum.inr a) invFun := Sum.elim (fun X ↦ Arrow.mk (𝟙 X)) (Sum.elim (fun a ↦ Arrow.mk (Hom.fst a : left _ ⟶ right _)) (fun a ↦ Arrow.mk (Hom.snd a : left _ ⟶ right _))) left_inv := by rintro ⟨_, _, (_ | _ | _)⟩ <;> rfl right_inv := by rintro (_ | _ | _) <;> rfl end WalkingMultispan /-- This is a structure encapsulating the data necessary to define a `Multicospan`. -/ @[nolint checkUnivs] structure MulticospanIndex (J : MulticospanShape.{w, w'}) (C : Type u) [Category.{v} C] where /-- Left map, from `J.L` to `C` -/ left : J.L → C /-- Right map, from `J.R` to `C` -/ right : J.R → C /-- A family of maps from `left (J.fst b)` to `right b` -/ fst : ∀ b, left (J.fst b) ⟶ right b /-- A family of maps from `left (J.snd b)` to `right b` -/ snd : ∀ b, left (J.snd b) ⟶ right b /-- This is a structure encapsulating the data necessary to define a `Multispan`. -/ @[nolint checkUnivs] structure MultispanIndex (J : MultispanShape.{w, w'}) (C : Type u) [Category.{v} C] where /-- Left map, from `J.L` to `C` -/ left : J.L → C /-- Right map, from `J.R` to `C` -/ right : J.R → C /-- A family of maps from `left a` to `right (J.fst a)` -/ fst : ∀ a, left a ⟶ right (J.fst a) /-- A family of maps from `left a` to `right (J.snd a)` -/ snd : ∀ a, left a ⟶ right (J.snd a) namespace MulticospanIndex variable {C : Type u} [Category.{v} C] {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) /-- The multicospan associated to `I : MulticospanIndex`. -/ @[simps] def multicospan : WalkingMulticospan J ⥤ C where obj x := match x with | WalkingMulticospan.left a => I.left a | WalkingMulticospan.right b => I.right b map {x y} f := match x, y, f with | _, _, WalkingMulticospan.Hom.id x => 𝟙 _ | _, _, WalkingMulticospan.Hom.fst b => I.fst _ | _, _, WalkingMulticospan.Hom.snd b => I.snd _ map_id := by rintro (_ | _) <;> rfl map_comp := by rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> cat_disch variable [HasProduct I.left] [HasProduct I.right] /-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.fst`. -/ noncomputable def fstPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right := Pi.lift fun b => Pi.π I.left (J.fst b) ≫ I.fst b /-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.snd`. -/ noncomputable def sndPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right := Pi.lift fun b => Pi.π I.left (J.snd b) ≫ I.snd b @[reassoc (attr := simp)] theorem fstPiMap_π (b) : I.fstPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.fst b := by simp [fstPiMap] @[reassoc (attr := simp)] theorem sndPiMap_π (b) : I.sndPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.snd b := by simp [sndPiMap] /-- Taking the multiequalizer over the multicospan index is equivalent to taking the equalizer over the two morphisms `∏ᶜ I.left ⇉ ∏ᶜ I.right`. This is the diagram of the latter. -/ @[simps!] protected noncomputable def parallelPairDiagram := parallelPair I.fstPiMap I.sndPiMap end MulticospanIndex namespace MultispanIndex variable {C : Type u} [Category.{v} C] {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) /-- The multispan associated to `I : MultispanIndex`. -/ def multispan : WalkingMultispan J ⥤ C where obj x := match x with | WalkingMultispan.left a => I.left a | WalkingMultispan.right b => I.right b map {x y} f := match x, y, f with | _, _, WalkingMultispan.Hom.id x => 𝟙 _ | _, _, WalkingMultispan.Hom.fst b => I.fst _ | _, _, WalkingMultispan.Hom.snd b => I.snd _ map_id := by rintro (_ | _) <;> rfl map_comp := by rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> cat_disch @[simp] theorem multispan_obj_left (a) : I.multispan.obj (WalkingMultispan.left a) = I.left a := rfl @[simp] theorem multispan_obj_right (b) : I.multispan.obj (WalkingMultispan.right b) = I.right b := rfl @[simp] theorem multispan_map_fst (a) : I.multispan.map (WalkingMultispan.Hom.fst a) = I.fst a := rfl @[simp] theorem multispan_map_snd (a) : I.multispan.map (WalkingMultispan.Hom.snd a) = I.snd a := rfl variable [HasCoproduct I.left] [HasCoproduct I.right] /-- The induced map `∐ I.left ⟶ ∐ I.right` via `I.fst`. -/ noncomputable def fstSigmaMap : ∐ I.left ⟶ ∐ I.right := Sigma.desc fun b => I.fst b ≫ Sigma.ι _ (J.fst b) /-- The induced map `∐ I.left ⟶ ∐ I.right` via `I.snd`. -/ noncomputable def sndSigmaMap : ∐ I.left ⟶ ∐ I.right := Sigma.desc fun b => I.snd b ≫ Sigma.ι _ (J.snd b) @[reassoc (attr := simp)] theorem ι_fstSigmaMap (b) : Sigma.ι I.left b ≫ I.fstSigmaMap = I.fst b ≫ Sigma.ι I.right _ := by simp [fstSigmaMap] @[reassoc (attr := simp)] theorem ι_sndSigmaMap (b) : Sigma.ι I.left b ≫ I.sndSigmaMap = I.snd b ≫ Sigma.ι I.right _ := by simp [sndSigmaMap] /-- Taking the multicoequalizer over the multispan index is equivalent to taking the coequalizer over the two morphisms `∐ I.left ⇉ ∐ I.right`. This is the diagram of the latter. -/ protected noncomputable abbrev parallelPairDiagram := parallelPair I.fstSigmaMap I.sndSigmaMap end MultispanIndex variable {C : Type u} [Category.{v} C] /-- A multifork is a cone over a multicospan. -/ abbrev Multifork {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) := Cone I.multicospan /-- A multicofork is a cocone over a multispan. -/ abbrev Multicofork {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) := Cocone I.multispan namespace Multifork variable {J : MulticospanShape.{w, w'}} {I : MulticospanIndex J C} (K : Multifork I) /-- The maps from the cone point of a multifork to the objects on the left. -/ def ι (a : J.L) : K.pt ⟶ I.left a := K.π.app (WalkingMulticospan.left _) @[simp] theorem app_left_eq_ι (a) : K.π.app (WalkingMulticospan.left a) = K.ι a := rfl @[simp] theorem app_right_eq_ι_comp_fst (b) : K.π.app (WalkingMulticospan.right b) = K.ι (J.fst b) ≫ I.fst b := by rw [← K.w (WalkingMulticospan.Hom.fst b)] rfl @[reassoc] theorem app_right_eq_ι_comp_snd (b) : K.π.app (WalkingMulticospan.right b) = K.ι (J.snd b) ≫ I.snd b := by rw [← K.w (WalkingMulticospan.Hom.snd b)] rfl @[reassoc (attr := simp)] theorem hom_comp_ι (K₁ K₂ : Multifork I) (f : K₁ ⟶ K₂) (j : J.L) : f.hom ≫ K₂.ι j = K₁.ι j := f.w _ /-- Construct a multifork using a collection `ι` of morphisms. -/ @[simps] def ofι {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) (P : C) (ι : ∀ a, P ⟶ I.left a) (w : ∀ b, ι (J.fst b) ≫ I.fst b = ι (J.snd b) ≫ I.snd b) : Multifork I where pt := P π := { app := fun x => match x with | WalkingMulticospan.left _ => ι _ | WalkingMulticospan.right b => ι (J.fst b) ≫ I.fst b naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp only [Category.id_comp, Category.comp_id] apply w } @[reassoc (attr := simp)] theorem condition (b) : K.ι (J.fst b) ≫ I.fst b = K.ι (J.snd b) ≫ I.snd b := by rw [← app_right_eq_ι_comp_fst, ← app_right_eq_ι_comp_snd] /-- This definition provides a convenient way to show that a multifork is a limit. -/ @[simps] def IsLimit.mk (lift : ∀ E : Multifork I, E.pt ⟶ K.pt) (fac : ∀ (E : Multifork I) (i : J.L), lift E ≫ K.ι i = E.ι i) (uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ i : J.L, m ≫ K.ι i = E.ι i) → m = lift E) : IsLimit K := { lift fac := by rintro E (a | b) · apply fac · rw [← E.w (WalkingMulticospan.Hom.fst b), ← K.w (WalkingMulticospan.Hom.fst b), ← Category.assoc] congr 1 apply fac uniq := by rintro E m hm apply uniq intro i apply hm } variable {K} lemma IsLimit.hom_ext (hK : IsLimit K) {T : C} {f g : T ⟶ K.pt} (h : ∀ a, f ≫ K.ι a = g ≫ K.ι a) : f = g := by apply hK.hom_ext rintro (_ | b) · apply h · dsimp rw [app_right_eq_ι_comp_fst, reassoc_of% h] /-- Constructor for morphisms to the point of a limit multifork. -/ def IsLimit.lift (hK : IsLimit K) {T : C} (k : ∀ a, T ⟶ I.left a) (hk : ∀ b, k (J.fst b) ≫ I.fst b = k (J.snd b) ≫ I.snd b) : T ⟶ K.pt := hK.lift (Multifork.ofι _ _ k hk) @[reassoc (attr := simp)] lemma IsLimit.fac (hK : IsLimit K) {T : C} (k : ∀ a, T ⟶ I.left a) (hk : ∀ b, k (J.fst b) ≫ I.fst b = k (J.snd b) ≫ I.snd b) (a : J.L) : IsLimit.lift hK k hk ≫ K.ι a = k a := hK.fac _ _ variable (K) variable [HasProduct I.left] [HasProduct I.right] @[reassoc (attr := simp)] theorem pi_condition : Pi.lift K.ι ≫ I.fstPiMap = Pi.lift K.ι ≫ I.sndPiMap := by ext simp /-- Given a multifork, we may obtain a fork over `∏ᶜ I.left ⇉ ∏ᶜ I.right`. -/ @[simps pt] noncomputable def toPiFork (K : Multifork I) : Fork I.fstPiMap I.sndPiMap where pt := K.pt π := { app := fun x => match x with | WalkingParallelPair.zero => Pi.lift K.ι | WalkingParallelPair.one => Pi.lift K.ι ≫ I.fstPiMap naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp only [Category.id_comp, Functor.map_id, parallelPair_obj_zero, Category.comp_id, pi_condition, parallelPair_obj_one] } @[simp] theorem toPiFork_π_app_zero : K.toPiFork.ι = Pi.lift K.ι := rfl @[simp] theorem toPiFork_π_app_one : K.toPiFork.π.app WalkingParallelPair.one = Pi.lift K.ι ≫ I.fstPiMap := rfl variable (I) /-- Given a fork over `∏ᶜ I.left ⇉ ∏ᶜ I.right`, we may obtain a multifork. -/ @[simps pt] noncomputable def ofPiFork (c : Fork I.fstPiMap I.sndPiMap) : Multifork I where pt := c.pt π := { app := fun x => match x with | WalkingMulticospan.left _ => c.ι ≫ Pi.π _ _ | WalkingMulticospan.right _ => c.ι ≫ I.fstPiMap ≫ Pi.π _ _ naturality := by rintro (_ | _) (_ | _) (_ | _ | _) · simp · simp · dsimp; rw [c.condition_assoc]; simp · simp } @[simp] theorem ofPiFork_π_app_left (c : Fork I.fstPiMap I.sndPiMap) (a) : (ofPiFork I c).ι a = c.ι ≫ Pi.π _ _ := rfl @[simp] theorem ofPiFork_π_app_right (c : Fork I.fstPiMap I.sndPiMap) (a) : (ofPiFork I c).π.app (WalkingMulticospan.right a) = c.ι ≫ I.fstPiMap ≫ Pi.π _ _ := rfl end Multifork namespace MulticospanIndex variable {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) [HasProduct I.left] [HasProduct I.right] /-- `Multifork.toPiFork` as a functor. -/ @[simps] noncomputable def toPiForkFunctor : Multifork I ⥤ Fork I.fstPiMap I.sndPiMap where obj := Multifork.toPiFork map {K₁ K₂} f := { hom := f.hom w := by rintro (_ | _) · apply limit.hom_ext simp · apply limit.hom_ext intro j simp only [Multifork.toPiFork_π_app_one, Multifork.pi_condition, Category.assoc] dsimp [sndPiMap] simp } /-- `Multifork.ofPiFork` as a functor. -/ @[simps] noncomputable def ofPiForkFunctor : Fork I.fstPiMap I.sndPiMap ⥤ Multifork I where obj := Multifork.ofPiFork I map {K₁ K₂} f := { hom := f.hom w := by rintro (_ | _) <;> simp } /-- The category of multiforks is equivalent to the category of forks over `∏ᶜ I.left ⇉ ∏ᶜ I.right`. It then follows from `CategoryTheory.IsLimit.ofPreservesConeTerminal` (or `reflects`) that it preserves and reflects limit cones. -/ @[simps] noncomputable def multiforkEquivPiFork : Multifork I ≌ Fork I.fstPiMap I.sndPiMap where functor := toPiForkFunctor I inverse := ofPiForkFunctor I unitIso := NatIso.ofComponents fun K => Cones.ext (Iso.refl _) (by rintro (_ | _) <;> simp) counitIso := NatIso.ofComponents fun K => Fork.ext (Iso.refl _) end MulticospanIndex namespace Multicofork variable {J : MultispanShape.{w, w'}} {I : MultispanIndex J C} (K : Multicofork I) /-- The maps to the cocone point of a multicofork from the objects on the right. -/ def π (b : J.R) : I.right b ⟶ K.pt := K.ι.app (WalkingMultispan.right _) @[simp] theorem π_eq_app_right (b) : K.ι.app (WalkingMultispan.right _) = K.π b := rfl @[simp] theorem fst_app_right (a) : K.ι.app (WalkingMultispan.left a) = I.fst a ≫ K.π _ := by rw [← K.w (WalkingMultispan.Hom.fst a)] rfl @[reassoc] theorem snd_app_right (a) : K.ι.app (WalkingMultispan.left a) = I.snd a ≫ K.π _ := by rw [← K.w (WalkingMultispan.Hom.snd a)] rfl @[reassoc (attr := simp)] lemma π_comp_hom (K₁ K₂ : Multicofork I) (f : K₁ ⟶ K₂) (b : J.R) : K₁.π b ≫ f.hom = K₂.π b := f.w _ /-- Construct a multicofork using a collection `π` of morphisms. -/ @[simps] def ofπ {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) (P : C) (π : ∀ b, I.right b ⟶ P) (w : ∀ a, I.fst a ≫ π (J.fst a) = I.snd a ≫ π (J.snd a)) : Multicofork I where pt := P ι := { app := fun x => match x with | WalkingMultispan.left a => I.fst a ≫ π _ | WalkingMultispan.right _ => π _ naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp only [Functor.map_id, MultispanIndex.multispan_obj_left, Category.id_comp, Category.comp_id, MultispanIndex.multispan_obj_right] symm apply w } @[reassoc (attr := simp)] theorem condition (a) : I.fst a ≫ K.π (J.fst a) = I.snd a ≫ K.π (J.snd a) := by rw [← K.snd_app_right, ← K.fst_app_right] /-- This definition provides a convenient way to show that a multicofork is a colimit. -/ @[simps] def IsColimit.mk (desc : ∀ E : Multicofork I, K.pt ⟶ E.pt) (fac : ∀ (E : Multicofork I) (i : J.R), K.π i ≫ desc E = E.π i) (uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ i : J.R, K.π i ≫ m = E.π i) → m = desc E) : IsColimit K := { desc fac := by rintro S (a | b) · rw [← K.w (WalkingMultispan.Hom.fst a), ← S.w (WalkingMultispan.Hom.fst a), Category.assoc] congr 1 apply fac · apply fac uniq := by intro S m hm apply uniq intro i apply hm } variable {K} lemma IsColimit.hom_ext (hK : IsColimit K) {T : C} {f g : K.pt ⟶ T} (h : ∀ a, K.π a ≫ f = K.π a ≫ g) : f = g := by apply hK.hom_ext rintro (_ | _) <;> simp [h] /-- Constructor for morphisms from the point of a colimit multicofork. -/ def IsColimit.desc (hK : IsColimit K) {T : C} (k : ∀ a, I.right a ⟶ T) (hk : ∀ b, I.fst b ≫ k (J.fst b) = I.snd b ≫ k (J.snd b)) : K.pt ⟶ T := hK.desc (Multicofork.ofπ _ _ k hk) @[reassoc (attr := simp)] lemma IsColimit.fac (hK : IsColimit K) {T : C} (k : ∀ a, I.right a ⟶ T) (hk : ∀ b, I.fst b ≫ k (J.fst b) = I.snd b ≫ k (J.snd b)) (a : J.R) : K.π a ≫ IsColimit.desc hK k hk = k a := hK.fac _ _ variable (K) [HasCoproduct I.left] [HasCoproduct I.right] @[reassoc (attr := simp)] theorem sigma_condition : I.fstSigmaMap ≫ Sigma.desc K.π = I.sndSigmaMap ≫ Sigma.desc K.π := by ext simp /-- Given a multicofork, we may obtain a cofork over `∐ I.left ⇉ ∐ I.right`. -/ @[simps pt] noncomputable def toSigmaCofork (K : Multicofork I) : Cofork I.fstSigmaMap I.sndSigmaMap where pt := K.pt ι := { app := fun x => match x with | WalkingParallelPair.zero => I.fstSigmaMap ≫ Sigma.desc K.π | WalkingParallelPair.one => Sigma.desc K.π naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp only [Functor.map_id, parallelPair_obj_zero, parallelPair_obj_one, sigma_condition, Category.id_comp, Category.comp_id] } @[simp] theorem toSigmaCofork_π : K.toSigmaCofork.π = Sigma.desc K.π := rfl variable (I) /-- Given a cofork over `∐ I.left ⇉ ∐ I.right`, we may obtain a multicofork. -/ @[simps pt] noncomputable def ofSigmaCofork (c : Cofork I.fstSigmaMap I.sndSigmaMap) : Multicofork I where pt := c.pt ι := { app := fun x => match x with | WalkingMultispan.left a => (Sigma.ι I.left a :) ≫ I.fstSigmaMap ≫ c.π | WalkingMultispan.right b => (Sigma.ι I.right b :) ≫ c.π naturality := by rintro (_ | _) (_ | _) (_ | _ | _) · simp · simp · simp [c.condition] · simp } @[simp] theorem ofSigmaCofork_ι_app_left (c : Cofork I.fstSigmaMap I.sndSigmaMap) (a) : (ofSigmaCofork I c).ι.app (WalkingMultispan.left a) = (Sigma.ι I.left a :) ≫ I.fstSigmaMap ≫ c.π := rfl -- LHS simplifies; `(d)simp`-normal form is `ofSigmaCofork_ι_app_right'` theorem ofSigmaCofork_ι_app_right (c : Cofork I.fstSigmaMap I.sndSigmaMap) (b) : (ofSigmaCofork I c).ι.app (WalkingMultispan.right b) = (Sigma.ι I.right b :) ≫ c.π := rfl @[simp] theorem ofSigmaCofork_ι_app_right' (c : Cofork I.fstSigmaMap I.sndSigmaMap) (b) : π (ofSigmaCofork I c) b = (Sigma.ι I.right b :) ≫ c.π := rfl variable {I} in /-- Constructor for isomorphisms between multicoforks. -/ @[simps!] def ext {K K' : Multicofork I} (e : K.pt ≅ K'.pt) (h : ∀ (i : J.R), K.π i ≫ e.hom = K'.π i := by cat_disch) : K ≅ K' := Cocones.ext e (by rintro (i | j) <;> simp [h]) end Multicofork namespace MultispanIndex variable {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) [HasCoproduct I.left] [HasCoproduct I.right] /-- `Multicofork.toSigmaCofork` as a functor. -/ @[simps] noncomputable def toSigmaCoforkFunctor : Multicofork I ⥤ Cofork I.fstSigmaMap I.sndSigmaMap where obj := Multicofork.toSigmaCofork map {K₁ K₂} f := { hom := f.hom w := by rintro (_ | _) all_goals { apply colimit.hom_ext rintro ⟨j⟩ simp } } /-- `Multicofork.ofSigmaCofork` as a functor. -/ @[simps] noncomputable def ofSigmaCoforkFunctor : Cofork I.fstSigmaMap I.sndSigmaMap ⥤ Multicofork I where obj := Multicofork.ofSigmaCofork I map {K₁ K₂} f := { hom := f.hom w := by rintro (_ | _) <;> simp } /-- The category of multicoforks is equivalent to the category of coforks over `∐ I.left ⇉ ∐ I.right`. It then follows from `CategoryTheory.IsColimit.ofPreservesCoconeInitial` (or `reflects`) that it preserves and reflects colimit cocones. -/ @[simps] noncomputable def multicoforkEquivSigmaCofork : Multicofork I ≌ Cofork I.fstSigmaMap I.sndSigmaMap where functor := toSigmaCoforkFunctor I inverse := ofSigmaCoforkFunctor I unitIso := NatIso.ofComponents fun K => Cocones.ext (Iso.refl _) (by rintro (_ | _) <;> simp) counitIso := NatIso.ofComponents fun K => Cofork.ext (Iso.refl _) (by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): in mathlib3 this was just `ext` and I don't know why it's not here apply Limits.colimit.hom_ext rintro ⟨j⟩ simp) end MultispanIndex /-- For `I : MulticospanIndex J C`, we say that it has a multiequalizer if the associated multicospan has a limit. -/ abbrev HasMultiequalizer {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) := HasLimit I.multicospan noncomputable section /-- The multiequalizer of `I : MulticospanIndex J C`. -/ abbrev multiequalizer {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) [HasMultiequalizer I] : C := limit I.multicospan /-- For `I : MultispanIndex J C`, we say that it has a multicoequalizer if the associated multicospan has a limit. -/ abbrev HasMulticoequalizer {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) := HasColimit I.multispan /-- The multicoequalizer of `I : MultispanIndex J C`. -/ abbrev multicoequalizer {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) [HasMulticoequalizer I] : C := colimit I.multispan namespace Multiequalizer variable {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) [HasMultiequalizer I] /-- The canonical map from the multiequalizer to the objects on the left. -/ abbrev ι (a : J.L) : multiequalizer I ⟶ I.left a := limit.π _ (WalkingMulticospan.left a) /-- The multifork associated to the multiequalizer. -/ abbrev multifork : Multifork I := limit.cone _ @[simp] theorem multifork_ι (a) : (Multiequalizer.multifork I).ι a = Multiequalizer.ι I a := rfl @[simp] theorem multifork_π_app_left (a) : (Multiequalizer.multifork I).π.app (WalkingMulticospan.left a) = Multiequalizer.ι I a := rfl @[reassoc] theorem condition (b) : Multiequalizer.ι I (J.fst b) ≫ I.fst b = Multiequalizer.ι I (J.snd b) ≫ I.snd b := Multifork.condition _ _ /-- Construct a morphism to the multiequalizer from its universal property. -/ abbrev lift (W : C) (k : ∀ a, W ⟶ I.left a) (h : ∀ b, k (J.fst b) ≫ I.fst b = k (J.snd b) ≫ I.snd b) : W ⟶ multiequalizer I := limit.lift _ (Multifork.ofι I _ k h) @[reassoc] theorem lift_ι (W : C) (k : ∀ a, W ⟶ I.left a) (h : ∀ b, k (J.fst b) ≫ I.fst b = k (J.snd b) ≫ I.snd b) (a) : Multiequalizer.lift I _ k h ≫ Multiequalizer.ι I a = k _ := limit.lift_π _ _ @[ext] theorem hom_ext {W : C} (i j : W ⟶ multiequalizer I) (h : ∀ a, i ≫ Multiequalizer.ι I a = j ≫ Multiequalizer.ι I a) : i = j := Multifork.IsLimit.hom_ext (limit.isLimit _) h variable [HasProduct I.left] [HasProduct I.right] instance : HasEqualizer I.fstPiMap I.sndPiMap := ⟨⟨⟨_, IsLimit.ofPreservesConeTerminal I.multiforkEquivPiFork.functor (limit.isLimit _)⟩⟩⟩ /-- The multiequalizer is isomorphic to the equalizer of `∏ᶜ I.left ⇉ ∏ᶜ I.right`. -/ def isoEqualizer : multiequalizer I ≅ equalizer I.fstPiMap I.sndPiMap := limit.isoLimitCone ⟨_, IsLimit.ofPreservesConeTerminal I.multiforkEquivPiFork.inverse (limit.isLimit _)⟩ /-- The canonical injection `multiequalizer I ⟶ ∏ᶜ I.left`. -/ def ιPi : multiequalizer I ⟶ ∏ᶜ I.left := (isoEqualizer I).hom ≫ equalizer.ι I.fstPiMap I.sndPiMap @[reassoc (attr := simp)] theorem ιPi_π (a) : ιPi I ≫ Pi.π I.left a = ι I a := by rw [ιPi, Category.assoc, ← Iso.eq_inv_comp, isoEqualizer] simp instance : Mono (ιPi I) := mono_comp _ _ end Multiequalizer namespace Multicoequalizer variable {J : MultispanShape.{w, w'}} (I : MultispanIndex J C) [HasMulticoequalizer I] /-- The canonical map from the multiequalizer to the objects on the left. -/ abbrev π (b : J.R) : I.right b ⟶ multicoequalizer I := colimit.ι I.multispan (WalkingMultispan.right _) /-- The multicofork associated to the multicoequalizer. -/ abbrev multicofork : Multicofork I := colimit.cocone _ @[simp] theorem multicofork_π (b) : (Multicoequalizer.multicofork I).π b = Multicoequalizer.π I b := rfl theorem multicofork_ι_app_right (b) : (Multicoequalizer.multicofork I).ι.app (WalkingMultispan.right b) = Multicoequalizer.π I b := rfl /-- `@[simp]`-normal form of multicofork_ι_app_right. -/ @[simp] theorem multicofork_ι_app_right' (b) : colimit.ι (MultispanIndex.multispan I) (WalkingMultispan.right b) = π I b := rfl @[reassoc] theorem condition (a) : I.fst a ≫ Multicoequalizer.π I (J.fst a) = I.snd a ≫ Multicoequalizer.π I (J.snd a) := Multicofork.condition _ _ /-- Construct a morphism from the multicoequalizer from its universal property. -/ abbrev desc (W : C) (k : ∀ b, I.right b ⟶ W) (h : ∀ a, I.fst a ≫ k (J.fst a) = I.snd a ≫ k (J.snd a)) : multicoequalizer I ⟶ W := colimit.desc _ (Multicofork.ofπ I _ k h) @[reassoc] theorem π_desc (W : C) (k : ∀ b, I.right b ⟶ W) (h : ∀ a, I.fst a ≫ k (J.fst a) = I.snd a ≫ k (J.snd a)) (b) : Multicoequalizer.π I b ≫ Multicoequalizer.desc I _ k h = k _ := colimit.ι_desc _ _ @[ext] theorem hom_ext {W : C} (i j : multicoequalizer I ⟶ W) (h : ∀ b, Multicoequalizer.π I b ≫ i = Multicoequalizer.π I b ≫ j) : i = j := colimit.hom_ext (by rintro (a | b) · simp_rw [← colimit.w I.multispan (WalkingMultispan.Hom.fst a), Category.assoc, h] · apply h) variable [HasCoproduct I.left] [HasCoproduct I.right] instance : HasCoequalizer I.fstSigmaMap I.sndSigmaMap := ⟨⟨⟨_, IsColimit.ofPreservesCoconeInitial I.multicoforkEquivSigmaCofork.functor (colimit.isColimit _)⟩⟩⟩ /-- The multicoequalizer is isomorphic to the coequalizer of `∐ I.left ⇉ ∐ I.right`. -/ def isoCoequalizer : multicoequalizer I ≅ coequalizer I.fstSigmaMap I.sndSigmaMap := colimit.isoColimitCocone ⟨_, IsColimit.ofPreservesCoconeInitial I.multicoforkEquivSigmaCofork.inverse (colimit.isColimit _)⟩ /-- The canonical projection `∐ I.right ⟶ multicoequalizer I`. -/ def sigmaπ : ∐ I.right ⟶ multicoequalizer I := coequalizer.π I.fstSigmaMap I.sndSigmaMap ≫ (isoCoequalizer I).inv @[reassoc (attr := simp)] theorem ι_sigmaπ (b) : Sigma.ι I.right b ≫ sigmaπ I = π I b := by rw [sigmaπ, ← Category.assoc, Iso.comp_inv_eq, isoCoequalizer] simp instance : Epi (sigmaπ I) := epi_comp _ _ end Multicoequalizer end /-- The inclusion functor `WalkingMultispan (.ofLinearOrder ι) ⥤ WalkingMultispan (.prod ι)`. -/ @[simps!] def WalkingMultispan.inclusionOfLinearOrder (ι : Type w) [LinearOrder ι] : WalkingMultispan (.ofLinearOrder ι) ⥤ WalkingMultispan (.prod ι) := MultispanIndex.multispan { left j := .left j.1 right i := .right i fst j := WalkingMultispan.Hom.fst (J := .prod ι) j.1 snd j := WalkingMultispan.Hom.snd (J := .prod ι) j.1 } section symmetry namespace MultispanIndex variable {ι : Type w} (I : MultispanIndex (.prod ι) C) /-- Structure expressing a symmetry of `I : MultispanIndex (.prod ι) C` which allows to compare the corresponding multicoequalizer to the multicoequalizer of `I.toLinearOrder`. -/ structure SymmStruct where /-- the symmetry isomorphism -/ iso (i j : ι) : I.left ⟨i, j⟩ ≅ I.left ⟨j, i⟩ iso_hom_fst (i j : ι) : (iso i j).hom ≫ I.fst ⟨j, i⟩ = I.snd ⟨i, j⟩ iso_hom_snd (i j : ι) : (iso i j).hom ≫ I.snd ⟨j, i⟩ = I.fst ⟨i, j⟩ fst_eq_snd (i : ι) : I.fst ⟨i, i⟩ = I.snd ⟨i, i⟩ attribute [reassoc] SymmStruct.iso_hom_fst SymmStruct.iso_hom_snd variable [LinearOrder ι] /-- The multispan index for `MultispanShape.ofLinearOrder ι` deduced from a multispan index for `MultispanShape.prod ι` when `ι` is linearly ordered. -/ @[simps] def toLinearOrder : MultispanIndex (.ofLinearOrder ι) C where left j := I.left j.1 right i := I.right i fst j := I.fst j.1 snd j := I.snd j.1 /-- Given a linearly ordered type `ι` and `I : MultispanIndex (.prod ι) C`, this is the isomorphism of functors between `WalkingMultispan.inclusionOfLinearOrder ι ⋙ I.multispan` and `I.toLinearOrder.multispan`. -/ @[simps!] def toLinearOrderMultispanIso : WalkingMultispan.inclusionOfLinearOrder ι ⋙ I.multispan ≅ I.toLinearOrder.multispan := NatIso.ofComponents (fun i ↦ match i with | .left _ => Iso.refl _ | .right _ => Iso.refl _) end MultispanIndex namespace Multicofork variable {ι : Type w} [LinearOrder ι] {I : MultispanIndex (.prod ι) C} /-- The multicofork for `I.toLinearOrder` deduced from a multicofork for `I : MultispanIndex (.prod ι) C` when `ι` is linearly ordered. -/ def toLinearOrder (c : Multicofork I) : Multicofork I.toLinearOrder := Multicofork.ofπ _ c.pt c.π (fun _ ↦ c.condition _) /-- The multicofork for `I : MultispanIndex (.prod ι) C` deduced from a multicofork for `I.toLinearOrder` when `ι` is linearly ordered and `I` is symmetric. -/ def ofLinearOrder (c : Multicofork I.toLinearOrder) (h : I.SymmStruct) : Multicofork I := Multicofork.ofπ _ c.pt c.π (by rintro ⟨x, y⟩ obtain hxy | rfl | hxy := lt_trichotomy x y · exact c.condition ⟨⟨x, y⟩, hxy⟩ · simp [h.fst_eq_snd] · have := c.condition ⟨⟨y, x⟩, hxy⟩ dsimp at this ⊢ rw [← h.iso_hom_fst_assoc, ← h.iso_hom_snd_assoc, this]) /-- If `ι` is a linearly ordered type, `I : MultispanIndex (.prod ι) C`, and `c` a colimit multicofork for `I`, then `c.toLinearOrder` is a colimit multicofork for `I.toLinearOrder`. -/ def isColimitToLinearOrder (c : Multicofork I) (hc : IsColimit c) (h : I.SymmStruct) : IsColimit c.toLinearOrder := Multicofork.IsColimit.mk _ (fun s ↦ hc.desc (ofLinearOrder s h)) (fun s _ ↦ hc.fac (ofLinearOrder s h) _) (fun s m hm ↦ Multicofork.IsColimit.hom_ext hc (fun i ↦ by have := hc.fac (ofLinearOrder s h) (.right i) dsimp at this rw [this] apply hm)) end Multicofork end symmetry end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/CombinedProducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # Constructors for combining (co)fans We provide constructors for combining (co)fans and show their (co)limit properties. ## TODO * Combine (co)fans on sigma types -/ universe u₁ u₂ namespace CategoryTheory namespace Limits variable {C : Type u₁} [Category.{u₂} C] namespace Fan variable {ι₁ ι₂ : Type*} {X : C} {f₁ : ι₁ → C} {f₂ : ι₂ → C} (c₁ : Fan f₁) (c₂ : Fan f₂) (bc : BinaryFan c₁.pt c₂.pt) (h₁ : IsLimit c₁) (h₂ : IsLimit c₂) (h : IsLimit bc) /-- For fans on maps `f₁ : ι₁ → C`, `f₂ : ι₂ → C` and a binary fan on their cone points, construct one family of morphisms indexed by `ι₁ ⊕ ι₂` -/ @[simp] abbrev combPairHoms : (i : ι₁ ⊕ ι₂) → bc.pt ⟶ Sum.elim f₁ f₂ i | .inl a => bc.fst ≫ c₁.proj a | .inr a => bc.snd ≫ c₂.proj a variable {c₁ c₂ bc} /-- If `c₁` and `c₂` are limit fans and `bc` is a limit binary fan on their cone points, then the fan constructed from `combPairHoms` is a limit cone. -/ def combPairIsLimit : IsLimit (Fan.mk bc.pt (combPairHoms c₁ c₂ bc)) := mkFanLimit _ (fun s ↦ Fan.IsLimit.desc h <| fun i ↦ by cases i · exact Fan.IsLimit.desc h₁ (fun a ↦ s.proj (.inl a)) · exact Fan.IsLimit.desc h₂ (fun a ↦ s.proj (.inr a))) (fun s w ↦ by cases w <;> · simp only [fan_mk_proj, combPairHoms] erw [← Category.assoc, h.fac] simp only [pair_obj_left, mk_pt, mk_π_app, IsLimit.fac]) (fun s m hm ↦ Fan.IsLimit.hom_ext h _ _ <| fun w ↦ by cases w · refine Fan.IsLimit.hom_ext h₁ _ _ (fun a ↦ by aesop) · refine Fan.IsLimit.hom_ext h₂ _ _ (fun a ↦ by aesop)) end Fan namespace Cofan variable {ι₁ ι₂ : Type*} {X : C} {f₁ : ι₁ → C} {f₂ : ι₂ → C} (c₁ : Cofan f₁) (c₂ : Cofan f₂) (bc : BinaryCofan c₁.pt c₂.pt) (h₁ : IsColimit c₁) (h₂ : IsColimit c₂) (h : IsColimit bc) /-- For cofans on maps `f₁ : ι₁ → C`, `f₂ : ι₂ → C` and a binary cofan on their cocone points, construct one family of morphisms indexed by `ι₁ ⊕ ι₂` -/ @[simp] abbrev combPairHoms : (i : ι₁ ⊕ ι₂) → Sum.elim f₁ f₂ i ⟶ bc.pt | .inl a => c₁.inj a ≫ bc.inl | .inr a => c₂.inj a ≫ bc.inr variable {c₁ c₂ bc} /-- If `c₁` and `c₂` are colimit cofans and `bc` is a colimit binary cofan on their cocone points, then the cofan constructed from `combPairHoms` is a colimit cocone. -/ def combPairIsColimit : IsColimit (Cofan.mk bc.pt (combPairHoms c₁ c₂ bc)) := mkCofanColimit _ (fun s ↦ Cofan.IsColimit.desc h <| fun i ↦ by cases i · exact Cofan.IsColimit.desc h₁ (fun a ↦ s.inj (.inl a)) · exact Cofan.IsColimit.desc h₂ (fun a ↦ s.inj (.inr a))) (fun s w ↦ by cases w <;> · simp only [cofan_mk_inj, combPairHoms, Category.assoc] erw [h.fac] simp only [Cofan.mk_ι_app, Cofan.IsColimit.fac]) (fun s m hm ↦ Cofan.IsColimit.hom_ext h _ _ <| fun w ↦ by cases w · refine Cofan.IsColimit.hom_ext h₁ _ _ (fun a ↦ by aesop) · refine Cofan.IsColimit.hom_ext h₂ _ _ (fun a ↦ by aesop)) end Cofan end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/FiniteProducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Shapes.Products /-! # Categories with finite (co)products Typeclasses representing categories with (co)products over finite indexing types. -/ universe w v u open CategoryTheory namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] /-- A category has finite products if there exists a limit for every diagram with shape `Discrete J`, where we have `[Finite J]`. We require this condition only for `J = Fin n` in the definition, then deduce a version for any `J : Type*` as a corollary of this definition. -/ class HasFiniteProducts : Prop where /-- `C` has finite products -/ out (n : ℕ) : HasLimitsOfShape (Discrete (Fin n)) C /-- If `C` has finite limits then it has finite products. -/ instance (priority := 10) hasFiniteProducts_of_hasFiniteLimits [HasFiniteLimits C] : HasFiniteProducts C := ⟨fun _ => inferInstance⟩ instance hasLimitsOfShape_discrete [HasFiniteProducts C] (ι : Type w) [Finite ι] : HasLimitsOfShape (Discrete ι) C := by rcases Finite.exists_equiv_fin ι with ⟨n, ⟨e⟩⟩ haveI : HasLimitsOfShape (Discrete (Fin n)) C := HasFiniteProducts.out n exact hasLimitsOfShape_of_equivalence (Discrete.equivalence e.symm) /-- We can now write this for powers. -/ noncomputable example [HasFiniteProducts C] (X : C) : C := ∏ᶜ fun _ : Fin 5 => X /-- If a category has all products then in particular it has finite products. -/ theorem hasFiniteProducts_of_hasProducts [HasProducts.{w} C] : HasFiniteProducts C := ⟨fun _ => hasLimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift.{w})⟩ /-- A category has finite coproducts if there exists a colimit for every diagram with shape `Discrete J`, where we have `[Fintype J]`. We require this condition only for `J = Fin n` in the definition, then deduce a version for any `J : Type*` as a corollary of this definition. -/ class HasFiniteCoproducts : Prop where /-- `C` has all finite coproducts -/ out (n : ℕ) : HasColimitsOfShape (Discrete (Fin n)) C instance hasColimitsOfShape_discrete [HasFiniteCoproducts C] (ι : Type w) [Finite ι] : HasColimitsOfShape (Discrete ι) C := by rcases Finite.exists_equiv_fin ι with ⟨n, ⟨e⟩⟩ haveI : HasColimitsOfShape (Discrete (Fin n)) C := HasFiniteCoproducts.out n exact hasColimitsOfShape_of_equivalence (Discrete.equivalence e.symm) /-- If `C` has finite colimits then it has finite coproducts. -/ instance (priority := 10) hasFiniteCoproducts_of_hasFiniteColimits [HasFiniteColimits C] : HasFiniteCoproducts C := ⟨fun J => by infer_instance⟩ /-- If a category has all coproducts then in particular it has finite coproducts. -/ theorem hasFiniteCoproducts_of_hasCoproducts [HasCoproducts.{w} C] : HasFiniteCoproducts C := ⟨fun _ => hasColimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift.{w})⟩ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Equivalence.lean
import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Transporting existence of specific limits across equivalences For now, we only treat the case of initial and terminal objects, but other special shapes can be added in the future. -/ open CategoryTheory CategoryTheory.Limits namespace CategoryTheory universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] theorem hasInitial_of_equivalence (e : D ⥤ C) [e.IsEquivalence] [HasInitial C] : HasInitial D := Adjunction.hasColimitsOfShape_of_equivalence e theorem Equivalence.hasInitial_iff (e : C ≌ D) : HasInitial C ↔ HasInitial D := ⟨fun (_ : HasInitial C) => hasInitial_of_equivalence e.inverse, fun (_ : HasInitial D) => hasInitial_of_equivalence e.functor⟩ theorem hasTerminal_of_equivalence (e : D ⥤ C) [e.IsEquivalence] [HasTerminal C] : HasTerminal D := Adjunction.hasLimitsOfShape_of_equivalence e theorem Equivalence.hasTerminal_iff (e : C ≌ D) : HasTerminal C ↔ HasTerminal D := ⟨fun (_ : HasTerminal C) => hasTerminal_of_equivalence e.inverse, fun (_ : HasTerminal D) => hasTerminal_of_equivalence e.functor⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/WideEqualizers.lean
import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Shapes.Equalizers /-! # Wide equalizers and wide coequalizers This file defines wide (co)equalizers as special cases of (co)limits. A wide equalizer for the family of morphisms `X ⟶ Y` indexed by `J` is the categorical generalization of the subobject `{a ∈ A | ∀ j₁ j₂, f(j₁, a) = f(j₂, a)}`. Note that if `J` has fewer than two morphisms this condition is trivial, so some lemmas and definitions assume `J` is nonempty. ## Main definitions * `WalkingParallelFamily` is the indexing category used for wide (co)equalizer diagrams * `parallelFamily` is a functor from `WalkingParallelFamily` to our category `C`. * a `Trident` is a cone over a parallel family. * there is really only one interesting morphism in a trident: the arrow from the vertex of the trident to the domain of f and g. It is called `Trident.ι`. * a `wideEqualizer` is now just a `limit (parallelFamily f)` Each of these has a dual. ## Main statements * `wideEqualizer.ι_mono` states that every wideEqualizer map is a monomorphism ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ noncomputable section namespace CategoryTheory.Limits open CategoryTheory universe w v u u₂ variable {J : Type w} /-- The type of objects for the diagram indexing a wide (co)equalizer. -/ inductive WalkingParallelFamily (J : Type w) : Type w | zero : WalkingParallelFamily J | one : WalkingParallelFamily J open WalkingParallelFamily instance : DecidableEq (WalkingParallelFamily J) | zero, zero => isTrue rfl | zero, one => isFalse fun t => WalkingParallelFamily.noConfusion t | one, zero => isFalse fun t => WalkingParallelFamily.noConfusion t | one, one => isTrue rfl instance : Inhabited (WalkingParallelFamily J) := ⟨zero⟩ -- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type family of morphisms for the diagram indexing a wide (co)equalizer. -/ inductive WalkingParallelFamily.Hom (J : Type w) : WalkingParallelFamily J → WalkingParallelFamily J → Type w | id : ∀ X : WalkingParallelFamily.{w} J, WalkingParallelFamily.Hom J X X | line : J → WalkingParallelFamily.Hom J zero one deriving DecidableEq /-- Satisfying the inhabited linter -/ instance (J : Type v) : Inhabited (WalkingParallelFamily.Hom J zero zero) where default := Hom.id _ open WalkingParallelFamily.Hom /-- Composition of morphisms in the indexing diagram for wide (co)equalizers. -/ def WalkingParallelFamily.Hom.comp : ∀ {X Y Z : WalkingParallelFamily J} (_ : WalkingParallelFamily.Hom J X Y) (_ : WalkingParallelFamily.Hom J Y Z), WalkingParallelFamily.Hom J X Z | _, _, _, id _, h => h | _, _, _, line j, id one => line j attribute [local aesop safe cases] WalkingParallelFamily.Hom instance WalkingParallelFamily.category : SmallCategory (WalkingParallelFamily J) where Hom := WalkingParallelFamily.Hom J id := WalkingParallelFamily.Hom.id comp := WalkingParallelFamily.Hom.comp @[simp] theorem WalkingParallelFamily.hom_id (X : WalkingParallelFamily J) : WalkingParallelFamily.Hom.id X = 𝟙 X := rfl variable (J) in /-- `Arrow (WalkingParallelFamily J)` identifies to the type obtained by adding two elements to `T`. -/ def WalkingParallelFamily.arrowEquiv : Arrow (WalkingParallelFamily J) ≃ Option (Option J) where toFun f := match f.left, f.right, f.hom with | zero, _, .id _ => none | one, _, .id _ => some none | zero, one, .line t => some (some t) invFun x := match x with | none => Arrow.mk (𝟙 zero) | some none => Arrow.mk (𝟙 one) | some (some t) => Arrow.mk (.line t) left_inv := by rintro ⟨(_ | _), _, (_ | _)⟩ <;> rfl right_inv := by rintro (_ | (_ | _)) <;> rfl variable {C : Type u} [Category.{v} C] variable {X Y : C} (f : J → (X ⟶ Y)) /-- `parallelFamily f` is the diagram in `C` consisting of the given family of morphisms, each with common domain and codomain. -/ def parallelFamily : WalkingParallelFamily J ⥤ C where obj x := WalkingParallelFamily.casesOn x X Y map {x y} h := match x, y, h with | _, _, Hom.id _ => 𝟙 _ | _, _, line j => f j map_comp := by rintro _ _ _ ⟨⟩ ⟨⟩ <;> · cat_disch @[simp] theorem parallelFamily_obj_zero : (parallelFamily f).obj zero = X := rfl @[simp] theorem parallelFamily_obj_one : (parallelFamily f).obj one = Y := rfl @[simp] theorem parallelFamily_map_left {j : J} : (parallelFamily f).map (line j) = f j := rfl /-- Every functor indexing a wide (co)equalizer is naturally isomorphic (actually, equal) to a `parallelFamily` -/ @[simps!] def diagramIsoParallelFamily (F : WalkingParallelFamily J ⥤ C) : F ≅ parallelFamily fun j => F.map (line j) := NatIso.ofComponents (fun j => eqToIso <| by cases j <;> cat_disch) <| by rintro _ _ (_ | _) <;> cat_disch /-- `WalkingParallelPair` as a category is equivalent to a special case of `WalkingParallelFamily`. -/ @[simps!] def walkingParallelFamilyEquivWalkingParallelPair : WalkingParallelFamily.{w} (ULift Bool) ≌ WalkingParallelPair where functor := parallelFamily fun p => cond p.down WalkingParallelPairHom.left WalkingParallelPairHom.right inverse := parallelPair (line (ULift.up true)) (line (ULift.up false)) unitIso := NatIso.ofComponents (fun X => eqToIso (by cases X <;> rfl)) (by rintro _ _ (_ | ⟨_ | _⟩) <;> cat_disch) counitIso := NatIso.ofComponents (fun X => eqToIso (by cases X <;> rfl)) (by rintro _ _ (_ | _ | _) <;> cat_disch) functor_unitIso_comp := by rintro (_ | _) <;> cat_disch /-- A trident on `f` is just a `Cone (parallelFamily f)`. -/ abbrev Trident := Cone (parallelFamily f) /-- A cotrident on `f` and `g` is just a `Cocone (parallelFamily f)`. -/ abbrev Cotrident := Cocone (parallelFamily f) variable {f} /-- A trident `t` on the parallel family `f : J → (X ⟶ Y)` consists of two morphisms `t.π.app zero : t.X ⟶ X` and `t.π.app one : t.X ⟶ Y`. Of these, only the first one is interesting, and we give it the shorter name `Trident.ι t`. -/ abbrev Trident.ι (t : Trident f) := t.π.app zero /-- A cotrident `t` on the parallel family `f : J → (X ⟶ Y)` consists of two morphisms `t.ι.app zero : X ⟶ t.X` and `t.ι.app one : Y ⟶ t.X`. Of these, only the second one is interesting, and we give it the shorter name `Cotrident.π t`. -/ abbrev Cotrident.π (t : Cotrident f) := t.ι.app one @[simp] theorem Trident.ι_eq_app_zero (t : Trident f) : t.ι = t.π.app zero := rfl @[simp] theorem Cotrident.π_eq_app_one (t : Cotrident f) : t.π = t.ι.app one := rfl @[reassoc (attr := simp)] theorem Trident.app_zero (s : Trident f) (j : J) : s.π.app zero ≫ f j = s.π.app one := by rw [← s.w (line j), parallelFamily_map_left] @[reassoc (attr := simp)] theorem Cotrident.app_one (s : Cotrident f) (j : J) : f j ≫ s.ι.app one = s.ι.app zero := by rw [← s.w (line j), parallelFamily_map_left] /-- A trident on `f : J → (X ⟶ Y)` is determined by the morphism `ι : P ⟶ X` satisfying `∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂`. -/ @[simps] def Trident.ofι [Nonempty J] {P : C} (ι : P ⟶ X) (w : ∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂) : Trident f where pt := P π := { app := fun X => WalkingParallelFamily.casesOn X ι (ι ≫ f (Classical.arbitrary J)) naturality := fun i j f => by obtain - | k := f · simp · simp [w (Classical.arbitrary J) k] } /-- A cotrident on `f : J → (X ⟶ Y)` is determined by the morphism `π : Y ⟶ P` satisfying `∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π`. -/ @[simps] def Cotrident.ofπ [Nonempty J] {P : C} (π : Y ⟶ P) (w : ∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π) : Cotrident f where pt := P ι := { app := fun X => WalkingParallelFamily.casesOn X (f (Classical.arbitrary J) ≫ π) π naturality := fun i j f => by obtain - | k := f · simp · simp [w (Classical.arbitrary J) k] } theorem Trident.ι_ofι [Nonempty J] {P : C} (ι : P ⟶ X) (w : ∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂) : (Trident.ofι ι w).ι = ι := rfl theorem Cotrident.π_ofπ [Nonempty J] {P : C} (π : Y ⟶ P) (w : ∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π) : (Cotrident.ofπ π w).π = π := rfl @[reassoc] theorem Trident.condition (j₁ j₂ : J) (t : Trident f) : t.ι ≫ f j₁ = t.ι ≫ f j₂ := by rw [t.app_zero, t.app_zero] @[reassoc] theorem Cotrident.condition (j₁ j₂ : J) (t : Cotrident f) : f j₁ ≫ t.π = f j₂ ≫ t.π := by rw [t.app_one, t.app_one] /-- To check whether two maps are equalized by both maps of a trident, it suffices to check it for the first map -/ theorem Trident.equalizer_ext [Nonempty J] (s : Trident f) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelFamily J, k ≫ s.π.app j = l ≫ s.π.app j | zero => h | one => by rw [← s.app_zero (Classical.arbitrary J), reassoc_of% h] /-- To check whether two maps are coequalized by both maps of a cotrident, it suffices to check it for the second map -/ theorem Cotrident.coequalizer_ext [Nonempty J] (s : Cotrident f) {W : C} {k l : s.pt ⟶ W} (h : s.π ≫ k = s.π ≫ l) : ∀ j : WalkingParallelFamily J, s.ι.app j ≫ k = s.ι.app j ≫ l | zero => by rw [← s.app_one (Classical.arbitrary J), Category.assoc, Category.assoc, h] | one => h theorem Trident.IsLimit.hom_ext [Nonempty J] {s : Trident f} (hs : IsLimit s) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : k = l := hs.hom_ext <| Trident.equalizer_ext _ h theorem Cotrident.IsColimit.hom_ext [Nonempty J] {s : Cotrident f} (hs : IsColimit s) {W : C} {k l : s.pt ⟶ W} (h : s.π ≫ k = s.π ≫ l) : k = l := hs.hom_ext <| Cotrident.coequalizer_ext _ h /-- If `s` is a limit trident over `f`, then a morphism `k : W ⟶ X` satisfying `∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂` induces a morphism `l : W ⟶ s.X` such that `l ≫ Trident.ι s = k`. -/ def Trident.IsLimit.lift' [Nonempty J] {s : Trident f} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : { l : W ⟶ s.pt // l ≫ Trident.ι s = k } := ⟨hs.lift <| Trident.ofι _ h, hs.fac _ _⟩ /-- If `s` is a colimit cotrident over `f`, then a morphism `k : Y ⟶ W` satisfying `∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k` induces a morphism `l : s.X ⟶ W` such that `Cotrident.π s ≫ l = k`. -/ def Cotrident.IsColimit.desc' [Nonempty J] {s : Cotrident f} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : { l : s.pt ⟶ W // Cotrident.π s ≫ l = k } := ⟨hs.desc <| Cotrident.ofπ _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a trident is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def Trident.IsLimit.mk [Nonempty J] (t : Trident f) (lift : ∀ s : Trident f, s.pt ⟶ t.pt) (fac : ∀ s : Trident f, lift s ≫ t.ι = s.ι) (uniq : ∀ (s : Trident f) (m : s.pt ⟶ t.pt) (_ : ∀ j : WalkingParallelFamily J, m ≫ t.π.app j = s.π.app j), m = lift s) : IsLimit t := { lift fac := fun s j => WalkingParallelFamily.casesOn j (fac s) (by rw [← t.w (line (Classical.arbitrary J)), reassoc_of% fac, s.w]) uniq := uniq } /-- This is another convenient method to verify that a trident is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Trident.IsLimit.mk' [Nonempty J] (t : Trident f) (create : ∀ s : Trident f, { l // l ≫ t.ι = s.ι ∧ ∀ {m}, m ≫ t.ι = s.ι → m = l }) : IsLimit t := Trident.IsLimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 (w zero) /-- This is a slightly more convenient method to verify that a cotrident is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def Cotrident.IsColimit.mk [Nonempty J] (t : Cotrident f) (desc : ∀ s : Cotrident f, t.pt ⟶ s.pt) (fac : ∀ s : Cotrident f, t.π ≫ desc s = s.π) (uniq : ∀ (s : Cotrident f) (m : t.pt ⟶ s.pt) (_ : ∀ j : WalkingParallelFamily J, t.ι.app j ≫ m = s.ι.app j), m = desc s) : IsColimit t := { desc fac := fun s j => WalkingParallelFamily.casesOn j (by rw [← t.w_assoc (line (Classical.arbitrary J)), fac, s.w]) (fac s) uniq := uniq } /-- This is another convenient method to verify that a cotrident is a colimit cocone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Cotrident.IsColimit.mk' [Nonempty J] (t : Cotrident f) (create : ∀ s : Cotrident f, { l : t.pt ⟶ s.pt // t.π ≫ l = s.π ∧ ∀ {m}, t.π ≫ m = s.π → m = l }) : IsColimit t := Cotrident.IsColimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 (w one) /-- Given a limit cone for the family `f : J → (X ⟶ Y)`, for any `Z`, morphisms from `Z` to its point are in bijection with morphisms `h : Z ⟶ X` such that `∀ j₁ j₂, h ≫ f j₁ = h ≫ f j₂`. Further, this bijection is natural in `Z`: see `Trident.Limits.homIso_natural`. -/ @[simps] def Trident.IsLimit.homIso [Nonempty J] {t : Trident f} (ht : IsLimit t) (Z : C) : (Z ⟶ t.pt) ≃ { h : Z ⟶ X // ∀ j₁ j₂, h ≫ f j₁ = h ≫ f j₂ } where toFun k := ⟨k ≫ t.ι, by simp⟩ invFun h := (Trident.IsLimit.lift' ht _ h.prop).1 left_inv _ := Trident.IsLimit.hom_ext ht (Trident.IsLimit.lift' _ _ _).prop right_inv _ := Subtype.ext (Trident.IsLimit.lift' ht _ _).prop /-- The bijection of `Trident.IsLimit.homIso` is natural in `Z`. -/ theorem Trident.IsLimit.homIso_natural [Nonempty J] {t : Trident f} (ht : IsLimit t) {Z Z' : C} (q : Z' ⟶ Z) (k : Z ⟶ t.pt) : (Trident.IsLimit.homIso ht _ (q ≫ k) : Z' ⟶ X) = q ≫ (Trident.IsLimit.homIso ht _ k : Z ⟶ X) := Category.assoc _ _ _ /-- Given a colimit cocone for the family `f : J → (X ⟶ Y)`, for any `Z`, morphisms from the cocone point to `Z` are in bijection with morphisms `h : Z ⟶ X` such that `∀ j₁ j₂, f j₁ ≫ h = f j₂ ≫ h`. Further, this bijection is natural in `Z`: see `Cotrident.IsColimit.homIso_natural`. -/ @[simps] def Cotrident.IsColimit.homIso [Nonempty J] {t : Cotrident f} (ht : IsColimit t) (Z : C) : (t.pt ⟶ Z) ≃ { h : Y ⟶ Z // ∀ j₁ j₂, f j₁ ≫ h = f j₂ ≫ h } where toFun k := ⟨t.π ≫ k, by simp⟩ invFun h := (Cotrident.IsColimit.desc' ht _ h.prop).1 left_inv _ := Cotrident.IsColimit.hom_ext ht (Cotrident.IsColimit.desc' _ _ _).prop right_inv _ := Subtype.ext (Cotrident.IsColimit.desc' ht _ _).prop /-- The bijection of `Cotrident.IsColimit.homIso` is natural in `Z`. -/ theorem Cotrident.IsColimit.homIso_natural [Nonempty J] {t : Cotrident f} {Z Z' : C} (q : Z ⟶ Z') (ht : IsColimit t) (k : t.pt ⟶ Z) : (Cotrident.IsColimit.homIso ht _ (k ≫ q) : Y ⟶ Z') = (Cotrident.IsColimit.homIso ht _ k : Y ⟶ Z) ≫ q := (Category.assoc _ _ _).symm /-- This is a helper construction that can be useful when verifying that a category has certain wide equalizers. Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (fun j ↦ F.map (line j))`, and a trident on `fun j ↦ F.map (line j)`, we get a cone on `F`. If you're thinking about using this, have a look at `hasWideEqualizers_of_hasLimit_parallelFamily`, which you may find to be an easier way of achieving your goal. -/ def Cone.ofTrident {F : WalkingParallelFamily J ⥤ C} (t : Trident fun j => F.map (line j)) : Cone F where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by cases X <;> cat_disch) naturality := fun j j' g => by cases g <;> cat_disch } /-- This is a helper construction that can be useful when verifying that a category has all coequalizers. Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (fun j ↦ F.map (line j))`, and a cotrident on `fun j ↦ F.map (line j)` we get a cocone on `F`. If you're thinking about using this, have a look at `hasWideCoequalizers_of_hasColimit_parallelFamily`, which you may find to be an easier way of achieving your goal. -/ def Cocone.ofCotrident {F : WalkingParallelFamily J ⥤ C} (t : Cotrident fun j => F.map (line j)) : Cocone F where pt := t.pt ι := { app := fun X => eqToHom (by cases X <;> cat_disch) ≫ t.ι.app X naturality := fun j j' g => by cases g <;> simp [Cotrident.app_one t] } @[simp] theorem Cone.ofTrident_π {F : WalkingParallelFamily J ⥤ C} (t : Trident fun j => F.map (line j)) (j) : (Cone.ofTrident t).π.app j = t.π.app j ≫ eqToHom (by cases j <;> cat_disch) := rfl @[simp] theorem Cocone.ofCotrident_ι {F : WalkingParallelFamily J ⥤ C} (t : Cotrident fun j => F.map (line j)) (j) : (Cocone.ofCotrident t).ι.app j = eqToHom (by cases j <;> cat_disch) ≫ t.ι.app j := rfl /-- Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (fun j ↦ F.map (line j))` and a cone on `F`, we get a trident on `fun j ↦ F.map (line j)`. -/ def Trident.ofCone {F : WalkingParallelFamily J ⥤ C} (t : Cone F) : Trident fun j => F.map (line j) where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by cases X <;> cat_disch) naturality := by rintro _ _ (_ | _) <;> cat_disch } /-- Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (F.map left) (F.map right)` and a cocone on `F`, we get a cotrident on `fun j ↦ F.map (line j)`. -/ def Cotrident.ofCocone {F : WalkingParallelFamily J ⥤ C} (t : Cocone F) : Cotrident fun j => F.map (line j) where pt := t.pt ι := { app := fun X => eqToHom (by cases X <;> cat_disch) ≫ t.ι.app X naturality := by rintro _ _ (_ | _) <;> cat_disch } @[simp] theorem Trident.ofCone_π {F : WalkingParallelFamily J ⥤ C} (t : Cone F) (j) : (Trident.ofCone t).π.app j = t.π.app j ≫ eqToHom (by cases j <;> cat_disch) := rfl @[simp] theorem Cotrident.ofCocone_ι {F : WalkingParallelFamily J ⥤ C} (t : Cocone F) (j) : (Cotrident.ofCocone t).ι.app j = eqToHom (by cases j <;> cat_disch) ≫ t.ι.app j := rfl /-- Helper function for constructing morphisms between wide equalizer tridents. -/ @[simps] def Trident.mkHom [Nonempty J] {s t : Trident f} (k : s.pt ⟶ t.pt) (w : k ≫ t.ι = s.ι := by cat_disch) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · exact w · simpa using w =≫ f (Classical.arbitrary J) /-- To construct an isomorphism between tridents, it suffices to give an isomorphism between the cone points and check that it commutes with the `ι` morphisms. -/ @[simps] def Trident.ext [Nonempty J] {s t : Trident f} (i : s.pt ≅ t.pt) (w : i.hom ≫ t.ι = s.ι := by cat_disch) : s ≅ t where hom := Trident.mkHom i.hom w inv := Trident.mkHom i.inv (by rw [← w, Iso.inv_hom_id_assoc]) /-- Helper function for constructing morphisms between coequalizer cotridents. -/ @[simps] def Cotrident.mkHom [Nonempty J] {s t : Cotrident f} (k : s.pt ⟶ t.pt) (w : s.π ≫ k = t.π := by cat_disch) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · simpa using f (Classical.arbitrary J) ≫= w · exact w /-- To construct an isomorphism between cotridents, it suffices to give an isomorphism between the cocone points and check that it commutes with the `π` morphisms. -/ def Cotrident.ext [Nonempty J] {s t : Cotrident f} (i : s.pt ≅ t.pt) (w : s.π ≫ i.hom = t.π := by cat_disch) : s ≅ t where hom := Cotrident.mkHom i.hom w inv := Cotrident.mkHom i.inv (by rw [Iso.comp_inv_eq, w]) variable (f) section /-- A family `f` of parallel morphisms has a wide equalizer if the diagram `parallelFamily f` has a limit. -/ abbrev HasWideEqualizer := HasLimit (parallelFamily f) variable [HasWideEqualizer f] /-- If a wide equalizer of `f` exists, we can access an arbitrary choice of such by saying `wideEqualizer f`. -/ abbrev wideEqualizer : C := limit (parallelFamily f) /-- If a wide equalizer of `f` exists, we can access the inclusion `wideEqualizer f ⟶ X` by saying `wideEqualizer.ι f`. -/ abbrev wideEqualizer.ι : wideEqualizer f ⟶ X := limit.π (parallelFamily f) zero /-- A wide equalizer cone for a parallel family `f`. -/ abbrev wideEqualizer.trident : Trident f := limit.cone (parallelFamily f) theorem wideEqualizer.trident_ι : (wideEqualizer.trident f).ι = wideEqualizer.ι f := rfl theorem wideEqualizer.trident_π_app_zero : (wideEqualizer.trident f).π.app zero = wideEqualizer.ι f := rfl @[reassoc] theorem wideEqualizer.condition (j₁ j₂ : J) : wideEqualizer.ι f ≫ f j₁ = wideEqualizer.ι f ≫ f j₂ := Trident.condition j₁ j₂ <| limit.cone <| parallelFamily f /-- The wideEqualizer built from `wideEqualizer.ι f` is limiting. -/ def wideEqualizerIsWideEqualizer [Nonempty J] : IsLimit (Trident.ofι (wideEqualizer.ι f) (wideEqualizer.condition f)) := IsLimit.ofIsoLimit (limit.isLimit _) (Trident.ext (Iso.refl _)) variable {f} /-- A morphism `k : W ⟶ X` satisfying `∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂` factors through the wide equalizer of `f` via `wideEqualizer.lift : W ⟶ wideEqualizer f`. -/ abbrev wideEqualizer.lift [Nonempty J] {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : W ⟶ wideEqualizer f := limit.lift (parallelFamily f) (Trident.ofι k h) @[reassoc] theorem wideEqualizer.lift_ι [Nonempty J] {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : wideEqualizer.lift k h ≫ wideEqualizer.ι f = k := by simp /-- A morphism `k : W ⟶ X` satisfying `∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂` induces a morphism `l : W ⟶ wideEqualizer f` satisfying `l ≫ wideEqualizer.ι f = k`. -/ def wideEqualizer.lift' [Nonempty J] {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : { l : W ⟶ wideEqualizer f // l ≫ wideEqualizer.ι f = k } := ⟨wideEqualizer.lift k h, wideEqualizer.lift_ι _ _⟩ /-- Two maps into a wide equalizer are equal if they are equal when composed with the wide equalizer map. -/ @[ext] theorem wideEqualizer.hom_ext [Nonempty J] {W : C} {k l : W ⟶ wideEqualizer f} (h : k ≫ wideEqualizer.ι f = l ≫ wideEqualizer.ι f) : k = l := Trident.IsLimit.hom_ext (limit.isLimit _) h /-- A wide equalizer morphism is a monomorphism -/ instance wideEqualizer.ι_mono [Nonempty J] : Mono (wideEqualizer.ι f) where right_cancellation _ _ w := wideEqualizer.hom_ext w end section variable {f} /-- The wide equalizer morphism in any limit cone is a monomorphism. -/ theorem mono_of_isLimit_parallelFamily [Nonempty J] {c : Cone (parallelFamily f)} (i : IsLimit c) : Mono (Trident.ι c) where right_cancellation _ _ w := Trident.IsLimit.hom_ext i w end section /-- A family `f` of parallel morphisms has a wide coequalizer if the diagram `parallelFamily f` has a colimit. -/ abbrev HasWideCoequalizer := HasColimit (parallelFamily f) variable [HasWideCoequalizer f] /-- If a wide coequalizer of `f` exists, we can access an arbitrary choice of such by saying `wideCoequalizer f`. -/ abbrev wideCoequalizer : C := colimit (parallelFamily f) /-- If a wideCoequalizer of `f` exists, we can access the corresponding projection by saying `wideCoequalizer.π f`. -/ abbrev wideCoequalizer.π : Y ⟶ wideCoequalizer f := colimit.ι (parallelFamily f) one /-- An arbitrary choice of coequalizer cocone for a parallel family `f`. -/ abbrev wideCoequalizer.cotrident : Cotrident f := colimit.cocone (parallelFamily f) theorem wideCoequalizer.cotrident_π : (wideCoequalizer.cotrident f).π = wideCoequalizer.π f := rfl theorem wideCoequalizer.cotrident_ι_app_one : (wideCoequalizer.cotrident f).ι.app one = wideCoequalizer.π f := rfl @[reassoc] theorem wideCoequalizer.condition (j₁ j₂ : J) : f j₁ ≫ wideCoequalizer.π f = f j₂ ≫ wideCoequalizer.π f := Cotrident.condition j₁ j₂ <| colimit.cocone <| parallelFamily f /-- The cotrident built from `wideCoequalizer.π f` is colimiting. -/ def wideCoequalizerIsWideCoequalizer [Nonempty J] : IsColimit (Cotrident.ofπ (wideCoequalizer.π f) (wideCoequalizer.condition f)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cotrident.ext (Iso.refl _)) variable {f} /-- Any morphism `k : Y ⟶ W` satisfying `∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k` factors through the wide coequalizer of `f` via `wideCoequalizer.desc : wideCoequalizer f ⟶ W`. -/ abbrev wideCoequalizer.desc [Nonempty J] {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : wideCoequalizer f ⟶ W := colimit.desc (parallelFamily f) (Cotrident.ofπ k h) @[reassoc] theorem wideCoequalizer.π_desc [Nonempty J] {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : wideCoequalizer.π f ≫ wideCoequalizer.desc k h = k := by simp /-- Any morphism `k : Y ⟶ W` satisfying `∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k` induces a morphism `l : wideCoequalizer f ⟶ W` satisfying `wideCoequalizer.π ≫ g = l`. -/ def wideCoequalizer.desc' [Nonempty J] {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : { l : wideCoequalizer f ⟶ W // wideCoequalizer.π f ≫ l = k } := ⟨wideCoequalizer.desc k h, wideCoequalizer.π_desc _ _⟩ /-- Two maps from a wide coequalizer are equal if they are equal when composed with the wide coequalizer map -/ @[ext] theorem wideCoequalizer.hom_ext [Nonempty J] {W : C} {k l : wideCoequalizer f ⟶ W} (h : wideCoequalizer.π f ≫ k = wideCoequalizer.π f ≫ l) : k = l := Cotrident.IsColimit.hom_ext (colimit.isColimit _) h /-- A wide coequalizer morphism is an epimorphism -/ instance wideCoequalizer.π_epi [Nonempty J] : Epi (wideCoequalizer.π f) where left_cancellation _ _ w := wideCoequalizer.hom_ext w end section variable {f} /-- The wide coequalizer morphism in any colimit cocone is an epimorphism. -/ theorem epi_of_isColimit_parallelFamily [Nonempty J] {c : Cocone (parallelFamily f)} (i : IsColimit c) : Epi (c.ι.app one) where left_cancellation _ _ w := Cotrident.IsColimit.hom_ext i w end variable (C) /-- A category `HasWideEqualizers` if it has all limits of shape `WalkingParallelFamily J`, i.e. if it has a wide equalizer for every family of parallel morphisms. -/ abbrev HasWideEqualizers := ∀ J, HasLimitsOfShape (WalkingParallelFamily.{w} J) C /-- A category `HasWideCoequalizers` if it has all colimits of shape `WalkingParallelFamily J`, i.e. if it has a wide coequalizer for every family of parallel morphisms. -/ abbrev HasWideCoequalizers := ∀ J, HasColimitsOfShape (WalkingParallelFamily.{w} J) C /-- If `C` has all limits of diagrams `parallelFamily f`, then it has all wide equalizers -/ theorem hasWideEqualizers_of_hasLimit_parallelFamily [∀ {J : Type w} {X Y : C} {f : J → (X ⟶ Y)}, HasLimit (parallelFamily f)] : HasWideEqualizers.{w} C := fun _ => { has_limit := fun F => hasLimit_of_iso (diagramIsoParallelFamily F).symm } /-- If `C` has all colimits of diagrams `parallelFamily f`, then it has all wide coequalizers -/ theorem hasWideCoequalizers_of_hasColimit_parallelFamily [∀ {J : Type w} {X Y : C} {f : J → (X ⟶ Y)}, HasColimit (parallelFamily f)] : HasWideCoequalizers.{w} C := fun _ => { has_colimit := fun F => hasColimit_of_iso (diagramIsoParallelFamily F) } instance (priority := 10) hasEqualizers_of_hasWideEqualizers [HasWideEqualizers.{w} C] : HasEqualizers C := hasLimitsOfShape_of_equivalence.{w} walkingParallelFamilyEquivWalkingParallelPair instance (priority := 10) hasCoequalizers_of_hasWideCoequalizers [HasWideCoequalizers.{w} C] : HasCoequalizers C := hasColimitsOfShape_of_equivalence.{w} walkingParallelFamilyEquivWalkingParallelPair end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Images.lean
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.MorphismProperty.Factorization /-! # Categorical images We define the categorical image of `f` as a factorisation `f = e ≫ m` through a monomorphism `m`, so that `m` factors through the `m'` in any other such factorisation. ## Main definitions * A `MonoFactorisation` is a factorisation `f = e ≫ m`, where `m` is a monomorphism * `IsImage F` means that a given mono factorisation `F` has the universal property of the image. * `HasImage f` means that there is some image factorization for the morphism `f : X ⟶ Y`. * In this case, `image f` is some image object (selected with choice), `image.ι f : image f ⟶ Y` is the monomorphism `m` of the factorisation and `factorThruImage f : X ⟶ image f` is the morphism `e`. * `HasImages C` means that every morphism in `C` has an image. * Let `f : X ⟶ Y` and `g : P ⟶ Q` be morphisms in `C`, which we will represent as objects of the arrow category `Arrow C`. Then `sq : f ⟶ g` is a commutative square in `C`. If `f` and `g` have images, then `HasImageMap sq` represents the fact that there is a morphism `i : image f ⟶ image g` making the diagram X ----→ image f ----→ Y | | | | | | ↓ ↓ ↓ P ----→ image g ----→ Q commute, where the top row is the image factorisation of `f`, the bottom row is the image factorisation of `g`, and the outer rectangle is the commutative square `sq`. * If a category `HasImages`, then `HasImageMaps` means that every commutative square admits an image map. * If a category `HasImages`, then `HasStrongEpiImages` means that the morphism to the image is always a strong epimorphism. ## Main statements * When `C` has equalizers, the morphism `e` appearing in an image factorisation is an epimorphism. * When `C` has strong epi images, then these images admit image maps. ## Future work * TODO: coimages, and abelian categories. * TODO: connect this with existing working in the group theory and ring theory libraries. -/ noncomputable section universe v u open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {X Y : C} (f : X ⟶ Y) /-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/ structure MonoFactorisation (f : X ⟶ Y) where I : C m : I ⟶ Y [m_mono : Mono m] e : X ⟶ I fac : e ≫ m = f := by cat_disch attribute [inherit_doc MonoFactorisation] MonoFactorisation.I MonoFactorisation.m MonoFactorisation.m_mono MonoFactorisation.e MonoFactorisation.fac attribute [reassoc (attr := simp)] MonoFactorisation.fac attribute [instance] MonoFactorisation.m_mono namespace MonoFactorisation /-- The obvious factorisation of a monomorphism through itself. -/ def self [Mono f] : MonoFactorisation f where I := X m := f e := 𝟙 X -- I'm not sure we really need this, but the linter says that an inhabited instance -- ought to exist... instance [Mono f] : Inhabited (MonoFactorisation f) := ⟨self f⟩ variable {f} /-- The morphism `m` in a factorisation `f = e ≫ m` through a monomorphism is uniquely determined. -/ @[ext (iff := false)] theorem ext {F F' : MonoFactorisation f} (hI : F.I = F'.I) (hm : F.m = eqToHom hI ≫ F'.m) : F = F' := by obtain ⟨_, Fm, _, Ffac⟩ := F; obtain ⟨_, Fm', _, Ffac'⟩ := F' cases hI replace hm : Fm = Fm' := by simpa using hm congr apply (cancel_mono Fm).1 rw [Ffac, hm, Ffac'] /-- Any mono factorisation of `f` gives a mono factorisation of `f ≫ g` when `g` is a mono. -/ @[simps] def compMono (F : MonoFactorisation f) {Y' : C} (g : Y ⟶ Y') [Mono g] : MonoFactorisation (f ≫ g) where I := F.I m := F.m ≫ g m_mono := mono_comp _ _ e := F.e /-- A mono factorisation of `f ≫ g`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofCompIso {Y' : C} {g : Y ⟶ Y'} [IsIso g] (F : MonoFactorisation (f ≫ g)) : MonoFactorisation f where I := F.I m := F.m ≫ inv g m_mono := mono_comp _ _ e := F.e /-- Any mono factorisation of `f` gives a mono factorisation of `g ≫ f`. -/ @[simps] def isoComp (F : MonoFactorisation f) {X' : C} (g : X' ⟶ X) : MonoFactorisation (g ≫ f) where I := F.I m := F.m e := g ≫ F.e /-- A mono factorisation of `g ≫ f`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofIsoComp {X' : C} (g : X' ⟶ X) [IsIso g] (F : MonoFactorisation (g ≫ f)) : MonoFactorisation f where I := F.I m := F.m e := inv g ≫ F.e /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` gives a mono factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : MonoFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : MonoFactorisation g.hom where I := F.I m := F.m ≫ sq.right e := inv sq.left ≫ F.e m_mono := mono_comp _ _ fac := by simp only [fac_assoc, Arrow.w, IsIso.inv_comp_eq, Category.assoc] /-- Given a mono factorisation `X ⟶ I ⟶ Y` of an arrow `f`, an isomorphism `I ≅ I'` gives a new mono factorisation `X ⟶ I' ⟶ Y` of `f`. -/ @[simps] def ofIsoI (F : MonoFactorisation f) {I'} (e : F.I ≅ I') : MonoFactorisation f where I := I' m := e.inv ≫ F.m e := F.e ≫ e.hom /-- Copying a mono factorisation to another mono factorisation with propositionally equal `m` and `e` fields. -/ @[simps] def copy (F : MonoFactorisation f) (m : F.I ⟶ Y) (e : X ⟶ F.I) (hm : m = F.m := by cat_disch) (he : e = F.e := by cat_disch) : MonoFactorisation f where I := F.I m := m e := e m_mono := by rw [hm]; infer_instance end MonoFactorisation variable {f} /-- Data exhibiting that a given factorisation through a mono is initial. -/ structure IsImage (F : MonoFactorisation f) where lift : ∀ F' : MonoFactorisation f, F.I ⟶ F'.I lift_fac : ∀ F' : MonoFactorisation f, lift F' ≫ F'.m = F.m := by cat_disch attribute [inherit_doc IsImage] IsImage.lift IsImage.lift_fac attribute [reassoc (attr := simp)] IsImage.lift_fac namespace IsImage @[reassoc (attr := simp)] theorem fac_lift {F : MonoFactorisation f} (hF : IsImage F) (F' : MonoFactorisation f) : F.e ≫ hF.lift F' = F'.e := (cancel_mono F'.m).1 <| by simp variable (f) /-- The trivial factorisation of a monomorphism satisfies the universal property. -/ @[simps] def self [Mono f] : IsImage (MonoFactorisation.self f) where lift F' := F'.e instance [Mono f] : Inhabited (IsImage (MonoFactorisation.self f)) := ⟨self f⟩ variable {f} -- TODO this is another good candidate for a future `UniqueUpToCanonicalIso`. /-- Two factorisations through monomorphisms satisfying the universal property must factor through isomorphic objects. -/ @[simps] def isoExt {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') : F.I ≅ F'.I where hom := hF.lift F' inv := hF'.lift F hom_inv_id := (cancel_mono F.m).1 (by simp) inv_hom_id := (cancel_mono F'.m).1 (by simp) variable {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') theorem isoExt_hom_m : (isoExt hF hF').hom ≫ F'.m = F.m := by simp theorem isoExt_inv_m : (isoExt hF hF').inv ≫ F.m = F'.m := by simp theorem e_isoExt_hom : F.e ≫ (isoExt hF hF').hom = F'.e := by simp theorem e_isoExt_inv : F'.e ≫ (isoExt hF hF').inv = F.e := by simp /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` that is an image gives a mono factorisation of `g` that is an image -/ @[simps] def ofArrowIso {f g : Arrow C} {F : MonoFactorisation f.hom} (hF : IsImage F) (sq : f ⟶ g) [IsIso sq] : IsImage (F.ofArrowIso sq) where lift F' := hF.lift (F'.ofArrowIso (inv sq)) lift_fac F' := by simpa only [MonoFactorisation.ofArrowIso_m, Arrow.inv_right, ← Category.assoc, IsIso.comp_inv_eq] using hF.lift_fac (F'.ofArrowIso (inv sq)) /-- Given a mono factorisation `X ⟶ I ⟶ Y` of an arrow `f` that is an image and an isomorphism `I ≅ I'`, the induced mono factorisation by the isomorphism is also an image. -/ @[simps] def ofIsoI {F : MonoFactorisation f} (hF : IsImage F) {I' : C} (e : F.I ≅ I') : IsImage (F.ofIsoI e) where lift F' := e.inv ≫ hF.lift F' /-- Copying a mono factorisation to another mono factorisation with propositionally equal fields preserves the property of being an image. This is useful when one needs precise control of the `m` and `e` fields. -/ @[simps] def copy {F : MonoFactorisation f} (hF : IsImage F) (m : F.I ⟶ Y) (e : X ⟶ F.I) (hm : m = F.m := by cat_disch) (he : e = F.e := by cat_disch) : IsImage (F.copy m e) where lift := hF.lift end IsImage variable (f) /-- Data exhibiting that a morphism `f` has an image. -/ structure ImageFactorisation (f : X ⟶ Y) where F : MonoFactorisation f isImage : IsImage F attribute [inherit_doc ImageFactorisation] ImageFactorisation.F ImageFactorisation.isImage namespace ImageFactorisation instance [Mono f] : Inhabited (ImageFactorisation f) := ⟨⟨_, IsImage.self f⟩⟩ /-- If `f` and `g` are isomorphic arrows, then an image factorisation of `f` gives an image factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : ImageFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : ImageFactorisation g.hom where F := F.F.ofArrowIso sq isImage := F.isImage.ofArrowIso sq /-- Given an image factorisation `X ⟶ I ⟶ Y` of an arrow `f`, an isomorphism `I ≅ I'` induces a new image factorisation `X ⟶ I' ⟶ Y` of `f`. -/ @[simps] def ofIsoI {f : X ⟶ Y} (F : ImageFactorisation f) {I' : C} (e : F.F.I ≅ I') : ImageFactorisation f where F := F.F.ofIsoI e isImage := F.isImage.ofIsoI e /-- Copying an image factorisation to another image factorisation with propositionally equal `m` and `e` fields. -/ @[simps] def copy {f : X ⟶ Y} (F : ImageFactorisation f) (m : F.F.I ⟶ Y) (e : X ⟶ F.F.I) (hm : m = F.F.m := by cat_disch) (he : e = F.F.e := by cat_disch) : ImageFactorisation f where F := F.F.copy m e isImage := F.isImage.copy m e end ImageFactorisation /-- `HasImage f` means that there exists an image factorisation of `f`. -/ class HasImage (f : X ⟶ Y) : Prop where mk' :: exists_image : Nonempty (ImageFactorisation f) attribute [inherit_doc HasImage] HasImage.exists_image theorem HasImage.mk {f : X ⟶ Y} (F : ImageFactorisation f) : HasImage f := ⟨Nonempty.intro F⟩ theorem HasImage.of_arrow_iso {f g : Arrow C} [h : HasImage f.hom] (sq : f ⟶ g) [IsIso sq] : HasImage g.hom := ⟨⟨h.exists_image.some.ofArrowIso sq⟩⟩ instance (priority := 100) mono_hasImage (f : X ⟶ Y) [Mono f] : HasImage f := HasImage.mk ⟨_, IsImage.self f⟩ section variable [HasImage f] /-- Some image factorisation of `f` through a monomorphism (selected with choice). -/ def Image.imageFactorisation : ImageFactorisation f := Classical.choice HasImage.exists_image /-- Some factorisation of `f` through a monomorphism (selected with choice). -/ def Image.monoFactorisation : MonoFactorisation f := (Image.imageFactorisation f).F /-- The witness of the universal property for the chosen factorisation of `f` through a monomorphism. -/ def Image.isImage : IsImage (Image.monoFactorisation f) := (Image.imageFactorisation f).isImage /-- The categorical image of a morphism. -/ def image : C := (Image.monoFactorisation f).I /-- The inclusion of the image of a morphism into the target. -/ def image.ι : image f ⟶ Y := (Image.monoFactorisation f).m @[simp] theorem image.as_ι : (Image.monoFactorisation f).m = image.ι f := rfl instance : Mono (image.ι f) := (Image.monoFactorisation f).m_mono /-- The map from the source to the image of a morphism. -/ def factorThruImage : X ⟶ image f := (Image.monoFactorisation f).e /-- Rewrite in terms of the `factorThruImage` interface. -/ @[simp] theorem as_factorThruImage : (Image.monoFactorisation f).e = factorThruImage f := rfl @[reassoc (attr := simp)] theorem image.fac : factorThruImage f ≫ image.ι f = f := (Image.monoFactorisation f).fac variable {f} /-- Any other factorisation of the morphism `f` through a monomorphism receives a map from the image. -/ def image.lift (F' : MonoFactorisation f) : image f ⟶ F'.I := (Image.isImage f).lift F' @[reassoc (attr := simp)] theorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' ≫ F'.m = image.ι f := (Image.isImage f).lift_fac F' @[reassoc (attr := simp)] theorem image.fac_lift (F' : MonoFactorisation f) : factorThruImage f ≫ image.lift F' = F'.e := (Image.isImage f).fac_lift F' @[simp] theorem image.isImage_lift (F : MonoFactorisation f) : (Image.isImage f).lift F = image.lift F := rfl @[reassoc (attr := simp)] theorem IsImage.lift_ι {F : MonoFactorisation f} (hF : IsImage F) : hF.lift (Image.monoFactorisation f) ≫ image.ι f = F.m := hF.lift_fac _ @[reassoc (attr := simp)] theorem image.lift_mk_factorThruImage : image.lift { I := image f, m := ι f, e := factorThruImage f } ≫ image.ι f = image.ι f := (Image.isImage f).lift_fac _ @[reassoc (attr := simp)] theorem image.lift_mk_comp {C : Type u} [Category.{v} C] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasImage g] [HasImage (f ≫ g)] (h : Y ⟶ image g) (H : (f ≫ h) ≫ image.ι g = f ≫ g) : image.lift { I := image g, m := ι g, e := (f ≫ h) } ≫ image.ι g = image.ι (f ≫ g) := image.lift_fac _ -- TODO we could put a category structure on `MonoFactorisation f`, -- with the morphisms being `g : I ⟶ I'` commuting with the `m`s -- (they then automatically commute with the `e`s) -- and show that an `imageOf f` gives an initial object there -- (uniqueness of the lift comes for free). instance image.lift_mono (F' : MonoFactorisation f) : Mono (image.lift F') := by refine @mono_of_mono _ _ _ _ _ _ F'.m ?_ simpa using MonoFactorisation.m_mono _ theorem HasImage.uniq (F' : MonoFactorisation f) (l : image f ⟶ F'.I) (w : l ≫ F'.m = image.ι f) : l = image.lift F' := (cancel_mono F'.m).1 (by simp [w]) /-- If `has_image g`, then `has_image (f ≫ g)` when `f` is an isomorphism. -/ instance {X Y Z : C} (f : X ⟶ Y) [IsIso f] (g : Y ⟶ Z) [HasImage g] : HasImage (f ≫ g) where exists_image := ⟨{ F := { I := image g m := image.ι g e := f ≫ factorThruImage g } isImage := { lift := fun F' => image.lift { I := F'.I m := F'.m e := inv f ≫ F'.e } } }⟩ end section variable (C) /-- `HasImages` asserts that every morphism has an image. -/ class HasImages : Prop where has_image : ∀ {X Y : C} (f : X ⟶ Y), HasImage f attribute [inherit_doc HasImages] HasImages.has_image attribute [instance 100] HasImages.has_image end section /-- The image of a monomorphism is isomorphic to the source. -/ def imageMonoIsoSource [Mono f] : image f ≅ X := IsImage.isoExt (Image.isImage f) (IsImage.self f) @[reassoc (attr := simp)] theorem imageMonoIsoSource_inv_ι [Mono f] : (imageMonoIsoSource f).inv ≫ image.ι f = f := by simp [imageMonoIsoSource] @[reassoc (attr := simp)] theorem imageMonoIsoSource_hom_self [Mono f] : (imageMonoIsoSource f).hom ≫ f = image.ι f := by simp only [← imageMonoIsoSource_inv_ι f] rw [← Category.assoc, Iso.hom_inv_id, Category.id_comp] -- This is the proof that `factorThruImage f` is an epimorphism -- from https://en.wikipedia.org/wiki/Image_%28category_theory%29, which is in turn taken from: -- Mitchell, Barry (1965), Theory of categories, MR 0202787, p.12, Proposition 10.1 @[ext (iff := false)] theorem image.ext [HasImage f] {W : C} {g h : image f ⟶ W} [HasLimit (parallelPair g h)] (w : factorThruImage f ≫ g = factorThruImage f ≫ h) : g = h := by let q := equalizer.ι g h let e' := equalizer.lift _ w let F' : MonoFactorisation f := { I := equalizer g h m := q ≫ image.ι f m_mono := mono_comp _ _ e := e' } let v := image.lift F' have t₀ : v ≫ q ≫ image.ι f = image.ι f := image.lift_fac F' have t : v ≫ q = 𝟙 (image f) := (cancel_mono_id (image.ι f)).1 (by convert t₀ using 1 rw [Category.assoc]) -- The proof from wikipedia next proves `q ≫ v = 𝟙 _`, -- and concludes that `equalizer g h ≅ image f`, -- but this isn't necessary. calc g = 𝟙 (image f) ≫ g := by rw [Category.id_comp] _ = v ≫ q ≫ g := by rw [← t, Category.assoc] _ = v ≫ q ≫ h := by rw [equalizer.condition g h] _ = 𝟙 (image f) ≫ h := by rw [← Category.assoc, t] _ = h := by rw [Category.id_comp] instance [HasImage f] [∀ {Z : C} (g h : image f ⟶ Z), HasLimit (parallelPair g h)] : Epi (factorThruImage f) := ⟨fun _ _ w => image.ext f w⟩ theorem epi_image_of_epi {X Y : C} (f : X ⟶ Y) [HasImage f] [E : Epi f] : Epi (image.ι f) := by rw [← image.fac f] at E exact epi_of_epi (factorThruImage f) (image.ι f) theorem epi_of_epi_image {X Y : C} (f : X ⟶ Y) [HasImage f] [Epi (image.ι f)] [Epi (factorThruImage f)] : Epi f := by rw [← image.fac f] apply epi_comp end section variable {f} variable {f' : X ⟶ Y} [HasImage f] [HasImage f'] /-- An equation between morphisms gives a comparison map between the images (which momentarily we prove is an iso). -/ def image.eqToHom (h : f = f') : image f ⟶ image f' := image.lift { I := image f' m := image.ι f' e := factorThruImage f' fac := by rw [h]; simp only [image.fac]} instance (h : f = f') : IsIso (image.eqToHom h) := ⟨⟨image.eqToHom h.symm, ⟨(cancel_mono (image.ι f)).1 (by subst h simp [image.eqToHom, Category.assoc, Category.id_comp]), (cancel_mono (image.ι f')).1 (by subst h simp [image.eqToHom])⟩⟩⟩ /-- An equation between morphisms gives an isomorphism between the images. -/ def image.eqToIso (h : f = f') : image f ≅ image f' := asIso (image.eqToHom h) /-- As long as the category has equalizers, the image inclusion maps commute with `image.eqToIso`. -/ theorem image.eq_fac [HasEqualizers C] (h : f = f') : image.ι f = (image.eqToIso h).hom ≫ image.ι f' := by apply image.ext subst h simp [asIso, image.eqToIso, image.eqToHom] end section variable {Z : C} (g : Y ⟶ Z) /-- The comparison map `image (f ≫ g) ⟶ image g`. -/ def image.preComp [HasImage g] [HasImage (f ≫ g)] : image (f ≫ g) ⟶ image g := image.lift { I := image g m := image.ι g e := f ≫ factorThruImage g } @[reassoc (attr := simp)] theorem image.preComp_ι [HasImage g] [HasImage (f ≫ g)] : image.preComp f g ≫ image.ι g = image.ι (f ≫ g) := by simp [image.preComp] @[reassoc (attr := simp)] theorem image.factorThruImage_preComp [HasImage g] [HasImage (f ≫ g)] : factorThruImage (f ≫ g) ≫ image.preComp f g = f ≫ factorThruImage g := by simp [image.preComp] /-- `image.preComp f g` is a monomorphism. -/ instance image.preComp_mono [HasImage g] [HasImage (f ≫ g)] : Mono (image.preComp f g) := by refine @mono_of_mono _ _ _ _ _ _ (image.ι g) ?_ simp only [image.preComp_ι] infer_instance /-- The two step comparison map `image (f ≫ (g ≫ h)) ⟶ image (g ≫ h) ⟶ image h` agrees with the one step comparison map `image (f ≫ (g ≫ h)) ≅ image ((f ≫ g) ≫ h) ⟶ image h`. -/ theorem image.preComp_comp {W : C} (h : Z ⟶ W) [HasImage (g ≫ h)] [HasImage (f ≫ g ≫ h)] [HasImage h] [HasImage ((f ≫ g) ≫ h)] : image.preComp f (g ≫ h) ≫ image.preComp g h = image.eqToHom (Category.assoc f g h).symm ≫ image.preComp (f ≫ g) h := by apply (cancel_mono (image.ι h)).1 simp only [preComp, Category.assoc, fac, lift_mk_comp, eqToHom] rw [image.lift_fac] variable [HasEqualizers C] /-- `image.preComp f g` is an epimorphism when `f` is an epimorphism (we need `C` to have equalizers to prove this). -/ instance image.preComp_epi_of_epi [HasImage g] [HasImage (f ≫ g)] [Epi f] : Epi (image.preComp f g) := by apply @epi_of_epi_fac _ _ _ _ _ _ _ _ ?_ (image.factorThruImage_preComp _ _) exact epi_comp _ _ instance hasImage_iso_comp [IsIso f] [HasImage g] : HasImage (f ≫ g) := HasImage.mk { F := (Image.monoFactorisation g).isoComp f isImage := { lift := fun F' => image.lift (F'.ofIsoComp f) lift_fac := fun F' => by dsimp have : (MonoFactorisation.ofIsoComp f F').m = F'.m := rfl rw [← this,image.lift_fac (MonoFactorisation.ofIsoComp f F')] } } /-- `image.preComp f g` is an isomorphism when `f` is an isomorphism (we need `C` to have equalizers to prove this). -/ instance image.isIso_precomp_iso (f : X ⟶ Y) [IsIso f] [HasImage g] : IsIso (image.preComp f g) := ⟨⟨image.lift { I := image (f ≫ g) m := image.ι (f ≫ g) e := inv f ≫ factorThruImage (f ≫ g) }, ⟨by ext simp [image.preComp], by ext simp [image.preComp]⟩⟩⟩ -- Note that in general we don't have the other comparison map you might expect -- `image f ⟶ image (f ≫ g)`. instance hasImage_comp_iso [HasImage f] [IsIso g] : HasImage (f ≫ g) := HasImage.mk { F := (Image.monoFactorisation f).compMono g isImage := { lift := fun F' => image.lift F'.ofCompIso lift_fac := fun F' => by rw [← Category.comp_id (image.lift (MonoFactorisation.ofCompIso F') ≫ F'.m), ← IsIso.inv_hom_id g,← Category.assoc] refine congrArg (· ≫ g) ?_ have : (image.lift (MonoFactorisation.ofCompIso F') ≫ F'.m) ≫ inv g = image.lift (MonoFactorisation.ofCompIso F') ≫ ((MonoFactorisation.ofCompIso F').m) := by simp only [MonoFactorisation.ofCompIso_I, Category.assoc, MonoFactorisation.ofCompIso_m] rw [this, image.lift_fac (MonoFactorisation.ofCompIso F'),image.as_ι] }} /-- Postcomposing by an isomorphism induces an isomorphism on the image. -/ def image.compIso [HasImage f] [IsIso g] : image f ≅ image (f ≫ g) where hom := image.lift (Image.monoFactorisation (f ≫ g)).ofCompIso inv := image.lift ((Image.monoFactorisation f).compMono g) @[reassoc (attr := simp)] theorem image.compIso_hom_comp_image_ι [HasImage f] [IsIso g] : (image.compIso f g).hom ≫ image.ι (f ≫ g) = image.ι f ≫ g := by ext simp [image.compIso] @[reassoc (attr := simp)] theorem image.compIso_inv_comp_image_ι [HasImage f] [IsIso g] : (image.compIso f g).inv ≫ image.ι f = image.ι (f ≫ g) ≫ inv g := by ext simp [image.compIso] end end CategoryTheory.Limits namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] section instance {X Y : C} (f : X ⟶ Y) [HasImage f] : HasImage (Arrow.mk f).hom := show HasImage f by infer_instance end section HasImageMap -- Don't generate unnecessary injectivity lemmas which the `simpNF` linter will complain about. set_option genInjectivity false in /-- An image map is a morphism `image f → image g` fitting into a commutative square and satisfying the obvious commutativity conditions. -/ structure ImageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) where map : image f.hom ⟶ image g.hom map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by aesop attribute [inherit_doc ImageMap] ImageMap.map ImageMap.map_ι instance inhabitedImageMap {f : Arrow C} [HasImage f.hom] : Inhabited (ImageMap (𝟙 f)) := ⟨⟨𝟙 _, by simp⟩⟩ attribute [reassoc (attr := simp)] ImageMap.map_ι @[reassoc (attr := simp)] theorem ImageMap.factor_map {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (m : ImageMap sq) : factorThruImage f.hom ≫ m.map = sq.left ≫ factorThruImage g.hom := (cancel_mono (image.ι g.hom)).1 <| by simp /-- To give an image map for a commutative square with `f` at the top and `g` at the bottom, it suffices to give a map between any mono factorisation of `f` and any image factorisation of `g`. -/ def ImageMap.transport {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (F : MonoFactorisation f.hom) {F' : MonoFactorisation g.hom} (hF' : IsImage F') {map : F.I ⟶ F'.I} (map_ι : map ≫ F'.m = F.m ≫ sq.right) : ImageMap sq where map := image.lift F ≫ map ≫ hF'.lift (Image.monoFactorisation g.hom) map_ι := by simp [map_ι] /-- `HasImageMap sq` means that there is an `ImageMap` for the square `sq`. -/ class HasImageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) : Prop where mk' :: has_image_map : Nonempty (ImageMap sq) attribute [inherit_doc HasImageMap] HasImageMap.has_image_map theorem HasImageMap.mk {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (m : ImageMap sq) : HasImageMap sq := ⟨Nonempty.intro m⟩ theorem HasImageMap.transport {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (F : MonoFactorisation f.hom) {F' : MonoFactorisation g.hom} (hF' : IsImage F') (map : F.I ⟶ F'.I) (map_ι : map ≫ F'.m = F.m ≫ sq.right) : HasImageMap sq := HasImageMap.mk <| ImageMap.transport sq F hF' map_ι /-- Obtain an `ImageMap` from a `HasImageMap` instance. -/ def HasImageMap.imageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) [HasImageMap sq] : ImageMap sq := Classical.choice <| @HasImageMap.has_image_map _ _ _ _ _ _ sq _ -- see Note [lower instance priority] instance (priority := 100) hasImageMapOfIsIso {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) [IsIso sq] : HasImageMap sq := HasImageMap.mk { map := image.lift ((Image.monoFactorisation g.hom).ofArrowIso (inv sq)) map_ι := by erw [← cancel_mono (inv sq).right, Category.assoc, ← MonoFactorisation.ofArrowIso_m, image.lift_fac, Category.assoc, ← Comma.comp_right, IsIso.hom_inv_id, Comma.id_right, Category.comp_id] } instance HasImageMap.comp {f g h : Arrow C} [HasImage f.hom] [HasImage g.hom] [HasImage h.hom] (sq1 : f ⟶ g) (sq2 : g ⟶ h) [HasImageMap sq1] [HasImageMap sq2] : HasImageMap (sq1 ≫ sq2) := HasImageMap.mk { map := (HasImageMap.imageMap sq1).map ≫ (HasImageMap.imageMap sq2).map map_ι := by rw [Category.assoc,ImageMap.map_ι, ImageMap.map_ι_assoc, Comma.comp_right] } variable {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) section attribute [local ext] ImageMap theorem ImageMap.map_uniq_aux {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (map : image f.hom ⟶ image g.hom) (map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by cat_disch) (map' : image f.hom ⟶ image g.hom) (map_ι' : map' ≫ image.ι g.hom = image.ι f.hom ≫ sq.right) : (map = map') := by have : map ≫ image.ι g.hom = map' ≫ image.ι g.hom := by rw [map_ι, map_ι'] apply (cancel_mono (image.ι g.hom)).1 this theorem ImageMap.map_uniq {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (F G : ImageMap sq) : F.map = G.map := by apply ImageMap.map_uniq_aux _ F.map_ι _ G.map_ι /-- `@[simp]`-normal form of `ImageMap.mk.injEq`. -/ @[simp] theorem ImageMap.mk.injEq' {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (map : image f.hom ⟶ image g.hom) (map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by cat_disch) (map' : image f.hom ⟶ image g.hom) (map_ι' : map' ≫ image.ι g.hom = image.ι f.hom ≫ sq.right) : (map = map') = True := by simp only [Functor.id_obj, eq_iff_iff, iff_true] apply ImageMap.map_uniq_aux _ map_ι _ map_ι' instance : Subsingleton (ImageMap sq) := Subsingleton.intro fun a b => ImageMap.ext <| ImageMap.map_uniq a b end variable [HasImageMap sq] /-- The map on images induced by a commutative square. -/ abbrev image.map : image f.hom ⟶ image g.hom := (HasImageMap.imageMap sq).map theorem image.factor_map : factorThruImage f.hom ≫ image.map sq = sq.left ≫ factorThruImage g.hom := by simp theorem image.map_ι : image.map sq ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by simp theorem image.map_homMk'_ι {X Y P Q : C} {k : X ⟶ Y} [HasImage k] {l : P ⟶ Q} [HasImage l] {m : X ⟶ P} {n : Y ⟶ Q} (w : m ≫ l = k ≫ n) [HasImageMap (Arrow.homMk' _ _ w)] : image.map (Arrow.homMk' _ _ w) ≫ image.ι l = image.ι k ≫ n := image.map_ι _ section variable {h : Arrow C} [HasImage h.hom] (sq' : g ⟶ h) variable [HasImageMap sq'] /-- Image maps for composable commutative squares induce an image map in the composite square. -/ def imageMapComp : ImageMap (sq ≫ sq') where map := image.map sq ≫ image.map sq' @[simp] theorem image.map_comp [HasImageMap (sq ≫ sq')] : image.map (sq ≫ sq') = image.map sq ≫ image.map sq' := show (HasImageMap.imageMap (sq ≫ sq')).map = (imageMapComp sq sq').map by congr; simp only [eq_iff_true_of_subsingleton] end section variable (f) /-- The identity `image f ⟶ image f` fits into the commutative square represented by the identity morphism `𝟙 f` in the arrow category. -/ def imageMapId : ImageMap (𝟙 f) where map := 𝟙 (image f.hom) @[simp] theorem image.map_id [HasImageMap (𝟙 f)] : image.map (𝟙 f) = 𝟙 (image f.hom) := show (HasImageMap.imageMap (𝟙 f)).map = (imageMapId f).map by congr; simp only [eq_iff_true_of_subsingleton] end end HasImageMap section variable (C) [HasImages C] /-- If a category `has_image_maps`, then all commutative squares induce morphisms on images. -/ class HasImageMaps : Prop where has_image_map : ∀ {f g : Arrow C} (st : f ⟶ g), HasImageMap st attribute [instance 100] HasImageMaps.has_image_map end section HasImageMaps variable [HasImages C] [HasImageMaps C] /-- The functor from the arrow category of `C` to `C` itself that maps a morphism to its image and a commutative square to the induced morphism on images. -/ @[simps] def im : Arrow C ⥤ C where obj f := image f.hom map st := image.map st end HasImageMaps section StrongEpiMonoFactorisation /-- A strong epi-mono factorisation is a decomposition `f = e ≫ m` with `e` a strong epimorphism and `m` a monomorphism. -/ structure StrongEpiMonoFactorisation {X Y : C} (f : X ⟶ Y) extends MonoFactorisation f where [e_strong_epi : StrongEpi e] attribute [inherit_doc StrongEpiMonoFactorisation] StrongEpiMonoFactorisation.e_strong_epi attribute [instance] StrongEpiMonoFactorisation.e_strong_epi /-- Satisfying the inhabited linter -/ instance strongEpiMonoFactorisationInhabited {X Y : C} (f : X ⟶ Y) [StrongEpi f] : Inhabited (StrongEpiMonoFactorisation f) := ⟨⟨⟨Y, 𝟙 Y, f, by simp⟩⟩⟩ /-- A mono factorisation coming from a strong epi-mono factorisation always has the universal property of the image. -/ def StrongEpiMonoFactorisation.toMonoIsImage {X Y : C} {f : X ⟶ Y} (F : StrongEpiMonoFactorisation f) : IsImage F.toMonoFactorisation where lift G := (CommSq.mk (show G.e ≫ G.m = F.e ≫ F.m by rw [F.toMonoFactorisation.fac, G.fac])).lift variable (C) /-- A category has strong epi-mono factorisations if every morphism admits a strong epi-mono factorisation. -/ class HasStrongEpiMonoFactorisations : Prop where mk' :: has_fac : ∀ {X Y : C} (f : X ⟶ Y), Nonempty (StrongEpiMonoFactorisation f) attribute [inherit_doc HasStrongEpiMonoFactorisations] HasStrongEpiMonoFactorisations.has_fac variable {C} theorem HasStrongEpiMonoFactorisations.mk (d : ∀ {X Y : C} (f : X ⟶ Y), StrongEpiMonoFactorisation f) : HasStrongEpiMonoFactorisations C := ⟨fun f => Nonempty.intro <| d f⟩ instance (priority := 100) hasImages_of_hasStrongEpiMonoFactorisations [HasStrongEpiMonoFactorisations C] : HasImages C where has_image f := let F' := Classical.choice (HasStrongEpiMonoFactorisations.has_fac f) HasImage.mk { F := F'.toMonoFactorisation isImage := F'.toMonoIsImage } end StrongEpiMonoFactorisation section HasStrongEpiImages variable (C) [HasImages C] /-- A category has strong epi images if it has all images and `factorThruImage f` is a strong epimorphism for all `f`. -/ class HasStrongEpiImages : Prop where strong_factorThruImage : ∀ {X Y : C} (f : X ⟶ Y), StrongEpi (factorThruImage f) attribute [instance] HasStrongEpiImages.strong_factorThruImage end HasStrongEpiImages section HasStrongEpiImages /-- If there is a single strong epi-mono factorisation of `f`, then every image factorisation is a strong epi-mono factorisation. -/ theorem strongEpi_of_strongEpiMonoFactorisation {X Y : C} {f : X ⟶ Y} (F : StrongEpiMonoFactorisation f) {F' : MonoFactorisation f} (hF' : IsImage F') : StrongEpi F'.e := by rw [← IsImage.e_isoExt_hom F.toMonoIsImage hF'] apply strongEpi_comp theorem strongEpi_factorThruImage_of_strongEpiMonoFactorisation {X Y : C} {f : X ⟶ Y} [HasImage f] (F : StrongEpiMonoFactorisation f) : StrongEpi (factorThruImage f) := strongEpi_of_strongEpiMonoFactorisation F <| Image.isImage f /-- If we constructed our images from strong epi-mono factorisations, then these images are strong epi images. -/ instance (priority := 100) hasStrongEpiImages_of_hasStrongEpiMonoFactorisations [HasStrongEpiMonoFactorisations C] : HasStrongEpiImages C where strong_factorThruImage f := strongEpi_factorThruImage_of_strongEpiMonoFactorisation <| Classical.choice <| HasStrongEpiMonoFactorisations.has_fac f end HasStrongEpiImages section HasStrongEpiImages variable [HasImages C] /-- A category with strong epi images has image maps. -/ instance (priority := 100) hasImageMapsOfHasStrongEpiImages [HasStrongEpiImages C] : HasImageMaps C where has_image_map {f} {g} st := HasImageMap.mk { map := (CommSq.mk (show (st.left ≫ factorThruImage g.hom) ≫ image.ι g.hom = factorThruImage f.hom ≫ image.ι f.hom ≫ st.right by simp)).lift } /-- If a category has images, equalizers and pullbacks, then images are automatically strong epi images. -/ instance (priority := 100) hasStrongEpiImages_of_hasPullbacks_of_hasEqualizers [HasPullbacks C] [HasEqualizers C] : HasStrongEpiImages C where strong_factorThruImage f := StrongEpi.mk' fun {A} {B} h h_mono x y sq => CommSq.HasLift.mk' { l := image.lift { I := pullback h y m := pullback.snd h y ≫ image.ι f m_mono := mono_comp _ _ e := pullback.lift _ _ sq.w } ≫ pullback.fst h y fac_left := by simp only [image.fac_lift_assoc, pullback.lift_fst] fac_right := by apply image.ext simp only [sq.w, Category.assoc, image.fac_lift_assoc, pullback.lift_fst_assoc] } end HasStrongEpiImages variable [HasStrongEpiMonoFactorisations C] variable {X Y : C} {f : X ⟶ Y} /-- If `C` has strong epi mono factorisations, then the image is unique up to isomorphism, in that if `f` factors as a strong epi followed by a mono, this factorisation is essentially the image factorisation. -/ def image.isoStrongEpiMono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : I' ≅ image f := let F : StrongEpiMonoFactorisation f := { I := I', m := m, e := e} IsImage.isoExt F.toMonoIsImage <| Image.isImage f @[simp] theorem image.isoStrongEpiMono_hom_comp_ι {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : (image.isoStrongEpiMono e m comm).hom ≫ image.ι f = m := by dsimp [isoStrongEpiMono] apply IsImage.lift_fac @[simp] theorem image.isoStrongEpiMono_inv_comp_mono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : (image.isoStrongEpiMono e m comm).inv ≫ m = image.ι f := image.lift_fac _ open MorphismProperty variable (C) /-- A category with strong epi mono factorisations admits functorial epi/mono factorizations. -/ noncomputable def functorialEpiMonoFactorizationData : FunctorialFactorizationData (epimorphisms C) (monomorphisms C) where Z := im i := { app := fun f => factorThruImage f.hom } p := { app := fun f => image.ι f.hom } hi _ := epimorphisms.infer_property _ hp _ := monomorphisms.infer_property _ end CategoryTheory.Limits namespace CategoryTheory.Functor open CategoryTheory.Limits variable {C D : Type*} [Category C] [Category D] theorem hasStrongEpiMonoFactorisations_imp_of_isEquivalence (F : C ⥤ D) [IsEquivalence F] [h : HasStrongEpiMonoFactorisations C] : HasStrongEpiMonoFactorisations D := ⟨fun {X} {Y} f => by let em : StrongEpiMonoFactorisation (F.inv.map f) := (HasStrongEpiMonoFactorisations.has_fac (F.inv.map f)).some haveI : Mono (F.map em.m ≫ F.asEquivalence.counitIso.hom.app Y) := mono_comp _ _ haveI : StrongEpi (F.asEquivalence.counitIso.inv.app X ≫ F.map em.e) := strongEpi_comp _ _ exact Nonempty.intro { I := F.obj em.I e := F.asEquivalence.counitIso.inv.app X ≫ F.map em.e m := F.map em.m ≫ F.asEquivalence.counitIso.hom.app Y fac := by simp only [asEquivalence_functor, Category.assoc, ← F.map_comp_assoc, MonoFactorisation.fac, fun_inv_map, id_obj, Iso.inv_hom_id_app, Category.comp_id, Iso.inv_hom_id_app_assoc] }⟩ end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean
import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Binary (co)products We define a category `WalkingPair`, which is the index category for a binary (co)product diagram. A convenience method `pair X Y` constructs the functor from the walking pair, hitting the given objects. We define `prod X Y` and `coprod X Y` as limits and colimits of such functors. Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence of (co)limits shaped as walking pairs. We include lemmas for simplifying equations involving projections and coprojections, and define braiding and associating isomorphisms, and the product comparison morphism. ## References * [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R) * [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN) -/ universe v v₁ u u₁ u₂ open CategoryTheory namespace CategoryTheory.Limits /-- The type of objects for the diagram indexing a binary (co)product. -/ inductive WalkingPair : Type | left | right deriving DecidableEq, Inhabited open WalkingPair /-- The equivalence swapping left and right. -/ def WalkingPair.swap : WalkingPair ≃ WalkingPair where toFun | left => right | right => left invFun | left => right | right => left left_inv j := by cases j <;> rfl right_inv j := by cases j <;> rfl @[simp] theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right := rfl @[simp] theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left := rfl @[simp] theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right := rfl @[simp] theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left := rfl /-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits. -/ def WalkingPair.equivBool : WalkingPair ≃ Bool where toFun | left => true | right => false -- to match equiv.sum_equiv_sigma_bool invFun b := Bool.recOn b right left left_inv j := by cases j <;> rfl right_inv b := by cases b <;> rfl @[simp] theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true := rfl @[simp] theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right := rfl variable {C : Type u} /-- The function on the walking pair, sending the two points to `X` and `Y`. -/ def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y @[simp] theorem pairFunction_left (X Y : C) : pairFunction X Y left = X := rfl @[simp] theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y := rfl variable [Category.{v} C] /-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/ def pair (X Y : C) : Discrete WalkingPair ⥤ C := Discrete.functor fun j => WalkingPair.casesOn j X Y @[simp] theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X := rfl @[simp] theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y := rfl section variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- The natural transformation between two functors out of the walking pair, specified by its components. -/ def mapPair : F ⟶ G where app | ⟨left⟩ => f | ⟨right⟩ => g naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by cat_disch @[simp] theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f := rfl @[simp] theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g := rfl /-- The natural isomorphism between two functors out of the walking pair, specified by its components. -/ @[simps!] def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G := NatIso.ofComponents (fun j ↦ match j with | ⟨left⟩ => f | ⟨right⟩ => g) (fun ⟨⟨u⟩⟩ => by cat_disch) end /-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/ @[simps!] def diagramIsoPair (F : Discrete WalkingPair ⥤ C) : F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) := mapPairIso (Iso.refl _) (Iso.refl _) section variable {D : Type u₁} [Category.{v₁} D] /-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/ def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) := diagramIsoPair _ end /-- A binary fan is just a cone on a diagram indexing a product. -/ abbrev BinaryFan (X Y : C) := Cone (pair X Y) /-- The first projection of a binary fan. -/ abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.left⟩ /-- The second projection of a binary fan. -/ abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.right⟩ -- Marking this `@[simp]` causes loops since `s.fst` is reducibly defeq to the LHS. theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst := rfl -- Marking this `@[simp]` causes loops since `s.snd` is reducibly defeq to the LHS. theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd := rfl /-- Constructs an isomorphism of `BinaryFan`s out of an isomorphism of the tips that commutes with the projections. -/ def BinaryFan.ext {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt) (h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : c ≅ c' := Cones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption) @[simp] lemma BinaryFan.ext_hom_hom {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt) (h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : (ext e h₁ h₂).hom.hom = e.hom := rfl /-- A convenient way to show that a binary fan is a limit. -/ def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y) (lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt) (hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f) (hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g) (uniq : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g), m = lift f g) : IsLimit s := Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t)) (by rintro t (rfl | rfl) · exact hl₁ _ _ · exact hl₂ _ _) fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt} (h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ /-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/ abbrev BinaryCofan (X Y : C) := Cocone (pair X Y) /-- The first inclusion of a binary cofan. -/ abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩ /-- The second inclusion of a binary cofan. -/ abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩ /-- Constructs an isomorphism of `BinaryCofan`s out of an isomorphism of the tips that commutes with the injections. -/ def BinaryCofan.ext {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt) (h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : c ≅ c' := Cocones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption) @[simp] lemma BinaryCofan.ext_hom_hom {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt) (h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : (ext e h₁ h₂).hom.hom = e.hom := rfl -- This cannot be `@[simp]` because `s.inl` is reducibly defeq to the LHS. theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl -- This cannot be `@[simp]` because `s.inr` is reducibly defeq to the LHS. theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl /-- A convenient way to show that a binary cofan is a colimit. -/ def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y) (desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T) (hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f) (hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g) (uniq : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g), m = desc f g) : IsColimit s := Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t)) (by rintro t (rfl | rfl) · exact hd₁ _ _ · exact hd₂ _ _) fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) {f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ variable {X Y : C} section attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- TODO: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/ @[simps pt] def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where pt := P π := { app := fun | { as := j } => match j with | left => π₁ | right => π₂ } /-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/ @[simps pt] def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where pt := P ι := { app := fun | { as := j } => match j with | left => ι₁ | right => ι₂ } end @[simp] theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ := rfl @[simp] theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ := rfl @[simp] theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ := rfl @[simp] theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ := rfl /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd := Cones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr := Cocones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp /-- This is a more convenient formulation to show that a `BinaryFan` constructed using `BinaryFan.mk` is a limit cone. -/ def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W) (fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst) (fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd) (uniq : ∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (BinaryFan.mk fst snd) := { lift := lift fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- This is a more convenient formulation to show that a `BinaryCofan` constructed using `BinaryCofan.mk` is a colimit cocone. -/ def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W} (desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt) (fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl) (fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr) (uniq : ∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (BinaryCofan.mk inl inr) := { desc := desc fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`. -/ @[simps] def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } := ⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩ /-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`. -/ @[simps] def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W) (g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } := ⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩ /-- Binary products are symmetric. -/ def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) : IsLimit (BinaryFan.mk c.snd c.fst) := BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryFan.IsLimit.hom_ext hc (e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm) theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.fst := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X) exact ⟨⟨l, BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _) (h.hom_ext _ _), hl⟩⟩ · intro exact ⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩ theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.snd := by refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst)) exact ⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h => ⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩ /-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/ noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by fapply BinaryFan.isLimitMk · exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd) · simp · simp · intro s m e₁ e₂ apply BinaryFan.IsLimit.hom_ext h · simpa · simpa /-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/ noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) := BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h) /-- Binary coproducts are symmetric. -/ def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) : IsColimit (BinaryCofan.mk c.inr c.inl) := BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryCofan.IsColimit.hom_ext hc (e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm) theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inl := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X) refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩ rw [Category.comp_id] have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (· ≫ inl c) hl rwa [Category.assoc, Category.id_comp] at e · intro exact ⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f) (fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => (IsIso.eq_inv_comp _).mpr e⟩ theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inr := by refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl)) exact ⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h => ⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩ /-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/ noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by fapply BinaryCofan.isColimitMk · exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr) · simp · simp · intro s m e₁ e₂ apply BinaryCofan.IsColimit.hom_ext h · rw [← cancel_epi f] simpa using e₁ · simpa /-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/ noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) := BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h) /-- An abbreviation for `HasLimit (pair X Y)`. -/ abbrev HasBinaryProduct (X Y : C) := HasLimit (pair X Y) /-- An abbreviation for `HasColimit (pair X Y)`. -/ abbrev HasBinaryCoproduct (X Y : C) := HasColimit (pair X Y) /-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or `X ⨯ Y`. -/ noncomputable abbrev prod (X Y : C) [HasBinaryProduct X Y] := limit (pair X Y) /-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or `X ⨿ Y`. -/ noncomputable abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] := colimit (pair X Y) /-- Notation for the product -/ notation:20 X " ⨯ " Y:20 => prod X Y /-- Notation for the coproduct -/ notation:20 X " ⨿ " Y:20 => coprod X Y /-- The projection map to the first component of the product. -/ noncomputable abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X := limit.π (pair X Y) ⟨WalkingPair.left⟩ /-- The projection map to the second component of the product. -/ noncomputable abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y := limit.π (pair X Y) ⟨WalkingPair.right⟩ /-- The inclusion map from the first component of the coproduct. -/ noncomputable abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.left⟩ /-- The inclusion map from the second component of the coproduct. -/ noncomputable abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.right⟩ /-- The binary fan constructed from the projection maps is a limit. -/ noncomputable def prodIsProd (X Y : C) [HasBinaryProduct X Y] : IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) := (limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · simp [Category.id_comp] · simp [Category.id_comp] )) /-- The binary cofan constructed from the coprojection maps is a colimit. -/ noncomputable def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] : IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) := (colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.comp_id] · dsimp; simp only [Category.comp_id] )) @[ext 1100] theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y} (h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g := BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂ @[ext 1100] theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W} (h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂ /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/ noncomputable abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y := limit.lift _ (BinaryFan.mk f g) /-- diagonal arrow of the binary product in the category `fam I` -/ noncomputable abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X := prod.lift (𝟙 _) (𝟙 _) /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/ noncomputable abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W := colimit.desc _ (BinaryCofan.mk f g) /-- codiagonal arrow of the binary coproduct -/ noncomputable abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X := coprod.desc (𝟙 _) (𝟙 _) @[reassoc] theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.fst = f := limit.lift_π _ _ @[reassoc] theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.snd = g := limit.lift_π _ _ @[reassoc] theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inl ≫ coprod.desc f g = f := colimit.ι_desc _ _ @[reassoc] theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inr ≫ coprod.desc f g = g := colimit.ι_desc _ _ instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_fst _ _ instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_snd _ _ instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inl_desc _ _ instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inr_desc _ _ /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/ noncomputable def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } := ⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩ /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and `coprod.inr ≫ l = g`. -/ noncomputable def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : { l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } := ⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩ /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/ noncomputable def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z := limMap (mapPair f g) /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/ noncomputable def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z := colimMap (mapPair f g) noncomputable section ProdLemmas -- Making the reassoc version of this a simp lemma seems to be more harmful than helpful. @[reassoc, simp] theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) : f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) : f ≫ diag Y = prod.lift f f := by simp @[reassoc (attr := simp)] theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f := limMap_π _ _ @[reassoc (attr := simp)] theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g := limMap_π _ _ @[simp] theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp @[simp] theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] : prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp @[reassoc (attr := simp)] theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W) (g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) : prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp @[simp] theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by rw [← prod.lift_map] simp -- We take the right-hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (e.g. `id_comp`), while `map_fst` and `map_snd` can still work just -- as well. @[reassoc (attr := simp)] theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂] [HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp -- TODO: is it necessary to weaken the assumption here? @[reassoc] theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasLimitsOfShape (Discrete WalkingPair) C] : prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp @[reassoc] theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W] [HasBinaryProduct Z W] [HasBinaryProduct Y W] : prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp @[reassoc] theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X] [HasBinaryProduct W Y] [HasBinaryProduct W Z] : prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/ @[simps] def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where hom := prod.map f.hom g.hom inv := prod.map f.inv g.inv instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) := (prod.mapIso (asIso f) (asIso g)).isIso_hom instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_mono f] simpa using congr_arg (fun f => f ≫ prod.fst) h · rw [← cancel_mono g] simpa using congr_arg (fun f => f ≫ prod.snd) h⟩ @[reassoc] theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] : diag X ≫ prod.map f f = f ≫ diag Y := by simp @[reassoc] theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] : diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp @[reassoc] theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) := IsSplitMono.mk' { retraction := prod.fst } end ProdLemmas noncomputable section CoprodLemmas @[reassoc, simp] theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by ext <;> simp theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) : codiag X ≫ f = coprod.desc f f := by simp @[reassoc (attr := simp)] theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl := ι_colimMap _ _ @[reassoc (attr := simp)] theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr := ι_colimMap _ _ @[simp] theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp @[simp] theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] : coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp -- The simp linter says simp can prove the reassoc version of this lemma. @[reassoc, simp] theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V] (f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) : coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by ext <;> simp @[simp] theorem coprod.desc_comp_inl_comp_inr {W X Y Z : C} [HasBinaryCoproduct W Y] [HasBinaryCoproduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : coprod.desc (g ≫ coprod.inl) (g' ≫ coprod.inr) = coprod.map g g' := by rw [← coprod.map_desc]; simp -- We take the right-hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (e.g. `id_comp`), while `inl_map` and `inr_map` can still work just -- as well. @[reassoc (attr := simp)] theorem coprod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryCoproduct A₁ B₁] [HasBinaryCoproduct A₂ B₂] [HasBinaryCoproduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : coprod.map f g ≫ coprod.map h k = coprod.map (f ≫ h) (g ≫ k) := by ext <;> simp -- I don't think it's a good idea to make any of the following three simp lemmas. @[reassoc] theorem coprod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasColimitsOfShape (Discrete WalkingPair) C] : coprod.map (𝟙 X) f ≫ coprod.map g (𝟙 B) = coprod.map g (𝟙 A) ≫ coprod.map (𝟙 Y) f := by simp @[reassoc] theorem coprod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct Z W] [HasBinaryCoproduct Y W] [HasBinaryCoproduct X W] : coprod.map (f ≫ g) (𝟙 W) = coprod.map f (𝟙 W) ≫ coprod.map g (𝟙 W) := by simp @[reassoc] theorem coprod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct W X] [HasBinaryCoproduct W Y] [HasBinaryCoproduct W Z] : coprod.map (𝟙 W) (f ≫ g) = coprod.map (𝟙 W) f ≫ coprod.map (𝟙 W) g := by simp /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : W ≅ Z` induces an isomorphism `coprod.mapIso f g : W ⨿ X ≅ Y ⨿ Z`. -/ @[simps] def coprod.mapIso {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨿ X ≅ Y ⨿ Z where hom := coprod.map f.hom g.hom inv := coprod.map f.inv g.inv instance isIso_coprod {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (coprod.map f g) := (coprod.mapIso (asIso f) (asIso g)).isIso_hom instance coprod.map_epi {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f] [Epi g] [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] : Epi (coprod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_epi f] simpa using congr_arg (fun f => coprod.inl ≫ f) h · rw [← cancel_epi g] simpa using congr_arg (fun f => coprod.inr ≫ f) h⟩ @[reassoc] theorem coprod.map_codiag {X Y : C} (f : X ⟶ Y) [HasBinaryCoproduct X X] [HasBinaryCoproduct Y Y] : coprod.map f f ≫ codiag Y = codiag X ≫ f := by simp @[reassoc] theorem coprod.map_inl_inr_codiag {X Y : C} [HasBinaryCoproduct X Y] [HasBinaryCoproduct (X ⨿ Y) (X ⨿ Y)] : coprod.map coprod.inl coprod.inr ≫ codiag (X ⨿ Y) = 𝟙 (X ⨿ Y) := by simp @[reassoc] theorem coprod.map_comp_inl_inr_codiag [HasColimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : coprod.map (g ≫ coprod.inl) (g' ≫ coprod.inr) ≫ codiag (Y ⨿ Y') = coprod.map g g' := by simp end CoprodLemmas variable (C) /-- A category `HasBinaryProducts` if it has all limits of shape `Discrete WalkingPair`, i.e. if it has a product for every pair of objects. -/ @[stacks 001T] abbrev HasBinaryProducts := HasLimitsOfShape (Discrete WalkingPair) C /-- A category `HasBinaryCoproducts` if it has all colimit of shape `Discrete WalkingPair`, i.e. if it has a coproduct for every pair of objects. -/ @[stacks 04AP] abbrev HasBinaryCoproducts := HasColimitsOfShape (Discrete WalkingPair) C /-- If `C` has all limits of diagrams `pair X Y`, then it has all binary products -/ theorem hasBinaryProducts_of_hasLimit_pair [∀ {X Y : C}, HasLimit (pair X Y)] : HasBinaryProducts C := { has_limit := fun F => hasLimit_of_iso (diagramIsoPair F).symm } /-- If `C` has all colimits of diagrams `pair X Y`, then it has all binary coproducts -/ theorem hasBinaryCoproducts_of_hasColimit_pair [∀ {X Y : C}, HasColimit (pair X Y)] : HasBinaryCoproducts C := { has_colimit := fun F => hasColimit_of_iso (diagramIsoPair F) } noncomputable section variable {C} /-- The braiding isomorphism which swaps a binary product. -/ @[simps] def prod.braiding (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : P ⨯ Q ≅ Q ⨯ P where hom := prod.lift prod.snd prod.fst inv := prod.lift prod.snd prod.fst /-- The braiding isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem braid_natural [HasBinaryProducts C] {W X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ W) : prod.map f g ≫ (prod.braiding _ _).hom = (prod.braiding _ _).hom ≫ prod.map g f := by simp @[reassoc] theorem prod.symmetry' (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : prod.lift prod.snd prod.fst ≫ prod.lift prod.snd prod.fst = 𝟙 (P ⨯ Q) := (prod.braiding _ _).hom_inv_id /-- The braiding isomorphism is symmetric. -/ @[reassoc] theorem prod.symmetry (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : (prod.braiding P Q).hom ≫ (prod.braiding Q P).hom = 𝟙 _ := (prod.braiding _ _).hom_inv_id /-- The associator isomorphism for binary products. -/ @[simps] def prod.associator [HasBinaryProducts C] (P Q R : C) : (P ⨯ Q) ⨯ R ≅ P ⨯ Q ⨯ R where hom := prod.lift (prod.fst ≫ prod.fst) (prod.lift (prod.fst ≫ prod.snd) prod.snd) inv := prod.lift (prod.lift prod.fst (prod.snd ≫ prod.fst)) (prod.snd ≫ prod.snd) @[reassoc] theorem prod.pentagon [HasBinaryProducts C] (W X Y Z : C) : prod.map (prod.associator W X Y).hom (𝟙 Z) ≫ (prod.associator W (X ⨯ Y) Z).hom ≫ prod.map (𝟙 W) (prod.associator X Y Z).hom = (prod.associator (W ⨯ X) Y Z).hom ≫ (prod.associator W X (Y ⨯ Z)).hom := by simp @[reassoc] theorem prod.associator_naturality [HasBinaryProducts C] {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) : prod.map (prod.map f₁ f₂) f₃ ≫ (prod.associator Y₁ Y₂ Y₃).hom = (prod.associator X₁ X₂ X₃).hom ≫ prod.map f₁ (prod.map f₂ f₃) := by simp variable [HasTerminal C] /-- The left unitor isomorphism for binary products with the terminal object. -/ @[simps] def prod.leftUnitor (P : C) [HasBinaryProduct (⊤_ C) P] : (⊤_ C) ⨯ P ≅ P where hom := prod.snd inv := prod.lift (terminal.from P) (𝟙 _) hom_inv_id := by apply prod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp /-- The right unitor isomorphism for binary products with the terminal object. -/ @[simps] def prod.rightUnitor (P : C) [HasBinaryProduct P (⊤_ C)] : P ⨯ ⊤_ C ≅ P where hom := prod.fst inv := prod.lift (𝟙 _) (terminal.from P) hom_inv_id := by apply prod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp @[reassoc] theorem prod.leftUnitor_hom_naturality [HasBinaryProducts C] (f : X ⟶ Y) : prod.map (𝟙 _) f ≫ (prod.leftUnitor Y).hom = (prod.leftUnitor X).hom ≫ f := prod.map_snd _ _ @[reassoc] theorem prod.leftUnitor_inv_naturality [HasBinaryProducts C] (f : X ⟶ Y) : (prod.leftUnitor X).inv ≫ prod.map (𝟙 _) f = f ≫ (prod.leftUnitor Y).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, prod.leftUnitor_hom_naturality] @[reassoc] theorem prod.rightUnitor_hom_naturality [HasBinaryProducts C] (f : X ⟶ Y) : prod.map f (𝟙 _) ≫ (prod.rightUnitor Y).hom = (prod.rightUnitor X).hom ≫ f := prod.map_fst _ _ @[reassoc] theorem prod_rightUnitor_inv_naturality [HasBinaryProducts C] (f : X ⟶ Y) : (prod.rightUnitor X).inv ≫ prod.map f (𝟙 _) = f ≫ (prod.rightUnitor Y).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, prod.rightUnitor_hom_naturality] theorem prod.triangle [HasBinaryProducts C] (X Y : C) : (prod.associator X (⊤_ C) Y).hom ≫ prod.map (𝟙 X) (prod.leftUnitor Y).hom = prod.map (prod.rightUnitor X).hom (𝟙 Y) := by ext <;> simp end noncomputable section variable {C} variable [HasBinaryCoproducts C] /-- The braiding isomorphism which swaps a binary coproduct. -/ @[simps] def coprod.braiding (P Q : C) : P ⨿ Q ≅ Q ⨿ P where hom := coprod.desc coprod.inr coprod.inl inv := coprod.desc coprod.inr coprod.inl @[reassoc] theorem coprod.symmetry' (P Q : C) : coprod.desc coprod.inr coprod.inl ≫ coprod.desc coprod.inr coprod.inl = 𝟙 (P ⨿ Q) := (coprod.braiding _ _).hom_inv_id /-- The braiding isomorphism is symmetric. -/ theorem coprod.symmetry (P Q : C) : (coprod.braiding P Q).hom ≫ (coprod.braiding Q P).hom = 𝟙 _ := coprod.symmetry' _ _ /-- The associator isomorphism for binary coproducts. -/ @[simps] def coprod.associator (P Q R : C) : (P ⨿ Q) ⨿ R ≅ P ⨿ Q ⨿ R where hom := coprod.desc (coprod.desc coprod.inl (coprod.inl ≫ coprod.inr)) (coprod.inr ≫ coprod.inr) inv := coprod.desc (coprod.inl ≫ coprod.inl) (coprod.desc (coprod.inr ≫ coprod.inl) coprod.inr) theorem coprod.pentagon (W X Y Z : C) : coprod.map (coprod.associator W X Y).hom (𝟙 Z) ≫ (coprod.associator W (X ⨿ Y) Z).hom ≫ coprod.map (𝟙 W) (coprod.associator X Y Z).hom = (coprod.associator (W ⨿ X) Y Z).hom ≫ (coprod.associator W X (Y ⨿ Z)).hom := by simp theorem coprod.associator_naturality {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) : coprod.map (coprod.map f₁ f₂) f₃ ≫ (coprod.associator Y₁ Y₂ Y₃).hom = (coprod.associator X₁ X₂ X₃).hom ≫ coprod.map f₁ (coprod.map f₂ f₃) := by simp variable [HasInitial C] /-- The left unitor isomorphism for binary coproducts with the initial object. -/ @[simps] def coprod.leftUnitor (P : C) : (⊥_ C) ⨿ P ≅ P where hom := coprod.desc (initial.to P) (𝟙 _) inv := coprod.inr hom_inv_id := by apply coprod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp /-- The right unitor isomorphism for binary coproducts with the initial object. -/ @[simps] def coprod.rightUnitor (P : C) : P ⨿ ⊥_ C ≅ P where hom := coprod.desc (𝟙 _) (initial.to P) inv := coprod.inl hom_inv_id := by apply coprod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp theorem coprod.triangle (X Y : C) : (coprod.associator X (⊥_ C) Y).hom ≫ coprod.map (𝟙 X) (coprod.leftUnitor Y).hom = coprod.map (coprod.rightUnitor X).hom (𝟙 Y) := by ext <;> simp end noncomputable section ProdFunctor variable {C} [Category.{v} C] [HasBinaryProducts C] /-- The binary product functor. -/ @[simps] def prod.functor : C ⥤ C ⥤ C where obj X := { obj := fun Y => X ⨯ Y map := fun {_ _} => prod.map (𝟙 X) } map f := { app := fun T => prod.map f (𝟙 T) } /-- The product functor can be decomposed. -/ def prod.functorLeftComp (X Y : C) : prod.functor.obj (X ⨯ Y) ≅ prod.functor.obj Y ⋙ prod.functor.obj X := NatIso.ofComponents (prod.associator _ _) end ProdFunctor noncomputable section CoprodFunctor variable {C} [HasBinaryCoproducts C] /-- The binary coproduct functor. -/ @[simps] def coprod.functor : C ⥤ C ⥤ C where obj X := { obj := fun Y => X ⨿ Y map := fun {_ _} => coprod.map (𝟙 X) } map f := { app := fun T => coprod.map f (𝟙 T) } /-- The coproduct functor can be decomposed. -/ def coprod.functorLeftComp (X Y : C) : coprod.functor.obj (X ⨿ Y) ≅ coprod.functor.obj Y ⋙ coprod.functor.obj X := NatIso.ofComponents (coprod.associator _ _) end CoprodFunctor noncomputable section ProdComparison universe w w' u₃ variable {C} {D : Type u₂} [Category.{w} D] {E : Type u₃} [Category.{w'} E] variable (F : C ⥤ D) (G : D ⥤ E) {A A' B B' : C} variable [HasBinaryProduct A B] [HasBinaryProduct A' B'] variable [HasBinaryProduct (F.obj A) (F.obj B)] variable [HasBinaryProduct (F.obj A') (F.obj B')] variable [HasBinaryProduct (G.obj (F.obj A)) (G.obj (F.obj B))] variable [HasBinaryProduct ((F ⋙ G).obj A) ((F ⋙ G).obj B)] /-- The product comparison morphism. In `CategoryTheory/Limits/Preserves` we show this is always an iso iff F preserves binary products. -/ def prodComparison (F : C ⥤ D) (A B : C) [HasBinaryProduct A B] [HasBinaryProduct (F.obj A) (F.obj B)] : F.obj (A ⨯ B) ⟶ F.obj A ⨯ F.obj B := prod.lift (F.map prod.fst) (F.map prod.snd) variable (A B) @[reassoc (attr := simp)] theorem prodComparison_fst : prodComparison F A B ≫ prod.fst = F.map prod.fst := prod.lift_fst _ _ @[reassoc (attr := simp)] theorem prodComparison_snd : prodComparison F A B ≫ prod.snd = F.map prod.snd := prod.lift_snd _ _ variable {A B} /-- Naturality of the `prodComparison` morphism in both arguments. -/ @[reassoc] theorem prodComparison_natural (f : A ⟶ A') (g : B ⟶ B') : F.map (prod.map f g) ≫ prodComparison F A' B' = prodComparison F A B ≫ prod.map (F.map f) (F.map g) := by rw [prodComparison, prodComparison, prod.lift_map, ← F.map_comp, ← F.map_comp, prod.comp_lift, ← F.map_comp, prod.map_fst, ← F.map_comp, prod.map_snd] variable {F} /-- Naturality of the `prodComparison` morphism in a natural transformation. -/ @[reassoc] theorem prodComparison_natural_of_natTrans {H : C ⥤ D} [HasBinaryProduct (H.obj A) (H.obj B)] (α : F ⟶ H) : α.app (prod A B) ≫ prodComparison H A B = prodComparison F A B ≫ prod.map (α.app A) (α.app B) := by rw [prodComparison, prodComparison, prod.lift_map, prod.comp_lift, α.naturality, α.naturality] variable (F) /-- The product comparison morphism from `F(A ⨯ -)` to `FA ⨯ F-`, whose components are given by `prodComparison`. -/ @[simps] def prodComparisonNatTrans [HasBinaryProducts C] [HasBinaryProducts D] (F : C ⥤ D) (A : C) : prod.functor.obj A ⋙ F ⟶ F ⋙ prod.functor.obj (F.obj A) where app B := prodComparison F A B naturality f := by simp [prodComparison_natural] @[reassoc] theorem inv_prodComparison_map_fst [IsIso (prodComparison F A B)] : inv (prodComparison F A B) ≫ F.map prod.fst = prod.fst := by simp [IsIso.inv_comp_eq] @[reassoc] theorem inv_prodComparison_map_snd [IsIso (prodComparison F A B)] : inv (prodComparison F A B) ≫ F.map prod.snd = prod.snd := by simp [IsIso.inv_comp_eq] /-- If the product comparison morphism is an iso, its inverse is natural. -/ @[reassoc] theorem prodComparison_inv_natural (f : A ⟶ A') (g : B ⟶ B') [IsIso (prodComparison F A B)] [IsIso (prodComparison F A' B')] : inv (prodComparison F A B) ≫ F.map (prod.map f g) = prod.map (F.map f) (F.map g) ≫ inv (prodComparison F A' B') := by rw [IsIso.eq_comp_inv, Category.assoc, IsIso.inv_comp_eq, prodComparison_natural] /-- The natural isomorphism `F(A ⨯ -) ≅ FA ⨯ F-`, provided each `prodComparison F A B` is an isomorphism (as `B` changes). -/ @[simps] def prodComparisonNatIso [HasBinaryProducts C] [HasBinaryProducts D] (A : C) [∀ B, IsIso (prodComparison F A B)] : prod.functor.obj A ⋙ F ≅ F ⋙ prod.functor.obj (F.obj A) := by refine { @asIso _ _ _ _ _ (?_) with hom := prodComparisonNatTrans F A } apply NatIso.isIso_of_isIso_app theorem prodComparison_comp : prodComparison (F ⋙ G) A B = G.map (prodComparison F A B) ≫ prodComparison G (F.obj A) (F.obj B) := by unfold prodComparison ext <;> simp [← G.map_comp] end ProdComparison noncomputable section CoprodComparison universe w variable {C} {D : Type u₂} [Category.{w} D] variable (F : C ⥤ D) {A A' B B' : C} variable [HasBinaryCoproduct A B] [HasBinaryCoproduct A' B'] variable [HasBinaryCoproduct (F.obj A) (F.obj B)] [HasBinaryCoproduct (F.obj A') (F.obj B')] /-- The coproduct comparison morphism. In `Mathlib/CategoryTheory/Limits/Preserves/` we show this is always an iso iff F preserves binary coproducts. -/ def coprodComparison (F : C ⥤ D) (A B : C) [HasBinaryCoproduct A B] [HasBinaryCoproduct (F.obj A) (F.obj B)] : F.obj A ⨿ F.obj B ⟶ F.obj (A ⨿ B) := coprod.desc (F.map coprod.inl) (F.map coprod.inr) @[reassoc (attr := simp)] theorem coprodComparison_inl : coprod.inl ≫ coprodComparison F A B = F.map coprod.inl := coprod.inl_desc _ _ @[reassoc (attr := simp)] theorem coprodComparison_inr : coprod.inr ≫ coprodComparison F A B = F.map coprod.inr := coprod.inr_desc _ _ /-- Naturality of the coprod_comparison morphism in both arguments. -/ @[reassoc] theorem coprodComparison_natural (f : A ⟶ A') (g : B ⟶ B') : coprodComparison F A B ≫ F.map (coprod.map f g) = coprod.map (F.map f) (F.map g) ≫ coprodComparison F A' B' := by rw [coprodComparison, coprodComparison, coprod.map_desc, ← F.map_comp, ← F.map_comp, coprod.desc_comp, ← F.map_comp, coprod.inl_map, ← F.map_comp, coprod.inr_map] /-- The coproduct comparison morphism from `FA ⨿ F-` to `F(A ⨿ -)`, whose components are given by `coprodComparison`. -/ @[simps] def coprodComparisonNatTrans [HasBinaryCoproducts C] [HasBinaryCoproducts D] (F : C ⥤ D) (A : C) : F ⋙ coprod.functor.obj (F.obj A) ⟶ coprod.functor.obj A ⋙ F where app B := coprodComparison F A B naturality f := by simp [coprodComparison_natural] @[reassoc] theorem map_inl_inv_coprodComparison [IsIso (coprodComparison F A B)] : F.map coprod.inl ≫ inv (coprodComparison F A B) = coprod.inl := by simp @[reassoc] theorem map_inr_inv_coprodComparison [IsIso (coprodComparison F A B)] : F.map coprod.inr ≫ inv (coprodComparison F A B) = coprod.inr := by simp /-- If the coproduct comparison morphism is an iso, its inverse is natural. -/ @[reassoc] theorem coprodComparison_inv_natural (f : A ⟶ A') (g : B ⟶ B') [IsIso (coprodComparison F A B)] [IsIso (coprodComparison F A' B')] : inv (coprodComparison F A B) ≫ coprod.map (F.map f) (F.map g) = F.map (coprod.map f g) ≫ inv (coprodComparison F A' B') := by rw [IsIso.eq_comp_inv, Category.assoc, IsIso.inv_comp_eq, coprodComparison_natural] /-- The natural isomorphism `FA ⨿ F- ≅ F(A ⨿ -)`, provided each `coprodComparison F A B` is an isomorphism (as `B` changes). -/ @[simps] def coprodComparisonNatIso [HasBinaryCoproducts C] [HasBinaryCoproducts D] (A : C) [∀ B, IsIso (coprodComparison F A B)] : F ⋙ coprod.functor.obj (F.obj A) ≅ coprod.functor.obj A ⋙ F := { @asIso _ _ _ _ _ (NatIso.isIso_of_isIso_app ..) with hom := coprodComparisonNatTrans F A } end CoprodComparison end CategoryTheory.Limits open CategoryTheory.Limits namespace CategoryTheory variable {C : Type u} [Category.{v} C] /-- Auxiliary definition for `Over.coprod`. -/ @[simps] noncomputable def Over.coprodObj [HasBinaryCoproducts C] {A : C} : Over A → Over A ⥤ Over A := fun f => { obj := fun g => Over.mk (coprod.desc f.hom g.hom) map := fun k => Over.homMk (coprod.map (𝟙 _) k.left) } /-- A category with binary coproducts has a functorial `sup` operation on over categories. -/ @[simps] noncomputable def Over.coprod [HasBinaryCoproducts C] {A : C} : Over A ⥤ Over A ⥤ Over A where obj f := Over.coprodObj f map k := { app := fun g => Over.homMk (coprod.map k.left (𝟙 _)) (by dsimp; rw [coprod.map_desc, Category.id_comp, Over.w k]) naturality := fun f g k => by ext simp } map_id X := by ext simp map_comp f g := by ext simp end CategoryTheory namespace CategoryTheory.Limits open Opposite variable {C : Type u} [Category.{v} C] {X Y Z P : C} section opposite /-- A binary fan gives a binary cofan in the opposite category. -/ protected abbrev BinaryFan.op (c : BinaryFan X Y) : BinaryCofan (op X) (op Y) := .mk c.fst.op c.snd.op /-- A binary cofan gives a binary fan in the opposite category. -/ protected abbrev BinaryCofan.op (c : BinaryCofan X Y) : BinaryFan (op X) (op Y) := .mk c.inl.op c.inr.op /-- A binary fan in the opposite category gives a binary cofan. -/ protected abbrev BinaryFan.unop (c : BinaryFan (op X) (op Y)) : BinaryCofan X Y := .mk c.fst.unop c.snd.unop /-- A binary cofan in the opposite category gives a binary fan. -/ protected abbrev BinaryCofan.unop (c : BinaryCofan (op X) (op Y)) : BinaryFan X Y := .mk c.inl.unop c.inr.unop @[simp] lemma BinaryFan.op_mk (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan.op (mk π₁ π₂) = .mk π₁.op π₂.op := rfl @[simp] lemma BinaryFan.unop_mk (π₁ : op P ⟶ op X) (π₂ : op P ⟶ op Y) : BinaryFan.unop (mk π₁ π₂) = .mk π₁.unop π₂.unop := rfl @[simp] lemma BinaryCofan.op_mk (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan.op (mk ι₁ ι₂) = .mk ι₁.op ι₂.op := rfl @[simp] lemma BinaryCofan.unop_mk (ι₁ : op X ⟶ op P) (ι₂ : op Y ⟶ op P) : BinaryCofan.unop (mk ι₁ ι₂) = .mk ι₁.unop ι₂.unop := rfl /-- If a `BinaryFan` is a limit, then its opposite is a colimit. -/ protected def BinaryFan.IsLimit.op {c : BinaryFan X Y} (hc : IsLimit c) : IsColimit c.op := BinaryCofan.isColimitMk (fun s ↦ (hc.lift s.unop).op) (fun _ ↦ Quiver.Hom.unop_inj (by simp)) (fun _ ↦ Quiver.Hom.unop_inj (by simp)) (fun s m h₁ h₂ ↦ Quiver.Hom.unop_inj (BinaryFan.IsLimit.hom_ext hc (by simp [← h₁]) (by simp [← h₂]))) /-- If a `BinaryCofan` is a colimit, then its opposite is a limit. -/ protected def BinaryCofan.IsColimit.op {c : BinaryCofan X Y} (hc : IsColimit c) : IsLimit c.op := BinaryFan.isLimitMk (fun s ↦ (hc.desc s.unop).op) (fun _ ↦ Quiver.Hom.unop_inj (by simp)) (fun _ ↦ Quiver.Hom.unop_inj (by simp)) (fun s m h₁ h₂ ↦ Quiver.Hom.unop_inj (BinaryCofan.IsColimit.hom_ext hc (by simp [← h₁]) (by simp [← h₂]))) /-- If a `BinaryFan` in the opposite category is a limit, then its `unop` is a colimit. -/ protected def BinaryFan.IsLimit.unop {c : BinaryFan (op X) (op Y)} (hc : IsLimit c) : IsColimit c.unop := BinaryCofan.isColimitMk (fun s ↦ (hc.lift s.op).unop) (fun _ ↦ Quiver.Hom.op_inj (by simp)) (fun _ ↦ Quiver.Hom.op_inj (by simp)) (fun s m h₁ h₂ ↦ Quiver.Hom.op_inj (BinaryFan.IsLimit.hom_ext hc (by simp [← h₁]) (by simp [← h₂]))) /-- If a `BinaryCofan` in the opposite category is a colimit, then its `unop` is a limit. -/ protected def BinaryCofan.IsColimit.unop {c : BinaryCofan (op X) (op Y)} (hc : IsColimit c) : IsLimit c.unop := BinaryFan.isLimitMk (fun s ↦ (hc.desc s.op).unop) (fun _ ↦ Quiver.Hom.op_inj (by simp)) (fun _ ↦ Quiver.Hom.op_inj (by simp)) (fun s m h₁ h₂ ↦ Quiver.Hom.op_inj (BinaryCofan.IsColimit.hom_ext hc (by simp [← h₁]) (by simp [← h₂]))) end opposite section swap variable {s : BinaryFan X Y} {t : BinaryFan Y X} /-- Swap the two sides of a `BinaryFan`. -/ def BinaryFan.swap (s : BinaryFan X Y) : BinaryFan Y X := .mk s.snd s.fst @[simp] lemma BinaryFan.swap_fst (s : BinaryFan X Y) : s.swap.fst = s.snd := rfl @[simp] lemma BinaryFan.swap_snd (s : BinaryFan X Y) : s.swap.snd = s.fst := rfl /-- If a binary fan `s` over `X Y` is a limit cone, then `s.swap` is a limit cone over `Y X`. -/ @[simps] def IsLimit.binaryFanSwap (I : IsLimit s) : IsLimit s.swap where lift t := I.lift (BinaryFan.swap t) fac t := by rintro ⟨⟨⟩⟩ <;> simp uniq t m w := by have h := I.uniq (BinaryFan.swap t) m rw [h] rintro ⟨j⟩ specialize w ⟨WalkingPair.swap j⟩ cases j <;> exact w @[deprecated (since := "2025-05-04")] alias IsLimit.swapBinaryFan := IsLimit.binaryFanSwap /-- Construct `HasBinaryProduct Y X` from `HasBinaryProduct X Y`. This can't be an instance, as it would cause a loop in typeclass search. -/ lemma HasBinaryProduct.swap (X Y : C) [HasBinaryProduct X Y] : HasBinaryProduct Y X := .mk ⟨BinaryFan.swap (limit.cone (pair X Y)), (limit.isLimit (pair X Y)).binaryFanSwap⟩ end swap section braiding variable {X Y : C} {s : BinaryFan X Y} (P : IsLimit s) {t : BinaryFan Y X} (Q : IsLimit t) /-- Given a limit cone over `X` and `Y`, and another limit cone over `Y` and `X`, we can construct an isomorphism between the cone points. Relative to some fixed choice of limits cones for every pair, these isomorphisms constitute a braiding. -/ def BinaryFan.braiding (P : IsLimit s) (Q : IsLimit t) : s.pt ≅ t.pt := P.conePointUniqueUpToIso Q.binaryFanSwap @[reassoc (attr := simp)] lemma BinaryFan.braiding_hom_fst : (braiding P Q).hom ≫ t.fst = s.snd := P.conePointUniqueUpToIso_hom_comp _ ⟨.right⟩ @[reassoc (attr := simp)] lemma BinaryFan.braiding_hom_snd : (braiding P Q).hom ≫ t.snd = s.fst := P.conePointUniqueUpToIso_hom_comp _ ⟨.left⟩ @[reassoc (attr := simp)] lemma BinaryFan.braiding_inv_fst : (braiding P Q).inv ≫ s.fst = t.snd := P.conePointUniqueUpToIso_inv_comp _ ⟨.left⟩ @[reassoc (attr := simp)] lemma BinaryFan.braiding_inv_snd : (braiding P Q).inv ≫ s.snd = t.fst := P.conePointUniqueUpToIso_inv_comp _ ⟨.right⟩ end braiding section assoc variable {sXY : BinaryFan X Y} {sYZ : BinaryFan Y Z} /-- Given binary fans `sXY` over `X Y`, and `sYZ` over `Y Z`, and `s` over `sXY.X Z`, if `sYZ` is a limit cone we can construct a binary fan over `X sYZ.X`. This is an ingredient of building the associator for a Cartesian category. -/ def BinaryFan.assoc (Q : IsLimit sYZ) (s : BinaryFan sXY.pt Z) : BinaryFan X sYZ.pt := mk (s.fst ≫ sXY.fst) (Q.lift (mk (s.fst ≫ sXY.snd) s.snd)) @[simp] lemma BinaryFan.assoc_fst (Q : IsLimit sYZ) (s : BinaryFan sXY.pt Z) : (assoc Q s).fst = s.fst ≫ sXY.fst := rfl @[simp] lemma BinaryFan.assoc_snd (Q : IsLimit sYZ) (s : BinaryFan sXY.pt Z) : (assoc Q s).snd = Q.lift (mk (s.fst ≫ sXY.snd) s.snd) := rfl /-- Given binary fans `sXY` over `X Y`, and `sYZ` over `Y Z`, and `s` over `X sYZ.X`, if `sYZ` is a limit cone we can construct a binary fan over `sXY.X Z`. This is an ingredient of building the associator for a Cartesian category. -/ def BinaryFan.assocInv (P : IsLimit sXY) (s : BinaryFan X sYZ.pt) : BinaryFan sXY.pt Z := BinaryFan.mk (P.lift (BinaryFan.mk s.fst (s.snd ≫ sYZ.fst))) (s.snd ≫ sYZ.snd) @[simp] lemma BinaryFan.assocInv_fst (P : IsLimit sXY) (s : BinaryFan X sYZ.pt) : (assocInv P s).fst = P.lift (mk s.fst (s.snd ≫ sYZ.fst)) := rfl @[simp] lemma BinaryFan.assocInv_snd (P : IsLimit sXY) (s : BinaryFan X sYZ.pt) : (assocInv P s).snd = s.snd ≫ sYZ.snd := rfl /-- If all the binary fans involved a limit cones, `BinaryFan.assoc` produces another limit cone. -/ @[simps] protected def IsLimit.assoc (P : IsLimit sXY) (Q : IsLimit sYZ) {s : BinaryFan sXY.pt Z} (R : IsLimit s) : IsLimit (BinaryFan.assoc Q s) where lift t := R.lift (BinaryFan.assocInv P t) fac t := by rintro ⟨⟨⟩⟩ <;> simp; apply Q.hom_ext; rintro ⟨⟨⟩⟩ <;> simp uniq t m w := by have h := R.uniq (BinaryFan.assocInv P t) m rw [h] rintro ⟨⟨⟩⟩ <;> simp · apply P.hom_ext rintro ⟨⟨⟩⟩ <;> simp · exact w ⟨.left⟩ · replace w : m ≫ Q.lift (BinaryFan.mk (s.fst ≫ sXY.snd) s.snd) = t.π.app ⟨.right⟩ := by simpa using w ⟨.right⟩ simp [← w] · replace w : m ≫ Q.lift (BinaryFan.mk (s.fst ≫ sXY.snd) s.snd) = t.π.app ⟨.right⟩ := by simpa using w ⟨.right⟩ simp [← w] /-- Given two pairs of limit cones corresponding to the parenthesisations of `X × Y × Z`, we obtain an isomorphism between the cone points. -/ abbrev BinaryFan.associator (P : IsLimit sXY) (Q : IsLimit sYZ) {s : BinaryFan sXY.pt Z} (R : IsLimit s) {t : BinaryFan X sYZ.pt} (S : IsLimit t) : s.pt ≅ t.pt := (P.assoc Q R).conePointUniqueUpToIso S /-- Given a fixed family of limit data for every pair `X Y`, we obtain an associator. -/ abbrev BinaryFan.associatorOfLimitCone (L : ∀ X Y : C, LimitCone (pair X Y)) (X Y Z : C) : (L (L X Y).cone.pt Z).cone.pt ≅ (L X (L Y Z).cone.pt).cone.pt := associator (L X Y).isLimit (L Y Z).isLimit (L (L X Y).cone.pt Z).isLimit (L X (L Y Z).cone.pt).isLimit end assoc section unitor /-- Construct a left unitor from specified limit cones. -/ @[simps] def BinaryFan.leftUnitor {X : C} {s : Cone (Functor.empty.{0} C)} (P : IsLimit s) {t : BinaryFan s.pt X} (Q : IsLimit t) : t.pt ≅ X where hom := t.snd inv := Q.lift <| BinaryFan.mk (P.lift ⟨_, fun x => x.as.elim, fun {x} => x.as.elim⟩) (𝟙 _) hom_inv_id := by apply Q.hom_ext rintro ⟨⟨⟩⟩ · apply P.hom_ext rintro ⟨⟨⟩⟩ · simp /-- Construct a right unitor from specified limit cones. -/ @[simps] def BinaryFan.rightUnitor {X : C} {s : Cone (Functor.empty.{0} C)} (P : IsLimit s) {t : BinaryFan X s.pt} (Q : IsLimit t) : t.pt ≅ X where hom := t.fst inv := Q.lift <| BinaryFan.mk (𝟙 _) <| P.lift ⟨_, fun x => x.as.elim, fun {x} => x.as.elim⟩ hom_inv_id := by apply Q.hom_ext rintro ⟨⟨⟩⟩ · simp · apply P.hom_ext rintro ⟨⟨⟩⟩ end unitor end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/DisjointCoproduct.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Shapes.Products /-! # Disjoint coproducts Defines disjoint coproducts: coproducts where the intersection is initial and the coprojections are monic. Shows that a category with disjoint coproducts is `InitialMonoClass`. ## TODO * Adapt this to the infinitary (small) version: This is one of the conditions in Giraud's theorem characterising sheaf topoi. * Construct examples (and counterexamples?), e.g. Type, Vec. * Define extensive categories, and show every extensive category has disjoint coproducts. * Define coherent categories and use this to define positive coherent categories. -/ universe v u namespace CategoryTheory.Limits open Category variable {C : Type u} [Category.{v} C] /-- We say the coproduct of the family `Xᵢ` is disjoint, if whenever we have a pullback diagram of the form ``` Z ⟶ X₁ ↓ ↓ X₂ ⟶ ∐ X ``` `Z` is initial. -/ class CoproductDisjoint {ι : Type*} (X : ι → C) : Prop where nonempty_isInitial_of_ne {c : Cofan X} (hc : IsColimit c) {i j : ι} (_ : i ≠ j) (s : PullbackCone (c.inj i) (c.inj j)) : IsLimit s → Nonempty (IsInitial s.pt) mono_inj {c : Cofan X} (hc : IsColimit c) (i : ι) : Mono (c.inj i) section variable {ι : Type*} {X : ι → C} lemma CoproductDisjoint.of_cofan {c : Cofan X} (hc : IsColimit c) [∀ i, Mono (c.inj i)] (s : ∀ {i j : ι} (_ : i ≠ j), PullbackCone (c.inj i) (c.inj j)) (hs : ∀ {i j : ι} (hij : i ≠ j), IsLimit (s hij)) (H : ∀ {i j : ι} (hij : i ≠ j), IsInitial (s hij).pt) : CoproductDisjoint X where nonempty_isInitial_of_ne {d} hd {i j} hij t ht := by let e := hd.uniqueUpToIso hc have heq (i) : d.inj i ≫ e.hom.hom = c.inj i := e.hom.w ⟨i⟩ let u : t.pt ⟶ (s hij).pt := by refine PullbackCone.IsLimit.lift (hs hij) t.fst t.snd ?_ simp [← heq, t.condition_assoc] refine ⟨(H hij).ofIso ⟨(H hij).to t.pt, u, (H hij).hom_ext _ _, ?_⟩⟩ refine PullbackCone.IsLimit.hom_ext ht ?_ ?_ · simp [show (H hij).to (X i) = (s hij).fst from (H hij).hom_ext _ _, u] · simp [show (H hij).to (X j) = (s hij).snd from (H hij).hom_ext _ _, u] mono_inj {d} hd i := by rw [show d.inj i = c.inj i ≫ (hd.uniqueUpToIso hc).inv.hom by simp] infer_instance variable [CoproductDisjoint X] lemma _root_.CategoryTheory.Mono.of_coproductDisjoint {c : Cofan X} (hc : IsColimit c) (i : ι) : Mono (c.inj i) := CoproductDisjoint.mono_inj hc i instance _root_.CategoryTheory.Mono.ι_of_coproductDisjoint [HasCoproduct X] (i : ι) : Mono (Sigma.ι X i) := CoproductDisjoint.mono_inj (colimit.isColimit _) i namespace IsInitial variable {i j : ι} (hij : i ≠ j) /-- If `i ≠ j` and `Xᵢ ← Y → Xⱼ` is a pullback diagram over `Z`, where `Z` is the coproduct of the `Xᵢ`, then `Y` is initial. -/ noncomputable def ofCoproductDisjointOfIsColimitOfIsLimit {c : Cofan X} (hc : IsColimit c) {s : PullbackCone (c.inj i) (c.inj j)} (hs : IsLimit s) : IsInitial s.pt := (CoproductDisjoint.nonempty_isInitial_of_ne hc hij _ hs).some /-- If `i ≠ j`, the pullback `Xᵢ ×[∐ X] Xⱼ` is initial. -/ noncomputable def ofCoproductDisjoint [HasCoproduct X] [HasPullback (Sigma.ι X i) (Sigma.ι X j)] : IsInitial (pullback (Sigma.ι X i) (Sigma.ι X j)) := ofCoproductDisjointOfIsColimitOfIsLimit hij (colimit.isColimit _) (pullback.isLimit (Sigma.ι X i) (Sigma.ι X j)) /-- If `i ≠ j`, the pullback `Xᵢ ×[Z] Xⱼ` is initial, if `Z` is the coproduct of the `Xᵢ`. -/ noncomputable def ofCoproductDisjointOfIsColimit {Z : C} {f : ∀ i, X i ⟶ Z} [HasPullback (f i) (f j)] (hc : IsColimit (Cofan.mk _ f)) : IsInitial (pullback (f i) (f j)) := ofCoproductDisjointOfIsColimitOfIsLimit hij hc (pullback.isLimit (f i) (f j)) /-- If `i ≠ j` and `Xᵢ ← Y → Xⱼ` is a pullback diagram over `∐ X`, `Y` is initial. -/ noncomputable def ofCoproductDisjointOfIsLimit [HasCoproduct X] {s : PullbackCone (Sigma.ι X i) (Sigma.ι X j)} (hs : IsLimit s) : IsInitial s.pt := ofCoproductDisjointOfIsColimitOfIsLimit hij (colimit.isColimit _) hs end IsInitial end /-- The binary coproduct of `X` and `Y` is disjoint if the coproduct of the family `{X, Y}` is disjoint. -/ abbrev BinaryCoproductDisjoint (X Y : C) := CoproductDisjoint (fun j : WalkingPair ↦ (j.casesOn X Y : C)) section variable {X Y : C} lemma BinaryCoproductDisjoint.of_binaryCofan {c : BinaryCofan X Y} (hc : IsColimit c) [Mono c.inl] [Mono c.inr] {s : PullbackCone c.inl c.inr} (hs : IsLimit s) (H : IsInitial s.pt) : BinaryCoproductDisjoint X Y := by have (i : WalkingPair) : Mono (Cofan.inj c i) := by cases i · exact inferInstanceAs <| Mono c.inl · exact inferInstanceAs <| Mono c.inr refine .of_cofan hc (fun {i j} hij ↦ ?_) (fun {i j} hij ↦ ?_) (fun {i j} hij ↦ ?_) · match i, j with | .left, .right => exact s | .right, .left => exact s.flip · dsimp split · exact hs · exact PullbackCone.flipIsLimit hs · dsimp; split <;> exact H variable [BinaryCoproductDisjoint X Y] lemma _root_.CategoryTheory.Mono.cofanInl_of_binaryCoproductDisjoint {c : BinaryCofan X Y} (hc : IsColimit c) : Mono c.inl := .of_coproductDisjoint hc .left lemma _root_.CategoryTheory.Mono.cofanInr_of_binaryCoproductDisjoint {c : BinaryCofan X Y} (hc : IsColimit c) : Mono c.inr := .of_coproductDisjoint hc .right lemma _root_.CategoryTheory.Mono.of_binaryCoproductDisjoint_left {Z : C} {f : X ⟶ Z} (g : Y ⟶ Z) (hc : IsColimit <| BinaryCofan.mk f g) : Mono f := .of_coproductDisjoint hc .left lemma _root_.CategoryTheory.Mono.of_binaryCoproductDisjoint_right {Z : C} (f : X ⟶ Z) {g : Y ⟶ Z} (hc : IsColimit <| BinaryCofan.mk f g) : Mono g := .of_coproductDisjoint hc .right instance _root_.CategoryTheory.Mono.inl_of_binaryCoproductDisjoint [HasBinaryCoproduct X Y] : Mono (coprod.inl : X ⟶ X ⨿ Y) := @Mono.ι_of_coproductDisjoint _ _ _ _ _ ‹_› WalkingPair.left instance _root_.CategoryTheory.Mono.inr_of_binaryCoproductDisjoint [HasBinaryCoproduct X Y] : Mono (coprod.inr : Y ⟶ X ⨿ Y) := @Mono.ι_of_coproductDisjoint _ _ _ _ _ ‹_› WalkingPair.right namespace IsInitial /-- If `X ← Z → Y` is a pullback diagram over `W`, where `W` is the coproduct of `X` and `Y`, then `Z` is initial. -/ noncomputable def ofBinaryCoproductDisjointOfIsColimitOfIsLimit {c : BinaryCofan X Y} (hc : IsColimit c) {s : PullbackCone c.inl c.inr} (hs : IsLimit s) : IsInitial s.pt := (CoproductDisjoint.nonempty_isInitial_of_ne hc (by simp) _ hs).some /-- `X ×[X ⨿ Y] Y` is initial. -/ noncomputable def ofBinaryCoproductDisjoint [HasBinaryCoproduct X Y] [HasPullback (coprod.inl : X ⟶ X ⨿ Y) coprod.inr] : IsInitial (pullback (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) := ofBinaryCoproductDisjointOfIsColimitOfIsLimit (colimit.isColimit _) (pullback.isLimit _ _) /-- The pullback `X ×[W] Y` is initial, if `W` is the coproduct of `X` and `Y`. -/ noncomputable def ofBinaryCoproductDisjointOfIsColimit {Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (hc : IsColimit (BinaryCofan.mk f g)) : IsInitial (pullback f g) := ofBinaryCoproductDisjointOfIsColimitOfIsLimit hc (pullback.isLimit f g) /-- If `X ← Z → Y` is a pullback diagram over `X ⨿ Y`, `Z` is initial. -/ noncomputable def ofBinaryCoproductDisjointOfIsLimit [HasBinaryCoproduct X Y] (s : PullbackCone (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) (hs : IsLimit s) : IsInitial s.pt := ofBinaryCoproductDisjointOfIsColimitOfIsLimit (colimit.isColimit _) hs end IsInitial @[deprecated (since := "2025-06-18")] alias isInitialOfIsPullbackOfIsCoproduct := IsInitial.ofBinaryCoproductDisjointOfIsColimitOfIsLimit @[deprecated (since := "2025-06-18")] alias isInitialOfIsPullbackOfCoproduct := IsInitial.ofBinaryCoproductDisjointOfIsLimit @[deprecated (since := "2025-06-18")] alias isInitialOfPullbackOfIsCoproduct := IsInitial.ofBinaryCoproductDisjointOfIsColimit @[deprecated (since := "2025-06-18")] alias isInitialOfPullbackOfCoproduct := IsInitial.ofBinaryCoproductDisjoint @[deprecated (since := "2025-06-18")] alias CoproductDisjoint.mono_inl := CategoryTheory.Mono.of_binaryCoproductDisjoint_left @[deprecated (since := "2025-06-18")] alias CoproductDisjoint.mono_inr := CategoryTheory.Mono.of_binaryCoproductDisjoint_right end /-- `C` has disjoint coproducts if every coproduct is disjoint. -/ class CoproductsOfShapeDisjoint (C : Type*) [Category C] (ι : Type*) : Prop where coproductDisjoint (X : ι → C) : CoproductDisjoint X /-- `C` has disjoint binary coproducts if every binary coproduct is disjoint. -/ abbrev BinaryCoproductsDisjoint (C : Type*) [Category C] : Prop := CoproductsOfShapeDisjoint C WalkingPair attribute [instance 999] CoproductsOfShapeDisjoint.coproductDisjoint lemma BinaryCoproductsDisjoint.mk (H : ∀ (X Y : C), BinaryCoproductDisjoint X Y) : BinaryCoproductsDisjoint C where coproductDisjoint X := by convert H (X .left) (X .right) using 2 casesm WalkingPair <;> simp /-- If `C` has disjoint coproducts, any morphism out of initial is mono. Note it isn't true in general that `C` has strict initial objects, for instance consider the category of types and partial functions. -/ theorem initialMonoClass_of_coproductsDisjoint [BinaryCoproductsDisjoint C] : InitialMonoClass C where isInitial_mono_from X hI := .of_binaryCoproductDisjoint_left (CategoryTheory.CategoryStruct.id X) { desc := fun s : BinaryCofan _ _ => s.inr fac := fun _s j => Discrete.casesOn j fun j => WalkingPair.casesOn j (hI.hom_ext _ _) (id_comp _) uniq := fun (_s : BinaryCofan _ _) _m w => (id_comp _).symm.trans (w ⟨WalkingPair.right⟩) } @[deprecated (since := "2025-06-18")] alias initialMonoClass_of_disjoint_coproducts := initialMonoClass_of_coproductsDisjoint end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/ConcreteCategory.lean
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic import Mathlib.CategoryTheory.Limits.Constructions.EpiMono import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Types.Coproducts import Mathlib.CategoryTheory.Limits.Types.Products import Mathlib.CategoryTheory.Limits.Types.Pullbacks /-! # Limits in concrete categories In this file, we combine the description of limits in `Types` and the API about the preservation of products and pullbacks in order to describe these limits in a concrete category `C`. If `F : J → C` is a family of objects in `C`, we define a bijection `Limits.Concrete.productEquiv F : ToType (∏ᶜ F) ≃ ∀ j, ToType (F j)`. Similarly, if `f₁ : X₁ ⟶ S` and `f₂ : X₂ ⟶ S` are two morphisms, the elements in `pullback f₁ f₂` are identified by `Limits.Concrete.pullbackEquiv` to compatible tuples of elements in `X₁ × X₂`. Some results are also obtained for the terminal object, binary products, wide-pullbacks, wide-pushouts, multiequalizers and cokernels. -/ universe s w w' v u t r namespace CategoryTheory.Limits.Concrete variable {C : Type u} [Category.{v} C] section Products section ProductEquiv variable {FC : C → C → Type*} {CC : C → Type max w v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{max w v} C FC] {J : Type w} (F : J → C) [HasProduct F] [PreservesLimit (Discrete.functor F) (forget C)] /-- The equivalence `ToType (∏ᶜ F) ≃ ∀ j, ToType (F j)` if `F : J → C` is a family of objects in a concrete category `C`. -/ noncomputable def productEquiv : ToType (∏ᶜ F) ≃ ∀ j, ToType (F j) := ((PreservesProduct.iso (forget C) F) ≪≫ (Types.productIso.{w, v} fun j => ToType (F j))).toEquiv @[simp] lemma productEquiv_apply_apply (x : ToType (∏ᶜ F)) (j : J) : productEquiv F x j = Pi.π F j x := congr_fun (piComparison_comp_π (forget C) F j) x @[simp] lemma productEquiv_symm_apply_π (x : ∀ j, ToType (F j)) (j : J) : Pi.π F j ((productEquiv F).symm x) = x j := by rw [← productEquiv_apply_apply, Equiv.apply_symm_apply] end ProductEquiv section ProductExt variable {J : Type w} (f : J → C) [HasProduct f] {D : Type t} [Category.{r} D] variable {FD : D → D → Type*} {DD : D → Type max w r} [∀ X Y, FunLike (FD X Y) (DD X) (DD Y)] variable [ConcreteCategory.{max w r} D FD] (F : C ⥤ D) [PreservesLimit (Discrete.functor f) F] [HasProduct fun j => F.obj (f j)] [PreservesLimitsOfShape WalkingCospan (forget D)] [PreservesLimit (Discrete.functor fun b ↦ F.obj (f b)) (forget D)] lemma Pi.map_ext (x y : ToType (F.obj (∏ᶜ f : C))) (h : ∀ i, F.map (Pi.π f i) x = F.map (Pi.π f i) y) : x = y := by apply ConcreteCategory.injective_of_mono_of_preservesPullback (PreservesProduct.iso F f).hom apply Concrete.limit_ext _ (piComparison F _ x) (piComparison F _ y) intro ⟨j⟩ rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, piComparison_comp_π] exact h j end ProductExt end Products section Terminal variable {FC : C → C → Type*} {CC : C → Type w} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{w} C FC] /-- If `forget C` preserves terminals and `X` is terminal, then `ToType X` is a singleton. -/ noncomputable def uniqueOfTerminalOfPreserves [PreservesLimit (Functor.empty.{0} C) (forget C)] (X : C) (h : IsTerminal X) : Unique (ToType X) := Types.isTerminalEquivUnique (ToType X) <| IsTerminal.isTerminalObj (forget C) X h /-- If `forget C` reflects terminals and `ToType X` is a singleton, then `X` is terminal. -/ noncomputable def terminalOfUniqueOfReflects [ReflectsLimit (Functor.empty.{0} C) (forget C)] (X : C) (h : Unique (ToType X)) : IsTerminal X := IsTerminal.isTerminalOfObj (forget C) X <| (Types.isTerminalEquivUnique (ToType X)).symm h /-- The equivalence `IsTerminal X ≃ Unique (ToType X)` if the forgetful functor preserves and reflects terminals. -/ noncomputable def terminalIffUnique [PreservesLimit (Functor.empty.{0} C) (forget C)] [ReflectsLimit (Functor.empty.{0} C) (forget C)] (X : C) : IsTerminal X ≃ Unique (ToType X) := (IsTerminal.isTerminalIffObj (forget C) X).trans <| Types.isTerminalEquivUnique _ variable (C) variable [HasTerminal C] [PreservesLimit (Functor.empty.{0} C) (forget C)] /-- The equivalence `ToType (⊤_ C) ≃ PUnit` when `C` is a concrete category. -/ noncomputable def terminalEquiv : ToType (⊤_ C) ≃ PUnit := (PreservesTerminal.iso (forget C) ≪≫ Types.terminalIso).toEquiv noncomputable instance : Unique (ToType (⊤_ C)) where default := (terminalEquiv C).symm PUnit.unit uniq _ := (terminalEquiv C).injective (Subsingleton.elim _ _) end Terminal section Initial variable {FC : C → C → Type*} {CC : C → Type w} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{w} C FC] /-- If `forget C` preserves initials and `X` is initial, then `ToType X` is empty. -/ lemma empty_of_initial_of_preserves [PreservesColimit (Functor.empty.{0} C) (forget C)] (X : C) (h : Nonempty (IsInitial X)) : IsEmpty (ToType X) := by rw [← Types.initial_iff_empty] exact Nonempty.map (IsInitial.isInitialObj (forget C) _) h /-- If `forget C` reflects initials and `ToType X` is empty, then `X` is initial. -/ lemma initial_of_empty_of_reflects [ReflectsColimit (Functor.empty.{0} C) (forget C)] (X : C) (h : IsEmpty (ToType X)) : Nonempty (IsInitial X) := Nonempty.map (IsInitial.isInitialOfObj (forget C) _) <| (Types.initial_iff_empty (ToType X)).mpr h /-- If `forget C` preserves and reflects initials, then `X` is initial if and only if `ToType X` is empty. -/ lemma initial_iff_empty_of_preserves_of_reflects [PreservesColimit (Functor.empty.{0} C) (forget C)] [ReflectsColimit (Functor.empty.{0} C) (forget C)] (X : C) : Nonempty (IsInitial X) ↔ IsEmpty (ToType X) := by rw [← Types.initial_iff_empty, (IsInitial.isInitialIffObj (forget C) X).nonempty_congr] rfl end Initial section BinaryProducts variable {FC : C → C → Type*} {CC : C → Type w} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{w} C FC] (X₁ X₂ : C) [HasBinaryProduct X₁ X₂] [PreservesLimit (pair X₁ X₂) (forget C)] /-- The equivalence `ToType (X₁ ⨯ X₂) ≃ (ToType X₁) × (ToType X₂)` if `X₁` and `X₂` are objects in a concrete category `C`. -/ noncomputable def prodEquiv : ToType (X₁ ⨯ X₂) ≃ ToType X₁ × ToType X₂ := (PreservesLimitPair.iso (forget C) X₁ X₂ ≪≫ Types.binaryProductIso _ _).toEquiv @[simp] lemma prodEquiv_apply_fst (x : ToType (X₁ ⨯ X₂)) : (prodEquiv X₁ X₂ x).fst = (Limits.prod.fst : X₁ ⨯ X₂ ⟶ X₁) x := congr_fun (prodComparison_fst (forget C) X₁ X₂) x @[simp] lemma prodEquiv_apply_snd (x : ToType (X₁ ⨯ X₂)) : (prodEquiv X₁ X₂ x).snd = (Limits.prod.snd : X₁ ⨯ X₂ ⟶ X₂) x := congr_fun (prodComparison_snd (forget C) X₁ X₂) x @[simp] lemma prodEquiv_symm_apply_fst (x : ToType X₁ × ToType X₂) : (Limits.prod.fst : X₁ ⨯ X₂ ⟶ X₁) ((prodEquiv X₁ X₂).symm x) = x.1 := by obtain ⟨y, rfl⟩ := (prodEquiv X₁ X₂).surjective x simp @[simp] lemma prodEquiv_symm_apply_snd (x : ToType X₁ × ToType X₂) : (Limits.prod.snd : X₁ ⨯ X₂ ⟶ X₂) ((prodEquiv X₁ X₂).symm x) = x.2 := by obtain ⟨y, rfl⟩ := (prodEquiv X₁ X₂).surjective x simp end BinaryProducts section Pullbacks variable {FC : C → C → Type*} {CC : C → Type v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{v} C FC] variable {X₁ X₂ S : C} (f₁ : X₁ ⟶ S) (f₂ : X₂ ⟶ S) [HasPullback f₁ f₂] [PreservesLimit (cospan f₁ f₂) (forget C)] /-- In a concrete category `C`, given two morphisms `f₁ : X₁ ⟶ S` and `f₂ : X₂ ⟶ S`, the elements in `pullback f₁ f₁` can be identified to compatible tuples of elements in `X₁` and `X₂`. -/ noncomputable def pullbackEquiv : ToType (pullback f₁ f₂) ≃ { p : ToType X₁ × ToType X₂ // f₁ p.1 = f₂ p.2 } := (PreservesPullback.iso (forget C) f₁ f₂ ≪≫ Types.pullbackIsoPullback ⇑(ConcreteCategory.hom f₁) ⇑(ConcreteCategory.hom f₂)).toEquiv /-- Constructor for elements in a pullback in a concrete category. -/ noncomputable def pullbackMk (x₁ : ToType X₁) (x₂ : ToType X₂) (h : f₁ x₁ = f₂ x₂) : ToType (pullback f₁ f₂) := (pullbackEquiv f₁ f₂).symm ⟨⟨x₁, x₂⟩, h⟩ lemma pullbackMk_surjective (x : ToType (pullback f₁ f₂)) : ∃ (x₁ : ToType X₁) (x₂ : ToType X₂) (h : f₁ x₁ = f₂ x₂), x = pullbackMk f₁ f₂ x₁ x₂ h := by obtain ⟨⟨⟨x₁, x₂⟩, h⟩, rfl⟩ := (pullbackEquiv f₁ f₂).symm.surjective x exact ⟨x₁, x₂, h, rfl⟩ @[simp] lemma pullbackMk_fst (x₁ : ToType X₁) (x₂ : ToType X₂) (h : f₁ x₁ = f₂ x₂) : pullback.fst f₁ f₂ (pullbackMk f₁ f₂ x₁ x₂ h) = x₁ := (congr_fun (PreservesPullback.iso_inv_fst (forget C) f₁ f₂) _).trans (congr_fun (Types.pullbackIsoPullback_inv_fst ⇑(ConcreteCategory.hom f₁) ⇑(ConcreteCategory.hom f₂)) _) @[simp] lemma pullbackMk_snd (x₁ : ToType X₁) (x₂ : ToType X₂) (h : f₁ x₁ = f₂ x₂) : pullback.snd f₁ f₂ (pullbackMk f₁ f₂ x₁ x₂ h) = x₂ := (congr_fun (PreservesPullback.iso_inv_snd (forget C) f₁ f₂) _).trans (congr_fun (Types.pullbackIsoPullback_inv_snd ⇑(ConcreteCategory.hom f₁) ⇑(ConcreteCategory.hom f₂)) _) end Pullbacks section WidePullback variable {FC : C → C → Type*} {CC : C → Type (max v w)} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{max v w} C FC] open WidePullback open WidePullbackShape theorem widePullback_ext {B : C} {ι : Type w} {X : ι → C} (f : ∀ j : ι, X j ⟶ B) [HasWidePullback B X f] [PreservesLimit (wideCospan B X f) (forget C)] (x y : ToType (widePullback B X f)) (h₀ : base f x = base f y) (h : ∀ j, π f j x = π f j y) : x = y := by apply Concrete.limit_ext rintro (_ | j) · exact h₀ · apply h theorem widePullback_ext' {B : C} {ι : Type w} [Nonempty ι] {X : ι → C} (f : ∀ j : ι, X j ⟶ B) [HasWidePullback.{w} B X f] [PreservesLimit (wideCospan B X f) (forget C)] (x y : ToType (widePullback B X f)) (h : ∀ j, π f j x = π f j y) : x = y := by apply Concrete.widePullback_ext _ _ _ _ h inhabit ι simp only [← π_arrow f default, ConcreteCategory.comp_apply, h] end WidePullback section Multiequalizer variable {FC : C → C → Type*} {CC : C → Type s} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{s} C FC] theorem multiequalizer_ext {J : MulticospanShape.{w, w'}} {I : MulticospanIndex J C} [HasMultiequalizer I] [PreservesLimit I.multicospan (forget C)] (x y : ToType (multiequalizer I)) (h : ∀ t : J.L, Multiequalizer.ι I t x = Multiequalizer.ι I t y) : x = y := by apply Concrete.limit_ext rintro (a | b) · apply h · rw [← limit.w I.multicospan (WalkingMulticospan.Hom.fst b), ConcreteCategory.comp_apply, ConcreteCategory.comp_apply] simp [h] /-- An auxiliary equivalence to be used in `multiequalizerEquiv` below. -/ def multiequalizerEquivAux {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) : (I.multicospan ⋙ forget C).sections ≃ { x : ∀ i : J.L, ToType (I.left i) // ∀ i : J.R, I.fst i (x _) = I.snd i (x _) } where toFun x := ⟨fun _ => x.1 (WalkingMulticospan.left _), fun i => by have a := x.2 (WalkingMulticospan.Hom.fst i) have b := x.2 (WalkingMulticospan.Hom.snd i) rw [← b] at a exact a⟩ invFun x := { val := fun j => match j with | WalkingMulticospan.left _ => x.1 _ | WalkingMulticospan.right b => I.fst b (x.1 _) property := by rintro (a | b) (a' | b') (f | f | f) · simp · rfl · dsimp exact (x.2 b').symm · simp } left_inv := by intro x; ext (a | b) · rfl · rw [← x.2 (WalkingMulticospan.Hom.fst b)] rfl right_inv := by intro x ext i rfl /-- The equivalence between the noncomputable multiequalizer and the concrete multiequalizer. -/ noncomputable def multiequalizerEquiv {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) [HasMultiequalizer I] [PreservesLimit I.multicospan (forget C)] : ToType (multiequalizer I) ≃ { x : ∀ i : J.L, ToType (I.left i) // ∀ i : J.R, I.fst i (x _) = I.snd i (x _) } := letI h1 := limit.isLimit I.multicospan letI h2 := isLimitOfPreserves (forget C) h1 (Types.isLimitEquivSections h2).trans (Concrete.multiequalizerEquivAux I) @[simp] theorem multiequalizerEquiv_apply {J : MulticospanShape.{w, w'}} (I : MulticospanIndex J C) [HasMultiequalizer I] [PreservesLimit I.multicospan (forget C)] (x : ToType (multiequalizer I)) (i : J.L) : ((Concrete.multiequalizerEquiv I) x : ∀ i : J.L, ToType (I.left i)) i = Multiequalizer.ι I i x := rfl end Multiequalizer section WidePushout open WidePushout open WidePushoutShape variable {FC : C → C → Type*} {CC : C → Type v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory.{v} C FC] theorem widePushout_exists_rep {B : C} {α : Type _} {X : α → C} (f : ∀ j : α, B ⟶ X j) [HasWidePushout.{v} B X f] [PreservesColimit (wideSpan B X f) (forget C)] (x : ToType (widePushout B X f)) : (∃ y : ToType B, head f y = x) ∨ ∃ (i : α) (y : ToType (X i)), ι f i y = x := by obtain ⟨_ | j, y, rfl⟩ := Concrete.colimit_exists_rep _ x · left use y rfl · right use j, y rfl theorem widePushout_exists_rep' {B : C} {α : Type _} [Nonempty α] {X : α → C} (f : ∀ j : α, B ⟶ X j) [HasWidePushout.{v} B X f] [PreservesColimit (wideSpan B X f) (forget C)] (x : ToType (widePushout B X f)) : ∃ (i : α) (y : ToType (X i)), ι f i y = x := by rcases Concrete.widePushout_exists_rep f x with (⟨y, rfl⟩ | ⟨i, y, rfl⟩) · inhabit α use default, f _ y simp only [← arrow_ι _ default, ConcreteCategory.comp_apply] · use i, y end WidePushout attribute [local ext] ConcreteCategory.hom_ext in -- We don't mark this as an `@[ext]` lemma as we don't always want to work elementwise. theorem cokernel_funext {C : Type*} [Category C] [HasZeroMorphisms C] {FC : C → C → Type*} {CC : C → Type*} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC] {M N K : C} {f : M ⟶ N} [HasCokernel f] {g h : cokernel f ⟶ K} (w : ∀ n : ToType N, g (cokernel.π f n) = h (cokernel.π f n)) : g = h := by ext x simpa using w x -- TODO: Add analogous lemmas about coproducts and coequalizers. end CategoryTheory.Limits.Concrete
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/FiniteMultiequalizer.lean
import Mathlib.CategoryTheory.FinCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.Tactic.DeriveFintype /-! # Finiteness instances on multi-spans -/ namespace CategoryTheory.Limits namespace WalkingMulticospan variable {J : MulticospanShape} [Fintype J.L] [Fintype J.R] instance : Fintype (WalkingMulticospan J) := .ofEquiv _ (proxy_equiv% (WalkingMulticospan J)) instance [DecidableEq J.L] [DecidableEq J.R] : FinCategory (WalkingMulticospan J) where fintypeHom | .left a, .left b => ⟨if e : a = b then {eqToHom (e ▸ rfl)} else ∅, by rintro ⟨⟩; simp⟩ | .left a, .right b => ⟨⟨(if e : J.fst b = a then {eqToHom (e ▸ rfl) ≫ Hom.fst b} else 0) + (if e : J.snd b = a then {eqToHom (e ▸ rfl) ≫ Hom.snd b} else 0), by split_ifs with h₁ h₂ · simp only [Multiset.singleton_add, Multiset.nodup_cons, Multiset.mem_singleton, Multiset.nodup_singleton, and_true] let f : ((left a : WalkingMulticospan J) ⟶ right b) → Prop | .fst a => True | .snd a => False apply ne_of_apply_ne f conv_lhs => tactic => subst h₁; simp only [eqToHom_refl, Category.id_comp, f] conv_rhs => tactic => subst h₂; simp only [eqToHom_refl, Category.id_comp, f] simp all_goals simp⟩, by rintro ⟨⟩ <;> simp⟩ | .right a, .left b => ⟨∅, by rintro ⟨⟩⟩ | .right a, .right b => ⟨if e : a = b then {eqToHom (e ▸ rfl)} else ∅, by rintro ⟨⟩; simp⟩ end WalkingMulticospan namespace WalkingMultispan variable {J : MultispanShape} [Fintype J.L] [Fintype J.R] instance : Fintype (WalkingMultispan J) := .ofEquiv _ (proxy_equiv% (WalkingMultispan J)) instance [DecidableEq J.L] [DecidableEq J.R] : FinCategory (WalkingMultispan J) where fintypeHom | .left a, .left b => ⟨if e : a = b then {eqToHom (e ▸ rfl)} else ∅, by rintro ⟨⟩; simp⟩ | .left a, .right b => ⟨⟨(if e : J.fst a = b then {Hom.fst a ≫ eqToHom (e ▸ rfl)} else 0) + (if e : J.snd a = b then {Hom.snd a ≫ eqToHom (e ▸ rfl)} else 0), by split_ifs with h₁ h₂ · simp only [Multiset.singleton_add, Multiset.nodup_cons, Multiset.mem_singleton, Multiset.nodup_singleton, and_true] let f : ((left a : WalkingMultispan J) ⟶ right b) → Prop | .fst a => True | .snd a => False apply ne_of_apply_ne f conv_lhs => tactic => subst h₁; simp only [eqToHom_refl, f] conv_rhs => tactic => subst h₂; simp only [eqToHom_refl, f] simp all_goals simp⟩, by rintro ⟨⟩ <;> simp⟩ | .right a, .left b => ⟨∅, by rintro ⟨⟩⟩ | .right a, .right b => ⟨if e : a = b then {eqToHom (e ▸ rfl)} else ∅, by rintro ⟨⟩; simp⟩ end WalkingMultispan end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Countable.lean
import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Countable import Mathlib.Data.Countable.Defs /-! # Countable limits and colimits A typeclass for categories with all countable (co)limits. We also prove that all cofiltered limits over countable preorders are isomorphic to sequential limits, see `sequentialFunctor_initial`. ## Projects * There is a series of `proof_wanted` at the bottom of this file, implying that all cofiltered limits over countable categories are isomorphic to sequential limits. * Prove the dual result for filtered colimits. -/ open CategoryTheory Opposite CountableCategory variable (C : Type*) [Category C] (J : Type*) [Countable J] namespace CategoryTheory.Limits /-- A category has all countable limits if every functor `J ⥤ C` with a `CountableCategory J` instance and `J : Type` has a limit. -/ class HasCountableLimits : Prop where /-- `C` has all limits over any type `J` whose objects and morphisms lie in the same universe and which has countably many objects and morphisms -/ out (J : Type) [SmallCategory J] [CountableCategory J] : HasLimitsOfShape J C instance (priority := 100) hasFiniteLimits_of_hasCountableLimits [HasCountableLimits C] : HasFiniteLimits C where out J := HasCountableLimits.out J instance (priority := 100) hasCountableLimits_of_hasLimits [HasLimits C] : HasCountableLimits C where out := inferInstance universe v in instance [HasCountableLimits C] [Category.{v} J] [CountableCategory J] : HasLimitsOfShape J C := have : HasLimitsOfShape (HomAsType J) C := HasCountableLimits.out (HomAsType J) hasLimitsOfShape_of_equivalence (homAsTypeEquiv J) /-- A category has countable products if it has all products indexed by countable types. -/ class HasCountableProducts where out (J : Type) [Countable J] : HasProductsOfShape J C instance [HasCountableProducts C] (J : Type*) [Countable J] : HasProductsOfShape J C := have : Countable (Shrink.{0} J) := Countable.of_equiv _ (equivShrink.{0} J) have : HasLimitsOfShape (Discrete (Shrink.{0} J)) C := HasCountableProducts.out _ hasLimitsOfShape_of_equivalence (Discrete.equivalence (equivShrink.{0} J)).symm instance (priority := 100) hasCountableProducts_of_hasProducts [HasProducts C] : HasCountableProducts C where out _ := have : HasProducts.{0} C := has_smallest_products_of_hasProducts inferInstance instance (priority := 100) hasCountableProducts_of_hasCountableLimits [HasCountableLimits C] : HasCountableProducts C where out _ := inferInstance instance (priority := 100) hasFiniteProducts_of_hasCountableProducts [HasCountableProducts C] : HasFiniteProducts C where out _ := inferInstance /-- A category has all countable colimits if every functor `J ⥤ C` with a `CountableCategory J` instance and `J : Type` has a colimit. -/ class HasCountableColimits : Prop where /-- `C` has all limits over any type `J` whose objects and morphisms lie in the same universe and which has countably many objects and morphisms -/ out (J : Type) [SmallCategory J] [CountableCategory J] : HasColimitsOfShape J C instance (priority := 100) hasFiniteColimits_of_hasCountableColimits [HasCountableColimits C] : HasFiniteColimits C where out J := HasCountableColimits.out J instance (priority := 100) hasCountableColimits_of_hasColimits [HasColimits C] : HasCountableColimits C where out := inferInstance -- See note [instance argument order] universe v in instance [HasCountableColimits C] (J : Type*) [Category.{v} J] [CountableCategory J] : HasColimitsOfShape J C := have : HasColimitsOfShape (HomAsType J) C := HasCountableColimits.out (HomAsType J) hasColimitsOfShape_of_equivalence (homAsTypeEquiv J) /-- A category has countable coproducts if it has all coproducts indexed by countable types. -/ class HasCountableCoproducts where out (J : Type) [Countable J] : HasCoproductsOfShape J C instance (priority := 100) hasCountableCoproducts_of_hasCoproducts [HasCoproducts C] : HasCountableCoproducts C where out _ := have : HasCoproducts.{0} C := has_smallest_coproducts_of_hasCoproducts inferInstance -- See note [instance argument order] instance [HasCountableCoproducts C] (J : Type*) [Countable J] : HasCoproductsOfShape J C := have : Countable (Shrink.{0} J) := Countable.of_equiv _ (equivShrink.{0} J) have : HasColimitsOfShape (Discrete (Shrink.{0} J)) C := HasCountableCoproducts.out _ hasColimitsOfShape_of_equivalence (Discrete.equivalence (equivShrink.{0} J)).symm instance (priority := 100) hasCountableCoproducts_of_hasCountableColimits [HasCountableColimits C] : HasCountableCoproducts C where out _ := inferInstance instance (priority := 100) hasFiniteCoproducts_of_hasCountableCoproducts [HasCountableCoproducts C] : HasFiniteCoproducts C where out _ := inferInstance section Preorder namespace IsFiltered attribute [local instance] IsFiltered.nonempty variable {C} [Preorder J] [IsFiltered J] /-- The object part of the initial functor `ℕᵒᵖ ⥤ J` -/ noncomputable def sequentialFunctor_obj : ℕ → J := fun | .zero => (exists_surjective_nat _).choose 0 | .succ n => (IsFilteredOrEmpty.cocone_objs ((exists_surjective_nat _).choose n) (sequentialFunctor_obj n)).choose theorem sequentialFunctor_map : Monotone (sequentialFunctor_obj J) := monotone_nat_of_le_succ fun n ↦ leOfHom (IsFilteredOrEmpty.cocone_objs ((exists_surjective_nat _).choose n) (sequentialFunctor_obj J n)).choose_spec.choose_spec.choose /-- The initial functor `ℕᵒᵖ ⥤ J`, which allows us to turn cofiltered limits over countable preorders into sequential limits. -/ noncomputable def sequentialFunctor : ℕ ⥤ J where obj n := sequentialFunctor_obj J n map h := homOfLE (sequentialFunctor_map J (leOfHom h)) theorem sequentialFunctor_final_aux (j : J) : ∃ (n : ℕ), j ≤ sequentialFunctor_obj J n := by obtain ⟨m, h⟩ := (exists_surjective_nat _).choose_spec j refine ⟨m + 1, ?_⟩ simpa only [h] using leOfHom (IsFilteredOrEmpty.cocone_objs ((exists_surjective_nat _).choose m) (sequentialFunctor_obj J m)).choose_spec.choose instance sequentialFunctor_final : (sequentialFunctor J).Final where out d := by obtain ⟨n, (g : d ≤ (sequentialFunctor J).obj n)⟩ := sequentialFunctor_final_aux J d have : Nonempty (StructuredArrow d (sequentialFunctor J)) := ⟨StructuredArrow.mk (homOfLE g)⟩ apply isConnected_of_zigzag refine fun i j ↦ ⟨[j], ?_⟩ simp only [List.isChain_cons_cons, Zag, List.isChain_singleton, and_true, ne_eq, not_false_eq_true, List.getLast_cons, List.getLast_singleton', reduceCtorEq] clear! C wlog h : j.right ≤ i.right · exact or_comm.1 (this J d n g inferInstance j i (le_of_lt (not_le.mp h))) · right exact ⟨StructuredArrow.homMk (homOfLE h) rfl⟩ end IsFiltered namespace IsCofiltered attribute [local instance] IsCofiltered.nonempty variable {C} [Preorder J] [IsCofiltered J] /-- The object part of the initial functor `ℕᵒᵖ ⥤ J` -/ noncomputable def sequentialFunctor_obj : ℕ → J := fun | .zero => (exists_surjective_nat _).choose 0 | .succ n => (IsCofilteredOrEmpty.cone_objs ((exists_surjective_nat _).choose n) (sequentialFunctor_obj n)).choose theorem sequentialFunctor_map : Antitone (sequentialFunctor_obj J) := antitone_nat_of_succ_le fun n ↦ leOfHom (IsCofilteredOrEmpty.cone_objs ((exists_surjective_nat _).choose n) (sequentialFunctor_obj J n)).choose_spec.choose_spec.choose /-- The initial functor `ℕᵒᵖ ⥤ J`, which allows us to turn cofiltered limits over countable preorders into sequential limits. TODO: redefine this as `(IsFiltered.sequentialFunctor Jᵒᵖ).leftOp`. This would need API for initial/ final functors of the form `leftOp`/`rightOp`. -/ noncomputable def sequentialFunctor : ℕᵒᵖ ⥤ J where obj n := sequentialFunctor_obj J (unop n) map h := homOfLE (sequentialFunctor_map J (leOfHom h.unop)) theorem sequentialFunctor_initial_aux (j : J) : ∃ (n : ℕ), sequentialFunctor_obj J n ≤ j := by obtain ⟨m, h⟩ := (exists_surjective_nat _).choose_spec j refine ⟨m + 1, ?_⟩ simpa only [h] using leOfHom (IsCofilteredOrEmpty.cone_objs ((exists_surjective_nat _).choose m) (sequentialFunctor_obj J m)).choose_spec.choose instance sequentialFunctor_initial : (sequentialFunctor J).Initial where out d := by obtain ⟨n, (g : (sequentialFunctor J).obj ⟨n⟩ ≤ d)⟩ := sequentialFunctor_initial_aux J d have : Nonempty (CostructuredArrow (sequentialFunctor J) d) := ⟨CostructuredArrow.mk (homOfLE g)⟩ apply isConnected_of_zigzag refine fun i j ↦ ⟨[j], ?_⟩ simp only [List.isChain_cons_cons, Zag, List.isChain_singleton, and_true, ne_eq, not_false_eq_true, List.getLast_cons, List.getLast_singleton', reduceCtorEq] clear! C wlog h : (unop i.left) ≤ (unop j.left) · exact or_comm.1 (this J d n g inferInstance j i (le_of_lt (not_le.mp h))) · right exact ⟨CostructuredArrow.homMk (homOfLE h).op rfl⟩ @[stacks 0032] proof_wanted preorder_of_cofiltered (J : Type*) [Category J] [IsCofiltered J] : ∃ (I : Type*) (_ : Preorder I) (_ : IsCofiltered I) (F : I ⥤ J), F.Initial /-- The proof of `preorder_of_cofiltered` should give a countable `I` in the case that `J` is a countable category. -/ proof_wanted preorder_of_cofiltered_countable (J : Type*) [SmallCategory J] [IsCofiltered J] [CountableCategory J] : ∃ (I : Type) (_ : Preorder I) (_ : Countable I) (_ : IsCofiltered I) (F : I ⥤ J), F.Initial /-- Put together `sequentialFunctor_initial` and `preorder_of_cofiltered_countable`. -/ proof_wanted hasCofilteredCountableLimits_of_hasSequentialLimits [HasLimitsOfShape ℕᵒᵖ C] : ∀ (J : Type) [SmallCategory J] [IsCofiltered J] [CountableCategory J], HasLimitsOfShape J C /-- This is the countable version of `CategoryTheory.Limits.has_limits_of_finite_and_cofiltered`, given all of the above. -/ proof_wanted hasCountableLimits_of_hasFiniteLimits_and_hasSequentialLimits [HasFiniteLimits C] [HasLimitsOfShape ℕᵒᵖ C] : HasCountableLimits C /-- For this we need to dualize this whole section. -/ proof_wanted hasCountableColimits_of_hasFiniteColimits_and_hasSequentialColimits [HasFiniteColimits C] [HasLimitsOfShape ℕ C] : HasCountableColimits C end IsCofiltered end Preorder end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Preorder/Fin.lean
import Mathlib.CategoryTheory.Limits.Shapes.IsTerminal import Mathlib.Order.Fin.Basic /-! # Limits and colimits indexed by `Fin` In this file, we show that `0 : Fin (n + 1)` is an initial object and `Fin.last n` is a terminal object. This allows to compute limits and colimits indexed by `Fin (n + 1)`, see `limitOfDiagramInitial` and `colimitOfDiagramTerminal` in the file `Limits.Shapes.IsTerminal`. -/ universe v v' u u' w open CategoryTheory Limits namespace Fin variable (n : ℕ) /-- `0` is an initial object in `Fin n` when `n ≠ 0`. -/ def isInitialZero [NeZero n] : IsInitial (0 : Fin n) := isInitialBot /-- `Fin.last n` is a terminal object in `Fin (n + 1)`. -/ def isTerminalLast : IsTerminal (Fin.last n) := isTerminalTop end Fin