path
stringlengths
11
71
content
stringlengths
75
124k
CategoryTheory\Functor\KanExtension\Pointwise.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Functor.KanExtension.Basic /-! # Pointwise Kan extensions In this file, we define the notion of pointwise (left) Kan extension. Given two functors `L : C ⥤ D` and `F : C ⥤ H`, and `E : LeftExtension L F`, we introduce a cocone `E.coconeAt Y` for the functor `CostructuredArrow.proj L Y ⋙ F : CostructuredArrow L Y ⥤ H` the point of which is `E.right.obj Y`, and the type `E.IsPointwiseLeftKanExtensionAt Y` which expresses that `E.coconeAt Y` is colimit. When this holds for all `Y : D`, we may say that `E` is a pointwise left Kan extension (`E.IsPointwiseLeftKanExtension`). Conversely, when `CostructuredArrow.proj L Y ⋙ F` has a colimit, we say that `F` has a pointwise left Kan extension at `Y : D` (`HasPointwiseLeftKanExtensionAt L F Y`), and if this holds for all `Y : D`, we construct a functor `pointwiseLeftKanExtension L F : D ⥤ H` and show it is a pointwise Kan extension. A dual API for pointwise right Kan extension is also formalized. ## References * https://ncatlab.org/nlab/show/Kan+extension -/ namespace CategoryTheory open Category Limits namespace Functor variable {C D H : Type*} [Category C] [Category D] [Category H] (L : C ⥤ D) (F : C ⥤ H) /-- The condition that a functor `F` has a pointwise left Kan extension along `L` at `Y`. It means that the functor `CostructuredArrow.proj L Y ⋙ F : CostructuredArrow L Y ⥤ H` has a colimit. -/ abbrev HasPointwiseLeftKanExtensionAt (Y : D) := HasColimit (CostructuredArrow.proj L Y ⋙ F) /-- The condition that a functor `F` has a pointwise left Kan extension along `L`: it means that it has a pointwise left Kan extension at any object. -/ abbrev HasPointwiseLeftKanExtension := ∀ (Y : D), HasPointwiseLeftKanExtensionAt L F Y /-- The condition that a functor `F` has a pointwise right Kan extension along `L` at `Y`. It means that the functor `StructuredArrow.proj Y L ⋙ F : StructuredArrow Y L ⥤ H` has a limit. -/ abbrev HasPointwiseRightKanExtensionAt (Y : D) := HasLimit (StructuredArrow.proj Y L ⋙ F) /-- The condition that a functor `F` has a pointwise right Kan extension along `L`: it means that it has a pointwise right Kan extension at any object. -/ abbrev HasPointwiseRightKanExtension := ∀ (Y : D), HasPointwiseRightKanExtensionAt L F Y namespace LeftExtension variable {F L} variable (E : LeftExtension L F) /-- The cocone for `CostructuredArrow.proj L Y ⋙ F` attached to `E : LeftExtension L F`. The point of this cocone is `E.right.obj Y` -/ @[simps] def coconeAt (Y : D) : Cocone (CostructuredArrow.proj L Y ⋙ F) where pt := E.right.obj Y ι := { app := fun g => E.hom.app g.left ≫ E.right.map g.hom naturality := fun g₁ g₂ φ => by dsimp rw [← CostructuredArrow.w φ] simp only [assoc, NatTrans.naturality_assoc, Functor.comp_map, Functor.map_comp, comp_id] } variable (L F) in /-- The cocones for `CostructuredArrow.proj L Y ⋙ F`, as a functor from `LeftExtension L F`. -/ @[simps] def coconeAtFunctor (Y : D) : LeftExtension L F ⥤ Cocone (CostructuredArrow.proj L Y ⋙ F) where obj E := E.coconeAt Y map {E E'} φ := CoconeMorphism.mk (φ.right.app Y) (fun G => by dsimp rw [← StructuredArrow.w φ] simp) /-- A left extension `E : LeftExtension L F` is a pointwise left Kan extension at `Y` when `E.coconeAt Y` is a colimit cocone. -/ def IsPointwiseLeftKanExtensionAt (Y : D) := IsColimit (E.coconeAt Y) variable {E} in lemma IsPointwiseLeftKanExtensionAt.hasPointwiseLeftKanExtensionAt {Y : D} (h : E.IsPointwiseLeftKanExtensionAt Y) : HasPointwiseLeftKanExtensionAt L F Y := ⟨_, h⟩ lemma IsPointwiseLeftKanExtensionAt.isIso_hom_app {X : C} (h : E.IsPointwiseLeftKanExtensionAt (L.obj X)) [L.Full] [L.Faithful] : IsIso (E.hom.app X) := by simpa using h.isIso_ι_app_of_isTerminal _ CostructuredArrow.mkIdTerminal /-- A left extension `E : LeftExtension L F` is a pointwise left Kan extension when it is a pointwise left Kan extension at any object. -/ abbrev IsPointwiseLeftKanExtension := ∀ (Y : D), E.IsPointwiseLeftKanExtensionAt Y variable {E E'} /-- If two left extensions `E` and `E'` are isomorphic, `E` is a pointwise left Kan extension at `Y` iff `E'` is. -/ def isPointwiseLeftKanExtensionAtEquivOfIso (e : E ≅ E') (Y : D) : E.IsPointwiseLeftKanExtensionAt Y ≃ E'.IsPointwiseLeftKanExtensionAt Y := IsColimit.equivIsoColimit ((coconeAtFunctor L F Y).mapIso e) /-- If two left extensions `E` and `E'` are isomorphic, `E` is a pointwise left Kan extension iff `E'` is. -/ def isPointwiseLeftKanExtensionEquivOfIso (e : E ≅ E') : E.IsPointwiseLeftKanExtension ≃ E'.IsPointwiseLeftKanExtension where toFun h := fun Y => (isPointwiseLeftKanExtensionAtEquivOfIso e Y) (h Y) invFun h := fun Y => (isPointwiseLeftKanExtensionAtEquivOfIso e Y).symm (h Y) left_inv h := by aesop right_inv h := by aesop variable (h : E.IsPointwiseLeftKanExtension) lemma IsPointwiseLeftKanExtension.hasPointwiseLeftKanExtension : HasPointwiseLeftKanExtension L F := fun Y => (h Y).hasPointwiseLeftKanExtensionAt /-- The (unique) morphism from a pointwise left Kan extension. -/ def IsPointwiseLeftKanExtension.homFrom (G : LeftExtension L F) : E ⟶ G := StructuredArrow.homMk { app := fun Y => (h Y).desc (LeftExtension.coconeAt G Y) naturality := fun Y₁ Y₂ φ => (h Y₁).hom_ext (fun X => by rw [(h Y₁).fac_assoc (coconeAt G Y₁) X] simpa using (h Y₂).fac (coconeAt G Y₂) ((CostructuredArrow.map φ).obj X)) } (by ext X simpa using (h (L.obj X)).fac (LeftExtension.coconeAt G _) (CostructuredArrow.mk (𝟙 _))) lemma IsPointwiseLeftKanExtension.hom_ext (h : E.IsPointwiseLeftKanExtension) {G : LeftExtension L F} {f₁ f₂ : E ⟶ G} : f₁ = f₂ := by ext Y apply (h Y).hom_ext intro X have eq₁ := congr_app (StructuredArrow.w f₁) X.left have eq₂ := congr_app (StructuredArrow.w f₂) X.left dsimp at eq₁ eq₂ ⊢ simp only [assoc, NatTrans.naturality] rw [reassoc_of% eq₁, reassoc_of% eq₂] /-- A pointwise left Kan extension is universal, i.e. it is a left Kan extension. -/ def IsPointwiseLeftKanExtension.isUniversal : E.IsUniversal := IsInitial.ofUniqueHom h.homFrom (fun _ _ => h.hom_ext) lemma IsPointwiseLeftKanExtension.isLeftKanExtension : E.right.IsLeftKanExtension E.hom where nonempty_isUniversal := ⟨h.isUniversal⟩ lemma IsPointwiseLeftKanExtension.hasLeftKanExtension : HasLeftKanExtension L F := have := h.isLeftKanExtension HasLeftKanExtension.mk E.right E.hom lemma IsPointwiseLeftKanExtension.isIso_hom [L.Full] [L.Faithful] : IsIso (E.hom) := have := fun X => (h (L.obj X)).isIso_hom_app NatIso.isIso_of_isIso_app .. end LeftExtension namespace RightExtension variable {F L} variable (E E' : RightExtension L F) /-- The cone for `StructuredArrow.proj Y L ⋙ F` attached to `E : RightExtension L F`. The point of this cone is `E.left.obj Y` -/ @[simps] def coneAt (Y : D) : Cone (StructuredArrow.proj Y L ⋙ F) where pt := E.left.obj Y π := { app := fun g ↦ E.left.map g.hom ≫ E.hom.app g.right naturality := fun g₁ g₂ φ ↦ by dsimp rw [assoc, id_comp, ← StructuredArrow.w φ, Functor.map_comp, assoc] congr 1 apply E.hom.naturality } variable (L F) in /-- The cones for `StructuredArrow.proj Y L ⋙ F`, as a functor from `RightExtension L F`. -/ @[simps] def coneAtFunctor (Y : D) : RightExtension L F ⥤ Cone (StructuredArrow.proj Y L ⋙ F) where obj E := E.coneAt Y map {E E'} φ := ConeMorphism.mk (φ.left.app Y) (fun G ↦ by dsimp rw [← CostructuredArrow.w φ] simp) /-- A right extension `E : RightExtension L F` is a pointwise right Kan extension at `Y` when `E.coneAt Y` is a limit cone. -/ def IsPointwiseRightKanExtensionAt (Y : D) := IsLimit (E.coneAt Y) variable {E} in lemma IsPointwiseRightKanExtensionAt.hasPointwiseRightKanExtensionAt {Y : D} (h : E.IsPointwiseRightKanExtensionAt Y) : HasPointwiseRightKanExtensionAt L F Y := ⟨_, h⟩ lemma IsPointwiseRightKanExtensionAt.isIso_hom_app {X : C} (h : E.IsPointwiseRightKanExtensionAt (L.obj X)) [L.Full] [L.Faithful] : IsIso (E.hom.app X) := by simpa using h.isIso_π_app_of_isInitial _ StructuredArrow.mkIdInitial /-- A right extension `E : RightExtension L F` is a pointwise right Kan extension when it is a pointwise right Kan extension at any object. -/ abbrev IsPointwiseRightKanExtension := ∀ (Y : D), E.IsPointwiseRightKanExtensionAt Y variable {E E'} /-- If two right extensions `E` and `E'` are isomorphic, `E` is a pointwise right Kan extension at `Y` iff `E'` is. -/ def isPointwiseRightKanExtensionAtEquivOfIso (e : E ≅ E') (Y : D) : E.IsPointwiseRightKanExtensionAt Y ≃ E'.IsPointwiseRightKanExtensionAt Y := IsLimit.equivIsoLimit ((coneAtFunctor L F Y).mapIso e) /-- If two right extensions `E` and `E'` are isomorphic, `E` is a pointwise right Kan extension iff `E'` is. -/ def isPointwiseRightKanExtensionEquivOfIso (e : E ≅ E') : E.IsPointwiseRightKanExtension ≃ E'.IsPointwiseRightKanExtension where toFun h := fun Y => (isPointwiseRightKanExtensionAtEquivOfIso e Y) (h Y) invFun h := fun Y => (isPointwiseRightKanExtensionAtEquivOfIso e Y).symm (h Y) left_inv h := by aesop right_inv h := by aesop variable (h : E.IsPointwiseRightKanExtension) lemma IsPointwiseRightKanExtension.hasPointwiseRightKanExtension : HasPointwiseRightKanExtension L F := fun Y => (h Y).hasPointwiseRightKanExtensionAt /-- The (unique) morphism to a pointwise right Kan extension. -/ def IsPointwiseRightKanExtension.homTo (G : RightExtension L F) : G ⟶ E := CostructuredArrow.homMk { app := fun Y ↦ (h Y).lift (RightExtension.coneAt G Y) naturality := fun Y₁ Y₂ φ ↦ (h Y₂).hom_ext (fun X ↦ by rw [assoc, (h Y₂).fac (coneAt G Y₂) X] simpa using ((h Y₁).fac (coneAt G Y₁) ((StructuredArrow.map φ).obj X)).symm) } (by ext X simpa using (h (L.obj X)).fac (RightExtension.coneAt G _) (StructuredArrow.mk (𝟙 _)) ) lemma IsPointwiseRightKanExtension.hom_ext (h : E.IsPointwiseRightKanExtension) {G : RightExtension L F} {f₁ f₂ : G ⟶ E} : f₁ = f₂ := by ext Y apply (h Y).hom_ext intro X have eq₁ := congr_app (CostructuredArrow.w f₁) X.right have eq₂ := congr_app (CostructuredArrow.w f₂) X.right dsimp at eq₁ eq₂ ⊢ simp only [assoc, ← NatTrans.naturality_assoc, eq₁, eq₂] /-- A pointwise right Kan extension is universal, i.e. it is a right Kan extension. -/ def IsPointwiseRightKanExtension.isUniversal : E.IsUniversal := IsTerminal.ofUniqueHom h.homTo (fun _ _ => h.hom_ext) lemma IsPointwiseRightKanExtension.isRightKanExtension : E.left.IsRightKanExtension E.hom where nonempty_isUniversal := ⟨h.isUniversal⟩ lemma IsPointwiseRightKanExtension.hasRightKanExtension : HasRightKanExtension L F := have := h.isRightKanExtension HasRightKanExtension.mk E.left E.hom lemma IsPointwiseRightKanExtension.isIso_hom [L.Full] [L.Faithful] : IsIso (E.hom) := have := fun X => (h (L.obj X)).isIso_hom_app NatIso.isIso_of_isIso_app .. end RightExtension section variable [HasPointwiseLeftKanExtension L F] /-- The constructed pointwise left Kan extension when `HasPointwiseLeftKanExtension L F` holds. -/ @[simps] noncomputable def pointwiseLeftKanExtension : D ⥤ H where obj Y := colimit (CostructuredArrow.proj L Y ⋙ F) map {Y₁ Y₂} f := colimit.desc (CostructuredArrow.proj L Y₁ ⋙ F) (Cocone.mk (colimit (CostructuredArrow.proj L Y₂ ⋙ F)) { app := fun g => colimit.ι (CostructuredArrow.proj L Y₂ ⋙ F) ((CostructuredArrow.map f).obj g) naturality := fun g₁ g₂ φ => by simpa using colimit.w (CostructuredArrow.proj L Y₂ ⋙ F) ((CostructuredArrow.map f).map φ) }) map_id Y := colimit.hom_ext (fun j => by dsimp simp only [colimit.ι_desc, comp_id] congr apply CostructuredArrow.map_id) map_comp {Y₁ Y₂ Y₃} f f' := colimit.hom_ext (fun j => by dsimp simp only [colimit.ι_desc, colimit.ι_desc_assoc, comp_obj, CostructuredArrow.proj_obj] congr 1 apply CostructuredArrow.map_comp) /-- The unit of the constructed pointwise left Kan extension when `HasPointwiseLeftKanExtension L F` holds. -/ @[simps] noncomputable def pointwiseLeftKanExtensionUnit : F ⟶ L ⋙ pointwiseLeftKanExtension L F where app X := colimit.ι (CostructuredArrow.proj L (L.obj X) ⋙ F) (CostructuredArrow.mk (𝟙 (L.obj X))) naturality {X₁ X₂} f := by simp only [comp_obj, pointwiseLeftKanExtension_obj, comp_map, pointwiseLeftKanExtension_map, colimit.ι_desc, CostructuredArrow.map_mk] rw [id_comp] let φ : CostructuredArrow.mk (L.map f) ⟶ CostructuredArrow.mk (𝟙 (L.obj X₂)) := CostructuredArrow.homMk f exact colimit.w (CostructuredArrow.proj L (L.obj X₂) ⋙ F) φ /-- The functor `pointwiseLeftKanExtension L F` is a pointwise left Kan extension of `F` along `L`. -/ noncomputable def pointwiseLeftKanExtensionIsPointwiseLeftKanExtension : (LeftExtension.mk _ (pointwiseLeftKanExtensionUnit L F)).IsPointwiseLeftKanExtension := fun X => IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (Iso.refl _) (fun j => by dsimp simp only [comp_id, colimit.ι_desc, CostructuredArrow.map_mk] congr 1 rw [id_comp, ← CostructuredArrow.eq_mk])) /-- The functor `pointwiseLeftKanExtension L F` is a left Kan extension of `F` along `L`. -/ noncomputable def pointwiseLeftKanExtensionIsUniversal : (LeftExtension.mk _ (pointwiseLeftKanExtensionUnit L F)).IsUniversal := (pointwiseLeftKanExtensionIsPointwiseLeftKanExtension L F).isUniversal instance : (pointwiseLeftKanExtension L F).IsLeftKanExtension (pointwiseLeftKanExtensionUnit L F) where nonempty_isUniversal := ⟨pointwiseLeftKanExtensionIsUniversal L F⟩ instance : HasLeftKanExtension L F := HasLeftKanExtension.mk _ (pointwiseLeftKanExtensionUnit L F) variable {F L} /-- If `F` admits a pointwise left Kan extension along `L`, then any left Kan extension of `F` along `L` is a pointwise left Kan extension. -/ noncomputable def isPointwiseLeftKanExtensionOfIsLeftKanExtension (F' : D ⥤ H) (α : F ⟶ L ⋙ F') [F'.IsLeftKanExtension α] : (LeftExtension.mk _ α).IsPointwiseLeftKanExtension := LeftExtension.isPointwiseLeftKanExtensionEquivOfIso (IsColimit.coconePointUniqueUpToIso (pointwiseLeftKanExtensionIsUniversal L F) (F'.isUniversalOfIsLeftKanExtension α)) (pointwiseLeftKanExtensionIsPointwiseLeftKanExtension L F) end section variable [HasPointwiseRightKanExtension L F] /-- The constructed pointwise right Kan extension when `HasPointwiseRightKanExtension L F` holds. -/ @[simps] noncomputable def pointwiseRightKanExtension : D ⥤ H where obj Y := limit (StructuredArrow.proj Y L ⋙ F) map {Y₁ Y₂} f := limit.lift (StructuredArrow.proj Y₂ L ⋙ F) (Cone.mk (limit (StructuredArrow.proj Y₁ L ⋙ F)) { app := fun g ↦ limit.π (StructuredArrow.proj Y₁ L ⋙ F) ((StructuredArrow.map f).obj g) naturality := fun g₁ g₂ φ ↦ by simpa using (limit.w (StructuredArrow.proj Y₁ L ⋙ F) ((StructuredArrow.map f).map φ)).symm }) map_id Y := limit.hom_ext (fun j => by dsimp simp only [limit.lift_π, id_comp] congr apply StructuredArrow.map_id) map_comp {Y₁ Y₂ Y₃} f f' := limit.hom_ext (fun j => by dsimp simp only [limit.lift_π, assoc] congr 1 apply StructuredArrow.map_comp) /-- The counit of the constructed pointwise right Kan extension when `HasPointwiseRightKanExtension L F` holds. -/ @[simps] noncomputable def pointwiseRightKanExtensionCounit : L ⋙ pointwiseRightKanExtension L F ⟶ F where app X := limit.π (StructuredArrow.proj (L.obj X) L ⋙ F) (StructuredArrow.mk (𝟙 (L.obj X))) naturality {X₁ X₂} f := by simp only [comp_obj, pointwiseRightKanExtension_obj, comp_map, pointwiseRightKanExtension_map, limit.lift_π, StructuredArrow.map_mk] rw [comp_id] let φ : StructuredArrow.mk (𝟙 (L.obj X₁)) ⟶ StructuredArrow.mk (L.map f) := StructuredArrow.homMk f exact (limit.w (StructuredArrow.proj (L.obj X₁) L ⋙ F) φ).symm /-- The functor `pointwiseRightKanExtension L F` is a pointwise right Kan extension of `F` along `L`. -/ noncomputable def pointwiseRightKanExtensionIsPointwiseRightKanExtension : (RightExtension.mk _ (pointwiseRightKanExtensionCounit L F)).IsPointwiseRightKanExtension := fun X => IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext (Iso.refl _) (fun j => by dsimp simp only [limit.lift_π, StructuredArrow.map_mk, id_comp] congr rw [comp_id, ← StructuredArrow.eq_mk])) /-- The functor `pointwiseRightKanExtension L F` is a right Kan extension of `F` along `L`. -/ noncomputable def pointwiseRightKanExtensionIsUniversal : (RightExtension.mk _ (pointwiseRightKanExtensionCounit L F)).IsUniversal := (pointwiseRightKanExtensionIsPointwiseRightKanExtension L F).isUniversal instance : (pointwiseRightKanExtension L F).IsRightKanExtension (pointwiseRightKanExtensionCounit L F) where nonempty_isUniversal := ⟨pointwiseRightKanExtensionIsUniversal L F⟩ instance : HasRightKanExtension L F := HasRightKanExtension.mk _ (pointwiseRightKanExtensionCounit L F) variable {F L} /-- If `F` admits a pointwise right Kan extension along `L`, then any right Kan extension of `F` along `L` is a pointwise right Kan extension. -/ noncomputable def isPointwiseRightKanExtensionOfIsRightKanExtension (F' : D ⥤ H) (α : L ⋙ F' ⟶ F) [F'.IsRightKanExtension α] : (RightExtension.mk _ α).IsPointwiseRightKanExtension := RightExtension.isPointwiseRightKanExtensionEquivOfIso (IsLimit.conePointUniqueUpToIso (pointwiseRightKanExtensionIsUniversal L F) (F'.isUniversalOfIsRightKanExtension α)) (pointwiseRightKanExtensionIsPointwiseRightKanExtension L F) end end Functor end CategoryTheory
CategoryTheory\Galois\Basic.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.FintypeCat import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Limits.FintypeCat import Mathlib.CategoryTheory.Limits.MonoCoprod import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.Types import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory import Mathlib.CategoryTheory.Limits.Shapes.Diagonal import Mathlib.CategoryTheory.SingleObj import Mathlib.Data.Finite.Card /-! # Definition and basic properties of Galois categories We define the notion of a Galois category and a fiber functor as in SGA1, following the definitions in Lenstras notes (see below for a reference). ## Main definitions * `PreGaloisCategory` : defining properties of Galois categories not involving a fiber functor * `FiberFunctor` : a fiber functor from a `PreGaloisCategory` to `FintypeCat` * `GaloisCategory` : a `PreGaloisCategory` that admits a `FiberFunctor` * `IsConnected` : an object of a category is connected if it is not initial and does not have non-trivial subobjects ## Implementation details We mostly follow Def 3.1 in Lenstras notes. In axiom (G3) we omit the factorisation of morphisms in epimorphisms and monomorphisms as this is not needed for the proof of the fundamental theorem on Galois categories (and then follows from it). ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ v₁ v₂ w namespace CategoryTheory open Limits Functor /-! A category `C` is a PreGalois category if it satisfies all properties of a Galois category in the sense of SGA1 that do not involve a fiber functor. A Galois category should furthermore admit a fiber functor. The only difference between `[PreGaloisCategory C] (F : C ⥤ FintypeCat) [FiberFunctor F]` and `[GaloisCategory C]` is that the former fixes one fiber functor `F`. -/ /-- Definition of a (Pre)Galois category. Lenstra, Def 3.1, (G1)-(G3) -/ class PreGaloisCategory (C : Type u₁) [Category.{u₂, u₁} C] : Prop where /-- `C` has a terminal object (G1). -/ hasTerminal : HasTerminal C := by infer_instance /-- `C` has pullbacks (G1). -/ hasPullbacks : HasPullbacks C := by infer_instance /-- `C` has finite coproducts (G2). -/ hasFiniteCoproducts : HasFiniteCoproducts C := by infer_instance /-- `C` has quotients by finite groups (G2). -/ hasQuotientsByFiniteGroups (G : Type u₂) [Group G] [Finite G] : HasColimitsOfShape (SingleObj G) C := by infer_instance /-- Every monomorphism in `C` induces an isomorphism on a direct summand (G3). -/ monoInducesIsoOnDirectSummand {X Y : C} (i : X ⟶ Y) [Mono i] : ∃ (Z : C) (u : Z ⟶ Y), Nonempty (IsColimit (BinaryCofan.mk i u)) namespace PreGaloisCategory /-- Definition of a fiber functor from a Galois category. Lenstra, Def 3.1, (G4)-(G6) -/ class FiberFunctor {C : Type u₁} [Category.{u₂, u₁} C] [PreGaloisCategory C] (F : C ⥤ FintypeCat.{w}) where /-- `F` preserves terminal objects (G4). -/ preservesTerminalObjects : PreservesLimitsOfShape (CategoryTheory.Discrete PEmpty.{1}) F := by infer_instance /-- `F` preserves pullbacks (G4). -/ preservesPullbacks : PreservesLimitsOfShape WalkingCospan F := by infer_instance /-- `F` preserves finite coproducts (G5). -/ preservesFiniteCoproducts : PreservesFiniteCoproducts F := by infer_instance /-- `F` preserves epimorphisms (G5). -/ preservesEpis : Functor.PreservesEpimorphisms F := by infer_instance /-- `F` preserves quotients by finite groups (G5). -/ preservesQuotientsByFiniteGroups (G : Type u₂) [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) F := by infer_instance /-- `F` reflects isomorphisms (G6). -/ reflectsIsos : F.ReflectsIsomorphisms := by infer_instance /-- An object of a category `C` is connected if it is not initial and has no non-trivial subobjects. Lenstra, 3.12. -/ class IsConnected {C : Type u₁} [Category.{u₂, u₁} C] (X : C) : Prop where /-- `X` is not an initial object. -/ notInitial : IsInitial X → False /-- `X` has no non-trivial subobjects. -/ noTrivialComponent (Y : C) (i : Y ⟶ X) [Mono i] : (IsInitial Y → False) → IsIso i /-- A functor is said to preserve connectedness if whenever `X : C` is connected, also `F.obj X` is connected. -/ class PreservesIsConnected {C : Type u₁} [Category.{u₂, u₁} C] {D : Type v₁} [Category.{v₂, v₁} D] (F : C ⥤ D) : Prop where /-- `F.obj X` is connected if `X` is connected. -/ preserves : ∀ {X : C} [IsConnected X], IsConnected (F.obj X) section variable {C : Type u₁} [Category.{u₂, u₁} C] [PreGaloisCategory C] attribute [instance] hasTerminal hasPullbacks hasFiniteCoproducts hasQuotientsByFiniteGroups instance : HasFiniteLimits C := hasFiniteLimits_of_hasTerminal_and_pullbacks instance : HasBinaryProducts C := hasBinaryProducts_of_hasTerminal_and_pullbacks C instance : HasEqualizers C := hasEqualizers_of_hasPullbacks_and_binary_products end namespace FiberFunctor variable {C : Type u₁} [Category.{u₂, u₁} C] {F : C ⥤ FintypeCat.{w}} [PreGaloisCategory C] [FiberFunctor F] attribute [instance] preservesTerminalObjects preservesPullbacks preservesEpis preservesFiniteCoproducts reflectsIsos preservesQuotientsByFiniteGroups noncomputable instance : ReflectsLimitsOfShape (Discrete PEmpty.{1}) F := reflectsLimitsOfShapeOfReflectsIsomorphisms noncomputable instance : ReflectsColimitsOfShape (Discrete PEmpty.{1}) F := reflectsColimitsOfShapeOfReflectsIsomorphisms noncomputable instance : PreservesFiniteLimits F := preservesFiniteLimitsOfPreservesTerminalAndPullbacks F /-- Fiber functors reflect monomorphisms. -/ instance : ReflectsMonomorphisms F := ReflectsMonomorphisms.mk <| by intro X Y f _ haveI : IsIso (pullback.fst (F.map f) (F.map f)) := fst_iso_of_mono_eq (F.map f) haveI : IsIso (F.map (pullback.fst f f)) := by rw [← PreservesPullback.iso_hom_fst] exact IsIso.comp_isIso haveI : IsIso (pullback.fst f f) := isIso_of_reflects_iso (pullback.fst _ _) F exact (pullback.diagonal_isKernelPair f).mono_of_isIso_fst /-- Fiber functors are faithful. -/ instance : F.Faithful where map_injective {X Y} f g h := by haveI : IsIso (equalizer.ι (F.map f) (F.map g)) := equalizer.ι_of_eq h haveI : IsIso (F.map (equalizer.ι f g)) := by rw [← equalizerComparison_comp_π f g F] exact IsIso.comp_isIso haveI : IsIso (equalizer.ι f g) := isIso_of_reflects_iso _ F exact eq_of_epi_equalizer end FiberFunctor variable {C : Type u₁} [Category.{u₂, u₁} C] (F : C ⥤ FintypeCat.{w}) /-- The canonical action of `Aut F` on the fiber of each object. -/ instance (X : C) : MulAction (Aut F) (F.obj X) where smul σ x := σ.hom.app X x one_smul _ := rfl mul_smul _ _ _ := rfl lemma mulAction_def {X : C} (σ : Aut F) (x : F.obj X) : σ • x = σ.hom.app X x := rfl /-- An object that is neither initial or connected has a non-trivial subobject. -/ lemma has_non_trivial_subobject_of_not_isConnected_of_not_initial (X : C) (hc : ¬ IsConnected X) (hi : IsInitial X → False) : ∃ (Y : C) (v : Y ⟶ X), (IsInitial Y → False) ∧ Mono v ∧ (¬ IsIso v) := by contrapose! hc exact ⟨hi, fun Y i hm hni ↦ hc Y i hni hm⟩ /-- The cardinality of the fiber is preserved under isomorphisms. -/ lemma card_fiber_eq_of_iso {X Y : C} (i : X ≅ Y) : Nat.card (F.obj X) = Nat.card (F.obj Y) := by have e : F.obj X ≃ F.obj Y := Iso.toEquiv (mapIso (F ⋙ FintypeCat.incl) i) exact Nat.card_eq_of_bijective e (Equiv.bijective e) variable [PreGaloisCategory C] [FiberFunctor F] /-- An object is initial if and only if its fiber is empty. -/ lemma initial_iff_fiber_empty (X : C) : Nonempty (IsInitial X) ↔ IsEmpty (F.obj X) := by rw [(IsInitial.isInitialIffObj F X).nonempty_congr] haveI : PreservesFiniteColimits (forget FintypeCat) := by show PreservesFiniteColimits FintypeCat.incl infer_instance haveI : ReflectsColimit (Functor.empty.{0} _) (forget FintypeCat) := by show ReflectsColimit (Functor.empty.{0} _) FintypeCat.incl infer_instance exact Concrete.initial_iff_empty_of_preserves_of_reflects (F.obj X) /-- An object is not initial if and only if its fiber is nonempty. -/ lemma not_initial_iff_fiber_nonempty (X : C) : (IsInitial X → False) ↔ Nonempty (F.obj X) := by rw [← not_isEmpty_iff] refine ⟨fun h he ↦ ?_, fun h hin ↦ h <| (initial_iff_fiber_empty F X).mp ⟨hin⟩⟩ exact Nonempty.elim ((initial_iff_fiber_empty F X).mpr he) h /-- An object whose fiber is inhabited is not initial. -/ lemma not_initial_of_inhabited {X : C} (x : F.obj X) (h : IsInitial X) : False := ((initial_iff_fiber_empty F X).mp ⟨h⟩).false x /-- The fiber of a connected object is nonempty. -/ instance nonempty_fiber_of_isConnected (X : C) [IsConnected X] : Nonempty (F.obj X) := by by_contra h have ⟨hin⟩ : Nonempty (IsInitial X) := (initial_iff_fiber_empty F X).mpr (not_nonempty_iff.mp h) exact IsConnected.notInitial hin /-- The fiber of the equalizer of `f g : X ⟶ Y` is equivalent to the set of agreement of `f` and `g`. -/ noncomputable def fiberEqualizerEquiv {X Y : C} (f g : X ⟶ Y) : F.obj (equalizer f g) ≃ { x : F.obj X // F.map f x = F.map g x } := (PreservesEqualizer.iso (F ⋙ FintypeCat.incl) f g ≪≫ Types.equalizerIso (F.map f) (F.map g)).toEquiv @[simp] lemma fiberEqualizerEquiv_symm_ι_apply {X Y : C} {f g : X ⟶ Y} (x : F.obj X) (h : F.map f x = F.map g x) : F.map (equalizer.ι f g) ((fiberEqualizerEquiv F f g).symm ⟨x, h⟩) = x := by simp [fiberEqualizerEquiv] change ((Types.equalizerIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (equalizer.ι f g)) _ = _ erw [PreservesEqualizer.iso_inv_ι, Types.equalizerIso_inv_comp_ι] /-- The fiber of the pullback is the fiber product of the fibers. -/ noncomputable def fiberPullbackEquiv {X A B : C} (f : A ⟶ X) (g : B ⟶ X) : F.obj (pullback f g) ≃ { p : F.obj A × F.obj B // F.map f p.1 = F.map g p.2 } := (PreservesPullback.iso (F ⋙ FintypeCat.incl) f g ≪≫ Types.pullbackIsoPullback (F.map f) (F.map g)).toEquiv @[simp] lemma fiberPullbackEquiv_symm_fst_apply {X A B : C} {f : A ⟶ X} {g : B ⟶ X} (a : F.obj A) (b : F.obj B) (h : F.map f a = F.map g b) : F.map (pullback.fst f g) ((fiberPullbackEquiv F f g).symm ⟨(a, b), h⟩) = a := by simp [fiberPullbackEquiv] change ((Types.pullbackIsoPullback _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (pullback.fst f g)) _ = _ erw [PreservesPullback.iso_inv_fst, Types.pullbackIsoPullback_inv_fst] @[simp] lemma fiberPullbackEquiv_symm_snd_apply {X A B : C} {f : A ⟶ X} {g : B ⟶ X} (a : F.obj A) (b : F.obj B) (h : F.map f a = F.map g b) : F.map (pullback.snd f g) ((fiberPullbackEquiv F f g).symm ⟨(a, b), h⟩) = b := by simp [fiberPullbackEquiv] change ((Types.pullbackIsoPullback _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (pullback.snd f g)) _ = _ erw [PreservesPullback.iso_inv_snd, Types.pullbackIsoPullback_inv_snd] /-- The fiber of the binary product is the binary product of the fibers. -/ noncomputable def fiberBinaryProductEquiv (X Y : C) : F.obj (X ⨯ Y) ≃ F.obj X × F.obj Y := (PreservesLimitPair.iso (F ⋙ FintypeCat.incl) X Y ≪≫ Types.binaryProductIso (F.obj X) (F.obj Y)).toEquiv @[simp] lemma fiberBinaryProductEquiv_symm_fst_apply {X Y : C} (x : F.obj X) (y : F.obj Y) : F.map prod.fst ((fiberBinaryProductEquiv F X Y).symm (x, y)) = x := by simp only [fiberBinaryProductEquiv, comp_obj, FintypeCat.incl_obj, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun] change ((Types.binaryProductIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map prod.fst) _ = _ erw [PreservesLimitPair.iso_inv_fst, Types.binaryProductIso_inv_comp_fst] @[simp] lemma fiberBinaryProductEquiv_symm_snd_apply {X Y : C} (x : F.obj X) (y : F.obj Y) : F.map prod.snd ((fiberBinaryProductEquiv F X Y).symm (x, y)) = y := by simp only [fiberBinaryProductEquiv, comp_obj, FintypeCat.incl_obj, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun] change ((Types.binaryProductIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map prod.snd) _ = _ erw [PreservesLimitPair.iso_inv_snd, Types.binaryProductIso_inv_comp_snd] /-- The evaluation map is injective for connected objects. -/ lemma evaluation_injective_of_isConnected (A X : C) [IsConnected A] (a : F.obj A) : Function.Injective (fun (f : A ⟶ X) ↦ F.map f a) := by intro f g (h : F.map f a = F.map g a) haveI : IsIso (equalizer.ι f g) := by apply IsConnected.noTrivialComponent _ (equalizer.ι f g) exact not_initial_of_inhabited F ((fiberEqualizerEquiv F f g).symm ⟨a, h⟩) exact eq_of_epi_equalizer /-- The evaluation map on automorphisms is injective for connected objects. -/ lemma evaluation_aut_injective_of_isConnected (A : C) [IsConnected A] (a : F.obj A) : Function.Injective (fun f : Aut A ↦ F.map (f.hom) a) := by show Function.Injective ((fun f : A ⟶ A ↦ F.map f a) ∘ (fun f : Aut A ↦ f.hom)) apply Function.Injective.comp · exact evaluation_injective_of_isConnected F A A a · exact @Aut.ext _ _ A /-- A morphism from an object `X` with non-empty fiber to a connected object `A` is an epimorphism. -/ lemma epi_of_nonempty_of_isConnected {X A : C} [IsConnected A] [h : Nonempty (F.obj X)] (f : X ⟶ A) : Epi f := Epi.mk <| fun {Z} u v huv ↦ by apply evaluation_injective_of_isConnected F A Z (F.map f (Classical.arbitrary _)) simpa using congr_fun (F.congr_map huv) _ /-- An epimorphism induces a surjective map on fibers. -/ lemma surjective_on_fiber_of_epi {X Y : C} (f : X ⟶ Y) [Epi f] : Function.Surjective (F.map f) := surjective_of_epi (FintypeCat.incl.map (F.map f)) /- A morphism from an object with non-empty fiber to a connected object is surjective on fibers. -/ lemma surjective_of_nonempty_fiber_of_isConnected {X A : C} [Nonempty (F.obj X)] [IsConnected A] (f : X ⟶ A) : Function.Surjective (F.map f) := by have : Epi f := epi_of_nonempty_of_isConnected F f exact surjective_on_fiber_of_epi F f section CardFiber open ConcreteCategory /-- A mono between objects with equally sized fibers is an iso. -/ lemma isIso_of_mono_of_eq_card_fiber {X Y : C} (f : X ⟶ Y) [Mono f] (h : Nat.card (F.obj X) = Nat.card (F.obj Y)) : IsIso f := by have : IsIso (F.map f) := by apply (ConcreteCategory.isIso_iff_bijective (F.map f)).mpr apply (Fintype.bijective_iff_injective_and_card (F.map f)).mpr refine ⟨injective_of_mono_of_preservesPullback (F.map f), ?_⟩ simp only [← Nat.card_eq_fintype_card, h] exact isIso_of_reflects_iso f F /-- Along a mono that is not an iso, the cardinality of the fiber strictly increases. -/ lemma lt_card_fiber_of_mono_of_notIso {X Y : C} (f : X ⟶ Y) [Mono f] (h : ¬ IsIso f) : Nat.card (F.obj X) < Nat.card (F.obj Y) := by by_contra hlt apply h apply isIso_of_mono_of_eq_card_fiber F f simp only [gt_iff_lt, not_lt] at hlt exact Nat.le_antisymm (Finite.card_le_of_injective (F.map f) (injective_of_mono_of_preservesPullback (F.map f))) hlt /-- The cardinality of the fiber of a not-initial object is non-zero. -/ lemma non_zero_card_fiber_of_not_initial (X : C) (h : IsInitial X → False) : Nat.card (F.obj X) ≠ 0 := by intro hzero refine Nonempty.elim ?_ h rw [initial_iff_fiber_empty F] exact Finite.card_eq_zero_iff.mp hzero /-- The cardinality of the fiber of a coproduct is the sum of the cardinalities of the fibers. -/ lemma card_fiber_coprod_eq_sum (X Y : C) : Nat.card (F.obj (X ⨿ Y)) = Nat.card (F.obj X) + Nat.card (F.obj Y) := by let e : F.obj (X ⨿ Y) ≃ F.obj X ⊕ F.obj Y := Iso.toEquiv <| (PreservesColimitPair.iso (F ⋙ FintypeCat.incl) X Y).symm.trans <| Types.binaryCoproductIso (FintypeCat.incl.obj (F.obj X)) (FintypeCat.incl.obj (F.obj Y)) rw [← Nat.card_sum] exact Nat.card_eq_of_bijective e.toFun (Equiv.bijective e) /-- The cardinality of morphisms `A ⟶ X` is smaller than the cardinality of the fiber of the target if the source is connected. -/ lemma card_hom_le_card_fiber_of_connected (A X : C) [IsConnected A] : Nat.card (A ⟶ X) ≤ Nat.card (F.obj X) := by apply Nat.card_le_card_of_injective exact evaluation_injective_of_isConnected F A X (Classical.arbitrary _) /-- If `A` is connected, the cardinality of `Aut A` is smaller than the cardinality of the fiber of `A`. -/ lemma card_aut_le_card_fiber_of_connected (A : C) [IsConnected A] : Nat.card (Aut A) ≤ Nat.card (F.obj A) := by have h : Nonempty (F.obj A) := inferInstance obtain ⟨a⟩ := h apply Nat.card_le_card_of_injective exact evaluation_aut_injective_of_isConnected _ _ a end CardFiber end PreGaloisCategory /-- A `PreGaloisCategory` is a `GaloisCategory` if it admits a fiber functor. -/ class GaloisCategory (C : Type u₁) [Category.{u₂, u₁} C] extends PreGaloisCategory C : Prop where hasFiberFunctor : ∃ F : C ⥤ FintypeCat.{u₂}, Nonempty (PreGaloisCategory.FiberFunctor F) namespace PreGaloisCategory variable (C : Type u₁) [Category.{u₂, u₁} C] [GaloisCategory C] /-- Arbitrarily choose a fiber functor for a Galois category using choice. -/ noncomputable def GaloisCategory.getFiberFunctor : C ⥤ FintypeCat.{u₂} := Classical.choose <| @GaloisCategory.hasFiberFunctor C _ _ /-- The arbitrarily chosen fiber functor `GaloisCategory.getFiberFunctor` is a fiber functor. -/ noncomputable instance : FiberFunctor (GaloisCategory.getFiberFunctor C) := Classical.choice <| Classical.choose_spec (@GaloisCategory.hasFiberFunctor C _ _) variable {C} /-- In a `GaloisCategory` the set of morphisms out of a connected object is finite. -/ instance (A X : C) [IsConnected A] : Finite (A ⟶ X) := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A apply Finite.of_injective (fun f ↦ F.map f a) exact evaluation_injective_of_isConnected F A X a /-- In a `GaloisCategory` the set of automorphism of a connected object is finite. -/ instance (A : C) [IsConnected A] : Finite (Aut A) := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A apply Finite.of_injective (fun f ↦ F.map f.hom a) exact evaluation_aut_injective_of_isConnected F A a /-- Coproduct inclusions are monic in Galois categories. -/ instance : MonoCoprod C := by let F := GaloisCategory.getFiberFunctor C exact MonoCoprod.monoCoprod_of_preservesCoprod_of_reflectsMono F end PreGaloisCategory end CategoryTheory
CategoryTheory\Galois\Decomposition.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Galois.GaloisObjects import Mathlib.CategoryTheory.Limits.Shapes.CombinedProducts /-! # Decomposition of objects into connected components and applications We show that in a Galois category every object is the (finite) coproduct of connected subobjects. This has many useful corollaries, in particular that the fiber of every object is represented by a Galois object. ## Main results * `has_decomp_connected_components`: Every object is the sum of its (finitely many) connected components. * `fiber_in_connected_component`: An element of the fiber of `X` lies in the fiber of some connected component. * `connected_component_unique`: Up to isomorphism, for each element `x` in the fiber of `X` there is only one connected component whose fiber contains `x`. * `exists_galois_representative`: The fiber of `X` is represented by some Galois object `A`: Evaluation at some `a` in the fiber of `A` induces a bijection `A ⟶ X` to `F.obj X`. ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ w namespace CategoryTheory open Limits Functor variable {C : Type u₁} [Category.{u₂} C] namespace PreGaloisCategory variable [GaloisCategory C] section Decomposition /-! ### Decomposition in connected components To show that an object `X` of a Galois category admits a decomposition into connected objects, we proceed by induction on the cardinality of the fiber under an arbitrary fiber functor. If `X` is connected, there is nothing to show. If not, we can write `X` as the sum of two non-trivial subobjects which have strictly smaller fiber and conclude by the induction hypothesis. -/ /-- The trivial case if `X` is connected. -/ private lemma has_decomp_connected_components_aux_conn (X : C) [IsConnected X] : ∃ (ι : Type) (f : ι → C) (g : (i : ι) → (f i) ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by refine ⟨Unit, fun _ ↦ X, fun _ ↦ 𝟙 X, mkCofanColimit _ (fun s ↦ s.inj ()), ?_⟩ exact ⟨fun _ ↦ inferInstance, inferInstance⟩ /-- The trivial case if `X` is initial. -/ private lemma has_decomp_connected_components_aux_initial (X : C) (h : IsInitial X) : ∃ (ι : Type) (f : ι → C) (g : (i : ι) → (f i) ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by refine ⟨Empty, fun _ ↦ X, fun _ ↦ 𝟙 X, ?_⟩ use mkCofanColimit _ (fun s ↦ IsInitial.to h s.pt) (fun s ↦ by aesop) (fun s m _ ↦ IsInitial.hom_ext h m _) exact ⟨by simp only [IsEmpty.forall_iff], inferInstance⟩ /- Show decomposition by inducting on `Nat.card (F.obj X)`. -/ private lemma has_decomp_connected_components_aux (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] (n : ℕ) : ∀ (X : C), n = Nat.card (F.obj X) → ∃ (ι : Type) (f : ι → C) (g : (i : ι) → (f i) ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by induction' n using Nat.strongRecOn with n hi intro X hn by_cases h : IsConnected X · exact has_decomp_connected_components_aux_conn X by_cases nhi : IsInitial X → False · obtain ⟨Y, v, hni, hvmono, hvnoiso⟩ := has_non_trivial_subobject_of_not_isConnected_of_not_initial X h nhi obtain ⟨Z, u, ⟨c⟩⟩ := PreGaloisCategory.monoInducesIsoOnDirectSummand v let t : ColimitCocone (pair Y Z) := { cocone := BinaryCofan.mk v u, isColimit := c } have hn1 : Nat.card (F.obj Y) < n := by rw [hn] exact lt_card_fiber_of_mono_of_notIso F v hvnoiso have i : X ≅ Y ⨿ Z := (colimit.isoColimitCocone t).symm have hnn : Nat.card (F.obj X) = Nat.card (F.obj Y) + Nat.card (F.obj Z) := by rw [card_fiber_eq_of_iso F i] exact card_fiber_coprod_eq_sum F Y Z have hn2 : Nat.card (F.obj Z) < n := by rw [hn, hnn, lt_add_iff_pos_left] exact Nat.pos_of_ne_zero (non_zero_card_fiber_of_not_initial F Y hni) let ⟨ι₁, f₁, g₁, hc₁, hf₁, he₁⟩ := hi (Nat.card (F.obj Y)) hn1 Y rfl let ⟨ι₂, f₂, g₂, hc₂, hf₂, he₂⟩ := hi (Nat.card (F.obj Z)) hn2 Z rfl refine ⟨ι₁ ⊕ ι₂, Sum.elim f₁ f₂, Cofan.combPairHoms (Cofan.mk Y g₁) (Cofan.mk Z g₂) (BinaryCofan.mk v u), ?_⟩ use Cofan.combPairIsColimit hc₁ hc₂ c refine ⟨fun i ↦ ?_, inferInstance⟩ cases i · exact hf₁ _ · exact hf₂ _ · simp only [not_forall, not_false_eq_true] at nhi obtain ⟨hi⟩ := nhi exact has_decomp_connected_components_aux_initial X hi /-- In a Galois category, every object is the sum of connected objects. -/ theorem has_decomp_connected_components (X : C) : ∃ (ι : Type) (f : ι → C) (g : (i : ι) → f i ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by let F := GaloisCategory.getFiberFunctor C exact has_decomp_connected_components_aux F (Nat.card <| F.obj X) X rfl /-- In a Galois category, every object is the sum of connected objects. -/ theorem has_decomp_connected_components' (X : C) : ∃ (ι : Type) (_ : Finite ι) (f : ι → C) (_ : ∐ f ≅ X), ∀ i, IsConnected (f i) := by obtain ⟨ι, f, g, hl, hc, hf⟩ := has_decomp_connected_components X exact ⟨ι, hf, f, colimit.isoColimitCocone ⟨Cofan.mk X g, hl⟩, hc⟩ variable (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] /-- Every element in the fiber of `X` lies in some connected component of `X`. -/ lemma fiber_in_connected_component (X : C) (x : F.obj X) : ∃ (Y : C) (i : Y ⟶ X) (y : F.obj Y), F.map i y = x ∧ IsConnected Y ∧ Mono i := by obtain ⟨ι, f, g, hl, hc, he⟩ := has_decomp_connected_components X have : Fintype ι := Fintype.ofFinite ι let s : Cocone (Discrete.functor f ⋙ F) := F.mapCocone (Cofan.mk X g) let s' : IsColimit s := isColimitOfPreserves F hl obtain ⟨⟨j⟩, z, h⟩ := Concrete.isColimit_exists_rep _ s' x refine ⟨f j, g j, z, ⟨?_, hc j, MonoCoprod.mono_inj _ (Cofan.mk X g) hl j⟩⟩ subst h rfl /-- Up to isomorphism an element of the fiber of `X` only lies in one connected component. -/ lemma connected_component_unique {X A B : C} [IsConnected A] [IsConnected B] (a : F.obj A) (b : F.obj B) (i : A ⟶ X) (j : B ⟶ X) (h : F.map i a = F.map j b) [Mono i] [Mono j] : ∃ (f : A ≅ B), F.map f.hom a = b := by /- We consider the fiber product of A and B over X. This is a non-empty (because of `h`) subobject of `A` and `B` and hence isomorphic to `A` and `B` by connectedness. -/ let Y : C := pullback i j let u : Y ⟶ A := pullback.fst i j let v : Y ⟶ B := pullback.snd i j let G := F ⋙ FintypeCat.incl let e : F.obj Y ≃ { p : F.obj A × F.obj B // F.map i p.1 = F.map j p.2 } := fiberPullbackEquiv F i j let y : F.obj Y := e.symm ⟨(a, b), h⟩ have hn : IsInitial Y → False := not_initial_of_inhabited F y have : IsIso u := IsConnected.noTrivialComponent Y u hn have : IsIso v := IsConnected.noTrivialComponent Y v hn use (asIso u).symm ≪≫ asIso v have hu : G.map u y = a := by simp only [y, e, ← PreservesPullback.iso_hom_fst G, fiberPullbackEquiv, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun, types_comp_apply, inv_hom_id_apply] erw [Types.pullbackIsoPullback_inv_fst_apply (F.map i) (F.map j)] have hv : G.map v y = b := by simp only [y, e, ← PreservesPullback.iso_hom_snd G, fiberPullbackEquiv, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun, types_comp_apply, inv_hom_id_apply] erw [Types.pullbackIsoPullback_inv_snd_apply (F.map i) (F.map j)] rw [← hu, ← hv] show (F.toPrefunctor.map u ≫ F.toPrefunctor.map _) y = F.toPrefunctor.map v y simp only [← F.map_comp, Iso.trans_hom, Iso.symm_hom, asIso_inv, asIso_hom, IsIso.hom_inv_id_assoc] end Decomposition section GaloisRep /-! ### Galois representative of fiber If `X` is any object, then its fiber is represented by some Galois object: There exists a Galois object `A` and an element `a` in the fiber of `A` such that the evaluation at `a` from `A ⟶ X` to `F.obj X` is bijective. To show this we consider the product `∏ᶜ (fun _ : F.obj X ↦ X)` and let `A` be the connected component whose fiber contains the element `a` in the fiber of the self product that has at each index `x : F.obj X` the element `x`. This `A` is Galois and evaluation at `a` is bijective. Reference: [lenstraGSchemes, 3.14] -/ variable (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] section GaloisRepAux variable (X : C) /-- The self product of `X` indexed by its fiber. -/ @[simp] private noncomputable def selfProd : C := ∏ᶜ (fun _ : F.obj X ↦ X) /-- For `g : F.obj X → F.obj X`, this is the element in the fiber of the self product, which has at index `x : F.obj X` the element `g x`. -/ private noncomputable def mkSelfProdFib : F.obj (selfProd F X) := (PreservesProduct.iso F _).inv ((Concrete.productEquiv (fun _ : F.obj X ↦ F.obj X)).symm id) @[simp] private lemma mkSelfProdFib_map_π (t : F.obj X) : F.map (Pi.π _ t) (mkSelfProdFib F X) = t := by rw [← congrFun (piComparison_comp_π F _ t), FintypeCat.comp_apply, ← PreservesProduct.iso_hom] simp only [mkSelfProdFib, FintypeCat.inv_hom_id_apply] exact Concrete.productEquiv_symm_apply_π.{w, w, w+1} (fun _ : F.obj X ↦ F.obj X) id t variable {X} {A : C} (u : A ⟶ selfProd F X) (a : F.obj A) (h : F.map u a = mkSelfProdFib F X) {F} /-- For each `x : F.obj X`, this is the composition of `u` with the projection at `x`. -/ @[simp] private noncomputable def selfProdProj (x : F.obj X) : A ⟶ X := u ≫ Pi.π _ x variable {u a} private lemma selfProdProj_fiber (x : F.obj X) : F.map (selfProdProj u x) a = x := by simp only [selfProdProj, selfProd, F.map_comp, FintypeCat.comp_apply, h] rw [mkSelfProdFib_map_π F X x] variable [IsConnected A] /-- An element `b : F.obj A` defines a permutation of the fiber of `X` by projecting onto the `F.map u b` factor. -/ private noncomputable def fiberPerm (b : F.obj A) : F.obj X ≃ F.obj X := by let σ (t : F.obj X) : F.obj X := F.map (selfProdProj u t) b apply Equiv.ofBijective σ apply Finite.injective_iff_bijective.mp intro t s (hs : F.map (selfProdProj u t) b = F.map (selfProdProj u s) b) show id t = id s have h' : selfProdProj u t = selfProdProj u s := evaluation_injective_of_isConnected F A X b hs rw [← selfProdProj_fiber h s, ← selfProdProj_fiber h t, h'] /-- Twisting `u` by `fiberPerm h b` yields an inclusion of `A` into `selfProd F X`. -/ private noncomputable def selfProdPermIncl (b : F.obj A) : A ⟶ selfProd F X := u ≫ (Pi.whiskerEquiv (fiberPerm h b) (fun _ => Iso.refl X)).inv private instance [Mono u] (b : F.obj A) : Mono (selfProdPermIncl h b) := mono_comp _ _ /-- Key technical lemma: the twisted inclusion `selfProdPermIncl h b` maps `a` to `F.map u b`. -/ private lemma selfProdTermIncl_fib_eq (b : F.obj A) : F.map u b = F.map (selfProdPermIncl h b) a := by apply Concrete.Pi.map_ext _ F intro (t : F.obj X) convert_to F.map (selfProdProj u t) b = _ · simp only [selfProdProj, map_comp, FintypeCat.comp_apply]; rfl · dsimp only [selfProdPermIncl, Pi.whiskerEquiv] rw [map_comp, FintypeCat.comp_apply, h] convert_to F.map (selfProdProj u t) b = (F.map (Pi.map' (fiberPerm h b) fun _ ↦ 𝟙 X) ≫ F.map (Pi.π (fun _ ↦ X) t)) (mkSelfProdFib F X) rw [← map_comp, Pi.map'_comp_π, Category.comp_id, mkSelfProdFib_map_π F X (fiberPerm h b t)] rfl /-- There exists an automorphism `f` of `A` that maps `b` to `a`. `f` is obtained by considering `u` and `selfProdPermIncl h b`. Both are inclusions of `A` into `selfProd F X` mapping `b` respectively `a` to the same element in the fiber of `selfProd F X`. Applying `connected_component_unique` yields the result. -/ private lemma subobj_selfProd_trans [Mono u] (b : F.obj A) : ∃ (f : A ≅ A), F.map f.hom b = a := by apply connected_component_unique F b a u (selfProdPermIncl h b) exact selfProdTermIncl_fib_eq h b end GaloisRepAux /-- The fiber of any object in a Galois category is represented by a Galois object. -/ lemma exists_galois_representative (X : C) : ∃ (A : C) (a : F.obj A), IsGalois A ∧ Function.Bijective (fun (f : A ⟶ X) ↦ F.map f a) := by obtain ⟨A, u, a, h1, h2, h3⟩ := fiber_in_connected_component F (selfProd F X) (mkSelfProdFib F X) use A use a constructor · refine (isGalois_iff_pretransitive F A).mpr ⟨fun x y ↦ ?_⟩ obtain ⟨fi1, hfi1⟩ := subobj_selfProd_trans h1 x obtain ⟨fi2, hfi2⟩ := subobj_selfProd_trans h1 y use fi1 ≪≫ fi2.symm show F.map (fi1.hom ≫ fi2.inv) x = y simp only [map_comp, FintypeCat.comp_apply] rw [hfi1, ← hfi2] exact congr_fun (F.mapIso fi2).hom_inv_id y · refine ⟨evaluation_injective_of_isConnected F A X a, ?_⟩ intro x use u ≫ Pi.π _ x exact (selfProdProj_fiber h1) x /-- Any element in the fiber of an object `X` is the evaluation of a morphism from a Galois object. -/ lemma exists_hom_from_galois_of_fiber (X : C) (x : F.obj X) : ∃ (A : C) (f : A ⟶ X) (a : F.obj A), IsGalois A ∧ F.map f a = x := by obtain ⟨A, a, h1, h2⟩ := exists_galois_representative F X obtain ⟨f, hf⟩ := h2.surjective x exact ⟨A, f, a, h1, hf⟩ /-- Any object with non-empty fiber admits a hom from a Galois object. -/ lemma exists_hom_from_galois_of_fiber_nonempty (X : C) (h : Nonempty (F.obj X)) : ∃ (A : C) (_ : A ⟶ X), IsGalois A := by obtain ⟨x⟩ := h obtain ⟨A, f, a, h1, _⟩ := exists_hom_from_galois_of_fiber F X x exact ⟨A, f, h1⟩ /-- Any connected object admits a hom from a Galois object. -/ lemma exists_hom_from_galois_of_connected (X : C) [IsConnected X] : ∃ (A : C) (_ : A ⟶ X), IsGalois A := exists_hom_from_galois_of_fiber_nonempty F X inferInstance end GaloisRep end PreGaloisCategory end CategoryTheory
CategoryTheory\Galois\Examples.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Galois.Basic import Mathlib.RepresentationTheory.Action.Basic import Mathlib.RepresentationTheory.Action.Concrete import Mathlib.RepresentationTheory.Action.Limits import Mathlib.CategoryTheory.Limits.FintypeCat import Mathlib.CategoryTheory.Limits.Shapes.Types import Mathlib.Logic.Equiv.TransferInstance /-! # Examples of Galois categories and fiber functors We show that for a group `G` the category of finite `G`-sets is a `PreGaloisCategory` and that the forgetful functor to `FintypeCat` is a `FiberFunctor`. The connected finite `G`-sets are precisely the ones with transitive `G`-action. -/ universe u v w namespace CategoryTheory namespace FintypeCat open Limits Functor PreGaloisCategory /-- Complement of the image of a morphism `f : X ⟶ Y` in `FintypeCat`. -/ noncomputable def imageComplement {X Y : FintypeCat.{u}} (f : X ⟶ Y) : FintypeCat.{u} := by haveI : Fintype (↑(Set.range f)ᶜ) := Fintype.ofFinite _ exact FintypeCat.of (↑(Set.range f)ᶜ) /-- The inclusion from the complement of the image of `f : X ⟶ Y` into `Y`. -/ def imageComplementIncl {X Y : FintypeCat.{u}} (f : X ⟶ Y) : imageComplement f ⟶ Y := Subtype.val variable (G : Type u) [Group G] /-- Given `f : X ⟶ Y` for `X Y : Action FintypeCat (MonCat.of G)`, the complement of the image of `f` has a natural `G`-action. -/ noncomputable def Action.imageComplement {X Y : Action FintypeCat (MonCat.of G)} (f : X ⟶ Y) : Action FintypeCat (MonCat.of G) where V := FintypeCat.imageComplement f.hom ρ := MonCat.ofHom <| { toFun := fun g y ↦ Subtype.mk (Y.ρ g y.val) <| by intro ⟨x, h⟩ apply y.property use X.ρ g⁻¹ x calc (X.ρ g⁻¹ ≫ f.hom) x = (Y.ρ g⁻¹ * Y.ρ g) y.val := by rw [f.comm, FintypeCat.comp_apply, h]; rfl _ = y.val := by rw [← map_mul, mul_left_inv, Action.ρ_one, FintypeCat.id_apply] map_one' := by simp only [Action.ρ_one]; rfl map_mul' := fun g h ↦ FintypeCat.hom_ext _ _ <| fun y ↦ Subtype.ext <| by exact congrFun (MonoidHom.map_mul Y.ρ g h) y.val } /-- The inclusion from the complement of the image of `f : X ⟶ Y` into `Y`. -/ def Action.imageComplementIncl {X Y : Action FintypeCat (MonCat.of G)} (f : X ⟶ Y) : Action.imageComplement G f ⟶ Y where hom := FintypeCat.imageComplementIncl f.hom comm _ := rfl instance {X Y : Action FintypeCat (MonCat.of G)} (f : X ⟶ Y) : Mono (Action.imageComplementIncl G f) := by apply Functor.mono_of_mono_map (forget _) apply ConcreteCategory.mono_of_injective exact Subtype.val_injective /-- The category of finite sets has quotients by finite groups in arbitrary universes. -/ instance [Finite G] : HasColimitsOfShape (SingleObj G) FintypeCat.{w} := by obtain ⟨G', hg, hf, ⟨e⟩⟩ := Finite.exists_type_zero_nonempty_mulEquiv G exact Limits.hasColimitsOfShape_of_equivalence e.toSingleObjEquiv.symm noncomputable instance : PreservesFiniteLimits (forget (Action FintypeCat (MonCat.of G))) := by show PreservesFiniteLimits (Action.forget FintypeCat _ ⋙ FintypeCat.incl) apply compPreservesFiniteLimits /-- The category of finite `G`-sets is a `PreGaloisCategory`. -/ instance : PreGaloisCategory (Action FintypeCat (MonCat.of G)) where hasQuotientsByFiniteGroups G _ _ := inferInstance monoInducesIsoOnDirectSummand {X Y} i h := ⟨Action.imageComplement G i, Action.imageComplementIncl G i, ⟨isColimitOfReflects (Action.forget _ _ ⋙ FintypeCat.incl) <| (isColimitMapCoconeBinaryCofanEquiv (forget _) i _).symm (Types.isCoprodOfMono ((forget _).map i))⟩⟩ /-- The forgetful functor from finite `G`-sets to sets is a `FiberFunctor`. -/ noncomputable instance : FiberFunctor (Action.forget FintypeCat (MonCat.of G)) where preservesFiniteCoproducts := ⟨fun _ _ ↦ inferInstance⟩ preservesQuotientsByFiniteGroups _ _ _ := inferInstance reflectsIsos := ⟨fun f (h : IsIso f.hom) => inferInstance⟩ /-- The category of finite `G`-sets is a `GaloisCategory`. -/ instance : GaloisCategory (Action FintypeCat (MonCat.of G)) where hasFiberFunctor := ⟨Action.forget FintypeCat (MonCat.of G), ⟨inferInstance⟩⟩ /-- The `G`-action on a connected finite `G`-set is transitive. -/ theorem Action.pretransitive_of_isConnected (X : Action FintypeCat (MonCat.of G)) [IsConnected X] : MulAction.IsPretransitive G X.V where exists_smul_eq x y := by /- We show that the `G`-orbit of `x` is a non-initial subobject of `X` and hence by connectedness, the orbit equals `X.V`. -/ let T : Set X.V := MulAction.orbit G x have : Fintype T := Fintype.ofFinite T letI : MulAction G (FintypeCat.of T) := inferInstanceAs <| MulAction G ↑(MulAction.orbit G x) let T' : Action FintypeCat (MonCat.of G) := Action.FintypeCat.ofMulAction G (FintypeCat.of T) let i : T' ⟶ X := ⟨Subtype.val, fun _ ↦ rfl⟩ have : Mono i := ConcreteCategory.mono_of_injective _ (Subtype.val_injective) have : IsIso i := by apply IsConnected.noTrivialComponent T' i apply (not_initial_iff_fiber_nonempty (Action.forget _ _) T').mpr exact Set.Nonempty.coe_sort (MulAction.orbit_nonempty x) have hb : Function.Bijective i.hom := by apply (ConcreteCategory.isIso_iff_bijective i.hom).mp exact map_isIso (forget₂ _ FintypeCat) i obtain ⟨⟨y', ⟨g, (hg : g • x = y')⟩⟩, (hy' : y' = y)⟩ := hb.surjective y use g exact hg.trans hy' /-- A nonempty `G`-set with transitive `G`-action is connected. -/ theorem Action.isConnected_of_transitive (X : FintypeCat) [MulAction G X] [MulAction.IsPretransitive G X] [h : Nonempty X] : IsConnected (Action.FintypeCat.ofMulAction G X) where notInitial := not_initial_of_inhabited (Action.forget _ _) h.some noTrivialComponent Y i hm hni := by /- We show that the induced inclusion `i.hom` of finite sets is surjective, using the transitivity of the `G`-action. -/ obtain ⟨(y : Y.V)⟩ := (not_initial_iff_fiber_nonempty (Action.forget _ _) Y).mp hni have : IsIso i.hom := by refine (ConcreteCategory.isIso_iff_bijective i.hom).mpr ⟨?_, fun x' ↦ ?_⟩ · haveI : Mono i.hom := map_mono (forget₂ _ _) i exact ConcreteCategory.injective_of_mono_of_preservesPullback i.hom · letI x : X := i.hom y obtain ⟨σ, hσ⟩ := MulAction.exists_smul_eq G x x' use σ • y show (Y.ρ σ ≫ i.hom) y = x' rw [i.comm, FintypeCat.comp_apply] exact hσ apply isIso_of_reflects_iso i (Action.forget _ _) /-- A nonempty finite `G`-set is connected if and only if the `G`-action is transitive. -/ theorem Action.isConnected_iff_transitive (X : Action FintypeCat (MonCat.of G)) [Nonempty X.V] : IsConnected X ↔ MulAction.IsPretransitive G X.V := ⟨fun _ ↦ pretransitive_of_isConnected G X, fun _ ↦ isConnected_of_transitive G X.V⟩ end FintypeCat end CategoryTheory
CategoryTheory\Galois\GaloisObjects.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Galois.Basic import Mathlib.CategoryTheory.Limits.FintypeCat import Mathlib.CategoryTheory.Limits.Preserves.Limits import Mathlib.CategoryTheory.Limits.Shapes.SingleObj import Mathlib.Logic.Equiv.TransferInstance /-! # Galois objects in Galois categories We define when a connected object of a Galois category `C` is Galois in a fiber functor independent way and show equivalent characterisations. ## Main definitions * `IsGalois` : Connected object `X` of `C` such that `X / Aut X` is terminal. ## Main results * `galois_iff_pretransitive` : A connected object `X` is Galois if and only if `Aut X` acts transitively on `F.obj X` for a fiber functor `F`. -/ universe u₁ u₂ v₁ v₂ v w namespace CategoryTheory namespace PreGaloisCategory open Limits Functor noncomputable instance {G : Type v} [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) FintypeCat.incl.{w} := by choose G' hg hf e using Finite.exists_type_zero_nonempty_mulEquiv G exact Limits.preservesColimitsOfShapeOfEquiv (Classical.choice e).toSingleObjEquiv.symm _ /-- A connected object `X` of `C` is Galois if the quotient `X / Aut X` is terminal. -/ class IsGalois {C : Type u₁} [Category.{u₂, u₁} C] [GaloisCategory C] (X : C) extends IsConnected X : Prop where quotientByAutTerminal : Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X) variable {C : Type u₁} [Category.{u₂, u₁} C] /-- The natural action of `Aut X` on `F.obj X`. -/ instance autMulFiber (F : C ⥤ FintypeCat.{w}) (X : C) : MulAction (Aut X) (F.obj X) where smul σ a := F.map σ.hom a one_smul a := by show F.map (𝟙 X) a = a simp only [map_id, FintypeCat.id_apply] mul_smul g h a := by show F.map (h.hom ≫ g.hom) a = (F.map h.hom ≫ F.map g.hom) a simp only [map_comp, FintypeCat.comp_apply] variable [GaloisCategory C] (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] /-- For a connected object `X` of `C`, the quotient `X / Aut X` is terminal if and only if the quotient `F.obj X / Aut X` has exactly one element. -/ noncomputable def quotientByAutTerminalEquivUniqueQuotient (X : C) [IsConnected X] : IsTerminal (colimit <| SingleObj.functor <| Aut.toEnd X) ≃ Unique (MulAction.orbitRel.Quotient (Aut X) (F.obj X)) := by let J : SingleObj (Aut X) ⥤ C := SingleObj.functor (Aut.toEnd X) let e : (F ⋙ FintypeCat.incl).obj (colimit J) ≅ _ := preservesColimitIso (F ⋙ FintypeCat.incl) J ≪≫ (Equiv.toIso <| SingleObj.Types.colimitEquivQuotient (J ⋙ F ⋙ FintypeCat.incl)) apply Equiv.trans · apply (IsTerminal.isTerminalIffObj (F ⋙ FintypeCat.incl) _).trans (isLimitEmptyConeEquiv _ (asEmptyCone _) (asEmptyCone _) e) exact Types.isTerminalEquivUnique _ lemma isGalois_iff_aux (X : C) [IsConnected X] : IsGalois X ↔ Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X) := ⟨fun h ↦ h.quotientByAutTerminal, fun h ↦ ⟨h⟩⟩ /-- Given a fiber functor `F` and a connected object `X` of `C`. Then `X` is Galois if and only if the natural action of `Aut X` on `F.obj X` is transitive. -/ theorem isGalois_iff_pretransitive (X : C) [IsConnected X] : IsGalois X ↔ MulAction.IsPretransitive (Aut X) (F.obj X) := by rw [isGalois_iff_aux, Equiv.nonempty_congr <| quotientByAutTerminalEquivUniqueQuotient F X] exact (MulAction.pretransitive_iff_unique_quotient_of_nonempty (Aut X) (F.obj X)).symm /-- If `X` is Galois, the quotient `X / Aut X` is terminal. -/ noncomputable def isTerminalQuotientOfIsGalois (X : C) [IsGalois X] : IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X := Nonempty.some IsGalois.quotientByAutTerminal /-- If `X` is Galois, then the action of `Aut X` on `F.obj X` is transitive for every fiber functor `F`. -/ instance isPretransitive_of_isGalois (X : C) [IsGalois X] : MulAction.IsPretransitive (Aut X) (F.obj X) := by rw [← isGalois_iff_pretransitive] infer_instance theorem evaluation_aut_surjective_of_isGalois (A : C) [IsGalois A] (a : F.obj A) : Function.Surjective (fun f : Aut A ↦ F.map f.hom a) := MulAction.IsPretransitive.exists_smul_eq a theorem evaluation_aut_bijective_of_isGalois (A : C) [IsGalois A] (a : F.obj A) : Function.Bijective (fun f : Aut A ↦ F.map f.hom a) := ⟨evaluation_aut_injective_of_isConnected F A a, evaluation_aut_surjective_of_isGalois F A a⟩ /-- For Galois `A` and a point `a` of the fiber of `A`, the evaluation at `A` as an equivalence. -/ noncomputable def evaluationEquivOfIsGalois (A : C) [IsGalois A] (a : F.obj A) : Aut A ≃ F.obj A := Equiv.ofBijective _ (evaluation_aut_bijective_of_isGalois F A a) @[simp] lemma evaluationEquivOfIsGalois_apply (A : C) [IsGalois A] (a : F.obj A) (φ : Aut A) : evaluationEquivOfIsGalois F A a φ = F.map φ.hom a := rfl @[simp] lemma evaluationEquivOfIsGalois_symm_fiber (A : C) [IsGalois A] (a b : F.obj A) : F.map ((evaluationEquivOfIsGalois F A a).symm b).hom a = b := by change (evaluationEquivOfIsGalois F A a) _ = _ simp section AutMap /-- For a morphism from a connected object `A` to a Galois object `B` and an automorphism of `A`, there exists a unique automorphism of `B` making the canonical diagram commute. -/ lemma exists_autMap {A B : C} (f : A ⟶ B) [IsConnected A] [IsGalois B] (σ : Aut A) : ∃! (τ : Aut B), f ≫ τ.hom = σ.hom ≫ f := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A refine ⟨?_, ?_, ?_⟩ · exact (evaluationEquivOfIsGalois F B (F.map f a)).symm (F.map (σ.hom ≫ f) a) · apply evaluation_injective_of_isConnected F A B a simp · intro τ hτ apply evaluation_aut_injective_of_isConnected F B (F.map f a) simpa using congr_fun (F.congr_map hτ) a /-- A morphism from a connected object to a Galois object induces a map on automorphism groups. This is a group homomorphism (see `autMapHom`). -/ noncomputable def autMap {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) : Aut B := (exists_autMap f σ).choose @[simp] lemma comp_autMap {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) : f ≫ (autMap f σ).hom = σ.hom ≫ f := (exists_autMap f σ).choose_spec.left @[simp] lemma comp_autMap_apply (F : C ⥤ FintypeCat.{w}) {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) (a : F.obj A) : F.map (autMap f σ).hom (F.map f a) = F.map f (F.map σ.hom a) := by simpa [-comp_autMap] using congrFun (F.congr_map (comp_autMap f σ)) a /-- `autMap` is uniquely characterized by making the canonical diagram commute. -/ lemma autMap_unique {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) (τ : Aut B) (h : f ≫ τ.hom = σ.hom ≫ f) : autMap f σ = τ := ((exists_autMap f σ).choose_spec.right τ h).symm @[simp] lemma autMap_id {A : C} [IsGalois A] : autMap (𝟙 A) = id := funext fun σ ↦ autMap_unique (𝟙 A) σ _ (by simp) @[simp] lemma autMap_comp {X Y Z : C} [IsConnected X] [IsGalois Y] [IsGalois Z] (f : X ⟶ Y) (g : Y ⟶ Z) : autMap (f ≫ g) = autMap g ∘ autMap f := by refine funext fun σ ↦ autMap_unique _ σ _ ?_ rw [Function.comp_apply, Category.assoc, comp_autMap, ← Category.assoc] simp /-- `autMap` is surjective, if the source is also Galois. -/ lemma autMap_surjective_of_isGalois {A B : C} [IsGalois A] [IsGalois B] (f : A ⟶ B) : Function.Surjective (autMap f) := by intro σ let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A obtain ⟨a', ha'⟩ := surjective_of_nonempty_fiber_of_isConnected F f (F.map σ.hom (F.map f a)) obtain ⟨τ, (hτ : F.map τ.hom a = a')⟩ := MulAction.exists_smul_eq (Aut A) a a' use τ apply evaluation_aut_injective_of_isConnected F B (F.map f a) simp [hτ, ha'] @[simp] lemma autMap_apply_mul {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ τ : Aut A) : autMap f (σ * τ) = autMap f σ * autMap f τ := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A apply evaluation_aut_injective_of_isConnected F (B : C) (F.map f a) simp [Aut.Aut_mul_def] /-- `MonoidHom` version of `autMap`. -/ @[simps!] noncomputable def autMapHom {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) : Aut A →* Aut B := MonoidHom.mk' (autMap f) (autMap_apply_mul f) end AutMap end PreGaloisCategory end CategoryTheory
CategoryTheory\Galois\Prorepresentability.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.Algebra.Category.Grp.Limits import Mathlib.CategoryTheory.CofilteredSystem import Mathlib.CategoryTheory.Galois.Decomposition import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.IndYoneda import Mathlib.CategoryTheory.Limits.Preserves.Ulift /-! # Pro-Representability of fiber functors We show that any fiber functor is pro-representable, i.e. there exists a pro-object `X : I ⥤ C` such that `F` is naturally isomorphic to the colimit of `X ⋙ coyoneda`. From this we deduce the canonical isomorphism of `Aut F` with the limit over the automorphism groups of all Galois objects. ## Main definitions - `PointedGaloisObject`: the category of pointed Galois objects - `PointedGaloisObject.cocone`: a cocone on `(PointedGaloisObject.incl F).op ≫ coyoneda` with point `F ⋙ FintypeCat.incl`. - `autGaloisSystem`: the system of automorphism groups indexed by the pointed Galois objects. ## Main results - `PointedGaloisObject.isColimit`: the cocone `PointedGaloisObject.cocone` is a colimit cocone. - `autMulEquivAutGalois`: `Aut F` is canonically isomorphic to the limit over the automorphism groups of all Galois objects. - `FiberFunctor.isPretransitive_of_isConnected`: The `Aut F` action on the fiber of a connected object is transitive. ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ w namespace CategoryTheory namespace PreGaloisCategory open Limits Functor variable {C : Type u₁} [Category.{u₂} C] [GaloisCategory C] variable (F : C ⥤ FintypeCat.{u₂}) /-- A pointed Galois object is a Galois object with a fixed point of its fiber. -/ structure PointedGaloisObject : Type (max u₁ u₂) where /-- The underlying object of `C`. -/ obj : C /-- An element of the fiber of `obj`. -/ pt : F.obj obj /-- `obj` is Galois. -/ isGalois : IsGalois obj := by infer_instance namespace PointedGaloisObject attribute [instance] isGalois instance (X : PointedGaloisObject F) : CoeDep (PointedGaloisObject F) X C where coe := X.obj variable {F} in /-- The type of homomorphisms between two pointed Galois objects. This is a homomorphism of the underlying objects of `C` that maps the distinguished points to each other. -/ @[ext] structure Hom (A B : PointedGaloisObject F) where /-- The underlying homomorphism of `C`. -/ val : A.obj ⟶ B.obj /-- The distinguished point of `A` is mapped to the distinguished point of `B`. -/ comp : F.map val A.pt = B.pt := by simp attribute [simp] Hom.comp /-- The category of pointed Galois objects. -/ instance : Category.{u₂} (PointedGaloisObject F) where Hom A B := Hom A B id A := { val := 𝟙 (A : C) } comp {A B C} f g := { val := f.val ≫ g.val } instance {A B : PointedGaloisObject F} : Coe (Hom A B) (A.obj ⟶ B.obj) where coe f := f.val variable {F} @[ext] lemma hom_ext {A B : PointedGaloisObject F} {f g : A ⟶ B} (h : f.val = g.val) : f = g := Hom.ext h @[simp] lemma id_val (A : PointedGaloisObject F) : 𝟙 A = 𝟙 A.obj := rfl @[simp, reassoc] lemma comp_val {A B C : PointedGaloisObject F} (f : A ⟶ B) (g : B ⟶ C) : (f ≫ g).val = f.val ≫ g.val := rfl variable (F) /-- The canonical functor from pointed Galois objects to `C`. -/ def incl : PointedGaloisObject F ⥤ C where obj := fun A ↦ A map := fun ⟨f, _⟩ ↦ f @[simp] lemma incl_obj (A : PointedGaloisObject F) : (incl F).obj A = A := rfl @[simp] lemma incl_map {A B : PointedGaloisObject F} (f : A ⟶ B) : (incl F).map f = f.val := rfl /-- `F ⋙ FintypeCat.incl` as a cocone over `(can F).op ⋙ coyoneda`. This is a colimit cocone (see `PreGaloisCategory.isColimìt`) -/ def cocone : Cocone ((incl F).op ⋙ coyoneda) where pt := F ⋙ FintypeCat.incl ι := { app := fun ⟨A, a, _⟩ ↦ { app := fun X (f : (A : C) ⟶ X) ↦ F.map f a } naturality := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ⟨f, (hf : F.map f b = a)⟩ ↦ by ext Y (g : (A : C) ⟶ Y) suffices h : F.map g (F.map f b) = F.map g a by simpa rw [hf] } @[simp] lemma cocone_app (A : PointedGaloisObject F) (B : C) (f : (A : C) ⟶ B) : ((cocone F).ι.app ⟨A⟩).app B f = F.map f A.pt := rfl variable [FiberFunctor F] /-- The category of pointed Galois objects is cofiltered. -/ instance : IsCofilteredOrEmpty (PointedGaloisObject F) where cone_objs := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ↦ by obtain ⟨Z, f, z, hgal, hfz⟩ := exists_hom_from_galois_of_fiber F (A ⨯ B) <| (fiberBinaryProductEquiv F A B).symm (a, b) refine ⟨⟨Z, z, hgal⟩, ⟨f ≫ prod.fst, ?_⟩, ⟨f ≫ prod.snd, ?_⟩, trivial⟩ · simp only [F.map_comp, hfz, FintypeCat.comp_apply, fiberBinaryProductEquiv_symm_fst_apply] · simp only [F.map_comp, hfz, FintypeCat.comp_apply, fiberBinaryProductEquiv_symm_snd_apply] cone_maps := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ⟨f, hf⟩ ⟨g, hg⟩ ↦ by obtain ⟨Z, h, z, hgal, hhz⟩ := exists_hom_from_galois_of_fiber F A a refine ⟨⟨Z, z, hgal⟩, ⟨h, hhz⟩, hom_ext ?_⟩ apply evaluation_injective_of_isConnected F Z B z simp [hhz, hf, hg] /-- `cocone F` is a colimit cocone, i.e. `F` is pro-represented by `incl F`. -/ noncomputable def isColimit : IsColimit (cocone F) := by refine evaluationJointlyReflectsColimits _ (fun X ↦ ?_) refine Types.FilteredColimit.isColimitOf _ _ ?_ ?_ · intro (x : F.obj X) obtain ⟨Y, i, y, h1, _, _⟩ := fiber_in_connected_component F X x obtain ⟨Z, f, z, hgal, hfz⟩ := exists_hom_from_galois_of_fiber F Y y refine ⟨⟨Z, z, hgal⟩, f ≫ i, ?_⟩ simp only [mapCocone_ι_app, evaluation_obj_map, cocone_app, map_comp, ← h1, FintypeCat.comp_apply, hfz] · intro ⟨A, a, _⟩ ⟨B, b, _⟩ (u : (A : C) ⟶ X) (v : (B : C) ⟶ X) (h : F.map u a = F.map v b) obtain ⟨⟨Z, z, _⟩, ⟨f, hf⟩, ⟨g, hg⟩, _⟩ := IsFilteredOrEmpty.cocone_objs (C := (PointedGaloisObject F)ᵒᵖ) ⟨{ obj := A, pt := a}⟩ ⟨{obj := B, pt := b}⟩ refine ⟨⟨{ obj := Z, pt := z }⟩, ⟨f, hf⟩, ⟨g, hg⟩, ?_⟩ apply evaluation_injective_of_isConnected F Z X z change F.map (f ≫ u) z = F.map (g ≫ v) z rw [map_comp, FintypeCat.comp_apply, hf, map_comp, FintypeCat.comp_apply, hg, h] instance : HasColimit ((incl F).op ⋙ coyoneda) where exists_colimit := ⟨cocone F, isColimit F⟩ end PointedGaloisObject open PointedGaloisObject /-- The diagram sending each pointed Galois object to its automorphism group as an object of `C`. -/ @[simps] noncomputable def autGaloisSystem : PointedGaloisObject F ⥤ Grp.{u₂} where obj := fun A ↦ Grp.of <| Aut (A : C) map := fun {A B} f ↦ (autMapHom f : Aut (A : C) →* Aut (B : C)) map_id := fun A ↦ by ext (σ : Aut A.obj) simp map_comp {A B C} f g := by ext (σ : Aut A.obj) simp /-- The limit of `autGaloisSystem`. -/ noncomputable def AutGalois : Type (max u₁ u₂) := (autGaloisSystem F ⋙ forget _).sections noncomputable instance : Group (AutGalois F) := inferInstanceAs <| Group (autGaloisSystem F ⋙ forget _).sections /-- The canonical projection from `AutGalois F` to the `C`-automorphism group of each pointed Galois object. -/ noncomputable def AutGalois.π (A : PointedGaloisObject F) : AutGalois F →* Aut (A : C) := Grp.sectionsπMonoidHom (autGaloisSystem F) A /- Not a `simp` lemma, because we usually don't want to expose the internals here. -/ lemma AutGalois.π_apply (A : PointedGaloisObject F) (x : AutGalois F) : AutGalois.π F A x = x.val A := rfl lemma autGaloisSystem_map_surjective ⦃A B : PointedGaloisObject F⦄ (f : A ⟶ B) : Function.Surjective ((autGaloisSystem F).map f) := by intro (φ : Aut B.obj) obtain ⟨ψ, hψ⟩ := autMap_surjective_of_isGalois f.val φ use ψ simp only [autGaloisSystem_map] exact hψ /-- Equality of elements of `AutGalois F` can be checked on the projections on each pointed Galois object. -/ lemma AutGalois.ext {f g : AutGalois F} (h : ∀ (A : PointedGaloisObject F), AutGalois.π F A f = AutGalois.π F A g) : f = g := by dsimp only [AutGalois] ext A exact h A /-- `autGalois.π` is surjective for every pointed Galois object. -/ theorem AutGalois.π_surjective [FiberFunctor F] (A : PointedGaloisObject F) : Function.Surjective (AutGalois.π F A) := fun (σ : Aut A.obj) ↦ by have (i : PointedGaloisObject F) : Finite ((autGaloisSystem F ⋙ forget _).obj i) := inferInstanceAs <| Finite (Aut (i.obj)) exact eval_section_surjective_of_surjective (autGaloisSystem F ⋙ forget _) (autGaloisSystem_map_surjective F) A σ variable [FiberFunctor F] section EndAutGaloisIsomorphism /-! ### Isomorphism between `Aut F` and `AutGalois F` In this section we establish the isomorphism between the automorphism group of `F` and the limit over the automorphism groups of all Galois objects. We first establish the isomorphism between `End F` and `AutGalois F`, from which we deduce that `End F` is a group, hence `End F = Aut F`. The isomorphism is built in multiple steps: - `endEquivSectionsFibers : End F ≅ (incl F ⋙ F').sections`: the endomorphisms of `F` are isomorphic to the limit over `F.obj A` for all Galois objects `A`. This is obtained as the composition (slighty simplified): `End F ≅ (colimit ((incl F).op ⋙ coyoneda) ⟶ F) ≅ (incl F ⋙ F).sections` Where the first isomorphism is induced from the pro-representability of `F` and the second one from the pro-coyoneda lemma. - `endEquivAutGalois : End F ≅ AutGalois F`: this is the composition of `endEquivSectionsFibers` with: `(incl F ⋙ F).sections ≅ (autGaloisSystem F ⋙ forget Grp).sections` which is induced from the level-wise equivalence `Aut A ≃ F.obj A` for a Galois object `A`. -/ -- Local notation for `F` considered as a functor to types instead of finite types. local notation "F'" => F ⋙ FintypeCat.incl /-- The endomorphisms of `F` are isomorphic to the limit over the fibers of `F` on all Galois objects. -/ noncomputable def endEquivSectionsFibers : End F ≃ (incl F ⋙ F').sections := let i1 : End F ≃ End F' := (FullyFaithful.whiskeringRight (FullyFaithful.ofFullyFaithful FintypeCat.incl) C).homEquiv let i2 : End F' ≅ (colimit ((incl F).op ⋙ coyoneda) ⟶ F') := (yoneda.obj (F ⋙ FintypeCat.incl)).mapIso (colimit.isoColimitCocone ⟨cocone F, isColimit F⟩).op let i3 : (colimit ((incl F).op ⋙ coyoneda) ⟶ F') ≅ limit ((incl F ⋙ F') ⋙ uliftFunctor.{u₁}) := colimitCoyonedaHomIsoLimit' (incl F) F' let i4 : limit (incl F ⋙ F' ⋙ uliftFunctor.{u₁}) ≃ ((incl F ⋙ F') ⋙ uliftFunctor.{u₁}).sections := Types.limitEquivSections (incl F ⋙ (F ⋙ FintypeCat.incl) ⋙ uliftFunctor.{u₁, u₂}) let i5 : ((incl F ⋙ F') ⋙ uliftFunctor.{u₁}).sections ≃ (incl F ⋙ F').sections := (Types.sectionsEquiv (incl F ⋙ F')).symm i1.trans <| i2.toEquiv.trans <| i3.toEquiv.trans <| i4.trans i5 @[simp] lemma endEquivSectionsFibers_π (f : End F) (A : PointedGaloisObject F) : (endEquivSectionsFibers F f).val A = f.app A A.pt := by dsimp [endEquivSectionsFibers, Types.sectionsEquiv] erw [Types.limitEquivSections_apply] simp only [colimitCoyonedaHomIsoLimit'_π_apply, incl_obj, comp_obj, FintypeCat.incl_obj, op_obj, FunctorToTypes.comp] change (((FullyFaithful.whiskeringRight (FullyFaithful.ofFullyFaithful FintypeCat.incl) C).homEquiv) f).app A (((colimit.ι _ _) ≫ (colimit.isoColimitCocone ⟨cocone F, isColimit F⟩).hom).app A _) = f.app A A.pt simp rfl /-- Functorial isomorphism `Aut A ≅ F.obj A` for Galois objects `A`. -/ noncomputable def autIsoFibers : autGaloisSystem F ⋙ forget Grp ≅ incl F ⋙ F' := NatIso.ofComponents (fun A ↦ ((evaluationEquivOfIsGalois F A A.pt).toIso)) (fun {A B} f ↦ by ext (φ : Aut A.obj) dsimp erw [evaluationEquivOfIsGalois_apply, evaluationEquivOfIsGalois_apply] simp [-Hom.comp, ← f.comp]) lemma autIsoFibers_inv_app (A : PointedGaloisObject F) (b : F.obj A) : (autIsoFibers F).inv.app A b = (evaluationEquivOfIsGalois F A A.pt).symm b := rfl /-- The equivalence between endomorphisms of `F` and the limit over the automorphism groups of all Galois objects. -/ noncomputable def endEquivAutGalois : End F ≃ AutGalois F := let e1 := endEquivSectionsFibers F let e2 := ((Functor.sectionsFunctor _).mapIso (autIsoFibers F).symm).toEquiv e1.trans e2 lemma endEquivAutGalois_π (f : End F) (A : PointedGaloisObject F) : F.map (AutGalois.π F A (endEquivAutGalois F f)).hom A.pt = f.app A A.pt := by dsimp [endEquivAutGalois, AutGalois.π_apply] change F.map ((((sectionsFunctor _).map (autIsoFibers F).inv) _).val A).hom A.pt = _ dsimp [autIsoFibers] simp only [endEquivSectionsFibers_π] erw [evaluationEquivOfIsGalois_symm_fiber] @[simp] theorem endEquivAutGalois_mul (f g : End F) : (endEquivAutGalois F) (g ≫ f) = (endEquivAutGalois F g) * (endEquivAutGalois F f) := by refine AutGalois.ext F (fun A ↦ evaluation_aut_injective_of_isConnected F A A.pt ?_) simp only [map_mul, endEquivAutGalois_π, Aut.Aut_mul_def, NatTrans.comp_app, Iso.trans_hom] simp only [map_comp, FintypeCat.comp_apply, endEquivAutGalois_π] change f.app A (g.app A A.pt) = (f.app A ≫ F.map ((AutGalois.π F A) ((endEquivAutGalois F) g)).hom) A.pt rw [← f.naturality, FintypeCat.comp_apply, endEquivAutGalois_π] /-- The monoid isomorphism between endomorphisms of `F` and the (multiplicative opposite of the) limit of automorphism groups of all Galois objects. -/ noncomputable def endMulEquivAutGalois : End F ≃* (AutGalois F)ᵐᵒᵖ := MulEquiv.mk (Equiv.trans (endEquivAutGalois F) MulOpposite.opEquiv) (by simp) lemma endMulEquivAutGalois_pi (f : End F) (A : PointedGaloisObject F) : F.map (AutGalois.π F A (endMulEquivAutGalois F f).unop).hom A.2 = f.app A A.pt := endEquivAutGalois_π F f A /-- Any endomorphism of a fiber functor is a unit. -/ theorem FibreFunctor.end_isUnit (f : End F) : IsUnit f := (MulEquiv.map_isUnit_iff (endMulEquivAutGalois F)).mp (Group.isUnit ((endMulEquivAutGalois F) f)) /-- Any endomorphism of a fiber functor is an isomorphism. -/ instance FibreFunctor.end_isIso (f : End F) : IsIso f := by rw [← isUnit_iff_isIso] exact FibreFunctor.end_isUnit F f /-- The automorphism group of `F` is multiplicatively isomorphic to (the multiplicative opposite of) the limit over the automorphism groups of the Galois objects. -/ noncomputable def autMulEquivAutGalois : Aut F ≃* (AutGalois F)ᵐᵒᵖ where toFun := MonoidHom.comp (endMulEquivAutGalois F) (Aut.toEnd F) invFun t := asIso ((endMulEquivAutGalois F).symm t) left_inv t := by simp only [MonoidHom.coe_comp, MonoidHom.coe_coe, Function.comp_apply, MulEquiv.symm_apply_apply] exact Aut.ext rfl right_inv t := by simp only [MonoidHom.coe_comp, MonoidHom.coe_coe, Function.comp_apply, Aut.toEnd_apply] exact (MulEquiv.eq_symm_apply (endMulEquivAutGalois F)).mp rfl map_mul' := by simp lemma autMulEquivAutGalois_π (f : Aut F) (A : C) [IsGalois A] (a : F.obj A) : F.map (AutGalois.π F { obj := A, pt := a } (autMulEquivAutGalois F f).unop).hom a = f.hom.app A a := by dsimp [autMulEquivAutGalois, endMulEquivAutGalois] rw [endEquivAutGalois_π] rfl @[simp] lemma autMulEquivAutGalois_symm_app (x : AutGalois F) (A : C) [IsGalois A] (a : F.obj A) : ((autMulEquivAutGalois F).symm ⟨x⟩).hom.app A a = F.map (AutGalois.π F ⟨A, a, inferInstance⟩ x).hom a := by rw [← autMulEquivAutGalois_π, MulEquiv.apply_symm_apply] rfl end EndAutGaloisIsomorphism /-- The `Aut F` action on the fiber of a Galois object is transitive. See `pretransitive_of_isConnected` for the same result for connected objects. -/ theorem FiberFunctor.isPretransitive_of_isGalois (X : C) [IsGalois X] : MulAction.IsPretransitive (Aut F) (F.obj X) := by refine ⟨fun x y ↦ ?_⟩ obtain ⟨(φ : Aut X), h⟩ := MulAction.IsPretransitive.exists_smul_eq (M := Aut X) x y obtain ⟨a, ha⟩ := AutGalois.π_surjective F ⟨X, x, inferInstance⟩ φ use (autMulEquivAutGalois F).symm ⟨a⟩ simpa [mulAction_def, ha] /-- The `Aut F` action on the fiber of a connected object is transitive. -/ instance FiberFunctor.isPretransitive_of_isConnected (X : C) [IsConnected X] : MulAction.IsPretransitive (Aut F) (F.obj X) := by obtain ⟨A, f, hgal⟩ := exists_hom_from_galois_of_connected F X have hs : Function.Surjective (F.map f) := surjective_of_nonempty_fiber_of_isConnected F f refine ⟨fun x y ↦ ?_⟩ obtain ⟨a, ha⟩ := hs x obtain ⟨b, hb⟩ := hs y have : MulAction.IsPretransitive (Aut F) (F.obj A) := isPretransitive_of_isGalois F A obtain ⟨σ, (hσ : σ.hom.app A a = b)⟩ := MulAction.exists_smul_eq (Aut F) a b use σ rw [← ha, ← hb] show (F.map f ≫ σ.hom.app X) a = F.map f b rw [σ.hom.naturality, FintypeCat.comp_apply, hσ] end PreGaloisCategory end CategoryTheory
CategoryTheory\GradedObject\Associator.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.GradedObject.Trifunctor /-! # The associator for actions of bifunctors on graded objects Given functors `F₁₂ : C₁ ⥤ C₂ ⥤ C₁₂`, `G : C₁₂ ⥤ C₃ ⥤ C₄`, `F : C₁ ⥤ C₂₃ ⥤ C₄`, `G₂₃ : C₂ ⥤ C₃ ⥤ C₂₃` equipped with an isomorphism `associator : bifunctorComp₁₂ F₁₂ G ≅ bifunctorComp₂₃ F G₂₃` (which informally means that we have natural isomorphisms `G(F₁₂(X₁, X₂), X₃) ≅ F(X₁, G₂₃(X₂, X₃))`), a map `r : I₁ × I₂ × I₃ → J`, and data `ρ₁₂ : BifunctorComp₁₂IndexData r` and `ρ₂₃ : BifunctorComp₂₃IndexData r`, then if `X₁ : GradedObject I₁ C₁`, `X₂ : GradedObject I₂ C₂` and `X₃ : GradedObject I₃ C₃` satisfy suitable assumptions, we construct an isomorphism `mapBifunctorAssociator associator ρ₁₂ ρ₂₃ X₁ X₂ X₃` between `mapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃` and `mapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃)` in the category `GradedObject J C₄`. This construction shall be used in the definition of the monoidal category structure on graded objects indexed by an additive monoid. -/ namespace CategoryTheory open Category namespace GradedObject variable {C₁ C₂ C₁₂ C₂₃ C₃ C₄ : Type*} [Category C₁] [Category C₂] [Category C₃] [Category C₄] [Category C₁₂] [Category C₂₃] {F₁₂ : C₁ ⥤ C₂ ⥤ C₁₂} {G : C₁₂ ⥤ C₃ ⥤ C₄} {F : C₁ ⥤ C₂₃ ⥤ C₄} {G₂₃ : C₂ ⥤ C₃ ⥤ C₂₃} (associator : bifunctorComp₁₂ F₁₂ G ≅ bifunctorComp₂₃ F G₂₃) {I₁ I₂ I₃ J : Type*} {r : I₁ × I₂ × I₃ → J} (ρ₁₂ : BifunctorComp₁₂IndexData r) (ρ₂₃ : BifunctorComp₂₃IndexData r) (X₁ : GradedObject I₁ C₁) (X₂ : GradedObject I₂ C₂) (X₃ : GradedObject I₃ C₃) [HasMap (((mapBifunctor F₁₂ I₁ I₂).obj X₁).obj X₂) ρ₁₂.p] [HasMap (((mapBifunctor G ρ₁₂.I₁₂ I₃).obj (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂)).obj X₃) ρ₁₂.q] [HasMap (((mapBifunctor G₂₃ I₂ I₃).obj X₂).obj X₃) ρ₂₃.p] [HasMap (((mapBifunctor F I₁ ρ₂₃.I₂₃).obj X₁).obj (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃)) ρ₂₃.q] [H₁₂ : HasGoodTrifunctor₁₂Obj F₁₂ G ρ₁₂ X₁ X₂ X₃] [H₂₃ : HasGoodTrifunctor₂₃Obj F G₂₃ ρ₂₃ X₁ X₂ X₃] /-- Associator isomorphism for the action of bifunctors on graded objects. -/ noncomputable def mapBifunctorAssociator : mapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ ≅ mapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) := have := H₁₂.hasMap have := H₂₃.hasMap (mapBifunctorComp₁₂MapObjIso F₁₂ G ρ₁₂ X₁ X₂ X₃).symm ≪≫ mapIso ((((mapTrifunctorMapIso associator I₁ I₂ I₃).app X₁).app X₂).app X₃) r ≪≫ mapBifunctorComp₂₃MapObjIso F G₂₃ ρ₂₃ X₁ X₂ X₃ @[reassoc (attr := simp, nolint unusedHavesSuffices)] lemma ι_mapBifunctorAssociator_hom (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (mapBifunctorAssociator associator ρ₁₂ ρ₂₃ X₁ X₂ X₃).hom j = ((associator.hom.app (X₁ i₁)).app (X₂ i₂)).app (X₃ i₃) ≫ ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h := by have := H₁₂.hasMap have := H₂₃.hasMap dsimp [mapBifunctorAssociator] rw [ι_mapBifunctorComp₁₂MapObjIso_inv_assoc, ιMapTrifunctorMapObj, ι_mapMap_assoc, mapTrifunctorMapNatTrans_app_app_app] erw [ι_mapBifunctorComp₂₃MapObjIso_hom] @[reassoc (attr := simp)] lemma ι_mapBifunctorAssociator_inv (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (mapBifunctorAssociator associator ρ₁₂ ρ₂₃ X₁ X₂ X₃).inv j = ((associator.inv.app (X₁ i₁)).app (X₂ i₂)).app (X₃ i₃) ≫ ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j h := by rw [← cancel_mono ((mapBifunctorAssociator associator ρ₁₂ ρ₂₃ X₁ X₂ X₃).hom j), assoc, assoc, Iso.inv_hom_id_eval, comp_id, ι_mapBifunctorAssociator_hom, ← NatTrans.comp_app_assoc, ← NatTrans.comp_app, Iso.inv_hom_id_app, NatTrans.id_app, NatTrans.id_app, id_comp] end GradedObject end CategoryTheory
CategoryTheory\GradedObject\Bifunctor.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.GradedObject /-! # The action of bifunctors on graded objects Given a bifunctor `F : C₁ ⥤ C₂ ⥤ C₃` and types `I` and `J`, we construct an obvious functor `mapBifunctor F I J : GradedObject I C₁ ⥤ GradedObject J C₂ ⥤ GradedObject (I × J) C₃`. When we have a map `p : I × J → K` and that suitable coproducts exists, we also get a functor `mapBifunctorMap F p : GradedObject I C₁ ⥤ GradedObject J C₂ ⥤ GradedObject K C₃`. In case `p : I × I → I` is the addition on a monoid and `F` is the tensor product on a monoidal category `C`, these definitions shall be used in order to construct a monoidal structure on `GradedObject I C` (TODO @joelriou). -/ namespace CategoryTheory open Category variable {C₁ C₂ C₃ : Type*} [Category C₁] [Category C₂] [Category C₃] (F : C₁ ⥤ C₂ ⥤ C₃) namespace GradedObject /-- Given a bifunctor `F : C₁ ⥤ C₂ ⥤ C₃` and types `I` and `J`, this is the obvious functor `GradedObject I C₁ ⥤ GradedObject J C₂ ⥤ GradedObject (I × J) C₃`. -/ @[simps] def mapBifunctor (I J : Type*) : GradedObject I C₁ ⥤ GradedObject J C₂ ⥤ GradedObject (I × J) C₃ where obj X := { obj := fun Y ij => (F.obj (X ij.1)).obj (Y ij.2) map := fun φ ij => (F.obj (X ij.1)).map (φ ij.2) } map φ := { app := fun Y ij => (F.map (φ ij.1)).app (Y ij.2) } section variable {I J K : Type*} (p : I × J → K) /-- Given a bifunctor `F : C₁ ⥤ C₂ ⥤ C₃`, graded objects `X : GradedObject I C₁` and `Y : GradedObject J C₂` and a map `p : I × J → K`, this is the `K`-graded object sending `k` to the coproduct of `(F.obj (X i)).obj (Y j)` for `p ⟨i, j⟩ = k`. -/ @[simp] noncomputable def mapBifunctorMapObj (X : GradedObject I C₁) (Y : GradedObject J C₂) [HasMap (((mapBifunctor F I J).obj X).obj Y) p] : GradedObject K C₃ := (((mapBifunctor F I J).obj X).obj Y).mapObj p /-- The inclusion of `(F.obj (X i)).obj (Y j)` in `mapBifunctorMapObj F p X Y k` when `i + j = k`. -/ noncomputable def ιMapBifunctorMapObj (X : GradedObject I C₁) (Y : GradedObject J C₂) [HasMap (((mapBifunctor F I J).obj X).obj Y) p] (i : I) (j : J) (k : K) (h : p ⟨i, j⟩ = k) : (F.obj (X i)).obj (Y j) ⟶ mapBifunctorMapObj F p X Y k := (((mapBifunctor F I J).obj X).obj Y).ιMapObj p ⟨i, j⟩ k h /-- The maps `mapBifunctorMapObj F p X₁ Y₁ ⟶ mapBifunctorMapObj F p X₂ Y₂` which express the functoriality of `mapBifunctorMapObj`, see `mapBifunctorMap`. -/ noncomputable def mapBifunctorMapMap {X₁ X₂ : GradedObject I C₁} (f : X₁ ⟶ X₂) {Y₁ Y₂ : GradedObject J C₂} (g : Y₁ ⟶ Y₂) [HasMap (((mapBifunctor F I J).obj X₁).obj Y₁) p] [HasMap (((mapBifunctor F I J).obj X₂).obj Y₂) p] : mapBifunctorMapObj F p X₁ Y₁ ⟶ mapBifunctorMapObj F p X₂ Y₂ := GradedObject.mapMap (((mapBifunctor F I J).map f).app Y₁ ≫ ((mapBifunctor F I J).obj X₂).map g) p @[reassoc (attr := simp)] lemma ι_mapBifunctorMapMap {X₁ X₂ : GradedObject I C₁} (f : X₁ ⟶ X₂) {Y₁ Y₂ : GradedObject J C₂} (g : Y₁ ⟶ Y₂) [HasMap (((mapBifunctor F I J).obj X₁).obj Y₁) p] [HasMap (((mapBifunctor F I J).obj X₂).obj Y₂) p] (i : I) (j : J) (k : K) (h : p ⟨i, j⟩ = k) : ιMapBifunctorMapObj F p X₁ Y₁ i j k h ≫ mapBifunctorMapMap F p f g k = (F.map (f i)).app (Y₁ j) ≫ (F.obj (X₂ i)).map (g j) ≫ ιMapBifunctorMapObj F p X₂ Y₂ i j k h := by simp [ιMapBifunctorMapObj, mapBifunctorMapMap] @[ext] lemma mapBifunctorMapObj_ext {X : GradedObject I C₁} {Y : GradedObject J C₂} {A : C₃} {k : K} [HasMap (((mapBifunctor F I J).obj X).obj Y) p] {f g : mapBifunctorMapObj F p X Y k ⟶ A} (h : ∀ (i : I) (j : J) (hij : p ⟨i, j⟩ = k), ιMapBifunctorMapObj F p X Y i j k hij ≫ f = ιMapBifunctorMapObj F p X Y i j k hij ≫ g) : f = g := by apply mapObj_ext rintro ⟨i, j⟩ hij exact h i j hij variable {F p} in /-- Constructor for morphisms from `mapBifunctorMapObj F p X Y k`. -/ noncomputable def mapBifunctorMapObjDesc {X : GradedObject I C₁} {Y : GradedObject J C₂} {A : C₃} {k : K} [HasMap (((mapBifunctor F I J).obj X).obj Y) p] (f : ∀ (i : I) (j : J) (_ : p ⟨i, j⟩ = k), (F.obj (X i)).obj (Y j) ⟶ A) : mapBifunctorMapObj F p X Y k ⟶ A := descMapObj _ _ (fun ⟨i, j⟩ hij => f i j hij) @[reassoc (attr := simp)] lemma ι_mapBifunctorMapObjDesc {X : GradedObject I C₁} {Y : GradedObject J C₂} {A : C₃} {k : K} [HasMap (((mapBifunctor F I J).obj X).obj Y) p] (f : ∀ (i : I) (j : J) (_ : p ⟨i, j⟩ = k), (F.obj (X i)).obj (Y j) ⟶ A) (i : I) (j : J) (hij : p ⟨i, j⟩ = k) : ιMapBifunctorMapObj F p X Y i j k hij ≫ mapBifunctorMapObjDesc f = f i j hij := by apply ι_descMapObj section variable {X₁ X₂ : GradedObject I C₁} {Y₁ Y₂ : GradedObject J C₂} [HasMap (((mapBifunctor F I J).obj X₁).obj Y₁) p] [HasMap (((mapBifunctor F I J).obj X₂).obj Y₂) p] /-- The isomorphism `mapBifunctorMapObj F p X₁ Y₁ ≅ mapBifunctorMapObj F p X₂ Y₂` induced by isomorphisms `X₁ ≅ X₂` and `Y₁ ≅ Y₂`. -/ @[simps] noncomputable def mapBifunctorMapMapIso (e : X₁ ≅ X₂) (e' : Y₁ ≅ Y₂) : mapBifunctorMapObj F p X₁ Y₁ ≅ mapBifunctorMapObj F p X₂ Y₂ where hom := mapBifunctorMapMap F p e.hom e'.hom inv := mapBifunctorMapMap F p e.inv e'.inv hom_inv_id := by ext; simp inv_hom_id := by ext; simp instance (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) [IsIso f] [IsIso g] : IsIso (mapBifunctorMapMap F p f g) := (inferInstance : IsIso (mapBifunctorMapMapIso F p (asIso f) (asIso g)).hom) end attribute [local simp] mapBifunctorMapMap /-- Given a bifunctor `F : C₁ ⥤ C₂ ⥤ C₃` and a map `p : I × J → K`, this is the functor `GradedObject I C₁ ⥤ GradedObject J C₂ ⥤ GradedObject K C₃` sending `X : GradedObject I C₁` and `Y : GradedObject J C₂` to the `K`-graded object sending `k` to the coproduct of `(F.obj (X i)).obj (Y j)` for `p ⟨i, j⟩ = k`. -/ @[simps] noncomputable def mapBifunctorMap [∀ X Y, HasMap (((mapBifunctor F I J).obj X).obj Y) p] : GradedObject I C₁ ⥤ GradedObject J C₂ ⥤ GradedObject K C₃ where obj X := { obj := fun Y => mapBifunctorMapObj F p X Y map := fun ψ => mapBifunctorMapMap F p (𝟙 X) ψ } map {X₁ X₂} φ := { app := fun Y => mapBifunctorMapMap F p φ (𝟙 Y) naturality := fun {Y₁ Y₂} ψ => by dsimp simp only [Functor.map_id, NatTrans.id_app, id_comp, comp_id, ← mapMap_comp, NatTrans.naturality] } end end GradedObject end CategoryTheory
CategoryTheory\GradedObject\Monoidal.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Kim Morrison -/ import Mathlib.CategoryTheory.GradedObject.Unitor import Mathlib.Data.Fintype.Prod /-! # The monoidal category structures on graded objects Assuming that `C` is a monoidal category and that `I` is an additive monoid, we introduce a partially defined tensor product on the category `GradedObject I C`: given `X₁` and `X₂` two objects in `GradedObject I C`, we define `GradedObject.Monoidal.tensorObj X₁ X₂` under the assumption `HasTensor X₁ X₂` that the coproduct of `X₁ i ⊗ X₂ j` for `i + j = n` exists for any `n : I`. Under suitable assumptions about the existence of coproducts and the preservation of certain coproducts by the tensor products in `C`, we obtain a monoidal category structure on `GradedObject I C`. In particular, if `C` has finite coproducts to which the tensor product commutes, we obtain a monoidal category structure on `GradedObject ℕ C`. -/ universe u namespace CategoryTheory open Limits MonoidalCategory Category variable {I : Type u} [AddMonoid I] {C : Type*} [Category C] [MonoidalCategory C] namespace GradedObject /-- The tensor product of two graded objects `X₁` and `X₂` exists if for any `n`, the coproduct of the objects `X₁ i ⊗ X₂ j` for `i + j = n` exists. -/ abbrev HasTensor (X₁ X₂ : GradedObject I C) : Prop := HasMap (((mapBifunctor (curriedTensor C) I I).obj X₁).obj X₂) (fun ⟨i, j⟩ => i + j) namespace Monoidal /-- The tensor product of two graded objects. -/ noncomputable abbrev tensorObj (X₁ X₂ : GradedObject I C) [HasTensor X₁ X₂] : GradedObject I C := mapBifunctorMapObj (curriedTensor C) (fun ⟨i, j⟩ => i + j) X₁ X₂ section variable (X₁ X₂ : GradedObject I C) [HasTensor X₁ X₂] /-- The inclusion of a summand in a tensor product of two graded objects. -/ noncomputable def ιTensorObj (i₁ i₂ i₁₂ : I) (h : i₁ + i₂ = i₁₂) : X₁ i₁ ⊗ X₂ i₂ ⟶ tensorObj X₁ X₂ i₁₂ := ιMapBifunctorMapObj (curriedTensor C) _ _ _ _ _ _ h variable {X₁ X₂} @[ext] lemma tensorObj_ext {A : C} {j : I} (f g : tensorObj X₁ X₂ j ⟶ A) (h : ∀ (i₁ i₂ : I) (hi : i₁ + i₂ = j), ιTensorObj X₁ X₂ i₁ i₂ j hi ≫ f = ιTensorObj X₁ X₂ i₁ i₂ j hi ≫ g) : f = g := by apply mapObj_ext rintro ⟨i₁, i₂⟩ hi exact h i₁ i₂ hi /-- Constructor for morphisms from a tensor product of two graded objects. -/ noncomputable def tensorObjDesc {A : C} {k : I} (f : ∀ (i₁ i₂ : I) (_ : i₁ + i₂ = k), X₁ i₁ ⊗ X₂ i₂ ⟶ A) : tensorObj X₁ X₂ k ⟶ A := mapBifunctorMapObjDesc f @[reassoc (attr := simp)] lemma ι_tensorObjDesc {A : C} {k : I} (f : ∀ (i₁ i₂ : I) (_ : i₁ + i₂ = k), X₁ i₁ ⊗ X₂ i₂ ⟶ A) (i₁ i₂ : I) (hi : i₁ + i₂ = k) : ιTensorObj X₁ X₂ i₁ i₂ k hi ≫ tensorObjDesc f = f i₁ i₂ hi := by apply ι_mapBifunctorMapObjDesc end /-- The morphism `tensorObj X₁ Y₁ ⟶ tensorObj X₂ Y₂` induced by morphisms of graded objects `f : X₁ ⟶ X₂` and `g : Y₁ ⟶ Y₂`. -/ noncomputable def tensorHom {X₁ X₂ Y₁ Y₂ : GradedObject I C} (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) [HasTensor X₁ Y₁] [HasTensor X₂ Y₂] : tensorObj X₁ Y₁ ⟶ tensorObj X₂ Y₂ := mapBifunctorMapMap _ _ f g @[reassoc (attr := simp)] lemma ι_tensorHom {X₁ X₂ Y₁ Y₂ : GradedObject I C} (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) [HasTensor X₁ Y₁] [HasTensor X₂ Y₂] (i₁ i₂ i₁₂ : I) (h : i₁ + i₂ = i₁₂) : ιTensorObj X₁ Y₁ i₁ i₂ i₁₂ h ≫ tensorHom f g i₁₂ = (f i₁ ⊗ g i₂) ≫ ιTensorObj X₂ Y₂ i₁ i₂ i₁₂ h := by rw [MonoidalCategory.tensorHom_def, assoc] apply ι_mapBifunctorMapMap /-- The morphism `tensorObj X Y₁ ⟶ tensorObj X Y₂` induced by a morphism of graded objects `φ : Y₁ ⟶ Y₂`. -/ noncomputable abbrev whiskerLeft (X : GradedObject I C) {Y₁ Y₂ : GradedObject I C} (φ : Y₁ ⟶ Y₂) [HasTensor X Y₁] [HasTensor X Y₂] : tensorObj X Y₁ ⟶ tensorObj X Y₂ := tensorHom (𝟙 X) φ /-- The morphism `tensorObj X₁ Y ⟶ tensorObj X₂ Y` induced by a morphism of graded objects `φ : X₁ ⟶ X₂`. -/ noncomputable abbrev whiskerRight {X₁ X₂ : GradedObject I C} (φ : X₁ ⟶ X₂) (Y : GradedObject I C) [HasTensor X₁ Y] [HasTensor X₂ Y] : tensorObj X₁ Y ⟶ tensorObj X₂ Y := tensorHom φ (𝟙 Y) @[simp] lemma tensor_id (X Y : GradedObject I C) [HasTensor X Y] : tensorHom (𝟙 X) (𝟙 Y) = 𝟙 _ := by dsimp [tensorHom, mapBifunctorMapMap] simp only [Functor.map_id, NatTrans.id_app, comp_id, mapMap_id] rfl @[reassoc] lemma tensor_comp {X₁ X₂ X₃ Y₁ Y₂ Y₃ : GradedObject I C} (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃) (g₁ : Y₁ ⟶ Y₂) (g₂ : Y₂ ⟶ Y₃) [HasTensor X₁ Y₁] [HasTensor X₂ Y₂] [HasTensor X₃ Y₃] : tensorHom (f₁ ≫ f₂) (g₁ ≫ g₂) = tensorHom f₁ g₁ ≫ tensorHom f₂ g₂ := by dsimp only [tensorHom, mapBifunctorMapMap] rw [← mapMap_comp] apply congr_mapMap simp lemma tensorHom_def {X₁ X₂ Y₁ Y₂ : GradedObject I C} (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) [HasTensor X₁ Y₁] [HasTensor X₂ Y₂] [HasTensor X₂ Y₁] : tensorHom f g = whiskerRight f Y₁ ≫ whiskerLeft X₂ g := by rw [← tensor_comp, id_comp, comp_id] /-- This is the addition map `I × I × I → I` for an additive monoid `I`. -/ def r₁₂₃ : I × I × I → I := fun ⟨i, j, k⟩ => i + j + k /-- Auxiliary definition for `associator`. -/ @[reducible] def ρ₁₂ : BifunctorComp₁₂IndexData (r₁₂₃ : _ → I) where I₁₂ := I p := fun ⟨i₁, i₂⟩ => i₁ + i₂ q := fun ⟨i₁₂, i₃⟩ => i₁₂ + i₃ hpq := fun _ => rfl /-- Auxiliary definition for `associator`. -/ @[reducible] def ρ₂₃ : BifunctorComp₂₃IndexData (r₁₂₃ : _ → I) where I₂₃ := I p := fun ⟨i₂, i₃⟩ => i₂ + i₃ q := fun ⟨i₁₂, i₃⟩ => i₁₂ + i₃ hpq _ := (add_assoc _ _ _).symm variable (I) in /-- Auxiliary definition for `associator`. -/ @[reducible] def triangleIndexData : TriangleIndexData (r₁₂₃ : _ → I) (fun ⟨i₁, i₃⟩ => i₁ + i₃) where p₁₂ := fun ⟨i₁, i₂⟩ => i₁ + i₂ p₂₃ := fun ⟨i₂, i₃⟩ => i₂ + i₃ hp₁₂ := fun _ => rfl hp₂₃ := fun _ => (add_assoc _ _ _).symm h₁ := add_zero h₃ := zero_add /-- Given three graded objects `X₁`, `X₂`, `X₃` in `GradedObject I C`, this is the assumption that for all `i₁₂ : I` and `i₃ : I`, the tensor product functor `- ⊗ X₃ i₃` commutes with the coproduct of the objects `X₁ i₁ ⊗ X₂ i₂` such that `i₁ + i₂ = i₁₂`. -/ abbrev _root_.CategoryTheory.GradedObject.HasGoodTensor₁₂Tensor (X₁ X₂ X₃ : GradedObject I C) := HasGoodTrifunctor₁₂Obj (curriedTensor C) (curriedTensor C) ρ₁₂ X₁ X₂ X₃ /-- Given three graded objects `X₁`, `X₂`, `X₃` in `GradedObject I C`, this is the assumption that for all `i₁ : I` and `i₂₃ : I`, the tensor product functor `X₁ i₁ ⊗ -` commutes with the coproduct of the objects `X₂ i₂ ⊗ X₃ i₃` such that `i₂ + i₃ = i₂₃`. -/ abbrev _root_.CategoryTheory.GradedObject.HasGoodTensorTensor₂₃ (X₁ X₂ X₃ : GradedObject I C) := HasGoodTrifunctor₂₃Obj (curriedTensor C) (curriedTensor C) ρ₂₃ X₁ X₂ X₃ section variable (Z : C) (X₁ X₂ X₃ : GradedObject I C) {Y₁ Y₂ Y₃ : GradedObject I C} section variable [HasTensor X₂ X₃] [HasTensor X₁ (tensorObj X₂ X₃)] [HasTensor Y₂ Y₃] [HasTensor Y₁ (tensorObj Y₂ Y₃)] /-- The inclusion `X₁ i₁ ⊗ X₂ i₂ ⊗ X₃ i₃ ⟶ tensorObj X₁ (tensorObj X₂ X₃) j` when `i₁ + i₂ + i₃ = j`. -/ noncomputable def ιTensorObj₃ (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) : X₁ i₁ ⊗ X₂ i₂ ⊗ X₃ i₃ ⟶ tensorObj X₁ (tensorObj X₂ X₃) j := X₁ i₁ ◁ ιTensorObj X₂ X₃ i₂ i₃ _ rfl ≫ ιTensorObj X₁ (tensorObj X₂ X₃) i₁ (i₂ + i₃) j (by rw [← add_assoc, h]) @[reassoc] lemma ιTensorObj₃_eq (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) (i₂₃ : I) (h' : i₂ + i₃ = i₂₃) : ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j h = (X₁ i₁ ◁ ιTensorObj X₂ X₃ i₂ i₃ i₂₃ h') ≫ ιTensorObj X₁ (tensorObj X₂ X₃) i₁ i₂₃ j (by rw [← h', ← add_assoc, h]) := by subst h' rfl variable {X₁ X₂ X₃} @[reassoc (attr := simp)] lemma ιTensorObj₃_tensorHom (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) : ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ tensorHom f₁ (tensorHom f₂ f₃) j = (f₁ i₁ ⊗ f₂ i₂ ⊗ f₃ i₃) ≫ ιTensorObj₃ Y₁ Y₂ Y₃ i₁ i₂ i₃ j h := by rw [ιTensorObj₃_eq _ _ _ i₁ i₂ i₃ j h _ rfl, ιTensorObj₃_eq _ _ _ i₁ i₂ i₃ j h _ rfl, assoc, ι_tensorHom, ← id_tensorHom, ← id_tensorHom, ← MonoidalCategory.tensor_comp_assoc, ι_tensorHom, ← MonoidalCategory.tensor_comp_assoc, id_comp, comp_id] @[ext (iff := false)] lemma tensorObj₃_ext {j : I} {A : C} (f g : tensorObj X₁ (tensorObj X₂ X₃) j ⟶ A) [H : HasGoodTensorTensor₂₃ X₁ X₂ X₃] (h : ∀ (i₁ i₂ i₃ : I) (hi : i₁ + i₂ + i₃ = j), ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j hi ≫ f = ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j hi ≫ g) : f = g := by apply mapBifunctorBifunctor₂₃MapObj_ext (H := H) intro i₁ i₂ i₃ hi exact h i₁ i₂ i₃ hi end section variable [HasTensor X₁ X₂] [HasTensor (tensorObj X₁ X₂) X₃] [HasTensor Y₁ Y₂] [HasTensor (tensorObj Y₁ Y₂) Y₃] /-- The inclusion `X₁ i₁ ⊗ X₂ i₂ ⊗ X₃ i₃ ⟶ tensorObj (tensorObj X₁ X₂) X₃ j` when `i₁ + i₂ + i₃ = j`. -/ noncomputable def ιTensorObj₃' (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) : (X₁ i₁ ⊗ X₂ i₂) ⊗ X₃ i₃ ⟶ tensorObj (tensorObj X₁ X₂) X₃ j := (ιTensorObj X₁ X₂ i₁ i₂ (i₁ + i₂) rfl ▷ X₃ i₃) ≫ ιTensorObj (tensorObj X₁ X₂) X₃ (i₁ + i₂) i₃ j h @[reassoc] lemma ιTensorObj₃'_eq (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) (i₁₂ : I) (h' : i₁ + i₂ = i₁₂) : ιTensorObj₃' X₁ X₂ X₃ i₁ i₂ i₃ j h = (ιTensorObj X₁ X₂ i₁ i₂ i₁₂ h' ▷ X₃ i₃) ≫ ιTensorObj (tensorObj X₁ X₂) X₃ i₁₂ i₃ j (by rw [← h', h]) := by subst h' rfl variable {X₁ X₂ X₃} @[reassoc (attr := simp)] lemma ιTensorObj₃'_tensorHom (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) : ιTensorObj₃' X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ tensorHom (tensorHom f₁ f₂) f₃ j = ((f₁ i₁ ⊗ f₂ i₂) ⊗ f₃ i₃) ≫ ιTensorObj₃' Y₁ Y₂ Y₃ i₁ i₂ i₃ j h := by rw [ιTensorObj₃'_eq _ _ _ i₁ i₂ i₃ j h _ rfl, ιTensorObj₃'_eq _ _ _ i₁ i₂ i₃ j h _ rfl, assoc, ι_tensorHom, ← tensorHom_id, ← tensorHom_id, ← MonoidalCategory.tensor_comp_assoc, id_comp, ι_tensorHom, ← MonoidalCategory.tensor_comp_assoc, comp_id] @[ext (iff := false)] lemma tensorObj₃'_ext {j : I} {A : C} (f g : tensorObj (tensorObj X₁ X₂) X₃ j ⟶ A) [H : HasGoodTensor₁₂Tensor X₁ X₂ X₃] (h : ∀ (i₁ i₂ i₃ : I) (h : i₁ + i₂ + i₃ = j), ιTensorObj₃' X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ f = ιTensorObj₃' X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ g) : f = g := by apply mapBifunctor₁₂BifunctorMapObj_ext (H := H) intro i₁ i₂ i₃ hi exact h i₁ i₂ i₃ hi end section variable [HasTensor X₁ X₂] [HasTensor (tensorObj X₁ X₂) X₃] [HasTensor X₂ X₃] [HasTensor X₁ (tensorObj X₂ X₃)] /-- The associator isomorphism for graded objects. -/ noncomputable def associator [HasGoodTensor₁₂Tensor X₁ X₂ X₃] [HasGoodTensorTensor₂₃ X₁ X₂ X₃] : tensorObj (tensorObj X₁ X₂) X₃ ≅ tensorObj X₁ (tensorObj X₂ X₃) := mapBifunctorAssociator (MonoidalCategory.curriedAssociatorNatIso C) ρ₁₂ ρ₂₃ X₁ X₂ X₃ @[reassoc (attr := simp)] lemma ιTensorObj₃'_associator_hom [HasGoodTensor₁₂Tensor X₁ X₂ X₃] [HasGoodTensorTensor₂₃ X₁ X₂ X₃] (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) : ιTensorObj₃' X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (associator X₁ X₂ X₃).hom j = (α_ _ _ _).hom ≫ ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j h := ι_mapBifunctorAssociator_hom (MonoidalCategory.curriedAssociatorNatIso C) ρ₁₂ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h @[reassoc (attr := simp)] lemma ιTensorObj₃_associator_inv [HasGoodTensor₁₂Tensor X₁ X₂ X₃] [HasGoodTensorTensor₂₃ X₁ X₂ X₃] (i₁ i₂ i₃ j : I) (h : i₁ + i₂ + i₃ = j) : ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (associator X₁ X₂ X₃).inv j = (α_ _ _ _).inv ≫ ιTensorObj₃' X₁ X₂ X₃ i₁ i₂ i₃ j h := ι_mapBifunctorAssociator_inv (MonoidalCategory.curriedAssociatorNatIso C) ρ₁₂ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h variable {X₁ X₂ X₃} variable [HasTensor Y₁ Y₂] [HasTensor (tensorObj Y₁ Y₂) Y₃] [HasTensor Y₂ Y₃] [HasTensor Y₁ (tensorObj Y₂ Y₃)] in lemma associator_naturality (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) [HasGoodTensor₁₂Tensor X₁ X₂ X₃] [HasGoodTensorTensor₂₃ X₁ X₂ X₃] [HasGoodTensor₁₂Tensor Y₁ Y₂ Y₃] [HasGoodTensorTensor₂₃ Y₁ Y₂ Y₃] : tensorHom (tensorHom f₁ f₂) f₃ ≫ (associator Y₁ Y₂ Y₃).hom = (associator X₁ X₂ X₃).hom ≫ tensorHom f₁ (tensorHom f₂ f₃) := by aesop_cat end /-- Given `Z : C` and three graded objects `X₁`, `X₂` and `X₃` in `GradedObject I C`, this typeclass expresses that functor `Z ⊗ _` commutes with the coproduct of the objects `X₁ i₁ ⊗ (X₂ i₂ ⊗ X₃ i₃)` such that `i₁ + i₂ + i₃ = j` for a certain `j`. See lemma `left_tensor_tensorObj₃_ext`. -/ abbrev _root_.CategoryTheory.GradedObject.HasLeftTensor₃ObjExt (j : I) := PreservesColimit (Discrete.functor fun (i : { i : (I × I × I) | i.1 + i.2.1 + i.2.2 = j }) ↦ (((mapTrifunctor (bifunctorComp₂₃ (curriedTensor C) (curriedTensor C)) I I I).obj X₁).obj X₂).obj X₃ i) ((curriedTensor C).obj Z) variable {X₁ X₂ X₃} variable [HasTensor X₂ X₃] [HasTensor X₁ (tensorObj X₂ X₃)] @[ext (iff := false)] lemma left_tensor_tensorObj₃_ext {j : I} {A : C} (Z : C) (f g : Z ⊗ tensorObj X₁ (tensorObj X₂ X₃) j ⟶ A) [H : HasGoodTensorTensor₂₃ X₁ X₂ X₃] [hZ : HasLeftTensor₃ObjExt Z X₁ X₂ X₃ j] (h : ∀ (i₁ i₂ i₃ : I) (h : i₁ + i₂ + i₃ = j), (_ ◁ ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j h) ≫ f = (_ ◁ ιTensorObj₃ X₁ X₂ X₃ i₁ i₂ i₃ j h) ≫ g) : f = g := by refine (@isColimitOfPreserves C _ C _ _ _ _ ((curriedTensor C).obj Z) _ (isColimitCofan₃MapBifunctorBifunctor₂₃MapObj (H := H) j) hZ).hom_ext ?_ intro ⟨⟨i₁, i₂, i₃⟩, hi⟩ exact h _ _ _ hi end section variable (X₁ X₂ X₃ X₄ : GradedObject I C) [HasTensor X₃ X₄] [HasTensor X₂ (tensorObj X₃ X₄)] [HasTensor X₁ (tensorObj X₂ (tensorObj X₃ X₄))] /-- The inclusion `X₁ i₁ ⊗ X₂ i₂ ⊗ X₃ i₃ ⊗ X₄ i₄ ⟶ tensorObj X₁ (tensorObj X₂ (tensorObj X₃ X₄)) j` when `i₁ + i₂ + i₃ + i₄ = j`. -/ noncomputable def ιTensorObj₄ (i₁ i₂ i₃ i₄ j : I) (h : i₁ + i₂ + i₃ + i₄ = j) : X₁ i₁ ⊗ X₂ i₂ ⊗ X₃ i₃ ⊗ X₄ i₄ ⟶ tensorObj X₁ (tensorObj X₂ (tensorObj X₃ X₄)) j := (_ ◁ ιTensorObj₃ X₂ X₃ X₄ i₂ i₃ i₄ _ rfl) ≫ ιTensorObj X₁ (tensorObj X₂ (tensorObj X₃ X₄)) i₁ (i₂ + i₃ + i₄) j (by rw [← h, ← add_assoc, ← add_assoc]) lemma ιTensorObj₄_eq (i₁ i₂ i₃ i₄ j : I) (h : i₁ + i₂ + i₃ + i₄ = j) (i₂₃₄ : I) (hi : i₂ + i₃ + i₄ = i₂₃₄) : ιTensorObj₄ X₁ X₂ X₃ X₄ i₁ i₂ i₃ i₄ j h = (_ ◁ ιTensorObj₃ X₂ X₃ X₄ i₂ i₃ i₄ _ hi) ≫ ιTensorObj X₁ (tensorObj X₂ (tensorObj X₃ X₄)) i₁ i₂₃₄ j (by rw [← hi, ← add_assoc, ← add_assoc, h]) := by subst hi rfl /-- Given four graded objects, this is the condition `HasLeftTensor₃ObjExt (X₁ i₁) X₂ X₃ X₄ i₂₃₄` for all indices `i₁` and `i₂₃₄`, see the lemma `tensorObj₄_ext`. -/ abbrev _root_.CategoryTheory.GradedObject.HasTensor₄ObjExt := ∀ (i₁ i₂₃₄ : I), HasLeftTensor₃ObjExt (X₁ i₁) X₂ X₃ X₄ i₂₃₄ variable {X₁ X₂ X₃ X₄} @[ext (iff := false)] lemma tensorObj₄_ext {j : I} {A : C} (f g : tensorObj X₁ (tensorObj X₂ (tensorObj X₃ X₄)) j ⟶ A) [HasGoodTensorTensor₂₃ X₂ X₃ X₄] [H : HasTensor₄ObjExt X₁ X₂ X₃ X₄] (h : ∀ (i₁ i₂ i₃ i₄ : I) (h : i₁ + i₂ + i₃ + i₄ = j), ιTensorObj₄ X₁ X₂ X₃ X₄ i₁ i₂ i₃ i₄ j h ≫ f = ιTensorObj₄ X₁ X₂ X₃ X₄ i₁ i₂ i₃ i₄ j h ≫ g) : f = g := by apply tensorObj_ext intro i₁ i₂₃₄ h' apply left_tensor_tensorObj₃_ext intro i₂ i₃ i₄ h'' have hj : i₁ + i₂ + i₃ + i₄ = j := by simp only [← h', ← h'', add_assoc] simpa only [assoc, ιTensorObj₄_eq X₁ X₂ X₃ X₄ i₁ i₂ i₃ i₄ j hj i₂₃₄ h''] using h i₁ i₂ i₃ i₄ hj end section Pentagon variable (X₁ X₂ X₃ X₄ : GradedObject I C) [HasTensor X₁ X₂] [HasTensor X₂ X₃] [HasTensor X₃ X₄] [HasTensor (tensorObj X₁ X₂) X₃] [HasTensor X₁ (tensorObj X₂ X₃)] [HasTensor (tensorObj X₂ X₃) X₄] [HasTensor X₂ (tensorObj X₃ X₄)] [HasTensor (tensorObj (tensorObj X₁ X₂) X₃) X₄] [HasTensor (tensorObj X₁ (tensorObj X₂ X₃)) X₄] [HasTensor X₁ (tensorObj (tensorObj X₂ X₃) X₄)] [HasTensor X₁ (tensorObj X₂ (tensorObj X₃ X₄))] [HasTensor (tensorObj X₁ X₂) (tensorObj X₃ X₄)] [HasGoodTensor₁₂Tensor X₁ X₂ X₃] [HasGoodTensorTensor₂₃ X₁ X₂ X₃] [HasGoodTensor₁₂Tensor X₁ (tensorObj X₂ X₃) X₄] [HasGoodTensorTensor₂₃ X₁ (tensorObj X₂ X₃) X₄] [HasGoodTensor₁₂Tensor X₂ X₃ X₄] [HasGoodTensorTensor₂₃ X₂ X₃ X₄] [HasGoodTensor₁₂Tensor (tensorObj X₁ X₂) X₃ X₄] [HasGoodTensorTensor₂₃ (tensorObj X₁ X₂) X₃ X₄] [HasGoodTensor₁₂Tensor X₁ X₂ (tensorObj X₃ X₄)] [HasGoodTensorTensor₂₃ X₁ X₂ (tensorObj X₃ X₄)] [HasTensor₄ObjExt X₁ X₂ X₃ X₄] @[reassoc] lemma pentagon_inv : tensorHom (𝟙 X₁) (associator X₂ X₃ X₄).inv ≫ (associator X₁ (tensorObj X₂ X₃) X₄).inv ≫ tensorHom (associator X₁ X₂ X₃).inv (𝟙 X₄) = (associator X₁ X₂ (tensorObj X₃ X₄)).inv ≫ (associator (tensorObj X₁ X₂) X₃ X₄).inv := by ext j i₁ i₂ i₃ i₄ h dsimp conv_lhs => rw [ιTensorObj₄_eq X₁ X₂ X₃ X₄ i₁ i₂ i₃ i₄ j h _ rfl, assoc, ι_tensorHom_assoc] dsimp rw [id_tensorHom, ← MonoidalCategory.whiskerLeft_comp_assoc, ιTensorObj₃_associator_inv, ιTensorObj₃'_eq X₂ X₃ X₄ i₂ i₃ i₄ _ rfl _ rfl, MonoidalCategory.whiskerLeft_comp_assoc, MonoidalCategory.whiskerLeft_comp_assoc, ← ιTensorObj₃_eq_assoc X₁ (tensorObj X₂ X₃) X₄ i₁ (i₂ + i₃) i₄ j (by simp only [← add_assoc, h]) _ rfl, ιTensorObj₃_associator_inv_assoc, ιTensorObj₃'_eq_assoc X₁ (tensorObj X₂ X₃) X₄ i₁ (i₂ + i₃) i₄ j (by simp only [← add_assoc, h]) (i₁ + i₂ + i₃) (by rw [add_assoc]), ι_tensorHom] dsimp rw [tensorHom_id, whisker_assoc_symm_assoc, Iso.hom_inv_id_assoc, ← MonoidalCategory.comp_whiskerRight_assoc, ← MonoidalCategory.comp_whiskerRight_assoc, ← ιTensorObj₃_eq X₁ X₂ X₃ i₁ i₂ i₃ _ rfl _ rfl, ιTensorObj₃_associator_inv, MonoidalCategory.comp_whiskerRight_assoc, MonoidalCategory.pentagon_inv_assoc] conv_rhs => rw [ιTensorObj₄_eq X₁ X₂ X₃ X₄ i₁ i₂ i₃ i₄ _ _ _ rfl, ιTensorObj₃_eq X₂ X₃ X₄ i₂ i₃ i₄ _ rfl _ rfl, assoc, MonoidalCategory.whiskerLeft_comp_assoc, ← ιTensorObj₃_eq_assoc X₁ X₂ (tensorObj X₃ X₄) i₁ i₂ (i₃ + i₄) j (by rw [← add_assoc, h]) (i₂ + i₃ + i₄) (by rw [add_assoc]), ιTensorObj₃_associator_inv_assoc, whiskerLeft_whiskerLeft_associator_inv_assoc, ιTensorObj₃'_eq_assoc X₁ X₂ (tensorObj X₃ X₄) i₁ i₂ (i₃ + i₄) j (by rw [← add_assoc, h]) _ rfl, whisker_exchange_assoc, ← ιTensorObj₃_eq_assoc (tensorObj X₁ X₂) X₃ X₄ (i₁ + i₂) i₃ i₄ j h _ rfl, ιTensorObj₃_associator_inv, whiskerRight_tensor_assoc, Iso.hom_inv_id_assoc, ιTensorObj₃'_eq (tensorObj X₁ X₂) X₃ X₄ (i₁ + i₂) i₃ i₄ j h _ rfl, ← MonoidalCategory.comp_whiskerRight_assoc, ← ιTensorObj₃'_eq X₁ X₂ X₃ i₁ i₂ i₃ _ rfl _ rfl] lemma pentagon : tensorHom (associator X₁ X₂ X₃).hom (𝟙 X₄) ≫ (associator X₁ (tensorObj X₂ X₃) X₄).hom ≫ tensorHom (𝟙 X₁) (associator X₂ X₃ X₄).hom = (associator (tensorObj X₁ X₂) X₃ X₄).hom ≫ (associator X₁ X₂ (tensorObj X₃ X₄)).hom := by rw [← cancel_epi (associator (tensorObj X₁ X₂) X₃ X₄).inv, ← cancel_epi (associator X₁ X₂ (tensorObj X₃ X₄)).inv, Iso.inv_hom_id_assoc, Iso.inv_hom_id, ← pentagon_inv_assoc, ← tensor_comp_assoc, id_comp, Iso.inv_hom_id, tensor_id, id_comp, Iso.inv_hom_id_assoc, ← tensor_comp, id_comp, Iso.inv_hom_id, tensor_id] end Pentagon section TensorUnit variable [DecidableEq I] [HasInitial C] /-- The unit of the tensor product on graded objects is `(single₀ I).obj (𝟙_ C)`. -/ noncomputable def tensorUnit : GradedObject I C := (single₀ I).obj (𝟙_ C) /-- The canonical isomorphism `tensorUnit 0 ≅ 𝟙_ C` -/ noncomputable def tensorUnit₀ : (tensorUnit : GradedObject I C) 0 ≅ 𝟙_ C := singleObjApplyIso (0 : I) (𝟙_ C) /-- `tensorUnit i` is an initial object when `i ≠ 0`. -/ noncomputable def isInitialTensorUnitApply (i : I) (hi : i ≠ 0) : IsInitial ((tensorUnit : GradedObject I C) i) := isInitialSingleObjApply _ _ _ hi end TensorUnit section LeftUnitor variable [DecidableEq I] [HasInitial C] [∀ X₂, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).flip.obj X₂)] (X X' : GradedObject I C) instance : HasTensor tensorUnit X := mapBifunctorLeftUnitor_hasMap _ _ (leftUnitorNatIso C) _ zero_add _ instance : HasMap (((mapBifunctor (curriedTensor C) I I).obj ((single₀ I).obj (𝟙_ C))).obj X) (fun ⟨i₁, i₂⟩ => i₁ + i₂) := (inferInstance : HasTensor tensorUnit X) /-- The left unitor isomorphism for graded objects. -/ noncomputable def leftUnitor : tensorObj tensorUnit X ≅ X := mapBifunctorLeftUnitor (curriedTensor C) (𝟙_ C) (leftUnitorNatIso C) (fun (⟨i₁, i₂⟩ : I × I) => i₁ + i₂) zero_add X lemma leftUnitor_inv_apply (i : I) : (leftUnitor X).inv i = (λ_ (X i)).inv ≫ tensorUnit₀.inv ▷ (X i) ≫ ιTensorObj tensorUnit X 0 i i (zero_add i) := rfl variable {X X'} @[reassoc (attr := simp)] lemma leftUnitor_naturality (φ : X ⟶ X') : tensorHom (𝟙 (tensorUnit)) φ ≫ (leftUnitor X').hom = (leftUnitor X).hom ≫ φ := by apply mapBifunctorLeftUnitor_naturality end LeftUnitor section RightUnitor variable [DecidableEq I] [HasInitial C] [∀ X₁, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).obj X₁)] (X X' : GradedObject I C) instance : HasTensor X tensorUnit := mapBifunctorRightUnitor_hasMap (curriedTensor C) _ (rightUnitorNatIso C) _ add_zero _ instance : HasMap (((mapBifunctor (curriedTensor C) I I).obj X).obj ((single₀ I).obj (𝟙_ C))) (fun ⟨i₁, i₂⟩ => i₁ + i₂) := (inferInstance : HasTensor X tensorUnit) /-- The right unitor isomorphism for graded objects. -/ noncomputable def rightUnitor : tensorObj X tensorUnit ≅ X := mapBifunctorRightUnitor (curriedTensor C) (𝟙_ C) (rightUnitorNatIso C) (fun (⟨i₁, i₂⟩ : I × I) => i₁ + i₂) add_zero X lemma rightUnitor_inv_apply (i : I) : (rightUnitor X).inv i = (ρ_ (X i)).inv ≫ (X i) ◁ tensorUnit₀.inv ≫ ιTensorObj X tensorUnit i 0 i (add_zero i) := rfl variable {X X'} @[reassoc (attr := simp)] lemma rightUnitor_naturality (φ : X ⟶ X') : tensorHom φ (𝟙 (tensorUnit)) ≫ (rightUnitor X').hom = (rightUnitor X).hom ≫ φ := by apply mapBifunctorRightUnitor_naturality end RightUnitor section Triangle variable [DecidableEq I] [HasInitial C] [∀ X₁, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).obj X₁)] [∀ X₂, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).flip.obj X₂)] (X₁ X₃ : GradedObject I C) [HasTensor X₁ X₃] [HasTensor (tensorObj X₁ tensorUnit) X₃] [HasTensor X₁ (tensorObj tensorUnit X₃)] [HasGoodTensor₁₂Tensor X₁ tensorUnit X₃] [HasGoodTensorTensor₂₃ X₁ tensorUnit X₃] lemma triangle : (associator X₁ tensorUnit X₃).hom ≫ tensorHom (𝟙 X₁) (leftUnitor X₃).hom = tensorHom (rightUnitor X₁).hom (𝟙 X₃) := by convert mapBifunctor_triangle (curriedAssociatorNatIso C) (𝟙_ C) (rightUnitorNatIso C) (leftUnitorNatIso C) (triangleIndexData I) X₁ X₃ (by simp) end Triangle end Monoidal section variable [∀ (X₁ X₂ : GradedObject I C), HasTensor X₁ X₂] [∀ (X₁ X₂ X₃ : GradedObject I C), HasGoodTensor₁₂Tensor X₁ X₂ X₃] [∀ (X₁ X₂ X₃ : GradedObject I C), HasGoodTensorTensor₂₃ X₁ X₂ X₃] [DecidableEq I] [HasInitial C] [∀ X₁, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).obj X₁)] [∀ X₂, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).flip.obj X₂)] [∀ (X₁ X₂ X₃ X₄ : GradedObject I C), HasTensor₄ObjExt X₁ X₂ X₃ X₄] noncomputable instance monoidalCategory : MonoidalCategory (GradedObject I C) where tensorObj X Y := Monoidal.tensorObj X Y tensorHom f g := Monoidal.tensorHom f g tensorHom_def f g := Monoidal.tensorHom_def f g whiskerLeft X _ _ φ := Monoidal.whiskerLeft X φ whiskerRight {_ _ φ Y} := Monoidal.whiskerRight φ Y tensorUnit := Monoidal.tensorUnit associator X₁ X₂ X₃ := Monoidal.associator X₁ X₂ X₃ associator_naturality f₁ f₂ f₃ := Monoidal.associator_naturality f₁ f₂ f₃ leftUnitor X := Monoidal.leftUnitor X leftUnitor_naturality := Monoidal.leftUnitor_naturality rightUnitor X := Monoidal.rightUnitor X rightUnitor_naturality := Monoidal.rightUnitor_naturality tensor_comp f₁ f₂ g₁ g₂ := Monoidal.tensor_comp f₁ g₁ f₂ g₂ pentagon X₁ X₂ X₃ X₄ := Monoidal.pentagon X₁ X₂ X₃ X₄ triangle X₁ X₂ := Monoidal.triangle X₁ X₂ end section instance (n : ℕ) : Finite ((fun (i : ℕ × ℕ) => i.1 + i.2) ⁻¹' {n}) := by refine Finite.of_injective (fun ⟨⟨i₁, i₂⟩, (hi : i₁ + i₂ = n)⟩ => ((⟨i₁, by omega⟩, ⟨i₂, by omega⟩) : Fin (n + 1) × Fin (n + 1) )) ?_ rintro ⟨⟨_, _⟩, _⟩ ⟨⟨_, _⟩, _⟩ h simpa using h instance (n : ℕ) : Finite ({ i : (ℕ × ℕ × ℕ) | i.1 + i.2.1 + i.2.2 = n }) := by refine Finite.of_injective (fun ⟨⟨i₁, i₂, i₃⟩, (hi : i₁ + i₂ + i₃ = n)⟩ => (⟨⟨i₁, by omega⟩, ⟨i₂, by omega⟩, ⟨i₃, by omega⟩⟩ : Fin (n + 1) × Fin (n + 1) × Fin (n + 1))) ?_ rintro ⟨⟨_, _, _⟩, _⟩ ⟨⟨_, _, _⟩, _⟩ h simpa using h /-! The monoidal category structure on `GradedObject ℕ C` can be inferred from the assumptions `[HasFiniteCoproducts C]`, `[∀ (X : C), PreservesFiniteCoproducts ((curriedTensor C).obj X)]` and `[∀ (X : C), PreservesFiniteCoproducts ((curriedTensor C).flip.obj X)]`. This requires importing `Mathlib.CategoryTheory.Limits.Preserves.Finite`. -/ end end GradedObject end CategoryTheory
CategoryTheory\GradedObject\Single.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.GradedObject /-! # The graded object in a single degree In this file, we define the functor `GradedObject.single j : C ⥤ GradedObject J C` which sends an object `X : C` to the graded object which is `X` in degree `j` and the initial object of `C` in other degrees. -/ namespace CategoryTheory open Limits namespace GradedObject variable {J : Type*} {C : Type*} [Category C] [HasInitial C] [DecidableEq J] /-- The functor which sends `X : C` to the graded object which is `X` in degree `j` and the initial object in other degrees. -/ noncomputable def single (j : J) : C ⥤ GradedObject J C where obj X i := if i = j then X else ⊥_ C map {X₁ X₂} f i := if h : i = j then eqToHom (if_pos h) ≫ f ≫ eqToHom (if_pos h).symm else eqToHom (by dsimp; rw [if_neg h, if_neg h]) variable (J) in /-- The functor which sends `X : C` to the graded object which is `X` in degree `0` and the initial object in nonzero degrees. -/ noncomputable abbrev single₀ [Zero J] : C ⥤ GradedObject J C := single 0 /-- The canonical isomorphism `(single j).obj X i ≅ X` when `i = j`. -/ noncomputable def singleObjApplyIsoOfEq (j : J) (X : C) (i : J) (h : i = j) : (single j).obj X i ≅ X := eqToIso (if_pos h) /-- The canonical isomorphism `(single j).obj X j ≅ X`. -/ noncomputable abbrev singleObjApplyIso (j : J) (X : C) : (single j).obj X j ≅ X := singleObjApplyIsoOfEq j X j rfl /-- The object `(single j).obj X i` is initial when `i ≠ j`. -/ noncomputable def isInitialSingleObjApply (j : J) (X : C) (i : J) (h : i ≠ j) : IsInitial ((single j).obj X i) := by dsimp [single] rw [if_neg h] exact initialIsInitial lemma singleObjApplyIsoOfEq_inv_single_map (j : J) {X Y : C} (f : X ⟶ Y) (i : J) (h : i = j) : (singleObjApplyIsoOfEq j X i h).inv ≫ (single j).map f i = f ≫ (singleObjApplyIsoOfEq j Y i h).inv := by subst h simp [singleObjApplyIsoOfEq, single] lemma single_map_singleObjApplyIsoOfEq_hom (j : J) {X Y : C} (f : X ⟶ Y) (i : J) (h : i = j) : (single j).map f i ≫ (singleObjApplyIsoOfEq j Y i h).hom = (singleObjApplyIsoOfEq j X i h).hom ≫ f := by subst h simp [singleObjApplyIsoOfEq, single] @[reassoc (attr := simp)] lemma singleObjApplyIso_inv_single_map (j : J) {X Y : C} (f : X ⟶ Y) : (singleObjApplyIso j X).inv ≫ (single j).map f j = f ≫ (singleObjApplyIso j Y).inv := by apply singleObjApplyIsoOfEq_inv_single_map @[reassoc (attr := simp)] lemma single_map_singleObjApplyIso_hom (j : J) {X Y : C} (f : X ⟶ Y) : (single j).map f j ≫ (singleObjApplyIso j Y).hom = (singleObjApplyIso j X).hom ≫ f := by apply single_map_singleObjApplyIsoOfEq_hom variable (C) in /-- The composition of the single functor `single j : C ⥤ GradedObject J C` and the evaluation functor `eval j` identifies to the identity functor. -/ @[simps!] noncomputable def singleCompEval (j : J) : single j ⋙ eval j ≅ 𝟭 C := NatIso.ofComponents (singleObjApplyIso j) (by aesop_cat) end GradedObject end CategoryTheory
CategoryTheory\GradedObject\Trifunctor.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.GradedObject.Bifunctor import Mathlib.CategoryTheory.Functor.Trifunctor /-! # The action of trifunctors on graded objects Given a trifunctor `F. C₁ ⥤ C₂ ⥤ C₃ ⥤ C₄` and types `I₁`, `I₂` and `I₃`, we define a functor `GradedObject I₁ C₁ ⥤ GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject (I₁ × I₂ × I₃) C₄` (see `mapTrifunctor`). When we have a map `p : I₁ × I₂ × I₃ → J` and suitable coproducts exists, we define a functor `GradedObject I₁ C₁ ⥤ GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject J C₄` (see `mapTrifunctorMap`) which sends graded objects `X₁`, `X₂`, `X₃` to the graded object which sets `j` to the coproduct of the objects `((F.obj (X₁ i₁)).obj (X₂ i₂)).obj (X₃ i₃)` for `p ⟨i₁, i₂, i₃⟩ = j`. This shall be used in order to construct the associator isomorphism for the monoidal category structure on `GradedObject I C` induced by a monoidal structure on `C` and an additive monoid structure on `I` (TODO @joelriou). -/ namespace CategoryTheory open Category Limits variable {C₁ C₂ C₃ C₄ C₁₂ C₂₃ : Type*} [Category C₁] [Category C₂] [Category C₃] [Category C₄] [Category C₁₂] [Category C₂₃] (F F' : C₁ ⥤ C₂ ⥤ C₃ ⥤ C₄) namespace GradedObject /-- Auxiliary definition for `mapTrifunctor`. -/ @[simps] def mapTrifunctorObj {I₁ : Type*} (X₁ : GradedObject I₁ C₁) (I₂ I₃ : Type*) : GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject (I₁ × I₂ × I₃) C₄ where obj X₂ := { obj := fun X₃ x => ((F.obj (X₁ x.1)).obj (X₂ x.2.1)).obj (X₃ x.2.2) map := fun {X₃ Y₃} φ x => ((F.obj (X₁ x.1)).obj (X₂ x.2.1)).map (φ x.2.2) } map {X₂ Y₂} φ := { app := fun X₃ x => ((F.obj (X₁ x.1)).map (φ x.2.1)).app (X₃ x.2.2) } /-- Given a trifunctor `F : C₁ ⥤ C₂ ⥤ C₃ ⥤ C₄` and types `I₁`, `I₂`, `I₃`, this is the obvious functor `GradedObject I₁ C₁ ⥤ GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject (I₁ × I₂ × I₃) C₄`. -/ @[simps] def mapTrifunctor (I₁ I₂ I₃ : Type*) : GradedObject I₁ C₁ ⥤ GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject (I₁ × I₂ × I₃) C₄ where obj X₁ := mapTrifunctorObj F X₁ I₂ I₃ map {X₁ Y₁} φ := { app := fun X₂ => { app := fun X₃ x => ((F.map (φ x.1)).app (X₂ x.2.1)).app (X₃ x.2.2) } naturality := fun {X₂ Y₂} ψ => by ext X₃ x dsimp simp only [← NatTrans.comp_app] congr 1 rw [NatTrans.naturality] } section variable {F F'} /-- The natural transformation `mapTrifunctor F I₁ I₂ I₃ ⟶ mapTrifunctor F' I₁ I₂ I₃` induced by a natural transformation `F ⟶ F` of trifunctors. -/ @[simps] def mapTrifunctorMapNatTrans (α : F ⟶ F') (I₁ I₂ I₃ : Type*) : mapTrifunctor F I₁ I₂ I₃ ⟶ mapTrifunctor F' I₁ I₂ I₃ where app X₁ := { app := fun X₂ => { app := fun X₃ i => ((α.app _).app _).app _ } naturality := fun {X₂ Y₂} φ => by ext X₃ ⟨i₁, i₂, i₃⟩ dsimp simp only [← NatTrans.comp_app, NatTrans.naturality] } naturality := fun {X₁ Y₁} φ => by ext X₂ X₃ ⟨i₁, i₂, i₃⟩ dsimp simp only [← NatTrans.comp_app, NatTrans.naturality] /-- The natural isomorphism `mapTrifunctor F I₁ I₂ I₃ ≅ mapTrifunctor F' I₁ I₂ I₃` induced by a natural isomorphism `F ≅ F` of trifunctors. -/ @[simps] def mapTrifunctorMapIso (e : F ≅ F') (I₁ I₂ I₃ : Type*) : mapTrifunctor F I₁ I₂ I₃ ≅ mapTrifunctor F' I₁ I₂ I₃ where hom := mapTrifunctorMapNatTrans e.hom I₁ I₂ I₃ inv := mapTrifunctorMapNatTrans e.inv I₁ I₂ I₃ hom_inv_id := by ext X₁ X₂ X₃ ⟨i₁, i₂, i₃⟩ dsimp simp only [← NatTrans.comp_app, e.hom_inv_id, NatTrans.id_app] inv_hom_id := by ext X₁ X₂ X₃ ⟨i₁, i₂, i₃⟩ dsimp simp only [← NatTrans.comp_app, e.inv_hom_id, NatTrans.id_app] end section variable {I₁ I₂ I₃ J : Type*} (p : I₁ × I₂ × I₃ → J) /-- Given a trifunctor `F : C₁ ⥤ C₂ ⥤ C₃ ⥤ C₃`, graded objects `X₁ : GradedObject I₁ C₁`, `X₂ : GradedObject I₂ C₂`, `X₃ : GradedObject I₃ C₃`, and a map `p : I₁ × I₂ × I₃ → J`, this is the `J`-graded object sending `j` to the coproduct of `((F.obj (X₁ i₁)).obj (X₂ i₂)).obj (X₃ i₃)` for `p ⟨i₁, i₂, i₃⟩ = k`. -/ noncomputable def mapTrifunctorMapObj (X₁ : GradedObject I₁ C₁) (X₂ : GradedObject I₂ C₂) (X₃ : GradedObject I₃ C₃) [HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] : GradedObject J C₄ := ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃).mapObj p /-- The obvious inclusion `((F.obj (X₁ i₁)).obj (X₂ i₂)).obj (X₃ i₃) ⟶ mapTrifunctorMapObj F p X₁ X₂ X₃ j` when `p ⟨i₁, i₂, i₃⟩ = j`. -/ noncomputable def ιMapTrifunctorMapObj (X₁ : GradedObject I₁ C₁) (X₂ : GradedObject I₂ C₂) (X₃ : GradedObject I₃ C₃) (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : p ⟨i₁, i₂, i₃⟩ = j) [HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] : ((F.obj (X₁ i₁)).obj (X₂ i₂)).obj (X₃ i₃) ⟶ mapTrifunctorMapObj F p X₁ X₂ X₃ j := ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃).ιMapObj p ⟨i₁, i₂, i₃⟩ j h /-- The maps `mapTrifunctorMapObj F p X₁ X₂ X₃ ⟶ mapTrifunctorMapObj F p Y₁ Y₂ Y₃` which express the functoriality of `mapTrifunctorMapObj`, see `mapTrifunctorMap` -/ noncomputable def mapTrifunctorMapMap {X₁ Y₁ : GradedObject I₁ C₁} (f₁ : X₁ ⟶ Y₁) {X₂ Y₂ : GradedObject I₂ C₂} (f₂ : X₂ ⟶ Y₂) {X₃ Y₃ : GradedObject I₃ C₃} (f₃ : X₃ ⟶ Y₃) [HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] [HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj Y₁).obj Y₂).obj Y₃) p] : mapTrifunctorMapObj F p X₁ X₂ X₃ ⟶ mapTrifunctorMapObj F p Y₁ Y₂ Y₃ := GradedObject.mapMap ((((mapTrifunctor F I₁ I₂ I₃).map f₁).app X₂).app X₃ ≫ (((mapTrifunctor F I₁ I₂ I₃).obj Y₁).map f₂).app X₃ ≫ (((mapTrifunctor F I₁ I₂ I₃).obj Y₁).obj Y₂).map f₃) p @[reassoc (attr := simp)] lemma ι_mapTrifunctorMapMap {X₁ Y₁ : GradedObject I₁ C₁} (f₁ : X₁ ⟶ Y₁) {X₂ Y₂ : GradedObject I₂ C₂} (f₂ : X₂ ⟶ Y₂) {X₃ Y₃ : GradedObject I₃ C₃} (f₃ : X₃ ⟶ Y₃) [HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] [HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj Y₁).obj Y₂).obj Y₃) p] (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : p ⟨i₁, i₂, i₃⟩ = j) : ιMapTrifunctorMapObj F p X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ mapTrifunctorMapMap F p f₁ f₂ f₃ j = ((F.map (f₁ i₁)).app (X₂ i₂)).app (X₃ i₃) ≫ ((F.obj (Y₁ i₁)).map (f₂ i₂)).app (X₃ i₃) ≫ ((F.obj (Y₁ i₁)).obj (Y₂ i₂)).map (f₃ i₃) ≫ ιMapTrifunctorMapObj F p Y₁ Y₂ Y₃ i₁ i₂ i₃ j h := by dsimp only [ιMapTrifunctorMapObj, mapTrifunctorMapMap] rw [ι_mapMap] dsimp rw [assoc, assoc] @[ext] lemma mapTrifunctorMapObj_ext {X₁ : GradedObject I₁ C₁} {X₂ : GradedObject I₂ C₂} {X₃ : GradedObject I₃ C₃} {Y : C₄} (j : J) [HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] {φ φ' : mapTrifunctorMapObj F p X₁ X₂ X₃ j ⟶ Y} (h : ∀ (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (h : p ⟨i₁, i₂, i₃⟩ = j), ιMapTrifunctorMapObj F p X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ φ = ιMapTrifunctorMapObj F p X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ φ') : φ = φ' := by apply mapObj_ext rintro ⟨i₁, i₂, i₃⟩ hi apply h instance (X₁ : GradedObject I₁ C₁) (X₂ : GradedObject I₂ C₂) (X₃ : GradedObject I₃ C₃) [h : HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] : HasMap (((mapTrifunctorObj F X₁ I₂ I₃).obj X₂).obj X₃) p := h /-- Given a trifunctor `F : C₁ ⥤ C₂ ⥤ C₃ ⥤ C₄`, a map `p : I₁ × I₂ × I₃ → J`, and graded objects `X₁ : GradedObject I₁ C₁`, `X₂ : GradedObject I₂ C₂` and `X₃ : GradedObject I₃ C₃`, this is the `J`-graded object sending `j` to the coproduct of `((F.obj (X₁ i₁)).obj (X₂ i₂)).obj (X₃ i₃)` for `p ⟨i₁, i₂, i₃⟩ = j`. -/ @[simps] noncomputable def mapTrifunctorMapFunctorObj (X₁ : GradedObject I₁ C₁) [∀ X₂ X₃, HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] : GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject J C₄ where obj X₂ := { obj := fun X₃ => mapTrifunctorMapObj F p X₁ X₂ X₃ map := fun {X₃ Y₃} φ => mapTrifunctorMapMap F p (𝟙 X₁) (𝟙 X₂) φ map_id := fun X₃ => by dsimp ext j i₁ i₂ i₃ h simp only [ι_mapTrifunctorMapMap, categoryOfGradedObjects_id, Functor.map_id, NatTrans.id_app, id_comp, comp_id] map_comp := fun {X₃ Y₃ Z₃} φ ψ => by dsimp ext j i₁ i₂ i₃ h simp only [ι_mapTrifunctorMapMap, categoryOfGradedObjects_id, Functor.map_id, NatTrans.id_app, categoryOfGradedObjects_comp, Functor.map_comp, assoc, id_comp, ι_mapTrifunctorMapMap_assoc] } map {X₂ Y₂} φ := { app := fun X₃ => mapTrifunctorMapMap F p (𝟙 X₁) φ (𝟙 X₃) naturality := fun {X₃ Y₃} ψ => by ext j i₁ i₂ i₃ h dsimp simp only [ι_mapTrifunctorMapMap_assoc, categoryOfGradedObjects_id, Functor.map_id, NatTrans.id_app, ι_mapTrifunctorMapMap, id_comp, NatTrans.naturality_assoc] } map_id X₂ := by dsimp ext X₃ j i₁ i₂ i₃ h simp only [ι_mapTrifunctorMapMap, categoryOfGradedObjects_id, Functor.map_id, NatTrans.id_app, id_comp, comp_id] map_comp {X₂ Y₂ Z₂} φ ψ := by dsimp ext X₃ j i₁ i₂ i₃ simp only [ι_mapTrifunctorMapMap, categoryOfGradedObjects_id, Functor.map_id, NatTrans.id_app, categoryOfGradedObjects_comp, Functor.map_comp, NatTrans.comp_app, id_comp, assoc, ι_mapTrifunctorMapMap_assoc] /-- Given a trifunctor `F : C₁ ⥤ C₂ ⥤ C₃ ⥤ C₄` and a map `p : I₁ × I₂ × I₃ → J`, this is the functor `GradedObject I₁ C₁ ⥤ GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject J C₄` sending `X₁ : GradedObject I₁ C₁`, `X₂ : GradedObject I₂ C₂` and `X₃ : GradedObject I₃ C₃` to the `J`-graded object sending `j` to the coproduct of `((F.obj (X₁ i₁)).obj (X₂ i₂)).obj (X₃ i₃)` for `p ⟨i₁, i₂, i₃⟩ = j`. -/ @[simps] noncomputable def mapTrifunctorMap [∀ X₁ X₂ X₃, HasMap ((((mapTrifunctor F I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) p] : GradedObject I₁ C₁ ⥤ GradedObject I₂ C₂ ⥤ GradedObject I₃ C₃ ⥤ GradedObject J C₄ where obj X₁ := mapTrifunctorMapFunctorObj F p X₁ map := fun {X₁ Y₁} φ => { app := fun X₂ => { app := fun X₃ => mapTrifunctorMapMap F p φ (𝟙 X₂) (𝟙 X₃) naturality := fun {X₃ Y₃} φ => by dsimp ext j i₁ i₂ i₃ h dsimp simp only [ι_mapTrifunctorMapMap_assoc, categoryOfGradedObjects_id, Functor.map_id, NatTrans.id_app, ι_mapTrifunctorMapMap, id_comp, NatTrans.naturality_assoc] } naturality := fun {X₂ Y₂} ψ => by ext X₃ j dsimp ext i₁ i₂ i₃ h simp only [ι_mapTrifunctorMapMap_assoc, categoryOfGradedObjects_id, Functor.map_id, NatTrans.id_app, ι_mapTrifunctorMapMap, id_comp, NatTrans.naturality_app_assoc] } end section variable (F₁₂ : C₁ ⥤ C₂ ⥤ C₁₂) (G : C₁₂ ⥤ C₃ ⥤ C₄) {I₁ I₂ I₃ J : Type*} (r : I₁ × I₂ × I₃ → J) /-- Given a map `r : I₁ × I₂ × I₃ → J`, a `BifunctorComp₁₂IndexData r` consists of the data of a type `I₁₂`, maps `p : I₁ × I₂ → I₁₂` and `q : I₁₂ × I₃ → J`, such that `r` is obtained by composition of `p` and `q`. -/ structure BifunctorComp₁₂IndexData := /-- an auxiliary type -/ I₁₂ : Type* /-- a map `I₁ × I₂ → I₁₂` -/ p : I₁ × I₂ → I₁₂ /-- a map `I₁₂ × I₃ → J` -/ q : I₁₂ × I₃ → J hpq (i : I₁ × I₂ × I₃) : q ⟨p ⟨i.1, i.2.1⟩, i.2.2⟩ = r i variable {r} (ρ₁₂ : BifunctorComp₁₂IndexData r) (X₁ : GradedObject I₁ C₁) (X₂ : GradedObject I₂ C₂) (X₃ : GradedObject I₃ C₃) /-- Given bifunctors `F₁₂ : C₁ ⥤ C₂ ⥤ C₁₂`, `G : C₁₂ ⥤ C₃ ⥤ C₄`, graded objects `X₁ : GradedObject I₁ C₁`, `X₂ : GradedObject I₂ C₂`, `X₃ : GradedObject I₃ C₃` and `ρ₁₂ : BifunctorComp₁₂IndexData r`, this asserts that for all `i₁₂ : ρ₁₂.I₁₂` and `i₃ : I₃`, the functor `G(-, X₃ i₃)` commutes wich the coproducts of the `F₁₂(X₁ i₁, X₂ i₂)` such that `ρ₁₂.p ⟨i₁, i₂⟩ = i₁₂`. -/ abbrev HasGoodTrifunctor₁₂Obj := ∀ (i₁₂ : ρ₁₂.I₁₂) (i₃ : I₃), PreservesColimit (Discrete.functor (mapObjFun (((mapBifunctor F₁₂ I₁ I₂).obj X₁).obj X₂) ρ₁₂.p i₁₂)) ((Functor.flip G).obj (X₃ i₃)) variable [HasMap (((mapBifunctor F₁₂ I₁ I₂).obj X₁).obj X₂) ρ₁₂.p] [HasMap (((mapBifunctor G ρ₁₂.I₁₂ I₃).obj (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂)).obj X₃) ρ₁₂.q] /-- The inclusion of `(G.obj ((F₁₂.obj (X₁ i₁)).obj (X₂ i₂))).obj (X₃ i₃)` in `mapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ j` when `r (i₁, i₂, i₃) = j`. -/ noncomputable def ιMapBifunctor₁₂BifunctorMapObj (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : (G.obj ((F₁₂.obj (X₁ i₁)).obj (X₂ i₂))).obj (X₃ i₃) ⟶ mapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ j := (G.map (ιMapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂ i₁ i₂ _ rfl)).app (X₃ i₃) ≫ ιMapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ (ρ₁₂.p ⟨i₁, i₂⟩) i₃ j (by rw [← h, ← ρ₁₂.hpq]) @[reassoc] lemma ιMapBifunctor₁₂BifunctorMapObj_eq (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) (i₁₂ : ρ₁₂.I₁₂) (h₁₂ : ρ₁₂.p ⟨i₁, i₂⟩ = i₁₂) : ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j h = (G.map (ιMapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂ i₁ i₂ i₁₂ h₁₂)).app (X₃ i₃) ≫ ιMapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ i₁₂ i₃ j (by rw [← h₁₂, ← h, ← ρ₁₂.hpq]) := by subst h₁₂ rfl /-- The cofan consisting of the inclusions given by `ιMapBifunctor₁₂BifunctorMapObj`. -/ noncomputable def cofan₃MapBifunctor₁₂BifunctorMapObj (j : J) : ((((mapTrifunctor (bifunctorComp₁₂ F₁₂ G) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃).CofanMapObjFun r j := Cofan.mk (mapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ j) (fun ⟨⟨i₁, i₂, i₃⟩, (hi : r ⟨i₁, i₂, i₃⟩ = j)⟩ => ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j hi) variable [H : HasGoodTrifunctor₁₂Obj F₁₂ G ρ₁₂ X₁ X₂ X₃] /-- The cofan `cofan₃MapBifunctor₁₂BifunctorMapObj` is a colimit, see the induced isomorphism `mapBifunctorComp₁₂MapObjIso`. -/ noncomputable def isColimitCofan₃MapBifunctor₁₂BifunctorMapObj (j : J) : IsColimit (cofan₃MapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ j) := by let c₁₂ := fun i₁₂ => (((mapBifunctor F₁₂ I₁ I₂).obj X₁).obj X₂).cofanMapObj ρ₁₂.p i₁₂ have h₁₂ : ∀ i₁₂, IsColimit (c₁₂ i₁₂) := fun i₁₂ => (((mapBifunctor F₁₂ I₁ I₂).obj X₁).obj X₂).isColimitCofanMapObj ρ₁₂.p i₁₂ let c := (((mapBifunctor G ρ₁₂.I₁₂ I₃).obj (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂)).obj X₃).cofanMapObj ρ₁₂.q j have hc : IsColimit c := (((mapBifunctor G ρ₁₂.I₁₂ I₃).obj (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂)).obj X₃).isColimitCofanMapObj ρ₁₂.q j let c₁₂' := fun (i : ρ₁₂.q ⁻¹' {j}) => (G.flip.obj (X₃ i.1.2)).mapCocone (c₁₂ i.1.1) have hc₁₂' : ∀ i, IsColimit (c₁₂' i) := fun i => isColimitOfPreserves _ (h₁₂ i.1.1) let Z := (((mapTrifunctor (bifunctorComp₁₂ F₁₂ G) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃ let p' : I₁ × I₂ × I₃ → ρ₁₂.I₁₂ × I₃ := fun ⟨i₁, i₂, i₃⟩ => ⟨ρ₁₂.p ⟨i₁, i₂⟩, i₃⟩ let e : ∀ (i₁₂ : ρ₁₂.I₁₂) (i₃ : I₃), p' ⁻¹' {(i₁₂, i₃)} ≃ ρ₁₂.p ⁻¹' {i₁₂} := fun i₁₂ i₃ => { toFun := fun ⟨⟨i₁, i₂, i₃'⟩, hi⟩ => ⟨⟨i₁, i₂⟩, by aesop_cat⟩ invFun := fun ⟨⟨i₁, i₂⟩, hi⟩ => ⟨⟨i₁, i₂, i₃⟩, by aesop_cat⟩ left_inv := fun ⟨⟨i₁, i₂, i₃'⟩, hi⟩ => by obtain rfl : i₃ = i₃' := by aesop_cat rfl right_inv := fun _ => rfl } let c₁₂'' : ∀ (i : ρ₁₂.q ⁻¹' {j}), CofanMapObjFun Z p' (i.1.1, i.1.2) := fun ⟨⟨i₁₂, i₃⟩, hi⟩ => by refine (Cocones.precompose (Iso.hom ?_)).obj ((Cocones.whiskeringEquivalence (Discrete.equivalence (e i₁₂ i₃))).functor.obj (c₁₂' ⟨⟨i₁₂, i₃⟩, hi⟩)) refine (Discrete.natIso (fun ⟨⟨i₁, i₂, i₃'⟩, hi⟩ => (G.obj ((F₁₂.obj (X₁ i₁)).obj (X₂ i₂))).mapIso (eqToIso ?_))) obtain rfl : i₃' = i₃ := congr_arg _root_.Prod.snd hi rfl have h₁₂'' : ∀ i, IsColimit (c₁₂'' i) := fun _ => (IsColimit.precomposeHomEquiv _ _).symm (IsColimit.whiskerEquivalenceEquiv _ (hc₁₂' _)) refine IsColimit.ofIsoColimit (isColimitCofanMapObjComp Z p' ρ₁₂.q r ρ₁₂.hpq j (fun ⟨i₁₂, i₃⟩ h => c₁₂'' ⟨⟨i₁₂, i₃⟩, h⟩) (fun ⟨i₁₂, i₃⟩ h => h₁₂'' ⟨⟨i₁₂, i₃⟩, h⟩) c hc) (Cocones.ext (Iso.refl _) (fun ⟨⟨i₁, i₂, i₃⟩, h⟩ => ?_)) dsimp [Cofan.inj, c₁₂'', Z] rw [comp_id, Functor.map_id, id_comp] rfl variable {F₁₂ G ρ₁₂ X₁ X₂ X₃} lemma HasGoodTrifunctor₁₂Obj.hasMap : HasMap ((((mapTrifunctor (bifunctorComp₁₂ F₁₂ G) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) r := fun j => ⟨_, isColimitCofan₃MapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ j⟩ variable (F₁₂ G ρ₁₂ X₁ X₂ X₃) variable [HasMap ((((mapTrifunctor (bifunctorComp₁₂ F₁₂ G) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) r] /-- The action on graded objects of a trifunctor obtained by composition of two bifunctors can be computed as a composition of the actions of these two bifunctors. -/ noncomputable def mapBifunctorComp₁₂MapObjIso : mapTrifunctorMapObj (bifunctorComp₁₂ F₁₂ G) r X₁ X₂ X₃ ≅ mapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ := isoMk _ _ (fun j => (CofanMapObjFun.iso (isColimitCofan₃MapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ j)).symm) @[reassoc (attr := simp)] lemma ι_mapBifunctorComp₁₂MapObjIso_hom (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : ιMapTrifunctorMapObj (bifunctorComp₁₂ F₁₂ G) r X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (mapBifunctorComp₁₂MapObjIso F₁₂ G ρ₁₂ X₁ X₂ X₃).hom j = ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j h := by dsimp [mapBifunctorComp₁₂MapObjIso] apply CofanMapObjFun.ιMapObj_iso_inv @[reassoc (attr := simp)] lemma ι_mapBifunctorComp₁₂MapObjIso_inv (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (mapBifunctorComp₁₂MapObjIso F₁₂ G ρ₁₂ X₁ X₂ X₃).inv j = ιMapTrifunctorMapObj (bifunctorComp₁₂ F₁₂ G) r X₁ X₂ X₃ i₁ i₂ i₃ j h := CofanMapObjFun.inj_iso_hom (isColimitCofan₃MapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ j) _ h variable {X₁ X₂ X₃ F₁₂ G ρ₁₂} @[ext] lemma mapBifunctor₁₂BifunctorMapObj_ext {j : J} {A : C₄} (f g : mapBifunctorMapObj G ρ₁₂.q (mapBifunctorMapObj F₁₂ ρ₁₂.p X₁ X₂) X₃ j ⟶ A) (h : ∀ (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (h : r ⟨i₁, i₂, i₃⟩ = j), ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ f = ιMapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ g) : f = g := by apply Cofan.IsColimit.hom_ext (isColimitCofan₃MapBifunctor₁₂BifunctorMapObj F₁₂ G ρ₁₂ X₁ X₂ X₃ j) rintro ⟨i, hi⟩ exact h _ _ _ hi end section variable (F : C₁ ⥤ C₂₃ ⥤ C₄) (G₂₃ : C₂ ⥤ C₃ ⥤ C₂₃) {I₁ I₂ I₃ J : Type*} (r : I₁ × I₂ × I₃ → J) /-- Given a map `r : I₁ × I₂ × I₃ → J`, a `BifunctorComp₂₃IndexData r` consists of the data of a type `I₂₃`, maps `p : I₂ × I₃ → I₂₃` and `q : I₁ × I₂₃ → J`, such that `r` is obtained by composition of `p` and `q`. -/ structure BifunctorComp₂₃IndexData := /-- an auxiliary type -/ I₂₃ : Type* /-- a map `I₂ × I₃ → I₂₃` -/ p : I₂ × I₃ → I₂₃ /-- a map `I₁ × I₂₃ → J` -/ q : I₁ × I₂₃ → J hpq (i : I₁ × I₂ × I₃) : q ⟨i.1, p i.2⟩ = r i variable {r} (ρ₂₃ : BifunctorComp₂₃IndexData r) (X₁ : GradedObject I₁ C₁) (X₂ : GradedObject I₂ C₂) (X₃ : GradedObject I₃ C₃) /-- Given bifunctors `F : C₁ ⥤ C₂₃ ⥤ C₄`, `G₂₃ : C₂ ⥤ C₃ ⥤ C₂₃`, graded objects `X₁ : GradedObject I₁ C₁`, `X₂ : GradedObject I₂ C₂`, `X₃ : GradedObject I₃ C₃` and `ρ₂₃ : BifunctorComp₂₃IndexData r`, this asserts that for all `i₁ : I₁` and `i₂₃ : ρ₂₃.I₂₃`, the functor `F(X₁ i₁, _)` commutes wich the coproducts of the `G₂₃(X₂ i₂, X₃ i₃)` such that `ρ₂₃.p ⟨i₂, i₃⟩ = i₂₃`. -/ abbrev HasGoodTrifunctor₂₃Obj := ∀ (i₁ : I₁) (i₂₃ : ρ₂₃.I₂₃), PreservesColimit (Discrete.functor (mapObjFun (((mapBifunctor G₂₃ I₂ I₃).obj X₂).obj X₃) ρ₂₃.p i₂₃)) (F.obj (X₁ i₁)) variable [HasMap (((mapBifunctor G₂₃ I₂ I₃).obj X₂).obj X₃) ρ₂₃.p] [HasMap (((mapBifunctor F I₁ ρ₂₃.I₂₃).obj X₁).obj (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃)) ρ₂₃.q] /-- The inclusion of `(F.obj (X₁ i₁)).obj ((G₂₃.obj (X₂ i₂)).obj (X₃ i₃))` in `mapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) j` when `r (i₁, i₂, i₃) = j`. -/ noncomputable def ιMapBifunctorBifunctor₂₃MapObj (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : (F.obj (X₁ i₁)).obj ((G₂₃.obj (X₂ i₂)).obj (X₃ i₃)) ⟶ mapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) j := (F.obj (X₁ i₁)).map (ιMapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃ i₂ i₃ _ rfl) ≫ ιMapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) i₁ (ρ₂₃.p ⟨i₂, i₃⟩) j (by rw [← h, ← ρ₂₃.hpq]) @[reassoc] lemma ιMapBifunctorBifunctor₂₃MapObj_eq (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) (i₂₃ : ρ₂₃.I₂₃) (h₂₃ : ρ₂₃.p ⟨i₂, i₃⟩ = i₂₃) : ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h = (F.obj (X₁ i₁)).map (ιMapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃ i₂ i₃ i₂₃ h₂₃) ≫ ιMapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) i₁ i₂₃ j (by rw [← h, ← h₂₃, ← ρ₂₃.hpq]) := by subst h₂₃ rfl /-- The cofan consisting of the inclusions given by `ιMapBifunctorBifunctor₂₃MapObj`. -/ noncomputable def cofan₃MapBifunctorBifunctor₂₃MapObj (j : J) : ((((mapTrifunctor (bifunctorComp₂₃ F G₂₃) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃).CofanMapObjFun r j := Cofan.mk (mapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) j) (fun ⟨⟨i₁, i₂, i₃⟩, (hi : r ⟨i₁, i₂, i₃⟩ = j)⟩ => ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j hi) variable [H : HasGoodTrifunctor₂₃Obj F G₂₃ ρ₂₃ X₁ X₂ X₃] /-- The cofan `cofan₃MapBifunctorBifunctor₂₃MapObj` is a colimit, see the induced isomorphism `mapBifunctorComp₁₂MapObjIso`. -/ noncomputable def isColimitCofan₃MapBifunctorBifunctor₂₃MapObj (j : J) : IsColimit (cofan₃MapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ j) := by let c₂₃ := fun i₂₃ => (((mapBifunctor G₂₃ I₂ I₃).obj X₂).obj X₃).cofanMapObj ρ₂₃.p i₂₃ have h₂₃ : ∀ i₂₃, IsColimit (c₂₃ i₂₃) := fun i₂₃ => (((mapBifunctor G₂₃ I₂ I₃).obj X₂).obj X₃).isColimitCofanMapObj ρ₂₃.p i₂₃ let c := (((mapBifunctor F I₁ ρ₂₃.I₂₃).obj X₁).obj (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃)).cofanMapObj ρ₂₃.q j have hc : IsColimit c := (((mapBifunctor F I₁ ρ₂₃.I₂₃).obj X₁).obj (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃)).isColimitCofanMapObj ρ₂₃.q j let c₂₃' := fun (i : ρ₂₃.q ⁻¹' {j}) => (F.obj (X₁ i.1.1)).mapCocone (c₂₃ i.1.2) have hc₂₃' : ∀ i, IsColimit (c₂₃' i) := fun i => isColimitOfPreserves _ (h₂₃ i.1.2) let Z := (((mapTrifunctor (bifunctorComp₂₃ F G₂₃) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃ let p' : I₁ × I₂ × I₃ → I₁ × ρ₂₃.I₂₃ := fun ⟨i₁, i₂, i₃⟩ => ⟨i₁, ρ₂₃.p ⟨i₂, i₃⟩⟩ let e : ∀ (i₁ : I₁) (i₂₃ : ρ₂₃.I₂₃) , p' ⁻¹' {(i₁, i₂₃)} ≃ ρ₂₃.p ⁻¹' {i₂₃} := fun i₁ i₂₃ => { toFun := fun ⟨⟨i₁', i₂, i₃⟩, hi⟩ => ⟨⟨i₂, i₃⟩, by aesop_cat⟩ invFun := fun ⟨⟨i₂, i₃⟩, hi⟩ => ⟨⟨i₁, i₂, i₃⟩, by aesop_cat⟩ left_inv := fun ⟨⟨i₁', i₂, i₃⟩, hi⟩ => by obtain rfl : i₁ = i₁' := by aesop_cat rfl right_inv := fun _ => rfl } let c₂₃'' : ∀ (i : ρ₂₃.q ⁻¹' {j}), CofanMapObjFun Z p' (i.1.1, i.1.2) := fun ⟨⟨i₁, i₂₃⟩, hi⟩ => by refine (Cocones.precompose (Iso.hom ?_)).obj ((Cocones.whiskeringEquivalence (Discrete.equivalence (e i₁ i₂₃))).functor.obj (c₂₃' ⟨⟨i₁, i₂₃⟩, hi⟩)) refine Discrete.natIso (fun ⟨⟨i₁', i₂, i₃⟩, hi⟩ => eqToIso ?_) obtain rfl : i₁' = i₁ := congr_arg _root_.Prod.fst hi rfl have h₂₃'' : ∀ i, IsColimit (c₂₃'' i) := fun _ => (IsColimit.precomposeHomEquiv _ _).symm (IsColimit.whiskerEquivalenceEquiv _ (hc₂₃' _)) refine IsColimit.ofIsoColimit (isColimitCofanMapObjComp Z p' ρ₂₃.q r ρ₂₃.hpq j (fun ⟨i₁, i₂₃⟩ h => c₂₃'' ⟨⟨i₁, i₂₃⟩, h⟩) (fun ⟨i₁, i₂₃⟩ h => h₂₃'' ⟨⟨i₁, i₂₃⟩, h⟩) c hc) (Cocones.ext (Iso.refl _) (fun ⟨⟨i₁, i₂, i₃⟩, h⟩ => ?_)) dsimp [Cofan.inj, c₂₃''] rw [comp_id, id_comp] rfl variable {F₁₂ G ρ₁₂ X₁ X₂ X₃} lemma HasGoodTrifunctor₂₃Obj.hasMap : HasMap ((((mapTrifunctor (bifunctorComp₂₃ F G₂₃) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) r := fun j => ⟨_, isColimitCofan₃MapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ j⟩ variable (F₁₂ G ρ₁₂ X₁ X₂ X₃) variable [HasMap ((((mapTrifunctor (bifunctorComp₂₃ F G₂₃) I₁ I₂ I₃).obj X₁).obj X₂).obj X₃) r] /-- The action on graded objects of a trifunctor obtained by composition of two bifunctors can be computed as a composition of the actions of these two bifunctors. -/ noncomputable def mapBifunctorComp₂₃MapObjIso : mapTrifunctorMapObj (bifunctorComp₂₃ F G₂₃) r X₁ X₂ X₃ ≅ mapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) := isoMk _ _ (fun j => (CofanMapObjFun.iso (isColimitCofan₃MapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ j)).symm) @[reassoc (attr := simp)] lemma ι_mapBifunctorComp₂₃MapObjIso_hom (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : ιMapTrifunctorMapObj (bifunctorComp₂₃ F G₂₃) r X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (mapBifunctorComp₂₃MapObjIso F G₂₃ ρ₂₃ X₁ X₂ X₃).hom j = ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h := by dsimp [mapBifunctorComp₂₃MapObjIso] apply CofanMapObjFun.ιMapObj_iso_inv @[reassoc (attr := simp)] lemma ι_mapBifunctorComp₂₃MapObjIso_inv (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (j : J) (h : r (i₁, i₂, i₃) = j) : ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ (mapBifunctorComp₂₃MapObjIso F G₂₃ ρ₂₃ X₁ X₂ X₃).inv j = ιMapTrifunctorMapObj (bifunctorComp₂₃ F G₂₃) r X₁ X₂ X₃ i₁ i₂ i₃ j h := CofanMapObjFun.inj_iso_hom (isColimitCofan₃MapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ j) _ h variable {X₁ X₂ X₃ F₁₂ G ρ₁₂} @[ext] lemma mapBifunctorBifunctor₂₃MapObj_ext {j : J} {A : C₄} (f g : mapBifunctorMapObj F ρ₂₃.q X₁ (mapBifunctorMapObj G₂₃ ρ₂₃.p X₂ X₃) j ⟶ A) (h : ∀ (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) (h : r ⟨i₁, i₂, i₃⟩ = j), ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ f = ιMapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ i₁ i₂ i₃ j h ≫ g) : f = g := by apply Cofan.IsColimit.hom_ext (isColimitCofan₃MapBifunctorBifunctor₂₃MapObj F G₂₃ ρ₂₃ X₁ X₂ X₃ j) rintro ⟨i, hi⟩ exact h _ _ _ hi end end GradedObject end CategoryTheory
CategoryTheory\GradedObject\Unitor.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.GradedObject.Associator import Mathlib.CategoryTheory.GradedObject.Single /-! # The left and right unitors Given a bifunctor `F : C ⥤ D ⥤ D`, an object `X : C` such that `F.obj X ≅ 𝟭 D` and a map `p : I × J → J` such that `hp : ∀ (j : J), p ⟨0, j⟩ = j`, we define an isomorphism of `J`-graded objects for any `Y : GradedObject J D`. `mapBifunctorLeftUnitor F X e p hp Y : mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y`. Under similar assumptions, we also obtain a right unitor isomorphism `mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X`. Finally, the lemma `mapBifunctor_triangle` promotes a triangle identity involving functors to a triangle identity for the induced functors on graded objects. -/ namespace CategoryTheory open Category Limits namespace GradedObject section LeftUnitor variable {C D I J : Type*} [Category C] [Category D] [Zero I] [DecidableEq I] [HasInitial C] (F : C ⥤ D ⥤ D) (X : C) (e : F.obj X ≅ 𝟭 D) [∀ (Y : D), PreservesColimit (Functor.empty.{0} C) (F.flip.obj Y)] (p : I × J → J) (hp : ∀ (j : J), p ⟨0, j⟩ = j) (Y Y' : GradedObject J D) (φ : Y ⟶ Y') /-- Given `F : C ⥤ D ⥤ D`, `X : C`, `e : F.obj X ≅ 𝟭 D` and `Y : GradedObject J D`, this is the isomorphism `((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a ≅ Y a.2` when `a : I × J` is such that `a.1 = 0`. -/ @[simps!] noncomputable def mapBifunctorObjSingle₀ObjIso (a : I × J) (ha : a.1 = 0) : ((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a ≅ Y a.2 := (F.mapIso (singleObjApplyIsoOfEq _ X _ ha)).app _ ≪≫ e.app (Y a.2) /-- Given `F : C ⥤ D ⥤ D`, `X : C` and `Y : GradedObject J D`, `((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a` is an initial object when `a : I × J` is such that `a.1 ≠ 0`. -/ noncomputable def mapBifunctorObjSingle₀ObjIsInitial (a : I × J) (ha : a.1 ≠ 0) : IsInitial (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a) := IsInitial.isInitialObj (F.flip.obj (Y a.2)) _ (isInitialSingleObjApply _ _ _ ha) /-- Given `F : C ⥤ D ⥤ D`, `X : C`, `e : F.obj X ≅ 𝟭 D`, `Y : GradedObject J D` and `p : I × J → J` such that `p ⟨0, j⟩ = j` for all `j`, this is the (colimit) cofan which shall be used to construct the isomorphism `mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y`, see `mapBifunctorLeftUnitor`. -/ noncomputable def mapBifunctorLeftUnitorCofan (hp : ∀ (j : J), p ⟨0, j⟩ = j) (Y) (j : J) : (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y).CofanMapObjFun p j := CofanMapObjFun.mk _ _ _ (Y j) (fun a ha => if ha : a.1 = 0 then (mapBifunctorObjSingle₀ObjIso F X e Y a ha).hom ≫ eqToHom (by aesop) else (mapBifunctorObjSingle₀ObjIsInitial F X Y a ha).to _) @[simp, reassoc] lemma mapBifunctorLeftUnitorCofan_inj (j : J) : (mapBifunctorLeftUnitorCofan F X e p hp Y j).inj ⟨⟨0, j⟩, hp j⟩ = (F.map (singleObjApplyIso (0 : I) X).hom).app (Y j) ≫ e.hom.app (Y j) := by simp [mapBifunctorLeftUnitorCofan] /-- The cofan `mapBifunctorLeftUnitorCofan F X e p hp Y j` is a colimit. -/ noncomputable def mapBifunctorLeftUnitorCofanIsColimit (j : J) : IsColimit (mapBifunctorLeftUnitorCofan F X e p hp Y j) := mkCofanColimit _ (fun s => e.inv.app (Y j) ≫ (F.map (singleObjApplyIso (0 : I) X).inv).app (Y j) ≫ s.inj ⟨⟨0, j⟩, hp j⟩) (fun s => by rintro ⟨⟨i, j'⟩, h⟩ by_cases hi : i = 0 · subst hi simp only [Set.mem_preimage, hp, Set.mem_singleton_iff] at h subst h simp · apply IsInitial.hom_ext exact mapBifunctorObjSingle₀ObjIsInitial _ _ _ _ hi) (fun s m hm => by simp [← hm ⟨⟨0, j⟩, hp j⟩]) lemma mapBifunctorLeftUnitor_hasMap : HasMap (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y) p := CofanMapObjFun.hasMap _ _ _ (mapBifunctorLeftUnitorCofanIsColimit F X e p hp Y) variable [HasMap (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y) p] [HasMap (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y') p] /-- Given `F : C ⥤ D ⥤ D`, `X : C`, `e : F.obj X ≅ 𝟭 D`, `Y : GradedObject J D` and `p : I × J → J` such that `p ⟨0, j⟩ = j` for all `j`, this is the left unitor isomorphism `mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y`. -/ noncomputable def mapBifunctorLeftUnitor : mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y := isoMk _ _ (fun j => (CofanMapObjFun.iso (mapBifunctorLeftUnitorCofanIsColimit F X e p hp Y j)).symm) @[reassoc (attr := simp)] lemma ι_mapBifunctorLeftUnitor_hom_apply (j : J) : ιMapBifunctorMapObj F p ((single₀ I).obj X) Y 0 j j (hp j) ≫ (mapBifunctorLeftUnitor F X e p hp Y).hom j = (F.map (singleObjApplyIso (0 : I) X).hom).app _ ≫ e.hom.app (Y j) := by dsimp [mapBifunctorLeftUnitor] erw [CofanMapObjFun.ιMapObj_iso_inv] rw [mapBifunctorLeftUnitorCofan_inj] lemma mapBifunctorLeftUnitor_inv_apply (j : J) : (mapBifunctorLeftUnitor F X e p hp Y).inv j = e.inv.app (Y j) ≫ (F.map (singleObjApplyIso (0 : I) X).inv).app (Y j) ≫ ιMapBifunctorMapObj F p ((single₀ I).obj X) Y 0 j j (hp j) := rfl variable {Y Y'} @[reassoc] lemma mapBifunctorLeftUnitor_inv_naturality : φ ≫ (mapBifunctorLeftUnitor F X e p hp Y').inv = (mapBifunctorLeftUnitor F X e p hp Y).inv ≫ mapBifunctorMapMap F p (𝟙 _) φ := by ext j dsimp rw [mapBifunctorLeftUnitor_inv_apply, mapBifunctorLeftUnitor_inv_apply, assoc, assoc, ι_mapBifunctorMapMap] dsimp rw [Functor.map_id, NatTrans.id_app, id_comp] erw [← NatTrans.naturality_assoc, ← NatTrans.naturality_assoc] rfl @[reassoc] lemma mapBifunctorLeftUnitor_naturality : mapBifunctorMapMap F p (𝟙 _) φ ≫ (mapBifunctorLeftUnitor F X e p hp Y').hom = (mapBifunctorLeftUnitor F X e p hp Y).hom ≫ φ := by rw [← cancel_mono (mapBifunctorLeftUnitor F X e p hp Y').inv, assoc, assoc, Iso.hom_inv_id, comp_id, mapBifunctorLeftUnitor_inv_naturality, Iso.hom_inv_id_assoc] end LeftUnitor section RightUnitor variable {C D I J : Type*} [Category C] [Category D] [Zero I] [DecidableEq I] [HasInitial C] (F : D ⥤ C ⥤ D) (Y : C) (e : F.flip.obj Y ≅ 𝟭 D) [∀ (X : D), PreservesColimit (Functor.empty.{0} C) (F.obj X)] (p : J × I → J) (hp : ∀ (j : J), p ⟨j, 0⟩ = j) (X X' : GradedObject J D) (φ : X ⟶ X') /-- Given `F : D ⥤ C ⥤ D`, `Y : C`, `e : F.flip.obj X ≅ 𝟭 D` and `X : GradedObject J D`, this is the isomorphism `((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y) a ≅ Y a.2` when `a : J × I` is such that `a.2 = 0`. -/ @[simps!] noncomputable def mapBifunctorObjObjSingle₀Iso (a : J × I) (ha : a.2 = 0) : ((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y) a ≅ X a.1 := Functor.mapIso _ (singleObjApplyIsoOfEq _ Y _ ha) ≪≫ e.app (X a.1) /-- Given `F : D ⥤ C ⥤ D`, `Y : C` and `X : GradedObject J D`, `((mapBifunctor F J I).obj X).obj ((single₀ I).obj X) a` is an initial when `a : J × I` is such that `a.2 ≠ 0`. -/ noncomputable def mapBifunctorObjObjSingle₀IsInitial (a : J × I) (ha : a.2 ≠ 0) : IsInitial (((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y) a) := IsInitial.isInitialObj (F.obj (X a.1)) _ (isInitialSingleObjApply _ _ _ ha) /-- Given `F : D ⥤ C ⥤ D`, `Y : C`, `e : F.flip.obj Y ≅ 𝟭 D`, `X : GradedObject J D` and `p : J × I → J` such that `p ⟨j, 0⟩ = j` for all `j`, this is the (colimit) cofan which shall be used to construct the isomorphism `mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X`, see `mapBifunctorRightUnitor`. -/ noncomputable def mapBifunctorRightUnitorCofan (hp : ∀ (j : J), p ⟨j, 0⟩ = j) (X) (j : J) : (((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y)).CofanMapObjFun p j := CofanMapObjFun.mk _ _ _ (X j) (fun a ha => if ha : a.2 = 0 then (mapBifunctorObjObjSingle₀Iso F Y e X a ha).hom ≫ eqToHom (by aesop) else (mapBifunctorObjObjSingle₀IsInitial F Y X a ha).to _) @[simp, reassoc] lemma mapBifunctorRightUnitorCofan_inj (j : J) : (mapBifunctorRightUnitorCofan F Y e p hp X j).inj ⟨⟨j, 0⟩, hp j⟩ = (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).hom ≫ e.hom.app (X j) := by simp [mapBifunctorRightUnitorCofan] /-- The cofan `mapBifunctorRightUnitorCofan F Y e p hp X j` is a colimit. -/ noncomputable def mapBifunctorRightUnitorCofanIsColimit (j : J) : IsColimit (mapBifunctorRightUnitorCofan F Y e p hp X j) := mkCofanColimit _ (fun s => e.inv.app (X j) ≫ (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).inv ≫ s.inj ⟨⟨j, 0⟩, hp j⟩) (fun s => by rintro ⟨⟨j', i⟩, h⟩ by_cases hi : i = 0 · subst hi simp only [Set.mem_preimage, hp, Set.mem_singleton_iff] at h subst h dsimp rw [mapBifunctorRightUnitorCofan_inj, assoc, Iso.hom_inv_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id, Functor.map_id, id_comp] · apply IsInitial.hom_ext exact mapBifunctorObjObjSingle₀IsInitial _ _ _ _ hi) (fun s m hm => by dsimp rw [← hm ⟨⟨j, 0⟩, hp j⟩, mapBifunctorRightUnitorCofan_inj, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id, Functor.map_id, id_comp, Iso.inv_hom_id_app_assoc]) lemma mapBifunctorRightUnitor_hasMap : HasMap (((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y)) p := CofanMapObjFun.hasMap _ _ _ (mapBifunctorRightUnitorCofanIsColimit F Y e p hp X) variable [HasMap (((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y)) p] [HasMap (((mapBifunctor F J I).obj X').obj ((single₀ I).obj Y)) p] /-- Given `F : D ⥤ C ⥤ D`, `Y : C`, `e : F.flip.obj Y ≅ 𝟭 D`, `X : GradedObject J D` and `p : J × I → J` such that `p ⟨j, 0⟩ = j` for all `j`, this is the right unitor isomorphism `mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X`. -/ noncomputable def mapBifunctorRightUnitor : mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X := isoMk _ _ (fun j => (CofanMapObjFun.iso (mapBifunctorRightUnitorCofanIsColimit F Y e p hp X j)).symm) @[reassoc (attr := simp)] lemma ι_mapBifunctorRightUnitor_hom_apply (j : J) : ιMapBifunctorMapObj F p X ((single₀ I).obj Y) j 0 j (hp j) ≫ (mapBifunctorRightUnitor F Y e p hp X).hom j = (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).hom ≫ e.hom.app (X j) := by dsimp [mapBifunctorRightUnitor] erw [CofanMapObjFun.ιMapObj_iso_inv] rw [mapBifunctorRightUnitorCofan_inj] lemma mapBifunctorRightUnitor_inv_apply (j : J) : (mapBifunctorRightUnitor F Y e p hp X).inv j = e.inv.app (X j) ≫ (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).inv ≫ ιMapBifunctorMapObj F p X ((single₀ I).obj Y) j 0 j (hp j) := rfl variable {Y Y'} @[reassoc] lemma mapBifunctorRightUnitor_inv_naturality : φ ≫ (mapBifunctorRightUnitor F Y e p hp X').inv = (mapBifunctorRightUnitor F Y e p hp X).inv ≫ mapBifunctorMapMap F p φ (𝟙 _) := by ext j dsimp rw [mapBifunctorRightUnitor_inv_apply, mapBifunctorRightUnitor_inv_apply, assoc, assoc, ι_mapBifunctorMapMap] dsimp rw [Functor.map_id, id_comp, NatTrans.naturality_assoc] erw [← NatTrans.naturality_assoc] rfl @[reassoc] lemma mapBifunctorRightUnitor_naturality : mapBifunctorMapMap F p φ (𝟙 _) ≫ (mapBifunctorRightUnitor F Y e p hp X').hom = (mapBifunctorRightUnitor F Y e p hp X).hom ≫ φ := by rw [← cancel_mono (mapBifunctorRightUnitor F Y e p hp X').inv, assoc, assoc, Iso.hom_inv_id, comp_id, mapBifunctorRightUnitor_inv_naturality, Iso.hom_inv_id_assoc] end RightUnitor section variable {I₁ I₂ I₃ J : Type*} [Zero I₂] /-- Given two maps `r : I₁ × I₂ × I₃ → J` and `π : I₁ × I₃ → J`, this structure is the input in the formulation of the triangle equality `mapBifunctor_triangle` which relates the left and right unitor and the associator for `GradedObject.mapBifunctor`. -/ structure TriangleIndexData (r : I₁ × I₂ × I₃ → J) (π : I₁ × I₃ → J) where /-- a map `I₁ × I₂ → I₁` -/ p₁₂ : I₁ × I₂ → I₁ hp₁₂ (i : I₁ × I₂ × I₃) : π ⟨p₁₂ ⟨i.1, i.2.1⟩, i.2.2⟩ = r i /-- a map `I₂ × I₃ → I₃` -/ p₂₃ : I₂ × I₃ → I₃ hp₂₃ (i : I₁ × I₂ × I₃) : π ⟨i.1, p₂₃ i.2⟩ = r i h₁ (i₁ : I₁) : p₁₂ (i₁, 0) = i₁ h₃ (i₃ : I₃) : p₂₃ (0, i₃) = i₃ variable {r : I₁ × I₂ × I₃ → J} {π : I₁ × I₃ → J} (τ : TriangleIndexData r π) namespace TriangleIndexData attribute [simp] h₁ h₃ lemma r_zero (i₁ : I₁) (i₃ : I₃) : r ⟨i₁, 0, i₃⟩ = π ⟨i₁, i₃⟩ := by rw [← τ.hp₂₃, τ.h₃ i₃] /-- The `BifunctorComp₁₂IndexData r` attached to a `TriangleIndexData r π`. -/ @[reducible] def ρ₁₂ : BifunctorComp₁₂IndexData r where I₁₂ := I₁ p := τ.p₁₂ q := π hpq := τ.hp₁₂ /-- The `BifunctorComp₂₃IndexData r` attached to a `TriangleIndexData r π`. -/ @[reducible] def ρ₂₃ : BifunctorComp₂₃IndexData r where I₂₃ := I₃ p := τ.p₂₃ q := π hpq := τ.hp₂₃ end TriangleIndexData end section Triangle variable {C₁ C₂ C₃ D I₁ I₂ I₃ J : Type*} [Category C₁] [Category C₂] [Category C₃] [Category D] [Zero I₂] [DecidableEq I₂] [HasInitial C₂] {F₁ : C₁ ⥤ C₂ ⥤ C₁} {F₂ : C₂ ⥤ C₃ ⥤ C₃} {G : C₁ ⥤ C₃ ⥤ D} (associator : bifunctorComp₁₂ F₁ G ≅ bifunctorComp₂₃ G F₂) (X₂ : C₂) (e₁ : F₁.flip.obj X₂ ≅ 𝟭 C₁) (e₂ : F₂.obj X₂ ≅ 𝟭 C₃) [∀ (X₁ : C₁), PreservesColimit (Functor.empty.{0} C₂) (F₁.obj X₁)] [∀ (X₃ : C₃), PreservesColimit (Functor.empty.{0} C₂) (F₂.flip.obj X₃)] {r : I₁ × I₂ × I₃ → J} {π : I₁ × I₃ → J} (τ : TriangleIndexData r π) (X₁ : GradedObject I₁ C₁) (X₃ : GradedObject I₃ C₃) [HasMap (((mapBifunctor F₁ I₁ I₂).obj X₁).obj ((single₀ I₂).obj X₂)) τ.p₁₂] [HasMap (((mapBifunctor G I₁ I₃).obj (mapBifunctorMapObj F₁ τ.p₁₂ X₁ ((single₀ I₂).obj X₂))).obj X₃) π] [HasMap (((mapBifunctor F₂ I₂ I₃).obj ((single₀ I₂).obj X₂)).obj X₃) τ.p₂₃] [HasMap (((mapBifunctor G I₁ I₃).obj X₁).obj (mapBifunctorMapObj F₂ τ.p₂₃ ((single₀ I₂).obj X₂) X₃)) π] [HasGoodTrifunctor₁₂Obj F₁ G τ.ρ₁₂ X₁ ((single₀ I₂).obj X₂) X₃] [HasGoodTrifunctor₂₃Obj G F₂ τ.ρ₂₃ X₁ ((single₀ I₂).obj X₂) X₃] [HasMap (((mapBifunctor G I₁ I₃).obj X₁).obj X₃) π] (triangle : ∀ (X₁ : C₁) (X₃ : C₃), ((associator.hom.app X₁).app X₂).app X₃ ≫ (G.obj X₁).map (e₂.hom.app X₃) = (G.map (e₁.hom.app X₁)).app X₃) lemma mapBifunctor_triangle : (mapBifunctorAssociator associator τ.ρ₁₂ τ.ρ₂₃ X₁ ((single₀ I₂).obj X₂) X₃).hom ≫ mapBifunctorMapMap G π (𝟙 X₁) (mapBifunctorLeftUnitor F₂ X₂ e₂ τ.p₂₃ τ.h₃ X₃).hom = mapBifunctorMapMap G π (mapBifunctorRightUnitor F₁ X₂ e₁ τ.p₁₂ τ.h₁ X₁).hom (𝟙 X₃) := by rw [← cancel_epi ((mapBifunctorMapMap G π (mapBifunctorRightUnitor F₁ X₂ e₁ τ.p₁₂ τ.h₁ X₁).inv (𝟙 X₃)))] ext j i₁ i₃ hj simp only [categoryOfGradedObjects_comp, ι_mapBifunctorMapMap_assoc, mapBifunctorRightUnitor_inv_apply, Functor.id_obj, Functor.flip_obj_obj, Functor.map_comp, NatTrans.comp_app, categoryOfGradedObjects_id, Functor.map_id, id_comp, assoc, ι_mapBifunctorMapMap] congr 2 rw [← ιMapBifunctor₁₂BifunctorMapObj_eq_assoc F₁ G τ.ρ₁₂ _ _ _ i₁ 0 i₃ j (by rw [τ.r_zero, hj]) i₁ (by simp), ι_mapBifunctorAssociator_hom_assoc, ιMapBifunctorBifunctor₂₃MapObj_eq_assoc G F₂ τ.ρ₂₃ _ _ _ i₁ 0 i₃ j (by rw [τ.r_zero, hj]) i₃ (by simp), ι_mapBifunctorMapMap] dsimp rw [Functor.map_id, NatTrans.id_app, id_comp, ← Functor.map_comp_assoc, ← NatTrans.comp_app_assoc, ← Functor.map_comp, ι_mapBifunctorLeftUnitor_hom_apply F₂ X₂ e₂ τ.p₂₃ τ.h₃ X₃ i₃, ι_mapBifunctorRightUnitor_hom_apply F₁ X₂ e₁ τ.p₁₂ τ.h₁ X₁ i₁] dsimp simp only [Functor.map_comp, NatTrans.comp_app, ← triangle (X₁ i₁) (X₃ i₃), ← assoc] congr 2 symm apply NatTrans.naturality_app (associator.hom.app (X₁ i₁)) end Triangle end GradedObject end CategoryTheory
CategoryTheory\Groupoid\Basic.lean
/- Copyright (c) 2022 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli -/ import Mathlib.CategoryTheory.Groupoid import Mathlib.Combinatorics.Quiver.Basic /-! This file defines a few basic properties of groupoids. -/ namespace CategoryTheory namespace Groupoid variable (C : Type*) [Groupoid C] section Thin theorem isThin_iff : Quiver.IsThin C ↔ ∀ c : C, Subsingleton (c ⟶ c) := by refine ⟨fun h c => h c c, fun h c d => Subsingleton.intro fun f g => ?_⟩ haveI := h d calc f = f ≫ inv g ≫ g := by simp only [inv_eq_inv, IsIso.inv_hom_id, Category.comp_id] _ = f ≫ inv f ≫ g := by congr 1 simp only [inv_eq_inv, IsIso.inv_hom_id, eq_iff_true_of_subsingleton] _ = g := by simp only [inv_eq_inv, IsIso.hom_inv_id_assoc] end Thin section Disconnected /-- A subgroupoid is totally disconnected if it only has loops. -/ def IsTotallyDisconnected := ∀ c d : C, (c ⟶ d) → c = d end Disconnected end Groupoid end CategoryTheory
CategoryTheory\Groupoid\FreeGroupoid.lean
/- Copyright (c) 2022 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli -/ import Mathlib.CategoryTheory.Category.Basic import Mathlib.CategoryTheory.Functor.Basic import Mathlib.CategoryTheory.Groupoid import Mathlib.Tactic.NthRewrite import Mathlib.CategoryTheory.PathCategory import Mathlib.CategoryTheory.Quotient import Mathlib.Combinatorics.Quiver.Symmetric /-! # Free groupoid on a quiver This file defines the free groupoid on a quiver, the lifting of a prefunctor to its unique extension as a functor from the free groupoid, and proves uniqueness of this extension. ## Main results Given the type `V` and a quiver instance on `V`: - `FreeGroupoid V`: a type synonym for `V`. - `FreeGroupoid.instGroupoid`: the `Groupoid` instance on `FreeGroupoid V`. - `lift`: the lifting of a prefunctor from `V` to `V'` where `V'` is a groupoid, to a functor. `FreeGroupoid V ⥤ V'`. - `lift_spec` and `lift_unique`: the proofs that, respectively, `lift` indeed is a lifting and is the unique one. ## Implementation notes The free groupoid is first defined by symmetrifying the quiver, taking the induced path category and finally quotienting by the reducibility relation. -/ open Set Function namespace CategoryTheory namespace Groupoid namespace Free universe u v u' v' u'' v'' variable {V : Type u} [Quiver.{v + 1} V] /-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/ abbrev _root_.Quiver.Hom.toPosPath {X Y : V} (f : X ⟶ Y) : (CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom X Y := f.toPos.toPath /-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/ abbrev _root_.Quiver.Hom.toNegPath {X Y : V} (f : X ⟶ Y) : (CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom Y X := f.toNeg.toPath /-- The "reduction" relation -/ inductive redStep : HomRel (Paths (Quiver.Symmetrify V)) | step (X Z : Quiver.Symmetrify V) (f : X ⟶ Z) : redStep (𝟙 (Paths.of.obj X)) (f.toPath ≫ (Quiver.reverse f).toPath) /-- The underlying vertices of the free groupoid -/ def _root_.CategoryTheory.FreeGroupoid (V) [Q : Quiver V] := Quotient (@redStep V Q) instance {V} [Quiver V] [Nonempty V] : Nonempty (FreeGroupoid V) := by inhabit V; exact ⟨⟨@default V _⟩⟩ theorem congr_reverse {X Y : Paths <| Quiver.Symmetrify V} (p q : X ⟶ Y) : Quotient.CompClosure redStep p q → Quotient.CompClosure redStep p.reverse q.reverse := by rintro ⟨XW, pp, qq, WY, _, Z, f⟩ have : Quotient.CompClosure redStep (WY.reverse ≫ 𝟙 _ ≫ XW.reverse) (WY.reverse ≫ (f.toPath ≫ (Quiver.reverse f).toPath) ≫ XW.reverse) := by constructor constructor simpa only [CategoryStruct.comp, CategoryStruct.id, Quiver.Path.reverse, Quiver.Path.nil_comp, Quiver.Path.reverse_comp, Quiver.reverse_reverse, Quiver.Path.reverse_toPath, Quiver.Path.comp_assoc] using this theorem congr_comp_reverse {X Y : Paths <| Quiver.Symmetrify V} (p : X ⟶ Y) : Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (p ≫ p.reverse) = Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (𝟙 X) := by apply Quot.EqvGen_sound induction' p with a b q f ih · apply EqvGen.refl · simp only [Quiver.Path.reverse] fapply EqvGen.trans -- Porting note: `Quiver.Path.*` and `Quiver.Hom.*` notation not working · exact q ≫ Quiver.Path.reverse q · apply EqvGen.symm apply EqvGen.rel have : Quotient.CompClosure redStep (q ≫ 𝟙 _ ≫ Quiver.Path.reverse q) (q ≫ (Quiver.Hom.toPath f ≫ Quiver.Hom.toPath (Quiver.reverse f)) ≫ Quiver.Path.reverse q) := by apply Quotient.CompClosure.intro apply redStep.step simp only [Category.assoc, Category.id_comp] at this ⊢ -- Porting note: `simp` cannot see how `Quiver.Path.comp_assoc` is relevant, so change to -- category notation change Quotient.CompClosure redStep (q ≫ Quiver.Path.reverse q) (Quiver.Path.cons q f ≫ (Quiver.Hom.toPath (Quiver.reverse f)) ≫ (Quiver.Path.reverse q)) simp only [← Category.assoc] at this ⊢ exact this · exact ih theorem congr_reverse_comp {X Y : Paths <| Quiver.Symmetrify V} (p : X ⟶ Y) : Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (p.reverse ≫ p) = Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (𝟙 Y) := by nth_rw 2 [← Quiver.Path.reverse_reverse p] apply congr_comp_reverse instance : Category (FreeGroupoid V) := Quotient.category redStep /-- The inverse of an arrow in the free groupoid -/ def quotInv {X Y : FreeGroupoid V} (f : X ⟶ Y) : Y ⟶ X := Quot.liftOn f (fun pp => Quot.mk _ <| pp.reverse) fun pp qq con => Quot.sound <| congr_reverse pp qq con instance _root_.CategoryTheory.FreeGroupoid.instGroupoid : Groupoid (FreeGroupoid V) where inv := quotInv inv_comp p := Quot.inductionOn p fun pp => congr_reverse_comp pp comp_inv p := Quot.inductionOn p fun pp => congr_comp_reverse pp /-- The inclusion of the quiver on `V` to the underlying quiver on `FreeGroupoid V`-/ def of (V) [Quiver V] : V ⥤q FreeGroupoid V where obj X := ⟨X⟩ map f := Quot.mk _ f.toPosPath theorem of_eq : of V = (Quiver.Symmetrify.of ⋙q Paths.of).comp (Quotient.functor <| @redStep V _).toPrefunctor := rfl section UniversalProperty variable {V' : Type u'} [Groupoid V'] (φ : V ⥤q V') /-- The lift of a prefunctor to a groupoid, to a functor from `FreeGroupoid V` -/ def lift (φ : V ⥤q V') : FreeGroupoid V ⥤ V' := Quotient.lift _ (Paths.lift <| Quiver.Symmetrify.lift φ) <| by rintro _ _ _ _ ⟨X, Y, f⟩ -- Porting note: `simp` does not work, so manually `rewrite` erw [Paths.lift_nil, Paths.lift_cons, Quiver.Path.comp_nil, Paths.lift_toPath, Quiver.Symmetrify.lift_reverse] symm apply Groupoid.comp_inv theorem lift_spec (φ : V ⥤q V') : of V ⋙q (lift φ).toPrefunctor = φ := by rw [of_eq, Prefunctor.comp_assoc, Prefunctor.comp_assoc, Functor.toPrefunctor_comp] dsimp [lift] rw [Quotient.lift_spec, Paths.lift_spec, Quiver.Symmetrify.lift_spec] theorem lift_unique (φ : V ⥤q V') (Φ : FreeGroupoid V ⥤ V') (hΦ : of V ⋙q Φ.toPrefunctor = φ) : Φ = lift φ := by apply Quotient.lift_unique apply Paths.lift_unique fapply @Quiver.Symmetrify.lift_unique _ _ _ _ _ _ _ _ _ · rw [← Functor.toPrefunctor_comp] exact hΦ · rintro X Y f simp only [← Functor.toPrefunctor_comp, Prefunctor.comp_map, Paths.of_map, inv_eq_inv] change Φ.map (inv ((Quotient.functor redStep).toPrefunctor.map f.toPath)) = inv (Φ.map ((Quotient.functor redStep).toPrefunctor.map f.toPath)) have := Functor.map_inv Φ ((Quotient.functor redStep).toPrefunctor.map f.toPath) convert this <;> simp only [inv_eq_inv] end UniversalProperty section Functoriality variable {V' : Type u'} [Quiver.{v' + 1} V'] {V'' : Type u''} [Quiver.{v'' + 1} V''] /-- The functor of free groupoid induced by a prefunctor of quivers -/ def _root_.CategoryTheory.freeGroupoidFunctor (φ : V ⥤q V') : FreeGroupoid V ⥤ FreeGroupoid V' := lift (φ ⋙q of V') theorem freeGroupoidFunctor_id : freeGroupoidFunctor (Prefunctor.id V) = Functor.id (FreeGroupoid V) := by dsimp only [freeGroupoidFunctor]; symm apply lift_unique; rfl theorem freeGroupoidFunctor_comp (φ : V ⥤q V') (φ' : V' ⥤q V'') : freeGroupoidFunctor (φ ⋙q φ') = freeGroupoidFunctor φ ⋙ freeGroupoidFunctor φ' := by dsimp only [freeGroupoidFunctor]; symm apply lift_unique; rfl end Functoriality end Free end Groupoid end CategoryTheory
CategoryTheory\Groupoid\Subgroupoid.lean
/- Copyright (c) 2022 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli, Junyan Xu -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.CategoryTheory.Groupoid.VertexGroup import Mathlib.CategoryTheory.Groupoid.Basic import Mathlib.CategoryTheory.Groupoid import Mathlib.Data.Set.Lattice import Mathlib.Order.GaloisConnection /-! # Subgroupoid This file defines subgroupoids as `structure`s containing the subsets of arrows and their stability under composition and inversion. Also defined are: * containment of subgroupoids is a complete lattice; * images and preimages of subgroupoids under a functor; * the notion of normality of subgroupoids and its stability under intersection and preimage; * compatibility of the above with `CategoryTheory.Groupoid.vertexGroup`. ## Main definitions Given a type `C` with associated `groupoid C` instance. * `CategoryTheory.Subgroupoid C` is the type of subgroupoids of `C` * `CategoryTheory.Subgroupoid.IsNormal` is the property that the subgroupoid is stable under conjugation by arbitrary arrows, _and_ that all identity arrows are contained in the subgroupoid. * `CategoryTheory.Subgroupoid.comap` is the "preimage" map of subgroupoids along a functor. * `CategoryTheory.Subgroupoid.map` is the "image" map of subgroupoids along a functor _injective on objects_. * `CategoryTheory.Subgroupoid.vertexSubgroup` is the subgroup of the *vertex group* at a given vertex `v`, assuming `v` is contained in the `CategoryTheory.Subgroupoid` (meaning, by definition, that the arrow `𝟙 v` is contained in the subgroupoid). ## Implementation details The structure of this file is copied from/inspired by `Mathlib/GroupTheory/Subgroup/Basic.lean` and `Mathlib/Combinatorics/SimpleGraph/Subgraph.lean`. ## TODO * Equivalent inductive characterization of generated (normal) subgroupoids. * Characterization of normal subgroupoids as kernels. * Prove that `CategoryTheory.Subgroupoid.full` and `CategoryTheory.Subgroupoid.disconnect` preserve intersections (and `CategoryTheory.Subgroupoid.disconnect` also unions) ## Tags category theory, groupoid, subgroupoid -/ namespace CategoryTheory open Set Groupoid universe u v variable {C : Type u} [Groupoid C] /-- A sugroupoid of `C` consists of a choice of arrows for each pair of vertices, closed under composition and inverses. -/ @[ext] structure Subgroupoid (C : Type u) [Groupoid C] where arrows : ∀ c d : C, Set (c ⟶ d) protected inv : ∀ {c d} {p : c ⟶ d}, p ∈ arrows c d → Groupoid.inv p ∈ arrows d c protected mul : ∀ {c d e} {p}, p ∈ arrows c d → ∀ {q}, q ∈ arrows d e → p ≫ q ∈ arrows c e namespace Subgroupoid variable (S : Subgroupoid C) theorem inv_mem_iff {c d : C} (f : c ⟶ d) : Groupoid.inv f ∈ S.arrows d c ↔ f ∈ S.arrows c d := by constructor · intro h simpa only [inv_eq_inv, IsIso.inv_inv] using S.inv h · apply S.inv theorem mul_mem_cancel_left {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hf : f ∈ S.arrows c d) : f ≫ g ∈ S.arrows c e ↔ g ∈ S.arrows d e := by constructor · rintro h suffices Groupoid.inv f ≫ f ≫ g ∈ S.arrows d e by simpa only [inv_eq_inv, IsIso.inv_hom_id_assoc] using this apply S.mul (S.inv hf) h · apply S.mul hf theorem mul_mem_cancel_right {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hg : g ∈ S.arrows d e) : f ≫ g ∈ S.arrows c e ↔ f ∈ S.arrows c d := by constructor · rintro h suffices (f ≫ g) ≫ Groupoid.inv g ∈ S.arrows c d by simpa only [inv_eq_inv, IsIso.hom_inv_id, Category.comp_id, Category.assoc] using this apply S.mul h (S.inv hg) · exact fun hf => S.mul hf hg /-- The vertices of `C` on which `S` has non-trivial isotropy -/ def objs : Set C := {c : C | (S.arrows c c).Nonempty} theorem mem_objs_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : c ∈ S.objs := ⟨f ≫ Groupoid.inv f, S.mul h (S.inv h)⟩ theorem mem_objs_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : d ∈ S.objs := ⟨Groupoid.inv f ≫ f, S.mul (S.inv h) h⟩ theorem id_mem_of_nonempty_isotropy (c : C) : c ∈ objs S → 𝟙 c ∈ S.arrows c c := by rintro ⟨γ, hγ⟩ convert S.mul hγ (S.inv hγ) simp only [inv_eq_inv, IsIso.hom_inv_id] theorem id_mem_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 c ∈ S.arrows c c := id_mem_of_nonempty_isotropy S c (mem_objs_of_src S h) theorem id_mem_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 d ∈ S.arrows d d := id_mem_of_nonempty_isotropy S d (mem_objs_of_tgt S h) /-- A subgroupoid seen as a quiver on vertex set `C` -/ def asWideQuiver : Quiver C := ⟨fun c d => Subtype <| S.arrows c d⟩ /-- The coercion of a subgroupoid as a groupoid -/ @[simps comp_coe, simps (config := .lemmasOnly) inv_coe] instance coe : Groupoid S.objs where Hom a b := S.arrows a.val b.val id a := ⟨𝟙 a.val, id_mem_of_nonempty_isotropy S a.val a.prop⟩ comp p q := ⟨p.val ≫ q.val, S.mul p.prop q.prop⟩ inv p := ⟨Groupoid.inv p.val, S.inv p.prop⟩ @[simp] theorem coe_inv_coe' {c d : S.objs} (p : c ⟶ d) : (CategoryTheory.inv p).val = CategoryTheory.inv p.val := by simp only [← inv_eq_inv, coe_inv_coe] /-- The embedding of the coerced subgroupoid to its parent-/ def hom : S.objs ⥤ C where obj c := c.val map f := f.val map_id _ := rfl map_comp _ _ := rfl theorem hom.inj_on_objects : Function.Injective (hom S).obj := by rintro ⟨c, hc⟩ ⟨d, hd⟩ hcd simp only [Subtype.mk_eq_mk]; exact hcd theorem hom.faithful : ∀ c d, Function.Injective fun f : c ⟶ d => (hom S).map f := by rintro ⟨c, hc⟩ ⟨d, hd⟩ ⟨f, hf⟩ ⟨g, hg⟩ hfg; exact Subtype.eq hfg /-- The subgroup of the vertex group at `c` given by the subgroupoid -/ def vertexSubgroup {c : C} (hc : c ∈ S.objs) : Subgroup (c ⟶ c) where carrier := S.arrows c c mul_mem' hf hg := S.mul hf hg one_mem' := id_mem_of_nonempty_isotropy _ _ hc inv_mem' hf := S.inv hf /-- The set of all arrows of a subgroupoid, as a set in `Σ c d : C, c ⟶ d`. -/ @[coe] def toSet (S : Subgroupoid C) : Set (Σ c d : C, c ⟶ d) := {F | F.2.2 ∈ S.arrows F.1 F.2.1} instance : SetLike (Subgroupoid C) (Σ c d : C, c ⟶ d) where coe := toSet coe_injective' := fun ⟨S, _, _⟩ ⟨T, _, _⟩ h => by ext c d f; apply Set.ext_iff.1 h ⟨c, d, f⟩ theorem mem_iff (S : Subgroupoid C) (F : Σ c d, c ⟶ d) : F ∈ S ↔ F.2.2 ∈ S.arrows F.1 F.2.1 := Iff.rfl theorem le_iff (S T : Subgroupoid C) : S ≤ T ↔ ∀ {c d}, S.arrows c d ⊆ T.arrows c d := by rw [SetLike.le_def, Sigma.forall]; exact forall_congr' fun c => Sigma.forall instance : Top (Subgroupoid C) := ⟨{ arrows := fun _ _ => Set.univ mul := by intros; trivial inv := by intros; trivial }⟩ theorem mem_top {c d : C} (f : c ⟶ d) : f ∈ (⊤ : Subgroupoid C).arrows c d := trivial theorem mem_top_objs (c : C) : c ∈ (⊤ : Subgroupoid C).objs := by dsimp [Top.top, objs] simp only [univ_nonempty] instance : Bot (Subgroupoid C) := ⟨{ arrows := fun _ _ => ∅ mul := False.elim inv := False.elim }⟩ instance : Inhabited (Subgroupoid C) := ⟨⊤⟩ instance : Inf (Subgroupoid C) := ⟨fun S T => { arrows := fun c d => S.arrows c d ∩ T.arrows c d inv := fun hp ↦ ⟨S.inv hp.1, T.inv hp.2⟩ mul := fun hp _ hq ↦ ⟨S.mul hp.1 hq.1, T.mul hp.2 hq.2⟩ }⟩ instance : InfSet (Subgroupoid C) := ⟨fun s => { arrows := fun c d => ⋂ S ∈ s, Subgroupoid.arrows S c d inv := fun hp ↦ by rw [mem_iInter₂] at hp ⊢; exact fun S hS => S.inv (hp S hS) mul := fun hp _ hq ↦ by rw [mem_iInter₂] at hp hq ⊢ exact fun S hS => S.mul (hp S hS) (hq S hS) }⟩ theorem mem_sInf_arrows {s : Set (Subgroupoid C)} {c d : C} {p : c ⟶ d} : p ∈ (sInf s).arrows c d ↔ ∀ S ∈ s, p ∈ S.arrows c d := mem_iInter₂ theorem mem_sInf {s : Set (Subgroupoid C)} {p : Σ c d : C, c ⟶ d} : p ∈ sInf s ↔ ∀ S ∈ s, p ∈ S := mem_sInf_arrows instance : CompleteLattice (Subgroupoid C) := { completeLatticeOfInf (Subgroupoid C) (by refine fun s => ⟨fun S Ss F => ?_, fun T Tl F fT => ?_⟩ <;> simp only [mem_sInf] exacts [fun hp => hp S Ss, fun S Ss => Tl Ss fT]) with bot := ⊥ bot_le := fun S => empty_subset _ top := ⊤ le_top := fun S => subset_univ _ inf := (· ⊓ ·) le_inf := fun R S T RS RT _ pR => ⟨RS pR, RT pR⟩ inf_le_left := fun R S _ => And.left inf_le_right := fun R S _ => And.right } theorem le_objs {S T : Subgroupoid C} (h : S ≤ T) : S.objs ⊆ T.objs := fun s ⟨γ, hγ⟩ => ⟨γ, @h ⟨s, s, γ⟩ hγ⟩ /-- The functor associated to the embedding of subgroupoids -/ def inclusion {S T : Subgroupoid C} (h : S ≤ T) : S.objs ⥤ T.objs where obj s := ⟨s.val, le_objs h s.prop⟩ map f := ⟨f.val, @h ⟨_, _, f.val⟩ f.prop⟩ map_id _ := rfl map_comp _ _ := rfl theorem inclusion_inj_on_objects {S T : Subgroupoid C} (h : S ≤ T) : Function.Injective (inclusion h).obj := fun ⟨s, hs⟩ ⟨t, ht⟩ => by simpa only [inclusion, Subtype.mk_eq_mk] using id theorem inclusion_faithful {S T : Subgroupoid C} (h : S ≤ T) (s t : S.objs) : Function.Injective fun f : s ⟶ t => (inclusion h).map f := fun ⟨f, hf⟩ ⟨g, hg⟩ => by -- Porting note: was `...; simpa only [Subtype.mk_eq_mk] using id` dsimp only [inclusion]; rw [Subtype.mk_eq_mk, Subtype.mk_eq_mk]; exact id theorem inclusion_refl {S : Subgroupoid C} : inclusion (le_refl S) = 𝟭 S.objs := Functor.hext (fun _ => rfl) fun _ _ _ => HEq.refl _ theorem inclusion_trans {R S T : Subgroupoid C} (k : R ≤ S) (h : S ≤ T) : inclusion (k.trans h) = inclusion k ⋙ inclusion h := rfl theorem inclusion_comp_embedding {S T : Subgroupoid C} (h : S ≤ T) : inclusion h ⋙ T.hom = S.hom := rfl /-- The family of arrows of the discrete groupoid -/ inductive Discrete.Arrows : ∀ c d : C, (c ⟶ d) → Prop | id (c : C) : Discrete.Arrows c c (𝟙 c) /-- The only arrows of the discrete groupoid are the identity arrows. -/ def discrete : Subgroupoid C where arrows c d := {p | Discrete.Arrows c d p} inv := by rintro _ _ _ ⟨⟩; simp only [inv_eq_inv, IsIso.inv_id]; constructor mul := by rintro _ _ _ _ ⟨⟩ _ ⟨⟩; rw [Category.comp_id]; constructor theorem mem_discrete_iff {c d : C} (f : c ⟶ d) : f ∈ discrete.arrows c d ↔ ∃ h : c = d, f = eqToHom h := ⟨by rintro ⟨⟩; exact ⟨rfl, rfl⟩, by rintro ⟨rfl, rfl⟩; constructor⟩ /-- A subgroupoid is wide if its carrier set is all of `C`-/ structure IsWide : Prop where wide : ∀ c, 𝟙 c ∈ S.arrows c c theorem isWide_iff_objs_eq_univ : S.IsWide ↔ S.objs = Set.univ := by constructor · rintro h ext x; constructor <;> simp only [top_eq_univ, mem_univ, imp_true_iff, forall_true_left] apply mem_objs_of_src S (h.wide x) · rintro h refine ⟨fun c => ?_⟩ obtain ⟨γ, γS⟩ := (le_of_eq h.symm : ⊤ ⊆ S.objs) (Set.mem_univ c) exact id_mem_of_src S γS theorem IsWide.id_mem {S : Subgroupoid C} (Sw : S.IsWide) (c : C) : 𝟙 c ∈ S.arrows c c := Sw.wide c theorem IsWide.eqToHom_mem {S : Subgroupoid C} (Sw : S.IsWide) {c d : C} (h : c = d) : eqToHom h ∈ S.arrows c d := by cases h; simp only [eqToHom_refl]; apply Sw.id_mem c /-- A subgroupoid is normal if it is wide and satisfies the expected stability under conjugacy. -/ structure IsNormal extends IsWide S : Prop where conj : ∀ {c d} (p : c ⟶ d) {γ : c ⟶ c}, γ ∈ S.arrows c c → Groupoid.inv p ≫ γ ≫ p ∈ S.arrows d d theorem IsNormal.conj' {S : Subgroupoid C} (Sn : IsNormal S) : ∀ {c d} (p : d ⟶ c) {γ : c ⟶ c}, γ ∈ S.arrows c c → p ≫ γ ≫ Groupoid.inv p ∈ S.arrows d d := fun p γ hs => by convert Sn.conj (Groupoid.inv p) hs; simp theorem IsNormal.conjugation_bij (Sn : IsNormal S) {c d} (p : c ⟶ d) : Set.BijOn (fun γ : c ⟶ c => Groupoid.inv p ≫ γ ≫ p) (S.arrows c c) (S.arrows d d) := by refine ⟨fun γ γS => Sn.conj p γS, fun γ₁ _ γ₂ _ h => ?_, fun δ δS => ⟨p ≫ δ ≫ Groupoid.inv p, Sn.conj' p δS, ?_⟩⟩ · simpa only [inv_eq_inv, Category.assoc, IsIso.hom_inv_id, Category.comp_id, IsIso.hom_inv_id_assoc] using p ≫= h =≫ inv p · simp only [inv_eq_inv, Category.assoc, IsIso.inv_hom_id, Category.comp_id, IsIso.inv_hom_id_assoc] theorem top_isNormal : IsNormal (⊤ : Subgroupoid C) := { wide := fun _ => trivial conj := fun _ _ _ => trivial } theorem sInf_isNormal (s : Set <| Subgroupoid C) (sn : ∀ S ∈ s, IsNormal S) : IsNormal (sInf s) := { wide := by simp_rw [sInf, mem_iInter₂]; exact fun c S Ss => (sn S Ss).wide c conj := by simp_rw [sInf, mem_iInter₂]; exact fun p γ hγ S Ss => (sn S Ss).conj p (hγ S Ss) } theorem discrete_isNormal : (@discrete C _).IsNormal := { wide := fun c => by constructor conj := fun f γ hγ => by cases hγ simp only [inv_eq_inv, Category.id_comp, IsIso.inv_hom_id]; constructor } theorem IsNormal.vertexSubgroup (Sn : IsNormal S) (c : C) (cS : c ∈ S.objs) : (S.vertexSubgroup cS).Normal where conj_mem x hx y := by rw [mul_assoc]; exact Sn.conj' y hx section GeneratedSubgroupoid -- TODO: proof that generated is just "words in X" and generatedNormal is similarly variable (X : ∀ c d : C, Set (c ⟶ d)) /-- The subgropoid generated by the set of arrows `X` -/ def generated : Subgroupoid C := sInf {S : Subgroupoid C | ∀ c d, X c d ⊆ S.arrows c d} theorem subset_generated (c d : C) : X c d ⊆ (generated X).arrows c d := by dsimp only [generated, sInf] simp only [subset_iInter₂_iff] exact fun S hS f fS => hS _ _ fS /-- The normal sugroupoid generated by the set of arrows `X` -/ def generatedNormal : Subgroupoid C := sInf {S : Subgroupoid C | (∀ c d, X c d ⊆ S.arrows c d) ∧ S.IsNormal} theorem generated_le_generatedNormal : generated X ≤ generatedNormal X := by apply @sInf_le_sInf (Subgroupoid C) _ exact fun S ⟨h, _⟩ => h theorem generatedNormal_isNormal : (generatedNormal X).IsNormal := sInf_isNormal _ fun _ h => h.right theorem IsNormal.generatedNormal_le {S : Subgroupoid C} (Sn : S.IsNormal) : generatedNormal X ≤ S ↔ ∀ c d, X c d ⊆ S.arrows c d := by constructor · rintro h c d have h' := generated_le_generatedNormal X rw [le_iff] at h h' exact ((subset_generated X c d).trans (@h' c d)).trans (@h c d) · rintro h apply @sInf_le (Subgroupoid C) _ exact ⟨h, Sn⟩ end GeneratedSubgroupoid section Hom variable {D : Type*} [Groupoid D] (φ : C ⥤ D) /-- A functor between groupoid defines a map of subgroupoids in the reverse direction by taking preimages. -/ def comap (S : Subgroupoid D) : Subgroupoid C where arrows c d := {f : c ⟶ d | φ.map f ∈ S.arrows (φ.obj c) (φ.obj d)} inv hp := by rw [mem_setOf, inv_eq_inv, φ.map_inv, ← inv_eq_inv]; exact S.inv hp mul := by intros simp only [mem_setOf, Functor.map_comp] apply S.mul <;> assumption theorem comap_mono (S T : Subgroupoid D) : S ≤ T → comap φ S ≤ comap φ T := fun ST _ => @ST ⟨_, _, _⟩ theorem isNormal_comap {S : Subgroupoid D} (Sn : IsNormal S) : IsNormal (comap φ S) where wide c := by rw [comap, mem_setOf, Functor.map_id]; apply Sn.wide conj f γ hγ := by simp_rw [inv_eq_inv f, comap, mem_setOf, Functor.map_comp, Functor.map_inv, ← inv_eq_inv] exact Sn.conj _ hγ @[simp] theorem comap_comp {E : Type*} [Groupoid E] (ψ : D ⥤ E) : comap (φ ⋙ ψ) = comap φ ∘ comap ψ := rfl /-- The kernel of a functor between subgroupoid is the preimage. -/ def ker : Subgroupoid C := comap φ discrete theorem mem_ker_iff {c d : C} (f : c ⟶ d) : f ∈ (ker φ).arrows c d ↔ ∃ h : φ.obj c = φ.obj d, φ.map f = eqToHom h := mem_discrete_iff (φ.map f) theorem ker_isNormal : (ker φ).IsNormal := isNormal_comap φ discrete_isNormal @[simp] theorem ker_comp {E : Type*} [Groupoid E] (ψ : D ⥤ E) : ker (φ ⋙ ψ) = comap φ (ker ψ) := rfl /-- The family of arrows of the image of a subgroupoid under a functor injective on objects -/ inductive Map.Arrows (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : ∀ c d : D, (c ⟶ d) → Prop | im {c d : C} (f : c ⟶ d) (hf : f ∈ S.arrows c d) : Map.Arrows hφ S (φ.obj c) (φ.obj d) (φ.map f) theorem Map.arrows_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) : Map.Arrows φ hφ S c d f ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by constructor · rintro ⟨g, hg⟩; exact ⟨_, _, g, rfl, rfl, hg, eq_conj_eqToHom _⟩ · rintro ⟨a, b, g, rfl, rfl, hg, rfl⟩; rw [← eq_conj_eqToHom]; constructor; exact hg /-- The "forward" image of a subgroupoid under a functor injective on objects -/ def map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : Subgroupoid D where arrows c d := {x | Map.Arrows φ hφ S c d x} inv := by rintro _ _ _ ⟨⟩ rw [inv_eq_inv, ← Functor.map_inv, ← inv_eq_inv] constructor; apply S.inv; assumption mul := by rintro _ _ _ _ ⟨f, hf⟩ q hq obtain ⟨c₃, c₄, g, he, rfl, hg, gq⟩ := (Map.arrows_iff φ hφ S q).mp hq cases hφ he; rw [gq, ← eq_conj_eqToHom, ← φ.map_comp] constructor; exact S.mul hf hg theorem mem_map_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) : f ∈ (map φ hφ S).arrows c d ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := Map.arrows_iff φ hφ S f theorem galoisConnection_map_comap (hφ : Function.Injective φ.obj) : GaloisConnection (map φ hφ) (comap φ) := by rintro S T; simp_rw [le_iff]; constructor · exact fun h c d f fS => h (Map.Arrows.im f fS) · rintro h _ _ g ⟨a, gφS⟩ exact h gφS theorem map_mono (hφ : Function.Injective φ.obj) (S T : Subgroupoid C) : S ≤ T → map φ hφ S ≤ map φ hφ T := fun h => (galoisConnection_map_comap φ hφ).monotone_l h theorem le_comap_map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : S ≤ comap φ (map φ hφ S) := (galoisConnection_map_comap φ hφ).le_u_l S theorem map_comap_le (hφ : Function.Injective φ.obj) (T : Subgroupoid D) : map φ hφ (comap φ T) ≤ T := (galoisConnection_map_comap φ hφ).l_u_le T theorem map_le_iff_le_comap (hφ : Function.Injective φ.obj) (S : Subgroupoid C) (T : Subgroupoid D) : map φ hφ S ≤ T ↔ S ≤ comap φ T := (galoisConnection_map_comap φ hφ).le_iff_le theorem mem_map_objs_iff (hφ : Function.Injective φ.obj) (d : D) : d ∈ (map φ hφ S).objs ↔ ∃ c ∈ S.objs, φ.obj c = d := by dsimp [objs, map] constructor · rintro ⟨f, hf⟩ change Map.Arrows φ hφ S d d f at hf; rw [Map.arrows_iff] at hf obtain ⟨c, d, g, ec, ed, eg, gS, eg⟩ := hf exact ⟨c, ⟨mem_objs_of_src S eg, ec⟩⟩ · rintro ⟨c, ⟨γ, γS⟩, rfl⟩ exact ⟨φ.map γ, ⟨γ, γS⟩⟩ @[simp] theorem map_objs_eq (hφ : Function.Injective φ.obj) : (map φ hφ S).objs = φ.obj '' S.objs := by ext x; convert mem_map_objs_iff S φ hφ x /-- The image of a functor injective on objects -/ def im (hφ : Function.Injective φ.obj) := map φ hφ ⊤ theorem mem_im_iff (hφ : Function.Injective φ.obj) {c d : D} (f : c ⟶ d) : f ∈ (im φ hφ).arrows c d ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by convert Map.arrows_iff φ hφ ⊤ f; simp only [Top.top, mem_univ, exists_true_left] theorem mem_im_objs_iff (hφ : Function.Injective φ.obj) (d : D) : d ∈ (im φ hφ).objs ↔ ∃ c : C, φ.obj c = d := by simp only [im, mem_map_objs_iff, mem_top_objs, true_and] theorem obj_surjective_of_im_eq_top (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊤) : Function.Surjective φ.obj := by rintro d rw [← mem_im_objs_iff, hφ'] apply mem_top_objs theorem isNormal_map (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊤) (Sn : S.IsNormal) : (map φ hφ S).IsNormal := { wide := fun d => by obtain ⟨c, rfl⟩ := obj_surjective_of_im_eq_top φ hφ hφ' d change Map.Arrows φ hφ S _ _ (𝟙 _); rw [← Functor.map_id] constructor; exact Sn.wide c conj := fun {d d'} g δ hδ => by rw [mem_map_iff] at hδ obtain ⟨c, c', γ, cd, cd', γS, hγ⟩ := hδ; subst_vars; cases hφ cd' have : d' ∈ (im φ hφ).objs := by rw [hφ']; apply mem_top_objs rw [mem_im_objs_iff] at this obtain ⟨c', rfl⟩ := this have : g ∈ (im φ hφ).arrows (φ.obj c) (φ.obj c') := by rw [hφ']; trivial rw [mem_im_iff] at this obtain ⟨b, b', f, hb, hb', _, hf⟩ := this; cases hφ hb; cases hφ hb' change Map.Arrows φ hφ S (φ.obj c') (φ.obj c') _ simp only [eqToHom_refl, Category.comp_id, Category.id_comp, inv_eq_inv] suffices Map.Arrows φ hφ S (φ.obj c') (φ.obj c') (φ.map <| Groupoid.inv f ≫ γ ≫ f) by simp only [inv_eq_inv, Functor.map_comp, Functor.map_inv] at this; exact this constructor; apply Sn.conj f γS } end Hom section Thin /-- A subgroupoid is thin (`CategoryTheory.Subgroupoid.IsThin`) if it has at most one arrow between any two vertices. -/ abbrev IsThin := Quiver.IsThin S.objs nonrec theorem isThin_iff : S.IsThin ↔ ∀ c : S.objs, Subsingleton (S.arrows c c) := isThin_iff _ end Thin section Disconnected /-- A subgroupoid `IsTotallyDisconnected` if it has only isotropy arrows. -/ nonrec abbrev IsTotallyDisconnected := IsTotallyDisconnected S.objs theorem isTotallyDisconnected_iff : S.IsTotallyDisconnected ↔ ∀ c d, (S.arrows c d).Nonempty → c = d := by constructor · rintro h c d ⟨f, fS⟩ have := h ⟨c, mem_objs_of_src S fS⟩ ⟨d, mem_objs_of_tgt S fS⟩ ⟨f, fS⟩ exact congr_arg Subtype.val this · rintro h ⟨c, hc⟩ ⟨d, hd⟩ ⟨f, fS⟩ simp only [Subtype.mk_eq_mk] exact h c d ⟨f, fS⟩ /-- The isotropy subgroupoid of `S` -/ def disconnect : Subgroupoid C where arrows c d := {f | c = d ∧ f ∈ S.arrows c d} inv := by rintro _ _ _ ⟨rfl, h⟩; exact ⟨rfl, S.inv h⟩ mul := by rintro _ _ _ _ ⟨rfl, h⟩ _ ⟨rfl, h'⟩; exact ⟨rfl, S.mul h h'⟩ theorem disconnect_le : S.disconnect ≤ S := by rw [le_iff]; rintro _ _ _ ⟨⟩; assumption theorem disconnect_normal (Sn : S.IsNormal) : S.disconnect.IsNormal := { wide := fun c => ⟨rfl, Sn.wide c⟩ conj := fun _ _ ⟨_, h'⟩ => ⟨rfl, Sn.conj _ h'⟩ } @[simp] theorem mem_disconnect_objs_iff {c : C} : c ∈ S.disconnect.objs ↔ c ∈ S.objs := ⟨fun ⟨γ, _, γS⟩ => ⟨γ, γS⟩, fun ⟨γ, γS⟩ => ⟨γ, rfl, γS⟩⟩ theorem disconnect_objs : S.disconnect.objs = S.objs := Set.ext fun _ ↦ mem_disconnect_objs_iff _ theorem disconnect_isTotallyDisconnected : S.disconnect.IsTotallyDisconnected := by rw [isTotallyDisconnected_iff]; exact fun c d ⟨_, h, _⟩ => h end Disconnected section Full variable (D : Set C) /-- The full subgroupoid on a set `D : Set C` -/ def full : Subgroupoid C where arrows c d := {_f | c ∈ D ∧ d ∈ D} inv := by rintro _ _ _ ⟨⟩; constructor <;> assumption mul := by rintro _ _ _ _ ⟨⟩ _ ⟨⟩; constructor <;> assumption theorem full_objs : (full D).objs = D := Set.ext fun _ => ⟨fun ⟨_, h, _⟩ => h, fun h => ⟨𝟙 _, h, h⟩⟩ @[simp] theorem mem_full_iff {c d : C} {f : c ⟶ d} : f ∈ (full D).arrows c d ↔ c ∈ D ∧ d ∈ D := Iff.rfl @[simp] theorem mem_full_objs_iff {c : C} : c ∈ (full D).objs ↔ c ∈ D := by rw [full_objs] @[simp] theorem full_empty : full ∅ = (⊥ : Subgroupoid C) := by ext simp only [Bot.bot, mem_full_iff, mem_empty_iff_false, and_self_iff] @[simp] theorem full_univ : full Set.univ = (⊤ : Subgroupoid C) := by ext simp only [mem_full_iff, mem_univ, and_self, mem_top] theorem full_mono {D E : Set C} (h : D ≤ E) : full D ≤ full E := by rw [le_iff] rintro c d f simp only [mem_full_iff] exact fun ⟨hc, hd⟩ => ⟨h hc, h hd⟩ -- Porting note: using `.1` instead of `↑` theorem full_arrow_eq_iff {c d : (full D).objs} {f g : c ⟶ d} : f = g ↔ (f.1 : c.val ⟶ d.val) = g.1 := Subtype.ext_iff end Full end Subgroupoid end CategoryTheory
CategoryTheory\Groupoid\VertexGroup.lean
/- Copyright (c) 2022 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.CategoryTheory.Groupoid import Mathlib.CategoryTheory.PathCategory import Mathlib.Combinatorics.Quiver.Path /-! # Vertex group This file defines the vertex group (*aka* isotropy group) of a groupoid at a vertex. ## Implementation notes * The instance is defined "manually", instead of relying on `CategoryTheory.Aut.group` or using `CategoryTheory.inv`. * The multiplication order therefore matches the categorical one: `x * y = x ≫ y`. * The inverse is directly defined in terms of the groupoidal inverse: `x ⁻¹ = Groupoid.inv x`. ## Tags isotropy, vertex group, groupoid -/ namespace CategoryTheory namespace Groupoid universe u v variable {C : Type u} [Groupoid C] /-- The vertex group at `c`. -/ @[simps mul one inv] instance vertexGroup (c : C) : Group (c ⟶ c) where mul := fun x y : c ⟶ c => x ≫ y mul_assoc := Category.assoc one := 𝟙 c one_mul := Category.id_comp mul_one := Category.comp_id inv := Groupoid.inv mul_left_inv := inv_comp -- dsimp loops when applying this lemma to its LHS, -- probably https://github.com/leanprover/lean4/pull/2867 attribute [nolint simpNF] CategoryTheory.Groupoid.vertexGroup_one /-- The inverse in the group is equal to the inverse given by `CategoryTheory.inv`. -/ theorem vertexGroup.inv_eq_inv (c : C) (γ : c ⟶ c) : γ⁻¹ = CategoryTheory.inv γ := Groupoid.inv_eq_inv γ /-- An arrow in the groupoid defines, by conjugation, an isomorphism of groups between its endpoints. -/ @[simps] def vertexGroupIsomOfMap {c d : C} (f : c ⟶ d) : (c ⟶ c) ≃* (d ⟶ d) where toFun γ := inv f ≫ γ ≫ f invFun δ := f ≫ δ ≫ inv f left_inv γ := by simp_rw [Category.assoc, comp_inv, Category.comp_id, ← Category.assoc, comp_inv, Category.id_comp] right_inv δ := by simp_rw [Category.assoc, inv_comp, ← Category.assoc, inv_comp, Category.id_comp, Category.comp_id] map_mul' γ₁ γ₂ := by simp only [vertexGroup_mul, inv_eq_inv, Category.assoc, IsIso.hom_inv_id_assoc] /-- A path in the groupoid defines an isomorphism between its endpoints. -/ def vertexGroupIsomOfPath {c d : C} (p : Quiver.Path c d) : (c ⟶ c) ≃* (d ⟶ d) := vertexGroupIsomOfMap (composePath p) /-- A functor defines a morphism of vertex group. -/ @[simps] def CategoryTheory.Functor.mapVertexGroup {D : Type v} [Groupoid D] (φ : C ⥤ D) (c : C) : (c ⟶ c) →* (φ.obj c ⟶ φ.obj c) where toFun := φ.map map_one' := φ.map_id c map_mul' := φ.map_comp end Groupoid end CategoryTheory
CategoryTheory\GuitartExact\Basic.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.Final /-! # Guitart exact squares Given four functors `T`, `L`, `R` and `B`, a 2-square `TwoSquare T L R B` consists of a natural transformation `w : T ⋙ R ⟶ L ⋙ B`: ``` T C₁ ⥤ C₂ L | | R v v C₃ ⥤ C₄ B ``` In this file, we define a typeclass `w.GuitartExact` which expresses that this square is exact in the sense of Guitart. This means that for any `X₃ : C₃`, the induced functor `CostructuredArrow L X₃ ⥤ CostructuredArrow R (B.obj X₃)` is final. It is also equivalent to the fact that for any `X₂ : C₂`, the induced functor `StructuredArrow X₂ T ⥤ StructuredArrow (R.obj X₂) B` is initial. Various categorical notions (fully faithful functors, adjunctions, etc.) can be characterized in terms of Guitart exact squares. Their particular role in pointwise Kan extensions shall also be used in the construction of derived functors. ## TODO * Define the notion of derivability structure from [the paper by Kahn and Maltsiniotis][KahnMaltsiniotis2008] using Guitart exact squares and construct (pointwise) derived functors using this notion ## References * https://ncatlab.org/nlab/show/exact+square * [René Guitart, *Relations et carrés exacts*][Guitart1980] * [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008] -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace CategoryTheory open Category variable {C₁ : Type u₁} {C₂ : Type u₂} {C₃ : Type u₃} {C₄ : Type u₄} [Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} C₃] [Category.{v₄} C₄] (T : C₁ ⥤ C₂) (L : C₁ ⥤ C₃) (R : C₂ ⥤ C₄) (B : C₃ ⥤ C₄) /-- A `2`-square consists of a natural transformation `T ⋙ R ⟶ L ⋙ B` involving fours functors `T`, `L`, `R`, `B` that are on the top/left/right/bottom sides of a square of categories. -/ def TwoSquare := T ⋙ R ⟶ L ⋙ B namespace TwoSquare /-- Constructor for `TwoSquare`. -/ abbrev mk (α : T ⋙ R ⟶ L ⋙ B) : TwoSquare T L R B := α variable {T L R B} @[ext] lemma ext (w w' : TwoSquare T L R B) (h : ∀ (X : C₁), w.app X = w'.app X) : w = w' := NatTrans.ext (funext h) variable (w : TwoSquare T L R B) /-- Given `w : TwoSquare T L R B` and `X₃ : C₃`, this is the obvious functor `CostructuredArrow L X₃ ⥤ CostructuredArrow R (B.obj X₃)`. -/ @[simps! obj map] def costructuredArrowRightwards (X₃ : C₃) : CostructuredArrow L X₃ ⥤ CostructuredArrow R (B.obj X₃) := CostructuredArrow.post L B X₃ ⋙ Comma.mapLeft _ w ⋙ CostructuredArrow.pre T R (B.obj X₃) /-- Given `w : TwoSquare T L R B` and `X₂ : C₂`, this is the obvious functor `StructuredArrow X₂ T ⥤ StructuredArrow (R.obj X₂) B`. -/ @[simps! obj map] def structuredArrowDownwards (X₂ : C₂) : StructuredArrow X₂ T ⥤ StructuredArrow (R.obj X₂) B := StructuredArrow.post X₂ T R ⋙ Comma.mapRight _ w ⋙ StructuredArrow.pre (R.obj X₂) L B section variable {X₂ : C₂} {X₃ : C₃} (g : R.obj X₂ ⟶ B.obj X₃) /- In [the paper by Kahn and Maltsiniotis, §4.3][KahnMaltsiniotis2008], given `w : TwoSquare T L R B` and `g : R.obj X₂ ⟶ B.obj X₃`, a category `J` is introduced and it is observed that it is equivalent to the two categories `w.StructuredArrowRightwards g` and `w.CostructuredArrowDownwards g`. We shall show below that there is an equivalence `w.equivalenceJ g : w.StructuredArrowRightwards g ≌ w.CostructuredArrowDownwards g`. -/ /-- Given `w : TwoSquare T L R B` and a morphism `g : R.obj X₂ ⟶ B.obj X₃`, this is the category `StructuredArrow (CostructuredArrow.mk g) (w.costructuredArrowRightwards X₃)`, see the constructor `StructuredArrowRightwards.mk` for the data that is involved. -/ abbrev StructuredArrowRightwards := StructuredArrow (CostructuredArrow.mk g) (w.costructuredArrowRightwards X₃) /-- Given `w : TwoSquare T L R B` and a morphism `g : R.obj X₂ ⟶ B.obj X₃`, this is the category `CostructuredArrow (w.structuredArrowDownwards X₂) (StructuredArrow.mk g)`, see the constructor `CostructuredArrowDownwards.mk` for the data that is involved. -/ abbrev CostructuredArrowDownwards := CostructuredArrow (w.structuredArrowDownwards X₂) (StructuredArrow.mk g) section variable (X₁ : C₁) (a : X₂ ⟶ T.obj X₁) (b : L.obj X₁ ⟶ X₃) /-- Constructor for objects in `w.StructuredArrowRightwards g`. -/ abbrev StructuredArrowRightwards.mk (comm : R.map a ≫ w.app X₁ ≫ B.map b = g) : w.StructuredArrowRightwards g := StructuredArrow.mk (Y := CostructuredArrow.mk b) (CostructuredArrow.homMk a comm) /-- Constructor for objects in `w.CostructuredArrowDownwards g`. -/ abbrev CostructuredArrowDownwards.mk (comm : R.map a ≫ w.app X₁ ≫ B.map b = g) : w.CostructuredArrowDownwards g := CostructuredArrow.mk (Y := StructuredArrow.mk a) (StructuredArrow.homMk b (by simpa using comm)) variable (comm : R.map a ≫ w.app X₁ ≫ B.map b = g) variable {w g} lemma StructuredArrowRightwards.mk_surjective (f : w.StructuredArrowRightwards g) : ∃ (X₁ : C₁) (a : X₂ ⟶ T.obj X₁) (b : L.obj X₁ ⟶ X₃) (comm : R.map a ≫ w.app X₁ ≫ B.map b = g), f = mk w g X₁ a b comm := by obtain ⟨g, φ, rfl⟩ := StructuredArrow.mk_surjective f obtain ⟨X₁, b, rfl⟩ := g.mk_surjective obtain ⟨a, ha, rfl⟩ := CostructuredArrow.homMk_surjective φ exact ⟨X₁, a, b, by simpa using ha, rfl⟩ lemma CostructuredArrowDownwards.mk_surjective (f : w.CostructuredArrowDownwards g) : ∃ (X₁ : C₁) (a : X₂ ⟶ T.obj X₁) (b : L.obj X₁ ⟶ X₃) (comm : R.map a ≫ w.app X₁ ≫ B.map b = g), f = mk w g X₁ a b comm := by obtain ⟨g, φ, rfl⟩ := CostructuredArrow.mk_surjective f obtain ⟨X₁, a, rfl⟩ := g.mk_surjective obtain ⟨b, hb, rfl⟩ := StructuredArrow.homMk_surjective φ exact ⟨X₁, a, b, by simpa using hb, rfl⟩ end namespace EquivalenceJ /-- Given `w : TwoSquare T L R B` and a morphism `g : R.obj X₂ ⟶ B.obj X₃`, this is the obvious functor `w.StructuredArrowRightwards g ⥤ w.CostructuredArrowDownwards g`. -/ @[simps] def functor : w.StructuredArrowRightwards g ⥤ w.CostructuredArrowDownwards g where obj f := CostructuredArrow.mk (Y := StructuredArrow.mk f.hom.left) (StructuredArrow.homMk f.right.hom (by simpa using CostructuredArrow.w f.hom)) map {f₁ f₂} φ := CostructuredArrow.homMk (StructuredArrow.homMk φ.right.left (by dsimp; rw [← StructuredArrow.w φ]; rfl)) (by ext; exact CostructuredArrow.w φ.right) map_id _ := rfl map_comp _ _ := rfl /-- Given `w : TwoSquare T L R B` and a morphism `g : R.obj X₂ ⟶ B.obj X₃`, this is the obvious functor `w.CostructuredArrowDownwards g ⥤ w.StructuredArrowRightwards g`. -/ @[simps] def inverse : w.CostructuredArrowDownwards g ⥤ w.StructuredArrowRightwards g where obj f := StructuredArrow.mk (Y := CostructuredArrow.mk f.hom.right) (CostructuredArrow.homMk f.left.hom (by simpa using StructuredArrow.w f.hom)) map {f₁ f₂} φ := StructuredArrow.homMk (CostructuredArrow.homMk φ.left.right (by dsimp; rw [← CostructuredArrow.w φ]; rfl)) (by ext; exact StructuredArrow.w φ.left) map_id _ := rfl map_comp _ _ := rfl end EquivalenceJ /-- Given `w : TwoSquare T L R B` and a morphism `g : R.obj X₂ ⟶ B.obj X₃`, this is the obvious equivalence of categories `w.StructuredArrowRightwards g ≌ w.CostructuredArrowDownwards g`. -/ @[simps functor inverse unitIso counitIso] def equivalenceJ : w.StructuredArrowRightwards g ≌ w.CostructuredArrowDownwards g where functor := EquivalenceJ.functor w g inverse := EquivalenceJ.inverse w g unitIso := Iso.refl _ counitIso := Iso.refl _ lemma isConnected_rightwards_iff_downwards : IsConnected (w.StructuredArrowRightwards g) ↔ IsConnected (w.CostructuredArrowDownwards g) := isConnected_iff_of_equivalence (w.equivalenceJ g) end section /-- The functor `w.CostructuredArrowDownwards g ⥤ w.CostructuredArrowDownwards g'` induced by a morphism `γ` such that `R.map γ ≫ g = g'`. -/ @[simps] def costructuredArrowDownwardsPrecomp {X₂ X₂' : C₂} {X₃ : C₃} (g : R.obj X₂ ⟶ B.obj X₃) (g' : R.obj X₂' ⟶ B.obj X₃) (γ : X₂' ⟶ X₂) (hγ : R.map γ ≫ g = g') : w.CostructuredArrowDownwards g ⥤ w.CostructuredArrowDownwards g' where obj A := CostructuredArrowDownwards.mk _ _ A.left.right (γ ≫ A.left.hom) A.hom.right (by simpa [← hγ] using R.map γ ≫= StructuredArrow.w A.hom) map {A A'} φ := CostructuredArrow.homMk (StructuredArrow.homMk φ.left.right (by dsimp rw [assoc, StructuredArrow.w])) (by ext dsimp rw [← CostructuredArrow.w φ, structuredArrowDownwards_map] rfl) map_id A := rfl map_comp φ φ' := rfl end /-- Condition on `w : TwoSquare T L R B` expressing that it is a Guitart exact square. It is equivalent to saying that for any `X₃ : C₃`, the induced functor `CostructuredArrow L X₃ ⥤ CostructuredArrow R (B.obj X₃)` is final (see `guitartExact_iff_final`) or equivalently that for any `X₂ : C₂`, the induced functor `StructuredArrow X₂ T ⥤ StructuredArrow (R.obj X₂) B` is initial (see `guitartExact_iff_initial`). See also `guitartExact_iff_isConnected_rightwards`, `guitartExact_iff_isConnected_downwards` for characterizations in terms of the connectedness of auxiliary categories. -/ class GuitartExact : Prop where isConnected_rightwards {X₂ : C₂} {X₃ : C₃} (g : R.obj X₂ ⟶ B.obj X₃) : IsConnected (w.StructuredArrowRightwards g) lemma guitartExact_iff_isConnected_rightwards : w.GuitartExact ↔ ∀ {X₂ : C₂} {X₃ : C₃} (g : R.obj X₂ ⟶ B.obj X₃), IsConnected (w.StructuredArrowRightwards g) := ⟨fun h => h.isConnected_rightwards, fun h => ⟨h⟩⟩ lemma guitartExact_iff_isConnected_downwards : w.GuitartExact ↔ ∀ {X₂ : C₂} {X₃ : C₃} (g : R.obj X₂ ⟶ B.obj X₃), IsConnected (w.CostructuredArrowDownwards g) := by simp only [guitartExact_iff_isConnected_rightwards, isConnected_rightwards_iff_downwards] instance [hw : w.GuitartExact] {X₃ : C₃} (g : CostructuredArrow R (B.obj X₃)) : IsConnected (StructuredArrow g (w.costructuredArrowRightwards X₃)) := by rw [guitartExact_iff_isConnected_rightwards] at hw apply hw instance [hw : w.GuitartExact] {X₂ : C₂} (g : StructuredArrow (R.obj X₂) B) : IsConnected (CostructuredArrow (w.structuredArrowDownwards X₂) g) := by rw [guitartExact_iff_isConnected_downwards] at hw apply hw lemma guitartExact_iff_final : w.GuitartExact ↔ ∀ (X₃ : C₃), (w.costructuredArrowRightwards X₃).Final := ⟨fun _ _ => ⟨fun _ => inferInstance⟩, fun _ => ⟨fun _ => inferInstance⟩⟩ instance [hw : w.GuitartExact] (X₃ : C₃) : (w.costructuredArrowRightwards X₃).Final := by rw [guitartExact_iff_final] at hw apply hw lemma guitartExact_iff_initial : w.GuitartExact ↔ ∀ (X₂ : C₂), (w.structuredArrowDownwards X₂).Initial := ⟨fun _ _ => ⟨fun _ => inferInstance⟩, by rw [guitartExact_iff_isConnected_downwards] intros infer_instance⟩ instance [hw : w.GuitartExact] (X₂ : C₂) : (w.structuredArrowDownwards X₂).Initial := by rw [guitartExact_iff_initial] at hw apply hw /-- When the left and right functors of a 2-square are equivalences, and the natural transformation of the 2-square is an isomorphism, then the 2-square is Guitart exact. -/ instance (priority := 100) guitartExact_of_isEquivalence_of_isIso [L.IsEquivalence] [R.IsEquivalence] [IsIso w] : GuitartExact w := by rw [guitartExact_iff_initial] intro X₂ have := StructuredArrow.isEquivalence_post X₂ T R have : (Comma.mapRight _ w : StructuredArrow (R.obj X₂) _ ⥤ _).IsEquivalence := (Comma.mapRightIso _ (asIso w)).isEquivalence_functor have := StructuredArrow.isEquivalence_pre (R.obj X₂) L B dsimp only [structuredArrowDownwards] infer_instance instance guitartExact_id (F : C₁ ⥤ C₂) : GuitartExact (TwoSquare.mk (𝟭 C₁) F F (𝟭 C₂) (𝟙 F)) := by rw [guitartExact_iff_isConnected_rightwards] intro X₂ X₃ (g : F.obj X₂ ⟶ X₃) let Z := StructuredArrowRightwards (TwoSquare.mk (𝟭 C₁) F F (𝟭 C₂) (𝟙 F)) g let X₀ : Z := StructuredArrow.mk (Y := CostructuredArrow.mk g) (CostructuredArrow.homMk (𝟙 _)) have φ : ∀ (X : Z), X₀ ⟶ X := fun X => StructuredArrow.homMk (CostructuredArrow.homMk X.hom.left (by simpa using CostructuredArrow.w X.hom)) have : Nonempty Z := ⟨X₀⟩ apply zigzag_isConnected intro X Y exact Zigzag.of_inv_hom (φ X) (φ Y) end TwoSquare end CategoryTheory
CategoryTheory\GuitartExact\VerticalComposition.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.CatCommSq import Mathlib.CategoryTheory.GuitartExact.Basic /-! # Vertical composition of Guitart exact squares In this file, we show that the vertical composition of Guitart exact squares is Guitart exact. -/ namespace CategoryTheory open Category variable {C₁ C₂ C₃ D₁ D₂ D₃ : Type*} [Category C₁] [Category C₂] [Category C₃] [Category D₁] [Category D₂] [Category D₃] namespace TwoSquare section WhiskerVertical variable {T : C₁ ⥤ D₁} {L : C₁ ⥤ C₂} {R : D₁ ⥤ D₂} {B : C₂ ⥤ D₂} (w : TwoSquare T L R B) {L' : C₁ ⥤ C₂} {R' : D₁ ⥤ D₂} /-- Given `w : TwoSquare T L R B`, one may obtain a 2-square `TwoSquare T L' R' B` if we provide natural transformations `α : L ⟶ L'` and `β : R' ⟶ R`. -/ @[simps!] def whiskerVertical (α : L ⟶ L') (β : R' ⟶ R) : TwoSquare T L' R' B := whiskerLeft _ β ≫ w ≫ whiskerRight α _ namespace GuitartExact /-- A 2-square stays Guitart exact if we replace the left and right functors by isomorphic functors. See also `whiskerVertical_iff`. -/ lemma whiskerVertical [w.GuitartExact] (α : L ≅ L') (β : R ≅ R') : (w.whiskerVertical α.hom β.inv).GuitartExact := by rw [guitartExact_iff_initial] intro X₂ let e : structuredArrowDownwards (w.whiskerVertical α.hom β.inv) X₂ ≅ w.structuredArrowDownwards X₂ ⋙ (StructuredArrow.mapIso (β.app X₂) ).functor := NatIso.ofComponents (fun f => StructuredArrow.isoMk (α.symm.app f.right) (by dsimp simp only [NatTrans.naturality_assoc, assoc, NatIso.cancel_natIso_inv_left, ← B.map_comp, Iso.hom_inv_id_app, B.map_id, comp_id])) rw [Functor.initial_natIso_iff e] infer_instance /-- A 2-square is Guitart exact iff it is so after replacing the left and right functors by isomorphic functors. -/ @[simp] lemma whiskerVertical_iff (α : L ≅ L') (β : R ≅ R') : (w.whiskerVertical α.hom β.inv).GuitartExact ↔ w.GuitartExact := by constructor · intro h have : w = TwoSquare.whiskerVertical (TwoSquare.whiskerVertical w α.hom β.inv) α.inv β.hom := by ext X₁ simp only [Functor.comp_obj, whiskerVertical_app, assoc, Iso.hom_inv_id_app_assoc, ← B.map_comp, Iso.hom_inv_id_app, B.map_id, comp_id] rw [this] exact whiskerVertical (w.whiskerVertical α.hom β.inv) α.symm β.symm · intro h exact whiskerVertical w α β instance [w.GuitartExact] (α : L ⟶ L') (β : R' ⟶ R) [IsIso α] [IsIso β] : (w.whiskerVertical α β).GuitartExact := whiskerVertical w (asIso α) (asIso β).symm end GuitartExact end WhiskerVertical section VerticalComposition variable {H₁ : C₁ ⥤ D₁} {L₁ : C₁ ⥤ C₂} {R₁ : D₁ ⥤ D₂} {H₂ : C₂ ⥤ D₂} (w : TwoSquare H₁ L₁ R₁ H₂) {L₂ : C₂ ⥤ C₃} {R₂ : D₂ ⥤ D₃} {H₃ : C₃ ⥤ D₃} (w' : TwoSquare H₂ L₂ R₂ H₃) /-- The vertical composition of 2-squares. -/ @[simps!] def vComp : TwoSquare H₁ (L₁ ⋙ L₂) (R₁ ⋙ R₂) H₃ := (Functor.associator _ _ _).inv ≫ whiskerRight w R₂ ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft L₁ w' ≫ (Functor.associator _ _ _).inv /-- The canonical isomorphism between `w.structuredArrowDownwards Y₁ ⋙ w'.structuredArrowDownwards (R₁.obj Y₁)` and `(w.vComp w').structuredArrowDownwards Y₁.` -/ def structuredArrowDownwardsComp (Y₁ : D₁) : w.structuredArrowDownwards Y₁ ⋙ w'.structuredArrowDownwards (R₁.obj Y₁) ≅ (w.vComp w').structuredArrowDownwards Y₁ := NatIso.ofComponents (fun _ => StructuredArrow.isoMk (Iso.refl _)) /-- The vertical composition of 2-squares. (Variant where we allow the replacement of the vertical compositions by isomorphic functors.) -/ @[simps!] def vComp' {L₁₂ : C₁ ⥤ C₃} {R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ L₂ ≅ L₁₂) (eR : R₁ ⋙ R₂ ≅ R₁₂) : TwoSquare H₁ L₁₂ R₁₂ H₃ := (w.vComp w').whiskerVertical eL.hom eR.inv namespace GuitartExact instance vComp [hw : w.GuitartExact] [hw' : w'.GuitartExact] : (w.vComp w').GuitartExact := by simp only [TwoSquare.guitartExact_iff_initial] intro Y₁ rw [← Functor.initial_natIso_iff (structuredArrowDownwardsComp w w' Y₁)] infer_instance instance vComp' [GuitartExact w] [GuitartExact w'] {L₁₂ : C₁ ⥤ C₃} {R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ L₂ ≅ L₁₂) (eR : R₁ ⋙ R₂ ≅ R₁₂) : (w.vComp' w' eL eR).GuitartExact := by dsimp only [TwoSquare.vComp'] infer_instance lemma vComp_iff_of_equivalences (eL : C₂ ≌ C₃) (eR : D₂ ≌ D₃) (w' : H₂ ⋙ eR.functor ≅ eL.functor ⋙ H₃) : (w.vComp w'.hom).GuitartExact ↔ w.GuitartExact := by constructor · intro hww' letI : CatCommSq H₂ eL.functor eR.functor H₃ := ⟨w'⟩ have hw' : CatCommSq.iso H₂ eL.functor eR.functor H₃ = w' := rfl letI : CatCommSq H₃ eL.inverse eR.inverse H₂ := CatCommSq.vInvEquiv _ _ _ _ inferInstance let w'' := CatCommSq.iso H₃ eL.inverse eR.inverse H₂ let α : (L₁ ⋙ eL.functor) ⋙ eL.inverse ≅ L₁ := Functor.associator _ _ _ ≪≫ isoWhiskerLeft L₁ eL.unitIso.symm ≪≫ L₁.rightUnitor let β : (R₁ ⋙ eR.functor) ⋙ eR.inverse ≅ R₁ := Functor.associator _ _ _ ≪≫ isoWhiskerLeft R₁ eR.unitIso.symm ≪≫ R₁.rightUnitor have : w = (w.vComp w'.hom).vComp' w''.hom α β := by ext X₁ dsimp simp? [w'', β, α] says simp only [vComp'_app, Functor.comp_obj, Iso.trans_inv, isoWhiskerLeft_inv, Iso.symm_inv, assoc, NatTrans.comp_app, Functor.id_obj, Functor.rightUnitor_inv_app, whiskerLeft_app, Functor.associator_inv_app, comp_id, id_comp, vComp_app, Functor.map_comp, Equivalence.inv_fun_map, Iso.trans_hom, isoWhiskerLeft_hom, Iso.symm_hom, Functor.associator_hom_app, Functor.rightUnitor_hom_app, Iso.hom_inv_id_app_assoc, w'', α, β] erw [CatCommSq.vInv_iso'_hom_app] simp only [hw', assoc, ← eR.inverse.map_comp_assoc] rw [Equivalence.counitInv_app_functor] erw [← NatTrans.naturality_assoc] simp [← H₂.map_comp] rw [this] infer_instance · intro exact vComp w w'.hom lemma vComp'_iff_of_equivalences (E : C₂ ≌ C₃) (E' : D₂ ≌ D₃) (w' : H₂ ⋙ E'.functor ≅ E.functor ⋙ H₃) {L₁₂ : C₁ ⥤ C₃} {R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ E.functor ≅ L₁₂) (eR : R₁ ⋙ E'.functor ≅ R₁₂) : (w.vComp' w'.hom eL eR).GuitartExact ↔ w.GuitartExact := by rw [← vComp_iff_of_equivalences w E E' w', TwoSquare.vComp', whiskerVertical_iff] end GuitartExact end VerticalComposition end TwoSquare end CategoryTheory
CategoryTheory\Idempotents\Basic.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Abelian.Basic /-! # Idempotent complete categories In this file, we define the notion of idempotent complete categories (also known as Karoubian categories, or pseudoabelian in the case of preadditive categories). ## Main definitions - `IsIdempotentComplete C` expresses that `C` is idempotent complete, i.e. all idempotents in `C` split. Other characterisations of idempotent completeness are given by `isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent` and `isIdempotentComplete_iff_idempotents_have_kernels`. - `isIdempotentComplete_of_abelian` expresses that abelian categories are idempotent complete. - `isIdempotentComplete_iff_ofEquivalence` expresses that if two categories `C` and `D` are equivalent, then `C` is idempotent complete iff `D` is. - `isIdempotentComplete_iff_opposite` expresses that `Cᵒᵖ` is idempotent complete iff `C` is. ## References * [Stacks: Karoubian categories] https://stacks.math.columbia.edu/tag/09SF -/ open CategoryTheory open CategoryTheory.Category open CategoryTheory.Limits open CategoryTheory.Preadditive open Opposite namespace CategoryTheory variable (C : Type*) [Category C] /-- A category is idempotent complete iff all idempotent endomorphisms `p` split as a composition `p = e ≫ i` with `i ≫ e = 𝟙 _` -/ class IsIdempotentComplete : Prop where /-- A category is idempotent complete iff all idempotent endomorphisms `p` split as a composition `p = e ≫ i` with `i ≫ e = 𝟙 _` -/ idempotents_split : ∀ (X : C) (p : X ⟶ X), p ≫ p = p → ∃ (Y : C) (i : Y ⟶ X) (e : X ⟶ Y), i ≫ e = 𝟙 Y ∧ e ≫ i = p namespace Idempotents /-- A category is idempotent complete iff for all idempotent endomorphisms, the equalizer of the identity and this idempotent exists. -/ theorem isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent : IsIdempotentComplete C ↔ ∀ (X : C) (p : X ⟶ X), p ≫ p = p → HasEqualizer (𝟙 X) p := by constructor · intro intro X p hp rcases IsIdempotentComplete.idempotents_split X p hp with ⟨Y, i, e, ⟨h₁, h₂⟩⟩ exact ⟨Nonempty.intro { cone := Fork.ofι i (show i ≫ 𝟙 X = i ≫ p by rw [comp_id, ← h₂, ← assoc, h₁, id_comp]) isLimit := by apply Fork.IsLimit.mk' intro s refine ⟨s.ι ≫ e, ?_⟩ constructor · erw [assoc, h₂, ← Limits.Fork.condition s, comp_id] · intro m hm rw [Fork.ι_ofι] at hm rw [← hm] simp only [← hm, assoc, h₁] exact (comp_id m).symm }⟩ · intro h refine ⟨?_⟩ intro X p hp haveI : HasEqualizer (𝟙 X) p := h X p hp refine ⟨equalizer (𝟙 X) p, equalizer.ι (𝟙 X) p, equalizer.lift p (show p ≫ 𝟙 X = p ≫ p by rw [hp, comp_id]), ?_, equalizer.lift_ι _ _⟩ ext simp only [assoc, limit.lift_π, Eq.ndrec, id_eq, eq_mpr_eq_cast, Fork.ofι_pt, Fork.ofι_π_app, id_comp] rw [← equalizer.condition, comp_id] variable {C} /-- In a preadditive category, when `p : X ⟶ X` is idempotent, then `𝟙 X - p` is also idempotent. -/ theorem idem_of_id_sub_idem [Preadditive C] {X : C} (p : X ⟶ X) (hp : p ≫ p = p) : (𝟙 _ - p) ≫ (𝟙 _ - p) = 𝟙 _ - p := by simp only [comp_sub, sub_comp, id_comp, comp_id, hp, sub_self, sub_zero] variable (C) /-- A preadditive category is pseudoabelian iff all idempotent endomorphisms have a kernel. -/ theorem isIdempotentComplete_iff_idempotents_have_kernels [Preadditive C] : IsIdempotentComplete C ↔ ∀ (X : C) (p : X ⟶ X), p ≫ p = p → HasKernel p := by rw [isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent] constructor · intro h X p hp haveI : HasEqualizer (𝟙 X) (𝟙 X - p) := h X (𝟙 _ - p) (idem_of_id_sub_idem p hp) convert hasKernel_of_hasEqualizer (𝟙 X) (𝟙 X - p) rw [sub_sub_cancel] · intro h X p hp haveI : HasKernel (𝟙 _ - p) := h X (𝟙 _ - p) (idem_of_id_sub_idem p hp) apply Preadditive.hasEqualizer_of_hasKernel /-- An abelian category is idempotent complete. -/ instance (priority := 100) isIdempotentComplete_of_abelian (D : Type*) [Category D] [Abelian D] : IsIdempotentComplete D := by rw [isIdempotentComplete_iff_idempotents_have_kernels] intros infer_instance variable {C} theorem split_imp_of_iso {X X' : C} (φ : X ≅ X') (p : X ⟶ X) (p' : X' ⟶ X') (hpp' : p ≫ φ.hom = φ.hom ≫ p') (h : ∃ (Y : C) (i : Y ⟶ X) (e : X ⟶ Y), i ≫ e = 𝟙 Y ∧ e ≫ i = p) : ∃ (Y' : C) (i' : Y' ⟶ X') (e' : X' ⟶ Y'), i' ≫ e' = 𝟙 Y' ∧ e' ≫ i' = p' := by rcases h with ⟨Y, i, e, ⟨h₁, h₂⟩⟩ use Y, i ≫ φ.hom, φ.inv ≫ e constructor · slice_lhs 2 3 => rw [φ.hom_inv_id] rw [id_comp, h₁] · slice_lhs 2 3 => rw [h₂] rw [hpp', ← assoc, φ.inv_hom_id, id_comp] theorem split_iff_of_iso {X X' : C} (φ : X ≅ X') (p : X ⟶ X) (p' : X' ⟶ X') (hpp' : p ≫ φ.hom = φ.hom ≫ p') : (∃ (Y : C) (i : Y ⟶ X) (e : X ⟶ Y), i ≫ e = 𝟙 Y ∧ e ≫ i = p) ↔ ∃ (Y' : C) (i' : Y' ⟶ X') (e' : X' ⟶ Y'), i' ≫ e' = 𝟙 Y' ∧ e' ≫ i' = p' := by constructor · exact split_imp_of_iso φ p p' hpp' · apply split_imp_of_iso φ.symm p' p rw [← comp_id p, ← φ.hom_inv_id] slice_rhs 2 3 => rw [hpp'] slice_rhs 1 2 => erw [φ.inv_hom_id] simp only [id_comp] rfl theorem Equivalence.isIdempotentComplete {D : Type*} [Category D] (ε : C ≌ D) (h : IsIdempotentComplete C) : IsIdempotentComplete D := by refine ⟨?_⟩ intro X' p hp let φ := ε.counitIso.symm.app X' erw [split_iff_of_iso φ p (φ.inv ≫ p ≫ φ.hom) (by slice_rhs 1 2 => rw [φ.hom_inv_id] rw [id_comp])] rcases IsIdempotentComplete.idempotents_split (ε.inverse.obj X') (ε.inverse.map p) (by rw [← ε.inverse.map_comp, hp]) with ⟨Y, i, e, ⟨h₁, h₂⟩⟩ use ε.functor.obj Y, ε.functor.map i, ε.functor.map e constructor · rw [← ε.functor.map_comp, h₁, ε.functor.map_id] · simp only [← ε.functor.map_comp, h₂, Equivalence.fun_inv_map] rfl /-- If `C` and `D` are equivalent categories, that `C` is idempotent complete iff `D` is. -/ theorem isIdempotentComplete_iff_of_equivalence {D : Type*} [Category D] (ε : C ≌ D) : IsIdempotentComplete C ↔ IsIdempotentComplete D := by constructor · exact Equivalence.isIdempotentComplete ε · exact Equivalence.isIdempotentComplete ε.symm theorem isIdempotentComplete_of_isIdempotentComplete_opposite (h : IsIdempotentComplete Cᵒᵖ) : IsIdempotentComplete C := by refine ⟨?_⟩ intro X p hp rcases IsIdempotentComplete.idempotents_split (op X) p.op (by rw [← op_comp, hp]) with ⟨Y, i, e, ⟨h₁, h₂⟩⟩ use Y.unop, e.unop, i.unop constructor · simp only [← unop_comp, h₁] rfl · simp only [← unop_comp, h₂] rfl theorem isIdempotentComplete_iff_opposite : IsIdempotentComplete Cᵒᵖ ↔ IsIdempotentComplete C := by constructor · exact isIdempotentComplete_of_isIdempotentComplete_opposite · intro h apply isIdempotentComplete_of_isIdempotentComplete_opposite rw [isIdempotentComplete_iff_of_equivalence (opOpEquivalence C)] exact h instance [IsIdempotentComplete C] : IsIdempotentComplete Cᵒᵖ := by rwa [isIdempotentComplete_iff_opposite] end Idempotents end CategoryTheory
CategoryTheory\Idempotents\Biproducts.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Karoubi /-! # Biproducts in the idempotent completion of a preadditive category In this file, we define an instance expressing that if `C` is an additive category (i.e. is preadditive and has finite biproducts), then `Karoubi C` is also an additive category. We also obtain that for all `P : Karoubi C` where `C` is a preadditive category `C`, there is a canonical isomorphism `P ⊞ P.complement ≅ (toKaroubi C).obj P.X` in the category `Karoubi C` where `P.complement` is the formal direct factor of `P.X` corresponding to the idempotent endomorphism `𝟙 P.X - P.p`. -/ noncomputable section open CategoryTheory.Category open CategoryTheory.Limits open CategoryTheory.Preadditive universe v namespace CategoryTheory namespace Idempotents namespace Karoubi variable {C : Type*} [Category.{v} C] [Preadditive C] namespace Biproducts /-- The `Bicone` used in order to obtain the existence of the biproduct of a functor `J ⥤ Karoubi C` when the category `C` is additive. -/ @[simps] def bicone [HasFiniteBiproducts C] {J : Type} [Finite J] (F : J → Karoubi C) : Bicone F where pt := { X := biproduct fun j => (F j).X p := biproduct.map fun j => (F j).p idem := by ext simp only [assoc, biproduct.map_π, biproduct.map_π_assoc, idem] } π j := { f := (biproduct.map fun j => (F j).p) ≫ Bicone.π _ j comm := by simp only [assoc, biproduct.bicone_π, biproduct.map_π, biproduct.map_π_assoc, (F j).idem] } ι j := { f := biproduct.ι (fun j => (F j).X) j ≫ biproduct.map fun j => (F j).p comm := by simp only [biproduct.ι_map, assoc, idem_assoc] } ι_π j j' := by split_ifs with h · subst h simp only [biproduct.ι_map, biproduct.bicone_π, biproduct.map_π, eqToHom_refl, id_f, hom_ext_iff, comp_f, assoc, bicone_ι_π_self_assoc, idem] · dsimp simp only [biproduct.ι_map, biproduct.map_π, hom_ext_iff, comp_f, assoc, biproduct.ι_π_ne_assoc _ h, zero_comp, comp_zero, instZero_zero] end Biproducts theorem karoubi_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteBiproducts (Karoubi C) := { out := fun n => { has_biproduct := fun F => by apply hasBiproduct_of_total (Biproducts.bicone F) simp only [hom_ext_iff] refine biproduct.hom_ext' _ _ (fun j => ?_) simp only [Biproducts.bicone_pt_X, sum_hom, comp_f, Biproducts.bicone_π_f, biproduct.bicone_π, biproduct.map_π, Biproducts.bicone_ι_f, biproduct.ι_map, assoc, idem_assoc, id_f, Biproducts.bicone_pt_p, comp_sum] rw [Finset.sum_eq_single j] · simp only [bicone_ι_π_self_assoc] · intro b _ hb simp only [biproduct.ι_π_ne_assoc _ hb.symm, zero_comp] · intro hj simp only [Finset.mem_univ, not_true] at hj } } attribute [instance] karoubi_hasFiniteBiproducts /-- `P.complement` is the formal direct factor of `P.X` given by the idempotent endomorphism `𝟙 P.X - P.p` -/ @[simps] def complement (P : Karoubi C) : Karoubi C where X := P.X p := 𝟙 _ - P.p idem := idem_of_id_sub_idem P.p P.idem instance (P : Karoubi C) : HasBinaryBiproduct P P.complement := hasBinaryBiproduct_of_total { pt := P.X fst := P.decompId_p snd := P.complement.decompId_p inl := P.decompId_i inr := P.complement.decompId_i inl_fst := P.decompId.symm inl_snd := by simp only [instZero_zero, hom_ext_iff, complement_X, comp_f, decompId_i_f, decompId_p_f, complement_p, comp_sub, comp_id, idem, sub_self] inr_fst := by simp only [instZero_zero, hom_ext_iff, complement_X, comp_f, decompId_i_f, complement_p, decompId_p_f, sub_comp, id_comp, idem, sub_self] inr_snd := P.complement.decompId.symm } (by ext simp only [complement_X, comp_f, decompId_i_f, decompId_p_f, complement_p, instAdd_add, idem, comp_sub, comp_id, sub_comp, id_comp, sub_self, sub_zero, add_sub_cancel, id_f]) attribute [-simp] hom_ext_iff /-- A formal direct factor `P : Karoubi C` of an object `P.X : C` in a preadditive category is actually a direct factor of the image `(toKaroubi C).obj P.X` of `P.X` in the category `Karoubi C` -/ def decomposition (P : Karoubi C) : P ⊞ P.complement ≅ (toKaroubi _).obj P.X where hom := biprod.desc P.decompId_i P.complement.decompId_i inv := biprod.lift P.decompId_p P.complement.decompId_p hom_inv_id := by apply biprod.hom_ext' · rw [biprod.inl_desc_assoc, comp_id, biprod.lift_eq, comp_add, ← decompId_assoc, add_right_eq_self, ← assoc] refine (?_ =≫ _).trans zero_comp ext simp only [comp_f, toKaroubi_obj_X, decompId_i_f, decompId_p_f, complement_p, comp_sub, comp_id, idem, sub_self, instZero_zero] · rw [biprod.inr_desc_assoc, comp_id, biprod.lift_eq, comp_add, ← decompId_assoc, add_left_eq_self, ← assoc] refine (?_ =≫ _).trans zero_comp ext simp only [complement_X, comp_f, decompId_i_f, complement_p, decompId_p_f, sub_comp, id_comp, idem, sub_self, instZero_zero] inv_hom_id := by ext simp only [toKaroubi_obj_X, biprod.lift_desc, instAdd_add, comp_f, decompId_p_f, decompId_i_f, idem, complement_X, complement_p, comp_sub, comp_id, sub_comp, id_comp, sub_self, sub_zero, add_sub_cancel, id_f, toKaroubi_obj_p] end Karoubi end Idempotents end CategoryTheory
CategoryTheory\Idempotents\FunctorCategories.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Karoubi /-! # Idempotent completeness and functor categories In this file we define an instance `functor_category_isIdempotentComplete` expressing that a functor category `J ⥤ C` is idempotent complete when the target category `C` is. We also provide a fully faithful functor `karoubiFunctorCategoryEmbedding : Karoubi (J ⥤ C)) : J ⥤ Karoubi C` for all categories `J` and `C`. -/ open CategoryTheory open CategoryTheory.Category open CategoryTheory.Idempotents.Karoubi open CategoryTheory.Limits namespace CategoryTheory namespace Idempotents variable {J C : Type*} [Category J] [Category C] (P Q : Karoubi (J ⥤ C)) (f : P ⟶ Q) (X : J) @[reassoc (attr := simp)] theorem app_idem : P.p.app X ≫ P.p.app X = P.p.app X := congr_app P.idem X variable {P Q} @[reassoc (attr := simp)] theorem app_p_comp : P.p.app X ≫ f.f.app X = f.f.app X := congr_app (p_comp f) X @[reassoc (attr := simp)] theorem app_comp_p : f.f.app X ≫ Q.p.app X = f.f.app X := congr_app (comp_p f) X @[reassoc] theorem app_p_comm : P.p.app X ≫ f.f.app X = f.f.app X ≫ Q.p.app X := congr_app (p_comm f) X variable (J C) instance functor_category_isIdempotentComplete [IsIdempotentComplete C] : IsIdempotentComplete (J ⥤ C) := by refine ⟨fun F p hp => ?_⟩ have hC := (isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent C).mp inferInstance haveI : ∀ j : J, HasEqualizer (𝟙 _) (p.app j) := fun j => hC _ _ (congr_app hp j) /- We construct the direct factor `Y` associated to `p : F ⟶ F` by computing the equalizer of the identity and `p.app j` on each object `(j : J)`. -/ let Y : J ⥤ C := { obj := fun j => Limits.equalizer (𝟙 _) (p.app j) map := fun {j j'} φ => equalizer.lift (Limits.equalizer.ι (𝟙 _) (p.app j) ≫ F.map φ) (by rw [comp_id, assoc, p.naturality φ, ← assoc, ← Limits.equalizer.condition, comp_id]) } let i : Y ⟶ F := { app := fun j => equalizer.ι _ _ naturality := fun _ _ _ => by rw [equalizer.lift_ι] } let e : F ⟶ Y := { app := fun j => equalizer.lift (p.app j) (by simpa only [comp_id] using (congr_app hp j).symm) naturality := fun j j' φ => equalizer.hom_ext (by simp) } use Y, i, e constructor · ext j dsimp rw [assoc, equalizer.lift_ι, ← equalizer.condition, id_comp, comp_id] · ext j simp namespace KaroubiFunctorCategoryEmbedding variable {J C} /-- On objects, the functor which sends a formal direct factor `P` of a functor `F : J ⥤ C` to the functor `J ⥤ Karoubi C` which sends `(j : J)` to the corresponding direct factor of `F.obj j`. -/ @[simps] def obj (P : Karoubi (J ⥤ C)) : J ⥤ Karoubi C where obj j := ⟨P.X.obj j, P.p.app j, congr_app P.idem j⟩ map {j j'} φ := { f := P.p.app j ≫ P.X.map φ comm := by simp only [NatTrans.naturality, assoc] have h := congr_app P.idem j rw [NatTrans.comp_app] at h erw [reassoc_of% h, reassoc_of% h] } /-- Tautological action on maps of the functor `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)`. -/ @[simps] def map {P Q : Karoubi (J ⥤ C)} (f : P ⟶ Q) : obj P ⟶ obj Q where app j := ⟨f.f.app j, congr_app f.comm j⟩ end KaroubiFunctorCategoryEmbedding /-- The tautological fully faithful functor `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)`. -/ @[simps] def karoubiFunctorCategoryEmbedding : Karoubi (J ⥤ C) ⥤ J ⥤ Karoubi C where obj := KaroubiFunctorCategoryEmbedding.obj map := KaroubiFunctorCategoryEmbedding.map instance : (karoubiFunctorCategoryEmbedding J C).Full where map_surjective {P Q} f := ⟨{ f := { app := fun j => (f.app j).f naturality := fun j j' φ => by rw [← Karoubi.comp_p_assoc] have h := hom_ext_iff.mp (f.naturality φ) simp only [comp_f] at h dsimp [karoubiFunctorCategoryEmbedding] at h erw [← h, assoc, ← P.p.naturality_assoc φ, p_comp (f.app j')] } comm := by ext j exact (f.app j).comm }, rfl⟩ instance : (karoubiFunctorCategoryEmbedding J C).Faithful where map_injective h := by ext j exact hom_ext_iff.mp (congr_app h j) /-- The composition of `(J ⥤ C) ⥤ Karoubi (J ⥤ C)` and `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)` equals the functor `(J ⥤ C) ⥤ (J ⥤ Karoubi C)` given by the composition with `toKaroubi C : C ⥤ Karoubi C`. -/ theorem toKaroubi_comp_karoubiFunctorCategoryEmbedding : toKaroubi _ ⋙ karoubiFunctorCategoryEmbedding J C = (whiskeringRight J _ _).obj (toKaroubi C) := by apply Functor.ext · intro X Y f ext j dsimp [toKaroubi] simp only [eqToHom_app, eqToHom_refl] erw [comp_id, id_comp] · intro X apply Functor.ext · intro j j' φ ext dsimp simp · intro j rfl end Idempotents end CategoryTheory
CategoryTheory\Idempotents\FunctorExtension.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Karoubi /-! # Extension of functors to the idempotent completion In this file, we construct an extension `functorExtension₁` of functors `C ⥤ Karoubi D` to functors `Karoubi C ⥤ Karoubi D`. This results in an equivalence `karoubiUniversal₁ C D : (C ⥤ Karoubi D) ≌ (Karoubi C ⥤ Karoubi D)`. We also construct an extension `functorExtension₂` of functors `(C ⥤ D) ⥤ (Karoubi C ⥤ Karoubi D)`. Moreover, when `D` is idempotent complete, we get equivalences `karoubiUniversal₂ C D : C ⥤ D ≌ Karoubi C ⥤ Karoubi D` and `karoubiUniversal C D : C ⥤ D ≌ Karoubi C ⥤ D`. -/ namespace CategoryTheory namespace Idempotents open Category Karoubi variable {C D E : Type*} [Category C] [Category D] [Category E] /-- A natural transformation between functors `Karoubi C ⥤ D` is determined by its value on objects coming from `C`. -/ theorem natTrans_eq {F G : Karoubi C ⥤ D} (φ : F ⟶ G) (P : Karoubi C) : φ.app P = F.map (decompId_i P) ≫ φ.app P.X ≫ G.map (decompId_p P) := by rw [← φ.naturality, ← assoc, ← F.map_comp] conv_lhs => rw [← id_comp (φ.app P), ← F.map_id] congr apply decompId namespace FunctorExtension₁ /-- The canonical extension of a functor `C ⥤ Karoubi D` to a functor `Karoubi C ⥤ Karoubi D` -/ @[simps] def obj (F : C ⥤ Karoubi D) : Karoubi C ⥤ Karoubi D where obj P := ⟨(F.obj P.X).X, (F.map P.p).f, by simpa only [F.map_comp, hom_ext_iff] using F.congr_map P.idem⟩ map f := ⟨(F.map f.f).f, by simpa only [F.map_comp, hom_ext_iff] using F.congr_map f.comm⟩ /-- Extension of a natural transformation `φ` between functors `C ⥤ karoubi D` to a natural transformation between the extension of these functors to `karoubi C ⥤ karoubi D` -/ @[simps] def map {F G : C ⥤ Karoubi D} (φ : F ⟶ G) : obj F ⟶ obj G where app P := { f := (F.map P.p).f ≫ (φ.app P.X).f comm := by have h := φ.naturality P.p have h' := F.congr_map P.idem simp only [hom_ext_iff, Karoubi.comp_f, F.map_comp] at h h' simp only [obj_obj_p, assoc, ← h] slice_rhs 1 3 => rw [h', h'] } naturality _ _ f := by ext dsimp [obj] have h := φ.naturality f.f have h' := F.congr_map (comp_p f) have h'' := F.congr_map (p_comp f) simp only [hom_ext_iff, Functor.map_comp, comp_f] at h h' h'' ⊢ slice_rhs 2 3 => rw [← h] slice_lhs 1 2 => rw [h'] slice_rhs 1 2 => rw [h''] end FunctorExtension₁ variable (C D E) /-- The canonical functor `(C ⥤ Karoubi D) ⥤ (Karoubi C ⥤ Karoubi D)` -/ @[simps] def functorExtension₁ : (C ⥤ Karoubi D) ⥤ Karoubi C ⥤ Karoubi D where obj := FunctorExtension₁.obj map := FunctorExtension₁.map map_id F := by ext P exact comp_p (F.map P.p) map_comp {F G H} φ φ' := by ext P simp only [comp_f, FunctorExtension₁.map_app_f, NatTrans.comp_app, assoc] have h := φ.naturality P.p have h' := F.congr_map P.idem simp only [hom_ext_iff, comp_f, F.map_comp] at h h' slice_rhs 2 3 => rw [← h] slice_rhs 1 2 => rw [h'] simp only [assoc] /-- The natural isomorphism expressing that functors `Karoubi C ⥤ Karoubi D` obtained using `functorExtension₁` actually extends the original functors `C ⥤ Karoubi D`. -/ @[simps!] def functorExtension₁CompWhiskeringLeftToKaroubiIso : functorExtension₁ C D ⋙ (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) ≅ 𝟭 _ := NatIso.ofComponents (fun F => NatIso.ofComponents (fun X => { hom := { f := (F.obj X).p } inv := { f := (F.obj X).p } }) (fun {X Y} f => by aesop_cat)) (by aesop_cat) /-- The counit isomorphism of the equivalence `(C ⥤ Karoubi D) ≌ (Karoubi C ⥤ Karoubi D)`. -/ @[simps!] def KaroubiUniversal₁.counitIso : (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) ⋙ functorExtension₁ C D ≅ 𝟭 _ := NatIso.ofComponents (fun G => { hom := { app := fun P => { f := (G.map (decompId_p P)).f comm := by simpa only [hom_ext_iff, G.map_comp, G.map_id] using G.congr_map (show P.decompId_p = (toKaroubi C).map P.p ≫ P.decompId_p ≫ 𝟙 _ by simp) } naturality := fun P Q f => by simpa only [hom_ext_iff, G.map_comp] using (G.congr_map (decompId_p_naturality f)).symm } inv := { app := fun P => { f := (G.map (decompId_i P)).f comm := by simpa only [hom_ext_iff, G.map_comp, G.map_id] using G.congr_map (show P.decompId_i = 𝟙 _ ≫ P.decompId_i ≫ (toKaroubi C).map P.p by simp) } naturality := fun P Q f => by simpa only [hom_ext_iff, G.map_comp] using G.congr_map (decompId_i_naturality f) } hom_inv_id := by ext P simpa only [hom_ext_iff, G.map_comp, G.map_id] using G.congr_map P.decomp_p.symm inv_hom_id := by ext P simpa only [hom_ext_iff, G.map_comp, G.map_id] using G.congr_map P.decompId.symm }) (fun {X Y} φ => by ext P dsimp rw [natTrans_eq φ P, P.decomp_p] simp only [Functor.map_comp, comp_f, assoc] rfl) /-- The equivalence of categories `(C ⥤ Karoubi D) ≌ (Karoubi C ⥤ Karoubi D)`. -/ @[simps] def karoubiUniversal₁ : C ⥤ Karoubi D ≌ Karoubi C ⥤ Karoubi D where functor := functorExtension₁ C D inverse := (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) unitIso := (functorExtension₁CompWhiskeringLeftToKaroubiIso C D).symm counitIso := KaroubiUniversal₁.counitIso C D functor_unitIso_comp F := by ext P dsimp rw [comp_p, ← comp_f, ← F.map_comp, P.idem] /-- Compatibility isomorphisms of `functorExtension₁` with respect to the composition of functors. -/ def functorExtension₁Comp (F : C ⥤ Karoubi D) (G : D ⥤ Karoubi E) : (functorExtension₁ C E).obj (F ⋙ (functorExtension₁ D E).obj G) ≅ (functorExtension₁ C D).obj F ⋙ (functorExtension₁ D E).obj G := Iso.refl _ /-- The canonical functor `(C ⥤ D) ⥤ (Karoubi C ⥤ Karoubi D)` -/ @[simps!] def functorExtension₂ : (C ⥤ D) ⥤ Karoubi C ⥤ Karoubi D := (whiskeringRight C D (Karoubi D)).obj (toKaroubi D) ⋙ functorExtension₁ C D /-- The natural isomorphism expressing that functors `Karoubi C ⥤ Karoubi D` obtained using `functorExtension₂` actually extends the original functors `C ⥤ D`. -/ @[simps!] def functorExtension₂CompWhiskeringLeftToKaroubiIso : functorExtension₂ C D ⋙ (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) ≅ (whiskeringRight C D (Karoubi D)).obj (toKaroubi D) := NatIso.ofComponents (fun F => NatIso.ofComponents (fun X => { hom := { f := 𝟙 _ } inv := { f := 𝟙 _ } }) (by aesop_cat)) (by aesop_cat) section IsIdempotentComplete variable [IsIdempotentComplete D] /-- The equivalence of categories `(C ⥤ D) ≌ (Karoubi C ⥤ Karoubi D)` when `D` is idempotent complete. -/ @[simp] noncomputable def karoubiUniversal₂ : C ⥤ D ≌ Karoubi C ⥤ Karoubi D := (Equivalence.congrRight (toKaroubi D).asEquivalence).trans (karoubiUniversal₁ C D) theorem karoubiUniversal₂_functor_eq : (karoubiUniversal₂ C D).functor = functorExtension₂ C D := rfl noncomputable instance : (functorExtension₂ C D).IsEquivalence := by rw [← karoubiUniversal₂_functor_eq] infer_instance /-- The extension of functors functor `(C ⥤ D) ⥤ (Karoubi C ⥤ D)` when `D` is idempotent complete. -/ @[simps!] noncomputable def functorExtension : (C ⥤ D) ⥤ Karoubi C ⥤ D := functorExtension₂ C D ⋙ (whiskeringRight (Karoubi C) (Karoubi D) D).obj (toKaroubiEquivalence D).inverse /-- The equivalence `(C ⥤ D) ≌ (Karoubi C ⥤ D)` when `D` is idempotent complete. -/ @[simp] noncomputable def karoubiUniversal : C ⥤ D ≌ Karoubi C ⥤ D := (karoubiUniversal₂ C D).trans (Equivalence.congrRight (toKaroubi D).asEquivalence.symm) theorem karoubiUniversal_functor_eq : (karoubiUniversal C D).functor = functorExtension C D := rfl noncomputable instance : (functorExtension C D).IsEquivalence := by rw [← karoubiUniversal_functor_eq] infer_instance instance : ((whiskeringLeft C (Karoubi C) D).obj (toKaroubi C)).IsEquivalence := by have : ((whiskeringLeft C (Karoubi C) D).obj (toKaroubi C) ⋙ (whiskeringRight C D (Karoubi D)).obj (toKaroubi D) ⋙ (whiskeringRight C (Karoubi D) D).obj (Functor.inv (toKaroubi D))).IsEquivalence := by change (karoubiUniversal C D).inverse.IsEquivalence infer_instance exact Functor.isEquivalence_of_comp_right _ ((whiskeringRight C _ _).obj (toKaroubi D) ⋙ (whiskeringRight C (Karoubi D) D).obj (Functor.inv (toKaroubi D))) variable {C D} theorem whiskeringLeft_obj_preimage_app {F G : Karoubi C ⥤ D} (τ : toKaroubi _ ⋙ F ⟶ toKaroubi _ ⋙ G) (P : Karoubi C) : (((whiskeringLeft _ _ _).obj (toKaroubi _)).preimage τ).app P = F.map P.decompId_i ≫ τ.app P.X ≫ G.map P.decompId_p := by rw [natTrans_eq] congr 2 rw [← congr_app (((whiskeringLeft _ _ _).obj (toKaroubi _)).map_preimage τ) P.X] dsimp congr end IsIdempotentComplete end Idempotents end CategoryTheory
CategoryTheory\Idempotents\HomologicalComplex.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Additive import Mathlib.CategoryTheory.Idempotents.Karoubi /-! # Idempotent completeness and homological complexes This file contains simplifications lemmas for categories `Karoubi (HomologicalComplex C c)` and the construction of an equivalence of categories `Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`. When the category `C` is idempotent complete, it is shown that `HomologicalComplex (Karoubi C) c` is also idempotent complete. -/ namespace CategoryTheory open Category variable {C : Type*} [Category C] [Preadditive C] {ι : Type*} {c : ComplexShape ι} namespace Idempotents namespace Karoubi namespace HomologicalComplex variable {P Q : Karoubi (HomologicalComplex C c)} (f : P ⟶ Q) (n : ι) @[simp, reassoc] theorem p_comp_d : P.p.f n ≫ f.f.f n = f.f.f n := HomologicalComplex.congr_hom (p_comp f) n @[simp, reassoc] theorem comp_p_d : f.f.f n ≫ Q.p.f n = f.f.f n := HomologicalComplex.congr_hom (comp_p f) n @[reassoc] theorem p_comm_f : P.p.f n ≫ f.f.f n = f.f.f n ≫ Q.p.f n := HomologicalComplex.congr_hom (p_comm f) n variable (P) @[simp, reassoc] theorem p_idem : P.p.f n ≫ P.p.f n = P.p.f n := HomologicalComplex.congr_hom P.idem n end HomologicalComplex end Karoubi open Karoubi namespace KaroubiHomologicalComplexEquivalence namespace Functor /-- The functor `Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c`, on objects. -/ @[simps] def obj (P : Karoubi (HomologicalComplex C c)) : HomologicalComplex (Karoubi C) c where X n := ⟨P.X.X n, P.p.f n, by simpa only [HomologicalComplex.comp_f] using HomologicalComplex.congr_hom P.idem n⟩ d i j := { f := P.p.f i ≫ P.X.d i j } shape i j hij := by simp only [hom_eq_zero_iff, P.X.shape i j hij, Limits.comp_zero]; aesop_cat /-- The functor `Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c`, on morphisms. -/ @[simps] def map {P Q : Karoubi (HomologicalComplex C c)} (f : P ⟶ Q) : obj P ⟶ obj Q where f n := { f := f.f.f n } end Functor /-- The functor `Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c`. -/ @[simps] def functor : Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c where obj := Functor.obj map f := Functor.map f namespace Inverse /-- The functor `HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c)`, on objects -/ @[simps] def obj (K : HomologicalComplex (Karoubi C) c) : Karoubi (HomologicalComplex C c) where X := { X := fun n => (K.X n).X d := fun i j => (K.d i j).f shape := fun i j hij => hom_eq_zero_iff.mp (K.shape i j hij) d_comp_d' := fun i j k _ _ => by simpa only [comp_f] using hom_eq_zero_iff.mp (K.d_comp_d i j k) } p := { f := fun n => (K.X n).p } /-- The functor `HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c)`, on morphisms -/ @[simps] def map {K L : HomologicalComplex (Karoubi C) c} (f : K ⟶ L) : obj K ⟶ obj L where f := { f := fun n => (f.f n).f comm' := fun i j hij => by simpa only [comp_f] using hom_ext_iff.mp (f.comm' i j hij) } end Inverse /-- The functor `HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c)`. -/ @[simps] def inverse : HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c) where obj := Inverse.obj map f := Inverse.map f /-- The counit isomorphism of the equivalence `Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`. -/ @[simps!] def counitIso : inverse ⋙ functor ≅ 𝟭 (HomologicalComplex (Karoubi C) c) := eqToIso (Functor.ext (fun P => HomologicalComplex.ext (by aesop_cat) (by aesop_cat)) (by aesop_cat)) /-- The unit isomorphism of the equivalence `Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`. -/ @[simps] def unitIso : 𝟭 (Karoubi (HomologicalComplex C c)) ≅ functor ⋙ inverse where hom := { app := fun P => { f := { f := fun n => P.p.f n comm' := fun i j _ => by dsimp simp only [HomologicalComplex.Hom.comm, HomologicalComplex.Hom.comm_assoc, HomologicalComplex.p_idem] } comm := by ext n dsimp simp only [HomologicalComplex.p_idem] } naturality := fun P Q φ => by ext dsimp simp only [comp_f, HomologicalComplex.comp_f, HomologicalComplex.comp_p_d, Inverse.map_f_f, Functor.map_f_f, HomologicalComplex.p_comp_d] } inv := { app := fun P => { f := { f := fun n => P.p.f n comm' := fun i j _ => by dsimp simp only [HomologicalComplex.Hom.comm, assoc, HomologicalComplex.p_idem] } comm := by ext n dsimp simp only [HomologicalComplex.p_idem] } naturality := fun P Q φ => by ext dsimp simp only [comp_f, HomologicalComplex.comp_f, Inverse.map_f_f, Functor.map_f_f, HomologicalComplex.comp_p_d, HomologicalComplex.p_comp_d] } hom_inv_id := by ext dsimp simp only [HomologicalComplex.p_idem, comp_f, HomologicalComplex.comp_f, _root_.id_eq] inv_hom_id := by ext dsimp simp only [HomologicalComplex.p_idem, comp_f, HomologicalComplex.comp_f, _root_.id_eq, Inverse.obj_p_f, Functor.obj_X_p] end KaroubiHomologicalComplexEquivalence variable (C) (c) /-- The equivalence `Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`. -/ @[simps] def karoubiHomologicalComplexEquivalence : Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c where functor := KaroubiHomologicalComplexEquivalence.functor inverse := KaroubiHomologicalComplexEquivalence.inverse unitIso := KaroubiHomologicalComplexEquivalence.unitIso counitIso := KaroubiHomologicalComplexEquivalence.counitIso variable (α : Type*) [AddRightCancelSemigroup α] [One α] /-- The equivalence `Karoubi (ChainComplex C α) ≌ ChainComplex (Karoubi C) α`. -/ @[simps!] def karoubiChainComplexEquivalence : Karoubi (ChainComplex C α) ≌ ChainComplex (Karoubi C) α := karoubiHomologicalComplexEquivalence C (ComplexShape.down α) /-- The equivalence `Karoubi (CochainComplex C α) ≌ CochainComplex (Karoubi C) α`. -/ @[simps!] def karoubiCochainComplexEquivalence : Karoubi (CochainComplex C α) ≌ CochainComplex (Karoubi C) α := karoubiHomologicalComplexEquivalence C (ComplexShape.up α) instance [IsIdempotentComplete C] : IsIdempotentComplete (HomologicalComplex C c) := by rw [isIdempotentComplete_iff_of_equivalence ((toKaroubiEquivalence C).mapHomologicalComplex c), ← isIdempotentComplete_iff_of_equivalence (karoubiHomologicalComplexEquivalence C c)] infer_instance end Idempotents end CategoryTheory
CategoryTheory\Idempotents\Karoubi.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Basic import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Equivalence /-! # The Karoubi envelope of a category In this file, we define the Karoubi envelope `Karoubi C` of a category `C`. ## Main constructions and definitions - `Karoubi C` is the Karoubi envelope of a category `C`: it is an idempotent complete category. It is also preadditive when `C` is preadditive. - `toKaroubi C : C ⥤ Karoubi C` is a fully faithful functor, which is an equivalence (`toKaroubiIsEquivalence`) when `C` is idempotent complete. -/ noncomputable section open CategoryTheory.Category CategoryTheory.Preadditive CategoryTheory.Limits namespace CategoryTheory variable (C : Type*) [Category C] namespace Idempotents -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- In a preadditive category `C`, when an object `X` decomposes as `X ≅ P ⨿ Q`, one may consider `P` as a direct factor of `X` and up to unique isomorphism, it is determined by the obvious idempotent `X ⟶ P ⟶ X` which is the projection onto `P` with kernel `Q`. More generally, one may define a formal direct factor of an object `X : C` : it consists of an idempotent `p : X ⟶ X` which is thought as the "formal image" of `p`. The type `Karoubi C` shall be the type of the objects of the karoubi envelope of `C`. It makes sense for any category `C`. -/ structure Karoubi where /-- an object of the underlying category -/ X : C /-- an endomorphism of the object -/ p : X ⟶ X /-- the condition that the given endomorphism is an idempotent -/ idem : p ≫ p = p := by aesop_cat namespace Karoubi variable {C} attribute [reassoc (attr := simp)] idem @[ext (iff := false)] theorem ext {P Q : Karoubi C} (h_X : P.X = Q.X) (h_p : P.p ≫ eqToHom h_X = eqToHom h_X ≫ Q.p) : P = Q := by cases P cases Q dsimp at h_X h_p subst h_X simpa only [mk.injEq, heq_eq_eq, true_and, eqToHom_refl, comp_id, id_comp] using h_p /-- A morphism `P ⟶ Q` in the category `Karoubi C` is a morphism in the underlying category `C` which satisfies a relation, which in the preadditive case, expresses that it induces a map between the corresponding "formal direct factors" and that it vanishes on the complement formal direct factor. -/ @[ext] structure Hom (P Q : Karoubi C) where /-- a morphism between the underlying objects -/ f : P.X ⟶ Q.X /-- compatibility of the given morphism with the given idempotents -/ comm : f = P.p ≫ f ≫ Q.p := by aesop_cat instance [Preadditive C] (P Q : Karoubi C) : Inhabited (Hom P Q) := ⟨⟨0, by rw [zero_comp, comp_zero]⟩⟩ @[reassoc (attr := simp)] theorem p_comp {P Q : Karoubi C} (f : Hom P Q) : P.p ≫ f.f = f.f := by rw [f.comm, ← assoc, P.idem] @[reassoc (attr := simp)] theorem comp_p {P Q : Karoubi C} (f : Hom P Q) : f.f ≫ Q.p = f.f := by rw [f.comm, assoc, assoc, Q.idem] @[reassoc] theorem p_comm {P Q : Karoubi C} (f : Hom P Q) : P.p ≫ f.f = f.f ≫ Q.p := by rw [p_comp, comp_p] theorem comp_proof {P Q R : Karoubi C} (g : Hom Q R) (f : Hom P Q) : f.f ≫ g.f = P.p ≫ (f.f ≫ g.f) ≫ R.p := by rw [assoc, comp_p, ← assoc, p_comp] /-- The category structure on the karoubi envelope of a category. -/ instance : Category (Karoubi C) where Hom := Karoubi.Hom id P := ⟨P.p, by repeat' rw [P.idem]⟩ comp f g := ⟨f.f ≫ g.f, Karoubi.comp_proof g f⟩ @[simp] theorem hom_ext_iff {P Q : Karoubi C} {f g : P ⟶ Q} : f = g ↔ f.f = g.f := by constructor · intro h rw [h] · apply Hom.ext -- Porting note: added because `Hom.ext` is not triggered automatically @[ext] theorem hom_ext {P Q : Karoubi C} (f g : P ⟶ Q) (h : f.f = g.f) : f = g := by simpa [hom_ext_iff] using h @[simp] theorem comp_f {P Q R : Karoubi C} (f : P ⟶ Q) (g : Q ⟶ R) : (f ≫ g).f = f.f ≫ g.f := rfl @[simp] theorem id_f {P : Karoubi C} : Hom.f (𝟙 P) = P.p := rfl @[deprecated (since := "2024-07-15")] theorem id_eq {P : Karoubi C} : 𝟙 P = ⟨P.p, by repeat' rw [P.idem]⟩ := rfl /-- It is possible to coerce an object of `C` into an object of `Karoubi C`. See also the functor `toKaroubi`. -/ instance coe : CoeTC C (Karoubi C) := ⟨fun X => ⟨X, 𝟙 X, by rw [comp_id]⟩⟩ -- Porting note: removed @[simp] as the linter complains theorem coe_X (X : C) : (X : Karoubi C).X = X := rfl @[simp] theorem coe_p (X : C) : (X : Karoubi C).p = 𝟙 X := rfl @[simp] theorem eqToHom_f {P Q : Karoubi C} (h : P = Q) : Karoubi.Hom.f (eqToHom h) = P.p ≫ eqToHom (congr_arg Karoubi.X h) := by subst h simp only [eqToHom_refl, Karoubi.id_f, comp_id] end Karoubi /-- The obvious fully faithful functor `toKaroubi` sends an object `X : C` to the obvious formal direct factor of `X` given by `𝟙 X`. -/ @[simps] def toKaroubi : C ⥤ Karoubi C where obj X := ⟨X, 𝟙 X, by rw [comp_id]⟩ map f := ⟨f, by simp only [comp_id, id_comp]⟩ instance : (toKaroubi C).Full where map_surjective f := ⟨f.f, rfl⟩ instance : (toKaroubi C).Faithful where map_injective := fun h => congr_arg Karoubi.Hom.f h variable {C} @[simps add] instance instAdd [Preadditive C] {P Q : Karoubi C} : Add (P ⟶ Q) where add f g := ⟨f.f + g.f, by rw [add_comp, comp_add, ← f.comm, ← g.comm]⟩ @[simps neg] instance instNeg [Preadditive C] {P Q : Karoubi C} : Neg (P ⟶ Q) where neg f := ⟨-f.f, by simpa only [neg_comp, comp_neg, neg_inj] using f.comm⟩ @[simps zero] instance instZero [Preadditive C] {P Q : Karoubi C} : Zero (P ⟶ Q) where zero := ⟨0, by simp only [comp_zero, zero_comp]⟩ -- dsimp loops when applying this lemma to its LHS, -- probably https://github.com/leanprover/lean4/pull/2867 attribute [nolint simpNF] CategoryTheory.Idempotents.instZero_zero instance instAddCommGroupHom [Preadditive C] {P Q : Karoubi C} : AddCommGroup (P ⟶ Q) where zero_add f := by ext apply zero_add add_zero f := by ext apply add_zero add_assoc f g h' := by ext apply add_assoc add_comm f g := by ext apply add_comm add_left_neg f := by ext apply add_left_neg zsmul := zsmulRec nsmul := nsmulRec namespace Karoubi theorem hom_eq_zero_iff [Preadditive C] {P Q : Karoubi C} {f : P ⟶ Q} : f = 0 ↔ f.f = 0 := hom_ext_iff /-- The map sending `f : P ⟶ Q` to `f.f : P.X ⟶ Q.X` is additive. -/ @[simps] def inclusionHom [Preadditive C] (P Q : Karoubi C) : AddMonoidHom (P ⟶ Q) (P.X ⟶ Q.X) where toFun f := f.f map_zero' := rfl map_add' _ _ := rfl @[simp] theorem sum_hom [Preadditive C] {P Q : Karoubi C} {α : Type*} (s : Finset α) (f : α → (P ⟶ Q)) : (∑ x ∈ s, f x).f = ∑ x ∈ s, (f x).f := map_sum (inclusionHom P Q) f s end Karoubi /-- The category `Karoubi C` is preadditive if `C` is. -/ instance [Preadditive C] : Preadditive (Karoubi C) where homGroup P Q := by infer_instance instance [Preadditive C] : Functor.Additive (toKaroubi C) where open Karoubi variable (C) instance : IsIdempotentComplete (Karoubi C) := by refine ⟨?_⟩ intro P p hp simp only [hom_ext_iff, comp_f] at hp use ⟨P.X, p.f, hp⟩ use ⟨p.f, by rw [comp_p p, hp]⟩ use ⟨p.f, by rw [hp, p_comp p]⟩ simp [hp] instance [IsIdempotentComplete C] : (toKaroubi C).EssSurj := ⟨fun P => by rcases IsIdempotentComplete.idempotents_split P.X P.p P.idem with ⟨Y, i, e, ⟨h₁, h₂⟩⟩ use Y exact Nonempty.intro { hom := ⟨i, by erw [id_comp, ← h₂, ← assoc, h₁, id_comp]⟩ inv := ⟨e, by erw [comp_id, ← h₂, assoc, h₁, comp_id]⟩ }⟩ /-- If `C` is idempotent complete, the functor `toKaroubi : C ⥤ Karoubi C` is an equivalence. -/ instance toKaroubi_isEquivalence [IsIdempotentComplete C] : (toKaroubi C).IsEquivalence where /-- The equivalence `C ≅ Karoubi C` when `C` is idempotent complete. -/ def toKaroubiEquivalence [IsIdempotentComplete C] : C ≌ Karoubi C := (toKaroubi C).asEquivalence instance toKaroubiEquivalence_functor_additive [Preadditive C] [IsIdempotentComplete C] : (toKaroubiEquivalence C).functor.Additive := (inferInstance : (toKaroubi C).Additive) namespace Karoubi variable {C} /-- The split mono which appears in the factorisation `decompId P`. -/ @[simps] def decompId_i (P : Karoubi C) : P ⟶ P.X := ⟨P.p, by erw [coe_p, comp_id, P.idem]⟩ /-- The split epi which appears in the factorisation `decompId P`. -/ @[simps] def decompId_p (P : Karoubi C) : (P.X : Karoubi C) ⟶ P := ⟨P.p, by erw [coe_p, id_comp, P.idem]⟩ /-- The formal direct factor of `P.X` given by the idempotent `P.p` in the category `C` is actually a direct factor in the category `Karoubi C`. -/ @[reassoc] theorem decompId (P : Karoubi C) : 𝟙 P = decompId_i P ≫ decompId_p P := by ext simp only [comp_f, id_f, P.idem, decompId_i, decompId_p] theorem decomp_p (P : Karoubi C) : (toKaroubi C).map P.p = decompId_p P ≫ decompId_i P := by ext simp only [comp_f, decompId_p_f, decompId_i_f, P.idem, toKaroubi_map_f] theorem decompId_i_toKaroubi (X : C) : decompId_i ((toKaroubi C).obj X) = 𝟙 _ := by rfl theorem decompId_p_toKaroubi (X : C) : decompId_p ((toKaroubi C).obj X) = 𝟙 _ := by rfl theorem decompId_i_naturality {P Q : Karoubi C} (f : P ⟶ Q) : f ≫ decompId_i Q = decompId_i P ≫ (by exact Hom.mk f.f (by simp)) := by aesop_cat theorem decompId_p_naturality {P Q : Karoubi C} (f : P ⟶ Q) : decompId_p P ≫ f = (by exact Hom.mk f.f (by simp)) ≫ decompId_p Q := by aesop_cat @[simp] theorem zsmul_hom [Preadditive C] {P Q : Karoubi C} (n : ℤ) (f : P ⟶ Q) : (n • f).f = n • f.f := map_zsmul (inclusionHom P Q) n f end Karoubi end Idempotents end CategoryTheory
CategoryTheory\Idempotents\KaroubiKaroubi.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Karoubi /-! # Idempotence of the Karoubi envelope In this file, we construct the equivalence of categories `KaroubiKaroubi.equivalence C : Karoubi C ≌ Karoubi (Karoubi C)` for any category `C`. -/ open CategoryTheory.Category open CategoryTheory.Idempotents.Karoubi namespace CategoryTheory namespace Idempotents namespace KaroubiKaroubi variable (C : Type*) [Category C] -- Porting note (#10688): added to ease automation @[reassoc (attr := simp)] lemma idem_f (P : Karoubi (Karoubi C)) : P.p.f ≫ P.p.f = P.p.f := by simpa only [hom_ext_iff, comp_f] using P.idem @[reassoc] lemma p_comm_f {P Q : Karoubi (Karoubi C)} (f : P ⟶ Q) : P.p.f ≫ f.f.f = f.f.f ≫ Q.p.f := by simpa only [hom_ext_iff, comp_f] using p_comm f /-- The canonical functor `Karoubi (Karoubi C) ⥤ Karoubi C` -/ @[simps] def inverse : Karoubi (Karoubi C) ⥤ Karoubi C where obj P := ⟨P.X.X, P.p.f, by simpa only [hom_ext_iff] using P.idem⟩ map f := ⟨f.f.f, by simpa only [hom_ext_iff] using f.comm⟩ instance [Preadditive C] : Functor.Additive (inverse C) where /-- The unit isomorphism of the equivalence -/ @[simps!] def unitIso : 𝟭 (Karoubi C) ≅ toKaroubi (Karoubi C) ⋙ inverse C := eqToIso (Functor.ext (by aesop_cat) (by aesop_cat)) attribute [local simp] p_comm_f in /-- The counit isomorphism of the equivalence -/ @[simps] def counitIso : inverse C ⋙ toKaroubi (Karoubi C) ≅ 𝟭 (Karoubi (Karoubi C)) where hom := { app := fun P => { f := { f := P.p.1 } } } inv := { app := fun P => { f := { f := P.p.1 } } } /-- The equivalence `Karoubi C ≌ Karoubi (Karoubi C)` -/ @[simps] def equivalence : Karoubi C ≌ Karoubi (Karoubi C) where functor := toKaroubi (Karoubi C) inverse := KaroubiKaroubi.inverse C unitIso := KaroubiKaroubi.unitIso C counitIso := KaroubiKaroubi.counitIso C instance equivalence.additive_functor [Preadditive C] : Functor.Additive (equivalence C).functor where instance equivalence.additive_inverse [Preadditive C] : Functor.Additive (equivalence C).inverse where end KaroubiKaroubi end Idempotents end CategoryTheory
CategoryTheory\Idempotents\SimplicialObject.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.AlgebraicTopology.SimplicialObject import Mathlib.CategoryTheory.Idempotents.FunctorCategories /-! # Idempotent completeness of categories of simplicial objects In this file, we provide an instance expressing that `SimplicialObject C` and `CosimplicialObject C` are idempotent complete categories when the category `C` is. -/ namespace CategoryTheory namespace Idempotents variable {C : Type*} [Category C] [IsIdempotentComplete C] instance : IsIdempotentComplete (SimplicialObject C) := Idempotents.functor_category_isIdempotentComplete _ _ instance : IsIdempotentComplete (CosimplicialObject C) := Idempotents.functor_category_isIdempotentComplete _ _ end Idempotents end CategoryTheory
CategoryTheory\LiftingProperties\Adjunction.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.LiftingProperties.Basic import Mathlib.CategoryTheory.Adjunction.Basic /-! # Lifting properties and adjunction In this file, we obtain `Adjunction.HasLiftingProperty_iff`, which states that when we have an adjunction `adj : G ⊣ F` between two functors `G : C ⥤ D` and `F : D ⥤ C`, then a morphism of the form `G.map i` has the left lifting property in `D` with respect to a morphism `p` if and only the morphism `i` has the left lifting property in `C` with respect to `F.map p`. -/ namespace CategoryTheory open Category variable {C D : Type*} [Category C] [Category D] {G : C ⥤ D} {F : D ⥤ C} namespace CommSq section variable {A B : C} {X Y : D} {i : A ⟶ B} {p : X ⟶ Y} {u : G.obj A ⟶ X} {v : G.obj B ⟶ Y} /-- When we have an adjunction `G ⊣ F`, any commutative square where the left map is of the form `G.map i` and the right map is `p` has an "adjoint" commutative square whose left map is `i` and whose right map is `F.map p`. -/ theorem right_adjoint (sq : CommSq u (G.map i) p v) (adj : G ⊣ F) : CommSq (adj.homEquiv _ _ u) i (F.map p) (adj.homEquiv _ _ v) := ⟨by simp only [Adjunction.homEquiv_unit, assoc, ← F.map_comp, sq.w] rw [F.map_comp, Adjunction.unit_naturality_assoc]⟩ variable (sq : CommSq u (G.map i) p v) (adj : G ⊣ F) /-- The liftings of a commutative are in bijection with the liftings of its (right) adjoint square. -/ def rightAdjointLiftStructEquiv : sq.LiftStruct ≃ (sq.right_adjoint adj).LiftStruct where toFun l := { l := adj.homEquiv _ _ l.l fac_left := by rw [← adj.homEquiv_naturality_left, l.fac_left] fac_right := by rw [← Adjunction.homEquiv_naturality_right, l.fac_right] } invFun l := { l := (adj.homEquiv _ _).symm l.l fac_left := by rw [← Adjunction.homEquiv_naturality_left_symm, l.fac_left] apply (adj.homEquiv _ _).left_inv fac_right := by rw [← Adjunction.homEquiv_naturality_right_symm, l.fac_right] apply (adj.homEquiv _ _).left_inv } left_inv := by aesop_cat right_inv := by aesop_cat /-- A square has a lifting if and only if its (right) adjoint square has a lifting. -/ theorem right_adjoint_hasLift_iff : HasLift (sq.right_adjoint adj) ↔ HasLift sq := by simp only [HasLift.iff] exact Equiv.nonempty_congr (sq.rightAdjointLiftStructEquiv adj).symm instance [HasLift sq] : HasLift (sq.right_adjoint adj) := by rw [right_adjoint_hasLift_iff] infer_instance end section variable {A B : C} {X Y : D} {i : A ⟶ B} {p : X ⟶ Y} {u : A ⟶ F.obj X} {v : B ⟶ F.obj Y} /-- When we have an adjunction `G ⊣ F`, any commutative square where the left map is of the form `i` and the right map is `F.map p` has an "adjoint" commutative square whose left map is `G.map i` and whose right map is `p`. -/ theorem left_adjoint (sq : CommSq u i (F.map p) v) (adj : G ⊣ F) : CommSq ((adj.homEquiv _ _).symm u) (G.map i) p ((adj.homEquiv _ _).symm v) := ⟨by simp only [Adjunction.homEquiv_counit, assoc, ← G.map_comp_assoc, ← sq.w] rw [G.map_comp, assoc, Adjunction.counit_naturality]⟩ variable (sq : CommSq u i (F.map p) v) (adj : G ⊣ F) /-- The liftings of a commutative are in bijection with the liftings of its (left) adjoint square. -/ def leftAdjointLiftStructEquiv : sq.LiftStruct ≃ (sq.left_adjoint adj).LiftStruct where toFun l := { l := (adj.homEquiv _ _).symm l.l fac_left := by rw [← adj.homEquiv_naturality_left_symm, l.fac_left] fac_right := by rw [← adj.homEquiv_naturality_right_symm, l.fac_right] } invFun l := { l := (adj.homEquiv _ _) l.l fac_left := by rw [← adj.homEquiv_naturality_left, l.fac_left] apply (adj.homEquiv _ _).right_inv fac_right := by rw [← adj.homEquiv_naturality_right, l.fac_right] apply (adj.homEquiv _ _).right_inv } left_inv := by aesop_cat right_inv := by aesop_cat /-- A (left) adjoint square has a lifting if and only if the original square has a lifting. -/ theorem left_adjoint_hasLift_iff : HasLift (sq.left_adjoint adj) ↔ HasLift sq := by simp only [HasLift.iff] exact Equiv.nonempty_congr (sq.leftAdjointLiftStructEquiv adj).symm instance [HasLift sq] : HasLift (sq.left_adjoint adj) := by rw [left_adjoint_hasLift_iff] infer_instance end end CommSq namespace Adjunction theorem hasLiftingProperty_iff (adj : G ⊣ F) {A B : C} {X Y : D} (i : A ⟶ B) (p : X ⟶ Y) : HasLiftingProperty (G.map i) p ↔ HasLiftingProperty i (F.map p) := by constructor <;> intro <;> constructor <;> intro f g sq · rw [← sq.left_adjoint_hasLift_iff adj] infer_instance · rw [← sq.right_adjoint_hasLift_iff adj] infer_instance end Adjunction end CategoryTheory
CategoryTheory\LiftingProperties\Basic.lean
/- Copyright (c) 2021 Jakob Scholbach. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob Scholbach, Joël Riou -/ import Mathlib.CategoryTheory.CommSq /-! # Lifting properties This file defines the lifting property of two morphisms in a category and shows basic properties of this notion. ## Main results - `HasLiftingProperty`: the definition of the lifting property ## Tags lifting property @TODO : 1) define llp/rlp with respect to a `morphism_property` 2) retracts, direct/inverse images, (co)products, adjunctions -/ universe v namespace CategoryTheory open Category variable {C : Type*} [Category C] {A B B' X Y Y' : C} (i : A ⟶ B) (i' : B ⟶ B') (p : X ⟶ Y) (p' : Y ⟶ Y') /-- `HasLiftingProperty i p` means that `i` has the left lifting property with respect to `p`, or equivalently that `p` has the right lifting property with respect to `i`. -/ class HasLiftingProperty : Prop where /-- Unique field expressing that any commutative square built from `f` and `g` has a lift -/ sq_hasLift : ∀ {f : A ⟶ X} {g : B ⟶ Y} (sq : CommSq f i p g), sq.HasLift instance (priority := 100) sq_hasLift_of_hasLiftingProperty {f : A ⟶ X} {g : B ⟶ Y} (sq : CommSq f i p g) [hip : HasLiftingProperty i p] : sq.HasLift := by apply hip.sq_hasLift namespace HasLiftingProperty variable {i p} theorem op (h : HasLiftingProperty i p) : HasLiftingProperty p.op i.op := ⟨fun {f} {g} sq => by simp only [CommSq.HasLift.iff_unop, Quiver.Hom.unop_op] infer_instance⟩ theorem unop {A B X Y : Cᵒᵖ} {i : A ⟶ B} {p : X ⟶ Y} (h : HasLiftingProperty i p) : HasLiftingProperty p.unop i.unop := ⟨fun {f} {g} sq => by rw [CommSq.HasLift.iff_op] simp only [Quiver.Hom.op_unop] infer_instance⟩ theorem iff_op : HasLiftingProperty i p ↔ HasLiftingProperty p.op i.op := ⟨op, unop⟩ theorem iff_unop {A B X Y : Cᵒᵖ} (i : A ⟶ B) (p : X ⟶ Y) : HasLiftingProperty i p ↔ HasLiftingProperty p.unop i.unop := ⟨unop, op⟩ variable (i p) instance (priority := 100) of_left_iso [IsIso i] : HasLiftingProperty i p := ⟨fun {f} {g} sq => CommSq.HasLift.mk' { l := inv i ≫ f fac_left := by simp only [IsIso.hom_inv_id_assoc] fac_right := by simp only [sq.w, assoc, IsIso.inv_hom_id_assoc] }⟩ instance (priority := 100) of_right_iso [IsIso p] : HasLiftingProperty i p := ⟨fun {f} {g} sq => CommSq.HasLift.mk' { l := g ≫ inv p fac_left := by simp only [← sq.w_assoc, IsIso.hom_inv_id, comp_id] fac_right := by simp only [assoc, IsIso.inv_hom_id, comp_id] }⟩ instance of_comp_left [HasLiftingProperty i p] [HasLiftingProperty i' p] : HasLiftingProperty (i ≫ i') p := ⟨fun {f} {g} sq => by have fac := sq.w rw [assoc] at fac exact CommSq.HasLift.mk' { l := (CommSq.mk (CommSq.mk fac).fac_right).lift fac_left := by simp only [assoc, CommSq.fac_left] fac_right := by simp only [CommSq.fac_right] }⟩ instance of_comp_right [HasLiftingProperty i p] [HasLiftingProperty i p'] : HasLiftingProperty i (p ≫ p') := ⟨fun {f} {g} sq => by have fac := sq.w rw [← assoc] at fac let _ := (CommSq.mk (CommSq.mk fac).fac_left.symm).lift exact CommSq.HasLift.mk' { l := (CommSq.mk (CommSq.mk fac).fac_left.symm).lift fac_left := by simp only [CommSq.fac_left] fac_right := by simp only [CommSq.fac_right_assoc, CommSq.fac_right] }⟩ theorem of_arrow_iso_left {A B A' B' X Y : C} {i : A ⟶ B} {i' : A' ⟶ B'} (e : Arrow.mk i ≅ Arrow.mk i') (p : X ⟶ Y) [hip : HasLiftingProperty i p] : HasLiftingProperty i' p := by rw [Arrow.iso_w' e] infer_instance theorem of_arrow_iso_right {A B X Y X' Y' : C} (i : A ⟶ B) {p : X ⟶ Y} {p' : X' ⟶ Y'} (e : Arrow.mk p ≅ Arrow.mk p') [hip : HasLiftingProperty i p] : HasLiftingProperty i p' := by rw [Arrow.iso_w' e] infer_instance theorem iff_of_arrow_iso_left {A B A' B' X Y : C} {i : A ⟶ B} {i' : A' ⟶ B'} (e : Arrow.mk i ≅ Arrow.mk i') (p : X ⟶ Y) : HasLiftingProperty i p ↔ HasLiftingProperty i' p := by constructor <;> intro exacts [of_arrow_iso_left e p, of_arrow_iso_left e.symm p] theorem iff_of_arrow_iso_right {A B X Y X' Y' : C} (i : A ⟶ B) {p : X ⟶ Y} {p' : X' ⟶ Y'} (e : Arrow.mk p ≅ Arrow.mk p') : HasLiftingProperty i p ↔ HasLiftingProperty i p' := by constructor <;> intro exacts [of_arrow_iso_right i e, of_arrow_iso_right i e.symm] end HasLiftingProperty end CategoryTheory
CategoryTheory\Limits\Bicones.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Cones import Mathlib.CategoryTheory.FinCategory.Basic /-! # Bicones Given a category `J`, a walking `Bicone J` is a category whose objects are the objects of `J` and two extra vertices `Bicone.left` and `Bicone.right`. The morphisms are the morphisms of `J` and `left ⟶ j`, `right ⟶ j` for each `j : J` such that `(· ⟶ j)` and `(· ⟶ k)` commutes with each `f : j ⟶ k`. Given a diagram `F : J ⥤ C` and two `Cone F`s, we can join them into a diagram `Bicone J ⥤ C` via `biconeMk`. This is used in `CategoryTheory.Functor.Flat`. -/ universe v₁ u₁ noncomputable section open CategoryTheory.Limits open scoped Classical namespace CategoryTheory section Bicone /-- Given a category `J`, construct a walking `Bicone J` by adjoining two elements. -/ inductive Bicone (J : Type u₁) | left : Bicone J | right : Bicone J | diagram (val : J) : Bicone J deriving DecidableEq variable (J : Type u₁) instance : Inhabited (Bicone J) := ⟨Bicone.left⟩ instance finBicone [Fintype J] : Fintype (Bicone J) where elems := [Bicone.left, Bicone.right].toFinset ∪ Finset.image Bicone.diagram Fintype.elems complete j := by cases j <;> simp apply Fintype.complete variable [Category.{v₁} J] /-- The homs for a walking `Bicone J`. -/ inductive BiconeHom : Bicone J → Bicone J → Type max u₁ v₁ | left_id : BiconeHom Bicone.left Bicone.left | right_id : BiconeHom Bicone.right Bicone.right | left (j : J) : BiconeHom Bicone.left (Bicone.diagram j) | right (j : J) : BiconeHom Bicone.right (Bicone.diagram j) | diagram {j k : J} (f : j ⟶ k) : BiconeHom (Bicone.diagram j) (Bicone.diagram k) instance : Inhabited (BiconeHom J Bicone.left Bicone.left) := ⟨BiconeHom.left_id⟩ instance BiconeHom.decidableEq {j k : Bicone J} : DecidableEq (BiconeHom J j k) := fun f g => by cases f <;> cases g <;> simp <;> infer_instance @[simps] instance biconeCategoryStruct : CategoryStruct (Bicone J) where Hom := BiconeHom J id j := Bicone.casesOn j BiconeHom.left_id BiconeHom.right_id fun k => BiconeHom.diagram (𝟙 k) comp f g := by rcases f with (_ | _ | _ | _ | f) · exact g · exact g · cases g apply BiconeHom.left · cases g apply BiconeHom.right · rcases g with (_|_|_|_|g) exact BiconeHom.diagram (f ≫ g) instance biconeCategory : Category (Bicone J) where id_comp f := by cases f <;> simp comp_id f := by cases f <;> simp assoc f g h := by cases f <;> cases g <;> cases h <;> simp end Bicone section SmallCategory variable (J : Type v₁) [SmallCategory J] /-- Given a diagram `F : J ⥤ C` and two `Cone F`s, we can join them into a diagram `Bicone J ⥤ C`. -/ @[simps] def biconeMk {C : Type u₁} [Category.{v₁} C] {F : J ⥤ C} (c₁ c₂ : Cone F) : Bicone J ⥤ C where obj X := Bicone.casesOn X c₁.pt c₂.pt fun j => F.obj j map f := by rcases f with (_|_|_|_|f) · exact 𝟙 _ · exact 𝟙 _ · exact c₁.π.app _ · exact c₂.π.app _ · exact F.map f map_id X := by cases X <;> simp map_comp f g := by rcases f with (_|_|_|_|_) · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm · cases g exact (Category.id_comp _).symm.trans (c₁.π.naturality _) · cases g exact (Category.id_comp _).symm.trans (c₂.π.naturality _) · cases g apply F.map_comp instance finBiconeHom [FinCategory J] (j k : Bicone J) : Fintype (j ⟶ k) := by cases j <;> cases k · exact { elems := {BiconeHom.left_id} complete := fun f => by cases f; simp } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := {BiconeHom.left _} complete := fun f => by cases f; simp } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := {BiconeHom.right_id} complete := fun f => by cases f; simp } · exact { elems := {BiconeHom.right _} complete := fun f => by cases f; simp } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := ∅ complete := fun f => by cases f } · exact { elems := Finset.image BiconeHom.diagram Fintype.elems complete := fun f => by rcases f with (_|_|_|_|f) simp only [Finset.mem_image] use f simpa using Fintype.complete _ } instance biconeSmallCategory : SmallCategory (Bicone J) := CategoryTheory.biconeCategory J instance biconeFinCategory [FinCategory J] : FinCategory (Bicone J) where end SmallCategory end CategoryTheory
CategoryTheory\Limits\ColimitLimit.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Limits.FunctorCategory /-! # The morphism comparing a colimit of limits with the corresponding limit of colimits. For `F : J × K ⥤ C` there is always a morphism $\colim_k \lim_j F(j,k) → \lim_j \colim_k F(j, k)$. While it is not usually an isomorphism, with additional hypotheses on `J` and `K` it may be, in which case we say that "colimits commute with limits". The prototypical example, proved in `CategoryTheory.Limits.FilteredColimitCommutesFiniteLimit`, is that when `C = Type`, filtered colimits commute with finite limits. ## References * Borceux, Handbook of categorical algebra 1, Section 2.13 * [Stacks: Filtered colimits](https://stacks.math.columbia.edu/tag/002W) -/ universe v₁ v₂ v u₁ u₂ u open CategoryTheory namespace CategoryTheory.Limits variable {J : Type u₁} {K : Type u₂} [Category.{v₁} J] [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable (F : J × K ⥤ C) open CategoryTheory.prod theorem map_id_left_eq_curry_map {j : J} {k k' : K} {f : k ⟶ k'} : F.map ((𝟙 j, f) : (j, k) ⟶ (j, k')) = ((curry.obj F).obj j).map f := rfl theorem map_id_right_eq_curry_swap_map {j j' : J} {f : j ⟶ j'} {k : K} : F.map ((f, 𝟙 k) : (j, k) ⟶ (j', k)) = ((curry.obj (Prod.swap K J ⋙ F)).obj k).map f := rfl variable [HasLimitsOfShape J C] variable [HasColimitsOfShape K C] /-- The universal morphism $\colim_k \lim_j F(j,k) → \lim_j \colim_k F(j, k)$. -/ noncomputable def colimitLimitToLimitColimit : colimit (curry.obj (Prod.swap K J ⋙ F) ⋙ lim) ⟶ limit (curry.obj F ⋙ colim) := limit.lift (curry.obj F ⋙ colim) { pt := _ π := { app := fun j => colimit.desc (curry.obj (Prod.swap K J ⋙ F) ⋙ lim) { pt := _ ι := { app := fun k => limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j ≫ colimit.ι ((curry.obj F).obj j) k naturality := by intro k k' f simp only [Functor.comp_obj, lim_obj, colimit.cocone_x, Functor.const_obj_obj, Functor.comp_map, lim_map, curry_obj_obj_obj, Prod.swap_obj, limMap_π_assoc, curry_obj_map_app, Prod.swap_map, Functor.const_obj_map, Category.comp_id] rw [map_id_left_eq_curry_map, colimit.w] } } naturality := by intro j j' f dsimp ext k simp only [Functor.comp_obj, lim_obj, Category.id_comp, colimit.ι_desc, colimit.ι_desc_assoc, Category.assoc, ι_colimMap, curry_obj_obj_obj, curry_obj_map_app] rw [map_id_right_eq_curry_swap_map, limit.w_assoc] } } /-- Since `colimit_limit_to_limit_colimit` is a morphism from a colimit to a limit, this lemma characterises it. -/ @[reassoc (attr := simp)] theorem ι_colimitLimitToLimitColimit_π (j) (k) : colimit.ι _ k ≫ colimitLimitToLimitColimit F ≫ limit.π _ j = limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j ≫ colimit.ι ((curry.obj F).obj j) k := by dsimp [colimitLimitToLimitColimit] simp @[simp] theorem ι_colimitLimitToLimitColimit_π_apply [Small.{v} J] [Small.{v} K] (F : J × K ⥤ Type v) (j : J) (k : K) (f) : limit.π (curry.obj F ⋙ colim) j (colimitLimitToLimitColimit F (colimit.ι (curry.obj (Prod.swap K J ⋙ F) ⋙ lim) k f)) = colimit.ι ((curry.obj F).obj j) k (limit.π ((curry.obj (Prod.swap K J ⋙ F)).obj k) j f) := by dsimp [colimitLimitToLimitColimit] rw [Types.Limit.lift_π_apply] dsimp only rw [Types.Colimit.ι_desc_apply] dsimp /-- The map `colimit_limit_to_limit_colimit` realized as a map of cones. -/ @[simps] noncomputable def colimitLimitToLimitColimitCone (G : J ⥤ K ⥤ C) [HasLimit G] : colim.mapCone (limit.cone G) ⟶ limit.cone (G ⋙ colim) where hom := colim.map (limitIsoSwapCompLim G).hom ≫ colimitLimitToLimitColimit (uncurry.obj G : _) ≫ lim.map (whiskerRight (currying.unitIso.app G).inv colim) w j := by dsimp ext1 k simp only [Category.assoc, limMap_π, Functor.comp_obj, colim_obj, whiskerRight_app, colim_map, ι_colimMap_assoc, lim_obj, limitIsoSwapCompLim_hom_app, ι_colimitLimitToLimitColimit_π_assoc, curry_obj_obj_obj, Prod.swap_obj, uncurry_obj_obj, ι_colimMap, currying_unitIso_inv_app_app_app, Category.id_comp, limMap_π_assoc, Functor.flip_obj_obj, flipIsoCurrySwapUncurry_hom_app_app] erw [limitObjIsoLimitCompEvaluation_hom_π_assoc] end CategoryTheory.Limits
CategoryTheory\Limits\Comma.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Arrow import Mathlib.CategoryTheory.Comma.StructuredArrow import Mathlib.CategoryTheory.Limits.Constructions.EpiMono import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Unit /-! # Limits and colimits in comma categories We build limits in the comma category `Comma L R` provided that the two source categories have limits and `R` preserves them. This is used to construct limits in the arrow category, structured arrow category and under category, and show that the appropriate forgetful functors create limits. The duals of all the above are also given. -/ namespace CategoryTheory open Category Limits universe w' w v₁ v₂ v₃ u₁ u₂ u₃ variable {J : Type w} [Category.{w'} J] variable {A : Type u₁} [Category.{v₁} A] variable {B : Type u₂} [Category.{v₂} B] variable {T : Type u₃} [Category.{v₃} T] namespace Comma variable {L : A ⥤ T} {R : B ⥤ T} variable (F : J ⥤ Comma L R) /-- (Implementation). An auxiliary cone which is useful in order to construct limits in the comma category. -/ @[simps!] def limitAuxiliaryCone (c₁ : Cone (F ⋙ fst L R)) : Cone ((F ⋙ snd L R) ⋙ R) := (Cones.postcompose (whiskerLeft F (Comma.natTrans L R) : _)).obj (L.mapCone c₁) /-- If `R` preserves the appropriate limit, then given a cone for `F ⋙ fst L R : J ⥤ L` and a limit cone for `F ⋙ snd L R : J ⥤ R` we can build a cone for `F` which will turn out to be a limit cone. -/ @[simps] def coneOfPreserves [PreservesLimit (F ⋙ snd L R) R] (c₁ : Cone (F ⋙ fst L R)) {c₂ : Cone (F ⋙ snd L R)} (t₂ : IsLimit c₂) : Cone F where pt := { left := c₁.pt right := c₂.pt hom := (isLimitOfPreserves R t₂).lift (limitAuxiliaryCone _ c₁) } π := { app := fun j => { left := c₁.π.app j right := c₂.π.app j w := ((isLimitOfPreserves R t₂).fac (limitAuxiliaryCone F c₁) j).symm } naturality := fun j₁ j₂ t => by ext · simp [← c₁.w t] · simp [← c₂.w t] } /-- Provided that `R` preserves the appropriate limit, then the cone in `coneOfPreserves` is a limit. -/ def coneOfPreservesIsLimit [PreservesLimit (F ⋙ snd L R) R] {c₁ : Cone (F ⋙ fst L R)} (t₁ : IsLimit c₁) {c₂ : Cone (F ⋙ snd L R)} (t₂ : IsLimit c₂) : IsLimit (coneOfPreserves F c₁ t₂) where lift s := { left := t₁.lift ((fst L R).mapCone s) right := t₂.lift ((snd L R).mapCone s) w := (isLimitOfPreserves R t₂).hom_ext fun j => by rw [coneOfPreserves_pt_hom, assoc, assoc, (isLimitOfPreserves R t₂).fac, limitAuxiliaryCone_π_app, ← L.map_comp_assoc, t₁.fac, R.mapCone_π_app, ← R.map_comp, t₂.fac] exact (s.π.app j).w } uniq s m w := by apply CommaMorphism.ext · exact t₁.uniq ((fst L R).mapCone s) _ (fun j => by simp [← w]) · exact t₂.uniq ((snd L R).mapCone s) _ (fun j => by simp [← w]) /-- (Implementation). An auxiliary cocone which is useful in order to construct colimits in the comma category. -/ @[simps!] def colimitAuxiliaryCocone (c₂ : Cocone (F ⋙ snd L R)) : Cocone ((F ⋙ fst L R) ⋙ L) := (Cocones.precompose (whiskerLeft F (Comma.natTrans L R) : _)).obj (R.mapCocone c₂) /-- If `L` preserves the appropriate colimit, then given a colimit cocone for `F ⋙ fst L R : J ⥤ L` and a cocone for `F ⋙ snd L R : J ⥤ R` we can build a cocone for `F` which will turn out to be a colimit cocone. -/ @[simps] def coconeOfPreserves [PreservesColimit (F ⋙ fst L R) L] {c₁ : Cocone (F ⋙ fst L R)} (t₁ : IsColimit c₁) (c₂ : Cocone (F ⋙ snd L R)) : Cocone F where pt := { left := c₁.pt right := c₂.pt hom := (isColimitOfPreserves L t₁).desc (colimitAuxiliaryCocone _ c₂) } ι := { app := fun j => { left := c₁.ι.app j right := c₂.ι.app j w := (isColimitOfPreserves L t₁).fac (colimitAuxiliaryCocone _ c₂) j } naturality := fun j₁ j₂ t => by ext · simp [← c₁.w t] · simp [← c₂.w t] } /-- Provided that `L` preserves the appropriate colimit, then the cocone in `coconeOfPreserves` is a colimit. -/ def coconeOfPreservesIsColimit [PreservesColimit (F ⋙ fst L R) L] {c₁ : Cocone (F ⋙ fst L R)} (t₁ : IsColimit c₁) {c₂ : Cocone (F ⋙ snd L R)} (t₂ : IsColimit c₂) : IsColimit (coconeOfPreserves F t₁ c₂) where desc s := { left := t₁.desc ((fst L R).mapCocone s) right := t₂.desc ((snd L R).mapCocone s) w := (isColimitOfPreserves L t₁).hom_ext fun j => by rw [coconeOfPreserves_pt_hom, (isColimitOfPreserves L t₁).fac_assoc, colimitAuxiliaryCocone_ι_app, assoc, ← R.map_comp, t₂.fac, L.mapCocone_ι_app, ← L.map_comp_assoc, t₁.fac] exact (s.ι.app j).w } uniq s m w := by apply CommaMorphism.ext · exact t₁.uniq ((fst L R).mapCocone s) _ (fun j => by simp [← w]) · exact t₂.uniq ((snd L R).mapCocone s) _ (fun j => by simp [← w]) instance hasLimit (F : J ⥤ Comma L R) [HasLimit (F ⋙ fst L R)] [HasLimit (F ⋙ snd L R)] [PreservesLimit (F ⋙ snd L R) R] : HasLimit F := HasLimit.mk ⟨_, coneOfPreservesIsLimit _ (limit.isLimit _) (limit.isLimit _)⟩ instance hasLimitsOfShape [HasLimitsOfShape J A] [HasLimitsOfShape J B] [PreservesLimitsOfShape J R] : HasLimitsOfShape J (Comma L R) where instance hasLimitsOfSize [HasLimitsOfSize.{w, w'} A] [HasLimitsOfSize.{w, w'} B] [PreservesLimitsOfSize.{w, w'} R] : HasLimitsOfSize.{w, w'} (Comma L R) := ⟨fun _ _ => inferInstance⟩ instance hasColimit (F : J ⥤ Comma L R) [HasColimit (F ⋙ fst L R)] [HasColimit (F ⋙ snd L R)] [PreservesColimit (F ⋙ fst L R) L] : HasColimit F := HasColimit.mk ⟨_, coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _)⟩ instance hasColimitsOfShape [HasColimitsOfShape J A] [HasColimitsOfShape J B] [PreservesColimitsOfShape J L] : HasColimitsOfShape J (Comma L R) where instance hasColimitsOfSize [HasColimitsOfSize.{w, w'} A] [HasColimitsOfSize.{w, w'} B] [PreservesColimitsOfSize.{w, w'} L] : HasColimitsOfSize.{w, w'} (Comma L R) := ⟨fun _ _ => inferInstance⟩ end Comma namespace Arrow instance hasLimit (F : J ⥤ Arrow T) [i₁ : HasLimit (F ⋙ leftFunc)] [i₂ : HasLimit (F ⋙ rightFunc)] : HasLimit F := by haveI : HasLimit (F ⋙ Comma.fst _ _) := i₁ haveI : HasLimit (F ⋙ Comma.snd _ _) := i₂ apply Comma.hasLimit instance hasLimitsOfShape [HasLimitsOfShape J T] : HasLimitsOfShape J (Arrow T) where instance hasLimits [HasLimits T] : HasLimits (Arrow T) := ⟨fun _ _ => inferInstance⟩ instance hasColimit (F : J ⥤ Arrow T) [i₁ : HasColimit (F ⋙ leftFunc)] [i₂ : HasColimit (F ⋙ rightFunc)] : HasColimit F := by haveI : HasColimit (F ⋙ Comma.fst _ _) := i₁ haveI : HasColimit (F ⋙ Comma.snd _ _) := i₂ apply Comma.hasColimit instance hasColimitsOfShape [HasColimitsOfShape J T] : HasColimitsOfShape J (Arrow T) where instance hasColimits [HasColimits T] : HasColimits (Arrow T) := ⟨fun _ _ => inferInstance⟩ end Arrow namespace StructuredArrow variable {X : T} {G : A ⥤ T} (F : J ⥤ StructuredArrow X G) instance hasLimit [i₁ : HasLimit (F ⋙ proj X G)] [i₂ : PreservesLimit (F ⋙ proj X G) G] : HasLimit F := by haveI : HasLimit (F ⋙ Comma.snd (Functor.fromPUnit X) G) := i₁ haveI : PreservesLimit (F ⋙ Comma.snd (Functor.fromPUnit X) G) _ := i₂ apply Comma.hasLimit instance hasLimitsOfShape [HasLimitsOfShape J A] [PreservesLimitsOfShape J G] : HasLimitsOfShape J (StructuredArrow X G) where instance hasLimitsOfSize [HasLimitsOfSize.{w, w'} A] [PreservesLimitsOfSize.{w, w'} G] : HasLimitsOfSize.{w, w'} (StructuredArrow X G) := ⟨fun J hJ => by infer_instance⟩ noncomputable instance createsLimit [i : PreservesLimit (F ⋙ proj X G) G] : CreatesLimit F (proj X G) := letI : PreservesLimit (F ⋙ Comma.snd (Functor.fromPUnit X) G) G := i createsLimitOfReflectsIso fun _ t => { liftedCone := Comma.coneOfPreserves F punitCone t makesLimit := Comma.coneOfPreservesIsLimit _ punitConeIsLimit _ validLift := Cones.ext (Iso.refl _) fun _ => (id_comp _).symm } noncomputable instance createsLimitsOfShape [PreservesLimitsOfShape J G] : CreatesLimitsOfShape J (proj X G) where noncomputable instance createsLimitsOfSize [PreservesLimitsOfSize.{w, w'} G] : CreatesLimitsOfSize.{w, w'} (proj X G : _) where instance mono_right_of_mono [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G] {Y Z : StructuredArrow X G} (f : Y ⟶ Z) [Mono f] : Mono f.right := show Mono ((proj X G).map f) from inferInstance theorem mono_iff_mono_right [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G] {Y Z : StructuredArrow X G} (f : Y ⟶ Z) : Mono f ↔ Mono f.right := ⟨fun _ => inferInstance, fun _ => mono_of_mono_right f⟩ end StructuredArrow namespace CostructuredArrow variable {G : A ⥤ T} {X : T} (F : J ⥤ CostructuredArrow G X) instance hasColimit [i₁ : HasColimit (F ⋙ proj G X)] [i₂ : PreservesColimit (F ⋙ proj G X) G] : HasColimit F := by haveI : HasColimit (F ⋙ Comma.fst G (Functor.fromPUnit X)) := i₁ haveI : PreservesColimit (F ⋙ Comma.fst G (Functor.fromPUnit X)) _ := i₂ apply Comma.hasColimit instance hasColimitsOfShape [HasColimitsOfShape J A] [PreservesColimitsOfShape J G] : HasColimitsOfShape J (CostructuredArrow G X) where instance hasColimitsOfSize [HasColimitsOfSize.{w, w'} A] [PreservesColimitsOfSize.{w, w'} G] : HasColimitsOfSize.{w, w'} (CostructuredArrow G X) := ⟨fun _ _ => inferInstance⟩ noncomputable instance createsColimit [i : PreservesColimit (F ⋙ proj G X) G] : CreatesColimit F (proj G X) := letI : PreservesColimit (F ⋙ Comma.fst G (Functor.fromPUnit X)) G := i createsColimitOfReflectsIso fun _ t => { liftedCocone := Comma.coconeOfPreserves F t punitCocone makesColimit := Comma.coconeOfPreservesIsColimit _ _ punitCoconeIsColimit validLift := Cocones.ext (Iso.refl _) fun _ => comp_id _ } noncomputable instance createsColimitsOfShape [PreservesColimitsOfShape J G] : CreatesColimitsOfShape J (proj G X) where noncomputable instance createsColimitsOfSize [PreservesColimitsOfSize.{w, w'} G] : CreatesColimitsOfSize.{w, w'} (proj G X : _) where instance epi_left_of_epi [HasPushouts A] [PreservesColimitsOfShape WalkingSpan G] {Y Z : CostructuredArrow G X} (f : Y ⟶ Z) [Epi f] : Epi f.left := show Epi ((proj G X).map f) from inferInstance theorem epi_iff_epi_left [HasPushouts A] [PreservesColimitsOfShape WalkingSpan G] {Y Z : CostructuredArrow G X} (f : Y ⟶ Z) : Epi f ↔ Epi f.left := ⟨fun _ => inferInstance, fun _ => epi_of_epi_left f⟩ end CostructuredArrow end CategoryTheory
CategoryTheory\Limits\ConeCategory.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Adjunction.Comma import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.Equivalence /-! # Limits and the category of (co)cones This files contains results that stem from the limit API. For the definition and the category instance of `Cone`, please refer to `CategoryTheory/Limits/Cones.lean`. ## Main results * The category of cones on `F : J ⥤ C` is equivalent to the category `CostructuredArrow (const J) F`. * A cone is limiting iff it is terminal in the category of cones. As a corollary, an equivalence of categories of cones preserves limiting properties. -/ namespace CategoryTheory.Limits open CategoryTheory CategoryTheory.Functor universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] {D : Type u₄} [Category.{v₄} D] /-- Given a cone `c` over `F`, we can interpret the legs of `c` as structured arrows `c.pt ⟶ F.obj -`. -/ @[simps] def Cone.toStructuredArrow {F : J ⥤ C} (c : Cone F) : J ⥤ StructuredArrow c.pt F where obj j := StructuredArrow.mk (c.π.app j) map f := StructuredArrow.homMk f /-- If `F` has a limit, then the limit projections can be interpreted as structured arrows `limit F ⟶ F.obj -`. -/ @[simps] noncomputable def limit.toStructuredArrow (F : J ⥤ C) [HasLimit F] : J ⥤ StructuredArrow (limit F) F where obj j := StructuredArrow.mk (limit.π F j) map f := StructuredArrow.homMk f /-- `Cone.toStructuredArrow` can be expressed in terms of `Functor.toStructuredArrow`. -/ def Cone.toStructuredArrowIsoToStructuredArrow {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ≅ (𝟭 J).toStructuredArrow c.pt F c.π.app (by simp) := Iso.refl _ /-- `Functor.toStructuredArrow` can be expressed in terms of `Cone.toStructuredArrow`. -/ def _root_.CategoryTheory.Functor.toStructuredArrowIsoToStructuredArrow (G : J ⥤ K) (X : C) (F : K ⥤ C) (f : (Y : J) → X ⟶ F.obj (G.obj Y)) (h : ∀ {Y Z : J} (g : Y ⟶ Z), f Y ≫ F.map (G.map g) = f Z) : G.toStructuredArrow X F f h ≅ (Cone.mk X ⟨f, by simp [h]⟩).toStructuredArrow ⋙ StructuredArrow.pre _ _ _ := Iso.refl _ /-- Interpreting the legs of a cone as a structured arrow and then forgetting the arrow again does nothing. -/ @[simps!] def Cone.toStructuredArrowCompProj {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.proj _ _ ≅ 𝟭 J := Iso.refl _ @[simp] lemma Cone.toStructuredArrow_comp_proj {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.proj _ _ = 𝟭 J := rfl /-- Interpreting the legs of a cone as a structured arrow, interpreting this arrow as an arrow over the cone point, and finally forgetting the arrow is the same as just applying the functor the cone was over. -/ @[simps!] def Cone.toStructuredArrowCompToUnderCompForget {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.toUnder _ _ ⋙ Under.forget _ ≅ F := Iso.refl _ @[simp] lemma Cone.toStructuredArrow_comp_toUnder_comp_forget {F : J ⥤ C} (c : Cone F) : c.toStructuredArrow ⋙ StructuredArrow.toUnder _ _ ⋙ Under.forget _ = F := rfl /-- A cone `c` on `F : J ⥤ C` lifts to a cone in `Over c.pt` with cone point `𝟙 c.pt`. -/ @[simps] def Cone.toUnder {F : J ⥤ C} (c : Cone F) : Cone (c.toStructuredArrow ⋙ StructuredArrow.toUnder _ _) where pt := Under.mk (𝟙 c.pt) π := { app := fun j => Under.homMk (c.π.app j) (by simp) } /-- The limit cone for `F : J ⥤ C` lifts to a cocone in `Under (limit F)` with cone point `𝟙 (limit F)`. This is automatically also a limit cone. -/ noncomputable def limit.toUnder (F : J ⥤ C) [HasLimit F] : Cone (limit.toStructuredArrow F ⋙ StructuredArrow.toUnder _ _) where pt := Under.mk (𝟙 (limit F)) π := { app := fun j => Under.homMk (limit.π F j) (by simp) } /-- `c.toUnder` is a lift of `c` under the forgetful functor. -/ @[simps!] def Cone.mapConeToUnder {F : J ⥤ C} (c : Cone F) : (Under.forget c.pt).mapCone c.toUnder ≅ c := Iso.refl _ /-- Given a diagram of `StructuredArrow X F`s, we may obtain a cone with cone point `X`. -/ @[simps!] def Cone.fromStructuredArrow (F : C ⥤ D) {X : D} (G : J ⥤ StructuredArrow X F) : Cone (G ⋙ StructuredArrow.proj X F ⋙ F) where π := { app := fun j => (G.obj j).hom } /-- Given a cone `c : Cone K` and a map `f : X ⟶ F.obj c.X`, we can construct a cone of structured arrows over `X` with `f` as the cone point. -/ @[simps] def Cone.toStructuredArrowCone {K : J ⥤ C} (c : Cone K) (F : C ⥤ D) {X : D} (f : X ⟶ F.obj c.pt) : Cone ((F.mapCone c).toStructuredArrow ⋙ StructuredArrow.map f ⋙ StructuredArrow.pre _ K F) where pt := StructuredArrow.mk f π := { app := fun j => StructuredArrow.homMk (c.π.app j) rfl } /-- Construct an object of the category `(Δ ↓ F)` from a cone on `F`. This is part of an equivalence, see `Cone.equivCostructuredArrow`. -/ @[simps] def Cone.toCostructuredArrow (F : J ⥤ C) : Cone F ⥤ CostructuredArrow (const J) F where obj c := CostructuredArrow.mk c.π map f := CostructuredArrow.homMk f.hom /-- Construct a cone on `F` from an object of the category `(Δ ↓ F)`. This is part of an equivalence, see `Cone.equivCostructuredArrow`. -/ @[simps] def Cone.fromCostructuredArrow (F : J ⥤ C) : CostructuredArrow (const J) F ⥤ Cone F where obj c := ⟨c.left, c.hom⟩ map f := { hom := f.left w := fun j => by convert congr_fun (congr_arg NatTrans.app f.w) j dsimp simp } /- Porting note: `simps!` alone generated lemmas of the form `_ = _` where `_` are proofs of some proposition. This caused the simpNF linter to complain. We therefore explicitly tell simps! to avoid applying projections for `PLift` and `ULift`. Similarly for `Cocone.equivStructuredArrow`. -/ /-- The category of cones on `F` is just the comma category `(Δ ↓ F)`, where `Δ` is the constant functor. -/ @[simps! (config := { notRecursive := [`PLift, `ULift] })] def Cone.equivCostructuredArrow (F : J ⥤ C) : Cone F ≌ CostructuredArrow (const J) F := Equivalence.mk (Cone.toCostructuredArrow F) (Cone.fromCostructuredArrow F) (NatIso.ofComponents Cones.eta) (NatIso.ofComponents fun c => (CostructuredArrow.eta _).symm) /-- A cone is a limit cone iff it is terminal. -/ def Cone.isLimitEquivIsTerminal {F : J ⥤ C} (c : Cone F) : IsLimit c ≃ IsTerminal c := IsLimit.isoUniqueConeMorphism.toEquiv.trans { toFun := fun h => IsTerminal.ofUnique _ invFun := fun h s => ⟨⟨IsTerminal.from h s⟩, fun a => IsTerminal.hom_ext h a _⟩ left_inv := by aesop_cat right_inv := by aesop_cat } theorem hasLimit_iff_hasTerminal_cone (F : J ⥤ C) : HasLimit F ↔ HasTerminal (Cone F) := ⟨fun _ => (Cone.isLimitEquivIsTerminal _ (limit.isLimit F)).hasTerminal, fun h => haveI : HasTerminal (Cone F) := h ⟨⟨⟨⊤_ _, (Cone.isLimitEquivIsTerminal _).symm terminalIsTerminal⟩⟩⟩⟩ theorem hasLimitsOfShape_iff_isLeftAdjoint_const : HasLimitsOfShape J C ↔ IsLeftAdjoint (const J : C ⥤ _) := calc HasLimitsOfShape J C ↔ ∀ F : J ⥤ C, HasLimit F := ⟨fun h => h.has_limit, fun h => HasLimitsOfShape.mk⟩ _ ↔ ∀ F : J ⥤ C, HasTerminal (Cone F) := forall_congr' hasLimit_iff_hasTerminal_cone _ ↔ ∀ F : J ⥤ C, HasTerminal (CostructuredArrow (const J) F) := (forall_congr' fun F => (Cone.equivCostructuredArrow F).hasTerminal_iff) _ ↔ (IsLeftAdjoint (const J : C ⥤ _)) := isLeftAdjoint_iff_hasTerminal_costructuredArrow.symm theorem IsLimit.liftConeMorphism_eq_isTerminal_from {F : J ⥤ C} {c : Cone F} (hc : IsLimit c) (s : Cone F) : hc.liftConeMorphism s = IsTerminal.from (Cone.isLimitEquivIsTerminal _ hc) _ := rfl theorem IsTerminal.from_eq_liftConeMorphism {F : J ⥤ C} {c : Cone F} (hc : IsTerminal c) (s : Cone F) : IsTerminal.from hc s = ((Cone.isLimitEquivIsTerminal _).symm hc).liftConeMorphism s := (IsLimit.liftConeMorphism_eq_isTerminal_from (c.isLimitEquivIsTerminal.symm hc) s).symm /-- If `G : Cone F ⥤ Cone F'` preserves terminal objects, it preserves limit cones. -/ def IsLimit.ofPreservesConeTerminal {F : J ⥤ C} {F' : K ⥤ D} (G : Cone F ⥤ Cone F') [PreservesLimit (Functor.empty.{0} _) G] {c : Cone F} (hc : IsLimit c) : IsLimit (G.obj c) := (Cone.isLimitEquivIsTerminal _).symm <| (Cone.isLimitEquivIsTerminal _ hc).isTerminalObj _ _ /-- If `G : Cone F ⥤ Cone F'` reflects terminal objects, it reflects limit cones. -/ def IsLimit.ofReflectsConeTerminal {F : J ⥤ C} {F' : K ⥤ D} (G : Cone F ⥤ Cone F') [ReflectsLimit (Functor.empty.{0} _) G] {c : Cone F} (hc : IsLimit (G.obj c)) : IsLimit c := (Cone.isLimitEquivIsTerminal _).symm <| (Cone.isLimitEquivIsTerminal _ hc).isTerminalOfObj _ _ /-- Given a cocone `c` over `F`, we can interpret the legs of `c` as costructured arrows `F.obj - ⟶ c.pt`. -/ @[simps] def Cocone.toCostructuredArrow {F : J ⥤ C} (c : Cocone F) : J ⥤ CostructuredArrow F c.pt where obj j := CostructuredArrow.mk (c.ι.app j) map f := CostructuredArrow.homMk f /-- If `F` has a colimit, then the colimit inclusions can be interpreted as costructured arrows `F.obj - ⟶ colimit F`. -/ @[simps] noncomputable def colimit.toCostructuredArrow (F : J ⥤ C) [HasColimit F] : J ⥤ CostructuredArrow F (colimit F) where obj j := CostructuredArrow.mk (colimit.ι F j) map f := CostructuredArrow.homMk f /-- `Cocone.toCostructuredArrow` can be expressed in terms of `Functor.toCostructuredArrow`. -/ def Cocone.toCostructuredArrowIsoToCostructuredArrow {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ≅ (𝟭 J).toCostructuredArrow F c.pt c.ι.app (by simp) := Iso.refl _ /-- `Functor.toCostructuredArrow` can be expressed in terms of `Cocone.toCostructuredArrow`. -/ def _root_.CategoryTheory.Functor.toCostructuredArrowIsoToCostructuredArrow (G : J ⥤ K) (F : K ⥤ C) (X : C) (f : (Y : J) → F.obj (G.obj Y) ⟶ X) (h : ∀ {Y Z : J} (g : Y ⟶ Z), F.map (G.map g) ≫ f Z = f Y) : G.toCostructuredArrow F X f h ≅ (Cocone.mk X ⟨f, by simp [h]⟩).toCostructuredArrow ⋙ CostructuredArrow.pre _ _ _ := Iso.refl _ /-- Interpreting the legs of a cocone as a costructured arrow and then forgetting the arrow again does nothing. -/ @[simps!] def Cocone.toCostructuredArrowCompProj {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.proj _ _ ≅ 𝟭 J := Iso.refl _ @[simp] lemma Cocone.toCostructuredArrow_comp_proj {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.proj _ _ = 𝟭 J := rfl /-- Interpreting the legs of a cocone as a costructured arrow, interpreting this arrow as an arrow over the cocone point, and finally forgetting the arrow is the same as just applying the functor the cocone was over. -/ @[simps!] def Cocone.toCostructuredArrowCompToOverCompForget {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.toOver _ _ ⋙ Over.forget _ ≅ F := Iso.refl _ @[simp] lemma Cocone.toCostructuredArrow_comp_toOver_comp_forget {F : J ⥤ C} (c : Cocone F) : c.toCostructuredArrow ⋙ CostructuredArrow.toOver _ _ ⋙ Over.forget _ = F := rfl /-- A cocone `c` on `F : J ⥤ C` lifts to a cocone in `Over c.pt` with cone point `𝟙 c.pt`. -/ @[simps] def Cocone.toOver {F : J ⥤ C} (c : Cocone F) : Cocone (c.toCostructuredArrow ⋙ CostructuredArrow.toOver _ _) where pt := Over.mk (𝟙 c.pt) ι := { app := fun j => Over.homMk (c.ι.app j) (by simp) } /-- The colimit cocone for `F : J ⥤ C` lifts to a cocone in `Over (colimit F)` with cone point `𝟙 (colimit F)`. This is automatically also a colimit cocone. -/ @[simps] noncomputable def colimit.toOver (F : J ⥤ C) [HasColimit F] : Cocone (colimit.toCostructuredArrow F ⋙ CostructuredArrow.toOver _ _) where pt := Over.mk (𝟙 (colimit F)) ι := { app := fun j => Over.homMk (colimit.ι F j) (by simp) } /-- `c.toOver` is a lift of `c` under the forgetful functor. -/ @[simps!] def Cocone.mapCoconeToOver {F : J ⥤ C} (c : Cocone F) : (Over.forget c.pt).mapCocone c.toOver ≅ c := Iso.refl _ /-- Given a diagram `CostructuredArrow F X`s, we may obtain a cocone with cone point `X`. -/ @[simps!] def Cocone.fromCostructuredArrow (F : C ⥤ D) {X : D} (G : J ⥤ CostructuredArrow F X) : Cocone (G ⋙ CostructuredArrow.proj F X ⋙ F) where ι := { app := fun j => (G.obj j).hom } /-- Given a cocone `c : Cocone K` and a map `f : F.obj c.X ⟶ X`, we can construct a cocone of costructured arrows over `X` with `f` as the cone point. -/ @[simps] def Cocone.toCostructuredArrowCocone {K : J ⥤ C} (c : Cocone K) (F : C ⥤ D) {X : D} (f : F.obj c.pt ⟶ X) : Cocone ((F.mapCocone c).toCostructuredArrow ⋙ CostructuredArrow.map f ⋙ CostructuredArrow.pre _ _ _) where pt := CostructuredArrow.mk f ι := { app := fun j => CostructuredArrow.homMk (c.ι.app j) rfl } /-- Construct an object of the category `(F ↓ Δ)` from a cocone on `F`. This is part of an equivalence, see `Cocone.equivStructuredArrow`. -/ @[simps] def Cocone.toStructuredArrow (F : J ⥤ C) : Cocone F ⥤ StructuredArrow F (const J) where obj c := StructuredArrow.mk c.ι map f := StructuredArrow.homMk f.hom /-- Construct a cocone on `F` from an object of the category `(F ↓ Δ)`. This is part of an equivalence, see `Cocone.equivStructuredArrow`. -/ @[simps] def Cocone.fromStructuredArrow (F : J ⥤ C) : StructuredArrow F (const J) ⥤ Cocone F where obj c := ⟨c.right, c.hom⟩ map f := { hom := f.right w := fun j => by convert (congr_fun (congr_arg NatTrans.app f.w) j).symm dsimp simp } /-- The category of cocones on `F` is just the comma category `(F ↓ Δ)`, where `Δ` is the constant functor. -/ @[simps! (config := { notRecursive := [`PLift, `ULift] })] def Cocone.equivStructuredArrow (F : J ⥤ C) : Cocone F ≌ StructuredArrow F (const J) := Equivalence.mk (Cocone.toStructuredArrow F) (Cocone.fromStructuredArrow F) (NatIso.ofComponents Cocones.eta) (NatIso.ofComponents fun c => (StructuredArrow.eta _).symm) /-- A cocone is a colimit cocone iff it is initial. -/ def Cocone.isColimitEquivIsInitial {F : J ⥤ C} (c : Cocone F) : IsColimit c ≃ IsInitial c := IsColimit.isoUniqueCoconeMorphism.toEquiv.trans { toFun := fun h => IsInitial.ofUnique _ invFun := fun h s => ⟨⟨IsInitial.to h s⟩, fun a => IsInitial.hom_ext h a _⟩ left_inv := by aesop_cat right_inv := by aesop_cat } theorem hasColimit_iff_hasInitial_cocone (F : J ⥤ C) : HasColimit F ↔ HasInitial (Cocone F) := ⟨fun _ => (Cocone.isColimitEquivIsInitial _ (colimit.isColimit F)).hasInitial, fun h => haveI : HasInitial (Cocone F) := h ⟨⟨⟨⊥_ _, (Cocone.isColimitEquivIsInitial _).symm initialIsInitial⟩⟩⟩⟩ theorem hasColimitsOfShape_iff_isRightAdjoint_const : HasColimitsOfShape J C ↔ IsRightAdjoint (const J : C ⥤ _) := calc HasColimitsOfShape J C ↔ ∀ F : J ⥤ C, HasColimit F := ⟨fun h => h.has_colimit, fun h => HasColimitsOfShape.mk⟩ _ ↔ ∀ F : J ⥤ C, HasInitial (Cocone F) := forall_congr' hasColimit_iff_hasInitial_cocone _ ↔ ∀ F : J ⥤ C, HasInitial (StructuredArrow F (const J)) := (forall_congr' fun F => (Cocone.equivStructuredArrow F).hasInitial_iff) _ ↔ (IsRightAdjoint (const J : C ⥤ _)) := isRightAdjoint_iff_hasInitial_structuredArrow.symm theorem IsColimit.descCoconeMorphism_eq_isInitial_to {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (s : Cocone F) : hc.descCoconeMorphism s = IsInitial.to (Cocone.isColimitEquivIsInitial _ hc) _ := rfl theorem IsInitial.to_eq_descCoconeMorphism {F : J ⥤ C} {c : Cocone F} (hc : IsInitial c) (s : Cocone F) : IsInitial.to hc s = ((Cocone.isColimitEquivIsInitial _).symm hc).descCoconeMorphism s := (IsColimit.descCoconeMorphism_eq_isInitial_to (c.isColimitEquivIsInitial.symm hc) s).symm /-- If `G : Cocone F ⥤ Cocone F'` preserves initial objects, it preserves colimit cocones. -/ def IsColimit.ofPreservesCoconeInitial {F : J ⥤ C} {F' : K ⥤ D} (G : Cocone F ⥤ Cocone F') [PreservesColimit (Functor.empty.{0} _) G] {c : Cocone F} (hc : IsColimit c) : IsColimit (G.obj c) := (Cocone.isColimitEquivIsInitial _).symm <| (Cocone.isColimitEquivIsInitial _ hc).isInitialObj _ _ /-- If `G : Cocone F ⥤ Cocone F'` reflects initial objects, it reflects colimit cocones. -/ def IsColimit.ofReflectsCoconeInitial {F : J ⥤ C} {F' : K ⥤ D} (G : Cocone F ⥤ Cocone F') [ReflectsColimit (Functor.empty.{0} _) G] {c : Cocone F} (hc : IsColimit (G.obj c)) : IsColimit c := (Cocone.isColimitEquivIsInitial _).symm <| (Cocone.isColimitEquivIsInitial _ hc).isInitialOfObj _ _ end CategoryTheory.Limits
CategoryTheory\Limits\Cones.lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Functor.Const import Mathlib.CategoryTheory.DiscreteCategory import Mathlib.CategoryTheory.Yoneda import Mathlib.CategoryTheory.Functor.ReflectsIso /-! # Cones and cocones We define `Cone F`, a cone over a functor `F`, and `F.cones : Cᵒᵖ ⥤ Type`, the functor associating to `X` the cones over `F` with cone point `X`. A cone `c` is defined by specifying its cone point `c.pt` and a natural transformation `c.π` from the constant `c.pt` valued functor to `F`. We provide `c.w f : c.π.app j ≫ F.map f = c.π.app j'` for any `f : j ⟶ j'` as a wrapper for `c.π.naturality f` avoiding unneeded identity morphisms. We define `c.extend f`, where `c : cone F` and `f : Y ⟶ c.pt` for some other `Y`, which replaces the cone point by `Y` and inserts `f` into each of the components of the cone. Similarly we have `c.whisker F` producing a `Cone (E ⋙ F)` We define morphisms of cones, and the category of cones. We define `Cone.postcompose α : cone F ⥤ cone G` for `α` a natural transformation `F ⟶ G`. And, of course, we dualise all this to cocones as well. For more results about the category of cones, see `cone_category.lean`. -/ -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ open CategoryTheory variable {J : Type u₁} [Category.{v₁} J] variable {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] variable {D : Type u₄} [Category.{v₄} D] open CategoryTheory open CategoryTheory.Category open CategoryTheory.Functor open Opposite namespace CategoryTheory namespace Functor variable (F : J ⥤ C) /-- If `F : J ⥤ C` then `F.cones` is the functor assigning to an object `X : C` the type of natural transformations from the constant functor with value `X` to `F`. An object representing this functor is a limit of `F`. -/ @[simps!] def cones : Cᵒᵖ ⥤ Type max u₁ v₃ := (const J).op ⋙ yoneda.obj F /-- If `F : J ⥤ C` then `F.cocones` is the functor assigning to an object `(X : C)` the type of natural transformations from `F` to the constant functor with value `X`. An object corepresenting this functor is a colimit of `F`. -/ @[simps!] def cocones : C ⥤ Type max u₁ v₃ := const J ⋙ coyoneda.obj (op F) end Functor section variable (J C) /-- Functorially associated to each functor `J ⥤ C`, we have the `C`-presheaf consisting of cones with a given cone point. -/ @[simps!] def cones : (J ⥤ C) ⥤ Cᵒᵖ ⥤ Type max u₁ v₃ where obj := Functor.cones map f := whiskerLeft (const J).op (yoneda.map f) /-- Contravariantly associated to each functor `J ⥤ C`, we have the `C`-copresheaf consisting of cocones with a given cocone point. -/ @[simps!] def cocones : (J ⥤ C)ᵒᵖ ⥤ C ⥤ Type max u₁ v₃ where obj F := Functor.cocones (unop F) map f := whiskerLeft (const J) (coyoneda.map f) end namespace Limits section /-- A `c : Cone F` is: * an object `c.pt` and * a natural transformation `c.π : c.pt ⟶ F` from the constant `c.pt` functor to `F`. Example: if `J` is a category coming from a poset then the data required to make a term of type `Cone F` is morphisms `πⱼ : c.pt ⟶ F j` for all `j : J` and, for all `i ≤ j` in `J`, morphisms `πᵢⱼ : F i ⟶ F j` such that `πᵢ ≫ πᵢⱼ = πᵢ`. `Cone F` is equivalent, via `cone.equiv` below, to `Σ X, F.cones.obj X`. -/ structure Cone (F : J ⥤ C) where /-- An object of `C` -/ pt : C /-- A natural transformation from the constant functor at `X` to `F` -/ π : (const J).obj pt ⟶ F instance inhabitedCone (F : Discrete PUnit ⥤ C) : Inhabited (Cone F) := ⟨{ pt := F.obj ⟨⟨⟩⟩ π := { app := fun ⟨⟨⟩⟩ => 𝟙 _ naturality := by intro X Y f match X, Y, f with | .mk A, .mk B, .up g => aesop_cat } }⟩ @[reassoc (attr := simp)] theorem Cone.w {F : J ⥤ C} (c : Cone F) {j j' : J} (f : j ⟶ j') : c.π.app j ≫ F.map f = c.π.app j' := by rw [← c.π.naturality f] apply id_comp /-- A `c : Cocone F` is * an object `c.pt` and * a natural transformation `c.ι : F ⟶ c.pt` from `F` to the constant `c.pt` functor. For example, if the source `J` of `F` is a partially ordered set, then to give `c : Cocone F` is to give a collection of morphisms `ιⱼ : F j ⟶ c.pt` and, for all `j ≤ k` in `J`, morphisms `ιⱼₖ : F j ⟶ F k` such that `Fⱼₖ ≫ Fₖ = Fⱼ` for all `j ≤ k`. `Cocone F` is equivalent, via `Cone.equiv` below, to `Σ X, F.cocones.obj X`. -/ structure Cocone (F : J ⥤ C) where /-- An object of `C` -/ pt : C /-- A natural transformation from `F` to the constant functor at `pt` -/ ι : F ⟶ (const J).obj pt instance inhabitedCocone (F : Discrete PUnit ⥤ C) : Inhabited (Cocone F) := ⟨{ pt := F.obj ⟨⟨⟩⟩ ι := { app := fun ⟨⟨⟩⟩ => 𝟙 _ naturality := by intro X Y f match X, Y, f with | .mk A, .mk B, .up g => aesop_cat } }⟩ @[reassoc] -- @[simp] -- Porting note (#10618): simp can prove this theorem Cocone.w {F : J ⥤ C} (c : Cocone F) {j j' : J} (f : j ⟶ j') : F.map f ≫ c.ι.app j' = c.ι.app j := by rw [c.ι.naturality f] apply comp_id attribute [simp 1001] Cocone.w_assoc end variable {F : J ⥤ C} namespace Cone /-- The isomorphism between a cone on `F` and an element of the functor `F.cones`. -/ @[simps!] def equiv (F : J ⥤ C) : Cone F ≅ ΣX, F.cones.obj X where hom c := ⟨op c.pt, c.π⟩ inv c := { pt := c.1.unop π := c.2 } hom_inv_id := by funext X cases X rfl inv_hom_id := by funext X cases X rfl /-- A map to the vertex of a cone naturally induces a cone by composition. -/ @[simps] def extensions (c : Cone F) : yoneda.obj c.pt ⋙ uliftFunctor.{u₁} ⟶ F.cones where app X f := (const J).map f.down ≫ c.π /-- A map to the vertex of a cone induces a cone by composition. -/ @[simps] def extend (c : Cone F) {X : C} (f : X ⟶ c.pt) : Cone F := { pt := X π := c.extensions.app (op X) ⟨f⟩ } /-- Whisker a cone by precomposition of a functor. -/ @[simps] def whisker (E : K ⥤ J) (c : Cone F) : Cone (E ⋙ F) where pt := c.pt π := whiskerLeft E c.π end Cone namespace Cocone /-- The isomorphism between a cocone on `F` and an element of the functor `F.cocones`. -/ def equiv (F : J ⥤ C) : Cocone F ≅ ΣX, F.cocones.obj X where hom c := ⟨c.pt, c.ι⟩ inv c := { pt := c.1 ι := c.2 } hom_inv_id := by funext X cases X rfl inv_hom_id := by funext X cases X rfl /-- A map from the vertex of a cocone naturally induces a cocone by composition. -/ @[simps] def extensions (c : Cocone F) : coyoneda.obj (op c.pt) ⋙ uliftFunctor.{u₁} ⟶ F.cocones where app X f := c.ι ≫ (const J).map f.down /-- A map from the vertex of a cocone induces a cocone by composition. -/ @[simps] def extend (c : Cocone F) {Y : C} (f : c.pt ⟶ Y) : Cocone F where pt := Y ι := c.extensions.app Y ⟨f⟩ /-- Whisker a cocone by precomposition of a functor. See `whiskering` for a functorial version. -/ @[simps] def whisker (E : K ⥤ J) (c : Cocone F) : Cocone (E ⋙ F) where pt := c.pt ι := whiskerLeft E c.ι end Cocone /-- A cone morphism between two cones for the same diagram is a morphism of the cone points which commutes with the cone legs. -/ structure ConeMorphism (A B : Cone F) where /-- A morphism between the two vertex objects of the cones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ w : ∀ j : J, hom ≫ B.π.app j = A.π.app j := by aesop_cat attribute [reassoc (attr := simp)] ConeMorphism.w instance inhabitedConeMorphism (A : Cone F) : Inhabited (ConeMorphism A A) := ⟨{ hom := 𝟙 _ }⟩ /-- The category of cones on a given diagram. -/ @[simps] instance Cone.category : Category (Cone F) where Hom A B := ConeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the hom field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem ConeMorphism.ext {c c' : Cone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Cones /-- To give an isomorphism between cones, it suffices to give an isomorphism between their vertices which commutes with the cone maps. -/ -- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Cone F} (φ : c.pt ≅ c'.pt) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv w := fun j => φ.inv_comp_eq.mpr (w j) } /-- Eta rule for cones. -/ @[simps!] def eta (c : Cone F) : c ≅ ⟨c.pt, c.π⟩ := Cones.ext (Iso.refl _) /-- Given a cone morphism whose object part is an isomorphism, produce an isomorphism of cones. -/ theorem cone_iso_of_hom_iso {K : J ⥤ C} {c d : Cone K} (f : c ⟶ d) [i : IsIso f.hom] : IsIso f := ⟨⟨{ hom := inv f.hom w := fun j => (asIso f.hom).inv_comp_eq.2 (f.w j).symm }, by aesop_cat⟩⟩ /-- There is a morphism from an extended cone to the original cone. -/ @[simps] def extend (s : Cone F) {X : C} (f : X ⟶ s.pt) : s.extend f ⟶ s where hom := f /-- Extending a cone by the identity does nothing. -/ @[simps!] def extendId (s : Cone F) : s.extend (𝟙 s.pt) ≅ s := Cones.ext (Iso.refl _) /-- Extending a cone by a composition is the same as extending the cone twice. -/ @[simps!] def extendComp (s : Cone F) {X Y : C} (f : X ⟶ Y) (g : Y ⟶ s.pt) : s.extend (f ≫ g) ≅ (s.extend g).extend f := Cones.ext (Iso.refl _) /-- A cone extended by an isomorphism is isomorphic to the original cone. -/ @[simps] def extendIso (s : Cone F) {X : C} (f : X ≅ s.pt) : s.extend f.hom ≅ s where hom := { hom := f.hom } inv := { hom := f.inv } instance {s : Cone F} {X : C} (f : X ⟶ s.pt) [IsIso f] : IsIso (Cones.extend s f) := ⟨(extendIso s (asIso f)).inv, by aesop_cat⟩ /-- Functorially postcompose a cone for `F` by a natural transformation `F ⟶ G` to give a cone for `G`. -/ @[simps] def postcompose {G : J ⥤ C} (α : F ⟶ G) : Cone F ⥤ Cone G where obj c := { pt := c.pt π := c.π ≫ α } map f := { hom := f.hom } /-- Postcomposing a cone by the composite natural transformation `α ≫ β` is the same as postcomposing by `α` and then by `β`. -/ @[simps!] def postcomposeComp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) : postcompose (α ≫ β) ≅ postcompose α ⋙ postcompose β := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- Postcomposing by the identity does not change the cone up to isomorphism. -/ @[simps!] def postcomposeId : postcompose (𝟙 F) ≅ 𝟭 (Cone F) := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- If `F` and `G` are naturally isomorphic functors, then they have equivalent categories of cones. -/ @[simps] def postcomposeEquivalence {G : J ⥤ C} (α : F ≅ G) : Cone F ≌ Cone G where functor := postcompose α.hom inverse := postcompose α.inv unitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- Whiskering on the left by `E : K ⥤ J` gives a functor from `Cone F` to `Cone (E ⋙ F)`. -/ @[simps] def whiskering (E : K ⥤ J) : Cone F ⥤ Cone (E ⋙ F) where obj c := c.whisker E map f := { hom := f.hom } /-- Whiskering by an equivalence gives an equivalence between categories of cones. -/ @[simps] def whiskeringEquivalence (e : K ≌ J) : Cone F ≌ Cone (e.functor ⋙ F) where functor := whiskering e.functor inverse := whiskering e.inverse ⋙ postcompose (e.invFunIdAssoc F).hom unitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) (by intro k simpa [e.counit_app_functor] using s.w (e.unitInv.app k)) /-- The categories of cones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic (possibly after changing the indexing category by an equivalence). -/ @[simps! functor inverse unitIso counitIso] def equivalenceOfReindexing {G : K ⥤ C} (e : K ≌ J) (α : e.functor ⋙ F ≅ G) : Cone F ≌ Cone G := (whiskeringEquivalence e).trans (postcomposeEquivalence α) section variable (F) /-- Forget the cone structure and obtain just the cone point. -/ @[simps] def forget : Cone F ⥤ C where obj t := t.pt map f := f.hom variable (G : C ⥤ D) /-- A functor `G : C ⥤ D` sends cones over `F` to cones over `F ⋙ G` functorially. -/ @[simps] def functoriality : Cone F ⥤ Cone (F ⋙ G) where obj A := { pt := G.obj A.pt π := { app := fun j => G.map (A.π.app j) naturality := by intros; erw [← G.map_comp]; aesop_cat } } map f := { hom := G.map f.hom w := fun j => by simp [-ConeMorphism.w, ← f.w j] } instance functoriality_full [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom w := fun j => G.map_injective (by simpa using t.w j) }, by aesop_cat⟩ instance functoriality_faithful [G.Faithful] : (Cones.functoriality F G).Faithful where map_injective {_X} {_Y} f g h := ConeMorphism.ext f g <| G.map_injective <| congr_arg ConeMorphism.hom h /-- If `e : C ≌ D` is an equivalence of categories, then `functoriality F e.functor` induces an equivalence between cones over `F` and cones over `F ⋙ e.functor`. -/ @[simps] def functorialityEquivalence (e : C ≌ D) : Cone F ≌ Cone (F ⋙ e.functor) := let f : (F ⋙ e.functor) ⋙ e.inverse ≅ F := Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e.unitIso.symm ≪≫ Functor.rightUnitor _ { functor := functoriality F e.functor inverse := functoriality (F ⋙ e.functor) e.inverse ⋙ (postcomposeEquivalence f).functor unitIso := NatIso.ofComponents fun c => Cones.ext (e.unitIso.app _) counitIso := NatIso.ofComponents fun c => Cones.ext (e.counitIso.app _) } /-- If `F` reflects isomorphisms, then `Cones.functoriality F` reflects isomorphisms as well. -/ instance reflects_cone_isomorphism (F : C ⥤ D) [F.ReflectsIsomorphisms] (K : J ⥤ C) : (Cones.functoriality K F).ReflectsIsomorphisms := by constructor intro A B f _ haveI : IsIso (F.map f.hom) := (Cones.forget (K ⋙ F)).map_isIso ((Cones.functoriality K F).map f) haveI := ReflectsIsomorphisms.reflects F f.hom apply cone_iso_of_hom_iso end end Cones /-- A cocone morphism between two cocones for the same diagram is a morphism of the cocone points which commutes with the cocone legs. -/ structure CoconeMorphism (A B : Cocone F) where /-- A morphism between the (co)vertex objects in `C` -/ hom : A.pt ⟶ B.pt /-- The triangle made from the two natural transformations and `hom` commutes -/ w : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j := by aesop_cat instance inhabitedCoconeMorphism (A : Cocone F) : Inhabited (CoconeMorphism A A) := ⟨{ hom := 𝟙 _ }⟩ attribute [reassoc (attr := simp)] CoconeMorphism.w @[simps] instance Cocone.category : Category (Cocone F) where Hom A B := CoconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the hom field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem CoconeMorphism.ext {c c' : Cocone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Cocones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ -- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Cocone F} (φ : c.pt ≅ c'.pt) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv w := fun j => φ.comp_inv_eq.mpr (w j).symm } /-- Eta rule for cocones. -/ @[simps!] def eta (c : Cocone F) : c ≅ ⟨c.pt, c.ι⟩ := Cocones.ext (Iso.refl _) /-- Given a cocone morphism whose object part is an isomorphism, produce an isomorphism of cocones. -/ theorem cocone_iso_of_hom_iso {K : J ⥤ C} {c d : Cocone K} (f : c ⟶ d) [i : IsIso f.hom] : IsIso f := ⟨⟨{ hom := inv f.hom w := fun j => (asIso f.hom).comp_inv_eq.2 (f.w j).symm }, by aesop_cat⟩⟩ /-- There is a morphism from a cocone to its extension. -/ @[simps] def extend (s : Cocone F) {X : C} (f : s.pt ⟶ X) : s ⟶ s.extend f where hom := f /-- Extending a cocone by the identity does nothing. -/ @[simps!] def extendId (s : Cocone F) : s ≅ s.extend (𝟙 s.pt) := Cocones.ext (Iso.refl _) /-- Extending a cocone by a composition is the same as extending the cone twice. -/ @[simps!] def extendComp (s : Cocone F) {X Y : C} (f : s.pt ⟶ X) (g : X ⟶ Y) : s.extend (f ≫ g) ≅ (s.extend f).extend g := Cocones.ext (Iso.refl _) /-- A cocone extended by an isomorphism is isomorphic to the original cone. -/ @[simps] def extendIso (s : Cocone F) {X : C} (f : s.pt ≅ X) : s ≅ s.extend f.hom where hom := { hom := f.hom } inv := { hom := f.inv } instance {s : Cocone F} {X : C} (f : s.pt ⟶ X) [IsIso f] : IsIso (Cocones.extend s f) := ⟨(extendIso s (asIso f)).inv, by aesop_cat⟩ /-- Functorially precompose a cocone for `F` by a natural transformation `G ⟶ F` to give a cocone for `G`. -/ @[simps] def precompose {G : J ⥤ C} (α : G ⟶ F) : Cocone F ⥤ Cocone G where obj c := { pt := c.pt ι := α ≫ c.ι } map f := { hom := f.hom } /-- Precomposing a cocone by the composite natural transformation `α ≫ β` is the same as precomposing by `β` and then by `α`. -/ def precomposeComp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) : precompose (α ≫ β) ≅ precompose β ⋙ precompose α := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) /-- Precomposing by the identity does not change the cocone up to isomorphism. -/ def precomposeId : precompose (𝟙 F) ≅ 𝟭 (Cocone F) := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) /-- If `F` and `G` are naturally isomorphic functors, then they have equivalent categories of cocones. -/ @[simps] def precomposeEquivalence {G : J ⥤ C} (α : G ≅ F) : Cocone F ≌ Cocone G where functor := precompose α.hom inverse := precompose α.inv unitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) /-- Whiskering on the left by `E : K ⥤ J` gives a functor from `Cocone F` to `Cocone (E ⋙ F)`. -/ @[simps] def whiskering (E : K ⥤ J) : Cocone F ⥤ Cocone (E ⋙ F) where obj c := c.whisker E map f := { hom := f.hom } /-- Whiskering by an equivalence gives an equivalence between categories of cones. -/ @[simps] def whiskeringEquivalence (e : K ≌ J) : Cocone F ≌ Cocone (e.functor ⋙ F) where functor := whiskering e.functor inverse := whiskering e.inverse ⋙ precompose ((Functor.leftUnitor F).inv ≫ whiskerRight e.counitIso.inv F ≫ (Functor.associator _ _ _).inv) unitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) fun k => by simpa [e.counitInv_app_functor k] using s.w (e.unit.app k) /-- The categories of cocones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic (possibly after changing the indexing category by an equivalence). -/ @[simps! functor_obj] def equivalenceOfReindexing {G : K ⥤ C} (e : K ≌ J) (α : e.functor ⋙ F ≅ G) : Cocone F ≌ Cocone G := (whiskeringEquivalence e).trans (precomposeEquivalence α.symm) section variable (F) /-- Forget the cocone structure and obtain just the cocone point. -/ @[simps] def forget : Cocone F ⥤ C where obj t := t.pt map f := f.hom variable (G : C ⥤ D) /-- A functor `G : C ⥤ D` sends cocones over `F` to cocones over `F ⋙ G` functorially. -/ @[simps] def functoriality : Cocone F ⥤ Cocone (F ⋙ G) where obj A := { pt := G.obj A.pt ι := { app := fun j => G.map (A.ι.app j) naturality := by intros; erw [← G.map_comp]; aesop_cat } } map f := { hom := G.map f.hom w := by intros; rw [← Functor.map_comp, CoconeMorphism.w] } instance functoriality_full [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom w := fun j => G.map_injective (by simpa using t.w j) }, by aesop_cat⟩ instance functoriality_faithful [G.Faithful] : (functoriality F G).Faithful where map_injective {_X} {_Y} f g h := CoconeMorphism.ext f g <| G.map_injective <| congr_arg CoconeMorphism.hom h /-- If `e : C ≌ D` is an equivalence of categories, then `functoriality F e.functor` induces an equivalence between cocones over `F` and cocones over `F ⋙ e.functor`. -/ @[simps] def functorialityEquivalence (e : C ≌ D) : Cocone F ≌ Cocone (F ⋙ e.functor) := let f : (F ⋙ e.functor) ⋙ e.inverse ≅ F := Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e.unitIso.symm ≪≫ Functor.rightUnitor _ { functor := functoriality F e.functor inverse := functoriality (F ⋙ e.functor) e.inverse ⋙ (precomposeEquivalence f.symm).functor unitIso := NatIso.ofComponents fun c => Cocones.ext (e.unitIso.app _) counitIso := NatIso.ofComponents fun c => Cocones.ext (e.counitIso.app _) } /-- If `F` reflects isomorphisms, then `Cocones.functoriality F` reflects isomorphisms as well. -/ instance reflects_cocone_isomorphism (F : C ⥤ D) [F.ReflectsIsomorphisms] (K : J ⥤ C) : (Cocones.functoriality K F).ReflectsIsomorphisms := by constructor intro A B f _ haveI : IsIso (F.map f.hom) := (Cocones.forget (K ⋙ F)).map_isIso ((Cocones.functoriality K F).map f) haveI := ReflectsIsomorphisms.reflects F f.hom apply cocone_iso_of_hom_iso end end Cocones end Limits namespace Functor variable (H : C ⥤ D) {F : J ⥤ C} {G : J ⥤ C} open CategoryTheory.Limits /-- The image of a cone in C under a functor G : C ⥤ D is a cone in D. -/ @[simps!] def mapCone (c : Cone F) : Cone (F ⋙ H) := (Cones.functoriality F H).obj c /-- The image of a cocone in C under a functor G : C ⥤ D is a cocone in D. -/ @[simps!] def mapCocone (c : Cocone F) : Cocone (F ⋙ H) := (Cocones.functoriality F H).obj c /-- Given a cone morphism `c ⟶ c'`, construct a cone morphism on the mapped cones functorially. -/ def mapConeMorphism {c c' : Cone F} (f : c ⟶ c') : H.mapCone c ⟶ H.mapCone c' := (Cones.functoriality F H).map f /-- Given a cocone morphism `c ⟶ c'`, construct a cocone morphism on the mapped cocones functorially. -/ def mapCoconeMorphism {c c' : Cocone F} (f : c ⟶ c') : H.mapCocone c ⟶ H.mapCocone c' := (Cocones.functoriality F H).map f /-- If `H` is an equivalence, we invert `H.mapCone` and get a cone for `F` from a cone for `F ⋙ H`. -/ noncomputable def mapConeInv [IsEquivalence H] (c : Cone (F ⋙ H)) : Cone F := (Limits.Cones.functorialityEquivalence F (asEquivalence H)).inverse.obj c /-- `mapCone` is the left inverse to `mapConeInv`. -/ noncomputable def mapConeMapConeInv {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cone (F ⋙ H)) : mapCone H (mapConeInv H c) ≅ c := (Limits.Cones.functorialityEquivalence F (asEquivalence H)).counitIso.app c /-- `MapCone` is the right inverse to `mapConeInv`. -/ noncomputable def mapConeInvMapCone {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cone F) : mapConeInv H (mapCone H c) ≅ c := (Limits.Cones.functorialityEquivalence F (asEquivalence H)).unitIso.symm.app c /-- If `H` is an equivalence, we invert `H.mapCone` and get a cone for `F` from a cone for `F ⋙ H`. -/ noncomputable def mapCoconeInv [IsEquivalence H] (c : Cocone (F ⋙ H)) : Cocone F := (Limits.Cocones.functorialityEquivalence F (asEquivalence H)).inverse.obj c /-- `mapCocone` is the left inverse to `mapCoconeInv`. -/ noncomputable def mapCoconeMapCoconeInv {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cocone (F ⋙ H)) : mapCocone H (mapCoconeInv H c) ≅ c := (Limits.Cocones.functorialityEquivalence F (asEquivalence H)).counitIso.app c /-- `mapCocone` is the right inverse to `mapCoconeInv`. -/ noncomputable def mapCoconeInvMapCocone {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cocone F) : mapCoconeInv H (mapCocone H c) ≅ c := (Limits.Cocones.functorialityEquivalence F (asEquivalence H)).unitIso.symm.app c /-- `functoriality F _ ⋙ postcompose (whisker_left F _)` simplifies to `functoriality F _`. -/ @[simps!] def functorialityCompPostcompose {H H' : C ⥤ D} (α : H ≅ H') : Cones.functoriality F H ⋙ Cones.postcompose (whiskerLeft F α.hom) ≅ Cones.functoriality F H' := NatIso.ofComponents fun c => Cones.ext (α.app _) /-- For `F : J ⥤ C`, given a cone `c : Cone F`, and a natural isomorphism `α : H ≅ H'` for functors `H H' : C ⥤ D`, the postcomposition of the cone `H.mapCone` using the isomorphism `α` is isomorphic to the cone `H'.mapCone`. -/ @[simps!] def postcomposeWhiskerLeftMapCone {H H' : C ⥤ D} (α : H ≅ H') (c : Cone F) : (Cones.postcompose (whiskerLeft F α.hom : _)).obj (mapCone H c) ≅ mapCone H' c := (functorialityCompPostcompose α).app c /-- `mapCone` commutes with `postcompose`. In particular, for `F : J ⥤ C`, given a cone `c : Cone F`, a natural transformation `α : F ⟶ G` and a functor `H : C ⥤ D`, we have two obvious ways of producing a cone over `G ⋙ H`, and they are both isomorphic. -/ @[simps!] def mapConePostcompose {α : F ⟶ G} {c} : mapCone H ((Cones.postcompose α).obj c) ≅ (Cones.postcompose (whiskerRight α H : _)).obj (mapCone H c) := Cones.ext (Iso.refl _) /-- `mapCone` commutes with `postcomposeEquivalence` -/ @[simps!] def mapConePostcomposeEquivalenceFunctor {α : F ≅ G} {c} : mapCone H ((Cones.postcomposeEquivalence α).functor.obj c) ≅ (Cones.postcomposeEquivalence (isoWhiskerRight α H : _)).functor.obj (mapCone H c) := Cones.ext (Iso.refl _) /-- `functoriality F _ ⋙ precompose (whiskerLeft F _)` simplifies to `functoriality F _`. -/ @[simps!] def functorialityCompPrecompose {H H' : C ⥤ D} (α : H ≅ H') : Cocones.functoriality F H ⋙ Cocones.precompose (whiskerLeft F α.inv) ≅ Cocones.functoriality F H' := NatIso.ofComponents fun c => Cocones.ext (α.app _) /-- For `F : J ⥤ C`, given a cocone `c : Cocone F`, and a natural isomorphism `α : H ≅ H'` for functors `H H' : C ⥤ D`, the precomposition of the cocone `H.mapCocone` using the isomorphism `α` is isomorphic to the cocone `H'.mapCocone`. -/ @[simps!] def precomposeWhiskerLeftMapCocone {H H' : C ⥤ D} (α : H ≅ H') (c : Cocone F) : (Cocones.precompose (whiskerLeft F α.inv : _)).obj (mapCocone H c) ≅ mapCocone H' c := (functorialityCompPrecompose α).app c /-- `map_cocone` commutes with `precompose`. In particular, for `F : J ⥤ C`, given a cocone `c : Cocone F`, a natural transformation `α : F ⟶ G` and a functor `H : C ⥤ D`, we have two obvious ways of producing a cocone over `G ⋙ H`, and they are both isomorphic. -/ @[simps!] def mapCoconePrecompose {α : F ⟶ G} {c} : mapCocone H ((Cocones.precompose α).obj c) ≅ (Cocones.precompose (whiskerRight α H : _)).obj (mapCocone H c) := Cocones.ext (Iso.refl _) /-- `mapCocone` commutes with `precomposeEquivalence` -/ @[simps!] def mapCoconePrecomposeEquivalenceFunctor {α : F ≅ G} {c} : mapCocone H ((Cocones.precomposeEquivalence α).functor.obj c) ≅ (Cocones.precomposeEquivalence (isoWhiskerRight α H : _)).functor.obj (mapCocone H c) := Cocones.ext (Iso.refl _) /-- `mapCone` commutes with `whisker` -/ @[simps!] def mapConeWhisker {E : K ⥤ J} {c : Cone F} : mapCone H (c.whisker E) ≅ (mapCone H c).whisker E := Cones.ext (Iso.refl _) /-- `mapCocone` commutes with `whisker` -/ @[simps!] def mapCoconeWhisker {E : K ⥤ J} {c : Cocone F} : mapCocone H (c.whisker E) ≅ (mapCocone H c).whisker E := Cocones.ext (Iso.refl _) end Functor end CategoryTheory namespace CategoryTheory.Limits section variable {F : J ⥤ C} /-- Change a `Cocone F` into a `Cone F.op`. -/ @[simps] def Cocone.op (c : Cocone F) : Cone F.op where pt := Opposite.op c.pt π := NatTrans.op c.ι /-- Change a `Cone F` into a `Cocone F.op`. -/ @[simps] def Cone.op (c : Cone F) : Cocone F.op where pt := Opposite.op c.pt ι := NatTrans.op c.π /-- Change a `Cocone F.op` into a `Cone F`. -/ @[simps] def Cocone.unop (c : Cocone F.op) : Cone F where pt := Opposite.unop c.pt π := NatTrans.removeOp c.ι /-- Change a `Cone F.op` into a `Cocone F`. -/ @[simps] def Cone.unop (c : Cone F.op) : Cocone F where pt := Opposite.unop c.pt ι := NatTrans.removeOp c.π variable (F) /-- The category of cocones on `F` is equivalent to the opposite category of the category of cones on the opposite of `F`. -/ def coconeEquivalenceOpConeOp : Cocone F ≌ (Cone F.op)ᵒᵖ where functor := { obj := fun c => op (Cocone.op c) map := fun {X} {Y} f => Quiver.Hom.op { hom := f.hom.op w := fun j => by apply Quiver.Hom.unop_inj dsimp apply CoconeMorphism.w } } inverse := { obj := fun c => Cone.unop (unop c) map := fun {X} {Y} f => { hom := f.unop.hom.unop w := fun j => by apply Quiver.Hom.op_inj dsimp apply ConeMorphism.w } } unitIso := NatIso.ofComponents (fun c => Cocones.ext (Iso.refl _)) counitIso := NatIso.ofComponents (fun c => by induction c apply Iso.op exact Cones.ext (Iso.refl _)) fun {X} {Y} f => Quiver.Hom.unop_inj (ConeMorphism.ext _ _ (by simp)) functor_unitIso_comp c := by apply Quiver.Hom.unop_inj apply ConeMorphism.ext dsimp apply comp_id attribute [simps] coconeEquivalenceOpConeOp end section variable {F : J ⥤ Cᵒᵖ} /-- Change a cocone on `F.leftOp : Jᵒᵖ ⥤ C` to a cocone on `F : J ⥤ Cᵒᵖ`. -/ @[simps!] def coneOfCoconeLeftOp (c : Cocone F.leftOp) : Cone F where pt := op c.pt π := NatTrans.removeLeftOp c.ι /-- Change a cone on `F : J ⥤ Cᵒᵖ` to a cocone on `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps!] def coconeLeftOpOfCone (c : Cone F) : Cocone F.leftOp where pt := unop c.pt ι := NatTrans.leftOp c.π /- When trying use `@[simps]` to generate the `ι_app` field of this definition, `@[simps]` tries to reduce the RHS using `expr.dsimp` and `expr.simp`, but for some reason the expression is not being simplified properly. -/ /-- Change a cone on `F.leftOp : Jᵒᵖ ⥤ C` to a cocone on `F : J ⥤ Cᵒᵖ`. -/ @[simps pt] def coconeOfConeLeftOp (c : Cone F.leftOp) : Cocone F where pt := op c.pt ι := NatTrans.removeLeftOp c.π @[simp] theorem coconeOfConeLeftOp_ι_app (c : Cone F.leftOp) (j) : (coconeOfConeLeftOp c).ι.app j = (c.π.app (op j)).op := by dsimp only [coconeOfConeLeftOp] simp /-- Change a cocone on `F : J ⥤ Cᵒᵖ` to a cone on `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps!] def coneLeftOpOfCocone (c : Cocone F) : Cone F.leftOp where pt := unop c.pt π := NatTrans.leftOp c.ι end section variable {F : Jᵒᵖ ⥤ C} /-- Change a cocone on `F.rightOp : J ⥤ Cᵒᵖ` to a cone on `F : Jᵒᵖ ⥤ C`. -/ @[simps] def coneOfCoconeRightOp (c : Cocone F.rightOp) : Cone F where pt := unop c.pt π := NatTrans.removeRightOp c.ι /-- Change a cone on `F : Jᵒᵖ ⥤ C` to a cocone on `F.rightOp : Jᵒᵖ ⥤ C`. -/ @[simps] def coconeRightOpOfCone (c : Cone F) : Cocone F.rightOp where pt := op c.pt ι := NatTrans.rightOp c.π /-- Change a cone on `F.rightOp : J ⥤ Cᵒᵖ` to a cocone on `F : Jᵒᵖ ⥤ C`. -/ @[simps] def coconeOfConeRightOp (c : Cone F.rightOp) : Cocone F where pt := unop c.pt ι := NatTrans.removeRightOp c.π /-- Change a cocone on `F : Jᵒᵖ ⥤ C` to a cone on `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def coneRightOpOfCocone (c : Cocone F) : Cone F.rightOp where pt := op c.pt π := NatTrans.rightOp c.ι end section variable {F : Jᵒᵖ ⥤ Cᵒᵖ} /-- Change a cocone on `F.unop : J ⥤ C` into a cone on `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def coneOfCoconeUnop (c : Cocone F.unop) : Cone F where pt := op c.pt π := NatTrans.removeUnop c.ι /-- Change a cone on `F : Jᵒᵖ ⥤ Cᵒᵖ` into a cocone on `F.unop : J ⥤ C`. -/ @[simps] def coconeUnopOfCone (c : Cone F) : Cocone F.unop where pt := unop c.pt ι := NatTrans.unop c.π /-- Change a cone on `F.unop : J ⥤ C` into a cocone on `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def coconeOfConeUnop (c : Cone F.unop) : Cocone F where pt := op c.pt ι := NatTrans.removeUnop c.π /-- Change a cocone on `F : Jᵒᵖ ⥤ Cᵒᵖ` into a cone on `F.unop : J ⥤ C`. -/ @[simps] def coneUnopOfCocone (c : Cocone F) : Cone F.unop where pt := unop c.pt π := NatTrans.unop c.ι end end CategoryTheory.Limits namespace CategoryTheory.Functor open CategoryTheory.Limits variable {F : J ⥤ C} section variable (G : C ⥤ D) /-- The opposite cocone of the image of a cone is the image of the opposite cocone. -/ -- Porting note: removed @[simps (config := { rhsMd := semireducible })] and replaced with @[simps!] def mapConeOp (t : Cone F) : (mapCone G t).op ≅ mapCocone G.op t.op := Cocones.ext (Iso.refl _) /-- The opposite cone of the image of a cocone is the image of the opposite cone. -/ -- Porting note: removed @[simps (config := { rhsMd := semireducible })] and replaced with @[simps!] def mapCoconeOp {t : Cocone F} : (mapCocone G t).op ≅ mapCone G.op t.op := Cones.ext (Iso.refl _) end end CategoryTheory.Functor
CategoryTheory\Limits\Connected.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Connected limits A connected limit is a limit whose shape is a connected category. We give examples of connected categories, and prove that the functor given by `(X × -)` preserves any connected limit. That is, any limit of shape `J` where `J` is a connected category is preserved by the functor `(X × -)`. -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits namespace CategoryTheory section Examples instance widePullbackShape_connected (J : Type v₁) : IsConnected (WidePullbackShape J) := by apply IsConnected.of_induct · introv hp t cases j · exact hp · rwa [t (WidePullbackShape.Hom.term _)] instance widePushoutShape_connected (J : Type v₁) : IsConnected (WidePushoutShape J) := by apply IsConnected.of_induct · introv hp t cases j · exact hp · rwa [← t (WidePushoutShape.Hom.init _)] instance parallelPairInhabited : Inhabited WalkingParallelPair := ⟨WalkingParallelPair.one⟩ instance parallel_pair_connected : IsConnected WalkingParallelPair := by apply IsConnected.of_induct · introv _ t cases j · rwa [t WalkingParallelPairHom.left] · assumption end Examples variable {C : Type u₂} [Category.{v₂} C] variable [HasBinaryProducts C] variable {J : Type v₂} [SmallCategory J] namespace ProdPreservesConnectedLimits /-- (Impl). The obvious natural transformation from (X × K -) to K. -/ @[simps] def γ₂ {K : J ⥤ C} (X : C) : K ⋙ prod.functor.obj X ⟶ K where app Y := Limits.prod.snd /-- (Impl). The obvious natural transformation from (X × K -) to X -/ @[simps] def γ₁ {K : J ⥤ C} (X : C) : K ⋙ prod.functor.obj X ⟶ (Functor.const J).obj X where app Y := Limits.prod.fst /-- (Impl). Given a cone for (X × K -), produce a cone for K using the natural transformation `γ₂` -/ @[simps] def forgetCone {X : C} {K : J ⥤ C} (s : Cone (K ⋙ prod.functor.obj X)) : Cone K where pt := s.pt π := s.π ≫ γ₂ X end ProdPreservesConnectedLimits open ProdPreservesConnectedLimits /-- The functor `(X × -)` preserves any connected limit. Note that this functor does not preserve the two most obvious disconnected limits - that is, `(X × -)` does not preserve products or terminal object, eg `(X ⨯ A) ⨯ (X ⨯ B)` is not isomorphic to `X ⨯ (A ⨯ B)` and `X ⨯ 1` is not isomorphic to `1`. -/ noncomputable def prodPreservesConnectedLimits [IsConnected J] (X : C) : PreservesLimitsOfShape J (prod.functor.obj X) where preservesLimit {K} := { preserves := fun {c} l => { lift := fun s => prod.lift (s.π.app (Classical.arbitrary _) ≫ Limits.prod.fst) (l.lift (forgetCone s)) fac := fun s j => by apply prod.hom_ext · erw [assoc, limMap_π, comp_id, limit.lift_π] exact (nat_trans_from_is_connected (s.π ≫ γ₁ X) j (Classical.arbitrary _)).symm · simp [← l.fac (forgetCone s) j] uniq := fun s m L => by apply prod.hom_ext · erw [limit.lift_π, ← L (Classical.arbitrary J), assoc, limMap_π, comp_id] rfl · rw [limit.lift_π] apply l.uniq (forgetCone s) intro j simp [← L j] } } end CategoryTheory
CategoryTheory\Limits\Creates.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Creating (co)limits We say that `F` creates limits of `K` if, given any limit cone `c` for `K ⋙ F` (i.e. below) we can lift it to a cone "above", and further that `F` reflects limits for `K`. -/ open CategoryTheory CategoryTheory.Limits noncomputable section namespace CategoryTheory universe w' w v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] section Creates variable {D : Type u₂} [Category.{v₂} D] variable {J : Type w} [Category.{w'} J] {K : J ⥤ C} /-- Define the lift of a cone: For a cone `c` for `K ⋙ F`, give a cone for `K` which is a lift of `c`, i.e. the image of it under `F` is (iso) to `c`. We will then use this as part of the definition of creation of limits: every limit cone has a lift. Note this definition is really only useful when `c` is a limit already. -/ structure LiftableCone (K : J ⥤ C) (F : C ⥤ D) (c : Cone (K ⋙ F)) where /-- a cone in the source category of the functor -/ liftedCone : Cone K /-- the isomorphism expressing that `liftedCone` lifts the given cone -/ validLift : F.mapCone liftedCone ≅ c /-- Define the lift of a cocone: For a cocone `c` for `K ⋙ F`, give a cocone for `K` which is a lift of `c`, i.e. the image of it under `F` is (iso) to `c`. We will then use this as part of the definition of creation of colimits: every limit cocone has a lift. Note this definition is really only useful when `c` is a colimit already. -/ structure LiftableCocone (K : J ⥤ C) (F : C ⥤ D) (c : Cocone (K ⋙ F)) where /-- a cocone in the source category of the functor -/ liftedCocone : Cocone K /-- the isomorphism expressing that `liftedCocone` lifts the given cocone -/ validLift : F.mapCocone liftedCocone ≅ c /-- Definition 3.3.1 of [Riehl]. We say that `F` creates limits of `K` if, given any limit cone `c` for `K ⋙ F` (i.e. below) we can lift it to a cone "above", and further that `F` reflects limits for `K`. If `F` reflects isomorphisms, it suffices to show only that the lifted cone is a limit - see `createsLimitOfReflectsIso`. -/ class CreatesLimit (K : J ⥤ C) (F : C ⥤ D) extends ReflectsLimit K F where /-- any limit cone can be lifted to a cone above -/ lifts : ∀ c, IsLimit c → LiftableCone K F c /-- `F` creates limits of shape `J` if `F` creates the limit of any diagram `K : J ⥤ C`. -/ class CreatesLimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where CreatesLimit : ∀ {K : J ⥤ C}, CreatesLimit K F := by infer_instance -- This should be used with explicit universe variables. /-- `F` creates limits if it creates limits of shape `J` for any `J`. -/ @[nolint checkUnivs, pp_with_univ] class CreatesLimitsOfSize (F : C ⥤ D) where CreatesLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesLimitsOfShape J F := by infer_instance /-- `F` creates small limits if it creates limits of shape `J` for any small `J`. -/ abbrev CreatesLimits (F : C ⥤ D) := CreatesLimitsOfSize.{v₂, v₂} F /-- Dual of definition 3.3.1 of [Riehl]. We say that `F` creates colimits of `K` if, given any limit cocone `c` for `K ⋙ F` (i.e. below) we can lift it to a cocone "above", and further that `F` reflects limits for `K`. If `F` reflects isomorphisms, it suffices to show only that the lifted cocone is a limit - see `createsColimitOfReflectsIso`. -/ class CreatesColimit (K : J ⥤ C) (F : C ⥤ D) extends ReflectsColimit K F where /-- any limit cocone can be lifted to a cocone above -/ lifts : ∀ c, IsColimit c → LiftableCocone K F c /-- `F` creates colimits of shape `J` if `F` creates the colimit of any diagram `K : J ⥤ C`. -/ class CreatesColimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where CreatesColimit : ∀ {K : J ⥤ C}, CreatesColimit K F := by infer_instance -- This should be used with explicit universe variables. /-- `F` creates colimits if it creates colimits of shape `J` for any small `J`. -/ @[nolint checkUnivs, pp_with_univ] class CreatesColimitsOfSize (F : C ⥤ D) where CreatesColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesColimitsOfShape J F := by infer_instance /-- `F` creates small colimits if it creates colimits of shape `J` for any small `J`. -/ abbrev CreatesColimits (F : C ⥤ D) := CreatesColimitsOfSize.{v₂, v₂} F -- see Note [lower instance priority] attribute [instance 100] CreatesLimitsOfShape.CreatesLimit CreatesLimitsOfSize.CreatesLimitsOfShape CreatesColimitsOfShape.CreatesColimit CreatesColimitsOfSize.CreatesColimitsOfShape -- see Note [lower instance priority] -- Interface to the `CreatesLimit` class. /-- `liftLimit t` is the cone for `K` given by lifting the limit `t` for `K ⋙ F`. -/ def liftLimit {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) : Cone K := (CreatesLimit.lifts c t).liftedCone /-- The lifted cone has an image isomorphic to the original cone. -/ def liftedLimitMapsToOriginal {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) : F.mapCone (liftLimit t) ≅ c := (CreatesLimit.lifts c t).validLift lemma liftedLimitMapsToOriginal_inv_map_π {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) (j : J) : (liftedLimitMapsToOriginal t).inv.hom ≫ F.map ((liftLimit t).π.app j) = c.π.app j := by rw [show F.map ((liftLimit t).π.app j) = (liftedLimitMapsToOriginal t).hom.hom ≫ c.π.app j from (by simp), ← Category.assoc, ← Cone.category_comp_hom] simp /-- The lifted cone is a limit. -/ def liftedLimitIsLimit {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) : IsLimit (liftLimit t) := ReflectsLimit.reflects (IsLimit.ofIsoLimit t (liftedLimitMapsToOriginal t).symm) /-- If `F` creates the limit of `K` and `K ⋙ F` has a limit, then `K` has a limit. -/ theorem hasLimit_of_created (K : J ⥤ C) (F : C ⥤ D) [HasLimit (K ⋙ F)] [CreatesLimit K F] : HasLimit K := HasLimit.mk { cone := liftLimit (limit.isLimit (K ⋙ F)) isLimit := liftedLimitIsLimit _ } /-- If `F` creates limits of shape `J`, and `D` has limits of shape `J`, then `C` has limits of shape `J`. -/ theorem hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (F : C ⥤ D) [HasLimitsOfShape J D] [CreatesLimitsOfShape J F] : HasLimitsOfShape J C := ⟨fun G => hasLimit_of_created G F⟩ /-- If `F` creates limits, and `D` has all limits, then `C` has all limits. -/ theorem hasLimits_of_hasLimits_createsLimits (F : C ⥤ D) [HasLimitsOfSize.{w, w'} D] [CreatesLimitsOfSize.{w, w'} F] : HasLimitsOfSize.{w, w'} C := ⟨fun _ _ => hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape F⟩ -- Interface to the `CreatesColimit` class. /-- `liftColimit t` is the cocone for `K` given by lifting the colimit `t` for `K ⋙ F`. -/ def liftColimit {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)} (t : IsColimit c) : Cocone K := (CreatesColimit.lifts c t).liftedCocone /-- The lifted cocone has an image isomorphic to the original cocone. -/ def liftedColimitMapsToOriginal {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)} (t : IsColimit c) : F.mapCocone (liftColimit t) ≅ c := (CreatesColimit.lifts c t).validLift /-- The lifted cocone is a colimit. -/ def liftedColimitIsColimit {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)} (t : IsColimit c) : IsColimit (liftColimit t) := ReflectsColimit.reflects (IsColimit.ofIsoColimit t (liftedColimitMapsToOriginal t).symm) /-- If `F` creates the limit of `K` and `K ⋙ F` has a limit, then `K` has a limit. -/ theorem hasColimit_of_created (K : J ⥤ C) (F : C ⥤ D) [HasColimit (K ⋙ F)] [CreatesColimit K F] : HasColimit K := HasColimit.mk { cocone := liftColimit (colimit.isColimit (K ⋙ F)) isColimit := liftedColimitIsColimit _ } /-- If `F` creates colimits of shape `J`, and `D` has colimits of shape `J`, then `C` has colimits of shape `J`. -/ theorem hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape (F : C ⥤ D) [HasColimitsOfShape J D] [CreatesColimitsOfShape J F] : HasColimitsOfShape J C := ⟨fun G => hasColimit_of_created G F⟩ /-- If `F` creates colimits, and `D` has all colimits, then `C` has all colimits. -/ theorem hasColimits_of_hasColimits_createsColimits (F : C ⥤ D) [HasColimitsOfSize.{w, w'} D] [CreatesColimitsOfSize.{w, w'} F] : HasColimitsOfSize.{w, w'} C := ⟨fun _ _ => hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape F⟩ instance (priority := 10) reflectsLimitsOfShapeOfCreatesLimitsOfShape (F : C ⥤ D) [CreatesLimitsOfShape J F] : ReflectsLimitsOfShape J F where instance (priority := 10) reflectsLimitsOfCreatesLimits (F : C ⥤ D) [CreatesLimitsOfSize.{w, w'} F] : ReflectsLimitsOfSize.{w, w'} F where instance (priority := 10) reflectsColimitsOfShapeOfCreatesColimitsOfShape (F : C ⥤ D) [CreatesColimitsOfShape J F] : ReflectsColimitsOfShape J F where instance (priority := 10) reflectsColimitsOfCreatesColimits (F : C ⥤ D) [CreatesColimitsOfSize.{w, w'} F] : ReflectsColimitsOfSize.{w, w'} F where /-- A helper to show a functor creates limits. In particular, if we can show that for any limit cone `c` for `K ⋙ F`, there is a lift of it which is a limit and `F` reflects isomorphisms, then `F` creates limits. Usually, `F` creating limits says that _any_ lift of `c` is a limit, but here we only need to show that our particular lift of `c` is a limit. -/ structure LiftsToLimit (K : J ⥤ C) (F : C ⥤ D) (c : Cone (K ⋙ F)) (t : IsLimit c) extends LiftableCone K F c where /-- the lifted cone is limit -/ makesLimit : IsLimit liftedCone /-- A helper to show a functor creates colimits. In particular, if we can show that for any limit cocone `c` for `K ⋙ F`, there is a lift of it which is a limit and `F` reflects isomorphisms, then `F` creates colimits. Usually, `F` creating colimits says that _any_ lift of `c` is a colimit, but here we only need to show that our particular lift of `c` is a colimit. -/ structure LiftsToColimit (K : J ⥤ C) (F : C ⥤ D) (c : Cocone (K ⋙ F)) (t : IsColimit c) extends LiftableCocone K F c where /-- the lifted cocone is colimit -/ makesColimit : IsColimit liftedCocone /-- If `F` reflects isomorphisms and we can lift any limit cone to a limit cone, then `F` creates limits. In particular here we don't need to assume that F reflects limits. -/ def createsLimitOfReflectsIso {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] (h : ∀ c t, LiftsToLimit K F c t) : CreatesLimit K F where lifts c t := (h c t).toLiftableCone toReflectsLimit := { reflects := fun {d} hd => by let d' : Cone K := (h (F.mapCone d) hd).toLiftableCone.liftedCone let i : F.mapCone d' ≅ F.mapCone d := (h (F.mapCone d) hd).toLiftableCone.validLift let hd' : IsLimit d' := (h (F.mapCone d) hd).makesLimit let f : d ⟶ d' := hd'.liftConeMorphism d have : (Cones.functoriality K F).map f = i.inv := (hd.ofIsoLimit i.symm).uniq_cone_morphism haveI : IsIso ((Cones.functoriality K F).map f) := by rw [this] infer_instance haveI : IsIso f := isIso_of_reflects_iso f (Cones.functoriality K F) exact IsLimit.ofIsoLimit hd' (asIso f).symm } /-- If `F` reflects isomorphisms and we can lift a single limit cone to a limit cone, then `F` creates limits. Note that unlike `createsLimitOfReflectsIso`, to apply this result it is necessary to know that `K ⋙ F` actually has a limit. -/ def createsLimitOfReflectsIso' {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] {c : Cone (K ⋙ F)} (hc : IsLimit c) (h : LiftsToLimit K F c hc) : CreatesLimit K F := createsLimitOfReflectsIso fun _ t => { liftedCone := h.liftedCone validLift := h.validLift ≪≫ IsLimit.uniqueUpToIso hc t makesLimit := h.makesLimit } -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the limit for `K` it suffices to exhibit a lift of a limit cone for `K ⋙ F`. -/ def createsLimitOfFullyFaithfulOfLift' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cone (K ⋙ F)} (hl : IsLimit l) (c : Cone K) (i : F.mapCone c ≅ l) : CreatesLimit K F := createsLimitOfReflectsIso fun _ t => { liftedCone := c validLift := i ≪≫ IsLimit.uniqueUpToIso hl t makesLimit := IsLimit.ofFaithful F (IsLimit.ofIsoLimit hl i.symm) _ fun _ => F.map_preimage _ } -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasLimit (K ⋙ F)`, to show that `F` creates the limit for `K` it suffices to exhibit a lift of the chosen limit cone for `K ⋙ F`. -/ def createsLimitOfFullyFaithfulOfLift {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasLimit (K ⋙ F)] (c : Cone K) (i : F.mapCone c ≅ limit.cone (K ⋙ F)) : CreatesLimit K F := createsLimitOfFullyFaithfulOfLift' (limit.isLimit _) c i -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the limit for `K` it suffices to show that a limit point is in the essential image of `F`. -/ def createsLimitOfFullyFaithfulOfIso' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cone (K ⋙ F)} (hl : IsLimit l) (X : C) (i : F.obj X ≅ l.pt) : CreatesLimit K F := createsLimitOfFullyFaithfulOfLift' hl { pt := X π := { app := fun j => F.preimage (i.hom ≫ l.π.app j) naturality := fun Y Z f => F.map_injective <| by dsimp simpa using (l.w f).symm } } (Cones.ext i fun j => by simp only [Functor.map_preimage, Functor.mapCone_π_app]) -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cone maps, -- so the constructed limits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasLimit (K ⋙ F)`, to show that `F` creates the limit for `K` it suffices to show that the chosen limit point is in the essential image of `F`. -/ def createsLimitOfFullyFaithfulOfIso {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasLimit (K ⋙ F)] (X : C) (i : F.obj X ≅ limit (K ⋙ F)) : CreatesLimit K F := createsLimitOfFullyFaithfulOfIso' (limit.isLimit _) X i /-- A fully faithful functor that preserves a limit that exists also creates the limit. -/ def createsLimitOfFullyFaithfulOfPreserves {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasLimit K] [PreservesLimit K F] : CreatesLimit K F := createsLimitOfFullyFaithfulOfLift' (PreservesLimit.preserves <| limit.isLimit K) _ (Iso.refl _) -- see Note [lower instance priority] /-- `F` preserves the limit of `K` if it creates the limit and `K ⋙ F` has the limit. -/ instance (priority := 100) preservesLimitOfCreatesLimitAndHasLimit (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] [HasLimit (K ⋙ F)] : PreservesLimit K F where preserves t := IsLimit.ofIsoLimit (limit.isLimit _) ((liftedLimitMapsToOriginal (limit.isLimit _)).symm ≪≫ (Cones.functoriality K F).mapIso ((liftedLimitIsLimit (limit.isLimit _)).uniqueUpToIso t)) -- see Note [lower instance priority] /-- `F` preserves the limit of shape `J` if it creates these limits and `D` has them. -/ instance (priority := 100) preservesLimitOfShapeOfCreatesLimitsOfShapeAndHasLimitsOfShape (F : C ⥤ D) [CreatesLimitsOfShape J F] [HasLimitsOfShape J D] : PreservesLimitsOfShape J F where -- see Note [lower instance priority] /-- `F` preserves limits if it creates limits and `D` has limits. -/ instance (priority := 100) preservesLimitsOfCreatesLimitsAndHasLimits (F : C ⥤ D) [CreatesLimitsOfSize.{w, w'} F] [HasLimitsOfSize.{w, w'} D] : PreservesLimitsOfSize.{w, w'} F where /-- If `F` reflects isomorphisms and we can lift any colimit cocone to a colimit cocone, then `F` creates colimits. In particular here we don't need to assume that F reflects colimits. -/ def createsColimitOfReflectsIso {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] (h : ∀ c t, LiftsToColimit K F c t) : CreatesColimit K F where lifts c t := (h c t).toLiftableCocone toReflectsColimit := { reflects := fun {d} hd => by let d' : Cocone K := (h (F.mapCocone d) hd).toLiftableCocone.liftedCocone let i : F.mapCocone d' ≅ F.mapCocone d := (h (F.mapCocone d) hd).toLiftableCocone.validLift let hd' : IsColimit d' := (h (F.mapCocone d) hd).makesColimit let f : d' ⟶ d := hd'.descCoconeMorphism d have : (Cocones.functoriality K F).map f = i.hom := (hd.ofIsoColimit i.symm).uniq_cocone_morphism haveI : IsIso ((Cocones.functoriality K F).map f) := by rw [this] infer_instance haveI := isIso_of_reflects_iso f (Cocones.functoriality K F) exact IsColimit.ofIsoColimit hd' (asIso f) } /-- If `F` reflects isomorphisms and we can lift a single colimit cocone to a colimit cocone, then `F` creates limits. Note that unlike `createsColimitOfReflectsIso`, to apply this result it is necessary to know that `K ⋙ F` actually has a colimit. -/ def createsColimitOfReflectsIso' {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms] {c : Cocone (K ⋙ F)} (hc : IsColimit c) (h : LiftsToColimit K F c hc) : CreatesColimit K F := createsColimitOfReflectsIso fun _ t => { liftedCocone := h.liftedCocone validLift := h.validLift ≪≫ IsColimit.uniqueUpToIso hc t makesColimit := h.makesColimit } -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the colimit for `K` it suffices to exhibit a lift of a colimit cocone for `K ⋙ F`. -/ def createsColimitOfFullyFaithfulOfLift' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cocone (K ⋙ F)} (hl : IsColimit l) (c : Cocone K) (i : F.mapCocone c ≅ l) : CreatesColimit K F := createsColimitOfReflectsIso fun _ t => { liftedCocone := c validLift := i ≪≫ IsColimit.uniqueUpToIso hl t makesColimit := IsColimit.ofFaithful F (IsColimit.ofIsoColimit hl i.symm) _ fun _ => F.map_preimage _ } -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasColimit (K ⋙ F)`, to show that `F` creates the colimit for `K` it suffices to exhibit a lift of the chosen colimit cocone for `K ⋙ F`. -/ def createsColimitOfFullyFaithfulOfLift {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasColimit (K ⋙ F)] (c : Cocone K) (i : F.mapCocone c ≅ colimit.cocone (K ⋙ F)) : CreatesColimit K F := createsColimitOfFullyFaithfulOfLift' (colimit.isColimit _) c i /-- A fully faithful functor that preserves a colimit that exists also creates the colimit. -/ def createsColimitOfFullyFaithfulOfPreserves {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasColimit K] [PreservesColimit K F] : CreatesColimit K F := createsColimitOfFullyFaithfulOfLift' (PreservesColimit.preserves <| colimit.isColimit K) _ (Iso.refl _) -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, to show that `F` creates the colimit for `K` it suffices to show that a colimit point is in the essential image of `F`. -/ def createsColimitOfFullyFaithfulOfIso' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] {l : Cocone (K ⋙ F)} (hl : IsColimit l) (X : C) (i : F.obj X ≅ l.pt) : CreatesColimit K F := createsColimitOfFullyFaithfulOfLift' hl { pt := X ι := { app := fun j => F.preimage (l.ι.app j ≫ i.inv) naturality := fun Y Z f => F.map_injective <| by dsimp simpa [← cancel_mono i.hom] using l.w f } } (Cocones.ext i fun j => by simp) -- Notice however that even if the isomorphism is `Iso.refl _`, -- this construction will insert additional identity morphisms in the cocone maps, -- so the constructed colimits may not be ideal, definitionally. /-- When `F` is fully faithful, and `HasColimit (K ⋙ F)`, to show that `F` creates the colimit for `K` it suffices to show that the chosen colimit point is in the essential image of `F`. -/ def createsColimitOfFullyFaithfulOfIso {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful] [HasColimit (K ⋙ F)] (X : C) (i : F.obj X ≅ colimit (K ⋙ F)) : CreatesColimit K F := createsColimitOfFullyFaithfulOfIso' (colimit.isColimit _) X i -- see Note [lower instance priority] /-- `F` preserves the colimit of `K` if it creates the colimit and `K ⋙ F` has the colimit. -/ instance (priority := 100) preservesColimitOfCreatesColimitAndHasColimit (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] [HasColimit (K ⋙ F)] : PreservesColimit K F where preserves t := IsColimit.ofIsoColimit (colimit.isColimit _) ((liftedColimitMapsToOriginal (colimit.isColimit _)).symm ≪≫ (Cocones.functoriality K F).mapIso ((liftedColimitIsColimit (colimit.isColimit _)).uniqueUpToIso t)) -- see Note [lower instance priority] /-- `F` preserves the colimit of shape `J` if it creates these colimits and `D` has them. -/ instance (priority := 100) preservesColimitOfShapeOfCreatesColimitsOfShapeAndHasColimitsOfShape (F : C ⥤ D) [CreatesColimitsOfShape J F] [HasColimitsOfShape J D] : PreservesColimitsOfShape J F where -- see Note [lower instance priority] /-- `F` preserves limits if it creates limits and `D` has limits. -/ instance (priority := 100) preservesColimitsOfCreatesColimitsAndHasColimits (F : C ⥤ D) [CreatesColimitsOfSize.{w, w'} F] [HasColimitsOfSize.{w, w'} D] : PreservesColimitsOfSize.{w, w'} F where /-- Transfer creation of limits along a natural isomorphism in the diagram. -/ def createsLimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [CreatesLimit K₁ F] : CreatesLimit K₂ F := { reflectsLimitOfIsoDiagram F h with lifts := fun c t => let t' := (IsLimit.postcomposeInvEquiv (isoWhiskerRight h F : _) c).symm t { liftedCone := (Cones.postcompose h.hom).obj (liftLimit t') validLift := Functor.mapConePostcompose F ≪≫ (Cones.postcompose (isoWhiskerRight h F).hom).mapIso (liftedLimitMapsToOriginal t') ≪≫ Cones.ext (Iso.refl _) fun j => by dsimp rw [Category.assoc, ← F.map_comp] simp } } /-- If `F` creates the limit of `K` and `F ≅ G`, then `G` creates the limit of `K`. -/ def createsLimitOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimit K F] : CreatesLimit K G where lifts c t := { liftedCone := liftLimit ((IsLimit.postcomposeInvEquiv (isoWhiskerLeft K h : _) c).symm t) validLift := by refine (IsLimit.mapConeEquiv h ?_).uniqueUpToIso t apply IsLimit.ofIsoLimit _ (liftedLimitMapsToOriginal _).symm apply (IsLimit.postcomposeInvEquiv _ _).symm t } toReflectsLimit := reflectsLimitOfNatIso _ h /-- If `F` creates limits of shape `J` and `F ≅ G`, then `G` creates limits of shape `J`. -/ def createsLimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimitsOfShape J F] : CreatesLimitsOfShape J G where CreatesLimit := createsLimitOfNatIso h /-- If `F` creates limits and `F ≅ G`, then `G` creates limits. -/ def createsLimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimitsOfSize.{w, w'} F] : CreatesLimitsOfSize.{w, w'} G where CreatesLimitsOfShape := createsLimitsOfShapeOfNatIso h /-- Transfer creation of colimits along a natural isomorphism in the diagram. -/ def createsColimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [CreatesColimit K₁ F] : CreatesColimit K₂ F := { reflectsColimitOfIsoDiagram F h with lifts := fun c t => let t' := (IsColimit.precomposeHomEquiv (isoWhiskerRight h F : _) c).symm t { liftedCocone := (Cocones.precompose h.inv).obj (liftColimit t') validLift := Functor.mapCoconePrecompose F ≪≫ (Cocones.precompose (isoWhiskerRight h F).inv).mapIso (liftedColimitMapsToOriginal t') ≪≫ Cocones.ext (Iso.refl _) fun j => by dsimp rw [← F.map_comp_assoc] simp } } /-- If `F` creates the colimit of `K` and `F ≅ G`, then `G` creates the colimit of `K`. -/ def createsColimitOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimit K F] : CreatesColimit K G where lifts c t := { liftedCocone := liftColimit ((IsColimit.precomposeHomEquiv (isoWhiskerLeft K h : _) c).symm t) validLift := by refine (IsColimit.mapCoconeEquiv h ?_).uniqueUpToIso t apply IsColimit.ofIsoColimit _ (liftedColimitMapsToOriginal _).symm apply (IsColimit.precomposeHomEquiv _ _).symm t } toReflectsColimit := reflectsColimitOfNatIso _ h /-- If `F` creates colimits of shape `J` and `F ≅ G`, then `G` creates colimits of shape `J`. -/ def createsColimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimitsOfShape J F] : CreatesColimitsOfShape J G where CreatesColimit := createsColimitOfNatIso h /-- If `F` creates colimits and `F ≅ G`, then `G` creates colimits. -/ def createsColimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimitsOfSize.{w, w'} F] : CreatesColimitsOfSize.{w, w'} G where CreatesColimitsOfShape := createsColimitsOfShapeOfNatIso h -- For the inhabited linter later. /-- If F creates the limit of K, any cone lifts to a limit. -/ def liftsToLimitOfCreates (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] (c : Cone (K ⋙ F)) (t : IsLimit c) : LiftsToLimit K F c t where liftedCone := liftLimit t validLift := liftedLimitMapsToOriginal t makesLimit := liftedLimitIsLimit t -- For the inhabited linter later. /-- If F creates the colimit of K, any cocone lifts to a colimit. -/ def liftsToColimitOfCreates (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] (c : Cocone (K ⋙ F)) (t : IsColimit c) : LiftsToColimit K F c t where liftedCocone := liftColimit t validLift := liftedColimitMapsToOriginal t makesColimit := liftedColimitIsColimit t /-- Any cone lifts through the identity functor. -/ def idLiftsCone (c : Cone (K ⋙ 𝟭 C)) : LiftableCone K (𝟭 C) c where liftedCone := { pt := c.pt π := c.π ≫ K.rightUnitor.hom } validLift := Cones.ext (Iso.refl _) /-- The identity functor creates all limits. -/ instance idCreatesLimits : CreatesLimitsOfSize.{w, w'} (𝟭 C) where CreatesLimitsOfShape := { CreatesLimit := { lifts := fun c _ => idLiftsCone c } } /-- Any cocone lifts through the identity functor. -/ def idLiftsCocone (c : Cocone (K ⋙ 𝟭 C)) : LiftableCocone K (𝟭 C) c where liftedCocone := { pt := c.pt ι := K.rightUnitor.inv ≫ c.ι } validLift := Cocones.ext (Iso.refl _) /-- The identity functor creates all colimits. -/ instance idCreatesColimits : CreatesColimitsOfSize.{w, w'} (𝟭 C) where CreatesColimitsOfShape := { CreatesColimit := { lifts := fun c _ => idLiftsCocone c } } /-- Satisfy the inhabited linter -/ instance inhabitedLiftableCone (c : Cone (K ⋙ 𝟭 C)) : Inhabited (LiftableCone K (𝟭 C) c) := ⟨idLiftsCone c⟩ instance inhabitedLiftableCocone (c : Cocone (K ⋙ 𝟭 C)) : Inhabited (LiftableCocone K (𝟭 C) c) := ⟨idLiftsCocone c⟩ /-- Satisfy the inhabited linter -/ instance inhabitedLiftsToLimit (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] (c : Cone (K ⋙ F)) (t : IsLimit c) : Inhabited (LiftsToLimit _ _ _ t) := ⟨liftsToLimitOfCreates K F c t⟩ instance inhabitedLiftsToColimit (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] (c : Cocone (K ⋙ F)) (t : IsColimit c) : Inhabited (LiftsToColimit _ _ _ t) := ⟨liftsToColimitOfCreates K F c t⟩ section Comp variable {E : Type u₃} [ℰ : Category.{v₃} E] variable (F : C ⥤ D) (G : D ⥤ E) instance compCreatesLimit [CreatesLimit K F] [CreatesLimit (K ⋙ F) G] : CreatesLimit K (F ⋙ G) where lifts c t := by let c' : Cone ((K ⋙ F) ⋙ G) := c let t' : IsLimit c' := t exact { liftedCone := liftLimit (liftedLimitIsLimit t') validLift := (Cones.functoriality (K ⋙ F) G).mapIso (liftedLimitMapsToOriginal (liftedLimitIsLimit t')) ≪≫ liftedLimitMapsToOriginal t' } instance compCreatesLimitsOfShape [CreatesLimitsOfShape J F] [CreatesLimitsOfShape J G] : CreatesLimitsOfShape J (F ⋙ G) where CreatesLimit := inferInstance instance compCreatesLimits [CreatesLimitsOfSize.{w, w'} F] [CreatesLimitsOfSize.{w, w'} G] : CreatesLimitsOfSize.{w, w'} (F ⋙ G) where CreatesLimitsOfShape := inferInstance instance compCreatesColimit [CreatesColimit K F] [CreatesColimit (K ⋙ F) G] : CreatesColimit K (F ⋙ G) where lifts c t := let c' : Cocone ((K ⋙ F) ⋙ G) := c let t' : IsColimit c' := t { liftedCocone := liftColimit (liftedColimitIsColimit t') validLift := (Cocones.functoriality (K ⋙ F) G).mapIso (liftedColimitMapsToOriginal (liftedColimitIsColimit t')) ≪≫ liftedColimitMapsToOriginal t' } instance compCreatesColimitsOfShape [CreatesColimitsOfShape J F] [CreatesColimitsOfShape J G] : CreatesColimitsOfShape J (F ⋙ G) where CreatesColimit := inferInstance instance compCreatesColimits [CreatesColimitsOfSize.{w, w'} F] [CreatesColimitsOfSize.{w, w'} G] : CreatesColimitsOfSize.{w, w'} (F ⋙ G) where CreatesColimitsOfShape := inferInstance end Comp end Creates end CategoryTheory
CategoryTheory\Limits\Elements.lean
/- Copyright (c) 2024 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Elements import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Preserves.Limits /-! # Limits in the category of elements We show that if `C` has limits of shape `I` and `A : C ⥤ Type w` preserves limits of shape `I`, then the category of elements of `A` has limits of shape `I` and the forgetful functor `π : A.Elements ⥤ C` creates them. -/ universe w v₁ v u₁ u namespace CategoryTheory open Limits Opposite variable {C : Type u} [Category.{v} C] namespace CategoryOfElements variable {A : C ⥤ Type w} {I : Type u₁} [Category.{v₁} I] [Small.{w} I] namespace CreatesLimitsAux variable (F : I ⥤ A.Elements) /-- (implementation) A system `(Fi, fi)_i` of elements induces an element in `lim_i A(Fi)`. -/ noncomputable def liftedConeElement' : limit ((F ⋙ π A) ⋙ A) := Types.Limit.mk _ (fun i => (F.obj i).2) (by simp) @[simp] lemma π_liftedConeElement' (i : I) : limit.π ((F ⋙ π A) ⋙ A) i (liftedConeElement' F) = (F.obj i).2 := Types.Limit.π_mk _ _ _ _ variable [HasLimitsOfShape I C] [PreservesLimitsOfShape I A] /-- (implementation) A system `(Fi, fi)_i` of elements induces an element in `A(lim_i Fi)`. -/ noncomputable def liftedConeElement : A.obj (limit (F ⋙ π A)) := (preservesLimitIso A (F ⋙ π A)).inv (liftedConeElement' F) @[simp] lemma map_lift_mapCone (c : Cone F) : A.map (limit.lift (F ⋙ π A) ((π A).mapCone c)) c.pt.snd = liftedConeElement F := by apply (preservesLimitIso A (F ⋙ π A)).toEquiv.injective ext i have h₁ := congrFun (preservesLimitsIso_hom_π A (F ⋙ π A) i) (A.map (limit.lift (F ⋙ π A) ((π A).mapCone c)) c.pt.snd) have h₂ := (c.π.app i).property simp_all [← FunctorToTypes.map_comp_apply, liftedConeElement] @[simp] lemma map_π_liftedConeElement (i : I) : A.map (limit.π (F ⋙ π A) i) (liftedConeElement F) = (F.obj i).snd := by have := congrFun (preservesLimitsIso_inv_π A (F ⋙ π A) i) (liftedConeElement' F) simp_all [liftedConeElement] /-- (implementation) The constructured limit cone. -/ @[simps] noncomputable def liftedCone : Cone F where pt := ⟨_, liftedConeElement F⟩ π := { app := fun i => ⟨limit.π (F ⋙ π A) i, by simp⟩ naturality := fun i i' f => by ext; simpa using (limit.w _ _).symm } /-- (implementation) The constructed limit cone is a lift of the limit cone in `C`. -/ noncomputable def isValidLift : (π A).mapCone (liftedCone F) ≅ limit.cone (F ⋙ π A) := Iso.refl _ /-- (implementation) The constuctured limit cone is a limit cone. -/ noncomputable def isLimit : IsLimit (liftedCone F) where lift s := ⟨limit.lift (F ⋙ π A) ((π A).mapCone s), by simp⟩ uniq s m h := ext _ _ _ <| limit.hom_ext fun i => by simpa using congrArg Subtype.val (h i) end CreatesLimitsAux variable [HasLimitsOfShape I C] [PreservesLimitsOfShape I A] section open CreatesLimitsAux noncomputable instance (F : I ⥤ A.Elements) : CreatesLimit F (π A) := createsLimitOfReflectsIso' (limit.isLimit _) ⟨⟨liftedCone F, isValidLift F⟩, isLimit F⟩ end noncomputable instance : CreatesLimitsOfShape I (π A) where instance : HasLimitsOfShape I A.Elements := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (π A) end CategoryOfElements end CategoryTheory
CategoryTheory\Limits\EpiMono.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Relation between mono/epi and pullback/pushout squares In this file, monomorphisms and epimorphisms are characterized in terms of pullback and pushout squares. For example, we obtain `mono_iff_isPullback` which asserts that a morphism `f : X ⟶ Y` is a monomorphism iff the obvious square ``` X ⟶ X | | v v X ⟶ Y ``` is a pullback square. -/ namespace CategoryTheory open Category Limits variable {C : Type*} [Category C] {X Y : C} {f : X ⟶ Y} section Mono variable {c : PullbackCone f f} lemma mono_iff_fst_eq_snd (hc : IsLimit c) : Mono f ↔ c.fst = c.snd := by constructor · intro hf simpa only [← cancel_mono f] using c.condition · intro hf constructor intro Z g g' h obtain ⟨φ, rfl, rfl⟩ := PullbackCone.IsLimit.lift' hc g g' h rw [hf] lemma mono_iff_isIso_fst (hc : IsLimit c) : Mono f ↔ IsIso c.fst := by rw [mono_iff_fst_eq_snd hc] constructor · intro h obtain ⟨φ, hφ₁, hφ₂⟩ := PullbackCone.IsLimit.lift' hc (𝟙 X) (𝟙 X) (by simp) refine ⟨φ, PullbackCone.IsLimit.hom_ext hc ?_ ?_, hφ₁⟩ · dsimp simp only [assoc, hφ₁, id_comp, comp_id] · dsimp simp only [assoc, hφ₂, id_comp, comp_id, h] · intro obtain ⟨φ, hφ₁, hφ₂⟩ := PullbackCone.IsLimit.lift' hc (𝟙 X) (𝟙 X) (by simp) have : IsSplitEpi φ := IsSplitEpi.mk ⟨SplitEpi.mk c.fst (by rw [← cancel_mono c.fst, assoc, id_comp, hφ₁, comp_id])⟩ rw [← cancel_epi φ, hφ₁, hφ₂] lemma mono_iff_isIso_snd (hc : IsLimit c) : Mono f ↔ IsIso c.snd := mono_iff_isIso_fst (PullbackCone.flipIsLimit hc) variable (f) lemma mono_iff_isPullback : Mono f ↔ IsPullback (𝟙 X) (𝟙 X) f f := by constructor · intro exact IsPullback.of_isLimit (PullbackCone.isLimitMkIdId f) · intro hf exact (mono_iff_fst_eq_snd hf.isLimit).2 rfl end Mono section Epi variable {c : PushoutCocone f f} lemma epi_iff_inl_eq_inr (hc : IsColimit c) : Epi f ↔ c.inl = c.inr := by constructor · intro hf simpa only [← cancel_epi f] using c.condition · intro hf constructor intro Z g g' h obtain ⟨φ, rfl, rfl⟩ := PushoutCocone.IsColimit.desc' hc g g' h rw [hf] lemma epi_iff_isIso_inl (hc : IsColimit c) : Epi f ↔ IsIso c.inl := by rw [epi_iff_inl_eq_inr hc] constructor · intro h obtain ⟨φ, hφ₁, hφ₂⟩ := PushoutCocone.IsColimit.desc' hc (𝟙 Y) (𝟙 Y) (by simp) refine ⟨φ, hφ₁, PushoutCocone.IsColimit.hom_ext hc ?_ ?_⟩ · dsimp simp only [comp_id, reassoc_of% hφ₁] · dsimp simp only [comp_id, h, reassoc_of% hφ₂] · intro obtain ⟨φ, hφ₁, hφ₂⟩ := PushoutCocone.IsColimit.desc' hc (𝟙 Y) (𝟙 Y) (by simp) have : IsSplitMono φ := IsSplitMono.mk ⟨SplitMono.mk c.inl (by rw [← cancel_epi c.inl, reassoc_of% hφ₁, comp_id])⟩ rw [← cancel_mono φ, hφ₁, hφ₂] lemma epi_iff_isIso_inr (hc : IsColimit c) : Epi f ↔ IsIso c.inr := epi_iff_isIso_inl (PushoutCocone.flipIsColimit hc) variable (f) lemma epi_iff_isPushout : Epi f ↔ IsPushout f f (𝟙 Y) (𝟙 Y) := by constructor · intro exact IsPushout.of_isColimit (PushoutCocone.isColimitMkIdId f) · intro hf exact (epi_iff_inl_eq_inr hf.isColimit).2 rfl end Epi end CategoryTheory
CategoryTheory\Limits\EssentiallySmall.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.EssentiallySmall /-! # Limits over essentially small indexing categories If `C` has limits of size `w` and `J` is `w`-essentially small, then `C` has limits of shape `J`. See also the file `FinallySmall.lean` for more general results. -/ universe w₁ w₂ v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory namespace CategoryTheory.Limits variable (J : Type u₂) [Category.{v₂} J] (C : Type u₁) [Category.{v₁} C] theorem hasLimitsOfShape_of_essentiallySmall [EssentiallySmall.{w₁} J] [HasLimitsOfSize.{w₁, w₁} C] : HasLimitsOfShape J C := hasLimitsOfShape_of_equivalence <| Equivalence.symm <| equivSmallModel.{w₁} J theorem hasColimitsOfShape_of_essentiallySmall [EssentiallySmall.{w₁} J] [HasColimitsOfSize.{w₁, w₁} C] : HasColimitsOfShape J C := hasColimitsOfShape_of_equivalence <| Equivalence.symm <| equivSmallModel.{w₁} J theorem hasProductsOfShape_of_small (β : Type w₂) [Small.{w₁} β] [HasProducts.{w₁} C] : HasProductsOfShape β C := hasLimitsOfShape_of_equivalence <| Discrete.equivalence <| Equiv.symm <| equivShrink β theorem hasCoproductsOfShape_of_small (β : Type w₂) [Small.{w₁} β] [HasCoproducts.{w₁} C] : HasCoproductsOfShape β C := hasColimitsOfShape_of_equivalence <| Discrete.equivalence <| Equiv.symm <| equivShrink β end CategoryTheory.Limits
CategoryTheory\Limits\ExactFunctor.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Preserves.Finite /-! # Bundled exact functors We say that a functor `F` is left exact if it preserves finite limits, it is right exact if it preserves finite colimits, and it is exact if it is both left exact and right exact. In this file, we define the categories of bundled left exact, right exact and exact functors. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory.Limits namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] section variable (C) (D) -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- Bundled left-exact functors. -/ def LeftExactFunctor := FullSubcategory fun F : C ⥤ D => Nonempty (PreservesFiniteLimits F) instance : Category (LeftExactFunctor C D) := FullSubcategory.category _ /-- `C ⥤ₗ D` denotes left exact functors `C ⥤ D` -/ infixr:26 " ⥤ₗ " => LeftExactFunctor /-- A left exact functor is in particular a functor. -/ def LeftExactFunctor.forget : (C ⥤ₗ D) ⥤ C ⥤ D := fullSubcategoryInclusion _ instance : (LeftExactFunctor.forget C D).Full := FullSubcategory.full _ instance : (LeftExactFunctor.forget C D).Faithful := FullSubcategory.faithful _ -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- Bundled right-exact functors. -/ def RightExactFunctor := FullSubcategory fun F : C ⥤ D => Nonempty (PreservesFiniteColimits F) instance : Category (RightExactFunctor C D) := FullSubcategory.category _ /-- `C ⥤ᵣ D` denotes right exact functors `C ⥤ D` -/ infixr:26 " ⥤ᵣ " => RightExactFunctor /-- A right exact functor is in particular a functor. -/ def RightExactFunctor.forget : (C ⥤ᵣ D) ⥤ C ⥤ D := fullSubcategoryInclusion _ instance : (RightExactFunctor.forget C D).Full := FullSubcategory.full _ instance : (RightExactFunctor.forget C D).Faithful := FullSubcategory.faithful _ -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- Bundled exact functors. -/ def ExactFunctor := FullSubcategory fun F : C ⥤ D => Nonempty (PreservesFiniteLimits F) ∧ Nonempty (PreservesFiniteColimits F) instance : Category (ExactFunctor C D) := FullSubcategory.category _ /-- `C ⥤ₑ D` denotes exact functors `C ⥤ D` -/ infixr:26 " ⥤ₑ " => ExactFunctor /-- An exact functor is in particular a functor. -/ def ExactFunctor.forget : (C ⥤ₑ D) ⥤ C ⥤ D := fullSubcategoryInclusion _ instance : (ExactFunctor.forget C D).Full := FullSubcategory.full _ instance : (ExactFunctor.forget C D).Faithful := FullSubcategory.faithful _ /-- Turn an exact functor into a left exact functor. -/ def LeftExactFunctor.ofExact : (C ⥤ₑ D) ⥤ C ⥤ₗ D := FullSubcategory.map fun _ => And.left instance : (LeftExactFunctor.ofExact C D).Full := FullSubcategory.full_map _ instance : (LeftExactFunctor.ofExact C D).Faithful := FullSubcategory.faithful_map _ /-- Turn an exact functor into a left exact functor. -/ def RightExactFunctor.ofExact : (C ⥤ₑ D) ⥤ C ⥤ᵣ D := FullSubcategory.map fun _ => And.right instance : (RightExactFunctor.ofExact C D).Full := FullSubcategory.full_map _ instance : (RightExactFunctor.ofExact C D).Faithful := FullSubcategory.faithful_map _ variable {C D} @[simp] theorem LeftExactFunctor.ofExact_obj (F : C ⥤ₑ D) : (LeftExactFunctor.ofExact C D).obj F = ⟨F.1, F.2.1⟩ := rfl @[simp] theorem RightExactFunctor.ofExact_obj (F : C ⥤ₑ D) : (RightExactFunctor.ofExact C D).obj F = ⟨F.1, F.2.2⟩ := rfl @[simp] theorem LeftExactFunctor.ofExact_map {F G : C ⥤ₑ D} (α : F ⟶ G) : (LeftExactFunctor.ofExact C D).map α = α := rfl @[simp] theorem RightExactFunctor.ofExact_map {F G : C ⥤ₑ D} (α : F ⟶ G) : (RightExactFunctor.ofExact C D).map α = α := rfl @[simp] theorem LeftExactFunctor.forget_obj (F : C ⥤ₗ D) : (LeftExactFunctor.forget C D).obj F = F.1 := rfl @[simp] theorem RightExactFunctor.forget_obj (F : C ⥤ᵣ D) : (RightExactFunctor.forget C D).obj F = F.1 := rfl @[simp] theorem ExactFunctor.forget_obj (F : C ⥤ₑ D) : (ExactFunctor.forget C D).obj F = F.1 := rfl @[simp] theorem LeftExactFunctor.forget_map {F G : C ⥤ₗ D} (α : F ⟶ G) : (LeftExactFunctor.forget C D).map α = α := rfl @[simp] theorem RightExactFunctor.forget_map {F G : C ⥤ᵣ D} (α : F ⟶ G) : (RightExactFunctor.forget C D).map α = α := rfl @[simp] theorem ExactFunctor.forget_map {F G : C ⥤ₑ D} (α : F ⟶ G) : (ExactFunctor.forget C D).map α = α := rfl /-- Turn a left exact functor into an object of the category `LeftExactFunctor C D`. -/ def LeftExactFunctor.of (F : C ⥤ D) [PreservesFiniteLimits F] : C ⥤ₗ D := ⟨F, ⟨inferInstance⟩⟩ /-- Turn a right exact functor into an object of the category `RightExactFunctor C D`. -/ def RightExactFunctor.of (F : C ⥤ D) [PreservesFiniteColimits F] : C ⥤ᵣ D := ⟨F, ⟨inferInstance⟩⟩ /-- Turn an exact functor into an object of the category `ExactFunctor C D`. -/ def ExactFunctor.of (F : C ⥤ D) [PreservesFiniteLimits F] [PreservesFiniteColimits F] : C ⥤ₑ D := ⟨F, ⟨⟨inferInstance⟩, ⟨inferInstance⟩⟩⟩ @[simp] theorem LeftExactFunctor.of_fst (F : C ⥤ D) [PreservesFiniteLimits F] : (LeftExactFunctor.of F).obj = F := rfl @[simp] theorem RightExactFunctor.of_fst (F : C ⥤ D) [PreservesFiniteColimits F] : (RightExactFunctor.of F).obj = F := rfl @[simp] theorem ExactFunctor.of_fst (F : C ⥤ D) [PreservesFiniteLimits F] [PreservesFiniteColimits F] : (ExactFunctor.of F).obj = F := rfl theorem LeftExactFunctor.forget_obj_of (F : C ⥤ D) [PreservesFiniteLimits F] : (LeftExactFunctor.forget C D).obj (LeftExactFunctor.of F) = F := rfl theorem RightExactFunctor.forget_obj_of (F : C ⥤ D) [PreservesFiniteColimits F] : (RightExactFunctor.forget C D).obj (RightExactFunctor.of F) = F := rfl theorem ExactFunctor.forget_obj_of (F : C ⥤ D) [PreservesFiniteLimits F] [PreservesFiniteColimits F] : (ExactFunctor.forget C D).obj (ExactFunctor.of F) = F := rfl noncomputable instance (F : C ⥤ₗ D) : PreservesFiniteLimits F.obj := F.property.some noncomputable instance (F : C ⥤ᵣ D) : PreservesFiniteColimits F.obj := F.property.some noncomputable instance (F : C ⥤ₑ D) : PreservesFiniteLimits F.obj := F.property.1.some noncomputable instance (F : C ⥤ₑ D) : PreservesFiniteColimits F.obj := F.property.2.some end end CategoryTheory
CategoryTheory\Limits\Filtered.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Types /-! # Filtered categories and limits In this file , we show that `C` is filtered if and only if for every functor `F : J ⥤ C` from a finite category there is some `X : C` such that `lim Hom(F·, X)` is nonempty. Furthermore, we define the type classes `HasCofilteredLimitsOfSize` and `HasFilteredColimitsOfSize`. -/ universe w' w v u noncomputable section open CategoryTheory variable {C : Type u} [Category.{v} C] namespace CategoryTheory section NonemptyLimit open CategoryTheory.Limits Opposite /-- `C` is filtered if and only if for every functor `F : J ⥤ C` from a finite category there is some `X : C` such that `lim Hom(F·, X)` is nonempty. Lemma 3.1.2 of [Kashiwara2006] -/ theorem IsFiltered.iff_nonempty_limit : IsFiltered C ↔ ∀ {J : Type v} [SmallCategory J] [FinCategory J] (F : J ⥤ C), ∃ (X : C), Nonempty (limit (F.op ⋙ yoneda.obj X)) := by rw [IsFiltered.iff_cocone_nonempty.{v}] refine ⟨fun h J _ _ F => ?_, fun h J _ _ F => ?_⟩ · obtain ⟨c⟩ := h F exact ⟨c.pt, ⟨(limitCompYonedaIsoCocone F c.pt).inv c.ι⟩⟩ · obtain ⟨pt, ⟨ι⟩⟩ := h F exact ⟨⟨pt, (limitCompYonedaIsoCocone F pt).hom ι⟩⟩ /-- `C` is cofiltered if and only if for every functor `F : J ⥤ C` from a finite category there is some `X : C` such that `lim Hom(X, F·)` is nonempty. -/ theorem IsCofiltered.iff_nonempty_limit : IsCofiltered C ↔ ∀ {J : Type v} [SmallCategory J] [FinCategory J] (F : J ⥤ C), ∃ (X : C), Nonempty (limit (F ⋙ coyoneda.obj (op X))) := by rw [IsCofiltered.iff_cone_nonempty.{v}] refine ⟨fun h J _ _ F => ?_, fun h J _ _ F => ?_⟩ · obtain ⟨c⟩ := h F exact ⟨c.pt, ⟨(limitCompCoyonedaIsoCone F c.pt).inv c.π⟩⟩ · obtain ⟨pt, ⟨π⟩⟩ := h F exact ⟨⟨pt, (limitCompCoyonedaIsoCone F pt).hom π⟩⟩ end NonemptyLimit namespace Limits section variable (C) /-- Class for having all cofiltered limits of a given size. -/ @[pp_with_univ] class HasCofilteredLimitsOfSize : Prop where /-- For all filtered types of size `w`, we have limits -/ HasLimitsOfShape : ∀ (I : Type w) [Category.{w'} I] [IsCofiltered I], HasLimitsOfShape I C /-- Class for having all filtered colimits of a given size. -/ @[pp_with_univ] class HasFilteredColimitsOfSize : Prop where /-- For all filtered types of a size `w`, we have colimits -/ HasColimitsOfShape : ∀ (I : Type w) [Category.{w'} I] [IsFiltered I], HasColimitsOfShape I C end instance (priority := 100) hasLimitsOfShape_of_has_cofiltered_limits [HasCofilteredLimitsOfSize.{w', w} C] (I : Type w) [Category.{w'} I] [IsCofiltered I] : HasLimitsOfShape I C := HasCofilteredLimitsOfSize.HasLimitsOfShape _ instance (priority := 100) hasColimitsOfShape_of_has_filtered_colimits [HasFilteredColimitsOfSize.{w', w} C] (I : Type w) [Category.{w'} I] [IsFiltered I] : HasColimitsOfShape I C := HasFilteredColimitsOfSize.HasColimitsOfShape _ end Limits end CategoryTheory
CategoryTheory\Limits\FilteredColimitCommutesFiniteLimit.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.ColimitLimit import Mathlib.CategoryTheory.Limits.Preserves.FunctorCategory import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.TypesFiltered import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Products.Bifunctor import Mathlib.Data.Countable.Small /-! # Filtered colimits commute with finite limits. We show that for a functor `F : J × K ⥤ Type v`, when `J` is finite and `K` is filtered, the universal morphism `colimitLimitToLimitColimit F` comparing the colimit (over `K`) of the limits (over `J`) with the limit of the colimits is an isomorphism. (In fact, to prove that it is injective only requires that `J` has finitely many objects.) ## References * Borceux, Handbook of categorical algebra 1, Theorem 2.13.4 * [Stacks: Filtered colimits](https://stacks.math.columbia.edu/tag/002W) -/ -- Various pieces of algebra that have previously been spuriously imported here: assert_not_exists map_ne_zero assert_not_exists Field -- TODO: We should morally be able to strengthen this to `assert_not_exists GroupWithZero`, but -- finiteness currently relies on more algebra than it needs. universe w v₁ v₂ v u₁ u₂ u open CategoryTheory CategoryTheory.Category CategoryTheory.Limits.Types CategoryTheory.Limits.Types.FilteredColimit namespace CategoryTheory.Limits section variable {J : Type u₁} {K : Type u₂} [Category.{v₁} J] [Category.{v₂} K] [Small.{v} K] /-- `(G ⋙ lim).obj j` = `limit (G.obj j)` definitionally, so this is just a variant of `limit_ext'`. -/ @[ext] lemma comp_lim_obj_ext {j : J} {G : J ⥤ K ⥤ Type v} (x y : (G ⋙ lim).obj j) (w : ∀ (k : K), limit.π (G.obj j) k x = limit.π (G.obj j) k y) : x = y := limit_ext _ x y w variable (F : J × K ⥤ Type v) open CategoryTheory.Prod variable [IsFiltered K] section /-! Injectivity doesn't need that we have finitely many morphisms in `J`, only that there are finitely many objects. -/ variable [Finite J] /-- This follows this proof from * Borceux, Handbook of categorical algebra 1, Theorem 2.13.4 -/ theorem colimitLimitToLimitColimit_injective : Function.Injective (colimitLimitToLimitColimit F) := by classical cases nonempty_fintype J -- Suppose we have two terms `x y` in the colimit (over `K`) of the limits (over `J`), -- and that these have the same image under `colimitLimitToLimitColimit F`. intro x y h -- These elements of the colimit have representatives somewhere: obtain ⟨kx, x, rfl⟩ := jointly_surjective' x obtain ⟨ky, y, rfl⟩ := jointly_surjective' y dsimp at x y -- Since the images of `x` and `y` are equal in a limit, they are equal componentwise -- (indexed by `j : J`), replace h := fun j => congr_arg (limit.π (curry.obj F ⋙ colim) j) h -- and they are equations in a filtered colimit, -- so for each `j` we have some place `k j` to the right of both `kx` and `ky` simp? [colimit_eq_iff] at h says simp only [Functor.comp_obj, colim_obj, ι_colimitLimitToLimitColimit_π_apply, colimit_eq_iff, curry_obj_obj_obj, curry_obj_obj_map] at h let k j := (h j).choose let f : ∀ j, kx ⟶ k j := fun j => (h j).choose_spec.choose let g : ∀ j, ky ⟶ k j := fun j => (h j).choose_spec.choose_spec.choose -- where the images of the components of the representatives become equal: have w : ∀ j, F.map ((𝟙 j, f j) : (j, kx) ⟶ (j, k j)) (limit.π ((curry.obj (swap K J ⋙ F)).obj kx) j x) = F.map ((𝟙 j, g j) : (j, ky) ⟶ (j, k j)) (limit.π ((curry.obj (swap K J ⋙ F)).obj ky) j y) := fun j => (h j).choose_spec.choose_spec.choose_spec -- We now use that `K` is filtered, picking some point to the right of all these -- morphisms `f j` and `g j`. let O : Finset K := Finset.univ.image k ∪ {kx, ky} have kxO : kx ∈ O := Finset.mem_union.mpr (Or.inr (by simp)) have kyO : ky ∈ O := Finset.mem_union.mpr (Or.inr (by simp)) have kjO : ∀ j, k j ∈ O := fun j => Finset.mem_union.mpr (Or.inl (by simp)) let H : Finset (Σ' (X Y : K) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) := (Finset.univ.image fun j : J => ⟨kx, k j, kxO, Finset.mem_union.mpr (Or.inl (by simp)), f j⟩) ∪ Finset.univ.image fun j : J => ⟨ky, k j, kyO, Finset.mem_union.mpr (Or.inl (by simp)), g j⟩ obtain ⟨S, T, W⟩ := IsFiltered.sup_exists O H have fH : ∀ j, (⟨kx, k j, kxO, kjO j, f j⟩ : Σ' (X Y : K) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H := fun j => Finset.mem_union.mpr (Or.inl (by simp only [true_and_iff, Finset.mem_univ, eq_self_iff_true, exists_prop_of_true, Finset.mem_image, heq_iff_eq] refine ⟨j, ?_⟩ simp only [heq_iff_eq] )) have gH : ∀ j, (⟨ky, k j, kyO, kjO j, g j⟩ : Σ' (X Y : K) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H := fun j => Finset.mem_union.mpr (Or.inr (by simp only [true_and_iff, Finset.mem_univ, eq_self_iff_true, exists_prop_of_true, Finset.mem_image, heq_iff_eq] refine ⟨j, ?_⟩ simp only [heq_iff_eq])) -- Our goal is now an equation between equivalence classes of representatives of a colimit, -- and so it suffices to show those representative become equal somewhere, in particular at `S`. apply colimit_sound' (T kxO) (T kyO) -- We can check if two elements of a limit (in `Type`) -- are equal by comparing them componentwise. ext j -- Now it's just a calculation using `W` and `w`. simp only [Functor.comp_map, Limit.map_π_apply, curry_obj_map_app, swap_map] rw [← W _ _ (fH j), ← W _ _ (gH j)] -- Porting note(#10745): had to add `Limit.map_π_apply` -- (which was un-tagged simp since "simp can prove it") simp [Limit.map_π_apply, w] end end section variable {J : Type u₁} {K : Type u₂} [SmallCategory J] [Category.{v₂} K] [Small.{v} K] variable [FinCategory J] variable (F : J × K ⥤ Type v) open CategoryTheory.Prod variable [IsFiltered K] /-- This follows this proof from * Borceux, Handbook of categorical algebra 1, Theorem 2.13.4 although with different names. -/ theorem colimitLimitToLimitColimit_surjective : Function.Surjective (colimitLimitToLimitColimit F) := by classical -- We begin with some element `x` in the limit (over J) over the colimits (over K), intro x -- This consists of some coherent family of elements in the various colimits, -- and so our first task is to pick representatives of these elements. have z := fun j => jointly_surjective' (limit.π (curry.obj F ⋙ Limits.colim) j x) -- `k : J ⟶ K` records where the representative of the -- element in the `j`-th element of `x` lives let k : J → K := fun j => (z j).choose -- `y j : F.obj (j, k j)` is the representative let y : ∀ j, F.obj (j, k j) := fun j => (z j).choose_spec.choose -- and we record that these representatives, when mapped back into the relevant colimits, -- are actually the components of `x`. have e : ∀ j, colimit.ι ((curry.obj F).obj j) (k j) (y j) = limit.π (curry.obj F ⋙ Limits.colim) j x := fun j => (z j).choose_spec.choose_spec clear_value k y -- A little tidying up of things we no longer need. clear z -- As a first step, we use that `K` is filtered to pick some point `k' : K` above all the `k j` let k' : K := IsFiltered.sup (Finset.univ.image k) ∅ -- and name the morphisms as `g j : k j ⟶ k'`. have g : ∀ j, k j ⟶ k' := fun j => IsFiltered.toSup (Finset.univ.image k) ∅ (by simp) clear_value k' -- Recalling that the components of `x`, which are indexed by `j : J`, are "coherent", -- in other words preserved by morphisms in the `J` direction, -- we see that for any morphism `f : j ⟶ j'` in `J`, -- the images of `y j` and `y j'`, when mapped to `F.obj (j', k')` respectively by -- `(f, g j)` and `(𝟙 j', g j')`, both represent the same element in the colimit. have w : ∀ {j j' : J} (f : j ⟶ j'), colimit.ι ((curry.obj F).obj j') k' (F.map ((𝟙 j', g j') : (j', k j') ⟶ (j', k')) (y j')) = colimit.ι ((curry.obj F).obj j') k' (F.map ((f, g j) : (j, k j) ⟶ (j', k')) (y j)) := by intro j j' f have t : (f, g j) = (((f, 𝟙 (k j)) : (j, k j) ⟶ (j', k j)) ≫ (𝟙 j', g j) : (j, k j) ⟶ (j', k')) := by simp only [id_comp, comp_id, prod_comp] erw [Colimit.w_apply, t, FunctorToTypes.map_comp_apply, Colimit.w_apply, e, ← Limit.w_apply.{u₁, v, u₁} f, ← e] simp only [Functor.comp_map, Types.Colimit.ι_map_apply, curry_obj_map_app] -- Because `K` is filtered, we can restate this as saying that -- for each such `f`, there is some place to the right of `k'` -- where these images of `y j` and `y j'` become equal. simp_rw [colimit_eq_iff] at w -- We take a moment to restate `w` more conveniently. let kf : ∀ {j j'} (_ : j ⟶ j'), K := fun f => (w f).choose let gf : ∀ {j j'} (f : j ⟶ j'), k' ⟶ kf f := fun f => (w f).choose_spec.choose let hf : ∀ {j j'} (f : j ⟶ j'), k' ⟶ kf f := fun f => (w f).choose_spec.choose_spec.choose have wf : ∀ {j j'} (f : j ⟶ j'), F.map ((𝟙 j', g j' ≫ gf f) : (j', k j') ⟶ (j', kf f)) (y j') = F.map ((f, g j ≫ hf f) : (j, k j) ⟶ (j', kf f)) (y j) := fun {j j'} f => by have q : ((curry.obj F).obj j').map (gf f) (F.map ((𝟙 j', g j') : (j', k j') ⟶ (j', k')) (y j')) = ((curry.obj F).obj j').map (hf f) (F.map ((f, g j) : (j, k j) ⟶ (j', k')) (y j)) := (w f).choose_spec.choose_spec.choose_spec rw [curry_obj_obj_map, curry_obj_obj_map] at q -- Porting note: Lean 4 `dsimp` unfolds `gf` and `hf` in `q` :-( -- See discussion at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.60dsimp.60.20unfolding.20local.20lets simp_rw [← FunctorToTypes.map_comp_apply, CategoryStruct.comp] at q convert q <;> simp only [comp_id] clear_value kf gf hf -- and clean up some things that are no longer needed. clear w -- We're now ready to use the fact that `K` is filtered a second time, -- picking some place to the right of all of -- the morphisms `gf f : k' ⟶ kh f` and `hf f : k' ⟶ kf f`. -- At this point we're relying on there being only finitely morphisms in `J`. let O := (Finset.univ.biUnion fun j => Finset.univ.biUnion fun j' => Finset.univ.image (@kf j j')) ∪ {k'} have kfO : ∀ {j j'} (f : j ⟶ j'), kf f ∈ O := fun {j} {j'} f => Finset.mem_union.mpr (Or.inl (Finset.mem_biUnion.mpr ⟨j, Finset.mem_univ j, Finset.mem_biUnion.mpr ⟨j', Finset.mem_univ j', Finset.mem_image.mpr ⟨f, Finset.mem_univ _, rfl⟩⟩⟩)) have k'O : k' ∈ O := Finset.mem_union.mpr (Or.inr (Finset.mem_singleton.mpr rfl)) let H : Finset (Σ' (X Y : K) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) := Finset.univ.biUnion fun j : J => Finset.univ.biUnion fun j' : J => Finset.univ.biUnion fun f : j ⟶ j' => {⟨k', kf f, k'O, kfO f, gf f⟩, ⟨k', kf f, k'O, kfO f, hf f⟩} obtain ⟨k'', i', s'⟩ := IsFiltered.sup_exists O H -- We then restate this slightly more conveniently, as a family of morphism `i f : kf f ⟶ k''`, -- satisfying `gf f ≫ i f = hf f' ≫ i f'`. let i : ∀ {j j'} (f : j ⟶ j'), kf f ⟶ k'' := fun {j} {j'} f => i' (kfO f) have s : ∀ {j₁ j₂ j₃ j₄} (f : j₁ ⟶ j₂) (f' : j₃ ⟶ j₄), gf f ≫ i f = hf f' ≫ i f' := by intros j₁ j₂ j₃ j₄ f f' rw [s', s'] -- Porting note: the three goals here in Lean 3 were in a different order · exact k'O · exact Finset.mem_biUnion.mpr ⟨j₃, Finset.mem_univ _, Finset.mem_biUnion.mpr ⟨j₄, Finset.mem_univ _, Finset.mem_biUnion.mpr ⟨f', Finset.mem_univ _, by -- This works by `simp`, but has very high variation in heartbeats. rw [Finset.mem_insert, PSigma.mk.injEq, heq_eq_eq, PSigma.mk.injEq, heq_eq_eq, PSigma.mk.injEq, heq_eq_eq, PSigma.mk.injEq, heq_eq_eq, eq_self, true_and, eq_self, true_and, eq_self, true_and, eq_self, true_and, Finset.mem_singleton, eq_self, or_true] trivial⟩⟩⟩ · exact Finset.mem_biUnion.mpr ⟨j₁, Finset.mem_univ _, Finset.mem_biUnion.mpr ⟨j₂, Finset.mem_univ _, Finset.mem_biUnion.mpr ⟨f, Finset.mem_univ _, by -- This works by `simp`, but has very high variation in heartbeats. rw [Finset.mem_insert, PSigma.mk.injEq, heq_eq_eq, PSigma.mk.injEq, heq_eq_eq, PSigma.mk.injEq, heq_eq_eq, PSigma.mk.injEq, heq_eq_eq, eq_self, true_and, eq_self, true_and, eq_self, true_and, eq_self, true_and, Finset.mem_singleton, eq_self, true_or] trivial⟩⟩⟩ clear_value i clear s' i' H kfO k'O O -- We're finally ready to construct the pre-image, and verify it really maps to `x`. -- ⊢ ∃ a, colimitLimitToLimitColimit F a = x fconstructor · -- We construct the pre-image (which, recall is meant to be a point -- in the colimit (over `K`) of the limits (over `J`)) via a representative at `k''`. apply colimit.ι (curry.obj (swap K J ⋙ F) ⋙ Limits.lim) k'' _ dsimp -- This representative is meant to be an element of a limit, -- so we need to construct a family of elements in `F.obj (j, k'')` for varying `j`, -- then show that are coherent with respect to morphisms in the `j` direction. apply Limit.mk swap ·-- We construct the elements as the images of the `y j`. exact fun j => F.map (⟨𝟙 j, g j ≫ gf (𝟙 j) ≫ i (𝟙 j)⟩ : (j, k j) ⟶ (j, k'')) (y j) · -- After which it's just a calculation, using `s` and `wf`, to see they are coherent. dsimp intro j j' f simp only [← FunctorToTypes.map_comp_apply, prod_comp, id_comp, comp_id] calc F.map ((f, g j ≫ gf (𝟙 j) ≫ i (𝟙 j)) : (j, k j) ⟶ (j', k'')) (y j) = F.map ((f, g j ≫ hf f ≫ i f) : (j, k j) ⟶ (j', k'')) (y j) := by rw [s (𝟙 j) f] _ = F.map ((𝟙 j', i f) : (j', kf f) ⟶ (j', k'')) (F.map ((f, g j ≫ hf f) : (j, k j) ⟶ (j', kf f)) (y j)) := by rw [← FunctorToTypes.map_comp_apply, prod_comp, comp_id, assoc] _ = F.map ((𝟙 j', i f) : (j', kf f) ⟶ (j', k'')) (F.map ((𝟙 j', g j' ≫ gf f) : (j', k j') ⟶ (j', kf f)) (y j')) := by rw [← wf f] _ = F.map ((𝟙 j', g j' ≫ gf f ≫ i f) : (j', k j') ⟶ (j', k'')) (y j') := by rw [← FunctorToTypes.map_comp_apply, prod_comp, id_comp, assoc] _ = F.map ((𝟙 j', g j' ≫ gf (𝟙 j') ≫ i (𝟙 j')) : (j', k j') ⟶ (j', k'')) (y j') := by rw [s f (𝟙 j'), ← s (𝟙 j') (𝟙 j')] -- Finally we check that this maps to `x`. · -- We can do this componentwise: apply limit_ext intro j -- and as each component is an equation in a colimit, we can verify it by -- pointing out the morphism which carries one representative to the other: simp only [id, ← e, Limits.ι_colimitLimitToLimitColimit_π_apply, colimit_eq_iff, Bifunctor.map_id_comp, types_comp_apply, curry_obj_obj_map, Functor.comp_obj, colim_obj, Limit.π_mk] refine ⟨k'', 𝟙 k'', g j ≫ gf (𝟙 j) ≫ i (𝟙 j), ?_⟩ -- Porting note: the lean 3 proof finished with -- `simp only [Bifunctor.map_id_comp, types_comp_apply, Bifunctor.map_id, types_id_apply]` -- which doesn't work; the corresponding `rw` works fine: rw [Bifunctor.map_id_comp, Bifunctor.map_id_comp, types_comp_apply, types_comp_apply, Bifunctor.map_id, types_id_apply] instance colimitLimitToLimitColimit_isIso : IsIso (colimitLimitToLimitColimit F) := (isIso_iff_bijective _).mpr ⟨colimitLimitToLimitColimit_injective F, colimitLimitToLimitColimit_surjective F⟩ instance colimitLimitToLimitColimitCone_iso (F : J ⥤ K ⥤ Type v) : IsIso (colimitLimitToLimitColimitCone F) := by have : IsIso (colimitLimitToLimitColimitCone F).hom := by suffices IsIso (colimitLimitToLimitColimit (uncurry.obj F) ≫ lim.map (whiskerRight (currying.unitIso.app F).inv colim)) by apply IsIso.comp_isIso infer_instance apply Cones.cone_iso_of_hom_iso noncomputable instance filteredColimPreservesFiniteLimitsOfTypes : PreservesFiniteLimits (colim : (K ⥤ Type v) ⥤ _) := by apply preservesFiniteLimitsOfPreservesFiniteLimitsOfSize.{v₂} intro J _ _ refine ⟨fun {F} => ⟨fun {c} hc => IsLimit.ofIsoLimit (limit.isLimit _) ?_⟩⟩ symm trans colim.mapCone (limit.cone F) · exact Functor.mapIso _ (hc.uniqueUpToIso (limit.isLimit F)) · exact asIso (colimitLimitToLimitColimitCone F) variable {C : Type u} [Category.{v} C] [ConcreteCategory.{v} C] section variable [HasLimitsOfShape J C] [HasColimitsOfShape K C] variable [ReflectsLimitsOfShape J (forget C)] [PreservesColimitsOfShape K (forget C)] variable [PreservesLimitsOfShape J (forget C)] noncomputable instance filteredColimPreservesFiniteLimits : PreservesLimitsOfShape J (colim : (K ⥤ C) ⥤ _) := haveI : PreservesLimitsOfShape J ((colim : (K ⥤ C) ⥤ _) ⋙ forget C) := preservesLimitsOfShapeOfNatIso (preservesColimitNatIso _).symm preservesLimitsOfShapeOfReflectsOfPreserves _ (forget C) end attribute [local instance] reflectsLimitsOfShapeOfReflectsIsomorphisms noncomputable instance [PreservesFiniteLimits (forget C)] [PreservesColimitsOfShape K (forget C)] [HasFiniteLimits C] [HasColimitsOfShape K C] [(forget C).ReflectsIsomorphisms] : PreservesFiniteLimits (colim : (K ⥤ C) ⥤ _) := by apply preservesFiniteLimitsOfPreservesFiniteLimitsOfSize.{v} intro J _ _ infer_instance section variable [HasLimitsOfShape J C] [HasColimitsOfShape K C] variable [ReflectsLimitsOfShape J (forget C)] [PreservesColimitsOfShape K (forget C)] variable [PreservesLimitsOfShape J (forget C)] /-- A curried version of the fact that filtered colimits commute with finite limits. -/ noncomputable def colimitLimitIso (F : J ⥤ K ⥤ C) : colimit (limit F) ≅ limit (colimit F.flip) := (isLimitOfPreserves colim (limit.isLimit _)).conePointUniqueUpToIso (limit.isLimit _) ≪≫ HasLimit.isoOfNatIso (colimitFlipIsoCompColim _).symm @[reassoc (attr := simp)] theorem ι_colimitLimitIso_limit_π (F : J ⥤ K ⥤ C) (a) (b) : colimit.ι (limit F) a ≫ (colimitLimitIso F).hom ≫ limit.π (colimit F.flip) b = (limit.π F b).app a ≫ (colimit.ι F.flip a).app b := by dsimp [colimitLimitIso] simp only [Functor.mapCone_π_app, Iso.symm_hom, Limits.limit.conePointUniqueUpToIso_hom_comp_assoc, Limits.limit.cone_π, Limits.colimit.ι_map_assoc, Limits.colimitFlipIsoCompColim_inv_app, assoc, Limits.HasLimit.isoOfNatIso_hom_π] congr 1 simp only [← Category.assoc, Iso.comp_inv_eq, Limits.colimitObjIsoColimitCompEvaluation_ι_app_hom, Limits.HasColimit.isoOfNatIso_ι_hom, NatIso.ofComponents_hom_app] dsimp simp end end end CategoryTheory.Limits
CategoryTheory\Limits\Final.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Comma.StructuredArrow import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.Types import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.PUnit /-! # Final and initial functors A functor `F : C ⥤ D` is final if for every `d : D`, the comma category of morphisms `d ⟶ F.obj c` is connected. Dually, a functor `F : C ⥤ D` is initial if for every `d : D`, the comma category of morphisms `F.obj c ⟶ d` is connected. We show that right adjoints are examples of final functors, while left adjoints are examples of initial functors. For final functors, we prove that the following three statements are equivalent: 1. `F : C ⥤ D` is final. 2. Every functor `G : D ⥤ E` has a colimit if and only if `F ⋙ G` does, and these colimits are isomorphic via `colimit.pre G F`. 3. `colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit`. Starting at 1. we show (in `coconesEquiv`) that the categories of cocones over `G : D ⥤ E` and over `F ⋙ G` are equivalent. (In fact, via an equivalence which does not change the cocone point.) This readily implies 2., as `comp_hasColimit`, `hasColimit_of_comp`, and `colimitIso`. From 2. we can specialize to `G = coyoneda.obj (op d)` to obtain 3., as `colimitCompCoyonedaIso`. From 3., we prove 1. directly in `cofinal_of_colimit_comp_coyoneda_iso_pUnit`. Dually, we prove that if a functor `F : C ⥤ D` is initial, then any functor `G : D ⥤ E` has a limit if and only if `F ⋙ G` does, and these limits are isomorphic via `limit.pre G F`. ## Naming There is some discrepancy in the literature about naming; some say 'cofinal' instead of 'final'. The explanation for this is that the 'co' prefix here is *not* the usual category-theoretic one indicating duality, but rather indicating the sense of "along with". ## See also In `CategoryTheory.Filtered.Final` we give additional equivalent conditions in the case that `C` is filtered. ## Future work Dualise condition 3 above and the implications 2 ⇒ 3 and 3 ⇒ 1 to initial functors. ## References * https://stacks.math.columbia.edu/tag/09WN * https://ncatlab.org/nlab/show/final+functor * Borceux, Handbook of Categorical Algebra I, Section 2.11. (Note he reverses the roles of definition and main result relative to here!) -/ noncomputable section universe v v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory namespace Functor open Opposite open CategoryTheory.Limits section ArbitraryUniverse variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] /-- A functor `F : C ⥤ D` is final if for every `d : D`, the comma category of morphisms `d ⟶ F.obj c` is connected. See <https://stacks.math.columbia.edu/tag/04E6> -/ class Final (F : C ⥤ D) : Prop where out (d : D) : IsConnected (StructuredArrow d F) attribute [instance] Final.out /-- A functor `F : C ⥤ D` is initial if for every `d : D`, the comma category of morphisms `F.obj c ⟶ d` is connected. -/ class Initial (F : C ⥤ D) : Prop where out (d : D) : IsConnected (CostructuredArrow F d) attribute [instance] Initial.out instance final_op_of_initial (F : C ⥤ D) [Initial F] : Final F.op where out d := isConnected_of_equivalent (costructuredArrowOpEquivalence F (unop d)) instance initial_op_of_final (F : C ⥤ D) [Final F] : Initial F.op where out d := isConnected_of_equivalent (structuredArrowOpEquivalence F (unop d)) theorem final_of_initial_op (F : C ⥤ D) [Initial F.op] : Final F := { out := fun d => @isConnected_of_isConnected_op _ _ (isConnected_of_equivalent (structuredArrowOpEquivalence F d).symm) } theorem initial_of_final_op (F : C ⥤ D) [Final F.op] : Initial F := { out := fun d => @isConnected_of_isConnected_op _ _ (isConnected_of_equivalent (costructuredArrowOpEquivalence F d).symm) } /-- If a functor `R : D ⥤ C` is a right adjoint, it is final. -/ theorem final_of_adjunction {L : C ⥤ D} {R : D ⥤ C} (adj : L ⊣ R) : Final R := { out := fun c => let u : StructuredArrow c R := StructuredArrow.mk (adj.unit.app c) @zigzag_isConnected _ _ ⟨u⟩ fun f g => Relation.ReflTransGen.trans (Relation.ReflTransGen.single (show Zag f u from Or.inr ⟨StructuredArrow.homMk ((adj.homEquiv c f.right).symm f.hom) (by simp [u])⟩)) (Relation.ReflTransGen.single (show Zag u g from Or.inl ⟨StructuredArrow.homMk ((adj.homEquiv c g.right).symm g.hom) (by simp [u])⟩)) } /-- If a functor `L : C ⥤ D` is a left adjoint, it is initial. -/ theorem initial_of_adjunction {L : C ⥤ D} {R : D ⥤ C} (adj : L ⊣ R) : Initial L := { out := fun d => let u : CostructuredArrow L d := CostructuredArrow.mk (adj.counit.app d) @zigzag_isConnected _ _ ⟨u⟩ fun f g => Relation.ReflTransGen.trans (Relation.ReflTransGen.single (show Zag f u from Or.inl ⟨CostructuredArrow.homMk (adj.homEquiv f.left d f.hom) (by simp [u])⟩)) (Relation.ReflTransGen.single (show Zag u g from Or.inr ⟨CostructuredArrow.homMk (adj.homEquiv g.left d g.hom) (by simp [u])⟩)) } instance (priority := 100) final_of_isRightAdjoint (F : C ⥤ D) [IsRightAdjoint F] : Final F := final_of_adjunction (Adjunction.ofIsRightAdjoint F) instance (priority := 100) initial_of_isLeftAdjoint (F : C ⥤ D) [IsLeftAdjoint F] : Initial F := initial_of_adjunction (Adjunction.ofIsLeftAdjoint F) theorem final_of_natIso {F F' : C ⥤ D} [Final F] (i : F ≅ F') : Final F' where out _ := isConnected_of_equivalent (StructuredArrow.mapNatIso i) theorem final_natIso_iff {F F' : C ⥤ D} (i : F ≅ F') : Final F ↔ Final F' := ⟨fun _ => final_of_natIso i, fun _ => final_of_natIso i.symm⟩ theorem initial_of_natIso {F F' : C ⥤ D} [Initial F] (i : F ≅ F') : Initial F' where out _ := isConnected_of_equivalent (CostructuredArrow.mapNatIso i) theorem initial_natIso_iff {F F' : C ⥤ D} (i : F ≅ F') : Initial F ↔ Initial F' := ⟨fun _ => initial_of_natIso i, fun _ => initial_of_natIso i.symm⟩ namespace Final variable (F : C ⥤ D) [Final F] instance (d : D) : Nonempty (StructuredArrow d F) := IsConnected.is_nonempty variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- When `F : C ⥤ D` is cofinal, we denote by `lift F d` an arbitrary choice of object in `C` such that there exists a morphism `d ⟶ F.obj (lift F d)`. -/ def lift (d : D) : C := (Classical.arbitrary (StructuredArrow d F)).right /-- When `F : C ⥤ D` is cofinal, we denote by `homToLift` an arbitrary choice of morphism `d ⟶ F.obj (lift F d)`. -/ def homToLift (d : D) : d ⟶ F.obj (lift F d) := (Classical.arbitrary (StructuredArrow d F)).hom /-- We provide an induction principle for reasoning about `lift` and `homToLift`. We want to perform some construction (usually just a proof) about the particular choices `lift F d` and `homToLift F d`, it suffices to perform that construction for some other pair of choices (denoted `X₀ : C` and `k₀ : d ⟶ F.obj X₀` below), and to show how to transport such a construction *both* directions along a morphism between such choices. -/ def induction {d : D} (Z : ∀ (X : C) (_ : d ⟶ F.obj X), Sort*) (h₁ : ∀ (X₁ X₂) (k₁ : d ⟶ F.obj X₁) (k₂ : d ⟶ F.obj X₂) (f : X₁ ⟶ X₂), k₁ ≫ F.map f = k₂ → Z X₁ k₁ → Z X₂ k₂) (h₂ : ∀ (X₁ X₂) (k₁ : d ⟶ F.obj X₁) (k₂ : d ⟶ F.obj X₂) (f : X₁ ⟶ X₂), k₁ ≫ F.map f = k₂ → Z X₂ k₂ → Z X₁ k₁) {X₀ : C} {k₀ : d ⟶ F.obj X₀} (z : Z X₀ k₀) : Z (lift F d) (homToLift F d) := by apply Nonempty.some apply @isPreconnected_induction _ _ _ (fun Y : StructuredArrow d F => Z Y.right Y.hom) _ _ (StructuredArrow.mk k₀) z · intro j₁ j₂ f a fapply h₁ _ _ _ _ f.right _ a convert f.w.symm dsimp simp · intro j₁ j₂ f a fapply h₂ _ _ _ _ f.right _ a convert f.w.symm dsimp simp variable {F G} /-- Given a cocone over `F ⋙ G`, we can construct a `Cocone G` with the same cocone point. -/ @[simps] def extendCocone : Cocone (F ⋙ G) ⥤ Cocone G where obj c := { pt := c.pt ι := { app := fun X => G.map (homToLift F X) ≫ c.ι.app (lift F X) naturality := fun X Y f => by dsimp; simp -- This would be true if we'd chosen `lift F X` to be `lift F Y` -- and `homToLift F X` to be `f ≫ homToLift F Y`. apply induction F fun Z k => G.map f ≫ G.map (homToLift F Y) ≫ c.ι.app (lift F Y) = G.map k ≫ c.ι.app Z · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, Category.assoc, ← Functor.comp_map, c.w, z] · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, Category.assoc, ← Functor.comp_map, c.w] at z rw [z] · rw [← Functor.map_comp_assoc] } } map f := { hom := f.hom } @[simp] theorem colimit_cocone_comp_aux (s : Cocone (F ⋙ G)) (j : C) : G.map (homToLift F (F.obj j)) ≫ s.ι.app (lift F (F.obj j)) = s.ι.app j := by -- This point is that this would be true if we took `lift (F.obj j)` to just be `j` -- and `homToLift (F.obj j)` to be `𝟙 (F.obj j)`. apply induction F fun X k => G.map k ≫ s.ι.app X = (s.ι.app j : _) · intro j₁ j₂ k₁ k₂ f w h rw [← w] rw [← s.w f] at h simpa using h · intro j₁ j₂ k₁ k₂ f w h rw [← w] at h rw [← s.w f] simpa using h · exact s.w (𝟙 _) variable (F G) /-- If `F` is cofinal, the category of cocones on `F ⋙ G` is equivalent to the category of cocones on `G`, for any `G : D ⥤ E`. -/ @[simps] def coconesEquiv : Cocone (F ⋙ G) ≌ Cocone G where functor := extendCocone inverse := Cocones.whiskering F unitIso := NatIso.ofComponents fun c => Cocones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun c => Cocones.ext (Iso.refl _) variable {G} /-- When `F : C ⥤ D` is cofinal, and `t : Cocone G` for some `G : D ⥤ E`, `t.whisker F` is a colimit cocone exactly when `t` is. -/ def isColimitWhiskerEquiv (t : Cocone G) : IsColimit (t.whisker F) ≃ IsColimit t := IsColimit.ofCoconeEquiv (coconesEquiv F G).symm /-- When `F` is cofinal, and `t : Cocone (F ⋙ G)`, `extendCocone.obj t` is a colimit cocone exactly when `t` is. -/ def isColimitExtendCoconeEquiv (t : Cocone (F ⋙ G)) : IsColimit (extendCocone.obj t) ≃ IsColimit t := IsColimit.ofCoconeEquiv (coconesEquiv F G) /-- Given a colimit cocone over `G : D ⥤ E` we can construct a colimit cocone over `F ⋙ G`. -/ @[simps] def colimitCoconeComp (t : ColimitCocone G) : ColimitCocone (F ⋙ G) where cocone := _ isColimit := (isColimitWhiskerEquiv F _).symm t.isColimit instance (priority := 100) comp_hasColimit [HasColimit G] : HasColimit (F ⋙ G) := HasColimit.mk (colimitCoconeComp F (getColimitCocone G)) instance colimit_pre_isIso [HasColimit G] : IsIso (colimit.pre G F) := by rw [colimit.pre_eq (colimitCoconeComp F (getColimitCocone G)) (getColimitCocone G)] erw [IsColimit.desc_self] dsimp infer_instance section variable (G) /-- When `F : C ⥤ D` is cofinal, and `G : D ⥤ E` has a colimit, then `F ⋙ G` has a colimit also and `colimit (F ⋙ G) ≅ colimit G` https://stacks.math.columbia.edu/tag/04E7 -/ def colimitIso [HasColimit G] : colimit (F ⋙ G) ≅ colimit G := asIso (colimit.pre G F) end /-- Given a colimit cocone over `F ⋙ G` we can construct a colimit cocone over `G`. -/ @[simps] def colimitCoconeOfComp (t : ColimitCocone (F ⋙ G)) : ColimitCocone G where cocone := extendCocone.obj t.cocone isColimit := (isColimitExtendCoconeEquiv F _).symm t.isColimit /-- When `F` is cofinal, and `F ⋙ G` has a colimit, then `G` has a colimit also. We can't make this an instance, because `F` is not determined by the goal. (Even if this weren't a problem, it would cause a loop with `comp_hasColimit`.) -/ theorem hasColimit_of_comp [HasColimit (F ⋙ G)] : HasColimit G := HasColimit.mk (colimitCoconeOfComp F (getColimitCocone (F ⋙ G))) theorem hasColimitsOfShape_of_final [HasColimitsOfShape C E] : HasColimitsOfShape D E where has_colimit := fun _ => hasColimit_of_comp F section -- Porting note: this instance does not seem to be found automatically --attribute [local instance] hasColimit_of_comp /-- When `F` is cofinal, and `F ⋙ G` has a colimit, then `G` has a colimit also and `colimit (F ⋙ G) ≅ colimit G` https://stacks.math.columbia.edu/tag/04E7 -/ def colimitIso' [HasColimit (F ⋙ G)] : haveI : HasColimit G := hasColimit_of_comp F colimit (F ⋙ G) ≅ colimit G := haveI : HasColimit G := hasColimit_of_comp F asIso (colimit.pre G F) end end Final end ArbitraryUniverse section LocallySmall variable {C : Type v} [Category.{v} C] {D : Type u₁} [Category.{v} D] (F : C ⥤ D) namespace Final theorem zigzag_of_eqvGen_quot_rel {F : C ⥤ D} {d : D} {f₁ f₂ : ΣX, d ⟶ F.obj X} (t : EqvGen (Types.Quot.Rel.{v, v} (F ⋙ coyoneda.obj (op d))) f₁ f₂) : Zigzag (StructuredArrow.mk f₁.2) (StructuredArrow.mk f₂.2) := by induction t with | rel x y r => obtain ⟨f, w⟩ := r fconstructor swap · fconstructor left; fconstructor exact StructuredArrow.homMk f | refl => fconstructor | symm x y _ ih => apply zigzag_symmetric exact ih | trans x y z _ _ ih₁ ih₂ => apply Relation.ReflTransGen.trans · exact ih₁ · exact ih₂ end Final /-- If `colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit` for all `d : D`, then `F` is cofinal. -/ theorem cofinal_of_colimit_comp_coyoneda_iso_pUnit (I : ∀ d, colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit) : Final F := ⟨fun d => by have : Nonempty (StructuredArrow d F) := by have := (I d).inv PUnit.unit obtain ⟨j, y, rfl⟩ := Limits.Types.jointly_surjective'.{v, v} this exact ⟨StructuredArrow.mk y⟩ apply zigzag_isConnected rintro ⟨⟨⟨⟩⟩, X₁, f₁⟩ ⟨⟨⟨⟩⟩, X₂, f₂⟩ let y₁ := colimit.ι (F ⋙ coyoneda.obj (op d)) X₁ f₁ let y₂ := colimit.ι (F ⋙ coyoneda.obj (op d)) X₂ f₂ have e : y₁ = y₂ := by apply (I d).toEquiv.injective ext have t := Types.colimit_eq.{v, v} e clear e y₁ y₂ exact Final.zigzag_of_eqvGen_quot_rel t⟩ /-- A variant of `cofinal_of_colimit_comp_coyoneda_iso_pUnit` where we bind the various claims about `colimit (F ⋙ coyoneda.obj (Opposite.op d))` for each `d : D` into a single claim about the presheaf `colimit (F ⋙ yoneda)`. -/ theorem cofinal_of_isTerminal_colimit_comp_yoneda (h : IsTerminal (colimit (F ⋙ yoneda))) : Final F := by refine cofinal_of_colimit_comp_coyoneda_iso_pUnit _ (fun d => ?_) refine Types.isTerminalEquivIsoPUnit _ ?_ let b := IsTerminal.isTerminalObj ((evaluation _ _).obj (Opposite.op d)) _ h exact b.ofIso <| preservesColimitIso ((evaluation _ _).obj (Opposite.op d)) (F ⋙ yoneda) /-- If the universal morphism `colimit (F ⋙ coyoneda.obj (op d)) ⟶ colimit (coyoneda.obj (op d))` is an isomorphism (as it always is when `F` is cofinal), then `colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit` (simply because `colimit (coyoneda.obj (op d)) ≅ PUnit`). -/ def Final.colimitCompCoyonedaIso (d : D) [IsIso (colimit.pre (coyoneda.obj (op d)) F)] : colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit := asIso (colimit.pre (coyoneda.obj (op d)) F) ≪≫ Coyoneda.colimitCoyonedaIso (op d) end LocallySmall section SmallCategory variable {C : Type v} [Category.{v} C] {D : Type v} [Category.{v} D] (F : C ⥤ D) theorem final_iff_isIso_colimit_pre : Final F ↔ ∀ G : D ⥤ Type v, IsIso (colimit.pre G F) := ⟨fun _ => inferInstance, fun _ => cofinal_of_colimit_comp_coyoneda_iso_pUnit _ fun _ => Final.colimitCompCoyonedaIso _ _⟩ end SmallCategory namespace Initial variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) [Initial F] instance (d : D) : Nonempty (CostructuredArrow F d) := IsConnected.is_nonempty variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- When `F : C ⥤ D` is initial, we denote by `lift F d` an arbitrary choice of object in `C` such that there exists a morphism `F.obj (lift F d) ⟶ d`. -/ def lift (d : D) : C := (Classical.arbitrary (CostructuredArrow F d)).left /-- When `F : C ⥤ D` is initial, we denote by `homToLift` an arbitrary choice of morphism `F.obj (lift F d) ⟶ d`. -/ def homToLift (d : D) : F.obj (lift F d) ⟶ d := (Classical.arbitrary (CostructuredArrow F d)).hom /-- We provide an induction principle for reasoning about `lift` and `homToLift`. We want to perform some construction (usually just a proof) about the particular choices `lift F d` and `homToLift F d`, it suffices to perform that construction for some other pair of choices (denoted `X₀ : C` and `k₀ : F.obj X₀ ⟶ d` below), and to show how to transport such a construction *both* directions along a morphism between such choices. -/ def induction {d : D} (Z : ∀ (X : C) (_ : F.obj X ⟶ d), Sort*) (h₁ : ∀ (X₁ X₂) (k₁ : F.obj X₁ ⟶ d) (k₂ : F.obj X₂ ⟶ d) (f : X₁ ⟶ X₂), F.map f ≫ k₂ = k₁ → Z X₁ k₁ → Z X₂ k₂) (h₂ : ∀ (X₁ X₂) (k₁ : F.obj X₁ ⟶ d) (k₂ : F.obj X₂ ⟶ d) (f : X₁ ⟶ X₂), F.map f ≫ k₂ = k₁ → Z X₂ k₂ → Z X₁ k₁) {X₀ : C} {k₀ : F.obj X₀ ⟶ d} (z : Z X₀ k₀) : Z (lift F d) (homToLift F d) := by apply Nonempty.some apply @isPreconnected_induction _ _ _ (fun Y : CostructuredArrow F d => Z Y.left Y.hom) _ _ (CostructuredArrow.mk k₀) z · intro j₁ j₂ f a fapply h₁ _ _ _ _ f.left _ a convert f.w dsimp simp · intro j₁ j₂ f a fapply h₂ _ _ _ _ f.left _ a convert f.w dsimp simp variable {F G} /-- Given a cone over `F ⋙ G`, we can construct a `Cone G` with the same cocone point. -/ @[simps] def extendCone : Cone (F ⋙ G) ⥤ Cone G where obj c := { pt := c.pt π := { app := fun d => c.π.app (lift F d) ≫ G.map (homToLift F d) naturality := fun X Y f => by dsimp; simp -- This would be true if we'd chosen `lift F Y` to be `lift F X` -- and `homToLift F Y` to be `homToLift F X ≫ f`. apply induction F fun Z k => (c.π.app Z ≫ G.map k : c.pt ⟶ _) = c.π.app (lift F X) ≫ G.map (homToLift F X) ≫ G.map f · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, ← Functor.comp_map, ← Category.assoc, ← Category.assoc, c.w] at z rw [z, Category.assoc] · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, ← Functor.comp_map, ← Category.assoc, ← Category.assoc, c.w, z, Category.assoc] · rw [← Functor.map_comp] } } map f := { hom := f.hom } @[simp] theorem limit_cone_comp_aux (s : Cone (F ⋙ G)) (j : C) : s.π.app (lift F (F.obj j)) ≫ G.map (homToLift F (F.obj j)) = s.π.app j := by -- This point is that this would be true if we took `lift (F.obj j)` to just be `j` -- and `homToLift (F.obj j)` to be `𝟙 (F.obj j)`. apply induction F fun X k => s.π.app X ≫ G.map k = (s.π.app j : _) · intro j₁ j₂ k₁ k₂ f w h rw [← s.w f] rw [← w] at h simpa using h · intro j₁ j₂ k₁ k₂ f w h rw [← s.w f] at h rw [← w] simpa using h · exact s.w (𝟙 _) variable (F G) /-- If `F` is initial, the category of cones on `F ⋙ G` is equivalent to the category of cones on `G`, for any `G : D ⥤ E`. -/ @[simps] def conesEquiv : Cone (F ⋙ G) ≌ Cone G where functor := extendCone inverse := Cones.whiskering F unitIso := NatIso.ofComponents fun c => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun c => Cones.ext (Iso.refl _) variable {G} /-- When `F : C ⥤ D` is initial, and `t : Cone G` for some `G : D ⥤ E`, `t.whisker F` is a limit cone exactly when `t` is. -/ def isLimitWhiskerEquiv (t : Cone G) : IsLimit (t.whisker F) ≃ IsLimit t := IsLimit.ofConeEquiv (conesEquiv F G).symm /-- When `F` is initial, and `t : Cone (F ⋙ G)`, `extendCone.obj t` is a limit cone exactly when `t` is. -/ def isLimitExtendConeEquiv (t : Cone (F ⋙ G)) : IsLimit (extendCone.obj t) ≃ IsLimit t := IsLimit.ofConeEquiv (conesEquiv F G) /-- Given a limit cone over `G : D ⥤ E` we can construct a limit cone over `F ⋙ G`. -/ @[simps] def limitConeComp (t : LimitCone G) : LimitCone (F ⋙ G) where cone := _ isLimit := (isLimitWhiskerEquiv F _).symm t.isLimit instance (priority := 100) comp_hasLimit [HasLimit G] : HasLimit (F ⋙ G) := HasLimit.mk (limitConeComp F (getLimitCone G)) instance limit_pre_isIso [HasLimit G] : IsIso (limit.pre G F) := by rw [limit.pre_eq (limitConeComp F (getLimitCone G)) (getLimitCone G)] erw [IsLimit.lift_self] dsimp infer_instance section variable (G) /-- When `F : C ⥤ D` is initial, and `G : D ⥤ E` has a limit, then `F ⋙ G` has a limit also and `limit (F ⋙ G) ≅ limit G` https://stacks.math.columbia.edu/tag/04E7 -/ def limitIso [HasLimit G] : limit (F ⋙ G) ≅ limit G := (asIso (limit.pre G F)).symm end /-- Given a limit cone over `F ⋙ G` we can construct a limit cone over `G`. -/ @[simps] def limitConeOfComp (t : LimitCone (F ⋙ G)) : LimitCone G where cone := extendCone.obj t.cone isLimit := (isLimitExtendConeEquiv F _).symm t.isLimit /-- When `F` is initial, and `F ⋙ G` has a limit, then `G` has a limit also. We can't make this an instance, because `F` is not determined by the goal. (Even if this weren't a problem, it would cause a loop with `comp_hasLimit`.) -/ theorem hasLimit_of_comp [HasLimit (F ⋙ G)] : HasLimit G := HasLimit.mk (limitConeOfComp F (getLimitCone (F ⋙ G))) theorem hasLimitsOfShape_of_initial [HasLimitsOfShape C E] : HasLimitsOfShape D E where has_limit := fun _ => hasLimit_of_comp F section -- Porting note: this instance does not seem to be found automatically -- attribute [local instance] hasLimit_of_comp /-- When `F` is initial, and `F ⋙ G` has a limit, then `G` has a limit also and `limit (F ⋙ G) ≅ limit G` https://stacks.math.columbia.edu/tag/04E7 -/ def limitIso' [HasLimit (F ⋙ G)] : haveI : HasLimit G := hasLimit_of_comp F limit (F ⋙ G) ≅ limit G := haveI : HasLimit G := hasLimit_of_comp F (asIso (limit.pre G F)).symm end end Initial section variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] (F : C ⥤ D) (G : D ⥤ E) /-- The hypotheses also imply that `G` is final, see `final_of_comp_full_faithful'`. -/ theorem final_of_comp_full_faithful [Full G] [Faithful G] [Final (F ⋙ G)] : Final F where out d := isConnected_of_equivalent (StructuredArrow.post d F G).asEquivalence.symm /-- The hypotheses also imply that `G` is initial, see `initial_of_comp_full_faithful'`. -/ theorem initial_of_comp_full_faithful [Full G] [Faithful G] [Initial (F ⋙ G)] : Initial F where out d := isConnected_of_equivalent (CostructuredArrow.post F G d).asEquivalence.symm /-- See also the strictly more general `final_comp` below. -/ theorem final_comp_equivalence [Final F] [IsEquivalence G] : Final (F ⋙ G) := let i : F ≅ (F ⋙ G) ⋙ G.inv := isoWhiskerLeft F G.asEquivalence.unitIso have : Final ((F ⋙ G) ⋙ G.inv) := final_of_natIso i final_of_comp_full_faithful (F ⋙ G) G.inv /-- See also the strictly more general `initial_comp` below. -/ theorem initial_comp_equivalence [Initial F] [IsEquivalence G] : Initial (F ⋙ G) := let i : F ≅ (F ⋙ G) ⋙ G.inv := isoWhiskerLeft F G.asEquivalence.unitIso have : Initial ((F ⋙ G) ⋙ G.inv) := initial_of_natIso i initial_of_comp_full_faithful (F ⋙ G) G.inv /-- See also the strictly more general `final_comp` below. -/ theorem final_equivalence_comp [IsEquivalence F] [Final G] : Final (F ⋙ G) where out d := isConnected_of_equivalent (StructuredArrow.pre d F G).asEquivalence.symm /-- See also the strictly more general `inital_comp` below. -/ theorem initial_equivalence_comp [IsEquivalence F] [Initial G] : Initial (F ⋙ G) where out d := isConnected_of_equivalent (CostructuredArrow.pre F G d).asEquivalence.symm /-- See also the strictly more general `final_of_final_comp` below. -/ theorem final_of_equivalence_comp [IsEquivalence F] [Final (F ⋙ G)] : Final G where out d := isConnected_of_equivalent (StructuredArrow.pre d F G).asEquivalence /-- See also the strictly more general `initial_of_initial_comp` below. -/ theorem initial_of_equivalence_comp [IsEquivalence F] [Initial (F ⋙ G)] : Initial G where out d := isConnected_of_equivalent (CostructuredArrow.pre F G d).asEquivalence /-- See also the strictly more general `final_iff_comp_final_full_faithful` below. -/ theorem final_iff_comp_equivalence [IsEquivalence G] : Final F ↔ Final (F ⋙ G) := ⟨fun _ => final_comp_equivalence _ _, fun _ => final_of_comp_full_faithful _ G⟩ /-- See also the strictly more general `final_iff_final_comp` below. -/ theorem final_iff_equivalence_comp [IsEquivalence F] : Final G ↔ Final (F ⋙ G) := ⟨fun _ => final_equivalence_comp _ _, fun _ => final_of_equivalence_comp F _⟩ /-- See also the strictly more general `initial_iff_comp_initial_full_faithful` below. -/ theorem initial_iff_comp_equivalence [IsEquivalence G] : Initial F ↔ Initial (F ⋙ G) := ⟨fun _ => initial_comp_equivalence _ _, fun _ => initial_of_comp_full_faithful _ G⟩ /-- See also the strictly more general `initial_iff_initial_comp` below. -/ theorem initial_iff_equivalence_comp [IsEquivalence F] : Initial G ↔ Initial (F ⋙ G) := ⟨fun _ => initial_equivalence_comp _ _, fun _ => initial_of_equivalence_comp F _⟩ instance final_comp [hF : Final F] [hG : Final G] : Final (F ⋙ G) := by let s₁ : C ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} C := AsSmall.equiv let s₂ : D ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} D := AsSmall.equiv let s₃ : E ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} E := AsSmall.equiv let i : s₁.inverse ⋙ (F ⋙ G) ⋙ s₃.functor ≅ (s₁.inverse ⋙ F ⋙ s₂.functor) ⋙ (s₂.inverse ⋙ G ⋙ s₃.functor) := isoWhiskerLeft (s₁.inverse ⋙ F) (isoWhiskerRight s₂.unitIso (G ⋙ s₃.functor)) rw [final_iff_comp_equivalence (F ⋙ G) s₃.functor, final_iff_equivalence_comp s₁.inverse, final_natIso_iff i, final_iff_isIso_colimit_pre] rw [final_iff_comp_equivalence F s₂.functor, final_iff_equivalence_comp s₁.inverse, final_iff_isIso_colimit_pre] at hF rw [final_iff_comp_equivalence G s₃.functor, final_iff_equivalence_comp s₂.inverse, final_iff_isIso_colimit_pre] at hG intro H rw [← colimit.pre_pre] infer_instance instance initial_comp [Initial F] [Initial G] : Initial (F ⋙ G) := by suffices Final (F ⋙ G).op from initial_of_final_op _ exact final_comp F.op G.op theorem final_of_final_comp [hF : Final F] [hFG : Final (F ⋙ G)] : Final G := by let s₁ : C ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} C := AsSmall.equiv let s₂ : D ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} D := AsSmall.equiv let s₃ : E ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} E := AsSmall.equiv let _i : s₁.inverse ⋙ (F ⋙ G) ⋙ s₃.functor ≅ (s₁.inverse ⋙ F ⋙ s₂.functor) ⋙ (s₂.inverse ⋙ G ⋙ s₃.functor) := isoWhiskerLeft (s₁.inverse ⋙ F) (isoWhiskerRight s₂.unitIso (G ⋙ s₃.functor)) rw [final_iff_comp_equivalence G s₃.functor, final_iff_equivalence_comp s₂.inverse, final_iff_isIso_colimit_pre] rw [final_iff_comp_equivalence F s₂.functor, final_iff_equivalence_comp s₁.inverse, final_iff_isIso_colimit_pre] at hF rw [final_iff_comp_equivalence (F ⋙ G) s₃.functor, final_iff_equivalence_comp s₁.inverse, final_natIso_iff _i, final_iff_isIso_colimit_pre] at hFG intro H replace hFG := hFG H rw [← colimit.pre_pre] at hFG exact IsIso.of_isIso_comp_left (colimit.pre _ (s₁.inverse ⋙ F ⋙ s₂.functor)) _ theorem initial_of_initial_comp [Initial F] [Initial (F ⋙ G)] : Initial G := by suffices Final G.op from initial_of_final_op _ have : Final (F.op ⋙ G.op) := show Final (F ⋙ G).op from inferInstance exact final_of_final_comp F.op G.op /-- The hypotheses also imply that `F` is final, see `final_of_comp_full_faithful`. -/ theorem final_of_comp_full_faithful' [Full G] [Faithful G] [Final (F ⋙ G)] : Final G := have := final_of_comp_full_faithful F G final_of_final_comp F G /-- The hypotheses also imply that `F` is initial, see `initial_of_comp_full_faithful`. -/ theorem initial_of_comp_full_faithful' [Full G] [Faithful G] [Initial (F ⋙ G)] : Initial G := have := initial_of_comp_full_faithful F G initial_of_initial_comp F G theorem final_iff_comp_final_full_faithful [Final G] [Full G] [Faithful G] : Final F ↔ Final (F ⋙ G) := ⟨fun _ => final_comp _ _, fun _ => final_of_comp_full_faithful F G⟩ theorem initial_iff_comp_initial_full_faithful [Initial G] [Full G] [Faithful G] : Initial F ↔ Initial (F ⋙ G) := ⟨fun _ => initial_comp _ _, fun _ => initial_of_comp_full_faithful F G⟩ theorem final_iff_final_comp [Final F] : Final G ↔ Final (F ⋙ G) := ⟨fun _ => final_comp _ _, fun _ => final_of_final_comp F G⟩ theorem initial_iff_initial_comp [Initial F] : Initial G ↔ Initial (F ⋙ G) := ⟨fun _ => initial_comp _ _, fun _ => initial_of_initial_comp F G⟩ end end Functor section Filtered open Functor variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] /-- Final functors preserve filteredness. This can be seen as a generalization of `IsFiltered.of_right_adjoint` (which states that right adjoints preserve filteredness), as right adjoints are always final, see `final_of_adjunction`. -/ theorem IsFilteredOrEmpty.of_final (F : C ⥤ D) [Final F] [IsFilteredOrEmpty C] : IsFilteredOrEmpty D where cocone_objs X Y := ⟨F.obj (IsFiltered.max (Final.lift F X) (Final.lift F Y)), Final.homToLift F X ≫ F.map (IsFiltered.leftToMax _ _), ⟨Final.homToLift F Y ≫ F.map (IsFiltered.rightToMax _ _), trivial⟩⟩ cocone_maps {X Y} f g := by let P : StructuredArrow X F → Prop := fun h => ∃ (Z : C) (q₁ : h.right ⟶ Z) (q₂ : Final.lift F Y ⟶ Z), h.hom ≫ F.map q₁ = f ≫ Final.homToLift F Y ≫ F.map q₂ rsuffices ⟨Z, q₁, q₂, h⟩ : Nonempty (P (StructuredArrow.mk (g ≫ Final.homToLift F Y))) · refine ⟨F.obj (IsFiltered.coeq q₁ q₂), Final.homToLift F Y ≫ F.map (q₁ ≫ IsFiltered.coeqHom q₁ q₂), ?_⟩ conv_lhs => rw [IsFiltered.coeq_condition] simp only [F.map_comp, ← reassoc_of% h, StructuredArrow.mk_hom_eq_self, Category.assoc] have h₀ : P (StructuredArrow.mk (f ≫ Final.homToLift F Y)) := ⟨_, 𝟙 _, 𝟙 _, by simp⟩ refine isPreconnected_induction P ?_ ?_ h₀ _ · rintro U V h ⟨Z, q₁, q₂, hq⟩ obtain ⟨W, q₃, q₄, hq'⟩ := IsFiltered.span q₁ h.right refine ⟨W, q₄, q₂ ≫ q₃, ?_⟩ rw [F.map_comp, ← reassoc_of% hq, ← F.map_comp, hq', F.map_comp, StructuredArrow.w_assoc] · rintro U V h ⟨Z, q₁, q₂, hq⟩ exact ⟨Z, h.right ≫ q₁, q₂, by simp only [F.map_comp, StructuredArrow.w_assoc, hq]⟩ /-- Final functors preserve filteredness. This can be seen as a generalization of `IsFiltered.of_right_adjoint` (which states that right adjoints preserve filteredness), as right adjoints are always final, see `final_of_adjunction`. -/ theorem IsFiltered.of_final (F : C ⥤ D) [Final F] [IsFiltered C] : IsFiltered D := { IsFilteredOrEmpty.of_final F with nonempty := Nonempty.map F.obj IsFiltered.nonempty } /-- Initial functors preserve cofilteredness. This can be seen as a generalization of `IsCofiltered.of_left_adjoint` (which states that left adjoints preserve cofilteredness), as right adjoints are always initial, see `intial_of_adjunction`. -/ theorem IsCofilteredOrEmpty.of_initial (F : C ⥤ D) [Initial F] [IsCofilteredOrEmpty C] : IsCofilteredOrEmpty D := have : IsFilteredOrEmpty Dᵒᵖ := IsFilteredOrEmpty.of_final F.op isCofilteredOrEmpty_of_isFilteredOrEmpty_op _ /-- Initial functors preserve cofilteredness. This can be seen as a generalization of `IsCofiltered.of_left_adjoint` (which states that left adjoints preserve cofilteredness), as right adjoints are always initial, see `intial_of_adjunction`. -/ theorem IsCofiltered.of_initial (F : C ⥤ D) [Initial F] [IsCofiltered C] : IsCofiltered D := have : IsFiltered Dᵒᵖ := IsFiltered.of_final F.op isCofiltered_of_isFiltered_op _ end Filtered end CategoryTheory
CategoryTheory\Limits\FinallySmall.lean
/- Copyright (c) 2023 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Filtered.Final /-! # Finally small categories A category given by `(J : Type u) [Category.{v} J]` is `w`-finally small if there exists a `FinalModel J : Type w` equipped with `[SmallCategory (FinalModel J)]` and a final functor `FinalModel J ⥤ J`. This means that if a category `C` has colimits of size `w` and `J` is `w`-finally small, then `C` has colimits of shape `J`. In this way, the notion of "finally small" can be seen of a generalization of the notion of "essentially small" for indexing categories of colimits. Dually, we have a notion of initially small category. We show that a finally small category admits a small weakly terminal set, i.e., a small set `s` of objects such that from every object there a morphism to a member of `s`. We also show that the converse holds if `J` is filtered. -/ universe w v v₁ u u₁ open CategoryTheory Functor namespace CategoryTheory section FinallySmall variable (J : Type u) [Category.{v} J] /-- A category is `FinallySmall.{w}` if there is a final functor from a `w`-small category. -/ class FinallySmall : Prop where /-- There is a final functor from a small category. -/ final_smallCategory : ∃ (S : Type w) (_ : SmallCategory S) (F : S ⥤ J), Final F /-- Constructor for `FinallySmall C` from an explicit small category witness. -/ theorem FinallySmall.mk' {J : Type u} [Category.{v} J] {S : Type w} [SmallCategory S] (F : S ⥤ J) [Final F] : FinallySmall.{w} J := ⟨S, _, F, inferInstance⟩ /-- An arbitrarily chosen small model for a finally small category. -/ def FinalModel [FinallySmall.{w} J] : Type w := Classical.choose (@FinallySmall.final_smallCategory J _ _) noncomputable instance smallCategoryFinalModel [FinallySmall.{w} J] : SmallCategory (FinalModel J) := Classical.choose (Classical.choose_spec (@FinallySmall.final_smallCategory J _ _)) /-- An arbitrarily chosen final functor `FinalModel J ⥤ J`. -/ noncomputable def fromFinalModel [FinallySmall.{w} J] : FinalModel J ⥤ J := Classical.choose (Classical.choose_spec (Classical.choose_spec (@FinallySmall.final_smallCategory J _ _))) instance final_fromFinalModel [FinallySmall.{w} J] : Final (fromFinalModel J) := Classical.choose_spec (Classical.choose_spec (Classical.choose_spec (@FinallySmall.final_smallCategory J _ _))) theorem finallySmall_of_essentiallySmall [EssentiallySmall.{w} J] : FinallySmall.{w} J := FinallySmall.mk' (equivSmallModel.{w} J).inverse variable {J} variable {K : Type u₁} [Category.{v₁} K] theorem finallySmall_of_final_of_finallySmall [FinallySmall.{w} K] (F : K ⥤ J) [Final F] : FinallySmall.{w} J := suffices Final ((fromFinalModel K) ⋙ F) from .mk' ((fromFinalModel K) ⋙ F) final_comp _ _ theorem finallySmall_of_final_of_essentiallySmall [EssentiallySmall.{w} K] (F : K ⥤ J) [Final F] : FinallySmall.{w} J := have := finallySmall_of_essentiallySmall K finallySmall_of_final_of_finallySmall F end FinallySmall section InitiallySmall variable (J : Type u) [Category.{v} J] /-- A category is `InitiallySmall.{w}` if there is an initial functor from a `w`-small category. -/ class InitiallySmall : Prop where /-- There is an initial functor from a small category. -/ initial_smallCategory : ∃ (S : Type w) (_ : SmallCategory S) (F : S ⥤ J), Initial F /-- Constructor for `InitialSmall C` from an explicit small category witness. -/ theorem InitiallySmall.mk' {J : Type u} [Category.{v} J] {S : Type w} [SmallCategory S] (F : S ⥤ J) [Initial F] : InitiallySmall.{w} J := ⟨S, _, F, inferInstance⟩ /-- An arbitrarily chosen small model for an initially small category. -/ def InitialModel [InitiallySmall.{w} J] : Type w := Classical.choose (@InitiallySmall.initial_smallCategory J _ _) noncomputable instance smallCategoryInitialModel [InitiallySmall.{w} J] : SmallCategory (InitialModel J) := Classical.choose (Classical.choose_spec (@InitiallySmall.initial_smallCategory J _ _)) /-- An arbitrarily chosen initial functor `InitialModel J ⥤ J`. -/ noncomputable def fromInitialModel [InitiallySmall.{w} J] : InitialModel J ⥤ J := Classical.choose (Classical.choose_spec (Classical.choose_spec (@InitiallySmall.initial_smallCategory J _ _))) instance initial_fromInitialModel [InitiallySmall.{w} J] : Initial (fromInitialModel J) := Classical.choose_spec (Classical.choose_spec (Classical.choose_spec (@InitiallySmall.initial_smallCategory J _ _))) theorem initiallySmall_of_essentiallySmall [EssentiallySmall.{w} J] : InitiallySmall.{w} J := InitiallySmall.mk' (equivSmallModel.{w} J).inverse variable {J} variable {K : Type u₁} [Category.{v₁} K] theorem initiallySmall_of_initial_of_initiallySmall [InitiallySmall.{w} K] (F : K ⥤ J) [Initial F] : InitiallySmall.{w} J := suffices Initial ((fromInitialModel K) ⋙ F) from .mk' ((fromInitialModel K) ⋙ F) initial_comp _ _ theorem initiallySmall_of_initial_of_essentiallySmall [EssentiallySmall.{w} K] (F : K ⥤ J) [Initial F] : InitiallySmall.{w} J := have := initiallySmall_of_essentiallySmall K initiallySmall_of_initial_of_initiallySmall F end InitiallySmall section WeaklyTerminal variable (J : Type u) [Category.{v} J] /-- The converse is true if `J` is filtered, see `finallySmall_of_small_weakly_terminal_set`. -/ theorem FinallySmall.exists_small_weakly_terminal_set [FinallySmall.{w} J] : ∃ (s : Set J) (_ : Small.{w} s), ∀ i, ∃ j ∈ s, Nonempty (i ⟶ j) := by refine ⟨Set.range (fromFinalModel J).obj, inferInstance, fun i => ?_⟩ obtain ⟨f⟩ : Nonempty (StructuredArrow i (fromFinalModel J)) := IsConnected.is_nonempty exact ⟨(fromFinalModel J).obj f.right, Set.mem_range_self _, ⟨f.hom⟩⟩ variable {J} in theorem finallySmall_of_small_weakly_terminal_set [IsFilteredOrEmpty J] (s : Set J) [Small.{v} s] (hs : ∀ i, ∃ j ∈ s, Nonempty (i ⟶ j)) : FinallySmall.{v} J := by suffices Functor.Final (fullSubcategoryInclusion (· ∈ s)) from finallySmall_of_final_of_essentiallySmall (fullSubcategoryInclusion (· ∈ s)) refine Functor.final_of_exists_of_isFiltered_of_fullyFaithful _ (fun i => ?_) obtain ⟨j, hj₁, hj₂⟩ := hs i exact ⟨⟨j, hj₁⟩, hj₂⟩ theorem finallySmall_iff_exists_small_weakly_terminal_set [IsFilteredOrEmpty J] : FinallySmall.{v} J ↔ ∃ (s : Set J) (_ : Small.{v} s), ∀ i, ∃ j ∈ s, Nonempty (i ⟶ j) := by refine ⟨fun _ => FinallySmall.exists_small_weakly_terminal_set _, fun h => ?_⟩ rcases h with ⟨s, hs, hs'⟩ exact finallySmall_of_small_weakly_terminal_set s hs' end WeaklyTerminal section WeaklyInitial variable (J : Type u) [Category.{v} J] /-- The converse is true if `J` is cofiltered, see `intiallySmall_of_small_weakly_initial_set`. -/ theorem InitiallySmall.exists_small_weakly_initial_set [InitiallySmall.{w} J] : ∃ (s : Set J) (_ : Small.{w} s), ∀ i, ∃ j ∈ s, Nonempty (j ⟶ i) := by refine ⟨Set.range (fromInitialModel J).obj, inferInstance, fun i => ?_⟩ obtain ⟨f⟩ : Nonempty (CostructuredArrow (fromInitialModel J) i) := IsConnected.is_nonempty exact ⟨(fromInitialModel J).obj f.left, Set.mem_range_self _, ⟨f.hom⟩⟩ variable {J} in theorem initiallySmall_of_small_weakly_initial_set [IsCofilteredOrEmpty J] (s : Set J) [Small.{v} s] (hs : ∀ i, ∃ j ∈ s, Nonempty (j ⟶ i)) : InitiallySmall.{v} J := by suffices Functor.Initial (fullSubcategoryInclusion (· ∈ s)) from initiallySmall_of_initial_of_essentiallySmall (fullSubcategoryInclusion (· ∈ s)) refine Functor.initial_of_exists_of_isCofiltered_of_fullyFaithful _ (fun i => ?_) obtain ⟨j, hj₁, hj₂⟩ := hs i exact ⟨⟨j, hj₁⟩, hj₂⟩ theorem initiallySmall_iff_exists_small_weakly_initial_set [IsCofilteredOrEmpty J] : InitiallySmall.{v} J ↔ ∃ (s : Set J) (_ : Small.{v} s), ∀ i, ∃ j ∈ s, Nonempty (j ⟶ i) := by refine ⟨fun _ => InitiallySmall.exists_small_weakly_initial_set _, fun h => ?_⟩ rcases h with ⟨s, hs, hs'⟩ exact initiallySmall_of_small_weakly_initial_set s hs' end WeaklyInitial namespace Limits theorem hasColimitsOfShape_of_finallySmall (J : Type u) [Category.{v} J] [FinallySmall.{w} J] (C : Type u₁) [Category.{v₁} C] [HasColimitsOfSize.{w, w} C] : HasColimitsOfShape J C := Final.hasColimitsOfShape_of_final (fromFinalModel J) theorem hasLimitsOfShape_of_initiallySmall (J : Type u) [Category.{v} J] [InitiallySmall.{w} J] (C : Type u₁) [Category.{v₁} C] [HasLimitsOfSize.{w, w} C] : HasLimitsOfShape J C := Initial.hasLimitsOfShape_of_initial (fromInitialModel J) end Limits end CategoryTheory
CategoryTheory\Limits\FintypeCat.lean
/- Copyright (c) 2023 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.FintypeCat import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.Data.Finite.Basic /-! # (Co)limits in the category of finite types We show that finite (co)limits exist in `FintypeCat` and that they are preserved by the natural inclusion `FintypeCat.incl`. -/ open CategoryTheory Limits Functor universe u namespace CategoryTheory.Limits.FintypeCat instance {J : Type} [SmallCategory J] (K : J ⥤ FintypeCat.{u}) (j : J) : Finite ((K ⋙ FintypeCat.incl.{u}).obj j) := by simp only [comp_obj, FintypeCat.incl_obj] infer_instance /-- Any functor from a finite category to Types that only involves finite objects, has a finite limit. -/ noncomputable instance finiteLimitOfFiniteDiagram {J : Type} [SmallCategory J] [FinCategory J] (K : J ⥤ Type*) [∀ j, Finite (K.obj j)] : Fintype (limit K) := by have : Fintype (sections K) := Fintype.ofFinite (sections K) exact Fintype.ofEquiv (sections K) (Types.limitEquivSections K).symm noncomputable instance inclusionCreatesFiniteLimits {J : Type} [SmallCategory J] [FinCategory J] : CreatesLimitsOfShape J FintypeCat.incl.{u} where CreatesLimit {K} := createsLimitOfFullyFaithfulOfIso (FintypeCat.of <| limit <| K ⋙ FintypeCat.incl) (Iso.refl _) /- Help typeclass inference to infer creation of finite limits for the forgtful functor. -/ noncomputable instance {J : Type} [SmallCategory J] [FinCategory J] : CreatesLimitsOfShape J (forget FintypeCat) := FintypeCat.inclusionCreatesFiniteLimits instance {J : Type} [SmallCategory J] [FinCategory J] : HasLimitsOfShape J FintypeCat.{u} where has_limit F := hasLimit_of_created F FintypeCat.incl instance hasFiniteLimits : HasFiniteLimits FintypeCat.{u} where out _ := inferInstance noncomputable instance inclusionPreservesFiniteLimits : PreservesFiniteLimits FintypeCat.incl.{u} where preservesFiniteLimits _ := preservesLimitOfShapeOfCreatesLimitsOfShapeAndHasLimitsOfShape FintypeCat.incl /- Help typeclass inference to infer preservation of finite limits for the forgtful functor. -/ noncomputable instance : PreservesFiniteLimits (forget FintypeCat) := FintypeCat.inclusionPreservesFiniteLimits /-- Any functor from a finite category to Types that only involves finite objects, has a finite colimit. -/ noncomputable instance finiteColimitOfFiniteDiagram {J : Type} [SmallCategory J] [FinCategory J] (K : J ⥤ Type*) [∀ j, Finite (K.obj j)] : Fintype (colimit K) := by have : Finite (Types.Quot K) := Quot.finite (Types.Quot.Rel K) have : Fintype (Types.Quot K) := Fintype.ofFinite (Types.Quot K) exact Fintype.ofEquiv (Types.Quot K) (Types.colimitEquivQuot K).symm noncomputable instance inclusionCreatesFiniteColimits {J : Type} [SmallCategory J] [FinCategory J] : CreatesColimitsOfShape J FintypeCat.incl.{u} where CreatesColimit {K} := createsColimitOfFullyFaithfulOfIso (FintypeCat.of <| colimit <| K ⋙ FintypeCat.incl) (Iso.refl _) /- Help typeclass inference to infer creation of finite colimits for the forgtful functor. -/ noncomputable instance {J : Type} [SmallCategory J] [FinCategory J] : CreatesColimitsOfShape J (forget FintypeCat) := FintypeCat.inclusionCreatesFiniteColimits instance {J : Type} [SmallCategory J] [FinCategory J] : HasColimitsOfShape J FintypeCat.{u} where has_colimit F := hasColimit_of_created F FintypeCat.incl instance hasFiniteColimits : HasFiniteColimits FintypeCat.{u} where out _ := inferInstance noncomputable instance inclusionPreservesFiniteColimits : PreservesFiniteColimits FintypeCat.incl.{u} where preservesFiniteColimits _ := preservesColimitOfShapeOfCreatesColimitsOfShapeAndHasColimitsOfShape FintypeCat.incl /- Help typeclass inference to infer preservation of finite colimits for the forgtful functor. -/ noncomputable instance : PreservesFiniteColimits (forget FintypeCat) := FintypeCat.inclusionPreservesFiniteColimits end CategoryTheory.Limits.FintypeCat
CategoryTheory\Limits\Fubini.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Products.Basic import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Products.Bifunctor /-! # A Fubini theorem for categorical (co)limits We prove that $lim_{J × K} G = lim_J (lim_K G(j, -))$ for a functor `G : J × K ⥤ C`, when all the appropriate limits exist. We begin working with a functor `F : J ⥤ K ⥤ C`. We'll write `G : J × K ⥤ C` for the associated "uncurried" functor. In the first part, given a coherent family `D` of limit cones over the functors `F.obj j`, and a cone `c` over `G`, we construct a cone over the cone points of `D`. We then show that if `c` is a limit cone, the constructed cone is also a limit cone. In the second part, we state the Fubini theorem in the setting where limits are provided by suitable `HasLimit` classes. We construct `limitUncurryIsoLimitCompLim F : limit (uncurry.obj F) ≅ limit (F ⋙ lim)` and give simp lemmas characterising it. For convenience, we also provide `limitIsoLimitCurryCompLim G : limit G ≅ limit ((curry.obj G) ⋙ lim)` in terms of the uncurried functor. All statements have their counterpart for colimits. -/ universe v u open CategoryTheory namespace CategoryTheory.Limits variable {J K : Type v} [SmallCategory J] [SmallCategory K] variable {C : Type u} [Category.{v} C] variable (F : J ⥤ K ⥤ C) -- We could try introducing a "dependent functor type" to handle this? /-- A structure carrying a diagram of cones over the functors `F.obj j`. -/ structure DiagramOfCones where /-- For each object, a cone. -/ obj : ∀ j : J, Cone (F.obj j) /-- For each map, a map of cones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (Cones.postcompose (F.map f)).obj (obj j) ⟶ obj j' id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat /-- A structure carrying a diagram of cocones over the functors `F.obj j`. -/ structure DiagramOfCocones where /-- For each object, a cocone. -/ obj : ∀ j : J, Cocone (F.obj j) /-- For each map, a map of cocones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (obj j) ⟶ (Cocones.precompose (F.map f)).obj (obj j') id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat variable {F} /-- Extract the functor `J ⥤ C` consisting of the cone points and the maps between them, from a `DiagramOfCones`. -/ @[simps] def DiagramOfCones.conePoints (D : DiagramOfCones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g /-- Extract the functor `J ⥤ C` consisting of the cocone points and the maps between them, from a `DiagramOfCocones`. -/ @[simps] def DiagramOfCocones.coconePoints (D : DiagramOfCocones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g /-- Given a diagram `D` of limit cones over the `F.obj j`, and a cone over `uncurry.obj F`, we can construct a cone over the diagram consisting of the cone points from `D`. -/ @[simps] def coneOfConeUncurry {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) (c : Cone (uncurry.obj F)) : Cone D.conePoints where pt := c.pt π := { app := fun j => (Q j).lift { pt := c.pt π := { app := fun k => c.π.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.id_comp] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j, k') (𝟙 j, f) dsimp at this simp? at this says simp only [Category.id_comp, Functor.map_id, NatTrans.id_app] at this exact this } } naturality := fun j j' f => (Q j').hom_ext (by dsimp intro k simp only [Limits.ConeMorphism.w, Limits.Cones.postcompose_obj_π, Limits.IsLimit.fac_assoc, Limits.IsLimit.fac, NatTrans.comp_app, Category.id_comp, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } /-- Given a diagram `D` of colimit cocones over the `F.obj j`, and a cocone over `uncurry.obj F`, we can construct a cocone over the diagram consisting of the cocone points from `D`. -/ @[simps] def coconeOfCoconeUncurry {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) (c : Cocone (uncurry.obj F)) : Cocone D.coconePoints where pt := c.pt ι := { app := fun j => (Q j).desc { pt := c.pt ι := { app := fun k => c.ι.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.comp_id] conv_lhs => arg 1; equals (F.map (𝟙 _)).app _ ≫ (F.obj j).map f => simp conv_lhs => arg 1; rw [← uncurry_obj_map F ((𝟙 j,f) : (j,k) ⟶ (j,k'))] rw [c.w] } } naturality := fun j j' f => (Q j).hom_ext (by dsimp intro k simp only [Limits.CoconeMorphism.w_assoc, Limits.Cocones.precompose_obj_ι, Limits.IsColimit.fac_assoc, Limits.IsColimit.fac, NatTrans.comp_app, Category.comp_id, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.ι (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } /-- `coneOfConeUncurry Q c` is a limit cone when `c` is a limit cone. -/ def coneOfConeUncurryIsLimit {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) {c : Cone (uncurry.obj F)} (P : IsLimit c) : IsLimit (coneOfConeUncurry Q c) where lift s := P.lift { pt := s.pt π := { app := fun p => s.π.app p.1 ≫ (D.obj p.1).π.app p.2 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_rhs 3 4 => rw [← NatTrans.naturality] slice_rhs 2 3 => rw [← (D.obj j).π.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k' dsimp at w rw [← w] have n := s.π.naturality fj dsimp at n simp only [Category.id_comp] at n rw [n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt π := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp /-- `coconeOfCoconeUncurry Q c` is a colimit cocone when `c` is a colimit cocone. -/ def coconeOfCoconeUncurryIsColimit {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) {c : Cocone (uncurry.obj F)} (P : IsColimit c) : IsColimit (coconeOfCoconeUncurry Q c) where desc s := P.desc { pt := s.pt ι := { app := fun p => (D.obj p.1).ι.app p.2 ≫ s.ι.app p.1 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_lhs 2 3 => rw [(D.obj j').ι.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k dsimp at w slice_lhs 1 2 => rw [← w] have n := s.ι.naturality fj dsimp at n simp only [Category.comp_id] at n rw [← n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt ι := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp section variable (F) variable [HasLimitsOfShape K C] /-- Given a functor `F : J ⥤ K ⥤ C`, with all needed limits, we can construct a diagram consisting of the limit cone over each functor `F.obj j`, and the universal cone morphisms between these. -/ @[simps] noncomputable def DiagramOfCones.mkOfHasLimits : DiagramOfCones F where obj j := limit.cone (F.obj j) map f := { hom := lim.map (F.map f) } -- Satisfying the inhabited linter. noncomputable instance diagramOfConesInhabited : Inhabited (DiagramOfCones F) := ⟨DiagramOfCones.mkOfHasLimits F⟩ @[simp] theorem DiagramOfCones.mkOfHasLimits_conePoints : (DiagramOfCones.mkOfHasLimits F).conePoints = F ⋙ lim := rfl variable [HasLimit (uncurry.obj F)] variable [HasLimit (F ⋙ lim)] /-- The Fubini theorem for a functor `F : J ⥤ K ⥤ C`, showing that the limit of `uncurry.obj F` can be computed as the limit of the limits of the functors `F.obj j`. -/ noncomputable def limitUncurryIsoLimitCompLim : limit (uncurry.obj F) ≅ limit (F ⋙ lim) := by let c := limit.cone (uncurry.obj F) let P : IsLimit c := limit.isLimit _ let G := DiagramOfCones.mkOfHasLimits F let Q : ∀ j, IsLimit (G.obj j) := fun j => limit.isLimit _ have Q' := coneOfConeUncurryIsLimit Q P have Q'' := limit.isLimit (F ⋙ lim) exact IsLimit.conePointUniqueUpToIso Q' Q'' @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_hom_π_π {j} {k} : (limitUncurryIsoLimitCompLim F).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) := by dsimp [limitUncurryIsoLimitCompLim, IsLimit.conePointUniqueUpToIso, IsLimit.uniqueUpToIso] simp -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_inv_π {j} {k} : (limitUncurryIsoLimitCompLim F).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by rw [← cancel_epi (limitUncurryIsoLimitCompLim F).hom] simp end section variable (F) variable [HasColimitsOfShape K C] /-- Given a functor `F : J ⥤ K ⥤ C`, with all needed colimits, we can construct a diagram consisting of the colimit cocone over each functor `F.obj j`, and the universal cocone morphisms between these. -/ @[simps] noncomputable def DiagramOfCocones.mkOfHasColimits : DiagramOfCocones F where obj j := colimit.cocone (F.obj j) map f := { hom := colim.map (F.map f) } -- Satisfying the inhabited linter. noncomputable instance diagramOfCoconesInhabited : Inhabited (DiagramOfCocones F) := ⟨DiagramOfCocones.mkOfHasColimits F⟩ @[simp] theorem DiagramOfCocones.mkOfHasColimits_coconePoints : (DiagramOfCocones.mkOfHasColimits F).coconePoints = F ⋙ colim := rfl variable [HasColimit (uncurry.obj F)] variable [HasColimit (F ⋙ colim)] /-- The Fubini theorem for a functor `F : J ⥤ K ⥤ C`, showing that the colimit of `uncurry.obj F` can be computed as the colimit of the colimits of the functors `F.obj j`. -/ noncomputable def colimitUncurryIsoColimitCompColim : colimit (uncurry.obj F) ≅ colimit (F ⋙ colim) := by let c := colimit.cocone (uncurry.obj F) let P : IsColimit c := colimit.isColimit _ let G := DiagramOfCocones.mkOfHasColimits F let Q : ∀ j, IsColimit (G.obj j) := fun j => colimit.isColimit _ have Q' := coconeOfCoconeUncurryIsColimit Q P have Q'' := colimit.isColimit (F ⋙ colim) exact IsColimit.coconePointUniqueUpToIso Q' Q'' @[simp, reassoc] theorem colimitUncurryIsoColimitCompColim_ι_ι_inv {j} {k} : colimit.ι (F.obj j) k ≫ colimit.ι (F ⋙ colim) j ≫ (colimitUncurryIsoColimitCompColim F).inv = colimit.ι (uncurry.obj F) (j, k) := by dsimp [colimitUncurryIsoColimitCompColim, IsColimit.coconePointUniqueUpToIso, IsColimit.uniqueUpToIso] simp @[simp, reassoc] theorem colimitUncurryIsoColimitCompColim_ι_hom {j} {k} : colimit.ι _ (j, k) ≫ (colimitUncurryIsoColimitCompColim F).hom = (colimit.ι _ k ≫ colimit.ι (F ⋙ colim) j : _ ⟶ (colimit (F ⋙ colim))) := by rw [← cancel_mono (colimitUncurryIsoColimitCompColim F).inv] simp end section variable (F) [HasLimitsOfShape J C] [HasLimitsOfShape K C] -- With only moderate effort these could be derived if needed: variable [HasLimitsOfShape (J × K) C] [HasLimitsOfShape (K × J) C] /-- The limit of `F.flip ⋙ lim` is isomorphic to the limit of `F ⋙ lim`. -/ noncomputable def limitFlipCompLimIsoLimitCompLim : limit (F.flip ⋙ lim) ≅ limit (F ⋙ lim) := (limitUncurryIsoLimitCompLim _).symm ≪≫ HasLimit.isoOfNatIso (uncurryObjFlip _) ≪≫ HasLimit.isoOfEquivalence (Prod.braiding _ _) (NatIso.ofComponents fun _ => by rfl) ≪≫ limitUncurryIsoLimitCompLim _ -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp, reassoc] theorem limitFlipCompLimIsoLimitCompLim_hom_π_π (j) (k) : (limitFlipCompLimIsoLimitCompLim F).hom ≫ limit.π _ j ≫ limit.π _ k = (limit.π _ k ≫ limit.π _ j : limit (_ ⋙ lim) ⟶ _) := by dsimp [limitFlipCompLimIsoLimitCompLim] simp -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` -- See note [dsimp, simp] @[simp, reassoc] theorem limitFlipCompLimIsoLimitCompLim_inv_π_π (k) (j) : (limitFlipCompLimIsoLimitCompLim F).inv ≫ limit.π _ k ≫ limit.π _ j = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by dsimp [limitFlipCompLimIsoLimitCompLim] simp end section variable (F) [HasColimitsOfShape J C] [HasColimitsOfShape K C] variable [HasColimitsOfShape (J × K) C] [HasColimitsOfShape (K × J) C] /-- The colimit of `F.flip ⋙ colim` is isomorphic to the colimit of `F ⋙ colim`. -/ noncomputable def colimitFlipCompColimIsoColimitCompColim : colimit (F.flip ⋙ colim) ≅ colimit (F ⋙ colim) := (colimitUncurryIsoColimitCompColim _).symm ≪≫ HasColimit.isoOfNatIso (uncurryObjFlip _) ≪≫ HasColimit.isoOfEquivalence (Prod.braiding _ _) (NatIso.ofComponents fun _ => by rfl) ≪≫ colimitUncurryIsoColimitCompColim _ @[simp, reassoc] theorem colimitFlipCompColimIsoColimitCompColim_ι_ι_hom (j) (k) : colimit.ι (F.flip.obj k) j ≫ colimit.ι (F.flip ⋙ colim) k ≫ (colimitFlipCompColimIsoColimitCompColim F).hom = (colimit.ι _ k ≫ colimit.ι (F ⋙ colim) j : _ ⟶ colimit (F⋙ colim)) := by dsimp [colimitFlipCompColimIsoColimitCompColim] slice_lhs 1 3 => simp only [] simp @[simp, reassoc] theorem colimitFlipCompColimIsoColimitCompColim_ι_ι_inv (k) (j) : colimit.ι (F.obj j) k ≫ colimit.ι (F ⋙ colim) j ≫ (colimitFlipCompColimIsoColimitCompColim F).inv = (colimit.ι _ j ≫ colimit.ι (F.flip ⋙ colim) k : _ ⟶ colimit (F.flip ⋙ colim)) := by dsimp [colimitFlipCompColimIsoColimitCompColim] slice_lhs 1 3 => simp only [] simp end variable (G : J × K ⥤ C) section variable [HasLimitsOfShape K C] variable [HasLimit G] variable [HasLimit (curry.obj G ⋙ lim)] /-- The Fubini theorem for a functor `G : J × K ⥤ C`, showing that the limit of `G` can be computed as the limit of the limits of the functors `G.obj (j, _)`. -/ noncomputable def limitIsoLimitCurryCompLim : limit G ≅ limit (curry.obj G ⋙ lim) := by have i : G ≅ uncurry.obj ((@curry J _ K _ C _).obj G) := currying.symm.unitIso.app G haveI : Limits.HasLimit (uncurry.obj ((@curry J _ K _ C _).obj G)) := hasLimitOfIso i trans limit (uncurry.obj ((@curry J _ K _ C _).obj G)) · apply HasLimit.isoOfNatIso i · exact limitUncurryIsoLimitCompLim ((@curry J _ K _ C _).obj G) @[simp, reassoc] theorem limitIsoLimitCurryCompLim_hom_π_π {j} {k} : (limitIsoLimitCurryCompLim G).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) := by set_option tactic.skipAssignedInstances false in simp [limitIsoLimitCurryCompLim, Trans.simple, HasLimit.isoOfNatIso, limitUncurryIsoLimitCompLim] -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp, reassoc] theorem limitIsoLimitCurryCompLim_inv_π {j} {k} : (limitIsoLimitCurryCompLim G).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by rw [← cancel_epi (limitIsoLimitCurryCompLim G).hom] simp end section variable [HasColimitsOfShape K C] variable [HasColimit G] variable [HasColimit (curry.obj G ⋙ colim)] /-- The Fubini theorem for a functor `G : J × K ⥤ C`, showing that the colimit of `G` can be computed as the colimit of the colimits of the functors `G.obj (j, _)`. -/ noncomputable def colimitIsoColimitCurryCompColim : colimit G ≅ colimit (curry.obj G ⋙ colim) := by have i : G ≅ uncurry.obj ((@curry J _ K _ C _).obj G) := currying.symm.unitIso.app G haveI : Limits.HasColimit (uncurry.obj ((@curry J _ K _ C _).obj G)) := hasColimitOfIso i.symm trans colimit (uncurry.obj ((@curry J _ K _ C _).obj G)) · apply HasColimit.isoOfNatIso i · exact colimitUncurryIsoColimitCompColim ((@curry J _ K _ C _).obj G) @[simp, reassoc] theorem colimitIsoColimitCurryCompColim_ι_ι_inv {j} {k} : colimit.ι ((curry.obj G).obj j) k ≫ colimit.ι (curry.obj G ⋙ colim) j ≫ (colimitIsoColimitCurryCompColim G).inv = colimit.ι _ (j, k) := by set_option tactic.skipAssignedInstances false in simp [colimitIsoColimitCurryCompColim, Trans.simple, HasColimit.isoOfNatIso, colimitUncurryIsoColimitCompColim] @[simp, reassoc] theorem colimitIsoColimitCurryCompColim_ι_hom {j} {k} : colimit.ι _ (j, k) ≫ (colimitIsoColimitCurryCompColim G).hom = (colimit.ι (_) k ≫ colimit.ι (curry.obj G ⋙ colim) j : _ ⟶ colimit (_ ⋙ colim)) := by rw [← cancel_mono (colimitIsoColimitCurryCompColim G).inv] simp end section variable [HasLimits C] -- Certainly one could weaken the hypotheses here. open CategoryTheory.prod /-- A variant of the Fubini theorem for a functor `G : J × K ⥤ C`, showing that $\lim_k \lim_j G(j,k) ≅ \lim_j \lim_k G(j,k)$. -/ noncomputable def limitCurrySwapCompLimIsoLimitCurryCompLim : limit (curry.obj (Prod.swap K J ⋙ G) ⋙ lim) ≅ limit (curry.obj G ⋙ lim) := calc limit (curry.obj (Prod.swap K J ⋙ G) ⋙ lim) ≅ limit (Prod.swap K J ⋙ G) := (limitIsoLimitCurryCompLim _).symm _ ≅ limit G := HasLimit.isoOfEquivalence (Prod.braiding K J) (Iso.refl _) _ ≅ limit (curry.obj G ⋙ lim) := limitIsoLimitCurryCompLim _ -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp] theorem limitCurrySwapCompLimIsoLimitCurryCompLim_hom_π_π {j} {k} : (limitCurrySwapCompLimIsoLimitCurryCompLim G).hom ≫ limit.π _ j ≫ limit.π _ k = (limit.π _ k ≫ limit.π _ j : limit (_ ⋙ lim) ⟶ _) := by dsimp [limitCurrySwapCompLimIsoLimitCurryCompLim] simp only [Iso.refl_hom, Prod.braiding_counitIso_hom_app, Limits.HasLimit.isoOfEquivalence_hom_π, Iso.refl_inv, limitIsoLimitCurryCompLim_hom_π_π, eqToIso_refl, Category.assoc] erw [NatTrans.id_app] -- Why can't `simp` do this? dsimp -- Porting note: the original proof only had `simp`. -- However, now `CategoryTheory.Bifunctor.map_id` does not get used by `simp` rw [CategoryTheory.Bifunctor.map_id] simp -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp] theorem limitCurrySwapCompLimIsoLimitCurryCompLim_inv_π_π {j} {k} : (limitCurrySwapCompLimIsoLimitCurryCompLim G).inv ≫ limit.π _ k ≫ limit.π _ j = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by dsimp [limitCurrySwapCompLimIsoLimitCurryCompLim] simp only [Iso.refl_hom, Prod.braiding_counitIso_hom_app, Limits.HasLimit.isoOfEquivalence_inv_π, Iso.refl_inv, limitIsoLimitCurryCompLim_hom_π_π, eqToIso_refl, Category.assoc] erw [NatTrans.id_app] -- Porting note (#10618): `simp` can do this in lean 4. simp end section variable [HasColimits C] open CategoryTheory.prod /-- A variant of the Fubini theorem for a functor `G : J × K ⥤ C`, showing that $\colim_k \colim_j G(j,k) ≅ \colim_j \colim_k G(j,k)$. -/ noncomputable def colimitCurrySwapCompColimIsoColimitCurryCompColim : colimit (curry.obj (Prod.swap K J ⋙ G) ⋙ colim) ≅ colimit (curry.obj G ⋙ colim) := calc colimit (curry.obj (Prod.swap K J ⋙ G) ⋙ colim) ≅ colimit (Prod.swap K J ⋙ G) := (colimitIsoColimitCurryCompColim _).symm _ ≅ colimit G := HasColimit.isoOfEquivalence (Prod.braiding K J) (Iso.refl _) _ ≅ colimit (curry.obj G ⋙ colim) := colimitIsoColimitCurryCompColim _ @[simp] theorem colimitCurrySwapCompColimIsoColimitCurryCompColim_ι_ι_hom {j} {k} : colimit.ι _ j ≫ colimit.ι (curry.obj (Prod.swap K J ⋙ G) ⋙ colim) k ≫ (colimitCurrySwapCompColimIsoColimitCurryCompColim G).hom = (colimit.ι _ k ≫ colimit.ι (curry.obj G ⋙ colim) j : _ ⟶ colimit (curry.obj G⋙ colim)) := by dsimp [colimitCurrySwapCompColimIsoColimitCurryCompColim] slice_lhs 1 3 => simp only [] simp @[simp] theorem colimitCurrySwapCompColimIsoColimitCurryCompColim_ι_ι_inv {j} {k} : colimit.ι _ k ≫ colimit.ι (curry.obj G ⋙ colim) j ≫ (colimitCurrySwapCompColimIsoColimitCurryCompColim G).inv = (colimit.ι _ j ≫ colimit.ι (curry.obj _ ⋙ colim) k : _ ⟶ colimit (curry.obj (Prod.swap K J ⋙ G) ⋙ colim)) := by dsimp [colimitCurrySwapCompColimIsoColimitCurryCompColim] slice_lhs 1 3 => simp only [] simp only [colimitIsoColimitCurryCompColim_ι_ι_inv, HasColimit.isoOfEquivalence_inv_π, Functor.id_obj, Functor.comp_obj, Prod.braiding_inverse_obj, Prod.braiding_functor_obj, Prod.braiding_counitIso_inv_app, Prod.swap_obj, Iso.refl_hom, NatTrans.id_app, Category.id_comp, Category.assoc, colimitIsoColimitCurryCompColim_ι_hom, curry_obj_obj_obj] erw [CategoryTheory.Bifunctor.map_id] simp end end CategoryTheory.Limits
CategoryTheory\Limits\FullSubcategory.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Creates /-! # Limits in full subcategories We introduce the notion of a property closed under taking limits and show that if `P` is closed under taking limits, then limits in `FullSubcategory P` can be constructed from limits in `C`. More precisely, the inclusion creates such limits. -/ noncomputable section universe w' w v u open CategoryTheory namespace CategoryTheory.Limits /-- We say that a property is closed under limits of shape `J` if whenever all objects in a `J`-shaped diagram have the property, any limit of this diagram also has the property. -/ def ClosedUnderLimitsOfShape {C : Type u} [Category.{v} C] (J : Type w) [Category.{w'} J] (P : C → Prop) : Prop := ∀ ⦃F : J ⥤ C⦄ ⦃c : Cone F⦄ (_hc : IsLimit c), (∀ j, P (F.obj j)) → P c.pt /-- We say that a property is closed under colimits of shape `J` if whenever all objects in a `J`-shaped diagram have the property, any colimit of this diagram also has the property. -/ def ClosedUnderColimitsOfShape {C : Type u} [Category.{v} C] (J : Type w) [Category.{w'} J] (P : C → Prop) : Prop := ∀ ⦃F : J ⥤ C⦄ ⦃c : Cocone F⦄ (_hc : IsColimit c), (∀ j, P (F.obj j)) → P c.pt section variable {C : Type u} [Category.{v} C] {J : Type w} [Category.{w'} J] {P : C → Prop} theorem ClosedUnderLimitsOfShape.limit (h : ClosedUnderLimitsOfShape J P) {F : J ⥤ C} [HasLimit F] : (∀ j, P (F.obj j)) → P (limit F) := h (limit.isLimit _) theorem ClosedUnderColimitsOfShape.colimit (h : ClosedUnderColimitsOfShape J P) {F : J ⥤ C} [HasColimit F] : (∀ j, P (F.obj j)) → P (colimit F) := h (colimit.isColimit _) end section variable {J : Type w} [Category.{w'} J] {C : Type u} [Category.{v} C] {P : C → Prop} /-- If a `J`-shaped diagram in `FullSubcategory P` has a limit cone in `C` whose cone point lives in the full subcategory, then this defines a limit in the full subcategory. -/ def createsLimitFullSubcategoryInclusion' (F : J ⥤ FullSubcategory P) {c : Cone (F ⋙ fullSubcategoryInclusion P)} (hc : IsLimit c) (h : P c.pt) : CreatesLimit F (fullSubcategoryInclusion P) := createsLimitOfFullyFaithfulOfIso' hc ⟨_, h⟩ (Iso.refl _) /-- If a `J`-shaped diagram in `FullSubcategory P` has a limit in `C` whose cone point lives in the full subcategory, then this defines a limit in the full subcategory. -/ def createsLimitFullSubcategoryInclusion (F : J ⥤ FullSubcategory P) [HasLimit (F ⋙ fullSubcategoryInclusion P)] (h : P (limit (F ⋙ fullSubcategoryInclusion P))) : CreatesLimit F (fullSubcategoryInclusion P) := createsLimitFullSubcategoryInclusion' F (limit.isLimit _) h /-- If a `J`-shaped diagram in `FullSubcategory P` has a colimit cocone in `C` whose cocone point lives in the full subcategory, then this defines a colimit in the full subcategory. -/ def createsColimitFullSubcategoryInclusion' (F : J ⥤ FullSubcategory P) {c : Cocone (F ⋙ fullSubcategoryInclusion P)} (hc : IsColimit c) (h : P c.pt) : CreatesColimit F (fullSubcategoryInclusion P) := createsColimitOfFullyFaithfulOfIso' hc ⟨_, h⟩ (Iso.refl _) /-- If a `J`-shaped diagram in `FullSubcategory P` has a colimit in `C` whose cocone point lives in the full subcategory, then this defines a colimit in the full subcategory. -/ def createsColimitFullSubcategoryInclusion (F : J ⥤ FullSubcategory P) [HasColimit (F ⋙ fullSubcategoryInclusion P)] (h : P (colimit (F ⋙ fullSubcategoryInclusion P))) : CreatesColimit F (fullSubcategoryInclusion P) := createsColimitFullSubcategoryInclusion' F (colimit.isColimit _) h /-- If `P` is closed under limits of shape `J`, then the inclusion creates such limits. -/ def createsLimitFullSubcategoryInclusionOfClosed (h : ClosedUnderLimitsOfShape J P) (F : J ⥤ FullSubcategory P) [HasLimit (F ⋙ fullSubcategoryInclusion P)] : CreatesLimit F (fullSubcategoryInclusion P) := createsLimitFullSubcategoryInclusion F (h.limit fun j => (F.obj j).property) /-- If `P` is closed under limits of shape `J`, then the inclusion creates such limits. -/ def createsLimitsOfShapeFullSubcategoryInclusion (h : ClosedUnderLimitsOfShape J P) [HasLimitsOfShape J C] : CreatesLimitsOfShape J (fullSubcategoryInclusion P) where CreatesLimit := @fun F => createsLimitFullSubcategoryInclusionOfClosed h F theorem hasLimit_of_closedUnderLimits (h : ClosedUnderLimitsOfShape J P) (F : J ⥤ FullSubcategory P) [HasLimit (F ⋙ fullSubcategoryInclusion P)] : HasLimit F := have : CreatesLimit F (fullSubcategoryInclusion P) := createsLimitFullSubcategoryInclusionOfClosed h F hasLimit_of_created F (fullSubcategoryInclusion P) @[deprecated (since := "2024-03-23")] alias hasLimit_of_closed_under_limits := hasLimit_of_closedUnderLimits theorem hasLimitsOfShape_of_closedUnderLimits (h : ClosedUnderLimitsOfShape J P) [HasLimitsOfShape J C] : HasLimitsOfShape J (FullSubcategory P) := { has_limit := fun F => hasLimit_of_closedUnderLimits h F } /-- If `P` is closed under colimits of shape `J`, then the inclusion creates such colimits. -/ def createsColimitFullSubcategoryInclusionOfClosed (h : ClosedUnderColimitsOfShape J P) (F : J ⥤ FullSubcategory P) [HasColimit (F ⋙ fullSubcategoryInclusion P)] : CreatesColimit F (fullSubcategoryInclusion P) := createsColimitFullSubcategoryInclusion F (h.colimit fun j => (F.obj j).property) /-- If `P` is closed under colimits of shape `J`, then the inclusion creates such colimits. -/ def createsColimitsOfShapeFullSubcategoryInclusion (h : ClosedUnderColimitsOfShape J P) [HasColimitsOfShape J C] : CreatesColimitsOfShape J (fullSubcategoryInclusion P) where CreatesColimit := @fun F => createsColimitFullSubcategoryInclusionOfClosed h F theorem hasColimit_of_closedUnderColimits (h : ClosedUnderColimitsOfShape J P) (F : J ⥤ FullSubcategory P) [HasColimit (F ⋙ fullSubcategoryInclusion P)] : HasColimit F := have : CreatesColimit F (fullSubcategoryInclusion P) := createsColimitFullSubcategoryInclusionOfClosed h F hasColimit_of_created F (fullSubcategoryInclusion P) @[deprecated (since := "2024-03-23")] alias hasColimit_of_closed_under_colimits := hasColimit_of_closedUnderColimits theorem hasColimitsOfShape_of_closedUnderColimits (h : ClosedUnderColimitsOfShape J P) [HasColimitsOfShape J C] : HasColimitsOfShape J (FullSubcategory P) := { has_colimit := fun F => hasColimit_of_closedUnderColimits h F } @[deprecated (since := "2024-03-23")] alias hasColimitsOfShape_of_closed_under_colimits := hasColimitsOfShape_of_closedUnderColimits end end CategoryTheory.Limits
CategoryTheory\Limits\FunctorCategory.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Limits.Preserves.Limits /-! # (Co)limits in functor categories. We show that if `D` has limits, then the functor category `C ⥤ D` also has limits (`CategoryTheory.Limits.functorCategoryHasLimits`), and the evaluation functors preserve limits (`CategoryTheory.Limits.evaluationPreservesLimits`) (and similarly for colimits). We also show that `F : D ⥤ K ⥤ C` preserves (co)limits if it does so for each `k : K` (`CategoryTheory.Limits.preservesLimitsOfEvaluation` and `CategoryTheory.Limits.preservesColimitsOfEvaluation`). -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Functor -- morphism levels before object levels. See note [CategoryTheory universes]. universe w' w v₁ v₂ u₁ u₂ v v' u u' namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] @[reassoc (attr := simp)] theorem limit.lift_π_app (H : J ⥤ K ⥤ C) [HasLimit H] (c : Cone H) (j : J) (k : K) : (limit.lift H c).app k ≫ (limit.π H j).app k = (c.π.app j).app k := congr_app (limit.lift_π c j) k @[reassoc (attr := simp)] theorem colimit.ι_desc_app (H : J ⥤ K ⥤ C) [HasColimit H] (c : Cocone H) (j : J) (k : K) : (colimit.ι H j).app k ≫ (colimit.desc H c).app k = (c.ι.app j).app k := congr_app (colimit.ι_desc c j) k /-- The evaluation functors jointly reflect limits: that is, to show a cone is a limit of `F` it suffices to show that each evaluation cone is a limit. In other words, to prove a cone is limiting you can show it's pointwise limiting. -/ def evaluationJointlyReflectsLimits {F : J ⥤ K ⥤ C} (c : Cone F) (t : ∀ k : K, IsLimit (((evaluation K C).obj k).mapCone c)) : IsLimit c where lift s := { app := fun k => (t k).lift ⟨s.pt.obj k, whiskerRight s.π ((evaluation K C).obj k)⟩ naturality := fun X Y f => (t Y).hom_ext fun j => by rw [assoc, (t Y).fac _ j] simpa using ((t X).fac_assoc ⟨s.pt.obj X, whiskerRight s.π ((evaluation K C).obj X)⟩ j _).symm } fac s j := by ext k; exact (t k).fac _ j uniq s m w := by ext x exact (t x).hom_ext fun j => (congr_app (w j) x).trans ((t x).fac ⟨s.pt.obj _, whiskerRight s.π ((evaluation K C).obj _)⟩ j).symm /-- Given a functor `F` and a collection of limit cones for each diagram `X ↦ F X k`, we can stitch them together to give a cone for the diagram `F`. `combinedIsLimit` shows that the new cone is limiting, and `evalCombined` shows it is (essentially) made up of the original cones. -/ @[simps] def combineCones (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) : Cone F where pt := { obj := fun k => (c k).cone.pt map := fun {k₁} {k₂} f => (c k₂).isLimit.lift ⟨_, (c k₁).cone.π ≫ F.flip.map f⟩ map_id := fun k => (c k).isLimit.hom_ext fun j => by dsimp simp map_comp := fun {k₁} {k₂} {k₃} f₁ f₂ => (c k₃).isLimit.hom_ext fun j => by simp } π := { app := fun j => { app := fun k => (c k).cone.π.app j } naturality := fun j₁ j₂ g => by ext k; exact (c k).cone.π.naturality g } /-- The stitched together cones each project down to the original given cones (up to iso). -/ def evaluateCombinedCones (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) (k : K) : ((evaluation K C).obj k).mapCone (combineCones F c) ≅ (c k).cone := Cones.ext (Iso.refl _) /-- Stitching together limiting cones gives a limiting cone. -/ def combinedIsLimit (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) : IsLimit (combineCones F c) := evaluationJointlyReflectsLimits _ fun k => (c k).isLimit.ofIsoLimit (evaluateCombinedCones F c k).symm /-- The evaluation functors jointly reflect colimits: that is, to show a cocone is a colimit of `F` it suffices to show that each evaluation cocone is a colimit. In other words, to prove a cocone is colimiting you can show it's pointwise colimiting. -/ def evaluationJointlyReflectsColimits {F : J ⥤ K ⥤ C} (c : Cocone F) (t : ∀ k : K, IsColimit (((evaluation K C).obj k).mapCocone c)) : IsColimit c where desc s := { app := fun k => (t k).desc ⟨s.pt.obj k, whiskerRight s.ι ((evaluation K C).obj k)⟩ naturality := fun X Y f => (t X).hom_ext fun j => by rw [(t X).fac_assoc _ j] erw [← (c.ι.app j).naturality_assoc f] erw [(t Y).fac ⟨s.pt.obj _, whiskerRight s.ι _⟩ j] dsimp simp } fac s j := by ext k; exact (t k).fac _ j uniq s m w := by ext x exact (t x).hom_ext fun j => (congr_app (w j) x).trans ((t x).fac ⟨s.pt.obj _, whiskerRight s.ι ((evaluation K C).obj _)⟩ j).symm /-- Given a functor `F` and a collection of colimit cocones for each diagram `X ↦ F X k`, we can stitch them together to give a cocone for the diagram `F`. `combinedIsColimit` shows that the new cocone is colimiting, and `evalCombined` shows it is (essentially) made up of the original cocones. -/ @[simps] def combineCocones (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) : Cocone F where pt := { obj := fun k => (c k).cocone.pt map := fun {k₁} {k₂} f => (c k₁).isColimit.desc ⟨_, F.flip.map f ≫ (c k₂).cocone.ι⟩ map_id := fun k => (c k).isColimit.hom_ext fun j => by dsimp simp map_comp := fun {k₁} {k₂} {k₃} f₁ f₂ => (c k₁).isColimit.hom_ext fun j => by simp } ι := { app := fun j => { app := fun k => (c k).cocone.ι.app j } naturality := fun j₁ j₂ g => by ext k; exact (c k).cocone.ι.naturality g } /-- The stitched together cocones each project down to the original given cocones (up to iso). -/ def evaluateCombinedCocones (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) (k : K) : ((evaluation K C).obj k).mapCocone (combineCocones F c) ≅ (c k).cocone := Cocones.ext (Iso.refl _) /-- Stitching together colimiting cocones gives a colimiting cocone. -/ def combinedIsColimit (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) : IsColimit (combineCocones F c) := evaluationJointlyReflectsColimits _ fun k => (c k).isColimit.ofIsoColimit (evaluateCombinedCocones F c k).symm noncomputable section instance functorCategoryHasLimitsOfShape [HasLimitsOfShape J C] : HasLimitsOfShape J (K ⥤ C) where has_limit F := HasLimit.mk { cone := combineCones F fun _ => getLimitCone _ isLimit := combinedIsLimit _ _ } instance functorCategoryHasColimitsOfShape [HasColimitsOfShape J C] : HasColimitsOfShape J (K ⥤ C) where has_colimit _ := HasColimit.mk { cocone := combineCocones _ fun _ => getColimitCocone _ isColimit := combinedIsColimit _ _ } -- Porting note: previously Lean could see through the binders and infer_instance sufficed instance functorCategoryHasLimitsOfSize [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₁, u₁} (K ⥤ C) where has_limits_of_shape := fun _ _ => inferInstance -- Porting note: previously Lean could see through the binders and infer_instance sufficed instance functorCategoryHasColimitsOfSize [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfSize.{v₁, u₁} (K ⥤ C) where has_colimits_of_shape := fun _ _ => inferInstance instance evaluationPreservesLimitsOfShape [HasLimitsOfShape J C] (k : K) : PreservesLimitsOfShape J ((evaluation K C).obj k) where preservesLimit {F} := by -- Porting note: added a let because X was not inferred let X : (k : K) → LimitCone (Prefunctor.obj (Functor.flip F).toPrefunctor k) := fun k => getLimitCone (Prefunctor.obj (Functor.flip F).toPrefunctor k) exact preservesLimitOfPreservesLimitCone (combinedIsLimit _ _) <| IsLimit.ofIsoLimit (limit.isLimit _) (evaluateCombinedCones F X k).symm /-- If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a limit, then the evaluation of that limit at `k` is the limit of the evaluations of `F.obj j` at `k`. -/ def limitObjIsoLimitCompEvaluation [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (k : K) : (limit F).obj k ≅ limit (F ⋙ (evaluation K C).obj k) := preservesLimitIso ((evaluation K C).obj k) F @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_hom_π [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (limitObjIsoLimitCompEvaluation F k).hom ≫ limit.π (F ⋙ (evaluation K C).obj k) j = (limit.π F j).app k := by dsimp [limitObjIsoLimitCompEvaluation] simp @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_inv_π_app [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (limitObjIsoLimitCompEvaluation F k).inv ≫ (limit.π F j).app k = limit.π (F ⋙ (evaluation K C).obj k) j := by dsimp [limitObjIsoLimitCompEvaluation] rw [Iso.inv_comp_eq] simp @[reassoc (attr := simp)] theorem limit_map_limitObjIsoLimitCompEvaluation_hom [HasLimitsOfShape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) : (limit F).map f ≫ (limitObjIsoLimitCompEvaluation _ _).hom = (limitObjIsoLimitCompEvaluation _ _).hom ≫ limMap (whiskerLeft _ ((evaluation _ _).map f)) := by ext dsimp simp @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_inv_limit_map [HasLimitsOfShape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) : (limitObjIsoLimitCompEvaluation _ _).inv ≫ (limit F).map f = limMap (whiskerLeft _ ((evaluation _ _).map f)) ≫ (limitObjIsoLimitCompEvaluation _ _).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, limit_map_limitObjIsoLimitCompEvaluation_hom] @[ext] theorem limit_obj_ext {H : J ⥤ K ⥤ C} [HasLimitsOfShape J C] {k : K} {W : C} {f g : W ⟶ (limit H).obj k} (w : ∀ j, f ≫ (Limits.limit.π H j).app k = g ≫ (Limits.limit.π H j).app k) : f = g := by apply (cancel_mono (limitObjIsoLimitCompEvaluation H k).hom).1 ext j simpa using w j instance evaluationPreservesColimitsOfShape [HasColimitsOfShape J C] (k : K) : PreservesColimitsOfShape J ((evaluation K C).obj k) where preservesColimit {F} := by -- Porting note: added a let because X was not inferred let X : (k : K) → ColimitCocone (Prefunctor.obj (Functor.flip F).toPrefunctor k) := fun k => getColimitCocone (Prefunctor.obj (Functor.flip F).toPrefunctor k) refine preservesColimitOfPreservesColimitCocone (combinedIsColimit _ _) <| IsColimit.ofIsoColimit (colimit.isColimit _) (evaluateCombinedCocones F X k).symm /-- If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a colimit, then the evaluation of that colimit at `k` is the colimit of the evaluations of `F.obj j` at `k`. -/ def colimitObjIsoColimitCompEvaluation [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (k : K) : (colimit F).obj k ≅ colimit (F ⋙ (evaluation K C).obj k) := preservesColimitIso ((evaluation K C).obj k) F @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_ι_inv [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : colimit.ι (F ⋙ (evaluation K C).obj k) j ≫ (colimitObjIsoColimitCompEvaluation F k).inv = (colimit.ι F j).app k := by dsimp [colimitObjIsoColimitCompEvaluation] simp @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_ι_app_hom [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (colimit.ι F j).app k ≫ (colimitObjIsoColimitCompEvaluation F k).hom = colimit.ι (F ⋙ (evaluation K C).obj k) j := by dsimp [colimitObjIsoColimitCompEvaluation] rw [← Iso.eq_comp_inv] simp @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_inv_colimit_map [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) : (colimitObjIsoColimitCompEvaluation _ _).inv ≫ (colimit F).map f = colimMap (whiskerLeft _ ((evaluation _ _).map f)) ≫ (colimitObjIsoColimitCompEvaluation _ _).inv := by ext dsimp simp @[reassoc (attr := simp)] theorem colimit_map_colimitObjIsoColimitCompEvaluation_hom [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) : (colimit F).map f ≫ (colimitObjIsoColimitCompEvaluation _ _).hom = (colimitObjIsoColimitCompEvaluation _ _).hom ≫ colimMap (whiskerLeft _ ((evaluation _ _).map f)) := by rw [← Iso.inv_comp_eq, ← Category.assoc, ← Iso.eq_comp_inv, colimitObjIsoColimitCompEvaluation_inv_colimit_map] @[ext] theorem colimit_obj_ext {H : J ⥤ K ⥤ C} [HasColimitsOfShape J C] {k : K} {W : C} {f g : (colimit H).obj k ⟶ W} (w : ∀ j, (colimit.ι H j).app k ≫ f = (colimit.ι H j).app k ≫ g) : f = g := by apply (cancel_epi (colimitObjIsoColimitCompEvaluation H k).inv).1 ext j simpa using w j instance evaluationPreservesLimits [HasLimits C] (k : K) : PreservesLimits ((evaluation K C).obj k) where preservesLimitsOfShape {_} _𝒥 := inferInstance /-- `F : D ⥤ K ⥤ C` preserves the limit of some `G : J ⥤ D` if it does for each `k : K`. -/ def preservesLimitOfEvaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D) (H : ∀ k : K, PreservesLimit G (F ⋙ (evaluation K C).obj k : D ⥤ C)) : PreservesLimit G F := ⟨fun {c} hc => by apply evaluationJointlyReflectsLimits intro X haveI := H X change IsLimit ((F ⋙ (evaluation K C).obj X).mapCone c) exact PreservesLimit.preserves hc⟩ /-- `F : D ⥤ K ⥤ C` preserves limits of shape `J` if it does for each `k : K`. -/ def preservesLimitsOfShapeOfEvaluation (F : D ⥤ K ⥤ C) (J : Type*) [Category J] (_ : ∀ k : K, PreservesLimitsOfShape J (F ⋙ (evaluation K C).obj k)) : PreservesLimitsOfShape J F := ⟨fun {G} => preservesLimitOfEvaluation F G fun _ => PreservesLimitsOfShape.preservesLimit⟩ /-- `F : D ⥤ K ⥤ C` preserves all limits if it does for each `k : K`. -/ def preservesLimitsOfEvaluation (F : D ⥤ K ⥤ C) (_ : ∀ k : K, PreservesLimitsOfSize.{w', w} (F ⋙ (evaluation K C).obj k)) : PreservesLimitsOfSize.{w', w} F := ⟨fun {L} _ => preservesLimitsOfShapeOfEvaluation F L fun _ => PreservesLimitsOfSize.preservesLimitsOfShape⟩ /-- The constant functor `C ⥤ (D ⥤ C)` preserves limits. -/ instance preservesLimitsConst : PreservesLimitsOfSize.{w', w} (const D : C ⥤ _) := preservesLimitsOfEvaluation _ fun _ => preservesLimitsOfNatIso <| Iso.symm <| constCompEvaluationObj _ _ instance evaluationPreservesColimits [HasColimits C] (k : K) : PreservesColimits ((evaluation K C).obj k) where preservesColimitsOfShape := inferInstance /-- `F : D ⥤ K ⥤ C` preserves the colimit of some `G : J ⥤ D` if it does for each `k : K`. -/ def preservesColimitOfEvaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D) (H : ∀ k, PreservesColimit G (F ⋙ (evaluation K C).obj k)) : PreservesColimit G F := ⟨fun {c} hc => by apply evaluationJointlyReflectsColimits intro X haveI := H X change IsColimit ((F ⋙ (evaluation K C).obj X).mapCocone c) exact PreservesColimit.preserves hc⟩ /-- `F : D ⥤ K ⥤ C` preserves all colimits of shape `J` if it does for each `k : K`. -/ def preservesColimitsOfShapeOfEvaluation (F : D ⥤ K ⥤ C) (J : Type*) [Category J] (_ : ∀ k : K, PreservesColimitsOfShape J (F ⋙ (evaluation K C).obj k)) : PreservesColimitsOfShape J F := ⟨fun {G} => preservesColimitOfEvaluation F G fun _ => PreservesColimitsOfShape.preservesColimit⟩ /-- `F : D ⥤ K ⥤ C` preserves all colimits if it does for each `k : K`. -/ def preservesColimitsOfEvaluation (F : D ⥤ K ⥤ C) (_ : ∀ k : K, PreservesColimitsOfSize.{w', w} (F ⋙ (evaluation K C).obj k)) : PreservesColimitsOfSize.{w', w} F := ⟨fun {L} _ => preservesColimitsOfShapeOfEvaluation F L fun _ => PreservesColimitsOfSize.preservesColimitsOfShape⟩ /-- The constant functor `C ⥤ (D ⥤ C)` preserves colimits. -/ instance preservesColimitsConst : PreservesColimitsOfSize.{w', w} (const D : C ⥤ _) := preservesColimitsOfEvaluation _ fun _ => preservesColimitsOfNatIso <| Iso.symm <| constCompEvaluationObj _ _ open CategoryTheory.prod /-- The limit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by the individual limits on objects. -/ @[simps!] def limitIsoFlipCompLim [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) : limit F ≅ F.flip ⋙ lim := NatIso.ofComponents (limitObjIsoLimitCompEvaluation F) /-- A variant of `limitIsoFlipCompLim` where the arguments of `F` are flipped. -/ @[simps!] def limitFlipIsoCompLim [HasLimitsOfShape J C] (F : K ⥤ J ⥤ C) : limit F.flip ≅ F ⋙ lim := let f := fun k => limitObjIsoLimitCompEvaluation F.flip k ≪≫ HasLimit.isoOfNatIso (flipCompEvaluation _ _) NatIso.ofComponents f /-- For a functor `G : J ⥤ K ⥤ C`, its limit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ lim`. Note that this does not require `K` to be small. -/ @[simps!] def limitIsoSwapCompLim [HasLimitsOfShape J C] (G : J ⥤ K ⥤ C) : limit G ≅ curry.obj (Prod.swap K J ⋙ uncurry.obj G) ⋙ lim := limitIsoFlipCompLim G ≪≫ isoWhiskerRight (flipIsoCurrySwapUncurry _) _ /-- The colimit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by the individual colimits on objects. -/ @[simps!] def colimitIsoFlipCompColim [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) : colimit F ≅ F.flip ⋙ colim := NatIso.ofComponents (colimitObjIsoColimitCompEvaluation F) /-- A variant of `colimit_iso_flip_comp_colim` where the arguments of `F` are flipped. -/ @[simps!] def colimitFlipIsoCompColim [HasColimitsOfShape J C] (F : K ⥤ J ⥤ C) : colimit F.flip ≅ F ⋙ colim := let f := fun k => colimitObjIsoColimitCompEvaluation _ _ ≪≫ HasColimit.isoOfNatIso (flipCompEvaluation _ _) NatIso.ofComponents f /-- For a functor `G : J ⥤ K ⥤ C`, its colimit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ colim`. Note that this does not require `K` to be small. -/ @[simps!] def colimitIsoSwapCompColim [HasColimitsOfShape J C] (G : J ⥤ K ⥤ C) : colimit G ≅ curry.obj (Prod.swap K J ⋙ uncurry.obj G) ⋙ colim := colimitIsoFlipCompColim G ≪≫ isoWhiskerRight (flipIsoCurrySwapUncurry _) _ end end Limits end CategoryTheory
CategoryTheory\Limits\FunctorToTypes.lean
/- Copyright (c) 2024 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Types /-! # Concrete description of (co)limits in functor categories Some of the concrete descriptions of (co)limits in `Type v` extend to (co)limits in the functor category `K ⥤ Type v`. -/ namespace CategoryTheory.FunctorToTypes open CategoryTheory.Limits universe w v₁ v₂ u₁ u₂ variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable (F : J ⥤ K ⥤ TypeMax.{u₁, w}) theorem jointly_surjective (k : K) {t : Cocone F} (h : IsColimit t) (x : t.pt.obj k) : ∃ j y, x = (t.ι.app j).app k y := by let hev := isColimitOfPreserves ((evaluation _ _).obj k) h obtain ⟨j, y, rfl⟩ := Types.jointly_surjective _ hev x exact ⟨j, y, by simp⟩ theorem jointly_surjective' (k : K) (x : (colimit F).obj k) : ∃ j y, x = (colimit.ι F j).app k y := jointly_surjective _ _ (colimit.isColimit _) x end CategoryTheory.FunctorToTypes
CategoryTheory\Limits\HasLimits.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.Logic.Equiv.Basic /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit @[reassoc (attr := simp)] theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat @[reassoc (attr := simp)] theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat @[ext] theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.isLimit F).hom_ext w @[simp] theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) : limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by ext rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π] rfl @[simp] theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) := (limit.isLimit _).lift_self /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and cones with cone point `W`. -/ def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) := (limit.isLimit F).homIso W @[simp] theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) : (limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π := (limit.isLimit F).homIso_hom f /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and an explicit componentwise description of cones with cone point `W`. -/ def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.isLimit F).homIso' W theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by aesop_cat /-- If a functor `F` has a limit, so does any naturally isomorphic functor. -/ theorem hasLimitOfIso {F G : J ⥤ C} [HasLimit F] (α : F ≅ G) : HasLimit G := HasLimit.mk { cone := (Cones.postcompose α.hom).obj (limit.cone F) isLimit := (IsLimit.postcomposeHomEquiv _ _).symm (limit.isLimit F) } -- See the construction of limits from products and equalizers -- for an example usage. /-- If a functor `G` has the same collection of cones as a functor `F` which has a limit, then `G` also has a limit. -/ theorem HasLimit.ofConesIso {J K : Type u₁} [Category.{v₁} J] [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cones ≅ G.cones) [HasLimit F] : HasLimit G := HasLimit.mk ⟨_, IsLimit.ofNatIso (IsLimit.natIso (limit.isLimit F) ≪≫ h)⟩ /-- The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasLimit.isoOfNatIso {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) : limit F ≅ limit G := IsLimit.conePointsIsoOfNatIso (limit.isLimit F) (limit.isLimit G) w @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_hom_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j := IsLimit.conePointsIsoOfNatIso_hom_comp _ _ _ _ @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_inv_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j := IsLimit.conePointsIsoOfNatIso_inv_comp _ _ _ _ @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_hom {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone F) (w : F ≅ G) : limit.lift F t ≫ (HasLimit.isoOfNatIso w).hom = limit.lift G ((Cones.postcompose w.hom).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_hom _ _ _ @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_inv {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone G) (w : F ≅ G) : limit.lift G t ≫ (HasLimit.isoOfNatIso w).inv = limit.lift F ((Cones.postcompose w.inv).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_inv _ _ _ /-- The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasLimit.isoOfEquivalence {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : limit F ≅ limit G := IsLimit.conePointsIsoOfEquivalence (limit.isLimit F) (limit.isLimit G) e w @[simp] theorem HasLimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : (HasLimit.isoOfEquivalence e w).hom ≫ limit.π G k = limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp @[simp] theorem HasLimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : (HasLimit.isoOfEquivalence e w).inv ≫ limit.π F j = limit.π G (e.functor.obj j) ≫ w.hom.app j := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp section Pre variable (F) variable [HasLimit F] (E : K ⥤ J) [HasLimit (E ⋙ F)] /-- The canonical morphism from the limit of `F` to the limit of `E ⋙ F`. -/ def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) ((limit.cone F).whisker E) @[reassoc (attr := simp)] theorem limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw [IsLimit.fac] rfl @[simp] theorem limit.lift_pre (c : Cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) @[simp] theorem limit.pre_pre [h : HasLimit (D ⋙ E ⋙ F)] : haveI : HasLimit ((D ⋙ E) ⋙ F) := h limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by haveI : HasLimit ((D ⋙ E) ⋙ F) := h ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; rfl variable {E F} /-- - If we have particular limit cones available for `E ⋙ F` and for `F`, we obtain a formula for `limit.pre F E`. -/ theorem limit.pre_eq (s : LimitCone (E ⋙ F)) (t : LimitCone F) : limit.pre F E = (limit.isoLimitCone t).hom ≫ s.isLimit.lift (t.cone.whisker E) ≫ (limit.isoLimitCone s).inv := by aesop_cat end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F : J ⥤ C) [HasLimit F] (G : C ⥤ D) [HasLimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`. -/ def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) (G.mapCone (limit.cone F)) @[reassoc (attr := simp)] theorem limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw [IsLimit.fac] rfl @[simp] theorem limit.lift_post (c : Cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.mapCone c) := by ext rw [assoc, limit.post_π, ← G.map_comp, limit.lift_π, limit.lift_π] rfl @[simp] theorem limit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) [h : HasLimit ((F ⋙ G) ⋙ H)] : -- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) haveI : HasLimit (F ⋙ G ⋙ H) := h H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by haveI : HasLimit (F ⋙ G ⋙ H) := h ext; erw [assoc, limit.post_π, ← H.map_comp, limit.post_π, limit.post_π]; rfl end Post theorem limit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasLimit F] [HasLimit (E ⋙ F)] [HasLimit (F ⋙ G)] [h : HasLimit ((E ⋙ F) ⋙ G)] :-- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or haveI : HasLimit (E ⋙ F ⋙ G) := h G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by haveI : HasLimit (E ⋙ F ⋙ G) := h ext; erw [assoc, limit.post_π, ← G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π] open CategoryTheory.Equivalence instance hasLimitEquivalenceComp (e : K ≌ J) [HasLimit F] : HasLimit (e.functor ⋙ F) := HasLimit.mk { cone := Cone.whisker e.functor (limit.cone F) isLimit := IsLimit.whiskerEquivalence (limit.isLimit F) e } -- Porting note: testing whether this still needed -- attribute [local elab_without_expected_type] inv_fun_id_assoc -- not entirely sure why this is needed /-- If a `E ⋙ F` has a limit, and `E` is an equivalence, we can construct a limit of `F`. -/ theorem hasLimitOfEquivalenceComp (e : K ≌ J) [HasLimit (e.functor ⋙ F)] : HasLimit F := by haveI : HasLimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasLimitEquivalenceComp e.symm apply hasLimitOfIso (e.invFunIdAssoc F) -- `hasLimitCompEquivalence` and `hasLimitOfCompEquivalence` -- are proved in `CategoryTheory/Adjunction/Limits.lean`. section LimFunctor variable [HasLimitsOfShape J C] section /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ @[simps] def lim : (J ⥤ C) ⥤ C where obj F := limit F map α := limMap α map_id F := by apply Limits.limit.hom_ext; intro j erw [limMap_π, Category.id_comp, Category.comp_id] map_comp α β := by apply Limits.limit.hom_ext; intro j erw [assoc, IsLimit.fac, IsLimit.fac, ← assoc, IsLimit.fac, assoc]; rfl end variable {G : J ⥤ C} (α : F ⟶ G) theorem limit.map_pre [HasLimitsOfShape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whiskerLeft E α) := by ext simp theorem limit.map_pre' [HasLimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whiskerRight α F) := by ext1; simp [← category.assoc] theorem limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (Functor.leftUnitor F).inv := by aesop_cat theorem limit.map_post {D : Type u'} [Category.{v'} D] [HasLimitsOfShape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (limMap α) ≫ limit.post G H = limit.post F H ≫ limMap (whiskerRight α H) := by ext simp only [whiskerRight_app, limMap_π, assoc, limit.post_π_assoc, limit.post_π, ← H.map_comp] /-- The isomorphism between morphisms from `W` to the cone point of the limit cone for `F` and cones over `F` with cone point `W` is natural in `F`. -/ def limYoneda : lim ⋙ yoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => limit.homIso F (unop W) /-- The constant functor and limit functor are adjoint to each other-/ def constLimAdj : (const J : C ⥤ J ⥤ C) ⊣ lim where homEquiv c g := { toFun := fun f => limit.lift _ ⟨c, f⟩ invFun := fun f => { app := fun j => f ≫ limit.π _ _ } left_inv := by aesop_cat right_inv := by aesop_cat } unit := { app := fun c => limit.lift _ ⟨_, 𝟙 _⟩ } counit := { app := fun g => { app := limit.π _ } } -- This used to be automatic before leanprover/lean4#2644 homEquiv_unit := by -- Sad that aesop can no longer do this! intros dsimp ext simp instance : IsRightAdjoint (lim : (J ⥤ C) ⥤ C) := ⟨_, ⟨constLimAdj⟩⟩ end LimFunctor instance limMap_mono' {F G : J ⥤ C} [HasLimitsOfShape J C] (α : F ⟶ G) [Mono α] : Mono (limMap α) := (lim : (J ⥤ C) ⥤ C).map_mono α instance limMap_mono {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) [∀ j, Mono (α.app j)] : Mono (limMap α) := ⟨fun {Z} u v h => limit.hom_ext fun j => (cancel_mono (α.app j)).1 <| by simpa using h =≫ limit.π _ j⟩ section Adjunction variable {L : (J ⥤ C) ⥤ C} (adj : Functor.const _ ⊣ L) /- The fact that the existence of limits of shape `J` is equivalent to the existence of a right adjoint to the constant functor `C ⥤ (J ⥤ C)` is obtained in the file `Mathlib.CategoryTheory.Limits.ConeCategory`: see the lemma `hasLimitsOfShape_iff_isLeftAdjoint_const`. In the definitions below, given an adjunction `adj : Functor.const _ ⊣ (L : (J ⥤ C) ⥤ C)`, we directly construct a limit cone for any `F : J ⥤ C`. -/ /-- The limit cone obtained from a right adjoint of the constant functor. -/ @[simps] noncomputable def coneOfAdj (F : J ⥤ C) : Cone F where pt := L.obj F π := adj.counit.app F /-- The cones defined by `coneOfAdj` are limit cones. -/ @[simps] def isLimitConeOfAdj (F : J ⥤ C) : IsLimit (coneOfAdj adj F) where lift s := adj.homEquiv _ _ s.π fac s j := by have eq := NatTrans.congr_app (adj.counit.naturality s.π) j have eq' := NatTrans.congr_app (adj.left_triangle_components s.pt) j dsimp at eq eq' ⊢ rw [Adjunction.homEquiv_unit, assoc, eq, reassoc_of% eq'] uniq s m hm := (adj.homEquiv _ _).symm.injective (by ext j; simpa using hm j) end Adjunction /-- We can transport limits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasLimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasLimitsOfShape J C] : HasLimitsOfShape J' C := by constructor intro F apply hasLimitOfEquivalenceComp e variable (C) /-- A category that has larger limits also has smaller limits. -/ theorem hasLimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₂, u₂} C where has_limits_of_shape J {_} := hasLimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasLimitsOfSizeShrink.{v u} C` tries to obtain `HasLimitsOfSize.{v u} C` from some other `HasLimitsOfSize C`. -/ theorem hasLimitsOfSizeShrink [HasLimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasLimitsOfSize.{v₁, u₁} C := hasLimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C instance (priority := 100) hasSmallestLimitsOfHasLimits [HasLimits C] : HasLimitsOfSize.{0, 0} C := hasLimitsOfSizeShrink.{0, 0} C end Limit section Colimit /-- `ColimitCocone F` contains a cocone over `F` together with the information that it is a colimit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure ColimitCocone (F : J ⥤ C) where /-- The cocone itself -/ cocone : Cocone F /-- The proof that it is the colimit cocone -/ isColimit : IsColimit cocone /-- `HasColimit F` represents the mere existence of a colimit for `F`. -/ class HasColimit (F : J ⥤ C) : Prop where mk' :: /-- There exists a colimit for `F` -/ exists_colimit : Nonempty (ColimitCocone F) theorem HasColimit.mk {F : J ⥤ C} (d : ColimitCocone F) : HasColimit F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `ColimitCocone F` from `HasColimit F`. -/ def getColimitCocone (F : J ⥤ C) [HasColimit F] : ColimitCocone F := Classical.choice <| HasColimit.exists_colimit variable (J C) /-- `C` has colimits of shape `J` if there exists a colimit for every functor `F : J ⥤ C`. -/ class HasColimitsOfShape : Prop where /-- All `F : J ⥤ C` have colimits for a fixed `J` -/ has_colimit : ∀ F : J ⥤ C, HasColimit F := by infer_instance /-- `C` has all colimits of size `v₁ u₁` (`HasColimitsOfSize.{v₁ u₁} C`) if it has colimits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasColimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All `F : J ⥤ C` have colimits for all small `J` -/ has_colimits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasColimitsOfShape J C := by infer_instance /-- `C` has all (small) colimits if it has colimits of every shape that is as big as its hom-sets. -/ abbrev HasColimits (C : Type u) [Category.{v} C] : Prop := HasColimitsOfSize.{v, v} C theorem HasColimits.hasColimitsOfShape {C : Type u} [Category.{v} C] [HasColimits C] (J : Type v) [Category.{v} J] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasColimitOfHasColimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasColimitsOfShape J C] (F : J ⥤ C) : HasColimit F := HasColimitsOfShape.has_colimit F -- see Note [lower instance priority] instance (priority := 100) hasColimitsOfShapeOfHasColimitsOfSize {J : Type u₁} [Category.{v₁} J] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J -- Interface to the `HasColimit` class. /-- An arbitrary choice of colimit cocone of a functor. -/ def colimit.cocone (F : J ⥤ C) [HasColimit F] : Cocone F := (getColimitCocone F).cocone /-- An arbitrary choice of colimit object of a functor. -/ def colimit (F : J ⥤ C) [HasColimit F] := (colimit.cocone F).pt /-- The coprojection from a value of the functor to the colimit object. -/ def colimit.ι (F : J ⥤ C) [HasColimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j @[simp] theorem colimit.cocone_ι {F : J ⥤ C} [HasColimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl @[simp] theorem colimit.cocone_x {F : J ⥤ C} [HasColimit F] : (colimit.cocone F).pt = colimit F := rfl @[reassoc (attr := simp)] theorem colimit.w (F : J ⥤ C) [HasColimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f /-- Evidence that the arbitrary choice of cocone is a colimit cocone. -/ def colimit.isColimit (F : J ⥤ C) [HasColimit F] : IsColimit (colimit.cocone F) := (getColimitCocone F).isColimit /-- The morphism from the colimit object to the cone point of any other cocone. -/ def colimit.desc (F : J ⥤ C) [HasColimit F] (c : Cocone F) : colimit F ⟶ c.pt := (colimit.isColimit F).desc c @[simp] theorem colimit.isColimit_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.isColimit F).desc c = colimit.desc F c := rfl /-- We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`, and combined with `colimit.ext` we rely on these lemmas for many calculations. However, since `Category.assoc` is a `@[simp]` lemma, often expressions are right associated, and it's hard to apply these lemmas about `colimit.ι`. We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism. (see `Tactic/reassoc_axiom.lean`) -/ @[reassoc (attr := simp)] theorem colimit.ι_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := IsColimit.fac _ c j /-- Functoriality of colimits. Usually this morphism should be accessed through `colim.map`, but may be needed separately when you have specified colimits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) : colimit F ⟶ colimit G := IsColimit.map (colimit.isColimit F) _ α @[reassoc (attr := simp)] theorem ι_colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) (j : J) : colimit.ι F j ≫ colimMap α = α.app j ≫ colimit.ι G j := colimit.ι_desc _ j /-- The cocone morphism from the arbitrary choice of colimit cocone to any cocone. -/ def colimit.coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) : colimit.cocone F ⟶ c := (colimit.isColimit F).descCoconeMorphism c @[simp] theorem colimit.coconeMorphism_hom {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.coconeMorphism c).hom = colimit.desc F c := rfl theorem colimit.ι_coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ (colimit.coconeMorphism c).hom = c.ι.app j := by simp @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_hom {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hc).hom = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _ @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_inv {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso hc (colimit.isColimit _)).inv = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _ theorem colimit.existsUnique {F : J ⥤ C} [HasColimit F] (t : Cocone F) : ∃! d : colimit F ⟶ t.pt, ∀ j, colimit.ι F j ≫ d = t.ι.app j := (colimit.isColimit F).existsUnique _ /-- Given any other colimit cocone for `F`, the chosen `colimit F` is isomorphic to the cocone point. -/ def colimit.isoColimitCocone {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) : colimit F ≅ t.cocone.pt := IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) t.isColimit @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_hom {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : colimit.ι F j ≫ (colimit.isoColimitCocone t).hom = t.cocone.ι.app j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_inv {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : t.cocone.ι.app j ≫ (colimit.isoColimitCocone t).inv = colimit.ι F j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] aesop_cat @[ext] theorem colimit.hom_ext {F : J ⥤ C} [HasColimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.isColimit F).hom_ext w @[simp] theorem colimit.desc_cocone {F : J ⥤ C} [HasColimit F] : colimit.desc F (colimit.cocone F) = 𝟙 (colimit F) := (colimit.isColimit _).desc_self /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and cocones with cone point `W`. -/ def colimit.homIso (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ F.cocones.obj W := (colimit.isColimit F).homIso W @[simp] theorem colimit.homIso_hom (F : J ⥤ C) [HasColimit F] {W : C} (f : ULift (colimit F ⟶ W)) : (colimit.homIso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f.down := (colimit.isColimit F).homIso_hom f /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and an explicit componentwise description of cocones with cone point `W`. -/ def colimit.homIso' (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.isColimit F).homIso' W theorem colimit.desc_extend (F : J ⥤ C) [HasColimit F] (c : Cocone F) {X : C} (f : c.pt ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := by ext1; rw [← Category.assoc]; simp -- This has the isomorphism pointing in the opposite direction than in `has_limit_of_iso`. -- This is intentional; it seems to help with elaboration. /-- If `F` has a colimit, so does any naturally isomorphic functor. -/ theorem hasColimitOfIso {F G : J ⥤ C} [HasColimit F] (α : G ≅ F) : HasColimit G := HasColimit.mk { cocone := (Cocones.precompose α.hom).obj (colimit.cocone F) isColimit := (IsColimit.precomposeHomEquiv _ _).symm (colimit.isColimit F) } /-- If a functor `G` has the same collection of cocones as a functor `F` which has a colimit, then `G` also has a colimit. -/ theorem HasColimit.ofCoconesIso {K : Type u₁} [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cocones ≅ G.cocones) [HasColimit F] : HasColimit G := HasColimit.mk ⟨_, IsColimit.ofNatIso (IsColimit.natIso (colimit.isColimit F) ≪≫ h)⟩ /-- The colimits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasColimit.isoOfNatIso {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfNatIso (colimit.isColimit F) (colimit.isColimit G) w @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_hom {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfNatIso w).hom = w.hom.app j ≫ colimit.ι G j := IsColimit.comp_coconePointsIsoOfNatIso_hom _ _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_inv {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι G j ≫ (HasColimit.isoOfNatIso w).inv = w.inv.app j ≫ colimit.ι F j := IsColimit.comp_coconePointsIsoOfNatIso_inv _ _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_hom_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone G) (w : F ≅ G) : (HasColimit.isoOfNatIso w).hom ≫ colimit.desc G t = colimit.desc F ((Cocones.precompose w.hom).obj _) := IsColimit.coconePointsIsoOfNatIso_hom_desc _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_inv_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone F) (w : F ≅ G) : (HasColimit.isoOfNatIso w).inv ≫ colimit.desc F t = colimit.desc G ((Cocones.precompose w.inv).obj _) := IsColimit.coconePointsIsoOfNatIso_inv_desc _ _ _ /-- The colimits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasColimit.isoOfEquivalence {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfEquivalence (colimit.isColimit F) (colimit.isColimit G) e w @[simp] theorem HasColimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfEquivalence e w).hom = F.map (e.unit.app j) ≫ w.inv.app _ ≫ colimit.ι G _ := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] @[simp] theorem HasColimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : colimit.ι G k ≫ (HasColimit.isoOfEquivalence e w).inv = G.map (e.counitInv.app k) ≫ w.hom.app (e.inverse.obj k) ≫ colimit.ι F (e.inverse.obj k) := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] section Pre variable (F) variable [HasColimit F] (E : K ⥤ J) [HasColimit (E ⋙ F)] /-- The canonical morphism from the colimit of `E ⋙ F` to the colimit of `F`. -/ def colimit.pre : colimit (E ⋙ F) ⟶ colimit F := colimit.desc (E ⋙ F) ((colimit.cocone F).whisker E) @[reassoc (attr := simp)] theorem colimit.ι_pre (k : K) : colimit.ι (E ⋙ F) k ≫ colimit.pre F E = colimit.ι F (E.obj k) := by erw [IsColimit.fac] rfl @[reassoc (attr := simp)] theorem colimit.pre_desc (c : Cocone F) : colimit.pre F E ≫ colimit.desc F c = colimit.desc (E ⋙ F) (c.whisker E) := by ext; rw [← assoc, colimit.ι_pre]; simp variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) @[simp] theorem colimit.pre_pre [h : HasColimit (D ⋙ E ⋙ F)] : haveI : HasColimit ((D ⋙ E) ⋙ F) := h colimit.pre (E ⋙ F) D ≫ colimit.pre F E = colimit.pre F (D ⋙ E) := by ext j rw [← assoc, colimit.ι_pre, colimit.ι_pre] haveI : HasColimit ((D ⋙ E) ⋙ F) := h exact (colimit.ι_pre F (D ⋙ E) j).symm variable {E F} /-- - If we have particular colimit cocones available for `E ⋙ F` and for `F`, we obtain a formula for `colimit.pre F E`. -/ theorem colimit.pre_eq (s : ColimitCocone (E ⋙ F)) (t : ColimitCocone F) : colimit.pre F E = (colimit.isoColimitCocone s).hom ≫ s.isColimit.desc (t.cocone.whisker E) ≫ (colimit.isoColimitCocone t).inv := by aesop_cat end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F) variable [HasColimit F] (G : C ⥤ D) [HasColimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the colimit of `F ⋙ G` to `G` applied to the colimit of `F`. -/ def colimit.post : colimit (F ⋙ G) ⟶ G.obj (colimit F) := colimit.desc (F ⋙ G) (G.mapCocone (colimit.cocone F)) @[reassoc (attr := simp)] theorem colimit.ι_post (j : J) : colimit.ι (F ⋙ G) j ≫ colimit.post F G = G.map (colimit.ι F j) := by erw [IsColimit.fac] rfl @[simp] theorem colimit.post_desc (c : Cocone F) : colimit.post F G ≫ G.map (colimit.desc F c) = colimit.desc (F ⋙ G) (G.mapCocone c) := by ext rw [← assoc, colimit.ι_post, ← G.map_comp, colimit.ι_desc, colimit.ι_desc] rfl @[simp] theorem colimit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) -- H G (colimit F) ⟶ H (colimit (F ⋙ G)) ⟶ colimit ((F ⋙ G) ⋙ H) equals -- H G (colimit F) ⟶ colimit (F ⋙ (G ⋙ H)) [h : HasColimit ((F ⋙ G) ⋙ H)] : haveI : HasColimit (F ⋙ G ⋙ H) := h colimit.post (F ⋙ G) H ≫ H.map (colimit.post F G) = colimit.post F (G ⋙ H) := by ext j rw [← assoc, colimit.ι_post, ← H.map_comp, colimit.ι_post] haveI : HasColimit (F ⋙ G ⋙ H) := h exact (colimit.ι_post F (G ⋙ H) j).symm end Post theorem colimit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasColimit F] [HasColimit (E ⋙ F)] [HasColimit (F ⋙ G)] [h : HasColimit ((E ⋙ F) ⋙ G)] : -- G (colimit F) ⟶ G (colimit (E ⋙ F)) ⟶ colimit ((E ⋙ F) ⋙ G) vs -- G (colimit F) ⟶ colimit F ⋙ G ⟶ colimit (E ⋙ (F ⋙ G)) or haveI : HasColimit (E ⋙ F ⋙ G) := h colimit.post (E ⋙ F) G ≫ G.map (colimit.pre F E) = colimit.pre (F ⋙ G) E ≫ colimit.post F G := by ext j rw [← assoc, colimit.ι_post, ← G.map_comp, colimit.ι_pre, ← assoc] haveI : HasColimit (E ⋙ F ⋙ G) := h erw [colimit.ι_pre (F ⋙ G) E j, colimit.ι_post] open CategoryTheory.Equivalence instance hasColimit_equivalence_comp (e : K ≌ J) [HasColimit F] : HasColimit (e.functor ⋙ F) := HasColimit.mk { cocone := Cocone.whisker e.functor (colimit.cocone F) isColimit := IsColimit.whiskerEquivalence (colimit.isColimit F) e } /-- If a `E ⋙ F` has a colimit, and `E` is an equivalence, we can construct a colimit of `F`. -/ theorem hasColimit_of_equivalence_comp (e : K ≌ J) [HasColimit (e.functor ⋙ F)] : HasColimit F := by haveI : HasColimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasColimit_equivalence_comp e.symm apply hasColimitOfIso (e.invFunIdAssoc F).symm section ColimFunctor variable [HasColimitsOfShape J C] section -- attribute [local simp] colimMap -- Porting note: errors out colim.map_id and map_comp now /-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/ @[simps] -- Porting note: simps on all fields now def colim : (J ⥤ C) ⥤ C where obj F := colimit F map α := colimMap α end variable {G : J ⥤ C} (α : F ⟶ G) -- @[reassoc (attr := simp)] Porting note: now simp can prove these @[reassoc] theorem colimit.ι_map (j : J) : colimit.ι F j ≫ colim.map α = α.app j ≫ colimit.ι G j := by simp @[simp] -- Porting note: proof adjusted to account for @[simps] on all fields of colim theorem colimit.map_desc (c : Cocone G) : colimMap α ≫ colimit.desc G c = colimit.desc F ((Cocones.precompose α).obj c) := by ext j simp [← assoc, colimit.ι_map, assoc, colimit.ι_desc, colimit.ι_desc] theorem colimit.pre_map [HasColimitsOfShape K C] (E : K ⥤ J) : colimit.pre F E ≫ colim.map α = colim.map (whiskerLeft E α) ≫ colimit.pre G E := by ext rw [← assoc, colimit.ι_pre, colimit.ι_map, ← assoc, colimit.ι_map, assoc, colimit.ι_pre] rfl theorem colimit.pre_map' [HasColimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : colimit.pre F E₁ = colim.map (whiskerRight α F) ≫ colimit.pre F E₂ := by ext1 simp [← assoc, assoc] theorem colimit.pre_id (F : J ⥤ C) : colimit.pre F (𝟭 _) = colim.map (Functor.leftUnitor F).hom := by aesop_cat theorem colimit.map_post {D : Type u'} [Category.{v'} D] [HasColimitsOfShape J D] (H : C ⥤ D) :/- H (colimit F) ⟶ H (colimit G) ⟶ colimit (G ⋙ H) vs H (colimit F) ⟶ colimit (F ⋙ H) ⟶ colimit (G ⋙ H) -/ colimit.post F H ≫ H.map (colim.map α) = colim.map (whiskerRight α H) ≫ colimit.post G H := by ext rw [← assoc, colimit.ι_post, ← H.map_comp, colimit.ι_map, H.map_comp] rw [← assoc, colimit.ι_map, assoc, colimit.ι_post] rfl /-- The isomorphism between morphisms from the cone point of the colimit cocone for `F` to `W` and cocones over `F` with cone point `W` is natural in `F`. -/ def colimCoyoneda : colim.op ⋙ coyoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cocones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => colimit.homIso (unop F) W /-- The colimit functor and constant functor are adjoint to each other -/ def colimConstAdj : (colim : (J ⥤ C) ⥤ C) ⊣ const J where homEquiv f c := { toFun := fun g => { app := fun _ => colimit.ι _ _ ≫ g } invFun := fun g => colimit.desc _ ⟨_, g⟩ left_inv := by aesop_cat right_inv := by aesop_cat } unit := { app := fun g => { app := colimit.ι _ } } counit := { app := fun c => colimit.desc _ ⟨_, 𝟙 _⟩ } instance : IsLeftAdjoint (colim : (J ⥤ C) ⥤ C) := ⟨_, ⟨colimConstAdj⟩⟩ end ColimFunctor instance colimMap_epi' {F G : J ⥤ C} [HasColimitsOfShape J C] (α : F ⟶ G) [Epi α] : Epi (colimMap α) := (colim : (J ⥤ C) ⥤ C).map_epi α instance colimMap_epi {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) [∀ j, Epi (α.app j)] : Epi (colimMap α) := ⟨fun {Z} u v h => colimit.hom_ext fun j => (cancel_epi (α.app j)).1 <| by simpa using colimit.ι _ j ≫= h⟩ /-- We can transport colimits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasColimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasColimitsOfShape J C] : HasColimitsOfShape J' C := by constructor intro F apply hasColimit_of_equivalence_comp e variable (C) /-- A category that has larger colimits also has smaller colimits. -/ theorem hasColimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfSize.{v₂, u₂} C where has_colimits_of_shape J {_} := hasColimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasColimitsOfSizeShrink.{v u} C` tries to obtain `HasColimitsOfSize.{v u} C` from some other `HasColimitsOfSize C`. -/ theorem hasColimitsOfSizeShrink [HasColimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasColimitsOfSize.{v₁, u₁} C := hasColimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C instance (priority := 100) hasSmallestColimitsOfHasColimits [HasColimits C] : HasColimitsOfSize.{0, 0} C := hasColimitsOfSizeShrink.{0, 0} C end Colimit section Opposite /-- If `t : Cone F` is a limit cone, then `t.op : Cocone F.op` is a colimit cocone. -/ def IsLimit.op {t : Cone F} (P : IsLimit t) : IsColimit t.op where desc s := (P.lift s.unop).op fac s j := congrArg Quiver.Hom.op (P.fac s.unop (unop j)) uniq s m w := by dsimp rw [← P.uniq s.unop m.unop] · rfl · dsimp intro j rw [← w] rfl /-- If `t : Cocone F` is a colimit cocone, then `t.op : Cone F.op` is a limit cone. -/ def IsColimit.op {t : Cocone F} (P : IsColimit t) : IsLimit t.op where lift s := (P.desc s.unop).op fac s j := congrArg Quiver.Hom.op (P.fac s.unop (unop j)) uniq s m w := by dsimp rw [← P.uniq s.unop m.unop] · rfl · dsimp intro j rw [← w] rfl /-- If `t : Cone F.op` is a limit cone, then `t.unop : Cocone F` is a colimit cocone. -/ def IsLimit.unop {t : Cone F.op} (P : IsLimit t) : IsColimit t.unop where desc s := (P.lift s.op).unop fac s j := congrArg Quiver.Hom.unop (P.fac s.op (Opposite.op j)) -- Porting note: thinks `op j` is `IsLimit.op j` uniq s m w := by dsimp rw [← P.uniq s.op m.op] · rfl · dsimp intro j rw [← w] rfl /-- If `t : Cocone F.op` is a colimit cocone, then `t.unop : Cone F.` is a limit cone. -/ def IsColimit.unop {t : Cocone F.op} (P : IsColimit t) : IsLimit t.unop where lift s := (P.desc s.op).unop fac s j := congrArg Quiver.Hom.unop (P.fac s.op (Opposite.op j)) -- Porting note: thinks `op j` is `IsLimit.op j` uniq s m w := by dsimp rw [← P.uniq s.op m.op] · rfl · dsimp intro j rw [← w] rfl /-- `t : Cone F` is a limit cone if and only if `t.op : Cocone F.op` is a colimit cocone. -/ def isLimitEquivIsColimitOp {t : Cone F} : IsLimit t ≃ IsColimit t.op := equivOfSubsingletonOfSubsingleton IsLimit.op fun P => P.unop.ofIsoLimit (Cones.ext (Iso.refl _)) /-- `t : Cocone F` is a colimit cocone if and only if `t.op : Cone F.op` is a limit cone. -/ def isColimitEquivIsLimitOp {t : Cocone F} : IsColimit t ≃ IsLimit t.op := equivOfSubsingletonOfSubsingleton IsColimit.op fun P => P.unop.ofIsoColimit (Cocones.ext (Iso.refl _)) end Opposite end Limits end CategoryTheory
CategoryTheory\Limits\IndYoneda.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Preserves.Limits import Mathlib.CategoryTheory.Limits.Yoneda /-! # Ind- and pro- (co)yoneda lemmas We define limit versions of the yoneda and coyoneda lemmas. ## Main results Notation: categories `C`, `I` and functors `D : Iᵒᵖ ⥤ C`, `F : C ⥤ Type`. - `colimitCoyonedaHomIsoLimit`: pro-coyoneda lemma: homorphisms from colimit of coyoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. - `colimitCoyonedaHomIsoLimit'`: a variant of `colimitCoyonedaHomIsoLimit` for a covariant diagram. ## TODO - define the ind-yoneda versions (for contravariant `F`) -/ universe u₁ u₂ v₁ v₂ namespace CategoryTheory namespace Limits open Opposite variable {C : Type u₁} [Category.{u₂} C] {I : Type v₁} [Category.{v₂} I] section LimitOpColimit instance (F : I ⥤ C) [HasColimit F] : HasLimit F.op := hasLimit_op_of_hasColimit F /-- The limit of `F.op` is the opposite of `colimit F`. -/ noncomputable def limitOpIsoOpColimit (F : I ⥤ C) [HasColimit F] : limit F.op ≅ op <| colimit F := limit.isoLimitCone ⟨(colimit.cocone F).op, (colimit.isColimit F).op⟩ @[reassoc (attr := simp)] lemma limitOpIsoOpColimit_inv_comp_π (F : I ⥤ C) [HasColimit F] (i : I) : (limitOpIsoOpColimit F).inv ≫ limit.π F.op ⟨i⟩ = (colimit.ι F i).op := by simp [limitOpIsoOpColimit] @[reassoc (attr := simp)] lemma limitOpIsoOpColimit_hom_comp_ι (F : I ⥤ C) [HasColimit F] (i : I) : (limitOpIsoOpColimit F).hom ≫ (colimit.ι F i).op = limit.π F.op ⟨i⟩ := by rw [← limitOpIsoOpColimit_inv_comp_π, ← Category.assoc, Iso.hom_inv_id, Category.id_comp] instance (F : Iᵒᵖ ⥤ C) [HasColimit F] : HasLimit F.rightOp where exists_limit := ⟨⟨coneRightOpOfCocone (colimit.cocone F), isLimitConeRightOpOfCocone F (colimit.isColimit F)⟩⟩ /-- `limitOpIsoOpColimit` for contravariant functor. -/ noncomputable def limitRightOpIsoOpColimit (F : Iᵒᵖ ⥤ C) [HasColimit F] : limit F.rightOp ≅ op <| colimit F := limit.isoLimitCone ⟨coneRightOpOfCocone (colimit.cocone F), isLimitConeRightOpOfCocone F (colimit.isColimit F)⟩ @[reassoc (attr := simp)] lemma limitRightOpIsoOpColimit_inv_comp_π (F : Iᵒᵖ ⥤ C) [HasColimit F] (i : I) : (limitRightOpIsoOpColimit F).inv ≫ limit.π F.rightOp i = (colimit.ι F ⟨i⟩).op := by simp [limitRightOpIsoOpColimit] @[reassoc (attr := simp)] lemma limitRightOpIsoOpColimit_hom_comp_ι (F : Iᵒᵖ ⥤ C) [HasColimit F] (i : I) : (limitRightOpIsoOpColimit F).hom ≫ (colimit.ι F ⟨i⟩).op = limit.π F.rightOp i := by rw [← limitRightOpIsoOpColimit_inv_comp_π, ← Category.assoc, Iso.hom_inv_id, Category.id_comp] end LimitOpColimit section HomCocontinuousCovariant variable (F : I ⥤ C) [HasColimit F] /-- Hom is functorially cocontinuous: coyoneda of a colimit is the limit over coyoneda of the diagram. -/ noncomputable def coyonedaOpColimitIsoLimitCoyoneda : coyoneda.obj (op <| colimit F) ≅ limit (F.op ⋙ coyoneda) := coyoneda.mapIso (limitOpIsoOpColimit F).symm ≪≫ (preservesLimitIso coyoneda F.op) @[reassoc (attr := simp)] lemma coyonedaOpColimitIsoLimitCoyoneda_hom_comp_π (i : I) : (coyonedaOpColimitIsoLimitCoyoneda F).hom ≫ limit.π (F.op.comp coyoneda) ⟨i⟩ = coyoneda.map (colimit.ι F i).op := by simp only [coyonedaOpColimitIsoLimitCoyoneda, Functor.mapIso_symm, Iso.trans_hom, Iso.symm_hom, Functor.mapIso_inv, Category.assoc, preservesLimitsIso_hom_π, ← Functor.map_comp, limitOpIsoOpColimit_inv_comp_π] @[reassoc (attr := simp)] lemma coyonedaOpColimitIsoLimitCoyoneda_inv_comp_π (i : I) : (coyonedaOpColimitIsoLimitCoyoneda F).inv ≫ coyoneda.map (colimit.ι F i).op = limit.π (F.op.comp coyoneda) ⟨i⟩ := by rw [← coyonedaOpColimitIsoLimitCoyoneda_hom_comp_π, ← Category.assoc, Iso.inv_hom_id, Category.id_comp] /-- Hom is cocontinuous: homomorphisms from a colimit is the limit over yoneda of the diagram. -/ noncomputable def colimitHomIsoLimitYoneda [HasLimitsOfShape Iᵒᵖ (Type u₂)] (A : C) : (colimit F ⟶ A) ≅ limit (F.op ⋙ yoneda.obj A) := (coyonedaOpColimitIsoLimitCoyoneda F).app A ≪≫ limitObjIsoLimitCompEvaluation _ _ @[reassoc (attr := simp)] lemma colimitHomIsoLimitYoneda_hom_comp_π [HasLimitsOfShape Iᵒᵖ (Type u₂)] (A : C) (i : I) : (colimitHomIsoLimitYoneda F A).hom ≫ limit.π (F.op ⋙ yoneda.obj A) ⟨i⟩ = (coyoneda.map (colimit.ι F i).op).app A := by simp only [colimitHomIsoLimitYoneda, Iso.trans_hom, Iso.app_hom, Category.assoc] erw [limitObjIsoLimitCompEvaluation_hom_π] change ((coyonedaOpColimitIsoLimitCoyoneda F).hom ≫ _).app A = _ rw [coyonedaOpColimitIsoLimitCoyoneda_hom_comp_π] @[reassoc (attr := simp)] lemma colimitHomIsoLimitYoneda_inv_comp_π [HasLimitsOfShape Iᵒᵖ (Type u₂)] (A : C) (i : I) : (colimitHomIsoLimitYoneda F A).inv ≫ (coyoneda.map (colimit.ι F i).op).app A = limit.π (F.op ⋙ yoneda.obj A) ⟨i⟩ := by rw [← colimitHomIsoLimitYoneda_hom_comp_π, ← Category.assoc, Iso.inv_hom_id, Category.id_comp] end HomCocontinuousCovariant section HomCocontinuousContravariant variable (F : Iᵒᵖ ⥤ C) [HasColimit F] /-- Variant of `coyonedaOoColimitIsoLimitCoyoneda` for contravariant `F`. -/ noncomputable def coyonedaOpColimitIsoLimitCoyoneda' : coyoneda.obj (op <| colimit F) ≅ limit (F.rightOp ⋙ coyoneda) := coyoneda.mapIso (limitRightOpIsoOpColimit F).symm ≪≫ preservesLimitIso coyoneda F.rightOp @[reassoc (attr := simp)] lemma coyonedaOpColimitIsoLimitCoyoneda'_hom_comp_π (i : I) : (coyonedaOpColimitIsoLimitCoyoneda' F).hom ≫ limit.π (F.rightOp ⋙ coyoneda) i = coyoneda.map (colimit.ι F ⟨i⟩).op := by simp only [coyonedaOpColimitIsoLimitCoyoneda', Functor.mapIso_symm, Iso.trans_hom, Iso.symm_hom, Functor.mapIso_inv, Category.assoc, preservesLimitsIso_hom_π, ← Functor.map_comp, limitRightOpIsoOpColimit_inv_comp_π] @[reassoc (attr := simp)] lemma coyonedaOpColimitIsoLimitCoyoneda'_inv_comp_π (i : I) : (coyonedaOpColimitIsoLimitCoyoneda' F).inv ≫ coyoneda.map (colimit.ι F ⟨i⟩).op = limit.π (F.rightOp ⋙ coyoneda) i := by rw [← coyonedaOpColimitIsoLimitCoyoneda'_hom_comp_π, ← Category.assoc, Iso.inv_hom_id, Category.id_comp] /-- Variant of `colimitHomIsoLimitYoneda` for contravariant `F`. -/ noncomputable def colimitHomIsoLimitYoneda' [HasLimitsOfShape I (Type u₂)] (A : C) : (colimit F ⟶ A) ≅ limit (F.rightOp ⋙ yoneda.obj A) := (coyonedaOpColimitIsoLimitCoyoneda' F).app A ≪≫ limitObjIsoLimitCompEvaluation _ _ @[reassoc (attr := simp)] lemma colimitHomIsoLimitYoneda'_hom_comp_π [HasLimitsOfShape I (Type u₂)] (A : C) (i : I) : (colimitHomIsoLimitYoneda' F A).hom ≫ limit.π (F.rightOp ⋙ yoneda.obj A) i = (coyoneda.map (colimit.ι F ⟨i⟩).op).app A := by simp only [yoneda_obj_obj, colimitHomIsoLimitYoneda', Iso.trans_hom, Iso.app_hom, Category.assoc] erw [limitObjIsoLimitCompEvaluation_hom_π] change ((coyonedaOpColimitIsoLimitCoyoneda' F).hom ≫ _).app A = _ rw [coyonedaOpColimitIsoLimitCoyoneda'_hom_comp_π] @[reassoc (attr := simp)] lemma colimitHomIsoLimitYoneda'_inv_comp_π [HasLimitsOfShape I (Type u₂)] (A : C) (i : I) : (colimitHomIsoLimitYoneda' F A).inv ≫ (coyoneda.map (colimit.ι F ⟨i⟩).op).app A = limit.π (F.rightOp ⋙ yoneda.obj A) i := by rw [← colimitHomIsoLimitYoneda'_hom_comp_π, ← Category.assoc, Iso.inv_hom_id, Category.id_comp] end HomCocontinuousContravariant section ProCoyonedaContravariant variable (D : Iᵒᵖ ⥤ C) (F : C ⥤ Type u₂) variable [HasColimit (D.rightOp ⋙ coyoneda)] [HasLimitsOfShape Iᵒᵖ (Type (max u₁ u₂))] /-- Pro-Coyoneda lemma: homorphisms from colimit of coyoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. -/ noncomputable def colimitCoyonedaHomIsoLimit : (colimit (D.rightOp ⋙ coyoneda) ⟶ F) ≅ limit (D ⋙ F ⋙ uliftFunctor.{u₁}) := colimitHomIsoLimitYoneda _ F ≪≫ HasLimit.isoOfNatIso (isoWhiskerLeft (D ⋙ Prod.sectl C F) (coyonedaLemma C)) @[simp] lemma colimitCoyonedaHomIsoLimit_π_apply (f : colimit (D.rightOp ⋙ coyoneda) ⟶ F) (i : I) : limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) (op i) ((colimitCoyonedaHomIsoLimit D F).hom f) = ⟨f.app (D.obj (op i)) ((colimit.ι (D.rightOp ⋙ coyoneda) i).app (D.obj (op i)) (𝟙 (D.obj (op i))))⟩ := by change ((colimitCoyonedaHomIsoLimit D F).hom ≫ (limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) (op i))) f = _ simp only [colimitCoyonedaHomIsoLimit, Iso.trans_hom, Category.assoc, HasLimit.isoOfNatIso_hom_π] rw [← Category.assoc, colimitHomIsoLimitYoneda_hom_comp_π] dsimp [coyonedaLemma, types_comp_apply] erw [coyonedaEquiv_comp, coyonedaEquiv_apply] rfl end ProCoyonedaContravariant section ProCoyonedaCovariant variable (D : I ⥤ C) (F : C ⥤ Type u₂) variable [HasColimit (D.op ⋙ coyoneda)] [HasLimitsOfShape I (Type (max u₁ u₂))] /-- A variant of `colimitCoyonedaHomIsoLimit` for a contravariant diagram. -/ noncomputable def colimitCoyonedaHomIsoLimit' : (colimit (D.op ⋙ coyoneda) ⟶ F) ≅ limit (D ⋙ F ⋙ uliftFunctor.{u₁}) := colimitHomIsoLimitYoneda' _ F ≪≫ HasLimit.isoOfNatIso (isoWhiskerLeft (D ⋙ Prod.sectl C F) (coyonedaLemma C)) @[simp] lemma colimitCoyonedaHomIsoLimit'_π_apply (f : colimit (D.op ⋙ coyoneda) ⟶ F) (i : I) : limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) i ((colimitCoyonedaHomIsoLimit' D F).hom f) = ⟨f.app (D.obj i) ((colimit.ι (D.op ⋙ coyoneda) ⟨i⟩).app (D.obj i) (𝟙 (D.obj i)))⟩ := by change ((colimitCoyonedaHomIsoLimit' D F).hom ≫ (limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) i)) f = _ simp only [colimitCoyonedaHomIsoLimit', Iso.trans_hom, Category.assoc, HasLimit.isoOfNatIso_hom_π] rw [← Category.assoc, colimitHomIsoLimitYoneda'_hom_comp_π] dsimp [coyonedaLemma] erw [coyonedaEquiv_comp, coyonedaEquiv_apply] rfl end ProCoyonedaCovariant end Limits end CategoryTheory
CategoryTheory\Limits\IsConnected.lean
/- Copyright (c) 2024 Paul Reichert. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul Reichert -/ import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.HomCongr /-! # Colimits of connected index categories This file proves two characterizations of connected categories by means of colimits. ## Characterization of connected categories by means of the unit-valued functor First, it is proved that a category `C` is connected if and only if `colim F` is a singleton, where `F : C ⥤ Type w` and `F.obj _ = PUnit` (for arbitrary `w`). See `isConnected_iff_colimit_constPUnitFunctor_iso_pUnit` for the proof of this characterization and `constPUnitFunctor` for the definition of the constant functor used in the statement. A formulation based on `IsColimit` instead of `colimit` is given in `isConnected_iff_isColimit_pUnitCocone`. The `if` direction is also available directly in several formulations: For connected index categories `C`, `PUnit.{w}` is a colimit of the `constPUnitFunctor`, where `w` is arbitrary. See `instHasColimitConstPUnitFunctor`, `isColimitPUnitCocone` and `colimitConstPUnitIsoPUnit`. ## Final functors preserve connectedness of categories (in both directions) `isConnected_iff_of_final` proves that the domain of a final functor is connected if and only if its codomain is connected. ## Tags unit-valued, singleton, colimit -/ universe w v u namespace CategoryTheory.Limits.Types variable (C : Type u) [Category.{v} C] /-- The functor mapping every object to `PUnit`. -/ def constPUnitFunctor : C ⥤ Type w := (Functor.const C).obj PUnit.{w + 1} /-- The cocone on `constPUnitFunctor` with cone point `PUnit`. -/ @[simps] def pUnitCocone : Cocone (constPUnitFunctor.{w} C) where pt := PUnit ι := { app := fun X => id } /-- If `C` is connected, the cocone on `constPUnitFunctor` with cone point `PUnit` is a colimit cocone. -/ noncomputable def isColimitPUnitCocone [IsConnected C] : IsColimit (pUnitCocone.{w} C) where desc s := s.ι.app Classical.ofNonempty fac s j := by ext ⟨⟩ apply constant_of_preserves_morphisms (s.ι.app · PUnit.unit) intros X Y f exact congrFun (s.ι.naturality f).symm PUnit.unit uniq s m h := by ext ⟨⟩ simp [← h Classical.ofNonempty] instance instHasColimitConstPUnitFunctor [IsConnected C] : HasColimit (constPUnitFunctor.{w} C) := ⟨_, isColimitPUnitCocone _⟩ instance instSubsingletonColimitPUnit [IsPreconnected C] [HasColimit (constPUnitFunctor.{w} C)] : Subsingleton (colimit (constPUnitFunctor.{w} C)) where allEq a b := by obtain ⟨c, ⟨⟩, rfl⟩ := jointly_surjective' a obtain ⟨d, ⟨⟩, rfl⟩ := jointly_surjective' b apply constant_of_preserves_morphisms (colimit.ι (constPUnitFunctor C) · PUnit.unit) exact fun c d f => colimit_sound f rfl /-- Given a connected index category, the colimit of the constant unit-valued functor is `PUnit`. -/ noncomputable def colimitConstPUnitIsoPUnit [IsConnected C] : colimit (constPUnitFunctor.{w} C) ≅ PUnit.{w + 1} := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitPUnitCocone.{w} C) /-- Let `F` be a `Type`-valued functor. If two elements `a : F c` and `b : F d` represent the same element of `colimit F`, then `c` and `d` are related by a `Zigzag`. -/ theorem zigzag_of_eqvGen_quot_rel (F : C ⥤ Type w) (c d : Σ j, F.obj j) (h : EqvGen (Quot.Rel F) c d) : Zigzag c.1 d.1 := by induction h with | rel _ _ h => exact Zigzag.of_hom <| Exists.choose h | refl _ => exact Zigzag.refl _ | symm _ _ _ ih => exact zigzag_symmetric ih | trans _ _ _ _ _ ih₁ ih₂ => exact ih₁.trans ih₂ /-- An index category is connected iff the colimit of the constant singleton-valued functor is a singleton. -/ theorem isConnected_iff_colimit_constPUnitFunctor_iso_pUnit [HasColimit (constPUnitFunctor.{w} C)] : IsConnected C ↔ Nonempty (colimit (constPUnitFunctor.{w} C) ≅ PUnit) := by refine ⟨fun _ => ⟨colimitConstPUnitIsoPUnit.{w} C⟩, fun ⟨h⟩ => ?_⟩ have : Nonempty C := nonempty_of_nonempty_colimit <| Nonempty.map h.inv inferInstance refine zigzag_isConnected <| fun c d => ?_ refine zigzag_of_eqvGen_quot_rel _ (constPUnitFunctor C) ⟨c, PUnit.unit⟩ ⟨d, PUnit.unit⟩ ?_ exact colimit_eq <| h.toEquiv.injective rfl theorem isConnected_iff_isColimit_pUnitCocone : IsConnected C ↔ Nonempty (IsColimit (pUnitCocone.{w} C)) := by refine ⟨fun inst => ⟨isColimitPUnitCocone C⟩, fun ⟨h⟩ => ?_⟩ let colimitCocone : ColimitCocone (constPUnitFunctor C) := ⟨pUnitCocone.{w} C, h⟩ have : HasColimit (constPUnitFunctor.{w} C) := ⟨⟨colimitCocone⟩⟩ simp only [isConnected_iff_colimit_constPUnitFunctor_iso_pUnit.{w} C] exact ⟨colimit.isoColimitCocone colimitCocone⟩ universe v₂ u₂ variable {C : Type u} {D : Type u₂} [Category.{v} C] [Category.{v₂} D] /-- The domain of a final functor is connected if and only if its codomain is connected. -/ theorem isConnected_iff_of_final (F : C ⥤ D) [CategoryTheory.Functor.Final F] : IsConnected C ↔ IsConnected D := by rw [isConnected_iff_colimit_constPUnitFunctor_iso_pUnit.{max v u v₂ u₂} C, isConnected_iff_colimit_constPUnitFunctor_iso_pUnit.{max v u v₂ u₂} D] exact Equiv.nonempty_congr <| Iso.isoCongrLeft <| CategoryTheory.Functor.Final.colimitIso F <| constPUnitFunctor.{max u v u₂ v₂} D end CategoryTheory.Limits.Types
CategoryTheory\Limits\IsLimit.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Limits.Cones import Batteries.Tactic.Congr /-! # Limits and colimits We set up the general theory of limits and colimits in a category. In this introduction we only describe the setup for limits; it is repeated, with slightly different names, for colimits. The main structures defined in this file is * `IsLimit c`, for `c : Cone F`, `F : J ⥤ C`, expressing that `c` is a limit cone, See also `CategoryTheory.Limits.HasLimits` which further builds: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] variable {F : J ⥤ C} /-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique cone morphism to `t`. See <https://stacks.math.columbia.edu/tag/002E>. -/ -- porting note (#5171): removed @[nolint has_nonempty_instance] structure IsLimit (t : Cone F) where /-- There is a morphism from any cone point to `t.pt` -/ lift : ∀ s : Cone F, s.pt ⟶ t.pt /-- The map makes the triangle with the two natural transformations commute -/ fac : ∀ (s : Cone F) (j : J), lift s ≫ t.π.app j = s.π.app j := by aesop_cat /-- It is the unique such map to do this -/ uniq : ∀ (s : Cone F) (m : s.pt ⟶ t.pt) (_ : ∀ j : J, m ≫ t.π.app j = s.π.app j), m = lift s := by aesop_cat -- Porting note (#10618): simp can prove this. Linter complains it still exists attribute [-simp, nolint simpNF] IsLimit.mk.injEq attribute [reassoc (attr := simp)] IsLimit.fac namespace IsLimit instance subsingleton {t : Cone F} : Subsingleton (IsLimit t) := ⟨by intro P Q; cases P; cases Q; congr; aesop_cat⟩ /-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cone point of any cone over `F` to the cone point of a limit cone over `G`. -/ def map {F G : J ⥤ C} (s : Cone F) {t : Cone G} (P : IsLimit t) (α : F ⟶ G) : s.pt ⟶ t.pt := P.lift ((Cones.postcompose α).obj s) @[reassoc (attr := simp)] theorem map_π {F G : J ⥤ C} (c : Cone F) {d : Cone G} (hd : IsLimit d) (α : F ⟶ G) (j : J) : hd.map c α ≫ d.π.app j = c.π.app j ≫ α.app j := fac _ _ _ @[simp] theorem lift_self {c : Cone F} (t : IsLimit c) : t.lift c = 𝟙 c.pt := (t.uniq _ _ fun _ => id_comp _).symm -- Repackaging the definition in terms of cone morphisms. /-- The universal morphism from any other cone to a limit cone. -/ @[simps] def liftConeMorphism {t : Cone F} (h : IsLimit t) (s : Cone F) : s ⟶ t where hom := h.lift s theorem uniq_cone_morphism {s t : Cone F} (h : IsLimit t) {f f' : s ⟶ t} : f = f' := have : ∀ {g : s ⟶ t}, g = h.liftConeMorphism s := by intro g; apply ConeMorphism.ext; exact h.uniq _ _ g.w this.trans this.symm /-- Restating the definition of a limit cone in terms of the ∃! operator. -/ theorem existsUnique {t : Cone F} (h : IsLimit t) (s : Cone F) : ∃! l : s.pt ⟶ t.pt, ∀ j, l ≫ t.π.app j = s.π.app j := ⟨h.lift s, h.fac s, h.uniq s⟩ /-- Noncomputably make a limit cone from the existence of unique factorizations. -/ def ofExistsUnique {t : Cone F} (ht : ∀ s : Cone F, ∃! l : s.pt ⟶ t.pt, ∀ j, l ≫ t.π.app j = s.π.app j) : IsLimit t := by choose s hs hs' using ht exact ⟨s, hs, hs'⟩ /-- Alternative constructor for `isLimit`, providing a morphism of cones rather than a morphism between the cone points and separately the factorisation condition. -/ @[simps] def mkConeMorphism {t : Cone F} (lift : ∀ s : Cone F, s ⟶ t) (uniq : ∀ (s : Cone F) (m : s ⟶ t), m = lift s) : IsLimit t where lift s := (lift s).hom uniq s m w := have : ConeMorphism.mk m w = lift s := by apply uniq congrArg ConeMorphism.hom this /-- Limit cones on `F` are unique up to isomorphism. -/ @[simps] def uniqueUpToIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : s ≅ t where hom := Q.liftConeMorphism s inv := P.liftConeMorphism t hom_inv_id := P.uniq_cone_morphism inv_hom_id := Q.uniq_cone_morphism /-- Any cone morphism between limit cones is an isomorphism. -/ theorem hom_isIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (f : s ⟶ t) : IsIso f := ⟨⟨P.liftConeMorphism t, ⟨P.uniq_cone_morphism, Q.uniq_cone_morphism⟩⟩⟩ /-- Limits of `F` are unique up to isomorphism. -/ def conePointUniqueUpToIso {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : s.pt ≅ t.pt := (Cones.forget F).mapIso (uniqueUpToIso P Q) @[reassoc (attr := simp)] theorem conePointUniqueUpToIso_hom_comp {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (j : J) : (conePointUniqueUpToIso P Q).hom ≫ t.π.app j = s.π.app j := (uniqueUpToIso P Q).hom.w _ @[reassoc (attr := simp)] theorem conePointUniqueUpToIso_inv_comp {s t : Cone F} (P : IsLimit s) (Q : IsLimit t) (j : J) : (conePointUniqueUpToIso P Q).inv ≫ s.π.app j = t.π.app j := (uniqueUpToIso P Q).inv.w _ @[reassoc (attr := simp)] theorem lift_comp_conePointUniqueUpToIso_hom {r s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : P.lift r ≫ (conePointUniqueUpToIso P Q).hom = Q.lift r := Q.uniq _ _ (by simp) @[reassoc (attr := simp)] theorem lift_comp_conePointUniqueUpToIso_inv {r s t : Cone F} (P : IsLimit s) (Q : IsLimit t) : Q.lift r ≫ (conePointUniqueUpToIso P Q).inv = P.lift r := P.uniq _ _ (by simp) /-- Transport evidence that a cone is a limit cone across an isomorphism of cones. -/ def ofIsoLimit {r t : Cone F} (P : IsLimit r) (i : r ≅ t) : IsLimit t := IsLimit.mkConeMorphism (fun s => P.liftConeMorphism s ≫ i.hom) fun s m => by rw [← i.comp_inv_eq]; apply P.uniq_cone_morphism @[simp] theorem ofIsoLimit_lift {r t : Cone F} (P : IsLimit r) (i : r ≅ t) (s) : (P.ofIsoLimit i).lift s = P.lift s ≫ i.hom.hom := rfl /-- Isomorphism of cones preserves whether or not they are limiting cones. -/ def equivIsoLimit {r t : Cone F} (i : r ≅ t) : IsLimit r ≃ IsLimit t where toFun h := h.ofIsoLimit i invFun h := h.ofIsoLimit i.symm left_inv := by aesop_cat right_inv := by aesop_cat @[simp] theorem equivIsoLimit_apply {r t : Cone F} (i : r ≅ t) (P : IsLimit r) : equivIsoLimit i P = P.ofIsoLimit i := rfl @[simp] theorem equivIsoLimit_symm_apply {r t : Cone F} (i : r ≅ t) (P : IsLimit t) : (equivIsoLimit i).symm P = P.ofIsoLimit i.symm := rfl /-- If the canonical morphism from a cone point to a limiting cone point is an iso, then the first cone was limiting also. -/ def ofPointIso {r t : Cone F} (P : IsLimit r) [i : IsIso (P.lift t)] : IsLimit t := ofIsoLimit P (by haveI : IsIso (P.liftConeMorphism t).hom := i haveI : IsIso (P.liftConeMorphism t) := Cones.cone_iso_of_hom_iso _ symm apply asIso (P.liftConeMorphism t)) variable {t : Cone F} theorem hom_lift (h : IsLimit t) {W : C} (m : W ⟶ t.pt) : m = h.lift { pt := W, π := { app := fun b => m ≫ t.π.app b } } := h.uniq { pt := W, π := { app := fun b => m ≫ t.π.app b } } m fun b => rfl /-- Two morphisms into a limit are equal if their compositions with each cone morphism are equal. -/ theorem hom_ext (h : IsLimit t) {W : C} {f f' : W ⟶ t.pt} (w : ∀ j, f ≫ t.π.app j = f' ≫ t.π.app j) : f = f' := by rw [h.hom_lift f, h.hom_lift f']; congr; exact funext w /-- Given a right adjoint functor between categories of cones, the image of a limit cone is a limit cone. -/ def ofRightAdjoint {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} {left : Cone F ⥤ Cone G} {right : Cone G ⥤ Cone F} (adj : left ⊣ right) {c : Cone G} (t : IsLimit c) : IsLimit (right.obj c) := mkConeMorphism (fun s => adj.homEquiv s c (t.liftConeMorphism _)) fun _ _ => (Adjunction.eq_homEquiv_apply _ _ _).2 t.uniq_cone_morphism /-- Given two functors which have equivalent categories of cones, we can transport a limiting cone across the equivalence. -/ def ofConeEquiv {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F) {c : Cone G} : IsLimit (h.functor.obj c) ≃ IsLimit c where toFun P := ofIsoLimit (ofRightAdjoint h.toAdjunction P) (h.unitIso.symm.app c) invFun := ofRightAdjoint h.symm.toAdjunction left_inv := by aesop_cat right_inv := by aesop_cat @[simp] theorem ofConeEquiv_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F) {c : Cone G} (P : IsLimit (h.functor.obj c)) (s) : (ofConeEquiv h P).lift s = ((h.unitIso.hom.app s).hom ≫ (h.inverse.map (P.liftConeMorphism (h.functor.obj s))).hom) ≫ (h.unitIso.inv.app c).hom := rfl @[simp] theorem ofConeEquiv_symm_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cone G ≌ Cone F) {c : Cone G} (P : IsLimit c) (s) : ((ofConeEquiv h).symm P).lift s = (h.counitIso.inv.app s).hom ≫ (h.functor.map (P.liftConeMorphism (h.inverse.obj s))).hom := rfl /-- A cone postcomposed with a natural isomorphism is a limit cone if and only if the original cone is. -/ def postcomposeHomEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cone F) : IsLimit ((Cones.postcompose α.hom).obj c) ≃ IsLimit c := ofConeEquiv (Cones.postcomposeEquivalence α) /-- A cone postcomposed with the inverse of a natural isomorphism is a limit cone if and only if the original cone is. -/ def postcomposeInvEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cone G) : IsLimit ((Cones.postcompose α.inv).obj c) ≃ IsLimit c := postcomposeHomEquiv α.symm c /-- Constructing an equivalence `IsLimit c ≃ IsLimit d` from a natural isomorphism between the underlying functors, and then an isomorphism between `c` transported along this and `d`. -/ def equivOfNatIsoOfIso {F G : J ⥤ C} (α : F ≅ G) (c : Cone F) (d : Cone G) (w : (Cones.postcompose α.hom).obj c ≅ d) : IsLimit c ≃ IsLimit d := (postcomposeHomEquiv α _).symm.trans (equivIsoLimit w) /-- The cone points of two limit cones for naturally isomorphic functors are themselves isomorphic. -/ @[simps] def conePointsIsoOfNatIso {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) : s.pt ≅ t.pt where hom := Q.map s w.hom inv := P.map t w.inv hom_inv_id := P.hom_ext (by aesop_cat) inv_hom_id := Q.hom_ext (by aesop_cat) @[reassoc] theorem conePointsIsoOfNatIso_hom_comp {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) (j : J) : (conePointsIsoOfNatIso P Q w).hom ≫ t.π.app j = s.π.app j ≫ w.hom.app j := by simp @[reassoc] theorem conePointsIsoOfNatIso_inv_comp {F G : J ⥤ C} {s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) (j : J) : (conePointsIsoOfNatIso P Q w).inv ≫ s.π.app j = t.π.app j ≫ w.inv.app j := by simp @[reassoc] theorem lift_comp_conePointsIsoOfNatIso_hom {F G : J ⥤ C} {r s : Cone F} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (w : F ≅ G) : P.lift r ≫ (conePointsIsoOfNatIso P Q w).hom = Q.map r w.hom := Q.hom_ext (by simp) @[reassoc] theorem lift_comp_conePointsIsoOfNatIso_inv {F G : J ⥤ C} {r s : Cone G} {t : Cone F} (P : IsLimit t) (Q : IsLimit s) (w : F ≅ G) : Q.lift r ≫ (conePointsIsoOfNatIso P Q w).inv = P.map r w.inv := P.hom_ext (by simp) section Equivalence open CategoryTheory.Equivalence /-- If `s : Cone F` is a limit cone, so is `s` whiskered by an equivalence `e`. -/ def whiskerEquivalence {s : Cone F} (P : IsLimit s) (e : K ≌ J) : IsLimit (s.whisker e.functor) := ofRightAdjoint (Cones.whiskeringEquivalence e).symm.toAdjunction P /-- If `s : Cone F` whiskered by an equivalence `e` is a limit cone, so is `s`. -/ def ofWhiskerEquivalence {s : Cone F} (e : K ≌ J) (P : IsLimit (s.whisker e.functor)) : IsLimit s := equivIsoLimit ((Cones.whiskeringEquivalence e).unitIso.app s).symm (ofRightAdjoint (Cones.whiskeringEquivalence e).toAdjunction P) /-- Given an equivalence of diagrams `e`, `s` is a limit cone iff `s.whisker e.functor` is. -/ def whiskerEquivalenceEquiv {s : Cone F} (e : K ≌ J) : IsLimit s ≃ IsLimit (s.whisker e.functor) := ⟨fun h => h.whiskerEquivalence e, ofWhiskerEquivalence e, by aesop_cat, by aesop_cat⟩ /-- A limit cone extended by an isomorphism is a limit cone. -/ def extendIso {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] (hs : IsLimit s) : IsLimit (s.extend i) := IsLimit.ofIsoLimit hs (Cones.extendIso s (asIso i)).symm /-- A cone is a limit cone if its extension by an isomorphism is. -/ def ofExtendIso {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] (hs : IsLimit (s.extend i)) : IsLimit s := IsLimit.ofIsoLimit hs (Cones.extendIso s (asIso i)) /-- A cone is a limit cone iff its extension by an isomorphism is. -/ def extendIsoEquiv {s : Cone F} {X : C} (i : X ⟶ s.pt) [IsIso i] : IsLimit s ≃ IsLimit (s.extend i) := equivOfSubsingletonOfSubsingleton (extendIso i) (ofExtendIso i) /-- We can prove two cone points `(s : Cone F).pt` and `(t : Cone G).pt` are isomorphic if * both cones are limit cones * their indexing categories are equivalent via some `e : J ≌ K`, * the triangle of functors commutes up to a natural isomorphism: `e.functor ⋙ G ≅ F`. This is the most general form of uniqueness of cone points, allowing relabelling of both the indexing category (up to equivalence) and the functor (up to natural isomorphism). -/ @[simps] def conePointsIsoOfEquivalence {F : J ⥤ C} {s : Cone F} {G : K ⥤ C} {t : Cone G} (P : IsLimit s) (Q : IsLimit t) (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : s.pt ≅ t.pt := let w' : e.inverse ⋙ F ≅ G := (isoWhiskerLeft e.inverse w).symm ≪≫ invFunIdAssoc e G { hom := Q.lift ((Cones.equivalenceOfReindexing e.symm w').functor.obj s) inv := P.lift ((Cones.equivalenceOfReindexing e w).functor.obj t) hom_inv_id := by apply hom_ext P; intro j dsimp [w'] simp only [Limits.Cone.whisker_π, Limits.Cones.postcompose_obj_π, fac, whiskerLeft_app, assoc, id_comp, invFunIdAssoc_hom_app, fac_assoc, NatTrans.comp_app] rw [counit_app_functor, ← Functor.comp_map] have l : NatTrans.app w.hom j = NatTrans.app w.hom (Prefunctor.obj (𝟭 J).toPrefunctor j) := by dsimp rw [l,w.hom.naturality] simp inv_hom_id := by apply hom_ext Q aesop_cat } end Equivalence /-- The universal property of a limit cone: a map `W ⟶ X` is the same as a cone on `F` with cone point `W`. -/ def homIso (h : IsLimit t) (W : C) : ULift.{u₁} (W ⟶ t.pt : Type v₃) ≅ (const J).obj W ⟶ F where hom f := (t.extend f.down).π inv π := ⟨h.lift { pt := W, π }⟩ hom_inv_id := by funext f; apply ULift.ext apply h.hom_ext; intro j; simp @[simp] theorem homIso_hom (h : IsLimit t) {W : C} (f : ULift.{u₁} (W ⟶ t.pt)) : (IsLimit.homIso h W).hom f = (t.extend f.down).π := rfl /-- The limit of `F` represents the functor taking `W` to the set of cones on `F` with cone point `W`. -/ def natIso (h : IsLimit t) : yoneda.obj t.pt ⋙ uliftFunctor.{u₁} ≅ F.cones := NatIso.ofComponents fun W => IsLimit.homIso h (unop W) /-- Another, more explicit, formulation of the universal property of a limit cone. See also `homIso`. -/ def homIso' (h : IsLimit t) (W : C) : ULift.{u₁} (W ⟶ t.pt : Type v₃) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j'} (f : j ⟶ j'), p j ≫ F.map f = p j' } := h.homIso W ≪≫ { hom := fun π => ⟨fun j => π.app j, fun f => by convert ← (π.naturality f).symm; apply id_comp⟩ inv := fun p => { app := fun j => p.1 j naturality := fun j j' f => by dsimp; rw [id_comp]; exact (p.2 f).symm } } /-- If G : C → D is a faithful functor which sends t to a limit cone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def ofFaithful {t : Cone F} {D : Type u₄} [Category.{v₄} D] (G : C ⥤ D) [G.Faithful] (ht : IsLimit (mapCone G t)) (lift : ∀ s : Cone F, s.pt ⟶ t.pt) (h : ∀ s, G.map (lift s) = ht.lift (mapCone G s)) : IsLimit t := { lift fac := fun s j => by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac uniq := fun s m w => by apply G.map_injective; rw [h] refine ht.uniq (mapCone G s) _ fun j => ?_ convert ← congrArg (fun f => G.map f) (w j) apply G.map_comp } /-- If `F` and `G` are naturally isomorphic, then `F.mapCone c` being a limit implies `G.mapCone c` is also a limit. -/ def mapConeEquiv {D : Type u₄} [Category.{v₄} D] {K : J ⥤ C} {F G : C ⥤ D} (h : F ≅ G) {c : Cone K} (t : IsLimit (mapCone F c)) : IsLimit (mapCone G c) := by apply postcomposeInvEquiv (isoWhiskerLeft K h : _) (mapCone G c) _ apply t.ofIsoLimit (postcomposeWhiskerLeftMapCone h.symm c).symm /-- A cone is a limit cone exactly if there is a unique cone morphism from any other cone. -/ def isoUniqueConeMorphism {t : Cone F} : IsLimit t ≅ ∀ s, Unique (s ⟶ t) where hom h s := { default := h.liftConeMorphism s uniq := fun _ => h.uniq_cone_morphism } inv h := { lift := fun s => (h s).default.hom uniq := fun s f w => congrArg ConeMorphism.hom ((h s).uniq ⟨f, w⟩) } namespace OfNatIso variable {X : C} (h : yoneda.obj X ⋙ uliftFunctor.{u₁} ≅ F.cones) /-- If `F.cones` is represented by `X`, each morphism `f : Y ⟶ X` gives a cone with cone point `Y`. -/ def coneOfHom {Y : C} (f : Y ⟶ X) : Cone F where pt := Y π := h.hom.app (op Y) ⟨f⟩ /-- If `F.cones` is represented by `X`, each cone `s` gives a morphism `s.pt ⟶ X`. -/ def homOfCone (s : Cone F) : s.pt ⟶ X := (h.inv.app (op s.pt) s.π).down @[simp] theorem coneOfHom_homOfCone (s : Cone F) : coneOfHom h (homOfCone h s) = s := by dsimp [coneOfHom, homOfCone] match s with | .mk s_pt s_π => congr; dsimp convert congrFun (congrFun (congrArg NatTrans.app h.inv_hom_id) (op s_pt)) s_π using 1 @[simp] theorem homOfCone_coneOfHom {Y : C} (f : Y ⟶ X) : homOfCone h (coneOfHom h f) = f := congrArg ULift.down (congrFun (congrFun (congrArg NatTrans.app h.hom_inv_id) (op Y)) ⟨f⟩ : _) /-- If `F.cones` is represented by `X`, the cone corresponding to the identity morphism on `X` will be a limit cone. -/ def limitCone : Cone F := coneOfHom h (𝟙 X) /-- If `F.cones` is represented by `X`, the cone corresponding to a morphism `f : Y ⟶ X` is the limit cone extended by `f`. -/ theorem coneOfHom_fac {Y : C} (f : Y ⟶ X) : coneOfHom h f = (limitCone h).extend f := by dsimp [coneOfHom, limitCone, Cone.extend] congr with j have t := congrFun (h.hom.naturality f.op) ⟨𝟙 X⟩ dsimp at t simp only [comp_id] at t rw [congrFun (congrArg NatTrans.app t) j] rfl /-- If `F.cones` is represented by `X`, any cone is the extension of the limit cone by the corresponding morphism. -/ theorem cone_fac (s : Cone F) : (limitCone h).extend (homOfCone h s) = s := by rw [← coneOfHom_homOfCone h s] conv_lhs => simp only [homOfCone_coneOfHom] apply (coneOfHom_fac _ _).symm end OfNatIso section open OfNatIso /-- If `F.cones` is representable, then the cone corresponding to the identity morphism on the representing object is a limit cone. -/ def ofNatIso {X : C} (h : yoneda.obj X ⋙ uliftFunctor.{u₁} ≅ F.cones) : IsLimit (limitCone h) where lift s := homOfCone h s fac s j := by have h := cone_fac h s cases s injection h with h₁ h₂ simp only [heq_iff_eq] at h₂ conv_rhs => rw [← h₂] rfl uniq s m w := by rw [← homOfCone_coneOfHom h m] congr rw [coneOfHom_fac] dsimp [Cone.extend]; cases s; congr with j; exact w j end end IsLimit /-- A cocone `t` on `F` is a colimit cocone if each cocone on `F` admits a unique cocone morphism from `t`. See <https://stacks.math.columbia.edu/tag/002F>. -/ -- Porting note(#5171): removed @[nolint has_nonempty_instance] structure IsColimit (t : Cocone F) where /-- `t.pt` maps to all other cocone covertices -/ desc : ∀ s : Cocone F, t.pt ⟶ s.pt /-- The map `desc` makes the diagram with the natural transformations commute -/ fac : ∀ (s : Cocone F) (j : J), t.ι.app j ≫ desc s = s.ι.app j := by aesop_cat /-- `desc` is the unique such map -/ uniq : ∀ (s : Cocone F) (m : t.pt ⟶ s.pt) (_ : ∀ j : J, t.ι.app j ≫ m = s.ι.app j), m = desc s := by aesop_cat attribute [reassoc (attr := simp)] IsColimit.fac -- Porting note (#10618): simp can prove this. Linter claims it still is tagged with simp attribute [-simp, nolint simpNF] IsColimit.mk.injEq namespace IsColimit instance subsingleton {t : Cocone F} : Subsingleton (IsColimit t) := ⟨by intro P Q; cases P; cases Q; congr; aesop_cat⟩ /-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cocone point of a colimit cocone over `F` to the cocone point of any cocone over `G`. -/ def map {F G : J ⥤ C} {s : Cocone F} (P : IsColimit s) (t : Cocone G) (α : F ⟶ G) : s.pt ⟶ t.pt := P.desc ((Cocones.precompose α).obj t) @[reassoc (attr := simp)] theorem ι_map {F G : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (d : Cocone G) (α : F ⟶ G) (j : J) : c.ι.app j ≫ IsColimit.map hc d α = α.app j ≫ d.ι.app j := fac _ _ _ @[simp] theorem desc_self {t : Cocone F} (h : IsColimit t) : h.desc t = 𝟙 t.pt := (h.uniq _ _ fun _ => comp_id _).symm -- Repackaging the definition in terms of cocone morphisms. /-- The universal morphism from a colimit cocone to any other cocone. -/ @[simps] def descCoconeMorphism {t : Cocone F} (h : IsColimit t) (s : Cocone F) : t ⟶ s where hom := h.desc s theorem uniq_cocone_morphism {s t : Cocone F} (h : IsColimit t) {f f' : t ⟶ s} : f = f' := have : ∀ {g : t ⟶ s}, g = h.descCoconeMorphism s := by intro g; ext; exact h.uniq _ _ g.w this.trans this.symm /-- Restating the definition of a colimit cocone in terms of the ∃! operator. -/ theorem existsUnique {t : Cocone F} (h : IsColimit t) (s : Cocone F) : ∃! d : t.pt ⟶ s.pt, ∀ j, t.ι.app j ≫ d = s.ι.app j := ⟨h.desc s, h.fac s, h.uniq s⟩ /-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/ def ofExistsUnique {t : Cocone F} (ht : ∀ s : Cocone F, ∃! d : t.pt ⟶ s.pt, ∀ j, t.ι.app j ≫ d = s.ι.app j) : IsColimit t := by choose s hs hs' using ht exact ⟨s, hs, hs'⟩ /-- Alternative constructor for `IsColimit`, providing a morphism of cocones rather than a morphism between the cocone points and separately the factorisation condition. -/ @[simps] def mkCoconeMorphism {t : Cocone F} (desc : ∀ s : Cocone F, t ⟶ s) (uniq' : ∀ (s : Cocone F) (m : t ⟶ s), m = desc s) : IsColimit t where desc s := (desc s).hom uniq s m w := have : CoconeMorphism.mk m w = desc s := by apply uniq' congrArg CoconeMorphism.hom this /-- Colimit cocones on `F` are unique up to isomorphism. -/ @[simps] def uniqueUpToIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : s ≅ t where hom := P.descCoconeMorphism t inv := Q.descCoconeMorphism s hom_inv_id := P.uniq_cocone_morphism inv_hom_id := Q.uniq_cocone_morphism /-- Any cocone morphism between colimit cocones is an isomorphism. -/ theorem hom_isIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) (f : s ⟶ t) : IsIso f := ⟨⟨Q.descCoconeMorphism s, ⟨P.uniq_cocone_morphism, Q.uniq_cocone_morphism⟩⟩⟩ /-- Colimits of `F` are unique up to isomorphism. -/ def coconePointUniqueUpToIso {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : s.pt ≅ t.pt := (Cocones.forget F).mapIso (uniqueUpToIso P Q) @[reassoc (attr := simp)] theorem comp_coconePointUniqueUpToIso_hom {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) (j : J) : s.ι.app j ≫ (coconePointUniqueUpToIso P Q).hom = t.ι.app j := (uniqueUpToIso P Q).hom.w _ @[reassoc (attr := simp)] theorem comp_coconePointUniqueUpToIso_inv {s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) (j : J) : t.ι.app j ≫ (coconePointUniqueUpToIso P Q).inv = s.ι.app j := (uniqueUpToIso P Q).inv.w _ @[reassoc (attr := simp)] theorem coconePointUniqueUpToIso_hom_desc {r s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : (coconePointUniqueUpToIso P Q).hom ≫ Q.desc r = P.desc r := P.uniq _ _ (by simp) @[reassoc (attr := simp)] theorem coconePointUniqueUpToIso_inv_desc {r s t : Cocone F} (P : IsColimit s) (Q : IsColimit t) : (coconePointUniqueUpToIso P Q).inv ≫ P.desc r = Q.desc r := Q.uniq _ _ (by simp) /-- Transport evidence that a cocone is a colimit cocone across an isomorphism of cocones. -/ def ofIsoColimit {r t : Cocone F} (P : IsColimit r) (i : r ≅ t) : IsColimit t := IsColimit.mkCoconeMorphism (fun s => i.inv ≫ P.descCoconeMorphism s) fun s m => by rw [i.eq_inv_comp]; apply P.uniq_cocone_morphism @[simp] theorem ofIsoColimit_desc {r t : Cocone F} (P : IsColimit r) (i : r ≅ t) (s) : (P.ofIsoColimit i).desc s = i.inv.hom ≫ P.desc s := rfl /-- Isomorphism of cocones preserves whether or not they are colimiting cocones. -/ def equivIsoColimit {r t : Cocone F} (i : r ≅ t) : IsColimit r ≃ IsColimit t where toFun h := h.ofIsoColimit i invFun h := h.ofIsoColimit i.symm left_inv := by aesop_cat right_inv := by aesop_cat @[simp] theorem equivIsoColimit_apply {r t : Cocone F} (i : r ≅ t) (P : IsColimit r) : equivIsoColimit i P = P.ofIsoColimit i := rfl @[simp] theorem equivIsoColimit_symm_apply {r t : Cocone F} (i : r ≅ t) (P : IsColimit t) : (equivIsoColimit i).symm P = P.ofIsoColimit i.symm := rfl /-- If the canonical morphism to a cocone point from a colimiting cocone point is an iso, then the first cocone was colimiting also. -/ def ofPointIso {r t : Cocone F} (P : IsColimit r) [i : IsIso (P.desc t)] : IsColimit t := ofIsoColimit P (by haveI : IsIso (P.descCoconeMorphism t).hom := i haveI : IsIso (P.descCoconeMorphism t) := Cocones.cocone_iso_of_hom_iso _ apply asIso (P.descCoconeMorphism t)) variable {t : Cocone F} theorem hom_desc (h : IsColimit t) {W : C} (m : t.pt ⟶ W) : m = h.desc { pt := W ι := { app := fun b => t.ι.app b ≫ m naturality := by intros; erw [← assoc, t.ι.naturality, comp_id, comp_id] } } := h.uniq { pt := W ι := { app := fun b => t.ι.app b ≫ m naturality := _ } } m fun _ => rfl /-- Two morphisms out of a colimit are equal if their compositions with each cocone morphism are equal. -/ theorem hom_ext (h : IsColimit t) {W : C} {f f' : t.pt ⟶ W} (w : ∀ j, t.ι.app j ≫ f = t.ι.app j ≫ f') : f = f' := by rw [h.hom_desc f, h.hom_desc f']; congr; exact funext w /-- Given a left adjoint functor between categories of cocones, the image of a colimit cocone is a colimit cocone. -/ def ofLeftAdjoint {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} {left : Cocone G ⥤ Cocone F} {right : Cocone F ⥤ Cocone G} (adj : left ⊣ right) {c : Cocone G} (t : IsColimit c) : IsColimit (left.obj c) := mkCoconeMorphism (fun s => (adj.homEquiv c s).symm (t.descCoconeMorphism _)) fun _ _ => (Adjunction.homEquiv_apply_eq _ _ _).1 t.uniq_cocone_morphism /-- Given two functors which have equivalent categories of cocones, we can transport a colimiting cocone across the equivalence. -/ def ofCoconeEquiv {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cocone G ≌ Cocone F) {c : Cocone G} : IsColimit (h.functor.obj c) ≃ IsColimit c where toFun P := ofIsoColimit (ofLeftAdjoint h.symm.toAdjunction P) (h.unitIso.symm.app c) invFun := ofLeftAdjoint h.toAdjunction left_inv := by aesop_cat right_inv := by aesop_cat @[simp] theorem ofCoconeEquiv_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cocone G ≌ Cocone F) {c : Cocone G} (P : IsColimit (h.functor.obj c)) (s) : (ofCoconeEquiv h P).desc s = (h.unit.app c).hom ≫ (h.inverse.map (P.descCoconeMorphism (h.functor.obj s))).hom ≫ (h.unitInv.app s).hom := rfl @[simp] theorem ofCoconeEquiv_symm_apply_desc {D : Type u₄} [Category.{v₄} D] {G : K ⥤ D} (h : Cocone G ≌ Cocone F) {c : Cocone G} (P : IsColimit c) (s) : ((ofCoconeEquiv h).symm P).desc s = (h.functor.map (P.descCoconeMorphism (h.inverse.obj s))).hom ≫ (h.counit.app s).hom := rfl /-- A cocone precomposed with a natural isomorphism is a colimit cocone if and only if the original cocone is. -/ def precomposeHomEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cocone G) : IsColimit ((Cocones.precompose α.hom).obj c) ≃ IsColimit c := ofCoconeEquiv (Cocones.precomposeEquivalence α) /-- A cocone precomposed with the inverse of a natural isomorphism is a colimit cocone if and only if the original cocone is. -/ def precomposeInvEquiv {F G : J ⥤ C} (α : F ≅ G) (c : Cocone F) : IsColimit ((Cocones.precompose α.inv).obj c) ≃ IsColimit c := precomposeHomEquiv α.symm c /-- Constructing an equivalence `is_colimit c ≃ is_colimit d` from a natural isomorphism between the underlying functors, and then an isomorphism between `c` transported along this and `d`. -/ def equivOfNatIsoOfIso {F G : J ⥤ C} (α : F ≅ G) (c : Cocone F) (d : Cocone G) (w : (Cocones.precompose α.inv).obj c ≅ d) : IsColimit c ≃ IsColimit d := (precomposeInvEquiv α _).symm.trans (equivIsoColimit w) /-- The cocone points of two colimit cocones for naturally isomorphic functors are themselves isomorphic. -/ @[simps] def coconePointsIsoOfNatIso {F G : J ⥤ C} {s : Cocone F} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) : s.pt ≅ t.pt where hom := P.map t w.hom inv := Q.map s w.inv hom_inv_id := P.hom_ext (by aesop_cat) inv_hom_id := Q.hom_ext (by aesop_cat) @[reassoc] theorem comp_coconePointsIsoOfNatIso_hom {F G : J ⥤ C} {s : Cocone F} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) (j : J) : s.ι.app j ≫ (coconePointsIsoOfNatIso P Q w).hom = w.hom.app j ≫ t.ι.app j := by simp @[reassoc] theorem comp_coconePointsIsoOfNatIso_inv {F G : J ⥤ C} {s : Cocone F} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) (j : J) : t.ι.app j ≫ (coconePointsIsoOfNatIso P Q w).inv = w.inv.app j ≫ s.ι.app j := by simp @[reassoc] theorem coconePointsIsoOfNatIso_hom_desc {F G : J ⥤ C} {s : Cocone F} {r t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (w : F ≅ G) : (coconePointsIsoOfNatIso P Q w).hom ≫ Q.desc r = P.map _ w.hom := P.hom_ext (by simp) @[reassoc] theorem coconePointsIsoOfNatIso_inv_desc {F G : J ⥤ C} {s : Cocone G} {r t : Cocone F} (P : IsColimit t) (Q : IsColimit s) (w : F ≅ G) : (coconePointsIsoOfNatIso P Q w).inv ≫ P.desc r = Q.map _ w.inv := Q.hom_ext (by simp) section Equivalence open CategoryTheory.Equivalence /-- If `s : Cocone F` is a colimit cocone, so is `s` whiskered by an equivalence `e`. -/ def whiskerEquivalence {s : Cocone F} (P : IsColimit s) (e : K ≌ J) : IsColimit (s.whisker e.functor) := ofLeftAdjoint (Cocones.whiskeringEquivalence e).toAdjunction P /-- If `s : Cocone F` whiskered by an equivalence `e` is a colimit cocone, so is `s`. -/ def ofWhiskerEquivalence {s : Cocone F} (e : K ≌ J) (P : IsColimit (s.whisker e.functor)) : IsColimit s := equivIsoColimit ((Cocones.whiskeringEquivalence e).unitIso.app s).symm (ofLeftAdjoint (Cocones.whiskeringEquivalence e).symm.toAdjunction P) /-- Given an equivalence of diagrams `e`, `s` is a colimit cocone iff `s.whisker e.functor` is. -/ def whiskerEquivalenceEquiv {s : Cocone F} (e : K ≌ J) : IsColimit s ≃ IsColimit (s.whisker e.functor) := ⟨fun h => h.whiskerEquivalence e, ofWhiskerEquivalence e, by aesop_cat, by aesop_cat⟩ /-- A colimit cocone extended by an isomorphism is a colimit cocone. -/ def extendIso {s : Cocone F} {X : C} (i : s.pt ⟶ X) [IsIso i] (hs : IsColimit s) : IsColimit (s.extend i) := IsColimit.ofIsoColimit hs (Cocones.extendIso s (asIso i)) /-- A cocone is a colimit cocone if its extension by an isomorphism is. -/ def ofExtendIso {s : Cocone F} {X : C} (i : s.pt ⟶ X) [IsIso i] (hs : IsColimit (s.extend i)) : IsColimit s := IsColimit.ofIsoColimit hs (Cocones.extendIso s (asIso i)).symm /-- A cocone is a colimit cocone iff its extension by an isomorphism is. -/ def extendIsoEquiv {s : Cocone F} {X : C} (i : s.pt ⟶ X) [IsIso i] : IsColimit s ≃ IsColimit (s.extend i) := equivOfSubsingletonOfSubsingleton (extendIso i) (ofExtendIso i) /-- We can prove two cocone points `(s : Cocone F).pt` and `(t : Cocone G).pt` are isomorphic if * both cocones are colimit cocones * their indexing categories are equivalent via some `e : J ≌ K`, * the triangle of functors commutes up to a natural isomorphism: `e.functor ⋙ G ≅ F`. This is the most general form of uniqueness of cocone points, allowing relabelling of both the indexing category (up to equivalence) and the functor (up to natural isomorphism). -/ @[simps] def coconePointsIsoOfEquivalence {F : J ⥤ C} {s : Cocone F} {G : K ⥤ C} {t : Cocone G} (P : IsColimit s) (Q : IsColimit t) (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : s.pt ≅ t.pt := let w' : e.inverse ⋙ F ≅ G := (isoWhiskerLeft e.inverse w).symm ≪≫ invFunIdAssoc e G { hom := P.desc ((Cocones.equivalenceOfReindexing e w).functor.obj t) inv := Q.desc ((Cocones.equivalenceOfReindexing e.symm w').functor.obj s) hom_inv_id := by apply hom_ext P; intro j dsimp [w'] simp only [Limits.Cocone.whisker_ι, fac, invFunIdAssoc_inv_app, whiskerLeft_app, assoc, comp_id, Limits.Cocones.precompose_obj_ι, fac_assoc, NatTrans.comp_app] rw [counitInv_app_functor, ← Functor.comp_map, ← w.inv.naturality_assoc] dsimp simp inv_hom_id := by apply hom_ext Q aesop_cat } end Equivalence /-- The universal property of a colimit cocone: a map `X ⟶ W` is the same as a cocone on `F` with cone point `W`. -/ def homEquiv (h : IsColimit t) (W : C) : (t.pt ⟶ W) ≃ (F ⟶ (const J).obj W) where toFun f := (t.extend f).ι invFun ι := h.desc { pt := W ι } left_inv f := h.hom_ext (by simp) right_inv ι := by aesop_cat @[simp] lemma homEquiv_apply (h : IsColimit t) {W : C} (f : t.pt ⟶ W) : h.homEquiv W f = (t.extend f).ι := rfl /-- The universal property of a colimit cocone: a map `X ⟶ W` is the same as a cocone on `F` with cone point `W`. -/ def homIso (h : IsColimit t) (W : C) : ULift.{u₁} (t.pt ⟶ W : Type v₃) ≅ F ⟶ (const J).obj W := Equiv.toIso (Equiv.ulift.trans (h.homEquiv W)) @[simp] theorem homIso_hom (h : IsColimit t) {W : C} (f : ULift (t.pt ⟶ W)) : (IsColimit.homIso h W).hom f = (t.extend f.down).ι := rfl /-- The colimit of `F` represents the functor taking `W` to the set of cocones on `F` with cone point `W`. -/ def natIso (h : IsColimit t) : coyoneda.obj (op t.pt) ⋙ uliftFunctor.{u₁} ≅ F.cocones := NatIso.ofComponents (IsColimit.homIso h) /-- Another, more explicit, formulation of the universal property of a colimit cocone. See also `homIso`. -/ def homIso' (h : IsColimit t) (W : C) : ULift.{u₁} (t.pt ⟶ W : Type v₃) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j' : J} (f : j ⟶ j'), F.map f ≫ p j' = p j } := h.homIso W ≪≫ { hom := fun ι => ⟨fun j => ι.app j, fun {j} {j'} f => by convert ← ι.naturality f; apply comp_id⟩ inv := fun p => { app := fun j => p.1 j naturality := fun j j' f => by dsimp; rw [comp_id]; exact p.2 f } } /-- If G : C → D is a faithful functor which sends t to a colimit cocone, then it suffices to check that the induced maps for the image of t can be lifted to maps of C. -/ def ofFaithful {t : Cocone F} {D : Type u₄} [Category.{v₄} D] (G : C ⥤ D) [G.Faithful] (ht : IsColimit (mapCocone G t)) (desc : ∀ s : Cocone F, t.pt ⟶ s.pt) (h : ∀ s, G.map (desc s) = ht.desc (mapCocone G s)) : IsColimit t := { desc fac := fun s j => by apply G.map_injective; rw [G.map_comp, h]; apply ht.fac uniq := fun s m w => by apply G.map_injective; rw [h] refine ht.uniq (mapCocone G s) _ fun j => ?_ convert ← congrArg (fun f => G.map f) (w j) apply G.map_comp } /-- If `F` and `G` are naturally isomorphic, then `F.mapCocone c` being a colimit implies `G.mapCocone c` is also a colimit. -/ def mapCoconeEquiv {D : Type u₄} [Category.{v₄} D] {K : J ⥤ C} {F G : C ⥤ D} (h : F ≅ G) {c : Cocone K} (t : IsColimit (mapCocone F c)) : IsColimit (mapCocone G c) := by apply IsColimit.ofIsoColimit _ (precomposeWhiskerLeftMapCocone h c) apply (precomposeInvEquiv (isoWhiskerLeft K h : _) _).symm t /-- A cocone is a colimit cocone exactly if there is a unique cocone morphism from any other cocone. -/ def isoUniqueCoconeMorphism {t : Cocone F} : IsColimit t ≅ ∀ s, Unique (t ⟶ s) where hom h s := { default := h.descCoconeMorphism s uniq := fun _ => h.uniq_cocone_morphism } inv h := { desc := fun s => (h s).default.hom uniq := fun s f w => congrArg CoconeMorphism.hom ((h s).uniq ⟨f, w⟩) } namespace OfNatIso variable {X : C} (h : coyoneda.obj (op X) ⋙ uliftFunctor.{u₁} ≅ F.cocones) /-- If `F.cocones` is corepresented by `X`, each morphism `f : X ⟶ Y` gives a cocone with cone point `Y`. -/ def coconeOfHom {Y : C} (f : X ⟶ Y) : Cocone F where pt := Y ι := h.hom.app Y ⟨f⟩ /-- If `F.cocones` is corepresented by `X`, each cocone `s` gives a morphism `X ⟶ s.pt`. -/ def homOfCocone (s : Cocone F) : X ⟶ s.pt := (h.inv.app s.pt s.ι).down @[simp] theorem coconeOfHom_homOfCocone (s : Cocone F) : coconeOfHom h (homOfCocone h s) = s := by dsimp [coconeOfHom, homOfCocone] have ⟨s_pt,s_ι⟩ := s congr; dsimp convert congrFun (congrFun (congrArg NatTrans.app h.inv_hom_id) s_pt) s_ι using 1 @[simp] theorem homOfCocone_cooneOfHom {Y : C} (f : X ⟶ Y) : homOfCocone h (coconeOfHom h f) = f := congrArg ULift.down (congrFun (congrFun (congrArg NatTrans.app h.hom_inv_id) Y) ⟨f⟩ : _) /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to the identity morphism on `X` will be a colimit cocone. -/ def colimitCocone : Cocone F := coconeOfHom h (𝟙 X) /-- If `F.cocones` is corepresented by `X`, the cocone corresponding to a morphism `f : Y ⟶ X` is the colimit cocone extended by `f`. -/ theorem coconeOfHom_fac {Y : C} (f : X ⟶ Y) : coconeOfHom h f = (colimitCocone h).extend f := by dsimp [coconeOfHom, colimitCocone, Cocone.extend] congr with j have t := congrFun (h.hom.naturality f) ⟨𝟙 X⟩ dsimp at t simp only [id_comp] at t rw [congrFun (congrArg NatTrans.app t) j] rfl /-- If `F.cocones` is corepresented by `X`, any cocone is the extension of the colimit cocone by the corresponding morphism. -/ theorem cocone_fac (s : Cocone F) : (colimitCocone h).extend (homOfCocone h s) = s := by rw [← coconeOfHom_homOfCocone h s] conv_lhs => simp only [homOfCocone_cooneOfHom] apply (coconeOfHom_fac _ _).symm end OfNatIso section open OfNatIso /-- If `F.cocones` is corepresentable, then the cocone corresponding to the identity morphism on the representing object is a colimit cocone. -/ def ofNatIso {X : C} (h : coyoneda.obj (op X) ⋙ uliftFunctor.{u₁} ≅ F.cocones) : IsColimit (colimitCocone h) where desc s := homOfCocone h s fac s j := by have h := cocone_fac h s cases s injection h with h₁ h₂ simp only [heq_iff_eq] at h₂ conv_rhs => rw [← h₂] rfl uniq s m w := by rw [← homOfCocone_cooneOfHom h m] congr rw [coconeOfHom_fac] dsimp [Cocone.extend]; cases s; congr with j; exact w j end end IsColimit end CategoryTheory.Limits
CategoryTheory\Limits\Lattice.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Justus Springer -/ import Mathlib.Order.CompleteLattice import Mathlib.Data.Finset.Lattice import Mathlib.CategoryTheory.Category.Preorder import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits /-! # Limits in lattice categories are given by infimums and supremums. -/ universe w u open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory.Limits.CompleteLattice section Semilattice variable {α : Type u} variable {J : Type w} [SmallCategory J] [FinCategory J] /-- The limit cone over any functor from a finite diagram into a `SemilatticeInf` with `OrderTop`. -/ def finiteLimitCone [SemilatticeInf α] [OrderTop α] (F : J ⥤ α) : LimitCone F where cone := { pt := Finset.univ.inf F.obj π := { app := fun j => homOfLE (Finset.inf_le (Fintype.complete _)) } } isLimit := { lift := fun s => homOfLE (Finset.le_inf fun j _ => (s.π.app j).down.down) } /-- The colimit cocone over any functor from a finite diagram into a `SemilatticeSup` with `OrderBot`. -/ def finiteColimitCocone [SemilatticeSup α] [OrderBot α] (F : J ⥤ α) : ColimitCocone F where cocone := { pt := Finset.univ.sup F.obj ι := { app := fun i => homOfLE (Finset.le_sup (Fintype.complete _)) } } isColimit := { desc := fun s => homOfLE (Finset.sup_le fun j _ => (s.ι.app j).down.down) } -- see Note [lower instance priority] instance (priority := 100) hasFiniteLimits_of_semilatticeInf_orderTop [SemilatticeInf α] [OrderTop α] : HasFiniteLimits α := ⟨by intro J 𝒥₁ 𝒥₂ exact { has_limit := fun F => HasLimit.mk (finiteLimitCone F) }⟩ -- see Note [lower instance priority] instance (priority := 100) hasFiniteColimits_of_semilatticeSup_orderBot [SemilatticeSup α] [OrderBot α] : HasFiniteColimits α := ⟨by intro J 𝒥₁ 𝒥₂ exact { has_colimit := fun F => HasColimit.mk (finiteColimitCocone F) }⟩ /-- The limit of a functor from a finite diagram into a `SemilatticeInf` with `OrderTop` is the infimum of the objects in the image. -/ theorem finite_limit_eq_finset_univ_inf [SemilatticeInf α] [OrderTop α] (F : J ⥤ α) : limit F = Finset.univ.inf F.obj := (IsLimit.conePointUniqueUpToIso (limit.isLimit F) (finiteLimitCone F).isLimit).to_eq /-- The colimit of a functor from a finite diagram into a `SemilatticeSup` with `OrderBot` is the supremum of the objects in the image. -/ theorem finite_colimit_eq_finset_univ_sup [SemilatticeSup α] [OrderBot α] (F : J ⥤ α) : colimit F = Finset.univ.sup F.obj := (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (finiteColimitCocone F).isColimit).to_eq /-- A finite product in the category of a `SemilatticeInf` with `OrderTop` is the same as the infimum. -/ theorem finite_product_eq_finset_inf [SemilatticeInf α] [OrderTop α] {ι : Type u} [Fintype ι] (f : ι → α) : ∏ᶜ f = Fintype.elems.inf f := by trans · exact (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (finiteLimitCone (Discrete.functor f)).isLimit).to_eq change Finset.univ.inf (f ∘ discreteEquiv.toEmbedding) = Fintype.elems.inf f simp only [← Finset.inf_map, Finset.univ_map_equiv_to_embedding] rfl /-- A finite coproduct in the category of a `SemilatticeSup` with `OrderBot` is the same as the supremum. -/ theorem finite_coproduct_eq_finset_sup [SemilatticeSup α] [OrderBot α] {ι : Type u} [Fintype ι] (f : ι → α) : ∐ f = Fintype.elems.sup f := by trans · exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (finiteColimitCocone (Discrete.functor f)).isColimit).to_eq change Finset.univ.sup (f ∘ discreteEquiv.toEmbedding) = Fintype.elems.sup f simp only [← Finset.sup_map, Finset.univ_map_equiv_to_embedding] rfl -- see Note [lower instance priority] instance (priority := 100) [SemilatticeInf α] [OrderTop α] : HasBinaryProducts α := by have : ∀ x y : α, HasLimit (pair x y) := by letI := hasFiniteLimits_of_hasFiniteLimits_of_size.{u} α infer_instance apply hasBinaryProducts_of_hasLimit_pair /-- The binary product in the category of a `SemilatticeInf` with `OrderTop` is the same as the infimum. -/ @[simp] theorem prod_eq_inf [SemilatticeInf α] [OrderTop α] (x y : α) : Limits.prod x y = x ⊓ y := calc Limits.prod x y = limit (pair x y) := rfl _ = Finset.univ.inf (pair x y).obj := by rw [finite_limit_eq_finset_univ_inf (pair.{u} x y)] _ = x ⊓ (y ⊓ ⊤) := rfl -- Note: finset.inf is realized as a fold, hence the definitional equality _ = x ⊓ y := by rw [inf_top_eq] -- see Note [lower instance priority] instance (priority := 100) [SemilatticeSup α] [OrderBot α] : HasBinaryCoproducts α := by have : ∀ x y : α, HasColimit (pair x y) := by letI := hasFiniteColimits_of_hasFiniteColimits_of_size.{u} α infer_instance apply hasBinaryCoproducts_of_hasColimit_pair /-- The binary coproduct in the category of a `SemilatticeSup` with `OrderBot` is the same as the supremum. -/ @[simp] theorem coprod_eq_sup [SemilatticeSup α] [OrderBot α] (x y : α) : Limits.coprod x y = x ⊔ y := calc Limits.coprod x y = colimit (pair x y) := rfl _ = Finset.univ.sup (pair x y).obj := by rw [finite_colimit_eq_finset_univ_sup (pair x y)] _ = x ⊔ (y ⊔ ⊥) := rfl -- Note: Finset.sup is realized as a fold, hence the definitional equality _ = x ⊔ y := by rw [sup_bot_eq] /-- The pullback in the category of a `SemilatticeInf` with `OrderTop` is the same as the infimum over the objects. -/ @[simp] theorem pullback_eq_inf [SemilatticeInf α] [OrderTop α] {x y z : α} (f : x ⟶ z) (g : y ⟶ z) : pullback f g = x ⊓ y := calc pullback f g = limit (cospan f g) := rfl _ = Finset.univ.inf (cospan f g).obj := by rw [finite_limit_eq_finset_univ_inf] _ = z ⊓ (x ⊓ (y ⊓ ⊤)) := rfl _ = z ⊓ (x ⊓ y) := by rw [inf_top_eq] _ = x ⊓ y := inf_eq_right.mpr (inf_le_of_left_le f.le) /-- The pushout in the category of a `SemilatticeSup` with `OrderBot` is the same as the supremum over the objects. -/ @[simp] theorem pushout_eq_sup [SemilatticeSup α] [OrderBot α] (x y z : α) (f : z ⟶ x) (g : z ⟶ y) : pushout f g = x ⊔ y := calc pushout f g = colimit (span f g) := rfl _ = Finset.univ.sup (span f g).obj := by rw [finite_colimit_eq_finset_univ_sup] _ = z ⊔ (x ⊔ (y ⊔ ⊥)) := rfl _ = z ⊔ (x ⊔ y) := by rw [sup_bot_eq] _ = x ⊔ y := sup_eq_right.mpr (le_sup_of_le_left f.le) end Semilattice variable {α : Type u} [CompleteLattice α] variable {J : Type u} [SmallCategory J] /-- The limit cone over any functor into a complete lattice. -/ def limitCone (F : J ⥤ α) : LimitCone F where cone := { pt := iInf F.obj π := { app := fun j => homOfLE (CompleteLattice.sInf_le _ _ (Set.mem_range_self _)) } } isLimit := { lift := fun s => homOfLE (CompleteLattice.le_sInf _ _ (by rintro _ ⟨j, rfl⟩; exact (s.π.app j).le)) } /-- The colimit cocone over any functor into a complete lattice. -/ def colimitCocone (F : J ⥤ α) : ColimitCocone F where cocone := { pt := iSup F.obj ι := { app := fun j => homOfLE (CompleteLattice.le_sSup _ _ (Set.mem_range_self _)) } } isColimit := { desc := fun s => homOfLE (CompleteLattice.sSup_le _ _ (by rintro _ ⟨j, rfl⟩; exact (s.ι.app j).le)) } -- It would be nice to only use the `Inf` half of the complete lattice, but -- this seems not to have been described separately. -- see Note [lower instance priority] instance (priority := 100) hasLimits_of_completeLattice : HasLimits α where has_limits_of_shape _ := { has_limit := fun F => HasLimit.mk (limitCone F) } -- see Note [lower instance priority] instance (priority := 100) hasColimits_of_completeLattice : HasColimits α where has_colimits_of_shape _ := { has_colimit := fun F => HasColimit.mk (colimitCocone F) } /-- The limit of a functor into a complete lattice is the infimum of the objects in the image. -/ theorem limit_eq_iInf (F : J ⥤ α) : limit F = iInf F.obj := (IsLimit.conePointUniqueUpToIso (limit.isLimit F) (limitCone F).isLimit).to_eq /-- The colimit of a functor into a complete lattice is the supremum of the objects in the image. -/ theorem colimit_eq_iSup (F : J ⥤ α) : colimit F = iSup F.obj := (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (colimitCocone F).isColimit).to_eq end CategoryTheory.Limits.CompleteLattice
CategoryTheory\Limits\MonoCoprod.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms /-! # Categories where inclusions into coproducts are monomorphisms If `C` is a category, the class `MonoCoprod C` expresses that left inclusions `A ⟶ A ⨿ B` are monomorphisms when `HasCoproduct A B` is satisfied. If it is so, it is shown that right inclusions are also monomorphisms. More generally, we deduce that when suitable coproducts exists, then if `X : I → C` and `ι : J → I` is an injective map, then the canonical morphism `∐ (X ∘ ι) ⟶ ∐ X` is a monomorphism. It also follows that for any `i : I`, `Sigma.ι X i : X i ⟶ ∐ X` is a monomorphism. TODO: define distributive categories, and show that they satisfy `MonoCoprod`, see <https://ncatlab.org/toddtrimble/published/distributivity+implies+monicity+of+coproduct+inclusions> -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits universe u namespace CategoryTheory namespace Limits variable (C : Type*) [Category C] /-- This condition expresses that inclusion morphisms into coproducts are monomorphisms. -/ class MonoCoprod : Prop where /-- the left inclusion of a colimit binary cofan is mono -/ binaryCofan_inl : ∀ ⦃A B : C⦄ (c : BinaryCofan A B) (_ : IsColimit c), Mono c.inl variable {C} instance (priority := 100) monoCoprodOfHasZeroMorphisms [HasZeroMorphisms C] : MonoCoprod C := ⟨fun A B c hc => by haveI : IsSplitMono c.inl := IsSplitMono.mk' (SplitMono.mk (hc.desc (BinaryCofan.mk (𝟙 A) 0)) (IsColimit.fac _ _ _)) infer_instance⟩ namespace MonoCoprod theorem binaryCofan_inr {A B : C} [MonoCoprod C] (c : BinaryCofan A B) (hc : IsColimit c) : Mono c.inr := by haveI hc' : IsColimit (BinaryCofan.mk c.inr c.inl) := BinaryCofan.IsColimit.mk _ (fun f₁ f₂ => hc.desc (BinaryCofan.mk f₂ f₁)) (by aesop_cat) (by aesop_cat) (fun f₁ f₂ m h₁ h₂ => BinaryCofan.IsColimit.hom_ext hc (by aesop_cat) (by aesop_cat)) exact binaryCofan_inl _ hc' instance {A B : C} [MonoCoprod C] [HasBinaryCoproduct A B] : Mono (coprod.inl : A ⟶ A ⨿ B) := binaryCofan_inl _ (colimit.isColimit _) instance {A B : C} [MonoCoprod C] [HasBinaryCoproduct A B] : Mono (coprod.inr : B ⟶ A ⨿ B) := binaryCofan_inr _ (colimit.isColimit _) theorem mono_inl_iff {A B : C} {c₁ c₂ : BinaryCofan A B} (hc₁ : IsColimit c₁) (hc₂ : IsColimit c₂) : Mono c₁.inl ↔ Mono c₂.inl := by suffices ∀ (c₁ c₂ : BinaryCofan A B) (_ : IsColimit c₁) (_ : IsColimit c₂) (_ : Mono c₁.inl), Mono c₂.inl by exact ⟨fun h₁ => this _ _ hc₁ hc₂ h₁, fun h₂ => this _ _ hc₂ hc₁ h₂⟩ intro c₁ c₂ hc₁ hc₂ intro simpa only [IsColimit.comp_coconePointUniqueUpToIso_hom] using mono_comp c₁.inl (hc₁.coconePointUniqueUpToIso hc₂).hom theorem mk' (h : ∀ A B : C, ∃ (c : BinaryCofan A B) (_ : IsColimit c), Mono c.inl) : MonoCoprod C := ⟨fun A B c' hc' => by obtain ⟨c, hc₁, hc₂⟩ := h A B simpa only [mono_inl_iff hc' hc₁] using hc₂⟩ instance monoCoprodType : MonoCoprod (Type u) := MonoCoprod.mk' fun A B => by refine ⟨BinaryCofan.mk (Sum.inl : A ⟶ A ⊕ B) Sum.inr, ?_, ?_⟩ · exact BinaryCofan.IsColimit.mk _ (fun f₁ f₂ x => by rcases x with x | x exacts [f₁ x, f₂ x]) (fun f₁ f₂ => by rfl) (fun f₁ f₂ => by rfl) (fun f₁ f₂ m h₁ h₂ => by funext x rcases x with x | x · exact congr_fun h₁ x · exact congr_fun h₂ x) · rw [mono_iff_injective] intro a₁ a₂ h simpa using h section variable {I₁ I₂ : Type*} {X : I₁ ⊕ I₂ → C} (c : Cofan X) (c₁ : Cofan (X ∘ Sum.inl)) (c₂ : Cofan (X ∘ Sum.inr)) (hc : IsColimit c) (hc₁ : IsColimit c₁) (hc₂ : IsColimit c₂) /-- Given a family of objects `X : I₁ ⊕ I₂ → C`, a cofan of `X`, and two colimit cofans of `X ∘ Sum.inl` and `X ∘ Sum.inr`, this is a cofan for `c₁.pt` and `c₂.pt` whose point is `c.pt`. -/ @[simp] def binaryCofanSum : BinaryCofan c₁.pt c₂.pt := BinaryCofan.mk (Cofan.IsColimit.desc hc₁ (fun i₁ => c.inj (Sum.inl i₁))) (Cofan.IsColimit.desc hc₂ (fun i₂ => c.inj (Sum.inr i₂))) /-- The binary cofan `binaryCofanSum c c₁ c₂ hc₁ hc₂` is colimit. -/ def isColimitBinaryCofanSum : IsColimit (binaryCofanSum c c₁ c₂ hc₁ hc₂) := BinaryCofan.IsColimit.mk _ (fun f₁ f₂ => Cofan.IsColimit.desc hc (fun i => match i with | Sum.inl i₁ => c₁.inj i₁ ≫ f₁ | Sum.inr i₂ => c₂.inj i₂ ≫ f₂)) (fun f₁ f₂ => Cofan.IsColimit.hom_ext hc₁ _ _ (by simp)) (fun f₁ f₂ => Cofan.IsColimit.hom_ext hc₂ _ _ (by simp)) (fun f₁ f₂ m hm₁ hm₂ => by apply Cofan.IsColimit.hom_ext hc rintro (i₁|i₂) <;> aesop_cat) lemma mono_binaryCofanSum_inl [MonoCoprod C] : Mono (binaryCofanSum c c₁ c₂ hc₁ hc₂).inl := MonoCoprod.binaryCofan_inl _ (isColimitBinaryCofanSum c c₁ c₂ hc hc₁ hc₂) lemma mono_binaryCofanSum_inr [MonoCoprod C] : Mono (binaryCofanSum c c₁ c₂ hc₁ hc₂).inr := MonoCoprod.binaryCofan_inr _ (isColimitBinaryCofanSum c c₁ c₂ hc hc₁ hc₂) lemma mono_binaryCofanSum_inl' [MonoCoprod C] (inl : c₁.pt ⟶ c.pt) (hinl : ∀ (i₁ : I₁), c₁.inj i₁ ≫ inl = c.inj (Sum.inl i₁)) : Mono inl := by suffices inl = (binaryCofanSum c c₁ c₂ hc₁ hc₂).inl by rw [this] exact MonoCoprod.binaryCofan_inl _ (isColimitBinaryCofanSum c c₁ c₂ hc hc₁ hc₂) exact Cofan.IsColimit.hom_ext hc₁ _ _ (by simpa using hinl) lemma mono_binaryCofanSum_inr' [MonoCoprod C] (inr : c₂.pt ⟶ c.pt) (hinr : ∀ (i₂ : I₂), c₂.inj i₂ ≫ inr = c.inj (Sum.inr i₂)) : Mono inr := by suffices inr = (binaryCofanSum c c₁ c₂ hc₁ hc₂).inr by rw [this] exact MonoCoprod.binaryCofan_inr _ (isColimitBinaryCofanSum c c₁ c₂ hc hc₁ hc₂) exact Cofan.IsColimit.hom_ext hc₂ _ _ (by simpa using hinr) end section variable [MonoCoprod C] {I J : Type*} (X : I → C) (ι : J → I) lemma mono_of_injective_aux (hι : Function.Injective ι) (c : Cofan X) (c₁ : Cofan (X ∘ ι)) (hc : IsColimit c) (hc₁ : IsColimit c₁) (c₂ : Cofan (fun (k : ((Set.range ι)ᶜ : Set I)) => X k.1)) (hc₂ : IsColimit c₂) : Mono (Cofan.IsColimit.desc hc₁ (fun i => c.inj (ι i))) := by classical let e := ((Equiv.ofInjective ι hι).sumCongr (Equiv.refl _)).trans (Equiv.Set.sumCompl _) refine mono_binaryCofanSum_inl' (Cofan.mk c.pt (fun i' => c.inj (e i'))) _ _ ?_ hc₁ hc₂ _ (by simp [e]) exact IsColimit.ofIsoColimit ((IsColimit.ofCoconeEquiv (Cocones.equivalenceOfReindexing (Discrete.equivalence e) (Iso.refl _))).symm hc) (Cocones.ext (Iso.refl _)) variable (hι : Function.Injective ι) (c : Cofan X) (c₁ : Cofan (X ∘ ι)) (hc : IsColimit c) (hc₁ : IsColimit c₁) lemma mono_of_injective [HasCoproduct (fun (k : ((Set.range ι)ᶜ : Set I)) => X k.1)] : Mono (Cofan.IsColimit.desc hc₁ (fun i => c.inj (ι i))) := mono_of_injective_aux X ι hι c c₁ hc hc₁ _ (colimit.isColimit _) lemma mono_of_injective' [HasCoproduct (X ∘ ι)] [HasCoproduct X] [HasCoproduct (fun (k : ((Set.range ι)ᶜ : Set I)) => X k.1)] : Mono (Sigma.desc (f := X ∘ ι) (fun j => Sigma.ι X (ι j))) := mono_of_injective X ι hι _ _ (colimit.isColimit _) (colimit.isColimit _) lemma mono_map'_of_injective [HasCoproduct (X ∘ ι)] [HasCoproduct X] [HasCoproduct (fun (k : ((Set.range ι)ᶜ : Set I)) => X k.1)] : Mono (Sigma.map' ι (fun j => 𝟙 ((X ∘ ι) j))) := by convert mono_of_injective' X ι hι apply Sigma.hom_ext intro j rw [Sigma.ι_comp_map', id_comp, colimit.ι_desc] simp end section variable [MonoCoprod C] {I : Type*} (X : I → C) lemma mono_inj (c : Cofan X) (h : IsColimit c) (i : I) [HasCoproduct (fun (k : ((Set.range (fun _ : Unit ↦ i))ᶜ : Set I)) => X k.1)] : Mono (Cofan.inj c i) := by let ι : Unit → I := fun _ ↦ i have hι : Function.Injective ι := fun _ _ _ ↦ rfl exact mono_of_injective X ι hι c (Cofan.mk (X i) (fun _ ↦ 𝟙 _)) h (mkCofanColimit _ (fun s => s.inj ())) instance mono_ι [HasCoproduct X] (i : I) [HasCoproduct (fun (k : ((Set.range (fun _ : Unit ↦ i))ᶜ : Set I)) => X k.1)] : Mono (Sigma.ι X i) := mono_inj X _ (colimit.isColimit _) i end open Functor section Preservation variable {D : Type*} [Category D] (F : C ⥤ D) theorem monoCoprod_of_preservesCoprod_of_reflectsMono [MonoCoprod D] [PreservesColimitsOfShape (Discrete WalkingPair) F] [ReflectsMonomorphisms F] : MonoCoprod C where binaryCofan_inl {A B} c h := by let c' := BinaryCofan.mk (F.map c.inl) (F.map c.inr) apply mono_of_mono_map F show Mono c'.inl apply MonoCoprod.binaryCofan_inl apply mapIsColimitOfPreservesOfIsColimit F apply IsColimit.ofIsoColimit h refine Cocones.ext (φ := eqToIso rfl) ?_ rintro ⟨(j₁|j₂)⟩ <;> simp only [const_obj_obj, eqToIso_refl, Iso.refl_hom, Category.comp_id, BinaryCofan.mk_inl, BinaryCofan.mk_inr] end Preservation section Concrete instance [ConcreteCategory C] [PreservesColimitsOfShape (Discrete WalkingPair) (forget C)] [ReflectsMonomorphisms (forget C)] : MonoCoprod C := monoCoprod_of_preservesCoprod_of_reflectsMono (forget C) end Concrete end MonoCoprod end Limits end CategoryTheory
CategoryTheory\Limits\Opposites.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.Filtered import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.DiscreteCategory /-! # Limits in `C` give colimits in `Cᵒᵖ`. We also give special cases for (co)products, (co)equalizers, and pullbacks / pushouts. -/ 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] @[deprecated (since := "2024-03-26")] alias isLimitCoconeOp := IsColimit.op @[deprecated (since := "2024-03-26")] alias isColimitConeOp := IsLimit.op @[deprecated (since := "2024-03-26")] alias isLimitCoconeUnop := IsColimit.unop @[deprecated (since := "2024-03-26")] alias isColimitConeUnop := IsLimit.unop /-- Turn a colimit for `F : J ⥤ Cᵒᵖ` into a limit for `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps] def isLimitConeLeftOpOfCocone (F : J ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneLeftOpOfCocone c) where lift s := (hc.desc (coconeOfConeLeftOp s)).unop fac s j := Quiver.Hom.op_inj <| by simp only [coneLeftOpOfCocone_π_app, op_comp, Quiver.Hom.op_unop, IsColimit.fac, coconeOfConeLeftOp_ι_app, op_unop] uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac, coconeOfConeLeftOp_ι_app] using w (op j) /-- Turn a limit of `F : J ⥤ Cᵒᵖ` into a colimit of `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps] def isColimitCoconeLeftOpOfCone (F : J ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeLeftOpOfCone c) where desc s := (hc.lift (coneOfCoconeLeftOp s)).unop fac s j := Quiver.Hom.op_inj <| by simp only [coconeLeftOpOfCone_ι_app, op_comp, Quiver.Hom.op_unop, IsLimit.fac, coneOfCoconeLeftOp_π_app, op_unop] uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac, coneOfCoconeLeftOp_π_app] using w (op j) /-- Turn a colimit for `F : Jᵒᵖ ⥤ C` into a limit for `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeRightOpOfCocone (F : Jᵒᵖ ⥤ C) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneRightOpOfCocone c) where lift s := (hc.desc (coconeOfConeRightOp s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (unop j) /-- Turn a limit for `F : Jᵒᵖ ⥤ C` into a colimit for `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def isColimitCoconeRightOpOfCone (F : Jᵒᵖ ⥤ C) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeRightOpOfCone c) where desc s := (hc.lift (coneOfCoconeRightOp s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (unop j) /-- Turn a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a limit for `F.unop : J ⥤ C`. -/ @[simps] def isLimitConeUnopOfCocone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneUnopOfCocone c) where lift s := (hc.desc (coconeOfConeUnop s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (unop j) /-- Turn a limit of `F : Jᵒᵖ ⥤ Cᵒᵖ` into a colimit of `F.unop : J ⥤ C`. -/ @[simps] def isColimitCoconeUnopOfCone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeUnopOfCone c) where desc s := (hc.lift (coneOfCoconeUnop s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (unop j) /-- Turn a colimit for `F.leftOp : Jᵒᵖ ⥤ C` into a limit for `F : J ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeOfCoconeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cocone F.leftOp} (hc : IsColimit c) : IsLimit (coneOfCoconeLeftOp c) where lift s := (hc.desc (coconeLeftOpOfCone s)).op fac s j := Quiver.Hom.unop_inj <| by simp only [coneOfCoconeLeftOp_π_app, unop_comp, Quiver.Hom.unop_op, IsColimit.fac, coconeLeftOpOfCone_ι_app, unop_op] uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac, coneOfCoconeLeftOp_π_app] using w (unop j) /-- Turn a limit of `F.leftOp : Jᵒᵖ ⥤ C` into a colimit of `F : J ⥤ Cᵒᵖ`. -/ @[simps] def isColimitCoconeOfConeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cone F.leftOp} (hc : IsLimit c) : IsColimit (coconeOfConeLeftOp c) where desc s := (hc.lift (coneLeftOpOfCocone s)).op fac s j := Quiver.Hom.unop_inj <| by simp only [coconeOfConeLeftOp_ι_app, unop_comp, Quiver.Hom.unop_op, IsLimit.fac, coneLeftOpOfCocone_π_app, unop_op] uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac, coconeOfConeLeftOp_ι_app] using w (unop j) /-- Turn a colimit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/ @[simps] def isLimitConeOfCoconeRightOp (F : Jᵒᵖ ⥤ C) {c : Cocone F.rightOp} (hc : IsColimit c) : IsLimit (coneOfCoconeRightOp c) where lift s := (hc.desc (coconeRightOpOfCone s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (op j) /-- Turn a limit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/ @[simps] def isColimitCoconeOfConeRightOp (F : Jᵒᵖ ⥤ C) {c : Cone F.rightOp} (hc : IsLimit c) : IsColimit (coconeOfConeRightOp c) where desc s := (hc.lift (coneRightOpOfCocone s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (op j) /-- Turn a colimit for `F.unop : J ⥤ C` into a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F.unop} (hc : IsColimit c) : IsLimit (coneOfCoconeUnop c) where lift s := (hc.desc (coconeUnopOfCone s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (op j) /-- Turn a limit for `F.unop : J ⥤ C` into a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def isColimitConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F.unop} (hc : IsLimit c) : IsColimit (coconeOfConeUnop c) where desc s := (hc.lift (coneUnopOfCocone s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (op j) /-- If `F.leftOp : Jᵒᵖ ⥤ C` has a colimit, we can construct a limit for `F : J ⥤ Cᵒᵖ`. -/ theorem hasLimit_of_hasColimit_leftOp (F : J ⥤ Cᵒᵖ) [HasColimit F.leftOp] : HasLimit F := HasLimit.mk { cone := coneOfCoconeLeftOp (colimit.cocone F.leftOp) isLimit := isLimitConeOfCoconeLeftOp _ (colimit.isColimit _) } theorem hasLimit_of_hasColimit_op (F : J ⥤ C) [HasColimit F.op] : HasLimit F := HasLimit.mk { cone := (colimit.cocone F.op).unop isLimit := (colimit.isColimit _).unop } theorem hasLimit_op_of_hasColimit (F : J ⥤ C) [HasColimit F] : HasLimit F.op := HasLimit.mk { cone := (colimit.cocone F).op isLimit := (colimit.isColimit _).op } /-- If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`. -/ theorem hasLimitsOfShape_op_of_hasColimitsOfShape [HasColimitsOfShape Jᵒᵖ C] : HasLimitsOfShape J Cᵒᵖ := { has_limit := fun F => hasLimit_of_hasColimit_leftOp F } theorem hasLimitsOfShape_of_hasColimitsOfShape_op [HasColimitsOfShape Jᵒᵖ Cᵒᵖ] : HasLimitsOfShape J C := { has_limit := fun F => hasLimit_of_hasColimit_op F } attribute [local instance] hasLimitsOfShape_op_of_hasColimitsOfShape /-- If `C` has colimits, we can construct limits for `Cᵒᵖ`. -/ instance hasLimits_op_of_hasColimits [HasColimits C] : HasLimits Cᵒᵖ := ⟨fun _ => inferInstance⟩ theorem hasLimits_of_hasColimits_op [HasColimits Cᵒᵖ] : HasLimits C := { has_limits_of_shape := fun _ _ => hasLimitsOfShape_of_hasColimitsOfShape_op } 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 } /-- If `F.leftOp : Jᵒᵖ ⥤ C` has a limit, we can construct a colimit for `F : J ⥤ Cᵒᵖ`. -/ theorem hasColimit_of_hasLimit_leftOp (F : J ⥤ Cᵒᵖ) [HasLimit F.leftOp] : HasColimit F := HasColimit.mk { cocone := coconeOfConeLeftOp (limit.cone F.leftOp) isColimit := isColimitCoconeOfConeLeftOp _ (limit.isLimit _) } theorem hasColimit_of_hasLimit_op (F : J ⥤ C) [HasLimit F.op] : HasColimit F := HasColimit.mk { cocone := (limit.cone F.op).unop isColimit := (limit.isLimit _).unop } theorem hasColimit_op_of_hasLimit (F : J ⥤ C) [HasLimit F] : HasColimit F.op := HasColimit.mk { cocone := (limit.cone F).op isColimit := (limit.isLimit _).op } /-- If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`. -/ instance hasColimitsOfShape_op_of_hasLimitsOfShape [HasLimitsOfShape Jᵒᵖ C] : HasColimitsOfShape J Cᵒᵖ where has_colimit F := hasColimit_of_hasLimit_leftOp F theorem hasColimitsOfShape_of_hasLimitsOfShape_op [HasLimitsOfShape Jᵒᵖ Cᵒᵖ] : HasColimitsOfShape J C := { has_colimit := fun F => hasColimit_of_hasLimit_op F } /-- If `C` has limits, we can construct colimits for `Cᵒᵖ`. -/ instance hasColimits_op_of_hasLimits [HasLimits C] : HasColimits Cᵒᵖ := ⟨fun _ => inferInstance⟩ theorem hasColimits_of_hasLimits_op [HasLimits Cᵒᵖ] : HasColimits C := { has_colimits_of_shape := fun _ _ => hasColimitsOfShape_of_hasLimitsOfShape_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 } 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ᵒᵖ := by haveI : HasColimitsOfShape (Discrete X)ᵒᵖ C := hasColimitsOfShape_of_equivalence (Discrete.opposite X).symm infer_instance 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) := hasLimitEquivalenceComp (Discrete.opposite α).symm instance : HasProduct (op <| Z ·) := hasLimitOfIso ((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. -/ 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⟩ ↦ ?_)) dsimp erw [Category.id_comp, Category.comp_id] rfl /-- 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 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 _ π) · ext; simp [Sigma.desc, coproductIsCoproduct] · ext; 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 ·) := hasColimitOfIso ((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. -/ 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 _ π) · ext; simp [Pi.lift, productIsProduct] · ext; 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) := ‹_› show 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 [limit.lift_π] 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 instance hasEqualizers_opposite [HasCoequalizers C] : HasEqualizers Cᵒᵖ := by haveI : HasColimitsOfShape WalkingParallelPairᵒᵖ C := hasColimitsOfShape_of_equivalence walkingParallelPairOpEquiv infer_instance instance hasCoequalizers_opposite [HasEqualizers C] : HasCoequalizers Cᵒᵖ := by haveI : HasLimitsOfShape WalkingParallelPairᵒᵖ C := hasLimitsOfShape_of_equivalence walkingParallelPairOpEquiv infer_instance instance hasFiniteColimits_opposite [HasFiniteLimits C] : HasFiniteColimits Cᵒᵖ := ⟨fun _ _ _ => inferInstance⟩ instance hasFiniteLimits_opposite [HasFiniteColimits C] : HasFiniteLimits Cᵒᵖ := ⟨fun _ _ _ => inferInstance⟩ 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 (by rintro (_ | _ | _) <;> rfl) (by rintro (_ | _ | _) (_ | _ | _) f <;> cases f <;> aesop_cat) /-- 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 := by rfl _ ≅ (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 (by rintro (_ | _ | _) <;> rfl) (by rintro (_ | _ | _) (_ | _ | _) f <;> cases f <;> aesop_cat) /-- 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 := by rfl _ ≅ (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 -- Porting note: it was originally @[simps (config := lemmasOnly)] /-- 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)) -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp 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 -- Porting note (#10618): removed simp attribute as the equality can already be obtained 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 aesop_cat -- Porting note: it was originally @[simps (config := lemmasOnly)] /-- 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)) -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp theorem op_fst {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.op.fst = c.inl.op := by aesop_cat -- Porting note (#10618): removed simp attribute as the equality can already be obtained 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 aesop_cat end PushoutCocone namespace PullbackCone -- Porting note: it was originally @[simps (config := lemmasOnly)] /-- 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)) -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp theorem unop_inl {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.unop.inl = c.fst.unop := by aesop_cat -- Porting note (#10618): removed simp attribute as the equality can already be obtained 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 aesop_cat /-- 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)) -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp theorem op_inl {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.op.inl = c.fst.op := by aesop_cat -- Porting note (#10618): removed simp attribute as the equality can already be obtained 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 aesop_cat /-- If `c` is a pullback cone, then `c.op.unop` is isomorphic to `c`. -/ def opUnop {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 unopOp {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 opUnop {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 unopOp {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. -/ 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.opUnop).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. -/ 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.unopOp).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.opUnop).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.unopOp).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 _ _ : _ ⟶ pushout 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 _ _ : _ ⟶ pushout 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 _ _ ≫ (pullbackIsoUnopPushout f g).hom.op = (pullback.fst f g).op := by apply Quiver.Hom.unop_inj dsimp rw [← pullbackIsoUnopPushout_inv_fst, Iso.hom_inv_id_assoc] @[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 _ _ ≫ (pullbackIsoUnopPushout f g).hom.op = (pullback.snd f g).op := by apply Quiver.Hom.unop_inj dsimp rw [← pullbackIsoUnopPushout_inv_snd, Iso.hom_inv_id_assoc] 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 := by apply Quiver.Hom.unop_inj dsimp rw [← pushoutIsoUnopPullback_inl_hom, Category.assoc, Iso.hom_inv_id, Category.comp_id] @[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 := by apply Quiver.Hom.unop_inj dsimp rw [← pushoutIsoUnopPullback_inr_hom, Category.assoc, Iso.hom_inv_id, Category.comp_id] end Pushout 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 x hx => 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 x hx => 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 x hx => 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 x hx => 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
CategoryTheory\Limits\Over.lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.Limits.Comma import Mathlib.CategoryTheory.Limits.ConeCategory import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Limits and colimits in the over and under categories Show that the forgetful functor `forget X : Over X ⥤ C` creates colimits, and hence `Over X` has any colimits that `C` has (as well as the dual that `forget X : Under X ⟶ C` creates limits). Note that the folder `CategoryTheory.Limits.Shapes.Constructions.Over` further shows that `forget X : Over X ⥤ C` creates connected limits (so `Over X` has connected limits), and that `Over X` has `J`-indexed products if `C` has `J`-indexed wide pullbacks. -/ noncomputable section -- morphism levels before object levels. See note [category_theory universes]. universe w' w v u open CategoryTheory CategoryTheory.Limits variable {J : Type w} [Category.{w'} J] variable {C : Type u} [Category.{v} C] variable {X : C} namespace CategoryTheory.Over instance hasColimit_of_hasColimit_comp_forget (F : J ⥤ Over X) [i : HasColimit (F ⋙ forget X)] : HasColimit F := CostructuredArrow.hasColimit (i₁ := i) instance [HasColimitsOfShape J C] : HasColimitsOfShape J (Over X) where instance [HasColimits C] : HasColimits (Over X) := ⟨inferInstance⟩ instance createsColimitsOfSize : CreatesColimitsOfSize.{w, w'} (forget X) := CostructuredArrow.createsColimitsOfSize -- We can automatically infer that the forgetful functor preserves and reflects colimits. example [HasColimits C] : PreservesColimits (forget X) := inferInstance example : ReflectsColimits (forget X) := inferInstance theorem epi_left_of_epi [HasPushouts C] {f g : Over X} (h : f ⟶ g) [Epi h] : Epi h.left := CostructuredArrow.epi_left_of_epi _ theorem epi_iff_epi_left [HasPushouts C] {f g : Over X} (h : f ⟶ g) : Epi h ↔ Epi h.left := CostructuredArrow.epi_iff_epi_left _ instance createsColimitsOfSizeMapCompForget {Y : C} (f : X ⟶ Y) : CreatesColimitsOfSize.{w, w'} (map f ⋙ forget Y) := show CreatesColimitsOfSize.{w, w'} (forget X) from inferInstance instance preservesColimitsOfSizeMap [HasColimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) : PreservesColimitsOfSize.{w, w'} (map f) := preservesColimitsOfReflectsOfPreserves (map f) (forget Y) /-- If `c` is a colimit cocone, then so is the cocone `c.toOver` with cocone point `𝟙 c.pt`. -/ def isColimitToOver {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsColimit c.toOver := isColimitOfReflects (forget c.pt) <| IsColimit.equivIsoColimit c.mapCoconeToOver.symm hc /-- If `F` has a colimit, then the cocone `colimit.toOver F` with cocone point `𝟙 (colimit F)` is also a colimit cocone. -/ def _root_.CategoryTheory.Limits.colimit.isColimitToOver (F : J ⥤ C) [HasColimit F] : IsColimit (colimit.toOver F) := Over.isColimitToOver (colimit.isColimit F) end CategoryTheory.Over namespace CategoryTheory.Under instance hasLimit_of_hasLimit_comp_forget (F : J ⥤ Under X) [i : HasLimit (F ⋙ forget X)] : HasLimit F := StructuredArrow.hasLimit (i₁ := i) instance [HasLimitsOfShape J C] : HasLimitsOfShape J (Under X) where instance [HasLimits C] : HasLimits (Under X) := ⟨inferInstance⟩ theorem mono_right_of_mono [HasPullbacks C] {f g : Under X} (h : f ⟶ g) [Mono h] : Mono h.right := StructuredArrow.mono_right_of_mono _ theorem mono_iff_mono_right [HasPullbacks C] {f g : Under X} (h : f ⟶ g) : Mono h ↔ Mono h.right := StructuredArrow.mono_iff_mono_right _ instance createsLimitsOfSize : CreatesLimitsOfSize.{w, w'} (forget X) := StructuredArrow.createsLimitsOfSize -- We can automatically infer that the forgetful functor preserves and reflects limits. example [HasLimits C] : PreservesLimits (forget X) := inferInstance example : ReflectsLimits (forget X) := inferInstance instance createLimitsOfSizeMapCompForget {Y : C} (f : X ⟶ Y) : CreatesLimitsOfSize.{w, w'} (map f ⋙ forget X) := show CreatesLimitsOfSize.{w, w'} (forget Y) from inferInstance instance preservesLimitsOfSizeMap [HasLimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) : PreservesLimitsOfSize.{w, w'} (map f) := preservesLimitsOfReflectsOfPreserves (map f) (forget X) /-- If `c` is a limit cone, then so is the cone `c.toUnder` with cone point `𝟙 c.pt`. -/ def isLimitToUnder {F : J ⥤ C} {c : Cone F} (hc : IsLimit c) : IsLimit c.toUnder := isLimitOfReflects (forget c.pt) (IsLimit.equivIsoLimit c.mapConeToUnder.symm hc) /-- If `F` has a limit, then the cone `limit.toUnder F` with cone point `𝟙 (limit F)` is also a limit cone. -/ def _root_.CategoryTheory.Limits.limit.isLimitToOver (F : J ⥤ C) [HasLimit F] : IsLimit (limit.toUnder F) := Under.isLimitToUnder (limit.isLimit F) end CategoryTheory.Under
CategoryTheory\Limits\Pi.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Pi.Basic import Mathlib.CategoryTheory.Limits.HasLimits /-! # Limits in the category of indexed families of objects. Given a functor `F : J ⥤ Π i, C i` into a category of indexed families, 1. we can assemble a collection of cones over `F ⋙ Pi.eval C i` into a cone over `F` 2. if all those cones are limit cones, the assembled cone is a limit cone, and 3. if we have limits for each of `F ⋙ Pi.eval C i`, we can produce a `HasLimit F` instance -/ open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory.pi universe v₁ v₂ u₁ u₂ variable {I : Type v₁} {C : I → Type u₁} [∀ i, Category.{v₁} (C i)] variable {J : Type v₁} [SmallCategory J] variable {F : J ⥤ ∀ i, C i} /-- A cone over `F : J ⥤ Π i, C i` has as its components cones over each of the `F ⋙ Pi.eval C i`. -/ def coneCompEval (c : Cone F) (i : I) : Cone (F ⋙ Pi.eval C i) where pt := c.pt i π := { app := fun j => c.π.app j i naturality := fun _ _ f => congr_fun (c.π.naturality f) i } /-- A cocone over `F : J ⥤ Π i, C i` has as its components cocones over each of the `F ⋙ Pi.eval C i`. -/ def coconeCompEval (c : Cocone F) (i : I) : Cocone (F ⋙ Pi.eval C i) where pt := c.pt i ι := { app := fun j => c.ι.app j i naturality := fun _ _ f => congr_fun (c.ι.naturality f) i } /-- Given a family of cones over the `F ⋙ Pi.eval C i`, we can assemble these together as a `Cone F`. -/ def coneOfConeCompEval (c : ∀ i, Cone (F ⋙ Pi.eval C i)) : Cone F where pt i := (c i).pt π := { app := fun j i => (c i).π.app j naturality := fun j j' f => by funext i exact (c i).π.naturality f } /-- Given a family of cocones over the `F ⋙ Pi.eval C i`, we can assemble these together as a `Cocone F`. -/ def coconeOfCoconeCompEval (c : ∀ i, Cocone (F ⋙ Pi.eval C i)) : Cocone F where pt i := (c i).pt ι := { app := fun j i => (c i).ι.app j naturality := fun j j' f => by funext i exact (c i).ι.naturality f } /-- Given a family of limit cones over the `F ⋙ Pi.eval C i`, assembling them together as a `Cone F` produces a limit cone. -/ def coneOfConeEvalIsLimit {c : ∀ i, Cone (F ⋙ Pi.eval C i)} (P : ∀ i, IsLimit (c i)) : IsLimit (coneOfConeCompEval c) where lift s i := (P i).lift (coneCompEval s i) fac s j := by funext i exact (P i).fac (coneCompEval s i) j uniq s m w := by funext i exact (P i).uniq (coneCompEval s i) (m i) fun j => congr_fun (w j) i /-- Given a family of colimit cocones over the `F ⋙ Pi.eval C i`, assembling them together as a `Cocone F` produces a colimit cocone. -/ def coconeOfCoconeEvalIsColimit {c : ∀ i, Cocone (F ⋙ Pi.eval C i)} (P : ∀ i, IsColimit (c i)) : IsColimit (coconeOfCoconeCompEval c) where desc s i := (P i).desc (coconeCompEval s i) fac s j := by funext i exact (P i).fac (coconeCompEval s i) j uniq s m w := by funext i exact (P i).uniq (coconeCompEval s i) (m i) fun j => congr_fun (w j) i section variable [∀ i, HasLimit (F ⋙ Pi.eval C i)] /-- If we have a functor `F : J ⥤ Π i, C i` into a category of indexed families, and we have limits for each of the `F ⋙ Pi.eval C i`, then `F` has a limit. -/ theorem hasLimit_of_hasLimit_comp_eval : HasLimit F := HasLimit.mk { cone := coneOfConeCompEval fun _ => limit.cone _ isLimit := coneOfConeEvalIsLimit fun _ => limit.isLimit _ } end section variable [∀ i, HasColimit (F ⋙ Pi.eval C i)] /-- If we have a functor `F : J ⥤ Π i, C i` into a category of indexed families, and colimits exist for each of the `F ⋙ Pi.eval C i`, there is a colimit for `F`. -/ theorem hasColimit_of_hasColimit_comp_eval : HasColimit F := HasColimit.mk { cocone := coconeOfCoconeCompEval fun _ => colimit.cocone _ isColimit := coconeOfCoconeEvalIsColimit fun _ => colimit.isColimit _ } end /-! As an example, we can use this to construct particular shapes of limits in a category of indexed families. With the addition of `import CategoryTheory.Limits.Shapes.Types` we can use: ``` attribute [local instance] hasLimit_of_hasLimit_comp_eval example : hasBinaryProducts (I → Type v₁) := ⟨by infer_instance⟩ ``` -/ end CategoryTheory.pi
CategoryTheory\Limits\Presheaf.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Joël Riou -/ import Mathlib.CategoryTheory.Comma.Presheaf import Mathlib.CategoryTheory.Elements import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Limits.ConeCategory import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Over import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Types /-! # Colimit of representables This file constructs an adjunction `Presheaf.yonedaAdjunction` between `(Cᵒᵖ ⥤ Type u)` and `ℰ` given a functor `A : C ⥤ ℰ`, where the right adjoint `restrictedYoneda` sends `(E : ℰ)` to `c ↦ (A.obj c ⟶ E)`, and the left adjoint `(Cᵒᵖ ⥤ Type v₁) ⥤ ℰ` is a pointwise left Kan extension of `A` along the Yoneda embedding, which exists provided `ℰ` has colimits) We also show that every presheaf is a colimit of representables. This result is also known as the density theorem, the co-Yoneda lemma and the Ninja Yoneda lemma. Two formulations are given: * `colimitOfRepresentable` uses the category of elements of a functor to types; * `isColimitTautologicalCocone` uses the category of costructured arrows. In the lemma `isLeftKanExtension_along_yoneda_iff`, we show that if `L : (Cᵒᵖ ⥤ Type v₁) ⥤ ℰ)` and `α : A ⟶ yoneda ⋙ L`, then `α` makes `L` the left Kan extension of `L` along yoneda if and only if `α` is an isomorphism (i.e. `L` extends `A`) and `L` preserves colimits. `uniqueExtensionAlongYoneda` shows `yoneda.leftKanExtension A` is unique amongst functors preserving colimits with this property, establishing the presheaf category as the free cocompletion of a category. Given a functor `F : C ⥤ D`, we also show construct an isomorphism `compYonedaIsoYonedaCompLan : F ⋙ yoneda ≅ yoneda ⋙ F.op.lan`, and show that it makes `F.op.lan` a left Kan extension of `F ⋙ yoneda`. ## Tags colimit, representable, presheaf, free cocompletion ## References * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] * https://ncatlab.org/nlab/show/Yoneda+extension -/ namespace CategoryTheory open Category Limits universe v₁ v₂ v₃ u₁ u₂ u₃ namespace Presheaf variable {C : Type u₁} [Category.{v₁} C] variable {ℰ : Type u₂} [Category.{v₁} ℰ] (A : C ⥤ ℰ) /-- The functor taking `(E : ℰ) (c : Cᵒᵖ)` to the homset `(A.obj C ⟶ E)`. It is shown in `L_adjunction` that this functor has a left adjoint (provided `E` has colimits) given by taking colimits over categories of elements. In the case where `ℰ = Cᵒᵖ ⥤ Type u` and `A = yoneda`, this functor is isomorphic to the identity. Defined as in [MM92], Chapter I, Section 5, Theorem 2. -/ @[simps!] def restrictedYoneda : ℰ ⥤ Cᵒᵖ ⥤ Type v₁ := yoneda ⋙ (whiskeringLeft _ _ (Type v₁)).obj (Functor.op A) /-- Auxiliary definition for `restrictedYonedaHomEquiv`. -/ def restrictedYonedaHomEquiv' (P : Cᵒᵖ ⥤ Type v₁) (E : ℰ) : (CostructuredArrow.proj yoneda P ⋙ A ⟶ (Functor.const (CostructuredArrow yoneda P)).obj E) ≃ (P ⟶ (restrictedYoneda A).obj E) where toFun f := { app := fun X x => f.app (CostructuredArrow.mk (yonedaEquiv.symm x)) naturality := fun {X₁ X₂} φ => by ext x let ψ : CostructuredArrow.mk (yonedaEquiv.symm (P.toPrefunctor.map φ x)) ⟶ CostructuredArrow.mk (yonedaEquiv.symm x) := CostructuredArrow.homMk φ.unop (by dsimp [yonedaEquiv] aesop_cat ) simpa using (f.naturality ψ).symm } invFun g := { app := fun y => yonedaEquiv (y.hom ≫ g) naturality := fun {X₁ X₂} φ => by dsimp rw [← CostructuredArrow.w φ] dsimp [yonedaEquiv] simp only [comp_id, id_comp] refine (congr_fun (g.naturality φ.left.op) (X₂.hom.app (Opposite.op X₂.left) (𝟙 _))).symm.trans ?_ dsimp apply congr_arg simpa using congr_fun (X₂.hom.naturality φ.left.op).symm (𝟙 _) } left_inv f := by ext ⟨X, ⟨⟨⟩⟩, φ⟩ suffices yonedaEquiv.symm (φ.app (Opposite.op X) (𝟙 X)) = φ by dsimp erw [yonedaEquiv_apply] dsimp [CostructuredArrow.mk] erw [this] exact yonedaEquiv.injective (by aesop_cat) right_inv g := by ext X x dsimp erw [yonedaEquiv_apply] dsimp rw [yonedaEquiv_symm_app_apply] simp section example [HasColimitsOfSize.{v₁, max u₁ v₁} ℰ] : yoneda.HasPointwiseLeftKanExtension A := inferInstance variable [yoneda.HasPointwiseLeftKanExtension A] variable {A} variable (L : (Cᵒᵖ ⥤ Type v₁) ⥤ ℰ) (α : A ⟶ yoneda ⋙ L) [L.IsLeftKanExtension α] /-- Auxiliary definition for `yonedaAdjunction`. -/ noncomputable def restrictedYonedaHomEquiv (P : Cᵒᵖ ⥤ Type v₁) (E : ℰ) : (L.obj P ⟶ E) ≃ (P ⟶ (restrictedYoneda A).obj E) := ((Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ α P).homEquiv E).trans (restrictedYonedaHomEquiv' A P E) /-- If `L : (Cᵒᵖ ⥤ Type v₁) ⥤ ℰ` is a pointwise left Kan extension of a functor `A : C ⥤ ℰ` along the Yoneda embedding, then `L` is a left adjoint of `restrictedYoneda A : ℰ ⥤ Cᵒᵖ ⥤ Type v₁` -/ noncomputable def yonedaAdjunction : L ⊣ restrictedYoneda A := Adjunction.mkOfHomEquiv { homEquiv := restrictedYonedaHomEquiv L α homEquiv_naturality_left_symm := fun {P Q X} f g => by obtain ⟨g, rfl⟩ := (restrictedYonedaHomEquiv L α Q X).surjective g apply (restrictedYonedaHomEquiv L α P X).injective simp only [Equiv.apply_symm_apply, Equiv.symm_apply_apply] ext Y y dsimp [restrictedYonedaHomEquiv, restrictedYonedaHomEquiv', IsColimit.homEquiv] rw [assoc, assoc, ← L.map_comp_assoc] congr 3 apply yonedaEquiv.injective simp [yonedaEquiv] homEquiv_naturality_right := fun {P X Y} f g => by apply (restrictedYonedaHomEquiv L α P Y).symm.injective simp only [Equiv.symm_apply_apply] dsimp [restrictedYonedaHomEquiv, restrictedYonedaHomEquiv', IsColimit.homEquiv] apply (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α P).hom_ext intro p rw [IsColimit.fac] dsimp [restrictedYoneda, yonedaEquiv] simp only [assoc] congr 3 apply yonedaEquiv.injective simp [yonedaEquiv] } /-- Any left Kan extension along the Yoneda embedding preserves colimits. -/ noncomputable def preservesColimitsOfSizeOfIsLeftKanExtension : PreservesColimitsOfSize.{v₃, u₃} L := (yonedaAdjunction L α).leftAdjointPreservesColimits lemma isIso_of_isLeftKanExtension : IsIso α := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ α).isIso_hom variable (A) /-- See Property 2 of https://ncatlab.org/nlab/show/Yoneda+extension#properties. -/ noncomputable instance preservesColimitsOfSizeLeftKanExtension : PreservesColimitsOfSize.{v₃, u₃} (yoneda.leftKanExtension A) := (yonedaAdjunction _ (yoneda.leftKanExtensionUnit A)).leftAdjointPreservesColimits instance : IsIso (yoneda.leftKanExtensionUnit A) := isIso_of_isLeftKanExtension _ (yoneda.leftKanExtensionUnit A) /-- A pointwise left Kan extension along the Yoneda embedding is an extension. -/ noncomputable def isExtensionAlongYoneda : yoneda ⋙ yoneda.leftKanExtension A ≅ A := (asIso (yoneda.leftKanExtensionUnit A)).symm end /-- A functor to the presheaf category in which everything in the image is representable (witnessed by the fact that it factors through the yoneda embedding). `coconeOfRepresentable` gives a cocone for this functor which is a colimit and has point `P`. -/ @[reducible] def functorToRepresentables (P : Cᵒᵖ ⥤ Type v₁) : P.Elementsᵒᵖ ⥤ Cᵒᵖ ⥤ Type v₁ := (CategoryOfElements.π P).leftOp ⋙ yoneda /-- This is a cocone with point `P` for the functor `functorToRepresentables P`. It is shown in `colimitOfRepresentable P` that this cocone is a colimit: that is, we have exhibited an arbitrary presheaf `P` as a colimit of representables. The construction of [MM92], Chapter I, Section 5, Corollary 3. -/ @[simps] noncomputable def coconeOfRepresentable (P : Cᵒᵖ ⥤ Type v₁) : Cocone (functorToRepresentables P) where pt := P ι := { app := fun x => yonedaEquiv.symm x.unop.2 naturality := fun {x₁ x₂} f => by dsimp rw [comp_id] erw [← yonedaEquiv_symm_map] congr 1 rw [f.unop.2] } /-- The legs of the cocone `coconeOfRepresentable` are natural in the choice of presheaf. -/ theorem coconeOfRepresentable_naturality {P₁ P₂ : Cᵒᵖ ⥤ Type v₁} (α : P₁ ⟶ P₂) (j : P₁.Elementsᵒᵖ) : (coconeOfRepresentable P₁).ι.app j ≫ α = (coconeOfRepresentable P₂).ι.app ((CategoryOfElements.map α).op.obj j) := by ext T f simpa [coconeOfRepresentable_ι_app] using FunctorToTypes.naturality _ _ α f.op _ /-- The cocone with point `P` given by `coconeOfRepresentable` is a colimit: that is, we have exhibited an arbitrary presheaf `P` as a colimit of representables. The result of [MM92], Chapter I, Section 5, Corollary 3. -/ noncomputable def colimitOfRepresentable (P : Cᵒᵖ ⥤ Type v₁) : IsColimit (coconeOfRepresentable P) where desc s := { app := fun X x => (s.ι.app (Opposite.op (Functor.elementsMk P X x))).app X (𝟙 _) naturality := fun X Y f => by ext x have eq₁ := congr_fun (congr_app (s.w (CategoryOfElements.homMk (P.elementsMk X x) (P.elementsMk Y (P.map f x)) f rfl).op) Y) (𝟙 _) dsimp at eq₁ ⊢ simpa [← eq₁, id_comp] using congr_fun ((s.ι.app (Opposite.op (P.elementsMk X x))).naturality f) (𝟙 _) } fac s j := by ext X x let φ : j.unop ⟶ Functor.elementsMk P X ((yonedaEquiv.symm j.unop.2).app X x) := ⟨x.op, rfl⟩ simpa using congr_fun (congr_app (s.ι.naturality φ.op).symm X) (𝟙 _) uniq s m hm := by ext X x dsimp rw [← hm] apply congr_arg simp [coconeOfRepresentable_ι_app, yonedaEquiv] variable {A : C ⥤ ℰ} example [HasColimitsOfSize.{v₁, max u₁ v₁} ℰ] : yoneda.HasPointwiseLeftKanExtension A := inferInstance variable [yoneda.HasPointwiseLeftKanExtension A] section variable (L : (Cᵒᵖ ⥤ Type v₁) ⥤ ℰ) (α : A ⟶ yoneda ⋙ L) instance [L.IsLeftKanExtension α] : IsIso α := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α).isIso_hom lemma isLeftKanExtension_along_yoneda_iff : L.IsLeftKanExtension α ↔ (IsIso α ∧ Nonempty (PreservesColimitsOfSize.{v₁, max u₁ v₁} L)) := by constructor · intro exact ⟨inferInstance, ⟨preservesColimitsOfNatIso (Functor.leftKanExtensionUnique _ (yoneda.leftKanExtensionUnit A) _ α)⟩⟩ · rintro ⟨_, ⟨_⟩⟩ apply Functor.LeftExtension.IsPointwiseLeftKanExtension.isLeftKanExtension (E := Functor.LeftExtension.mk _ α) intro P dsimp [Functor.LeftExtension.IsPointwiseLeftKanExtensionAt] apply IsColimit.ofWhiskerEquivalence (CategoryOfElements.costructuredArrowYonedaEquivalence _) let e : CategoryOfElements.toCostructuredArrow P ⋙ CostructuredArrow.proj yoneda P ⋙ A ≅ functorToRepresentables P ⋙ L := isoWhiskerLeft _ (isoWhiskerLeft _ (asIso α)) ≪≫ isoWhiskerLeft _ (Functor.associator _ _ _).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (Iso.refl _) L apply (IsColimit.precomposeHomEquiv e.symm _).1 exact IsColimit.ofIsoColimit (isColimitOfPreserves L (colimitOfRepresentable P)) (Cocones.ext (Iso.refl _)) lemma isLeftKanExtension_of_preservesColimits (L : (Cᵒᵖ ⥤ Type v₁) ⥤ ℰ) (e : A ≅ yoneda ⋙ L) [PreservesColimitsOfSize.{v₁, max u₁ v₁} L] : L.IsLeftKanExtension e.hom := by rw [isLeftKanExtension_along_yoneda_iff] exact ⟨inferInstance, ⟨inferInstance⟩⟩ end /-- Show that `yoneda.leftKanExtension A` is the unique colimit-preserving functor which extends `A` to the presheaf category. The second part of [MM92], Chapter I, Section 5, Corollary 4. See Property 3 of https://ncatlab.org/nlab/show/Yoneda+extension#properties. -/ noncomputable def uniqueExtensionAlongYoneda (L : (Cᵒᵖ ⥤ Type v₁) ⥤ ℰ) (e : A ≅ yoneda ⋙ L) [PreservesColimitsOfSize.{v₁, max u₁ v₁} L] : L ≅ yoneda.leftKanExtension A := have := isLeftKanExtension_of_preservesColimits L e Functor.leftKanExtensionUnique _ e.hom _ (yoneda.leftKanExtensionUnit A) instance (L : (Cᵒᵖ ⥤ Type v₁) ⥤ ℰ) [PreservesColimitsOfSize.{v₁, max u₁ v₁} L] [yoneda.HasPointwiseLeftKanExtension (yoneda ⋙ L)] : L.IsLeftKanExtension (𝟙 _ : yoneda ⋙ L ⟶ _) := isLeftKanExtension_of_preservesColimits _ (Iso.refl _) /-- If `L` preserves colimits and `ℰ` has them, then it is a left adjoint. Note this is a (partial) converse to `leftAdjointPreservesColimits`. -/ lemma isLeftAdjoint_of_preservesColimits (L : (C ⥤ Type v₁) ⥤ ℰ) [PreservesColimitsOfSize.{v₁, max u₁ v₁} L] [yoneda.HasPointwiseLeftKanExtension (yoneda ⋙ (opOpEquivalence C).congrLeft.functor.comp L)] : L.IsLeftAdjoint := ⟨_, ⟨((opOpEquivalence C).congrLeft.symm.toAdjunction.comp (yonedaAdjunction _ (𝟙 _))).ofNatIsoLeft ((opOpEquivalence C).congrLeft.invFunIdAssoc L)⟩⟩ section variable {D : Type u₂} [Category.{v₁} D] (F : C ⥤ D) section instance (X : C) (Y : F.op.LeftExtension (yoneda.obj X)) : Unique (Functor.LeftExtension.mk _ (yonedaMap F X) ⟶ Y) where default := StructuredArrow.homMk (yonedaEquiv.symm (yonedaEquiv (F := F.op.comp Y.right) Y.hom)) (by ext Z f simpa using congr_fun (Y.hom.naturality f.op).symm (𝟙 _)) uniq φ := by ext1 apply yonedaEquiv.injective dsimp simp only [Equiv.apply_symm_apply, ← StructuredArrow.w φ] dsimp [yonedaEquiv] simp only [yonedaMap_app_apply, Functor.map_id] /-- Given `F : C ⥤ D` and `X : C`, `yoneda.obj (F.obj X) : Dᵒᵖ ⥤ Type _` is the left Kan extension of `yoneda.obj X : Cᵒᵖ ⥤ Type _` along `F.op`. -/ instance (X : C) : (yoneda.obj (F.obj X)).IsLeftKanExtension (yonedaMap F X) := ⟨⟨Limits.IsInitial.ofUnique _⟩⟩ end section variable [∀ (P : Cᵒᵖ ⥤ Type v₁), F.op.HasLeftKanExtension P] /-- `F ⋙ yoneda` is naturally isomorphic to `yoneda ⋙ F.op.lan`. -/ noncomputable def compYonedaIsoYonedaCompLan : F ⋙ yoneda ≅ yoneda ⋙ F.op.lan := NatIso.ofComponents (fun X => Functor.leftKanExtensionUnique _ (yonedaMap F X) (F.op.lan.obj _) (F.op.lanUnit.app (yoneda.obj X))) (fun {X Y} f => by apply yonedaEquiv.injective have eq₁ := congr_fun ((yoneda.obj (F.obj Y)).descOfIsLeftKanExtension_fac_app (yonedaMap F Y) (F.op.lan.obj (yoneda.obj Y)) (F.op.lanUnit.app (yoneda.obj Y)) _) f have eq₂ := congr_fun (((yoneda.obj (F.obj X)).descOfIsLeftKanExtension_fac_app (yonedaMap F X) (F.op.lan.obj (yoneda.obj X)) (F.op.lanUnit.app (yoneda.obj X))) _) (𝟙 _) have eq₃ := congr_fun (congr_app (F.op.lanUnit.naturality (yoneda.map f)) _) (𝟙 _) dsimp at eq₁ eq₂ eq₃ simp only [Functor.map_id] at eq₂ simp only [id_comp] at eq₃ simp [yonedaEquiv, eq₁, eq₂, eq₃]) @[simp] lemma compYonedaIsoYonedaCompLan_inv_app_app_apply_eq_id (X : C) : ((compYonedaIsoYonedaCompLan F).inv.app X).app (Opposite.op (F.obj X)) ((F.op.lanUnit.app (yoneda.obj X)).app _ (𝟙 X)) = 𝟙 _ := (congr_fun (Functor.descOfIsLeftKanExtension_fac_app _ (F.op.lanUnit.app (yoneda.obj X)) _ (yonedaMap F X) (Opposite.op X)) (𝟙 _)).trans (by simp) end namespace compYonedaIsoYonedaCompLan variable {F} section variable {X : C} {G : (Cᵒᵖ ⥤ Type v₁) ⥤ Dᵒᵖ ⥤ Type v₁} (φ : F ⋙ yoneda ⟶ yoneda ⋙ G) /-- Auxiliary definition for `presheafHom`. -/ def coconeApp {P : Cᵒᵖ ⥤ Type v₁} (x : P.Elements) : yoneda.obj x.1.unop ⟶ F.op ⋙ G.obj P := yonedaEquiv.symm ((G.map (yonedaEquiv.symm x.2)).app _ ((φ.app x.1.unop).app _ (𝟙 _))) @[reassoc (attr := simp)] lemma coconeApp_naturality {P : Cᵒᵖ ⥤ Type v₁} {x y : P.Elements} (f : x ⟶ y) : yoneda.map f.1.unop ≫ coconeApp φ x = coconeApp φ y := by have eq₁ : yoneda.map f.1.unop ≫ yonedaEquiv.symm x.2 = yonedaEquiv.symm y.2 := yonedaEquiv.injective (by simpa only [Equiv.apply_symm_apply, ← yonedaEquiv_naturality] using f.2) have eq₂ := congr_fun ((G.map (yonedaEquiv.symm x.2)).naturality (F.map f.1.unop).op) ((φ.app x.1.unop).app _ (𝟙 _)) have eq₃ := congr_fun (congr_app (φ.naturality f.1.unop) _) (𝟙 _) have eq₄ := congr_fun ((φ.app x.1.unop).naturality (F.map f.1.unop).op) dsimp at eq₂ eq₃ eq₄ apply yonedaEquiv.injective dsimp only [coconeApp] rw [Equiv.apply_symm_apply, ← yonedaEquiv_naturality, Equiv.apply_symm_apply] simp [← eq₁, ← eq₂, ← eq₃, ← eq₄, Functor.map_comp, FunctorToTypes.comp, id_comp, comp_id] /-- Given functors `F : C ⥤ D` and `G : (Cᵒᵖ ⥤ Type v₁) ⥤ (Dᵒᵖ ⥤ Type v₁)`, and a natural transformation `φ : F ⋙ yoneda ⟶ yoneda ⋙ G`, this is the (natural) morphism `P ⟶ F.op ⋙ G.obj P` for all `P : Cᵒᵖ ⥤ Type v₁` that is determined by `φ`. -/ noncomputable def presheafHom (P : Cᵒᵖ ⥤ Type v₁) : P ⟶ F.op ⋙ G.obj P := (colimitOfRepresentable P).desc (Cocone.mk _ { app := fun x => coconeApp φ x.unop }) lemma yonedaEquiv_ι_presheafHom (P : Cᵒᵖ ⥤ Type v₁) {X : C} (f : yoneda.obj X ⟶ P) : yonedaEquiv (f ≫ presheafHom φ P) = (G.map f).app (Opposite.op (F.obj X)) ((φ.app X).app _ (𝟙 _)) := by obtain ⟨x, rfl⟩ := yonedaEquiv.symm.surjective f erw [(colimitOfRepresentable P).fac _ (Opposite.op (P.elementsMk _ x))] dsimp only [coconeApp] apply Equiv.apply_symm_apply lemma yonedaEquiv_presheafHom_yoneda_obj (X : C) : yonedaEquiv (presheafHom φ (yoneda.obj X)) = ((φ.app X).app (F.op.obj (Opposite.op X)) (𝟙 _)) := by simpa using yonedaEquiv_ι_presheafHom φ (yoneda.obj X) (𝟙 _) @[reassoc (attr := simp)] lemma presheafHom_naturality {P Q : Cᵒᵖ ⥤ Type v₁} (f : P ⟶ Q) : presheafHom φ P ≫ whiskerLeft F.op (G.map f) = f ≫ presheafHom φ Q := hom_ext_yoneda (fun X p => yonedaEquiv.injective (by rw [← assoc p f, yonedaEquiv_ι_presheafHom, ← assoc, yonedaEquiv_comp, yonedaEquiv_ι_presheafHom, whiskerLeft_app, Functor.map_comp, FunctorToTypes.comp] dsimp)) variable [∀ (P : Cᵒᵖ ⥤ Type v₁), F.op.HasLeftKanExtension P] /-- Given functors `F : C ⥤ D` and `G : (Cᵒᵖ ⥤ Type v₁) ⥤ (Dᵒᵖ ⥤ Type v₁)`, and a natural transformation `φ : F ⋙ yoneda ⟶ yoneda ⋙ G`, this is the canonical natural transformation `F.op.lan ⟶ G`, which is part of the that `F.op.lan : (Cᵒᵖ ⥤ Type v₁) ⥤ Dᵒᵖ ⥤ Type v₁` is the left Kan extension of `F ⋙ yoneda : C ⥤ Dᵒᵖ ⥤ Type v₁` along `yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁`. -/ noncomputable def natTrans : F.op.lan ⟶ G where app P := (F.op.lan.obj P).descOfIsLeftKanExtension (F.op.lanUnit.app P) _ (presheafHom φ P) naturality {P Q} f := by apply (F.op.lan.obj P).hom_ext_of_isLeftKanExtension (F.op.lanUnit.app P) have eq := F.op.lanUnit.naturality f dsimp at eq ⊢ rw [Functor.descOfIsLeftKanExtension_fac_assoc, ← reassoc_of% eq, Functor.descOfIsLeftKanExtension_fac, presheafHom_naturality] lemma natTrans_app_yoneda_obj (X : C) : (natTrans φ).app (yoneda.obj X) = (compYonedaIsoYonedaCompLan F).inv.app X ≫ φ.app X := by dsimp [natTrans] apply (F.op.lan.obj (yoneda.obj X)).hom_ext_of_isLeftKanExtension (F.op.lanUnit.app _) rw [Functor.descOfIsLeftKanExtension_fac] apply yonedaEquiv.injective rw [yonedaEquiv_presheafHom_yoneda_obj] exact congr_arg _ (compYonedaIsoYonedaCompLan_inv_app_app_apply_eq_id F X).symm end variable [∀ (P : Cᵒᵖ ⥤ Type v₁), F.op.HasLeftKanExtension P] /-- Given a functor `F : C ⥤ D`, this definition is part of the verification that `Functor.LeftExtension.mk F.op.lan (compYonedaIsoYonedaCompLan F).hom` is universal, i.e. that `F.op.lan : (Cᵒᵖ ⥤ Type v₁) ⥤ Dᵒᵖ ⥤ Type v₁` is the left Kan extension of `F ⋙ yoneda : C ⥤ Dᵒᵖ ⥤ Type v₁` along `yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁`. -/ noncomputable def extensionHom (Φ : yoneda.LeftExtension (F ⋙ yoneda)) : Functor.LeftExtension.mk F.op.lan (compYonedaIsoYonedaCompLan F).hom ⟶ Φ := StructuredArrow.homMk (natTrans Φ.hom) (by ext X : 2 dsimp rw [natTrans_app_yoneda_obj, Iso.hom_inv_id_app_assoc]) @[ext] lemma hom_ext {Φ : yoneda.LeftExtension (F ⋙ yoneda)} (f g : Functor.LeftExtension.mk F.op.lan (compYonedaIsoYonedaCompLan F).hom ⟶ Φ) : f = g := by ext P : 3 apply (F.op.lan.obj P).hom_ext_of_isLeftKanExtension (F.op.lanUnit.app P) apply (colimitOfRepresentable P).hom_ext intro x have eq := F.op.lanUnit.naturality (yonedaEquiv.symm x.unop.2) have eq₁ := congr_fun (congr_app (congr_app (StructuredArrow.w f) x.unop.1.unop) (F.op.obj x.unop.1)) (𝟙 _) have eq₂ := congr_fun (congr_app (congr_app (StructuredArrow.w g) x.unop.1.unop) (F.op.obj x.unop.1)) (𝟙 _) dsimp at eq₁ eq₂ eq ⊢ simp only [reassoc_of% eq, ← whiskerLeft_comp] congr 2 simp only [← cancel_epi ((compYonedaIsoYonedaCompLan F).hom.app x.unop.1.unop), NatTrans.naturality] apply yonedaEquiv.injective dsimp [yonedaEquiv_apply] rw [eq₁, eq₂] end compYonedaIsoYonedaCompLan variable [∀ (P : Cᵒᵖ ⥤ Type v₁), F.op.HasLeftKanExtension P] noncomputable instance (Φ : StructuredArrow (F ⋙ yoneda) ((whiskeringLeft C (Cᵒᵖ ⥤ Type v₁) (Dᵒᵖ ⥤ Type v₁)).obj yoneda)) : Unique (Functor.LeftExtension.mk F.op.lan (compYonedaIsoYonedaCompLan F).hom ⟶ Φ) where default := compYonedaIsoYonedaCompLan.extensionHom Φ uniq _ := compYonedaIsoYonedaCompLan.hom_ext _ _ /-- Given a functor `F : C ⥤ D`, `F.op.lan : (Cᵒᵖ ⥤ Type v₁) ⥤ Dᵒᵖ ⥤ Type v₁` is the left Kan extension of `F ⋙ yoneda : C ⥤ Dᵒᵖ ⥤ Type v₁` along `yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁`. -/ instance : F.op.lan.IsLeftKanExtension (compYonedaIsoYonedaCompLan F).hom := ⟨⟨Limits.IsInitial.ofUnique _⟩⟩ end section variable {C : Type u₁} [Category.{v₁} C] (P : Cᵒᵖ ⥤ Type v₁) /-- For a presheaf `P`, consider the forgetful functor from the category of representable presheaves over `P` to the category of presheaves. There is a tautological cocone over this functor whose leg for a natural transformation `V ⟶ P` with `V` representable is just that natural transformation. -/ @[simps] def tautologicalCocone : Cocone (CostructuredArrow.proj yoneda P ⋙ yoneda) where pt := P ι := { app := fun X => X.hom } /-- The tautological cocone with point `P` is a colimit cocone, exhibiting `P` as a colimit of representables. Proposition 2.6.3(i) in [Kashiwara2006] -/ def isColimitTautologicalCocone : IsColimit (tautologicalCocone P) where desc := fun s => by refine ⟨fun X t => yonedaEquiv (s.ι.app (CostructuredArrow.mk (yonedaEquiv.symm t))), ?_⟩ intros X Y f ext t dsimp rw [yonedaEquiv_naturality', yonedaEquiv_symm_map] simpa using (s.ι.naturality (CostructuredArrow.homMk' (CostructuredArrow.mk (yonedaEquiv.symm t)) f.unop)).symm fac := by intro s t dsimp apply yonedaEquiv.injective rw [yonedaEquiv_comp] dsimp only rw [Equiv.symm_apply_apply] rfl uniq := by intro s j h ext V x obtain ⟨t, rfl⟩ := yonedaEquiv.surjective x dsimp rw [Equiv.symm_apply_apply, ← yonedaEquiv_comp] exact congr_arg _ (h (CostructuredArrow.mk t)) variable {I : Type v₁} [SmallCategory I] (F : I ⥤ C) /-- Given a functor `F : I ⥤ C`, a cocone `c` on `F ⋙ yoneda : I ⥤ Cᵒᵖ ⥤ Type v₁` induces a functor `I ⥤ CostructuredArrow yoneda c.pt` which maps `i : I` to the leg `yoneda.obj (F.obj i) ⟶ c.pt`. If `c` is a colimit cocone, then that functor is final. Proposition 2.6.3(ii) in [Kashiwara2006] -/ theorem final_toCostructuredArrow_comp_pre {c : Cocone (F ⋙ yoneda)} (hc : IsColimit c) : Functor.Final (c.toCostructuredArrow ⋙ CostructuredArrow.pre F yoneda c.pt) := by apply Functor.cofinal_of_isTerminal_colimit_comp_yoneda suffices IsTerminal (colimit ((c.toCostructuredArrow ⋙ CostructuredArrow.pre F yoneda c.pt) ⋙ CostructuredArrow.toOver yoneda c.pt)) by apply IsTerminal.isTerminalOfObj (overEquivPresheafCostructuredArrow c.pt).inverse apply IsTerminal.ofIso this refine ?_ ≪≫ (preservesColimitIso (overEquivPresheafCostructuredArrow c.pt).inverse _).symm apply HasColimit.isoOfNatIso exact isoWhiskerLeft _ (CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow c.pt).isoCompInverse apply IsTerminal.ofIso Over.mkIdTerminal let isc : IsColimit ((Over.forget _).mapCocone _) := PreservesColimit.preserves (colimit.isColimit ((c.toCostructuredArrow ⋙ CostructuredArrow.pre F yoneda c.pt) ⋙ CostructuredArrow.toOver yoneda c.pt)) exact Over.isoMk (hc.coconePointUniqueUpToIso isc) (hc.hom_ext fun i => by simp) end end Presheaf end CategoryTheory
CategoryTheory\Limits\SmallComplete.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.SetTheory.Cardinal.Basic /-! # Any small complete category is a preorder We show that any small category which has all (small) limits is a preorder: In particular, we show that if a small category `C` in universe `u` has products of size `u`, then for any `X Y : C` there is at most one morphism `X ⟶ Y`. Note that in Lean, a preorder category is strictly one where the morphisms are in `Prop`, so we instead show that the homsets are subsingleton. ## References * https://ncatlab.org/nlab/show/complete+small+category#in_classical_logic ## Tags small complete, preorder, Freyd -/ namespace CategoryTheory open Category Limits open Cardinal universe u variable {C : Type u} [SmallCategory C] [HasProducts.{u} C] /-- A small category with products is a thin category. in Lean, a preorder category is one where the morphisms are in Prop, which is weaker than the usual notion of a preorder/thin category which says that each homset is subsingleton; we show the latter rather than providing a `Preorder C` instance. -/ instance (priority := 100) : Quiver.IsThin C := fun X Y => ⟨fun r s => by classical by_contra r_ne_s have z : (2 : Cardinal) ≤ #(X ⟶ Y) := by rw [Cardinal.two_le_iff] exact ⟨_, _, r_ne_s⟩ let md := ΣZ W : C, Z ⟶ W let α := #md apply not_le_of_lt (Cardinal.cantor α) let yp : C := ∏ᶜ fun _ : md => Y apply _root_.trans _ _ · exact #(X ⟶ yp) · apply le_trans (Cardinal.power_le_power_right z) rw [Cardinal.power_def] apply le_of_eq rw [Cardinal.eq] refine ⟨⟨Pi.lift, fun f k => f ≫ Pi.π _ k, ?_, ?_⟩⟩ · intro f ext k simp · intro f ext ⟨j⟩ simp · apply Cardinal.mk_le_of_injective _ · intro f exact ⟨_, _, f⟩ · rintro f g k cases k rfl⟩ end CategoryTheory
CategoryTheory\Limits\Types.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Reid Barton -/ import Mathlib.Data.TypeMax import Mathlib.Logic.UnivLE import Mathlib.CategoryTheory.Limits.Shapes.Images /-! # Limits in the category of types. We show that the category of types has all (co)limits, by providing the usual concrete models. Next, we prove the category of types has categorical images, and that these agree with the range of a function. Finally, we give the natural isomorphism between cones on `F` with cone point `X` and the type `lim Hom(X, F·)`, and similarly the natural isomorphism between cocones on `F` with cocone point `X` and the type `lim Hom(F·, X)`. -/ open CategoryTheory CategoryTheory.Limits universe v u w namespace CategoryTheory.Limits namespace Types section limit_characterization variable {J : Type v} [Category.{w} J] {F : J ⥤ Type u} /-- Given a section of a functor F into `Type*`, construct a cone over F with `PUnit` as the cone point. -/ def coneOfSection {s} (hs : s ∈ F.sections) : Cone F where pt := PUnit π := { app := fun j _ ↦ s j, naturality := fun i j f ↦ by ext; exact (hs f).symm } /-- Given a cone over a functor F into `Type*` and an element in the cone point, construct a section of F. -/ def sectionOfCone (c : Cone F) (x : c.pt) : F.sections := ⟨fun j ↦ c.π.app j x, fun f ↦ congr_fun (c.π.naturality f).symm x⟩ theorem isLimit_iff (c : Cone F) : Nonempty (IsLimit c) ↔ ∀ s ∈ F.sections, ∃! x : c.pt, ∀ j, c.π.app j x = s j := by refine ⟨fun ⟨t⟩ s hs ↦ ?_, fun h ↦ ⟨?_⟩⟩ · let cs := coneOfSection hs exact ⟨t.lift cs ⟨⟩, fun j ↦ congr_fun (t.fac cs j) ⟨⟩, fun x hx ↦ congr_fun (t.uniq cs (fun _ ↦ x) fun j ↦ funext fun _ ↦ hx j) ⟨⟩⟩ · choose x hx using fun c y ↦ h _ (sectionOfCone c y).2 exact ⟨x, fun c j ↦ funext fun y ↦ (hx c y).1 j, fun c f hf ↦ funext fun y ↦ (hx c y).2 (f y) (fun j ↦ congr_fun (hf j) y)⟩ theorem isLimit_iff_bijective_sectionOfCone (c : Cone F) : Nonempty (IsLimit c) ↔ (Types.sectionOfCone c).Bijective := by simp_rw [isLimit_iff, Function.bijective_iff_existsUnique, Subtype.forall, F.sections_ext_iff, sectionOfCone] /-- The equivalence between a limiting cone of `F` in `Type u` and the "concrete" definition as the sections of `F`. -/ noncomputable def isLimitEquivSections {c : Cone F} (t : IsLimit c) : c.pt ≃ F.sections where toFun := sectionOfCone c invFun s := t.lift (coneOfSection s.2) ⟨⟩ left_inv x := (congr_fun (t.uniq (coneOfSection _) (fun _ ↦ x) fun _ ↦ rfl) ⟨⟩).symm right_inv s := Subtype.ext (funext fun j ↦ congr_fun (t.fac (coneOfSection s.2) j) ⟨⟩) @[simp] theorem isLimitEquivSections_apply {c : Cone F} (t : IsLimit c) (j : J) (x : c.pt) : (isLimitEquivSections t x : ∀ j, F.obj j) j = c.π.app j x := rfl @[simp] theorem isLimitEquivSections_symm_apply {c : Cone F} (t : IsLimit c) (x : F.sections) (j : J) : c.π.app j ((isLimitEquivSections t).symm x) = (x : ∀ j, F.obj j) j := by conv_rhs => rw [← (isLimitEquivSections t).right_inv x] rfl end limit_characterization variable {J : Type v} [Category.{w} J] /-! We now provide two distinct implementations in the category of types. The first, in the `CategoryTheory.Limits.Types.Small` namespace, assumes `Small.{u} J` and constructs `J`-indexed limits in `Type u`. The second, in the `CategoryTheory.Limits.Types.TypeMax` namespace constructs limits for functors `F : J ⥤ TypeMax.{v, u}`, for `J : Type v`. This construction is slightly nicer, as the limit is definitionally just `F.sections`, rather than `Shrink F.sections`, which makes an arbitrary choice of `u`-small representative. Hopefully we might be able to entirely remove the `TypeMax` constructions, but for now they are useful glue for the later parts of the library. -/ namespace Small variable (F : J ⥤ Type u) section variable [Small.{u} F.sections] /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone : Cone F where pt := Shrink F.sections π := { app := fun j u => ((equivShrink F.sections).symm u).val j naturality := fun j j' f => by funext x simp } @[ext] lemma limitCone_pt_ext {x y : (limitCone F).pt} (w : (equivShrink F.sections).symm x = (equivShrink F.sections).symm y) : x = y := by aesop /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit : IsLimit (limitCone.{v, u} F) where lift s v := equivShrink F.sections { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by ext x j simpa using congr_fun (w j) x end end Small theorem hasLimit_iff_small_sections (F : J ⥤ Type u) : HasLimit F ↔ Small.{u} F.sections := ⟨fun _ => .mk ⟨_, ⟨(Equiv.ofBijective _ ((isLimit_iff_bijective_sectionOfCone (limit.cone F)).mp ⟨limit.isLimit _⟩)).symm⟩⟩, fun _ => ⟨_, Small.limitConeIsLimit F⟩⟩ -- TODO: If `UnivLE` works out well, we will eventually want to deprecate these -- definitions, and probably as a first step put them in namespace or otherwise rename them. section TypeMax /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone (F : J ⥤ TypeMax.{v, u}) : Cone F where pt := F.sections π := { app := fun j u => u.val j naturality := fun j j' f => by funext x simp } /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit (F : J ⥤ TypeMax.{v, u}) : IsLimit (limitCone F) where lift s v := { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by funext x apply Subtype.ext funext j exact congr_fun (w j) x end TypeMax /-! The results in this section have a `UnivLE.{v, u}` hypothesis, but as they only use the constructions from the `CategoryTheory.Limits.Types.UnivLE` namespace in their definitions (rather than their statements), we leave them in the main `CategoryTheory.Limits.Types` namespace. -/ section UnivLE open UnivLE instance hasLimit [Small.{u} J] (F : J ⥤ Type u) : HasLimit F := (hasLimit_iff_small_sections F).mpr inferInstance instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J (Type u) where /-- The category of types has all limits. More specifically, when `UnivLE.{v, u}`, the category `Type u` has all `v`-small limits. See <https://stacks.math.columbia.edu/tag/002U>. -/ instance (priority := 1300) hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} (Type u) where has_limits_of_shape _ := { } variable (F : J ⥤ Type u) [HasLimit F] /-- The equivalence between the abstract limit of `F` in `TypeMax.{v, u}` and the "concrete" definition as the sections of `F`. -/ noncomputable def limitEquivSections : limit F ≃ F.sections := isLimitEquivSections (limit.isLimit F) @[simp] theorem limitEquivSections_apply (x : limit F) (j : J) : ((limitEquivSections F) x : ∀ j, F.obj j) j = limit.π F j x := isLimitEquivSections_apply _ _ _ @[simp] theorem limitEquivSections_symm_apply (x : F.sections) (j : J) : limit.π F j ((limitEquivSections F).symm x) = (x : ∀ j, F.obj j) j := isLimitEquivSections_symm_apply _ _ _ -- Porting note: `limitEquivSections_symm_apply'` was removed because the linter -- complains it is unnecessary --@[simp] --theorem limitEquivSections_symm_apply' (F : J ⥤ Type v) (x : F.sections) (j : J) : -- limit.π F j ((limitEquivSections.{v, v} F).symm x) = (x : ∀ j, F.obj j) j := -- isLimitEquivSections_symm_apply _ _ _ -- Porting note (#11182): removed @[ext] /-- Construct a term of `limit F : Type u` from a family of terms `x : Π j, F.obj j` which are "coherent": `∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j'`. -/ noncomputable def Limit.mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') : limit F := (limitEquivSections F).symm ⟨x, h _ _⟩ @[simp] theorem Limit.π_mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') (j) : limit.π F j (Limit.mk F x h) = x j := by dsimp [Limit.mk] simp -- Porting note: `Limit.π_mk'` was removed because the linter complains it is unnecessary --@[simp] --theorem Limit.π_mk' (F : J ⥤ Type v) (x : ∀ j, F.obj j) -- (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') (j) : -- limit.π F j (Limit.mk.{v, v} F x h) = x j := by -- dsimp [Limit.mk] -- simp -- PROJECT: prove this for concrete categories where the forgetful functor preserves limits @[ext] theorem limit_ext (x y : limit F) (w : ∀ j, limit.π F j x = limit.π F j y) : x = y := by apply (limitEquivSections F).injective ext j simp [w j] @[ext] theorem limit_ext' (F : J ⥤ Type v) (x y : limit F) (w : ∀ j, limit.π F j x = limit.π F j y) : x = y := limit_ext F x y w theorem limit_ext_iff' (F : J ⥤ Type v) (x y : limit F) : x = y ↔ ∀ j, limit.π F j x = limit.π F j y := ⟨fun t _ => t ▸ rfl, limit_ext' _ _ _⟩ -- TODO: are there other limits lemmas that should have `_apply` versions? -- Can we generate these like with `@[reassoc]`? -- PROJECT: prove these for any concrete category where the forgetful functor preserves limits? -- Porting note (#11119): @[simp] was removed because the linter said it was useless --@[simp] variable {F} in theorem Limit.w_apply {j j' : J} {x : limit F} (f : j ⟶ j') : F.map f (limit.π F j x) = limit.π F j' x := congr_fun (limit.w F f) x -- Porting note (#11119): @[simp] was removed because the linter said it was useless theorem Limit.lift_π_apply (s : Cone F) (j : J) (x : s.pt) : limit.π F j (limit.lift F s x) = s.π.app j x := congr_fun (limit.lift_π s j) x -- Porting note (#11119): @[simp] was removed because the linter said it was useless theorem Limit.map_π_apply {F G : J ⥤ Type u} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) (x : limit F) : limit.π G j (limMap α x) = α.app j (limit.π F j x) := congr_fun (limMap_π α j) x @[simp] theorem Limit.w_apply' {F : J ⥤ Type v} {j j' : J} {x : limit F} (f : j ⟶ j') : F.map f (limit.π F j x) = limit.π F j' x := congr_fun (limit.w F f) x @[simp] theorem Limit.lift_π_apply' (F : J ⥤ Type v) (s : Cone F) (j : J) (x : s.pt) : limit.π F j (limit.lift F s x) = s.π.app j x := congr_fun (limit.lift_π s j) x @[simp] theorem Limit.map_π_apply' {F G : J ⥤ Type v} (α : F ⟶ G) (j : J) (x : limit F) : limit.π G j (limMap α x) = α.app j (limit.π F j x) := congr_fun (limMap_π α j) x end UnivLE /-! In this section we verify that instances are available as expected. -/ section instances example : HasLimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (TypeMax.{w, v}) := inferInstance example : HasLimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (Type max v w) := inferInstance example : HasLimitsOfSize.{0, 0, v, v+1} (Type v) := inferInstance example : HasLimitsOfSize.{v, v, v, v+1} (Type v) := inferInstance example [UnivLE.{v, u}] : HasLimitsOfSize.{v, v, u, u+1} (Type u) := inferInstance end instances /-- The relation defining the quotient type which implements the colimit of a functor `F : J ⥤ Type u`. See `CategoryTheory.Limits.Types.Quot`. -/ def Quot.Rel (F : J ⥤ Type u) : (Σ j, F.obj j) → (Σ j, F.obj j) → Prop := fun p p' => ∃ f : p.1 ⟶ p'.1, p'.2 = F.map f p.2 -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- A quotient type implementing the colimit of a functor `F : J ⥤ Type u`, as pairs `⟨j, x⟩` where `x : F.obj j`, modulo the equivalence relation generated by `⟨j, x⟩ ~ ⟨j', x'⟩` whenever there is a morphism `f : j ⟶ j'` so `F.map f x = x'`. -/ def Quot (F : J ⥤ Type u) : Type (max v u) := _root_.Quot (Quot.Rel F) instance [Small.{u} J] (F : J ⥤ Type u) : Small.{u} (Quot F) := small_of_surjective (surjective_quot_mk _) /-- Inclusion into the quotient type implementing the colimit. -/ def Quot.ι (F : J ⥤ Type u) (j : J) : F.obj j → Quot F := fun x => Quot.mk _ ⟨j, x⟩ lemma Quot.jointly_surjective {F : J ⥤ Type u} (x : Quot F) : ∃ j y, x = Quot.ι F j y := Quot.ind (β := fun x => ∃ j y, x = Quot.ι F j y) (fun ⟨j, y⟩ => ⟨j, y, rfl⟩) x section variable {F : J ⥤ Type u} (c : Cocone F) /-- (implementation detail) Part of the universal property of the colimit cocone, but without assuming that `Quot F` lives in the correct universe. -/ def Quot.desc : Quot F → c.pt := Quot.lift (fun x => c.ι.app x.1 x.2) <| by rintro ⟨j, x⟩ ⟨j', _⟩ ⟨φ : j ⟶ j', rfl : _ = F.map φ x⟩ exact congr_fun (c.ι.naturality φ).symm x @[simp] lemma Quot.ι_desc (j : J) (x : F.obj j) : Quot.desc c (Quot.ι F j x) = c.ι.app j x := rfl @[simp] lemma Quot.map_ι {j j' : J} {f : j ⟶ j'} (x : F.obj j) : Quot.ι F j' (F.map f x) = Quot.ι F j x := (Quot.sound ⟨f, rfl⟩).symm /-- (implementation detail) A function `Quot F → α` induces a cocone on `F` as long as the universes work out. -/ @[simps] def toCocone {α : Type u} (f : Quot F → α) : Cocone F where pt := α ι := { app := fun j => f ∘ Quot.ι F j } lemma Quot.desc_toCocone_desc {α : Type u} (f : Quot F → α) (hc : IsColimit c) (x : Quot F) : hc.desc (toCocone f) (Quot.desc c x) = f x := by obtain ⟨j, y, rfl⟩ := Quot.jointly_surjective x simpa using congrFun (hc.fac _ j) y theorem isColimit_iff_bijective_desc : Nonempty (IsColimit c) ↔ (Quot.desc c).Bijective := by classical refine ⟨?_, ?_⟩ · refine fun ⟨hc⟩ => ⟨fun x y h => ?_, fun x => ?_⟩ · let f : Quot F → ULift.{u} Bool := fun z => ULift.up (x = z) suffices f x = f y by simpa [f] using this rw [← Quot.desc_toCocone_desc c f hc x, h, Quot.desc_toCocone_desc] · let f₁ : c.pt ⟶ ULift.{u} Bool := fun _ => ULift.up true let f₂ : c.pt ⟶ ULift.{u} Bool := fun x => ULift.up (∃ a, Quot.desc c a = x) suffices f₁ = f₂ by simpa [f₁, f₂] using congrFun this x refine hc.hom_ext fun j => funext fun x => ?_ simpa [f₁, f₂] using ⟨Quot.ι F j x, by simp⟩ · refine fun h => ⟨?_⟩ let e := Equiv.ofBijective _ h have h : ∀ j x, e.symm (c.ι.app j x) = Quot.ι F j x := fun j x => e.injective (Equiv.ofBijective_apply_symm_apply _ _ _) exact { desc := fun s => Quot.desc s ∘ e.symm fac := fun s j => by ext x simp [h] uniq := fun s m hm => by ext x obtain ⟨x, rfl⟩ := e.surjective x obtain ⟨j, x, rfl⟩ := Quot.jointly_surjective x rw [← h, Equiv.apply_symm_apply] simpa [h] using congrFun (hm j) x } end /-- (internal implementation) the colimit cocone of a functor, implemented as a quotient of a sigma type -/ @[simps] noncomputable def colimitCocone (F : J ⥤ Type u) [Small.{u} (Quot F)] : Cocone F where pt := Shrink (Quot F) ι := { app := fun j x => equivShrink.{u} _ (Quot.mk _ ⟨j, x⟩) naturality := fun _ _ f => funext fun _ => congrArg _ (Quot.sound ⟨f, rfl⟩).symm } @[simp] theorem Quot.desc_colimitCocone (F : J ⥤ Type u) [Small.{u} (Quot F)] : Quot.desc (colimitCocone F) = equivShrink.{u} (Quot F) := by ext ⟨j, x⟩ rfl /-- (internal implementation) the fact that the proposed colimit cocone is the colimit -/ noncomputable def colimitCoconeIsColimit (F : J ⥤ Type u) [Small.{u} (Quot F)] : IsColimit (colimitCocone F) := Nonempty.some <| by rw [isColimit_iff_bijective_desc, Quot.desc_colimitCocone] exact (equivShrink _).bijective theorem hasColimit_iff_small_quot (F : J ⥤ Type u) : HasColimit F ↔ Small.{u} (Quot F) := ⟨fun _ => .mk ⟨_, ⟨(Equiv.ofBijective _ ((isColimit_iff_bijective_desc (colimit.cocone F)).mp ⟨colimit.isColimit _⟩))⟩⟩, fun _ => ⟨_, colimitCoconeIsColimit F⟩⟩ theorem small_quot_of_hasColimit (F : J ⥤ Type u) [HasColimit F] : Small.{u} (Quot F) := (hasColimit_iff_small_quot F).mp inferInstance instance hasColimit [Small.{u} J] (F : J ⥤ Type u) : HasColimit F := (hasColimit_iff_small_quot F).mpr inferInstance instance hasColimitsOfShape [Small.{u} J] : HasColimitsOfShape J (Type u) where /-- The category of types has all colimits. See <https://stacks.math.columbia.edu/tag/002U>. -/ instance (priority := 1300) hasColimitsOfSize [UnivLE.{v, u}] : HasColimitsOfSize.{w, v} (Type u) where section instances example : HasColimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (TypeMax.{w, v}) := inferInstance example : HasColimitsOfSize.{w, w, max v w, max (v + 1) (w + 1)} (Type max v w) := inferInstance example : HasColimitsOfSize.{0, 0, v, v+1} (Type v) := inferInstance example : HasColimitsOfSize.{v, v, v, v+1} (Type v) := inferInstance example [UnivLE.{v, u}] : HasColimitsOfSize.{v, v, u, u+1} (Type u) := inferInstance end instances namespace TypeMax /-- (internal implementation) the colimit cocone of a functor, implemented as a quotient of a sigma type -/ @[simps] def colimitCocone (F : J ⥤ TypeMax.{v, u}) : Cocone F where pt := Quot F ι := { app := fun j x => Quot.mk (Quot.Rel F) ⟨j, x⟩ naturality := fun _ _ f => funext fun _ => (Quot.sound ⟨f, rfl⟩).symm } /-- (internal implementation) the fact that the proposed colimit cocone is the colimit -/ def colimitCoconeIsColimit (F : J ⥤ TypeMax.{v, u}) : IsColimit (colimitCocone F) where desc s := Quot.lift (fun p : Σj, F.obj j => s.ι.app p.1 p.2) fun ⟨j, x⟩ ⟨j', x'⟩ ⟨f, hf⟩ => by dsimp at hf rw [hf] exact (congr_fun (Cocone.w s f) x).symm uniq s m hm := by funext x induction' x using Quot.ind with x exact congr_fun (hm x.1) x.2 end TypeMax variable (F : J ⥤ Type u) [HasColimit F] attribute [local instance] small_quot_of_hasColimit /-- The equivalence between the abstract colimit of `F` in `Type u` and the "concrete" definition as a quotient. -/ noncomputable def colimitEquivQuot : colimit F ≃ Quot F := (IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) (colimitCoconeIsColimit F)).toEquiv.trans (equivShrink _).symm @[simp] theorem colimitEquivQuot_symm_apply (j : J) (x : F.obj j) : (colimitEquivQuot F).symm (Quot.mk _ ⟨j, x⟩) = colimit.ι F j x := congrFun (IsColimit.comp_coconePointUniqueUpToIso_inv (colimit.isColimit F) _ _) x @[simp] theorem colimitEquivQuot_apply (j : J) (x : F.obj j) : (colimitEquivQuot F) (colimit.ι F j x) = Quot.mk _ ⟨j, x⟩ := by apply (colimitEquivQuot F).symm.injective simp -- Porting note (#11119): @[simp] was removed because the linter said it was useless variable {F} in theorem Colimit.w_apply {j j' : J} {x : F.obj j} (f : j ⟶ j') : colimit.ι F j' (F.map f x) = colimit.ι F j x := congr_fun (colimit.w F f) x -- Porting note (#11119): @[simp] was removed because the linter said it was useless theorem Colimit.ι_desc_apply (s : Cocone F) (j : J) (x : F.obj j) : colimit.desc F s (colimit.ι F j x) = s.ι.app j x := congr_fun (colimit.ι_desc s j) x -- Porting note (#11119): @[simp] was removed because the linter said it was useless theorem Colimit.ι_map_apply {F G : J ⥤ Type u} [HasColimitsOfShape J (Type u)] (α : F ⟶ G) (j : J) (x : F.obj j) : colim.map α (colimit.ι F j x) = colimit.ι G j (α.app j x) := congr_fun (colimit.ι_map α j) x @[simp] theorem Colimit.w_apply' {F : J ⥤ Type v} {j j' : J} {x : F.obj j} (f : j ⟶ j') : colimit.ι F j' (F.map f x) = colimit.ι F j x := congr_fun (colimit.w F f) x @[simp] theorem Colimit.ι_desc_apply' (F : J ⥤ Type v) (s : Cocone F) (j : J) (x : F.obj j) : colimit.desc F s (colimit.ι F j x) = s.ι.app j x := congr_fun (colimit.ι_desc s j) x @[simp] theorem Colimit.ι_map_apply' {F G : J ⥤ Type v} (α : F ⟶ G) (j : J) (x) : colim.map α (colimit.ι F j x) = colimit.ι G j (α.app j x) := congr_fun (colimit.ι_map α j) x variable {F} in theorem colimit_sound {j j' : J} {x : F.obj j} {x' : F.obj j'} (f : j ⟶ j') (w : F.map f x = x') : colimit.ι F j x = colimit.ι F j' x' := by rw [← w, Colimit.w_apply] variable {F} in theorem colimit_sound' {j j' : J} {x : F.obj j} {x' : F.obj j'} {j'' : J} (f : j ⟶ j'') (f' : j' ⟶ j'') (w : F.map f x = F.map f' x') : colimit.ι F j x = colimit.ι F j' x' := by rw [← colimit.w _ f, ← colimit.w _ f'] rw [types_comp_apply, types_comp_apply, w] variable {F} in theorem colimit_eq {j j' : J} {x : F.obj j} {x' : F.obj j'} (w : colimit.ι F j x = colimit.ι F j' x') : EqvGen (Quot.Rel F) ⟨j, x⟩ ⟨j', x'⟩ := by apply Quot.eq.1 simpa using congr_arg (colimitEquivQuot F) w theorem jointly_surjective_of_isColimit {F : J ⥤ Type u} {t : Cocone F} (h : IsColimit t) (x : t.pt) : ∃ j y, t.ι.app j y = x := by by_contra hx simp_rw [not_exists] at hx apply (_ : (fun _ ↦ ULift.up True) ≠ (⟨· ≠ x⟩)) · refine h.hom_ext fun j ↦ ?_ ext y exact (true_iff _).mpr (hx j y) · exact fun he ↦ of_eq_true (congr_arg ULift.down <| congr_fun he x).symm rfl theorem jointly_surjective (F : J ⥤ Type u) {t : Cocone F} (h : IsColimit t) (x : t.pt) : ∃ j y, t.ι.app j y = x := jointly_surjective_of_isColimit h x variable {F} in /-- A variant of `jointly_surjective` for `x : colimit F`. -/ theorem jointly_surjective' (x : colimit F) : ∃ j y, colimit.ι F j y = x := jointly_surjective F (colimit.isColimit F) x /-- If a colimit is nonempty, also its index category is nonempty. -/ theorem nonempty_of_nonempty_colimit {F : J ⥤ Type u} [HasColimit F] : Nonempty (colimit F) → Nonempty J := Nonempty.map <| Sigma.fst ∘ Quot.out ∘ (colimitEquivQuot F).toFun variable {α β : Type u} (f : α ⟶ β) section -- implementation of `HasImage` /-- the image of a morphism in Type is just `Set.range f` -/ def Image : Type u := Set.range f instance [Inhabited α] : Inhabited (Image f) where default := ⟨f default, ⟨_, rfl⟩⟩ /-- the inclusion of `Image f` into the target -/ def Image.ι : Image f ⟶ β := Subtype.val instance : Mono (Image.ι f) := (mono_iff_injective _).2 Subtype.val_injective variable {f} /-- the universal property for the image factorisation -/ noncomputable def Image.lift (F' : MonoFactorisation f) : Image f ⟶ F'.I := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : Image f → F'.I) theorem Image.lift_fac (F' : MonoFactorisation f) : Image.lift F' ≫ F'.m = Image.ι f := by funext x change (F'.e ≫ F'.m) _ = _ rw [F'.fac, (Classical.indefiniteDescription _ x.2).2] rfl end /-- the factorisation of any morphism in Type through a mono. -/ def monoFactorisation : MonoFactorisation f where I := Image f m := Image.ι f e := Set.rangeFactorization f /-- the factorisation through a mono has the universal property of the image. -/ noncomputable def isImage : IsImage (monoFactorisation f) where lift := Image.lift lift_fac := Image.lift_fac instance : HasImage f := HasImage.mk ⟨_, isImage f⟩ instance : HasImages (Type u) where has_image := by infer_instance instance : HasImageMaps (Type u) where has_image_map {f g} st := HasImageMap.transport st (monoFactorisation f.hom) (isImage g.hom) (fun x => ⟨st.right x.1, ⟨st.left (Classical.choose x.2), by have p := st.w replace p := congr_fun p (Classical.choose x.2) simp only [Functor.id_obj, Functor.id_map, types_comp_apply] at p erw [p, Classical.choose_spec x.2]⟩⟩) rfl variable {F : ℕᵒᵖ ⥤ Type u} {c : Cone F} (hc : IsLimit c) (hF : ∀ n, Function.Surjective (F.map (homOfLE (Nat.le_succ n)).op)) private noncomputable def limitOfSurjectionsSurjective.preimage (a : F.obj ⟨0⟩) : (n : ℕ) → F.obj ⟨n⟩ | 0 => a | n+1 => (hF n (preimage a n)).choose open limitOfSurjectionsSurjective in /-- Auxiliary lemma. Use `limit_of_surjections_surjective` instead. -/ lemma surjective_π_app_zero_of_surjective_map_aux : Function.Surjective ((limitCone F).π.app ⟨0⟩) := by intro a refine ⟨⟨fun ⟨n⟩ ↦ preimage hF a n, ?_⟩, rfl⟩ intro ⟨n⟩ ⟨m⟩ ⟨⟨⟨(h : m ≤ n)⟩⟩⟩ induction h with | refl => erw [CategoryTheory.Functor.map_id, types_id_apply] | @step p h ih => rw [← ih] have h' : m ≤ p := h erw [CategoryTheory.Functor.map_comp (f := (homOfLE (Nat.le_succ p)).op) (g := (homOfLE h').op), types_comp_apply, (hF p _).choose_spec] rfl /-- Given surjections `⋯ ⟶ Xₙ₊₁ ⟶ Xₙ ⟶ ⋯ ⟶ X₀`, the projection map `lim Xₙ ⟶ X₀` is surjective. -/ lemma surjective_π_app_zero_of_surjective_map (hc : IsLimit c) (hF : ∀ n, Function.Surjective (F.map (homOfLE (Nat.le_succ n)).op)) : Function.Surjective (c.π.app ⟨0⟩) := by let i := hc.conePointUniqueUpToIso (limitConeIsLimit F) have : c.π.app ⟨0⟩ = i.hom ≫ (limitCone F).π.app ⟨0⟩ := by simp [i] rw [this] apply Function.Surjective.comp · exact surjective_π_app_zero_of_surjective_map_aux hF · rw [← epi_iff_surjective] infer_instance end Types open Functor Opposite section variable {J C : Type*} [Category J] [Category C] /-- Sections of `F ⋙ coyoneda.obj (op X)` identify to natural transformations `(const J).obj X ⟶ F`. -/ @[simps] def compCoyonedaSectionsEquiv (F : J ⥤ C) (X : C) : (F ⋙ coyoneda.obj (op X)).sections ≃ ((const J).obj X ⟶ F) where toFun s := { app := fun j => s.val j naturality := fun j j' f => by dsimp rw [Category.id_comp] exact (s.property f).symm } invFun τ := ⟨τ.app, fun {j j'} f => by simpa using (τ.naturality f).symm⟩ left_inv _ := rfl right_inv _ := rfl /-- Sections of `F.op ⋙ yoneda.obj X` identify to natural transformations `F ⟶ (const J).obj X`. -/ @[simps] def opCompYonedaSectionsEquiv (F : J ⥤ C) (X : C) : (F.op ⋙ yoneda.obj X).sections ≃ (F ⟶ (const J).obj X) where toFun s := { app := fun j => s.val (op j) naturality := fun j j' f => by dsimp rw [Category.comp_id] exact (s.property f.op) } invFun τ := ⟨fun j => τ.app j.unop, fun {j j'} f => by simp [τ.naturality f.unop]⟩ left_inv _ := rfl right_inv _ := rfl /-- Sections of `F ⋙ yoneda.obj X` identify to natural transformations `(const J).obj X ⟶ F`. -/ @[simps] def compYonedaSectionsEquiv (F : J ⥤ Cᵒᵖ) (X : C) : (F ⋙ yoneda.obj X).sections ≃ ((const J).obj (op X) ⟶ F) where toFun s := { app := fun j => (s.val j).op naturality := fun j j' f => by dsimp rw [Category.id_comp] exact Quiver.Hom.unop_inj (s.property f).symm } invFun τ := ⟨fun j => (τ.app j).unop, fun {j j'} f => Quiver.Hom.op_inj (by simpa using (τ.naturality f).symm)⟩ left_inv _ := rfl right_inv _ := rfl end variable {J : Type v} [SmallCategory J] {C : Type u} [Category.{v} C] /-- A cone on `F` with cone point `X` is the same as an element of `lim Hom(X, F·)`. -/ @[simps!] noncomputable def limitCompCoyonedaIsoCone (F : J ⥤ C) (X : C) : limit (F ⋙ coyoneda.obj (op X)) ≅ ((const J).obj X ⟶ F) := ((Types.limitEquivSections _).trans (compCoyonedaSectionsEquiv F X)).toIso /-- A cone on `F` with cone point `X` is the same as an element of `lim Hom(X, F·)`, naturally in `X`. -/ @[simps!] noncomputable def coyonedaCompLimIsoCones (F : J ⥤ C) : coyoneda ⋙ (whiskeringLeft _ _ _).obj F ⋙ lim ≅ F.cones := NatIso.ofComponents (fun X => limitCompCoyonedaIsoCone F X.unop) variable (J) (C) in /-- A cone on `F` with cone point `X` is the same as an element of `lim Hom(X, F·)`, naturally in `F` and `X`. -/ @[simps!] noncomputable def whiskeringLimYonedaIsoCones : whiskeringLeft _ _ _ ⋙ (whiskeringRight _ _ _).obj lim ⋙ (whiskeringLeft _ _ _).obj coyoneda ≅ cones J C := NatIso.ofComponents coyonedaCompLimIsoCones /-- A cocone on `F` with cocone point `X` is the same as an element of `lim Hom(F·, X)`. -/ @[simps!] noncomputable def limitCompYonedaIsoCocone (F : J ⥤ C) (X : C) : limit (F.op ⋙ yoneda.obj X) ≅ (F ⟶ (const J).obj X) := ((Types.limitEquivSections _).trans (opCompYonedaSectionsEquiv F X)).toIso /-- A cocone on `F` with cocone point `X` is the same as an element of `lim Hom(F·, X)`, naturally in `X`. -/ @[simps!] noncomputable def yonedaCompLimIsoCocones (F : J ⥤ C) : yoneda ⋙ (whiskeringLeft _ _ _).obj F.op ⋙ lim ≅ F.cocones := NatIso.ofComponents (limitCompYonedaIsoCocone F) variable (J) (C) in /-- A cocone on `F` with cocone point `X` is the same as an element of `lim Hom(F·, X)`, naturally in `F` and `X`. -/ @[simps!] noncomputable def opHomCompWhiskeringLimYonedaIsoCocones : opHom _ _ ⋙ whiskeringLeft _ _ _ ⋙ (whiskeringRight _ _ _).obj lim ⋙ (whiskeringLeft _ _ _).obj yoneda ≅ cocones J C := NatIso.ofComponents (fun F => yonedaCompLimIsoCocones F.unop) end CategoryTheory.Limits
CategoryTheory\Limits\TypesFiltered.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Reid Barton -/ import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Filtered.Basic /-! # Filtered colimits in the category of types. We give a characterisation of the equality in filtered colimits in `Type` as a lemma `CategoryTheory.Limits.Types.FilteredColimit.colimit_eq_iff`: `colimit.ι F i xi = colimit.ι F j xj ↔ ∃ k (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj`. -/ open CategoryTheory CategoryTheory.Limits universe v u w namespace CategoryTheory.Limits.Types.FilteredColimit variable {J : Type v} [Category.{w} J] (F : J ⥤ Type u) attribute [local instance] small_quot_of_hasColimit /- For filtered colimits of types, we can give an explicit description of the equivalence relation generated by the relation used to form the colimit. -/ /-- An alternative relation on `Σ j, F.obj j`, which generates the same equivalence relation as we use to define the colimit in `Type` above, but that is more convenient when working with filtered colimits. Elements in `F.obj j` and `F.obj j'` are equivalent if there is some `k : J` to the right where their images are equal. -/ protected def Rel (x y : Σ j, F.obj j) : Prop := ∃ (k : _) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2 theorem rel_of_quot_rel (x y : Σ j, F.obj j) : Quot.Rel F x y → FilteredColimit.Rel.{v, u} F x y := fun ⟨f, h⟩ => ⟨y.1, f, 𝟙 y.1, by rw [← h, FunctorToTypes.map_id_apply]⟩ theorem eqvGen_quot_rel_of_rel (x y : Σ j, F.obj j) : FilteredColimit.Rel.{v, u} F x y → EqvGen (Quot.Rel F) x y := fun ⟨k, f, g, h⟩ => by refine EqvGen.trans _ ⟨k, F.map f x.2⟩ _ ?_ ?_ · exact (EqvGen.rel _ _ ⟨f, rfl⟩) · exact (EqvGen.symm _ _ (EqvGen.rel _ _ ⟨g, h⟩)) /-- Recognizing filtered colimits of types. -/ noncomputable def isColimitOf (t : Cocone F) (hsurj : ∀ x : t.pt, ∃ i xi, x = t.ι.app i xi) (hinj : ∀ i j xi xj, t.ι.app i xi = t.ι.app j xj → ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj) : IsColimit t := by let α : t.pt → J := fun x => (hsurj x).choose let f : ∀ (x : t.pt), F.obj (α x) := fun x => (hsurj x).choose_spec.choose have hf : ∀ (x : t.pt), x = t.ι.app _ (f x) := fun x => (hsurj x).choose_spec.choose_spec exact { desc := fun s x => s.ι.app _ (f x) fac := fun s j => by ext y obtain ⟨k, l, g, eq⟩ := hinj _ _ _ _ (hf (t.ι.app j y)) have h := congr_fun (s.ι.naturality g) (f (t.ι.app j y)) have h' := congr_fun (s.ι.naturality l) y dsimp at h h' ⊢ rw [← h, ← eq, h'] uniq := fun s m hm => by ext x dsimp nth_rw 1 [hf x] rw [← hm, types_comp_apply] } variable [IsFilteredOrEmpty J] protected theorem rel_equiv : _root_.Equivalence (FilteredColimit.Rel.{v, u} F) where refl x := ⟨x.1, 𝟙 x.1, 𝟙 x.1, rfl⟩ symm := fun ⟨k, f, g, h⟩ => ⟨k, g, f, h.symm⟩ trans {x y z} := fun ⟨k, f, g, h⟩ ⟨k', f', g', h'⟩ => let ⟨l, fl, gl, _⟩ := IsFilteredOrEmpty.cocone_objs k k' let ⟨m, n, hn⟩ := IsFilteredOrEmpty.cocone_maps (g ≫ fl) (f' ≫ gl) ⟨m, f ≫ fl ≫ n, g' ≫ gl ≫ n, calc F.map (f ≫ fl ≫ n) x.2 = F.map (fl ≫ n) (F.map f x.2) := by simp _ = F.map (fl ≫ n) (F.map g y.2) := by rw [h] _ = F.map ((g ≫ fl) ≫ n) y.2 := by simp _ = F.map ((f' ≫ gl) ≫ n) y.2 := by rw [hn] _ = F.map (gl ≫ n) (F.map f' y.2) := by simp _ = F.map (gl ≫ n) (F.map g' z.2) := by rw [h'] _ = F.map (g' ≫ gl ≫ n) z.2 := by simp⟩ protected theorem rel_eq_eqvGen_quot_rel : FilteredColimit.Rel.{v, u} F = EqvGen (Quot.Rel F) := by ext ⟨j, x⟩ ⟨j', y⟩ constructor · apply eqvGen_quot_rel_of_rel · rw [← (FilteredColimit.rel_equiv F).eqvGen_iff] exact EqvGen.mono (rel_of_quot_rel F) variable [HasColimit F] theorem colimit_eq_iff_aux {i j : J} {xi : F.obj i} {xj : F.obj j} : (colimitCocone F).ι.app i xi = (colimitCocone F).ι.app j xj ↔ FilteredColimit.Rel.{v, u} F ⟨i, xi⟩ ⟨j, xj⟩ := by dsimp rw [← (equivShrink _).symm.injective.eq_iff, Equiv.symm_apply_apply, Equiv.symm_apply_apply, Quot.eq, FilteredColimit.rel_eq_eqvGen_quot_rel] theorem isColimit_eq_iff {t : Cocone F} (ht : IsColimit t) {i j : J} {xi : F.obj i} {xj : F.obj j} : t.ι.app i xi = t.ι.app j xj ↔ ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj := by refine Iff.trans ?_ (colimit_eq_iff_aux F) rw [← (IsColimit.coconePointUniqueUpToIso ht (colimitCoconeIsColimit F)).toEquiv.injective.eq_iff] convert Iff.rfl · exact (congrFun (IsColimit.comp_coconePointUniqueUpToIso_hom ht (colimitCoconeIsColimit F) _) xi).symm · exact (congrFun (IsColimit.comp_coconePointUniqueUpToIso_hom ht (colimitCoconeIsColimit F) _) xj).symm theorem colimit_eq_iff {i j : J} {xi : F.obj i} {xj : F.obj j} : colimit.ι F i xi = colimit.ι F j xj ↔ ∃ (k : _) (f : i ⟶ k) (g : j ⟶ k), F.map f xi = F.map g xj := isColimit_eq_iff _ (colimit.isColimit F) end CategoryTheory.Limits.Types.FilteredColimit
CategoryTheory\Limits\Unit.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.PUnit import Mathlib.CategoryTheory.Limits.HasLimits /-! # `Discrete PUnit` has limits and colimits Mostly for the sake of constructing trivial examples, we show all (co)cones into `Discrete PUnit` are (co)limit (co)cones. We also show that such (co)cones exist, and that `Discrete PUnit` has all (co)limits. -/ universe v' v open CategoryTheory namespace CategoryTheory.Limits variable {J : Type v} [Category.{v'} J] {F : J ⥤ Discrete PUnit} /-- A trivial cone for a functor into `PUnit`. `punitConeIsLimit` shows it is a limit. -/ def punitCone : Cone F := ⟨⟨⟨⟩⟩, (Functor.punitExt _ _).hom⟩ /-- A trivial cocone for a functor into `PUnit`. `punitCoconeIsLimit` shows it is a colimit. -/ def punitCocone : Cocone F := ⟨⟨⟨⟩⟩, (Functor.punitExt _ _).hom⟩ /-- Any cone over a functor into `PUnit` is a limit cone. -/ def punitConeIsLimit {c : Cone F} : IsLimit c where lift := fun s => eqToHom (by simp [eq_iff_true_of_subsingleton]) /-- Any cocone over a functor into `PUnit` is a colimit cocone. -/ def punitCoconeIsColimit {c : Cocone F} : IsColimit c where desc := fun s => eqToHom (by simp [eq_iff_true_of_subsingleton]) instance : HasLimitsOfSize.{v', v} (Discrete PUnit) := ⟨fun _ _ => ⟨fun _ => ⟨punitCone, punitConeIsLimit⟩⟩⟩ instance : HasColimitsOfSize.{v', v} (Discrete PUnit) := ⟨fun _ _ => ⟨fun _ => ⟨punitCocone, punitCoconeIsColimit⟩⟩⟩ end CategoryTheory.Limits
CategoryTheory\Limits\VanKampen.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts /-! # Universal colimits and van Kampen colimits ## Main definitions - `CategoryTheory.IsUniversalColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. - `CategoryTheory.IsVanKampenColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. ## References - https://ncatlab.org/nlab/show/van+Kampen+colimit - [Stephen Lack and Paweł Sobociński, Adhesive Categories][adhesive2004] -/ open CategoryTheory.Limits namespace CategoryTheory universe v' u' v u variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C] variable {K : Type*} [Category K] {D : Type*} [Category D] section NatTrans /-- A natural transformation is equifibered if every commutative square of the following form is a pullback. ``` F(X) → F(Y) ↓ ↓ G(X) → G(Y) ``` -/ def NatTrans.Equifibered {F G : J ⥤ C} (α : F ⟶ G) : Prop := ∀ ⦃i j : J⦄ (f : i ⟶ j), IsPullback (F.map f) (α.app i) (α.app j) (G.map f) theorem NatTrans.equifibered_of_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] : Equifibered α := fun _ _ f => IsPullback.of_vert_isIso ⟨NatTrans.naturality _ f⟩ theorem NatTrans.Equifibered.comp {F G H : J ⥤ C} {α : F ⟶ G} {β : G ⟶ H} (hα : Equifibered α) (hβ : Equifibered β) : Equifibered (α ≫ β) := fun _ _ f => (hα f).paste_vert (hβ f) theorem NatTrans.Equifibered.whiskerRight {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : C ⥤ D) [∀ (i j : J) (f : j ⟶ i), PreservesLimit (cospan (α.app i) (G.map f)) H] : Equifibered (whiskerRight α H) := fun _ _ f => (hα f).map H theorem NatTrans.Equifibered.whiskerLeft {K : Type*} [Category K] {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : K ⥤ J) : Equifibered (whiskerLeft H α) := fun _ _ f => hα (H.map f) theorem mapPair_equifibered {F F' : Discrete WalkingPair ⥤ C} (α : F ⟶ F') : NatTrans.Equifibered α := by rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ all_goals dsimp; simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by simp only [Category.comp_id, Category.id_comp]⟩ theorem NatTrans.equifibered_of_discrete {ι : Type*} {F G : Discrete ι ⥤ C} (α : F ⟶ G) : NatTrans.Equifibered α := by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by rw [Category.id_comp, Category.comp_id]⟩ end NatTrans /-- A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. -/ def IsUniversalColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), (∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j)) → Nonempty (IsColimit c') /-- A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. TODO: Show that this is iff the functor `C ⥤ Catᵒᵖ` sending `x` to `C/x` preserves it. TODO: Show that this is iff the inclusion functor `C ⥤ Span(C)` preserves it. -/ def IsVanKampenColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), Nonempty (IsColimit c') ↔ ∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j) theorem IsVanKampenColimit.isUniversal {F : J ⥤ C} {c : Cocone F} (H : IsVanKampenColimit c) : IsUniversalColimit c := fun _ c' α f h hα => (H c' α f h hα).mpr /-- A universal colimit is a colimit. -/ noncomputable def IsUniversalColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsUniversalColimit c) : IsColimit c := by refine ((h c (𝟙 F) (𝟙 c.pt : _) (by rw [Functor.map_id, Category.comp_id, Category.id_comp]) (NatTrans.equifibered_of_isIso _)) fun j => ?_).some haveI : IsIso (𝟙 c.pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by erw [NatTrans.id_app, Category.comp_id, Category.id_comp]⟩ /-- A van Kampen colimit is a colimit. -/ noncomputable def IsVanKampenColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsVanKampenColimit c) : IsColimit c := h.isUniversal.isColimit theorem IsInitial.isVanKampenColimit [HasStrictInitialObjects C] {X : C} (h : IsInitial X) : IsVanKampenColimit (asEmptyCocone X) := by intro F' c' α f hf hα have : F' = Functor.empty C := by apply Functor.hext <;> rintro ⟨⟨⟩⟩ subst this haveI := h.isIso_to f refine ⟨by rintro _ ⟨⟨⟩⟩, fun _ => ⟨IsColimit.ofIsoColimit h (Cocones.ext (asIso f).symm <| by rintro ⟨⟨⟩⟩)⟩⟩ section Functor theorem IsUniversalColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (hc : IsUniversalColimit c) (e : c ≅ c') : IsUniversalColimit c' := by intro F' c'' α f h hα H have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j apply hc c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα intro j rw [← Category.comp_id (α.app j)] have : IsIso e.inv.hom := Functor.map_isIso (Cocones.forget _) e.inv exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨by simp⟩) theorem IsVanKampenColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (H : IsVanKampenColimit c) (e : c ≅ c') : IsVanKampenColimit c' := by intro F' c'' α f h hα have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j rw [H c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα] apply forall_congr' intro j conv_lhs => rw [← Category.comp_id (α.app j)] haveI : IsIso e.inv.hom := Functor.map_isIso (Cocones.forget _) e.inv exact (IsPullback.of_vert_isIso ⟨by simp⟩).paste_vert_iff (NatTrans.congr_app h j).symm theorem IsVanKampenColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsVanKampenColimit c) : IsVanKampenColimit ((Cocones.precompose α).obj c) := by intros F' c' α' f e hα refine (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))).trans ?_ apply forall_congr' intro j simp only [Functor.const_obj_obj, NatTrans.comp_app, Cocones.precompose_obj_pt, Cocones.precompose_obj_ι] have : IsPullback (α.app j ≫ c.ι.app j) (α.app j) (𝟙 _) (c.ι.app j) := IsPullback.of_vert_isIso ⟨Category.comp_id _⟩ rw [← IsPullback.paste_vert_iff this _, Category.comp_id] exact (congr_app e j).symm theorem IsUniversalColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsUniversalColimit c) : IsUniversalColimit ((Cocones.precompose α).obj c) := by intros F' c' α' f e hα H apply (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))) intro j simp only [Functor.const_obj_obj, NatTrans.comp_app, Cocones.precompose_obj_pt, Cocones.precompose_obj_ι] rw [← Category.comp_id f] exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨Category.comp_id _⟩) theorem IsVanKampenColimit.precompose_isIso_iff {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} : IsVanKampenColimit ((Cocones.precompose α).obj c) ↔ IsVanKampenColimit c := ⟨fun hc ↦ IsVanKampenColimit.of_iso (IsVanKampenColimit.precompose_isIso (inv α) hc) (Cocones.ext (Iso.refl _) (by simp)), IsVanKampenColimit.precompose_isIso α⟩ theorem IsUniversalColimit.of_mapCocone (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [PreservesLimitsOfShape WalkingCospan G] [ReflectsColimitsOfShape J G] (hc : IsUniversalColimit (G.mapCocone c)) : IsUniversalColimit c := fun F' c' α f h hα H ↦ ⟨ReflectsColimit.reflects (hc (G.mapCocone c') (whiskerRight α G) (G.map f) (by ext j; simpa using G.congr_map (NatTrans.congr_app h j)) (hα.whiskerRight G) (fun j ↦ (H j).map G)).some⟩ theorem IsVanKampenColimit.of_mapCocone (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [∀ (i j : J) (X : C) (f : X ⟶ F.obj j) (g : i ⟶ j), PreservesLimit (cospan f (F.map g)) G] [∀ (i : J) (X : C) (f : X ⟶ c.pt), PreservesLimit (cospan f (c.ι.app i)) G] [ReflectsLimitsOfShape WalkingCospan G] [PreservesColimitsOfShape J G] [ReflectsColimitsOfShape J G] (H : IsVanKampenColimit (G.mapCocone c)) : IsVanKampenColimit c := by intro F' c' α f h hα refine (Iff.trans ?_ (H (G.mapCocone c') (whiskerRight α G) (G.map f) (by ext j; simpa using G.congr_map (NatTrans.congr_app h j)) (hα.whiskerRight G))).trans (forall_congr' fun j => ?_) · exact ⟨fun h => ⟨isColimitOfPreserves G h.some⟩, fun h => ⟨isColimitOfReflects G h.some⟩⟩ · exact IsPullback.map_iff G (NatTrans.congr_app h.symm j) theorem IsVanKampenColimit.mapCocone_iff (G : C ⥤ D) {F : J ⥤ C} {c : Cocone F} [G.IsEquivalence] : IsVanKampenColimit (G.mapCocone c) ↔ IsVanKampenColimit c := ⟨IsVanKampenColimit.of_mapCocone G, fun hc ↦ by let e : F ⋙ G ⋙ Functor.inv G ≅ F := NatIso.hcomp (Iso.refl F) G.asEquivalence.unitIso.symm apply IsVanKampenColimit.of_mapCocone G.inv apply (IsVanKampenColimit.precompose_isIso_iff e.inv).mp exact hc.of_iso (Cocones.ext (G.asEquivalence.unitIso.app c.pt) (fun j => (by simp [e])))⟩ theorem IsUniversalColimit.whiskerEquivalence {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} (hc : IsUniversalColimit c) : IsUniversalColimit (c.whisker e.functor) := by intro F' c' α f e' hα H convert hc (c'.whisker e.inverse) (whiskerLeft e.inverse α ≫ (e.invFunIdAssoc F).hom) f ?_ ((hα.whiskerLeft _).comp (NatTrans.equifibered_of_isIso _)) ?_ using 1 · exact (IsColimit.whiskerEquivalenceEquiv e.symm).nonempty_congr · convert congr_arg (whiskerLeft e.inverse) e' ext simp · intro k rw [← Category.comp_id f] refine (H (e.inverse.obj k)).paste_vert ?_ have : IsIso (𝟙 (Cocone.whisker e.functor c).pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by simp⟩ theorem IsUniversalColimit.whiskerEquivalence_iff {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} : IsUniversalColimit (c.whisker e.functor) ↔ IsUniversalColimit c := ⟨fun hc ↦ ((hc.whiskerEquivalence e.symm).precompose_isIso (e.invFunIdAssoc F).inv).of_iso (Cocones.ext (Iso.refl _) (by simp)), IsUniversalColimit.whiskerEquivalence e⟩ theorem IsVanKampenColimit.whiskerEquivalence {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) : IsVanKampenColimit (c.whisker e.functor) := by intro F' c' α f e' hα convert hc (c'.whisker e.inverse) (whiskerLeft e.inverse α ≫ (e.invFunIdAssoc F).hom) f ?_ ((hα.whiskerLeft _).comp (NatTrans.equifibered_of_isIso _)) using 1 · exact (IsColimit.whiskerEquivalenceEquiv e.symm).nonempty_congr · simp only [Functor.const_obj_obj, Functor.comp_obj, Cocone.whisker_pt, Cocone.whisker_ι, whiskerLeft_app, NatTrans.comp_app, Equivalence.invFunIdAssoc_hom_app, Functor.id_obj] constructor · intro H k rw [← Category.comp_id f] refine (H (e.inverse.obj k)).paste_vert ?_ have : IsIso (𝟙 (Cocone.whisker e.functor c).pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by simp⟩ · intro H j have : α.app j = F'.map (e.unit.app _) ≫ α.app _ ≫ F.map (e.counit.app (e.functor.obj j)) := by simp [← Functor.map_comp] rw [← Category.id_comp f, this] refine IsPullback.paste_vert ?_ (H (e.functor.obj j)) exact IsPullback.of_vert_isIso ⟨by simp⟩ · ext k simpa using congr_app e' (e.inverse.obj k) theorem IsVanKampenColimit.whiskerEquivalence_iff {K : Type*} [Category K] (e : J ≌ K) {F : K ⥤ C} {c : Cocone F} : IsVanKampenColimit (c.whisker e.functor) ↔ IsVanKampenColimit c := ⟨fun hc ↦ ((hc.whiskerEquivalence e.symm).precompose_isIso (e.invFunIdAssoc F).inv).of_iso (Cocones.ext (Iso.refl _) (by simp)), IsVanKampenColimit.whiskerEquivalence e⟩ theorem isVanKampenColimit_of_evaluation [HasPullbacks D] [HasColimitsOfShape J D] (F : J ⥤ C ⥤ D) (c : Cocone F) (hc : ∀ x : C, IsVanKampenColimit (((evaluation C D).obj x).mapCocone c)) : IsVanKampenColimit c := by intro F' c' α f e hα have := fun x => hc x (((evaluation C D).obj x).mapCocone c') (whiskerRight α _) (((evaluation C D).obj x).map f) (by ext y dsimp exact NatTrans.congr_app (NatTrans.congr_app e y) x) (hα.whiskerRight _) constructor · rintro ⟨hc'⟩ j refine ⟨⟨(NatTrans.congr_app e j).symm⟩, ⟨evaluationJointlyReflectsLimits _ ?_⟩⟩ refine fun x => (isLimitMapConePullbackConeEquiv _ _).symm ?_ exact ((this x).mp ⟨PreservesColimit.preserves hc'⟩ _).isLimit · exact fun H => ⟨evaluationJointlyReflectsColimits _ fun x => ((this x).mpr fun j => (H j).map ((evaluation C D).obj x)).some⟩ end Functor section reflective theorem IsUniversalColimit.map_reflective {Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful] {F : J ⥤ D} {c : Cocone (F ⋙ Gr)} (H : IsUniversalColimit c) [∀ X (f : X ⟶ Gl.obj c.pt), HasPullback (Gr.map f) (adj.unit.app c.pt)] [∀ X (f : X ⟶ Gl.obj c.pt), PreservesLimit (cospan (Gr.map f) (adj.unit.app c.pt)) Gl] : IsUniversalColimit (Gl.mapCocone c) := by have := adj.rightAdjointPreservesLimits have : PreservesColimitsOfSize.{u', v'} Gl := adj.leftAdjointPreservesColimits intros F' c' α f h hα hc' have : HasPullback (Gl.map (Gr.map f)) (Gl.map (adj.unit.app c.pt)) := ⟨⟨_, isLimitPullbackConeMapOfIsLimit _ pullback.condition (IsPullback.of_hasPullback _ _).isLimit⟩⟩ let α' := α ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft F adj.counit ≫ F.rightUnitor.hom have hα' : NatTrans.Equifibered α' := hα.comp (NatTrans.equifibered_of_isIso _) have hadj : ∀ X, Gl.map (adj.unit.app X) = inv (adj.counit.app _) := by intro X apply IsIso.eq_inv_of_inv_hom_id exact adj.left_triangle_components _ haveI : ∀ X, IsIso (Gl.map (adj.unit.app X)) := by simp_rw [hadj] infer_instance have hα'' : ∀ j, Gl.map (Gr.map <| α'.app j) = adj.counit.app _ ≫ α.app j := by intro j rw [← cancel_mono (adj.counit.app <| F.obj j)] dsimp [α'] simp only [Category.comp_id, Adjunction.counit_naturality_assoc, Category.id_comp, Adjunction.counit_naturality, Category.assoc, Functor.map_comp] have hc'' : ∀ j, α.app j ≫ Gl.map (c.ι.app j) = c'.ι.app j ≫ f := NatTrans.congr_app h let β := isoWhiskerLeft F' (asIso adj.counit) ≪≫ F'.rightUnitor let c'' : Cocone (F' ⋙ Gr) := by refine { pt := pullback (Gr.map f) (adj.unit.app _) ι := { app := fun j ↦ pullback.lift (Gr.map <| c'.ι.app j) (Gr.map (α'.app j) ≫ c.ι.app j) ?_ naturality := ?_ } } · rw [← Gr.map_comp, ← hc''] erw [← adj.unit_naturality] rw [Gl.map_comp, hα''] dsimp simp only [Category.assoc, Functor.map_comp, adj.right_triangle_components_assoc] · intros i j g dsimp [α'] ext all_goals simp only [Category.comp_id, Category.id_comp, Category.assoc, ← Functor.map_comp, pullback.lift_fst, pullback.lift_snd, ← Functor.map_comp_assoc] · congr 1 exact c'.w _ · rw [α.naturality_assoc] dsimp rw [adj.counit_naturality, ← Category.assoc, Gr.map_comp_assoc] congr 1 exact c.w _ let cf : (Cocones.precompose β.hom).obj c' ⟶ Gl.mapCocone c'' := by refine { hom := pullback.lift ?_ f ?_ ≫ (PreservesPullback.iso _ _ _).inv, w := ?_ } · exact inv <| adj.counit.app c'.pt · rw [IsIso.inv_comp_eq, ← adj.counit_naturality_assoc f, ← cancel_mono (adj.counit.app <| Gl.obj c.pt), Category.assoc, Category.assoc, adj.left_triangle_components] erw [Category.comp_id] rfl · intro j rw [← Category.assoc, Iso.comp_inv_eq] ext all_goals simp only [PreservesPullback.iso_hom_fst, PreservesPullback.iso_hom_snd, pullback.lift_fst, pullback.lift_snd, Category.assoc, Functor.mapCocone_ι_app, ← Gl.map_comp] · rw [IsIso.comp_inv_eq, adj.counit_naturality] dsimp [β] rw [Category.comp_id] · rw [Gl.map_comp, hα'', Category.assoc, hc''] dsimp [β] rw [Category.comp_id, Category.assoc] have : cf.hom ≫ (PreservesPullback.iso _ _ _).hom ≫ pullback.fst _ _ ≫ adj.counit.app _ = 𝟙 _ := by simp only [IsIso.inv_hom_id, Iso.inv_hom_id_assoc, Category.assoc, pullback.lift_fst_assoc] have : IsIso cf := by apply @Cocones.cocone_iso_of_hom_iso (i := ?_) rw [← IsIso.eq_comp_inv] at this rw [this] infer_instance have ⟨Hc''⟩ := H c'' (whiskerRight α' Gr) (pullback.snd _ _) ?_ (hα'.whiskerRight Gr) ?_ · exact ⟨IsColimit.precomposeHomEquiv β c' <| (isColimitOfPreserves Gl Hc'').ofIsoColimit (asIso cf).symm⟩ · ext j dsimp simp only [Category.comp_id, Category.id_comp, Category.assoc, Functor.map_comp, pullback.lift_snd] · intro j apply IsPullback.of_right _ _ (IsPullback.of_hasPullback _ _) · dsimp [α'] simp only [Category.comp_id, Category.id_comp, Category.assoc, Functor.map_comp, pullback.lift_fst] rw [← Category.comp_id (Gr.map f)] refine ((hc' j).map Gr).paste_vert (IsPullback.of_vert_isIso ⟨?_⟩) rw [← adj.unit_naturality, Category.comp_id, ← Category.assoc, ← Category.id_comp (Gr.map ((Gl.mapCocone c).ι.app j))] congr 1 rw [← cancel_mono (Gr.map (adj.counit.app (F.obj j)))] dsimp simp only [Category.comp_id, Adjunction.right_triangle_components, Category.id_comp, Category.assoc] · dsimp simp only [Category.comp_id, Category.id_comp, Category.assoc, Functor.map_comp, pullback.lift_snd] theorem IsVanKampenColimit.map_reflective [HasColimitsOfShape J C] {Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful] {F : J ⥤ D} {c : Cocone (F ⋙ Gr)} (H : IsVanKampenColimit c) [∀ X (f : X ⟶ Gl.obj c.pt), HasPullback (Gr.map f) (adj.unit.app c.pt)] [∀ X (f : X ⟶ Gl.obj c.pt), PreservesLimit (cospan (Gr.map f) (adj.unit.app c.pt)) Gl] [∀ X i (f : X ⟶ c.pt), PreservesLimit (cospan f (c.ι.app i)) Gl] : IsVanKampenColimit (Gl.mapCocone c) := by have := adj.rightAdjointPreservesLimits have : PreservesColimitsOfSize.{u', v'} Gl := adj.leftAdjointPreservesColimits intro F' c' α f h hα refine ⟨?_, H.isUniversal.map_reflective adj c' α f h hα⟩ intro ⟨hc'⟩ j let α' := α ≫ (Functor.associator _ _ _).hom ≫ whiskerLeft F adj.counit ≫ F.rightUnitor.hom have hα' : NatTrans.Equifibered α' := hα.comp (NatTrans.equifibered_of_isIso _) have hα'' : ∀ j, Gl.map (Gr.map <| α'.app j) = adj.counit.app _ ≫ α.app j := by intro j rw [← cancel_mono (adj.counit.app <| F.obj j)] dsimp [α'] simp only [Category.comp_id, Adjunction.counit_naturality_assoc, Category.id_comp, Adjunction.counit_naturality, Category.assoc, Functor.map_comp] let β := isoWhiskerLeft F' (asIso adj.counit) ≪≫ F'.rightUnitor let hl := (IsColimit.precomposeHomEquiv β c').symm hc' let hr := isColimitOfPreserves Gl (colimit.isColimit <| F' ⋙ Gr) have : α.app j = β.inv.app _ ≫ Gl.map (Gr.map <| α'.app j) := by rw [hα''] simp [β] rw [this] have : f = (hl.coconePointUniqueUpToIso hr).hom ≫ Gl.map (colimit.desc _ ⟨_, whiskerRight α' Gr ≫ c.2⟩) := by symm convert @IsColimit.coconePointUniqueUpToIso_hom_desc _ _ _ _ ((F' ⋙ Gr) ⋙ Gl) (Gl.mapCocone ⟨_, (whiskerRight α' Gr ≫ c.2 : _)⟩) _ _ hl hr using 2 · apply hr.hom_ext intro j rw [hr.fac, Functor.mapCocone_ι_app, ← Gl.map_comp, colimit.cocone_ι, colimit.ι_desc] rfl · clear_value α' apply hl.hom_ext intro j rw [hl.fac] dsimp [β] simp only [Category.comp_id, hα'', Category.assoc, Gl.map_comp] congr 1 exact (NatTrans.congr_app h j).symm rw [this] have := ((H (colimit.cocone <| F' ⋙ Gr) (whiskerRight α' Gr) (colimit.desc _ ⟨_, whiskerRight α' Gr ≫ c.2⟩) ?_ (hα'.whiskerRight Gr)).mp ⟨(getColimitCocone <| F' ⋙ Gr).2⟩ j).map Gl · convert IsPullback.paste_vert _ this refine IsPullback.of_vert_isIso ⟨?_⟩ rw [← IsIso.inv_comp_eq, ← Category.assoc, NatIso.inv_inv_app] exact IsColimit.comp_coconePointUniqueUpToIso_hom hl hr _ · clear_value α' ext j simp end reflective section Initial theorem hasStrictInitial_of_isUniversal [HasInitial C] (H : IsUniversalColimit (BinaryCofan.mk (𝟙 (⊥_ C)) (𝟙 (⊥_ C)))) : HasStrictInitialObjects C := hasStrictInitialObjects_of_initial_is_strict (by intro A f suffices IsColimit (BinaryCofan.mk (𝟙 A) (𝟙 A)) by obtain ⟨l, h₁, h₂⟩ := Limits.BinaryCofan.IsColimit.desc' this (f ≫ initial.to A) (𝟙 A) rcases(Category.id_comp _).symm.trans h₂ with rfl exact ⟨⟨_, ((Category.id_comp _).symm.trans h₁).symm, initialIsInitial.hom_ext _ _⟩⟩ refine (H (BinaryCofan.mk (𝟙 _) (𝟙 _)) (mapPair f f) f (by ext ⟨⟨⟩⟩ <;> dsimp <;> simp) (mapPair_equifibered _) ?_).some rintro ⟨⟨⟩⟩ <;> dsimp <;> exact IsPullback.of_horiz_isIso ⟨(Category.id_comp _).trans (Category.comp_id _).symm⟩) theorem isVanKampenColimit_of_isEmpty [HasStrictInitialObjects C] [IsEmpty J] {F : J ⥤ C} (c : Cocone F) (hc : IsColimit c) : IsVanKampenColimit c := by have : IsInitial c.pt := by have := (IsColimit.precomposeInvEquiv (Functor.uniqueFromEmpty _) _).symm (hc.whiskerEquivalence (equivalenceOfIsEmpty (Discrete PEmpty.{1}) J)) exact IsColimit.ofIsoColimit this (Cocones.ext (Iso.refl c.pt) (fun {X} ↦ isEmptyElim X)) replace this := IsInitial.isVanKampenColimit this apply (IsVanKampenColimit.whiskerEquivalence_iff (equivalenceOfIsEmpty (Discrete PEmpty.{1}) J)).mp exact (this.precompose_isIso (Functor.uniqueFromEmpty ((equivalenceOfIsEmpty (Discrete PEmpty.{1}) J).functor ⋙ F)).hom).of_iso (Cocones.ext (Iso.refl _) (by simp)) end Initial section BinaryCoproduct variable {X Y : C} theorem BinaryCofan.isVanKampen_iff (c : BinaryCofan X Y) : IsVanKampenColimit c ↔ ∀ {X' Y' : C} (c' : BinaryCofan X' Y') (αX : X' ⟶ X) (αY : Y' ⟶ Y) (f : c'.pt ⟶ c.pt) (_ : αX ≫ c.inl = c'.inl ≫ f) (_ : αY ≫ c.inr = c'.inr ≫ f), Nonempty (IsColimit c') ↔ IsPullback c'.inl αX f c.inl ∧ IsPullback c'.inr αY f c.inr := by constructor · introv H hαX hαY rw [H c' (mapPair αX αY) f (by ext ⟨⟨⟩⟩ <;> dsimp <;> assumption) (mapPair_equifibered _)] constructor · intro H exact ⟨H _, H _⟩ · rintro H ⟨⟨⟩⟩ exacts [H.1, H.2] · introv H F' hα h let X' := F'.obj ⟨WalkingPair.left⟩ let Y' := F'.obj ⟨WalkingPair.right⟩ have : F' = pair X' Y' := by apply Functor.hext · rintro ⟨⟨⟩⟩ <;> rfl · rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ <;> simp clear_value X' Y' subst this change BinaryCofan X' Y' at c' rw [H c' _ _ _ (NatTrans.congr_app hα ⟨WalkingPair.left⟩) (NatTrans.congr_app hα ⟨WalkingPair.right⟩)] constructor · rintro H ⟨⟨⟩⟩ exacts [H.1, H.2] · intro H exact ⟨H _, H _⟩ theorem BinaryCofan.isVanKampen_mk {X Y : C} (c : BinaryCofan X Y) (cofans : ∀ X Y : C, BinaryCofan X Y) (colimits : ∀ X Y, IsColimit (cofans X Y)) (cones : ∀ {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z), PullbackCone f g) (limits : ∀ {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z), IsLimit (cones f g)) (h₁ : ∀ {X' Y' : C} (αX : X' ⟶ X) (αY : Y' ⟶ Y) (f : (cofans X' Y').pt ⟶ c.pt) (_ : αX ≫ c.inl = (cofans X' Y').inl ≫ f) (_ : αY ≫ c.inr = (cofans X' Y').inr ≫ f), IsPullback (cofans X' Y').inl αX f c.inl ∧ IsPullback (cofans X' Y').inr αY f c.inr) (h₂ : ∀ {Z : C} (f : Z ⟶ c.pt), IsColimit (BinaryCofan.mk (cones f c.inl).fst (cones f c.inr).fst)) : IsVanKampenColimit c := by rw [BinaryCofan.isVanKampen_iff] introv hX hY constructor · rintro ⟨h⟩ let e := h.coconePointUniqueUpToIso (colimits _ _) obtain ⟨hl, hr⟩ := h₁ αX αY (e.inv ≫ f) (by simp [e, hX]) (by simp [e, hY]) constructor · rw [← Category.id_comp αX, ← Iso.hom_inv_id_assoc e f] haveI : IsIso (𝟙 X') := inferInstance have : c'.inl ≫ e.hom = 𝟙 X' ≫ (cofans X' Y').inl := by dsimp [e] simp exact (IsPullback.of_vert_isIso ⟨this⟩).paste_vert hl · rw [← Category.id_comp αY, ← Iso.hom_inv_id_assoc e f] haveI : IsIso (𝟙 Y') := inferInstance have : c'.inr ≫ e.hom = 𝟙 Y' ≫ (cofans X' Y').inr := by dsimp [e] simp exact (IsPullback.of_vert_isIso ⟨this⟩).paste_vert hr · rintro ⟨H₁, H₂⟩ refine ⟨IsColimit.ofIsoColimit ?_ <| (isoBinaryCofanMk _).symm⟩ let e₁ : X' ≅ _ := H₁.isLimit.conePointUniqueUpToIso (limits _ _) let e₂ : Y' ≅ _ := H₂.isLimit.conePointUniqueUpToIso (limits _ _) have he₁ : c'.inl = e₁.hom ≫ (cones f c.inl).fst := by simp [e₁] have he₂ : c'.inr = e₂.hom ≫ (cones f c.inr).fst := by simp [e₂] rw [he₁, he₂] exact (BinaryCofan.mk _ _).isColimitCompRightIso e₂.hom ((BinaryCofan.mk _ _).isColimitCompLeftIso e₁.hom (h₂ f)) theorem BinaryCofan.mono_inr_of_isVanKampen [HasInitial C] {X Y : C} {c : BinaryCofan X Y} (h : IsVanKampenColimit c) : Mono c.inr := by refine PullbackCone.mono_of_isLimitMkIdId _ (IsPullback.isLimit ?_) refine (h (BinaryCofan.mk (initial.to Y) (𝟙 Y)) (mapPair (initial.to X) (𝟙 Y)) c.inr ?_ (mapPair_equifibered _)).mp ⟨?_⟩ ⟨WalkingPair.right⟩ · ext ⟨⟨⟩⟩ <;> dsimp; simp · exact ((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by dsimp infer_instance)).some theorem BinaryCofan.isPullback_initial_to_of_isVanKampen [HasInitial C] {c : BinaryCofan X Y} (h : IsVanKampenColimit c) : IsPullback (initial.to _) (initial.to _) c.inl c.inr := by refine ((h (BinaryCofan.mk (initial.to Y) (𝟙 Y)) (mapPair (initial.to X) (𝟙 Y)) c.inr ?_ (mapPair_equifibered _)).mp ⟨?_⟩ ⟨WalkingPair.left⟩).flip · ext ⟨⟨⟩⟩ <;> dsimp; simp · exact ((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by dsimp infer_instance)).some end BinaryCoproduct section FiniteCoproducts theorem isUniversalColimit_extendCofan {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n ↦ f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsUniversalColimit c₁) (t₂ : IsUniversalColimit c₂) [∀ {Z} (i : Z ⟶ c₂.pt), HasPullback c₂.inr i] : IsUniversalColimit (extendCofan c₁ c₂) := by intro F c α i e hα H let F' : Fin (n + 1) → C := F.obj ∘ Discrete.mk have : F = Discrete.functor F' := by apply Functor.hext · exact fun i ↦ rfl · rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp [F'] have t₁' := @t₁ (Discrete.functor (fun j ↦ F.obj ⟨j.succ⟩)) (Cofan.mk (pullback c₂.inr i) fun j ↦ pullback.lift (α.app _ ≫ c₁.inj _) (c.ι.app _) ?_) (Discrete.natTrans fun i ↦ α.app _) (pullback.fst _ _) ?_ (NatTrans.equifibered_of_discrete _) ?_ rotate_left · simpa only [Functor.const_obj_obj, pair_obj_right, Discrete.functor_obj, Category.assoc, extendCofan_pt, Functor.const_obj_obj, NatTrans.comp_app, extendCofan_ι_app, Fin.cases_succ, Functor.const_map_app] using congr_app e ⟨j.succ⟩ · ext j dsimp simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Cofan.inj] · intro j simp only [pair_obj_right, Functor.const_obj_obj, Discrete.functor_obj, id_eq, extendCofan_pt, eq_mpr_eq_cast, Cofan.mk_pt, Cofan.mk_ι_app, Discrete.natTrans_app] refine IsPullback.of_right ?_ ?_ (IsPullback.of_hasPullback (BinaryCofan.inr c₂) i).flip · simp only [Functor.const_obj_obj, pair_obj_right, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] exact H _ · simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Cofan.inj] obtain ⟨H₁⟩ := t₁' have t₂' := @t₂ (pair (F.obj ⟨0⟩) (pullback c₂.inr i)) (BinaryCofan.mk (c.ι.app ⟨0⟩) (pullback.snd _ _)) (mapPair (α.app _) (pullback.fst _ _)) i ?_ (mapPair_equifibered _) ?_ rotate_left · ext ⟨⟨⟩⟩ · simpa [mapPair] using congr_app e ⟨0⟩ · simpa using pullback.condition · rintro ⟨⟨⟩⟩ · simp only [pair_obj_right, Functor.const_obj_obj, pair_obj_left, BinaryCofan.mk_pt, BinaryCofan.ι_app_left, BinaryCofan.mk_inl, mapPair_left] exact H ⟨0⟩ · simp only [pair_obj_right, Functor.const_obj_obj, BinaryCofan.mk_pt, BinaryCofan.ι_app_right, BinaryCofan.mk_inr, mapPair_right] exact (IsPullback.of_hasPullback (BinaryCofan.inr c₂) i).flip obtain ⟨H₂⟩ := t₂' clear_value F' subst this refine ⟨IsColimit.ofIsoColimit (extendCofanIsColimit (fun i ↦ (Discrete.functor F').obj ⟨i⟩) H₁ H₂) <| Cocones.ext (Iso.refl _) ?_⟩ dsimp rintro ⟨j⟩ simp only [Discrete.functor_obj, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, Category.comp_id] induction' j using Fin.inductionOn · simp only [Fin.cases_zero] · simp only [Fin.cases_succ] theorem isVanKampenColimit_extendCofan {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n ↦ f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsVanKampenColimit c₁) (t₂ : IsVanKampenColimit c₂) [∀ {Z} (i : Z ⟶ c₂.pt), HasPullback c₂.inr i] [HasFiniteCoproducts C] : IsVanKampenColimit (extendCofan c₁ c₂) := by intro F c α i e hα refine ⟨?_, isUniversalColimit_extendCofan f t₁.isUniversal t₂.isUniversal c α i e hα⟩ intro ⟨Hc⟩ ⟨j⟩ have t₂' := (@t₂ (pair (F.obj ⟨0⟩) (∐ fun (j : Fin n) ↦ F.obj ⟨j.succ⟩)) (BinaryCofan.mk (P := c.pt) (c.ι.app _) (Sigma.desc fun b ↦ c.ι.app _)) (mapPair (α.app _) (Sigma.desc fun b ↦ α.app _ ≫ c₁.inj _)) i ?_ (mapPair_equifibered _)).mp ⟨?_⟩ rotate_left · ext ⟨⟨⟩⟩ · simpa only [pair_obj_left, Functor.const_obj_obj, pair_obj_right, Discrete.functor_obj, NatTrans.comp_app, mapPair_left, BinaryCofan.ι_app_left, BinaryCofan.mk_pt, BinaryCofan.mk_inl, Functor.const_map_app, extendCofan_pt, extendCofan_ι_app, Fin.cases_zero] using congr_app e ⟨0⟩ · dsimp ext j simpa only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, Category.assoc, extendCofan_pt, Functor.const_obj_obj, NatTrans.comp_app, extendCofan_ι_app, Fin.cases_succ, Functor.const_map_app] using congr_app e ⟨j.succ⟩ · let F' : Fin (n + 1) → C := F.obj ∘ Discrete.mk have : F = Discrete.functor F' := by apply Functor.hext · exact fun i ↦ rfl · rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp [F'] clear_value F' subst this apply BinaryCofan.IsColimit.mk _ (fun {T} f₁ f₂ ↦ Hc.desc (Cofan.mk T (Fin.cases f₁ (fun i ↦ Sigma.ι (fun (j : Fin n) ↦ (Discrete.functor F').obj ⟨j.succ⟩) _ ≫ f₂)))) · intro T f₁ f₂ simp only [Discrete.functor_obj, pair_obj_left, BinaryCofan.mk_pt, Functor.const_obj_obj, BinaryCofan.ι_app_left, BinaryCofan.mk_inl, IsColimit.fac, Cofan.mk_pt, Cofan.mk_ι_app, Fin.cases_zero] · intro T f₁ f₂ simp only [Discrete.functor_obj, pair_obj_right, BinaryCofan.mk_pt, Functor.const_obj_obj, BinaryCofan.ι_app_right, BinaryCofan.mk_inr] ext j simp only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, IsColimit.fac, Fin.cases_succ] · intro T f₁ f₂ f₃ m₁ m₂ simp at m₁ m₂ ⊢ refine Hc.uniq (Cofan.mk T (Fin.cases f₁ (fun i ↦ Sigma.ι (fun (j : Fin n) ↦ (Discrete.functor F').obj ⟨j.succ⟩) _ ≫ f₂))) _ ?_ intro ⟨j⟩ simp only [Discrete.functor_obj, Cofan.mk_pt, Functor.const_obj_obj, Cofan.mk_ι_app] induction' j using Fin.inductionOn with j _ · simp only [Fin.cases_zero, m₁] · simp only [← m₂, colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, Fin.cases_succ] induction' j using Fin.inductionOn with j _ · exact t₂' ⟨WalkingPair.left⟩ · have t₁' := (@t₁ (Discrete.functor (fun j ↦ F.obj ⟨j.succ⟩)) (Cofan.mk _ _) (Discrete.natTrans fun i ↦ α.app _) (Sigma.desc (fun j ↦ α.app _ ≫ c₁.inj _)) ?_ (NatTrans.equifibered_of_discrete _)).mp ⟨coproductIsCoproduct _⟩ ⟨j⟩ rotate_left · ext ⟨j⟩ dsimp erw [colimit.ι_desc] -- Why? rfl simpa [Functor.const_obj_obj, Discrete.functor_obj, extendCofan_pt, extendCofan_ι_app, Fin.cases_succ, BinaryCofan.mk_pt, colimit.cocone_x, Cofan.mk_pt, Cofan.mk_ι_app, BinaryCofan.ι_app_right, BinaryCofan.mk_inr, colimit.ι_desc, Discrete.natTrans_app] using t₁'.paste_horiz (t₂' ⟨WalkingPair.right⟩) theorem isPullback_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {X : ι → C} {c : Cofan X} (hc : IsVanKampenColimit c) (i j : ι) [DecidableEq ι] : IsPullback (P := (if j = i then X i else ⊥_ C)) (if h : j = i then eqToHom (if_pos h) else eqToHom (if_neg h) ≫ initial.to (X i)) (if h : j = i then eqToHom ((if_pos h).trans (congr_arg X h.symm)) else eqToHom (if_neg h) ≫ initial.to (X j)) (Cofan.inj c i) (Cofan.inj c j) := by refine (hc (Cofan.mk (X i) (f := fun k ↦ if k = i then X i else ⊥_ C) (fun k ↦ if h : k = i then (eqToHom <| if_pos h) else (eqToHom <| if_neg h) ≫ initial.to _)) (Discrete.natTrans (fun k ↦ if h : k.1 = i then (eqToHom <| (if_pos h).trans (congr_arg X h.symm)) else (eqToHom <| if_neg h) ≫ initial.to _)) (c.inj i) ?_ (NatTrans.equifibered_of_discrete _)).mp ⟨?_⟩ ⟨j⟩ · ext ⟨k⟩ simp only [Discrete.functor_obj, Functor.const_obj_obj, NatTrans.comp_app, Discrete.natTrans_app, Cofan.mk_pt, Cofan.mk_ι_app, Functor.const_map_app] split · subst ‹k = i›; rfl · simp · refine mkCofanColimit _ (fun t ↦ (eqToHom (if_pos rfl).symm) ≫ t.inj i) ?_ ?_ · intro t j simp only [Cofan.mk_pt, cofan_mk_inj] split · subst ‹j = i›; simp · rw [Category.assoc, ← IsIso.eq_inv_comp] exact initialIsInitial.hom_ext _ _ · intro t m hm simp [← hm i] theorem isPullback_initial_to_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) (i j : Discrete ι) (hi : i ≠ j) : IsPullback (initial.to _) (initial.to _) (c.ι.app i) (c.ι.app j) := by classical let f : ι → C := F.obj ∘ Discrete.mk have : F = Discrete.functor f := Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f]) clear_value f subst this have : ∀ i, Subsingleton (⊥_ C ⟶ (Discrete.functor f).obj i) := inferInstance convert isPullback_of_cofan_isVanKampen hc i.as j.as exact (if_neg (mt Discrete.ext hi.symm)).symm theorem mono_of_cofan_isVanKampen [HasInitial C] {ι : Type*} {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsVanKampenColimit c) (i : Discrete ι) : Mono (c.ι.app i) := by classical let f : ι → C := F.obj ∘ Discrete.mk have : F = Discrete.functor f := Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f]) clear_value f subst this refine PullbackCone.mono_of_isLimitMkIdId _ (IsPullback.isLimit ?_) nth_rw 1 [← Category.id_comp (c.ι.app i)] convert IsPullback.paste_vert _ (isPullback_of_cofan_isVanKampen hc i.as i.as) swap · exact (eqToHom (if_pos rfl).symm) · simp · exact IsPullback.of_vert_isIso ⟨by simp⟩ end FiniteCoproducts end CategoryTheory
CategoryTheory\Limits\Yoneda.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Types import Mathlib.Util.AssertExists /-! # Limit properties relating to the (co)yoneda embedding. We calculate the colimit of `Y ↦ (X ⟶ Y)`, which is just `PUnit`. (This is used in characterising cofinal functors.) We also show the (co)yoneda embeddings preserve limits and jointly reflect them. -/ open Opposite CategoryTheory Limits universe t w v u namespace CategoryTheory namespace Coyoneda variable {C : Type u} [Category.{v} C] /-- The colimit cocone over `coyoneda.obj X`, with cocone point `PUnit`. -/ @[simps] def colimitCocone (X : Cᵒᵖ) : Cocone (coyoneda.obj X) where pt := PUnit ι := { app := by aesop_cat } /-- The proposed colimit cocone over `coyoneda.obj X` is a colimit cocone. -/ @[simps] def colimitCoconeIsColimit (X : Cᵒᵖ) : IsColimit (colimitCocone X) where desc s _ := s.ι.app (unop X) (𝟙 _) fac s Y := by funext f convert congr_fun (s.w f).symm (𝟙 (unop X)) simp only [coyoneda_obj_obj, Functor.const_obj_obj, types_comp_apply, coyoneda_obj_map, Category.id_comp] uniq s m w := by apply funext; rintro ⟨⟩ dsimp rw [← w] simp instance (X : Cᵒᵖ) : HasColimit (coyoneda.obj X) := HasColimit.mk { cocone := _ isColimit := colimitCoconeIsColimit X } /-- The colimit of `coyoneda.obj X` is isomorphic to `PUnit`. -/ noncomputable def colimitCoyonedaIso (X : Cᵒᵖ) : colimit (coyoneda.obj X) ≅ PUnit := by apply colimit.isoColimitCocone { cocone := _ isColimit := colimitCoconeIsColimit X } end Coyoneda variable {C : Type u} [Category.{v} C] open Limits section variable {J : Type w} [Category.{t} J] /-- The cone of `F` corresponding to an element in `(F ⋙ yoneda.obj X).sections`. -/ @[simps] def Limits.coneOfSectionCompYoneda (F : J ⥤ Cᵒᵖ) (X : C) (s : (F ⋙ yoneda.obj X).sections) : Cone F where pt := Opposite.op X π := compYonedaSectionsEquiv F X s noncomputable instance yonedaPreservesLimit (F : J ⥤ Cᵒᵖ) (X : C) : PreservesLimit F (yoneda.obj X) where preserves {c} hc := Nonempty.some (by rw [Types.isLimit_iff] intro s hs exact ⟨(hc.lift (Limits.coneOfSectionCompYoneda F X ⟨s, hs⟩)).unop, fun j => Quiver.Hom.op_inj (hc.fac (Limits.coneOfSectionCompYoneda F X ⟨s, hs⟩) j), fun m hm => Quiver.Hom.op_inj (hc.uniq (Limits.coneOfSectionCompYoneda F X ⟨s, hs⟩) _ (fun j => Quiver.Hom.unop_inj (hm j)))⟩) variable (J) in noncomputable instance yonedaPreservesLimitsOfShape (X : C) : PreservesLimitsOfShape J (yoneda.obj X) where /-- The yoneda embeddings jointly reflect limits. -/ def yonedaJointlyReflectsLimits (F : J ⥤ Cᵒᵖ) (c : Cone F) (hc : ∀ X : C, IsLimit ((yoneda.obj X).mapCone c)) : IsLimit c where lift s := ((hc s.pt.unop).lift ((yoneda.obj s.pt.unop).mapCone s) (𝟙 _)).op fac s j := Quiver.Hom.unop_inj (by simpa using congr_fun ((hc s.pt.unop).fac ((yoneda.obj s.pt.unop).mapCone s) j) (𝟙 _)) uniq s m hm := Quiver.Hom.unop_inj (by apply (Types.isLimitEquivSections (hc s.pt.unop)).injective ext j have eq := congr_fun ((hc s.pt.unop).fac ((yoneda.obj s.pt.unop).mapCone s) j) (𝟙 _) dsimp at eq dsimp [Types.isLimitEquivSections, Types.sectionOfCone] rw [eq, Category.comp_id, ← hm, unop_comp]) /-- A cocone is colimit iff it becomes limit after the application of `yoneda.obj X` for all `X : C`. -/ noncomputable def Limits.Cocone.isColimitYonedaEquiv {F : J ⥤ C} (c : Cocone F) : IsColimit c ≃ ∀ (X : C), IsLimit ((yoneda.obj X).mapCone c.op) where toFun h X := isLimitOfPreserves _ h.op invFun h := IsLimit.unop (yonedaJointlyReflectsLimits _ _ h) left_inv _ := Subsingleton.elim _ _ right_inv _ := by ext; apply Subsingleton.elim /-- The cone of `F` corresponding to an element in `(F ⋙ coyoneda.obj X).sections`. -/ @[simps] def Limits.coneOfSectionCompCoyoneda (F : J ⥤ C) (X : Cᵒᵖ) (s : (F ⋙ coyoneda.obj X).sections) : Cone F where pt := X.unop π := compCoyonedaSectionsEquiv F X.unop s noncomputable instance coyonedaPreservesLimit (F : J ⥤ C) (X : Cᵒᵖ) : PreservesLimit F (coyoneda.obj X) where preserves {c} hc := Nonempty.some (by rw [Types.isLimit_iff] intro s hs exact ⟨hc.lift (Limits.coneOfSectionCompCoyoneda F X ⟨s, hs⟩), hc.fac _, hc.uniq (Limits.coneOfSectionCompCoyoneda F X ⟨s, hs⟩)⟩) variable (J) in noncomputable instance coyonedaPreservesLimitsOfShape (X : Cᵒᵖ) : PreservesLimitsOfShape J (coyoneda.obj X) where /-- The coyoneda embeddings jointly reflect limits. -/ def coyonedaJointlyReflectsLimits (F : J ⥤ C) (c : Cone F) (hc : ∀ X : Cᵒᵖ, IsLimit ((coyoneda.obj X).mapCone c)) : IsLimit c where lift s := (hc (op s.pt)).lift ((coyoneda.obj (op s.pt)).mapCone s) (𝟙 _) fac s j := by simpa using congr_fun ((hc (op s.pt)).fac ((coyoneda.obj (op s.pt)).mapCone s) j) (𝟙 _) uniq s m hm := by apply (Types.isLimitEquivSections (hc (op s.pt))).injective ext j dsimp [Types.isLimitEquivSections, Types.sectionOfCone] have eq := congr_fun ((hc (op s.pt)).fac ((coyoneda.obj (op s.pt)).mapCone s) j) (𝟙 _) dsimp at eq rw [eq, Category.id_comp, ← hm] /-- A cone is limit iff it is so after the application of `coyoneda.obj X` for all `X : Cᵒᵖ`. -/ noncomputable def Limits.Cone.isLimitCoyonedaEquiv {F : J ⥤ C} (c : Cone F) : IsLimit c ≃ ∀ (X : Cᵒᵖ), IsLimit ((coyoneda.obj X).mapCone c) where toFun h X := isLimitOfPreserves _ h invFun h := coyonedaJointlyReflectsLimits _ _ h left_inv _ := Subsingleton.elim _ _ right_inv _ := by ext; apply Subsingleton.elim end /-- The yoneda embedding `yoneda.obj X : Cᵒᵖ ⥤ Type v` for `X : C` preserves limits. -/ noncomputable instance yonedaPreservesLimits (X : C) : PreservesLimitsOfSize.{t, w} (yoneda.obj X) where /-- The coyoneda embedding `coyoneda.obj X : C ⥤ Type v` for `X : Cᵒᵖ` preserves limits. -/ noncomputable instance coyonedaPreservesLimits (X : Cᵒᵖ) : PreservesLimitsOfSize.{t, w} (coyoneda.obj X) where noncomputable instance yonedaFunctorPreservesLimits : PreservesLimitsOfSize.{t, w} (@yoneda C _) := by apply preservesLimitsOfEvaluation intro K change PreservesLimitsOfSize (coyoneda.obj K) infer_instance noncomputable instance coyonedaFunctorPreservesLimits : PreservesLimitsOfSize.{t, w} (@coyoneda C _) := by apply preservesLimitsOfEvaluation intro K change PreservesLimitsOfSize (yoneda.obj K) infer_instance noncomputable instance yonedaFunctorReflectsLimits : ReflectsLimitsOfSize.{t, w} (@yoneda C _) := inferInstance noncomputable instance coyonedaFunctorReflectsLimits : ReflectsLimitsOfSize.{t, w} (@coyoneda C _) := inferInstance namespace Functor section Representable variable (F : Cᵒᵖ ⥤ Type v) [F.Representable] {J : Type*} [Category J] noncomputable instance representablePreservesLimit (G : J ⥤ Cᵒᵖ) : PreservesLimit G F := preservesLimitOfNatIso _ F.reprW variable (J) in noncomputable instance representablePreservesLimitsOfShape : PreservesLimitsOfShape J F where noncomputable instance representablePreservesLimits : PreservesLimitsOfSize.{t, w} F where end Representable section Corepresentable variable (F : C ⥤ Type v) [F.Corepresentable] {J : Type*} [Category J] noncomputable instance corepresentablePreservesLimit (G : J ⥤ C) : PreservesLimit G F := preservesLimitOfNatIso _ F.coreprW variable (J) in noncomputable instance corepresentablePreservesLimitsOfShape : PreservesLimitsOfShape J F where noncomputable instance corepresentablePreservesLimits : PreservesLimitsOfSize.{t, w} F where end Corepresentable end Functor end CategoryTheory assert_not_exists AddCommMonoid
CategoryTheory\Limits\ConcreteCategory\Basic.lean
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Adam Topaz -/ import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.TypesFiltered import Mathlib.CategoryTheory.Limits.Yoneda /-! # Facts about (co)limits of functors into concrete categories -/ universe t w v u r open CategoryTheory namespace CategoryTheory.Limits.Concrete attribute [local instance] ConcreteCategory.instFunLike ConcreteCategory.hasCoeToSort 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] [ConcreteCategory.{v} C] [(forget C).Corepresentable] {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] [ConcreteCategory.{max w v} C] {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 : D.pt) (j : J) => D.π.app j x := by let E := (forget C).mapCone D let hE : IsLimit E := isLimitOfPreserves _ hD let G := Types.limitCone.{w, v} (F ⋙ forget C) let hG := Types.limitConeIsLimit.{w, v} (F ⋙ forget C) let T : E.pt ≅ G.pt := hE.conePointUniqueUpToIso hG change Function.Injective (T.hom ≫ fun x j => G.π.app j x) have h : Function.Injective T.hom := by intro a b h suffices T.inv (T.hom a) = T.inv (T.hom b) by simpa rw [h] suffices Function.Injective fun (x : G.pt) j => G.π.app j x by exact this.comp h apply Subtype.ext theorem isLimit_ext {D : Cone F} (hD : IsLimit D) (x y : 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 : ↑(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] [ConcreteCategory.{v} C] [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 _ hc) hF end Surjective end Limits section Colimits section variable {C : Type u} [Category.{v} C] [ConcreteCategory.{t} C] {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, F.obj j) → 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 : D.pt) : ∃ (j : J) (y : 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 : ↑(colimit F)) : ∃ (j : J) (y : 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 : F.obj i) (y : 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 show 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 : F.obj i) (y : 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] [ConcreteCategory.{max t w} C] {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 : F.obj i) (y : 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 : F.obj i) (y : 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.{t} _ hD _ _, Concrete.isColimit_rep_eq_of_exists _ _ _⟩ theorem colimit_exists_of_rep_eq [HasColimit F] {i j : J} (x : F.obj i) (y : 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.{t} F (colimit.isColimit _) x y h theorem colimit_rep_eq_iff_exists [HasColimit F] {i j : J} (x : F.obj i) (y : 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.{t} _ _ _, Concrete.colimit_rep_eq_of_exists _ _ _⟩ end FilteredColimits end Colimits end CategoryTheory.Limits.Concrete
CategoryTheory\Limits\ConcreteCategory\WithAlgebraicStructures.lean
/- Copyright (c) 2024 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic import Mathlib.Algebra.Module.LinearMap.Defs import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Colimits in concrete categories with algebraic structures 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`. -/ universe t w v u r open CategoryTheory namespace CategoryTheory.Limits.Concrete attribute [local instance] ConcreteCategory.instFunLike ConcreteCategory.hasCoeToSort variable {C : Type u} [Category.{v} C] [ConcreteCategory.{max t w} C] {J : Type w} [Category.{r} J] section zero theorem colimit_rep_eq_zero (F : J ⥤ C) [PreservesColimit F (forget C)] [IsFiltered J] [∀ c : C, Zero c] [∀ {c c' : C}, ZeroHomClass (c ⟶ c') c c'] [HasColimit F] (j : J) (x : F.obj j) (hx : colimit.ι F j x = 0) : ∃ (j' : J) (i : j ⟶ j'), F.map i 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 ⥤ C) [PreservesColimit F (forget C)] [IsFiltered J] [HasColimit F] (R : Type*) [Semiring R] [∀ c : C, AddCommMonoid c] [∀ c : C, Module R c] [∀ {c c' : C}, LinearMapClass (c ⟶ c') R c c'] (r : R) (H : ∃ (j' : J), ∀ (j : J) (_ : j' ⟶ j), ∀ (c : F.obj j), r • c = 0 → c = 0) (x : (forget C).obj (colimit F)) (hx : r • x = 0) : x = 0 := by classical obtain ⟨j, x, rfl⟩ := Concrete.colimit_exists_rep F x rw [← map_smul] 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, comp_apply, ← map_smul, ← map_smul, h, map_zero]))) end module end CategoryTheory.Limits.Concrete
CategoryTheory\Limits\Constructions\BinaryProducts.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal /-! # Constructing binary product from pullbacks and terminal object. The product is the pullback over the terminal objects. In particular, if a category has pullbacks and a terminal object, then it has binary products. We also provide the dual. -/ universe v v' u u' open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] (F : C ⥤ D) /-- If a span is the pullback span over the terminal object, then it is a binary product. -/ def isBinaryProductOfIsTerminalIsPullback (F : Discrete WalkingPair ⥤ C) (c : Cone F) {X : C} (hX : IsTerminal X) (f : F.obj ⟨WalkingPair.left⟩ ⟶ X) (g : F.obj ⟨WalkingPair.right⟩ ⟶ X) (hc : IsLimit (PullbackCone.mk (c.π.app ⟨WalkingPair.left⟩) (c.π.app ⟨WalkingPair.right⟩ : _) <| hX.hom_ext (_ ≫ f) (_ ≫ g))) : IsLimit c where lift s := hc.lift (PullbackCone.mk (s.π.app ⟨WalkingPair.left⟩) (s.π.app ⟨WalkingPair.right⟩) (hX.hom_ext _ _)) fac s j := Discrete.casesOn j fun j => WalkingPair.casesOn j (hc.fac _ WalkingCospan.left) (hc.fac _ WalkingCospan.right) uniq s m J := by let c' := PullbackCone.mk (m ≫ c.π.app ⟨WalkingPair.left⟩) (m ≫ c.π.app ⟨WalkingPair.right⟩ : _) (hX.hom_ext (_ ≫ f) (_ ≫ g)) dsimp; rw [← J, ← J] apply hc.hom_ext rintro (_ | (_ | _)) <;> simp only [PullbackCone.mk_π_app_one, PullbackCone.mk_π_app] exacts [(Category.assoc _ _ _).symm.trans (hc.fac_assoc c' WalkingCospan.left f).symm, (hc.fac c' WalkingCospan.left).symm, (hc.fac c' WalkingCospan.right).symm] /-- The pullback over the terminal object is the product -/ def isProductOfIsTerminalIsPullback {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsTerminal Z) (H₂ : IsLimit (PullbackCone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _))) : IsLimit (BinaryFan.mk h k) := by apply isBinaryProductOfIsTerminalIsPullback _ _ H₁ exact H₂ /-- The product is the pullback over the terminal object. -/ def isPullbackOfIsTerminalIsProduct {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsTerminal Z) (H₂ : IsLimit (BinaryFan.mk h k)) : IsLimit (PullbackCone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _)) := by apply PullbackCone.isLimitAux' intro s use H₂.lift (BinaryFan.mk s.fst s.snd) use H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.left⟩ use H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.right⟩ intro m h₁ h₂ apply H₂.hom_ext rintro ⟨⟨⟩⟩ · exact h₁.trans (H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.left⟩).symm · exact h₂.trans (H₂.fac (BinaryFan.mk s.fst s.snd) ⟨WalkingPair.right⟩).symm /-- Any category with pullbacks and a terminal object has a limit cone for each walking pair. -/ noncomputable def limitConeOfTerminalAndPullbacks [HasTerminal C] [HasPullbacks C] (F : Discrete WalkingPair ⥤ C) : LimitCone F where cone := { pt := pullback (terminal.from (F.obj ⟨WalkingPair.left⟩)) (terminal.from (F.obj ⟨WalkingPair.right⟩)) π := Discrete.natTrans fun x => Discrete.casesOn x fun x => WalkingPair.casesOn x (pullback.fst _ _) (pullback.snd _ _) } isLimit := isBinaryProductOfIsTerminalIsPullback F _ terminalIsTerminal _ _ (pullbackIsPullback _ _) variable (C) -- This is not an instance, as it is not always how one wants to construct binary products! /-- Any category with pullbacks and terminal object has binary products. -/ theorem hasBinaryProducts_of_hasTerminal_and_pullbacks [HasTerminal C] [HasPullbacks C] : HasBinaryProducts C := { has_limit := fun F => HasLimit.mk (limitConeOfTerminalAndPullbacks F) } variable {C} /-- A functor that preserves terminal objects and pullbacks preserves binary products. -/ noncomputable def preservesBinaryProductsOfPreservesTerminalAndPullbacks [HasTerminal C] [HasPullbacks C] [PreservesLimitsOfShape (Discrete.{0} PEmpty) F] [PreservesLimitsOfShape WalkingCospan F] : PreservesLimitsOfShape (Discrete WalkingPair) F := ⟨fun {K} => preservesLimitOfPreservesLimitCone (limitConeOfTerminalAndPullbacks K).2 (by apply isBinaryProductOfIsTerminalIsPullback _ _ (isLimitOfHasTerminalOfPreservesLimit F) apply isLimitOfHasPullbackOfPreservesLimit)⟩ /-- In a category with a terminal object and pullbacks, a product of objects `X` and `Y` is isomorphic to a pullback. -/ noncomputable def prodIsoPullback [HasTerminal C] [HasPullbacks C] (X Y : C) [HasBinaryProduct X Y] : X ⨯ Y ≅ pullback (terminal.from X) (terminal.from Y) := limit.isoLimitCone (limitConeOfTerminalAndPullbacks _) /-- If a cospan is the pushout cospan under the initial object, then it is a binary coproduct. -/ def isBinaryCoproductOfIsInitialIsPushout (F : Discrete WalkingPair ⥤ C) (c : Cocone F) {X : C} (hX : IsInitial X) (f : X ⟶ F.obj ⟨WalkingPair.left⟩) (g : X ⟶ F.obj ⟨WalkingPair.right⟩) (hc : IsColimit (PushoutCocone.mk (c.ι.app ⟨WalkingPair.left⟩) (c.ι.app ⟨WalkingPair.right⟩ : _) <| hX.hom_ext (f ≫ _) (g ≫ _))) : IsColimit c where desc s := hc.desc (PushoutCocone.mk (s.ι.app ⟨WalkingPair.left⟩) (s.ι.app ⟨WalkingPair.right⟩) (hX.hom_ext _ _)) fac s j := Discrete.casesOn j fun j => WalkingPair.casesOn j (hc.fac _ WalkingSpan.left) (hc.fac _ WalkingSpan.right) uniq s m J := by let c' := PushoutCocone.mk (c.ι.app ⟨WalkingPair.left⟩ ≫ m) (c.ι.app ⟨WalkingPair.right⟩ ≫ m) (hX.hom_ext (f ≫ _) (g ≫ _)) dsimp; rw [← J, ← J] apply hc.hom_ext rintro (_ | (_ | _)) <;> simp only [PushoutCocone.mk_ι_app_zero, PushoutCocone.mk_ι_app, Category.assoc] on_goal 1 => congr 1 exacts [(hc.fac c' WalkingSpan.left).symm, (hc.fac c' WalkingSpan.left).symm, (hc.fac c' WalkingSpan.right).symm] /-- The pushout under the initial object is the coproduct -/ def isCoproductOfIsInitialIsPushout {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsInitial W) (H₂ : IsColimit (PushoutCocone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _))) : IsColimit (BinaryCofan.mk f g) := by apply isBinaryCoproductOfIsInitialIsPushout _ _ H₁ exact H₂ /-- The coproduct is the pushout under the initial object. -/ def isPushoutOfIsInitialIsCoproduct {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ X) (k : W ⟶ Y) (H₁ : IsInitial W) (H₂ : IsColimit (BinaryCofan.mk f g)) : IsColimit (PushoutCocone.mk _ _ (show h ≫ f = k ≫ g from H₁.hom_ext _ _)) := by apply PushoutCocone.isColimitAux' intro s use H₂.desc (BinaryCofan.mk s.inl s.inr) use H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.left⟩ use H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.right⟩ intro m h₁ h₂ apply H₂.hom_ext rintro ⟨⟨⟩⟩ · exact h₁.trans (H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.left⟩).symm · exact h₂.trans (H₂.fac (BinaryCofan.mk s.inl s.inr) ⟨WalkingPair.right⟩).symm /-- Any category with pushouts and an initial object has a colimit cocone for each walking pair. -/ noncomputable def colimitCoconeOfInitialAndPushouts [HasInitial C] [HasPushouts C] (F : Discrete WalkingPair ⥤ C) : ColimitCocone F where cocone := { pt := pushout (initial.to (F.obj ⟨WalkingPair.left⟩)) (initial.to (F.obj ⟨WalkingPair.right⟩)) ι := Discrete.natTrans fun x => Discrete.casesOn x fun x => WalkingPair.casesOn x (pushout.inl _ _) (pushout.inr _ _) } isColimit := isBinaryCoproductOfIsInitialIsPushout F _ initialIsInitial _ _ (pushoutIsPushout _ _) variable (C) -- This is not an instance, as it is not always how one wants to construct binary coproducts! /-- Any category with pushouts and initial object has binary coproducts. -/ theorem hasBinaryCoproducts_of_hasInitial_and_pushouts [HasInitial C] [HasPushouts C] : HasBinaryCoproducts C := { has_colimit := fun F => HasColimit.mk (colimitCoconeOfInitialAndPushouts F) } variable {C} /-- A functor that preserves initial objects and pushouts preserves binary coproducts. -/ noncomputable def preservesBinaryCoproductsOfPreservesInitialAndPushouts [HasInitial C] [HasPushouts C] [PreservesColimitsOfShape (Discrete.{0} PEmpty) F] [PreservesColimitsOfShape WalkingSpan F] : PreservesColimitsOfShape (Discrete WalkingPair) F := ⟨fun {K} => preservesColimitOfPreservesColimitCocone (colimitCoconeOfInitialAndPushouts K).2 (by apply isBinaryCoproductOfIsInitialIsPushout _ _ (isColimitOfHasInitialOfPreservesColimit F) apply isColimitOfHasPushoutOfPreservesColimit)⟩ /-- In a category with an initial object and pushouts, a coproduct of objects `X` and `Y` is isomorphic to a pushout. -/ noncomputable def coprodIsoPushout [HasInitial C] [HasPushouts C] (X Y : C) [HasBinaryCoproduct X Y] : X ⨿ Y ≅ pushout (initial.to X) (initial.to Y) := colimit.isoColimitCocone (colimitCoconeOfInitialAndPushouts _)
CategoryTheory\Limits\Constructions\EpiMono.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Pullbacks /-! # Relating monomorphisms and epimorphisms to limits and colimits If `F` preserves (resp. reflects) pullbacks, then it preserves (resp. reflects) monomorphisms. We also provide the dual version for epimorphisms. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Category Limits variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] variable (F : C ⥤ D) /-- If `F` preserves pullbacks, then it preserves monomorphisms. -/ theorem preserves_mono_of_preservesLimit {X Y : C} (f : X ⟶ Y) [PreservesLimit (cospan f f) F] [Mono f] : Mono (F.map f) := by have := isLimitPullbackConeMapOfIsLimit F _ (PullbackCone.isLimitMkIdId f) simp_rw [F.map_id] at this apply PullbackCone.mono_of_isLimitMkIdId _ this instance (priority := 100) preservesMonomorphisms_of_preservesLimitsOfShape [PreservesLimitsOfShape WalkingCospan F] : F.PreservesMonomorphisms where preserves f _ := preserves_mono_of_preservesLimit F f /-- If `F` reflects pullbacks, then it reflects monomorphisms. -/ theorem reflects_mono_of_reflectsLimit {X Y : C} (f : X ⟶ Y) [ReflectsLimit (cospan f f) F] [Mono (F.map f)] : Mono f := by have := PullbackCone.isLimitMkIdId (F.map f) simp_rw [← F.map_id] at this apply PullbackCone.mono_of_isLimitMkIdId _ (isLimitOfIsLimitPullbackConeMap F _ this) instance (priority := 100) reflectsMonomorphisms_of_reflectsLimitsOfShape [ReflectsLimitsOfShape WalkingCospan F] : F.ReflectsMonomorphisms where reflects f _ := reflects_mono_of_reflectsLimit F f /-- If `F` preserves pushouts, then it preserves epimorphisms. -/ theorem preserves_epi_of_preservesColimit {X Y : C} (f : X ⟶ Y) [PreservesColimit (span f f) F] [Epi f] : Epi (F.map f) := by have := isColimitPushoutCoconeMapOfIsColimit F _ (PushoutCocone.isColimitMkIdId f) simp_rw [F.map_id] at this apply PushoutCocone.epi_of_isColimitMkIdId _ this instance (priority := 100) preservesEpimorphisms_of_preservesColimitsOfShape [PreservesColimitsOfShape WalkingSpan F] : F.PreservesEpimorphisms where preserves f _ := preserves_epi_of_preservesColimit F f /-- If `F` reflects pushouts, then it reflects epimorphisms. -/ theorem reflects_epi_of_reflectsColimit {X Y : C} (f : X ⟶ Y) [ReflectsColimit (span f f) F] [Epi (F.map f)] : Epi f := by have := PushoutCocone.isColimitMkIdId (F.map f) simp_rw [← F.map_id] at this apply PushoutCocone.epi_of_isColimitMkIdId _ (isColimitOfIsColimitPushoutCoconeMap F _ this) instance (priority := 100) reflectsEpimorphisms_of_reflectsColimitsOfShape [ReflectsColimitsOfShape WalkingSpan F] : F.ReflectsEpimorphisms where reflects f _ := reflects_epi_of_reflectsColimit F f end CategoryTheory
CategoryTheory\Limits\Constructions\Equalizers.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts /-! # Constructing equalizers from pullbacks and binary products. If a category has pullbacks and binary products, then it has equalizers. TODO: generalize universe -/ noncomputable section universe v v' u u' open CategoryTheory CategoryTheory.Category namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v'} D] (G : C ⥤ D) -- We hide the "implementation details" inside a namespace namespace HasEqualizersOfHasPullbacksAndBinaryProducts variable [HasBinaryProducts C] [HasPullbacks C] /-- Define the equalizing object -/ abbrev constructEqualizer (F : WalkingParallelPair ⥤ C) : C := pullback (prod.lift (𝟙 _) (F.map WalkingParallelPairHom.left)) (prod.lift (𝟙 _) (F.map WalkingParallelPairHom.right)) /-- Define the equalizing morphism -/ abbrev pullbackFst (F : WalkingParallelPair ⥤ C) : constructEqualizer F ⟶ F.obj WalkingParallelPair.zero := pullback.fst _ _ theorem pullbackFst_eq_pullback_snd (F : WalkingParallelPair ⥤ C) : pullbackFst F = pullback.snd _ _ := by convert (eq_whisker pullback.condition Limits.prod.fst : (_ : constructEqualizer F ⟶ F.obj WalkingParallelPair.zero) = _) <;> simp /-- Define the equalizing cone -/ abbrev equalizerCone (F : WalkingParallelPair ⥤ C) : Cone F := Cone.ofFork (Fork.ofι (pullbackFst F) (by conv_rhs => rw [pullbackFst_eq_pullback_snd] convert (eq_whisker pullback.condition Limits.prod.snd : (_ : constructEqualizer F ⟶ F.obj WalkingParallelPair.one) = _) using 1 <;> simp)) /-- Show the equalizing cone is a limit -/ def equalizerConeIsLimit (F : WalkingParallelPair ⥤ C) : IsLimit (equalizerCone F) where lift := by intro c; apply pullback.lift (c.π.app _) (c.π.app _) ext <;> simp fac := by rintro c (_ | _) <;> simp uniq := by intro c _ J have J0 := J WalkingParallelPair.zero; simp at J0 apply pullback.hom_ext · rwa [limit.lift_π] · erw [limit.lift_π, ← J0, pullbackFst_eq_pullback_snd] end HasEqualizersOfHasPullbacksAndBinaryProducts open HasEqualizersOfHasPullbacksAndBinaryProducts -- This is not an instance, as it is not always how one wants to construct equalizers! /-- Any category with pullbacks and binary products, has equalizers. -/ theorem hasEqualizers_of_hasPullbacks_and_binary_products [HasBinaryProducts C] [HasPullbacks C] : HasEqualizers C := { has_limit := fun F => HasLimit.mk { cone := equalizerCone F isLimit := equalizerConeIsLimit F } } attribute [local instance] hasPullback_of_preservesPullback /-- A functor that preserves pullbacks and binary products also presrves equalizers. -/ def preservesEqualizersOfPreservesPullbacksAndBinaryProducts [HasBinaryProducts C] [HasPullbacks C] [PreservesLimitsOfShape (Discrete WalkingPair) G] [PreservesLimitsOfShape WalkingCospan G] : PreservesLimitsOfShape WalkingParallelPair G := ⟨fun {K} => preservesLimitOfPreservesLimitCone (equalizerConeIsLimit K) <| { lift := fun c => by refine pullback.lift ?_ ?_ ?_ ≫ (PreservesPullback.iso _ _ _ ).inv · exact c.π.app WalkingParallelPair.zero · exact c.π.app WalkingParallelPair.zero apply (mapIsLimitOfPreservesOfIsLimit G _ _ (prodIsProd _ _)).hom_ext rintro (_ | _) · simp only [Category.assoc, ← G.map_comp, prod.lift_fst, BinaryFan.π_app_left, BinaryFan.mk_fst] · simp only [BinaryFan.π_app_right, BinaryFan.mk_snd, Category.assoc, ← G.map_comp, prod.lift_snd] exact (c.π.naturality WalkingParallelPairHom.left).symm.trans (c.π.naturality WalkingParallelPairHom.right) fac := fun c j => by rcases j with (_ | _) <;> simp only [Category.comp_id, PreservesPullback.iso_inv_fst, Cone.ofFork_π, G.map_comp, PreservesPullback.iso_inv_fst_assoc, Functor.mapCone_π_app, eqToHom_refl, Category.assoc, Fork.ofι_π_app, pullback.lift_fst, pullback.lift_fst_assoc] exact (c.π.naturality WalkingParallelPairHom.left).symm.trans (Category.id_comp _) uniq := fun s m h => by rw [Iso.eq_comp_inv] have := h WalkingParallelPair.zero dsimp [equalizerCone] at this ext <;> simp only [PreservesPullback.iso_hom_snd, Category.assoc, PreservesPullback.iso_hom_fst, pullback.lift_fst, pullback.lift_snd, Category.comp_id, ← pullbackFst_eq_pullback_snd, ← this] }⟩ -- We hide the "implementation details" inside a namespace namespace HasCoequalizersOfHasPushoutsAndBinaryCoproducts variable [HasBinaryCoproducts C] [HasPushouts C] /-- Define the equalizing object -/ abbrev constructCoequalizer (F : WalkingParallelPair ⥤ C) : C := pushout (coprod.desc (𝟙 _) (F.map WalkingParallelPairHom.left)) (coprod.desc (𝟙 _) (F.map WalkingParallelPairHom.right)) /-- Define the equalizing morphism -/ abbrev pushoutInl (F : WalkingParallelPair ⥤ C) : F.obj WalkingParallelPair.one ⟶ constructCoequalizer F := pushout.inl _ _ theorem pushoutInl_eq_pushout_inr (F : WalkingParallelPair ⥤ C) : pushoutInl F = pushout.inr _ _ := by convert (whisker_eq Limits.coprod.inl pushout.condition : (_ : F.obj _ ⟶ constructCoequalizer _) = _) <;> simp /-- Define the equalizing cocone -/ abbrev coequalizerCocone (F : WalkingParallelPair ⥤ C) : Cocone F := Cocone.ofCofork (Cofork.ofπ (pushoutInl F) (by conv_rhs => rw [pushoutInl_eq_pushout_inr] convert (whisker_eq Limits.coprod.inr pushout.condition : (_ : F.obj _ ⟶ constructCoequalizer _) = _) using 1 <;> simp)) /-- Show the equalizing cocone is a colimit -/ def coequalizerCoconeIsColimit (F : WalkingParallelPair ⥤ C) : IsColimit (coequalizerCocone F) where desc := by intro c; apply pushout.desc (c.ι.app _) (c.ι.app _) ext <;> simp fac := by rintro c (_ | _) <;> simp uniq := by intro c m J have J1 : pushoutInl F ≫ m = c.ι.app WalkingParallelPair.one := by simpa using J WalkingParallelPair.one apply pushout.hom_ext · rw [colimit.ι_desc] exact J1 · rw [colimit.ι_desc, ← pushoutInl_eq_pushout_inr] exact J1 end HasCoequalizersOfHasPushoutsAndBinaryCoproducts open HasCoequalizersOfHasPushoutsAndBinaryCoproducts -- This is not an instance, as it is not always how one wants to construct equalizers! /-- Any category with pullbacks and binary products, has equalizers. -/ theorem hasCoequalizers_of_hasPushouts_and_binary_coproducts [HasBinaryCoproducts C] [HasPushouts C] : HasCoequalizers C := { has_colimit := fun F => HasColimit.mk { cocone := coequalizerCocone F isColimit := coequalizerCoconeIsColimit F } } attribute [local instance] hasPushout_of_preservesPushout /-- A functor that preserves pushouts and binary coproducts also presrves coequalizers. -/ def preservesCoequalizersOfPreservesPushoutsAndBinaryCoproducts [HasBinaryCoproducts C] [HasPushouts C] [PreservesColimitsOfShape (Discrete WalkingPair) G] [PreservesColimitsOfShape WalkingSpan G] : PreservesColimitsOfShape WalkingParallelPair G := ⟨fun {K} => preservesColimitOfPreservesColimitCocone (coequalizerCoconeIsColimit K) <| { desc := fun c => by refine (PreservesPushout.iso _ _ _).inv ≫ pushout.desc ?_ ?_ ?_ · exact c.ι.app WalkingParallelPair.one · exact c.ι.app WalkingParallelPair.one apply (mapIsColimitOfPreservesOfIsColimit G _ _ (coprodIsCoprod _ _)).hom_ext rintro (_ | _) · simp only [BinaryCofan.ι_app_left, BinaryCofan.mk_inl, Category.assoc, ← G.map_comp_assoc, coprod.inl_desc] · simp only [BinaryCofan.ι_app_right, BinaryCofan.mk_inr, Category.assoc, ← G.map_comp_assoc, coprod.inr_desc] exact (c.ι.naturality WalkingParallelPairHom.left).trans (c.ι.naturality WalkingParallelPairHom.right).symm fac := fun c j => by rcases j with (_ | _) <;> simp only [Functor.mapCocone_ι_app, Cocone.ofCofork_ι, Category.id_comp, eqToHom_refl, Category.assoc, Functor.map_comp, Cofork.ofπ_ι_app, pushout.inl_desc, PreservesPushout.inl_iso_inv_assoc] exact (c.ι.naturality WalkingParallelPairHom.left).trans (Category.comp_id _) uniq := fun s m h => by rw [Iso.eq_inv_comp] have := h WalkingParallelPair.one dsimp [coequalizerCocone] at this ext <;> simp only [PreservesPushout.inl_iso_hom_assoc, Category.id_comp, pushout.inl_desc, pushout.inr_desc, PreservesPushout.inr_iso_hom_assoc, ← pushoutInl_eq_pushout_inr, ← this] }⟩ end CategoryTheory.Limits
CategoryTheory\Limits\Constructions\Filtered.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Limits.Opposites /-! # Constructing colimits from finite colimits and filtered colimits We construct colimits of size `w` from finite colimits and filtered colimits of size `w`. Since `w`-sized colimits are constructed from coequalizers and `w`-sized coproducts, it suffices to construct `w`-sized coproducts from finite coproducts and `w`-sized filtered colimits. The idea is simple: to construct coproducts of shape `α`, we take the colimit of the filtered diagram of all coproducts of finite subsets of `α`. We also deduce the dual statement by invoking the original statement in `Cᵒᵖ`. -/ universe w v u noncomputable section open CategoryTheory variable {C : Type u} [Category.{v} C] {α : Type w} namespace CategoryTheory.Limits namespace CoproductsFromFiniteFiltered /-- If `C` has finite coproducts, a functor `Discrete α ⥤ C` lifts to a functor `Finset (Discrete α) ⥤ C` by taking coproducts. -/ @[simps!] def liftToFinset [HasFiniteCoproducts C] (F : Discrete α ⥤ C) : Finset (Discrete α) ⥤ C where obj s := ∐ fun x : s => F.obj x map {_ Y} h := Sigma.desc fun y => Sigma.ι (fun (x : { x // x ∈ Y }) => F.obj x) ⟨y, h.down.down y.2⟩ /-- If `C` has finite coproducts and filtered colimits, we can construct arbitrary coproducts by taking the colimit of the diagram formed by the coproducts of finite sets over the indexing type. -/ @[simps!] def liftToFinsetColimitCocone [HasFiniteCoproducts C] [HasFilteredColimitsOfSize.{w, w} C] (F : Discrete α ⥤ C) : ColimitCocone F where cocone := { pt := colimit (liftToFinset F) ι := Discrete.natTrans fun j => @Sigma.ι _ _ _ (fun x : ({j} : Finset (Discrete α)) => F.obj x) _ ⟨j, by simp⟩ ≫ colimit.ι (liftToFinset F) {j} } isColimit := { desc := fun s => colimit.desc (liftToFinset F) { pt := s.pt ι := { app := fun t => Sigma.desc fun x => s.ι.app x } } uniq := fun s m h => by apply colimit.hom_ext rintro t dsimp [liftToFinset] apply colimit.hom_ext rintro ⟨⟨j, hj⟩⟩ convert h j using 1 · simp [← colimit.w (liftToFinset F) ⟨⟨Finset.singleton_subset_iff.2 hj⟩⟩] rfl · aesop_cat } end CoproductsFromFiniteFiltered open CoproductsFromFiniteFiltered theorem hasCoproducts_of_finite_and_filtered [HasFiniteCoproducts C] [HasFilteredColimitsOfSize.{w, w} C] : HasCoproducts.{w} C := fun α => by classical exact ⟨fun F => HasColimit.mk (liftToFinsetColimitCocone F)⟩ theorem has_colimits_of_finite_and_filtered [HasFiniteColimits C] [HasFilteredColimitsOfSize.{w, w} C] : HasColimitsOfSize.{w, w} C := have : HasCoproducts.{w} C := hasCoproducts_of_finite_and_filtered has_colimits_of_hasCoequalizers_and_coproducts theorem hasProducts_of_finite_and_cofiltered [HasFiniteProducts C] [HasCofilteredLimitsOfSize.{w, w} C] : HasProducts.{w} C := have : HasCoproducts.{w} Cᵒᵖ := hasCoproducts_of_finite_and_filtered hasProducts_of_opposite theorem has_limits_of_finite_and_cofiltered [HasFiniteLimits C] [HasCofilteredLimitsOfSize.{w, w} C] : HasLimitsOfSize.{w, w} C := have : HasProducts.{w} C := hasProducts_of_finite_and_cofiltered has_limits_of_hasEqualizers_and_products end CategoryTheory.Limits
CategoryTheory\Limits\Constructions\FiniteProductsOfBinaryProducts.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.Logic.Equiv.Fin /-! # Constructing finite products from binary products and terminal. If a category has binary products and a terminal object then it has finite products. If a functor preserves binary products and the terminal object then it preserves finite products. ## TODO Provide the dual results. Show the analogous results for functors which reflect or create (co)limits. -/ universe v v' u u' noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits namespace CategoryTheory variable {J : Type v} [SmallCategory J] variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v'} D] /-- Given `n+1` objects of `C`, a fan for the last `n` with point `c₁.pt` and a binary fan on `c₁.pt` and `f 0`, we can build a fan for all `n+1`. In `extendFanIsLimit` we show that if the two given fans are limits, then this fan is also a limit. -/ @[simps!] -- Porting note: removed semi-reducible config def extendFan {n : ℕ} {f : Fin (n + 1) → C} (c₁ : Fan fun i : Fin n => f i.succ) (c₂ : BinaryFan (f 0) c₁.pt) : Fan f := Fan.mk c₂.pt (by refine Fin.cases ?_ ?_ · apply c₂.fst · intro i apply c₂.snd ≫ c₁.π.app ⟨i⟩) /-- Show that if the two given fans in `extendFan` are limits, then the constructed fan is also a limit. -/ def extendFanIsLimit {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Fan fun i : Fin n => f i.succ} {c₂ : BinaryFan (f 0) c₁.pt} (t₁ : IsLimit c₁) (t₂ : IsLimit c₂) : IsLimit (extendFan c₁ c₂) where lift s := by apply (BinaryFan.IsLimit.lift' t₂ (s.π.app ⟨0⟩) _).1 apply t₁.lift ⟨_, Discrete.natTrans fun ⟨i⟩ => s.π.app ⟨i.succ⟩⟩ fac := fun s ⟨j⟩ => by refine Fin.inductionOn j ?_ ?_ · apply (BinaryFan.IsLimit.lift' t₂ _ _).2.1 · rintro i - dsimp only [extendFan_π_app] rw [Fin.cases_succ, ← assoc, (BinaryFan.IsLimit.lift' t₂ _ _).2.2, t₁.fac] rfl uniq s m w := by apply BinaryFan.IsLimit.hom_ext t₂ · rw [(BinaryFan.IsLimit.lift' t₂ _ _).2.1] apply w ⟨0⟩ · rw [(BinaryFan.IsLimit.lift' t₂ _ _).2.2] apply t₁.uniq ⟨_, _⟩ rintro ⟨j⟩ rw [assoc] dsimp only [Discrete.natTrans_app] rw [← w ⟨j.succ⟩] dsimp only [extendFan_π_app] rw [Fin.cases_succ] section variable [HasBinaryProducts C] [HasTerminal C] /-- If `C` has a terminal object and binary products, then it has a product for objects indexed by `Fin n`. This is a helper lemma for `hasFiniteProductsOfHasBinaryAndTerminal`, which is more general than this. -/ private theorem hasProduct_fin : ∀ (n : ℕ) (f : Fin n → C), HasProduct f | 0 => fun _ => letI : HasLimitsOfShape (Discrete (Fin 0)) C := hasLimitsOfShape_of_equivalence (Discrete.equivalence.{0} finZeroEquiv'.symm) inferInstance | n + 1 => fun f => haveI := hasProduct_fin n HasLimit.mk ⟨_, extendFanIsLimit f (limit.isLimit _) (limit.isLimit _)⟩ /-- If `C` has a terminal object and binary products, then it has finite products. -/ theorem hasFiniteProducts_of_has_binary_and_terminal : HasFiniteProducts C := ⟨fun n => ⟨fun K => let this := hasProduct_fin n fun n => K.obj ⟨n⟩ let that : (Discrete.functor fun n => K.obj ⟨n⟩) ≅ K := Discrete.natIso fun ⟨_⟩ => Iso.refl _ @hasLimitOfIso _ _ _ _ _ _ this that⟩⟩ end section Preserves variable (F : C ⥤ D) variable [PreservesLimitsOfShape (Discrete WalkingPair) F] variable [PreservesLimitsOfShape (Discrete.{0} PEmpty) F] variable [HasFiniteProducts.{v} C] /-- If `F` preserves the terminal object and binary products, then it preserves products indexed by `Fin n` for any `n`. -/ noncomputable def preservesFinOfPreservesBinaryAndTerminal : ∀ (n : ℕ) (f : Fin n → C), PreservesLimit (Discrete.functor f) F | 0 => fun f => by letI : PreservesLimitsOfShape (Discrete (Fin 0)) F := preservesLimitsOfShapeOfEquiv.{0, 0} (Discrete.equivalence finZeroEquiv'.symm) _ infer_instance | n + 1 => by haveI := preservesFinOfPreservesBinaryAndTerminal n intro f apply preservesLimitOfPreservesLimitCone (extendFanIsLimit f (limit.isLimit _) (limit.isLimit _)) _ apply (isLimitMapConeFanMkEquiv _ _ _).symm _ let this := extendFanIsLimit (fun i => F.obj (f i)) (isLimitOfHasProductOfPreservesLimit F _) (isLimitOfHasBinaryProductOfPreservesLimit F _ _) refine IsLimit.ofIsoLimit this ?_ apply Cones.ext _ _ · apply Iso.refl _ rintro ⟨j⟩ refine Fin.inductionOn j ?_ ?_ · apply (Category.id_comp _).symm · rintro i _ dsimp [extendFan_π_app, Iso.refl_hom, Fan.mk_π_app] change F.map _ ≫ _ = 𝟙 _ ≫ _ simp only [id_comp, ← F.map_comp] rfl /-- If `F` preserves the terminal object and binary products, then it preserves limits of shape `Discrete (Fin n)`. -/ def preservesShapeFinOfPreservesBinaryAndTerminal (n : ℕ) : PreservesLimitsOfShape (Discrete (Fin n)) F where preservesLimit {K} := by let that : (Discrete.functor fun n => K.obj ⟨n⟩) ≅ K := Discrete.natIso fun ⟨i⟩ => Iso.refl _ haveI := preservesFinOfPreservesBinaryAndTerminal F n fun n => K.obj ⟨n⟩ apply preservesLimitOfIsoDiagram F that /-- If `F` preserves the terminal object and binary products then it preserves finite products. -/ def preservesFiniteProductsOfPreservesBinaryAndTerminal (J : Type) [Fintype J] : PreservesLimitsOfShape (Discrete J) F := by classical let e := Fintype.equivFin J haveI := preservesShapeFinOfPreservesBinaryAndTerminal F (Fintype.card J) apply preservesLimitsOfShapeOfEquiv.{0, 0} (Discrete.equivalence e).symm end Preserves /-- Given `n+1` objects of `C`, a cofan for the last `n` with point `c₁.pt` and a binary cofan on `c₁.X` and `f 0`, we can build a cofan for all `n+1`. In `extendCofanIsColimit` we show that if the two given cofans are colimits, then this cofan is also a colimit. -/ @[simps!] -- Porting note: removed semireducible config def extendCofan {n : ℕ} {f : Fin (n + 1) → C} (c₁ : Cofan fun i : Fin n => f i.succ) (c₂ : BinaryCofan (f 0) c₁.pt) : Cofan f := Cofan.mk c₂.pt (by refine Fin.cases ?_ ?_ · apply c₂.inl · intro i apply c₁.ι.app ⟨i⟩ ≫ c₂.inr) /-- Show that if the two given cofans in `extendCofan` are colimits, then the constructed cofan is also a colimit. -/ def extendCofanIsColimit {n : ℕ} (f : Fin (n + 1) → C) {c₁ : Cofan fun i : Fin n => f i.succ} {c₂ : BinaryCofan (f 0) c₁.pt} (t₁ : IsColimit c₁) (t₂ : IsColimit c₂) : IsColimit (extendCofan c₁ c₂) where desc s := by apply (BinaryCofan.IsColimit.desc' t₂ (s.ι.app ⟨0⟩) _).1 apply t₁.desc ⟨_, Discrete.natTrans fun i => s.ι.app ⟨i.as.succ⟩⟩ fac s := by rintro ⟨j⟩ refine Fin.inductionOn j ?_ ?_ · apply (BinaryCofan.IsColimit.desc' t₂ _ _).2.1 · rintro i - dsimp only [extendCofan_ι_app] rw [Fin.cases_succ, assoc, (BinaryCofan.IsColimit.desc' t₂ _ _).2.2, t₁.fac] rfl uniq s m w := by apply BinaryCofan.IsColimit.hom_ext t₂ · rw [(BinaryCofan.IsColimit.desc' t₂ _ _).2.1] apply w ⟨0⟩ · rw [(BinaryCofan.IsColimit.desc' t₂ _ _).2.2] apply t₁.uniq ⟨_, _⟩ rintro ⟨j⟩ dsimp only [Discrete.natTrans_app] rw [← w ⟨j.succ⟩] dsimp only [extendCofan_ι_app] rw [Fin.cases_succ, assoc] section variable [HasBinaryCoproducts C] [HasInitial C] /-- If `C` has an initial object and binary coproducts, then it has a coproduct for objects indexed by `Fin n`. This is a helper lemma for `hasCofiniteProductsOfHasBinaryAndTerminal`, which is more general than this. -/ private theorem hasCoproduct_fin : ∀ (n : ℕ) (f : Fin n → C), HasCoproduct f | 0 => fun _ => letI : HasColimitsOfShape (Discrete (Fin 0)) C := hasColimitsOfShape_of_equivalence (Discrete.equivalence.{0} finZeroEquiv'.symm) inferInstance | n + 1 => fun f => haveI := hasCoproduct_fin n HasColimit.mk ⟨_, extendCofanIsColimit f (colimit.isColimit _) (colimit.isColimit _)⟩ /-- If `C` has an initial object and binary coproducts, then it has finite coproducts. -/ theorem hasFiniteCoproducts_of_has_binary_and_initial : HasFiniteCoproducts C := ⟨fun n => ⟨fun K => letI := hasCoproduct_fin n fun n => K.obj ⟨n⟩ let that : K ≅ Discrete.functor fun n => K.obj ⟨n⟩ := Discrete.natIso fun ⟨_⟩ => Iso.refl _ @hasColimitOfIso _ _ _ _ _ _ this that⟩⟩ end section Preserves variable (F : C ⥤ D) variable [PreservesColimitsOfShape (Discrete WalkingPair) F] variable [PreservesColimitsOfShape (Discrete.{0} PEmpty) F] variable [HasFiniteCoproducts.{v} C] /-- If `F` preserves the initial object and binary coproducts, then it preserves products indexed by `Fin n` for any `n`. -/ noncomputable def preservesFinOfPreservesBinaryAndInitial : ∀ (n : ℕ) (f : Fin n → C), PreservesColimit (Discrete.functor f) F | 0 => fun f => by letI : PreservesColimitsOfShape (Discrete (Fin 0)) F := preservesColimitsOfShapeOfEquiv.{0, 0} (Discrete.equivalence finZeroEquiv'.symm) _ infer_instance | n + 1 => by haveI := preservesFinOfPreservesBinaryAndInitial n intro f apply preservesColimitOfPreservesColimitCocone (extendCofanIsColimit f (colimit.isColimit _) (colimit.isColimit _)) _ apply (isColimitMapCoconeCofanMkEquiv _ _ _).symm _ let this := extendCofanIsColimit (fun i => F.obj (f i)) (isColimitOfHasCoproductOfPreservesColimit F _) (isColimitOfHasBinaryCoproductOfPreservesColimit F _ _) refine IsColimit.ofIsoColimit this ?_ apply Cocones.ext _ _ · apply Iso.refl _ rintro ⟨j⟩ refine Fin.inductionOn j ?_ ?_ · apply Category.comp_id · rintro i _ dsimp [extendCofan_ι_app, Iso.refl_hom, Cofan.mk_ι_app] rw [comp_id, ← F.map_comp] /-- If `F` preserves the initial object and binary coproducts, then it preserves colimits of shape `Discrete (Fin n)`. -/ def preservesShapeFinOfPreservesBinaryAndInitial (n : ℕ) : PreservesColimitsOfShape (Discrete (Fin n)) F where preservesColimit {K} := by let that : (Discrete.functor fun n => K.obj ⟨n⟩) ≅ K := Discrete.natIso fun ⟨i⟩ => Iso.refl _ haveI := preservesFinOfPreservesBinaryAndInitial F n fun n => K.obj ⟨n⟩ apply preservesColimitOfIsoDiagram F that /-- If `F` preserves the initial object and binary coproducts then it preserves finite products. -/ def preservesFiniteCoproductsOfPreservesBinaryAndInitial (J : Type) [Fintype J] : PreservesColimitsOfShape (Discrete J) F := by classical let e := Fintype.equivFin J haveI := preservesShapeFinOfPreservesBinaryAndInitial F (Fintype.card J) apply preservesColimitsOfShapeOfEquiv.{0, 0} (Discrete.equivalence e).symm end Preserves end CategoryTheory
CategoryTheory\Limits\Constructions\LimitsOfProductsAndEqualizers.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Scott Morrison -/ import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Sigma import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts import Mathlib.CategoryTheory.Limits.Constructions.Equalizers import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts /-! # Constructing limits from products and equalizers. If a category has all products, and all equalizers, then it has all limits. Similarly, if it has all finite products, and all equalizers, then it has all finite limits. If a functor preserves all products and equalizers, then it preserves all limits. Similarly, if it preserves all finite products and equalizers, then it preserves all finite limits. ## TODO Provide the dual results. Show the analogous results for functors which reflect or create (co)limits. -/ open CategoryTheory open Opposite namespace CategoryTheory.Limits universe w v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {J : Type w} [SmallCategory J] -- We hide the "implementation details" inside a namespace namespace HasLimitOfHasProductsOfHasEqualizers variable {F : J ⥤ C} {c₁ : Fan F.obj} {c₂ : Fan fun f : Σp : J × J, p.1 ⟶ p.2 => F.obj f.1.2} (s t : c₁.pt ⟶ c₂.pt) /-- (Implementation) Given the appropriate product and equalizer cones, build the cone for `F` which is limiting if the given cones are also. -/ @[simps] def buildLimit (hs : ∀ f : Σp : J × J, p.1 ⟶ p.2, s ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.1⟩ ≫ F.map f.2) (ht : ∀ f : Σp : J × J, p.1 ⟶ p.2, t ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.2⟩) (i : Fork s t) : Cone F where pt := i.pt π := { app := fun j => i.ι ≫ c₁.π.app ⟨_⟩ naturality := fun j₁ j₂ f => by dsimp rw [Category.id_comp, Category.assoc, ← hs ⟨⟨_, _⟩, f⟩, i.condition_assoc, ht] } variable (hs : ∀ f : Σp : J × J, p.1 ⟶ p.2, s ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.1⟩ ≫ F.map f.2) (ht : ∀ f : Σp : J × J, p.1 ⟶ p.2, t ≫ c₂.π.app ⟨f⟩ = c₁.π.app ⟨f.1.2⟩) {i : Fork s t} /-- (Implementation) Show the cone constructed in `buildLimit` is limiting, provided the cones used in its construction are. -/ def buildIsLimit (t₁ : IsLimit c₁) (t₂ : IsLimit c₂) (hi : IsLimit i) : IsLimit (buildLimit s t hs ht i) where lift q := by refine hi.lift (Fork.ofι ?_ ?_) · refine t₁.lift (Fan.mk _ fun j => ?_) apply q.π.app j · apply t₂.hom_ext intro ⟨j⟩ simp [hs, ht] uniq q m w := hi.hom_ext (i.equalizer_ext (t₁.hom_ext fun j => by cases' j with j simpa using w j)) fac s j := by simp end HasLimitOfHasProductsOfHasEqualizers open HasLimitOfHasProductsOfHasEqualizers /-- Given the existence of the appropriate (possibly finite) products and equalizers, we can construct a limit cone for `F`. (This assumes the existence of all equalizers, which is technically stronger than needed.) -/ noncomputable def limitConeOfEqualizerAndProduct (F : J ⥤ C) [HasLimit (Discrete.functor F.obj)] [HasLimit (Discrete.functor fun f : Σp : J × J, p.1 ⟶ p.2 => F.obj f.1.2)] [HasEqualizers C] : LimitCone F where cone := _ isLimit := buildIsLimit (Pi.lift fun f => limit.π (Discrete.functor F.obj) ⟨_⟩ ≫ F.map f.2) (Pi.lift fun f => limit.π (Discrete.functor F.obj) ⟨f.1.2⟩) (by simp) (by simp) (limit.isLimit _) (limit.isLimit _) (limit.isLimit _) /-- Given the existence of the appropriate (possibly finite) products and equalizers, we know a limit of `F` exists. (This assumes the existence of all equalizers, which is technically stronger than needed.) -/ theorem hasLimit_of_equalizer_and_product (F : J ⥤ C) [HasLimit (Discrete.functor F.obj)] [HasLimit (Discrete.functor fun f : Σp : J × J, p.1 ⟶ p.2 => F.obj f.1.2)] [HasEqualizers C] : HasLimit F := HasLimit.mk (limitConeOfEqualizerAndProduct F) /-- A limit can be realised as a subobject of a product. -/ noncomputable def limitSubobjectProduct [HasLimitsOfSize.{w, w} C] (F : J ⥤ C) : limit F ⟶ ∏ᶜ fun j => F.obj j := have := hasFiniteLimits_of_hasLimitsOfSize C (limit.isoLimitCone (limitConeOfEqualizerAndProduct F)).hom ≫ equalizer.ι _ _ instance limitSubobjectProduct_mono [HasLimitsOfSize.{w, w} C] (F : J ⥤ C) : Mono (limitSubobjectProduct F) := mono_comp _ _ /-- Any category with products and equalizers has all limits. See <https://stacks.math.columbia.edu/tag/002N>. -/ theorem has_limits_of_hasEqualizers_and_products [HasProducts.{w} C] [HasEqualizers C] : HasLimitsOfSize.{w, w} C := { has_limits_of_shape := fun _ _ => { has_limit := fun F => hasLimit_of_equalizer_and_product F } } /-- Any category with finite products and equalizers has all finite limits. See <https://stacks.math.columbia.edu/tag/002O>. -/ theorem hasFiniteLimits_of_hasEqualizers_and_finite_products [HasFiniteProducts C] [HasEqualizers C] : HasFiniteLimits C where out _ := { has_limit := fun F => hasLimit_of_equalizer_and_product F } variable {D : Type u₂} [Category.{v₂} D] /- Porting note: Removed this and made whatever necessary noncomputable -/ -- noncomputable section section variable [HasLimitsOfShape (Discrete J) C] [HasLimitsOfShape (Discrete (Σp : J × J, p.1 ⟶ p.2)) C] [HasEqualizers C] variable (G : C ⥤ D) [PreservesLimitsOfShape WalkingParallelPair G] -- [PreservesFiniteProducts G] [PreservesLimitsOfShape (Discrete.{w} J) G] [PreservesLimitsOfShape (Discrete.{w} (Σp : J × J, p.1 ⟶ p.2)) G] /-- If a functor preserves equalizers and the appropriate products, it preserves limits. -/ noncomputable def preservesLimitOfPreservesEqualizersAndProduct : PreservesLimitsOfShape J G where preservesLimit {K} := by let P := ∏ᶜ K.obj let Q := ∏ᶜ fun f : Σp : J × J, p.fst ⟶ p.snd => K.obj f.1.2 let s : P ⟶ Q := Pi.lift fun f => limit.π (Discrete.functor K.obj) ⟨_⟩ ≫ K.map f.2 let t : P ⟶ Q := Pi.lift fun f => limit.π (Discrete.functor K.obj) ⟨f.1.2⟩ let I := equalizer s t let i : I ⟶ P := equalizer.ι s t apply preservesLimitOfPreservesLimitCone (buildIsLimit s t (by simp [s]) (by simp [t]) (limit.isLimit _) (limit.isLimit _) (limit.isLimit _)) apply IsLimit.ofIsoLimit (buildIsLimit _ _ _ _ _ _ _) _ · exact Fan.mk _ fun j => G.map (Pi.π _ j) · exact Fan.mk (G.obj Q) fun f => G.map (Pi.π _ f) · apply G.map s · apply G.map t · intro f dsimp [s, Fan.mk] simp only [← G.map_comp, limit.lift_π] congr · intro f dsimp [t, Fan.mk] simp only [← G.map_comp, limit.lift_π] apply congrArg G.map dsimp · apply Fork.ofι (G.map i) rw [← G.map_comp, ← G.map_comp] apply congrArg G.map exact equalizer.condition s t · apply isLimitOfHasProductOfPreservesLimit · apply isLimitOfHasProductOfPreservesLimit · apply isLimitForkMapOfIsLimit apply equalizerIsEqualizer · refine Cones.ext (Iso.refl _) ?_ intro j; dsimp; simp -- See note [dsimp, simp]. end /- Porting note: the original parameter [∀ (J) [Fintype J], PreservesColimitsOfShape (Discrete.{0} J) G] triggered the error "invalid parametric local instance, parameter with type Fintype J does not have forward dependencies, type class resolution cannot use this kind of local instance because it will not be able to infer a value for this parameter." Factored out this as new class in `CategoryTheory.Limits.Preserves.Finite` -/ /-- If G preserves equalizers and finite products, it preserves finite limits. -/ noncomputable def preservesFiniteLimitsOfPreservesEqualizersAndFiniteProducts [HasEqualizers C] [HasFiniteProducts C] (G : C ⥤ D) [PreservesLimitsOfShape WalkingParallelPair G] [PreservesFiniteProducts G] : PreservesFiniteLimits G where preservesFiniteLimits := by intro J sJ fJ haveI : Fintype J := inferInstance haveI : Fintype ((p : J × J) × (p.fst ⟶ p.snd)) := inferInstance apply @preservesLimitOfPreservesEqualizersAndProduct _ _ _ sJ _ _ ?_ ?_ _ G _ ?_ ?_ · apply hasLimitsOfShape_discrete _ _ · apply hasLimitsOfShape_discrete _ · apply PreservesFiniteProducts.preserves _ · apply PreservesFiniteProducts.preserves _ /-- If G preserves equalizers and products, it preserves all limits. -/ noncomputable def preservesLimitsOfPreservesEqualizersAndProducts [HasEqualizers C] [HasProducts.{w} C] (G : C ⥤ D) [PreservesLimitsOfShape WalkingParallelPair G] [∀ J, PreservesLimitsOfShape (Discrete.{w} J) G] : PreservesLimitsOfSize.{w, w} G where preservesLimitsOfShape := preservesLimitOfPreservesEqualizersAndProduct G theorem hasFiniteLimits_of_hasTerminal_and_pullbacks [HasTerminal C] [HasPullbacks C] : HasFiniteLimits C := @hasFiniteLimits_of_hasEqualizers_and_finite_products C _ (@hasFiniteProducts_of_has_binary_and_terminal C _ (hasBinaryProducts_of_hasTerminal_and_pullbacks C) inferInstance) (@hasEqualizers_of_hasPullbacks_and_binary_products C _ (hasBinaryProducts_of_hasTerminal_and_pullbacks C) inferInstance) /-- If G preserves terminal objects and pullbacks, it preserves all finite limits. -/ noncomputable def preservesFiniteLimitsOfPreservesTerminalAndPullbacks [HasTerminal C] [HasPullbacks C] (G : C ⥤ D) [PreservesLimitsOfShape (Discrete.{0} PEmpty) G] [PreservesLimitsOfShape WalkingCospan G] : PreservesFiniteLimits G := by haveI : HasFiniteLimits C := hasFiniteLimits_of_hasTerminal_and_pullbacks haveI : PreservesLimitsOfShape (Discrete WalkingPair) G := preservesBinaryProductsOfPreservesTerminalAndPullbacks G haveI : PreservesLimitsOfShape WalkingParallelPair G := preservesEqualizersOfPreservesPullbacksAndBinaryProducts G apply @preservesFiniteLimitsOfPreservesEqualizersAndFiniteProducts _ _ _ _ _ _ G _ ?_ apply PreservesFiniteProducts.mk apply preservesFiniteProductsOfPreservesBinaryAndTerminal G /-! We now dualize the above constructions, resorting to copy-paste. -/ -- We hide the "implementation details" inside a namespace namespace HasColimitOfHasCoproductsOfHasCoequalizers variable {F : J ⥤ C} {c₁ : Cofan fun f : Σp : J × J, p.1 ⟶ p.2 => F.obj f.1.1} {c₂ : Cofan F.obj} (s t : c₁.pt ⟶ c₂.pt) /-- (Implementation) Given the appropriate coproduct and coequalizer cocones, build the cocone for `F` which is colimiting if the given cocones are also. -/ @[simps] def buildColimit (hs : ∀ f : Σp : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ s = F.map f.2 ≫ c₂.ι.app ⟨f.1.2⟩) (ht : ∀ f : Σp : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ t = c₂.ι.app ⟨f.1.1⟩) (i : Cofork s t) : Cocone F where pt := i.pt ι := { app := fun j => c₂.ι.app ⟨_⟩ ≫ i.π naturality := fun j₁ j₂ f => by dsimp have reassoced (f : (p : J × J) × (p.fst ⟶ p.snd)) {W : C} {h : _ ⟶ W} : c₁.ι.app ⟨f⟩ ≫ s ≫ h = F.map f.snd ≫ c₂.ι.app ⟨f.fst.snd⟩ ≫ h := by simp only [← Category.assoc, eq_whisker (hs f)] rw [Category.comp_id, ← reassoced ⟨⟨_, _⟩, f⟩, i.condition, ← Category.assoc, ht] } variable (hs : ∀ f : Σp : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ s = F.map f.2 ≫ c₂.ι.app ⟨f.1.2⟩) (ht : ∀ f : Σp : J × J, p.1 ⟶ p.2, c₁.ι.app ⟨f⟩ ≫ t = c₂.ι.app ⟨f.1.1⟩) {i : Cofork s t} /-- (Implementation) Show the cocone constructed in `buildColimit` is colimiting, provided the cocones used in its construction are. -/ def buildIsColimit (t₁ : IsColimit c₁) (t₂ : IsColimit c₂) (hi : IsColimit i) : IsColimit (buildColimit s t hs ht i) where desc q := by refine hi.desc (Cofork.ofπ ?_ ?_) · refine t₂.desc (Cofan.mk _ fun j => ?_) apply q.ι.app j · apply t₁.hom_ext intro j cases' j with j have reassoced_s (f : (p : J × J) × (p.fst ⟶ p.snd)) {W : C} (h : _ ⟶ W) : c₁.ι.app ⟨f⟩ ≫ s ≫ h = F.map f.snd ≫ c₂.ι.app ⟨f.fst.snd⟩ ≫ h := by simp only [← Category.assoc] apply eq_whisker (hs f) have reassoced_t (f : (p : J × J) × (p.fst ⟶ p.snd)) {W : C} (h : _ ⟶ W) : c₁.ι.app ⟨f⟩ ≫ t ≫ h = c₂.ι.app ⟨f.fst.fst⟩ ≫ h := by simp only [← Category.assoc] apply eq_whisker (ht f) simp [reassoced_s, reassoced_t] uniq q m w := hi.hom_ext (i.coequalizer_ext (t₂.hom_ext fun j => by cases' j with j simpa using w j)) fac s j := by simp end HasColimitOfHasCoproductsOfHasCoequalizers open HasColimitOfHasCoproductsOfHasCoequalizers /-- Given the existence of the appropriate (possibly finite) coproducts and coequalizers, we can construct a colimit cocone for `F`. (This assumes the existence of all coequalizers, which is technically stronger than needed.) -/ noncomputable def colimitCoconeOfCoequalizerAndCoproduct (F : J ⥤ C) [HasColimit (Discrete.functor F.obj)] [HasColimit (Discrete.functor fun f : Σp : J × J, p.1 ⟶ p.2 => F.obj f.1.1)] [HasCoequalizers C] : ColimitCocone F where cocone := _ isColimit := buildIsColimit (Sigma.desc fun f => F.map f.2 ≫ colimit.ι (Discrete.functor F.obj) ⟨f.1.2⟩) (Sigma.desc fun f => colimit.ι (Discrete.functor F.obj) ⟨f.1.1⟩) (by simp) (by simp) (colimit.isColimit _) (colimit.isColimit _) (colimit.isColimit _) /-- Given the existence of the appropriate (possibly finite) coproducts and coequalizers, we know a colimit of `F` exists. (This assumes the existence of all coequalizers, which is technically stronger than needed.) -/ theorem hasColimit_of_coequalizer_and_coproduct (F : J ⥤ C) [HasColimit (Discrete.functor F.obj)] [HasColimit (Discrete.functor fun f : Σp : J × J, p.1 ⟶ p.2 => F.obj f.1.1)] [HasCoequalizers C] : HasColimit F := HasColimit.mk (colimitCoconeOfCoequalizerAndCoproduct F) /-- A colimit can be realised as a quotient of a coproduct. -/ noncomputable def colimitQuotientCoproduct [HasColimitsOfSize.{w, w} C] (F : J ⥤ C) : ∐ (fun j => F.obj j) ⟶ colimit F := have := hasFiniteColimits_of_hasColimitsOfSize C coequalizer.π _ _ ≫ (colimit.isoColimitCocone (colimitCoconeOfCoequalizerAndCoproduct F)).inv instance colimitQuotientCoproduct_epi [HasColimitsOfSize.{w, w} C] (F : J ⥤ C) : Epi (colimitQuotientCoproduct F) := epi_comp _ _ /-- Any category with coproducts and coequalizers has all colimits. See <https://stacks.math.columbia.edu/tag/002P>. -/ theorem has_colimits_of_hasCoequalizers_and_coproducts [HasCoproducts.{w} C] [HasCoequalizers C] : HasColimitsOfSize.{w, w} C where has_colimits_of_shape := fun _ _ => { has_colimit := fun F => hasColimit_of_coequalizer_and_coproduct F } /-- Any category with finite coproducts and coequalizers has all finite colimits. See <https://stacks.math.columbia.edu/tag/002Q>. -/ theorem hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts [HasFiniteCoproducts C] [HasCoequalizers C] : HasFiniteColimits C where out _ := { has_colimit := fun F => hasColimit_of_coequalizer_and_coproduct F } -- Porting note: removed and added individually -- noncomputable section section variable [HasColimitsOfShape (Discrete.{w} J) C] [HasColimitsOfShape (Discrete.{w} (Σp : J × J, p.1 ⟶ p.2)) C] [HasCoequalizers C] variable (G : C ⥤ D) [PreservesColimitsOfShape WalkingParallelPair G] [PreservesColimitsOfShape (Discrete.{w} J) G] [PreservesColimitsOfShape (Discrete.{w} (Σp : J × J, p.1 ⟶ p.2)) G] /-- If a functor preserves coequalizers and the appropriate coproducts, it preserves colimits. -/ noncomputable def preservesColimitOfPreservesCoequalizersAndCoproduct : PreservesColimitsOfShape J G where preservesColimit {K} := by let P := ∐ K.obj let Q := ∐ fun f : Σp : J × J, p.fst ⟶ p.snd => K.obj f.1.1 let s : Q ⟶ P := Sigma.desc fun f => K.map f.2 ≫ colimit.ι (Discrete.functor K.obj) ⟨_⟩ let t : Q ⟶ P := Sigma.desc fun f => colimit.ι (Discrete.functor K.obj) ⟨f.1.1⟩ let I := coequalizer s t let i : P ⟶ I := coequalizer.π s t apply preservesColimitOfPreservesColimitCocone (buildIsColimit s t (by simp [s]) (by simp [t]) (colimit.isColimit _) (colimit.isColimit _) (colimit.isColimit _)) apply IsColimit.ofIsoColimit (buildIsColimit _ _ _ _ _ _ _) _ · refine Cofan.mk (G.obj Q) fun j => G.map ?_ apply Sigma.ι _ j -- fun j => G.map (Sigma.ι _ j) · exact Cofan.mk _ fun f => G.map (Sigma.ι _ f) · apply G.map s · apply G.map t · intro f dsimp [s, Cofan.mk] simp only [← G.map_comp, colimit.ι_desc] congr · intro f dsimp [t, Cofan.mk] simp only [← G.map_comp, colimit.ι_desc] dsimp · refine Cofork.ofπ (G.map i) ?_ rw [← G.map_comp, ← G.map_comp] apply congrArg G.map apply coequalizer.condition · apply isColimitOfHasCoproductOfPreservesColimit · apply isColimitOfHasCoproductOfPreservesColimit · apply isColimitCoforkMapOfIsColimit apply coequalizerIsCoequalizer refine Cocones.ext (Iso.refl _) ?_ intro j dsimp simp -- See note [dsimp, simp]. end /- Porting note: the original parameter [∀ (J) [Fintype J], PreservesColimitsOfShape (Discrete.{0} J) G] triggered the error "invalid parametric local instance, parameter with type Fintype J does not have forward dependencies, type class resolution cannot use this kind of local instance because it will not be able to infer a value for this parameter." Factored out this as new class in `CategoryTheory.Limits.Preserves.Finite` -/ /-- If G preserves coequalizers and finite coproducts, it preserves finite colimits. -/ noncomputable def preservesFiniteColimitsOfPreservesCoequalizersAndFiniteCoproducts [HasCoequalizers C] [HasFiniteCoproducts C] (G : C ⥤ D) [PreservesColimitsOfShape WalkingParallelPair G] [PreservesFiniteCoproducts G] : PreservesFiniteColimits G where preservesFiniteColimits := by intro J sJ fJ haveI : Fintype J := inferInstance haveI : Fintype ((p : J × J) × (p.fst ⟶ p.snd)) := inferInstance apply @preservesColimitOfPreservesCoequalizersAndCoproduct _ _ _ sJ _ _ ?_ ?_ _ G _ ?_ ?_ · apply hasColimitsOfShape_discrete _ _ · apply hasColimitsOfShape_discrete _ · apply PreservesFiniteCoproducts.preserves _ · apply PreservesFiniteCoproducts.preserves _ /-- If G preserves coequalizers and coproducts, it preserves all colimits. -/ noncomputable def preservesColimitsOfPreservesCoequalizersAndCoproducts [HasCoequalizers C] [HasCoproducts.{w} C] (G : C ⥤ D) [PreservesColimitsOfShape WalkingParallelPair G] [∀ J, PreservesColimitsOfShape (Discrete.{w} J) G] : PreservesColimitsOfSize.{w} G where preservesColimitsOfShape := preservesColimitOfPreservesCoequalizersAndCoproduct G theorem hasFiniteColimits_of_hasInitial_and_pushouts [HasInitial C] [HasPushouts C] : HasFiniteColimits C := @hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts C _ (@hasFiniteCoproducts_of_has_binary_and_initial C _ (hasBinaryCoproducts_of_hasInitial_and_pushouts C) inferInstance) (@hasCoequalizers_of_hasPushouts_and_binary_coproducts C _ (hasBinaryCoproducts_of_hasInitial_and_pushouts C) inferInstance) /-- If G preserves initial objects and pushouts, it preserves all finite colimits. -/ noncomputable def preservesFiniteColimitsOfPreservesInitialAndPushouts [HasInitial C] [HasPushouts C] (G : C ⥤ D) [PreservesColimitsOfShape (Discrete.{0} PEmpty) G] [PreservesColimitsOfShape WalkingSpan G] : PreservesFiniteColimits G := by haveI : HasFiniteColimits C := hasFiniteColimits_of_hasInitial_and_pushouts haveI : PreservesColimitsOfShape (Discrete WalkingPair) G := preservesBinaryCoproductsOfPreservesInitialAndPushouts G haveI : PreservesColimitsOfShape (WalkingParallelPair) G := (preservesCoequalizersOfPreservesPushoutsAndBinaryCoproducts G) refine @preservesFiniteColimitsOfPreservesCoequalizersAndFiniteCoproducts _ _ _ _ _ _ G _ ?_ apply PreservesFiniteCoproducts.mk apply preservesFiniteCoproductsOfPreservesBinaryAndInitial G end CategoryTheory.Limits
CategoryTheory\Limits\Constructions\Pullbacks.lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Constructing pullbacks from binary products and equalizers If a category as binary products and equalizers, then it has pullbacks. Also, if a category has binary coproducts and coequalizers, then it has pushouts -/ universe v u open CategoryTheory namespace CategoryTheory.Limits /-- If the product `X ⨯ Y` and the equalizer of `π₁ ≫ f` and `π₂ ≫ g` exist, then the pullback of `f` and `g` exists: It is given by composing the equalizer with the projections. -/ theorem hasLimit_cospan_of_hasLimit_pair_of_hasLimit_parallelPair {C : Type u} [𝒞 : Category.{v} C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (pair X Y)] [HasLimit (parallelPair (prod.fst ≫ f) (prod.snd ≫ g))] : HasLimit (cospan f g) := let π₁ : X ⨯ Y ⟶ X := prod.fst let π₂ : X ⨯ Y ⟶ Y := prod.snd let e := equalizer.ι (π₁ ≫ f) (π₂ ≫ g) HasLimit.mk { cone := PullbackCone.mk (e ≫ π₁) (e ≫ π₂) <| by rw [Category.assoc, equalizer.condition]; simp isLimit := PullbackCone.IsLimit.mk _ (fun s => equalizer.lift (prod.lift (s.π.app WalkingCospan.left) (s.π.app WalkingCospan.right)) <| by rw [← Category.assoc, limit.lift_π, ← Category.assoc, limit.lift_π] exact PullbackCone.condition _) (by simp [π₁, e]) (by simp [π₂, e]) fun s m h₁ h₂ => by ext · dsimp; simpa using h₁ · simpa using h₂ } section attribute [local instance] hasLimit_cospan_of_hasLimit_pair_of_hasLimit_parallelPair /-- If a category has all binary products and all equalizers, then it also has all pullbacks. As usual, this is not an instance, since there may be a more direct way to construct pullbacks. -/ theorem hasPullbacks_of_hasBinaryProducts_of_hasEqualizers (C : Type u) [Category.{v} C] [HasBinaryProducts C] [HasEqualizers C] : HasPullbacks C := { has_limit := fun F => hasLimitOfIso (diagramIsoCospan F).symm } end /-- If the coproduct `Y ⨿ Z` and the coequalizer of `f ≫ ι₁` and `g ≫ ι₂` exist, then the pushout of `f` and `g` exists: It is given by composing the inclusions with the coequalizer. -/ theorem hasColimit_span_of_hasColimit_pair_of_hasColimit_parallelPair {C : Type u} [𝒞 : Category.{v} C] {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasColimit (pair Y Z)] [HasColimit (parallelPair (f ≫ coprod.inl) (g ≫ coprod.inr))] : HasColimit (span f g) := let ι₁ : Y ⟶ Y ⨿ Z := coprod.inl let ι₂ : Z ⟶ Y ⨿ Z := coprod.inr let c := coequalizer.π (f ≫ ι₁) (g ≫ ι₂) HasColimit.mk { cocone := PushoutCocone.mk (ι₁ ≫ c) (ι₂ ≫ c) <| by rw [← Category.assoc, ← Category.assoc, coequalizer.condition] isColimit := PushoutCocone.IsColimit.mk _ (fun s => coequalizer.desc (coprod.desc (s.ι.app WalkingSpan.left) (s.ι.app WalkingSpan.right)) <| by rw [Category.assoc, colimit.ι_desc, Category.assoc, colimit.ι_desc] exact PushoutCocone.condition _) (by simp [ι₁, c]) (by simp [ι₂, c]) fun s m h₁ h₂ => by ext · simpa using h₁ · simpa using h₂ } section attribute [local instance] hasColimit_span_of_hasColimit_pair_of_hasColimit_parallelPair /-- If a category has all binary coproducts and all coequalizers, then it also has all pushouts. As usual, this is not an instance, since there may be a more direct way to construct pushouts. -/ theorem hasPushouts_of_hasBinaryCoproducts_of_hasCoequalizers (C : Type u) [Category.{v} C] [HasBinaryCoproducts C] [HasCoequalizers C] : HasPushouts C := hasPushouts_of_hasColimit_span C end end CategoryTheory.Limits
CategoryTheory\Limits\Constructions\WeaklyInitial.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.WideEqualizers import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Constructions related to weakly initial objects This file gives constructions related to weakly initial objects, namely: * If a category has small products and a small weakly initial set of objects, then it has a weakly initial object. * If a category has wide equalizers and a weakly initial object, then it has an initial object. These are primarily useful to show the General Adjoint Functor Theorem. -/ universe v u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] /-- If `C` has (small) products and a small weakly initial set of objects, then it has a weakly initial object. -/ theorem has_weakly_initial_of_weakly_initial_set_and_hasProducts [HasProducts.{v} C] {ι : Type v} {B : ι → C} (hB : ∀ A : C, ∃ i, Nonempty (B i ⟶ A)) : ∃ T : C, ∀ X, Nonempty (T ⟶ X) := ⟨∏ᶜ B, fun X => ⟨Pi.π _ _ ≫ (hB X).choose_spec.some⟩⟩ /-- If `C` has (small) wide equalizers and a weakly initial object, then it has an initial object. The initial object is constructed as the wide equalizer of all endomorphisms on the given weakly initial object. -/ theorem hasInitial_of_weakly_initial_and_hasWideEqualizers [HasWideEqualizers.{v} C] {T : C} (hT : ∀ X, Nonempty (T ⟶ X)) : HasInitial C := by let endos := T ⟶ T let i := wideEqualizer.ι (id : endos → endos) haveI : Nonempty endos := ⟨𝟙 _⟩ have : ∀ X : C, Unique (wideEqualizer (id : endos → endos) ⟶ X) := by intro X refine ⟨⟨i ≫ Classical.choice (hT X)⟩, fun a => ?_⟩ let E := equalizer a (i ≫ Classical.choice (hT _)) let e : E ⟶ wideEqualizer id := equalizer.ι _ _ let h : T ⟶ E := Classical.choice (hT E) have : ((i ≫ h) ≫ e) ≫ i = i ≫ 𝟙 _ := by rw [Category.assoc, Category.assoc] apply wideEqualizer.condition (id : endos → endos) (h ≫ e ≫ i) rw [Category.comp_id, cancel_mono_id i] at this haveI : IsSplitEpi e := IsSplitEpi.mk' ⟨i ≫ h, this⟩ rw [← cancel_epi e] apply equalizer.condition exact hasInitial_of_unique (wideEqualizer (id : endos → endos)) end CategoryTheory
CategoryTheory\Limits\Constructions\ZeroObjects.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts /-! # Limits involving zero objects Binary products and coproducts with a zero object always exist, and pullbacks/pushouts over a zero object are products/coproducts. -/ noncomputable section open CategoryTheory variable {C : Type*} [Category C] namespace CategoryTheory.Limits variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The limit cone for the product with a zero object. -/ def binaryFanZeroLeft (X : C) : BinaryFan (0 : C) X := BinaryFan.mk 0 (𝟙 X) /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroLeftIsLimit (X : C) : IsLimit (binaryFanZeroLeft X) := BinaryFan.isLimitMk (fun s => BinaryFan.snd s) (by aesop_cat) (by aesop_cat) (fun s m _ h₂ => by simpa using h₂) instance hasBinaryProduct_zero_left (X : C) : HasBinaryProduct (0 : C) X := HasLimit.mk ⟨_, binaryFanZeroLeftIsLimit X⟩ /-- A zero object is a left unit for categorical product. -/ def zeroProdIso (X : C) : (0 : C) ⨯ X ≅ X := limit.isoLimitCone ⟨_, binaryFanZeroLeftIsLimit X⟩ @[simp] theorem zeroProdIso_hom (X : C) : (zeroProdIso X).hom = prod.snd := rfl @[simp] theorem zeroProdIso_inv_snd (X : C) : (zeroProdIso X).inv ≫ prod.snd = 𝟙 X := by dsimp [zeroProdIso, binaryFanZeroLeft] simp /-- The limit cone for the product with a zero object. -/ def binaryFanZeroRight (X : C) : BinaryFan X (0 : C) := BinaryFan.mk (𝟙 X) 0 /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroRightIsLimit (X : C) : IsLimit (binaryFanZeroRight X) := BinaryFan.isLimitMk (fun s => BinaryFan.fst s) (by aesop_cat) (by aesop_cat) (fun s m h₁ _ => by simpa using h₁) instance hasBinaryProduct_zero_right (X : C) : HasBinaryProduct X (0 : C) := HasLimit.mk ⟨_, binaryFanZeroRightIsLimit X⟩ /-- A zero object is a right unit for categorical product. -/ def prodZeroIso (X : C) : X ⨯ (0 : C) ≅ X := limit.isoLimitCone ⟨_, binaryFanZeroRightIsLimit X⟩ @[simp] theorem prodZeroIso_hom (X : C) : (prodZeroIso X).hom = prod.fst := rfl @[simp] theorem prodZeroIso_iso_inv_snd (X : C) : (prodZeroIso X).inv ≫ prod.fst = 𝟙 X := by dsimp [prodZeroIso, binaryFanZeroRight] simp /-- The colimit cocone for the coproduct with a zero object. -/ def binaryCofanZeroLeft (X : C) : BinaryCofan (0 : C) X := BinaryCofan.mk 0 (𝟙 X) /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binaryCofanZeroLeftIsColimit (X : C) : IsColimit (binaryCofanZeroLeft X) := BinaryCofan.isColimitMk (fun s => BinaryCofan.inr s) (by aesop_cat) (by aesop_cat) (fun s m _ h₂ => by simpa using h₂) instance hasBinaryCoproduct_zero_left (X : C) : HasBinaryCoproduct (0 : C) X := HasColimit.mk ⟨_, binaryCofanZeroLeftIsColimit X⟩ /-- A zero object is a left unit for categorical coproduct. -/ def zeroCoprodIso (X : C) : (0 : C) ⨿ X ≅ X := colimit.isoColimitCocone ⟨_, binaryCofanZeroLeftIsColimit X⟩ @[simp] theorem inr_zeroCoprodIso_hom (X : C) : coprod.inr ≫ (zeroCoprodIso X).hom = 𝟙 X := by dsimp [zeroCoprodIso, binaryCofanZeroLeft] simp @[simp] theorem zeroCoprodIso_inv (X : C) : (zeroCoprodIso X).inv = coprod.inr := rfl /-- The colimit cocone for the coproduct with a zero object. -/ def binaryCofanZeroRight (X : C) : BinaryCofan X (0 : C) := BinaryCofan.mk (𝟙 X) 0 /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binaryCofanZeroRightIsColimit (X : C) : IsColimit (binaryCofanZeroRight X) := BinaryCofan.isColimitMk (fun s => BinaryCofan.inl s) (by aesop_cat) (by aesop_cat) (fun s m h₁ _ => by simpa using h₁) instance hasBinaryCoproduct_zero_right (X : C) : HasBinaryCoproduct X (0 : C) := HasColimit.mk ⟨_, binaryCofanZeroRightIsColimit X⟩ /-- A zero object is a right unit for categorical coproduct. -/ def coprodZeroIso (X : C) : X ⨿ (0 : C) ≅ X := colimit.isoColimitCocone ⟨_, binaryCofanZeroRightIsColimit X⟩ @[simp] theorem inr_coprodZeroIso_hom (X : C) : coprod.inl ≫ (coprodZeroIso X).hom = 𝟙 X := by dsimp [coprodZeroIso, binaryCofanZeroRight] simp @[simp] theorem coprodZeroIso_inv (X : C) : (coprodZeroIso X).inv = coprod.inl := rfl instance hasPullback_over_zero (X Y : C) [HasBinaryProduct X Y] : HasPullback (0 : X ⟶ 0) (0 : Y ⟶ 0) := HasLimit.mk ⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩ /-- The pullback over the zero object is the product. -/ def pullbackZeroZeroIso (X Y : C) [HasBinaryProduct X Y] : pullback (0 : X ⟶ 0) (0 : Y ⟶ 0) ≅ X ⨯ Y := limit.isoLimitCone ⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩ @[simp] theorem pullbackZeroZeroIso_inv_fst (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).inv ≫ pullback.fst 0 0 = prod.fst := by dsimp [pullbackZeroZeroIso] simp @[simp] theorem pullbackZeroZeroIso_inv_snd (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).inv ≫ pullback.snd 0 0 = prod.snd := by dsimp [pullbackZeroZeroIso] simp @[simp] theorem pullbackZeroZeroIso_hom_fst (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).hom ≫ prod.fst = pullback.fst 0 0 := by simp [← Iso.eq_inv_comp] @[simp] theorem pullbackZeroZeroIso_hom_snd (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).hom ≫ prod.snd = pullback.snd 0 0 := by simp [← Iso.eq_inv_comp] instance hasPushout_over_zero (X Y : C) [HasBinaryCoproduct X Y] : HasPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) := HasColimit.mk ⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩ /-- The pushout over the zero object is the coproduct. -/ def pushoutZeroZeroIso (X Y : C) [HasBinaryCoproduct X Y] : pushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) ≅ X ⨿ Y := colimit.isoColimitCocone ⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩ @[simp] theorem inl_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] : pushout.inl _ _ ≫ (pushoutZeroZeroIso X Y).hom = coprod.inl := by dsimp [pushoutZeroZeroIso] simp @[simp] theorem inr_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] : pushout.inr _ _ ≫ (pushoutZeroZeroIso X Y).hom = coprod.inr := by dsimp [pushoutZeroZeroIso] simp @[simp] theorem inl_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] : coprod.inl ≫ (pushoutZeroZeroIso X Y).inv = pushout.inl _ _ := by simp [Iso.comp_inv_eq] @[simp] theorem inr_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] : coprod.inr ≫ (pushoutZeroZeroIso X Y).inv = pushout.inr _ _ := by simp [Iso.comp_inv_eq] end CategoryTheory.Limits
CategoryTheory\Limits\Constructions\Over\Basic.lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Connected import Mathlib.CategoryTheory.Limits.Constructions.Over.Products import Mathlib.CategoryTheory.Limits.Constructions.Over.Connected import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Limits.Constructions.Equalizers /-! # Limits in the over category Declare instances for limits in the over category: If `C` has finite wide pullbacks, `Over B` has finite limits, and if `C` has arbitrary wide pullbacks then `Over B` has limits. -/ universe w v u -- morphism levels before object levels. See note [category_theory universes]. open CategoryTheory CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {X : C} namespace CategoryTheory.Over /-- Make sure we can derive pullbacks in `Over B`. -/ instance {B : C} [HasPullbacks C] : HasPullbacks (Over B) := by letI : HasLimitsOfShape (ULiftHom.{v} (ULift.{v} WalkingCospan)) C := hasLimitsOfShape_of_equivalence (ULiftHomULiftCategory.equiv.{v} _) letI : Category (ULiftHom.{v} (ULift.{v} WalkingCospan)) := inferInstance exact hasLimitsOfShape_of_equivalence (ULiftHomULiftCategory.equiv.{v, v} _).symm /-- Make sure we can derive equalizers in `Over B`. -/ instance {B : C} [HasEqualizers C] : HasEqualizers (Over B) := by letI : HasLimitsOfShape (ULiftHom.{v} (ULift.{v} WalkingParallelPair)) C := hasLimitsOfShape_of_equivalence (ULiftHomULiftCategory.equiv.{v} _) letI : Category (ULiftHom.{v} (ULift.{v} WalkingParallelPair)) := inferInstance exact hasLimitsOfShape_of_equivalence (ULiftHomULiftCategory.equiv.{v, v} _).symm instance hasFiniteLimits {B : C} [HasFiniteWidePullbacks C] : HasFiniteLimits (Over B) := by apply @hasFiniteLimits_of_hasEqualizers_and_finite_products _ _ ?_ ?_ · exact ConstructProducts.over_finiteProducts_of_finiteWidePullbacks · apply @hasEqualizers_of_hasPullbacks_and_binary_products _ _ ?_ _ haveI : HasPullbacks C := ⟨inferInstance⟩ exact ConstructProducts.over_binaryProduct_of_pullback instance hasLimits {B : C} [HasWidePullbacks.{w} C] : HasLimitsOfSize.{w, w} (Over B) := by apply @has_limits_of_hasEqualizers_and_products _ _ ?_ ?_ · exact ConstructProducts.over_products_of_widePullbacks · apply @hasEqualizers_of_hasPullbacks_and_binary_products _ _ ?_ _ haveI : HasPullbacks C := ⟨inferInstance⟩ exact ConstructProducts.over_binaryProduct_of_pullback end CategoryTheory.Over
CategoryTheory\Limits\Constructions\Over\Connected.lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.IsConnected /-! # Connected limits in the over category Shows that the forgetful functor `Over B ⥤ C` creates connected limits, in particular `Over B` has any connected limit which `C` has. -/ universe v u -- morphism levels before object levels. See note [CategoryTheory universes]. noncomputable section open CategoryTheory CategoryTheory.Limits variable {J : Type v} [SmallCategory J] variable {C : Type u} [Category.{v} C] variable {X : C} namespace CategoryTheory.Over namespace CreatesConnected /-- (Impl) Given a diagram in the over category, produce a natural transformation from the diagram legs to the specific object. -/ def natTransInOver {B : C} (F : J ⥤ Over B) : F ⋙ forget B ⟶ (CategoryTheory.Functor.const J).obj B where app j := (F.obj j).hom /-- (Impl) Given a cone in the base category, raise it to a cone in the over category. Note this is where the connected assumption is used. -/ @[simps] def raiseCone [IsConnected J] {B : C} {F : J ⥤ Over B} (c : Cone (F ⋙ forget B)) : Cone F where pt := Over.mk (c.π.app (Classical.arbitrary J) ≫ (F.obj (Classical.arbitrary J)).hom) π := { app := fun j => Over.homMk (c.π.app j) (nat_trans_from_is_connected (c.π ≫ natTransInOver F) j _) naturality := by intro X Y f apply CommaMorphism.ext · simpa using (c.w f).symm · simp } theorem raised_cone_lowers_to_original [IsConnected J] {B : C} {F : J ⥤ Over B} (c : Cone (F ⋙ forget B)) : (forget B).mapCone (raiseCone c) = c := by aesop_cat /-- (Impl) Show that the raised cone is a limit. -/ def raisedConeIsLimit [IsConnected J] {B : C} {F : J ⥤ Over B} {c : Cone (F ⋙ forget B)} (t : IsLimit c) : IsLimit (raiseCone c) where lift s := Over.homMk (t.lift ((forget B).mapCone s)) uniq s m K := by ext1 apply t.hom_ext intro j simp [← K j] end CreatesConnected /-- The forgetful functor from the over category creates any connected limit. -/ instance forgetCreatesConnectedLimits [IsConnected J] {B : C} : CreatesLimitsOfShape J (forget B) where CreatesLimit := createsLimitOfReflectsIso fun c t => { liftedCone := CreatesConnected.raiseCone c validLift := eqToIso (CreatesConnected.raised_cone_lowers_to_original c) makesLimit := CreatesConnected.raisedConeIsLimit t } /-- The over category has any connected limit which the original category has. -/ instance has_connected_limits {B : C} [IsConnected J] [HasLimitsOfShape J C] : HasLimitsOfShape J (Over B) where has_limit F := hasLimit_of_created F (forget B) end CategoryTheory.Over
CategoryTheory\Limits\Constructions\Over\Products.lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Products in the over category Shows that products in the over category can be derived from wide pullbacks in the base category. The main result is `over_product_of_widePullback`, which says that if `C` has `J`-indexed wide pullbacks, then `Over B` has `J`-indexed products. -/ universe w v u -- morphism levels before object levels. See note [category_theory universes]. open CategoryTheory CategoryTheory.Limits variable {J : Type w} variable {C : Type u} [Category.{v} C] variable {X : C} namespace CategoryTheory.Over namespace ConstructProducts /-- (Implementation) Given a product diagram in `C/B`, construct the corresponding wide pullback diagram in `C`. -/ abbrev widePullbackDiagramOfDiagramOver (B : C) {J : Type w} (F : Discrete J ⥤ Over B) : WidePullbackShape J ⥤ C := WidePullbackShape.wideCospan B (fun j => (F.obj ⟨j⟩).left) fun j => (F.obj ⟨j⟩).hom /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def conesEquivInverseObj (B : C) {J : Type w} (F : Discrete J ⥤ Over B) (c : Cone F) : Cone (widePullbackDiagramOfDiagramOver B F) where pt := c.pt.left π := { app := fun X => Option.casesOn X c.pt.hom fun j : J => (c.π.app ⟨j⟩).left -- `tidy` can do this using `case_bash`, but let's try to be a good `-T50000` citizen: naturality := fun X Y f => by dsimp; cases X <;> cases Y <;> cases f · rw [Category.id_comp, Category.comp_id] · rw [Over.w, Category.id_comp] · rw [Category.id_comp, Category.comp_id] } /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def conesEquivInverse (B : C) {J : Type w} (F : Discrete J ⥤ Over B) : Cone F ⥤ Cone (widePullbackDiagramOfDiagramOver B F) where obj := conesEquivInverseObj B F map f := { hom := f.hom.left w := fun j => by cases' j with j · simp · dsimp rw [← f.w ⟨j⟩] rfl } -- Porting note: this should help with the additional `naturality` proof we now have to give in -- `conesEquivFunctor`, but doesn't. -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Discrete /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simps] def conesEquivFunctor (B : C) {J : Type w} (F : Discrete J ⥤ Over B) : Cone (widePullbackDiagramOfDiagramOver B F) ⥤ Cone F where obj c := { pt := Over.mk (c.π.app none) π := { app := fun ⟨j⟩ => Over.homMk (c.π.app (some j)) (c.w (WidePullbackShape.Hom.term j)) -- Porting note (#10888): added proof for `naturality` naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨f⟩⟩ => by dsimp at f ⊢; aesop_cat } } map f := { hom := Over.homMk f.hom } -- Porting note: unfortunately `aesop` can't cope with a `cases` rule here for the type synonym -- `WidePullbackShape`. -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] WidePullbackShape -- If this worked we could avoid the `rintro` in `conesEquivUnitIso`. /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simp] def conesEquivUnitIso (B : C) (F : Discrete J ⥤ Over B) : 𝟭 (Cone (widePullbackDiagramOfDiagramOver B F)) ≅ conesEquivFunctor B F ⋙ conesEquivInverse B F := NatIso.ofComponents fun _ => Cones.ext { hom := 𝟙 _ inv := 𝟙 _ } (by rintro (j | j) <;> aesop_cat) -- TODO: Can we add `:= by aesop` to the second arguments of `NatIso.ofComponents` and -- `Cones.ext`? /-- (Impl) A preliminary definition to avoid timeouts. -/ @[simp] def conesEquivCounitIso (B : C) (F : Discrete J ⥤ Over B) : conesEquivInverse B F ⋙ conesEquivFunctor B F ≅ 𝟭 (Cone F) := NatIso.ofComponents fun _ => Cones.ext { hom := Over.homMk (𝟙 _) inv := Over.homMk (𝟙 _) } /-- (Impl) Establish an equivalence between the category of cones for `F` and for the "grown" `F`. -/ @[simps] def conesEquiv (B : C) (F : Discrete J ⥤ Over B) : Cone (widePullbackDiagramOfDiagramOver B F) ≌ Cone F where functor := conesEquivFunctor B F inverse := conesEquivInverse B F unitIso := conesEquivUnitIso B F counitIso := conesEquivCounitIso B F /-- Use the above equivalence to prove we have a limit. -/ theorem has_over_limit_discrete_of_widePullback_limit {B : C} (F : Discrete J ⥤ Over B) [HasLimit (widePullbackDiagramOfDiagramOver B F)] : HasLimit F := HasLimit.mk { cone := _ isLimit := IsLimit.ofRightAdjoint (conesEquiv B F).symm.toAdjunction (limit.isLimit (widePullbackDiagramOfDiagramOver B F)) } /-- Given a wide pullback in `C`, construct a product in `C/B`. -/ theorem over_product_of_widePullback [HasLimitsOfShape (WidePullbackShape J) C] {B : C} : HasLimitsOfShape (Discrete J) (Over B) := { has_limit := fun F => has_over_limit_discrete_of_widePullback_limit F } /-- Given a pullback in `C`, construct a binary product in `C/B`. -/ theorem over_binaryProduct_of_pullback [HasPullbacks C] {B : C} : HasBinaryProducts (Over B) := over_product_of_widePullback /-- Given all wide pullbacks in `C`, construct products in `C/B`. -/ theorem over_products_of_widePullbacks [HasWidePullbacks.{w} C] {B : C} : HasProducts.{w} (Over B) := fun _ => over_product_of_widePullback /-- Given all finite wide pullbacks in `C`, construct finite products in `C/B`. -/ theorem over_finiteProducts_of_finiteWidePullbacks [HasFiniteWidePullbacks C] {B : C} : HasFiniteProducts (Over B) := ⟨fun _ => over_product_of_widePullback⟩ end ConstructProducts /-- Construct terminal object in the over category. This isn't an instance as it's not typically the way we want to define terminal objects. (For instance, this gives a terminal object which is different from the generic one given by `over_product_of_widePullback` above.) -/ theorem over_hasTerminal (B : C) : HasTerminal (Over B) where has_limit F := HasLimit.mk { cone := { pt := Over.mk (𝟙 _) π := { app := fun p => p.as.elim } } isLimit := { lift := fun s => Over.homMk s.pt.hom fac := fun _ j => j.as.elim uniq := fun s m _ => by simp only ext rw [Over.homMk_left _] have := m.w dsimp at this rwa [Category.comp_id, Category.comp_id] at this } } end CategoryTheory.Over
CategoryTheory\Limits\Final\ParallelPair.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Joël Riou -/ 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
CategoryTheory\Limits\Indization\IndObject.lean
/- Copyright (c) 2024 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.FinallySmall import Mathlib.CategoryTheory.Limits.Presheaf import Mathlib.CategoryTheory.Filtered.Small /-! # Ind-objects For a presheaf `A : Cᵒᵖ ⥤ Type v` we define the type `IndObjectPresentation A` of presentations of `A` as a small filtered colimit of representable presheaves and define the predicate `IsIndObject A` asserting that there is at least one such presentation. A presheaf is an ind-object if and only if the category `CostructuredArrow yoneda A` is filtered and finally small. In this way, `CostructuredArrow yoneda A` can be thought of the universal indexing category for the representation of `A` as a small filtered colimit of representable presheaves. ## Future work There are various useful ways to understand natural transformations between ind-objects in terms of their presentations. The ind-objects form a locally `v`-small category `IndCategory C` which has numerous interesting properties. ## Implementation notes One might be tempted to introduce another universe parameter and consider being a `w`-ind-object as a property of presheaves `C ⥤ TypeMax.{v, w}`. This comes with significant technical hurdles. The recommended alternative is to consider ind-objects over `ULiftHom.{w} C` instead. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Chapter 6 -/ universe v u namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] /-- The data that witnesses that a presheaf `A` is an ind-object. It consists of a small filtered indexing category `I`, a diagram `F : I ⥤ C` and the data for a colimit cocone on `F ⋙ yoneda : I ⥤ Cᵒᵖ ⥤ Type v` with cocone point `A`. -/ structure IndObjectPresentation (A : Cᵒᵖ ⥤ Type v) where /-- The indexing category of the filtered colimit presentation -/ I : Type v /-- The indexing category of the filtered colimit presentation -/ [ℐ : SmallCategory I] [hI : IsFiltered I] /-- The diagram of the filtered colimit presentation -/ F : I ⥤ C /-- Use `IndObjectPresentation.cocone` instead. -/ ι : F ⋙ yoneda ⟶ (Functor.const I).obj A /-- Use `IndObjectPresenation.coconeIsColimit` instead. -/ isColimit : IsColimit (Cocone.mk A ι) namespace IndObjectPresentation /-- Alternative constructor for `IndObjectPresentation` taking a cocone instead of its defining natural transformation. -/ @[simps] def ofCocone {I : Type v} [SmallCategory I] [IsFiltered I] {F : I ⥤ C} (c : Cocone (F ⋙ yoneda)) (hc : IsColimit c) : IndObjectPresentation c.pt where I := I F := F ι := c.ι isColimit := hc variable {A : Cᵒᵖ ⥤ Type v} (P : IndObjectPresentation A) instance : SmallCategory P.I := P.ℐ instance : IsFiltered P.I := P.hI /-- The (colimit) cocone with cocone point `A`. -/ @[simps pt] def cocone : Cocone (P.F ⋙ yoneda) where pt := A ι := P.ι /-- `P.cocone` is a colimit cocone. -/ def coconeIsColimit : IsColimit P.cocone := P.isColimit /-- If `A` and `B` are isomorphic, then an ind-object presentation of `A` can be extended to an ind-object presentation of `B`. -/ @[simps!] noncomputable def extend {A B : Cᵒᵖ ⥤ Type v} (P : IndObjectPresentation A) (η : A ⟶ B) [IsIso η] : IndObjectPresentation B := .ofCocone (P.cocone.extend η) (P.coconeIsColimit.extendIso (by exact η)) /-- The canonical comparison functor between the indexing category of the presentation and the comma category `CostructuredArrow yoneda A`. This functor is always final. -/ @[simps! obj_left obj_right_as obj_hom map_left] def toCostructuredArrow : P.I ⥤ CostructuredArrow yoneda A := P.cocone.toCostructuredArrow ⋙ CostructuredArrow.pre _ _ _ instance : P.toCostructuredArrow.Final := Presheaf.final_toCostructuredArrow_comp_pre _ P.coconeIsColimit /-- Representable presheaves are (trivially) ind-objects. -/ @[simps] def yoneda (X : C) : IndObjectPresentation (yoneda.obj X) where I := Discrete PUnit.{v + 1} F := Functor.fromPUnit X ι := { app := fun s => 𝟙 _ } isColimit := { desc := fun s => s.ι.app ⟨PUnit.unit⟩ uniq := fun s m h => h ⟨PUnit.unit⟩ } end IndObjectPresentation /-- A presheaf is called an ind-object if it can be written as a filtered colimit of representable presheaves. -/ structure IsIndObject (A : Cᵒᵖ ⥤ Type v) : Prop where mk' :: nonempty_presentation : Nonempty (IndObjectPresentation A) theorem IsIndObject.mk {A : Cᵒᵖ ⥤ Type v} (P : IndObjectPresentation A) : IsIndObject A := ⟨⟨P⟩⟩ /-- Representable presheaves are (trivially) ind-objects. -/ theorem isIndObject_yoneda (X : C) : IsIndObject (yoneda.obj X) := .mk <| IndObjectPresentation.yoneda X namespace IsIndObject variable {A : Cᵒᵖ ⥤ Type v} theorem map {A B : Cᵒᵖ ⥤ Type v} (η : A ⟶ B) [IsIso η] : IsIndObject A → IsIndObject B | ⟨⟨P⟩⟩ => ⟨⟨P.extend η⟩⟩ theorem iff_of_iso {A B : Cᵒᵖ ⥤ Type v} (η : A ⟶ B) [IsIso η] : IsIndObject A ↔ IsIndObject B := ⟨.map η, .map (inv η)⟩ /-- Pick a presentation for an ind-object using choice. -/ noncomputable def presentation : IsIndObject A → IndObjectPresentation A | ⟨P⟩ => P.some theorem isFiltered (h : IsIndObject A) : IsFiltered (CostructuredArrow yoneda A) := IsFiltered.of_final h.presentation.toCostructuredArrow theorem finallySmall (h : IsIndObject A) : FinallySmall.{v} (CostructuredArrow yoneda A) := FinallySmall.mk' h.presentation.toCostructuredArrow end IsIndObject open IsFiltered.SmallFilteredIntermediate theorem isIndObject_of_isFiltered_of_finallySmall (A : Cᵒᵖ ⥤ Type v) [IsFiltered (CostructuredArrow yoneda A)] [FinallySmall.{v} (CostructuredArrow yoneda A)] : IsIndObject A := by have h₁ : (factoring (fromFinalModel (CostructuredArrow yoneda A)) ⋙ inclusion (fromFinalModel (CostructuredArrow yoneda A))).Final := Functor.final_of_natIso (factoringCompInclusion (fromFinalModel <| CostructuredArrow yoneda A)).symm have h₂ : Functor.Final (inclusion (fromFinalModel (CostructuredArrow yoneda A))) := Functor.final_of_comp_full_faithful' (factoring _) (inclusion _) let c := (Presheaf.tautologicalCocone A).whisker (inclusion (fromFinalModel (CostructuredArrow yoneda A))) let hc : IsColimit c := (Functor.Final.isColimitWhiskerEquiv _ _).symm (Presheaf.isColimitTautologicalCocone A) have hq : Nonempty (FinalModel (CostructuredArrow yoneda A)) := Nonempty.map (Functor.Final.lift (fromFinalModel (CostructuredArrow yoneda A))) IsFiltered.nonempty exact ⟨_, inclusion (fromFinalModel _) ⋙ CostructuredArrow.proj yoneda A, c.ι, hc⟩ /-- The recognition theorem for ind-objects: `A : Cᵒᵖ ⥤ Type v` is an ind-object if and only if `CostructuredArrow yoneda A` is filtered and finally `v`-small. Theorem 6.1.5 of [Kashiwara2006] -/ theorem isIndObject_iff (A : Cᵒᵖ ⥤ Type v) : IsIndObject A ↔ (IsFiltered (CostructuredArrow yoneda A) ∧ FinallySmall.{v} (CostructuredArrow yoneda A)) := ⟨fun h => ⟨h.isFiltered, h.finallySmall⟩, fun ⟨_, _⟩ => isIndObject_of_isFiltered_of_finallySmall A⟩ end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\Basic.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Reid Barton, Bhavik Mehta, Jakob von Raumer -/ 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 [CategoryTheory 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) where preserves : ∀ {c : Cone K}, IsLimit c → 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) where preserves : ∀ {c : Cocone K}, IsColimit c → 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) 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) 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) 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) 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 /-- 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 instance preservesLimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (PreservesLimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance preservesColimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (PreservesColimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance preservesLimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (PreservesLimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance preservesColimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (PreservesColimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance preserves_limits_subsingleton (F : C ⥤ D) : Subsingleton (PreservesLimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance preserves_colimits_subsingleton (F : C ⥤ D) : Subsingleton (PreservesColimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance idPreservesLimits : 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 j j' 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 idPreservesColimits : 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 j j' 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 := ⟨⟨F.mapCone (limit.cone K), PreservesLimit.preserves (limit.isLimit K)⟩⟩ instance [HasColimit K] {F : C ⥤ D} [PreservesColimit K F] : HasColimit (K ⋙ F) where exists_colimit := ⟨⟨F.mapCocone (colimit.cocone K), PreservesColimit.preserves (colimit.isColimit K)⟩⟩ section variable {E : Type u₃} [ℰ : Category.{v₃} E] variable (F : C ⥤ D) (G : D ⥤ E) -- Porting note: made this global by removing local attribute [elab_without_expected_type] PreservesLimit.preserves PreservesColimit.preserves instance compPreservesLimit [PreservesLimit K F] [PreservesLimit (K ⋙ F) G] : PreservesLimit K (F ⋙ G) := ⟨fun h => PreservesLimit.preserves (PreservesLimit.preserves h)⟩ instance compPreservesLimitsOfShape [PreservesLimitsOfShape J F] [PreservesLimitsOfShape J G] : PreservesLimitsOfShape J (F ⋙ G) where instance compPreservesLimits [PreservesLimitsOfSize.{w', w} F] [PreservesLimitsOfSize.{w', w} G] : PreservesLimitsOfSize.{w', w} (F ⋙ G) where instance compPreservesColimit [PreservesColimit K F] [PreservesColimit (K ⋙ F) G] : PreservesColimit K (F ⋙ G) := ⟨fun h => PreservesColimit.preserves (PreservesColimit.preserves h)⟩ instance compPreservesColimitsOfShape [PreservesColimitsOfShape J F] [PreservesColimitsOfShape J G] : PreservesColimitsOfShape J (F ⋙ G) where instance compPreservesColimits [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. -/ def preservesLimitOfPreservesLimitCone {F : C ⥤ D} {t : Cone K} (h : IsLimit t) (hF : IsLimit (F.mapCone t)) : PreservesLimit K F := ⟨fun h' => IsLimit.ofIsoLimit hF (Functor.mapIso _ (IsLimit.uniqueUpToIso h h'))⟩ /-- Transfer preservation of limits along a natural isomorphism in the diagram. -/ def preservesLimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [PreservesLimit K₁ F] : PreservesLimit K₂ F where preserves {c} t := by apply IsLimit.postcomposeInvEquiv (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. -/ def preservesLimitOfNatIso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [PreservesLimit K F] : PreservesLimit K G where preserves t := IsLimit.mapConeEquiv h (PreservesLimit.preserves t) /-- Transfer preservation of limits of shape along a natural isomorphism in the functor. -/ def preservesLimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [PreservesLimitsOfShape J F] : PreservesLimitsOfShape J G where preservesLimit {K} := preservesLimitOfNatIso K h /-- Transfer preservation of limits along a natural isomorphism in the functor. -/ def preservesLimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [PreservesLimitsOfSize.{w, w'} F] : PreservesLimitsOfSize.{w, w'} G where preservesLimitsOfShape {_J} _𝒥₁ := preservesLimitsOfShapeOfNatIso h /-- Transfer preservation of limits along an equivalence in the shape. -/ def preservesLimitsOfShapeOfEquiv {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 => ?_ dsimp simp [equ, ← Functor.map_comp] } /-- A functor preserving larger limits also preserves smaller limits. -/ def preservesLimitsOfSizeOfUnivLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [PreservesLimitsOfSize.{w', w₂'} F] : PreservesLimitsOfSize.{w, w₂} F where preservesLimitsOfShape {J} := preservesLimitsOfShapeOfEquiv ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm F -- See library note [dsimp, simp]. /-- `PreservesLimitsOfSizeShrink.{w w'} F` tries to obtain `PreservesLimitsOfSize.{w w'} F` from some other `PreservesLimitsOfSize F`. -/ def preservesLimitsOfSizeShrink (F : C ⥤ D) [PreservesLimitsOfSize.{max w w₂, max w' w₂'} F] : PreservesLimitsOfSize.{w, w'} F := preservesLimitsOfSizeOfUnivLE.{max w w₂, max w' w₂'} F /-- Preserving limits at any universe level implies preserving limits in universe `0`. -/ def preservesSmallestLimitsOfPreservesLimits (F : C ⥤ D) [PreservesLimitsOfSize.{v₃, u₃} F] : PreservesLimitsOfSize.{0, 0} F := preservesLimitsOfSizeShrink F /-- If F preserves one colimit cocone for the diagram K, then it preserves any colimit cocone for K. -/ def preservesColimitOfPreservesColimitCocone {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. -/ def preservesColimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [PreservesColimit K₁ F] : PreservesColimit K₂ F where preserves {c} t := by apply IsColimit.precomposeHomEquiv (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. -/ def preservesColimitOfNatIso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [PreservesColimit K F] : PreservesColimit K G where preserves t := IsColimit.mapCoconeEquiv h (PreservesColimit.preserves t) /-- Transfer preservation of colimits of shape along a natural isomorphism in the functor. -/ def preservesColimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [PreservesColimitsOfShape J F] : PreservesColimitsOfShape J G where preservesColimit {K} := preservesColimitOfNatIso K h /-- Transfer preservation of colimits along a natural isomorphism in the functor. -/ def preservesColimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [PreservesColimitsOfSize.{w, w'} F] : PreservesColimitsOfSize.{w, w'} G where preservesColimitsOfShape {_J} _𝒥₁ := preservesColimitsOfShapeOfNatIso h /-- Transfer preservation of colimits along an equivalence in the shape. -/ def preservesColimitsOfShapeOfEquiv {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 => ?_ dsimp simp [equ, ← Functor.map_comp] } /-- A functor preserving larger colimits also preserves smaller colimits. -/ def preservesColimitsOfSizeOfUnivLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [PreservesColimitsOfSize.{w', w₂'} F] : PreservesColimitsOfSize.{w, w₂} F where preservesColimitsOfShape {J} := preservesColimitsOfShapeOfEquiv ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm F -- See library note [dsimp, simp]. /-- `PreservesColimitsOfSizeShrink.{w w'} F` tries to obtain `PreservesColimitsOfSize.{w w'} F` from some other `PreservesColimitsOfSize F`. -/ def preservesColimitsOfSizeShrink (F : C ⥤ D) [PreservesColimitsOfSize.{max w w₂, max w' w₂'} F] : PreservesColimitsOfSize.{w, w'} F := preservesColimitsOfSizeOfUnivLE.{max w w₂, max w' w₂'} F /-- Preserving colimits at any universe implies preserving colimits at universe `0`. -/ def preservesSmallestColimitsOfPreservesColimits (F : C ⥤ D) [PreservesColimitsOfSize.{v₃, u₃} F] : PreservesColimitsOfSize.{0, 0} F := preservesColimitsOfSizeShrink 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) where reflects : ∀ {c : Cone K}, IsLimit (F.mapCone c) → 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) where reflects : ∀ {c : Cocone K}, IsColimit (F.mapCocone c) → 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) 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) 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) 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) 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 /-- 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 instance reflectsLimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (ReflectsLimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance reflectsColimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : Subsingleton (ReflectsColimit K F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance reflectsLimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (ReflectsLimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance reflectsColimitsOfShape_subsingleton (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Subsingleton (ReflectsColimitsOfShape J F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance reflects_limits_subsingleton (F : C ⥤ D) : Subsingleton (ReflectsLimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton instance reflects_colimits_subsingleton (F : C ⥤ D) : Subsingleton (ReflectsColimitsOfSize.{w', w} F) := by constructor; rintro ⟨a⟩ ⟨b⟩; congr!; subsingleton -- see Note [lower instance priority] instance (priority := 100) reflectsLimitOfReflectsLimitsOfShape (K : J ⥤ C) (F : C ⥤ D) [ReflectsLimitsOfShape J F] : ReflectsLimit K F := ReflectsLimitsOfShape.reflectsLimit -- see Note [lower instance priority] instance (priority := 100) reflectsColimitOfReflectsColimitsOfShape (K : J ⥤ C) (F : C ⥤ D) [ReflectsColimitsOfShape J F] : ReflectsColimit K F := ReflectsColimitsOfShape.reflectsColimit -- see Note [lower instance priority] instance (priority := 100) reflectsLimitsOfShapeOfReflectsLimits (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) reflectsColimitsOfShapeOfReflectsColimits (J : Type w) [Category.{w'} J] (F : C ⥤ D) [ReflectsColimitsOfSize.{w', w} F] : ReflectsColimitsOfShape J F := ReflectsColimitsOfSize.reflectsColimitsOfShape instance idReflectsLimits : 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 j j' 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 idReflectsColimits : 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 j j' 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 compReflectsLimit [ReflectsLimit K F] [ReflectsLimit (K ⋙ F) G] : ReflectsLimit K (F ⋙ G) := ⟨fun h => ReflectsLimit.reflects (ReflectsLimit.reflects h)⟩ instance compReflectsLimitsOfShape [ReflectsLimitsOfShape J F] [ReflectsLimitsOfShape J G] : ReflectsLimitsOfShape J (F ⋙ G) where instance compReflectsLimits [ReflectsLimitsOfSize.{w', w} F] [ReflectsLimitsOfSize.{w', w} G] : ReflectsLimitsOfSize.{w', w} (F ⋙ G) where instance compReflectsColimit [ReflectsColimit K F] [ReflectsColimit (K ⋙ F) G] : ReflectsColimit K (F ⋙ G) := ⟨fun h => ReflectsColimit.reflects (ReflectsColimit.reflects h)⟩ instance compReflectsColimitsOfShape [ReflectsColimitsOfShape J F] [ReflectsColimitsOfShape J G] : ReflectsColimitsOfShape J (F ⋙ G) where instance compReflectsColimits [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`. -/ def preservesLimitOfReflectsOfPreserves [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`. -/ def preservesLimitsOfShapeOfReflectsOfPreserves [PreservesLimitsOfShape J (F ⋙ G)] [ReflectsLimitsOfShape J G] : PreservesLimitsOfShape J F where preservesLimit := preservesLimitOfReflectsOfPreserves F G /-- If `F ⋙ G` preserves limits and `G` reflects limits, then `F` preserves limits. -/ def preservesLimitsOfReflectsOfPreserves [PreservesLimitsOfSize.{w', w} (F ⋙ G)] [ReflectsLimitsOfSize.{w', w} G] : PreservesLimitsOfSize.{w', w} F where preservesLimitsOfShape := preservesLimitsOfShapeOfReflectsOfPreserves F G /-- Transfer reflection of limits along a natural isomorphism in the diagram. -/ def reflectsLimitOfIsoDiagram {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 (isoWhiskerRight h F : _) _).symm t).ofIsoLimit _ exact Cones.ext (Iso.refl _) /-- Transfer reflection of a limit along a natural isomorphism in the functor. -/ def reflectsLimitOfNatIso (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. -/ def reflectsLimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsLimitsOfShape J F] : ReflectsLimitsOfShape J G where reflectsLimit {K} := reflectsLimitOfNatIso K h /-- Transfer reflection of limits along a natural isomorphism in the functor. -/ def reflectsLimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsLimitsOfSize.{w', w} F] : ReflectsLimitsOfSize.{w', w} G where reflectsLimitsOfShape := reflectsLimitsOfShapeOfNatIso h /-- Transfer reflection of limits along an equivalence in the shape. -/ def reflectsLimitsOfShapeOfEquiv {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. -/ def reflectsLimitsOfSizeOfUnivLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [ReflectsLimitsOfSize.{w', w₂'} F] : ReflectsLimitsOfSize.{w, w₂} F where reflectsLimitsOfShape {J} := reflectsLimitsOfShapeOfEquiv ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm F /-- `reflectsLimitsOfSizeShrink.{w w'} F` tries to obtain `reflectsLimitsOfSize.{w w'} F` from some other `reflectsLimitsOfSize F`. -/ def reflectsLimitsOfSizeShrink (F : C ⥤ D) [ReflectsLimitsOfSize.{max w w₂, max w' w₂'} F] : ReflectsLimitsOfSize.{w, w'} F := reflectsLimitsOfSizeOfUnivLE.{max w w₂, max w' w₂'} F /-- Reflecting limits at any universe implies reflecting limits at universe `0`. -/ def reflectsSmallestLimitsOfReflectsLimits (F : C ⥤ D) [ReflectsLimitsOfSize.{v₃, u₃} F] : ReflectsLimitsOfSize.{0, 0} F := reflectsLimitsOfSizeShrink 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 def reflectsLimitOfReflectsIsomorphisms (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 (Prefunctor.map (Cones.functoriality F G).toPrefunctor (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`. -/ def reflectsLimitsOfShapeOfReflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasLimitsOfShape J C] [PreservesLimitsOfShape J G] : ReflectsLimitsOfShape J G where reflectsLimit {F} := reflectsLimitOfReflectsIsomorphisms F G /-- If `C` has limits and `G` preserves limits, then if `G` reflects isomorphisms then it reflects limits. -/ def reflectsLimitsOfReflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasLimitsOfSize.{w', w} C] [PreservesLimitsOfSize.{w', w} G] : ReflectsLimitsOfSize.{w', w} G where reflectsLimitsOfShape := reflectsLimitsOfShapeOfReflectsIsomorphisms /-- If `F ⋙ G` preserves colimits for `K`, and `G` reflects colimits for `K ⋙ F`, then `F` preserves colimits for `K`. -/ def preservesColimitOfReflectsOfPreserves [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`. -/ def preservesColimitsOfShapeOfReflectsOfPreserves [PreservesColimitsOfShape J (F ⋙ G)] [ReflectsColimitsOfShape J G] : PreservesColimitsOfShape J F where preservesColimit := preservesColimitOfReflectsOfPreserves F G /-- If `F ⋙ G` preserves colimits and `G` reflects colimits, then `F` preserves colimits. -/ def preservesColimitsOfReflectsOfPreserves [PreservesColimitsOfSize.{w', w} (F ⋙ G)] [ReflectsColimitsOfSize.{w', w} G] : PreservesColimitsOfSize.{w', w} F where preservesColimitsOfShape := preservesColimitsOfShapeOfReflectsOfPreserves F G /-- Transfer reflection of colimits along a natural isomorphism in the diagram. -/ def reflectsColimitOfIsoDiagram {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 (isoWhiskerRight h F : _) _).symm t).ofIsoColimit _ exact Cocones.ext (Iso.refl _) /-- Transfer reflection of a colimit along a natural isomorphism in the functor. -/ def reflectsColimitOfNatIso (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. -/ def reflectsColimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsColimitsOfShape J F] : ReflectsColimitsOfShape J G where reflectsColimit {K} := reflectsColimitOfNatIso K h /-- Transfer reflection of colimits along a natural isomorphism in the functor. -/ def reflectsColimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [ReflectsColimitsOfSize.{w, w'} F] : ReflectsColimitsOfSize.{w, w'} G where reflectsColimitsOfShape := reflectsColimitsOfShapeOfNatIso h /-- Transfer reflection of colimits along an equivalence in the shape. -/ def reflectsColimitsOfShapeOfEquiv {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. -/ def reflectsColimitsOfSizeOfUnivLE (F : C ⥤ D) [UnivLE.{w, w'}] [UnivLE.{w₂, w₂'}] [ReflectsColimitsOfSize.{w', w₂'} F] : ReflectsColimitsOfSize.{w, w₂} F where reflectsColimitsOfShape {J} := reflectsColimitsOfShapeOfEquiv ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm F /-- `reflectsColimitsOfSizeShrink.{w w'} F` tries to obtain `reflectsColimitsOfSize.{w w'} F` from some other `reflectsColimitsOfSize F`. -/ def reflectsColimitsOfSizeShrink (F : C ⥤ D) [ReflectsColimitsOfSize.{max w w₂, max w' w₂'} F] : ReflectsColimitsOfSize.{w, w'} F := reflectsColimitsOfSizeOfUnivLE.{max w w₂, max w' w₂'} F /-- Reflecting colimits at any universe implies reflecting colimits at universe `0`. -/ def reflectsSmallestColimitsOfReflectsColimits (F : C ⥤ D) [ReflectsColimitsOfSize.{v₃, u₃} F] : ReflectsColimitsOfSize.{0, 0} F := reflectsColimitsOfSizeShrink 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 def reflectsColimitOfReflectsIsomorphisms (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 (Prefunctor.map (Cocones.functoriality F G).toPrefunctor (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`. -/ def reflectsColimitsOfShapeOfReflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasColimitsOfShape J C] [PreservesColimitsOfShape J G] : ReflectsColimitsOfShape J G where reflectsColimit {F} := reflectsColimitOfReflectsIsomorphisms F G /-- If `C` has colimits and `G` preserves colimits, then if `G` reflects isomorphisms then it reflects colimits. -/ def reflectsColimitsOfReflectsIsomorphisms {G : C ⥤ D} [G.ReflectsIsomorphisms] [HasColimitsOfSize.{w', w} C] [PreservesColimitsOfSize.{w', w} G] : ReflectsColimitsOfSize.{w', w} G where reflectsColimitsOfShape := reflectsColimitsOfShapeOfReflectsIsomorphisms end variable (F : C ⥤ D) /-- A fully faithful functor reflects limits. -/ instance fullyFaithfulReflectsLimits [F.Full] [F.Faithful] : ReflectsLimitsOfSize.{w, w'} F where reflectsLimitsOfShape {J} 𝒥₁ := { reflectsLimit := fun {K} => { reflects := fun {c} t => (IsLimit.mkConeMorphism fun s => (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 fullyFaithfulReflectsColimits [F.Full] [F.Faithful] : ReflectsColimitsOfSize.{w, w'} F where reflectsColimitsOfShape {J} 𝒥₁ := { reflectsColimit := fun {K} => { reflects := fun {c} t => (IsColimit.mkCoconeMorphism fun s => (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
CategoryTheory\Limits\Preserves\Filtered.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Justus Springer -/ 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`. ## Future work This could be generalised to allow diagrams in lower universes. -/ open CategoryTheory open CategoryTheory.Functor namespace CategoryTheory.Limits universe 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] variable {J : Type v} [SmallCategory J] {K : J ⥤ C} /-- A functor is said to preserve filtered colimits, if it preserves all colimits of shape `J`, where `J` is a filtered category. -/ class PreservesFilteredColimits (F : C ⥤ D) : Type max u₁ u₂ (v + 1) where preserves_filtered_colimits : ∀ (J : Type v) [SmallCategory J] [IsFiltered J], PreservesColimitsOfShape J F attribute [instance 100] PreservesFilteredColimits.preserves_filtered_colimits instance (priority := 100) PreservesColimits.preservesFilteredColimits (F : C ⥤ D) [PreservesColimits F] : PreservesFilteredColimits F where preserves_filtered_colimits _ := inferInstance instance compPreservesFilteredColimits (F : C ⥤ D) (G : D ⥤ E) [PreservesFilteredColimits F] [PreservesFilteredColimits G] : PreservesFilteredColimits (F ⋙ G) where preserves_filtered_colimits _ := inferInstance /-- A functor is said to preserve cofiltered limits, if it preserves all limits of shape `J`, where `J` is a cofiltered category. -/ class PreservesCofilteredLimits (F : C ⥤ D) : Type max u₁ u₂ (v + 1) where preserves_cofiltered_limits : ∀ (J : Type v) [SmallCategory J] [IsCofiltered J], PreservesLimitsOfShape J F attribute [instance 100] PreservesCofilteredLimits.preserves_cofiltered_limits instance (priority := 100) PreservesLimits.preservesCofilteredLimits (F : C ⥤ D) [PreservesLimits F] : PreservesCofilteredLimits F where preserves_cofiltered_limits _ := inferInstance instance compPreservesCofilteredLimits (F : C ⥤ D) (G : D ⥤ E) [PreservesCofilteredLimits F] [PreservesCofilteredLimits G] : PreservesCofilteredLimits (F ⋙ G) where preserves_cofiltered_limits _ := inferInstance end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\Finite.lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ 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 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) 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. -/ noncomputable instance (priority := 100) preservesLimitsOfShapeOfPreservesFiniteLimits (F : C ⥤ D) [PreservesFiniteLimits F] (J : Type w) [SmallCategory J] [FinCategory J] : PreservesLimitsOfShape J F := by apply preservesLimitsOfShapeOfEquiv (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. -/ noncomputable def PreservesLimitsOfSize.preservesFiniteLimits (F : C ⥤ D) [PreservesLimitsOfSize.{w, w₂} F] : PreservesFiniteLimits F where preservesFiniteLimits J (sJ : SmallCategory J) fJ := by haveI := preservesSmallestLimitsOfPreservesLimits F exact preservesLimitsOfShapeOfEquiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for limits indexed in Type 0. noncomputable 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. noncomputable instance (priority := 120) PreservesLimits.preservesFiniteLimits (F : C ⥤ D) [PreservesLimits F] : PreservesFiniteLimits F := PreservesLimitsOfSize.preservesFiniteLimits F /-- We can always derive `PreservesFiniteLimits C` by showing that we are preserving limits at an arbitrary universe. -/ def preservesFiniteLimitsOfPreservesFiniteLimitsOfSize (F : C ⥤ D) (h : ∀ (J : Type w) {𝒥 : SmallCategory J} (_ : @FinCategory J 𝒥), PreservesLimitsOfShape J F) : PreservesFiniteLimits F where preservesFiniteLimits J (_ : SmallCategory J) _ := by letI : Category (ULiftHom (ULift J)) := ULiftHom.category haveI := h (ULiftHom (ULift J)) CategoryTheory.finCategoryUlift exact preservesLimitsOfShapeOfEquiv (ULiftHomULiftCategory.equiv J).symm F /-- The composition of two left exact functors is left exact. -/ def compPreservesFiniteLimits (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteLimits F] [PreservesFiniteLimits G] : PreservesFiniteLimits (F ⋙ G) := ⟨fun _ _ _ => inferInstance⟩ /- Porting note: adding this class because quantified classes don't behave well [#2764](https://github.com/leanprover-community/mathlib4/pull/2764) -/ /-- A functor `F` preserves finite products if it preserves all from `Discrete J` for `Fintype J` -/ class PreservesFiniteProducts (F : C ⥤ D) where preserves : ∀ (J : Type) [Fintype J], PreservesLimitsOfShape (Discrete J) F attribute [instance] PreservesFiniteProducts.preserves instance compPreservesFiniteProducts (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteProducts F] [PreservesFiniteProducts G] : PreservesFiniteProducts (F ⋙ G) where preserves _ _ := inferInstance noncomputable 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) 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` -/ class ReflectsFiniteProducts (F : C ⥤ D) where reflects : ∀ (J : Type) [Fintype J], ReflectsLimitsOfShape (Discrete J) F attribute [instance] ReflectsFiniteProducts.reflects -- 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. -/ noncomputable def ReflectsLimitsOfSize.reflectsFiniteLimits (F : C ⥤ D) [ReflectsLimitsOfSize.{w, w₂} F] : ReflectsFiniteLimits F where reflects J (sJ : SmallCategory J) fJ := by haveI := reflectsSmallestLimitsOfReflectsLimits F exact reflectsLimitsOfShapeOfEquiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for colimits indexed in Type 0. noncomputable 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. noncomputable 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. -/ def preservesFiniteLimitsOfReflectsOfPreserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteLimits (F ⋙ G)] [ReflectsFiniteLimits G] : PreservesFiniteLimits F where preservesFiniteLimits _ _ _ := preservesLimitsOfShapeOfReflectsOfPreserves F G /-- If `F ⋙ G` preserves finite products and `G` reflects finite products, then `F` preserves finite products. -/ def preservesFiniteProductsOfReflectsOfPreserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteProducts (F ⋙ G)] [ReflectsFiniteProducts G] : PreservesFiniteProducts F where preserves _ _ := preservesLimitsOfShapeOfReflectsOfPreserves F G noncomputable instance reflectsFiniteLimitsOfReflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteLimits C] [PreservesFiniteLimits F] : ReflectsFiniteLimits F where reflects _ _ _ := reflectsLimitsOfShapeOfReflectsIsomorphisms noncomputable instance reflectsFiniteProductsOfReflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteProducts C] [PreservesFiniteProducts F] : ReflectsFiniteProducts F where reflects _ _ := reflectsLimitsOfShapeOfReflectsIsomorphisms instance compReflectsFiniteProducts (F : C ⥤ D) (G : D ⥤ E) [ReflectsFiniteProducts F] [ReflectsFiniteProducts G] : ReflectsFiniteProducts (F ⋙ G) where reflects _ _ := inferInstance noncomputable 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) 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, though through a noncomputable instance. -/ noncomputable instance (priority := 100) preservesColimitsOfShapeOfPreservesFiniteColimits (F : C ⥤ D) [PreservesFiniteColimits F] (J : Type w) [SmallCategory J] [FinCategory J] : PreservesColimitsOfShape J F := by apply preservesColimitsOfShapeOfEquiv (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. -/ noncomputable def PreservesColimitsOfSize.preservesFiniteColimits (F : C ⥤ D) [PreservesColimitsOfSize.{w, w₂} F] : PreservesFiniteColimits F where preservesFiniteColimits J (sJ : SmallCategory J) fJ := by haveI := preservesSmallestColimitsOfPreservesColimits F exact preservesColimitsOfShapeOfEquiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for colimits indexed in Type 0. noncomputable 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. noncomputable instance (priority := 120) PreservesColimits.preservesFiniteColimits (F : C ⥤ D) [PreservesColimits F] : PreservesFiniteColimits F := PreservesColimitsOfSize.preservesFiniteColimits F /-- We can always derive `PreservesFiniteColimits C` by showing that we are preserving colimits at an arbitrary universe. -/ def preservesFiniteColimitsOfPreservesFiniteColimitsOfSize (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 preservesColimitsOfShapeOfEquiv (ULiftHomULiftCategory.equiv J).symm F /-- The composition of two right exact functors is right exact. -/ def compPreservesFiniteColimits (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteColimits F] [PreservesFiniteColimits G] : PreservesFiniteColimits (F ⋙ G) := ⟨fun _ _ _ => inferInstance⟩ /- Porting note: adding this class because quantified classes don't behave well [#2764](https://github.com/leanprover-community/mathlib4/pull/2764) -/ /-- A functor `F` preserves finite products if it preserves all from `Discrete J` for `Fintype J` -/ class PreservesFiniteCoproducts (F : C ⥤ D) where /-- preservation of colimits indexed by `Discrete J` when `[Fintype J]` -/ preserves : ∀ (J : Type) [Fintype J], PreservesColimitsOfShape (Discrete J) F noncomputable instance (F : C ⥤ D) (J : Type*) [Finite J] [PreservesFiniteCoproducts F] : PreservesColimitsOfShape (Discrete J) F := by apply Nonempty.some obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin J have : PreservesColimitsOfShape (Discrete (Fin n)) F := PreservesFiniteCoproducts.preserves _ exact ⟨preservesColimitsOfShapeOfEquiv (Discrete.equivalence e.symm) F⟩ noncomputable instance compPreservesFiniteCoproducts (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteCoproducts F] [PreservesFiniteCoproducts G] : PreservesFiniteCoproducts (F ⋙ G) where preserves _ _ := inferInstance noncomputable 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) where reflects : ∀ (J : Type) [SmallCategory J] [FinCategory J], ReflectsColimitsOfShape J F := by infer_instance 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. -/ noncomputable def ReflectsColimitsOfSize.reflectsFiniteColimits (F : C ⥤ D) [ReflectsColimitsOfSize.{w, w₂} F] : ReflectsFiniteColimits F where reflects J (sJ : SmallCategory J) fJ := by haveI := reflectsSmallestColimitsOfReflectsColimits F exact reflectsColimitsOfShapeOfEquiv (FinCategory.equivAsType J) F -- Added as a specialization of the dangerous instance above, for colimits indexed in Type 0. noncomputable 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. noncomputable 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` -/ class ReflectsFiniteCoproducts (F : C ⥤ D) where reflects : ∀ (J : Type) [Fintype J], ReflectsColimitsOfShape (Discrete J) F attribute [instance] ReflectsFiniteCoproducts.reflects /-- If `F ⋙ G` preserves finite colimits and `G` reflects finite colimits, then `F` preserves finite colimits. -/ def preservesFiniteColimitsOfReflectsOfPreserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteColimits (F ⋙ G)] [ReflectsFiniteColimits G] : PreservesFiniteColimits F where preservesFiniteColimits _ _ _ := preservesColimitsOfShapeOfReflectsOfPreserves F G /-- If `F ⋙ G` preserves finite coproducts and `G` reflects finite coproducts, then `F` preserves finite coproducts. -/ noncomputable def preservesFiniteCoproductsOfReflectsOfPreserves (F : C ⥤ D) (G : D ⥤ E) [PreservesFiniteCoproducts (F ⋙ G)] [ReflectsFiniteCoproducts G] : PreservesFiniteCoproducts F where preserves _ _ := preservesColimitsOfShapeOfReflectsOfPreserves F G noncomputable instance reflectsFiniteColimitsOfReflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteColimits C] [PreservesFiniteColimits F] : ReflectsFiniteColimits F where reflects _ _ _ := reflectsColimitsOfShapeOfReflectsIsomorphisms noncomputable instance reflectsFiniteCoproductsOfReflectsIsomorphisms (F : C ⥤ D) [F.ReflectsIsomorphisms] [HasFiniteCoproducts C] [PreservesFiniteCoproducts F] : ReflectsFiniteCoproducts F where reflects _ _ := reflectsColimitsOfShapeOfReflectsIsomorphisms instance compReflectsFiniteCoproducts (F : C ⥤ D) (G : D ⥤ E) [ReflectsFiniteCoproducts F] [ReflectsFiniteCoproducts G] : ReflectsFiniteCoproducts (F ⋙ G) where reflects _ _ := inferInstance noncomputable instance (F : C ⥤ D) [ReflectsFiniteColimits F] : ReflectsFiniteCoproducts F where reflects _ _ := inferInstance end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\FunctorCategory.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.Limits.Presheaf /-! # 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₂ u u₂ noncomputable section namespace CategoryTheory open Category Limits 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` -/ def FunctorCategory.prodPreservesColimits [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) } ) } instance whiskeringLeftPreservesLimits [HasLimits D] (F : C ⥤ E) : PreservesLimits ((whiskeringLeft C E D).obj F) := ⟨fun {J} [hJ : Category J] => ⟨fun {K} => ⟨fun c {hc} => by apply evaluationJointlyReflectsLimits intro Y change IsLimit (((evaluation E D).obj (F.obj Y)).mapCone c) exact PreservesLimit.preserves hc⟩⟩⟩ instance whiskeringRightPreservesLimitsOfShape {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 PreservesLimit.preserves hc⟩⟩ 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⟩ -- Porting note: fixed spelling mistake in def /-- If `Lan F.op : (Cᵒᵖ ⥤ Type*) ⥤ (Dᵒᵖ ⥤ Type*)` preserves limits of shape `J`, so will `F`. -/ noncomputable def preservesLimitOfLanPreservesLimit {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 := by apply @preservesLimitsOfShapeOfReflectsOfPreserves _ _ _ _ _ _ _ _ F yoneda ?_ exact preservesLimitsOfShapeOfNatIso (Presheaf.compYonedaIsoYonedaCompLan F).symm end CategoryTheory
CategoryTheory\Limits\Preserves\Limits.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ 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₁) : (PreservesLimit.preserves t).lift (G.mapCone c₂) = G.map (t.lift c₂) := ((PreservesLimit.preserves 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) := (PreservesLimit.preserves (limit.isLimit _)).conePointUniqueUpToIso (limit.isLimit _) @[reassoc (attr := simp)] theorem preservesLimitsIso_hom_π (j) : (preservesLimitIso G F).hom ≫ limit.π _ j = G.map (limit.π F j) := IsLimit.conePointUniqueUpToIso_hom_comp _ _ j @[reassoc (attr := simp)] theorem preservesLimitsIso_inv_π (j) : (preservesLimitIso G F).inv ≫ G.map (limit.π F j) = limit.π _ j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ j @[reassoc (attr := simp)] theorem lift_comp_preservesLimitsIso_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 wrt `F`. -/ @[simps!] def preservesLimitNatIso : lim ⋙ G ≅ (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 [preservesLimitsIso_hom_π, whiskerRight_app, limMap_π, Category.assoc, preservesLimitsIso_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`. -/ def preservesLimitOfIsIsoPost [IsIso (limit.post F G)] : PreservesLimit F G := preservesLimitOfPreservesLimitCone (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₁) : (PreservesColimit.preserves t).desc (G.mapCocone _) = G.map (t.desc c₂) := ((PreservesColimit.preserves 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) := (PreservesColimit.preserves (colimit.isColimit _)).coconePointUniqueUpToIso (colimit.isColimit _) @[reassoc (attr := simp)] theorem ι_preservesColimitsIso_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 ι_preservesColimitsIso_hom (j : J) : G.map (colimit.ι F j) ≫ (preservesColimitIso G F).hom = colimit.ι (F ⋙ G) j := (PreservesColimit.preserves (colimit.isColimit _)).comp_coconePointUniqueUpToIso_hom _ j @[reassoc (attr := simp)] theorem preservesColimitsIso_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 wrt `F`. -/ @[simps!] def preservesColimitNatIso : colim ⋙ G ≅ (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 erw [ι_colimMap_assoc] simp only [ι_preservesColimitsIso_inv, whiskerRight_app, Category.assoc, ι_preservesColimitsIso_inv_assoc, ← G.map_comp] erw [ι_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`. -/ def preservesColimitOfIsIsoPost [IsIso (colimit.post F G)] : PreservesColimit F G := preservesColimitOfPreservesColimitCocone (colimit.isColimit F) (by convert IsColimit.ofPointIso (colimit.isColimit (F ⋙ G)) assumption) end end CategoryTheory
CategoryTheory\Limits\Preserves\Opposites.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ 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. ## Future work * Dually, it is possible to formulate conditions about `F.op` ec. for `F` to preserve certain (co)limits. -/ 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ᵒᵖ`. -/ def preservesLimitOp (K : J ⥤ Cᵒᵖ) (F : C ⥤ D) [PreservesColimit K.leftOp F] : PreservesLimit K F.op where preserves {_} hc := isLimitConeRightOpOfCocone _ (isColimitOfPreserves F (isColimitCoconeLeftOpOfCone _ hc)) /-- If `F : C ⥤ Dᵒᵖ` preserves colimits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves limits of `K : J ⥤ Cᵒᵖ`. -/ def preservesLimitLeftOp (K : J ⥤ Cᵒᵖ) (F : C ⥤ Dᵒᵖ) [PreservesColimit K.leftOp F] : PreservesLimit K F.leftOp where preserves {_} hc := isLimitConeUnopOfCocone _ (isColimitOfPreserves F (isColimitCoconeLeftOpOfCone _ hc)) /-- If `F : Cᵒᵖ ⥤ D` preserves colimits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves limits of `K : J ⥤ C`. -/ def preservesLimitRightOp (K : J ⥤ C) (F : Cᵒᵖ ⥤ D) [PreservesColimit K.op F] : PreservesLimit K F.rightOp where preserves {_} hc := isLimitConeRightOpOfCocone _ (isColimitOfPreserves F hc.op) /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.unop : C ⥤ D` preserves limits of `K : J ⥤ C`. -/ def preservesLimitUnop (K : J ⥤ C) (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimit K.op F] : PreservesLimit K F.unop where preserves {_} hc := isLimitConeUnopOfCocone _ (isColimitOfPreserves F hc.op) /-- If `F : C ⥤ D` preserves limits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of `K : J ⥤ Cᵒᵖ`. -/ def preservesColimitOp (K : J ⥤ Cᵒᵖ) (F : C ⥤ D) [PreservesLimit K.leftOp F] : PreservesColimit K F.op where preserves {_} hc := isColimitCoconeRightOpOfCone _ (isLimitOfPreserves F (isLimitConeLeftOpOfCocone _ hc)) /-- If `F : C ⥤ Dᵒᵖ` preserves limits of `K.leftOp : Jᵒᵖ ⥤ C`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits of `K : J ⥤ Cᵒᵖ`. -/ def preservesColimitLeftOp (K : J ⥤ Cᵒᵖ) (F : C ⥤ Dᵒᵖ) [PreservesLimit K.leftOp F] : PreservesColimit K F.leftOp where preserves {_} hc := isColimitCoconeUnopOfCone _ (isLimitOfPreserves F (isLimitConeLeftOpOfCocone _ hc)) /-- If `F : Cᵒᵖ ⥤ D` preserves limits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits of `K : J ⥤ C`. -/ def preservesColimitRightOp (K : J ⥤ C) (F : Cᵒᵖ ⥤ D) [PreservesLimit K.op F] : PreservesColimit K F.rightOp where preserves {_} hc := isColimitCoconeRightOpOfCone _ (isLimitOfPreserves F hc.op) /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of `K.op : Jᵒᵖ ⥤ Cᵒᵖ`, then `F.unop : C ⥤ D` preserves colimits of `K : J ⥤ C`. -/ def preservesColimitUnop (K : J ⥤ C) (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimit K.op F] : PreservesColimit K F.unop where preserves {_} hc := isColimitCoconeUnopOfCone _ (isLimitOfPreserves F hc.op) section variable (J) /-- If `F : C ⥤ D` preserves colimits of shape `Jᵒᵖ`, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of shape `J`. -/ def preservesLimitsOfShapeOp (F : C ⥤ D) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.op where preservesLimit {K} := preservesLimitOp K F /-- If `F : C ⥤ Dᵒᵖ` preserves colimits of shape `Jᵒᵖ`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves limits of shape `J`. -/ def preservesLimitsOfShapeLeftOp (F : C ⥤ Dᵒᵖ) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.leftOp where preservesLimit {K} := preservesLimitLeftOp K F /-- If `F : Cᵒᵖ ⥤ D` preserves colimits of shape `Jᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves limits of shape `J`. -/ def preservesLimitsOfShapeRightOp (F : Cᵒᵖ ⥤ D) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.rightOp where preservesLimit {K} := preservesLimitRightOp K F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of shape `Jᵒᵖ`, then `F.unop : C ⥤ D` preserves limits of shape `J`. -/ def preservesLimitsOfShapeUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimitsOfShape Jᵒᵖ F] : PreservesLimitsOfShape J F.unop where preservesLimit {K} := preservesLimitUnop K F /-- If `F : C ⥤ D` preserves limits of shape `Jᵒᵖ`, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits of shape `J`. -/ def preservesColimitsOfShapeOp (F : C ⥤ D) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.op where preservesColimit {K} := preservesColimitOp K F /-- If `F : C ⥤ Dᵒᵖ` preserves limits of shape `Jᵒᵖ`, then `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits of shape `J`. -/ def preservesColimitsOfShapeLeftOp (F : C ⥤ Dᵒᵖ) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.leftOp where preservesColimit {K} := preservesColimitLeftOp K F /-- If `F : Cᵒᵖ ⥤ D` preserves limits of shape `Jᵒᵖ`, then `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits of shape `J`. -/ def preservesColimitsOfShapeRightOp (F : Cᵒᵖ ⥤ D) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.rightOp where preservesColimit {K} := preservesColimitRightOp K F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits of shape `Jᵒᵖ`, then `F.unop : C ⥤ D` preserves colimits of shape `J`. -/ def preservesColimitsOfShapeUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimitsOfShape Jᵒᵖ F] : PreservesColimitsOfShape J F.unop where preservesColimit {K} := preservesColimitUnop K F end /-- If `F : C ⥤ D` preserves colimits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits. -/ def preservesLimitsOp (F : C ⥤ D) [PreservesColimits F] : PreservesLimits F.op where preservesLimitsOfShape {_} _ := preservesLimitsOfShapeOp _ _ /-- If `F : C ⥤ Dᵒᵖ` preserves colimits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves limits. -/ def preservesLimitsLeftOp (F : C ⥤ Dᵒᵖ) [PreservesColimits F] : PreservesLimits F.leftOp where preservesLimitsOfShape {_} _ := preservesLimitsOfShapeLeftOp _ _ /-- If `F : Cᵒᵖ ⥤ D` preserves colimits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves limits. -/ def preservesLimitsRightOp (F : Cᵒᵖ ⥤ D) [PreservesColimits F] : PreservesLimits F.rightOp where preservesLimitsOfShape {_} _ := preservesLimitsOfShapeRightOp _ _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits, then `F.unop : C ⥤ D` preserves limits. -/ def preservesLimitsUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesColimits F] : PreservesLimits F.unop where preservesLimitsOfShape {_} _ := preservesLimitsOfShapeUnop _ _ /-- If `F : C ⥤ D` preserves limits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves colimits. -/ def perservesColimitsOp (F : C ⥤ D) [PreservesLimits F] : PreservesColimits F.op where preservesColimitsOfShape {_} _ := preservesColimitsOfShapeOp _ _ /-- If `F : C ⥤ Dᵒᵖ` preserves limits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves colimits. -/ def preservesColimitsLeftOp (F : C ⥤ Dᵒᵖ) [PreservesLimits F] : PreservesColimits F.leftOp where preservesColimitsOfShape {_} _ := preservesColimitsOfShapeLeftOp _ _ /-- If `F : Cᵒᵖ ⥤ D` preserves limits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves colimits. -/ def preservesColimitsRightOp (F : Cᵒᵖ ⥤ D) [PreservesLimits F] : PreservesColimits F.rightOp where preservesColimitsOfShape {_} _ := preservesColimitsOfShapeRightOp _ _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves limits, then `F.unop : C ⥤ D` preserves colimits. -/ def preservesColimitsUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesLimits F] : PreservesColimits F.unop where preservesColimitsOfShape {_} _ := preservesColimitsOfShapeUnop _ _ /-- If `F : C ⥤ D` preserves finite colimits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite limits. -/ def preservesFiniteLimitsOp (F : C ⥤ D) [PreservesFiniteColimits F] : PreservesFiniteLimits F.op where preservesFiniteLimits J (_ : SmallCategory J) _ := preservesLimitsOfShapeOp J F /-- If `F : C ⥤ Dᵒᵖ` preserves finite colimits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite limits. -/ def preservesFiniteLimitsLeftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteColimits F] : PreservesFiniteLimits F.leftOp where preservesFiniteLimits J (_ : SmallCategory J) _ := preservesLimitsOfShapeLeftOp J F /-- If `F : Cᵒᵖ ⥤ D` preserves finite colimits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite limits. -/ def preservesFiniteLimitsRightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteColimits F] : PreservesFiniteLimits F.rightOp where preservesFiniteLimits J (_ : SmallCategory J) _ := preservesLimitsOfShapeRightOp J F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite colimits, then `F.unop : C ⥤ D` preserves finite limits. -/ def preservesFiniteLimitsUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteColimits F] : PreservesFiniteLimits F.unop where preservesFiniteLimits J (_ : SmallCategory J) _ := preservesLimitsOfShapeUnop J F /-- If `F : C ⥤ D` preserves finite limits, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite colimits. -/ def preservesFiniteColimitsOp (F : C ⥤ D) [PreservesFiniteLimits F] : PreservesFiniteColimits F.op where preservesFiniteColimits J (_ : SmallCategory J) _ := preservesColimitsOfShapeOp J F /-- If `F : C ⥤ Dᵒᵖ` preserves finite limits, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite colimits. -/ def preservesFiniteColimitsLeftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteLimits F] : PreservesFiniteColimits F.leftOp where preservesFiniteColimits J (_ : SmallCategory J) _ := preservesColimitsOfShapeLeftOp J F /-- If `F : Cᵒᵖ ⥤ D` preserves finite limits, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite colimits. -/ def preservesFiniteColimitsRightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteLimits F] : PreservesFiniteColimits F.rightOp where preservesFiniteColimits J (_ : SmallCategory J) _ := preservesColimitsOfShapeRightOp J F /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite limits, then `F.unop : C ⥤ D` preserves finite colimits. -/ def preservesFiniteColimitsUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteLimits F] : PreservesFiniteColimits F.unop where preservesFiniteColimits J (_ : SmallCategory J) _ := preservesColimitsOfShapeUnop J F /-- If `F : C ⥤ D` preserves finite coproducts, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite products. -/ def preservesFiniteProductsOp (F : C ⥤ D) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.op where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShapeOp exact preservesColimitsOfShapeOfEquiv (Discrete.opposite J).symm _ /-- If `F : C ⥤ Dᵒᵖ` preserves finite coproducts, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite products. -/ def preservesFiniteProductsLeftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.leftOp where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShapeLeftOp exact preservesColimitsOfShapeOfEquiv (Discrete.opposite J).symm _ /-- If `F : Cᵒᵖ ⥤ D` preserves finite coproducts, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite products. -/ def preservesFiniteProductsRightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.rightOp where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShapeRightOp exact preservesColimitsOfShapeOfEquiv (Discrete.opposite J).symm _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite coproducts, then `F.unop : C ⥤ D` preserves finite products. -/ def preservesFiniteProductsUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteCoproducts F] : PreservesFiniteProducts F.unop where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesLimitsOfShapeUnop exact preservesColimitsOfShapeOfEquiv (Discrete.opposite J).symm _ /-- If `F : C ⥤ D` preserves finite products, then `F.op : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite coproducts. -/ def preservesFiniteCoproductsOp (F : C ⥤ D) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.op where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShapeOp exact preservesLimitsOfShapeOfEquiv (Discrete.opposite J).symm _ /-- If `F : C ⥤ Dᵒᵖ` preserves finite products, then `F.leftOp : Cᵒᵖ ⥤ D` preserves finite coproducts. -/ def preservesFiniteCoproductsLeftOp (F : C ⥤ Dᵒᵖ) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.leftOp where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShapeLeftOp exact preservesLimitsOfShapeOfEquiv (Discrete.opposite J).symm _ /-- If `F : Cᵒᵖ ⥤ D` preserves finite products, then `F.rightOp : C ⥤ Dᵒᵖ` preserves finite coproducts. -/ def preservesFiniteCoproductsRightOp (F : Cᵒᵖ ⥤ D) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.rightOp where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShapeRightOp exact preservesLimitsOfShapeOfEquiv (Discrete.opposite J).symm _ /-- If `F : Cᵒᵖ ⥤ Dᵒᵖ` preserves finite products, then `F.unop : C ⥤ D` preserves finite coproducts. -/ def preservesFiniteCoproductsUnop (F : Cᵒᵖ ⥤ Dᵒᵖ) [PreservesFiniteProducts F] : PreservesFiniteCoproducts F.unop where preserves J _ := by apply (config := { allowSynthFailures := true }) preservesColimitsOfShapeUnop exact preservesLimitsOfShapeOfEquiv (Discrete.opposite J).symm _ end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\Ulift.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Junyan Xu -/ import Mathlib.CategoryTheory.Limits.Creates import Mathlib.CategoryTheory.Limits.Types import Mathlib.Data.Set.Subsingleton /-! # `ULift` creates small (co)limits This file shows that `uliftFunctor.{v, u}` creates (and hence preserves) limits and colimits indexed by `J` with `[Category.{w, u} J]`. It also shows that `uliftFunctor.{v, u}` *preserves* "all" limits, potentially too big to exist in `Type u`). -/ 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]⟩ left_inv _ := rfl right_inv _ := rfl /-- 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 apply Nonempty.some 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})} /-- Given a subset of the cocone point of a cocone over the lifted functor, produce a cocone over the original functor. -/ def coconeOfSet (ls : Set lc.pt) : Cocone K where pt := ULift Prop ι := { app := fun j x ↦ ⟨lc.ι.app j ⟨x⟩ ∈ ls⟩ naturality := fun i j f ↦ by dsimp only; rw [← lc.w f]; rfl } /-- Given a subset of the cocone point of a cocone over the lifted functor, produce a subset of the cocone point of a colimit cocone over the original functor. -/ def descSet (ls : Set lc.pt) : Set c.pt := {x | (hc.desc (coconeOfSet ls) x).down} /-- Characterization the map `descSet hc`: the image of an element in a vertex of the original diagram in the cocone point lies in `descSet hc ls` if and only if the image of the corresponding element in the lifted diagram lie in `ls`. -/ lemma descSet_spec (s : Set c.pt) (ls : Set lc.pt) : descSet hc ls = s ↔ ∀ j x, lc.ι.app j ⟨x⟩ ∈ ls ↔ c.ι.app j x ∈ s := by refine ⟨?_, fun he ↦ funext fun x ↦ ?_⟩ · rintro rfl j x exact (congr_arg ULift.down (congr_fun (hc.fac (coconeOfSet ls) j) x).symm).to_iff · refine (congr_arg ULift.down (congr_fun (hc.uniq (coconeOfSet ls) (⟨· ∈ s⟩) fun j ↦ ?_) x)).symm ext y; exact congr_arg ULift.up (propext (he j y).symm) lemma mem_descSet_singleton {x : lc.pt} {j : J} {y : K.obj j} : c.ι.app j y ∈ descSet hc {x} ↔ lc.ι.app j ⟨y⟩ = x := ((descSet_spec hc _ {x}).mp rfl j y).symm variable (lc) lemma descSet_univ : descSet hc (@Set.univ lc.pt) = Set.univ := by simp [descSet_spec] lemma iUnion_descSet_singleton : ⋃ x : lc.pt, descSet hc {x} = Set.univ := by rw [← descSet_univ hc lc, eq_comm, descSet_spec] intro j x erw [true_iff, Set.mem_iUnion] use lc.ι.app j ⟨x⟩ rw [mem_descSet_singleton] lemma descSet_empty : descSet hc (∅ : Set lc.pt) = ∅ := by simp [descSet_spec] lemma descSet_inter_of_ne (x y : lc.pt) (hn : x ≠ y) : descSet hc {x} ∩ descSet hc {y} = ∅ := by rw [eq_comm, ← descSet_empty hc lc, descSet_spec] intro j z erw [false_iff] rintro ⟨hx, hy⟩ rw [mem_descSet_singleton] at hx hy exact hn (hx ▸ hy) lemma exists_unique_mem_descSet (x : c.pt) : ∃! y : lc.pt, x ∈ descSet hc {y} := exists_unique_of_exists_of_unique (Set.mem_iUnion.mp <| Set.eq_univ_iff_forall.mp (iUnion_descSet_singleton hc lc) x) fun y₁ y₂ h₁ h₂ ↦ by_contra fun hn ↦ Set.eq_empty_iff_forall_not_mem.1 (descSet_inter_of_ne hc lc y₁ y₂ hn) x ⟨h₁, h₂⟩ /-- Given a colimit cocone in `Type u` and an arbitrary cocone over the diagram lifted to `Type (max u v)`, produce a function from the cocone point of the colimit cocone to the cocone point of the other cocone, that witnesses the colimit cocone also being a colimit in the higher universe. -/ noncomputable def descFun (x : c.pt) : lc.pt := (exists_unique_mem_descSet hc lc x).exists.choose lemma descFun_apply_spec {x : c.pt} {y : lc.pt} : descFun hc lc x = y ↔ x ∈ descSet hc {y} := have hu := exists_unique_mem_descSet hc lc x have hm := hu.exists.choose_spec ⟨fun he ↦ he ▸ hm, hu.unique hm⟩ lemma descFun_spec (f : c.pt → lc.pt) : f = descFun hc lc ↔ ∀ j, f ∘ c.ι.app j = lc.ι.app j ∘ ULift.up := by refine ⟨?_, fun he ↦ funext fun x ↦ ((descFun_apply_spec hc lc).mpr ?_).symm⟩ · rintro rfl j; ext apply (descFun_apply_spec hc lc).mpr rw [mem_descSet_singleton]; rfl · rw [← (jointly_surjective_of_isColimit hc x).choose_spec.choose_spec, mem_descSet_singleton] exact (congr_fun (he _) _).symm /-- 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 ↦ { desc := fun lc x ↦ descFun hc lc x.down fac := fun lc j ↦ by ext ⟨⟩; apply congr_fun ((descFun_spec hc lc _).mp rfl j) uniq := fun lc f hf ↦ by ext ⟨⟩; apply congr_fun ((descFun_spec hc lc (f ∘ ULift.up)).mpr fun j ↦ funext fun y ↦ congr_fun (hf j) ⟨y⟩) } } } /-- 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 {_} ↦ createsColimitOfFullyFaithfulOfPreserves } end CategoryTheory.Limits.Types
CategoryTheory\Limits\Preserves\Shapes\BinaryProducts.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ 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 (PreservesLimit.preserves 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) := ReflectsLimit.reflects ((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) 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)`. -/ def PreservesLimitPair.ofIsoProdComparison [i : IsIso (prodComparison G X Y)] : PreservesLimit (pair X Y) G := by apply preservesLimitOfPreservesLimitCone (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] 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] 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 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 (PreservesColimit.preserves 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) := ReflectsColimit.reflects ((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)`. -/ def PreservesColimitPair.ofIsoCoprodComparison [i : IsIso (coprodComparison G X Y)] : PreservesColimit (pair X Y) G := by apply preservesColimitOfPreservesColimitCocone (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 end end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\Shapes\Biproducts.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.Biproducts 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] where preserves : ∀ {b : Bicone f}, b.IsBilimit → (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 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] 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 fintype. -/ class PreservesFiniteBiproducts (F : C ⥤ D) [PreservesZeroMorphisms F] where preserves : ∀ {J : Type} [Fintype 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] 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. -/ def preservesBiproductsShrink (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 := preservesBiproductsShrink.{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] where preserves : ∀ {b : BinaryBicone X Y}, b.IsBilimit → (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 /-- 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] 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. -/ def preservesBinaryBiproductOfPreservesBiproduct (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. -/ def preservesBinaryBiproductsOfPreservesBiproducts (F : C ⥤ D) [PreservesZeroMorphisms F] [PreservesBiproductsOfShape WalkingPair F] : PreservesBinaryBiproducts F where preserves {X} Y := preservesBinaryBiproductOfPreservesBiproduct 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 aesop 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 aesop 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 := PreservesBiproduct.preserves (biproduct.isBilimit _) } /-- If `F` preserves a biproduct, we get a definitionally nice isomorphism `F.obj (⨁ f) ≅ ⨁ (F.obj ∘ f)`. -/ @[simp] def mapBiproduct : F.obj (⨁ f) ≅ ⨁ F.obj ∘ f := biproduct.uniqueUpToIso _ (PreservesBiproduct.preserves (biproduct.isBilimit _)) theorem mapBiproduct_hom : haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f (mapBiproduct F f).hom = biproduct.lift fun j => F.map (biproduct.π f j) := rfl theorem mapBiproduct_inv : haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f (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 aesop 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 aesop 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 := PreservesBinaryBiproduct.preserves (BinaryBiproduct.isBilimit _ _) } /-- If `F` preserves a binary biproduct, we get a definitionally nice isomorphism `F.obj (X ⊞ Y) ≅ F.obj X ⊞ F.obj Y`. -/ @[simp] def mapBiprod : F.obj (X ⊞ Y) ≅ F.obj X ⊞ F.obj Y := biprod.uniqueUpToIso _ _ (PreservesBinaryBiproduct.preserves (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) : -- Porting note: twice we need haveI to tell Lean about hasBiproduct_of_preserves F f haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f 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] haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f simp only [mapBiproduct_hom, Category.assoc, biproduct.lift_π, ← F.map_comp] theorem biproduct.mapBiproduct_inv_map_desc (g : ∀ j, f j ⟶ W) : -- Porting note: twice we need haveI to tell Lean about hasBiproduct_of_preserves F f haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f (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] haveI : HasBiproduct fun j => F.obj (f j) := hasBiproduct_of_preserves F f 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
CategoryTheory\Limits\Preserves\Shapes\Equalizers.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ 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 (PreservesLimit.preserves 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) := ReflectsLimit.reflects ((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)`. -/ def PreservesEqualizer.ofIsoComparison [i : IsIso (equalizerComparison f g G)] : PreservesLimit (parallelPair f g) G := by apply preservesLimitOfPreservesLimitCone (equalizerIsEqualizer f g) apply (isLimitMapConeForkEquiv _ _).symm _ refine @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (parallelPair (G.map f) (G.map g))) ?_ apply 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 (PreservesColimit.preserves 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) := ReflectsColimit.reflects ((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)`. -/ def ofIsoComparison [i : IsIso (coequalizerComparison f g G)] : PreservesColimit (parallelPair f g) G := by apply preservesColimitOfPreservesColimitCocone (coequalizerIsCoequalizer f g) apply (isColimitMapCoconeCoforkEquiv _ _).symm _ refine @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (parallelPair (G.map f) (G.map g))) ?_ apply 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 preservesColimitOfPreservesColimitCocone (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 preservesLimitOfPreservesLimitCone (HasSplitEqualizer.isSplitEqualizer f g).isEqualizer apply (isLimitMapConeForkEquiv G _).symm ((HasSplitEqualizer.isSplitEqualizer f g).map G).isEqualizer end Coequalizers end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\Shapes\Images.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ 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
CategoryTheory\Limits\Preserves\Shapes\Kernels.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ 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 (_|_) <;> aesop_cat) /-- 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 (PreservesLimit.preserves 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`. -/ def PreservesKernel.ofIsoComparison [i : IsIso (kernelComparison f G)] : PreservesLimit (parallelPair f 0) G := by apply preservesLimitOfPreservesLimitCone (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 _) @[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 (_|_) <;> aesop_cat) /-- 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 (PreservesColimit.preserves 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`. -/ def PreservesCokernel.ofIsoComparison [i : IsIso (cokernelComparison f G)] : PreservesColimit (parallelPair f 0) G := by apply preservesColimitOfPreservesColimitCocone (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 _) @[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] noncomputable instance preservesKernelZero : 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 preservesCokernelZero : 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. -/ noncomputable def preservesKernelZero' (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. -/ noncomputable def preservesCokernelZero' (f : X ⟶ Y) (hf : f = 0) : PreservesColimit (parallelPair f 0) G := by rw [hf] infer_instance end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\Shapes\Products.lean
/- Copyright (c) 2020 Scott Morrison, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ 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 _ _ _ (PreservesLimit.preserves 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) := ReflectsLimit.reflects ((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`. -/ def PreservesProduct.ofIsoComparison [i : IsIso (piComparison G f)] : PreservesLimit (Discrete.functor f) G := by apply preservesLimitOfPreservesLimitCone (productIsProduct f) apply (isLimitMapConeFanMkEquiv _ _ _).symm _ refine @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (Discrete.functor fun j : J => G.obj (f j))) ?_ apply i 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 _ _ _ (PreservesColimit.preserves 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) := ReflectsColimit.reflects ((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`. -/ def PreservesCoproduct.ofIsoComparison [i : IsIso (sigmaComparison G f)] : PreservesColimit (Discrete.functor f) G := by apply preservesColimitOfPreservesColimitCocone (coproductIsCoproduct f) apply (isColimitMapCoconeCofanMkEquiv _ _ _).symm _ refine @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (Discrete.functor fun j : J => G.obj (f j))) ?_ apply i 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 end CategoryTheory.Limits
CategoryTheory\Limits\Preserves\Shapes\Pullbacks.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Opposites 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₂ -- Porting note: need Functor namespace for mapCone 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 (PreservesLimit.preserves 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) := ReflectsLimit.reflects ((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`. -/ def preservesPullbackSymmetry : 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 @PreservesLimit.preserves _ _ _ _ _ _ _ _ ?_ _ ?_ · dsimp infer_instance apply PullbackCone.isLimitOfFlip apply IsLimit.ofIsoLimit _ (PullbackCone.isoMk _) exact (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₁} _) _).invFun hc · 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 (PreservesColimit.preserves 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) := ReflectsColimit.reflects ((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`. -/ def preservesPushoutSymmetry : 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 · refine @PreservesColimit.preserves _ _ _ _ _ _ _ _ ?_ _ ?_ -- Porting note: more TC coddling · dsimp infer_instance · exact 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 delta PreservesPushout.iso simp @[reassoc] theorem PreservesPushout.inr_iso_hom : pushout.inr _ _ ≫ (PreservesPushout.iso G f g).hom = G.map (pushout.inr _ _) := by delta PreservesPushout.iso 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)`. -/ def PreservesPullback.ofIsoComparison [i : IsIso (pullbackComparison G f g)] : PreservesLimit (cospan f g) G := by apply preservesLimitOfPreservesLimitCone (pullbackIsPullback f g) apply (isLimitMapConePullbackConeEquiv _ _).symm _ refine @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (cospan (G.map f) (G.map g))) ?_ apply 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)`. -/ def PreservesPushout.ofIsoComparison [i : IsIso (pushoutComparison G f g)] : PreservesColimit (span f g) G := by apply preservesColimitOfPreservesColimitCocone (pushoutIsPushout f g) apply (isColimitMapCoconePushoutCoconeEquiv _ _).symm _ -- Porting note: apply no longer creates goals for instances refine @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (span (G.map f) (G.map g))) ?_ apply 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
CategoryTheory\Limits\Preserves\Shapes\Square.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Square import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Pullbacks /-! # 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 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) 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 _))))⟩ end Square end CategoryTheory
CategoryTheory\Limits\Preserves\Shapes\Terminal.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ 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 (PreservesLimit.preserves 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 := ReflectsLimit.reflects ((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 aesop_cat right_inv := by aesop_cat /-- Preserving the terminal object implies preserving all limits of the empty diagram. -/ def preservesLimitsOfShapePemptyOfPreservesTerminal [PreservesLimit (Functor.empty.{0} C) G] : PreservesLimitsOfShape (Discrete PEmpty) G where preservesLimit := preservesLimitOfIsoDiagram 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 hasLimitOfIso F.uniqueFromEmpty.symm⟩ variable [HasTerminal D] /-- If the terminal comparison map for `G` is an isomorphism, then `G` preserves terminal objects. -/ def PreservesTerminal.ofIsoComparison [i : IsIso (terminalComparison G)] : PreservesLimit (Functor.empty C) G := by apply preservesLimitOfPreservesLimitCone 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. -/ def preservesTerminalOfIsIso (f : G.obj (⊤_ C) ⟶ ⊤_ D) [i : IsIso f] : PreservesLimit (Functor.empty C) G := by rw [Subsingleton.elim f (terminalComparison G)] at i exact PreservesTerminal.ofIsoComparison G /-- If there is any isomorphism `G.obj ⊤ ≅ ⊤`, then `G` preserves terminal objects. -/ def preservesTerminalOfIso (f : G.obj (⊤_ C) ≅ ⊤_ D) : PreservesLimit (Functor.empty C) G := preservesTerminalOfIsIso 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 (PreservesColimit.preserves 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 := ReflectsColimit.reflects ((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 aesop_cat right_inv := by aesop_cat /-- Preserving the initial object implies preserving all colimits of the empty diagram. -/ def preservesColimitsOfShapePemptyOfPreservesInitial [PreservesColimit (Functor.empty.{0} C) G] : PreservesColimitsOfShape (Discrete PEmpty) G where preservesColimit := preservesColimitOfIsoDiagram 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 hasColimitOfIso F.uniqueFromEmpty⟩ variable [HasInitial D] /-- If the initial comparison map for `G` is an isomorphism, then `G` preserves initial objects. -/ def PreservesInitial.ofIsoComparison [i : IsIso (initialComparison G)] : PreservesColimit (Functor.empty C) G := by apply preservesColimitOfPreservesColimitCocone 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. -/ def preservesInitialOfIsIso (f : ⊥_ D ⟶ G.obj (⊥_ C)) [i : IsIso f] : PreservesColimit (Functor.empty C) G := by rw [Subsingleton.elim f (initialComparison G)] at i exact PreservesInitial.ofIsoComparison G /-- If there is any isomorphism `⊥ ≅ G.obj ⊥`, then `G` preserves initial objects. -/ def preservesInitialOfIso (f : ⊥_ D ≅ G.obj (⊥_ C)) : PreservesColimit (Functor.empty C) G := preservesInitialOfIsIso 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
CategoryTheory\Limits\Preserves\Shapes\Zero.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ 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 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. -/ def preservesTerminalObjectOfPreservesZeroMorphisms [PreservesZeroMorphisms F] : PreservesLimit (Functor.empty C) F := preservesTerminalOfIso F <| F.mapIso HasZeroObject.zeroIsoTerminal.symm ≪≫ mapZeroObject F ≪≫ HasZeroObject.zeroIsoTerminal /-- Preserving zero morphisms implies preserving terminal objects. -/ def preservesInitialObjectOfPreservesZeroMorphisms [PreservesZeroMorphisms F] : PreservesColimit (Functor.empty C) F := preservesInitialOfIso 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] /-- A zero functor preserves limits. -/ def preservesLimitsOfShapeOfIsZero : PreservesLimitsOfShape J G where preservesLimit {K} := ⟨fun hc => by rw [Functor.isZero_iff] at hG exact IsLimit.ofIsZero _ ((K ⋙ G).isZero (fun X ↦ hG _)) (hG _)⟩ /-- A zero functor preserves colimits. -/ def preservesColimitsOfShapeOfIsZero : PreservesColimitsOfShape J G where preservesColimit {K} := ⟨fun hc => by rw [Functor.isZero_iff] at hG exact IsColimit.ofIsZero _ ((K ⋙ G).isZero (fun X ↦ hG _)) (hG _)⟩ /-- A zero functor preserves limits. -/ def preservesLimitsOfSizeOfIsZero : PreservesLimitsOfSize.{v, u} G where preservesLimitsOfShape := G.preservesLimitsOfShapeOfIsZero hG _ /-- A zero functor preserves colimits. -/ def preservesColimitsOfSizeOfIsZero : PreservesColimitsOfSize.{v, u} G where preservesColimitsOfShape := G.preservesColimitsOfShapeOfIsZero hG _ end end CategoryTheory.Functor
CategoryTheory\Limits\Shapes\BinaryProducts.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over import Mathlib.CategoryTheory.DiscreteCategory import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Binary (co)products We define a category `WalkingPair`, which is the index category for a binary (co)product diagram. A convenience method `pair X Y` constructs the functor from the walking pair, hitting the given objects. We define `prod X Y` and `coprod X Y` as limits and colimits of such functors. Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence of (co)limits shaped as walking pairs. We include lemmas for simplifying equations involving projections and coprojections, and define braiding and associating isomorphisms, and the product comparison morphism. ## References * [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R) * [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN) -/ noncomputable section universe v u u₂ open CategoryTheory namespace CategoryTheory.Limits /-- The type of objects for the diagram indexing a binary (co)product. -/ inductive WalkingPair : Type | left | right deriving DecidableEq, Inhabited open WalkingPair /-- The equivalence swapping left and right. -/ def WalkingPair.swap : WalkingPair ≃ WalkingPair where toFun j := WalkingPair.recOn j right left invFun j := WalkingPair.recOn j right left left_inv j := by cases j; repeat rfl right_inv j := by cases j; repeat rfl @[simp] theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right := rfl @[simp] theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left := rfl @[simp] theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right := rfl @[simp] theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left := rfl /-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits. -/ def WalkingPair.equivBool : WalkingPair ≃ Bool where toFun j := WalkingPair.recOn j true false -- to match equiv.sum_equiv_sigma_bool invFun b := Bool.recOn b right left left_inv j := by cases j; repeat rfl right_inv b := by cases b; repeat rfl @[simp] theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true := rfl @[simp] theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right := rfl variable {C : Type u} /-- The function on the walking pair, sending the two points to `X` and `Y`. -/ def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y @[simp] theorem pairFunction_left (X Y : C) : pairFunction X Y left = X := rfl @[simp] theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y := rfl variable [Category.{v} C] /-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/ def pair (X Y : C) : Discrete WalkingPair ⥤ C := Discrete.functor fun j => WalkingPair.casesOn j X Y @[simp] theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X := rfl @[simp] theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y := rfl section variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- The natural transformation between two functors out of the walking pair, specified by its components. -/ def mapPair : F ⟶ G where app j := Discrete.recOn j fun j => WalkingPair.casesOn j f g naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat @[simp] theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f := rfl @[simp] theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g := rfl /-- The natural isomorphism between two functors out of the walking pair, specified by its components. -/ @[simps!] def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G := NatIso.ofComponents (fun j => Discrete.recOn j fun j => WalkingPair.casesOn j f g) (fun ⟨⟨u⟩⟩ => by aesop_cat) end /-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/ @[simps!] def diagramIsoPair (F : Discrete WalkingPair ⥤ C) : F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) := mapPairIso (Iso.refl _) (Iso.refl _) section variable {D : Type u} [Category.{v} D] /-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/ def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) := diagramIsoPair _ end /-- A binary fan is just a cone on a diagram indexing a product. -/ abbrev BinaryFan (X Y : C) := Cone (pair X Y) /-- The first projection of a binary fan. -/ abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.left⟩ /-- The second projection of a binary fan. -/ abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.right⟩ @[simp] theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst := rfl @[simp] theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd := rfl /-- A convenient way to show that a binary fan is a limit. -/ def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y) (lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt) (hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f) (hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g) (uniq : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g), m = lift f g) : IsLimit s := Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t)) (by rintro t (rfl | rfl) · exact hl₁ _ _ · exact hl₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt} (h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ /-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/ abbrev BinaryCofan (X Y : C) := Cocone (pair X Y) /-- The first inclusion of a binary cofan. -/ abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩ /-- The second inclusion of a binary cofan. -/ abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩ @[simp] theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl @[simp] theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl /-- A convenient way to show that a binary cofan is a colimit. -/ def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y) (desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T) (hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f) (hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g) (uniq : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g), m = desc f g) : IsColimit s := Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t)) (by rintro t (rfl | rfl) · exact hd₁ _ _ · exact hd₂ _ _) fun t m h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) {f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ variable {X Y : C} section attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/ @[simps pt] def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where pt := P π := { app := fun | { as := j } => match j with | left => π₁ | right => π₂ } /-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/ @[simps pt] def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where pt := P ι := { app := fun | { as := j } => match j with | left => ι₁ | right => ι₂ } end @[simp] theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ := rfl @[simp] theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ := rfl @[simp] theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ := rfl @[simp] theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ := rfl /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd := Cones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr := Cocones.ext (Iso.refl _) fun j => by cases' j with l; cases l; repeat simp /-- This is a more convenient formulation to show that a `BinaryFan` constructed using `BinaryFan.mk` is a limit cone. -/ def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W) (fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst) (fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd) (uniq : ∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (BinaryFan.mk fst snd) := { lift := lift fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- This is a more convenient formulation to show that a `BinaryCofan` constructed using `BinaryCofan.mk` is a colimit cocone. -/ def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W} (desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt) (fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl) (fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr) (uniq : ∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (BinaryCofan.mk inl inr) := { desc := desc fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`. -/ @[simps] def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } := ⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩ /-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`. -/ @[simps] def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W) (g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } := ⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩ /-- Binary products are symmetric. -/ def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) : IsLimit (BinaryFan.mk c.snd c.fst) := BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryFan.IsLimit.hom_ext hc (e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm) theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.fst := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X) exact ⟨⟨l, BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _) (h.hom_ext _ _), hl⟩⟩ · intro exact ⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩ theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.snd := by refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst)) exact ⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h => ⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩ /-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/ noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by fapply BinaryFan.isLimitMk · exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd) · intro s -- Porting note: simp timed out here simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id, BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc] · intro s -- Porting note: simp timed out here simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac] · intro s m e₁ e₂ -- Porting note: simpa timed out here also apply BinaryFan.IsLimit.hom_ext h · simpa only [BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv] · simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac] /-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/ noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) := BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h) /-- Binary coproducts are symmetric. -/ def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) : IsColimit (BinaryCofan.mk c.inr c.inl) := BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryCofan.IsColimit.hom_ext hc (e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm) theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inl := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X) refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩ rw [Category.comp_id] have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl rwa [Category.assoc,Category.id_comp] at e · intro exact ⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f) (fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => (IsIso.eq_inv_comp _).mpr e⟩ theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inr := by refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl)) exact ⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h => ⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩ /-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/ noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by fapply BinaryCofan.isColimitMk · exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr) · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] · intro s m e₁ e₂ apply BinaryCofan.IsColimit.hom_ext h · rw [← cancel_epi f] -- Porting note: simp timed out here too simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁ -- Porting note: simp timed out here too · simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] /-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/ noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) := BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h) /-- An abbreviation for `HasLimit (pair X Y)`. -/ abbrev HasBinaryProduct (X Y : C) := HasLimit (pair X Y) /-- An abbreviation for `HasColimit (pair X Y)`. -/ abbrev HasBinaryCoproduct (X Y : C) := HasColimit (pair X Y) /-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or `X ⨯ Y`. -/ abbrev prod (X Y : C) [HasBinaryProduct X Y] := limit (pair X Y) /-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or `X ⨿ Y`. -/ abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] := colimit (pair X Y) /-- Notation for the product -/ notation:20 X " ⨯ " Y:20 => prod X Y /-- Notation for the coproduct -/ notation:20 X " ⨿ " Y:20 => coprod X Y /-- The projection map to the first component of the product. -/ abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X := limit.π (pair X Y) ⟨WalkingPair.left⟩ /-- The projection map to the second component of the product. -/ abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y := limit.π (pair X Y) ⟨WalkingPair.right⟩ /-- The inclusion map from the first component of the coproduct. -/ abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.left⟩ /-- The inclusion map from the second component of the coproduct. -/ abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.right⟩ /-- The binary fan constructed from the projection maps is a limit. -/ def prodIsProd (X Y : C) [HasBinaryProduct X Y] : IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) := (limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.id_comp]; rfl · dsimp; simp only [Category.id_comp]; rfl )) /-- The binary cofan constructed from the coprojection maps is a colimit. -/ def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] : IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) := (colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.comp_id] · dsimp; simp only [Category.comp_id] )) @[ext 1100] theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y} (h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g := BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂ @[ext 1100] theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W} (h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂ /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/ abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y := limit.lift _ (BinaryFan.mk f g) /-- diagonal arrow of the binary product in the category `fam I` -/ abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X := prod.lift (𝟙 _) (𝟙 _) /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/ abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W := colimit.desc _ (BinaryCofan.mk f g) /-- codiagonal arrow of the binary coproduct -/ abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X := coprod.desc (𝟙 _) (𝟙 _) -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.fst = f := limit.lift_π _ _ -- Porting note (#10618): simp removes as simp can prove this @[reassoc] theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.snd = g := limit.lift_π _ _ -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inl ≫ coprod.desc f g = f := colimit.ι_desc _ _ -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: it can also prove the og version @[reassoc] theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inr ≫ coprod.desc f g = g := colimit.ι_desc _ _ instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_fst _ _ instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_snd _ _ instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inl_desc _ _ instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inr_desc _ _ /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/ def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } := ⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩ /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and `coprod.inr ≫ l = g`. -/ def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : { l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } := ⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩ /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/ def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z := limMap (mapPair f g) /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/ def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z := colimMap (mapPair f g) section ProdLemmas -- Making the reassoc version of this a simp lemma seems to be more harmful than helpful. @[reassoc, simp] theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) : f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) : f ≫ diag Y = prod.lift f f := by simp @[reassoc (attr := simp)] theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f := limMap_π _ _ @[reassoc (attr := simp)] theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g := limMap_π _ _ @[simp] theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp @[simp] theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] : prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp @[reassoc (attr := simp)] theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W) (g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) : prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp @[simp] theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by rw [← prod.lift_map] simp -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just -- as well. @[reassoc (attr := simp)] theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂] [HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp -- TODO: is it necessary to weaken the assumption here? @[reassoc] theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasLimitsOfShape (Discrete WalkingPair) C] : prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp @[reassoc] theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W] [HasBinaryProduct Z W] [HasBinaryProduct Y W] : prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp @[reassoc] theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X] [HasBinaryProduct W Y] [HasBinaryProduct W Z] : prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/ @[simps] def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where hom := prod.map f.hom g.hom inv := prod.map f.inv g.inv instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) := (prod.mapIso (asIso f) (asIso g)).isIso_hom instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_mono f] simpa using congr_arg (fun f => f ≫ prod.fst) h · rw [← cancel_mono g] simpa using congr_arg (fun f => f ≫ prod.snd) h⟩ @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] : diag X ≫ prod.map f f = f ≫ diag Y := by simp @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] : diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp @[reassoc] -- Porting note (#10618): simp can prove these theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) := IsSplitMono.mk' { retraction := prod.fst } end ProdLemmas section CoprodLemmas -- @[reassoc (attr := simp)] @[simp] -- Porting note: removing reassoc tag since result is not hygienic (two h's) theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by ext <;> simp -- Porting note: hand generated reassoc here. Simp can prove it theorem coprod.desc_comp_assoc {C : Type u} [Category C] {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) {Z : C} (l : W ⟶ Z) : coprod.desc g h ≫ f ≫ l = coprod.desc (g ≫ f) (h ≫ f) ≫ l := by simp theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) : codiag X ≫ f = coprod.desc f f := by simp @[reassoc (attr := simp)] theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl := ι_colimMap _ _ @[reassoc (attr := simp)] theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr := ι_colimMap _ _ @[simp] theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp @[simp] theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] : coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp -- The simp linter says simp can prove the reassoc version of this lemma. @[reassoc, simp] theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V] (f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) : coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by ext <;> simp @[simp] theorem coprod.desc_comp_inl_comp_inr {W X Y Z : C} [HasBinaryCoproduct W Y] [HasBinaryCoproduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : coprod.desc (g ≫ coprod.inl) (g' ≫ coprod.inr) = coprod.map g g' := by rw [← coprod.map_desc]; simp -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `inl_map` and `inr_map` can still work just -- as well. @[reassoc (attr := simp)] theorem coprod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryCoproduct A₁ B₁] [HasBinaryCoproduct A₂ B₂] [HasBinaryCoproduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : coprod.map f g ≫ coprod.map h k = coprod.map (f ≫ h) (g ≫ k) := by ext <;> simp -- I don't think it's a good idea to make any of the following three simp lemmas. @[reassoc] theorem coprod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasColimitsOfShape (Discrete WalkingPair) C] : coprod.map (𝟙 X) f ≫ coprod.map g (𝟙 B) = coprod.map g (𝟙 A) ≫ coprod.map (𝟙 Y) f := by simp @[reassoc] theorem coprod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct Z W] [HasBinaryCoproduct Y W] [HasBinaryCoproduct X W] : coprod.map (f ≫ g) (𝟙 W) = coprod.map f (𝟙 W) ≫ coprod.map g (𝟙 W) := by simp @[reassoc] theorem coprod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct W X] [HasBinaryCoproduct W Y] [HasBinaryCoproduct W Z] : coprod.map (𝟙 W) (f ≫ g) = coprod.map (𝟙 W) f ≫ coprod.map (𝟙 W) g := by simp /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : W ≅ Z` induces an isomorphism `coprod.mapIso f g : W ⨿ X ≅ Y ⨿ Z`. -/ @[simps] def coprod.mapIso {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨿ X ≅ Y ⨿ Z where hom := coprod.map f.hom g.hom inv := coprod.map f.inv g.inv instance isIso_coprod {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (coprod.map f g) := (coprod.mapIso (asIso f) (asIso g)).isIso_hom instance coprod.map_epi {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f] [Epi g] [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] : Epi (coprod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_epi f] simpa using congr_arg (fun f => coprod.inl ≫ f) h · rw [← cancel_epi g] simpa using congr_arg (fun f => coprod.inr ≫ f) h⟩ -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc] theorem coprod.map_codiag {X Y : C} (f : X ⟶ Y) [HasBinaryCoproduct X X] [HasBinaryCoproduct Y Y] : coprod.map f f ≫ codiag Y = codiag X ≫ f := by simp -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc] theorem coprod.map_inl_inr_codiag {X Y : C} [HasBinaryCoproduct X Y] [HasBinaryCoproduct (X ⨿ Y) (X ⨿ Y)] : coprod.map coprod.inl coprod.inr ≫ codiag (X ⨿ Y) = 𝟙 (X ⨿ Y) := by simp -- The simp linter says simp can prove the reassoc version of this lemma. -- Porting note: and the og version too @[reassoc] theorem coprod.map_comp_inl_inr_codiag [HasColimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : coprod.map (g ≫ coprod.inl) (g' ≫ coprod.inr) ≫ codiag (Y ⨿ Y') = coprod.map g g' := by simp end CoprodLemmas variable (C) /-- `HasBinaryProducts` represents a choice of product for every pair of objects. See <https://stacks.math.columbia.edu/tag/001T>. -/ abbrev HasBinaryProducts := HasLimitsOfShape (Discrete WalkingPair) C /-- `HasBinaryCoproducts` represents a choice of coproduct for every pair of objects. See <https://stacks.math.columbia.edu/tag/04AP>. -/ abbrev HasBinaryCoproducts := HasColimitsOfShape (Discrete WalkingPair) C /-- If `C` has all limits of diagrams `pair X Y`, then it has all binary products -/ theorem hasBinaryProducts_of_hasLimit_pair [∀ {X Y : C}, HasLimit (pair X Y)] : HasBinaryProducts C := { has_limit := fun F => hasLimitOfIso (diagramIsoPair F).symm } /-- If `C` has all colimits of diagrams `pair X Y`, then it has all binary coproducts -/ theorem hasBinaryCoproducts_of_hasColimit_pair [∀ {X Y : C}, HasColimit (pair X Y)] : HasBinaryCoproducts C := { has_colimit := fun F => hasColimitOfIso (diagramIsoPair F) } section variable {C} /-- The braiding isomorphism which swaps a binary product. -/ @[simps] def prod.braiding (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : P ⨯ Q ≅ Q ⨯ P where hom := prod.lift prod.snd prod.fst inv := prod.lift prod.snd prod.fst /-- The braiding isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem braid_natural [HasBinaryProducts C] {W X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ W) : prod.map f g ≫ (prod.braiding _ _).hom = (prod.braiding _ _).hom ≫ prod.map g f := by simp @[reassoc] theorem prod.symmetry' (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : prod.lift prod.snd prod.fst ≫ prod.lift prod.snd prod.fst = 𝟙 (P ⨯ Q) := (prod.braiding _ _).hom_inv_id /-- The braiding isomorphism is symmetric. -/ @[reassoc] theorem prod.symmetry (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : (prod.braiding P Q).hom ≫ (prod.braiding Q P).hom = 𝟙 _ := (prod.braiding _ _).hom_inv_id /-- The associator isomorphism for binary products. -/ @[simps] def prod.associator [HasBinaryProducts C] (P Q R : C) : (P ⨯ Q) ⨯ R ≅ P ⨯ Q ⨯ R where hom := prod.lift (prod.fst ≫ prod.fst) (prod.lift (prod.fst ≫ prod.snd) prod.snd) inv := prod.lift (prod.lift prod.fst (prod.snd ≫ prod.fst)) (prod.snd ≫ prod.snd) @[reassoc] theorem prod.pentagon [HasBinaryProducts C] (W X Y Z : C) : prod.map (prod.associator W X Y).hom (𝟙 Z) ≫ (prod.associator W (X ⨯ Y) Z).hom ≫ prod.map (𝟙 W) (prod.associator X Y Z).hom = (prod.associator (W ⨯ X) Y Z).hom ≫ (prod.associator W X (Y ⨯ Z)).hom := by simp @[reassoc] theorem prod.associator_naturality [HasBinaryProducts C] {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) : prod.map (prod.map f₁ f₂) f₃ ≫ (prod.associator Y₁ Y₂ Y₃).hom = (prod.associator X₁ X₂ X₃).hom ≫ prod.map f₁ (prod.map f₂ f₃) := by simp variable [HasTerminal C] /-- The left unitor isomorphism for binary products with the terminal object. -/ @[simps] def prod.leftUnitor (P : C) [HasBinaryProduct (⊤_ C) P] : (⊤_ C) ⨯ P ≅ P where hom := prod.snd inv := prod.lift (terminal.from P) (𝟙 _) hom_inv_id := by apply prod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp /-- The right unitor isomorphism for binary products with the terminal object. -/ @[simps] def prod.rightUnitor (P : C) [HasBinaryProduct P (⊤_ C)] : P ⨯ ⊤_ C ≅ P where hom := prod.fst inv := prod.lift (𝟙 _) (terminal.from P) hom_inv_id := by apply prod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp @[reassoc] theorem prod.leftUnitor_hom_naturality [HasBinaryProducts C] (f : X ⟶ Y) : prod.map (𝟙 _) f ≫ (prod.leftUnitor Y).hom = (prod.leftUnitor X).hom ≫ f := prod.map_snd _ _ @[reassoc] theorem prod.leftUnitor_inv_naturality [HasBinaryProducts C] (f : X ⟶ Y) : (prod.leftUnitor X).inv ≫ prod.map (𝟙 _) f = f ≫ (prod.leftUnitor Y).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, prod.leftUnitor_hom_naturality] @[reassoc] theorem prod.rightUnitor_hom_naturality [HasBinaryProducts C] (f : X ⟶ Y) : prod.map f (𝟙 _) ≫ (prod.rightUnitor Y).hom = (prod.rightUnitor X).hom ≫ f := prod.map_fst _ _ @[reassoc] theorem prod_rightUnitor_inv_naturality [HasBinaryProducts C] (f : X ⟶ Y) : (prod.rightUnitor X).inv ≫ prod.map f (𝟙 _) = f ≫ (prod.rightUnitor Y).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, prod.rightUnitor_hom_naturality] theorem prod.triangle [HasBinaryProducts C] (X Y : C) : (prod.associator X (⊤_ C) Y).hom ≫ prod.map (𝟙 X) (prod.leftUnitor Y).hom = prod.map (prod.rightUnitor X).hom (𝟙 Y) := by ext <;> simp end section variable {C} variable [HasBinaryCoproducts C] /-- The braiding isomorphism which swaps a binary coproduct. -/ @[simps] def coprod.braiding (P Q : C) : P ⨿ Q ≅ Q ⨿ P where hom := coprod.desc coprod.inr coprod.inl inv := coprod.desc coprod.inr coprod.inl @[reassoc] theorem coprod.symmetry' (P Q : C) : coprod.desc coprod.inr coprod.inl ≫ coprod.desc coprod.inr coprod.inl = 𝟙 (P ⨿ Q) := (coprod.braiding _ _).hom_inv_id /-- The braiding isomorphism is symmetric. -/ theorem coprod.symmetry (P Q : C) : (coprod.braiding P Q).hom ≫ (coprod.braiding Q P).hom = 𝟙 _ := coprod.symmetry' _ _ /-- The associator isomorphism for binary coproducts. -/ @[simps] def coprod.associator (P Q R : C) : (P ⨿ Q) ⨿ R ≅ P ⨿ Q ⨿ R where hom := coprod.desc (coprod.desc coprod.inl (coprod.inl ≫ coprod.inr)) (coprod.inr ≫ coprod.inr) inv := coprod.desc (coprod.inl ≫ coprod.inl) (coprod.desc (coprod.inr ≫ coprod.inl) coprod.inr) theorem coprod.pentagon (W X Y Z : C) : coprod.map (coprod.associator W X Y).hom (𝟙 Z) ≫ (coprod.associator W (X ⨿ Y) Z).hom ≫ coprod.map (𝟙 W) (coprod.associator X Y Z).hom = (coprod.associator (W ⨿ X) Y Z).hom ≫ (coprod.associator W X (Y ⨿ Z)).hom := by simp theorem coprod.associator_naturality {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) : coprod.map (coprod.map f₁ f₂) f₃ ≫ (coprod.associator Y₁ Y₂ Y₃).hom = (coprod.associator X₁ X₂ X₃).hom ≫ coprod.map f₁ (coprod.map f₂ f₃) := by simp variable [HasInitial C] /-- The left unitor isomorphism for binary coproducts with the initial object. -/ @[simps] def coprod.leftUnitor (P : C) : (⊥_ C) ⨿ P ≅ P where hom := coprod.desc (initial.to P) (𝟙 _) inv := coprod.inr hom_inv_id := by apply coprod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp /-- The right unitor isomorphism for binary coproducts with the initial object. -/ @[simps] def coprod.rightUnitor (P : C) : P ⨿ ⊥_ C ≅ P where hom := coprod.desc (𝟙 _) (initial.to P) inv := coprod.inl hom_inv_id := by apply coprod.hom_ext <;> simp [eq_iff_true_of_subsingleton] inv_hom_id := by simp theorem coprod.triangle (X Y : C) : (coprod.associator X (⊥_ C) Y).hom ≫ coprod.map (𝟙 X) (coprod.leftUnitor Y).hom = coprod.map (coprod.rightUnitor X).hom (𝟙 Y) := by ext <;> simp end section ProdFunctor -- Porting note (#10754): added category instance as it did not propagate variable {C} [Category.{v} C] [HasBinaryProducts C] /-- The binary product functor. -/ @[simps] def prod.functor : C ⥤ C ⥤ C where obj X := { obj := fun Y => X ⨯ Y map := fun {Y Z} => prod.map (𝟙 X) } map f := { app := fun T => prod.map f (𝟙 T) } /-- The product functor can be decomposed. -/ def prod.functorLeftComp (X Y : C) : prod.functor.obj (X ⨯ Y) ≅ prod.functor.obj Y ⋙ prod.functor.obj X := NatIso.ofComponents (prod.associator _ _) end ProdFunctor section CoprodFunctor -- Porting note (#10754): added category instance as it did not propagate variable {C} [Category.{v} C] [HasBinaryCoproducts C] /-- The binary coproduct functor. -/ @[simps] def coprod.functor : C ⥤ C ⥤ C where obj X := { obj := fun Y => X ⨿ Y map := fun {Y Z} => coprod.map (𝟙 X) } map f := { app := fun T => coprod.map f (𝟙 T) } /-- The coproduct functor can be decomposed. -/ def coprod.functorLeftComp (X Y : C) : coprod.functor.obj (X ⨿ Y) ≅ coprod.functor.obj Y ⋙ coprod.functor.obj X := NatIso.ofComponents (coprod.associator _ _) end CoprodFunctor section ProdComparison universe w w' u₃ variable {C} {D : Type u₂} [Category.{w} D] {E : Type u₃} [Category.{w'} E] variable (F : C ⥤ D) (G : D ⥤ E) {A A' B B' : C} variable [HasBinaryProduct A B] [HasBinaryProduct A' B'] variable [HasBinaryProduct (F.obj A) (F.obj B)] variable [HasBinaryProduct (F.obj A') (F.obj B')] variable [HasBinaryProduct (G.obj (F.obj A)) (G.obj (F.obj B))] variable [HasBinaryProduct ((F ⋙ G).obj A) ((F ⋙ G).obj B)] /-- The product comparison morphism. In `CategoryTheory/Limits/Preserves` we show this is always an iso iff F preserves binary products. -/ def prodComparison (F : C ⥤ D) (A B : C) [HasBinaryProduct A B] [HasBinaryProduct (F.obj A) (F.obj B)] : F.obj (A ⨯ B) ⟶ F.obj A ⨯ F.obj B := prod.lift (F.map prod.fst) (F.map prod.snd) variable (A B) @[reassoc (attr := simp)] theorem prodComparison_fst : prodComparison F A B ≫ prod.fst = F.map prod.fst := prod.lift_fst _ _ @[reassoc (attr := simp)] theorem prodComparison_snd : prodComparison F A B ≫ prod.snd = F.map prod.snd := prod.lift_snd _ _ variable {A B} /-- Naturality of the `prodComparison` morphism in both arguments. -/ @[reassoc] theorem prodComparison_natural (f : A ⟶ A') (g : B ⟶ B') : F.map (prod.map f g) ≫ prodComparison F A' B' = prodComparison F A B ≫ prod.map (F.map f) (F.map g) := by rw [prodComparison, prodComparison, prod.lift_map, ← F.map_comp, ← F.map_comp, prod.comp_lift, ← F.map_comp, prod.map_fst, ← F.map_comp, prod.map_snd] /-- The product comparison morphism from `F(A ⨯ -)` to `FA ⨯ F-`, whose components are given by `prodComparison`. -/ @[simps] def prodComparisonNatTrans [HasBinaryProducts C] [HasBinaryProducts D] (F : C ⥤ D) (A : C) : prod.functor.obj A ⋙ F ⟶ F ⋙ prod.functor.obj (F.obj A) where app B := prodComparison F A B naturality f := by simp [prodComparison_natural] @[reassoc] theorem inv_prodComparison_map_fst [IsIso (prodComparison F A B)] : inv (prodComparison F A B) ≫ F.map prod.fst = prod.fst := by simp [IsIso.inv_comp_eq] @[reassoc] theorem inv_prodComparison_map_snd [IsIso (prodComparison F A B)] : inv (prodComparison F A B) ≫ F.map prod.snd = prod.snd := by simp [IsIso.inv_comp_eq] /-- If the product comparison morphism is an iso, its inverse is natural. -/ @[reassoc] theorem prodComparison_inv_natural (f : A ⟶ A') (g : B ⟶ B') [IsIso (prodComparison F A B)] [IsIso (prodComparison F A' B')] : inv (prodComparison F A B) ≫ F.map (prod.map f g) = prod.map (F.map f) (F.map g) ≫ inv (prodComparison F A' B') := by rw [IsIso.eq_comp_inv, Category.assoc, IsIso.inv_comp_eq, prodComparison_natural] /-- The natural isomorphism `F(A ⨯ -) ≅ FA ⨯ F-`, provided each `prodComparison F A B` is an isomorphism (as `B` changes). -/ -- @[simps (config := { rhsMd := semireducible })] -- Porting note: no config for semireducible @[simps] def prodComparisonNatIso [HasBinaryProducts C] [HasBinaryProducts D] (A : C) [∀ B, IsIso (prodComparison F A B)] : prod.functor.obj A ⋙ F ≅ F ⋙ prod.functor.obj (F.obj A) := by refine { @asIso _ _ _ _ _ (?_) with hom := prodComparisonNatTrans F A } apply NatIso.isIso_of_isIso_app theorem prodComparison_comp : prodComparison (F ⋙ G) A B = G.map (prodComparison F A B) ≫ prodComparison G (F.obj A) (F.obj B) := by unfold prodComparison ext <;> simp <;> rw [← G.map_comp] <;> simp end ProdComparison section CoprodComparison universe w variable {C} {D : Type u₂} [Category.{w} D] variable (F : C ⥤ D) {A A' B B' : C} variable [HasBinaryCoproduct A B] [HasBinaryCoproduct A' B'] variable [HasBinaryCoproduct (F.obj A) (F.obj B)] [HasBinaryCoproduct (F.obj A') (F.obj B')] /-- The coproduct comparison morphism. In `CategoryTheory/Limits/Preserves` we show this is always an iso iff F preserves binary coproducts. -/ def coprodComparison (F : C ⥤ D) (A B : C) [HasBinaryCoproduct A B] [HasBinaryCoproduct (F.obj A) (F.obj B)] : F.obj A ⨿ F.obj B ⟶ F.obj (A ⨿ B) := coprod.desc (F.map coprod.inl) (F.map coprod.inr) @[reassoc (attr := simp)] theorem coprodComparison_inl : coprod.inl ≫ coprodComparison F A B = F.map coprod.inl := coprod.inl_desc _ _ @[reassoc (attr := simp)] theorem coprodComparison_inr : coprod.inr ≫ coprodComparison F A B = F.map coprod.inr := coprod.inr_desc _ _ /-- Naturality of the coprod_comparison morphism in both arguments. -/ @[reassoc] theorem coprodComparison_natural (f : A ⟶ A') (g : B ⟶ B') : coprodComparison F A B ≫ F.map (coprod.map f g) = coprod.map (F.map f) (F.map g) ≫ coprodComparison F A' B' := by rw [coprodComparison, coprodComparison, coprod.map_desc, ← F.map_comp, ← F.map_comp, coprod.desc_comp, ← F.map_comp, coprod.inl_map, ← F.map_comp, coprod.inr_map] /-- The coproduct comparison morphism from `FA ⨿ F-` to `F(A ⨿ -)`, whose components are given by `coprodComparison`. -/ @[simps] def coprodComparisonNatTrans [HasBinaryCoproducts C] [HasBinaryCoproducts D] (F : C ⥤ D) (A : C) : F ⋙ coprod.functor.obj (F.obj A) ⟶ coprod.functor.obj A ⋙ F where app B := coprodComparison F A B naturality f := by simp [coprodComparison_natural] @[reassoc] theorem map_inl_inv_coprodComparison [IsIso (coprodComparison F A B)] : F.map coprod.inl ≫ inv (coprodComparison F A B) = coprod.inl := by simp [IsIso.inv_comp_eq] @[reassoc] theorem map_inr_inv_coprodComparison [IsIso (coprodComparison F A B)] : F.map coprod.inr ≫ inv (coprodComparison F A B) = coprod.inr := by simp [IsIso.inv_comp_eq] /-- If the coproduct comparison morphism is an iso, its inverse is natural. -/ @[reassoc] theorem coprodComparison_inv_natural (f : A ⟶ A') (g : B ⟶ B') [IsIso (coprodComparison F A B)] [IsIso (coprodComparison F A' B')] : inv (coprodComparison F A B) ≫ coprod.map (F.map f) (F.map g) = F.map (coprod.map f g) ≫ inv (coprodComparison F A' B') := by rw [IsIso.eq_comp_inv, Category.assoc, IsIso.inv_comp_eq, coprodComparison_natural] /-- The natural isomorphism `FA ⨿ F- ≅ F(A ⨿ -)`, provided each `coprodComparison F A B` is an isomorphism (as `B` changes). -/ -- @[simps (config := { rhsMd := semireducible })] -- Porting note: no config for semireducible @[simps] def coprodComparisonNatIso [HasBinaryCoproducts C] [HasBinaryCoproducts D] (A : C) [∀ B, IsIso (coprodComparison F A B)] : F ⋙ coprod.functor.obj (F.obj A) ≅ coprod.functor.obj A ⋙ F := by refine { @asIso _ _ _ _ _ (?_) with hom := coprodComparisonNatTrans F A } apply NatIso.isIso_of_isIso_app -- Porting note: this did not work inside { } end CoprodComparison end CategoryTheory.Limits open CategoryTheory.Limits namespace CategoryTheory variable {C : Type u} [Category.{v} C] /-- Auxiliary definition for `Over.coprod`. -/ @[simps] def Over.coprodObj [HasBinaryCoproducts C] {A : C} : Over A → Over A ⥤ Over A := fun f => { obj := fun g => Over.mk (coprod.desc f.hom g.hom) map := fun k => Over.homMk (coprod.map (𝟙 _) k.left) } /-- A category with binary coproducts has a functorial `sup` operation on over categories. -/ @[simps] def Over.coprod [HasBinaryCoproducts C] {A : C} : Over A ⥤ Over A ⥤ Over A where obj f := Over.coprodObj f map k := { app := fun g => Over.homMk (coprod.map k.left (𝟙 _)) (by dsimp; rw [coprod.map_desc, Category.id_comp, Over.w k]) naturality := fun f g k => by ext dsimp; simp } map_id X := by ext dsimp; simp map_comp f g := by ext dsimp; simp end CategoryTheory
CategoryTheory\Limits\Shapes\Biproducts.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Jakob von Raumer -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Biproducts and binary biproducts We introduce the notion of (finite) biproducts and binary biproducts. These are slightly unusual relative to the other shapes in the library, as they are simultaneously limits and colimits. (Zero objects are similar; they are "biterminal".) For results about biproducts in preadditive categories see `CategoryTheory.Preadditive.Biproducts`. In a category with zero morphisms, we model the (binary) biproduct of `P Q : C` using a `BinaryBicone`, which has a cone point `X`, and morphisms `fst : X ⟶ P`, `snd : X ⟶ Q`, `inl : P ⟶ X` and `inr : X ⟶ Q`, such that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q`. Such a `BinaryBicone` is a biproduct if the cone is a limit cone, and the cocone is a colimit cocone. For biproducts indexed by a `Fintype J`, a `bicone` again consists of a cone point `X` and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`, such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. ## Notation As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for a binary biproduct. We introduce `⨁ f` for the indexed biproduct. ## Implementation notes Prior to leanprover-community/mathlib#14046, `HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type. As this had no pay-off (everything about limits is non-constructive in mathlib), and occasional cost (constructing decidability instances appropriate for constructions involving the indexing type), we made everything classical. -/ noncomputable section universe w w' v u open CategoryTheory open CategoryTheory.Functor open scoped Classical namespace CategoryTheory namespace Limits variable {J : Type w} universe uC' uC uD' uD variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] /-- A `c : Bicone F` is: * an object `c.pt` and * morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`, * such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure Bicone (F : J → C) where pt : C π : ∀ j, pt ⟶ F j ι : ∀ j, F j ⟶ pt ι_π : ∀ j j', ι j ≫ π j' = if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π @[reassoc (attr := simp)] theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by simpa using B.ι_π j j @[reassoc (attr := simp)] theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by simpa [h] using B.ι_π j j' variable {F : J → C} /-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points which commutes with the cone and cocone legs. -/ structure BiconeMorphism {F : J → C} (A B : Bicone F) where /-- A morphism between the two vertex objects of the bicones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wπ : ∀ j : J, hom ≫ B.π j = A.π j := by aesop_cat /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by aesop_cat attribute [reassoc (attr := simp)] BiconeMorphism.wι attribute [reassoc (attr := simp)] BiconeMorphism.wπ /-- The category of bicones on a given diagram. -/ @[simps] instance Bicone.category : Category (Bicone F) where Hom A B := BiconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Bicones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ -- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt) (wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by aesop_cat) (wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv wι := fun j => φ.comp_inv_eq.mpr (wι j).symm wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm } variable (F) in /-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/ @[simps] def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] : Bicone F ⥤ Bicone (G.obj ∘ F) where obj A := { pt := G.obj A.pt π := fun j => G.map (A.π j) ι := fun j => G.map (A.ι j) ι_π := fun i j => (Functor.map_comp _ _ _).symm.trans <| by rw [A.ι_π] aesop_cat } map f := { hom := G.map f.hom wπ := fun j => by simp [-BiconeMorphism.wπ, ← f.wπ j] wι := fun j => by simp [-BiconeMorphism.wι, ← f.wι j] } variable (G : C ⥤ D) instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom wι := fun j => G.map_injective (by simpa using t.wι j) wπ := fun j => G.map_injective (by simpa using t.wπ j) }, by aesop_cat⟩ instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] : (functoriality F G).Faithful where map_injective {_X} {_Y} f g h := BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h end Bicones namespace Bicone attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- Extract the cone from a bicone. -/ def toConeFunctor : Bicone F ⥤ Cone (Discrete.functor F) where obj B := { pt := B.pt, π := { app := fun j => B.π j.as } } map {X Y} F := { hom := F.hom, w := fun _ => F.wπ _ } /-- A shorthand for `toConeFunctor.obj` -/ abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B -- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`. @[simp] theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl @[simp] theorem toCone_π_app (B : Bicone F) (j : Discrete J) : B.toCone.π.app j = B.π j.as := rfl theorem toCone_π_app_mk (B : Bicone F) (j : J) : B.toCone.π.app ⟨j⟩ = B.π j := rfl @[simp] theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.π j := rfl /-- Extract the cocone from a bicone. -/ def toCoconeFunctor : Bicone F ⥤ Cocone (Discrete.functor F) where obj B := { pt := B.pt, ι := { app := fun j => B.ι j.as } } map {X Y} F := { hom := F.hom, w := fun _ => F.wι _ } /-- A shorthand for `toCoconeFunctor.obj` -/ abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B @[simp] theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl @[simp] theorem toCocone_ι_app (B : Bicone F) (j : Discrete J) : B.toCocone.ι.app j = B.ι j.as := rfl @[simp] theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ι j := rfl theorem toCocone_ι_app_mk (B : Bicone F) (j : J) : B.toCocone.ι.app ⟨j⟩ = B.ι j := rfl /-- We can turn any limit cone over a discrete collection of objects into a bicone. -/ @[simps] def ofLimitCone {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where pt := t.pt π j := t.π.app ⟨j⟩ ι j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) ι_π j j' := by simp theorem ι_of_isLimit {f : J → C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) : t.ι j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] /-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/ @[simps] def ofColimitCocone {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : Bicone f where pt := t.pt π j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) ι j := t.ι.app ⟨j⟩ ι_π j j' := by simp theorem π_of_isColimit {f : J → C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) : t.π j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] /-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure IsBilimit {F : J → C} (B : Bicone F) where isLimit : IsLimit B.toCone isColimit : IsColimit B.toCocone attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit -- Porting note (#10618): simp can prove this, linter doesn't notice it is removed attribute [-simp, nolint simpNF] IsBilimit.mk.injEq attribute [local ext] Bicone.IsBilimit instance subsingleton_isBilimit {f : J → C} {c : Bicone f} : Subsingleton c.IsBilimit := ⟨fun _ _ => Bicone.IsBilimit.ext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩ section Whisker variable {K : Type w'} /-- Whisker a bicone with an equivalence between the indexing types. -/ @[simps] def whisker {f : J → C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where pt := c.pt π k := c.π (g k) ι k := c.ι (g k) ι_π k k' := by simp only [c.ι_π] split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto /-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cone and postcomposing with a suitable isomorphism. -/ def whiskerToCone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCone ≅ (Cones.postcompose (Discrete.functorComp f g).inv).obj (c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cones.ext (Iso.refl _) (by aesop_cat) /-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cocone and precomposing with a suitable isomorphism. -/ def whiskerToCocone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCocone ≅ (Cocones.precompose (Discrete.functorComp f g).hom).obj (c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cocones.ext (Iso.refl _) (by aesop_cat) /-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/ def whiskerIsBilimitIff {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).IsBilimit ≃ c.IsBilimit := by refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩ · let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g) let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this · let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g) let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this · apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _ exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g) · apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _ exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g) end Whisker end Bicone /-- A bicone over `F : J → C`, which is both a limit cone and a colimit cocone. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitBicone (F : J → C) where bicone : Bicone F isBilimit : bicone.IsBilimit attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit /-- `HasBiproduct F` expresses the mere existence of a bicone which is simultaneously a limit and a colimit of the diagram `F`. -/ class HasBiproduct (F : J → C) : Prop where mk' :: exists_biproduct : Nonempty (LimitBicone F) attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct theorem HasBiproduct.mk {F : J → C} (d : LimitBicone F) : HasBiproduct F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/ def getBiproductData (F : J → C) [HasBiproduct F] : LimitBicone F := Classical.choice HasBiproduct.exists_biproduct /-- A bicone for `F` which is both a limit cone and a colimit cocone. -/ def biproduct.bicone (F : J → C) [HasBiproduct F] : Bicone F := (getBiproductData F).bicone /-- `biproduct.bicone F` is a bilimit bicone. -/ def biproduct.isBilimit (F : J → C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit := (getBiproductData F).isBilimit /-- `biproduct.bicone F` is a limit cone. -/ def biproduct.isLimit (F : J → C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone := (getBiproductData F).isBilimit.isLimit /-- `biproduct.bicone F` is a colimit cocone. -/ def biproduct.isColimit (F : J → C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone := (getBiproductData F).isBilimit.isColimit instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F := HasLimit.mk { cone := (biproduct.bicone F).toCone isLimit := biproduct.isLimit F } instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F := HasColimit.mk { cocone := (biproduct.bicone F).toCocone isColimit := biproduct.isColimit F } variable (J C) /-- `C` has biproducts of shape `J` if we have a limit and a colimit, with the same cone points, of every function `F : J → C`. -/ class HasBiproductsOfShape : Prop where has_biproduct : ∀ F : J → C, HasBiproduct F attribute [instance 100] HasBiproductsOfShape.has_biproduct /-- `HasFiniteBiproducts C` represents a choice of biproduct for every family of objects in `C` indexed by a finite type. -/ class HasFiniteBiproducts : Prop where out : ∀ n, HasBiproductsOfShape (Fin n) C attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out variable {J} theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) : HasBiproductsOfShape J C := ⟨fun F => let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm) let ⟨c, hc⟩ := h HasBiproduct.mk <| by simpa only [(· ∘ ·), e.symm_apply_apply] using LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩ instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] : HasBiproductsOfShape J C := by rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩ haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n exact hasBiproductsOfShape_of_equiv C e instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteProducts C where out _ := ⟨fun _ => hasLimitOfIso Discrete.natIsoFunctor.symm⟩ instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteCoproducts C where out _ := ⟨fun _ => hasColimitOfIso Discrete.natIsoFunctor⟩ variable {C} /-- The isomorphism between the specified limit and the specified colimit for a functor with a bilimit. -/ def biproductIso (F : J → C) [HasBiproduct F] : Limits.piObj F ≅ Limits.sigmaObj F := (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <| IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _) end Limits namespace Limits variable {J : Type w} {K : Type*} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] /-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will just use general facts about limits and colimits.) -/ abbrev biproduct (f : J → C) [HasBiproduct f] : C := (biproduct.bicone f).pt @[inherit_doc biproduct] notation "⨁ " f:20 => biproduct f /-- The projection onto a summand of a biproduct. -/ abbrev biproduct.π (f : J → C) [HasBiproduct f] (b : J) : ⨁ f ⟶ f b := (biproduct.bicone f).π b @[simp] theorem biproduct.bicone_π (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).π b = biproduct.π f b := rfl /-- The inclusion into a summand of a biproduct. -/ abbrev biproduct.ι (f : J → C) [HasBiproduct f] (b : J) : f b ⟶ ⨁ f := (biproduct.bicone f).ι b @[simp] theorem biproduct.bicone_ι (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).ι b = biproduct.ι f b := rfl /-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument. This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/ @[reassoc] theorem biproduct.ι_π [DecidableEq J] (f : J → C) [HasBiproduct f] (j j' : J) : biproduct.ι f j ≫ biproduct.π f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by convert (biproduct.bicone f).ι_π j j' @[reassoc] -- Porting note: both versions proven by simp theorem biproduct.ι_π_self (f : J → C) [HasBiproduct f] (j : J) : biproduct.ι f j ≫ biproduct.π f j = 𝟙 _ := by simp [biproduct.ι_π] @[reassoc (attr := simp)] theorem biproduct.ι_π_ne (f : J → C) [HasBiproduct f] {j j' : J} (h : j ≠ j') : biproduct.ι f j ≫ biproduct.π f j' = 0 := by simp [biproduct.ι_π, h] -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.eqToHom_comp_ι (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : eqToHom (by simp [w]) ≫ biproduct.ι f j' = biproduct.ι f j := by cases w simp -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.π_comp_eqToHom (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : biproduct.π f j ≫ eqToHom (by simp [w]) = biproduct.π f j' := by cases w simp /-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/ abbrev biproduct.lift {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ⨁ f := (biproduct.isLimit f).lift (Fan.mk P p) /-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/ abbrev biproduct.desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ⨁ f ⟶ P := (biproduct.isColimit f).desc (Cofan.mk P p) @[reassoc (attr := simp)] theorem biproduct.lift_π {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) (j : J) : biproduct.lift p ≫ biproduct.π f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩ @[reassoc (attr := simp)] theorem biproduct.ι_desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) (j : J) : biproduct.ι f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩ /-- Given a collection of maps between corresponding summands of a pair of biproducts indexed by the same type, we obtain a map between the biproducts. -/ abbrev biproduct.map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g) (Discrete.natTrans (fun j => p j.as)) /-- An alternative to `biproduct.map` constructed via colimits. This construction only exists in order to show it is equal to `biproduct.map`. -/ abbrev biproduct.map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) -- We put this at slightly higher priority than `biproduct.hom_ext'`, -- to get the matrix indices in the "right" order. @[ext 1001] theorem biproduct.hom_ext {f : J → C} [HasBiproduct f] {Z : C} (g h : Z ⟶ ⨁ f) (w : ∀ j, g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h := (biproduct.isLimit f).hom_ext fun j => w j.as @[ext] theorem biproduct.hom_ext' {f : J → C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟶ Z) (w : ∀ j, biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h := (biproduct.isColimit f).hom_ext fun j => w j.as /-- The canonical isomorphism between the chosen biproduct and the chosen product. -/ def biproduct.isoProduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∏ᶜ f := IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _) @[simp] theorem biproduct.isoProduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).hom = Pi.lift (biproduct.π f) := limit.hom_ext fun j => by simp [biproduct.isoProduct] @[simp] theorem biproduct.isoProduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).inv = biproduct.lift (Pi.π f) := biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq] /-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/ def biproduct.isoCoproduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∐ f := IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _) @[simp] theorem biproduct.isoCoproduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ι f) := colimit.hom_ext fun j => by simp [biproduct.isoCoproduct] @[simp] theorem biproduct.isoCoproduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ι f) := biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv] theorem biproduct.map_eq_map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : biproduct.map p = biproduct.map' p := by ext dsimp simp only [Discrete.natTrans_app, Limits.IsColimit.ι_map_assoc, Limits.IsLimit.map_π, Category.assoc, ← Bicone.toCone_π_app_mk, ← biproduct.bicone_π, ← Bicone.toCocone_ι_app_mk, ← biproduct.bicone_ι] dsimp rw [biproduct.ι_π_assoc, biproduct.ι_π] split_ifs with h · subst h; rw [eqToHom_refl, Category.id_comp]; erw [Category.comp_id] · simp @[reassoc (attr := simp)] theorem biproduct.map_π {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.map p ≫ biproduct.π g j = biproduct.π f j ≫ p j := Limits.IsLimit.map_π _ _ _ (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.ι_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.ι f j ≫ biproduct.map p = p j ≫ biproduct.ι g j := by rw [biproduct.map_eq_map'] apply Limits.IsColimit.ι_map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.map_desc {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) {P : C} (k : ∀ j, g j ⟶ P) : biproduct.map p ≫ biproduct.desc k = biproduct.desc fun j => p j ≫ k j := by ext; simp @[reassoc (attr := simp)] theorem biproduct.lift_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] {P : C} (k : ∀ j, P ⟶ f j) (p : ∀ j, f j ⟶ g j) : biproduct.lift k ≫ biproduct.map p = biproduct.lift fun j => k j ≫ p j := by ext; simp /-- Given a collection of isomorphisms between corresponding summands of a pair of biproducts indexed by the same type, we obtain an isomorphism between the biproducts. -/ @[simps] def biproduct.mapIso {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ≅ g b) : ⨁ f ≅ ⨁ g where hom := biproduct.map fun b => (p b).hom inv := biproduct.map fun b => (p b).inv /-- Two biproducts which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. Unfortunately there are two natural ways to define each direction of this isomorphism (because it is true for both products and coproducts separately). We give the alternative definitions as lemmas below. -/ @[simps] def biproduct.whiskerEquiv {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : ⨁ f ≅ ⨁ g where hom := biproduct.desc fun j => (w j).inv ≫ biproduct.ι g (e j) inv := biproduct.desc fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom ≫ biproduct.ι f _ lemma biproduct.whiskerEquiv_hom_eq_lift {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).hom = biproduct.lift fun k => biproduct.π f (e.symm k) ≫ (w _).inv ≫ eqToHom (by simp) := by simp only [whiskerEquiv_hom] ext k j by_cases h : k = e j · subst h simp · simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] · simp · rintro rfl simp at h · exact Ne.symm h lemma biproduct.whiskerEquiv_inv_eq_lift {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).inv = biproduct.lift fun j => biproduct.π g (e j) ≫ (w j).hom := by simp only [whiskerEquiv_inv] ext j k by_cases h : k = e j · subst h simp only [ι_desc_assoc, ← eqToHom_iso_hom_naturality_assoc w (e.symm_apply_apply j).symm, Equiv.symm_apply_apply, eqToHom_comp_ι, Category.assoc, bicone_ι_π_self, Category.comp_id, lift_π, bicone_ι_π_self_assoc] · simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] · simp · exact h · rintro rfl simp at h instance {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : HasBiproduct fun p : Σ i, f i => g p.1 p.2 where exists_biproduct := Nonempty.intro { bicone := { pt := ⨁ fun i => ⨁ g i ι := fun X => biproduct.ι (g X.1) X.2 ≫ biproduct.ι (fun i => ⨁ g i) X.1 π := fun X => biproduct.π (fun i => ⨁ g i) X.1 ≫ biproduct.π (g X.1) X.2 ι_π := fun ⟨j, x⟩ ⟨j', y⟩ => by split_ifs with h · obtain ⟨rfl, rfl⟩ := h simp · simp only [Sigma.mk.inj_iff, not_and] at h by_cases w : j = j' · cases w simp only [heq_eq_eq, forall_true_left] at h simp [biproduct.ι_π_ne _ h] · simp [biproduct.ι_π_ne_assoc _ w] } isBilimit := { isLimit := mkFanLimit _ (fun s => biproduct.lift fun b => biproduct.lift fun c => s.proj ⟨b, c⟩) isColimit := mkCofanColimit _ (fun s => biproduct.desc fun b => biproduct.desc fun c => s.inj ⟨b, c⟩) } } /-- An iterated biproduct is a biproduct over a sigma type. -/ @[simps] def biproductBiproductIso {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : (⨁ fun i => ⨁ g i) ≅ (⨁ fun p : Σ i, f i => g p.1 p.2) where hom := biproduct.lift fun ⟨i, x⟩ => biproduct.π _ i ≫ biproduct.π _ x inv := biproduct.lift fun i => biproduct.lift fun x => biproduct.π _ (⟨i, x⟩ : Σ i, f i) section πKernel section variable (f : J → C) [HasBiproduct f] variable (p : J → Prop) [HasBiproduct (Subtype.restrict p f)] /-- The canonical morphism from the biproduct over a restricted index type to the biproduct of the full index type. -/ def biproduct.fromSubtype : ⨁ Subtype.restrict p f ⟶ ⨁ f := biproduct.desc fun j => biproduct.ι _ j.val /-- The canonical morphism from a biproduct to the biproduct over a restriction of its index type. -/ def biproduct.toSubtype : ⨁ f ⟶ ⨁ Subtype.restrict p f := biproduct.lift fun _ => biproduct.π _ _ @[reassoc (attr := simp)] theorem biproduct.fromSubtype_π [DecidablePred p] (j : J) : biproduct.fromSubtype f p ≫ biproduct.π f j = if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := by ext i; dsimp rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π] by_cases h : p j · rw [dif_pos h, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] · rw [dif_neg h, dif_neg (show (i : J) ≠ j from fun h₂ => h (h₂ ▸ i.2)), comp_zero] theorem biproduct.fromSubtype_eq_lift [DecidablePred p] : biproduct.fromSubtype f p = biproduct.lift fun j => if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext _ _ (by simp) @[reassoc] -- Porting note: both version solved using simp theorem biproduct.fromSubtype_π_subtype (j : Subtype p) : biproduct.fromSubtype f p ≫ biproduct.π f j = biproduct.π (Subtype.restrict p f) j := by ext rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] @[reassoc (attr := simp)] theorem biproduct.toSubtype_π (j : Subtype p) : biproduct.toSubtype f p ≫ biproduct.π (Subtype.restrict p f) j = biproduct.π f j := biproduct.lift_π _ _ @[reassoc (attr := simp)] theorem biproduct.ι_toSubtype [DecidablePred p] (j : J) : biproduct.ι f j ≫ biproduct.toSubtype f p = if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := by ext i rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π] by_cases h : p j · rw [dif_pos h, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] · rw [dif_neg h, dif_neg (show j ≠ i from fun h₂ => h (h₂.symm ▸ i.2)), zero_comp] theorem biproduct.toSubtype_eq_desc [DecidablePred p] : biproduct.toSubtype f p = biproduct.desc fun j => if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext' _ _ (by simp) @[reassoc] -- Porting note (#10618): simp can prove both versions theorem biproduct.ι_toSubtype_subtype (j : Subtype p) : biproduct.ι f j ≫ biproduct.toSubtype f p = biproduct.ι (Subtype.restrict p f) j := by ext rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] @[reassoc (attr := simp)] theorem biproduct.ι_fromSubtype (j : Subtype p) : biproduct.ι (Subtype.restrict p f) j ≫ biproduct.fromSubtype f p = biproduct.ι f j := biproduct.ι_desc _ _ @[reassoc (attr := simp)] theorem biproduct.fromSubtype_toSubtype : biproduct.fromSubtype f p ≫ biproduct.toSubtype f p = 𝟙 (⨁ Subtype.restrict p f) := by refine biproduct.hom_ext _ _ fun j => ?_ rw [Category.assoc, biproduct.toSubtype_π, biproduct.fromSubtype_π_subtype, Category.id_comp] @[reassoc (attr := simp)] theorem biproduct.toSubtype_fromSubtype [DecidablePred p] : biproduct.toSubtype f p ≫ biproduct.fromSubtype f p = biproduct.map fun j => if p j then 𝟙 (f j) else 0 := by ext1 i by_cases h : p i · simp [h] · simp [h] end section variable (f : J → C) (i : J) [HasBiproduct f] [HasBiproduct (Subtype.restrict (fun j => j ≠ i) f)] /-- The kernel of `biproduct.π f i` is the inclusion from the biproduct which omits `i` from the index set `J` into the biproduct over `J`. -/ def biproduct.isLimitFromSubtype : IsLimit (KernelFork.ofι (biproduct.fromSubtype f fun j => j ≠ i) (by simp) : KernelFork (biproduct.π f i)) := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ biproduct.toSubtype _ _, by apply biproduct.hom_ext; intro j rw [KernelFork.ι_ofι, Category.assoc, Category.assoc, biproduct.toSubtype_fromSubtype_assoc, biproduct.map_π] rcases Classical.em (i = j) with (rfl | h) · rw [if_neg (Classical.not_not.2 rfl), comp_zero, comp_zero, KernelFork.condition] · rw [if_pos (Ne.symm h), Category.comp_id], by intro m hm rw [← hm, KernelFork.ι_ofι, Category.assoc, biproduct.fromSubtype_toSubtype] exact (Category.comp_id _).symm⟩ instance : HasKernel (biproduct.π f i) := HasLimit.mk ⟨_, biproduct.isLimitFromSubtype f i⟩ /-- The kernel of `biproduct.π f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/ @[simps!] def kernelBiproductπIso : kernel (biproduct.π f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f := limit.isoLimitCone ⟨_, biproduct.isLimitFromSubtype f i⟩ /-- The cokernel of `biproduct.ι f i` is the projection from the biproduct over the index set `J` onto the biproduct omitting `i`. -/ def biproduct.isColimitToSubtype : IsColimit (CokernelCofork.ofπ (biproduct.toSubtype f fun j => j ≠ i) (by simp) : CokernelCofork (biproduct.ι f i)) := Cofork.IsColimit.mk' _ fun s => ⟨biproduct.fromSubtype _ _ ≫ s.π, by apply biproduct.hom_ext'; intro j rw [CokernelCofork.π_ofπ, biproduct.toSubtype_fromSubtype_assoc, biproduct.ι_map_assoc] rcases Classical.em (i = j) with (rfl | h) · rw [if_neg (Classical.not_not.2 rfl), zero_comp, CokernelCofork.condition] · rw [if_pos (Ne.symm h), Category.id_comp], by intro m hm rw [← hm, CokernelCofork.π_ofπ, ← Category.assoc, biproduct.fromSubtype_toSubtype] exact (Category.id_comp _).symm⟩ instance : HasCokernel (biproduct.ι f i) := HasColimit.mk ⟨_, biproduct.isColimitToSubtype f i⟩ /-- The cokernel of `biproduct.ι f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/ @[simps!] def cokernelBiproductιIso : cokernel (biproduct.ι f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f := colimit.isoColimitCocone ⟨_, biproduct.isColimitToSubtype f i⟩ end section open scoped Classical -- Per leanprover-community/mathlib#15067, we only allow indexing in `Type 0` here. variable {K : Type} [Finite K] [HasFiniteBiproducts C] (f : K → C) /-- The limit cone exhibiting `⨁ Subtype.restrict pᶜ f` as the kernel of `biproduct.toSubtype f p` -/ @[simps] def kernelForkBiproductToSubtype (p : Set K) : LimitCone (parallelPair (biproduct.toSubtype f p) 0) where cone := KernelFork.ofι (biproduct.fromSubtype f pᶜ) (by ext j k simp only [Category.assoc, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] erw [dif_neg k.2] simp only [zero_comp]) isLimit := KernelFork.IsLimit.ofι _ _ (fun {W} g _ => g ≫ biproduct.toSubtype f pᶜ) (by intro W' g' w ext j simp only [Category.assoc, biproduct.toSubtype_fromSubtype, Pi.compl_apply, biproduct.map_π] split_ifs with h · simp · replace w := w =≫ biproduct.π _ ⟨j, not_not.mp h⟩ simpa using w.symm) (by aesop_cat) instance (p : Set K) : HasKernel (biproduct.toSubtype f p) := HasLimit.mk (kernelForkBiproductToSubtype f p) /-- The kernel of `biproduct.toSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/ @[simps!] def kernelBiproductToSubtypeIso (p : Set K) : kernel (biproduct.toSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f := limit.isoLimitCone (kernelForkBiproductToSubtype f p) /-- The colimit cocone exhibiting `⨁ Subtype.restrict pᶜ f` as the cokernel of `biproduct.fromSubtype f p` -/ @[simps] def cokernelCoforkBiproductFromSubtype (p : Set K) : ColimitCocone (parallelPair (biproduct.fromSubtype f p) 0) where cocone := CokernelCofork.ofπ (biproduct.toSubtype f pᶜ) (by ext j k simp only [Category.assoc, Pi.compl_apply, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] rw [dif_neg] · simp only [zero_comp] · exact not_not.mpr k.2) isColimit := CokernelCofork.IsColimit.ofπ _ _ (fun {W} g _ => biproduct.fromSubtype f pᶜ ≫ g) (by intro W g' w ext j simp only [biproduct.toSubtype_fromSubtype_assoc, Pi.compl_apply, biproduct.ι_map_assoc] split_ifs with h · simp · replace w := biproduct.ι _ (⟨j, not_not.mp h⟩ : p) ≫= w simpa using w.symm) (by aesop_cat) instance (p : Set K) : HasCokernel (biproduct.fromSubtype f p) := HasColimit.mk (cokernelCoforkBiproductFromSubtype f p) /-- The cokernel of `biproduct.fromSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/ @[simps!] def cokernelBiproductFromSubtypeIso (p : Set K) : cokernel (biproduct.fromSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f := colimit.isoColimitCocone (cokernelCoforkBiproductFromSubtype f p) end end πKernel end Limits namespace Limits section FiniteBiproducts variable {J : Type} [Finite J] {K : Type} [Finite K] {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasFiniteBiproducts C] {f : J → C} {g : K → C} /-- Convert a (dependently typed) matrix to a morphism of biproducts. -/ def biproduct.matrix (m : ∀ j k, f j ⟶ g k) : ⨁ f ⟶ ⨁ g := biproduct.desc fun j => biproduct.lift fun k => m j k @[reassoc (attr := simp)] theorem biproduct.matrix_π (m : ∀ j k, f j ⟶ g k) (k : K) : biproduct.matrix m ≫ biproduct.π g k = biproduct.desc fun j => m j k := by ext simp [biproduct.matrix] @[reassoc (attr := simp)] theorem biproduct.ι_matrix (m : ∀ j k, f j ⟶ g k) (j : J) : biproduct.ι f j ≫ biproduct.matrix m = biproduct.lift fun k => m j k := by ext simp [biproduct.matrix] /-- Extract the matrix components from a morphism of biproducts. -/ def biproduct.components (m : ⨁ f ⟶ ⨁ g) (j : J) (k : K) : f j ⟶ g k := biproduct.ι f j ≫ m ≫ biproduct.π g k @[simp] theorem biproduct.matrix_components (m : ∀ j k, f j ⟶ g k) (j : J) (k : K) : biproduct.components (biproduct.matrix m) j k = m j k := by simp [biproduct.components] @[simp] theorem biproduct.components_matrix (m : ⨁ f ⟶ ⨁ g) : (biproduct.matrix fun j k => biproduct.components m j k) = m := by ext simp [biproduct.components] /-- Morphisms between direct sums are matrices. -/ @[simps] def biproduct.matrixEquiv : (⨁ f ⟶ ⨁ g) ≃ ∀ j k, f j ⟶ g k where toFun := biproduct.components invFun := biproduct.matrix left_inv := biproduct.components_matrix right_inv m := by ext apply biproduct.matrix_components end FiniteBiproducts universe uD uD' variable {J : Type w} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] instance biproduct.ι_mono (f : J → C) [HasBiproduct f] (b : J) : IsSplitMono (biproduct.ι f b) := IsSplitMono.mk' { retraction := biproduct.desc <| Pi.single b (𝟙 (f b)) } instance biproduct.π_epi (f : J → C) [HasBiproduct f] (b : J) : IsSplitEpi (biproduct.π f b) := IsSplitEpi.mk' { section_ := biproduct.lift <| Pi.single b (𝟙 (f b)) } /-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/ theorem biproduct.conePointUniqueUpToIso_hom (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).hom = biproduct.lift b.π := rfl /-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/ theorem biproduct.conePointUniqueUpToIso_inv (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).inv = biproduct.desc b.ι := by refine biproduct.hom_ext' _ _ fun j => hb.isLimit.hom_ext fun j' => ?_ rw [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp, Bicone.toCone_π_app, biproduct.bicone_π, biproduct.ι_desc, biproduct.ι_π, b.toCone_π_app, b.ι_π] /-- Biproducts are unique up to isomorphism. This already follows because bilimits are limits, but in the case of biproducts we can give an isomorphism with particularly nice definitional properties, namely that `biproduct.lift b.π` and `biproduct.desc b.ι` are inverses of each other. -/ @[simps] def biproduct.uniqueUpToIso (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : b.pt ≅ ⨁ f where hom := biproduct.lift b.π inv := biproduct.desc b.ι hom_inv_id := by rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.hom_inv_id] inv_hom_id := by rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.inv_hom_id] variable (C) -- see Note [lower instance priority] /-- A category with finite biproducts has a zero object. -/ instance (priority := 100) hasZeroObject_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasZeroObject C := by refine ⟨⟨biproduct Empty.elim, fun X => ⟨⟨⟨0⟩, ?_⟩⟩, fun X => ⟨⟨⟨0⟩, ?_⟩⟩⟩⟩ · intro a; apply biproduct.hom_ext'; simp · intro a; apply biproduct.hom_ext; simp section variable {C} [Unique J] (f : J → C) attribute [local simp] eq_iff_true_of_subsingleton in /-- The limit bicone for the biproduct over an index type with exactly one term. -/ @[simps] def limitBiconeOfUnique : LimitBicone f where bicone := { pt := f default π := fun j => eqToHom (by congr; rw [← Unique.uniq] ) ι := fun j => eqToHom (by congr; rw [← Unique.uniq] ) } isBilimit := { isLimit := (limitConeOfUnique f).isLimit isColimit := (colimitCoconeOfUnique f).isColimit } instance (priority := 100) hasBiproduct_unique : HasBiproduct f := HasBiproduct.mk (limitBiconeOfUnique f) /-- A biproduct over an index type with exactly one term is just the object over that term. -/ @[simps!] def biproductUniqueIso : ⨁ f ≅ f default := (biproduct.uniqueUpToIso _ (limitBiconeOfUnique f).isBilimit).symm end variable {C} /-- A binary bicone for a pair of objects `P Q : C` consists of the cone point `X`, maps from `X` to both `P` and `Q`, and maps from both `P` and `Q` to `X`, so that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q` -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure BinaryBicone (P Q : C) where pt : C fst : pt ⟶ P snd : pt ⟶ Q inl : P ⟶ pt inr : Q ⟶ pt inl_fst : inl ≫ fst = 𝟙 P := by aesop inl_snd : inl ≫ snd = 0 := by aesop inr_fst : inr ≫ fst = 0 := by aesop inr_snd : inr ≫ snd = 𝟙 Q := by aesop attribute [inherit_doc BinaryBicone] BinaryBicone.pt BinaryBicone.fst BinaryBicone.snd BinaryBicone.inl BinaryBicone.inr BinaryBicone.inl_fst BinaryBicone.inl_snd BinaryBicone.inr_fst BinaryBicone.inr_snd attribute [reassoc (attr := simp)] BinaryBicone.inl_fst BinaryBicone.inl_snd BinaryBicone.inr_fst BinaryBicone.inr_snd /-- A binary bicone morphism between two binary bicones for the same diagram is a morphism of the binary bicone points which commutes with the cone and cocone legs. -/ structure BinaryBiconeMorphism {P Q : C} (A B : BinaryBicone P Q) where /-- A morphism between the two vertex objects of the bicones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wfst : hom ≫ B.fst = A.fst := by aesop_cat /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wsnd : hom ≫ B.snd = A.snd := by aesop_cat /-- The triangle consisting of the two natural transformations and `hom` commutes -/ winl : A.inl ≫ hom = B.inl := by aesop_cat /-- The triangle consisting of the two natural transformations and `hom` commutes -/ winr : A.inr ≫ hom = B.inr := by aesop_cat attribute [reassoc (attr := simp)] BinaryBiconeMorphism.wfst BinaryBiconeMorphism.wsnd attribute [reassoc (attr := simp)] BinaryBiconeMorphism.winl BinaryBiconeMorphism.winr /-- The category of binary bicones on a given diagram. -/ @[simps] instance BinaryBicone.category {P Q : C} : Category (BinaryBicone P Q) where Hom A B := BinaryBiconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem BinaryBiconeMorphism.ext {P Q : C} {c c' : BinaryBicone P Q} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace BinaryBicones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ -- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {P Q : C} {c c' : BinaryBicone P Q} (φ : c.pt ≅ c'.pt) (winl : c.inl ≫ φ.hom = c'.inl := by aesop_cat) (winr : c.inr ≫ φ.hom = c'.inr := by aesop_cat) (wfst : φ.hom ≫ c'.fst = c.fst := by aesop_cat) (wsnd : φ.hom ≫ c'.snd = c.snd := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv wfst := φ.inv_comp_eq.mpr wfst.symm wsnd := φ.inv_comp_eq.mpr wsnd.symm winl := φ.comp_inv_eq.mpr winl.symm winr := φ.comp_inv_eq.mpr winr.symm } variable (P Q : C) (F : C ⥤ D) [Functor.PreservesZeroMorphisms F] /-- A functor `F : C ⥤ D` sends binary bicones for `P` and `Q` to binary bicones for `G.obj P` and `G.obj Q` functorially. -/ @[simps] def functoriality : BinaryBicone P Q ⥤ BinaryBicone (F.obj P) (F.obj Q) where obj A := { pt := F.obj A.pt fst := F.map A.fst snd := F.map A.snd inl := F.map A.inl inr := F.map A.inr inl_fst := by rw [← F.map_comp, A.inl_fst, F.map_id] inl_snd := by rw [← F.map_comp, A.inl_snd, F.map_zero] inr_fst := by rw [← F.map_comp, A.inr_fst, F.map_zero] inr_snd := by rw [← F.map_comp, A.inr_snd, F.map_id] } map f := { hom := F.map f.hom wfst := by simp [-BinaryBiconeMorphism.wfst, ← f.wfst] wsnd := by simp [-BinaryBiconeMorphism.wsnd, ← f.wsnd] winl := by simp [-BinaryBiconeMorphism.winl, ← f.winl] winr := by simp [-BinaryBiconeMorphism.winr, ← f.winr] } instance functoriality_full [F.Full] [F.Faithful] : (functoriality P Q F).Full where map_surjective t := ⟨{ hom := F.preimage t.hom winl := F.map_injective (by simpa using t.winl) winr := F.map_injective (by simpa using t.winr) wfst := F.map_injective (by simpa using t.wfst) wsnd := F.map_injective (by simpa using t.wsnd) }, by aesop_cat⟩ instance functoriality_faithful [F.Faithful] : (functoriality P Q F).Faithful where map_injective {_X} {_Y} f g h := BinaryBiconeMorphism.ext f g <| F.map_injective <| congr_arg BinaryBiconeMorphism.hom h end BinaryBicones namespace BinaryBicone variable {P Q : C} /-- Extract the cone from a binary bicone. -/ def toCone (c : BinaryBicone P Q) : Cone (pair P Q) := BinaryFan.mk c.fst c.snd @[simp] theorem toCone_pt (c : BinaryBicone P Q) : c.toCone.pt = c.pt := rfl @[simp] theorem toCone_π_app_left (c : BinaryBicone P Q) : c.toCone.π.app ⟨WalkingPair.left⟩ = c.fst := rfl @[simp] theorem toCone_π_app_right (c : BinaryBicone P Q) : c.toCone.π.app ⟨WalkingPair.right⟩ = c.snd := rfl @[simp] theorem binary_fan_fst_toCone (c : BinaryBicone P Q) : BinaryFan.fst c.toCone = c.fst := rfl @[simp] theorem binary_fan_snd_toCone (c : BinaryBicone P Q) : BinaryFan.snd c.toCone = c.snd := rfl /-- Extract the cocone from a binary bicone. -/ def toCocone (c : BinaryBicone P Q) : Cocone (pair P Q) := BinaryCofan.mk c.inl c.inr @[simp] theorem toCocone_pt (c : BinaryBicone P Q) : c.toCocone.pt = c.pt := rfl @[simp] theorem toCocone_ι_app_left (c : BinaryBicone P Q) : c.toCocone.ι.app ⟨WalkingPair.left⟩ = c.inl := rfl @[simp] theorem toCocone_ι_app_right (c : BinaryBicone P Q) : c.toCocone.ι.app ⟨WalkingPair.right⟩ = c.inr := rfl @[simp] theorem binary_cofan_inl_toCocone (c : BinaryBicone P Q) : BinaryCofan.inl c.toCocone = c.inl := rfl @[simp] theorem binary_cofan_inr_toCocone (c : BinaryBicone P Q) : BinaryCofan.inr c.toCocone = c.inr := rfl instance (c : BinaryBicone P Q) : IsSplitMono c.inl := IsSplitMono.mk' { retraction := c.fst id := c.inl_fst } instance (c : BinaryBicone P Q) : IsSplitMono c.inr := IsSplitMono.mk' { retraction := c.snd id := c.inr_snd } instance (c : BinaryBicone P Q) : IsSplitEpi c.fst := IsSplitEpi.mk' { section_ := c.inl id := c.inl_fst } instance (c : BinaryBicone P Q) : IsSplitEpi c.snd := IsSplitEpi.mk' { section_ := c.inr id := c.inr_snd } /-- Convert a `BinaryBicone` into a `Bicone` over a pair. -/ @[simps] def toBiconeFunctor {X Y : C} : BinaryBicone X Y ⥤ Bicone (pairFunction X Y) where obj b := { pt := b.pt π := fun j => WalkingPair.casesOn j b.fst b.snd ι := fun j => WalkingPair.casesOn j b.inl b.inr ι_π := fun j j' => by rcases j with ⟨⟩ <;> rcases j' with ⟨⟩ <;> simp } map f := { hom := f.hom wπ := fun i => WalkingPair.casesOn i f.wfst f.wsnd wι := fun i => WalkingPair.casesOn i f.winl f.winr } /-- A shorthand for `toBiconeFunctor.obj` -/ abbrev toBicone {X Y : C} (b : BinaryBicone X Y) : Bicone (pairFunction X Y) := toBiconeFunctor.obj b /-- A binary bicone is a limit cone if and only if the corresponding bicone is a limit cone. -/ def toBiconeIsLimit {X Y : C} (b : BinaryBicone X Y) : IsLimit b.toBicone.toCone ≃ IsLimit b.toCone := IsLimit.equivIsoLimit <| Cones.ext (Iso.refl _) fun j => by cases' j with as; cases as <;> simp /-- A binary bicone is a colimit cocone if and only if the corresponding bicone is a colimit cocone. -/ def toBiconeIsColimit {X Y : C} (b : BinaryBicone X Y) : IsColimit b.toBicone.toCocone ≃ IsColimit b.toCocone := IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) fun j => by cases' j with as; cases as <;> simp end BinaryBicone namespace Bicone /-- Convert a `Bicone` over a function on `WalkingPair` to a BinaryBicone. -/ @[simps] def toBinaryBiconeFunctor {X Y : C} : Bicone (pairFunction X Y) ⥤ BinaryBicone X Y where obj b := { pt := b.pt fst := b.π WalkingPair.left snd := b.π WalkingPair.right inl := b.ι WalkingPair.left inr := b.ι WalkingPair.right inl_fst := by simp [Bicone.ι_π] inr_fst := by simp [Bicone.ι_π] inl_snd := by simp [Bicone.ι_π] inr_snd := by simp [Bicone.ι_π] } map f := { hom := f.hom } /-- A shorthand for `toBinaryBiconeFunctor.obj` -/ abbrev toBinaryBicone {X Y : C} (b : Bicone (pairFunction X Y)) : BinaryBicone X Y := toBinaryBiconeFunctor.obj b /-- A bicone over a pair is a limit cone if and only if the corresponding binary bicone is a limit cone. -/ def toBinaryBiconeIsLimit {X Y : C} (b : Bicone (pairFunction X Y)) : IsLimit b.toBinaryBicone.toCone ≃ IsLimit b.toCone := IsLimit.equivIsoLimit <| Cones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp /-- A bicone over a pair is a colimit cocone if and only if the corresponding binary bicone is a colimit cocone. -/ def toBinaryBiconeIsColimit {X Y : C} (b : Bicone (pairFunction X Y)) : IsColimit b.toBinaryBicone.toCocone ≃ IsColimit b.toCocone := IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp end Bicone /-- Structure witnessing that a binary bicone is a limit cone and a limit cocone. -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure BinaryBicone.IsBilimit {P Q : C} (b : BinaryBicone P Q) where isLimit : IsLimit b.toCone isColimit : IsColimit b.toCocone attribute [inherit_doc BinaryBicone.IsBilimit] BinaryBicone.IsBilimit.isLimit BinaryBicone.IsBilimit.isColimit /-- A binary bicone is a bilimit bicone if and only if the corresponding bicone is a bilimit. -/ def BinaryBicone.toBiconeIsBilimit {X Y : C} (b : BinaryBicone X Y) : b.toBicone.IsBilimit ≃ b.IsBilimit where toFun h := ⟨b.toBiconeIsLimit h.isLimit, b.toBiconeIsColimit h.isColimit⟩ invFun h := ⟨b.toBiconeIsLimit.symm h.isLimit, b.toBiconeIsColimit.symm h.isColimit⟩ left_inv := fun ⟨h, h'⟩ => by dsimp only; simp right_inv := fun ⟨h, h'⟩ => by dsimp only; simp /-- A bicone over a pair is a bilimit bicone if and only if the corresponding binary bicone is a bilimit. -/ def Bicone.toBinaryBiconeIsBilimit {X Y : C} (b : Bicone (pairFunction X Y)) : b.toBinaryBicone.IsBilimit ≃ b.IsBilimit where toFun h := ⟨b.toBinaryBiconeIsLimit h.isLimit, b.toBinaryBiconeIsColimit h.isColimit⟩ invFun h := ⟨b.toBinaryBiconeIsLimit.symm h.isLimit, b.toBinaryBiconeIsColimit.symm h.isColimit⟩ left_inv := fun ⟨h, h'⟩ => by dsimp only; simp right_inv := fun ⟨h, h'⟩ => by dsimp only; simp /-- A bicone over `P Q : C`, which is both a limit cone and a colimit cocone. -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure BinaryBiproductData (P Q : C) where bicone : BinaryBicone P Q isBilimit : bicone.IsBilimit attribute [inherit_doc BinaryBiproductData] BinaryBiproductData.bicone BinaryBiproductData.isBilimit /-- `HasBinaryBiproduct P Q` expresses the mere existence of a bicone which is simultaneously a limit and a colimit of the diagram `pair P Q`. -/ class HasBinaryBiproduct (P Q : C) : Prop where mk' :: exists_binary_biproduct : Nonempty (BinaryBiproductData P Q) attribute [inherit_doc HasBinaryBiproduct] HasBinaryBiproduct.exists_binary_biproduct theorem HasBinaryBiproduct.mk {P Q : C} (d : BinaryBiproductData P Q) : HasBinaryBiproduct P Q := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `BinaryBiproductData F` from `HasBinaryBiproduct F`. -/ def getBinaryBiproductData (P Q : C) [HasBinaryBiproduct P Q] : BinaryBiproductData P Q := Classical.choice HasBinaryBiproduct.exists_binary_biproduct /-- A bicone for `P Q` which is both a limit cone and a colimit cocone. -/ def BinaryBiproduct.bicone (P Q : C) [HasBinaryBiproduct P Q] : BinaryBicone P Q := (getBinaryBiproductData P Q).bicone /-- `BinaryBiproduct.bicone P Q` is a limit bicone. -/ def BinaryBiproduct.isBilimit (P Q : C) [HasBinaryBiproduct P Q] : (BinaryBiproduct.bicone P Q).IsBilimit := (getBinaryBiproductData P Q).isBilimit /-- `BinaryBiproduct.bicone P Q` is a limit cone. -/ def BinaryBiproduct.isLimit (P Q : C) [HasBinaryBiproduct P Q] : IsLimit (BinaryBiproduct.bicone P Q).toCone := (getBinaryBiproductData P Q).isBilimit.isLimit /-- `BinaryBiproduct.bicone P Q` is a colimit cocone. -/ def BinaryBiproduct.isColimit (P Q : C) [HasBinaryBiproduct P Q] : IsColimit (BinaryBiproduct.bicone P Q).toCocone := (getBinaryBiproductData P Q).isBilimit.isColimit section variable (C) /-- `HasBinaryBiproducts C` represents the existence of a bicone which is simultaneously a limit and a colimit of the diagram `pair P Q`, for every `P Q : C`. -/ class HasBinaryBiproducts : Prop where has_binary_biproduct : ∀ P Q : C, HasBinaryBiproduct P Q attribute [instance 100] HasBinaryBiproducts.has_binary_biproduct /-- A category with finite biproducts has binary biproducts. This is not an instance as typically in concrete categories there will be an alternative construction with nicer definitional properties. -/ theorem hasBinaryBiproducts_of_finite_biproducts [HasFiniteBiproducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun P Q => HasBinaryBiproduct.mk { bicone := (biproduct.bicone (pairFunction P Q)).toBinaryBicone isBilimit := (Bicone.toBinaryBiconeIsBilimit _).symm (biproduct.isBilimit _) } } end variable {P Q : C} instance HasBinaryBiproduct.hasLimit_pair [HasBinaryBiproduct P Q] : HasLimit (pair P Q) := HasLimit.mk ⟨_, BinaryBiproduct.isLimit P Q⟩ instance HasBinaryBiproduct.hasColimit_pair [HasBinaryBiproduct P Q] : HasColimit (pair P Q) := HasColimit.mk ⟨_, BinaryBiproduct.isColimit P Q⟩ instance (priority := 100) hasBinaryProducts_of_hasBinaryBiproducts [HasBinaryBiproducts C] : HasBinaryProducts C where has_limit F := hasLimitOfIso (diagramIsoPair F).symm instance (priority := 100) hasBinaryCoproducts_of_hasBinaryBiproducts [HasBinaryBiproducts C] : HasBinaryCoproducts C where has_colimit F := hasColimitOfIso (diagramIsoPair F) /-- The isomorphism between the specified binary product and the specified binary coproduct for a pair for a binary biproduct. -/ def biprodIso (X Y : C) [HasBinaryBiproduct X Y] : Limits.prod X Y ≅ Limits.coprod X Y := (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (BinaryBiproduct.isLimit X Y)).trans <| IsColimit.coconePointUniqueUpToIso (BinaryBiproduct.isColimit X Y) (colimit.isColimit _) /-- An arbitrary choice of biproduct of a pair of objects. -/ abbrev biprod (X Y : C) [HasBinaryBiproduct X Y] := (BinaryBiproduct.bicone X Y).pt @[inherit_doc biprod] notation:20 X " ⊞ " Y:20 => biprod X Y /-- The projection onto the first summand of a binary biproduct. -/ abbrev biprod.fst {X Y : C} [HasBinaryBiproduct X Y] : X ⊞ Y ⟶ X := (BinaryBiproduct.bicone X Y).fst /-- The projection onto the second summand of a binary biproduct. -/ abbrev biprod.snd {X Y : C} [HasBinaryBiproduct X Y] : X ⊞ Y ⟶ Y := (BinaryBiproduct.bicone X Y).snd /-- The inclusion into the first summand of a binary biproduct. -/ abbrev biprod.inl {X Y : C} [HasBinaryBiproduct X Y] : X ⟶ X ⊞ Y := (BinaryBiproduct.bicone X Y).inl /-- The inclusion into the second summand of a binary biproduct. -/ abbrev biprod.inr {X Y : C} [HasBinaryBiproduct X Y] : Y ⟶ X ⊞ Y := (BinaryBiproduct.bicone X Y).inr section variable {X Y : C} [HasBinaryBiproduct X Y] @[simp] theorem BinaryBiproduct.bicone_fst : (BinaryBiproduct.bicone X Y).fst = biprod.fst := rfl @[simp] theorem BinaryBiproduct.bicone_snd : (BinaryBiproduct.bicone X Y).snd = biprod.snd := rfl @[simp] theorem BinaryBiproduct.bicone_inl : (BinaryBiproduct.bicone X Y).inl = biprod.inl := rfl @[simp] theorem BinaryBiproduct.bicone_inr : (BinaryBiproduct.bicone X Y).inr = biprod.inr := rfl end @[reassoc] -- Porting note: simp can solve both versions theorem biprod.inl_fst {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inl : X ⟶ X ⊞ Y) ≫ (biprod.fst : X ⊞ Y ⟶ X) = 𝟙 X := (BinaryBiproduct.bicone X Y).inl_fst @[reassoc] -- Porting note: simp can solve both versions theorem biprod.inl_snd {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inl : X ⟶ X ⊞ Y) ≫ (biprod.snd : X ⊞ Y ⟶ Y) = 0 := (BinaryBiproduct.bicone X Y).inl_snd @[reassoc] -- Porting note: simp can solve both versions theorem biprod.inr_fst {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inr : Y ⟶ X ⊞ Y) ≫ (biprod.fst : X ⊞ Y ⟶ X) = 0 := (BinaryBiproduct.bicone X Y).inr_fst @[reassoc] -- Porting note: simp can solve both versions theorem biprod.inr_snd {X Y : C} [HasBinaryBiproduct X Y] : (biprod.inr : Y ⟶ X ⊞ Y) ≫ (biprod.snd : X ⊞ Y ⟶ Y) = 𝟙 Y := (BinaryBiproduct.bicone X Y).inr_snd /-- Given a pair of maps into the summands of a binary biproduct, we obtain a map into the binary biproduct. -/ abbrev biprod.lift {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⊞ Y := (BinaryBiproduct.isLimit X Y).lift (BinaryFan.mk f g) /-- Given a pair of maps out of the summands of a binary biproduct, we obtain a map out of the binary biproduct. -/ abbrev biprod.desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⊞ Y ⟶ W := (BinaryBiproduct.isColimit X Y).desc (BinaryCofan.mk f g) @[reassoc (attr := simp)] theorem biprod.lift_fst {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : biprod.lift f g ≫ biprod.fst = f := (BinaryBiproduct.isLimit X Y).fac _ ⟨WalkingPair.left⟩ @[reassoc (attr := simp)] theorem biprod.lift_snd {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : biprod.lift f g ≫ biprod.snd = g := (BinaryBiproduct.isLimit X Y).fac _ ⟨WalkingPair.right⟩ @[reassoc (attr := simp)] theorem biprod.inl_desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : biprod.inl ≫ biprod.desc f g = f := (BinaryBiproduct.isColimit X Y).fac _ ⟨WalkingPair.left⟩ @[reassoc (attr := simp)] theorem biprod.inr_desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : biprod.inr ≫ biprod.desc f g = g := (BinaryBiproduct.isColimit X Y).fac _ ⟨WalkingPair.right⟩ instance biprod.mono_lift_of_mono_left {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (biprod.lift f g) := mono_of_mono_fac <| biprod.lift_fst _ _ instance biprod.mono_lift_of_mono_right {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (biprod.lift f g) := mono_of_mono_fac <| biprod.lift_snd _ _ instance biprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (biprod.desc f g) := epi_of_epi_fac <| biprod.inl_desc _ _ instance biprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (biprod.desc f g) := epi_of_epi_fac <| biprod.inr_desc _ _ /-- Given a pair of maps between the summands of a pair of binary biproducts, we obtain a map between the binary biproducts. -/ abbrev biprod.map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z := IsLimit.map (BinaryBiproduct.bicone W X).toCone (BinaryBiproduct.isLimit Y Z) (@mapPair _ _ (pair W X) (pair Y Z) f g) /-- An alternative to `biprod.map` constructed via colimits. This construction only exists in order to show it is equal to `biprod.map`. -/ abbrev biprod.map' {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z := IsColimit.map (BinaryBiproduct.isColimit W X) (BinaryBiproduct.bicone Y Z).toCocone (@mapPair _ _ (pair W X) (pair Y Z) f g) @[ext] theorem biprod.hom_ext {X Y Z : C} [HasBinaryBiproduct X Y] (f g : Z ⟶ X ⊞ Y) (h₀ : f ≫ biprod.fst = g ≫ biprod.fst) (h₁ : f ≫ biprod.snd = g ≫ biprod.snd) : f = g := BinaryFan.IsLimit.hom_ext (BinaryBiproduct.isLimit X Y) h₀ h₁ @[ext] theorem biprod.hom_ext' {X Y Z : C} [HasBinaryBiproduct X Y] (f g : X ⊞ Y ⟶ Z) (h₀ : biprod.inl ≫ f = biprod.inl ≫ g) (h₁ : biprod.inr ≫ f = biprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (BinaryBiproduct.isColimit X Y) h₀ h₁ /-- The canonical isomorphism between the chosen biproduct and the chosen product. -/ def biprod.isoProd (X Y : C) [HasBinaryBiproduct X Y] : X ⊞ Y ≅ X ⨯ Y := IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit X Y) (limit.isLimit _) @[simp] theorem biprod.isoProd_hom {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoProd X Y).hom = prod.lift biprod.fst biprod.snd := by ext <;> simp [biprod.isoProd] @[simp] theorem biprod.isoProd_inv {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoProd X Y).inv = biprod.lift prod.fst prod.snd := by ext <;> simp [Iso.inv_comp_eq] /-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/ def biprod.isoCoprod (X Y : C) [HasBinaryBiproduct X Y] : X ⊞ Y ≅ X ⨿ Y := IsColimit.coconePointUniqueUpToIso (BinaryBiproduct.isColimit X Y) (colimit.isColimit _) @[simp] theorem biprod.isoCoprod_inv {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoCoprod X Y).inv = coprod.desc biprod.inl biprod.inr := by ext <;> simp [biprod.isoCoprod] @[simp] theorem biprod_isoCoprod_hom {X Y : C} [HasBinaryBiproduct X Y] : (biprod.isoCoprod X Y).hom = biprod.desc coprod.inl coprod.inr := by ext <;> simp [← Iso.eq_comp_inv] theorem biprod.map_eq_map' {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.map f g = biprod.map' f g := by ext · simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, biprod.inl_fst_assoc, Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBiproduct.bicone_fst, ← BinaryBicone.toCocone_ι_app_left, ← BinaryBiproduct.bicone_inl] dsimp; simp · simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, zero_comp, biprod.inl_snd_assoc, Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBiproduct.bicone_snd, ← BinaryBicone.toCocone_ι_app_left, ← BinaryBiproduct.bicone_inl] simp · simp only [mapPair_right, biprod.inr_fst_assoc, IsColimit.ι_map, IsLimit.map_π, zero_comp, Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBiproduct.bicone_fst, ← BinaryBicone.toCocone_ι_app_right, ← BinaryBiproduct.bicone_inr] simp · simp only [mapPair_right, IsColimit.ι_map, IsLimit.map_π, biprod.inr_snd_assoc, Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBiproduct.bicone_snd, ← BinaryBicone.toCocone_ι_app_right, ← BinaryBiproduct.bicone_inr] simp instance biprod.inl_mono {X Y : C} [HasBinaryBiproduct X Y] : IsSplitMono (biprod.inl : X ⟶ X ⊞ Y) := IsSplitMono.mk' { retraction := biprod.fst } instance biprod.inr_mono {X Y : C} [HasBinaryBiproduct X Y] : IsSplitMono (biprod.inr : Y ⟶ X ⊞ Y) := IsSplitMono.mk' { retraction := biprod.snd } instance biprod.fst_epi {X Y : C} [HasBinaryBiproduct X Y] : IsSplitEpi (biprod.fst : X ⊞ Y ⟶ X) := IsSplitEpi.mk' { section_ := biprod.inl } instance biprod.snd_epi {X Y : C} [HasBinaryBiproduct X Y] : IsSplitEpi (biprod.snd : X ⊞ Y ⟶ Y) := IsSplitEpi.mk' { section_ := biprod.inr } @[reassoc (attr := simp)] theorem biprod.map_fst {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.map f g ≫ biprod.fst = biprod.fst ≫ f := IsLimit.map_π _ _ _ (⟨WalkingPair.left⟩ : Discrete WalkingPair) @[reassoc (attr := simp)] theorem biprod.map_snd {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.map f g ≫ biprod.snd = biprod.snd ≫ g := IsLimit.map_π _ _ _ (⟨WalkingPair.right⟩ : Discrete WalkingPair) -- Because `biprod.map` is defined in terms of `lim` rather than `colim`, -- we need to provide additional `simp` lemmas. @[reassoc (attr := simp)] theorem biprod.inl_map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.inl ≫ biprod.map f g = f ≫ biprod.inl := by rw [biprod.map_eq_map'] exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.left⟩ @[reassoc (attr := simp)] theorem biprod.inr_map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : biprod.inr ≫ biprod.map f g = g ≫ biprod.inr := by rw [biprod.map_eq_map'] exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.right⟩ /-- Given a pair of isomorphisms between the summands of a pair of binary biproducts, we obtain an isomorphism between the binary biproducts. -/ @[simps] def biprod.mapIso {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⊞ X ≅ Y ⊞ Z where hom := biprod.map f.hom g.hom inv := biprod.map f.inv g.inv /-- Auxiliary lemma for `biprod.uniqueUpToIso`. -/ theorem biprod.conePointUniqueUpToIso_hom (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit _ _)).hom = biprod.lift b.fst b.snd := rfl /-- Auxiliary lemma for `biprod.uniqueUpToIso`. -/ theorem biprod.conePointUniqueUpToIso_inv (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit _ _)).inv = biprod.desc b.inl b.inr := by refine biprod.hom_ext' _ _ (hb.isLimit.hom_ext fun j => ?_) (hb.isLimit.hom_ext fun j => ?_) all_goals simp only [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp] rcases j with ⟨⟨⟩⟩ all_goals simp /-- Binary biproducts are unique up to isomorphism. This already follows because bilimits are limits, but in the case of biproducts we can give an isomorphism with particularly nice definitional properties, namely that `biprod.lift b.fst b.snd` and `biprod.desc b.inl b.inr` are inverses of each other. -/ @[simps] def biprod.uniqueUpToIso (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y} (hb : b.IsBilimit) : b.pt ≅ X ⊞ Y where hom := biprod.lift b.fst b.snd inv := biprod.desc b.inl b.inr hom_inv_id := by rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ← biprod.conePointUniqueUpToIso_inv X Y hb, Iso.hom_inv_id] inv_hom_id := by rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ← biprod.conePointUniqueUpToIso_inv X Y hb, Iso.inv_hom_id] -- There are three further variations, -- about `IsIso biprod.inr`, `IsIso biprod.fst` and `IsIso biprod.snd`, -- but any one suffices to prove `indecomposable_of_simple` -- and they are likely not separately useful. theorem biprod.isIso_inl_iff_id_eq_fst_comp_inl (X Y : C) [HasBinaryBiproduct X Y] : IsIso (biprod.inl : X ⟶ X ⊞ Y) ↔ 𝟙 (X ⊞ Y) = biprod.fst ≫ biprod.inl := by constructor · intro h have := (cancel_epi (inv biprod.inl : X ⊞ Y ⟶ X)).2 <| @biprod.inl_fst _ _ _ X Y _ rw [IsIso.inv_hom_id_assoc, Category.comp_id] at this rw [this, IsIso.inv_hom_id] · intro h exact ⟨⟨biprod.fst, biprod.inl_fst, h.symm⟩⟩ section BiprodKernel section BinaryBicone variable {X Y : C} (c : BinaryBicone X Y) /-- A kernel fork for the kernel of `BinaryBicone.fst`. It consists of the morphism `BinaryBicone.inr`. -/ def BinaryBicone.fstKernelFork : KernelFork c.fst := KernelFork.ofι c.inr c.inr_fst @[simp] theorem BinaryBicone.fstKernelFork_ι : (BinaryBicone.fstKernelFork c).ι = c.inr := rfl /-- A kernel fork for the kernel of `BinaryBicone.snd`. It consists of the morphism `BinaryBicone.inl`. -/ def BinaryBicone.sndKernelFork : KernelFork c.snd := KernelFork.ofι c.inl c.inl_snd @[simp] theorem BinaryBicone.sndKernelFork_ι : (BinaryBicone.sndKernelFork c).ι = c.inl := rfl /-- A cokernel cofork for the cokernel of `BinaryBicone.inl`. It consists of the morphism `BinaryBicone.snd`. -/ def BinaryBicone.inlCokernelCofork : CokernelCofork c.inl := CokernelCofork.ofπ c.snd c.inl_snd @[simp] theorem BinaryBicone.inlCokernelCofork_π : (BinaryBicone.inlCokernelCofork c).π = c.snd := rfl /-- A cokernel cofork for the cokernel of `BinaryBicone.inr`. It consists of the morphism `BinaryBicone.fst`. -/ def BinaryBicone.inrCokernelCofork : CokernelCofork c.inr := CokernelCofork.ofπ c.fst c.inr_fst @[simp] theorem BinaryBicone.inrCokernelCofork_π : (BinaryBicone.inrCokernelCofork c).π = c.fst := rfl variable {c} /-- The fork defined in `BinaryBicone.fstKernelFork` is indeed a kernel. -/ def BinaryBicone.isLimitFstKernelFork (i : IsLimit c.toCone) : IsLimit c.fstKernelFork := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ c.snd, by apply BinaryFan.IsLimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ /-- The fork defined in `BinaryBicone.sndKernelFork` is indeed a kernel. -/ def BinaryBicone.isLimitSndKernelFork (i : IsLimit c.toCone) : IsLimit c.sndKernelFork := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ c.fst, by apply BinaryFan.IsLimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ /-- The cofork defined in `BinaryBicone.inlCokernelCofork` is indeed a cokernel. -/ def BinaryBicone.isColimitInlCokernelCofork (i : IsColimit c.toCocone) : IsColimit c.inlCokernelCofork := Cofork.IsColimit.mk' _ fun s => ⟨c.inr ≫ s.π, by apply BinaryCofan.IsColimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ /-- The cofork defined in `BinaryBicone.inrCokernelCofork` is indeed a cokernel. -/ def BinaryBicone.isColimitInrCokernelCofork (i : IsColimit c.toCocone) : IsColimit c.inrCokernelCofork := Cofork.IsColimit.mk' _ fun s => ⟨c.inl ≫ s.π, by apply BinaryCofan.IsColimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩ end BinaryBicone section HasBinaryBiproduct variable (X Y : C) [HasBinaryBiproduct X Y] /-- A kernel fork for the kernel of `biprod.fst`. It consists of the morphism `biprod.inr`. -/ def biprod.fstKernelFork : KernelFork (biprod.fst : X ⊞ Y ⟶ X) := BinaryBicone.fstKernelFork _ @[simp] theorem biprod.fstKernelFork_ι : Fork.ι (biprod.fstKernelFork X Y) = (biprod.inr : Y ⟶ X ⊞ Y) := rfl /-- The fork `biprod.fstKernelFork` is indeed a limit. -/ def biprod.isKernelFstKernelFork : IsLimit (biprod.fstKernelFork X Y) := BinaryBicone.isLimitFstKernelFork (BinaryBiproduct.isLimit _ _) /-- A kernel fork for the kernel of `biprod.snd`. It consists of the morphism `biprod.inl`. -/ def biprod.sndKernelFork : KernelFork (biprod.snd : X ⊞ Y ⟶ Y) := BinaryBicone.sndKernelFork _ @[simp] theorem biprod.sndKernelFork_ι : Fork.ι (biprod.sndKernelFork X Y) = (biprod.inl : X ⟶ X ⊞ Y) := rfl /-- The fork `biprod.sndKernelFork` is indeed a limit. -/ def biprod.isKernelSndKernelFork : IsLimit (biprod.sndKernelFork X Y) := BinaryBicone.isLimitSndKernelFork (BinaryBiproduct.isLimit _ _) /-- A cokernel cofork for the cokernel of `biprod.inl`. It consists of the morphism `biprod.snd`. -/ def biprod.inlCokernelCofork : CokernelCofork (biprod.inl : X ⟶ X ⊞ Y) := BinaryBicone.inlCokernelCofork _ @[simp] theorem biprod.inlCokernelCofork_π : Cofork.π (biprod.inlCokernelCofork X Y) = biprod.snd := rfl /-- The cofork `biprod.inlCokernelFork` is indeed a colimit. -/ def biprod.isCokernelInlCokernelFork : IsColimit (biprod.inlCokernelCofork X Y) := BinaryBicone.isColimitInlCokernelCofork (BinaryBiproduct.isColimit _ _) /-- A cokernel cofork for the cokernel of `biprod.inr`. It consists of the morphism `biprod.fst`. -/ def biprod.inrCokernelCofork : CokernelCofork (biprod.inr : Y ⟶ X ⊞ Y) := BinaryBicone.inrCokernelCofork _ @[simp] theorem biprod.inrCokernelCofork_π : Cofork.π (biprod.inrCokernelCofork X Y) = biprod.fst := rfl /-- The cofork `biprod.inrCokernelFork` is indeed a colimit. -/ def biprod.isCokernelInrCokernelFork : IsColimit (biprod.inrCokernelCofork X Y) := BinaryBicone.isColimitInrCokernelCofork (BinaryBiproduct.isColimit _ _) end HasBinaryBiproduct variable {X Y : C} [HasBinaryBiproduct X Y] instance : HasKernel (biprod.fst : X ⊞ Y ⟶ X) := HasLimit.mk ⟨_, biprod.isKernelFstKernelFork X Y⟩ /-- The kernel of `biprod.fst : X ⊞ Y ⟶ X` is `Y`. -/ @[simps!] def kernelBiprodFstIso : kernel (biprod.fst : X ⊞ Y ⟶ X) ≅ Y := limit.isoLimitCone ⟨_, biprod.isKernelFstKernelFork X Y⟩ instance : HasKernel (biprod.snd : X ⊞ Y ⟶ Y) := HasLimit.mk ⟨_, biprod.isKernelSndKernelFork X Y⟩ /-- The kernel of `biprod.snd : X ⊞ Y ⟶ Y` is `X`. -/ @[simps!] def kernelBiprodSndIso : kernel (biprod.snd : X ⊞ Y ⟶ Y) ≅ X := limit.isoLimitCone ⟨_, biprod.isKernelSndKernelFork X Y⟩ instance : HasCokernel (biprod.inl : X ⟶ X ⊞ Y) := HasColimit.mk ⟨_, biprod.isCokernelInlCokernelFork X Y⟩ /-- The cokernel of `biprod.inl : X ⟶ X ⊞ Y` is `Y`. -/ @[simps!] def cokernelBiprodInlIso : cokernel (biprod.inl : X ⟶ X ⊞ Y) ≅ Y := colimit.isoColimitCocone ⟨_, biprod.isCokernelInlCokernelFork X Y⟩ instance : HasCokernel (biprod.inr : Y ⟶ X ⊞ Y) := HasColimit.mk ⟨_, biprod.isCokernelInrCokernelFork X Y⟩ /-- The cokernel of `biprod.inr : Y ⟶ X ⊞ Y` is `X`. -/ @[simps!] def cokernelBiprodInrIso : cokernel (biprod.inr : Y ⟶ X ⊞ Y) ≅ X := colimit.isoColimitCocone ⟨_, biprod.isCokernelInrCokernelFork X Y⟩ end BiprodKernel section IsZero /-- If `Y` is a zero object, `X ≅ X ⊞ Y` for any `X`. -/ @[simps!] def isoBiprodZero {X Y : C} [HasBinaryBiproduct X Y] (hY : IsZero Y) : X ≅ X ⊞ Y where hom := biprod.inl inv := biprod.fst inv_hom_id := by apply CategoryTheory.Limits.biprod.hom_ext <;> simp only [Category.assoc, biprod.inl_fst, Category.comp_id, Category.id_comp, biprod.inl_snd, comp_zero] apply hY.eq_of_tgt /-- If `X` is a zero object, `Y ≅ X ⊞ Y` for any `Y`. -/ @[simps] def isoZeroBiprod {X Y : C} [HasBinaryBiproduct X Y] (hY : IsZero X) : Y ≅ X ⊞ Y where hom := biprod.inr inv := biprod.snd inv_hom_id := by apply CategoryTheory.Limits.biprod.hom_ext <;> simp only [Category.assoc, biprod.inr_snd, Category.comp_id, Category.id_comp, biprod.inr_fst, comp_zero] apply hY.eq_of_tgt @[simp] lemma biprod_isZero_iff (A B : C) [HasBinaryBiproduct A B] : IsZero (biprod A B) ↔ IsZero A ∧ IsZero B := by constructor · intro h simp only [IsZero.iff_id_eq_zero] at h ⊢ simp only [show 𝟙 A = biprod.inl ≫ 𝟙 (A ⊞ B) ≫ biprod.fst by simp, show 𝟙 B = biprod.inr ≫ 𝟙 (A ⊞ B) ≫ biprod.snd by simp, h, zero_comp, comp_zero, and_self] · rintro ⟨hA, hB⟩ rw [IsZero.iff_id_eq_zero] apply biprod.hom_ext · apply hA.eq_of_tgt · apply hB.eq_of_tgt end IsZero section variable [HasBinaryBiproducts C] /-- The braiding isomorphism which swaps a binary biproduct. -/ @[simps] def biprod.braiding (P Q : C) : P ⊞ Q ≅ Q ⊞ P where hom := biprod.lift biprod.snd biprod.fst inv := biprod.lift biprod.snd biprod.fst /-- An alternative formula for the braiding isomorphism which swaps a binary biproduct, using the fact that the biproduct is a coproduct. -/ @[simps] def biprod.braiding' (P Q : C) : P ⊞ Q ≅ Q ⊞ P where hom := biprod.desc biprod.inr biprod.inl inv := biprod.desc biprod.inr biprod.inl theorem biprod.braiding'_eq_braiding {P Q : C} : biprod.braiding' P Q = biprod.braiding P Q := by aesop_cat /-- The braiding isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem biprod.braid_natural {W X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ W) : biprod.map f g ≫ (biprod.braiding _ _).hom = (biprod.braiding _ _).hom ≫ biprod.map g f := by aesop_cat @[reassoc] theorem biprod.braiding_map_braiding {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) : (biprod.braiding X W).hom ≫ biprod.map f g ≫ (biprod.braiding Y Z).hom = biprod.map g f := by aesop_cat @[reassoc (attr := simp)] theorem biprod.symmetry' (P Q : C) : biprod.lift biprod.snd biprod.fst ≫ biprod.lift biprod.snd biprod.fst = 𝟙 (P ⊞ Q) := by aesop_cat /-- The braiding isomorphism is symmetric. -/ @[reassoc] theorem biprod.symmetry (P Q : C) : (biprod.braiding P Q).hom ≫ (biprod.braiding Q P).hom = 𝟙 _ := by simp /-- The associator isomorphism which associates a binary biproduct. -/ @[simps] def biprod.associator (P Q R : C) : (P ⊞ Q) ⊞ R ≅ P ⊞ (Q ⊞ R) where hom := biprod.lift (biprod.fst ≫ biprod.fst) (biprod.lift (biprod.fst ≫ biprod.snd) biprod.snd) inv := biprod.lift (biprod.lift biprod.fst (biprod.snd ≫ biprod.fst)) (biprod.snd ≫ biprod.snd) /-- The associator isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem biprod.associator_natural {U V W X Y Z : C} (f : U ⟶ X) (g : V ⟶ Y) (h : W ⟶ Z) : biprod.map (biprod.map f g) h ≫ (biprod.associator _ _ _).hom = (biprod.associator _ _ _).hom ≫ biprod.map f (biprod.map g h) := by aesop_cat /-- The associator isomorphism can be passed through a map by swapping the order. -/ @[reassoc] theorem biprod.associator_inv_natural {U V W X Y Z : C} (f : U ⟶ X) (g : V ⟶ Y) (h : W ⟶ Z) : biprod.map f (biprod.map g h) ≫ (biprod.associator _ _ _).inv = (biprod.associator _ _ _).inv ≫ biprod.map (biprod.map f g) h := by aesop_cat end end Limits open CategoryTheory.Limits -- TODO: -- If someone is interested, they could provide the constructions: -- HasBinaryBiproducts ↔ HasFiniteBiproducts variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasBinaryBiproducts C] /-- An object is indecomposable if it cannot be written as the biproduct of two nonzero objects. -/ def Indecomposable (X : C) : Prop := ¬IsZero X ∧ ∀ Y Z, (X ≅ Y ⊞ Z) → IsZero Y ∨ IsZero Z /-- If ``` (f 0) (0 g) ``` is invertible, then `f` is invertible. -/ theorem isIso_left_of_isIso_biprod_map {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [IsIso (biprod.map f g)] : IsIso f := ⟨⟨biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst, ⟨by have t := congrArg (fun p : W ⊞ X ⟶ W ⊞ X => biprod.inl ≫ p ≫ biprod.fst) (IsIso.hom_inv_id (biprod.map f g)) simp only [Category.id_comp, Category.assoc, biprod.inl_map_assoc] at t simp [t], by have t := congrArg (fun p : Y ⊞ Z ⟶ Y ⊞ Z => biprod.inl ≫ p ≫ biprod.fst) (IsIso.inv_hom_id (biprod.map f g)) simp only [Category.id_comp, Category.assoc, biprod.map_fst] at t simp only [Category.assoc] simp [t]⟩⟩⟩ /-- If ``` (f 0) (0 g) ``` is invertible, then `g` is invertible. -/ theorem isIso_right_of_isIso_biprod_map {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [IsIso (biprod.map f g)] : IsIso g := letI : IsIso (biprod.map g f) := by rw [← biprod.braiding_map_braiding] infer_instance isIso_left_of_isIso_biprod_map g f end CategoryTheory
CategoryTheory\Limits\Shapes\CombinedProducts.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # Constructors for combining (co)fans We provide constructors for combining (co)fans and show their (co)limit properties. ## TODO * Combine (co)fans on sigma types -/ universe u₁ u₂ namespace CategoryTheory namespace Limits variable {C : Type u₁} [Category.{u₂} C] namespace Fan variable {ι₁ ι₂ : Type*} {X : C} {f₁ : ι₁ → C} {f₂ : ι₂ → C} (c₁ : Fan f₁) (c₂ : Fan f₂) (bc : BinaryFan c₁.pt c₂.pt) (h₁ : IsLimit c₁) (h₂ : IsLimit c₂) (h : IsLimit bc) /-- For fans on maps `f₁ : ι₁ → C`, `f₂ : ι₂ → C` and a binary fan on their cone points, construct one family of morphisms indexed by `ι₁ ⊕ ι₂` -/ @[simp] abbrev combPairHoms : (i : ι₁ ⊕ ι₂) → bc.pt ⟶ Sum.elim f₁ f₂ i | .inl a => bc.fst ≫ c₁.proj a | .inr a => bc.snd ≫ c₂.proj a variable {c₁ c₂ bc} /-- If `c₁` and `c₂` are limit fans and `bc` is a limit binary fan on their cone points, then the fan constructed from `combPairHoms` is a limit cone. -/ def combPairIsLimit : IsLimit (Fan.mk bc.pt (combPairHoms c₁ c₂ bc)) := mkFanLimit _ (fun s ↦ Fan.IsLimit.desc h <| fun i ↦ by cases i · exact Fan.IsLimit.desc h₁ (fun a ↦ s.proj (.inl a)) · exact Fan.IsLimit.desc h₂ (fun a ↦ s.proj (.inr a))) (fun s w ↦ by cases w <;> · simp only [fan_mk_proj, combPairHoms] erw [← Category.assoc, h.fac] simp only [pair_obj_left, mk_pt, mk_π_app, IsLimit.fac]) (fun s m hm ↦ Fan.IsLimit.hom_ext h _ _ <| fun w ↦ by cases w · refine Fan.IsLimit.hom_ext h₁ _ _ (fun a ↦ by aesop) · refine Fan.IsLimit.hom_ext h₂ _ _ (fun a ↦ by aesop)) end Fan namespace Cofan variable {ι₁ ι₂ : Type*} {X : C} {f₁ : ι₁ → C} {f₂ : ι₂ → C} (c₁ : Cofan f₁) (c₂ : Cofan f₂) (bc : BinaryCofan c₁.pt c₂.pt) (h₁ : IsColimit c₁) (h₂ : IsColimit c₂) (h : IsColimit bc) /-- For cofans on maps `f₁ : ι₁ → C`, `f₂ : ι₂ → C` and a binary cofan on their cocone points, construct one family of morphisms indexed by `ι₁ ⊕ ι₂` -/ @[simp] abbrev combPairHoms : (i : ι₁ ⊕ ι₂) → Sum.elim f₁ f₂ i ⟶ bc.pt | .inl a => c₁.inj a ≫ bc.inl | .inr a => c₂.inj a ≫ bc.inr variable {c₁ c₂ bc} /-- If `c₁` and `c₂` are colimit cofans and `bc` is a colimit binary cofan on their cocone points, then the cofan constructed from `combPairHoms` is a colimit cocone. -/ def combPairIsColimit : IsColimit (Cofan.mk bc.pt (combPairHoms c₁ c₂ bc)) := mkCofanColimit _ (fun s ↦ Cofan.IsColimit.desc h <| fun i ↦ by cases i · exact Cofan.IsColimit.desc h₁ (fun a ↦ s.inj (.inl a)) · exact Cofan.IsColimit.desc h₂ (fun a ↦ s.inj (.inr a))) (fun s w ↦ by cases w <;> · simp only [cofan_mk_inj, combPairHoms, Category.assoc] erw [h.fac] simp only [Cofan.mk_ι_app, Cofan.IsColimit.fac]) (fun s m hm ↦ Cofan.IsColimit.hom_ext h _ _ <| fun w ↦ by cases w · refine Cofan.IsColimit.hom_ext h₁ _ _ (fun a ↦ by aesop) · refine Cofan.IsColimit.hom_ext h₂ _ _ (fun a ↦ by aesop)) end Cofan end Limits end CategoryTheory