source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Preorder/PrincipalSeg.lean
import Mathlib.Order.InitialSeg import Mathlib.CategoryTheory.Category.Preorder import Mathlib.CategoryTheory.Limits.Cones /-! # Cocones associated to principal segments If `f : α <i β` is a principal segment and `F : β ⥤ C`, there is a cocone for `f.monotone.functor ⋙ F : α ⥤ C` the point of which is `F.obj f.top`. -/ open CategoryTheory Category Limits /-- When `f : α <i β` and a functor `F : β ⥤ C`, this is the cocone for `f.monotone.functor ⋙ F : α ⥤ C` whose point if `F.obj f.top`. -/ @[simps] def PrincipalSeg.cocone {α β : Type*} [PartialOrder α] [PartialOrder β] (f : α <i β) {C : Type*} [Category C] (F : β ⥤ C) : Cocone (f.monotone.functor ⋙ F) where pt := F.obj f.top ι := { app i := F.map (homOfLE (f.lt_top i).le) naturality i j f := by dsimp rw [← F.map_comp, comp_id] rfl }
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Preorder/Basic.lean
import Mathlib.CategoryTheory.Limits.Preorder /-! # Limits and colimits indexed by preorders In this file, we obtain the following very basic results about limits and colimits indexed by a preordered type `J`: * a least element in `J` implies the existence of all limits indexed by `J` * a greatest element in `J` implies the existence of all colimits indexed by `J` -/ universe v v' u u' w open CategoryTheory Limits variable (C : Type u) [Category.{v} C] (J : Type w) [Preorder J] namespace Preorder section OrderBot variable [OrderBot J] instance : HasLimitsOfShape J C := ⟨fun _ ↦ by infer_instance⟩ end OrderBot section OrderTop variable [OrderTop J] instance : HasColimitsOfShape J C := ⟨fun _ ↦ by infer_instance⟩ end OrderTop end Preorder
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Preorder/TransfiniteCompositionOfShape.lean
import Mathlib.CategoryTheory.ComposableArrows.Basic import Mathlib.CategoryTheory.Limits.Shapes.Preorder.WellOrderContinuous import Mathlib.CategoryTheory.Limits.Shapes.Preorder.Fin import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Filtered.Final import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Preorder import Mathlib.Data.Fin.SuccPredOrder import Mathlib.Order.LatticeIntervals import Mathlib.Order.Interval.Set.Final /-! # A structure to describe transfinite compositions Given a well-ordered type `J` and a morphism `f : X ⟶ Y` in a category, we introduce a structure `TransfiniteCompositionOfShape J f` expressing that `f` is a transfinite composition of shape `J`. This allows to extend this structure in order to require more properties or data for the morphisms `F.obj j ⟶ F.obj (Order.succ j)` which appear in the transfinite composition. See `MorphismProperty.TransfiniteCompositionOfShape` in the file `MorphismProperty.TransfiniteComposition`. -/ universe w w' v v' u u' namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] (J : Type w) [LinearOrder J] [OrderBot J] {X Y : C} (f : X ⟶ Y) /-- Given a well-ordered type `J`, a morphism `f : X ⟶ Y` in a category `C` is a transfinite composition of shape `J` if we have a well order continuous functor `F : J ⥤ C`, an isomorphism `F.obj ⊥ ≅ X`, a colimit cocone for `F` whose point is `Y`, such that the composition `X ⟶ F.obj ⊥ ⟶ Y` is `f`. -/ structure TransfiniteCompositionOfShape [SuccOrder J] [WellFoundedLT J] where /-- a well order continuous functor `F : J ⥤ C` -/ F : J ⥤ C /-- the isomorphism `F.obj ⊥ ≅ X` -/ isoBot : F.obj ⊥ ≅ X isWellOrderContinuous : F.IsWellOrderContinuous := by infer_instance /-- the natural morphism `F.obj j ⟶ Y` -/ incl : F ⟶ (Functor.const _).obj Y /-- the colimit of `F` identifies to `Y` -/ isColimit : IsColimit (Cocone.mk Y incl) fac : isoBot.inv ≫ incl.app ⊥ = f := by cat_disch namespace TransfiniteCompositionOfShape attribute [reassoc (attr := simp)] fac attribute [instance] isWellOrderContinuous variable {J f} [SuccOrder J] [WellFoundedLT J] (c : TransfiniteCompositionOfShape J f) /-- If `f` and `f'` are two isomorphic morphisms, and `f` is a transfinite composition of shape `J`, then `f'` also is. -/ @[simps] def ofArrowIso {X' Y' : C} {f' : X' ⟶ Y'} (e : Arrow.mk f ≅ Arrow.mk f') : TransfiniteCompositionOfShape J f' where F := c.F isoBot := c.isoBot ≪≫ Arrow.leftFunc.mapIso e incl := c.incl ≫ (Functor.const J).map e.hom.right isColimit := IsColimit.ofIsoColimit c.isColimit (Cocones.ext (Arrow.rightFunc.mapIso e)) /-- If `G : ComposableArrows C n`, then `G.hom : G.left ⟶ G.right` is a transfinite composition of shape `Fin (n + 1)`. -/ @[simps] def ofComposableArrows {n : ℕ} (G : ComposableArrows C n) : TransfiniteCompositionOfShape (Fin (n + 1)) G.hom where F := G isoBot := Iso.refl _ incl := _ isColimit := colimitOfDiagramTerminal (Fin.isTerminalLast n) G fac := Category.id_comp _ /-- If `f` is a transfinite composition of shape `J`, then it is also a transfinite composition of shape `J'` if `J' ≃o J`. -/ @[simps] def ofOrderIso {J' : Type w'} [LinearOrder J'] [OrderBot J'] [SuccOrder J'] [WellFoundedLT J'] (e : J' ≃o J) : TransfiniteCompositionOfShape J' f where F := e.equivalence.functor ⋙ c.F isoBot := c.F.mapIso (eqToIso e.map_bot) ≪≫ c.isoBot incl := Functor.whiskerLeft e.equivalence.functor c.incl isColimit := IsColimit.whiskerEquivalence (c.isColimit) e.equivalence /-- If `f` is a transfinite composition of shape `J`, then `F.map f` also is provided `F` preserves suitable colimits. -/ @[simps] noncomputable def map (F : C ⥤ D) [PreservesWellOrderContinuousOfShape J F] [PreservesColimitsOfShape J F] : TransfiniteCompositionOfShape J (F.map f) where F := c.F ⋙ F isoBot := F.mapIso c.isoBot incl := Functor.whiskerRight c.incl F ≫ (Functor.constComp _ _ _).hom isColimit := IsColimit.ofIsoColimit (isColimitOfPreserves F c.isColimit) (Cocones.ext (Iso.refl _)) fac := by simp [← Functor.map_comp] /-- A transfinite composition of shape `J` induces a transfinite composition of shape `Set.Iic j` for any `j : J`. -/ @[simps] noncomputable def iic (j : J) : TransfiniteCompositionOfShape (Set.Iic j) (c.F.map (homOfLE bot_le : ⊥ ⟶ j)) where F := (Set.initialSegIic j).monotone.functor ⋙ c.F isoBot := Iso.refl _ incl := { app i := c.F.map (homOfLE i.2) naturality i i' φ := by dsimp rw [← Functor.map_comp, Category.comp_id] rfl } isColimit := colimitOfDiagramTerminal isTerminalTop _ /-- A transfinite composition of shape `J` induces a transfinite composition of shape `Set.Ici j` for any `j : J`. -/ @[simps] noncomputable def ici (j : J) : TransfiniteCompositionOfShape (Set.Ici j) (c.incl.app j) where F := (Subtype.mono_coe (Set.Ici j)).functor ⋙ c.F isWellOrderContinuous := Functor.IsWellOrderContinuous.restriction_setIci _ isoBot := Iso.refl _ incl := Functor.whiskerLeft _ c.incl isColimit := (Functor.Final.isColimitWhiskerEquiv ((Subtype.mono_coe (Set.Ici j)).functor) _).2 c.isColimit end TransfiniteCompositionOfShape end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Preorder/HasIterationOfShape.lean
import Mathlib.CategoryTheory.Limits.Comma import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Preorder.Basic import Mathlib.Order.SuccPred.Limit import Mathlib.Order.Interval.Set.InitialSeg /-! # An assumption for constructions by transfinite induction In this file, we introduce the typeclass `HasIterationOfShape J C` which is an assumption in order to do constructions by transfinite induction indexed by a well-ordered type `J` in a category `C` (see `CategoryTheory.SmallObject`). -/ universe w v v' u u' namespace CategoryTheory.Limits variable (J : Type w) [LinearOrder J] (C : Type u) [Category.{v} C] (K : Type u') [Category.{v'} K] /-- A category `C` has iterations of shape a linearly ordered type `J` when certain specific shapes of colimits exists: colimits indexed by `J`, and by `Set.Iio j` for `j : J`. -/ class HasIterationOfShape : Prop where hasColimitsOfShape_of_isSuccLimit (j : J) (hj : Order.IsSuccLimit j) : HasColimitsOfShape (Set.Iio j) C := by infer_instance hasColimitsOfShape : HasColimitsOfShape J C := by infer_instance attribute [instance] HasIterationOfShape.hasColimitsOfShape instance [HasColimitsOfSize.{w, w} C] : HasIterationOfShape J C where variable [HasIterationOfShape J C] variable {J} in lemma hasColimitsOfShape_of_isSuccLimit (j : J) (hj : Order.IsSuccLimit j) : HasColimitsOfShape (Set.Iio j) C := HasIterationOfShape.hasColimitsOfShape_of_isSuccLimit j hj variable {J} in lemma hasColimitsOfShape_of_isSuccLimit' {α : Type*} [PartialOrder α] (h : α <i J) (hα : Order.IsSuccLimit h.top) : HasColimitsOfShape α C := by have := hasColimitsOfShape_of_isSuccLimit C h.top hα exact hasColimitsOfShape_of_equivalence h.orderIsoIio.equivalence.symm instance : HasIterationOfShape J (Arrow C) where hasColimitsOfShape_of_isSuccLimit j hj := by have := hasColimitsOfShape_of_isSuccLimit C j hj infer_instance instance : HasIterationOfShape J (K ⥤ C) where hasColimitsOfShape_of_isSuccLimit j hj := by have := hasColimitsOfShape_of_isSuccLimit C j hj infer_instance variable {J} [SuccOrder J] [WellFoundedLT J] lemma hasColimitsOfShape_of_initialSeg {α : Type*} [PartialOrder α] (f : α ≤i J) [Nonempty α] : HasColimitsOfShape α C := by by_cases hf : Function.Surjective f · exact hasColimitsOfShape_of_equivalence (OrderIso.ofRelIsoLT (RelIso.ofSurjective f.toRelEmbedding hf)).equivalence.symm · let s := f.toPrincipalSeg hf obtain ⟨i, hi₀⟩ : ∃ i, i = s.top := ⟨_, rfl⟩ induction i using SuccOrder.limitRecOn with | isMin i hi => subst hi₀ exact (hi.not_lt (s.lt_top (Classical.arbitrary _))).elim | succ i hi _ => obtain ⟨a, rfl⟩ := (s.mem_range_iff_rel (b := i)).2 (by simpa only [← hi₀] using Order.lt_succ_of_not_isMax hi) have : OrderTop α := { top := a le_top b := by rw [← s.le_iff_le] exact Order.le_of_lt_succ (by simpa only [hi₀] using s.lt_top b) } infer_instance | isSuccLimit i hi => subst hi₀ exact hasColimitsOfShape_of_isSuccLimit' C s hi lemma hasIterationOfShape_of_initialSeg {α : Type*} [LinearOrder α] (h : α ≤i J) [Nonempty α] : HasIterationOfShape α C where hasColimitsOfShape := hasColimitsOfShape_of_initialSeg C h hasColimitsOfShape_of_isSuccLimit j hj := by have := hj.nonempty_Iio.to_subtype exact hasColimitsOfShape_of_initialSeg _ (InitialSeg.trans (Set.principalSegIio j) h) instance (j : J) : HasIterationOfShape (Set.Iic j) C := hasIterationOfShape_of_initialSeg C (Set.initialSegIic j) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Preorder/WellOrderContinuous.lean
import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Limits.Shapes.Preorder.PrincipalSeg import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Filtered.Final import Mathlib.Data.Nat.SuccPred import Mathlib.Data.Fin.SuccPredOrder import Mathlib.Order.Interval.Set.InitialSeg import Mathlib.Order.Interval.Set.Limit import Mathlib.Order.SuccPred.InitialSeg import Mathlib.Order.SuccPred.Limit import Mathlib.Order.SuccPred.LinearLocallyFinite /-! # Continuity of functors from well-ordered types Let `F : J ⥤ C` be functor from a well-ordered type `J`. We introduce the typeclass `F.IsWellOrderContinuous` to say that if `m` is a limit element, then `F.obj m` is the colimit of the `F.obj j` for `j < m`. -/ universe w w' v u namespace CategoryTheory.Functor open Category Limits variable {C : Type u} [Category.{v} C] {J : Type w} [PartialOrder J] /-- A functor `F : J ⥤ C` is well-order-continuous if for any limit element `m : J`, `F.obj m` identifies to the colimit of the `F.obj j` for `j < m`. -/ class IsWellOrderContinuous (F : J ⥤ C) : Prop where nonempty_isColimit (m : J) (hm : Order.IsSuccLimit m) : Nonempty (IsColimit ((Set.principalSegIio m).cocone F)) /-- If `F : J ⥤ C` is well-order-continuous and `m : J` is a limit element, then `F.obj m` identifies to the colimit of the `F.obj j` for `j < m`. -/ noncomputable def isColimitOfIsWellOrderContinuous (F : J ⥤ C) [F.IsWellOrderContinuous] (m : J) (hm : Order.IsSuccLimit m) : IsColimit ((Set.principalSegIio m).cocone F) := (IsWellOrderContinuous.nonempty_isColimit m hm).some /-- If `F : J ⥤ C` is well-order-continuous and `h : α <i J` is a principal segment such that `h.top` is a limit element, then `F.obj h.top` identifies to the colimit of the `F.obj j` for `j : α`. -/ noncomputable def isColimitOfIsWellOrderContinuous' (F : J ⥤ C) [F.IsWellOrderContinuous] {α : Type*} [PartialOrder α] (f : α <i J) (hα : Order.IsSuccLimit f.top) : IsColimit (f.cocone F) := (F.isColimitOfIsWellOrderContinuous f.top hα).whiskerEquivalence f.orderIsoIio.equivalence instance (F : ℕ ⥤ C) : F.IsWellOrderContinuous where nonempty_isColimit m hm := by simp at hm instance {n : ℕ} (F : Fin n ⥤ C) : F.IsWellOrderContinuous where nonempty_isColimit _ hj := (Order.not_isSuccLimit hj).elim lemma isWellOrderContinuous_of_iso {F G : J ⥤ C} (e : F ≅ G) [F.IsWellOrderContinuous] : G.IsWellOrderContinuous where nonempty_isColimit (m : J) (hm : Order.IsSuccLimit m) := ⟨(IsColimit.precomposeHomEquiv (isoWhiskerLeft _ e) _).1 (IsColimit.ofIsoColimit (F.isColimitOfIsWellOrderContinuous m hm) (Cocones.ext (e.app _)))⟩ instance (F : J ⥤ C) {J' : Type w'} [PartialOrder J'] (f : J' ≤i J) [F.IsWellOrderContinuous] : (f.monotone.functor ⋙ F).IsWellOrderContinuous where nonempty_isColimit m' hm' := ⟨F.isColimitOfIsWellOrderContinuous' ((Set.principalSegIio m').transInitial f) (by simpa)⟩ instance (F : J ⥤ C) {J' : Type w'} [PartialOrder J'] (e : J' ≃o J) [F.IsWellOrderContinuous] : (e.equivalence.functor ⋙ F).IsWellOrderContinuous := inferInstanceAs (e.toInitialSeg.monotone.functor ⋙ F).IsWellOrderContinuous instance IsWellOrderContinuous.restriction_setIci {J : Type w} [LinearOrder J] {F : J ⥤ C} [F.IsWellOrderContinuous] (j : J) : ((Subtype.mono_coe (Set.Ici j)).functor ⋙ F).IsWellOrderContinuous where nonempty_isColimit m hm := ⟨by let f : Set.Iio m → Set.Iio m.1 := fun ⟨⟨a, ha⟩, ha'⟩ ↦ ⟨a, ha'⟩ have hf : Monotone f := fun _ _ h ↦ h have : hf.functor.Final := by rw [Monotone.final_functor_iff] rintro ⟨j', hj'⟩ simp only [Set.mem_Iio] at hj' dsimp only [f] by_cases! h : j' ≤ j · refine ⟨⟨⟨j, le_refl j⟩, ?_⟩, h⟩ by_contra! simp only [Set.mem_Iio, not_lt] at this apply hm.1 rintro ⟨k, hk⟩ hkm exact this.trans hk · exact ⟨⟨⟨j', h.le⟩, hj'⟩, by rfl⟩ exact (Functor.Final.isColimitWhiskerEquiv (F := hf.functor) _).2 (F.isColimitOfIsWellOrderContinuous m.1 (Set.Ici.isSuccLimit_coe m hm))⟩ end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/NormalMono/Basic.lean
import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Definitions and basic properties of normal monomorphisms and epimorphisms. A normal monomorphism is a morphism that is the kernel of some other morphism. We give the construction `NormalMono → RegularMono` (`CategoryTheory.NormalMono.regularMono`) as well as the dual construction for normal epimorphisms. We show equivalences reflect normal monomorphisms (`CategoryTheory.equivalenceReflectsNormalMono`), and that the pullback of a normal monomorphism is normal (`CategoryTheory.normalOfIsPullbackSndOfNormal`). We also define classes `IsNormalMonoCategory` and `IsNormalEpiCategory` for categories in which every monomorphism or epimorphism is normal, and deduce that these categories are `RegularMonoCategory`s resp. `RegularEpiCategory`s. -/ noncomputable section namespace CategoryTheory open CategoryTheory.Limits universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] variable {X Y : C} section variable [HasZeroMorphisms C] /-- A normal monomorphism is a morphism which is the kernel of some morphism. -/ class NormalMono (f : X ⟶ Y) where Z : C g : Y ⟶ Z w : f ≫ g = 0 isLimit : IsLimit (KernelFork.ofι f w) attribute [inherit_doc NormalMono] NormalMono.Z NormalMono.g NormalMono.w NormalMono.isLimit section /-- If `F` is an equivalence and `F.map f` is a normal mono, then `f` is a normal mono. -/ def equivalenceReflectsNormalMono {D : Type u₂} [Category.{v₁} D] [HasZeroMorphisms D] (F : C ⥤ D) [F.IsEquivalence] {X Y : C} {f : X ⟶ Y} (hf : NormalMono (F.map f)) : NormalMono f where Z := F.objPreimage hf.Z g := F.preimage (hf.g ≫ (F.objObjPreimageIso hf.Z).inv) w := F.map_injective <| by have reassoc' {W : D} (h : hf.Z ⟶ W) : F.map f ≫ hf.g ≫ h = 0 ≫ h := by rw [← Category.assoc, eq_whisker hf.w] simp [reassoc'] isLimit := isLimitOfReflects F <| IsLimit.ofConeEquiv (Cones.postcomposeEquivalence (compNatIso F)) <| (IsLimit.ofIsoLimit (IsKernel.ofCompIso _ _ (F.objObjPreimageIso hf.Z) (by simp only [Functor.map_preimage, Category.assoc, Iso.inv_hom_id, Category.comp_id]) hf.isLimit)) (Fork.ext (Iso.refl _) (by simp [compNatIso, Fork.ι])) end /-- Every normal monomorphism is a regular monomorphism. -/ instance (priority := 100) NormalMono.regularMono (f : X ⟶ Y) [I : NormalMono f] : RegularMono f := { I with left := I.g right := 0 w := by simpa using I.w } /-- If `f` is a normal mono, then any map `k : W ⟶ Y` such that `k ≫ normal_mono.g = 0` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def NormalMono.lift' {W : C} (f : X ⟶ Y) [hf : NormalMono f] (k : W ⟶ Y) (h : k ≫ hf.g = 0) : { l : W ⟶ X // l ≫ f = k } := KernelFork.IsLimit.lift' NormalMono.isLimit _ h /-- The second leg of a pullback cone is a normal monomorphism if the right component is too. See also `pullback.sndOfMono` for the basic monomorphism version, and `normalOfIsPullbackFstOfNormal` for the flipped version. -/ def normalOfIsPullbackSndOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [hn : NormalMono h] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : NormalMono g where Z := hn.Z g := k ≫ hn.g w := by have reassoc' {W : C} (h' : S ⟶ W) : f ≫ h ≫ h' = g ≫ k ≫ h' := by simp only [← Category.assoc, eq_whisker comm] rw [← reassoc', hn.w, HasZeroMorphisms.comp_zero] isLimit := by letI gr := regularOfIsPullbackSndOfRegular comm t have q := (HasZeroMorphisms.comp_zero k hn.Z).symm convert gr.isLimit /-- The first leg of a pullback cone is a normal monomorphism if the left component is too. See also `pullback.fstOfMono` for the basic monomorphism version, and `normalOfIsPullbackSndOfNormal` for the flipped version. -/ def normalOfIsPullbackFstOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [NormalMono k] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : NormalMono f := normalOfIsPullbackSndOfNormal comm.symm (PullbackCone.flipIsLimit t) section variable (C) /-- A normal mono category is a category in which every monomorphism is normal. -/ class IsNormalMonoCategory : Prop where normalMonoOfMono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], Nonempty (NormalMono f) attribute [inherit_doc IsNormalMonoCategory] IsNormalMonoCategory.normalMonoOfMono end /-- In a category in which every monomorphism is normal, we can express every monomorphism as a kernel. This is not an instance because it would create an instance loop. -/ def normalMonoOfMono [IsNormalMonoCategory C] (f : X ⟶ Y) [Mono f] : NormalMono f := (IsNormalMonoCategory.normalMonoOfMono _).some instance (priority := 100) regularMonoCategoryOfNormalMonoCategory [IsNormalMonoCategory C] : IsRegularMonoCategory C where regularMonoOfMono f _ := ⟨by haveI := normalMonoOfMono f infer_instance⟩ end section variable [HasZeroMorphisms C] /-- A normal epimorphism is a morphism which is the cokernel of some morphism. -/ class NormalEpi (f : X ⟶ Y) where W : C g : W ⟶ X w : g ≫ f = 0 isColimit : IsColimit (CokernelCofork.ofπ f w) attribute [inherit_doc NormalEpi] NormalEpi.W NormalEpi.g NormalEpi.w NormalEpi.isColimit section /-- If `F` is an equivalence and `F.map f` is a normal epi, then `f` is a normal epi. -/ def equivalenceReflectsNormalEpi {D : Type u₂} [Category.{v₁} D] [HasZeroMorphisms D] (F : C ⥤ D) [F.IsEquivalence] {X Y : C} {f : X ⟶ Y} (hf : NormalEpi (F.map f)) : NormalEpi f where W := F.objPreimage hf.W g := F.preimage ((F.objObjPreimageIso hf.W).hom ≫ hf.g) w := F.map_injective <| by simp [hf.w] isColimit := isColimitOfReflects F <| IsColimit.ofCoconeEquiv (Cocones.precomposeEquivalence (compNatIso F).symm) <| (IsColimit.ofIsoColimit (IsCokernel.ofIsoComp _ _ (F.objObjPreimageIso hf.W).symm (by simp) hf.isColimit) (Cofork.ext (Iso.refl _) (by simp [compNatIso, Cofork.π]))) end /-- Every normal epimorphism is a regular epimorphism. -/ instance (priority := 100) NormalEpi.regularEpi (f : X ⟶ Y) [I : NormalEpi f] : RegularEpi f := { I with left := I.g right := 0 w := by simpa using I.w } /-- If `f` is a normal epi, then every morphism `k : X ⟶ W` satisfying `NormalEpi.g ≫ k = 0` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def NormalEpi.desc' {W : C} (f : X ⟶ Y) [nef : NormalEpi f] (k : X ⟶ W) (h : nef.g ≫ k = 0) : { l : Y ⟶ W // f ≫ l = k } := CokernelCofork.IsColimit.desc' NormalEpi.isColimit _ h /-- The second leg of a pushout cocone is a normal epimorphism if the right component is too. See also `pushout.sndOfEpi` for the basic epimorphism version, and `normalOfIsPushoutFstOfNormal` for the flipped version. -/ def normalOfIsPushoutSndOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [gn : NormalEpi g] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : NormalEpi h where W := gn.W g := gn.g ≫ f w := by have reassoc' {W : C} (h' : R ⟶ W) : gn.g ≫ g ≫ h' = 0 ≫ h' := by rw [← Category.assoc, eq_whisker gn.w] rw [Category.assoc, comm, reassoc', zero_comp] isColimit := by letI hn := regularOfIsPushoutSndOfRegular comm t have q := (@zero_comp _ _ _ gn.W _ _ f).symm convert hn.isColimit /-- The first leg of a pushout cocone is a normal epimorphism if the left component is too. See also `pushout.fstOfEpi` for the basic epimorphism version, and `normalOfIsPushoutSndOfNormal` for the flipped version. -/ def normalOfIsPushoutFstOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [NormalEpi f] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : NormalEpi k := normalOfIsPushoutSndOfNormal comm.symm (PushoutCocone.flipIsColimit t) end open Opposite variable [HasZeroMorphisms C] /-- A normal mono becomes a normal epi in the opposite category. -/ def normalEpiOfNormalMonoUnop {X Y : Cᵒᵖ} (f : X ⟶ Y) (m : NormalMono f.unop) : NormalEpi f where W := op m.Z g := m.g.op w := congrArg Quiver.Hom.op m.w isColimit := CokernelCofork.IsColimit.ofπ _ _ (fun g' w' => (KernelFork.IsLimit.lift' m.isLimit g'.unop (congrArg Quiver.Hom.unop w')).1.op) (fun g' w' => congrArg Quiver.Hom.op (KernelFork.IsLimit.lift' m.isLimit g'.unop (congrArg Quiver.Hom.unop w')).2) (by rintro Z' g' w' m' rfl apply Quiver.Hom.unop_inj apply m.isLimit.uniq (KernelFork.ofι (m'.unop ≫ f.unop) _) m'.unop rintro (⟨⟩ | ⟨⟩) <;> simp) /-- A normal epi becomes a normal mono in the opposite category. -/ def normalMonoOfNormalEpiUnop {X Y : Cᵒᵖ} (f : X ⟶ Y) (m : NormalEpi f.unop) : NormalMono f where Z := op m.W g := m.g.op w := congrArg Quiver.Hom.op m.w isLimit := KernelFork.IsLimit.ofι _ _ (fun g' w' => (CokernelCofork.IsColimit.desc' m.isColimit g'.unop (congrArg Quiver.Hom.unop w')).1.op) (fun g' w' => congrArg Quiver.Hom.op (CokernelCofork.IsColimit.desc' m.isColimit g'.unop (congrArg Quiver.Hom.unop w')).2) (by rintro Z' g' w' m' rfl apply Quiver.Hom.unop_inj apply m.isColimit.uniq (CokernelCofork.ofπ (f.unop ≫ m'.unop) _) m'.unop rintro (⟨⟩ | ⟨⟩) <;> simp) section variable (C) /-- A normal epi category is a category in which every epimorphism is normal. -/ class IsNormalEpiCategory : Prop where normalEpiOfEpi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], Nonempty (NormalEpi f) attribute [inherit_doc IsNormalEpiCategory] IsNormalEpiCategory.normalEpiOfEpi end /-- In a category in which every epimorphism is normal, we can express every epimorphism as a kernel. This is not an instance because it would create an instance loop. -/ def normalEpiOfEpi [IsNormalEpiCategory C] (f : X ⟶ Y) [Epi f] : NormalEpi f := (IsNormalEpiCategory.normalEpiOfEpi _).some instance (priority := 100) regularEpiCategoryOfNormalEpiCategory [IsNormalEpiCategory C] : IsRegularEpiCategory C where regularEpiOfEpi f _ := ⟨by haveI := normalEpiOfEpi f infer_instance⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/NormalMono/Equalizers.lean
import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Basic import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Normal mono categories with finite products and kernels have all equalizers. This, and the dual result, are used in the development of abelian categories. -/ noncomputable section open CategoryTheory open CategoryTheory.Limits variable {C : Type*} [Category C] [HasZeroMorphisms C] namespace CategoryTheory.NormalMonoCategory variable [HasFiniteProducts C] [HasKernels C] [IsNormalMonoCategory C] /-- The pullback of two monomorphisms exists. -/ lemma pullback_of_mono {X Y Z : C} (a : X ⟶ Z) (b : Y ⟶ Z) [Mono a] [Mono b] : HasLimit (cospan a b) := let ⟨P, f, haf, i⟩ := normalMonoOfMono a let ⟨Q, g, hbg, i'⟩ := normalMonoOfMono b let ⟨a', ha'⟩ := KernelFork.IsLimit.lift' i (kernel.ι (prod.lift f g)) <| calc kernel.ι (prod.lift f g) ≫ f _ = kernel.ι (prod.lift f g) ≫ prod.lift f g ≫ Limits.prod.fst := by rw [prod.lift_fst] _ = (0 : kernel (prod.lift f g) ⟶ P ⨯ Q) ≫ Limits.prod.fst := by rw [kernel.condition_assoc] _ = 0 := zero_comp let ⟨b', hb'⟩ := KernelFork.IsLimit.lift' i' (kernel.ι (prod.lift f g)) <| calc kernel.ι (prod.lift f g) ≫ g _ = kernel.ι (prod.lift f g) ≫ prod.lift f g ≫ Limits.prod.snd := by rw [prod.lift_snd] _ = (0 : kernel (prod.lift f g) ⟶ P ⨯ Q) ≫ Limits.prod.snd := by rw [kernel.condition_assoc] _ = 0 := zero_comp HasLimit.mk { cone := PullbackCone.mk a' b' <| by simp? at ha' hb' says simp only [parallelPair_obj_zero, Fork.ofι_pt, Fork.ι_ofι] at ha' hb' rw [ha', hb'] isLimit := PullbackCone.IsLimit.mk _ (fun s => kernel.lift (prod.lift f g) (PullbackCone.snd s ≫ b) <| Limits.prod.hom_ext (calc ((PullbackCone.snd s ≫ b) ≫ prod.lift f g) ≫ Limits.prod.fst = PullbackCone.snd s ≫ b ≫ f := by simp only [prod.lift_fst, Category.assoc] _ = PullbackCone.fst s ≫ a ≫ f := by rw [PullbackCone.condition_assoc] _ = PullbackCone.fst s ≫ 0 := by rw [haf] _ = 0 ≫ Limits.prod.fst := by rw [comp_zero, zero_comp] ) (calc ((PullbackCone.snd s ≫ b) ≫ prod.lift f g) ≫ Limits.prod.snd = PullbackCone.snd s ≫ b ≫ g := by simp only [prod.lift_snd, Category.assoc] _ = PullbackCone.snd s ≫ 0 := by rw [hbg] _ = 0 ≫ Limits.prod.snd := by rw [comp_zero, zero_comp] )) (fun s => (cancel_mono a).1 <| by rw [KernelFork.ι_ofι] at ha' simp [ha', PullbackCone.condition s]) (fun s => (cancel_mono b).1 <| by rw [KernelFork.ι_ofι] at hb' simp [hb']) fun s m h₁ _ => (cancel_mono (kernel.ι (prod.lift f g))).1 <| calc m ≫ kernel.ι (prod.lift f g) = m ≫ a' ≫ a := by congr exact ha'.symm _ = PullbackCone.fst s ≫ a := by rw [← Category.assoc, h₁] _ = PullbackCone.snd s ≫ b := PullbackCone.condition s _ = kernel.lift (prod.lift f g) (PullbackCone.snd s ≫ b) _ ≫ kernel.ι (prod.lift f g) := by rw [kernel.lift_ι] } section attribute [local instance] pullback_of_mono /-- The pullback of `(𝟙 X, f)` and `(𝟙 X, g)` -/ private abbrev P {X Y : C} (f g : X ⟶ Y) [Mono (prod.lift (𝟙 X) f)] [Mono (prod.lift (𝟙 X) g)] : C := pullback (prod.lift (𝟙 X) f) (prod.lift (𝟙 X) g) /-- The equalizer of `f` and `g` exists. -/ lemma hasLimit_parallelPair {X Y : C} (f g : X ⟶ Y) : HasLimit (parallelPair f g) := have huv : (pullback.fst _ _ : P f g ⟶ X) = pullback.snd _ _ := calc (pullback.fst _ _ : P f g ⟶ X) = pullback.fst _ _ ≫ 𝟙 _ := Eq.symm <| Category.comp_id _ _ = pullback.fst _ _ ≫ prod.lift (𝟙 X) f ≫ Limits.prod.fst := by rw [prod.lift_fst] _ = pullback.snd _ _ ≫ prod.lift (𝟙 X) g ≫ Limits.prod.fst := by rw [pullback.condition_assoc] _ = pullback.snd _ _ := by rw [prod.lift_fst, Category.comp_id] have hvu : (pullback.fst _ _ : P f g ⟶ X) ≫ f = pullback.snd _ _ ≫ g := calc (pullback.fst _ _ : P f g ⟶ X) ≫ f = pullback.fst _ _ ≫ prod.lift (𝟙 X) f ≫ Limits.prod.snd := by rw [prod.lift_snd] _ = pullback.snd _ _ ≫ prod.lift (𝟙 X) g ≫ Limits.prod.snd := by rw [pullback.condition_assoc] _ = pullback.snd _ _ ≫ g := by rw [prod.lift_snd] have huu : (pullback.fst _ _ : P f g ⟶ X) ≫ f = pullback.fst _ _ ≫ g := by rw [hvu, ← huv] HasLimit.mk { cone := Fork.ofι (pullback.fst _ _) huu isLimit := Fork.IsLimit.mk _ (fun s => pullback.lift (Fork.ι s) (Fork.ι s) <| Limits.prod.hom_ext (by simp only [prod.lift_fst, Category.assoc]) (by simp only [prod.comp_lift, Fork.condition s])) (fun s => by simp) fun s m h => pullback.hom_ext (by simpa only [pullback.lift_fst] using h) (by simpa only [huv.symm, pullback.lift_fst] using h) } end section attribute [local instance] hasLimit_parallelPair /-- A `NormalMonoCategory` category with finite products and kernels has all equalizers. -/ instance (priority := 100) hasEqualizers : HasEqualizers C := hasEqualizers_of_hasLimit_parallelPair _ end /-- If a zero morphism is a cokernel of `f`, then `f` is an epimorphism. -/ theorem epi_of_zero_cokernel {X Y : C} (f : X ⟶ Y) (Z : C) (l : IsColimit (CokernelCofork.ofπ (0 : Y ⟶ Z) (show f ≫ 0 = 0 by simp))) : Epi f := ⟨fun u v huv => by obtain ⟨W, w, hw, hl⟩ := normalMonoOfMono (equalizer.ι u v) obtain ⟨m, hm⟩ := equalizer.lift' f huv have hwf : f ≫ w = 0 := by rw [← hm, Category.assoc, hw, comp_zero] obtain ⟨n, hn⟩ := CokernelCofork.IsColimit.desc' l _ hwf rw [Cofork.π_ofπ, zero_comp] at hn have : IsIso (equalizer.ι u v) := by apply isIso_limit_cone_parallelPair_of_eq hn.symm hl apply (cancel_epi (equalizer.ι u v)).1 exact equalizer.condition _ _⟩ section variable [HasZeroObject C] open ZeroObject /-- If `f ≫ g = 0` implies `g = 0` for all `g`, then `g` is a monomorphism. -/ theorem epi_of_zero_cancel {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Y ⟶ Z) (_ : f ≫ g = 0), g = 0) : Epi f := epi_of_zero_cokernel f 0 <| zeroCokernelOfZeroCancel f hf end end CategoryTheory.NormalMonoCategory namespace CategoryTheory.NormalEpiCategory variable [HasFiniteCoproducts C] [HasCokernels C] [IsNormalEpiCategory C] /-- The pushout of two epimorphisms exists. -/ lemma pushout_of_epi {X Y Z : C} (a : X ⟶ Y) (b : X ⟶ Z) [Epi a] [Epi b] : HasColimit (span a b) := let ⟨P, f, hfa, i⟩ := normalEpiOfEpi a let ⟨Q, g, hgb, i'⟩ := normalEpiOfEpi b let ⟨a', ha'⟩ := CokernelCofork.IsColimit.desc' i (cokernel.π (coprod.desc f g)) <| calc f ≫ cokernel.π (coprod.desc f g) = coprod.inl ≫ coprod.desc f g ≫ cokernel.π (coprod.desc f g) := by rw [coprod.inl_desc_assoc] _ = coprod.inl ≫ (0 : P ⨿ Q ⟶ cokernel (coprod.desc f g)) := by rw [cokernel.condition] _ = 0 := HasZeroMorphisms.comp_zero _ _ let ⟨b', hb'⟩ := CokernelCofork.IsColimit.desc' i' (cokernel.π (coprod.desc f g)) <| calc g ≫ cokernel.π (coprod.desc f g) = coprod.inr ≫ coprod.desc f g ≫ cokernel.π (coprod.desc f g) := by rw [coprod.inr_desc_assoc] _ = coprod.inr ≫ (0 : P ⨿ Q ⟶ cokernel (coprod.desc f g)) := by rw [cokernel.condition] _ = 0 := HasZeroMorphisms.comp_zero _ _ HasColimit.mk { cocone := PushoutCocone.mk a' b' <| by simp only [Cofork.π_ofπ] at ha' hb' rw [ha', hb'] isColimit := PushoutCocone.IsColimit.mk _ (fun s => cokernel.desc (coprod.desc f g) (b ≫ PushoutCocone.inr s) <| coprod.hom_ext (calc coprod.inl ≫ coprod.desc f g ≫ b ≫ PushoutCocone.inr s = f ≫ b ≫ PushoutCocone.inr s := by rw [coprod.inl_desc_assoc] _ = f ≫ a ≫ PushoutCocone.inl s := by rw [PushoutCocone.condition] _ = 0 ≫ PushoutCocone.inl s := by rw [← Category.assoc, eq_whisker hfa] _ = coprod.inl ≫ 0 := by rw [comp_zero, zero_comp] ) (calc coprod.inr ≫ coprod.desc f g ≫ b ≫ PushoutCocone.inr s = g ≫ b ≫ PushoutCocone.inr s := by rw [coprod.inr_desc_assoc] _ = 0 ≫ PushoutCocone.inr s := by rw [← Category.assoc, eq_whisker hgb] _ = coprod.inr ≫ 0 := by rw [comp_zero, zero_comp] )) (fun s => (cancel_epi a).1 <| by rw [CokernelCofork.π_ofπ] at ha' have reassoced {W : C} (h : cokernel (coprod.desc f g) ⟶ W) : a ≫ a' ≫ h = cokernel.π (coprod.desc f g) ≫ h := by rw [← Category.assoc, eq_whisker ha'] simp [reassoced, PushoutCocone.condition s]) (fun s => (cancel_epi b).1 <| by rw [CokernelCofork.π_ofπ] at hb' have reassoced' {W : C} (h : cokernel (coprod.desc f g) ⟶ W) : b ≫ b' ≫ h = cokernel.π (coprod.desc f g) ≫ h := by rw [← Category.assoc, eq_whisker hb'] simp [reassoced']) fun s m h₁ _ => (cancel_epi (cokernel.π (coprod.desc f g))).1 <| calc cokernel.π (coprod.desc f g) ≫ m = (a ≫ a') ≫ m := by congr exact ha'.symm _ = a ≫ PushoutCocone.inl s := by rw [Category.assoc, h₁] _ = b ≫ PushoutCocone.inr s := PushoutCocone.condition s _ = cokernel.π (coprod.desc f g) ≫ cokernel.desc (coprod.desc f g) (b ≫ PushoutCocone.inr s) _ := by rw [cokernel.π_desc] } section attribute [local instance] pushout_of_epi /-- The pushout of `(𝟙 Y, f)` and `(𝟙 Y, g)`. -/ private abbrev Q {X Y : C} (f g : X ⟶ Y) [Epi (coprod.desc (𝟙 Y) f)] [Epi (coprod.desc (𝟙 Y) g)] : C := pushout (coprod.desc (𝟙 Y) f) (coprod.desc (𝟙 Y) g) /-- The coequalizer of `f` and `g` exists. -/ lemma hasColimit_parallelPair {X Y : C} (f g : X ⟶ Y) : HasColimit (parallelPair f g) := have huv : (pushout.inl _ _ : Y ⟶ Q f g) = pushout.inr _ _ := calc (pushout.inl _ _ : Y ⟶ Q f g) = 𝟙 _ ≫ pushout.inl _ _ := Eq.symm <| Category.id_comp _ _ = (coprod.inl ≫ coprod.desc (𝟙 Y) f) ≫ pushout.inl _ _ := by rw [coprod.inl_desc] _ = (coprod.inl ≫ coprod.desc (𝟙 Y) g) ≫ pushout.inr _ _ := by simp only [Category.assoc, pushout.condition] _ = pushout.inr _ _ := by rw [coprod.inl_desc, Category.id_comp] have hvu : f ≫ (pushout.inl _ _ : Y ⟶ Q f g) = g ≫ pushout.inr _ _ := calc f ≫ (pushout.inl _ _ : Y ⟶ Q f g) = (coprod.inr ≫ coprod.desc (𝟙 Y) f) ≫ pushout.inl _ _ := by rw [coprod.inr_desc] _ = (coprod.inr ≫ coprod.desc (𝟙 Y) g) ≫ pushout.inr _ _ := by simp only [Category.assoc, pushout.condition] _ = g ≫ pushout.inr _ _ := by rw [coprod.inr_desc] have huu : f ≫ (pushout.inl _ _ : Y ⟶ Q f g) = g ≫ pushout.inl _ _ := by rw [hvu, huv] HasColimit.mk { cocone := Cofork.ofπ (pushout.inl _ _) huu isColimit := Cofork.IsColimit.mk _ (fun s => pushout.desc (Cofork.π s) (Cofork.π s) <| coprod.hom_ext (by simp only [coprod.inl_desc_assoc]) (by simp only [coprod.desc_comp, Cofork.condition s])) (fun s => by simp only [pushout.inl_desc, Cofork.π_ofπ]) fun s m h => pushout.hom_ext (by simpa only [pushout.inl_desc] using h) (by simpa only [huv.symm, pushout.inl_desc] using h) } end section attribute [local instance] hasColimit_parallelPair /-- A `NormalEpiCategory` category with finite coproducts and cokernels has all coequalizers. -/ instance (priority := 100) hasCoequalizers : HasCoequalizers C := hasCoequalizers_of_hasColimit_parallelPair _ end /-- If a zero morphism is a kernel of `f`, then `f` is a monomorphism. -/ theorem mono_of_zero_kernel {X Y : C} (f : X ⟶ Y) (Z : C) (l : IsLimit (KernelFork.ofι (0 : Z ⟶ X) (show 0 ≫ f = 0 by simp))) : Mono f := ⟨fun u v huv => by obtain ⟨W, w, hw, hl⟩ := normalEpiOfEpi (coequalizer.π u v) obtain ⟨m, hm⟩ := coequalizer.desc' f huv have reassoced {W : C} (h : coequalizer u v ⟶ W) : w ≫ coequalizer.π u v ≫ h = 0 ≫ h := by rw [← Category.assoc, eq_whisker hw] have hwf : w ≫ f = 0 := by rw [← hm, reassoced, zero_comp] obtain ⟨n, hn⟩ := KernelFork.IsLimit.lift' l _ hwf rw [Fork.ι_ofι, HasZeroMorphisms.comp_zero] at hn have : IsIso (coequalizer.π u v) := by apply isIso_colimit_cocone_parallelPair_of_eq hn.symm hl apply (cancel_mono (coequalizer.π u v)).1 exact coequalizer.condition _ _⟩ section variable [HasZeroObject C] open ZeroObject /-- If `g ≫ f = 0` implies `g = 0` for all `g`, then `f` is a monomorphism. -/ theorem mono_of_cancel_zero {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Z ⟶ X) (_ : g ≫ f = 0), g = 0) : Mono f := mono_of_zero_kernel f 0 <| zeroKernelOfCancelZero f hf end end CategoryTheory.NormalEpiCategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Opposites/Products.lean
import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Products and coproducts in `C` and `Cᵒᵖ` We construct products and coproducts 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] variable (X : Type v₂) /-- If `C` has products indexed by `X`, then `Cᵒᵖ` has coproducts indexed by `X`. -/ instance hasCoproductsOfShape_opposite [HasProductsOfShape X C] : HasCoproductsOfShape X Cᵒᵖ := by haveI : HasLimitsOfShape (Discrete X)ᵒᵖ C := hasLimitsOfShape_of_equivalence (Discrete.opposite X).symm infer_instance theorem hasCoproductsOfShape_of_opposite [HasProductsOfShape X Cᵒᵖ] : HasCoproductsOfShape X C := haveI : HasLimitsOfShape (Discrete X)ᵒᵖ Cᵒᵖ := hasLimitsOfShape_of_equivalence (Discrete.opposite X).symm hasColimitsOfShape_of_hasLimitsOfShape_op /-- If `C` has coproducts indexed by `X`, then `Cᵒᵖ` has products indexed by `X`. -/ instance hasProductsOfShape_opposite [HasCoproductsOfShape X C] : HasProductsOfShape X Cᵒᵖ := haveI : HasColimitsOfShape (Discrete X)ᵒᵖ C := hasColimitsOfShape_of_equivalence (Discrete.opposite X).symm hasLimitsOfShape_op_of_hasColimitsOfShape theorem hasProductsOfShape_of_opposite [HasCoproductsOfShape X Cᵒᵖ] : HasProductsOfShape X C := haveI : HasColimitsOfShape (Discrete X)ᵒᵖ Cᵒᵖ := hasColimitsOfShape_of_equivalence (Discrete.opposite X).symm hasLimitsOfShape_of_hasColimitsOfShape_op instance hasProducts_opposite [HasCoproducts.{v₂} C] : HasProducts.{v₂} Cᵒᵖ := fun _ => inferInstance theorem hasProducts_of_opposite [HasCoproducts.{v₂} Cᵒᵖ] : HasProducts.{v₂} C := fun X => hasProductsOfShape_of_opposite X instance hasCoproducts_opposite [HasProducts.{v₂} C] : HasCoproducts.{v₂} Cᵒᵖ := fun _ => inferInstance theorem hasCoproducts_of_opposite [HasProducts.{v₂} Cᵒᵖ] : HasCoproducts.{v₂} C := fun X => hasCoproductsOfShape_of_opposite X instance hasFiniteCoproducts_opposite [HasFiniteProducts C] : HasFiniteCoproducts Cᵒᵖ where out _ := Limits.hasCoproductsOfShape_opposite _ theorem hasFiniteCoproducts_of_opposite [HasFiniteProducts Cᵒᵖ] : HasFiniteCoproducts C := { out := fun _ => hasCoproductsOfShape_of_opposite _ } instance hasFiniteProducts_opposite [HasFiniteCoproducts C] : HasFiniteProducts Cᵒᵖ where out _ := inferInstance theorem hasFiniteProducts_of_opposite [HasFiniteCoproducts Cᵒᵖ] : HasFiniteProducts C := { out := fun _ => hasProductsOfShape_of_opposite _ } section OppositeCoproducts variable {α : Type*} {Z : α → C} section variable [HasCoproduct Z] instance : HasLimit (Discrete.functor Z).op := hasLimit_op_of_hasColimit (Discrete.functor Z) instance : HasLimit ((Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op) := hasLimit_equivalence_comp (Discrete.opposite α).symm instance : HasProduct (op <| Z ·) := hasLimit_of_iso ((Discrete.natIsoFunctor ≪≫ Discrete.natIso (fun _ ↦ by rfl)) : (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op ≅ Discrete.functor (op <| Z ·)) /-- A `Cofan` gives a `Fan` in the opposite category. -/ @[simp] def Cofan.op (c : Cofan Z) : Fan (op <| Z ·) := Fan.mk _ (fun a ↦ (c.inj a).op) /-- If a `Cofan` is colimit, then its opposite is limit. -/ -- noncomputability is just for performance (compilation takes a while) noncomputable def Cofan.IsColimit.op {c : Cofan Z} (hc : IsColimit c) : IsLimit c.op := by let e : Discrete.functor (Opposite.op <| Z ·) ≅ (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op := Discrete.natIso (fun _ ↦ Iso.refl _) refine IsLimit.ofIsoLimit ((IsLimit.postcomposeInvEquiv e _).2 (IsLimit.whiskerEquivalence hc.op (Discrete.opposite α).symm)) (Cones.ext (Iso.refl _) (fun ⟨a⟩ ↦ ?_)) simp [e, Cofan.inj] /-- The canonical isomorphism from the opposite of an abstract coproduct to the corresponding product in the opposite category. -/ def opCoproductIsoProduct' {c : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hf : IsLimit f) : op c.pt ≅ f.pt := IsLimit.conePointUniqueUpToIso (Cofan.IsColimit.op hc) hf variable (Z) in /-- The canonical isomorphism from the opposite of the coproduct to the product in the opposite category. -/ def opCoproductIsoProduct : op (∐ Z) ≅ ∏ᶜ (op <| Z ·) := opCoproductIsoProduct' (coproductIsCoproduct Z) (productIsProduct (op <| Z ·)) end @[reassoc (attr := simp)] lemma opCoproductIsoProduct'_hom_comp_proj {c : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hf : IsLimit f) (i : α) : (opCoproductIsoProduct' hc hf).hom ≫ f.proj i = (c.inj i).op := by simp [opCoproductIsoProduct', Fan.proj] @[reassoc (attr := simp)] lemma opCoproductIsoProduct_hom_comp_π [HasCoproduct Z] (i : α) : (opCoproductIsoProduct Z).hom ≫ Pi.π _ i = (Sigma.ι _ i).op := Limits.opCoproductIsoProduct'_hom_comp_proj .. theorem opCoproductIsoProduct'_inv_comp_inj {c : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hf : IsLimit f) (b : α) : (opCoproductIsoProduct' hc hf).inv ≫ (c.inj b).op = f.proj b := IsLimit.conePointUniqueUpToIso_inv_comp (Cofan.IsColimit.op hc) hf ⟨b⟩ theorem opCoproductIsoProduct'_comp_self {c c' : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hc' : IsColimit c') (hf : IsLimit f) : (opCoproductIsoProduct' hc hf).hom ≫ (opCoproductIsoProduct' hc' hf).inv = (hc.coconePointUniqueUpToIso hc').op.inv := by apply Quiver.Hom.unop_inj apply hc'.hom_ext intro ⟨j⟩ change c'.inj _ ≫ _ = _ simp only [unop_op, unop_comp, Discrete.functor_obj, const_obj_obj, Iso.op_inv, Quiver.Hom.unop_op, IsColimit.comp_coconePointUniqueUpToIso_inv] apply Quiver.Hom.op_inj simp only [op_comp, op_unop, Quiver.Hom.op_unop, Category.assoc, opCoproductIsoProduct'_inv_comp_inj] rw [← opCoproductIsoProduct'_inv_comp_inj hc hf] simp only [Iso.hom_inv_id_assoc] rfl variable (Z) in theorem opCoproductIsoProduct_inv_comp_ι [HasCoproduct Z] (b : α) : (opCoproductIsoProduct Z).inv ≫ (Sigma.ι Z b).op = Pi.π (op <| Z ·) b := opCoproductIsoProduct'_inv_comp_inj _ _ b theorem desc_op_comp_opCoproductIsoProduct'_hom {c : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hf : IsLimit f) (c' : Cofan Z) : (hc.desc c').op ≫ (opCoproductIsoProduct' hc hf).hom = hf.lift c'.op := by refine (Iso.eq_comp_inv _).mp (Quiver.Hom.unop_inj (hc.hom_ext (fun ⟨j⟩ ↦ Quiver.Hom.op_inj ?_))) simp only [unop_op, Discrete.functor_obj, const_obj_obj, Quiver.Hom.unop_op, IsColimit.fac, Cofan.op, unop_comp, op_comp, op_unop, Quiver.Hom.op_unop, Category.assoc] erw [opCoproductIsoProduct'_inv_comp_inj, IsLimit.fac] rfl theorem desc_op_comp_opCoproductIsoProduct_hom [HasCoproduct Z] {X : C} (π : (a : α) → Z a ⟶ X) : (Sigma.desc π).op ≫ (opCoproductIsoProduct Z).hom = Pi.lift (fun a ↦ (π a).op) := by convert desc_op_comp_opCoproductIsoProduct'_hom (coproductIsCoproduct Z) (productIsProduct (op <| Z ·)) (Cofan.mk _ π) · simp [Sigma.desc, coproductIsCoproduct] · simp [Pi.lift, productIsProduct] end OppositeCoproducts section OppositeProducts variable {α : Type*} {Z : α → C} section variable [HasProduct Z] instance : HasColimit (Discrete.functor Z).op := hasColimit_op_of_hasLimit (Discrete.functor Z) instance : HasColimit ((Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op) := hasColimit_equivalence_comp (Discrete.opposite α).symm instance : HasCoproduct (op <| Z ·) := hasColimit_of_iso ((Discrete.natIsoFunctor ≪≫ Discrete.natIso (fun _ ↦ by rfl)) : (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op ≅ Discrete.functor (op <| Z ·)).symm /-- A `Fan` gives a `Cofan` in the opposite category. -/ @[simp] def Fan.op (f : Fan Z) : Cofan (op <| Z ·) := Cofan.mk _ (fun a ↦ (f.proj a).op) /-- If a `Fan` is limit, then its opposite is colimit. -/ -- noncomputability is just for performance (compilation takes a while) noncomputable def Fan.IsLimit.op {f : Fan Z} (hf : IsLimit f) : IsColimit f.op := by let e : Discrete.functor (Opposite.op <| Z ·) ≅ (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op := Discrete.natIso (fun _ ↦ Iso.refl _) refine IsColimit.ofIsoColimit ((IsColimit.precomposeHomEquiv e _).2 (IsColimit.whiskerEquivalence hf.op (Discrete.opposite α).symm)) (Cocones.ext (Iso.refl _) (fun ⟨a⟩ ↦ ?_)) dsimp erw [Category.id_comp, Category.comp_id] rfl /-- The canonical isomorphism from the opposite of an abstract product to the corresponding coproduct in the opposite category. -/ def opProductIsoCoproduct' {f : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hc : IsColimit c) : op f.pt ≅ c.pt := IsColimit.coconePointUniqueUpToIso (Fan.IsLimit.op hf) hc variable (Z) in /-- The canonical isomorphism from the opposite of the product to the coproduct in the opposite category. -/ def opProductIsoCoproduct : op (∏ᶜ Z) ≅ ∐ (op <| Z ·) := opProductIsoCoproduct' (productIsProduct Z) (coproductIsCoproduct (op <| Z ·)) end theorem proj_comp_opProductIsoCoproduct'_hom {f : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hc : IsColimit c) (b : α) : (f.proj b).op ≫ (opProductIsoCoproduct' hf hc).hom = c.inj b := IsColimit.comp_coconePointUniqueUpToIso_hom (Fan.IsLimit.op hf) hc ⟨b⟩ theorem opProductIsoCoproduct'_comp_self {f f' : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hf' : IsLimit f') (hc : IsColimit c) : (opProductIsoCoproduct' hf hc).hom ≫ (opProductIsoCoproduct' hf' hc).inv = (hf.conePointUniqueUpToIso hf').op.inv := by apply Quiver.Hom.unop_inj apply hf.hom_ext intro ⟨j⟩ change _ ≫ f.proj _ = _ simp only [unop_op, unop_comp, Category.assoc, Discrete.functor_obj, Iso.op_inv, Quiver.Hom.unop_op, IsLimit.conePointUniqueUpToIso_inv_comp] apply Quiver.Hom.op_inj simp only [op_comp, op_unop, Quiver.Hom.op_unop, proj_comp_opProductIsoCoproduct'_hom] rw [← proj_comp_opProductIsoCoproduct'_hom hf' hc] simp only [Category.assoc, Iso.hom_inv_id, Category.comp_id] rfl variable (Z) in theorem π_comp_opProductIsoCoproduct_hom [HasProduct Z] (b : α) : (Pi.π Z b).op ≫ (opProductIsoCoproduct Z).hom = Sigma.ι (op <| Z ·) b := proj_comp_opProductIsoCoproduct'_hom _ _ b theorem opProductIsoCoproduct'_inv_comp_lift {f : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hc : IsColimit c) (f' : Fan Z) : (opProductIsoCoproduct' hf hc).inv ≫ (hf.lift f').op = hc.desc f'.op := by refine (Iso.inv_comp_eq _).mpr (Quiver.Hom.unop_inj (hf.hom_ext (fun ⟨j⟩ ↦ Quiver.Hom.op_inj ?_))) simp only [Discrete.functor_obj, unop_op, Quiver.Hom.unop_op, IsLimit.fac, Fan.op, unop_comp, Category.assoc, op_comp, op_unop, Quiver.Hom.op_unop] erw [← Category.assoc, proj_comp_opProductIsoCoproduct'_hom, IsColimit.fac] rfl theorem opProductIsoCoproduct_inv_comp_lift [HasProduct Z] {X : C} (π : (a : α) → X ⟶ Z a) : (opProductIsoCoproduct Z).inv ≫ (Pi.lift π).op = Sigma.desc (fun a ↦ (π a).op) := by convert opProductIsoCoproduct'_inv_comp_lift (productIsProduct Z) (coproductIsCoproduct (op <| Z ·)) (Fan.mk _ π) · simp [Pi.lift, productIsProduct] · simp [Sigma.desc, coproductIsCoproduct] end OppositeProducts section BinaryProducts variable {A B : C} [HasBinaryProduct A B] instance : HasBinaryCoproduct (op A) (op B) := by have : HasProduct fun x ↦ (WalkingPair.casesOn x A B : C) := ‹_› change HasCoproduct _ convert inferInstanceAs (HasCoproduct fun x ↦ op (WalkingPair.casesOn x A B : C)) with x cases x <;> rfl variable (A B) in /-- The canonical isomorphism from the opposite of the binary product to the coproduct in the opposite category. -/ def opProdIsoCoprod : op (A ⨯ B) ≅ (op A ⨿ op B) where hom := (prod.lift coprod.inl.unop coprod.inr.unop).op inv := coprod.desc prod.fst.op prod.snd.op hom_inv_id := by apply Quiver.Hom.unop_inj ext <;> · simp only apply Quiver.Hom.op_inj simp inv_hom_id := by ext <;> · simp only [colimit.ι_desc_assoc] apply Quiver.Hom.unop_inj simp @[reassoc (attr := simp)] lemma fst_opProdIsoCoprod_hom : prod.fst.op ≫ (opProdIsoCoprod A B).hom = coprod.inl := by rw [opProdIsoCoprod, ← op_comp, prod.lift_fst, Quiver.Hom.op_unop] @[reassoc (attr := simp)] lemma snd_opProdIsoCoprod_hom : prod.snd.op ≫ (opProdIsoCoprod A B).hom = coprod.inr := by rw [opProdIsoCoprod, ← op_comp, prod.lift_snd, Quiver.Hom.op_unop] @[reassoc (attr := simp)] lemma inl_opProdIsoCoprod_inv : coprod.inl ≫ (opProdIsoCoprod A B).inv = prod.fst.op := by rw [Iso.comp_inv_eq, fst_opProdIsoCoprod_hom] @[reassoc (attr := simp)] lemma inr_opProdIsoCoprod_inv : coprod.inr ≫ (opProdIsoCoprod A B).inv = prod.snd.op := by rw [Iso.comp_inv_eq, snd_opProdIsoCoprod_hom] @[reassoc (attr := simp)] lemma opProdIsoCoprod_hom_fst : (opProdIsoCoprod A B).hom.unop ≫ prod.fst = coprod.inl.unop := by simp [opProdIsoCoprod] @[reassoc (attr := simp)] lemma opProdIsoCoprod_hom_snd : (opProdIsoCoprod A B).hom.unop ≫ prod.snd = coprod.inr.unop := by simp [opProdIsoCoprod] @[reassoc (attr := simp)] lemma opProdIsoCoprod_inv_inl : (opProdIsoCoprod A B).inv.unop ≫ coprod.inl.unop = prod.fst := by rw [← unop_comp, inl_opProdIsoCoprod_inv, Quiver.Hom.unop_op] @[reassoc (attr := simp)] lemma opProdIsoCoprod_inv_inr : (opProdIsoCoprod A B).inv.unop ≫ coprod.inr.unop = prod.snd := by rw [← unop_comp, inr_opProdIsoCoprod_inv, Quiver.Hom.unop_op] end BinaryProducts end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Opposites/Filtered.lean
import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Filtered /-! # Filered colimits and cofilered limits in `C` and `Cᵒᵖ` We construct filered colimits and cofilered limits 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] instance has_cofiltered_limits_op_of_has_filtered_colimits [HasFilteredColimitsOfSize.{v₂, u₂} C] : HasCofilteredLimitsOfSize.{v₂, u₂} Cᵒᵖ where HasLimitsOfShape _ _ _ := hasLimitsOfShape_op_of_hasColimitsOfShape theorem has_cofiltered_limits_of_has_filtered_colimits_op [HasFilteredColimitsOfSize.{v₂, u₂} Cᵒᵖ] : HasCofilteredLimitsOfSize.{v₂, u₂} C := { HasLimitsOfShape := fun _ _ _ => hasLimitsOfShape_of_hasColimitsOfShape_op } instance has_filtered_colimits_op_of_has_cofiltered_limits [HasCofilteredLimitsOfSize.{v₂, u₂} C] : HasFilteredColimitsOfSize.{v₂, u₂} Cᵒᵖ where HasColimitsOfShape _ _ _ := inferInstance theorem has_filtered_colimits_of_has_cofiltered_limits_op [HasCofilteredLimitsOfSize.{v₂, u₂} Cᵒᵖ] : HasFilteredColimitsOfSize.{v₂, u₂} C := { HasColimitsOfShape := fun _ _ _ => hasColimitsOfShape_of_hasLimitsOfShape_op } end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Opposites/Equalizers.lean
import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Pullbacks /-! # Equalizers and coequalizers in `C` and `Cᵒᵖ` We construct equalizers and coequalizers 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] instance hasEqualizers_opposite [HasCoequalizers C] : HasEqualizers Cᵒᵖ := haveI : HasColimitsOfShape WalkingParallelPairᵒᵖ C := hasColimitsOfShape_of_equivalence walkingParallelPairOpEquiv hasLimitsOfShape_op_of_hasColimitsOfShape instance hasCoequalizers_opposite [HasEqualizers C] : HasCoequalizers Cᵒᵖ := haveI : HasLimitsOfShape WalkingParallelPairᵒᵖ C := hasLimitsOfShape_of_equivalence walkingParallelPairOpEquiv hasColimitsOfShape_op_of_hasLimitsOfShape /-- The canonical isomorphism relating `parallelPair f.op g.op` and `(parallelPair f g).op` -/ def parallelPairOpIso {X Y : C} (f g : X ⟶ Y) : parallelPair f.op g.op ≅ walkingParallelPairOpEquiv.functor ⋙ (parallelPair f g).op := NatIso.ofComponents (fun | .zero => .refl _ | .one => .refl _) (by rintro (_ | _ | _) (_ | _ | _) f <;> cases f <;> cat_disch) @[simp] lemma parallelPairOpIso_hom_app_zero {X Y : C} (f g : X ⟶ Y) : (parallelPairOpIso f g).hom.app WalkingParallelPair.zero = 𝟙 _ := rfl @[simp] lemma parallelPairOpIso_hom_app_one {X Y : C} (f g : X ⟶ Y) : (parallelPairOpIso f g).hom.app WalkingParallelPair.one = 𝟙 _ := rfl @[simp] lemma parallelPairOpIso_inv_app_zero {X Y : C} (f g : X ⟶ Y) : (parallelPairOpIso f g).inv.app WalkingParallelPair.zero = 𝟙 _ := rfl @[simp] lemma parallelPairOpIso_inv_app_one {X Y : C} (f g : X ⟶ Y) : (parallelPairOpIso f g).inv.app WalkingParallelPair.one = 𝟙 _ := rfl /-- The canonical isomorphism relating `(parallelPair f g).op` and `parallelPair f.op g.op` -/ def opParallelPairIso {X Y : C} (f g : X ⟶ Y) : (parallelPair f g).op ≅ walkingParallelPairOpEquiv.inverse ⋙ parallelPair f.op g.op := calc (parallelPair f g).op ≅ 𝟭 _ ⋙ (parallelPair f g).op := .refl _ _ ≅ (walkingParallelPairOpEquiv.inverse ⋙ walkingParallelPairOpEquiv.functor) ⋙ _ := isoWhiskerRight walkingParallelPairOpEquiv.symm.unitIso _ _ ≅ walkingParallelPairOpEquiv.inverse ⋙ walkingParallelPairOpEquiv.functor ⋙ _ := Functor.associator _ _ _ _ ≅ walkingParallelPairOpEquiv.inverse ⋙ parallelPair f.op g.op := isoWhiskerLeft _ (parallelPairOpIso f g).symm @[simp] lemma opParallelPairIso_hom_app_zero {X Y : C} (f g : X ⟶ Y) : (opParallelPairIso f g).hom.app (op WalkingParallelPair.zero) = 𝟙 _ := by simp [opParallelPairIso] @[simp] lemma opParallelPairIso_hom_app_one {X Y : C} (f g : X ⟶ Y) : (opParallelPairIso f g).hom.app (op WalkingParallelPair.one) = 𝟙 _ := by simp [opParallelPairIso] @[simp] lemma opParallelPairIso_inv_app_zero {X Y : C} (f g : X ⟶ Y) : (opParallelPairIso f g).inv.app (op WalkingParallelPair.zero) = 𝟙 _ := by simp [opParallelPairIso] @[simp] lemma opParallelPairIso_inv_app_one {X Y : C} (f g : X ⟶ Y) : (opParallelPairIso f g).inv.app (op WalkingParallelPair.one) = 𝟙 _ := by simp [opParallelPairIso] namespace Cofork /-- The obvious map `Cofork f g → Fork f.unop g.unop` -/ def unop {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Cofork f g) : Fork f.unop g.unop := Cocone.unop ((Cocones.precompose (opParallelPairIso f.unop g.unop).hom).obj (Cocone.whisker walkingParallelPairOpEquiv.inverse c)) lemma unop_π_app_one {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Cofork f g) : c.unop.π.app .one = Quiver.Hom.unop (c.ι.app .zero) := by simp [unop] lemma unop_π_app_zero {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Cofork f g) : c.unop.π.app .zero = Quiver.Hom.unop (c.ι.app .one) := by simp [unop] theorem unop_ι {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Cofork f g) : c.unop.ι = c.π.unop := by simp [Cofork.unop, Fork.ι] /-- The obvious map `Cofork f g → Fork f.op g.op` -/ def op {X Y : C} {f g : X ⟶ Y} (c : Cofork f g) : Fork f.op g.op := (Cones.postcompose (parallelPairOpIso f g).symm.hom).obj (Cone.whisker walkingParallelPairOpEquiv.functor (Cocone.op c)) lemma op_π_app_one {X Y : C} {f g : X ⟶ Y} (c : Cofork f g) : c.op.π.app .one = Quiver.Hom.op (c.ι.app .zero) := by simp [op] lemma op_π_app_zero {X Y : C} {f g : X ⟶ Y} (c : Cofork f g) : c.op.π.app .zero = Quiver.Hom.op (c.ι.app .one) := by simp [op] theorem op_ι {X Y : C} {f g : X ⟶ Y} (c : Cofork f g) : c.op.ι = c.π.op := by simp [Cofork.op, Fork.ι] end Cofork namespace Fork /-- The obvious map `Fork f g → Cofork f.unop g.unop` -/ def unop {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Fork f g) : Cofork f.unop g.unop := Cone.unop ((Cones.postcompose (opParallelPairIso f.unop g.unop).symm.hom).obj (Cone.whisker walkingParallelPairOpEquiv.inverse c)) lemma unop_ι_app_one {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Fork f g) : c.unop.ι.app .one = Quiver.Hom.unop (c.π.app .zero) := by simp [unop] lemma unop_ι_app_zero {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Fork f g) : c.unop.ι.app .zero = Quiver.Hom.unop (c.π.app .one) := by simp [unop] theorem unop_π {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Fork f g) : c.unop.π = c.ι.unop := by simp [Fork.unop, Cofork.π] /-- The obvious map `Fork f g → Cofork f.op g.op` -/ @[simps!] def op {X Y : C} {f g : X ⟶ Y} (c : Fork f g) : Cofork f.op g.op := (Cocones.precompose (parallelPairOpIso f g).hom).obj (Cocone.whisker walkingParallelPairOpEquiv.functor (Cone.op c)) lemma op_ι_app_one {X Y : C} {f g : X ⟶ Y} (c : Fork f g) : c.op.ι.app .one = Quiver.Hom.op (c.π.app .zero) := by simp [op] lemma op_ι_app_zero {X Y : C} {f g : X ⟶ Y} (c : Fork f g) : c.op.ι.app .zero = Quiver.Hom.op (c.π.app .one) := by simp [op] theorem op_π {X Y : C} {f g : X ⟶ Y} (c : Fork f g) : c.op.π = c.ι.op := by simp [Fork.op, Cofork.π] end Fork namespace Cofork theorem op_unop_π {X Y : C} {f g : X ⟶ Y} (c : Cofork f g) : c.op.unop.π = c.π := by simp [Fork.unop_π, Cofork.op_ι] theorem unop_op_π {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Cofork f g) : c.unop.op.π = c.π := by simp [Fork.op_π, Cofork.unop_ι] /-- If `c` is a cofork, then `c.op.unop` is isomorphic to `c`. -/ def opUnopIso {X Y : C} {f g : X ⟶ Y} (c : Cofork f g) : c.op.unop ≅ c := Cofork.ext (Iso.refl _) (by simp [op_unop_π]) /-- If `c` is a cofork in `Cᵒᵖ`, then `c.unop.op` is isomorphic to `c`. -/ def unopOpIso {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Cofork f g) : c.unop.op ≅ c := Cofork.ext (Iso.refl _) (by simp [unop_op_π]) end Cofork namespace Fork theorem op_unop_ι {X Y : C} {f g : X ⟶ Y} (c : Fork f g) : c.op.unop.ι = c.ι := by simp [Cofork.unop_ι, Fork.op_π] theorem unop_op_ι {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Fork f g) : c.unop.op.ι = c.ι := by simp [Fork.unop_π, Cofork.op_ι] /-- If `c` is a fork, then `c.op.unop` is isomorphic to `c`. -/ def opUnopIso {X Y : C} {f g : X ⟶ Y} (c : Fork f g) : c.op.unop ≅ c := Fork.ext (Iso.refl _) (by simp [op_unop_ι]) /-- If `c` is a fork in `Cᵒᵖ`, then `c.unop.op` is isomorphic to `c`. -/ def unopOpIso {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Fork f g) : c.unop.op ≅ c := Fork.ext (Iso.refl _) (by simp [unop_op_ι]) end Fork namespace Cofork /-- A cofork is a colimit cocone if and only if the corresponding fork in the opposite category is a limit cone. -/ noncomputable -- just for performance; compilation takes several seconds def isColimitEquivIsLimitOp {X Y : C} {f g : X ⟶ Y} (c : Cofork f g) : IsColimit c ≃ IsLimit c.op := by apply equivOfSubsingletonOfSubsingleton · intro h exact (IsLimit.postcomposeHomEquiv _ _).invFun ((IsLimit.whiskerEquivalenceEquiv _).toFun h.op) · intro h exact (IsColimit.equivIsoColimit c.opUnopIso).toFun (((IsLimit.postcomposeHomEquiv _ _).invFun ((IsLimit.whiskerEquivalenceEquiv walkingParallelPairOpEquiv.symm).toFun h)).unop) /-- A cofork is a colimit cocone in `Cᵒᵖ` if and only if the corresponding fork in `C` is a limit cone. -/ noncomputable -- just for performance; compilation takes several seconds def isColimitEquivIsLimitUnop {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Cofork f g) : IsColimit c ≃ IsLimit c.unop := by apply equivOfSubsingletonOfSubsingleton · intro h exact ((IsColimit.precomposeHomEquiv _ _).invFun ((IsColimit.whiskerEquivalenceEquiv walkingParallelPairOpEquiv.symm).toFun h)).unop · intro h exact (IsColimit.equivIsoColimit c.unopOpIso).toFun ((IsColimit.precomposeHomEquiv _ _).invFun ((IsColimit.whiskerEquivalenceEquiv _).toFun h.op)) /-- The canonical isomorphism between `(Cofork.ofπ π w).op` and `Fork.ofι π.op w'`. -/ def ofπOpIsoOfι {X Y P : C} {f g : X ⟶ Y} (π π' : Y ⟶ P) (w : f ≫ π = g ≫ π) (w' : π'.op ≫ f.op = π'.op ≫ g.op) (h : π = π') : (Cofork.ofπ π w).op ≅ Fork.ofι π'.op w' := Fork.ext (Iso.refl _) (by simp [Cofork.op_ι, h]) /-- The canonical isomorphism between `(Cofork.ofπ π w).unop` and `Fork.ofι π.unop w'`. -/ def ofπUnopIsoOfι {X Y P : Cᵒᵖ} {f g : X ⟶ Y} (π π' : Y ⟶ P) (w : f ≫ π = g ≫ π) (w' : π'.unop ≫ f.unop = π'.unop ≫ g.unop) (h : π = π') : (Cofork.ofπ π w).unop ≅ Fork.ofι π'.unop w' := Fork.ext (Iso.refl _) (by simp [Cofork.unop_ι, h]) /-- `Cofork.ofπ π w` is a colimit cocone if and only if `Fork.ofι π.op w'` in the opposite category is a limit cone. -/ def isColimitOfπEquivIsLimitOp {X Y P : C} {f g : X ⟶ Y} (π π' : Y ⟶ P) (w : f ≫ π = g ≫ π) (w' : π'.op ≫ f.op = π'.op ≫ g.op) (h : π = π') : IsColimit (Cofork.ofπ π w) ≃ IsLimit (Fork.ofι π'.op w') := (Cofork.ofπ π w).isColimitEquivIsLimitOp.trans (IsLimit.equivIsoLimit (ofπOpIsoOfι π π' w w' h)) /-- `Cofork.ofπ π w` is a colimit cocone in `Cᵒᵖ` if and only if `Fork.ofι π'.unop w'` in `C` is a limit cone. -/ def isColimitOfπEquivIsLimitUnop {X Y P : Cᵒᵖ} {f g : X ⟶ Y} (π π' : Y ⟶ P) (w : f ≫ π = g ≫ π) (w' : π'.unop ≫ f.unop = π'.unop ≫ g.unop) (h : π = π') : IsColimit (Cofork.ofπ π w) ≃ IsLimit (Fork.ofι π'.unop w') := (Cofork.ofπ π w).isColimitEquivIsLimitUnop.trans (IsLimit.equivIsoLimit (ofπUnopIsoOfι π π' w w' h)) end Cofork namespace Fork /-- A fork is a limit cone if and only if the corresponding cofork in the opposite category is a colimit cocone. -/ def isLimitEquivIsColimitOp {X Y : C} {f g : X ⟶ Y} (c : Fork f g) : IsLimit c ≃ IsColimit c.op := (IsLimit.equivIsoLimit c.opUnopIso).symm.trans c.op.isColimitEquivIsLimitUnop.symm /-- A fork is a limit cone in `Cᵒᵖ` if and only if the corresponding cofork in `C` is a colimit cocone. -/ def isLimitEquivIsColimitUnop {X Y : Cᵒᵖ} {f g : X ⟶ Y} (c : Fork f g) : IsLimit c ≃ IsColimit c.unop := (IsLimit.equivIsoLimit c.unopOpIso).symm.trans c.unop.isColimitEquivIsLimitOp.symm /-- The canonical isomorphism between `(Fork.ofι ι w).op` and `Cofork.ofπ ι.op w'`. -/ def ofιOpIsoOfπ {X Y P : C} {f g : X ⟶ Y} (ι ι' : P ⟶ X) (w : ι ≫ f = ι ≫ g) (w' : f.op ≫ ι'.op = g.op ≫ ι'.op) (h : ι = ι') : (Fork.ofι ι w).op ≅ Cofork.ofπ ι'.op w' := Cofork.ext (Iso.refl _) (by simp [Fork.op_π, h]) /-- The canonical isomorphism between `(Fork.ofι ι w).unop` and `Cofork.ofπ ι.unop w.unop`. -/ def ofιUnopIsoOfπ {X Y P : Cᵒᵖ} {f g : X ⟶ Y} (ι ι' : P ⟶ X) (w : ι ≫ f = ι ≫ g) (w' : f.unop ≫ ι'.unop = g.unop ≫ ι'.unop) (h : ι = ι') : (Fork.ofι ι w).unop ≅ Cofork.ofπ ι'.unop w' := Cofork.ext (Iso.refl _) (by simp [Fork.unop_π, h]) /-- `Fork.ofι ι w` is a limit cone if and only if `Cofork.ofπ ι'.op w'` in the opposite category is a colimit cocone. -/ def isLimitOfιEquivIsColimitOp {X Y P : C} {f g : X ⟶ Y} (ι ι' : P ⟶ X) (w : ι ≫ f = ι ≫ g) (w' : f.op ≫ ι'.op = g.op ≫ ι'.op) (h : ι = ι') : IsLimit (Fork.ofι ι w) ≃ IsColimit (Cofork.ofπ ι'.op w') := (Fork.ofι ι w).isLimitEquivIsColimitOp.trans (IsColimit.equivIsoColimit (ofιOpIsoOfπ ι ι' w w' h)) /-- `Fork.ofι ι w` is a limit cone in `Cᵒᵖ` if and only if `Cofork.ofπ ι.unop w.unop` in `C` is a colimit cocone. -/ def isLimitOfιEquivIsColimitUnop {X Y P : Cᵒᵖ} {f g : X ⟶ Y} (ι ι' : P ⟶ X) (w : ι ≫ f = ι ≫ g) (w' : f.unop ≫ ι'.unop = g.unop ≫ ι'.unop) (h : ι = ι') : IsLimit (Fork.ofι ι w) ≃ IsColimit (Cofork.ofπ ι'.unop w') := (Fork.ofι ι w).isLimitEquivIsColimitUnop.trans (IsColimit.equivIsoColimit (ofιUnopIsoOfπ ι ι' w w' h)) end Fork namespace Cofork /-- `Cofork.ofπ f pullback.condition` is a colimit cocone if and only if `Fork.ofι f.op pushout.condition` in the opposite category is a limit cone. -/ def isColimitCoforkPushoutEquivIsColimitForkOpPullback {X Y : C} {f : X ⟶ Y} [HasPullback f f] [HasPushout f.op f.op] : IsColimit (Cofork.ofπ f pullback.condition) ≃ IsLimit (Fork.ofι f.op pushout.condition) where toFun h := Fork.isLimitOfIsos _ (Cofork.isColimitOfπEquivIsLimitOp f f pullback.condition (by simp only [← op_comp, pullback.condition]) rfl h) _ (.refl _) (pullbackIsoUnopPushout f f).op.symm (.refl _) (by simp [← op_comp]) (by simp [← op_comp]) (by simp) invFun h := Cofork.isColimitOfIsos _ (Fork.isLimitOfιEquivIsColimitUnop f.op f.op pushout.condition (by rw [← unop_comp, ← unop_comp, pushout.condition]) rfl h) _ (pullbackIsoUnopPushout f f).symm ( .refl _) (.refl _) (by simp) (by simp) (by simp) left_inv := by cat_disch right_inv := by cat_disch /-- `Cofork.ofπ f pullback.condition` is a colimit cocone in `Cᵒᵖ` if and only if `Fork.ofι f.unop pushout.condition` in `C` is a limit cone. -/ def isColimitCoforkPushoutEquivIsColimitForkUnopPullback {X Y : Cᵒᵖ} {f : X ⟶ Y} [HasPullback f f] [HasPushout f.unop f.unop] : IsColimit (Cofork.ofπ f pullback.condition) ≃ IsLimit (Fork.ofι f.unop pushout.condition) where toFun h := Fork.isLimitOfIsos _ (Cofork.isColimitOfπEquivIsLimitUnop f f pullback.condition (by simp only [← unop_comp, pullback.condition]) rfl h) _ (.refl _) (pullbackIsoOpPushout f f).unop.symm (.refl _) (by simp [← unop_comp]) (by simp [← unop_comp]) (by simp) invFun h := Cofork.isColimitOfIsos _ (Fork.isLimitOfιEquivIsColimitOp f.unop f.unop pushout.condition (by rw [← op_comp, ← op_comp, pushout.condition]) rfl h) _ (pullbackIsoOpPushout f f).symm ( .refl _) (.refl _) (by simp) (by simp) (by simp) left_inv := by cat_disch right_inv := by cat_disch end Cofork namespace Fork /-- `Fork.ofι f pushout.condition` is a limit cone if and only if `Cofork.ofπ f.op pullback.condition` in the opposite category is a colimit cocone. -/ def isLimitForkPushoutEquivIsColimitForkOpPullback {X Y : C} {f : X ⟶ Y} [HasPushout f f] [HasPullback f.op f.op] : IsLimit (Fork.ofι f pushout.condition) ≃ IsColimit (Cofork.ofπ f.op pullback.condition) where toFun h := Cofork.isColimitOfIsos _ (Fork.isLimitOfιEquivIsColimitOp f f pushout.condition (by simp only [← op_comp, pushout.condition]) rfl h) _ ((pushoutIsoUnopPullback f f).op.symm ≪≫ eqToIso rfl) (.refl _) (.refl _) (by simp) (by simp) (by simp) invFun h := by refine Fork.isLimitOfIsos _ (Cofork.isColimitOfπEquivIsLimitUnop f.op f.op pullback.condition (by simp only [← unop_comp, pullback.condition]) rfl h) _ (.refl _) ((pushoutIsoUnopPullback f f).symm) (.refl _) ?_ ?_ (by simp) · rw [Iso.symm_hom, ← Quiver.Hom.unop_op (pushoutIsoUnopPullback f f).inv, ← unop_comp, pushoutIsoUnopPullback_inv_fst, Quiver.Hom.unop_op, Iso.refl_hom, Category.id_comp] · rw [Iso.symm_hom, ← Quiver.Hom.unop_op (pushoutIsoUnopPullback f f).inv, ← unop_comp, pushoutIsoUnopPullback_inv_snd, Quiver.Hom.unop_op, Iso.refl_hom, Category.id_comp] left_inv := by cat_disch right_inv := by cat_disch /-- `Fork.ofι f pushout.condition` is a limit cone in `Cᵒᵖ` if and only if `Cofork.ofπ f.op pullback.condition` in `C` is a colimit cocone. -/ def isLimitForkPushoutEquivIsColimitForkUnopPullback {X Y : Cᵒᵖ} {f : X ⟶ Y} [HasPushout f f] [HasPullback f.unop f.unop] : IsLimit (Fork.ofι f pushout.condition) ≃ IsColimit (Cofork.ofπ f.unop pullback.condition) where toFun h := Cofork.isColimitOfIsos _ (Fork.isLimitOfιEquivIsColimitUnop f f pushout.condition (by simp only [← unop_comp, pushout.condition]) rfl h) _ ((pushoutIsoOpPullback f f).unop.symm ≪≫ eqToIso rfl) (.refl _) (.refl _) (by simp) (by simp) (by simp) invFun h := by refine Fork.isLimitOfIsos _ (Cofork.isColimitOfπEquivIsLimitOp f.unop f.unop pullback.condition (by simp only [← op_comp, pullback.condition]) rfl h) _ (.refl _) ((pushoutIsoOpPullback f f).symm) (.refl _) ?_ ?_ (by simp) · rw [Iso.symm_hom, ← Quiver.Hom.op_unop (pushoutIsoOpPullback f f).inv, ← op_comp, pushoutIsoOpPullback_inv_fst, Quiver.Hom.op_unop, Iso.refl_hom, Category.id_comp] · rw [Iso.symm_hom, ← Quiver.Hom.op_unop (pushoutIsoOpPullback f f).inv, ← op_comp, pushoutIsoOpPullback_inv_snd, Quiver.Hom.op_unop, Iso.refl_hom, Category.id_comp] left_inv := by cat_disch right_inv := by cat_disch end Fork end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Opposites/Kernels.lean
import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Kernels and cokernels in `C` and `Cᵒᵖ` We construct kernels and cokernels 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] section HasZeroMorphisms variable [HasZeroMorphisms C] /-- A colimit cokernel cofork gives a limit kernel fork in the opposite category -/ def CokernelCofork.IsColimit.ofπOp {X Y Q : C} (p : Y ⟶ Q) {f : X ⟶ Y} (w : f ≫ p = 0) (h : IsColimit (CokernelCofork.ofπ p w)) : IsLimit (KernelFork.ofι p.op (show p.op ≫ f.op = 0 by rw [← op_comp, w, op_zero])) := KernelFork.IsLimit.ofι _ _ (fun x hx => (h.desc (CokernelCofork.ofπ x.unop (Quiver.Hom.op_inj hx))).op) (fun _ _ => Quiver.Hom.unop_inj (Cofork.IsColimit.π_desc h)) (fun x hx b hb => Quiver.Hom.unop_inj (Cofork.IsColimit.hom_ext h (by simpa only [Quiver.Hom.unop_op, Cofork.IsColimit.π_desc] using Quiver.Hom.op_inj hb))) /-- A colimit cokernel cofork in the opposite category gives a limit kernel fork in the original category -/ def CokernelCofork.IsColimit.ofπUnop {X Y Q : Cᵒᵖ} (p : Y ⟶ Q) {f : X ⟶ Y} (w : f ≫ p = 0) (h : IsColimit (CokernelCofork.ofπ p w)) : IsLimit (KernelFork.ofι p.unop (show p.unop ≫ f.unop = 0 by rw [← unop_comp, w, unop_zero])) := KernelFork.IsLimit.ofι _ _ (fun x hx => (h.desc (CokernelCofork.ofπ x.op (Quiver.Hom.unop_inj hx))).unop) (fun _ _ => Quiver.Hom.op_inj (Cofork.IsColimit.π_desc h)) (fun x hx b hb => Quiver.Hom.op_inj (Cofork.IsColimit.hom_ext h (by simpa only [Quiver.Hom.op_unop, Cofork.IsColimit.π_desc] using Quiver.Hom.unop_inj hb))) /-- A limit kernel fork gives a colimit cokernel cofork in the opposite category -/ def KernelFork.IsLimit.ofιOp {K X Y : C} (i : K ⟶ X) {f : X ⟶ Y} (w : i ≫ f = 0) (h : IsLimit (KernelFork.ofι i w)) : IsColimit (CokernelCofork.ofπ i.op (show f.op ≫ i.op = 0 by rw [← op_comp, w, op_zero])) := CokernelCofork.IsColimit.ofπ _ _ (fun x hx => (h.lift (KernelFork.ofι x.unop (Quiver.Hom.op_inj hx))).op) (fun _ _ => Quiver.Hom.unop_inj (Fork.IsLimit.lift_ι h)) (fun x hx b hb => Quiver.Hom.unop_inj (Fork.IsLimit.hom_ext h (by simpa only [Quiver.Hom.unop_op, Fork.IsLimit.lift_ι] using Quiver.Hom.op_inj hb))) /-- A limit kernel fork in the opposite category gives a colimit cokernel cofork in the original category -/ def KernelFork.IsLimit.ofιUnop {K X Y : Cᵒᵖ} (i : K ⟶ X) {f : X ⟶ Y} (w : i ≫ f = 0) (h : IsLimit (KernelFork.ofι i w)) : IsColimit (CokernelCofork.ofπ i.unop (show f.unop ≫ i.unop = 0 by rw [← unop_comp, w, unop_zero])) := CokernelCofork.IsColimit.ofπ _ _ (fun x hx => (h.lift (KernelFork.ofι x.op (Quiver.Hom.unop_inj hx))).unop) (fun _ _ => Quiver.Hom.op_inj (Fork.IsLimit.lift_ι h)) (fun x hx b hb => Quiver.Hom.op_inj (Fork.IsLimit.hom_ext h (by simpa only [Quiver.Hom.op_unop, Fork.IsLimit.lift_ι] using Quiver.Hom.unop_inj hb))) end HasZeroMorphisms end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Opposites/Pullbacks.lean
import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Pullbacks and pushouts in `C` and `Cᵒᵖ` We construct pullbacks and pushouts 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] instance hasPullbacks_opposite [HasPushouts C] : HasPullbacks Cᵒᵖ := by haveI : HasColimitsOfShape WalkingCospanᵒᵖ C := hasColimitsOfShape_of_equivalence walkingCospanOpEquiv.symm apply hasLimitsOfShape_op_of_hasColimitsOfShape instance hasPushouts_opposite [HasPullbacks C] : HasPushouts Cᵒᵖ := by haveI : HasLimitsOfShape WalkingSpanᵒᵖ C := hasLimitsOfShape_of_equivalence walkingSpanOpEquiv.symm infer_instance /-- The canonical isomorphism relating `Span f.op g.op` and `(Cospan f g).op` -/ @[simps!] def spanOp {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : span f.op g.op ≅ walkingCospanOpEquiv.inverse ⋙ (cospan f g).op := NatIso.ofComponents (fun | .none => .refl _ | .left => .refl _ | .right => .refl _) (by rintro (_ | _ | _) (_ | _ | _) f <;> cases f <;> cat_disch) /-- The canonical isomorphism relating `(Cospan f g).op` and `Span f.op g.op` -/ @[simps!] def opCospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).op ≅ walkingCospanOpEquiv.functor ⋙ span f.op g.op := calc (cospan f g).op ≅ 𝟭 _ ⋙ (cospan f g).op := .refl _ _ ≅ (walkingCospanOpEquiv.functor ⋙ walkingCospanOpEquiv.inverse) ⋙ (cospan f g).op := isoWhiskerRight walkingCospanOpEquiv.unitIso _ _ ≅ walkingCospanOpEquiv.functor ⋙ walkingCospanOpEquiv.inverse ⋙ (cospan f g).op := Functor.associator _ _ _ _ ≅ walkingCospanOpEquiv.functor ⋙ span f.op g.op := isoWhiskerLeft _ (spanOp f g).symm /-- The canonical isomorphism relating `Cospan f.op g.op` and `(Span f g).op` -/ @[simps!] def cospanOp {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : cospan f.op g.op ≅ walkingSpanOpEquiv.inverse ⋙ (span f g).op := NatIso.ofComponents (fun | .none => .refl _ | .left => .refl _ | .right => .refl _) (by rintro (_ | _ | _) (_ | _ | _) f <;> cases f <;> cat_disch) /-- The canonical isomorphism relating `(Span f g).op` and `Cospan f.op g.op` -/ @[simps!] def opSpan {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).op ≅ walkingSpanOpEquiv.functor ⋙ cospan f.op g.op := calc (span f g).op ≅ 𝟭 _ ⋙ (span f g).op := .refl _ _ ≅ (walkingSpanOpEquiv.functor ⋙ walkingSpanOpEquiv.inverse) ⋙ (span f g).op := isoWhiskerRight walkingSpanOpEquiv.unitIso _ _ ≅ walkingSpanOpEquiv.functor ⋙ walkingSpanOpEquiv.inverse ⋙ (span f g).op := Functor.associator _ _ _ _ ≅ walkingSpanOpEquiv.functor ⋙ cospan f.op g.op := isoWhiskerLeft _ (cospanOp f g).symm namespace PushoutCocone /-- The obvious map `PushoutCocone f g → PullbackCone f.unop g.unop` -/ @[simps!] def unop {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : PullbackCone f.unop g.unop := Cocone.unop ((Cocones.precompose (opCospan f.unop g.unop).hom).obj (Cocone.whisker walkingCospanOpEquiv.functor c)) theorem unop_fst {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.unop.fst = c.inl.unop := by simp theorem unop_snd {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.unop.snd = c.inr.unop := by simp /-- The obvious map `PushoutCocone f.op g.op → PullbackCone f g` -/ @[simps!] def op {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : PullbackCone f.op g.op := (Cones.postcompose (cospanOp f g).symm.hom).obj (Cone.whisker walkingSpanOpEquiv.inverse (Cocone.op c)) theorem op_fst {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.op.fst = c.inl.op := by simp theorem op_snd {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.op.snd = c.inr.op := by simp end PushoutCocone namespace PullbackCone /-- The obvious map `PullbackCone f g → PushoutCocone f.unop g.unop` -/ @[simps!] def unop {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : PushoutCocone f.unop g.unop := Cone.unop ((Cones.postcompose (opSpan f.unop g.unop).symm.hom).obj (Cone.whisker walkingSpanOpEquiv.functor c)) theorem unop_inl {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.unop.inl = c.fst.unop := by simp theorem unop_inr {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.unop.inr = c.snd.unop := by simp /-- The obvious map `PullbackCone f g → PushoutCocone f.op g.op` -/ @[simps!] def op {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : PushoutCocone f.op g.op := (Cocones.precompose (spanOp f g).hom).obj (Cocone.whisker walkingCospanOpEquiv.inverse (Cone.op c)) theorem op_inl {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.op.inl = c.fst.op := by simp theorem op_inr {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.op.inr = c.snd.op := by simp /-- If `c` is a pullback cone, then `c.op.unop` is isomorphic to `c`. -/ def opUnopIso {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.op.unop ≅ c := PullbackCone.ext (Iso.refl _) (by simp) (by simp) /-- If `c` is a pullback cone in `Cᵒᵖ`, then `c.unop.op` is isomorphic to `c`. -/ def unopOpIso {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.unop.op ≅ c := PullbackCone.ext (Iso.refl _) (by simp) (by simp) end PullbackCone namespace PushoutCocone /-- If `c` is a pushout cocone, then `c.op.unop` is isomorphic to `c`. -/ def opUnopIso {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.op.unop ≅ c := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) /-- If `c` is a pushout cocone in `Cᵒᵖ`, then `c.unop.op` is isomorphic to `c`. -/ def unopOpIso {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.unop.op ≅ c := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) /-- A pushout cone is a colimit cocone if and only if the corresponding pullback cone in the opposite category is a limit cone. -/ noncomputable -- just for performance; compilation takes several seconds def isColimitEquivIsLimitOp {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : IsColimit c ≃ IsLimit c.op := by apply equivOfSubsingletonOfSubsingleton · intro h exact (IsLimit.postcomposeHomEquiv _ _).invFun ((IsLimit.whiskerEquivalenceEquiv walkingSpanOpEquiv.symm).toFun h.op) · intro h exact (IsColimit.equivIsoColimit c.opUnopIso).toFun (((IsLimit.postcomposeHomEquiv _ _).invFun ((IsLimit.whiskerEquivalenceEquiv _).toFun h)).unop) /-- A pushout cone is a colimit cocone in `Cᵒᵖ` if and only if the corresponding pullback cone in `C` is a limit cone. -/ noncomputable -- just for performance; compilation takes several seconds def isColimitEquivIsLimitUnop {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : IsColimit c ≃ IsLimit c.unop := by apply equivOfSubsingletonOfSubsingleton · intro h exact ((IsColimit.precomposeHomEquiv _ _).invFun ((IsColimit.whiskerEquivalenceEquiv _).toFun h)).unop · intro h exact (IsColimit.equivIsoColimit c.unopOpIso).toFun ((IsColimit.precomposeHomEquiv _ _).invFun ((IsColimit.whiskerEquivalenceEquiv walkingCospanOpEquiv.symm).toFun h.op)) end PushoutCocone namespace PullbackCone /-- A pullback cone is a limit cone if and only if the corresponding pushout cocone in the opposite category is a colimit cocone. -/ def isLimitEquivIsColimitOp {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : IsLimit c ≃ IsColimit c.op := (IsLimit.equivIsoLimit c.opUnopIso).symm.trans c.op.isColimitEquivIsLimitUnop.symm /-- A pullback cone is a limit cone in `Cᵒᵖ` if and only if the corresponding pushout cocone in `C` is a colimit cocone. -/ def isLimitEquivIsColimitUnop {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : IsLimit c ≃ IsColimit c.unop := (IsLimit.equivIsoLimit c.unopOpIso).symm.trans c.unop.isColimitEquivIsLimitOp.symm end PullbackCone section Pullback open Opposite /-- The pullback of `f` and `g` in `C` is isomorphic to the pushout of `f.op` and `g.op` in `Cᵒᵖ`. -/ noncomputable def pullbackIsoUnopPushout {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [h : HasPullback f g] [HasPushout f.op g.op] : pullback f g ≅ unop (pushout f.op g.op) := IsLimit.conePointUniqueUpToIso (@limit.isLimit _ _ _ _ _ h) ((PushoutCocone.isColimitEquivIsLimitUnop _) (colimit.isColimit (span f.op g.op))) @[reassoc (attr := simp)] theorem pullbackIsoUnopPushout_inv_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.op g.op] : (pullbackIsoUnopPushout f g).inv ≫ pullback.fst f g = (pushout.inl f.op g.op).unop := (IsLimit.conePointUniqueUpToIso_inv_comp _ _ _).trans (by simp [unop_id (X := { unop := X })]) @[reassoc (attr := simp)] theorem pullbackIsoUnopPushout_inv_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.op g.op] : (pullbackIsoUnopPushout f g).inv ≫ pullback.snd f g = (pushout.inr f.op g.op).unop := (IsLimit.conePointUniqueUpToIso_inv_comp _ _ _).trans (by simp [unop_id (X := { unop := Y })]) @[reassoc (attr := simp)] theorem pullbackIsoUnopPushout_hom_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.op g.op] : pushout.inl f.op g.op ≫ (pullbackIsoUnopPushout f g).hom.op = (pullback.fst f g).op := Quiver.Hom.unop_inj <| by simp [← pullbackIsoUnopPushout_inv_fst] @[reassoc (attr := simp)] theorem pullbackIsoUnopPushout_hom_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.op g.op] : pushout.inr f.op g.op ≫ (pullbackIsoUnopPushout f g).hom.op = (pullback.snd f g).op := Quiver.Hom.unop_inj <| by simp [← pullbackIsoUnopPushout_inv_snd] /-- The pullback of `f` and `g` in `Cᵒᵖ` is isomorphic to the pushout of `f.unop` and `g.unop` in `C`. -/ noncomputable def pullbackIsoOpPushout {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : Y ⟶ Z) [h : HasPullback f g] [HasPushout f.unop g.unop] : pullback f g ≅ op (pushout f.unop g.unop) := IsLimit.conePointUniqueUpToIso (@limit.isLimit _ _ _ _ _ h) ((PushoutCocone.isColimitEquivIsLimitOp _) (colimit.isColimit (span f.unop g.unop))) @[reassoc (attr := simp)] theorem pullbackIsoOpPushout_inv_fst {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.unop g.unop] : (pullbackIsoOpPushout f g).inv ≫ pullback.fst f g = (pushout.inl f.unop g.unop).op := (IsLimit.conePointUniqueUpToIso_inv_comp _ _ _).trans (by simp) @[reassoc (attr := simp)] theorem pullbackIsoOpPushout_inv_snd {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.unop g.unop] : (pullbackIsoOpPushout f g).inv ≫ pullback.snd f g = (pushout.inr f.unop g.unop).op := (IsLimit.conePointUniqueUpToIso_inv_comp _ _ _).trans (by simp) @[reassoc (attr := simp)] theorem pullbackIsoOpPushout_hom_inl {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.unop g.unop] : pushout.inl _ _ ≫ (pullbackIsoOpPushout f g).hom.unop = (pullback.fst f g).unop := Quiver.Hom.op_inj <| by simp [← pullbackIsoOpPushout_inv_fst] @[reassoc (attr := simp)] theorem pullbackIsoOpPushout_hom_inr {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPushout f.unop g.unop] : pushout.inr _ _ ≫ (pullbackIsoOpPushout f g).hom.unop = (pullback.snd f g).unop := Quiver.Hom.op_inj <| by simp [← pullbackIsoOpPushout_inv_snd] end Pullback section Pushout /-- The pushout of `f` and `g` in `C` is isomorphic to the pullback of `f.op` and `g.op` in `Cᵒᵖ`. -/ noncomputable def pushoutIsoUnopPullback {X Y Z : C} (f : X ⟶ Z) (g : X ⟶ Y) [h : HasPushout f g] [HasPullback f.op g.op] : pushout f g ≅ unop (pullback f.op g.op) := IsColimit.coconePointUniqueUpToIso (@colimit.isColimit _ _ _ _ _ h) ((PullbackCone.isLimitEquivIsColimitUnop _) (limit.isLimit (cospan f.op g.op))) @[reassoc (attr := simp)] theorem pushoutIsoUnopPullback_inl_hom {X Y Z : C} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.op g.op] : pushout.inl _ _ ≫ (pushoutIsoUnopPullback f g).hom = (pullback.fst f.op g.op).unop := (IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _).trans (by simp) @[reassoc (attr := simp)] theorem pushoutIsoUnopPullback_inr_hom {X Y Z : C} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.op g.op] : pushout.inr _ _ ≫ (pushoutIsoUnopPullback f g).hom = (pullback.snd f.op g.op).unop := (IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _).trans (by simp) @[simp] theorem pushoutIsoUnopPullback_inv_fst {X Y Z : C} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.op g.op] : (pushoutIsoUnopPullback f g).inv.op ≫ pullback.fst f.op g.op = (pushout.inl f g).op := Quiver.Hom.unop_inj <| by simp [← pushoutIsoUnopPullback_inl_hom] @[simp] theorem pushoutIsoUnopPullback_inv_snd {X Y Z : C} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.op g.op] : (pushoutIsoUnopPullback f g).inv.op ≫ pullback.snd f.op g.op = (pushout.inr f g).op := Quiver.Hom.unop_inj <| by simp [← pushoutIsoUnopPullback_inr_hom] /-- The pushout of `f` and `g` in `Cᵒᵖ` is isomorphic to the pullback of `f.unop` and `g.unop` in `C`. -/ noncomputable def pushoutIsoOpPullback {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : X ⟶ Y) [h : HasPushout f g] [HasPullback f.unop g.unop] : pushout f g ≅ op (pullback f.unop g.unop) := IsColimit.coconePointUniqueUpToIso (@colimit.isColimit _ _ _ _ _ h) ((PullbackCone.isLimitEquivIsColimitOp _) (limit.isLimit (cospan f.unop g.unop))) @[reassoc (attr := simp)] theorem pushoutIsoOpPullback_inl_hom {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.unop g.unop] : pushout.inl _ _ ≫ (pushoutIsoOpPullback f g).hom = (pullback.fst f.unop g.unop).op := (IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _).trans (by simp) @[reassoc (attr := simp)] theorem pushoutIsoOpPullback_inr_hom {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.unop g.unop] : pushout.inr _ _ ≫ (pushoutIsoOpPullback f g).hom = (pullback.snd f.unop g.unop).op := (IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _).trans (by simp) @[simp] theorem pushoutIsoOpPullback_inv_fst {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.unop g.unop] : (pushoutIsoOpPullback f g).inv.unop ≫ pullback.fst f.unop g.unop = (pushout.inl f g).unop := Quiver.Hom.op_inj <| by simp [← pushoutIsoOpPullback_inl_hom] @[simp] theorem pushoutIsoOpPullback_inv_snd {X Y Z : Cᵒᵖ} (f : X ⟶ Z) (g : X ⟶ Y) [HasPushout f g] [HasPullback f.unop g.unop] : (pushoutIsoOpPullback f g).inv.unop ≫ pullback.snd f.unop g.unop = (pushout.inr f g).unop := Quiver.Hom.op_inj <| by simp [← pushoutIsoOpPullback_inr_hom] end Pushout end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/HasPullback.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.PullbackCone /-! # HasPullback `HasPullback f g` and `pullback f g` provides API for `HasLimit` and `limit` in the case of pullbacks. ## Main definitions * `HasPullback f g`: this is an abbreviation for `HasLimit (cospan f g)`, and is a typeclass used to express the fact that a given pair of morphisms has a pullback. * `HasPullbacks`: expresses the fact that `C` admits all pullbacks, it is implemented as an abbreviation for `HasLimitsOfShape WalkingCospan C` * `pullback f g`: Given a `HasPullback f g` instance, this function returns the choice of a limit object corresponding to the pullback of `f` and `g`. It fits into the following diagram: ``` pullback f g ---pullback.fst f g---> X | | | | pullback.snd f g f | | v v Y --------------g--------------> Z ``` * `HasPushout f g`: this is an abbreviation for `HasColimit (span f g)`, and is a typeclass used to express the fact that a given pair of morphisms has a pushout. * `HasPushouts`: expresses the fact that `C` admits all pushouts, it is implemented as an abbreviation for `HasColimitsOfShape WalkingSpan C` * `pushout f g`: Given a `HasPushout f g` instance, this function returns the choice of a colimit object corresponding to the pushout of `f` and `g`. It fits into the following diagram: ``` X --------------f--------------> Y | | g pushout.inl f g | | v v Z ---pushout.inr f g---> pushout f g ``` ## Main results & API * The following API is available for using the universal property of `pullback f g`: `lift`, `lift_fst`, `lift_snd`, `lift'`, `hom_ext` (for uniqueness). * `pullback.map` is the induced map between pullbacks `W ×ₛ X ⟶ Y ×ₜ Z` given pointwise (compatible) maps `W ⟶ Y`, `X ⟶ Z` and `S ⟶ T`. * `pullbackComparison`: Given a functor `G`, this is the natural morphism `G.obj (pullback f g) ⟶ pullback (G.map f) (G.map g)` * `pullbackSymmetry` provides the natural isomorphism `pullback f g ≅ pullback g f` (The dual results for pushouts are also available) ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] {W X Y Z : C} /-- Two morphisms `f : X ⟶ Z` and `g : Y ⟶ Z` have a pullback if the diagram `cospan f g` has a limit. -/ abbrev HasPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) := HasLimit (cospan f g) /-- Two morphisms `f : X ⟶ Y` and `g : X ⟶ Z` have a pushout if the diagram `span f g` has a colimit. -/ abbrev HasPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) := HasColimit (span f g) /-- `pullback f g` computes the pullback of a pair of morphisms with the same target. -/ abbrev pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] := limit (cospan f g) /-- The cone associated to the pullback of `f` and `g` -/ abbrev pullback.cone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : PullbackCone f g := limit.cone (cospan f g) /-- `pushout f g` computes the pushout of a pair of morphisms with the same source. -/ abbrev pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] := colimit (span f g) /-- The cocone associated to the pullback of `f` and `g` -/ abbrev pushout.cocone {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : PushoutCocone f g := colimit.cocone (span f g) /-- The first projection of the pullback of `f` and `g`. -/ abbrev pullback.fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : pullback f g ⟶ X := limit.π (cospan f g) WalkingCospan.left /-- The second projection of the pullback of `f` and `g`. -/ abbrev pullback.snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : pullback f g ⟶ Y := limit.π (cospan f g) WalkingCospan.right /-- The first inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inl {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : Y ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.left /-- The second inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inr {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : Z ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.right /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `pullback.lift : W ⟶ pullback f g`. -/ abbrev pullback.lift {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g := by cat_disch) : W ⟶ pullback f g := limit.lift _ (PullbackCone.mk h k w) /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `pushout.desc : pushout f g ⟶ W`. -/ abbrev pushout.desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k := by cat_disch) : pushout f g ⟶ W := colimit.desc _ (PushoutCocone.mk h k w) /-- The cone associated to a pullback is a limit cone. -/ abbrev pullback.isLimit {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsLimit (pullback.cone f g) := limit.isLimit (cospan f g) /-- The cocone associated to a pushout is a colimit cone. -/ abbrev pushout.isColimit {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : IsColimit (pushout.cocone f g) := colimit.isColimit (span f g) @[simp] theorem PullbackCone.fst_limit_cone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.fst (limit.cone (cospan f g)) = pullback.fst f g := rfl @[simp] theorem PullbackCone.snd_limit_cone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.snd (limit.cone (cospan f g)) = pullback.snd f g := rfl theorem PushoutCocone.inl_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inl (colimit.cocone (span f g)) = pushout.inl _ _ := rfl theorem PushoutCocone.inr_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inr (colimit.cocone (span f g)) = pushout.inr _ _ := rfl @[reassoc] theorem pullback.lift_fst {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.fst f g = h := limit.lift_π _ _ @[reassoc] theorem pullback.lift_snd {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.snd f g = k := limit.lift_π _ _ @[reassoc] theorem pushout.inl_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inl _ _ ≫ pushout.desc h k w = h := colimit.ι_desc _ _ @[reassoc] theorem pushout.inr_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inr _ _ ≫ pushout.desc h k w = k := colimit.ι_desc _ _ /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `l : W ⟶ pullback f g` such that `l ≫ pullback.fst = h` and `l ≫ pullback.snd = k`. -/ def pullback.lift' {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ pullback f g // l ≫ pullback.fst f g = h ∧ l ≫ pullback.snd f g = k } := ⟨pullback.lift h k w, pullback.lift_fst _ _ _, pullback.lift_snd _ _ _⟩ /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `l : pushout f g ⟶ W` such that `pushout.inl _ _ ≫ l = h` and `pushout.inr _ _ ≫ l = k`. -/ def pullback.desc' {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : pushout f g ⟶ W // pushout.inl _ _ ≫ l = h ∧ pushout.inr _ _ ≫ l = k } := ⟨pushout.desc h k w, pushout.inl_desc _ _ _, pushout.inr_desc _ _ _⟩ @[reassoc] theorem pullback.condition {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback.fst f g ≫ f = pullback.snd f g ≫ g := PullbackCone.condition _ @[reassoc] theorem pushout.condition {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : f ≫ (pushout.inl f g) = g ≫ pushout.inr _ _ := PushoutCocone.condition _ /-- Two morphisms into a pullback are equal if their compositions with the pullback morphisms are equal -/ @[ext 1100] theorem pullback.hom_ext {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] {W : C} {k l : W ⟶ pullback f g} (h₀ : k ≫ pullback.fst f g = l ≫ pullback.fst f g) (h₁ : k ≫ pullback.snd f g = l ≫ pullback.snd f g) : k = l := limit.hom_ext <| PullbackCone.equalizer_ext _ h₀ h₁ /-- The pullback cone built from the pullback projections is a pullback. -/ def pullbackIsPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsLimit (PullbackCone.mk (pullback.fst f g) (pullback.snd f g) pullback.condition) := PullbackCone.mkSelfIsLimit <| pullback.isLimit f g /-- Two morphisms out of a pushout are equal if their compositions with the pushout morphisms are equal -/ @[ext 1100] theorem pushout.hom_ext {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] {W : C} {k l : pushout f g ⟶ W} (h₀ : pushout.inl _ _ ≫ k = pushout.inl _ _ ≫ l) (h₁ : pushout.inr _ _ ≫ k = pushout.inr _ _ ≫ l) : k = l := colimit.hom_ext <| PushoutCocone.coequalizer_ext _ h₀ h₁ /-- The pushout cocone built from the pushout coprojections is a pushout. -/ def pushoutIsPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : IsColimit (PushoutCocone.mk (pushout.inl f g) (pushout.inr _ _) pushout.condition) := PushoutCocone.IsColimit.mk _ (fun s => pushout.desc s.inl s.inr s.condition) (by simp) (by simp) (by cat_disch) @[simp] lemma pullback.lift_fst_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : lift (fst f g) (snd f g) condition = 𝟙 (pullback f g) := by apply hom_ext <;> simp @[simp] lemma pushout.desc_inl_inr {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : desc (inl f g) (inr f g) condition = 𝟙 (pushout f g) := by apply hom_ext <;> simp /-- Given such a diagram, then there is a natural morphism `W ×ₛ X ⟶ Y ×ₜ Z`. ``` W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z ``` -/ abbrev pullback.map {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : pullback f₁ f₂ ⟶ pullback g₁ g₂ := pullback.lift (pullback.fst f₁ f₂ ≫ i₁) (pullback.snd f₁ f₂ ≫ i₂) (by simp only [Category.assoc, ← eq₁, ← eq₂, pullback.condition_assoc]) /-- The canonical map `X ×ₛ Y ⟶ X ×ₜ Y` given `S ⟶ T`. -/ abbrev pullback.mapDesc {X Y S T : C} (f : X ⟶ S) (g : Y ⟶ S) (i : S ⟶ T) [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] : pullback f g ⟶ pullback (f ≫ i) (g ≫ i) := pullback.map f g (f ≫ i) (g ≫ i) (𝟙 _) (𝟙 _) i (Category.id_comp _).symm (Category.id_comp _).symm @[reassoc] lemma pullback.map_comp {X Y Z X' Y' Z' X'' Y'' Z'' : C} {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} {f'' : X'' ⟶ Z''} {g'' : Y'' ⟶ Z''} (i₁ : X ⟶ X') (j₁ : X' ⟶ X'') (i₂ : Y ⟶ Y') (j₂ : Y' ⟶ Y'') (i₃ : Z ⟶ Z') (j₃ : Z' ⟶ Z'') [HasPullback f g] [HasPullback f' g'] [HasPullback f'' g''] (e₁ e₂ e₃ e₄) : pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂ ≫ pullback.map f' g' f'' g'' j₁ j₂ j₃ e₃ e₄ = pullback.map f g f'' g'' (i₁ ≫ j₁) (i₂ ≫ j₂) (i₃ ≫ j₃) (by rw [reassoc_of% e₁, e₃, Category.assoc]) (by rw [reassoc_of% e₂, e₄, Category.assoc]) := by ext <;> simp @[simp] lemma pullback.map_id {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback.map f g f g (𝟙 _) (𝟙 _) (𝟙 _) (by simp) (by simp) = 𝟙 _ := by ext <;> simp /-- Given such a diagram, then there is a natural morphism `W ⨿ₛ X ⟶ Y ⨿ₜ Z`. ``` W ⟶ Y ↗ ↗ S ⟶ T ↘ ↘ X ⟶ Z ``` -/ abbrev pushout.map {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) : pushout f₁ f₂ ⟶ pushout g₁ g₂ := pushout.desc (i₁ ≫ pushout.inl _ _) (i₂ ≫ pushout.inr _ _) (by simp only [reassoc_of% eq₁, reassoc_of% eq₂, condition]) /-- The canonical map `X ⨿ₛ Y ⟶ X ⨿ₜ Y` given `S ⟶ T`. -/ abbrev pushout.mapLift {X Y S T : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] : pushout (i ≫ f) (i ≫ g) ⟶ pushout f g := pushout.map (i ≫ f) (i ≫ g) f g (𝟙 _) (𝟙 _) i (Category.comp_id _) (Category.comp_id _) @[reassoc] lemma pushout.map_comp {X Y Z X' Y' Z' X'' Y'' Z'' : C} {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'} {f'' : X'' ⟶ Y''} {g'' : X'' ⟶ Z''} (i₁ : X ⟶ X') (j₁ : X' ⟶ X'') (i₂ : Y ⟶ Y') (j₂ : Y' ⟶ Y'') (i₃ : Z ⟶ Z') (j₃ : Z' ⟶ Z'') [HasPushout f g] [HasPushout f' g'] [HasPushout f'' g''] (e₁ e₂ e₃ e₄) : pushout.map f g f' g' i₂ i₃ i₁ e₁ e₂ ≫ pushout.map f' g' f'' g'' j₂ j₃ j₁ e₃ e₄ = pushout.map f g f'' g'' (i₂ ≫ j₂) (i₃ ≫ j₃) (i₁ ≫ j₁) (by rw [reassoc_of% e₁, e₃, Category.assoc]) (by rw [reassoc_of% e₂, e₄, Category.assoc]) := by ext <;> simp @[simp] lemma pushout.map_id {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : pushout.map f g f g (𝟙 _) (𝟙 _) (𝟙 _) (by simp) (by simp) = 𝟙 _ := by ext <;> simp instance pullback.map_isIso {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pullback.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · cat_disch · cat_disch /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pullback f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pullback.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : pullback f₁ g₁ ≅ pullback f₂ g₂ := asIso <| pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) @[simp] theorem pullback.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : (pullback.congrHom h₁ h₂).inv = pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext <;> simp [Iso.inv_comp_eq] instance pushout.map_isIso {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pushout.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pushout.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · cat_disch · cat_disch theorem pullback.mapDesc_comp {X Y S T S' : C} (f : X ⟶ T) (g : Y ⟶ T) (i : T ⟶ S) (i' : S ⟶ S') [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] [HasPullback (f ≫ i ≫ i') (g ≫ i ≫ i')] [HasPullback ((f ≫ i) ≫ i') ((g ≫ i) ≫ i')] : pullback.mapDesc f g (i ≫ i') = pullback.mapDesc f g i ≫ pullback.mapDesc _ _ i' ≫ (pullback.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom := by cat_disch /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pushout f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pushout.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : pushout f₁ g₁ ≅ pushout f₂ g₂ := asIso <| pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) @[simp] theorem pushout.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : (pushout.congrHom h₁ h₂).inv = pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext <;> simp [Iso.comp_inv_eq] theorem pushout.mapLift_comp {X Y S T S' : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) (i' : S' ⟶ S) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] [HasPushout (i' ≫ i ≫ f) (i' ≫ i ≫ g)] [HasPushout ((i' ≫ i) ≫ f) ((i' ≫ i) ≫ g)] : pushout.mapLift f g (i' ≫ i) = (pushout.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom ≫ pushout.mapLift _ _ i' ≫ pushout.mapLift f g i := by cat_disch section variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) /-- The comparison morphism for the pullback of `f,g`. This is an isomorphism iff `G` preserves the pullback of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : G.obj (pullback f g) ⟶ pullback (G.map f) (G.map g) := pullback.lift (G.map (pullback.fst f g)) (G.map (pullback.snd f g)) (by simp only [← G.map_comp, pullback.condition]) @[reassoc (attr := simp)] theorem pullbackComparison_comp_fst (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.fst _ _ = G.map (pullback.fst f g) := pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem pullbackComparison_comp_snd (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.snd _ _ = G.map (pullback.snd f g) := pullback.lift_snd _ _ _ @[reassoc (attr := simp)] theorem map_lift_pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] {W : C} {h : W ⟶ X} {k : W ⟶ Y} (w : h ≫ f = k ≫ g) : G.map (pullback.lift _ _ w) ≫ pullbackComparison G f g = pullback.lift (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] /-- The comparison morphism for the pushout of `f,g`. This is an isomorphism iff `G` preserves the pushout of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout (G.map f) (G.map g) ⟶ G.obj (pushout f g) := pushout.desc (G.map (pushout.inl _ _)) (G.map (pushout.inr _ _)) (by simp only [← G.map_comp, pushout.condition]) @[reassoc (attr := simp)] theorem inl_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inl _ _ ≫ pushoutComparison G f g = G.map (pushout.inl _ _) := pushout.inl_desc _ _ _ @[reassoc (attr := simp)] theorem inr_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inr _ _ ≫ pushoutComparison G f g = G.map (pushout.inr _ _) := pushout.inr_desc _ _ _ @[reassoc (attr := simp)] theorem pushoutComparison_map_desc (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] {W : C} {h : Y ⟶ W} {k : Z ⟶ W} (w : f ≫ h = g ≫ k) : pushoutComparison G f g ≫ G.map (pushout.desc _ _ w) = pushout.desc (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] end section PullbackSymmetry open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPullback_symmetry [HasPullback f g] : HasPullback g f := ⟨⟨⟨_, PullbackCone.flipIsLimit (pullbackIsPullback f g)⟩⟩⟩ attribute [local instance] hasPullback_symmetry /-- The isomorphism `X ×[Z] Y ≅ Y ×[Z] X`. -/ def pullbackSymmetry [HasPullback f g] : pullback f g ≅ pullback g f := IsLimit.conePointUniqueUpToIso (PullbackCone.flipIsLimit (pullbackIsPullback f g)) (limit.isLimit _) @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_fst [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.fst g f = pullback.snd f g := by simp [pullbackSymmetry] @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_snd [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.snd g f = pullback.fst f g := by simp [pullbackSymmetry] @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_fst [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.fst f g = pullback.snd g f := by simp [Iso.inv_comp_eq] @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_snd [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.snd f g = pullback.fst g f := by simp [Iso.inv_comp_eq] end PullbackSymmetry section PushoutSymmetry open WalkingCospan variable (f : X ⟶ Y) (g : X ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPushout_symmetry [HasPushout f g] : HasPushout g f := ⟨⟨⟨_, PushoutCocone.flipIsColimit (pushoutIsPushout f g)⟩⟩⟩ attribute [local instance] hasPushout_symmetry /-- The isomorphism `Y ⨿[X] Z ≅ Z ⨿[X] Y`. -/ def pushoutSymmetry [HasPushout f g] : pushout f g ≅ pushout g f := IsColimit.coconePointUniqueUpToIso (PushoutCocone.flipIsColimit (pushoutIsPushout f g)) (colimit.isColimit _) @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inl _ _ ≫ (pushoutSymmetry f g).hom = pushout.inr _ _ := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ @[reassoc (attr := simp)] theorem inr_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inr _ _ ≫ (pushoutSymmetry f g).hom = pushout.inl _ _ := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inl _ _ ≫ (pushoutSymmetry f g).inv = pushout.inr _ _ := by simp [Iso.comp_inv_eq] @[reassoc (attr := simp)] theorem inr_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inr _ _ ≫ (pushoutSymmetry f g).inv = pushout.inl _ _ := by simp [Iso.comp_inv_eq] end PushoutSymmetry /-- `HasPullbacksAlong f` states that pullbacks of all morphisms into `Y` along `f : X ⟶ Y` exist. -/ abbrev HasPullbacksAlong (f : X ⟶ Y) : Prop := ∀ {W} (h : W ⟶ Y), HasPullback h f /-- `HasPushoutsAlong f` states that pushouts of all morphisms out of `X` along `f : X ⟶ Y` exist. -/ abbrev HasPushoutsAlong (f : X ⟶ Y) : Prop := ∀ {W} (h : X ⟶ W), HasPushout h f variable (C) /-- A category `HasPullbacks` if it has all limits of shape `WalkingCospan`, i.e. if it has a pullback for every pair of morphisms with the same codomain. -/ @[stacks 001W] abbrev HasPullbacks := HasLimitsOfShape WalkingCospan C /-- A category `HasPushouts` if it has all colimits of shape `WalkingSpan`, i.e. if it has a pushout for every pair of morphisms with the same domain. -/ abbrev HasPushouts := HasColimitsOfShape WalkingSpan C /-- If `C` has all limits of diagrams `cospan f g`, then it has all pullbacks -/ theorem hasPullbacks_of_hasLimit_cospan [∀ {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z}, HasLimit (cospan f g)] : HasPullbacks C := { has_limit := fun F => hasLimit_of_iso (diagramIsoCospan F).symm } /-- If `C` has all colimits of diagrams `span f g`, then it has all pushouts -/ theorem hasPushouts_of_hasColimit_span [∀ {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z}, HasColimit (span f g)] : HasPushouts C := { has_colimit := fun F => hasColimit_of_iso (diagramIsoSpan F) } /-- The duality equivalence `WalkingSpanᵒᵖ ≌ WalkingCospan` -/ @[simps!] def walkingSpanOpEquiv : WalkingSpanᵒᵖ ≌ WalkingCospan := widePushoutShapeOpEquiv _ /-- The duality equivalence `WalkingCospanᵒᵖ ≌ WalkingSpan` -/ @[simps!] def walkingCospanOpEquiv : WalkingCospanᵒᵖ ≌ WalkingSpan := widePullbackShapeOpEquiv _ -- see Note [lower instance priority] /-- Having wide pullback at any universe level implies having binary pullbacks. -/ instance (priority := 100) hasPullbacks_of_hasWidePullbacks (D : Type u) [Category.{v} D] [HasWidePullbacks.{w} D] : HasPullbacks.{v, u} D := hasWidePullbacks_shrink WalkingPair -- see Note [lower instance priority] /-- Having wide pushout at any universe level implies having binary pushouts. -/ instance (priority := 100) hasPushouts_of_hasWidePushouts (D : Type u) [Category.{v} D] [HasWidePushouts.{w} D] : HasPushouts.{v, u} D := hasWidePushouts_shrink WalkingPair end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Assoc.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Pasting /-! # Associativity of pullbacks This file shows that pullbacks (and pushouts) are associative up to natural isomorphism. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] section PullbackAssoc /- The objects and morphisms are as follows: ``` Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ ``` where the two squares are pullbacks. We can then construct the pullback squares ``` W - l₂ -> Z₂ - g₄ -> X₃ | | l₁ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ ``` and ``` W' - l₂' -> Z₂ | | l₁' g₃ ∨ ∨ Z₁ X₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ ``` We will show that both `W` and `W'` are pullbacks over `g₁, g₂`, and thus we may construct a canonical isomorphism between them. -/ variable {X₁ X₂ X₃ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₁) (f₃ : X₂ ⟶ Y₂) variable (f₄ : X₃ ⟶ Y₂) [HasPullback f₁ f₂] [HasPullback f₃ f₄] local notation "Z₁" => pullback f₁ f₂ local notation "Z₂" => pullback f₃ f₄ local notation "g₁" => (pullback.fst _ _ : Z₁ ⟶ X₁) local notation "g₂" => (pullback.snd _ _ : Z₁ ⟶ X₂) local notation "g₃" => (pullback.fst _ _ : Z₂ ⟶ X₂) local notation "g₄" => (pullback.snd _ _ : Z₂ ⟶ X₃) local notation "W" => pullback (g₂ ≫ f₃) f₄ local notation "W'" => pullback f₁ (g₃ ≫ f₂) local notation "l₁" => (pullback.fst _ _ : W ⟶ Z₁) local notation "l₂" => (pullback.lift (pullback.fst _ _ ≫ g₂) (pullback.snd _ _) (Eq.trans (Category.assoc _ _ _) pullback.condition) : W ⟶ Z₂) local notation "l₁'" => (pullback.lift (pullback.fst _ _) (pullback.snd _ _ ≫ g₃) (pullback.condition.trans (Eq.symm (Category.assoc _ _ _))) : W' ⟶ Z₁) local notation "l₂'" => (pullback.snd f₁ (g₃ ≫ f₂)) /-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/ def pullbackPullbackLeftIsPullback [HasPullback (g₂ ≫ f₃) f₄] : IsLimit (PullbackCone.mk l₁ l₂ (show l₁ ≫ g₂ = l₂ ≫ g₃ from (pullback.lift_fst _ _ _).symm)) := by apply leftSquareIsPullback _ rfl (pullbackIsPullback f₃ f₄) simpa [PullbackCone.pasteHoriz] using PullbackCone.mkSelfIsLimit (pullbackIsPullback _ f₄) /-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/ def pullbackAssocIsPullback [HasPullback (g₂ ≫ f₃) f₄] : IsLimit (PullbackCone.mk (l₁ ≫ g₁) l₂ (show (l₁ ≫ g₁) ≫ f₁ = l₂ ≫ g₃ ≫ f₂ by rw [pullback.lift_fst_assoc, Category.assoc, Category.assoc, pullback.condition])) := by simpa using pasteVertIsPullback rfl (pullbackIsPullback _ _) (pullbackPullbackLeftIsPullback f₁ f₂ f₃ f₄) theorem hasPullback_assoc [HasPullback (g₂ ≫ f₃) f₄] : HasPullback f₁ (g₃ ≫ f₂) := ⟨⟨⟨_, pullbackAssocIsPullback f₁ f₂ f₃ f₄⟩⟩⟩ /-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/ def pullbackPullbackRightIsPullback [HasPullback f₁ (g₃ ≫ f₂)] : IsLimit (PullbackCone.mk l₁' l₂' (show l₁' ≫ g₂ = l₂' ≫ g₃ from pullback.lift_snd _ _ _)) := by apply topSquareIsPullback _ rfl (pullbackIsPullback f₁ f₂) simpa [PullbackCone.pasteVert] using PullbackCone.mkSelfIsLimit (pullbackIsPullback _ _) /-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[Y₂] X₃`. -/ def pullbackAssocSymmIsPullback [HasPullback f₁ (g₃ ≫ f₂)] : IsLimit (PullbackCone.mk l₁' (l₂' ≫ g₄) (show l₁' ≫ g₂ ≫ f₃ = (l₂' ≫ g₄) ≫ f₄ by rw [pullback.lift_snd_assoc, Category.assoc, Category.assoc, pullback.condition])) := by simpa [PullbackCone.pasteHoriz] using pasteHorizIsPullback rfl (pullbackIsPullback f₃ f₄) (pullbackPullbackRightIsPullback _ _ _ _) theorem hasPullback_assoc_symm [HasPullback f₁ (g₃ ≫ f₂)] : HasPullback (g₂ ≫ f₃) f₄ := ⟨⟨⟨_, pullbackAssocSymmIsPullback f₁ f₂ f₃ f₄⟩⟩⟩ /-- The canonical isomorphism `(X₁ ×[Y₁] X₂) ×[Y₂] X₃ ≅ X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/ noncomputable def pullbackAssoc [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : pullback (pullback.snd _ _ ≫ f₃ : pullback f₁ f₂ ⟶ _) f₄ ≅ pullback f₁ (pullback.fst _ _ ≫ f₂ : pullback f₃ f₄ ⟶ _) := (pullbackPullbackLeftIsPullback f₁ f₂ f₃ f₄).conePointUniqueUpToIso (pullbackPullbackRightIsPullback f₁ f₂ f₃ f₄) @[reassoc (attr := simp)] theorem pullbackAssoc_inv_fst_fst [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := by trans l₁' ≫ pullback.fst _ _ · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left · exact pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem pullbackAssoc_hom_fst [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by rw [← Iso.eq_inv_comp, pullbackAssoc_inv_fst_fst] @[reassoc (attr := simp)] theorem pullbackAssoc_hom_snd_fst [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by trans l₂ ≫ pullback.fst _ _ · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right · exact pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem pullbackAssoc_hom_snd_snd [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := by trans l₂ ≫ pullback.snd _ _ · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right · exact pullback.lift_snd _ _ _ @[reassoc (attr := simp)] theorem pullbackAssoc_inv_fst_snd [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by rw [Iso.inv_comp_eq, pullbackAssoc_hom_snd_fst] @[reassoc (attr := simp)] theorem pullbackAssoc_inv_snd [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by rw [Iso.inv_comp_eq, pullbackAssoc_hom_snd_snd] end PullbackAssoc section PushoutAssoc /- The objects and morphisms are as follows: ``` Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ ``` where the two squares are pushouts. We can then construct the pushout squares ``` Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ l₂ ∨ ∨ X₁ - f₁ -> Y₁ - l₁ -> W and Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ X₂ Y₂ | | f₂ l₂' ∨ ∨ Y₁ - l₁' -> W' ``` We will show that both `W` and `W'` are pushouts over `f₂, f₃`, and thus we may construct a canonical isomorphism between them. -/ variable {X₁ X₂ X₃ Z₁ Z₂ : C} (g₁ : Z₁ ⟶ X₁) (g₂ : Z₁ ⟶ X₂) (g₃ : Z₂ ⟶ X₂) variable (g₄ : Z₂ ⟶ X₃) [HasPushout g₁ g₂] [HasPushout g₃ g₄] local notation "Y₁" => pushout g₁ g₂ local notation "Y₂" => pushout g₃ g₄ local notation "f₁" => (pushout.inl _ _ : X₁ ⟶ Y₁) local notation "f₂" => (pushout.inr _ _ : X₂ ⟶ Y₁) local notation "f₃" => (pushout.inl _ _ : X₂ ⟶ Y₂) local notation "f₄" => (pushout.inr _ _ : X₃ ⟶ Y₂) local notation "W" => pushout g₁ (g₂ ≫ f₃) local notation "W'" => pushout (g₃ ≫ f₂) g₄ local notation "l₁" => (pushout.desc (pushout.inl _ _) (f₃ ≫ pushout.inr _ _) (pushout.condition.trans (Category.assoc _ _ _)) : Y₁ ⟶ W) local notation "l₂" => (pushout.inr _ _ : Y₂ ⟶ W) local notation "l₁'" => (pushout.inl _ _ : Y₁ ⟶ W') local notation "l₂'" => (pushout.desc (f₂ ≫ pushout.inl _ _) (pushout.inr _ _) (Eq.trans (Eq.symm (Category.assoc _ _ _)) pushout.condition) : Y₂ ⟶ W') /-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutPushoutLeftIsPushout [HasPushout (g₃ ≫ f₂) g₄] : IsColimit (PushoutCocone.mk l₁' l₂' (show f₂ ≫ l₁' = f₃ ≫ l₂' from (pushout.inl_desc _ _ _).symm)) := by apply botSquareIsPushout _ rfl (pushoutIsPushout _ g₄) simpa [PushoutCocone.pasteVert] using PushoutCocone.mkSelfIsColimit (pushoutIsPushout (g₃ ≫ f₂) g₄) /-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutAssocIsPushout [HasPushout (g₃ ≫ f₂) g₄] : IsColimit (PushoutCocone.mk (f₁ ≫ l₁') l₂' (show g₁ ≫ f₁ ≫ l₁' = (g₂ ≫ f₃) ≫ l₂' by rw [Category.assoc, pushout.inl_desc, pushout.condition_assoc])) := by simpa using pasteHorizIsPushout rfl (pushoutIsPushout g₁ g₂) (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄) theorem hasPushout_assoc [HasPushout (g₃ ≫ f₂) g₄] : HasPushout g₁ (g₂ ≫ f₃) := ⟨⟨⟨_, pushoutAssocIsPushout g₁ g₂ g₃ g₄⟩⟩⟩ /-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutPushoutRightIsPushout [HasPushout g₁ (g₂ ≫ f₃)] : IsColimit (PushoutCocone.mk l₁ l₂ (show f₂ ≫ l₁ = f₃ ≫ l₂ from pushout.inr_desc _ _ _)) := by apply rightSquareIsPushout _ rfl (pushoutIsPushout _ _) simpa [PushoutCocone.pasteHoriz] using PushoutCocone.mkSelfIsColimit (pushoutIsPushout _ _) /-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃`. -/ def pushoutAssocSymmIsPushout [HasPushout g₁ (g₂ ≫ f₃)] : IsColimit (PushoutCocone.mk l₁ (f₄ ≫ l₂) (show (g₃ ≫ f₂) ≫ l₁ = g₄ ≫ f₄ ≫ l₂ by rw [Category.assoc, pushout.inr_desc, pushout.condition_assoc])) := by simpa using pasteVertIsPushout rfl (pushoutIsPushout _ _) (pushoutPushoutRightIsPushout _ _ _ _) theorem hasPushout_assoc_symm [HasPushout g₁ (g₂ ≫ f₃)] : HasPushout (g₃ ≫ f₂) g₄ := ⟨⟨⟨_, pushoutAssocSymmIsPushout g₁ g₂ g₃ g₄⟩⟩⟩ /-- The canonical isomorphism `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃ ≅ X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/ noncomputable def pushoutAssoc [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout (g₃ ≫ pushout.inr _ _ : _ ⟶ pushout g₁ g₂) g₄ ≅ pushout g₁ (g₂ ≫ pushout.inl _ _ : _ ⟶ pushout g₃ g₄) := (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).coconePointUniqueUpToIso (pushoutPushoutRightIsPushout g₁ g₂ g₃ g₄) @[reassoc (attr := simp)] theorem inl_inl_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inl _ _ ≫ pushout.inl _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inl _ _ := by trans f₁ ≫ l₁ · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_hom _ WalkingCospan.left · exact pushout.inl_desc _ _ _ @[reassoc (attr := simp)] theorem inr_inl_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inr _ _ ≫ pushout.inl _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inl _ _ ≫ pushout.inr _ _ := by trans f₂ ≫ l₁ · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_hom _ WalkingCospan.left · exact pushout.inr_desc _ _ _ @[reassoc (attr := simp)] theorem inr_inr_pushoutAssoc_inv [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inr _ _ ≫ pushout.inr _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).inv = pushout.inr _ _ := by trans f₄ ≫ l₂' · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_inv (pushoutPushoutRightIsPushout g₁ g₂ g₃ g₄) WalkingCospan.right · exact pushout.inr_desc _ _ _ @[reassoc (attr := simp)] theorem inl_pushoutAssoc_inv [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inl _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).inv = pushout.inl _ _ ≫ pushout.inl _ _ := by rw [Iso.comp_inv_eq, Category.assoc, inl_inl_pushoutAssoc_hom] @[reassoc (attr := simp)] theorem inl_inr_pushoutAssoc_inv [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inl _ _ ≫ pushout.inr _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).inv = pushout.inr _ _ ≫ pushout.inl _ _ := by rw [← Category.assoc, Iso.comp_inv_eq, Category.assoc, inr_inl_pushoutAssoc_hom] @[reassoc (attr := simp)] theorem inr_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inr _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inr _ _ ≫ pushout.inr _ _ := by rw [← Iso.eq_comp_inv, Category.assoc, inr_inr_pushoutAssoc_inv] end PushoutAssoc end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/PullbackCone.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Cospan /-! # PullbackCone This file provides API for interacting with cones (resp. cocones) in the case of pullbacks (resp. pushouts). ## Main definitions * `PullbackCone f g`: Given morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`, a term `t : PullbackCone f g` provides the data of a cone pictured as follows ``` t.pt ---t.snd---> Y | | t.fst g | | v v X -----f------> Z ``` The type `PullbackCone f g` is implemented as an abbreviation for `Cone (cospan f g)`, so general results about cones are also available for `PullbackCone f g`. * `PushoutCone f g`: Given morphisms `f : X ⟶ Y` and `g : X ⟶ Z`, a term `t : PushoutCone f g` provides the data of a cocone pictured as follows ``` X -----f------> Y | | g t.inr | | v v Z ---t.inl---> t.pt ``` Similar to `PullbackCone`, `PushoutCone f g` is implemented as an abbreviation for `Cocone (span f g)`, so general results about cocones are also available for `PushoutCone f g`. ## API We summarize the most important parts of the API for pullback cones here. The dual notions for pushout cones is also available in this file. Various ways of constructing pullback cones: * `PullbackCone.mk` constructs a term of `PullbackCone f g` given morphisms `fst` and `snd` such that `fst ≫ f = snd ≫ g`. * `PullbackCone.flip` is the `PullbackCone` obtained by flipping `fst` and `snd`. Interaction with `IsLimit`: * `PullbackCone.isLimitAux` and `PullbackCone.isLimitAux'` provide two convenient ways to show that a given `PullbackCone` is a limit cone. * `PullbackCone.isLimit.mk` provides a convenient way to show that a `PullbackCone` constructed using `PullbackCone.mk` is a limit cone. * `PullbackCone.IsLimit.lift` and `PullbackCone.IsLimit.lift'` provides convenient ways for constructing the morphisms to the point of a limit `PullbackCone` from the universal property. * `PullbackCone.IsLimit.hom_ext` provides a convenient way to show that two morphisms to the point of a limit `PullbackCone` are equal. ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] {W X Y Z : C} /-- A pullback cone is just a cone on the cospan formed by two morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`. -/ abbrev PullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) := Cone (cospan f g) namespace PullbackCone variable {f : X ⟶ Z} {g : Y ⟶ Z} /-- The first projection of a pullback cone. -/ abbrev fst (t : PullbackCone f g) : t.pt ⟶ X := t.π.app WalkingCospan.left /-- The second projection of a pullback cone. -/ abbrev snd (t : PullbackCone f g) : t.pt ⟶ Y := t.π.app WalkingCospan.right theorem π_app_left (c : PullbackCone f g) : c.π.app WalkingCospan.left = c.fst := rfl theorem π_app_right (c : PullbackCone f g) : c.π.app WalkingCospan.right = c.snd := rfl @[simp] theorem condition_one (t : PullbackCone f g) : t.π.app WalkingCospan.one = t.fst ≫ f := by have w := t.π.naturality WalkingCospan.Hom.inl dsimp at w; simpa using w /-- A pullback cone on `f` and `g` is determined by morphisms `fst : W ⟶ X` and `snd : W ⟶ Y` such that `fst ≫ f = snd ≫ g`. -/ @[simps] def mk {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : PullbackCone f g where pt := W π := { app := fun j => Option.casesOn j (fst ≫ f) fun j' => WalkingPair.casesOn j' fst snd naturality := by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) j <;> cases j <;> simp [eq] } @[simp] theorem mk_π_app_left {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.left = fst := rfl @[simp] theorem mk_π_app_right {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.right = snd := rfl @[simp] theorem mk_π_app_one {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.one = fst ≫ f := rfl @[simp] theorem mk_fst {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).fst = fst := rfl @[simp] theorem mk_snd {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).snd = snd := rfl @[reassoc] theorem condition (t : PullbackCone f g) : fst t ≫ f = snd t ≫ g := (t.w inl).trans (t.w inr).symm /-- To check whether two morphisms are equalized by the maps of a pullback cone, it suffices to check it for `fst t` and `snd t` -/ theorem equalizer_ext (t : PullbackCone f g) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : ∀ j : WalkingCospan, k ≫ t.π.app j = l ≫ t.π.app j | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w inl, reassoc_of% h₀] /-- To construct an isomorphism of pullback cones, it suffices to construct an isomorphism of the cone points and check it commutes with `fst` and `snd`. -/ def ext {s t : PullbackCone f g} (i : s.pt ≅ t.pt) (w₁ : s.fst = i.hom ≫ t.fst := by cat_disch) (w₂ : s.snd = i.hom ≫ t.snd := by cat_disch) : s ≅ t := WalkingCospan.ext i w₁ w₂ /-- The natural isomorphism between a pullback cone and the corresponding pullback cone reconstructed using `PullbackCone.mk`. -/ @[simps!] def eta (t : PullbackCone f g) : t ≅ mk t.fst t.snd t.condition := PullbackCone.ext (Iso.refl _) /-- This is a slightly more convenient method to verify that a pullback cone is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : PullbackCone f g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ t.pt) (fac_left : ∀ s : PullbackCone f g, lift s ≫ t.fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ t.snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ t.pt) (_ : ∀ j : WalkingCospan, m ≫ t.π.app j = s.π.app j), m = lift s) : IsLimit t := { lift fac := fun s j => Option.casesOn j (by rw [← s.w inl, ← t.w inl, ← Category.assoc] congr exact fac_left s) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } /-- This is another convenient method to verify that a pullback cone 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 isLimitAux' (t : PullbackCone f g) (create : ∀ s : PullbackCone f g, { l // l ≫ t.fst = s.fst ∧ l ≫ t.snd = s.snd ∧ ∀ {m}, m ≫ t.fst = s.fst → m ≫ t.snd = s.snd → m = l }) : Limits.IsLimit t := PullbackCone.isLimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) /-- This is a more convenient formulation to show that a `PullbackCone` constructed using `PullbackCone.mk` is a limit cone. -/ def IsLimit.mk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (eq : fst ≫ f = snd ≫ g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ W) (fac_left : ∀ s : PullbackCone f g, lift s ≫ fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (mk fst snd eq) := isLimitAux _ lift fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) theorem IsLimit.hom_ext {t : PullbackCone f g} (ht : IsLimit t) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : k = l := ht.hom_ext <| equalizer_ext _ h₀ h₁ /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we get `l : W ⟶ t.pt`, which satisfies `l ≫ fst t = h` and `l ≫ snd t = k`, see `IsLimit.lift_fst` and `IsLimit.lift_snd`. -/ def IsLimit.lift {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ t.pt := ht.lift <| PullbackCone.mk _ _ w @[reassoc (attr := simp)] lemma IsLimit.lift_fst {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ fst t = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsLimit.lift_snd {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ snd t = k := ht.fac _ _ /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we have `l : W ⟶ t.pt` satisfying `l ≫ fst t = h` and `l ≫ snd t = k`. -/ def IsLimit.lift' {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ t.pt // l ≫ fst t = h ∧ l ≫ snd t = k } := ⟨IsLimit.lift ht h k w, by simp⟩ /-- The pullback cone reconstructed using `PullbackCone.mk` from a pullback cone that is a limit, is also a limit. -/ def mkSelfIsLimit {t : PullbackCone f g} (ht : IsLimit t) : IsLimit (mk t.fst t.snd t.condition) := IsLimit.ofIsoLimit ht (eta t) section Flip variable (t : PullbackCone f g) /-- The pullback cone obtained by flipping `fst` and `snd`. -/ def flip : PullbackCone g f := PullbackCone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_fst : t.flip.fst = t.snd := rfl @[simp] lemma flip_snd : t.flip.snd = t.fst := rfl /-- Flipping a pullback cone twice gives an isomorphic cone. -/ def flipFlipIso : t.flip.flip ≅ t := PullbackCone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pullback square is a pullback square. -/ def flipIsLimit (ht : IsLimit t) : IsLimit t.flip := IsLimit.mk _ (fun s => ht.lift s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsLimit.hom_ext ht <;> simp [h₁, h₂]) /-- A square is a pullback square if its flip is. -/ def isLimitOfFlip (ht : IsLimit t.flip) : IsLimit t := IsLimit.ofIsoLimit (flipIsLimit ht) t.flipFlipIso end Flip end PullbackCone /-- This is a helper construction that can be useful when verifying that a category has all pullbacks. Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a pullback cone on `F.map inl` and `F.map inr`, we get a cone on `F`. If you're thinking about using this, have a look at `hasPullbacks_of_hasLimit_cospan`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cone.ofPullbackCone {F : WalkingCospan ⥤ C} (t : PullbackCone (F.map inl) (F.map inr)) : Cone F where pt := t.pt π := t.π ≫ (diagramIsoCospan F).inv /-- Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a cone on `F`, we get a pullback cone on `F.map inl` and `F.map inr`. -/ @[simps] def PullbackCone.ofCone {F : WalkingCospan ⥤ C} (t : Cone F) : PullbackCone (F.map inl) (F.map inr) where pt := t.pt π := t.π ≫ (diagramIsoCospan F).hom /-- A diagram `WalkingCospan ⥤ C` is isomorphic to some `PullbackCone.mk` after composing with `diagramIsoCospan`. -/ @[simps!] def PullbackCone.isoMk {F : WalkingCospan ⥤ C} (t : Cone F) : (Cones.postcompose (diagramIsoCospan.{v} _).hom).obj t ≅ PullbackCone.mk (t.π.app WalkingCospan.left) (t.π.app WalkingCospan.right) ((t.π.naturality inl).symm.trans (t.π.naturality inr :)) := Cones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> simp /-- A pushout cocone is just a cocone on the span formed by two morphisms `f : X ⟶ Y` and `g : X ⟶ Z`. -/ abbrev PushoutCocone (f : X ⟶ Y) (g : X ⟶ Z) := Cocone (span f g) namespace PushoutCocone variable {f : X ⟶ Y} {g : X ⟶ Z} /-- The first inclusion of a pushout cocone. -/ abbrev inl (t : PushoutCocone f g) : Y ⟶ t.pt := t.ι.app WalkingSpan.left /-- The second inclusion of a pushout cocone. -/ abbrev inr (t : PushoutCocone f g) : Z ⟶ t.pt := t.ι.app WalkingSpan.right -- This cannot be `@[simp]` because `c.inl` is reducibly defeq to the LHS. theorem ι_app_left (c : PushoutCocone f g) : c.ι.app WalkingSpan.left = c.inl := rfl -- This cannot be `@[simp]` because `c.inr` is reducibly defeq to the LHS. theorem ι_app_right (c : PushoutCocone f g) : c.ι.app WalkingSpan.right = c.inr := rfl @[simp] theorem condition_zero (t : PushoutCocone f g) : t.ι.app WalkingSpan.zero = f ≫ t.inl := by have w := t.ι.naturality WalkingSpan.Hom.fst dsimp at w; simpa using w.symm /-- A pushout cocone on `f` and `g` is determined by morphisms `inl : Y ⟶ W` and `inr : Z ⟶ W` such that `f ≫ inl = g ↠ inr`. -/ @[simps] def mk {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : PushoutCocone f g where pt := W ι := { app := fun j => Option.casesOn j (f ≫ inl) fun j' => WalkingPair.casesOn j' inl inr naturality := by rintro (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) <;> intro f <;> cases f <;> dsimp <;> aesop } @[simp] theorem mk_ι_app_left {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.left = inl := rfl @[simp] theorem mk_ι_app_right {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.right = inr := rfl @[simp] theorem mk_ι_app_zero {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.zero = f ≫ inl := rfl @[simp] theorem mk_inl {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inl = inl := rfl @[simp] theorem mk_inr {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inr = inr := rfl @[reassoc] theorem condition (t : PushoutCocone f g) : f ≫ inl t = g ≫ inr t := (t.w fst).trans (t.w snd).symm /-- To check whether a morphism is coequalized by the maps of a pushout cocone, it suffices to check it for `inl t` and `inr t` -/ theorem coequalizer_ext (t : PushoutCocone f g) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : ∀ j : WalkingSpan, t.ι.app j ≫ k = t.ι.app j ≫ l | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w fst, Category.assoc, Category.assoc, h₀] /-- To construct an isomorphism of pushout cocones, it suffices to construct an isomorphism of the cocone points and check it commutes with `inl` and `inr`. -/ def ext {s t : PushoutCocone f g} (i : s.pt ≅ t.pt) (w₁ : s.inl ≫ i.hom = t.inl := by cat_disch) (w₂ : s.inr ≫ i.hom = t.inr := by cat_disch) : s ≅ t := WalkingSpan.ext i w₁ w₂ /-- The natural isomorphism between a pushout cocone and the corresponding pushout cocone reconstructed using `PushoutCocone.mk`. -/ @[simps!] def eta (t : PushoutCocone f g) : t ≅ mk t.inl t.inr t.condition := PushoutCocone.ext (Iso.refl _) /-- This is a slightly more convenient method to verify that a pushout cocone is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def isColimitAux (t : PushoutCocone f g) (desc : ∀ s : PushoutCocone f g, t.pt ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, t.inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, t.inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : t.pt ⟶ s.pt) (_ : ∀ j : WalkingSpan, t.ι.app j ≫ m = s.ι.app j), m = desc s) : IsColimit t := { desc fac := fun s j => Option.casesOn j (by simp [← s.w fst, ← t.w fst, fac_left s]) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } /-- This is another convenient method to verify that a pushout cocone 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 isColimitAux' (t : PushoutCocone f g) (create : ∀ s : PushoutCocone f g, { l // t.inl ≫ l = s.inl ∧ t.inr ≫ l = s.inr ∧ ∀ {m}, t.inl ≫ m = s.inl → t.inr ≫ m = s.inr → m = l }) : IsColimit t := isColimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) theorem IsColimit.hom_ext {t : PushoutCocone f g} (ht : IsColimit t) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : k = l := ht.hom_ext <| coequalizer_ext _ h₀ h₁ /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`, see `IsColimit.inl_desc` and `IsColimit.inr_desc`. -/ def IsColimit.desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : t.pt ⟶ W := ht.desc (PushoutCocone.mk _ _ w) @[reassoc (attr := simp)] lemma IsColimit.inl_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inl t ≫ IsColimit.desc ht h k w = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsColimit.inr_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inr t ≫ IsColimit.desc ht h k w = k := ht.fac _ _ /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`. -/ def IsColimit.desc' {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : t.pt ⟶ W // inl t ≫ l = h ∧ inr t ≫ l = k } := ⟨IsColimit.desc ht h k w, by simp⟩ /-- This is a more convenient formulation to show that a `PushoutCocone` constructed using `PushoutCocone.mk` is a colimit cocone. -/ def IsColimit.mk {W : C} {inl : Y ⟶ W} {inr : Z ⟶ W} (eq : f ≫ inl = g ≫ inr) (desc : ∀ s : PushoutCocone f g, W ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (mk inl inr eq) := isColimitAux _ desc fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) /-- The pushout cocone reconstructed using `PushoutCocone.mk` from a pushout cocone that is a colimit, is also a colimit. -/ def mkSelfIsColimit {t : PushoutCocone f g} (ht : IsColimit t) : IsColimit (mk t.inl t.inr t.condition) := IsColimit.ofIsoColimit ht (eta t) section Flip variable (t : PushoutCocone f g) /-- The pushout cocone obtained by flipping `inl` and `inr`. -/ def flip : PushoutCocone g f := PushoutCocone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_inl : t.flip.inl = t.inr := rfl @[simp] lemma flip_inr : t.flip.inr = t.inl := rfl /-- Flipping a pushout cocone twice gives an isomorphic cocone. -/ def flipFlipIso : t.flip.flip ≅ t := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pushout square is a pushout square. -/ def flipIsColimit (ht : IsColimit t) : IsColimit t.flip := IsColimit.mk _ (fun s => ht.desc s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsColimit.hom_ext ht <;> simp [h₁, h₂]) /-- A square is a pushout square if its flip is. -/ def isColimitOfFlip (ht : IsColimit t.flip) : IsColimit t := IsColimit.ofIsoColimit (flipIsColimit ht) t.flipFlipIso end Flip end PushoutCocone /-- This is a helper construction that can be useful when verifying that a category has all pushout. Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a pushout cocone on `F.map fst` and `F.map snd`, we get a cocone on `F`. If you're thinking about using this, have a look at `hasPushouts_of_hasColimit_span`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cocone.ofPushoutCocone {F : WalkingSpan ⥤ C} (t : PushoutCocone (F.map fst) (F.map snd)) : Cocone F where pt := t.pt ι := (diagramIsoSpan F).hom ≫ t.ι /-- Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a cocone on `F`, we get a pushout cocone on `F.map fst` and `F.map snd`. -/ @[simps] def PushoutCocone.ofCocone {F : WalkingSpan ⥤ C} (t : Cocone F) : PushoutCocone (F.map fst) (F.map snd) where pt := t.pt ι := (diagramIsoSpan F).inv ≫ t.ι /-- A diagram `WalkingSpan ⥤ C` is isomorphic to some `PushoutCocone.mk` after composing with `diagramIsoSpan`. -/ @[simps!] def PushoutCocone.isoMk {F : WalkingSpan ⥤ C} (t : Cocone F) : (Cocones.precompose (diagramIsoSpan.{v} _).inv).obj t ≅ PushoutCocone.mk (t.ι.app WalkingSpan.left) (t.ι.app WalkingSpan.right) ((t.ι.naturality fst).trans (t.ι.naturality snd).symm) := Cocones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> simp end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Square.lean
import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.CategoryTheory.Square import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Commutative squares that are pushout or pullback squares In this file, we translate the `IsPushout` and `IsPullback` API for the objects of the category `Square C` of commutative squares in a category `C`. We also obtain lemmas which states in this language that a pullback of a monomorphism is a monomorphism (and similarly for pushouts of epimorphisms). -/ universe v u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] namespace Square variable (sq : Square C) /-- The pullback cone attached to a commutative square. -/ abbrev pullbackCone : PullbackCone sq.f₂₄ sq.f₃₄ := PullbackCone.mk sq.f₁₂ sq.f₁₃ sq.fac /-- The pushout cocone attached to a commutative square. -/ abbrev pushoutCocone : PushoutCocone sq.f₁₂ sq.f₁₃ := PushoutCocone.mk sq.f₂₄ sq.f₃₄ sq.fac /-- The condition that a commutative square is a pullback square. -/ protected def IsPullback : Prop := IsPullback sq.f₁₂ sq.f₁₃ sq.f₂₄ sq.f₃₄ /-- The condition that a commutative square is a pushout square. -/ protected def IsPushout : Prop := IsPushout sq.f₁₂ sq.f₁₃ sq.f₂₄ sq.f₃₄ lemma isPullback_iff : sq.IsPullback ↔ Nonempty (IsLimit sq.pullbackCone) := ⟨fun h ↦ ⟨h.isLimit⟩, fun h ↦ { w := sq.fac, isLimit' := h }⟩ lemma isPushout_iff : sq.IsPushout ↔ Nonempty (IsColimit sq.pushoutCocone) := ⟨fun h ↦ ⟨h.isColimit⟩, fun h ↦ { w := sq.fac, isColimit' := h }⟩ lemma IsPullback.mk (h : IsLimit sq.pullbackCone) : sq.IsPullback := sq.isPullback_iff.2 ⟨h⟩ lemma IsPushout.mk (h : IsColimit sq.pushoutCocone) : sq.IsPushout := sq.isPushout_iff.2 ⟨h⟩ variable {sq} /-- If a commutative square `sq` is a pullback square, then `sq.pullbackCone` is limit. -/ noncomputable def IsPullback.isLimit (h : sq.IsPullback) : IsLimit sq.pullbackCone := CategoryTheory.IsPullback.isLimit h /-- If a commutative square `sq` is a pushout square, then `sq.pushoutCocone` is colimit. -/ noncomputable def IsPushout.isColimit (h : sq.IsPushout) : IsColimit sq.pushoutCocone := CategoryTheory.IsPushout.isColimit h lemma IsPullback.of_iso {sq₁ sq₂ : Square C} (h : sq₁.IsPullback) (e : sq₁ ≅ sq₂) : sq₂.IsPullback := by refine CategoryTheory.IsPullback.of_iso h (evaluation₁.mapIso e) (evaluation₂.mapIso e) (evaluation₃.mapIso e) (evaluation₄.mapIso e) ?_ ?_ ?_ ?_ all_goals simp lemma IsPullback.iff_of_iso {sq₁ sq₂ : Square C} (e : sq₁ ≅ sq₂) : sq₁.IsPullback ↔ sq₂.IsPullback := ⟨fun h ↦ h.of_iso e, fun h ↦ h.of_iso e.symm⟩ lemma IsPushout.of_iso {sq₁ sq₂ : Square C} (h : sq₁.IsPushout) (e : sq₁ ≅ sq₂) : sq₂.IsPushout := by refine CategoryTheory.IsPushout.of_iso h (evaluation₁.mapIso e) (evaluation₂.mapIso e) (evaluation₃.mapIso e) (evaluation₄.mapIso e) ?_ ?_ ?_ ?_ all_goals simp lemma IsPushout.iff_of_iso {sq₁ sq₂ : Square C} (e : sq₁ ≅ sq₂) : sq₁.IsPushout ↔ sq₂.IsPushout := ⟨fun h ↦ h.of_iso e, fun h ↦ h.of_iso e.symm⟩ lemma IsPushout.op {sq : Square C} (h : sq.IsPushout) : sq.op.IsPullback := CategoryTheory.IsPushout.op h.flip lemma IsPushout.unop {sq : Square Cᵒᵖ} (h : sq.IsPushout) : sq.unop.IsPullback := CategoryTheory.IsPushout.unop h.flip lemma IsPullback.op {sq : Square C} (h : sq.IsPullback) : sq.op.IsPushout := CategoryTheory.IsPullback.op h.flip lemma IsPullback.unop {sq : Square Cᵒᵖ} (h : sq.IsPullback) : sq.unop.IsPushout := CategoryTheory.IsPullback.unop h.flip namespace IsPullback variable (h : sq.IsPullback) include h lemma flip : sq.flip.IsPullback := CategoryTheory.IsPullback.flip h lemma mono_f₁₃ [Mono sq.f₂₄] : Mono sq.f₁₃ := (MorphismProperty.monomorphisms C).of_isPullback h (by assumption) lemma mono_f₁₂ [Mono sq.f₃₄] : Mono sq.f₁₂ := by have : Mono sq.flip.f₂₄ := by dsimp; infer_instance exact h.flip.mono_f₁₃ end IsPullback namespace IsPushout variable (h : sq.IsPushout) include h lemma flip : sq.flip.IsPushout := CategoryTheory.IsPushout.flip h lemma epi_f₂₄ [Epi sq.f₁₃] : Epi sq.f₂₄ := (MorphismProperty.epimorphisms C).of_isPushout h (by assumption) lemma epi_f₃₄ [Epi sq.f₁₂] : Epi sq.f₃₄ := by have : Epi sq.flip.f₁₃ := by dsimp; infer_instance exact h.flip.epi_f₂₄ end IsPushout end Square end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Pasting.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Pasting lemma This file proves the pasting lemma for pullbacks. That is, given the following diagram: ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` if the right square is a pullback, then the left square is a pullback iff the big square is a pullback. ## Main results * `pasteHorizIsPullback` shows that the big square is a pullback if both the small squares are. * `leftSquareIsPullback` shows that the left square is a pullback if the other two are. * `pullbackRightPullbackFstIso` shows, using the `pullback` API, that `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y`. * `pullbackLeftPullbackSndIso` shows, using the `pullback` API, that `(X ×[Z] Y) ×[Y] W ≅ X ×[Z] W`. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] section PasteLemma section PastePullbackHoriz /- Let's consider the following diagram ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` where `t₁` denotes the cone corresponding to the left square, and `t₂` denotes the cone corresponding to the right square. -/ variable {X₃ Y₁ Y₂ Y₃ : C} {g₁ : Y₁ ⟶ Y₂} {g₂ : Y₂ ⟶ Y₃} {i₃ : X₃ ⟶ Y₃} /-- The `PullbackCone` obtained by pasting two `PullbackCone`'s horizontally -/ abbrev PullbackCone.pasteHoriz (t₂ : PullbackCone g₂ i₃) {i₂ : t₂.pt ⟶ Y₂} (t₁ : PullbackCone g₁ i₂) (hi₂ : i₂ = t₂.fst) : PullbackCone (g₁ ≫ g₂) i₃ := PullbackCone.mk t₁.fst (t₁.snd ≫ t₂.snd) (by rw [reassoc_of% t₁.condition, Category.assoc, ← t₂.condition, ← hi₂]) variable (t₂ : PullbackCone g₂ i₃) {i₂ : t₂.pt ⟶ Y₂} (t₁ : PullbackCone g₁ i₂) (hi₂ : i₂ = t₂.fst) local notation "f₂" => t₂.snd local notation "X₁" => t₁.pt local notation "i₁" => t₁.fst local notation "f₁" => t₁.snd variable {t₁} {t₂} /-- Given ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` Then the big square is a pullback if both the small squares are. -/ def pasteHorizIsPullback (H : IsLimit t₂) (H' : IsLimit t₁) : IsLimit (t₂.pasteHoriz t₁ hi₂) := by apply PullbackCone.isLimitAux' intro s -- Obtain the lift from lifting from both the small squares consecutively. obtain ⟨l₂, hl₂, hl₂'⟩ := PullbackCone.IsLimit.lift' H (s.fst ≫ g₁) s.snd (by rw [← s.condition, Category.assoc]) obtain ⟨l₁, hl₁, hl₁'⟩ := PullbackCone.IsLimit.lift' H' s.fst l₂ (by rw [← hl₂, hi₂]) refine ⟨l₁, hl₁, by simp [reassoc_of% hl₁', hl₂'], ?_⟩ -- Uniqueness also follows from the universal property of both the small squares. intro m hm₁ hm₂ apply PullbackCone.IsLimit.hom_ext H' (by simpa [hl₁] using hm₁) apply PullbackCone.IsLimit.hom_ext H · dsimp at hm₁ rw [Category.assoc, ← hi₂, ← t₁.condition, reassoc_of% hm₁, hl₁', hi₂, hl₂] · simpa [hl₁', hl₂'] using hm₂ variable (t₁) /-- Given ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` Then the left square is a pullback if the right square and the big square are. -/ def leftSquareIsPullback (H : IsLimit t₂) (H' : IsLimit (t₂.pasteHoriz t₁ hi₂)) : IsLimit t₁ := by apply PullbackCone.isLimitAux' intro s -- Obtain the induced morphism from the universal property of the big square obtain ⟨l, hl, hl'⟩ := PullbackCone.IsLimit.lift' H' s.fst (s.snd ≫ f₂) (by rw [Category.assoc, ← t₂.condition, reassoc_of% s.condition, ← hi₂]) refine ⟨l, hl, ?_, ?_⟩ -- To check that `l` is compatible with the projections, we use the universal property of `t₂` · apply PullbackCone.IsLimit.hom_ext H · simp [← s.condition, ← hl, ← t₁.condition, ← hi₂] · simpa using hl' -- Uniqueness of the lift follows from the universal property of the big square · intro m hm₁ hm₂ apply PullbackCone.IsLimit.hom_ext H' · simpa [hm₁] using hl.symm · simpa [← hm₂] using hl'.symm /-- Given that the right square is a pullback, the pasted square is a pullback iff the left square is. -/ def pasteHorizIsPullbackEquiv (H : IsLimit t₂) : IsLimit (t₂.pasteHoriz t₁ hi₂) ≃ IsLimit t₁ where toFun H' := leftSquareIsPullback t₁ _ H H' invFun H' := pasteHorizIsPullback _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePullbackHoriz section PastePullbackVert /- Let's consider the following diagram ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` Let `t₁` denote the cone corresponding to the bottom square, and `t₂` denote the cone corresponding to the top square. -/ variable {X₁ X₂ X₃ Y₁ : C} {f₁ : X₂ ⟶ X₁} {f₂ : X₃ ⟶ X₂} {i₁ : Y₁ ⟶ X₁} /-- The `PullbackCone` obtained by pasting two `PullbackCone`'s vertically -/ abbrev PullbackCone.pasteVert (t₁ : PullbackCone i₁ f₁) {i₂ : t₁.pt ⟶ X₂} (t₂ : PullbackCone i₂ f₂) (hi₂ : i₂ = t₁.snd) : PullbackCone i₁ (f₂ ≫ f₁) := PullbackCone.mk (t₂.fst ≫ t₁.fst) t₂.snd (by rw [← reassoc_of% t₂.condition, Category.assoc, t₁.condition, ← hi₂]) variable (t₁ : PullbackCone i₁ f₁) {i₂ : t₁.pt ⟶ X₂} (t₂ : PullbackCone i₂ f₂) (hi₂ : i₂ = t₁.snd) local notation "Y₂" => t₁.pt local notation "g₁" => t₁.fst local notation "i₂" => t₁.snd local notation "Y₃" => t₂.pt local notation "g₂" => t₂.fst local notation "i₃" => t₂.snd /-- Pasting two pullback cones vertically is isomorphic to the pullback cone obtained by flipping them, pasting horizontally, and then flipping the result again. -/ def PullbackCone.pasteVertFlip : (t₁.pasteVert t₂ hi₂).flip ≅ (t₁.flip.pasteHoriz t₂.flip hi₂) := PullbackCone.ext (Iso.refl _) (by simp) (by simp) variable {t₁} {t₂} /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The big square is a pullback if both the small squares are. -/ def pasteVertIsPullback (H₁ : IsLimit t₁) (H₂ : IsLimit t₂) : IsLimit (t₁.pasteVert t₂ hi₂) := by apply PullbackCone.isLimitOfFlip <| IsLimit.ofIsoLimit _ (t₁.pasteVertFlip t₂ hi₂).symm exact pasteHorizIsPullback hi₂ (PullbackCone.flipIsLimit H₁) (PullbackCone.flipIsLimit H₂) variable (t₂) /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The top square is a pullback if the bottom square and the big square are. -/ def topSquareIsPullback (H₁ : IsLimit t₁) (H₂ : IsLimit (t₁.pasteVert t₂ hi₂)) : IsLimit t₂ := PullbackCone.isLimitOfFlip (leftSquareIsPullback _ hi₂ (PullbackCone.flipIsLimit H₁) (PullbackCone.flipIsLimit H₂)) /-- Given that the bottom square is a pullback, the pasted square is a pullback iff the top square is. -/ def pasteVertIsPullbackEquiv (H : IsLimit t₁) : IsLimit (t₁.pasteVert t₂ hi₂) ≃ IsLimit t₂ where toFun H' := topSquareIsPullback t₂ _ H H' invFun H' := pasteVertIsPullback _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePullbackVert section PastePushoutHoriz /- Let's consider the following diagram ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` where `t₁` denotes the left pushout cocone, and `t₂` denotes the right pushout cocone. -/ variable {X₁ X₂ X₃ Y₁ : C} {f₁ : X₁ ⟶ X₂} {f₂ : X₂ ⟶ X₃} {i₁ : X₁ ⟶ Y₁} /-- The pushout cocone obtained by pasting two pushout cocones horizontally. -/ abbrev PushoutCocone.pasteHoriz (t₁ : PushoutCocone i₁ f₁) {i₂ : X₂ ⟶ t₁.pt} (t₂ : PushoutCocone i₂ f₂) (hi₂ : i₂ = t₁.inr) : PushoutCocone i₁ (f₁ ≫ f₂) := PushoutCocone.mk (t₁.inl ≫ t₂.inl) t₂.inr (by rw [reassoc_of% t₁.condition, Category.assoc, ← t₂.condition, ← hi₂]) variable (t₁ : PushoutCocone i₁ f₁) {i₂ : X₂ ⟶ t₁.pt} (t₂ : PushoutCocone i₂ f₂) (hi₂ : i₂ = t₁.inr) local notation "Y₂" => t₁.pt local notation "g₁" => t₁.inl local notation "i₂" => t₁.inr local notation "Y₃" => t₂.pt local notation "g₂" => t₂.inl local notation "i₃" => t₂.inr variable {t₁} {t₂} /-- Given ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` Then the big square is a pushout if both the small squares are. -/ def pasteHorizIsPushout (H : IsColimit t₁) (H' : IsColimit t₂) : IsColimit (t₁.pasteHoriz t₂ hi₂) := by apply PushoutCocone.isColimitAux' intro s -- Obtain the induced map from descending from both the small squares consecutively. obtain ⟨l₁, hl₁, hl₁'⟩ := PushoutCocone.IsColimit.desc' H s.inl (f₂ ≫ s.inr) (by rw [s.condition, Category.assoc]) obtain ⟨l₂, hl₂, hl₂'⟩ := PushoutCocone.IsColimit.desc' H' l₁ s.inr (by rw [← hl₁', hi₂]) refine ⟨l₂, by simp [hl₂, hl₁], hl₂', ?_⟩ -- Uniqueness also follows from the universal property of both the small squares. intro m hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H' _ (by simpa [hl₂'] using hm₂) simp only [PushoutCocone.mk_pt, PushoutCocone.mk_ι_app, Category.assoc] at hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H · rw [hm₁, ← hl₁, hl₂] · rw [← hi₂, reassoc_of% t₂.condition, reassoc_of% t₂.condition, hm₂, hl₂'] variable (t₂) /-- Given X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ Then the right square is a pushout if the left square and the big square are. -/ def rightSquareIsPushout (H : IsColimit t₁) (H' : IsColimit (t₁.pasteHoriz t₂ hi₂)) : IsColimit t₂ := by apply PushoutCocone.isColimitAux' intro s -- Obtain the induced morphism from the universal property of the big square obtain ⟨l, hl, hl'⟩ := PushoutCocone.IsColimit.desc' H' (g₁ ≫ s.inl) s.inr (by rw [reassoc_of% t₁.condition, ← hi₂, s.condition, Category.assoc]) refine ⟨l, ?_, hl', ?_⟩ -- To check that `l` is compatible with the projections, we use the universal property of `t₁` · simp only [PushoutCocone.mk_pt, PushoutCocone.mk_ι_app, Category.assoc] at hl hl' apply PushoutCocone.IsColimit.hom_ext H hl rw [← Category.assoc, ← hi₂, t₂.condition, s.condition, Category.assoc, hl'] -- Uniqueness of the lift follows from the universal property of the big square · intro m hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H' · simpa [← hm₁] using hl.symm · simpa [← hm₂] using hl'.symm /-- Given that the left square is a pushout, the pasted square is a pushout iff the right square is. -/ def pasteHorizIsPushoutEquiv (H : IsColimit t₁) : IsColimit (t₁.pasteHoriz t₂ hi₂) ≃ IsColimit t₂ where toFun H' := rightSquareIsPushout t₂ _ H H' invFun H' := pasteHorizIsPushout _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePushoutHoriz section PastePushoutVert /- Let's consider the following diagram ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` Let `t₁` denote the cone corresponding to the bottom square, and `t₂` denote the cone corresponding to the top square. -/ variable {Y₃ Y₂ Y₁ X₃ : C} {g₂ : Y₃ ⟶ Y₂} {g₁ : Y₂ ⟶ Y₁} {i₃ : Y₃ ⟶ X₃} variable (t₁ : PushoutCocone g₂ i₃) {i₂ : Y₂ ⟶ t₁.pt} (t₂ : PushoutCocone g₁ i₂) (hi₂ : i₂ = t₁.inl) /-- The `PullbackCone` obtained by pasting two `PullbackCone`'s vertically -/ abbrev PushoutCocone.pasteVert (t₁ : PushoutCocone g₂ i₃) {i₂ : Y₂ ⟶ t₁.pt} (t₂ : PushoutCocone g₁ i₂) (hi₂ : i₂ = t₁.inl) : PushoutCocone (g₂ ≫ g₁) i₃ := PushoutCocone.mk t₂.inl (t₁.inr ≫ t₂.inr) (by rw [← reassoc_of% t₁.condition, Category.assoc, t₂.condition, ← hi₂]) local notation "X₂" => t₁.pt local notation "f₂" => t₁.inr local notation "i₂" => t₁.inl local notation "X₁" => t₂.pt local notation "f₁" => t₂.inr local notation "i₁" => t₂.inl /-- Pasting two pushout cocones vertically is isomorphic to the pushout cocone obtained by flipping them, pasting horizontally, and then flipping the result again. -/ def PushoutCocone.pasteVertFlip : (t₁.pasteVert t₂ hi₂).flip ≅ (t₁.flip.pasteHoriz t₂.flip hi₂) := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) variable {t₁} {t₂} /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The big square is a pushout if both the small squares are. -/ def pasteVertIsPushout (H₁ : IsColimit t₁) (H₂ : IsColimit t₂) : IsColimit (t₁.pasteVert t₂ hi₂) := by apply PushoutCocone.isColimitOfFlip <| IsColimit.ofIsoColimit _ (t₁.pasteVertFlip t₂ hi₂).symm exact pasteHorizIsPushout hi₂ (PushoutCocone.flipIsColimit H₁) (PushoutCocone.flipIsColimit H₂) variable (t₂) /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The bottom square is a pushout if the top square and the big square are. -/ def botSquareIsPushout (H₁ : IsColimit t₁) (H₂ : IsColimit (t₁.pasteVert t₂ hi₂)) : IsColimit t₂ := PushoutCocone.isColimitOfFlip (rightSquareIsPushout _ hi₂ (PushoutCocone.flipIsColimit H₁) (PushoutCocone.flipIsColimit H₂)) /-- Given that the top square is a pushout, the pasted square is a pushout iff the bottom square is. -/ def pasteVertIsPushoutEquiv (H : IsColimit t₁) : IsColimit (t₁.pasteVert t₂ hi₂) ≃ IsColimit t₂ where toFun H' := botSquareIsPushout t₂ _ H H' invFun H' := pasteVertIsPushout _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePushoutVert end PasteLemma section /- Let's consider the following diagram of pullbacks ``` W ×[X] (X ×[Z] Y) --snd--> X ×[Z] Y --snd--> Y | | | fst fst g v v v W --------- f' ---------> X ---- f ---> Y ``` In this section we show that `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y`. -/ variable {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (f' : W ⟶ X) variable [HasPullback f g] [HasPullback f' (pullback.fst f g)] instance hasPullbackHorizPaste : HasPullback (f' ≫ f) g := HasLimit.mk { cone := (pullback.cone f g).pasteHoriz (pullback.cone f' (pullback.fst f g)) rfl isLimit := pasteHorizIsPullback rfl (pullback.isLimit f g) (pullback.isLimit f' (pullback.fst f g)) } /-- The canonical isomorphism `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y` -/ noncomputable def pullbackRightPullbackFstIso : pullback f' (pullback.fst f g) ≅ pullback (f' ≫ f) g := IsLimit.conePointUniqueUpToIso (pasteHorizIsPullback rfl (pullback.isLimit f g) (pullback.isLimit f' (pullback.fst f g))) (pullback.isLimit (f' ≫ f) g) @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_hom_fst : (pullbackRightPullbackFstIso f g f').hom ≫ pullback.fst (f' ≫ f) g = pullback.fst f' (pullback.fst f g) := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_hom_snd : (pullbackRightPullbackFstIso f g f').hom ≫ pullback.snd _ _ = pullback.snd f' (pullback.fst f g) ≫ pullback.snd f g := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_fst : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.fst f' (pullback.fst f g) = pullback.fst (f' ≫ f) g := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_snd_snd : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_snd_fst : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ f' := by rw [← pullback.condition] exact pullbackRightPullbackFstIso_inv_fst_assoc f g f' _ end section /- Let's consider the following diagram of pullbacks ``` (X ×[Z] Y) ×[Y] W --snd--> W | | fst g' v v (X ×[Z] Y) --- snd ---> Y | | fst g v v X -------- f --------> Z ``` In this section we show that `(X ×[Z] Y) ×[Y] W ≅ X ×[Z] W`. -/ variable {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (g' : W ⟶ Y) variable [HasPullback f g] [HasPullback (pullback.snd f g) g'] instance hasPullbackVertPaste : HasPullback f (g' ≫ g) := HasLimit.mk { cone := (pullback.cone f g).pasteVert (pullback.cone (pullback.snd f g) g') rfl isLimit := pasteVertIsPullback rfl (pullback.isLimit f g) (pullback.isLimit (pullback.snd f g) g') } /-- The canonical isomorphism `(X ×[Z] Y) ×[Y] W ≅ X ×[Z] W` -/ def pullbackLeftPullbackSndIso : pullback (pullback.snd f g) g' ≅ pullback f (g' ≫ g) := IsLimit.conePointUniqueUpToIso (pasteVertIsPullback rfl (pullback.isLimit f g) (pullback.isLimit (pullback.snd f g) g')) (pullback.isLimit f (g' ≫ g)) @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_hom_fst : (pullbackLeftPullbackSndIso f g g').hom ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_hom_snd : (pullbackLeftPullbackSndIso f g g').hom ≫ pullback.snd _ _ = pullback.snd _ _ := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_inv_fst : (pullbackLeftPullbackSndIso f g g').inv ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_inv_snd_snd : (pullbackLeftPullbackSndIso f g g').inv ≫ pullback.snd _ _ = pullback.snd _ _ := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_inv_fst_snd : (pullbackLeftPullbackSndIso f g g').inv ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ g' := by rw [pullback.condition] exact pullbackLeftPullbackSndIso_inv_snd_snd_assoc f g g' g' end section /- Let's consider the following diagram of pushouts ``` X ---- g ----> Z ----- g' -----> W | | | f inr inr v v v Y - inl -> Y ⨿[X] Z --inl--> (Y ⨿[X] Z) ⨿[Z] W ``` In this section we show that `(Y ⨿[X] Z) ⨿[Z] W ≅ Y ⨿[X] W`. -/ variable {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (g' : Z ⟶ W) variable [HasPushout f g] [HasPushout (pushout.inr f g) g'] instance : HasPushout f (g ≫ g') := HasColimit.mk { cocone := (pushout.cocone f g).pasteHoriz (pushout.cocone (pushout.inr f g) g') rfl isColimit := pasteHorizIsPushout rfl (pushout.isColimit f g) (pushout.isColimit (pushout.inr f g) g') } /-- The canonical isomorphism `(Y ⨿[X] Z) ⨿[Z] W ≅ Y ⨿[X] W` -/ noncomputable def pushoutLeftPushoutInrIso : pushout (pushout.inr f g) g' ≅ pushout f (g ≫ g') := IsColimit.coconePointUniqueUpToIso (pasteHorizIsPushout rfl (pushout.isColimit f g) (pushout.isColimit (pushout.inr f g) g')) (pushout.isColimit f (g ≫ g')) @[reassoc (attr := simp)] theorem inl_pushoutLeftPushoutInrIso_inv : (pushout.inl f (g ≫ g')) ≫ (pushoutLeftPushoutInrIso f g g').inv = (pushout.inl f g) ≫ (pushout.inl (pushout.inr f g) g') := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_pushoutLeftPushoutInrIso_hom : (pushout.inr (pushout.inr f g) g') ≫ (pushoutLeftPushoutInrIso f g g').hom = (pushout.inr f (g ≫ g')) := IsColimit.comp_coconePointUniqueUpToIso_hom (pasteHorizIsPushout _ _ _) _ WalkingSpan.right @[reassoc (attr := simp)] theorem inr_pushoutLeftPushoutInrIso_inv : (pushout.inr f (g ≫ g')) ≫ (pushoutLeftPushoutInrIso f g g').inv = (pushout.inr (pushout.inr f g) g') := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.right @[reassoc (attr := simp)] theorem inl_inl_pushoutLeftPushoutInrIso_hom : (pushout.inl f g) ≫ (pushout.inl (pushout.inr f g) g') ≫ (pushoutLeftPushoutInrIso f g g').hom = (pushout.inl f (g ≫ g')) := by rw [← Category.assoc] apply IsColimit.comp_coconePointUniqueUpToIso_hom (pasteHorizIsPushout _ _ _) _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_inl_pushoutLeftPushoutInrIso_hom : pushout.inr f g ≫ pushout.inl (pushout.inr f g) g' ≫ (pushoutLeftPushoutInrIso f g g').hom = g' ≫ pushout.inr f (g ≫ g') := by rw [← Category.assoc, ← Iso.eq_comp_inv, Category.assoc, inr_pushoutLeftPushoutInrIso_inv, pushout.condition] end section /- Let's consider the diagram of pushouts ``` X ---- g ----> Z | | f inr v v Y - inl -> Y ⨿[X] Z | | f' inr v v W - inl -> W ⨿[Y] (Y ⨿[X] Z) ``` In this section we will construct the isomorphism `W ⨿[Y] (Y ⨿[X] Z) ≅ W ⨿[X] Z`. -/ variable {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (f' : Y ⟶ W) variable [HasPushout f g] [HasPushout f' (pushout.inl f g)] instance hasPushoutVertPaste : HasPushout (f ≫ f') g := HasColimit.mk { cocone := (pushout.cocone f g).pasteVert (pushout.cocone f' (pushout.inl f g)) rfl isColimit := pasteVertIsPushout rfl (pushout.isColimit f g) (pushout.isColimit f' (pushout.inl f g)) } /-- The canonical isomorphism `W ⨿[Y] (Y ⨿[X] Z) ≅ W ⨿[X] Z` -/ noncomputable def pushoutRightPushoutInlIso : pushout f' (pushout.inl f g) ≅ pushout (f ≫ f') g := IsColimit.coconePointUniqueUpToIso (pasteVertIsPushout rfl (pushout.isColimit f g) (pushout.isColimit f' (pushout.inl f g))) (pushout.isColimit (f ≫ f') g) @[reassoc (attr := simp)] theorem inl_pushoutRightPushoutInlIso_inv : pushout.inl _ _ ≫ (pushoutRightPushoutInlIso f g f').inv = pushout.inl _ _ := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_inr_pushoutRightPushoutInlIso_hom : pushout.inr _ _ ≫ pushout.inr _ _ ≫ (pushoutRightPushoutInlIso f g f').hom = pushout.inr _ _ := by rw [← Category.assoc] apply IsColimit.comp_coconePointUniqueUpToIso_hom (pasteVertIsPushout rfl _ _) _ WalkingSpan.right @[reassoc (attr := simp)] theorem inr_pushoutRightPushoutInlIso_inv : pushout.inr _ _ ≫ (pushoutRightPushoutInlIso f g f').inv = pushout.inr _ _ ≫ pushout.inr _ _ := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.right @[reassoc (attr := simp)] theorem inl_pushoutRightPushoutInlIso_hom : pushout.inl _ _ ≫ (pushoutRightPushoutInlIso f g f').hom = pushout.inl _ _ := IsColimit.comp_coconePointUniqueUpToIso_hom (pasteVertIsPushout rfl _ _) _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_inl_pushoutRightPushoutInlIso_hom : pushout.inl _ _ ≫ pushout.inr _ _ ≫ (pushoutRightPushoutInlIso f g f').hom = f' ≫ pushout.inl _ _ := by rw [← Category.assoc, ← pushout.condition, Category.assoc, inl_pushoutRightPushoutInlIso_hom] end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Mono.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Iso /-! # Pullbacks and monomorphisms This file provides some results about interactions between pullbacks and monomorphisms, as well as the dual statements between pushouts and epimorphisms. ## Main results * Monomorphisms are stable under pullback. This is available using the `PullbackCone` API as `mono_fst_of_is_pullback_of_mono` and `mono_snd_of_is_pullback_of_mono`, and using the `pullback` API as `pullback.fst_of_mono` and `pullback.snd_of_mono`. * A pullback cone is a limit iff its composition with a monomorphism is a limit. This is available as `IsLimitOfCompMono` and `pullbackIsPullbackOfCompMono` respectively. * Monomorphisms admit kernel pairs, this is `has_kernel_pair_of_mono`. The dual notions for pushouts are also available. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom PullbackCone variable {C : Type u} [Category.{v} C] {W X Y Z : C} section Monomorphisms namespace PullbackCone variable {f : X ⟶ Z} {g : Y ⟶ Z} /-- Monomorphisms are stable under pullback in the first argument. -/ theorem mono_snd_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono f] : Mono t.snd := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht ?_ i⟩ rw [← cancel_mono f, Category.assoc, Category.assoc, condition] apply reassoc_of% i /-- Monomorphisms are stable under pullback in the second argument. -/ theorem mono_fst_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono g] : Mono t.fst := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht i ?_⟩ rw [← cancel_mono g, Category.assoc, Category.assoc, ← condition] apply reassoc_of% i /-- The pullback cone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a limit if `f` is a mono. The converse is shown in `mono_of_pullback_is_id`. -/ def isLimitMkIdId (f : X ⟶ Y) [Mono f] : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f) := IsLimit.mk _ (fun s => s.fst) (fun _ => Category.comp_id _) (fun s => by rw [← cancel_mono f, Category.comp_id, s.condition]) fun s m m₁ _ => by simpa using m₁ /-- `f` is a mono if the pullback cone `(𝟙 X, 𝟙 X)` is a limit for the pair `(f, f)`. The converse is given in `PullbackCone.is_id_of_mono`. -/ theorem mono_of_isLimitMkIdId (f : X ⟶ Y) (t : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f)) : Mono f := ⟨fun {Z} g h eq => by rcases PullbackCone.IsLimit.lift' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ /-- Suppose `f` and `g` are two morphisms with a common codomain and `s` is a limit cone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through a monomorphism `h` via `x` and `y`, respectively. Then `s` is also a limit cone over the diagram formed by `x` and `y`. -/ def isLimitOfFactors (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ Z) [Mono h] (x : X ⟶ W) (y : Y ⟶ W) (hxh : x ≫ h = f) (hyh : y ≫ h = g) (s : PullbackCone f g) (hs : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ x = s.snd ≫ y from (cancel_mono h).1 <| by simp only [Category.assoc, hxh, hyh, s.condition])) := PullbackCone.isLimitAux' _ fun t => have : fst t ≫ x ≫ h = snd t ≫ y ≫ h := by -- Porting note: reassoc workaround rw [← Category.assoc, ← Category.assoc] apply congrArg (· ≫ h) t.condition ⟨hs.lift (PullbackCone.mk t.fst t.snd <| by rw [← hxh, ← hyh, this]), ⟨hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right, fun hr hr' => by apply PullbackCone.IsLimit.hom_ext hs <;> simp only [PullbackCone.mk_fst, PullbackCone.mk_snd] at hr hr' ⊢ <;> simp only [hr, hr'] <;> symm exacts [hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right]⟩⟩ /-- If `W` is the pullback of `f, g`, it is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/ def isLimitOfCompMono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] (s : PullbackCone f g) (H : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ f ≫ i = s.snd ≫ g ≫ i by rw [← Category.assoc, ← Category.assoc, s.condition])) := by apply PullbackCone.isLimitAux' intro s rcases PullbackCone.IsLimit.lift' H s.fst s.snd ((cancel_mono i).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PullbackCone.IsLimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) :) end PullbackCone end Monomorphisms /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.fst_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono g] : Mono (pullback.fst f g) := PullbackCone.mono_fst_of_is_pullback_of_mono (limit.isLimit _) /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.snd_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono f] : Mono (pullback.snd f g) := PullbackCone.mono_snd_of_is_pullback_of_mono (limit.isLimit _) /-- The map `X ×[Z] Y ⟶ X × Y` is mono. -/ instance mono_pullback_to_prod {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasBinaryProduct X Y] : Mono (prod.lift (pullback.fst f g) (pullback.snd f g)) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => f ≫ prod.fst) h · simpa using congrArg (fun f => f ≫ prod.snd) h⟩ /-- The pullback of `f, g` is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/ noncomputable def pullbackIsPullbackOfCompMono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] [HasPullback f g] : IsLimit (PullbackCone.mk (pullback.fst f g) (pullback.snd f g) -- Porting note: following used to be _ (show (pullback.fst f g) ≫ f ≫ i = (pullback.snd f g) ≫ g ≫ i by simp only [← Category.assoc]; rw [cancel_mono]; apply pullback.condition)) := PullbackCone.isLimitOfCompMono f g i _ (limit.isLimit (cospan f g)) instance hasPullback_of_comp_mono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] [HasPullback f g] : HasPullback (f ≫ i) (g ≫ i) := ⟨⟨⟨_, pullbackIsPullbackOfCompMono f g i⟩⟩⟩ section attribute [local instance] hasPullback_of_left_iso variable (f : X ⟶ Z) (i : Z ⟶ W) [Mono i] instance hasPullback_of_right_factors_mono : HasPullback i (f ≫ i) := by simpa only [Category.id_comp] using hasPullback_of_comp_mono (𝟙 Z) f i instance pullback_snd_iso_of_right_factors_mono : IsIso (pullback.snd i (f ≫ i)) := by have := limit.isoLimitCone_hom_π ⟨_, pullbackIsPullbackOfCompMono (𝟙 _) f i⟩ WalkingCospan.right convert (congrArg IsIso (show _ ≫ pullback.snd (𝟙 Z) f = _ from this)).mp inferInstance · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm attribute [local instance] hasPullback_of_right_iso instance hasPullback_of_left_factors_mono : HasPullback (f ≫ i) i := by simpa only [Category.id_comp] using hasPullback_of_comp_mono f (𝟙 Z) i instance pullback_snd_iso_of_left_factors_mono : IsIso (pullback.fst (f ≫ i) i) := by have := limit.isoLimitCone_hom_π ⟨_, pullbackIsPullbackOfCompMono f (𝟙 _) i⟩ WalkingCospan.left convert (congrArg IsIso (show _ ≫ pullback.fst f (𝟙 Z) = _ from this)).mp inferInstance · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm end section open WalkingCospan variable (f : X ⟶ Y) [Mono f] instance has_kernel_pair_of_mono : HasPullback f f := ⟨⟨⟨_, PullbackCone.isLimitMkIdId f⟩⟩⟩ theorem PullbackCone.fst_eq_snd_of_mono_eq {f : X ⟶ Y} [Mono f] (t : PullbackCone f f) : t.fst = t.snd := (cancel_mono f).1 t.condition theorem fst_eq_snd_of_mono_eq : pullback.fst f f = pullback.snd f f := PullbackCone.fst_eq_snd_of_mono_eq (getLimitCone (cospan f f)).cone @[simp] theorem pullbackSymmetry_hom_of_mono_eq : (pullbackSymmetry f f).hom = 𝟙 _ := by ext · simp [fst_eq_snd_of_mono_eq] · simp [fst_eq_snd_of_mono_eq] variable {f} in lemma PullbackCone.isIso_fst_of_mono_of_isLimit {t : PullbackCone f f} (ht : IsLimit t) : IsIso t.fst := by refine ⟨⟨PullbackCone.IsLimit.lift ht (𝟙 _) (𝟙 _) (by simp), ?_, by simp⟩⟩ apply PullbackCone.IsLimit.hom_ext ht · simp · simp [fst_eq_snd_of_mono_eq] variable {f} in lemma PullbackCone.isIso_snd_of_mono_of_isLimit {t : PullbackCone f f} (ht : IsLimit t) : IsIso t.snd := t.fst_eq_snd_of_mono_eq ▸ t.isIso_fst_of_mono_of_isLimit ht instance isIso_fst_of_mono : IsIso (pullback.fst f f) := PullbackCone.isIso_fst_of_mono_of_isLimit (getLimitCone (cospan f f)).isLimit instance isIso_snd_of_mono : IsIso (pullback.snd f f) := PullbackCone.isIso_snd_of_mono_of_isLimit (getLimitCone (cospan f f)).isLimit end namespace PushoutCocone variable {f : X ⟶ Y} {g : X ⟶ Z} theorem epi_inr_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi f] : Epi t.inr := ⟨fun {W} h k i => IsColimit.hom_ext ht (by simp [← cancel_epi f, t.condition_assoc, i]) i⟩ theorem epi_inl_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi g] : Epi t.inl := ⟨fun {W} h k i => IsColimit.hom_ext ht i (by simp [← cancel_epi g, ← t.condition_assoc, i])⟩ /-- The pushout cocone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a colimit if `f` is an epi. The converse is shown in `epi_of_isColimit_mk_id_id`. -/ def isColimitMkIdId (f : X ⟶ Y) [Epi f] : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f) := IsColimit.mk _ (fun s => s.inl) (fun _ => Category.id_comp _) (fun s => by rw [← cancel_epi f, Category.id_comp, s.condition]) fun s m m₁ _ => by simpa using m₁ /-- `f` is an epi if the pushout cocone `(𝟙 X, 𝟙 X)` is a colimit for the pair `(f, f)`. The converse is given in `PushoutCocone.isColimitMkIdId`. -/ theorem epi_of_isColimitMkIdId (f : X ⟶ Y) (t : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f)) : Epi f := ⟨fun {Z} g h eq => by rcases PushoutCocone.IsColimit.desc' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ /-- Suppose `f` and `g` are two morphisms with a common domain and `s` is a colimit cocone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through an epimorphism `h` via `x` and `y`, respectively. Then `s` is also a colimit cocone over the diagram formed by `x` and `y`. -/ def isColimitOfFactors (f : X ⟶ Y) (g : X ⟶ Z) (h : X ⟶ W) [Epi h] (x : W ⟶ Y) (y : W ⟶ Z) (hhx : h ≫ x = f) (hhy : h ≫ y = g) (s : PushoutCocone f g) (hs : IsColimit s) : have reassoc₁ : h ≫ x ≫ inl s = f ≫ inl s := by -- Porting note: working around reassoc rw [← Category.assoc]; apply congrArg (· ≫ inl s) hhx have reassoc₂ : h ≫ y ≫ inr s = g ≫ inr s := by rw [← Category.assoc]; apply congrArg (· ≫ inr s) hhy IsColimit (PushoutCocone.mk _ _ (show x ≫ s.inl = y ≫ s.inr from (cancel_epi h).1 <| by rw [reassoc₁, reassoc₂, s.condition])) := PushoutCocone.isColimitAux' _ fun t => ⟨hs.desc (PushoutCocone.mk t.inl t.inr <| by rw [← hhx, ← hhy, Category.assoc, Category.assoc, t.condition]), ⟨hs.fac _ WalkingSpan.left, hs.fac _ WalkingSpan.right, fun hr hr' => by apply PushoutCocone.IsColimit.hom_ext hs · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr] symm exact hs.fac _ WalkingSpan.left · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr'] symm exact hs.fac _ WalkingSpan.right⟩⟩ /-- If `W` is the pushout of `f, g`, it is also the pushout of `h ≫ f, h ≫ g` for any epi `h`. -/ def isColimitOfEpiComp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] (s : PushoutCocone f g) (H : IsColimit s) : IsColimit (PushoutCocone.mk _ _ (show (h ≫ f) ≫ s.inl = (h ≫ g) ≫ s.inr by rw [Category.assoc, Category.assoc, s.condition])) := by apply PushoutCocone.isColimitAux' intro s rcases PushoutCocone.IsColimit.desc' H s.inl s.inr ((cancel_epi h).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PushoutCocone.IsColimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) :) end PushoutCocone /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inl_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi g] : Epi (pushout.inl f g) := PushoutCocone.epi_inl_of_is_pushout_of_epi (colimit.isColimit _) /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inr_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi f] : Epi (pushout.inr _ _ : Z ⟶ pushout f g) := PushoutCocone.epi_inr_of_is_pushout_of_epi (colimit.isColimit _) /-- The map `X ⨿ Y ⟶ X ⨿[Z] Y` is epi. -/ instance epi_coprod_to_pushout {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasBinaryCoproduct Y Z] : Epi (coprod.desc (pushout.inl f g) (pushout.inr f g)) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => coprod.inl ≫ f) h · simpa using congrArg (fun f => coprod.inr ≫ f) h⟩ /-- The pushout of `f, g` is also the pullback of `h ≫ f, h ≫ g` for any epi `h`. -/ noncomputable def pushoutIsPushoutOfEpiComp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] [HasPushout f g] : IsColimit (PushoutCocone.mk (pushout.inl f g) (pushout.inr f g) (show (h ≫ f) ≫ pushout.inl f g = (h ≫ g) ≫ pushout.inr f g from by simp only [Category.assoc]; rw [cancel_epi]; exact pushout.condition)) := PushoutCocone.isColimitOfEpiComp f g h _ (colimit.isColimit (span f g)) instance hasPushout_of_epi_comp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] [HasPushout f g] : HasPushout (h ≫ f) (h ≫ g) := ⟨⟨⟨_, pushoutIsPushoutOfEpiComp f g h⟩⟩⟩ section attribute [local instance] hasPushout_of_left_iso variable (f : X ⟶ Z) (h : W ⟶ X) [Epi h] instance hasPushout_of_right_factors_epi : HasPushout h (h ≫ f) := by simpa only [Category.comp_id] using hasPushout_of_epi_comp (𝟙 X) f h instance pushout_inr_iso_of_right_factors_epi : IsIso (pushout.inr _ _ : _ ⟶ pushout h (h ≫ f)) := by convert (congrArg IsIso (show pushout.inr _ _ ≫ _ = _ from colimit.isoColimitCocone_ι_inv ⟨_, pushoutIsPushoutOfEpiComp (𝟙 _) f h⟩ WalkingSpan.right)).mp inferInstance · apply (Category.comp_id _).symm · apply (Category.comp_id _).symm attribute [local instance] hasPushout_of_right_iso instance hasPushout_of_left_factors_epi (f : X ⟶ Y) : HasPushout (h ≫ f) h := by simpa only [Category.comp_id] using hasPushout_of_epi_comp f (𝟙 X) h instance pushout_inl_iso_of_left_factors_epi (f : X ⟶ Y) : IsIso (pushout.inl _ _ : _ ⟶ pushout (h ≫ f) h) := by convert (congrArg IsIso (show pushout.inl _ _ ≫ _ = _ from colimit.isoColimitCocone_ι_inv ⟨_, pushoutIsPushoutOfEpiComp f (𝟙 _) h⟩ WalkingSpan.left)).mp inferInstance · exact (Category.comp_id _).symm · exact (Category.comp_id _).symm end section open WalkingSpan variable (f : X ⟶ Y) [Epi f] instance has_cokernel_pair_of_epi : HasPushout f f := ⟨⟨⟨_, PushoutCocone.isColimitMkIdId f⟩⟩⟩ theorem PushoutCocone.inl_eq_inr_of_epi_eq {f : X ⟶ Y} [Epi f] (t : PushoutCocone f f) : t.inl = t.inr := (cancel_epi f).1 t.condition theorem inl_eq_inr_of_epi_eq : pushout.inl f f = pushout.inr f f := PushoutCocone.inl_eq_inr_of_epi_eq (getColimitCocone (span f f)).cocone @[simp] theorem pullback_symmetry_hom_of_epi_eq : (pushoutSymmetry f f).hom = 𝟙 _ := by ext <;> simp [inl_eq_inr_of_epi_eq] variable {f} in lemma PushoutCocone.isIso_inl_of_epi_of_isColimit {t : PushoutCocone f f} (ht : IsColimit t) : IsIso t.inl := by refine ⟨⟨PushoutCocone.IsColimit.desc ht (𝟙 _) (𝟙 _) (by simp), by simp, ?_⟩⟩ apply PushoutCocone.IsColimit.hom_ext ht · simp · simp [inl_eq_inr_of_epi_eq] variable {f} in lemma PushoutCocone.isIso_inr_of_epi_of_isColimit {t : PushoutCocone f f} (ht : IsColimit t) : IsIso t.inr := t.inl_eq_inr_of_epi_eq ▸ t.isIso_inl_of_epi_of_isColimit ht instance isIso_inl_of_epi : IsIso (pushout.inl f f) := PushoutCocone.isIso_inl_of_epi_of_isColimit (getColimitCocone (span f f)).isColimit instance isIso_inr_of_epi : IsIso (pushout.inr f f) := PushoutCocone.isIso_inr_of_epi_of_isColimit (getColimitCocone (span f f)).isColimit end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Cospan.lean
import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # Cospan & Span We define a category `WalkingCospan` (resp. `WalkingSpan`), which is the index category for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g` and `span f g` construct functors from the walking (co)span, hitting the given morphisms. ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits -- Porting note: `aesop cases` does not work on type synonyms like `WidePullbackShape` -- attribute [local aesop safe cases] WidePullbackShape WalkingPair /-- The type of objects for the diagram indexing a pullback, defined as a special case of `WidePullbackShape`. -/ abbrev WalkingCospan : Type := WidePullbackShape WalkingPair /-- The left point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.left : WalkingCospan := some WalkingPair.left /-- The right point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.right : WalkingCospan := some WalkingPair.right /-- The central point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.one : WalkingCospan := none /-- The type of objects for the diagram indexing a pushout, defined as a special case of `WidePushoutShape`. -/ abbrev WalkingSpan : Type := WidePushoutShape WalkingPair /-- The left point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.left : WalkingSpan := some WalkingPair.left /-- The right point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.right : WalkingSpan := some WalkingPair.right /-- The central point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.zero : WalkingSpan := none namespace WalkingCospan /-- The type of arrows for the diagram indexing a pullback. -/ abbrev Hom : WalkingCospan → WalkingCospan → Type := WidePullbackShape.Hom /-- The left arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inl : left ⟶ one := WidePullbackShape.Hom.term _ /-- The right arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inr : right ⟶ one := WidePullbackShape.Hom.term _ /-- The identity arrows of the walking cospan. -/ @[match_pattern] abbrev Hom.id (X : WalkingCospan) : X ⟶ X := WidePullbackShape.Hom.id X instance (X Y : WalkingCospan) : Subsingleton (X ⟶ Y) := by constructor; intros; simp [eq_iff_true_of_subsingleton] end WalkingCospan namespace WalkingSpan /-- The type of arrows for the diagram indexing a pushout. -/ abbrev Hom : WalkingSpan → WalkingSpan → Type := WidePushoutShape.Hom /-- The left arrow of the walking span. -/ @[match_pattern] abbrev Hom.fst : zero ⟶ left := WidePushoutShape.Hom.init _ /-- The right arrow of the walking span. -/ @[match_pattern] abbrev Hom.snd : zero ⟶ right := WidePushoutShape.Hom.init _ /-- The identity arrows of the walking span. -/ @[match_pattern] abbrev Hom.id (X : WalkingSpan) : X ⟶ X := WidePushoutShape.Hom.id X instance (X Y : WalkingSpan) : Subsingleton (X ⟶ Y) := by constructor; intro a b; simp [eq_iff_true_of_subsingleton] end WalkingSpan open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] /-- To construct an isomorphism of cones over the walking cospan, it suffices to construct an isomorphism of the cone points and check it commutes with the legs to `left` and `right`. -/ def WalkingCospan.ext {F : WalkingCospan ⥤ C} {s t : Cone F} (i : s.pt ≅ t.pt) (w₁ : s.π.app WalkingCospan.left = i.hom ≫ t.π.app WalkingCospan.left) (w₂ : s.π.app WalkingCospan.right = i.hom ≫ t.π.app WalkingCospan.right) : s ≅ t := by apply Cones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.π.naturality WalkingCospan.Hom.inl dsimp at h₁ simp only [Category.id_comp] at h₁ have h₂ := t.π.naturality WalkingCospan.Hom.inl dsimp at h₂ simp only [Category.id_comp] at h₂ simp_rw [h₂, ← Category.assoc, ← w₁, ← h₁] · exact w₁ · exact w₂ /-- To construct an isomorphism of cocones over the walking span, it suffices to construct an isomorphism of the cocone points and check it commutes with the legs from `left` and `right`. -/ def WalkingSpan.ext {F : WalkingSpan ⥤ C} {s t : Cocone F} (i : s.pt ≅ t.pt) (w₁ : s.ι.app WalkingCospan.left ≫ i.hom = t.ι.app WalkingCospan.left) (w₂ : s.ι.app WalkingCospan.right ≫ i.hom = t.ι.app WalkingCospan.right) : s ≅ t := by apply Cocones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.ι.naturality WalkingSpan.Hom.fst dsimp at h₁ simp only [Category.comp_id] at h₁ have h₂ := t.ι.naturality WalkingSpan.Hom.fst dsimp at h₂ simp only [Category.comp_id] at h₂ simp_rw [← h₁, Category.assoc, w₁, h₂] · exact w₁ · exact w₂ /-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/ def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : WalkingCospan ⥤ C := WidePullbackShape.wideCospan Z (fun j => WalkingPair.casesOn j X Y) fun j => WalkingPair.casesOn j f g /-- `span f g` is the functor from the walking span hitting `f` and `g`. -/ def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : WalkingSpan ⥤ C := WidePushoutShape.wideSpan X (fun j => WalkingPair.casesOn j Y Z) fun j => WalkingPair.casesOn j f g @[simp] theorem cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.left = X := rfl @[simp] theorem span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.left = Y := rfl @[simp] theorem cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.right = Y := rfl @[simp] theorem span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.right = Z := rfl @[simp] theorem cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.one = Z := rfl @[simp] theorem span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.zero = X := rfl @[simp] theorem cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inl = f := rfl @[simp] theorem span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.fst = f := rfl @[simp] theorem cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inr = g := rfl @[simp] theorem span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.snd = g := rfl theorem cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : WalkingCospan) : (cospan f g).map (WalkingCospan.Hom.id w) = 𝟙 _ := rfl theorem span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : WalkingSpan) : (span f g).map (WalkingSpan.Hom.id w) = 𝟙 _ := rfl /-- Every diagram indexing a pullback is naturally isomorphic (actually, equal) to a `cospan` -/ @[simps (rhsMd := default)] def diagramIsoCospan (F : WalkingCospan ⥤ C) : F ≅ cospan (F.map inl) (F.map inr) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) /-- Every diagram indexing a pushout is naturally isomorphic (actually, equal) to a `span` -/ @[simps (rhsMd := default)] def diagramIsoSpan (F : WalkingSpan ⥤ C) : F ≅ span (F.map fst) (F.map snd) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) variable {D : Type u₂} [Category.{v₂} D] /-- A functor applied to a cospan is a cospan. -/ def cospanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : cospan f g ⋙ F ≅ cospan (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) @[simp] theorem cospanCompIso_app_left : (cospanCompIso F f g).app WalkingCospan.left = Iso.refl _ := rfl @[simp] theorem cospanCompIso_app_right : (cospanCompIso F f g).app WalkingCospan.right = Iso.refl _ := rfl @[simp] theorem cospanCompIso_app_one : (cospanCompIso F f g).app WalkingCospan.one = Iso.refl _ := rfl @[simp] theorem cospanCompIso_hom_app_left : (cospanCompIso F f g).hom.app WalkingCospan.left = 𝟙 _ := rfl @[simp] theorem cospanCompIso_hom_app_right : (cospanCompIso F f g).hom.app WalkingCospan.right = 𝟙 _ := rfl @[simp] theorem cospanCompIso_hom_app_one : (cospanCompIso F f g).hom.app WalkingCospan.one = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_left : (cospanCompIso F f g).inv.app WalkingCospan.left = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_right : (cospanCompIso F f g).inv.app WalkingCospan.right = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_one : (cospanCompIso F f g).inv.app WalkingCospan.one = 𝟙 _ := rfl end /-- A functor applied to a span is a span. -/ def spanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : span f g ⋙ F ≅ span (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) @[simp] theorem spanCompIso_app_left : (spanCompIso F f g).app WalkingSpan.left = Iso.refl _ := rfl @[simp] theorem spanCompIso_app_right : (spanCompIso F f g).app WalkingSpan.right = Iso.refl _ := rfl @[simp] theorem spanCompIso_app_zero : (spanCompIso F f g).app WalkingSpan.zero = Iso.refl _ := rfl @[simp] theorem spanCompIso_hom_app_left : (spanCompIso F f g).hom.app WalkingSpan.left = 𝟙 _ := rfl @[simp] theorem spanCompIso_hom_app_right : (spanCompIso F f g).hom.app WalkingSpan.right = 𝟙 _ := rfl @[simp] theorem spanCompIso_hom_app_zero : (spanCompIso F f g).hom.app WalkingSpan.zero = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_left : (spanCompIso F f g).inv.app WalkingSpan.left = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_right : (spanCompIso F f g).inv.app WalkingSpan.right = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_zero : (spanCompIso F f g).inv.app WalkingSpan.zero = 𝟙 _ := rfl end section variable {X Y Z X' Y' Z' : C} (iX : X ≅ X') (iY : Y ≅ Y') (iZ : Z ≅ Z') section variable {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} /-- Construct an isomorphism of cospans from components. -/ def cospanExt (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) : cospan f g ≅ cospan f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iZ, iX, iY]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp [wf, wg]) variable (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem cospanExt_app_left : (cospanExt iX iY iZ wf wg).app WalkingCospan.left = iX := rfl @[simp] theorem cospanExt_app_right : (cospanExt iX iY iZ wf wg).app WalkingCospan.right = iY := rfl @[simp] theorem cospanExt_app_one : (cospanExt iX iY iZ wf wg).app WalkingCospan.one = iZ := rfl @[simp] theorem cospanExt_hom_app_left : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.left = iX.hom := rfl @[simp] theorem cospanExt_hom_app_right : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.right = iY.hom := rfl @[simp] theorem cospanExt_hom_app_one : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.one = iZ.hom := rfl @[simp] theorem cospanExt_inv_app_left : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.left = iX.inv := rfl @[simp] theorem cospanExt_inv_app_right : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.right = iY.inv := rfl @[simp] theorem cospanExt_inv_app_one : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.one = iZ.inv := by rfl end section variable {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'} /-- Construct an isomorphism of spans from components. -/ def spanExt (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) : span f g ≅ span f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iX, iY, iZ]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp [wf, wg]) variable (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem spanExt_app_left : (spanExt iX iY iZ wf wg).app WalkingSpan.left = iY := rfl @[simp] theorem spanExt_app_right : (spanExt iX iY iZ wf wg).app WalkingSpan.right = iZ := rfl @[simp] theorem spanExt_app_one : (spanExt iX iY iZ wf wg).app WalkingSpan.zero = iX := rfl @[simp] theorem spanExt_hom_app_left : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.left = iY.hom := rfl @[simp] theorem spanExt_hom_app_right : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.right = iZ.hom := rfl @[simp] theorem spanExt_hom_app_zero : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.zero = iX.hom := rfl @[simp] theorem spanExt_inv_app_left : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.left = iY.inv := rfl @[simp] theorem spanExt_inv_app_right : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.right = iZ.inv := rfl @[simp] theorem spanExt_inv_app_zero : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.zero = iX.inv := rfl end end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Connected.lean
import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Pullbacks commute with connected limits -/ universe v u namespace CategoryTheory.Limits /-- Let `F` and `G` be two diagrams indexed by a connected `I`, and `X` and `Y` be two cones over `F` and `G` respectively, with maps `α : F ⟶ G` and `f : X ⟶ Y` that commutes with the cone maps. Suppose `X = Y x[G i] F i` for all `i` and `Y = lim G`, then `X = lim F`. -/ noncomputable def isLimitOfIsPullbackOfIsConnected {I C : Type*} [Category I] [IsConnected I] [Category C] {F G : I ⥤ C} (α : F ⟶ G) (cF : Cone F) (cG : Cone G) (f : (Cones.postcompose α).obj cF ⟶ cG) (hf : ∀ i, IsPullback (cF.π.app i) f.hom (α.app i) (cG.π.app i)) (hcG : IsLimit cG) : IsLimit cF where lift s := (hf (Classical.arbitrary _)).lift (s.π.app (Classical.arbitrary _)) (hcG.lift ((Cones.postcompose α).obj s)) (by simp) fac s j := by let f (i : _) : s.pt ⟶ cF.pt := (hf i).lift (s.π.app i) (hcG.lift ((Cones.postcompose α).obj s)) (by simp) have (i j : _) : f i = f j := by refine constant_of_preserves_morphisms f (fun j₁ j₂ g ↦ ?_) i j refine (hf j₂).hom_ext ?_ (by simp [f]) rw [IsPullback.lift_fst, ← cF.w g, IsPullback.lift_fst_assoc, Cone.w] change f _ ≫ _ = _ rw [this _ j] simp [f] uniq s g hg := (hf (Classical.arbitrary _)).hom_ext (by simp [hg]) (hcG.hom_ext <| by simp [reassoc_of% hg]) /-- Let `F` and `G` be two diagrams indexed by a connected `I`, and `X` and `Y` be two cocones over `F` and `G` respectively, with maps `α : F ⟶ G` and `f : X ⟶ Y` that commutes with the cocone maps. Suppose `Y = X ⨿[F i] G i` for all `i` and `Y = colim G`, then `X = colim F`. -/ noncomputable def isColimitOfIsPushoutOfIsConnected {I C : Type*} [Category I] [IsConnected I] [Category C] {F G : I ⥤ C} (α : F ⟶ G) (cF : Cocone F) (cG : Cocone G) (f : cF ⟶ (Cocones.precompose α).obj cG) (hf : ∀ i, IsPushout (cF.ι.app i) (α.app i) f.hom (cG.ι.app i)) (hcF : IsColimit cF) : IsColimit cG where desc s := (hf (Classical.arbitrary _)).desc (hcF.desc ((Cocones.precompose α).obj s)) (s.ι.app (Classical.arbitrary _)) (by simp) fac s j := by let f (i : _) : cG.pt ⟶ s.pt := (hf i).desc (hcF.desc ((Cocones.precompose α).obj s)) (s.ι.app i) (by simp) have (i j : _) : f i = f j := by refine constant_of_preserves_morphisms f (fun j₁ j₂ g ↦ ?_) i j refine (hf j₁).hom_ext (by simp [f]) ?_ rw [IsPushout.inr_desc, ← cG.w g, Category.assoc, IsPushout.inr_desc, Cocone.w] change _ ≫ f _ = _ rw [this _ j] simp [f] uniq s g hg := (hf (Classical.arbitrary _)).hom_ext (hcF.hom_ext <| by simp [hg]) (by simp [hg]) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Iso.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # The pullback of an isomorphism This file provides some basic results about the pullback (and pushout) of an isomorphism. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {X Y Z : C} section PullbackLeftIso open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso f] /-- If `f : X ⟶ Z` is iso, then `X ×[Z] Y ≅ Y`. This is the explicit limit cone. -/ def pullbackConeOfLeftIso : PullbackCone f g := PullbackCone.mk (g ≫ inv f) (𝟙 _) <| by simp @[simp] theorem pullbackConeOfLeftIso_x : (pullbackConeOfLeftIso f g).pt = Y := rfl @[simp] theorem pullbackConeOfLeftIso_fst : (pullbackConeOfLeftIso f g).fst = g ≫ inv f := rfl @[simp] theorem pullbackConeOfLeftIso_snd : (pullbackConeOfLeftIso f g).snd = 𝟙 _ := rfl theorem pullbackConeOfLeftIso_π_app_none : (pullbackConeOfLeftIso f g).π.app none = g := by simp @[simp] theorem pullbackConeOfLeftIso_π_app_left : (pullbackConeOfLeftIso f g).π.app left = g ≫ inv f := rfl @[simp] theorem pullbackConeOfLeftIso_π_app_right : (pullbackConeOfLeftIso f g).π.app right = 𝟙 _ := rfl /-- Verify that the constructed limit cone is indeed a limit. -/ def pullbackConeOfLeftIsoIsLimit : IsLimit (pullbackConeOfLeftIso f g) := PullbackCone.isLimitAux' _ fun s => ⟨s.snd, by simp [← s.condition_assoc]⟩ theorem hasPullback_of_left_iso : HasPullback f g := ⟨⟨⟨_, pullbackConeOfLeftIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPullback_of_left_iso instance pullback_snd_iso_of_left_iso : IsIso (pullback.snd f g) := by refine ⟨⟨pullback.lift (g ≫ inv f) (𝟙 _) (by simp), ?_, by simp⟩⟩ ext · simp [← pullback.condition_assoc] · simp @[reassoc (attr := simp)] lemma pullback_inv_snd_fst_of_left_isIso : inv (pullback.snd f g) ≫ pullback.fst f g = g ≫ inv f := by rw [IsIso.inv_comp_eq, ← pullback.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PullbackLeftIso section PullbackRightIso open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso g] /-- If `g : Y ⟶ Z` is iso, then `X ×[Z] Y ≅ X`. This is the explicit limit cone. -/ def pullbackConeOfRightIso : PullbackCone f g := PullbackCone.mk (𝟙 _) (f ≫ inv g) <| by simp @[simp] theorem pullbackConeOfRightIso_x : (pullbackConeOfRightIso f g).pt = X := rfl @[simp] theorem pullbackConeOfRightIso_fst : (pullbackConeOfRightIso f g).fst = 𝟙 _ := rfl @[simp] theorem pullbackConeOfRightIso_snd : (pullbackConeOfRightIso f g).snd = f ≫ inv g := rfl theorem pullbackConeOfRightIso_π_app_none : (pullbackConeOfRightIso f g).π.app none = f := by simp @[simp] theorem pullbackConeOfRightIso_π_app_left : (pullbackConeOfRightIso f g).π.app left = 𝟙 _ := rfl @[simp] theorem pullbackConeOfRightIso_π_app_right : (pullbackConeOfRightIso f g).π.app right = f ≫ inv g := rfl /-- Verify that the constructed limit cone is indeed a limit. -/ def pullbackConeOfRightIsoIsLimit : IsLimit (pullbackConeOfRightIso f g) := PullbackCone.isLimitAux' _ fun s => ⟨s.fst, by simp [s.condition_assoc]⟩ theorem hasPullback_of_right_iso : HasPullback f g := ⟨⟨⟨_, pullbackConeOfRightIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPullback_of_right_iso instance pullback_fst_iso_of_right_iso : IsIso (pullback.fst f g) := by refine ⟨⟨pullback.lift (𝟙 _) (f ≫ inv g) (by simp), ?_, by simp⟩⟩ ext · simp · simp [pullback.condition_assoc] @[reassoc (attr := simp)] lemma pullback_inv_fst_snd_of_right_isIso : inv (pullback.fst f g) ≫ pullback.snd f g = f ≫ inv g := by rw [IsIso.inv_comp_eq, pullback.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PullbackRightIso section PushoutLeftIso open WalkingSpan variable (f : X ⟶ Y) (g : X ⟶ Z) [IsIso f] /-- If `f : X ⟶ Y` is iso, then `Y ⨿[X] Z ≅ Z`. This is the explicit colimit cocone. -/ def pushoutCoconeOfLeftIso : PushoutCocone f g := PushoutCocone.mk (inv f ≫ g) (𝟙 _) <| by simp @[simp] theorem pushoutCoconeOfLeftIso_x : (pushoutCoconeOfLeftIso f g).pt = Z := rfl @[simp] theorem pushoutCoconeOfLeftIso_inl : (pushoutCoconeOfLeftIso f g).inl = inv f ≫ g := rfl @[simp] theorem pushoutCoconeOfLeftIso_inr : (pushoutCoconeOfLeftIso f g).inr = 𝟙 _ := rfl theorem pushoutCoconeOfLeftIso_ι_app_none : (pushoutCoconeOfLeftIso f g).ι.app none = g := by simp @[simp] theorem pushoutCoconeOfLeftIso_ι_app_left : (pushoutCoconeOfLeftIso f g).ι.app left = inv f ≫ g := rfl @[simp] theorem pushoutCoconeOfLeftIso_ι_app_right : (pushoutCoconeOfLeftIso f g).ι.app right = 𝟙 _ := rfl /-- Verify that the constructed cocone is indeed a colimit. -/ def pushoutCoconeOfLeftIsoIsLimit : IsColimit (pushoutCoconeOfLeftIso f g) := PushoutCocone.isColimitAux' _ fun s => ⟨s.inr, by simp [← s.condition]⟩ theorem hasPushout_of_left_iso : HasPushout f g := ⟨⟨⟨_, pushoutCoconeOfLeftIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPushout_of_left_iso instance pushout_inr_iso_of_left_iso : IsIso (pushout.inr f g) := by refine ⟨⟨pushout.desc (inv f ≫ g) (𝟙 _) (by simp), by simp, ?_⟩⟩ ext · simp [← pushout.condition] · simp @[reassoc (attr := simp)] lemma pushout_inl_inv_inr_of_right_isIso : pushout.inl f g ≫ inv (pushout.inr f g) = inv f ≫ g := by rw [IsIso.eq_inv_comp, pushout.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PushoutLeftIso section PushoutRightIso open WalkingSpan variable (f : X ⟶ Y) (g : X ⟶ Z) [IsIso g] /-- If `f : X ⟶ Z` is iso, then `Y ⨿[X] Z ≅ Y`. This is the explicit colimit cocone. -/ def pushoutCoconeOfRightIso : PushoutCocone f g := PushoutCocone.mk (𝟙 _) (inv g ≫ f) <| by simp @[simp] theorem pushoutCoconeOfRightIso_x : (pushoutCoconeOfRightIso f g).pt = Y := rfl @[simp] theorem pushoutCoconeOfRightIso_inl : (pushoutCoconeOfRightIso f g).inl = 𝟙 _ := rfl @[simp] theorem pushoutCoconeOfRightIso_inr : (pushoutCoconeOfRightIso f g).inr = inv g ≫ f := rfl theorem pushoutCoconeOfRightIso_ι_app_none : (pushoutCoconeOfRightIso f g).ι.app none = f := by simp @[simp] theorem pushoutCoconeOfRightIso_ι_app_left : (pushoutCoconeOfRightIso f g).ι.app left = 𝟙 _ := rfl @[simp] theorem pushoutCoconeOfRightIso_ι_app_right : (pushoutCoconeOfRightIso f g).ι.app right = inv g ≫ f := rfl /-- Verify that the constructed cocone is indeed a colimit. -/ def pushoutCoconeOfRightIsoIsLimit : IsColimit (pushoutCoconeOfRightIso f g) := PushoutCocone.isColimitAux' _ fun s => ⟨s.inl, by simp [← s.condition]⟩ theorem hasPushout_of_right_iso : HasPushout f g := ⟨⟨⟨_, pushoutCoconeOfRightIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPushout_of_right_iso instance pushout_inl_iso_of_right_iso : IsIso (pushout.inl _ _ : _ ⟶ pushout f g) := by refine ⟨⟨pushout.desc (𝟙 _) (inv g ≫ f) (by simp), by simp, ?_⟩⟩ ext · simp · simp [pushout.condition] @[reassoc (attr := simp)] lemma pushout_inr_inv_inl_of_right_isIso : pushout.inr f g ≫ inv (pushout.inl f g) = inv g ≫ f := by rw [IsIso.eq_inv_comp, ← pushout.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PushoutRightIso end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Equalizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Equalizers as pullbacks of products Also see `CategoryTheory.Limits.Constructions.Equalizers` for very similar results. -/ universe v u namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {X Y : C} (f g : X ⟶ Y) /-- The equalizer of `f g : X ⟶ Y` is the pullback of the diagonal map `Y ⟶ Y × Y` along the map `(f, g) : X ⟶ Y × Y`. -/ lemma isPullback_equalizer_prod [HasEqualizer f g] [HasBinaryProduct Y Y] : IsPullback (equalizer.ι f g) (equalizer.ι f g ≫ f) (prod.lift f g) (prod.lift (𝟙 _) (𝟙 _)) := by refine ⟨⟨by ext <;> simp [equalizer.condition f g]⟩, ⟨PullbackCone.IsLimit.mk _ ?_ ?_ ?_ ?_⟩⟩ · refine fun s ↦ equalizer.lift s.fst ?_ have H₁ : s.fst ≫ f = s.snd := by simpa using congr($s.condition ≫ prod.fst) have H₂ : s.fst ≫ g = s.snd := by simpa using congr($s.condition ≫ prod.snd) exact H₁.trans H₂.symm · exact fun s ↦ by simp · exact fun s ↦ by simpa using congr($s.condition ≫ prod.fst) · exact fun s m hm _ ↦ by ext; simp [*] /-- The coequalizer of `f g : X ⟶ Y` is the pushout of the diagonal map `X ⨿ X ⟶ X` along the map `(f, g) : X ⨿ X ⟶ Y`. -/ lemma isPushout_coequalizer_coprod [HasCoequalizer f g] [HasBinaryCoproduct X X] : IsPushout (coprod.desc f g) (coprod.desc (𝟙 _) (𝟙 _)) (coequalizer.π f g) (f ≫ coequalizer.π f g) := by refine ⟨⟨by ext <;> simp [coequalizer.condition f g]⟩, ⟨PushoutCocone.IsColimit.mk _ ?_ ?_ ?_ ?_⟩⟩ · refine fun s ↦ coequalizer.desc s.inl ?_ have H₁ : f ≫ s.inl = s.inr := by simpa using congr(coprod.inl ≫ $s.condition) have H₂ : g ≫ s.inl = s.inr := by simpa using congr(coprod.inr ≫ $s.condition) exact H₁.trans H₂.symm · exact fun s ↦ by simp · exact fun s ↦ by simpa using congr(coprod.inl ≫ $s.condition) · exact fun s m hm _ ↦ by ext; simp [*] end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/CommSq.lean
import Mathlib.CategoryTheory.Limits.Constructions.ZeroObjects import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Pasting import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Iso /-! # Pullback and pushout squares, and bi-Cartesian squares We provide another API for pullbacks and pushouts. `IsPullback fst snd f g` is the proposition that ``` P --fst--> X | | snd f | | v v Y ---g---> Z ``` is a pullback square. (And similarly for `IsPushout`.) We provide the glue to go back and forth to the usual `IsLimit` API for pullbacks, and prove `IsPullback (pullback.fst f g) (pullback.snd f g) f g` for the usual `pullback f g` provided by the `HasLimit` API. We don't attempt to restate everything we know about pullbacks in this language, but do restate the pasting lemmas. We define bi-Cartesian squares, and show that the pullback and pushout squares for a biproduct are bi-Cartesian. -/ noncomputable section open CategoryTheory open CategoryTheory.Limits universe v₁ v₂ u₁ u₂ namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] attribute [simp] CommSq.mk namespace CommSq variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} /-- The (not necessarily limiting) `PullbackCone h i` implicit in the statement that we have `CommSq f g h i`. -/ def cone (s : CommSq f g h i) : PullbackCone h i := PullbackCone.mk _ _ s.w /-- The (not necessarily limiting) `PushoutCocone f g` implicit in the statement that we have `CommSq f g h i`. -/ def cocone (s : CommSq f g h i) : PushoutCocone f g := PushoutCocone.mk _ _ s.w @[simp] theorem cone_fst (s : CommSq f g h i) : s.cone.fst = f := rfl @[simp] theorem cone_snd (s : CommSq f g h i) : s.cone.snd = g := rfl @[simp] theorem cocone_inl (s : CommSq f g h i) : s.cocone.inl = h := rfl @[simp] theorem cocone_inr (s : CommSq f g h i) : s.cocone.inr = i := rfl /-- The pushout cocone in the opposite category associated to the cone of a commutative square identifies to the cocone of the flipped commutative square in the opposite category -/ def coneOp (p : CommSq f g h i) : p.cone.op ≅ p.flip.op.cocone := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) /-- The pullback cone in the opposite category associated to the cocone of a commutative square identifies to the cone of the flipped commutative square in the opposite category -/ def coconeOp (p : CommSq f g h i) : p.cocone.op ≅ p.flip.op.cone := PullbackCone.ext (Iso.refl _) (by simp) (by simp) /-- The pushout cocone obtained from the pullback cone associated to a commutative square in the opposite category identifies to the cocone associated to the flipped square. -/ def coneUnop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) : p.cone.unop ≅ p.flip.unop.cocone := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) /-- The pullback cone obtained from the pushout cone associated to a commutative square in the opposite category identifies to the cone associated to the flipped square. -/ def coconeUnop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) : p.cocone.unop ≅ p.flip.unop.cone := PullbackCone.ext (Iso.refl _) (by simp) (by simp) end CommSq /-- The proposition that a square ``` P --fst--> X | | snd f | | v v Y ---g---> Z ``` is a pullback square. (Also known as a fibered product or Cartesian square.) -/ structure IsPullback {P X Y Z : C} (fst : P ⟶ X) (snd : P ⟶ Y) (f : X ⟶ Z) (g : Y ⟶ Z) : Prop extends CommSq fst snd f g where /-- the pullback cone is a limit -/ isLimit' : Nonempty (IsLimit (PullbackCone.mk _ _ w)) /-- The proposition that a square ``` Z ---f---> X | | g inl | | v v Y --inr--> P ``` is a pushout square. (Also known as a fiber coproduct or co-Cartesian square.) -/ structure IsPushout {Z X Y P : C} (f : Z ⟶ X) (g : Z ⟶ Y) (inl : X ⟶ P) (inr : Y ⟶ P) : Prop extends CommSq f g inl inr where /-- the pushout cocone is a colimit -/ isColimit' : Nonempty (IsColimit (PushoutCocone.mk _ _ w)) section /-- A *bi-Cartesian* square is a commutative square ``` W ---f---> X | | g h | | v v Y ---i---> Z ``` that is both a pullback square and a pushout square. -/ structure BicartesianSq {W X Y Z : C} (f : W ⟶ X) (g : W ⟶ Y) (h : X ⟶ Z) (i : Y ⟶ Z) : Prop extends IsPullback f g h i, IsPushout f g h i -- Lean should make these parent projections as `lemma`, not `def`. attribute [nolint defLemma docBlame] BicartesianSq.toIsPushout end /-! We begin by providing some glue between `IsPullback` and the `IsLimit` and `HasLimit` APIs. (And similarly for `IsPushout`.) -/ namespace IsPullback variable {P X Y Z : C} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} /-- The (limiting) `PullbackCone f g` implicit in the statement that we have an `IsPullback fst snd f g`. -/ def cone (h : IsPullback fst snd f g) : PullbackCone f g := h.toCommSq.cone @[simp] theorem cone_fst (h : IsPullback fst snd f g) : h.cone.fst = fst := rfl @[simp] theorem cone_snd (h : IsPullback fst snd f g) : h.cone.snd = snd := rfl /-- The cone obtained from `IsPullback fst snd f g` is a limit cone. -/ noncomputable def isLimit (h : IsPullback fst snd f g) : IsLimit h.cone := h.isLimit'.some /-- API for PullbackCone.IsLimit.lift for `IsPullback` -/ noncomputable def lift (hP : IsPullback fst snd f g) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ P := PullbackCone.IsLimit.lift hP.isLimit h k w @[reassoc (attr := simp)] lemma lift_fst (hP : IsPullback fst snd f g) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : hP.lift h k w ≫ fst = h := PullbackCone.IsLimit.lift_fst hP.isLimit h k w @[reassoc (attr := simp)] lemma lift_snd (hP : IsPullback fst snd f g) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : hP.lift h k w ≫ snd = k := PullbackCone.IsLimit.lift_snd hP.isLimit h k w lemma hom_ext (hP : IsPullback fst snd f g) {W : C} {k l : W ⟶ P} (h₀ : k ≫ fst = l ≫ fst) (h₁ : k ≫ snd = l ≫ snd) : k = l := PullbackCone.IsLimit.hom_ext hP.isLimit h₀ h₁ /-- If `c` is a limiting pullback cone, then we have an `IsPullback c.fst c.snd f g`. -/ theorem of_isLimit {c : PullbackCone f g} (h : Limits.IsLimit c) : IsPullback c.fst c.snd f g := { w := c.condition isLimit' := ⟨IsLimit.ofIsoLimit h (Limits.PullbackCone.ext (Iso.refl _) (by simp) (by simp))⟩ } /-- A variant of `of_isLimit` that is more useful with `apply`. -/ theorem of_isLimit' (w : CommSq fst snd f g) (h : Limits.IsLimit w.cone) : IsPullback fst snd f g := of_isLimit h /-- Variant of `of_isLimit` for an arbitrary cone on a diagram `WalkingCospan ⥤ C`. -/ lemma of_isLimit_cone {D : WalkingCospan ⥤ C} {c : Cone D} (hc : IsLimit c) : IsPullback (c.π.app .left) (c.π.app .right) (D.map WalkingCospan.Hom.inl) (D.map WalkingCospan.Hom.inr) where w := by simp_rw [Cone.w] isLimit' := ⟨IsLimit.equivOfNatIsoOfIso _ _ _ (PullbackCone.isoMk c) hc⟩ lemma hasPullback (h : IsPullback fst snd f g) : HasPullback f g where exists_limit := ⟨⟨h.cone, h.isLimit⟩⟩ /-- The pullback provided by `HasPullback f g` fits into an `IsPullback`. -/ theorem of_hasPullback (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsPullback (pullback.fst f g) (pullback.snd f g) f g := of_isLimit (limit.isLimit (cospan f g)) /-- If `c` is a limiting binary product cone, and we have a terminal object, then we have `IsPullback c.fst c.snd 0 0` (where each `0` is the unique morphism to the terminal object). -/ theorem of_is_product {c : BinaryFan X Y} (h : Limits.IsLimit c) (t : IsTerminal Z) : IsPullback c.fst c.snd (t.from _) (t.from _) := of_isLimit (isPullbackOfIsTerminalIsProduct _ _ _ _ t (IsLimit.ofIsoLimit h (Limits.Cones.ext (Iso.refl c.pt) (by rintro ⟨⟨⟩⟩ <;> simp)))) /-- A variant of `of_is_product` that is more useful with `apply`. -/ theorem of_is_product' (h : Limits.IsLimit (BinaryFan.mk fst snd)) (t : IsTerminal Z) : IsPullback fst snd (t.from _) (t.from _) := of_is_product h t variable (X Y) theorem of_hasBinaryProduct' [HasBinaryProduct X Y] [HasTerminal C] : IsPullback Limits.prod.fst Limits.prod.snd (terminal.from X) (terminal.from Y) := of_is_product (limit.isLimit _) terminalIsTerminal open ZeroObject theorem of_hasBinaryProduct [HasBinaryProduct X Y] [HasZeroObject C] [HasZeroMorphisms C] : IsPullback Limits.prod.fst Limits.prod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert @of_is_product _ _ X Y 0 _ (limit.isLimit _) HasZeroObject.zeroIsTerminal <;> subsingleton section variable {P' : C} {fst' : P' ⟶ X} {snd' : P' ⟶ Y} /-- Any object at the top left of a pullback square is isomorphic to the object at the top left of any other pullback square with the same cospan. -/ noncomputable def isoIsPullback (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : P ≅ P' := IsLimit.conePointUniqueUpToIso h.isLimit h'.isLimit @[reassoc (attr := simp)] theorem isoIsPullback_hom_fst (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback _ _ h').hom ≫ fst' = fst := IsLimit.conePointUniqueUpToIso_hom_comp h.isLimit h'.isLimit WalkingCospan.left @[reassoc (attr := simp)] theorem isoIsPullback_hom_snd (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback _ _ h').hom ≫ snd' = snd := IsLimit.conePointUniqueUpToIso_hom_comp h.isLimit h'.isLimit WalkingCospan.right @[reassoc (attr := simp)] theorem isoIsPullback_inv_fst (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback _ _ h').inv ≫ fst = fst' := by simp only [Iso.inv_comp_eq, isoIsPullback_hom_fst] @[reassoc (attr := simp)] theorem isoIsPullback_inv_snd (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback _ _ h').inv ≫ snd = snd' := by simp only [Iso.inv_comp_eq, isoIsPullback_hom_snd] end variable {X Y} /-- Any object at the top left of a pullback square is isomorphic to the pullback provided by the `HasLimit` API. -/ noncomputable def isoPullback (h : IsPullback fst snd f g) [HasPullback f g] : P ≅ pullback f g := (limit.isoLimitCone ⟨_, h.isLimit⟩).symm @[reassoc (attr := simp)] theorem isoPullback_hom_fst (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.hom ≫ pullback.fst _ _ = fst := by dsimp [isoPullback, cone, CommSq.cone] simp @[reassoc (attr := simp)] theorem isoPullback_hom_snd (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.hom ≫ pullback.snd _ _ = snd := by dsimp [isoPullback, cone, CommSq.cone] simp @[reassoc (attr := simp)] theorem isoPullback_inv_fst (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.inv ≫ fst = pullback.fst _ _ := by simp [Iso.inv_comp_eq] @[reassoc (attr := simp)] theorem isoPullback_inv_snd (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.inv ≫ snd = pullback.snd _ _ := by simp [Iso.inv_comp_eq] theorem of_iso_pullback (h : CommSq fst snd f g) [HasPullback f g] (i : P ≅ pullback f g) (w₁ : i.hom ≫ pullback.fst _ _ = fst) (w₂ : i.hom ≫ pullback.snd _ _ = snd) : IsPullback fst snd f g := of_isLimit' h (Limits.IsLimit.ofIsoLimit (limit.isLimit _) (@PullbackCone.ext _ _ _ _ _ _ _ (PullbackCone.mk _ _ _) _ i w₁.symm w₂.symm).symm) theorem of_horiz_isIso_mono [IsIso fst] [Mono g] (sq : CommSq fst snd f g) : IsPullback fst snd f g := of_isLimit' sq (by refine PullbackCone.IsLimit.mk _ (fun s => s.fst ≫ inv fst) (by simp) (fun s => ?_) (by cat_disch) simp only [← cancel_mono g, Category.assoc, ← sq.w, IsIso.inv_hom_id_assoc, s.condition]) theorem of_horiz_isIso [IsIso fst] [IsIso g] (sq : CommSq fst snd f g) : IsPullback fst snd f g := of_horiz_isIso_mono sq lemma of_iso (h : IsPullback fst snd f g) {P' X' Y' Z' : C} {fst' : P' ⟶ X'} {snd' : P' ⟶ Y'} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} (e₁ : P ≅ P') (e₂ : X ≅ X') (e₃ : Y ≅ Y') (e₄ : Z ≅ Z') (commfst : fst ≫ e₂.hom = e₁.hom ≫ fst') (commsnd : snd ≫ e₃.hom = e₁.hom ≫ snd') (commf : f ≫ e₄.hom = e₂.hom ≫ f') (commg : g ≫ e₄.hom = e₃.hom ≫ g') : IsPullback fst' snd' f' g' where w := by rw [← cancel_epi e₁.hom, ← reassoc_of% commfst, ← commf, ← reassoc_of% commsnd, ← commg, h.w_assoc] isLimit' := ⟨(IsLimit.postcomposeInvEquiv (cospanExt e₂ e₃ e₄ commf.symm commg.symm) _).1 (IsLimit.ofIsoLimit h.isLimit (by refine PullbackCone.ext e₁ ?_ ?_ · change fst = e₁.hom ≫ fst' ≫ e₂.inv rw [← reassoc_of% commfst, e₂.hom_inv_id, Category.comp_id] · change snd = e₁.hom ≫ snd' ≫ e₃.inv rw [← reassoc_of% commsnd, e₃.hom_inv_id, Category.comp_id]))⟩ section variable {P X Y : C} {fst : P ⟶ X} {snd : P ⟶ X} {f : X ⟶ Y} [Mono f] lemma isIso_fst_of_mono (h : IsPullback fst snd f f) : IsIso fst := h.cone.isIso_fst_of_mono_of_isLimit h.isLimit lemma isIso_snd_iso_of_mono {P X Y : C} {fst : P ⟶ X} {snd : P ⟶ X} {f : X ⟶ Y} [Mono f] (h : IsPullback fst snd f f) : IsIso snd := h.cone.isIso_snd_of_mono_of_isLimit h.isLimit end section lemma isIso_fst_of_isIso (h : IsPullback fst snd f g) [IsIso g] : IsIso fst := by have := h.hasPullback rw [← h.isoPullback_hom_fst] infer_instance lemma isIso_snd_of_isIso (h : IsPullback fst snd f g) [IsIso f] : IsIso snd := by have := h.hasPullback rw [← h.isoPullback_hom_snd] infer_instance end end IsPullback namespace IsPushout variable {Z X Y P : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} /-- The (colimiting) `PushoutCocone f g` implicit in the statement that we have an `IsPushout f g inl inr`. -/ def cocone (h : IsPushout f g inl inr) : PushoutCocone f g := h.toCommSq.cocone @[simp] theorem cocone_inl (h : IsPushout f g inl inr) : h.cocone.inl = inl := rfl @[simp] theorem cocone_inr (h : IsPushout f g inl inr) : h.cocone.inr = inr := rfl /-- The cocone obtained from `IsPushout f g inl inr` is a colimit cocone. -/ noncomputable def isColimit (h : IsPushout f g inl inr) : IsColimit h.cocone := h.isColimit'.some /-- API for PushoutCocone.IsColimit.lift for `IsPushout` -/ noncomputable def desc (hP : IsPushout f g inl inr) {W : C} (h : X ⟶ W) (k : Y ⟶ W) (w : f ≫ h = g ≫ k) : P ⟶ W := PushoutCocone.IsColimit.desc hP.isColimit h k w @[reassoc (attr := simp)] lemma inl_desc (hP : IsPushout f g inl inr) {W : C} (h : X ⟶ W) (k : Y ⟶ W) (w : f ≫ h = g ≫ k) : inl ≫ hP.desc h k w = h := PushoutCocone.IsColimit.inl_desc hP.isColimit h k w @[reassoc (attr := simp)] lemma inr_desc (hP : IsPushout f g inl inr) {W : C} (h : X ⟶ W) (k : Y ⟶ W) (w : f ≫ h = g ≫ k) : inr ≫ hP.desc h k w = k := PushoutCocone.IsColimit.inr_desc hP.isColimit h k w lemma hom_ext (hP : IsPushout f g inl inr) {W : C} {k l : P ⟶ W} (h₀ : inl ≫ k = inl ≫ l) (h₁ : inr ≫ k = inr ≫ l) : k = l := PushoutCocone.IsColimit.hom_ext hP.isColimit h₀ h₁ /-- If `c` is a colimiting pushout cocone, then we have an `IsPushout f g c.inl c.inr`. -/ theorem of_isColimit {c : PushoutCocone f g} (h : Limits.IsColimit c) : IsPushout f g c.inl c.inr := { w := c.condition isColimit' := ⟨IsColimit.ofIsoColimit h (Limits.PushoutCocone.ext (Iso.refl _) (by simp) (by simp))⟩ } /-- A variant of `of_isColimit` that is more useful with `apply`. -/ theorem of_isColimit' (w : CommSq f g inl inr) (h : Limits.IsColimit w.cocone) : IsPushout f g inl inr := of_isColimit h /-- Variant of `of_isColimit` for an arbitrary cocone on a diagram `WalkingSpan ⥤ C`. -/ lemma of_isColimit_cocone {D : WalkingSpan ⥤ C} {c : Cocone D} (hc : IsColimit c) : IsPushout (D.map WalkingSpan.Hom.fst) (D.map WalkingSpan.Hom.snd) (c.ι.app .left) (c.ι.app .right) where w := by simp_rw [Cocone.w] isColimit' := ⟨IsColimit.equivOfNatIsoOfIso _ _ _ (PushoutCocone.isoMk c) hc⟩ lemma hasPushout (h : IsPushout f g inl inr) : HasPushout f g where exists_colimit := ⟨⟨h.cocone, h.isColimit⟩⟩ /-- The pushout provided by `HasPushout f g` fits into an `IsPushout`. -/ theorem of_hasPushout (f : Z ⟶ X) (g : Z ⟶ Y) [HasPushout f g] : IsPushout f g (pushout.inl f g) (pushout.inr f g) := of_isColimit (colimit.isColimit (span f g)) /-- If `c` is a colimiting binary coproduct cocone, and we have an initial object, then we have `IsPushout 0 0 c.inl c.inr` (where each `0` is the unique morphism from the initial object). -/ theorem of_is_coproduct {c : BinaryCofan X Y} (h : Limits.IsColimit c) (t : IsInitial Z) : IsPushout (t.to _) (t.to _) c.inl c.inr := of_isColimit (isPushoutOfIsInitialIsCoproduct _ _ _ _ t (IsColimit.ofIsoColimit h (Limits.Cocones.ext (Iso.refl c.pt) (by rintro ⟨⟨⟩⟩ <;> simp)))) /-- A variant of `of_is_coproduct` that is more useful with `apply`. -/ theorem of_is_coproduct' (h : Limits.IsColimit (BinaryCofan.mk inl inr)) (t : IsInitial Z) : IsPushout (t.to _) (t.to _) inl inr := of_is_coproduct h t variable (X Y) theorem of_hasBinaryCoproduct' [HasBinaryCoproduct X Y] [HasInitial C] : IsPushout (initial.to _) (initial.to _) (coprod.inl : X ⟶ _) (coprod.inr : Y ⟶ _) := of_is_coproduct (colimit.isColimit _) initialIsInitial open ZeroObject theorem of_hasBinaryCoproduct [HasBinaryCoproduct X Y] [HasZeroObject C] [HasZeroMorphisms C] : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) coprod.inl coprod.inr := by convert @of_is_coproduct _ _ 0 X Y _ (colimit.isColimit _) HasZeroObject.zeroIsInitial <;> subsingleton section variable {P' : C} {inl' : X ⟶ P'} {inr' : Y ⟶ P'} /-- Any object at the bottom right of a pushout square is isomorphic to the object at the bottom right of any other pushout square with the same span. -/ noncomputable def isoIsPushout (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : P ≅ P' := IsColimit.coconePointUniqueUpToIso h.isColimit h'.isColimit @[reassoc (attr := simp)] theorem inl_isoIsPushout_hom (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inl ≫ (h.isoIsPushout _ _ h').hom = inl' := IsColimit.comp_coconePointUniqueUpToIso_hom h.isColimit h'.isColimit WalkingSpan.left @[reassoc (attr := simp)] theorem inr_isoIsPushout_hom (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inr ≫ (h.isoIsPushout _ _ h').hom = inr' := IsColimit.comp_coconePointUniqueUpToIso_hom h.isColimit h'.isColimit WalkingSpan.right @[reassoc (attr := simp)] theorem inl_isoIsPushout_inv (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inl' ≫ (h.isoIsPushout _ _ h').inv = inl := by simp only [Iso.comp_inv_eq, inl_isoIsPushout_hom] @[reassoc (attr := simp)] theorem inr_isoIsPushout_inv (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inr' ≫ (h.isoIsPushout _ _ h').inv = inr := by simp only [Iso.comp_inv_eq, inr_isoIsPushout_hom] end variable {X Y} /-- Any object at the top left of a pullback square is isomorphic to the pullback provided by the `HasLimit` API. -/ noncomputable def isoPushout (h : IsPushout f g inl inr) [HasPushout f g] : P ≅ pushout f g := (colimit.isoColimitCocone ⟨_, h.isColimit⟩).symm @[reassoc (attr := simp)] theorem inl_isoPushout_inv (h : IsPushout f g inl inr) [HasPushout f g] : pushout.inl _ _ ≫ h.isoPushout.inv = inl := by dsimp [isoPushout, cocone, CommSq.cocone] simp @[reassoc (attr := simp)] theorem inr_isoPushout_inv (h : IsPushout f g inl inr) [HasPushout f g] : pushout.inr _ _ ≫ h.isoPushout.inv = inr := by dsimp [isoPushout, cocone, CommSq.cocone] simp @[reassoc (attr := simp)] theorem inl_isoPushout_hom (h : IsPushout f g inl inr) [HasPushout f g] : inl ≫ h.isoPushout.hom = pushout.inl _ _ := by simp [← Iso.eq_comp_inv] @[reassoc (attr := simp)] theorem inr_isoPushout_hom (h : IsPushout f g inl inr) [HasPushout f g] : inr ≫ h.isoPushout.hom = pushout.inr _ _ := by simp [← Iso.eq_comp_inv] theorem of_iso_pushout (h : CommSq f g inl inr) [HasPushout f g] (i : P ≅ pushout f g) (w₁ : inl ≫ i.hom = pushout.inl _ _) (w₂ : inr ≫ i.hom = pushout.inr _ _) : IsPushout f g inl inr := of_isColimit' h (Limits.IsColimit.ofIsoColimit (colimit.isColimit _) (PushoutCocone.ext (s := PushoutCocone.mk ..) i w₁ w₂).symm) lemma of_iso (h : IsPushout f g inl inr) {Z' X' Y' P' : C} {f' : Z' ⟶ X'} {g' : Z' ⟶ Y'} {inl' : X' ⟶ P'} {inr' : Y' ⟶ P'} (e₁ : Z ≅ Z') (e₂ : X ≅ X') (e₃ : Y ≅ Y') (e₄ : P ≅ P') (commf : f ≫ e₂.hom = e₁.hom ≫ f') (commg : g ≫ e₃.hom = e₁.hom ≫ g') (comminl : inl ≫ e₄.hom = e₂.hom ≫ inl') (comminr : inr ≫ e₄.hom = e₃.hom ≫ inr') : IsPushout f' g' inl' inr' where w := by rw [← cancel_epi e₁.hom, ← reassoc_of% commf, ← comminl, ← reassoc_of% commg, ← comminr, h.w_assoc] isColimit' := ⟨(IsColimit.precomposeHomEquiv (spanExt e₁ e₂ e₃ commf.symm commg.symm) _).1 (IsColimit.ofIsoColimit h.isColimit (PushoutCocone.ext e₄ comminl comminr))⟩ section variable {P X Y : C} {inl : X ⟶ P} {inr : X ⟶ P} {f : Y ⟶ X} [Epi f] lemma isIso_inl_iso_of_epi (h : IsPushout f f inl inr) : IsIso inl := h.cocone.isIso_inl_of_epi_of_isColimit h.isColimit lemma isIso_inr_iso_of_epi (h : IsPushout f f inl inr) : IsIso inr := h.cocone.isIso_inr_of_epi_of_isColimit h.isColimit end section lemma isIso_inl_of_isIso (h : IsPushout f g inl inr) [IsIso g] : IsIso inl := by have := h.hasPushout rw [← h.inl_isoPushout_inv] infer_instance lemma isIso_inr_of_isIso (h : IsPushout f g inl inr) [IsIso f] : IsIso inr := by have := h.hasPushout rw [← h.inr_isoPushout_inv] infer_instance end end IsPushout namespace IsPullback variable {P X Y Z : C} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} theorem flip (h : IsPullback fst snd f g) : IsPullback snd fst g f := of_isLimit (PullbackCone.flipIsLimit h.isLimit) theorem flip_iff : IsPullback fst snd f g ↔ IsPullback snd fst g f := ⟨flip, flip⟩ section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The square with `0 : 0 ⟶ 0` on the left and `𝟙 X` on the right is a pullback square. -/ @[simp] theorem zero_left (X : C) : IsPullback (0 : 0 ⟶ X) (0 : (0 : C) ⟶ 0) (𝟙 X) (0 : 0 ⟶ X) := { w := by simp isLimit' := ⟨{ lift := fun _ => 0 fac := fun s => by simpa [eq_iff_true_of_subsingleton] using @PullbackCone.equalizer_ext _ _ _ _ _ _ _ s _ 0 (𝟙 _) (by simpa using (PullbackCone.condition s).symm) }⟩ } /-- The square with `0 : 0 ⟶ 0` on the top and `𝟙 X` on the bottom is a pullback square. -/ @[simp] theorem zero_top (X : C) : IsPullback (0 : (0 : C) ⟶ 0) (0 : 0 ⟶ X) (0 : 0 ⟶ X) (𝟙 X) := (zero_left X).flip /-- The square with `0 : 0 ⟶ 0` on the right and `𝟙 X` on the left is a pullback square. -/ @[simp] theorem zero_right (X : C) : IsPullback (0 : X ⟶ 0) (𝟙 X) (0 : (0 : C) ⟶ 0) (0 : X ⟶ 0) := of_iso_pullback (by simp) ((zeroProdIso X).symm ≪≫ (pullbackZeroZeroIso _ _).symm) (by simp [eq_iff_true_of_subsingleton]) (by simp) /-- The square with `0 : 0 ⟶ 0` on the bottom and `𝟙 X` on the top is a pullback square. -/ @[simp] theorem zero_bot (X : C) : IsPullback (𝟙 X) (0 : X ⟶ 0) (0 : X ⟶ 0) (0 : (0 : C) ⟶ 0) := (zero_right X).flip end -- Objects here are arranged in a 3x2 grid, and indexed by their xy coordinates. -- Morphisms are named `hᵢⱼ` for a horizontal morphism starting at `(i,j)`, -- and `vᵢⱼ` for a vertical morphism starting at `(i,j)`. /-- Paste two pullback squares "vertically" to obtain another pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem paste_vert {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ := of_isLimit (pasteHorizIsPullback rfl t.isLimit s.isLimit) /-- Paste two pullback squares "horizontally" to obtain another pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem paste_horiz {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) := (paste_vert s.flip t.flip).flip /-- Given a pullback square assembled from a commuting square on the top and a pullback square on the bottom, the top square is a pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_bot {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁) (p : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := of_isLimit (leftSquareIsPullback (PullbackCone.mk h₁₁ _ p) rfl t.isLimit s.isLimit) /-- Given a pullback square assembled from a commuting square on the left and a pullback square on the right, the left square is a pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_right {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (p : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := (of_bot s.flip p.symm t.flip).flip theorem paste_vert_iff {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) (e : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ ↔ IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := ⟨fun h => h.of_bot e s, fun h => h.paste_vert s⟩ theorem paste_horiz_iff {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) (e : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) ↔ IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := ⟨fun h => h.of_right e s, fun h => h.paste_horiz s⟩ /-- Variant of `IsPullback.of_right` where `h₁₁` is induced from a morphism `h₁₃ : X₁₁ ⟶ X₁₃`, and the universal property of the right square. The objects fit in the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_right' {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {h₁₃ : X₁₁ ⟶ X₁₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₃ v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback (t.lift h₁₃ (v₁₁ ≫ h₂₁) (by rw [s.w, Category.assoc])) v₁₁ v₁₂ h₂₁ := of_right ((t.lift_fst _ _ _) ▸ s) (t.lift_snd _ _ _) t /-- Variant of `IsPullback.of_bot`, where `v₁₁` is induced from a morphism `v₃₁ : X₁₁ ⟶ X₃₁`, and the universal property of the bottom square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_bot' {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₃₁ : X₁₁ ⟶ X₃₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ v₃₁ (v₁₂ ≫ v₂₂) h₃₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ (t.lift (h₁₁ ≫ v₁₂) v₃₁ (by rw [Category.assoc, s.w])) v₁₂ h₂₁ := of_bot ((t.lift_snd _ _ _) ▸ s) (by simp only [lift_fst]) t instance [HasPullbacksAlong f] (h : P ⟶ Y) : HasPullback h (pullback.fst g f) := IsPullback.hasPullback (IsPullback.of_bot' (IsPullback.of_hasPullback (h ≫ g) f) (IsPullback.of_hasPullback g f)) section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject theorem of_isBilimit {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.fst b.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert IsPullback.of_is_product' h.isLimit HasZeroObject.zeroIsTerminal <;> subsingleton @[simp] theorem of_has_biproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.fst biprod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := of_isBilimit (BinaryBiproduct.isBilimit X Y) theorem inl_snd' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.inl (0 : X ⟶ 0) b.snd (0 : 0 ⟶ Y) := by refine of_right ?_ (by simp) (of_isBilimit h) simp /-- The square ``` X --inl--> X ⊞ Y | | 0 snd | | v v 0 ---0-----> Y ``` is a pullback square. -/ @[simp] theorem inl_snd (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.inl (0 : X ⟶ 0) biprod.snd (0 : 0 ⟶ Y) := inl_snd' (BinaryBiproduct.isBilimit X Y) theorem inr_fst' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.inr (0 : Y ⟶ 0) b.fst (0 : 0 ⟶ X) := by apply flip refine of_bot ?_ (by simp) (of_isBilimit h) simp /-- The square ``` Y --inr--> X ⊞ Y | | 0 fst | | v v 0 ---0-----> X ``` is a pullback square. -/ @[simp] theorem inr_fst (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.inr (0 : Y ⟶ 0) biprod.fst (0 : 0 ⟶ X) := inr_fst' (BinaryBiproduct.isBilimit X Y) theorem of_is_bilimit' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := by refine IsPullback.of_right ?_ (by simp) (IsPullback.inl_snd' h).flip simp theorem of_hasBinaryBiproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPullback (0 : 0 ⟶ X) (0 : 0 ⟶ Y) biprod.inl biprod.inr := of_is_bilimit' (BinaryBiproduct.isBilimit X Y) instance hasPullback_biprod_fst_biprod_snd [HasBinaryBiproduct X Y] : HasPullback (biprod.inl : X ⟶ _) (biprod.inr : Y ⟶ _) := HasLimit.mk ⟨_, (of_hasBinaryBiproduct X Y).isLimit⟩ /-- The pullback of `biprod.inl` and `biprod.inr` is the zero object. -/ def pullbackBiprodInlBiprodInr [HasBinaryBiproduct X Y] : pullback (biprod.inl : X ⟶ _) (biprod.inr : Y ⟶ _) ≅ 0 := limit.isoLimitCone ⟨_, (of_hasBinaryBiproduct X Y).isLimit⟩ end theorem op (h : IsPullback fst snd f g) : IsPushout g.op f.op snd.op fst.op := IsPushout.of_isColimit (IsColimit.ofIsoColimit (Limits.PullbackCone.isLimitEquivIsColimitOp h.flip.cone h.flip.isLimit) h.toCommSq.flip.coneOp) theorem unop {P X Y Z : Cᵒᵖ} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} (h : IsPullback fst snd f g) : IsPushout g.unop f.unop snd.unop fst.unop := IsPushout.of_isColimit (IsColimit.ofIsoColimit (Limits.PullbackCone.isLimitEquivIsColimitUnop h.flip.cone h.flip.isLimit) h.toCommSq.flip.coneUnop) theorem of_vert_isIso_mono [IsIso snd] [Mono f] (sq : CommSq fst snd f g) : IsPullback fst snd f g := IsPullback.flip (of_horiz_isIso_mono sq.flip) theorem of_vert_isIso [IsIso snd] [IsIso f] (sq : CommSq fst snd f g) : IsPullback fst snd f g := of_vert_isIso_mono sq lemma of_id_fst : IsPullback (𝟙 _) f f (𝟙 _) := IsPullback.of_horiz_isIso ⟨by simp⟩ lemma of_id_snd : IsPullback f (𝟙 _) (𝟙 _) f := IsPullback.of_vert_isIso ⟨by simp⟩ /-- The following diagram is a pullback ``` X --f--> Z | | id id v v X --f--> Z ``` -/ lemma id_vert (f : X ⟶ Z) : IsPullback f (𝟙 X) (𝟙 Z) f := of_vert_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ /-- The following diagram is a pullback ``` X --id--> X | | f f v v Z --id--> Z ``` -/ lemma id_horiz (f : X ⟶ Z) : IsPullback (𝟙 X) f f (𝟙 Z) := of_horiz_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ /-- In a category, given a morphism `f : A ⟶ B` and an object `X`, this is the obvious pullback diagram: ``` A ⨯ X ⟶ A | | v v B ⨯ X ⟶ B ``` -/ lemma of_prod_fst_with_id {A B : C} (f : A ⟶ B) (X : C) [HasBinaryProduct A X] [HasBinaryProduct B X] : IsPullback prod.fst (prod.map f (𝟙 X)) f prod.fst where isLimit' := ⟨PullbackCone.isLimitAux' _ (fun s ↦ by refine ⟨prod.lift s.fst (s.snd ≫ prod.snd), ?_, ?_, ?_⟩ · simp · ext · simp [PullbackCone.condition] · simp · intro m h₁ h₂ dsimp at m h₁ h₂ ⊢ ext · simpa using h₁ · simp [← h₂])⟩ lemma of_isLimit_binaryFan_of_isTerminal {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) {T : C} (hT : IsTerminal T) : IsPullback c.fst c.snd (hT.from _) (hT.from _) where isLimit' := ⟨PullbackCone.IsLimit.mk _ (fun s ↦ hc.lift (BinaryFan.mk s.fst s.snd)) (fun s ↦ hc.fac (BinaryFan.mk s.fst s.snd) ⟨.left⟩) (fun s ↦ hc.fac (BinaryFan.mk s.fst s.snd) ⟨.right⟩) (fun s m h₁ h₂ ↦ by apply BinaryFan.IsLimit.hom_ext hc · rw [h₁, hc.fac (BinaryFan.mk s.fst s.snd) ⟨.left⟩] rfl · rw [h₂, hc.fac (BinaryFan.mk s.fst s.snd) ⟨.right⟩] rfl)⟩ end IsPullback namespace IsPushout variable {Z X Y P : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} theorem flip (h : IsPushout f g inl inr) : IsPushout g f inr inl := of_isColimit (PushoutCocone.flipIsColimit h.isColimit) theorem flip_iff : IsPushout f g inl inr ↔ IsPushout g f inr inl := ⟨flip, flip⟩ section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The square with `0 : 0 ⟶ 0` on the right and `𝟙 X` on the left is a pushout square. -/ @[simp] theorem zero_right (X : C) : IsPushout (0 : X ⟶ 0) (𝟙 X) (0 : (0 : C) ⟶ 0) (0 : X ⟶ 0) := { w := by simp isColimit' := ⟨{ desc := fun _ => 0 fac := fun s => by have c := @PushoutCocone.coequalizer_ext _ _ _ _ _ _ _ s _ 0 (𝟙 _) (by simp [eq_iff_true_of_subsingleton]) (by simpa using PushoutCocone.condition s) dsimp at c simpa using c }⟩ } /-- The square with `0 : 0 ⟶ 0` on the bottom and `𝟙 X` on the top is a pushout square. -/ @[simp] theorem zero_bot (X : C) : IsPushout (𝟙 X) (0 : X ⟶ 0) (0 : X ⟶ 0) (0 : (0 : C) ⟶ 0) := (zero_right X).flip /-- The square with `0 : 0 ⟶ 0` on the right left `𝟙 X` on the right is a pushout square. -/ @[simp] theorem zero_left (X : C) : IsPushout (0 : 0 ⟶ X) (0 : (0 : C) ⟶ 0) (𝟙 X) (0 : 0 ⟶ X) := of_iso_pushout (by simp) ((coprodZeroIso X).symm ≪≫ (pushoutZeroZeroIso _ _).symm) (by simp) (by simp [eq_iff_true_of_subsingleton]) /-- The square with `0 : 0 ⟶ 0` on the top and `𝟙 X` on the bottom is a pushout square. -/ @[simp] theorem zero_top (X : C) : IsPushout (0 : (0 : C) ⟶ 0) (0 : 0 ⟶ X) (0 : 0 ⟶ X) (𝟙 X) := (zero_left X).flip end -- Objects here are arranged in a 3x2 grid, and indexed by their xy coordinates. -- Morphisms are named `hᵢⱼ` for a horizontal morphism starting at `(i,j)`, -- and `vᵢⱼ` for a vertical morphism starting at `(i,j)`. /-- Paste two pushout squares "vertically" to obtain another pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem paste_vert {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPushout h₂₁ v₂₁ v₂₂ h₃₁) : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ := of_isColimit (pasteHorizIsPushout rfl s.isColimit t.isColimit) /-- Paste two pushout squares "horizontally" to obtain another pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem paste_horiz {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPushout h₁₂ v₁₂ v₁₃ h₂₂) : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) := (paste_vert s.flip t.flip).flip /-- Given a pushout square assembled from a pushout square on the top and a commuting square on the bottom, the bottom square is a pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_top {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁) (p : h₂₁ ≫ v₂₂ = v₂₁ ≫ h₃₁) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₂₁ v₂₁ v₂₂ h₃₁ := of_isColimit <| rightSquareIsPushout (PushoutCocone.mk _ _ p) (cocone_inr _) t.isColimit s.isColimit /-- Given a pushout square assembled from a pushout square on the left and a commuting square on the right, the right square is a pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_left {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (p : h₁₂ ≫ v₁₃ = v₁₂ ≫ h₂₂) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₁₂ v₁₂ v₁₃ h₂₂ := (of_top s.flip p.symm t.flip).flip theorem paste_vert_iff {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (e : h₂₁ ≫ v₂₂ = v₂₁ ≫ h₃₁) : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ ↔ IsPushout h₂₁ v₂₁ v₂₂ h₃₁ := ⟨fun h => h.of_top e s, s.paste_vert⟩ theorem paste_horiz_iff {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (e : h₁₂ ≫ v₁₃ = v₁₂ ≫ h₂₂) : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) ↔ IsPushout h₁₂ v₁₂ v₁₃ h₂₂ := ⟨fun h => h.of_left e s, s.paste_horiz⟩ /-- Variant of `IsPushout.of_top` where `v₂₂` is induced from a morphism `v₁₃ : X₁₂ ⟶ X₃₂`, and the universal property of the top square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_top' {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₂ ⟶ X₃₂} {v₂₁ : X₂₁ ⟶ X₃₁} (s : IsPushout h₁₁ (v₁₁ ≫ v₂₁) v₁₃ h₃₁) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₂₁ v₂₁ (t.desc v₁₃ (v₂₁ ≫ h₃₁) (by rw [s.w, Category.assoc])) h₃₁ := of_top ((t.inl_desc _ _ _).symm ▸ s) (t.inr_desc _ _ _) t /-- Variant of `IsPushout.of_right` where `h₂₂` is induced from a morphism `h₂₃ : X₂₁ ⟶ X₂₃`, and the universal property of the left square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_left' {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₃ : X₂₁ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ h₂₃) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₁₂ v₁₂ v₁₃ (t.desc (h₁₂ ≫ v₁₃) h₂₃ (by rw [← Category.assoc, s.w])) := of_left ((t.inr_desc _ _ _).symm ▸ s) (by simp only [inl_desc]) t section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject theorem of_isBilimit {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := by convert IsPushout.of_is_coproduct' h.isColimit HasZeroObject.zeroIsInitial <;> subsingleton @[simp] theorem of_has_biproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) biprod.inl biprod.inr := of_isBilimit (BinaryBiproduct.isBilimit X Y) theorem inl_snd' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout b.inl (0 : X ⟶ 0) b.snd (0 : 0 ⟶ Y) := by apply flip refine of_left ?_ (by simp) (of_isBilimit h) simp /-- The square ``` X --inl--> X ⊞ Y | | 0 snd | | v v 0 ---0-----> Y ``` is a pushout square. -/ theorem inl_snd (X Y : C) [HasBinaryBiproduct X Y] : IsPushout biprod.inl (0 : X ⟶ 0) biprod.snd (0 : 0 ⟶ Y) := inl_snd' (BinaryBiproduct.isBilimit X Y) theorem inr_fst' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout b.inr (0 : Y ⟶ 0) b.fst (0 : 0 ⟶ X) := by refine of_top ?_ (by simp) (of_isBilimit h) simp /-- The square ``` Y --inr--> X ⊞ Y | | 0 fst | | v v 0 ---0-----> X ``` is a pushout square. -/ theorem inr_fst (X Y : C) [HasBinaryBiproduct X Y] : IsPushout biprod.inr (0 : Y ⟶ 0) biprod.fst (0 : 0 ⟶ X) := inr_fst' (BinaryBiproduct.isBilimit X Y) theorem of_is_bilimit' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout b.fst b.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by refine IsPushout.of_left ?_ (by simp) (IsPushout.inl_snd' h) simp theorem of_hasBinaryBiproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPushout biprod.fst biprod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := of_is_bilimit' (BinaryBiproduct.isBilimit X Y) instance hasPushout_biprod_fst_biprod_snd [HasBinaryBiproduct X Y] : HasPushout (biprod.fst : _ ⟶ X) (biprod.snd : _ ⟶ Y) := HasColimit.mk ⟨_, (of_hasBinaryBiproduct X Y).isColimit⟩ /-- The pushout of `biprod.fst` and `biprod.snd` is the zero object. -/ def pushoutBiprodFstBiprodSnd [HasBinaryBiproduct X Y] : pushout (biprod.fst : _ ⟶ X) (biprod.snd : _ ⟶ Y) ≅ 0 := colimit.isoColimitCocone ⟨_, (of_hasBinaryBiproduct X Y).isColimit⟩ end theorem op (h : IsPushout f g inl inr) : IsPullback inr.op inl.op g.op f.op := IsPullback.of_isLimit (IsLimit.ofIsoLimit (Limits.PushoutCocone.isColimitEquivIsLimitOp h.flip.cocone h.flip.isColimit) h.toCommSq.flip.coconeOp) theorem unop {Z X Y P : Cᵒᵖ} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} (h : IsPushout f g inl inr) : IsPullback inr.unop inl.unop g.unop f.unop := IsPullback.of_isLimit (IsLimit.ofIsoLimit (Limits.PushoutCocone.isColimitEquivIsLimitUnop h.flip.cocone h.flip.isColimit) h.toCommSq.flip.coconeUnop) theorem of_horiz_isIso_epi [Epi f] [IsIso inr] (sq : CommSq f g inl inr) : IsPushout f g inl inr := of_isColimit' sq (by refine PushoutCocone.IsColimit.mk _ (fun s => inv inr ≫ s.inr) (fun s => ?_) (by simp) (by simp) simp only [← cancel_epi f, s.condition, sq.w_assoc, IsIso.hom_inv_id_assoc]) theorem of_horiz_isIso [IsIso f] [IsIso inr] (sq : CommSq f g inl inr) : IsPushout f g inl inr := of_horiz_isIso_epi sq theorem of_vert_isIso_epi [Epi g] [IsIso inl] (sq : CommSq f g inl inr) : IsPushout f g inl inr := (of_horiz_isIso_epi sq.flip).flip theorem of_vert_isIso [IsIso g] [IsIso inl] (sq : CommSq f g inl inr) : IsPushout f g inl inr := of_vert_isIso_epi sq lemma of_id_fst : IsPushout (𝟙 _) f f (𝟙 _) := IsPushout.of_horiz_isIso ⟨by simp⟩ lemma of_id_snd : IsPushout f (𝟙 _) (𝟙 _) f := IsPushout.of_vert_isIso ⟨by simp⟩ /-- The following diagram is a pullback ``` X --f--> Z | | id id v v X --f--> Z ``` -/ lemma id_vert (f : X ⟶ Z) : IsPushout f (𝟙 X) (𝟙 Z) f := of_vert_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ /-- The following diagram is a pullback ``` X --id--> X | | f f v v Z --id--> Z ``` -/ lemma id_horiz (f : X ⟶ Z) : IsPushout (𝟙 X) f f (𝟙 Z) := of_horiz_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ /-- In a category, given a morphism `f : A ⟶ B` and an object `X`, this is the obvious pushout diagram: ``` A ⟶ A ⨿ X | | v v B ⟶ B ⨿ X ``` -/ lemma of_coprod_inl_with_id {A B : C} (f : A ⟶ B) (X : C) [HasBinaryCoproduct A X] [HasBinaryCoproduct B X] : IsPushout coprod.inl f (coprod.map f (𝟙 X)) coprod.inl where w := by simp isColimit' := ⟨PushoutCocone.isColimitAux' _ (fun s ↦ by refine ⟨coprod.desc s.inr (coprod.inr ≫ s.inl), ?_, ?_, ?_⟩ · ext · simp [PushoutCocone.condition] · simp · simp · intro m h₁ h₂ dsimp at m h₁ h₂ ⊢ ext · simpa using h₂ · simp [← h₁])⟩ lemma of_isColimit_binaryCofan_of_isInitial {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) {I : C} (hI : IsInitial I) : IsPushout (hI.to _) (hI.to _) c.inr c.inl where w := hI.hom_ext _ _ isColimit' := ⟨PushoutCocone.IsColimit.mk _ (fun s ↦ hc.desc (BinaryCofan.mk s.inr s.inl)) (fun s ↦ hc.fac (BinaryCofan.mk s.inr s.inl) ⟨.right⟩) (fun s ↦ hc.fac (BinaryCofan.mk s.inr s.inl) ⟨.left⟩) (fun s m h₁ h₂ ↦ by apply BinaryCofan.IsColimit.hom_ext hc · rw [h₂, hc.fac (BinaryCofan.mk s.inr s.inl) ⟨.left⟩] rfl · rw [h₁, hc.fac (BinaryCofan.mk s.inr s.inl) ⟨.right⟩] rfl)⟩ end IsPushout section Equalizer variable {X Y Z : C} {f f' : X ⟶ Y} {g g' : Y ⟶ Z} /-- If `f : X ⟶ Y`, `g g' : Y ⟶ Z` forms a pullback square, then `f` is the equalizer of `g` and `g'`. -/ noncomputable def IsPullback.isLimitFork (H : IsPullback f f g g') : IsLimit (Fork.ofι f H.w) := by fapply Fork.IsLimit.mk · exact fun s => H.isLimit.lift (PullbackCone.mk s.ι s.ι s.condition) · exact fun s => H.isLimit.fac _ WalkingCospan.left · intro s m e apply PullbackCone.IsLimit.hom_ext H.isLimit <;> refine e.trans ?_ <;> symm <;> exact H.isLimit.fac _ _ /-- If `f f' : X ⟶ Y`, `g : Y ⟶ Z` forms a pushout square, then `g` is the coequalizer of `f` and `f'`. -/ noncomputable def IsPushout.isLimitFork (H : IsPushout f f' g g) : IsColimit (Cofork.ofπ g H.w) := by fapply Cofork.IsColimit.mk · exact fun s => H.isColimit.desc (PushoutCocone.mk s.π s.π s.condition) · exact fun s => H.isColimit.fac _ WalkingSpan.left · intro s m e apply PushoutCocone.IsColimit.hom_ext H.isColimit <;> refine e.trans ?_ <;> symm <;> exact H.isColimit.fac _ _ end Equalizer namespace BicartesianSq variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} theorem of_isPullback_isPushout (p₁ : IsPullback f g h i) (p₂ : IsPushout f g h i) : BicartesianSq f g h i := BicartesianSq.mk p₁ p₂.isColimit' theorem flip (p : BicartesianSq f g h i) : BicartesianSq g f i h := of_isPullback_isPushout p.toIsPullback.flip p.toIsPushout.flip variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- ``` X ⊞ Y --fst--> X | | snd 0 | | v v Y -----0---> 0 ``` is a bi-Cartesian square. -/ theorem of_is_biproduct₁ {b : BinaryBicone X Y} (h : b.IsBilimit) : BicartesianSq b.fst b.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := of_isPullback_isPushout (IsPullback.of_isBilimit h) (IsPushout.of_is_bilimit' h) /-- ``` 0 -----0---> X | | 0 inl | | v v Y --inr--> X ⊞ Y ``` is a bi-Cartesian square. -/ theorem of_is_biproduct₂ {b : BinaryBicone X Y} (h : b.IsBilimit) : BicartesianSq (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := of_isPullback_isPushout (IsPullback.of_is_bilimit' h) (IsPushout.of_isBilimit h) /-- ``` X ⊞ Y --fst--> X | | snd 0 | | v v Y -----0---> 0 ``` is a bi-Cartesian square. -/ @[simp] theorem of_has_biproduct₁ [HasBinaryBiproduct X Y] : BicartesianSq biprod.fst biprod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert of_is_biproduct₁ (BinaryBiproduct.isBilimit X Y) /-- ``` 0 -----0---> X | | 0 inl | | v v Y --inr--> X ⊞ Y ``` is a bi-Cartesian square. -/ @[simp] theorem of_has_biproduct₂ [HasBinaryBiproduct X Y] : BicartesianSq (0 : 0 ⟶ X) (0 : 0 ⟶ Y) biprod.inl biprod.inr := by convert of_is_biproduct₂ (BinaryBiproduct.isBilimit X Y) end BicartesianSq section Functor variable {D : Type u₂} [Category.{v₂} D] variable (F : C ⥤ D) {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} theorem Functor.map_isPullback [PreservesLimit (cospan h i) F] (s : IsPullback f g h i) : IsPullback (F.map f) (F.map g) (F.map h) (F.map i) := by -- This is made slightly awkward because `C` and `D` have different universes, -- and so the relevant `WalkingCospan` diagrams live in different universes too! refine IsPullback.of_isLimit' (F.map_commSq s.toCommSq) (IsLimit.equivOfNatIsoOfIso (cospanCompIso F h i) _ _ (WalkingCospan.ext ?_ ?_ ?_) (isLimitOfPreserves F s.isLimit)) · rfl · simp · simp theorem Functor.map_isPushout [PreservesColimit (span f g) F] (s : IsPushout f g h i) : IsPushout (F.map f) (F.map g) (F.map h) (F.map i) := by refine IsPushout.of_isColimit' (F.map_commSq s.toCommSq) (IsColimit.equivOfNatIsoOfIso (spanCompIso F f g) _ _ (WalkingSpan.ext ?_ ?_ ?_) (isColimitOfPreserves F s.isColimit)) · rfl · simp · simp alias IsPullback.map := Functor.map_isPullback alias IsPushout.map := Functor.map_isPushout theorem IsPullback.of_map [ReflectsLimit (cospan h i) F] (e : f ≫ h = g ≫ i) (H : IsPullback (F.map f) (F.map g) (F.map h) (F.map i)) : IsPullback f g h i := by refine ⟨⟨e⟩, ⟨isLimitOfReflects F <| ?_⟩⟩ refine (IsLimit.equivOfNatIsoOfIso (cospanCompIso F h i) _ _ (WalkingCospan.ext ?_ ?_ ?_)).symm H.isLimit exacts [Iso.refl _, (Category.comp_id _).trans (Category.id_comp _).symm, (Category.comp_id _).trans (Category.id_comp _).symm] theorem IsPullback.of_map_of_faithful [ReflectsLimit (cospan h i) F] [F.Faithful] (H : IsPullback (F.map f) (F.map g) (F.map h) (F.map i)) : IsPullback f g h i := H.of_map F (F.map_injective <| by simpa only [F.map_comp] using H.w) theorem IsPullback.map_iff {D : Type*} [Category D] (F : C ⥤ D) [PreservesLimit (cospan h i) F] [ReflectsLimit (cospan h i) F] (e : f ≫ h = g ≫ i) : IsPullback (F.map f) (F.map g) (F.map h) (F.map i) ↔ IsPullback f g h i := ⟨fun h => h.of_map F e, fun h => h.map F⟩ theorem IsPushout.of_map [ReflectsColimit (span f g) F] (e : f ≫ h = g ≫ i) (H : IsPushout (F.map f) (F.map g) (F.map h) (F.map i)) : IsPushout f g h i := by refine ⟨⟨e⟩, ⟨isColimitOfReflects F <| ?_⟩⟩ refine (IsColimit.equivOfNatIsoOfIso (spanCompIso F f g) _ _ (WalkingSpan.ext ?_ ?_ ?_)).symm H.isColimit exacts [Iso.refl _, (Category.comp_id _).trans (Category.id_comp _), (Category.comp_id _).trans (Category.id_comp _)] theorem IsPushout.of_map_of_faithful [ReflectsColimit (span f g) F] [F.Faithful] (H : IsPushout (F.map f) (F.map g) (F.map h) (F.map i)) : IsPushout f g h i := H.of_map F (F.map_injective <| by simpa only [F.map_comp] using H.w) theorem IsPushout.map_iff {D : Type*} [Category D] (F : C ⥤ D) [PreservesColimit (span f g) F] [ReflectsColimit (span f g) F] (e : f ≫ h = g ≫ i) : IsPushout (F.map f) (F.map g) (F.map h) (F.map i) ↔ IsPushout f g h i := ⟨fun h => h.of_map F e, fun h => h.map F⟩ end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Categorical/Basic.lean
import Mathlib.CategoryTheory.CatCommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Categorical.CatCospanTransform /-! # Categorical pullbacks This file defines the basic properties of categorical pullbacks. Given a pair of functors `(F : A ⥤ B, G : C ⥤ B)`, we define the category `CategoricalPullback F G` as the category of triples `(a : A, c : C, e : F.obj a ≅ G.obj b)`. The category `CategoricalPullback F G` sits in a canonical `CatCommSq`, and we formalize that this square is a "limit" in the following sense: functors `X ⥤ CategoricalPullback F G` are equivalent to pairs of functors `(L : X ⥤ A, R : X ⥤ C)` equipped with a natural isomorphism `L ⋙ F ≅ R ⋙ G`. We formalize this by introducing a category `CatCommSqOver F G X` that encodes exactly this data, and we prove that the category of functors `X ⥤ CategoricalPullback F G` is equivalent to `CatCommSqOver F G X`. ## Main declarations * `CategoricalPullback F G`: the type of the categorical pullback. * `π₁ F G : CategoricalPullback F G` and `π₂ F G : CategoricalPullback F G`: the canonical projections. * `CategoricalPullback.catCommSq`: the canonical `CatCommSq (π₁ F G) (π₂ F G) F G` which exhibits `CategoricalPullback F G` as the pullback (in the (2,1)-categorical sense) of the cospan of `F` and `G`. * `CategoricalPullback.functorEquiv F G X`: the equivalence of categories between functors `X ⥤ CategoricalPullback F G` and `CatCommSqOver F G X`, where the latter is an abbrev for `CategoricalPullback (whiskeringRight X A B|>.obj F) (whiskeringRight X C B|>.obj G)`. ## References * [Kerodon: section 1.4.5.2](https://kerodon.net/tag/032Y) * [Niles Johnson, Donald Yau, *2-Dimensional Categories*](https://arxiv.org/abs/2002.06055), example 5.3.9, although we take a slightly different (equivalent) model of the object. ## TODOs: * 2-functoriality of the construction with respect to "transformation of categorical cospans". * Full equivalence-invariance of the notion (follows from suitable 2-functoriality). * Define a `CatPullbackSquare` typeclass extending `CatCommSq`that encodes the fact that a given `CatCommSq` defines an equivalence between the top left corner and the categorical pullback of its legs. * Define a `IsCatPullbackSquare` propclass. * Define the "categorical fiber" of a functor at an object of the target category. * Pasting calculus for categorical pullback squares. * Categorical pullback squares attached to Grothendieck constructions of pseudofunctors. * Stability of (co)fibered categories under categorical pullbacks. -/ universe v₁ v₂ v₃ v₄ v₅ v₆ v₇ v₈ v₉ v₁₀ v₁₁ v₁₂ v₁₃ universe u₁ u₂ u₃ u₄ u₅ u₆ u₇ u₈ u₉ u₁₀ u₁₁ u₁₂ u₁₃ namespace CategoryTheory.Limits section variable {A : Type u₁} {B : Type u₂} {C : Type u₃} [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C] (F : A ⥤ B) (G : C ⥤ B) /-- The `CategoricalPullback F G` is the category of triples `(a : A, c : C, F a ≅ G c)`. Morphisms `(a, c, e) ⟶ (a', c', e')` are pairs of morphisms `(f₁ : a ⟶ a', f₂ : c ⟶ c')` compatible with the specified isomorphisms. -/ @[kerodon 032Z] structure CategoricalPullback where /-- the first component element -/ fst : A /-- the second component element -/ snd : C /-- the structural isomorphism `F.obj fst ≅ G.obj snd` -/ iso : F.obj fst ≅ G.obj snd namespace CategoricalPullback /-- A notation for the categorical pullback. -/ scoped notation:max L:max " ⊡ " R:max => CategoricalPullback L R variable {F G} /-- The Hom types for the categorical pullback are given by pairs of maps compatible with the structural isomorphisms. -/ @[ext] structure Hom (x y : F ⊡ G) where /-- the first component of `f : Hom x y` is a morphism `x.fst ⟶ y.fst` -/ fst : x.fst ⟶ y.fst /-- the second component of `f : Hom x y` is a morphism `x.snd ⟶ y.snd` -/ snd : x.snd ⟶ y.snd /-- the compatibility condition on `fst` and `snd` with respect to the structure isomorphisms -/ w : F.map fst ≫ y.iso.hom = x.iso.hom ≫ G.map snd := by cat_disch attribute [reassoc (attr := simp)] Hom.w @[simps! id_fst id_snd comp_fst comp_snd] instance : Category (CategoricalPullback F G) where Hom x y := CategoricalPullback.Hom x y id x := { fst := 𝟙 x.fst snd := 𝟙 x.snd } comp f g := { fst := f.fst ≫ g.fst snd := f.snd ≫ g.snd } attribute [reassoc] comp_fst comp_snd /-- Naturality square for morphisms in the inverse direction. -/ @[reassoc (attr := simp)] lemma Hom.w' {x y : F ⊡ G} (f : x ⟶ y) : G.map f.snd ≫ y.iso.inv = x.iso.inv ≫ F.map f.fst := by rw [Iso.comp_inv_eq, Category.assoc, Eq.comm, Iso.inv_comp_eq, f.w] /-- Extensionnality principle for morphisms in `CategoricalPullback F G`. -/ @[ext] theorem hom_ext {x y : F ⊡ G} {f g : x ⟶ y} (hₗ : f.fst = g.fst) (hᵣ : f.snd = g.snd) : f = g := by apply Hom.ext <;> assumption section variable (F G) /-- `CategoricalPullback.π₁ F G` is the first projection `CategoricalPullback F G ⥤ A`. -/ @[simps] def π₁ : F ⊡ G ⥤ A where obj x := x.fst map f := f.fst /-- `CategoricalPullback.π₂ F G` is the second projection `CategoricalPullback F G ⥤ C`. -/ @[simps] def π₂ : F ⊡ G ⥤ C where obj x := x.snd map f := f.snd /-- The canonical categorical commutative square in which `CategoricalPullback F G` sits. -/ @[simps!] instance catCommSq : CatCommSq (π₁ F G) (π₂ F G) F G where iso := NatIso.ofComponents (fun x ↦ x.iso) variable {F G} in /-- Constructor for isomorphisms in `CategoricalPullback F G`. -/ @[simps!] def mkIso {x y : F ⊡ G} (eₗ : x.fst ≅ y.fst) (eᵣ : x.snd ≅ y.snd) (w : F.map eₗ.hom ≫ y.iso.hom = x.iso.hom ≫ G.map eᵣ.hom := by cat_disch) : x ≅ y where hom := ⟨eₗ.hom, eᵣ.hom, w⟩ inv := ⟨eₗ.inv, eᵣ.inv, by simpa using F.map eₗ.inv ≫= w.symm =≫ G.map eᵣ.inv⟩ section variable {x y : F ⊡ G} (f : x ⟶ y) [IsIso f] instance : IsIso f.fst := inferInstanceAs (IsIso ((π₁ _ _).mapIso (asIso f)).hom) instance : IsIso f.snd := inferInstanceAs (IsIso ((π₂ _ _).mapIso (asIso f)).hom) @[simp] lemma inv_fst : (inv f).fst = inv f.fst := by symm apply IsIso.inv_eq_of_hom_inv_id simpa [-IsIso.hom_inv_id] using congrArg (fun t ↦ t.fst) (IsIso.hom_inv_id f) @[simp] lemma inv_snd : (inv f).snd = inv f.snd := by symm apply IsIso.inv_eq_of_hom_inv_id simpa [-IsIso.hom_inv_id] using congrArg (fun t ↦ t.snd) (IsIso.hom_inv_id f) end lemma isIso_iff {x y : F ⊡ G} (f : x ⟶ y) : IsIso f ↔ (IsIso f.fst ∧ IsIso f.snd) where mp h := ⟨inferInstance, inferInstance⟩ mpr | ⟨h₁, h₂⟩ => ⟨⟨inv f.fst, inv f.snd, by cat_disch⟩, by cat_disch⟩ end section open Functor variable (X : Type u₄) [Category.{v₄} X] variable (F G) in /-- The data of a categorical commutative square over a cospan `F, G` with cone point `X` is that of a functor `T : X ⥤ A`, a functor `L : X ⥤ C`, and a `CatCommSqOver T L F G`. Note that this is *exactly* what an object of `((whiskeringRight X A B).obj F) ⊡ ((whiskeringRight X C B).obj G)` is, so `CatCommSqOver F G X` is in fact an abbreviation for `((whiskeringRight X A B).obj F) ⊡ ((whiskeringRight X C B).obj G)`. -/ abbrev CatCommSqOver := (whiskeringRight X A B |>.obj F) ⊡ (whiskeringRight X C B |>.obj G) namespace CatCommSqOver /-- Interpret a `CatCommSqOver F G X` as a `CatCommSq`. -/ @[simps] instance asSquare (S : CatCommSqOver F G X) : CatCommSq S.fst S.snd F G where iso := S.iso @[reassoc (attr := simp)] lemma iso_hom_naturality (S : CatCommSqOver F G X) {x x' : X} (f : x ⟶ x') : F.map (S.fst.map f) ≫ S.iso.hom.app x' = S.iso.hom.app x ≫ G.map (S.snd.map f) := S.iso.hom.naturality f @[reassoc (attr := simp)] lemma w_app {S S' : CatCommSqOver F G X} (φ : S ⟶ S') (x : X) : F.map (φ.fst.app x) ≫ S'.iso.hom.app x = S.iso.hom.app x ≫ G.map (φ.snd.app x) := NatTrans.congr_app φ.w x variable (F G) /-- The "first projection" of a CatCommSqOver as a functor. -/ abbrev fstFunctor : CatCommSqOver F G X ⥤ X ⥤ A := π₁ _ _ /-- The "second projection" of a CatCommSqOver as a functor. -/ abbrev sndFunctor : CatCommSqOver F G X ⥤ X ⥤ C := π₂ _ _ /-- The structure isomorphism of a `CatCommSqOver` as a natural transformation. -/ abbrev e : fstFunctor F G X ⋙ (whiskeringRight X A B).obj F ≅ sndFunctor F G X ⋙ (whiskeringRight X C B).obj G := NatIso.ofComponents (fun S ↦ S.iso) end CatCommSqOver section functorEquiv variable (F G) -- We need to split up the definition of `functorEquiv` to avoid timeouts. /-- Interpret a functor to the categorical pullback as a `CatCommSqOver`. -/ @[simps!] def toCatCommSqOver : (X ⥤ F ⊡ G) ⥤ CatCommSqOver F G X where obj J := { fst := J ⋙ π₁ F G snd := J ⋙ π₂ F G iso := associator _ _ _ ≪≫ isoWhiskerLeft J (catCommSq F G).iso ≪≫ (associator _ _ _).symm } map {J J'} F := { fst := whiskerRight F (π₁ _ _) snd := whiskerRight F (π₂ _ _) } /-- Interpret a `CatCommSqOver` as a functor to the categorical pullback. -/ @[simps!] def CatCommSqOver.toFunctorToCategoricalPullback : (CatCommSqOver F G X) ⥤ X ⥤ F ⊡ G where obj S := { obj x := { fst := S.fst.obj x snd := S.snd.obj x iso := S.iso.app x } map {x y} f := { fst := S.fst.map f snd := S.snd.map f } } map {S S'} φ := { app x := { fst := φ.fst.app x snd := φ.snd.app x } } /-- The universal property of categorical pullbacks, stated as an equivalence of categories between functors `X ⥤ (F ⊡ G)` and categorical commutative squares over X. -/ @[simps] def functorEquiv : (X ⥤ F ⊡ G) ≌ CatCommSqOver F G X where functor := toCatCommSqOver F G X inverse := CatCommSqOver.toFunctorToCategoricalPullback F G X unitIso := NatIso.ofComponents (fun _ ↦ NatIso.ofComponents (fun _ ↦ CategoricalPullback.mkIso (.refl _) (.refl _))) counitIso := NatIso.ofComponents (fun _ ↦ CategoricalPullback.mkIso (NatIso.ofComponents (fun _ ↦ .refl _)) (NatIso.ofComponents (fun _ ↦ .refl _))) variable {F G X} /-- A constructor for natural isomorphisms of functors `X ⥤ CategoricalPullback`: to construct such an isomorphism, it suffices to produce isomorphisms after whiskering with the projections, and compatible with the canonical 2-commutative square . -/ @[simps!] def mkNatIso {J K : X ⥤ F ⊡ G} (e₁ : J ⋙ π₁ F G ≅ K ⋙ π₁ F G) (e₂ : J ⋙ π₂ F G ≅ K ⋙ π₂ F G) (coh : whiskerRight e₁.hom F ≫ (associator _ _ _).hom ≫ whiskerLeft K (CatCommSq.iso (π₁ F G) (π₂ F G) F G).hom ≫ (associator _ _ _).inv = (associator _ _ _).hom ≫ whiskerLeft J (CatCommSq.iso (π₁ F G) (π₂ F G) F G).hom ≫ (associator _ _ _).inv ≫ whiskerRight e₂.hom G := by cat_disch) : J ≅ K := NatIso.ofComponents (fun x ↦ CategoricalPullback.mkIso (e₁.app x) (e₂.app x) (by simpa using NatTrans.congr_app coh x)) (fun {_ _} f ↦ by ext · exact e₁.hom.naturality f · exact e₂.hom.naturality f) /-- To check equality of two natural transformations of functors to a `CategoricalPullback`, it suffices to do so after whiskering with the projections. -/ @[ext] lemma natTrans_ext {J K : X ⥤ F ⊡ G} {α β : J ⟶ K} (e₁ : whiskerRight α (π₁ F G) = whiskerRight β (π₁ F G)) (e₂ : whiskerRight α (π₂ F G) = whiskerRight β (π₂ F G)) : α = β := by ext x · exact congrArg (fun t ↦ t.app x) e₁ · exact congrArg (fun t ↦ t.app x) e₂ section variable {J K : X ⥤ F ⊡ G} (e₁ : J ⋙ π₁ F G ≅ K ⋙ π₁ F G) (e₂ : J ⋙ π₂ F G ≅ K ⋙ π₂ F G) (coh : whiskerRight e₁.hom F ≫ (associator _ _ _).hom ≫ whiskerLeft K (CatCommSq.iso (π₁ F G) (π₂ F G) F G).hom ≫ (associator _ _ _).inv = (associator _ _ _).hom ≫ whiskerLeft J (CatCommSq.iso (π₁ F G) (π₂ F G) F G).hom ≫ (associator _ _ _).inv ≫ whiskerRight e₂.hom G := by cat_disch) @[simp] lemma toCatCommSqOver_mapIso_mkNatIso_eq_mkIso : (toCatCommSqOver F G X).mapIso (mkNatIso e₁ e₂ coh) = CategoricalPullback.mkIso e₁ e₂ (by simpa [functorEquiv, toCatCommSqOver] using coh) := by cat_disch /-- Comparing mkNatIso with the corresponding construction one can deduce from `functorEquiv`. -/ lemma mkNatIso_eq : mkNatIso e₁ e₂ coh = (functorEquiv F G X).fullyFaithfulFunctor.preimageIso (CategoricalPullback.mkIso e₁ e₂ (by simpa [functorEquiv, toCatCommSqOver] using coh)) := by rw [← toCatCommSqOver_mapIso_mkNatIso_eq_mkIso e₁ e₂ coh] dsimp [Equivalence.fullyFaithfulFunctor] cat_disch end end functorEquiv end section Bifunctoriality namespace CatCommSqOver open Functor section transform variable {A₁ : Type u₄} {B₁ : Type u₅} {C₁ : Type u₆} [Category.{v₄} A₁] [Category.{v₅} B₁] [Category.{v₆} C₁] {F₁ : A₁ ⥤ B₁} {G₁ : C₁ ⥤ B₁} /-- Functorially transform a `CatCommSqOver F G X` by whiskering it with a `CatCospanTransform`. -/ @[simps] def transform (X : Type u₇) [Category.{v₇} X] : CatCospanTransform F G F₁ G₁ ⥤ CatCommSqOver F G X ⥤ CatCommSqOver F₁ G₁ X where obj ψ := { obj S := { fst := S.fst ⋙ ψ.left snd := S.snd ⋙ ψ.right iso := (Functor.associator _ _ _) ≪≫ isoWhiskerLeft S.fst (ψ.squareLeft.iso.symm) ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight S.iso _ ≪≫ isoWhiskerLeft S.snd (ψ.squareRight.iso) ≪≫ (Functor.associator _ _ _).symm } map {x y} f := { fst := whiskerRight f.fst ψ.left snd := whiskerRight f.snd ψ.right w := by ext x simp [← Functor.map_comp_assoc] } } map {ψ ψ'} η := { app S := { fst := { app y := η.left.app (S.fst.obj y) } snd := { app y := η.right.app (S.snd.obj y) } w := by ext t have := ψ.squareLeft.iso.inv.app (S.fst.obj t) ≫= η.left_coherence_app (S.fst.obj t) simp only [Iso.inv_hom_id_app_assoc] at this simp [this] } } variable {A₂ : Type u₇} {B₂ : Type u₈} {C₂ : Type u₉} [Category.{v₇} A₂] [Category.{v₈} B₂] [Category.{v₉} C₂] {F₂ : A₂ ⥤ B₂} {G₂ : C₂ ⥤ B₂} /-- The construction `CatCommSqOver.transform` respects vertical composition of `CatCospanTransform`s. -/ @[simps!] def transformObjComp (X : Type u₁₀) [Category.{v₁₀} X] (ψ : CatCospanTransform F G F₁ G₁) (ψ' : CatCospanTransform F₁ G₁ F₂ G₂) : (transform X).obj (ψ.comp ψ') ≅ (transform X).obj ψ ⋙ (transform X).obj ψ' := NatIso.ofComponents fun _ => CategoricalPullback.mkIso (Functor.associator _ _ _).symm (Functor.associator _ _ _).symm /-- The construction `CatCommSqOver.transform` respects the identity `CatCospanTransform`s. -/ @[simps!] def transformObjId (X : Type u₄) [Category.{v₄} X] (F : A ⥤ B) (G : C ⥤ B) : (transform X).obj (CatCospanTransform.id F G) ≅ 𝟭 _ := NatIso.ofComponents fun _ => CategoricalPullback.mkIso (Functor.rightUnitor _) (Functor.rightUnitor _) open scoped CatCospanTransform lemma transform_map_whiskerLeft (X : Type u₇) [Category.{v₇} X] (ψ : CatCospanTransform F G F₁ G₁) {φ φ' : CatCospanTransform F₁ G₁ F₂ G₂} (α : φ ⟶ φ') : (transform X).map (ψ ◁ α) = (transformObjComp X ψ φ).hom ≫ whiskerLeft (transform X |>.obj ψ) (transform X |>.map α) ≫ (transformObjComp X ψ φ').inv := by cat_disch lemma transform_map_whiskerRight (X : Type u₇) [Category.{v₇} X] {ψ ψ' : CatCospanTransform F G F₁ G₁} (α : ψ ⟶ ψ') (φ : CatCospanTransform F₁ G₁ F₂ G₂) : (transform X).map (α ▷ φ) = (transformObjComp X ψ φ).hom ≫ whiskerRight (transform X |>.map α) (transform X |>.obj φ) ≫ (transformObjComp X ψ' φ).inv := by cat_disch lemma transform_map_associator {A₃ : Type u₁₀} {B₃ : Type u₁₁} {C₃ : Type u₁₂} [Category.{v₁₀} A₃] [Category.{v₁₁} B₃] [Category.{v₁₂} C₃] {F₃ : A₃ ⥤ B₃} {G₃ : C₃ ⥤ B₃} (X : Type u₁₃) [Category.{v₁₃} X] (ψ : CatCospanTransform F G F₁ G₁) (φ : CatCospanTransform F₁ G₁ F₂ G₂) (τ : CatCospanTransform F₂ G₂ F₃ G₃) : (transform X).map (α_ ψ φ τ).hom = (transformObjComp X (ψ.comp φ) τ).hom ≫ whiskerRight (transformObjComp X ψ φ).hom (transform X |>.obj τ) ≫ ((transform X |>.obj ψ).associator (transform X |>.obj φ) (transform X |>.obj τ)).hom ≫ whiskerLeft (transform X |>.obj ψ) (transformObjComp X φ τ).inv ≫ (transformObjComp X ψ (φ.comp τ)).inv := by cat_disch lemma transform_map_leftUnitor (X : Type u₇) [Category.{v₇} X] (ψ : CatCospanTransform F G F₁ G₁) : (transform X).map (λ_ ψ).hom = (transformObjComp X (.id F G) ψ).hom ≫ whiskerRight (transformObjId X F G).hom (transform X |>.obj ψ) ≫ (transform X |>.obj ψ).leftUnitor.hom := by cat_disch lemma transform_map_rightUnitor (X : Type u₇) [Category.{v₇} X] (ψ : CatCospanTransform F G F₁ G₁) : (transform X).map (ρ_ ψ).hom = (transformObjComp X ψ (.id F₁ G₁)).hom ≫ whiskerLeft (transform X |>.obj ψ) (transformObjId X F₁ G₁).hom ≫ (transform X |>.obj ψ).rightUnitor.hom := by cat_disch end transform section precompose variable (F G) variable {X : Type u₄} {Y : Type u₅} {Z : Type u₆} [Category.{v₄} X] [Category.{v₅} Y] [Category.{v₆} Z] /-- A functor `U : X ⥤ Y` (functorially) induces a functor `CatCommSqOver F G Y ⥤ CatCommSqOver F G X` by whiskering left the underlying categorical commutative square by U. -/ @[simps] def precompose : (X ⥤ Y) ⥤ CatCommSqOver F G Y ⥤ CatCommSqOver F G X where obj U := { obj S := { fst := U ⋙ S.fst snd := U ⋙ S.snd iso := (Functor.associator _ _ _) ≪≫ isoWhiskerLeft U S.iso ≪≫ (Functor.associator _ _ _).symm } map {S S'} φ := { fst := whiskerLeft U φ.fst snd := whiskerLeft U φ.snd } } map {U V} α := { app x := { fst := whiskerRight α x.fst snd := whiskerRight α x.snd } } variable (X) in /-- The construction `precompose` respects functor identities. -/ @[simps!] def precomposeObjId : (precompose F G).obj (𝟭 X) ≅ 𝟭 (CatCommSqOver F G X) := NatIso.ofComponents fun _ => CategoricalPullback.mkIso (Functor.leftUnitor _) (Functor.leftUnitor _) /-- The construction `precompose` respects functor composition. -/ @[simps!] def precomposeObjComp (U : X ⥤ Y) (V : Y ⥤ Z) : (precompose F G).obj (U ⋙ V) ≅ (precompose F G).obj V ⋙ (precompose F G).obj U := NatIso.ofComponents fun _ => CategoricalPullback.mkIso (Functor.associator _ _ _) (Functor.associator _ _ _) lemma precompose_map_whiskerLeft (U : X ⥤ Y) {V W : Y ⥤ Z} (α : V ⟶ W) : (precompose F G).map (whiskerLeft U α) = (precomposeObjComp F G U V).hom ≫ whiskerRight (precompose F G |>.map α) (precompose F G |>.obj U) ≫ (precomposeObjComp F G U W).inv := by cat_disch lemma precompose_map_whiskerRight {U V : X ⥤ Y} (α : U ⟶ V) (W : Y ⥤ Z) : (precompose F G).map (whiskerRight α W) = (precomposeObjComp F G U W).hom ≫ whiskerLeft (precompose F G |>.obj W) (precompose F G |>.map α) ≫ (precomposeObjComp F G V W).inv := by cat_disch lemma precompose_map_associator {T : Type u₇} [Category.{v₇} T] (U : X ⥤ Y) (V : Y ⥤ Z) (W : Z ⥤ T) : (precompose F G).map (U.associator V W).hom = (precomposeObjComp F G (U ⋙ V) W).hom ≫ whiskerLeft (precompose F G |>.obj W) (precomposeObjComp F G U V).hom ≫ ((precompose F G |>.obj W).associator _ _).inv ≫ whiskerRight (precomposeObjComp F G V W).inv (precompose F G |>.obj U) ≫ (precomposeObjComp F G _ _).inv := by cat_disch lemma precompose_map_leftUnitor (U : X ⥤ Y) : (precompose F G).map U.leftUnitor.hom = (precomposeObjComp F G (𝟭 _) U).hom ≫ whiskerLeft (precompose F G |>.obj U) (precomposeObjId F G X).hom ≫ (Functor.rightUnitor _).hom := by cat_disch lemma precompose_map_rightUnitor (U : X ⥤ Y) : (precompose F G).map U.rightUnitor.hom = (precomposeObjComp F G U (𝟭 _)).hom ≫ whiskerRight (precomposeObjId F G Y).hom (precompose F G |>.obj U) ≫ (Functor.leftUnitor _).hom := by cat_disch end precompose section compatibility variable {A₁ : Type u₄} {B₁ : Type u₅} {C₁ : Type u₆} [Category.{v₄} A₁] [Category.{v₅} B₁] [Category.{v₆} C₁] {F₁ : A₁ ⥤ B₁} {G₁ : C₁ ⥤ B₁} /-- The canonical compatibility square between (the object components of) `precompose` and `transform`. This is a "naturality square" if we think as `transform _|>.obj _` as the (app component of the) map component of a pseudofunctor from the bicategory of categorical cospans with value in pseudofunctors (its value on the categorical cospan `F, G` being the pseudofunctor `precompose F G|>.obj _`). -/ @[simps!] instance precomposeObjTransformObjSquare {X : Type u₇} {Y : Type u₈} [Category.{v₇} X] [Category.{v₈} Y] (ψ : CatCospanTransform F G F₁ G₁) (U : X ⥤ Y) : CatCommSq (precompose F G |>.obj U) (transform Y |>.obj ψ) (transform X |>.obj ψ) (precompose F₁ G₁ |>.obj U) where iso := NatIso.ofComponents fun _ => CategoricalPullback.mkIso (Functor.associator _ _ _) (Functor.associator _ _ _) -- Compare the next 3 lemmas with the components of a strong natural transform -- of pseudofunctors /-- The square `precomposeObjTransformObjSquare` is itself natural. -/ lemma precomposeObjTransformObjSquare_iso_hom_naturality₂ {X : Type u₇} {Y : Type u₈} [Category.{v₇} X] [Category.{v₈} Y] (ψ : CatCospanTransform F G F₁ G₁) {U V : X ⥤ Y} (α : U ⟶ V) : whiskerRight (precompose F G |>.map α) (transform X |>.obj ψ) ≫ (CatCommSq.iso _ (transform Y |>.obj ψ) _ (precompose F₁ G₁ |>.obj V)).hom = (CatCommSq.iso _ (transform Y |>.obj ψ) _ (precompose F₁ G₁ |>.obj U)).hom ≫ whiskerLeft (transform Y |>.obj ψ) (precompose F₁ G₁ |>.map α) := by cat_disch /-- The square `precomposeObjTransformOBjSquare` respects identities. -/ lemma precomposeObjTransformObjSquare_iso_hom_id (ψ : CatCospanTransform F G F₁ G₁) (X : Type u₇) [Category.{v₇} X] : (CatCommSq.iso (precompose F G |>.obj <| 𝟭 X) (transform X |>.obj ψ) (transform X |>.obj ψ) (precompose F₁ G₁ |>.obj <| 𝟭 X)).hom ≫ whiskerLeft (transform X |>.obj ψ) (precomposeObjId F₁ G₁ X).hom = whiskerRight (precomposeObjId F G X).hom (transform X |>.obj ψ) ≫ (Functor.leftUnitor _).hom ≫ (Functor.rightUnitor _).inv := by cat_disch /-- The square `precomposeTransformSquare` respects compositions. -/ lemma precomposeObjTransformObjSquare_iso_hom_comp {X : Type u₇} {Y : Type u₈} {Z : Type u₉} [Category.{v₇} X] [Category.{v₈} Y] [Category.{v₉} Z] (ψ : CatCospanTransform F G F₁ G₁) (U : X ⥤ Y) (V : Y ⥤ Z) : (CatCommSq.iso (precompose F G |>.obj <| U ⋙ V) (transform Z |>.obj ψ) (transform X |>.obj ψ) (precompose F₁ G₁ |>.obj <| U ⋙ V)).hom ≫ whiskerLeft (transform Z |>.obj ψ) (precomposeObjComp F₁ G₁ U V).hom = whiskerRight (precomposeObjComp F G U V).hom (transform X |>.obj ψ) ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft (precompose F G |>.obj V) (CatCommSq.iso _ (transform _ |>.obj ψ) _ _).hom ≫ (Functor.associator _ _ _).inv ≫ whiskerRight (CatCommSq.iso _ _ _ _).hom (precompose F₁ G₁ |>.obj U) ≫ (Functor.associator _ _ _).hom := by cat_disch /-- The canonical compatibility square between (the object components of) `transform` and `precompose`. This is a "naturality square" if we think as `precompose` as the (app component of the) map component of a pseudofunctor from the opposite bicategory of categories to pseudofunctors of categorical cospans (its value on `X` being the pseudofunctor `transform X _`). -/ @[simps!] instance transformObjPrecomposeObjSquare {X : Type u₇} {Y : Type u₈} [Category.{v₇} X] [Category.{v₈} Y] (U : X ⥤ Y) (ψ : CatCospanTransform F G F₁ G₁) : CatCommSq (transform Y |>.obj ψ) (precompose F G |>.obj U) (precompose F₁ G₁ |>.obj U) (transform X |>.obj ψ) where iso := NatIso.ofComponents fun _ => CategoricalPullback.mkIso (Functor.associator _ _ _).symm (Functor.associator _ _ _).symm -- Compare the next 3 lemmas with the components of a strong natural transform -- of pseudofunctors /-- The square `transformObjPrecomposeObjSquare` is itself natural. -/ lemma transformObjPrecomposeObjSquare_iso_hom_naturality₂ {X : Type u₇} {Y : Type u₈} [Category.{v₇} X] [Category.{v₈} Y] (U : X ⥤ Y) {ψ ψ' : CatCospanTransform F G F₁ G₁} (η : ψ ⟶ ψ') : whiskerRight (transform Y |>.map η) (precompose F₁ G₁ |>.obj U) ≫ (CatCommSq.iso _ (precompose F G |>.obj U) _ (transform X |>.obj ψ')).hom = (CatCommSq.iso _ (precompose F G |>.obj U) _ (transform X |>.obj ψ)).hom ≫ whiskerLeft (precompose F G |>.obj U) (transform X |>.map η) := by cat_disch /-- The square `transformObjPrecomposeObjSquare` respects identities. -/ lemma transformObjPrecomposeObjSquare_iso_hom_id {X : Type u₇} {Y : Type u₈} [Category.{v₇} X] [Category.{v₈} Y] (U : X ⥤ Y) (F : A ⥤ B) (G : C ⥤ B) : (CatCommSq.iso (transform Y |>.obj <| .id F G) (precompose F G |>.obj U) (precompose F G |>.obj U) (transform X |>.obj <| .id F G)).hom ≫ whiskerLeft (precompose F G |>.obj U) (transformObjId X F G).hom = whiskerRight (transformObjId Y F G).hom (precompose F G |>.obj U) ≫ (precompose F G |>.obj U).leftUnitor.hom ≫ (precompose F G |>.obj U).rightUnitor.inv := by cat_disch /-- The square `transformPrecomposeSquare` respects compositions. -/ lemma transformPrecomposeObjSquare_iso_hom_comp {A₂ : Type u₇} {B₂ : Type u₈} {C₂ : Type u₉} [Category.{v₇} A₂] [Category.{v₈} B₂] [Category.{v₉} C₂] {F₂ : A₂ ⥤ B₂} {G₂ : C₂ ⥤ B₂} {X : Type u₁₀} {Y : Type u₁₁} [Category.{v₁₀} X] [Category.{v₁₁} Y] (U : X ⥤ Y) (ψ : CatCospanTransform F G F₁ G₁) (ψ' : CatCospanTransform F₁ G₁ F₂ G₂) : (CatCommSq.iso (transform Y |>.obj <| ψ.comp ψ') (precompose F G |>.obj U) (precompose F₂ G₂ |>.obj U) (transform X |>.obj <| ψ.comp ψ')).hom ≫ whiskerLeft (precompose F G |>.obj U) (transformObjComp X ψ ψ').hom = whiskerRight (transformObjComp Y ψ ψ').hom (precompose F₂ G₂ |>.obj U) ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft (transform Y |>.obj ψ) (CatCommSq.iso _ (precompose F₁ G₁ |>.obj U) _ (transform X |>.obj ψ')).hom ≫ (Functor.associator _ _ _).inv ≫ whiskerRight (CatCommSq.iso _ _ _ _).hom (transform X |>.obj ψ') ≫ (Functor.associator _ _ _).hom := by cat_disch end compatibility end CatCommSqOver end Bifunctoriality end CategoricalPullback end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Shapes/Pullback/Categorical/CatCospanTransform.lean
import Mathlib.CategoryTheory.CatCommSq /-! # Morphisms of categorical cospans. Given `F : A ⥤ B`, `G : C ⥤ B`, `F' : A' ⥤ B'` and `G' : C' ⥤ B'`, this file defines `CatCospanTransform F G F' G'`, the category of "categorical transformations" from the (categorical) cospan `F G` to the (categorical) cospan `F' G'`. Such a transformation consists of a diagram ``` F G A ⥤ B ⥢ C H₁| |H₂ |H₃ v v v A'⥤ B'⥢ C' F' G' ``` with specified `CatCommSq`s expressing 2-commutativity of the squares. These transformations are used to encode 2-functoriality of categorical pullback squares. -/ namespace CategoryTheory.Limits universe v₁ v₂ v₃ v₄ v₅ v₆ v₇ v₈ v₉ v₁₀ v₁₁ v₁₂ v₁₃ v₁₄ v₁₅ universe u₁ u₂ u₃ u₄ u₅ u₆ u₇ u₈ u₉ u₁₀ u₁₁ u₁₂ u₁₃ u₁₄ u₁₅ /-- A `CatCospanTransform F G F' G'` is a diagram ``` F G A ⥤ B ⥢ C H₁| |H₂ |H₃ v v v A'⥤ B'⥢ C' F' G' ``` with specified `CatCommSq`s expressing 2-commutativity of the squares. -/ structure CatCospanTransform {A : Type u₁} {B : Type u₂} {C : Type u₃} [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C] (F : A ⥤ B) (G : C ⥤ B) {A' : Type u₄} {B' : Type u₅} {C' : Type u₆} [Category.{v₄} A'] [Category.{v₅} B'] [Category.{v₆} C'] (F' : A' ⥤ B') (G' : C' ⥤ B') where /-- the functor on the left component -/ left : A ⥤ A' /-- the functor on the base component -/ base : B ⥤ B' /-- the functor on the right component -/ right : C ⥤ C' /-- a `CatCommSq` bundling the natural isomorphism `F ⋙ base ≅ left ⋙ F'`. -/ squareLeft : CatCommSq F left base F' := by infer_instance /-- a `CatCommSq` bundling the natural isomorphism `G ⋙ base ≅ right ⋙ G'`. -/ squareRight : CatCommSq G right base G' := by infer_instance namespace CatCospanTransform section variable {A : Type u₁} {B : Type u₂} {C : Type u₃} [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C] (F : A ⥤ B) (G : C ⥤ B) attribute [local instance] CatCommSq.vId in /-- The identity `CatCospanTransform` -/ @[simps] def id : CatCospanTransform F G F G where left := 𝟭 A base := 𝟭 B right := 𝟭 C variable {F G} /-- Composition of `CatCospanTransforms` is defined "componentwise". -/ @[simps] def comp {A' : Type u₄} {B' : Type u₅} {C' : Type u₆} [Category.{v₄} A'] [Category.{v₅} B'] [Category.{v₆} C'] {F' : A' ⥤ B'} {G' : C' ⥤ B'} {A'' : Type u₇} {B'' : Type u₈} {C'' : Type u₉} [Category.{v₇} A''] [Category.{v₈} B''] [Category.{v₉} C''] {F'' : A'' ⥤ B''} {G'' : C'' ⥤ B''} (ψ : CatCospanTransform F G F' G') (ψ' : CatCospanTransform F' G' F'' G'') : CatCospanTransform F G F'' G'' where left := ψ.left ⋙ ψ'.left base := ψ.base ⋙ ψ'.base right := ψ.right ⋙ ψ'.right squareLeft := ψ.squareLeft.vComp' ψ'.squareLeft squareRight := ψ.squareRight.vComp' ψ'.squareRight end end CatCospanTransform variable {A : Type u₁} {B : Type u₂} {C : Type u₃} {A' : Type u₄} {B' : Type u₅} {C' : Type u₆} {A'' : Type u₇} {B'' : Type u₈} {C'' : Type u₉} [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C] {F : A ⥤ B} {G : C ⥤ B} [Category.{v₄} A'] [Category.{v₅} B'] [Category.{v₆} C'] {F' : A' ⥤ B'} {G' : C' ⥤ B'} [Category.{v₇} A''] [Category.{v₈} B''] [Category.{v₉} C''] {F'' : A'' ⥤ B''} {G'' : C'' ⥤ B''} /-- A morphism of `CatCospanTransform F G F' G'` is a triple of natural transformations between the component functors, subjects to coherence conditions respective to the squares. -/ structure CatCospanTransformMorphism (ψ ψ' : CatCospanTransform F G F' G') where /-- the natural transformations between the left components -/ left : ψ.left ⟶ ψ'.left /-- the natural transformations between the right components -/ right : ψ.right ⟶ ψ'.right /-- the natural transformations between the base components -/ base : ψ.base ⟶ ψ'.base /-- the coherence condition for the left square -/ left_coherence : ψ.squareLeft.iso.hom ≫ Functor.whiskerRight left F' = Functor.whiskerLeft F base ≫ ψ'.squareLeft.iso.hom := by cat_disch /-- the coherence condition for the right square -/ right_coherence : ψ.squareRight.iso.hom ≫ Functor.whiskerRight right G' = Functor.whiskerLeft G base ≫ ψ'.squareRight.iso.hom := by cat_disch namespace CatCospanTransform attribute [reassoc (attr := simp)] CatCospanTransformMorphism.left_coherence CatCospanTransformMorphism.right_coherence @[simps] instance category : Category (CatCospanTransform F G F' G') where Hom ψ ψ' := CatCospanTransformMorphism ψ ψ' id ψ := { left := 𝟙 _ right := 𝟙 _ base := 𝟙 _ } comp α β := { left := α.left ≫ β.left right := α.right ≫ β.right base := α.base ≫ β.base} attribute [local ext] CatCospanTransformMorphism in @[ext] lemma hom_ext {ψ ψ' : CatCospanTransform F G F' G'} {θ θ' : ψ ⟶ ψ'} (hl : θ.left = θ'.left) (hr : θ.right = θ'.right) (hb : θ.base = θ'.base) : θ = θ' := by apply CatCospanTransformMorphism.ext <;> assumption end CatCospanTransform namespace CatCospanTransformMorphism @[reassoc (attr := simp)] lemma left_coherence_app {ψ ψ' : CatCospanTransform F G F' G'} (α : ψ ⟶ ψ') (x : A) : ψ.squareLeft.iso.hom.app x ≫ F'.map (α.left.app x) = α.base.app (F.obj x) ≫ ψ'.squareLeft.iso.hom.app x := congr_app α.left_coherence x @[reassoc (attr := simp)] lemma right_coherence_app {ψ ψ' : CatCospanTransform F G F' G'} (α : ψ ⟶ ψ') (x : C) : ψ.squareRight.iso.hom.app x ≫ G'.map (α.right.app x) = α.base.app (G.obj x) ≫ ψ'.squareRight.iso.hom.app x := congr_app α.right_coherence x /-- Whiskering left of a `CatCospanTransformMorphism` by a `CatCospanTransform`. -/ @[simps] def whiskerLeft (φ : CatCospanTransform F G F' G') {ψ ψ' : CatCospanTransform F' G' F'' G''} (α : ψ ⟶ ψ') : (φ.comp ψ) ⟶ (φ.comp ψ') where left := Functor.whiskerLeft φ.left α.left right := Functor.whiskerLeft φ.right α.right base := Functor.whiskerLeft φ.base α.base /-- Whiskering right of a `CatCospanTransformMorphism` by a `CatCospanTransform`. -/ @[simps] def whiskerRight {ψ ψ' : CatCospanTransform F G F' G'} (α : ψ ⟶ ψ') (φ : CatCospanTransform F' G' F'' G'') : (ψ.comp φ) ⟶ (ψ'.comp φ) where left := Functor.whiskerRight α.left φ.left right := Functor.whiskerRight α.right φ.right base := Functor.whiskerRight α.base φ.base left_coherence := by ext x dsimp simp only [CatCommSq.vComp_iso_hom_app, Category.assoc] rw [← Functor.map_comp_assoc, ← left_coherence_app, Functor.map_comp_assoc] simp right_coherence := by ext x dsimp simp only [CatCommSq.vComp_iso_hom_app, Category.assoc] rw [← Functor.map_comp_assoc, ← right_coherence_app, Functor.map_comp_assoc] simp end CatCospanTransformMorphism namespace CatCospanTransform /-- A constructor for isomorphisms of `CatCospanTransform`'s. -/ @[simps] def mkIso {ψ ψ' : CatCospanTransform F G F' G'} (left : ψ.left ≅ ψ'.left) (right : ψ.right ≅ ψ'.right) (base : ψ.base ≅ ψ'.base) (left_coherence : ψ.squareLeft.iso.hom ≫ Functor.whiskerRight left.hom F' = Functor.whiskerLeft F base.hom ≫ ψ'.squareLeft.iso.hom := by cat_disch) (right_coherence : ψ.squareRight.iso.hom ≫ Functor.whiskerRight right.hom G' = Functor.whiskerLeft G base.hom ≫ ψ'.squareRight.iso.hom := by cat_disch) : ψ ≅ ψ' where hom := { left := left.hom right := right.hom base := base.hom } inv := { left := left.inv right := right.inv base := base.inv left_coherence := by simpa using ψ'.squareLeft.iso.hom ≫= IsIso.inv_eq_inv.mpr left_coherence =≫ ψ.squareLeft.iso.hom right_coherence := by simpa using ψ'.squareRight.iso.hom ≫= IsIso.inv_eq_inv.mpr right_coherence =≫ ψ.squareRight.iso.hom } section Iso variable {ψ ψ' : CatCospanTransform F G F' G'} (f : ψ' ⟶ ψ') [IsIso f] (e : ψ ≅ ψ') instance isIso_left : IsIso f.left := ⟨(inv f).left, by simp [← CatCospanTransform.category_comp_left]⟩ instance isIso_right : IsIso f.right := ⟨(inv f).right, by simp [← CatCospanTransform.category_comp_right]⟩ instance isIso_base : IsIso f.base := ⟨(inv f).base, by simp [← CatCospanTransform.category_comp_base]⟩ @[simp] lemma inv_left : inv f.left = (inv f).left := by symm apply IsIso.eq_inv_of_inv_hom_id simp [← CatCospanTransform.category_comp_left] @[simp] lemma inv_right : inv f.right = (inv f).right := by symm apply IsIso.eq_inv_of_inv_hom_id simp [← CatCospanTransform.category_comp_right] @[simp] lemma inv_base : inv f.base = (inv f).base := by symm apply IsIso.eq_inv_of_inv_hom_id simp [← CatCospanTransform.category_comp_base] /-- Extract an isomorphism between left components from an isomorphism in `CatCospanTransform F G F' G'`. -/ @[simps] def leftIso : ψ.left ≅ ψ'.left where hom := e.hom.left inv := e.inv.left hom_inv_id := by simp [← category_comp_left] inv_hom_id := by simp [← category_comp_left] /-- Extract an isomorphism between right components from an isomorphism in `CatCospanTransform F G F' G'`. -/ @[simps] def rightIso : ψ.right ≅ ψ'.right where hom := e.hom.right inv := e.inv.right hom_inv_id := by simp [← category_comp_right] inv_hom_id := by simp [← category_comp_right] /-- Extract an isomorphism between base components from an isomorphism in `CatCospanTransform F G F' G'`. -/ @[simps] def baseIso : ψ.base ≅ ψ'.base where hom := e.hom.base inv := e.inv.base hom_inv_id := by simp [← category_comp_base] inv_hom_id := by simp [← category_comp_base] omit [IsIso f] in lemma isIso_iff : IsIso f ↔ IsIso f.left ∧ IsIso f.base ∧ IsIso f.right where mp h := ⟨inferInstance, inferInstance, inferInstance⟩ mpr h := by obtain ⟨_, _, _⟩ := h use mkIso (asIso f.left) (asIso f.right) (asIso f.base) f.left_coherence f.right_coherence|>.inv aesop_cat end Iso /-- The left unitor isomorphism for categorical cospan transformations. -/ @[simps!] def leftUnitor (φ : CatCospanTransform F G F' G') : (CatCospanTransform.id F G).comp φ ≅ φ := mkIso φ.left.leftUnitor φ.right.leftUnitor φ.base.leftUnitor /-- The right unitor isomorphism for categorical cospan transformations. -/ @[simps!] def rightUnitor (φ : CatCospanTransform F G F' G') : φ.comp (.id F' G') ≅ φ := mkIso φ.left.rightUnitor φ.right.rightUnitor φ.base.rightUnitor /-- The associator isomorphism for categorical cospan transformations. -/ @[simps!] def associator {A''' : Type u₁₀} {B''' : Type u₁₁} {C''' : Type u₁₂} [Category.{v₁₀} A'''] [Category.{v₁₁} B'''] [Category.{v₁₂} C'''] {F''' : A''' ⥤ B'''} {G''' : C''' ⥤ B'''} (φ : CatCospanTransform F G F' G') (φ' : CatCospanTransform F' G' F'' G'') (φ'' : CatCospanTransform F'' G'' F''' G''') : (φ.comp φ').comp φ'' ≅ φ.comp (φ'.comp φ'') := mkIso (φ.left.associator φ'.left φ''.left) (φ.right.associator φ'.right φ''.right) (φ.base.associator φ'.base φ''.base) section lemmas -- We scope the notations with notations from bicategories to make life easier. -- Due to performance issues, these notations should not be in scope at the same time -- as the ones in bicategories. @[inherit_doc] scoped infixr:81 " ◁ " => CatCospanTransformMorphism.whiskerLeft @[inherit_doc] scoped infixl:81 " ▷ " => CatCospanTransformMorphism.whiskerRight @[inherit_doc] scoped notation "α_" => CatCospanTransform.associator @[inherit_doc] scoped notation "λ_" => CatCospanTransform.leftUnitor @[inherit_doc] scoped notation "ρ_" => CatCospanTransform.rightUnitor variable {A''' : Type u₁₀} {B''' : Type u₁₁} {C''' : Type u₁₂} [Category.{v₁₀} A'''] [Category.{v₁₁} B'''] [Category.{v₁₂} C'''] {F''' : A''' ⥤ B'''} {G''' : C''' ⥤ B'''} {ψ ψ' ψ'' : CatCospanTransform F G F' G'} (η : ψ ⟶ ψ') (η' : ψ' ⟶ ψ'') {φ φ' φ'' : CatCospanTransform F' G' F'' G''} (θ : φ ⟶ φ') (θ' : φ' ⟶ φ'') {τ τ' : CatCospanTransform F'' G'' F''' G'''} (γ : τ ⟶ τ') @[reassoc] lemma whisker_exchange : ψ ◁ θ ≫ η ▷ φ' = η ▷ φ ≫ ψ' ◁ θ := by cat_disch @[simp] lemma id_whiskerRight : 𝟙 ψ ▷ φ = 𝟙 _ := by cat_disch @[reassoc] lemma whiskerRight_id : η ▷ (.id _ _) = (ρ_ _).hom ≫ η ≫ (ρ_ _).inv := by cat_disch @[simp, reassoc] lemma comp_whiskerRight : (η ≫ η') ▷ φ = η ▷ φ ≫ η' ▷ φ := by cat_disch @[reassoc] lemma whiskerRight_comp : η ▷ (φ.comp τ) = (α_ _ _ _).inv ≫ (η ▷ φ) ▷ τ ≫ (α_ _ _ _ ).hom := by cat_disch @[simp] lemma whiskerleft_id : ψ ◁ 𝟙 φ = 𝟙 _ := by cat_disch @[reassoc] lemma id_whiskerLeft : (.id _ _) ◁ η = (λ_ _).hom ≫ η ≫ (λ_ _).inv := by cat_disch @[simp, reassoc] lemma whiskerLeft_comp : ψ ◁ (θ ≫ θ') = (ψ ◁ θ) ≫ (ψ ◁ θ') := by cat_disch @[reassoc] lemma comp_whiskerLeft : (ψ.comp φ) ◁ γ = (α_ _ _ _).hom ≫ (ψ ◁ (φ ◁ γ)) ≫ (α_ _ _ _).inv := by cat_disch @[reassoc] lemma pentagon {A'''' : Type u₁₃} {B'''' : Type u₁₄} {C'''' : Type u₁₅} [Category.{v₁₃} A''''] [Category.{v₁₄} B''''] [Category.{v₁₅} C''''] {F'''' : A'''' ⥤ B''''} {G'''' : C'''' ⥤ B''''} {σ : CatCospanTransform F''' G''' F'''' G''''} : (α_ ψ φ τ).hom ▷ σ ≫ (α_ ψ (φ.comp τ) σ).hom ≫ ψ ◁ (α_ φ τ σ).hom = (α_ (ψ.comp φ) τ σ).hom ≫ (α_ ψ φ (τ.comp σ)).hom := by cat_disch @[reassoc] lemma triangle : (α_ ψ (.id _ _) φ).hom ≫ ψ ◁ (λ_ φ).hom = (ρ_ ψ).hom ▷ φ := by cat_disch @[reassoc] lemma triangle_inv : (α_ ψ (.id _ _) φ).inv ≫ (ρ_ ψ).hom ▷ φ = ψ ◁ (λ_ φ).hom := by cat_disch section Isos variable {ψ ψ' : CatCospanTransform F G F' G'} (η : ψ ⟶ ψ') [IsIso η] {φ φ' : CatCospanTransform F' G' F'' G''} (θ : φ ⟶ φ') [IsIso θ] instance : IsIso (ψ ◁ θ) := ⟨ψ ◁ inv θ, ⟨by simp [← whiskerLeft_comp], by simp [← whiskerLeft_comp]⟩⟩ lemma inv_whiskerLeft : inv (ψ ◁ θ) = ψ ◁ inv θ := by apply IsIso.inv_eq_of_hom_inv_id simp [← whiskerLeft_comp] instance : IsIso (η ▷ φ) := ⟨inv η ▷ φ, ⟨by simp [← comp_whiskerRight], by simp [← comp_whiskerRight]⟩⟩ lemma inv_whiskerRight : inv (η ▷ φ) = inv η ▷ φ := by apply IsIso.inv_eq_of_hom_inv_id simp [← comp_whiskerRight] end Isos end lemmas end CatCospanTransform end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/ConcreteCategory/WithAlgebraicStructures.lean
import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic import Mathlib.Algebra.Category.ModuleCat.Basic import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Colimits in ModuleCat Let `C` be a concrete category and `F : J ⥤ C` a filtered diagram in `C`. We discuss some results about `colimit F` when objects and morphisms in `C` have some algebraic structures. ## Main results - `CategoryTheory.Limits.Concrete.colimit_rep_eq_zero`: Let `C` be a category where its objects have zero elements and morphisms preserve zero. If `x : Fⱼ` is mapped to `0` in the colimit, then there exists a `i ⟶ j` such that `x` restricted to `i` is already `0`. - `CategoryTheory.Limits.Concrete.colimit_no_zero_smul_divisor`: Let `C` be a category where its objects are `R`-modules and morphisms `R`-linear maps. Let `r : R` be an element without zero smul divisors for all small sections, i.e. there exists some `j : J` such that for all `j ⟶ i` and `x : Fᵢ` we have `r • x = 0` implies `x = 0`, then if `r • x = 0` for `x : colimit F`, then `x = 0`. ## Implementation details For now, we specialize our results to `C = ModuleCat R`, which is the only place they are used. In the future they might be generalized by assuming a `HasForget₂ C (ModuleCat R)` instance, plus assertions that the module structures induced by `HasForget₂` coincide. -/ universe t w v u r open CategoryTheory namespace CategoryTheory.Limits.Concrete variable (R : Type*) [Ring R] {J : Type w} [Category.{r} J] section zero theorem colimit_rep_eq_zero (F : J ⥤ ModuleCat.{max t w} R) [PreservesColimit F (forget (ModuleCat R))] [IsFiltered J] [HasColimit F] (j : J) (x : F.obj j) (hx : colimit.ι F j x = 0) : ∃ (j' : J) (i : j ⟶ j'), (F.map i).hom x = 0 := by rw [show 0 = colimit.ι F j 0 by simp, colimit_rep_eq_iff_exists] at hx obtain ⟨j', i, y, g⟩ := hx exact ⟨j', i, g ▸ by simp⟩ end zero section module /-- if `r` has no zero smul divisors for all small-enough sections, then `r` has no zero smul divisors in the colimit. -/ lemma colimit_no_zero_smul_divisor (F : J ⥤ ModuleCat.{max t w} R) [PreservesColimit F (forget (ModuleCat R))] [IsFiltered J] [HasColimit F] (r : R) (H : ∃ (j' : J), ∀ (j : J) (_ : j' ⟶ j), ∀ (c : F.obj j), r • c = 0 → c = 0) (x : ToType (colimit F)) (hx : r • x = 0) : x = 0 := by classical obtain ⟨j, x, rfl⟩ := Concrete.colimit_exists_rep F x rw [← map_smul (colimit.ι F j).hom] at hx obtain ⟨j', i, h⟩ := Concrete.colimit_rep_eq_zero (hx := hx) obtain ⟨j'', H⟩ := H simpa [elementwise_of% (colimit.w F), map_zero] using congr(colimit.ι F _ $(H (IsFiltered.sup {j, j', j''} { ⟨j, j', by simp, by simp, i⟩ }) (IsFiltered.toSup _ _ <| by simp) (F.map (IsFiltered.toSup _ _ <| by simp) x) (by rw [← IsFiltered.toSup_commutes (f := i) (mY := by simp) (mf := by simp), F.map_comp, ModuleCat.comp_apply, ← map_smul, ← map_smul, h, map_zero]))) end module end CategoryTheory.Limits.Concrete
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/ConcreteCategory/Basic.lean
import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Limits.Types.Images import Mathlib.CategoryTheory.Limits.Types.Filtered import Mathlib.CategoryTheory.Limits.Yoneda /-! # Facts about (co)limits of functors into concrete categories -/ universe s t w v u r open CategoryTheory namespace CategoryTheory.Types open Limits /-! The forgetful functor on `Type u` is the identity; copy the instances on `𝟭 (Type u)` over to `forget (Type u)`. We currently have two instances for `HasForget (Type u)`: * A global `HasForget` instance where `forget (Type u)` reduces to `𝟭 Type` * A locally enabled `ConcreteCategory` where `forget (Type u)` is only reducible-with-instances equal to `𝟭 Type`. Since instance synthesis only looks through reducible definitions, we need to help it out by copying over the instances that wouldn't be found otherwise. -/ attribute [local instance] Types.instFunLike Types.instConcreteCategory instance : (@forget (Type u) _ ConcreteCategory.toHasForget).Full := Functor.Full.id instance : PreservesLimitsOfSize (@forget (Type u) _ ConcreteCategory.toHasForget) := id_preservesLimitsOfSize instance : PreservesColimitsOfSize (@forget (Type u) _ ConcreteCategory.toHasForget) := id_preservesColimitsOfSize instance : ReflectsLimitsOfSize (@forget (Type u) _ ConcreteCategory.toHasForget) := id_reflectsLimits instance : ReflectsColimitsOfSize (@forget (Type u) _ ConcreteCategory.toHasForget) := id_reflectsColimits instance : (@forget (Type u) _ ConcreteCategory.toHasForget).IsEquivalence := Functor.isEquivalence_refl instance : (@forget (Type u) _ ConcreteCategory.toHasForget).IsCorepresentable := instIsCorepresentableIdType end CategoryTheory.Types namespace CategoryTheory.Limits.Concrete section Limits /-- If a functor `G : J ⥤ C` to a concrete category has a limit and that `forget C` is corepresentable, then `(G ⋙ forget C).sections` is small. -/ lemma small_sections_of_hasLimit {C : Type u} [Category.{v} C] [HasForget.{v} C] [(forget C).IsCorepresentable] {J : Type w} [Category.{t} J] (G : J ⥤ C) [HasLimit G] : Small.{v} (G ⋙ forget C).sections := by rw [← Types.hasLimit_iff_small_sections] infer_instance variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type r} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{r} C FC] variable {J : Type w} [Category.{t} J] (F : J ⥤ C) [PreservesLimit F (forget C)] theorem to_product_injective_of_isLimit {D : Cone F} (hD : IsLimit D) : Function.Injective fun (x : ToType D.pt) (j : J) => D.π.app j x := by let E := (forget C).mapCone D intro (x : E.pt) y H apply (Types.isLimitEquivSections (isLimitOfPreserves _ hD)).injective ext j exact funext_iff.mp H j theorem isLimit_ext {D : Cone F} (hD : IsLimit D) (x y : ToType D.pt) : (∀ j, D.π.app j x = D.π.app j y) → x = y := fun h => Concrete.to_product_injective_of_isLimit _ hD (funext h) theorem limit_ext [HasLimit F] (x y : ToType (limit F)) : (∀ j, limit.π F j x = limit.π F j y) → x = y := Concrete.isLimit_ext F (limit.isLimit _) _ _ section Surjective /-- Given surjections `⋯ ⟶ Xₙ₊₁ ⟶ Xₙ ⟶ ⋯ ⟶ X₀` in a concrete category whose forgetful functor preserves sequential limits, the projection map `lim Xₙ ⟶ X₀` is surjective. -/ lemma surjective_π_app_zero_of_surjective_map {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{v} C FC] [PreservesLimitsOfShape ℕᵒᵖ (forget C)] {F : ℕᵒᵖ ⥤ C} {c : Cone F} (hc : IsLimit c) (hF : ∀ n, Function.Surjective (F.map (homOfLE (Nat.le_succ n)).op)) : Function.Surjective (c.π.app ⟨0⟩) := Types.surjective_π_app_zero_of_surjective_map (isLimitOfPreserves (forget C) hc) hF end Surjective end Limits section Colimits section variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type t} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{t} C FC] variable {J : Type w} [Category.{r} J] (F : J ⥤ C) section variable [PreservesColimit F (forget C)] theorem from_union_surjective_of_isColimit {D : Cocone F} (hD : IsColimit D) : let ff : (Σ j : J, ToType (F.obj j)) → ToType D.pt := fun a => D.ι.app a.1 a.2 Function.Surjective ff := by intro ff x let E : Cocone (F ⋙ forget C) := (forget C).mapCocone D let hE : IsColimit E := isColimitOfPreserves (forget C) hD obtain ⟨j, y, hy⟩ := Types.jointly_surjective_of_isColimit hE x exact ⟨⟨j, y⟩, hy⟩ theorem isColimit_exists_rep {D : Cocone F} (hD : IsColimit D) (x : ToType D.pt) : ∃ (j : J) (y : ToType (F.obj j)), D.ι.app j y = x := by obtain ⟨a, rfl⟩ := Concrete.from_union_surjective_of_isColimit F hD x exact ⟨a.1, a.2, rfl⟩ theorem colimit_exists_rep [HasColimit F] (x : ToType (colimit F)) : ∃ (j : J) (y : ToType (F.obj j)), colimit.ι F j y = x := Concrete.isColimit_exists_rep F (colimit.isColimit _) x end theorem isColimit_rep_eq_of_exists {D : Cocone F} {i j : J} (x : ToType (F.obj i)) (y : ToType (F.obj j)) (h : ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f x = F.map g y) : D.ι.app i x = D.ι.app j y := by let E := (forget C).mapCocone D obtain ⟨k, f, g, (hfg : (F ⋙ forget C).map f x = F.map g y)⟩ := h let h1 : (F ⋙ forget C).map f ≫ E.ι.app k = E.ι.app i := E.ι.naturality f let h2 : (F ⋙ forget C).map g ≫ E.ι.app k = E.ι.app j := E.ι.naturality g change E.ι.app i x = E.ι.app j y rw [← h1, types_comp_apply, hfg] exact congrFun h2 y theorem colimit_rep_eq_of_exists [HasColimit F] {i j : J} (x : ToType (F.obj i)) (y : ToType (F.obj j)) (h : ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f x = F.map g y) : colimit.ι F i x = colimit.ι F j y := Concrete.isColimit_rep_eq_of_exists F x y h end section FilteredColimits variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type s} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC] variable {J : Type w} [Category.{r} J] (F : J ⥤ C) [PreservesColimit F (forget C)] [IsFiltered J] theorem isColimit_exists_of_rep_eq {D : Cocone F} {i j : J} (hD : IsColimit D) (x : ToType (F.obj i)) (y : ToType (F.obj j)) (h : D.ι.app _ x = D.ι.app _ y) : ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f x = F.map g y := by let E := (forget C).mapCocone D let hE : IsColimit E := isColimitOfPreserves _ hD exact (Types.FilteredColimit.isColimit_eq_iff (F ⋙ forget C) hE).mp h theorem isColimit_rep_eq_iff_exists {D : Cocone F} {i j : J} (hD : IsColimit D) (x : ToType (F.obj i)) (y : ToType (F.obj j)) : D.ι.app i x = D.ι.app j y ↔ ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f x = F.map g y := ⟨Concrete.isColimit_exists_of_rep_eq.{s} _ hD _ _, Concrete.isColimit_rep_eq_of_exists _ _ _⟩ theorem colimit_exists_of_rep_eq [HasColimit F] {i j : J} (x : ToType (F.obj i)) (y : ToType (F.obj j)) (h : colimit.ι F _ x = colimit.ι F _ y) : ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f x = F.map g y := Concrete.isColimit_exists_of_rep_eq.{s} F (colimit.isColimit _) x y h theorem colimit_rep_eq_iff_exists [HasColimit F] {i j : J} (x : ToType (F.obj i)) (y : ToType (F.obj j)) : colimit.ι F i x = colimit.ι F j y ↔ ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f x = F.map g y := ⟨Concrete.colimit_exists_of_rep_eq.{s} _ _ _, Concrete.colimit_rep_eq_of_exists _ _ _⟩ end FilteredColimits end Colimits end CategoryTheory.Limits.Concrete
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Final/Type.lean
import Mathlib.CategoryTheory.Limits.Final /-! # Action of an initial functor on sections Given `F : C ⥤ D` and `P : D ⥤ Type w`, we define a map `sectionsPrecomp F : P.sections → (F ⋙ P).sections` and show that it is a bijection when `F` is initial. As `Functor.sections` identify to limits of functors to types (at least under suitable universe assumptions), this could be deduced from general results about limits and initial functors, but we provide a more down to earth proof. We also obtain the dual result that if `F` is final, then `F.colimitTypePrecomp : (F ⋙ P).ColimitType → P.ColimitType` is a bijection. -/ universe w v₁ v₂ u₁ u₂ namespace CategoryTheory namespace Functor variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] /-- When `F : C ⥤ D` and `P : D ⥤ Type _`, this is the obvious map `P.section → (F ⋙ P).sections`. -/ @[simps] def sectionsPrecomp (F : C ⥤ D) {P : D ⥤ Type w} (x : P.sections) : (F ⋙ P).sections where val _ := x.val _ property _ := x.property _ lemma bijective_sectionsPrecomp (F : C ⥤ D) (P : D ⥤ Type w) [F.Initial] : Function.Bijective (F.sectionsPrecomp (P := P)) := by refine ⟨fun s₁ s₂ h ↦ ?_, fun t ↦ ?_⟩ · ext Y let X : CostructuredArrow F Y := Classical.arbitrary _ have := congr_fun (congr_arg Subtype.val h) X.left have h₁ := s₁.property X.hom have h₂ := s₂.property X.hom dsimp at this h₁ h₂ rw [← h₁, this, h₂] · have h (Y : D) := constant_of_preserves_morphisms' (fun (Z : CostructuredArrow F Y) ↦ P.map Z.hom (t.val Z.left)) (by intro Z₁ Z₂ φ dsimp rw [← t.property φ.left] dsimp rw [← FunctorToTypes.map_comp_apply, CostructuredArrow.w]) choose val hval using h refine ⟨⟨val, fun {Y₁ Y₂} f ↦ ?_⟩, ?_⟩ · let X : CostructuredArrow F Y₁ := Classical.arbitrary _ simp [← hval Y₁ X, ← hval Y₂ ((CostructuredArrow.map f).obj X)] · ext X : 2 simpa using (hval (F.obj X) (CostructuredArrow.mk (𝟙 _))).symm /-- Given `P : D ⥤ Type w` and `F : C ⥤ D`, this is the obvious map `(F ⋙ P).ColimitType → P.ColimitType`. -/ def colimitTypePrecomp (F : C ⥤ D) (P : D ⥤ Type w) : (F ⋙ P).ColimitType → P.ColimitType := (F ⋙ P).descColimitType (P.coconeTypes.precomp F) @[simp] lemma colimitTypePrecomp_ιColimitType (F : C ⥤ D) {P : D ⥤ Type w} (i : C) (x : P.obj (F.obj i)) : colimitTypePrecomp F P ((F ⋙ P).ιColimitType i x) = P.ιColimitType (F.obj i) x := rfl lemma bijective_colimitTypePrecomp (F : C ⥤ D) (P : D ⥤ Type w) [F.Final] : Function.Bijective (F.colimitTypePrecomp (P := P)) := by refine ⟨?_, fun x ↦ ?_⟩ · have h (Y : D) := constant_of_preserves_morphisms' (fun (Z : StructuredArrow Y F) ↦ (F ⋙ P).ιColimitType Z.right ∘ P.map Z.hom) (by intro Z₁ Z₂ f ext x dsimp rw [← (F ⋙ P).ιColimitType_map f.right, comp_map, ← FunctorToTypes.map_comp_apply, StructuredArrow.w f]) choose φ hφ using h let c : P.CoconeTypes := { pt := (F ⋙ P).ColimitType ι Y := φ Y ι_naturality {Y₁ Y₂} f := by ext have X : StructuredArrow Y₂ F := Classical.arbitrary _ rw [← hφ Y₂ X, ← hφ Y₁ ((StructuredArrow.map f).obj X)] simp } refine Function.RightInverse.injective (g := (P.descColimitType c)) (fun x ↦ ?_) obtain ⟨X, x, rfl⟩ := (F ⋙ P).ιColimitType_jointly_surjective x simp [c, ← hφ (F.obj X) (StructuredArrow.mk (𝟙 _))] · obtain ⟨X, x, rfl⟩ := P.ιColimitType_jointly_surjective x let Y : StructuredArrow X F := Classical.arbitrary _ exact ⟨(F ⋙ P).ιColimitType Y.right (P.map Y.hom x), by simp⟩ end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Final/Connected.lean
import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Discrete.StructuredArrow /-! # Characterization of connected categories using initial/final functors A category `C` is connected iff the constant functor `C ⥤ Discrete PUnit` is final (or initial). We deduce that the projection `C × D ⥤ C` is final (or initial) if `D` is connected. -/ universe w v v' u u' namespace CategoryTheory variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] {T : Type w} [Unique T] lemma isConnected_iff_final_of_unique (F : C ⥤ Discrete T) : IsConnected C ↔ F.Final := by rw [← isConnected_iff_of_equivalence (Discrete.structuredArrowEquivalenceOfUnique F default)] refine ⟨fun _ ↦ ⟨?_⟩, fun _ ↦ inferInstance⟩ rintro ⟨d⟩ obtain rfl := Subsingleton.elim d default infer_instance lemma isConnected_iff_initial_of_unique (F : C ⥤ Discrete T) : IsConnected C ↔ F.Initial := by rw [← isConnected_iff_of_equivalence (Discrete.costructuredArrowEquivalenceOfUnique F default)] refine ⟨fun _ ↦ ⟨?_⟩, fun _ ↦ inferInstance⟩ rintro ⟨d⟩ obtain rfl := Subsingleton.elim d default infer_instance instance (F : C ⥤ Discrete T) [IsConnected C] : F.Final := by rwa [← isConnected_iff_final_of_unique F] instance (F : C ⥤ Discrete T) [IsConnected C] : F.Initial := by rwa [← isConnected_iff_initial_of_unique F] instance final_fst [IsConnected D] : (Prod.fst C D).Final := inferInstanceAs (Functor.prod (𝟭 C) ((Functor.const _).obj (Discrete.mk .unit)) ⋙ (prod.rightUnitorEquivalence.{0} C).functor).Final instance final_snd [IsConnected C] : (Prod.snd C D).Final := inferInstanceAs ((Prod.braiding C D).functor ⋙ Prod.fst D C).Final instance initial_fst [IsConnected D] : (Prod.fst C D).Initial := inferInstanceAs (Functor.prod (𝟭 C) ((Functor.const _).obj (Discrete.mk .unit)) ⋙ (prod.rightUnitorEquivalence.{0} C).functor).Initial instance initial_snd [IsConnected C] : (Prod.snd C D).Initial := inferInstanceAs ((Prod.braiding C D).functor ⋙ Prod.fst D C).Initial end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Final/ParallelPair.lean
import Mathlib.CategoryTheory.Limits.Final /-! # Conditions for `parallelPair` to be initial In this file we give sufficient conditions on a category `C` and parallel morphisms `f g : X ⟶ Y` in `C` so that `parallelPair f g` becomes an initial functor. The conditions are that there is a morphism out of `X` to every object of `C` and that any two parallel morphisms out of `X` factor through the parallel pair `f`, `g` (`h₂ : ∀ ⦃Z : C⦄ (i j : X ⟶ Z), ∃ (a : Y ⟶ Z), i = f ≫ a ∧ j = g ≫ a`). -/ namespace CategoryTheory.Limits variable {C : Type*} [Category C] open WalkingParallelPair WalkingParallelPairHom CostructuredArrow lemma parallelPair_initial_mk' {X Y : C} (f g : X ⟶ Y) (h₁ : ∀ Z, Nonempty (X ⟶ Z)) (h₂ : ∀ ⦃Z : C⦄ (i j : X ⟶ Z), Zigzag (J := CostructuredArrow (parallelPair f g) Z) (mk (Y := zero) i) (mk (Y := zero) j)) : (parallelPair f g).Initial where out Z := by have : Nonempty (CostructuredArrow (parallelPair f g) Z) := ⟨mk (Y := zero) (h₁ Z).some⟩ have : ∀ (x : CostructuredArrow (parallelPair f g) Z), Zigzag x (mk (Y := zero) (h₁ Z).some) := by rintro ⟨(_ | _), ⟨⟩, φ⟩ · apply h₂ · refine Zigzag.trans ?_ (h₂ (f ≫ φ) _) exact Zigzag.of_inv (homMk left) exact zigzag_isConnected (fun x y => (this x).trans (this y).symm) lemma parallelPair_initial_mk {X Y : C} (f g : X ⟶ Y) (h₁ : ∀ Z, Nonempty (X ⟶ Z)) (h₂ : ∀ ⦃Z : C⦄ (i j : X ⟶ Z), ∃ (a : Y ⟶ Z), i = f ≫ a ∧ j = g ≫ a) : (parallelPair f g).Initial := parallelPair_initial_mk' f g h₁ (fun Z i j => by obtain ⟨a, rfl, rfl⟩ := h₂ i j let f₁ : (mk (Y := zero) (f ≫ a) : CostructuredArrow (parallelPair f g) Z) ⟶ mk (Y := one) a := homMk left let f₂ : (mk (Y := zero) (g ≫ a) : CostructuredArrow (parallelPair f g) Z) ⟶ mk (Y := one) a := homMk right exact Zigzag.of_hom_inv f₁ f₂) end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Yoneda.lean
import Mathlib.CategoryTheory.Limits.Preserves.Ulift import Mathlib.CategoryTheory.Limits.FunctorToTypes /-! # Yoneda preserves certain colimits Given a bifunctor `F : J ⥤ Cᵒᵖ ⥤ Type v`, we prove the isomorphism `Hom(YX, colim_j F(j, -)) ≅ colim_j Hom(YX, F(j, -))`, where `Y` is the Yoneda embedding. We state this in two ways. One is functorial in `X` and stated as a natural isomorphism of functors `yoneda.op ⋙ yoneda.obj (colimit F) ≅ yoneda.op ⋙ colimit (F ⋙ yoneda)`, and from this we deduce the more traditional preservation statement `PreservesColimit F (coyoneda.obj (op (yoneda.obj X)))`. The proof combines the Yoneda lemma with the fact that colimits in functor categories are computed pointwise. ## See also There is also a relative version of this statement where `F : J ⥤ Over A` for some presheaf `A`, see `Mathlib/CategoryTheory/Comma/Presheaf/Colimit.lean`. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open CategoryTheory.Limits Opposite Functor variable {C : Type u₁} [Category.{v₁} C] variable {J : Type u₂} [Category.{v₂} J] [HasColimitsOfShape J (Type v₁)] [HasColimitsOfShape J (Type (max u₁ v₁))] (F : J ⥤ Cᵒᵖ ⥤ Type v₁) /-- Naturally in `X`, we have `Hom(YX, colim_i Fi) ≅ colim_i Hom(YX, Fi)`. -/ noncomputable def yonedaYonedaColimit : yoneda.op ⋙ yoneda.obj (colimit F) ≅ yoneda.op ⋙ colimit (F ⋙ yoneda) := calc yoneda.op ⋙ yoneda.obj (colimit F) ≅ colimit F ⋙ uliftFunctor.{u₁} := yonedaOpCompYonedaObj (colimit F) _ ≅ F.flip ⋙ colim ⋙ uliftFunctor.{u₁} := isoWhiskerRight (colimitIsoFlipCompColim F) uliftFunctor.{u₁} _ ≅ F.flip ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ⋙ colim := isoWhiskerLeft F.flip (preservesColimitNatIso uliftFunctor.{u₁}) _ ≅ (yoneda.op ⋙ coyoneda ⋙ (whiskeringLeft _ _ _).obj F) ⋙ colim := isoWhiskerRight (isoWhiskerRight largeCurriedYonedaLemma.symm ((whiskeringLeft _ _ _).obj F)) colim _ ≅ yoneda.op ⋙ colimit (F ⋙ yoneda) := isoWhiskerLeft yoneda.op (colimitIsoFlipCompColim (F ⋙ yoneda)).symm theorem yonedaYonedaColimit_app_inv {X : C} : ((yonedaYonedaColimit F).app (op X)).inv = (colimitObjIsoColimitCompEvaluation _ _).hom ≫ (colimit.post F (coyoneda.obj (op (yoneda.obj X)))) := by dsimp [yonedaYonedaColimit] simp only [Iso.cancel_iso_hom_left] apply colimit.hom_ext intro j rw [colimit.ι_post, ι_colimMap_assoc] simp only [← CategoryTheory.Functor.assoc, comp_evaluation] rw [ι_preservesColimitIso_inv_assoc, ← Functor.map_comp_assoc] simp only [← comp_evaluation] rw [colimitObjIsoColimitCompEvaluation_ι_inv, whiskerLeft_app] ext η Y f simp [largeCurriedYonedaLemma, yonedaOpCompYonedaObj, FunctorToTypes.colimit.map_ι_apply, map_yonedaEquiv] noncomputable instance {X : C} : PreservesColimit F (coyoneda.obj (op (yoneda.obj X))) := by suffices IsIso (colimit.post F (coyoneda.obj (op (yoneda.obj X)))) from preservesColimit_of_isIso_post _ _ suffices colimit.post F (coyoneda.obj (op (yoneda.obj X))) = (colimitObjIsoColimitCompEvaluation _ _).inv ≫ ((yonedaYonedaColimit F).app (op X)).inv from this ▸ inferInstance rw [yonedaYonedaColimit_app_inv, Iso.inv_hom_id_assoc] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Finite.lean
import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Preservation of finite (co)limits. These functors are also known as left exact (flat) or right exact functors when the categories involved are abelian, or more generally, finitely (co)complete. ## Related results * `CategoryTheory.Limits.preservesFiniteLimitsOfPreservesEqualizersAndFiniteProducts` : see `CategoryTheory/Limits/Constructions/LimitsOfProductsAndEqualizers.lean`. Also provides the dual version. * `CategoryTheory.Limits.preservesFiniteLimitsIffFlat` : see `CategoryTheory/Functor/Flat.lean`. -/ open CategoryTheory namespace CategoryTheory.Limits -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe u w w₂ v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] variable {J : Type w} [SmallCategory J] {K : J ⥤ C} /-- A functor is said to preserve finite limits, if it preserves all limits of shape `J`, where `J : Type` is a finite category. -/ class PreservesFiniteLimits (F : C ⥤ D) : Prop where preservesFiniteLimits : ∀ (J : Type) [SmallCategory J] [FinCategory J], PreservesLimitsOfShape J F := by infer_instance attribute [instance] PreservesFiniteLimits.preservesFiniteLimits /-- Preserving finite limits also implies preserving limits over finite shapes in higher universes, though through a noncomputable instance. -/ instance (priority := 100) preservesLimitsOfShapeOfPreservesFiniteLimits (F : C ⥤ D) [PreservesFiniteLimits F] (J : Type w) [SmallCategory J] [FinCategory J] : PreservesLimitsOfShape J F := by apply preservesLimitsOfShape_of_equiv (FinCategory.equivAsType J) -- This is a dangerous instance as it has unbound universe variables. /-- If we preserve limits of some arbitrary size, then we preserve all finite limits. -/ lemma PreservesLimitsOfSize.preservesFiniteLimits (F : C ⥤ D) [PreservesLimitsOfSize.{w, w₂} F] : PreservesFiniteLimits F where preservesFiniteLimits J (sJ : SmallCategory J) fJ := by haveI := preservesSmallestLimits_of_preservesLimits F exact preservesLimitsOfShape_of_equiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for limits indexed in Type 0. instance (priority := 120) PreservesLimitsOfSize0.preservesFiniteLimits (F : C ⥤ D) [PreservesLimitsOfSize.{0, 0} F] : PreservesFiniteLimits F := PreservesLimitsOfSize.preservesFiniteLimits F -- An alternative specialization of the dangerous instance for small limits. instance (priority := 120) PreservesLimits.preservesFiniteLimits (F : C ⥤ D) [PreservesLimits F] : PreservesFiniteLimits F := PreservesLimitsOfSize.preservesFiniteLimits F attribute [local instance] uliftCategory in /-- We can always derive `PreservesFiniteLimits C` by showing that we are preserving limits at an arbitrary universe. -/ lemma preservesFiniteLimits_of_preservesFiniteLimitsOfSize (F : C ⥤ D) (h : ∀ (J : Type w) {𝒥 : SmallCategory J} (_ : @FinCategory J 𝒥), PreservesLimitsOfShape J F) : PreservesFiniteLimits F where preservesFiniteLimits J (_ : SmallCategory J) _ := by haveI := h (ULiftHom (ULift J)) CategoryTheory.finCategoryUlift exact preservesLimitsOfShape_of_equiv (ULiftHomULiftCategory.equiv J).symm F /-- The composition of two left exact functors is left exact. -/ lemma comp_preservesFiniteLimits (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteLimits F] [PreservesFiniteLimits G] : PreservesFiniteLimits (F ⋙ G) := ⟨fun _ _ _ => inferInstance⟩ /-- Transfer preservation of finite limits along a natural isomorphism in the functor. -/ lemma preservesFiniteLimits_of_natIso {F G : C ⥤ D} (h : F ≅ G) [PreservesFiniteLimits F] : PreservesFiniteLimits G where preservesFiniteLimits _ _ _ := preservesLimitsOfShape_of_natIso h /-- A functor `F` preserves finite products if it preserves all from `Discrete J` for `Finite J`. We require this for `J = Fin n` in the definition, then generalize to `J : Type u` in the instance. -/ class PreservesFiniteProducts (F : C ⥤ D) : Prop where preserves : ∀ n, PreservesLimitsOfShape (Discrete (Fin n)) F instance (priority := 100) (F : C ⥤ D) (J : Type u) [Finite J] [PreservesFiniteProducts F] : PreservesLimitsOfShape (Discrete J) F := by obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin J have := PreservesFiniteProducts.preserves (F := F) n exact preservesLimitsOfShape_of_equiv (Discrete.equivalence e.symm) F instance comp_preservesFiniteProducts (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteProducts F] [PreservesFiniteProducts G] : PreservesFiniteProducts (F ⋙ G) where preserves _ := inferInstance instance (F : C ⥤ D) [PreservesFiniteLimits F] : PreservesFiniteProducts F where preserves _ := inferInstance /-- A functor is said to reflect finite limits, if it reflects all limits of shape `J`, where `J : Type` is a finite category. -/ class ReflectsFiniteLimits (F : C ⥤ D) : Prop where reflects : ∀ (J : Type) [SmallCategory J] [FinCategory J], ReflectsLimitsOfShape J F := by infer_instance attribute [instance] ReflectsFiniteLimits.reflects /- Similarly to preserving finite products, quantified classes don't behave well. -/ /-- A functor `F` preserves finite products if it reflects limits of shape `Discrete J` for finite `J`. We require this for `J = Fin n` in the definition, then generalize to `J : Type u` in the instance. -/ class ReflectsFiniteProducts (F : C ⥤ D) : Prop where reflects : ∀ n, ReflectsLimitsOfShape (Discrete (Fin n)) F instance (priority := 100) (F : C ⥤ D) [ReflectsFiniteProducts F] (J : Type u) [Finite J] : ReflectsLimitsOfShape (Discrete J) F := let ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin J have := ReflectsFiniteProducts.reflects (F := F) n reflectsLimitsOfShape_of_equiv (Discrete.equivalence e.symm) _ -- This is a dangerous instance as it has unbound universe variables. /-- If we reflect limits of some arbitrary size, then we reflect all finite limits. -/ lemma ReflectsLimitsOfSize.reflectsFiniteLimits (F : C ⥤ D) [ReflectsLimitsOfSize.{w, w₂} F] : ReflectsFiniteLimits F where reflects J (sJ : SmallCategory J) fJ := by haveI := reflectsSmallestLimits_of_reflectsLimits F exact reflectsLimitsOfShape_of_equiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for colimits indexed in Type 0. instance (priority := 120) (F : C ⥤ D) [ReflectsLimitsOfSize.{0, 0} F] : ReflectsFiniteLimits F := ReflectsLimitsOfSize.reflectsFiniteLimits F -- An alternative specialization of the dangerous instance for small colimits. instance (priority := 120) (F : C ⥤ D) [ReflectsLimits F] : ReflectsFiniteLimits F := ReflectsLimitsOfSize.reflectsFiniteLimits F /-- If `F ⋙ G` preserves finite limits and `G` reflects finite limits, then `F` preserves finite limits. -/ lemma preservesFiniteLimits_of_reflects_of_preserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteLimits (F ⋙ G)] [ReflectsFiniteLimits G] : PreservesFiniteLimits F where preservesFiniteLimits _ _ _ := preservesLimitsOfShape_of_reflects_of_preserves F G /-- If `F ⋙ G` preserves finite products and `G` reflects finite products, then `F` preserves finite products. -/ lemma preservesFiniteProducts_of_reflects_of_preserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteProducts (F ⋙ G)] [ReflectsFiniteProducts G] : PreservesFiniteProducts F where preserves _ := preservesLimitsOfShape_of_reflects_of_preserves F G instance reflectsFiniteLimits_of_reflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteLimits C] [PreservesFiniteLimits F] : ReflectsFiniteLimits F where reflects _ _ _ := reflectsLimitsOfShape_of_reflectsIsomorphisms instance reflectsFiniteProducts_of_reflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteProducts C] [PreservesFiniteProducts F] : ReflectsFiniteProducts F where reflects _ := reflectsLimitsOfShape_of_reflectsIsomorphisms instance comp_reflectsFiniteProducts (F : C ⥤ D) (G : D ⥤ E) [ReflectsFiniteProducts F] [ReflectsFiniteProducts G] : ReflectsFiniteProducts (F ⋙ G) where reflects _ := inferInstance instance (F : C ⥤ D) [ReflectsFiniteLimits F] : ReflectsFiniteProducts F where reflects _ := inferInstance /-- A functor is said to preserve finite colimits, if it preserves all colimits of shape `J`, where `J : Type` is a finite category. -/ class PreservesFiniteColimits (F : C ⥤ D) : Prop where preservesFiniteColimits : ∀ (J : Type) [SmallCategory J] [FinCategory J], PreservesColimitsOfShape J F := by infer_instance attribute [instance] PreservesFiniteColimits.preservesFiniteColimits /-- Preserving finite colimits also implies preserving colimits over finite shapes in higher universes. -/ instance (priority := 100) preservesColimitsOfShapeOfPreservesFiniteColimits (F : C ⥤ D) [PreservesFiniteColimits F] (J : Type w) [SmallCategory J] [FinCategory J] : PreservesColimitsOfShape J F := by apply preservesColimitsOfShape_of_equiv (FinCategory.equivAsType J) -- This is a dangerous instance as it has unbound universe variables. /-- If we preserve colimits of some arbitrary size, then we preserve all finite colimits. -/ lemma PreservesColimitsOfSize.preservesFiniteColimits (F : C ⥤ D) [PreservesColimitsOfSize.{w, w₂} F] : PreservesFiniteColimits F where preservesFiniteColimits J (sJ : SmallCategory J) fJ := by haveI := preservesSmallestColimits_of_preservesColimits F exact preservesColimitsOfShape_of_equiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for colimits indexed in Type 0. instance (priority := 120) PreservesColimitsOfSize0.preservesFiniteColimits (F : C ⥤ D) [PreservesColimitsOfSize.{0, 0} F] : PreservesFiniteColimits F := PreservesColimitsOfSize.preservesFiniteColimits F -- An alternative specialization of the dangerous instance for small colimits. instance (priority := 120) PreservesColimits.preservesFiniteColimits (F : C ⥤ D) [PreservesColimits F] : PreservesFiniteColimits F := PreservesColimitsOfSize.preservesFiniteColimits F attribute [local instance] uliftCategory in /-- We can always derive `PreservesFiniteColimits C` by showing that we are preserving colimits at an arbitrary universe. -/ lemma preservesFiniteColimits_of_preservesFiniteColimitsOfSize (F : C ⥤ D) (h : ∀ (J : Type w) {𝒥 : SmallCategory J} (_ : @FinCategory J 𝒥), PreservesColimitsOfShape J F) : PreservesFiniteColimits F where preservesFiniteColimits J (_ : SmallCategory J) _ := by letI : Category (ULiftHom (ULift J)) := ULiftHom.category haveI := h (ULiftHom (ULift J)) CategoryTheory.finCategoryUlift exact preservesColimitsOfShape_of_equiv (ULiftHomULiftCategory.equiv J).symm F /-- The composition of two right exact functors is right exact. -/ lemma comp_preservesFiniteColimits (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteColimits F] [PreservesFiniteColimits G] : PreservesFiniteColimits (F ⋙ G) := ⟨fun _ _ _ => inferInstance⟩ /-- Transfer preservation of finite colimits along a natural isomorphism in the functor. -/ lemma preservesFiniteColimits_of_natIso {F G : C ⥤ D} (h : F ≅ G) [PreservesFiniteColimits F] : PreservesFiniteColimits G where preservesFiniteColimits _ _ _ := preservesColimitsOfShape_of_natIso h /-- A functor `F` preserves finite products if it preserves all from `Discrete J` for `Fintype J`. We require this for `J = Fin n` in the definition, then generalize to `J : Type u` in the instance. -/ class PreservesFiniteCoproducts (F : C ⥤ D) : Prop where /-- preservation of colimits indexed by `Discrete (Fin n)`. -/ preserves : ∀ n, PreservesColimitsOfShape (Discrete (Fin n)) F instance (priority := 100) (F : C ⥤ D) (J : Type u) [Finite J] [PreservesFiniteCoproducts F] : PreservesColimitsOfShape (Discrete J) F := let ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin J have := PreservesFiniteCoproducts.preserves (F := F) n preservesColimitsOfShape_of_equiv (Discrete.equivalence e.symm) F instance comp_preservesFiniteCoproducts (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteCoproducts F] [PreservesFiniteCoproducts G] : PreservesFiniteCoproducts (F ⋙ G) where preserves _ := inferInstance instance (F : C ⥤ D) [PreservesFiniteColimits F] : PreservesFiniteCoproducts F where preserves _ := inferInstance /-- A functor is said to reflect finite colimits, if it reflects all colimits of shape `J`, where `J : Type` is a finite category. -/ class ReflectsFiniteColimits (F : C ⥤ D) : Prop where [reflects : ∀ (J : Type) [SmallCategory J] [FinCategory J], ReflectsColimitsOfShape J F] attribute [instance] ReflectsFiniteColimits.reflects -- This is a dangerous instance as it has unbound universe variables. /-- If we reflect colimits of some arbitrary size, then we reflect all finite colimits. -/ lemma ReflectsColimitsOfSize.reflectsFiniteColimits (F : C ⥤ D) [ReflectsColimitsOfSize.{w, w₂} F] : ReflectsFiniteColimits F where reflects J (sJ : SmallCategory J) fJ := by haveI := reflectsSmallestColimits_of_reflectsColimits F exact reflectsColimitsOfShape_of_equiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for colimits indexed in Type 0. instance (priority := 120) (F : C ⥤ D) [ReflectsColimitsOfSize.{0, 0} F] : ReflectsFiniteColimits F := ReflectsColimitsOfSize.reflectsFiniteColimits F -- An alternative specialization of the dangerous instance for small colimits. instance (priority := 120) (F : C ⥤ D) [ReflectsColimits F] : ReflectsFiniteColimits F := ReflectsColimitsOfSize.reflectsFiniteColimits F /- Similarly to preserving finite coproducts, quantified classes don't behave well. -/ /-- A functor `F` preserves finite coproducts if it reflects colimits of shape `Discrete J` for finite `J`. We require this for `J = Fin n` in the definition, then generalize to `J : Type u` in the instance. -/ class ReflectsFiniteCoproducts (F : C ⥤ D) : Prop where reflects : ∀ n, ReflectsColimitsOfShape (Discrete (Fin n)) F instance (priority := 100) (F : C ⥤ D) [ReflectsFiniteCoproducts F] (J : Type u) [Finite J] : ReflectsColimitsOfShape (Discrete J) F := let ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin J have := ReflectsFiniteCoproducts.reflects (F := F) n reflectsColimitsOfShape_of_equiv (Discrete.equivalence e.symm) _ /-- If `F ⋙ G` preserves finite colimits and `G` reflects finite colimits, then `F` preserves finite colimits. -/ lemma preservesFiniteColimits_of_reflects_of_preserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteColimits (F ⋙ G)] [ReflectsFiniteColimits G] : PreservesFiniteColimits F where preservesFiniteColimits _ _ _ := preservesColimitsOfShape_of_reflects_of_preserves F G /-- If `F ⋙ G` preserves finite coproducts and `G` reflects finite coproducts, then `F` preserves finite coproducts. -/ lemma preservesFiniteCoproducts_of_reflects_of_preserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteCoproducts (F ⋙ G)] [ReflectsFiniteCoproducts G] : PreservesFiniteCoproducts F where preserves _ := preservesColimitsOfShape_of_reflects_of_preserves F G instance reflectsFiniteColimitsOfReflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteColimits C] [PreservesFiniteColimits F] : ReflectsFiniteColimits F where reflects _ _ _ := reflectsColimitsOfShape_of_reflectsIsomorphisms instance reflectsFiniteCoproductsOfReflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteCoproducts C] [PreservesFiniteCoproducts F] : ReflectsFiniteCoproducts F where reflects _ := reflectsColimitsOfShape_of_reflectsIsomorphisms instance comp_reflectsFiniteCoproducts (F : C ⥤ D) (G : D ⥤ E) [ReflectsFiniteCoproducts F] [ReflectsFiniteCoproducts G] : ReflectsFiniteCoproducts (F ⋙ G) where reflects _ := inferInstance instance (F : C ⥤ D) [ReflectsFiniteColimits F] : ReflectsFiniteCoproducts F where reflects _ := inferInstance end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Filtered.lean
import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Filtered.Basic /-! # Preservation of filtered colimits and cofiltered limits. Typically forgetful functors from algebraic categories preserve filtered colimits (although not general colimits). See e.g. `Algebra/Category/MonCat/FilteredColimits`. -/ open CategoryTheory open CategoryTheory.Functor namespace CategoryTheory.Limits universe w' w₂' w w₂ v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] section FilteredColimits section Preserves -- This should be used with explicit universe variables. /-- `PreservesFilteredColimitsOfSize.{w', w} F` means that `F` sends all colimit cocones over any filtered diagram `J ⥤ C` to colimit cocones, where `J : Type w` with `[Category.{w'} J]`. -/ @[nolint checkUnivs, pp_with_univ] class PreservesFilteredColimitsOfSize (F : C ⥤ D) : Prop where preserves_filtered_colimits : ∀ (J : Type w) [Category.{w'} J] [IsFiltered J], PreservesColimitsOfShape J F /-- A functor is said to preserve filtered colimits, if it preserves all colimits of shape `J`, where `J` is a filtered category which is small relative to the universe in which morphisms of the source live. -/ abbrev PreservesFilteredColimits (F : C ⥤ D) : Prop := PreservesFilteredColimitsOfSize.{v₂, v₂} F attribute [instance 100] PreservesFilteredColimitsOfSize.preserves_filtered_colimits instance (priority := 100) PreservesColimits.preservesFilteredColimits (F : C ⥤ D) [PreservesColimitsOfSize.{w, w'} F] : PreservesFilteredColimitsOfSize.{w, w'} F where preserves_filtered_colimits _ := inferInstance instance comp_preservesFilteredColimits (F : C ⥤ D) (G : D ⥤ E) [PreservesFilteredColimitsOfSize.{w, w'} F] [PreservesFilteredColimitsOfSize.{w, w'} G] : PreservesFilteredColimitsOfSize.{w, w'} (F ⋙ G) where preserves_filtered_colimits _ := inferInstance /-- A functor preserving larger filtered colimits also preserves smaller filtered colimits. -/ lemma preservesFilteredColimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [PreservesFilteredColimitsOfSize.{w', w₂'} F] : PreservesFilteredColimitsOfSize.{w, w₂} F where preserves_filtered_colimits J _ _ := by let e := ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm haveI := IsFiltered.of_equivalence e.symm exact preservesColimitsOfShape_of_equiv e F /-- `PreservesFilteredColimitsOfSize_shrink.{w, w'} F` tries to obtain `PreservesFilteredColimitsOfSize.{w, w'} F` from some other `PreservesFilteredColimitsOfSize F`. -/ lemma preservesFilteredColimitsOfSize_shrink (F : C ⥤ D) [PreservesFilteredColimitsOfSize.{max w w₂, max w' w₂'} F] : PreservesFilteredColimitsOfSize.{w, w'} F := preservesFilteredColimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Preserving filtered colimits at any universe implies preserving filtered colimits at universe `0`. -/ lemma preservesSmallestFilteredColimits_of_preservesFilteredColimits (F : C ⥤ D) [PreservesFilteredColimitsOfSize.{w', w} F] : PreservesFilteredColimitsOfSize.{0, 0} F := preservesFilteredColimitsOfSize_shrink F end Preserves section Reflects -- This should be used with explicit universe variables. /-- `ReflectsFilteredColimitsOfSize.{w', w} F` means that whenever the image of a filtered cocone under `F` is a colimit cocone, the original cocone was already a colimit. -/ @[nolint checkUnivs, pp_with_univ] class ReflectsFilteredColimitsOfSize (F : C ⥤ D) : Prop where reflects_filtered_colimits : ∀ (J : Type w) [Category.{w'} J] [IsFiltered J], ReflectsColimitsOfShape J F /-- A functor is said to reflect filtered colimits, if it reflects all colimits of shape `J`, where `J` is a filtered category which is small relative to the universe in which morphisms of the source live. -/ abbrev ReflectsFilteredColimits (F : C ⥤ D) : Prop := ReflectsFilteredColimitsOfSize.{v₂, v₂} F attribute [instance 100] ReflectsFilteredColimitsOfSize.reflects_filtered_colimits instance (priority := 100) ReflectsColimits.reflectsFilteredColimits (F : C ⥤ D) [ReflectsColimitsOfSize.{w, w'} F] : ReflectsFilteredColimitsOfSize.{w, w'} F where reflects_filtered_colimits _ := inferInstance instance comp_reflectsFilteredColimits (F : C ⥤ D) (G : D ⥤ E) [ReflectsFilteredColimitsOfSize.{w, w'} F] [ReflectsFilteredColimitsOfSize.{w, w'} G] : ReflectsFilteredColimitsOfSize.{w, w'} (F ⋙ G) where reflects_filtered_colimits _ := inferInstance /-- A functor reflecting larger filtered colimits also reflects smaller filtered colimits. -/ lemma reflectsFilteredColimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [ReflectsFilteredColimitsOfSize.{w', w₂'} F] : ReflectsFilteredColimitsOfSize.{w, w₂} F where reflects_filtered_colimits J _ _ := by let e := ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm haveI := IsFiltered.of_equivalence e.symm exact reflectsColimitsOfShape_of_equiv e F /-- `ReflectsFilteredColimitsOfSize_shrink.{w, w'} F` tries to obtain `ReflectsFilteredColimitsOfSize.{w, w'} F` from some other `ReflectsFilteredColimitsOfSize F`. -/ lemma reflectsFilteredColimitsOfSize_shrink (F : C ⥤ D) [ReflectsFilteredColimitsOfSize.{max w w₂, max w' w₂'} F] : ReflectsFilteredColimitsOfSize.{w, w'} F := reflectsFilteredColimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Reflecting filtered colimits at any universe implies reflecting filtered colimits at universe `0`. -/ lemma reflectsSmallestFilteredColimits_of_reflectsFilteredColimits (F : C ⥤ D) [ReflectsFilteredColimitsOfSize.{w', w} F] : ReflectsFilteredColimitsOfSize.{0, 0} F := reflectsFilteredColimitsOfSize_shrink F end Reflects end FilteredColimits section CofilteredLimits section Preserves -- This should be used with explicit universe variables. /-- `PreservesCofilteredLimitsOfSize.{w', w} F` means that `F` sends all limit cones over any cofiltered diagram `J ⥤ C` to limit cones, where `J : Type w` with `[Category.{w'} J]`. -/ @[nolint checkUnivs, pp_with_univ] class PreservesCofilteredLimitsOfSize (F : C ⥤ D) : Prop where preserves_cofiltered_limits : ∀ (J : Type w) [Category.{w'} J] [IsCofiltered J], PreservesLimitsOfShape J F /-- A functor is said to preserve cofiltered limits, if it preserves all limits of shape `J`, where `J` is a cofiltered category which is small relative to the universe in which morphisms of the source live. -/ abbrev PreservesCofilteredLimits (F : C ⥤ D) : Prop := PreservesCofilteredLimitsOfSize.{v₂, v₂} F attribute [instance 100] PreservesCofilteredLimitsOfSize.preserves_cofiltered_limits instance (priority := 100) PreservesLimits.preservesCofilteredLimits (F : C ⥤ D) [PreservesLimitsOfSize.{w, w'} F] : PreservesCofilteredLimitsOfSize.{w, w'} F where preserves_cofiltered_limits _ := inferInstance instance comp_preservesCofilteredLimits (F : C ⥤ D) (G : D ⥤ E) [PreservesCofilteredLimitsOfSize.{w, w'} F] [PreservesCofilteredLimitsOfSize.{w, w'} G] : PreservesCofilteredLimitsOfSize.{w, w'} (F ⋙ G) where preserves_cofiltered_limits _ := inferInstance /-- A functor preserving larger cofiltered limits also preserves smaller cofiltered limits. -/ lemma preservesCofilteredLimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [PreservesCofilteredLimitsOfSize.{w', w₂'} F] : PreservesCofilteredLimitsOfSize.{w, w₂} F where preserves_cofiltered_limits J _ _ := by let e := ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm haveI := IsCofiltered.of_equivalence e.symm exact preservesLimitsOfShape_of_equiv e F /-- `PreservesCofilteredLimitsOfSizeShrink.{w, w'} F` tries to obtain `PreservesCofilteredLimitsOfSize.{w, w'} F` from some other `PreservesCofilteredLimitsOfSize F`. -/ lemma preservesCofilteredLimitsOfSize_shrink (F : C ⥤ D) [PreservesCofilteredLimitsOfSize.{max w w₂, max w' w₂'} F] : PreservesCofilteredLimitsOfSize.{w, w'} F := preservesCofilteredLimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Preserving cofiltered limits at any universe implies preserving cofiltered limits at universe `0`. -/ lemma preservesSmallestCofilteredLimits_of_preservesCofilteredLimits (F : C ⥤ D) [PreservesCofilteredLimitsOfSize.{w', w} F] : PreservesCofilteredLimitsOfSize.{0, 0} F := preservesCofilteredLimitsOfSize_shrink F end Preserves section Reflects -- This should be used with explicit universe variables. /-- `ReflectsCofilteredLimitsOfSize.{w', w} F` means that whenever the image of a cofiltered cone under `F` is a limit cone, the original cone was already a limit. -/ @[nolint checkUnivs, pp_with_univ] class ReflectsCofilteredLimitsOfSize (F : C ⥤ D) : Prop where reflects_cofiltered_limits : ∀ (J : Type w) [Category.{w'} J] [IsCofiltered J], ReflectsLimitsOfShape J F /-- A functor is said to reflect cofiltered limits, if it reflects all limits of shape `J`, where `J` is a cofiltered category which is small relative to the universe in which morphisms of the source live. -/ abbrev ReflectsCofilteredLimits (F : C ⥤ D) : Prop := ReflectsCofilteredLimitsOfSize.{v₂, v₂} F attribute [instance 100] ReflectsCofilteredLimitsOfSize.reflects_cofiltered_limits instance (priority := 100) ReflectsLimits.reflectsCofilteredLimits (F : C ⥤ D) [ReflectsLimitsOfSize.{w, w'} F] : ReflectsCofilteredLimitsOfSize.{w, w'} F where reflects_cofiltered_limits _ := inferInstance instance comp_reflectsCofilteredLimits (F : C ⥤ D) (G : D ⥤ E) [ReflectsCofilteredLimitsOfSize.{w, w'} F] [ReflectsCofilteredLimitsOfSize.{w, w'} G] : ReflectsCofilteredLimitsOfSize.{w, w'} (F ⋙ G) where reflects_cofiltered_limits _ := inferInstance /-- A functor reflecting larger cofiltered limits also reflects smaller cofiltered limits. -/ lemma reflectsCofilteredLimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [ReflectsCofilteredLimitsOfSize.{w', w₂'} F] : ReflectsCofilteredLimitsOfSize.{w, w₂} F where reflects_cofiltered_limits J _ _ := by let e := ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm haveI := IsCofiltered.of_equivalence e.symm exact reflectsLimitsOfShape_of_equiv e F /-- `ReflectsCofilteredLimitsOfSize_shrink.{w, w'} F` tries to obtain `ReflectsCofilteredLimitsOfSize.{w, w'} F` from some other `ReflectsCofilteredLimitsOfSize F`. -/ lemma reflectsCofilteredLimitsOfSize_shrink (F : C ⥤ D) [ReflectsCofilteredLimitsOfSize.{max w w₂, max w' w₂'} F] : ReflectsCofilteredLimitsOfSize.{w, w'} F := reflectsCofilteredLimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Reflecting cofiltered limits at any universe implies reflecting cofiltered limits at universe `0`. -/ lemma reflectsSmallestCofilteredLimits_of_reflectsCofilteredLimits (F : C ⥤ D) [ReflectsCofilteredLimitsOfSize.{w', w} F] : ReflectsCofilteredLimitsOfSize.{0, 0} F := reflectsCofilteredLimitsOfSize_shrink F end Reflects end CofilteredLimits end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Presheaf.lean
import Mathlib.CategoryTheory.Limits.FilteredColimitCommutesFiniteLimit import Mathlib.CategoryTheory.Limits.Elements /-! # Finite-limit-preserving presheaves In this file we prove that if `C` is a small finitely cocomplete category and `A : Cᵒᵖ ⥤ Type u` is a presheaf, then `CostructuredArrow yoneda A` is filtered (equivalently, the category of elements of `A` is cofiltered) if and only if `A` preserves finite limits. This is one of the keys steps of establishing the equivalence `Ind C ≌ (Cᵒᵖ ⥤ₗ Type u)` (here, `Cᵒᵖ ⥤ₗ Type u` is the category of left exact functors) for a *small* finitely cocomplete category `C`. ## Implementation notes In the entire file, we are careful about details like functor associativity to ensure that we do not end up in situations where we have morphisms like `colimit.ι F i ≫ f`, where the domain of `f` is `colimit G` where `F` and `G` are definitionally equal but not syntactically equal. In these situations, lemmas about `colimit.ι G i ≫ f` cannot be applied using `rw` and `simp`, forcing the use of `erw`. In particular, for us this means that `HasColimit.isoOfNatIso (Iso.refl _)` is better than `Iso.refl _` and that we should be very particular about functor associativity. The theorem is also true for large categories and the proof given here generalizes to this case on paper. However, our infrastructure for commuting finite limits of shape `J` and filtered colimits of shape `K` is fundamentally not equipped to deal with the case where not all limits of shape `K` exist. In fact, not even the definition `colimitLimitToLimitColimit` can be written down if not all limits of shape `K` exist. Refactoring this to the level of generality we need would be a major undertaking. Since the application to the category of Ind-objects only require the case where `C` is small, we leave this as a TODO. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Proposition 3.3.13 * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1], Proposition 6.1.2 -/ open CategoryTheory Limits Functor universe v u namespace CategoryTheory.Limits section LargeCategory variable {C : Type u} [Category.{v} C] [HasFiniteColimits C] (A : Cᵒᵖ ⥤ Type v) /-- If `C` is a finitely cocomplete category and `A : Cᵒᵖ ⥤ Type u` is a presheaf that preserves finite limits, then `CostructuredArrow yoneda A` is filtered. One direction of Proposition 3.3.13 of [Kashiwara2006]. -/ theorem isFiltered_costructuredArrow_yoneda_of_preservesFiniteLimits [PreservesFiniteLimits A] : IsFiltered (CostructuredArrow yoneda A) := by suffices IsCofiltered A.Elements from IsFiltered.of_equivalence (CategoryOfElements.costructuredArrowYonedaEquivalence _) suffices HasFiniteLimits A.Elements from IsCofiltered.of_hasFiniteLimits A.Elements exact ⟨fun J _ _ => inferInstance⟩ end LargeCategory variable {C : Type u} [SmallCategory C] [HasFiniteColimits C] variable (A : Cᵒᵖ ⥤ Type u) namespace PreservesFiniteLimitsOfIsFilteredCostructuredArrowYonedaAux variable {J : Type} [SmallCategory J] [FinCategory J] (K : J ⥤ Cᵒᵖ) /-- (Implementation) This is the bifunctor we will apply "filtered colimits commute with finite limits" to. -/ def functorToInterchange : J ⥤ CostructuredArrow yoneda A ⥤ Type u := K ⋙ coyoneda ⋙ (whiskeringLeft _ _ _).obj (CostructuredArrow.proj _ _) /-- (Implementation) The definition of `functorToInterchange`. -/ @[simps!] def functorToInterchangeIso : functorToInterchange A K ≅ K ⋙ coyoneda ⋙ (whiskeringLeft _ _ _).obj (CostructuredArrow.proj _ _) := Iso.refl _ /-- (Implementation) One way to express the flipped version of our functor. We choose this association because the type of `Presheaf.tautologicalCocone` is `Cocone (CostructuredArrow.proj yoneda P ⋙ yoneda)`, so this association will show up in the proof. -/ @[simps!] def flipFunctorToInterchange : (functorToInterchange A K).flip ≅ ((CostructuredArrow.proj yoneda A ⋙ yoneda) ⋙ (whiskeringLeft J Cᵒᵖ (Type u)).obj K) := Iso.refl _ /-- (Implementation) A natural isomorphism we will need to construct `iso`. -/ @[simps! -fullyApplied hom_app] noncomputable def isoAux : (CostructuredArrow.proj yoneda A ⋙ yoneda ⋙ (evaluation Cᵒᵖ (Type u)).obj (limit K)) ≅ ((coyoneda ⋙ (whiskeringLeft (CostructuredArrow yoneda A) C (Type u)).obj (CostructuredArrow.proj yoneda A)).obj (limit K)) := Iso.refl _ /-- (Implementation) The isomorphism that proves that `A` preserves finite limits. -/ noncomputable def iso [IsFiltered (CostructuredArrow yoneda A)] : A.obj (limit K) ≅ limit (K ⋙ A) := calc A.obj (limit K) ≅ (colimit (CostructuredArrow.proj yoneda A ⋙ yoneda)).obj (limit K) := (IsColimit.coconePointUniqueUpToIso (Presheaf.isColimitTautologicalCocone A) (colimit.isColimit _)).app _ _ ≅ colimit (((CostructuredArrow.proj yoneda A) ⋙ yoneda) ⋙ (evaluation _ _).obj (limit K)) := (colimitObjIsoColimitCompEvaluation _ _) _ ≅ colimit ((CostructuredArrow.proj yoneda A) ⋙ yoneda ⋙ (evaluation _ _).obj (limit K)) := HasColimit.isoOfNatIso (Functor.associator _ _ _) _ ≅ colimit ((coyoneda ⋙ (whiskeringLeft _ _ _).obj (CostructuredArrow.proj yoneda A)).obj (limit K)) := HasColimit.isoOfNatIso (isoAux A K) _ ≅ colimit (limit (K ⋙ (coyoneda ⋙ (whiskeringLeft _ _ _).obj (CostructuredArrow.proj _ _)))) := HasColimit.isoOfNatIso (preservesLimitIso _ _) _ ≅ colimit (limit (functorToInterchange A K)) := HasColimit.isoOfNatIso (HasLimit.isoOfNatIso (functorToInterchangeIso A K).symm) _ ≅ limit (colimit (functorToInterchange A K).flip) := colimitLimitIso _ _ ≅ limit (colimit ((CostructuredArrow.proj yoneda A ⋙ yoneda) ⋙ (whiskeringLeft _ _ _).obj K)) := HasLimit.isoOfNatIso (HasColimit.isoOfNatIso (flipFunctorToInterchange A K)) _ ≅ limit (K ⋙ colimit (CostructuredArrow.proj yoneda A ⋙ yoneda)) := HasLimit.isoOfNatIso (colimitCompWhiskeringLeftIsoCompColimit (CostructuredArrow.proj yoneda A ⋙ yoneda) K) _ ≅ limit (K ⋙ A) := HasLimit.isoOfNatIso (isoWhiskerLeft _ (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (Presheaf.isColimitTautologicalCocone A))) theorem iso_hom [IsFiltered (CostructuredArrow yoneda A)] : (iso A K).hom = limit.post K A := by -- We will have to use `ι_colimitLimitIso_limit_π` eventually, so let's start by -- transforming the goal into something from a colimit to a limit so that we can apply -- `limit.hom_ext` and `colimit.hom_ext`. dsimp [iso, -Iso.app_hom] simp only [Category.assoc] rw [Eq.comm, ← Iso.inv_comp_eq, ← Iso.inv_comp_eq] refine limit.hom_ext (fun j => colimit.hom_ext (fun i => ?_)) simp only [Category.assoc] -- `simp` is not too helpful here because we will need to apply `NatTrans.comp_app_assoc` -- backwards at certain points, so we rewrite the term manually. rw [HasLimit.isoOfNatIso_hom_π, HasLimit.isoOfNatIso_hom_π_assoc, limit.post_π, colimitObjIsoColimitCompEvaluation_ι_inv_assoc (CostructuredArrow.proj yoneda A ⋙ yoneda), Iso.app_inv, ← NatTrans.comp_app_assoc, colimit.comp_coconePointUniqueUpToIso_inv, Presheaf.tautologicalCocone_ι_app, HasColimit.isoOfNatIso_ι_hom_assoc, HasLimit.isoOfNatIso_hom_π_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, ι_colimitLimitIso_limit_π_assoc, isoAux_hom_app, ← NatTrans.comp_app_assoc, ← NatTrans.comp_app_assoc, Category.assoc, HasLimit.isoOfNatIso_hom_π, preservesLimitIso_hom_π_assoc, Iso.symm_hom, ← NatTrans.comp_app_assoc, HasColimit.isoOfNatIso_ι_hom, ← NatTrans.comp_app_assoc, Category.assoc, ι_colimitCompWhiskeringLeftIsoCompColimit_hom, NatTrans.comp_app, Category.assoc, isoWhiskerLeft_hom, NatTrans.comp_app, Category.assoc, ← NatTrans.comp_app, ← whiskerLeft_comp, colimit.comp_coconePointUniqueUpToIso_hom] have := i.hom.naturality (limit.π K j) dsimp only [yoneda_obj_obj, Functor.const_obj_obj] at this rw [← this] ext simp theorem isIso_post [IsFiltered (CostructuredArrow yoneda A)] : IsIso (limit.post K A) := iso_hom A K ▸ inferInstance end PreservesFiniteLimitsOfIsFilteredCostructuredArrowYonedaAux attribute [local instance] PreservesFiniteLimitsOfIsFilteredCostructuredArrowYonedaAux.isIso_post /-- If `C` is a small finitely cocomplete category and `A : Cᵒᵖ ⥤ Type u` is a presheaf such that `CostructuredArrow yoneda A` is filtered, then `A` preserves finite limits. One direction of Proposition 3.3.13 of [Kashiwara2006]. -/ lemma preservesFiniteLimits_of_isFiltered_costructuredArrow_yoneda [IsFiltered (CostructuredArrow yoneda A)] : PreservesFiniteLimits A where preservesFiniteLimits _ _ _ := ⟨fun {_} => preservesLimit_of_isIso_post _ _⟩ /-- If `C` is a small finitely cocomplete category and `A : Cᵒᵖ ⥤ Type u` is a presheaf, then `CostructuredArrow yoneda A` is filtered if and only if `A` preserves finite limits. Proposition 3.3.13 of [Kashiwara2006]. -/ theorem isFiltered_costructuredArrow_yoneda_iff_nonempty_preservesFiniteLimits : IsFiltered (CostructuredArrow yoneda A) ↔ PreservesFiniteLimits A := ⟨fun _ => preservesFiniteLimits_of_isFiltered_costructuredArrow_yoneda A, fun _ => isFiltered_costructuredArrow_yoneda_of_preservesFiniteLimits A⟩ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Over.lean
import Mathlib.CategoryTheory.Limits.Preserves.Filtered /-! # Forgetful functor from `Over X` preserves cofiltered limits Note that `Over.forget X : Over X ⥤ C` already preserves all colimits because it is a left adjoint. See `Mathlib/CategoryTheory/Adjunction/Over.lean` -/ namespace CategoryTheory.Limits variable {C : Type*} [Category C] attribute [local instance] IsFiltered.nonempty IsCofiltered.nonempty instance {X : C} : PreservesCofilteredLimitsOfSize (Over.forget X) := by refine ⟨fun J hJ hJ' ↦ ⟨fun {F} ↦ ⟨fun {c} hc ↦ ⟨.ofExistsUnique fun s ↦ ?_⟩⟩⟩⟩ obtain i := Nonempty.some (inferInstanceAs (Nonempty J)) let s' : Cone F := ⟨Over.mk (s.π.app i ≫ (F.obj i).hom), fun j ↦ Over.homMk (s.π.app j) (by obtain ⟨k, hik, hjk, -⟩ := IsCofilteredOrEmpty.cone_objs i j simp only [Functor.const_obj_obj, Over.mk_left, Over.mk_hom, ← s.w hjk, ← s.w hik] simp), fun j k e ↦ by ext; simpa using (s.w e).symm⟩ refine ⟨(hc.lift s').left, fun j ↦ congr($(hc.fac s' j).left), fun f hf ↦ ?_⟩ dsimp at hf exact congr($(hc.uniq s' (Over.homMk f (by simp [s', ← hf])) fun j ↦ Over.OverMorphism.ext (hf j)).left) instance {X : C} : PreservesFilteredColimitsOfSize (Under.forget X) := by refine ⟨fun J hJ hJ' ↦ ⟨fun {F} ↦ ⟨fun {c} hc ↦ ⟨.ofExistsUnique fun s ↦ ?_⟩⟩⟩⟩ obtain i := Nonempty.some (inferInstanceAs (Nonempty J)) let s' : Cocone F := ⟨Under.mk ((F.obj i).hom ≫ s.ι.app i), fun j ↦ Under.homMk (s.ι.app j) (by obtain ⟨k, hik, hjk, -⟩ := IsFilteredOrEmpty.cocone_objs i j simp only [Functor.const_obj_obj, Functor.id_obj, Under.mk_right, Under.mk_hom, ← s.w hjk, ← s.w hik] simp), fun j k e ↦ by ext; simpa using s.w e⟩ refine ⟨(hc.desc s').right, fun j ↦ congr($(hc.fac s' j).right), fun f hf ↦ ?_⟩ dsimp at hf exact congr($(hc.uniq s' (Under.homMk f (by simp [s', ← hf])) fun j ↦ Under.UnderMorphism.ext (hf j)).right) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Bifunctor.lean
import Mathlib.CategoryTheory.Limits.Fubini import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Preservations of limits for bifunctors Let `G : C₁ ⥤ C₂ ⥤ C` a functor. We introduce a class `PreservesLimit₂ K₁ K₂ G` that encodes the hypothesis that the curried functor `F : C₁ × C₂ ⥤ C` preserves limits of the diagram `K₁ × K₂ : J₁ × J₂ ⥤ C₁ × C₂`. We give a basic API to extract isomorphisms $\lim_{(j_1,j_2)} G(K_1(j_1), K_2(j_2)) \simeq G(\lim K_1, \lim K_2)$ out of this typeclass. -/ namespace CategoryTheory open Category Limits Functor variable {J₁ J₂ : Type*} [Category J₁] [Category J₂] {C₁ C₂ C : Type*} [Category C₁] [Category C₂] [Category C] /-- Given a bifunctor `G : C₁ ⥤ C₂ ⥤ C`, diagrams `K₁ : J₁ ⥤ C₁` and `K₂ : J₂ ⥤ C₂`, and cocones over these diagrams, `G.mapCocone₂ c₁ c₂` is the cocone over the diagram `J₁ × J₂ ⥤ C` obtained by applying `G` to both `c₁` and `c₂`. -/ @[simps!] def Functor.mapCocone₂ (G : C₁ ⥤ C₂ ⥤ C) {K₁ : J₁ ⥤ C₁} {K₂ : J₂ ⥤ C₂} (c₁ : Cocone K₁) (c₂ : Cocone K₂) : Cocone <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G) where pt := (G.obj c₁.pt).obj c₂.pt ι := { app := fun ⟨j₁, j₂⟩ ↦ (G.map <| c₁.ι.app j₁).app _ ≫ (G.obj _).map (c₂.ι.app j₂) naturality := by rintro ⟨j₁, j₂⟩ ⟨k₁, k₂⟩ ⟨f₁, f₂⟩ dsimp simp only [assoc, comp_id, NatTrans.naturality_assoc, ← Functor.map_comp, NatTrans.naturality, const_obj_map, const_obj_obj, ← NatTrans.comp_app_assoc, c₁.w] } /-- Given a bifunctor `G : C₁ ⥤ C₂ ⥤ C`, diagrams `K₁ : J₁ ⥤ C₁` and `K₂ : J₂ ⥤ C₂`, and cones over these diagrams, `G.mapCone₂ c₁ c₂` is the cone over the diagram `J₁ × J₂ ⥤ C` obtained by applying `G` to both `c₁` and `c₂`. -/ @[simps!] def Functor.mapCone₂ (G : C₁ ⥤ C₂ ⥤ C) {K₁ : J₁ ⥤ C₁} {K₂ : J₂ ⥤ C₂} (c₁ : Cone K₁) (c₂ : Cone K₂) : Cone <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G) where pt := (G.obj c₁.pt).obj c₂.pt π := { app := fun ⟨j₁, j₂⟩ ↦ (G.map <| c₁.π.app j₁).app _ ≫ (G.obj _).map (c₂.π.app j₂) naturality := by rintro ⟨j₁, j₂⟩ ⟨k₁, k₂⟩ ⟨f₁, f₂⟩ dsimp simp only [assoc, id_comp, NatTrans.naturality_assoc, ← Functor.map_comp, ← NatTrans.comp_app_assoc, c₁.w, c₂.w] } namespace Limits /-- A functor `PreservesColimit₂ K₁ K₂` if whenever `c₁` is a colimit cocone and `c₂` is a colimit cocone then `G.mapCocone₂ c₁ c₂` is a colimit cocone. This can be thought of as the data of an isomorphism $\mathrm{colim}_{(j_1,j_2)} G(K_1(j_1),K_2(j_2)) \simeq G(\mathrm{colim} K_1,\mathrm{colim} K_2)$. -/ class PreservesColimit₂ (K₁ : J₁ ⥤ C₁) (K₂ : J₂ ⥤ C₂) (G : C₁ ⥤ C₂ ⥤ C) : Prop where nonempty_isColimit_mapCocone₂ {c₁ : Cocone K₁} (hc₁ : IsColimit c₁) {c₂ : Cocone K₂} (hc₂ : IsColimit c₂) : Nonempty <| IsColimit <| G.mapCocone₂ c₁ c₂ /-- A functor `PreservesLimit₂ K₁ K₂` if whenever `c₁` is a limit cone and `c₂` is a limit cone then `G.mapCone₂ c₁ c₂` is a limit cone. This can be thought of as the data of an isomorphism $\lim_{(j_1,j_2)} G(K_1(j_1), K_2(j_2)) \simeq G(\lim K_1, \lim K_2)$. -/ class PreservesLimit₂ (K₁ : J₁ ⥤ C₁) (K₂ : J₂ ⥤ C₂) (G : C₁ ⥤ C₂ ⥤ C) : Prop where nonempty_isLimit_mapCone₂ {c₁ : Cone K₁} (hc₁ : IsLimit c₁) {c₂ : Cone K₂} (hc₂ : IsLimit c₂) : Nonempty <| IsLimit <| G.mapCone₂ c₁ c₂ variable {K₁ : J₁ ⥤ C₁} {K₂ : J₂ ⥤ C₂} (G : C₁ ⥤ C₂ ⥤ C) /-- If `PreservesColimit₂ K₁ K₂ G`, obtain that `G.mapCocone₂ c₁ c₂` is a colimit cocone whenever c₁ c₂ are colimit cocones. -/ noncomputable def isColimitOfPreserves₂ [PreservesColimit₂ K₁ K₂ G] {c₁ : Cocone K₁} (hc₁ : IsColimit c₁) {c₂ : Cocone K₂} (hc₂ : IsColimit c₂) : IsColimit (G.mapCocone₂ c₁ c₂) := PreservesColimit₂.nonempty_isColimit_mapCocone₂ hc₁ hc₂ |>.some /-- If `PreservesLimit₂ K₁ K₂ G`, obtain that `G.mapCone₂ c₁ c₂` is a limit cone whenever c₁ c₂ are limit cones. -/ noncomputable def isLimitOfPreserves₂ [PreservesLimit₂ K₁ K₂ G] {c₁ : Cone K₁} (hc₁ : IsLimit c₁) {c₂ : Cone K₂} (hc₂ : IsLimit c₂) : IsLimit (G.mapCone₂ c₁ c₂) := PreservesLimit₂.nonempty_isLimit_mapCone₂ hc₁ hc₂ |>.some instance [HasColimit K₁] [HasColimit K₂] [PreservesColimit₂ K₁ K₂ G] : HasColimit <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G) where exists_colimit := ⟨{ cocone := _ isColimit := PreservesColimit₂.nonempty_isColimit_mapCocone₂ (getColimitCocone K₁).isColimit (getColimitCocone K₂).isColimit |>.some }⟩ instance [HasLimit K₁] [HasLimit K₂] [PreservesLimit₂ K₁ K₂ G] : HasLimit <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G) where exists_limit := ⟨{ cone := _ isLimit := PreservesLimit₂.nonempty_isLimit_mapCone₂ (getLimitCone K₁).isLimit (getLimitCone K₂).isLimit|>.some }⟩ namespace PreservesColimit₂ variable [PreservesColimit₂ K₁ K₂ G] /-- Given a `PreservesColimit₂` instance, extract the isomorphism between a colimit of `uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G)` and `(G.obj c₁).obj c₂` where c₁ (resp. c₂) is a colimit of `K₁` (resp `K₂`). -/ noncomputable def isoObjCoconePointsOfIsColimit {c₁ : Cocone K₁} (hc₁ : IsColimit c₁) {c₂ : Cocone K₂} (hc₂ : IsColimit c₂) {c₃ : Cocone <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)} (hc₃ : IsColimit c₃) : (G.obj c₁.pt).obj c₂.pt ≅ c₃.pt := IsColimit.coconePointUniqueUpToIso (isColimitOfPreserves₂ G hc₁ hc₂) hc₃ section variable {c₁ : Cocone K₁} (hc₁ : IsColimit c₁) {c₂ : Cocone K₂} (hc₂ : IsColimit c₂) {c₃ : Cocone <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)} (hc₃ : IsColimit c₃) /-- Characterize the inverse direction of the isomorphism `PreservesColimit₂.isoObjCoconePointsOfIsColimit` w.r.t. the canonical maps to the colimit. -/ @[reassoc (attr := simp)] lemma ι_comp_isoObjConePointsOfIsColimit_inv (j : J₁ × J₂) : c₃.ι.app j ≫ (isoObjCoconePointsOfIsColimit G hc₁ hc₂ hc₃).inv = (G.map <| c₁.ι.app j.1).app (K₂.obj j.2) ≫ (G.obj c₁.pt).map (c₂.ι.app j.2) := by dsimp [isoObjCoconePointsOfIsColimit, Functor.mapCocone₂] cat_disch /-- Characterize the forward direction of the isomorphism `PreservesColimit₂.isoObjCoconePointsOfIsColimit` w.r.t. the canonical maps to the colimit. -/ @[reassoc (attr := simp)] lemma map_ι_comp_isoObjConePointsOfIsColimit_hom (j : J₁ × J₂) : (G.map (c₁.ι.app j.1)).app (K₂.obj j.2) ≫ (G.obj c₁.pt).map (c₂.ι.app j.2) ≫ (isoObjCoconePointsOfIsColimit G hc₁ hc₂ hc₃).hom = c₃.ι.app j := by rw [← Category.assoc, ← Iso.eq_comp_inv] simp end section variable (K₁ K₂) [HasColimit K₁] [HasColimit K₂] /-- Extract the isomorphism between `colim (uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G))` and `(G.obj (colim K₁)).obj (colim K₂)` from a `PreservesColimit₂` instance, provided the relevant colimits exist. -/ noncomputable def isoColimitUncurryWhiskeringLeft₂ : colimit (uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)) ≅ (G.obj <| colimit K₁).obj (colimit K₂) := isoObjCoconePointsOfIsColimit G (colimit.isColimit _) (colimit.isColimit _) (colimit.isColimit _) |>.symm /-- Characterize the forward direction of the isomorphism `PreservesColimit₂.isoColimitUncurryWhiskeringLeft₂` w.r.t. the canonical maps to the colimit. -/ @[reassoc (attr := simp)] lemma ι_comp_isoColimitUncurryWhiskeringLeft₂_hom (j : J₁ × J₂) : colimit.ι (uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)) j ≫ (PreservesColimit₂.isoColimitUncurryWhiskeringLeft₂ K₁ K₂ G).hom = (G.map <| colimit.ι K₁ j.1).app (K₂.obj j.2) ≫ (G.obj <| colimit K₁).map (colimit.ι K₂ j.2) := ι_comp_isoObjConePointsOfIsColimit_inv G (colimit.isColimit _) (colimit.isColimit _) (colimit.isColimit _) j /-- Characterize the forward direction of the isomorphism `PreservesColimit₂.isoColimitUncurryWhiskeringLeft₂` w.r.t. the canonical maps to the colimit. -/ @[reassoc (attr := simp)] lemma map_ι_comp_isoColimitUncurryWhiskeringLeft₂_inv (j : J₁ × J₂) : (G.map (colimit.ι K₁ j.1)).app (K₂.obj j.2) ≫ (G.obj <| colimit K₁).map (colimit.ι K₂ j.2) ≫ (PreservesColimit₂.isoColimitUncurryWhiskeringLeft₂ K₁ K₂ G).inv = colimit.ι (uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)) j := map_ι_comp_isoObjConePointsOfIsColimit_hom G (colimit.isColimit _) (colimit.isColimit _) (colimit.isColimit _) j end /-- If a bifunctor preserves separately colimits of `K₁` in the first variable and colimits of `K₂` in the second variable, then it preserves colimit of the pair `K₁, K₂`. -/ instance of_preservesColimits_in_each_variable [∀ x : C₂, PreservesColimit K₁ (G.flip.obj x)] [∀ x : C₁, PreservesColimit K₂ (G.obj x)] : PreservesColimit₂ K₁ K₂ G where nonempty_isColimit_mapCocone₂ {c₁} hc₁ {c₂} hc₂ := let Q₀ : DiagramOfCocones (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G) := { obj j₁ := G.obj (K₁.obj j₁) |>.mapCocone c₂ map f := { hom := G.map (K₁.map f)|>.app c₂.pt }} let P : ∀ j₁, IsColimit (Q₀.obj j₁) := fun j ↦ isColimitOfPreserves _ hc₂ let E₀ : Q₀.coconePoints ≅ K₁ ⋙ G.flip.obj c₂.pt := NatIso.ofComponents (fun _ ↦ Iso.refl _) let E₁ : (Cocones.precompose E₀.hom).obj (coconeOfCoconeUncurry P <| G.mapCocone₂ c₁ c₂) ≅ (G.flip.obj c₂.pt).mapCocone c₁ := Cocones.ext (Iso.refl _) (fun j₁ => by dsimp [E₀, Q₀] simp only [id_comp, comp_id] let s : Cocone (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G |>.obj j₁) := ?_ change (P j₁).desc s = _ symm apply (P j₁).hom_ext intro j₂ haveI := (P j₁).fac s j₂ simp only [Functor.mapCocone_pt, Functor.const_obj_obj, Functor.mapCocone_ι_app, Q₀, s] at this simp only [Functor.mapCocone_pt, Functor.const_obj_obj, Functor.mapCocone_ι_app, NatTrans.naturality, this, Q₀, s]) ⟨IsColimit.ofCoconeUncurry P <| IsColimit.precomposeHomEquiv E₀ _ <| IsColimit.ofIsoColimit (isColimitOfPreserves _ hc₁) E₁.symm⟩ theorem of_preservesColimit₂_flip : PreservesColimit₂ K₂ K₁ G.flip where nonempty_isColimit_mapCocone₂ {c₁} hc₁ {c₂} hc₂ := by constructor let E₀ : uncurry.obj (whiskeringLeft₂ C|>.obj K₂|>.obj K₁|>.obj G.flip) ≅ uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G).flip := Iso.refl _ let E₁ : uncurry.obj (whiskeringLeft₂ C|>.obj K₂|>.obj K₁|>.obj G.flip) ≅ Prod.swap _ _ ⋙ uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G) := E₀ ≪≫ uncurryObjFlip _ refine IsColimit.precomposeInvEquiv E₁ _ ?_ apply IsColimit.ofWhiskerEquivalence (e := Prod.braiding _ _) refine IsColimit.equivOfNatIsoOfIso (Iso.refl _) (G.mapCocone₂ c₂ c₁) _ ?_ |>.toFun <| isColimitOfPreserves₂ G hc₂ hc₁ exact Cocones.ext (Iso.refl _) (fun ⟨j₁, j₂⟩ ↦ by simp [E₁, E₀]) end PreservesColimit₂ namespace PreservesLimit₂ variable [PreservesLimit₂ K₁ K₂ G] /-- Given a `PreservesLimit₂` instance, extract the isomorphism between a limit of `uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G)` and `(G.obj c₁).obj c₂` where c₁ (resp. c₂) is a limit of `K₁` (resp `K₂`). -/ noncomputable def isoObjConePointsOfIsLimit {c₁ : Cone K₁} (hc₁ : IsLimit c₁) {c₂ : Cone K₂} (hc₂ : IsLimit c₂) {c₃ : Cone <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)} (hc₃ : IsLimit c₃) : (G.obj c₁.pt).obj c₂.pt ≅ c₃.pt := IsLimit.conePointUniqueUpToIso (isLimitOfPreserves₂ G hc₁ hc₂) hc₃ section variable {c₁ : Cone K₁} (hc₁ : IsLimit c₁) {c₂ : Cone K₂} (hc₂ : IsLimit c₂) {c₃ : Cone <| uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)} (hc₃ : IsLimit c₃) /-- Characterize the forward direction of the isomorphism `PreservesLimit₂.isoObjConePointsOfIsLimit` w.r.t. the canonical maps to the limit. -/ @[reassoc (attr := simp)] lemma isoObjConePointsOfIsLimit_hom_comp_π (j : J₁ × J₂) : (isoObjConePointsOfIsLimit G hc₁ hc₂ hc₃).hom ≫ c₃.π.app j = (G.map <| c₁.π.app j.1).app c₂.pt ≫ (G.obj <| K₁.obj j.1).map (c₂.π.app j.2) := by dsimp [isoObjConePointsOfIsLimit, Functor.mapCocone₂] cat_disch /-- Characterize the inverse direction of the isomorphism `PreservesLimit₂.isoObjConePointsOfIsLimit` w.r.t. the canonical maps to the limit. -/ @[reassoc (attr := simp)] lemma isoObjConePointsOfIsColimit_inv_comp_map_π (j : J₁ × J₂) : (isoObjConePointsOfIsLimit G hc₁ hc₂ hc₃).inv ≫ (G.map (c₁.π.app j.1)).app c₂.pt ≫ (G.obj <| K₁.obj j.1).map (c₂.π.app j.2) = c₃.π.app j := by rw [Iso.inv_comp_eq] simp end section variable (K₁) (K₂) [HasLimit K₁] [HasLimit K₂] /-- Extract the isomorphism between `colim (uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G))` and `(G.obj (colim K₁)).obj (colim K₂)` from a `PreservesLimit₂` instance, provided the relevant limits exist. -/ noncomputable def isoLimitUncurryWhiskeringLeft₂ : limit (uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)) ≅ (G.obj <| limit K₁).obj (limit K₂) := isoObjConePointsOfIsLimit G (limit.isLimit _) (limit.isLimit _) (limit.isLimit _) |>.symm /-- Characterize the inverse direction of the isomorphism `PreservesLimit₂.isoLimitUncurryWhiskeringLeft₂` w.r.t. the canonical maps to the limit. -/ @[reassoc (attr := simp)] lemma isoLimitUncurryWhiskeringLeft₂_inv_comp_π (j : J₁ × J₂) : (PreservesLimit₂.isoLimitUncurryWhiskeringLeft₂ K₁ K₂ G).inv ≫ limit.π (uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)) j = (G.map <| limit.π K₁ j.1).app (limit K₂) ≫ (G.obj <| K₁.obj j.1).map (limit.π K₂ j.2) := isoObjConePointsOfIsLimit_hom_comp_π G (limit.isLimit _) (limit.isLimit _) (limit.isLimit _) _ /-- Characterize the forward direction of the isomorphism `PreservesLimit₂.isoLimitUncurryWhiskeringLeft₂` w.r.t. the canonical maps to the limit. -/ @[reassoc (attr := simp)] lemma isoLimitUncurryWhiskeringLeft₂_hom_comp_map_π (j : J₁ × J₂) : (PreservesLimit₂.isoLimitUncurryWhiskeringLeft₂ K₁ K₂ G).hom ≫ (G.map (limit.π K₁ j.1)).app (limit K₂) ≫ (G.obj <| K₁.obj j.1).map (limit.π K₂ j.2) = limit.π (uncurry.obj (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G)) j := isoObjConePointsOfIsColimit_inv_comp_map_π G (limit.isLimit _) (limit.isLimit _) (limit.isLimit _) _ end /-- If a bifunctor preserves separately limits of `K₁` in the first variable and limits of `K₂` in the second variable, then it preserves colimit of the pair of cones `K₁, K₂`. -/ instance of_preservesLimits_in_each_variable [∀ x : C₂, PreservesLimit K₁ (G.flip.obj x)] [∀ x : C₁, PreservesLimit K₂ (G.obj x)] : PreservesLimit₂ K₁ K₂ G where nonempty_isLimit_mapCone₂ {c₁} hc₁ {c₂} hc₂ := let Q₀ : DiagramOfCones (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G) := { obj j₁ := G.obj (K₁.obj j₁) |>.mapCone c₂ map f := { hom := G.map (K₁.map f)|>.app c₂.pt }} let P : ∀ j₁, IsLimit (Q₀.obj j₁) := fun _ => isLimitOfPreserves _ hc₂ let E₀ : Q₀.conePoints ≅ K₁ ⋙ G.flip.obj c₂.pt := NatIso.ofComponents (fun _ ↦ Iso.refl _) let E₁ : (Cones.postcompose E₀.hom).obj (coneOfConeUncurry P <| G.mapCone₂ c₁ c₂) ≅ (G.flip.obj c₂.pt).mapCone c₁ := Cones.ext (Iso.refl _) (fun j₁ => by dsimp [E₀, Q₀] simp only [id_comp, comp_id] let s : Cone (whiskeringLeft₂ C |>.obj K₁ |>.obj K₂ |>.obj G |>.obj j₁) := ?_ change (P j₁).lift s = _ symm apply (P j₁).hom_ext intro j₂ haveI := (P j₁).fac s j₂ simp only [whiskeringLeft₂_obj_obj_obj_obj_obj, Functor.mapCone_pt, Functor.mapCone_π_app, s, Q₀] at this simp only [whiskeringLeft₂_obj_obj_obj_obj_obj, Functor.mapCone_pt, Functor.mapCone_π_app, this, Q₀, s]) ⟨IsLimit.ofConeOfConeUncurry P <| IsLimit.postcomposeHomEquiv E₀ _ <| IsLimit.ofIsoLimit (isLimitOfPreserves _ hc₁) E₁.symm⟩ theorem of_preservesLimit₂_flip : PreservesLimit₂ K₂ K₁ G.flip where nonempty_isLimit_mapCone₂ {c₁} hc₁ {c₂} hc₂ := by constructor let E₀ : uncurry.obj (whiskeringLeft₂ C|>.obj K₂|>.obj K₁|>.obj G.flip) ≅ uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G).flip := Iso.refl _ let E₁ : uncurry.obj (whiskeringLeft₂ C|>.obj K₂|>.obj K₁|>.obj G.flip) ≅ Prod.swap _ _ ⋙ uncurry.obj (whiskeringLeft₂ C|>.obj K₁|>.obj K₂|>.obj G) := E₀ ≪≫ uncurryObjFlip _ refine IsLimit.postcomposeHomEquiv E₁ _ ?_ apply IsLimit.ofWhiskerEquivalence (e := Prod.braiding _ _) refine IsLimit.equivOfNatIsoOfIso (Iso.refl _) (G.mapCone₂ c₂ c₁) _ ?_ |>.toFun <| isLimitOfPreserves₂ G hc₂ hc₁ exact Cones.ext (Iso.refl _) (fun ⟨j₁, j₂⟩ ↦ by simp [E₁, E₀]) end PreservesLimit₂ end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Basic.lean
import Mathlib.CategoryTheory.Limits.HasLimits /-! # Preservation and reflection of (co)limits. There are various distinct notions of "preserving limits". The one we aim to capture here is: A functor F : C ⥤ D "preserves limits" if it sends every limit cone in C to a limit cone in D. Informally, F preserves all the limits which exist in C. Note that: * Of course, we do not want to require F to *strictly* take chosen limit cones of C to chosen limit cones of D. Indeed, the above definition makes no reference to a choice of limit cones so it makes sense without any conditions on C or D. * Some diagrams in C may have no limit. In this case, there is no condition on the behavior of F on such diagrams. There are other notions (such as "flat functor") which impose conditions also on diagrams in C with no limits, but these are not considered here. In order to be able to express the property of preserving limits of a certain form, we say that a functor F preserves the limit of a diagram K if F sends every limit cone on K to a limit cone. This is vacuously satisfied when K does not admit a limit, which is consistent with the above definition of "preserves limits". -/ open CategoryTheory noncomputable section namespace CategoryTheory.Limits -- morphism levels before object levels. See note [category theory universes]. universe w' w₂' w w₂ v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {J : Type w} [Category.{w'} J] {K : J ⥤ C} /-- A functor `F` preserves limits of `K` (written as `PreservesLimit K F`) if `F` maps any limit cone over `K` to a limit cone. -/ class PreservesLimit (K : J ⥤ C) (F : C ⥤ D) : Prop where preserves {c : Cone K} (hc : IsLimit c) : Nonempty (IsLimit (F.mapCone c)) /-- A functor `F` preserves colimits of `K` (written as `PreservesColimit K F`) if `F` maps any colimit cocone over `K` to a colimit cocone. -/ class PreservesColimit (K : J ⥤ C) (F : C ⥤ D) : Prop where preserves {c : Cocone K} (hc : IsColimit c) : Nonempty (IsColimit (F.mapCocone c)) /-- We say that `F` preserves limits of shape `J` if `F` preserves limits for every diagram `K : J ⥤ C`, i.e., `F` maps limit cones over `K` to limit cones. -/ class PreservesLimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Prop where preservesLimit : ∀ {K : J ⥤ C}, PreservesLimit K F := by infer_instance /-- We say that `F` preserves colimits of shape `J` if `F` preserves colimits for every diagram `K : J ⥤ C`, i.e., `F` maps colimit cocones over `K` to colimit cocones. -/ class PreservesColimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Prop where preservesColimit : ∀ {K : J ⥤ C}, PreservesColimit K F := by infer_instance -- This should be used with explicit universe variables. /-- `PreservesLimitsOfSize.{v u} F` means that `F` sends all limit cones over any diagram `J ⥤ C` to limit cones, where `J : Type u` with `[Category.{v} J]`. -/ @[nolint checkUnivs, pp_with_univ] class PreservesLimitsOfSize (F : C ⥤ D) : Prop where preservesLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], PreservesLimitsOfShape J F := by infer_instance /-- We say that `F` preserves (small) limits if it sends small limit cones over any diagram to limit cones. -/ abbrev PreservesLimits (F : C ⥤ D) := PreservesLimitsOfSize.{v₂, v₂} F -- This should be used with explicit universe variables. /-- `PreservesColimitsOfSize.{v u} F` means that `F` sends all colimit cocones over any diagram `J ⥤ C` to colimit cocones, where `J : Type u` with `[Category.{v} J]`. -/ @[nolint checkUnivs, pp_with_univ] class PreservesColimitsOfSize (F : C ⥤ D) : Prop where preservesColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], PreservesColimitsOfShape J F := by infer_instance /-- We say that `F` preserves (small) limits if it sends small limit cones over any diagram to limit cones. -/ abbrev PreservesColimits (F : C ⥤ D) := PreservesColimitsOfSize.{v₂, v₂} F -- see Note [lower instance priority] attribute [instance 100] PreservesLimitsOfShape.preservesLimit PreservesLimitsOfSize.preservesLimitsOfShape PreservesColimitsOfShape.preservesColimit PreservesColimitsOfSize.preservesColimitsOfShape -- see Note [lower instance priority] /-- A convenience function for `PreservesLimit`, which takes the functor as an explicit argument to guide typeclass resolution. -/ def isLimitOfPreserves (F : C ⥤ D) {c : Cone K} (t : IsLimit c) [PreservesLimit K F] : IsLimit (F.mapCone c) := (PreservesLimit.preserves t).some /-- A convenience function for `PreservesColimit`, which takes the functor as an explicit argument to guide typeclass resolution. -/ def isColimitOfPreserves (F : C ⥤ D) {c : Cocone K} (t : IsColimit c) [PreservesColimit K F] : IsColimit (F.mapCocone c) := (PreservesColimit.preserves t).some instance preservesLimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (PreservesLimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance preservesColimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (PreservesColimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance preservesLimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (PreservesLimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance preservesColimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (PreservesColimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance preservesLimitsOfSize_subsingleton (F : C ⥤ D) : Subsingleton (PreservesLimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance preservesColimitsOfSize_subsingleton (F : C ⥤ D) : Subsingleton (PreservesColimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance id_preservesLimitsOfSize : PreservesLimitsOfSize.{w', w} (𝟭 C) where preservesLimitsOfShape {J} 𝒥 := { preservesLimit := fun {K} => ⟨fun {c} h => ⟨fun s => h.lift ⟨s.pt, fun j => s.π.app j, fun _ _ f => s.π.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intro s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intro s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } instance id_preservesColimitsOfSize : PreservesColimitsOfSize.{w', w} (𝟭 C) where preservesColimitsOfShape {J} 𝒥 := { preservesColimit := fun {K} => ⟨fun {c} h => ⟨fun s => h.desc ⟨s.pt, fun j => s.ι.app j, fun _ _ f => s.ι.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intro s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intro s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } instance [HasLimit K] {F : C ⥤ D} [PreservesLimit K F] : HasLimit (K ⋙ F) where exists_limit := ⟨_, isLimitOfPreserves F (limit.isLimit K)⟩ instance [HasColimit K] {F : C ⥤ D} [PreservesColimit K F] : HasColimit (K ⋙ F) where exists_colimit := ⟨_, isColimitOfPreserves F (colimit.isColimit K)⟩ section variable {E : Type u₃} [ℰ : Category.{v₃} E] variable (F : C ⥤ D) (G : D ⥤ E) instance comp_preservesLimit [PreservesLimit K F] [PreservesLimit (K ⋙ F) G] : PreservesLimit K (F ⋙ G) where preserves hc := ⟨isLimitOfPreserves G (isLimitOfPreserves F hc)⟩ instance comp_preservesLimitsOfShape [PreservesLimitsOfShape J F] [PreservesLimitsOfShape J G] : PreservesLimitsOfShape J (F ⋙ G) where instance comp_preservesLimits [PreservesLimitsOfSize.{w', w} F] [PreservesLimitsOfSize.{w', w} G] : PreservesLimitsOfSize.{w', w} (F ⋙ G) where instance comp_preservesColimit [PreservesColimit K F] [PreservesColimit (K ⋙ F) G] : PreservesColimit K (F ⋙ G) where preserves hc := ⟨isColimitOfPreserves G (isColimitOfPreserves F hc)⟩ instance comp_preservesColimitsOfShape [PreservesColimitsOfShape J F] [PreservesColimitsOfShape J G] : PreservesColimitsOfShape J (F ⋙ G) where instance comp_preservesColimits [PreservesColimitsOfSize.{w', w} F] [PreservesColimitsOfSize.{w', w} G] : PreservesColimitsOfSize.{w', w} (F ⋙ G) where end /-- If F preserves one limit cone for the diagram K, then it preserves any limit cone for K. -/ lemma preservesLimit_of_preserves_limit_cone {F : C ⥤ D} {t : Cone K} (h : IsLimit t) (hF : IsLimit (F.mapCone t)) : PreservesLimit K F where preserves h' := ⟨IsLimit.ofIsoLimit hF (Functor.mapIso _ (IsLimit.uniqueUpToIso h h'))⟩ /-- Transfer preservation of limits along a natural isomorphism in the diagram. -/ lemma preservesLimit_of_iso_diagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [PreservesLimit K₁ F] : PreservesLimit K₂ F where preserves {c} t := ⟨by apply IsLimit.postcomposeInvEquiv (Functor.isoWhiskerRight h F :) _ _ have := (IsLimit.postcomposeInvEquiv h c).symm t apply IsLimit.ofIsoLimit (isLimitOfPreserves F this) exact Cones.ext (Iso.refl _)⟩ /-- Transfer preservation of a limit along a natural isomorphism in the functor. -/ lemma preservesLimit_of_natIso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [PreservesLimit K F] : PreservesLimit K G where preserves t := ⟨IsLimit.mapConeEquiv h (isLimitOfPreserves F t)⟩ /-- Transfer preservation of limits of shape along a natural isomorphism in the functor. -/ lemma preservesLimitsOfShape_of_natIso {F G : C ⥤ D} (h : F ≅ G) [PreservesLimitsOfShape J F] : PreservesLimitsOfShape J G where preservesLimit {K} := preservesLimit_of_natIso K h /-- Transfer preservation of limits along a natural isomorphism in the functor. -/ lemma preservesLimits_of_natIso {F G : C ⥤ D} (h : F ≅ G) [PreservesLimitsOfSize.{w, w'} F] : PreservesLimitsOfSize.{w, w'} G where preservesLimitsOfShape := preservesLimitsOfShape_of_natIso h /-- Transfer preservation of limits along an equivalence in the shape. -/ lemma preservesLimitsOfShape_of_equiv {J' : Type w₂} [Category.{w₂'} J'] (e : J ≌ J') (F : C ⥤ D) [PreservesLimitsOfShape J F] : PreservesLimitsOfShape J' F where preservesLimit {K} := { preserves := fun {c} t => ⟨by let equ := e.invFunIdAssoc (K ⋙ F) have := (isLimitOfPreserves F (t.whiskerEquivalence e)).whiskerEquivalence e.symm apply ((IsLimit.postcomposeHomEquiv equ _).symm this).ofIsoLimit refine Cones.ext (Iso.refl _) fun j => ?_ simp [equ, ← Functor.map_comp]⟩ } /-- A functor preserving larger limits also preserves smaller limits. -/ lemma preservesLimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [PreservesLimitsOfSize.{w', w₂'} F] : PreservesLimitsOfSize.{w, w₂} F where preservesLimitsOfShape {J} := preservesLimitsOfShape_of_equiv ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm F /-- `PreservesLimitsOfSize_shrink.{w w'} F` tries to obtain `PreservesLimitsOfSize.{w w'} F` from some other `PreservesLimitsOfSize F`. -/ lemma preservesLimitsOfSize_shrink (F : C ⥤ D) [PreservesLimitsOfSize.{max w w₂, max w' w₂'} F] : PreservesLimitsOfSize.{w, w'} F := preservesLimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Preserving limits at any universe level implies preserving limits in universe `0`. -/ lemma preservesSmallestLimits_of_preservesLimits (F : C ⥤ D) [PreservesLimitsOfSize.{v₃, u₃} F] : PreservesLimitsOfSize.{0, 0} F := preservesLimitsOfSize_shrink F /-- If F preserves one colimit cocone for the diagram K, then it preserves any colimit cocone for K. -/ lemma preservesColimit_of_preserves_colimit_cocone {F : C ⥤ D} {t : Cocone K} (h : IsColimit t) (hF : IsColimit (F.mapCocone t)) : PreservesColimit K F := ⟨fun h' => ⟨IsColimit.ofIsoColimit hF (Functor.mapIso _ (IsColimit.uniqueUpToIso h h'))⟩⟩ /-- Transfer preservation of colimits along a natural isomorphism in the shape. -/ lemma preservesColimit_of_iso_diagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [PreservesColimit K₁ F] : PreservesColimit K₂ F where preserves {c} t := ⟨by apply IsColimit.precomposeHomEquiv (Functor.isoWhiskerRight h F :) _ _ have := (IsColimit.precomposeHomEquiv h c).symm t apply IsColimit.ofIsoColimit (isColimitOfPreserves F this) exact Cocones.ext (Iso.refl _)⟩ /-- Transfer preservation of a colimit along a natural isomorphism in the functor. -/ lemma preservesColimit_of_natIso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [PreservesColimit K F] : PreservesColimit K G where preserves t := ⟨IsColimit.mapCoconeEquiv h (isColimitOfPreserves F t)⟩ /-- Transfer preservation of colimits of shape along a natural isomorphism in the functor. -/ lemma preservesColimitsOfShape_of_natIso {F G : C ⥤ D} (h : F ≅ G) [PreservesColimitsOfShape J F] : PreservesColimitsOfShape J G where preservesColimit {K} := preservesColimit_of_natIso K h /-- Transfer preservation of colimits along a natural isomorphism in the functor. -/ lemma preservesColimits_of_natIso {F G : C ⥤ D} (h : F ≅ G) [PreservesColimitsOfSize.{w, w'} F] : PreservesColimitsOfSize.{w, w'} G where preservesColimitsOfShape {_J} _𝒥₁ := preservesColimitsOfShape_of_natIso h /-- Transfer preservation of colimits along an equivalence in the shape. -/ lemma preservesColimitsOfShape_of_equiv {J' : Type w₂} [Category.{w₂'} J'] (e : J ≌ J') (F : C ⥤ D) [PreservesColimitsOfShape J F] : PreservesColimitsOfShape J' F where preservesColimit {K} := { preserves := fun {c} t => ⟨by let equ := e.invFunIdAssoc (K ⋙ F) have := (isColimitOfPreserves F (t.whiskerEquivalence e)).whiskerEquivalence e.symm apply ((IsColimit.precomposeInvEquiv equ _).symm this).ofIsoColimit refine Cocones.ext (Iso.refl _) fun j => ?_ simp [equ, ← Functor.map_comp]⟩ } /-- A functor preserving larger colimits also preserves smaller colimits. -/ lemma preservesColimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [PreservesColimitsOfSize.{w', w₂'} F] : PreservesColimitsOfSize.{w, w₂} F where preservesColimitsOfShape {J} := preservesColimitsOfShape_of_equiv ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm F /-- `PreservesColimitsOfSize_shrink.{w w'} F` tries to obtain `PreservesColimitsOfSize.{w w'} F` from some other `PreservesColimitsOfSize F`. -/ lemma preservesColimitsOfSize_shrink (F : C ⥤ D) [PreservesColimitsOfSize.{max w w₂, max w' w₂'} F] : PreservesColimitsOfSize.{w, w'} F := preservesColimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Preserving colimits at any universe implies preserving colimits at universe `0`. -/ lemma preservesSmallestColimits_of_preservesColimits (F : C ⥤ D) [PreservesColimitsOfSize.{v₃, u₃} F] : PreservesColimitsOfSize.{0, 0} F := preservesColimitsOfSize_shrink F /-- A functor `F : C ⥤ D` reflects limits for `K : J ⥤ C` if whenever the image of a cone over `K` under `F` is a limit cone in `D`, the cone was already a limit cone in `C`. Note that we do not assume a priori that `D` actually has any limits. -/ class ReflectsLimit (K : J ⥤ C) (F : C ⥤ D) : Prop where reflects {c : Cone K} (hc : IsLimit (F.mapCone c)) : Nonempty (IsLimit c) /-- A functor `F : C ⥤ D` reflects colimits for `K : J ⥤ C` if whenever the image of a cocone over `K` under `F` is a colimit cocone in `D`, the cocone was already a colimit cocone in `C`. Note that we do not assume a priori that `D` actually has any colimits. -/ class ReflectsColimit (K : J ⥤ C) (F : C ⥤ D) : Prop where reflects {c : Cocone K} (hc : IsColimit (F.mapCocone c)) : Nonempty (IsColimit c) /-- A functor `F : C ⥤ D` reflects limits of shape `J` if whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone in `D`, the cone was already a limit cone in `C`. Note that we do not assume a priori that `D` actually has any limits. -/ class ReflectsLimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Prop where reflectsLimit : ∀ {K : J ⥤ C}, ReflectsLimit K F := by infer_instance /-- A functor `F : C ⥤ D` reflects colimits of shape `J` if whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit cocone in `D`, the cocone was already a colimit cocone in `C`. Note that we do not assume a priori that `D` actually has any colimits. -/ class ReflectsColimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Prop where reflectsColimit : ∀ {K : J ⥤ C}, ReflectsColimit K F := by infer_instance -- This should be used with explicit universe variables. /-- A functor `F : C ⥤ D` reflects limits if whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone in `D`, the cone was already a limit cone in `C`. Note that we do not assume a priori that `D` actually has any limits. -/ @[nolint checkUnivs, pp_with_univ] class ReflectsLimitsOfSize (F : C ⥤ D) : Prop where reflectsLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], ReflectsLimitsOfShape J F := by infer_instance /-- A functor `F : C ⥤ D` reflects (small) limits if whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone in `D`, the cone was already a limit cone in `C`. Note that we do not assume a priori that `D` actually has any limits. -/ abbrev ReflectsLimits (F : C ⥤ D) := ReflectsLimitsOfSize.{v₂, v₂} F -- This should be used with explicit universe variables. /-- A functor `F : C ⥤ D` reflects colimits if whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit cocone in `D`, the cocone was already a colimit cocone in `C`. Note that we do not assume a priori that `D` actually has any colimits. -/ @[nolint checkUnivs, pp_with_univ] class ReflectsColimitsOfSize (F : C ⥤ D) : Prop where reflectsColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], ReflectsColimitsOfShape J F := by infer_instance /-- A functor `F : C ⥤ D` reflects (small) colimits if whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit cocone in `D`, the cocone was already a colimit cocone in `C`. Note that we do not assume a priori that `D` actually has any colimits. -/ abbrev ReflectsColimits (F : C ⥤ D) := ReflectsColimitsOfSize.{v₂, v₂} F /-- A convenience function for `ReflectsLimit`, which takes the functor as an explicit argument to guide typeclass resolution. -/ def isLimitOfReflects (F : C ⥤ D) {c : Cone K} (t : IsLimit (F.mapCone c)) [ReflectsLimit K F] : IsLimit c := (ReflectsLimit.reflects t).some /-- A convenience function for `ReflectsColimit`, which takes the functor as an explicit argument to guide typeclass resolution. -/ def isColimitOfReflects (F : C ⥤ D) {c : Cocone K} (t : IsColimit (F.mapCocone c)) [ReflectsColimit K F] : IsColimit c := (ReflectsColimit.reflects t).some instance reflectsLimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (ReflectsLimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance reflectsColimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (ReflectsColimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance reflectsLimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (ReflectsLimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance reflectsColimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (ReflectsColimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance reflects_limits_subsingleton (F : C ⥤ D) : Subsingleton (ReflectsLimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! instance reflects_colimits_subsingleton (F : C ⥤ D) : Subsingleton (ReflectsColimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr! -- see Note [lower instance priority] instance (priority := 100) reflectsLimit_of_reflectsLimitsOfShape (K : J ⥤ C) (F : C ⥤ D) [ReflectsLimitsOfShape J F] : ReflectsLimit K F := ReflectsLimitsOfShape.reflectsLimit -- see Note [lower instance priority] instance (priority := 100) reflectsColimit_of_reflectsColimitsOfShape (K : J ⥤ C) (F : C ⥤ D) [ReflectsColimitsOfShape J F] : ReflectsColimit K F := ReflectsColimitsOfShape.reflectsColimit -- see Note [lower instance priority] instance (priority := 100) reflectsLimitsOfShape_of_reflectsLimits (J : Type w) [Category.{w'} J] (F : C ⥤ D) [ReflectsLimitsOfSize.{w', w} F] : ReflectsLimitsOfShape J F := ReflectsLimitsOfSize.reflectsLimitsOfShape -- see Note [lower instance priority] instance (priority := 100) reflectsColimitsOfShape_of_reflectsColimits (J : Type w) [Category.{w'} J] (F : C ⥤ D) [ReflectsColimitsOfSize.{w', w} F] : ReflectsColimitsOfShape J F := ReflectsColimitsOfSize.reflectsColimitsOfShape instance id_reflectsLimits : ReflectsLimitsOfSize.{w, w'} (𝟭 C) where reflectsLimitsOfShape {J} 𝒥 := { reflectsLimit := fun {K} => ⟨fun {c} h => ⟨fun s => h.lift ⟨s.pt, fun j => s.π.app j, fun _ _ f => s.π.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intro s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intro s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } instance id_reflectsColimits : ReflectsColimitsOfSize.{w, w'} (𝟭 C) where reflectsColimitsOfShape {J} 𝒥 := { reflectsColimit := fun {K} => ⟨fun {c} h => ⟨fun s => h.desc ⟨s.pt, fun j => s.ι.app j, fun _ _ f => s.ι.naturality f⟩, by cases K; rcases c with ⟨_, _, _⟩; intro s j; cases s; exact h.fac _ j, by cases K; rcases c with ⟨_, _, _⟩; intro s m w; rcases s with ⟨_, _, _⟩; exact h.uniq _ m w⟩⟩ } section variable {E : Type u₃} [ℰ : Category.{v₃} E] variable (F : C ⥤ D) (G : D ⥤ E) instance comp_reflectsLimit [ReflectsLimit K F] [ReflectsLimit (K ⋙ F) G] : ReflectsLimit K (F ⋙ G) := ⟨fun h => ReflectsLimit.reflects (isLimitOfReflects G h)⟩ instance comp_reflectsLimitsOfShape [ReflectsLimitsOfShape J F] [ReflectsLimitsOfShape J G] : ReflectsLimitsOfShape J (F ⋙ G) where instance comp_reflectsLimits [ReflectsLimitsOfSize.{w', w} F] [ReflectsLimitsOfSize.{w', w} G] : ReflectsLimitsOfSize.{w', w} (F ⋙ G) where instance comp_reflectsColimit [ReflectsColimit K F] [ReflectsColimit (K ⋙ F) G] : ReflectsColimit K (F ⋙ G) := ⟨fun h => ReflectsColimit.reflects (isColimitOfReflects G h)⟩ instance comp_reflectsColimitsOfShape [ReflectsColimitsOfShape J F] [ReflectsColimitsOfShape J G] : ReflectsColimitsOfShape J (F ⋙ G) where instance comp_reflectsColimits [ReflectsColimitsOfSize.{w', w} F] [ReflectsColimitsOfSize.{w', w} G] : ReflectsColimitsOfSize.{w', w} (F ⋙ G) where /-- If `F ⋙ G` preserves limits for `K`, and `G` reflects limits for `K ⋙ F`, then `F` preserves limits for `K`. -/ lemma preservesLimit_of_reflects_of_preserves [PreservesLimit K (F ⋙ G)] [ReflectsLimit (K ⋙ F) G] : PreservesLimit K F := ⟨fun h => ⟨by apply isLimitOfReflects G apply isLimitOfPreserves (F ⋙ G) h⟩⟩ /-- If `F ⋙ G` preserves limits of shape `J` and `G` reflects limits of shape `J`, then `F` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_of_reflects_of_preserves [PreservesLimitsOfShape J (F ⋙ G)] [ReflectsLimitsOfShape J G] : PreservesLimitsOfShape J F where preservesLimit := preservesLimit_of_reflects_of_preserves F G /-- If `F ⋙ G` preserves limits and `G` reflects limits, then `F` preserves limits. -/ lemma preservesLimits_of_reflects_of_preserves [PreservesLimitsOfSize.{w', w} (F ⋙ G)] [ReflectsLimitsOfSize.{w', w} G] : PreservesLimitsOfSize.{w', w} F where preservesLimitsOfShape := preservesLimitsOfShape_of_reflects_of_preserves F G /-- Transfer reflection of limits along a natural isomorphism in the diagram. -/ lemma reflectsLimit_of_iso_diagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [ReflectsLimit K₁ F] : ReflectsLimit K₂ F where reflects {c} t := ⟨by apply IsLimit.postcomposeInvEquiv h c (isLimitOfReflects F _) apply ((IsLimit.postcomposeInvEquiv (Functor.isoWhiskerRight h F :) _).symm t).ofIsoLimit _ exact Cones.ext (Iso.refl _)⟩ /-- Transfer reflection of a limit along a natural isomorphism in the functor. -/ lemma reflectsLimit_of_natIso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [ReflectsLimit K F] : ReflectsLimit K G where reflects t := ReflectsLimit.reflects (IsLimit.mapConeEquiv h.symm t) /-- Transfer reflection of limits of shape along a natural isomorphism in the functor. -/ lemma reflectsLimitsOfShape_of_natIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsLimitsOfShape J F] : ReflectsLimitsOfShape J G where reflectsLimit {K} := reflectsLimit_of_natIso K h /-- Transfer reflection of limits along a natural isomorphism in the functor. -/ lemma reflectsLimits_of_natIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsLimitsOfSize.{w', w} F] : ReflectsLimitsOfSize.{w', w} G where reflectsLimitsOfShape := reflectsLimitsOfShape_of_natIso h /-- Transfer reflection of limits along an equivalence in the shape. -/ lemma reflectsLimitsOfShape_of_equiv {J' : Type w₂} [Category.{w₂'} J'] (e : J ≌ J') (F : C ⥤ D) [ReflectsLimitsOfShape J F] : ReflectsLimitsOfShape J' F where reflectsLimit {K} := { reflects := fun {c} t => ⟨by apply IsLimit.ofWhiskerEquivalence e apply isLimitOfReflects F apply IsLimit.ofIsoLimit _ (Functor.mapConeWhisker _).symm exact IsLimit.whiskerEquivalence t _⟩ } /-- A functor reflecting larger limits also reflects smaller limits. -/ lemma reflectsLimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [ReflectsLimitsOfSize.{w', w₂'} F] : ReflectsLimitsOfSize.{w, w₂} F where reflectsLimitsOfShape {J} := reflectsLimitsOfShape_of_equiv ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm F /-- `reflectsLimitsOfSize_shrink.{w w'} F` tries to obtain `reflectsLimitsOfSize.{w w'} F` from some other `reflectsLimitsOfSize F`. -/ lemma reflectsLimitsOfSize_shrink (F : C ⥤ D) [ReflectsLimitsOfSize.{max w w₂, max w' w₂'} F] : ReflectsLimitsOfSize.{w, w'} F := reflectsLimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Reflecting limits at any universe implies reflecting limits at universe `0`. -/ lemma reflectsSmallestLimits_of_reflectsLimits (F : C ⥤ D) [ReflectsLimitsOfSize.{v₃, u₃} F] : ReflectsLimitsOfSize.{0, 0} F := reflectsLimitsOfSize_shrink F /-- If the limit of `F` exists and `G` preserves it, then if `G` reflects isomorphisms then it reflects the limit of `F`. -/ -- Porting note: previous behavior of apply pushed instance holes into hypotheses, this errors lemma reflectsLimit_of_reflectsIsomorphisms (F : J ⥤ C) (G : C ⥤ D) [G.ReflectsIsomorphisms] [HasLimit F] [PreservesLimit F G] : ReflectsLimit F G where reflects {c} t := by suffices IsIso (IsLimit.lift (limit.isLimit F) c) from ⟨by apply IsLimit.ofPointIso (limit.isLimit F)⟩ change IsIso ((Cones.forget _).map ((limit.isLimit F).liftConeMorphism c)) suffices IsIso (IsLimit.liftConeMorphism (limit.isLimit F) c) from by apply (Cones.forget F).map_isIso _ suffices IsIso ((Cones.functoriality F G).map (IsLimit.liftConeMorphism (limit.isLimit F) c)) from by apply isIso_of_reflects_iso _ (Cones.functoriality F G) exact t.hom_isIso (isLimitOfPreserves G (limit.isLimit F)) _ /-- If `C` has limits of shape `J` and `G` preserves them, then if `G` reflects isomorphisms then it reflects limits of shape `J`. -/ lemma reflectsLimitsOfShape_of_reflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasLimitsOfShape J C] [PreservesLimitsOfShape J G] : ReflectsLimitsOfShape J G where reflectsLimit {F} := reflectsLimit_of_reflectsIsomorphisms F G /-- If `C` has limits and `G` preserves limits, then if `G` reflects isomorphisms then it reflects limits. -/ lemma reflectsLimits_of_reflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasLimitsOfSize.{w', w} C] [PreservesLimitsOfSize.{w', w} G] : ReflectsLimitsOfSize.{w', w} G where reflectsLimitsOfShape := reflectsLimitsOfShape_of_reflectsIsomorphisms /-- If `F ⋙ G` preserves colimits for `K`, and `G` reflects colimits for `K ⋙ F`, then `F` preserves colimits for `K`. -/ lemma preservesColimit_of_reflects_of_preserves [PreservesColimit K (F ⋙ G)] [ReflectsColimit (K ⋙ F) G] : PreservesColimit K F := ⟨fun {c} h => ⟨by apply isColimitOfReflects G apply isColimitOfPreserves (F ⋙ G) h⟩⟩ /-- If `F ⋙ G` preserves colimits of shape `J` and `G` reflects colimits of shape `J`, then `F` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_of_reflects_of_preserves [PreservesColimitsOfShape J (F ⋙ G)] [ReflectsColimitsOfShape J G] : PreservesColimitsOfShape J F where preservesColimit := preservesColimit_of_reflects_of_preserves F G /-- If `F ⋙ G` preserves colimits and `G` reflects colimits, then `F` preserves colimits. -/ lemma preservesColimits_of_reflects_of_preserves [PreservesColimitsOfSize.{w', w} (F ⋙ G)] [ReflectsColimitsOfSize.{w', w} G] : PreservesColimitsOfSize.{w', w} F where preservesColimitsOfShape := preservesColimitsOfShape_of_reflects_of_preserves F G /-- Transfer reflection of colimits along a natural isomorphism in the diagram. -/ lemma reflectsColimit_of_iso_diagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [ReflectsColimit K₁ F] : ReflectsColimit K₂ F where reflects {c} t := ⟨by apply IsColimit.precomposeHomEquiv h c (isColimitOfReflects F _) apply ((IsColimit.precomposeHomEquiv (Functor.isoWhiskerRight h F :) _).symm t).ofIsoColimit _ exact Cocones.ext (Iso.refl _)⟩ /-- Transfer reflection of a colimit along a natural isomorphism in the functor. -/ lemma reflectsColimit_of_natIso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [ReflectsColimit K F] : ReflectsColimit K G where reflects t := ReflectsColimit.reflects (IsColimit.mapCoconeEquiv h.symm t) /-- Transfer reflection of colimits of shape along a natural isomorphism in the functor. -/ lemma reflectsColimitsOfShape_of_natIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsColimitsOfShape J F] : ReflectsColimitsOfShape J G where reflectsColimit {K} := reflectsColimit_of_natIso K h /-- Transfer reflection of colimits along a natural isomorphism in the functor. -/ lemma reflectsColimits_of_natIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsColimitsOfSize.{w, w'} F] : ReflectsColimitsOfSize.{w, w'} G where reflectsColimitsOfShape := reflectsColimitsOfShape_of_natIso h /-- Transfer reflection of colimits along an equivalence in the shape. -/ lemma reflectsColimitsOfShape_of_equiv {J' : Type w₂} [Category.{w₂'} J'] (e : J ≌ J') (F : C ⥤ D) [ReflectsColimitsOfShape J F] : ReflectsColimitsOfShape J' F where reflectsColimit := { reflects := fun {c} t => ⟨by apply IsColimit.ofWhiskerEquivalence e apply isColimitOfReflects F apply IsColimit.ofIsoColimit _ (Functor.mapCoconeWhisker _).symm exact IsColimit.whiskerEquivalence t _⟩ } /-- A functor reflecting larger colimits also reflects smaller colimits. -/ lemma reflectsColimitsOfSize_of_univLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [ReflectsColimitsOfSize.{w', w₂'} F] : ReflectsColimitsOfSize.{w, w₂} F where reflectsColimitsOfShape {J} := reflectsColimitsOfShape_of_equiv ((ShrinkHoms.equivalence.{w'} J).trans <| Shrink.equivalence _).symm F /-- `reflectsColimitsOfSize_shrink.{w w'} F` tries to obtain `reflectsColimitsOfSize.{w w'} F` from some other `reflectsColimitsOfSize F`. -/ lemma reflectsColimitsOfSize_shrink (F : C ⥤ D) [ReflectsColimitsOfSize.{max w w₂, max w' w₂'} F] : ReflectsColimitsOfSize.{w, w'} F := reflectsColimitsOfSize_of_univLE.{max w w₂, max w' w₂'} F /-- Reflecting colimits at any universe implies reflecting colimits at universe `0`. -/ lemma reflectsSmallestColimits_of_reflectsColimits (F : C ⥤ D) [ReflectsColimitsOfSize.{v₃, u₃} F] : ReflectsColimitsOfSize.{0, 0} F := reflectsColimitsOfSize_shrink F /-- If the colimit of `F` exists and `G` preserves it, then if `G` reflects isomorphisms then it reflects the colimit of `F`. -/ -- Porting note: previous behavior of apply pushed instance holes into hypotheses, this errors lemma reflectsColimit_of_reflectsIsomorphisms (F : J ⥤ C) (G : C ⥤ D) [G.ReflectsIsomorphisms] [HasColimit F] [PreservesColimit F G] : ReflectsColimit F G where reflects {c} t := by suffices IsIso (IsColimit.desc (colimit.isColimit F) c) from ⟨by apply IsColimit.ofPointIso (colimit.isColimit F)⟩ change IsIso ((Cocones.forget _).map ((colimit.isColimit F).descCoconeMorphism c)) suffices IsIso (IsColimit.descCoconeMorphism (colimit.isColimit F) c) from by apply (Cocones.forget F).map_isIso _ suffices IsIso ((Cocones.functoriality F G).map (IsColimit.descCoconeMorphism (colimit.isColimit F) c)) from by apply isIso_of_reflects_iso _ (Cocones.functoriality F G) exact (isColimitOfPreserves G (colimit.isColimit F)).hom_isIso t _ /-- If `C` has colimits of shape `J` and `G` preserves them, then if `G` reflects isomorphisms then it reflects colimits of shape `J`. -/ lemma reflectsColimitsOfShape_of_reflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasColimitsOfShape J C] [PreservesColimitsOfShape J G] : ReflectsColimitsOfShape J G where reflectsColimit {F} := reflectsColimit_of_reflectsIsomorphisms F G /-- If `C` has colimits and `G` preserves colimits, then if `G` reflects isomorphisms then it reflects colimits. -/ lemma reflectsColimits_of_reflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasColimitsOfSize.{w', w} C] [PreservesColimitsOfSize.{w', w} G] : ReflectsColimitsOfSize.{w', w} G where reflectsColimitsOfShape := reflectsColimitsOfShape_of_reflectsIsomorphisms end section open Functor lemma isIso_app_coconePt_of_preservesColimit {C D J : Type*} [Category C] [Category D] [Category J] (K : J ⥤ C) {L L' : C ⥤ D} (α : L ⟶ L') [IsIso (whiskerLeft K α)] (c : Cocone K) (hc : IsColimit c) [PreservesColimit K L] [PreservesColimit K L'] : IsIso (α.app c.pt) := by let e := IsColimit.coconePointsIsoOfNatIso (isColimitOfPreserves L hc) (isColimitOfPreserves L' hc) (asIso (whiskerLeft K α)) convert inferInstanceAs (IsIso e.hom) apply (isColimitOfPreserves L hc).hom_ext fun j ↦ ?_ simp only [Functor.comp_obj, Functor.mapCocone_pt, Functor.const_obj_obj, Functor.mapCocone_ι_app, NatTrans.naturality, IsColimit.coconePointsIsoOfNatIso_hom, asIso_hom, e] refine (((isColimitOfPreserves L hc).ι_map (L'.mapCocone c) (whiskerLeft K α) j).trans ?_).symm simp end variable (F : C ⥤ D) /-- A fully faithful functor reflects limits. -/ instance fullyFaithful_reflectsLimits [F.Full] [F.Faithful] : ReflectsLimitsOfSize.{w, w'} F where reflectsLimitsOfShape {J} 𝒥₁ := { reflectsLimit := fun {K} => { reflects := fun {c} t => ⟨(IsLimit.mkConeMorphism fun _ => (Cones.functoriality K F).preimage (t.liftConeMorphism _)) <| by apply fun s m => (Cones.functoriality K F).map_injective _ intro s m rw [Functor.map_preimage] apply t.uniq_cone_morphism⟩ } } /-- A fully faithful functor reflects colimits. -/ instance fullyFaithful_reflectsColimits [F.Full] [F.Faithful] : ReflectsColimitsOfSize.{w, w'} F where reflectsColimitsOfShape {J} 𝒥₁ := { reflectsColimit := fun {K} => { reflects := fun {c} t => ⟨(IsColimit.mkCoconeMorphism fun _ => (Cocones.functoriality K F).preimage (t.descCoconeMorphism _)) <| by apply fun s m => (Cocones.functoriality K F).map_injective _ intro s m rw [Functor.map_preimage] apply t.uniq_cocone_morphism⟩ }} end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Ulift.lean
import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.Data.Set.Subsingleton /-! # `ULift` creates small (co)limits This file shows that `uliftFunctor.{v, u}` preserves all limits and colimits, including those potentially too big to exist in `Type u`. As this functor is fully faithful, we also deduce that it creates `u`-small limits and colimits. -/ universe v w w' u namespace CategoryTheory.Limits.Types /-- The equivalence between `K.sections` and `(K ⋙ uliftFunctor.{v, u}).sections`. This is used to show that `uliftFunctor` preserves limits that are potentially too large to exist in the source category. -/ def sectionsEquiv {J : Type*} [Category J] (K : J ⥤ Type u) : K.sections ≃ (K ⋙ uliftFunctor.{v, u}).sections where toFun := fun ⟨u, hu⟩ => ⟨fun j => ⟨u j⟩, fun f => by simp [hu f]⟩ invFun := fun ⟨u, hu⟩ => ⟨fun j => (u j).down, @fun j j' f => by simp [← hu f]⟩ /-- The functor `uliftFunctor : Type u ⥤ Type (max u v)` preserves limits of arbitrary size. -/ noncomputable instance : PreservesLimitsOfSize.{w', w} uliftFunctor.{v, u} where preservesLimitsOfShape {J} := { preservesLimit := fun {K} => { preserves := fun {c} hc => by rw [Types.isLimit_iff ((uliftFunctor.{v, u}).mapCone c)] intro s hs obtain ⟨x, hx₁, hx₂⟩ := (Types.isLimit_iff c).mp ⟨hc⟩ _ ((sectionsEquiv K).symm ⟨s, hs⟩).2 exact ⟨⟨x⟩, fun i => ULift.ext _ _ (hx₁ i), fun y hy => ULift.ext _ _ (hx₂ y.down fun i ↦ ULift.ext_iff.mp (hy i))⟩ } } /-- The functor `uliftFunctor : Type u ⥤ Type (max u v)` creates `u`-small limits. -/ noncomputable instance : CreatesLimitsOfSize.{w, u} uliftFunctor.{v, u} where CreatesLimitsOfShape := { CreatesLimit := fun {_} ↦ createsLimitOfFullyFaithfulOfPreserves } variable {J : Type*} [Category J] {K : J ⥤ Type u} {c : Cocone K} (hc : IsColimit c) variable {lc : Cocone (K ⋙ uliftFunctor.{v, u})} /-- The functor `uliftFunctor : Type u ⥤ Type (max u v)` preserves colimits of arbitrary size. -/ noncomputable instance : PreservesColimitsOfSize.{w', w} uliftFunctor.{v, u} where preservesColimitsOfShape {J _} := { preservesColimit := fun {F} ↦ { preserves := fun {c} hc ↦ by rw [isColimit_iff_coconeTypesIsColimit] exact (((isColimit_iff_coconeTypesIsColimit _).1 ⟨hc⟩).precompose (G := F ⋙ uliftFunctor.{v}) (fun _ ↦ Equiv.ulift) (fun _ ↦ rfl)).of_equiv Equiv.ulift.symm (fun _ _ ↦ rfl) } } /-- The functor `uliftFunctor : Type u ⥤ Type (max u v)` creates `u`-small colimits. -/ noncomputable instance : CreatesColimitsOfSize.{w, u} uliftFunctor.{v, u} where CreatesColimitsOfShape := { CreatesColimit := fun {_} ↦ createsColimitOfReflectsIsomorphismsOfPreserves } end CategoryTheory.Limits.Types
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Opposites.lean
import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Preserves.Finite /-! # Limit preservation properties of `Functor.op` and related constructions We formulate conditions about `F` which imply that `F.op`, `F.unop`, `F.leftOp` and `F.rightOp` preserve certain (co)limits and vice versa. -/ universe w w' v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] variable {J : Type w} [Category.{w'} J] /-- If `F : C ⥤ D` preserves colimits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesLimit_op (K : J ⥤ Cᵒᵖ) (F : C ⥤ D) [PreservesColimit K.leftOp F] : PreservesLimit K F.op where preserves {_} hc := ⟨isLimitConeRightOpOfCocone _ (isColimitOfPreserves F (isColimitCoconeLeftOpOfCone _ hc))⟩ /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F : C ⥤ D` preserves limits of `K : J ⥤ C`. -/ lemma preservesLimit_of_op (K : J ⥤ C) (F : C ⥤ D) [PreservesColimit K.op F.op] : PreservesLimit K F where preserves {_} hc := ⟨isLimitOfOp (isColimitOfPreserves F.op (IsLimit.op hc))⟩ /-- If `F : C ⥤ Dᵒᵖ` preserves colimits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves limits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesLimit_leftOp (K : J ⥤ Cᵒᵖ) (F : C ⥤ Dᵒᵖ) [PreservesColimit K.leftOp F] : PreservesLimit K F.leftOp where preserves {_} hc := ⟨isLimitConeUnopOfCocone _ (isColimitOfPreserves F (isColimitCoconeLeftOpOfCone _ hc))⟩ /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F : C ⥤ Dᵒᵖ` preserves limits of `K : J ⥤ C`. -/ lemma preservesLimit_of_leftOp (K : J ⥤ C) (F : C ⥤ Dᵒᵖ) [PreservesColimit K.op F.leftOp] : PreservesLimit K F where preserves {_} hc := ⟨isLimitOfCoconeLeftOpOfCone _ (isColimitOfPreserves F.leftOp (IsLimit.op hc))⟩ /-- If `F : Cᵒᵖ ⥤ D` preserves colimits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves limits of `K : J ⥤ C`. -/ lemma preservesLimit_rightOp (K : J ⥤ C) (F : Cᵒᵖ ⥤ D) [PreservesColimit K.op F] : PreservesLimit K F.rightOp where preserves {_} hc := ⟨isLimitConeRightOpOfCocone _ (isColimitOfPreserves F hc.op)⟩ /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits of `K.leftOp : Jᵒᵖ ⥤ Cᵒᵖ`, then `F : Cᵒᵖ ⥤ D` preserves limits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesLimit_of_rightOp (K : J ⥤ Cᵒᵖ) (F : Cᵒᵖ ⥤ D) [PreservesColimit K.leftOp F.rightOp] : PreservesLimit K F where preserves {_} hc := ⟨isLimitOfOp (isColimitOfPreserves F.rightOp (isColimitCoconeLeftOpOfCone _ hc))⟩ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.unop : C ⥤ D` preserves limits of `K : J ⥤ C`. -/ lemma preservesLimit_unop (K : J ⥤ C) (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimit K.op F] : PreservesLimit K F.unop where preserves {_} hc := ⟨isLimitConeUnopOfCocone _ (isColimitOfPreserves F hc.op)⟩ /-- If `F.unop : C ⥤ D` preserves colimits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesLimit_of_unop (K : J ⥤ Cᵒᵖ) (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimit K.leftOp F.unop] : PreservesLimit K F where preserves {_} hc := ⟨isLimitOfCoconeLeftOpOfCone _ (isColimitOfPreserves F.unop (isColimitCoconeLeftOpOfCone _ hc))⟩ /-- If `F : C ⥤ D` preserves limits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesColimit_op (K : J ⥤ Cᵒᵖ) (F : C ⥤ D) [PreservesLimit K.leftOp F] : PreservesColimit K F.op where preserves {_} hc := ⟨isColimitCoconeRightOpOfCone _ (isLimitOfPreserves F (isLimitConeLeftOpOfCocone _ hc))⟩ /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F : C ⥤ D` preserves colimits of `K : J ⥤ C`. -/ lemma preservesColimit_of_op (K : J ⥤ C) (F : C ⥤ D) [PreservesLimit K.op F.op] : PreservesColimit K F where preserves {_} hc := ⟨isColimitOfOp (isLimitOfPreserves F.op (IsColimit.op hc))⟩ /-- If `F : C ⥤ Dᵒᵖ` preserves limits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesColimit_leftOp (K : J ⥤ Cᵒᵖ) (F : C ⥤ Dᵒᵖ) [PreservesLimit K.leftOp F] : PreservesColimit K F.leftOp where preserves {_} hc := ⟨isColimitCoconeUnopOfCone _ (isLimitOfPreserves F (isLimitConeLeftOpOfCocone _ hc))⟩ /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves limits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F : C ⥤ Dᵒᵖ` preserves colimits of `K : J ⥤ C`. -/ lemma preservesColimit_of_leftOp (K : J ⥤ C) (F : C ⥤ Dᵒᵖ) [PreservesLimit K.op F.leftOp] : PreservesColimit K F where preserves {_} hc := ⟨isColimitOfConeLeftOpOfCocone _ (isLimitOfPreserves F.leftOp (IsColimit.op hc))⟩ /-- If `F : Cᵒᵖ ⥤ D` preserves limits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits of `K : J ⥤ C`. -/ lemma preservesColimit_rightOp (K : J ⥤ C) (F : Cᵒᵖ ⥤ D) [PreservesLimit K.op F] : PreservesColimit K F.rightOp where preserves {_} hc := ⟨isColimitCoconeRightOpOfCone _ (isLimitOfPreserves F hc.op)⟩ /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves limits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F : Cᵒᵖ ⥤ D` preserves colimits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesColimit_of_rightOp (K : J ⥤ Cᵒᵖ) (F : Cᵒᵖ ⥤ D) [PreservesLimit K.leftOp F.rightOp] : PreservesColimit K F where preserves {_} hc := ⟨isColimitOfOp (isLimitOfPreserves F.rightOp (isLimitConeLeftOpOfCocone _ hc))⟩ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.unop : C ⥤ D` preserves colimits of `K : J ⥤ C`. -/ lemma preservesColimit_unop (K : J ⥤ C) (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimit K.op F] : PreservesColimit K F.unop where preserves {_} hc := ⟨isColimitCoconeUnopOfCone _ (isLimitOfPreserves F hc.op)⟩ /-- If `F.unop : C ⥤ D` preserves limits of `K.op : Jᵒᵖ ⥤ C`, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of `K : J ⥤ Cᵒᵖ`. -/ lemma preservesColimit_of_unop (K : J ⥤ Cᵒᵖ) (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimit K.leftOp F.unop] : PreservesColimit K F where preserves {_} hc := ⟨isColimitOfConeLeftOpOfCocone _ (isLimitOfPreserves F.unop (isLimitConeLeftOpOfCocone _ hc))⟩ section variable (J) /-- If `F : C ⥤ D` preserves colimits of shape `Jᵒᵖ`, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_op (F : C ⥤ D) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.op where preservesLimit {K} := preservesLimit_op K F /-- If `F : C ⥤ Dᵒᵖ` preserves colimits of shape `Jᵒᵖ`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_leftOp (F : C ⥤ Dᵒᵖ) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.leftOp where preservesLimit {K} := preservesLimit_leftOp K F /-- If `F : Cᵒᵖ ⥤ D` preserves colimits of shape `Jᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_rightOp (F : Cᵒᵖ ⥤ D) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.rightOp where preservesLimit {K} := preservesLimit_rightOp K F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of shape `Jᵒᵖ`, then `F.unop : C ⥤ D` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.unop where preservesLimit {K} := preservesLimit_unop K F /-- If `F : C ⥤ D` preserves limits of shape `Jᵒᵖ`, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_op (F : C ⥤ D) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.op where preservesColimit {K} := preservesColimit_op K F /-- If `F : C ⥤ Dᵒᵖ` preserves limits of shape `Jᵒᵖ`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_leftOp (F : C ⥤ Dᵒᵖ) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.leftOp where preservesColimit {K} := preservesColimit_leftOp K F /-- If `F : Cᵒᵖ ⥤ D` preserves limits of shape `Jᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_rightOp (F : Cᵒᵖ ⥤ D) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.rightOp where preservesColimit {K} := preservesColimit_rightOp K F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of shape `Jᵒᵖ`, then `F.unop : C ⥤ D` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.unop where preservesColimit {K} := preservesColimit_unop K F /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of shape `Jᵒᵖ`, then `F : C ⥤ D` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_of_op (F : C ⥤ D) [PreservesColimitsOfShape Jᵒᵖ F.op] : PreservesLimitsOfShape J F where preservesLimit {K} := preservesLimit_of_op K F /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits of shape `Jᵒᵖ`, then `F : C ⥤ Dᵒᵖ` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesColimitsOfShape Jᵒᵖ F.leftOp] : PreservesLimitsOfShape J F where preservesLimit {K} := preservesLimit_of_leftOp K F /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits of shape `Jᵒᵖ`, then `F : Cᵒᵖ ⥤ D` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesColimitsOfShape Jᵒᵖ F.rightOp] : PreservesLimitsOfShape J F where preservesLimit {K} := preservesLimit_of_rightOp K F /-- If `F.unop : C ⥤ D` preserves colimits of shape `Jᵒᵖ`, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of shape `J`. -/ lemma preservesLimitsOfShape_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimitsOfShape Jᵒᵖ F.unop] : PreservesLimitsOfShape J F where preservesLimit {K} := preservesLimit_of_unop K F /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of shape `Jᵒᵖ`, then `F : C ⥤ D` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_of_op (F : C ⥤ D) [PreservesLimitsOfShape Jᵒᵖ F.op] : PreservesColimitsOfShape J F where preservesColimit {K} := preservesColimit_of_op K F /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves limits of shape `Jᵒᵖ`, then `F : C ⥤ Dᵒᵖ` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesLimitsOfShape Jᵒᵖ F.leftOp] : PreservesColimitsOfShape J F where preservesColimit {K} := preservesColimit_of_leftOp K F /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves limits of shape `Jᵒᵖ`, then `F : Cᵒᵖ ⥤ D` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesLimitsOfShape Jᵒᵖ F.rightOp] : PreservesColimitsOfShape J F where preservesColimit {K} := preservesColimit_of_rightOp K F /-- If `F.unop : C ⥤ D` preserves limits of shape `Jᵒᵖ`, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of shape `J`. -/ lemma preservesColimitsOfShape_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimitsOfShape Jᵒᵖ F.unop] : PreservesColimitsOfShape J F where preservesColimit {K} := preservesColimit_of_unop K F end /-- If `F : C ⥤ D` preserves colimits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimitsOfSize_op (F : C ⥤ D) [PreservesColimitsOfSize.{w, w'} F] : PreservesLimitsOfSize.{w, w'} F.op where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_op _ _ /-- If `F : C ⥤ Dᵒᵖ` preserves colimits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves limits. -/ lemma preservesLimitsOfSize_leftOp (F : C ⥤ Dᵒᵖ) [PreservesColimitsOfSize.{w, w'} F] : PreservesLimitsOfSize.{w, w'} F.leftOp where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_leftOp _ _ /-- If `F : Cᵒᵖ ⥤ D` preserves colimits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimitsOfSize_rightOp (F : Cᵒᵖ ⥤ D) [PreservesColimitsOfSize.{w, w'} F] : PreservesLimitsOfSize.{w, w'} F.rightOp where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_rightOp _ _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits, then `F.unop : C ⥤ D` preserves limits. -/ lemma preservesLimitsOfSize_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimitsOfSize.{w, w'} F] : PreservesLimitsOfSize.{w, w'} F.unop where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_unop _ _ /-- If `F : C ⥤ D` preserves limits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimitsOfSize_op (F : C ⥤ D) [PreservesLimitsOfSize.{w, w'} F] : PreservesColimitsOfSize.{w, w'} F.op where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_op _ _ /-- If `F : C ⥤ Dᵒᵖ` preserves limits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits. -/ lemma preservesColimitsOfSize_leftOp (F : C ⥤ Dᵒᵖ) [PreservesLimitsOfSize.{w, w'} F] : PreservesColimitsOfSize.{w, w'} F.leftOp where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_leftOp _ _ /-- If `F : Cᵒᵖ ⥤ D` preserves limits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimitsOfSize_rightOp (F : Cᵒᵖ ⥤ D) [PreservesLimitsOfSize.{w, w'} F] : PreservesColimitsOfSize.{w, w'} F.rightOp where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_rightOp _ _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits, then `F.unop : C ⥤ D` preserves colimits. -/ lemma preservesColimitsOfSize_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimitsOfSize.{w, w'} F] : PreservesColimitsOfSize.{w, w'} F.unop where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_unop _ _ /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits, then `F : C ⥤ D` preserves limits. -/ lemma preservesLimitsOfSize_of_op (F : C ⥤ D) [PreservesColimitsOfSize.{w, w'} F.op] : PreservesLimitsOfSize.{w, w'} F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_op _ _ /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits, then `F : C ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimitsOfSize_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesColimitsOfSize.{w, w'} F.leftOp] : PreservesLimitsOfSize.{w, w'} F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_leftOp _ _ /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits, then `F : Cᵒᵖ ⥤ D` preserves limits. -/ lemma preservesLimitsOfSize_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesColimitsOfSize.{w, w'} F.rightOp] : PreservesLimitsOfSize.{w, w'} F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_rightOp _ _ /-- If `F.unop : C ⥤ D` preserves colimits, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimitsOfSize_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimitsOfSize.{w, w'} F.unop] : PreservesLimitsOfSize.{w, w'} F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_unop _ _ /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits, then `F : C ⥤ D` preserves colimits. -/ lemma preservesColimitsOfSize_of_op (F : C ⥤ D) [PreservesLimitsOfSize.{w, w'} F.op] : PreservesColimitsOfSize.{w, w'} F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_op _ _ /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves limits, then `F : C ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimitsOfSize_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesLimitsOfSize.{w, w'} F.leftOp] : PreservesColimitsOfSize.{w, w'} F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_leftOp _ _ /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves limits, then `F : Cᵒᵖ ⥤ D` preserves colimits. -/ lemma preservesColimitsOfSize_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesLimitsOfSize.{w, w'} F.rightOp] : PreservesColimitsOfSize.{w, w'} F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_rightOp _ _ /-- If `F.unop : C ⥤ D` preserves limits, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimitsOfSize_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimitsOfSize.{w, w'} F.unop] : PreservesColimitsOfSize.{w, w'} F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_unop _ _ /-- If `F : C ⥤ D` preserves colimits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimits_op (F : C ⥤ D) [PreservesColimits F] : PreservesLimits F.op where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_op _ _ /-- If `F : C ⥤ Dᵒᵖ` preserves colimits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves limits. -/ lemma preservesLimits_leftOp (F : C ⥤ Dᵒᵖ) [PreservesColimits F] : PreservesLimits F.leftOp where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_leftOp _ _ /-- If `F : Cᵒᵖ ⥤ D` preserves colimits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimits_rightOp (F : Cᵒᵖ ⥤ D) [PreservesColimits F] : PreservesLimits F.rightOp where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_rightOp _ _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits, then `F.unop : C ⥤ D` preserves limits. -/ lemma preservesLimits_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimits F] : PreservesLimits F.unop where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_unop _ _ /-- If `F : C ⥤ D` preserves limits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimits_op (F : C ⥤ D) [PreservesLimits F] : PreservesColimits F.op where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_op _ _ /-- If `F : C ⥤ Dᵒᵖ` preserves limits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits. -/ lemma preservesColimits_leftOp (F : C ⥤ Dᵒᵖ) [PreservesLimits F] : PreservesColimits F.leftOp where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_leftOp _ _ /-- If `F : Cᵒᵖ ⥤ D` preserves limits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimits_rightOp (F : Cᵒᵖ ⥤ D) [PreservesLimits F] : PreservesColimits F.rightOp where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_rightOp _ _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits, then `F.unop : C ⥤ D` preserves colimits. -/ lemma preservesColimits_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimits F] : PreservesColimits F.unop where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_unop _ _ /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits, then `F : C ⥤ D` preserves limits. -/ lemma preservesLimits_of_op (F : C ⥤ D) [PreservesColimits F.op] : PreservesLimits F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_op _ _ /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits, then `F : C ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimits_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesColimits F.leftOp] : PreservesLimits F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_leftOp _ _ /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits, then `F : Cᵒᵖ ⥤ D` preserves limits. -/ lemma preservesLimits_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesColimits F.rightOp] : PreservesLimits F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_rightOp _ _ /-- If `F.unop : C ⥤ D` preserves colimits, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits. -/ lemma preservesLimits_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimits F.unop] : PreservesLimits F where preservesLimitsOfShape {_} _ := preservesLimitsOfShape_of_unop _ _ /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits, then `F : C ⥤ D` preserves colimits. -/ lemma preservesColimits_of_op (F : C ⥤ D) [PreservesLimits F.op] : PreservesColimits F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_op _ _ /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves limits, then `F : C ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimits_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesLimits F.leftOp] : PreservesColimits F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_leftOp _ _ /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves limits, then `F : Cᵒᵖ ⥤ D` preserves colimits. -/ lemma preservesColimits_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesLimits F.rightOp] : PreservesColimits F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_rightOp _ _ /-- If `F.unop : C ⥤ D` preserves limits, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits. -/ lemma preservesColimits_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimits F.unop] : PreservesColimits F where preservesColimitsOfShape {_} _ := preservesColimitsOfShape_of_unop _ _ /-- If `F : C ⥤ D` preserves finite colimits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite limits. -/ lemma preservesFiniteLimits_op (F : C ⥤ D) [PreservesFiniteColimits F] : PreservesFiniteLimits F.op where preservesFiniteLimits J _ _ := preservesLimitsOfShape_op J F /-- If `F : C ⥤ Dᵒᵖ` preserves finite colimits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite limits. -/ lemma preservesFiniteLimits_leftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteColimits F] : PreservesFiniteLimits F.leftOp where preservesFiniteLimits J _ _ := preservesLimitsOfShape_leftOp J F /-- If `F : Cᵒᵖ ⥤ D` preserves finite colimits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite limits. -/ lemma preservesFiniteLimits_rightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteColimits F] : PreservesFiniteLimits F.rightOp where preservesFiniteLimits J _ _ := preservesLimitsOfShape_rightOp J F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite colimits, then `F.unop : C ⥤ D` preserves finite limits. -/ lemma preservesFiniteLimits_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteColimits F] : PreservesFiniteLimits F.unop where preservesFiniteLimits J _ _ := preservesLimitsOfShape_unop J F /-- If `F : C ⥤ D` preserves finite limits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite colimits. -/ lemma preservesFiniteColimits_op (F : C ⥤ D) [PreservesFiniteLimits F] : PreservesFiniteColimits F.op where preservesFiniteColimits J _ _ := preservesColimitsOfShape_op J F /-- If `F : C ⥤ Dᵒᵖ` preserves finite limits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite colimits. -/ lemma preservesFiniteColimits_leftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteLimits F] : PreservesFiniteColimits F.leftOp where preservesFiniteColimits J _ _ := preservesColimitsOfShape_leftOp J F /-- If `F : Cᵒᵖ ⥤ D` preserves finite limits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite colimits. -/ lemma preservesFiniteColimits_rightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteLimits F] : PreservesFiniteColimits F.rightOp where preservesFiniteColimits J _ _ := preservesColimitsOfShape_rightOp J F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite limits, then `F.unop : C ⥤ D` preserves finite colimits. -/ lemma preservesFiniteColimits_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteLimits F] : PreservesFiniteColimits F.unop where preservesFiniteColimits J _ _ := preservesColimitsOfShape_unop J F /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite colimits, then `F : C ⥤ D` preserves finite limits. -/ lemma preservesFiniteLimits_of_op (F : C ⥤ D) [PreservesFiniteColimits F.op] : PreservesFiniteLimits F where preservesFiniteLimits J _ _ := preservesLimitsOfShape_of_op J F /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves finite colimits, then `F : C ⥤ Dᵒᵖ` preserves finite limits. -/ lemma preservesFiniteLimits_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteColimits F.leftOp] : PreservesFiniteLimits F where preservesFiniteLimits J _ _ := preservesLimitsOfShape_of_leftOp J F /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves finite colimits, then `F : Cᵒᵖ ⥤ D` preserves finite limits. -/ lemma preservesFiniteLimits_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteColimits F.rightOp] : PreservesFiniteLimits F where preservesFiniteLimits J _ _ := preservesLimitsOfShape_of_rightOp J F /-- If `F.unop : C ⥤ D` preserves finite colimits, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite limits. -/ lemma preservesFiniteLimits_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteColimits F.unop] : PreservesFiniteLimits F where preservesFiniteLimits J _ _ := preservesLimitsOfShape_of_unop J F /-- If `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite limits, then `F : C ⥤ D` preserves finite colimits. -/ lemma preservesFiniteColimits_of_op (F : C ⥤ D) [PreservesFiniteLimits F.op] : PreservesFiniteColimits F where preservesFiniteColimits J _ _ := preservesColimitsOfShape_of_op J F /-- If `F.leftOp : Cᵒᵖ ⥤ D` preserves finite limits, then `F : C ⥤ Dᵒᵖ` preserves finite colimits. -/ lemma preservesFiniteColimits_of_leftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteLimits F.leftOp] : PreservesFiniteColimits F where preservesFiniteColimits J _ _ := preservesColimitsOfShape_of_leftOp J F /-- If `F.rightOp : C ⥤ Dᵒᵖ` preserves finite limits, then `F : Cᵒᵖ ⥤ D` preserves finite colimits. -/ lemma preservesFiniteColimits_of_rightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteLimits F.rightOp] : PreservesFiniteColimits F where preservesFiniteColimits J _ _ := preservesColimitsOfShape_of_rightOp J F /-- If `F.unop : C ⥤ D` preserves finite limits, then `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite colimits. -/ lemma preservesFiniteColimits_of_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteLimits F.unop] : PreservesFiniteColimits F where preservesFiniteColimits J _ _ := preservesColimitsOfShape_of_unop J F /-- If `F : C ⥤ D` preserves finite coproducts, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite products. -/ lemma preservesFiniteProducts_op (F : C ⥤ D) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.op where preserves n := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShape_op exact preservesColimitsOfShape_of_equiv (Discrete.opposite _).symm _ /-- If `F : C ⥤ Dᵒᵖ` preserves finite coproducts, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite products. -/ lemma preservesFiniteProducts_leftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.leftOp where preserves _ := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShape_leftOp exact preservesColimitsOfShape_of_equiv (Discrete.opposite _).symm _ /-- If `F : Cᵒᵖ ⥤ D` preserves finite coproducts, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite products. -/ lemma preservesFiniteProducts_rightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.rightOp where preserves _ := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShape_rightOp exact preservesColimitsOfShape_of_equiv (Discrete.opposite _).symm _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite coproducts, then `F.unop : C ⥤ D` preserves finite products. -/ lemma preservesFiniteProducts_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.unop where preserves _ := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShape_unop exact preservesColimitsOfShape_of_equiv (Discrete.opposite _).symm _ /-- If `F : C ⥤ D` preserves finite products, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite coproducts. -/ lemma preservesFiniteCoproducts_op (F : C ⥤ D) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.op where preserves _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShape_op exact preservesLimitsOfShape_of_equiv (Discrete.opposite _).symm _ /-- If `F : C ⥤ Dᵒᵖ` preserves finite products, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite coproducts. -/ lemma preservesFiniteCoproducts_leftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.leftOp where preserves _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShape_leftOp exact preservesLimitsOfShape_of_equiv (Discrete.opposite _).symm _ /-- If `F : Cᵒᵖ ⥤ D` preserves finite products, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite coproducts. -/ lemma preservesFiniteCoproducts_rightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.rightOp where preserves _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShape_rightOp exact preservesLimitsOfShape_of_equiv (Discrete.opposite _).symm _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite products, then `F.unop : C ⥤ D` preserves finite coproducts. -/ lemma preservesFiniteCoproducts_unop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.unop where preserves _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShape_unop exact preservesLimitsOfShape_of_equiv (Discrete.opposite _).symm _ end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Grothendieck.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Grothendieck /-! # Colimits on Grothendieck constructions preserving limits We characterize the condition in which colimits on Grothendieck constructions preserve limits: By preserving limits on the Grothendieck construction's base category as well as on each of its fibers. -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace CategoryTheory open Functor namespace Limits noncomputable section variable {C : Type u₁} [Category.{v₁} C] variable {H : Type u₂} [Category.{v₂} H] variable {J : Type u₃} [Category.{v₃} J] variable {F : C ⥤ Cat.{v₄, u₄}} /-- If `colim` on each fiber `F.obj c` of a functor `F : C ⥤ Cat` preserves limits of shape `J`, then the fiberwise colimit of the limit of a functor `K : J ⥤ Grothendieck F ⥤ H` is naturally isomorphic to taking the limit of the composition `K ⋙ fiberwiseColim F H`. -/ @[simps!] def fiberwiseColimitLimitIso (K : J ⥤ Grothendieck F ⥤ H) [∀ (c : C), HasColimitsOfShape (↑(F.obj c)) H] [HasLimitsOfShape J H] [∀ c, PreservesLimitsOfShape J (colim (J := F.obj c) (C := H))] : fiberwiseColimit (limit K) ≅ limit (K ⋙ fiberwiseColim F H) := NatIso.ofComponents (fun c => HasColimit.isoOfNatIso (limitCompWhiskeringLeftIsoCompLimit K (Grothendieck.ι F c)).symm ≪≫ preservesLimitIso colim _ ≪≫ HasLimit.isoOfNatIso (associator _ _ _ ≪≫ isoWhiskerLeft _ (fiberwiseColimCompEvaluationIso _).symm ≪≫ (associator _ _ _).symm) ≪≫ (limitObjIsoLimitCompEvaluation _ c).symm) fun {c₁ c₂} f => by simp only [fiberwiseColimit_obj, fiberwiseColimit_map, Iso.trans_hom, Iso.symm_hom, Category.assoc, limitObjIsoLimitCompEvaluation_inv_limit_map] apply colimit.hom_ext intro d simp only [← Category.assoc] congr 1 apply limit.hom_ext intro e simp [← NatTrans.comp_app_assoc] variable (C) (F) in /-- If `colim` on a category `C` preserves limits of shape `J` and if it does so for `colim` on every `F.obj c` for a functor `F : C ⥤ Cat`, then `colim` on `Grothendieck F` also preserves limits of shape `J`. -/ instance preservesLimitsOfShape_colim_grothendieck [HasColimitsOfShape C H] [HasLimitsOfShape J H] [∀ c, HasColimitsOfShape (↑(F.obj c)) H] [PreservesLimitsOfShape J (colim (J := C) (C := H))] [∀ c, PreservesLimitsOfShape J (colim (J := F.obj c) (C := H))] : PreservesLimitsOfShape J (colim (J := Grothendieck F) (C := H)) := by constructor intro K let i₂ := calc colimit (limit K) _ ≅ colimit (fiberwiseColimit (limit K)) := (colimitFiberwiseColimitIso _).symm _ ≅ colimit (limit (K ⋙ fiberwiseColim _ _)) := HasColimit.isoOfNatIso (fiberwiseColimitLimitIso _) _ ≅ limit ((K ⋙ fiberwiseColim _ _) ⋙ colim) := preservesLimitIso colim (K ⋙ fiberwiseColim _ _) _ ≅ limit (K ⋙ colim) := HasLimit.isoOfNatIso (associator _ _ _ ≪≫ isoWhiskerLeft _ fiberwiseColimCompColimIso) haveI : IsIso (limit.post K colim) := by convert Iso.isIso_hom i₂ ext simp only [colim_obj, Functor.comp_obj, limit.post_π, colim_map, Iso.trans_def, Iso.trans_assoc, Iso.trans_hom, Category.assoc, HasLimit.isoOfNatIso_hom_π, fiberwiseColim_obj, isoWhiskerLeft_hom, NatTrans.comp_app, Functor.associator_hom_app, whiskerLeft_app, fiberwiseColimCompColimIso_hom_app, Category.id_comp, preservesLimitIso_hom_π_assoc, i₂] ext simp only [ι_colimMap, Trans.trans, Iso.symm_hom, ι_colimitFiberwiseColimitIso_inv_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, fiberwiseColimit_obj, fiberwiseColimitLimitIso_hom_app, ι_colimMap_assoc, Category.assoc, limitObjIsoLimitCompEvaluation_inv_π_app_assoc, Functor.comp_obj, fiberwiseColim_obj, HasLimit.isoOfNatIso_hom_π_assoc, whiskeringLeft_obj_obj, colim_obj, evaluation_obj_obj, Iso.trans_hom, isoWhiskerLeft_hom, NatTrans.comp_app, Functor.associator_hom_app, whiskerLeft_app, fiberwiseColimCompEvaluationIso_inv_app, Functor.associator_inv_app, Category.comp_id, Category.id_comp, preservesLimitIso_hom_π_assoc, colim_map, Grothendieck.ι_obj, ι_colimitFiberwiseColimitIso_hom] simp [← Category.assoc, ← NatTrans.comp_app] apply preservesLimit_of_isIso_post end end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Limits.lean
import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Isomorphisms about functors which preserve (co)limits If `G` preserves limits, and `C` and `D` have limits, then for any diagram `F : J ⥤ C` we have a canonical isomorphism `preservesLimitsIso : G.obj (Limit F) ≅ Limit (F ⋙ G)`. We also show that we can commute `IsLimit.lift` of a preserved limit with `Functor.mapCone`: `(PreservesLimit.preserves t).lift (G.mapCone c₂) = G.map (t.lift c₂)`. The duals of these are also given. For functors which preserve (co)limits of specific shapes, see `preserves/shapes.lean`. -/ universe w' w v₁ v₂ u₁ u₂ noncomputable section namespace CategoryTheory open Category Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {J : Type w} [Category.{w'} J] variable (F : J ⥤ C) section variable [PreservesLimit F G] @[simp] theorem preserves_lift_mapCone (c₁ c₂ : Cone F) (t : IsLimit c₁) : (isLimitOfPreserves G t).lift (G.mapCone c₂) = G.map (t.lift c₂) := ((isLimitOfPreserves G t).uniq (G.mapCone c₂) _ (by simp [← G.map_comp])).symm variable [HasLimit F] /-- If `G` preserves limits, we have an isomorphism from the image of the limit of a functor `F` to the limit of the functor `F ⋙ G`. -/ def preservesLimitIso : G.obj (limit F) ≅ limit (F ⋙ G) := (isLimitOfPreserves G (limit.isLimit _)).conePointUniqueUpToIso (limit.isLimit _) @[reassoc (attr := simp)] theorem preservesLimitIso_hom_π (j) : (preservesLimitIso G F).hom ≫ limit.π _ j = G.map (limit.π F j) := IsLimit.conePointUniqueUpToIso_hom_comp _ _ j @[reassoc (attr := simp)] theorem preservesLimitIso_inv_π (j) : (preservesLimitIso G F).inv ≫ G.map (limit.π F j) = limit.π _ j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ j @[reassoc (attr := simp)] theorem lift_comp_preservesLimitIso_hom (t : Cone F) : G.map (limit.lift _ t) ≫ (preservesLimitIso G F).hom = limit.lift (F ⋙ G) (G.mapCone _) := by ext simp [← G.map_comp] instance : IsIso (limit.post F G) := show IsIso (preservesLimitIso G F).hom from inferInstance variable [PreservesLimitsOfShape J G] [HasLimitsOfShape J D] [HasLimitsOfShape J C] /-- If `C, D` has all limits of shape `J`, and `G` preserves them, then `preservesLimitsIso` is functorial w.r.t. `F`. -/ @[simps!] def preservesLimitNatIso : lim ⋙ G ≅ (Functor.whiskeringRight J C D).obj G ⋙ lim := NatIso.ofComponents (fun F => preservesLimitIso G F) (by intro _ _ f apply limit.hom_ext; intro j dsimp simp only [preservesLimitIso_hom_π, Functor.whiskerRight_app, limMap_π, Category.assoc, preservesLimitIso_hom_π_assoc, ← G.map_comp]) end section variable [HasLimit F] [HasLimit (F ⋙ G)] /-- If the comparison morphism `G.obj (limit F) ⟶ limit (F ⋙ G)` is an isomorphism, then `G` preserves limits of `F`. -/ lemma preservesLimit_of_isIso_post [IsIso (limit.post F G)] : PreservesLimit F G := preservesLimit_of_preserves_limit_cone (limit.isLimit F) (by convert IsLimit.ofPointIso (limit.isLimit (F ⋙ G)) assumption) end section variable [PreservesColimit F G] @[simp] theorem preserves_desc_mapCocone (c₁ c₂ : Cocone F) (t : IsColimit c₁) : (isColimitOfPreserves G t).desc (G.mapCocone _) = G.map (t.desc c₂) := ((isColimitOfPreserves G t).uniq (G.mapCocone _) _ (by simp [← G.map_comp])).symm variable [HasColimit F] -- TODO: think about swapping the order here /-- If `G` preserves colimits, we have an isomorphism from the image of the colimit of a functor `F` to the colimit of the functor `F ⋙ G`. -/ def preservesColimitIso : G.obj (colimit F) ≅ colimit (F ⋙ G) := (isColimitOfPreserves G (colimit.isColimit _)).coconePointUniqueUpToIso (colimit.isColimit _) @[reassoc (attr := simp)] theorem ι_preservesColimitIso_inv (j : J) : colimit.ι _ j ≫ (preservesColimitIso G F).inv = G.map (colimit.ι F j) := IsColimit.comp_coconePointUniqueUpToIso_inv _ (colimit.isColimit (F ⋙ G)) j @[reassoc (attr := simp)] theorem ι_preservesColimitIso_hom (j : J) : G.map (colimit.ι F j) ≫ (preservesColimitIso G F).hom = colimit.ι (F ⋙ G) j := (isColimitOfPreserves G (colimit.isColimit _)).comp_coconePointUniqueUpToIso_hom _ j @[reassoc (attr := simp)] theorem preservesColimitIso_inv_comp_desc (t : Cocone F) : (preservesColimitIso G F).inv ≫ G.map (colimit.desc _ t) = colimit.desc _ (G.mapCocone t) := by ext simp [← G.map_comp] instance : IsIso (colimit.post F G) := show IsIso (preservesColimitIso G F).inv from inferInstance variable [PreservesColimitsOfShape J G] [HasColimitsOfShape J D] [HasColimitsOfShape J C] /-- If `C, D` has all colimits of shape `J`, and `G` preserves them, then `preservesColimitIso` is functorial w.r.t. `F`. -/ @[simps!] def preservesColimitNatIso : colim ⋙ G ≅ (Functor.whiskeringRight J C D).obj G ⋙ colim := NatIso.ofComponents (fun F => preservesColimitIso G F) (by intro _ _ f rw [← Iso.inv_comp_eq, ← Category.assoc, ← Iso.eq_comp_inv] apply colimit.hom_ext; intro j dsimp rw [ι_colimMap_assoc] simp only [ι_preservesColimitIso_inv, Functor.whiskerRight_app, ι_preservesColimitIso_inv_assoc, ← G.map_comp] rw [ι_colimMap]) end section variable [HasColimit F] [HasColimit (F ⋙ G)] /-- If the comparison morphism `colimit (F ⋙ G) ⟶ G.obj (colimit F)` is an isomorphism, then `G` preserves colimits of `F`. -/ lemma preservesColimit_of_isIso_post [IsIso (colimit.post F G)] : PreservesColimit F G := preservesColimit_of_preserves_colimit_cocone (colimit.isColimit F) (by convert IsColimit.ofPointIso (colimit.isColimit (F ⋙ G)) assumption) end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/FunctorCategory.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Preserves.Ulift import Mathlib.CategoryTheory.Limits.Presheaf import Mathlib.CategoryTheory.Limits.Yoneda /-! # Preservation of (co)limits in the functor category * Show that if `X ⨯ -` preserves colimits in `D` for any `X : D`, then the product functor `F ⨯ -` for `F : C ⥤ D` preserves colimits. The idea of the proof is simply that products and colimits in the functor category are computed pointwise, so pointwise preservation implies general preservation. * Show that `F ⋙ -` preserves limits if the target category has limits. * Show that `F : C ⥤ D` preserves limits of a certain shape if `Lan F.op : Cᵒᵖ ⥤ Type*` preserves such limits. ## References https://ncatlab.org/nlab/show/commutativity+of+limits+and+colimits#preservation_by_functor_categories_and_localizations -/ universe w w' v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section namespace CategoryTheory open Category Limits Functor section variable {C : Type u} [Category.{v₁} C] variable {D : Type u₂} [Category.{u} D] variable {E : Type u} [Category.{v₂} E] /-- If `X × -` preserves colimits in `D` for any `X : D`, then the product functor `F ⨯ -` for `F : C ⥤ D` also preserves colimits. Note this is (mathematically) a special case of the statement that "if limits commute with colimits in `D`, then they do as well in `C ⥤ D`" but the story in Lean is a bit more complex, and this statement isn't directly a special case. That is, even with a formalised proof of the general statement, there would still need to be some work to convert to this version: namely, the natural isomorphism `(evaluation C D).obj k ⋙ prod.functor.obj (F.obj k) ≅ prod.functor.obj F ⋙ (evaluation C D).obj k` -/ lemma FunctorCategory.prod_preservesColimits [HasBinaryProducts D] [HasColimits D] [∀ X : D, PreservesColimits (prod.functor.obj X)] (F : C ⥤ D) : PreservesColimits (prod.functor.obj F) where preservesColimitsOfShape {J : Type u} [Category.{u, u} J] := { preservesColimit := fun {K : J ⥤ C ⥤ D} => ({ preserves := fun {c : Cocone K} (t : IsColimit c) => ⟨by apply evaluationJointlyReflectsColimits _ fun {k} => ?_ change IsColimit ((prod.functor.obj F ⋙ (evaluation _ _).obj k).mapCocone c) let this := isColimitOfPreserves ((evaluation C D).obj k ⋙ prod.functor.obj (F.obj k)) t apply IsColimit.mapCoconeEquiv _ this apply (NatIso.ofComponents _ _).symm · intro G apply asIso (prodComparison ((evaluation C D).obj k) F G) · intro G G' apply prodComparison_natural ((evaluation C D).obj k) (𝟙 F)⟩ } ) } end section variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] instance whiskeringLeft_preservesLimitsOfShape (J : Type u) [Category.{v} J] [HasLimitsOfShape J D] (F : C ⥤ E) : PreservesLimitsOfShape J ((whiskeringLeft C E D).obj F) := ⟨fun {K} => ⟨fun c {hc} => ⟨by apply evaluationJointlyReflectsLimits intro Y change IsLimit (((evaluation E D).obj (F.obj Y)).mapCone c) exact isLimitOfPreserves _ hc⟩⟩⟩ instance whiskeringLeft_preservesColimitsOfShape (J : Type u) [Category.{v} J] [HasColimitsOfShape J D] (F : C ⥤ E) : PreservesColimitsOfShape J ((whiskeringLeft C E D).obj F) := ⟨fun {K} => ⟨fun c {hc} => ⟨by apply evaluationJointlyReflectsColimits intro Y change IsColimit (((evaluation E D).obj (F.obj Y)).mapCocone c) exact isColimitOfPreserves _ hc⟩⟩⟩ instance whiskeringLeft_preservesLimits [HasLimitsOfSize.{w, w'} D] (F : C ⥤ E) : PreservesLimitsOfSize.{w, w'} ((whiskeringLeft C E D).obj F) := ⟨fun {J} _ => whiskeringLeft_preservesLimitsOfShape J F⟩ instance whiskeringLeft_preservesColimit [HasColimitsOfSize.{w, w'} D] (F : C ⥤ E) : PreservesColimitsOfSize.{w, w'} ((whiskeringLeft C E D).obj F) := ⟨fun {J} _ => whiskeringLeft_preservesColimitsOfShape J F⟩ instance whiskeringRight_preservesLimitsOfShape {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasLimitsOfShape J D] (F : D ⥤ E) [PreservesLimitsOfShape J F] : PreservesLimitsOfShape J ((whiskeringRight C D E).obj F) := ⟨fun {K} => ⟨fun c {hc} => ⟨by apply evaluationJointlyReflectsLimits _ (fun k => ?_) change IsLimit (((evaluation _ _).obj k ⋙ F).mapCone c) exact isLimitOfPreserves _ hc⟩⟩⟩ /-- Whiskering right and then taking a limit is the same as taking the limit and applying the functor. -/ def limitCompWhiskeringRightIsoLimitComp {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasLimitsOfShape J D] (F : D ⥤ E) [PreservesLimitsOfShape J F] (G : J ⥤ C ⥤ D) : limit (G ⋙ (whiskeringRight _ _ _).obj F) ≅ limit G ⋙ F := (preservesLimitIso _ _).symm @[reassoc (attr := simp)] theorem limitCompWhiskeringRightIsoLimitComp_inv_π {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasLimitsOfShape J D] (F : D ⥤ E) [PreservesLimitsOfShape J F] (G : J ⥤ C ⥤ D) (j : J) : (limitCompWhiskeringRightIsoLimitComp F G).inv ≫ limit.π (G ⋙ (whiskeringRight _ _ _).obj F) j = whiskerRight (limit.π G j) F := by simp [limitCompWhiskeringRightIsoLimitComp] @[reassoc (attr := simp)] theorem limitCompWhiskeringRightIsoLimitComp_hom_whiskerRight_π {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasLimitsOfShape J D] (F : D ⥤ E) [PreservesLimitsOfShape J F] (G : J ⥤ C ⥤ D) (j : J) : (limitCompWhiskeringRightIsoLimitComp F G).hom ≫ whiskerRight (limit.π G j) F = limit.π (G ⋙ (whiskeringRight _ _ _).obj F) j := by simp [← Iso.eq_inv_comp] instance whiskeringRight_preservesColimitsOfShape {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasColimitsOfShape J D] (F : D ⥤ E) [PreservesColimitsOfShape J F] : PreservesColimitsOfShape J ((whiskeringRight C D E).obj F) := ⟨fun {K} => ⟨fun c {hc} => ⟨by apply evaluationJointlyReflectsColimits _ (fun k => ?_) change IsColimit (((evaluation _ _).obj k ⋙ F).mapCocone c) exact isColimitOfPreserves _ hc⟩⟩⟩ /-- Whiskering right and then taking a colimit is the same as taking the colimit and applying the functor. -/ def colimitCompWhiskeringRightIsoColimitComp {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasColimitsOfShape J D] (F : D ⥤ E) [PreservesColimitsOfShape J F] (G : J ⥤ C ⥤ D) : colimit (G ⋙ (whiskeringRight _ _ _).obj F) ≅ colimit G ⋙ F := (preservesColimitIso _ _).symm @[reassoc (attr := simp)] theorem ι_colimitCompWhiskeringRightIsoColimitComp_hom {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasColimitsOfShape J D] (F : D ⥤ E) [PreservesColimitsOfShape J F] (G : J ⥤ C ⥤ D) (j : J) : colimit.ι (G ⋙ (whiskeringRight _ _ _).obj F) j ≫ (colimitCompWhiskeringRightIsoColimitComp F G).hom = whiskerRight (colimit.ι G j) F := by simp [colimitCompWhiskeringRightIsoColimitComp] @[reassoc (attr := simp)] theorem whiskerRight_ι_colimitCompWhiskeringRightIsoColimitComp_inv {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {J : Type*} [Category J] [HasColimitsOfShape J D] (F : D ⥤ E) [PreservesColimitsOfShape J F] (G : J ⥤ C ⥤ D) (j : J) : whiskerRight (colimit.ι G j) F ≫ (colimitCompWhiskeringRightIsoColimitComp F G).inv = colimit.ι (G ⋙ (whiskeringRight _ _ _).obj F) j := by simp [Iso.comp_inv_eq] instance whiskeringRightPreservesLimits {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] (F : D ⥤ E) [HasLimitsOfSize.{w, w'} D] [PreservesLimitsOfSize.{w, w'} F] : PreservesLimitsOfSize.{w, w'} ((whiskeringRight C D E).obj F) := ⟨inferInstance⟩ instance whiskeringRightPreservesColimits {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] (F : D ⥤ E) [HasColimitsOfSize.{w, w'} D] [PreservesColimitsOfSize.{w, w'} F] : PreservesColimitsOfSize.{w, w'} ((whiskeringRight C D E).obj F) := ⟨inferInstance⟩ /-- If `Lan F.op : (Cᵒᵖ ⥤ Type*) ⥤ (Dᵒᵖ ⥤ Type*)` preserves limits of shape `J`, so will `F`. -/ lemma preservesLimit_of_lan_preservesLimit {C D : Type u} [SmallCategory C] [SmallCategory D] (F : C ⥤ D) (J : Type u) [SmallCategory J] [PreservesLimitsOfShape J (F.op.lan : _ ⥤ Dᵒᵖ ⥤ Type u)] : PreservesLimitsOfShape J F := letI := preservesLimitsOfShape_of_natIso (J := J) (Presheaf.compULiftYonedaIsoULiftYonedaCompLan.{u} F).symm preservesLimitsOfShape_of_reflects_of_preserves F uliftYoneda.{u} /-- `F : C ⥤ D ⥤ E` preserves finite limits if it does for each `d : D`. -/ lemma preservesFiniteLimits_of_evaluation {D : Type*} [Category D] {E : Type*} [Category E] (F : C ⥤ D ⥤ E) (h : ∀ d : D, PreservesFiniteLimits (F ⋙ (evaluation D E).obj d)) : PreservesFiniteLimits F := ⟨fun J _ _ => preservesLimitsOfShape_of_evaluation F J fun k => (h k).preservesFiniteLimits _⟩ /-- `F : C ⥤ D ⥤ E` preserves finite limits if it does for each `d : D`. -/ lemma preservesFiniteColimits_of_evaluation {D : Type*} [Category D] {E : Type*} [Category E] (F : C ⥤ D ⥤ E) (h : ∀ d : D, PreservesFiniteColimits (F ⋙ (evaluation D E).obj d)) : PreservesFiniteColimits F := ⟨fun J _ _ => preservesColimitsOfShape_of_evaluation F J fun k => (h k).preservesFiniteColimits _⟩ end section variable {C : Type u} [Category.{v} C] variable {J : Type u₁} [Category.{v₁} J] variable {K : Type u₂} [Category.{v₂} K] variable {D : Type u₃} [Category.{v₃} D] section variable [HasLimitsOfShape J C] [HasColimitsOfShape K C] variable [PreservesLimitsOfShape J (colim : (K ⥤ C) ⥤ _)] noncomputable instance : PreservesLimitsOfShape J (colim : (K ⥤ D ⥤ C) ⥤ _) := preservesLimitsOfShape_of_evaluation _ _ (fun d => let i : (colim : (K ⥤ D ⥤ C) ⥤ _) ⋙ (evaluation D C).obj d ≅ colimit ((whiskeringRight K (D ⥤ C) C).obj ((evaluation D C).obj d)).flip := NatIso.ofComponents (fun X => (colimitObjIsoColimitCompEvaluation _ _) ≪≫ (by exact HasColimit.isoOfNatIso (Iso.refl _)) ≪≫ (colimitObjIsoColimitCompEvaluation _ _).symm) (fun {F G} η => colimit_obj_ext (fun j => by simp [← NatTrans.comp_app_assoc])) preservesLimitsOfShape_of_natIso (i ≪≫ colimitFlipIsoCompColim _).symm) end section variable [HasColimitsOfShape J C] [HasLimitsOfShape K C] variable [PreservesColimitsOfShape J (lim : (K ⥤ C) ⥤ _)] noncomputable instance : PreservesColimitsOfShape J (lim : (K ⥤ D ⥤ C) ⥤ _) := preservesColimitsOfShape_of_evaluation _ _ (fun d => let i : (lim : (K ⥤ D ⥤ C) ⥤ _) ⋙ (evaluation D C).obj d ≅ limit ((whiskeringRight K (D ⥤ C) C).obj ((evaluation D C).obj d)).flip := NatIso.ofComponents (fun X => (limitObjIsoLimitCompEvaluation _ _) ≪≫ (by exact HasLimit.isoOfNatIso (Iso.refl _)) ≪≫ (limitObjIsoLimitCompEvaluation _ _).symm) (fun {F G} η => limit_obj_ext (fun j => by simp [← NatTrans.comp_app])) preservesColimitsOfShape_of_natIso (i ≪≫ limitFlipIsoCompLim _).symm) end end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Creates/Finite.lean
import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.FinCategory.AsType /-! # Creation of finite limits This file defines the classes `CreatesFiniteLimits`, `CreatesFiniteColimits`, `CreatesFiniteProducts` and `CreatesFiniteCoproducts`. -/ namespace CategoryTheory.Limits universe w w' v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] /-- We say that a functor creates finite limits if it creates all limits of shape `J` where `J : Type` is a finite category. -/ class CreatesFiniteLimits (F : C ⥤ D) where /-- `F` creates all finite limits. -/ createsFiniteLimits : ∀ (J : Type) [SmallCategory J] [FinCategory J], CreatesLimitsOfShape J F := by infer_instance attribute [instance] CreatesFiniteLimits.createsFiniteLimits noncomputable section instance (priority := 100) createsLimitsOfShapeOfCreatesFiniteLimits (F : C ⥤ D) [CreatesFiniteLimits F] (J : Type w) [SmallCategory J] [FinCategory J] : CreatesLimitsOfShape J F := createsLimitsOfShapeOfEquiv (FinCategory.equivAsType J) _ -- Cannot be an instance because of unbound universe variables. /-- If `F` creates limits of any size, it creates finite limits. -/ def CreatesLimitsOfSize.createsFiniteLimits (F : C ⥤ D) [CreatesLimitsOfSize.{w, w'} F] : CreatesFiniteLimits F where createsFiniteLimits J _ _ := createsLimitsOfShapeOfEquiv ((ShrinkHoms.equivalence.{w} J).trans (Shrink.equivalence.{w'} _)).symm _ instance (priority := 120) CreatesLimitsOfSize0.createsFiniteLimits (F : C ⥤ D) [CreatesLimitsOfSize.{0, 0} F] : CreatesFiniteLimits F := CreatesLimitsOfSize.createsFiniteLimits F instance (priority := 100) CreatesLimits.createsFiniteLimits (F : C ⥤ D) [CreatesLimits F] : CreatesFiniteLimits F := CreatesLimitsOfSize.createsFiniteLimits F attribute [local instance] uliftCategory in /-- If `F` creates finite limits in any universe, then it creates finite limits. -/ def createsFiniteLimitsOfCreatesFiniteLimitsOfSize (F : C ⥤ D) (h : ∀ (J : Type w) {_ : SmallCategory J} (_ : FinCategory J), CreatesLimitsOfShape J F) : CreatesFiniteLimits F where createsFiniteLimits J _ _ := haveI := h (ULiftHom (ULift J)) CategoryTheory.finCategoryUlift createsLimitsOfShapeOfEquiv (ULiftHomULiftCategory.equiv J).symm _ instance compCreatesFiniteLimits (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteLimits F] [CreatesFiniteLimits G] : CreatesFiniteLimits (F ⋙ G) where createsFiniteLimits _ _ _ := compCreatesLimitsOfShape F G /-- Transfer creation of finite limits along a natural isomorphism in the functor. -/ def createsFiniteLimitsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteLimits F] : CreatesFiniteLimits G where createsFiniteLimits _ _ _ := createsLimitsOfShapeOfNatIso h theorem hasFiniteLimits_of_hasLimitsLimits_of_createsFiniteLimits (F : C ⥤ D) [HasFiniteLimits D] [CreatesFiniteLimits F] : HasFiniteLimits C where out _ _ _ := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape F instance (priority := 100) preservesFiniteLimits_of_createsFiniteLimits_and_hasFiniteLimits (F : C ⥤ D) [CreatesFiniteLimits F] [HasFiniteLimits D] : PreservesFiniteLimits F where preservesFiniteLimits _ _ _ := inferInstance end /-- We say that a functor creates finite products if it creates all limits of shape `Discrete J` where `J : Type` is finite. -/ class CreatesFiniteProducts (F : C ⥤ D) where /-- `F` creates all finite limits. -/ creates : ∀ (J : Type) [Fintype J], CreatesLimitsOfShape (Discrete J) F := by infer_instance attribute [instance] CreatesFiniteProducts.creates noncomputable section instance (priority := 100) createsLimitsOfShapeOfCreatesFiniteProducts (F : C ⥤ D) [CreatesFiniteProducts F] (J : Type w) [Finite J] : CreatesLimitsOfShape (Discrete J) F := createsLimitsOfShapeOfEquiv (Discrete.equivalence (Finite.exists_equiv_fin J).choose_spec.some.symm) F instance compCreatesFiniteProducts (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteProducts F] [CreatesFiniteProducts G] : CreatesFiniteProducts (F ⋙ G) where creates _ _ := compCreatesLimitsOfShape _ _ /-- Transfer creation of finite products along a natural isomorphism in the functor. -/ def createsFiniteProductsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteProducts F] : CreatesFiniteProducts G where creates _ _ := createsLimitsOfShapeOfNatIso h instance (F : C ⥤ D) [CreatesFiniteLimits F] : CreatesFiniteProducts F where creates _ _ := inferInstance end /-- We say that a functor creates finite colimits if it creates all colimits of shape `J` where `J : Type` is a finite category. -/ class CreatesFiniteColimits (F : C ⥤ D) where /-- `F` creates all finite colimits. -/ createsFiniteColimits : ∀ (J : Type) [SmallCategory J] [FinCategory J], CreatesColimitsOfShape J F := by infer_instance attribute [instance] CreatesFiniteColimits.createsFiniteColimits noncomputable section instance (priority := 100) createsColimitsOfShapeOfCreatesFiniteColimits (F : C ⥤ D) [CreatesFiniteColimits F] (J : Type w) [SmallCategory J] [FinCategory J] : CreatesColimitsOfShape J F := createsColimitsOfShapeOfEquiv (FinCategory.equivAsType J) _ -- Cannot be an instance because of unbound universe variables. /-- If `F` creates colimits of any size, it creates finite colimits. -/ def CreatesColimitsOfSize.createsFiniteColimits (F : C ⥤ D) [CreatesColimitsOfSize.{w, w'} F] : CreatesFiniteColimits F where createsFiniteColimits J _ _ := createsColimitsOfShapeOfEquiv ((ShrinkHoms.equivalence.{w} J).trans (Shrink.equivalence.{w'} _)).symm _ instance (priority := 120) CreatesColimitsOfSize0.createsFiniteColimits (F : C ⥤ D) [CreatesColimitsOfSize.{0, 0} F] : CreatesFiniteColimits F := CreatesColimitsOfSize.createsFiniteColimits F instance (priority := 100) CreatesColimits.createsFiniteColimits (F : C ⥤ D) [CreatesColimits F] : CreatesFiniteColimits F := CreatesColimitsOfSize.createsFiniteColimits F attribute [local instance] uliftCategory in /-- If `F` creates finite colimits in any universe, then it creates finite colimits. -/ def createsFiniteColimitsOfCreatesFiniteColimitsOfSize (F : C ⥤ D) (h : ∀ (J : Type w) {_ : SmallCategory J} (_ : FinCategory J), CreatesColimitsOfShape J F) : CreatesFiniteColimits F where createsFiniteColimits J _ _ := haveI := h (ULiftHom (ULift J)) CategoryTheory.finCategoryUlift createsColimitsOfShapeOfEquiv (ULiftHomULiftCategory.equiv J).symm _ instance compCreatesFiniteColimits (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteColimits F] [CreatesFiniteColimits G] : CreatesFiniteColimits (F ⋙ G) where createsFiniteColimits _ _ _ := compCreatesColimitsOfShape F G /-- Transfer creation of finite colimits along a natural isomorphism in the functor. -/ def createsFiniteColimitsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteColimits F] : CreatesFiniteColimits G where createsFiniteColimits _ _ _ := createsColimitsOfShapeOfNatIso h theorem hasFiniteColimits_of_hasColimits_of_createsFiniteColimits (F : C ⥤ D) [HasFiniteColimits D] [CreatesFiniteColimits F] : HasFiniteColimits C where out _ _ _ := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape F instance (priority := 100) preservesFiniteColimits_of_createsFiniteColimits_and_hasFiniteColimits (F : C ⥤ D) [CreatesFiniteColimits F] [HasFiniteColimits D] : PreservesFiniteColimits F where preservesFiniteColimits _ _ _ := inferInstance end /-- We say that a functor creates finite limits if it creates all limits of shape `J` where `J : Type` is a finite category. -/ class CreatesFiniteCoproducts (F : C ⥤ D) where /-- `F` creates all finite limits. -/ creates : ∀ (J : Type) [Fintype J], CreatesColimitsOfShape (Discrete J) F := by infer_instance attribute [instance] CreatesFiniteCoproducts.creates noncomputable section instance (priority := 100) createsColimitsOfShapeOfCreatesFiniteProducts (F : C ⥤ D) [CreatesFiniteCoproducts F] (J : Type w) [Finite J] : CreatesColimitsOfShape (Discrete J) F := createsColimitsOfShapeOfEquiv (Discrete.equivalence (Finite.exists_equiv_fin J).choose_spec.some.symm) F instance compCreatesFiniteCoproducts (F : C ⥤ D) (G : D ⥤ E) [CreatesFiniteCoproducts F] [CreatesFiniteCoproducts G] : CreatesFiniteCoproducts (F ⋙ G) where creates _ _ := compCreatesColimitsOfShape _ _ /-- Transfer creation of finite limits along a natural isomorphism in the functor. -/ def createsFiniteCoproductsOfNatIso {F G : C ⥤ D} {h : F ≅ G} [CreatesFiniteCoproducts F] : CreatesFiniteCoproducts G where creates _ _ := createsColimitsOfShapeOfNatIso h instance (F : C ⥤ D) [CreatesFiniteColimits F] : CreatesFiniteCoproducts F where creates _ _ := inferInstance end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Creates/Pullbacks.lean
import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Creation of limits and pullbacks We show some lemmas relating creation of (co)limits and pullbacks (resp. pushouts). -/ namespace CategoryTheory.Limits variable {C : Type*} [Category C] {D : Type*} [Category D] lemma HasPullback.of_createsLimit (F : C ⥤ D) {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [CreatesLimit (cospan f g) F] [HasPullback (F.map f) (F.map g)] : HasPullback f g := have : HasLimit (cospan f g ⋙ F) := hasLimit_of_iso (cospanCompIso F f g).symm hasLimit_of_created _ F lemma HasPushout.of_createsColimit (F : C ⥤ D) {X Y S : C} (f : S ⟶ X) (g : S ⟶ Y) [CreatesColimit (span f g) F] [HasPushout (F.map f) (F.map g)] : HasPushout f g := have : HasColimit (span f g ⋙ F) := hasColimit_of_iso (spanCompIso F f g) hasColimit_of_created _ F end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Biproducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero /-! # Preservation of biproducts We define the image of a (binary) bicone under a functor that preserves zero morphisms and define classes `PreservesBiproduct` and `PreservesBinaryBiproduct`. We then * show that a functor that preserves biproducts of a two-element type preserves binary biproducts, * construct the comparison morphisms between the image of a biproduct and the biproduct of the images and show that the biproduct is preserved if one of them is an isomorphism, * give the canonical isomorphism between the image of a biproduct and the biproduct of the images in case that the biproduct is preserved. -/ universe w₁ w₂ v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] section HasZeroMorphisms variable [HasZeroMorphisms C] [HasZeroMorphisms D] namespace Functor section Map variable (F : C ⥤ D) [PreservesZeroMorphisms F] section Bicone variable {J : Type w₁} /-- The image of a bicone under a functor. -/ @[simps] def mapBicone {f : J → C} (b : Bicone f) : Bicone (F.obj ∘ f) where pt := F.obj b.pt π j := F.map (b.π j) ι j := F.map (b.ι j) ι_π j j' := by rw [← F.map_comp] split_ifs with h · subst h simp only [bicone_ι_π_self, CategoryTheory.Functor.map_id, eqToHom_refl]; dsimp · rw [bicone_ι_π_ne _ h, F.map_zero] theorem mapBicone_whisker {K : Type w₂} {g : K ≃ J} {f : J → C} (c : Bicone f) : F.mapBicone (c.whisker g) = (F.mapBicone c).whisker g := rfl end Bicone /-- The image of a binary bicone under a functor. -/ @[simps!] def mapBinaryBicone {X Y : C} (b : BinaryBicone X Y) : BinaryBicone (F.obj X) (F.obj Y) := (BinaryBicones.functoriality _ _ F).obj b end Map end Functor open CategoryTheory.Functor namespace Limits section Bicone variable {J : Type w₁} {K : Type w₂} /-- A functor `F` preserves biproducts of `f` if `F` maps every bilimit bicone over `f` to a bilimit bicone over `F.obj ∘ f`. -/ class PreservesBiproduct (f : J → C) (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where preserves : ∀ {b : Bicone f}, b.IsBilimit → Nonempty (F.mapBicone b).IsBilimit attribute [inherit_doc PreservesBiproduct] PreservesBiproduct.preserves /-- A functor `F` preserves biproducts of `f` if `F` maps every bilimit bicone over `f` to a bilimit bicone over `F.obj ∘ f`. -/ def isBilimitOfPreserves {f : J → C} (F : C ⥤ D) [PreservesZeroMorphisms F] [PreservesBiproduct f F] {b : Bicone f} (hb : b.IsBilimit) : (F.mapBicone b).IsBilimit := (PreservesBiproduct.preserves hb).some variable (J) /-- A functor `F` preserves biproducts of shape `J` if it preserves biproducts of `f` for every `f : J → C`. -/ class PreservesBiproductsOfShape (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where preserves : ∀ {f : J → C}, PreservesBiproduct f F attribute [inherit_doc PreservesBiproductsOfShape] PreservesBiproductsOfShape.preserves attribute [instance 100] PreservesBiproductsOfShape.preserves end Bicone /-- A functor `F` preserves finite biproducts if it preserves biproducts of shape `J` whenever `J` is a finite type. -/ class PreservesFiniteBiproducts (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where preserves : ∀ {J : Type} [Finite J], PreservesBiproductsOfShape J F attribute [inherit_doc PreservesFiniteBiproducts] PreservesFiniteBiproducts.preserves attribute [instance 100] PreservesFiniteBiproducts.preserves /-- A functor `F` preserves biproducts if it preserves biproducts of any shape `J` of size `w`. The usual notion of preservation of biproducts is recovered by choosing `w` to be the universe of the morphisms of `C`. -/ class PreservesBiproducts (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where preserves : ∀ {J : Type w₁}, PreservesBiproductsOfShape J F attribute [inherit_doc PreservesBiproducts] PreservesBiproducts.preserves attribute [instance 100] PreservesBiproducts.preserves /-- Preserving biproducts at a bigger universe level implies preserving biproducts at a smaller universe level. -/ lemma preservesBiproducts_shrink (F : C ⥤ D) [PreservesZeroMorphisms F] [PreservesBiproducts.{max w₁ w₂} F] : PreservesBiproducts.{w₁} F := ⟨fun {_} => ⟨fun {_} => ⟨fun {b} ib => ⟨((F.mapBicone b).whiskerIsBilimitIff _).toFun (isBilimitOfPreserves F ((b.whiskerIsBilimitIff Equiv.ulift.{w₂}).invFun ib))⟩⟩⟩⟩ instance (priority := 100) preservesFiniteBiproductsOfPreservesBiproducts (F : C ⥤ D) [PreservesZeroMorphisms F] [PreservesBiproducts.{w₁} F] : PreservesFiniteBiproducts F where preserves {J} _ := by letI := preservesBiproducts_shrink.{0} F; infer_instance /-- A functor `F` preserves binary biproducts of `X` and `Y` if `F` maps every bilimit bicone over `X` and `Y` to a bilimit bicone over `F.obj X` and `F.obj Y`. -/ class PreservesBinaryBiproduct (X Y : C) (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where preserves : ∀ {b : BinaryBicone X Y}, b.IsBilimit → Nonempty ((F.mapBinaryBicone b).IsBilimit) attribute [inherit_doc PreservesBinaryBiproduct] PreservesBinaryBiproduct.preserves /-- A functor `F` preserves binary biproducts of `X` and `Y` if `F` maps every bilimit bicone over `X` and `Y` to a bilimit bicone over `F.obj X` and `F.obj Y`. -/ def isBinaryBilimitOfPreserves {X Y : C} (F : C ⥤ D) [PreservesZeroMorphisms F] [PreservesBinaryBiproduct X Y F] {b : BinaryBicone X Y} (hb : b.IsBilimit) : (F.mapBinaryBicone b).IsBilimit := (PreservesBinaryBiproduct.preserves hb).some /-- A functor `F` preserves binary biproducts if it preserves the binary biproduct of `X` and `Y` for all `X` and `Y`. -/ class PreservesBinaryBiproducts (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where preserves : ∀ {X Y : C}, PreservesBinaryBiproduct X Y F := by infer_instance attribute [inherit_doc PreservesBinaryBiproducts] PreservesBinaryBiproducts.preserves /-- A functor that preserves biproducts of a pair preserves binary biproducts. -/ lemma preservesBinaryBiproduct_of_preservesBiproduct (F : C ⥤ D) [PreservesZeroMorphisms F] (X Y : C) [PreservesBiproduct (pairFunction X Y) F] : PreservesBinaryBiproduct X Y F where preserves {b} hb := ⟨{ isLimit := IsLimit.ofIsoLimit ((IsLimit.postcomposeHomEquiv (diagramIsoPair _) _).symm (isBilimitOfPreserves F (b.toBiconeIsBilimit.symm hb)).isLimit) <| Cones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp isColimit := IsColimit.ofIsoColimit ((IsColimit.precomposeInvEquiv (diagramIsoPair _) _).symm (isBilimitOfPreserves F (b.toBiconeIsBilimit.symm hb)).isColimit) <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp }⟩ /-- A functor that preserves biproducts of a pair preserves binary biproducts. -/ lemma preservesBinaryBiproducts_of_preservesBiproducts (F : C ⥤ D) [PreservesZeroMorphisms F] [PreservesBiproductsOfShape WalkingPair F] : PreservesBinaryBiproducts F where preserves {X} Y := preservesBinaryBiproduct_of_preservesBiproduct F X Y attribute [instance 100] PreservesBinaryBiproducts.preserves end Limits open CategoryTheory.Limits namespace Functor section Bicone variable {J : Type w₁} (F : C ⥤ D) (f : J → C) [HasBiproduct f] section variable [HasBiproduct (F.obj ∘ f)] /-- As for products, any functor between categories with biproducts gives rise to a morphism `F.obj (⨁ f) ⟶ ⨁ (F.obj ∘ f)`. -/ def biproductComparison : F.obj (⨁ f) ⟶ ⨁ F.obj ∘ f := biproduct.lift fun j => F.map (biproduct.π f j) @[reassoc (attr := simp)] theorem biproductComparison_π (j : J) : biproductComparison F f ≫ biproduct.π _ j = F.map (biproduct.π f j) := biproduct.lift_π _ _ /-- As for coproducts, any functor between categories with biproducts gives rise to a morphism `⨁ (F.obj ∘ f) ⟶ F.obj (⨁ f)` -/ def biproductComparison' : ⨁ F.obj ∘ f ⟶ F.obj (⨁ f) := biproduct.desc fun j => F.map (biproduct.ι f j) @[reassoc (attr := simp)] theorem ι_biproductComparison' (j : J) : biproduct.ι _ j ≫ biproductComparison' F f = F.map (biproduct.ι f j) := biproduct.ι_desc _ _ variable [PreservesZeroMorphisms F] /-- The composition in the opposite direction is equal to the identity if and only if `F` preserves the biproduct, see `preservesBiproduct_of_monoBiproductComparison`. -/ @[reassoc (attr := simp)] theorem biproductComparison'_comp_biproductComparison : biproductComparison' F f ≫ biproductComparison F f = 𝟙 (⨁ F.obj ∘ f) := by classical ext simp [biproduct.ι_π, ← Functor.map_comp, eqToHom_map] /-- `biproduct_comparison F f` is a split epimorphism. -/ @[simps] def splitEpiBiproductComparison : SplitEpi (biproductComparison F f) where section_ := biproductComparison' F f id := by simp instance : IsSplitEpi (biproductComparison F f) := IsSplitEpi.mk' (splitEpiBiproductComparison F f) /-- `biproduct_comparison' F f` is a split monomorphism. -/ @[simps] def splitMonoBiproductComparison' : SplitMono (biproductComparison' F f) where retraction := biproductComparison F f id := by simp instance : IsSplitMono (biproductComparison' F f) := IsSplitMono.mk' (splitMonoBiproductComparison' F f) end variable [PreservesZeroMorphisms F] [PreservesBiproduct f F] instance hasBiproduct_of_preserves : HasBiproduct (F.obj ∘ f) := HasBiproduct.mk { bicone := F.mapBicone (biproduct.bicone f) isBilimit := isBilimitOfPreserves _ (biproduct.isBilimit _) } /-- This instance applies more often than `hasBiproduct_of_preserves`, but the discrimination tree key matches a lot more (since it does not look through lambdas). -/ instance (priority := low) hasBiproduct_of_preserves' : HasBiproduct fun i => F.obj (f i) := HasBiproduct.mk { bicone := F.mapBicone (biproduct.bicone f) isBilimit := isBilimitOfPreserves _ (biproduct.isBilimit _) } /-- If `F` preserves a biproduct, we get a definitionally nice isomorphism `F.obj (⨁ f) ≅ ⨁ (F.obj ∘ f)`. -/ abbrev mapBiproduct : F.obj (⨁ f) ≅ ⨁ F.obj ∘ f := biproduct.uniqueUpToIso _ (isBilimitOfPreserves _ (biproduct.isBilimit _)) theorem mapBiproduct_hom : (mapBiproduct F f).hom = biproduct.lift fun j => F.map (biproduct.π f j) := rfl theorem mapBiproduct_inv : (mapBiproduct F f).inv = biproduct.desc fun j => F.map (biproduct.ι f j) := rfl end Bicone variable (F : C ⥤ D) (X Y : C) [HasBinaryBiproduct X Y] section variable [HasBinaryBiproduct (F.obj X) (F.obj Y)] /-- As for products, any functor between categories with binary biproducts gives rise to a morphism `F.obj (X ⊞ Y) ⟶ F.obj X ⊞ F.obj Y`. -/ def biprodComparison : F.obj (X ⊞ Y) ⟶ F.obj X ⊞ F.obj Y := biprod.lift (F.map biprod.fst) (F.map biprod.snd) @[reassoc (attr := simp)] theorem biprodComparison_fst : biprodComparison F X Y ≫ biprod.fst = F.map biprod.fst := biprod.lift_fst _ _ @[reassoc (attr := simp)] theorem biprodComparison_snd : biprodComparison F X Y ≫ biprod.snd = F.map biprod.snd := biprod.lift_snd _ _ /-- As for coproducts, any functor between categories with binary biproducts gives rise to a morphism `F.obj X ⊞ F.obj Y ⟶ F.obj (X ⊞ Y)`. -/ def biprodComparison' : F.obj X ⊞ F.obj Y ⟶ F.obj (X ⊞ Y) := biprod.desc (F.map biprod.inl) (F.map biprod.inr) @[reassoc (attr := simp)] theorem inl_biprodComparison' : biprod.inl ≫ biprodComparison' F X Y = F.map biprod.inl := biprod.inl_desc _ _ @[reassoc (attr := simp)] theorem inr_biprodComparison' : biprod.inr ≫ biprodComparison' F X Y = F.map biprod.inr := biprod.inr_desc _ _ variable [PreservesZeroMorphisms F] /-- The composition in the opposite direction is equal to the identity if and only if `F` preserves the biproduct, see `preservesBinaryBiproduct_of_monoBiprodComparison`. -/ @[reassoc (attr := simp)] theorem biprodComparison'_comp_biprodComparison : biprodComparison' F X Y ≫ biprodComparison F X Y = 𝟙 (F.obj X ⊞ F.obj Y) := by ext <;> simp [← Functor.map_comp] /-- `biprodComparison F X Y` is a split epi. -/ @[simps] def splitEpiBiprodComparison : SplitEpi (biprodComparison F X Y) where section_ := biprodComparison' F X Y id := by simp instance : IsSplitEpi (biprodComparison F X Y) := IsSplitEpi.mk' (splitEpiBiprodComparison F X Y) /-- `biprodComparison' F X Y` is a split mono. -/ @[simps] def splitMonoBiprodComparison' : SplitMono (biprodComparison' F X Y) where retraction := biprodComparison F X Y id := by simp instance : IsSplitMono (biprodComparison' F X Y) := IsSplitMono.mk' (splitMonoBiprodComparison' F X Y) end variable [PreservesZeroMorphisms F] [PreservesBinaryBiproduct X Y F] instance hasBinaryBiproduct_of_preserves : HasBinaryBiproduct (F.obj X) (F.obj Y) := HasBinaryBiproduct.mk { bicone := F.mapBinaryBicone (BinaryBiproduct.bicone X Y) isBilimit := isBinaryBilimitOfPreserves F (BinaryBiproduct.isBilimit _ _) } /-- If `F` preserves a binary biproduct, we get a definitionally nice isomorphism `F.obj (X ⊞ Y) ≅ F.obj X ⊞ F.obj Y`. -/ abbrev mapBiprod : F.obj (X ⊞ Y) ≅ F.obj X ⊞ F.obj Y := biprod.uniqueUpToIso _ _ (isBinaryBilimitOfPreserves F (BinaryBiproduct.isBilimit _ _)) theorem mapBiprod_hom : (mapBiprod F X Y).hom = biprod.lift (F.map biprod.fst) (F.map biprod.snd) := rfl theorem mapBiprod_inv : (mapBiprod F X Y).inv = biprod.desc (F.map biprod.inl) (F.map biprod.inr) := rfl end Functor namespace Limits variable (F : C ⥤ D) [PreservesZeroMorphisms F] section Bicone variable {J : Type w₁} (f : J → C) [HasBiproduct f] [PreservesBiproduct f F] {W : C} theorem biproduct.map_lift_mapBiprod (g : ∀ j, W ⟶ f j) : F.map (biproduct.lift g) ≫ (F.mapBiproduct f).hom = biproduct.lift fun j => F.map (g j) := by ext j dsimp only [Function.comp_def] simp only [mapBiproduct_hom, Category.assoc, biproduct.lift_π, ← F.map_comp] theorem biproduct.mapBiproduct_inv_map_desc (g : ∀ j, f j ⟶ W) : (F.mapBiproduct f).inv ≫ F.map (biproduct.desc g) = biproduct.desc fun j => F.map (g j) := by ext j dsimp only [Function.comp_def] simp only [mapBiproduct_inv, ← Category.assoc, biproduct.ι_desc, ← F.map_comp] theorem biproduct.mapBiproduct_hom_desc (g : ∀ j, f j ⟶ W) : ((F.mapBiproduct f).hom ≫ biproduct.desc fun j => F.map (g j)) = F.map (biproduct.desc g) := by rw [← biproduct.mapBiproduct_inv_map_desc, Iso.hom_inv_id_assoc] end Bicone section BinaryBicone variable (X Y : C) [HasBinaryBiproduct X Y] [PreservesBinaryBiproduct X Y F] {W : C} theorem biprod.map_lift_mapBiprod (f : W ⟶ X) (g : W ⟶ Y) : F.map (biprod.lift f g) ≫ (F.mapBiprod X Y).hom = biprod.lift (F.map f) (F.map g) := by ext <;> simp [mapBiprod, ← F.map_comp] theorem biprod.lift_mapBiprod (f : W ⟶ X) (g : W ⟶ Y) : biprod.lift (F.map f) (F.map g) ≫ (F.mapBiprod X Y).inv = F.map (biprod.lift f g) := by rw [← biprod.map_lift_mapBiprod, Category.assoc, Iso.hom_inv_id, Category.comp_id] theorem biprod.mapBiprod_inv_map_desc (f : X ⟶ W) (g : Y ⟶ W) : (F.mapBiprod X Y).inv ≫ F.map (biprod.desc f g) = biprod.desc (F.map f) (F.map g) := by ext <;> simp [mapBiprod, ← F.map_comp] theorem biprod.mapBiprod_hom_desc (f : X ⟶ W) (g : Y ⟶ W) : (F.mapBiprod X Y).hom ≫ biprod.desc (F.map f) (F.map g) = F.map (biprod.desc f g) := by rw [← biprod.mapBiprod_inv_map_desc, Iso.hom_inv_id_assoc] end BinaryBicone end Limits end HasZeroMorphisms end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Products.lean
import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Preserving products Constructions to relate the notions of preserving products and reflecting products to concrete fans. In particular, we show that `piComparison G f` is an isomorphism iff `G` preserves the limit of `f`. -/ noncomputable section universe w v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) namespace CategoryTheory.Limits variable {J : Type w} (f : J → C) /-- The map of a fan is a limit iff the fan consisting of the mapped morphisms is a limit. This essentially lets us commute `Fan.mk` with `Functor.mapCone`. -/ def isLimitMapConeFanMkEquiv {P : C} (g : ∀ j, P ⟶ f j) : IsLimit (Functor.mapCone G (Fan.mk P g)) ≃ IsLimit (Fan.mk _ fun j => G.map (g j) : Fan fun j => G.obj (f j)) := by refine (IsLimit.postcomposeHomEquiv ?_ _).symm.trans (IsLimit.equivIsoLimit ?_) · refine Discrete.natIso fun j => Iso.refl (G.obj (f j.as)) refine Cones.ext (Iso.refl _) fun j => by dsimp; cases j; simp /-- The property of preserving products expressed in terms of fans. -/ def isLimitFanMkObjOfIsLimit [PreservesLimit (Discrete.functor f) G] {P : C} (g : ∀ j, P ⟶ f j) (t : IsLimit (Fan.mk _ g)) : IsLimit (Fan.mk (G.obj P) fun j => G.map (g j) : Fan fun j => G.obj (f j)) := isLimitMapConeFanMkEquiv _ _ _ (isLimitOfPreserves G t) /-- The property of reflecting products expressed in terms of fans. -/ def isLimitOfIsLimitFanMkObj [ReflectsLimit (Discrete.functor f) G] {P : C} (g : ∀ j, P ⟶ f j) (t : IsLimit (Fan.mk _ fun j => G.map (g j) : Fan fun j => G.obj (f j))) : IsLimit (Fan.mk P g) := isLimitOfReflects G ((isLimitMapConeFanMkEquiv _ _ _).symm t) section variable [HasProduct f] /-- If `G` preserves products and `C` has them, then the fan constructed of the mapped projection of a product is a limit. -/ def isLimitOfHasProductOfPreservesLimit [PreservesLimit (Discrete.functor f) G] : IsLimit (Fan.mk _ fun j : J => G.map (Pi.π f j) : Fan fun j => G.obj (f j)) := isLimitFanMkObjOfIsLimit G f _ (productIsProduct _) variable [HasProduct fun j : J => G.obj (f j)] /-- If `pi_comparison G f` is an isomorphism, then `G` preserves the limit of `f`. -/ lemma PreservesProduct.of_iso_comparison [i : IsIso (piComparison G f)] : PreservesLimit (Discrete.functor f) G := by apply preservesLimit_of_preserves_limit_cone (productIsProduct f) apply (isLimitMapConeFanMkEquiv _ _ _).symm _ exact @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (Discrete.functor fun j : J => G.obj (f j))) i @[reassoc (attr := simp)] lemma inv_piComparison_comp_map_π [IsIso (piComparison G f)] (j : J) : inv (piComparison G f) ≫ G.map (Pi.π _ j) = Pi.π (fun x ↦ (G.obj (f x))) j := by simp only [IsIso.inv_comp_eq, piComparison_comp_π] variable [PreservesLimit (Discrete.functor f) G] /-- If `G` preserves limits, we have an isomorphism from the image of a product to the product of the images. -/ def PreservesProduct.iso : G.obj (∏ᶜ f) ≅ ∏ᶜ fun j => G.obj (f j) := IsLimit.conePointUniqueUpToIso (isLimitOfHasProductOfPreservesLimit G f) (limit.isLimit _) @[simp] theorem PreservesProduct.iso_hom : (PreservesProduct.iso G f).hom = piComparison G f := rfl instance : IsIso (piComparison G f) := by rw [← PreservesProduct.iso_hom] infer_instance end /-- The map of a cofan is a colimit iff the cofan consisting of the mapped morphisms is a colimit. This essentially lets us commute `Cofan.mk` with `Functor.mapCocone`. -/ def isColimitMapCoconeCofanMkEquiv {P : C} (g : ∀ j, f j ⟶ P) : IsColimit (Functor.mapCocone G (Cofan.mk P g)) ≃ IsColimit (Cofan.mk _ fun j => G.map (g j) : Cofan fun j => G.obj (f j)) := by refine (IsColimit.precomposeHomEquiv ?_ _).symm.trans (IsColimit.equivIsoColimit ?_) · refine Discrete.natIso fun j => Iso.refl (G.obj (f j.as)) refine Cocones.ext (Iso.refl _) fun j => by dsimp; cases j; simp /-- The property of preserving coproducts expressed in terms of cofans. -/ def isColimitCofanMkObjOfIsColimit [PreservesColimit (Discrete.functor f) G] {P : C} (g : ∀ j, f j ⟶ P) (t : IsColimit (Cofan.mk _ g)) : IsColimit (Cofan.mk (G.obj P) fun j => G.map (g j) : Cofan fun j => G.obj (f j)) := isColimitMapCoconeCofanMkEquiv _ _ _ (isColimitOfPreserves G t) /-- The property of reflecting coproducts expressed in terms of cofans. -/ def isColimitOfIsColimitCofanMkObj [ReflectsColimit (Discrete.functor f) G] {P : C} (g : ∀ j, f j ⟶ P) (t : IsColimit (Cofan.mk _ fun j => G.map (g j) : Cofan fun j => G.obj (f j))) : IsColimit (Cofan.mk P g) := isColimitOfReflects G ((isColimitMapCoconeCofanMkEquiv _ _ _).symm t) section variable [HasCoproduct f] /-- If `G` preserves coproducts and `C` has them, then the cofan constructed of the mapped inclusion of a coproduct is a colimit. -/ def isColimitOfHasCoproductOfPreservesColimit [PreservesColimit (Discrete.functor f) G] : IsColimit (Cofan.mk _ fun j : J => G.map (Sigma.ι f j) : Cofan fun j => G.obj (f j)) := isColimitCofanMkObjOfIsColimit G f _ (coproductIsCoproduct _) variable [HasCoproduct fun j : J => G.obj (f j)] /-- If `sigma_comparison G f` is an isomorphism, then `G` preserves the colimit of `f`. -/ lemma PreservesCoproduct.of_iso_comparison [i : IsIso (sigmaComparison G f)] : PreservesColimit (Discrete.functor f) G := by apply preservesColimit_of_preserves_colimit_cocone (coproductIsCoproduct f) apply (isColimitMapCoconeCofanMkEquiv _ _ _).symm _ exact @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (Discrete.functor fun j : J => G.obj (f j))) i @[reassoc (attr := simp)] lemma map_ι_comp_inv_sigmaComparison [IsIso (sigmaComparison G f)] (j : J) : G.map (Sigma.ι _ j) ≫ inv (sigmaComparison G f) = Sigma.ι (fun x ↦ (G.obj (f x))) j := by simp variable [PreservesColimit (Discrete.functor f) G] /-- If `G` preserves colimits, we have an isomorphism from the image of a coproduct to the coproduct of the images. -/ def PreservesCoproduct.iso : G.obj (∐ f) ≅ ∐ fun j => G.obj (f j) := IsColimit.coconePointUniqueUpToIso (isColimitOfHasCoproductOfPreservesColimit G f) (colimit.isColimit _) @[simp] theorem PreservesCoproduct.inv_hom : (PreservesCoproduct.iso G f).inv = sigmaComparison G f := rfl instance : IsIso (sigmaComparison G f) := by rw [← PreservesCoproduct.inv_hom] infer_instance end /-- If `F` preserves the limit of every `Discrete.functor f`, it preserves all limits of shape `Discrete J`. -/ lemma preservesLimitsOfShape_of_discrete (F : C ⥤ D) [∀ (f : J → C), PreservesLimit (Discrete.functor f) F] : PreservesLimitsOfShape (Discrete J) F where preservesLimit := preservesLimit_of_iso_diagram F (Discrete.natIsoFunctor).symm /-- If `F` preserves the colimit of every `Discrete.functor f`, it preserves all colimits of shape `Discrete J`. -/ lemma preservesColimitsOfShape_of_discrete (F : C ⥤ D) [∀ (f : J → C), PreservesColimit (Discrete.functor f) F] : PreservesColimitsOfShape (Discrete J) F where preservesColimit := preservesColimit_of_iso_diagram F (Discrete.natIsoFunctor).symm end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Terminal.lean
import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Preserving terminal object Constructions to relate the notions of preserving terminal objects and reflecting terminal objects to concrete objects. In particular, we show that `terminalComparison G` is an isomorphism iff `G` preserves terminal objects. -/ universe w v v₁ v₂ u u₁ u₂ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) namespace CategoryTheory.Limits variable (X : C) section Terminal /-- The map of an empty cone is a limit iff the mapped object is terminal. -/ def isLimitMapConeEmptyConeEquiv : IsLimit (G.mapCone (asEmptyCone X)) ≃ IsTerminal (G.obj X) := isLimitEmptyConeEquiv D _ _ (eqToIso rfl) /-- The property of preserving terminal objects expressed in terms of `IsTerminal`. -/ def IsTerminal.isTerminalObj [PreservesLimit (Functor.empty.{0} C) G] (l : IsTerminal X) : IsTerminal (G.obj X) := isLimitMapConeEmptyConeEquiv G X (isLimitOfPreserves G l) /-- The property of reflecting terminal objects expressed in terms of `IsTerminal`. -/ def IsTerminal.isTerminalOfObj [ReflectsLimit (Functor.empty.{0} C) G] (l : IsTerminal (G.obj X)) : IsTerminal X := isLimitOfReflects G ((isLimitMapConeEmptyConeEquiv G X).symm l) /-- A functor that preserves and reflects terminal objects induces an equivalence on `IsTerminal`. -/ def IsTerminal.isTerminalIffObj [PreservesLimit (Functor.empty.{0} C) G] [ReflectsLimit (Functor.empty.{0} C) G] (X : C) : IsTerminal X ≃ IsTerminal (G.obj X) where toFun := IsTerminal.isTerminalObj G X invFun := IsTerminal.isTerminalOfObj G X left_inv := by cat_disch right_inv := by cat_disch /-- Preserving the terminal object implies preserving all limits of the empty diagram. -/ lemma preservesLimitsOfShape_pempty_of_preservesTerminal [PreservesLimit (Functor.empty.{0} C) G] : PreservesLimitsOfShape (Discrete PEmpty.{1}) G where preservesLimit := preservesLimit_of_iso_diagram G (Functor.emptyExt (Functor.empty.{0} C) _) variable [HasTerminal C] /-- If `G` preserves the terminal object and `C` has a terminal object, then the image of the terminal object is terminal. -/ def isLimitOfHasTerminalOfPreservesLimit [PreservesLimit (Functor.empty.{0} C) G] : IsTerminal (G.obj (⊤_ C)) := terminalIsTerminal.isTerminalObj G (⊤_ C) /-- If `C` has a terminal object and `G` preserves terminal objects, then `D` has a terminal object also. Note this property is somewhat unique to (co)limits of the empty diagram: for general `J`, if `C` has limits of shape `J` and `G` preserves them, then `D` does not necessarily have limits of shape `J`. -/ theorem hasTerminal_of_hasTerminal_of_preservesLimit [PreservesLimit (Functor.empty.{0} C) G] : HasTerminal D := ⟨fun F => by haveI := HasLimit.mk ⟨_, isLimitOfHasTerminalOfPreservesLimit G⟩ apply hasLimit_of_iso F.uniqueFromEmpty.symm⟩ variable [HasTerminal D] /-- If the terminal comparison map for `G` is an isomorphism, then `G` preserves terminal objects. -/ lemma PreservesTerminal.of_iso_comparison [i : IsIso (terminalComparison G)] : PreservesLimit (Functor.empty.{0} C) G := by apply preservesLimit_of_preserves_limit_cone terminalIsTerminal apply (isLimitMapConeEmptyConeEquiv _ _).symm _ exact @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (Functor.empty.{0} D)) i /-- If there is any isomorphism `G.obj ⊤ ⟶ ⊤`, then `G` preserves terminal objects. -/ lemma preservesTerminal_of_isIso (f : G.obj (⊤_ C) ⟶ ⊤_ D) [i : IsIso f] : PreservesLimit (Functor.empty.{0} C) G := by rw [Subsingleton.elim f (terminalComparison G)] at i exact PreservesTerminal.of_iso_comparison G /-- If there is any isomorphism `G.obj ⊤ ≅ ⊤`, then `G` preserves terminal objects. -/ lemma preservesTerminal_of_iso (f : G.obj (⊤_ C) ≅ ⊤_ D) : PreservesLimit (Functor.empty.{0} C) G := preservesTerminal_of_isIso G f.hom variable [PreservesLimit (Functor.empty.{0} C) G] /-- If `G` preserves terminal objects, then the terminal comparison map for `G` is an isomorphism. -/ def PreservesTerminal.iso : G.obj (⊤_ C) ≅ ⊤_ D := (isLimitOfHasTerminalOfPreservesLimit G).conePointUniqueUpToIso (limit.isLimit _) @[simp] theorem PreservesTerminal.iso_hom : (PreservesTerminal.iso G).hom = terminalComparison G := rfl instance : IsIso (terminalComparison G) := by rw [← PreservesTerminal.iso_hom] infer_instance end Terminal section Initial /-- The map of an empty cocone is a colimit iff the mapped object is initial. -/ def isColimitMapCoconeEmptyCoconeEquiv : IsColimit (G.mapCocone (asEmptyCocone.{v₁} X)) ≃ IsInitial (G.obj X) := isColimitEmptyCoconeEquiv D _ _ (eqToIso rfl) /-- The property of preserving initial objects expressed in terms of `IsInitial`. -/ def IsInitial.isInitialObj [PreservesColimit (Functor.empty.{0} C) G] (l : IsInitial X) : IsInitial (G.obj X) := isColimitMapCoconeEmptyCoconeEquiv G X (isColimitOfPreserves G l) /-- The property of reflecting initial objects expressed in terms of `IsInitial`. -/ def IsInitial.isInitialOfObj [ReflectsColimit (Functor.empty.{0} C) G] (l : IsInitial (G.obj X)) : IsInitial X := isColimitOfReflects G ((isColimitMapCoconeEmptyCoconeEquiv G X).symm l) /-- A functor that preserves and reflects initial objects induces an equivalence on `IsInitial`. -/ def IsInitial.isInitialIffObj [PreservesColimit (Functor.empty.{0} C) G] [ReflectsColimit (Functor.empty.{0} C) G] (X : C) : IsInitial X ≃ IsInitial (G.obj X) where toFun := IsInitial.isInitialObj G X invFun := IsInitial.isInitialOfObj G X left_inv := by cat_disch right_inv := by cat_disch /-- Preserving the initial object implies preserving all colimits of the empty diagram. -/ lemma preservesColimitsOfShape_pempty_of_preservesInitial [PreservesColimit (Functor.empty.{0} C) G] : PreservesColimitsOfShape (Discrete PEmpty.{1}) G where preservesColimit := preservesColimit_of_iso_diagram G (Functor.emptyExt (Functor.empty.{0} C) _) variable [HasInitial C] /-- If `G` preserves the initial object and `C` has an initial object, then the image of the initial object is initial. -/ def isColimitOfHasInitialOfPreservesColimit [PreservesColimit (Functor.empty.{0} C) G] : IsInitial (G.obj (⊥_ C)) := initialIsInitial.isInitialObj G (⊥_ C) /-- If `C` has an initial object and `G` preserves initial objects, then `D` has an initial object also. Note this property is somewhat unique to colimits of the empty diagram: for general `J`, if `C` has colimits of shape `J` and `G` preserves them, then `D` does not necessarily have colimits of shape `J`. -/ theorem hasInitial_of_hasInitial_of_preservesColimit [PreservesColimit (Functor.empty.{0} C) G] : HasInitial D := ⟨fun F => by haveI := HasColimit.mk ⟨_, isColimitOfHasInitialOfPreservesColimit G⟩ apply hasColimit_of_iso F.uniqueFromEmpty⟩ variable [HasInitial D] /-- If the initial comparison map for `G` is an isomorphism, then `G` preserves initial objects. -/ lemma PreservesInitial.of_iso_comparison [i : IsIso (initialComparison G)] : PreservesColimit (Functor.empty.{0} C) G := by apply preservesColimit_of_preserves_colimit_cocone initialIsInitial apply (isColimitMapCoconeEmptyCoconeEquiv _ _).symm _ exact @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (Functor.empty.{0} D)) i /-- If there is any isomorphism `⊥ ⟶ G.obj ⊥`, then `G` preserves initial objects. -/ lemma preservesInitial_of_isIso (f : ⊥_ D ⟶ G.obj (⊥_ C)) [i : IsIso f] : PreservesColimit (Functor.empty.{0} C) G := by rw [Subsingleton.elim f (initialComparison G)] at i exact PreservesInitial.of_iso_comparison G /-- If there is any isomorphism `⊥ ≅ G.obj ⊥`, then `G` preserves initial objects. -/ lemma preservesInitial_of_iso (f : ⊥_ D ≅ G.obj (⊥_ C)) : PreservesColimit (Functor.empty.{0} C) G := preservesInitial_of_isIso G f.hom variable [PreservesColimit (Functor.empty.{0} C) G] /-- If `G` preserves initial objects, then the initial comparison map for `G` is an isomorphism. -/ def PreservesInitial.iso : G.obj (⊥_ C) ≅ ⊥_ D := (isColimitOfHasInitialOfPreservesColimit G).coconePointUniqueUpToIso (colimit.isColimit _) @[simp] theorem PreservesInitial.iso_hom : (PreservesInitial.iso G).inv = initialComparison G := rfl instance : IsIso (initialComparison G) := by rw [← PreservesInitial.iso_hom] infer_instance end Initial end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Over.lean
import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.WithTerminal.FinCategory import Mathlib.CategoryTheory.WithTerminal.Cone /-! # If a functor preserves limits, so does the induced functor in the `Over` or `Under` category Suppose we are given categories `C` and `D`, and object `X : C`, and a functor `F : C ⥤ D`. `F` induces a functor `Over.post F : Over X ⥤ Over (F.obj X)`. If `F` preserves limits of a certain shape `WithTerminal J`, then `Over.post F` preserves limits of shape `J`. As a corollary, if `F` preserves finite limits, or limits of a certain size, so does `Over.post F`. Dually, if `F` preserves certain colimits, `Under.post F` will preserve certain colimits as well. -/ namespace CategoryTheory.Limits universe w w' v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {J : Type w} [Category.{w'} J] {X : C} {F : C ⥤ D} -- TODO: Do we even want to keep `WidePullbackShape` around? instance PreservesLimitsOfShape.ofWidePullbacks {J : Type*} [PreservesLimitsOfShape (WidePullbackShape J) F] : PreservesLimitsOfShape (WithTerminal <| Discrete J) F := preservesLimitsOfShape_of_equiv WithTerminal.widePullbackShapeEquiv F open WithTerminal in instance PreservesLimitsOfShape.overPost [PreservesLimitsOfShape (WithTerminal J) F] : PreservesLimitsOfShape J (Over.post F (X := X)) where preservesLimit.preserves {coneK} isLimitConeK := have isLimitConeD := (IsLimit.postcomposeHomEquiv liftFromOverComp.symm _).symm <| isLimitOfPreserves F (isLimitEquiv.symm isLimitConeK) ⟨isLimitEquiv <| isLimitConeD.ofIsoLimit <| Cones.ext (.refl _) fun | .star | .of a => by aesop⟩ instance PreservesFiniteLimits.overPost [PreservesFiniteLimits F] : PreservesFiniteLimits (Over.post F (X := X)) where preservesFiniteLimits _ := inferInstance instance PreservesLimitsOfSize.overPost [PreservesLimitsOfSize.{w', w} F] : PreservesLimitsOfSize.{w', w} (Over.post F (X := X)) where open WithInitial in instance PreservesColimitsOfShape.underPost [PreservesColimitsOfShape (WithInitial J) F] : PreservesColimitsOfShape J (Under.post F (X := X)) where preservesColimit.preserves {coconeK} isColimitCoconeK := have isColimitCoconeD := (IsColimit.precomposeHomEquiv liftFromUnderComp _).symm <| isColimitOfPreserves F (isColimitEquiv.symm isColimitCoconeK) ⟨isColimitEquiv <| isColimitCoconeD.ofIsoColimit <| Cocones.ext (.refl _) fun | .star | .of a => by aesop⟩ instance PreservesFiniteColimits.underPost [PreservesFiniteColimits F] : PreservesFiniteColimits (Under.post F (X := X)) where preservesFiniteColimits _ := inferInstance instance PreservesColimitsOfSize.underPost [PreservesColimitsOfSize.{w', w} F] : PreservesColimitsOfSize.{w', w} (Under.post F (X := X)) where end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Equalizers.lean
import Mathlib.CategoryTheory.Limits.Shapes.SplitCoequalizer import Mathlib.CategoryTheory.Limits.Shapes.SplitEqualizer import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Preserving (co)equalizers Constructions to relate the notions of preserving (co)equalizers and reflecting (co)equalizers to concrete (co)forks. In particular, we show that `equalizerComparison f g G` is an isomorphism iff `G` preserves the limit of the parallel pair `f,g`, as well as the dual result. -/ noncomputable section universe w v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) namespace CategoryTheory.Limits section Equalizers variable {X Y Z : C} {f g : X ⟶ Y} {h : Z ⟶ X} (w : h ≫ f = h ≫ g) /-- The map of a fork is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `Fork.ofι` with `Functor.mapCone`. -/ def isLimitMapConeForkEquiv : IsLimit (G.mapCone (Fork.ofι h w)) ≃ IsLimit (Fork.ofι (G.map h) (by simp only [← G.map_comp, w]) : Fork (G.map f) (G.map g)) := (IsLimit.postcomposeHomEquiv (diagramIsoParallelPair _) _).symm.trans (IsLimit.equivIsoLimit (Fork.ext (Iso.refl _) (by simp [Fork.ι]))) /-- The property of preserving equalizers expressed in terms of forks. -/ def isLimitForkMapOfIsLimit [PreservesLimit (parallelPair f g) G] (l : IsLimit (Fork.ofι h w)) : IsLimit (Fork.ofι (G.map h) (by simp only [← G.map_comp, w]) : Fork (G.map f) (G.map g)) := isLimitMapConeForkEquiv G w (isLimitOfPreserves G l) /-- The property of reflecting equalizers expressed in terms of forks. -/ def isLimitOfIsLimitForkMap [ReflectsLimit (parallelPair f g) G] (l : IsLimit (Fork.ofι (G.map h) (by simp only [← G.map_comp, w]) : Fork (G.map f) (G.map g))) : IsLimit (Fork.ofι h w) := isLimitOfReflects G ((isLimitMapConeForkEquiv G w).symm l) variable (f g) variable [HasEqualizer f g] /-- If `G` preserves equalizers and `C` has them, then the fork constructed of the mapped morphisms of a fork is a limit. -/ def isLimitOfHasEqualizerOfPreservesLimit [PreservesLimit (parallelPair f g) G] : IsLimit (Fork.ofι (G.map (equalizer.ι f g)) (by simp only [← G.map_comp]; rw [equalizer.condition]) : Fork (G.map f) (G.map g)) := isLimitForkMapOfIsLimit G _ (equalizerIsEqualizer f g) variable [HasEqualizer (G.map f) (G.map g)] /-- If the equalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the equalizer of `(f,g)`. -/ lemma PreservesEqualizer.of_iso_comparison [i : IsIso (equalizerComparison f g G)] : PreservesLimit (parallelPair f g) G := by apply preservesLimit_of_preserves_limit_cone (equalizerIsEqualizer f g) apply (isLimitMapConeForkEquiv _ _).symm _ exact @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (parallelPair (G.map f) (G.map g))) i variable [PreservesLimit (parallelPair f g) G] /-- If `G` preserves the equalizer of `(f,g)`, then the equalizer comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesEqualizer.iso : G.obj (equalizer f g) ≅ equalizer (G.map f) (G.map g) := IsLimit.conePointUniqueUpToIso (isLimitOfHasEqualizerOfPreservesLimit G f g) (limit.isLimit _) @[simp] theorem PreservesEqualizer.iso_hom : (PreservesEqualizer.iso G f g).hom = equalizerComparison f g G := rfl @[simp] theorem PreservesEqualizer.iso_inv_ι : (PreservesEqualizer.iso G f g).inv ≫ G.map (equalizer.ι f g) = equalizer.ι (G.map f) (G.map g) := by rw [← Iso.cancel_iso_hom_left (PreservesEqualizer.iso G f g), ← Category.assoc, Iso.hom_inv_id] simp instance : IsIso (equalizerComparison f g G) := by rw [← PreservesEqualizer.iso_hom] infer_instance end Equalizers section Coequalizers variable {X Y Z : C} {f g : X ⟶ Y} {h : Y ⟶ Z} (w : f ≫ h = g ≫ h) /-- The map of a cofork is a colimit iff the cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `Cofork.ofπ` with `Functor.mapCocone`. -/ def isColimitMapCoconeCoforkEquiv : IsColimit (G.mapCocone (Cofork.ofπ h w)) ≃ IsColimit (Cofork.ofπ (G.map h) (by simp only [← G.map_comp, w]) : Cofork (G.map f) (G.map g)) := (IsColimit.precomposeInvEquiv (diagramIsoParallelPair _) _).symm.trans <| IsColimit.equivIsoColimit <| Cofork.ext (Iso.refl _) <| by dsimp only [Cofork.π, Cofork.ofπ_ι_app] dsimp; rw [Category.comp_id, Category.id_comp] /-- The property of preserving coequalizers expressed in terms of coforks. -/ def isColimitCoforkMapOfIsColimit [PreservesColimit (parallelPair f g) G] (l : IsColimit (Cofork.ofπ h w)) : IsColimit (Cofork.ofπ (G.map h) (by simp only [← G.map_comp, w]) : Cofork (G.map f) (G.map g)) := isColimitMapCoconeCoforkEquiv G w (isColimitOfPreserves G l) /-- The property of reflecting coequalizers expressed in terms of coforks. -/ def isColimitOfIsColimitCoforkMap [ReflectsColimit (parallelPair f g) G] (l : IsColimit (Cofork.ofπ (G.map h) (by simp only [← G.map_comp, w]) : Cofork (G.map f) (G.map g))) : IsColimit (Cofork.ofπ h w) := isColimitOfReflects G ((isColimitMapCoconeCoforkEquiv G w).symm l) variable (f g) variable [HasCoequalizer f g] /-- If `G` preserves coequalizers and `C` has them, then the cofork constructed of the mapped morphisms of a cofork is a colimit. -/ def isColimitOfHasCoequalizerOfPreservesColimit [PreservesColimit (parallelPair f g) G] : IsColimit (Cofork.ofπ (G.map (coequalizer.π f g)) (by simp only [← G.map_comp]; rw [coequalizer.condition]) : Cofork (G.map f) (G.map g)) := isColimitCoforkMapOfIsColimit G _ (coequalizerIsCoequalizer f g) variable [HasCoequalizer (G.map f) (G.map g)] /-- If the coequalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the coequalizer of `(f,g)`. -/ lemma of_iso_comparison [i : IsIso (coequalizerComparison f g G)] : PreservesColimit (parallelPair f g) G := by apply preservesColimit_of_preserves_colimit_cocone (coequalizerIsCoequalizer f g) apply (isColimitMapCoconeCoforkEquiv _ _).symm _ exact @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (parallelPair (G.map f) (G.map g))) i variable [PreservesColimit (parallelPair f g) G] /-- If `G` preserves the coequalizer of `(f,g)`, then the coequalizer comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesCoequalizer.iso : coequalizer (G.map f) (G.map g) ≅ G.obj (coequalizer f g) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitOfHasCoequalizerOfPreservesColimit G f g) @[simp] theorem PreservesCoequalizer.iso_hom : (PreservesCoequalizer.iso G f g).hom = coequalizerComparison f g G := rfl instance : IsIso (coequalizerComparison f g G) := by rw [← PreservesCoequalizer.iso_hom] infer_instance instance map_π_epi : Epi (G.map (coequalizer.π f g)) := ⟨fun {W} h k => by rw [← ι_comp_coequalizerComparison] haveI : Epi (coequalizer.π (G.map f) (G.map g) ≫ coequalizerComparison f g G) := by apply epi_comp apply (cancel_epi _).1⟩ @[reassoc] theorem map_π_preserves_coequalizer_inv : G.map (coequalizer.π f g) ≫ (PreservesCoequalizer.iso G f g).inv = coequalizer.π (G.map f) (G.map g) := by rw [← ι_comp_coequalizerComparison_assoc, ← PreservesCoequalizer.iso_hom, Iso.hom_inv_id, comp_id] @[reassoc] theorem map_π_preserves_coequalizer_inv_desc {W : D} (k : G.obj Y ⟶ W) (wk : G.map f ≫ k = G.map g ≫ k) : G.map (coequalizer.π f g) ≫ (PreservesCoequalizer.iso G f g).inv ≫ coequalizer.desc k wk = k := by rw [← Category.assoc, map_π_preserves_coequalizer_inv, coequalizer.π_desc] @[reassoc] theorem map_π_preserves_coequalizer_inv_colimMap {X' Y' : D} (f' g' : X' ⟶ Y') [HasCoequalizer f' g'] (p : G.obj X ⟶ X') (q : G.obj Y ⟶ Y') (wf : G.map f ≫ q = p ≫ f') (wg : G.map g ≫ q = p ≫ g') : G.map (coequalizer.π f g) ≫ (PreservesCoequalizer.iso G f g).inv ≫ colimMap (parallelPairHom (G.map f) (G.map g) f' g' p q wf wg) = q ≫ coequalizer.π f' g' := by rw [← Category.assoc, map_π_preserves_coequalizer_inv, ι_colimMap, parallelPairHom_app_one] @[reassoc] theorem map_π_preserves_coequalizer_inv_colimMap_desc {X' Y' : D} (f' g' : X' ⟶ Y') [HasCoequalizer f' g'] (p : G.obj X ⟶ X') (q : G.obj Y ⟶ Y') (wf : G.map f ≫ q = p ≫ f') (wg : G.map g ≫ q = p ≫ g') {Z' : D} (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : G.map (coequalizer.π f g) ≫ (PreservesCoequalizer.iso G f g).inv ≫ colimMap (parallelPairHom (G.map f) (G.map g) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := by slice_lhs 1 3 => rw [map_π_preserves_coequalizer_inv_colimMap] slice_lhs 2 3 => rw [coequalizer.π_desc] /-- Any functor preserves coequalizers of split pairs. -/ instance (priority := 1) preservesSplitCoequalizers (f g : X ⟶ Y) [HasSplitCoequalizer f g] : PreservesColimit (parallelPair f g) G := by apply preservesColimit_of_preserves_colimit_cocone (HasSplitCoequalizer.isSplitCoequalizer f g).isCoequalizer apply (isColimitMapCoconeCoforkEquiv G _).symm ((HasSplitCoequalizer.isSplitCoequalizer f g).map G).isCoequalizer instance (priority := 1) preservesSplitEqualizers (f g : X ⟶ Y) [HasSplitEqualizer f g] : PreservesLimit (parallelPair f g) G := by apply preservesLimit_of_preserves_limit_cone (HasSplitEqualizer.isSplitEqualizer f g).isEqualizer apply (isLimitMapConeForkEquiv G _).symm ((HasSplitEqualizer.isSplitEqualizer f g).map G).isEqualizer end Coequalizers end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Kernels.lean
import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero /-! # Preserving (co)kernels Constructions to relate the notions of preserving (co)kernels and reflecting (co)kernels to concrete (co)forks. In particular, we show that `kernel_comparison f g G` is an isomorphism iff `G` preserves the limit of the parallel pair `f,0`, as well as the dual result. -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] [HasZeroMorphisms C] variable {D : Type u₂} [Category.{v₂} D] [HasZeroMorphisms D] namespace CategoryTheory.Limits namespace KernelFork variable {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] @[reassoc (attr := simp)] lemma map_condition : G.map c.ι ≫ G.map f = 0 := by rw [← G.map_comp, c.condition, G.map_zero] /-- A kernel fork for `f` is mapped to a kernel fork for `G.map f` if `G` is a functor which preserves zero morphisms. -/ def map : KernelFork (G.map f) := KernelFork.ofι (G.map c.ι) (c.map_condition G) @[simp] lemma map_ι : (c.map G).ι = G.map c.ι := rfl /-- The underlying cone of a kernel fork is mapped to a limit cone if and only if the mapped kernel fork is limit. -/ def isLimitMapConeEquiv : IsLimit (G.mapCone c) ≃ IsLimit (c.map G) := by refine (IsLimit.postcomposeHomEquiv ?_ _).symm.trans (IsLimit.equivIsoLimit ?_) refine parallelPair.ext (Iso.refl _) (Iso.refl _) ?_ ?_ <;> simp exact Cones.ext (Iso.refl _) (by rintro (_ | _) <;> cat_disch) /-- A limit kernel fork is mapped to a limit kernel fork by a functor `G` when this functor preserves the corresponding limit. -/ def mapIsLimit (hc : IsLimit c) (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] [PreservesLimit (parallelPair f 0) G] : IsLimit (c.map G) := c.isLimitMapConeEquiv G (isLimitOfPreserves G hc) end KernelFork section Kernels variable (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] {X Y Z : C} {f : X ⟶ Y} {h : Z ⟶ X} (w : h ≫ f = 0) /-- The map of a kernel fork is a limit iff the kernel fork consisting of the mapped morphisms is a limit. This essentially lets us commute `KernelFork.ofι` with `Functor.mapCone`. This is a variant of `isLimitMapConeForkEquiv` for equalizers, which we can't use directly between `G.map 0 = 0` does not hold definitionally. -/ def isLimitMapConeForkEquiv' : IsLimit (G.mapCone (KernelFork.ofι h w)) ≃ IsLimit (KernelFork.ofι (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) : Fork (G.map f) 0) := KernelFork.isLimitMapConeEquiv _ _ /-- The property of preserving kernels expressed in terms of kernel forks. This is a variant of `isLimitForkMapOfIsLimit` for equalizers, which we can't use directly between `G.map 0 = 0` does not hold definitionally. -/ def isLimitForkMapOfIsLimit' [PreservesLimit (parallelPair f 0) G] (l : IsLimit (KernelFork.ofι h w)) : IsLimit (KernelFork.ofι (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) : Fork (G.map f) 0) := isLimitMapConeForkEquiv' G w (isLimitOfPreserves G l) variable (f) variable [HasKernel f] /-- If `G` preserves kernels and `C` has them, then the fork constructed of the mapped morphisms of a kernel fork is a limit. -/ def isLimitOfHasKernelOfPreservesLimit [PreservesLimit (parallelPair f 0) G] : IsLimit (Fork.ofι (G.map (kernel.ι f)) (by simp only [← G.map_comp, kernel.condition, comp_zero, Functor.map_zero]) : Fork (G.map f) 0) := isLimitForkMapOfIsLimit' G (kernel.condition f) (kernelIsKernel f) instance [PreservesLimit (parallelPair f 0) G] : HasKernel (G.map f) where exists_limit := ⟨⟨_, isLimitOfHasKernelOfPreservesLimit G f⟩⟩ variable [HasKernel (G.map f)] /-- If the kernel comparison map for `G` at `f` is an isomorphism, then `G` preserves the kernel of `f`. -/ lemma PreservesKernel.of_iso_comparison [i : IsIso (kernelComparison f G)] : PreservesLimit (parallelPair f 0) G := by apply preservesLimit_of_preserves_limit_cone (kernelIsKernel f) apply (isLimitMapConeForkEquiv' G (kernel.condition f)).symm _ exact @IsLimit.ofPointIso _ _ _ _ _ _ _ (kernelIsKernel (G.map f)) i variable [PreservesLimit (parallelPair f 0) G] /-- If `G` preserves the kernel of `f`, then the kernel comparison map for `G` at `f` is an isomorphism. -/ def PreservesKernel.iso : G.obj (kernel f) ≅ kernel (G.map f) := IsLimit.conePointUniqueUpToIso (isLimitOfHasKernelOfPreservesLimit G f) (limit.isLimit _) @[reassoc (attr := simp)] theorem PreservesKernel.iso_inv_ι : (PreservesKernel.iso G f).inv ≫ G.map (kernel.ι f) = kernel.ι (G.map f) := IsLimit.conePointUniqueUpToIso_inv_comp (isLimitOfHasKernelOfPreservesLimit G f) (limit.isLimit _) (WalkingParallelPair.zero) @[simp] theorem PreservesKernel.iso_hom : (PreservesKernel.iso G f).hom = kernelComparison f G := by rw [← cancel_mono (kernel.ι _)] simp [PreservesKernel.iso] instance : IsIso (kernelComparison f G) := by rw [← PreservesKernel.iso_hom] infer_instance @[reassoc] theorem kernel_map_comp_preserves_kernel_iso_inv {X' Y' : C} (g : X' ⟶ Y') [HasKernel g] [HasKernel (G.map g)] [PreservesLimit (parallelPair g 0) G] (p : X ⟶ X') (q : Y ⟶ Y') (hpq : f ≫ q = p ≫ g) : kernel.map (G.map f) (G.map g) (G.map p) (G.map q) (by rw [← G.map_comp, hpq, G.map_comp]) ≫ (PreservesKernel.iso G _).inv = (PreservesKernel.iso G _).inv ≫ G.map (kernel.map f g p q hpq) := by rw [Iso.comp_inv_eq, Category.assoc, PreservesKernel.iso_hom, Iso.eq_inv_comp, PreservesKernel.iso_hom, kernelComparison_comp_kernel_map] end Kernels namespace CokernelCofork variable {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] @[reassoc (attr := simp)] lemma map_condition : G.map f ≫ G.map c.π = 0 := by rw [← G.map_comp, c.condition, G.map_zero] /-- A cokernel cofork for `f` is mapped to a cokernel cofork for `G.map f` if `G` is a functor which preserves zero morphisms. -/ def map : CokernelCofork (G.map f) := CokernelCofork.ofπ (G.map c.π) (c.map_condition G) @[simp] lemma map_π : (c.map G).π = G.map c.π := rfl /-- The underlying cocone of a cokernel cofork is mapped to a colimit cocone if and only if the mapped cokernel cofork is colimit. -/ def isColimitMapCoconeEquiv : IsColimit (G.mapCocone c) ≃ IsColimit (c.map G) := by refine (IsColimit.precomposeHomEquiv ?_ _).symm.trans (IsColimit.equivIsoColimit ?_) refine parallelPair.ext (Iso.refl _) (Iso.refl _) ?_ ?_ <;> simp exact Cocones.ext (Iso.refl _) (by rintro (_ | _) <;> cat_disch) /-- A colimit cokernel cofork is mapped to a colimit cokernel cofork by a functor `G` when this functor preserves the corresponding colimit. -/ def mapIsColimit (hc : IsColimit c) (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] [PreservesColimit (parallelPair f 0) G] : IsColimit (c.map G) := c.isColimitMapCoconeEquiv G (isColimitOfPreserves G hc) end CokernelCofork section Cokernels variable (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] {X Y Z : C} {f : X ⟶ Y} {h : Y ⟶ Z} (w : f ≫ h = 0) /-- The map of a cokernel cofork is a colimit iff the cokernel cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `CokernelCofork.ofπ` with `Functor.mapCocone`. This is a variant of `isColimitMapCoconeCoforkEquiv` for equalizers, which we can't use directly between `G.map 0 = 0` does not hold definitionally. -/ def isColimitMapCoconeCoforkEquiv' : IsColimit (G.mapCocone (CokernelCofork.ofπ h w)) ≃ IsColimit (CokernelCofork.ofπ (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) : Cofork (G.map f) 0) := CokernelCofork.isColimitMapCoconeEquiv _ _ /-- The property of preserving cokernels expressed in terms of cokernel coforks. This is a variant of `isColimitCoforkMapOfIsColimit` for equalizers, which we can't use directly between `G.map 0 = 0` does not hold definitionally. -/ def isColimitCoforkMapOfIsColimit' [PreservesColimit (parallelPair f 0) G] (l : IsColimit (CokernelCofork.ofπ h w)) : IsColimit (CokernelCofork.ofπ (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) : Cofork (G.map f) 0) := isColimitMapCoconeCoforkEquiv' G w (isColimitOfPreserves G l) variable (f) variable [HasCokernel f] /-- If `G` preserves cokernels and `C` has them, then the cofork constructed of the mapped morphisms of a cokernel cofork is a colimit. -/ def isColimitOfHasCokernelOfPreservesColimit [PreservesColimit (parallelPair f 0) G] : IsColimit (Cofork.ofπ (G.map (cokernel.π f)) (by simp only [← G.map_comp, cokernel.condition, zero_comp, Functor.map_zero]) : Cofork (G.map f) 0) := isColimitCoforkMapOfIsColimit' G (cokernel.condition f) (cokernelIsCokernel f) instance [PreservesColimit (parallelPair f 0) G] : HasCokernel (G.map f) where exists_colimit := ⟨⟨_, isColimitOfHasCokernelOfPreservesColimit G f⟩⟩ variable [HasCokernel (G.map f)] /-- If the cokernel comparison map for `G` at `f` is an isomorphism, then `G` preserves the cokernel of `f`. -/ lemma PreservesCokernel.of_iso_comparison [i : IsIso (cokernelComparison f G)] : PreservesColimit (parallelPair f 0) G := by apply preservesColimit_of_preserves_colimit_cocone (cokernelIsCokernel f) apply (isColimitMapCoconeCoforkEquiv' G (cokernel.condition f)).symm _ exact @IsColimit.ofPointIso _ _ _ _ _ _ _ (cokernelIsCokernel (G.map f)) i variable [PreservesColimit (parallelPair f 0) G] /-- If `G` preserves the cokernel of `f`, then the cokernel comparison map for `G` at `f` is an isomorphism. -/ def PreservesCokernel.iso : G.obj (cokernel f) ≅ cokernel (G.map f) := IsColimit.coconePointUniqueUpToIso (isColimitOfHasCokernelOfPreservesColimit G f) (colimit.isColimit _) @[reassoc (attr := simp)] theorem PreservesCokernel.π_iso_hom : G.map (cokernel.π f) ≫ (iso G f).hom = cokernel.π (G.map f) := IsColimit.comp_coconePointUniqueUpToIso_hom (isColimitOfHasCokernelOfPreservesColimit G f) (colimit.isColimit _) (WalkingParallelPair.one) @[simp] theorem PreservesCokernel.iso_inv : (PreservesCokernel.iso G f).inv = cokernelComparison f G := by rw [← cancel_epi (cokernel.π _)] simp [PreservesCokernel.iso] instance : IsIso (cokernelComparison f G) := by rw [← PreservesCokernel.iso_inv] infer_instance @[reassoc] theorem preserves_cokernel_iso_comp_cokernel_map {X' Y' : C} (g : X' ⟶ Y') [HasCokernel g] [HasCokernel (G.map g)] [PreservesColimit (parallelPair g 0) G] (p : X ⟶ X') (q : Y ⟶ Y') (hpq : f ≫ q = p ≫ g) : (PreservesCokernel.iso G _).hom ≫ cokernel.map (G.map f) (G.map g) (G.map p) (G.map q) (by rw [← G.map_comp, hpq, G.map_comp]) = G.map (cokernel.map f g p q hpq) ≫ (PreservesCokernel.iso G _).hom := by rw [← Iso.comp_inv_eq, Category.assoc, ← Iso.eq_inv_comp, PreservesCokernel.iso_inv, cokernel_map_comp_cokernelComparison, PreservesCokernel.iso_inv] end Cokernels variable (X Y : C) (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] instance preservesKernel_zero : PreservesLimit (parallelPair (0 : X ⟶ Y) 0) G where preserves {c} hc := ⟨by have := KernelFork.IsLimit.isIso_ι c hc rfl refine (KernelFork.isLimitMapConeEquiv c G).symm ?_ refine IsLimit.ofIsoLimit (KernelFork.IsLimit.ofId _ (G.map_zero _ _)) ?_ exact (Fork.ext (G.mapIso (asIso (Fork.ι c))).symm (by simp))⟩ noncomputable instance preservesCokernel_zero : PreservesColimit (parallelPair (0 : X ⟶ Y) 0) G where preserves {c} hc := ⟨by have := CokernelCofork.IsColimit.isIso_π c hc rfl refine (CokernelCofork.isColimitMapCoconeEquiv c G).symm ?_ refine IsColimit.ofIsoColimit (CokernelCofork.IsColimit.ofId _ (G.map_zero _ _)) ?_ exact (Cofork.ext (G.mapIso (asIso (Cofork.π c))) (by simp))⟩ variable {X Y} /-- The kernel of a zero map is preserved by any functor which preserves zero morphisms. -/ lemma preservesKernel_zero' (f : X ⟶ Y) (hf : f = 0) : PreservesLimit (parallelPair f 0) G := by rw [hf] infer_instance /-- The cokernel of a zero map is preserved by any functor which preserves zero morphisms. -/ lemma preservesCokernel_zero' (f : X ⟶ Y) (hf : f = 0) : PreservesColimit (parallelPair f 0) G := by rw [hf] infer_instance end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Square.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Square import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.Limits.Preserves.Ulift /-! # Preservations of pullback/pushout squares If a functor `F : C ⥤ D` preserves suitable cospans (resp. spans), and `sq : Square C` is a pullback square (resp. a pushout square) then so is the square`sq.map F`. The lemma `Square.isPullback_iff_map_coyoneda_isPullback` also shows that a square is a pullback square iff it is so after the application of the functor `coyoneda.obj X` for all `X : Cᵒᵖ`. Similarly, a square is a pushout square iff the opposite square becomes a pullback square after the application of the functor `yoneda.obj X` for all `X : C`. -/ universe v v' u u' namespace CategoryTheory open Opposite Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] namespace Square variable {sq : Square C} lemma IsPullback.map (h : sq.IsPullback) (F : C ⥤ D) [PreservesLimit (cospan sq.f₂₄ sq.f₃₄) F] : (sq.map F).IsPullback := Square.IsPullback.mk _ (isLimitPullbackConeMapOfIsLimit F sq.fac h.isLimit) lemma IsPullback.of_map (F : C ⥤ D) [ReflectsLimit (cospan sq.f₂₄ sq.f₃₄) F] (h : (sq.map F).IsPullback) : sq.IsPullback := CategoryTheory.IsPullback.of_map F sq.fac h variable (sq) in lemma IsPullback.map_iff (F : C ⥤ D) [PreservesLimit (cospan sq.f₂₄ sq.f₃₄) F] [ReflectsLimit (cospan sq.f₂₄ sq.f₃₄) F] : (sq.map F).IsPullback ↔ sq.IsPullback := ⟨fun h ↦ of_map F h, fun h ↦ h.map F⟩ lemma IsPushout.map (h : sq.IsPushout) (F : C ⥤ D) [PreservesColimit (span sq.f₁₂ sq.f₁₃) F] : (sq.map F).IsPushout := Square.IsPushout.mk _ (isColimitPushoutCoconeMapOfIsColimit F sq.fac h.isColimit) lemma IsPushout.of_map (F : C ⥤ D) [ReflectsColimit (span sq.f₁₂ sq.f₁₃) F] (h : (sq.map F).IsPushout) : sq.IsPushout := CategoryTheory.IsPushout.of_map F sq.fac h variable (sq) in lemma IsPushout.map_iff (F : C ⥤ D) [PreservesColimit (span sq.f₁₂ sq.f₁₃) F] [ReflectsColimit (span sq.f₁₂ sq.f₁₃) F] : (sq.map F).IsPushout ↔ sq.IsPushout := ⟨fun h ↦ of_map F h, fun h ↦ h.map F⟩ variable (sq) lemma isPullback_iff_map_coyoneda_isPullback : sq.IsPullback ↔ ∀ (X : Cᵒᵖ), (sq.map (coyoneda.obj X)).IsPullback := ⟨fun h _ ↦ h.map _, fun h ↦ IsPullback.mk _ ((sq.pullbackCone.isLimitCoyonedaEquiv).symm (fun X ↦ (h X).isLimit))⟩ lemma isPushout_iff_op_map_yoneda_isPullback : sq.IsPushout ↔ ∀ (X : C), (sq.op.map (yoneda.obj X)).IsPullback := ⟨fun h _ ↦ h.op.map _, fun h ↦ IsPushout.mk _ ((sq.pushoutCocone.isColimitYonedaEquiv).symm (fun X ↦ IsLimit.ofIsoLimit (h X).isLimit (PullbackCone.ext (Iso.refl _))))⟩ section variable {sq₁ : Square (Type v)} {sq₂ : Square (Type u)} (e₁ : sq₁.X₁ ≃ sq₂.X₁) (e₂ : sq₁.X₂ ≃ sq₂.X₂) (e₃ : sq₁.X₃ ≃ sq₂.X₃) (e₄ : sq₁.X₄ ≃ sq₂.X₄) (comm₁₂ : e₂ ∘ sq₁.f₁₂ = sq₂.f₁₂ ∘ e₁) (comm₁₃ : e₃ ∘ sq₁.f₁₃ = sq₂.f₁₃ ∘ e₁) (comm₂₄ : e₄ ∘ sq₁.f₂₄ = sq₂.f₂₄ ∘ e₂) (comm₃₄ : e₄ ∘ sq₁.f₃₄ = sq₂.f₃₄ ∘ e₃) include comm₁₂ comm₁₃ comm₂₄ comm₃₄ variable (sq₁ sq₂) in lemma IsPullback.iff_of_equiv : sq₁.IsPullback ↔ sq₂.IsPullback := by rw [← IsPullback.map_iff sq₁ uliftFunctor.{max u v}, ← IsPullback.map_iff sq₂ uliftFunctor.{max u v}] refine iff_of_iso (Square.isoMk (((Equiv.trans Equiv.ulift e₁).trans Equiv.ulift.symm).toIso) (((Equiv.trans Equiv.ulift e₂).trans Equiv.ulift.symm).toIso) (((Equiv.trans Equiv.ulift e₃).trans Equiv.ulift.symm).toIso) (((Equiv.trans Equiv.ulift e₄).trans Equiv.ulift.symm).toIso) ?_ ?_ ?_ ?_) all_goals ext; apply ULift.down_injective · simpa [types_comp, uliftFunctor_map] using congrFun comm₁₂ _ · simpa [types_comp, uliftFunctor_map] using congrFun comm₁₃ _ · simpa [types_comp, uliftFunctor_map] using congrFun comm₂₄ _ · simpa [types_comp, uliftFunctor_map] using congrFun comm₃₄ _ lemma IsPullback.of_equiv (h₁ : sq₁.IsPullback) : sq₂.IsPullback := (iff_of_equiv sq₁ sq₂ e₁ e₂ e₃ e₄ comm₁₂ comm₁₃ comm₂₄ comm₃₄).1 h₁ end end Square end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Multiequalizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer /-! # Preservation of multicoequalizers Let `J : MultispanShape` and `d : MultispanIndex J C`. If `F : C ⥤ D`, we define `d.map F : MultispanIndex J D` and an isomorphism of functors `(d.map F).multispan ≅ d.multispan ⋙ F` (see `MultispanIndex.multispanMapIso`). If `c : Multicofork d`, we define `c.map F : Multicofork (d.map F)` and obtain a bijection `IsColimit (F.mapCocone c) ≃ IsColimit (c.map F)` (see `Multicofork.isColimitMapEquiv`). As a result, if `F` preserves the colimit of `d.multispan`, we deduce that if `c` is a colimit, then `c.map F` also is (see `Multicofork.isColimitMapOfPreserves`). -/ universe w w' v u namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] namespace Limits variable {J : MultispanShape.{w, w'}} (d : MultispanIndex J C) (c : Multicofork d) (F : C ⥤ D) /-- The multispan index obtained by applying a functor. -/ @[simps] def MultispanIndex.map : MultispanIndex J D where left i := F.obj (d.left i) right i := F.obj (d.right i) fst i := F.map (d.fst i) snd i := F.map (d.snd i) /-- If `d : MultispanIndex J C` and `F : C ⥤ D`, this is the obvious isomorphism `(d.map F).multispan ≅ d.multispan ⋙ F`. -/ @[simps!] def MultispanIndex.multispanMapIso : (d.map F).multispan ≅ d.multispan ⋙ F := NatIso.ofComponents (fun i ↦ match i with | .left _ => Iso.refl _ | .right _ => Iso.refl _) (by rintro _ _ (_ | _) <;> simp) variable {d} /-- If `d : MultispanIndex J C`, `c : Multicofork d` and `F : C ⥤ D`, this is the induced multicofork of `d.map F`. -/ @[simps!] def Multicofork.map : Multicofork (d.map F) := Multicofork.ofπ _ (F.obj c.pt) (fun i ↦ F.map (c.π i)) (fun j ↦ by dsimp rw [← F.map_comp, ← F.map_comp, condition]) /-- If `d : MultispanIndex J C`, `c : Multicofork d` and `F : C ⥤ D`, the cocone `F.mapCocone c` is colimit iff the multicofork `c.map F` is. -/ def Multicofork.isColimitMapEquiv : IsColimit (F.mapCocone c) ≃ IsColimit (c.map F) := (IsColimit.precomposeInvEquiv (d.multispanMapIso F).symm (F.mapCocone c)).symm.trans (IsColimit.equivIsoColimit (Multicofork.ext (Iso.refl _) (fun i ↦ by dsimp only [Multicofork.π]; simp))) /-- If `d : MultispanIndex J C`, `c : Multicofork d` is a colimit multicofork, and `F : C ⥤ D` is a functor which preserves the colimit of `d.multispan`, then the multicofork `c.map F` is colimit. -/ noncomputable def Multicofork.isColimitMapOfPreserves [PreservesColimit d.multispan F] (hc : IsColimit c) : IsColimit (c.map F) := (isColimitMapEquiv c F) (isColimitOfPreserves F hc) end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Preorder.lean
import Mathlib.CategoryTheory.Limits.Shapes.Preorder.WellOrderContinuous import Mathlib.CategoryTheory.Limits.Shapes.Preorder.HasIterationOfShape import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Preservation of well order continuous functors Given a well-ordered type `J` and a functor `G : C ⥤ D`, we define a type class `PreservesWellOrderContinuousOfShape J G` saying that `G` preserves colimits of shape `Set.Iio j` for any limit element `j : J`. It follows that if `F : J ⥤ C` is well order continuous, then so is `F ⋙ G`. -/ universe w w' v v' v'' u' u u'' namespace CategoryTheory namespace Limits variable {C : Type u} {D : Type u'} {E : Type u''} [Category.{v} C] [Category.{v'} D] [Category.{v''} E] (J : Type w) [LinearOrder J] /-- A functor `G : C ⥤ D` satisfies `PreservesWellOrderContinuousOfShape J G` if for any limit element `j` in the preordered type `J`, the functor `G` preserves colimits of shape `Set.Iio j`. -/ class PreservesWellOrderContinuousOfShape (G : C ⥤ D) : Prop where preservesColimitsOfShape (j : J) (hj : Order.IsSuccLimit j) : PreservesColimitsOfShape (Set.Iio j) G := by infer_instance variable {J} in lemma preservesColimitsOfShape_of_preservesWellOrderContinuousOfShape (G : C ⥤ D) [PreservesWellOrderContinuousOfShape J G] (j : J) (hj : Order.IsSuccLimit j) : PreservesColimitsOfShape (Set.Iio j) G := PreservesWellOrderContinuousOfShape.preservesColimitsOfShape j hj instance (F : J ⥤ C) (G : C ⥤ D) [F.IsWellOrderContinuous] [PreservesWellOrderContinuousOfShape J G] : (F ⋙ G).IsWellOrderContinuous where nonempty_isColimit j hj := ⟨by have := preservesColimitsOfShape_of_preservesWellOrderContinuousOfShape G j hj exact isColimitOfPreserves G (F.isColimitOfIsWellOrderContinuous j hj)⟩ instance (G₁ : C ⥤ D) (G₂ : D ⥤ E) [PreservesWellOrderContinuousOfShape J G₁] [PreservesWellOrderContinuousOfShape J G₂] : PreservesWellOrderContinuousOfShape J (G₁ ⋙ G₂) where preservesColimitsOfShape j hj := by have := preservesColimitsOfShape_of_preservesWellOrderContinuousOfShape G₁ j hj have := preservesColimitsOfShape_of_preservesWellOrderContinuousOfShape G₂ j hj infer_instance instance [HasIterationOfShape J C] (K : Type*) [Category K] (X : K) : PreservesWellOrderContinuousOfShape J ((evaluation K C).obj X) where preservesColimitsOfShape j hj := by have := hasColimitsOfShape_of_isSuccLimit C j hj infer_instance instance [HasIterationOfShape J C] : PreservesWellOrderContinuousOfShape J (Arrow.leftFunc : _ ⥤ C) where preservesColimitsOfShape j hj := by have := hasColimitsOfShape_of_isSuccLimit C j hj infer_instance instance [HasIterationOfShape J C] : PreservesWellOrderContinuousOfShape J (Arrow.rightFunc : _ ⥤ C) where preservesColimitsOfShape j hj := by have := hasColimitsOfShape_of_isSuccLimit C j hj infer_instance end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Images.lean
import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Preserving images In this file, we show that if a functor preserves span and cospan, then it preserves images. -/ noncomputable section namespace CategoryTheory namespace PreservesImage open CategoryTheory open CategoryTheory.Limits universe u₁ u₂ v₁ v₂ variable {A : Type u₁} {B : Type u₂} [Category.{v₁} A] [Category.{v₂} B] variable [HasEqualizers A] [HasImages A] variable [StrongEpiCategory B] [HasImages B] variable (L : A ⥤ B) variable [∀ {X Y Z : A} (f : X ⟶ Z) (g : Y ⟶ Z), PreservesLimit (cospan f g) L] variable [∀ {X Y Z : A} (f : X ⟶ Y) (g : X ⟶ Z), PreservesColimit (span f g) L] /-- If a functor preserves span and cospan, then it preserves images. -/ @[simps!] def iso {X Y : A} (f : X ⟶ Y) : image (L.map f) ≅ L.obj (image f) := let aux1 : StrongEpiMonoFactorisation (L.map f) := { I := L.obj (Limits.image f) m := L.map <| Limits.image.ι _ m_mono := preserves_mono_of_preservesLimit _ _ e := L.map <| factorThruImage _ e_strong_epi := @strongEpi_of_epi B _ _ _ _ _ (preserves_epi_of_preservesColimit L _) fac := by rw [← L.map_comp, Limits.image.fac] } IsImage.isoExt (Image.isImage (L.map f)) aux1.toMonoIsImage @[reassoc] theorem factorThruImage_comp_hom {X Y : A} (f : X ⟶ Y) : factorThruImage (L.map f) ≫ (iso L f).hom = L.map (factorThruImage f) := by simp @[reassoc] theorem hom_comp_map_image_ι {X Y : A} (f : X ⟶ Y) : (iso L f).hom ≫ L.map (image.ι f) = image.ι (L.map f) := by rw [iso_hom, image.lift_fac] @[reassoc] theorem inv_comp_image_ι_map {X Y : A} (f : X ⟶ Y) : (iso L f).inv ≫ image.ι (L.map f) = L.map (image.ι f) := by simp end PreservesImage end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/AbelianImages.lean
import Mathlib.CategoryTheory.Abelian.Images import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels /-! # Preservation of coimage-image comparisons If a functor preserves kernels and cokernels, then it preserves abelian images, abelian coimages and coimage-image comparisons. -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory Limits namespace CategoryTheory.Abelian variable {C : Type u₁} [Category.{v₁} C] [HasZeroMorphisms C] variable {D : Type u₂} [Category.{v₂} D] [HasZeroMorphisms D] variable (F : C ⥤ D) [F.PreservesZeroMorphisms] variable {X Y : C} (f : X ⟶ Y) section Images variable [HasCokernel f] [HasKernel (cokernel.π f)] [PreservesColimit (parallelPair f 0) F] [PreservesLimit (parallelPair (cokernel.π f) 0) F] [HasCokernel (F.map f)] [HasKernel (cokernel.π (F.map f))] /-- If a functor preserves kernels and cokernels, it preserves abelian images. -/ def PreservesImage.iso : F.obj (Abelian.image f) ≅ Abelian.image (F.map f) := PreservesKernel.iso F _ ≪≫ kernel.mapIso _ _ (Iso.refl _) (PreservesCokernel.iso F _) (by simp) @[reassoc (attr := simp)] theorem PreservesImage.iso_hom_ι : (PreservesImage.iso F f).hom ≫ Abelian.image.ι (F.map f) = F.map (Abelian.image.ι f) := by simp [iso] @[reassoc (attr := simp)] theorem PreservesImage.factorThruImage_iso_hom : F.map (Abelian.factorThruImage f) ≫ (PreservesImage.iso F f).hom = Abelian.factorThruImage (F.map f) := by ext; simp [iso] @[reassoc (attr := simp)] theorem PreservesImage.iso_inv_ι : (PreservesImage.iso F f).inv ≫ F.map (Abelian.image.ι f) = Abelian.image.ι (F.map f) := by simp [iso] @[reassoc (attr := simp)] theorem PreservesImage.factorThruImage_iso_inv : Abelian.factorThruImage (F.map f) ≫ (PreservesImage.iso F f).inv = F.map (Abelian.factorThruImage f) := by simp [Iso.comp_inv_eq] end Images section Coimages variable [HasKernel f] [HasCokernel (kernel.ι f)] [PreservesLimit (parallelPair f 0) F] [PreservesColimit (parallelPair (kernel.ι f) 0) F] [HasKernel (F.map f)] [HasCokernel (kernel.ι (F.map f))] /-- If a functor preserves kernels and cokernels, it preserves abelian coimages. -/ def PreservesCoimage.iso : F.obj (Abelian.coimage f) ≅ Abelian.coimage (F.map f) := PreservesCokernel.iso F _ ≪≫ cokernel.mapIso _ _ (PreservesKernel.iso F _) (Iso.refl _) (by simp) @[reassoc (attr := simp)] theorem PreservesCoimage.iso_hom_π : F.map (Abelian.coimage.π f) ≫ (PreservesCoimage.iso F f).hom = Abelian.coimage.π (F.map f) := by simp [iso] @[reassoc (attr := simp)] theorem PreservesCoimage.factorThruCoimage_iso_inv : (PreservesCoimage.iso F f).inv ≫ F.map (Abelian.factorThruCoimage f) = Abelian.factorThruCoimage (F.map f) := by ext; simp [iso] @[reassoc (attr := simp)] theorem PreservesCoimage.factorThruCoimage_iso_hom : (PreservesCoimage.iso F f).hom ≫ Abelian.factorThruCoimage (F.map f) = F.map (Abelian.factorThruCoimage f) := by simp [← Iso.eq_inv_comp] @[reassoc (attr := simp)] theorem PreservesCoimage.iso_inv_π : Abelian.coimage.π (F.map f) ≫ (PreservesCoimage.iso F f).inv = F.map (Abelian.coimage.π f) := by simp [Iso.comp_inv_eq] end Coimages variable [HasKernel f] [HasCokernel f] [HasKernel (cokernel.π f)] [HasCokernel (kernel.ι f)] [PreservesLimit (parallelPair f 0) F] [PreservesColimit (parallelPair f 0) F] [PreservesLimit (parallelPair (cokernel.π f) 0) F] [PreservesColimit (parallelPair (kernel.ι f) 0) F] [HasKernel (cokernel.π (F.map f))] [HasCokernel (kernel.ι (F.map f))] theorem PreservesCoimage.hom_coimageImageComparison : (PreservesCoimage.iso F f).hom ≫ coimageImageComparison (F.map f) = F.map (coimageImageComparison f) ≫ (PreservesImage.iso F f).hom := by simp [← Functor.map_comp, ← Iso.eq_inv_comp, ← cancel_epi (Abelian.coimage.π (F.map f)), ← cancel_mono (Abelian.image.ι (F.map f))] /-- If a functor preserves kernels and cokernels, it preserves coimage-image comparisons. -/ @[simps!] def PreservesCoimageImageComparison.iso : Arrow.mk (F.map (coimageImageComparison f)) ≅ Arrow.mk (coimageImageComparison (F.map f)) := Arrow.isoMk' _ _ (PreservesCoimage.iso F f) (PreservesImage.iso F f) (PreservesCoimage.hom_coimageImageComparison F f) end CategoryTheory.Abelian
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/BinaryProducts.lean
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Preserving binary products Constructions to relate the notions of preserving binary products and reflecting binary products to concrete binary fans. In particular, we show that `ProdComparison G X Y` is an isomorphism iff `G` preserves the product of `X` and `Y`. -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) namespace CategoryTheory.Limits section variable {P X Y Z : C} (f : P ⟶ X) (g : P ⟶ Y) /-- The map of a binary fan is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `BinaryFan.mk` with `Functor.mapCone`. -/ def isLimitMapConeBinaryFanEquiv : IsLimit (G.mapCone (BinaryFan.mk f g)) ≃ IsLimit (BinaryFan.mk (G.map f) (G.map g)) := (IsLimit.postcomposeHomEquiv (diagramIsoPair _) _).symm.trans (IsLimit.equivIsoLimit (Cones.ext (Iso.refl _) (by rintro (_ | _) <;> simp))) /-- The property of preserving products expressed in terms of binary fans. -/ def mapIsLimitOfPreservesOfIsLimit [PreservesLimit (pair X Y) G] (l : IsLimit (BinaryFan.mk f g)) : IsLimit (BinaryFan.mk (G.map f) (G.map g)) := isLimitMapConeBinaryFanEquiv G f g (isLimitOfPreserves G l) /-- The property of reflecting products expressed in terms of binary fans. -/ def isLimitOfReflectsOfMapIsLimit [ReflectsLimit (pair X Y) G] (l : IsLimit (BinaryFan.mk (G.map f) (G.map g))) : IsLimit (BinaryFan.mk f g) := isLimitOfReflects G ((isLimitMapConeBinaryFanEquiv G f g).symm l) variable (X Y) variable [HasBinaryProduct X Y] /-- If `G` preserves binary products and `C` has them, then the binary fan constructed of the mapped morphisms of the binary product cone is a limit. -/ def isLimitOfHasBinaryProductOfPreservesLimit [PreservesLimit (pair X Y) G] : IsLimit (BinaryFan.mk (G.map (Limits.prod.fst : X ⨯ Y ⟶ X)) (G.map Limits.prod.snd)) := mapIsLimitOfPreservesOfIsLimit G _ _ (prodIsProd X Y) instance [PreservesLimit (pair X Y) G] : HasBinaryProduct (G.obj X) (G.obj Y) := ⟨_, isLimitOfHasBinaryProductOfPreservesLimit G X Y⟩ variable [HasBinaryProduct (G.obj X) (G.obj Y)] /-- If the product comparison map for `G` at `(X,Y)` is an isomorphism, then `G` preserves the pair of `(X,Y)`. -/ lemma PreservesLimitPair.of_iso_prod_comparison [i : IsIso (prodComparison G X Y)] : PreservesLimit (pair X Y) G := by apply preservesLimit_of_preserves_limit_cone (prodIsProd X Y) apply (isLimitMapConeBinaryFanEquiv _ _ _).symm _ refine @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (pair (G.obj X) (G.obj Y))) ?_ apply i variable [PreservesLimit (pair X Y) G] /-- If `G` preserves the product of `(X,Y)`, then the product comparison map for `G` at `(X,Y)` is an isomorphism. -/ def PreservesLimitPair.iso : G.obj (X ⨯ Y) ≅ G.obj X ⨯ G.obj Y := IsLimit.conePointUniqueUpToIso (isLimitOfHasBinaryProductOfPreservesLimit G X Y) (limit.isLimit _) @[simp] theorem PreservesLimitPair.iso_hom : (PreservesLimitPair.iso G X Y).hom = prodComparison G X Y := rfl @[simp, reassoc] theorem PreservesLimitPair.iso_inv_fst : (PreservesLimitPair.iso G X Y).inv ≫ G.map prod.fst = prod.fst := by rw [← Iso.cancel_iso_hom_left (PreservesLimitPair.iso G X Y), ← Category.assoc, Iso.hom_inv_id] simp @[simp, reassoc] theorem PreservesLimitPair.iso_inv_snd : (PreservesLimitPair.iso G X Y).inv ≫ G.map prod.snd = prod.snd := by rw [← Iso.cancel_iso_hom_left (PreservesLimitPair.iso G X Y), ← Category.assoc, Iso.hom_inv_id] simp instance : IsIso (prodComparison G X Y) := by rw [← PreservesLimitPair.iso_hom] infer_instance /-- If the product comparison maps of `G` at every pair `(X,Y)` is an isomorphism, then `G` preserves binary products. -/ lemma preservesBinaryProducts_of_isIso_prodComparison [HasBinaryProducts C] [HasBinaryProducts D] [i : ∀ {X Y : C}, IsIso (prodComparison G X Y)] : PreservesLimitsOfShape (Discrete WalkingPair) G where preservesLimit := by intro K have : PreservesLimit (pair (K.obj ⟨WalkingPair.left⟩) (K.obj ⟨WalkingPair.right⟩)) G := PreservesLimitPair.of_iso_prod_comparison .. apply preservesLimit_of_iso_diagram G (diagramIsoPair K).symm end section variable {P X Y Z : C} (f : X ⟶ P) (g : Y ⟶ P) /-- The map of a binary cofan is a colimit iff the cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `BinaryCofan.mk` with `Functor.mapCocone`. -/ def isColimitMapCoconeBinaryCofanEquiv : IsColimit (Functor.mapCocone G (BinaryCofan.mk f g)) ≃ IsColimit (BinaryCofan.mk (G.map f) (G.map g)) := (IsColimit.precomposeHomEquiv (diagramIsoPair _).symm _).symm.trans (IsColimit.equivIsoColimit (Cocones.ext (Iso.refl _) (by rintro (_ | _) <;> simp))) /-- The property of preserving coproducts expressed in terms of binary cofans. -/ def mapIsColimitOfPreservesOfIsColimit [PreservesColimit (pair X Y) G] (l : IsColimit (BinaryCofan.mk f g)) : IsColimit (BinaryCofan.mk (G.map f) (G.map g)) := isColimitMapCoconeBinaryCofanEquiv G f g (isColimitOfPreserves G l) /-- The property of reflecting coproducts expressed in terms of binary cofans. -/ def isColimitOfReflectsOfMapIsColimit [ReflectsColimit (pair X Y) G] (l : IsColimit (BinaryCofan.mk (G.map f) (G.map g))) : IsColimit (BinaryCofan.mk f g) := isColimitOfReflects G ((isColimitMapCoconeBinaryCofanEquiv G f g).symm l) variable (X Y) variable [HasBinaryCoproduct X Y] /-- If `G` preserves binary coproducts and `C` has them, then the binary cofan constructed of the mapped morphisms of the binary product cocone is a colimit. -/ def isColimitOfHasBinaryCoproductOfPreservesColimit [PreservesColimit (pair X Y) G] : IsColimit (BinaryCofan.mk (G.map (Limits.coprod.inl : X ⟶ X ⨿ Y)) (G.map Limits.coprod.inr)) := mapIsColimitOfPreservesOfIsColimit G _ _ (coprodIsCoprod X Y) variable [HasBinaryCoproduct (G.obj X) (G.obj Y)] /-- If the coproduct comparison map for `G` at `(X,Y)` is an isomorphism, then `G` preserves the pair of `(X,Y)`. -/ lemma PreservesColimitPair.of_iso_coprod_comparison [i : IsIso (coprodComparison G X Y)] : PreservesColimit (pair X Y) G := by apply preservesColimit_of_preserves_colimit_cocone (coprodIsCoprod X Y) apply (isColimitMapCoconeBinaryCofanEquiv _ _ _).symm _ refine @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (pair (G.obj X) (G.obj Y))) ?_ apply i variable [PreservesColimit (pair X Y) G] /-- If `G` preserves the coproduct of `(X,Y)`, then the coproduct comparison map for `G` at `(X,Y)` is an isomorphism. -/ def PreservesColimitPair.iso : G.obj X ⨿ G.obj Y ≅ G.obj (X ⨿ Y) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitOfHasBinaryCoproductOfPreservesColimit G X Y) @[simp] theorem PreservesColimitPair.iso_hom : (PreservesColimitPair.iso G X Y).hom = coprodComparison G X Y := rfl instance : IsIso (coprodComparison G X Y) := by rw [← PreservesColimitPair.iso_hom] infer_instance /-- If the coproduct comparison maps of `G` at every pair `(X,Y)` is an isomorphism, then `G` preserves binary coproducts. -/ lemma preservesBinaryCoproducts_of_isIso_coprodComparison [HasBinaryCoproducts C] [HasBinaryCoproducts D] [i : ∀ {X Y : C}, IsIso (coprodComparison G X Y)] : PreservesColimitsOfShape (Discrete WalkingPair) G where preservesColimit := by intro K have : PreservesColimit (pair (K.obj ⟨WalkingPair.left⟩) (K.obj ⟨WalkingPair.right⟩)) G := PreservesColimitPair.of_iso_coprod_comparison .. apply preservesColimit_of_iso_diagram G (diagramIsoPair K).symm end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Zero.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms /-! # Preservation of zero objects and zero morphisms We define the class `PreservesZeroMorphisms` and show basic properties. ## Main results We provide the following results: * Left adjoints and right adjoints preserve zero morphisms; * full functors preserve zero morphisms; * if both categories involved have a zero object, then a functor preserves zero morphisms if and only if it preserves the zero object; * functors which preserve initial or terminal objects preserve zero morphisms. -/ universe v u v₁ v₂ v₃ u₁ u₂ u₃ noncomputable section open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory.Functor variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {E : Type u₃} [Category.{v₃} E] section ZeroMorphisms variable [HasZeroMorphisms C] [HasZeroMorphisms D] [HasZeroMorphisms E] /-- A functor preserves zero morphisms if it sends zero morphisms to zero morphisms. -/ class PreservesZeroMorphisms (F : C ⥤ D) : Prop where /-- For any pair objects `F (0: X ⟶ Y) = (0 : F X ⟶ F Y)` -/ map_zero : ∀ X Y : C, F.map (0 : X ⟶ Y) = 0 := by aesop @[simp] protected theorem map_zero (F : C ⥤ D) [PreservesZeroMorphisms F] (X Y : C) : F.map (0 : X ⟶ Y) = 0 := PreservesZeroMorphisms.map_zero _ _ lemma map_isZero (F : C ⥤ D) [PreservesZeroMorphisms F] {X : C} (hX : IsZero X) : IsZero (F.obj X) := by simp only [IsZero.iff_id_eq_zero] at hX ⊢ rw [← F.map_id, hX, F.map_zero] theorem zero_of_map_zero (F : C ⥤ D) [PreservesZeroMorphisms F] [Faithful F] {X Y : C} (f : X ⟶ Y) (h : F.map f = 0) : f = 0 := F.map_injective <| h.trans <| Eq.symm <| F.map_zero _ _ theorem map_eq_zero_iff (F : C ⥤ D) [PreservesZeroMorphisms F] [Faithful F] {X Y : C} {f : X ⟶ Y} : F.map f = 0 ↔ f = 0 := ⟨F.zero_of_map_zero _, by rintro rfl exact F.map_zero _ _⟩ instance (priority := 100) preservesZeroMorphisms_of_isLeftAdjoint (F : C ⥤ D) [IsLeftAdjoint F] : PreservesZeroMorphisms F where map_zero X Y := by let adj := Adjunction.ofIsLeftAdjoint F calc F.map (0 : X ⟶ Y) = F.map 0 ≫ F.map (adj.unit.app Y) ≫ adj.counit.app (F.obj Y) := ?_ _ = F.map 0 ≫ F.map ((rightAdjoint F).map (0 : F.obj X ⟶ _)) ≫ adj.counit.app (F.obj Y) := ?_ _ = 0 := ?_ · rw [Adjunction.left_triangle_components] exact (Category.comp_id _).symm · simp only [← Category.assoc, ← F.map_comp, zero_comp] · simp only [Adjunction.counit_naturality, comp_zero] instance (priority := 100) preservesZeroMorphisms_of_isRightAdjoint (G : C ⥤ D) [IsRightAdjoint G] : PreservesZeroMorphisms G where map_zero X Y := by let adj := Adjunction.ofIsRightAdjoint G calc G.map (0 : X ⟶ Y) = adj.unit.app (G.obj X) ≫ G.map (adj.counit.app X) ≫ G.map 0 := ?_ _ = adj.unit.app (G.obj X) ≫ G.map ((leftAdjoint G).map (0 : _ ⟶ G.obj X)) ≫ G.map 0 := ?_ _ = 0 := ?_ · rw [Adjunction.right_triangle_components_assoc] · simp only [← G.map_comp, comp_zero] · simp only [id_obj, comp_obj, Adjunction.unit_naturality_assoc, zero_comp] instance (priority := 100) preservesZeroMorphisms_of_full (F : C ⥤ D) [Full F] : PreservesZeroMorphisms F where map_zero X Y := calc F.map (0 : X ⟶ Y) = F.map (0 ≫ F.preimage (0 : F.obj Y ⟶ F.obj Y)) := by rw [zero_comp] _ = 0 := by rw [F.map_comp, F.map_preimage, comp_zero] instance preservesZeroMorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] : (F ⋙ G).PreservesZeroMorphisms := ⟨by simp⟩ lemma preservesZeroMorphisms_of_iso {F₁ F₂ : C ⥤ D} [F₁.PreservesZeroMorphisms] (e : F₁ ≅ F₂) : F₂.PreservesZeroMorphisms where map_zero X Y := by simp only [← cancel_epi (e.hom.app X), ← e.hom.naturality, F₁.map_zero, zero_comp, comp_zero] instance preservesZeroMorphisms_evaluation_obj (j : D) : PreservesZeroMorphisms ((evaluation D C).obj j) where instance (F : C ⥤ D ⥤ E) [∀ X, (F.obj X).PreservesZeroMorphisms] : F.flip.PreservesZeroMorphisms where instance (F : C ⥤ D ⥤ E) [F.PreservesZeroMorphisms] (Y : D) : (F.flip.obj Y).PreservesZeroMorphisms where omit [HasZeroMorphisms C] in @[simp] lemma whiskerRight_zero {F G : C ⥤ D} (H : D ⥤ E) [H.PreservesZeroMorphisms] : whiskerRight (0 : F ⟶ G) H = 0 := by cat_disch end ZeroMorphisms section ZeroObject variable [HasZeroObject C] [HasZeroObject D] open ZeroObject variable [HasZeroMorphisms C] [HasZeroMorphisms D] (F : C ⥤ D) /-- A functor that preserves zero morphisms also preserves the zero object. -/ @[simps] def mapZeroObject [PreservesZeroMorphisms F] : F.obj 0 ≅ 0 where hom := 0 inv := 0 hom_inv_id := by rw [← F.map_id, id_zero, F.map_zero, zero_comp] inv_hom_id := by rw [id_zero, comp_zero] variable {F} theorem preservesZeroMorphisms_of_map_zero_object (i : F.obj 0 ≅ 0) : PreservesZeroMorphisms F where map_zero X Y := calc F.map (0 : X ⟶ Y) = F.map (0 : X ⟶ 0) ≫ F.map 0 := by rw [← Functor.map_comp, comp_zero] _ = F.map 0 ≫ (i.hom ≫ i.inv) ≫ F.map 0 := by rw [Iso.hom_inv_id, Category.id_comp] _ = 0 := by simp only [zero_of_to_zero i.hom, zero_comp, comp_zero] instance (priority := 100) preservesZeroMorphisms_of_preserves_initial_object [PreservesColimit (Functor.empty.{0} C) F] : PreservesZeroMorphisms F := preservesZeroMorphisms_of_map_zero_object <| F.mapIso HasZeroObject.zeroIsoInitial ≪≫ PreservesInitial.iso F ≪≫ HasZeroObject.zeroIsoInitial.symm instance (priority := 100) preservesZeroMorphisms_of_preserves_terminal_object [PreservesLimit (Functor.empty.{0} C) F] : PreservesZeroMorphisms F := preservesZeroMorphisms_of_map_zero_object <| F.mapIso HasZeroObject.zeroIsoTerminal ≪≫ PreservesTerminal.iso F ≪≫ HasZeroObject.zeroIsoTerminal.symm variable (F) /-- Preserving zero morphisms implies preserving terminal objects. -/ lemma preservesTerminalObject_of_preservesZeroMorphisms [PreservesZeroMorphisms F] : PreservesLimit (Functor.empty.{0} C) F := preservesTerminal_of_iso F <| F.mapIso HasZeroObject.zeroIsoTerminal.symm ≪≫ mapZeroObject F ≪≫ HasZeroObject.zeroIsoTerminal /-- Preserving zero morphisms implies preserving terminal objects. -/ lemma preservesInitialObject_of_preservesZeroMorphisms [PreservesZeroMorphisms F] : PreservesColimit (Functor.empty.{0} C) F := preservesInitial_of_iso F <| HasZeroObject.zeroIsoInitial.symm ≪≫ (mapZeroObject F).symm ≪≫ (F.mapIso HasZeroObject.zeroIsoInitial.symm).symm end ZeroObject section variable [HasZeroObject D] [HasZeroMorphisms D] (G : C ⥤ D) (hG : IsZero G) (J : Type*) [Category J] include hG /-- A zero functor preserves limits. -/ lemma preservesLimitsOfShape_of_isZero : PreservesLimitsOfShape J G where preservesLimit {K} := ⟨fun _ => ⟨by rw [Functor.isZero_iff] at hG exact IsLimit.ofIsZero _ ((K ⋙ G).isZero (fun X ↦ hG _)) (hG _)⟩⟩ /-- A zero functor preserves colimits. -/ lemma preservesColimitsOfShape_of_isZero : PreservesColimitsOfShape J G where preservesColimit {K} := ⟨fun _ => ⟨by rw [Functor.isZero_iff] at hG exact IsColimit.ofIsZero _ ((K ⋙ G).isZero (fun X ↦ hG _)) (hG _)⟩⟩ /-- A zero functor preserves limits. -/ lemma preservesLimitsOfSize_of_isZero : PreservesLimitsOfSize.{v, u} G where preservesLimitsOfShape := G.preservesLimitsOfShape_of_isZero hG _ /-- A zero functor preserves colimits. -/ lemma preservesColimitsOfSize_of_isZero : PreservesColimitsOfSize.{v, u} G where preservesColimitsOfShape := G.preservesColimitsOfShape_of_isZero hG _ end end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Pullbacks import Mathlib.CategoryTheory.Limits.Yoneda /-! # Preserving pullbacks Constructions to relate the notions of preserving pullbacks and reflecting pullbacks to concrete pullback cones. In particular, we show that `pullbackComparison G f g` is an isomorphism iff `G` preserves the pullback of `f` and `g`. The dual is also given. ## TODO * Generalise to wide pullbacks -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Functor namespace CategoryTheory.Limits section Pullback variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] namespace PullbackCone variable {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) (G : C ⥤ D) /-- The image of a pullback cone by a functor. -/ abbrev map : PullbackCone (G.map f) (G.map g) := PullbackCone.mk (G.map c.fst) (G.map c.snd) (by simpa using G.congr_map c.condition) /-- The map (as a cone) of a pullback cone is limit iff the map (as a pullback cone) is limit. -/ def isLimitMapConeEquiv : IsLimit (mapCone G c) ≃ IsLimit (c.map G) := (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₂} _) _).symm.trans <| IsLimit.equivIsoLimit <| by refine PullbackCone.ext (Iso.refl _) ?_ ?_ · dsimp only [fst] simp · dsimp only [snd] simp end PullbackCone variable (G : C ⥤ D) variable {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} {h : W ⟶ X} {k : W ⟶ Y} (comm : h ≫ f = k ≫ g) /-- The map of a pullback cone is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `PullbackCone.mk` with `Functor.mapCone`. -/ def isLimitMapConePullbackConeEquiv : IsLimit (mapCone G (PullbackCone.mk h k comm)) ≃ IsLimit (PullbackCone.mk (G.map h) (G.map k) (by simp only [← G.map_comp, comm]) : PullbackCone (G.map f) (G.map g)) := (PullbackCone.mk _ _ comm).isLimitMapConeEquiv G /-- The property of preserving pullbacks expressed in terms of binary fans. -/ def isLimitPullbackConeMapOfIsLimit [PreservesLimit (cospan f g) G] (l : IsLimit (PullbackCone.mk h k comm)) : have : G.map h ≫ G.map f = G.map k ≫ G.map g := by rw [← G.map_comp, ← G.map_comp,comm] IsLimit (PullbackCone.mk (G.map h) (G.map k) this) := (PullbackCone.isLimitMapConeEquiv _ G).1 (isLimitOfPreserves G l) /-- The property of reflecting pullbacks expressed in terms of binary fans. -/ def isLimitOfIsLimitPullbackConeMap [ReflectsLimit (cospan f g) G] (l : IsLimit (PullbackCone.mk (G.map h) (G.map k) (show G.map h ≫ G.map f = G.map k ≫ G.map g from by simp only [← G.map_comp, comm]))) : IsLimit (PullbackCone.mk h k comm) := isLimitOfReflects G ((PullbackCone.isLimitMapConeEquiv (PullbackCone.mk _ _ comm) G).2 l) variable (f g) [PreservesLimit (cospan f g) G] /-- If `G` preserves pullbacks and `C` has them, then the pullback cone constructed of the mapped morphisms of the pullback cone is a limit. -/ def isLimitOfHasPullbackOfPreservesLimit [HasPullback f g] : have : G.map (pullback.fst f g) ≫ G.map f = G.map (pullback.snd f g) ≫ G.map g := by simp only [← G.map_comp, pullback.condition] IsLimit (PullbackCone.mk (G.map (pullback.fst f g)) (G.map (pullback.snd f g)) this) := isLimitPullbackConeMapOfIsLimit G _ (pullbackIsPullback f g) /-- If `F` preserves the pullback of `f, g`, it also preserves the pullback of `g, f`. -/ lemma preservesPullback_symmetry : PreservesLimit (cospan g f) G where preserves {c} hc := ⟨by apply (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₂} _) _).toFun apply IsLimit.ofIsoLimit _ (PullbackCone.isoMk _).symm apply PullbackCone.isLimitOfFlip apply (isLimitMapConePullbackConeEquiv _ _).toFun · refine @isLimitOfPreserves _ _ _ _ _ _ _ _ _ ?_ ?_ · apply PullbackCone.isLimitOfFlip apply IsLimit.ofIsoLimit _ (PullbackCone.isoMk _) exact (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₁} _) _).invFun hc · dsimp infer_instance · exact (c.π.naturality WalkingCospan.Hom.inr).symm.trans (c.π.naturality WalkingCospan.Hom.inl :)⟩ theorem hasPullback_of_preservesPullback [HasPullback f g] : HasPullback (G.map f) (G.map g) := ⟨⟨⟨_, isLimitPullbackConeMapOfIsLimit G _ (pullbackIsPullback _ _)⟩⟩⟩ variable [HasPullback f g] [HasPullback (G.map f) (G.map g)] /-- If `G` preserves the pullback of `(f,g)`, then the pullback comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesPullback.iso : G.obj (pullback f g) ≅ pullback (G.map f) (G.map g) := IsLimit.conePointUniqueUpToIso (isLimitOfHasPullbackOfPreservesLimit G f g) (limit.isLimit _) @[simp] theorem PreservesPullback.iso_hom : (PreservesPullback.iso G f g).hom = pullbackComparison G f g := rfl @[reassoc] theorem PreservesPullback.iso_hom_fst : (PreservesPullback.iso G f g).hom ≫ pullback.fst _ _ = G.map (pullback.fst f g) := by simp [PreservesPullback.iso] @[reassoc] theorem PreservesPullback.iso_hom_snd : (PreservesPullback.iso G f g).hom ≫ pullback.snd _ _ = G.map (pullback.snd f g) := by simp [PreservesPullback.iso] @[reassoc (attr := simp)] theorem PreservesPullback.iso_inv_fst : (PreservesPullback.iso G f g).inv ≫ G.map (pullback.fst f g) = pullback.fst _ _ := by simp [PreservesPullback.iso, Iso.inv_comp_eq] @[reassoc (attr := simp)] theorem PreservesPullback.iso_inv_snd : (PreservesPullback.iso G f g).inv ≫ G.map (pullback.snd f g) = pullback.snd _ _ := by simp [PreservesPullback.iso, Iso.inv_comp_eq] /-- A pullback cone in `C` is limit iff if it is so after the application of `coyoneda.obj X` for all `X : Cᵒᵖ`. -/ def PullbackCone.isLimitCoyonedaEquiv (c : PullbackCone f g) : IsLimit c ≃ ∀ (X : Cᵒᵖ), IsLimit (c.map (coyoneda.obj X)) := (Cone.isLimitCoyonedaEquiv c).trans (Equiv.piCongrRight (fun X ↦ c.isLimitMapConeEquiv (coyoneda.obj X))) end Pullback section Pushout variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] namespace PushoutCocone variable {W X Y : C} {f : W ⟶ X} {g : W ⟶ Y} (c : PushoutCocone f g) (G : C ⥤ D) /-- The image of a pullback cone by a functor. -/ abbrev map : PushoutCocone (G.map f) (G.map g) := PushoutCocone.mk (G.map c.inl) (G.map c.inr) (by simpa using G.congr_map c.condition) /-- The map (as a cocone) of a pushout cocone is colimit iff the map (as a pushout cocone) is limit. -/ def isColimitMapCoconeEquiv : IsColimit (mapCocone G c) ≃ IsColimit (c.map G) := (IsColimit.precomposeHomEquiv (diagramIsoSpan.{v₂} _).symm _).symm.trans <| IsColimit.equivIsoColimit <| by refine PushoutCocone.ext (Iso.refl _) ?_ ?_ · dsimp only [inl] simp · dsimp only [inr] simp end PushoutCocone variable (G : C ⥤ D) variable {W X Y Z : C} {h : X ⟶ Z} {k : Y ⟶ Z} {f : W ⟶ X} {g : W ⟶ Y} (comm : f ≫ h = g ≫ k) /-- The map of a pushout cocone is a colimit iff the cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `PushoutCocone.mk` with `Functor.mapCocone`. -/ def isColimitMapCoconePushoutCoconeEquiv : IsColimit (mapCocone G (PushoutCocone.mk h k comm)) ≃ IsColimit (PushoutCocone.mk (G.map h) (G.map k) (by simp only [← G.map_comp, comm]) : PushoutCocone (G.map f) (G.map g)) := (IsColimit.precomposeHomEquiv (diagramIsoSpan.{v₂} _).symm _).symm.trans <| IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) <| by rintro (_ | _ | _) <;> dsimp <;> simp only [Category.comp_id, Category.id_comp, ← G.map_comp] /-- The property of preserving pushouts expressed in terms of binary cofans. -/ def isColimitPushoutCoconeMapOfIsColimit [PreservesColimit (span f g) G] (l : IsColimit (PushoutCocone.mk h k comm)) : IsColimit (PushoutCocone.mk (G.map h) (G.map k) (show G.map f ≫ G.map h = G.map g ≫ G.map k from by simp only [← G.map_comp,comm] )) := isColimitMapCoconePushoutCoconeEquiv G comm (isColimitOfPreserves G l) /-- The property of reflecting pushouts expressed in terms of binary cofans. -/ def isColimitOfIsColimitPushoutCoconeMap [ReflectsColimit (span f g) G] (l : IsColimit (PushoutCocone.mk (G.map h) (G.map k) (show G.map f ≫ G.map h = G.map g ≫ G.map k from by simp only [← G.map_comp, comm]))) : IsColimit (PushoutCocone.mk h k comm) := isColimitOfReflects G ((isColimitMapCoconePushoutCoconeEquiv G comm).symm l) variable (f g) [PreservesColimit (span f g) G] /-- If `G` preserves pushouts and `C` has them, then the pushout cocone constructed of the mapped morphisms of the pushout cocone is a colimit. -/ def isColimitOfHasPushoutOfPreservesColimit [i : HasPushout f g] : IsColimit (PushoutCocone.mk (G.map (pushout.inl _ _)) (G.map (@pushout.inr _ _ _ _ _ f g i)) (show G.map f ≫ G.map (pushout.inl _ _) = G.map g ≫ G.map (pushout.inr _ _) from by simp only [← G.map_comp, pushout.condition])) := isColimitPushoutCoconeMapOfIsColimit G _ (pushoutIsPushout f g) /-- If `F` preserves the pushout of `f, g`, it also preserves the pushout of `g, f`. -/ lemma preservesPushout_symmetry : PreservesColimit (span g f) G where preserves {c} hc := ⟨by apply (IsColimit.precomposeHomEquiv (diagramIsoSpan.{v₂} _).symm _).toFun apply IsColimit.ofIsoColimit _ (PushoutCocone.isoMk _).symm apply PushoutCocone.isColimitOfFlip apply (isColimitMapCoconePushoutCoconeEquiv _ _).toFun · -- Need to unfold these to allow the `PreservesColimit` instance to be found. dsimp only [span_map_fst, span_map_snd] exact isColimitOfPreserves _ (PushoutCocone.flipIsColimit hc)⟩ theorem hasPushout_of_preservesPushout [HasPushout f g] : HasPushout (G.map f) (G.map g) := ⟨⟨⟨_, isColimitPushoutCoconeMapOfIsColimit G _ (pushoutIsPushout _ _)⟩⟩⟩ variable [HasPushout f g] [HasPushout (G.map f) (G.map g)] /-- If `G` preserves the pushout of `(f,g)`, then the pushout comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesPushout.iso : pushout (G.map f) (G.map g) ≅ G.obj (pushout f g) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitOfHasPushoutOfPreservesColimit G f g) @[simp] theorem PreservesPushout.iso_hom : (PreservesPushout.iso G f g).hom = pushoutComparison G f g := rfl @[reassoc] theorem PreservesPushout.inl_iso_hom : pushout.inl _ _ ≫ (PreservesPushout.iso G f g).hom = G.map (pushout.inl _ _) := by simp @[reassoc] theorem PreservesPushout.inr_iso_hom : pushout.inr _ _ ≫ (PreservesPushout.iso G f g).hom = G.map (pushout.inr _ _) := by simp @[reassoc (attr := simp)] theorem PreservesPushout.inl_iso_inv : G.map (pushout.inl _ _) ≫ (PreservesPushout.iso G f g).inv = pushout.inl _ _ := by simp [PreservesPushout.iso, Iso.comp_inv_eq] @[reassoc (attr := simp)] theorem PreservesPushout.inr_iso_inv : G.map (pushout.inr _ _) ≫ (PreservesPushout.iso G f g).inv = pushout.inr _ _ := by simp [PreservesPushout.iso, Iso.comp_inv_eq] end Pushout section variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) section Pullback variable {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} variable [HasPullback f g] [HasPullback (G.map f) (G.map g)] /-- If the pullback comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the pullback of `(f,g)`. -/ lemma PreservesPullback.of_iso_comparison [i : IsIso (pullbackComparison G f g)] : PreservesLimit (cospan f g) G := by apply preservesLimit_of_preserves_limit_cone (pullbackIsPullback f g) apply (isLimitMapConePullbackConeEquiv _ _).symm _ exact @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (cospan (G.map f) (G.map g))) i variable [PreservesLimit (cospan f g) G] instance : IsIso (pullbackComparison G f g) := by rw [← PreservesPullback.iso_hom] infer_instance end Pullback section Pushout variable {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} variable [HasPushout f g] [HasPushout (G.map f) (G.map g)] /-- If the pushout comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the pushout of `(f,g)`. -/ lemma PreservesPushout.of_iso_comparison [i : IsIso (pushoutComparison G f g)] : PreservesColimit (span f g) G := by apply preservesColimit_of_preserves_colimit_cocone (pushoutIsPushout f g) apply (isColimitMapCoconePushoutCoconeEquiv _ _).symm _ exact IsColimit.ofPointIso _ (i := i) variable [PreservesColimit (span f g) G] instance : IsIso (pushoutComparison G f g) := by rw [← PreservesPushout.iso_hom] infer_instance /-- A pushout cocone in `C` is colimit iff it becomes limit after the application of `yoneda.obj X` for all `X : C`. -/ def PushoutCocone.isColimitYonedaEquiv (c : PushoutCocone f g) : IsColimit c ≃ ∀ (X : C), IsLimit (c.op.map (yoneda.obj X)) := (Limits.Cocone.isColimitYonedaEquiv c).trans (Equiv.piCongrRight (fun X ↦ (IsLimit.whiskerEquivalenceEquiv walkingSpanOpEquiv.symm).trans ((IsLimit.postcomposeHomEquiv (isoWhiskerRight (cospanOp f g).symm (yoneda.obj X)) _).symm.trans (Equiv.trans (IsLimit.equivIsoLimit (by exact Cones.ext (Iso.refl _) (by rintro (_ | _ | _) <;> simp))) (c.op.isLimitMapConeEquiv (yoneda.obj X)))))) end Pushout end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/CardinalArrow.lean
import Mathlib.CategoryTheory.Comma.Arrow import Mathlib.CategoryTheory.FinCategory.Basic import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.Data.Set.Finite.Basic import Mathlib.SetTheory.Cardinal.HasCardinalLT /-! # Cardinal of Arrow We obtain various results about the cardinality of `Arrow C`. For example, If `A` is a (small) category, `Arrow C` is finite iff `FinCategory C` holds. -/ universe w w' v u namespace CategoryTheory lemma Arrow.finite_iff (C : Type u) [SmallCategory C] : Finite (Arrow C) ↔ Nonempty (FinCategory C) := by constructor · intro refine ⟨?_, fun a b ↦ ?_⟩ · have := Finite.of_injective (fun (a : C) ↦ Arrow.mk (𝟙 a)) (fun _ _ ↦ congr_arg Comma.left) apply Fintype.ofFinite · have := Finite.of_injective (fun (f : a ⟶ b) ↦ Arrow.mk f) (fun f g h ↦ by change (Arrow.mk f).hom = (Arrow.mk g).hom congr) apply Fintype.ofFinite · rintro ⟨_⟩ have := Fintype.ofEquiv _ (Arrow.equivSigma C).symm infer_instance instance Arrow.finite {C : Type u} [SmallCategory C] [FinCategory C] : Finite (Arrow C) := by rw [Arrow.finite_iff] exact ⟨inferInstance⟩ /-- The bijection `Arrow Cᵒᵖ ≃ Arrow C`. -/ def Arrow.opEquiv (C : Type u) [Category.{v} C] : Arrow Cᵒᵖ ≃ Arrow C where toFun f := Arrow.mk f.hom.unop invFun g := Arrow.mk g.hom.op @[simp] lemma hasCardinalLT_arrow_op_iff (C : Type u) [Category.{v} C] (κ : Cardinal.{w}) : HasCardinalLT (Arrow Cᵒᵖ) κ ↔ HasCardinalLT (Arrow C) κ := hasCardinalLT_iff_of_equiv (Arrow.opEquiv C) κ @[simp] lemma hasCardinalLT_arrow_discrete_iff {X : Type u} (κ : Cardinal.{w}) : HasCardinalLT (Arrow (Discrete X)) κ ↔ HasCardinalLT X κ := hasCardinalLT_iff_of_equiv (Arrow.discreteEquiv X) κ lemma small_of_small_arrow (C : Type u) [Category.{v} C] [Small.{w} (Arrow C)] : Small.{w} C := small_of_injective (f := fun X ↦ Arrow.mk (𝟙 X)) (fun _ _ h ↦ congr_arg Comma.left h) lemma locallySmall_of_small_arrow (C : Type u) [Category.{v} C] [Small.{w} (Arrow C)] : LocallySmall.{w} C where hom_small X Y := small_of_injective (f := fun f ↦ Arrow.mk f) (fun f g h ↦ by change (Arrow.mk f).hom = (Arrow.mk g).hom congr) /-- The bijection `Arrow.{w} (ShrinkHoms C) ≃ Arrow C`. -/ noncomputable def Arrow.shrinkHomsEquiv (C : Type u) [Category.{v} C] [LocallySmall.{w} C] : Arrow.{w} (ShrinkHoms C) ≃ Arrow C where toFun := (ShrinkHoms.equivalence C).inverse.mapArrow.obj invFun := (ShrinkHoms.equivalence C).functor.mapArrow.obj left_inv _ := by simp right_inv _ := by simp /-- The bijection `Arrow (Shrink C) ≃ Arrow C`. -/ noncomputable def Arrow.shrinkEquiv (C : Type u) [Category.{v} C] [Small.{w} C] : Arrow (Shrink.{w} C) ≃ Arrow C where toFun := (Shrink.equivalence C).inverse.mapArrow.obj invFun := (Shrink.equivalence C).functor.mapArrow.obj left_inv _ := Arrow.ext (Equiv.apply_symm_apply _ _) ((Equiv.apply_symm_apply _ _)) (by simp; rfl) right_inv _ := Arrow.ext (by simp [Shrink.equivalence]) (by simp [Shrink.equivalence]) (by simp [Shrink.equivalence]) @[simp] lemma hasCardinalLT_arrow_shrinkHoms_iff (C : Type u) [Category.{v} C] [LocallySmall.{w'} C] (κ : Cardinal.{w}) : HasCardinalLT (Arrow.{w'} (ShrinkHoms C)) κ ↔ HasCardinalLT (Arrow C) κ := hasCardinalLT_iff_of_equiv (Arrow.shrinkHomsEquiv C) κ @[simp] lemma hasCardinalLT_arrow_shrink_iff (C : Type u) [Category.{v} C] [Small.{w'} C] (κ : Cardinal.{w}) : HasCardinalLT (Arrow (Shrink.{w'} C)) κ ↔ HasCardinalLT (Arrow C) κ := hasCardinalLT_iff_of_equiv (Arrow.shrinkEquiv C) κ lemma hasCardinalLT_of_hasCardinalLT_arrow {C : Type u} [Category.{v} C] {κ : Cardinal.{w}} (h : HasCardinalLT (Arrow C) κ) : HasCardinalLT C κ := h.of_injective (fun X ↦ Arrow.mk (𝟙 X)) (fun _ _ h ↦ congr_arg Comma.left h) end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/LocallySmall.lean
import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.EssentiallySmall /-! # Comma categories are locally small We introduce instances showing that the various comma categories are locally small when the relevant categories that are involved are locally small. -/ universe w v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory variable {A : Type u₁} {B : Type u₂} {T : Type u₃} [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} T] instance Comma.locallySmall (L : A ⥤ T) (R : B ⥤ T) [LocallySmall.{w} A] [LocallySmall.{w} B] : LocallySmall.{w} (Comma L R) where hom_small X Y := small_of_injective.{w} (f := fun g ↦ (⟨g.left, g.right⟩ : _ × _)) (fun _ _ _ ↦ by aesop) instance StructuredArrow.locallySmall (S : T) (T : B ⥤ T) [LocallySmall.{w} B] : LocallySmall.{w} (StructuredArrow S T) := Comma.locallySmall _ _ instance CostructuredArrow.locallySmall (S : A ⥤ T) (X : T) [LocallySmall.{w} A] : LocallySmall.{w} (CostructuredArrow S X) := Comma.locallySmall _ _ instance Over.locallySmall (X : T) [LocallySmall.{w} T] : LocallySmall.{w} (Over X) := CostructuredArrow.locallySmall _ _ instance Under.locallySmall (X : T) [LocallySmall.{w} T] : LocallySmall.{w} (Under X) := StructuredArrow.locallySmall _ _ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Final.lean
import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Limits.IsConnected import Mathlib.CategoryTheory.Limits.Sifted import Mathlib.CategoryTheory.Filtered.Final import Mathlib.CategoryTheory.Filtered.Flat import Mathlib.CategoryTheory.Grothendieck import Mathlib.CategoryTheory.Comma.StructuredArrow.CommaMap /-! # Finality of Projections in Comma Categories We show that `fst L R` is final if `R` is and that `snd L R` is initial if `L` is. As a corollary, we show that `Comma L R` with `L : A ⥤ T` and `R : B ⥤ T` is connected if `R` is final and `A` is connected. We then use this in a proof that derives finality of `map` between two comma categories on a quasi-commutative diagram of functors, some of which need to be final. Finally we prove filteredness of a `Comma L R` and finality of `snd L R`, given that `R` is final and `A` and `B` are filtered. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Lemma 3.4.3 -- 3.4.5 -/ universe v₁ v₂ v₃ v₄ v₅ v₆ u₁ u₂ u₃ u₄ u₅ u₆ namespace CategoryTheory namespace Comma open Limits Functor CostructuredArrow section Small variable {A : Type v₁} [Category.{v₁} A] variable {B : Type v₁} [Category.{v₁} B] variable {T : Type v₁} [Category.{v₁} T] variable (L : A ⥤ T) (R : B ⥤ T) private lemma final_fst_small [R.Final] : (fst L R).Final := by rw [Functor.final_iff_isIso_colimit_pre] intro G let i : colimit G ≅ colimit (fst L R ⋙ G) := colimitIsoColimitGrothendieck L G ≪≫ (Final.colimitIso (Grothendieck.pre (functor L) R) (grothendieckProj L ⋙ G)).symm ≪≫ HasColimit.isoOfNatIso (Iso.refl _) ≪≫ Final.colimitIso (grothendieckPrecompFunctorEquivalence L R).functor (fst L R ⋙ G) convert i.isIso_inv apply colimit.hom_ext intro ⟨a, b, f⟩ simp only [colimit.ι_pre, comp_obj, fst_obj, grothendieckPrecompFunctorEquivalence_functor, Iso.trans_inv, Iso.symm_inv, Category.assoc, i] change _ = colimit.ι (fst L R ⋙ G) ((grothendieckPrecompFunctorToComma L R).obj ⟨b, CostructuredArrow.mk f⟩) ≫ _ simp end Small section NonSmall variable {A : Type u₁} [Category.{v₁} A] variable {B : Type u₂} [Category.{v₂} B] variable {T : Type u₃} [Category.{v₃} T] variable (L : A ⥤ T) (R : B ⥤ T) instance final_fst [R.Final] : (fst L R).Final := by let sA : A ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} A := AsSmall.equiv let sB : B ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} B := AsSmall.equiv let sT : T ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} T := AsSmall.equiv let L' := sA.inverse ⋙ L ⋙ sT.functor let R' := sB.inverse ⋙ R ⋙ sT.functor let fC : Comma L R ⥤ Comma L' R' := map (F₁ := sA.functor) (F := sT.functor) (F₂ := sB.functor) (isoWhiskerRight sA.unitIso (L ⋙ sT.functor)).hom (isoWhiskerRight sB.unitIso (R ⋙ sT.functor)).hom have : Final (fst L' R') := final_fst_small _ _ apply final_of_natIso (F := (fC ⋙ fst L' R' ⋙ sA.inverse)) exact (Functor.associator _ _ _).symm.trans (Iso.compInverseIso (mapFst _ _)) instance initial_snd [L.Initial] : (snd L R).Initial := by have : ((opFunctor L R).leftOp ⋙ fst R.op L.op).Final := final_equivalence_comp (opEquiv L R).functor.leftOp (fst R.op L.op) have : (snd L R).op.Final := final_of_natIso (opFunctorCompFst _ _) apply initial_of_final_op /-- `Comma L R` with `L : A ⥤ T` and `R : B ⥤ T` is connected if `R` is final and `A` is connected. -/ instance isConnected_comma_of_final [IsConnected A] [R.Final] : IsConnected (Comma L R) := by rwa [isConnected_iff_of_final (fst L R)] /-- `Comma L R` with `L : A ⥤ T` and `R : B ⥤ T` is connected if `L` is initial and `B` is connected. -/ instance isConnected_comma_of_initial [IsConnected B] [L.Initial] : IsConnected (Comma L R) := by rwa [isConnected_iff_of_initial (snd L R)] end NonSmall /-- Let the following diagram commute up to isomorphism: ``` L R A ---→ T ←--- B | | | | F | H | G ↓ ↓ ↓ A' ---→ T' ←--- B' L' R' ``` Let `F`, `G`, `R` and `R'` be final and `B` be filtered. Then, the induced functor between the comma categories of the first and second row of the diagram is final. -/ lemma map_final {A : Type u₁} [Category.{v₁} A] {B : Type u₂} [Category.{v₂} B] {T : Type u₃} [Category.{v₃} T] {L : A ⥤ T} {R : B ⥤ T} {A' : Type u₄} [Category.{v₄} A'] {B' : Type u₅} [Category.{v₅} B'] {T' : Type u₆} [Category.{v₆} T'] {L' : A' ⥤ T'} {R' : B' ⥤ T'} {F : A ⥤ A'} {G : B ⥤ B'} {H : T ⥤ T'} (iL : F ⋙ L' ≅ L ⋙ H) (iR : G ⋙ R' ≅ R ⋙ H) [IsFiltered B] [R.Final] [R'.Final] [F.Final] [G.Final] : (Comma.map iL.hom iR.inv).Final := ⟨fun ⟨i₂, j₂, u₂⟩ => by haveI := final_of_natIso iR rw [isConnected_iff_of_equivalence (StructuredArrow.commaMapEquivalence iL.hom iR.inv _)] have : StructuredArrow.map₂ u₂ iR.hom ≅ StructuredArrow.post j₂ G R' ⋙ StructuredArrow.map₂ (G := 𝟭 _) (F := 𝟭 _) (R' := R ⋙ H) u₂ iR.hom ⋙ StructuredArrow.pre _ R H := eqToIso (by congr · simp · ext; simp) ≪≫ (StructuredArrow.map₂CompMap₂Iso _ _ _ _).symm ≪≫ isoWhiskerLeft _ ((StructuredArrow.map₂CompMap₂Iso _ _ _ _).symm ≪≫ isoWhiskerLeft _ (StructuredArrow.preIsoMap₂ _ _ _).symm) ≪≫ isoWhiskerRight (StructuredArrow.postIsoMap₂ j₂ G R').symm _ haveI := final_of_natIso this.symm rw [IsIso.Iso.inv_inv] infer_instance⟩ section Filtered variable {A : Type u₁} [Category.{v₁} A] variable {B : Type u₂} [Category.{v₂} B] variable {T : Type u₃} [Category.{v₃} T] variable (L : A ⥤ T) (R : B ⥤ T) attribute [local instance] map_final in /-- Let `A` and `B` be filtered categories, `R : B ⥤ T` be final and `L : A ⥤ T`. Then, the comma category `Comma L R` is filtered. -/ instance isFiltered_of_final [IsFiltered A] [IsFiltered B] [R.Final] : IsFiltered (Comma L R) := by haveI (a : A) : IsFiltered (Comma (fromPUnit (L.obj a)) R) := R.final_iff_isFiltered_structuredArrow.mp inferInstance (L.obj a) have (a : A) : (fromPUnit (Over.mk (𝟙 a))).Final := final_const_of_isTerminal Over.mkIdTerminal let η (a : A) : fromPUnit (Over.mk (𝟙 a)) ⋙ Over.forget a ⋙ L ≅ fromPUnit (L.obj a) := NatIso.ofComponents (fun _ => Iso.refl _) have (a : A) := IsFiltered.of_final (map (L := fromPUnit (L.obj a)) (F := 𝟭 T) (η a).hom ((Iso.refl (𝟭 B ⋙ R)).inv)) have : RepresentablyCoflat (fst L R) := ⟨fun a => IsFiltered.of_equivalence (CostructuredArrow.ofCommaFstEquivalence L R a).symm⟩ apply isFiltered_of_representablyCoflat (fst L R) attribute [local instance] isFiltered_of_final in /-- Let `A` and `B` be cofiltered categories, `L : A ⥤ T` be initial and `R : B ⥤ T`. Then, the comma category `Comma L R` is cofiltered. -/ lemma isCofiltered_of_initial [IsCofiltered A] [IsCofiltered B] [L.Initial] : IsCofiltered (Comma L R) := IsCofiltered.of_equivalence (Comma.opEquiv _ _).symm attribute [local instance] final_of_isFiltered_of_pUnit in /-- Let `A` and `B` be filtered categories, `R : B ⥤ T` be final and `R : A ⥤ T`. Then, the projection `snd L R : Comma L R ⥤ B` is final. -/ instance final_snd [IsFiltered A] [IsFiltered B] [R.Final] : (snd L R).Final := by let iL : star.{1} A ⋙ 𝟭 _ ≅ L ⋙ star _ := Iso.refl _ let iR : 𝟭 B ⋙ star.{1} B ≅ R ⋙ star _ := Iso.refl _ have := map_final iL iR let s := (equivProd (𝟭 _) (star B)).trans <| prod.leftUnitorEquivalence B let iS : map iL.hom iR.inv ⋙ s.functor ≅ snd L R := NatIso.ofComponents (fun _ => Iso.refl _) (fun f => by simp [iL, iR, s]) apply final_of_natIso iS /-- Let `A` and `B` be cofiltered categories, `L : A ⥤ T` be initial and `R : B ⥤ T`. Then, the projection `fst L R : Comma L R ⥤ A` is initial. -/ instance initial_fst [IsCofiltered A] [IsCofiltered B] [L.Initial] : (fst L R).Initial := by have : ((opFunctor L R).leftOp ⋙ snd R.op L.op).Final := final_equivalence_comp (opEquiv L R).functor.leftOp _ have : (fst L R).op.Final := final_of_natIso <| opFunctorCompSnd _ _ apply initial_of_final_op end Filtered end Comma end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Basic.lean
import Mathlib.CategoryTheory.Iso import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Products.Unitor /-! # Comma categories A comma category is a construction in category theory, which builds a category out of two functors with a common codomain. Specifically, for functors `L : A ⥤ T` and `R : B ⥤ T`, an object in `Comma L R` is a morphism `hom : L.obj left ⟶ R.obj right` for some objects `left : A` and `right : B`, and a morphism in `Comma L R` between `hom : L.obj left ⟶ R.obj right` and `hom' : L.obj left' ⟶ R.obj right'` is a commutative square ``` L.obj left ⟶ L.obj left' | | hom | | hom' ↓ ↓ R.obj right ⟶ R.obj right', ``` where the top and bottom morphism come from morphisms `left ⟶ left'` and `right ⟶ right'`, respectively. ## Main definitions * `Comma L R`: the comma category of the functors `L` and `R`. * `Over X`: the over category of the object `X` (developed in `Over.lean`). * `Under X`: the under category of the object `X` (also developed in `Over.lean`). * `Arrow T`: the arrow category of the category `T` (developed in `Arrow.lean`). ## References * <https://ncatlab.org/nlab/show/comma+category> ## Tags comma, slice, coslice, over, under, arrow -/ namespace CategoryTheory open Category -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ v₄ v₅ v₆ u₁ u₂ u₃ u₄ u₅ u₆ variable {A : Type u₁} [Category.{v₁} A] variable {B : Type u₂} [Category.{v₂} B] variable {T : Type u₃} [Category.{v₃} T] variable {A' : Type u₄} [Category.{v₄} A'] variable {B' : Type u₅} [Category.{v₅} B'] variable {T' : Type u₆} [Category.{v₆} T'] /-- The objects of the comma category are triples of an object `left : A`, an object `right : B` and a morphism `hom : L.obj left ⟶ R.obj right`. -/ structure Comma (L : A ⥤ T) (R : B ⥤ T) : Type max u₁ u₂ v₃ where /-- The left subobject -/ left : A /-- The right subobject -/ right : B /-- A morphism from `L.obj left` to `R.obj right` -/ hom : L.obj left ⟶ R.obj right -- Satisfying the inhabited linter instance Comma.inhabited [Inhabited T] : Inhabited (Comma (𝟭 T) (𝟭 T)) where default := { left := default right := default hom := 𝟙 default } variable {L : A ⥤ T} {R : B ⥤ T} /-- A morphism between two objects in the comma category is a commutative square connecting the morphisms coming from the two objects using morphisms in the image of the functors `L` and `R`. -/ @[ext] structure CommaMorphism (X Y : Comma L R) where /-- Morphism on left objects -/ left : X.left ⟶ Y.left /-- Morphism on right objects -/ right : X.right ⟶ Y.right w : L.map left ≫ Y.hom = X.hom ≫ R.map right := by cat_disch -- Satisfying the inhabited linter instance CommaMorphism.inhabited [Inhabited (Comma L R)] : Inhabited (CommaMorphism (default : Comma L R) default) := ⟨{ left := 𝟙 _, right := 𝟙 _}⟩ attribute [reassoc (attr := simp)] CommaMorphism.w instance commaCategory : Category (Comma L R) where Hom X Y := CommaMorphism X Y id X := { left := 𝟙 X.left right := 𝟙 X.right } comp f g := { left := f.left ≫ g.left right := f.right ≫ g.right } namespace Comma section variable {X Y Z : Comma L R} {f : X ⟶ Y} {g : Y ⟶ Z} @[ext] lemma hom_ext (f g : X ⟶ Y) (h₁ : f.left = g.left) (h₂ : f.right = g.right) : f = g := CommaMorphism.ext h₁ h₂ @[simp] theorem id_left : (𝟙 X : CommaMorphism X X).left = 𝟙 X.left := rfl @[simp] theorem id_right : (𝟙 X : CommaMorphism X X).right = 𝟙 X.right := rfl @[simp] theorem comp_left : (f ≫ g).left = f.left ≫ g.left := rfl @[simp] theorem comp_right : (f ≫ g).right = f.right ≫ g.right := rfl end variable (L) (R) /-- The functor sending an object `X` in the comma category to `X.left`. -/ @[simps] def fst : Comma L R ⥤ A where obj X := X.left map f := f.left /-- The functor sending an object `X` in the comma category to `X.right`. -/ @[simps] def snd : Comma L R ⥤ B where obj X := X.right map f := f.right /-- We can interpret the commutative square constituting a morphism in the comma category as a natural transformation between the functors `fst ⋙ L` and `snd ⋙ R` from the comma category to `T`, where the components are given by the morphism that constitutes an object of the comma category. -/ @[simps] def natTrans : fst L R ⋙ L ⟶ snd L R ⋙ R where app X := X.hom @[simp] theorem eqToHom_left (X Y : Comma L R) (H : X = Y) : CommaMorphism.left (eqToHom H) = eqToHom (by cases H; rfl) := by cases H rfl @[simp] theorem eqToHom_right (X Y : Comma L R) (H : X = Y) : CommaMorphism.right (eqToHom H) = eqToHom (by cases H; rfl) := by cases H rfl section variable {L R} {X Y : Comma L R} (e : X ⟶ Y) instance [IsIso e] : IsIso e.left := (Comma.fst L R).map_isIso e instance [IsIso e] : IsIso e.right := (Comma.snd L R).map_isIso e @[simp] lemma inv_left [IsIso e] : (inv e).left = inv e.left := by apply IsIso.eq_inv_of_hom_inv_id rw [← Comma.comp_left, IsIso.hom_inv_id, id_left] @[simp] lemma inv_right [IsIso e] : (inv e).right = inv e.right := by apply IsIso.eq_inv_of_hom_inv_id rw [← Comma.comp_right, IsIso.hom_inv_id, id_right] lemma left_hom_inv_right [IsIso e] : L.map (e.left) ≫ Y.hom ≫ R.map (inv e.right) = X.hom := by simp lemma inv_left_hom_right [IsIso e] : L.map (inv e.left) ≫ X.hom ≫ R.map e.right = Y.hom := by simp end section variable {L₁ L₂ L₃ : A ⥤ T} {R₁ R₂ R₃ : B ⥤ T} /-- Extract the isomorphism between the left objects from an isomorphism in the comma category. -/ @[simps!] def leftIso {X Y : Comma L₁ R₁} (α : X ≅ Y) : X.left ≅ Y.left := (fst L₁ R₁).mapIso α /-- Extract the isomorphism between the right objects from an isomorphism in the comma category. -/ @[simps!] def rightIso {X Y : Comma L₁ R₁} (α : X ≅ Y) : X.right ≅ Y.right := (snd L₁ R₁).mapIso α /-- Construct an isomorphism in the comma category given isomorphisms of the objects whose forward directions give a commutative square. -/ @[simps] def isoMk {X Y : Comma L₁ R₁} (l : X.left ≅ Y.left) (r : X.right ≅ Y.right) (h : L₁.map l.hom ≫ Y.hom = X.hom ≫ R₁.map r.hom := by cat_disch) : X ≅ Y where hom := { left := l.hom right := r.hom w := h } inv := { left := l.inv right := r.inv w := by rw [← L₁.mapIso_inv l, Iso.inv_comp_eq, L₁.mapIso_hom, ← Category.assoc, h, Category.assoc, ← R₁.map_comp] simp } section variable {L R} variable {L' : A' ⥤ T'} {R' : B' ⥤ T'} {F₁ : A ⥤ A'} {F₂ : B ⥤ B'} {F : T ⥤ T'} (α : F₁ ⋙ L' ⟶ L ⋙ F) (β : R ⋙ F ⟶ F₂ ⋙ R') /-- The functor `Comma L R ⥤ Comma L' R'` induced by three functors `F₁`, `F₂`, `F` and two natural transformations `F₁ ⋙ L' ⟶ L ⋙ F` and `R ⋙ F ⟶ F₂ ⋙ R'`. -/ @[simps] def map : Comma L R ⥤ Comma L' R' where obj X := { left := F₁.obj X.left right := F₂.obj X.right hom := α.app X.left ≫ F.map X.hom ≫ β.app X.right } map {X Y} φ := { left := F₁.map φ.left right := F₂.map φ.right w := by dsimp rw [assoc, assoc, ← Functor.comp_map, α.naturality_assoc, ← Functor.comp_map, ← β.naturality] dsimp rw [← F.map_comp_assoc, ← F.map_comp_assoc, φ.w] } instance faithful_map [F₁.Faithful] [F₂.Faithful] : (map α β).Faithful where map_injective {X Y} f g h := by ext · exact F₁.map_injective (congr_arg CommaMorphism.left h) · exact F₂.map_injective (congr_arg CommaMorphism.right h) instance full_map [F.Faithful] [F₁.Full] [F₂.Full] [IsIso α] [IsIso β] : (map α β).Full where map_surjective {X Y} φ := ⟨{left := F₁.preimage φ.left right := F₂.preimage φ.right w := F.map_injective (by rw [← cancel_mono (β.app _), ← cancel_epi (α.app _), F.map_comp, F.map_comp, assoc, assoc] erw [← α.naturality_assoc, β.naturality] dsimp rw [F₁.map_preimage, F₂.map_preimage] simpa using φ.w) }, by cat_disch⟩ instance essSurj_map [F₁.EssSurj] [F₂.EssSurj] [F.Full] [IsIso α] [IsIso β] : (map α β).EssSurj where mem_essImage X := ⟨{left := F₁.objPreimage X.left right := F₂.objPreimage X.right hom := F.preimage ((inv α).app _ ≫ L'.map (F₁.objObjPreimageIso X.left).hom ≫ X.hom ≫ R'.map (F₂.objObjPreimageIso X.right).inv ≫ (inv β).app _) }, ⟨isoMk (F₁.objObjPreimageIso X.left) (F₂.objObjPreimageIso X.right) (by dsimp simp only [NatIso.isIso_inv_app, Functor.comp_obj, Functor.map_preimage, assoc, IsIso.inv_hom_id, comp_id, IsIso.hom_inv_id_assoc] rw [← R'.map_comp, Iso.inv_hom_id, R'.map_id, comp_id])⟩⟩ noncomputable instance isEquivalenceMap [F₁.IsEquivalence] [F₂.IsEquivalence] [F.Faithful] [F.Full] [IsIso α] [IsIso β] : (map α β).IsEquivalence where /-- The equality between `map α β ⋙ fst L' R'` and `fst L R ⋙ F₁`, where `α : F₁ ⋙ L' ⟶ L ⋙ F`. -/ @[simp] theorem map_fst : map α β ⋙ fst L' R' = fst L R ⋙ F₁ := rfl /-- The isomorphism between `map α β ⋙ fst L' R'` and `fst L R ⋙ F₁`, where `α : F₁ ⋙ L' ⟶ L ⋙ F`. -/ @[simps!] def mapFst : map α β ⋙ fst L' R' ≅ fst L R ⋙ F₁ := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) /-- The equality between `map α β ⋙ snd L' R'` and `snd L R ⋙ F₂`, where `β : R ⋙ F ⟶ F₂ ⋙ R'`. -/ @[simp] theorem map_snd : map α β ⋙ snd L' R' = snd L R ⋙ F₂ := rfl /-- The isomorphism between `map α β ⋙ snd L' R'` and `snd L R ⋙ F₂`, where `β : R ⋙ F ⟶ F₂ ⋙ R'`. -/ @[simps!] def mapSnd : map α β ⋙ snd L' R' ≅ snd L R ⋙ F₂ := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) end /-- A natural transformation `L₁ ⟶ L₂` induces a functor `Comma L₂ R ⥤ Comma L₁ R`. -/ @[simps] def mapLeft (l : L₁ ⟶ L₂) : Comma L₂ R ⥤ Comma L₁ R where obj X := { left := X.left right := X.right hom := l.app X.left ≫ X.hom } map f := { left := f.left right := f.right } /-- The functor `Comma L R ⥤ Comma L R` induced by the identity natural transformation on `L` is naturally isomorphic to the identity functor. -/ @[simps!] def mapLeftId : mapLeft R (𝟙 L) ≅ 𝟭 _ := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) /-- The functor `Comma L₁ R ⥤ Comma L₃ R` induced by the composition of two natural transformations `l : L₁ ⟶ L₂` and `l' : L₂ ⟶ L₃` is naturally isomorphic to the composition of the two functors induced by these natural transformations. -/ @[simps!] def mapLeftComp (l : L₁ ⟶ L₂) (l' : L₂ ⟶ L₃) : mapLeft R (l ≫ l') ≅ mapLeft R l' ⋙ mapLeft R l := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) /-- Two equal natural transformations `L₁ ⟶ L₂` yield naturally isomorphic functors `Comma L₁ R ⥤ Comma L₂ R`. -/ @[simps!] def mapLeftEq (l l' : L₁ ⟶ L₂) (h : l = l') : mapLeft R l ≅ mapLeft R l' := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) /-- A natural isomorphism `L₁ ≅ L₂` induces an equivalence of categories `Comma L₁ R ≌ Comma L₂ R`. -/ @[simps!] def mapLeftIso (i : L₁ ≅ L₂) : Comma L₁ R ≌ Comma L₂ R where functor := mapLeft _ i.inv inverse := mapLeft _ i.hom unitIso := (mapLeftId _ _).symm ≪≫ mapLeftEq _ _ _ i.hom_inv_id.symm ≪≫ mapLeftComp _ _ _ counitIso := (mapLeftComp _ _ _).symm ≪≫ mapLeftEq _ _ _ i.inv_hom_id ≪≫ mapLeftId _ _ /-- A natural transformation `R₁ ⟶ R₂` induces a functor `Comma L R₁ ⥤ Comma L R₂`. -/ @[simps] def mapRight (r : R₁ ⟶ R₂) : Comma L R₁ ⥤ Comma L R₂ where obj X := { left := X.left right := X.right hom := X.hom ≫ r.app X.right } map f := { left := f.left right := f.right } /-- The functor `Comma L R ⥤ Comma L R` induced by the identity natural transformation on `R` is naturally isomorphic to the identity functor. -/ @[simps!] def mapRightId : mapRight L (𝟙 R) ≅ 𝟭 _ := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) /-- The functor `Comma L R₁ ⥤ Comma L R₃` induced by the composition of the natural transformations `r : R₁ ⟶ R₂` and `r' : R₂ ⟶ R₃` is naturally isomorphic to the composition of the functors induced by these natural transformations. -/ @[simps!] def mapRightComp (r : R₁ ⟶ R₂) (r' : R₂ ⟶ R₃) : mapRight L (r ≫ r') ≅ mapRight L r ⋙ mapRight L r' := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) /-- Two equal natural transformations `R₁ ⟶ R₂` yield naturally isomorphic functors `Comma L R₁ ⥤ Comma L R₂`. -/ @[simps!] def mapRightEq (r r' : R₁ ⟶ R₂) (h : r = r') : mapRight L r ≅ mapRight L r' := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) /-- A natural isomorphism `R₁ ≅ R₂` induces an equivalence of categories `Comma L R₁ ≌ Comma L R₂`. -/ @[simps!] def mapRightIso (i : R₁ ≅ R₂) : Comma L R₁ ≌ Comma L R₂ where functor := mapRight _ i.hom inverse := mapRight _ i.inv unitIso := (mapRightId _ _).symm ≪≫ mapRightEq _ _ _ i.hom_inv_id.symm ≪≫ mapRightComp _ _ _ counitIso := (mapRightComp _ _ _).symm ≪≫ mapRightEq _ _ _ i.inv_hom_id ≪≫ mapRightId _ _ end section variable {C : Type u₄} [Category.{v₄} C] /-- The functor `(F ⋙ L, R) ⥤ (L, R)` -/ @[simps] def preLeft (F : C ⥤ A) (L : A ⥤ T) (R : B ⥤ T) : Comma (F ⋙ L) R ⥤ Comma L R where obj X := { left := F.obj X.left right := X.right hom := X.hom } map f := { left := F.map f.left right := f.right w := by simpa using f.w } /-- `Comma.preLeft` is a particular case of `Comma.map`, but with better definitional properties. -/ def preLeftIso (F : C ⥤ A) (L : A ⥤ T) (R : B ⥤ T) : preLeft F L R ≅ map (F ⋙ L).rightUnitor.inv (R.rightUnitor.hom ≫ R.leftUnitor.inv) := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) instance (F : C ⥤ A) (L : A ⥤ T) (R : B ⥤ T) [F.Faithful] : (preLeft F L R).Faithful := Functor.Faithful.of_iso (preLeftIso F L R).symm instance (F : C ⥤ A) (L : A ⥤ T) (R : B ⥤ T) [F.Full] : (preLeft F L R).Full := Functor.Full.of_iso (preLeftIso F L R).symm instance (F : C ⥤ A) (L : A ⥤ T) (R : B ⥤ T) [F.EssSurj] : (preLeft F L R).EssSurj := Functor.essSurj_of_iso (preLeftIso F L R).symm /-- If `F` is an equivalence, then so is `preLeft F L R`. -/ instance isEquivalence_preLeft (F : C ⥤ A) (L : A ⥤ T) (R : B ⥤ T) [F.IsEquivalence] : (preLeft F L R).IsEquivalence where /-- The functor `(L, F ⋙ R) ⥤ (L, R)` -/ @[simps] def preRight (L : A ⥤ T) (F : C ⥤ B) (R : B ⥤ T) : Comma L (F ⋙ R) ⥤ Comma L R where obj X := { left := X.left right := F.obj X.right hom := X.hom } map f := { left := f.left right := F.map f.right } /-- `Comma.preRight` is a particular case of `Comma.map`, but with better definitional properties. -/ def preRightIso (L : A ⥤ T) (F : C ⥤ B) (R : B ⥤ T) : preRight L F R ≅ map (L.leftUnitor.hom ≫ L.rightUnitor.inv) (F ⋙ R).rightUnitor.hom := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) instance (L : A ⥤ T) (F : C ⥤ B) (R : B ⥤ T) [F.Faithful] : (preRight L F R).Faithful := Functor.Faithful.of_iso (preRightIso L F R).symm instance (L : A ⥤ T) (F : C ⥤ B) (R : B ⥤ T) [F.Full] : (preRight L F R).Full := Functor.Full.of_iso (preRightIso L F R).symm instance (L : A ⥤ T) (F : C ⥤ B) (R : B ⥤ T) [F.EssSurj] : (preRight L F R).EssSurj := Functor.essSurj_of_iso (preRightIso L F R).symm /-- If `F` is an equivalence, then so is `preRight L F R`. -/ instance isEquivalence_preRight (L : A ⥤ T) (F : C ⥤ B) (R : B ⥤ T) [F.IsEquivalence] : (preRight L F R).IsEquivalence where /-- The functor `(L, R) ⥤ (L ⋙ F, R ⋙ F)` -/ @[simps] def post (L : A ⥤ T) (R : B ⥤ T) (F : T ⥤ C) : Comma L R ⥤ Comma (L ⋙ F) (R ⋙ F) where obj X := { left := X.left right := X.right hom := F.map X.hom } map f := { left := f.left right := f.right w := by simp only [Functor.comp_map, ← F.map_comp, f.w] } /-- `Comma.post` is a particular case of `Comma.map`, but with better definitional properties. -/ def postIso (L : A ⥤ T) (R : B ⥤ T) (F : T ⥤ C) : post L R F ≅ map (F₁ := 𝟭 _) (F₂ := 𝟭 _) (L ⋙ F).leftUnitor.hom (R ⋙ F).leftUnitor.inv := NatIso.ofComponents (fun X => isoMk (Iso.refl _) (Iso.refl _)) instance (L : A ⥤ T) (R : B ⥤ T) (F : T ⥤ C) : (post L R F).Faithful := Functor.Faithful.of_iso (postIso L R F).symm instance (L : A ⥤ T) (R : B ⥤ T) (F : T ⥤ C) [F.Faithful] : (post L R F).Full := Functor.Full.of_iso (postIso L R F).symm instance (L : A ⥤ T) (R : B ⥤ T) (F : T ⥤ C) [F.Full] : (post L R F).EssSurj := Functor.essSurj_of_iso (postIso L R F).symm /-- If `F` is an equivalence, then so is `post L R F`. -/ instance isEquivalence_post (L : A ⥤ T) (R : B ⥤ T) (F : T ⥤ C) [F.IsEquivalence] : (post L R F).IsEquivalence where /-- The canonical functor from the product of two categories to the comma category of their respective functors into `Discrete PUnit`. -/ @[simps] def fromProd (L : A ⥤ Discrete PUnit) (R : B ⥤ Discrete PUnit) : A × B ⥤ Comma L R where obj X := { left := X.1 right := X.2 hom := Discrete.eqToHom rfl } map {X} {Y} f := { left := f.1 right := f.2 } /-- Taking the comma category of two functors into `Discrete PUnit` results in something is equivalent to their product. -/ @[simps!] def equivProd (L : A ⥤ Discrete PUnit) (R : B ⥤ Discrete PUnit) : Comma L R ≌ A × B where functor := (fst L R).prod' (snd L R) inverse := fromProd L R unitIso := Iso.refl _ counitIso := Iso.refl _ /-- Taking the comma category of a functor into `A ⥤ Discrete PUnit` and the identity `Discrete PUnit ⥤ Discrete PUnit` results in a category equivalent to `A`. -/ @[simps!] def toPUnitIdEquiv (L : A ⥤ Discrete PUnit) (R : Discrete PUnit ⥤ Discrete PUnit) : Comma L R ≌ A := (equivProd L _).trans (prod.rightUnitorEquivalence A) @[simp] theorem toPUnitIdEquiv_functor_iso {L : A ⥤ Discrete PUnit} {R : Discrete PUnit ⥤ Discrete PUnit} : (toPUnitIdEquiv L R).functor = fst L R := rfl /-- Taking the comma category of the identity `Discrete PUnit ⥤ Discrete PUnit` and a functor `B ⥤ Discrete PUnit` results in a category equivalent to `B`. -/ @[simps!] def toIdPUnitEquiv (L : Discrete PUnit ⥤ Discrete PUnit) (R : B ⥤ Discrete PUnit) : Comma L R ≌ B := (equivProd _ R).trans (prod.leftUnitorEquivalence B) @[simp] theorem toIdPUnitEquiv_functor_iso {L : Discrete PUnit ⥤ Discrete PUnit} {R : B ⥤ Discrete PUnit} : (toIdPUnitEquiv L R).functor = snd L R := rfl end section Opposite open Opposite /-- The canonical functor from `Comma L R` to `(Comma R.op L.op)ᵒᵖ`. -/ @[simps] def opFunctor : Comma L R ⥤ (Comma R.op L.op)ᵒᵖ where obj X := ⟨op X.right, op X.left, op X.hom⟩ map f := ⟨op f.right, op f.left, Quiver.Hom.unop_inj (by simp)⟩ /-- Composing the `leftOp` of `opFunctor L R` with `fst L.op R.op` is naturally isomorphic to `snd L R`. -/ @[simps!] def opFunctorCompFst : (opFunctor L R).leftOp ⋙ fst _ _ ≅ (snd _ _).op := Iso.refl _ /-- Composing the `leftOp` of `opFunctor L R` with `snd L.op R.op` is naturally isomorphic to `fst L R`. -/ @[simps!] def opFunctorCompSnd : (opFunctor L R).leftOp ⋙ snd _ _ ≅ (fst _ _).op := Iso.refl _ /-- The canonical functor from `Comma L.op R.op` to `(Comma R L)ᵒᵖ`. -/ @[simps] def unopFunctor : Comma L.op R.op ⥤ (Comma R L)ᵒᵖ where obj X := ⟨X.right.unop, X.left.unop, X.hom.unop⟩ map f := ⟨f.right.unop, f.left.unop, Quiver.Hom.op_inj (by simpa using f.w.symm)⟩ /-- Composing `unopFunctor L R` with `(fst L R).op` is isomorphic to `snd L.op R.op`. -/ @[simps!] def unopFunctorCompFst : unopFunctor L R ⋙ (fst _ _).op ≅ snd _ _ := Iso.refl _ /-- Composing `unopFunctor L R` with `(snd L R).op` is isomorphic to `fst L.op R.op`. -/ @[simps!] def unopFunctorCompSnd : unopFunctor L R ⋙ (snd _ _).op ≅ fst _ _ := Iso.refl _ /-- The canonical equivalence between `Comma L R` and `(Comma R.op L.op)ᵒᵖ`. -/ @[simps] def opEquiv : Comma L R ≌ (Comma R.op L.op)ᵒᵖ where functor := opFunctor L R inverse := (unopFunctor R L).leftOp unitIso := NatIso.ofComponents (fun X => Iso.refl _) counitIso := NatIso.ofComponents (fun X => Iso.refl _) end Opposite end Comma end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Arrow.lean
import Mathlib.CategoryTheory.Comma.Basic /-! # The category of arrows The category of arrows, with morphisms commutative squares. We set this up as a specialization of the comma category `Comma L R`, where `L` and `R` are both the identity functor. ## Tags comma, arrow -/ namespace CategoryTheory universe v u -- morphism levels before object levels. See note [category theory universes]. variable {T : Type u} [Category.{v} T] section variable (T) /-- The arrow category of `T` has as objects all morphisms in `T` and as morphisms commutative squares in `T`. -/ def Arrow := Comma.{v, v, v} (𝟭 T) (𝟭 T) deriving Category, [Inhabited T] → Inhabited _ end namespace Arrow @[ext] lemma hom_ext {X Y : Arrow T} (f g : X ⟶ Y) (h₁ : f.left = g.left) (h₂ : f.right = g.right) : f = g := CommaMorphism.ext h₁ h₂ @[simp] theorem id_left (f : Arrow T) : CommaMorphism.left (𝟙 f) = 𝟙 f.left := rfl @[simp] theorem id_right (f : Arrow T) : CommaMorphism.right (𝟙 f) = 𝟙 f.right := rfl @[simp, reassoc] theorem comp_left {X Y Z : Arrow T} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).left = f.left ≫ g.left := rfl @[simp, reassoc] theorem comp_right {X Y Z : Arrow T} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).right = f.right ≫ g.right := rfl /-- An object in the arrow category is simply a morphism in `T`. -/ @[simps] def mk {X Y : T} (f : X ⟶ Y) : Arrow T where left := X right := Y hom := f @[simp] theorem mk_eq (f : Arrow T) : Arrow.mk f.hom = f := by cases f rfl theorem mk_injective (A B : T) : Function.Injective (Arrow.mk : (A ⟶ B) → Arrow T) := fun f g h => by cases h rfl theorem mk_inj (A B : T) {f g : A ⟶ B} : Arrow.mk f = Arrow.mk g ↔ f = g := (mk_injective A B).eq_iff instance {X Y : T} : CoeOut (X ⟶ Y) (Arrow T) where coe := mk lemma mk_eq_mk_iff {X Y X' Y' : T} (f : X ⟶ Y) (f' : X' ⟶ Y') : Arrow.mk f = Arrow.mk f' ↔ ∃ (hX : X = X') (hY : Y = Y'), f = eqToHom hX ≫ f' ≫ eqToHom hY.symm := by constructor · intro h refine ⟨congr_arg Comma.left h, congr_arg Comma.right h, ?_⟩ have := (eqToIso h).hom.w dsimp at this rw [Comma.eqToHom_left, Comma.eqToHom_right] at this rw [reassoc_of% this, eqToHom_trans, eqToHom_refl, Category.comp_id] · rintro ⟨rfl, rfl, h⟩ simp only [eqToHom_refl, Category.comp_id, Category.id_comp] at h rw [h] lemma ext {f g : Arrow T} (h₁ : f.left = g.left) (h₂ : f.right = g.right) (h₃ : f.hom = eqToHom h₁ ≫ g.hom ≫ eqToHom h₂.symm) : f = g := (mk_eq_mk_iff _ _).2 (by simp_all) @[simp] lemma arrow_mk_comp_eqToHom {X Y Y' : T} (f : X ⟶ Y) (h : Y = Y') : Arrow.mk (f ≫ eqToHom h) = Arrow.mk f := ext rfl h.symm (by simp) @[simp] lemma arrow_mk_eqToHom_comp {X' X Y : T} (f : X ⟶ Y) (h : X' = X) : Arrow.mk (eqToHom h ≫ f) = Arrow.mk f := ext h rfl (by simp) /-- A morphism in the arrow category is a commutative square connecting two objects of the arrow category. -/ @[simps] def homMk {f g : Arrow T} (u : f.left ⟶ g.left) (v : f.right ⟶ g.right) (w : u ≫ g.hom = f.hom ≫ v := by cat_disch) : f ⟶ g where left := u right := v w := w /-- We can also build a morphism in the arrow category out of any commutative square in `T`. -/ @[simps] def homMk' {X Y : T} {f : X ⟶ Y} {P Q : T} {g : P ⟶ Q} (u : X ⟶ P) (v : Y ⟶ Q) (w : u ≫ g = f ≫ v := by cat_disch) : Arrow.mk f ⟶ Arrow.mk g where left := u right := v w := w -- `w_mk_left` is not needed, as it is a consequence of `w` and `mk_hom`. @[reassoc (attr := simp)] theorem w_mk_right {f : Arrow T} {X Y : T} {g : X ⟶ Y} (sq : f ⟶ mk g) : sq.left ≫ g = f.hom ≫ sq.right := sq.w @[reassoc] theorem w {f g : Arrow T} (sq : f ⟶ g) : sq.left ≫ g.hom = f.hom ≫ sq.right := by simp theorem isIso_of_isIso_left_of_isIso_right {f g : Arrow T} (ff : f ⟶ g) [IsIso ff.left] [IsIso ff.right] : IsIso ff where out := by let inverse : g ⟶ f := ⟨inv ff.left, inv ff.right, (by simp)⟩ apply Exists.intro inverse cat_disch /-- Create an isomorphism between arrows, by providing isomorphisms between the domains and codomains, and a proof that the square commutes. -/ @[simps!] def isoMk {f g : Arrow T} (l : f.left ≅ g.left) (r : f.right ≅ g.right) (h : l.hom ≫ g.hom = f.hom ≫ r.hom := by cat_disch) : f ≅ g := Comma.isoMk l r h /-- A variant of `Arrow.isoMk` that creates an iso between two `Arrow.mk`s with a better type signature. -/ abbrev isoMk' {W X Y Z : T} (f : W ⟶ X) (g : Y ⟶ Z) (e₁ : W ≅ Y) (e₂ : X ≅ Z) (h : e₁.hom ≫ g = f ≫ e₂.hom := by cat_disch) : Arrow.mk f ≅ Arrow.mk g := Arrow.isoMk e₁ e₂ h theorem hom.congr_left {f g : Arrow T} {φ₁ φ₂ : f ⟶ g} (h : φ₁ = φ₂) : φ₁.left = φ₂.left := by rw [h] theorem hom.congr_right {f g : Arrow T} {φ₁ φ₂ : f ⟶ g} (h : φ₁ = φ₂) : φ₁.right = φ₂.right := by simp [h] theorem iso_w {f g : Arrow T} (e : f ≅ g) : g.hom = e.inv.left ≫ f.hom ≫ e.hom.right := by have eq := Arrow.hom.congr_right e.inv_hom_id rw [Arrow.comp_right, Arrow.id_right] at eq rw [Arrow.w_assoc, eq, Category.comp_id] theorem iso_w' {W X Y Z : T} {f : W ⟶ X} {g : Y ⟶ Z} (e : Arrow.mk f ≅ Arrow.mk g) : g = e.inv.left ≫ f ≫ e.hom.right := iso_w e section variable {f g : Arrow T} (sq : f ⟶ g) instance isIso_left [IsIso sq] : IsIso sq.left where out := by apply Exists.intro (inv sq).left simp only [← Comma.comp_left, IsIso.hom_inv_id, IsIso.inv_hom_id] simp instance isIso_right [IsIso sq] : IsIso sq.right where out := by apply Exists.intro (inv sq).right simp only [← Comma.comp_right, IsIso.hom_inv_id, IsIso.inv_hom_id] simp lemma isIso_of_isIso {X Y : T} {f : X ⟶ Y} {g : Arrow T} (sq : mk f ⟶ g) [IsIso sq] [IsIso f] : IsIso g.hom := by rw [iso_w' (asIso sq)] infer_instance lemma isIso_hom_iff_isIso_hom_of_isIso {f g : Arrow T} (sq : f ⟶ g) [IsIso sq] : IsIso f.hom ↔ IsIso g.hom := ⟨fun _ => isIso_of_isIso sq, fun _ => isIso_of_isIso (inv sq)⟩ lemma isIso_iff_isIso_of_isIso {W X Y Z : T} {f : W ⟶ X} {g : Y ⟶ Z} (sq : mk f ⟶ mk g) [IsIso sq] : IsIso f ↔ IsIso g := isIso_hom_iff_isIso_hom_of_isIso sq lemma isIso_hom_iff_isIso_of_isIso {Y Z : T} {f : Arrow T} {g : Y ⟶ Z} (sq : f ⟶ mk g) [IsIso sq] : IsIso f.hom ↔ IsIso g := isIso_hom_iff_isIso_hom_of_isIso sq @[simp] theorem inv_left [IsIso sq] : (inv sq).left = inv sq.left := IsIso.eq_inv_of_hom_inv_id <| by rw [← Comma.comp_left, IsIso.hom_inv_id, id_left] @[simp] theorem inv_right [IsIso sq] : (inv sq).right = inv sq.right := IsIso.eq_inv_of_hom_inv_id <| by rw [← Comma.comp_right, IsIso.hom_inv_id, id_right] theorem left_hom_inv_right [IsIso sq] : sq.left ≫ g.hom ≫ inv sq.right = f.hom := by simp only [← Category.assoc, IsIso.comp_inv_eq, w] theorem inv_left_hom_right [IsIso sq] : inv sq.left ≫ f.hom ≫ sq.right = g.hom := by simp only [w, IsIso.inv_comp_eq] instance mono_left [Mono sq] : Mono sq.left where right_cancellation {Z} φ ψ h := by let aux : (Z ⟶ f.left) → (Arrow.mk (𝟙 Z) ⟶ f) := fun φ => { left := φ right := φ ≫ f.hom } have : ∀ g, (aux g).right = g ≫ f.hom := fun g => by dsimp change (aux φ).left = (aux ψ).left congr 1 rw [← cancel_mono sq] apply CommaMorphism.ext · exact h · rw [Comma.comp_right, Comma.comp_right, this, this, Category.assoc, Category.assoc] rw [← Arrow.w] simp only [← Category.assoc, h] instance epi_right [Epi sq] : Epi sq.right where left_cancellation {Z} φ ψ h := by let aux : (g.right ⟶ Z) → (g ⟶ Arrow.mk (𝟙 Z)) := fun φ => { right := φ left := g.hom ≫ φ } change (aux φ).right = (aux ψ).right congr 1 rw [← cancel_epi sq] apply CommaMorphism.ext · rw [Comma.comp_left, Comma.comp_left, Arrow.w_assoc, Arrow.w_assoc, h] · exact h @[reassoc (attr := simp)] lemma hom_inv_id_left (e : f ≅ g) : e.hom.left ≫ e.inv.left = 𝟙 _ := by rw [← comp_left, e.hom_inv_id, id_left] @[reassoc (attr := simp)] lemma inv_hom_id_left (e : f ≅ g) : e.inv.left ≫ e.hom.left = 𝟙 _ := by rw [← comp_left, e.inv_hom_id, id_left] @[reassoc (attr := simp)] lemma hom_inv_id_right (e : f ≅ g) : e.hom.right ≫ e.inv.right = 𝟙 _ := by rw [← comp_right, e.hom_inv_id, id_right] @[reassoc (attr := simp)] lemma inv_hom_id_right (e : f ≅ g) : e.inv.right ≫ e.hom.right = 𝟙 _ := by rw [← comp_right, e.inv_hom_id, id_right] end /-- Given a square from an arrow `i` to an isomorphism `p`, express the source part of `sq` in terms of the inverse of `p`. -/ @[simp] theorem square_to_iso_invert (i : Arrow T) {X Y : T} (p : X ≅ Y) (sq : i ⟶ Arrow.mk p.hom) : i.hom ≫ sq.right ≫ p.inv = sq.left := by simpa only [Category.assoc] using (Iso.comp_inv_eq p).mpr (Arrow.w_mk_right sq).symm /-- Given a square from an isomorphism `i` to an arrow `p`, express the target part of `sq` in terms of the inverse of `i`. -/ theorem square_from_iso_invert {X Y : T} (i : X ≅ Y) (p : Arrow T) (sq : Arrow.mk i.hom ⟶ p) : i.inv ≫ sq.left ≫ p.hom = sq.right := by simp only [Iso.inv_hom_id_assoc, Arrow.w, Arrow.mk_hom] variable {C : Type u} [Category.{v} C] /-- A helper construction: given a square between `i` and `f ≫ g`, produce a square between `i` and `g`, whose top leg uses `f`: ``` A → X ↓f ↓i Y --> A → Y ↓g ↓i ↓g B → Z B → Z ``` -/ @[simps] def squareToSnd {X Y Z : C} {i : Arrow C} {f : X ⟶ Y} {g : Y ⟶ Z} (sq : i ⟶ Arrow.mk (f ≫ g)) : i ⟶ Arrow.mk g where left := sq.left ≫ f right := sq.right /-- The functor sending an arrow to its source. -/ @[simps!] def leftFunc : Arrow C ⥤ C := Comma.fst _ _ /-- The functor sending an arrow to its target. -/ @[simps!] def rightFunc : Arrow C ⥤ C := Comma.snd _ _ /-- The natural transformation from `leftFunc` to `rightFunc`, given by the arrow itself. -/ @[simps] def leftToRight : (leftFunc : Arrow C ⥤ C) ⟶ rightFunc where app f := f.hom end Arrow namespace Functor universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] /-- A functor `C ⥤ D` induces a functor between the corresponding arrow categories. -/ @[simps] def mapArrow (F : C ⥤ D) : Arrow C ⥤ Arrow D where obj a := Arrow.mk (F.map a.hom) map f := { left := F.map f.left right := F.map f.right w := by let w := f.w simp only [id_map] at w dsimp simp only [← F.map_comp, w] } variable (C D) /-- The functor `(C ⥤ D) ⥤ (Arrow C ⥤ Arrow D)` which sends a functor `F : C ⥤ D` to `F.mapArrow`. -/ @[simps] def mapArrowFunctor : (C ⥤ D) ⥤ (Arrow C ⥤ Arrow D) where obj F := F.mapArrow map τ := { app := fun f => { left := τ.app _ right := τ.app _ } } variable {C D} /-- The equivalence of categories `Arrow C ≌ Arrow D` induced by an equivalence `C ≌ D`. -/ def mapArrowEquivalence (e : C ≌ D) : Arrow C ≌ Arrow D where functor := e.functor.mapArrow inverse := e.inverse.mapArrow unitIso := Functor.mapIso (mapArrowFunctor C C) e.unitIso counitIso := Functor.mapIso (mapArrowFunctor D D) e.counitIso instance isEquivalence_mapArrow (F : C ⥤ D) [IsEquivalence F] : IsEquivalence F.mapArrow := (mapArrowEquivalence (asEquivalence F)).isEquivalence_functor end Functor variable {C D : Type*} [Category C] [Category D] /-- The images of `f : Arrow C` by two isomorphic functors `F : C ⥤ D` are isomorphic arrows in `D`. -/ def Arrow.isoOfNatIso {F G : C ⥤ D} (e : F ≅ G) (f : Arrow C) : F.mapArrow.obj f ≅ G.mapArrow.obj f := Arrow.isoMk (e.app f.left) (e.app f.right) variable (T) /-- `Arrow T` is equivalent to a sigma type. -/ @[simps!] def Arrow.equivSigma : Arrow T ≃ Σ (X Y : T), X ⟶ Y where toFun f := ⟨_, _, f.hom⟩ invFun x := Arrow.mk x.2.2 /-- The equivalence `Arrow (Discrete S) ≃ S`. -/ def Arrow.discreteEquiv (S : Type u) : Arrow (Discrete S) ≃ S where toFun f := f.left.as invFun s := Arrow.mk (𝟙 (Discrete.mk s)) left_inv := by rintro ⟨⟨_⟩, ⟨_⟩, f⟩ obtain rfl := Discrete.eq_of_hom f rfl /-- Extensionality lemma for functors `C ⥤ D` which uses as an assumption that the induced maps `Arrow C → Arrow D` coincide. -/ lemma Arrow.functor_ext {F G : C ⥤ D} (h : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), F.mapArrow.obj (Arrow.mk f) = G.mapArrow.obj (Arrow.mk f)) : F = G := Functor.ext (fun X ↦ congr_arg Comma.left (h (𝟙 X))) (fun X Y f ↦ by have := h f simp only [Functor.mapArrow_obj, mk_eq_mk_iff] at this tauto) end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/StructuredArrow/Final.lean
import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Limits.Final /-! # Finality on Costructured Arrow categories ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Proposition 3.1.8(i) -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory namespace Functor open Limits Functor CostructuredArrow section Small variable {A : Type u₁} [SmallCategory A] {B : Type u₁} [SmallCategory B] variable {T : Type u₁} [SmallCategory T] attribute [local instance] Grothendieck.final_map /-- The version of `final_of_final_costructuredArrowToOver` on small categories used to prove the full statement. -/ private lemma final_of_final_costructuredArrowToOver_small (L : A ⥤ T) (R : B ⥤ T) [Final R] [∀ b : B, Final (CostructuredArrow.toOver L (R.obj b))] : Final L := by rw [final_iff_isIso_colimit_pre] intro G have : ∀ (b : B), Final ((whiskerLeft R (preFunctor L (𝟭 T))).app b) := fun b => inferInstanceAs (Final (CostructuredArrow.toOver L (R.obj b))) let i : colimit (L ⋙ G) ≅ colimit G := calc colimit (L ⋙ G) ≅ colimit <| grothendieckProj L ⋙ L ⋙ G := colimitIsoColimitGrothendieck L (L ⋙ G) _ ≅ colimit <| Grothendieck.pre (functor L) R ⋙ grothendieckProj L ⋙ L ⋙ G := (Final.colimitIso (Grothendieck.pre (functor L) R) (grothendieckProj L ⋙ L ⋙ G)).symm _ ≅ colimit <| Grothendieck.map (whiskerLeft _ (preFunctor L (𝟭 T))) ⋙ grothendieckPrecompFunctorToComma (𝟭 T) R ⋙ Comma.fst (𝟭 T) R ⋙ G := HasColimit.isoOfNatIso (NatIso.ofComponents (fun _ => Iso.refl _)) _ ≅ colimit <| grothendieckPrecompFunctorToComma (𝟭 T) R ⋙ Comma.fst (𝟭 T) R ⋙ G := Final.colimitIso _ _ _ ≅ colimit <| Grothendieck.pre (functor (𝟭 T)) R ⋙ grothendieckProj (𝟭 T) ⋙ G := HasColimit.isoOfNatIso (Iso.refl _) _ ≅ colimit <| grothendieckProj (𝟭 T) ⋙ G := Final.colimitIso _ _ _ ≅ colimit G := (colimitIsoColimitGrothendieck (𝟭 T) G).symm convert Iso.isIso_hom i simp only [Iso.trans_def, comp_obj, grothendieckProj_obj, Grothendieck.pre_obj_base, Grothendieck.pre_obj_fiber, Iso.trans_assoc, Iso.trans_hom, Iso.symm_hom, i] rw [← Iso.inv_comp_eq, Iso.eq_inv_comp] apply colimit.hom_ext (fun _ => by simp) end Small variable {A : Type u₁} [Category.{v₁} A] {B : Type u₂} [Category.{v₂} B] variable {T : Type u₃} [Category.{v₃} T] /-- A functor `L : A ⥤ T` is final if there is a final functor `R : B ⥤ T` such that for all `b : B`, the canonical functor `CostructuredArrow L (R.obj b) ⥤ Over (R.obj b)` is final. -/ theorem final_of_final_costructuredArrowToOver (L : A ⥤ T) (R : B ⥤ T) [Final R] [hB : ∀ b : B, Final (CostructuredArrow.toOver L (R.obj b))] : Final L := by let sA : A ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} A := AsSmall.equiv let sB : B ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} B := AsSmall.equiv let sT : T ≌ AsSmall.{max u₁ u₂ u₃ v₁ v₂ v₃} T := AsSmall.equiv let L' := sA.inverse ⋙ L ⋙ sT.functor let R' := sB.inverse ⋙ R ⋙ sT.functor have (b : _) : (CostructuredArrow.toOver L' (R'.obj b)).Final := by dsimp only [L', R', CostructuredArrow.toOver] at hB ⊢ let x := (sB.inverse ⋙ R ⋙ sT.functor).obj b let F'' : CostructuredArrow (sA.inverse ⋙ L ⋙ sT.functor) x ⥤ CostructuredArrow (𝟭 _) x := map₂ (F := sA.inverse) (G := sT.inverse) (whiskerLeft (sA.inverse ⋙ L) sT.unit) (𝟙 _) ⋙ pre L (𝟭 T) (R.obj _) ⋙ map₂ (F := sT.functor) (G := sT.functor) (𝟙 _) (𝟙 _) apply final_of_natIso (F := F'') have hsT (X) : sT.counitInv.app X = 𝟙 _ := rfl exact NatIso.ofComponents (fun X => CostructuredArrow.isoMk (Iso.refl _) (by simp [F'', hsT])) have := final_of_final_costructuredArrowToOver_small L' R' apply final_of_natIso (F := (sA.functor ⋙ L' ⋙ sT.inverse)) exact (sA.functor.associator (sA.inverse ⋙ L ⋙ sT.functor) sT.inverse).symm ≪≫ ((sA.functor.associator sA.inverse (L ⋙ sT.functor)).symm ≪≫ isoWhiskerRight sA.unitIso.symm _ ≪≫ (L ⋙ sT.functor).leftUnitor).compInverseIso end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/StructuredArrow/Basic.lean
import Mathlib.CategoryTheory.Comma.Basic import Mathlib.CategoryTheory.PUnit import Mathlib.CategoryTheory.Limits.Shapes.IsTerminal import Mathlib.CategoryTheory.Functor.EpiMono /-! # The category of "structured arrows" For `T : C ⥤ D`, a `T`-structured arrow with source `S : D` is just a morphism `S ⟶ T.obj Y`, for some `Y : C`. These form a category with morphisms `g : Y ⟶ Y'` making the obvious diagram commute. We prove that `𝟙 (T.obj Y)` is the initial object in `T`-structured objects with source `T.obj Y`. -/ namespace CategoryTheory -- morphism levels before object levels. See note [category theory universes]. universe v₁ v₂ v₃ v₄ v₅ v₆ u₁ u₂ u₃ u₄ u₅ u₆ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] /-- The category of `T`-structured arrows with domain `S : D` (here `T : C ⥤ D`), has as its objects `D`-morphisms of the form `S ⟶ T Y`, for some `Y : C`, and morphisms `C`-morphisms `Y ⟶ Y'` making the obvious triangle commute. -/ -- We explicitly come from `PUnit.{1}` here to obtain the correct universe for morphisms of -- structured arrows. def StructuredArrow (S : D) (T : C ⥤ D) := Comma (Functor.fromPUnit.{0} S) T /-- See through the type synonym `StructuredArrow S T = Comma _ _`. -/ instance (S : D) (T : C ⥤ D) : Category (StructuredArrow S T) := inferInstanceAs <| Category (Comma _ _) namespace StructuredArrow /-- The obvious projection functor from structured arrows. -/ @[simps!] def proj (S : D) (T : C ⥤ D) : StructuredArrow S T ⥤ C := Comma.snd _ _ variable {S S' S'' : D} {Y Y' Y'' : C} {T T' : C ⥤ D} @[ext] lemma hom_ext {X Y : StructuredArrow S T} (f g : X ⟶ Y) (h : f.right = g.right) : f = g := CommaMorphism.ext (Subsingleton.elim _ _) h @[simp] theorem hom_eq_iff {X Y : StructuredArrow S T} (f g : X ⟶ Y) : f = g ↔ f.right = g.right := ⟨fun h ↦ by rw [h], hom_ext _ _⟩ /-- Construct a structured arrow from a morphism. -/ def mk (f : S ⟶ T.obj Y) : StructuredArrow S T := ⟨⟨⟨⟩⟩, Y, f⟩ @[simp] theorem mk_left (f : S ⟶ T.obj Y) : (mk f).left = ⟨⟨⟩⟩ := rfl @[simp] theorem mk_right (f : S ⟶ T.obj Y) : (mk f).right = Y := rfl @[simp] theorem mk_hom_eq_self (f : S ⟶ T.obj Y) : (mk f).hom = f := rfl @[reassoc (attr := simp)] theorem w {A B : StructuredArrow S T} (f : A ⟶ B) : A.hom ≫ T.map f.right = B.hom := by have := f.w; cat_disch @[simp] theorem comp_right {X Y Z : StructuredArrow S T} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).right = f.right ≫ g.right := rfl @[simp] theorem id_right (X : StructuredArrow S T) : (𝟙 X : X ⟶ X).right = 𝟙 X.right := rfl @[simp] theorem eqToHom_right {X Y : StructuredArrow S T} (h : X = Y) : (eqToHom h).right = eqToHom (by rw [h]) := by subst h simp only [eqToHom_refl, id_right] @[simp] theorem left_eq_id {X Y : StructuredArrow S T} (f : X ⟶ Y) : f.left = 𝟙 X.left := rfl /-- To construct a morphism of structured arrows, we need a morphism of the objects underlying the target, and to check that the triangle commutes. -/ @[simps right] def homMk {f f' : StructuredArrow S T} (g : f.right ⟶ f'.right) (w : f.hom ≫ T.map g = f'.hom := by cat_disch) : f ⟶ f' where left := 𝟙 f.left right := g w := by dsimp simpa using w.symm theorem homMk_surjective {f f' : StructuredArrow S T} (φ : f ⟶ f') : ∃ (ψ : f.right ⟶ f'.right) (hψ : f.hom ≫ T.map ψ = f'.hom), φ = StructuredArrow.homMk ψ hψ := ⟨φ.right, StructuredArrow.w φ, rfl⟩ /-- Given a structured arrow `X ⟶ T(Y)`, and an arrow `Y ⟶ Y'`, we can construct a morphism of structured arrows given by `(X ⟶ T(Y)) ⟶ (X ⟶ T(Y) ⟶ T(Y'))`. -/ @[simps] def homMk' (f : StructuredArrow S T) (g : f.right ⟶ Y') : f ⟶ mk (f.hom ≫ T.map g) where left := 𝟙 _ right := g lemma homMk'_id (f : StructuredArrow S T) : homMk' f (𝟙 f.right) = eqToHom (by cat_disch) := by simp [eqToHom_right] lemma homMk'_mk_id (f : S ⟶ T.obj Y) : homMk' (mk f) (𝟙 Y) = eqToHom (by simp) := homMk'_id _ lemma homMk'_comp (f : StructuredArrow S T) (g : f.right ⟶ Y') (g' : Y' ⟶ Y'') : homMk' f (g ≫ g') = homMk' f g ≫ homMk' (mk (f.hom ≫ T.map g)) g' ≫ eqToHom (by simp) := by simp [eqToHom_right] lemma homMk'_mk_comp (f : S ⟶ T.obj Y) (g : Y ⟶ Y') (g' : Y' ⟶ Y'') : homMk' (mk f) (g ≫ g') = homMk' (mk f) g ≫ homMk' (mk (f ≫ T.map g)) g' ≫ eqToHom (by simp) := homMk'_comp _ _ _ /-- Variant of `homMk'` where both objects are applications of `mk`. -/ @[simps] def mkPostcomp (f : S ⟶ T.obj Y) (g : Y ⟶ Y') : mk f ⟶ mk (f ≫ T.map g) where left := 𝟙 _ right := g lemma mkPostcomp_id (f : S ⟶ T.obj Y) : mkPostcomp f (𝟙 Y) = eqToHom (by simp) := by simp lemma mkPostcomp_comp (f : S ⟶ T.obj Y) (g : Y ⟶ Y') (g' : Y' ⟶ Y'') : mkPostcomp f (g ≫ g') = mkPostcomp f g ≫ mkPostcomp (f ≫ T.map g) g' ≫ eqToHom (by simp) := by simp /-- To construct an isomorphism of structured arrows, we need an isomorphism of the objects underlying the target, and to check that the triangle commutes. -/ @[simps! hom_right inv_right] def isoMk {f f' : StructuredArrow S T} (g : f.right ≅ f'.right) (w : f.hom ≫ T.map g.hom = f'.hom := by cat_disch) : f ≅ f' := Comma.isoMk (eqToIso (by ext)) g (by simpa using w.symm) theorem obj_ext (x y : StructuredArrow S T) (hr : x.right = y.right) (hh : x.hom ≫ T.map (eqToHom hr) = y.hom) : x = y := by cases x cases y cases hr cat_disch theorem ext {A B : StructuredArrow S T} (f g : A ⟶ B) : f.right = g.right → f = g := CommaMorphism.ext (Subsingleton.elim _ _) theorem ext_iff {A B : StructuredArrow S T} (f g : A ⟶ B) : f = g ↔ f.right = g.right := ⟨fun h => h ▸ rfl, ext f g⟩ instance proj_faithful : (proj S T).Faithful where map_injective {_ _} := ext /-- The converse of this is true with additional assumptions, see `mono_iff_mono_right`. -/ theorem mono_of_mono_right {A B : StructuredArrow S T} (f : A ⟶ B) [h : Mono f.right] : Mono f := (proj S T).mono_of_mono_map h theorem epi_of_epi_right {A B : StructuredArrow S T} (f : A ⟶ B) [h : Epi f.right] : Epi f := (proj S T).epi_of_epi_map h instance mono_homMk {A B : StructuredArrow S T} (f : A.right ⟶ B.right) (w) [h : Mono f] : Mono (homMk f w) := (proj S T).mono_of_mono_map h instance epi_homMk {A B : StructuredArrow S T} (f : A.right ⟶ B.right) (w) [h : Epi f] : Epi (homMk f w) := (proj S T).epi_of_epi_map h /-- Eta rule for structured arrows. Prefer `StructuredArrow.eta` for rewriting, since equality of objects tends to cause problems. -/ theorem eq_mk (f : StructuredArrow S T) : f = mk f.hom := rfl /-- Eta rule for structured arrows. -/ @[simps! hom_right inv_right] def eta (f : StructuredArrow S T) : f ≅ mk f.hom := isoMk (Iso.refl _) lemma mk_surjective (f : StructuredArrow S T) : ∃ (Y : C) (g : S ⟶ T.obj Y), f = mk g := ⟨_, _, eq_mk f⟩ /-- A morphism between source objects `S ⟶ S'` contravariantly induces a functor between structured arrows, `StructuredArrow S' T ⥤ StructuredArrow S T`. Ideally this would be described as a 2-functor from `D` (promoted to a 2-category with equations as 2-morphisms) to `Cat`. -/ @[simps!] def map (f : S ⟶ S') : StructuredArrow S' T ⥤ StructuredArrow S T := Comma.mapLeft _ ((Functor.const _).map f) @[simp] theorem map_mk {f : S' ⟶ T.obj Y} (g : S ⟶ S') : (map g).obj (mk f) = mk (g ≫ f) := rfl @[simp] theorem map_id {f : StructuredArrow S T} : (map (𝟙 S)).obj f = f := by rw [eq_mk f] simp @[simp] theorem map_comp {f : S ⟶ S'} {f' : S' ⟶ S''} {h : StructuredArrow S'' T} : (map (f ≫ f')).obj h = (map f).obj ((map f').obj h) := by rw [eq_mk h] simp /-- An isomorphism `S ≅ S'` induces an equivalence `StructuredArrow S T ≌ StructuredArrow S' T`. -/ @[simps!] def mapIso (i : S ≅ S') : StructuredArrow S T ≌ StructuredArrow S' T := Comma.mapLeftIso _ ((Functor.const _).mapIso i) /-- A natural isomorphism `T ≅ T'` induces an equivalence `StructuredArrow S T ≌ StructuredArrow S T'`. -/ @[simps!] def mapNatIso (i : T ≅ T') : StructuredArrow S T ≌ StructuredArrow S T' := Comma.mapRightIso _ i instance proj_reflectsIsomorphisms : (proj S T).ReflectsIsomorphisms where reflects {Y Z} f t := ⟨⟨StructuredArrow.homMk (inv ((proj S T).map f)) (by rw [Functor.map_inv, IsIso.comp_inv_eq]; simp), by constructor <;> apply CommaMorphism.ext <;> dsimp at t ⊢ <;> simp⟩⟩ open CategoryTheory.Limits /-- The identity structured arrow is initial. -/ noncomputable def mkIdInitial [T.Full] [T.Faithful] : IsInitial (mk (𝟙 (T.obj Y))) where desc c := homMk (T.preimage c.pt.hom) uniq c m _ := by apply CommaMorphism.ext · simp · apply T.map_injective simpa only [homMk_right, T.map_preimage, ← w m] using (Category.id_comp _).symm variable {A : Type u₃} [Category.{v₃} A] {B : Type u₄} [Category.{v₄} B] /-- The functor `(S, F ⋙ G) ⥤ (S, G)`. -/ @[simps!] def pre (S : D) (F : B ⥤ C) (G : C ⥤ D) : StructuredArrow S (F ⋙ G) ⥤ StructuredArrow S G := Comma.preRight _ F G instance (S : D) (F : B ⥤ C) (G : C ⥤ D) [F.Faithful] : (pre S F G).Faithful := show (Comma.preRight _ _ _).Faithful from inferInstance instance (S : D) (F : B ⥤ C) (G : C ⥤ D) [F.Full] : (pre S F G).Full := show (Comma.preRight _ _ _).Full from inferInstance instance (S : D) (F : B ⥤ C) (G : C ⥤ D) [F.EssSurj] : (pre S F G).EssSurj := show (Comma.preRight _ _ _).EssSurj from inferInstance /-- If `F` is an equivalence, then so is the functor `(S, F ⋙ G) ⥤ (S, G)`. -/ instance isEquivalence_pre (S : D) (F : B ⥤ C) (G : C ⥤ D) [F.IsEquivalence] : (pre S F G).IsEquivalence := Comma.isEquivalence_preRight _ _ _ /-- The functor `(S, F) ⥤ (G(S), F ⋙ G)`. -/ @[simps] def post (S : C) (F : B ⥤ C) (G : C ⥤ D) : StructuredArrow S F ⥤ StructuredArrow (G.obj S) (F ⋙ G) where obj X := StructuredArrow.mk (G.map X.hom) map f := StructuredArrow.homMk f.right (by simp [Functor.comp_map, ← G.map_comp, ← f.w]) instance (S : C) (F : B ⥤ C) (G : C ⥤ D) : (post S F G).Faithful where map_injective {_ _} _ _ h := by simpa [ext_iff] using h instance (S : C) (F : B ⥤ C) (G : C ⥤ D) [G.Faithful] : (post S F G).Full where map_surjective f := ⟨homMk f.right (G.map_injective (by simpa using f.w.symm)), by simp⟩ instance (S : C) (F : B ⥤ C) (G : C ⥤ D) [G.Full] : (post S F G).EssSurj where mem_essImage h := ⟨mk (G.preimage h.hom), ⟨isoMk (Iso.refl _) (by simp)⟩⟩ /-- If `G` is fully faithful, then `post S F G : (S, F) ⥤ (G(S), F ⋙ G)` is an equivalence. -/ instance isEquivalence_post (S : C) (F : B ⥤ C) (G : C ⥤ D) [G.Full] [G.Faithful] : (post S F G).IsEquivalence where section variable {L : D} {R : C ⥤ D} {L' : B} {R' : A ⥤ B} {F : C ⥤ A} {G : D ⥤ B} (α : L' ⟶ G.obj L) (β : R ⋙ G ⟶ F ⋙ R') /-- The functor `StructuredArrow L R ⥤ StructuredArrow L' R'` that is deduced from a natural transformation `R ⋙ G ⟶ F ⋙ R'` and a morphism `L' ⟶ G.obj L.` -/ @[simps!] def map₂ : StructuredArrow L R ⥤ StructuredArrow L' R' := Comma.map (F₁ := 𝟭 (Discrete PUnit)) (Discrete.natTrans (fun _ => α)) β instance faithful_map₂ [F.Faithful] : (map₂ α β).Faithful := by apply Comma.faithful_map instance full_map₂ [G.Faithful] [F.Full] [IsIso α] [IsIso β] : (map₂ α β).Full := by apply Comma.full_map instance essSurj_map₂ [F.EssSurj] [G.Full] [IsIso α] [IsIso β] : (map₂ α β).EssSurj := by apply Comma.essSurj_map noncomputable instance isEquivalenceMap₂ [F.IsEquivalence] [G.Faithful] [G.Full] [IsIso α] [IsIso β] : (map₂ α β).IsEquivalence := by apply Comma.isEquivalenceMap /-- The composition of two applications of `map₂` is naturally isomorphic to a single such one. -/ def map₂CompMap₂Iso {C' : Type u₆} [Category.{v₆} C'] {D' : Type u₅} [Category.{v₅} D'] {L'' : D'} {R'' : C' ⥤ D'} {F' : C' ⥤ C} {G' : D' ⥤ D} (α' : L ⟶ G'.obj L'') (β' : R'' ⋙ G' ⟶ F' ⋙ R) : map₂ α' β' ⋙ map₂ α β ≅ map₂ (α ≫ G.map α') ((Functor.associator _ _ _).inv ≫ Functor.whiskerRight β' _ ≫ (Functor.associator _ _ _).hom ≫ Functor.whiskerLeft _ β ≫ (Functor.associator _ _ _).inv) := NatIso.ofComponents (fun X => isoMk (Iso.refl _)) end /-- `StructuredArrow.post` is a special case of `StructuredArrow.map₂` up to natural isomorphism. -/ def postIsoMap₂ (S : C) (F : B ⥤ C) (G : C ⥤ D) : post S F G ≅ map₂ (F := 𝟭 _) (𝟙 _) (𝟙 (F ⋙ G)) := NatIso.ofComponents fun _ => isoMk <| Iso.refl _ /-- `StructuredArrow.map` is a special case of `StructuredArrow.map₂` up to natural isomorphism. -/ def mapIsoMap₂ {S S' : D} (f : S ⟶ S') : map (T := T) f ≅ map₂ (F := 𝟭 _) (G := 𝟭 _) f (𝟙 T) := NatIso.ofComponents fun _ => isoMk <| Iso.refl _ /-- `StructuredArrow.pre` is a special case of `StructuredArrow.map₂` up to natural isomorphism. -/ def preIsoMap₂ (S : D) (F : B ⥤ C) (G : C ⥤ D) : pre S F G ≅ map₂ (G := 𝟭 _) (𝟙 _) (𝟙 (F ⋙ G)) := NatIso.ofComponents fun _ => isoMk <| Iso.refl _ /-- A structured arrow is called universal if it is initial. -/ abbrev IsUniversal (f : StructuredArrow S T) := IsInitial f namespace IsUniversal variable {f g : StructuredArrow S T} theorem uniq (h : IsUniversal f) (η : f ⟶ g) : η = h.to g := h.hom_ext η (h.to g) /-- The family of morphisms out of a universal arrow. -/ def desc (h : IsUniversal f) (g : StructuredArrow S T) : f.right ⟶ g.right := (h.to g).right /-- Any structured arrow factors through a universal arrow. -/ @[reassoc (attr := simp)] theorem fac (h : IsUniversal f) (g : StructuredArrow S T) : f.hom ≫ T.map (h.desc g) = g.hom := Category.id_comp g.hom ▸ (h.to g).w.symm theorem hom_desc (h : IsUniversal f) {c : C} (η : f.right ⟶ c) : η = h.desc (mk <| f.hom ≫ T.map η) := let g := mk <| f.hom ≫ T.map η congrArg CommaMorphism.right (h.hom_ext (homMk η rfl : f ⟶ g) (h.to g)) /-- Two morphisms out of a universal `T`-structured arrow are equal if their image under `T` are equal after precomposing the universal arrow. -/ theorem hom_ext (h : IsUniversal f) {c : C} {η η' : f.right ⟶ c} (w : f.hom ≫ T.map η = f.hom ≫ T.map η') : η = η' := by rw [h.hom_desc η, h.hom_desc η', w] theorem existsUnique (h : IsUniversal f) (g : StructuredArrow S T) : ∃! η : f.right ⟶ g.right, f.hom ≫ T.map η = g.hom := ⟨h.desc g, h.fac g, fun f w ↦ h.hom_ext <| by simp [w]⟩ end IsUniversal end StructuredArrow /-- The category of `S`-costructured arrows with target `T : D` (here `S : C ⥤ D`), has as its objects `D`-morphisms of the form `S Y ⟶ T`, for some `Y : C`, and morphisms `C`-morphisms `Y ⟶ Y'` making the obvious triangle commute. -/ -- We explicitly come from `PUnit.{1}` here to obtain the correct universe for morphisms of -- costructured arrows. def CostructuredArrow (S : C ⥤ D) (T : D) := Comma S (Functor.fromPUnit.{0} T) instance (S : C ⥤ D) (T : D) : Category (CostructuredArrow S T) := commaCategory namespace CostructuredArrow /-- The obvious projection functor from costructured arrows. -/ @[simps!] def proj (S : C ⥤ D) (T : D) : CostructuredArrow S T ⥤ C := Comma.fst _ _ variable {T T' T'' : D} {Y Y' Y'' : C} {S S' : C ⥤ D} @[ext] lemma hom_ext {X Y : CostructuredArrow S T} (f g : X ⟶ Y) (h : f.left = g.left) : f = g := CommaMorphism.ext h (Subsingleton.elim _ _) @[simp] theorem hom_eq_iff {X Y : CostructuredArrow S T} (f g : X ⟶ Y) : f = g ↔ f.left = g.left := ⟨fun h ↦ by rw [h], hom_ext _ _⟩ /-- Construct a costructured arrow from a morphism. -/ def mk (f : S.obj Y ⟶ T) : CostructuredArrow S T := ⟨Y, ⟨⟨⟩⟩, f⟩ @[simp] theorem mk_left (f : S.obj Y ⟶ T) : (mk f).left = Y := rfl @[simp] theorem mk_right (f : S.obj Y ⟶ T) : (mk f).right = ⟨⟨⟩⟩ := rfl @[simp] theorem mk_hom_eq_self (f : S.obj Y ⟶ T) : (mk f).hom = f := rfl @[reassoc] theorem w {A B : CostructuredArrow S T} (f : A ⟶ B) : S.map f.left ≫ B.hom = A.hom := by simp @[simp] theorem comp_left {X Y Z : CostructuredArrow S T} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).left = f.left ≫ g.left := rfl @[simp] theorem id_left (X : CostructuredArrow S T) : (𝟙 X : X ⟶ X).left = 𝟙 X.left := rfl @[simp] theorem eqToHom_left {X Y : CostructuredArrow S T} (h : X = Y) : (eqToHom h).left = eqToHom (by rw [h]) := by subst h simp only [eqToHom_refl, id_left] @[simp] theorem right_eq_id {X Y : CostructuredArrow S T} (f : X ⟶ Y) : f.right = 𝟙 X.right := rfl /-- To construct a morphism of costructured arrows, we need a morphism of the objects underlying the source, and to check that the triangle commutes. -/ @[simps! left] def homMk {f f' : CostructuredArrow S T} (g : f.left ⟶ f'.left) (w : S.map g ≫ f'.hom = f.hom := by cat_disch) : f ⟶ f' where left := g right := 𝟙 f.right theorem homMk_surjective {f f' : CostructuredArrow S T} (φ : f ⟶ f') : ∃ (ψ : f.left ⟶ f'.left) (hψ : S.map ψ ≫ f'.hom = f.hom), φ = CostructuredArrow.homMk ψ hψ := ⟨φ.left, CostructuredArrow.w φ, rfl⟩ /-- Given a costructured arrow `S(Y) ⟶ X`, and an arrow `Y' ⟶ Y'`, we can construct a morphism of costructured arrows given by `(S(Y) ⟶ X) ⟶ (S(Y') ⟶ S(Y) ⟶ X)`. -/ @[simps] def homMk' (f : CostructuredArrow S T) (g : Y' ⟶ f.left) : mk (S.map g ≫ f.hom) ⟶ f where left := g right := 𝟙 _ lemma homMk'_id (f : CostructuredArrow S T) : homMk' f (𝟙 f.left) = eqToHom (by cat_disch) := by simp [eqToHom_left] lemma homMk'_mk_id (f : S.obj Y ⟶ T) : homMk' (mk f) (𝟙 Y) = eqToHom (by simp) := homMk'_id _ lemma homMk'_comp (f : CostructuredArrow S T) (g : Y' ⟶ f.left) (g' : Y'' ⟶ Y') : homMk' f (g' ≫ g) = eqToHom (by simp) ≫ homMk' (mk (S.map g ≫ f.hom)) g' ≫ homMk' f g := by simp [eqToHom_left] lemma homMk'_mk_comp (f : S.obj Y ⟶ T) (g : Y' ⟶ Y) (g' : Y'' ⟶ Y') : homMk' (mk f) (g' ≫ g) = eqToHom (by simp) ≫ homMk' (mk (S.map g ≫ f)) g' ≫ homMk' (mk f) g := homMk'_comp _ _ _ /-- Variant of `homMk'` where both objects are applications of `mk`. -/ @[simps] def mkPrecomp (f : S.obj Y ⟶ T) (g : Y' ⟶ Y) : mk (S.map g ≫ f) ⟶ mk f where left := g right := 𝟙 _ lemma mkPrecomp_id (f : S.obj Y ⟶ T) : mkPrecomp f (𝟙 Y) = eqToHom (by simp) := by simp lemma mkPrecomp_comp (f : S.obj Y ⟶ T) (g : Y' ⟶ Y) (g' : Y'' ⟶ Y') : mkPrecomp f (g' ≫ g) = eqToHom (by simp) ≫ mkPrecomp (S.map g ≫ f) g' ≫ mkPrecomp f g := by simp /-- To construct an isomorphism of costructured arrows, we need an isomorphism of the objects underlying the source, and to check that the triangle commutes. -/ @[simps! hom_left inv_left] def isoMk {f f' : CostructuredArrow S T} (g : f.left ≅ f'.left) (w : S.map g.hom ≫ f'.hom = f.hom := by cat_disch) : f ≅ f' := Comma.isoMk g (eqToIso (by ext)) (by simpa using w) theorem obj_ext (x y : CostructuredArrow S T) (hl : x.left = y.left) (hh : S.map (eqToHom hl) ≫ y.hom = x.hom) : x = y := by cases x cases y cases hl cat_disch theorem ext {A B : CostructuredArrow S T} (f g : A ⟶ B) (h : f.left = g.left) : f = g := CommaMorphism.ext h (Subsingleton.elim _ _) theorem ext_iff {A B : CostructuredArrow S T} (f g : A ⟶ B) : f = g ↔ f.left = g.left := ⟨fun h => h ▸ rfl, ext f g⟩ instance proj_faithful : (proj S T).Faithful where map_injective {_ _} := ext theorem mono_of_mono_left {A B : CostructuredArrow S T} (f : A ⟶ B) [h : Mono f.left] : Mono f := (proj S T).mono_of_mono_map h /-- The converse of this is true with additional assumptions, see `epi_iff_epi_left`. -/ theorem epi_of_epi_left {A B : CostructuredArrow S T} (f : A ⟶ B) [h : Epi f.left] : Epi f := (proj S T).epi_of_epi_map h instance mono_homMk {A B : CostructuredArrow S T} (f : A.left ⟶ B.left) (w) [h : Mono f] : Mono (homMk f w) := (proj S T).mono_of_mono_map h instance epi_homMk {A B : CostructuredArrow S T} (f : A.left ⟶ B.left) (w) [h : Epi f] : Epi (homMk f w) := (proj S T).epi_of_epi_map h /-- Eta rule for costructured arrows. Prefer `CostructuredArrow.eta` for rewriting, as equality of objects tends to cause problems. -/ theorem eq_mk (f : CostructuredArrow S T) : f = mk f.hom := rfl /-- Eta rule for costructured arrows. -/ @[simps! hom_left inv_left] def eta (f : CostructuredArrow S T) : f ≅ mk f.hom := isoMk (Iso.refl _) lemma mk_surjective (f : CostructuredArrow S T) : ∃ (Y : C) (g : S.obj Y ⟶ T), f = mk g := ⟨_, _, eq_mk f⟩ /-- A morphism between target objects `T ⟶ T'` covariantly induces a functor between costructured arrows, `CostructuredArrow S T ⥤ CostructuredArrow S T'`. Ideally this would be described as a 2-functor from `D` (promoted to a 2-category with equations as 2-morphisms) to `Cat`. -/ @[simps!] def map (f : T ⟶ T') : CostructuredArrow S T ⥤ CostructuredArrow S T' := Comma.mapRight _ ((Functor.const _).map f) @[simp] theorem map_mk {f : S.obj Y ⟶ T} (g : T ⟶ T') : (map g).obj (mk f) = mk (f ≫ g) := rfl @[simp] theorem map_id {f : CostructuredArrow S T} : (map (𝟙 T)).obj f = f := by rw [eq_mk f] simp @[simp] theorem map_comp {f : T ⟶ T'} {f' : T' ⟶ T''} {h : CostructuredArrow S T} : (map (f ≫ f')).obj h = (map f').obj ((map f).obj h) := by rw [eq_mk h] simp /-- An isomorphism `T ≅ T'` induces an equivalence `CostructuredArrow S T ≌ CostructuredArrow S T'`. -/ @[simps!] def mapIso (i : T ≅ T') : CostructuredArrow S T ≌ CostructuredArrow S T' := Comma.mapRightIso _ ((Functor.const _).mapIso i) /-- A natural isomorphism `S ≅ S'` induces an equivalence `CostrucutredArrow S T ≌ CostructuredArrow S' T`. -/ @[simps!] def mapNatIso (i : S ≅ S') : CostructuredArrow S T ≌ CostructuredArrow S' T := Comma.mapLeftIso _ i instance proj_reflectsIsomorphisms : (proj S T).ReflectsIsomorphisms where reflects {Y Z} f t := ⟨⟨CostructuredArrow.homMk (inv ((proj S T).map f)) (by rw [Functor.map_inv, IsIso.inv_comp_eq]; simp), by constructor <;> ext <;> dsimp at t ⊢ <;> simp⟩⟩ open CategoryTheory.Limits /-- The identity costructured arrow is terminal. -/ noncomputable def mkIdTerminal [S.Full] [S.Faithful] : IsTerminal (mk (𝟙 (S.obj Y))) where lift c := homMk (S.preimage c.pt.hom) uniq := by rintro c m - ext apply S.map_injective simpa only [homMk_left, S.map_preimage, ← w m] using (Category.comp_id _).symm variable {A : Type u₃} [Category.{v₃} A] {B : Type u₄} [Category.{v₄} B] /-- The functor `(F ⋙ G, S) ⥤ (G, S)`. -/ @[simps!] def pre (F : B ⥤ C) (G : C ⥤ D) (S : D) : CostructuredArrow (F ⋙ G) S ⥤ CostructuredArrow G S := Comma.preLeft F G _ instance (F : B ⥤ C) (G : C ⥤ D) (S : D) [F.Faithful] : (pre F G S).Faithful := show (Comma.preLeft _ _ _).Faithful from inferInstance instance (F : B ⥤ C) (G : C ⥤ D) (S : D) [F.Full] : (pre F G S).Full := show (Comma.preLeft _ _ _).Full from inferInstance instance (F : B ⥤ C) (G : C ⥤ D) (S : D) [F.EssSurj] : (pre F G S).EssSurj := show (Comma.preLeft _ _ _).EssSurj from inferInstance /-- If `F` is an equivalence, then so is the functor `(F ⋙ G, S) ⥤ (G, S)`. -/ instance isEquivalence_pre (F : B ⥤ C) (G : C ⥤ D) (S : D) [F.IsEquivalence] : (pre F G S).IsEquivalence := Comma.isEquivalence_preLeft _ _ _ /-- The functor `(F, S) ⥤ (F ⋙ G, G(S))`. -/ @[simps] def post (F : B ⥤ C) (G : C ⥤ D) (S : C) : CostructuredArrow F S ⥤ CostructuredArrow (F ⋙ G) (G.obj S) where obj X := CostructuredArrow.mk (G.map X.hom) map f := CostructuredArrow.homMk f.left (by simp [Functor.comp_map, ← G.map_comp]) instance (F : B ⥤ C) (G : C ⥤ D) (S : C) : (post F G S).Faithful where map_injective {_ _} _ _ h := by simpa [ext_iff] using h instance (F : B ⥤ C) (G : C ⥤ D) (S : C) [G.Faithful] : (post F G S).Full where map_surjective f := ⟨homMk f.left (G.map_injective (by simpa using f.w)), by simp⟩ instance (F : B ⥤ C) (G : C ⥤ D) (S : C) [G.Full] : (post F G S).EssSurj where mem_essImage h := ⟨mk (G.preimage h.hom), ⟨isoMk (Iso.refl _) (by simp)⟩⟩ /-- If `G` is fully faithful, then `post F G S : (F, S) ⥤ (F ⋙ G, G(S))` is an equivalence. -/ instance isEquivalence_post (S : C) (F : B ⥤ C) (G : C ⥤ D) [G.Full] [G.Faithful] : (post F G S).IsEquivalence where section variable {U : A ⥤ B} {V : B} {F : C ⥤ A} {G : D ⥤ B} (α : F ⋙ U ⟶ S ⋙ G) (β : G.obj T ⟶ V) /-- The functor `CostructuredArrow S T ⥤ CostructuredArrow U V` that is deduced from a natural transformation `F ⋙ U ⟶ S ⋙ G` and a morphism `G.obj T ⟶ V` -/ @[simps!] def map₂ : CostructuredArrow S T ⥤ CostructuredArrow U V := Comma.map (F₂ := 𝟭 (Discrete PUnit)) α (Discrete.natTrans (fun _ => β)) instance faithful_map₂ [F.Faithful] : (map₂ α β).Faithful := by apply Comma.faithful_map instance full_map₂ [G.Faithful] [F.Full] [IsIso α] [IsIso β] : (map₂ α β).Full := by apply Comma.full_map instance essSurj_map₂ [F.EssSurj] [G.Full] [IsIso α] [IsIso β] : (map₂ α β).EssSurj := by apply Comma.essSurj_map noncomputable instance isEquivalenceMap₂ [F.IsEquivalence] [G.Faithful] [G.Full] [IsIso α] [IsIso β] : (map₂ α β).IsEquivalence := by apply Comma.isEquivalenceMap end /-- `CostructuredArrow.post` is a special case of `CostructuredArrow.map₂` up to natural isomorphism. -/ def postIsoMap₂ (S : C) (F : B ⥤ C) (G : C ⥤ D) : post F G S ≅ map₂ (F := 𝟭 _) (𝟙 (F ⋙ G)) (𝟙 _) := NatIso.ofComponents fun _ => isoMk <| Iso.refl _ /-- A costructured arrow is called universal if it is terminal. -/ abbrev IsUniversal (f : CostructuredArrow S T) := IsTerminal f namespace IsUniversal variable {f g : CostructuredArrow S T} theorem uniq (h : IsUniversal f) (η : g ⟶ f) : η = h.from g := h.hom_ext η (h.from g) /-- The family of morphisms into a universal arrow. -/ def lift (h : IsUniversal f) (g : CostructuredArrow S T) : g.left ⟶ f.left := (h.from g).left /-- Any costructured arrow factors through a universal arrow. -/ @[reassoc (attr := simp)] theorem fac (h : IsUniversal f) (g : CostructuredArrow S T) : S.map (h.lift g) ≫ f.hom = g.hom := Category.comp_id g.hom ▸ (h.from g).w theorem hom_desc (h : IsUniversal f) {c : C} (η : c ⟶ f.left) : η = h.lift (mk <| S.map η ≫ f.hom) := let g := mk <| S.map η ≫ f.hom congrArg CommaMorphism.left (h.hom_ext (homMk η rfl : g ⟶ f) (h.from g)) /-- Two morphisms into a universal `S`-costructured arrow are equal if their image under `S` are equal after postcomposing the universal arrow. -/ theorem hom_ext (h : IsUniversal f) {c : C} {η η' : c ⟶ f.left} (w : S.map η ≫ f.hom = S.map η' ≫ f.hom) : η = η' := by rw [h.hom_desc η, h.hom_desc η', w] theorem existsUnique (h : IsUniversal f) (g : CostructuredArrow S T) : ∃! η : g.left ⟶ f.left, S.map η ≫ f.hom = g.hom := ⟨h.lift g, h.fac g, fun f w ↦ h.hom_ext <| by simp [w]⟩ end IsUniversal end CostructuredArrow namespace Functor variable {E : Type u₃} [Category.{v₃} E] /-- Given `X : D` and `F : C ⥤ D`, to upgrade a functor `G : E ⥤ C` to a functor `E ⥤ StructuredArrow X F`, it suffices to provide maps `X ⟶ F.obj (G.obj Y)` for all `Y` making the obvious triangles involving all `F.map (G.map g)` commute. This is of course the same as providing a cone over `F ⋙ G` with cone point `X`, see `Functor.toStructuredArrowIsoToStructuredArrow`. -/ @[simps] def toStructuredArrow (G : E ⥤ C) (X : D) (F : C ⥤ D) (f : (Y : E) → X ⟶ F.obj (G.obj Y)) (h : ∀ {Y Z : E} (g : Y ⟶ Z), f Y ≫ F.map (G.map g) = f Z) : E ⥤ StructuredArrow X F where obj Y := StructuredArrow.mk (f Y) map g := StructuredArrow.homMk (G.map g) (h g) /-- Upgrading a functor `E ⥤ C` to a functor `E ⥤ StructuredArrow X F` and composing with the forgetful functor `StructuredArrow X F ⥤ C` recovers the original functor. -/ def toStructuredArrowCompProj (G : E ⥤ C) (X : D) (F : C ⥤ D) (f : (Y : E) → X ⟶ F.obj (G.obj Y)) (h : ∀ {Y Z : E} (g : Y ⟶ Z), f Y ≫ F.map (G.map g) = f Z) : G.toStructuredArrow X F f h ⋙ StructuredArrow.proj _ _ ≅ G := Iso.refl _ @[simp] lemma toStructuredArrow_comp_proj (G : E ⥤ C) (X : D) (F : C ⥤ D) (f : (Y : E) → X ⟶ F.obj (G.obj Y)) (h : ∀ {Y Z : E} (g : Y ⟶ Z), f Y ≫ F.map (G.map g) = f Z) : G.toStructuredArrow X F f h ⋙ StructuredArrow.proj _ _ = G := rfl /-- Given `F : C ⥤ D` and `X : D`, to upgrade a functor `G : E ⥤ C` to a functor `E ⥤ CostructuredArrow F X`, it suffices to provide maps `F.obj (G.obj Y) ⟶ X` for all `Y` making the obvious triangles involving all `F.map (G.map g)` commute. This is of course the same as providing a cocone over `F ⋙ G` with cocone point `X`, see `Functor.toCostructuredArrowIsoToCostructuredArrow`. -/ @[simps] def toCostructuredArrow (G : E ⥤ C) (F : C ⥤ D) (X : D) (f : (Y : E) → F.obj (G.obj Y) ⟶ X) (h : ∀ {Y Z : E} (g : Y ⟶ Z), F.map (G.map g) ≫ f Z = f Y) : E ⥤ CostructuredArrow F X where obj Y := CostructuredArrow.mk (f Y) map g := CostructuredArrow.homMk (G.map g) (h g) /-- Upgrading a functor `E ⥤ C` to a functor `E ⥤ CostructuredArrow F X` and composing with the forgetful functor `CostructuredArrow F X ⥤ C` recovers the original functor. -/ def toCostructuredArrowCompProj (G : E ⥤ C) (F : C ⥤ D) (X : D) (f : (Y : E) → F.obj (G.obj Y) ⟶ X) (h : ∀ {Y Z : E} (g : Y ⟶ Z), F.map (G.map g) ≫ f Z = f Y) : G.toCostructuredArrow F X f h ⋙ CostructuredArrow.proj _ _ ≅ G := Iso.refl _ @[simp] lemma toCostructuredArrow_comp_proj (G : E ⥤ C) (F : C ⥤ D) (X : D) (f : (Y : E) → F.obj (G.obj Y) ⟶ X) (h : ∀ {Y Z : E} (g : Y ⟶ Z), F.map (G.map g) ≫ f Z = f Y) : G.toCostructuredArrow F X f h ⋙ CostructuredArrow.proj _ _ = G := rfl end Functor open Opposite namespace StructuredArrow /-- For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the category of structured arrows `d ⟶ F.obj c` to the category of costructured arrows `F.op.obj c ⟶ (op d)`. -/ @[simps] def toCostructuredArrow (F : C ⥤ D) (d : D) : (StructuredArrow d F)ᵒᵖ ⥤ CostructuredArrow F.op (op d) where obj X := @CostructuredArrow.mk _ _ _ _ _ (op X.unop.right) F.op X.unop.hom.op map f := CostructuredArrow.homMk f.unop.right.op (by simp [← op_comp]) /-- For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the category of structured arrows `op d ⟶ F.op.obj c` to the category of costructured arrows `F.obj c ⟶ d`. -/ @[simps] def toCostructuredArrow' (F : C ⥤ D) (d : D) : (StructuredArrow (op d) F.op)ᵒᵖ ⥤ CostructuredArrow F d where obj X := @CostructuredArrow.mk _ _ _ _ _ (unop X.unop.right) F X.unop.hom.unop map f := CostructuredArrow.homMk f.unop.right.unop (by dsimp rw [← Quiver.Hom.unop_op (F.map (Quiver.Hom.unop f.unop.right)), ← unop_comp, ← F.op_map, ← f.unop.w] simp) end StructuredArrow namespace CostructuredArrow /-- For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the category of costructured arrows `F.obj c ⟶ d` to the category of structured arrows `op d ⟶ F.op.obj c`. -/ @[simps] def toStructuredArrow (F : C ⥤ D) (d : D) : (CostructuredArrow F d)ᵒᵖ ⥤ StructuredArrow (op d) F.op where obj X := @StructuredArrow.mk _ _ _ _ _ (op X.unop.left) F.op X.unop.hom.op map f := StructuredArrow.homMk f.unop.left.op (by simp [← op_comp]) /-- For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the category of costructured arrows `F.op.obj c ⟶ op d` to the category of structured arrows `d ⟶ F.obj c`. -/ @[simps] def toStructuredArrow' (F : C ⥤ D) (d : D) : (CostructuredArrow F.op (op d))ᵒᵖ ⥤ StructuredArrow d F where obj X := @StructuredArrow.mk _ _ _ _ _ (unop X.unop.left) F X.unop.hom.unop map f := StructuredArrow.homMk f.unop.left.unop (by dsimp rw [← Quiver.Hom.unop_op (F.map f.unop.left.unop), ← unop_comp, ← F.op_map, f.unop.w, Functor.const_obj_map] simp) end CostructuredArrow /-- For a functor `F : C ⥤ D` and an object `d : D`, the category of structured arrows `d ⟶ F.obj c` is contravariantly equivalent to the category of costructured arrows `F.op.obj c ⟶ op d`. -/ def structuredArrowOpEquivalence (F : C ⥤ D) (d : D) : (StructuredArrow d F)ᵒᵖ ≌ CostructuredArrow F.op (op d) where functor := StructuredArrow.toCostructuredArrow F d inverse := (CostructuredArrow.toStructuredArrow' F d).rightOp unitIso := NatIso.ofComponents (fun X => (StructuredArrow.isoMk (Iso.refl _)).op) fun {X Y} f => Quiver.Hom.unop_inj <| by apply CommaMorphism.ext <;> dsimp [StructuredArrow.isoMk, Comma.isoMk,StructuredArrow.homMk]; simp counitIso := NatIso.ofComponents (fun X => CostructuredArrow.isoMk (Iso.refl _)) fun {X Y} f => by apply CommaMorphism.ext <;> dsimp [CostructuredArrow.isoMk, Comma.isoMk, CostructuredArrow.homMk]; simp /-- For a functor `F : C ⥤ D` and an object `d : D`, the category of costructured arrows `F.obj c ⟶ d` is contravariantly equivalent to the category of structured arrows `op d ⟶ F.op.obj c`. -/ def costructuredArrowOpEquivalence (F : C ⥤ D) (d : D) : (CostructuredArrow F d)ᵒᵖ ≌ StructuredArrow (op d) F.op where functor := CostructuredArrow.toStructuredArrow F d inverse := (StructuredArrow.toCostructuredArrow' F d).rightOp unitIso := NatIso.ofComponents (fun X => (CostructuredArrow.isoMk (Iso.refl _)).op) fun {X Y} f => Quiver.Hom.unop_inj <| by apply CommaMorphism.ext <;> dsimp [CostructuredArrow.isoMk, CostructuredArrow.homMk, Comma.isoMk]; simp counitIso := NatIso.ofComponents (fun X => StructuredArrow.isoMk (Iso.refl _)) fun {X Y} f => by apply CommaMorphism.ext <;> dsimp [StructuredArrow.isoMk, StructuredArrow.homMk, Comma.isoMk]; simp section Pre variable {E : Type u₃} [Category.{v₃} E] (F : C ⥤ D) {G : D ⥤ E} {e : E} /-- The functor establishing the equivalence `StructuredArrow.preEquivalence`. -/ @[simps!] def StructuredArrow.preEquivalenceFunctor (f : StructuredArrow e G) : StructuredArrow f (pre e F G) ⥤ StructuredArrow f.right F where obj g := mk g.hom.right map φ := homMk φ.right.right <| by have := w φ simp only [Functor.const_obj_obj] at this ⊢ rw [← this, comp_right] simp /-- The inverse functor establishing the equivalence `StructuredArrow.preEquivalence`. -/ @[simps!] def StructuredArrow.preEquivalenceInverse (f : StructuredArrow e G) : StructuredArrow f.right F ⥤ StructuredArrow f (pre e F G) where obj g := mk (Y := mk (Y := g.right) (f.hom ≫ (G.map g.hom : G.obj f.right ⟶ (F ⋙ G).obj g.right))) (homMk g.hom) map φ := homMk <| homMk φ.right <| by simp only [Functor.const_obj_obj, Functor.comp_obj, mk_right, mk_left, mk_hom_eq_self, Functor.comp_map, Category.assoc, ← w φ, Functor.map_comp] /-- A structured arrow category on a `StructuredArrow.pre e F G` functor is equivalent to the structured arrow category on F -/ @[simps] def StructuredArrow.preEquivalence (f : StructuredArrow e G) : StructuredArrow f (pre e F G) ≌ StructuredArrow f.right F where functor := preEquivalenceFunctor F f inverse := preEquivalenceInverse F f unitIso := NatIso.ofComponents (fun _ => isoMk (isoMk (Iso.refl _))) counitIso := NatIso.ofComponents (fun _ => isoMk (Iso.refl _)) /-- The functor `StructuredArrow d T ⥤ StructuredArrow e (T ⋙ S)` that `u : e ⟶ S.obj d` induces via `StructuredArrow.map₂` can be expressed up to isomorphism by `StructuredArrow.preEquivalence` and `StructuredArrow.proj`. -/ def StructuredArrow.map₂IsoPreEquivalenceInverseCompProj {T : C ⥤ D} {S : D ⥤ E} {T' : C ⥤ E} (d : D) (e : E) (u : e ⟶ S.obj d) (α : T ⋙ S ⟶ T') : map₂ (F := 𝟭 _) u α ≅ (preEquivalence T (mk u)).inverse ⋙ proj (mk u) (pre _ T S) ⋙ map₂ (F := 𝟭 _) (G := 𝟭 _) (𝟙 _) α := NatIso.ofComponents fun _ => isoMk (Iso.refl _) /-- The functor establishing the equivalence `CostructuredArrow.preEquivalence`. -/ @[simps!] def CostructuredArrow.preEquivalence.functor (f : CostructuredArrow G e) : CostructuredArrow (pre F G e) f ⥤ CostructuredArrow F f.left where obj g := mk g.hom.left map φ := homMk φ.left.left <| by have := w φ simp only [Functor.const_obj_obj] at this ⊢ rw [← this, comp_left] simp /-- The inverse functor establishing the equivalence `CostructuredArrow.preEquivalence`. -/ @[simps!] def CostructuredArrow.preEquivalence.inverse (f : CostructuredArrow G e) : CostructuredArrow F f.left ⥤ CostructuredArrow (pre F G e) f where obj g := mk (Y := mk (Y := g.left) (G.map g.hom ≫ f.hom)) (homMk g.hom) map φ := homMk <| homMk φ.left <| by simp only [Functor.const_obj_obj, Functor.comp_obj, mk_left, Functor.comp_map, mk_hom_eq_self, ← w φ, Functor.map_comp, Category.assoc] /-- A costructured arrow category on a `CostructuredArrow.pre F G e` functor is equivalent to the costructured arrow category on F -/ def CostructuredArrow.preEquivalence (f : CostructuredArrow G e) : CostructuredArrow (pre F G e) f ≌ CostructuredArrow F f.left where functor := preEquivalence.functor F f inverse := preEquivalence.inverse F f unitIso := NatIso.ofComponents (fun _ => isoMk (isoMk (Iso.refl _))) counitIso := NatIso.ofComponents (fun _ => isoMk (Iso.refl _)) /-- The functor `CostructuredArrow T d ⥤ CostructuredArrow (T ⋙ S) e` that `u : S.obj d ⟶ e` induces via `CostructuredArrow.map₂` can be expressed up to isomorphism by `CostructuredArrow.preEquivalence` and `CostructuredArrow.proj`. -/ def CostructuredArrow.map₂IsoPreEquivalenceInverseCompProj (T : C ⥤ D) (S : D ⥤ E) (d : D) (e : E) (u : S.obj d ⟶ e) : map₂ (F := 𝟭 _) (U := T ⋙ S) (𝟙 (T ⋙ S)) u ≅ (preEquivalence T (mk u)).inverse ⋙ proj (pre T S _) (mk u) := NatIso.ofComponents fun _ => isoMk (Iso.refl _) end Pre section Prod section variable {C' : Type u₃} [Category.{v₃} C'] {D' : Type u₄} [Category.{v₄} D'] (S : D) (S' : D') (T : C ⥤ D) (T' : C' ⥤ D') @[reassoc (attr := simp)] theorem StructuredArrow.w_prod_fst {X Y : StructuredArrow (S, S') (T.prod T')} (f : X ⟶ Y) : X.hom.1 ≫ T.map f.right.1 = Y.hom.1 := congr_arg _root_.Prod.fst (StructuredArrow.w f) @[reassoc (attr := simp)] theorem StructuredArrow.w_prod_snd {X Y : StructuredArrow (S, S') (T.prod T')} (f : X ⟶ Y) : X.hom.2 ≫ T'.map f.right.2 = Y.hom.2 := congr_arg _root_.Prod.snd (StructuredArrow.w f) /-- Implementation; see `StructuredArrow.prodEquivalence`. -/ @[simps] def StructuredArrow.prodFunctor : StructuredArrow (S, S') (T.prod T') ⥤ StructuredArrow S T × StructuredArrow S' T' where obj f := ⟨.mk f.hom.1, .mk f.hom.2⟩ map η := ⟨StructuredArrow.homMk η.right.1 (by simp), StructuredArrow.homMk η.right.2 (by simp)⟩ /-- Implementation; see `StructuredArrow.prodEquivalence`. -/ @[simps] def StructuredArrow.prodInverse : StructuredArrow S T × StructuredArrow S' T' ⥤ StructuredArrow (S, S') (T.prod T') where obj f := .mk (Y := (f.1.right, f.2.right)) ⟨f.1.hom, f.2.hom⟩ map η := StructuredArrow.homMk ⟨η.1.right, η.2.right⟩ (by simp) /-- The natural equivalence `StructuredArrow (S, S') (T.prod T') ≌ StructuredArrow S T × StructuredArrow S' T'`. -/ @[simps] def StructuredArrow.prodEquivalence : StructuredArrow (S, S') (T.prod T') ≌ StructuredArrow S T × StructuredArrow S' T' where functor := StructuredArrow.prodFunctor S S' T T' inverse := StructuredArrow.prodInverse S S' T T' unitIso := NatIso.ofComponents (fun f => Iso.refl _) (by simp) counitIso := NatIso.ofComponents (fun f => Iso.refl _) (by simp) end section variable {C' : Type u₃} [Category.{v₃} C'] {D' : Type u₄} [Category.{v₄} D'] (S : C ⥤ D) (S' : C' ⥤ D') (T : D) (T' : D') @[reassoc (attr := simp)] theorem CostructuredArrow.w_prod_fst {A B : CostructuredArrow (S.prod S') (T, T')} (f : A ⟶ B) : S.map f.left.1 ≫ B.hom.1 = A.hom.1 := congr_arg _root_.Prod.fst (CostructuredArrow.w f) @[reassoc (attr := simp)] theorem CostructuredArrow.w_prod_snd {A B : CostructuredArrow (S.prod S') (T, T')} (f : A ⟶ B) : S'.map f.left.2 ≫ B.hom.2 = A.hom.2 := congr_arg _root_.Prod.snd (CostructuredArrow.w f) /-- Implementation; see `CostructuredArrow.prodEquivalence`. -/ @[simps] def CostructuredArrow.prodFunctor : CostructuredArrow (S.prod S') (T, T') ⥤ CostructuredArrow S T × CostructuredArrow S' T' where obj f := ⟨.mk f.hom.1, .mk f.hom.2⟩ map η := ⟨CostructuredArrow.homMk η.left.1 (by simp), CostructuredArrow.homMk η.left.2 (by simp)⟩ /-- Implementation; see `CostructuredArrow.prodEquivalence`. -/ @[simps] def CostructuredArrow.prodInverse : CostructuredArrow S T × CostructuredArrow S' T' ⥤ CostructuredArrow (S.prod S') (T, T') where obj f := .mk (Y := (f.1.left, f.2.left)) ⟨f.1.hom, f.2.hom⟩ map η := CostructuredArrow.homMk ⟨η.1.left, η.2.left⟩ (by simp) /-- The natural equivalence `CostructuredArrow (S.prod S') (T, T') ≌ CostructuredArrow S T × CostructuredArrow S' T'`. -/ @[simps] def CostructuredArrow.prodEquivalence : CostructuredArrow (S.prod S') (T, T') ≌ CostructuredArrow S T × CostructuredArrow S' T' where functor := CostructuredArrow.prodFunctor S S' T T' inverse := CostructuredArrow.prodInverse S S' T T' unitIso := NatIso.ofComponents (fun f => Iso.refl _) (by simp) counitIso := NatIso.ofComponents (fun f => Iso.refl _) (by simp) end end Prod end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/StructuredArrow/Functor.lean
import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic import Mathlib.CategoryTheory.Grothendieck /-! # Structured Arrow Categories as strict functor to Cat Forming a structured arrow category `StructuredArrow d T` with `d : D` and `T : C ⥤ D` is strictly functorial in `S`, inducing a functor `Dᵒᵖ ⥤ Cat`. This file constructs said functor and proves that, in the dual case, we can precompose it with another functor `L : E ⥤ D` to obtain a category equivalent to `Comma L T`. -/ namespace CategoryTheory universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] namespace StructuredArrow /-- The structured arrow category `StructuredArrow d T` depends on the chosen domain `d : D` in a functorial way, inducing a functor `Dᵒᵖ ⥤ Cat`. -/ @[simps] def functor (T : C ⥤ D) : Dᵒᵖ ⥤ Cat where obj d := .of <| StructuredArrow d.unop T map f := map f.unop map_id d := Functor.ext (fun ⟨_, _, _⟩ => by simp) map_comp f g := Functor.ext (fun _ => by simp) end StructuredArrow namespace CostructuredArrow /-- The costructured arrow category `CostructuredArrow T d` depends on the chosen codomain `d : D` in a functorial way, inducing a functor `D ⥤ Cat`. -/ @[simps] def functor (T : C ⥤ D) : D ⥤ Cat where obj d := .of <| CostructuredArrow T d map f := CostructuredArrow.map f map_id d := Functor.ext (fun ⟨_, _, _⟩ => by simp [CostructuredArrow.map, Comma.mapRight]) map_comp f g := Functor.ext (fun _ => by simp [CostructuredArrow.map, Comma.mapRight]) variable {E : Type u₃} [Category.{v₃} E] variable (L : C ⥤ D) (R : E ⥤ D) /-- The functor used to establish the equivalence `grothendieckPrecompFunctorEquivalence` between the Grothendieck construction on `CostructuredArrow.functor` and the comma category. -/ @[simps] def grothendieckPrecompFunctorToComma : Grothendieck (R ⋙ functor L) ⥤ Comma L R where obj P := ⟨P.fiber.left, P.base, P.fiber.hom⟩ map f := ⟨f.fiber.left, f.base, by simp⟩ /-- Fibers of `grothendieckPrecompFunctorToComma L R`, composed with `Comma.fst L R`, are isomorphic to the projection `proj L (R.obj X)`. -/ @[simps!] def ιCompGrothendieckPrecompFunctorToCommaCompFst (X : E) : Grothendieck.ι (R ⋙ functor L) X ⋙ grothendieckPrecompFunctorToComma L R ⋙ Comma.fst _ _ ≅ proj L (R.obj X) := NatIso.ofComponents (fun X => Iso.refl _) (fun _ => by simp) /-- The inverse functor used to establish the equivalence `grothendieckPrecompFunctorEquivalence` between the Grothendieck construction on `CostructuredArrow.functor` and the comma category. -/ @[simps] def commaToGrothendieckPrecompFunctor : Comma L R ⥤ Grothendieck (R ⋙ functor L) where obj X := ⟨X.right, mk X.hom⟩ map f := ⟨f.right, homMk f.left⟩ map_id X := Grothendieck.ext _ _ rfl (by simp) map_comp f g := Grothendieck.ext _ _ rfl (by simp) /-- For `L : C ⥤ D`, taking the Grothendieck construction of `CostructuredArrow.functor L` precomposed with another functor `R : E ⥤ D` results in a category which is equivalent to the comma category `Comma L R`. -/ @[simps] def grothendieckPrecompFunctorEquivalence : Grothendieck (R ⋙ functor L) ≌ Comma L R where functor := grothendieckPrecompFunctorToComma _ _ inverse := commaToGrothendieckPrecompFunctor _ _ unitIso := NatIso.ofComponents (fun _ => Iso.refl _) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) /-- The functor projecting out the domain of arrows from the Grothendieck construction on costructured arrows. -/ @[simps!] def grothendieckProj : Grothendieck (functor L) ⥤ C := grothendieckPrecompFunctorToComma L (𝟭 _) ⋙ Comma.fst _ _ /-- Fibers of `grothendieckProj L` are isomorphic to the projection `proj L X`. -/ @[simps!] def ιCompGrothendieckProj (X : D) : Grothendieck.ι (functor L) X ⋙ grothendieckProj L ≅ proj L X := ιCompGrothendieckPrecompFunctorToCommaCompFst L (𝟭 _) X /-- Functors between costructured arrow categories induced by morphisms in the base category composed with fibers of `grothendieckProj L` are isomorphic to the projection `proj L X`. -/ @[simps!] def mapCompιCompGrothendieckProj {X Y : D} (f : X ⟶ Y) : CostructuredArrow.map f ⋙ Grothendieck.ι (functor L) Y ⋙ grothendieckProj L ≅ proj L X := Functor.isoWhiskerLeft (CostructuredArrow.map f) (ιCompGrothendieckPrecompFunctorToCommaCompFst L (𝟭 _) Y) /-- The functor `CostructuredArrow.pre` induces a natural transformation `CostructuredArrow.functor (S ⋙ T) ⟶ CostructuredArrow.functor T` for `S : C ⥤ D` and `T : D ⥤ E`. -/ @[simps] def preFunctor {D : Type u₁} [Category.{v₁} D] (S : C ⥤ D) (T : D ⥤ E) : functor (S ⋙ T) ⟶ functor T where app e := pre S T e end CostructuredArrow end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/StructuredArrow/Small.lean
import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.CategoryTheory.ObjectProperty.Small /-! # Small sets in the category of structured arrows Here we prove a technical result about small sets in the category of structured arrows that will be used in the proof of the Special Adjoint Functor Theorem. -/ namespace CategoryTheory -- morphism levels before object levels. See note [category theory universes]. universe w v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] namespace StructuredArrow variable {S : D} {T : C ⥤ D} instance [Small.{w} C] [LocallySmall.{w} D] : Small.{w} (StructuredArrow S T) := small_of_surjective (f := fun (f : Σ (X : C), S ⟶ T.obj X) ↦ StructuredArrow.mk f.2) (fun f ↦ by obtain ⟨X, f, rfl⟩ := f.mk_surjective exact ⟨⟨X, f⟩, rfl⟩) instance small_inverseImage_proj_of_locallySmall {P : ObjectProperty C} [ObjectProperty.Small.{v₁} P] [LocallySmall.{v₁} D] : ObjectProperty.Small.{v₁} (P.inverseImage (proj S T)) := by suffices P.inverseImage (proj S T) = .ofObj fun f : Σ (G : Subtype P), S ⟶ T.obj G => mk f.2 by rw [this] infer_instance ext X simp only [ObjectProperty.prop_inverseImage_iff, proj_obj, ObjectProperty.ofObj_iff, Sigma.exists, Subtype.exists, exists_prop] exact ⟨fun h ↦ ⟨_, h, _, rfl⟩, by rintro ⟨_, h, _, rfl⟩; exact h⟩ @[deprecated (since := "2025-10-07")] alias small_proj_preimage_of_locallySmall := small_inverseImage_proj_of_locallySmall end StructuredArrow namespace CostructuredArrow variable {S : C ⥤ D} {T : D} instance [Small.{w} C] [LocallySmall.{w} D] : Small.{w} (CostructuredArrow S T) := small_of_surjective (f := fun (f : Σ (X : C), S.obj X ⟶ T) ↦ CostructuredArrow.mk f.2) (fun f ↦ by obtain ⟨X, f, rfl⟩ := f.mk_surjective exact ⟨⟨X, f⟩, rfl⟩) instance small_inverseImage_proj_of_locallySmall {P : ObjectProperty C} [ObjectProperty.Small.{v₁} P] [LocallySmall.{v₁} D] : ObjectProperty.Small.{v₁} (P.inverseImage (proj S T)) := by suffices P.inverseImage (proj S T) = .ofObj fun f : Σ (G : Subtype P), S.obj G ⟶ T => mk f.2 by rw [this] infer_instance ext X simp only [ObjectProperty.prop_inverseImage_iff, proj_obj, ObjectProperty.ofObj_iff, Sigma.exists, Subtype.exists, exists_prop] exact ⟨fun h ↦ ⟨_, h, _, rfl⟩, by rintro ⟨_, h, _, rfl⟩; exact h⟩ @[deprecated (since := "2025-10-07")] alias small_proj_preimage_of_locallySmall := small_inverseImage_proj_of_locallySmall end CostructuredArrow end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/StructuredArrow/CommaMap.lean
import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic /-! # Structured arrow categories on `Comma.map` We characterize structured arrow categories on arbitrary instances of `Comma.map` as a comma category itself. -/ namespace CategoryTheory namespace StructuredArrow universe v₁ v₂ v₃ v₄ v₅ v₆ u₁ u₂ u₃ u₄ u₅ u₆ noncomputable section variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {T : Type u₃} [Category.{v₃} T] {L : C ⥤ T} {R : D ⥤ T} {C' : Type u₄} [Category.{v₄} C'] {D' : Type u₅} [Category.{v₅} D'] {T' : Type u₆} [Category.{v₆} T'] {L' : C' ⥤ T'} {R' : D' ⥤ T'} {F₁ : C ⥤ C'} {F₂ : D ⥤ D'} {F : T ⥤ T'} (α : F₁ ⋙ L' ⟶ L ⋙ F) (β : R ⋙ F ⟶ F₂ ⋙ R') /-- The functor establishing the equivalence `StructuredArrow.commaMapEquivalence`. -/ @[simps] def commaMapEquivalenceFunctor [IsIso β] (X : Comma L' R') : StructuredArrow X (Comma.map α β) ⥤ Comma (map₂ (𝟙 _) α) (map₂ X.hom (inv β)) where obj Y := ⟨mk Y.hom.left, mk Y.hom.right, homMk Y.right.hom (by simpa only [Functor.const_obj_obj, map₂_obj_left, mk_left, map₂_obj_right, mk_right, map₂_obj_hom, mk_hom_eq_self, Category.id_comp, Category.assoc, NatIso.isIso_inv_app, Functor.comp_obj, Comma.map_obj_right, Comma.map_obj_left, Comma.map_obj_hom, IsIso.hom_inv_id, Category.comp_id] using congrFun (congrArg CategoryStruct.comp Y.hom.w) (inv (β.app Y.right.right)))⟩ map {Y Z} f := ⟨homMk f.right.left (congrArg CommaMorphism.left (StructuredArrow.w f)), homMk f.right.right (congrArg CommaMorphism.right (StructuredArrow.w f)), by simp only [Functor.const_obj_obj, map₂_obj_right, mk_right, hom_eq_iff, comp_right, map₂_map_right, homMk_right, CommaMorphism.w] ⟩ map_id X := by ext <;> rfl map_comp f g := by ext <;> rfl /-- The inverse functor establishing the equivalence `StructuredArrow.commaMapEquivalence`. -/ @[simps] def commaMapEquivalenceInverse [IsIso β] (X : Comma L' R') : Comma (map₂ (𝟙 _) α) (map₂ X.hom (inv β)) ⥤ StructuredArrow X (Comma.map α β) where obj Y := mk (Y := ⟨Y.left.right, Y.right.right, Y.hom.right⟩) ⟨by exact Y.left.hom, by exact Y.right.hom, by simpa using congrFun (congrArg CategoryStruct.comp (StructuredArrow.w Y.hom)) (β.app Y.right.right)⟩ map {Y Z} f := homMk ⟨by exact f.left.right, by exact f.right.right, by exact congrArg CommaMorphism.right f.w⟩ (by ext <;> simp only [Comma.map_obj_right, Comma.map_obj_left, Functor.const_obj_obj, mk_left, mk_right, mk_hom_eq_self, Comma.comp_left, Comma.map_map_left, w] · simp only [Comma.map_obj_right, Comma.comp_right, Comma.map_map_right, w] ) map_id X := by ext <;> rfl map_comp f g := by ext <;> rfl /-- The unit establishing the equivalence `StructuredArrow.commaMapEquivalence`. -/ @[simps!] def commaMapEquivalenceUnitIso [IsIso β] (X : Comma L' R') : 𝟭 (StructuredArrow X (Comma.map α β)) ≅ commaMapEquivalenceFunctor α β X ⋙ commaMapEquivalenceInverse α β X := NatIso.ofComponents (fun _ => isoMk (Iso.refl _)) /-- The counit functor establishing the equivalence `StructuredArrow.commaMapEquivalence`. -/ @[simps!] def commaMapEquivalenceCounitIso [IsIso β] (X : Comma L' R') : commaMapEquivalenceInverse α β X ⋙ commaMapEquivalenceFunctor α β X ≅ 𝟭 (Comma (map₂ (𝟙 (L'.obj X.left)) α) (map₂ X.hom (inv β))) := NatIso.ofComponents (fun _ => Comma.isoMk (Iso.refl _) (Iso.refl _)) /-- The structured arrow category on the functor `Comma.map α β`, with `β` a natural isomorphism, is equivalent to a comma category on two instances of `StructuredArrow.map₂`. -/ def commaMapEquivalence [IsIso β] (X : Comma L' R') : StructuredArrow X (Comma.map α β) ≌ Comma (map₂ (𝟙 _) α) (map₂ X.hom (inv β)) where functor := commaMapEquivalenceFunctor α β X inverse := commaMapEquivalenceInverse α β X unitIso := commaMapEquivalenceUnitIso α β X counitIso := commaMapEquivalenceCounitIso α β X end end StructuredArrow end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Over/Basic.lean
import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic import Mathlib.CategoryTheory.Category.Cat /-! # Over and under categories Over (and under) categories are special cases of comma categories. * If `L` is the identity functor and `R` is a constant functor, then `Comma L R` is the "slice" or "over" category over the object `R` maps to. * Conversely, if `L` is a constant functor and `R` is the identity functor, then `Comma L R` is the "coslice" or "under" category under the object `L` maps to. ## Tags Comma, Slice, Coslice, Over, Under -/ namespace CategoryTheory universe v₁ v₂ v₃ u₁ u₂ u₃ -- morphism levels before object levels. See note [category theory universes]. variable {T : Type u₁} [Category.{v₁} T] variable {D : Type u₂} [Category.{v₂} D] /-- The over category has as objects arrows in `T` with codomain `X` and as morphisms commutative triangles. -/ @[stacks 001G] def Over (X : T) := CostructuredArrow (𝟭 T) X instance (X : T) : Category (Over X) := commaCategory -- Satisfying the inhabited linter instance Over.inhabited [Inhabited T] : Inhabited (Over (default : T)) where default := { left := default right := default hom := 𝟙 _ } namespace Over variable {X : T} @[ext] theorem OverMorphism.ext {X : T} {U V : Over X} {f g : U ⟶ V} (h : f.left = g.left) : f = g := by let ⟨_,b,_⟩ := f let ⟨_,e,_⟩ := g congr simp only [eq_iff_true_of_subsingleton] @[simp] theorem over_right (U : Over X) : U.right = ⟨⟨⟩⟩ := by simp only @[simp] theorem id_left (U : Over X) : CommaMorphism.left (𝟙 U) = 𝟙 U.left := rfl @[simp, reassoc] theorem comp_left (a b c : Over X) (f : a ⟶ b) (g : b ⟶ c) : (f ≫ g).left = f.left ≫ g.left := rfl @[reassoc (attr := simp)] theorem w {A B : Over X} (f : A ⟶ B) : f.left ≫ B.hom = A.hom := by have := f.w; cat_disch /-- To give an object in the over category, it suffices to give a morphism with codomain `X`. -/ @[simps! left hom] def mk {X Y : T} (f : Y ⟶ X) : Over X := CostructuredArrow.mk f /-- We can set up a coercion from arrows with codomain `X` to `over X`. This most likely should not be a global instance, but it is sometimes useful. -/ def coeFromHom {X Y : T} : CoeOut (Y ⟶ X) (Over X) where coe := mk section attribute [local instance] coeFromHom @[simp] theorem coe_hom {X Y : T} (f : Y ⟶ X) : (f : Over X).hom = f := rfl end /-- To give a morphism in the over category, it suffices to give an arrow fitting in a commutative triangle. -/ @[simps! left] def homMk {U V : Over X} (f : U.left ⟶ V.left) (w : f ≫ V.hom = U.hom := by cat_disch) : U ⟶ V := CostructuredArrow.homMk f w @[simp] lemma homMk_eta {U V : Over X} (f : U ⟶ V) (h) : homMk f.left h = f := rfl /-- This is useful when `homMk (· ≫ ·)` appears under `Functor.map` or a natural equivalence. -/ lemma homMk_comp {U V W : Over X} (f : U.left ⟶ V.left) (g : V.left ⟶ W.left) (w_f w_g) : homMk (f ≫ g) (by simp_all) = homMk f w_f ≫ homMk g w_g := by ext simp /-- Construct an isomorphism in the over category given isomorphisms of the objects whose forward direction gives a commutative triangle. -/ @[simps! hom_left inv_left] def isoMk {f g : Over X} (hl : f.left ≅ g.left) (hw : hl.hom ≫ g.hom = f.hom := by cat_disch) : f ≅ g := CostructuredArrow.isoMk hl hw @[reassoc (attr := simp)] lemma hom_left_inv_left {f g : Over X} (e : f ≅ g) : e.hom.left ≫ e.inv.left = 𝟙 f.left := by simp [← Over.comp_left] @[reassoc (attr := simp)] lemma inv_left_hom_left {f g : Over X} (e : f ≅ g) : e.inv.left ≫ e.hom.left = 𝟙 g.left := by simp [← Over.comp_left] lemma forall_iff (P : Over X → Prop) : (∀ Y, P Y) ↔ (∀ (Y) (f : Y ⟶ X), P (.mk f)) := by aesop section variable (X) /-- The forgetful functor mapping an arrow to its domain. -/ @[stacks 001G] def forget : Over X ⥤ T := Comma.fst _ _ end @[simp] theorem forget_obj {U : Over X} : (forget X).obj U = U.left := rfl @[simp] theorem forget_map {U V : Over X} {f : U ⟶ V} : (forget X).map f = f.left := rfl /-- The natural cocone over the forgetful functor `Over X ⥤ T` with cocone point `X`. -/ @[simps] def forgetCocone (X : T) : Limits.Cocone (forget X) := { pt := X ι := { app := Comma.hom } } /-- A morphism `f : X ⟶ Y` induces a functor `Over X ⥤ Over Y` in the obvious way. -/ @[stacks 001G] def map {Y : T} (f : X ⟶ Y) : Over X ⥤ Over Y := Comma.mapRight _ <| Discrete.natTrans fun _ => f section variable {Y : T} {f : X ⟶ Y} {U V : Over X} {g : U ⟶ V} @[simp] theorem map_obj_left : ((map f).obj U).left = U.left := rfl @[simp] theorem map_obj_hom : ((map f).obj U).hom = U.hom ≫ f := rfl @[simp] theorem map_map_left : ((map f).map g).left = g.left := rfl /-- If `f` is an isomorphism, `map f` is an equivalence of categories. -/ def mapIso (f : X ≅ Y) : Over X ≌ Over Y := Comma.mapRightIso _ <| Discrete.natIso fun _ ↦ f @[simp] lemma mapIso_functor (f : X ≅ Y) : (mapIso f).functor = map f.hom := rfl @[simp] lemma mapIso_inverse (f : X ≅ Y) : (mapIso f).inverse = map f.inv := rfl instance [IsIso f] : (Over.map f).IsEquivalence := (Over.mapIso <| asIso f).isEquivalence_functor end section coherences /-! This section proves various equalities between functors that demonstrate, for instance, that over categories assemble into a functor `mapFunctor : T ⥤ Cat`. These equalities between functors are then converted to natural isomorphisms using `eqToIso`. Such natural isomorphisms could be obtained directly using `Iso.refl` but this method will have better computational properties, when used, for instance, in developing the theory of Beck-Chevalley transformations. -/ /-- Mapping by the identity morphism is just the identity functor. -/ theorem mapId_eq (Y : T) : map (𝟙 Y) = 𝟭 _ := by fapply Functor.ext · intro x dsimp [Over, Over.map, Comma.mapRight] simp only [Category.comp_id] exact rfl · intro x y u dsimp [Over, Over.map, Comma.mapRight] simp /-- The natural isomorphism arising from `mapForget_eq`. -/ @[simps!] def mapId (Y : T) : map (𝟙 Y) ≅ 𝟭 _ := NatIso.ofComponents (fun _ ↦ isoMk (Iso.refl _)) /-- Mapping by `f` and then forgetting is the same as forgetting. -/ theorem mapForget_eq {X Y : T} (f : X ⟶ Y) : (map f) ⋙ (forget Y) = (forget X) := rfl /-- The natural isomorphism arising from `mapForget_eq`. -/ def mapForget {X Y : T} (f : X ⟶ Y) : (map f) ⋙ (forget Y) ≅ (forget X) := eqToIso (mapForget_eq f) @[simp] theorem eqToHom_left {X : T} {U V : Over X} (e : U = V) : (eqToHom e).left = eqToHom (e ▸ rfl : U.left = V.left) := by subst e; rfl /-- Mapping by the composite morphism `f ≫ g` is the same as mapping by `f` then by `g`. -/ theorem mapComp_eq {X Y Z : T} (f : X ⟶ Y) (g : Y ⟶ Z) : map (f ≫ g) = (map f) ⋙ (map g) := by fapply Functor.ext · simp [Over.map, Comma.mapRight] · intro U V k ext simp /-- The natural isomorphism arising from `mapComp_eq`. -/ @[simps!] def mapComp {X Y Z : T} (f : X ⟶ Y) (g : Y ⟶ Z) : map (f ≫ g) ≅ map f ⋙ map g := NatIso.ofComponents (fun _ ↦ isoMk (Iso.refl _)) /-- If `f = g`, then `map f` is naturally isomorphic to `map g`. -/ @[simps!] def mapCongr {X Y : T} (f g : X ⟶ Y) (h : f = g) : map f ≅ map g := NatIso.ofComponents (fun _ ↦ isoMk (Iso.refl _)) @[simp] lemma mapCongr_rfl {X Y : T} (f : X ⟶ Y) : mapCongr f f rfl = Iso.refl _ := rfl variable (T) in /-- The functor defined by the over categories -/ @[simps] def mapFunctor : T ⥤ Cat where obj X := Cat.of (Over X) map := map map_id := mapId_eq map_comp := mapComp_eq end coherences instance forget_reflects_iso : (forget X).ReflectsIsomorphisms where reflects {Y Z} f t := by let g : Z ⟶ Y := Over.homMk (inv ((forget X).map f)) ((asIso ((forget X).map f)).inv_comp_eq.2 (Over.w f).symm) dsimp [forget] at t refine ⟨⟨g, ⟨?_,?_⟩⟩⟩ repeat (ext; simp [g]) /-- The identity over `X` is terminal. -/ noncomputable def mkIdTerminal : Limits.IsTerminal (mk (𝟙 X)) := CostructuredArrow.mkIdTerminal instance forget_faithful : (forget X).Faithful where -- TODO: Show the converse holds if `T` has binary products. /-- If `k.left` is an epimorphism, then `k` is an epimorphism. In other words, `Over.forget X` reflects epimorphisms. The converse does not hold without additional assumptions on the underlying category, see `CategoryTheory.Over.epi_left_of_epi`. -/ theorem epi_of_epi_left {f g : Over X} (k : f ⟶ g) [hk : Epi k.left] : Epi k := (forget X).epi_of_epi_map hk instance epi_homMk {U V : Over X} {f : U.left ⟶ V.left} [Epi f] (w) : Epi (homMk f w) := (forget X).epi_of_epi_map ‹_› /-- If `k.left` is a monomorphism, then `k` is a monomorphism. In other words, `Over.forget X` reflects monomorphisms. The converse of `CategoryTheory.Over.mono_left_of_mono`. This lemma is not an instance, to avoid loops in type class inference. -/ theorem mono_of_mono_left {f g : Over X} (k : f ⟶ g) [hk : Mono k.left] : Mono k := (forget X).mono_of_mono_map hk instance mono_homMk {U V : Over X} {f : U.left ⟶ V.left} [Mono f] (w) : Mono (homMk f w) := (forget X).mono_of_mono_map ‹_› /-- If `k` is a monomorphism, then `k.left` is a monomorphism. In other words, `Over.forget X` preserves monomorphisms. The converse of `CategoryTheory.Over.mono_of_mono_left`. -/ instance mono_left_of_mono {f g : Over X} (k : f ⟶ g) [Mono k] : Mono k.left := by refine ⟨fun {Y : T} l m a => ?_⟩ let l' : mk (m ≫ f.hom) ⟶ f := homMk l (by dsimp; rw [← Over.w k, ← Category.assoc, congrArg (· ≫ g.hom) a, Category.assoc]) suffices l' = (homMk m : mk (m ≫ f.hom) ⟶ f) by apply congrArg CommaMorphism.left this rw [← cancel_mono k] ext apply a section IteratedSlice variable (f : Over X) /-- Given f : Y ⟶ X, this is the obvious functor from (T/X)/f to T/Y -/ @[simps] def iteratedSliceForward : Over f ⥤ Over f.left where obj α := Over.mk α.hom.left map κ := Over.homMk κ.left.left (by dsimp; rw [← Over.w κ]; rfl) /-- Given f : Y ⟶ X, this is the obvious functor from T/Y to (T/X)/f -/ @[simps] def iteratedSliceBackward : Over f.left ⥤ Over f where obj g := mk (homMk g.hom : mk (g.hom ≫ f.hom) ⟶ f) map α := homMk (homMk α.left (w_assoc α f.hom)) (OverMorphism.ext (w α)) /-- Given f : Y ⟶ X, we have an equivalence between (T/X)/f and T/Y -/ @[simps] def iteratedSliceEquiv : Over f ≌ Over f.left where functor := iteratedSliceForward f inverse := iteratedSliceBackward f unitIso := NatIso.ofComponents (fun g => Over.isoMk (Over.isoMk (Iso.refl _))) counitIso := NatIso.ofComponents (fun g => Over.isoMk (Iso.refl _)) theorem iteratedSliceForward_forget : iteratedSliceForward f ⋙ forget f.left = forget f ⋙ forget X := rfl theorem iteratedSliceBackward_forget_forget : iteratedSliceBackward f ⋙ forget f ⋙ forget X = forget f.left := rfl end IteratedSlice /-- A functor `F : T ⥤ D` induces a functor `Over X ⥤ Over (F.obj X)` in the obvious way. -/ @[simps] def post (F : T ⥤ D) : Over X ⥤ Over (F.obj X) where obj Y := mk <| F.map Y.hom map f := Over.homMk (F.map f.left) (by simp only [Functor.id_obj, mk_left, Functor.const_obj_obj, mk_hom, ← F.map_comp, w]) lemma post_comp {E : Type*} [Category E] (F : T ⥤ D) (G : D ⥤ E) : post (X := X) (F ⋙ G) = post (X := X) F ⋙ post G := rfl /-- `post (F ⋙ G)` is isomorphic (actually equal) to `post F ⋙ post G`. -/ @[simps!] def postComp {E : Type*} [Category E] (F : T ⥤ D) (G : D ⥤ E) : post (X := X) (F ⋙ G) ≅ post F ⋙ post G := NatIso.ofComponents (fun X ↦ Iso.refl _) /-- A natural transformation `F ⟶ G` induces a natural transformation on `Over X` up to `Over.map`. -/ @[simps] def postMap {F G : T ⥤ D} (e : F ⟶ G) : post F ⋙ map (e.app X) ⟶ post G where app Y := Over.homMk (e.app Y.left) /-- If `F` and `G` are naturally isomorphic, then `Over.post F` and `Over.post G` are also naturally isomorphic up to `Over.map` -/ @[simps!] def postCongr {F G : T ⥤ D} (e : F ≅ G) : post F ⋙ map (e.hom.app X) ≅ post G := NatIso.ofComponents (fun A ↦ Over.isoMk (e.app A.left)) variable (X) (F : T ⥤ D) instance [F.Faithful] : (Over.post (X := X) F).Faithful where map_injective {A B} f g h := by ext exact F.map_injective (congrArg CommaMorphism.left h) instance [F.Faithful] [F.Full] : (Over.post (X := X) F).Full where map_surjective {A B} f := by obtain ⟨a, ha⟩ := F.map_surjective f.left have w : a ≫ B.hom = A.hom := F.map_injective <| by simpa [ha] using Over.w _ exact ⟨Over.homMk a, by ext; simpa⟩ instance [F.Full] [F.EssSurj] : (Over.post (X := X) F).EssSurj where mem_essImage B := by obtain ⟨A', ⟨e⟩⟩ := Functor.EssSurj.mem_essImage (F := F) B.left obtain ⟨f, hf⟩ := F.map_surjective (e.hom ≫ B.hom) exact ⟨Over.mk f, ⟨Over.isoMk e⟩⟩ instance [F.IsEquivalence] : (Over.post (X := X) F).IsEquivalence where /-- If `F` is fully faithful, then so is `Over.post F`. -/ def _root_.CategoryTheory.Functor.FullyFaithful.over (h : F.FullyFaithful) : (post (X := X) F).FullyFaithful where preimage {A B} f := Over.homMk (h.preimage f.left) <| h.map_injective (by simpa using Over.w f) /-- If `G` is a right adjoint, then so is `post G : Over Y ⥤ Over (G Y)`. If the left adjoint of `G` is `F`, then the left adjoint of `post G` is given by `(X ⟶ G Y) ↦ (F X ⟶ F G Y ⟶ Y)`. -/ @[simps] def postAdjunctionRight {Y : D} {F : T ⥤ D} {G : D ⥤ T} (a : F ⊣ G) : post F ⋙ map (a.counit.app Y) ⊣ post G where unit.app A := homMk <| a.unit.app A.left counit.app A := homMk <| a.counit.app A.left instance isRightAdjoint_post {Y : D} {G : D ⥤ T} [G.IsRightAdjoint] : (post (X := Y) G).IsRightAdjoint := let ⟨F, ⟨a⟩⟩ := ‹G.IsRightAdjoint›; ⟨_, ⟨postAdjunctionRight a⟩⟩ /-- An equivalence of categories induces an equivalence on over categories. -/ @[simps] def postEquiv (F : T ≌ D) : Over X ≌ Over (F.functor.obj X) where functor := Over.post F.functor inverse := Over.post (X := F.functor.obj X) F.inverse ⋙ Over.map (F.unitIso.inv.app X) unitIso := NatIso.ofComponents (fun A ↦ Over.isoMk (F.unitIso.app A.left)) counitIso := NatIso.ofComponents (fun A ↦ Over.isoMk (F.counitIso.app A.left)) open Limits variable {X} in /-- If `X : T` is terminal, then the over category of `X` is equivalent to `T`. -/ @[simps] def equivalenceOfIsTerminal (hX : IsTerminal X) : Over X ≌ T where functor := forget X inverse := { obj Y := mk (hX.from Y), map f := homMk f } unitIso := NatIso.ofComponents fun Y ↦ isoMk (.refl _) (hX.hom_ext _ _) counitIso := NatIso.ofComponents fun _ ↦ .refl _ /-- The induced functor to `Over X` from a functor `J ⥤ C` and natural maps `sᵢ : X ⟶ Dᵢ`. For the converse direction see `CategoryTheory.WithTerminal.commaFromOver`. -/ @[simps] protected def lift {J : Type*} [Category J] (D : J ⥤ T) {X : T} (s : D ⟶ (Functor.const J).obj X) : J ⥤ Over X where obj j := mk (s.app j) map f := homMk (D.map f) /-- The induced cone on `Over X` on the lifted functor. -/ @[simps] def liftCone {J : Type*} [Category J] (D : J ⥤ T) {X : T} (s : D ⟶ (Functor.const J).obj X) (c : Cone D) (p : c.pt ⟶ X) (hp : ∀ j, c.π.app j ≫ s.app j = p) : Cone (Over.lift D s) where pt := mk p π.app j := homMk (c.π.app j) /-- The lifted cone on `Over X` is a limit cone if the original cone was limiting and `J` is nonempty. -/ def isLimitLiftCone {J : Type*} [Category J] [Nonempty J] (D : J ⥤ T) {X : T} (s : D ⟶ (Functor.const J).obj X) (c : Cone D) (p : c.pt ⟶ X) (hp : ∀ j, c.π.app j ≫ s.app j = p) (hc : IsLimit c) : IsLimit (Over.liftCone D s c p hp) where lift s := homMk (hc.lift ((forget _).mapCone s)) (by simpa [← hp (Classical.arbitrary J)] using Over.w (s.π.app _)) fac _ _ := by ext; simp [hc.fac] uniq _ _ hm := by ext exact hc.hom_ext fun j ↦ by simpa [hc.fac] using congr($(hm j).left) end Over namespace CostructuredArrow /-- Reinterpreting an `F`-costructured arrow `F.obj d ⟶ X` as an arrow over `X` induces a functor `CostructuredArrow F X ⥤ Over X`. -/ @[simps!] def toOver (F : D ⥤ T) (X : T) : CostructuredArrow F X ⥤ Over X := CostructuredArrow.pre F (𝟭 T) X instance (F : D ⥤ T) (X : T) [F.Faithful] : (toOver F X).Faithful := show (CostructuredArrow.pre _ _ _).Faithful from inferInstance instance (F : D ⥤ T) (X : T) [F.Full] : (toOver F X).Full := show (CostructuredArrow.pre _ _ _).Full from inferInstance instance (F : D ⥤ T) (X : T) [F.EssSurj] : (toOver F X).EssSurj := show (CostructuredArrow.pre _ _ _).EssSurj from inferInstance /-- An equivalence `F` induces an equivalence `CostructuredArrow F X ≌ Over X`. -/ instance isEquivalence_toOver (F : D ⥤ T) (X : T) [F.IsEquivalence] : (toOver F X).IsEquivalence := CostructuredArrow.isEquivalence_pre _ _ _ end CostructuredArrow /-- The under category has as objects arrows with domain `X` and as morphisms commutative triangles. -/ def Under (X : T) := StructuredArrow X (𝟭 T) instance (X : T) : Category (Under X) := commaCategory -- Satisfying the inhabited linter instance Under.inhabited [Inhabited T] : Inhabited (Under (default : T)) where default := { left := default right := default hom := 𝟙 _ } namespace Under variable {X : T} @[ext] theorem UnderMorphism.ext {X : T} {U V : Under X} {f g : U ⟶ V} (h : f.right = g.right) : f = g := by let ⟨_,b,_⟩ := f; let ⟨_,e,_⟩ := g congr; simp only [eq_iff_true_of_subsingleton] @[simp] theorem under_left (U : Under X) : U.left = ⟨⟨⟩⟩ := by simp only @[simp] theorem id_right (U : Under X) : CommaMorphism.right (𝟙 U) = 𝟙 U.right := rfl @[simp] theorem comp_right (a b c : Under X) (f : a ⟶ b) (g : b ⟶ c) : (f ≫ g).right = f.right ≫ g.right := rfl @[reassoc (attr := simp)] theorem w {A B : Under X} (f : A ⟶ B) : A.hom ≫ f.right = B.hom := by have := f.w; cat_disch /-- To give an object in the under category, it suffices to give an arrow with domain `X`. -/ @[simps! right hom] def mk {X Y : T} (f : X ⟶ Y) : Under X := StructuredArrow.mk f /-- To give a morphism in the under category, it suffices to give a morphism fitting in a commutative triangle. -/ @[simps! right] def homMk {U V : Under X} (f : U.right ⟶ V.right) (w : U.hom ≫ f = V.hom := by cat_disch) : U ⟶ V := StructuredArrow.homMk f w @[simp] lemma homMk_eta {U V : Under X} (f : U ⟶ V) (h) : homMk f.right h = f := rfl /-- This is useful when `homMk (· ≫ ·)` appears under `Functor.map` or a natural equivalence. -/ lemma homMk_comp {U V W : Under X} (f : U.right ⟶ V.right) (g : V.right ⟶ W.right) (w_f w_g) : homMk (f ≫ g) (by simp only [reassoc_of% w_f, w_g]) = homMk f w_f ≫ homMk g w_g := by ext simp /-- Construct an isomorphism in the over category given isomorphisms of the objects whose forward direction gives a commutative triangle. -/ def isoMk {f g : Under X} (hr : f.right ≅ g.right) (hw : f.hom ≫ hr.hom = g.hom := by cat_disch) : f ≅ g := StructuredArrow.isoMk hr hw @[simp] theorem isoMk_hom_right {f g : Under X} (hr : f.right ≅ g.right) (hw : f.hom ≫ hr.hom = g.hom) : (isoMk hr hw).hom.right = hr.hom := rfl @[simp] theorem isoMk_inv_right {f g : Under X} (hr : f.right ≅ g.right) (hw : f.hom ≫ hr.hom = g.hom) : (isoMk hr hw).inv.right = hr.inv := rfl @[reassoc (attr := simp)] lemma hom_right_inv_right {f g : Under X} (e : f ≅ g) : e.hom.right ≫ e.inv.right = 𝟙 f.right := by simp [← Under.comp_right] @[reassoc (attr := simp)] lemma inv_right_hom_right {f g : Under X} (e : f ≅ g) : e.inv.right ≫ e.hom.right = 𝟙 g.right := by simp [← Under.comp_right] lemma forall_iff (P : Under X → Prop) : (∀ Y, P Y) ↔ (∀ (Y) (f : X ⟶ Y), P (.mk f)) := by aesop section variable (X) /-- The forgetful functor mapping an arrow to its domain. -/ def forget : Under X ⥤ T := Comma.snd _ _ end @[simp] theorem forget_obj {U : Under X} : (forget X).obj U = U.right := rfl @[simp] theorem forget_map {U V : Under X} {f : U ⟶ V} : (forget X).map f = f.right := rfl /-- The natural cone over the forgetful functor `Under X ⥤ T` with cone point `X`. -/ @[simps] def forgetCone (X : T) : Limits.Cone (forget X) := { pt := X π := { app := Comma.hom } } /-- A morphism `X ⟶ Y` induces a functor `Under Y ⥤ Under X` in the obvious way. -/ def map {Y : T} (f : X ⟶ Y) : Under Y ⥤ Under X := Comma.mapLeft _ <| Discrete.natTrans fun _ => f section variable {Y : T} {f : X ⟶ Y} {U V : Under Y} {g : U ⟶ V} @[simp] theorem map_obj_right : ((map f).obj U).right = U.right := rfl @[simp] theorem map_obj_hom : ((map f).obj U).hom = f ≫ U.hom := rfl @[simp] theorem map_map_right : ((map f).map g).right = g.right := rfl /-- If `f` is an isomorphism, `map f` is an equivalence of categories. -/ def mapIso (f : X ≅ Y) : Under Y ≌ Under X := Comma.mapLeftIso _ <| Discrete.natIso fun _ ↦ f.symm @[simp] lemma mapIso_functor (f : X ≅ Y) : (mapIso f).functor = map f.hom := rfl @[simp] lemma mapIso_inverse (f : X ≅ Y) : (mapIso f).inverse = map f.inv := rfl instance [IsIso f] : (Under.map f).IsEquivalence := (Under.mapIso <| asIso f).isEquivalence_functor end section coherences /-! This section proves various equalities between functors that demonstrate, for instance, that under categories assemble into a functor `mapFunctor : Tᵒᵖ ⥤ Cat`. -/ /-- Mapping by the identity morphism is just the identity functor. -/ theorem mapId_eq (Y : T) : map (𝟙 Y) = 𝟭 _ := by fapply Functor.ext · intro x dsimp [Under, Under.map, Comma.mapLeft] simp only [Category.id_comp] exact rfl · intro x y u dsimp [Under, Under.map, Comma.mapLeft] simp /-- Mapping by the identity morphism is just the identity functor. -/ @[simps!] def mapId (Y : T) : map (𝟙 Y) ≅ 𝟭 _ := eqToIso (mapId_eq Y) /-- Mapping by `f` and then forgetting is the same as forgetting. -/ theorem mapForget_eq {X Y : T} (f : X ⟶ Y) : (map f) ⋙ (forget X) = (forget Y) := rfl /-- The natural isomorphism arising from `mapForget_eq`. -/ def mapForget {X Y : T} (f : X ⟶ Y) : (map f) ⋙ (forget X) ≅ (forget Y) := eqToIso (mapForget_eq f) @[simp] theorem eqToHom_right {X : T} {U V : Under X} (e : U = V) : (eqToHom e).right = eqToHom (e ▸ rfl : U.right = V.right) := by subst e; rfl /-- Mapping by the composite morphism `f ≫ g` is the same as mapping by `f` then by `g`. -/ theorem mapComp_eq {X Y Z : T} (f : X ⟶ Y) (g : Y ⟶ Z) : map (f ≫ g) = (map g) ⋙ (map f) := by fapply Functor.ext · simp [Under.map, Comma.mapLeft] · intro U V k ext simp /-- The natural isomorphism arising from `mapComp_eq`. -/ @[simps!] def mapComp {Y Z : T} (f : X ⟶ Y) (g : Y ⟶ Z) : map (f ≫ g) ≅ map g ⋙ map f := eqToIso (mapComp_eq f g) /-- If `f = g`, then `map f` is naturally isomorphic to `map g`. -/ @[simps!] def mapCongr {X Y : T} (f g : X ⟶ Y) (h : f = g) : map f ≅ map g := NatIso.ofComponents (fun A ↦ eqToIso (by rw [h])) variable (T) in /-- The functor defined by the under categories -/ @[simps] def mapFunctor : Tᵒᵖ ⥤ Cat where obj X := Cat.of (Under X.unop) map f := map f.unop map_id X := mapId_eq X.unop map_comp f g := mapComp_eq (g.unop) (f.unop) end coherences instance forget_reflects_iso : (forget X).ReflectsIsomorphisms where reflects {Y Z} f t := by let g : Z ⟶ Y := Under.homMk (inv ((Under.forget X).map f)) ((IsIso.comp_inv_eq _).2 (Under.w f).symm) dsimp [forget] at t refine ⟨⟨g, ⟨?_,?_⟩⟩⟩ repeat (ext; simp [g]) /-- The identity under `X` is initial. -/ noncomputable def mkIdInitial : Limits.IsInitial (mk (𝟙 X)) := StructuredArrow.mkIdInitial instance forget_faithful : (forget X).Faithful where -- TODO: Show the converse holds if `T` has binary coproducts. /-- If `k.right` is a monomorphism, then `k` is a monomorphism. In other words, `Under.forget X` reflects epimorphisms. The converse does not hold without additional assumptions on the underlying category, see `CategoryTheory.Under.mono_right_of_mono`. -/ theorem mono_of_mono_right {f g : Under X} (k : f ⟶ g) [hk : Mono k.right] : Mono k := (forget X).mono_of_mono_map hk instance mono_homMk {U V : Under X} {f : U.right ⟶ V.right} [Mono f] (w) : Mono (homMk f w) := (forget X).mono_of_mono_map ‹_› /-- If `k.right` is an epimorphism, then `k` is an epimorphism. In other words, `Under.forget X` reflects epimorphisms. The converse of `CategoryTheory.Under.epi_right_of_epi`. This lemma is not an instance, to avoid loops in type class inference. -/ theorem epi_of_epi_right {f g : Under X} (k : f ⟶ g) [hk : Epi k.right] : Epi k := (forget X).epi_of_epi_map hk instance epi_homMk {U V : Under X} {f : U.right ⟶ V.right} [Epi f] (w) : Epi (homMk f w) := (forget X).epi_of_epi_map ‹_› /-- If `k` is an epimorphism, then `k.right` is an epimorphism. In other words, `Under.forget X` preserves epimorphisms. The converse of `CategoryTheory.under.epi_of_epi_right`. -/ instance epi_right_of_epi {f g : Under X} (k : f ⟶ g) [Epi k] : Epi k.right := by refine ⟨fun {Y : T} l m a => ?_⟩ let l' : g ⟶ mk (g.hom ≫ m) := homMk l (by dsimp; rw [← Under.w k, Category.assoc, a, Category.assoc]) suffices l' = (homMk m) by apply congrArg CommaMorphism.right this rw [← cancel_epi k]; ext; apply a /-- A functor `F : T ⥤ D` induces a functor `Under X ⥤ Under (F.obj X)` in the obvious way. -/ @[simps] def post {X : T} (F : T ⥤ D) : Under X ⥤ Under (F.obj X) where obj Y := mk <| F.map Y.hom map f := Under.homMk (F.map f.right) (by simp only [Functor.id_obj, Functor.const_obj_obj, mk_right, mk_hom, ← F.map_comp, w]) lemma post_comp {E : Type*} [Category E] (F : T ⥤ D) (G : D ⥤ E) : post (X := X) (F ⋙ G) = post (X := X) F ⋙ post G := rfl /-- `post (F ⋙ G)` is isomorphic (actually equal) to `post F ⋙ post G`. -/ @[simps!] def postComp {E : Type*} [Category E] (F : T ⥤ D) (G : D ⥤ E) : post (X := X) (F ⋙ G) ≅ post F ⋙ post G := NatIso.ofComponents (fun X ↦ Iso.refl _) /-- A natural transformation `F ⟶ G` induces a natural transformation on `Under X` up to `Under.map`. -/ @[simps] def postMap {F G : T ⥤ D} (e : F ⟶ G) : post (X := X) F ⟶ post G ⋙ map (e.app X) where app Y := Under.homMk (e.app Y.right) /-- If `F` and `G` are naturally isomorphic, then `Under.post F` and `Under.post G` are also naturally isomorphic up to `Under.map` -/ @[simps!] def postCongr {F G : T ⥤ D} (e : F ≅ G) : post F ≅ post G ⋙ map (e.hom.app X) := NatIso.ofComponents (fun A ↦ Under.isoMk (e.app A.right)) variable (X) (F : T ⥤ D) instance [F.Faithful] : (Under.post (X := X) F).Faithful where map_injective {A B} f g h := by ext exact F.map_injective (congrArg CommaMorphism.right h) instance [F.Faithful] [F.Full] : (Under.post (X := X) F).Full where map_surjective {A B} f := by obtain ⟨a, ha⟩ := F.map_surjective f.right dsimp at a have w : A.hom ≫ a = B.hom := F.map_injective <| by simpa [ha] using Under.w f exact ⟨Under.homMk a, by ext; simpa⟩ instance [F.Full] [F.EssSurj] : (Under.post (X := X) F).EssSurj where mem_essImage B := by obtain ⟨B', ⟨e⟩⟩ := Functor.EssSurj.mem_essImage (F := F) B.right obtain ⟨f, hf⟩ := F.map_surjective (B.hom ≫ e.inv) exact ⟨Under.mk f, ⟨Under.isoMk e⟩⟩ instance [F.IsEquivalence] : (Under.post (X := X) F).IsEquivalence where /-- If `F` is fully faithful, then so is `Under.post F`. -/ def _root_.CategoryTheory.Functor.FullyFaithful.under (h : F.FullyFaithful) : (post (X := X) F).FullyFaithful where preimage {A B} f := Under.homMk (h.preimage f.right) <| h.map_injective (by simpa using Under.w f) /-- If `F` is a left adjoint, then so is `post F : Under X ⥤ Under (F X)`. If the right adjoint of `F` is `G`, then the right adjoint of `post F` is given by `(F X ⟶ Y) ↦ (X ⟶ G F X ⟶ G Y)`. -/ @[simps] def postAdjunctionLeft {X : T} {F : T ⥤ D} {G : D ⥤ T} (a : F ⊣ G) : post F ⊣ post G ⋙ map (a.unit.app X) where unit.app A := homMk <| a.unit.app A.right counit.app A := homMk <| a.counit.app A.right instance isLeftAdjoint_post [F.IsLeftAdjoint] : (post (X := X) F).IsLeftAdjoint := let ⟨G, ⟨a⟩⟩ := ‹F.IsLeftAdjoint›; ⟨_, ⟨postAdjunctionLeft a⟩⟩ /-- An equivalence of categories induces an equivalence on under categories. -/ @[simps] def postEquiv (F : T ≌ D) : Under X ≌ Under (F.functor.obj X) where functor := post F.functor inverse := post (X := F.functor.obj X) F.inverse ⋙ Under.map (F.unitIso.hom.app X) unitIso := NatIso.ofComponents (fun A ↦ Under.isoMk (F.unitIso.app A.right)) counitIso := NatIso.ofComponents (fun A ↦ Under.isoMk (F.counitIso.app A.right)) open Limits variable {X} in /-- If `X : T` is initial, then the under category of `X` is equivalent to `T`. -/ @[simps] def equivalenceOfIsInitial (hX : IsInitial X) : Under X ≌ T where functor := forget X inverse := { obj Y := mk (hX.to Y), map f := homMk f } unitIso := NatIso.ofComponents fun Y ↦ isoMk (.refl _) (hX.hom_ext _ _) counitIso := NatIso.ofComponents fun _ ↦ .refl _ /-- The induced functor to `Under X` from a functor `J ⥤ C` and natural maps `sᵢ : X ⟶ Dᵢ`. -/ @[simps] protected def lift {J : Type*} [Category J] (D : J ⥤ T) {X : T} (s : (Functor.const J).obj X ⟶ D) : J ⥤ Under X where obj j := .mk (s.app j) map f := Under.homMk (D.map f) (by simpa using (s.naturality f).symm) /-- The induced cocone on `Under X` from on the lifted functor. -/ @[simps] def liftCocone {J : Type*} [Category J] (D : J ⥤ T) {X : T} (s : (Functor.const J).obj X ⟶ D) (c : Cocone D) (p : X ⟶ c.pt) (hp : ∀ j, s.app j ≫ c.ι.app j = p) : Cocone (Under.lift D s) where pt := mk p ι.app j := homMk (c.ι.app j) /-- The lifted cocone on `Under X` is a colimit cocone if the original cocone was colimiting and `J` is nonempty. -/ def isColimitLiftCocone {J : Type*} [Category J] [Nonempty J] (D : J ⥤ T) {X : T} (s : (Functor.const J).obj X ⟶ D) (c : Cocone D) (p : X ⟶ c.pt) (hp : ∀ j, s.app j ≫ c.ι.app j = p) (hc : IsColimit c) : IsColimit (liftCocone D s c p hp) where desc s := Under.homMk (hc.desc ((Under.forget _).mapCocone s)) (by simpa [← hp (Classical.arbitrary _)] using Under.w (s.ι.app _)) fac _ _ := by ext; simp [hc.fac] uniq _ _ hm := by ext exact hc.hom_ext fun j ↦ by simpa [hc.fac] using congr($(hm j).right) end Under namespace StructuredArrow variable {D : Type u₂} [Category.{v₂} D] /-- Reinterpreting an `F`-structured arrow `X ⟶ F.obj d` as an arrow under `X` induces a functor `StructuredArrow X F ⥤ Under X`. -/ @[simps!] def toUnder (X : T) (F : D ⥤ T) : StructuredArrow X F ⥤ Under X := StructuredArrow.pre X F (𝟭 T) instance (X : T) (F : D ⥤ T) [F.Faithful] : (toUnder X F).Faithful := show (StructuredArrow.pre _ _ _).Faithful from inferInstance instance (X : T) (F : D ⥤ T) [F.Full] : (toUnder X F).Full := show (StructuredArrow.pre _ _ _).Full from inferInstance instance (X : T) (F : D ⥤ T) [F.EssSurj] : (toUnder X F).EssSurj := show (StructuredArrow.pre _ _ _).EssSurj from inferInstance /-- An equivalence `F` induces an equivalence `StructuredArrow X F ≌ Under X`. -/ instance isEquivalence_toUnder (X : T) (F : D ⥤ T) [F.IsEquivalence] : (toUnder X F).IsEquivalence := StructuredArrow.isEquivalence_pre _ _ _ end StructuredArrow namespace Functor variable {X : T} {F : T ⥤ D} lemma essImage.of_overPost {Y : Over (F.obj X)} : (Over.post F (X := X)).essImage Y → F.essImage Y.left := fun ⟨Z, ⟨e⟩⟩ ↦ ⟨Z.left, ⟨(Over.forget _).mapIso e⟩⟩ lemma essImage.of_underPost {Y : Under (F.obj X)} : (Under.post F (X := X)).essImage Y → F.essImage Y.right := fun ⟨Z, ⟨e⟩⟩ ↦ ⟨Z.right, ⟨(Under.forget _).mapIso e⟩⟩ /-- The essential image of `Over.post F` where `F` is full is the same as the essential image of `F`. -/ @[simp] lemma essImage_overPost [F.Full] {Y : Over (F.obj X)} : (Over.post F (X := X)).essImage Y ↔ F.essImage Y.left where mp := .of_overPost mpr := fun ⟨Z, ⟨e⟩⟩ ↦ let ⟨f, hf⟩ := F.map_surjective (e.hom ≫ Y.hom); ⟨.mk f, ⟨Over.isoMk e⟩⟩ /-- The essential image of `Under.post F` where `F` is full is the same as the essential image of `F`. -/ @[simp] lemma essImage_underPost [F.Full] {Y : Under (F.obj X)} : (Under.post F (X := X)).essImage Y ↔ F.essImage Y.right where mp := .of_underPost mpr := fun ⟨Z, ⟨e⟩⟩ ↦ let ⟨f, hf⟩ := F.map_surjective (Y.hom ≫ e.inv); ⟨.mk f, ⟨Under.isoMk e⟩⟩ variable {S : Type u₂} [Category.{v₂} S] /-- Given `X : T`, to upgrade a functor `F : S ⥤ T` to a functor `S ⥤ Over X`, it suffices to provide maps `F.obj Y ⟶ X` for all `Y` making the obvious triangles involving all `F.map g` commute. -/ @[simps! obj_left map_left] def toOver (F : S ⥤ T) (X : T) (f : (Y : S) → F.obj Y ⟶ X) (h : ∀ {Y Z : S} (g : Y ⟶ Z), F.map g ≫ f Z = f Y) : S ⥤ Over X := F.toCostructuredArrow (𝟭 _) X f h /-- Upgrading a functor `S ⥤ T` to a functor `S ⥤ Over X` and composing with the forgetful functor `Over X ⥤ T` recovers the original functor. -/ def toOverCompForget (F : S ⥤ T) (X : T) (f : (Y : S) → F.obj Y ⟶ X) (h : ∀ {Y Z : S} (g : Y ⟶ Z), F.map g ≫ f Z = f Y) : F.toOver X f h ⋙ Over.forget _ ≅ F := Iso.refl _ @[simp] lemma toOver_comp_forget (F : S ⥤ T) (X : T) (f : (Y : S) → F.obj Y ⟶ X) (h : ∀ {Y Z : S} (g : Y ⟶ Z), F.map g ≫ f Z = f Y) : F.toOver X f h ⋙ Over.forget _ = F := rfl /-- Given `X : T`, to upgrade a functor `F : S ⥤ T` to a functor `S ⥤ Under X`, it suffices to provide maps `X ⟶ F.obj Y` for all `Y` making the obvious triangles involving all `F.map g` commute. -/ @[simps! obj_right map_right] def toUnder (F : S ⥤ T) (X : T) (f : (Y : S) → X ⟶ F.obj Y) (h : ∀ {Y Z : S} (g : Y ⟶ Z), f Y ≫ F.map g = f Z) : S ⥤ Under X := F.toStructuredArrow X (𝟭 _) f h /-- Upgrading a functor `S ⥤ T` to a functor `S ⥤ Under X` and composing with the forgetful functor `Under X ⥤ T` recovers the original functor. -/ def toUnderCompForget (F : S ⥤ T) (X : T) (f : (Y : S) → X ⟶ F.obj Y) (h : ∀ {Y Z : S} (g : Y ⟶ Z), f Y ≫ F.map g = f Z) : F.toUnder X f h ⋙ Under.forget _ ≅ F := Iso.refl _ @[simp] lemma toUnder_comp_forget (F : S ⥤ T) (X : T) (f : (Y : S) → X ⟶ F.obj Y) (h : ∀ {Y Z : S} (g : Y ⟶ Z), f Y ≫ F.map g = f Z) : F.toUnder X f h ⋙ Under.forget _ = F := rfl end Functor namespace StructuredArrow /-- A functor from the structured arrow category on the projection functor for any structured arrow category. -/ @[simps!] def ofStructuredArrowProjEquivalence.functor (F : D ⥤ T) (Y : T) (X : D) : StructuredArrow X (StructuredArrow.proj Y F) ⥤ StructuredArrow Y (Under.forget X ⋙ F) := Functor.toStructuredArrow (Functor.toUnder (StructuredArrow.proj X _ ⋙ StructuredArrow.proj Y _) _ (fun g => by exact g.hom) (fun m => by have := m.w; cat_disch)) _ _ (fun f => f.right.hom) (by simp) /-- The inverse functor of `ofStructuredArrowProjEquivalence.functor`. -/ @[simps!] def ofStructuredArrowProjEquivalence.inverse (F : D ⥤ T) (Y : T) (X : D) : StructuredArrow Y (Under.forget X ⋙ F) ⥤ StructuredArrow X (StructuredArrow.proj Y F) := Functor.toStructuredArrow (Functor.toStructuredArrow (StructuredArrow.proj Y _ ⋙ Under.forget X) _ _ (fun g => by exact g.hom) (fun m => by have := m.w; cat_disch)) _ _ (fun f => f.right.hom) (by simp) /-- Characterization of the structured arrow category on the projection functor of any structured arrow category. -/ def ofStructuredArrowProjEquivalence (F : D ⥤ T) (Y : T) (X : D) : StructuredArrow X (StructuredArrow.proj Y F) ≌ StructuredArrow Y (Under.forget X ⋙ F) where functor := ofStructuredArrowProjEquivalence.functor F Y X inverse := ofStructuredArrowProjEquivalence.inverse F Y X unitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by cat_disch) /-- The canonical functor from the structured arrow category on the diagonal functor `T ⥤ T × T` to the structured arrow category on `Under.forget`. -/ @[simps!] def ofDiagEquivalence.functor (X : T × T) : StructuredArrow X (Functor.diag _) ⥤ StructuredArrow X.2 (Under.forget X.1) := Functor.toStructuredArrow (Functor.toUnder (StructuredArrow.proj X _) _ (fun f => by exact f.hom.1) (fun m => by have := m.w; cat_disch)) _ _ (fun f => f.hom.2) (fun m => by have := m.w; cat_disch) /-- The inverse functor of `ofDiagEquivalence.functor`. -/ @[simps!] def ofDiagEquivalence.inverse (X : T × T) : StructuredArrow X.2 (Under.forget X.1) ⥤ StructuredArrow X (Functor.diag _) := Functor.toStructuredArrow (StructuredArrow.proj _ _ ⋙ Under.forget _) _ _ (fun f => (f.right.hom, f.hom)) (fun m => by have := m.w; cat_disch) /-- Characterization of the structured arrow category on the diagonal functor `T ⥤ T × T`. -/ def ofDiagEquivalence (X : T × T) : StructuredArrow X (Functor.diag _) ≌ StructuredArrow X.2 (Under.forget X.1) where functor := ofDiagEquivalence.functor X inverse := ofDiagEquivalence.inverse X unitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by cat_disch) /-- A version of `StructuredArrow.ofDiagEquivalence` with the roles of the first and second projection swapped. -/ -- noncomputability is only for performance noncomputable def ofDiagEquivalence' (X : T × T) : StructuredArrow X (Functor.diag _) ≌ StructuredArrow X.1 (Under.forget X.2) := (ofDiagEquivalence X).trans <| (ofStructuredArrowProjEquivalence (𝟭 T) X.1 X.2).trans <| StructuredArrow.mapNatIso (Under.forget X.2).rightUnitor section CommaFst variable {C : Type u₃} [Category.{v₃} C] (F : C ⥤ T) (G : D ⥤ T) /-- The functor used to define the equivalence `ofCommaSndEquivalence`. -/ @[simps] def ofCommaSndEquivalenceFunctor (c : C) : StructuredArrow c (Comma.fst F G) ⥤ Comma (Under.forget c ⋙ F) G where obj X := ⟨Under.mk X.hom, X.right.right, X.right.hom⟩ map f := ⟨Under.homMk f.right.left (by simpa using f.w.symm), f.right.right, by simp⟩ /-- The inverse functor used to define the equivalence `ofCommaSndEquivalence`. -/ @[simps!] def ofCommaSndEquivalenceInverse (c : C) : Comma (Under.forget c ⋙ F) G ⥤ StructuredArrow c (Comma.fst F G) := Functor.toStructuredArrow (Comma.preLeft (Under.forget c) F G) _ _ (fun Y => Y.left.hom) (fun _ => by simp) /-- There is a canonical equivalence between the structured arrow category with domain `c` on the functor `Comma.fst F G : Comma F G ⥤ F` and the comma category over `Under.forget c ⋙ F : Under c ⥤ T` and `G`. -/ @[simps] def ofCommaSndEquivalence (c : C) : StructuredArrow c (Comma.fst F G) ≌ Comma (Under.forget c ⋙ F) G where functor := ofCommaSndEquivalenceFunctor F G c inverse := ofCommaSndEquivalenceInverse F G c unitIso := NatIso.ofComponents (fun _ => Iso.refl _) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) end CommaFst end StructuredArrow namespace CostructuredArrow /-- A functor from the costructured arrow category on the projection functor for any costructured arrow category. -/ @[simps!] def ofCostructuredArrowProjEquivalence.functor (F : T ⥤ D) (Y : D) (X : T) : CostructuredArrow (CostructuredArrow.proj F Y) X ⥤ CostructuredArrow (Over.forget X ⋙ F) Y := Functor.toCostructuredArrow (Functor.toOver (CostructuredArrow.proj _ X ⋙ CostructuredArrow.proj F Y) _ (fun g => by exact g.hom) (fun m => by have := m.w; cat_disch)) _ _ (fun f => f.left.hom) (by simp) /-- The inverse functor of `ofCostructuredArrowProjEquivalence.functor`. -/ @[simps!] def ofCostructuredArrowProjEquivalence.inverse (F : T ⥤ D) (Y : D) (X : T) : CostructuredArrow (Over.forget X ⋙ F) Y ⥤ CostructuredArrow (CostructuredArrow.proj F Y) X := Functor.toCostructuredArrow (Functor.toCostructuredArrow (CostructuredArrow.proj _ Y ⋙ Over.forget X) _ _ (fun g => by exact g.hom) (fun m => by have := m.w; cat_disch)) _ _ (fun f => f.left.hom) (by simp) /-- Characterization of the costructured arrow category on the projection functor of any costructured arrow category. -/ def ofCostructuredArrowProjEquivalence (F : T ⥤ D) (Y : D) (X : T) : CostructuredArrow (CostructuredArrow.proj F Y) X ≌ CostructuredArrow (Over.forget X ⋙ F) Y where functor := ofCostructuredArrowProjEquivalence.functor F Y X inverse := ofCostructuredArrowProjEquivalence.inverse F Y X unitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by cat_disch) /-- The canonical functor from the costructured arrow category on the diagonal functor `T ⥤ T × T` to the costructured arrow category on `Under.forget`. -/ @[simps!] def ofDiagEquivalence.functor (X : T × T) : CostructuredArrow (Functor.diag _) X ⥤ CostructuredArrow (Over.forget X.1) X.2 := Functor.toCostructuredArrow (Functor.toOver (CostructuredArrow.proj _ X) _ (fun g => by exact g.hom.1) (fun m => by have := congrArg (·.1) m.w; cat_disch)) _ _ (fun f => f.hom.2) (fun m => by have := congrArg (·.2) m.w; cat_disch) /-- The inverse functor of `ofDiagEquivalence.functor`. -/ @[simps!] def ofDiagEquivalence.inverse (X : T × T) : CostructuredArrow (Over.forget X.1) X.2 ⥤ CostructuredArrow (Functor.diag _) X := Functor.toCostructuredArrow (CostructuredArrow.proj _ _ ⋙ Over.forget _) _ X (fun f => (f.left.hom, f.hom)) (fun m => by have := m.w; cat_disch) /-- Characterization of the costructured arrow category on the diagonal functor `T ⥤ T × T`. -/ def ofDiagEquivalence (X : T × T) : CostructuredArrow (Functor.diag _) X ≌ CostructuredArrow (Over.forget X.1) X.2 where functor := ofDiagEquivalence.functor X inverse := ofDiagEquivalence.inverse X unitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by cat_disch) /-- A version of `CostructuredArrow.ofDiagEquivalence` with the roles of the first and second projection swapped. -/ -- noncomputability is only for performance noncomputable def ofDiagEquivalence' (X : T × T) : CostructuredArrow (Functor.diag _) X ≌ CostructuredArrow (Over.forget X.2) X.1 := (ofDiagEquivalence X).trans <| (ofCostructuredArrowProjEquivalence (𝟭 T) X.1 X.2).trans <| CostructuredArrow.mapNatIso (Over.forget X.2).rightUnitor section CommaFst variable {C : Type u₃} [Category.{v₃} C] (F : C ⥤ T) (G : D ⥤ T) /-- The functor used to define the equivalence `ofCommaFstEquivalence`. -/ @[simps] def ofCommaFstEquivalenceFunctor (c : C) : CostructuredArrow (Comma.fst F G) c ⥤ Comma (Over.forget c ⋙ F) G where obj X := ⟨Over.mk X.hom, X.left.right, X.left.hom⟩ map f := ⟨Over.homMk f.left.left (by simpa using f.w), f.left.right, by simp⟩ /-- The inverse functor used to define the equivalence `ofCommaFstEquivalence`. -/ @[simps!] def ofCommaFstEquivalenceInverse (c : C) : Comma (Over.forget c ⋙ F) G ⥤ CostructuredArrow (Comma.fst F G) c := Functor.toCostructuredArrow (Comma.preLeft (Over.forget c) F G) _ _ (fun Y => Y.left.hom) (fun _ => by simp) /-- There is a canonical equivalence between the costructured arrow category with codomain `c` on the functor `Comma.fst F G : Comma F G ⥤ F` and the comma category over `Over.forget c ⋙ F : Over c ⥤ T` and `G`. -/ @[simps] def ofCommaFstEquivalence (c : C) : CostructuredArrow (Comma.fst F G) c ≌ Comma (Over.forget c ⋙ F) G where functor := ofCommaFstEquivalenceFunctor F G c inverse := ofCommaFstEquivalenceInverse F G c unitIso := NatIso.ofComponents (fun _ => Iso.refl _) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) end CommaFst end CostructuredArrow section Opposite open Opposite variable (X : T) /-- The canonical equivalence between over and under categories by reversing structure arrows. -/ @[simps] def Over.opEquivOpUnder : Over (op X) ≌ (Under X)ᵒᵖ where functor.obj Y := ⟨Under.mk Y.hom.unop⟩ functor.map {Z Y} f := ⟨Under.homMk (f.left.unop) (by dsimp; rw [← unop_comp, Over.w])⟩ inverse.obj Y := Over.mk (Y.unop.hom.op) inverse.map {Z Y} f := Over.homMk f.unop.right.op <| by dsimp; rw [← Under.w f.unop, op_comp] unitIso := Iso.refl _ counitIso := Iso.refl _ /-- The canonical equivalence between under and over categories by reversing structure arrows. -/ @[simps] def Under.opEquivOpOver : Under (op X) ≌ (Over X)ᵒᵖ where functor.obj Y := ⟨Over.mk Y.hom.unop⟩ functor.map {Z Y} f := ⟨Over.homMk (f.right.unop) (by dsimp; rw [← unop_comp, Under.w])⟩ inverse.obj Y := Under.mk (Y.unop.hom.op) inverse.map {Z Y} f := Under.homMk f.unop.left.op <| by dsimp; rw [← Over.w f.unop, op_comp] unitIso := Iso.refl _ counitIso := Iso.refl _ end Opposite end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Over/OverClass.lean
import Mathlib.Tactic.CategoryTheory.Reassoc import Mathlib.CategoryTheory.Comma.Over.Basic /-! # Typeclasses for `S`-objects and `S`-morphisms **Warning**: This is not usually how typeclasses should be used. This is only a sensible approach when the morphism is considered as a structure on `X`, typically in algebraic geometry. This is analogous to how we view ringhoms as structures via the `Algebra` typeclass. For other applications use unbundled arrows or `CategoryTheory.Over`. ## Main definition - `CategoryTheory.OverClass`: `OverClass X S` equips `X` with a morphism into `S`. `X ↘ S : X ⟶ S` is the structure morphism. - `CategoryTheory.HomIsOver`: `HomIsOver f S` asserts that `f` commutes with the structure morphisms. -/ namespace CategoryTheory universe v u variable {C : Type u} [Category.{v} C] variable {X Y Z : C} (f : X ⟶ Y) (S S' : C) /-- `OverClass X S` is the typeclass containing the data of a structure morphism `X ↘ S : X ⟶ S`. -/ class OverClass (X S : C) : Type v where ofHom :: /-- The structure morphism. Use `X ↘ S` instead. -/ hom : X ⟶ S /-- The structure morphism `X ↘ S : X ⟶ S` given `OverClass X S`. The instance argument is an `optParam` instead so that it appears in the discrimination tree. -/ def over (X S : C) (_ : OverClass X S := by infer_instance) : X ⟶ S := OverClass.hom /-- The structure morphism `X ↘ S : X ⟶ S` given `OverClass X S`. -/ notation:90 X:90 " ↘ " S:90 => CategoryTheory.over X S inferInstance /-- See Note [custom simps projection] -/ def OverClass.Simps.over (X S : C) [OverClass X S] : X ⟶ S := X ↘ S initialize_simps_projections OverClass (hom → over) /-- `X.CanonicallyOverClass S` is the typeclass containing the data of a structure morphism `X ↘ S : X ⟶ S`, and that `S` is (uniquely) inferable from the structure of `X`. -/ class CanonicallyOverClass (X : C) (S : semiOutParam C) extends OverClass X S where /-- See Note [custom simps projection] -/ def CanonicallyOverClass.Simps.over (X S : C) [CanonicallyOverClass X S] : X ⟶ S := X ↘ S initialize_simps_projections CanonicallyOverClass (hom → over) @[simps] instance : OverClass X X := ⟨𝟙 _⟩ instance : IsIso (S ↘ S) := inferInstanceAs (IsIso (𝟙 S)) namespace CanonicallyOverClass -- This cannot be a simp lemma be cause it loops with `comp_over`. @[simps -isSimp] instance (priority := 900) [CanonicallyOverClass X Y] [OverClass Y S] : OverClass X S := ⟨X ↘ Y ≫ Y ↘ S⟩ end CanonicallyOverClass /-- Given `OverClass X S` and `OverClass Y S` and `f : X ⟶ Y`, `HomIsOver f S` is the typeclass asserting `f` commutes with the structure morphisms. -/ class HomIsOver (f : X ⟶ Y) (S : C) [OverClass X S] [OverClass Y S] : Prop where comp_over : f ≫ Y ↘ S = X ↘ S := by aesop @[reassoc (attr := simp)] lemma comp_over [OverClass X S] [OverClass Y S] [HomIsOver f S] : f ≫ Y ↘ S = X ↘ S := HomIsOver.comp_over instance [OverClass X S] : HomIsOver (𝟙 X) S where instance [OverClass X S] [OverClass Y S] [OverClass Z S] (f : X ⟶ Y) (g : Y ⟶ Z) [HomIsOver f S] [HomIsOver g S] : HomIsOver (f ≫ g) S where /-- `IsOverTower X Y S` is the typeclass asserting that the structure morphisms `X ↘ Y`, `Y ↘ S`, and `X ↘ S` commute. -/ abbrev IsOverTower (X Y S : C) [OverClass X S] [OverClass Y S] [OverClass X Y] := HomIsOver (X ↘ Y) S instance [OverClass X S] : IsOverTower X X S where instance [OverClass X S] : IsOverTower X S S where instance [CanonicallyOverClass X Y] [OverClass Y S] : IsOverTower X Y S := ⟨rfl⟩ lemma homIsOver_of_isOverTower [OverClass X S] [OverClass X S'] [OverClass Y S] [OverClass Y S'] [OverClass S S'] [IsOverTower X S S'] [IsOverTower Y S S'] [HomIsOver f S] : HomIsOver f S' := by constructor rw [← comp_over (Y ↘ S), comp_over_assoc f, comp_over] instance [CanonicallyOverClass X S] [OverClass X S'] [OverClass Y S] [OverClass Y S'] [OverClass S S'] [IsOverTower X S S'] [IsOverTower Y S S'] [HomIsOver f S] : HomIsOver f S' := homIsOver_of_isOverTower f S S' instance [OverClass X S] [OverClass X S'] [CanonicallyOverClass Y S] [OverClass Y S'] [OverClass S S'] [IsOverTower X S S'] [IsOverTower Y S S'] [HomIsOver f S] : HomIsOver f S' := homIsOver_of_isOverTower f S S' variable (X) in /-- Bundle `X` with an `OverClass X S` instance into `Over S`. -/ @[simps! hom left] def OverClass.asOver [OverClass X S] : Over S := Over.mk (X ↘ S) /-- Bundle a morphism `f : X ⟶ Y` with `HomIsOver f S` into a morphism in `Over S`. -/ @[simps! left] def OverClass.asOverHom [OverClass X S] [OverClass Y S] (f : X ⟶ Y) [HomIsOver f S] : OverClass.asOver X S ⟶ OverClass.asOver Y S := Over.homMk f (comp_over f S) @[simps] instance OverClass.fromOver {S : C} (X : Over S) : OverClass X.left S where hom := X.hom instance {S : C} {X Y : Over S} (f : X ⟶ Y) : HomIsOver f.left S where comp_over := Over.w f variable [OverClass X S] [OverClass Y S] [OverClass Z S] namespace OverClass instance (f : X ⟶ Y) [IsIso f] [HomIsOver f S] : IsIso (asOverHom S f) := have : IsIso ((Over.forget S).map (asOverHom S f)) := ‹_› isIso_of_reflects_iso _ (Over.forget _) attribute [local simp] Iso.inv_comp_eq in instance {e : X ≅ Y} [HomIsOver e.hom S] : HomIsOver e.inv S where -- FIXME: False positive from the linter set_option linter.style.commandStart false in attribute [local simp ←] Iso.eq_inv_comp in instance {e : X ≅ Y} [HomIsOver e.inv S] : HomIsOver e.hom S where instance {f : X ⟶ Y} [IsIso f] [HomIsOver f S] : HomIsOver (asIso f).hom S where instance {f : X ⟶ Y} [IsIso f] [HomIsOver f S] : HomIsOver (asIso f).inv S where instance {f : X ⟶ Y} [IsIso f] [HomIsOver f S] : HomIsOver (inv f) S where @[simp] lemma asOverHom_id : asOverHom S (𝟙 X) = 𝟙 (asOver X S) := rfl @[simp, reassoc] lemma asOverHom_comp (f : X ⟶ Y) (g : Y ⟶ Z) [HomIsOver f S] [HomIsOver g S] : asOverHom S (f ≫ g) = asOverHom S f ≫ asOverHom S g := rfl @[simp] lemma asOverHom_inv (f : X ⟶ Y) [IsIso f] [HomIsOver f S] : asOverHom S (inv f) = inv (asOverHom S f) := by simp [← hom_comp_eq_id, ← asOverHom_comp] end OverClass /-- Reinterpret an isomorphism over an object `S` into an isomorphism in the category over `S`. -/ @[simps] def Iso.asOver (e : X ≅ Y) [HomIsOver e.hom S] : OverClass.asOver X S ≅ OverClass.asOver Y S where hom := OverClass.asOverHom S e.hom inv := OverClass.asOverHom S e.inv end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Over/Pullback.lean
import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Adjunction.Mates import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Monad.Products import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Pasting import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Iso /-! # Adjunctions related to the over category In a category with pullbacks, for any morphism `f : X ⟶ Y`, the functor `Over.map f : Over X ⥤ Over Y` has a right adjoint `Over.pullback f`. In a category with binary products, for any object `X` the functor `Over.forget X : Over X ⥤ C` has a right adjoint `Over.star X`. ## Main declarations - `Over.pullback f : Over Y ⥤ Over X` is the functor induced by a morphism `f : X ⟶ Y`. - `Over.mapPullbackAdj` is the adjunction `Over.map f ⊣ Over.pullback f`. - `star : C ⥤ Over X` is the functor induced by an object `X`. - `forgetAdjStar` is the adjunction `forget X ⊣ star X`. ## TODO Show `star X` itself has a right adjoint provided `C` is Cartesian closed and has pullbacks. -/ noncomputable section universe v v₂ u u₂ namespace CategoryTheory open Category Limits Comonad variable {C : Type u} [Category.{v} C] (X Y : C) variable {D : Type u₂} [Category.{v₂} D] namespace Over open Limits attribute [local instance] hasPullback_of_right_iso /-- In a category with pullbacks, a morphism `f : X ⟶ Y` induces a functor `Over Y ⥤ Over X`, by pulling back a morphism along `f`. -/ @[simps! +simpRhs obj_left obj_hom map_left] def pullback {X Y : C} (f : X ⟶ Y) [HasPullbacksAlong f] : Over Y ⥤ Over X where obj g := Over.mk (pullback.snd g.hom f) map := fun g {h} {k} => Over.homMk (pullback.lift (pullback.fst _ _ ≫ k.left) (pullback.snd _ _) (by simp [pullback.condition])) /-- `Over.map f` is left adjoint to `Over.pullback f`. -/ @[simps! unit_app counit_app] def mapPullbackAdj {X Y : C} (f : X ⟶ Y) [HasPullbacksAlong f] : Over.map f ⊣ pullback f := Adjunction.mkOfHomEquiv { homEquiv := fun x y => { toFun := fun u => Over.homMk (pullback.lift u.left x.hom <| by simp) invFun := fun v => Over.homMk (v.left ≫ pullback.fst _ _) <| by simp [← Over.w v, pullback.condition] left_inv := by cat_disch right_inv := fun v => by ext dsimp ext · simp · simpa using (Over.w v).symm } } /-- The pullback along an epi that's preserved under pullbacks is faithful. This "preserved under pullbacks" condition is automatically satisfied in abelian categories: ``` example [Abelian C] [Epi f] : (pullback f).Faithful := inferInstance ``` -/ instance faithful_pullback {X Y : C} (f : X ⟶ Y) [HasPullbacksAlong f] [∀ Z (g : Z ⟶ Y), Epi (pullback.fst g f)] : (pullback f).Faithful := by have (Z : Over Y) : Epi ((mapPullbackAdj f).counit.app Z) := by simp only [Functor.comp_obj, Functor.id_obj, mapPullbackAdj_counit_app]; infer_instance exact (mapPullbackAdj f).faithful_R_of_epi_counit_app /-- pullback (𝟙 X) : Over X ⥤ Over X is the identity functor. -/ def pullbackId {X : C} : pullback (𝟙 X) ≅ 𝟭 _ := conjugateIsoEquiv (mapPullbackAdj (𝟙 _)) (Adjunction.id (C := Over _)) (Over.mapId _).symm /-- pullback commutes with composition (up to natural isomorphism). -/ def pullbackComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasPullbacksAlong f] [HasPullbacksAlong g] : pullback (f ≫ g) ≅ pullback g ⋙ pullback f := conjugateIsoEquiv (mapPullbackAdj _) ((mapPullbackAdj _).comp (mapPullbackAdj _)) (Over.mapComp _ _).symm instance pullbackIsRightAdjoint {X Y : C} (f : X ⟶ Y) [HasPullbacksAlong f] : (pullback f).IsRightAdjoint := ⟨_, ⟨mapPullbackAdj f⟩⟩ open pullback in /-- If `F` is a left adjoint and its source category has pullbacks, then so is `post F : Over Y ⥤ Over (G Y)`. If the right adjoint of `F` is `G`, then the right adjoint of `post F` is given by `(Y ⟶ F X) ↦ (G Y ⟶ X ×_{G F X} G Y ⟶ X)`. -/ @[simps!] def postAdjunctionLeft [HasPullbacks C] {X : C} {F : C ⥤ D} {G : D ⥤ C} (a : F ⊣ G) : post F ⊣ post G ⋙ pullback (a.unit.app X) := ((mapPullbackAdj (a.unit.app X)).comp (postAdjunctionRight a)).ofNatIsoLeft <| NatIso.ofComponents fun Y ↦ isoMk (.refl _) instance isLeftAdjoint_post [HasPullbacks C] {F : C ⥤ D} [F.IsLeftAdjoint] : (post (X := X) F).IsLeftAdjoint := let ⟨G, ⟨a⟩⟩ := ‹F.IsLeftAdjoint›; ⟨_, ⟨postAdjunctionLeft a⟩⟩ open Limits /-- The category over any object `X` factors through the category over the terminal object `T`. -/ @[simps!] noncomputable def forgetMapTerminal {T : C} (hT : IsTerminal T) : forget X ≅ map (hT.from X) ⋙ (equivalenceOfIsTerminal hT).functor := NatIso.ofComponents fun X ↦ .refl _ section HasBinaryProducts variable [HasBinaryProducts C] /-- The functor from `C` to `Over X` which sends `Y : C` to `π₁ : X ⨯ Y ⟶ X`, sometimes denoted `X*`. -/ @[simps! obj_left obj_hom map_left] def star : C ⥤ Over X := cofree _ ⋙ coalgebraToOver X /-- The functor `Over.forget X : Over X ⥤ C` has a right adjoint given by `star X`. Note that the binary products assumption is necessary: the existence of a right adjoint to `Over.forget X` is equivalent to the existence of each binary product `X ⨯ -`. -/ def forgetAdjStar : forget X ⊣ star X := (coalgebraEquivOver X).symm.toAdjunction.comp (adj _) instance : (star X).IsRightAdjoint := ⟨_, ⟨forgetAdjStar X⟩⟩ /-- Note that the binary products assumption is necessary: the existence of a right adjoint to `Over.forget X` is equivalent to the existence of each binary product `X ⨯ -`. -/ instance : (forget X).IsLeftAdjoint := ⟨_, ⟨forgetAdjStar X⟩⟩ end HasBinaryProducts end Over namespace Under attribute [local instance] hasPushout_of_right_iso /-- When `C` has pushouts, a morphism `f : X ⟶ Y` induces a functor `Under X ⥤ Under Y`, by pushing a morphism forward along `f`. -/ @[simps] def pushout {X Y : C} (f : X ⟶ Y) [HasPushoutsAlong f] : Under X ⥤ Under Y where obj x := Under.mk (pushout.inr x.hom f) map := fun x {x'} {u} => Under.homMk (pushout.desc (u.right ≫ pushout.inl _ _) (pushout.inr _ _) (by simp [← pushout.condition])) /-- `Under.pushout f` is left adjoint to `Under.map f`. -/ @[simps! unit_app counit_app] def mapPushoutAdj {X Y : C} (f : X ⟶ Y) [HasPushoutsAlong f] : pushout f ⊣ map f := Adjunction.mkOfHomEquiv { homEquiv := fun x y => { toFun := fun u => Under.homMk (pushout.inl _ _ ≫ u.right) <| by simp only [map_obj_hom] rw [← Under.w u] simp only [Functor.const_obj_obj, map_obj_right, Functor.id_obj, pushout_obj, mk_right, mk_hom] rw [← assoc, ← assoc, pushout.condition] invFun := fun v => Under.homMk (pushout.desc v.right y.hom <| by simp) left_inv := fun u => by ext dsimp ext · simp · simpa using (Under.w u).symm right_inv := by cat_disch } } /-- The pushout along a mono that's preserved under pushouts is faithful. This "preserved under pushouts" condition is automatically satisfied in abelian categories: ``` example [Abelian C] [Mono f] : (pushout f).Faithful := inferInstance ``` -/ instance faithful_pushout {X Y : C} (f : X ⟶ Y) [HasPushoutsAlong f] [∀ Z (g : X ⟶ Z), Mono (pushout.inl g f)] : (pushout f).Faithful := by have (Z : Under X) : Mono ((mapPushoutAdj f).unit.app Z) := by simp; infer_instance exact (mapPushoutAdj f).faithful_L_of_mono_unit_app /-- pushout (𝟙 X) : Under X ⥤ Under X is the identity functor. -/ def pushoutId {X : C} : pushout (𝟙 X) ≅ 𝟭 _ := (conjugateIsoEquiv (Adjunction.id (C := Under _)) (mapPushoutAdj (𝟙 _)) ).symm (Under.mapId X).symm /-- pushout commutes with composition (up to natural isomorphism). -/ def pushoutComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasPushoutsAlong f] [HasPushoutsAlong g] : pushout (f ≫ g) ≅ pushout f ⋙ pushout g := (conjugateIsoEquiv ((mapPushoutAdj _).comp (mapPushoutAdj _)) (mapPushoutAdj _) ).symm (mapComp f g).symm instance pushoutIsLeftAdjoint {X Y : C} (f : X ⟶ Y) [HasPushoutsAlong f] : (pushout f).IsLeftAdjoint := ⟨_, ⟨mapPushoutAdj f⟩⟩ open pushout in /-- If `G` is a right adjoint and its source category has pushouts, then so is `post G : Under Y ⥤ Under (G Y)`. If the left adjoint of `G` is `F`, then the left adjoint of `post G` is given by `(G Y ⟶ X) ↦ (Y ⟶ Y ⨿_{F G Y} F X ⟶ F X)`. -/ @[simps!] def postAdjunctionRight [HasPushouts D] {Y : D} {F : C ⥤ D} {G : D ⥤ C} (a : F ⊣ G) : post F ⋙ pushout (a.counit.app Y) ⊣ post G := ((postAdjunctionLeft a).comp (mapPushoutAdj (a.counit.app Y))).ofNatIsoRight <| NatIso.ofComponents fun Y ↦ isoMk (.refl _) open pushout in instance isRightAdjoint_post [HasPushouts D] {Y : D} {G : D ⥤ C} [G.IsRightAdjoint] : (post (X := Y) G).IsRightAdjoint := let ⟨F, ⟨a⟩⟩ := ‹G.IsRightAdjoint›; ⟨_, ⟨postAdjunctionRight a⟩⟩ /-- The category under any object `X` factors through the category under the initial object `I`. -/ @[simps!] noncomputable def forgetMapInitial {I : C} (hI : IsInitial I) : forget X ≅ map (hI.to X) ⋙ (equivalenceOfIsInitial hI).functor := NatIso.ofComponents fun X ↦ .refl _ section HasBinaryCoproducts variable [HasBinaryCoproducts C] /-- The functor from `C` to `Under X` which sends `Y : C` to `in₁ : X ⟶ X ⨿ Y`. -/ @[simps! obj_left obj_hom map_left] def costar : C ⥤ Under X := Monad.free _ ⋙ algebraToUnder X /-- The functor `Under.forget X : Under X ⥤ C` has a left adjoint given by `costar X`. Note that the binary coproducts assumption is necessary: the existence of a left adjoint to `Under.forget X` is equivalent to the existence of each binary coproduct `X ⨿ -`. -/ def costarAdjForget : costar X ⊣ forget X := (Monad.adj _).comp (algebraEquivUnder X).toAdjunction instance : (costar X).IsLeftAdjoint := ⟨_, ⟨costarAdjForget X⟩⟩ /-- Note that the binary coproducts assumption is necessary: the existence of a left adjoint to `Under.forget X` is equivalent to the existence of each binary coproduct `X ⨿ -`. -/ instance : (forget X).IsRightAdjoint := ⟨_, ⟨costarAdjForget X⟩⟩ end HasBinaryCoproducts end Under end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Presheaf/Colimit.lean
import Mathlib.CategoryTheory.Comma.Presheaf.Basic import Mathlib.CategoryTheory.Limits.Preserves.Yoneda import Mathlib.CategoryTheory.Limits.Over /-! # Relative Yoneda preserves certain colimits In this file we turn the statement `yonedaYonedaColimit` from `CategoryTheory.Limits.Preserves.Yoneda` from a functor `F : J ⥤ Cᵒᵖ ⥤ Type v` into a statement about families of presheaves over `A`, i.e., functors `F : J ⥤ Over A`. -/ namespace CategoryTheory open Category Opposite Limits universe w v u variable {C : Type u} [Category.{v} C] {A : Cᵒᵖ ⥤ Type v} variable {J : Type v} [SmallCategory J] {A : Cᵒᵖ ⥤ Type v} (F : J ⥤ Over A) -- We introduce some local notation to reduce visual noise in the following proof local notation "E" => Equivalence.functor (overEquivPresheafCostructuredArrow A) local notation "E.obj" => Functor.obj (Equivalence.functor (overEquivPresheafCostructuredArrow A)) /-- Naturally in `X`, we have `Hom(YX, colim_i Fi) ≅ colim_i Hom(YX, Fi)`, where `Y` is the "Yoneda embedding" `CostructuredArrow.toOver yoneda A`. This is a relative version of `yonedaYonedaColimit`. -/ noncomputable def CostructuredArrow.toOverCompYonedaColimit : (CostructuredArrow.toOver yoneda A).op ⋙ yoneda.obj (colimit F) ≅ (CostructuredArrow.toOver yoneda A).op ⋙ colimit (F ⋙ yoneda) := calc (CostructuredArrow.toOver yoneda A).op ⋙ yoneda.obj (colimit F) ≅ yoneda.op ⋙ yoneda.obj (E.obj (colimit F)) := CostructuredArrow.toOverCompYoneda A _ _ ≅ yoneda.op ⋙ yoneda.obj (colimit (F ⋙ E)) := Functor.isoWhiskerLeft yoneda.op (yoneda.mapIso (preservesColimitIso E F)) _ ≅ yoneda.op ⋙ colimit ((F ⋙ E) ⋙ yoneda) := yonedaYonedaColimit _ _ ≅ yoneda.op ⋙ ((F ⋙ E) ⋙ yoneda).flip ⋙ colim := Functor.isoWhiskerLeft _ (colimitIsoFlipCompColim _) _ ≅ (yoneda.op ⋙ coyoneda ⋙ (Functor.whiskeringLeft _ _ _).obj E) ⋙ (Functor.whiskeringLeft _ _ _).obj F ⋙ colim := Iso.refl _ _ ≅ (CostructuredArrow.toOver yoneda A).op ⋙ coyoneda ⋙ (Functor.whiskeringLeft _ _ _).obj F ⋙ colim := Functor.isoWhiskerRight (CostructuredArrow.toOverCompCoyoneda _).symm _ _ ≅ (CostructuredArrow.toOver yoneda A).op ⋙ (F ⋙ yoneda).flip ⋙ colim := Iso.refl _ _ ≅ (CostructuredArrow.toOver yoneda A).op ⋙ colimit (F ⋙ yoneda) := Functor.isoWhiskerLeft _ (colimitIsoFlipCompColim _).symm end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Comma/Presheaf/Basic.lean
import Mathlib.CategoryTheory.HomCongr import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Computation of `Over A` for a presheaf `A` Let `A : Cᵒᵖ ⥤ Type v` be a presheaf. In this file, we construct an equivalence `e : Over A ≌ (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v` and show that there is a quasi-commutative diagram ``` CostructuredArrow yoneda A ⥤ Over A ⇘ ⥥ PSh(CostructuredArrow yoneda A) ``` where the top arrow is the forgetful functor forgetting the yoneda-costructure, the right arrow is the aforementioned equivalence and the diagonal arrow is the Yoneda embedding. In the notation of Kashiwara-Schapira, the type of the equivalence is written `C^ₐ ≌ Cₐ^`, where `·ₐ` is `CostructuredArrow` (with the functor `S` being either the identity or the Yoneda embedding) and `^` is taking presheaves. The equivalence is a key ingredient in various results in Kashiwara-Schapira. The proof is somewhat long and technical, in part due to the construction inherently involving a sigma type which comes with the usual DTT issues. However, a user of this result should not need to interact with the actual construction, the mere existence of the equivalence and the commutative triangle should generally be sufficient. ## Main results * `overEquivPresheafCostructuredArrow`: the equivalence `Over A ≌ (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v` * `CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow`: the natural isomorphism `CostructuredArrow.toOver yoneda A ⋙ (overEquivPresheafCostructuredArrow A).functor ≅ yoneda` ## Implementation details The proof needs to introduce "correction terms" in various places in order to overcome DTT issues, and these need to be canceled against each other when appropriate. It is important to deal with these in a structured manner, otherwise you get large goals containing many correction terms which are very tedious to manipulate. We avoid this blowup by carefully controlling which definitions `(d)simp` is allowed to unfold and stating many lemmas explicitly before they are required. This leads to manageable goals containing only a small number of correction terms. Generally, we use the form `F.map (eqToHom _)` for these correction terms and try to push them as far outside as possible. ## Future work * If needed, it should be possible to show that the equivalence is natural in `A`. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Lemma 1.4.12 ## Tags presheaf, over category, coyoneda -/ namespace CategoryTheory open Category Opposite universe w v u variable {C : Type u} [Category.{v} C] {A : Cᵒᵖ ⥤ Type v} namespace OverPresheafAux attribute [local simp] FunctorToTypes.naturality /-! ### Construction of the forward functor `Over A ⥤ (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v` -/ /-- Via the Yoneda lemma, `u : F.obj (op X)` defines a natural transformation `yoneda.obj X ⟶ F` and via the element `η.app (op X) u` also a morphism `yoneda.obj X ⟶ A`. This structure witnesses the fact that these morphisms from a commutative triangle with `η : F ⟶ A`, i.e., that `yoneda.obj X ⟶ F` lifts to a morphism in `Over A`. -/ structure MakesOverArrow {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) {X : C} (s : yoneda.obj X ⟶ A) (u : F.obj (op X)) : Prop where app : η.app (op X) u = yonedaEquiv s namespace MakesOverArrow /-- "Functoriality" of `MakesOverArrow η s` in `η`. -/ lemma map₁ {F G : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {μ : G ⟶ A} {ε : F ⟶ G} (hε : ε ≫ μ = η) {X : C} {s : yoneda.obj X ⟶ A} {u : F.obj (op X)} (h : MakesOverArrow η s u) : MakesOverArrow μ s (ε.app _ u) := ⟨by rw [← elementwise_of% NatTrans.comp_app ε μ, hε, h.app]⟩ /-- "Functoriality of `MakesOverArrow η s` in `s`. -/ lemma map₂ {F : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {X Y : C} (f : X ⟶ Y) {s : yoneda.obj X ⟶ A} {t : yoneda.obj Y ⟶ A} (hst : yoneda.map f ≫ t = s) {u : F.obj (op Y)} (h : MakesOverArrow η t u) : MakesOverArrow η s (F.map f.op u) := ⟨by rw [elementwise_of% η.naturality, h.app, yonedaEquiv_naturality, hst]⟩ lemma of_arrow {F : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} {f : yoneda.obj X ⟶ F} (hf : f ≫ η = s) : MakesOverArrow η s (yonedaEquiv f) := ⟨hf ▸ rfl⟩ lemma of_yoneda_arrow {Y : C} {η : yoneda.obj Y ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} {f : X ⟶ Y} (hf : yoneda.map f ≫ η = s) : MakesOverArrow η s f := by simpa only [yonedaEquiv_yoneda_map f] using of_arrow hf end MakesOverArrow /-- This is equivalent to the type `Over.mk s ⟶ Over.mk η`, but that lives in the wrong universe. However, if `F = yoneda.obj Y` for some `Y`, then (using that the Yoneda embedding is fully faithful) we get a good statement, see `OverArrow.costructuredArrowIso`. -/ def OverArrows {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) {X : C} (s : yoneda.obj X ⟶ A) : Type v := Subtype (MakesOverArrow η s) namespace OverArrows /-- Since `OverArrows η s` can be thought of to contain certain morphisms `yoneda.obj X ⟶ F`, the Yoneda lemma yields elements `F.obj (op X)`. -/ def val {F : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} : OverArrows η s → F.obj (op X) := Subtype.val @[simp] lemma val_mk {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) {X : C} (s : yoneda.obj X ⟶ A) (u : F.obj (op X)) (h : MakesOverArrow η s u) : val ⟨u, h⟩ = u := rfl @[ext] lemma ext {F : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} {u v : OverArrows η s} : u.val = v.val → u = v := Subtype.ext /-- The defining property of `OverArrows.val`. -/ lemma app_val {F : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} (p : OverArrows η s) : η.app (op X) p.val = yonedaEquiv s := p.prop.app /-- In the special case `F = yoneda.obj Y`, the element `p.val` for `p : OverArrows η s` is itself a morphism `X ⟶ Y`. -/ @[simp] lemma map_val {Y : C} {η : yoneda.obj Y ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} (p : OverArrows η s) : yoneda.map p.val ≫ η = s := by rw [← yonedaEquiv.injective.eq_iff, yonedaEquiv_comp, yonedaEquiv_yoneda_map] simp only [unop_op, p.app_val] /-- Functoriality of `OverArrows η s` in `η`. -/ def map₁ {F G : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {μ : G ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} (u : OverArrows η s) (ε : F ⟶ G) (hε : ε ≫ μ = η) : OverArrows μ s := ⟨ε.app _ u.val, MakesOverArrow.map₁ hε u.2⟩ @[simp] lemma map₁_val {F G : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {μ : G ⟶ A} {X : C} (s : yoneda.obj X ⟶ A) (u : OverArrows η s) (ε : F ⟶ G) (hε : ε ≫ μ = η) : (u.map₁ ε hε).val = ε.app _ u.val := rfl /-- Functoriality of `OverArrows η s` in `s`. -/ def map₂ {F : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {X Y : C} {s : yoneda.obj X ⟶ A} {t : yoneda.obj Y ⟶ A} (u : OverArrows η t) (f : X ⟶ Y) (hst : yoneda.map f ≫ t = s) : OverArrows η s := ⟨F.map f.op u.val, MakesOverArrow.map₂ f hst u.2⟩ @[simp] lemma map₂_val {F : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {X Y : C} (f : X ⟶ Y) {s : yoneda.obj X ⟶ A} {t : yoneda.obj Y ⟶ A} (hst : yoneda.map f ≫ t = s) (u : OverArrows η t) : (u.map₂ f hst).val = F.map f.op u.val := rfl @[simp] lemma map₁_map₂ {F G : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {μ : G ⟶ A} (ε : F ⟶ G) (hε : ε ≫ μ = η) {X Y : C} {s : yoneda.obj X ⟶ A} {t : yoneda.obj Y ⟶ A} (f : X ⟶ Y) (hf : yoneda.map f ≫ t = s) (u : OverArrows η t) : (u.map₁ ε hε).map₂ f hf = (u.map₂ f hf).map₁ ε hε := OverArrows.ext <| (elementwise_of% (ε.naturality f.op).symm) u.val /-- Construct an element of `OverArrows η s` with `F = yoneda.obj Y` from a suitable morphism `f : X ⟶ Y`. -/ def yonedaArrow {Y : C} {η : yoneda.obj Y ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} (f : X ⟶ Y) (hf : yoneda.map f ≫ η = s) : OverArrows η s := ⟨f, .of_yoneda_arrow hf⟩ @[simp] lemma yonedaArrow_val {Y : C} {η : yoneda.obj Y ⟶ A} {X : C} {s : yoneda.obj X ⟶ A} {f : X ⟶ Y} (hf : yoneda.map f ≫ η = s) : (yonedaArrow f hf).val = f := rfl /-- If `η` is also `yoneda`-costructured, then `OverArrows η s` is just morphisms of costructured arrows. -/ def costructuredArrowIso (s t : CostructuredArrow yoneda A) : OverArrows s.hom t.hom ≅ t ⟶ s where hom p := CostructuredArrow.homMk p.val (by simp) inv f := yonedaArrow f.left f.w end OverArrows /-- This is basically just `yoneda.obj η : (Over A)ᵒᵖ ⥤ Type (max u v)` restricted along the forgetful functor `CostructuredArrow yoneda A ⥤ Over A`, but done in a way that we land in a smaller universe. -/ @[simps] def restrictedYonedaObj {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v where obj s := OverArrows η s.unop.hom map f u := u.map₂ f.unop.left f.unop.w /-- Functoriality of `restrictedYonedaObj η` in `η`. -/ @[simps] def restrictedYonedaObjMap₁ {F G : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {μ : G ⟶ A} (ε : F ⟶ G) (hε : ε ≫ μ = η) : restrictedYonedaObj η ⟶ restrictedYonedaObj μ where app _ u := u.map₁ ε hε /-- This is basically just `yoneda : Over A ⥤ (Over A)ᵒᵖ ⥤ Type (max u v)` restricted in the second argument along the forgetful functor `CostructuredArrow yoneda A ⥤ Over A`, but done in a way that we land in a smaller universe. This is one direction of the equivalence we're constructing. -/ @[simps] def restrictedYoneda (A : Cᵒᵖ ⥤ Type v) : Over A ⥤ (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v where obj η := restrictedYonedaObj η.hom map ε := restrictedYonedaObjMap₁ ε.left ε.w /-- Further restricting the functor `restrictedYoneda : Over A ⥤ (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v` along the forgetful functor in the first argument recovers the Yoneda embedding `CostructuredArrow yoneda A ⥤ (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v`. This basically follows from the fact that the Yoneda embedding on `C` is fully faithful. -/ def toOverYonedaCompRestrictedYoneda (A : Cᵒᵖ ⥤ Type v) : CostructuredArrow.toOver yoneda A ⋙ restrictedYoneda A ≅ yoneda := NatIso.ofComponents (fun s => NatIso.ofComponents (fun _ => OverArrows.costructuredArrowIso _ _) (by cat_disch)) (by cat_disch) /-! ### Construction of the backward functor `((CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) ⥤ Over A` -/ /-- This lemma will be key to establishing good simp normal forms. -/ lemma map_mkPrecomp_eqToHom {F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} {X Y : C} {f : X ⟶ Y} {g g' : yoneda.obj Y ⟶ A} (h : g = g') {x : F.obj (op (CostructuredArrow.mk g'))} : F.map (CostructuredArrow.mkPrecomp g f).op (F.map (eqToHom (by rw [h])) x) = F.map (eqToHom (by rw [h])) (F.map (CostructuredArrow.mkPrecomp g' f).op x) := by cat_disch attribute [local simp] map_mkPrecomp_eqToHom /-- To give an object of `Over A`, we will in particular need a presheaf `Cᵒᵖ ⥤ Type v`. This is the definition of that presheaf on objects. We would prefer to think of this sigma type to be indexed by natural transformations `yoneda.obj X ⟶ A` instead of `A.obj (op X)`. These are equivalent by the Yoneda lemma, but we cannot use the former because that type lives in the wrong universe. Hence, we will provide a lot of API that will enable us to pretend that we are really indexing over `yoneda.obj X ⟶ A`. -/ def YonedaCollection (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) (X : C) : Type v := Σ s : A.obj (op X), F.obj (op (CostructuredArrow.mk (yonedaEquiv.symm s))) namespace YonedaCollection variable {F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} {X : C} /-- Given a costructured arrow `s : yoneda.obj X ⟶ A` and an element `x : F.obj s`, construct an element of `YonedaCollection F X`. -/ def mk (s : yoneda.obj X ⟶ A) (x : F.obj (op (CostructuredArrow.mk s))) : YonedaCollection F X := ⟨yonedaEquiv s, F.map (eqToHom <| by rw [Equiv.symm_apply_apply]) x⟩ /-- Access the first component of an element of `YonedaCollection F X`. -/ def fst (p : YonedaCollection F X) : yoneda.obj X ⟶ A := yonedaEquiv.symm p.1 /-- Access the second component of an element of `YonedaCollection F X`. -/ def snd (p : YonedaCollection F X) : F.obj (op (CostructuredArrow.mk p.fst)) := p.2 /-- This is a definition because it will be helpful to be able to control precisely when this definition is unfolded. -/ def yonedaEquivFst (p : YonedaCollection F X) : A.obj (op X) := yonedaEquiv p.fst lemma yonedaEquivFst_eq (p : YonedaCollection F X) : p.yonedaEquivFst = yonedaEquiv p.fst := rfl @[simp] lemma mk_fst (s : yoneda.obj X ⟶ A) (x : F.obj (op (CostructuredArrow.mk s))) : (mk s x).fst = s := Equiv.apply_symm_apply _ _ @[simp] lemma mk_snd (s : yoneda.obj X ⟶ A) (x : F.obj (op (CostructuredArrow.mk s))) : (mk s x).snd = F.map (eqToHom <| by rw [YonedaCollection.mk_fst]) x := rfl @[ext (iff := false)] lemma ext {p q : YonedaCollection F X} (h : p.fst = q.fst) (h' : F.map (eqToHom <| by rw [h]) q.snd = p.snd) : p = q := by rcases p with ⟨p, p'⟩ rcases q with ⟨q, q'⟩ obtain rfl : p = q := yonedaEquiv.symm.injective h exact Sigma.ext rfl (by simpa [snd] using h'.symm) /-- Functoriality of `YonedaCollection F X` in `F`. -/ def map₁ {G : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) : YonedaCollection F X → YonedaCollection G X := fun p => YonedaCollection.mk p.fst (η.app _ p.snd) @[simp] lemma map₁_fst {G : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) (p : YonedaCollection F X) : (YonedaCollection.map₁ η p).fst = p.fst := by simp [map₁] @[simp] lemma map₁_yonedaEquivFst {G : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) (p : YonedaCollection F X) : (YonedaCollection.map₁ η p).yonedaEquivFst = p.yonedaEquivFst := by simp only [YonedaCollection.yonedaEquivFst_eq, map₁_fst] @[simp] lemma map₁_snd {G : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) (p : YonedaCollection F X) : (YonedaCollection.map₁ η p).snd = G.map (eqToHom (by rw [YonedaCollection.map₁_fst])) (η.app _ p.snd) := by simp [map₁] /-- Functoriality of `YonedaCollection F X` in `X`. -/ def map₂ (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) {Y : C} (f : X ⟶ Y) (p : YonedaCollection F Y) : YonedaCollection F X := YonedaCollection.mk (yoneda.map f ≫ p.fst) <| F.map (CostructuredArrow.mkPrecomp p.fst f).op p.snd @[simp] lemma map₂_fst {Y : C} (f : X ⟶ Y) (p : YonedaCollection F Y) : (YonedaCollection.map₂ F f p).fst = yoneda.map f ≫ p.fst := by simp [map₂] @[simp] lemma map₂_yonedaEquivFst {Y : C} (f : X ⟶ Y) (p : YonedaCollection F Y) : (YonedaCollection.map₂ F f p).yonedaEquivFst = A.map f.op p.yonedaEquivFst := by simp only [YonedaCollection.yonedaEquivFst_eq, map₂_fst, yonedaEquiv_naturality] @[simp] lemma map₂_snd {Y : C} (f : X ⟶ Y) (p : YonedaCollection F Y) : (YonedaCollection.map₂ F f p).snd = F.map ((CostructuredArrow.mkPrecomp p.fst f).op ≫ eqToHom (by rw [YonedaCollection.map₂_fst f])) p.snd := by simp [map₂] attribute [local simp] CostructuredArrow.mkPrecomp_id CostructuredArrow.mkPrecomp_comp @[simp] lemma map₁_id : YonedaCollection.map₁ (𝟙 F) (X := X) = id := by cat_disch @[simp] lemma map₁_comp {G H : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) (μ : G ⟶ H) : YonedaCollection.map₁ (η ≫ μ) (X := X) = YonedaCollection.map₁ μ (X := X) ∘ YonedaCollection.map₁ η (X := X) := by ext; all_goals simp @[simp] lemma map₂_id : YonedaCollection.map₂ F (𝟙 X) = id := by ext; all_goals simp @[simp] lemma map₂_comp {Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : YonedaCollection.map₂ F (f ≫ g) = YonedaCollection.map₂ F f ∘ YonedaCollection.map₂ F g := by ext; all_goals simp @[simp] lemma map₁_map₂ {G : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) {Y : C} (f : X ⟶ Y) (p : YonedaCollection F Y) : YonedaCollection.map₂ G f (YonedaCollection.map₁ η p) = YonedaCollection.map₁ η (YonedaCollection.map₂ F f p) := by ext; all_goals simp end YonedaCollection /-- Given `F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v`, this is the presheaf that is given by `YonedaCollection F X` on objects. -/ @[simps] def yonedaCollectionPresheaf (A : Cᵒᵖ ⥤ Type v) (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) : Cᵒᵖ ⥤ Type v where obj X := YonedaCollection F X.unop map f := YonedaCollection.map₂ F f.unop /-- Functoriality of `yonedaCollectionPresheaf A F` in `F`. -/ @[simps] def yonedaCollectionPresheafMap₁ {F G : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) : yonedaCollectionPresheaf A F ⟶ yonedaCollectionPresheaf A G where app _ := YonedaCollection.map₁ η naturality := by intros ext simp /-- This is the functor `F ↦ X ↦ YonedaCollection F X`. -/ @[simps] def yonedaCollectionFunctor (A : Cᵒᵖ ⥤ Type v) : ((CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) ⥤ Cᵒᵖ ⥤ Type v where obj := yonedaCollectionPresheaf A map η := yonedaCollectionPresheafMap₁ η /-- The Yoneda lemma yields a natural transformation `yonedaCollectionPresheaf A F ⟶ A`. -/ @[simps] def yonedaCollectionPresheafToA (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) : yonedaCollectionPresheaf A F ⟶ A where app _ := YonedaCollection.yonedaEquivFst /-- This is the reverse direction of the equivalence we're constructing. -/ @[simps! obj map] def costructuredArrowPresheafToOver (A : Cᵒᵖ ⥤ Type v) : ((CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) ⥤ Over A := (yonedaCollectionFunctor A).toOver _ (yonedaCollectionPresheafToA) (by cat_disch) section unit /-! ### Construction of the unit -/ /-- Forward direction of the unit. -/ def unitForward {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) (X : C) : YonedaCollection (restrictedYonedaObj η) X → F.obj (op X) := fun p => p.snd.val @[simp] lemma unitForward_naturality₁ {F G : Cᵒᵖ ⥤ Type v} {η : F ⟶ A} {μ : G ⟶ A} (ε : F ⟶ G) (hε : ε ≫ μ = η) (X : C) (p : YonedaCollection (restrictedYonedaObj η) X) : unitForward μ X (p.map₁ (restrictedYonedaObjMap₁ ε hε)) = ε.app _ (unitForward η X p) := by simp [unitForward] @[simp] lemma unitForward_naturality₂ {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) (X Y : C) (f : X ⟶ Y) (p : YonedaCollection (restrictedYonedaObj η) Y) : unitForward η X (YonedaCollection.map₂ (restrictedYonedaObj η) f p) = F.map f.op (unitForward η Y p) := by simp [unitForward] @[simp] lemma app_unitForward {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) (X : Cᵒᵖ) (p : YonedaCollection (restrictedYonedaObj η) X.unop) : η.app X (unitForward η X.unop p) = p.yonedaEquivFst := by simpa [unitForward] using p.snd.app_val /-- Backward direction of the unit. -/ def unitBackward {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) (X : C) : F.obj (op X) → YonedaCollection (restrictedYonedaObj η) X := fun x => YonedaCollection.mk (yonedaEquiv.symm (η.app _ x)) ⟨x, ⟨by simp⟩⟩ lemma unitForward_unitBackward {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) (X : C) : unitForward η X ∘ unitBackward η X = id := funext fun x => by simp [unitForward, unitBackward] lemma unitBackward_unitForward {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) (X : C) : unitBackward η X ∘ unitForward η X = id := by refine funext fun p => YonedaCollection.ext ?_ (OverArrows.ext ?_) · simpa [unitForward, unitBackward] using congrArg yonedaEquiv.symm p.snd.app_val · simp [unitForward, unitBackward] /-- Intermediate stage of assembling the unit. -/ @[simps] def unitAuxAuxAux {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) (X : C) : YonedaCollection (restrictedYonedaObj η) X ≅ F.obj (op X) where hom := unitForward η X inv := unitBackward η X hom_inv_id := unitBackward_unitForward η X inv_hom_id := unitForward_unitBackward η X /-- Intermediate stage of assembling the unit. -/ @[simps!] def unitAuxAux {F : Cᵒᵖ ⥤ Type v} (η : F ⟶ A) : yonedaCollectionPresheaf A (restrictedYonedaObj η) ≅ F := NatIso.ofComponents (fun X => unitAuxAuxAux η X.unop) (by cat_disch) /-- Intermediate stage of assembling the unit. -/ @[simps! hom] def unitAux (η : Over A) : (restrictedYoneda A ⋙ costructuredArrowPresheafToOver A).obj η ≅ η := Over.isoMk (unitAuxAux η.hom) (by cat_disch) /-- The unit of the equivalence we're constructing. -/ def unit (A : Cᵒᵖ ⥤ Type v) : 𝟭 (Over A) ≅ restrictedYoneda A ⋙ costructuredArrowPresheafToOver A := Iso.symm <| NatIso.ofComponents unitAux (by cat_disch) end unit /-! ### Construction of the counit -/ section counit variable {F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} {X : C} @[simp] lemma OverArrows.yonedaCollectionPresheafToA_val_fst (s : yoneda.obj X ⟶ A) (p : OverArrows (yonedaCollectionPresheafToA F) s) : p.val.fst = s := by simpa [YonedaCollection.yonedaEquivFst_eq] using p.app_val /-- Forward direction of the counit. -/ def counitForward (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) (s : CostructuredArrow yoneda A) : F.obj (op s) → OverArrows (yonedaCollectionPresheafToA F) s.hom := fun x => ⟨YonedaCollection.mk s.hom x, ⟨by simp [YonedaCollection.yonedaEquivFst_eq]⟩⟩ lemma counitForward_val_fst (s : CostructuredArrow yoneda A) (x : F.obj (op s)) : (counitForward F s x).val.fst = s.hom := by simp @[simp] lemma counitForward_val_snd (s : CostructuredArrow yoneda A) (x : F.obj (op s)) : (counitForward F s x).val.snd = F.map (eqToHom (by simp [← CostructuredArrow.eq_mk])) x := YonedaCollection.mk_snd _ _ @[simp] lemma counitForward_naturality₁ {G : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v} (η : F ⟶ G) (s : (CostructuredArrow yoneda A)ᵒᵖ) (x : F.obj s) : counitForward G s.unop (η.app s x) = OverArrows.map₁ (counitForward F s.unop x) (yonedaCollectionPresheafMap₁ η) (by cat_disch) := OverArrows.ext <| YonedaCollection.ext (by simp) (by simp) @[simp] lemma counitForward_naturality₂ (s t : (CostructuredArrow yoneda A)ᵒᵖ) (f : t ⟶ s) (x : F.obj t) : counitForward F s.unop (F.map f x) = OverArrows.map₂ (counitForward F t.unop x) f.unop.left (by simp) := by refine OverArrows.ext <| YonedaCollection.ext (by simp) ?_ have : (CostructuredArrow.mkPrecomp t.unop.hom f.unop.left).op = f ≫ eqToHom (by simp [← CostructuredArrow.eq_mk]) := by apply Quiver.Hom.unop_inj simp cat_disch /-- Backward direction of the counit. -/ def counitBackward (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) (s : CostructuredArrow yoneda A) : OverArrows (yonedaCollectionPresheafToA F) s.hom → F.obj (op s) := fun p => F.map (eqToHom (by simp [← CostructuredArrow.eq_mk])) p.val.snd lemma counitForward_counitBackward (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) (s : CostructuredArrow yoneda A) : counitForward F s ∘ counitBackward F s = id := funext fun p => OverArrows.ext <| YonedaCollection.ext (by simp) (by simp [counitBackward]) lemma counitBackward_counitForward (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) (s : CostructuredArrow yoneda A) : counitBackward F s ∘ counitForward F s = id := funext fun x => by simp [counitBackward] /-- Intermediate stage of assembling the counit. -/ @[simps] def counitAuxAux (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) (s : CostructuredArrow yoneda A) : F.obj (op s) ≅ OverArrows (yonedaCollectionPresheafToA F) s.hom where hom := counitForward F s inv := counitBackward F s hom_inv_id := counitBackward_counitForward F s inv_hom_id := counitForward_counitBackward F s /-- Intermediate stage of assembling the counit. -/ @[simps! hom] def counitAux (F : (CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) : F ≅ restrictedYonedaObj (yonedaCollectionPresheafToA F) := NatIso.ofComponents (fun s => counitAuxAux F s.unop) (by cat_disch) /-- The counit of the equivalence we're constructing. -/ def counit (A : Cᵒᵖ ⥤ Type v) : (costructuredArrowPresheafToOver A ⋙ restrictedYoneda A) ≅ 𝟭 _ := Iso.symm <| NatIso.ofComponents counitAux (by cat_disch) end counit end OverPresheafAux open OverPresheafAux /-- If `A : Cᵒᵖ ⥤ Type v` is a presheaf, then we have an equivalence between presheaves lying over `A` and the category of presheaves on `CostructuredArrow yoneda A`. There is a quasicommutative triangle involving this equivalence, see `CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow`. This is Lemma 1.4.12 in [Kashiwara2006]. -/ def overEquivPresheafCostructuredArrow (A : Cᵒᵖ ⥤ Type v) : Over A ≌ ((CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v) := .mk (restrictedYoneda A) (costructuredArrowPresheafToOver A) (unit A) (counit A) /-- If `A : Cᵒᵖ ⥤ Type v` is a presheaf, then the Yoneda embedding for `CostructuredArrow yoneda A` factors through `Over A` via a forgetful functor and an equivalence. This is Lemma 1.4.12 in [Kashiwara2006]. -/ def CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow (A : Cᵒᵖ ⥤ Type v) : CostructuredArrow.toOver yoneda A ⋙ (overEquivPresheafCostructuredArrow A).functor ≅ yoneda := toOverYonedaCompRestrictedYoneda A /-- This isomorphism says that hom-sets in the category `Over A` for a presheaf `A` where the domain is of the form `(CostructuredArrow.toOver yoneda A).obj X` can instead be interpreted as hom-sets in the category `(CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v` where the domain is of the form `yoneda.obj X` after adjusting the codomain accordingly. This is desirable because in the latter case the Yoneda lemma can be applied. -/ def CostructuredArrow.toOverCompYoneda (A : Cᵒᵖ ⥤ Type v) (T : Over A) : (CostructuredArrow.toOver yoneda A).op ⋙ yoneda.obj T ≅ yoneda.op ⋙ yoneda.obj ((overEquivPresheafCostructuredArrow A).functor.obj T) := NatIso.ofComponents (fun X => (overEquivPresheafCostructuredArrow A).fullyFaithfulFunctor.homEquiv.toIso ≪≫ (Iso.homCongr ((CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow A).app X.unop) (Iso.refl _)).toIso) (by cat_disch) @[simp] theorem CostructuredArrow.overEquivPresheafCostructuredArrow_inverse_map_toOverCompYoneda {A : Cᵒᵖ ⥤ Type v} {T : Over A} {X : CostructuredArrow yoneda A} (f : (CostructuredArrow.toOver yoneda A).obj X ⟶ T) : (overEquivPresheafCostructuredArrow A).inverse.map (((CostructuredArrow.toOverCompYoneda A T).hom.app (op X) f)) = (CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow A).isoCompInverse.inv.app X ≫ f ≫ (overEquivPresheafCostructuredArrow A).unit.app T := by simp [CostructuredArrow.toOverCompYoneda] @[simp] theorem CostructuredArrow.overEquivPresheafCostructuredArrow_functor_map_toOverCompYoneda {A : Cᵒᵖ ⥤ Type v} {T : Over A} {X : CostructuredArrow yoneda A} (f : yoneda.obj X ⟶ (overEquivPresheafCostructuredArrow A).functor.obj T) : (overEquivPresheafCostructuredArrow A).functor.map (((CostructuredArrow.toOverCompYoneda A T).inv.app (op X) f)) = (CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow A).hom.app X ≫ f := by simp [CostructuredArrow.toOverCompYoneda] /-- This isomorphism says that hom-sets in the category `Over A` for a presheaf `A` where the domain is of the form `(CostructuredArrow.toOver yoneda A).obj X` can instead be interpreted as hom-sets in the category `(CostructuredArrow yoneda A)ᵒᵖ ⥤ Type v` where the domain is of the form `yoneda.obj X` after adjusting the codomain accordingly. This is desirable because in the latter case the Yoneda lemma can be applied. -/ def CostructuredArrow.toOverCompCoyoneda (A : Cᵒᵖ ⥤ Type v) : (CostructuredArrow.toOver yoneda A).op ⋙ coyoneda ≅ yoneda.op ⋙ coyoneda ⋙ (Functor.whiskeringLeft _ _ _).obj (overEquivPresheafCostructuredArrow A).functor := NatIso.ofComponents (fun X => NatIso.ofComponents (fun Y => (overEquivPresheafCostructuredArrow A).fullyFaithfulFunctor.homEquiv.toIso ≪≫ (Iso.homCongr ((CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow A).app X.unop) (Iso.refl _)).toIso)) (by cat_disch) @[simp] theorem CostructuredArrow.overEquivPresheafCostructuredArrow_inverse_map_toOverCompCoyoneda {A : Cᵒᵖ ⥤ Type v} {T : Over A} {X : CostructuredArrow yoneda A} (f : (CostructuredArrow.toOver yoneda A).obj X ⟶ T) : (overEquivPresheafCostructuredArrow A).inverse.map (((CostructuredArrow.toOverCompCoyoneda A).hom.app (op X)).app T f) = (CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow A).isoCompInverse.inv.app X ≫ f ≫ (overEquivPresheafCostructuredArrow A).unit.app T := by simp [CostructuredArrow.toOverCompCoyoneda] @[simp] theorem CostructuredArrow.overEquivPresheafCostructuredArrow_functor_map_toOverCompCoyoneda {A : Cᵒᵖ ⥤ Type v} {T : Over A} {X : CostructuredArrow yoneda A} (f : yoneda.obj X ⟶ (overEquivPresheafCostructuredArrow A).functor.obj T) : (overEquivPresheafCostructuredArrow A).functor.map (((CostructuredArrow.toOverCompCoyoneda A).inv.app (op X)).app T f) = (CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow A).hom.app X ≫ f := by simp [CostructuredArrow.toOverCompCoyoneda] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/ConcreteCategory/EpiMono.lean
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.MorphismProperty.Concrete import Mathlib.CategoryTheory.Types.Basic /-! # Epi and mono in concrete categories In this file, we relate epimorphisms and monomorphisms in a concrete category `C` to surjective and injective morphisms, and we show that if `C` has strong epi mono factorizations and is such that `forget C` preserves both epi and mono, then any morphism in `C` can be factored in a functorial manner as a composition of a surjective morphism followed by an injective morphism. -/ universe w v v' u u' namespace CategoryTheory variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] open Limits MorphismProperty namespace ConcreteCategory section /-- In any concrete category, injective morphisms are monomorphisms. -/ theorem mono_of_injective {X Y : C} (f : X ⟶ Y) (i : Function.Injective f) : Mono f := (forget C).mono_of_mono_map ((mono_iff_injective ((forget C).map f)).2 i) instance forget₂_preservesMonomorphisms (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] [(forget C).PreservesMonomorphisms] : (forget₂ C D).PreservesMonomorphisms := have : (forget₂ C D ⋙ forget D).PreservesMonomorphisms := by simp only [HasForget₂.forget_comp] infer_instance Functor.preservesMonomorphisms_of_preserves_of_reflects _ (forget D) instance forget₂_preservesEpimorphisms (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] [(forget C).PreservesEpimorphisms] : (forget₂ C D).PreservesEpimorphisms := have : (forget₂ C D ⋙ forget D).PreservesEpimorphisms := by simp only [HasForget₂.forget_comp] infer_instance Functor.preservesEpimorphisms_of_preserves_of_reflects _ (forget D) variable (C) lemma surjective_le_epimorphisms : MorphismProperty.surjective C ≤ epimorphisms C := fun _ _ _ hf => (forget C).epi_of_epi_map ((epi_iff_surjective _).2 hf) lemma injective_le_monomorphisms : MorphismProperty.injective C ≤ monomorphisms C := fun _ _ _ hf => (forget C).mono_of_mono_map ((mono_iff_injective _).2 hf) lemma surjective_eq_epimorphisms_iff : MorphismProperty.surjective C = epimorphisms C ↔ (forget C).PreservesEpimorphisms := by constructor · intro h constructor rintro _ _ f (hf : epimorphisms C f) rw [epi_iff_surjective] rw [← h] at hf exact hf · intro apply le_antisymm (surjective_le_epimorphisms C) intro _ _ f hf have : Epi f := hf change Function.Surjective ((forget C).map f) rw [← epi_iff_surjective] infer_instance lemma injective_eq_monomorphisms_iff : MorphismProperty.injective C = monomorphisms C ↔ (forget C).PreservesMonomorphisms := by constructor · intro h constructor rintro _ _ f (hf : monomorphisms C f) rw [mono_iff_injective] rw [← h] at hf exact hf · intro apply le_antisymm (injective_le_monomorphisms C) intro _ _ f hf have : Mono f := hf change Function.Injective ((forget C).map f) rw [← mono_iff_injective] infer_instance lemma injective_eq_monomorphisms [(forget C).PreservesMonomorphisms] : MorphismProperty.injective C = monomorphisms C := by rw [injective_eq_monomorphisms_iff] infer_instance lemma surjective_eq_epimorphisms [(forget C).PreservesEpimorphisms] : MorphismProperty.surjective C = epimorphisms C := by rw [surjective_eq_epimorphisms_iff] infer_instance variable [HasStrongEpiMonoFactorisations C] [(forget C).PreservesMonomorphisms] [(forget C).PreservesEpimorphisms] /-- A concrete category with strong epi mono factorizations and such that the forget functor preserves mono and epi admits functorial surjective/injective factorizations. -/ noncomputable def functorialSurjectiveInjectiveFactorizationData : FunctorialSurjectiveInjectiveFactorizationData C := (functorialEpiMonoFactorizationData C).ofLE (by rw [surjective_eq_epimorphisms]) (by rw [injective_eq_monomorphisms]) instance (priority := 100) : HasFunctorialSurjectiveInjectiveFactorization C where nonempty_functorialFactorizationData := ⟨functorialSurjectiveInjectiveFactorizationData C⟩ end section open CategoryTheory.Limits theorem injective_of_mono_of_preservesPullback {X Y : C} (f : X ⟶ Y) [Mono f] [PreservesLimitsOfShape WalkingCospan (forget C)] : Function.Injective f := (mono_iff_injective ((forget C).map f)).mp inferInstance theorem mono_iff_injective_of_preservesPullback {X Y : C} (f : X ⟶ Y) [PreservesLimitsOfShape WalkingCospan (forget C)] : Mono f ↔ Function.Injective f := ((forget C).mono_map_iff_mono _).symm.trans (mono_iff_injective _) /-- In any concrete category, surjective morphisms are epimorphisms. -/ theorem epi_of_surjective {X Y : C} (f : X ⟶ Y) (s : Function.Surjective f) : Epi f := (forget C).epi_of_epi_map ((epi_iff_surjective ((forget C).map f)).2 s) theorem surjective_of_epi_of_preservesPushout {X Y : C} (f : X ⟶ Y) [Epi f] [PreservesColimitsOfShape WalkingSpan (forget C)] : Function.Surjective f := (epi_iff_surjective ((forget C).map f)).mp inferInstance theorem epi_iff_surjective_of_preservesPushout {X Y : C} (f : X ⟶ Y) [PreservesColimitsOfShape WalkingSpan (forget C)] : Epi f ↔ Function.Surjective f := ((forget C).epi_map_iff_epi _).symm.trans (epi_iff_surjective _) theorem bijective_of_isIso {X Y : C} (f : X ⟶ Y) [IsIso f] : Function.Bijective f := by rw [← isIso_iff_bijective] infer_instance /-- If the forgetful functor of a concrete category reflects isomorphisms, being an isomorphism is equivalent to being bijective. -/ theorem isIso_iff_bijective [(forget C).ReflectsIsomorphisms] {X Y : C} (f : X ⟶ Y) : IsIso f ↔ Function.Bijective f := by rw [← CategoryTheory.isIso_iff_bijective] exact ⟨fun _ ↦ inferInstance, fun _ ↦ isIso_of_reflects_iso f (forget C)⟩ end end ConcreteCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/ConcreteCategory/ReflectsIso.lean
import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic /-! A `forget₂ C D` forgetful functor between concrete categories `C` and `D` whose forgetful functors both reflect isomorphisms, itself reflects isomorphisms. -/ universe u namespace CategoryTheory instance : (forget (Type u)).ReflectsIsomorphisms where reflects _ _ _ {i} := i variable (C : Type (u + 1)) [Category C] [HasForget.{u} C] variable (D : Type (u + 1)) [Category D] [HasForget.{u} D] -- This should not be an instance, as it causes a typeclass loop -- with `CategoryTheory.hasForgetToType`. /-- A `forget₂ C D` forgetful functor between concrete categories `C` and `D` where `forget C` reflects isomorphisms, itself reflects isomorphisms. -/ theorem reflectsIsomorphisms_forget₂ [HasForget₂ C D] [(forget C).ReflectsIsomorphisms] : (forget₂ C D).ReflectsIsomorphisms := { reflects := fun X Y f {i} => by haveI i' : IsIso ((forget D).map ((forget₂ C D).map f)) := Functor.map_isIso (forget D) _ haveI : IsIso ((forget C).map f) := by have := @HasForget₂.forget_comp C D rwa [← this] apply isIso_of_reflects_iso f (forget C) } end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/ConcreteCategory/Elementwise.lean
import Mathlib.Tactic.CategoryTheory.Elementwise import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.ConcreteCategory.Basic /-! In this file we provide various simp lemmas in its elementwise form via `Tactic.Elementwise`. -/ open CategoryTheory CategoryTheory.Limits set_option linter.existingAttributeWarning false in attribute [elementwise (attr := simp)] Cone.w limit.lift_π limit.w colimit.ι_desc colimit.w kernel.lift_ι cokernel.π_desc kernel.condition cokernel.condition attribute [elementwise] Cocone.w
.lake/packages/mathlib/Mathlib/CategoryTheory/ConcreteCategory/Basic.lean
import Mathlib.CategoryTheory.Types.Basic /-! # Concrete categories A concrete category is a category `C` where the objects and morphisms correspond with types and (bundled) functions between these types. We define concrete categories using `class ConcreteCategory`. To convert an object to a type, write `ToHom`. To convert a morphism to a (bundled) function, write `hom`. Each concrete category `C` comes with a canonical faithful functor `forget C : C ⥤ Type*`, see `class HasForget`. In particular, we impose no restrictions on the category `C`, so `Type` has the identity forgetful functor. We say that a concrete category `C` admits a *forgetful functor* to a concrete category `D`, if it has a functor `forget₂ C D : C ⥤ D` such that `(forget₂ C D) ⋙ (forget D) = forget C`, see `class HasForget₂`. Due to `Faithful.div_comp`, it suffices to verify that `forget₂.obj` and `forget₂.map` agree with the equality above; then `forget₂` will satisfy the functor laws automatically, see `HasForget₂.mk'`. Two classes helping construct concrete categories in the two most common cases are provided in the files `BundledHom` and `UnbundledHom`, see their documentation for details. ## Implementation notes We are currently switching over from `HasForget` to a new class `ConcreteCategory`, see Zulip thread: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Concrete.20category.20class.20redesign Previously, `ConcreteCategory` had the same definition as now `HasForget`; the coercion of objects/morphisms to types/functions was defined as `(forget C).obj` and `(forget C).map` respectively. This leads to defeq issues since existing `CoeFun` and `FunLike` instances provide their own casts. We replace this with a less bundled `ConcreteCategory` that does not directly use these coercions. We do not use `CoeSort` to convert objects in a concrete category to types, since this would lead to elaboration mismatches between results taking a `[ConcreteCategory C]` instance and specific types `C` that hold a `ConcreteCategory C` instance: the first gets a literal `CoeSort.coe` and the second gets unfolded to the actual `coe` field. `ToType` and `ToHom` are `abbrev`s so that we do not need to copy over instances such as `Ring` or `RingHomClass` respectively. Since `X → Y` is not a `FunLike`, the category of types is not a `ConcreteCategory`, but it does have a `HasForget` instance. ## References See [Ahrens and Lumsdaine, *Displayed Categories*][ahrens2017] for related work. -/ assert_not_exists CategoryTheory.CommSq CategoryTheory.Adjunction universe w w' v v' v'' u u' u'' namespace CategoryTheory /-- A concrete category is a category `C` with a fixed faithful functor `Forget : C ⥤ Type`. Note that `HasForget` potentially depends on three independent universe levels, * the universe level `w` appearing in `Forget : C ⥤ Type w` * the universe level `v` of the morphisms (i.e. we have a `Category.{v} C`) * the universe level `u` of the objects (i.e `C : Type u`) They are specified that order, to avoid unnecessary universe annotations. -/ class HasForget (C : Type u) [Category.{v} C] where /-- We have a functor to Type -/ protected forget : C ⥤ Type w /-- That functor is faithful -/ [forget_faithful : forget.Faithful] attribute [inline, reducible] HasForget.forget attribute [instance] HasForget.forget_faithful /-- The forgetful functor from a concrete category to `Type u`. -/ abbrev forget (C : Type u) [Category.{v} C] [HasForget.{w} C] : C ⥤ Type w := HasForget.forget -- this is reducible because we want `forget (Type u)` to unfold to `𝟭 _` @[instance] abbrev HasForget.types : HasForget.{u, u, u + 1} (Type u) where forget := 𝟭 _ /-- Provide a coercion to `Type u` for a concrete category. This is not marked as an instance as it could potentially apply to every type, and so is too expensive in typeclass search. You can use it on particular examples as: ``` instance : HasCoeToSort X := HasForget.hasCoeToSort X ``` -/ def HasForget.hasCoeToSort (C : Type u) [Category.{v} C] [HasForget.{w} C] : CoeSort C (Type w) where coe X := (forget C).obj X section attribute [local instance] HasForget.hasCoeToSort variable {C : Type u} [Category.{v} C] [HasForget.{w} C] /-- In any concrete category, `(forget C).map` is injective. -/ abbrev HasForget.instFunLike {X Y : C} : FunLike (X ⟶ Y) X Y where coe f := (forget C).map f coe_injective' _ _ h := (forget C).map_injective h attribute [local instance] HasForget.instFunLike /-- In any concrete category, we can test equality of morphisms by pointwise evaluations. -/ @[ext low] theorem ConcreteCategory.hom_ext {X Y : C} (f g : X ⟶ Y) (w : ∀ x : X, f x = g x) : f = g := by apply (forget C).map_injective dsimp [forget] funext x exact w x theorem forget_map_eq_coe {X Y : C} (f : X ⟶ Y) : (forget C).map f = f := rfl /-- Analogue of `congr_fun h x`, when `h : f = g` is an equality between morphisms in a concrete category. -/ theorem congr_hom {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x := congrFun (congrArg (fun k : X ⟶ Y => (k : X → Y)) h) x theorem coe_id {X : C} : (𝟙 X : X → X) = id := (forget _).map_id X theorem coe_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g : X → Z) = g ∘ f := (forget _).map_comp f g @[simp] theorem id_apply {X : C} (x : X) : (𝟙 X : X → X) x = x := congr_fun ((forget _).map_id X) x @[simp] theorem comp_apply {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := congr_fun ((forget _).map_comp _ _) x /-- Variation of `ConcreteCategory.comp_apply` that uses `forget` instead. -/ theorem comp_apply' {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (forget C).map (f ≫ g) x = (forget C).map g ((forget C).map f x) := comp_apply f g x theorem ConcreteCategory.congr_hom {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x := congr_fun (congr_arg (fun f : X ⟶ Y => (f : X → Y)) h) x theorem ConcreteCategory.congr_arg {X Y : C} (f : X ⟶ Y) {x x' : X} (h : x = x') : f x = f x' := congrArg (f : X → Y) h @[simp] theorem ConcreteCategory.hasCoeToFun_Type {X Y : Type u} (f : X ⟶ Y) : CoeFun.coe f = f := rfl end /-- `HasForget₂ C D`, where `C` and `D` are both concrete categories, provides a functor `forget₂ C D : C ⥤ D` and a proof that `forget₂ ⋙ (forget D) = forget C`. -/ class HasForget₂ (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] where /-- A functor from `C` to `D` -/ forget₂ : C ⥤ D /-- It covers the `HasForget.forget` for `C` and `D` -/ forget_comp : forget₂ ⋙ forget D = forget C := by aesop /-- The forgetful functor `C ⥤ D` between concrete categories for which we have an instance `HasForget₂ C`. -/ abbrev forget₂ (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] : C ⥤ D := HasForget₂.forget₂ attribute [local instance] HasForget.instFunLike HasForget.hasCoeToSort lemma forget₂_comp_apply {C : Type u} {D : Type u'} [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : (forget₂ C D).obj X) : ((forget₂ C D).map (f ≫ g) x) = (forget₂ C D).map g ((forget₂ C D).map f x) := by rw [Functor.map_comp, comp_apply] instance forget₂_faithful (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] : (forget₂ C D).Faithful := HasForget₂.forget_comp.faithful_of_comp instance InducedCategory.hasForget {C : Type u} {D : Type u'} [Category.{v'} D] [HasForget.{w} D] (f : C → D) : HasForget (InducedCategory D f) where forget := inducedFunctor f ⋙ forget D instance InducedCategory.hasForget₂ {C : Type u} {D : Type u'} [Category.{v} D] [HasForget.{w} D] (f : C → D) : HasForget₂ (InducedCategory D f) D where forget₂ := inducedFunctor f forget_comp := rfl instance FullSubcategory.hasForget {C : Type u} [Category.{v} C] [HasForget.{w} C] (P : ObjectProperty C) : HasForget P.FullSubcategory where forget := P.ι ⋙ forget C instance FullSubcategory.hasForget₂ {C : Type u} [Category.{v} C] [HasForget.{w} C] (P : ObjectProperty C) : HasForget₂ P.FullSubcategory C where forget₂ := P.ι forget_comp := rfl /-- In order to construct a “partially forgetting” functor, we do not need to verify functor laws; it suffices to ensure that compositions agree with `forget₂ C D ⋙ forget D = forget C`. -/ def HasForget₂.mk' {C : Type u} {D : Type u'} [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] (obj : C → D) (h_obj : ∀ X, (forget D).obj (obj X) = (forget C).obj X) (map : ∀ {X Y}, (X ⟶ Y) → (obj X ⟶ obj Y)) (h_map : ∀ {X Y} {f : X ⟶ Y}, (forget D).map (map f) ≍ (forget C).map f) : HasForget₂ C D where forget₂ := Functor.Faithful.div _ _ _ @h_obj _ @h_map forget_comp := by apply Functor.Faithful.div_comp /-- Composition of `HasForget₂` instances. -/ @[reducible] def HasForget₂.trans (C : Type u) [Category.{v} C] [HasForget.{w} C] (D : Type u') [Category.{v'} D] [HasForget.{w} D] (E : Type u'') [Category.{v''} E] [HasForget.{w} E] [HasForget₂ C D] [HasForget₂ D E] : HasForget₂ C E where forget₂ := CategoryTheory.forget₂ C D ⋙ CategoryTheory.forget₂ D E forget_comp := by change (CategoryTheory.forget₂ _ D) ⋙ (CategoryTheory.forget₂ D E ⋙ CategoryTheory.forget E) = _ simp only [HasForget₂.forget_comp] /-- Every forgetful functor factors through the identity functor. This is not a global instance as it is prone to creating type class resolution loops. -/ def hasForgetToType (C : Type u) [Category.{v} C] [HasForget.{w} C] : HasForget₂ C (Type w) where forget₂ := forget C forget_comp := Functor.comp_id _ section ConcreteCategory /-- A concrete category is a category `C` where objects correspond to types and morphisms to (bundled) functions between those types. In other words, it has a fixed faithful functor `forget : C ⥤ Type`. Note that `ConcreteCategory` potentially depends on three independent universe levels, * the universe level `w` appearing in `forget : C ⥤ Type w` * the universe level `v` of the morphisms (i.e. we have a `Category.{v} C`) * the universe level `u` of the objects (i.e `C : Type u`) They are specified that order, to avoid unnecessary universe annotations. -/ class ConcreteCategory (C : Type u) [Category.{v} C] (FC : outParam <| C → C → Type*) {CC : outParam <| C → Type w} [outParam <| ∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] where /-- Convert a morphism of `C` to a bundled function. -/ (hom : ∀ {X Y}, (X ⟶ Y) → FC X Y) /-- Convert a bundled function to a morphism of `C`. -/ (ofHom : ∀ {X Y}, FC X Y → (X ⟶ Y)) (hom_ofHom : ∀ {X Y} (f : FC X Y), hom (ofHom f) = f := by cat_disch) (ofHom_hom : ∀ {X Y} (f : X ⟶ Y), ofHom (hom f) = f := by cat_disch) (id_apply : ∀ {X} (x : CC X), hom (𝟙 X) x = x := by cat_disch) (comp_apply : ∀ {X Y Z} (f : X ⟶ Y) (g : Y ⟶ Z) (x : CC X), hom (f ≫ g) x = hom g (hom f x) := by cat_disch) export ConcreteCategory (id_apply comp_apply) variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory C FC] /-- `ToType X` converts the object `X` of the concrete category `C` to a type. This is an `abbrev` so that instances on `X` (e.g. `Ring`) do not need to be redeclared. -/ @[nolint unusedArguments] -- Need the instance to trigger unification that finds `CC`. abbrev ToType [ConcreteCategory C FC] := CC /-- `ToHom X Y` is the type of (bundled) functions between objects `X Y : C`. This is an `abbrev` so that instances (e.g. `RingHomClass`) do not need to be redeclared. -/ @[nolint unusedArguments] -- Need the instance to trigger unification that finds `FC`. abbrev ToHom [ConcreteCategory C FC] := FC namespace ConcreteCategory attribute [simp] id_apply comp_apply /-- We can apply morphisms of concrete categories by first casting them down to the base functions. -/ instance {X Y : C} : CoeFun (X ⟶ Y) (fun _ ↦ ToType X → ToType Y) where coe f := hom f /-- `ConcreteCategory.hom` bundled as an `Equiv`. -/ def homEquiv {X Y : C} : (X ⟶ Y) ≃ ToHom X Y where toFun := hom invFun := ofHom left_inv := ofHom_hom right_inv := hom_ofHom lemma hom_bijective {X Y : C} : Function.Bijective (hom : (X ⟶ Y) → ToHom X Y) := homEquiv.bijective lemma hom_injective {X Y : C} : Function.Injective (hom : (X ⟶ Y) → ToHom X Y) := hom_bijective.injective /-- In any concrete category, we can test equality of morphisms by pointwise evaluations. -/ @[ext] lemma ext {X Y : C} {f g : X ⟶ Y} (h : hom f = hom g) : f = g := hom_injective h lemma coe_ext {X Y : C} {f g : X ⟶ Y} (h : ⇑(hom f) = ⇑(hom g)) : f = g := ext (DFunLike.coe_injective h) lemma ext_apply {X Y : C} {f g : X ⟶ Y} (h : ∀ x, f x = g x) : f = g := ext (DFunLike.ext _ _ h) /-- A concrete category comes with a forgetful functor to `Type`. Warning: because of the way that `ConcreteCategory` and `HasForget` are set up, we can't make `forget Type` reducibly defeq to the identity functor. -/ instance toHasForget : HasForget C where forget.obj := ToType forget.map f := ⇑(hom f) forget_faithful.map_injective h := coe_ext h end ConcreteCategory theorem forget_obj (X : C) : (forget C).obj X = ToType X := rfl @[simp] theorem ConcreteCategory.forget_map_eq_coe {X Y : C} (f : X ⟶ Y) : (forget C).map f = f := rfl /-- Analogue of `congr_fun h x`, when `h : f = g` is an equality between morphisms in a concrete category. -/ protected theorem congr_fun {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : ToType X) : f x = g x := congrFun (congrArg (fun k : X ⟶ Y => (k : ToType X → ToType Y)) h) x /-- Analogue of `congr_arg f h`, when `h : x = x'` is an equality between elements of objects in a concrete category. -/ protected theorem congr_arg {X Y : C} (f : X ⟶ Y) {x x' : ToType X} (h : x = x') : f x = f x' := congrArg (f : ToType X → ToType Y) h theorem hom_id {X : C} : (𝟙 X : ToType X → ToType X) = id := (forget _).map_id X theorem hom_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g : ToType X → ToType Z) = g ∘ f := (forget _).map_comp f g /-- Using the `FunLike` coercion of `HasForget` does the same as the original coercion. -/ theorem coe_toHasForget_instFunLike {C : Type*} [Category C] {FC : C → C → Type*} {CC : C → Type*} [inst : ∀ X Y : C, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC] {X Y : C} (f : X ⟶ Y) : @DFunLike.coe (X ⟶ Y) (ToType X) (fun _ => ToType Y) HasForget.instFunLike f = f := rfl lemma ConcreteCategory.forget₂_comp_apply {C : Type u} {D : Type u'} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] [Category.{v'} D] {FD : D → D → Type*} {CD : D → Type w} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{w} D FD] [HasForget₂ C D] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : ToType ((forget₂ C D).obj X)) : ((forget₂ C D).map (f ≫ g) x) = (forget₂ C D).map g ((forget₂ C D).map f x) := by rw [Functor.map_comp, ConcreteCategory.comp_apply] instance hom_isIso {X Y : C} (f : X ⟶ Y) [IsIso f] : IsIso (C := Type _) ⇑(ConcreteCategory.hom f) := ((forget C).mapIso (asIso f)).isIso_hom @[simp] lemma NatTrans.naturality_apply {C D : Type*} [Category C] [Category D] {FD : D → D → Type*} {CD : D → Type*} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory D FD] {F G : C ⥤ D} (φ : F ⟶ G) {X Y : C} (f : X ⟶ Y) (x : ToType (F.obj X)) : φ.app Y (F.map f x) = G.map f (φ.app X x) := by simpa only [Functor.map_comp] using congr_fun ((forget D).congr_map (φ.naturality f)) x section variable (C) /-- Build a coercion to functions out of `HasForget`. The intended usecase is to provide a `FunLike` instance in `HasForget.toConcreteCategory`. See that definition for the considerations in making this an instance. See note [reducible non-instances]. -/ abbrev HasForget.toFunLike [HasForget C] (X Y : C) : FunLike (X ⟶ Y) ((forget C).obj X) ((forget C).obj Y) where coe := (forget C).map coe_injective' _ _ h := Functor.Faithful.map_injective h /-- Build a concrete category out of `HasForget`. The intended usecase is to prove theorems referencing only `(forget C)` and not `(forget C).obj X` nor `(forget C).map f`: those should be written as `ToType X` and `ConcreteCategory.hom f` respectively. See note [reducible non-instances]. -/ abbrev HasForget.toConcreteCategory [HasForget C] : ConcreteCategory C (· ⟶ ·) where hom f := f ofHom f := f id_apply := congr_fun ((forget C).map_id _) comp_apply _ _ := congr_fun ((forget C).map_comp _ _) /-- Check that the new `ConcreteCategory` has the same forgetful functor as we started with. -/ example [inst : HasForget C] : @forget C _ ((HasForget.toConcreteCategory _).toHasForget) = @forget C _ inst := by with_reducible_and_instances rfl /-- Note that the `ConcreteCategory` and `HasForget` instances here differ from `forget_map_eq_coe`. -/ theorem forget_eq_ConcreteCategory_hom [HasForget C] {X Y : C} (f : X ⟶ Y) : (forget C).map f = @ConcreteCategory.hom _ _ _ _ _ (HasForget.toConcreteCategory C) _ _ f := by with_reducible_and_instances rfl /-- A `FunLike` instance on plain functions, in order to instantiate a `ConcreteCategory` structure on the category of types. This is not an instance (yet) because that would require a lot of downstream fixes. See note [reducible non-instances]. -/ abbrev Types.instFunLike : ∀ X Y : Type u, FunLike (X ⟶ Y) X Y := HasForget.toFunLike _ /-- The category of types is concrete, using the identity functor. This is not an instance (yet) because that would require a lot of downstream fixes. See note [reducible non-instances]. -/ abbrev Types.instConcreteCategory : ConcreteCategory (Type u) (fun X Y => X ⟶ Y) where hom f := f ofHom f := f end open ConcreteCategory instance InducedCategory.concreteCategory {C : Type u} {D : Type u'} [Category.{v'} D] {FD : D → D → Type*} {CD : D → Type w} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{w} D FD] (f : C → D) : ConcreteCategory (InducedCategory D f) (fun X Y => FD (f X) (f Y)) where hom := hom (C := D) ofHom := ofHom (C := D) hom_ofHom := hom_ofHom (C := D) ofHom_hom := ofHom_hom (C := D) comp_apply := ConcreteCategory.comp_apply (C := D) id_apply := ConcreteCategory.id_apply (C := D) instance FullSubcategory.concreteCategory {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] (P : ObjectProperty C) : ConcreteCategory P.FullSubcategory (fun X Y => FC X.1 Y.1) where hom := hom (C := C) ofHom := ofHom (C := C) hom_ofHom := hom_ofHom (C := C) ofHom_hom := ofHom_hom (C := C) comp_apply := ConcreteCategory.comp_apply (C := C) id_apply := ConcreteCategory.id_apply (C := C) end ConcreteCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/ConcreteCategory/Bundled.lean
import Mathlib.Init import Batteries.Tactic.Lint.Misc /-! # Bundled types `Bundled c` provides a uniform structure for bundling a type equipped with a type class. We provide `Category` instances for these in `Mathlib/CategoryTheory/HasForget/UnbundledHom.lean` (for categories with unbundled homs, e.g. topological spaces) and in `Mathlib/CategoryTheory/HasForget/BundledHom.lean` (for categories with bundled homs, e.g. monoids). -/ universe u v namespace CategoryTheory variable {c d : Type u → Type v} /-- `Bundled` is a type bundled with a type class instance for that type. Only the type class is exposed as a parameter. -/ structure Bundled (c : Type u → Type v) : Type max (u + 1) v where /-- The underlying type of the bundled type -/ α : Type u /-- The corresponding instance of the bundled type class -/ str : c α := by infer_instance namespace Bundled attribute [coe] α -- This is needed so that we can ask for an instance of `c α` below even though Lean doesn't know -- that `c α` is a typeclass. set_option checkBinderAnnotations false in -- Usually explicit instances will provide their own version of this, e.g. `MonCat.of` and -- `TopCat.of`. /-- A generic function for lifting a type equipped with an instance to a bundled object. -/ def of {c : Type u → Type v} (α : Type u) [str : c α] : Bundled c := ⟨α, str⟩ instance coeSort : CoeSort (Bundled c) (Type u) := ⟨Bundled.α⟩ theorem coe_mk (α) (str) : (@Bundled.mk c α str : Type u) = α := rfl /-- Map over the bundled structure -/ abbrev map (f : ∀ {α}, c α → d α) (b : Bundled c) : Bundled d := ⟨b, f b.str⟩ end Bundled end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/ConcreteCategory/UnbundledHom.lean
import Mathlib.CategoryTheory.ConcreteCategory.BundledHom /-! # Category instances for structures that use unbundled homs This file provides basic infrastructure to define concrete categories using unbundled homs (see `class UnbundledHom`), and define forgetful functors between them (see `UnbundledHom.mkHasForget₂`). -/ universe v u namespace CategoryTheory /-- A class for unbundled homs used to define a category. `hom` must take two types `α`, `β` and instances of the corresponding structures, and return a predicate on `α → β`. -/ class UnbundledHom {c : Type u → Type u} (hom : ∀ ⦃α β⦄, c α → c β → (α → β) → Prop) : Prop where hom_id : ∀ {α} (ia : c α), hom ia ia id hom_comp : ∀ {α β γ} {Iα : c α} {Iβ : c β} {Iγ : c γ} {g : β → γ} {f : α → β} (_ : hom Iβ Iγ g) (_ : hom Iα Iβ f), hom Iα Iγ (g ∘ f) namespace UnbundledHom variable (c : Type u → Type u) (hom : ∀ ⦃α β⦄, c α → c β → (α → β) → Prop) [𝒞 : UnbundledHom hom] instance bundledHom : BundledHom fun α β (Iα : c α) (Iβ : c β) => Subtype (hom Iα Iβ) where toFun _ _ := Subtype.val id Iα := ⟨id, hom_id Iα⟩ id_toFun _ := rfl comp _ _ _ g f := ⟨g.1 ∘ f.1, hom_comp g.2 f.2⟩ comp_toFun _ _ _ _ _ := rfl hom_ext _ _ _ _ := Subtype.eq section HasForget₂ variable {c hom} {c' : Type u → Type u} {hom' : ∀ ⦃α β⦄, c' α → c' β → (α → β) → Prop} [𝒞' : UnbundledHom hom'] variable (obj : ∀ ⦃α⦄, c α → c' α) (map : ∀ ⦃α β Iα Iβ f⦄, @hom α β Iα Iβ f → hom' (obj Iα) (obj Iβ) f) /-- A custom constructor for forgetful functor between concrete categories defined using `UnbundledHom`. -/ def mkHasForget₂ : HasForget₂ (Bundled c) (Bundled c') := BundledHom.mkHasForget₂ obj (fun f => ⟨f.val, map f.property⟩) fun _ => rfl end HasForget₂ end UnbundledHom end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/ConcreteCategory/BundledHom.lean
import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.ConcreteCategory.Bundled /-! # Category instances for algebraic structures that use bundled homs. Many algebraic structures in Lean initially used unbundled homs (e.g. a bare function between types, along with an `IsMonoidHom` typeclass), but the general trend is towards using bundled homs. This file provides a basic infrastructure to define concrete categories using bundled homs, and define forgetful functors between them. -/ universe u namespace CategoryTheory variable {c : Type u → Type u} (hom : ∀ ⦃α β : Type u⦄ (_ : c α) (_ : c β), Type u) /-- Class for bundled homs. Note that the arguments order follows that of lemmas for `MonoidHom`. This way we can use `⟨@MonoidHom.toFun, @MonoidHom.id ...⟩` in an instance. -/ structure BundledHom where /-- the underlying map of a bundled morphism -/ toFun : ∀ {α β : Type u} (Iα : c α) (Iβ : c β), hom Iα Iβ → α → β /-- the identity as a bundled morphism -/ id : ∀ {α : Type u} (I : c α), hom I I /-- composition of bundled morphisms -/ comp : ∀ {α β γ : Type u} (Iα : c α) (Iβ : c β) (Iγ : c γ), hom Iβ Iγ → hom Iα Iβ → hom Iα Iγ /-- a bundled morphism is determined by the underlying map -/ hom_ext : ∀ {α β : Type u} (Iα : c α) (Iβ : c β), Function.Injective (toFun Iα Iβ) := by cat_disch /-- compatibility with identities -/ id_toFun : ∀ {α : Type u} (I : c α), toFun I I (id I) = _root_.id := by cat_disch /-- compatibility with the composition -/ comp_toFun : ∀ {α β γ : Type u} (Iα : c α) (Iβ : c β) (Iγ : c γ) (f : hom Iα Iβ) (g : hom Iβ Iγ), toFun Iα Iγ (comp Iα Iβ Iγ g f) = toFun Iβ Iγ g ∘ toFun Iα Iβ f := by cat_disch attribute [class] BundledHom attribute [simp] BundledHom.id_toFun BundledHom.comp_toFun namespace BundledHom variable [𝒞 : BundledHom hom] set_option synthInstance.checkSynthOrder false in /-- Every `@BundledHom c _` defines a category with objects in `Bundled c`. This instance generates the type-class problem `BundledHom ?m`. Currently that is not a problem, as there are almost no instances of `BundledHom`. -/ instance category : Category (Bundled c) where Hom := fun X Y => hom X.str Y.str id := fun X => BundledHom.id 𝒞 (α := X) X.str comp := fun {X Y Z} f g => BundledHom.comp 𝒞 (α := X) (β := Y) (γ := Z) X.str Y.str Z.str g f comp_id _ := by apply 𝒞.hom_ext; simp assoc _ _ _ := by apply 𝒞.hom_ext; cat_disch id_comp _ := by apply 𝒞.hom_ext; simp /-- A category given by `BundledHom` is a concrete category. -/ instance hasForget : HasForget.{u} (Bundled c) where forget := { obj := fun X => X map := fun {X Y} f => 𝒞.toFun X.str Y.str f map_id := fun X => 𝒞.id_toFun X.str map_comp := fun f g => by erw [𝒞.comp_toFun]; rfl } forget_faithful := { map_injective := by (intros; apply 𝒞.hom_ext) } /-- This unification hint helps `rw` to figure out how to apply statements about abstract concrete categories to specific concrete categories. Crucially, it fires also at `reducible` levels so `rw` can use it (and we don't have to use `erw`). -/ unif_hint (C : Bundled c) where ⊢ (CategoryTheory.forget (Bundled c)).obj C =?= Bundled.α C variable {hom} attribute [local instance] HasForget.instFunLike /-- A version of `HasForget₂.mk'` for categories defined using `@BundledHom`. -/ def mkHasForget₂ {d : Type u → Type u} {hom_d : ∀ ⦃α β : Type u⦄ (_ : d α) (_ : d β), Type u} [BundledHom hom_d] (obj : ∀ ⦃α⦄, c α → d α) (map : ∀ {X Y : Bundled c}, (X ⟶ Y) → (Bundled.map @obj X ⟶ (Bundled.map @obj Y))) (h_map : ∀ {X Y : Bundled c} (f : X ⟶ Y), ⇑(map f) = ⇑f) : HasForget₂ (Bundled c) (Bundled d) := HasForget₂.mk' (Bundled.map @obj) (fun _ => rfl) map (by intro X Y f rw [heq_eq_eq, forget_map_eq_coe, forget_map_eq_coe, h_map f]) variable {d : Type u → Type u} variable (hom) section /-- The `hom` corresponding to first forgetting along `F`, then taking the `hom` associated to `c`. For typical usage, see the construction of `CommMonCat` from `MonCat`. -/ abbrev MapHom (F : ∀ {α}, d α → c α) : ∀ ⦃α β : Type u⦄ (_ : d α) (_ : d β), Type u := fun _ _ iα iβ => hom (F iα) (F iβ) end /-- Construct the `CategoryTheory.BundledHom` induced by a map between type classes. This is useful for building categories such as `CommMonCat` from `MonCat`. -/ def map (F : ∀ {α}, d α → c α) : BundledHom (MapHom hom @F) where toFun _ _ {iα} {iβ} f := 𝒞.toFun (F iα) (F iβ) f id _ {iα} := 𝒞.id (F iα) comp := @fun _ _ _ iα iβ iγ f g => 𝒞.comp (F iα) (F iβ) (F iγ) f g hom_ext := @fun _ _ iα iβ _ _ h => 𝒞.hom_ext (F iα) (F iβ) h section /-- We use the empty `ParentProjection` class to label functions like `CommMonoid.toMonoid`, which we would like to use to automatically construct `BundledHom` instances from. Once we've set up `MonCat` as the category of bundled monoids, this allows us to set up `CommMonCat` by defining an instance ```instance : ParentProjection (CommMonoid.toMonoid) := ⟨⟩``` -/ class ParentProjection (F : ∀ {α}, d α → c α) : Prop end -- The `ParentProjection` typeclass is just a marker, so won't be used. @[nolint unusedArguments] instance bundledHomOfParentProjection (F : ∀ {α}, d α → c α) [ParentProjection @F] : BundledHom (MapHom hom @F) := map hom @F instance forget₂ (F : ∀ {α}, d α → c α) [ParentProjection @F] : HasForget₂ (Bundled d) (Bundled c) where forget₂ := { obj := fun X => ⟨X, F X.2⟩ map := @fun _ _ f => f } instance forget₂_full (F : ∀ {α}, d α → c α) [ParentProjection @F] : Functor.Full (CategoryTheory.forget₂ (Bundled d) (Bundled c)) where map_surjective f := ⟨f, rfl⟩ end BundledHom end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/FunctorToTypes.lean
import Mathlib.CategoryTheory.Functor.FunctorHom import Mathlib.CategoryTheory.Closed.Monoidal /-! # Functors to Type are closed. Show that `C ⥤ Type max w v u` is monoidal closed for `C` a category in `Type u` with morphisms in `Type v`, and `w` an arbitrary universe. ## TODO It should be shown that `C ⥤ Type max w v u` is Cartesian closed. -/ universe w v' v u u' open CategoryTheory Functor MonoidalCategory namespace CategoryTheory.FunctorToTypes variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] variable (F : C ⥤ Type max w v u) /-- When `F G H : C ⥤ Type max w v u`, we have `(G ⟶ F.functorHom H) ≃ (F ⊗ G ⟶ H)`. -/ @[simps!] def functorHomEquiv (G H : C ⥤ Type max w v u) : (G ⟶ F.functorHom H) ≃ (F ⊗ G ⟶ H) := (Functor.functorHomEquiv F H G).trans (homObjEquiv F H G) /-- Given a morphism `f : G ⟶ H`, an object `c : C`, and an element of `(F.functorHom G).obj c`, construct an element of `(F.functorHom H).obj c`. -/ @[simps] def rightAdj_map {F G H : C ⥤ Type max w v u} (f : G ⟶ H) (c : C) (a : (F.functorHom G).obj c) : (F.functorHom H).obj c where app d b := a.app d b ≫ f.app d naturality g h := by have := a.naturality g h change (F.map g ≫ a.app _ (h ≫ g)) ≫ _ = _ aesop /-- A right adjoint of `tensorLeft F`. -/ @[simps!] def rightAdj : (C ⥤ Type max w v u) ⥤ C ⥤ Type max w v u where obj G := F.functorHom G map f := { app := rightAdj_map f } /-- The adjunction `tensorLeft F ⊣ rightAdj F`. -/ def adj : tensorLeft F ⊣ rightAdj F where unit := { app := fun G ↦ (functorHomEquiv F G _).2 (𝟙 _) naturality := fun G H f ↦ by dsimp [rightAdj] ext _ simp [FunctorToTypes.naturality] } counit := { app := fun G ↦ functorHomEquiv F _ G (𝟙 _) } instance closed : Closed F where rightAdj := rightAdj F adj := adj F instance monoidalClosed : MonoidalClosed (C ⥤ Type max w v u) where end CategoryTheory.FunctorToTypes
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/Monoidal.lean
import Mathlib.CategoryTheory.Monoidal.Functor import Mathlib.CategoryTheory.Monoidal.CoherenceLemmas import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Adjunction.Mates import Mathlib.CategoryTheory.Adjunction.Parametrized /-! # Closed monoidal categories Define (right) closed objects and (right) closed monoidal categories. ## TODO Some of the theorems proved about Cartesian closed categories should be generalised and moved to this file. -/ universe v u u₂ v₂ namespace CategoryTheory open Category MonoidalCategory -- Note that this class carries a particular choice of right adjoint, -- (which is only unique up to isomorphism), -- not merely the existence of such, and -- so definitional properties of instances may be important. /-- An object `X` is (right) closed if `(X ⊗ -)` is a left adjoint. -/ class Closed {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] (X : C) where /-- a choice of a right adjoint for `tensorLeft X` -/ rightAdj : C ⥤ C /-- `tensorLeft X` is a left adjoint -/ adj : tensorLeft X ⊣ rightAdj /-- A monoidal category `C` is (right) monoidal closed if every object is (right) closed. -/ class MonoidalClosed (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] where closed (X : C) : Closed X := by infer_instance attribute [instance 100] MonoidalClosed.closed variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] /-- If `X` and `Y` are closed then `X ⊗ Y` is. This isn't an instance because it's not usually how we want to construct internal homs, we'll usually prove all objects are closed uniformly. -/ def tensorClosed {X Y : C} (hX : Closed X) (hY : Closed Y) : Closed (X ⊗ Y) where rightAdj := Closed.rightAdj X ⋙ Closed.rightAdj Y adj := (hY.adj.comp hX.adj).ofNatIsoLeft (MonoidalCategory.tensorLeftTensor X Y).symm /-- The unit object is always closed. This isn't an instance because most of the time we'll prove closedness for all objects at once, rather than just for this one. -/ def unitClosed : Closed (𝟙_ C) where rightAdj := 𝟭 C adj := Adjunction.id.ofNatIsoLeft (MonoidalCategory.leftUnitorNatIso C).symm variable (A B : C) {X X' Y Y' Z : C} variable [Closed A] /-- This is the internal hom `A ⟶[C] -`. -/ def ihom : C ⥤ C := Closed.rightAdj (X := A) namespace ihom /-- The adjunction between `A ⊗ -` and `A ⟹ -`. -/ def adjunction : tensorLeft A ⊣ ihom A := Closed.adj instance : (tensorLeft A).IsLeftAdjoint := (ihom.adjunction A).isLeftAdjoint /-- The evaluation natural transformation. -/ def ev : ihom A ⋙ tensorLeft A ⟶ 𝟭 C := (ihom.adjunction A).counit /-- The coevaluation natural transformation. -/ def coev : 𝟭 C ⟶ tensorLeft A ⋙ ihom A := (ihom.adjunction A).unit @[simp] theorem ihom_adjunction_counit : (ihom.adjunction A).counit = ev A := rfl @[simp] theorem ihom_adjunction_unit : (ihom.adjunction A).unit = coev A := rfl @[reassoc (attr := simp)] theorem ev_naturality {X Y : C} (f : X ⟶ Y) : A ◁ (ihom A).map f ≫ (ev A).app Y = (ev A).app X ≫ f := (ev A).naturality f @[reassoc (attr := simp)] theorem coev_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (coev A).app Y = (coev A).app X ≫ (ihom A).map (A ◁ f) := (coev A).naturality f set_option quotPrecheck false in /-- `A ⟶[C] B` denotes the internal hom from `A` to `B` -/ notation A " ⟶[" C "] " B:10 => (@ihom C _ _ A _).obj B @[reassoc (attr := simp)] theorem ev_coev : (A ◁ (coev A).app B) ≫ (ev A).app (A ⊗ B) = 𝟙 (A ⊗ B) := (ihom.adjunction A).left_triangle_components _ @[reassoc (attr := simp)] theorem coev_ev : (coev A).app (A ⟶[C] B) ≫ (ihom A).map ((ev A).app B) = 𝟙 (A ⟶[C] B) := Adjunction.right_triangle_components (ihom.adjunction A) _ end ihom open CategoryTheory.Limits instance : PreservesColimits (tensorLeft A) := (ihom.adjunction A).leftAdjoint_preservesColimits variable {A} -- Wrap these in a namespace so we don't clash with the core versions. namespace MonoidalClosed /-- Currying in a monoidal closed category. -/ def curry : (A ⊗ Y ⟶ X) → (Y ⟶ A ⟶[C] X) := (ihom.adjunction A).homEquiv _ _ /-- Uncurrying in a monoidal closed category. -/ def uncurry : (Y ⟶ A ⟶[C] X) → (A ⊗ Y ⟶ X) := ((ihom.adjunction A).homEquiv _ _).symm theorem homEquiv_apply_eq (f : A ⊗ Y ⟶ X) : (ihom.adjunction A).homEquiv _ _ f = curry f := rfl theorem homEquiv_symm_apply_eq (f : Y ⟶ A ⟶[C] X) : ((ihom.adjunction A).homEquiv _ _).symm f = uncurry f := rfl @[reassoc] theorem curry_natural_left (f : X ⟶ X') (g : A ⊗ X' ⟶ Y) : curry (_ ◁ f ≫ g) = f ≫ curry g := Adjunction.homEquiv_naturality_left _ _ _ @[reassoc] theorem curry_natural_right (f : A ⊗ X ⟶ Y) (g : Y ⟶ Y') : curry (f ≫ g) = curry f ≫ (ihom _).map g := Adjunction.homEquiv_naturality_right _ _ _ @[reassoc] theorem uncurry_natural_right (f : X ⟶ A ⟶[C] Y) (g : Y ⟶ Y') : uncurry (f ≫ (ihom _).map g) = uncurry f ≫ g := Adjunction.homEquiv_naturality_right_symm _ _ _ @[reassoc] theorem uncurry_natural_left (f : X ⟶ X') (g : X' ⟶ A ⟶[C] Y) : uncurry (f ≫ g) = _ ◁ f ≫ uncurry g := Adjunction.homEquiv_naturality_left_symm _ _ _ @[simp] theorem uncurry_curry (f : A ⊗ X ⟶ Y) : uncurry (curry f) = f := (Closed.adj.homEquiv _ _).left_inv f @[simp] theorem curry_uncurry (f : X ⟶ A ⟶[C] Y) : curry (uncurry f) = f := (Closed.adj.homEquiv _ _).right_inv f theorem curry_eq_iff (f : A ⊗ Y ⟶ X) (g : Y ⟶ A ⟶[C] X) : curry f = g ↔ f = uncurry g := Adjunction.homEquiv_apply_eq (ihom.adjunction A) f g theorem eq_curry_iff (f : A ⊗ Y ⟶ X) (g : Y ⟶ A ⟶[C] X) : g = curry f ↔ uncurry g = f := Adjunction.eq_homEquiv_apply (ihom.adjunction A) f g -- I don't think these two should be simp. theorem uncurry_eq (g : Y ⟶ A ⟶[C] X) : uncurry g = (A ◁ g) ≫ (ihom.ev A).app X := by rfl theorem curry_eq (g : A ⊗ Y ⟶ X) : curry g = (ihom.coev A).app Y ≫ (ihom A).map g := rfl theorem curry_injective : Function.Injective (curry : (A ⊗ Y ⟶ X) → (Y ⟶ A ⟶[C] X)) := (Closed.adj.homEquiv _ _).injective theorem uncurry_injective : Function.Injective (uncurry : (Y ⟶ A ⟶[C] X) → (A ⊗ Y ⟶ X)) := (Closed.adj.homEquiv _ _).symm.injective variable (A X) theorem uncurry_id_eq_ev : uncurry (𝟙 (A ⟶[C] X)) = (ihom.ev A).app X := by simp [uncurry_eq] theorem curry_id_eq_coev : curry (𝟙 _) = (ihom.coev A).app X := by rw [curry_eq, (ihom A).map_id (A ⊗ _)] apply comp_id @[reassoc (attr := simp)] lemma whiskerLeft_curry_ihom_ev_app (g : A ⊗ Y ⟶ X) : A ◁ curry g ≫ (ihom.ev A).app X = g := by simp [curry_eq] theorem uncurry_ihom_map (g : Y ⟶ Y') : uncurry ((ihom A).map g) = (ihom.ev A).app Y ≫ g := by apply curry_injective rw [curry_uncurry, curry_natural_right, ← uncurry_id_eq_ev, curry_uncurry, id_comp] /-- The internal hom out of the unit is naturally isomorphic to the identity functor. -/ def unitNatIso [Closed (𝟙_ C)] : 𝟭 C ≅ ihom (𝟙_ C) := conjugateIsoEquiv (Adjunction.id (C := C)) (ihom.adjunction (𝟙_ C)) (leftUnitorNatIso C) section Pre variable {A B} variable [Closed B] /-- Pre-compose an internal hom with an external hom. -/ def pre (f : B ⟶ A) : ihom A ⟶ ihom B := conjugateEquiv (ihom.adjunction _) (ihom.adjunction _) ((tensoringLeft C).map f) @[reassoc (attr := simp)] theorem id_tensor_pre_app_comp_ev (f : B ⟶ A) (X : C) : B ◁ (pre f).app X ≫ (ihom.ev B).app X = f ▷ (A ⟶[C] X) ≫ (ihom.ev A).app X := conjugateEquiv_counit _ _ ((tensoringLeft C).map f) X @[simp] theorem uncurry_pre (f : B ⟶ A) (X : C) : MonoidalClosed.uncurry ((pre f).app X) = f ▷ _ ≫ (ihom.ev A).app X := by simp [uncurry_eq] @[reassoc] lemma curry_pre_app (f : B ⟶ A) {X Y : C} (g : A ⊗ Y ⟶ X) : curry g ≫ (pre f).app X = curry (f ▷ _ ≫ g) := uncurry_injective (by rw [uncurry_curry, uncurry_eq, MonoidalCategory.whiskerLeft_comp, assoc, id_tensor_pre_app_comp_ev, whisker_exchange_assoc, whiskerLeft_curry_ihom_ev_app]) @[reassoc (attr := simp)] theorem coev_app_comp_pre_app (f : B ⟶ A) : (ihom.coev A).app X ≫ (pre f).app (A ⊗ X) = (ihom.coev B).app X ≫ (ihom B).map (f ▷ _) := unit_conjugateEquiv _ _ ((tensoringLeft C).map f) X @[reassoc] lemma uncurry_pre_app (f : Y ⟶ A ⟶[C] X) (g : B ⟶ A) : uncurry (f ≫ (pre g).app X) = g ▷ _ ≫ uncurry f := curry_injective (by rw [curry_uncurry, ← curry_pre_app, curry_uncurry]) @[simp] theorem pre_id (A : C) [Closed A] : pre (𝟙 A) = 𝟙 _ := by rw [pre, Functor.map_id] apply conjugateEquiv_id @[simp] theorem pre_map {A₁ A₂ A₃ : C} [Closed A₁] [Closed A₂] [Closed A₃] (f : A₁ ⟶ A₂) (g : A₂ ⟶ A₃) : pre (f ≫ g) = pre g ≫ pre f := by rw [pre, pre, pre, conjugateEquiv_comp, (tensoringLeft C).map_comp] theorem pre_comm_ihom_map {W X Y Z : C} [Closed W] [Closed X] (f : W ⟶ X) (g : Y ⟶ Z) : (pre f).app Y ≫ (ihom W).map g = (ihom X).map g ≫ (pre f).app Z := by simp end Pre /-- The internal hom functor given by the monoidal closed structure. -/ @[simps] def internalHom [MonoidalClosed C] : Cᵒᵖ ⥤ C ⥤ C where obj X := ihom X.unop map f := pre f.unop /-- The parametrized adjunction between `curriedTensor C : C ⥤ C ⥤ C` and `internalHom : Cᵒᵖ ⥤ C ⥤ C` -/ @[simps!] def internalHomAdjunction₂ [MonoidalClosed C] : curriedTensor C ⊣₂ internalHom where adj _ := ihom.adjunction _ section OfEquiv variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] variable (F : C ⥤ D) {G : D ⥤ C} (adj : F ⊣ G) [F.Monoidal] [F.IsEquivalence] [MonoidalClosed D] /-- Transport the property of being monoidal closed across a monoidal equivalence of categories -/ noncomputable def ofEquiv : MonoidalClosed C where closed X := { rightAdj := F ⋙ ihom (F.obj X) ⋙ G adj := (adj.comp ((ihom.adjunction (F.obj X)).comp adj.toEquivalence.symm.toAdjunction)).ofNatIsoLeft (Iso.compInverseIso (H := adj.toEquivalence) (Functor.Monoidal.commTensorLeft F X)) } /-- Suppose we have a monoidal equivalence `F : C ≌ D`, with `D` monoidal closed. We can pull the monoidal closed instance back along the equivalence. For `X, Y, Z : C`, this lemma describes the resulting currying map `Hom(X ⊗ Y, Z) → Hom(Y, (X ⟶[C] Z))`. (`X ⟶[C] Z` is defined to be `F⁻¹(F(X) ⟶[D] F(Z))`, so currying in `C` is given by essentially conjugating currying in `D` by `F.`) -/ theorem ofEquiv_curry_def {X Y Z : C} (f : X ⊗ Y ⟶ Z) : letI := ofEquiv F adj MonoidalClosed.curry f = adj.homEquiv Y ((ihom (F.obj X)).obj (F.obj Z)) (MonoidalClosed.curry (adj.toEquivalence.symm.toAdjunction.homEquiv (F.obj X ⊗ F.obj Y) Z ((Iso.compInverseIso (H := adj.toEquivalence) (Functor.Monoidal.commTensorLeft F X)).hom.app Y ≫ f))) := by -- This whole proof used to be `rfl` before https://github.com/leanprover-community/mathlib4/pull/16317. change ((adj.comp ((ihom.adjunction (F.obj X)).comp adj.toEquivalence.symm.toAdjunction)).ofNatIsoLeft _).homEquiv _ _ _ = _ dsimp only [Adjunction.ofNatIsoLeft] rw [Adjunction.mkOfHomEquiv_homEquiv] dsimp rw [Adjunction.comp_homEquiv, Adjunction.comp_homEquiv] rfl /-- Suppose we have a monoidal equivalence `F : C ≌ D`, with `D` monoidal closed. We can pull the monoidal closed instance back along the equivalence. For `X, Y, Z : C`, this lemma describes the resulting uncurrying map `Hom(Y, (X ⟶[C] Z)) → Hom(X ⊗ Y ⟶ Z)`. (`X ⟶[C] Z` is defined to be `F⁻¹(F(X) ⟶[D] F(Z))`, so uncurrying in `C` is given by essentially conjugating uncurrying in `D` by `F.`) -/ theorem ofEquiv_uncurry_def {X Y Z : C} : letI := ofEquiv F adj ∀ (f : Y ⟶ (ihom X).obj Z), MonoidalClosed.uncurry f = ((Iso.compInverseIso (H := adj.toEquivalence) (Functor.Monoidal.commTensorLeft F X)).inv.app Y) ≫ (adj.toEquivalence.symm.toAdjunction.homEquiv _ _).symm (MonoidalClosed.uncurry ((adj.homEquiv _ _).symm f)) := by intro f -- This whole proof used to be `rfl` before https://github.com/leanprover-community/mathlib4/pull/16317. change (((adj.comp ((ihom.adjunction (F.obj X)).comp adj.toEquivalence.symm.toAdjunction)).ofNatIsoLeft _).homEquiv _ _).symm _ = _ dsimp only [Adjunction.ofNatIsoLeft] rw [Adjunction.mkOfHomEquiv_homEquiv] dsimp rw [Adjunction.comp_homEquiv, Adjunction.comp_homEquiv] rfl end OfEquiv -- A closed monoidal category C is always enriched over itself. -- This section contains the necessary definitions and equalities to endow C with -- the structure of a C-category, while the instance itself is defined in `Closed/Enrichment`. -- In particular, we only assume the necessary instances of `Closed x`, rather than assuming -- C comes with an instance of `MonoidalClosed` section Enriched /-- The C-identity morphism `𝟙_ C ⟶ hom(x, x)` used to equip `C` with the structure of a `C`-category -/ def id (x : C) [Closed x] : 𝟙_ C ⟶ (ihom x).obj x := curry (ρ_ x).hom /-- The *uncurried* composition morphism `x ⊗ (hom(x, y) ⊗ hom(y, z)) ⟶ (x ⊗ hom(x, y)) ⊗ hom(y, z) ⟶ y ⊗ hom(y, z) ⟶ z`. The `C`-composition morphism will be defined as the adjoint transpose of this map. -/ def compTranspose (x y z : C) [Closed x] [Closed y] : x ⊗ (ihom x).obj y ⊗ (ihom y).obj z ⟶ z := (α_ x ((ihom x).obj y) ((ihom y).obj z)).inv ≫ (ihom.ev x).app y ▷ ((ihom y).obj z) ≫ (ihom.ev y).app z /-- The `C`-composition morphism `hom(x, y) ⊗ hom(y, z) ⟶ hom(x, z)` used to equip `C` with the structure of a `C`-category -/ def comp (x y z : C) [Closed x] [Closed y] : (ihom x).obj y ⊗ (ihom y).obj z ⟶ (ihom x).obj z := curry (compTranspose x y z) /-- Unfold the definition of `id`. This exists to streamline the proofs of `MonoidalClosed.id_comp` and `MonoidalClosed.comp_id` -/ lemma id_eq (x : C) [Closed x] : id x = curry (ρ_ x).hom := rfl /-- Unfold the definition of `compTranspose`. This exists to streamline the proof of `MonoidalClosed.assoc` -/ lemma compTranspose_eq (x y z : C) [Closed x] [Closed y] : compTranspose x y z = (α_ _ _ _).inv ≫ (ihom.ev x).app y ▷ _ ≫ (ihom.ev y).app z := rfl /-- Unfold the definition of `comp`. This exists to streamline the proof of `MonoidalClosed.assoc` -/ lemma comp_eq (x y z : C) [Closed x] [Closed y] : comp x y z = curry (compTranspose x y z) := rfl /-! The proofs of associativity and unitality use the following outline: 1. Take adjoint transpose on each side of the equality (uncurry_injective) 2. Do whatever rewrites/simps are necessary to apply uncurry_curry 3. Conclude with simp -/ /-- Left unitality of the enriched structure -/ @[reassoc (attr := simp)] lemma id_comp (x y : C) [Closed x] : (λ_ ((ihom x).obj y)).inv ≫ id x ▷ _ ≫ comp x x y = 𝟙 _:= by apply uncurry_injective rw [uncurry_natural_left, uncurry_natural_left, comp_eq, uncurry_curry, id_eq, compTranspose_eq, associator_inv_naturality_middle_assoc, ← comp_whiskerRight_assoc, ← uncurry_eq, uncurry_curry, triangle_assoc_comp_right_assoc, whiskerLeft_inv_hom_assoc, uncurry_id_eq_ev _ _] /-- Right unitality of the enriched structure -/ @[reassoc (attr := simp)] lemma comp_id (x y : C) [Closed x] [Closed y] : (ρ_ ((ihom x).obj y)).inv ≫ _ ◁ id y ≫ comp x y y = 𝟙 _ := by apply uncurry_injective rw [uncurry_natural_left, uncurry_natural_left, comp_eq, uncurry_curry, compTranspose_eq, associator_inv_naturality_right_assoc, ← rightUnitor_tensor_inv_assoc, whisker_exchange_assoc, ← rightUnitor_inv_naturality_assoc, ← uncurry_id_eq_ev y y] simp only [Functor.id_obj] rw [← uncurry_natural_left] simp [id_eq, uncurry_id_eq_ev] /-- Associativity of the enriched structure -/ @[reassoc] lemma assoc (w x y z : C) [Closed w] [Closed x] [Closed y] : (α_ _ _ _).inv ≫ comp w x y ▷ _ ≫ comp w y z = _ ◁ comp x y z ≫ comp w x z := by apply uncurry_injective simp only [uncurry_natural_left, comp_eq] rw [uncurry_curry, uncurry_curry]; simp only [compTranspose_eq] rw [associator_inv_naturality_middle_assoc, ← comp_whiskerRight_assoc]; dsimp rw [← uncurry_eq, uncurry_curry, associator_inv_naturality_right_assoc, whisker_exchange_assoc, ← uncurry_eq, uncurry_curry] simp end Enriched section OrdinaryEnriched /-- The morphism `𝟙_ C ⟶ (ihom X).obj Y` corresponding to a morphism `X ⟶ Y`. -/ def curry' {X Y : C} [Closed X] (f : X ⟶ Y) : 𝟙_ C ⟶ (ihom X).obj Y := curry ((ρ_ _).hom ≫ f) /-- The morphism `X ⟶ Y` corresponding to a morphism `𝟙_ C ⟶ (ihom X).obj Y`. -/ def uncurry' {X Y : C} [Closed X] (g : 𝟙_ C ⟶ (ihom X).obj Y) : X ⟶ Y := (ρ_ _).inv ≫ uncurry g /-- `curry'` and `uncurry`' are inverse bijections. -/ @[simp] lemma curry'_uncurry' {X Y : C} [Closed X] (g : 𝟙_ C ⟶ (ihom X).obj Y) : curry' (uncurry' g) = g := by simp [curry', uncurry'] /-- `curry'` and `uncurry`' are inverse bijections. -/ @[simp] lemma uncurry'_curry' {X Y : C} [Closed X] (f : X ⟶ Y) : uncurry' (curry' f) = f := by simp [curry', uncurry'] /-- The bijection `(X ⟶ Y) ≃ (𝟙_ C ⟶ (ihom X).obj Y)` in a monoidal closed category. -/ @[simps] def curryHomEquiv' {X Y : C} [Closed X] : (X ⟶ Y) ≃ (𝟙_ C ⟶ (ihom X).obj Y) where toFun := curry' invFun := uncurry' left_inv _ := by simp right_inv _ := by simp lemma curry'_injective {X Y : C} [Closed X] {f f' : X ⟶ Y} (h : curry' f = curry' f') : f = f' := curryHomEquiv'.injective h lemma uncurry'_injective {X Y : C} [Closed X] {f f' : 𝟙_ C ⟶ (ihom X).obj Y} (h : uncurry' f = uncurry' f') : f = f' := curryHomEquiv'.symm.injective h @[simp] lemma curry'_id (X : C) [Closed X] : curry' (𝟙 X) = id X := by dsimp [curry'] rw [Category.comp_id] rfl @[reassoc] lemma whiskerLeft_curry'_ihom_ev_app {X Y : C} [Closed X] (f : X ⟶ Y) : X ◁ curry' f ≫ (ihom.ev X).app Y = (ρ_ _).hom ≫ f := by dsimp [curry'] simp only [whiskerLeft_curry_ihom_ev_app] @[reassoc] lemma curry'_whiskerRight_comp {X Y Z : C} [Closed X] [Closed Y] (f : X ⟶ Y) : curry' f ▷ _ ≫ comp X Y Z = (λ_ _).hom ≫ (pre f).app Z := by rw [← cancel_epi (λ_ _).inv, Iso.inv_hom_id_assoc] apply uncurry_injective rw [uncurry_pre, comp_eq, ← curry_natural_left, ← curry_natural_left, uncurry_curry, compTranspose_eq, associator_inv_naturality_middle_assoc, ← comp_whiskerRight_assoc, whiskerLeft_curry'_ihom_ev_app, comp_whiskerRight_assoc, triangle_assoc_comp_right_assoc, whiskerLeft_inv_hom_assoc] @[reassoc] lemma whiskerLeft_curry'_comp {X Y Z : C} [Closed X] [Closed Y] (f : Y ⟶ Z) : _ ◁ curry' f ≫ comp X Y Z = (ρ_ _).hom ≫ (ihom X).map f := by rw [← cancel_epi (ρ_ _).inv, Iso.inv_hom_id_assoc] apply uncurry_injective rw [uncurry_ihom_map, comp_eq, ← curry_natural_left, ← curry_natural_left, uncurry_curry, compTranspose_eq, associator_inv_naturality_right_assoc, whisker_exchange_assoc] dsimp rw [whiskerLeft_curry'_ihom_ev_app, whiskerLeft_rightUnitor_inv, MonoidalCategory.whiskerRight_id_assoc, Category.assoc, Iso.inv_hom_id_assoc, Iso.hom_inv_id_assoc, Iso.inv_hom_id_assoc,] lemma curry'_ihom_map {X Y Z : C} [Closed X] (f : X ⟶ Y) (g : Y ⟶ Z) : curry' f ≫ (ihom X).map g = curry' (f ≫ g) := by simp only [curry', ← curry_natural_right, Category.assoc] lemma curry'_comp {X Y Z : C} [Closed X] [Closed Y] (f : X ⟶ Y) (g : Y ⟶ Z) : curry' (f ≫ g) = (λ_ (𝟙_ C)).inv ≫ (curry' f ⊗ₘ curry' g) ≫ comp X Y Z := by rw [tensorHom_def_assoc, whiskerLeft_curry'_comp, MonoidalCategory.whiskerRight_id, Category.assoc, Category.assoc, Iso.inv_hom_id_assoc, ← unitors_equal, Iso.inv_hom_id_assoc, curry'_ihom_map] end OrdinaryEnriched end MonoidalClosed end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/Enrichment.lean
import Mathlib.CategoryTheory.Enriched.Ordinary.Basic import Mathlib.CategoryTheory.Closed.Monoidal /-! # A closed monoidal category is enriched in itself From the data of a closed monoidal category `C`, we define a `C`-category structure for `C`. where the hom-object is given by the internal hom (coming from the closed structure). We use `scoped instance` to avoid potential issues where `C` may also have a `C`-category structure coming from another source (e.g. the type of simplicial sets `SSet.{v}` has an instance of `EnrichedCategory SSet.{v}` as a category of simplicial objects; see `Mathlib/AlgebraicTopology/SimplicialCategory/SimplicialObject.lean`). All structure field values are defined in `Mathlib/CategoryTheory/Closed/Monoidal.lean`. -/ universe u v namespace CategoryTheory open Category MonoidalCategory namespace MonoidalClosed variable (C : Type u) [Category.{v} C] [MonoidalCategory C] [MonoidalClosed C] /-- For `C` closed monoidal, build an instance of `C` as a `C`-category -/ scoped instance enrichedCategorySelf : EnrichedCategory C C where Hom x := (ihom x).obj id _ := id _ comp _ _ _ := comp _ _ _ assoc _ _ _ _ := assoc _ _ _ _ section variable {C} lemma enrichedCategorySelf_hom (X Y : C) : EnrichedCategory.Hom X Y = (ihom X).obj Y := rfl lemma enrichedCategorySelf_id (X : C) : eId C X = id X := rfl lemma enrichedCategorySelf_comp (X Y Z : C) : eComp C X Y Z = comp X Y Z := rfl end /-- A monoidal closed category is an enriched ordinary category over itself. -/ scoped instance enrichedOrdinaryCategorySelf : EnrichedOrdinaryCategory C C where homEquiv := curryHomEquiv' homEquiv_id X := curry'_id X homEquiv_comp := curry'_comp lemma enrichedOrdinaryCategorySelf_eHomWhiskerLeft (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) : eHomWhiskerLeft C X g = (ihom X).map g := by change (ρ_ _).inv ≫ _ ◁ curry' g ≫ comp X Y₁ Y₂ = _ rw [whiskerLeft_curry'_comp, Iso.inv_hom_id_assoc] lemma enrichedOrdinaryCategorySelf_eHomWhiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : eHomWhiskerRight C f Y = (pre f).app Y := by change (λ_ _).inv ≫ curry' f ▷ _ ≫ comp X₁ X₂ Y = _ rw [curry'_whiskerRight_comp, Iso.inv_hom_id_assoc] lemma enrichedOrdinaryCategorySelf_homEquiv {X Y : C} (f : X ⟶ Y) : eHomEquiv C f = curry' f := rfl lemma enrichedOrdinaryCategorySelf_homEquiv_symm {X Y : C} (g : 𝟙_ C ⟶ (ihom X).obj Y) : (eHomEquiv C).symm g = uncurry' g := rfl end MonoidalClosed end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/Cartesian.lean
import Mathlib.CategoryTheory.Closed.Monoidal import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic /-! # Cartesian closed categories We define exponentiable objects to be closed objects in a Cartesian monoidal category, i.e. `(X × -)` is a left adjoint. We say a category is Cartesian closed if every object is exponentiable (equivalently, that the category equipped with the Cartesian monoidal structure is closed monoidal). Show that exponential forms a difunctor and define the exponential comparison morphisms. ## Implementation Details Cartesian closed categories require a `CartesianMonoidalCategory` instance. If one wishes to state that a category that `hasFiniteProducts` is Cartesian closed, they should first promote the `hasFiniteProducts` instance to a `CartesianMonoidalCategory` one using `CategoryTheory.ofChosenFiniteProducts`. ## TODO Some of the results here are true more generally for closed objects and for closed monoidal categories, and these could be generalised. -/ universe v v₂ u u₂ namespace CategoryTheory open Category Limits MonoidalCategory CartesianMonoidalCategory variable {C : Type u} [Category.{v} C] [CartesianMonoidalCategory C] {X X' Y Y' Z : C} /-- An object `X` is *exponentiable* if `(X × -)` is a left adjoint. We define this as being `Closed` in the Cartesian monoidal structure. -/ abbrev Exponentiable (X : C) := Closed X /-- Constructor for `Exponentiable X` which takes as an input an adjunction `MonoidalCategory.tensorLeft X ⊣ exp` for some functor `exp : C ⥤ C`. -/ abbrev Exponentiable.mk (X : C) (exp : C ⥤ C) (adj : tensorLeft X ⊣ exp) : Exponentiable X where rightAdj := exp adj := adj /-- If `X` and `Y` are exponentiable then `X ⨯ Y` is. This isn't an instance because it's not usually how we want to construct exponentials, we'll usually prove all objects are exponential uniformly. -/ def binaryProductExponentiable (hX : Exponentiable X) (hY : Exponentiable Y) : Exponentiable (X ⊗ Y) := tensorClosed hX hY /-- The terminal object is always exponentiable. This isn't an instance because most of the time we'll prove Cartesian closed for all objects at once, rather than just for this one. -/ def terminalExponentiable : Exponentiable (𝟙_ C) := unitClosed variable (C) in /-- A category `C` is Cartesian closed if it has finite products and every object is exponentiable. We define this as `MonoidalClosed` with respect to the Cartesian monoidal structure. -/ abbrev CartesianClosed := MonoidalClosed C variable (C) in /-- Constructor for `CartesianClosed C`. -/ def CartesianClosed.mk (exp : ∀ (X : C), Exponentiable X) : CartesianClosed C where closed X := exp X variable (A B : C) [Exponentiable A] /-- This is (-)^A. -/ abbrev exp : C ⥤ C := ihom A namespace exp /-- The adjunction between A ⨯ - and (-)^A. -/ abbrev adjunction : tensorLeft A ⊣ exp A := ihom.adjunction A /-- The evaluation natural transformation. -/ abbrev ev : exp A ⋙ tensorLeft A ⟶ 𝟭 C := ihom.ev A /-- The coevaluation natural transformation. -/ abbrev coev : 𝟭 C ⟶ tensorLeft A ⋙ exp A := ihom.coev A -- Porting note: notation fails to elaborate with `quotPrecheck` on. set_option quotPrecheck false in /-- Morphisms obtained using an exponentiable object. -/ notation:20 A " ⟹ " B:19 => (exp A).obj B open Lean PrettyPrinter.Delaborator SubExpr in /-- Delaborator for `Functor.obj` -/ @[app_delab Functor.obj] def delabFunctorObjExp : Delab := whenPPOption getPPNotation <| withOverApp 6 <| do let e ← getExpr guard <| e.isAppOfArity' ``Functor.obj 6 let A ← withNaryArg 4 do let e ← getExpr guard <| e.isAppOfArity' ``exp 5 withNaryArg 3 delab let B ← withNaryArg 5 delab `($A ⟹ $B) -- Porting note: notation fails to elaborate with `quotPrecheck` on. set_option quotPrecheck false in /-- Morphisms from an exponentiable object. -/ notation:30 B " ^^ " A:30 => (exp A).obj B -- Not simp as it can already prove it. @[reassoc] theorem ev_coev : (A ◁ (coev A).app B) ≫ (ev A).app (A ⊗ B) = 𝟙 (A ⊗ B : C) := ihom.ev_coev A B @[reassoc] theorem coev_ev : (coev A).app (A ⟹ B) ≫ (exp A).map ((ev A).app B) = 𝟙 (A ⟹ B) := ihom.coev_ev A B end exp lemma CartesianMonoidalCategory.isLeftAdjoint_prod_functor (A : C) [Closed A] : (prod.functor.obj A).IsLeftAdjoint := Functor.isLeftAdjoint_of_iso (CartesianMonoidalCategory.tensorLeftIsoProd A) instance : PreservesColimits (tensorLeft A) := (ihom.adjunction A).leftAdjoint_preservesColimits variable {A} -- Wrap these in a namespace so we don't clash with the core versions. namespace CartesianClosed /-- Currying in a Cartesian closed category. -/ def curry : (A ⊗ Y ⟶ X) → (Y ⟶ A ⟹ X) := (exp.adjunction A).homEquiv _ _ /-- Uncurrying in a Cartesian closed category. -/ def uncurry : (Y ⟶ A ⟹ X) → (A ⊗ Y ⟶ X) := ((exp.adjunction A).homEquiv _ _).symm theorem homEquiv_apply_eq (f : A ⊗ Y ⟶ X) : (exp.adjunction A).homEquiv _ _ f = curry f := rfl theorem homEquiv_symm_apply_eq (f : Y ⟶ A ⟹ X) : ((exp.adjunction A).homEquiv _ _).symm f = uncurry f := rfl @[reassoc] theorem curry_natural_left (f : X ⟶ X') (g : A ⊗ X' ⟶ Y) : curry (_ ◁ f ≫ g) = f ≫ curry g := Adjunction.homEquiv_naturality_left _ _ _ @[reassoc] theorem curry_natural_right (f : A ⊗ X ⟶ Y) (g : Y ⟶ Y') : curry (f ≫ g) = curry f ≫ (exp _).map g := Adjunction.homEquiv_naturality_right _ _ _ @[reassoc] theorem uncurry_natural_right (f : X ⟶ A ⟹ Y) (g : Y ⟶ Y') : uncurry (f ≫ (exp _).map g) = uncurry f ≫ g := Adjunction.homEquiv_naturality_right_symm _ _ _ @[reassoc] theorem uncurry_natural_left (f : X ⟶ X') (g : X' ⟶ A ⟹ Y) : uncurry (f ≫ g) = _ ◁ f ≫ uncurry g := Adjunction.homEquiv_naturality_left_symm _ _ _ @[simp] theorem uncurry_curry (f : A ⊗ X ⟶ Y) : uncurry (curry f) = f := (Closed.adj.homEquiv _ _).left_inv f @[simp] theorem curry_uncurry (f : X ⟶ A ⟹ Y) : curry (uncurry f) = f := (Closed.adj.homEquiv _ _).right_inv f theorem curry_eq_iff (f : A ⊗ Y ⟶ X) (g : Y ⟶ A ⟹ X) : curry f = g ↔ f = uncurry g := Adjunction.homEquiv_apply_eq (exp.adjunction A) f g theorem eq_curry_iff (f : A ⊗ Y ⟶ X) (g : Y ⟶ A ⟹ X) : g = curry f ↔ uncurry g = f := Adjunction.eq_homEquiv_apply (exp.adjunction A) f g -- I don't think these two should be simp. theorem uncurry_eq (g : Y ⟶ A ⟹ X) : uncurry g = (A ◁ g) ≫ (exp.ev A).app X := rfl theorem curry_eq (g : A ⊗ Y ⟶ X) : curry g = (exp.coev A).app Y ≫ (exp A).map g := rfl theorem uncurry_id_eq_ev (A X : C) [Exponentiable A] : uncurry (𝟙 (A ⟹ X)) = (exp.ev A).app X := by rw [uncurry_eq, whiskerLeft_id_assoc] theorem curry_id_eq_coev (A X : C) [Exponentiable A] : curry (𝟙 _) = (exp.coev A).app X := by rw [curry_eq, (exp A).map_id (A ⊗ _)]; apply comp_id theorem curry_injective : Function.Injective (curry : (A ⊗ Y ⟶ X) → (Y ⟶ A ⟹ X)) := (Closed.adj.homEquiv _ _).injective theorem uncurry_injective : Function.Injective (uncurry : (Y ⟶ A ⟹ X) → (A ⊗ Y ⟶ X)) := (Closed.adj.homEquiv _ _).symm.injective end CartesianClosed open CartesianClosed /-- The exponential with the terminal object is naturally isomorphic to the identity. The typeclass argument is explicit: any instance can be used. -/ def expUnitNatIso [Exponentiable (𝟙_ C)] : 𝟭 C ≅ exp (𝟙_ C) := MonoidalClosed.unitNatIso (C := C) /-- The exponential of any object with the terminal object is isomorphic to itself, i.e. `X^1 ≅ X`. The typeclass argument is explicit: any instance can be used. -/ def expUnitIsoSelf [Exponentiable (𝟙_ C)] : (𝟙_ C) ⟹ X ≅ X := (expUnitNatIso.app X).symm /-- The internal element which points at the given morphism. -/ def internalizeHom (f : A ⟶ Y) : 𝟙_ C ⟶ A ⟹ Y := CartesianClosed.curry (fst _ _ ≫ f) section Pre variable {B} /-- Pre-compose an internal hom with an external hom. -/ def pre (f : B ⟶ A) [Exponentiable B] : exp A ⟶ exp B := conjugateEquiv (exp.adjunction _) (exp.adjunction _) ((tensoringLeft _).map f) theorem prod_map_pre_app_comp_ev (f : B ⟶ A) [Exponentiable B] (X : C) : (B ◁ (pre f).app X) ≫ (exp.ev B).app X = f ▷ (A ⟹ X) ≫ (exp.ev A).app X := conjugateEquiv_counit _ _ ((tensoringLeft _).map f) X theorem uncurry_pre (f : B ⟶ A) [Exponentiable B] (X : C) : CartesianClosed.uncurry ((pre f).app X) = f ▷ _ ≫ (exp.ev A).app X := by rw [uncurry_eq, prod_map_pre_app_comp_ev] theorem coev_app_comp_pre_app (f : B ⟶ A) [Exponentiable B] : (exp.coev A).app X ≫ (pre f).app (A ⊗ X) = (exp.coev B).app X ≫ (exp B).map (f ⊗ₘ 𝟙 _) := by rw [tensorHom_id] exact unit_conjugateEquiv _ _ ((tensoringLeft _).map f) X @[simp] theorem pre_id (A : C) [Exponentiable A] : pre (𝟙 A) = 𝟙 _ := by simp only [pre, Functor.map_id] simp @[simp] theorem pre_map {A₁ A₂ A₃ : C} [Exponentiable A₁] [Exponentiable A₂] [Exponentiable A₃] (f : A₁ ⟶ A₂) (g : A₂ ⟶ A₃) : pre (f ≫ g) = pre g ≫ pre f := by rw [pre, pre, pre, conjugateEquiv_comp] simp end Pre /-- The internal hom functor given by the Cartesian closed structure. -/ def internalHom [CartesianClosed C] : Cᵒᵖ ⥤ C ⥤ C where obj X := exp X.unop map f := pre f.unop /-- If an initial object `I` exists in a CCC, then `A ⨯ I ≅ I`. -/ @[simps] def zeroMul {I : C} (t : IsInitial I) : A ⊗ I ≅ I where hom := snd _ _ inv := t.to _ hom_inv_id := by have : snd A I = CartesianClosed.uncurry (t.to _) := by rw [← curry_eq_iff] apply t.hom_ext rw [this, ← uncurry_natural_right, ← eq_curry_iff] apply t.hom_ext inv_hom_id := t.hom_ext _ _ /-- If an initial object `0` exists in a CCC, then `0 ⨯ A ≅ 0`. -/ def mulZero [BraidedCategory C] {I : C} (t : IsInitial I) : I ⊗ A ≅ I := β_ _ _ ≪≫ zeroMul t /-- If an initial object `0` exists in a CCC then `0^B ≅ 1` for any `B`. -/ def powZero [BraidedCategory C] {I : C} (t : IsInitial I) [CartesianClosed C] : I ⟹ B ≅ 𝟙_ C where hom := default inv := CartesianClosed.curry ((mulZero t).hom ≫ t.to _) hom_inv_id := by rw [← curry_natural_left, curry_eq_iff, ← cancel_epi (mulZero t).inv] apply t.hom_ext -- TODO: Generalise the below to its commuted variants. -- TODO: Define a distributive category, so that zero_mul and friends can be derived from this. /-- In a CCC with binary coproducts, the distribution morphism is an isomorphism. -/ noncomputable def prodCoprodDistrib [HasBinaryCoproducts C] [CartesianClosed C] (X Y Z : C) : (Z ⊗ X) ⨿ Z ⊗ Y ≅ Z ⊗ (X ⨿ Y) where hom := coprod.desc (_ ◁ coprod.inl) (_ ◁ coprod.inr) inv := CartesianClosed.uncurry (coprod.desc (CartesianClosed.curry coprod.inl) (CartesianClosed.curry coprod.inr)) hom_inv_id := by ext · rw [coprod.inl_desc_assoc, comp_id, ← uncurry_natural_left, coprod.inl_desc, uncurry_curry] rw [coprod.inr_desc_assoc, comp_id, ← uncurry_natural_left, coprod.inr_desc, uncurry_curry] inv_hom_id := by rw [← uncurry_natural_right, ← eq_curry_iff] ext · rw [coprod.inl_desc_assoc, ← curry_natural_right, coprod.inl_desc, ← curry_natural_left, comp_id] rw [coprod.inr_desc_assoc, ← curry_natural_right, coprod.inr_desc, ← curry_natural_left, comp_id] /-- If an initial object `I` exists in a CCC then it is a strict initial object, i.e. any morphism to `I` is an iso. This actually shows a slightly stronger version: any morphism to an initial object from an exponentiable object is an isomorphism. -/ theorem strict_initial {I : C} (t : IsInitial I) (f : A ⟶ I) : IsIso f := by haveI : Mono f := by rw [← lift_snd (𝟙 A) f, ← zeroMul_hom t] exact mono_comp _ _ haveI : IsSplitEpi f := IsSplitEpi.mk' ⟨t.to _, t.hom_ext _ _⟩ apply isIso_of_mono_of_isSplitEpi instance to_initial_isIso [HasInitial C] (f : A ⟶ ⊥_ C) : IsIso f := strict_initial initialIsInitial _ /-- If an initial object `0` exists in a CCC then every morphism from it is monic. -/ theorem initial_mono {I : C} (B : C) (t : IsInitial I) [CartesianClosed C] : Mono (t.to B) := ⟨fun g h _ => by haveI := strict_initial t g haveI := strict_initial t h exact eq_of_inv_eq_inv (t.hom_ext _ _)⟩ instance Initial.mono_to [HasInitial C] (B : C) [CartesianClosed C] : Mono (initial.to B) := initial_mono B initialIsInitial variable {D : Type u₂} [Category.{v₂} D] section Functor variable [CartesianMonoidalCategory D] /-- Transport the property of being Cartesian closed across an equivalence of categories. Note we didn't require any coherence between the choice of finite products here, since we transport along the `prodComparison` isomorphism. -/ noncomputable def cartesianClosedOfEquiv (e : C ≌ D) [CartesianClosed C] : CartesianClosed D := letI : e.inverse.Monoidal := .ofChosenFiniteProducts _ MonoidalClosed.ofEquiv e.inverse e.symm.toAdjunction end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/Ideal.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts import Mathlib.CategoryTheory.Monad.Limits import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Adjunction.Reflective import Mathlib.CategoryTheory.Closed.Cartesian import Mathlib.CategoryTheory.Subterminal /-! # Exponential ideals An exponential ideal of a Cartesian closed category `C` is a subcategory `D ⊆ C` such that for any `B : D` and `A : C`, the exponential `A ⟹ B` is in `D`: resembling ring-theoretic ideals. We define the notion here for inclusion functors `i : D ⥤ C` rather than explicit subcategories to preserve the principle of equivalence. We additionally show that if `C` is Cartesian closed and `i : D ⥤ C` is a reflective functor, the following are equivalent. * The left adjoint to `i` preserves binary (equivalently, finite) products. * `i` is an exponential ideal. -/ universe v₁ v₂ u₁ u₂ noncomputable section namespace CategoryTheory open Category section Ideal variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₁} D] {i : D ⥤ C} variable (i) [CartesianMonoidalCategory C] [CartesianClosed C] /-- The subcategory `D` of `C` expressed as an inclusion functor is an *exponential ideal* if `B ∈ D` implies `A ⟹ B ∈ D` for all `A`. -/ class ExponentialIdeal : Prop where exp_closed : ∀ {B}, i.essImage B → ∀ A, i.essImage (A ⟹ B) attribute [nolint docBlame] ExponentialIdeal.exp_closed /-- To show `i` is an exponential ideal it suffices to show that `A ⟹ iB` is "in" `D` for any `A` in `C` and `B` in `D`. -/ theorem ExponentialIdeal.mk' (h : ∀ (B : D) (A : C), i.essImage (A ⟹ i.obj B)) : ExponentialIdeal i := ⟨fun hB A => by rcases hB with ⟨B', ⟨iB'⟩⟩ exact Functor.essImage.ofIso ((exp A).mapIso iB') (h B' A)⟩ /-- The entire category viewed as a subcategory is an exponential ideal. -/ instance : ExponentialIdeal (𝟭 C) := ExponentialIdeal.mk' _ fun _ _ => ⟨_, ⟨Iso.refl _⟩⟩ open CartesianClosed /-- The subcategory of subterminal objects is an exponential ideal. -/ instance : ExponentialIdeal (subterminalInclusion C) := by apply ExponentialIdeal.mk' intro B A refine ⟨⟨A ⟹ B.1, fun Z g h => ?_⟩, ⟨Iso.refl _⟩⟩ exact uncurry_injective (B.2 (CartesianClosed.uncurry g) (CartesianClosed.uncurry h)) /-- If `D` is a reflective subcategory, the property of being an exponential ideal is equivalent to the presence of a natural isomorphism `i ⋙ exp A ⋙ leftAdjoint i ⋙ i ≅ i ⋙ exp A`, that is: `(A ⟹ iB) ≅ i L (A ⟹ iB)`, naturally in `B`. The converse is given in `ExponentialIdeal.mk_of_iso`. -/ def exponentialIdealReflective (A : C) [Reflective i] [ExponentialIdeal i] : i ⋙ exp A ⋙ reflector i ⋙ i ≅ i ⋙ exp A := by symm apply NatIso.ofComponents _ _ · intro X haveI := Functor.essImage.unit_isIso (ExponentialIdeal.exp_closed (i.obj_mem_essImage X) A) apply asIso ((reflectorAdjunction i).unit.app (A ⟹ i.obj X)) · simp [asIso] /-- Given a natural isomorphism `i ⋙ exp A ⋙ leftAdjoint i ⋙ i ≅ i ⋙ exp A`, we can show `i` is an exponential ideal. -/ theorem ExponentialIdeal.mk_of_iso [Reflective i] (h : ∀ A : C, i ⋙ exp A ⋙ reflector i ⋙ i ≅ i ⋙ exp A) : ExponentialIdeal i := by apply ExponentialIdeal.mk' intro B A exact ⟨_, ⟨(h A).app B⟩⟩ end Ideal section variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₁} D] variable (i : D ⥤ C) /- This cannot be a local instance since it has free variables, it can instead be used as a have when needed. We assume HasFiniteProducts D as a hypothesis below, to avoid making this a local instance. -/ theorem reflective_products [Limits.HasFiniteProducts C] [Reflective i] : Limits.HasFiniteProducts D := ⟨fun _ => hasLimitsOfShape_of_reflective i⟩ open CartesianClosed MonoidalCategory CartesianMonoidalCategory open Limits in /-- Given a reflective subcategory `D` of a category with chosen finite products `C`, `D` admits finite chosen products. -/ -- Note: This is not an instance as one might already have a (different) `CartesianMonoidalCategory` -- instance on `D` (as for example with sheaves). -- See note [reducible non-instances] abbrev CartesianMonoidalCategory.ofReflective [CartesianMonoidalCategory C] [Reflective i] : CartesianMonoidalCategory D := .ofChosenFiniteProducts ({ cone := Limits.asEmptyCone <| (reflector i).obj (𝟙_ C) isLimit := by apply isLimitOfReflects i apply isLimitChangeEmptyCone _ isTerminalTensorUnit letI : IsIso ((reflectorAdjunction i).unit.app (𝟙_ C)) := by have := reflective_products i refine Functor.essImage.unit_isIso ⟨terminal D, ⟨PreservesTerminal.iso i |>.trans ?_⟩⟩ exact IsLimit.conePointUniqueUpToIso (limit.isLimit _) isTerminalTensorUnit exact asIso ((reflectorAdjunction i).unit.app (𝟙_ C)) }) fun X Y ↦ { cone := BinaryFan.mk ((reflector i).map (fst (i.obj X) (i.obj Y)) ≫ (reflectorAdjunction i).counit.app _) ((reflector i).map (snd (i.obj X) (i.obj Y)) ≫ (reflectorAdjunction i).counit.app _) isLimit := by apply isLimitOfReflects i apply IsLimit.equivOfNatIsoOfIso (pairComp X Y _) _ _ _|>.invFun (tensorProductIsBinaryProduct (i.obj X) (i.obj Y)) fapply BinaryFan.ext · change (reflector i ⋙ i).obj (i.obj X ⊗ i.obj Y) ≅ (𝟭 C).obj (i.obj X ⊗ i.obj Y) letI : IsIso ((reflectorAdjunction i).unit.app (i.obj X ⊗ i.obj Y)) := by apply Functor.essImage.unit_isIso haveI := reflective_products i use Limits.prod X Y constructor apply Limits.PreservesLimitPair.iso i _ _|>.trans refine Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit (pair (i.obj X) (i.obj Y))) (tensorProductIsBinaryProduct _ _) exact asIso ((reflectorAdjunction i).unit.app (i.obj X ⊗ i.obj Y))|>.symm · simp only [BinaryFan.fst, Cones.postcompose, pairComp] simp [← Functor.comp_map, ← NatTrans.naturality_assoc] · simp only [BinaryFan.snd, Cones.postcompose, pairComp] simp [← Functor.comp_map, ← NatTrans.naturality_assoc] } @[deprecated (since := "2025-05-15")] noncomputable alias reflectiveChosenFiniteProducts := CartesianMonoidalCategory.ofReflective variable [CartesianMonoidalCategory C] [Reflective i] [CartesianClosed C] [CartesianMonoidalCategory D] /-- If the reflector preserves binary products, the subcategory is an exponential ideal. This is the converse of `preservesBinaryProductsOfExponentialIdeal`. -/ instance (priority := 10) exponentialIdeal_of_preservesBinaryProducts [Limits.PreservesLimitsOfShape (Discrete Limits.WalkingPair) (reflector i)] : ExponentialIdeal i := by let ir := reflectorAdjunction i let L : C ⥤ D := reflector i let η : 𝟭 C ⟶ L ⋙ i := ir.unit let ε : i ⋙ L ⟶ 𝟭 D := ir.counit apply ExponentialIdeal.mk' intro B A let q : i.obj (L.obj (A ⟹ i.obj B)) ⟶ A ⟹ i.obj B := by apply CartesianClosed.curry (ir.homEquiv _ _ _) apply _ ≫ (ir.homEquiv _ _).symm ((exp.ev A).app (i.obj B)) exact prodComparison L A _ ≫ (_ ◁ (ε.app _)) ≫ inv (prodComparison _ _ _) have : η.app (A ⟹ i.obj B) ≫ q = 𝟙 (A ⟹ i.obj B) := by dsimp rw [← curry_natural_left, curry_eq_iff, uncurry_id_eq_ev, ← ir.homEquiv_naturality_left, ir.homEquiv_apply_eq, assoc, assoc, prodComparison_natural_whiskerLeft_assoc, ← whiskerLeft_comp_assoc, ir.left_triangle_components, whiskerLeft_id, id_comp] apply IsIso.hom_inv_id_assoc haveI : IsSplitMono (η.app (A ⟹ i.obj B)) := IsSplitMono.mk' ⟨_, this⟩ apply mem_essImage_of_unit_isSplitMono variable [ExponentialIdeal i] /-- If `i` witnesses that `D` is a reflective subcategory and an exponential ideal, then `D` is itself Cartesian closed. To allow for better control of definitional equality, this construction takes in an explicit choice of lift of the essential image of `i` to `D`, in the form of a functor `l : i.EssImageSubcategory ⥤ D` and natural isomorphism `φ : l ⋙ i ≅ i.essImage.ι`. When `l ⋙ i` is defeq to `i.essImage.ι`, images of exponential objects in `D` under `i` will be defeq to the respective exponential objects in `C`. -/ def cartesianClosedOfReflective' (l : i.EssImageSubcategory ⥤ D) (φ : l ⋙ i ≅ i.essImage.ι) : CartesianClosed D where closed := fun B => { rightAdj := i.essImage.lift (i ⋙ exp (i.obj B)) (fun X ↦ ExponentialIdeal.exp_closed (i.obj_mem_essImage X) _) ⋙ l adj := by apply (exp.adjunction (i.obj B)).restrictFullyFaithful i.fullyFaithfulOfReflective i.fullyFaithfulOfReflective · symm refine NatIso.ofComponents (fun X => ?_) (fun f => ?_) · haveI := Adjunction.rightAdjoint_preservesLimits.{0, 0} (reflectorAdjunction i) apply asIso (prodComparison i B X) · dsimp [asIso] rw [prodComparison_natural_whiskerLeft] · exact (i.essImage.liftCompιIso _ _).symm.trans <| (Functor.isoWhiskerLeft _ φ.symm).trans (Functor.associator _ _ _).symm } /-- If `i` witnesses that `D` is a reflective subcategory and an exponential ideal, then `D` is itself Cartesian closed. Unlike `cartesianClosedOfReflective'` this construction lifts exponential objects in `C` to exponential objects in `D` by applying the reflector to them, even though they already lie in the essential image of `i`; if you need better control over definitional equality, use `cartesianClosedOfReflective'` instead. -/ def cartesianClosedOfReflective : CartesianClosed D := cartesianClosedOfReflective' i (i.essImage.ι ⋙ reflector i) (NatIso.ofComponents (fun X ↦ have := Functor.essImage.unit_isIso X.2 (asIso ((reflectorAdjunction i).unit.app X.obj)).symm)) variable [BraidedCategory C] /-- We construct a bijection between morphisms `L(A ⊗ B) ⟶ X` and morphisms `LA ⊗ LB ⟶ X`. This bijection has two key properties: * It is natural in `X`: See `bijection_natural`. * When `X = LA ⨯ LB`, then the backwards direction sends the identity morphism to the product comparison morphism: See `bijection_symm_apply_id`. Together these help show that `L` preserves binary products. This should be considered *internal implementation* towards `preservesBinaryProductsOfExponentialIdeal`. -/ noncomputable def bijection (A B : C) (X : D) : ((reflector i).obj (A ⊗ B) ⟶ X) ≃ ((reflector i).obj A ⊗ (reflector i).obj B ⟶ X) := calc _ ≃ (A ⊗ B ⟶ i.obj X) := (reflectorAdjunction i).homEquiv _ _ _ ≃ (B ⊗ A ⟶ i.obj X) := (β_ _ _).homCongr (Iso.refl _) _ ≃ (A ⟶ B ⟹ i.obj X) := (exp.adjunction _).homEquiv _ _ _ ≃ (i.obj ((reflector i).obj A) ⟶ B ⟹ i.obj X) := (unitCompPartialBijective _ (ExponentialIdeal.exp_closed (i.obj_mem_essImage _) _)) _ ≃ (B ⊗ i.obj ((reflector i).obj A) ⟶ i.obj X) := ((exp.adjunction _).homEquiv _ _).symm _ ≃ (i.obj ((reflector i).obj A) ⊗ B ⟶ i.obj X) := ((β_ _ _).homCongr (Iso.refl _)) _ ≃ (B ⟶ i.obj ((reflector i).obj A) ⟹ i.obj X) := (exp.adjunction _).homEquiv _ _ _ ≃ (i.obj ((reflector i).obj B) ⟶ i.obj ((reflector i).obj A) ⟹ i.obj X) := (unitCompPartialBijective _ (ExponentialIdeal.exp_closed (i.obj_mem_essImage _) _)) _ ≃ (i.obj ((reflector i).obj A) ⊗ i.obj ((reflector i).obj B) ⟶ i.obj X) := ((exp.adjunction _).homEquiv _ _).symm _ ≃ (i.obj ((reflector i).obj A ⊗ (reflector i).obj B) ⟶ i.obj X) := haveI : Limits.PreservesLimits i := (reflectorAdjunction i).rightAdjoint_preservesLimits haveI := Limits.preservesSmallestLimits_of_preservesLimits i Iso.homCongr (prodComparisonIso _ _ _).symm (Iso.refl (i.obj X)) _ ≃ ((reflector i).obj A ⊗ (reflector i).obj B ⟶ X) := i.fullyFaithfulOfReflective.homEquiv.symm theorem bijection_symm_apply_id (A B : C) : (bijection i A B _).symm (𝟙 _) = prodComparison _ _ _ := by simp only [bijection, Equiv.trans_def, curriedTensor_obj_obj, Equiv.symm_trans_apply, Equiv.symm_symm, Functor.FullyFaithful.homEquiv_apply, Functor.map_id, Iso.homCongr_symm, Iso.symm_symm_eq, Iso.refl_symm, Iso.homCongr_apply, Iso.refl_hom, comp_id, unitCompPartialBijective_symm_apply, Functor.id_obj, Functor.comp_obj, Iso.symm_inv] -- Porting note: added erw [homEquiv_symm_apply_eq, homEquiv_symm_apply_eq, homEquiv_apply_eq, homEquiv_apply_eq] rw [uncurry_natural_left, uncurry_curry, uncurry_natural_left, uncurry_curry, ← BraidedCategory.braiding_naturality_left_assoc, SymmetricCategory.symmetry_assoc, ← MonoidalCategory.whisker_exchange_assoc, ← tensorHom_def'_assoc, Adjunction.homEquiv_symm_apply, ← Adjunction.eq_unit_comp_map_iff, Iso.comp_inv_eq, assoc, prodComparisonIso_hom i ((reflector i).obj A) ((reflector i).obj B)] apply hom_ext · rw [tensorHom_fst, assoc, assoc, prodComparison_fst, ← i.map_comp, prodComparison_fst] apply (reflectorAdjunction i).unit.naturality · rw [tensorHom_snd, assoc, assoc, prodComparison_snd, ← i.map_comp, prodComparison_snd] apply (reflectorAdjunction i).unit.naturality theorem bijection_natural (A B : C) (X X' : D) (f : (reflector i).obj (A ⊗ B) ⟶ X) (g : X ⟶ X') : bijection i _ _ _ (f ≫ g) = bijection i _ _ _ f ≫ g := by dsimp [bijection] -- Porting note: added erw [homEquiv_symm_apply_eq, homEquiv_symm_apply_eq, homEquiv_apply_eq, homEquiv_apply_eq, homEquiv_symm_apply_eq, homEquiv_symm_apply_eq, homEquiv_apply_eq, homEquiv_apply_eq] apply i.map_injective rw [Functor.FullyFaithful.map_preimage, i.map_comp, Adjunction.homEquiv_unit, Adjunction.homEquiv_unit] simp only [comp_id, Functor.map_comp, Functor.FullyFaithful.map_preimage, assoc] rw [← assoc, ← assoc, curry_natural_right _ (i.map g), unitCompPartialBijective_natural, uncurry_natural_right, ← assoc, curry_natural_right, unitCompPartialBijective_natural, uncurry_natural_right, assoc] /-- The bijection allows us to show that `prodComparison L A B` is an isomorphism, where the inverse is the forward map of the identity morphism. -/ theorem prodComparison_iso (A B : C) : IsIso (prodComparison (reflector i) A B) := ⟨⟨bijection i _ _ _ (𝟙 _), by rw [← (bijection i _ _ _).injective.eq_iff, bijection_natural, ← bijection_symm_apply_id, Equiv.apply_symm_apply, id_comp], by rw [← bijection_natural, id_comp, ← bijection_symm_apply_id, Equiv.apply_symm_apply]⟩⟩ attribute [local instance] prodComparison_iso open Limits /-- If a reflective subcategory is an exponential ideal, then the reflector preserves binary products. This is the converse of `exponentialIdeal_of_preserves_binary_products`. -/ lemma preservesBinaryProducts_of_exponentialIdeal : PreservesLimitsOfShape (Discrete WalkingPair) (reflector i) where preservesLimit {K} := letI := preservesLimit_pair_of_isIso_prodComparison (reflector i) (K.obj ⟨WalkingPair.left⟩) (K.obj ⟨WalkingPair.right⟩) Limits.preservesLimit_of_iso_diagram _ (diagramIsoPair K).symm /-- If a reflective subcategory is an exponential ideal, then the reflector preserves finite products. -/ lemma Limits.PreservesFiniteProducts.of_exponentialIdeal : PreservesFiniteProducts (reflector i) := have := preservesBinaryProducts_of_exponentialIdeal i have : PreservesLimitsOfShape _ (reflector i) := leftAdjoint_preservesTerminal_of_reflective.{0} i .of_preserves_binary_and_terminal _ @[deprecated (since := "2025-04-22")] alias preservesFiniteProducts_of_exponentialIdeal := PreservesFiniteProducts.of_exponentialIdeal end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/Functor.lean
import Mathlib.CategoryTheory.Closed.Cartesian import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Adjunction.FullyFaithful /-! # Cartesian closed functors Define the exponential comparison morphisms for a functor which preserves binary products, and use them to define a Cartesian closed functor: one which (naturally) preserves exponentials. Define the Frobenius morphism, and show it is an isomorphism iff the exponential comparison is an isomorphism. ## TODO Some of the results here are true more generally for closed objects and for closed monoidal categories, and these could be generalised. ## References https://ncatlab.org/nlab/show/cartesian+closed+functor https://ncatlab.org/nlab/show/Frobenius+reciprocity ## Tags Frobenius reciprocity, Cartesian closed functor -/ noncomputable section namespace CategoryTheory open Category CartesianClosed MonoidalCategory CartesianMonoidalCategory TwoSquare universe v u u' variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v} D] variable [CartesianMonoidalCategory C] [CartesianMonoidalCategory D] variable (F : C ⥤ D) {L : D ⥤ C} /-- The Frobenius morphism for an adjunction `L ⊣ F` at `A` is given by the morphism L(FA ⨯ B) ⟶ LFA ⨯ LB ⟶ A ⨯ LB natural in `B`, where the first morphism is the product comparison and the latter uses the counit of the adjunction. We will show that if `C` and `D` are Cartesian closed, then this morphism is an isomorphism for all `A` iff `F` is a Cartesian closed functor, i.e. it preserves exponentials. -/ def frobeniusMorphism (h : L ⊣ F) (A : C) : TwoSquare (tensorLeft (F.obj A)) L L (tensorLeft A) := prodComparisonNatTrans L (F.obj A) ≫ Functor.whiskerLeft _ ((curriedTensor C).map (h.counit.app _)) /-- If `F` is full and faithful and has a left adjoint `L` which preserves binary products, then the Frobenius morphism is an isomorphism. -/ instance frobeniusMorphism_iso_of_preserves_binary_products (h : L ⊣ F) (A : C) [Limits.PreservesLimitsOfShape (Discrete Limits.WalkingPair) L] [F.Full] [F.Faithful] : IsIso (frobeniusMorphism F h A).natTrans := suffices ∀ (X : D), IsIso ((frobeniusMorphism F h A).natTrans.app X) from NatIso.isIso_of_isIso_app _ fun B ↦ by dsimp [frobeniusMorphism]; infer_instance variable [CartesianClosed C] [CartesianClosed D] variable [Limits.PreservesLimitsOfShape (Discrete Limits.WalkingPair) F] /-- The exponential comparison map. `F` is a Cartesian closed functor if this is an iso for all `A`. -/ def expComparison (A : C) : TwoSquare (exp A) F F (exp (F.obj A)) := mateEquiv (exp.adjunction A) (exp.adjunction (F.obj A)) (prodComparisonNatIso F A).inv theorem expComparison_ev (A B : C) : F.obj A ◁ ((expComparison F A).natTrans.app B) ≫ (exp.ev (F.obj A)).app (F.obj B) = inv (prodComparison F _ _) ≫ F.map ((exp.ev _).app _) := by convert mateEquiv_counit _ _ (prodComparisonNatIso F A).inv B using 2 apply IsIso.inv_eq_of_hom_inv_id -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): was `ext` simp only [prodComparisonNatTrans_app, prodComparisonNatIso_inv, NatIso.isIso_inv_app, IsIso.hom_inv_id] theorem coev_expComparison (A B : C) : F.map ((exp.coev A).app B) ≫ (expComparison F A).natTrans.app (A ⊗ B) = (exp.coev _).app (F.obj B) ≫ (exp (F.obj A)).map (inv (prodComparison F A B)) := by convert unit_mateEquiv _ _ (prodComparisonNatIso F A).inv B using 3 apply IsIso.inv_eq_of_hom_inv_id -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): was `ext` simp theorem uncurry_expComparison (A B : C) : CartesianClosed.uncurry ((expComparison F A).natTrans.app B) = inv (prodComparison F _ _) ≫ F.map ((exp.ev _).app _) := by rw [uncurry_eq, expComparison_ev] /-- The exponential comparison map is natural in `A`. -/ theorem expComparison_whiskerLeft {A A' : C} (f : A' ⟶ A) : (expComparison F A).whiskerBottom (pre (F.map f)) = (expComparison F A').whiskerTop (pre f) := by unfold expComparison pre have vcomp1 := mateEquiv_conjugateEquiv_vcomp (exp.adjunction A) (exp.adjunction (F.obj A)) (exp.adjunction (F.obj A')) ((prodComparisonNatIso F A).inv) (((curriedTensor D).map (F.map f))) have vcomp2 := conjugateEquiv_mateEquiv_vcomp (exp.adjunction A) (exp.adjunction A') (exp.adjunction (F.obj A')) (((curriedTensor C).map f)) ((prodComparisonNatIso F A').inv) rw [← vcomp1, ← vcomp2] unfold TwoSquare.whiskerLeft TwoSquare.whiskerRight congr 1 apply congr_arg ext B simp only [Functor.comp_obj, curriedTensor_obj_obj, prodComparisonNatIso_inv, NatTrans.comp_app, Functor.whiskerLeft_app, curriedTensor_map_app, NatIso.isIso_inv_app, Functor.whiskerRight_app, IsIso.eq_inv_comp, prodComparisonNatTrans_app] rw [← prodComparison_inv_natural_whiskerRight F f] simp /-- The functor `F` is Cartesian closed (i.e. preserves exponentials) if each natural transformation `exp_comparison F A` is an isomorphism -/ class CartesianClosedFunctor : Prop where comparison_iso : ∀ A, IsIso (expComparison F A).natTrans attribute [instance] CartesianClosedFunctor.comparison_iso theorem frobeniusMorphism_mate (h : L ⊣ F) (A : C) : conjugateEquiv (h.comp (exp.adjunction A)) ((exp.adjunction (F.obj A)).comp h) (frobeniusMorphism F h A).natTrans = (expComparison F A).natTrans := by unfold expComparison frobeniusMorphism have conjeq := iterated_mateEquiv_conjugateEquiv h h (exp.adjunction (F.obj A)) (exp.adjunction A) (prodComparisonNatTrans L (F.obj A) ≫ Functor.whiskerLeft L ((curriedTensor C).map (h.counit.app A))) rw [← conjeq] congr 1 apply congr_arg ext B unfold mateEquiv simp only [Functor.comp_obj, curriedTensor_obj_obj, Equiv.coe_fn_mk, Functor.whiskerRight_comp, Functor.whiskerLeft_comp, assoc, NatTrans.comp_app, Functor.id_obj, Functor.rightUnitor_inv_app, Functor.whiskerLeft_app, Functor.associator_hom_app, Functor.associator_inv_app, Functor.whiskerRight_app, prodComparisonNatTrans_app, curriedTensor_map_app, Functor.comp_map, curriedTensor_obj_map, Functor.leftUnitor_hom_app, comp_id, id_comp, prodComparisonNatIso_inv, NatIso.isIso_inv_app] rw [← F.map_comp, ← F.map_comp] simp only [Functor.map_comp] apply IsIso.eq_inv_of_inv_hom_id simp only [assoc] rw [prodComparison_natural_whiskerLeft, prodComparison_natural_whiskerRight_assoc] slice_lhs 2 3 => rw [← prodComparison_comp] simp only [assoc] unfold prodComparison simp /-- If the exponential comparison transformation (at `A`) is an isomorphism, then the Frobenius morphism at `A` is an isomorphism. -/ theorem frobeniusMorphism_iso_of_expComparison_iso (h : L ⊣ F) (A : C) [i : IsIso (expComparison F A).natTrans] : IsIso (frobeniusMorphism F h A).natTrans := by rw [← frobeniusMorphism_mate F h] at i exact @conjugateEquiv_of_iso _ _ _ _ _ _ _ _ _ _ _ i /-- If the Frobenius morphism at `A` is an isomorphism, then the exponential comparison transformation (at `A`) is an isomorphism. -/ theorem expComparison_iso_of_frobeniusMorphism_iso (h : L ⊣ F) (A : C) [i : IsIso (frobeniusMorphism F h A)] : IsIso (expComparison F A).natTrans := by rw [← frobeniusMorphism_mate F h]; infer_instance open Limits in /-- If `F` is full and faithful, and has a left adjoint which preserves binary products, then it is Cartesian closed. TODO: Show the converse, that if `F` is Cartesian closed and its left adjoint preserves binary products, then it is full and faithful. -/ theorem cartesianClosedFunctorOfLeftAdjointPreservesBinaryProducts (h : L ⊣ F) [F.Full] [F.Faithful] [PreservesLimitsOfShape (Discrete WalkingPair) L] : CartesianClosedFunctor F where comparison_iso _ := expComparison_iso_of_frobeniusMorphism_iso F h _ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/Types.lean
import Mathlib.CategoryTheory.Closed.Cartesian import Mathlib.CategoryTheory.Limits.Presheaf import Mathlib.CategoryTheory.Monoidal.Cartesian.FunctorCategory import Mathlib.CategoryTheory.Monoidal.Types.Basic /-! # Cartesian closure of Type Show that `Type u₁` is Cartesian closed, and `C ⥤ Type u₁` is Cartesian closed for `C` a small category in `Type u₁`. Note this implies that the category of presheaves on a small category `C` is Cartesian closed. -/ namespace CategoryTheory noncomputable section open Category Limits MonoidalCategory universe v₁ v₂ u₁ u₂ variable {C : Type v₂} [Category.{v₁} C] section CartesianClosed /-- The adjunction `tensorLeft.obj X ⊣ coyoneda.obj (Opposite.op X)` for any `X : Type v₁`. -/ def Types.tensorProductAdjunction (X : Type v₁) : tensorLeft X ⊣ coyoneda.obj (Opposite.op X) where unit := { app := fun Z (z : Z) x => ⟨x, z⟩ } counit := { app := fun _ xf => xf.2 xf.1 } instance (X : Type v₁) : (tensorLeft X).IsLeftAdjoint := ⟨_, ⟨Types.tensorProductAdjunction X⟩⟩ instance : CartesianClosed (Type v₁) := CartesianClosed.mk _ fun X => Exponentiable.mk _ _ (Types.tensorProductAdjunction X) instance {C : Type v₁} [SmallCategory C] : CartesianClosed (C ⥤ Type v₁) := CartesianClosed.mk _ fun F => by haveI : ∀ X : Type v₁, PreservesColimits (tensorLeft X) := by infer_instance letI : PreservesColimits (tensorLeft F) := ⟨by infer_instance⟩ have := Presheaf.isLeftAdjoint_of_preservesColimits.{v₁} (tensorLeft F) exact Exponentiable.mk _ _ (Adjunction.ofIsLeftAdjoint (tensorLeft F)) -- TODO: once we have `MonoidalClosed` instances for functor categories into general monoidal -- closed categories, replace this with that, as it will be a more explicit construction. attribute [local instance] uliftCategory in /-- This is not a good instance because of the universe levels. Below is the instance where the target category is `Type (max u₁ v₁)`. -/ def cartesianClosedFunctorToTypes {C : Type u₁} [Category.{v₁} C] : CartesianClosed (C ⥤ Type (max u₁ v₁ u₂)) := let e : (ULiftHom.{max u₁ v₁ u₂} (ULift.{max u₁ v₁ u₂} C)) ⥤ Type (max u₁ v₁ u₂) ≌ C ⥤ Type (max u₁ v₁ u₂) := Functor.asEquivalence ((Functor.whiskeringLeft _ _ _).obj (ULift.equivalence.trans ULiftHom.equiv).functor) cartesianClosedOfEquiv e -- TODO: once we have `MonoidalClosed` instances for functor categories into general monoidal -- closed categories, replace this with that, as it will be a more explicit construction. instance {C : Type u₁} [Category.{v₁} C] : CartesianClosed (C ⥤ Type (max u₁ v₁)) := cartesianClosedFunctorToTypes -- TODO: once we have `MonoidalClosed` instances for functor categories into general monoidal -- closed categories, replace this with that, as it will be a more explicit construction. instance {C : Type u₁} [Category.{v₁} C] [EssentiallySmall.{v₁} C] : CartesianClosed (C ⥤ Type v₁) := let e : (SmallModel C) ⥤ Type v₁ ≌ C ⥤ Type v₁ := Functor.asEquivalence ((Functor.whiskeringLeft _ _ _).obj (equivSmallModel _).functor) cartesianClosedOfEquiv e end CartesianClosed end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/Zero.lean
import Mathlib.CategoryTheory.Closed.Cartesian import Mathlib.CategoryTheory.PUnit import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects /-! # A Cartesian closed category with zero object is trivial A Cartesian closed category with zero object is trivial: it is equivalent to the category with one object and one morphism. ## References * https://mathoverflow.net/a/136480 -/ universe w v u noncomputable section namespace CategoryTheory open Category Limits MonoidalCategory variable {C : Type u} [Category.{v} C] variable [CartesianMonoidalCategory C] [CartesianClosed C] /-- If a Cartesian closed category has an initial object which is isomorphic to the terminal object, then each homset has exactly one element. -/ def uniqueHomsetOfInitialIsoUnit [HasInitial C] (i : ⊥_ C ≅ 𝟙_ C) (X Y : C) : Unique (X ⟶ Y) := Equiv.unique <| calc (X ⟶ Y) ≃ (X ⊗ 𝟙_ C ⟶ Y) := Iso.homCongr (rightUnitor _).symm (Iso.refl _) _ ≃ (X ⊗ ⊥_ C ⟶ Y) := (Iso.homCongr ((Iso.refl _) ⊗ᵢ i.symm) (Iso.refl _)) _ ≃ (⊥_ C ⟶ Y ^^ X) := (exp.adjunction _).homEquiv _ _ open scoped ZeroObject /-- If a Cartesian closed category has a zero object, each homset has exactly one element. -/ def uniqueHomsetOfZero [HasZeroObject C] (X Y : C) : Unique (X ⟶ Y) := by haveI : HasInitial C := HasZeroObject.hasInitial apply uniqueHomsetOfInitialIsoUnit _ X Y refine ⟨default, (default : 𝟙_ C ⟶ 0) ≫ default, ?_, ?_⟩ <;> simp [eq_iff_true_of_subsingleton] attribute [local instance] uniqueHomsetOfZero /-- A Cartesian closed category with a zero object is equivalent to the category with one object and one morphism. -/ def equivPUnit [HasZeroObject C] : C ≌ Discrete PUnit.{w + 1} where functor := Functor.star C inverse := Functor.fromPUnit 0 unitIso := NatIso.ofComponents (fun X => { hom := default inv := default }) fun _ => Subsingleton.elim _ _ counitIso := Functor.punitExt _ _ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/FunctorCategory/Complete.lean
import Mathlib.CategoryTheory.Adjunction.Lifting.Right import Mathlib.CategoryTheory.Closed.FunctorCategory.Groupoid import Mathlib.CategoryTheory.Groupoid.Discrete import Mathlib.CategoryTheory.Limits.Preserves.FunctorCategory import Mathlib.CategoryTheory.Monad.Comonadicity /-! # Functors into a complete monoidal closed category form a monoidal closed category. TODO (in progress by Joël Riou): make a more explicit construction of the internal hom in functor categories. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory MonoidalCategory MonoidalClosed Limits noncomputable section namespace CategoryTheory.Functor section variable (I : Type u₂) [Category.{v₂} I] private abbrev incl : Discrete I ⥤ I := Discrete.functor id variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory C] [MonoidalClosed C] variable [∀ (F : Discrete I ⥤ C), (Discrete.functor id).HasRightKanExtension F] -- is also implied by: `[HasLimitsOfSize.{u₂, max u₂ v₂} C]` instance : ReflectsIsomorphisms <| (whiskeringLeft _ _ C).obj (incl I) where reflects f h := by simp only [NatTrans.isIso_iff_isIso_app] at * intro X exact h ⟨X⟩ variable [HasLimitsOfShape WalkingParallelPair C] instance : Comonad.PreservesLimitOfIsCoreflexivePair ((whiskeringLeft _ _ C).obj (incl I)) := ⟨inferInstance⟩ instance : ComonadicLeftAdjoint ((whiskeringLeft _ _ C).obj (incl I)) := Comonad.comonadicOfHasPreservesCoreflexiveEqualizersOfReflectsIsomorphisms ((incl I).ranAdjunction C) instance (F : I ⥤ C) : IsLeftAdjoint (tensorLeft (incl I ⋙ F)) := (ihom.adjunction (incl I ⋙ F)).isLeftAdjoint /-- Auxiliary definition for `functorCategoryMonoidalClosed` -/ def functorCategoryClosed (F : I ⥤ C) : Closed F := have := (ihom.adjunction (incl I ⋙ F)).isLeftAdjoint have := isLeftAdjoint_square_lift_comonadic (tensorLeft F) ((whiskeringLeft _ _ C).obj (incl I)) ((whiskeringLeft _ _ C).obj (incl I)) (tensorLeft (incl I ⋙ F)) (Iso.refl _) { rightAdj := (tensorLeft F).rightAdjoint adj := Adjunction.ofIsLeftAdjoint (tensorLeft F) } /-- Assuming the existence of certain limits, functors into a monoidal closed category form a monoidal closed category. Note: this is defined completely abstractly, and does not have any good definitional properties. See the TODO in the module docstring. -/ def functorCategoryMonoidalClosed : MonoidalClosed (I ⥤ C) where closed F := functorCategoryClosed I C F end end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/FunctorCategory/Groupoid.lean
import Mathlib.CategoryTheory.Closed.Monoidal import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Monoidal.FunctorCategory /-! # Functors from a groupoid into a monoidal closed category form a monoidal closed category. (Using the pointwise monoidal structure on the functor category.) -/ noncomputable section open CategoryTheory CategoryTheory.MonoidalCategory CategoryTheory.MonoidalClosed namespace CategoryTheory.Functor variable {D C : Type*} [Groupoid D] [Category C] [MonoidalCategory C] [MonoidalClosed C] /-- Auxiliary definition for `CategoryTheory.Functor.closed`. The internal hom functor `F ⟶[C] -` -/ @[simps!] def closedIhom (F : D ⥤ C) : (D ⥤ C) ⥤ D ⥤ C := ((whiskeringRight₂ D Cᵒᵖ C C).obj internalHom).obj (Groupoid.invFunctor D ⋙ F.op) /-- Auxiliary definition for `CategoryTheory.Functor.closed`. The unit for the adjunction `(tensorLeft F) ⊣ (ihom F)`. -/ @[simps] def closedUnit (F : D ⥤ C) : 𝟭 (D ⥤ C) ⟶ tensorLeft F ⋙ closedIhom F where app G := { app := fun X => (ihom.coev (F.obj X)).app (G.obj X) naturality := by intro X Y f dsimp simp only [ihom.coev_naturality, closedIhom_obj_map, Monoidal.tensorObj_map] dsimp rw [coev_app_comp_pre_app_assoc, ← Functor.map_comp, tensorHom_def] simp } /-- Auxiliary definition for `CategoryTheory.Functor.closed`. The counit for the adjunction `(tensorLeft F) ⊣ (ihom F)`. -/ @[simps] def closedCounit (F : D ⥤ C) : closedIhom F ⋙ tensorLeft F ⟶ 𝟭 (D ⥤ C) where app G := { app := fun X => (ihom.ev (F.obj X)).app (G.obj X) naturality := by intro X Y f dsimp simp only [closedIhom_obj_map, pre_comm_ihom_map] rw [tensorHom_def] simp } /-- If `C` is a monoidal closed category and `D` is a groupoid, then every functor `F : D ⥤ C` is closed in the functor category `F : D ⥤ C` with the pointwise monoidal structure. -/ instance closed (F : D ⥤ C) : Closed F where rightAdj := closedIhom F adj := { unit := closedUnit F counit := closedCounit F } /-- If `C` is a monoidal closed category and `D` is groupoid, then the functor category `D ⥤ C`, with the pointwise monoidal structure, is monoidal closed. -/ @[simps! closed_adj] instance monoidalClosed : MonoidalClosed (D ⥤ C) where theorem ihom_map (F : D ⥤ C) {G H : D ⥤ C} (f : G ⟶ H) : (ihom F).map f = (closedIhom F).map f := rfl theorem ihom_ev_app (F G : D ⥤ C) : (ihom.ev F).app G = (closedCounit F).app G := rfl theorem ihom_coev_app (F G : D ⥤ C) : (ihom.coev F).app G = (closedUnit F).app G := rfl end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Closed/FunctorCategory/Basic.lean
import Mathlib.CategoryTheory.Closed.Enrichment import Mathlib.CategoryTheory.Enriched.FunctorCategory /-! # Functor categories are monoidal closed Let `C` be a monoidal closed category. Let `J` be a category. In this file, we obtain that the category `J ⥤ C` is monoidal closed if `C` has suitable limits. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Category Limits MonoidalCategory namespace MonoidalClosed namespace FunctorCategory open Enriched.FunctorCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [MonoidalClosed C] {J : Type u₂} [Category.{v₂} J] [∀ (F₁ F₂ : J ⥤ C), HasFunctorEnrichedHom C F₁ F₂] attribute [local simp] enrichedCategorySelf_hom section variable {F₁ F₂ F₂' F₃ F₃' : J ⥤ C} /-- The bijection `(F₁ ⊗ F₂ ⟶ F₃) ≃ (F₂ ⟶ functorEnrichedHom C F₁ F₃)` when `F₁`, `F₂` and `F₃` are functors `J ⥤ C`, and `C` is monoidal closed. -/ noncomputable def homEquiv : (F₁ ⊗ F₂ ⟶ F₃) ≃ (F₂ ⟶ functorEnrichedHom C F₁ F₃) where toFun f := { app j := end_.lift (fun k ↦ F₂.map k.hom ≫ curry (f.app k.right)) (fun k₁ k₂ φ ↦ by dsimp simp only [enrichedOrdinaryCategorySelf_eHomWhiskerLeft, Category.assoc, enrichedOrdinaryCategorySelf_eHomWhiskerRight] rw [← curry_natural_left_assoc, ← curry_natural_left_assoc, ← curry_natural_right, curry_pre_app, Category.assoc, ← f.naturality φ.right, Monoidal.tensorObj_map, tensorHom_def_assoc, ← Under.w φ, Functor.map_comp, MonoidalCategory.whiskerLeft_comp_assoc, whisker_exchange_assoc]) } invFun g := { app j := uncurry (g.app j ≫ enrichedHomπ C _ _ (Under.mk (𝟙 j)) ) naturality j j' φ := by dsimp rw [← uncurry_natural_right, tensorHom_def'_assoc, ← uncurry_pre_app, ← uncurry_natural_left, Category.assoc, Category.assoc, NatTrans.naturality_assoc, functorEnrichedHom_map, end_.lift_π_assoc, enrichedOrdinaryCategorySelf_eHomWhiskerRight] dsimp rw [pre_id, NatTrans.id_app, enrichedOrdinaryCategorySelf_eHomWhiskerLeft, Functor.map_id, Category.comp_id, Category.comp_id] congr 2 dsimp rw [← enrichedOrdinaryCategorySelf_eHomWhiskerRight, ← enrichedOrdinaryCategorySelf_eHomWhiskerLeft] let α : Under.mk (𝟙 j) ⟶ (Under.map φ).obj (Under.mk (𝟙 j')) := Under.homMk φ exact (enrichedHom_condition C (Under.forget j ⋙ F₁) (Under.forget j ⋙ F₃) α).symm } left_inv f := by cat_disch right_inv g := by ext j dsimp ext k -- this following list was obtained by -- `simp? [enrichedOrdinaryCategorySelf_eHomWhiskerLeft, Under.map, Comma.mapLeft]` simp only [diagram_obj_obj, Functor.comp_obj, Under.forget_obj, enrichedCategorySelf_hom, curry_uncurry, NatTrans.naturality_assoc, functorEnrichedHom_obj, functorEnrichedHom_map, Under.map, Comma.mapLeft, Functor.const_obj_obj, Functor.id_obj, Discrete.natTrans_app, StructuredArrow.left_eq_id, end_.lift_π, Under.mk_right, Under.mk_hom, Iso.refl_inv, NatTrans.id_app, enrichedOrdinaryCategorySelf_eHomWhiskerRight, pre_id, Iso.refl_hom, enrichedOrdinaryCategorySelf_eHomWhiskerLeft, Functor.map_id, Category.comp_id] congr simp lemma homEquiv_naturality_two_symm (f₂ : F₂ ⟶ F₂') (g : F₂' ⟶ functorEnrichedHom C F₁ F₃) : homEquiv.symm (f₂ ≫ g) = F₁ ◁ f₂ ≫ homEquiv.symm g := by dsimp [homEquiv] ext j simp [← uncurry_natural_left] lemma homEquiv_naturality_three [∀ (F₁ F₂ : J ⥤ C), HasEnrichedHom C F₁ F₂] (f : F₁ ⊗ F₂ ⟶ F₃) (f₃ : F₃ ⟶ F₃') : homEquiv (f ≫ f₃) = homEquiv f ≫ (ρ_ _).inv ≫ _ ◁ functorHomEquiv _ f₃ ≫ functorEnrichedComp C F₁ F₃ F₃' := by dsimp [homEquiv] ext j dsimp ext k rw [Category.assoc, Category.assoc, Category.assoc, end_.lift_π, enrichedComp_π, tensorHom_def, Category.assoc, whisker_exchange_assoc, whiskerRight_id_assoc, Iso.inv_hom_id_assoc, end_.lift_π_assoc, Category.assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, Category.assoc, end_.lift_π, enrichedOrdinaryCategorySelf_eHomWhiskerRight, enrichedOrdinaryCategorySelf_eHomWhiskerLeft] dsimp rw [pre_id, NatTrans.id_app, Functor.map_id, Category.comp_id, Category.comp_id, homEquiv_apply_π, curry_natural_right] congr 2 symm apply enrichedOrdinaryCategorySelf_eHomWhiskerLeft end variable [∀ (F₁ F₂ : J ⥤ C), HasEnrichedHom C F₁ F₂] attribute [local instance] Enriched.FunctorCategory.functorEnrichedOrdinaryCategory /-- When `C` is monoidal closed and has suitable limits, then for any `F : J ⥤ C`, `tensorLeft F` has a right adjoint. -/ noncomputable def adj (F : J ⥤ C) : MonoidalCategory.tensorLeft F ⊣ (eHomFunctor _ _).obj ⟨F⟩ := Adjunction.mkOfHomEquiv { homEquiv := fun _ _ ↦ homEquiv homEquiv_naturality_left_symm := homEquiv_naturality_two_symm homEquiv_naturality_right := homEquiv_naturality_three } /-- When `C` is monoidal closed and has suitable limits, then for any `F : J ⥤ C`, `tensorLeft F` has a right adjoint. -/ noncomputable def closed (F : J ⥤ C) : Closed F where rightAdj := (eHomFunctor _ _).obj ⟨F⟩ adj := adj F /-- If `C` is monoidal closed and has suitable limits, the functor category `J ⥤ C` is monoidal closed. -/ noncomputable scoped instance monoidalClosed : MonoidalClosed (J ⥤ C) where closed := closed end FunctorCategory end MonoidalClosed end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Topos/Classifier.lean
import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Functor.ReflectsIso.Balanced import Mathlib.CategoryTheory.Subobject.Presheaf /-! # Subobject Classifier We define what it means for a morphism in a category to be a subobject classifier as `CategoryTheory.HasClassifier`. c.f. the following Lean 3 code, where similar work was done: https://github.com/b-mehta/topos/blob/master/src/subobject_classifier.lean ## Main definitions Let `C` refer to a category with a terminal object. * `CategoryTheory.Classifier C` is the data of a subobject classifier in `C`. * `CategoryTheory.HasClassifier C` says that there is at least one subobject classifier. `Ω C` denotes a choice of subobject classifier. ## Main results * It is a theorem that the truth morphism `⊤_ C ⟶ Ω C` is a (split, and therefore regular) monomorphism, simply because its source is the terminal object. * An instance of `IsRegularMonoCategory C` is exhibited for any category with a subobject classifier. * `CategoryTheory.Classifier.representableBy`: any subobject classifier `Ω` in `C` represents the subobjects functor `CategoryTheory.Subobject.presheaf C`. * `CategoryTheory.Classifier.SubobjectRepresentableBy.classifier`: any representation `Ω` of `CategoryTheory.Subobject.presheaf C` is a subobject classifier in `C`. * `CategoryTheory.hasClassifier_isRepresentable_iff`: from the two above mappings, we get that a category `C` has a subobject classifier if and only if the subobjects presheaf `CategoryTheory.Subobject.presheaf C` is representable (Proposition 1 in Section I.3 of [MM92]). ## References * [S. MacLane and I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] -/ universe u v u₀ v₀ namespace CategoryTheory open Category Limits Functor IsPullback variable (C : Type u) [Category.{v} C] /-- A monomorphism `truth : Ω₀ ⟶ Ω` is a subobject classifier if, for every monomorphism `m : U ⟶ X` in `C`, there is a unique map `χ : X ⟶ Ω` such that for some (necessarily unique) `χ₀ : U ⟶ Ω₀` the following square is a pullback square: ``` U ---------m----------> X | | χ₀ U χ m | | v v Ω₀ ------truth--------> Ω ``` An equivalent formulation replaces `Ω₀` with the terminal object. -/ structure Classifier where /-- The domain of the truth morphism -/ Ω₀ : C /-- The codomain of the truth morphism -/ Ω : C /-- The truth morphism of the subobject classifier -/ truth : Ω₀ ⟶ Ω /-- The truth morphism is a monomorphism -/ mono_truth : Mono truth /-- The top arrow in the pullback square -/ χ₀ (U : C) : U ⟶ Ω₀ /-- For any monomorphism `U ⟶ X`, there is an associated characteristic map `X ⟶ Ω`. -/ χ {U X : C} (m : U ⟶ X) [Mono m] : X ⟶ Ω /-- `χ₀ U` and `χ m` form the appropriate pullback square. -/ isPullback {U X : C} (m : U ⟶ X) [Mono m] : IsPullback m (χ₀ U) (χ m) truth /-- `χ m` is the only map `X ⟶ Ω` which forms the appropriate pullback square for any `χ₀'`. -/ uniq {U X : C} (m : U ⟶ X) [Mono m] {χ₀' : U ⟶ Ω₀} {χ' : X ⟶ Ω} (hχ' : IsPullback m χ₀' χ' truth) : χ' = χ m variable {C} namespace Classifier attribute [instance] mono_truth /-- More explicit constructor in case `Ω₀` is already known to be a terminal object. -/ @[simps] def mkOfTerminalΩ₀ (Ω₀ : C) (t : IsTerminal Ω₀) (Ω : C) (truth : Ω₀ ⟶ Ω) (χ : ∀ {U X : C} (m : U ⟶ X) [Mono m], X ⟶ Ω) (isPullback : ∀ {U X : C} (m : U ⟶ X) [Mono m], IsPullback m (t.from U) (χ m) truth) (uniq : ∀ {U X : C} (m : U ⟶ X) [Mono m] (χ' : X ⟶ Ω) (_ : IsPullback m (t.from U) χ' truth), χ' = χ m) : Classifier C where Ω₀ := Ω₀ Ω := Ω truth := truth mono_truth := t.mono_from _ χ₀ := t.from χ m _ := χ m isPullback m _ := isPullback m uniq m _ χ₀' χ' hχ' := uniq m χ' ((t.hom_ext χ₀' (t.from _)) ▸ hχ') instance {c : Classifier C} : ∀ Y : C, Unique (Y ⟶ c.Ω₀) := fun Y => { default := c.χ₀ Y, uniq f := have : f ≫ c.truth = c.χ₀ Y ≫ c.truth := by calc _ = c.χ (𝟙 Y) := c.uniq (𝟙 Y) (of_horiz_isIso_mono { }) _ = c.χ₀ Y ≫ c.truth := by simp [← (c.isPullback (𝟙 Y)).w] Mono.right_cancellation _ _ this } /-- Given `c : Classifier C`, `c.Ω₀` is a terminal object. Prefer `c.χ₀` over `c.isTerminalΩ₀.from`. -/ def isTerminalΩ₀ {c : Classifier C} : IsTerminal c.Ω₀ := IsTerminal.ofUnique c.Ω₀ @[simp] lemma isTerminalFrom_eq_χ₀ (c : Classifier C) : c.isTerminalΩ₀.from = c.χ₀ := rfl end Classifier /-- A category `C` has a subobject classifier if there is at least one subobject classifier. -/ class HasClassifier (C : Type u) [Category.{v} C] : Prop where /-- There is some classifier. -/ exists_classifier : Nonempty (Classifier C) namespace HasClassifier variable (C) [HasClassifier C] noncomputable section /-- Notation for the `Ω₀` in an arbitrary choice of a subobject classifier -/ abbrev Ω₀ : C := HasClassifier.exists_classifier.some.Ω₀ /-- Notation for the `Ω` in an arbitrary choice of a subobject classifier -/ abbrev Ω : C := HasClassifier.exists_classifier.some.Ω /-- Notation for the "truth arrow" in an arbitrary choice of a subobject classifier -/ abbrev truth : Ω₀ C ⟶ Ω C := HasClassifier.exists_classifier.some.truth variable {C} {U X : C} (m : U ⟶ X) [Mono m] /-- returns the characteristic morphism of the subobject `(m : U ⟶ X) [Mono m]` -/ def χ : X ⟶ Ω C := HasClassifier.exists_classifier.some.χ m /-- The diagram ``` U ---------m----------> X | | χ₀ U χ m | | v v Ω₀ ------truth--------> Ω ``` is a pullback square. -/ lemma isPullback_χ : IsPullback m (Classifier.χ₀ _ U) (χ m) (truth C) := Classifier.isPullback _ m /-- The diagram ``` U ---------m----------> X | | χ₀ U χ m | | v v Ω₀ ------truth--------> Ω ``` commutes. -/ @[reassoc] lemma comm : m ≫ χ m = Classifier.χ₀ _ U ≫ truth C := (isPullback_χ m).w /-- `χ m` is the only map for which the associated square is a pullback square. -/ lemma unique (χ' : X ⟶ Ω C) (hχ' : IsPullback m (Classifier.χ₀ _ U) χ' (truth C)) : χ' = χ m := Classifier.uniq _ m hχ' instance truthIsSplitMono : IsSplitMono (truth C) := Classifier.isTerminalΩ₀.isSplitMono_from _ /-- `truth C` is a regular monomorphism (because it is split). -/ noncomputable instance truthIsRegularMono : RegularMono (truth C) := RegularMono.ofIsSplitMono (truth C) /-- The following diagram ``` U ---------m----------> X | | χ₀ U χ m | | v v Ω₀ ------truth--------> Ω ``` being a pullback for any monic `m` means that every monomorphism in `C` is the pullback of a regular monomorphism; since regularity is stable under base change, every monomorphism is regular. Hence, `C` is a regular mono category. It also follows that `C` is a balanced category. -/ instance isRegularMonoCategory : IsRegularMonoCategory C where regularMonoOfMono := fun m => ⟨regularOfIsPullbackFstOfRegular (isPullback_χ m).w (isPullback_χ m).isLimit⟩ /-- If the source of a faithful functor has a subobject classifier, the functor reflects isomorphisms. This holds for any balanced category. -/ instance reflectsIsomorphisms (D : Type u₀) [Category.{v₀} D] (F : C ⥤ D) [Functor.Faithful F] : Functor.ReflectsIsomorphisms F := reflectsIsomorphisms_of_reflectsMonomorphisms_of_reflectsEpimorphisms F /-- If the source of a faithful functor is the opposite category of one with a subobject classifier, the same holds -- the functor reflects isomorphisms. -/ instance reflectsIsomorphismsOp (D : Type u₀) [Category.{v₀} D] (F : Cᵒᵖ ⥤ D) [Functor.Faithful F] : Functor.ReflectsIsomorphisms F := reflectsIsomorphisms_of_reflectsMonomorphisms_of_reflectsEpimorphisms F end end HasClassifier /-! ### The representability theorem of subobject classifiers -/ section Representability namespace Classifier open Subobject /-! #### From classifiers to representations -/ section RepresentableBy variable {C : Type u} [Category.{v} C] [HasPullbacks C] (𝒞 : Classifier C) /-- The subobject of `𝒞.Ω` corresponding to the `truth` morphism. -/ abbrev truth_as_subobject : Subobject 𝒞.Ω := Subobject.mk 𝒞.truth lemma surjective_χ {X : C} (φ : X ⟶ 𝒞.Ω) : ∃ (Z : C) (i : Z ⟶ X) (_ : Mono i), φ = 𝒞.χ i := ⟨Limits.pullback φ 𝒞.truth, pullback.fst _ _, inferInstance, 𝒞.uniq _ (by convert IsPullback.of_hasPullback φ 𝒞.truth)⟩ @[simp] lemma pullback_χ_obj_mk_truth {Z X : C} (i : Z ⟶ X) [Mono i] : (Subobject.pullback (𝒞.χ i)).obj 𝒞.truth_as_subobject = .mk i := Subobject.pullback_obj_mk (𝒞.isPullback i).flip @[simp] lemma χ_pullback_obj_mk_truth_arrow {X : C} (φ : X ⟶ 𝒞.Ω) : 𝒞.χ ((Subobject.pullback φ).obj 𝒞.truth_as_subobject).arrow = φ := by obtain ⟨Z, i, _, rfl⟩ := 𝒞.surjective_χ φ refine (𝒞.uniq _ (?_ : IsPullback _ (𝒞.χ₀ _) _ _)).symm refine (IsPullback.of_hasPullback 𝒞.truth (𝒞.χ i)).flip.of_iso (underlyingIso _).symm (Iso.refl _) (Iso.refl _) (Iso.refl _) ?_ (𝒞.isTerminalΩ₀.hom_ext _ _) (by simp) (by simp) dsimp rw [Iso.eq_inv_comp, comp_id, underlyingIso_hom_comp_eq_mk] rfl /-- Any subobject classifier `Ω` represents the subobjects functor `Subobject.presheaf`. -/ noncomputable def representableBy : (Subobject.presheaf C).RepresentableBy 𝒞.Ω where homEquiv := { toFun φ := (Subobject.pullback φ).obj 𝒞.truth_as_subobject invFun x := 𝒞.χ x.arrow left_inv φ := by simp right_inv x := by simp } homEquiv_comp _ _ := by simp [pullback_comp] end RepresentableBy /-! #### From representations to classifiers -/ section FromRepresentation variable {C : Type u} [Category.{v} C] [HasPullbacks C] (Ω : C) /-- Abbreviation to enable dot notation on the hypothesis `h` stating that the subobjects presheaf is representable by some object `Ω`. -/ abbrev SubobjectRepresentableBy := (Subobject.presheaf C).RepresentableBy Ω variable {Ω} (h : SubobjectRepresentableBy Ω) namespace SubobjectRepresentableBy /-- `h.Ω₀` is the subobject of `Ω` which corresponds to the identity `𝟙 Ω`, given `h : SubobjectRepresentableBy Ω`. -/ def Ω₀ : Subobject Ω := h.homEquiv (𝟙 Ω) /-- `h.homEquiv` acts like an "object comprehension" operator: it maps any characteristic map `f : X ⟶ Ω` to the associated subobject of `X`, obtained by pulling back `h.Ω₀` along `f`. -/ lemma homEquiv_eq {X : C} (f : X ⟶ Ω) : h.homEquiv f = (Subobject.pullback f).obj h.Ω₀ := by simpa using h.homEquiv_comp f (𝟙 _) /-- For any subobject `x`, the pullback of `h.Ω₀` along the characteristic map of `x` given by `h.homEquiv` is `x` itself. -/ lemma pullback_homEquiv_symm_obj_Ω₀ {X : C} (x : Subobject X) : (Subobject.pullback (h.homEquiv.symm x)).obj h.Ω₀ = x := by rw [← homEquiv_eq, Equiv.apply_symm_apply] section variable {U X : C} (m : U ⟶ X) [Mono m] /-- `h.χ m` is the characteristic map of monomorphism `m` given by the bijection `h.homEquiv`. -/ def χ : X ⟶ Ω := h.homEquiv.symm (Subobject.mk m) /-- `h.iso m` is the isomorphism between `m` and the pullback of `Ω₀` along the characteristic map of `m`. -/ noncomputable def iso : MonoOver.mk' m ≅ Subobject.representative.obj ((Subobject.pullback (h.χ m)).obj h.Ω₀) := (Subobject.representativeIso (.mk' m)).symm ≪≫ Subobject.representative.mapIso (eqToIso (h.pullback_homEquiv_symm_obj_Ω₀ (.mk m)).symm) /-- `h.π m` is the first projection in the following pullback square: ``` U --h.π m--> (Ω₀ : C) | | m Ω₀.arrow | | v v X -----h.χ m---> Ω ``` -/ noncomputable def π : U ⟶ Subobject.underlying.obj h.Ω₀ := (h.iso m).hom.left ≫ Subobject.pullbackπ (h.χ m) h.Ω₀ @[reassoc (attr := simp)] lemma iso_inv_left_π : (h.iso m).inv.left ≫ h.π m = Subobject.pullbackπ (h.χ m) h.Ω₀ := by dsimp only [π] rw [← Over.comp_left_assoc] convert Category.id_comp _ using 2 exact (MonoOver.forget _ ⋙ Over.forget _ ).congr_map (h.iso m).inv_hom_id @[reassoc (attr := simp)] lemma iso_inv_left_comp : (h.iso m).inv.left ≫ m = ((Subobject.pullback (h.χ m)).obj h.Ω₀).arrow := MonoOver.w (h.iso m).inv lemma isPullback {U X : C} (m : U ⟶ X) [Mono m] : IsPullback m (h.π m) (h.χ m) h.Ω₀.arrow := by fapply (Subobject.isPullback (h.χ m) h.Ω₀).flip.of_iso (((MonoOver.forget _ ⋙ Over.forget _).mapIso (h.iso m)).symm) (Iso.refl _) (Iso.refl _) (Iso.refl _) all_goals simp [MonoOver.forget] variable {m} lemma uniq {χ' : X ⟶ Ω} {π : U ⟶ h.Ω₀} (sq : IsPullback m π χ' h.Ω₀.arrow) : χ' = h.χ m := by apply h.homEquiv.injective simp only [χ, Equiv.apply_symm_apply, homEquiv_eq] simpa using Subobject.pullback_obj_mk sq.flip end /-- The main non-trivial result: `h.Ω₀` is actually a terminal object. -/ noncomputable def isTerminalΩ₀ : IsTerminal (h.Ω₀ : C) := IsTerminal.ofUniqueHom (fun X ↦ h.π (𝟙 X)) (fun X π' ↦ by have : IsPullback (𝟙 X) π' (π' ≫ h.Ω₀.arrow) h.Ω₀.arrow := { isLimit' := ⟨PullbackCone.IsLimit.mk _ (fun s ↦ s.fst) (by simp) (fun s ↦ by rw [← cancel_mono h.Ω₀.arrow, ← s.condition, Category.assoc]) (fun s m hm _ ↦ by simpa using hm) ⟩ } rw [← cancel_mono h.Ω₀.arrow, h.uniq this, ← (h.isPullback (𝟙 X)).w, Category.id_comp]) /-- The unique map to the terminal object. -/ noncomputable def χ₀ (U : C) : U ⟶ h.Ω₀ := h.isTerminalΩ₀.from U include h in lemma hasTerminal : HasTerminal C := h.isTerminalΩ₀.hasTerminal variable [HasTerminal C] /-- `h.isoΩ₀` is the unique isomorphism from `h.Ω₀` to the canonical terminal object `⊤_ C`. -/ noncomputable def isoΩ₀ : (h.Ω₀ : C) ≅ ⊤_ C := h.isTerminalΩ₀.conePointUniqueUpToIso (limit.isLimit _) /-- Any representation `Ω` of `Subobject.presheaf C` gives a subobject classifier with truth values object `Ω`. -/ noncomputable def classifier : Classifier C where Ω₀ := ⊤_ C Ω := Ω truth := h.isoΩ₀.inv ≫ h.Ω₀.arrow mono_truth := terminalIsTerminal.mono_from _ χ₀ := terminalIsTerminal.from χ m _ := h.χ m isPullback m _ := (h.isPullback m).of_iso (Iso.refl _) (Iso.refl _) h.isoΩ₀ (Iso.refl _) (by simp) (Subsingleton.elim _ _) (by simp) (by simp) uniq {U X} m _ χ₀ χ' sq := by have : IsPullback m (h.χ₀ U) χ' h.Ω₀.arrow := sq.of_iso (Iso.refl _) (Iso.refl _) (h.isoΩ₀.symm) (Iso.refl _) (by simp) (h.isTerminalΩ₀.hom_ext _ _) (by simp) (by simp) exact h.uniq this end SubobjectRepresentableBy end FromRepresentation end Classifier variable [HasTerminal C] /-- A category has a subobject classifier if and only if the subobjects functor is representable. -/ theorem isRepresentable_hasClassifier_iff [HasPullbacks C] : HasClassifier C ↔ (Subobject.presheaf C).IsRepresentable := by constructor <;> intro h · obtain ⟨⟨𝒞⟩⟩ := h apply RepresentableBy.isRepresentable exact 𝒞.representableBy · obtain ⟨Ω, ⟨h⟩⟩ := h constructor; constructor exact Classifier.SubobjectRepresentableBy.classifier h end Representability end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/WithTerminal/Lemmas.lean
import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.WithTerminal.Basic /-! # Further lemmas on `WithTerminal` These lemmas and instances need more imports. -/ namespace CategoryTheory variable {C : Type*} [Category C] namespace WithTerminal open IsCofiltered in instance [IsCofilteredOrEmpty C] : IsCofiltered (WithTerminal C) where cone_objs x y := match x, y with | star, y => ⟨y, default, 𝟙 y, trivial⟩ | x, star => ⟨x, 𝟙 x, default, trivial⟩ | of x, of y => ⟨.of <| min x y, minToLeft _ _, minToRight _ _, trivial⟩ cone_maps x y f g := match x, y with | star, _ => ⟨star, 𝟙 _, (IsIso.eq_comp_inv f).mp rfl⟩ | x, star => ⟨x, 𝟙 _, Subsingleton.elim _ _⟩ | of _, of _ => ⟨.of <| eq f g, eqHom _ _, eq_condition _ _⟩ end WithTerminal namespace WithInitial instance [IsFilteredOrEmpty C] : IsFiltered (WithInitial C) := have := IsCofiltered.of_equivalence (opEquiv C).symm isFiltered_of_isCofiltered_op _ end WithInitial end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/WithTerminal/Cone.lean
import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.WithTerminal.Basic /-! # Relations between `Cone`, `WithTerminal` and `Over` Given categories `C` and `J`, an object `X : C` and a functor `K : J ⥤ Over X`, it has an obvious lift `liftFromOver K : WithTerminal J ⥤ C`, namely, send the terminal object to `X`. These two functors have equivalent categories of cones (`coneEquiv`). As a corollary, the limit of `K` is the limit of `liftFromOver K`, and vice-versa. -/ open CategoryTheory Limits universe w w' v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {J : Type w} [Category.{w'} J] namespace CategoryTheory.WithTerminal variable {X : C} {K : J ⥤ Over X} {F : C ⥤ D} {t : Cone K} /-- The category of functors `J ⥤ Over X` can be seen as part of a comma category, namely the comma category constructed from the identity of the category of functors `J ⥤ C` and the functor that maps `X : C` to the constant functor `J ⥤ C`. Given a functor `K : J ⥤ Over X`, it is mapped to a natural transformation from the obvious functor `J ⥤ C` to the constant functor `X`. -/ @[simps] def commaFromOver : (J ⥤ Over X) ⥤ Comma (𝟭 (J ⥤ C)) (Functor.const J) where obj K := { left := K ⋙ Over.forget X right := X hom.app a := (K.obj a).hom } map f := { left := Functor.whiskerRight f (Over.forget X) right := 𝟙 X } /-- For any functor `K : J ⥤ Over X`, there is a canonical extension `WithTerminal J ⥤ C`, that sends `star` to `X`. -/ @[simps!] def liftFromOver : (J ⥤ Over X) ⥤ WithTerminal J ⥤ C := commaFromOver ⋙ equivComma.inverse /-- The extension of a functor to over categories behaves well with compositions. -/ @[simps] def liftFromOverComp : liftFromOver.obj (K ⋙ Over.post F) ≅ liftFromOver.obj K ⋙ F where hom.app | star | of a => 𝟙 _ inv.app | star | of a => 𝟙 _ /-- A cone of a functor `K : J ⥤ Over X` consists of an object of `Over X`, together with morphisms. This same object is a cone of the extended functor `liftFromOver.obj K : WithTerminal J ⥤ C`. -/ @[simps] private def coneLift : Cone K ⥤ Cone (liftFromOver.obj K) where obj t := { pt := t.pt.left π.app | of a => (t.π.app a).left | star => t.pt.hom π.naturality | star, star, _ | of a, star, _ => by aesop | of a, of b, f => by simp [← Comma.comp_left] } map {t₁ t₂} f := { hom := f.hom.left w | star => by cat_disch | of a => by simp [← Comma.comp_left] } /-- This is the inverse of the previous construction: a cone of an extended functor `liftFromOver.obj K : WithTerminal J ⥤ C` consists of an object of `C`, together with morphisms. This same object is a cone of the original functor `K : J ⥤ Over X`. -/ @[simps] private def coneBack : Cone (liftFromOver.obj K) ⥤ Cone K where obj t := { pt := .mk (t.π.app star) π.app a := { left := t.π.app (of a) right := 𝟙 _ w := by simpa using t.w (homFrom a) } π.naturality a b f := by ext; simpa using t.π.naturality (incl.map f) } map {t₁ t₂ f} := { hom := Over.homMk f.hom } /-- Given a functor `K : J ⥤ Over X` and its extension `liftFromOver K : WithTerminal J ⥤ C`, there is an obvious equivalence between cones of these two functors. A cone of `K` is an object of `Over X`, so it has the form `t ⟶ X`. Equivalently, a cone of `WithTerminal K` is an object `t : C`, and we can recover the structure morphism as `π.app X : t ⟶ X`. -/ @[simps! functor_obj_pt functor_map_hom inverse_obj_pt_left inverse_obj_pt_right_as inverse_obj_pt_hom inverse_obj_π_app_left inverse_map_hom_left unitIso_hom_app_hom_left unitIso_inv_app_hom_left counitIso_hom_app_hom counitIso_inv_app_hom] def coneEquiv : Cone K ≌ Cone (liftFromOver.obj K) where functor := coneLift inverse := coneBack unitIso := .refl _ counitIso := NatIso.ofComponents fun t ↦ Cones.ext <| .refl _ @[simp] lemma coneEquiv_functor_obj_π_app_star : (coneEquiv.functor.obj t).π.app star = t.pt.hom := rfl @[simp] lemma coneEquiv_functor_obj_π_app_of (Y : J) : (coneEquiv.functor.obj t).π.app (of Y) = (t.π.app Y).left := rfl /-- A cone `t` of `K : J ⥤ Over X` is a limit if and only if the corresponding cone `coneLift t` of `liftFromOver.obj K : WithTerminal K ⥤ C` is a limit. -/ @[simps!] def isLimitEquiv : IsLimit (coneEquiv.functor.obj t) ≃ IsLimit t := IsLimit.ofConeEquiv coneEquiv end WithTerminal open WithTerminal in lemma Over.hasLimit_of_hasLimit_liftFromOver {X : C} (F : J ⥤ Over X) [HasLimit (liftFromOver.obj F)] : HasLimit F := ⟨_, isLimitEquiv <| .ofIsoLimit (limit.isLimit (liftFromOver.obj F)) (coneEquiv.counitIso.app _).symm⟩ instance (X : C) [HasLimitsOfShape (WithTerminal J) C] : HasLimitsOfShape J (Over X) where has_limit _ := Over.hasLimit_of_hasLimit_liftFromOver .. instance (X : C) [HasLimitsOfSize.{w, w'} C] : HasLimitsOfSize.{w, w'} (Over X) where namespace WithInitial variable {X : C} {K : J ⥤ Under X} {F : C ⥤ D} {t : Cocone K} /-- The category of functors `J ⥤ Under X` can be seen as part of a comma category, namely the comma category constructed from the identity of the category of functors `J ⥤ C` and the functor that maps `X : C` to the constant functor `J ⥤ C`. Given a functor `K : J ⥤ Under X`, it is mapped to a natural transformation to the obvious functor `J ⥤ C` from the constant functor `X`. -/ @[simps] def commaFromUnder : (J ⥤ Under X) ⥤ Comma (Functor.const J) (𝟭 (J ⥤ C)) where obj K := { left := X right := K ⋙ Under.forget X hom.app a := (K.obj a).hom } map f := { left := 𝟙 X right := Functor.whiskerRight f (Under.forget X) } /-- For any functor `K : J ⥤ Under X`, there is a canonical extension `WithInitial J ⥤ C`, that sends `star` to `X`. -/ @[simps!] def liftFromUnder : (J ⥤ Under X) ⥤ WithInitial J ⥤ C := commaFromUnder ⋙ equivComma.inverse /-- The extension of a functor to under categories behaves well with compositions. -/ @[simps] def liftFromUnderComp : liftFromUnder.obj (K ⋙ Under.post F) ≅ liftFromUnder.obj K ⋙ F where hom.app | star | of a => 𝟙 _ inv.app | star | of a => 𝟙 _ /-- A cocone of a functor `K : J ⥤ Under X` consists of an object of `Under X`, together with morphisms. This same object is a cocone of the extended functor `liftFromUnder.obj K : WithInitial J ⥤ C`. -/ @[simps] private def coconeLift : Cocone K ⥤ Cocone (liftFromUnder.obj K) where obj t := { pt := t.pt.right ι.app | of a => (t.ι.app a).right | star => t.pt.hom ι.naturality | star, star, _ | star, of b, _ => by aesop | of a, of b, f => by simp [← Comma.comp_right] } map {t₁ t₂} f := { hom := f.hom.right w | star => by cat_disch | of a => by simp [← Comma.comp_right] } /-- This is the inverse of the previous construction: a cocone of an extended functor `liftFromUnder.obj K : WithInitial J ⥤ C` consists of an object of `C`, together with morphisms. This same object is a cocone of the original functor `K : J ⥤ Under X`. -/ @[simps] private def coconeBack : Cocone (liftFromUnder.obj K) ⥤ Cocone K where obj t := { pt := .mk (t.ι.app star) ι.app a := { left := 𝟙 _ right := t.ι.app (of a) w := by simpa using (t.w (homTo a)).symm } ι.naturality a b f := by ext; simpa using t.ι.naturality (incl.map f) } map {t₁ t₂ f} := { hom := Under.homMk f.hom } /-- Given a functor `K : J ⥤ Under X` and its extension `liftFromUnder K : WithInitial J ⥤ C`, there is an obvious equivalence between cocones of these two functors. A cocone of `K` is an object of `Under X`, so it has the form `X ⟶ t`. Equivalently, a cocone of `WithInitial K` is an object `t : C`, and we can recover the structure morphism as `ι.app X : X ⟶ t`. -/ @[simps! functor_obj_pt functor_map_hom inverse_obj_pt_right inverse_obj_pt_left_as inverse_obj_pt_hom inverse_obj_ι_app_right inverse_map_hom_right unitIso_hom_app_hom_right unitIso_inv_app_hom_right counitIso_hom_app_hom counitIso_inv_app_hom] def coconeEquiv : Cocone K ≌ Cocone (liftFromUnder.obj K) where functor := coconeLift inverse := coconeBack unitIso := .refl _ counitIso := NatIso.ofComponents fun t ↦ Cocones.ext <| .refl _ @[simp] lemma coconeEquiv_functor_obj_ι_app_star : (coconeEquiv.functor.obj t).ι.app star = t.pt.hom := rfl @[simp] lemma coconeEquiv_functor_obj_ι_app_of (Y : J) : (coconeEquiv.functor.obj t).ι.app (of Y) = (t.ι.app Y).right := rfl /-- A cocone `t` of `K : J ⥤ Under X` is a colimit if and only if the corresponding cocone `coconeLift t` of `liftFromUnder.obj K : WithInitial K ⥤ C` is a colimit. -/ @[simps!] def isColimitEquiv : IsColimit (coconeEquiv.functor.obj t) ≃ IsColimit t := IsColimit.ofCoconeEquiv coconeEquiv end CategoryTheory.WithInitial open WithInitial in lemma Under.hasColimit_of_hasColimit_liftFromUnder {X : C} (F : J ⥤ Under X) [HasColimit (liftFromUnder.obj F)] : HasColimit F := ⟨_, isColimitEquiv <| .ofIsoColimit (colimit.isColimit (liftFromUnder.obj F)) (coconeEquiv.counitIso.app _).symm⟩ instance (X : C) [HasColimitsOfShape (WithInitial J) C] : HasColimitsOfShape J (Under X) where has_colimit _ := Under.hasColimit_of_hasColimit_liftFromUnder .. instance (X : C) [HasColimitsOfSize.{w, w'} C] : HasColimitsOfSize.{w, w'} (Under X) where
.lake/packages/mathlib/Mathlib/CategoryTheory/WithTerminal/Basic.lean
import Mathlib.CategoryTheory.Limits.Shapes.IsTerminal import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor /-! # `WithInitial` and `WithTerminal` Given a category `C`, this file constructs two objects: 1. `WithTerminal C`, the category built from `C` by formally adjoining a terminal object. 2. `WithInitial C`, the category built from `C` by formally adjoining an initial object. The terminal resp. initial object is `WithTerminal.star` resp. `WithInitial.star`, and the proofs that these are terminal resp. initial are in `WithTerminal.star_terminal` and `WithInitial.star_initial`. The inclusion from `C` into `WithTerminal C` resp. `WithInitial C` is denoted `WithTerminal.incl` resp. `WithInitial.incl`. The relevant constructions needed for the universal properties of these constructions are: 1. `lift`, which lifts `F : C ⥤ D` to a functor from `WithTerminal C` resp. `WithInitial C` in the case where an object `Z : D` is provided satisfying some additional conditions. 2. `inclLift` shows that the composition of `lift` with `incl` is isomorphic to the functor which was lifted. 3. `liftUnique` provides the uniqueness property of `lift`. In addition to this, we provide `WithTerminal.map` and `WithInitial.map` providing the functoriality of these constructions with respect to functors on the base categories. We define corresponding pseudofunctors `WithTerminal.pseudofunctor` and `WithInitial.pseudofunctor` from `Cat` to `Cat`. -/ namespace CategoryTheory universe v u variable (C : Type u) [Category.{v} C] /-- Formally adjoin a terminal object to a category. -/ inductive WithTerminal : Type u | of : C → WithTerminal | star : WithTerminal deriving Inhabited attribute [local aesop safe cases (rule_sets := [CategoryTheory])] WithTerminal /-- Formally adjoin an initial object to a category. -/ inductive WithInitial : Type u | of : C → WithInitial | star : WithInitial deriving Inhabited attribute [local aesop safe cases (rule_sets := [CategoryTheory])] WithInitial namespace WithTerminal variable {C} /-- Morphisms for `WithTerminal C`. -/ @[simp] def Hom : WithTerminal C → WithTerminal C → Type v | of X, of Y => X ⟶ Y | star, of _ => PEmpty | _, star => PUnit attribute [nolint simpNF] Hom.eq_3 /-- Identity morphisms for `WithTerminal C`. -/ @[simp] def id : ∀ X : WithTerminal C, Hom X X | of _ => 𝟙 _ | star => PUnit.unit /-- Composition of morphisms for `WithTerminal C`. -/ @[simp] def comp : ∀ {X Y Z : WithTerminal C}, Hom X Y → Hom Y Z → Hom X Z | of _X, of _Y, of _Z => fun f g => f ≫ g | of _X, _, star => fun _f _g => PUnit.unit | star, of _X, _ => fun f _g => PEmpty.elim f | _, star, of _Y => fun _f g => PEmpty.elim g | star, star, star => fun _ _ => PUnit.unit attribute [nolint simpNF] comp.eq_4 @[aesop safe destruct (rule_sets := [CategoryTheory])] lemma false_of_from_star' {X : C} (f : Hom star (of X)) : False := (f : PEmpty).elim instance : Category.{v} (WithTerminal C) where Hom X Y := Hom X Y id _ := id _ comp := comp /-- Helper function for typechecking. -/ def down {X Y : C} (f : of X ⟶ of Y) : X ⟶ Y := f @[simp] lemma down_id {X : C} : down (𝟙 (of X)) = 𝟙 X := rfl @[simp] lemma down_comp {X Y Z : C} (f : of X ⟶ of Y) (g : of Y ⟶ of Z) : down (f ≫ g) = down f ≫ down g := rfl @[aesop safe destruct (rule_sets := [CategoryTheory])] lemma false_of_from_star {X : C} (f : star ⟶ of X) : False := (f : PEmpty).elim /-- The inclusion from `C` into `WithTerminal C`. -/ def incl : C ⥤ WithTerminal C where obj := of map f := f instance : (incl : C ⥤ _).Full where map_surjective f := ⟨f, rfl⟩ instance : (incl : C ⥤ _).Faithful where /-- Map `WithTerminal` with respect to a functor `F : C ⥤ D`. -/ @[simps] def map {D : Type*} [Category D] (F : C ⥤ D) : WithTerminal C ⥤ WithTerminal D where obj X := match X with | of x => of <| F.obj x | star => star map {X Y} f := match X, Y, f with | of _, of _, f => F.map (down f) | of _, star, _ => PUnit.unit | star, star, _ => PUnit.unit /-- A natural isomorphism between the functor `map (𝟭 C)` and `𝟭 (WithTerminal C)`. -/ @[simps!] def mapId (C : Type*) [Category C] : map (𝟭 C) ≅ 𝟭 (WithTerminal C) := NatIso.ofComponents (fun X => match X with | of _ => Iso.refl _ | star => Iso.refl _) (by cat_disch) /-- A natural isomorphism between the functor `map (F ⋙ G) ` and `map F ⋙ map G `. -/ @[simps!] def mapComp {D E : Type*} [Category D] [Category E] (F : C ⥤ D) (G : D ⥤ E) : map (F ⋙ G) ≅ map F ⋙ map G := NatIso.ofComponents (fun X => match X with | of _ => Iso.refl _ | star => Iso.refl _) (by cat_disch) /-- From a natural transformation of functors `C ⥤ D`, the induced natural transformation of functors `WithTerminal C ⥤ WithTerminal D`. -/ @[simps] def map₂ {D : Type*} [Category D] {F G : C ⥤ D} (η : F ⟶ G) : map F ⟶ map G where app := fun X => match X with | of x => η.app x | star => 𝟙 star naturality := by intro X Y f match X, Y, f with | of x, of y, f => exact η.naturality f | of x, star, _ => rfl | star, star, _ => rfl -- Note: ... /-- The prelax functor from `Cat` to `Cat` defined with `WithTerminal`. -/ @[simps] def prelaxfunctor : PrelaxFunctor Cat Cat where obj C := Cat.of (WithTerminal C) map := map map₂ := map₂ map₂_id := by intros apply NatTrans.ext funext X cases X <;> rfl map₂_comp := by intros apply NatTrans.ext funext X cases X <;> rfl /-- The pseudofunctor from `Cat` to `Cat` defined with `WithTerminal`. -/ @[simps] def pseudofunctor : Pseudofunctor Cat Cat where toPrelaxFunctor := prelaxfunctor mapId C := mapId C mapComp := mapComp map₂_whisker_left := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerLeft_app, mapComp_hom_app, Iso.refl_hom, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp] · rfl map₂_whisker_right := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerRight_app, mapComp_hom_app, Iso.refl_hom, map_map, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp] rfl · rfl map₂_associator := by intros dsimp apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app] simp only [map_obj, Cat.comp_obj, Bicategory.Strict.associator_eqToIso, eqToIso_refl, Iso.refl_hom, map₂_app, mapComp_hom_app, Cat.whiskerRight_app, map_map, down_id, Functor.map_id, Cat.whiskerLeft_app, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp] rw [NatTrans.id_app, NatTrans.id_app] simp only [Cat.comp_obj, map_obj, Category.comp_id] · rfl map₂_left_unitor := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, Bicategory.Strict.leftUnitor_eqToIso, eqToIso_refl, Iso.refl_hom, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerRight_app, mapId_hom_app, map_map, Category.id_comp] rw [NatTrans.id_app, NatTrans.id_app] simp only [Cat.comp_obj, map_obj, Category.comp_id] rw [← Functor.map_id] rfl · rfl map₂_right_unitor := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, Bicategory.Strict.rightUnitor_eqToIso, eqToIso_refl, Iso.refl_hom, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerLeft_app, mapId_hom_app, Category.id_comp] rw [NatTrans.id_app, NatTrans.id_app] simp only [Cat.comp_obj, map_obj, Category.comp_id] rw [← Functor.map_id] rfl · rfl instance {X : WithTerminal C} : Unique (X ⟶ star) where default := match X with | of _ => PUnit.unit | star => PUnit.unit uniq := by cat_disch /-- `WithTerminal.star` is terminal. -/ def starTerminal : Limits.IsTerminal (star : WithTerminal C) := Limits.IsTerminal.ofUnique _ instance : Limits.HasTerminal (WithTerminal C) := Limits.hasTerminal_of_unique star /-- The isomorphism between star and an abstract terminal object of `WithTerminal C` -/ @[simps!] noncomputable def starIsoTerminal : star ≅ ⊤_ (WithTerminal C) := starTerminal.uniqueUpToIso (Limits.terminalIsTerminal) /-- Lift a functor `F : C ⥤ D` to `WithTerminal C ⥤ D`. -/ @[simps] def lift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z) (hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) : WithTerminal C ⥤ D where obj X := match X with | of x => F.obj x | star => Z map {X Y} f := match X, Y, f with | of _, of _, f => F.map (down f) | of x, star, _ => M x | star, star, _ => 𝟙 Z /-- The isomorphism between `incl ⋙ lift F _ _` with `F`. -/ @[simps!] def inclLift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z) (hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) : incl ⋙ lift F M hM ≅ F where hom := { app := fun _ => 𝟙 _ } inv := { app := fun _ => 𝟙 _ } /-- The isomorphism between `(lift F _ _).obj WithTerminal.star` with `Z`. -/ @[simps!] def liftStar {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z) (hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) : (lift F M hM).obj star ≅ Z := eqToIso rfl theorem lift_map_liftStar {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z) (hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) (x : C) : (lift F M hM).map (starTerminal.from (incl.obj x)) ≫ (liftStar F M hM).hom = (inclLift F M hM).hom.app x ≫ M x := by simp rfl /-- The uniqueness of `lift`. -/ @[simp] def liftUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z) (hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) (G : WithTerminal C ⥤ D) (h : incl ⋙ G ≅ F) (hG : G.obj star ≅ Z) (hh : ∀ x : C, G.map (starTerminal.from (incl.obj x)) ≫ hG.hom = h.hom.app x ≫ M x) : G ≅ lift F M hM := NatIso.ofComponents (fun X => match X with | of x => h.app x | star => hG) (by rintro (X | X) (Y | Y) f · apply h.hom.naturality · cases f exact hh _ · cases f · cases f change G.map (𝟙 _) ≫ hG.hom = hG.hom ≫ 𝟙 _ simp) /-- A variant of `lift` with `Z` a terminal object. -/ @[simps!] def liftToTerminal {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsTerminal Z) : WithTerminal C ⥤ D := lift F (fun _x => hZ.from _) fun _x _y _f => hZ.hom_ext _ _ /-- A variant of `incl_lift` with `Z` a terminal object. -/ @[simps!] def inclLiftToTerminal {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsTerminal Z) : incl ⋙ liftToTerminal F hZ ≅ F := inclLift _ _ _ /-- A variant of `lift_unique` with `Z` a terminal object. -/ @[simps!] def liftToTerminalUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsTerminal Z) (G : WithTerminal C ⥤ D) (h : incl ⋙ G ≅ F) (hG : G.obj star ≅ Z) : G ≅ liftToTerminal F hZ := liftUnique F (fun _z => hZ.from _) (fun _x _y _f => hZ.hom_ext _ _) G h hG fun _x => hZ.hom_ext _ _ /-- Constructs a morphism to `star` from `of X`. -/ @[simp] def homFrom (X : C) : incl.obj X ⟶ star := starTerminal.from _ instance isIso_of_from_star {X : WithTerminal C} (f : star ⟶ X) : IsIso f := match X with | of _X => f.elim | star => ⟨f, rfl, rfl⟩ section variable {D : Type*} [Category D] /-- A functor `WithTerminal C ⥤ D` can be seen as an element of the comma category `Comma (𝟭 (C ⥤ D)) (const C)`. -/ @[simps!] def mkCommaObject (F : WithTerminal C ⥤ D) : Comma (𝟭 (C ⥤ D)) (Functor.const C) where right := F.obj .star left := (incl ⋙ F) hom := { app x := F.map (starTerminal.from (.of x)) naturality x y f := by dsimp rw [Category.comp_id, ← F.map_comp] congr 1} /-- A morphism of functors `WithTerminal C ⥤ D` gives a morphism between the associated comma objects. -/ @[simps!] def mkCommaMorphism {F G : WithTerminal C ⥤ D} (η : F ⟶ G) : mkCommaObject F ⟶ mkCommaObject G where right := η.app .star left := Functor.whiskerLeft incl η /-- An element of the comma category `Comma (𝟭 (C ⥤ D)) (Functor.const C)` can be seen as a functor `WithTerminal C ⥤ D`. -/ @[simps!] def ofCommaObject (c : Comma (𝟭 (C ⥤ D)) (Functor.const C)) : WithTerminal C ⥤ D := lift (Z := c.right) c.left (fun x ↦ c.hom.app x) (fun x y f ↦ by simp) /-- A morphism in `Comma (𝟭 (C ⥤ D)) (Functor.const C)` gives a morphism between the associated functors `WithTerminal C ⥤ D`. -/ @[simps!] def ofCommaMorphism {c c' : Comma (𝟭 (C ⥤ D)) (Functor.const C)} (φ : c ⟶ c') : ofCommaObject c ⟶ ofCommaObject c' where app x := match x with | of x => φ.left.app x | star => φ.right naturality x y f := match x, y, f with | of _, of _, f => by simp | of a, star, _ => by simp; simpa [-CommaMorphism.w] using (congrArg (fun f ↦ f.app a) φ.w).symm | star, star, _ => by simp /-- The category of functors `WithTerminal C ⥤ D` is equivalent to the category `Comma (𝟭 (C ⥤ D)) (const C) `. -/ @[simps!] def equivComma : (WithTerminal C ⥤ D) ≌ Comma (𝟭 (C ⥤ D)) (Functor.const C) where functor := { obj := mkCommaObject map := mkCommaMorphism } inverse := { obj := ofCommaObject map := ofCommaMorphism } unitIso := NatIso.ofComponents (fun F ↦ liftUnique (incl ⋙ F) (fun x ↦ F.map (starTerminal.from (of x))) (fun x y f ↦ by simp only [Functor.comp_obj, Functor.comp_map] rw [← F.map_comp] congr 1) F (Iso.refl _) (Iso.refl _) (fun x ↦ by simp only [Iso.refl_hom, Category.id_comp, Functor.comp_obj, NatTrans.id_app, Category.comp_id]; rfl)) (fun {x y} f ↦ by ext t; cases t <;> simp [incl]) counitIso := NatIso.ofComponents (fun F ↦ Iso.refl _) functor_unitIso_comp x := by simp only [Functor.id_obj, Functor.comp_obj, liftUnique, lift_obj, NatIso.ofComponents_hom_app, Iso.refl_hom, Category.comp_id] ext <;> rfl end open CategoryTheory.Limits CategoryTheory.Limits.WidePullbackShape instance subsingleton_hom {J : Type*} : Quiver.IsThin (WithTerminal (Discrete J)) := fun _ _ => by constructor intro a b casesm* WithTerminal _, (_ : WithTerminal _) ⟶ (_ : WithTerminal _) · exact congr_arg (ULift.up ∘ PLift.up) rfl · rfl · rfl /-- Implementation detail for `widePullbackShapeEquiv`. -/ @[simps apply] private def widePullbackShapeEquivObj {J : Type*} : WidePullbackShape J ≃ WithTerminal (Discrete J) where toFun | .some x => .of <| .mk x | .none => .star invFun | .of x => .some <| Discrete.as x | .star => .none left_inv x := by cases x <;> simp right_inv x := by cases x <;> simp /-- Implementation detail for `widePullbackShapeEquiv`. -/ private def widePullbackShapeEquivMap {J : Type*} (x y : WidePullbackShape J) : (x ⟶ y) ≃ (widePullbackShapeEquivObj x ⟶ widePullbackShapeEquivObj y) where toFun | .term _ => PUnit.unit | .id _ => 𝟙 _ invFun f := match x, y with | some x, some y => cast (by have eq : x = y := PLift.down (ULift.down (down f)) rw [eq] rfl ) (Hom.id (some y)) | none, some y => by cases f | some x, none => .term x | none, none => .id none left_inv f := by apply Subsingleton.allEq right_inv f := match x, y with | some x, some y => Subsingleton.allEq _ _ | none, some y => by cases f | some x, none | none, none => rfl /-- In the case of a discrete category, `WithTerminal` is the same category as `WidePullbackShape` TODO: Should we simply replace `WidePullbackShape J` with `WithTerminal (Discrete J)` everywhere? -/ @[simps! functor_obj inverse_obj] def widePullbackShapeEquiv {J : Type*} : WidePullbackShape J ≌ WithTerminal (Discrete J) where functor.obj := widePullbackShapeEquivObj functor.map := widePullbackShapeEquivMap _ _ inverse.obj := widePullbackShapeEquivObj.symm inverse.map f := (widePullbackShapeEquivMap _ _).symm (eqToHom (by simp) ≫ f ≫ eqToHom (by simp)) unitIso := NatIso.ofComponents fun x ↦ eqToIso (by aesop) counitIso := NatIso.ofComponents fun x ↦ eqToIso (by aesop) end WithTerminal namespace WithInitial variable {C} /-- Morphisms for `WithInitial C`. -/ @[simp] def Hom : WithInitial C → WithInitial C → Type v | of X, of Y => X ⟶ Y | of _, _ => PEmpty | star, _ => PUnit attribute [nolint simpNF] Hom.eq_2 /-- Identity morphisms for `WithInitial C`. -/ @[simp] def id : ∀ X : WithInitial C, Hom X X | of _ => 𝟙 _ | star => PUnit.unit /-- Composition of morphisms for `WithInitial C`. -/ @[simp] def comp : ∀ {X Y Z : WithInitial C}, Hom X Y → Hom Y Z → Hom X Z | of _X, of _Y, of _Z => fun f g => f ≫ g | star, _, of _X => fun _f _g => PUnit.unit | _, of _X, star => fun _f g => PEmpty.elim g | of _Y, star, _ => fun f _g => PEmpty.elim f | star, star, star => fun _ _ => PUnit.unit attribute [nolint simpNF] comp.eq_3 @[aesop safe destruct (rule_sets := [CategoryTheory])] lemma false_of_to_star' {X : C} (f : Hom (of X) star) : False := (f : PEmpty).elim instance : Category.{v} (WithInitial C) where Hom X Y := Hom X Y id X := id X comp f g := comp f g /-- Helper function for typechecking. -/ def down {X Y : C} (f : of X ⟶ of Y) : X ⟶ Y := f @[simp] lemma down_id {X : C} : down (𝟙 (of X)) = 𝟙 X := rfl @[simp] lemma down_comp {X Y Z : C} (f : of X ⟶ of Y) (g : of Y ⟶ of Z) : down (f ≫ g) = down f ≫ down g := rfl @[aesop safe destruct (rule_sets := [CategoryTheory])] lemma false_of_to_star {X : C} (f : of X ⟶ star) : False := (f : PEmpty).elim /-- The inclusion of `C` into `WithInitial C`. -/ def incl : C ⥤ WithInitial C where obj := of map f := f instance : (incl : C ⥤ _).Full where map_surjective f := ⟨f, rfl⟩ instance : (incl : C ⥤ _).Faithful where /-- Map `WithInitial` with respect to a functor `F : C ⥤ D`. -/ @[simps] def map {D : Type*} [Category D] (F : C ⥤ D) : WithInitial C ⥤ WithInitial D where obj X := match X with | of x => of <| F.obj x | star => star map {X Y} f := match X, Y, f with | of _, of _, f => F.map (down f) | star, of _, _ => PUnit.unit | star, star, _ => PUnit.unit /-- A natural isomorphism between the functor `map (𝟭 C)` and `𝟭 (WithInitial C)`. -/ @[simps!] def mapId (C : Type*) [Category C] : map (𝟭 C) ≅ 𝟭 (WithInitial C) := NatIso.ofComponents (fun X => match X with | of _ => Iso.refl _ | star => Iso.refl _) (by cat_disch) /-- A natural isomorphism between the functor `map (F ⋙ G) ` and `map F ⋙ map G `. -/ @[simps!] def mapComp {D E : Type*} [Category D] [Category E] (F : C ⥤ D) (G : D ⥤ E) : map (F ⋙ G) ≅ map F ⋙ map G := NatIso.ofComponents (fun X => match X with | of _ => Iso.refl _ | star => Iso.refl _) (by cat_disch) /-- From a natural transformation of functors `C ⥤ D`, the induced natural transformation of functors `WithInitial C ⥤ WithInitial D`. -/ @[simps] def map₂ {D : Type*} [Category D] {F G : C ⥤ D} (η : F ⟶ G) : map F ⟶ map G where app := fun X => match X with | of x => η.app x | star => 𝟙 star naturality := by intro X Y f match X, Y, f with | of x, of y, f => exact η.naturality f | star, of x, _ => rfl | star, star, _ => rfl /-- The prelax functor from `Cat` to `Cat` defined with `WithInitial`. -/ @[simps] def prelaxfunctor : PrelaxFunctor Cat Cat where obj C := Cat.of (WithInitial C) map := map map₂ := map₂ map₂_id := by intros apply NatTrans.ext funext X cases X <;> rfl map₂_comp := by intros apply NatTrans.ext funext X cases X <;> rfl /-- The pseudofunctor from `Cat` to `Cat` defined with `WithInitial`. -/ @[simps] def pseudofunctor : Pseudofunctor Cat Cat where toPrelaxFunctor := prelaxfunctor mapId C := mapId C mapComp := mapComp map₂_whisker_left := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerLeft_app, mapComp_hom_app, Iso.refl_hom, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp] · rfl map₂_whisker_right := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerRight_app, mapComp_hom_app, Iso.refl_hom, map_map, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp] rfl · rfl map₂_associator := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, Bicategory.Strict.associator_eqToIso, eqToIso_refl, Iso.refl_hom, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerRight_app, map_map, down_id, Functor.map_id, Cat.whiskerLeft_app, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp] rw [NatTrans.id_app, NatTrans.id_app] simp only [Cat.comp_obj, map_obj, Category.comp_id] · rfl map₂_left_unitor := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, Bicategory.Strict.leftUnitor_eqToIso, eqToIso_refl, Iso.refl_hom, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerRight_app, mapId_hom_app, map_map, Category.id_comp] rw [NatTrans.id_app, NatTrans.id_app] simp only [Cat.comp_obj, map_obj, Category.comp_id] rw [← Functor.map_id] rfl · rfl map₂_right_unitor := by intros apply NatTrans.ext funext X cases X · rw [NatTrans.comp_app, NatTrans.comp_app] simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj, prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj, Bicategory.Strict.rightUnitor_eqToIso, eqToIso_refl, Iso.refl_hom, prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerLeft_app, mapId_hom_app, Category.id_comp] rw [NatTrans.id_app, NatTrans.id_app] simp only [Cat.comp_obj, map_obj, Category.comp_id] rw [← Functor.map_id, Cat.id_map] rfl · rfl instance {X : WithInitial C} : Unique (star ⟶ X) where default := match X with | of _x => PUnit.unit | star => PUnit.unit uniq := by cat_disch /-- `WithInitial.star` is initial. -/ def starInitial : Limits.IsInitial (star : WithInitial C) := Limits.IsInitial.ofUnique _ instance : Limits.HasInitial (WithInitial C) := Limits.hasInitial_of_unique star /-- The isomorphism between star and an abstract initial object of `WithInitial C` -/ @[simps!] noncomputable def starIsoInitial : star ≅ ⊥_ (WithInitial C) := starInitial.uniqueUpToIso (Limits.initialIsInitial) /-- Lift a functor `F : C ⥤ D` to `WithInitial C ⥤ D`. -/ @[simps] def lift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x) (hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) : WithInitial C ⥤ D where obj X := match X with | of x => F.obj x | star => Z map {X Y} f := match X, Y, f with | of _, of _, f => F.map (down f) | star, of _, _ => M _ | star, star, _ => 𝟙 _ /-- The isomorphism between `incl ⋙ lift F _ _` with `F`. -/ @[simps!] def inclLift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x) (hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) : incl ⋙ lift F M hM ≅ F where hom := { app := fun _ => 𝟙 _ } inv := { app := fun _ => 𝟙 _ } /-- The isomorphism between `(lift F _ _).obj WithInitial.star` with `Z`. -/ @[simps!] def liftStar {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x) (hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) : (lift F M hM).obj star ≅ Z := eqToIso rfl theorem liftStar_lift_map {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x) (hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) (x : C) : (liftStar F M hM).hom ≫ (lift F M hM).map (starInitial.to (incl.obj x)) = M x ≫ (inclLift F M hM).hom.app x := by erw [Category.id_comp, Category.comp_id] rfl /-- The uniqueness of `lift`. -/ @[simp] def liftUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x) (hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) (G : WithInitial C ⥤ D) (h : incl ⋙ G ≅ F) (hG : G.obj star ≅ Z) (hh : ∀ x : C, hG.symm.hom ≫ G.map (starInitial.to (incl.obj x)) = M x ≫ h.symm.hom.app x) : G ≅ lift F M hM := NatIso.ofComponents (fun X => match X with | of x => h.app x | star => hG) (by rintro (X | X) (Y | Y) f · apply h.hom.naturality · cases f · cases f change G.map _ ≫ h.hom.app _ = hG.hom ≫ _ symm erw [← Iso.eq_inv_comp, ← Category.assoc, hh] simp · cases f change G.map (𝟙 _) ≫ hG.hom = hG.hom ≫ 𝟙 _ simp) /-- A variant of `lift` with `Z` an initial object. -/ @[simps!] def liftToInitial {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsInitial Z) : WithInitial C ⥤ D := lift F (fun _x => hZ.to _) fun _x _y _f => hZ.hom_ext _ _ /-- A variant of `incl_lift` with `Z` an initial object. -/ @[simps!] def inclLiftToInitial {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsInitial Z) : incl ⋙ liftToInitial F hZ ≅ F := inclLift _ _ _ /-- A variant of `lift_unique` with `Z` an initial object. -/ @[simps!] def liftToInitialUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsInitial Z) (G : WithInitial C ⥤ D) (h : incl ⋙ G ≅ F) (hG : G.obj star ≅ Z) : G ≅ liftToInitial F hZ := liftUnique F (fun _z => hZ.to _) (fun _x _y _f => hZ.hom_ext _ _) G h hG fun _x => hZ.hom_ext _ _ /-- Constructs a morphism from `star` to `of X`. -/ @[simp] def homTo (X : C) : star ⟶ incl.obj X := starInitial.to _ instance isIso_of_to_star {X : WithInitial C} (f : X ⟶ star) : IsIso f := match X with | of _ => f.elim | star => ⟨f, rfl, rfl⟩ section variable {D : Type*} [Category D] /-- A functor `WithInitial C ⥤ D` can be seen as an element of the comma category `Comma (const C) (𝟭 (C ⥤ D))`. -/ @[simps!] def mkCommaObject (F : WithInitial C ⥤ D) : Comma (Functor.const C) (𝟭 (C ⥤ D)) where left := F.obj .star right := (incl ⋙ F) hom := { app x := F.map (starInitial.to (.of x)) naturality x y f := by dsimp rw [Category.id_comp, ← F.map_comp] congr 1} /-- A morphism of functors `WithInitial C ⥤ D` gives a morphism between the associated comma objects. -/ @[simps!] def mkCommaMorphism {F G : WithInitial C ⥤ D} (η : F ⟶ G) : mkCommaObject F ⟶ mkCommaObject G where left := η.app .star right := Functor.whiskerLeft incl η /-- An element of the comma category `Comma (Functor.const C) (𝟭 (C ⥤ D))` can be seen as a functor `WithInitial C ⥤ D`. -/ @[simps!] def ofCommaObject (c : Comma (Functor.const C) (𝟭 (C ⥤ D))) : WithInitial C ⥤ D := lift (Z := c.left) c.right (fun x ↦ c.hom.app x) (fun x y f ↦ by simpa using (c.hom.naturality f).symm) /-- A morphism in `Comma (Functor.const C) (𝟭 (C ⥤ D))` gives a morphism between the associated functors `WithInitial C ⥤ D`. -/ @[simps!] def ofCommaMorphism {c c' : Comma (Functor.const C) (𝟭 (C ⥤ D))} (φ : c ⟶ c') : ofCommaObject c ⟶ ofCommaObject c' where app x := match x with | of x => φ.right.app x | star => φ.left naturality x y f := match x, y, f with | of _, of _, f => by simp | star, of a, _ => by simpa [-CommaMorphism.w] using (congrArg (fun f ↦ f.app a) φ.w).symm | star, star, _ => by simp /-- The category of functors `WithInitial C ⥤ D` is equivalent to the category `Comma (const C) (𝟭 (C ⥤ D))`. -/ @[simps!] def equivComma : (WithInitial C ⥤ D) ≌ Comma (Functor.const C) (𝟭 (C ⥤ D)) where functor := { obj := mkCommaObject map := mkCommaMorphism } inverse := { obj := ofCommaObject map := ofCommaMorphism } unitIso := NatIso.ofComponents (fun F ↦ liftUnique (incl ⋙ F) (fun x ↦ F.map (starInitial.to (of x))) (fun x y f ↦ by simp only [Functor.comp_obj, Functor.comp_map] rw [← F.map_comp] congr 1) F (Iso.refl _) (Iso.refl _) (fun x ↦ by simp only [Iso.refl_symm, Iso.refl_hom, Category.id_comp, Functor.comp_obj, NatTrans.id_app, Category.comp_id]; rfl)) (fun {x y} f ↦ by ext t; cases t <;> simp [incl]) counitIso := NatIso.ofComponents (fun F ↦ Iso.refl _) functor_unitIso_comp x := by simp only [Functor.id_obj, Functor.comp_obj, liftUnique, lift_obj, NatIso.ofComponents_hom_app, Iso.refl_hom, Category.comp_id] ext <;> rfl end end WithInitial open Opposite in /-- The opposite category of `WithTerminal C` is equivalent to `WithInitial Cᵒᵖ`. -/ @[simps!] def WithTerminal.opEquiv : (WithTerminal C)ᵒᵖ ≌ WithInitial Cᵒᵖ where functor := { obj := fun ⟨x⟩ ↦ match x with | of x => .of <| op x | star => .star map := fun {x y} ⟨f⟩ ↦ match x, y, f with | op (of x), op (of y), f => (WithTerminal.down f).op | op star, op (of _), _ => WithInitial.starInitial.to _ | op star, op star, _ => 𝟙 _ map_id := fun ⟨x⟩ ↦ by cases x <;> rfl map_comp := fun {x y z} ⟨f⟩ ⟨g⟩ ↦ match x, y, z, f, g with | op (of x), op (of y), op (of z), f, g => rfl | _, op (of y), op star, f, g => (g : PEmpty).elim | op (of x), op star, _, f, _ => (f : PEmpty).elim | op star, _, _, f, g => rfl } inverse := { obj := fun x ↦ match x with | .of x => op <| .of <| x.unop | .star => op .star map := fun {x y} f ↦ match x, y, f with | .of (op x), .of (op y), f => WithInitial.down f | .star, .of (op _), _ => op <| WithTerminal.starTerminal.from _ | .star, .star, _ => 𝟙 _ map_id := fun x ↦ by cases x <;> rfl map_comp := fun {x y z} f g ↦ match x, y, z, f, g with | .of (op x), .of (op y), .of (op z), f, g => rfl | _, .of (op y), .star, f, g => (g : PEmpty).elim | .of (op x), .star, _, f, _ => (f : PEmpty).elim | .star, _, _, f, g => by subsingleton } unitIso := NatIso.ofComponents (fun ⟨x⟩ ↦ match x with | .of x => Iso.refl _ | .star => Iso.refl _) (fun {x y} ⟨f⟩ ↦ match x, y, f with | op (of x), op (of y), f => by simp only [Functor.id_obj, Functor.comp_obj, Functor.id_map, Iso.refl_hom, Category.comp_id, Functor.comp_map, Category.id_comp] rfl | op star, op (of _), _ => rfl | op star, op star, _ => rfl) counitIso := NatIso.ofComponents (fun x ↦ match x with | .of x => Iso.refl _ | .star => Iso.refl _) functor_unitIso_comp := fun ⟨x⟩ ↦ match x with | .of x => by simp only [op_unop, Functor.id_obj, Functor.comp_obj, NatIso.ofComponents_hom_app, Iso.refl_hom, Category.comp_id] rfl | .star => rfl open Opposite in /-- The opposite category of `WithInitial C` is equivalent to `WithTerminal Cᵒᵖ`. -/ @[simps!] def WithInitial.opEquiv : (WithInitial C)ᵒᵖ ≌ WithTerminal Cᵒᵖ where functor := { obj := fun ⟨x⟩ ↦ match x with | of x => .of <| op x | star => .star map := fun {x y} ⟨f⟩ ↦ match x, y, f with | op (of x), op (of y), f => (WithTerminal.down f).op | op (of _), op star, _ => WithTerminal.starTerminal.from _ | op star, op star, _ => 𝟙 _ map_id := fun ⟨x⟩ ↦ by cases x <;> rfl map_comp := fun {x y z} ⟨f⟩ ⟨g⟩ ↦ match x, y, z, f, g with | op (of x), op (of y), op (of z), f, g => rfl | _, op star, op (of y), f, g => (g : PEmpty).elim | op star, op (of x), _, f, _ => (f : PEmpty).elim | _, _, op star, f, g => by subsingleton } inverse := { obj := fun x ↦ match x with | .of x => op <| .of <| x.unop | .star => op .star map := fun {x y} f ↦ match x, y, f with | .of (op x), .of (op y), f => WithInitial.down f | .of (op _), .star, _ => op <| WithInitial.starInitial.to _ | .star, .star, _ => 𝟙 _ map_id := fun x ↦ by cases x <;> rfl map_comp := fun {x y z} f g ↦ match x, y, z, f, g with | .of (op x), .of (op y), .of (op z), f, g => rfl | _, .star, .of (op y), f, g => (g : PEmpty).elim | .star, .of (op x), _, f, _ => (f : PEmpty).elim | _, _, .star, f, g => by rfl } unitIso := NatIso.ofComponents (fun ⟨x⟩ ↦ match x with | .of x => Iso.refl _ | .star => Iso.refl _) (fun {x y} f ↦ match x, y, f with | op (of x), op (of y), f => by simp only [Functor.id_obj, Functor.comp_obj, Functor.id_map, Iso.refl_hom, Category.comp_id, Functor.comp_map, Category.id_comp] rfl | op (of _), op star, _ => rfl | _, op star, _ => rfl) counitIso := NatIso.ofComponents (fun x ↦ match x with | .of x => Iso.refl _ | .star => Iso.refl _) functor_unitIso_comp := fun ⟨x⟩ ↦ match x with | .of x => by simp only [op_unop, Functor.id_obj, Functor.comp_obj, NatIso.ofComponents_hom_app, Iso.refl_hom, Category.comp_id] rfl | .star => rfl end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/WithTerminal/FinCategory.lean
import Mathlib.CategoryTheory.FinCategory.Basic import Mathlib.CategoryTheory.WithTerminal.Basic import Mathlib.Data.Fintype.Option /-! # `WithTerminal C` and `WithInitial C` are finite whenever `C` is If `C` has finitely many objects, then so do `WithTerminal C` and `WithInitial C`, and likewise if `C` has finitely many morphisms as well. -/ universe v u variable (C : Type u) [CategoryTheory.Category.{v} C] namespace CategoryTheory.WithTerminal /-- The equivalence between `Option C` and `WithTerminal C` (they are both the type `C` plus an extra object `none` or `star`). -/ def optionEquiv : Option C ≃ WithTerminal C where toFun | some a => of a | none => star invFun | of a => some a | star => none left_inv a := by cases a <;> simp right_inv a := by cases a <;> simp instance instFintype [Fintype C] : Fintype (WithTerminal C) := .ofEquiv (Option C) <| optionEquiv C instance instFinCategory [SmallCategory C] [FinCategory C] : FinCategory (WithTerminal C) where fintypeObj := inferInstance fintypeHom | star, star | of _, star => (inferInstance : Fintype PUnit) | star, of _ => (inferInstance : Fintype PEmpty) | of a, of b => (inferInstance : Fintype (a ⟶ b)) end CategoryTheory.WithTerminal namespace CategoryTheory.WithInitial /-- The equivalence between `Option C` and `WithInitial C` (they are both the type `C` plus an extra object `none` or `star`). -/ def optionEquiv : Option C ≃ WithInitial C where toFun | some a => of a | none => star invFun | of a => some a | star => none left_inv a := by cases a <;> simp right_inv a := by cases a <;> simp instance instFintype [Fintype C] : Fintype (WithInitial C) := .ofEquiv (Option C) <| optionEquiv C instance instFinCategory [SmallCategory C] [FinCategory C] : FinCategory (WithInitial C) where fintypeObj := inferInstance fintypeHom | star, star | star, of _ => (inferInstance : Fintype PUnit) | of _, star => (inferInstance : Fintype PEmpty) | of a, of b => (inferInstance : Fintype (a ⟶ b)) end CategoryTheory.WithInitial
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/Flat.lean
import Mathlib.CategoryTheory.Filtered.CostructuredArrow import Mathlib.CategoryTheory.Functor.Flat /-! # Pulling back filteredness along representably flat functors We show that if `F : C ⥤ D` is a representably coflat functor between two categories, filteredness of `D` implies filteredness of `C`. Dually, if `F` is representably flat, cofilteredness of `D` implies cofilteredness of `C`. Transferring (co)filteredness *along* representably (co)flat functors is given by `IsFiltered.of_final` and its dual, since every representably flat functor is final and every representably coflat functor is initial. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (F : C ⥤ D) lemma isFiltered_of_representablyCoflat [IsFiltered D] [RepresentablyCoflat F] : IsFiltered C := isFiltered_of_isFiltered_costructuredArrow F (𝟭 _) lemma isCofiltered_of_representablyFlat [IsCofiltered D] [RepresentablyFlat F] : IsCofiltered C := by have := isFiltered_of_representablyCoflat F.op exact isCofiltered_of_isFiltered_op C end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/Final.lean
import Mathlib.CategoryTheory.Filtered.Connected import Mathlib.CategoryTheory.Limits.Final.Connected import Mathlib.CategoryTheory.Limits.Types.Filtered import Mathlib.CategoryTheory.Limits.Sifted /-! # Final functors with filtered (co)domain If `C` is a filtered category, then the usual equivalent conditions for a functor `F : C ⥤ D` to be final can be restated. We show: * `final_iff_of_isFiltered`: a concrete description of finality which is sometimes a convenient way to show that a functor is final. * `final_iff_isFiltered_structuredArrow`: `F` is final if and only if `StructuredArrow d F` is filtered for all `d : D`, which strengthens the usual statement that `F` is final if and only if `StructuredArrow d F` is connected for all `d : D`. * Under categories of objects of filtered categories are filtered and their forgetful functors are final. * If `D` is a filtered category and `F : C ⥤ D` is fully faithful and satisfies the additional condition that for every `d : D` there is an object `c : D` and a morphism `d ⟶ F.obj c`, then `C` is filtered and `F` is final. * Finality and initiality of diagonal functors `diag : C ⥤ C × C` and of projection functors of (co)structured arrow categories. * Finality of `StructuredArrow.post`, given the finality of its arguments. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Section 3.2 -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open CategoryTheory.Limits CategoryTheory.Functor Opposite variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) /-- If `StructuredArrow d F` is filtered for any `d : D`, then `F : C ⥤ D` is final. This is simply because filtered categories are connected. More profoundly, the converse is also true if `C` is filtered, see `final_iff_isFiltered_structuredArrow`. -/ theorem Functor.final_of_isFiltered_structuredArrow [∀ d, IsFiltered (StructuredArrow d F)] : Final F where out _ := IsFiltered.isConnected _ /-- If `CostructuredArrow F d` is filtered for any `d : D`, then `F : C ⥤ D` is initial. This is simply because cofiltered categories are connected. More profoundly, the converse is also true if `C` is cofiltered, see `initial_iff_isCofiltered_costructuredArrow`. -/ theorem Functor.initial_of_isCofiltered_costructuredArrow [∀ d, IsCofiltered (CostructuredArrow F d)] : Initial F where out _ := IsCofiltered.isConnected _ theorem isFiltered_structuredArrow_of_isFiltered_of_exists [IsFilteredOrEmpty C] (h₁ : ∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) (h₂ : ∀ {d : D} {c : C} (s s' : d ⟶ F.obj c), ∃ (c' : C) (t : c ⟶ c'), s ≫ F.map t = s' ≫ F.map t) (d : D) : IsFiltered (StructuredArrow d F) := by have : Nonempty (StructuredArrow d F) := by obtain ⟨c, ⟨f⟩⟩ := h₁ d exact ⟨.mk f⟩ suffices IsFilteredOrEmpty (StructuredArrow d F) from IsFiltered.mk refine ⟨fun f g => ?_, fun f g η μ => ?_⟩ · obtain ⟨c, ⟨t, ht⟩⟩ := h₂ (f.hom ≫ F.map (IsFiltered.leftToMax f.right g.right)) (g.hom ≫ F.map (IsFiltered.rightToMax f.right g.right)) refine ⟨.mk (f.hom ≫ F.map (IsFiltered.leftToMax f.right g.right ≫ t)), ?_, ?_, trivial⟩ · exact StructuredArrow.homMk (IsFiltered.leftToMax _ _ ≫ t) rfl · exact StructuredArrow.homMk (IsFiltered.rightToMax _ _ ≫ t) (by simpa using ht.symm) · refine ⟨.mk (f.hom ≫ F.map (η.right ≫ IsFiltered.coeqHom η.right μ.right)), StructuredArrow.homMk (IsFiltered.coeqHom η.right μ.right) (by simp), ?_⟩ simpa using IsFiltered.coeq_condition _ _ theorem isCofiltered_costructuredArrow_of_isCofiltered_of_exists [IsCofilteredOrEmpty C] (h₁ : ∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) (h₂ : ∀ {d : D} {c : C} (s s' : F.obj c ⟶ d), ∃ (c' : C) (t : c' ⟶ c), F.map t ≫ s = F.map t ≫ s') (d : D) : IsCofiltered (CostructuredArrow F d) := by suffices IsFiltered (CostructuredArrow F d)ᵒᵖ from isCofiltered_of_isFiltered_op _ suffices IsFiltered (StructuredArrow (op d) F.op) from IsFiltered.of_equivalence (costructuredArrowOpEquivalence _ _).symm apply isFiltered_structuredArrow_of_isFiltered_of_exists · intro d obtain ⟨c, ⟨t⟩⟩ := h₁ d.unop exact ⟨op c, ⟨Quiver.Hom.op t⟩⟩ · intro d c s s' obtain ⟨c', t, ht⟩ := h₂ s.unop s'.unop exact ⟨op c', Quiver.Hom.op t, Quiver.Hom.unop_inj ht⟩ /-- If `C` is filtered, then we can give an explicit condition for a functor `F : C ⥤ D` to be final. The converse is also true, see `final_iff_of_isFiltered`. -/ theorem Functor.final_of_exists_of_isFiltered [IsFilteredOrEmpty C] (h₁ : ∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) (h₂ : ∀ {d : D} {c : C} (s s' : d ⟶ F.obj c), ∃ (c' : C) (t : c ⟶ c'), s ≫ F.map t = s' ≫ F.map t) : Functor.Final F := by suffices ∀ d, IsFiltered (StructuredArrow d F) from final_of_isFiltered_structuredArrow F exact isFiltered_structuredArrow_of_isFiltered_of_exists F h₁ h₂ /-- The inclusion of a terminal object is final. -/ theorem Functor.final_const_of_isTerminal [IsFiltered C] {X : D} (hX : IsTerminal X) : ((Functor.const C).obj X).Final := Functor.final_of_exists_of_isFiltered _ (fun _ => ⟨IsFiltered.nonempty.some, ⟨hX.from _⟩⟩) (fun {_ c} _ _ => ⟨c, 𝟙 _, hX.hom_ext _ _⟩) /-- The inclusion of the terminal object is final. -/ theorem Functor.final_const_terminal [IsFiltered C] [HasTerminal D] : ((Functor.const C).obj (⊤_ D)).Final := Functor.final_const_of_isTerminal terminalIsTerminal /-- If `C` is cofiltered, then we can give an explicit condition for a functor `F : C ⥤ D` to be final. The converse is also true, see `initial_iff_of_isCofiltered`. -/ theorem Functor.initial_of_exists_of_isCofiltered [IsCofilteredOrEmpty C] (h₁ : ∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) (h₂ : ∀ {d : D} {c : C} (s s' : F.obj c ⟶ d), ∃ (c' : C) (t : c' ⟶ c), F.map t ≫ s = F.map t ≫ s') : Functor.Initial F := by suffices ∀ d, IsCofiltered (CostructuredArrow F d) from initial_of_isCofiltered_costructuredArrow F exact isCofiltered_costructuredArrow_of_isCofiltered_of_exists F h₁ h₂ /-- The inclusion of an initial object is initial. -/ theorem Functor.initial_const_of_isInitial [IsCofiltered C] {X : D} (hX : IsInitial X) : ((Functor.const C).obj X).Initial := Functor.initial_of_exists_of_isCofiltered _ (fun _ => ⟨IsCofiltered.nonempty.some, ⟨hX.to _⟩⟩) (fun {_ c} _ _ => ⟨c, 𝟙 _, hX.hom_ext _ _⟩) /-- The inclusion of the initial object is initial. -/ theorem Functor.initial_const_initial [IsCofiltered C] [HasInitial D] : ((Functor.const C).obj (⊥_ D)).Initial := Functor.initial_const_of_isInitial initialIsInitial /-- In this situation, `F` is also final, see `Functor.final_of_exists_of_isFiltered_of_fullyFaithful`. -/ theorem IsFilteredOrEmpty.of_exists_of_isFiltered_of_fullyFaithful [IsFilteredOrEmpty D] [F.Full] [F.Faithful] (h : ∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) : IsFilteredOrEmpty C where cocone_objs c c' := by obtain ⟨c₀, ⟨f⟩⟩ := h (IsFiltered.max (F.obj c) (F.obj c')) exact ⟨c₀, F.preimage (IsFiltered.leftToMax _ _ ≫ f), F.preimage (IsFiltered.rightToMax _ _ ≫ f), trivial⟩ cocone_maps {c c'} f g := by obtain ⟨c₀, ⟨f₀⟩⟩ := h (IsFiltered.coeq (F.map f) (F.map g)) refine ⟨_, F.preimage (IsFiltered.coeqHom (F.map f) (F.map g) ≫ f₀), F.map_injective ?_⟩ simp [reassoc_of% (IsFiltered.coeq_condition (F.map f) (F.map g))] /-- In this situation, `F` is also initial, see `Functor.initial_of_exists_of_isCofiltered_of_fullyFaithful`. -/ theorem IsCofilteredOrEmpty.of_exists_of_isCofiltered_of_fullyFaithful [IsCofilteredOrEmpty D] [F.Full] [F.Faithful] (h : ∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) : IsCofilteredOrEmpty C := by suffices IsFilteredOrEmpty Cᵒᵖ from isCofilteredOrEmpty_of_isFilteredOrEmpty_op _ refine IsFilteredOrEmpty.of_exists_of_isFiltered_of_fullyFaithful F.op (fun d => ?_) obtain ⟨c, ⟨f⟩⟩ := h d.unop exact ⟨op c, ⟨f.op⟩⟩ /-- In this situation, `F` is also final, see `Functor.final_of_exists_of_isFiltered_of_fullyFaithful`. -/ theorem IsFiltered.of_exists_of_isFiltered_of_fullyFaithful [IsFiltered D] [F.Full] [F.Faithful] (h : ∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) : IsFiltered C := { IsFilteredOrEmpty.of_exists_of_isFiltered_of_fullyFaithful F h with nonempty := by have : Nonempty D := IsFiltered.nonempty obtain ⟨c, -⟩ := h (Classical.arbitrary D) exact ⟨c⟩ } /-- In this situation, `F` is also initial, see `Functor.initial_of_exists_of_isCofiltered_of_fullyFaithful`. -/ theorem IsCofiltered.of_exists_of_isCofiltered_of_fullyFaithful [IsCofiltered D] [F.Full] [F.Faithful] (h : ∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) : IsCofiltered C := { IsCofilteredOrEmpty.of_exists_of_isCofiltered_of_fullyFaithful F h with nonempty := by have : Nonempty D := IsCofiltered.nonempty obtain ⟨c, -⟩ := h (Classical.arbitrary D) exact ⟨c⟩ } /-- In this situation, `C` is also filtered, see `IsFilteredOrEmpty.of_exists_of_isFiltered_of_fullyFaithful`. -/ theorem Functor.final_of_exists_of_isFiltered_of_fullyFaithful [IsFilteredOrEmpty D] [F.Full] [F.Faithful] (h : ∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) : Final F := by have := IsFilteredOrEmpty.of_exists_of_isFiltered_of_fullyFaithful F h refine Functor.final_of_exists_of_isFiltered F h (fun {d c} s s' => ?_) obtain ⟨c₀, ⟨f⟩⟩ := h (IsFiltered.coeq s s') refine ⟨c₀, F.preimage (IsFiltered.coeqHom s s' ≫ f), ?_⟩ simp [reassoc_of% (IsFiltered.coeq_condition s s')] /-- In this situation, `C` is also cofiltered, see `IsCofilteredOrEmpty.of_exists_of_isCofiltered_of_fullyFaithful`. -/ theorem Functor.initial_of_exists_of_isCofiltered_of_fullyFaithful [IsCofilteredOrEmpty D] [F.Full] [Faithful F] (h : ∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) : Initial F := by suffices Final F.op from initial_of_final_op _ refine Functor.final_of_exists_of_isFiltered_of_fullyFaithful F.op (fun d => ?_) obtain ⟨c, ⟨f⟩⟩ := h d.unop exact ⟨op c, ⟨f.op⟩⟩ /-- Any under category on a filtered or empty category is filtered. (Note that under categories are always cofiltered since they have an initial object.) -/ instance IsFiltered.under [IsFilteredOrEmpty C] (c : C) : IsFiltered (Under c) := isFiltered_structuredArrow_of_isFiltered_of_exists _ (fun c' => ⟨c', ⟨𝟙 _⟩⟩) (fun s s' => IsFilteredOrEmpty.cocone_maps s s') c /-- Any over category on a cofiltered or empty category is cofiltered. (Note that over categories are always filtered since they have a terminal object.) -/ instance IsCofiltered.over [IsCofilteredOrEmpty C] (c : C) : IsCofiltered (Over c) := isCofiltered_costructuredArrow_of_isCofiltered_of_exists _ (fun c' => ⟨c', ⟨𝟙 _⟩⟩) (fun s s' => IsCofilteredOrEmpty.cone_maps s s') c /-- The forgetful functor of the under category on any filtered or empty category is final. -/ instance Under.final_forget [IsFilteredOrEmpty C] (c : C) : Final (Under.forget c) := final_of_exists_of_isFiltered _ (fun c' => ⟨mk (IsFiltered.leftToMax c c'), ⟨IsFiltered.rightToMax c c'⟩⟩) (fun {_} {x} s s' => by use mk (x.hom ≫ IsFiltered.coeqHom s s') use homMk (IsFiltered.coeqHom s s') (by simp) simp only [forget_obj, id_obj, mk_right, forget_map, homMk_right] rw [IsFiltered.coeq_condition]) /-- The forgetful functor of the over category on any cofiltered or empty category is initial. -/ instance Over.initial_forget [IsCofilteredOrEmpty C] (c : C) : Initial (Over.forget c) := initial_of_exists_of_isCofiltered _ (fun c' => ⟨mk (IsCofiltered.minToLeft c c'), ⟨IsCofiltered.minToRight c c'⟩⟩) (fun {_} {x} s s' => by use mk (IsCofiltered.eqHom s s' ≫ x.hom) use homMk (IsCofiltered.eqHom s s') (by simp) simp only [forget_obj, mk_left, forget_map, homMk_left] rw [IsCofiltered.eq_condition]) section LocallySmall variable {C : Type v₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₁} D] (F : C ⥤ D) /-- Implementation; use `Functor.Final.exists_coeq instead`. -/ theorem Functor.Final.exists_coeq_of_locally_small [IsFilteredOrEmpty C] [Final F] {d : D} {c : C} (s s' : d ⟶ F.obj c) : ∃ (c' : C) (t : c ⟶ c'), s ≫ F.map t = s' ≫ F.map t := by have : colimit.ι (F ⋙ coyoneda.obj (op d)) c s = colimit.ι (F ⋙ coyoneda.obj (op d)) c s' := by apply (Final.colimitCompCoyonedaIso F d).toEquiv.injective subsingleton obtain ⟨c', t₁, t₂, h⟩ := (Types.FilteredColimit.colimit_eq_iff.{v₁, v₁, v₁} _).mp this refine ⟨IsFiltered.coeq t₁ t₂, t₁ ≫ IsFiltered.coeqHom t₁ t₂, ?_⟩ conv_rhs => rw [IsFiltered.coeq_condition t₁ t₂] dsimp only [comp_obj, flip_obj_obj, yoneda_obj_obj, comp_map, flip_obj_map, yoneda_map_app] at h simp [reassoc_of% h] end LocallySmall /-- If `C` is filtered, then we can give an explicit condition for a functor `F : C ⥤ D` to be final. -/ theorem Functor.final_iff_of_isFiltered [IsFilteredOrEmpty C] : Final F ↔ (∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) ∧ (∀ {d : D} {c : C} (s s' : d ⟶ F.obj c), ∃ (c' : C) (t : c ⟶ c'), s ≫ F.map t = s' ≫ F.map t) := by refine ⟨fun hF => ⟨?_, ?_⟩, fun h => final_of_exists_of_isFiltered F h.1 h.2⟩ · intro d obtain ⟨f⟩ : Nonempty (StructuredArrow d F) := IsConnected.is_nonempty exact ⟨_, ⟨f.hom⟩⟩ · let s₁ : C ≌ AsSmall.{max u₁ v₁ u₂ v₂} C := AsSmall.equiv let s₂ : D ≌ AsSmall.{max u₁ v₁ u₂ v₂} D := AsSmall.equiv have : IsFilteredOrEmpty (AsSmall.{max u₁ v₁ u₂ v₂} C) := .of_equivalence s₁ intro d c s s' obtain ⟨c', t, ht⟩ := Functor.Final.exists_coeq_of_locally_small (s₁.inverse ⋙ F ⋙ s₂.functor) (AsSmall.up.map s) (AsSmall.up.map s') exact ⟨AsSmall.down.obj c', AsSmall.down.map t, s₂.functor.map_injective (by simp_all [s₁, s₂])⟩ /-- If `C` is cofiltered, then we can give an explicit condition for a functor `F : C ⥤ D` to be initial. -/ theorem Functor.initial_iff_of_isCofiltered [IsCofilteredOrEmpty C] : Initial F ↔ (∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) ∧ (∀ {d : D} {c : C} (s s' : F.obj c ⟶ d), ∃ (c' : C) (t : c' ⟶ c), F.map t ≫ s = F.map t ≫ s') := by refine ⟨fun hF => ?_, fun h => initial_of_exists_of_isCofiltered F h.1 h.2⟩ obtain ⟨h₁, h₂⟩ := F.op.final_iff_of_isFiltered.mp inferInstance refine ⟨?_, ?_⟩ · intro d obtain ⟨c, ⟨t⟩⟩ := h₁ (op d) exact ⟨c.unop, ⟨t.unop⟩⟩ · intro d c s s' obtain ⟨c', t, ht⟩ := h₂ (Quiver.Hom.op s) (Quiver.Hom.op s') exact ⟨c'.unop, t.unop, Quiver.Hom.op_inj ht⟩ theorem Functor.Final.exists_coeq [IsFilteredOrEmpty C] [Final F] {d : D} {c : C} (s s' : d ⟶ F.obj c) : ∃ (c' : C) (t : c ⟶ c'), s ≫ F.map t = s' ≫ F.map t := ((final_iff_of_isFiltered F).1 inferInstance).2 s s' theorem Functor.Initial.exists_eq [IsCofilteredOrEmpty C] [Initial F] {d : D} {c : C} (s s' : F.obj c ⟶ d) : ∃ (c' : C) (t : c' ⟶ c), F.map t ≫ s = F.map t ≫ s' := ((initial_iff_of_isCofiltered F).1 inferInstance).2 s s' /-- If `C` is filtered, then `F : C ⥤ D` is final if and only if `StructuredArrow d F` is filtered for all `d : D`. -/ theorem Functor.final_iff_isFiltered_structuredArrow [IsFilteredOrEmpty C] : Final F ↔ ∀ d, IsFiltered (StructuredArrow d F) := by refine ⟨?_, fun h => final_of_isFiltered_structuredArrow F⟩ rw [final_iff_of_isFiltered] exact fun h => isFiltered_structuredArrow_of_isFiltered_of_exists F h.1 h.2 /-- If `C` is cofiltered, then `F : C ⥤ D` is initial if and only if `CostructuredArrow F d` is cofiltered for all `d : D`. -/ theorem Functor.initial_iff_isCofiltered_costructuredArrow [IsCofilteredOrEmpty C] : Initial F ↔ ∀ d, IsCofiltered (CostructuredArrow F d) := by refine ⟨?_, fun h => initial_of_isCofiltered_costructuredArrow F⟩ rw [initial_iff_of_isCofiltered] exact fun h => isCofiltered_costructuredArrow_of_isCofiltered_of_exists F h.1 h.2 /-- If `C` is filtered, then the structured arrow category on the diagonal functor `C ⥤ C × C` is filtered as well. -/ instance [IsFilteredOrEmpty C] (X : C × C) : IsFiltered (StructuredArrow X (diag C)) := by haveI : ∀ Y, IsFiltered (StructuredArrow Y (Under.forget X.1)) := by rw [← final_iff_isFiltered_structuredArrow (Under.forget X.1)] infer_instance apply IsFiltered.of_equivalence (StructuredArrow.ofDiagEquivalence X).symm /-- The diagonal functor on any filtered category is final. -/ instance Functor.final_diag_of_isFiltered [IsFilteredOrEmpty C] : Final (Functor.diag C) := final_of_isFiltered_structuredArrow _ -- Adding this instance causes performance problems elsewhere, even with low priority theorem IsFilteredOrEmpty.isSiftedOrEmpty [IsFilteredOrEmpty C] : IsSiftedOrEmpty C := Functor.final_diag_of_isFiltered -- Adding this instance causes performance problems elsewhere, even with low priority attribute [local instance] IsFiltered.nonempty in theorem IsFiltered.isSifted [IsFiltered C] : IsSifted C where /-- If `C` is cofiltered, then the costructured arrow category on the diagonal functor `C ⥤ C × C` is cofiltered as well. -/ instance [IsCofilteredOrEmpty C] (X : C × C) : IsCofiltered (CostructuredArrow (diag C) X) := by haveI : ∀ Y, IsCofiltered (CostructuredArrow (Over.forget X.1) Y) := by rw [← initial_iff_isCofiltered_costructuredArrow (Over.forget X.1)] infer_instance apply IsCofiltered.of_equivalence (CostructuredArrow.ofDiagEquivalence X).symm /-- The diagonal functor on any cofiltered category is initial. -/ instance Functor.initial_diag_of_isFiltered [IsCofilteredOrEmpty C] : Initial (Functor.diag C) := initial_of_isCofiltered_costructuredArrow _ /-- If `C` is filtered, then every functor `F : C ⥤ Discrete PUnit` is final. -/ theorem Functor.final_of_isFiltered_of_pUnit [IsFiltered C] (F : C ⥤ Discrete PUnit) : Final F := by refine final_of_exists_of_isFiltered F (fun _ => ?_) (fun {_} {c} _ _ => ?_) · use Classical.choice IsFiltered.nonempty exact ⟨Discrete.eqToHom (by simp)⟩ · use c; use 𝟙 c apply Subsingleton.elim /-- If `C` is cofiltered, then every functor `F : C ⥤ Discrete PUnit` is initial. -/ theorem Functor.initial_of_isCofiltered_pUnit [IsCofiltered C] (F : C ⥤ Discrete PUnit) : Initial F := by refine initial_of_exists_of_isCofiltered F (fun _ => ?_) (fun {_} {c} _ _ => ?_) · use Classical.choice IsCofiltered.nonempty exact ⟨Discrete.eqToHom (by simp)⟩ · use c; use 𝟙 c apply Subsingleton.elim /-- The functor `StructuredArrow.proj : StructuredArrow Y T ⥤ C` is final if `T : C ⥤ D` is final and `C` is filtered. -/ instance StructuredArrow.final_proj_of_isFiltered [IsFilteredOrEmpty C] (T : C ⥤ D) [Final T] (Y : D) : Final (StructuredArrow.proj Y T) := by refine ⟨fun X => ?_⟩ rw [isConnected_iff_of_equivalence (ofStructuredArrowProjEquivalence T Y X)] exact (final_comp (Under.forget X) T).out _ /-- The functor `CostructuredArrow.proj : CostructuredArrow Y T ⥤ C` is initial if `T : C ⥤ D` is initial and `C` is cofiltered. -/ instance CostructuredArrow.initial_proj_of_isCofiltered [IsCofilteredOrEmpty C] (T : C ⥤ D) [Initial T] (Y : D) : Initial (CostructuredArrow.proj T Y) := by refine ⟨fun X => ?_⟩ rw [isConnected_iff_of_equivalence (ofCostructuredArrowProjEquivalence T Y X)] exact (initial_comp (Over.forget X) T).out _ /-- The functor `StructuredArrow d T ⥤ StructuredArrow e (T ⋙ S)` that `u : e ⟶ S.obj d` induces via `StructuredArrow.map₂` is final, if `T` and `S` are final and the domain of `T` is filtered. -/ instance StructuredArrow.final_map₂_id [IsFiltered C] {E : Type u₃} [Category.{v₃} E] {T : C ⥤ D} [T.Final] {S : D ⥤ E} [S.Final] {T' : C ⥤ E} {d : D} {e : E} (u : e ⟶ S.obj d) (α : T ⋙ S ⟶ T') [IsIso α] : Final (map₂ (F := 𝟭 _) u α) := by haveI : IsFiltered (StructuredArrow e (T ⋙ S)) := (T ⋙ S).final_iff_isFiltered_structuredArrow.mp inferInstance e apply final_of_natIso (map₂IsoPreEquivalenceInverseCompProj d e u α).symm /-- `StructuredArrow.map` is final if the functor `T` is final and its domain is filtered. -/ instance StructuredArrow.final_map [IsFiltered C] {S S' : D} (f : S ⟶ S') (T : C ⥤ D) [T.Final] : Final (map (T := T) f) := by haveI := NatIso.isIso_of_isIso_app (𝟙 T) have : (map₂ (F := 𝟭 C) (G := 𝟭 D) f (𝟙 T)).Final := by apply StructuredArrow.final_map₂_id (S := 𝟭 D) (T := T) (T' := T) f (𝟙 T) apply final_of_natIso (mapIsoMap₂ f).symm /-- `StructuredArrow.post X T S` is final if `T` and `S` are final and the domain of `T` is filtered. -/ instance StructuredArrow.final_post [IsFiltered C] {E : Type u₃} [Category.{v₃} E] (X : D) (T : C ⥤ D) [T.Final] (S : D ⥤ E) [S.Final] : Final (post X T S) := by apply final_of_natIso (postIsoMap₂ X T S).symm /-- The functor `CostructuredArrow T d ⥤ CostructuredArrow (T ⋙ S) e` that `u : S.obj d ⟶ e` induces via `CostructuredArrow.map₂` is initial, if `T` and `S` are initial and the domain of `T` is filtered. -/ instance CostructuredArrow.initial_map₂_id [IsCofiltered C] {E : Type u₃} [Category.{v₃} E] (T : C ⥤ D) [T.Initial] (S : D ⥤ E) [S.Initial] (d : D) (e : E) (u : S.obj d ⟶ e) : Initial (map₂ (F := 𝟭 _) (U := T ⋙ S) (𝟙 (T ⋙ S)) u) := by have := (T ⋙ S).initial_iff_isCofiltered_costructuredArrow.mp inferInstance e apply initial_of_natIso (map₂IsoPreEquivalenceInverseCompProj T S d e u).symm /-- `CostructuredArrow.post T S X` is initial if `T` and `S` are initial and the domain of `T` is cofiltered. -/ instance CostructuredArrow.initial_post [IsCofiltered C] {E : Type u₃} [Category.{v₃} E] (X : D) (T : C ⥤ D) [T.Initial] (S : D ⥤ E) [S.Initial] : Initial (post T S X) := by apply initial_of_natIso (postIsoMap₂ X T S).symm section Pi variable {α : Type u₁} {I : α → Type u₂} [∀ s, Category.{v₂} (I s)] open IsFiltered in instance final_eval [∀ s, IsFiltered (I s)] (s : α) : (Pi.eval I s).Final := by classical apply Functor.final_of_exists_of_isFiltered · exact fun i => ⟨Function.update (fun t => nonempty.some) s i, ⟨by simpa using 𝟙 _⟩⟩ · intro d c f g let c't : (∀ s, (c' : I s) × (c s ⟶ c')) := Function.update (fun t => ⟨c t, 𝟙 (c t)⟩) s ⟨coeq f g, coeqHom f g⟩ refine ⟨fun t => (c't t).1, fun t => (c't t).2, ?_⟩ dsimp only [Pi.eval_obj, Pi.eval_map, c't] rw [Function.update_self] simpa using coeq_condition _ _ open IsCofiltered in instance initial_eval [∀ s, IsCofiltered (I s)] (s : α) : (Pi.eval I s).Initial := by classical apply Functor.initial_of_exists_of_isCofiltered · exact fun i => ⟨Function.update (fun t => nonempty.some) s i, ⟨by simpa using 𝟙 _⟩⟩ · intro d c f g let c't : (∀ s, (c' : I s) × (c' ⟶ c s)) := Function.update (fun t => ⟨c t, 𝟙 (c t)⟩) s ⟨eq f g, eqHom f g⟩ refine ⟨fun t => (c't t).1, fun t => (c't t).2, ?_⟩ dsimp only [Pi.eval_obj, Pi.eval_map, c't] rw [Function.update_self] simpa using eq_condition _ _ end Pi section Prod namespace IsFiltered attribute [local instance] IsFiltered.isConnected IsCofiltered.isConnected instance final_fst [IsFiltered D] : (Prod.fst C D).Final := inferInstance instance final_snd [IsFiltered C] : (Prod.snd C D).Final := inferInstance instance initial_fst [IsCofiltered D] : (Prod.fst C D).Initial := inferInstance instance initial_snd [IsCofiltered C] : (Prod.snd C D).Initial := inferInstance end IsFiltered end Prod end CategoryTheory open CategoryTheory lemma Monotone.final_functor_iff {J₁ J₂ : Type*} [Preorder J₁] [Preorder J₂] [IsDirected J₁ (· ≤ ·)] {f : J₁ → J₂} (hf : Monotone f) : hf.functor.Final ↔ ∀ (j₂ : J₂), ∃ (j₁ : J₁), j₂ ≤ f j₁ := by rw [Functor.final_iff_of_isFiltered] constructor · rintro ⟨h, _⟩ j₂ obtain ⟨j₁, ⟨φ⟩⟩ := h j₂ exact ⟨j₁, leOfHom φ⟩ · intro h constructor · intro j₂ obtain ⟨j₁, h₁⟩ := h j₂ exact ⟨j₁, ⟨homOfLE h₁⟩⟩ · intro _ c _ _ exact ⟨c, 𝟙 _, rfl⟩
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/OfColimitCommutesFiniteLimit.lean
import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Limits.Filtered import Mathlib.CategoryTheory.Limits.Yoneda /-! # If colimits of shape `K` commute with finite limits, then `K` is filtered. -/ universe v u namespace CategoryTheory variable {K : Type v} [SmallCategory K] open Limits /-- A converse to `colimitLimitIso`: if colimits of shape `K` commute with finite limits, then `K` is filtered. -/ theorem isFiltered_of_nonempty_limit_colimit_to_colimit_limit (h : ∀ {J : Type v} [SmallCategory J] [FinCategory J] (F : J ⥤ K ⥤ Type v), Nonempty (limit (colimit F.flip) ⟶ colimit (limit F))) : IsFiltered K := by refine IsFiltered.iff_nonempty_limit.2 (fun {J} _ _ F => ?_) suffices Nonempty (limit (colimit (F.op ⋙ coyoneda).flip)) by obtain ⟨X, y, -⟩ := Types.jointly_surjective' (this.map (h (F.op ⋙ coyoneda)).some).some exact ⟨X, ⟨(limitObjIsoLimitCompEvaluation (F.op ⋙ coyoneda) _).hom y⟩⟩ let _ (j : Jᵒᵖ) : Unique ((colimit (F.op ⋙ coyoneda).flip).obj j) := ((colimitObjIsoColimitCompEvaluation (F.op ⋙ coyoneda).flip _ ≪≫ Coyoneda.colimitCoyonedaIso _)).toEquiv.unique exact ⟨Types.Limit.mk (colimit (F.op ⋙ coyoneda).flip) (fun j => default) (by subsingleton)⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Filtered/Basic.lean
import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits /-! # Filtered categories A category is filtered if every finite diagram admits a cocone. We give a simple characterisation of this condition as 1. for every pair of objects there exists another object "to the right", 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal, and 3. there exists some object. Filtered colimits are often better behaved than arbitrary colimits. See `CategoryTheory/Limits/Types` for some details. Filtered categories are nice because colimits indexed by filtered categories tend to be easier to describe than general colimits (and more often preserved by functors). In this file we show that any functor from a finite category to a filtered category admits a cocone: * `cocone_nonempty [FinCategory J] [IsFiltered C] (F : J ⥤ C) : Nonempty (Cocone F)` More generally, for any finite collection of objects and morphisms between them in a filtered category (even if not closed under composition) there exists some object `Z` receiving maps from all of them, so that all the triangles (one edge from the finite set, two from morphisms to `Z`) commute. This formulation is often more useful in practice and is available via `sup_exists`, which takes a finset of objects, and an indexed family (indexed by source and target) of finsets of morphisms. We also prove the converse of `cocone_nonempty` as `of_cocone_nonempty`. Furthermore, we give special support for two diagram categories: The `bowtie` and the `tulip`. This is because these shapes show up in the proofs that forgetful functors of algebraic categories (e.g. `MonCat`, `CommRingCat`, ...) preserve filtered colimits. All of the above API, except for the `bowtie` and the `tulip`, is also provided for cofiltered categories. ## See also In `CategoryTheory.Limits.FilteredColimitCommutesFiniteLimit` we show that filtered colimits commute with finite limits. There is another characterization of filtered categories, namely that whenever `F : J ⥤ C` is a functor from a finite category, there is `X : C` such that `Nonempty (limit (F.op ⋙ yoneda.obj X))`. This is shown in `CategoryTheory.Limits.Filtered`. -/ open Function -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe w v v₁ v₂ u u₁ u₂ namespace CategoryTheory attribute [local instance] uliftCategory variable (C : Type u) [Category.{v} C] /-- A category `IsFilteredOrEmpty` if 1. for every pair of objects there exists another object "to the right", and 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal. -/ class IsFilteredOrEmpty : Prop where /-- for every pair of objects there exists another object "to the right" -/ cocone_objs : ∀ X Y : C, ∃ (Z : _) (_ : X ⟶ Z) (_ : Y ⟶ Z), True /-- for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal -/ cocone_maps : ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), ∃ (Z : _) (h : Y ⟶ Z), f ≫ h = g ≫ h /-- A category `IsFiltered` if 1. for every pair of objects there exists another object "to the right", 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal, and 3. there exists some object. -/ @[stacks 002V "They also define a diagram being filtered."] class IsFiltered : Prop extends IsFilteredOrEmpty C where /-- a filtered category must be non-empty -/ -- This should be an instance but it causes significant slowdown [nonempty : Nonempty C] instance (priority := 100) isFilteredOrEmpty_of_semilatticeSup (α : Type u) [SemilatticeSup α] : IsFilteredOrEmpty α where cocone_objs X Y := ⟨X ⊔ Y, homOfLE le_sup_left, homOfLE le_sup_right, trivial⟩ cocone_maps X Y f g := ⟨Y, 𝟙 _, by subsingleton⟩ instance (priority := 100) isFiltered_of_semilatticeSup_nonempty (α : Type u) [SemilatticeSup α] [Nonempty α] : IsFiltered α where instance (priority := 100) isFilteredOrEmpty_of_directed_le (α : Type u) [Preorder α] [IsDirected α (· ≤ ·)] : IsFilteredOrEmpty α where cocone_objs X Y := let ⟨Z, h1, h2⟩ := exists_ge_ge X Y ⟨Z, homOfLE h1, homOfLE h2, trivial⟩ cocone_maps X Y f g := ⟨Y, 𝟙 _, by subsingleton⟩ instance (priority := 100) isFiltered_of_directed_le_nonempty (α : Type u) [Preorder α] [IsDirected α (· ≤ ·)] [Nonempty α] : IsFiltered α where -- Sanity checks example (α : Type u) [SemilatticeSup α] [OrderBot α] : IsFiltered α := by infer_instance example (α : Type u) [SemilatticeSup α] [OrderTop α] : IsFiltered α := by infer_instance instance : IsFiltered (Discrete PUnit) where cocone_objs X Y := ⟨⟨PUnit.unit⟩, ⟨⟨by trivial⟩⟩, ⟨⟨by subsingleton⟩⟩, trivial⟩ cocone_maps X Y f g := ⟨⟨PUnit.unit⟩, ⟨⟨by trivial⟩⟩, by subsingleton⟩ namespace IsFiltered section AllowEmpty variable {C} variable [IsFilteredOrEmpty C] /-- `max j j'` is an arbitrary choice of object to the right of both `j` and `j'`, whose existence is ensured by `IsFiltered`. -/ noncomputable def max (j j' : C) : C := (IsFilteredOrEmpty.cocone_objs j j').choose /-- `leftToMax j j'` is an arbitrary choice of morphism from `j` to `max j j'`, whose existence is ensured by `IsFiltered`. -/ noncomputable def leftToMax (j j' : C) : j ⟶ max j j' := (IsFilteredOrEmpty.cocone_objs j j').choose_spec.choose /-- `rightToMax j j'` is an arbitrary choice of morphism from `j'` to `max j j'`, whose existence is ensured by `IsFiltered`. -/ noncomputable def rightToMax (j j' : C) : j' ⟶ max j j' := (IsFilteredOrEmpty.cocone_objs j j').choose_spec.choose_spec.choose /-- `coeq f f'`, for morphisms `f f' : j ⟶ j'`, is an arbitrary choice of object which admits a morphism `coeqHom f f' : j' ⟶ coeq f f'` such that `coeq_condition : f ≫ coeqHom f f' = f' ≫ coeqHom f f'`. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeq {j j' : C} (f f' : j ⟶ j') : C := (IsFilteredOrEmpty.cocone_maps f f').choose /-- `coeqHom f f'`, for morphisms `f f' : j ⟶ j'`, is an arbitrary choice of morphism `coeqHom f f' : j' ⟶ coeq f f'` such that `coeq_condition : f ≫ coeqHom f f' = f' ≫ coeqHom f f'`. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeqHom {j j' : C} (f f' : j ⟶ j') : j' ⟶ coeq f f' := (IsFilteredOrEmpty.cocone_maps f f').choose_spec.choose /-- `coeq_condition f f'`, for morphisms `f f' : j ⟶ j'`, is the proof that `f ≫ coeqHom f f' = f' ≫ coeqHom f f'`. -/ @[reassoc] -- Not `@[simp]` as it does not fire. theorem coeq_condition {j j' : C} (f f' : j ⟶ j') : f ≫ coeqHom f f' = f' ≫ coeqHom f f' := (IsFilteredOrEmpty.cocone_maps f f').choose_spec.choose_spec end AllowEmpty end IsFiltered namespace IsFilteredOrEmpty open IsFiltered variable {C} variable [IsFilteredOrEmpty C] variable {D : Type u₁} [Category.{v₁} D] /-- If `C` is filtered or empty, and we have a functor `R : C ⥤ D` with a left adjoint, then `D` is filtered or empty. -/ theorem of_right_adjoint {L : D ⥤ C} {R : C ⥤ D} (h : L ⊣ R) : IsFilteredOrEmpty D := { cocone_objs := fun X Y => ⟨R.obj (max (L.obj X) (L.obj Y)), h.homEquiv _ _ (leftToMax _ _), h.homEquiv _ _ (rightToMax _ _), ⟨⟩⟩ cocone_maps := fun X Y f g => ⟨R.obj (coeq (L.map f) (L.map g)), h.homEquiv _ _ (coeqHom _ _), by rw [← h.homEquiv_naturality_left, ← h.homEquiv_naturality_left, coeq_condition]⟩ } /-- If `C` is filtered or empty, and we have a right adjoint functor `R : C ⥤ D`, then `D` is filtered or empty. -/ theorem of_isRightAdjoint (R : C ⥤ D) [R.IsRightAdjoint] : IsFilteredOrEmpty D := of_right_adjoint (Adjunction.ofIsRightAdjoint R) /-- Being filtered or empty is preserved by equivalence of categories. -/ theorem of_equivalence (h : C ≌ D) : IsFilteredOrEmpty D := of_right_adjoint h.symm.toAdjunction end IsFilteredOrEmpty namespace IsFiltered section Nonempty open CategoryTheory.Limits variable {C} variable [IsFiltered C] /-- Any finite collection of objects in a filtered category has an object "to the right". -/ theorem sup_objs_exists (O : Finset C) : ∃ S : C, ∀ {X}, X ∈ O → Nonempty (X ⟶ S) := by classical induction O using Finset.induction with | empty => exact ⟨Classical.choice IsFiltered.nonempty, by simp⟩ | insert X O' nm h => obtain ⟨S', w'⟩ := h use max X S' rintro Y mY obtain rfl | h := eq_or_ne Y X · exact ⟨leftToMax _ _⟩ · exact ⟨(w' (Finset.mem_of_mem_insert_of_ne mY h)).some ≫ rightToMax _ _⟩ variable (O : Finset C) (H : Finset (Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y)) /-- Given any `Finset` of objects `{X, ...}` and indexed collection of `Finset`s of morphisms `{f, ...}` in `C`, there exists an object `S`, with a morphism `T X : X ⟶ S` from each `X`, such that the triangles commute: `f ≫ T Y = T X`, for `f : X ⟶ Y` in the `Finset`. -/ theorem sup_exists : ∃ (S : C) (T : ∀ {X : C}, X ∈ O → (X ⟶ S)), ∀ {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟶ Y}, (⟨X, Y, mX, mY, f⟩ : Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H → f ≫ T mY = T mX := by classical induction H using Finset.induction with | empty => obtain ⟨S, f⟩ := sup_objs_exists O exact ⟨S, fun mX => (f mX).some, by rintro - - - - - ⟨⟩⟩ | insert h' H' nmf h'' => obtain ⟨X, Y, mX, mY, f⟩ := h' obtain ⟨S', T', w'⟩ := h'' refine ⟨coeq (f ≫ T' mY) (T' mX), fun mZ => T' mZ ≫ coeqHom (f ≫ T' mY) (T' mX), ?_⟩ intro X' Y' mX' mY' f' mf' rw [← Category.assoc] by_cases h : X = X' ∧ Y = Y' · rcases h with ⟨rfl, rfl⟩ by_cases hf : f = f' · subst hf apply coeq_condition · rw [@w' _ _ mX mY f'] grind · rw [@w' _ _ mX' mY' f' _] apply Finset.mem_of_mem_insert_of_ne mf' contrapose! h obtain ⟨rfl, h⟩ := h trivial /-- An arbitrary choice of object "to the right" of a finite collection of objects `O` and morphisms `H`, making all the triangles commute. -/ noncomputable def sup : C := (sup_exists O H).choose /-- The morphisms to `sup O H`. -/ noncomputable def toSup {X : C} (m : X ∈ O) : X ⟶ sup O H := (sup_exists O H).choose_spec.choose m /-- The triangles of consisting of a morphism in `H` and the maps to `sup O H` commute. -/ theorem toSup_commutes {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟶ Y} (mf : (⟨X, Y, mX, mY, f⟩ : Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H) : f ≫ toSup O H mY = toSup O H mX := (sup_exists O H).choose_spec.choose_spec mX mY mf variable {J : Type w} [SmallCategory J] [FinCategory J] /-- If we have `IsFiltered C`, then for any functor `F : J ⥤ C` with `FinCategory J`, there exists a cocone over `F`. -/ theorem cocone_nonempty (F : J ⥤ C) : Nonempty (Cocone F) := by classical let O := Finset.univ.image F.obj let H : Finset (Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) := Finset.univ.biUnion fun X : J => Finset.univ.biUnion fun Y : J => Finset.univ.image fun f : X ⟶ Y => ⟨F.obj X, F.obj Y, by simp [O], by simp [O], F.map f⟩ obtain ⟨Z, f, w⟩ := sup_exists O H refine ⟨⟨Z, ⟨fun X => f (by simp [O]), ?_⟩⟩⟩ intro j j' g dsimp simp only [Category.comp_id] apply w simp only [O, H, Finset.mem_biUnion, Finset.mem_univ, Finset.mem_image, PSigma.mk.injEq, true_and, exists_and_left] exact ⟨j, rfl, j', g, by simp⟩ /-- An arbitrary choice of cocone over `F : J ⥤ C`, for `FinCategory J` and `IsFiltered C`. -/ noncomputable def cocone (F : J ⥤ C) : Cocone F := (cocone_nonempty F).some variable {D : Type u₁} [Category.{v₁} D] /-- If `C` is filtered, and we have a functor `R : C ⥤ D` with a left adjoint, then `D` is filtered. -/ theorem of_right_adjoint {L : D ⥤ C} {R : C ⥤ D} (h : L ⊣ R) : IsFiltered D := { IsFilteredOrEmpty.of_right_adjoint h with nonempty := IsFiltered.nonempty.map R.obj } /-- If `C` is filtered, and we have a right adjoint functor `R : C ⥤ D`, then `D` is filtered. -/ theorem of_isRightAdjoint (R : C ⥤ D) [R.IsRightAdjoint] : IsFiltered D := of_right_adjoint (Adjunction.ofIsRightAdjoint R) /-- Being filtered is preserved by equivalence of categories. -/ theorem of_equivalence (h : C ≌ D) : IsFiltered D := of_right_adjoint h.symm.toAdjunction end Nonempty section OfCocone open CategoryTheory.Limits /-- If every finite diagram in `C` admits a cocone, then `C` is filtered. It is sufficient to verify this for diagrams whose shape lives in any one fixed universe. -/ theorem of_cocone_nonempty (h : ∀ {J : Type w} [SmallCategory J] [FinCategory J] (F : J ⥤ C), Nonempty (Cocone F)) : IsFiltered C := by have : Nonempty C := by obtain ⟨c⟩ := h (Functor.empty _) exact ⟨c.pt⟩ have : IsFilteredOrEmpty C := by refine ⟨?_, ?_⟩ · intro X Y obtain ⟨c⟩ := h (ULiftHom.down ⋙ ULift.downFunctor ⋙ pair X Y) exact ⟨c.pt, c.ι.app ⟨⟨WalkingPair.left⟩⟩, c.ι.app ⟨⟨WalkingPair.right⟩⟩, trivial⟩ · intro X Y f g obtain ⟨c⟩ := h (ULiftHom.down ⋙ ULift.downFunctor ⋙ parallelPair f g) refine ⟨c.pt, c.ι.app ⟨WalkingParallelPair.one⟩, ?_⟩ have h₁ := c.ι.naturality ⟨WalkingParallelPairHom.left⟩ have h₂ := c.ι.naturality ⟨WalkingParallelPairHom.right⟩ simp_all apply IsFiltered.mk theorem of_hasFiniteColimits [HasFiniteColimits C] : IsFiltered C := of_cocone_nonempty.{v} C fun F => ⟨colimit.cocone F⟩ theorem of_isTerminal {X : C} (h : IsTerminal X) : IsFiltered C := of_cocone_nonempty.{v} _ fun {_} _ _ _ => ⟨⟨X, ⟨fun _ => h.from _, fun _ _ _ => h.hom_ext _ _⟩⟩⟩ instance (priority := 100) of_hasTerminal [HasTerminal C] : IsFiltered C := of_isTerminal _ terminalIsTerminal /-- For every universe `w`, `C` is filtered if and only if every finite diagram in `C` with shape in `w` admits a cocone. -/ theorem iff_cocone_nonempty : IsFiltered C ↔ ∀ {J : Type w} [SmallCategory J] [FinCategory J] (F : J ⥤ C), Nonempty (Cocone F) := ⟨fun _ _ _ _ F => cocone_nonempty F, of_cocone_nonempty C⟩ end OfCocone section SpecialShapes variable {C} variable [IsFilteredOrEmpty C] /-- `max₃ j₁ j₂ j₃` is an arbitrary choice of object to the right of `j₁`, `j₂` and `j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def max₃ (j₁ j₂ j₃ : C) : C := max (max j₁ j₂) j₃ /-- `firstToMax₃ j₁ j₂ j₃` is an arbitrary choice of morphism from `j₁` to `max₃ j₁ j₂ j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def firstToMax₃ (j₁ j₂ j₃ : C) : j₁ ⟶ max₃ j₁ j₂ j₃ := leftToMax j₁ j₂ ≫ leftToMax (max j₁ j₂) j₃ /-- `secondToMax₃ j₁ j₂ j₃` is an arbitrary choice of morphism from `j₂` to `max₃ j₁ j₂ j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def secondToMax₃ (j₁ j₂ j₃ : C) : j₂ ⟶ max₃ j₁ j₂ j₃ := rightToMax j₁ j₂ ≫ leftToMax (max j₁ j₂) j₃ /-- `thirdToMax₃ j₁ j₂ j₃` is an arbitrary choice of morphism from `j₃` to `max₃ j₁ j₂ j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def thirdToMax₃ (j₁ j₂ j₃ : C) : j₃ ⟶ max₃ j₁ j₂ j₃ := rightToMax (max j₁ j₂) j₃ /-- `coeq₃ f g h`, for morphisms `f g h : j₁ ⟶ j₂`, is an arbitrary choice of object which admits a morphism `coeq₃Hom f g h : j₂ ⟶ coeq₃ f g h` such that `coeq₃_condition₁`, `coeq₃_condition₂` and `coeq₃_condition₃` are satisfied. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeq₃ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : C := coeq (coeqHom f g ≫ leftToMax (coeq f g) (coeq g h)) (coeqHom g h ≫ rightToMax (coeq f g) (coeq g h)) /-- `coeq₃Hom f g h`, for morphisms `f g h : j₁ ⟶ j₂`, is an arbitrary choice of morphism `j₂ ⟶ coeq₃ f g h` such that `coeq₃_condition₁`, `coeq₃_condition₂` and `coeq₃_condition₃` are satisfied. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeq₃Hom {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : j₂ ⟶ coeq₃ f g h := coeqHom f g ≫ leftToMax (coeq f g) (coeq g h) ≫ coeqHom (coeqHom f g ≫ leftToMax (coeq f g) (coeq g h)) (coeqHom g h ≫ rightToMax (coeq f g) (coeq g h)) theorem coeq₃_condition₁ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : f ≫ coeq₃Hom f g h = g ≫ coeq₃Hom f g h := by simp only [coeq₃Hom, ← Category.assoc, coeq_condition f g] theorem coeq₃_condition₂ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : g ≫ coeq₃Hom f g h = h ≫ coeq₃Hom f g h := by dsimp [coeq₃Hom] slice_lhs 2 4 => rw [← Category.assoc, coeq_condition _ _] slice_rhs 2 4 => rw [← Category.assoc, coeq_condition _ _] slice_lhs 1 3 => rw [← Category.assoc, coeq_condition _ _] simp only [Category.assoc] theorem coeq₃_condition₃ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : f ≫ coeq₃Hom f g h = h ≫ coeq₃Hom f g h := Eq.trans (coeq₃_condition₁ f g h) (coeq₃_condition₂ f g h) /-- For every span `j ⟵ i ⟶ j'`, there exists a cocone `j ⟶ k ⟵ j'` such that the square commutes. -/ theorem span {i j j' : C} (f : i ⟶ j) (f' : i ⟶ j') : ∃ (k : C) (g : j ⟶ k) (g' : j' ⟶ k), f ≫ g = f' ≫ g' := let ⟨K, G, G', _⟩ := IsFilteredOrEmpty.cocone_objs j j' let ⟨k, e, he⟩ := IsFilteredOrEmpty.cocone_maps (f ≫ G) (f' ≫ G') ⟨k, G ≫ e, G' ≫ e, by simpa only [← Category.assoc] ⟩ /-- Given a "bowtie" of morphisms ``` j₁ j₂ |\ /| | \/ | | /\ | |/ \∣ vv vv k₁ k₂ ``` in a filtered category, we can construct an object `s` and two morphisms from `k₁` and `k₂` to `s`, making the resulting squares commute. -/ theorem bowtie {j₁ j₂ k₁ k₂ : C} (f₁ : j₁ ⟶ k₁) (g₁ : j₁ ⟶ k₂) (f₂ : j₂ ⟶ k₁) (g₂ : j₂ ⟶ k₂) : ∃ (s : C) (α : k₁ ⟶ s) (β : k₂ ⟶ s), f₁ ≫ α = g₁ ≫ β ∧ f₂ ≫ α = g₂ ≫ β := by obtain ⟨t, k₁t, k₂t, ht⟩ := span f₁ g₁ obtain ⟨s, ts, hs⟩ := IsFilteredOrEmpty.cocone_maps (f₂ ≫ k₁t) (g₂ ≫ k₂t) simp_rw [Category.assoc] at hs exact ⟨s, k₁t ≫ ts, k₂t ≫ ts, by simp only [← Category.assoc, ht], hs⟩ /-- Given a "tulip" of morphisms ``` j₁ j₂ j₃ |\ / \ / | | \ / \ / | | vv vv | \ k₁ k₂ / \ / \ / \ / \ / v v l ``` in a filtered category, we can construct an object `s` and three morphisms from `k₁`, `k₂` and `l` to `s`, making the resulting squares commute. -/ theorem tulip {j₁ j₂ j₃ k₁ k₂ l : C} (f₁ : j₁ ⟶ k₁) (f₂ : j₂ ⟶ k₁) (f₃ : j₂ ⟶ k₂) (f₄ : j₃ ⟶ k₂) (g₁ : j₁ ⟶ l) (g₂ : j₃ ⟶ l) : ∃ (s : C) (α : k₁ ⟶ s) (β : l ⟶ s) (γ : k₂ ⟶ s), f₁ ≫ α = g₁ ≫ β ∧ f₂ ≫ α = f₃ ≫ γ ∧ f₄ ≫ γ = g₂ ≫ β := by obtain ⟨l', k₁l, k₂l, hl⟩ := span f₂ f₃ obtain ⟨s, ls, l's, hs₁, hs₂⟩ := bowtie g₁ (f₁ ≫ k₁l) g₂ (f₄ ≫ k₂l) refine ⟨s, k₁l ≫ l's, ls, k₂l ≫ l's, ?_, by simp only [← Category.assoc, hl], ?_⟩ <;> simp only [hs₁, hs₂, Category.assoc] end SpecialShapes end IsFiltered /-- A category `IsCofilteredOrEmpty` if 1. for every pair of objects there exists another object "to the left", and 2. for every pair of parallel morphisms there exists a morphism to the left so the compositions are equal. -/ class IsCofilteredOrEmpty : Prop where /-- for every pair of objects there exists another object "to the left" -/ cone_objs : ∀ X Y : C, ∃ (W : _) (_ : W ⟶ X) (_ : W ⟶ Y), True /-- for every pair of parallel morphisms there exists a morphism to the left so the compositions are equal -/ cone_maps : ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), ∃ (W : _) (h : W ⟶ X), h ≫ f = h ≫ g /-- A category `IsCofiltered` if 1. for every pair of objects there exists another object "to the left", 2. for every pair of parallel morphisms there exists a morphism to the left so the compositions are equal, and 3. there exists some object. -/ @[stacks 04AZ] class IsCofiltered : Prop extends IsCofilteredOrEmpty C where /-- a cofiltered category must be non-empty -/ -- This should be an instance but it causes significant slowdown [nonempty : Nonempty C] instance (priority := 100) isCofilteredOrEmpty_of_semilatticeInf (α : Type u) [SemilatticeInf α] : IsCofilteredOrEmpty α where cone_objs X Y := ⟨X ⊓ Y, homOfLE inf_le_left, homOfLE inf_le_right, trivial⟩ cone_maps X Y f g := ⟨X, 𝟙 _, by apply ULift.ext subsingleton⟩ instance (priority := 100) isCofiltered_of_semilatticeInf_nonempty (α : Type u) [SemilatticeInf α] [Nonempty α] : IsCofiltered α where instance (priority := 100) isCofilteredOrEmpty_of_directed_ge (α : Type u) [Preorder α] [IsDirected α (· ≥ ·)] : IsCofilteredOrEmpty α where cone_objs X Y := let ⟨Z, hX, hY⟩ := exists_le_le X Y ⟨Z, homOfLE hX, homOfLE hY, trivial⟩ cone_maps X Y f g := ⟨X, 𝟙 _, by apply ULift.ext subsingleton⟩ instance (priority := 100) isCofiltered_of_directed_ge_nonempty (α : Type u) [Preorder α] [IsDirected α (· ≥ ·)] [Nonempty α] : IsCofiltered α where -- Sanity checks example (α : Type u) [SemilatticeInf α] [OrderBot α] : IsCofiltered α := by infer_instance example (α : Type u) [SemilatticeInf α] [OrderTop α] : IsCofiltered α := by infer_instance instance : IsCofiltered (Discrete PUnit) where cone_objs _ Y := ⟨⟨PUnit.unit⟩, ⟨⟨by trivial⟩⟩, ⟨⟨by subsingleton⟩⟩, trivial⟩ cone_maps X Y f g := ⟨⟨PUnit.unit⟩, ⟨⟨by trivial⟩⟩, by apply ULift.ext subsingleton⟩ namespace IsCofiltered section AllowEmpty variable {C} variable [IsCofilteredOrEmpty C] /-- `min j j'` is an arbitrary choice of object to the left of both `j` and `j'`, whose existence is ensured by `IsCofiltered`. -/ noncomputable def min (j j' : C) : C := (IsCofilteredOrEmpty.cone_objs j j').choose /-- `minToLeft j j'` is an arbitrary choice of morphism from `min j j'` to `j`, whose existence is ensured by `IsCofiltered`. -/ noncomputable def minToLeft (j j' : C) : min j j' ⟶ j := (IsCofilteredOrEmpty.cone_objs j j').choose_spec.choose /-- `minToRight j j'` is an arbitrary choice of morphism from `min j j'` to `j'`, whose existence is ensured by `IsCofiltered`. -/ noncomputable def minToRight (j j' : C) : min j j' ⟶ j' := (IsCofilteredOrEmpty.cone_objs j j').choose_spec.choose_spec.choose /-- `eq f f'`, for morphisms `f f' : j ⟶ j'`, is an arbitrary choice of object which admits a morphism `eqHom f f' : eq f f' ⟶ j` such that `eq_condition : eqHom f f' ≫ f = eqHom f f' ≫ f'`. Its existence is ensured by `IsCofiltered`. -/ noncomputable def eq {j j' : C} (f f' : j ⟶ j') : C := (IsCofilteredOrEmpty.cone_maps f f').choose /-- `eqHom f f'`, for morphisms `f f' : j ⟶ j'`, is an arbitrary choice of morphism `eqHom f f' : eq f f' ⟶ j` such that `eq_condition : eqHom f f' ≫ f = eqHom f f' ≫ f'`. Its existence is ensured by `IsCofiltered`. -/ noncomputable def eqHom {j j' : C} (f f' : j ⟶ j') : eq f f' ⟶ j := (IsCofilteredOrEmpty.cone_maps f f').choose_spec.choose /-- `eq_condition f f'`, for morphisms `f f' : j ⟶ j'`, is the proof that `eqHom f f' ≫ f = eqHom f f' ≫ f'`. -/ @[reassoc] -- Not `@[simp]` as it does not fire. theorem eq_condition {j j' : C} (f f' : j ⟶ j') : eqHom f f' ≫ f = eqHom f f' ≫ f' := (IsCofilteredOrEmpty.cone_maps f f').choose_spec.choose_spec /-- For every cospan `j ⟶ i ⟵ j'`, there exists a cone `j ⟵ k ⟶ j'` such that the square commutes. -/ theorem cospan {i j j' : C} (f : j ⟶ i) (f' : j' ⟶ i) : ∃ (k : C) (g : k ⟶ j) (g' : k ⟶ j'), g ≫ f = g' ≫ f' := let ⟨K, G, G', _⟩ := IsCofilteredOrEmpty.cone_objs j j' let ⟨k, e, he⟩ := IsCofilteredOrEmpty.cone_maps (G ≫ f) (G' ≫ f') ⟨k, e ≫ G, e ≫ G', by simpa only [Category.assoc] using he⟩ theorem _root_.CategoryTheory.Functor.ranges_directed (F : C ⥤ Type*) (j : C) : Directed (· ⊇ ·) fun f : Σ' i, i ⟶ j => Set.range (F.map f.2) := fun ⟨i, ij⟩ ⟨k, kj⟩ => by let ⟨l, li, lk, e⟩ := cospan ij kj refine ⟨⟨l, lk ≫ kj⟩, e ▸ ?_, ?_⟩ <;> simp_rw [F.map_comp] <;> apply Set.range_comp_subset_range /-- Given a "bowtie" of morphisms ``` k₁ k₂ |\ /| | \/ | | /\ | |/ \∣ vv vv j₁ j₂ ``` in a cofiltered category, we can construct an object `s` and two morphisms from `s` to `k₁` and `k₂`, making the resulting squares commute. -/ theorem bowtie {j₁ j₂ k₁ k₂ : C} (f₁ : k₁ ⟶ j₁) (g₁ : k₂ ⟶ j₁) (f₂ : k₁ ⟶ j₂) (g₂ : k₂ ⟶ j₂) : ∃ (s : C) (α : s ⟶ k₁) (β : s ⟶ k₂), α ≫ f₁ = β ≫ g₁ ∧ α ≫ f₂ = β ≫ g₂ := by obtain ⟨t, k₁t, k₂t, ht⟩ := cospan f₁ g₁ obtain ⟨s, ts, hs⟩ := IsCofilteredOrEmpty.cone_maps (k₁t ≫ f₂) (k₂t ≫ g₂) exact ⟨s, ts ≫ k₁t, ts ≫ k₂t, by simp only [Category.assoc, ht], by simp only [Category.assoc, hs]⟩ end AllowEmpty end IsCofiltered namespace IsCofilteredOrEmpty open IsCofiltered variable {C} variable [IsCofilteredOrEmpty C] variable {D : Type u₁} [Category.{v₁} D] /-- If `C` is cofiltered or empty, and we have a functor `L : C ⥤ D` with a right adjoint, then `D` is cofiltered or empty. -/ theorem of_left_adjoint {L : C ⥤ D} {R : D ⥤ C} (h : L ⊣ R) : IsCofilteredOrEmpty D := { cone_objs := fun X Y => ⟨L.obj (min (R.obj X) (R.obj Y)), (h.homEquiv _ X).symm (minToLeft _ _), (h.homEquiv _ Y).symm (minToRight _ _), ⟨⟩⟩ cone_maps := fun X Y f g => ⟨L.obj (eq (R.map f) (R.map g)), (h.homEquiv _ _).symm (eqHom _ _), by rw [← h.homEquiv_naturality_right_symm, ← h.homEquiv_naturality_right_symm, eq_condition]⟩ } /-- If `C` is cofiltered or empty, and we have a left adjoint functor `L : C ⥤ D`, then `D` is cofiltered or empty. -/ theorem of_isLeftAdjoint (L : C ⥤ D) [L.IsLeftAdjoint] : IsCofilteredOrEmpty D := of_left_adjoint (Adjunction.ofIsLeftAdjoint L) /-- Being cofiltered or empty is preserved by equivalence of categories. -/ theorem of_equivalence (h : C ≌ D) : IsCofilteredOrEmpty D := of_left_adjoint h.toAdjunction end IsCofilteredOrEmpty namespace IsCofiltered section Nonempty open CategoryTheory.Limits variable {C} variable [IsCofiltered C] /-- Any finite collection of objects in a cofiltered category has an object "to the left". -/ theorem inf_objs_exists (O : Finset C) : ∃ S : C, ∀ {X}, X ∈ O → Nonempty (S ⟶ X) := by classical induction O using Finset.induction with | empty => exact ⟨Classical.choice IsCofiltered.nonempty, by simp⟩ | insert X O' nm h => obtain ⟨S', w'⟩ := h use min X S' rintro Y mY obtain rfl | h := eq_or_ne Y X · exact ⟨minToLeft _ _⟩ · exact ⟨minToRight _ _ ≫ (w' (Finset.mem_of_mem_insert_of_ne mY h)).some⟩ variable (O : Finset C) (H : Finset (Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y)) /-- Given any `Finset` of objects `{X, ...}` and indexed collection of `Finset`s of morphisms `{f, ...}` in `C`, there exists an object `S`, with a morphism `T X : S ⟶ X` from each `X`, such that the triangles commute: `T X ≫ f = T Y`, for `f : X ⟶ Y` in the `Finset`. -/ theorem inf_exists : ∃ (S : C) (T : ∀ {X : C}, X ∈ O → (S ⟶ X)), ∀ {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟶ Y}, (⟨X, Y, mX, mY, f⟩ : Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H → T mX ≫ f = T mY := by classical induction H using Finset.induction with | empty => obtain ⟨S, f⟩ := inf_objs_exists O exact ⟨S, fun mX => (f mX).some, by rintro - - - - - ⟨⟩⟩ | insert h' H' nmf h'' => obtain ⟨X, Y, mX, mY, f⟩ := h' obtain ⟨S', T', w'⟩ := h'' refine ⟨eq (T' mX ≫ f) (T' mY), fun mZ => eqHom (T' mX ≫ f) (T' mY) ≫ T' mZ, ?_⟩ intro X' Y' mX' mY' f' mf' rw [Category.assoc] by_cases h : X = X' ∧ Y = Y' · rcases h with ⟨rfl, rfl⟩ by_cases hf : f = f' · subst hf apply eq_condition · rw [@w' _ _ mX mY f'] simp only [Finset.mem_insert, PSigma.mk.injEq, heq_eq_eq, true_and] at mf' grind · rw [@w' _ _ mX' mY' f' _] apply Finset.mem_of_mem_insert_of_ne mf' contrapose! h obtain ⟨rfl, h⟩ := h trivial /-- An arbitrary choice of object "to the left" of a finite collection of objects `O` and morphisms `H`, making all the triangles commute. -/ noncomputable def inf : C := (inf_exists O H).choose /-- The morphisms from `inf O H`. -/ noncomputable def infTo {X : C} (m : X ∈ O) : inf O H ⟶ X := (inf_exists O H).choose_spec.choose m /-- The triangles consisting of a morphism in `H` and the maps from `inf O H` commute. -/ theorem infTo_commutes {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟶ Y} (mf : (⟨X, Y, mX, mY, f⟩ : Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H) : infTo O H mX ≫ f = infTo O H mY := (inf_exists O H).choose_spec.choose_spec mX mY mf variable {J : Type w} [SmallCategory J] [FinCategory J] /-- If we have `IsCofiltered C`, then for any functor `F : J ⥤ C` with `FinCategory J`, there exists a cone over `F`. -/ theorem cone_nonempty (F : J ⥤ C) : Nonempty (Cone F) := by classical let O := Finset.univ.image F.obj let H : Finset (Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) := Finset.univ.biUnion fun X : J => Finset.univ.biUnion fun Y : J => Finset.univ.image fun f : X ⟶ Y => ⟨F.obj X, F.obj Y, by simp [O], by simp [O], F.map f⟩ obtain ⟨Z, f, w⟩ := inf_exists O H refine ⟨⟨Z, ⟨fun X => f (by simp [O]), ?_⟩⟩⟩ intro j j' g dsimp simp only [Category.id_comp] symm apply w simp only [O, H, Finset.mem_biUnion, Finset.mem_univ, Finset.mem_image, PSigma.mk.injEq, true_and, exists_and_left] exact ⟨j, rfl, j', g, by simp⟩ /-- An arbitrary choice of cone over `F : J ⥤ C`, for `FinCategory J` and `IsCofiltered C`. -/ noncomputable def cone (F : J ⥤ C) : Cone F := (cone_nonempty F).some variable {D : Type u₁} [Category.{v₁} D] /-- If `C` is cofiltered, and we have a functor `L : C ⥤ D` with a right adjoint, then `D` is cofiltered. -/ theorem of_left_adjoint {L : C ⥤ D} {R : D ⥤ C} (h : L ⊣ R) : IsCofiltered D := { IsCofilteredOrEmpty.of_left_adjoint h with nonempty := IsCofiltered.nonempty.map L.obj } /-- If `C` is cofiltered, and we have a left adjoint functor `L : C ⥤ D`, then `D` is cofiltered. -/ theorem of_isLeftAdjoint (L : C ⥤ D) [L.IsLeftAdjoint] : IsCofiltered D := of_left_adjoint (Adjunction.ofIsLeftAdjoint L) /-- Being cofiltered is preserved by equivalence of categories. -/ theorem of_equivalence (h : C ≌ D) : IsCofiltered D := of_left_adjoint h.toAdjunction end Nonempty section OfCone open CategoryTheory.Limits /-- If every finite diagram in `C` admits a cone, then `C` is cofiltered. It is sufficient to verify this for diagrams whose shape lives in any one fixed universe. -/ theorem of_cone_nonempty (h : ∀ {J : Type w} [SmallCategory J] [FinCategory J] (F : J ⥤ C), Nonempty (Cone F)) : IsCofiltered C := by have : Nonempty C := by obtain ⟨c⟩ := h (Functor.empty _) exact ⟨c.pt⟩ have : IsCofilteredOrEmpty C := by refine ⟨?_, ?_⟩ · intro X Y obtain ⟨c⟩ := h (ULiftHom.down ⋙ ULift.downFunctor ⋙ pair X Y) exact ⟨c.pt, c.π.app ⟨⟨WalkingPair.left⟩⟩, c.π.app ⟨⟨WalkingPair.right⟩⟩, trivial⟩ · intro X Y f g obtain ⟨c⟩ := h (ULiftHom.down ⋙ ULift.downFunctor ⋙ parallelPair f g) refine ⟨c.pt, c.π.app ⟨WalkingParallelPair.zero⟩, ?_⟩ have h₁ := c.π.naturality ⟨WalkingParallelPairHom.left⟩ have h₂ := c.π.naturality ⟨WalkingParallelPairHom.right⟩ simp_all apply IsCofiltered.mk theorem of_hasFiniteLimits [HasFiniteLimits C] : IsCofiltered C := of_cone_nonempty.{v} C fun F => ⟨limit.cone F⟩ theorem of_isInitial {X : C} (h : IsInitial X) : IsCofiltered C := of_cone_nonempty.{v} _ fun {_} _ _ _ => ⟨⟨X, ⟨fun _ => h.to _, fun _ _ _ => h.hom_ext _ _⟩⟩⟩ instance (priority := 100) of_hasInitial [HasInitial C] : IsCofiltered C := of_isInitial _ initialIsInitial /-- For every universe `w`, `C` is filtered if and only if every finite diagram in `C` with shape in `w` admits a cocone. -/ theorem iff_cone_nonempty : IsCofiltered C ↔ ∀ {J : Type w} [SmallCategory J] [FinCategory J] (F : J ⥤ C), Nonempty (Cone F) := ⟨fun _ _ _ _ F => cone_nonempty F, of_cone_nonempty C⟩ end OfCone end IsCofiltered section Opposite open Opposite instance isCofilteredOrEmpty_op_of_isFilteredOrEmpty [IsFilteredOrEmpty C] : IsCofilteredOrEmpty Cᵒᵖ where cone_objs X Y := ⟨op (IsFiltered.max X.unop Y.unop), (IsFiltered.leftToMax _ _).op, (IsFiltered.rightToMax _ _).op, trivial⟩ cone_maps X Y f g := ⟨op (IsFiltered.coeq f.unop g.unop), (IsFiltered.coeqHom _ _).op, by rw [show f = f.unop.op by simp, show g = g.unop.op by simp, ← op_comp, ← op_comp] congr 1 exact IsFiltered.coeq_condition f.unop g.unop⟩ instance isCofiltered_op_of_isFiltered [IsFiltered C] : IsCofiltered Cᵒᵖ where nonempty := letI : Nonempty C := IsFiltered.nonempty; inferInstance instance isFilteredOrEmpty_op_of_isCofilteredOrEmpty [IsCofilteredOrEmpty C] : IsFilteredOrEmpty Cᵒᵖ where cocone_objs X Y := ⟨op (IsCofiltered.min X.unop Y.unop), (IsCofiltered.minToLeft X.unop Y.unop).op, (IsCofiltered.minToRight X.unop Y.unop).op, trivial⟩ cocone_maps X Y f g := ⟨op (IsCofiltered.eq f.unop g.unop), (IsCofiltered.eqHom f.unop g.unop).op, by rw [show f = f.unop.op by simp, show g = g.unop.op by simp, ← op_comp, ← op_comp] congr 1 exact IsCofiltered.eq_condition f.unop g.unop⟩ instance isFiltered_op_of_isCofiltered [IsCofiltered C] : IsFiltered Cᵒᵖ where nonempty := letI : Nonempty C := IsCofiltered.nonempty; inferInstance /-- If Cᵒᵖ is filtered or empty, then C is cofiltered or empty. -/ lemma isCofilteredOrEmpty_of_isFilteredOrEmpty_op [IsFilteredOrEmpty Cᵒᵖ] : IsCofilteredOrEmpty C := IsCofilteredOrEmpty.of_equivalence (opOpEquivalence _) /-- If Cᵒᵖ is cofiltered or empty, then C is filtered or empty. -/ lemma isFilteredOrEmpty_of_isCofilteredOrEmpty_op [IsCofilteredOrEmpty Cᵒᵖ] : IsFilteredOrEmpty C := IsFilteredOrEmpty.of_equivalence (opOpEquivalence _) /-- If Cᵒᵖ is filtered, then C is cofiltered. -/ lemma isCofiltered_of_isFiltered_op [IsFiltered Cᵒᵖ] : IsCofiltered C := IsCofiltered.of_equivalence (opOpEquivalence _) /-- If Cᵒᵖ is cofiltered, then C is filtered. -/ lemma isFiltered_of_isCofiltered_op [IsCofiltered Cᵒᵖ] : IsFiltered C := IsFiltered.of_equivalence (opOpEquivalence _) end Opposite section ULift instance [IsFiltered C] : IsFiltered (ULift.{u₂} C) := IsFiltered.of_equivalence ULift.equivalence instance [IsCofiltered C] : IsCofiltered (ULift.{u₂} C) := IsCofiltered.of_equivalence ULift.equivalence instance [IsFiltered C] : IsFiltered (ULiftHom C) := IsFiltered.of_equivalence ULiftHom.equiv instance [IsCofiltered C] : IsCofiltered (ULiftHom C) := IsCofiltered.of_equivalence ULiftHom.equiv instance [IsFiltered C] : IsFiltered (AsSmall C) := IsFiltered.of_equivalence AsSmall.equiv instance [IsCofiltered C] : IsCofiltered (AsSmall C) := IsCofiltered.of_equivalence AsSmall.equiv end ULift section Pi variable {α : Type w} {I : α → Type u₁} [∀ i, Category.{v₁} (I i)] open IsFiltered in instance [∀ i, IsFilteredOrEmpty (I i)] : IsFilteredOrEmpty (∀ i, I i) where cocone_objs k l := ⟨fun s => max (k s) (l s), fun s => leftToMax (k s) (l s), fun s => rightToMax (k s) (l s), trivial⟩ cocone_maps k l f g := ⟨fun s => coeq (f s) (g s), fun s => coeqHom (f s) (g s), funext fun s => by simp [coeq_condition (f s) (g s)]⟩ attribute [local instance] IsFiltered.nonempty in instance [∀ i, IsFiltered (I i)] : IsFiltered (∀ i, I i) where open IsCofiltered in instance [∀ i, IsCofilteredOrEmpty (I i)] : IsCofilteredOrEmpty (∀ i, I i) where cone_objs k l := ⟨fun s => min (k s) (l s), fun s => minToLeft (k s) (l s), fun s => minToRight (k s) (l s), trivial⟩ cone_maps k l f g := ⟨fun s => eq (f s) (g s), fun s => eqHom (f s) (g s), funext fun s => by simp [eq_condition (f s) (g s)]⟩ attribute [local instance] IsCofiltered.nonempty in instance [∀ i, IsCofiltered (I i)] : IsCofiltered (∀ i, I i) where end Pi section Prod variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] open IsFiltered in instance [IsFilteredOrEmpty C] [IsFilteredOrEmpty D] : IsFilteredOrEmpty (C × D) where cocone_objs k l := ⟨(max k.1 l.1, max k.2 l.2), (leftToMax k.1 l.1, leftToMax k.2 l.2), (rightToMax k.1 l.1, rightToMax k.2 l.2), trivial⟩ cocone_maps k l f g := ⟨(coeq f.1 g.1, coeq f.2 g.2), (coeqHom f.1 g.1, coeqHom f.2 g.2), by simp [coeq_condition]⟩ attribute [local instance] IsFiltered.nonempty in instance [IsFiltered C] [IsFiltered D] : IsFiltered (C × D) where open IsCofiltered in instance [IsCofilteredOrEmpty C] [IsCofilteredOrEmpty D] : IsCofilteredOrEmpty (C × D) where cone_objs k l := ⟨(min k.1 l.1, min k.2 l.2), (minToLeft k.1 l.1, minToLeft k.2 l.2), (minToRight k.1 l.1, minToRight k.2 l.2), trivial⟩ cone_maps k l f g := ⟨(eq f.1 g.1, eq f.2 g.2), (eqHom f.1 g.1, eqHom f.2 g.2), by simp [eq_condition]⟩ attribute [local instance] IsCofiltered.nonempty in instance [IsCofiltered C] [IsCofiltered D] : IsCofiltered (C × D) where end Prod end CategoryTheory