source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/CategoryTheory/GuitartExact/Basic.lean
import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Functor.TwoSquare /-! # 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₄) namespace TwoSquare variable {T L R B} (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 {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 _ := 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
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/Fiber.lean
import Mathlib.CategoryTheory.FiberedCategory.HomLift import Mathlib.CategoryTheory.Functor.Const /-! # Fibers of a functors In this file we define, for a functor `p : 𝒳 ⥤ 𝒴`, the fiber categories `Fiber p S` for every `S : 𝒮` as follows - An object in `Fiber p S` is a pair `(a, ha)` where `a : 𝒳` and `ha : p.obj a = S`. - A morphism in `Fiber p S` is a morphism `φ : a ⟶ b` in 𝒳 such that `p.map φ = 𝟙 S`. For any category `C` equipped with a functor `F : C ⥤ 𝒳` such that `F ⋙ p` is constant at `S`, we define a functor `inducedFunctor : C ⥤ Fiber p S` that `F` factors through. -/ universe v₁ u₁ v₂ u₂ v₃ u₃ namespace CategoryTheory open IsHomLift namespace Functor variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒮] [Category.{v₂} 𝒳] /-- `Fiber p S` is the type of elements of `𝒳` mapping to `S` via `p`. -/ def Fiber (p : 𝒳 ⥤ 𝒮) (S : 𝒮) := { a : 𝒳 // p.obj a = S } namespace Fiber variable {p : 𝒳 ⥤ 𝒮} {S : 𝒮} /-- `Fiber p S` has the structure of a category with morphisms being those lying over `𝟙 S`. -/ instance fiberCategory : Category (Fiber p S) where Hom a b := {φ : a.1 ⟶ b.1 // IsHomLift p (𝟙 S) φ} id a := ⟨𝟙 a.1, IsHomLift.id a.2⟩ comp φ ψ := ⟨φ.val ≫ ψ.val, by have := φ.2; have := ψ.2; infer_instance⟩ /-- The functor including `Fiber p S` into `𝒳`. -/ def fiberInclusion : Fiber p S ⥤ 𝒳 where obj a := a.1 map φ := φ.1 instance {a b : Fiber p S} (φ : a ⟶ b) : IsHomLift p (𝟙 S) (fiberInclusion.map φ) := φ.2 @[ext] lemma hom_ext {a b : Fiber p S} {φ ψ : a ⟶ b} (h : fiberInclusion.map φ = fiberInclusion.map ψ) : φ = ψ := Subtype.ext h instance : (fiberInclusion : Fiber p S ⥤ _).Faithful where lemma fiberInclusion_obj_inj : (fiberInclusion : Fiber p S ⥤ _).obj.Injective := fun _ _ f ↦ Subtype.val_inj.1 f /-- For fixed `S : 𝒮` this is the natural isomorphism between `fiberInclusion ⋙ p` and the constant function valued at `S`. -/ @[simps!] def fiberInclusionCompIsoConst : fiberInclusion ⋙ p ≅ (const (Fiber p S)).obj S := NatIso.ofComponents (fun X ↦ eqToIso X.2) (fun φ ↦ by simp [IsHomLift.fac' p (𝟙 S) (fiberInclusion.map φ)]) lemma fiberInclusion_comp_eq_const : fiberInclusion ⋙ p = (const (Fiber p S)).obj S := Functor.ext_of_iso fiberInclusionCompIsoConst (fun x ↦ x.2) /-- The object of the fiber over `S` corresponding to a `a : 𝒳` such that `p(a) = S`. -/ def mk {p : 𝒳 ⥤ 𝒮} {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : Fiber p S := ⟨a, ha⟩ @[simp] lemma fiberInclusion_mk {p : 𝒳 ⥤ 𝒮} {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : fiberInclusion.obj (mk ha) = a := rfl /-- The morphism in the fiber over `S` corresponding to a morphism in `𝒳` lifting `𝟙 S`. -/ def homMk (p : 𝒳 ⥤ 𝒮) (S : 𝒮) {a b : 𝒳} (φ : a ⟶ b) [IsHomLift p (𝟙 S) φ] : mk (domain_eq p (𝟙 S) φ) ⟶ mk (codomain_eq p (𝟙 S) φ) := ⟨φ, inferInstance⟩ @[simp] lemma fiberInclusion_homMk (p : 𝒳 ⥤ 𝒮) (S : 𝒮) {a b : 𝒳} (φ : a ⟶ b) [IsHomLift p (𝟙 S) φ] : fiberInclusion.map (homMk p S φ) = φ := rfl @[simp] lemma homMk_id (p : 𝒳 ⥤ 𝒮) (S : 𝒮) (a : 𝒳) [IsHomLift p (𝟙 S) (𝟙 a)] : homMk p S (𝟙 a) = 𝟙 (mk (domain_eq p (𝟙 S) (𝟙 a))) := rfl @[simp] lemma homMk_comp {a b c : 𝒳} (φ : a ⟶ b) (ψ : b ⟶ c) [IsHomLift p (𝟙 S) φ] [IsHomLift p (𝟙 S) ψ] : homMk p S φ ≫ homMk p S ψ = homMk p S (φ ≫ ψ) := rfl section variable {p : 𝒳 ⥤ 𝒮} {S : 𝒮} {C : Type u₃} [Category.{v₃} C] {F : C ⥤ 𝒳} (hF : F ⋙ p = (const C).obj S) /-- Given a functor `F : C ⥤ 𝒳` such that `F ⋙ p` is constant at some `S : 𝒮`, then we get an induced functor `C ⥤ Fiber p S` that `F` factors through. -/ def inducedFunctor : C ⥤ Fiber p S where obj x := ⟨F.obj x, by simp only [← comp_obj, hF, const_obj_obj]⟩ map φ := ⟨F.map φ, of_commsq _ _ _ (congr_obj hF _) (congr_obj hF _) <| by simpa using (eqToIso hF).hom.naturality φ⟩ /-- Given a functor `F : C ⥤ 𝒳` such that `F ⋙ p` is constant at some `S : 𝒮`, then we get a natural isomorphism between `inducedFunctor _ ⋙ fiberInclusion` and `F`. -/ @[simps!] def inducedFunctorCompIsoSelf : (inducedFunctor hF) ⋙ fiberInclusion ≅ F := .refl _ lemma inducedFunctor_comp : (inducedFunctor hF) ⋙ fiberInclusion = F := rfl @[simp] lemma inducedFunctor_comp_obj (X : C) : fiberInclusion.obj ((inducedFunctor hF).obj X) = F.obj X := rfl @[simp] lemma inducedFunctor_comp_map {X Y : C} (f : X ⟶ Y) : fiberInclusion.map ((inducedFunctor hF).map f) = F.map f := rfl end end Fiber end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/Cocartesian.lean
import Mathlib.CategoryTheory.FiberedCategory.HomLift /-! # Co-Cartesian morphisms This file defines co-Cartesian resp. strongly co-Cartesian morphisms with respect to a functor `p : 𝒳 ⥤ 𝒮`. This file has been adapted from `Mathlib/CategoryTheory/FiberedCategory/Cartesian.lean`, please try to change them in sync. ## Main definitions `IsCocartesian p f φ` expresses that `φ` is a co-Cartesian morphism lying over `f : R ⟶ S` with respect to `p`. This means that for any morphism `φ' : a ⟶ b'` lying over `f` there is a unique morphism `τ : b ⟶ b'` lying over `𝟙 S`, such that `φ' = φ ≫ τ`. `IsStronglyCocartesian p f φ` expresses that `φ` is a strongly co-Cartesian morphism lying over `f` with respect to `p`. ## Implementation The constructor of `IsStronglyCocartesian` has been named `universal_property'`, and is mainly intended to be used for constructing instances of this class. To use the universal property, we generally recommended to use the lemma `IsStronglyCocartesian.universal_property` instead. The difference between the two is that the latter is more flexible with respect to non-definitional equalities. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory Functor Category IsHomLift namespace CategoryTheory.Functor variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒮] [Category.{v₂} 𝒳] (p : 𝒳 ⥤ 𝒮) section variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) /-- A morphism `φ : a ⟶ b` in `𝒳` lying over `f : R ⟶ S` in `𝒮` is co-Cartesian if for all morphisms `φ' : a ⟶ b'`, also lying over `f`, there exists a unique morphism `χ : b ⟶ b'` lifting `𝟙 S` such that `φ' = φ ≫ χ`. -/ class IsCocartesian : Prop where [toIsHomLift : IsHomLift p f φ] universal_property {b' : 𝒳} (φ' : a ⟶ b') [IsHomLift p f φ'] : ∃! χ : b ⟶ b', IsHomLift p (𝟙 S) χ ∧ φ ≫ χ = φ' attribute [instance] IsCocartesian.toIsHomLift /-- A morphism `φ : a ⟶ b` in `𝒳` lying over `f : R ⟶ S` in `𝒮` is strongly co-Cartesian if for all morphisms `φ' : a ⟶ b'` and all diagrams of the form ``` a --φ--> b b' | | | v v v R --f--> S --g--> S' ``` such that `φ'` lifts `f ≫ g`, there exists a lift `χ` of `g` such that `φ' = χ ≫ φ`. -/ @[stacks 02XK] class IsStronglyCocartesian : Prop where [toIsHomLift : IsHomLift p f φ] universal_property' {b' : 𝒳} (g : S ⟶ p.obj b') (φ' : a ⟶ b') [IsHomLift p (f ≫ g) φ'] : ∃! χ : b ⟶ b', IsHomLift p g χ ∧ φ ≫ χ = φ' attribute [instance] IsStronglyCocartesian.toIsHomLift end namespace IsCocartesian variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [IsCocartesian p f φ] section variable {b' : 𝒳} (φ' : a ⟶ b') [IsHomLift p f φ'] /-- Given a co-Cartesian morphism `φ : a ⟶ b` lying over `f : R ⟶ S` in `𝒳`, and another morphism `φ' : a ⟶ b'` which also lifts `f`, then `IsCocartesian.map f φ φ'` is the morphism `b ⟶ b'` lying over `𝟙 S` obtained from the universal property of `φ`. -/ protected noncomputable def map : b ⟶ b' := Classical.choose <| IsCocartesian.universal_property (p := p) (f := f) (φ := φ) φ' instance map_isHomLift : IsHomLift p (𝟙 S) (IsCocartesian.map p f φ φ') := (Classical.choose_spec <| IsCocartesian.universal_property (p := p) (f := f) (φ := φ) φ').1.1 @[reassoc (attr := simp)] lemma fac : φ ≫ IsCocartesian.map p f φ φ' = φ' := (Classical.choose_spec <| IsCocartesian.universal_property (p := p) (f := f) (φ := φ) φ').1.2 /-- Given a co-Cartesian morphism `φ : a ⟶ b` lying over `f : R ⟶ S` in `𝒳`, and another morphism `φ' : a ⟶ b'` which also lifts `f`. Then any morphism `ψ : b ⟶ b'` lifting `𝟙 S` such that `g ≫ ψ = φ'` must equal the map induced by the universal property of `φ`. -/ lemma map_uniq (ψ : b ⟶ b') [IsHomLift p (𝟙 S) ψ] (hψ : φ ≫ ψ = φ') : ψ = IsCocartesian.map p f φ φ' := (Classical.choose_spec <| IsCocartesian.universal_property (p := p) (f := f) (φ := φ) φ').2 ψ ⟨inferInstance, hψ⟩ end /-- Given a co-Cartesian morphism `φ : a ⟶ b` lying over `f : R ⟶ S` in `𝒳`, and two morphisms `ψ ψ' : b ⟶ b'` lifting `𝟙 S` such that `φ ≫ ψ = φ ≫ ψ'`. Then we must have `ψ = ψ'`. -/ protected lemma ext (φ : a ⟶ b) [IsCocartesian p f φ] {b' : 𝒳} (ψ ψ' : b ⟶ b') [IsHomLift p (𝟙 S) ψ] [IsHomLift p (𝟙 S) ψ'] (h : φ ≫ ψ = φ ≫ ψ') : ψ = ψ' := by rw [map_uniq p f φ (φ ≫ ψ) ψ rfl, map_uniq p f φ (φ ≫ ψ) ψ' h.symm] @[simp] lemma map_self : IsCocartesian.map p f φ φ = 𝟙 b := by subst_hom_lift p f φ; symm apply map_uniq simp only [comp_id] /-- The canonical isomorphism between the codomains of two co-Cartesian morphisms lying over the same object. -/ noncomputable def codomainUniqueUpToIso {b' : 𝒳} (φ' : a ⟶ b') [IsCocartesian p f φ'] : b ≅ b' where hom := IsCocartesian.map p f φ φ' inv := IsCocartesian.map p f φ' φ hom_inv_id := by subst_hom_lift p f φ apply IsCocartesian.ext p (p.map φ) φ simp only [fac_assoc, fac, comp_id] inv_hom_id := by subst_hom_lift p f φ' apply IsCocartesian.ext p (p.map φ') φ' simp only [fac_assoc, fac, comp_id] /-- Postcomposing a co-Cartesian morphism with an isomorphism lifting the identity is co-Cartesian. -/ instance of_comp_iso {b' : 𝒳} (φ' : b ≅ b') [IsHomLift p (𝟙 S) φ'.hom] : IsCocartesian p f (φ ≫ φ'.hom) where universal_property := by intro c ψ hψ use φ'.inv ≫ IsCocartesian.map p f φ ψ refine ⟨⟨inferInstance, by simp⟩, ?_⟩ rintro τ ⟨hτ₁, hτ₂⟩ rw [Iso.eq_inv_comp] apply map_uniq exact ((assoc φ _ _) ▸ hτ₂) /-- Precomposing a co-Cartesian morphism with an isomorphism lifting the identity is co-Cartesian. -/ instance of_iso_comp {a' : 𝒳} (φ' : a' ≅ a) [IsHomLift p (𝟙 R) φ'.hom] : IsCocartesian p f (φ'.hom ≫ φ) where universal_property := by intro c ψ hψ use IsCocartesian.map p f φ (φ'.inv ≫ ψ) refine ⟨⟨inferInstance, by simp⟩, ?_⟩ rintro τ ⟨hτ₁, hτ₂⟩ apply map_uniq simp only [Iso.eq_inv_comp, ← assoc, hτ₂] end IsCocartesian namespace IsStronglyCocartesian section variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [IsStronglyCocartesian p f φ] /-- The universal property of a strongly co-Cartesian morphism. This lemma is more flexible with respect to non-definitional equalities than the field `universal_property'` of `IsStronglyCocartesian`. -/ lemma universal_property {S' : 𝒮} {b' : 𝒳} (g : S ⟶ S') (f' : R ⟶ S') (hf' : f' = f ≫ g) (φ' : a ⟶ b') [IsHomLift p f' φ'] : ∃! χ : b ⟶ b', IsHomLift p g χ ∧ φ ≫ χ = φ' := by subst_hom_lift p f' φ'; clear a b R S have : p.IsHomLift (f ≫ g) φ' := (hf' ▸ inferInstance) apply IsStronglyCocartesian.universal_property' f instance isCocartesian_of_isStronglyCocartesian [p.IsStronglyCocartesian f φ] : p.IsCocartesian f φ where universal_property := fun φ' => universal_property p f φ (𝟙 S) f (comp_id f).symm φ' section variable {S' : 𝒮} {b' : 𝒳} {g : S ⟶ S'} {f' : R ⟶ S'} (hf' : f' = f ≫ g) (φ' : a ⟶ b') [IsHomLift p f' φ'] /-- Given a diagram ``` a --φ--> b b' | | | v v v R --f--> S --g--> S' ``` such that `φ` is strongly co-Cartesian, and a morphism `φ' : a ⟶ b'`. Then `map` is the map `b ⟶ b'` lying over `g` obtained from the universal property of `φ`. -/ noncomputable def map : b ⟶ b' := Classical.choose <| universal_property p f φ _ _ hf' φ' instance map_isHomLift : IsHomLift p g (map p f φ hf' φ') := (Classical.choose_spec <| universal_property p f φ _ _ hf' φ').1.1 @[reassoc (attr := simp)] lemma fac : φ ≫ (map p f φ hf' φ') = φ' := (Classical.choose_spec <| universal_property p f φ _ _ hf' φ').1.2 /-- Given a diagram ``` a --φ--> b b' | | | v v v R --f--> S --g--> S' ``` such that `φ` is strongly co-Cartesian, and morphisms `φ' : a ⟶ b'`, `ψ : b ⟶ b'` such that `g ≫ ψ = φ'`. Then `ψ` is the map induced by the universal property. -/ lemma map_uniq (ψ : b ⟶ b') [IsHomLift p g ψ] (hψ : φ ≫ ψ = φ') : ψ = map p f φ hf' φ' := (Classical.choose_spec <| universal_property p f φ _ _ hf' φ').2 ψ ⟨inferInstance, hψ⟩ end /-- Given a diagram ``` a --φ--> b b' | | | v v v R --f--> S --g--> S' ``` such that `φ` is strongly co-Cartesian, and morphisms `ψ ψ' : b ⟶ b'` such that `g ≫ ψ = φ' = g ≫ ψ'`. Then we have that `ψ = ψ'`. -/ protected lemma ext (φ : a ⟶ b) [IsStronglyCocartesian p f φ] {S' : 𝒮} {b' : 𝒳} (g : S ⟶ S') {ψ ψ' : b ⟶ b'} [IsHomLift p g ψ] [IsHomLift p g ψ'] (h : φ ≫ ψ = φ ≫ ψ') : ψ = ψ' := by rw [map_uniq p f φ (g := g) rfl (φ ≫ ψ) ψ rfl, map_uniq p f φ (g := g) rfl (φ ≫ ψ) ψ' h.symm] @[simp] lemma map_self : map p f φ (comp_id f).symm φ = 𝟙 b := by subst_hom_lift p f φ; symm apply map_uniq simp only [comp_id] /-- When its possible to compare the two, the composition of two `IsStronglyCocartesian.map` will also be given by a `IsStronglyCocartesian.map`. In other words, given diagrams ``` a --φ--> b b' b'' | | | | v v v v R --f--> S --g--> S' --g'--> S' ``` and ``` a --φ'--> b' | | v v R --f'--> S' ``` and ``` a --φ''--> b'' | | v v R --f''--> S'' ``` such that `φ` and `φ'` are strongly co-Cartesian morphisms, and such that `f' = f ≫ g` and `f'' = f' ≫ g'`. Then composing the induced map from `b ⟶ b'` with the induced map from `b' ⟶ b''` gives the induced map from `b ⟶ b''`. -/ @[reassoc (attr := simp)] lemma map_comp_map {S' S'' : 𝒮} {b' b'' : 𝒳} {f' : R ⟶ S'} {f'' : R ⟶ S''} {g : S ⟶ S'} {g' : S' ⟶ S''} (H : f' = f ≫ g) (H' : f'' = f' ≫ g') (φ' : a ⟶ b') (φ'' : a ⟶ b'') [IsStronglyCocartesian p f' φ'] [IsHomLift p f'' φ''] : map p f φ H φ' ≫ map p f' φ' H' φ'' = map p f φ (show f'' = f ≫ (g ≫ g') by rwa [← assoc, ← H]) φ'' := by apply map_uniq p f φ simp only [fac_assoc, fac] end section variable {R S T : 𝒮} {a b c : 𝒳} {f : R ⟶ S} {g : S ⟶ T} {φ : a ⟶ b} {ψ : b ⟶ c} /-- Given two strongly co-Cartesian morphisms `φ`, `ψ` as follows ``` a --φ--> b --ψ--> c | | | v v v R --f--> S --g--> T ``` Then the composite `φ ≫ ψ` is also strongly co-Cartesian. -/ instance comp [IsStronglyCocartesian p f φ] [IsStronglyCocartesian p g ψ] : IsStronglyCocartesian p (f ≫ g) (φ ≫ ψ) where universal_property' := by intro c' h τ hτ use map p g ψ (f' := g ≫ h) rfl <| map p f φ (assoc f g h) τ refine ⟨⟨inferInstance, ?_⟩, ?_⟩ · simp only [assoc, fac] · intro π' ⟨hπ'₁, hπ'₂⟩ apply map_uniq apply map_uniq simp only [← hπ'₂, assoc] /-- Given two commutative squares ``` a --φ--> b --ψ--> c | | | v v v R --f--> S --g--> T ``` such that `φ ≫ ψ` and `φ` are strongly co-Cartesian, then so is `ψ`. -/ protected lemma of_comp [IsStronglyCocartesian p f φ] [IsStronglyCocartesian p (f ≫ g) (φ ≫ ψ)] [IsHomLift p g ψ] : IsStronglyCocartesian p g ψ where universal_property' := by intro c' h τ hτ /- We get a morphism `π : c ⟶ c'` such that `(φ ≫ ψ) ≫ π = φ ≫ τ` from the universal property of `φ ≫ ψ`. This will be the morphism induced by `φ`. -/ use map p (f ≫ g) (φ ≫ ψ) (f' := f ≫ g ≫ h) (assoc f g h).symm (φ ≫ τ) refine ⟨⟨inferInstance, ?_⟩, ?_⟩ /- The fact that `ψ ≫ π = τ` follows from `φ ≫ ψ ≫ π = φ ≫ τ` and the universal property of `φ`. -/ · apply IsStronglyCocartesian.ext p f φ (g ≫ h) <| by simp only [← assoc, fac] -- Finally, uniqueness of `π` comes from the universal property of `φ ≫ ψ`. · intro π' ⟨hπ'₁, hπ'₂⟩ apply map_uniq simp [hπ'₂.symm] end section variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) instance of_iso (φ : a ≅ b) [IsHomLift p f φ.hom] : IsStronglyCocartesian p f φ.hom where universal_property' := by intro b' g τ hτ use φ.inv ≫ τ refine ⟨?_, by cat_disch⟩ simpa [← assoc] using (IsHomLift.comp p (isoOfIsoLift p f φ).inv (f ≫ g) φ.inv τ) instance of_isIso (φ : a ⟶ b) [IsHomLift p f φ] [IsIso φ] : IsStronglyCocartesian p f φ := @IsStronglyCocartesian.of_iso _ _ _ _ p _ _ _ _ f (asIso φ) (by aesop) /-- A strongly co-Cartesian arrow lying over an isomorphism is an isomorphism. -/ lemma isIso_of_base_isIso (φ : a ⟶ b) [IsStronglyCocartesian p f φ] [IsIso f] : IsIso φ := by subst_hom_lift p f φ; clear a b R S -- Let `φ'` be the morphism induced by applying universal property to `𝟙 a` lying over `f ≫ f⁻¹`. let φ' := map p (p.map φ) φ (IsIso.hom_inv_id (p.map φ)).symm (𝟙 a) use φ' -- `φ ≫ φ' = 𝟙 a` follows immediately from the universal property. have inv_hom : φ ≫ φ' = 𝟙 a := fac p (p.map φ) φ _ (𝟙 a) refine ⟨inv_hom, ?_⟩ -- We will now show that `φ' ≫ φ = 𝟙 b` by showing that `φ ≫ (φ' ≫ φ) = φ ≫ 𝟙 b`. have h₁ : IsHomLift p (𝟙 (p.obj b)) (φ' ≫ φ) := by rw [← IsIso.inv_hom_id (p.map φ)] apply IsHomLift.comp apply IsStronglyCocartesian.ext p (p.map φ) φ (𝟙 (p.obj b)) simp only [← assoc, inv_hom, comp_id, id_comp] end /-- The canonical isomorphism between the codomains of two strongly co-Cartesian arrows lying over isomorphic objects. -/ noncomputable def codomainIsoOfBaseIso {R S S' : 𝒮} {a b b' : 𝒳} {f : R ⟶ S} {f' : R ⟶ S'} {g : S ≅ S'} (h : f' = f ≫ g.hom) (φ : a ⟶ b) (φ' : a ⟶ b') [IsStronglyCocartesian p f φ] [IsStronglyCocartesian p f' φ'] : b ≅ b' where hom := map p f φ h φ' inv := @map _ _ _ _ p _ _ _ _ f' φ' _ _ _ _ _ (congrArg (· ≫ g.inv) h.symm) φ (by simp only [assoc, Iso.hom_inv_id, comp_id]; infer_instance) end IsStronglyCocartesian end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/Cartesian.lean
import Mathlib.CategoryTheory.FiberedCategory.HomLift /-! # Cartesian morphisms This file defines Cartesian resp. strongly Cartesian morphisms with respect to a functor `p : 𝒳 ⥤ 𝒮`. This file has been adapted to `Mathlib/CategoryTheory/FiberedCategory/Cocartesian.lean`, please try to change them in sync. ## Main definitions `IsCartesian p f φ` expresses that `φ` is a Cartesian morphism lying over `f` with respect to `p` in the sense of SGA 1 VI 5.1. This means that for any morphism `φ' : a' ⟶ b` lying over `f` there is a unique morphism `τ : a' ⟶ a` lying over `𝟙 R`, such that `φ' = τ ≫ φ`. `IsStronglyCartesian p f φ` expresses that `φ` is a strongly Cartesian morphism lying over `f` with respect to `p`, see <https://stacks.math.columbia.edu/tag/02XK>. ## Implementation The constructor of `IsStronglyCartesian` has been named `universal_property'`, and is mainly intended to be used for constructing instances of this class. To use the universal property, we generally recommended to use the lemma `IsStronglyCartesian.universal_property` instead. The difference between the two is that the latter is more flexible with respect to non-definitional equalities. ## References * [A. Grothendieck, M. Raynaud, *SGA 1*](https://arxiv.org/abs/math/0206203) * [Stacks: Fibred Categories](https://stacks.math.columbia.edu/tag/02XJ) -/ universe v₁ v₂ u₁ u₂ open CategoryTheory Functor Category IsHomLift namespace CategoryTheory.Functor variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒮] [Category.{v₂} 𝒳] (p : 𝒳 ⥤ 𝒮) section variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) /-- A morphism `φ : a ⟶ b` in `𝒳` lying over `f : R ⟶ S` in `𝒮` is Cartesian if for all morphisms `φ' : a' ⟶ b`, also lying over `f`, there exists a unique morphism `χ : a' ⟶ a` lifting `𝟙 R` such that `φ' = χ ≫ φ`. See SGA 1 VI 5.1. -/ class IsCartesian : Prop where [toIsHomLift : IsHomLift p f φ] universal_property {a' : 𝒳} (φ' : a' ⟶ b) [IsHomLift p f φ'] : ∃! χ : a' ⟶ a, IsHomLift p (𝟙 R) χ ∧ χ ≫ φ = φ' attribute [instance] IsCartesian.toIsHomLift /-- A morphism `φ : a ⟶ b` in `𝒳` lying over `f : R ⟶ S` in `𝒮` is strongly Cartesian if for all morphisms `φ' : a' ⟶ b` and all diagrams of the form ``` a' a --φ--> b | | | v v v R' --g--> R --f--> S ``` such that `φ'` lifts `g ≫ f`, there exists a lift `χ` of `g` such that `φ' = χ ≫ φ`. -/ @[stacks 02XK] class IsStronglyCartesian : Prop where [toIsHomLift : IsHomLift p f φ] universal_property' {a' : 𝒳} (g : p.obj a' ⟶ R) (φ' : a' ⟶ b) [IsHomLift p (g ≫ f) φ'] : ∃! χ : a' ⟶ a, IsHomLift p g χ ∧ χ ≫ φ = φ' attribute [instance] IsStronglyCartesian.toIsHomLift end namespace IsCartesian variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [IsCartesian p f φ] section variable {a' : 𝒳} (φ' : a' ⟶ b) [IsHomLift p f φ'] /-- Given a Cartesian morphism `φ : a ⟶ b` lying over `f : R ⟶ S` in `𝒳`, and another morphism `φ' : a' ⟶ b` which also lifts `f`, then `IsCartesian.map f φ φ'` is the morphism `a' ⟶ a` lifting `𝟙 R` obtained from the universal property of `φ`. -/ protected noncomputable def map : a' ⟶ a := Classical.choose <| IsCartesian.universal_property (p := p) (f := f) (φ := φ) φ' instance map_isHomLift : IsHomLift p (𝟙 R) (IsCartesian.map p f φ φ') := (Classical.choose_spec <| IsCartesian.universal_property (p := p) (f := f) (φ := φ) φ').1.1 @[reassoc (attr := simp)] lemma fac : IsCartesian.map p f φ φ' ≫ φ = φ' := (Classical.choose_spec <| IsCartesian.universal_property (p := p) (f := f) (φ := φ) φ').1.2 /-- Given a Cartesian morphism `φ : a ⟶ b` lying over `f : R ⟶ S` in `𝒳`, and another morphism `φ' : a' ⟶ b` which also lifts `f`. Then any morphism `ψ : a' ⟶ a` lifting `𝟙 R` such that `g ≫ ψ = φ'` must equal the map induced from the universal property of `φ`. -/ lemma map_uniq (ψ : a' ⟶ a) [IsHomLift p (𝟙 R) ψ] (hψ : ψ ≫ φ = φ') : ψ = IsCartesian.map p f φ φ' := (Classical.choose_spec <| IsCartesian.universal_property (p := p) (f := f) (φ := φ) φ').2 ψ ⟨inferInstance, hψ⟩ end /-- Given a Cartesian morphism `φ : a ⟶ b` lying over `f : R ⟶ S` in `𝒳`, and two morphisms `ψ ψ' : a' ⟶ a` such that `ψ ≫ φ = ψ' ≫ φ`. Then we must have `ψ = ψ'`. -/ protected lemma ext (φ : a ⟶ b) [IsCartesian p f φ] {a' : 𝒳} (ψ ψ' : a' ⟶ a) [IsHomLift p (𝟙 R) ψ] [IsHomLift p (𝟙 R) ψ'] (h : ψ ≫ φ = ψ' ≫ φ) : ψ = ψ' := by rw [map_uniq p f φ (ψ ≫ φ) ψ rfl, map_uniq p f φ (ψ ≫ φ) ψ' h.symm] @[simp] lemma map_self : IsCartesian.map p f φ φ = 𝟙 a := by subst_hom_lift p f φ; symm apply map_uniq simp only [id_comp] instance of_comp_iso {b' : 𝒳} (φ' : b ≅ b') [IsHomLift p (𝟙 S) φ'.hom] : IsCartesian p f (φ ≫ φ'.hom) where universal_property := by intro c ψ hψ use IsCartesian.map p f φ (ψ ≫ φ'.inv) refine ⟨⟨inferInstance, by simp only [fac_assoc, assoc, Iso.inv_hom_id, comp_id]⟩, ?_⟩ rintro τ ⟨hτ₁, hτ₂⟩ apply map_uniq rw [Iso.eq_comp_inv] simp only [assoc, hτ₂] /-- The canonical isomorphism between the domains of two Cartesian arrows lying over the same object. -/ @[simps] noncomputable def domainUniqueUpToIso {a' : 𝒳} (φ' : a' ⟶ b) [IsCartesian p f φ'] : a' ≅ a where hom := IsCartesian.map p f φ φ' inv := IsCartesian.map p f φ' φ hom_inv_id := by subst_hom_lift p f φ' apply IsCartesian.ext p (p.map φ') φ' simp only [assoc, fac, id_comp] inv_hom_id := by subst_hom_lift p f φ apply IsCartesian.ext p (p.map φ) φ simp only [assoc, fac, id_comp] instance domainUniqueUpToIso_inv_isHomLift {a' : 𝒳} (φ' : a' ⟶ b) [IsCartesian p f φ'] : IsHomLift p (𝟙 R) (domainUniqueUpToIso p f φ φ').hom := domainUniqueUpToIso_hom p f φ φ' ▸ IsCartesian.map_isHomLift p f φ φ' instance domainUniqueUpToIso_hom_isHomLift {a' : 𝒳} (φ' : a' ⟶ b) [IsCartesian p f φ'] : IsHomLift p (𝟙 R) (domainUniqueUpToIso p f φ φ').inv := domainUniqueUpToIso_inv p f φ φ' ▸ IsCartesian.map_isHomLift p f φ' φ /-- Precomposing a Cartesian morphism with an isomorphism lifting the identity is Cartesian. -/ instance of_iso_comp {a' : 𝒳} (φ' : a' ≅ a) [IsHomLift p (𝟙 R) φ'.hom] : IsCartesian p f (φ'.hom ≫ φ) where universal_property := by intro c ψ hψ use IsCartesian.map p f φ ψ ≫ φ'.inv refine ⟨⟨inferInstance, by simp⟩, ?_⟩ rintro τ ⟨hτ₁, hτ₂⟩ rw [Iso.eq_comp_inv] apply map_uniq simp only [assoc, hτ₂] end IsCartesian namespace IsStronglyCartesian section variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [IsStronglyCartesian p f φ] /-- The universal property of a strongly Cartesian morphism. This lemma is more flexible with respect to non-definitional equalities than the field `universal_property'` of `IsStronglyCartesian`. -/ lemma universal_property {R' : 𝒮} {a' : 𝒳} (g : R' ⟶ R) (f' : R' ⟶ S) (hf' : f' = g ≫ f) (φ' : a' ⟶ b) [IsHomLift p f' φ'] : ∃! χ : a' ⟶ a, IsHomLift p g χ ∧ χ ≫ φ = φ' := by subst_hom_lift p f' φ'; clear a b R S have : p.IsHomLift (g ≫ f) φ' := (hf' ▸ inferInstance) apply IsStronglyCartesian.universal_property' f instance isCartesian_of_isStronglyCartesian [p.IsStronglyCartesian f φ] : p.IsCartesian f φ where universal_property := fun φ' => universal_property p f φ (𝟙 R) f (by simp) φ' section variable {R' : 𝒮} {a' : 𝒳} {g : R' ⟶ R} {f' : R' ⟶ S} (hf' : f' = g ≫ f) (φ' : a' ⟶ b) [IsHomLift p f' φ'] /-- Given a diagram ``` a' a --φ--> b | | | v v v R' --g--> R --f--> S ``` such that `φ` is strongly Cartesian, and a morphism `φ' : a' ⟶ b`. Then `map` is the map `a' ⟶ a` lying over `g` obtained from the universal property of `φ`. -/ noncomputable def map : a' ⟶ a := Classical.choose <| universal_property p f φ _ _ hf' φ' instance map_isHomLift : IsHomLift p g (map p f φ hf' φ') := (Classical.choose_spec <| universal_property p f φ _ _ hf' φ').1.1 @[reassoc (attr := simp)] lemma fac : (map p f φ hf' φ') ≫ φ = φ' := (Classical.choose_spec <| universal_property p f φ _ _ hf' φ').1.2 /-- Given a diagram ``` a' a --φ--> b | | | v v v R' --g--> R --f--> S ``` such that `φ` is strongly Cartesian, and morphisms `φ' : a' ⟶ b`, `ψ : a' ⟶ a` such that `ψ ≫ φ = φ'`. Then `ψ` is the map induced by the universal property. -/ lemma map_uniq (ψ : a' ⟶ a) [IsHomLift p g ψ] (hψ : ψ ≫ φ = φ') : ψ = map p f φ hf' φ' := (Classical.choose_spec <| universal_property p f φ _ _ hf' φ').2 ψ ⟨inferInstance, hψ⟩ end /-- Given a diagram ``` a' a --φ--> b | | | v v v R' --g--> R --f--> S ``` such that `φ` is strongly Cartesian, and morphisms `ψ ψ' : a' ⟶ a` such that `g ≫ ψ = φ' = g ≫ ψ'`. Then we have that `ψ = ψ'`. -/ protected lemma ext (φ : a ⟶ b) [IsStronglyCartesian p f φ] {R' : 𝒮} {a' : 𝒳} (g : R' ⟶ R) {ψ ψ' : a' ⟶ a} [IsHomLift p g ψ] [IsHomLift p g ψ'] (h : ψ ≫ φ = ψ' ≫ φ) : ψ = ψ' := by rw [map_uniq p f φ (g := g) rfl (ψ ≫ φ) ψ rfl, map_uniq p f φ (g := g) rfl (ψ ≫ φ) ψ' h.symm] @[simp] lemma map_self : map p f φ (id_comp f).symm φ = 𝟙 a := by subst_hom_lift p f φ; symm apply map_uniq simp only [id_comp] /-- When its possible to compare the two, the composition of two `IsStronglyCartesian.map` will also be given by a `IsStronglyCartesian.map`. In other words, given diagrams ``` a'' a' a --φ--> b | | | | v v v v R'' --g'--> R' --g--> R --f--> S ``` and ``` a' --φ'--> b | | v v R' --f'--> S ``` and ``` a'' --φ''--> b | | v v R'' --f''--> S ``` such that `φ` and `φ'` are strongly Cartesian morphisms, and such that `f' = g ≫ f` and `f'' = g' ≫ f'`. Then composing the induced map from `a'' ⟶ a'` with the induced map from `a' ⟶ a` gives the induced map from `a'' ⟶ a`. -/ @[reassoc (attr := simp)] lemma map_comp_map {R' R'' : 𝒮} {a' a'' : 𝒳} {f' : R' ⟶ S} {f'' : R'' ⟶ S} {g : R' ⟶ R} {g' : R'' ⟶ R'} (H : f' = g ≫ f) (H' : f'' = g' ≫ f') (φ' : a' ⟶ b) (φ'' : a'' ⟶ b) [IsStronglyCartesian p f' φ'] [IsHomLift p f'' φ''] : map p f' φ' H' φ'' ≫ map p f φ H φ' = map p f φ (show f'' = (g' ≫ g) ≫ f by rwa [assoc, ← H]) φ'' := by apply map_uniq p f φ simp only [assoc, fac] end section variable {R S T : 𝒮} {a b c : 𝒳} {f : R ⟶ S} {g : S ⟶ T} {φ : a ⟶ b} {ψ : b ⟶ c} /-- Given two strongly Cartesian morphisms `φ`, `ψ` as follows ``` a --φ--> b --ψ--> c | | | v v v R --f--> S --g--> T ``` Then the composite `φ ≫ ψ` is also strongly Cartesian. -/ instance comp [IsStronglyCartesian p f φ] [IsStronglyCartesian p g ψ] : IsStronglyCartesian p (f ≫ g) (φ ≫ ψ) where universal_property' := by intro a' h τ hτ use map p f φ (f' := h ≫ f) rfl (map p g ψ (assoc h f g).symm τ) refine ⟨⟨inferInstance, ?_⟩, ?_⟩ · rw [← assoc, fac, fac] · intro π' ⟨hπ'₁, hπ'₂⟩ apply map_uniq apply map_uniq simp only [assoc, hπ'₂] /-- Given two commutative squares ``` a --φ--> b --ψ--> c | | | v v v R --f--> S --g--> T ``` such that `φ ≫ ψ` and `ψ` are strongly Cartesian, then so is `φ`. -/ protected lemma of_comp [IsStronglyCartesian p g ψ] [IsStronglyCartesian p (f ≫ g) (φ ≫ ψ)] [IsHomLift p f φ] : IsStronglyCartesian p f φ where universal_property' := by intro a' h τ hτ have h₁ : IsHomLift p (h ≫ f ≫ g) (τ ≫ ψ) := by simpa using IsHomLift.comp p (h ≫ f) _ τ ψ /- We get a morphism `π : a' ⟶ a` such that `π ≫ φ ≫ ψ = τ ≫ ψ` from the universal property of `φ ≫ ψ`. This will be the morphism induced by `φ`. -/ use map p (f ≫ g) (φ ≫ ψ) (f' := h ≫ f ≫ g) rfl (τ ≫ ψ) refine ⟨⟨inferInstance, ?_⟩, ?_⟩ /- The fact that `π ≫ φ = τ` follows from `π ≫ φ ≫ ψ = τ ≫ ψ` and the universal property of `ψ`. -/ · apply IsStronglyCartesian.ext p g ψ (h ≫ f) (by simp) -- Finally, the uniqueness of `π` comes from the universal property of `φ ≫ ψ`. · intro π' ⟨hπ'₁, hπ'₂⟩ apply map_uniq simp [hπ'₂.symm] end section variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) instance of_iso (φ : a ≅ b) [IsHomLift p f φ.hom] : IsStronglyCartesian p f φ.hom where universal_property' := by intro a' g τ hτ use τ ≫ φ.inv refine ⟨?_, by cat_disch⟩ simpa using (IsHomLift.comp p (g ≫ f) (isoOfIsoLift p f φ).inv τ φ.inv) instance of_isIso (φ : a ⟶ b) [IsHomLift p f φ] [IsIso φ] : IsStronglyCartesian p f φ := @IsStronglyCartesian.of_iso _ _ _ _ p _ _ _ _ f (asIso φ) (by aesop) /-- A strongly Cartesian morphism lying over an isomorphism is an isomorphism. -/ lemma isIso_of_base_isIso (φ : a ⟶ b) [IsStronglyCartesian p f φ] [IsIso f] : IsIso φ := by subst_hom_lift p f φ; clear a b R S -- Let `φ` be the morphism induced by applying universal property to `𝟙 b` lying over `f⁻¹ ≫ f`. let φ' := map p (p.map φ) φ (IsIso.inv_hom_id (p.map φ)).symm (𝟙 b) use φ' -- `φ' ≫ φ = 𝟙 b` follows immediately from the universal property. have inv_hom : φ' ≫ φ = 𝟙 b := fac p (p.map φ) φ _ (𝟙 b) refine ⟨?_, inv_hom⟩ -- We will now show that `φ ≫ φ' = 𝟙 a` by showing that `(φ ≫ φ') ≫ φ = 𝟙 a ≫ φ`. have h₁ : IsHomLift p (𝟙 (p.obj a)) (φ ≫ φ') := by rw [← IsIso.hom_inv_id (p.map φ)] apply IsHomLift.comp apply IsStronglyCartesian.ext p (p.map φ) φ (𝟙 (p.obj a)) simp only [assoc, inv_hom, comp_id, id_comp] end section variable {R R' S : 𝒮} {a a' b : 𝒳} {f : R ⟶ S} {f' : R' ⟶ S} {g : R' ≅ R} /-- The canonical isomorphism between the domains of two strongly Cartesian morphisms lying over isomorphic objects. -/ @[simps] noncomputable def domainIsoOfBaseIso (h : f' = g.hom ≫ f) (φ : a ⟶ b) (φ' : a' ⟶ b) [IsStronglyCartesian p f φ] [IsStronglyCartesian p f' φ'] : a' ≅ a where hom := map p f φ h φ' inv := haveI : p.IsHomLift ((fun x ↦ g.inv ≫ x) (g.hom ≫ f)) φ := by simpa using IsCartesian.toIsHomLift map p f' φ' (congrArg (g.inv ≫ ·) h.symm) φ instance domainUniqueUpToIso_inv_isHomLift (h : f' = g.hom ≫ f) (φ : a ⟶ b) (φ' : a' ⟶ b) [IsStronglyCartesian p f φ] [IsStronglyCartesian p f' φ'] : IsHomLift p g.hom (domainIsoOfBaseIso p h φ φ').hom := domainIsoOfBaseIso_hom p h φ φ' ▸ IsStronglyCartesian.map_isHomLift p f φ h φ' instance domainUniqueUpToIso_hom_isHomLift (h : f' = g.hom ≫ f) (φ : a ⟶ b) (φ' : a' ⟶ b) [IsStronglyCartesian p f φ] [IsStronglyCartesian p f' φ'] : IsHomLift p g.inv (domainIsoOfBaseIso p h φ φ').inv := by haveI : p.IsHomLift ((fun x ↦ g.inv ≫ x) (g.hom ≫ f)) φ := by simpa using IsCartesian.toIsHomLift simpa using IsStronglyCartesian.map_isHomLift p f' φ' (congrArg (g.inv ≫ ·) h.symm) φ end end IsStronglyCartesian end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/BasedCategory.lean
import Mathlib.CategoryTheory.FiberedCategory.HomLift import Mathlib.CategoryTheory.Bicategory.Strict.Basic import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic /-! # The bicategory of based categories In this file we define the type `BasedCategory 𝒮`, and give it the structure of a strict bicategory. Given a category `𝒮`, we define the type `BasedCategory 𝒮` as the type of categories `𝒳` equipped with a functor `𝒳.p : 𝒳 ⥤ 𝒮`. We also define a type of functors between based categories `𝒳` and `𝒴`, which we call `BasedFunctor 𝒳 𝒴` and denote as `𝒳 ⥤ᵇ 𝒴`. These are defined as functors between the underlying categories `𝒳.obj` and `𝒴.obj` which commute with the projections to `𝒮`. Natural transformations between based functors `F G : 𝒳 ⥤ᵇ 𝒴 ` are given by the structure `BasedNatTrans F G`. These are defined as natural transformations `α` between the functors underlying `F` and `G` such that `α.app a` lifts `𝟙 S` whenever `𝒳.p.obj a = S`. -/ universe v₅ u₅ v₄ u₄ v₃ u₃ v₂ u₂ v₁ u₁ namespace CategoryTheory open Functor Category NatTrans IsHomLift variable {𝒮 : Type u₁} [Category.{v₁} 𝒮] /-- A based category over `𝒮` is a category `𝒳` together with a functor `p : 𝒳 ⥤ 𝒮`. -/ @[nolint checkUnivs] structure BasedCategory (𝒮 : Type u₁) [Category.{v₁} 𝒮] where /-- The type of objects in a `BasedCategory` -/ obj : Type u₂ /-- The underlying category of a `BasedCategory`. -/ category : Category.{v₂} obj := by infer_instance /-- The functor to the base. -/ p : obj ⥤ 𝒮 instance (𝒳 : BasedCategory.{v₂, u₂} 𝒮) : Category 𝒳.obj := 𝒳.category /-- The based category associated to a functor `p : 𝒳 ⥤ 𝒮`. -/ def BasedCategory.ofFunctor {𝒳 : Type u₂} [Category.{v₂} 𝒳] (p : 𝒳 ⥤ 𝒮) : BasedCategory 𝒮 where obj := 𝒳 p := p /-- A functor between based categories is a functor between the underlying categories that commutes with the projections. -/ structure BasedFunctor (𝒳 : BasedCategory.{v₂, u₂} 𝒮) (𝒴 : BasedCategory.{v₃, u₃} 𝒮) extends 𝒳.obj ⥤ 𝒴.obj where w : toFunctor ⋙ 𝒴.p = 𝒳.p := by cat_disch /-- Notation for `BasedFunctor`. -/ scoped infixr:26 " ⥤ᵇ " => BasedFunctor namespace BasedFunctor initialize_simps_projections BasedFunctor (+toFunctor, -obj, -map) /-- The identity based functor. -/ @[simps] def id (𝒳 : BasedCategory.{v₂, u₂} 𝒮) : 𝒳 ⥤ᵇ 𝒳 where toFunctor := 𝟭 𝒳.obj variable {𝒳 : BasedCategory.{v₂, u₂} 𝒮} {𝒴 : BasedCategory.{v₃, u₃} 𝒮} /-- Notation for the identity functor on a based category. -/ scoped notation "𝟭" => BasedFunctor.id /-- The composition of two based functors. -/ @[simps] def comp {𝒵 : BasedCategory.{v₄, u₄} 𝒮} (F : 𝒳 ⥤ᵇ 𝒴) (G : 𝒴 ⥤ᵇ 𝒵) : 𝒳 ⥤ᵇ 𝒵 where toFunctor := F.toFunctor ⋙ G.toFunctor w := by rw [Functor.assoc, G.w, F.w] /-- Notation for composition of based functors. -/ scoped infixr:80 " ⋙ " => BasedFunctor.comp @[simp] lemma comp_id (F : 𝒳 ⥤ᵇ 𝒴) : F ⋙ 𝟭 𝒴 = F := rfl @[simp] lemma id_comp (F : 𝒳 ⥤ᵇ 𝒴) : 𝟭 𝒳 ⋙ F = F := rfl @[simp] lemma comp_assoc {𝒵 : BasedCategory.{v₄, u₄} 𝒮} {𝒜 : BasedCategory.{v₅, u₅} 𝒮} (F : 𝒳 ⥤ᵇ 𝒴) (G : 𝒴 ⥤ᵇ 𝒵) (H : 𝒵 ⥤ᵇ 𝒜) : (F ⋙ G) ⋙ H = F ⋙ (G ⋙ H) := rfl @[simp] lemma w_obj (F : 𝒳 ⥤ᵇ 𝒴) (a : 𝒳.obj) : 𝒴.p.obj (F.obj a) = 𝒳.p.obj a := by rw [← Functor.comp_obj, F.w] instance (F : 𝒳 ⥤ᵇ 𝒴) (a : 𝒳.obj) : IsHomLift 𝒴.p (𝟙 (𝒳.p.obj a)) (𝟙 (F.obj a)) := IsHomLift.id (w_obj F a) section variable (F : 𝒳 ⥤ᵇ 𝒴) {R S : 𝒮} {a b : 𝒳.obj} (f : R ⟶ S) (φ : a ⟶ b) /-- For a based functor `F : 𝒳 ⟶ 𝒴`, then whenever an arrow `φ` in `𝒳` lifts some `f` in `𝒮`, then `F(φ)` also lifts `f`. -/ instance preserves_isHomLift [IsHomLift 𝒳.p f φ] : IsHomLift 𝒴.p f (F.map φ) := by apply of_fac 𝒴.p f (F.map φ) (Eq.trans (F.w_obj a) (domain_eq 𝒳.p f φ)) (Eq.trans (F.w_obj b) (codomain_eq 𝒳.p f φ)) rw [← Functor.comp_map, congr_hom F.w] simpa using (fac 𝒳.p f φ) /-- For a based functor `F : 𝒳 ⟶ 𝒴`, and an arrow `φ` in `𝒳`, then `φ` lifts an arrow `f` in `𝒮` if `F(φ)` does. -/ lemma isHomLift_map [IsHomLift 𝒴.p f (F.map φ)] : IsHomLift 𝒳.p f φ := by apply of_fac 𝒳.p f φ (F.w_obj a ▸ domain_eq 𝒴.p f (F.map φ)) (F.w_obj b ▸ codomain_eq 𝒴.p f (F.map φ)) simp [congr_hom F.w.symm, fac 𝒴.p f (F.map φ)] lemma isHomLift_iff : IsHomLift 𝒴.p f (F.map φ) ↔ IsHomLift 𝒳.p f φ := ⟨fun _ ↦ isHomLift_map F f φ, fun _ ↦ preserves_isHomLift F f φ⟩ end end BasedFunctor /-- A `BasedNatTrans` between two `BasedFunctor`s is a natural transformation `α` between the underlying functors, such that for all `a : 𝒳`, `α.app a` lifts `𝟙 S` whenever `𝒳.p.obj a = S`. -/ structure BasedNatTrans {𝒳 : BasedCategory.{v₂, u₂} 𝒮} {𝒴 : BasedCategory.{v₃, u₃} 𝒮} (F G : 𝒳 ⥤ᵇ 𝒴) extends CategoryTheory.NatTrans F.toFunctor G.toFunctor where isHomLift' : ∀ (a : 𝒳.obj), IsHomLift 𝒴.p (𝟙 (𝒳.p.obj a)) (toNatTrans.app a) := by cat_disch namespace BasedNatTrans open BasedFunctor variable {𝒳 : BasedCategory.{v₂, u₂} 𝒮} {𝒴 : BasedCategory.{v₃, u₃} 𝒮} initialize_simps_projections BasedNatTrans (+toNatTrans, -app) section variable {F G : 𝒳 ⥤ᵇ 𝒴} (α : BasedNatTrans F G) @[ext] lemma ext (β : BasedNatTrans F G) (h : α.toNatTrans = β.toNatTrans) : α = β := by cases α; subst h; rfl instance app_isHomLift (a : 𝒳.obj) : IsHomLift 𝒴.p (𝟙 (𝒳.p.obj a)) (α.toNatTrans.app a) := α.isHomLift' a lemma isHomLift {a : 𝒳.obj} {S : 𝒮} (ha : 𝒳.p.obj a = S) : IsHomLift 𝒴.p (𝟙 S) (α.toNatTrans.app a) := by subst ha; infer_instance end /-- The identity natural transformation is a `BasedNatTrans`. -/ @[simps] def id (F : 𝒳 ⥤ᵇ 𝒴) : BasedNatTrans F F where toNatTrans := CategoryTheory.NatTrans.id F.toFunctor isHomLift' := fun a ↦ of_fac 𝒴.p _ _ (w_obj F a) (w_obj F a) (by simp) /-- Composition of `BasedNatTrans`, given by composition of the underlying natural transformations. -/ @[simps] def comp {F G H : 𝒳 ⥤ᵇ 𝒴} (α : BasedNatTrans F G) (β : BasedNatTrans G H) : BasedNatTrans F H where toNatTrans := CategoryTheory.NatTrans.vcomp α.toNatTrans β.toNatTrans isHomLift' := by intro a rw [CategoryTheory.NatTrans.vcomp_app] infer_instance @[simps] instance homCategory (𝒳 : BasedCategory.{v₂, u₂} 𝒮) (𝒴 : BasedCategory.{v₃, u₃} 𝒮) : Category (𝒳 ⥤ᵇ 𝒴) where Hom := BasedNatTrans id := BasedNatTrans.id comp := BasedNatTrans.comp @[ext] lemma homCategory.ext {F G : 𝒳 ⥤ᵇ 𝒴} (α β : F ⟶ G) (h : α.toNatTrans = β.toNatTrans) : α = β := BasedNatTrans.ext α β h /-- The forgetful functor from the category of based functors `𝒳 ⥤ᵇ 𝒴` to the category of functors of underlying categories, `𝒳.obj ⥤ 𝒴.obj`. -/ @[simps] def forgetful (𝒳 : BasedCategory.{v₂, u₂} 𝒮) (𝒴 : BasedCategory.{v₃, u₃} 𝒮) : (𝒳 ⥤ᵇ 𝒴) ⥤ (𝒳.obj ⥤ 𝒴.obj) where obj := fun F ↦ F.toFunctor map := fun α ↦ α.toNatTrans instance : (forgetful 𝒳 𝒴).ReflectsIsomorphisms where reflects {F G} α _ := by constructor use { toNatTrans := inv ((forgetful 𝒳 𝒴).map α) isHomLift' := fun a ↦ by simp [lift_id_inv_isIso] } aesop instance {F G : 𝒳 ⥤ᵇ 𝒴} (α : F ⟶ G) [IsIso α] : IsIso (X := F.toFunctor) α.toNatTrans := by rw [← forgetful_map]; infer_instance end BasedNatTrans namespace BasedNatIso open BasedNatTrans variable {𝒳 : BasedCategory.{v₂, u₂} 𝒮} {𝒴 : BasedCategory.{v₃, u₃} 𝒮} /-- The identity natural transformation is a based natural isomorphism. -/ @[simps] def id (F : 𝒳 ⥤ᵇ 𝒴) : F ≅ F where hom := 𝟙 F inv := 𝟙 F variable {F G : 𝒳 ⥤ᵇ 𝒴} /-- The inverse of a based natural transformation whose underlying natural transformation is an isomorphism. -/ def mkNatIso (α : F.toFunctor ≅ G.toFunctor) (isHomLift' : ∀ a : 𝒳.obj, IsHomLift 𝒴.p (𝟙 (𝒳.p.obj a)) (α.hom.app a)) : F ≅ G where hom := { toNatTrans := α.hom } inv := { toNatTrans := α.inv isHomLift' := fun a ↦ by have : 𝒴.p.IsHomLift (𝟙 (𝒳.p.obj a)) (α.app a).hom := (Iso.app_hom α a) ▸ isHomLift' a rw [← Iso.app_inv] apply IsHomLift.lift_id_inv } lemma isIso_of_toNatTrans_isIso (α : F ⟶ G) [IsIso (X := F.toFunctor) α.toNatTrans] : IsIso α := have : IsIso ((forgetful 𝒳 𝒴).map α) := by simp_all Functor.ReflectsIsomorphisms.reflects (forgetful 𝒳 𝒴) α end BasedNatIso namespace BasedCategory open BasedFunctor BasedNatTrans section variable {𝒳 : BasedCategory.{v₂, u₂} 𝒮} {𝒴 : BasedCategory.{v₃, u₃} 𝒮} /-- Left-whiskering in the bicategory `BasedCategory` is given by whiskering the underlying functors and natural transformations. -/ @[simps] def whiskerLeft {𝒵 : BasedCategory.{v₄, u₄} 𝒮} (F : 𝒳 ⥤ᵇ 𝒴) {G H : 𝒴 ⥤ᵇ 𝒵} (α : G ⟶ H) : F ⋙ G ⟶ F ⋙ H where toNatTrans := Functor.whiskerLeft F.toFunctor α.toNatTrans isHomLift' := fun a ↦ α.isHomLift (F.w_obj a) /-- Right-whiskering in the bicategory `BasedCategory` is given by whiskering the underlying functors and natural transformations. -/ @[simps] def whiskerRight {𝒵 : BasedCategory.{v₄, u₄} 𝒮} {F G : 𝒳 ⥤ᵇ 𝒴} (α : F ⟶ G) (H : 𝒴 ⥤ᵇ 𝒵) : F ⋙ H ⟶ G ⋙ H where toNatTrans := Functor.whiskerRight α.toNatTrans H.toFunctor isHomLift' := fun _ ↦ BasedFunctor.preserves_isHomLift _ _ _ end /-- The category of based categories. -/ @[simps] instance : Category (BasedCategory.{v₂, u₂} 𝒮) where Hom := BasedFunctor id := id comp := comp /-- The bicategory of based categories. -/ instance bicategory : Bicategory (BasedCategory.{v₂, u₂} 𝒮) where Hom 𝒳 𝒴 := 𝒳 ⥤ᵇ 𝒴 id 𝒳 := 𝟭 𝒳 comp F G := F ⋙ G homCategory 𝒳 𝒴 := homCategory 𝒳 𝒴 whiskerLeft {_ _ _} F {_ _} α := whiskerLeft F α whiskerRight {_ _ _} _ _ α H := whiskerRight α H associator _ _ _ := BasedNatIso.id _ leftUnitor {_ _} F := BasedNatIso.id F rightUnitor {_ _} F := BasedNatIso.id F /-- The bicategory structure on `BasedCategory.{v₂, u₂} 𝒮` is strict. -/ instance : Bicategory.Strict (BasedCategory.{v₂, u₂} 𝒮) where end BasedCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/Fibered.lean
import Mathlib.CategoryTheory.FiberedCategory.Cartesian /-! # Fibered categories This file defines what it means for a functor `p : 𝒳 ⥤ 𝒮` to be (pre)fibered. ## Main definitions - `IsPreFibered p` expresses `𝒳` is fibered over `𝒮` via a functor `p : 𝒳 ⥤ 𝒮`, as in SGA VI.6.1. This means that any morphism in the base `𝒮` can be lifted to a Cartesian morphism in `𝒳`. - `IsFibered p` expresses `𝒳` is fibered over `𝒮` via a functor `p : 𝒳 ⥤ 𝒮`, as in SGA VI.6.1. This means that it is prefibered, and that the composition of any two Cartesian morphisms is Cartesian. In the literature one often sees the notion of a fibered category defined as the existence of strongly Cartesian morphisms lying over any given morphism in the base. This is equivalent to the notion above, and we give an alternate constructor `IsFibered.of_exists_isCartesian'` for constructing a fibered category this way. ## Implementation The constructor of `IsPreFibered` is called `exists_isCartesian'`. The reason for the prime is that when wanting to apply this condition, it is recommended to instead use the lemma `exists_isCartesian` (without the prime), which is more applicable with respect to non-definitional equalities. ## References * [A. Grothendieck, M. Raynaud, *SGA 1*](https://arxiv.org/abs/math/0206203) -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Functor Category IsHomLift variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒮] [Category.{v₂} 𝒳] /-- Definition of a prefibered category. See SGA 1 VI.6.1. -/ class Functor.IsPreFibered (p : 𝒳 ⥤ 𝒮) : Prop where exists_isCartesian' {a : 𝒳} {R : 𝒮} (f : R ⟶ p.obj a) : ∃ (b : 𝒳) (φ : b ⟶ a), IsCartesian p f φ protected lemma IsPreFibered.exists_isCartesian (p : 𝒳 ⥤ 𝒮) [p.IsPreFibered] {a : 𝒳} {R S : 𝒮} (ha : p.obj a = S) (f : R ⟶ S) : ∃ (b : 𝒳) (φ : b ⟶ a), IsCartesian p f φ := by subst ha; exact IsPreFibered.exists_isCartesian' f /-- Definition of a fibered category. See SGA 1 VI.6.1. -/ class Functor.IsFibered (p : 𝒳 ⥤ 𝒮) : Prop extends IsPreFibered p where comp {R S T : 𝒮} (f : R ⟶ S) (g : S ⟶ T) {a b c : 𝒳} (φ : a ⟶ b) (ψ : b ⟶ c) [IsCartesian p f φ] [IsCartesian p g ψ] : IsCartesian p (f ≫ g) (φ ≫ ψ) instance (p : 𝒳 ⥤ 𝒮) [p.IsFibered] {R S T : 𝒮} (f : R ⟶ S) (g : S ⟶ T) {a b c : 𝒳} (φ : a ⟶ b) (ψ : b ⟶ c) [IsCartesian p f φ] [IsCartesian p g ψ] : IsCartesian p (f ≫ g) (φ ≫ ψ) := IsFibered.comp f g φ ψ namespace Functor.IsPreFibered variable {p : 𝒳 ⥤ 𝒮} [IsPreFibered p] {R S : 𝒮} {a : 𝒳} (ha : p.obj a = S) (f : R ⟶ S) /-- Given a fibered category `p : 𝒳 ⥤ 𝒫`, a morphism `f : R ⟶ S` and an object `a` lying over `S`, then `pullbackObj` is the domain of some choice of a Cartesian morphism lying over `f` with codomain `a`. -/ noncomputable def pullbackObj : 𝒳 := Classical.choose (IsPreFibered.exists_isCartesian p ha f) /-- Given a fibered category `p : 𝒳 ⥤ 𝒫`, a morphism `f : R ⟶ S` and an object `a` lying over `S`, then `pullbackMap` is a choice of a Cartesian morphism lying over `f` with codomain `a`. -/ noncomputable def pullbackMap : pullbackObj ha f ⟶ a := Classical.choose (Classical.choose_spec (IsPreFibered.exists_isCartesian p ha f)) instance pullbackMap.IsCartesian : IsCartesian p f (pullbackMap ha f) := Classical.choose_spec (Classical.choose_spec (IsPreFibered.exists_isCartesian p ha f)) lemma pullbackObj_proj : p.obj (pullbackObj ha f) = R := domain_eq p f (pullbackMap ha f) end Functor.IsPreFibered namespace Functor.IsFibered open IsCartesian IsPreFibered /-- In a fibered category, any Cartesian morphism is strongly Cartesian. -/ instance isStronglyCartesian_of_isCartesian (p : 𝒳 ⥤ 𝒮) [p.IsFibered] {R S : 𝒮} (f : R ⟶ S) {a b : 𝒳} (φ : a ⟶ b) [p.IsCartesian f φ] : p.IsStronglyCartesian f φ where universal_property' g φ' hφ' := by -- Let `ψ` be a Cartesian arrow lying over `g` let ψ := pullbackMap (domain_eq p f φ) g -- Let `τ` be the map induced by the universal property of `ψ ≫ φ`. let τ := IsCartesian.map p (g ≫ f) (ψ ≫ φ) φ' use τ ≫ ψ -- It is easily verified that `τ ≫ ψ` lifts `g` and `τ ≫ ψ ≫ φ = φ'` refine ⟨⟨inferInstance, by simp only [assoc, IsCartesian.fac, τ]⟩, ?_⟩ -- It remains to check that `τ ≫ ψ` is unique. -- So fix another lift `π` of `g` satisfying `π ≫ φ = φ'`. intro π ⟨hπ, hπ_comp⟩ -- Write `π` as `π = τ' ≫ ψ` for some `τ'` induced by the universal property of `ψ`. rw [← fac p g ψ π] -- It remains to show that `τ' = τ`. This follows again from the universal property of `ψ`. congr 1 apply map_uniq rwa [← assoc, IsCartesian.fac] /-- In a category which admits strongly Cartesian pullbacks, any Cartesian morphism is strongly Cartesian. This is a helper-lemma for the fact that admitting strongly Cartesian pullbacks implies being fibered. -/ lemma isStronglyCartesian_of_exists_isCartesian (p : 𝒳 ⥤ 𝒮) (h : ∀ (a : 𝒳) (R : 𝒮) (f : R ⟶ p.obj a), ∃ (b : 𝒳) (φ : b ⟶ a), IsStronglyCartesian p f φ) {R S : 𝒮} (f : R ⟶ S) {a b : 𝒳} (φ : a ⟶ b) [p.IsCartesian f φ] : p.IsStronglyCartesian f φ := by constructor intro c g φ' hφ' subst_hom_lift p f φ; clear a b R S -- Let `ψ` be a Cartesian arrow lying over `g` obtain ⟨a', ψ, hψ⟩ := h _ _ (p.map φ) -- Let `τ' : c ⟶ a'` be the map induced by the universal property of `ψ` let τ' := IsStronglyCartesian.map p (p.map φ) ψ (f':= g ≫ p.map φ) rfl φ' -- Let `Φ : a' ≅ a` be natural isomorphism induced between `φ` and `ψ`. let Φ := domainUniqueUpToIso p (p.map φ) φ ψ -- The map induced by `φ` will be `τ' ≫ Φ.hom` use τ' ≫ Φ.hom -- It is easily verified that `τ' ≫ Φ.hom` lifts `g` and `τ' ≫ Φ.hom ≫ φ = φ'` refine ⟨⟨by simp only [Φ]; infer_instance, ?_⟩, ?_⟩ · simp [τ', Φ] -- It remains to check that it is unique. This follows from the universal property of `ψ`. intro π ⟨hπ, hπ_comp⟩ rw [← Iso.comp_inv_eq] apply IsStronglyCartesian.map_uniq p (p.map φ) ψ rfl φ' simp [hπ_comp, Φ] /-- Alternate constructor for `IsFibered`, a functor `p : 𝒳 ⥤ 𝒴` is fibered if any diagram of the form ``` a - | v R --f--> p(a) ``` admits a strongly Cartesian lift `b ⟶ a` of `f`. -/ lemma of_exists_isStronglyCartesian {p : 𝒳 ⥤ 𝒮} (h : ∀ (a : 𝒳) (R : 𝒮) (f : R ⟶ p.obj a), ∃ (b : 𝒳) (φ : b ⟶ a), IsStronglyCartesian p f φ) : IsFibered p where exists_isCartesian' := by intro a R f obtain ⟨b, φ, hφ⟩ := h a R f refine ⟨b, φ, inferInstance⟩ comp := fun R S T f g {a b c} φ ψ _ _ => have : p.IsStronglyCartesian f φ := isStronglyCartesian_of_exists_isCartesian p h _ _ have : p.IsStronglyCartesian g ψ := isStronglyCartesian_of_exists_isCartesian p h _ _ inferInstance /-- Given a diagram ``` a - | v T --g--> R --f--> S ``` we have an isomorphism `T ×_S a ≅ T ×_R (R ×_S a)` -/ noncomputable def pullbackPullbackIso {p : 𝒳 ⥤ 𝒮} [IsFibered p] {R S T : 𝒮} {a : 𝒳} (ha : p.obj a = S) (f : R ⟶ S) (g : T ⟶ R) : pullbackObj ha (g ≫ f) ≅ pullbackObj (pullbackObj_proj ha f) g := domainUniqueUpToIso p (g ≫ f) (pullbackMap (pullbackObj_proj ha f) g ≫ pullbackMap ha f) (pullbackMap ha (g ≫ f)) end Functor.IsFibered end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/Grothendieck.lean
import Mathlib.CategoryTheory.Bicategory.Grothendieck import Mathlib.CategoryTheory.FiberedCategory.HasFibers /-! # The Grothendieck construction gives a fibered category In this file we show that the Grothendieck construction applied to a pseudofunctor `F` gives a fibered category over the base category. We also provide a `HasFibers` instance to `∫ᶜ F`, such that the fiber over `S` is the category `F(S)`. ## References [Vistoli2008] "Notes on Grothendieck Topologies, Fibered Categories and Descent Theory" by Angelo Vistoli -/ namespace CategoryTheory.Pseudofunctor.CoGrothendieck open Functor Opposite Bicategory Fiber variable {𝒮 : Type*} [Category 𝒮] {F : LocallyDiscrete 𝒮ᵒᵖ ⥤ᵖ Cat} section variable {R S : 𝒮} (a : F.obj ⟨op S⟩) (f : R ⟶ S) /-- The domain of the Cartesian lift of `f`. -/ abbrev domainCartesianLift : ∫ᶜ F := ⟨R, (F.map f.op.toLoc).obj a⟩ /-- The Cartesian lift of `f`. -/ abbrev cartesianLift : domainCartesianLift a f ⟶ ⟨S, a⟩ := ⟨f, 𝟙 _⟩ instance isHomLift_cartesianLift : IsHomLift (forget F) f (cartesianLift a f) := IsHomLift.map (forget F) (cartesianLift a f) variable {a} in /-- Given some lift `φ'` of `g ≫ f`, the canonical map from the domain of `φ'` to the domain of the Cartesian lift of `f`. -/ abbrev homCartesianLift {a' : ∫ᶜ F} (g : a'.1 ⟶ R) (φ' : a' ⟶ ⟨S, a⟩) [IsHomLift (forget F) (g ≫ f) φ'] : a' ⟶ domainCartesianLift a f where base := g fiber := have : φ'.base = g ≫ f := by simpa using IsHomLift.fac' (forget F) (g ≫ f) φ' φ'.fiber ≫ eqToHom (by simp [this]) ≫ (F.mapComp f.op.toLoc g.op.toLoc).hom.app a instance isHomLift_homCartesianLift {a' : ∫ᶜ F} {φ' : a' ⟶ ⟨S, a⟩} {g : a'.1 ⟶ R} [IsHomLift (forget F) (g ≫ f) φ'] : IsHomLift (forget F) g (homCartesianLift f g φ') := IsHomLift.map (forget F) (homCartesianLift f g φ') lemma isStronglyCartesian_homCartesianLift : IsStronglyCartesian (forget F) f (cartesianLift a f) where universal_property' {a'} g φ' hφ' := by refine ⟨homCartesianLift f g φ', ⟨inferInstance, ?_⟩, ?_⟩ · exact Hom.ext _ _ (by simpa using IsHomLift.fac (forget F) (g ≫ f) φ') (by simp) rintro χ' ⟨hχ'.symm, rfl⟩ obtain ⟨rfl⟩ : g = χ'.1 := by simpa using IsHomLift.fac (forget F) g χ' ext <;> simp end /-- `forget F : ∫ᶜ F ⥤ 𝒮` is a fibered category. -/ instance : IsFibered (forget F) := IsFibered.of_exists_isStronglyCartesian (fun a _ f ↦ ⟨domainCartesianLift a.2 f, cartesianLift a.2 f, isStronglyCartesian_homCartesianLift a.2 f⟩) variable (F) (S : 𝒮) attribute [local simp] PrelaxFunctor.map₂_eqToHom in /-- The inclusion map from `F(S)` into `∫ᶜ F`. -/ @[simps] def ι : F.obj ⟨op S⟩ ⥤ ∫ᶜ F where obj a := { base := S, fiber := a} map {a b} φ := { base := 𝟙 S, fiber := φ ≫ (F.mapId ⟨op S⟩).inv.app b} map_comp {a b c} φ ψ := by ext · simp · simp [← (F.mapId ⟨op S⟩).inv.naturality_assoc ψ, F.whiskerRight_mapId_inv_app, Strict.leftUnitor_eqToIso] /-- The natural isomorphism encoding `comp_const`. -/ @[simps!] def compIso : (ι F S) ⋙ forget F ≅ (const (F.obj ⟨op S⟩)).obj S := NatIso.ofComponents (fun a => eqToIso rfl) lemma comp_const : (ι F S) ⋙ forget F = (const (F.obj ⟨op S⟩)).obj S := Functor.ext_of_iso (compIso F S) (fun _ ↦ rfl) (fun _ => rfl) noncomputable instance : (Fiber.inducedFunctor (comp_const F S)).Full where map_surjective {X Y} f := by have hf : (fiberInclusion.map f).base = 𝟙 S := by simpa using (IsHomLift.fac (forget F) (𝟙 S) (fiberInclusion.map f)).symm use (fiberInclusion.map f).2 ≫ eqToHom (by simp [hf]) ≫ (F.mapId ⟨op S⟩).hom.app Y ext <;> simp [hf] instance : (Fiber.inducedFunctor (comp_const F S)).Faithful where map_injective {a b} := by intro f g heq replace heq := fiberInclusion.congr_map heq simpa [cancel_mono] using ((Hom.ext_iff _ _).1 heq).2 noncomputable instance : (Fiber.inducedFunctor (comp_const F S)).EssSurj := by apply essSurj_of_surj intro Y have hYS : (fiberInclusion.obj Y).base = S := by simpa using Y.2 use hYS ▸ (fiberInclusion.obj Y).fiber apply fiberInclusion_obj_inj ext <;> simp [hYS] noncomputable instance : (Fiber.inducedFunctor (comp_const F S)).IsEquivalence where /-- `HasFibers` instance for `∫ᶜ F`, where the fiber over `S` is `F.obj ⟨op S⟩`. -/ noncomputable instance : HasFibers (forget F) where Fib S := F.obj ⟨op S⟩ ι := ι F comp_const := comp_const F end CategoryTheory.Pseudofunctor.CoGrothendieck
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/HasFibers.lean
import Mathlib.CategoryTheory.FiberedCategory.Fiber import Mathlib.CategoryTheory.FiberedCategory.Fibered /-! # Fibers of functors In this file we introduce a typeclass `HasFibers` for a functor `p : 𝒳 ⥤ 𝒮`, consisting of: - A collection of categories `Fib S` for every `S` in `𝒮` (the fiber categories) - Functors `ι : Fib S ⥤ 𝒳` such that `ι ⋙ p = const (Fib S) S` - The induced functor `Fib S ⥤ Fiber p S` is an equivalence. We also provide a canonical `HasFibers` instance, which uses the standard fibers `Fiber p S` (see `Mathlib/CategoryTheory/FiberedCategory/Fiber.lean`). This makes it so that any result proven about `HasFibers` can be used for the standard fibers as well. The reason for introducing this typeclass is that in practice, when working with (pre)fibered categories one often already has a collection of categories `Fib S` for every `S` that are equivalent to the fibers `Fiber p S`. One would then like to use these categories `Fib S` directly, instead of working through this equivalence of categories. By developing an API for the `HasFibers` typeclass, this will be possible. Here is an example of when this typeclass is useful. Suppose we have a presheaf of types `F : 𝒮ᵒᵖ ⥤ Type _`. The associated fibered category then has objects `(S, a)` where `S : 𝒮` and `a` is an element of `F(S)`. The fiber category `Fiber p S` is then equivalent to the discrete category `Fib S` with objects `a` in `F(S)`. In this case, the `HasFibers` instance is given by the categories `F(S)` and the functor `ι` sends `a : F(S)` to `(S, a)` in the fibered category. ## Main API The following API is developed so that the fibers from a `HasFibers` instance can be used analogously to the standard fibers. - `Fib.homMk φ` is a lift of a morphism `φ : (ι S).obj a ⟶ (ι S).obj b` in `𝒳`, which lies over `𝟙 S`, to a morphism in the fiber over `S`. - `Fib.mk` gives an object in the fiber over `S` which is isomorphic to a given `a : 𝒳` that satisfies `p(a) = S`. The isomorphism is given by `Fib.mkIsoSelf`. - `HasFibers.mkPullback` is a version of `IsPreFibered.mkPullback` which ensures that the object lies in a given fiber. The corresponding Cartesian morphism is given by `HasFibers.pullbackMap`. - `HasFibers.inducedMap` is a version of `IsCartesian.inducedMap` which gives the corresponding morphism in the fiber category. - `fiber_factorization` is the statement that any morphism in `𝒳` can be factored as a morphism in some fiber followed by a pullback. -/ universe v₃ u₃ v₂ u₂ v₁ u₁ open CategoryTheory Functor Category IsCartesian IsHomLift Fiber variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒮] [Category.{v₂} 𝒳] /-- HasFibers is an extrinsic notion of fibers on a functor `p : 𝒳 ⥤ 𝒮`. It is given by a collection of categories `Fib S` for every `S : 𝒮` (the fiber categories), each equipped with a functors `ι : Fib S ⥤ 𝒳` which map constantly to `S` on the base such that the induced functor `Fib S ⥤ Fiber p S` is an equivalence. -/ @[nolint checkUnivs] class HasFibers (p : 𝒳 ⥤ 𝒮) where /-- The type of objects of the category `Fib S` for each `S`. -/ Fib (S : 𝒮) : Type u₃ /-- `Fib S` is a category. -/ category (S : 𝒮) : Category.{v₃} (Fib S) := by infer_instance /-- The functor `ι : Fib S ⥤ 𝒳`. -/ ι (S : 𝒮) : Fib S ⥤ 𝒳 /-- The composition with the functor `p` is *equal* to the constant functor mapping to `S`. -/ comp_const (S : 𝒮) : ι S ⋙ p = (const (Fib S)).obj S /-- The induced functor from `Fib S` to the fiber of `𝒳 ⥤ 𝒮` over `S` is an equivalence. -/ equiv (S : 𝒮) : Functor.IsEquivalence (inducedFunctor (comp_const S)) := by infer_instance namespace HasFibers /-- The `HasFibers` on `p : 𝒳 ⥤ 𝒮` given by the fibers of `p` -/ def canonical (p : 𝒳 ⥤ 𝒮) : HasFibers p where Fib := Fiber p ι S := fiberInclusion comp_const S := fiberInclusion_comp_eq_const equiv S := by exact isEquivalence_of_iso (F := 𝟭 (Fiber p S)) (Iso.refl _) section variable (p : 𝒳 ⥤ 𝒮) [HasFibers p] (S : 𝒮) attribute [instance] category /-- The induced functor from `Fib p S` to the standard fiber. -/ @[simps!] def inducedFunctor : Fib p S ⥤ Fiber p S := Fiber.inducedFunctor (comp_const S) /-- The natural transformation `ι S ≅ (inducedFunctor p S) ⋙ (fiberInclusion p S)` -/ def inducedFunctor.natIso : ι S ≅ (inducedFunctor p S) ⋙ fiberInclusion := Fiber.inducedFunctorCompIsoSelf (comp_const S) lemma inducedFunctor_comp : ι S = (inducedFunctor p S) ⋙ fiberInclusion := Fiber.inducedFunctor_comp (comp_const S) instance : Functor.IsEquivalence (inducedFunctor p S) := equiv S instance : Functor.Faithful (ι (p:=p) S) := Functor.Faithful.of_iso (inducedFunctor.natIso p S).symm end section variable {p : 𝒳 ⥤ 𝒮} [HasFibers p] @[simp] lemma proj_eq {S : 𝒮} (a : Fib p S) : p.obj ((ι S).obj a) = S := by simp only [← comp_obj, comp_const, const_obj_obj] /-- The morphism `R ⟶ S` in `𝒮` obtained by projecting a morphism `φ : (ι R).obj a ⟶ (ι S).obj b`. -/ def projMap {R S : 𝒮} {a : Fib p R} {b : Fib p S} (φ : (ι R).obj a ⟶ (ι S).obj b) : R ⟶ S := eqToHom (proj_eq a).symm ≫ (p.map φ) ≫ eqToHom (proj_eq b) /-- For any homomorphism `φ` in a fiber `Fib S`, its image under `ι S` lies over `𝟙 S`. -/ instance homLift {S : 𝒮} {a b : Fib p S} (φ : a ⟶ b) : IsHomLift p (𝟙 S) ((ι S).map φ) := by apply of_fac p _ _ (proj_eq a) (proj_eq b) rw [← Functor.comp_map, Functor.congr_hom (comp_const S)] simp /-- A version of fullness of the functor `Fib S ⥤ Fiber p S` that can be used inside the category `𝒳`. -/ noncomputable def Fib.homMk {S : 𝒮} {a b : Fib p S} (φ : (ι S).obj a ⟶ (ι S).obj b) [IsHomLift p (𝟙 S) φ] : a ⟶ b := (inducedFunctor _ S).preimage (Fiber.homMk p S φ) @[simp] lemma Fib.map_homMk {S : 𝒮} {a b : Fib p S} (φ : (ι S).obj a ⟶ (ι S).obj b) [IsHomLift p (𝟙 S) φ] : (ι S).map (homMk φ) = φ := by simp [Fib.homMk, congr_hom (inducedFunctor_comp p S)] @[ext] lemma Fib.hom_ext {S : 𝒮} {a b : Fib p S} {f g : a ⟶ b} (h : (ι S).map f = (ι S).map g) : f = g := (ι S).map_injective h /-- The lift of an isomorphism `Φ : (ι S).obj a ≅ (ι S).obj b` lying over `𝟙 S` to an isomorphism in `Fib S`. -/ @[simps] noncomputable def Fib.isoMk {S : 𝒮} {a b : Fib p S} (Φ : (ι S).obj a ≅ (ι S).obj b) (hΦ : IsHomLift p (𝟙 S) Φ.hom) : a ≅ b where hom := Fib.homMk Φ.hom inv := Fib.homMk Φ.inv /-- An object in `Fib p S` isomorphic in `𝒳` to a given object `a : 𝒳` such that `p(a) = S`. -/ noncomputable def Fib.mk {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : Fib p S := Functor.objPreimage (inducedFunctor p S) (Fiber.mk ha) /-- Applying `ι S` to the preimage of `a : 𝒳` in `Fib p S` yields an object isomorphic to `a`. -/ noncomputable def Fib.mkIsoSelf {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : (ι S).obj (Fib.mk ha) ≅ a := fiberInclusion.mapIso (Functor.objObjPreimageIso (inducedFunctor p S) (Fiber.mk ha)) instance Fib.mkIsoSelfIsHomLift {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : IsHomLift p (𝟙 S) (Fib.mkIsoSelf ha).hom := (Functor.objObjPreimageIso (inducedFunctor p S) (Fiber.mk ha)).hom.2 section variable [IsPreFibered p] {R S : 𝒮} {a : 𝒳} (f : R ⟶ S) (ha : p.obj a = S) /-- The domain, taken in `Fib p R`, of some Cartesian morphism lifting a given `f : R ⟶ S` in `𝒮` -/ noncomputable def mkPullback : Fib p R := Fib.mk (domain_eq p f (IsPreFibered.pullbackMap ha f)) /-- A Cartesian morphism lifting `f : R ⟶ S` with domain in the image of `Fib p R` -/ noncomputable def pullbackMap : (ι R).obj (mkPullback f ha) ⟶ a := (Fib.mkIsoSelf (domain_eq p f (IsPreFibered.pullbackMap ha f))).hom ≫ (IsPreFibered.pullbackMap ha f) instance pullbackMap.isCartesian : IsCartesian p f (pullbackMap f ha) := by conv in f => rw [← id_comp f] simp only [id_comp, pullbackMap] infer_instance end section variable {R S : 𝒮} {a : 𝒳} {b b' : Fib p R} (f : R ⟶ S) (ψ : (ι R).obj b' ⟶ a) [IsCartesian p f ψ] (φ : (ι R).obj b ⟶ a) [IsHomLift p f φ] /-- Given a fibered category p, b' b in Fib R, and a pullback ψ : b ⟶ a in 𝒳, i.e. ``` b' b --ψ--> a | | | v v v R ====== R --f--> S ``` Then the induced map τ : b' ⟶ b can be lifted to the fiber over R -/ noncomputable def inducedMap : b ⟶ b' := Fib.homMk (IsCartesian.map p f ψ φ) @[reassoc] lemma inducedMap_comp : (ι R).map (inducedMap f ψ φ) ≫ ψ = φ := by simp only [inducedMap, Fib.map_homMk, IsCartesian.fac] end section variable [IsFibered p] {R S : 𝒮} {a : 𝒳} {b : Fib p R} /-- Given `a : 𝒳`, `b : Fib p R`, and a diagram ``` b --φ--> a - - | | v v R --f--> S ``` It can be factorized as ``` b --τ--> b'--ψ--> a - - - | | | v v v R ====== R --f--> S ``` with `ψ` Cartesian over `f` and `τ` a map in `Fib p R`. -/ lemma fiber_factorization (ha : p.obj a = S) {b : Fib p R} (f : R ⟶ S) (φ : (ι R).obj b ⟶ a) [IsHomLift p f φ] : ∃ (b' : Fib p R) (τ : b ⟶ b') (ψ : (ι R).obj b' ⟶ a), IsStronglyCartesian p f ψ ∧ (((ι R).map τ) ≫ ψ = φ) := let ψ := pullbackMap f ha ⟨mkPullback f ha, inducedMap f ψ φ, ψ, inferInstance, inducedMap_comp f ψ φ⟩ end end end HasFibers
.lake/packages/mathlib/Mathlib/CategoryTheory/FiberedCategory/HomLift.lean
import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.CommSq /-! # HomLift Given a functor `p : 𝒳 ⥤ 𝒮`, this file provides API for expressing the fact that `p(φ) = f` for given morphisms `φ` and `f`. The reason this API is needed is because, in general, `p.map φ = f` does not make sense when the domain and/or codomain of `φ` and `f` are not definitionally equal. ## Main definition Given morphism `φ : a ⟶ b` in `𝒳` and `f : R ⟶ S` in `𝒮`, `p.IsHomLift f φ` is a class which expresses the fact that `f = p(φ)`. We also define a macro `subst_hom_lift p f φ` which can be used to substitute `f` with `p(φ)` in a goal, this tactic is just short for `obtain ⟨⟩ := inferInstanceAs (p.IsHomLift f φ)`, and it is used to make the code more readable. ## Implementation The class `IsHomLift` is defined as an inductive with the single constructor `.map (φ : a ⟶ b) : IsHomLift p (p.map φ) φ`, similar to how `Eq a b` has the single constructor `.rfl (a : α) : Eq a a`. -/ universe u₁ v₁ u₂ v₂ open CategoryTheory Category variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒳] [Category.{v₂} 𝒮] (p : 𝒳 ⥤ 𝒮) namespace CategoryTheory /-- Given a functor `p : 𝒳 ⥤ 𝒮`, an arrow `φ : a ⟶ b` in `𝒳` and an arrow `f : R ⟶ S` in `𝒮`, `p.IsHomLift f φ` expresses the fact that `φ` lifts `f` through `p`. This is often drawn as: ``` a --φ--> b - - | | v v R --f--> S ``` -/ class inductive Functor.IsHomLift : ∀ {R S : 𝒮} {a b : 𝒳} (_ : R ⟶ S) (_ : a ⟶ b), Prop | map {a b : 𝒳} (φ : a ⟶ b) : IsHomLift (p.map φ) φ /-- `subst_hom_lift p f φ` tries to substitute `f` with `p(φ)` by using `p.IsHomLift f φ` -/ macro "subst_hom_lift" p:term:max f:term:max φ:term:max : tactic => `(tactic| obtain ⟨⟩ := inferInstanceAs (Functor.IsHomLift $p $f $φ)) namespace IsHomLift /-- For any arrow `φ : a ⟶ b` in `𝒳`, `φ` lifts the arrow `p.map φ` in the base `𝒮`. -/ @[simp] instance map {a b : 𝒳} (φ : a ⟶ b) : p.IsHomLift (p.map φ) φ := .map φ @[simp] instance (a : 𝒳) : p.IsHomLift (𝟙 (p.obj a)) (𝟙 a) := by rw [← p.map_id]; infer_instance protected lemma id {p : 𝒳 ⥤ 𝒮} {R : 𝒮} {a : 𝒳} (ha : p.obj a = R) : p.IsHomLift (𝟙 R) (𝟙 a) := by cases ha; infer_instance section variable {R S : 𝒮} {a b : 𝒳} lemma domain_eq (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] : p.obj a = R := by subst_hom_lift p f φ; rfl lemma codomain_eq (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] : p.obj b = S := by subst_hom_lift p f φ; rfl variable (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] lemma fac : f = eqToHom (domain_eq p f φ).symm ≫ p.map φ ≫ eqToHom (codomain_eq p f φ) := by subst_hom_lift p f φ; simp lemma fac' : p.map φ = eqToHom (domain_eq p f φ) ≫ f ≫ eqToHom (codomain_eq p f φ).symm := by subst_hom_lift p f φ; simp lemma commSq : CommSq (p.map φ) (eqToHom (domain_eq p f φ)) (eqToHom (codomain_eq p f φ)) f where w := by simp only [fac p f φ, eqToHom_trans_assoc, eqToHom_refl, id_comp] end lemma eq_of_isHomLift {a b : 𝒳} (f : p.obj a ⟶ p.obj b) (φ : a ⟶ b) [p.IsHomLift f φ] : f = p.map φ := by simp only [fac p f φ, eqToHom_refl, comp_id, id_comp] lemma of_fac {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S) (h : f = eqToHom ha.symm ≫ p.map φ ≫ eqToHom hb) : p.IsHomLift f φ := by subst ha hb h; simp lemma of_fac' {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S) (h : p.map φ = eqToHom ha ≫ f ≫ eqToHom hb.symm) : p.IsHomLift f φ := by subst ha hb obtain rfl : f = p.map φ := by simpa using h.symm infer_instance lemma of_commsq {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S) (h : p.map φ ≫ eqToHom hb = (eqToHom ha) ≫ f) : p.IsHomLift f φ := by subst ha hb obtain rfl : f = p.map φ := by simpa using h.symm infer_instance lemma of_commSq {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S) (h : CommSq (p.map φ) (eqToHom ha) (eqToHom hb) f) : p.IsHomLift f φ := of_commsq p f φ ha hb h.1 instance comp {R S T : 𝒮} {a b c : 𝒳} (f : R ⟶ S) (g : S ⟶ T) (φ : a ⟶ b) (ψ : b ⟶ c) [p.IsHomLift f φ] [p.IsHomLift g ψ] : p.IsHomLift (f ≫ g) (φ ≫ ψ) := by apply of_commSq -- This line transforms the first goal in suitable form; the last line closes all three goals. on_goal 1 => rw [p.map_comp] apply CommSq.horiz_comp (commSq p f φ) (commSq p g ψ) /-- If `φ : a ⟶ b` and `ψ : b ⟶ c` lift `𝟙 R`, then so does `φ ≫ ψ` -/ instance comp_of_lift_id (R : 𝒮) {a b c : 𝒳} (φ : a ⟶ b) (ψ : b ⟶ c) [p.IsHomLift (𝟙 R) φ] [p.IsHomLift (𝟙 R) ψ] : p.IsHomLift (𝟙 R) (φ ≫ ψ) := comp_id (𝟙 R) ▸ comp p (𝟙 R) (𝟙 R) φ ψ instance comp_lift_id_right {a b c : 𝒳} {S T : 𝒮} (f : S ⟶ T) (φ : a ⟶ b) [p.IsHomLift f φ] (ψ : b ⟶ c) [p.IsHomLift (𝟙 T) ψ] : p.IsHomLift f (φ ≫ ψ) := by simpa using inferInstanceAs (p.IsHomLift (f ≫ 𝟙 T) (φ ≫ ψ)) /-- If `φ : a ⟶ b` lifts `f` and `ψ : b ⟶ c` lifts `𝟙 T`, then `φ ≫ ψ` lifts `f` -/ lemma comp_lift_id_right' {R S : 𝒮} {a b c : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] (T : 𝒮) (ψ : b ⟶ c) [p.IsHomLift (𝟙 T) ψ] : p.IsHomLift f (φ ≫ ψ) := by obtain rfl : S = T := by rw [← codomain_eq p f φ, domain_eq p (𝟙 T) ψ] infer_instance instance comp_lift_id_left {a b c : 𝒳} {S T : 𝒮} (f : S ⟶ T) (ψ : b ⟶ c) [p.IsHomLift f ψ] (φ : a ⟶ b) [p.IsHomLift (𝟙 S) φ] : p.IsHomLift f (φ ≫ ψ) := by simpa using inferInstanceAs (p.IsHomLift (𝟙 S ≫ f) (φ ≫ ψ)) /-- If `φ : a ⟶ b` lifts `𝟙 T` and `ψ : b ⟶ c` lifts `f`, then `φ ≫ ψ` lifts `f` -/ lemma comp_lift_id_left' {a b c : 𝒳} (R : 𝒮) (φ : a ⟶ b) [p.IsHomLift (𝟙 R) φ] {S T : 𝒮} (f : S ⟶ T) (ψ : b ⟶ c) [p.IsHomLift f ψ] : p.IsHomLift f (φ ≫ ψ) := by obtain rfl : R = S := by rw [← codomain_eq p (𝟙 R) φ, domain_eq p f ψ] infer_instance lemma eqToHom_domain_lift_id {p : 𝒳 ⥤ 𝒮} {a b : 𝒳} (hab : a = b) {R : 𝒮} (hR : p.obj a = R) : p.IsHomLift (𝟙 R) (eqToHom hab) := by subst hR hab; simp lemma eqToHom_codomain_lift_id {p : 𝒳 ⥤ 𝒮} {a b : 𝒳} (hab : a = b) {S : 𝒮} (hS : p.obj b = S) : p.IsHomLift (𝟙 S) (eqToHom hab) := by subst hS hab; simp lemma id_lift_eqToHom_domain {p : 𝒳 ⥤ 𝒮} {R S : 𝒮} (hRS : R = S) {a : 𝒳} (ha : p.obj a = R) : p.IsHomLift (eqToHom hRS) (𝟙 a) := by subst hRS ha; simp lemma id_lift_eqToHom_codomain {p : 𝒳 ⥤ 𝒮} {R S : 𝒮} (hRS : R = S) {b : 𝒳} (hb : p.obj b = S) : p.IsHomLift (eqToHom hRS) (𝟙 b) := by subst hRS hb; simp section variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] instance comp_id_lift : p.IsHomLift f (𝟙 a ≫ φ) := by simp_all instance id_comp_lift : p.IsHomLift f (φ ≫ 𝟙 b) := by simp_all instance lift_id_comp : p.IsHomLift (𝟙 R ≫ f) φ := by simp_all instance lift_comp_id : p.IsHomLift (f ≫ 𝟙 S) φ := by simp_all instance comp_eqToHom_lift {a' : 𝒳} (h : a' = a) : p.IsHomLift f (eqToHom h ≫ φ) := by subst h; simp_all instance eqToHom_comp_lift {b' : 𝒳} (h : b = b') : p.IsHomLift f (φ ≫ eqToHom h) := by subst h; simp_all instance lift_eqToHom_comp {R' : 𝒮} (h : R' = R) : p.IsHomLift (eqToHom h ≫ f) φ := by subst h; simp_all instance lift_comp_eqToHom {S' : 𝒮} (h : S = S') : p.IsHomLift (f ≫ eqToHom h) φ := by subst h; simp_all end @[simp] lemma comp_eqToHom_lift_iff {R S : 𝒮} {a' a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : a' = a) : p.IsHomLift f (eqToHom h ≫ φ) ↔ p.IsHomLift f φ where mp hφ' := by subst h; simpa using hφ' mpr _ := inferInstance @[simp] lemma eqToHom_comp_lift_iff {R S : 𝒮} {a b b' : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : b = b') : p.IsHomLift f (φ ≫ eqToHom h) ↔ p.IsHomLift f φ where mp hφ' := by subst h; simpa using hφ' mpr _ := inferInstance @[simp] lemma lift_eqToHom_comp_iff {R' R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : R' = R) : p.IsHomLift (eqToHom h ≫ f) φ ↔ p.IsHomLift f φ where mp hφ' := by subst h; simpa using hφ' mpr _ := inferInstance @[simp] lemma lift_comp_eqToHom_iff {R S S' : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : S = S') : p.IsHomLift (f ≫ eqToHom h) φ ↔ p.IsHomLift f φ where mp := fun hφ' => by subst h; simpa using hφ' mpr := fun _ => inferInstance section variable {R S : 𝒮} {a b : 𝒳} /-- Given a morphism `f : R ⟶ S`, and an isomorphism `φ : a ≅ b` lifting `f`, `isoOfIsoLift f φ` is the isomorphism `Φ : R ≅ S` with `Φ.hom = f` induced from `φ` -/ @[simps hom] def isoOfIsoLift (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] : R ≅ S where hom := f inv := eqToHom (codomain_eq p f φ.hom).symm ≫ (p.mapIso φ).inv ≫ eqToHom (domain_eq p f φ.hom) hom_inv_id := by subst_hom_lift p f φ.hom; simp [← p.map_comp] inv_hom_id := by subst_hom_lift p f φ.hom; simp [← p.map_comp] @[simp] lemma isoOfIsoLift_inv_hom_id (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] : (isoOfIsoLift p f φ).inv ≫ f = 𝟙 S := (isoOfIsoLift p f φ).inv_hom_id @[simp] lemma isoOfIsoLift_hom_inv_id (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] : f ≫ (isoOfIsoLift p f φ).inv = 𝟙 R := (isoOfIsoLift p f φ).hom_inv_id /-- If `φ : a ⟶ b` lifts `f : R ⟶ S` and `φ` is an isomorphism, then so is `f`. -/ lemma isIso_of_lift_isIso (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] [IsIso φ] : IsIso f := (fac p f φ) ▸ inferInstance /-- Given `φ : a ≅ b` and `f : R ≅ S`, such that `φ.hom` lifts `f.hom`, then `φ.inv` lifts `f.inv`. -/ instance inv_lift_inv (f : R ≅ S) (φ : a ≅ b) [p.IsHomLift f.hom φ.hom] : p.IsHomLift f.inv φ.inv := by apply of_commSq apply CommSq.horiz_inv (f := p.mapIso φ) (commSq p f.hom φ.hom) /-- Given `φ : a ≅ b` and `f : R ⟶ S`, such that `φ.hom` lifts `f`, then `φ.inv` lifts the inverse of `f` given by `isoOfIsoLift`. -/ instance inv_lift (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] : p.IsHomLift (isoOfIsoLift p f φ).inv φ.inv := by apply of_commSq apply CommSq.horiz_inv (f := p.mapIso φ) (by apply commSq p f φ.hom) /-- If `φ : a ⟶ b` lifts `f : R ⟶ S` and both are isomorphisms, then `φ⁻¹` lifts `f⁻¹`. -/ protected instance inv (f : R ⟶ S) (φ : a ⟶ b) [IsIso f] [IsIso φ] [p.IsHomLift f φ] : p.IsHomLift (inv f) (inv φ) := have : p.IsHomLift (asIso f).hom (asIso φ).hom := by simp_all IsHomLift.inv_lift_inv p (asIso f) (asIso φ) end /-- If `φ : a ≅ b` is an isomorphism lifting `𝟙 S` for some `S : 𝒮`, then `φ⁻¹` also lifts `𝟙 S`. -/ instance lift_id_inv (S : 𝒮) {a b : 𝒳} (φ : a ≅ b) [p.IsHomLift (𝟙 S) φ.hom] : p.IsHomLift (𝟙 S) φ.inv := have : p.IsHomLift (asIso (𝟙 S)).hom φ.hom := by simp_all (IsIso.inv_id (X := S)) ▸ (IsHomLift.inv_lift_inv p (asIso (𝟙 S)) φ) instance lift_id_inv_isIso (S : 𝒮) {a b : 𝒳} (φ : a ⟶ b) [IsIso φ] [p.IsHomLift (𝟙 S) φ] : p.IsHomLift (𝟙 S) (inv φ) := (IsIso.inv_id (X := S)) ▸ (IsHomLift.inv p _ φ) end IsHomLift end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Center/Linear.lean
import Mathlib.CategoryTheory.Preadditive.FunctorCategory import Mathlib.CategoryTheory.Linear.Basic import Mathlib.CategoryTheory.Center.Basic /-! # Center of a linear category If `C` is a `R`-linear category, we define a ring morphism `R →+* CatCenter C` and conversely, if `C` is a preadditive category, and `φ : R →+* CatCenter C` is a ring morphism, we define a `R`-linear structure on `C` attached to `φ`. -/ universe w v u namespace CategoryTheory open Category Limits namespace Linear variable (R : Type w) [Ring R] (C : Type u) [Category.{v} C] [Preadditive C] /-- The canonical morphism `R →+* CatCenter C` when `C` is a `R`-linear category. -/ @[simps] def toCatCenter [Linear R C] : R →+* CatCenter C where toFun a := { app := fun X => a • 𝟙 X } map_one' := by cat_disch map_mul' a b := by rw [mul_comm] ext X dsimp only [CatCenter.mul_app'] rw [Linear.smul_comp, Linear.comp_smul, smul_smul] simp map_zero' := by cat_disch map_add' a b := by ext X dsimp rw [NatTrans.app_add, add_smul] section variable {R C} variable (φ : R →+* CatCenter C) (X Y : C) /-- The scalar multiplication by `R` on the type `X ⟶ Y` of morphisms in a category `C` equipped with a ring morphism `R →+* CatCenter C`. -/ def smulOfRingMorphism : SMul R (X ⟶ Y) where smul a f := (φ a).app X ≫ f variable {X Y} lemma smulOfRingMorphism_smul_eq (a : R) (f : X ⟶ Y) : letI := smulOfRingMorphism φ X Y a • f = (φ a).app X ≫ f := rfl /-- `a • f = f ≫ (φ a).app Y`. -/ lemma smulOfRingMorphism_smul_eq' (a : R) (f : X ⟶ Y) : letI := smulOfRingMorphism φ X Y a • f = f ≫ (φ a).app Y := by rw [smulOfRingMorphism_smul_eq] exact ((φ a).naturality f).symm variable (X Y) /-- The `R`-module structure on the type `X ⟶ Y` of morphisms in a category `C` equipped with a ring morphism `R →+* CatCenter C`. -/ def homModuleOfRingMorphism : Module R (X ⟶ Y) := by letI := smulOfRingMorphism φ X Y exact { one_smul := fun a => by simp only [smulOfRingMorphism_smul_eq, Functor.id_obj, map_one, End.one_def, NatTrans.id_app, id_comp] mul_smul := fun a b f => by simp only [smulOfRingMorphism_smul_eq', Functor.id_obj, map_mul, End.mul_def, NatTrans.comp_app, assoc] smul_zero := fun a => by simp only [smulOfRingMorphism_smul_eq, Functor.id_obj, comp_zero] zero_smul := fun a => by simp only [smulOfRingMorphism_smul_eq, Functor.id_obj, map_zero, zero_app, zero_comp] smul_add := fun a b => by simp [smulOfRingMorphism_smul_eq] add_smul := fun a b f => by simp only [smulOfRingMorphism_smul_eq] rw [map_add, NatTrans.app_add, Preadditive.add_comp] } /-- The `R`-linear structure on a preadditive category `C` equipped with a ring morphism `R →+* CatCenter C`. -/ def ofRingMorphism : Linear R C := by letI := homModuleOfRingMorphism φ exact { smul_comp := fun X Y Z r f g => by simp only [smulOfRingMorphism_smul_eq, assoc] comp_smul := fun X Y Z f r g => by simp only [smulOfRingMorphism_smul_eq', assoc] } end end Linear end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Center/Basic.lean
import Mathlib.CategoryTheory.Endomorphism /-! # The center of a category Given a category `C`, we introduce an abbreviation `CatCenter C` for the center of the category `C`, which is `End (𝟭 C)`, the type of endomorphisms of the identity functor of `C`. ## References * https://ncatlab.org/nlab/show/center+of+a+category -/ universe v u namespace CategoryTheory open Category variable (C : Type u) [Category.{v} C] /-- The center of a category `C` is the type `End (𝟭 C)` of the endomorphisms of the identify functor of `C`. -/ abbrev CatCenter := End (𝟭 C) namespace CatCenter variable {C} @[ext] lemma ext (x y : CatCenter C) (h : ∀ (X : C), x.app X = y.app X) : x = y := NatTrans.ext (funext h) @[reassoc] lemma mul_app' (x y : CatCenter C) (X : C) : (x * y).app X = y.app X ≫ x.app X := rfl @[reassoc] lemma mul_app (x y : CatCenter C) (X : C) : (x * y).app X = x.app X ≫ y.app X := by rw [mul_app'] exact x.naturality (y.app X) instance : IsMulCommutative (CatCenter C) where is_comm := ⟨fun x y ↦ by ext X rw [mul_app' x y, mul_app y x]⟩ end CatCenter end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Center/Localization.lean
import Mathlib.CategoryTheory.Center.Basic import Mathlib.CategoryTheory.Localization.Predicate import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! # Localization of the center of a category Given a localization functor `L : C ⥤ D` with respect to `W : MorphismProperty C`, we define a localization map `CatCenter C → CatCenter D` for the centers of these categories. In case `L` is an additive functor between preadditive categories, we promote this to a ring morphism `CatCenter C →+* CatCenter D`. -/ universe w v₁ v₂ u₁ u₂ namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (r s : CatCenter C) (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] namespace CatCenter /-- Given `r : CatCenter C` and `L : C ⥤ D` a localization functor with respect to `W : MorphismProperty D`, this is the induced element in `CatCenter D` obtained by localization. -/ noncomputable def localization : CatCenter D := Localization.liftNatTrans L W L L (𝟭 D) (𝟭 D) (Functor.whiskerRight r L) @[simp] lemma localization_app (X : C) : (r.localization L W).app (L.obj X) = L.map (r.app X) := by dsimp [localization] simp only [Localization.liftNatTrans_app, Functor.id_obj, Functor.whiskerRight_app, NatTrans.naturality, Functor.comp_map, Functor.id_map, Iso.hom_inv_id_app_assoc] include W lemma ext_of_localization (r s : CatCenter D) (h : ∀ (X : C), r.app (L.obj X) = s.app (L.obj X)) : r = s := Localization.natTrans_ext L W h lemma localization_one : (1 : CatCenter C).localization L W = 1 := ext_of_localization L W _ _ (fun X => by simp) lemma localization_mul : (r * s).localization L W = r.localization L W * s.localization L W := ext_of_localization L W _ _ (fun X => by simp) section Preadditive variable [Preadditive C] [Preadditive D] [L.Additive] lemma localization_zero : (0 : CatCenter C).localization L W = 0 := ext_of_localization L W _ _ (fun X => by simp) lemma localization_add : (r + s).localization L W = r.localization L W + s.localization L W := ext_of_localization L W _ _ (fun X => by rw [localization_app, NatTrans.app_add, NatTrans.app_add, L.map_add, localization_app, localization_app]) /-- The morphism of rings `CatCenter C →+* CatCenter D` when `L : C ⥤ D` is an additive localization functor between preadditive categories. -/ noncomputable def localizationRingHom : CatCenter C →+* CatCenter D where toFun r := r.localization L W map_zero' := localization_zero L W map_one' := localization_one L W map_add' _ _ := localization_add _ _ _ _ map_mul' _ _ := localization_mul _ _ _ _ end Preadditive end CatCenter end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Linear/Yoneda.lean
import Mathlib.Algebra.Category.ModuleCat.Basic import Mathlib.CategoryTheory.Linear.Basic import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic /-! # The Yoneda embedding for `R`-linear categories The Yoneda embedding for `R`-linear categories `C`, sends an object `X : C` to the `ModuleCat R`-valued presheaf on `C`, with value on `Y : Cᵒᵖ` given by `ModuleCat.of R (unop Y ⟶ X)`. TODO: `linearYoneda R C` is `R`-linear. TODO: In fact, `linearYoneda` itself is additive and `R`-linear. -/ universe w v u open Opposite CategoryTheory.Functor namespace CategoryTheory variable (R : Type w) [Ring R] {C : Type u} [Category.{v} C] [Preadditive C] [Linear R C] variable (C) /-- The Yoneda embedding for `R`-linear categories `C`, sending an object `X : C` to the `ModuleCat R`-valued presheaf on `C`, with value on `Y : Cᵒᵖ` given by `ModuleCat.of R (unop Y ⟶ X)`. -/ @[simps] def linearYoneda : C ⥤ Cᵒᵖ ⥤ ModuleCat R where obj X := { obj := fun Y => ModuleCat.of R (unop Y ⟶ X) map := fun f => ModuleCat.ofHom (Linear.leftComp R _ f.unop) } map {X₁ X₂} f := { app := fun Y => @ModuleCat.ofHom R _ (Y.unop ⟶ X₁) (Y.unop ⟶ X₂) _ _ _ _ (Linear.rightComp R _ f) } /-- The Yoneda embedding for `R`-linear categories `C`, sending an object `Y : Cᵒᵖ` to the `ModuleCat R`-valued copresheaf on `C`, with value on `X : C` given by `ModuleCat.of R (unop Y ⟶ X)`. -/ @[simps] def linearCoyoneda : Cᵒᵖ ⥤ C ⥤ ModuleCat R where obj Y := { obj := fun X => ModuleCat.of R (unop Y ⟶ X) map := fun f => ModuleCat.ofHom (Linear.rightComp R _ f) } map {Y₁ Y₂} f := { app := fun X => @ModuleCat.ofHom R _ (unop Y₁ ⟶ X) (unop Y₂ ⟶ X) _ _ _ _ (Linear.leftComp _ _ f.unop) } instance linearYoneda_obj_additive (X : C) : ((linearYoneda R C).obj X).Additive where instance linearCoyoneda_obj_additive (Y : Cᵒᵖ) : ((linearCoyoneda R C).obj Y).Additive where @[simp] theorem whiskering_linearYoneda : linearYoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R)) = yoneda := rfl @[simp] theorem whiskering_linearYoneda₂ : linearYoneda R C ⋙ (whiskeringRight _ _ _).obj (forget₂ (ModuleCat.{v} R) AddCommGrpCat.{v}) = preadditiveYoneda := rfl @[simp] theorem whiskering_linearCoyoneda : linearCoyoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R)) = coyoneda := rfl @[simp] theorem whiskering_linearCoyoneda₂ : linearCoyoneda R C ⋙ (whiskeringRight _ _ _).obj (forget₂ (ModuleCat.{v} R) AddCommGrpCat.{v}) = preadditiveCoyoneda := rfl instance full_linearYoneda : (linearYoneda R C).Full := let _ : Functor.Full (linearYoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) := Yoneda.yoneda_full Functor.Full.of_comp_faithful (linearYoneda R C) ((whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) instance full_linearCoyoneda : (linearCoyoneda R C).Full := let _ : Functor.Full (linearCoyoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) := Coyoneda.coyoneda_full Functor.Full.of_comp_faithful (linearCoyoneda R C) ((whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) instance faithful_linearYoneda : (linearYoneda R C).Faithful := Functor.Faithful.of_comp_eq (whiskering_linearYoneda R C) instance faithful_linearCoyoneda : (linearCoyoneda R C).Faithful := Functor.Faithful.of_comp_eq (whiskering_linearCoyoneda R C) end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Linear/LinearFunctor.lean
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Linear.Basic import Mathlib.Algebra.Module.LinearMap.Rat /-! # Linear Functors An additive functor between two `R`-linear categories is called *linear* if the induced map on hom types is a morphism of `R`-modules. ## Implementation details `Functor.Linear` is a `Prop`-valued class, defined by saying that for every two objects `X` and `Y`, the map `F.map : (X ⟶ Y) → (F.obj X ⟶ F.obj Y)` is a morphism of `R`-modules. -/ namespace CategoryTheory variable (R : Type*) [Semiring R] {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D] [CategoryTheory.Linear R C] [CategoryTheory.Linear R D] (F : C ⥤ D) /-- An additive functor `F` is `R`-linear provided `F.map` is an `R`-module morphism. -/ class Functor.Linear : Prop where /-- the functor induces a linear map on morphisms -/ map_smul : ∀ {X Y : C} (f : X ⟶ Y) (r : R), F.map (r • f) = r • F.map f := by cat_disch lemma Functor.linear_iff (F : C ⥤ D) : Functor.Linear R F ↔ ∀ (X : C) (r : R), F.map (r • 𝟙 X) = r • 𝟙 (F.obj X) := by constructor · intro h X r rw [h.map_smul, F.map_id] · refine fun h => ⟨fun {X Y} f r => ?_⟩ have : r • f = (r • 𝟙 X) ≫ f := by simp rw [this, F.map_comp, h, Linear.smul_comp, Category.id_comp] section Linear namespace Functor section variable {R} [Linear R F] @[simp] theorem map_smul {X Y : C} (r : R) (f : X ⟶ Y) : F.map (r • f) = r • F.map f := Functor.Linear.map_smul _ _ @[simp] theorem map_units_smul {X Y : C} (r : Rˣ) (f : X ⟶ Y) : F.map (r • f) = r • F.map f := by apply map_smul instance : Linear R (𝟭 C) where instance {E : Type*} [Category E] [Preadditive E] [CategoryTheory.Linear R E] (G : D ⥤ E) [Linear R G] : Linear R (F ⋙ G) where variable (R) [F.Additive] /-- `F.mapLinearMap` is an `R`-linear map whose underlying function is `F.map`. -/ @[simps] def mapLinearMap {X Y : C} : (X ⟶ Y) →ₗ[R] F.obj X ⟶ F.obj Y := { F.mapAddHom with map_smul' := fun r f => F.map_smul r f } theorem coe_mapLinearMap {X Y : C} : ⇑(F.mapLinearMap R : (X ⟶ Y) →ₗ[R] _) = F.map := rfl end variable {F} in lemma linear_of_iso {G : C ⥤ D} (e : F ≅ G) [F.Linear R] : G.Linear R := by exact { map_smul := fun f r => by simp only [← NatIso.naturality_1 e (r • f), F.map_smul, Linear.smul_comp, NatTrans.naturality, Linear.comp_smul, Iso.inv_hom_id_app_assoc] } section InducedCategory instance inducedFunctorLinear (F : C → D) : Functor.Linear R (inducedFunctor F) where end InducedCategory instance fullSubcategoryInclusionLinear {C : Type*} [Category C] [Preadditive C] [CategoryTheory.Linear R C] (Z : ObjectProperty C) : Z.ι.Linear R where section variable {R} [Additive F] instance natLinear : F.Linear ℕ where map_smul := F.mapAddHom.map_nsmul instance intLinear : F.Linear ℤ where map_smul f r := F.mapAddHom.map_zsmul f r variable [CategoryTheory.Linear ℚ C] [CategoryTheory.Linear ℚ D] instance ratLinear : F.Linear ℚ where map_smul f r := F.mapAddHom.toRatLinearMap.map_smul r f end end Functor namespace Equivalence instance inverseLinear (e : C ≌ D) [e.functor.Linear R] : e.inverse.Linear R where map_smul r f := by apply e.functor.map_injective simp end Equivalence end Linear end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Linear/Basic.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Group.Invertible.Defs import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.CategoryTheory.Preadditive.Basic /-! # Linear categories An `R`-linear category is a category in which `X ⟶ Y` is an `R`-module in such a way that composition of morphisms is `R`-linear in both variables. Note that sometimes in the literature a "linear category" is further required to be abelian. ## Implementation Corresponding to the fact that we need to have an `AddCommGroup X` structure in place to talk about a `Module R X` structure, we need `Preadditive C` as a prerequisite typeclass for `Linear R C`. This makes for longer signatures than would be ideal. ## Future work It would be nice to have a usable framework of enriched categories in which this just became a category enriched in `Module R`. -/ universe w v u open CategoryTheory.Limits open LinearMap namespace CategoryTheory /-- A category is called `R`-linear if `P ⟶ Q` is an `R`-module such that composition is `R`-linear in both variables. -/ class Linear (R : Type w) [Semiring R] (C : Type u) [Category.{v} C] [Preadditive C] where homModule : ∀ X Y : C, Module R (X ⟶ Y) := by infer_instance /-- compatibility of the scalar multiplication with the post-composition -/ smul_comp : ∀ (X Y Z : C) (r : R) (f : X ⟶ Y) (g : Y ⟶ Z), (r • f) ≫ g = r • f ≫ g := by cat_disch /-- compatibility of the scalar multiplication with the pre-composition -/ comp_smul : ∀ (X Y Z : C) (f : X ⟶ Y) (r : R) (g : Y ⟶ Z), f ≫ (r • g) = r • f ≫ g := by cat_disch attribute [instance] Linear.homModule attribute [simp] Linear.smul_comp Linear.comp_smul -- (the linter doesn't like `simp` on the `_assoc` lemma) end CategoryTheory open CategoryTheory namespace CategoryTheory.Linear variable {C : Type u} [Category.{v} C] [Preadditive C] instance preadditiveNatLinear : Linear ℕ C where smul_comp X _Y _Z r f g := by exact (Preadditive.rightComp X g).map_nsmul f r comp_smul _X _Y Z f r g := by exact (Preadditive.leftComp Z f).map_nsmul g r instance preadditiveIntLinear : Linear ℤ C where smul_comp X _Y _Z r f g := by exact (Preadditive.rightComp X g).map_zsmul f r comp_smul _X _Y Z f r g := by exact (Preadditive.leftComp Z f).map_zsmul g r section End variable {R : Type w} instance [Semiring R] [Linear R C] (X : C) : Module R (End X) := by dsimp [End] infer_instance instance [CommSemiring R] [Linear R C] (X : C) : Algebra R (End X) := Algebra.ofModule (fun _ _ _ => comp_smul _ _ _ _ _ _) fun _ _ _ => smul_comp _ _ _ _ _ _ end End section variable {R : Type w} [Semiring R] [Linear R C] section InducedCategory universe u' variable {D : Type u'} (F : D → C) instance inducedCategory : Linear.{w, v} R (InducedCategory C F) where homModule X Y := @Linear.homModule R _ C _ _ _ (F X) (F Y) smul_comp _ _ _ _ _ _ := smul_comp _ _ _ _ _ _ comp_smul _ _ _ _ _ _ := comp_smul _ _ _ _ _ _ end InducedCategory instance fullSubcategory (Z : ObjectProperty C) : Linear.{w, v} R Z.FullSubcategory where homModule X Y := @Linear.homModule R _ C _ _ _ X.obj Y.obj smul_comp _ _ _ _ _ _ := smul_comp _ _ _ _ _ _ comp_smul _ _ _ _ _ _ := comp_smul _ _ _ _ _ _ variable (R) /-- Composition by a fixed left argument as an `R`-linear map. -/ @[simps] def leftComp {X Y : C} (Z : C) (f : X ⟶ Y) : (Y ⟶ Z) →ₗ[R] X ⟶ Z where toFun g := f ≫ g map_add' := by simp map_smul' := by simp /-- Composition by a fixed right argument as an `R`-linear map. -/ @[simps] def rightComp (X : C) {Y Z : C} (g : Y ⟶ Z) : (X ⟶ Y) →ₗ[R] X ⟶ Z where toFun f := f ≫ g map_add' := by simp map_smul' := by simp instance {X Y : C} (f : X ⟶ Y) [Epi f] (r : R) [Invertible r] : Epi (r • f) := ⟨fun g g' H => by rw [smul_comp, smul_comp, ← comp_smul, ← comp_smul, cancel_epi] at H simpa [smul_smul] using congr_arg (fun f => ⅟r • f) H⟩ instance {X Y : C} (f : X ⟶ Y) [Mono f] (r : R) [Invertible r] : Mono (r • f) := ⟨fun g g' H => by rw [comp_smul, comp_smul, ← smul_comp, ← smul_comp, cancel_mono] at H simpa [smul_smul] using congr_arg (fun f => ⅟r • f) H⟩ /-- Given isomorphic objects `X ≅ Y, W ≅ Z` in a `k`-linear category, we have a `k`-linear isomorphism between `Hom(X, W)` and `Hom(Y, Z).` -/ def homCongr (k : Type*) {C : Type*} [Category C] [Semiring k] [Preadditive C] [Linear k C] {X Y W Z : C} (f₁ : X ≅ Y) (f₂ : W ≅ Z) : (X ⟶ W) ≃ₗ[k] Y ⟶ Z := { (rightComp k Y f₂.hom).comp (leftComp k W f₁.symm.hom) with invFun := (leftComp k W f₁.hom).comp (rightComp k Y f₂.symm.hom) left_inv := fun x => by simp only [Iso.symm_hom, LinearMap.toFun_eq_coe, LinearMap.coe_comp, Function.comp_apply, leftComp_apply, rightComp_apply, Category.assoc, Iso.hom_inv_id, Category.comp_id, Iso.hom_inv_id_assoc] right_inv := fun x => by simp only [Iso.symm_hom, LinearMap.coe_comp, Function.comp_apply, rightComp_apply, leftComp_apply, LinearMap.toFun_eq_coe, Iso.inv_hom_id_assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id] } theorem homCongr_apply (k : Type*) {C : Type*} [Category C] [Semiring k] [Preadditive C] [Linear k C] {X Y W Z : C} (f₁ : X ≅ Y) (f₂ : W ≅ Z) (f : X ⟶ W) : homCongr k f₁ f₂ f = (f₁.inv ≫ f) ≫ f₂.hom := rfl theorem homCongr_symm_apply (k : Type*) {C : Type*} [Category C] [Semiring k] [Preadditive C] [Linear k C] {X Y W Z : C} (f₁ : X ≅ Y) (f₂ : W ≅ Z) (f : Y ⟶ Z) : (homCongr k f₁ f₂).symm f = f₁.hom ≫ f ≫ f₂.inv := rfl variable {R} @[simp] lemma units_smul_comp {X Y Z : C} (r : Rˣ) (f : X ⟶ Y) (g : Y ⟶ Z) : (r • f) ≫ g = r • f ≫ g := by apply Linear.smul_comp @[simp] lemma comp_units_smul {X Y Z : C} (f : X ⟶ Y) (r : Rˣ) (g : Y ⟶ Z) : f ≫ (r • g) = r • f ≫ g := by apply Linear.comp_smul end section variable {S : Type w} [CommSemiring S] [Linear S C] /-- Composition as a bilinear map. -/ @[simps] def comp (X Y Z : C) : (X ⟶ Y) →ₗ[S] (Y ⟶ Z) →ₗ[S] X ⟶ Z where toFun f := leftComp S Z f map_add' := by intros ext simp map_smul' := by intros ext simp end end CategoryTheory.Linear
.lake/packages/mathlib/Mathlib/CategoryTheory/Linear/FunctorCategory.lean
import Mathlib.CategoryTheory.Preadditive.FunctorCategory import Mathlib.CategoryTheory.Linear.Basic /-! # Linear structure on functor categories If `C` and `D` are categories and `D` is `R`-linear, then `C ⥤ D` is also `R`-linear. -/ namespace CategoryTheory open CategoryTheory.Limits Linear variable {R : Type*} [Semiring R] variable {C D : Type*} [Category C] [Category D] [Preadditive D] [Linear R D] instance functorCategoryLinear : Linear R (C ⥤ D) where homModule F G := { smul := fun r α => { app := fun X => r • α.app X naturality := by intros rw [comp_smul, smul_comp, α.naturality] } one_smul := by intros ext apply one_smul zero_smul := by intros ext apply zero_smul smul_zero := by intros ext apply smul_zero add_smul := by intros ext apply add_smul smul_add := by intros ext apply smul_add mul_smul := by intros ext apply mul_smul } smul_comp := by intros ext apply smul_comp comp_smul := by intros ext apply comp_smul namespace NatTrans variable {F G : C ⥤ D} /-- Application of a natural transformation at a fixed object, as group homomorphism -/ @[simps] def appLinearMap (X : C) : (F ⟶ G) →ₗ[R] F.obj X ⟶ G.obj X where toFun α := α.app X map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem app_smul (X : C) (r : R) (α : F ⟶ G) : (r • α).app X = r • α.app X := rfl end NatTrans end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Discrete/Basic.lean
import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Pi.Basic import Mathlib.Data.ULift /-! # Discrete categories We define `Discrete α` as a structure containing a term `a : α` for any type `α`, and use this type alias to provide a `SmallCategory` instance whose only morphisms are the identities. There is an annoying technical difficulty that it has turned out to be inconvenient to allow categories with morphisms living in `Prop`, so instead of defining `X ⟶ Y` in `Discrete α` as `X = Y`, one might define it as `PLift (X = Y)`. In fact, to allow `Discrete α` to be a `SmallCategory` (i.e. with morphisms in the same universe as the objects), we actually define the hom type `X ⟶ Y` as `ULift (PLift (X = Y))`. `Discrete.functor` promotes a function `f : I → C` (for any category `C`) to a functor `Discrete.functor f : Discrete I ⥤ C`. Similarly, `Discrete.natTrans` and `Discrete.natIso` promote `I`-indexed families of morphisms, or `I`-indexed families of isomorphisms to natural transformations or natural isomorphism. We show equivalences of types are the same as (categorical) equivalences of the corresponding discrete categories. -/ namespace CategoryTheory -- morphism levels before object levels. See note [category theory universes]. universe v₁ v₂ v₃ u₁ u₁' u₂ u₃ -- This is intentionally a structure rather than a type synonym -- to enforce using `DiscreteEquiv` (or `Discrete.mk` and `Discrete.as`) to move between -- `Discrete α` and `α`. Otherwise there is too much API leakage. /-- A wrapper for promoting any type to a category, with the only morphisms being equalities. -/ @[ext, aesop safe cases (rule_sets := [CategoryTheory])] structure Discrete (α : Type u₁) where /-- A wrapper for promoting any type to a category, with the only morphisms being equalities. -/ as : α @[simp] theorem Discrete.mk_as {α : Type u₁} (X : Discrete α) : Discrete.mk X.as = X := rfl /-- `Discrete α` is equivalent to the original type `α`. -/ @[simps] def discreteEquiv {α : Type u₁} : Discrete α ≃ α where toFun := Discrete.as invFun := Discrete.mk left_inv := by cat_disch right_inv := by cat_disch instance {α : Type u₁} [DecidableEq α] : DecidableEq (Discrete α) := discreteEquiv.decidableEq /-- The "Discrete" category on a type, whose morphisms are equalities. Because we do not allow morphisms in `Prop` (only in `Type`), somewhat annoyingly we have to define `X ⟶ Y` as `ULift (PLift (X = Y))`. -/ @[stacks 001A] instance discreteCategory (α : Type u₁) : SmallCategory (Discrete α) where Hom X Y := ULift (PLift (X.as = Y.as)) id _ := ULift.up (PLift.up rfl) comp {X Y Z} g f := by cases X cases Y cases Z rcases f with ⟨⟨⟨⟩⟩⟩ exact g namespace Discrete variable {α : Type u₁} instance [Inhabited α] : Inhabited (Discrete α) := ⟨⟨default⟩⟩ instance [Subsingleton α] : Subsingleton (Discrete α) := ⟨by cat_disch⟩ instance instSubsingletonDiscreteHom (X Y : Discrete α) : Subsingleton (X ⟶ Y) := show Subsingleton (ULift (PLift _)) from inferInstance /-- A simple tactic to run `cases` on any `Discrete α` hypotheses. -/ macro "discrete_cases" : tactic => `(tactic| fail_if_no_progress casesm* Discrete _, (_ : Discrete _) ⟶ (_ : Discrete _), PLift _) open Lean Elab Tactic in /-- Use: ``` attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases ``` to locally give `cat_disch` the ability to call `cases` on `Discrete` and `(_ : Discrete _) ⟶ (_ : Discrete _)` hypotheses. -/ def discreteCases : TacticM Unit := do evalTactic (← `(tactic| discrete_cases)) -- TODO: investigate turning on either -- `attribute [aesop safe cases (rule_sets := [CategoryTheory])] Discrete` -- or -- `attribute [aesop safe tactic (rule_sets := [CategoryTheory])] discreteCases` -- globally. instance [Unique α] : Unique (Discrete α) := Unique.mk' (Discrete α) /-- Extract the equation from a morphism in a discrete category. -/ theorem eq_of_hom {X Y : Discrete α} (i : X ⟶ Y) : X.as = Y.as := i.down.down /-- Promote an equation between the wrapped terms in `X Y : Discrete α` to a morphism `X ⟶ Y` in the discrete category. -/ protected abbrev eqToHom {X Y : Discrete α} (h : X.as = Y.as) : X ⟶ Y := eqToHom (by cat_disch) /-- Promote an equation between the wrapped terms in `X Y : Discrete α` to an isomorphism `X ≅ Y` in the discrete category. -/ protected abbrev eqToIso {X Y : Discrete α} (h : X.as = Y.as) : X ≅ Y := eqToIso (by cat_disch) /-- A variant of `eqToHom` that lifts terms to the discrete category. -/ abbrev eqToHom' {a b : α} (h : a = b) : Discrete.mk a ⟶ Discrete.mk b := Discrete.eqToHom h /-- A variant of `eqToIso` that lifts terms to the discrete category. -/ abbrev eqToIso' {a b : α} (h : a = b) : Discrete.mk a ≅ Discrete.mk b := Discrete.eqToIso h @[simp] theorem id_def (X : Discrete α) : ULift.up (PLift.up (Eq.refl X.as)) = 𝟙 X := rfl @[simp] theorem id_def' (X : α) : ULift.up (PLift.up (Eq.refl X)) = 𝟙 (⟨X⟩ : Discrete α) := rfl variable {C : Type u₂} [Category.{v₂} C] instance {I : Type u₁} {i j : Discrete I} (f : i ⟶ j) : IsIso f := ⟨⟨Discrete.eqToHom (eq_of_hom f).symm, by cat_disch⟩⟩ attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- Any function `I → C` gives a functor `Discrete I ⥤ C`. -/ def functor {I : Type u₁} (F : I → C) : Discrete I ⥤ C where obj := F ∘ Discrete.as map {X Y} f := by dsimp rcases f with ⟨⟨h⟩⟩ exact eqToHom (congrArg _ h) @[simp] theorem functor_obj {I : Type u₁} (F : I → C) (i : I) : (Discrete.functor F).obj (Discrete.mk i) = F i := rfl theorem functor_map {I : Type u₁} (F : I → C) {i : Discrete I} (f : i ⟶ i) : (Discrete.functor F).map f = 𝟙 (F i.as) := by cat_disch @[simp] theorem functor_obj_eq_as {I : Type u₁} (F : I → C) (X : Discrete I) : (Discrete.functor F).obj X = F X.as := rfl @[ext] lemma functor_ext {I : Type u₁} {G F : Discrete I ⥤ C} (h : (i : I) → G.obj ⟨i⟩ = F.obj ⟨i⟩) : G = F := by fapply Functor.ext · intro I; rw [h] · intro ⟨X⟩ ⟨Y⟩ ⟨⟨p⟩⟩; simp only at p; induction p; simp /-- The discrete functor induced by a composition of maps can be written as a composition of two discrete functors. -/ @[simps!] def functorComp {I : Type u₁} {J : Type u₁'} (f : J → C) (g : I → J) : Discrete.functor (f ∘ g) ≅ Discrete.functor (Discrete.mk ∘ g) ⋙ Discrete.functor f := NatIso.ofComponents fun _ => Iso.refl _ /-- For functors out of a discrete category, a natural transformation is just a collection of maps, as the naturality squares are trivial. -/ @[simps] def natTrans {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ⟶ G.obj i) : F ⟶ G where app := f naturality := fun {X Y} ⟨⟨g⟩⟩ => by discrete_cases rcases g change F.map (𝟙 _) ≫ _ = _ ≫ G.map (𝟙 _) simp /-- For functors out of a discrete category, a natural isomorphism is just a collection of isomorphisms, as the naturality squares are trivial. -/ @[simps!] def natIso {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ≅ G.obj i) : F ≅ G := NatIso.ofComponents f fun ⟨⟨g⟩⟩ => by discrete_cases rcases g change F.map (𝟙 _) ≫ _ = _ ≫ G.map (𝟙 _) simp instance {I : Type*} {F G : Discrete I ⥤ C} (f : ∀ i, F.obj i ⟶ G.obj i) [∀ i, IsIso (f i)] : IsIso (Discrete.natTrans f) := by change IsIso (Discrete.natIso (fun i => asIso (f i))).hom infer_instance @[simp] theorem natIso_app {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ≅ G.obj i) (i : Discrete I) : (Discrete.natIso f).app i = f i := by cat_disch /-- Every functor `F` from a discrete category is naturally isomorphic (actually, equal) to `Discrete.functor (F.obj)`. -/ @[simps!] def natIsoFunctor {I : Type u₁} {F : Discrete I ⥤ C} : F ≅ Discrete.functor (F.obj ∘ Discrete.mk) := natIso fun _ => Iso.refl _ /-- Composing `Discrete.functor F` with another functor `G` amounts to composing `F` with `G.obj` -/ @[simps!] def compNatIsoDiscrete {I : Type u₁} {D : Type u₃} [Category.{v₃} D] (F : I → C) (G : C ⥤ D) : Discrete.functor F ⋙ G ≅ Discrete.functor (G.obj ∘ F) := natIso fun _ => Iso.refl _ /-- We can promote a type-level `Equiv` to an equivalence between the corresponding `discrete` categories. -/ @[simps] def equivalence {I : Type u₁} {J : Type u₂} (e : I ≃ J) : Discrete I ≌ Discrete J where functor := Discrete.functor (Discrete.mk ∘ (e : I → J)) inverse := Discrete.functor (Discrete.mk ∘ (e.symm : J → I)) unitIso := Discrete.natIso fun i => eqToIso (by simp) counitIso := Discrete.natIso fun j => eqToIso (by simp) /-- We can convert an equivalence of `discrete` categories to a type-level `Equiv`. -/ @[simps] def equivOfEquivalence {α : Type u₁} {β : Type u₂} (h : Discrete α ≌ Discrete β) : α ≃ β where toFun := Discrete.as ∘ h.functor.obj ∘ Discrete.mk invFun := Discrete.as ∘ h.inverse.obj ∘ Discrete.mk left_inv a := by simpa using eq_of_hom (h.unitIso.app (Discrete.mk a)).2 right_inv a := by simpa using eq_of_hom (h.counitIso.app (Discrete.mk a)).1 end Discrete namespace Discrete variable {J : Type v₁} open Opposite /-- A discrete category is equivalent to its opposite category. -/ @[simps! functor_obj_as inverse_obj] protected def opposite (α : Type u₁) : (Discrete α)ᵒᵖ ≌ Discrete α := let F : Discrete α ⥤ (Discrete α)ᵒᵖ := Discrete.functor fun x => op (Discrete.mk x) { functor := F.leftOp inverse := F unitIso := NatIso.ofComponents fun ⟨_⟩ => Iso.refl _ counitIso := Discrete.natIso fun ⟨_⟩ => Iso.refl _ } variable {C : Type u₂} [Category.{v₂} C] @[simp] theorem functor_map_id (F : Discrete J ⥤ C) {j : Discrete J} (f : j ⟶ j) : F.map f = 𝟙 (F.obj j) := by have h : f = 𝟙 j := by cat_disch rw [h] simp end Discrete @[simp] lemma Discrete.forall {α : Type*} {p : Discrete α → Prop} : (∀ (a : Discrete α), p a) ↔ ∀ (a' : α), p ⟨a'⟩ := by rw [iff_iff_eq, discreteEquiv.forall_congr_left] simp [discreteEquiv] @[simp] lemma Discrete.exists {α : Type*} {p : Discrete α → Prop} : (∃ (a : Discrete α), p a) ↔ ∃ (a' : α), p ⟨a'⟩ := by rw [iff_iff_eq, discreteEquiv.exists_congr_left] simp [discreteEquiv] /-- The equivalence of categories `(J → C) ≌ (Discrete J ⥤ C)`. -/ @[simps] def piEquivalenceFunctorDiscrete (J : Type u₂) (C : Type u₁) [Category.{v₁} C] : (J → C) ≌ (Discrete J ⥤ C) where functor := { obj := fun F => Discrete.functor F map := fun f => Discrete.natTrans (fun j => f j.as) } inverse := { obj := fun F j => F.obj ⟨j⟩ map := fun f j => f.app ⟨j⟩ } unitIso := Iso.refl _ counitIso := NatIso.ofComponents (fun F => (NatIso.ofComponents (fun _ => Iso.refl _) (by rintro ⟨x⟩ ⟨y⟩ f obtain rfl : x = y := Discrete.eq_of_hom f obtain rfl : f = 𝟙 _ := rfl simp))) (by cat_disch) /-- A category is discrete when there is at most one morphism between two objects, in which case they are equal. -/ class IsDiscrete (C : Type*) [Category C] : Prop where subsingleton (X Y : C) : Subsingleton (X ⟶ Y) := by infer_instance eq_of_hom {X Y : C} (f : X ⟶ Y) : X = Y attribute [instance] IsDiscrete.subsingleton instance Discrete.isDiscrete (C : Type*) : IsDiscrete (Discrete C) where eq_of_hom := by rintro ⟨_⟩ ⟨_⟩ ⟨⟨rfl⟩⟩; rfl section variable {C : Type*} [Category C] [IsDiscrete C] lemma obj_ext_of_isDiscrete {X Y : C} (f : X ⟶ Y) : X = Y := IsDiscrete.eq_of_hom f instance isIso_of_isDiscrete {X Y : C} (f : X ⟶ Y) : IsIso f := ⟨eqToHom (IsDiscrete.eq_of_hom f).symm, by cat_disch⟩ instance : IsDiscrete Cᵒᵖ where eq_of_hom := by rintro ⟨_⟩ ⟨_⟩ ⟨f⟩ obtain rfl := obj_ext_of_isDiscrete f rfl end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Discrete/SumsProducts.lean
import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.Sums.Basic import Mathlib.CategoryTheory.Products.Basic /-! # Sums and products of discrete categories. This file shows that binary products and binary sums of discrete categories are also discrete, both in the form of explicit equivalences and through the `IsDiscrete` typeclass. ## Main declarations * `Discrete.productEquiv`: The equivalence of categories between `Discrete (J × K)` and `Discrete J × Discrete K` * `Discrete.sumEquiv`: The equivalence of categories between `Discrete (J ⊕ K)` and `Discrete J ⊕ Discrete K`. * `IsDiscrete.prod`: an `IsDiscrete` instance on the product of two discrete categories. * `IsDiscrete.sum`: an `IsDiscrete` instance on the sum of two discrete categories. -/ namespace CategoryTheory namespace Discrete /-- The discrete category on a product is equivalent to the product of the discrete categories. -/ @[simps!] def productEquiv {J K : Type*} : Discrete (J × K) ≌ Discrete J × Discrete K where functor := Discrete.functor <| fun ⟨j, k⟩ ↦ ⟨.mk j, .mk k⟩ inverse := { obj := fun ⟨x, y⟩ ↦ .mk (⟨x.as, y.as⟩) map := fun ⟨f₁, f₂⟩ ↦ eqToHom (by discrete_cases; dsimp; rw [f₁, f₂]) } unitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _) counitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _) /-- The discrete category on a sum is equivalent to the sum of the discrete categories. -/ @[simps!] def sumEquiv {J K : Type*} : Discrete (J ⊕ K) ≌ Discrete J ⊕ Discrete K where functor := Discrete.functor <| fun t ↦ match t with | .inl j => Sum.inl (Discrete.mk j) | .inr k => Sum.inr (Discrete.mk k) inverse := (Discrete.functor <| fun t ↦ Discrete.mk (Sum.inl t)).sum' (Discrete.functor <| fun t ↦ Discrete.mk (Sum.inr t)) unitIso := NatIso.ofComponents (fun ⟨x⟩ ↦ match x with | .inl x => Iso.refl _ | .inr x => Iso.refl _) counitIso := Functor.sumIsoExt (Discrete.natIso <| fun _ ↦ Iso.refl _) (Discrete.natIso <| fun _ ↦ Iso.refl _) end Discrete namespace IsDiscrete variable (C C' : Type*) [Category C] [Category C'] (D : Type*) [Category D] [IsDiscrete C] [IsDiscrete C'] [IsDiscrete D] /-- A product of discrete categories is discrete. -/ instance prod : IsDiscrete (C × D) where subsingleton x y := inferInstanceAs (Subsingleton ((x.1 ⟶ y.1) × (x.2 ⟶ y.2))) eq_of_hom f := Prod.ext (IsDiscrete.eq_of_hom f.1) (IsDiscrete.eq_of_hom f.2) /-- A product of discrete categories is discrete. -/ instance sum : IsDiscrete (C ⊕ C') where subsingleton x y := { allEq f g := by cases f <;> cases g · case inl x y f g => rw [((by assumption : IsDiscrete C).subsingleton x y).allEq f g] · case inr x y f g => rw [((by assumption : IsDiscrete C').subsingleton x y).allEq f g] } eq_of_hom {x y} f := by cases f with | inl x y f => rw [(by assumption : IsDiscrete C).eq_of_hom f] | inr x y f => rw [(by assumption : IsDiscrete C').eq_of_hom f] end CategoryTheory.IsDiscrete
.lake/packages/mathlib/Mathlib/CategoryTheory/Discrete/StructuredArrow.lean
import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic /-! # Structured arrows when the target category is discrete When `T` is a type with a unique element `t`, we show that if `F : C ⥤ Discrete T`, then the categories `StructuredArrow (Discrete.mk t) F` and `CostructuredArrow (Discrete.mk t) F` are equivalent to `C`. -/ universe w v v' u u' namespace CategoryTheory variable {C : Type u} [Category.{v} C] {T : Type w} namespace Discrete /-- If `F : C ⥤ Discrete T` is a functor with `T` containing a unique element `t`, then this is the equivalence `StructuredArrow (Discrete.mk t) F ≌ C`. -/ def structuredArrowEquivalenceOfUnique (F : C ⥤ Discrete T) (t : T) [Subsingleton T] : StructuredArrow (.mk t) F ≌ C where functor := StructuredArrow.proj _ _ inverse.obj X := StructuredArrow.mk (Y := X) (eqToHom (by subsingleton)) inverse.map f := StructuredArrow.homMk f unitIso := NatIso.ofComponents (fun _ ↦ StructuredArrow.isoMk (Iso.refl _)) counitIso := Iso.refl _ /-- If `F : C ⥤ Discrete T` is a functor with `T` containing a unique element `t`, then this is the equivalence `CostructuredArrow F (Discrete.mk t) ≌ C`. -/ def costructuredArrowEquivalenceOfUnique (F : C ⥤ Discrete T) (t : T) [Subsingleton T] : CostructuredArrow F (.mk t) ≌ C where functor := CostructuredArrow.proj _ _ inverse.obj X := CostructuredArrow.mk (Y := X) (eqToHom (by subsingleton)) inverse.map f := CostructuredArrow.homMk f unitIso := NatIso.ofComponents (fun _ ↦ CostructuredArrow.isoMk (Iso.refl _)) counitIso := Iso.refl _ end Discrete end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/Biproducts.lean
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] 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 [zero_def, 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 [zero_def, 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, add_def, 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_eq_left, ← 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, zero_def] · rw [biprod.inr_desc_assoc, comp_id, biprod.lift_eq, comp_add, ← decompId_assoc, add_eq_right, ← 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, zero_def] inv_hom_id := by ext simp only [toKaroubi_obj_X, biprod.lift_desc, add_def, 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
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/HomologicalComplex.lean
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]; cat_disch /-- 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 cat_disch) (by simp)) (by cat_disch)) /-- 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 [HomologicalComplex.comp_p_d, 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 [HomologicalComplex.comp_p_d, HomologicalComplex.p_comp_d] } hom_inv_id := by ext dsimp simp only [HomologicalComplex.p_idem] inv_hom_id := by ext dsimp simp only [HomologicalComplex.p_idem] 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
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/SimplicialObject.lean
import Mathlib.AlgebraicTopology.SimplicialObject.Basic 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
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/FunctorExtension.lean
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 Functor 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_lhs 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 simp)) (by cat_disch) /-- The counit isomorphism of the equivalence `(C ⥤ Karoubi D) ≌ (Karoubi C ⥤ Karoubi D)`. -/ 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 (toKaroubi C).map P.p ≫ P.decompId_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 ≫ (toKaroubi C).map P.p = P.decompId_i 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) attribute [simps!] KaroubiUniversal₁.counitIso /-- 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 simp)) (by cat_disch) 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 variable {C D} in /-- The precomposition of functors with `toKaroubi C` is fully faithful. -/ def whiskeringLeftObjToKaroubiFullyFaithful : ((Functor.whiskeringLeft C (Karoubi C) D).obj (toKaroubi C)).FullyFaithful where preimage {F G} τ := { app P := F.map P.decompId_i ≫ τ.app P.X ≫ G.map P.decompId_p naturality X Y f := by dsimp at τ ⊢ have h₁ : f ≫ Y.decompId_i = X.decompId_i ≫ (toKaroubi C).map f.f := by simp have h₂ := τ.naturality f.f have h₃ : X.decompId_p ≫ f = (toKaroubi C).map f.f ≫ Y.decompId_p := by simp dsimp at h₂ rw [Category.assoc, Category.assoc, ← F.map_comp_assoc, h₁, F.map_comp_assoc, reassoc_of% h₂, ← G.map_comp, ← h₃, G.map_comp] } preimage_map {F G} τ := by ext X; exact (natTrans_eq _ _).symm map_preimage {F G} τ := by ext X dsimp rw [Karoubi.decompId_i_toKaroubi, Karoubi.decompId_p_toKaroubi, Functor.map_id, Category.id_comp] change _ ≫ G.map (𝟙 _) = _ simp end Idempotents end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/Karoubi.lean
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 /-- 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 cat_disch 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 : P.p ≫ f ≫ Q.p = f := by cat_disch 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) : P.p ≫ (f.f ≫ g.f) ≫ R.p = f.f ≫ g.f := by simp /-- 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 @[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 /-- 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]⟩⟩ theorem coe_X (X : C) : (X : Karoubi C).X = X := by simp @[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]⟩ 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 neg_add_cancel f := by ext apply neg_add_cancel 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 rw [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 rw [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) = 𝟙 _ := rfl theorem decompId_p_toKaroubi (X : C) : decompId_p ((toKaroubi C).obj X) = 𝟙 _ := 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 simp 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 simp @[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 /-- If `X : Karoubi C`, then `X` is a retract of `((toKaroubi C).obj X.X)`. -/ @[simps] def retract (X : Karoubi C) : Retract X ((toKaroubi C).obj X.X) where i := ⟨X.p, by simp⟩ r := ⟨X.p, by simp⟩ end Karoubi instance : (toKaroubi C).PreservesEpimorphisms where preserves f _ := ⟨fun g h eq ↦ by ext rw [← cancel_epi f] simpa using eq⟩ instance : (toKaroubi C).PreservesMonomorphisms where preserves f _ := ⟨fun g h eq ↦ by ext rw [← cancel_mono f] simpa using eq⟩ end Idempotents end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/Basic.lean
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 _ 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 [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_π, Fork.ofι_pt, Fork.ofι_π_app, id_comp] rw [← equalizer.condition, comp_id] variable {C} in /-- 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] /-- 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 grind 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'] simp 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
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/FunctorCategories.lean
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 [Y]) } use Y, i, e constructor · ext j dsimp rw [assoc, equalizer.lift_ι, ← equalizer.condition, id_comp, comp_id] · ext j simp [Y, i, e] 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 rw [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 φ) dsimp [karoubiFunctorCategoryEmbedding] at h simp only [assoc, h.symm, karoubiFunctorCategoryEmbedding_obj, KaroubiFunctorCategoryEmbedding.obj_obj_p] rw [← P.p.naturality_assoc] exact congrArg _ (p_comp (f.app _)).symm } 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 = (Functor.whiskeringRight J _ _).obj (toKaroubi C) := by apply Functor.ext · intro X Y f ext j simp · intro X apply Functor.ext · intro j j' φ ext simp · intro j rfl end Idempotents end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Idempotents/KaroubiKaroubi.lean
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] @[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 cat_disch) (by simp)) 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
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Opposite.lean
import Mathlib.CategoryTheory.Shift.Adjunction import Mathlib.CategoryTheory.Preadditive.Opposite /-! # The (naive) shift on the opposite category If `C` is a category equipped with a shift by a monoid `A`, the opposite category can be equipped with a shift such that the shift functor by `n` is `(shiftFunctor C n).op`. This is the "naive" opposite shift, which we shall set on a category `OppositeShift C A`, which is a type synonym for `Cᵒᵖ`. However, for the application to (pre)triangulated categories, we would like to define the shift on `Cᵒᵖ` so that `shiftFunctor Cᵒᵖ n` for `n : ℤ` identifies to `(shiftFunctor C (-n)).op` rather than `(shiftFunctor C n).op`. Then, the construction of the shift on `Cᵒᵖ` shall combine the shift on `OppositeShift C A` and another construction of the "pullback" of a shift by a monoid morphism like `n ↦ -n`. If `F : C ⥤ D` is a functor between categories equipped with shifts by `A`, we define a type synonym `OppositeShift.functor A F` for `F.op`. When `F` has a `CommShift` structure by `A`, we define a `CommShift` structure by `A` on `OppositeShift.functor A F`. In this way, we can make this an instance and reserve `F.op` for the `CommShift` instance by the modified shift in the case of (pre)triangulated categories. Similarly, if `τ` is a natural transformation between functors `F,G : C ⥤ D`, we define a type synonym for `τ.op` called `OppositeShift.natTrans A τ : OppositeShift.functor A F ⟶ OppositeShift.functor A G`. When `τ` has a `CommShift` structure by `A` (i.e. is compatible with `CommShift` structures on `F` and `G`), we define a `CommShift` structure by `A` on `OppositeShift.natTrans A τ`. Finally, if we have an adjunction `F ⊣ G` (with `G : D ⥤ C`), we define a type synonym `OppositeShift.adjunction A adj : OppositeShift.functor A G ⊣ OppositeShift.functor A F` for `adj.op`, and we show that, if `adj` compatible with `CommShift` structures on `F` and `G`, then `OppositeShift.adjunction A adj` is also compatible with the pulled back `CommShift` structures. Given a `CommShift` structure on a functor `F`, we define a `CommShift` structure on `F.op` (and vice versa). We also prove that, if an adjunction `F ⊣ G` is compatible with `CommShift` structures on `F` and `G`, then the opposite adjunction `G.op ⊣ F.op` is compatible with the opposite `CommShift` structures. -/ namespace CategoryTheory open Limits Category section variable (C : Type*) [Category C] (A : Type*) [AddMonoid A] [HasShift C A] namespace HasShift /-- Construction of the naive shift on the opposite category of a category `C`: the shiftfunctor by `n` is `(shiftFunctor C n).op`. -/ noncomputable def mkShiftCoreOp : ShiftMkCore Cᵒᵖ A where F n := (shiftFunctor C n).op zero := (NatIso.op (shiftFunctorZero C A)).symm add a b := (NatIso.op (shiftFunctorAdd C a b)).symm assoc_hom_app m₁ m₂ m₃ X := Quiver.Hom.unop_inj ((shiftFunctorAdd_assoc_inv_app m₁ m₂ m₃ X.unop).trans (by simp [shiftFunctorAdd'])) zero_add_hom_app n X := Quiver.Hom.unop_inj ((shiftFunctorAdd_zero_add_inv_app n X.unop).trans (by simp)) add_zero_hom_app n X := Quiver.Hom.unop_inj ((shiftFunctorAdd_add_zero_inv_app n X.unop).trans (by simp)) end HasShift /-- The category `OppositeShift C A` is the opposite category `Cᵒᵖ` equipped with the naive shift: `shiftFunctor (OppositeShift C A) n` is `(shiftFunctor C n).op`. -/ @[nolint unusedArguments] def OppositeShift (A : Type*) [AddMonoid A] [HasShift C A] := Cᵒᵖ instance : Category (OppositeShift C A) := inferInstanceAs (Category Cᵒᵖ) noncomputable instance : HasShift (OppositeShift C A) A := hasShiftMk Cᵒᵖ A (HasShift.mkShiftCoreOp C A) instance [HasZeroObject C] : HasZeroObject (OppositeShift C A) := by dsimp only [OppositeShift] infer_instance instance [Preadditive C] : Preadditive (OppositeShift C A) := inferInstanceAs (Preadditive Cᵒᵖ) instance [Preadditive C] (n : A) [(shiftFunctor C n).Additive] : (shiftFunctor (OppositeShift C A) n).Additive := by change (shiftFunctor C n).op.Additive infer_instance lemma oppositeShiftFunctorZero_inv_app (X : OppositeShift C A) : (shiftFunctorZero (OppositeShift C A) A).inv.app X = ((shiftFunctorZero C A).hom.app X.unop).op := rfl lemma oppositeShiftFunctorZero_hom_app (X : OppositeShift C A) : (shiftFunctorZero (OppositeShift C A) A).hom.app X = ((shiftFunctorZero C A).inv.app X.unop).op := by rw [← cancel_mono ((shiftFunctorZero (OppositeShift C A) A).inv.app X), Iso.hom_inv_id_app, oppositeShiftFunctorZero_inv_app, ← op_comp, Iso.hom_inv_id_app, op_id] rfl variable {C A} variable (X : OppositeShift C A) (a b c : A) (h : a + b = c) lemma oppositeShiftFunctorAdd_inv_app : (shiftFunctorAdd (OppositeShift C A) a b).inv.app X = ((shiftFunctorAdd C a b).hom.app X.unop).op := rfl lemma oppositeShiftFunctorAdd_hom_app : (shiftFunctorAdd (OppositeShift C A) a b).hom.app X = ((shiftFunctorAdd C a b).inv.app X.unop).op := by rw [← cancel_mono ((shiftFunctorAdd (OppositeShift C A) a b).inv.app X), Iso.hom_inv_id_app, oppositeShiftFunctorAdd_inv_app, ← op_comp, Iso.hom_inv_id_app, op_id] rfl lemma oppositeShiftFunctorAdd'_inv_app : (shiftFunctorAdd' (OppositeShift C A) a b c h).inv.app X = ((shiftFunctorAdd' C a b c h).hom.app X.unop).op := by subst h simp only [shiftFunctorAdd'_eq_shiftFunctorAdd, oppositeShiftFunctorAdd_inv_app] lemma oppositeShiftFunctorAdd'_hom_app : (shiftFunctorAdd' (OppositeShift C A) a b c h).hom.app X = ((shiftFunctorAdd' C a b c h).inv.app X.unop).op := by subst h simp only [shiftFunctorAdd'_eq_shiftFunctorAdd, oppositeShiftFunctorAdd_hom_app] end variable {C D : Type*} [Category C] [Category D] (A : Type*) [AddMonoid A] [HasShift C A] [HasShift D A] (F : C ⥤ D) /-- The functor `F.op`, seen as a functor from `OppositeShift C A` to `OppositeShift D A`. (We will use this to carry a `CommShift` instance for the naive shifts on the opposite category. Then, in the pretriangulated case, we will be able to put a `CommShift` instance on `F.op` for the modified shifts and not deal with instance clashes. -/ def OppositeShift.functor : OppositeShift C A ⥤ OppositeShift D A := F.op variable {F} in /-- The natural transformation `τ`, seen as a natural transformation from `OppositeShift.functor F A` to `OppositeShift.functor G A`.. -/ def OppositeShift.natTrans {G : C ⥤ D} (τ : F ⟶ G) : OppositeShift.functor A G ⟶ OppositeShift.functor A F := NatTrans.op τ namespace Functor /-- Given a `CommShift` structure on `F`, this is the corresponding `CommShift` structure on `OppositeShift.functor F` (for the naive shifts on the opposite categories). -/ noncomputable instance commShiftOp [CommShift F A] : CommShift (OppositeShift.functor A F) A where commShiftIso a := (NatIso.op (F.commShiftIso a)).symm commShiftIso_zero := by rw [commShiftIso_zero] ext simp only [op_obj, comp_obj, Iso.symm_hom, NatIso.op_inv, NatTrans.op_app, CommShift.isoZero_inv_app, op_comp, CommShift.isoZero_hom_app] erw [oppositeShiftFunctorZero_inv_app, oppositeShiftFunctorZero_hom_app] rfl commShiftIso_add a b := by rw [commShiftIso_add] ext simp only [op_obj, comp_obj, Iso.symm_hom, NatIso.op_inv, NatTrans.op_app, CommShift.isoAdd_inv_app, op_comp, Category.assoc, CommShift.isoAdd_hom_app] erw [oppositeShiftFunctorAdd_inv_app, oppositeShiftFunctorAdd_hom_app] rfl lemma commShiftOp_iso_eq [CommShift F A] (a : A) : (OppositeShift.functor A F).commShiftIso a = (NatIso.op (F.commShiftIso a)).symm := rfl /-- Given a `CommShift` structure on `OppositeShift.functor F` (for the naive shifts on the opposite categories), this is the corresponding `CommShift` structure on `F`. -/ @[simps -isSimp] noncomputable def commShiftUnop [CommShift (OppositeShift.functor A F) A] : CommShift F A where commShiftIso a := NatIso.removeOp ((OppositeShift.functor A F).commShiftIso a).symm commShiftIso_zero := by rw [commShiftIso_zero] ext simp only [comp_obj, NatIso.removeOp_hom, Iso.symm_hom, NatTrans.removeOp_app, op_obj, CommShift.isoZero_inv_app, unop_comp, CommShift.isoZero_hom_app] erw [oppositeShiftFunctorZero_hom_app, oppositeShiftFunctorZero_inv_app] rfl commShiftIso_add a b := by rw [commShiftIso_add] ext simp only [comp_obj, NatIso.removeOp_hom, Iso.symm_hom, NatTrans.removeOp_app, op_obj, CommShift.isoAdd_inv_app, unop_comp, Category.assoc, CommShift.isoAdd_hom_app] erw [oppositeShiftFunctorAdd_hom_app, oppositeShiftFunctorAdd_inv_app] rfl end Functor namespace NatTrans variable {F} {G : C ⥤ D} [F.CommShift A] [G.CommShift A] open Opposite in instance commShift_op (τ : F ⟶ G) [NatTrans.CommShift τ A] : NatTrans.CommShift (OppositeShift.natTrans A τ) A where shift_comm _ := by ext rw [← cancel_mono (((OppositeShift.functor A F).commShiftIso _ ).inv.app _), ← cancel_epi (((OppositeShift.functor A G).commShiftIso _).inv.app _)] dsimp simp only [assoc, Iso.inv_hom_id_app_assoc, Iso.hom_inv_id_app, Functor.comp_obj, comp_id] exact (op_inj_iff _ _).mpr (NatTrans.shift_app_comm τ _ (unop _)) end NatTrans namespace NatTrans variable (C) in /-- The obvious isomorphism between the identity of `OppositeShift C A` and `OppositeShift.functor (𝟙 C)`. -/ def OppositeShift.natIsoId : 𝟭 (OppositeShift C A) ≅ OppositeShift.functor A (𝟭 C) := Iso.refl _ /-- The natural isomorphism `NatTrans.OppositeShift.natIsoId C A` commutes with shifts. -/ instance : NatTrans.CommShift (OppositeShift.natIsoId C A).hom A where shift_comm _ := by ext dsimp [OppositeShift.natIsoId, Functor.commShiftOp_iso_eq] simp only [Functor.commShiftIso_id_hom_app, Functor.map_id, comp_id, Functor.commShiftIso_id_inv_app, CategoryTheory.op_id, id_comp] rfl variable {E : Type*} [Category E] [HasShift E A] (G : D ⥤ E) /-- The obvious isomorphism between `OppositeShift.functor (F ⋙ G)` and the composition of `OppositeShift.functor F` and `OppositeShift.functor G`. -/ def OppositeShift.natIsoComp : OppositeShift.functor A (F ⋙ G) ≅ OppositeShift.functor A F ⋙ OppositeShift.functor A G := Iso.refl _ instance [F.CommShift A] [G.CommShift A] : NatTrans.CommShift (OppositeShift.natIsoComp A F G).hom A where shift_comm _ := by ext dsimp [OppositeShift.natIsoComp, Functor.commShiftOp_iso_eq] simp only [Functor.map_id, comp_id, id_comp] rfl end NatTrans /-- The adjunction `adj`, seen as an adjunction between `OppositeShift.functor G` and `OppositeShift.functor F`. -/ @[simps -isSimp] def OppositeShift.adjunction {F} {G : D ⥤ C} (adj : F ⊣ G) : OppositeShift.functor A G ⊣ OppositeShift.functor A F where unit := (NatTrans.OppositeShift.natIsoId D A).hom ≫ OppositeShift.natTrans A adj.counit ≫ (NatTrans.OppositeShift.natIsoComp A G F).hom counit := (NatTrans.OppositeShift.natIsoComp A F G).inv ≫ OppositeShift.natTrans A adj.unit ≫ (NatTrans.OppositeShift.natIsoId C A).inv left_triangle_components _ := by dsimp [OppositeShift.natTrans, NatTrans.OppositeShift.natIsoComp, NatTrans.OppositeShift.natIsoId, OppositeShift.functor] simp only [comp_id, id_comp, Quiver.Hom.unop_op] rw [← op_comp, adj.right_triangle_components] rfl right_triangle_components _ := by dsimp [OppositeShift.natTrans, NatTrans.OppositeShift.natIsoComp, NatTrans.OppositeShift.natIsoId, OppositeShift.functor] simp only [comp_id, id_comp, Quiver.Hom.unop_op] rw [← op_comp, adj.left_triangle_components] rfl namespace Adjunction variable {F} {G : D ⥤ C} (adj : F ⊣ G) /-- If an adjunction `F ⊣ G` is compatible with `CommShift` structures on `F` and `G`, then the opposite adjunction `OppositeShift.adjunction adj` is compatible with the opposite `CommShift` structures. -/ instance commShift_op [F.CommShift A] [G.CommShift A] [adj.CommShift A] : Adjunction.CommShift (OppositeShift.adjunction A adj) A where commShift_unit := by dsimp [OppositeShift.adjunction]; infer_instance commShift_counit := by dsimp [OppositeShift.adjunction]; infer_instance end Adjunction end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/CommShift.lean
import Mathlib.CategoryTheory.Shift.Basic /-! # Functors which commute with shifts Let `C` and `D` be two categories equipped with shifts by an additive monoid `A`. In this file, we define the notion of functor `F : C ⥤ D` which "commutes" with these shifts. The associated type class is `[F.CommShift A]`. The data consists of commutation isomorphisms `F.commShiftIso a : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` for all `a : A` which satisfy a compatibility with the addition and the zero. After this was formalised in Lean, it was found that this definition is exactly the definition which appears in Jean-Louis Verdier's thesis (I 1.2.3/1.2.4), although the language is different. (In Verdier's thesis, the shift is not given by a monoidal functor `Discrete A ⥤ C ⥤ C`, but by a fibred category `C ⥤ BA`, where `BA` is the category with one object, the endomorphisms of which identify to `A`. The choice of a cleavage for this fibered category gives the individual shift functors.) ## References * [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996] -/ namespace CategoryTheory open Category namespace Functor variable {C D E : Type*} [Category C] [Category D] [Category E] (F : C ⥤ D) (G : D ⥤ E) (A B : Type*) [AddMonoid A] [AddCommMonoid B] [HasShift C A] [HasShift D A] [HasShift E A] [HasShift C B] [HasShift D B] namespace CommShift /-- For any functor `F : C ⥤ D`, this is the obvious isomorphism `shiftFunctor C (0 : A) ⋙ F ≅ F ⋙ shiftFunctor D (0 : A)` deduced from the isomorphisms `shiftFunctorZero` on both categories `C` and `D`. -/ @[simps!] noncomputable def isoZero : shiftFunctor C (0 : A) ⋙ F ≅ F ⋙ shiftFunctor D (0 : A) := isoWhiskerRight (shiftFunctorZero C A) F ≪≫ F.leftUnitor ≪≫ F.rightUnitor.symm ≪≫ isoWhiskerLeft F (shiftFunctorZero D A).symm /-- For any functor `F : C ⥤ D` and any `a` in `A` such that `a = 0`, this is the obvious isomorphism `shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` deduced from the isomorphisms `shiftFunctorZero'` on both categories `C` and `D`. -/ @[simps!] noncomputable def isoZero' (a : A) (ha : a = 0) : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a := isoWhiskerRight (shiftFunctorZero' C a ha) F ≪≫ F.leftUnitor ≪≫ F.rightUnitor.symm ≪≫ isoWhiskerLeft F (shiftFunctorZero' D a ha).symm @[simp] lemma isoZero'_eq_isoZero : isoZero' F A 0 rfl = isoZero F A := by ext; simp [isoZero', shiftFunctorZero'] variable {F A} /-- If a functor `F : C ⥤ D` is equipped with "commutation isomorphisms" with the shifts by `a` and `b`, then there is a commutation isomorphism with the shift by `c` when `a + b = c`. -/ @[simps!] noncomputable def isoAdd' {a b c : A} (h : a + b = c) (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) : shiftFunctor C c ⋙ F ≅ F ⋙ shiftFunctor D c := isoWhiskerRight (shiftFunctorAdd' C _ _ _ h) F ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e₂ ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight e₁ _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (shiftFunctorAdd' D _ _ _ h).symm /-- If a functor `F : C ⥤ D` is equipped with "commutation isomorphisms" with the shifts by `a` and `b`, then there is a commutation isomorphism with the shift by `a + b`. -/ noncomputable def isoAdd {a b : A} (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) : shiftFunctor C (a + b) ⋙ F ≅ F ⋙ shiftFunctor D (a + b) := CommShift.isoAdd' rfl e₁ e₂ @[simp] lemma isoAdd_hom_app {a b : A} (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) (X : C) : (CommShift.isoAdd e₁ e₂).hom.app X = F.map ((shiftFunctorAdd C a b).hom.app X) ≫ e₂.hom.app ((shiftFunctor C a).obj X) ≫ (shiftFunctor D b).map (e₁.hom.app X) ≫ (shiftFunctorAdd D a b).inv.app (F.obj X) := by simp only [isoAdd, isoAdd'_hom_app, shiftFunctorAdd'_eq_shiftFunctorAdd] @[simp] lemma isoAdd_inv_app {a b : A} (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) (X : C) : (CommShift.isoAdd e₁ e₂).inv.app X = (shiftFunctorAdd D a b).hom.app (F.obj X) ≫ (shiftFunctor D b).map (e₁.inv.app X) ≫ e₂.inv.app ((shiftFunctor C a).obj X) ≫ F.map ((shiftFunctorAdd C a b).inv.app X) := by simp only [isoAdd, isoAdd'_inv_app, shiftFunctorAdd'_eq_shiftFunctorAdd] end CommShift /-- A functor `F` commutes with the shift by a monoid `A` if it is equipped with commutation isomorphisms with the shifts by all `a : A`, and these isomorphisms satisfy coherence properties with respect to `0 : A` and the addition in `A`. -/ class CommShift (F : C ⥤ D) (A : Type*) [AddMonoid A] [HasShift C A] [HasShift D A] where /-- The commutation isomorphisms for all `a`-shifts this functor is equipped with -/ commShiftIso (F) (a : A) : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a commShiftIso_zero (F) (A) : commShiftIso 0 = CommShift.isoZero F A := by cat_disch commShiftIso_add (F) (a b : A) : commShiftIso (a + b) = CommShift.isoAdd (commShiftIso a) (commShiftIso b) := by cat_disch variable {A} export CommShift (commShiftIso commShiftIso_zero commShiftIso_add) @[deprecated (since := "2025-11-11")] alias CommShift.iso := commShiftIso @[deprecated (since := "2025-11-11")] alias CommShift.zero := commShiftIso_zero @[deprecated (since := "2025-11-11")] alias CommShift.add := commShiftIso_add section variable [F.CommShift A] -- Note: The following two lemmas are introduced in order to have more proofs work `by simp`. -- Indeed, `simp only [(F.commShiftIso a).hom.naturality f]` would almost never work because -- of the compositions of functors which appear in both the source and target of -- `F.commShiftIso a`. Otherwise, we would be forced to use `erw [NatTrans.naturality]`. @[reassoc (attr := simp)] lemma commShiftIso_hom_naturality {X Y : C} (f : X ⟶ Y) (a : A) : F.map (f⟦a⟧') ≫ (F.commShiftIso a).hom.app Y = (F.commShiftIso a).hom.app X ≫ (F.map f)⟦a⟧' := (F.commShiftIso a).hom.naturality f @[reassoc (attr := simp)] lemma commShiftIso_inv_naturality {X Y : C} (f : X ⟶ Y) (a : A) : (F.map f)⟦a⟧' ≫ (F.commShiftIso a).inv.app Y = (F.commShiftIso a).inv.app X ≫ F.map (f⟦a⟧') := (F.commShiftIso a).inv.naturality f variable (A) in set_option linter.docPrime false in lemma commShiftIso_zero' (a : A) (h : a = 0) : F.commShiftIso a = CommShift.isoZero' F A a h := by subst h; rw [CommShift.isoZero'_eq_isoZero, commShiftIso_zero] lemma commShiftIso_add' {a b c : A} (h : a + b = c) : F.commShiftIso c = CommShift.isoAdd' h (F.commShiftIso a) (F.commShiftIso b) := by subst h simp only [commShiftIso_add, CommShift.isoAdd] end namespace CommShift variable (C) in @[simps! -isSimp commShiftIso_hom_app commShiftIso_inv_app] instance id : CommShift (𝟭 C) A where commShiftIso := fun _ => rightUnitor _ ≪≫ (leftUnitor _).symm @[simps! -isSimp commShiftIso_hom_app commShiftIso_inv_app] instance comp [F.CommShift A] [G.CommShift A] : (F ⋙ G).CommShift A where commShiftIso a := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (F.commShiftIso a) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (G.commShiftIso a) ≪≫ (Functor.associator _ _ _).symm commShiftIso_zero := by ext X dsimp simp only [id_comp, comp_id, commShiftIso_zero, isoZero_hom_app, ← Functor.map_comp_assoc, assoc, Iso.inv_hom_id_app, id_obj, comp_map, comp_obj] commShiftIso_add := fun a b => by ext X dsimp simp only [commShiftIso_add, isoAdd_hom_app] dsimp simp only [comp_id, id_comp, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, comp_obj] simp only [map_comp, assoc, commShiftIso_hom_naturality_assoc] end CommShift alias commShiftIso_id_hom_app := CommShift.id_commShiftIso_hom_app alias commShiftIso_id_inv_app := CommShift.id_commShiftIso_inv_app alias commShiftIso_comp_hom_app := CommShift.comp_commShiftIso_hom_app alias commShiftIso_comp_inv_app := CommShift.comp_commShiftIso_inv_app attribute [simp] commShiftIso_id_hom_app commShiftIso_id_inv_app variable {B} lemma map_shiftFunctorComm_hom_app [F.CommShift B] (X : C) (a b : B) : F.map ((shiftFunctorComm C a b).hom.app X) = (F.commShiftIso b).hom.app (X⟦a⟧) ≫ ((F.commShiftIso a).hom.app X)⟦b⟧' ≫ (shiftFunctorComm D a b).hom.app (F.obj X) ≫ ((F.commShiftIso b).inv.app X)⟦a⟧' ≫ (F.commShiftIso a).inv.app (X⟦b⟧) := by have eq := NatTrans.congr_app (congr_arg Iso.hom (F.commShiftIso_add a b)) X simp only [comp_obj, CommShift.isoAdd_hom_app, ← cancel_epi (F.map ((shiftFunctorAdd C a b).inv.app X)), ← F.map_comp_assoc, Iso.inv_hom_id_app, F.map_id, Category.id_comp] at eq simp only [shiftFunctorComm_eq D a b _ rfl] dsimp simp only [shiftFunctorAdd'_eq_shiftFunctorAdd, Category.assoc, ← reassoc_of% eq, shiftFunctorComm_eq C a b _ rfl] dsimp rw [Functor.map_comp] simp only [NatTrans.congr_app (congr_arg Iso.hom (F.commShiftIso_add' (add_comm b a))) X, CommShift.isoAdd'_hom_app, Category.assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, Category.id_comp, comp_obj, Category.comp_id] @[simp, reassoc] lemma map_shiftFunctorCompIsoId_hom_app [F.CommShift A] (X : C) (a b : A) (h : a + b = 0) : F.map ((shiftFunctorCompIsoId C a b h).hom.app X) = (F.commShiftIso b).hom.app (X⟦a⟧) ≫ ((F.commShiftIso a).hom.app X)⟦b⟧' ≫ (shiftFunctorCompIsoId D a b h).hom.app (F.obj X) := by dsimp [shiftFunctorCompIsoId] have eq := NatTrans.congr_app (congr_arg Iso.hom (F.commShiftIso_add' h)) X simp only [commShiftIso_zero, comp_obj, CommShift.isoZero_hom_app, CommShift.isoAdd'_hom_app] at eq rw [← cancel_epi (F.map ((shiftFunctorAdd' C a b 0 h).hom.app X)), ← reassoc_of% eq, F.map_comp] simp only [Iso.inv_hom_id_app, id_obj, Category.comp_id, ← F.map_comp_assoc, Iso.hom_inv_id_app, F.map_id, Category.id_comp] @[simp, reassoc] lemma map_shiftFunctorCompIsoId_inv_app [F.CommShift A] (X : C) (a b : A) (h : a + b = 0) : F.map ((shiftFunctorCompIsoId C a b h).inv.app X) = (shiftFunctorCompIsoId D a b h).inv.app (F.obj X) ≫ ((F.commShiftIso a).inv.app X)⟦b⟧' ≫ (F.commShiftIso b).inv.app (X⟦a⟧) := by rw [← cancel_epi (F.map ((shiftFunctorCompIsoId C a b h).hom.app X)), ← F.map_comp, Iso.hom_inv_id_app, F.map_id, map_shiftFunctorCompIsoId_hom_app] simp only [comp_obj, id_obj, Category.assoc, Iso.hom_inv_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, Category.id_comp] end Functor namespace NatTrans variable {C D E J : Type*} [Category C] [Category D] [Category E] [Category J] {F₁ F₂ F₃ : C ⥤ D} (τ : F₁ ⟶ F₂) (τ' : F₂ ⟶ F₃) (e : F₁ ≅ F₂) (G G' : D ⥤ E) (τ'' : G ⟶ G') (H : E ⥤ J) (A : Type*) [AddMonoid A] [HasShift C A] [HasShift D A] [HasShift E A] [HasShift J A] [F₁.CommShift A] [F₂.CommShift A] [F₃.CommShift A] [G.CommShift A] [G'.CommShift A] [H.CommShift A] /-- If `τ : F₁ ⟶ F₂` is a natural transformation between two functors which commute with a shift by an additive monoid `A`, this typeclass asserts a compatibility of `τ` with these shifts. -/ class CommShift : Prop where shift_comm (a : A) : (F₁.commShiftIso a).hom ≫ Functor.whiskerRight τ _ = Functor.whiskerLeft _ τ ≫ (F₂.commShiftIso a).hom := by cat_disch section variable {A} [NatTrans.CommShift τ A] @[reassoc] lemma shift_comm (a : A) : (F₁.commShiftIso a).hom ≫ Functor.whiskerRight τ _ = Functor.whiskerLeft _ τ ≫ (F₂.commShiftIso a).hom := by apply CommShift.shift_comm @[reassoc] lemma shift_app_comm (a : A) (X : C) : (F₁.commShiftIso a).hom.app X ≫ (τ.app X)⟦a⟧' = τ.app (X⟦a⟧) ≫ (F₂.commShiftIso a).hom.app X := congr_app (shift_comm τ a) X @[reassoc] lemma shift_app (a : A) (X : C) : (τ.app X)⟦a⟧' = (F₁.commShiftIso a).inv.app X ≫ τ.app (X⟦a⟧) ≫ (F₂.commShiftIso a).hom.app X := by rw [← shift_app_comm, Iso.inv_hom_id_app_assoc] @[reassoc] lemma app_shift (a : A) (X : C) : τ.app (X⟦a⟧) = (F₁.commShiftIso a).hom.app X ≫ (τ.app X)⟦a⟧' ≫ (F₂.commShiftIso a).inv.app X := by simp [shift_app_comm_assoc τ a X] end namespace CommShift instance of_iso_inv [NatTrans.CommShift e.hom A] : NatTrans.CommShift e.inv A := ⟨fun a => by ext X dsimp rw [← cancel_epi (e.hom.app (X⟦a⟧)), e.hom_inv_id_app_assoc, ← shift_app_comm_assoc, ← Functor.map_comp, e.hom_inv_id_app, Functor.map_id, Category.comp_id]⟩ lemma of_isIso [IsIso τ] [NatTrans.CommShift τ A] : NatTrans.CommShift (inv τ) A := by haveI : NatTrans.CommShift (asIso τ).hom A := by assumption change NatTrans.CommShift (asIso τ).inv A infer_instance variable (F₁) in instance id : NatTrans.CommShift (𝟙 F₁) A where attribute [local simp] Functor.commShiftIso_comp_hom_app shift_app_comm shift_app_comm_assoc instance comp [NatTrans.CommShift τ A] [NatTrans.CommShift τ' A] : NatTrans.CommShift (τ ≫ τ') A where instance whiskerRight [NatTrans.CommShift τ A] : NatTrans.CommShift (Functor.whiskerRight τ G) A := ⟨fun a => by ext X simp only [Functor.whiskerRight_twice, comp_app, Functor.commShiftIso_comp_hom_app, Functor.associator_hom_app, Functor.whiskerRight_app, Functor.comp_map, Functor.associator_inv_app, comp_id, id_comp, assoc, ← Functor.commShiftIso_hom_naturality, ← G.map_comp_assoc, shift_app_comm, Functor.whiskerLeft_app]⟩ instance whiskerLeft [NatTrans.CommShift τ'' A] : NatTrans.CommShift (Functor.whiskerLeft F₁ τ'') A where instance associator : CommShift (Functor.associator F₁ G H).hom A where instance leftUnitor : CommShift F₁.leftUnitor.hom A where instance rightUnitor : CommShift F₁.rightUnitor.hom A where end CommShift end NatTrans namespace Functor namespace CommShift variable {C D E : Type*} [Category C] [Category D] {F : C ⥤ D} {G : C ⥤ D} (e : F ≅ G) (A : Type*) [AddMonoid A] [HasShift C A] [HasShift D A] [F.CommShift A] /-- If `e : F ≅ G` is an isomorphism of functors and if `F` commutes with the shift, then `G` also commutes with the shift. -/ @[simps! -isSimp commShiftIso_hom_app commShiftIso_inv_app] def ofIso : G.CommShift A where commShiftIso a := isoWhiskerLeft _ e.symm ≪≫ F.commShiftIso a ≪≫ isoWhiskerRight e _ commShiftIso_zero := by ext X simp [F.commShiftIso_zero, ← NatTrans.naturality] commShiftIso_add a b := by ext X simp only [comp_obj, F.commShiftIso_add, Iso.trans_hom, isoWhiskerLeft_hom, Iso.symm_hom, isoWhiskerRight_hom, NatTrans.comp_app, whiskerLeft_app, isoAdd_hom_app, whiskerRight_app, assoc, map_comp, NatTrans.naturality_assoc, NatIso.cancel_natIso_inv_left] simp only [← Functor.map_comp_assoc, e.hom_inv_id_app_assoc] simp only [← NatTrans.naturality, comp_obj, comp_map, map_comp, assoc] lemma ofIso_compatibility : letI := ofIso e A NatTrans.CommShift e.hom A := by letI := ofIso e A exact ⟨fun a => by ext; simp [ofIso_commShiftIso_hom_app]⟩ end CommShift end Functor /-- Assume that we have a diagram of categories ``` C₁ ⥤ D₁ ‖ ‖ v v C₂ ⥤ D₂ ‖ ‖ v v C₃ ⥤ D₃ ``` with functors `F₁₂ : C₁ ⥤ C₂`, `F₂₃ : C₂ ⥤ C₃` and `F₁₃ : C₁ ⥤ C₃` on the first column that are related by a natural transformation `α : F₁₃ ⟶ F₁₂ ⋙ F₂₃` and similarly `β : G₁₂ ⋙ G₂₃ ⟶ G₁₃` on the second column. Assume that we have natural transformations `e₁₂ : F₁₂ ⋙ L₂ ⟶ L₁ ⋙ G₁₂` (top square), `e₂₃ : F₂₃ ⋙ L₃ ⟶ L₂ ⋙ G₂₃` (bottom square), and `e₁₃ : F₁₃ ⋙ L₃ ⟶ L₁ ⋙ G₁₃` (outer square), where the horizontal functors are denoted `L₁`, `L₂` and `L₃`. Assume that `e₁₃` is determined by the other natural transformations `α`, `e₂₃`, `e₁₂` and `β`. Then, if all these categories are equipped with a shift by an additive monoid `A`, and all these functors commute with these shifts, then the natural transformation `e₁₃` of the outer square commutes with the shift if all `α`, `e₂₃`, `e₁₂` and `β` do. -/ lemma NatTrans.CommShift.verticalComposition {C₁ C₂ C₃ D₁ D₂ D₃ : Type*} [Category C₁] [Category C₂] [Category C₃] [Category D₁] [Category D₂] [Category D₃] {F₁₂ : C₁ ⥤ C₂} {F₂₃ : C₂ ⥤ C₃} {F₁₃ : C₁ ⥤ C₃} (α : F₁₃ ⟶ F₁₂ ⋙ F₂₃) {G₁₂ : D₁ ⥤ D₂} {G₂₃ : D₂ ⥤ D₃} {G₁₃ : D₁ ⥤ D₃} (β : G₁₂ ⋙ G₂₃ ⟶ G₁₃) {L₁ : C₁ ⥤ D₁} {L₂ : C₂ ⥤ D₂} {L₃ : C₃ ⥤ D₃} (e₁₂ : F₁₂ ⋙ L₂ ⟶ L₁ ⋙ G₁₂) (e₂₃ : F₂₃ ⋙ L₃ ⟶ L₂ ⋙ G₂₃) (e₁₃ : F₁₃ ⋙ L₃ ⟶ L₁ ⋙ G₁₃) (A : Type*) [AddMonoid A] [HasShift C₁ A] [HasShift C₂ A] [HasShift C₃ A] [HasShift D₁ A] [HasShift D₂ A] [HasShift D₃ A] [F₁₂.CommShift A] [F₂₃.CommShift A] [F₁₃.CommShift A] [CommShift α A] [G₁₂.CommShift A] [G₂₃.CommShift A] [G₁₃.CommShift A] [CommShift β A] [L₁.CommShift A] [L₂.CommShift A] [L₃.CommShift A] [CommShift e₁₂ A] [CommShift e₂₃ A] (h₁₃ : e₁₃ = Functor.whiskerRight α L₃ ≫ (Functor.associator _ _ _).hom ≫ Functor.whiskerLeft F₁₂ e₂₃ ≫ (Functor.associator _ _ _).inv ≫ Functor.whiskerRight e₁₂ G₂₃ ≫ (Functor.associator _ _ _).hom ≫ Functor.whiskerLeft L₁ β) : CommShift e₁₃ A := by subst h₁₃ infer_instance end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/ShiftedHomOpposite.lean
import Mathlib.CategoryTheory.Triangulated.Opposite.Basic import Mathlib.CategoryTheory.Shift.ShiftedHom /-! Shifted morphisms in the opposite category If `C` is a category equipped with a shift by `ℤ`, `X` and `Y` are objects of `C`, and `n : ℤ`, we define a bijection `ShiftedHom.opEquiv : ShiftedHom X Y n ≃ ShiftedHom (Opposite.op Y) (Opposite.op X) n`. We also introduce `ShiftedHom.opEquiv'` which produces a bijection `ShiftedHom X Y a' ≃ (Opposite.op (Y⟦a⟧) ⟶ (Opposite.op X)⟦n⟧)` when `n + a = a'`. The compatibilities that are obtained shall be used in order to study the homological functor `preadditiveYoneda.obj B : Cᵒᵖ ⥤ Type _` when `B` is an object in a pretriangulated category `C`. -/ namespace CategoryTheory open Category Pretriangulated.Opposite Pretriangulated variable {C : Type*} [Category C] [HasShift C ℤ] {X Y Z : C} namespace ShiftedHom /-- The bijection `ShiftedHom X Y n ≃ ShiftedHom (Opposite.op Y) (Opposite.op X) n` when `n : ℤ`, and `X` and `Y` are objects of a category equipped with a shift by `ℤ`. -/ noncomputable def opEquiv (n : ℤ) : ShiftedHom X Y n ≃ ShiftedHom (Opposite.op Y) (Opposite.op X) n := Quiver.Hom.opEquiv.trans ((opShiftFunctorEquivalence C n).symm.toAdjunction.homEquiv (Opposite.op Y) (Opposite.op X)) lemma opEquiv_symm_apply {n : ℤ} (f : ShiftedHom (Opposite.op Y) (Opposite.op X) n) : (opEquiv n).symm f = ((opShiftFunctorEquivalence C n).unitIso.inv.app (Opposite.op X)).unop ≫ f.unop⟦n⟧' := rfl lemma opEquiv_symm_apply_comp {X Y : C} {a : ℤ} (f : ShiftedHom (Opposite.op X) (Opposite.op Y) a) {b : ℤ} {Z : C} (z : ShiftedHom X Z b) {c : ℤ} (h : b + a = c) : ((ShiftedHom.opEquiv a).symm f).comp z h = (ShiftedHom.opEquiv a).symm (z.op ≫ f) ≫ (shiftFunctorAdd' C b a c h).inv.app Z := by rw [ShiftedHom.opEquiv_symm_apply, ShiftedHom.opEquiv_symm_apply, ShiftedHom.comp] dsimp simp only [assoc, Functor.map_comp] lemma opEquiv_symm_comp {a b : ℤ} (f : ShiftedHom (Opposite.op Z) (Opposite.op Y) a) (g : ShiftedHom (Opposite.op Y) (Opposite.op X) b) {c : ℤ} (h : b + a = c) : (opEquiv _).symm (f.comp g h) = ((opEquiv _).symm g).comp ((opEquiv _).symm f) (by cutsat) := by rw [opEquiv_symm_apply, opEquiv_symm_apply, opShiftFunctorEquivalence_unitIso_inv_app_eq _ _ _ _ (show a + b = c by cutsat), comp, comp] dsimp rw [assoc, assoc, assoc, assoc, ← Functor.map_comp, ← unop_comp_assoc, Iso.inv_hom_id_app] dsimp rw [assoc, id_comp, Functor.map_comp, ← NatTrans.naturality_assoc, ← NatTrans.naturality, opEquiv_symm_apply] dsimp rw [← Functor.map_comp_assoc, ← Functor.map_comp_assoc, ← Functor.map_comp_assoc] rw [← unop_comp_assoc] erw [← NatTrans.naturality] rfl /-- The bijection `ShiftedHom X Y a' ≃ (Opposite.op (Y⟦a⟧) ⟶ (Opposite.op X)⟦n⟧)` when integers `n`, `a` and `a'` satisfy `n + a = a'`, and `X` and `Y` are objects of a category equipped with a shift by `ℤ`. -/ noncomputable def opEquiv' (n a a' : ℤ) (h : n + a = a') : ShiftedHom X Y a' ≃ (Opposite.op (Y⟦a⟧) ⟶ (Opposite.op X)⟦n⟧) := ((shiftFunctorAdd' C a n a' (by cutsat)).symm.app Y).homToEquiv.symm.trans (opEquiv n) lemma opEquiv'_symm_apply {n a : ℤ} (f : Opposite.op (Y⟦a⟧) ⟶ (Opposite.op X)⟦n⟧) (a' : ℤ) (h : n + a = a') : (opEquiv' n a a' h).symm f = (opEquiv n).symm f ≫ (shiftFunctorAdd' C a n a' (by cutsat)).inv.app _ := rfl lemma opEquiv'_apply {a' : ℤ} (f : ShiftedHom X Y a') (n a : ℤ) (h : n + a = a') : opEquiv' n a a' h f = opEquiv n (f ≫ (shiftFunctorAdd' C a n a' (by cutsat)).hom.app Y) := by rfl lemma opEquiv'_symm_op_opShiftFunctorEquivalence_counitIso_inv_app_op_shift {n m : ℤ} (f : ShiftedHom X Y n) (g : ShiftedHom Y Z m) (q : ℤ) (hq : n + m = q) : (opEquiv' n m q hq).symm (g.op ≫ (opShiftFunctorEquivalence C n).counitIso.inv.app _ ≫ f.op⟦n⟧') = f.comp g (by cutsat) := by rw [opEquiv'_symm_apply, opEquiv_symm_apply] dsimp [comp] apply Quiver.Hom.op_inj simp only [assoc, Functor.map_comp, op_comp, Quiver.Hom.op_unop, opShiftFunctorEquivalence_unitIso_inv_naturality] erw [(opShiftFunctorEquivalence C n).inverse_counitInv_comp_assoc (Opposite.op Y)] lemma opEquiv'_symm_comp (f : Y ⟶ X) {n a : ℤ} (x : Opposite.op (Z⟦a⟧) ⟶ (Opposite.op X⟦n⟧)) (a' : ℤ) (h : n + a = a') : (opEquiv' n a a' h).symm (x ≫ f.op⟦n⟧') = f ≫ (opEquiv' n a a' h).symm x := Quiver.Hom.op_inj (by simp [opEquiv'_symm_apply, opEquiv_symm_apply]) lemma opEquiv'_zero_add_symm (a : ℤ) (f : Opposite.op (Y⟦a⟧) ⟶ (Opposite.op X)⟦(0 : ℤ)⟧) : (opEquiv' 0 a a (zero_add a)).symm f = ((shiftFunctorZero Cᵒᵖ ℤ).hom.app _).unop ≫ f.unop := by simp [opEquiv'_symm_apply, opEquiv_symm_apply, shiftFunctorAdd'_add_zero, opShiftFunctorEquivalence_zero_unitIso_inv_app] lemma opEquiv'_add_symm (n m a a' a'' : ℤ) (ha' : n + a = a') (ha'' : m + a' = a'') (x : (Opposite.op (Y⟦a⟧) ⟶ (Opposite.op X)⟦m + n⟧)) : (opEquiv' (m + n) a a'' (by cutsat)).symm x = (opEquiv' m a' a'' ha'').symm ((opEquiv' n a a' ha').symm (x ≫ (shiftFunctorAdd Cᵒᵖ m n).hom.app _)).op := by simp only [opEquiv'_symm_apply, opEquiv_symm_apply, opShiftFunctorEquivalence_unitIso_inv_app_eq _ _ _ _ (add_comm n m)] dsimp simp only [assoc, Functor.map_comp, ← shiftFunctorAdd'_eq_shiftFunctorAdd, ← NatTrans.naturality_assoc, shiftFunctorAdd'_assoc_inv_app a n m a' (m + n) a'' (by cutsat) (by cutsat) (by cutsat)] rfl section Preadditive variable [Preadditive C] [∀ (n : ℤ), (shiftFunctor C n).Additive] @[simp] lemma opEquiv_symm_add {n : ℤ} (x y : ShiftedHom (Opposite.op Y) (Opposite.op X) n) : (opEquiv n).symm (x + y) = (opEquiv n).symm x + (opEquiv n).symm y := by dsimp [opEquiv_symm_apply] rw [← Preadditive.comp_add, ← Functor.map_add] rfl @[simp] lemma opEquiv'_symm_add {n a : ℤ} (x y : (Opposite.op (Y⟦a⟧) ⟶ (Opposite.op X)⟦n⟧)) (a' : ℤ) (h : n + a = a') : (opEquiv' n a a' h).symm (x + y) = (opEquiv' n a a' h).symm x + (opEquiv' n a a' h).symm y := by dsimp [opEquiv'] erw [opEquiv_symm_add, Iso.homToEquiv_apply, Iso.homToEquiv_apply, Iso.homToEquiv_apply] rw [Preadditive.add_comp] rfl end Preadditive end ShiftedHom end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/SingleFunctors.lean
import Mathlib.CategoryTheory.Shift.CommShift /-! # Functors from a category to a category with a shift Given a category `C`, and a category `D` equipped with a shift by a monoid `A`, we define a structure `SingleFunctors C D A` which contains the data of functors `functor a : C ⥤ D` for all `a : A` and isomorphisms `shiftIso n a a' h : functor a' ⋙ shiftFunctor D n ≅ functor a` whenever `n + a = a'`. These isomorphisms should satisfy certain compatibilities with respect to the shift on `D`. This notion is similar to `Functor.ShiftSequence` which can be used in order to attach shifted versions of a homological functor `D ⥤ C` with `D` a triangulated category and `C` an abelian category. However, the definition `SingleFunctors` is for functors in the other direction: it is meant to ease the formalization of the compatibilities with shifts of the functors `C ⥤ CochainComplex C ℤ` (or `C ⥤ DerivedCategory C` (TODO)) which sends an object `X : C` to a complex where `X` sits in a single degree. -/ open CategoryTheory Category ZeroObject Limits Functor variable (C D E E' : Type*) [Category C] [Category D] [Category E] [Category E'] (A : Type*) [AddMonoid A] [HasShift D A] [HasShift E A] [HasShift E' A] namespace CategoryTheory /-- The type of families of functors `A → C ⥤ D` which are compatible with the shift by `A` on the category `D`. -/ structure SingleFunctors where /-- a family of functors `C ⥤ D` indexed by the elements of the additive monoid `A` -/ functor (a : A) : C ⥤ D /-- the isomorphism `functor a' ⋙ shiftFunctor D n ≅ functor a` when `n + a = a'` -/ shiftIso (n a a' : A) (ha' : n + a = a') : functor a' ⋙ shiftFunctor D n ≅ functor a /-- `shiftIso 0` is the obvious isomorphism. -/ shiftIso_zero (a : A) : shiftIso 0 a a (zero_add a) = isoWhiskerLeft _ (shiftFunctorZero D A) /-- `shiftIso (m + n)` is determined by `shiftIso m` and `shiftIso n`. -/ shiftIso_add (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') : shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerLeft _ (shiftFunctorAdd D m n) ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (shiftIso m a' a'' ha'') _ ≪≫ shiftIso n a a' ha' variable {C D E A} variable (F G H : SingleFunctors C D A) namespace SingleFunctors lemma shiftIso_add_hom_app (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X = (shiftFunctorAdd D m n).hom.app ((F.functor a'').obj X) ≫ ((F.shiftIso m a' a'' ha'').hom.app X)⟦n⟧' ≫ (F.shiftIso n a a' ha').hom.app X := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add_inv_app (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).inv.app X = (F.shiftIso n a a' ha').inv.app X ≫ ((F.shiftIso m a' a'' ha'').inv.app X)⟦n⟧' ≫ (shiftFunctorAdd D m n).inv.app ((F.functor a'').obj X) := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add' (n m mn : A) (hnm : m + n = mn) (a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc]) = isoWhiskerLeft _ (shiftFunctorAdd' D m n mn hnm) ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (F.shiftIso m a' a'' ha'') _ ≪≫ F.shiftIso n a a' ha' := by subst hnm rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftIso_add] lemma shiftIso_add'_hom_app (n m mn : A) (hnm : m + n = mn) (a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X = (shiftFunctorAdd' D m n mn hnm).hom.app ((F.functor a'').obj X) ≫ ((F.shiftIso m a' a'' ha'').hom.app X)⟦n⟧' ≫ (F.shiftIso n a a' ha').hom.app X := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] lemma shiftIso_add'_inv_app (n m mn : A) (hnm : m + n = mn) (a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).inv.app X = (F.shiftIso n a a' ha').inv.app X ≫ ((F.shiftIso m a' a'' ha'').inv.app X)⟦n⟧' ≫ (shiftFunctorAdd' D m n mn hnm).inv.app ((F.functor a'').obj X) := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] @[simp] lemma shiftIso_zero_hom_app (a : A) (X : C) : (F.shiftIso 0 a a (zero_add a)).hom.app X = (shiftFunctorZero D A).hom.app _ := by rw [shiftIso_zero] rfl @[simp] lemma shiftIso_zero_inv_app (a : A) (X : C) : (F.shiftIso 0 a a (zero_add a)).inv.app X = (shiftFunctorZero D A).inv.app _ := by rw [shiftIso_zero] rfl /-- The morphisms in the category `SingleFunctors C D A` -/ @[ext] structure Hom where /-- a family of natural transformations `F.functor a ⟶ G.functor a` -/ hom (a : A) : F.functor a ⟶ G.functor a comm (n a a' : A) (ha' : n + a = a') : (F.shiftIso n a a' ha').hom ≫ hom a = whiskerRight (hom a') (shiftFunctor D n) ≫ (G.shiftIso n a a' ha').hom := by cat_disch namespace Hom attribute [reassoc] comm attribute [local simp] comm comm_assoc /-- The identity morphism in `SingleFunctors C D A`. -/ @[simps] def id : Hom F F where hom _ := 𝟙 _ variable {F G H} /-- The composition of morphisms in `SingleFunctors C D A`. -/ @[simps] def comp (α : Hom F G) (β : Hom G H) : Hom F H where hom a := α.hom a ≫ β.hom a end Hom instance : Category (SingleFunctors C D A) where Hom := Hom id := Hom.id comp := Hom.comp @[simp] lemma id_hom (a : A) : Hom.hom (𝟙 F) a = 𝟙 _ := rfl variable {F G H} @[simp, reassoc] lemma comp_hom (f : F ⟶ G) (g : G ⟶ H) (a : A) : (f ≫ g).hom a = f.hom a ≫ g.hom a := rfl @[ext] lemma hom_ext (f g : F ⟶ G) (h : f.hom = g.hom) : f = g := Hom.ext h /-- Construct an isomorphism in `SingleFunctors C D A` by giving level-wise isomorphisms and checking compatibility only in the forward direction. -/ @[simps] def isoMk (iso : ∀ a, (F.functor a ≅ G.functor a)) (comm : ∀ (n a a' : A) (ha' : n + a = a'), (F.shiftIso n a a' ha').hom ≫ (iso a).hom = whiskerRight (iso a').hom (shiftFunctor D n) ≫ (G.shiftIso n a a' ha').hom) : F ≅ G where hom := { hom := fun a => (iso a).hom comm := comm } inv := { hom := fun a => (iso a).inv comm := fun n a a' ha' => by rw [← cancel_mono (iso a).hom, assoc, assoc, Iso.inv_hom_id, comp_id, comm, ← whiskerRight_comp_assoc, Iso.inv_hom_id, whiskerRight_id', id_comp] } variable (C D) /-- The evaluation `SingleFunctors C D A ⥤ C ⥤ D` for some `a : A`. -/ @[simps] def evaluation (a : A) : SingleFunctors C D A ⥤ C ⥤ D where obj F := F.functor a map {_ _} φ := φ.hom a variable {C D} @[reassoc (attr := simp)] lemma hom_inv_id_hom (e : F ≅ G) (n : A) : e.hom.hom n ≫ e.inv.hom n = 𝟙 _ := by rw [← comp_hom, e.hom_inv_id, id_hom] @[reassoc (attr := simp)] lemma inv_hom_id_hom (e : F ≅ G) (n : A) : e.inv.hom n ≫ e.hom.hom n = 𝟙 _ := by rw [← comp_hom, e.inv_hom_id, id_hom] @[reassoc (attr := simp)] lemma hom_inv_id_hom_app (e : F ≅ G) (n : A) (X : C) : (e.hom.hom n).app X ≫ (e.inv.hom n).app X = 𝟙 _ := by rw [← NatTrans.comp_app, hom_inv_id_hom, NatTrans.id_app] @[reassoc (attr := simp)] lemma inv_hom_id_hom_app (e : F ≅ G) (n : A) (X : C) : (e.inv.hom n).app X ≫ (e.hom.hom n).app X = 𝟙 _ := by rw [← NatTrans.comp_app, inv_hom_id_hom, NatTrans.id_app] instance (f : F ⟶ G) [IsIso f] (n : A) : IsIso (f.hom n) := (inferInstance : IsIso ((evaluation C D n).map f)) variable (F) /-- Given `F : SingleFunctors C D A`, and a functor `G : D ⥤ E` which commutes with the shift by `A`, this is the "composition" of `F` and `G` in `SingleFunctors C E A`. -/ @[simps! functor shiftIso_hom_app shiftIso_inv_app] def postcomp (G : D ⥤ E) [G.CommShift A] : SingleFunctors C E A where functor a := F.functor a ⋙ G shiftIso n a a' ha' := Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (G.commShiftIso n).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (F.shiftIso n a a' ha') G shiftIso_zero a := by ext X dsimp simp only [Functor.commShiftIso_zero, Functor.CommShift.isoZero_inv_app, SingleFunctors.shiftIso_zero_hom_app,id_comp, assoc, ← G.map_comp, Iso.inv_hom_id_app, Functor.map_id, Functor.id_obj, comp_id] shiftIso_add n m a a' a'' ha' ha'' := by ext X dsimp simp only [F.shiftIso_add_hom_app n m a a' a'' ha' ha'', Functor.commShiftIso_add, Functor.CommShift.isoAdd_inv_app, Functor.map_comp, id_comp, assoc, Functor.commShiftIso_inv_naturality_assoc] simp only [← G.map_comp, Iso.inv_hom_id_app_assoc] variable (C A) /-- The functor `SingleFunctors C D A ⥤ SingleFunctors C E A` given by the postcomposition by a functor `G : D ⥤ E` which commutes with the shift. -/ @[simps] def postcompFunctor (G : D ⥤ E) [G.CommShift A] : SingleFunctors C D A ⥤ SingleFunctors C E A where obj F := F.postcomp G map {F₁ F₂} φ := { hom := fun a => whiskerRight (φ.hom a) G comm := fun n a a' ha' => by ext X simpa using G.congr_map (congr_app (φ.comm n a a' ha') X) } variable {C E' A} /-- The canonical isomorphism `(F.postcomp G).postcomp G' ≅ F.postcomp (G ⋙ G')`. -/ @[simps!] def postcompPostcompIso (G : D ⥤ E) (G' : E ⥤ E') [G.CommShift A] [G'.CommShift A] : (F.postcomp G).postcomp G' ≅ F.postcomp (G ⋙ G') := isoMk (fun _ => Functor.associator _ _ _) (fun n a a' ha' => by ext X simp [Functor.commShiftIso_comp_inv_app]) /-- The isomorphism `F.postcomp G ≅ F.postcomp G'` induced by an isomorphism `e : G ≅ G'` which commutes with the shift. -/ @[simps!] def postcompIsoOfIso {G G' : D ⥤ E} (e : G ≅ G') [G.CommShift A] [G'.CommShift A] [NatTrans.CommShift e.hom A] : F.postcomp G ≅ F.postcomp G' := isoMk (fun a => isoWhiskerLeft (F.functor a) e) (fun n a a' ha' => by ext X simp [NatTrans.shift_app e.hom n]) end SingleFunctors end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Linear.lean
import Mathlib.CategoryTheory.Shift.CommShift import Mathlib.CategoryTheory.Localization.Linear /-! # Localization of the linearity of the shift functors If `L : C ⥤ D` is a localization functor with respect to `W : MorphismProperty C` and both `C` and `D` have been equipped with `R`-linear category structures such that `L` is `R`-linear and the shift functors on `C` are `R`-linear, then the shift functors on `D` are `R`-linear. -/ namespace CategoryTheory namespace Shift variable (R : Type*) [Ring R] {C : Type _} [Category C] [Preadditive C] [Linear R C] {D : Type*} [Category D] [Preadditive D] [Linear R D] {M : Type*} [AddMonoid M] [HasShift C M] [∀ (n : M), (shiftFunctor C n).Linear R] (L : C ⥤ D) (W : MorphismProperty C) lemma linear_of_localization [L.IsLocalization W] [L.Linear R] [HasShift D M] [L.CommShift M] (n : M) : (shiftFunctor D n).Linear R := by have : Localization.Lifting L W (shiftFunctor C n ⋙ L) (shiftFunctor D n) := ⟨(L.commShiftIso n).symm⟩ rw [← Localization.functor_linear_iff L W R (shiftFunctor C n ⋙ L) (shiftFunctor D n)] infer_instance instance [HasShift W.Localization M] [W.Q.CommShift M] [Preadditive W.Localization] [Linear R W.Localization] [W.Q.Linear R] (n : M) : (shiftFunctor W.Localization n).Linear R := linear_of_localization _ W.Q W _ instance (n : M) [W.HasLocalization] [HasShift W.Localization' M] [W.Q'.CommShift M] [Preadditive W.Localization'] [Linear R W.Localization'] [W.Q'.Linear R] : (shiftFunctor W.Localization' n).Linear R := linear_of_localization _ W.Q' W _ end Shift end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Basic.lean
import Mathlib.Algebra.Group.Basic import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero import Mathlib.CategoryTheory.Monoidal.End import Mathlib.CategoryTheory.Monoidal.Discrete /-! # Shift A `Shift` on a category `C` indexed by a monoid `A` is nothing more than a monoidal functor from `A` to `C ⥤ C`. A typical example to keep in mind might be the category of complexes `⋯ → C_{n-1} → C_n → C_{n+1} → ⋯`. It has a shift indexed by `ℤ`, where we assign to each `n : ℤ` the functor `C ⥤ C` that re-indexes the terms, so the degree `i` term of `Shift n C` would be the degree `i+n`-th term of `C`. ## Main definitions * `HasShift`: A typeclass asserting the existence of a shift functor. * `shiftEquiv`: When the indexing monoid is a group, then the functor indexed by `n` and `-n` forms a self-equivalence of `C`. * `shiftComm`: When the indexing monoid is commutative, then shifts commute as well. ## Implementation Notes `[HasShift C A]` is implemented using monoidal functors from `Discrete A` to `C ⥤ C`. However, the API of monoidal functors is used only internally: one should use the API of shifts functors which includes `shiftFunctor C a : C ⥤ C` for `a : A`, `shiftFunctorZero C A : shiftFunctor C (0 : A) ≅ 𝟭 C` and `shiftFunctorAdd C i j : shiftFunctor C (i + j) ≅ shiftFunctor C i ⋙ shiftFunctor C j` (and its variant `shiftFunctorAdd'`). These isomorphisms satisfy some coherence properties which are stated in lemmas like `shiftFunctorAdd'_assoc`, `shiftFunctorAdd'_zero_add` and `shiftFunctorAdd'_add_zero`. -/ namespace CategoryTheory open Functor noncomputable section universe v u variable (C : Type u) (A : Type*) [Category.{v} C] attribute [local instance] endofunctorMonoidalCategory variable {A C} section Defs variable (A C) [AddMonoid A] /-- A category has a shift indexed by an additive monoid `A` if there is a monoidal functor from `A` to `C ⥤ C`. -/ class HasShift (C : Type u) (A : Type*) [Category.{v} C] [AddMonoid A] where /-- a shift is a monoidal functor from `A` to `C ⥤ C` -/ shift : Discrete A ⥤ C ⥤ C /-- `shift` is monoidal -/ shiftMonoidal : shift.Monoidal := by infer_instance /-- A helper structure to construct the shift functor `(Discrete A) ⥤ (C ⥤ C)`. -/ structure ShiftMkCore where /-- the family of shift functors -/ F : A → C ⥤ C /-- the shift by 0 identifies to the identity functor -/ zero : F 0 ≅ 𝟭 C /-- the composition of shift functors identifies to the shift by the sum -/ add : ∀ n m : A, F (n + m) ≅ F n ⋙ F m /-- compatibility with the associativity -/ assoc_hom_app : ∀ (m₁ m₂ m₃ : A) (X : C), (add (m₁ + m₂) m₃).hom.app X ≫ (F m₃).map ((add m₁ m₂).hom.app X) = eqToHom (by rw [add_assoc]) ≫ (add m₁ (m₂ + m₃)).hom.app X ≫ (add m₂ m₃).hom.app ((F m₁).obj X) := by cat_disch /-- compatibility with the left addition with 0 -/ zero_add_hom_app : ∀ (n : A) (X : C), (add 0 n).hom.app X = eqToHom (by dsimp; rw [zero_add]) ≫ (F n).map (zero.inv.app X) := by cat_disch /-- compatibility with the right addition with 0 -/ add_zero_hom_app : ∀ (n : A) (X : C), (add n 0).hom.app X = eqToHom (by dsimp; rw [add_zero]) ≫ zero.inv.app ((F n).obj X) := by cat_disch namespace ShiftMkCore variable {C A} attribute [reassoc] assoc_hom_app @[reassoc] lemma assoc_inv_app (h : ShiftMkCore C A) (m₁ m₂ m₃ : A) (X : C) : (h.F m₃).map ((h.add m₁ m₂).inv.app X) ≫ (h.add (m₁ + m₂) m₃).inv.app X = (h.add m₂ m₃).inv.app ((h.F m₁).obj X) ≫ (h.add m₁ (m₂ + m₃)).inv.app X ≫ eqToHom (by rw [add_assoc]) := by rw [← cancel_mono ((h.add (m₁ + m₂) m₃).hom.app X ≫ (h.F m₃).map ((h.add m₁ m₂).hom.app X)), Category.assoc, Category.assoc, Category.assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id, h.assoc_hom_app, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app] rfl lemma zero_add_inv_app (h : ShiftMkCore C A) (n : A) (X : C) : (h.add 0 n).inv.app X = (h.F n).map (h.zero.hom.app X) ≫ eqToHom (by dsimp; rw [zero_add]) := by rw [← cancel_epi ((h.add 0 n).hom.app X), Iso.hom_inv_id_app, h.zero_add_hom_app, Category.assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, Category.id_comp, eqToHom_trans, eqToHom_refl] lemma add_zero_inv_app (h : ShiftMkCore C A) (n : A) (X : C) : (h.add n 0).inv.app X = h.zero.hom.app ((h.F n).obj X) ≫ eqToHom (by dsimp; rw [add_zero]) := by rw [← cancel_epi ((h.add n 0).hom.app X), Iso.hom_inv_id_app, h.add_zero_hom_app, Category.assoc, Iso.inv_hom_id_app_assoc, eqToHom_trans, eqToHom_refl] end ShiftMkCore section attribute [local simp] eqToHom_map instance (h : ShiftMkCore C A) : (Discrete.functor h.F).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := h.zero.symm μIso := fun m n ↦ (h.add m.as n.as).symm μIso_hom_natural_left := by rintro ⟨X⟩ ⟨Y⟩ ⟨⟨⟨rfl⟩⟩⟩ ⟨X'⟩ ext simp μIso_hom_natural_right := by rintro ⟨X⟩ ⟨Y⟩ ⟨X'⟩ ⟨⟨⟨rfl⟩⟩⟩ ext simp associativity := by rintro ⟨m₁⟩ ⟨m₂⟩ ⟨m₃⟩ ext X simp [endofunctorMonoidalCategory, h.assoc_inv_app_assoc] left_unitality := by rintro ⟨n⟩ ext X simp [endofunctorMonoidalCategory, h.zero_add_inv_app, ← Functor.map_comp] right_unitality := by rintro ⟨n⟩ ext X simp [endofunctorMonoidalCategory, h.add_zero_inv_app] } /-- Constructs a `HasShift C A` instance from `ShiftMkCore`. -/ def hasShiftMk (h : ShiftMkCore C A) : HasShift C A where shift := Discrete.functor h.F end section variable [HasShift C A] /-- The monoidal functor from `A` to `C ⥤ C` given a `HasShift` instance. -/ def shiftMonoidalFunctor : Discrete A ⥤ C ⥤ C := HasShift.shift instance : (shiftMonoidalFunctor C A).Monoidal := HasShift.shiftMonoidal variable {A} open Functor.Monoidal /-- The shift autoequivalence, moving objects and morphisms 'up'. -/ def shiftFunctor (i : A) : C ⥤ C := (shiftMonoidalFunctor C A).obj ⟨i⟩ /-- Shifting by `i + j` is the same as shifting by `i` and then shifting by `j`. -/ def shiftFunctorAdd (i j : A) : shiftFunctor C (i + j) ≅ shiftFunctor C i ⋙ shiftFunctor C j := (μIso (shiftMonoidalFunctor C A) ⟨i⟩ ⟨j⟩).symm /-- When `k = i + j`, shifting by `k` is the same as shifting by `i` and then shifting by `j`. -/ def shiftFunctorAdd' (i j k : A) (h : i + j = k) : shiftFunctor C k ≅ shiftFunctor C i ⋙ shiftFunctor C j := eqToIso (by rw [h]) ≪≫ shiftFunctorAdd C i j lemma shiftFunctorAdd'_eq_shiftFunctorAdd (i j : A) : shiftFunctorAdd' C i j (i+j) rfl = shiftFunctorAdd C i j := by ext1 apply Category.id_comp variable (A) in /-- Shifting by zero is the identity functor. -/ def shiftFunctorZero : shiftFunctor C (0 : A) ≅ 𝟭 C := (εIso (shiftMonoidalFunctor C A)).symm /-- Shifting by `a` such that `a = 0` identifies to the identity functor. -/ def shiftFunctorZero' (a : A) (ha : a = 0) : shiftFunctor C a ≅ 𝟭 C := eqToIso (by rw [ha]) ≪≫ shiftFunctorZero C A end variable {C A} lemma ShiftMkCore.shiftFunctor_eq (h : ShiftMkCore C A) (a : A) : letI := hasShiftMk C A h shiftFunctor C a = h.F a := rfl lemma ShiftMkCore.shiftFunctorZero_eq (h : ShiftMkCore C A) : letI := hasShiftMk C A h shiftFunctorZero C A = h.zero := rfl lemma ShiftMkCore.shiftFunctorAdd_eq (h : ShiftMkCore C A) (a b : A) : letI := hasShiftMk C A h shiftFunctorAdd C a b = h.add a b := rfl set_option quotPrecheck false in /-- shifting an object `X` by `n` is obtained by the notation `X⟦n⟧` -/ notation -- Any better notational suggestions? X "⟦" n "⟧" => (shiftFunctor _ n).obj X set_option quotPrecheck false in /-- shifting a morphism `f` by `n` is obtained by the notation `f⟦n⟧'` -/ notation f "⟦" n "⟧'" => (shiftFunctor _ n).map f variable (C) variable [HasShift C A] lemma shiftFunctorAdd'_zero_add (a : A) : shiftFunctorAdd' C 0 a a (zero_add a) = (leftUnitor _).symm ≪≫ isoWhiskerRight (shiftFunctorZero C A).symm (shiftFunctor C a) := by ext X dsimp [shiftFunctorAdd', shiftFunctorZero, shiftFunctor] simp only [eqToHom_app, obj_ε_app, Discrete.addMonoidal_leftUnitor, eqToIso.inv, eqToHom_map, Category.id_comp] rfl lemma shiftFunctorAdd'_add_zero (a : A) : shiftFunctorAdd' C a 0 a (add_zero a) = (rightUnitor _).symm ≪≫ isoWhiskerLeft (shiftFunctor C a) (shiftFunctorZero C A).symm := by ext dsimp [shiftFunctorAdd', shiftFunctorZero, shiftFunctor] simp only [eqToHom_app, ε_app_obj, Discrete.addMonoidal_rightUnitor, eqToIso.inv, eqToHom_map, Category.id_comp] rfl lemma shiftFunctorAdd'_assoc (a₁ a₂ a₃ a₁₂ a₂₃ a₁₂₃ : A) (h₁₂ : a₁ + a₂ = a₁₂) (h₂₃ : a₂ + a₃ = a₂₃) (h₁₂₃ : a₁ + a₂ + a₃ = a₁₂₃) : shiftFunctorAdd' C a₁₂ a₃ a₁₂₃ (by rw [← h₁₂, h₁₂₃]) ≪≫ isoWhiskerRight (shiftFunctorAdd' C a₁ a₂ a₁₂ h₁₂) _ ≪≫ associator _ _ _ = shiftFunctorAdd' C a₁ a₂₃ a₁₂₃ (by rw [← h₂₃, ← add_assoc, h₁₂₃]) ≪≫ isoWhiskerLeft _ (shiftFunctorAdd' C a₂ a₃ a₂₃ h₂₃) := by subst h₁₂ h₂₃ h₁₂₃ ext X dsimp simp only [shiftFunctorAdd'_eq_shiftFunctorAdd, Category.comp_id] dsimp [shiftFunctorAdd'] simp only [eqToHom_app] dsimp [shiftFunctorAdd, shiftFunctor] simp only [obj_μ_inv_app, Discrete.addMonoidal_associator, eqToIso.hom, eqToHom_map, eqToHom_app] erw [δ_μ_app_assoc, Category.assoc] rfl lemma shiftFunctorAdd_assoc (a₁ a₂ a₃ : A) : shiftFunctorAdd C (a₁ + a₂) a₃ ≪≫ isoWhiskerRight (shiftFunctorAdd C a₁ a₂) _ ≪≫ associator _ _ _ = shiftFunctorAdd' C a₁ (a₂ + a₃) _ (add_assoc a₁ a₂ a₃).symm ≪≫ isoWhiskerLeft _ (shiftFunctorAdd C a₂ a₃) := by ext X simpa [shiftFunctorAdd'_eq_shiftFunctorAdd] using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_assoc C a₁ a₂ a₃ _ _ _ rfl rfl rfl)) X variable {C} lemma shiftFunctorAdd'_zero_add_hom_app (a : A) (X : C) : (shiftFunctorAdd' C 0 a a (zero_add a)).hom.app X = ((shiftFunctorZero C A).inv.app X)⟦a⟧' := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_zero_add C a)) X lemma shiftFunctorAdd_zero_add_hom_app (a : A) (X : C) : (shiftFunctorAdd C 0 a).hom.app X = eqToHom (by dsimp; rw [zero_add]) ≫ ((shiftFunctorZero C A).inv.app X)⟦a⟧' := by simp [← shiftFunctorAdd'_zero_add_hom_app, shiftFunctorAdd'] lemma shiftFunctorAdd'_zero_add_inv_app (a : A) (X : C) : (shiftFunctorAdd' C 0 a a (zero_add a)).inv.app X = ((shiftFunctorZero C A).hom.app X)⟦a⟧' := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd'_zero_add C a)) X lemma shiftFunctorAdd_zero_add_inv_app (a : A) (X : C) : (shiftFunctorAdd C 0 a).inv.app X = ((shiftFunctorZero C A).hom.app X)⟦a⟧' ≫ eqToHom (by dsimp; rw [zero_add]) := by simp [← shiftFunctorAdd'_zero_add_inv_app, shiftFunctorAdd'] lemma shiftFunctorAdd'_add_zero_hom_app (a : A) (X : C) : (shiftFunctorAdd' C a 0 a (add_zero a)).hom.app X = (shiftFunctorZero C A).inv.app (X⟦a⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_add_zero C a)) X lemma shiftFunctorAdd_add_zero_hom_app (a : A) (X : C) : (shiftFunctorAdd C a 0).hom.app X = eqToHom (by dsimp; rw [add_zero]) ≫ (shiftFunctorZero C A).inv.app (X⟦a⟧) := by simp [← shiftFunctorAdd'_add_zero_hom_app, shiftFunctorAdd'] lemma shiftFunctorAdd'_add_zero_inv_app (a : A) (X : C) : (shiftFunctorAdd' C a 0 a (add_zero a)).inv.app X = (shiftFunctorZero C A).hom.app (X⟦a⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd'_add_zero C a)) X lemma shiftFunctorAdd_add_zero_inv_app (a : A) (X : C) : (shiftFunctorAdd C a 0).inv.app X = (shiftFunctorZero C A).hom.app (X⟦a⟧) ≫ eqToHom (by dsimp; rw [add_zero]) := by simp [← shiftFunctorAdd'_add_zero_inv_app, shiftFunctorAdd'] @[reassoc] lemma shiftFunctorAdd'_assoc_hom_app (a₁ a₂ a₃ a₁₂ a₂₃ a₁₂₃ : A) (h₁₂ : a₁ + a₂ = a₁₂) (h₂₃ : a₂ + a₃ = a₂₃) (h₁₂₃ : a₁ + a₂ + a₃ = a₁₂₃) (X : C) : (shiftFunctorAdd' C a₁₂ a₃ a₁₂₃ (by rw [← h₁₂, h₁₂₃])).hom.app X ≫ ((shiftFunctorAdd' C a₁ a₂ a₁₂ h₁₂).hom.app X)⟦a₃⟧' = (shiftFunctorAdd' C a₁ a₂₃ a₁₂₃ (by rw [← h₂₃, ← add_assoc, h₁₂₃])).hom.app X ≫ (shiftFunctorAdd' C a₂ a₃ a₂₃ h₂₃).hom.app (X⟦a₁⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_assoc C _ _ _ _ _ _ h₁₂ h₂₃ h₁₂₃)) X @[reassoc] lemma shiftFunctorAdd'_assoc_inv_app (a₁ a₂ a₃ a₁₂ a₂₃ a₁₂₃ : A) (h₁₂ : a₁ + a₂ = a₁₂) (h₂₃ : a₂ + a₃ = a₂₃) (h₁₂₃ : a₁ + a₂ + a₃ = a₁₂₃) (X : C) : ((shiftFunctorAdd' C a₁ a₂ a₁₂ h₁₂).inv.app X)⟦a₃⟧' ≫ (shiftFunctorAdd' C a₁₂ a₃ a₁₂₃ (by rw [← h₁₂, h₁₂₃])).inv.app X = (shiftFunctorAdd' C a₂ a₃ a₂₃ h₂₃).inv.app (X⟦a₁⟧) ≫ (shiftFunctorAdd' C a₁ a₂₃ a₁₂₃ (by rw [← h₂₃, ← add_assoc, h₁₂₃])).inv.app X := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd'_assoc C _ _ _ _ _ _ h₁₂ h₂₃ h₁₂₃)) X @[reassoc] lemma shiftFunctorAdd_assoc_hom_app (a₁ a₂ a₃ : A) (X : C) : (shiftFunctorAdd C (a₁ + a₂) a₃).hom.app X ≫ ((shiftFunctorAdd C a₁ a₂).hom.app X)⟦a₃⟧' = (shiftFunctorAdd' C a₁ (a₂ + a₃) (a₁ + a₂ + a₃) (add_assoc _ _ _).symm).hom.app X ≫ (shiftFunctorAdd C a₂ a₃).hom.app (X⟦a₁⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd_assoc C a₁ a₂ a₃)) X @[reassoc] lemma shiftFunctorAdd_assoc_inv_app (a₁ a₂ a₃ : A) (X : C) : ((shiftFunctorAdd C a₁ a₂).inv.app X)⟦a₃⟧' ≫ (shiftFunctorAdd C (a₁ + a₂) a₃).inv.app X = (shiftFunctorAdd C a₂ a₃).inv.app (X⟦a₁⟧) ≫ (shiftFunctorAdd' C a₁ (a₂ + a₃) (a₁ + a₂ + a₃) (add_assoc _ _ _).symm).inv.app X := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd_assoc C a₁ a₂ a₃)) X end Defs section AddMonoid variable [AddMonoid A] [HasShift C A] (X Y : C) (f : X ⟶ Y) --@[simp] --theorem HasShift.shift_obj_obj (n : A) (X : C) : (HasShift.shift.obj ⟨n⟩).obj X = X⟦n⟧ := -- rfl /-- Shifting by `i + j` is the same as shifting by `i` and then shifting by `j`. -/ abbrev shiftAdd (i j : A) : X⟦i + j⟧ ≅ X⟦i⟧⟦j⟧ := (shiftFunctorAdd C i j).app _ theorem shift_shift' (i j : A) : f⟦i⟧'⟦j⟧' = (shiftAdd X i j).inv ≫ f⟦i + j⟧' ≫ (shiftAdd Y i j).hom := by simp variable (A) /-- Shifting by zero is the identity functor. -/ abbrev shiftZero : X⟦(0 : A)⟧ ≅ X := (shiftFunctorZero C A).app _ theorem shiftZero' : f⟦(0 : A)⟧' = (shiftZero A X).hom ≫ f ≫ (shiftZero A Y).inv := by symm rw [Iso.app_inv, Iso.app_hom] apply NatIso.naturality_2 variable (C) {A} /-- When `i + j = 0`, shifting by `i` and by `j` gives the identity functor -/ def shiftFunctorCompIsoId (i j : A) (h : i + j = 0) : shiftFunctor C i ⋙ shiftFunctor C j ≅ 𝟭 C := (shiftFunctorAdd' C i j 0 h).symm ≪≫ shiftFunctorZero C A end AddMonoid section AddGroup variable (C) variable [AddGroup A] [HasShift C A] /-- Shifting by `i` and shifting by `j` forms an equivalence when `i + j = 0`. -/ @[simps] def shiftEquiv' (i j : A) (h : i + j = 0) : C ≌ C where functor := shiftFunctor C i inverse := shiftFunctor C j unitIso := (shiftFunctorCompIsoId C i j h).symm counitIso := shiftFunctorCompIsoId C j i (by rw [← add_left_inj j, add_assoc, h, zero_add, add_zero]) functor_unitIso_comp X := by convert (equivOfTensorIsoUnit (shiftMonoidalFunctor C A) ⟨i⟩ ⟨j⟩ (Discrete.eqToIso h) (Discrete.eqToIso (by dsimp; rw [← add_left_inj j, add_assoc, h, zero_add, add_zero])) (Subsingleton.elim _ _)).functor_unitIso_comp X all_goals ext X dsimp [shiftFunctorCompIsoId, unitOfTensorIsoUnit, shiftFunctorAdd'] simp only [Category.assoc, eqToHom_map] rfl /-- Shifting by `n` and shifting by `-n` forms an equivalence. -/ abbrev shiftEquiv (n : A) : C ≌ C := shiftEquiv' C n (-n) (add_neg_cancel n) variable (X Y : C) (f : X ⟶ Y) /-- Shifting by `i` is an equivalence. -/ instance (i : A) : (shiftFunctor C i).IsEquivalence := by change (shiftEquiv C i).functor.IsEquivalence infer_instance variable {C} /-- Shifting by `i` and then shifting by `-i` is the identity. -/ abbrev shiftShiftNeg (i : A) : X⟦i⟧⟦-i⟧ ≅ X := (shiftEquiv C i).unitIso.symm.app X /-- Shifting by `-i` and then shifting by `i` is the identity. -/ abbrev shiftNegShift (i : A) : X⟦-i⟧⟦i⟧ ≅ X := (shiftEquiv C i).counitIso.app X variable {X Y} theorem shift_shift_neg' (i : A) : f⟦i⟧'⟦-i⟧' = (shiftFunctorCompIsoId C i (-i) (add_neg_cancel i)).hom.app X ≫ f ≫ (shiftFunctorCompIsoId C i (-i) (add_neg_cancel i)).inv.app Y := (NatIso.naturality_2 (shiftFunctorCompIsoId C i (-i) (add_neg_cancel i)) f).symm theorem shift_neg_shift' (i : A) : f⟦-i⟧'⟦i⟧' = (shiftFunctorCompIsoId C (-i) i (neg_add_cancel i)).hom.app X ≫ f ≫ (shiftFunctorCompIsoId C (-i) i (neg_add_cancel i)).inv.app Y := (NatIso.naturality_2 (shiftFunctorCompIsoId C (-i) i (neg_add_cancel i)) f).symm theorem shift_equiv_triangle (n : A) (X : C) : (shiftShiftNeg X n).inv⟦n⟧' ≫ (shiftNegShift (X⟦n⟧) n).hom = 𝟙 (X⟦n⟧) := (shiftEquiv C n).functor_unitIso_comp X section theorem shift_shiftFunctorCompIsoId_hom_app (n m : A) (h : n + m = 0) (X : C) : ((shiftFunctorCompIsoId C n m h).hom.app X)⟦n⟧' = (shiftFunctorCompIsoId C m n (by rw [← neg_eq_of_add_eq_zero_left h, add_neg_cancel])).hom.app (X⟦n⟧) := by dsimp [shiftFunctorCompIsoId] simpa only [Functor.map_comp, ← shiftFunctorAdd'_zero_add_inv_app n X, ← shiftFunctorAdd'_add_zero_inv_app n X] using shiftFunctorAdd'_assoc_inv_app n m n 0 0 n h (by rw [← neg_eq_of_add_eq_zero_left h, add_neg_cancel]) (by rw [h, zero_add]) X theorem shift_shiftFunctorCompIsoId_inv_app (n m : A) (h : n + m = 0) (X : C) : ((shiftFunctorCompIsoId C n m h).inv.app X)⟦n⟧' = ((shiftFunctorCompIsoId C m n (by rw [← neg_eq_of_add_eq_zero_left h, add_neg_cancel])).inv.app (X⟦n⟧)) := by rw [← cancel_mono (((shiftFunctorCompIsoId C n m h).hom.app X)⟦n⟧'), ← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id, shift_shiftFunctorCompIsoId_hom_app, Iso.inv_hom_id_app] rfl theorem shift_shiftFunctorCompIsoId_add_neg_cancel_hom_app (n : A) (X : C) : ((shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).hom.app X)⟦n⟧' = (shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).hom.app (X⟦n⟧) := by apply shift_shiftFunctorCompIsoId_hom_app theorem shift_shiftFunctorCompIsoId_add_neg_cancel_inv_app (n : A) (X : C) : ((shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).inv.app X)⟦n⟧' = (shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).inv.app (X⟦n⟧) := by apply shift_shiftFunctorCompIsoId_inv_app theorem shift_shiftFunctorCompIsoId_neg_add_cancel_hom_app (n : A) (X : C) : ((shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).hom.app X)⟦-n⟧' = (shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).hom.app (X⟦-n⟧) := by apply shift_shiftFunctorCompIsoId_hom_app theorem shift_shiftFunctorCompIsoId_neg_add_cancel_inv_app (n : A) (X : C) : ((shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).inv.app X)⟦-n⟧' = (shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).inv.app (X⟦-n⟧) := by apply shift_shiftFunctorCompIsoId_inv_app end section variable (A) lemma shiftFunctorCompIsoId_zero_zero_hom_app (X : C) : (shiftFunctorCompIsoId C 0 0 (add_zero 0)).hom.app X = ((shiftFunctorZero C A).hom.app X)⟦0⟧' ≫ (shiftFunctorZero C A).hom.app X := by simp [shiftFunctorCompIsoId, shiftFunctorAdd'_zero_add_inv_app] lemma shiftFunctorCompIsoId_zero_zero_inv_app (X : C) : (shiftFunctorCompIsoId C 0 0 (add_zero 0)).inv.app X = (shiftFunctorZero C A).inv.app X ≫ ((shiftFunctorZero C A).inv.app X)⟦0⟧' := by simp [shiftFunctorCompIsoId, shiftFunctorAdd'_zero_add_hom_app] end section variable (m n p m' n' p' : A) (hm : m' + m = 0) (hn : n' + n = 0) (hp : p' + p = 0) (h : m + n = p) lemma shiftFunctorCompIsoId_add'_inv_app : (shiftFunctorCompIsoId C p' p hp).inv.app X = (shiftFunctorCompIsoId C n' n hn).inv.app X ≫ (shiftFunctorCompIsoId C m' m hm).inv.app (X⟦n'⟧)⟦n⟧' ≫ (shiftFunctorAdd' C m n p h).inv.app (X⟦n'⟧⟦m'⟧) ≫ ((shiftFunctorAdd' C n' m' p' (by rw [← add_left_inj p, hp, ← h, add_assoc, ← add_assoc m', hm, zero_add, hn])).inv.app X)⟦p⟧' := by dsimp [shiftFunctorCompIsoId] simp only [Functor.map_comp, Category.assoc] congr 1 rw [← NatTrans.naturality] dsimp rw [← cancel_mono ((shiftFunctorAdd' C p' p 0 hp).inv.app X), Iso.hom_inv_id_app, Category.assoc, Category.assoc, Category.assoc, Category.assoc, ← shiftFunctorAdd'_assoc_inv_app p' m n n' p 0 (by rw [← add_left_inj n, hn, add_assoc, h, hp]) h (by rw [add_assoc, h, hp]), ← Functor.map_comp_assoc, ← Functor.map_comp_assoc, ← Functor.map_comp_assoc, Category.assoc, Category.assoc, shiftFunctorAdd'_assoc_inv_app n' m' m p' 0 n' _ hm (by rw [add_assoc, hm, add_zero]), Iso.hom_inv_id_app_assoc, ← shiftFunctorAdd'_add_zero_hom_app, Iso.hom_inv_id_app, Functor.map_id, Category.id_comp, Iso.hom_inv_id_app] lemma shiftFunctorCompIsoId_add'_hom_app : (shiftFunctorCompIsoId C p' p hp).hom.app X = ((shiftFunctorAdd' C n' m' p' (by rw [← add_left_inj p, hp, ← h, add_assoc, ← add_assoc m', hm, zero_add, hn])).hom.app X)⟦p⟧' ≫ (shiftFunctorAdd' C m n p h).hom.app (X⟦n'⟧⟦m'⟧) ≫ (shiftFunctorCompIsoId C m' m hm).hom.app (X⟦n'⟧)⟦n⟧' ≫ (shiftFunctorCompIsoId C n' n hn).hom.app X := by rw [← cancel_mono ((shiftFunctorCompIsoId C p' p hp).inv.app X), Iso.hom_inv_id_app, shiftFunctorCompIsoId_add'_inv_app m n p m' n' p' hm hn hp h, Category.assoc, Category.assoc, Category.assoc, Iso.hom_inv_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app] dsimp rw [Functor.map_id, Category.id_comp, Iso.hom_inv_id_app_assoc, ← Functor.map_comp, Iso.hom_inv_id_app, Functor.map_id] end open CategoryTheory.Limits variable [HasZeroMorphisms C] theorem shift_zero_eq_zero (X Y : C) (n : A) : (0 : X ⟶ Y)⟦n⟧' = (0 : X⟦n⟧ ⟶ Y⟦n⟧) := CategoryTheory.Functor.map_zero _ _ _ end AddGroup section AddCommMonoid variable [AddCommMonoid A] [HasShift C A] variable (C) /-- When shifts are indexed by an additive commutative monoid, then shifts commute. -/ def shiftFunctorComm (i j : A) : shiftFunctor C i ⋙ shiftFunctor C j ≅ shiftFunctor C j ⋙ shiftFunctor C i := (shiftFunctorAdd C i j).symm ≪≫ shiftFunctorAdd' C j i (i + j) (add_comm j i) lemma shiftFunctorComm_eq (i j k : A) (h : i + j = k) : shiftFunctorComm C i j = (shiftFunctorAdd' C i j k h).symm ≪≫ shiftFunctorAdd' C j i k (by rw [add_comm j i, h]) := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd] rfl @[simp] lemma shiftFunctorComm_eq_refl (i : A) : shiftFunctorComm C i i = Iso.refl _ := by rw [shiftFunctorComm_eq C i i (i + i) rfl, Iso.symm_self_id] lemma shiftFunctorComm_symm (i j : A) : (shiftFunctorComm C i j).symm = shiftFunctorComm C j i := by ext1 dsimp rw [shiftFunctorComm_eq C i j (i+j) rfl, shiftFunctorComm_eq C j i (i+j) (add_comm j i)] rfl variable {C} variable (X Y : C) (f : X ⟶ Y) /-- When shifts are indexed by an additive commutative monoid, then shifts commute. -/ abbrev shiftComm (i j : A) : X⟦i⟧⟦j⟧ ≅ X⟦j⟧⟦i⟧ := (shiftFunctorComm C i j).app X @[simp] theorem shiftComm_symm (i j : A) : (shiftComm X i j).symm = shiftComm X j i := by ext exact NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorComm_symm C i j)) X variable {X Y} /-- When shifts are indexed by an additive commutative monoid, then shifts commute. -/ theorem shiftComm' (i j : A) : f⟦i⟧'⟦j⟧' = (shiftComm _ _ _).hom ≫ f⟦j⟧'⟦i⟧' ≫ (shiftComm _ _ _).hom := by erw [← shiftComm_symm Y i j, ← ((shiftFunctorComm C i j).hom.naturality_assoc f)] dsimp simp only [Iso.hom_inv_id_app, Functor.comp_obj, Category.comp_id] @[reassoc] theorem shiftComm_hom_comp (i j : A) : (shiftComm X i j).hom ≫ f⟦j⟧'⟦i⟧' = f⟦i⟧'⟦j⟧' ≫ (shiftComm Y i j).hom := by rw [shiftComm', ← shiftComm_symm, Iso.symm_hom, Iso.inv_hom_id_assoc] lemma shiftFunctorZero_hom_app_shift (n : A) : (shiftFunctorZero C A).hom.app (X⟦n⟧) = (shiftFunctorComm C n 0).hom.app X ≫ ((shiftFunctorZero C A).hom.app X)⟦n⟧' := by rw [← shiftFunctorAdd'_zero_add_inv_app n X, shiftFunctorComm_eq C n 0 n (add_zero n)] dsimp rw [Category.assoc, Iso.hom_inv_id_app, Category.comp_id, shiftFunctorAdd'_add_zero_inv_app] lemma shiftFunctorZero_inv_app_shift (n : A) : (shiftFunctorZero C A).inv.app (X⟦n⟧) = ((shiftFunctorZero C A).inv.app X)⟦n⟧' ≫ (shiftFunctorComm C n 0).inv.app X := by rw [← cancel_mono ((shiftFunctorZero C A).hom.app (X⟦n⟧)), Category.assoc, Iso.inv_hom_id_app, shiftFunctorZero_hom_app_shift, Iso.inv_hom_id_app_assoc, ← Functor.map_comp, Iso.inv_hom_id_app] dsimp rw [Functor.map_id] lemma shiftFunctorComm_zero_hom_app (a : A) : (shiftFunctorComm C a 0).hom.app X = (shiftFunctorZero C A).hom.app (X⟦a⟧) ≫ ((shiftFunctorZero C A).inv.app X)⟦a⟧' := by simp only [shiftFunctorZero_hom_app_shift, Category.assoc, ← Functor.map_comp, Iso.hom_inv_id_app, Functor.map_id, Functor.comp_obj, Category.comp_id] @[reassoc] lemma shiftFunctorComm_hom_app_comp_shift_shiftFunctorAdd_hom_app (m₁ m₂ m₃ : A) (X : C) : (shiftFunctorComm C m₁ (m₂ + m₃)).hom.app X ≫ ((shiftFunctorAdd C m₂ m₃).hom.app X)⟦m₁⟧' = (shiftFunctorAdd C m₂ m₃).hom.app (X⟦m₁⟧) ≫ ((shiftFunctorComm C m₁ m₂).hom.app X)⟦m₃⟧' ≫ (shiftFunctorComm C m₁ m₃).hom.app (X⟦m₂⟧) := by rw [← cancel_mono ((shiftFunctorComm C m₁ m₃).inv.app (X⟦m₂⟧)), ← cancel_mono (((shiftFunctorComm C m₁ m₂).inv.app X)⟦m₃⟧')] simp only [Category.assoc, Iso.hom_inv_id_app] dsimp simp only [Category.id_comp, ← Functor.map_comp, Iso.hom_inv_id_app] dsimp simp only [Functor.map_id, Category.comp_id, shiftFunctorComm_eq C _ _ _ rfl, ← shiftFunctorAdd'_eq_shiftFunctorAdd] dsimp simp only [Category.assoc, Iso.hom_inv_id_app_assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp, shiftFunctorAdd'_assoc_hom_app_assoc m₂ m₃ m₁ (m₂ + m₃) (m₁ + m₃) (m₁ + (m₂ + m₃)) rfl (add_comm m₃ m₁) (add_comm _ m₁) X, ← shiftFunctorAdd'_assoc_hom_app_assoc m₂ m₁ m₃ (m₁ + m₂) (m₁ + m₃) (m₁ + (m₂ + m₃)) (add_comm _ _) rfl (by rw [add_comm m₂ m₁, add_assoc]) X, shiftFunctorAdd'_assoc_hom_app m₁ m₂ m₃ (m₁ + m₂) (m₂ + m₃) (m₁ + (m₂ + m₃)) rfl rfl (add_assoc _ _ _) X] end AddCommMonoid namespace Functor.FullyFaithful variable {D : Type*} [Category D] [AddMonoid A] [HasShift D A] variable {F : C ⥤ D} (hF : F.FullyFaithful) variable (s : A → C ⥤ C) (i : ∀ i, s i ⋙ F ≅ F ⋙ shiftFunctor D i) namespace hasShift /-- auxiliary definition for `FullyFaithful.hasShift` -/ def zero : s 0 ≅ 𝟭 C := (hF.whiskeringRight C).preimageIso ((i 0) ≪≫ isoWhiskerLeft F (shiftFunctorZero D A) ≪≫ rightUnitor _ ≪≫ (leftUnitor _).symm) @[simp] lemma map_zero_hom_app (X : C) : F.map ((zero hF s i).hom.app X) = (i 0).hom.app X ≫ (shiftFunctorZero D A).hom.app (F.obj X) := by simp [zero] @[simp] lemma map_zero_inv_app (X : C) : F.map ((zero hF s i).inv.app X) = (shiftFunctorZero D A).inv.app (F.obj X) ≫ (i 0).inv.app X := by simp [zero] /-- auxiliary definition for `FullyFaithful.hasShift` -/ def add (a b : A) : s (a + b) ≅ s a ⋙ s b := (hF.whiskeringRight C).preimageIso (i (a + b) ≪≫ isoWhiskerLeft _ (shiftFunctorAdd D a b) ≪≫ (associator _ _ _).symm ≪≫ (isoWhiskerRight (i a).symm _) ≪≫ associator _ _ _ ≪≫ (isoWhiskerLeft _ (i b).symm) ≪≫ (associator _ _ _).symm) @[simp] lemma map_add_hom_app (a b : A) (X : C) : F.map ((add hF s i a b).hom.app X) = (i (a + b)).hom.app X ≫ (shiftFunctorAdd D a b).hom.app (F.obj X) ≫ ((i a).inv.app X)⟦b⟧' ≫ (i b).inv.app ((s a).obj X) := by dsimp [add] simp @[simp] lemma map_add_inv_app (a b : A) (X : C) : F.map ((add hF s i a b).inv.app X) = (i b).hom.app ((s a).obj X) ≫ ((i a).hom.app X)⟦b⟧' ≫ (shiftFunctorAdd D a b).inv.app (F.obj X) ≫ (i (a + b)).inv.app X := by dsimp [add] simp end hasShift open hasShift in /-- Given a family of endomorphisms of `C` which are intertwined by a fully faithful `F : C ⥤ D` with shift functors on `D`, we can promote that family to shift functors on `C`. -/ def hasShift : HasShift C A := hasShiftMk C A { F := s zero := zero hF s i add := add hF s i assoc_hom_app := fun m₁ m₂ m₃ X => hF.map_injective (by have h := shiftFunctorAdd'_assoc_hom_app m₁ m₂ m₃ _ _ (m₁+m₂+m₃) rfl rfl rfl (F.obj X) simp only [shiftFunctorAdd'_eq_shiftFunctorAdd] at h rw [← cancel_mono ((i m₃).hom.app ((s m₂).obj ((s m₁).obj X)))] simp only [Functor.comp_obj, Functor.map_comp, map_add_hom_app, Category.assoc, Iso.inv_hom_id_app_assoc, NatTrans.naturality_assoc, Functor.comp_map, Iso.inv_hom_id_app, Category.comp_id] erw [(i m₃).hom.naturality] rw [Functor.comp_map, map_add_hom_app, Functor.map_comp, Functor.map_comp, Iso.inv_hom_id_app_assoc, ← Functor.map_comp_assoc _ ((i (m₁ + m₂)).inv.app X), Iso.inv_hom_id_app, Functor.map_id, Category.id_comp, reassoc_of% h, dcongr_arg (fun a => (i a).hom.app X) (add_assoc m₁ m₂ m₃)] simp [shiftFunctorAdd', eqToHom_map]) zero_add_hom_app := fun n X => hF.map_injective (by have this := dcongr_arg (fun a => (i a).hom.app X) (zero_add n) rw [← cancel_mono ((i n).hom.app ((s 0).obj X)) ] simp only [comp_obj, map_add_hom_app, this, shiftFunctorAdd_zero_add_hom_app, id_obj, Category.assoc, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, Iso.inv_hom_id_app, Category.comp_id, map_comp, eqToHom_map] congr 1 erw [(i n).hom.naturality] simp) add_zero_hom_app := fun n X => hF.map_injective (by have := dcongr_arg (fun a => (i a).hom.app X) (add_zero n) simp [this, ← NatTrans.naturality_assoc, eqToHom_map, shiftFunctorAdd_add_zero_hom_app]) } end Functor.FullyFaithful end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Quotient.lean
import Mathlib.CategoryTheory.Shift.CommShift import Mathlib.CategoryTheory.Shift.Induced import Mathlib.CategoryTheory.Quotient /-! # The shift on a quotient category Let `C` be a category equipped a shift by a monoid `A`. If we have a relation on morphisms `r : HomRel C` that is compatible with the shift (i.e. if two morphisms `f` and `g` are related, then `f⟦a⟧'` and `g⟦a⟧'` are also related for all `a : A`), then the quotient category `Quotient r` is equipped with a shift. The condition `r.IsCompatibleWithShift A` on the relation `r` is a class so that the shift can be automatically inferred on the quotient category. -/ universe v v' u u' w open CategoryTheory Category variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] (F : C ⥤ D) (r : HomRel C) (A : Type w) [AddMonoid A] [HasShift C A] [HasShift D A] namespace HomRel /-- A relation on morphisms is compatible with the shift by a monoid `A` when the relation if preserved by the shift. -/ class IsCompatibleWithShift : Prop where /-- the condition that the relation is preserved by the shift -/ condition : ∀ (a : A) ⦃X Y : C⦄ (f g : X ⟶ Y), r f g → r (f⟦a⟧') (g⟦a⟧') end HomRel namespace CategoryTheory /-- The shift by a monoid `A` induced on a quotient category `Quotient r` when the relation `r` is compatible with the shift. -/ noncomputable instance HasShift.quotient [r.IsCompatibleWithShift A] : HasShift (Quotient r) A := HasShift.induced (Quotient.functor r) A (fun a => Quotient.lift r (shiftFunctor C a ⋙ Quotient.functor r) (fun _ _ _ _ hfg => Quotient.sound r (HomRel.IsCompatibleWithShift.condition _ _ _ hfg))) (fun _ => Quotient.lift.isLift _ _ _) /-- The functor `Quotient.functor r : C ⥤ Quotient r` commutes with the shift. -/ noncomputable instance Quotient.functor_commShift [r.IsCompatibleWithShift A] : (Quotient.functor r).CommShift A := Functor.CommShift.ofInduced _ _ _ _ -- the construction is made irreducible in order to prevent timeouts and abuse of defeq attribute [irreducible] HasShift.quotient Quotient.functor_commShift namespace Quotient variable [r.IsCompatibleWithShift A] [F.CommShift A] (hF : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) namespace LiftCommShift variable {A} /-- Auxiliary definition for `Quotient.liftCommShift`. -/ noncomputable def iso (a : A) : shiftFunctor (Quotient r) a ⋙ lift r F hF ≅ lift r F hF ⋙ shiftFunctor D a := natIsoLift r ((Functor.associator _ _ _).symm ≪≫ Functor.isoWhiskerRight ((functor r).commShiftIso a).symm _ ≪≫ Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft _ (lift.isLift r F hF) ≪≫ F.commShiftIso a ≪≫ Functor.isoWhiskerRight (lift.isLift r F hF).symm _ ≪≫ Functor.associator _ _ _) @[simp] lemma iso_hom_app (a : A) (X : C) : (iso F r hF a).hom.app ((functor r).obj X) = (lift r F hF).map (((functor r).commShiftIso a).inv.app X) ≫ (F.commShiftIso a).hom.app X := by dsimp only [iso, natIsoLift] rw [natTransLift_app] dsimp erw [comp_id, id_comp, id_comp, id_comp, Functor.map_id, comp_id] @[simp] lemma iso_inv_app (a : A) (X : C) : (iso F r hF a).inv.app ((functor r).obj X) = (F.commShiftIso a).inv.app X ≫ (lift r F hF).map (((functor r).commShiftIso a).hom.app X) := by dsimp only [iso, natIsoLift] rw [natTransLift_app] dsimp erw [id_comp, comp_id, comp_id, comp_id, Functor.map_id, id_comp] attribute [irreducible] iso end LiftCommShift /-- When `r : HomRel C` is compatible with the shift by an additive monoid, and `F : C ⥤ D` is a functor which commutes with the shift and is compatible with `r`, then the induced functor `Quotient.lift r F _ : Quotient r ⥤ D` also commutes with the shift. -/ @[simps -isSimp commShiftIso] noncomputable instance liftCommShift : (Quotient.lift r F hF).CommShift A where commShiftIso := LiftCommShift.iso F r hF commShiftIso_zero := by ext1 apply natTrans_ext ext X dsimp rw [LiftCommShift.iso_hom_app, (functor r).commShiftIso_zero, Functor.CommShift.isoZero_hom_app, Functor.CommShift.isoZero_inv_app, Functor.map_comp, assoc, F.commShiftIso_zero, Functor.CommShift.isoZero_hom_app, lift_map_functor_map, ← F.map_comp_assoc, Iso.inv_hom_id_app] dsimp [lift_obj_functor_obj] rw [F.map_id, id_comp] commShiftIso_add a b := by ext1 apply natTrans_ext ext X dsimp rw [LiftCommShift.iso_hom_app, (functor r).commShiftIso_add, F.commShiftIso_add, Functor.CommShift.isoAdd_hom_app, Functor.CommShift.isoAdd_hom_app, Functor.CommShift.isoAdd_inv_app, Functor.map_comp, Functor.map_comp, Functor.map_comp, assoc, assoc, assoc, LiftCommShift.iso_hom_app, lift_map_functor_map] congr 1 rw [← cancel_epi ((shiftFunctor (Quotient r) b ⋙ lift r F hF).map (NatTrans.app (Functor.commShiftIso (functor r) a).hom X))] erw [(LiftCommShift.iso F r hF b).hom.naturality_assoc (((functor r).commShiftIso a).hom.app X), LiftCommShift.iso_hom_app, ← Functor.map_comp_assoc, Iso.hom_inv_id_app] dsimp simp only [Functor.comp_obj, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, id_comp, Iso.hom_inv_id_app, lift_obj_functor_obj] instance liftCommShift_compatibility : NatTrans.CommShift (Quotient.lift.isLift r F hF).hom A where shift_comm a := by ext X dsimp rw [Functor.commShiftIso_comp_hom_app, liftCommShift_commShiftIso, LiftCommShift.iso_hom_app, ← Functor.map_comp_assoc, Iso.hom_inv_id_app] simp [lift, Quotient.functor] end Quotient end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/ShiftSequence.lean
import Mathlib.CategoryTheory.Shift.Basic import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! Sequences of functors from a category equipped with a shift Let `F : C ⥤ A` be a functor from a category `C` that is equipped with a shift by an additive monoid `M`. In this file, we define a typeclass `F.ShiftSequence M` which includes the data of a sequence of functors `F.shift a : C ⥤ A` for all `a : A`. For each `a : A`, we have an isomorphism `F.isoShift a : shiftFunctor C a ⋙ F ≅ F.shift a` which satisfies some coherence relations. This allows to state results (e.g. the long exact sequence of an homology functor (TODO)) using functors `F.shift a` rather than `shiftFunctor C a ⋙ F`. The reason for this design is that we can often choose functors `F.shift a` that have better definitional properties than `shiftFunctor C a ⋙ F`. For example, if `C` is the derived category (TODO) of an abelian category `A` and `F` is the homology functor in degree `0`, then for any `n : ℤ`, we may choose `F.shift n` to be the homology functor in degree `n`. -/ open CategoryTheory Category ZeroObject Limits variable {C A : Type*} [Category C] [Category A] (F : C ⥤ A) (M : Type*) [AddMonoid M] [HasShift C M] {G : Type*} [AddGroup G] [HasShift C G] namespace CategoryTheory namespace Functor /-- A shift sequence for a functor `F : C ⥤ A` when `C` is equipped with a shift by a monoid `M` involves a sequence of functor `sequence n : C ⥤ A` for all `n : M` which behave like `shiftFunctor C n ⋙ F`. -/ class ShiftSequence where /-- a sequence of functors -/ sequence : M → C ⥤ A /-- `sequence 0` identifies to the given functor -/ isoZero : sequence 0 ≅ F /-- compatibility isomorphism with the shift -/ shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ sequence a ≅ sequence a' shiftIso_zero (a : M) : shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ shiftIso_add : ∀ (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a''), shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (shiftIso n a a' ha') ≪≫ shiftIso m a' a'' ha'' /-- The tautological shift sequence on a functor. -/ noncomputable def ShiftSequence.tautological : ShiftSequence F M where sequence n := shiftFunctor C n ⋙ F isoZero := isoWhiskerRight (shiftFunctorZero C M) F ≪≫ F.rightUnitor shiftIso n a a' ha' := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (shiftFunctorAdd' C n a a' ha').symm _ shiftIso_zero a := by rw [shiftFunctorAdd'_zero_add] cat_disch shiftIso_add n m a a' a'' ha' ha'' := by ext X dsimp simp only [id_comp, ← Functor.map_comp] congr simpa only [← cancel_epi ((shiftFunctor C a).map ((shiftFunctorAdd C m n).hom.app X)), shiftFunctorAdd'_eq_shiftFunctorAdd, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, id_comp] using shiftFunctorAdd'_assoc_inv_app m n a (m+n) a' a'' rfl ha' (by rw [← ha'', ← ha', add_assoc]) X section variable {M} variable [F.ShiftSequence M] /-- The shifted functors given by the shift sequence. -/ def shift (n : M) : C ⥤ A := ShiftSequence.sequence F n /-- Compatibility isomorphism `shiftFunctor C n ⋙ F.shift a ≅ F.shift a'` when `n + a = a'`. -/ def shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ F.shift a ≅ F.shift a' := ShiftSequence.shiftIso n a a' ha' @[reassoc (attr := simp)] lemma shiftIso_hom_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a).map (f⟦n⟧') ≫ (shiftIso F n a a' ha').hom.app Y = (shiftIso F n a a' ha').hom.app X ≫ (shift F a').map f := (F.shiftIso n a a' ha').hom.naturality f @[reassoc] lemma shiftIso_inv_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a').map f ≫ (shiftIso F n a a' ha').inv.app Y = (shiftIso F n a a' ha').inv.app X ≫ (shift F a).map (f⟦n⟧') := by simp variable (M) in /-- The canonical isomorphism `F.shift 0 ≅ F`. -/ def isoShiftZero : F.shift (0 : M) ≅ F := ShiftSequence.isoZero /-- The canonical isomorphism `shiftFunctor C n ⋙ F ≅ F.shift n`. -/ def isoShift (n : M) : shiftFunctor C n ⋙ F ≅ F.shift n := isoWhiskerLeft _ (F.isoShiftZero M).symm ≪≫ F.shiftIso _ _ _ (add_zero n) @[reassoc] lemma isoShift_hom_naturality (n : M) {X Y : C} (f : X ⟶ Y) : F.map (f⟦n⟧') ≫ (F.isoShift n).hom.app Y = (F.isoShift n).hom.app X ≫ (F.shift n).map f := (F.isoShift n).hom.naturality f attribute [simp] isoShift_hom_naturality @[reassoc] lemma isoShift_inv_naturality (n : M) {X Y : C} (f : X ⟶ Y) : (F.shift n).map f ≫ (F.isoShift n).inv.app Y = (F.isoShift n).inv.app X ≫ F.map (f⟦n⟧') := (F.isoShift n).inv.naturality f lemma shiftIso_zero (a : M) : F.shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ := ShiftSequence.shiftIso_zero a @[simp] lemma shiftIso_zero_hom_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).hom.app X = (shift F a).map ((shiftFunctorZero C M).hom.app X) := by simp [F.shiftIso_zero a] @[simp] lemma shiftIso_zero_inv_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).inv.app X = (shift F a).map ((shiftFunctorZero C M).inv.app X) := by simp [F.shiftIso_zero a] lemma shiftIso_add (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' := ShiftSequence.shiftIso_add _ _ _ _ _ _ _ lemma shiftIso_add_hom_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X = (shift F a).map ((shiftFunctorAdd C m n).hom.app X) ≫ (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add_inv_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).inv.app X = (shiftIso F m a' a'' ha'').inv.app X ≫ (shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫ (shift F a).map ((shiftFunctorAdd C m n).inv.app X) := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add' (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc]) = isoWhiskerRight (shiftFunctorAdd' C m n _ hnm) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' := by subst hnm rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftIso_add] lemma shiftIso_add'_hom_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X = (shift F a).map ((shiftFunctorAdd' C m n mn hnm).hom.app X) ≫ (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] lemma shiftIso_add'_inv_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).inv.app X = (shiftIso F m a' a'' ha'').inv.app X ≫ (shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫ (shift F a).map ((shiftFunctorAdd' C m n mn hnm).inv.app X) := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] @[reassoc] lemma shiftIso_hom_app_comp (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X = (shift F a).map ((shiftFunctorAdd' C m n mn hnm).inv.app X) ≫ (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X := by rw [F.shiftIso_add'_hom_app n m mn hnm a a' a'' ha' ha'', ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, id_comp] /-- The morphism `(F.shift a).obj X ⟶ (F.shift a').obj Y` induced by a morphism `f : X ⟶ Y⟦n⟧` when `n + a = a'`. -/ def shiftMap {X Y : C} {n : M} (f : X ⟶ Y⟦n⟧) (a a' : M) (ha' : n + a = a') : (F.shift a).obj X ⟶ (F.shift a').obj Y := (F.shift a).map f ≫ (F.shiftIso _ _ _ ha').hom.app Y @[reassoc] lemma shiftMap_comp {X Y Z : C} {n : M} (f : X ⟶ Y⟦n⟧) (g : Y ⟶ Z) (a a' : M) (ha' : n + a = a') : F.shiftMap (f ≫ g⟦n⟧') a a' ha' = F.shiftMap f a a' ha' ≫ (F.shift a').map g := by simp [shiftMap] @[reassoc] lemma shiftMap_comp' {X Y Z : C} {n : M} (f : X ⟶ Y) (g : Y ⟶ Z⟦n⟧) (a a' : M) (ha' : n + a = a') : F.shiftMap (f ≫ g) a a' ha' = (F.shift a).map f ≫ F.shiftMap g a a' ha' := by simp [shiftMap] /-- When `f : X ⟶ Y⟦m⟧`, `m + n = mn`, `n + a = a'` and `ha'' : m + a' = a''`, this lemma relates the two morphisms `F.shiftMap f a' a'' ha''` and `(F.shift a).map (f⟦n⟧')`. Indeed, via canonical isomorphisms, they both identity to morphisms `(F.shift a').obj X ⟶ (F.shift a'').obj Y`. -/ lemma shiftIso_hom_app_comp_shiftMap {X Y : C} {m : M} (f : X ⟶ Y⟦m⟧) (n mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : (F.shiftIso n a a' ha').hom.app X ≫ F.shiftMap f a' a'' ha'' = (F.shift a).map (f⟦n⟧') ≫ (F.shift a).map ((shiftFunctorAdd' C m n mn hnm).inv.app Y) ≫ (F.shiftIso mn a a'' (by rw [← ha'', ← ha', ← hnm, add_assoc])).hom.app Y := by simp only [F.shiftIso_add'_hom_app n m mn hnm a a' a'' ha' ha'' Y, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, id_comp, comp_obj, shiftIso_hom_naturality_assoc, shiftMap] /-- If `f : X ⟶ Y⟦m⟧`, `n + m = 0` and `ha' : m + a = a'`, this lemma relates the two morphisms `F.shiftMap f a a' ha'` and `(F.shift a').map (f⟦n⟧')`. Indeed, via canonical isomorphisms, they both identify to morphisms `(F.shift a).obj X ⟶ (F.shift a').obj Y`. -/ lemma shiftIso_hom_app_comp_shiftMap_of_add_eq_zero [F.ShiftSequence G] {X Y : C} {m : G} (f : X ⟶ Y⟦m⟧) (n : G) (hnm : n + m = 0) (a a' : G) (ha' : m + a = a') : (F.shiftIso n a' a (by rw [← ha', ← add_assoc, hnm, zero_add])).hom.app X ≫ F.shiftMap f a a' ha' = (F.shift a').map (f⟦n⟧' ≫ (shiftFunctorCompIsoId C m n (by rw [← add_left_inj m, add_assoc, hnm, zero_add, add_zero])).hom.app Y) := by have hnm' : m + n = 0 := by rw [← add_left_inj m, add_assoc, hnm, zero_add, add_zero] simp [F.shiftIso_hom_app_comp_shiftMap f n 0 hnm' a' a, shiftIso_zero_hom_app, shiftFunctorCompIsoId] section variable [HasZeroMorphisms C] [HasZeroMorphisms A] [F.PreservesZeroMorphisms] [∀ (n : M), (shiftFunctor C n).PreservesZeroMorphisms] instance (n : M) : (F.shift n).PreservesZeroMorphisms := preservesZeroMorphisms_of_iso (F.isoShift n) @[simp] lemma shiftMap_zero (X Y : C) (n a a' : M) (ha' : n + a = a') : F.shiftMap (0 : X ⟶ Y⟦n⟧) a a' ha' = 0 := by simp [shiftMap] end section variable [Preadditive C] [Preadditive A] [F.Additive] [∀ (n : M), (shiftFunctor C n).Additive] instance (n : M) : (F.shift n).Additive := additive_of_iso (F.isoShift n) end end end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Localization.lean
import Mathlib.CategoryTheory.Shift.Induced import Mathlib.CategoryTheory.Localization.HasLocalization import Mathlib.CategoryTheory.Localization.LocalizerMorphism /-! # The shift induced on a localized category Let `C` be a category equipped with a shift by a monoid `A`. A morphism property `W` on `C` satisfies `W.IsCompatibleWithShift A` when for all `a : A`, a morphism `f` is in `W` iff `f⟦a⟧'` is. When this compatibility is satisfied, then the corresponding localized category can be equipped with a shift by `A`, and the localization functor is compatible with the shift. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ w namespace CategoryTheory variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] {E : Type u₃} [Category.{v₃} E] (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] (A : Type w) [AddMonoid A] [HasShift C A] namespace MorphismProperty /-- A morphism property `W` on a category `C` is compatible with the shift by a monoid `A` when for all `a : A`, a morphism `f` belongs to `W` if and only if `f⟦a⟧'` does. -/ class IsCompatibleWithShift : Prop where /-- the condition that for all `a : A`, the morphism property `W` is not changed when we take its inverse image by the shift functor by `a` -/ condition : ∀ (a : A), W.inverseImage (shiftFunctor C a) = W variable [W.IsCompatibleWithShift A] namespace IsCompatibleWithShift variable {A} lemma iff {X Y : C} (f : X ⟶ Y) (a : A) : W (f⟦a⟧') ↔ W f := by conv_rhs => rw [← @IsCompatibleWithShift.condition _ _ W A _ _ _ a] rfl lemma shiftFunctor_comp_inverts (a : A) : W.IsInvertedBy (shiftFunctor C a ⋙ L) := fun _ _ f hf => Localization.inverts L W _ (by simpa only [iff] using hf) end IsCompatibleWithShift variable {A} in lemma shift {X Y : C} {f : X ⟶ Y} (hf : W f) (a : A) : W (f⟦a⟧') := by simpa only [IsCompatibleWithShift.iff W f a] using hf variable {A} in /-- The morphism of localizer from `W` to `W` given by the functor `shiftFunctor C a` when `a : A` and `W` is compatible with the shift by `A`. -/ abbrev shiftLocalizerMorphism (a : A) : LocalizerMorphism W W where functor := shiftFunctor C a map := by rw [MorphismProperty.IsCompatibleWithShift.condition] end MorphismProperty section variable [W.IsCompatibleWithShift A] /-- When `L : C ⥤ D` is a localization functor with respect to a morphism property `W` that is compatible with the shift by a monoid `A` on `C`, this is the induced shift on the category `D`. -/ noncomputable def HasShift.localized : HasShift D A := have := Localization.full_whiskeringLeft L W D have := Localization.faithful_whiskeringLeft L W D HasShift.induced L A (fun a => Localization.lift (shiftFunctor C a ⋙ L) (MorphismProperty.IsCompatibleWithShift.shiftFunctor_comp_inverts L W a) L) (fun _ => Localization.fac _ _ _) /-- The localization functor `L : C ⥤ D` is compatible with the shift. -/ @[nolint unusedHavesSuffices] noncomputable def Functor.CommShift.localized : @Functor.CommShift _ _ _ _ L A _ _ (HasShift.localized L W A) := have := Localization.full_whiskeringLeft L W D have := Localization.faithful_whiskeringLeft L W D Functor.CommShift.ofInduced _ _ _ _ attribute [irreducible] HasShift.localized Functor.CommShift.localized /-- The localized category `W.Localization` is endowed with the induced shift. -/ noncomputable instance HasShift.localization : HasShift W.Localization A := HasShift.localized W.Q W A /-- The localization functor `W.Q : C ⥤ W.Localization` is compatible with the shift. -/ noncomputable instance MorphismProperty.commShift_Q : W.Q.CommShift A := Functor.CommShift.localized W.Q W A attribute [irreducible] HasShift.localization MorphismProperty.commShift_Q variable [W.HasLocalization] /-- The localized category `W.Localization'` is endowed with the induced shift. -/ noncomputable instance HasShift.localization' : HasShift W.Localization' A := HasShift.localized W.Q' W A /-- The localization functor `W.Q' : C ⥤ W.Localization'` is compatible with the shift. -/ noncomputable instance MorphismProperty.commShift_Q' : W.Q'.CommShift A := Functor.CommShift.localized W.Q' W A attribute [irreducible] HasShift.localization' MorphismProperty.commShift_Q' end section open Localization variable (F : C ⥤ E) (F' : D ⥤ E) [Lifting L W F F'] [HasShift D A] [HasShift E A] [L.CommShift A] [F.CommShift A] namespace Functor namespace commShiftOfLocalization variable {A} /-- Auxiliary definition for `Functor.commShiftOfLocalization`. -/ noncomputable def iso (a : A) : shiftFunctor D a ⋙ F' ≅ F' ⋙ shiftFunctor E a := Localization.liftNatIso L W (L ⋙ shiftFunctor D a ⋙ F') (L ⋙ F' ⋙ shiftFunctor E a) _ _ ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (L.commShiftIso a).symm F' ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Lifting.iso L W F F') ≪≫ F.commShiftIso a ≪≫ isoWhiskerRight (Lifting.iso L W F F').symm _ ≪≫ Functor.associator _ _ _) @[simp, reassoc] lemma iso_hom_app (a : A) (X : C) : (commShiftOfLocalization.iso L W F F' a).hom.app (L.obj X) = F'.map ((L.commShiftIso a).inv.app X) ≫ (Lifting.iso L W F F').hom.app (X⟦a⟧) ≫ (F.commShiftIso a).hom.app X ≫ (shiftFunctor E a).map ((Lifting.iso L W F F').inv.app X) := by simp [commShiftOfLocalization.iso] @[simp, reassoc] lemma iso_inv_app (a : A) (X : C) : (commShiftOfLocalization.iso L W F F' a).inv.app (L.obj X) = (shiftFunctor E a).map ((Lifting.iso L W F F').hom.app X) ≫ (F.commShiftIso a).inv.app X ≫ (Lifting.iso L W F F').inv.app (X⟦a⟧) ≫ F'.map ((L.commShiftIso a).hom.app X) := by simp [commShiftOfLocalization.iso] end commShiftOfLocalization /-- In the context of localization of categories, if a functor is induced by a functor which commutes with the shift, then this functor commutes with the shift. -/ noncomputable def commShiftOfLocalization : F'.CommShift A where commShiftIso := commShiftOfLocalization.iso L W F F' commShiftIso_zero := by ext1 apply natTrans_ext L W intro X dsimp simp only [commShiftOfLocalization.iso_hom_app, comp_obj, commShiftIso_zero, CommShift.isoZero_inv_app, map_comp, CommShift.isoZero_hom_app, Category.assoc, ← NatTrans.naturality_assoc, ← NatTrans.naturality] dsimp simp only [← Functor.map_comp_assoc, ← Functor.map_comp, Iso.inv_hom_id_app, id_obj, map_id, Category.id_comp, Iso.hom_inv_id_app_assoc] commShiftIso_add a b := by ext1 apply natTrans_ext L W intro X dsimp simp only [commShiftOfLocalization.iso_hom_app, comp_obj, commShiftIso_add, CommShift.isoAdd_inv_app, map_comp, CommShift.isoAdd_hom_app, Category.assoc] congr 1 rw [← cancel_epi (F'.map ((shiftFunctor D b).map ((L.commShiftIso a).hom.app X))), ← F'.map_comp_assoc, ← map_comp, Iso.hom_inv_id_app, map_id, map_id, Category.id_comp] conv_lhs => erw [← NatTrans.naturality_assoc] dsimp rw [← Functor.map_comp_assoc, ← map_comp_assoc, Category.assoc, ← map_comp, Iso.inv_hom_id_app] dsimp rw [map_id, Category.comp_id, ← NatTrans.naturality] dsimp conv_rhs => erw [← NatTrans.naturality_assoc] dsimp rw [← Functor.map_comp_assoc, ← map_comp, Iso.hom_inv_id_app] dsimp rw [map_id, map_id, Category.id_comp, commShiftOfLocalization.iso_hom_app, Category.assoc, Category.assoc, Category.assoc, ← map_comp_assoc, Iso.inv_hom_id_app, map_id, Category.id_comp] variable {A} lemma commShiftOfLocalization_iso_hom_app (a : A) (X : C) : letI := Functor.commShiftOfLocalization L W A F F' (F'.commShiftIso a).hom.app (L.obj X) = F'.map ((L.commShiftIso a).inv.app X) ≫ (Lifting.iso L W F F').hom.app (X⟦a⟧) ≫ (F.commShiftIso a).hom.app X ≫ (shiftFunctor E a).map ((Lifting.iso L W F F').inv.app X) := by apply commShiftOfLocalization.iso_hom_app lemma commShiftOfLocalization_iso_inv_app (a : A) (X : C) : letI := Functor.commShiftOfLocalization L W A F F' (F'.commShiftIso a).inv.app (L.obj X) = (shiftFunctor E a).map ((Lifting.iso L W F F').hom.app X) ≫ (F.commShiftIso a).inv.app X ≫ (Lifting.iso L W F F').inv.app (X⟦a⟧) ≫ F'.map ((L.commShiftIso a).hom.app X) := by apply commShiftOfLocalization.iso_inv_app end Functor instance NatTrans.commShift_iso_hom_of_localization : letI := Functor.commShiftOfLocalization L W A F F' NatTrans.CommShift (Lifting.iso L W F F').hom A := by letI := Functor.commShiftOfLocalization L W A F F' constructor intro a ext X simp only [comp_app, Functor.whiskerRight_app, Functor.whiskerLeft_app, Functor.commShiftIso_comp_hom_app, Functor.commShiftOfLocalization_iso_hom_app, Category.assoc, ← Functor.map_comp, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, Iso.inv_hom_id_app, Category.comp_id, Category.id_comp, Functor.comp_obj] end namespace LocalizerMorphism open Localization variable {C₁ C₂ : Type*} [Category C₁] [Category C₂] {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} (Φ : LocalizerMorphism W₁ W₂) {M : Type*} [AddMonoid M] [HasShift C₁ M] [HasShift C₂ M] [Φ.functor.CommShift M] {D₁ D₂ : Type*} [Category D₁] [Category D₂] (L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) [HasShift D₁ M] [HasShift D₂ M] [L₁.CommShift M] [L₂.CommShift M] section variable (G : D₁ ⥤ D₂) (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G) variable (M) in /-- This is the commutation of a functor `G` to shifts by an additive monoid `M` when `e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G` is an isomorphism, `Φ` is a localizer morphism and `L₁` is a localization functor. We assume that all categories involved are equipped with shifts and that `L₁`, `L₂` and `Φ.functor` commute to them. -/ noncomputable def commShift : G.CommShift M := by letI : Localization.Lifting L₁ W₁ (Φ.functor ⋙ L₂) G := ⟨e.symm⟩ exact Functor.commShiftOfLocalization L₁ W₁ M (Φ.functor ⋙ L₂) G @[reassoc] lemma commShift_iso_hom_app (m : M) (X : C₁) : letI := Φ.commShift M L₁ L₂ G e (G.commShiftIso m).hom.app (L₁.obj X) = G.map ((L₁.commShiftIso m).inv.app X) ≫ e.inv.app _ ≫ L₂.map ((Φ.functor.commShiftIso m).hom.app X) ≫ (L₂.commShiftIso m).hom.app _ ≫ (e.hom.app X)⟦m⟧' := by simp [Functor.commShiftOfLocalization_iso_hom_app, Functor.commShiftIso_comp_hom_app] @[reassoc] lemma commShift_iso_inv_app (m : M) (X : C₁) : letI := Φ.commShift M L₁ L₂ G e (G.commShiftIso m).inv.app (L₁.obj X) = (e.inv.app X)⟦m⟧' ≫ (L₂.commShiftIso m).inv.app _ ≫ L₂.map ((Φ.functor.commShiftIso m).inv.app X) ≫ e.hom.app _ ≫ G.map ((L₁.commShiftIso m).hom.app X) := by simp [Functor.commShiftOfLocalization_iso_inv_app, Functor.commShiftIso_comp_inv_app] lemma natTransCommShift_hom : letI := Φ.commShift M L₁ L₂ G e NatTrans.CommShift e.hom M := by letI := Φ.commShift M L₁ L₂ G e refine ⟨fun m ↦ ?_⟩ ext X simp [Functor.commShiftIso_comp_hom_app, commShift_iso_hom_app, ← Functor.map_comp_assoc] end variable [W₁.IsCompatibleWithShift M] [W₂.IsCompatibleWithShift M] [L₂.IsLocalization W₂] noncomputable instance : (Φ.localizedFunctor L₁ L₂).CommShift M := Φ.commShift M L₁ L₂ _ (CatCommSq.iso ..) instance : NatTrans.CommShift (CatCommSq.iso Φ.functor W₁.Q W₂.Q (Φ.localizedFunctor W₁.Q W₂.Q)).hom M := natTransCommShift_hom .. end LocalizerMorphism end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Pullback.lean
import Mathlib.CategoryTheory.Shift.Adjunction import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! # The pullback of a shift by a monoid morphism Given a shift by a monoid `B` on a category `C` and a monoid morphism `φ : A →+ B`, we define a shift by `A` on a category `PullbackShift C φ` which is a type synonym for `C`. If `F : C ⥤ D` is a functor between categories equipped with shifts by `B`, we define a type synonym `PullbackShift.functor F φ` for `F`. When `F` has a `CommShift` structure by `B`, we define a pulled back `CommShift` structure by `A` on `PullbackShift.functor F φ`. Similarly, if `τ` is a natural transformation between functors `F,G : C ⥤ D`, we define a type synonym `PullbackShift.natTrans τ φ : PullbackShift.functor F φ ⟶ PullbackShift.functor G φ`. When `τ` has a `CommShift` structure by `B` (i.e. is compatible with `CommShift` structures on `F` and `G`), we define a pulled back `CommShift` structure by `A` on `PullbackShift.natTrans τ φ`. Finally, if we have an adjunction `F ⊣ G` (with `G : D ⥤ C`), we define a type synonym `PullbackShift.adjunction adj φ : PullbackShift.functor F φ ⊣ PullbackShift.functor G φ` and we show that, if `adj` compatible with `CommShift` structures on `F` and `G`, then `PullbackShift.adjunction adj φ` iis also compatible with the pulled back `CommShift` structures. -/ namespace CategoryTheory open Limits Category variable (C : Type*) [Category C] {A B : Type*} [AddMonoid A] [AddMonoid B] (φ : A →+ B) [HasShift C B] /-- The category `PullbackShift C φ` is equipped with a shift such that for all `a`, the shift functor by `a` is `shiftFunctor C (φ a)`. -/ @[nolint unusedArguments] def PullbackShift (_ : A →+ B) [HasShift C B] := C instance : Category (PullbackShift C φ) := by dsimp only [PullbackShift] infer_instance attribute [local instance] endofunctorMonoidalCategory /-- The shift on `PullbackShift C φ` is obtained by precomposing the shift on `C` with the monoidal functor `Discrete.addMonoidalFunctor φ : Discrete A ⥤ Discrete B`. -/ noncomputable instance : HasShift (PullbackShift C φ) A where shift := Discrete.addMonoidalFunctor φ ⋙ shiftMonoidalFunctor C B instance [HasZeroObject C] : HasZeroObject (PullbackShift C φ) := by dsimp [PullbackShift] infer_instance instance [Preadditive C] : Preadditive (PullbackShift C φ) := by dsimp [PullbackShift] infer_instance instance [Preadditive C] (a : A) [(shiftFunctor C (φ a)).Additive] : (shiftFunctor (PullbackShift C φ) a).Additive := by change (shiftFunctor C (φ a)).Additive infer_instance /-- When `b = φ a`, this is the canonical isomorphism `shiftFunctor (PullbackShift C φ) a ≅ shiftFunctor C b`. -/ noncomputable def pullbackShiftIso (a : A) (b : B) (h : b = φ a) : shiftFunctor (PullbackShift C φ) a ≅ shiftFunctor C b := eqToIso (by subst h; rfl) variable {C} variable (X : PullbackShift C φ) (a₁ a₂ a₃ : A) (h : a₁ + a₂ = a₃) (b₁ b₂ b₃ : B) (h₁ : b₁ = φ a₁) (h₂ : b₂ = φ a₂) (h₃ : b₃ = φ a₃) lemma pullbackShiftFunctorZero_inv_app : (shiftFunctorZero _ A).inv.app X = (shiftFunctorZero C B).inv.app X ≫ (pullbackShiftIso C φ 0 0 (by simp)).inv.app X := by change (shiftFunctorZero C B).inv.app X ≫ _ = _ dsimp [Discrete.eqToHom, Discrete.addMonoidalFunctor_ε] congr 2 apply eqToHom_map lemma pullbackShiftFunctorZero_hom_app : (shiftFunctorZero _ A).hom.app X = (pullbackShiftIso C φ 0 0 (by simp)).hom.app X ≫ (shiftFunctorZero C B).hom.app X := by rw [← cancel_epi ((shiftFunctorZero _ A).inv.app X), Iso.inv_hom_id_app, pullbackShiftFunctorZero_inv_app, assoc, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app] rfl lemma pullbackShiftFunctorZero'_inv_app : (shiftFunctorZero _ A).inv.app X = (shiftFunctorZero' C (φ 0) (by rw [map_zero])).inv.app X ≫ (pullbackShiftIso C φ 0 (φ 0) rfl).inv.app X := by rw [pullbackShiftFunctorZero_inv_app] simp only [Functor.id_obj, pullbackShiftIso, eqToIso.inv, eqToHom_app, shiftFunctorZero', Iso.trans_inv, NatTrans.comp_app, eqToIso_refl, Iso.refl_inv, NatTrans.id_app, assoc] erw [comp_id] lemma pullbackShiftFunctorZero'_hom_app : (shiftFunctorZero _ A).hom.app X = (pullbackShiftIso C φ 0 (φ 0) rfl).hom.app X ≫ (shiftFunctorZero' C (φ 0) (by rw [map_zero])).hom.app X := by rw [← cancel_epi ((shiftFunctorZero _ A).inv.app X), Iso.inv_hom_id_app, pullbackShiftFunctorZero'_inv_app, assoc, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app] rfl lemma pullbackShiftFunctorAdd'_inv_app : (shiftFunctorAdd' _ a₁ a₂ a₃ h).inv.app X = (shiftFunctor (PullbackShift C φ) a₂).map ((pullbackShiftIso C φ a₁ b₁ h₁).hom.app X) ≫ (pullbackShiftIso C φ a₂ b₂ h₂).hom.app _ ≫ (shiftFunctorAdd' C b₁ b₂ b₃ (by rw [h₁, h₂, h₃, ← h, φ.map_add])).inv.app X ≫ (pullbackShiftIso C φ a₃ b₃ h₃).inv.app X := by subst h₁ h₂ h obtain rfl : b₃ = φ a₁ + φ a₂ := by rw [h₃, φ.map_add] simp only [Functor.comp_obj, NatTrans.naturality_assoc] erw [Functor.map_id, id_comp, id_comp, shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd'_eq_shiftFunctorAdd] change _ ≫ _ = _ congr 1 rw [Discrete.addMonoidalFunctor_μ] dsimp [Discrete.eqToHom] congr 2 apply eqToHom_map lemma pullbackShiftFunctorAdd'_hom_app : (shiftFunctorAdd' _ a₁ a₂ a₃ h).hom.app X = (pullbackShiftIso C φ a₃ b₃ h₃).hom.app X ≫ (shiftFunctorAdd' C b₁ b₂ b₃ (by rw [h₁, h₂, h₃, ← h, φ.map_add])).hom.app X ≫ (pullbackShiftIso C φ a₂ b₂ h₂).inv.app _ ≫ (shiftFunctor (PullbackShift C φ) a₂).map ((pullbackShiftIso C φ a₁ b₁ h₁).inv.app X) := by rw [← cancel_epi ((shiftFunctorAdd' _ a₁ a₂ a₃ h).inv.app X), Iso.inv_hom_id_app, pullbackShiftFunctorAdd'_inv_app φ X a₁ a₂ a₃ h b₁ b₂ b₃ h₁ h₂ h₃, assoc, assoc, assoc, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app_assoc, Iso.hom_inv_id_app_assoc, ← Functor.map_comp, Iso.hom_inv_id_app, Functor.map_id] rfl variable {D : Type*} [Category D] [HasShift D B] (F : C ⥤ D) [F.CommShift B] /-- The functor `F`, seen as a functor from `PullbackShift C φ` to `PullbackShift D φ`. Then a `CommShift B` instance on `F` will define a `CommShift A` instance on `PullbackShift.functor F φ`, and we won't have to juggle with two `CommShift` instances on `F`. -/ def PullbackShift.functor : PullbackShift C φ ⥤ PullbackShift D φ := F variable {F} in /-- The natural transformation `τ`, seen as a natural transformation from `PullbackShift.functor F φ` to `PullbackShift.functor G φ`. Then a `CommShift B` instance on `τ` will define a `CommShift A` instance on `PullbackShift.natTrans τ φ`, and we won't have to juggle with two `CommShift` instances on `τ`. -/ def PullbackShift.natTrans {G : C ⥤ D} (τ : F ⟶ G) : PullbackShift.functor φ F ⟶ PullbackShift.functor φ G := τ namespace Functor /-- If `F : C ⥤ D` commutes with the shifts on `C` and `D`, then `PullbackShift.functor F φ` commutes with their pullbacks by an additive map `φ`. -/ noncomputable instance commShiftPullback : (PullbackShift.functor φ F).CommShift A where commShiftIso a := isoWhiskerRight (pullbackShiftIso C φ a (φ a) rfl) F ≪≫ F.commShiftIso (φ a) ≪≫ isoWhiskerLeft _ (pullbackShiftIso D φ a (φ a) rfl).symm commShiftIso_zero := by ext dsimp simp only [F.commShiftIso_zero' (A := B) (φ 0) (by rw [map_zero]), CommShift.isoZero'_hom_app, assoc, CommShift.isoZero_hom_app, pullbackShiftFunctorZero'_hom_app, map_comp, pullbackShiftFunctorZero'_inv_app] rfl commShiftIso_add _ _ := by ext simp only [PullbackShift.functor, comp_obj, Iso.trans_hom, isoWhiskerRight_hom, isoWhiskerLeft_hom, Iso.symm_hom, NatTrans.comp_app, whiskerRight_app, whiskerLeft_app, CommShift.isoAdd_hom_app, map_comp, assoc] rw [F.commShiftIso_add' (φ.map_add _ _).symm, ← shiftFunctorAdd'_eq_shiftFunctorAdd, ← shiftFunctorAdd'_eq_shiftFunctorAdd, pullbackShiftFunctorAdd'_hom_app φ _ _ _ _ rfl _ _ _ rfl rfl rfl, pullbackShiftFunctorAdd'_inv_app φ _ _ _ _ rfl _ _ _ rfl rfl rfl] simp only [CommShift.isoAdd'_hom_app, assoc, map_comp, NatTrans.naturality_assoc, Iso.inv_hom_id_app_assoc] slice_rhs 9 10 => rw [← map_comp, Iso.inv_hom_id_app, map_id] simp only [comp_obj, id_comp] rw [← Functor.comp_map F (shiftFunctor D _), ← (F.commShiftIso _).hom.naturality_assoc] slice_rhs 4 5 => rw [← map_comp, (pullbackShiftIso C φ _ _ rfl).hom.naturality, map_comp] slice_rhs 3 4 => rw [← map_comp, Iso.inv_hom_id_app, map_id] simp only [comp_obj, id_comp, comp_map, assoc] slice_rhs 3 4 => rw [← map_comp, ← map_comp, Iso.inv_hom_id_app, map_id, map_id] rw [id_comp, assoc, assoc] rfl lemma commShiftPullback_iso_eq (a : A) (b : B) (h : b = φ a) : (PullbackShift.functor φ F).commShiftIso a (C := PullbackShift C φ) (D := PullbackShift D φ) = isoWhiskerRight (pullbackShiftIso C φ a b h) F ≪≫ (F.commShiftIso b) ≪≫ isoWhiskerLeft F (pullbackShiftIso D φ a b h).symm := by obtain rfl : b = φ a := h rfl end Functor namespace NatTrans variable {F} {G : C ⥤ D} [G.CommShift B] open Functor in instance commShiftPullback (τ : F ⟶ G) [NatTrans.CommShift τ B] : NatTrans.CommShift (PullbackShift.natTrans φ τ) A where shift_comm _ := by ext dsimp [PullbackShift.natTrans] simp only [commShiftPullback_iso_eq φ _ _ _ rfl, Iso.trans_hom, isoWhiskerRight_hom, isoWhiskerLeft_hom, Iso.symm_hom, comp_app, comp_obj, whiskerRight_app, whiskerLeft_app, assoc] rw [← τ.naturality_assoc] simp [← NatTrans.shift_app_comm_assoc] variable (C) in /-- The natural isomorphism between the identity of `PullbackShift C φ` and the pullback of the identity of `C`. -/ def PullbackShift.natIsoId : 𝟭 (PullbackShift C φ) ≅ PullbackShift.functor φ (𝟭 C) := Iso.refl _ /-- This expresses the compatibility between two `CommShift` structures by `A` on (synonyms of) `𝟭 C`: the canonical `CommShift` structure on `𝟭 (PullbackShift C φ)`, and the `CommShift` structure on `PullbackShift.functor (𝟭 C) φ` (i.e the pullback of the canonical `CommShift` structure on `𝟭 C`). -/ instance : NatTrans.CommShift (PullbackShift.natIsoId C φ).hom A where shift_comm _ := by ext simp [PullbackShift.natIsoId, Functor.commShiftPullback_iso_eq] variable (F) {E : Type*} [Category E] [HasShift E B] (G : D ⥤ E) [G.CommShift B] /-- The natural isomorphism between the pullback of `F ⋙ G` and the composition of the pullbacks of `F` and `G`. -/ def PullbackShift.natIsoComp : PullbackShift.functor φ (F ⋙ G) ≅ PullbackShift.functor φ F ⋙ PullbackShift.functor φ G := Iso.refl _ /- Suppose that `F` and `G` have `CommShift` structure by `B`. This expresses the compatibility between two `CommShift` structures by `A` on (synonyms of) `F ⋙ G`: the `CommShift` structure on `PullbackShift.functor (F ⋙ G) φ` (i.e the pullback of the composition of `CommShift` structures by `B` on `F` and `G`), and that on `PullbackShift.functor F φ ⋙ PullbackShift.functor G φ` (i.e. the one coming from the composition of the pulled back `CommShift` structures on `F` and `G`). -/ open Functor in instance : NatTrans.CommShift (PullbackShift.natIsoComp φ F G).hom A where shift_comm _ := by ext dsimp [PullbackShift.natIsoComp] simp only [commShiftPullback_iso_eq φ _ _ _ rfl, Iso.trans_hom, isoWhiskerRight_hom, isoWhiskerLeft_hom, Iso.symm_hom, comp_app, comp_obj, whiskerRight_app, Functor.comp_map, commShiftIso_comp_hom_app, whiskerLeft_app, assoc, map_id, comp_id, map_comp, id_comp] dsimp [PullbackShift.functor] slice_rhs 3 4 => rw [← G.map_comp, Iso.inv_hom_id_app] simp end NatTrans /-- The adjunction `adj`, seen as an adjunction between `PullbackShift.functor F φ` and `PullbackShift.functor G φ`. -/ @[simps -isSimp] def PullbackShift.adjunction {F} {G : D ⥤ C} (adj : F ⊣ G) : PullbackShift.functor φ F ⊣ PullbackShift.functor φ G where unit := (NatTrans.PullbackShift.natIsoId C φ).hom ≫ PullbackShift.natTrans φ adj.unit ≫ (NatTrans.PullbackShift.natIsoComp φ F G).hom counit := (NatTrans.PullbackShift.natIsoComp φ G F).inv ≫ PullbackShift.natTrans φ adj.counit ≫ (NatTrans.PullbackShift.natIsoId D φ).inv left_triangle_components _ := by simp [PullbackShift.natTrans, NatTrans.PullbackShift.natIsoComp, NatTrans.PullbackShift.natIsoId, PullbackShift.functor] right_triangle_components _ := by simp [PullbackShift.natTrans, NatTrans.PullbackShift.natIsoComp, NatTrans.PullbackShift.natIsoId, PullbackShift.functor] namespace Adjunction variable {F} {G : D ⥤ C} (adj : F ⊣ G) [G.CommShift B] /-- If an adjunction `F ⊣ G` is compatible with `CommShift` structures on `F` and `G`, then it is also compatible with the pulled back `CommShift` structures by an additive map `φ : B →+ A`. -/ instance commShiftPullback [adj.CommShift B] : (PullbackShift.adjunction φ adj).CommShift A where commShift_unit := by dsimp [PullbackShift.adjunction] infer_instance commShift_counit := by dsimp [PullbackShift.adjunction] infer_instance end Adjunction end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/ShiftedHom.lean
import Mathlib.CategoryTheory.Shift.CommShift import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Linear.LinearFunctor /-! Shifted morphisms Given a category `C` endowed with a shift by an additive monoid `M` and two objects `X` and `Y` in `C`, we consider the types `ShiftedHom X Y m` defined as `X ⟶ (Y⟦m⟧)` for all `m : M`, and the composition on these shifted hom. -/ namespace CategoryTheory open Category variable {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] {M : Type*} [AddMonoid M] [HasShift C M] [HasShift D M] [HasShift E M] /-- In a category `C` equipped with a shift by an additive monoid, this is the type of morphisms `X ⟶ (Y⟦n⟧)` for `m : M`. -/ def ShiftedHom (X Y : C) (m : M) : Type _ := X ⟶ (Y⟦m⟧) instance [Preadditive C] (X Y : C) (n : M) : AddCommGroup (ShiftedHom X Y n) := inferInstanceAs (AddCommGroup (_ ⟶ _)) namespace ShiftedHom variable {X Y Z T : C} /-- The composition of `f : X ⟶ Y⟦a⟧` and `g : Y ⟶ Z⟦b⟧`, as a morphism `X ⟶ Z⟦c⟧` when `b + a = c`. -/ noncomputable def comp {a b c : M} (f : ShiftedHom X Y a) (g : ShiftedHom Y Z b) (h : b + a = c) : ShiftedHom X Z c := f ≫ g⟦a⟧' ≫ (shiftFunctorAdd' C b a c h).inv.app _ lemma comp_assoc {a₁ a₂ a₃ a₁₂ a₂₃ a : M} (α : ShiftedHom X Y a₁) (β : ShiftedHom Y Z a₂) (γ : ShiftedHom Z T a₃) (h₁₂ : a₂ + a₁ = a₁₂) (h₂₃ : a₃ + a₂ = a₂₃) (h : a₃ + a₂ + a₁ = a) : (α.comp β h₁₂).comp γ (show a₃ + a₁₂ = a by rw [← h₁₂, ← add_assoc, h]) = α.comp (β.comp γ h₂₃) (by rw [← h₂₃, h]) := by simp only [comp, assoc, Functor.map_comp, shiftFunctorAdd'_assoc_inv_app a₃ a₂ a₁ a₂₃ a₁₂ a h₂₃ h₁₂ h, ← NatTrans.naturality_assoc, Functor.comp_map] /-! In degree `0 : M`, shifted hom `ShiftedHom X Y 0` identify to morphisms `X ⟶ Y`. We generalize this to `m₀ : M` such that `m₀ : 0` as it shall be convenient when we apply this with `M := ℤ` and `m₀` the coercion of `0 : ℕ`. -/ /-- The element of `ShiftedHom X Y m₀` (when `m₀ = 0`) attached to a morphism `X ⟶ Y`. -/ noncomputable def mk₀ (m₀ : M) (hm₀ : m₀ = 0) (f : X ⟶ Y) : ShiftedHom X Y m₀ := f ≫ (shiftFunctorZero' C m₀ hm₀).inv.app Y /-- The bijection `(X ⟶ Y) ≃ ShiftedHom X Y m₀` when `m₀ = 0`. -/ @[simps apply] noncomputable def homEquiv (m₀ : M) (hm₀ : m₀ = 0) : (X ⟶ Y) ≃ ShiftedHom X Y m₀ where toFun f := mk₀ m₀ hm₀ f invFun g := g ≫ (shiftFunctorZero' C m₀ hm₀).hom.app Y left_inv f := by simp [mk₀] right_inv g := by simp [mk₀] lemma mk₀_comp (m₀ : M) (hm₀ : m₀ = 0) (f : X ⟶ Y) {a : M} (g : ShiftedHom Y Z a) : (mk₀ m₀ hm₀ f).comp g (by rw [hm₀, add_zero]) = f ≫ g := by subst hm₀ simp [comp, mk₀, shiftFunctorAdd'_add_zero_inv_app, shiftFunctorZero'] @[simp] lemma mk₀_id_comp (m₀ : M) (hm₀ : m₀ = 0) {a : M} (f : ShiftedHom X Y a) : (mk₀ m₀ hm₀ (𝟙 X)).comp f (by rw [hm₀, add_zero]) = f := by simp [mk₀_comp] lemma comp_mk₀ {a : M} (f : ShiftedHom X Y a) (m₀ : M) (hm₀ : m₀ = 0) (g : Y ⟶ Z) : f.comp (mk₀ m₀ hm₀ g) (by rw [hm₀, zero_add]) = f ≫ g⟦a⟧' := by subst hm₀ simp only [comp, shiftFunctorAdd'_zero_add_inv_app, mk₀, shiftFunctorZero', eqToIso_refl, Iso.refl_trans, ← Functor.map_comp, assoc, Iso.inv_hom_id_app, Functor.id_obj, comp_id] @[simp] lemma comp_mk₀_id {a : M} (f : ShiftedHom X Y a) (m₀ : M) (hm₀ : m₀ = 0) : f.comp (mk₀ m₀ hm₀ (𝟙 Y)) (by rw [hm₀, zero_add]) = f := by simp [comp_mk₀] @[simp] lemma mk₀_comp_mk₀ (f : X ⟶ Y) (g : Y ⟶ Z) {a b c : M} (h : b + a = c) (ha : a = 0) (hb : b = 0) : (mk₀ a ha f).comp (mk₀ b hb g) h = mk₀ c (by rw [← h, ha, hb, add_zero]) (f ≫ g) := by subst ha hb obtain rfl : c = 0 := by rw [← h, zero_add] rw [mk₀_comp, mk₀, mk₀, assoc] @[simp] lemma mk₀_comp_mk₀_assoc (f : X ⟶ Y) (g : Y ⟶ Z) {a : M} (ha : a = 0) {d : M} (h : ShiftedHom Z T d) : (mk₀ a ha f).comp ((mk₀ a ha g).comp h (show _ = d by rw [ha, add_zero])) (show _ = d by rw [ha, add_zero]) = (mk₀ a ha (f ≫ g)).comp h (by rw [ha, add_zero]) := by subst ha rw [← comp_assoc, mk₀_comp_mk₀] all_goals simp section Preadditive variable [Preadditive C] variable (X Y) in @[simp] lemma mk₀_zero (m₀ : M) (hm₀ : m₀ = 0) : mk₀ m₀ hm₀ (0 : X ⟶ Y) = 0 := by simp [mk₀] @[simp] lemma comp_add [∀ (a : M), (shiftFunctor C a).Additive] {a b c : M} (α : ShiftedHom X Y a) (β₁ β₂ : ShiftedHom Y Z b) (h : b + a = c) : α.comp (β₁ + β₂) h = α.comp β₁ h + α.comp β₂ h := by rw [comp, comp, comp, Functor.map_add, Preadditive.add_comp, Preadditive.comp_add] @[simp] lemma add_comp {a b c : M} (α₁ α₂ : ShiftedHom X Y a) (β : ShiftedHom Y Z b) (h : b + a = c) : (α₁ + α₂).comp β h = α₁.comp β h + α₂.comp β h := by rw [comp, comp, comp, Preadditive.add_comp] @[simp] lemma comp_neg [∀ (a : M), (shiftFunctor C a).Additive] {a b c : M} (α : ShiftedHom X Y a) (β : ShiftedHom Y Z b) (h : b + a = c) : α.comp (-β) h = -α.comp β h := by rw [comp, comp, Functor.map_neg, Preadditive.neg_comp, Preadditive.comp_neg] @[simp] lemma neg_comp {a b c : M} (α : ShiftedHom X Y a) (β : ShiftedHom Y Z b) (h : b + a = c) : (-α).comp β h = -α.comp β h := by rw [comp, comp, Preadditive.neg_comp] variable (Z) in @[simp] lemma comp_zero [∀ (a : M), (shiftFunctor C a).PreservesZeroMorphisms] {a : M} (β : ShiftedHom X Y a) {b c : M} (h : b + a = c) : β.comp (0 : ShiftedHom Y Z b) h = 0 := by rw [comp, Functor.map_zero, Limits.zero_comp, Limits.comp_zero] variable (X) in @[simp] lemma zero_comp (a : M) {b c : M} (β : ShiftedHom Y Z b) (h : b + a = c) : (0 : ShiftedHom X Y a).comp β h = 0 := by rw [comp, Limits.zero_comp] end Preadditive /-- The action on `ShiftedHom` of a functor which commutes with the shift. -/ def map {a : M} (f : ShiftedHom X Y a) (F : C ⥤ D) [F.CommShift M] : ShiftedHom (F.obj X) (F.obj Y) a := F.map f ≫ (F.commShiftIso a).hom.app Y @[simp] lemma map_mk₀ (m₀ : M) (hm₀ : m₀ = 0) (f : X ⟶ Y) (F : C ⥤ D) [F.CommShift M] : (ShiftedHom.mk₀ m₀ hm₀ f).map F = .mk₀ _ hm₀ (F.map f) := by subst hm₀ simp [map, mk₀, shiftFunctorZero', F.commShiftIso_zero M, ← Functor.map_comp_assoc] @[simp] lemma id_map {a : M} (f : ShiftedHom X Y a) : f.map (𝟭 C) = f := by simp [map] lemma comp_map {a : M} (f : ShiftedHom X Y a) (F : C ⥤ D) [F.CommShift M] (G : D ⥤ E) [G.CommShift M] : f.map (F ⋙ G) = (f.map F).map G := by simp [map, Functor.commShiftIso_comp_hom_app] lemma map_comp {a b c : M} (f : ShiftedHom X Y a) (g : ShiftedHom Y Z b) (h : b + a = c) (F : C ⥤ D) [F.CommShift M] : (f.comp g h).map F = (f.map F).comp (g.map F) h := by dsimp [comp, map] simp only [Functor.map_comp, assoc] erw [← NatTrans.naturality_assoc] simp only [Functor.comp_map, F.commShiftIso_add' h, Functor.CommShift.isoAdd'_hom_app, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.comp_obj, comp_id] section Linear variable {R : Type*} [Ring R] [Preadditive C] [Linear R C] instance (X Y : C) (n : M) : Module R (ShiftedHom X Y n) := inferInstanceAs (Module R (_ ⟶ _)) @[simp] lemma comp_smul [∀ (a : M), Functor.Linear R (shiftFunctor C a)] (r : R) {a b c : M} (α : ShiftedHom X Y a) (β : ShiftedHom Y Z b) (h : b + a = c) : α.comp (r • β) h = r • α.comp β h := by rw [comp, Functor.map_smul, comp, Linear.smul_comp, Linear.comp_smul] @[simp] lemma smul_comp (r : R) {a b c : M} (α : ShiftedHom X Y a) (β : ShiftedHom Y Z b) (h : b + a = c) : (r • α).comp β h = r • α.comp β h := by rw [comp, comp, Linear.smul_comp] @[simp] lemma mk₀_smul (m₀ : M) (hm₀ : m₀ = 0) (r : R) {f : X ⟶ Y} : mk₀ m₀ hm₀ (r • f) = r • mk₀ m₀ hm₀ f := by simp [mk₀] end Linear end ShiftedHom end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Adjunction.lean
import Mathlib.CategoryTheory.Shift.CommShift import Mathlib.CategoryTheory.Adjunction.Mates /-! # Adjoints commute with shifts Given categories `C` and `D` that have shifts by an additive group `A`, functors `F : C ⥤ D` and `G : C ⥤ D`, an adjunction `F ⊣ G` and a `CommShift` structure on `F`, this file constructs a `CommShift` structure on `G`. We also do the construction in the other direction: given a `CommShift` structure on `G`, we construct a `CommShift` structure on `G`; we could do this using opposite categories, but the construction is simple enough that it is not really worth it. As an easy application, if `E : C ≌ D` is an equivalence and `E.functor` has a `CommShift` structure, we get a `CommShift` structure on `E.inverse`. We now explain the construction of a `CommShift` structure on `G` given a `CommShift` structure on `F`; the other direction is similar. The `CommShift` structure on `G` must be compatible with the one on `F` in the following sense (cf. `Adjunction.CommShift`): for every `a` in `A`, the natural transformation `adj.unit : 𝟭 C ⟶ G ⋙ F` commutes with the isomorphism `shiftFunctor C A ⋙ G ⋙ F ≅ G ⋙ F ⋙ shiftFunctor C A` induces by `F.commShiftIso a` and `G.commShiftIso a`. We actually require a similar condition for `adj.counit`, but it follows from the one for `adj.unit`. In order to simplify the construction of the `CommShift` structure on `G`, we first introduce the compatibility condition on `adj.unit` for a fixed `a` in `A` and for isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`. We then prove that: - If `e₁` and `e₂` satisfy this condition, then `e₁` uniquely determines `e₂` and vice versa. - If `a = 0`, the isomorphisms `Functor.CommShift.isoZero F` and `Functor.CommShift.isoZero G` satisfy the condition. - The condition is stable by addition on `A`, if we use `Functor.CommShift.isoAdd` to deduce commutation isomorphism for `a + b` from such isomorphism from `a` and `b`. - Given commutation isomorphisms for `F`, our candidate commutation isomorphisms for `G`, constructed in `Adjunction.RightAdjointCommShift.iso`, satisfy the compatibility condition. Once we have established all this, the compatibility of the commutation isomorphism for `F` expressed in `CommShift.zero` and `CommShift.add` immediately implies the similar statements for the commutation isomorphisms for `G`. -/ namespace CategoryTheory open Category namespace Adjunction variable {C D : Type*} [Category C] [Category D] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) {A : Type*} [AddMonoid A] [HasShift C A] [HasShift D A] namespace CommShift variable {a b : A} (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₁' : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (f₁ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) (e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a) (e₂' : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a) (f₂ : shiftFunctor D b ⋙ G ≅ G ⋙ shiftFunctor C b) /-- Given an adjunction `adj : F ⊣ G`, `a` in `A` and commutation isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`, this expresses the compatibility of `e₁` and `e₂` with the unit of the adjunction `adj`. -/ abbrev CompatibilityUnit := ∀ (X : C), (adj.unit.app X)⟦a⟧' = adj.unit.app (X⟦a⟧) ≫ G.map (e₁.hom.app X) ≫ e₂.hom.app _ /-- Given an adjunction `adj : F ⊣ G`, `a` in `A` and commutation isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`, this expresses the compatibility of `e₁` and `e₂` with the counit of the adjunction `adj`. -/ abbrev CompatibilityCounit := ∀ (Y : D), adj.counit.app (Y⟦a⟧) = F.map (e₂.hom.app Y) ≫ e₁.hom.app _ ≫ (adj.counit.app Y)⟦a⟧' /-- Given an adjunction `adj : F ⊣ G`, `a` in `A` and commutation isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`, compatibility of `e₁` and `e₂` with the unit of the adjunction `adj` implies compatibility with the counit of `adj`. -/ lemma compatibilityCounit_of_compatibilityUnit (h : CompatibilityUnit adj e₁ e₂) : CompatibilityCounit adj e₁ e₂ := by intro Y have eq := h (G.obj Y) simp only [← cancel_mono (e₂.inv.app _ ≫ G.map (e₁.inv.app _)), assoc, Iso.hom_inv_id_app_assoc, comp_id, ← Functor.map_comp, Iso.hom_inv_id_app, Functor.comp_obj, Functor.map_id] at eq apply (adj.homEquiv _ _).injective dsimp rw [adj.homEquiv_unit, adj.homEquiv_unit, G.map_comp, adj.unit_naturality_assoc, ← eq] simp only [assoc, ← Functor.map_comp, Iso.inv_hom_id_app_assoc] erw [← e₂.inv.naturality] dsimp simp only [right_triangle_components, ← Functor.map_comp_assoc, Functor.map_id, id_comp, Iso.hom_inv_id_app, Functor.comp_obj] /-- Given an adjunction `adj : F ⊣ G`, `a` in `A` and commutation isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`, if `e₁` and `e₂` are compatible with the unit of the adjunction `adj`, then we get a formula for `e₂.inv` in terms of `e₁`. -/ lemma compatibilityUnit_right (h : CompatibilityUnit adj e₁ e₂) (Y : D) : e₂.inv.app Y = adj.unit.app _ ≫ G.map (e₁.hom.app _) ≫ G.map ((adj.counit.app _)⟦a⟧') := by have := h (G.obj Y) rw [← cancel_mono (e₂.inv.app _), assoc, assoc, Iso.hom_inv_id_app] at this erw [comp_id] at this rw [← assoc, ← this, assoc]; erw [← e₂.inv.naturality] rw [← cancel_mono (e₂.hom.app _)] simp only [Functor.comp_obj, Iso.inv_hom_id_app, Functor.id_obj, Functor.comp_map, assoc, comp_id, ← (shiftFunctor C a).map_comp, right_triangle_components, Functor.map_id] /-- Given an adjunction `adj : F ⊣ G`, `a` in `A` and commutation isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`, if `e₁` and `e₂` are compatible with the counit of the adjunction `adj`, then we get a formula for `e₁.hom` in terms of `e₂`. -/ lemma compatibilityCounit_left (h : CompatibilityCounit adj e₁ e₂) (X : C) : e₁.hom.app X = F.map ((adj.unit.app X)⟦a⟧') ≫ F.map (e₂.inv.app _) ≫ adj.counit.app _ := by have := h (F.obj X) rw [← cancel_epi (F.map (e₂.inv.app _)), ← assoc, ← F.map_comp, Iso.inv_hom_id_app, F.map_id, id_comp] at this rw [this] erw [e₁.hom.naturality_assoc] rw [Functor.comp_map, ← Functor.map_comp, left_triangle_components] simp only [Functor.comp_obj, Functor.id_obj, Functor.map_id, comp_id] /-- Given an adjunction `adj : F ⊣ G`, `a` in `A` and commutation isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`, if `e₁` and `e₂` are compatible with the unit of the adjunction `adj`, then `e₁` uniquely determines `e₂`. -/ lemma compatibilityUnit_unique_right (h : CompatibilityUnit adj e₁ e₂) (h' : CompatibilityUnit adj e₁ e₂') : e₂ = e₂' := by rw [← Iso.symm_eq_iff] ext rw [Iso.symm_hom, Iso.symm_hom, compatibilityUnit_right adj e₁ e₂ h, compatibilityUnit_right adj e₁ e₂' h'] /-- Given an adjunction `adj : F ⊣ G`, `a` in `A` and commutation isomorphisms `e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` and `e₂ : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a`, if `e₁` and `e₂` are compatible with the unit of the adjunction `adj`, then `e₂` uniquely determines `e₁`. -/ lemma compatibilityUnit_unique_left (h : CompatibilityUnit adj e₁ e₂) (h' : CompatibilityUnit adj e₁' e₂) : e₁ = e₁' := by ext rw [compatibilityCounit_left adj e₁ e₂ (compatibilityCounit_of_compatibilityUnit adj _ _ h), compatibilityCounit_left adj e₁' e₂ (compatibilityCounit_of_compatibilityUnit adj _ _ h')] /-- The isomorphisms `Functor.CommShift.isoZero F` and `Functor.CommShift.isoZero G` are compatible with the unit of an adjunction `F ⊣ G`. -/ lemma compatibilityUnit_isoZero : CompatibilityUnit adj (Functor.CommShift.isoZero F A) (Functor.CommShift.isoZero G A) := by intro simp only [Functor.id_obj, Functor.comp_obj, Functor.CommShift.isoZero_hom_app, Functor.map_comp, assoc, unit_naturality_assoc, ← cancel_mono ((shiftFunctorZero C A).hom.app _), ← G.map_comp_assoc, Iso.inv_hom_id_app, Functor.id_obj, Functor.map_id, id_comp, NatTrans.naturality, Functor.id_map, assoc, comp_id] /-- Given an adjunction `adj : F ⊣ G`, `a, b` in `A` and commutation isomorphisms between shifts by `a` (resp. `b`) and `F` and `G`, if these commutation isomorphisms are compatible with the unit of `adj`, then so are the commutation isomorphisms between shifts by `a + b` and `F` and `G` constructed by `Functor.CommShift.isoAdd`. -/ lemma compatibilityUnit_isoAdd (h : CompatibilityUnit adj e₁ e₂) (h' : CompatibilityUnit adj f₁ f₂) : CompatibilityUnit adj (Functor.CommShift.isoAdd e₁ f₁) (Functor.CommShift.isoAdd e₂ f₂) := by intro X have := h' (X⟦a⟧) simp only [← cancel_mono (f₂.inv.app _), assoc, Iso.hom_inv_id_app, Functor.id_obj, Functor.comp_obj, comp_id] at this simp only [Functor.id_obj, Functor.comp_obj, Functor.CommShift.isoAdd_hom_app, Functor.map_comp, assoc, unit_naturality_assoc] slice_rhs 5 6 => rw [← G.map_comp, Iso.inv_hom_id_app] simp only [Functor.comp_obj, Functor.map_id, id_comp, assoc] erw [f₂.hom.naturality_assoc] rw [← reassoc_of% this, ← cancel_mono ((shiftFunctorAdd C a b).hom.app _), assoc, assoc, assoc, assoc, assoc, assoc, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app] dsimp rw [← (shiftFunctor C b).map_comp_assoc, ← (shiftFunctor C b).map_comp_assoc, assoc, ← h X, NatTrans.naturality] dsimp rw [comp_id] end CommShift variable (A) [F.CommShift A] [G.CommShift A] /-- The property for `CommShift` structures on `F` and `G` to be compatible with an adjunction `F ⊣ G`. -/ class CommShift : Prop where commShift_unit : NatTrans.CommShift adj.unit A := by infer_instance commShift_counit : NatTrans.CommShift adj.counit A := by infer_instance open CommShift in attribute [instance] commShift_unit commShift_counit @[reassoc (attr := simp)] lemma unit_app_commShiftIso_hom_app [adj.CommShift A] (a : A) (X : C) : adj.unit.app (X⟦a⟧) ≫ ((F ⋙ G).commShiftIso a).hom.app X = (adj.unit.app X)⟦a⟧' := by simpa using (NatTrans.shift_app_comm adj.unit a X).symm @[reassoc (attr := simp)] lemma unit_app_shift_commShiftIso_inv_app [adj.CommShift A] (a : A) (X : C) : (adj.unit.app X)⟦a⟧' ≫ ((F ⋙ G).commShiftIso a).inv.app X = adj.unit.app (X⟦a⟧) := by simp [← cancel_mono (((F ⋙ G).commShiftIso _).hom.app _)] @[reassoc (attr := simp)] lemma commShiftIso_hom_app_counit_app_shift [adj.CommShift A] (a : A) (Y : D) : ((G ⋙ F).commShiftIso a).hom.app Y ≫ (adj.counit.app Y)⟦a⟧' = adj.counit.app (Y⟦a⟧) := by simpa using (NatTrans.shift_app_comm adj.counit a Y) @[reassoc (attr := simp)] lemma commShiftIso_inv_app_counit_app [adj.CommShift A] (a : A) (Y : D) : ((G ⋙ F).commShiftIso a).inv.app Y ≫ adj.counit.app (Y⟦a⟧) = (adj.counit.app Y)⟦a⟧' := by simp [← cancel_epi (((G ⋙ F).commShiftIso _).hom.app _)] namespace CommShift /-- Constructor for `Adjunction.CommShift`. -/ lemma mk' (_ : NatTrans.CommShift adj.unit A) : adj.CommShift A where commShift_counit := ⟨fun a ↦ by ext simp only [Functor.comp_obj, Functor.id_obj, NatTrans.comp_app, Functor.commShiftIso_comp_hom_app, Functor.whiskerRight_app, assoc, Functor.whiskerLeft_app, Functor.commShiftIso_id_hom_app, comp_id] refine (compatibilityCounit_of_compatibilityUnit adj _ _ (fun X ↦ ?_) _).symm simpa [Functor.commShiftIso_comp_hom_app] using NatTrans.shift_app_comm adj.unit a X⟩ variable [adj.CommShift A] /-- The identity adjunction is compatible with the trivial `CommShift` structure on the identity functor. -/ instance instId : (Adjunction.id (C := C)).CommShift A where commShift_counit := inferInstanceAs (NatTrans.CommShift (𝟭 C).leftUnitor.hom A) commShift_unit := inferInstanceAs (NatTrans.CommShift (𝟭 C).leftUnitor.inv A) variable {E : Type*} [Category E] {F' : D ⥤ E} {G' : E ⥤ D} (adj' : F' ⊣ G') [HasShift E A] [F'.CommShift A] [G'.CommShift A] [adj.CommShift A] [adj'.CommShift A] /-- Compatibility of `Adjunction.Commshift` with the composition of adjunctions. -/ instance instComp : (adj.comp adj').CommShift A where commShift_counit := by rw [comp_counit] infer_instance commShift_unit := by rw [comp_unit] infer_instance end CommShift variable {A} @[reassoc] lemma shift_unit_app [adj.CommShift A] (a : A) (X : C) : (adj.unit.app X)⟦a⟧' = adj.unit.app (X⟦a⟧) ≫ G.map ((F.commShiftIso a).hom.app X) ≫ (G.commShiftIso a).hom.app (F.obj X) := by simpa [Functor.commShiftIso_comp_hom_app] using NatTrans.shift_app_comm adj.unit a X @[reassoc] lemma shift_counit_app [adj.CommShift A] (a : A) (Y : D) : (adj.counit.app Y)⟦a⟧' = (F.commShiftIso a).inv.app (G.obj Y) ≫ F.map ((G.commShiftIso a).inv.app Y) ≫ adj.counit.app (Y⟦a⟧) := by have eq := NatTrans.shift_app_comm adj.counit a Y simp only [Functor.comp_obj, Functor.id_obj, Functor.commShiftIso_comp_hom_app, assoc, Functor.commShiftIso_id_hom_app, comp_id] at eq simp only [← eq, Functor.comp_obj, Functor.id_obj, ← F.map_comp_assoc, Iso.inv_hom_id_app, F.map_id, id_comp, Iso.inv_hom_id_app_assoc] end Adjunction namespace Adjunction variable {C D : Type*} [Category C] [Category D] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) {A : Type*} [AddGroup A] [HasShift C A] [HasShift D A] namespace RightAdjointCommShift variable (a b : A) (h : b + a = 0) [F.CommShift A] /-- Auxiliary definition for `iso`. -/ noncomputable def iso' : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a := (conjugateIsoEquiv (Adjunction.comp adj (shiftEquiv' D b a h).toAdjunction) (Adjunction.comp (shiftEquiv' C b a h).toAdjunction adj)).toFun (F.commShiftIso b) /-- Given an adjunction `F ⊣ G` and a `CommShift` structure on `F`, these are the candidate `CommShift.iso a` isomorphisms for a compatible `CommShift` structure on `G`. -/ noncomputable def iso : shiftFunctor D a ⋙ G ≅ G ⋙ shiftFunctor C a := iso' adj _ _ (neg_add_cancel a) @[reassoc] lemma iso_hom_app (X : D) : (iso adj a).hom.app X = (shiftFunctorCompIsoId C b a h).inv.app (G.obj ((shiftFunctor D a).obj X)) ≫ (adj.unit.app ((shiftFunctor C b).obj (G.obj ((shiftFunctor D a).obj X))))⟦a⟧' ≫ (G.map ((F.commShiftIso b).hom.app (G.obj ((shiftFunctor D a).obj X))))⟦a⟧' ≫ (G.map ((shiftFunctor D b).map (adj.counit.app ((shiftFunctor D a).obj X))))⟦a⟧' ≫ (G.map ((shiftFunctorCompIsoId D a b (by rw [← add_left_inj a, add_assoc, h, zero_add, add_zero])).hom.app X))⟦a⟧' := by obtain rfl : b = -a := by rw [← add_left_inj a, h, neg_add_cancel] simp [iso, iso', shiftEquiv'] @[reassoc] lemma iso_inv_app (Y : D) : (iso adj a).inv.app Y = adj.unit.app ((shiftFunctor C a).obj (G.obj Y)) ≫ G.map ((shiftFunctorCompIsoId D b a h).inv.app (F.obj ((shiftFunctor C a).obj (G.obj Y)))) ≫ G.map ((shiftFunctor D a).map ((shiftFunctor D b).map ((F.commShiftIso a).hom.app (G.obj Y)))) ≫ G.map ((shiftFunctor D a).map ((shiftFunctorCompIsoId D a b (by rw [eq_neg_of_add_eq_zero_left h, add_neg_cancel])).hom.app (F.obj (G.obj Y)))) ≫ G.map ((shiftFunctor D a).map (adj.counit.app Y)) := by obtain rfl : b = -a := by rw [← add_left_inj a, h, neg_add_cancel] simp only [iso, iso', shiftEquiv', Equiv.toFun_as_coe, conjugateIsoEquiv_apply_inv, conjugateEquiv_apply_app, Functor.comp_obj, comp_unit_app, Functor.id_obj, Equivalence.toAdjunction_unit, Equivalence.Equivalence_mk'_unit, Iso.symm_hom, Functor.comp_map, comp_counit_app, Equivalence.toAdjunction_counit, Equivalence.Equivalence_mk'_counit, Functor.map_shiftFunctorCompIsoId_hom_app, assoc, Functor.map_comp] slice_lhs 3 4 => rw [← Functor.map_comp, ← Functor.map_comp, Iso.inv_hom_id_app] simp only [Functor.comp_obj, Functor.map_id, id_comp, assoc] /-- The commutation isomorphisms of `Adjunction.RightAdjointCommShift.iso` are compatible with the unit of the adjunction. -/ lemma compatibilityUnit_iso (a : A) : CommShift.CompatibilityUnit adj (F.commShiftIso a) (iso adj a) := by intro rw [← cancel_mono ((RightAdjointCommShift.iso adj a).inv.app _), assoc, assoc, Iso.hom_inv_id_app, RightAdjointCommShift.iso_inv_app adj _ _ (neg_add_cancel a)] apply (adj.homEquiv _ _).symm.injective dsimp simp only [comp_id, homEquiv_counit, Functor.map_comp, assoc, counit_naturality, counit_naturality_assoc, left_triangle_components_assoc] erw [← NatTrans.naturality_assoc] dsimp rw [shift_shiftFunctorCompIsoId_hom_app, Iso.inv_hom_id_app_assoc, Functor.commShiftIso_hom_naturality_assoc, ← Functor.map_comp, left_triangle_components, Functor.map_id, comp_id] end RightAdjointCommShift variable (A) open RightAdjointCommShift in /-- Given an adjunction `F ⊣ G` and a `CommShift` structure on `F`, this constructs the unique compatible `CommShift` structure on `G`. -/ @[simps -isSimp] noncomputable def rightAdjointCommShift [F.CommShift A] : G.CommShift A where commShiftIso a := iso adj a commShiftIso_zero := by refine CommShift.compatibilityUnit_unique_right adj (F.commShiftIso 0) _ _ (compatibilityUnit_iso adj 0) ?_ rw [F.commShiftIso_zero] exact CommShift.compatibilityUnit_isoZero adj commShiftIso_add a b := by refine CommShift.compatibilityUnit_unique_right adj (F.commShiftIso (a + b)) _ _ (compatibilityUnit_iso adj (a + b)) ?_ rw [F.commShiftIso_add] exact CommShift.compatibilityUnit_isoAdd adj _ _ _ _ (compatibilityUnit_iso adj a) (compatibilityUnit_iso adj b) lemma commShift_of_leftAdjoint [F.CommShift A] : letI := adj.rightAdjointCommShift A adj.CommShift A := by letI := adj.rightAdjointCommShift A refine CommShift.mk' _ _ ⟨fun a ↦ ?_⟩ ext X dsimp simpa only [Functor.commShiftIso_id_hom_app, Functor.comp_obj, Functor.id_obj, id_comp, Functor.commShiftIso_comp_hom_app] using RightAdjointCommShift.compatibilityUnit_iso adj a X namespace LeftAdjointCommShift variable {A} (a b : A) (h : a + b = 0) [G.CommShift A] /-- Auxiliary definition for `iso`. -/ noncomputable def iso' : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a := (conjugateIsoEquiv (Adjunction.comp adj (shiftEquiv' D a b h).toAdjunction) (Adjunction.comp (shiftEquiv' C a b h).toAdjunction adj)).invFun (G.commShiftIso b) /-- Given an adjunction `F ⊣ G` and a `CommShift` structure on `G`, these are the candidate `CommShift.iso a` isomorphisms for a compatible `CommShift` structure on `F`. -/ noncomputable def iso : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a := iso' adj _ _ (add_neg_cancel a) @[reassoc] lemma iso_hom_app (X : C) : (iso adj a).hom.app X = F.map ((adj.unit.app X)⟦a⟧') ≫ F.map (G.map (((shiftFunctorCompIsoId D a b h).inv.app (F.obj X)))⟦a⟧') ≫ F.map (((G.commShiftIso b).hom.app ((F.obj X)⟦a⟧))⟦a⟧') ≫ F.map ((shiftFunctorCompIsoId C b a (by simp [eq_neg_of_add_eq_zero_left h])).hom.app (G.obj ((F.obj X)⟦a⟧))) ≫ adj.counit.app ((F.obj X)⟦a⟧) := by obtain rfl : b = -a := eq_neg_of_add_eq_zero_right h simp [iso, iso', shiftEquiv'] @[reassoc] lemma iso_inv_app (Y : C) : (iso adj a).inv.app Y = (F.map ((shiftFunctorCompIsoId C a b h).inv.app Y))⟦a⟧' ≫ (F.map ((adj.unit.app (Y⟦a⟧))⟦b⟧'))⟦a⟧' ≫ (F.map ((G.commShiftIso b).inv.app (F.obj (Y⟦a⟧))))⟦a⟧' ≫ (adj.counit.app ((F.obj (Y⟦a⟧))⟦b⟧))⟦a⟧' ≫ (shiftFunctorCompIsoId D b a (by simp [eq_neg_of_add_eq_zero_left h])).hom.app (F.obj (Y⟦a⟧)) := by obtain rfl : b = -a := eq_neg_of_add_eq_zero_right h simp [iso, iso', shiftEquiv'] /-- The commutation isomorphisms of `Adjunction.LeftAdjointCommShift.iso` are compatible with the unit of the adjunction. -/ lemma compatibilityUnit_iso (a : A) : CommShift.CompatibilityUnit adj (iso adj a) (G.commShiftIso a) := by intro rw [LeftAdjointCommShift.iso_hom_app adj _ _ (add_neg_cancel a)] simp only [Functor.id_obj, Functor.comp_obj, Functor.map_shiftFunctorCompIsoId_inv_app, Functor.map_comp, assoc, unit_naturality_assoc, right_triangle_components_assoc] slice_rhs 4 5 => rw [← Functor.map_comp, Iso.inv_hom_id_app] simp only [Functor.comp_obj, Functor.map_id, id_comp] rw [shift_shiftFunctorCompIsoId_inv_app, ← Functor.comp_map, (shiftFunctorCompIsoId C _ _ (neg_add_cancel a)).hom.naturality_assoc] simp end LeftAdjointCommShift open LeftAdjointCommShift in /-- Given an adjunction `F ⊣ G` and a `CommShift` structure on `G`, this constructs the unique compatible `CommShift` structure on `F`. -/ @[simps -isSimp] noncomputable def leftAdjointCommShift [G.CommShift A] : F.CommShift A where commShiftIso a := iso adj a commShiftIso_zero := by refine CommShift.compatibilityUnit_unique_left adj _ _ (G.commShiftIso 0) (compatibilityUnit_iso adj 0) ?_ rw [G.commShiftIso_zero] exact CommShift.compatibilityUnit_isoZero adj commShiftIso_add a b := by refine CommShift.compatibilityUnit_unique_left adj _ _ (G.commShiftIso (a + b)) (compatibilityUnit_iso adj (a + b)) ?_ rw [G.commShiftIso_add] exact CommShift.compatibilityUnit_isoAdd adj _ _ _ _ (compatibilityUnit_iso adj a) (compatibilityUnit_iso adj b) lemma commShift_of_rightAdjoint [G.CommShift A] : letI := adj.leftAdjointCommShift A adj.CommShift A := by letI := adj.leftAdjointCommShift A refine CommShift.mk' _ _ ⟨fun a ↦ ?_⟩ ext X dsimp simpa only [Functor.commShiftIso_id_hom_app, Functor.comp_obj, Functor.id_obj, id_comp, Functor.commShiftIso_comp_hom_app] using LeftAdjointCommShift.compatibilityUnit_iso adj a X end Adjunction namespace Equivalence variable {C D : Type*} [Category C] [Category D] (E : C ≌ D) section variable (A : Type*) [AddMonoid A] [HasShift C A] [HasShift D A] /-- If `E : C ≌ D` is an equivalence, this expresses the compatibility of `CommShift` structures on `E.functor` and `E.inverse`. -/ abbrev CommShift [E.functor.CommShift A] [E.inverse.CommShift A] : Prop := E.toAdjunction.CommShift A namespace CommShift variable [E.functor.CommShift A] [E.inverse.CommShift A] instance [E.CommShift A] : NatTrans.CommShift E.unitIso.hom A := inferInstanceAs (NatTrans.CommShift E.toAdjunction.unit A) instance [E.CommShift A] : NatTrans.CommShift E.counitIso.hom A := inferInstanceAs (NatTrans.CommShift E.toAdjunction.counit A) instance [h : E.functor.CommShift A] : E.symm.inverse.CommShift A := h instance [h : E.inverse.CommShift A] : E.symm.functor.CommShift A := h /-- Constructor for `Equivalence.CommShift`. -/ lemma mk' (h : NatTrans.CommShift E.unitIso.hom A) : E.CommShift A where commShift_unit := h commShift_counit := (Adjunction.CommShift.mk' E.toAdjunction A h).commShift_counit /-- The forward functor of the identity equivalence is compatible with shifts. -/ instance : (Equivalence.refl (C := C)).functor.CommShift A := by dsimp infer_instance /-- The inverse functor of the identity equivalence is compatible with shifts. -/ instance : (Equivalence.refl (C := C)).inverse.CommShift A := by dsimp infer_instance /-- The identity equivalence is compatible with shifts. -/ instance : (Equivalence.refl (C := C)).CommShift A := by dsimp [Equivalence.CommShift, refl_toAdjunction] infer_instance /-- If an equivalence `E : C ≌ D` is compatible with shifts, so is `E.symm`. -/ instance [E.CommShift A] : E.symm.CommShift A := mk' E.symm A (inferInstanceAs (NatTrans.CommShift E.counitIso.inv A)) /-- Constructor for `Equivalence.CommShift`. -/ lemma mk'' (h : NatTrans.CommShift E.counitIso.hom A) : E.CommShift A := have := mk' E.symm A (inferInstanceAs (NatTrans.CommShift E.counitIso.inv A)) inferInstanceAs (E.symm.symm.CommShift A) variable {F : Type*} [Category F] [HasShift F A] {E' : D ≌ F} [E.CommShift A] [E'.functor.CommShift A] [E'.inverse.CommShift A] [E'.CommShift A] /-- If `E : C ≌ D` and `E' : D ≌ F` are equivalence whose forward functors are compatible with shifts, so is `(E.trans E').functor`. -/ instance : (E.trans E').functor.CommShift A := by dsimp infer_instance /-- If `E : C ≌ D` and `E' : D ≌ F` are equivalence whose inverse functors are compatible with shifts, so is `(E.trans E').inverse`. -/ instance : (E.trans E').inverse.CommShift A := by dsimp infer_instance /-- If equivalences `E : C ≌ D` and `E' : D ≌ F` are compatible with shifts, so is `E.trans E'`. -/ instance : (E.trans E').CommShift A := inferInstanceAs ((E.toAdjunction.comp E'.toAdjunction).CommShift A) end CommShift end variable (A : Type*) [AddGroup A] [HasShift C A] [HasShift D A] /-- If `E : C ≌ D` is an equivalence and we have a `CommShift` structure on `E.functor`, this constructs the unique compatible `CommShift` structure on `E.inverse`. -/ noncomputable def commShiftInverse [E.functor.CommShift A] : E.inverse.CommShift A := E.toAdjunction.rightAdjointCommShift A lemma commShift_of_functor [E.functor.CommShift A] : letI := E.commShiftInverse A E.CommShift A := by letI := E.commShiftInverse A exact CommShift.mk' _ _ (E.toAdjunction.commShift_of_leftAdjoint A).commShift_unit /-- If `E : C ≌ D` is an equivalence and we have a `CommShift` structure on `E.inverse`, this constructs the unique compatible `CommShift` structure on `E.functor`. -/ noncomputable def commShiftFunctor [E.inverse.CommShift A] : E.functor.CommShift A := E.symm.toAdjunction.rightAdjointCommShift A lemma commShift_of_inverse [E.inverse.CommShift A] : letI := E.commShiftFunctor A E.CommShift A := by letI := E.commShiftFunctor A have := E.symm.commShift_of_functor A exact inferInstanceAs (E.symm.symm.CommShift A) end Equivalence end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/InducedShiftSequence.lean
import Mathlib.CategoryTheory.Shift.CommShift import Mathlib.CategoryTheory.Shift.ShiftSequence /-! # Induced shift sequences When `G : C ⥤ A` is a functor from a category equipped with a shift by a monoid `M`, we have defined in the file `CategoryTheory.Shift.ShiftSequence` a type class `G.ShiftSequence M` which provides functors `G.shift a : C ⥤ A` for all `a : M`, isomorphisms `shiftFunctor C n ⋙ G.shift a ≅ G.shift a'` when `n + a = a'`, and isomorphisms `G.isoShift a : shiftFunctor C a ⋙ G ≅ G.shift a` for all `a`, all of which satisfy good coherence properties. The idea is that it allows to use functors `G.shift a` which may have better definitional properties than `shiftFunctor C a ⋙ G`. The typical example shall be `[(homologyFunctor C (ComplexShape.up ℤ) 0).ShiftSequence ℤ]` for any abelian category `C` (TODO). Similarly as a shift on a category may induce a shift on a quotient or a localized category (see the file `CategoryTheory.Shift.Induced`), this file shows that under certain assumptions, there is an induced "shift sequence". The main application will be the construction of a shift sequence for the homology functor on the homotopy category of cochain complexes (TODO), and also on the derived category (TODO). -/ open CategoryTheory Category Functor namespace CategoryTheory variable {C D A : Type*} [Category C] [Category D] [Category A] {L : C ⥤ D} {F : D ⥤ A} {G : C ⥤ A} (e : L ⋙ F ≅ G) (M : Type*) [AddMonoid M] [HasShift C M] [G.ShiftSequence M] (F' : M → D ⥤ A) (e' : ∀ m, L ⋙ F' m ≅ G.shift m) [((whiskeringLeft C D A).obj L).Full] [((whiskeringLeft C D A).obj L).Faithful] namespace Functor namespace ShiftSequence namespace induced /-- The `isoZero` field of the induced shift sequence. -/ noncomputable def isoZero : F' 0 ≅ F := ((whiskeringLeft C D A).obj L).preimageIso (e' 0 ≪≫ G.isoShiftZero M ≪≫ e.symm) lemma isoZero_hom_app_obj (X : C) : (isoZero e M F' e').hom.app (L.obj X) = (e' 0).hom.app X ≫ (isoShiftZero G M).hom.app X ≫ e.inv.app X := NatTrans.congr_app (((whiskeringLeft C D A).obj L).map_preimage _) X variable (L G) variable [HasShift D M] [L.CommShift M] /-- The `shiftIso` field of the induced shift sequence. -/ noncomputable def shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor D n ⋙ F' a ≅ F' a' := by exact ((whiskeringLeft C D A).obj L).preimageIso ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (L.commShiftIso n).symm _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (e' a) ≪≫ G.shiftIso n a a' ha' ≪≫ (e' a').symm) lemma shiftIso_hom_app_obj (n a a' : M) (ha' : n + a = a') (X : C) : (shiftIso L G M F' e' n a a' ha').hom.app (L.obj X) = (F' a).map ((L.commShiftIso n).inv.app X) ≫ (e' a).hom.app (X⟦n⟧) ≫ (G.shiftIso n a a' ha').hom.app X ≫ (e' a').inv.app X := (NatTrans.congr_app (((whiskeringLeft C D A).obj L).map_preimage _) X).trans (by simp) attribute [irreducible] isoZero shiftIso end induced variable [HasShift D M] [L.CommShift M] /-- Given an isomorphism of functors `e : L ⋙ F ≅ G` relating functors `L : C ⥤ D`, `F : D ⥤ A` and `G : C ⥤ A`, an additive monoid `M`, a family of functors `F' : M → D ⥤ A` equipped with isomorphisms `e' : ∀ m, L ⋙ F' m ≅ G.shift m`, this is the shift sequence induced on `F` induced by a shift sequence for the functor `G`, provided that the functor `(whiskeringLeft C D A).obj L` of precomposition by `L` is fully faithful. -/ noncomputable def induced : F.ShiftSequence M where sequence := F' isoZero := induced.isoZero e M F' e' shiftIso := induced.shiftIso L G M F' e' shiftIso_zero a := by ext1 apply ((whiskeringLeft C D A).obj L).map_injective ext K dsimp simp only [induced.shiftIso_hom_app_obj, shiftIso_zero_hom_app, id_obj, NatTrans.naturality, comp_map, Iso.hom_inv_id_app_assoc, comp_id, ← Functor.map_comp, L.commShiftIso_zero, CommShift.isoZero_inv_app, assoc, Iso.inv_hom_id_app, Functor.map_id] shiftIso_add n m a a' a'' ha' ha'' := by ext1 apply ((whiskeringLeft C D A).obj L).map_injective ext K dsimp simp only [id_comp, induced.shiftIso_hom_app_obj, G.shiftIso_add_hom_app n m a a' a'' ha' ha'', L.commShiftIso_add, comp_obj, CommShift.isoAdd_inv_app, (F' a).map_comp, assoc, ← (e' a).hom.naturality_assoc, comp_map] simp only [← NatTrans.naturality_assoc, induced.shiftIso_hom_app_obj, ← Functor.map_comp_assoc, ← Functor.map_comp, Iso.inv_hom_id_app, comp_obj, Functor.map_id, id_comp] dsimp simp only [Functor.map_comp, assoc, Iso.inv_hom_id_app_assoc] @[simp, reassoc] lemma induced_isoShiftZero_hom_app_obj (X : C) : letI := (induced e M F' e') (F.isoShiftZero M).hom.app (L.obj X) = (e' 0).hom.app X ≫ (isoShiftZero G M).hom.app X ≫ e.inv.app X := by apply induced.isoZero_hom_app_obj @[simp, reassoc] lemma induced_shiftIso_hom_app_obj (n a a' : M) (ha' : n + a = a') (X : C) : letI := (induced e M F' e') (F.shiftIso n a a' ha').hom.app (L.obj X) = (F.shift a).map ((L.commShiftIso n).inv.app X) ≫ (e' a).hom.app (X⟦n⟧) ≫ (G.shiftIso n a a' ha').hom.app X ≫ (e' a').inv.app X := by apply induced.shiftIso_hom_app_obj @[reassoc] lemma induced_shiftMap {n : M} {X Y : C} (f : X ⟶ Y⟦n⟧) (a a' : M) (h : n + a = a') : letI := induced e M F' e' F.shiftMap (L.map f ≫ (L.commShiftIso n).hom.app _) a a' h = (e' a).hom.app X ≫ G.shiftMap f a a' h ≫ (e' a').inv.app Y := by dsimp [shiftMap] rw [Functor.map_comp, induced_shiftIso_hom_app_obj, assoc, assoc] nth_rw 2 [← Functor.map_comp_assoc] simp only [comp_obj, Iso.hom_inv_id_app, map_id, id_comp] rw [← NatTrans.naturality_assoc] rfl end ShiftSequence end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Shift/Induced.lean
import Mathlib.CategoryTheory.Shift.CommShift /-! # Shift induced from a category to another In this file, we introduce a sufficient condition on a functor `F : C ⥤ D` so that a shift on `C` by a monoid `A` induces a shift on `D`. More precisely, when the functor `(D ⥤ D) ⥤ C ⥤ D` given by the precomposition with `F` is fully faithful, and that all the shift functors on `C` can be lifted to functors `D ⥤ D` (i.e. we have functors `s a : D ⥤ D` for all `a : A`, and isomorphisms `F ⋙ s a ≅ shiftFunctor C a ⋙ F`), then these functors `s a` are the shift functors of a term of type `HasShift D A`. As this condition on the functor `F` is satisfied for quotient and localization functors, the main construction `HasShift.induced` in this file shall be used for both quotient and localized shifts. -/ namespace CategoryTheory open Functor variable {C D : Type _} [Category C] [Category D] (F : C ⥤ D) {A : Type _} [AddMonoid A] [HasShift C A] (s : A → D ⥤ D) (i : ∀ a, F ⋙ s a ≅ shiftFunctor C a ⋙ F) [((whiskeringLeft C D D).obj F).Full] [((whiskeringLeft C D D).obj F).Faithful] namespace HasShift namespace Induced /-- The `zero` field of the `ShiftMkCore` structure for the induced shift. -/ noncomputable def zero : s 0 ≅ 𝟭 D := ((whiskeringLeft C D D).obj F).preimageIso ((i 0) ≪≫ isoWhiskerRight (shiftFunctorZero C A) F ≪≫ F.leftUnitor ≪≫ F.rightUnitor.symm) /-- The `add` field of the `ShiftMkCore` structure for the induced shift. -/ noncomputable def add (a b : A) : s (a + b) ≅ s a ⋙ s b := ((whiskeringLeft C D D).obj F).preimageIso (i (a + b) ≪≫ isoWhiskerRight (shiftFunctorAdd C a b) F ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (i b).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (i a).symm _ ≪≫ Functor.associator _ _ _) @[simp] lemma zero_hom_app_obj (X : C) : (zero F s i).hom.app (F.obj X) = (i 0).hom.app X ≫ F.map ((shiftFunctorZero C A).hom.app X) := by have h : whiskerLeft F (zero F s i).hom = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) @[simp] lemma zero_inv_app_obj (X : C) : (zero F s i).inv.app (F.obj X) = F.map ((shiftFunctorZero C A).inv.app X) ≫ (i 0).inv.app X := by have h : whiskerLeft F (zero F s i).inv = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) @[simp] lemma add_hom_app_obj (a b : A) (X : C) : (add F s i a b).hom.app (F.obj X) = (i (a + b)).hom.app X ≫ F.map ((shiftFunctorAdd C a b).hom.app X) ≫ (i b).inv.app ((shiftFunctor C a).obj X) ≫ (s b).map ((i a).inv.app X) := by have h : whiskerLeft F (add F s i a b).hom = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) @[simp] lemma add_inv_app_obj (a b : A) (X : C) : (add F s i a b).inv.app (F.obj X) = (s b).map ((i a).hom.app X) ≫ (i b).hom.app ((shiftFunctor C a).obj X) ≫ F.map ((shiftFunctorAdd C a b).inv.app X) ≫ (i (a + b)).inv.app X := by have h : whiskerLeft F (add F s i a b).inv = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) end Induced variable (A) /-- When `F : C ⥤ D` is a functor satisfying suitable technical assumptions, this is the induced term of type `HasShift D A` deduced from `[HasShift C A]`. -/ noncomputable def induced : HasShift D A := hasShiftMk D A { F := s zero := Induced.zero F s i add := Induced.add F s i zero_add_hom_app := fun n => by suffices (Induced.add F s i 0 n).hom = eqToHom (by rw [zero_add]; rfl) ≫ whiskerRight (Induced.zero F s i ).inv (s n) by intro X simpa using NatTrans.congr_app this X apply ((whiskeringLeft C D D).obj F).map_injective ext X have eq := dcongr_arg (fun a => (i a).hom.app X) (zero_add n) dsimp simp only [Induced.add_hom_app_obj, eq, shiftFunctorAdd_zero_add_hom_app, Functor.map_comp, eqToHom_map, Category.assoc, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, eqToHom_app, Induced.zero_inv_app_obj] erw [← NatTrans.naturality_assoc, Iso.hom_inv_id_app_assoc] rfl add_zero_hom_app := fun n => by suffices (Induced.add F s i n 0).hom = eqToHom (by rw [add_zero]; rfl) ≫ whiskerLeft (s n) (Induced.zero F s i).inv by intro X simpa using NatTrans.congr_app this X apply ((whiskeringLeft C D D).obj F).map_injective ext X dsimp erw [Induced.add_hom_app_obj, dcongr_arg (fun a => (i a).hom.app X) (add_zero n), ← cancel_mono ((s 0).map ((i n).hom.app X)), Category.assoc, Category.assoc, Category.assoc, Category.assoc, Category.assoc, Category.assoc, ← (s 0).map_comp, Iso.inv_hom_id_app, Functor.map_id, Category.comp_id, ← NatTrans.naturality, Induced.zero_inv_app_obj, shiftFunctorAdd_add_zero_hom_app] simp [eqToHom_map, eqToHom_app] assoc_hom_app := fun m₁ m₂ m₃ => by suffices (Induced.add F s i (m₁ + m₂) m₃).hom ≫ whiskerRight (Induced.add F s i m₁ m₂).hom (s m₃) = eqToHom (by rw [add_assoc]) ≫ (Induced.add F s i m₁ (m₂ + m₃)).hom ≫ whiskerLeft (s m₁) (Induced.add F s i m₂ m₃).hom by intro X simpa using NatTrans.congr_app this X apply ((whiskeringLeft C D D).obj F).map_injective ext X dsimp have eq := F.congr_map (shiftFunctorAdd'_assoc_hom_app m₁ m₂ m₃ _ _ (m₁+m₂+m₃) rfl rfl rfl X) simp only [shiftFunctorAdd'_eq_shiftFunctorAdd] at eq simp only [Functor.comp_obj, Functor.map_comp, shiftFunctorAdd', Iso.trans_hom, eqToIso.hom, NatTrans.comp_app, eqToHom_app, Category.assoc] at eq rw [← cancel_mono ((s m₃).map ((s m₂).map ((i m₁).hom.app X)))] simp only [Induced.add_hom_app_obj, Category.assoc, Functor.map_comp] slice_lhs 4 5 => erw [← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id] erw [Category.id_comp] slice_lhs 6 7 => erw [← Functor.map_comp, ← Functor.map_comp, Iso.inv_hom_id_app, (s m₂).map_id, (s m₃).map_id] erw [Category.comp_id, ← NatTrans.naturality_assoc, reassoc_of% eq, dcongr_arg (fun a => (i a).hom.app X) (add_assoc m₁ m₂ m₃).symm] simp only [Functor.comp_obj, eqToHom_map, eqToHom_app, NatTrans.naturality_assoc, Induced.add_hom_app_obj, Functor.comp_map, Category.assoc, Iso.inv_hom_id_app_assoc, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, Category.comp_id, ← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id] } end HasShift lemma shiftFunctor_of_induced (a : A) : letI := HasShift.induced F A s i shiftFunctor D a = s a := rfl variable (A) @[simp] lemma shiftFunctorZero_hom_app_obj_of_induced (X : C) : letI := HasShift.induced F A s i (shiftFunctorZero D A).hom.app (F.obj X) = (i 0).hom.app X ≫ F.map ((shiftFunctorZero C A).hom.app X) := by simp only [ShiftMkCore.shiftFunctorZero_eq, HasShift.Induced.zero_hom_app_obj] @[simp] lemma shiftFunctorZero_inv_app_obj_of_induced (X : C) : letI := HasShift.induced F A s i (shiftFunctorZero D A).inv.app (F.obj X) = F.map ((shiftFunctorZero C A).inv.app X) ≫ (i 0).inv.app X := by simp only [ShiftMkCore.shiftFunctorZero_eq, HasShift.Induced.zero_inv_app_obj] variable {A} @[simp] lemma shiftFunctorAdd_hom_app_obj_of_induced (a b : A) (X : C) : letI := HasShift.induced F A s i (shiftFunctorAdd D a b).hom.app (F.obj X) = (i (a + b)).hom.app X ≫ F.map ((shiftFunctorAdd C a b).hom.app X) ≫ (i b).inv.app ((shiftFunctor C a).obj X) ≫ (s b).map ((i a).inv.app X) := by simp only [ShiftMkCore.shiftFunctorAdd_eq, HasShift.Induced.add_hom_app_obj] @[simp] lemma shiftFunctorAdd_inv_app_obj_of_induced (a b : A) (X : C) : letI := HasShift.induced F A s i (shiftFunctorAdd D a b).inv.app (F.obj X) = (s b).map ((i a).hom.app X) ≫ (i b).hom.app ((shiftFunctor C a).obj X) ≫ F.map ((shiftFunctorAdd C a b).inv.app X) ≫ (i (a + b)).inv.app X := by simp only [ShiftMkCore.shiftFunctorAdd_eq, HasShift.Induced.add_inv_app_obj] variable (A) /-- When the target category of a functor `F : C ⥤ D` is equipped with the induced shift, this is the compatibility of `F` with the shifts on the categories `C` and `D`. -/ noncomputable def Functor.CommShift.ofInduced : letI := HasShift.induced F A s i F.CommShift A := by letI := HasShift.induced F A s i exact { commShiftIso := fun a => (i a).symm commShiftIso_zero := by ext X dsimp simp only [isoZero_hom_app, shiftFunctorZero_inv_app_obj_of_induced, ← F.map_comp_assoc, Iso.hom_inv_id_app, F.map_id, Category.id_comp] commShiftIso_add := fun a b => by ext X dsimp simp only [isoAdd_hom_app, Iso.symm_hom, shiftFunctorAdd_inv_app_obj_of_induced, shiftFunctor_of_induced] rw [← Functor.map_comp_assoc, Iso.inv_hom_id_app] dsimp rw [Functor.map_id, Category.id_comp, Iso.inv_hom_id_app_assoc, ← F.map_comp_assoc, Iso.hom_inv_id_app, F.map_id, Category.id_comp] } lemma Functor.commShiftIso_eq_ofInduced (a : A) : letI := HasShift.induced F A s i letI := Functor.CommShift.ofInduced F A s i F.commShiftIso a = (i a).symm := rfl end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/LiftingProperty.lean
import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.CategoryTheory.MorphismProperty.Retract import Mathlib.CategoryTheory.LiftingProperties.Limits import Mathlib.Order.GaloisConnection.Defs /-! # Left and right lifting properties Given a morphism property `T`, we define the left and right lifting property with respect to `T`. We show that the left lifting property is stable under retracts, cobase change, coproducts, and composition, with dual statements for the right lifting property. -/ universe w v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] (T : MorphismProperty C) namespace MorphismProperty /-- Given `T : MorphismProperty C`, this is the class of morphisms that have the left lifting property (llp) with respect to `T`. -/ def llp : MorphismProperty C := fun _ _ f ↦ ∀ ⦃X Y : C⦄ (g : X ⟶ Y) (_ : T g), HasLiftingProperty f g /-- Given `T : MorphismProperty C`, this is the class of morphisms that have the right lifting property (rlp) with respect to `T`. -/ def rlp : MorphismProperty C := fun _ _ f ↦ ∀ ⦃X Y : C⦄ (g : X ⟶ Y) (_ : T g), HasLiftingProperty g f lemma llp_of_isIso {A B : C} (i : A ⟶ B) [IsIso i] : T.llp i := fun _ _ _ _ ↦ inferInstance lemma rlp_of_isIso {X Y : C} (f : X ⟶ Y) [IsIso f] : T.rlp f := fun _ _ _ _ ↦ inferInstance instance llp_isStableUnderRetracts : T.llp.IsStableUnderRetracts where of_retract h hg _ _ f hf := letI := hg _ hf h.leftLiftingProperty f instance rlp_isStableUnderRetracts : T.rlp.IsStableUnderRetracts where of_retract h hf _ _ g hg := letI := hf _ hg h.rightLiftingProperty g instance llp_isStableUnderCobaseChange : T.llp.IsStableUnderCobaseChange where of_isPushout h hf _ _ g' hg' := letI := hf _ hg' h.hasLiftingProperty g' open IsPullback in instance rlp_isStableUnderBaseChange : T.rlp.IsStableUnderBaseChange where of_isPullback h hf _ _ f' hf' := letI := hf _ hf' h.hasLiftingProperty f' instance llp_isMultiplicative : T.llp.IsMultiplicative where id_mem X _ _ p hp := by infer_instance comp_mem i j hi hj _ _ p hp := by have := hi _ hp have := hj _ hp infer_instance instance rlp_isMultiplicative : T.rlp.IsMultiplicative where id_mem X _ _ p hp := by infer_instance comp_mem i j hi hj _ _ p hp := by have := hi _ hp have := hj _ hp infer_instance instance llp_isStableUnderCoproductsOfShape (J : Type*) : T.llp.IsStableUnderCoproductsOfShape J := by apply IsStableUnderCoproductsOfShape.mk intro A B _ _ f hf X Y p hp have := fun j ↦ hf j _ hp infer_instance instance rlp_isStableUnderProductsOfShape (J : Type*) : T.rlp.IsStableUnderProductsOfShape J := by apply IsStableUnderProductsOfShape.mk intro A B _ _ f hf X Y p hp have := fun j ↦ hf j _ hp infer_instance lemma le_llp_iff_le_rlp (T' : MorphismProperty C) : T ≤ T'.llp ↔ T' ≤ T.rlp := ⟨fun h _ _ _ hp _ _ _ hi ↦ h _ hi _ hp, fun h _ _ _ hi _ _ _ hp ↦ h _ hp _ hi⟩ lemma gc_llp_rlp : GaloisConnection (OrderDual.toDual (α := MorphismProperty C) ∘ llp) (rlp ∘ OrderDual.ofDual) := fun _ _ ↦ le_llp_iff_le_rlp _ _ lemma le_llp_rlp : T ≤ T.rlp.llp := by rw [le_llp_iff_le_rlp] @[simp] lemma rlp_llp_rlp : T.rlp.llp.rlp = T.rlp := gc_llp_rlp.u_l_u_eq_u T @[simp] lemma llp_rlp_llp : T.llp.rlp.llp = T.llp := gc_llp_rlp.l_u_l_eq_l T lemma antitone_rlp : Antitone (rlp : MorphismProperty C → _) := fun _ _ h ↦ gc_llp_rlp.monotone_u h lemma antitone_llp : Antitone (llp : MorphismProperty C → _) := fun _ _ h ↦ gc_llp_rlp.monotone_l h lemma pushouts_le_llp_rlp : T.pushouts ≤ T.rlp.llp := by intro A B i hi exact (T.rlp.llp.isStableUnderCobaseChange_iff_pushouts_le).1 inferInstance i (pushouts_monotone T.le_llp_rlp _ hi) @[simp] lemma rlp_pushouts : T.pushouts.rlp = T.rlp := by apply le_antisymm · exact antitone_rlp T.le_pushouts · rw [← le_llp_iff_le_rlp] exact T.pushouts_le_llp_rlp lemma colimitsOfShape_discrete_le_llp_rlp (J : Type w) : T.colimitsOfShape (Discrete J) ≤ T.rlp.llp := by intro A B i hi exact MorphismProperty.colimitsOfShape_le _ (colimitsOfShape_monotone T.le_llp_rlp _ _ hi) lemma coproducts_le_llp_rlp : (coproducts.{w} T) ≤ T.rlp.llp := by intro A B i hi rw [coproducts_iff] at hi obtain ⟨J, hi⟩ := hi exact T.colimitsOfShape_discrete_le_llp_rlp J _ hi @[simp] lemma rlp_coproducts : (coproducts.{w} T).rlp = T.rlp := by apply le_antisymm · exact antitone_rlp T.le_coproducts · rw [← le_llp_iff_le_rlp] exact T.coproducts_le_llp_rlp lemma retracts_le_llp_rlp : T.retracts ≤ T.rlp.llp := le_trans (retracts_monotone T.le_llp_rlp) T.rlp.llp.retracts_le @[simp] lemma rlp_retracts : T.retracts.rlp = T.rlp := by apply le_antisymm · exact antitone_rlp T.le_retracts · rw [← le_llp_iff_le_rlp] exact T.retracts_le_llp_rlp end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/IsInvertedBy.lean
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic import Mathlib.CategoryTheory.MorphismProperty.Basic /-! # Morphism properties that are inverted by a functor In this file, we introduce the predicate `P.IsInvertedBy F` which expresses that the morphisms satisfying `P : MorphismProperty C` are mapped to isomorphisms by a functor `F : C ⥤ D`. This is used in the localization of categories API (folder `CategoryTheory.Localization`). -/ universe w v v' u u' namespace CategoryTheory namespace MorphismProperty variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] /-- If `P : MorphismProperty C` and `F : C ⥤ D`, then `P.IsInvertedBy F` means that all morphisms in `P` are mapped by `F` to isomorphisms in `D`. -/ def IsInvertedBy (P : MorphismProperty C) (F : C ⥤ D) : Prop := ∀ ⦃X Y : C⦄ (f : X ⟶ Y) (_ : P f), IsIso (F.map f) namespace IsInvertedBy lemma of_le (P Q : MorphismProperty C) (F : C ⥤ D) (hQ : Q.IsInvertedBy F) (h : P ≤ Q) : P.IsInvertedBy F := fun _ _ _ hf => hQ _ (h _ hf) theorem of_comp {C₁ C₂ C₃ : Type*} [Category C₁] [Category C₂] [Category C₃] (W : MorphismProperty C₁) (F : C₁ ⥤ C₂) (hF : W.IsInvertedBy F) (G : C₂ ⥤ C₃) : W.IsInvertedBy (F ⋙ G) := fun X Y f hf => by haveI := hF f hf dsimp infer_instance theorem op {W : MorphismProperty C} {L : C ⥤ D} (h : W.IsInvertedBy L) : W.op.IsInvertedBy L.op := fun X Y f hf => by haveI := h f.unop hf dsimp infer_instance theorem rightOp {W : MorphismProperty C} {L : Cᵒᵖ ⥤ D} (h : W.op.IsInvertedBy L) : W.IsInvertedBy L.rightOp := fun X Y f hf => by haveI := h f.op hf dsimp infer_instance theorem leftOp {W : MorphismProperty C} {L : C ⥤ Dᵒᵖ} (h : W.IsInvertedBy L) : W.op.IsInvertedBy L.leftOp := fun X Y f hf => by haveI := h f.unop hf dsimp infer_instance theorem unop {W : MorphismProperty C} {L : Cᵒᵖ ⥤ Dᵒᵖ} (h : W.op.IsInvertedBy L) : W.IsInvertedBy L.unop := fun X Y f hf => by haveI := h f.op hf dsimp infer_instance lemma prod {C₁ C₂ : Type*} [Category C₁] [Category C₂] {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} {E₁ E₂ : Type*} [Category E₁] [Category E₂] {F₁ : C₁ ⥤ E₁} {F₂ : C₂ ⥤ E₂} (h₁ : W₁.IsInvertedBy F₁) (h₂ : W₂.IsInvertedBy F₂) : (W₁.prod W₂).IsInvertedBy (F₁.prod F₂) := fun _ _ f hf => by rw [isIso_prod_iff] exact ⟨h₁ _ hf.1, h₂ _ hf.2⟩ lemma pi {J : Type w} {C : J → Type u} {D : J → Type u'} [∀ j, Category.{v} (C j)] [∀ j, Category.{v'} (D j)] (W : ∀ j, MorphismProperty (C j)) (F : ∀ j, C j ⥤ D j) (hF : ∀ j, (W j).IsInvertedBy (F j)) : (MorphismProperty.pi W).IsInvertedBy (Functor.pi F) := by intro _ _ f hf rw [isIso_pi_iff] intro j exact hF j _ (hf j) end IsInvertedBy /-- The full subcategory of `C ⥤ D` consisting of functors inverting morphisms in `W` -/ def FunctorsInverting (W : MorphismProperty C) (D : Type*) [Category D] := ObjectProperty.FullSubcategory fun F : C ⥤ D => W.IsInvertedBy F @[ext] lemma FunctorsInverting.ext {W : MorphismProperty C} {F₁ F₂ : FunctorsInverting W D} (h : F₁.obj = F₂.obj) : F₁ = F₂ := by cases F₁ cases F₂ subst h rfl instance (W : MorphismProperty C) (D : Type*) [Category D] : Category (FunctorsInverting W D) := ObjectProperty.FullSubcategory.category _ @[ext] lemma FunctorsInverting.hom_ext {W : MorphismProperty C} {F₁ F₂ : FunctorsInverting W D} {α β : F₁ ⟶ F₂} (h : α.app = β.app) : α = β := NatTrans.ext h /-- A constructor for `W.FunctorsInverting D` -/ def FunctorsInverting.mk {W : MorphismProperty C} {D : Type*} [Category D] (F : C ⥤ D) (hF : W.IsInvertedBy F) : W.FunctorsInverting D := ⟨F, hF⟩ theorem IsInvertedBy.iff_of_iso (W : MorphismProperty C) {F₁ F₂ : C ⥤ D} (e : F₁ ≅ F₂) : W.IsInvertedBy F₁ ↔ W.IsInvertedBy F₂ := by dsimp [IsInvertedBy] simp only [NatIso.isIso_map_iff e] @[simp] lemma IsInvertedBy.isoClosure_iff (W : MorphismProperty C) (F : C ⥤ D) : W.isoClosure.IsInvertedBy F ↔ W.IsInvertedBy F := by constructor · intro h X Y f hf exact h _ (W.le_isoClosure _ hf) · intro h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ simp only [Arrow.iso_w' e, F.map_comp] have := h _ hf' infer_instance @[simp] lemma IsInvertedBy.iff_comp {C₁ C₂ C₃ : Type*} [Category C₁] [Category C₂] [Category C₃] (W : MorphismProperty C₁) (F : C₁ ⥤ C₂) (G : C₂ ⥤ C₃) [G.ReflectsIsomorphisms] : W.IsInvertedBy (F ⋙ G) ↔ W.IsInvertedBy F := by constructor · intro h X Y f hf have : IsIso (G.map (F.map f)) := h _ hf exact isIso_of_reflects_iso (F.map f) G · intro hF exact IsInvertedBy.of_comp W F hF G lemma IsInvertedBy.iff_le_inverseImage_isomorphisms (W : MorphismProperty C) (F : C ⥤ D) : W.IsInvertedBy F ↔ W ≤ (isomorphisms D).inverseImage F := Iff.rfl lemma IsInvertedBy.iff_map_le_isomorphisms (W : MorphismProperty C) (F : C ⥤ D) : W.IsInvertedBy F ↔ W.map F ≤ isomorphisms D := by rw [iff_le_inverseImage_isomorphisms, map_le_iff] lemma IsInvertedBy.map_iff {C₁ C₂ C₃ : Type*} [Category C₁] [Category C₂] [Category C₃] (W : MorphismProperty C₁) (F : C₁ ⥤ C₂) (G : C₂ ⥤ C₃) : (W.map F).IsInvertedBy G ↔ W.IsInvertedBy (F ⋙ G) := by simp only [IsInvertedBy.iff_map_le_isomorphisms, map_map] end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Retract.lean
import Mathlib.CategoryTheory.Retract import Mathlib.CategoryTheory.MorphismProperty.Basic /-! # Stability under retracts Given `P : MorphismProperty C`, we introduce a typeclass `P.IsStableUnderRetracts` which is the property that `P` is stable under retracts. -/ universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] namespace MorphismProperty /-- A class of morphisms is stable under retracts if a retract of such a morphism still lies in the class. -/ @[mk_iff] class IsStableUnderRetracts (P : MorphismProperty C) : Prop where of_retract {X Y Z W : C} {f : X ⟶ Y} {g : Z ⟶ W} (h : RetractArrow f g) (hg : P g) : P f lemma of_retract {P : MorphismProperty C} [P.IsStableUnderRetracts] {X Y Z W : C} {f : X ⟶ Y} {g : Z ⟶ W} (h : RetractArrow f g) (hg : P g) : P f := IsStableUnderRetracts.of_retract h hg instance IsStableUnderRetracts.monomorphisms : (monomorphisms C).IsStableUnderRetracts where of_retract {_ _ _ _ f g} h (hg : Mono g) := ⟨fun α β w ↦ by rw [← cancel_mono h.i.left, ← cancel_mono g, Category.assoc, Category.assoc, h.i_w, reassoc_of% w]⟩ instance IsStableUnderRetracts.epimorphisms : (epimorphisms C).IsStableUnderRetracts where of_retract {_ _ _ _ f g} h (hg : Epi g) := ⟨fun α β w ↦ by rw [← cancel_epi h.r.right, ← cancel_epi g, ← Category.assoc, ← Category.assoc, ← h.r_w, Category.assoc, Category.assoc, w]⟩ instance IsStableUnderRetracts.isomorphisms : (isomorphisms C).IsStableUnderRetracts where of_retract {X Y Z W f g} h (_ : IsIso _) := by refine ⟨h.i.right ≫ inv g ≫ h.r.left, ?_, ?_⟩ · rw [← h.i_w_assoc, IsIso.hom_inv_id_assoc, h.retract_left] · rw [Category.assoc, Category.assoc, h.r_w, IsIso.inv_hom_id_assoc, h.retract_right] instance (P : MorphismProperty C) [P.IsStableUnderRetracts] : P.op.IsStableUnderRetracts where of_retract h₁ h₂ := P.of_retract h₁.unop h₂ instance (P : MorphismProperty Cᵒᵖ) [P.IsStableUnderRetracts] : P.unop.IsStableUnderRetracts where of_retract h₁ h₂ := P.of_retract h₁.op h₂ instance (P₁ P₂ : MorphismProperty C) [P₁.IsStableUnderRetracts] [P₂.IsStableUnderRetracts] : (P₁ ⊓ P₂).IsStableUnderRetracts where of_retract := fun h ⟨h₁, h₂⟩ ↦ ⟨of_retract h h₁, of_retract h h₂⟩ /-- The class of morphisms that are retracts of morphisms belonging to `P : MorphismProperty C`. -/ def retracts (P : MorphismProperty C) : MorphismProperty C := fun _ _ f ↦ ∃ (Z W : C) (g : Z ⟶ W) (_ : RetractArrow f g), P g lemma le_retracts (P : MorphismProperty C) : P ≤ P.retracts := by intro X Y f hf exact ⟨_, _, f, { i := 𝟙 _, r := 𝟙 _}, hf⟩ lemma retracts_monotone : Monotone (retracts (C := C)) := by intro _ _ h _ _ _ ⟨_, _, _, hg, hg'⟩ exact ⟨_, _, _, hg, h _ hg'⟩ lemma isStableUnderRetracts_iff_retracts_le (P : MorphismProperty C) : P.IsStableUnderRetracts ↔ P.retracts ≤ P := by rw [isStableUnderRetracts_iff] constructor · intro h₁ X Y f ⟨_, _, _, h₂, h₃⟩ exact h₁ h₂ h₃ · intro h₁ _ _ _ _ _ _ h₂ h₃ exact h₁ _ ⟨_, _, _, h₂, h₃⟩ lemma retracts_le (P : MorphismProperty C) [P.IsStableUnderRetracts] : P.retracts ≤ P := by rwa [← isStableUnderRetracts_iff_retracts_le] @[simp] lemma retracts_le_iff {P Q : MorphismProperty C} [Q.IsStableUnderRetracts] : P.retracts ≤ Q ↔ P ≤ Q := by constructor · exact le_trans P.le_retracts · intro h exact le_trans (retracts_monotone h) Q.retracts_le instance {P : MorphismProperty C} [P.IsStableUnderRetracts] : P.RespectsIso := RespectsIso.of_respects_arrow_iso _ (fun _ _ e ↦ of_retract (Retract.ofIso e.symm)) end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Composition.lean
import Mathlib.CategoryTheory.MorphismProperty.Basic /-! # Compatibilities of properties of morphisms with respect to composition Given `P : MorphismProperty C`, we define the predicate `P.IsStableUnderComposition` which means that `P f → P g → P (f ≫ g)`. We also introduce the type classes `W.ContainsIdentities`, `W.IsMultiplicative`, and `W.HasTwoOutOfThreeProperty`. -/ universe w v v' u u' namespace CategoryTheory namespace MorphismProperty variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] /-- Typeclass expressing that a morphism property contain identities. -/ class ContainsIdentities (W : MorphismProperty C) : Prop where /-- for all `X : C`, the identity of `X` satisfies the morphism property -/ id_mem : ∀ (X : C), W (𝟙 X) lemma id_mem (W : MorphismProperty C) [W.ContainsIdentities] (X : C) : W (𝟙 X) := ContainsIdentities.id_mem X namespace ContainsIdentities instance op (W : MorphismProperty C) [W.ContainsIdentities] : W.op.ContainsIdentities := ⟨fun X => W.id_mem X.unop⟩ instance unop (W : MorphismProperty Cᵒᵖ) [W.ContainsIdentities] : W.unop.ContainsIdentities := ⟨fun X => W.id_mem (Opposite.op X)⟩ lemma of_op (W : MorphismProperty C) [W.op.ContainsIdentities] : W.ContainsIdentities := (inferInstance : W.op.unop.ContainsIdentities) lemma of_unop (W : MorphismProperty Cᵒᵖ) [W.unop.ContainsIdentities] : W.ContainsIdentities := (inferInstance : W.unop.op.ContainsIdentities) lemma eqToHom (W : MorphismProperty C) [W.ContainsIdentities] {x y : C} (h : x = y) : W (eqToHom h) := by subst h rw [eqToHom_refl] exact id_mem x instance inverseImage {P : MorphismProperty D} [P.ContainsIdentities] (F : C ⥤ D) : (P.inverseImage F).ContainsIdentities where id_mem X := by simpa only [← F.map_id] using P.id_mem (F.obj X) instance inf {P Q : MorphismProperty C} [P.ContainsIdentities] [Q.ContainsIdentities] : (P ⊓ Q).ContainsIdentities where id_mem X := ⟨P.id_mem X, Q.id_mem X⟩ end ContainsIdentities instance Prod.containsIdentities {C₁ C₂ : Type*} [Category C₁] [Category C₂] (W₁ : MorphismProperty C₁) (W₂ : MorphismProperty C₂) [W₁.ContainsIdentities] [W₂.ContainsIdentities] : (prod W₁ W₂).ContainsIdentities := ⟨fun _ => ⟨W₁.id_mem _, W₂.id_mem _⟩⟩ instance Pi.containsIdentities {J : Type w} {C : J → Type u} [∀ j, Category.{v} (C j)] (W : ∀ j, MorphismProperty (C j)) [∀ j, (W j).ContainsIdentities] : (pi W).ContainsIdentities := ⟨fun _ _ => MorphismProperty.id_mem _ _⟩ lemma of_isIso (P : MorphismProperty C) [P.ContainsIdentities] [P.RespectsIso] {X Y : C} (f : X ⟶ Y) [IsIso f] : P f := Category.id_comp f ▸ RespectsIso.postcomp P f (𝟙 X) (P.id_mem X) lemma isomorphisms_le_of_containsIdentities (P : MorphismProperty C) [P.ContainsIdentities] [P.RespectsIso] : isomorphisms C ≤ P := fun _ _ f (_ : IsIso f) ↦ P.of_isIso f /-- A morphism property satisfies `IsStableUnderComposition` if the composition of two such morphisms still falls in the class. -/ class IsStableUnderComposition (P : MorphismProperty C) : Prop where comp_mem {X Y Z} (f : X ⟶ Y) (g : Y ⟶ Z) : P f → P g → P (f ≫ g) lemma comp_mem (W : MorphismProperty C) [W.IsStableUnderComposition] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (hf : W f) (hg : W g) : W (f ≫ g) := IsStableUnderComposition.comp_mem f g hf hg instance (priority := 900) (W : MorphismProperty C) [W.IsStableUnderComposition] : W.Respects W where precomp _ hi _ hf := W.comp_mem _ _ hi hf postcomp _ hi _ hf := W.comp_mem _ _ hf hi instance IsStableUnderComposition.op {P : MorphismProperty C} [P.IsStableUnderComposition] : P.op.IsStableUnderComposition where comp_mem f g hf hg := P.comp_mem g.unop f.unop hg hf instance IsStableUnderComposition.unop {P : MorphismProperty Cᵒᵖ} [P.IsStableUnderComposition] : P.unop.IsStableUnderComposition where comp_mem f g hf hg := P.comp_mem g.op f.op hg hf instance IsStableUnderComposition.inf {P Q : MorphismProperty C} [P.IsStableUnderComposition] [Q.IsStableUnderComposition] : (P ⊓ Q).IsStableUnderComposition where comp_mem f g hf hg := ⟨P.comp_mem f g hf.left hg.left, Q.comp_mem f g hf.right hg.right⟩ /-- A morphism property is `StableUnderInverse` if the inverse of a morphism satisfying the property still falls in the class. -/ def StableUnderInverse (P : MorphismProperty C) : Prop := ∀ ⦃X Y⦄ (e : X ≅ Y), P e.hom → P e.inv theorem StableUnderInverse.op {P : MorphismProperty C} (h : StableUnderInverse P) : StableUnderInverse P.op := fun _ _ e he => h e.unop he theorem StableUnderInverse.unop {P : MorphismProperty Cᵒᵖ} (h : StableUnderInverse P) : StableUnderInverse P.unop := fun _ _ e he => h e.op he theorem respectsIso_of_isStableUnderComposition {P : MorphismProperty C} [P.IsStableUnderComposition] (hP : isomorphisms C ≤ P) : RespectsIso P := RespectsIso.mk _ (fun _ _ hf => P.comp_mem _ _ (hP _ (isomorphisms.infer_property _)) hf) (fun _ _ hf => P.comp_mem _ _ hf (hP _ (isomorphisms.infer_property _))) instance IsStableUnderComposition.inverseImage {P : MorphismProperty D} [P.IsStableUnderComposition] (F : C ⥤ D) : (P.inverseImage F).IsStableUnderComposition where comp_mem f g hf hg := by simpa only [← F.map_comp] using P.comp_mem _ _ hf hg /-- Given `app : Π X, F₁.obj X ⟶ F₂.obj X` where `F₁` and `F₂` are two functors, this is the `morphism_property C` satisfied by the morphisms in `C` with respect to whom `app` is natural. -/ @[simp] def naturalityProperty {F₁ F₂ : C ⥤ D} (app : ∀ X, F₁.obj X ⟶ F₂.obj X) : MorphismProperty C := fun X Y f => F₁.map f ≫ app Y = app X ≫ F₂.map f namespace naturalityProperty instance isStableUnderComposition {F₁ F₂ : C ⥤ D} (app : ∀ X, F₁.obj X ⟶ F₂.obj X) : (naturalityProperty app).IsStableUnderComposition where comp_mem f g hf hg := by simp only [naturalityProperty] at hf hg ⊢ simp only [Functor.map_comp, Category.assoc, hg] slice_lhs 1 2 => rw [hf] rw [Category.assoc] theorem stableUnderInverse {F₁ F₂ : C ⥤ D} (app : ∀ X, F₁.obj X ⟶ F₂.obj X) : (naturalityProperty app).StableUnderInverse := fun X Y e he => by simp only [naturalityProperty] at he ⊢ rw [← cancel_epi (F₁.map e.hom)] slice_rhs 1 2 => rw [he] simp only [Category.assoc, ← F₁.map_comp_assoc, ← F₂.map_comp, e.hom_inv_id, Functor.map_id, Category.id_comp, Category.comp_id] end naturalityProperty /-- A morphism property is multiplicative if it contains identities and is stable by composition. -/ class IsMultiplicative (W : MorphismProperty C) : Prop extends W.ContainsIdentities, W.IsStableUnderComposition namespace IsMultiplicative instance op (W : MorphismProperty C) [IsMultiplicative W] : IsMultiplicative W.op where comp_mem f g hf hg := W.comp_mem g.unop f.unop hg hf instance unop (W : MorphismProperty Cᵒᵖ) [IsMultiplicative W] : IsMultiplicative W.unop where id_mem _ := W.id_mem _ comp_mem f g hf hg := W.comp_mem g.op f.op hg hf lemma of_op (W : MorphismProperty C) [IsMultiplicative W.op] : IsMultiplicative W := (inferInstance : IsMultiplicative W.op.unop) lemma of_unop (W : MorphismProperty Cᵒᵖ) [IsMultiplicative W.unop] : IsMultiplicative W := (inferInstance : IsMultiplicative W.unop.op) instance : MorphismProperty.IsMultiplicative (⊤ : MorphismProperty C) where comp_mem _ _ _ _ := trivial id_mem _ := trivial instance : (isomorphisms C).IsMultiplicative where id_mem _ := isomorphisms.infer_property _ comp_mem f g hf hg := by rw [isomorphisms.iff] at hf hg ⊢ infer_instance instance : (monomorphisms C).IsMultiplicative where id_mem _ := monomorphisms.infer_property _ comp_mem f g hf hg := by rw [monomorphisms.iff] at hf hg ⊢ apply mono_comp instance : (epimorphisms C).IsMultiplicative where id_mem _ := epimorphisms.infer_property _ comp_mem f g hf hg := by rw [epimorphisms.iff] at hf hg ⊢ apply epi_comp instance {P : MorphismProperty D} [P.IsMultiplicative] (F : C ⥤ D) : (P.inverseImage F).IsMultiplicative where instance inf {P Q : MorphismProperty C} [P.IsMultiplicative] [Q.IsMultiplicative] : (P ⊓ Q).IsMultiplicative where instance naturalityProperty {F₁ F₂ : C ⥤ D} (app : ∀ X, F₁.obj X ⟶ F₂.obj X) : (naturalityProperty app).IsMultiplicative where id_mem _ := by simp end IsMultiplicative /-- Given a morphism property `W`, the `multiplicativeClosure W` is the smallest multiplicative property greater than or equal to `W`. -/ inductive multiplicativeClosure (W : MorphismProperty C) : MorphismProperty C | of {x y : C} (f : x ⟶ y) (hf : W f) : multiplicativeClosure W f | id (x : C) : multiplicativeClosure W (𝟙 x) | comp_of {x y z : C} (f : x ⟶ y) (g : y ⟶ z) (hf : multiplicativeClosure W f) (hg : W g) : multiplicativeClosure W (f ≫ g) /-- A variant of `multiplicativeClosure` in which compositions are taken on the left rather than on the right. It is not intended to be used directly, and one should rather access this via `multiplicativeClosure_eq_multiplicativeClosure'` in cases where the inductive principle of this variant is needed. -/ inductive multiplicativeClosure' (W : MorphismProperty C) : MorphismProperty C | of {x y : C} (f : x ⟶ y) (hf : W f) : multiplicativeClosure' W f | id (x : C) : multiplicativeClosure' W (𝟙 x) | of_comp {x y z : C} (f : x ⟶ y) (g : y ⟶ z) (hf : W f) (hg : multiplicativeClosure' W g) : multiplicativeClosure' W (f ≫ g) variable (W : MorphismProperty C) /-- `multiplicativeClosure W` is multiplicative. -/ instance : IsMultiplicative W.multiplicativeClosure where id_mem x := .id x comp_mem f g hf hg := by induction hg with | of _ hf₀ => exact .comp_of f _ hf hf₀ | id _ => rwa [Category.comp_id] | comp_of f' g hf' hg h_rec => rw [← Category.assoc] exact .comp_of (f ≫ f') g (h_rec f hf) hg /-- `multiplicativeClosure' W` is multiplicative. -/ instance : IsMultiplicative W.multiplicativeClosure' where id_mem x := .id x comp_mem f g hf hg := by induction hf with | of _ h => exact .of_comp _ g h hg | id _ => rwa [Category.id_comp] | of_comp g' f hg' hf h_rec => rw [Category.assoc] exact .of_comp g' (f ≫ g) hg' (h_rec g hg) /-- The multiplicative closure is greater than or equal to the original property. -/ lemma le_multiplicativeClosure : W ≤ W.multiplicativeClosure := fun {_ _} _ hf ↦ .of _ hf /-- The multiplicative closure of a multiplicative property is equal to itself. -/ @[simp] lemma multiplicativeClosure_eq_self [W.IsMultiplicative] : W.multiplicativeClosure = W := by apply le_antisymm _ <| le_multiplicativeClosure W intro _ _ _ hf induction hf with | of _ hf₀ => exact hf₀ | id x => exact W.id_mem x | comp_of _ _ _ hg hf => exact W.comp_mem _ _ hf hg lemma multiplicativeClosure_eq_self_iff : W.multiplicativeClosure = W ↔ W.IsMultiplicative where mp h := by rw [← h] infer_instance mpr h := multiplicativeClosure_eq_self W /-- The multiplicative closure of `W` is the smallest multiplicative property greater than or equal to `W`. -/ @[simp] lemma multiplicativeClosure_le_iff (W' : MorphismProperty C) [W'.IsMultiplicative] : multiplicativeClosure W ≤ W' ↔ W ≤ W' where mp h := le_multiplicativeClosure W |>.trans h mpr h := by intro _ _ _ hf induction hf with | of _ hf => exact h _ hf | id x => exact W'.id_mem _ | comp_of _ _ _ hg hf => exact W'.comp_mem _ _ hf (h _ hg) lemma multiplicativeClosure_monotone : Monotone (multiplicativeClosure (C := C)) := fun _ W' h ↦ by simpa using h.trans W'.le_multiplicativeClosure lemma multiplicativeClosure_eq_multiplicativeClosure' : W.multiplicativeClosure = W.multiplicativeClosure' := le_antisymm ((multiplicativeClosure_le_iff _ _).mpr (fun _ _ f hf ↦ .of f hf)) <| fun x y f hf ↦ by induction hf with | of _ h => exact .of _ h | id x => exact .id x | of_comp f g hf hg hr => exact W.multiplicativeClosure.comp_mem f g (.of f hf) hr /-- A class of morphisms `W` has the of-postcomp property w.r.t. `W'` if whenever `g` is in `W'` and `f ≫ g` is in `W`, also `f` is in `W`. -/ class HasOfPostcompProperty (W W' : MorphismProperty C) : Prop where of_postcomp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W' g → W (f ≫ g) → W f /-- A class of morphisms `W` has the of-precomp property w.r.t. `W'` if whenever `f` is in `W'` and `f ≫ g` is in `W`, also `g` is in `W`. -/ class HasOfPrecompProperty (W W' : MorphismProperty C) : Prop where of_precomp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W' f → W (f ≫ g) → W g /-- A class of morphisms `W` has the two-out-of-three property if whenever two out of three maps in `f`, `g`, `f ≫ g` are in `W`, then the third map is also in `W`. -/ class HasTwoOutOfThreeProperty (W : MorphismProperty C) : Prop extends W.IsStableUnderComposition, W.HasOfPostcompProperty W, W.HasOfPrecompProperty W where section variable (W W' : MorphismProperty C) {W'} lemma of_postcomp [W.HasOfPostcompProperty W'] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (hg : W' g) (hfg : W (f ≫ g)) : W f := HasOfPostcompProperty.of_postcomp f g hg hfg lemma of_precomp [W.HasOfPrecompProperty W'] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (hf : W' f) (hfg : W (f ≫ g)) : W g := HasOfPrecompProperty.of_precomp f g hf hfg lemma postcomp_iff [W.RespectsRight W'] [W.HasOfPostcompProperty W'] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (hg : W' g) : W (f ≫ g) ↔ W f := ⟨W.of_postcomp f g hg, fun hf ↦ RespectsRight.postcomp _ hg _ hf⟩ lemma precomp_iff [W.RespectsLeft W'] [W.HasOfPrecompProperty W'] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (hf : W' f) : W (f ≫ g) ↔ W g := ⟨W.of_precomp f g hf, fun hg ↦ RespectsLeft.precomp _ hf _ hg⟩ lemma HasOfPostcompProperty.of_le (Q : MorphismProperty C) [W.HasOfPostcompProperty Q] (hle : W' ≤ Q) : W.HasOfPostcompProperty W' where of_postcomp f g hg hfg := W.of_postcomp (W' := Q) f g (hle _ hg) hfg lemma HasOfPrecompProperty.of_le (Q : MorphismProperty C) [W.HasOfPrecompProperty Q] (hle : W' ≤ Q) : W.HasOfPrecompProperty W' where of_precomp f g hg hfg := W.of_precomp (W' := Q) f g (hle _ hg) hfg instance [W.HasOfPostcompProperty W'] : W.op.HasOfPrecompProperty W'.op where of_precomp _ _ hf hfg := W.of_postcomp _ _ hf hfg instance [W.HasOfPrecompProperty W'] : W.op.HasOfPostcompProperty W'.op where of_postcomp _ _ hg hfg := W.of_precomp _ _ hg hfg instance [W.HasTwoOutOfThreeProperty] : W.op.HasTwoOutOfThreeProperty where end section variable (W₁ W₂ : MorphismProperty Cᵒᵖ) instance [W₁.HasOfPostcompProperty W₂] : W₁.unop.HasOfPrecompProperty W₂.unop where of_precomp _ _ hf hfg := W₁.of_postcomp _ _ hf hfg instance [W₁.HasOfPrecompProperty W₂] : W₁.unop.HasOfPostcompProperty W₂.unop where of_postcomp _ _ hg hfg := W₁.of_precomp _ _ hg hfg instance [W₁.HasTwoOutOfThreeProperty] : W₁.unop.HasTwoOutOfThreeProperty where end instance : (isomorphisms C).HasTwoOutOfThreeProperty where of_postcomp f g := fun (hg : IsIso g) (hfg : IsIso (f ≫ g)) => by simpa using (inferInstance : IsIso ((f ≫ g) ≫ inv g)) of_precomp f g := fun (hf : IsIso f) (hfg : IsIso (f ≫ g)) => by simpa using (inferInstance : IsIso (inv f ≫ (f ≫ g))) instance (F : C ⥤ D) (W : MorphismProperty D) [W.HasTwoOutOfThreeProperty] : (W.inverseImage F).HasTwoOutOfThreeProperty where of_postcomp f g hg hfg := W.of_postcomp (F.map f) (F.map g) hg (by simpa using hfg) of_precomp f g hf hfg := W.of_precomp (F.map f) (F.map g) hf (by simpa using hfg) instance [W.RespectsIso] : W.HasOfPrecompProperty (isomorphisms C) where of_precomp _ _ (_ : IsIso _) := (W.cancel_left_of_respectsIso _ _).mp instance [W.RespectsIso] : W.HasOfPostcompProperty (isomorphisms C) where of_postcomp _ _ (_ : IsIso _) := (W.cancel_right_of_respectsIso _ _).mp end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Comma.lean
import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Subcategories of comma categories defined by morphism properties Given functors `L : A ⥤ T` and `R : B ⥤ T` and morphism properties `P`, `Q` and `W` on `T`, `A` and `B` respectively, we define the subcategory `P.Comma L R Q W` of `Comma L R` where - objects are objects of `Comma L R` with the structural morphism satisfying `P`, and - morphisms are morphisms of `Comma L R` where the left morphism satisfies `Q` and the right morphism satisfies `W`. For an object `X : T`, this specializes to `P.Over Q X` which is the subcategory of `Over X` where the structural morphism satisfies `P` and where the horizontal morphisms satisfy `Q`. Common examples of the latter are e.g. the category of schemes étale (finite, affine, etc.) over a base `X`. Here `Q = ⊤`. ## Implementation details - We provide the general constructor `P.Comma L R Q W` to obtain `Over X` and `Under X` as special cases of the more general setup. - Most results are developed only in the case where `Q = ⊤` and `W = ⊤`, but the definition is setup in the general case to allow for a later generalization if needed. -/ namespace CategoryTheory.MorphismProperty open Limits section Comma variable {A : Type*} [Category A] {B : Type*} [Category B] {T : Type*} [Category T] (L : A ⥤ T) (R : B ⥤ T) lemma costructuredArrow_iso_iff (P : MorphismProperty T) [P.RespectsIso] {L : A ⥤ T} {X : T} {f g : CostructuredArrow L X} (e : f ≅ g) : P f.hom ↔ P g.hom := P.comma_iso_iff e lemma over_iso_iff (P : MorphismProperty T) [P.RespectsIso] {X : T} {f g : Over X} (e : f ≅ g) : P f.hom ↔ P g.hom := P.comma_iso_iff e section variable {W : MorphismProperty T} {X : T} /-- The object property on `Comma L R` induced by a morphism property. -/ def commaObj (W : MorphismProperty T) : ObjectProperty (Comma L R) := fun f ↦ W f.hom @[simp] lemma commaObj_iff (Y : Comma L R) : W.commaObj L R Y ↔ W Y.hom := .rfl instance [W.RespectsIso] : (W.commaObj L R).IsClosedUnderIsomorphisms where of_iso {X Y} e h := by rwa [commaObj_iff, ← W.cancel_left_of_respectsIso (L.map e.hom.left), e.hom.w, W.cancel_right_of_respectsIso] /-- The object property on `CostructuredArrow L X` induced by a morphism property. -/ def costructuredArrowObj (W : MorphismProperty T) : ObjectProperty (CostructuredArrow L X) := fun f ↦ W f.hom @[simp] lemma costructuredArrowObj_iff (Y : CostructuredArrow L X) : W.costructuredArrowObj L Y ↔ W Y.hom := .rfl instance [W.RespectsIso] : (W.costructuredArrowObj L (X := X)).IsClosedUnderIsomorphisms := inferInstanceAs <| (W.commaObj _ _).IsClosedUnderIsomorphisms /-- The object property on `StructuredArrow X R` induced by a morphism property. -/ def structuredArrowObj (W : MorphismProperty T) : ObjectProperty (StructuredArrow X R) := fun f ↦ W f.hom @[simp] lemma structuredArrowObj_iff (Y : StructuredArrow X R) : W.structuredArrowObj R Y ↔ W Y.hom := .rfl instance [W.RespectsIso] : (W.structuredArrowObj L (X := X)).IsClosedUnderIsomorphisms := inferInstanceAs <| (W.commaObj _ _).IsClosedUnderIsomorphisms /-- The morphism property on `Over X` induced by a morphism property on `C`. -/ def over (W : MorphismProperty T) {X : T} : MorphismProperty (Over X) := fun _ _ f ↦ W f.left @[simp] lemma over_iff {Y Z : Over X} (f : Y ⟶ Z) : W.over f ↔ W f.left := .rfl /-- The morphism property on `Under X` induced by a morphism property on `C`. -/ def under (W : MorphismProperty T) {X : T} : MorphismProperty (Under X) := fun _ _ f ↦ W f.right @[simp] lemma under_iff {Y Z : Under X} (f : Y ⟶ Z) : W.under f ↔ W f.right := .rfl /-- The object property on `Over X` induced by a morphism property. -/ def overObj (W : MorphismProperty T) {X : T} : ObjectProperty (Over X) := fun f ↦ W f.hom @[simp] lemma overObj_iff (Y : Over X) : W.overObj Y ↔ W Y.hom := .rfl instance [W.RespectsIso] : (W.overObj (X := X)).IsClosedUnderIsomorphisms := inferInstanceAs <| (W.commaObj _ _).IsClosedUnderIsomorphisms /-- The object property on `Under X` induced by a morphism property. -/ def underObj (W : MorphismProperty T) {X : T} : ObjectProperty (Under X) := fun f ↦ W f.hom @[simp] lemma underObj_iff (Y : Under X) : W.underObj Y ↔ W Y.hom := .rfl instance [W.RespectsIso] : (W.underObj (X := X)).IsClosedUnderIsomorphisms := inferInstanceAs <| (W.commaObj _ _).IsClosedUnderIsomorphisms end variable (P : MorphismProperty T) (Q : MorphismProperty A) (W : MorphismProperty B) /-- `P.Comma L R Q W` is the subcategory of `Comma L R` consisting of objects `X : Comma L R` where `X.hom` satisfies `P`. The morphisms are given by morphisms in `Comma L R` where the left one satisfies `Q` and the right one satisfies `W`. -/ @[ext] protected structure Comma (Q : MorphismProperty A) (W : MorphismProperty B) extends Comma L R where prop : P toComma.hom namespace Comma variable {L R P Q W} /-- A morphism in `P.Comma L R Q W` is a morphism in `Comma L R` where the left hom satisfies `Q` and the right one satisfies `W`. -/ @[ext] structure Hom (X Y : P.Comma L R Q W) extends CommaMorphism X.toComma Y.toComma where prop_hom_left : Q toCommaMorphism.left prop_hom_right : W toCommaMorphism.right /-- The underlying morphism of objects in `Comma L R`. -/ abbrev Hom.hom {X Y : P.Comma L R Q W} (f : Comma.Hom X Y) : X.toComma ⟶ Y.toComma := f.toCommaMorphism @[simp, nolint simpVarHead] lemma Hom.hom_mk {X Y : P.Comma L R Q W} (f : CommaMorphism X.toComma Y.toComma) (hf) (hg) : Comma.Hom.hom ⟨f, hf, hg⟩ = f := rfl lemma Hom.hom_left {X Y : P.Comma L R Q W} (f : Comma.Hom X Y) : f.hom.left = f.left := rfl lemma Hom.hom_right {X Y : P.Comma L R Q W} (f : Comma.Hom X Y) : f.hom.right = f.right := rfl /-- See Note [custom simps projection] -/ def Hom.Simps.hom {X Y : P.Comma L R Q W} (f : X.Hom Y) : X.toComma ⟶ Y.toComma := f.hom initialize_simps_projections Comma.Hom (toCommaMorphism → hom) /-- The identity morphism of an object in `P.Comma L R Q W`. -/ @[simps] def id [Q.ContainsIdentities] [W.ContainsIdentities] (X : P.Comma L R Q W) : Comma.Hom X X where left := 𝟙 X.left right := 𝟙 X.right prop_hom_left := Q.id_mem X.toComma.left prop_hom_right := W.id_mem X.toComma.right /-- Composition of morphisms in `P.Comma L R Q W`. -/ @[simps] def Hom.comp [Q.IsStableUnderComposition] [W.IsStableUnderComposition] {X Y Z : P.Comma L R Q W} (f : Comma.Hom X Y) (g : Comma.Hom Y Z) : Comma.Hom X Z where left := f.left ≫ g.left right := f.right ≫ g.right prop_hom_left := Q.comp_mem _ _ f.prop_hom_left g.prop_hom_left prop_hom_right := W.comp_mem _ _ f.prop_hom_right g.prop_hom_right variable [Q.IsMultiplicative] [W.IsMultiplicative] variable (L R P Q W) in instance : Category (P.Comma L R Q W) where Hom X Y := X.Hom Y id X := X.id comp f g := f.comp g lemma toCommaMorphism_eq_hom {X Y : P.Comma L R Q W} (f : X ⟶ Y) : f.toCommaMorphism = f.hom := rfl /-- Alternative `ext` lemma for `Comma.Hom`. -/ @[ext] lemma Hom.ext' {X Y : P.Comma L R Q W} {f g : X ⟶ Y} (h : f.hom = g.hom) : f = g := Comma.Hom.ext (congrArg CommaMorphism.left h) (congrArg CommaMorphism.right h) @[simp] lemma id_hom (X : P.Comma L R Q W) : (𝟙 X : X ⟶ X).hom = 𝟙 X.toComma := rfl @[simp] lemma comp_hom {X Y Z : P.Comma L R Q W} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = f.hom ≫ g.hom := rfl @[reassoc] lemma comp_left {X Y Z : P.Comma L R Q W} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).left = f.left ≫ g.left := rfl @[reassoc] lemma comp_right {X Y Z : P.Comma L R Q W} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).right = f.right ≫ g.right := rfl /-- If `i` is an isomorphism in `Comma L R`, it is also a morphism in `P.Comma L R Q W`. -/ @[simps hom] def homFromCommaOfIsIso [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W} (i : X.toComma ⟶ Y.toComma) [IsIso i] : X ⟶ Y where __ := i prop_hom_left := Q.of_isIso i.left prop_hom_right := W.of_isIso i.right instance [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W} (i : X.toComma ⟶ Y.toComma) [IsIso i] : IsIso (homFromCommaOfIsIso i) := by constructor use homFromCommaOfIsIso (inv i) constructor <;> ext : 1 <;> simp /-- Any isomorphism between objects of `P.Comma L R Q W` in `Comma L R` is also an isomorphism in `P.Comma L R Q W`. -/ @[simps] def isoFromComma [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W} (i : X.toComma ≅ Y.toComma) : X ≅ Y where hom := homFromCommaOfIsIso i.hom inv := homFromCommaOfIsIso i.inv /-- Constructor for isomorphisms in `P.Comma L R Q W` from isomorphisms of the left and right components and naturality in the forward direction. -/ @[simps!] def isoMk [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W} (l : X.left ≅ Y.left) (r : X.right ≅ Y.right) (h : L.map l.hom ≫ Y.hom = X.hom ≫ R.map r.hom := by cat_disch) : X ≅ Y := isoFromComma (CategoryTheory.Comma.isoMk l r h) variable (L R P Q W) /-- The forgetful functor. -/ @[simps] def forget : P.Comma L R Q W ⥤ Comma L R where obj X := X.toComma map f := f.hom instance : (forget L R P Q W).Faithful where map_injective := Comma.Hom.ext' variable {L R P Q W} instance {X Y : P.Comma L R Q W} (f : X ⟶ Y) [IsIso f] : IsIso f.hom := (forget L R P Q W).map_isIso f lemma hom_homFromCommaOfIsIso [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W} (i : X ⟶ Y) [IsIso i.hom] : homFromCommaOfIsIso i.hom = i := rfl lemma inv_hom {X Y : P.Comma L R Q W} (f : X ⟶ Y) [IsIso f] : (inv f).hom = inv f.hom := by apply IsIso.eq_inv_of_hom_inv_id rw [← comp_hom, IsIso.hom_inv_id, id_hom] variable (L R P Q W) instance [Q.RespectsIso] [W.RespectsIso] : (forget L R P Q W).ReflectsIsomorphisms where reflects f hf := by simp only [forget_obj, forget_map] at hf rw [← hom_homFromCommaOfIsIso f] infer_instance /-- The forgetful functor from the full subcategory of `Comma L R` defined by `P` is fully faithful. -/ def forgetFullyFaithful : (forget L R P ⊤ ⊤).FullyFaithful where preimage {X Y} f := ⟨f, trivial, trivial⟩ instance : (forget L R P ⊤ ⊤).Full := Functor.FullyFaithful.full (forgetFullyFaithful L R P) section variable {L R} @[simp] lemma eqToHom_left {X Y : P.Comma L R Q W} (h : X = Y) : (eqToHom h).left = eqToHom (by rw [h]) := by subst h rfl @[simp] lemma eqToHom_right {X Y : P.Comma L R Q W} (h : X = Y) : (eqToHom h).right = eqToHom (by rw [h]) := by subst h rfl end section variable {P P' : MorphismProperty T} {Q Q' : MorphismProperty A} {W W' : MorphismProperty B} (hP : P ≤ P') (hQ : Q ≤ Q') (hW : W ≤ W') variable [Q.IsMultiplicative] [Q'.IsMultiplicative] [W.IsMultiplicative] [W'.IsMultiplicative] /-- Weaken the conditions on all components. -/ def changeProp : P.Comma L R Q W ⥤ P'.Comma L R Q' W' where obj X := ⟨X.toComma, hP _ X.2⟩ map f := ⟨f.toCommaMorphism, hQ _ f.2, hW _ f.3⟩ /-- Weakening the condition on the structure morphisms is fully faithful. -/ def fullyFaithfulChangeProp : (changeProp (Q := Q) (W := W) L R hP le_rfl le_rfl).FullyFaithful where preimage f := ⟨f.toCommaMorphism, f.2, f.3⟩ instance : (changeProp L R hP hQ hW).Faithful where map_injective {X Y} f g h := by ext : 1; exact congr($(h).hom) instance : (changeProp (Q := Q) (W := W) L R hP le_rfl le_rfl).Full := (fullyFaithfulChangeProp ..).full end section Functoriality variable {L R P Q W} variable {L₁ L₂ L₃ : A ⥤ T} {R₁ R₂ R₃ : B ⥤ T} /-- Lift a functor `F : C ⥤ Comma L R` to the subcategory `P.Comma L R Q W` under suitable assumptions on `F`. -/ @[simps obj_toComma map_hom] def lift {C : Type*} [Category C] (F : C ⥤ Comma L R) (hP : ∀ X, P (F.obj X).hom) (hQ : ∀ {X Y} (f : X ⟶ Y), Q (F.map f).left) (hW : ∀ {X Y} (f : X ⟶ Y), W (F.map f).right) : C ⥤ P.Comma L R Q W where obj X := { __ := F.obj X prop := hP X } map {X Y} f := { __ := F.map f prop_hom_left := hQ f prop_hom_right := hW f } variable (R) in /-- A natural transformation `L₁ ⟶ L₂` induces a functor `P.Comma L₂ R Q W ⥤ P.Comma L₁ R Q W`. -/ @[simps!] def mapLeft (l : L₁ ⟶ L₂) (hl : ∀ X : P.Comma L₂ R Q W, P (l.app X.left ≫ X.hom)) : P.Comma L₂ R Q W ⥤ P.Comma L₁ R Q W := lift (forget _ _ _ _ _ ⋙ CategoryTheory.Comma.mapLeft R l) hl (fun f ↦ f.prop_hom_left) (fun f ↦ f.prop_hom_right) variable (L) in /-- A natural transformation `R₁ ⟶ R₂` induces a functor `P.Comma L R₁ Q W ⥤ P.Comma L R₂ Q W`. -/ @[simps!] def mapRight (r : R₁ ⟶ R₂) (hr : ∀ X : P.Comma L R₁ Q W, P (X.hom ≫ r.app X.right)) : P.Comma L R₁ Q W ⥤ P.Comma L R₂ Q W := lift (forget _ _ _ _ _ ⋙ CategoryTheory.Comma.mapRight L r) hr (fun f ↦ f.prop_hom_left) (fun f ↦ f.prop_hom_right) end Functoriality end Comma end Comma section Over variable {T : Type*} [Category T] (P Q : MorphismProperty T) (X : T) [Q.IsMultiplicative] /-- Given a morphism property `P` on a category `C` and an object `X : C`, this is the subcategory of `Over X` defined by `P` where morphisms satisfy `Q`. -/ protected abbrev Over : Type _ := P.Comma (Functor.id T) (Functor.fromPUnit.{0} X) Q ⊤ /-- The forgetful functor from the full subcategory of `Over X` defined by `P` to `Over X`. -/ protected abbrev Over.forget : P.Over Q X ⥤ Over X := Comma.forget (Functor.id T) (Functor.fromPUnit.{0} X) P Q ⊤ instance : (Over.forget P ⊤ X).Faithful := inferInstanceAs <| (Comma.forget _ _ _ _ _).Faithful instance : (Over.forget P ⊤ X).Full := inferInstanceAs <| (Comma.forget _ _ _ _ _).Full variable {P Q X} /-- Construct a morphism in `P.Over Q X` from a morphism in `Over.X`. -/ @[simps hom] def Over.Hom.mk {A B : P.Over Q X} (f : A.toComma ⟶ B.toComma) (hf : Q f.left) : A ⟶ B where __ := f prop_hom_left := hf prop_hom_right := trivial variable (Q) in /-- Make an object of `P.Over Q X` from a morphism `f : A ⟶ X` and a proof of `P f`. -/ @[simps hom left] protected def Over.mk {A : T} (f : A ⟶ X) (hf : P f) : P.Over Q X where left := A right := ⟨⟨⟩⟩ hom := f prop := hf /-- Make a morphism in `P.Over Q X` from a morphism in `T` with compatibilities. -/ @[simps hom] protected def Over.homMk {A B : P.Over Q X} (f : A.left ⟶ B.left) (w : f ≫ B.hom = A.hom := by cat_disch) (hf : Q f := by trivial) : A ⟶ B where __ := CategoryTheory.Over.homMk f w prop_hom_left := hf prop_hom_right := trivial /-- Make an isomorphism in `P.Over Q X` from an isomorphism in `T` with compatibilities. -/ @[simps! hom_left inv_left] protected def Over.isoMk [Q.RespectsIso] {A B : P.Over Q X} (f : A.left ≅ B.left) (w : f.hom ≫ B.hom = A.hom := by cat_disch) : A ≅ B := Comma.isoMk f (Discrete.eqToIso' rfl) @[ext] lemma Over.Hom.ext {A B : P.Over Q X} {f g : A ⟶ B} (h : f.left = g.left) : f = g := by ext · exact h · simp @[reassoc] lemma Over.w {A B : P.Over Q X} (f : A ⟶ B) : f.left ≫ B.hom = A.hom := by simp end Over section Under variable {T : Type*} [Category T] (P Q : MorphismProperty T) (X : T) [Q.IsMultiplicative] /-- Given a morphism property `P` on a category `C` and an object `X : C`, this is the subcategory of `Under X` defined by `P` where morphisms satisfy `Q`. -/ protected abbrev Under : Type _ := P.Comma (Functor.fromPUnit.{0} X) (Functor.id T) ⊤ Q /-- The forgetful functor from the full subcategory of `Under X` defined by `P` to `Under X`. -/ protected abbrev Under.forget : P.Under Q X ⥤ Under X := Comma.forget (Functor.fromPUnit.{0} X) (Functor.id T) P ⊤ Q instance : (Under.forget P ⊤ X).Faithful := inferInstanceAs <| (Comma.forget _ _ _ _ _).Faithful instance : (Under.forget P ⊤ X).Full := inferInstanceAs <| (Comma.forget _ _ _ _ _).Full variable {P Q X} /-- Construct a morphism in `P.Under Q X` from a morphism in `Under.X`. -/ @[simps hom] def Under.Hom.mk {A B : P.Under Q X} (f : A.toComma ⟶ B.toComma) (hf : Q f.right) : A ⟶ B where __ := f prop_hom_left := trivial prop_hom_right := hf variable (Q) in /-- Make an object of `P.Under Q X` from a morphism `f : A ⟶ X` and a proof of `P f`. -/ @[simps hom left] protected def Under.mk {A : T} (f : X ⟶ A) (hf : P f) : P.Under Q X where left := ⟨⟨⟩⟩ right := A hom := f prop := hf /-- Make a morphism in `P.Under Q X` from a morphism in `T` with compatibilities. -/ @[simps hom] protected def Under.homMk {A B : P.Under Q X} (f : A.right ⟶ B.right) (w : A.hom ≫ f = B.hom := by cat_disch) (hf : Q f := by trivial) : A ⟶ B where __ := CategoryTheory.Under.homMk f w prop_hom_left := trivial prop_hom_right := hf /-- Make an isomorphism in `P.Under Q X` from an isomorphism in `T` with compatibilities. -/ @[simps! hom_right inv_right] protected def Under.isoMk [Q.RespectsIso] {A B : P.Under Q X} (f : A.right ≅ B.right) (w : A.hom ≫ f.hom = B.hom := by cat_disch) : A ≅ B := Comma.isoMk (Discrete.eqToIso' rfl) f @[ext] lemma Under.Hom.ext {A B : P.Under Q X} {f g : A ⟶ B} (h : f.right = g.right) : f = g := by ext · simp · exact h @[reassoc] lemma Under.w {A B : P.Under Q X} (f : A ⟶ B) : A.hom ≫ f.right = B.hom := by simp end Under end CategoryTheory.MorphismProperty
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Descent.lean
import Mathlib.CategoryTheory.MorphismProperty.Limits /-! # Descent of morphism properties Given morphism properties `P` and `Q` we say that `P` descends along `Q` (`P.DescendsAlong Q`), if whenever `Q` holds for `X ⟶ Z`, `P` holds for `X ×[Z] Y ⟶ X` implies `P` holds for `Y ⟶ Z`. Dually, we define `P.CodescendsAlong Q`. -/ namespace CategoryTheory.MorphismProperty open Limits variable {C : Type*} [Category C] variable {P Q W : MorphismProperty C} /-- `P` descends along `Q` if whenever `Q` holds for `X ⟶ Z`, `P` holds for `X ×[Z] Y ⟶ X` implies `P` holds for `Y ⟶ Z`. -/ class DescendsAlong (P Q : MorphismProperty C) : Prop where of_isPullback {A X Y Z : C} {fst : A ⟶ X} {snd : A ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} : IsPullback fst snd f g → Q f → P fst → P g section DescendsAlong variable {A X Y Z : C} {fst : A ⟶ X} {snd : A ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} lemma of_isPullback_of_descendsAlong [P.DescendsAlong Q] (h : IsPullback fst snd f g) (hf : Q f) (hfst : P fst) : P g := DescendsAlong.of_isPullback h hf hfst lemma iff_of_isPullback [P.IsStableUnderBaseChange] [P.DescendsAlong Q] (h : IsPullback fst snd f g) (hf : Q f) : P fst ↔ P g := ⟨fun hfst ↦ of_isPullback_of_descendsAlong h hf hfst, fun hf ↦ P.of_isPullback h.flip hf⟩ lemma of_pullback_fst_of_descendsAlong [P.DescendsAlong Q] [HasPullback f g] (hf : Q f) (hfst : P (pullback.fst f g)) : P g := of_isPullback_of_descendsAlong (.of_hasPullback f g) hf hfst lemma pullback_fst_iff [P.IsStableUnderBaseChange] [P.DescendsAlong Q] [HasPullback f g] (hf : Q f) : P (pullback.fst f g) ↔ P g := iff_of_isPullback (.of_hasPullback f g) hf lemma of_pullback_snd_of_descendsAlong [P.DescendsAlong Q] [HasPullback f g] (hg : Q g) (hsnd : P (pullback.snd f g)) : P f := of_isPullback_of_descendsAlong (IsPullback.of_hasPullback f g).flip hg hsnd lemma pullback_snd_iff [P.IsStableUnderBaseChange] [P.DescendsAlong Q] [HasPullback f g] (hg : Q g) : P (pullback.snd f g) ↔ P f := iff_of_isPullback (IsPullback.of_hasPullback f g).flip hg instance DescendsAlong.top : (⊤ : MorphismProperty C).DescendsAlong Q where of_isPullback _ _ _ := trivial instance DescendsAlong.inf [P.DescendsAlong Q] [W.DescendsAlong Q] : (P ⊓ W).DescendsAlong Q where of_isPullback h hg hfst := ⟨DescendsAlong.of_isPullback h hg hfst.1, DescendsAlong.of_isPullback h hg hfst.2⟩ lemma DescendsAlong.of_le [P.DescendsAlong Q] (hle : W ≤ Q) : P.DescendsAlong W where of_isPullback h hg hfst := DescendsAlong.of_isPullback h (hle _ hg) hfst /-- Alternative constructor for `CodescendsAlong` using `HasPullback`. -/ lemma DescendsAlong.mk' [P.RespectsIso] (H : ∀ {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g], Q f → P (pullback.fst f g) → P g) : P.DescendsAlong Q where of_isPullback {A X Y Z fst snd f g} h hf hfst := by have : HasPullback f g := h.hasPullback apply H hf rwa [← P.cancel_left_of_respectsIso h.isoPullback.hom, h.isoPullback_hom_fst] instance [Q.IsStableUnderBaseChange] [P.HasOfPrecompProperty Q] [P.RespectsRight Q] : P.DescendsAlong Q where of_isPullback {A X Y Z fst snd f g} h hf hfst := by apply P.of_precomp (W' := Q) _ _ (Q.of_isPullback h hf) rw [← h.1.1] exact RespectsRight.postcomp _ hf _ hfst end DescendsAlong /-- `P` codescends along `Q` if whenever `Q` holds for `Z ⟶ X`, `P` holds for `X ⟶ X ∐[Z] Y` implies `P` holds for `Z ⟶ Y`. -/ class CodescendsAlong (P Q : MorphismProperty C) : Prop where of_isPushout {Z X Y A : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ A} {inr : Y ⟶ A} : IsPushout f g inl inr → Q f → P inl → P g section CodescendsAlong variable {Z X Y A : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ A} {inr : Y ⟶ A} lemma of_isPushout_of_codescendsAlong [P.CodescendsAlong Q] (h : IsPushout f g inl inr) (hf : Q f) (hinl : P inl) : P g := CodescendsAlong.of_isPushout h hf hinl lemma iff_of_isPushout [P.IsStableUnderCobaseChange] [P.CodescendsAlong Q] (h : IsPushout f g inl inr) (hg : Q f) : P inl ↔ P g := ⟨fun hinl ↦ of_isPushout_of_codescendsAlong h hg hinl, fun hf ↦ P.of_isPushout h hf⟩ lemma of_pushout_inl_of_codescendsAlong [P.CodescendsAlong Q] [HasPushout f g] (hf : Q f) (hinl : P (pushout.inl f g)) : P g := of_isPushout_of_codescendsAlong (.of_hasPushout f g) hf hinl lemma pushout_inl_iff [P.IsStableUnderCobaseChange] [P.CodescendsAlong Q] [HasPushout f g] (hf : Q f) : P (pushout.inl f g) ↔ P g := iff_of_isPushout (.of_hasPushout f g) hf lemma of_pushout_inr_of_descendsAlong [P.CodescendsAlong Q] [HasPushout f g] (hg : Q g) (hinr : P (pushout.inr f g)) : P f := of_isPushout_of_codescendsAlong (IsPushout.of_hasPushout f g).flip hg hinr lemma pushout_inr_iff [P.IsStableUnderCobaseChange] [P.CodescendsAlong Q] [HasPushout f g] (hg : Q g) : P (pushout.inr f g) ↔ P f := iff_of_isPushout (IsPushout.of_hasPushout f g).flip hg lemma CodescendsAlong.of_le [P.CodescendsAlong Q] (hle : W ≤ Q) : P.CodescendsAlong W where of_isPushout h hg hinl := CodescendsAlong.of_isPushout h (hle _ hg) hinl instance CodescendsAlong.top : (⊤ : MorphismProperty C).CodescendsAlong Q where of_isPushout _ _ _ := trivial instance CodescendsAlong.inf [P.CodescendsAlong Q] [W.CodescendsAlong Q] : (P ⊓ W).CodescendsAlong Q where of_isPushout h hg hfst := ⟨CodescendsAlong.of_isPushout h hg hfst.1, CodescendsAlong.of_isPushout h hg hfst.2⟩ /-- Alternative constructor for `CodescendsAlong` using `HasPushout`. -/ lemma CodescendsAlong.mk' [P.RespectsIso] (H : ∀ {X Y Z : C} {f : Z ⟶ X} {g : Z ⟶ Y} [HasPushout f g], Q f → P (pushout.inl f g) → P g) : P.CodescendsAlong Q where of_isPushout {A X Y Z f g inl inr} h hf hfst := by have : HasPushout f g := h.hasPushout apply H hf rwa [← P.cancel_right_of_respectsIso _ h.isoPushout.inv, h.inl_isoPushout_inv] instance [Q.IsStableUnderCobaseChange] [P.HasOfPostcompProperty Q] [P.RespectsLeft Q] : P.CodescendsAlong Q where of_isPushout {X Y Z A f g inl inr} h hf hinl := by apply P.of_postcomp (W' := Q) g inr (Q.of_isPushout h.flip hf) rw [← h.1.1] exact RespectsLeft.precomp _ hf _ hinl end CodescendsAlong end CategoryTheory.MorphismProperty
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/IsSmall.lean
import Mathlib.CategoryTheory.MorphismProperty.Basic import Mathlib.Logic.Small.Basic /-! # Small classes of morphisms A class of morphisms `W : MorphismProperty C` is `w`-small if the corresponding set in `Set (Arrow C)` is. -/ universe w t v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] namespace MorphismProperty variable (W : MorphismProperty C) /-- A class of morphisms `W : MorphismProperty C` is `w`-small if the corresponding set in `Set (Arrow C)` is. -/ @[pp_with_univ] class IsSmall : Prop where small_toSet : Small.{w} W.toSet attribute [instance] IsSmall.small_toSet instance isSmall_ofHoms {ι : Type t} [Small.{w} ι] {A B : ι → C} (f : ∀ i, A i ⟶ B i) : IsSmall.{w} (ofHoms f) := by let φ (i : ι) : (ofHoms f).toSet := ⟨Arrow.mk (f i), ⟨i⟩⟩ have hφ : Function.Surjective φ := by rintro ⟨⟨_, _, f⟩, ⟨i⟩⟩ exact ⟨i, rfl⟩ exact ⟨small_of_surjective hφ⟩ lemma isSmall_iff_eq_ofHoms : IsSmall.{w} W ↔ ∃ (ι : Type w) (A B : ι → C) (f : ∀ i, A i ⟶ B i), W = ofHoms f := by constructor · intro refine ⟨Shrink.{w} W.toSet, _, _, fun i ↦ ((equivShrink _).symm i).1.hom, ?_⟩ ext A B f rw [ofHoms_iff] constructor · intro hf exact ⟨equivShrink _ ⟨f, hf⟩, by simp⟩ · rintro ⟨i, hi⟩ simp only [← W.arrow_mk_mem_toSet_iff, hi, Arrow.mk_eq, Subtype.coe_prop] · rintro ⟨_, _, _, _, rfl⟩ infer_instance end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Basic.lean
import Mathlib.CategoryTheory.Comma.Arrow import Mathlib.Order.CompleteBooleanAlgebra /-! # Properties of morphisms We provide the basic framework for talking about properties of morphisms. The following meta-property is defined * `RespectsLeft P Q`: `P` respects the property `Q` on the left if `P f → P (i ≫ f)` where `i` satisfies `Q`. * `RespectsRight P Q`: `P` respects the property `Q` on the right if `P f → P (f ≫ i)` where `i` satisfies `Q`. * `Respects`: `P` respects `Q` if `P` respects `Q` both on the left and on the right. -/ universe w v v' u u' open CategoryTheory Opposite noncomputable section namespace CategoryTheory /-- A `MorphismProperty C` is a class of morphisms between objects in `C`. -/ def MorphismProperty (C : Type u) [CategoryStruct.{v} C] := ∀ ⦃X Y : C⦄ (_ : X ⟶ Y), Prop namespace MorphismProperty section variable (C : Type u) [CategoryStruct.{v} C] instance : CompleteBooleanAlgebra (MorphismProperty C) where le P₁ P₂ := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P₁ f → P₂ f __ := inferInstanceAs (CompleteBooleanAlgebra (∀ ⦃X Y : C⦄ (_ : X ⟶ Y), Prop)) lemma le_def {P Q : MorphismProperty C} : P ≤ Q ↔ ∀ {X Y : C} (f : X ⟶ Y), P f → Q f := Iff.rfl instance : Inhabited (MorphismProperty C) := ⟨⊤⟩ lemma top_eq : (⊤ : MorphismProperty C) = fun _ _ _ => True := rfl variable {C} @[ext] lemma ext (W W' : MorphismProperty C) (h : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), W f ↔ W' f) : W = W' := by funext X Y f rw [h] @[simp] lemma top_apply {X Y : C} (f : X ⟶ Y) : (⊤ : MorphismProperty C) f := by simp only [top_eq] lemma of_eq_top {P : MorphismProperty C} (h : P = ⊤) {X Y : C} (f : X ⟶ Y) : P f := by simp [h] @[simp] lemma sSup_iff (S : Set (MorphismProperty C)) {X Y : C} (f : X ⟶ Y) : sSup S f ↔ ∃ (W : S), W.1 f := by dsimp [sSup, iSup] constructor · rintro ⟨_, ⟨⟨_, ⟨⟨_, ⟨_, h⟩, rfl⟩, rfl⟩⟩, rfl⟩, hf⟩ exact ⟨⟨_, h⟩, hf⟩ · rintro ⟨⟨W, hW⟩, hf⟩ exact ⟨_, ⟨⟨_, ⟨_, ⟨⟨W, hW⟩, rfl⟩⟩, rfl⟩, rfl⟩, hf⟩ @[simp] lemma iSup_iff {ι : Sort*} (W : ι → MorphismProperty C) {X Y : C} (f : X ⟶ Y) : iSup W f ↔ ∃ i, W i f := by apply (sSup_iff (Set.range W) f).trans constructor · rintro ⟨⟨_, i, rfl⟩, hf⟩ exact ⟨i, hf⟩ · rintro ⟨i, hf⟩ exact ⟨⟨_, i, rfl⟩, hf⟩ /-- The morphism property in `Cᵒᵖ` associated to a morphism property in `C` -/ @[simp] def op (P : MorphismProperty C) : MorphismProperty Cᵒᵖ := fun _ _ f => P f.unop /-- The morphism property in `C` associated to a morphism property in `Cᵒᵖ` -/ @[simp] def unop (P : MorphismProperty Cᵒᵖ) : MorphismProperty C := fun _ _ f => P f.op theorem unop_op (P : MorphismProperty C) : P.op.unop = P := rfl theorem op_unop (P : MorphismProperty Cᵒᵖ) : P.unop.op = P := rfl end section variable {C : Type u} [Category.{v} C] {D : Type*} [Category D] /-- The inverse image of a `MorphismProperty D` by a functor `C ⥤ D` -/ def inverseImage (P : MorphismProperty D) (F : C ⥤ D) : MorphismProperty C := fun _ _ f => P (F.map f) @[simp] lemma inverseImage_iff (P : MorphismProperty D) (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) : P.inverseImage F f ↔ P (F.map f) := by rfl /-- The image (up to isomorphisms) of a `MorphismProperty C` by a functor `C ⥤ D` -/ def map (P : MorphismProperty C) (F : C ⥤ D) : MorphismProperty D := fun _ _ f => ∃ (X' Y' : C) (f' : X' ⟶ Y') (_ : P f'), Nonempty (Arrow.mk (F.map f') ≅ Arrow.mk f) lemma map_mem_map (P : MorphismProperty C) (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (hf : P f) : (P.map F) (F.map f) := ⟨X, Y, f, hf, ⟨Iso.refl _⟩⟩ lemma monotone_map (F : C ⥤ D) : Monotone (map · F) := by intro P Q h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ exact ⟨X', Y', f', h _ hf', ⟨e⟩⟩ @[simp] lemma map_top_eq_top_of_essSurj_of_full (F : C ⥤ D) [F.EssSurj] [F.Full] : (⊤ : MorphismProperty C).map F = ⊤ := by rw [eq_top_iff] intro X Y f _ refine ⟨F.objPreimage X, F.objPreimage Y, F.preimage ?_, ⟨⟨⟩, ⟨?_⟩⟩⟩ · exact (Functor.objObjPreimageIso F X).hom ≫ f ≫ (Functor.objObjPreimageIso F Y).inv · exact Arrow.isoMk' _ _ (Functor.objObjPreimageIso F X) (Functor.objObjPreimageIso F Y) (by simp) section variable (P : MorphismProperty C) /-- The set in `Set (Arrow C)` which corresponds to `P : MorphismProperty C`. -/ def toSet : Set (Arrow C) := setOf (fun f ↦ P f.hom) /-- The family of morphisms indexed by `P.toSet` which corresponds to `P : MorphismProperty C`, see `MorphismProperty.ofHoms_homFamily`. -/ def homFamily (f : P.toSet) : f.1.left ⟶ f.1.right := f.1.hom lemma homFamily_apply (f : P.toSet) : P.homFamily f = f.1.hom := rfl @[simp] lemma homFamily_arrow_mk {X Y : C} (f : X ⟶ Y) (hf : P f) : P.homFamily ⟨Arrow.mk f, hf⟩ = f := rfl @[simp] lemma arrow_mk_mem_toSet_iff {X Y : C} (f : X ⟶ Y) : Arrow.mk f ∈ P.toSet ↔ P f := Iff.rfl lemma of_eq {X Y : C} {f : X ⟶ Y} (hf : P f) {X' Y' : C} {f' : X' ⟶ Y'} (hX : X = X') (hY : Y = Y') (h : f' = eqToHom hX.symm ≫ f ≫ eqToHom hY) : P f' := by rw [← P.arrow_mk_mem_toSet_iff] at hf ⊢ rwa [(Arrow.mk_eq_mk_iff f' f).2 ⟨hX.symm, hY.symm, h⟩] end /-- The class of morphisms given by a family of morphisms `f i : X i ⟶ Y i`. -/ inductive ofHoms {ι : Type*} {X Y : ι → C} (f : ∀ i, X i ⟶ Y i) : MorphismProperty C | mk (i : ι) : ofHoms f (f i) lemma ofHoms_iff {ι : Type*} {X Y : ι → C} (f : ∀ i, X i ⟶ Y i) {A B : C} (g : A ⟶ B) : ofHoms f g ↔ ∃ i, Arrow.mk g = Arrow.mk (f i) := by constructor · rintro ⟨i⟩ exact ⟨i, rfl⟩ · rintro ⟨i, h⟩ rw [← (ofHoms f).arrow_mk_mem_toSet_iff, h, arrow_mk_mem_toSet_iff] constructor @[simp] lemma ofHoms_homFamily (P : MorphismProperty C) : ofHoms P.homFamily = P := by ext _ _ f constructor · intro hf rw [ofHoms_iff] at hf obtain ⟨⟨f, hf⟩, ⟨_, _⟩⟩ := hf exact hf · intro hf exact ⟨(⟨f, hf⟩ : P.toSet)⟩ end section variable {C : Type u} [CategoryStruct.{v} C] /-- A morphism property `P` satisfies `P.RespectsRight Q` if it is stable under post-composition with morphisms satisfying `Q`, i.e. whenever `P` holds for `f` and `Q` holds for `i` then `P` holds for `f ≫ i`. -/ class RespectsRight (P Q : MorphismProperty C) : Prop where postcomp {X Y Z : C} (i : Y ⟶ Z) (hi : Q i) (f : X ⟶ Y) (hf : P f) : P (f ≫ i) /-- A morphism property `P` satisfies `P.RespectsLeft Q` if it is stable under pre-composition with morphisms satisfying `Q`, i.e. whenever `P` holds for `f` and `Q` holds for `i` then `P` holds for `i ≫ f`. -/ class RespectsLeft (P Q : MorphismProperty C) : Prop where precomp {X Y Z : C} (i : X ⟶ Y) (hi : Q i) (f : Y ⟶ Z) (hf : P f) : P (i ≫ f) /-- A morphism property `P` satisfies `P.Respects Q` if it is stable under composition on the left and right by morphisms satisfying `Q`. -/ class Respects (P Q : MorphismProperty C) : Prop extends P.RespectsLeft Q, P.RespectsRight Q where instance (P Q : MorphismProperty C) [P.RespectsLeft Q] [P.RespectsRight Q] : P.Respects Q where instance (P Q : MorphismProperty C) [P.RespectsLeft Q] : P.op.RespectsRight Q.op where postcomp i hi f hf := RespectsLeft.precomp (Q := Q) i.unop hi f.unop hf instance (P Q : MorphismProperty C) [P.RespectsRight Q] : P.op.RespectsLeft Q.op where precomp i hi f hf := RespectsRight.postcomp (Q := Q) i.unop hi f.unop hf instance RespectsLeft.inf (P₁ P₂ Q : MorphismProperty C) [P₁.RespectsLeft Q] [P₂.RespectsLeft Q] : (P₁ ⊓ P₂).RespectsLeft Q where precomp i hi f hf := ⟨precomp i hi f hf.left, precomp i hi f hf.right⟩ instance RespectsRight.inf (P₁ P₂ Q : MorphismProperty C) [P₁.RespectsRight Q] [P₂.RespectsRight Q] : (P₁ ⊓ P₂).RespectsRight Q where postcomp i hi f hf := ⟨postcomp i hi f hf.left, postcomp i hi f hf.right⟩ end section variable (C : Type u) [Category.{v} C] /-- The `MorphismProperty C` satisfied by isomorphisms in `C`. -/ def isomorphisms : MorphismProperty C := fun _ _ f => IsIso f /-- The `MorphismProperty C` satisfied by monomorphisms in `C`. -/ def monomorphisms : MorphismProperty C := fun _ _ f => Mono f /-- The `MorphismProperty C` satisfied by epimorphisms in `C`. -/ def epimorphisms : MorphismProperty C := fun _ _ f => Epi f section variable {C} /-- `P` respects isomorphisms, if it respects the morphism property `isomorphisms C`, i.e. it is stable under pre- and postcomposition with isomorphisms. -/ abbrev RespectsIso (P : MorphismProperty C) : Prop := P.Respects (isomorphisms C) instance inf (P Q : MorphismProperty C) [P.RespectsIso] [Q.RespectsIso] : (P ⊓ Q).RespectsIso where lemma RespectsIso.mk (P : MorphismProperty C) (hprecomp : ∀ {X Y Z : C} (e : X ≅ Y) (f : Y ⟶ Z) (_ : P f), P (e.hom ≫ f)) (hpostcomp : ∀ {X Y Z : C} (e : Y ≅ Z) (f : X ⟶ Y) (_ : P f), P (f ≫ e.hom)) : P.RespectsIso where precomp e (_ : IsIso e) f hf := hprecomp (asIso e) f hf postcomp e (_ : IsIso e) f hf := hpostcomp (asIso e) f hf lemma RespectsIso.precomp (P : MorphismProperty C) [P.RespectsIso] {X Y Z : C} (e : X ⟶ Y) [IsIso e] (f : Y ⟶ Z) (hf : P f) : P (e ≫ f) := RespectsLeft.precomp (Q := isomorphisms C) e ‹IsIso e› f hf instance : RespectsIso (⊤ : MorphismProperty C) where precomp _ _ _ _ := trivial postcomp _ _ _ _ := trivial lemma RespectsIso.postcomp (P : MorphismProperty C) [P.RespectsIso] {X Y Z : C} (e : Y ⟶ Z) [IsIso e] (f : X ⟶ Y) (hf : P f) : P (f ≫ e) := RespectsRight.postcomp (Q := isomorphisms C) e ‹IsIso e› f hf instance RespectsIso.op (P : MorphismProperty C) [RespectsIso P] : RespectsIso P.op where precomp e (_ : IsIso e) f hf := postcomp P e.unop f.unop hf postcomp e (_ : IsIso e) f hf := precomp P e.unop f.unop hf instance RespectsIso.unop (P : MorphismProperty Cᵒᵖ) [RespectsIso P] : RespectsIso P.unop where precomp e (_ : IsIso e) f hf := postcomp P e.op f.op hf postcomp e (_ : IsIso e) f hf := precomp P e.op f.op hf /-- The closure by isomorphisms of a `MorphismProperty` -/ def isoClosure (P : MorphismProperty C) : MorphismProperty C := fun _ _ f => ∃ (Y₁ Y₂ : C) (f' : Y₁ ⟶ Y₂) (_ : P f'), Nonempty (Arrow.mk f' ≅ Arrow.mk f) lemma le_isoClosure (P : MorphismProperty C) : P ≤ P.isoClosure := fun _ _ f hf => ⟨_, _, f, hf, ⟨Iso.refl _⟩⟩ instance isoClosure_respectsIso (P : MorphismProperty C) : RespectsIso P.isoClosure where precomp := fun e (he : IsIso e) f ⟨_, _, f', hf', ⟨iso⟩⟩ => ⟨_, _, f', hf', ⟨Arrow.isoMk (asIso iso.hom.left ≪≫ asIso (inv e)) (asIso iso.hom.right) (by simp)⟩⟩ postcomp := fun e (he : IsIso e) f ⟨_, _, f', hf', ⟨iso⟩⟩ => ⟨_, _, f', hf', ⟨Arrow.isoMk (asIso iso.hom.left) (asIso iso.hom.right ≪≫ asIso e) (by simp)⟩⟩ lemma monotone_isoClosure : Monotone (isoClosure (C := C)) := by intro P Q h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ exact ⟨X', Y', f', h _ hf', ⟨e⟩⟩ theorem cancel_left_of_respectsIso (P : MorphismProperty C) [hP : RespectsIso P] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] : P (f ≫ g) ↔ P g := ⟨fun h => by simpa using RespectsIso.precomp P (inv f) (f ≫ g) h, RespectsIso.precomp P f g⟩ theorem cancel_right_of_respectsIso (P : MorphismProperty C) [hP : RespectsIso P] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] : P (f ≫ g) ↔ P f := ⟨fun h => by simpa using RespectsIso.postcomp P (inv g) (f ≫ g) h, RespectsIso.postcomp P g f⟩ lemma comma_iso_iff (P : MorphismProperty C) [P.RespectsIso] {A B : Type*} [Category A] [Category B] {L : A ⥤ C} {R : B ⥤ C} {f g : Comma L R} (e : f ≅ g) : P f.hom ↔ P g.hom := by simp [← Comma.inv_left_hom_right e.hom, cancel_left_of_respectsIso, cancel_right_of_respectsIso] theorem arrow_iso_iff (P : MorphismProperty C) [RespectsIso P] {f g : Arrow C} (e : f ≅ g) : P f.hom ↔ P g.hom := P.comma_iso_iff e theorem arrow_mk_iso_iff (P : MorphismProperty C) [RespectsIso P] {W X Y Z : C} {f : W ⟶ X} {g : Y ⟶ Z} (e : Arrow.mk f ≅ Arrow.mk g) : P f ↔ P g := P.arrow_iso_iff e theorem RespectsIso.of_respects_arrow_iso (P : MorphismProperty C) (hP : ∀ (f g : Arrow C) (_ : f ≅ g) (_ : P f.hom), P g.hom) : RespectsIso P where precomp {X Y Z} e (he : IsIso e) f hf := by refine hP (Arrow.mk f) (Arrow.mk (e ≫ f)) (Arrow.isoMk (asIso (inv e)) (Iso.refl _) ?_) hf simp postcomp {X Y Z} e (he : IsIso e) f hf := by refine hP (Arrow.mk f) (Arrow.mk (f ≫ e)) (Arrow.isoMk (Iso.refl _) (asIso e) ?_) hf simp lemma isoClosure_eq_iff (P : MorphismProperty C) : P.isoClosure = P ↔ P.RespectsIso := by refine ⟨(· ▸ P.isoClosure_respectsIso), fun hP ↦ le_antisymm ?_ (P.le_isoClosure)⟩ intro X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ exact (P.arrow_mk_iso_iff e).1 hf' lemma isoClosure_eq_self (P : MorphismProperty C) [P.RespectsIso] : P.isoClosure = P := by rwa [isoClosure_eq_iff] @[simp] lemma isoClosure_isoClosure (P : MorphismProperty C) : P.isoClosure.isoClosure = P.isoClosure := P.isoClosure.isoClosure_eq_self lemma isoClosure_le_iff (P Q : MorphismProperty C) [Q.RespectsIso] : P.isoClosure ≤ Q ↔ P ≤ Q := by constructor · exact P.le_isoClosure.trans · intro h exact (monotone_isoClosure h).trans (by rw [Q.isoClosure_eq_self]) section variable {D : Type*} [Category D] instance map_respectsIso (P : MorphismProperty C) (F : C ⥤ D) : (P.map F).RespectsIso := by apply RespectsIso.of_respects_arrow_iso intro f g e ⟨X', Y', f', hf', ⟨e'⟩⟩ exact ⟨X', Y', f', hf', ⟨e' ≪≫ e⟩⟩ lemma map_le_iff (P : MorphismProperty C) {F : C ⥤ D} (Q : MorphismProperty D) [RespectsIso Q] : P.map F ≤ Q ↔ P ≤ Q.inverseImage F := by constructor · intro h X Y f hf exact h (F.map f) (map_mem_map P F f hf) · intro h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ exact (Q.arrow_mk_iso_iff e).1 (h _ hf') @[simp] lemma map_isoClosure (P : MorphismProperty C) (F : C ⥤ D) : P.isoClosure.map F = P.map F := by apply le_antisymm · rw [map_le_iff] intro X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ exact ⟨_, _, f', hf', ⟨F.mapArrow.mapIso e⟩⟩ · exact monotone_map _ (le_isoClosure P) lemma map_id_eq_isoClosure (P : MorphismProperty C) : P.map (𝟭 _) = P.isoClosure := rfl lemma map_id (P : MorphismProperty C) [RespectsIso P] : P.map (𝟭 _) = P := by rw [map_id_eq_isoClosure, P.isoClosure_eq_self] @[simp] lemma map_map (P : MorphismProperty C) (F : C ⥤ D) {E : Type*} [Category E] (G : D ⥤ E) : (P.map F).map G = P.map (F ⋙ G) := by apply le_antisymm · rw [map_le_iff] intro X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ exact ⟨X', Y', f', hf', ⟨G.mapArrow.mapIso e⟩⟩ · rw [map_le_iff] intro X Y f hf exact map_mem_map _ _ _ (map_mem_map _ _ _ hf) instance RespectsIso.inverseImage (P : MorphismProperty D) [RespectsIso P] (F : C ⥤ D) : RespectsIso (P.inverseImage F) where precomp {X Y Z} e (he : IsIso e) f hf := by simpa [MorphismProperty.inverseImage, cancel_left_of_respectsIso] using hf postcomp {X Y Z} e (he : IsIso e) f hf := by simpa [MorphismProperty.inverseImage, cancel_right_of_respectsIso] using hf lemma map_eq_of_iso (P : MorphismProperty C) {F G : C ⥤ D} (e : F ≅ G) : P.map F = P.map G := by revert F G e suffices ∀ {F G : C ⥤ D} (_ : F ≅ G), P.map F ≤ P.map G from fun F G e => le_antisymm (this e) (this e.symm) intro F G e X Y f ⟨X', Y', f', hf', ⟨e'⟩⟩ exact ⟨X', Y', f', hf', ⟨((Functor.mapArrowFunctor _ _).mapIso e.symm).app (Arrow.mk f') ≪≫ e'⟩⟩ lemma map_inverseImage_le (P : MorphismProperty D) (F : C ⥤ D) : (P.inverseImage F).map F ≤ P.isoClosure := fun _ _ _ ⟨_, _, f, hf, ⟨e⟩⟩ => ⟨_, _, F.map f, hf, ⟨e⟩⟩ lemma inverseImage_equivalence_inverse_eq_map_functor (P : MorphismProperty D) [RespectsIso P] (E : C ≌ D) : P.inverseImage E.functor = P.map E.inverse := by apply le_antisymm · intro X Y f hf refine ⟨_, _, _, hf, ⟨?_⟩⟩ exact ((Functor.mapArrowFunctor _ _).mapIso E.unitIso.symm).app (Arrow.mk f) · rw [map_le_iff] intro X Y f hf exact (P.arrow_mk_iso_iff (((Functor.mapArrowFunctor _ _).mapIso E.counitIso).app (Arrow.mk f))).2 hf lemma inverseImage_equivalence_functor_eq_map_inverse (Q : MorphismProperty C) [RespectsIso Q] (E : C ≌ D) : Q.inverseImage E.inverse = Q.map E.functor := inverseImage_equivalence_inverse_eq_map_functor Q E.symm lemma map_inverseImage_eq_of_isEquivalence (P : MorphismProperty D) [P.RespectsIso] (F : C ⥤ D) [F.IsEquivalence] : (P.inverseImage F).map F = P := by erw [P.inverseImage_equivalence_inverse_eq_map_functor F.asEquivalence, map_map, P.map_eq_of_iso F.asEquivalence.counitIso, map_id] lemma inverseImage_map_eq_of_isEquivalence (P : MorphismProperty C) [P.RespectsIso] (F : C ⥤ D) [F.IsEquivalence] : (P.map F).inverseImage F = P := by erw [((P.map F).inverseImage_equivalence_inverse_eq_map_functor (F.asEquivalence)), map_map, P.map_eq_of_iso F.asEquivalence.unitIso.symm, map_id] end end section variable {C} variable {X Y : C} (f : X ⟶ Y) @[simp] theorem isomorphisms.iff : (isomorphisms C) f ↔ IsIso f := by rfl @[simp] theorem monomorphisms.iff : (monomorphisms C) f ↔ Mono f := by rfl @[simp] theorem epimorphisms.iff : (epimorphisms C) f ↔ Epi f := by rfl theorem isomorphisms.infer_property [hf : IsIso f] : (isomorphisms C) f := hf theorem monomorphisms.infer_property [hf : Mono f] : (monomorphisms C) f := hf theorem epimorphisms.infer_property [hf : Epi f] : (epimorphisms C) f := hf end lemma isomorphisms_op : (isomorphisms C).op = isomorphisms Cᵒᵖ := by ext X Y f simp only [op, isomorphisms.iff] exact ⟨fun _ ↦ inferInstanceAs (IsIso f.unop.op), fun _ ↦ inferInstance⟩ instance RespectsIso.monomorphisms : RespectsIso (monomorphisms C) := by apply RespectsIso.mk <;> · intro X Y Z e f simp only [monomorphisms.iff] intro apply mono_comp instance RespectsIso.epimorphisms : RespectsIso (epimorphisms C) := by apply RespectsIso.mk <;> · intro X Y Z e f simp only [epimorphisms.iff] intro apply epi_comp instance RespectsIso.isomorphisms : RespectsIso (isomorphisms C) := by apply RespectsIso.mk <;> · intro X Y Z e f simp only [isomorphisms.iff] intro exact IsIso.comp_isIso end /-- If `W₁` and `W₂` are morphism properties on two categories `C₁` and `C₂`, this is the induced morphism property on `C₁ × C₂`. -/ def prod {C₁ C₂ : Type*} [CategoryStruct C₁] [CategoryStruct C₂] (W₁ : MorphismProperty C₁) (W₂ : MorphismProperty C₂) : MorphismProperty (C₁ × C₂) := fun _ _ f => W₁ f.1 ∧ W₂ f.2 /-- If `W j` are morphism properties on categories `C j` for all `j`, this is the induced morphism property on the category `∀ j, C j`. -/ def pi {J : Type w} {C : J → Type u} [∀ j, Category.{v} (C j)] (W : ∀ j, MorphismProperty (C j)) : MorphismProperty (∀ j, C j) := fun _ _ f => ∀ j, (W j) (f j) variable {C} [Category.{v} C] /-- The morphism property on `J ⥤ C` which is defined objectwise from `W : MorphismProperty C`. -/ def functorCategory (W : MorphismProperty C) (J : Type*) [Category J] : MorphismProperty (J ⥤ C) := fun _ _ f => ∀ (j : J), W (f.app j) /-- Given `W : MorphismProperty C`, this is the morphism property on `Arrow C` of morphisms whose left and right parts are in `W`. -/ def arrow (W : MorphismProperty C) : MorphismProperty (Arrow C) := fun _ _ f => W f.left ∧ W f.right end MorphismProperty namespace NatTrans variable {C : Type u} [Category.{v} C] {D : Type*} [Category D] lemma isIso_app_iff_of_iso {F G : C ⥤ D} (α : F ⟶ G) {X Y : C} (e : X ≅ Y) : IsIso (α.app X) ↔ IsIso (α.app Y) := (MorphismProperty.isomorphisms D).arrow_mk_iso_iff (Arrow.isoMk (F.mapIso e) (G.mapIso e) (by simp)) end NatTrans end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Local.lean
import Mathlib.CategoryTheory.Sites.Hypercover.Zero import Mathlib.CategoryTheory.MorphismProperty.Limits /-! # Locality conditions on morphism properties In this file we define locality conditions on morphism properties in a category. Let `K` be a precoverage in a category `C` and `P` be a morphism property on `C` that respects isomorphisms. We say that - `P` is local at the target if for every `f : X ⟶ Y`, `P` holds for `f` if and only if it holds for the restrictions of `f` to `Uᵢ` for a `K`-cover `{Uᵢ}` of `Y`. - `P` is local at the source if for every `f : X ⟶ Y`, `P` holds for `f` if and only if it holds for the restrictions of `f` to `Uᵢ` for a `K`-cover `{Uᵢ}` of `X`. ## Implementation details The covers appearing in the definitions have index type in the morphism universe of `C`. ## TODOs - Define source and target local closure of a morphism property. -/ universe w v u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] namespace MorphismProperty variable (K : Precoverage C) /-- A property of morphisms `P` in `C` is local at the target with respect to the precoverage `K` if it respects isomorphisms, and: `P` holds for `f : X ⟶ Y` if and only if it holds for the restrictions of `f` to `Uᵢ` for a `0`-hypercover `{Uᵢ}` of `Y` in the precoverage `K`. For a version of `of_zeroHypercover` that takes a `v`-small `0`-hypercover in an arbitrary universe, use `CategoryTheory.MorphismProperty.of_zeroHypercover_target`. -/ class IsLocalAtTarget (P : MorphismProperty C) (K : Precoverage C) [K.HasPullbacks] extends RespectsIso P where /-- If `P` holds for `f : X ⟶ Y`, it also holds for `f` restricted to `Uᵢ` for any `K`-cover `𝒰` of `Y`. -/ pullbackSnd {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{v} K Y) (i : 𝒰.I₀) (hf : P f) : P (pullback.snd f (𝒰.f i)) /-- If `P` holds for `f` restricted to `Uᵢ` for all `i`, it also holds for `f : X ⟶ Y` for any `K`-cover `𝒰` of `Y`. -/ of_zeroHypercover {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{v} K Y) (h : ∀ i, P (pullback.snd f (𝒰.f i))) : P f namespace IsLocalAtTarget variable {P : MorphismProperty C} {K L : Precoverage C} [K.HasPullbacks] lemma mk_of_iff [P.RespectsIso] (H : ∀ {X Y : C} (f : X ⟶ Y) (𝒰 : Precoverage.ZeroHypercover.{v} K Y), P f ↔ ∀ i, P (pullback.snd f (𝒰.f i))) : P.IsLocalAtTarget K where pullbackSnd 𝒰 i h := (H _ 𝒰).mp h i of_zeroHypercover 𝒰 h := (H _ 𝒰).mpr h lemma mk_of_isStableUnderBaseChange [P.IsStableUnderBaseChange] (H : ∀ {X Y : C} (f : X ⟶ Y) (𝒰 : Precoverage.ZeroHypercover.{v} K Y), (∀ i, P (pullback.snd f (𝒰.f i))) → P f) : P.IsLocalAtTarget K where pullbackSnd _ _ hf := P.pullback_snd _ _ hf of_zeroHypercover _ := H _ _ lemma of_le [L.HasPullbacks] [IsLocalAtTarget P L] (hle : K ≤ L) : IsLocalAtTarget P K where pullbackSnd 𝒰 i hf := pullbackSnd (𝒰.weaken hle) i hf of_zeroHypercover 𝒰 := of_zeroHypercover (𝒰.weaken hle) instance top : IsLocalAtTarget (⊤ : MorphismProperty C) K where pullbackSnd := by simp of_zeroHypercover := by simp variable [IsLocalAtTarget P K] {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{v} K Y) lemma of_isPullback {X' : C} (i : 𝒰.I₀) {fst : X' ⟶ X} {snd : X' ⟶ 𝒰.X i} (h : IsPullback fst snd f (𝒰.f i)) (hf : P f) : P snd := by rw [← P.cancel_left_of_respectsIso h.isoPullback.inv, h.isoPullback_inv_snd] exact pullbackSnd _ _ hf lemma iff_of_zeroHypercover : P f ↔ ∀ i, P (pullback.snd f (𝒰.f i)) := ⟨fun hf _ ↦ pullbackSnd _ _ hf, fun h ↦ of_zeroHypercover _ h⟩ instance inf (P Q : MorphismProperty C) [IsLocalAtTarget P K] [IsLocalAtTarget Q K] : IsLocalAtTarget (P ⊓ Q) K where pullbackSnd _ i h := ⟨pullbackSnd _ i h.1, pullbackSnd _ i h.2⟩ of_zeroHypercover _ h := ⟨of_zeroHypercover _ fun i ↦ (h i).1, of_zeroHypercover _ fun i ↦ (h i).2⟩ end IsLocalAtTarget lemma of_zeroHypercover_target {P : MorphismProperty C} {K : Precoverage C} [K.HasPullbacks] [P.IsLocalAtTarget K] {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{w} K Y) [Precoverage.ZeroHypercover.Small.{v} 𝒰] (h : ∀ i, P (pullback.snd f (𝒰.f i))) : P f := by rw [IsLocalAtTarget.iff_of_zeroHypercover (P := P) 𝒰.restrictIndexOfSmall] simp [h] alias iff_of_zeroHypercover_target := IsLocalAtTarget.iff_of_zeroHypercover /-- A property of morphisms `P` in `C` is local at the source with respect to the precoverage `K` if it respects isomorphisms, and: `P` holds for `f : X ⟶ Y` if and only if it holds for the restrictions of `f` to `Uᵢ` for a `0`-hypercover `{Uᵢ}` of `X` in the precoverage `K`. For a version of `of_zeroHypercover` that takes a `v`-small `0`-hypercover in an arbitrary universe, use `CategoryTheory.MorphismProperty.of_zeroHypercover_source`. -/ class IsLocalAtSource (P : MorphismProperty C) (K : Precoverage C) extends RespectsIso P where /-- If `P` holds for `f : X ⟶ Y`, it also holds for `𝒰.f i ≫ f` for any `K`-cover `𝒰` of `X`. -/ comp {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{v} K X) (i : 𝒰.I₀) (hf : P f) : P (𝒰.f i ≫ f) /-- If `P` holds for `𝒰.f i ≫ f` for all `i`, it holds for `f : X ⟶ Y` for any `K`-cover `𝒰` of X. -/ of_zeroHypercover {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{v} K X) : (∀ i, P (𝒰.f i ≫ f)) → P f namespace IsLocalAtSource variable {P : MorphismProperty C} {K L : Precoverage C} lemma mk_of_iff [P.RespectsIso] (H : ∀ {X Y : C} (f : X ⟶ Y) (𝒰 : Precoverage.ZeroHypercover.{v} K X), P f ↔ ∀ i, P (𝒰.f i ≫ f)) : P.IsLocalAtSource K where comp 𝒰 i h := (H _ 𝒰).mp h i of_zeroHypercover 𝒰 h := (H _ 𝒰).mpr h lemma of_le [IsLocalAtSource P L] (hle : K ≤ L) : IsLocalAtSource P K where comp 𝒰 i hf := comp (𝒰.weaken hle) i hf of_zeroHypercover 𝒰 h := of_zeroHypercover (𝒰.weaken hle) h instance top : IsLocalAtSource (⊤ : MorphismProperty C) K where comp := by simp of_zeroHypercover := by simp variable [IsLocalAtSource P K] {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{v} K X) lemma iff_of_zeroHypercover : P f ↔ ∀ i, P (𝒰.f i ≫ f) := ⟨fun hf i ↦ comp _ i hf, fun h ↦ of_zeroHypercover _ h⟩ instance inf (P Q : MorphismProperty C) [IsLocalAtSource P K] [IsLocalAtSource Q K] : IsLocalAtSource (P ⊓ Q) K where comp 𝒰 i hf := ⟨comp 𝒰 i hf.1, comp 𝒰 i hf.2⟩ of_zeroHypercover _ h := ⟨of_zeroHypercover _ fun i ↦ (h i).1, of_zeroHypercover _ fun i ↦ (h i).2⟩ end IsLocalAtSource lemma of_zeroHypercover_source {P : MorphismProperty C} {K : Precoverage C} [P.IsLocalAtSource K] {X Y : C} {f : X ⟶ Y} (𝒰 : Precoverage.ZeroHypercover.{w} K X) [Precoverage.ZeroHypercover.Small.{v} 𝒰] (h : ∀ i, P (𝒰.f i ≫ f)) : P f := by rw [IsLocalAtSource.iff_of_zeroHypercover (P := P) 𝒰.restrictIndexOfSmall] simp [h] alias iff_of_zeroHypercover_source := IsLocalAtSource.iff_of_zeroHypercover end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/RetractArgument.lean
import Mathlib.CategoryTheory.MorphismProperty.Factorization import Mathlib.CategoryTheory.MorphismProperty.LiftingProperty /-! # The retract argument Let `W₁` and `W₂` be classes of morphisms in a category `C` such that any morphism can be factored as a morphism in `W₁` followed by a morphism in `W₂` (this is `HasFactorization W₁ W₂`). If `W₁` has the left lifting property with respect to `W₂` (i.e. `W₁ ≤ W₂.llp`, or equivalently `W₂ ≤ W₁.rlp`), then `W₂.llp = W₁` if `W₁` is stable under retracts, and `W₁.rlp = W₂` if `W₂` is. ## Reference - https://ncatlab.org/nlab/show/weak+factorization+system#retract_argument -/ namespace CategoryTheory variable {C : Type*} [Category C] /-- If `i ≫ p = f`, and `f` has the left lifting property with respect to `p`, then `f` is a retract of `i`. -/ noncomputable def RetractArrow.ofLeftLiftingProperty {X Y Z : C} {f : X ⟶ Z} {i : X ⟶ Y} {p : Y ⟶ Z} (h : i ≫ p = f) [HasLiftingProperty f p] : RetractArrow f i := have sq : CommSq i f p (𝟙 _) := ⟨by simp [h]⟩ { i := Arrow.homMk (𝟙 X) sq.lift r := Arrow.homMk (𝟙 X) p } /-- If `i ≫ p = f`, and `f` has the right lifting property with respect to `i`, then `f` is a retract of `p`. -/ noncomputable def RetractArrow.ofRightLiftingProperty {X Y Z : C} {f : X ⟶ Z} {i : X ⟶ Y} {p : Y ⟶ Z} (h : i ≫ p = f) [HasLiftingProperty i f] : RetractArrow f p := have sq : CommSq (𝟙 _) i f p := ⟨by simp [h]⟩ { i := Arrow.homMk i (𝟙 _) r := Arrow.homMk sq.lift (𝟙 _) } namespace MorphismProperty variable {W₁ W₂ : MorphismProperty C} lemma llp_eq_of_le_llp_of_hasFactorization_of_isStableUnderRetracts [HasFactorization W₁ W₂] [W₁.IsStableUnderRetracts] (h₁ : W₁ ≤ W₂.llp) : W₂.llp = W₁ := le_antisymm (fun A B i hi ↦ by have h := factorizationData W₁ W₂ i have := hi _ h.hp simpa using of_retract (RetractArrow.ofLeftLiftingProperty h.fac) h.hi) h₁ lemma rlp_eq_of_le_rlp_of_hasFactorization_of_isStableUnderRetracts [HasFactorization W₁ W₂] [W₂.IsStableUnderRetracts] (h₂ : W₂ ≤ W₁.rlp) : W₁.rlp = W₂ := le_antisymm (fun X Y p hp ↦ by have h := factorizationData W₁ W₂ p have := hp _ h.hi simpa using of_retract (RetractArrow.ofRightLiftingProperty h.fac) h.hp) h₂ end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Ind.lean
import Mathlib.CategoryTheory.Comma.LocallySmall import Mathlib.CategoryTheory.Limits.Preserves.Over import Mathlib.CategoryTheory.MorphismProperty.Comma import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.CategoryTheory.ObjectProperty.Ind /-! # Ind and pro-properties Given a morphism property `P`, we define a morphism property `ind P` that is satisfied for `f : X ⟶ Y` if `Y` is a filtered colimit of `Yᵢ` and `fᵢ : X ⟶ Yᵢ` satisfy `P`. We show that `ind P` inherits stability properties from `P`. ## Main definitions - `CategoryTheory.MorphismProperty.ind`: `f` satisfies `ind P` if `f` is a filtered colimit of morphisms in `P`. ## Main results: - `CategoryTheory.MorphismProperty.ind_ind`: If `P` implies finitely presentable, then `P.ind.ind = P.ind`. ## TODOs: - Dualise to obtain `pro P`. - Show `ind P` is stable under composition if `P` spreads out (Christian). -/ universe w v u namespace CategoryTheory.MorphismProperty open Limits Opposite variable {C : Type u} [Category.{v} C] (P : MorphismProperty C) /-- Let `P` be a property of morphisms. `P.ind` is satisfied for `f : X ⟶ Y` if there exists a family of natural maps `tᵢ : X ⟶ Yᵢ` and `sᵢ : Yᵢ ⟶ Y` indexed by `J` such that - `J` is filtered - `Y ≅ colim Yᵢ` via `{sᵢ}ᵢ` - `tᵢ` satisfies `P` for all `i` - `f = tᵢ ≫ sᵢ` for all `i`. See `CategoryTheory.MorphismProperty.ind_iff_ind_under_mk` for an equivalent characterization in terms of `Y` as an object of `Under X`. -/ def ind (P : MorphismProperty C) : MorphismProperty C := fun X Y f ↦ ∃ (J : Type w) (_ : SmallCategory J) (_ : IsFiltered J) (D : J ⥤ C) (t : (Functor.const J).obj X ⟶ D) (s : D ⟶ (Functor.const J).obj Y) (_ : IsColimit (Cocone.mk _ s)), ∀ j, P (t.app j) ∧ t.app j ≫ s.app j = f lemma exists_hom_of_isFinitelyPresentable {J : Type w} [SmallCategory J] [IsFiltered J] {D : J ⥤ C} {c : Cocone D} (hc : IsColimit c) {X A : C} {p : X ⟶ A} (hp : isFinitelyPresentable.{w} C p) (s : (Functor.const J).obj X ⟶ D) (f : A ⟶ c.pt) (h : ∀ (j : J), s.app j ≫ c.ι.app j = p ≫ f) : ∃ (j : J) (q : A ⟶ D.obj j), p ≫ q = s.app j ∧ q ≫ c.ι.app j = f := hp.exists_hom_of_isColimit_under hc _ s _ h lemma le_ind : P ≤ ind.{w} P := by intro X Y f hf refine ⟨PUnit, inferInstance, inferInstance, (Functor.const PUnit).obj Y, ?_, 𝟙 _, ?_, ?_⟩ · exact { app _ := f } · exact isColimitConstCocone _ _ · simpa variable {P} lemma ind_iff_ind_underMk {X Y : C} (f : X ⟶ Y) : ind.{w} P f ↔ ObjectProperty.ind.{w} P.underObj (CategoryTheory.Under.mk f) := by refine ⟨fun ⟨J, _, _, D, t, s, hs, hst⟩ ↦ ?_, fun ⟨J, _, _, pres, hpres⟩ ↦ ?_⟩ · refine ⟨J, ‹_›, ‹_›, ⟨Under.lift D t, ?_, ?_⟩, ?_⟩ · exact { app j := CategoryTheory.Under.homMk (s.app j) (by simp [hst]) } · have : Nonempty J := IsFiltered.nonempty exact Under.isColimitLiftCocone _ _ _ _ (by simp [hst]) hs · simp [underObj, hst] · refine ⟨J, ‹_›, ‹_›, pres.diag ⋙ CategoryTheory.Under.forget _, ?_, ?_, ?_, fun j ↦ ⟨?_, ?_⟩⟩ · exact { app j := (pres.diag.obj j).hom } · exact Functor.whiskerRight pres.ι (CategoryTheory.Under.forget X) · exact isColimitOfPreserves (CategoryTheory.Under.forget _) pres.isColimit · exact hpres j · simp lemma underObj_ind_eq_ind_underObj (X : C) : underObj (ind.{w} P) (X := X) = ObjectProperty.ind.{w} P.underObj := by ext f simp [underObj, show f = CategoryTheory.Under.mk f.hom from rfl, ind_iff_ind_underMk] variable (Q : MorphismProperty C) instance [P.RespectsLeft Q] : P.ind.RespectsLeft Q where precomp {X Y Z} i hi f := fun ⟨J, _, _, D, t, s, hs, hst⟩ ↦ by refine ⟨J, ‹_›, ‹_›, D, (Functor.const J).map i ≫ t, s, hs, fun j ↦ ⟨?_, by simp [hst]⟩⟩ exact RespectsLeft.precomp _ hi _ (hst j).1 instance [P.RespectsIso] : P.ind.RespectsIso where postcomp {X Y Z} i (hi : IsIso i) f := fun ⟨J, _, _, D, t, s, hs, hst⟩ ↦ by refine ⟨J, ‹_›, ‹_›, D, t, s ≫ (Functor.const J).map i, ?_, fun j ↦ ⟨(hst j).1, ?_⟩⟩ · exact (IsColimit.equivIsoColimit (Cocones.ext (asIso i))) hs · simp [reassoc_of% (hst j).2] lemma ind_underObj_pushout {X Y : C} (g : X ⟶ Y) [HasPushouts C] [P.IsStableUnderCobaseChange] {f : Under X} (hf : ObjectProperty.ind.{w} P.underObj f) : ObjectProperty.ind.{w} P.underObj ((Under.pushout g).obj f) := by obtain ⟨J, _, _, pres, hpres⟩ := hf use J, inferInstance, inferInstance, pres.map (Under.pushout g) intro i exact P.pushout_inr _ _ (hpres i) instance [P.IsStableUnderCobaseChange] [HasPushouts C] : P.ind.IsStableUnderCobaseChange := by refine .mk' fun A B A' f g _ hf ↦ ?_ rw [ind_iff_ind_underMk] at hf ⊢ exact ind_underObj_pushout g hf /-- `ind` is idempotent if `P` implies finitely presentable. -/ lemma ind_ind (hp : P ≤ isFinitelyPresentable.{w} C) [LocallySmall.{w} C] : ind.{w} (ind.{w} P) = ind.{w} P := by refine le_antisymm (fun X Y f hf ↦ ?_) P.ind.le_ind have : P.underObj ≤ ObjectProperty.isFinitelyPresentable.{w} (Under X) := fun f hf ↦ hp _ hf simpa [ind_iff_ind_underMk, underObj_ind_eq_ind_underObj, ObjectProperty.ind_ind.{w} this] using hf end CategoryTheory.MorphismProperty
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Factorization.lean
import Mathlib.CategoryTheory.MorphismProperty.Basic /-! # The factorization axiom In this file, we introduce a type-class `HasFactorization W₁ W₂`, which, given two classes of morphisms `W₁` and `W₂` in a category `C`, asserts that any morphism in `C` can be factored as a morphism in `W₁` followed by a morphism in `W₂`. The data of such factorizations can be packaged in the type `FactorizationData W₁ W₂`. This shall be used in the formalization of model categories for which the CM5 axiom asserts that any morphism can be factored as a cofibration followed by a trivial fibration (or a trivial cofibration followed by a fibration). We also provide a structure `FunctorialFactorizationData W₁ W₂` which contains the data of a functorial factorization as above. With this design, when we formalize certain constructions (e.g. cylinder objects in model categories), we may first construct them using the data `data : FactorizationData W₁ W₂`. Without duplication of code, it shall be possible to show these cylinders are functorial when a term `data : FunctorialFactorizationData W₁ W₂` is available, the existence of which is asserted in the type-class `HasFunctorialFactorization W₁ W₂`. We also introduce the class `W₁.comp W₂` of morphisms of the form `i ≫ p` with `W₁ i` and `W₂ p` and show that `W₁.comp W₂ = ⊤` iff `HasFactorization W₁ W₂` holds (this is `MorphismProperty.comp_eq_top_iff`). -/ namespace CategoryTheory namespace MorphismProperty variable {C : Type*} [Category C] (W₁ W₂ : MorphismProperty C) /-- Given two classes of morphisms `W₁` and `W₂` on a category `C`, this is the data of the factorization of a morphism `f : X ⟶ Y` as `i ≫ p` with `W₁ i` and `W₂ p`. -/ structure MapFactorizationData {X Y : C} (f : X ⟶ Y) where /-- the intermediate object in the factorization -/ Z : C /-- the first morphism in the factorization -/ i : X ⟶ Z /-- the second morphism in the factorization -/ p : Z ⟶ Y fac : i ≫ p = f := by cat_disch hi : W₁ i hp : W₂ p namespace MapFactorizationData attribute [reassoc (attr := simp)] fac variable {X Y : C} (f : X ⟶ Y) /-- The opposite of a factorization. -/ @[simps] def op {X Y : C} {f : X ⟶ Y} (hf : MapFactorizationData W₁ W₂ f) : MapFactorizationData W₂.op W₁.op f.op where Z := Opposite.op hf.Z i := hf.p.op p := hf.i.op fac := Quiver.Hom.unop_inj (by simp) hi := hf.hp hp := hf.hi end MapFactorizationData /-- The data of a term in `MapFactorizationData W₁ W₂ f` for any morphism `f`. -/ abbrev FactorizationData := ∀ {X Y : C} (f : X ⟶ Y), MapFactorizationData W₁ W₂ f /-- The factorization axiom for two classes of morphisms `W₁` and `W₂` in a category `C`. It asserts that any morphism can be factored as a morphism in `W₁` followed by a morphism in `W₂`. -/ class HasFactorization : Prop where nonempty_mapFactorizationData {X Y : C} (f : X ⟶ Y) : Nonempty (MapFactorizationData W₁ W₂ f) /-- A chosen term in `FactorizationData W₁ W₂` when `HasFactorization W₁ W₂` holds. -/ noncomputable def factorizationData [HasFactorization W₁ W₂] : FactorizationData W₁ W₂ := fun _ => Nonempty.some (HasFactorization.nonempty_mapFactorizationData _) instance [HasFactorization W₁ W₂] : HasFactorization W₂.op W₁.op where nonempty_mapFactorizationData f := ⟨(factorizationData W₁ W₂ f.unop).op⟩ /-- The class of morphisms that are of the form `i ≫ p` with `W₁ i` and `W₂ p`. -/ def comp : MorphismProperty C := fun _ _ f => Nonempty (MapFactorizationData W₁ W₂ f) lemma comp_eq_top_iff : W₁.comp W₂ = ⊤ ↔ HasFactorization W₁ W₂ := by constructor · intro h refine ⟨fun f => ?_⟩ have : W₁.comp W₂ f := by simp only [h, top_apply] exact ⟨this.some⟩ · intro ext X Y f simp only [top_apply, iff_true] exact ⟨factorizationData W₁ W₂ f⟩ /-- The data of a functorial factorization of any morphism in `C` as a morphism in `W₁` followed by a morphism in `W₂`. -/ structure FunctorialFactorizationData where /-- the intermediate objects in the factorizations -/ Z : Arrow C ⥤ C /-- the first morphism in the factorizations -/ i : Arrow.leftFunc ⟶ Z /-- the second morphism in the factorizations -/ p : Z ⟶ Arrow.rightFunc fac : i ≫ p = Arrow.leftToRight := by cat_disch hi (f : Arrow C) : W₁ (i.app f) hp (f : Arrow C) : W₂ (p.app f) namespace FunctorialFactorizationData variable {W₁ W₂} variable (data : FunctorialFactorizationData W₁ W₂) attribute [reassoc (attr := simp)] fac @[reassoc (attr := simp)] lemma fac_app {f : Arrow C} : data.i.app f ≫ data.p.app f = f.hom := by rw [← NatTrans.comp_app, fac, Arrow.leftToRight_app] /-- If `W₁ ≤ W₁'` and `W₂ ≤ W₂'`, then a functorial factorization for `W₁` and `W₂` induces a functorial factorization for `W₁'` and `W₂'`. -/ def ofLE {W₁' W₂' : MorphismProperty C} (le₁ : W₁ ≤ W₁') (le₂ : W₂ ≤ W₂') : FunctorialFactorizationData W₁' W₂' where Z := data.Z i := data.i p := data.p hi f := le₁ _ (data.hi f) hp f := le₂ _ (data.hp f) /-- The term in `FactorizationData W₁ W₂` that is deduced from a functorial factorization. -/ def factorizationData : FactorizationData W₁ W₂ := fun f => { Z := data.Z.obj (Arrow.mk f) i := data.i.app (Arrow.mk f) p := data.p.app (Arrow.mk f) hi := data.hi _ hp := data.hp _ } section variable {X Y X' Y' : C} {f : X ⟶ Y} {g : X' ⟶ Y'} (φ : Arrow.mk f ⟶ Arrow.mk g) /-- When `data : FunctorialFactorizationData W₁ W₂`, this is the morphism `(data.factorizationData f).Z ⟶ (data.factorizationData g).Z` expressing the functoriality of the intermediate objects of the factorizations for `φ : Arrow.mk f ⟶ Arrow.mk g`. -/ def mapZ : (data.factorizationData f).Z ⟶ (data.factorizationData g).Z := data.Z.map φ @[reassoc (attr := simp)] lemma i_mapZ : (data.factorizationData f).i ≫ data.mapZ φ = φ.left ≫ (data.factorizationData g).i := (data.i.naturality φ).symm @[reassoc (attr := simp)] lemma mapZ_p : data.mapZ φ ≫ (data.factorizationData g).p = (data.factorizationData f).p ≫ φ.right := data.p.naturality φ variable (f) in @[simp] lemma mapZ_id : data.mapZ (𝟙 (Arrow.mk f)) = 𝟙 _ := data.Z.map_id _ @[reassoc, simp] lemma mapZ_comp {X'' Y'' : C} {h : X'' ⟶ Y''} (ψ : Arrow.mk g ⟶ Arrow.mk h) : data.mapZ (φ ≫ ψ) = data.mapZ φ ≫ data.mapZ ψ := data.Z.map_comp _ _ end section variable (J : Type*) [Category J] /-- Auxiliary definition for `FunctorialFactorizationData.functorCategory`. -/ @[simps] def functorCategory.Z : Arrow (J ⥤ C) ⥤ J ⥤ C where obj f := { obj := fun j => (data.factorizationData (f.hom.app j)).Z map := fun φ => data.mapZ { left := f.left.map φ right := f.right.map φ } map_id := fun j => by dsimp rw [← data.mapZ_id (f.hom.app j)] congr <;> simp map_comp := fun _ _ => by dsimp rw [← data.mapZ_comp] congr <;> simp } map τ := { app := fun j => data.mapZ { left := τ.left.app j right := τ.right.app j w := congr_app τ.w j } naturality := fun _ _ α => by dsimp rw [← data.mapZ_comp, ← data.mapZ_comp] congr 1 ext <;> simp } map_id f := by ext j dsimp rw [← data.mapZ_id] congr 1 map_comp f g := by ext j dsimp rw [← data.mapZ_comp] congr 1 /-- A functorial factorization in the category `C` extends to the functor category `J ⥤ C`. -/ def functorCategory : FunctorialFactorizationData (W₁.functorCategory J) (W₂.functorCategory J) where Z := functorCategory.Z data J i := { app := fun f => { app := fun j => (data.factorizationData (f.hom.app j)).i } } p := { app := fun f => { app := fun j => (data.factorizationData (f.hom.app j)).p } } hi _ _ := data.hi _ hp _ _ := data.hp _ end end FunctorialFactorizationData /-- The functorial factorization axiom for two classes of morphisms `W₁` and `W₂` in a category `C`. It asserts that any morphism can be factored in a functorial manner as a morphism in `W₁` followed by a morphism in `W₂`. -/ class HasFunctorialFactorization : Prop where nonempty_functorialFactorizationData : Nonempty (FunctorialFactorizationData W₁ W₂) /-- A chosen term in `FunctorialFactorizationData W₁ W₂` when the functorial factorization axiom `HasFunctorialFactorization W₁ W₂` holds. -/ noncomputable def functorialFactorizationData [HasFunctorialFactorization W₁ W₂] : FunctorialFactorizationData W₁ W₂ := Nonempty.some (HasFunctorialFactorization.nonempty_functorialFactorizationData) instance [HasFunctorialFactorization W₁ W₂] : HasFactorization W₁ W₂ where nonempty_mapFactorizationData f := ⟨(functorialFactorizationData W₁ W₂).factorizationData f⟩ instance [HasFunctorialFactorization W₁ W₂] (J : Type*) [Category J] : HasFunctorialFactorization (W₁.functorCategory J) (W₂.functorCategory J) := ⟨⟨(functorialFactorizationData W₁ W₂).functorCategory J⟩⟩ end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/WeakFactorizationSystem.lean
import Mathlib.CategoryTheory.MorphismProperty.RetractArgument /-! # Weak factorization systems In this file, we introduce the notion of weak factorization system, which is a property of two classes of morphisms `W₁` and `W₂` in a category `C`. The type class `IsWeakFactorizationSystem W₁ W₂` asserts that `W₁` is exactly `W₂.llp`, `W₂` is exactly `W₁.rlp`, and any morphism in `C` can be factored a `i ≫ p` with `W₁ i` and `W₂ p`. ## References * https://ncatlab.org/nlab/show/weak+factorization+system -/ universe v u namespace CategoryTheory.MorphismProperty variable {C : Type u} [Category.{v} C] (W₁ W₂ : MorphismProperty C) /-- Two classes of morphisms `W₁` and `W₂` in a category `C` form a weak factorization system if `W₁` is exactly `W₂.llp`, `W₂` is exactly `W₁.rlp`, and any morphism can be factored a `i ≫ p` with `W₁ i` and `W₂ p`. -/ class IsWeakFactorizationSystem : Prop where rlp : W₁.rlp = W₂ llp : W₂.llp = W₁ hasFactorization : HasFactorization W₁ W₂ := by infer_instance namespace IsWeakFactorizationSystem attribute [instance] hasFactorization lemma mk' [HasFactorization W₁ W₂] [W₁.IsStableUnderRetracts] [W₂.IsStableUnderRetracts] (h : ∀ {A B X Y : C} (i : A ⟶ B) (p : X ⟶ Y), W₁ i → W₂ p → HasLiftingProperty i p) : IsWeakFactorizationSystem W₁ W₂ where rlp := rlp_eq_of_le_rlp_of_hasFactorization_of_isStableUnderRetracts (fun _ _ _ hp _ _ _ hi ↦ h _ _ hi hp) llp := llp_eq_of_le_llp_of_hasFactorization_of_isStableUnderRetracts (fun _ _ _ hi _ _ _ hp ↦ h _ _ hi hp) end IsWeakFactorizationSystem section variable [IsWeakFactorizationSystem W₁ W₂] lemma rlp_eq_of_wfs : W₁.rlp = W₂ := IsWeakFactorizationSystem.rlp lemma llp_eq_of_wfs : W₂.llp = W₁ := IsWeakFactorizationSystem.llp variable {W₁ W₂} in lemma hasLiftingProperty_of_wfs {A B X Y : C} (i : A ⟶ B) (p : X ⟶ Y) (hi : W₁ i) (hp : W₂ p) : HasLiftingProperty i p := (llp_eq_of_wfs W₁ W₂ ▸ hi) p hp end end CategoryTheory.MorphismProperty
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Representable.lean
import Mathlib.CategoryTheory.MorphismProperty.Limits /-! # Relatively representable morphisms In this file we define and develop basic results about relatively representable morphisms. Classically, a morphism `f : F ⟶ G` of presheaves is said to be representable if for any morphism `g : yoneda.obj X ⟶ G`, there exists a pullback square of the following form ``` yoneda.obj Y --yoneda.map snd--> yoneda.obj X | | fst g | | v v F ------------ f --------------> G ``` In this file, we define a notion of relative representability which works with respect to any functor, and not just `yoneda`. The fact that a morphism `f : F ⟶ G` between presheaves is representable in the classical case will then be given by `yoneda.relativelyRepresentable f`. ## Main definitions Throughout this file, `F : C ⥤ D` is a functor between categories `C` and `D`. * `Functor.relativelyRepresentable`: A morphism `f : X ⟶ Y` in `D` is said to be relatively representable with respect to `F`, if for any `g : F.obj a ⟶ Y`, there exists a pullback square of the following form ``` F.obj b --F.map snd--> F.obj a | | fst g | | v v X ------- f --------> Y ``` * `MorphismProperty.relative`: Given a morphism property `P` in `C`, a morphism `f : X ⟶ Y` in `D` satisfies `P.relative F` if it is relatively representable and for any `g : F.obj a ⟶ Y`, the property `P` holds for any represented pullback of `f` by `g`. ## API Given `hf : relativelyRepresentable f`, with `f : X ⟶ Y` and `g : F.obj a ⟶ Y`, we provide: * `hf.pullback g` which is the object in `C` such that `F.obj (hf.pullback g)` is a pullback of `f` and `g`. * `hf.snd g` is the morphism `hf.pullback g ⟶ F.obj a` * `hf.fst g` is the morphism `F.obj (hf.pullback g) ⟶ X` * If `F` is full, and `f` is of type `F.obj c ⟶ G`, we also have `hf.fst' g : hf.pullback g ⟶ X` which is the preimage under `F` of `hf.fst g`. * `hom_ext`, `hom_ext'`, `lift`, `lift'` are variants of the universal property of `F.obj (hf.pullback g)`, where as much as possible has been formulated internally to `C`. For these theorems we also need that `F` is full and/or faithful. * `symmetry` and `symmetryIso` are variants of the fact that pullbacks are symmetric for representable morphisms, formulated internally to `C`. We assume that `F` is fully faithful here. We also provide some basic API for dealing with triple pullbacks, i.e. given `hf₁ : relativelyRepresentable f₁`, `f₂ : F.obj A₂ ⟶ X` and `f₃ : F.obj A₃ ⟶ X`, we define `hf₁.pullback₃ f₂ f₃` to be the pullback of `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. We then develop some API for working with this object, mirroring the usual API for pullbacks, but where as much as possible is phrased internally to `C`. ## Main results * `relativelyRepresentable.isMultiplicative`: The class of relatively representable morphisms is multiplicative. * `relativelyRepresentable.isStableUnderBaseChange`: Being relatively representable is stable under base change. * `relativelyRepresentable.of_isIso`: Isomorphisms are relatively representable. -/ namespace CategoryTheory open Category Limits MorphismProperty universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) /-- A morphism `f : X ⟶ Y` in `D` is said to be relatively representable if for any `g : F.obj a ⟶ Y`, there exists a pullback square of the following form ``` F.obj b --F.map snd--> F.obj a | | fst g | | v v X ------- f --------> Y ``` -/ def Functor.relativelyRepresentable : MorphismProperty D := fun X Y f ↦ ∀ ⦃a : C⦄ (g : F.obj a ⟶ Y), ∃ (b : C) (snd : b ⟶ a) (fst : F.obj b ⟶ X), IsPullback fst (F.map snd) f g namespace Functor.relativelyRepresentable section variable {F} variable {X Y : D} {f : X ⟶ Y} (hf : F.relativelyRepresentable f) {b : C} {f' : F.obj b ⟶ Y} (hf' : F.relativelyRepresentable f') {a : C} (g : F.obj a ⟶ Y) (hg : F.relativelyRepresentable g) /-- Let `f : X ⟶ Y` be a relatively representable morphism in `D`. Then, for any `g : F.obj a ⟶ Y`, `hf.pullback g` denotes the (choice of) a corresponding object in `C` such that there is a pullback square of the following form ``` hf.pullback g --F.map snd--> F.obj a | | fst g | | v v X ---------- f ----------> Y ``` -/ noncomputable def pullback : C := (hf g).choose /-- Given a representable morphism `f : X ⟶ Y`, then for any `g : F.obj a ⟶ Y`, `hf.snd g` denotes the morphism in `C` giving rise to the following diagram ``` hf.pullback g --F.map (hf.snd g)--> F.obj a | | fst g | | v v X -------------- f -------------> Y ``` -/ noncomputable abbrev snd : hf.pullback g ⟶ a := (hf g).choose_spec.choose /-- Given a relatively representable morphism `f : X ⟶ Y`, then for any `g : F.obj a ⟶ Y`, `hf.fst g` denotes the first projection in the following diagram, given by the defining property of `f` being relatively representable ``` hf.pullback g --F.map (hf.snd g)--> F.obj a | | hf.fst g g | | v v X -------------- f -------------> Y ``` -/ noncomputable abbrev fst : F.obj (hf.pullback g) ⟶ X := (hf g).choose_spec.choose_spec.choose /-- When `F` is full, given a representable morphism `f' : F.obj b ⟶ Y`, then `hf'.fst' g` denotes the preimage of `hf'.fst g` under `F`. -/ noncomputable abbrev fst' [Full F] : hf'.pullback g ⟶ b := F.preimage (hf'.fst g) lemma map_fst' [Full F] : F.map (hf'.fst' g) = hf'.fst g := F.map_preimage _ lemma isPullback : IsPullback (hf.fst g) (F.map (hf.snd g)) f g := (hf g).choose_spec.choose_spec.choose_spec @[reassoc] lemma w : hf.fst g ≫ f = F.map (hf.snd g) ≫ g := (hf.isPullback g).w /-- Variant of the pullback square when `F` is full, and given `f' : F.obj b ⟶ Y`. -/ lemma isPullback' [Full F] : IsPullback (F.map (hf'.fst' g)) (F.map (hf'.snd g)) f' g := (hf'.map_fst' _) ▸ hf'.isPullback g @[reassoc] lemma w' {X Y Z : C} {f : X ⟶ Z} (hf : F.relativelyRepresentable (F.map f)) (g : Y ⟶ Z) [Full F] [Faithful F] : hf.fst' (F.map g) ≫ f = hf.snd (F.map g) ≫ g := F.map_injective <| by simp [(hf.w (F.map g))] lemma isPullback_of_map {X Y Z : C} {f : X ⟶ Z} (hf : F.relativelyRepresentable (F.map f)) (g : Y ⟶ Z) [Full F] [Faithful F] : IsPullback (hf.fst' (F.map g)) (hf.snd (F.map g)) f g := IsPullback.of_map F (hf.w' g) (hf.isPullback' (F.map g)) variable {g} /-- Two morphisms `a b : c ⟶ hf.pullback g` are equal if * Their compositions (in `C`) with `hf.snd g : hf.pullback ⟶ X` are equal. * The compositions of `F.map a` and `F.map b` with `hf.fst g` are equal. -/ @[ext 100] lemma hom_ext [Faithful F] {c : C} {a b : c ⟶ hf.pullback g} (h₁ : F.map a ≫ hf.fst g = F.map b ≫ hf.fst g) (h₂ : a ≫ hf.snd g = b ≫ hf.snd g) : a = b := F.map_injective <| PullbackCone.IsLimit.hom_ext (hf.isPullback g).isLimit h₁ (by simpa using F.congr_map h₂) /-- In the case of a representable morphism `f' : F.obj Y ⟶ G`, whose codomain lies in the image of `F`, we get that two morphism `a b : Z ⟶ hf.pullback g` are equal if * Their compositions (in `C`) with `hf'.snd g : hf.pullback ⟶ X` are equal. * Their compositions (in `C`) with `hf'.fst' g : hf.pullback ⟶ Y` are equal. -/ @[ext] lemma hom_ext' [Full F] [Faithful F] {c : C} {a b : c ⟶ hf'.pullback g} (h₁ : a ≫ hf'.fst' g = b ≫ hf'.fst' g) (h₂ : a ≫ hf'.snd g = b ≫ hf'.snd g) : a = b := hf'.hom_ext (by simpa [map_fst'] using F.congr_map h₁) h₂ section variable {c : C} (i : F.obj c ⟶ X) (h : c ⟶ a) (hi : i ≫ f = F.map h ≫ g) /-- The lift (in `C`) obtained from the universal property of `F.obj (hf.pullback g)`, in the case when the cone point is in the image of `F.obj`. -/ noncomputable def lift [Full F] : c ⟶ hf.pullback g := F.preimage <| PullbackCone.IsLimit.lift (hf.isPullback g).isLimit _ _ hi @[reassoc (attr := simp)] lemma lift_fst [Full F] : F.map (hf.lift i h hi) ≫ hf.fst g = i := by simpa [lift] using PullbackCone.IsLimit.lift_fst _ _ _ _ @[reassoc (attr := simp)] lemma lift_snd [Full F] [Faithful F] : hf.lift i h hi ≫ hf.snd g = h := F.map_injective <| by simpa [lift] using PullbackCone.IsLimit.lift_snd _ _ _ _ end section variable {c : C} (i : c ⟶ b) (h : c ⟶ a) (hi : F.map i ≫ f' = F.map h ≫ g) /-- Variant of `lift` in the case when the domain of `f` lies in the image of `F.obj`. Thus, in this case, one can obtain the lift directly by giving two morphisms in `C`. -/ noncomputable def lift' [Full F] : c ⟶ hf'.pullback g := hf'.lift _ _ hi @[reassoc (attr := simp)] lemma lift'_fst [Full F] [Faithful F] : hf'.lift' i h hi ≫ hf'.fst' g = i := F.map_injective (by simp [lift']) @[reassoc (attr := simp)] lemma lift'_snd [Full F] [Faithful F] : hf'.lift' i h hi ≫ hf'.snd g = h := by simp [lift'] end /-- Given two representable morphisms `f' : F.obj b ⟶ Y` and `g : F.obj a ⟶ Y`, we obtain an isomorphism `hf'.pullback g ⟶ hg.pullback f'`. -/ noncomputable def symmetry [Full F] : hf'.pullback g ⟶ hg.pullback f' := hg.lift' (hf'.snd g) (hf'.fst' g) (hf'.isPullback' _).w.symm @[reassoc (attr := simp)] lemma symmetry_fst [Full F] [Faithful F] : hf'.symmetry hg ≫ hg.fst' f' = hf'.snd g := by simp [symmetry] @[reassoc (attr := simp)] lemma symmetry_snd [Full F] [Faithful F] : hf'.symmetry hg ≫ hg.snd f' = hf'.fst' g := by simp [symmetry] @[reassoc (attr := simp)] lemma symmetry_symmetry [Full F] [Faithful F] : hf'.symmetry hg ≫ hg.symmetry hf' = 𝟙 _ := hom_ext' hf' (by simp) (by simp) /-- The isomorphism given by `Presheaf.representable.symmetry`. -/ @[simps] noncomputable def symmetryIso [Full F] [Faithful F] : hf'.pullback g ≅ hg.pullback f' where hom := hf'.symmetry hg inv := hg.symmetry hf' instance [Full F] [Faithful F] : IsIso (hf'.symmetry hg) := (hf'.symmetryIso hg).isIso_hom end /-- When `C` has pullbacks, then `F.map f` is representable with respect to `F` for any `f : a ⟶ b` in `C`. -/ lemma map [Full F] [HasPullbacks C] {a b : C} (f : a ⟶ b) [∀ c (g : c ⟶ b), PreservesLimit (cospan f g) F] : F.relativelyRepresentable (F.map f) := fun c g ↦ by obtain ⟨g, rfl⟩ := F.map_surjective g refine ⟨Limits.pullback f g, Limits.pullback.snd f g, F.map (Limits.pullback.fst f g), ?_⟩ apply F.map_isPullback <| IsPullback.of_hasPullback f g lemma of_isIso {X Y : D} (f : X ⟶ Y) [IsIso f] : F.relativelyRepresentable f := fun a g ↦ ⟨a, 𝟙 a, g ≫ CategoryTheory.inv f, IsPullback.of_vert_isIso ⟨by simp⟩⟩ lemma isomorphisms_le : MorphismProperty.isomorphisms D ≤ F.relativelyRepresentable := fun _ _ f hf ↦ letI : IsIso f := hf; of_isIso F f instance isMultiplicative : IsMultiplicative F.relativelyRepresentable where id_mem _ := of_isIso F _ comp_mem {F G H} f g hf hg := fun X h ↦ ⟨hf.pullback (hg.fst h), hf.snd (hg.fst h) ≫ hg.snd h, hf.fst (hg.fst h), by simpa using IsPullback.paste_vert (hf.isPullback (hg.fst h)) (hg.isPullback h)⟩ instance isStableUnderBaseChange : IsStableUnderBaseChange F.relativelyRepresentable where of_isPullback {X Y Y' X' f g f' g'} P₁ hg a h := by refine ⟨hg.pullback (h ≫ f), hg.snd (h ≫ f), ?_, ?_⟩ · apply P₁.lift (hg.fst (h ≫ f)) (F.map (hg.snd (h ≫ f)) ≫ h) (by simpa using hg.w (h ≫ f)) · apply IsPullback.of_right' (hg.isPullback (h ≫ f)) P₁ instance respectsIso : RespectsIso F.relativelyRepresentable := (isStableUnderBaseChange F).respectsIso end Functor.relativelyRepresentable namespace MorphismProperty open Functor.relativelyRepresentable variable {X Y : D} (P : MorphismProperty C) /-- Given a morphism property `P` in a category `C`, a functor `F : C ⥤ D` and a morphism `f : X ⟶ Y` in `D`. Then `f` satisfies the morphism property `P.relative` with respect to `F` iff: * The morphism is representable with respect to `F` * For any morphism `g : F.obj a ⟶ Y`, the property `P` holds for any represented pullback of `f` by `g`. -/ def relative : MorphismProperty D := fun X Y f ↦ F.relativelyRepresentable f ∧ ∀ ⦃a b : C⦄ (g : F.obj a ⟶ Y) (fst : F.obj b ⟶ X) (snd : b ⟶ a) (_ : IsPullback fst (F.map snd) f g), P snd /-- Given a morphism property `P` in a category `C`, a morphism `f : F ⟶ G` of presheaves in the category `Cᵒᵖ ⥤ Type v` satisfies the morphism property `P.presheaf` iff: * The morphism is representable. * For any morphism `g : F.obj a ⟶ G`, the property `P` holds for any represented pullback of `f` by `g`. This is implemented as a special case of the more general notion of `P.relative`, to the case when the functor `F` is `yoneda`. -/ abbrev presheaf : MorphismProperty (Cᵒᵖ ⥤ Type v₁) := P.relative yoneda variable {P} {F} /-- A morphism satisfying `P.relative` is representable. -/ lemma relative.rep {f : X ⟶ Y} (hf : P.relative F f) : F.relativelyRepresentable f := hf.1 lemma relative.property {f : X ⟶ Y} (hf : P.relative F f) : ∀ ⦃a b : C⦄ (g : F.obj a ⟶ Y) (fst : F.obj b ⟶ X) (snd : b ⟶ a) (_ : IsPullback fst (F.map snd) f g), P snd := hf.2 lemma relative.property_snd {f : X ⟶ Y} (hf : P.relative F f) {a : C} (g : F.obj a ⟶ Y) : P (hf.rep.snd g) := hf.property g _ _ (hf.rep.isPullback g) /-- Given a morphism property `P` which respects isomorphisms, then to show that a morphism `f : X ⟶ Y` satisfies `P.relative` it suffices to show that: * The morphism is representable. * For any morphism `g : F.obj a ⟶ G`, the property `P` holds for *some* represented pullback of `f` by `g`. -/ lemma relative.of_exists [F.Faithful] [F.Full] [P.RespectsIso] {f : X ⟶ Y} (h₀ : ∀ ⦃a : C⦄ (g : F.obj a ⟶ Y), ∃ (b : C) (fst : F.obj b ⟶ X) (snd : b ⟶ a) (_ : IsPullback fst (F.map snd) f g), P snd) : P.relative F f := by refine ⟨fun a g ↦ ?_, fun a b g fst snd h ↦ ?_⟩ all_goals obtain ⟨c, g_fst, g_snd, BC, H⟩ := h₀ g · refine ⟨c, g_snd, g_fst, BC⟩ · refine (P.arrow_mk_iso_iff ?_).2 H exact Arrow.isoMk (F.preimageIso (h.isoIsPullback X (F.obj a) BC)) (Iso.refl _) (F.map_injective (by simp)) lemma relative_of_snd [F.Faithful] [F.Full] [P.RespectsIso] {f : X ⟶ Y} (hf : F.relativelyRepresentable f) (h : ∀ ⦃a : C⦄ (g : F.obj a ⟶ Y), P (hf.snd g)) : P.relative F f := relative.of_exists (fun _ g ↦ ⟨hf.pullback g, hf.fst g, hf.snd g, hf.isPullback g, h g⟩) /-- If `P : MorphismProperty C` is stable under base change, `F` is fully faithful and preserves pullbacks, and `C` has all pullbacks, then for any `f : a ⟶ b` in `C`, `F.map f` satisfies `P.relative` if `f` satisfies `P`. -/ lemma relative_map [F.Faithful] [F.Full] [HasPullbacks C] [IsStableUnderBaseChange P] {a b : C} {f : a ⟶ b} [∀ c (g : c ⟶ b), PreservesLimit (cospan f g) F] (hf : P f) : P.relative F (F.map f) := by apply relative.of_exists intro Y' g obtain ⟨g, rfl⟩ := F.map_surjective g exact ⟨_, _, _, (IsPullback.of_hasPullback f g).map F, P.pullback_snd _ _ hf⟩ lemma of_relative_map {a b : C} {f : a ⟶ b} (hf : P.relative F (F.map f)) : P f := hf.property (𝟙 _) (𝟙 _) f (IsPullback.id_horiz (F.map f)) lemma relative_map_iff [F.Faithful] [F.Full] [PreservesLimitsOfShape WalkingCospan F] [HasPullbacks C] [IsStableUnderBaseChange P] {X Y : C} {f : X ⟶ Y} : P.relative F (F.map f) ↔ P f := ⟨fun hf ↦ of_relative_map hf, fun hf ↦ relative_map hf⟩ /-- If `P' : MorphismProperty C` is satisfied whenever `P` is, then also `P'.relative` is satisfied whenever `P.relative` is. -/ lemma relative_monotone {P' : MorphismProperty C} (h : P ≤ P') : P.relative F ≤ P'.relative F := fun _ _ _ hf ↦ ⟨hf.rep, fun _ _ g fst snd BC ↦ h _ (hf.property g fst snd BC)⟩ section variable (P) lemma relative_isStableUnderBaseChange : IsStableUnderBaseChange (P.relative F) where of_isPullback hfBC hg := ⟨of_isPullback hfBC hg.rep, fun _ _ _ _ _ BC ↦ hg.property _ _ _ (IsPullback.paste_horiz BC hfBC)⟩ instance relative_isStableUnderComposition [F.Faithful] [F.Full] [P.IsStableUnderComposition] : IsStableUnderComposition (P.relative F) where comp_mem {F G H} f g hf hg := by refine ⟨comp_mem _ _ _ hf.1 hg.1, fun Z X p fst snd h ↦ ?_⟩ rw [← hg.1.lift_snd (fst ≫ f) snd (by simpa using h.w)] refine comp_mem _ _ _ (hf.property (hg.1.fst p) fst _ (IsPullback.of_bot ?_ ?_ (hg.1.isPullback p))) (hg.property_snd p) · rw [← Functor.map_comp, lift_snd] exact h · symm apply hg.1.lift_fst instance relative_respectsIso : RespectsIso (P.relative F) := (relative_isStableUnderBaseChange P).respectsIso instance relative_isMultiplicative [F.Faithful] [F.Full] [P.IsMultiplicative] [P.RespectsIso] : IsMultiplicative (P.relative F) where id_mem X := relative.of_exists (fun Y g ↦ ⟨Y, g, 𝟙 Y, by simpa using IsPullback.of_id_snd, id_mem _ _⟩) end section -- TODO(Calle): This could be generalized to functors whose image forms a separating family. /-- Morphisms satisfying `(monomorphism C).presheaf` are in particular monomorphisms. -/ lemma presheaf_monomorphisms_le_monomorphisms : (monomorphisms C).presheaf ≤ monomorphisms _ := fun F G f hf ↦ by suffices ∀ {X : C} {a b : yoneda.obj X ⟶ F}, a ≫ f = b ≫ f → a = b from ⟨fun _ _ h ↦ hom_ext_yoneda (fun _ _ ↦ this (by simp only [assoc, h]))⟩ intro X a b h /- It suffices to show that the lifts of `a` and `b` to morphisms `X ⟶ hf.rep.pullback g` are equal, where `g = a ≫ f = a ≫ f`. -/ suffices hf.rep.lift (g := a ≫ f) a (𝟙 X) (by simp) = hf.rep.lift b (𝟙 X) (by simp [← h]) by simpa using yoneda.congr_map this =≫ (hf.rep.fst (a ≫ f)) -- This follows from the fact that the induced maps `hf.rep.pullback g ⟶ X` are mono. have : Mono (hf.rep.snd (a ≫ f)) := hf.property_snd (a ≫ f) simp only [← cancel_mono (hf.rep.snd (a ≫ f)), lift_snd] variable {G : Cᵒᵖ ⥤ Type v₁} lemma presheaf_mono_of_le (hP : P ≤ MorphismProperty.monomorphisms C) {X : C} {f : yoneda.obj X ⟶ G} (hf : P.presheaf f) : Mono f := MorphismProperty.presheaf_monomorphisms_le_monomorphisms _ (MorphismProperty.relative_monotone hP _ hf) lemma fst'_self_eq_snd (hP : P ≤ MorphismProperty.monomorphisms C) {X : C} {f : yoneda.obj X ⟶ G} (hf : P.presheaf f) : hf.rep.fst' f = hf.rep.snd f := by have := P.presheaf_mono_of_le hP hf apply yoneda.map_injective rw [← cancel_mono f, (hf.rep.isPullback' f).w] lemma isIso_fst'_self (hP : P ≤ MorphismProperty.monomorphisms C) {X : C} {f : yoneda.obj X ⟶ G} (hf : P.presheaf f) : IsIso (hf.rep.fst' f) := have := P.presheaf_mono_of_le hP hf have := (hf.rep.isPullback' f).isIso_fst_of_mono Yoneda.fullyFaithful.isIso_of_isIso_map _ end end MorphismProperty namespace Functor.relativelyRepresentable section Pullbacks₃ /- In this section we develop some basic API that help deal with certain triple pullbacks obtained from morphism `f₁ : F.obj A₁ ⟶ X` which is relatively representable with respect to some functor `F : C ⥤ D`. More precisely, given two objects `A₂` and `A₃` in `C`, and two morphisms `f₂ : A₂ ⟶ X` and `f₃ : A₃ ⟶ X`, we can consider the pullbacks (in `D`) `(A₁ ×_X A₂)` and `(A₁ ×_X A₃)` (which makes sense as objects in `C` due to `F` being relatively representable). We can then consider the pullback, in `C`, of these two pullbacks. This is the object `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. In this section we develop some basic API for dealing with this pullback. This is used in `Mathlib/AlgebraicGeometry/Sites/Representability.lean` to show that representability is Zariski-local. -/ variable {F : C ⥤ D} [Full F] {A₁ A₂ A₃ : C} {X : D} {f₁ : F.obj A₁ ⟶ X} (hf₁ : F.relativelyRepresentable f₁) (f₂ : F.obj A₂ ⟶ X) (f₃ : F.obj A₃ ⟶ X) [HasPullback (hf₁.fst' f₂) (hf₁.fst' f₃)] /-- The pullback `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. -/ noncomputable def pullback₃ := Limits.pullback (hf₁.fst' f₂) (hf₁.fst' f₃) /-- The morphism `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ A₁`. -/ noncomputable def pullback₃.p₁ : hf₁.pullback₃ f₂ f₃ ⟶ A₁ := pullback.fst _ _ ≫ hf₁.fst' f₂ /-- The morphism `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ A₂`. -/ noncomputable def pullback₃.p₂ : hf₁.pullback₃ f₂ f₃ ⟶ A₂ := pullback.fst _ _ ≫ hf₁.snd f₂ /-- The morphism `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ A₃`. -/ noncomputable def pullback₃.p₃ : hf₁.pullback₃ f₂ f₃ ⟶ A₃ := pullback.snd _ _ ≫ hf₁.snd f₃ /-- The morphism `F.obj (A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ X`. -/ noncomputable def pullback₃.π : F.obj (pullback₃ hf₁ f₂ f₃) ⟶ X := F.map (p₁ hf₁ f₂ f₃) ≫ f₁ @[reassoc (attr := simp)] lemma pullback₃.map_p₁_comp : F.map (p₁ hf₁ f₂ f₃) ≫ f₁ = π _ _ _ := rfl @[reassoc (attr := simp)] lemma pullback₃.map_p₂_comp : F.map (p₂ hf₁ f₂ f₃) ≫ f₂ = π _ _ _ := by simp [π, p₁, p₂, ← hf₁.w f₂] @[reassoc (attr := simp)] lemma pullback₃.map_p₃_comp : F.map (p₃ hf₁ f₂ f₃) ≫ f₃ = π _ _ _ := by simp [π, p₁, p₃, ← hf₁.w f₃, pullback.condition] section variable [Faithful F] {Z : C} (x₁ : Z ⟶ A₁) (x₂ : Z ⟶ A₂) (x₃ : Z ⟶ A₃) (h₁₂ : F.map x₁ ≫ f₁ = F.map x₂ ≫ f₂) (h₁₃ : F.map x₁ ≫ f₁ = F.map x₃ ≫ f₃) /-- The lift obtained from the universal property of `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. -/ noncomputable def lift₃ : Z ⟶ pullback₃ hf₁ f₂ f₃ := pullback.lift (hf₁.lift' x₁ x₂ h₁₂) (hf₁.lift' x₁ x₃ h₁₃) (by simp) @[reassoc (attr := simp)] lemma lift₃_p₁ : hf₁.lift₃ f₂ f₃ x₁ x₂ x₃ h₁₂ h₁₃ ≫ pullback₃.p₁ hf₁ f₂ f₃ = x₁ := by simp [lift₃, pullback₃.p₁] @[reassoc (attr := simp)] lemma lift₃_p₂ : hf₁.lift₃ f₂ f₃ x₁ x₂ x₃ h₁₂ h₁₃ ≫ pullback₃.p₂ hf₁ f₂ f₃ = x₂ := by simp [lift₃, pullback₃.p₂] @[reassoc (attr := simp)] lemma lift₃_p₃ : hf₁.lift₃ f₂ f₃ x₁ x₂ x₃ h₁₂ h₁₃ ≫ pullback₃.p₃ hf₁ f₂ f₃ = x₃ := by simp [lift₃, pullback₃.p₃] end @[reassoc (attr := simp)] lemma pullback₃.fst_fst'_eq_p₁ : pullback.fst _ _ ≫ hf₁.fst' f₂ = pullback₃.p₁ hf₁ f₂ f₃ := rfl @[reassoc (attr := simp)] lemma pullback₃.fst_snd_eq_p₂ : pullback.fst _ _ ≫ hf₁.snd f₂ = pullback₃.p₂ hf₁ f₂ f₃ := rfl @[reassoc (attr := simp)] lemma pullback₃.snd_snd_eq_p₃ : pullback.snd _ _ ≫ hf₁.snd f₃ = pullback₃.p₃ hf₁ f₂ f₃ := rfl @[reassoc (attr := simp)] lemma pullback₃.snd_fst'_eq_p₁ : pullback.snd (hf₁.fst' f₂) (hf₁.fst' f₃) ≫ hf₁.fst' f₃ = pullback₃.p₁ hf₁ f₂ f₃ := pullback.condition.symm variable {hf₁ f₂ f₃} in @[ext] lemma pullback₃.hom_ext [Faithful F] {Z : C} {φ φ' : Z ⟶ pullback₃ hf₁ f₂ f₃} (h₁ : φ ≫ pullback₃.p₁ hf₁ f₂ f₃ = φ' ≫ pullback₃.p₁ hf₁ f₂ f₃) (h₂ : φ ≫ pullback₃.p₂ hf₁ f₂ f₃ = φ' ≫ pullback₃.p₂ hf₁ f₂ f₃) (h₃ : φ ≫ pullback₃.p₃ hf₁ f₂ f₃ = φ' ≫ pullback₃.p₃ hf₁ f₂ f₃) : φ = φ' := by apply pullback.hom_ext <;> ext <;> simpa end Pullbacks₃ section Diagonal /- In this section, we prove a criterion for the diagonal morphisms to be relatively representable. -/ variable {F : C ⥤ D} variable [HasBinaryProducts C] variable [HasPullbacks D] [HasBinaryProducts D] [HasTerminal D] variable [Full F] variable [PreservesLimitsOfShape (Discrete WalkingPair) F] /-- Assume that 1. `C` has binary products, 2. `D` has pullbacks, binary products and a terminal object, and 3. `F : C ⥤ D` is full and preserves binary products. For an object `X` in a category `D`, if the diagonal morphism `X ⟶ X × X` is relatively representable, then every morphism of the form `F.obj a ⟶ X` is relatively representable with respect to `F`. -/ lemma of_diag {X : D} (h : F.relativelyRepresentable (Limits.diag X)) ⦃a : C⦄ (g : F.obj a ⟶ X) : F.relativelyRepresentable g := by rw [(by cat_disch : Limits.diag X = pullback.lift (𝟙 X) (𝟙 X) ≫ (prodIsoPullback X X).inv)] at h intro a' g' obtain ⟨_, ⟨left⟩⟩ := pullback_map_diagonal_isPullback g g' (terminal.from X) let prodMap : F.obj (a ⨯ a') ⟶ X ⨯ X := (preservesLimitIso _ (pair _ _) ≪≫ HasLimit.isoOfNatIso (pairComp _ _ _)).hom ≫ prod.map g g' let pbRepr := (h prodMap).choose_spec.choose_spec.choose_spec.isLimit'.some.conePointUniqueUpToIso <| pasteHorizIsPullback rfl (IsPullback.of_vert_isIso_mono (snd := pullback.congrHom (terminal.comp_from g) (terminal.comp_from g') ≪≫ (prodIsoPullback _ _).symm ≪≫ (HasLimit.isoOfNatIso (pairComp _ _ _)).symm ≪≫ (preservesLimitIso _ (pair _ _)).symm|>.hom) ⟨by cat_disch⟩).isLimit'.some left exact ⟨_, ⟨_, ⟨_, IsPullback.of_iso_pullback (fst := pbRepr.hom ≫ pullback.fst g g') (snd := F.map (Functor.preimage F (pbRepr.hom ≫ pullback.snd g g'))) ⟨by simp [pullback.condition]⟩ pbRepr (by cat_disch) (by cat_disch)⟩⟩⟩ /-- Assume that 1. `C` has binary products and pullbacks, 2. `D` has pullbacks, binary products and a terminal object, and 3. `F : C ⥤ D` is full and preserves binary products and pullbacks. For a morphism `g : F.obj a ⟶ pullback (terminal.from X) (terminal.from X)`, the canonical morphism from `F.obj a` to `pullback ((g ≫ pullback.fst _ _) ≫ terminal.from X) ((g ≫ pullback.snd _ _) ≫ terminal.from X)` is relatively representable with respect to `F`. -/ lemma toPullbackTerminal {X : D} {a : C} [HasPullbacks C] [PreservesLimitsOfShape WalkingCospan F] (g : F.obj a ⟶ Limits.pullback (terminal.from X) (terminal.from X)) : F.relativelyRepresentable (pullback.lift (f := (g ≫ pullback.fst _ _) ≫ terminal.from X) (g := (g ≫ pullback.snd _ _) ≫ terminal.from X) (𝟙 _) (𝟙 _) (by cat_disch)) := by let pbIso := pullback.congrHom (terminal.comp_from _ : (g ≫ pullback.fst _ _) ≫ terminal.from X = terminal.from _) (terminal.comp_from _ : (g ≫ pullback.snd _ _) ≫ terminal.from X = terminal.from _) ≪≫ (prodIsoPullback _ _).symm ≪≫ (HasLimit.isoOfNatIso (pairComp _ _ _)).symm ≪≫ (preservesLimitIso _ (pair _ _)).symm rw [← comp_id (pullback.lift _ _), ← pbIso.hom_inv_id, ← Category.assoc] apply (respectsIso F).toRespectsRight.postcomp _ (inferInstance : IsIso _) _ exact map_preimage F (_ ≫ pbIso.hom) ▸ map F (F.preimage _) /-- Assume that 1. `C` has binary products and pullbacks, 2. `D` has pullbacks, binary products and a terminal object, and 3. `F : C ⥤ D` is full and preserves binary products and pullbacks. For an object `X` in a category `D`, if every morphism of the form `F.obj a ⟶ X` is relatively representable with respect to `F`, so is the diagonal morphism `X ⟶ X × X`. -/ lemma diag_of_map_from_obj [HasPullbacks C] [PreservesLimitsOfShape WalkingCospan F] {X : D} (h : ∀ ⦃a : C⦄ (g : F.obj a ⟶ X), F.relativelyRepresentable g) : F.relativelyRepresentable (Limits.diag X) := by rw [(by cat_disch : Limits.diag X = pullback.lift (𝟙 X) (𝟙 X) ≫ (prodIsoPullback X X).inv)] suffices F.relativelyRepresentable (pullback.lift (𝟙 _) (𝟙 _)) from (respectsIso F).toRespectsRight.postcomp _ (inferInstance : IsIso _) _ this intro a g obtain ⟨_, ⟨_, ⟨_, pbRepr⟩⟩⟩ := h (g ≫ pullback.fst _ _) (g ≫ pullback.snd _ _) obtain ⟨_, ⟨bot⟩⟩ := IsPullback.of_iso_pullback ⟨by rw [assoc]; simp [pullback.condition]⟩ (pbRepr.isoPullback ≪≫ (pullbackDiagonalMapIdIso (g ≫ pullback.fst _ _) (g ≫ pullback.snd _ _) (terminal.from X)).symm) rfl rfl obtain ⟨_, ⟨_, ⟨topMap, top⟩⟩⟩ := (toPullbackTerminal g) <| (pbRepr.isoPullback ≪≫ (pullbackDiagonalMapIdIso (g ≫ pullback.fst _ _) (g ≫ pullback.snd _ _) (terminal.from X)).symm).hom ≫ pullback.snd (pullback.diagonal (terminal.from X)) (pullback.map _ _ _ _ _ _ (𝟙 _) (by cat_disch) (by cat_disch)) have hg : g = pullback.lift (𝟙 _) (𝟙 _) (by cat_disch) ≫ pullback.map ((g ≫ pullback.fst _ _) ≫ terminal.from X) ((g ≫ pullback.snd _ _) ≫ terminal.from X) _ _ (g ≫ pullback.fst _ _) (g ≫ pullback.snd _ _) (𝟙 _) (by cat_disch) (by cat_disch) := by apply Limits.pullback.hom_ext <;> simp exact hg ▸ ⟨_, ⟨_, ⟨_, IsPullback.of_isLimit <| pasteVertIsPullback rfl bot (map_preimage F topMap ▸ top).flip.isLimit'.some⟩⟩⟩ /-- Assume that 1. `C` has binary products and pullbacks, 2. `D` has pullbacks, binary products and a terminal object, and 3. `F : C ⥤ D` is full and preserves binary products and pullbacks. For an object `X` in a category `D`, the diagonal morphism `X ⟶ X × X` is relatively representable with respect to `F` if and only if so is every morphism of the form `F.obj a ⟶ X`. -/ lemma diag_iff {X : D} [HasPullbacks C] [PreservesLimitsOfShape WalkingCospan F] : F.relativelyRepresentable (Limits.diag X) ↔ ∀ ⦃a : C⦄ (g : F.obj a ⟶ X), F.relativelyRepresentable g := ⟨fun h _ g => of_diag h g, fun h => diag_of_map_from_obj h⟩ end Diagonal end Functor.relativelyRepresentable end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Limits.lean
import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Limits.Connected import Mathlib.CategoryTheory.Filtered.Connected import Mathlib.CategoryTheory.Limits.Shapes.Diagonal import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Relation of morphism properties with limits The following predicates are introduces for morphism properties `P`: * `IsStableUnderBaseChange`: `P` is stable under base change if in all pullback squares, the left map satisfies `P` if the right map satisfies it. * `IsStableUnderCobaseChange`: `P` is stable under cobase change if in all pushout squares, the right map satisfies `P` if the left map satisfies it. We define `P.universally` for the class of morphisms which satisfy `P` after any base change. We also introduce properties `IsStableUnderProductsOfShape`, `IsStableUnderLimitsOfShape`, `IsStableUnderFiniteProducts`, and similar properties for colimits and coproducts. -/ universe w w' v u namespace CategoryTheory open Category Limits namespace MorphismProperty variable {C : Type u} [Category.{v} C] section variable (P : MorphismProperty C) /-- Given a class of morphisms `P`, this is the class of pullbacks of morphisms in `P`. -/ def pullbacks : MorphismProperty C := fun A B q ↦ ∃ (X Y : C) (p : X ⟶ Y) (f : A ⟶ X) (g : B ⟶ Y) (_ : P p), IsPullback f q p g lemma pullbacks_mk {A B X Y : C} {f : A ⟶ X} {q : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y} (sq : IsPullback f q p g) (hp : P p) : P.pullbacks q := ⟨_, _, _, _, _, hp, sq⟩ lemma le_pullbacks : P ≤ P.pullbacks := by intro A B q hq exact P.pullbacks_mk IsPullback.of_id_fst hq lemma pullbacks_monotone : Monotone (pullbacks (C := C)) := by rintro _ _ h _ _ _ ⟨_, _, _, _, _, hp, sq⟩ exact ⟨_, _, _, _, _, h _ hp, sq⟩ /-- Given a class of morphisms `P`, this is the class of pushouts of morphisms in `P`. -/ def pushouts : MorphismProperty C := fun X Y q ↦ ∃ (A B : C) (p : A ⟶ B) (f : A ⟶ X) (g : B ⟶ Y) (_ : P p), IsPushout f p q g lemma pushouts_mk {A B X Y : C} {f : A ⟶ X} {q : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y} (sq : IsPushout f q p g) (hq : P q) : P.pushouts p := ⟨_, _, _, _, _, hq, sq⟩ lemma le_pushouts : P ≤ P.pushouts := by intro X Y p hp exact P.pushouts_mk IsPushout.of_id_fst hp lemma pushouts_monotone : Monotone (pushouts (C := C)) := by rintro _ _ h _ _ _ ⟨_, _, _, _, _, hp, sq⟩ exact ⟨_, _, _, _, _, h _ hp, sq⟩ instance : P.pushouts.RespectsIso := RespectsIso.of_respects_arrow_iso _ (by rintro q q' e ⟨A, B, p, f, g, hp, h⟩ exact ⟨A, B, p, f ≫ e.hom.left, g ≫ e.hom.right, hp, IsPushout.paste_horiz h (IsPushout.of_horiz_isIso ⟨e.hom.w⟩)⟩) instance : P.pullbacks.RespectsIso := RespectsIso.of_respects_arrow_iso _ (by rintro q q' e ⟨X, Y, p, f, g, hp, h⟩ exact ⟨X, Y, p, e.inv.left ≫ f, e.inv.right ≫ g, hp, IsPullback.paste_horiz (IsPullback.of_horiz_isIso ⟨e.inv.w⟩) h⟩) /-- If `P : MorphismProperty C` is such that any object in `C` maps to the target of some morphism in `P`, then `P.pushouts` contains the isomorphisms. -/ lemma isomorphisms_le_pushouts (h : ∀ (X : C), ∃ (A B : C) (p : A ⟶ B) (_ : P p) (_ : B ⟶ X), IsIso p) : isomorphisms C ≤ P.pushouts := by intro X Y f (_ : IsIso f) obtain ⟨A, B, p, hp, g, _⟩ := h X exact ⟨A, B, p, p ≫ g, g ≫ f, hp, (IsPushout.of_id_snd (f := p ≫ g)).of_iso (Iso.refl _) (Iso.refl _) (asIso p) (asIso f) (by simp) (by simp) (by simp) (by simp)⟩ /-- A morphism property is `IsStableUnderBaseChange` if the base change of such a morphism still falls in the class. -/ class IsStableUnderBaseChange : Prop where of_isPullback {X Y Y' S : C} {f : X ⟶ S} {g : Y ⟶ S} {f' : Y' ⟶ Y} {g' : Y' ⟶ X} (sq : IsPullback f' g' g f) (hg : P g) : P g' instance : P.pullbacks.IsStableUnderBaseChange where of_isPullback := by rintro _ _ _ _ _ _ _ _ h ⟨_, _, _, _, _, hp, hq⟩ exact P.pullbacks_mk (h.paste_horiz hq) hp /-- A morphism property is `IsStableUnderCobaseChange` if the cobase change of such a morphism still falls in the class. -/ class IsStableUnderCobaseChange : Prop where of_isPushout {A A' B B' : C} {f : A ⟶ A'} {g : A ⟶ B} {f' : B ⟶ B'} {g' : A' ⟶ B'} (sq : IsPushout g f f' g') (hf : P f) : P f' instance : P.pushouts.IsStableUnderCobaseChange where of_isPushout := by rintro _ _ _ _ _ _ _ _ h ⟨_, _, _, _, _, hp, hq⟩ exact P.pushouts_mk (hq.paste_horiz h) hp variable {P} in lemma of_isPullback [P.IsStableUnderBaseChange] {X Y Y' S : C} {f : X ⟶ S} {g : Y ⟶ S} {f' : Y' ⟶ Y} {g' : Y' ⟶ X} (sq : IsPullback f' g' g f) (hg : P g) : P g' := IsStableUnderBaseChange.of_isPullback sq hg lemma isStableUnderBaseChange_iff_pullbacks_le : P.IsStableUnderBaseChange ↔ P.pullbacks ≤ P := by constructor · intro h _ _ _ ⟨_, _, _, _, _, h₁, h₂⟩ exact of_isPullback h₂ h₁ · intro h constructor intro _ _ _ _ _ _ _ _ h₁ h₂ exact h _ ⟨_, _, _, _, _, h₂, h₁⟩ lemma pullbacks_le [P.IsStableUnderBaseChange] : P.pullbacks ≤ P := by rwa [← isStableUnderBaseChange_iff_pullbacks_le] variable {P} in /-- Alternative constructor for `IsStableUnderBaseChange`. -/ theorem IsStableUnderBaseChange.mk' [RespectsIso P] (hP₂ : ∀ (X Y S : C) (f : X ⟶ S) (g : Y ⟶ S) [HasPullback f g] (_ : P g), P (pullback.fst f g)) : IsStableUnderBaseChange P where of_isPullback {X Y Y' S f g f' g'} sq hg := by haveI : HasPullback f g := sq.flip.hasPullback let e := sq.flip.isoPullback rw [← P.cancel_left_of_respectsIso e.inv, sq.flip.isoPullback_inv_fst] exact hP₂ _ _ _ f g hg variable (C) instance IsStableUnderBaseChange.isomorphisms : (isomorphisms C).IsStableUnderBaseChange where of_isPullback {_ _ _ _ f g _ _} h hg := have : IsIso g := hg have := hasPullback_of_left_iso g f h.isoPullback_hom_snd ▸ inferInstanceAs (IsIso _) instance IsStableUnderBaseChange.monomorphisms : (monomorphisms C).IsStableUnderBaseChange where of_isPullback {X Y Y' S f g f' g'} h hg := by have : Mono g := hg constructor intro Z f₁ f₂ h₁₂ apply PullbackCone.IsLimit.hom_ext h.isLimit · rw [← cancel_mono g] dsimp simp only [Category.assoc, h.w, reassoc_of% h₁₂] · exact h₁₂ variable {C P} instance (priority := 900) IsStableUnderBaseChange.respectsIso [IsStableUnderBaseChange P] : RespectsIso P := by apply RespectsIso.of_respects_arrow_iso intro f g e exact of_isPullback (IsPullback.of_horiz_isIso (CommSq.mk e.inv.w)) theorem pullback_fst [IsStableUnderBaseChange P] {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [HasPullback f g] (H : P g) : P (pullback.fst f g) := of_isPullback (IsPullback.of_hasPullback f g).flip H theorem pullback_snd [IsStableUnderBaseChange P] {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [HasPullback f g] (H : P f) : P (pullback.snd f g) := of_isPullback (IsPullback.of_hasPullback f g) H theorem baseChange_obj [IsStableUnderBaseChange P] {S S' : C} (f : S' ⟶ S) [∀ {W} (h : W ⟶ S), HasPullback h f] (X : Over S) (H : P X.hom) : P ((Over.pullback f).obj X).hom := pullback_snd X.hom f H theorem baseChange_map [IsStableUnderBaseChange P] {S S' : C} (f : S' ⟶ S) [∀ {W} (h : W ⟶ S), HasPullback h f] {X Y : Over S} (g : X ⟶ Y) (H : P g.left) : P ((Over.pullback f).map g).left := by let e := pullbackRightPullbackFstIso Y.hom f g.left ≪≫ pullback.congrHom (g.w.trans (Category.comp_id _)) rfl have : e.inv ≫ (pullback.snd _ _) = ((Over.pullback f).map g).left := by ext <;> dsimp [e] <;> simp rw [← this, P.cancel_left_of_respectsIso] exact pullback_snd _ _ H theorem pullback_map [HasPullbacks C] [IsStableUnderBaseChange P] [P.IsStableUnderComposition] {S X X' Y Y' : C} {f : X ⟶ S} {g : Y ⟶ S} {f' : X' ⟶ S} {g' : Y' ⟶ S} {i₁ : X ⟶ X'} {i₂ : Y ⟶ Y'} (h₁ : P i₁) (h₂ : P i₂) (e₁ : f = i₁ ≫ f') (e₂ : g = i₂ ≫ g') : P (pullback.map f g f' g' i₁ i₂ (𝟙 _) ((Category.comp_id _).trans e₁) ((Category.comp_id _).trans e₂)) := by have : pullback.map f g f' g' i₁ i₂ (𝟙 _) ((Category.comp_id _).trans e₁) ((Category.comp_id _).trans e₂) = ((pullbackSymmetry _ _).hom ≫ ((Over.pullback _).map (Over.homMk _ e₂.symm : Over.mk g ⟶ Over.mk g')).left) ≫ (pullbackSymmetry _ _).hom ≫ ((Over.pullback g').map (Over.homMk _ e₁.symm : Over.mk f ⟶ Over.mk f')).left := by ext <;> simp rw [this] apply P.comp_mem <;> rw [P.cancel_left_of_respectsIso] exacts [baseChange_map _ (Over.homMk _ e₂.symm : Over.mk g ⟶ Over.mk g') h₂, baseChange_map _ (Over.homMk _ e₁.symm : Over.mk f ⟶ Over.mk f') h₁] instance IsStableUnderBaseChange.hasOfPostcompProperty_monomorphisms [P.IsStableUnderBaseChange] : P.HasOfPostcompProperty (MorphismProperty.monomorphisms C) where of_postcomp {X Y Z} f g (hg : Mono g) hcomp := by have : f = (asIso (pullback.fst (f ≫ g) g)).inv ≫ pullback.snd (f ≫ g) g := by simp [← cancel_mono g, pullback.condition] rw [this, cancel_left_of_respectsIso (P := P)] exact P.pullback_snd _ _ hcomp lemma of_isPushout [P.IsStableUnderCobaseChange] {A A' B B' : C} {f : A ⟶ A'} {g : A ⟶ B} {f' : B ⟶ B'} {g' : A' ⟶ B'} (sq : IsPushout g f f' g') (hf : P f) : P f' := IsStableUnderCobaseChange.of_isPushout sq hf lemma isStableUnderCobaseChange_iff_pushouts_le : P.IsStableUnderCobaseChange ↔ P.pushouts ≤ P := by constructor · intro h _ _ _ ⟨_, _, _, _, _, h₁, h₂⟩ exact of_isPushout h₂ h₁ · intro h constructor intro _ _ _ _ _ _ _ _ h₁ h₂ exact h _ ⟨_, _, _, _, _, h₂, h₁⟩ lemma pushouts_le [P.IsStableUnderCobaseChange] : P.pushouts ≤ P := by rwa [← isStableUnderCobaseChange_iff_pushouts_le] @[simp] lemma pushouts_le_iff {P Q : MorphismProperty C} [Q.IsStableUnderCobaseChange] : P.pushouts ≤ Q ↔ P ≤ Q := by constructor · exact le_trans P.le_pushouts · intro h exact le_trans (pushouts_monotone h) pushouts_le /-- An alternative constructor for `IsStableUnderCobaseChange`. -/ theorem IsStableUnderCobaseChange.mk' [RespectsIso P] (hP₂ : ∀ (A B A' : C) (f : A ⟶ A') (g : A ⟶ B) [HasPushout f g] (_ : P f), P (pushout.inr f g)) : IsStableUnderCobaseChange P where of_isPushout {A A' B B' f g f' g'} sq hf := by haveI : HasPushout f g := sq.flip.hasPushout let e := sq.flip.isoPushout rw [← P.cancel_right_of_respectsIso _ e.hom, sq.flip.inr_isoPushout_hom] exact hP₂ _ _ _ f g hf instance IsStableUnderCobaseChange.isomorphisms : (isomorphisms C).IsStableUnderCobaseChange where of_isPushout {_ _ _ _ f g _ _} h (_ : IsIso f) := have := hasPushout_of_right_iso g f h.inl_isoPushout_inv ▸ inferInstanceAs (IsIso _) variable (C) in instance IsStableUnderCobaseChange.epimorphisms : (epimorphisms C).IsStableUnderCobaseChange where of_isPushout {X Y Y' S f g f' g'} h hf := by have : Epi f := hf constructor intro Z f₁ f₂ h₁₂ apply PushoutCocone.IsColimit.hom_ext h.isColimit · exact h₁₂ · rw [← cancel_epi f] dsimp simp only [← reassoc_of% h.w, h₁₂] instance IsStableUnderCobaseChange.respectsIso [IsStableUnderCobaseChange P] : RespectsIso P := RespectsIso.of_respects_arrow_iso _ fun _ _ e ↦ of_isPushout (IsPushout.of_horiz_isIso (CommSq.mk e.hom.w)) theorem pushout_inl [IsStableUnderCobaseChange P] {A B A' : C} (f : A ⟶ A') (g : A ⟶ B) [HasPushout f g] (H : P g) : P (pushout.inl f g) := of_isPushout (IsPushout.of_hasPushout f g) H theorem pushout_inr [IsStableUnderCobaseChange P] {A B A' : C} (f : A ⟶ A') (g : A ⟶ B) [HasPushout f g] (H : P f) : P (pushout.inr f g) := of_isPushout (IsPushout.of_hasPushout f g).flip H instance IsStableUnderCobaseChange.hasOfPrecompProperty_epimorphisms [P.IsStableUnderCobaseChange] : P.HasOfPrecompProperty (MorphismProperty.epimorphisms C) where of_precomp {X Y Z} f g (hf : Epi f) hcomp := by have : g = pushout.inr (f ≫ g) f ≫ (asIso (pushout.inl (f ≫ g) f)).inv := by rw [asIso_inv, IsIso.eq_comp_inv, ← cancel_epi f, ← pushout.condition, assoc] rw [this, cancel_right_of_respectsIso (P := P)] exact P.pushout_inr _ _ hcomp instance IsStableUnderCobaseChange.op [IsStableUnderCobaseChange P] : IsStableUnderBaseChange P.op where of_isPullback sq hg := P.of_isPushout sq.unop hg instance IsStableUnderCobaseChange.unop {P : MorphismProperty Cᵒᵖ} [IsStableUnderCobaseChange P] : IsStableUnderBaseChange P.unop where of_isPullback sq hg := P.of_isPushout sq.op hg instance IsStableUnderBaseChange.op [IsStableUnderBaseChange P] : IsStableUnderCobaseChange P.op where of_isPushout sq hf := P.of_isPullback sq.unop hf instance IsStableUnderBaseChange.unop {P : MorphismProperty Cᵒᵖ} [IsStableUnderBaseChange P] : IsStableUnderCobaseChange P.unop where of_isPushout sq hf := P.of_isPullback sq.op hf instance IsStableUnderBaseChange.inf {P Q : MorphismProperty C} [IsStableUnderBaseChange P] [IsStableUnderBaseChange Q] : IsStableUnderBaseChange (P ⊓ Q) where of_isPullback hp hg := ⟨of_isPullback hp hg.left, of_isPullback hp hg.right⟩ instance IsStableUnderCobaseChange.inf {P Q : MorphismProperty C} [IsStableUnderCobaseChange P] [IsStableUnderCobaseChange Q] : IsStableUnderCobaseChange (P ⊓ Q) where of_isPushout hp hg := ⟨of_isPushout hp hg.left, of_isPushout hp hg.right⟩ instance : (⊤ : MorphismProperty C).IsStableUnderBaseChange where of_isPullback _ _ := trivial instance : (⊤ : MorphismProperty C).IsStableUnderCobaseChange where of_isPushout _ _ := trivial end section LimitsOfShape variable (W : MorphismProperty C) (J : Type*) [Category J] /-- The class of morphisms in `C` that are limits of shape `J` of natural transformations involving morphisms in `W`. -/ inductive limitsOfShape : MorphismProperty C | mk (X₁ X₂ : J ⥤ C) (c₁ : Cone X₁) (c₂ : Cone X₂) (_ : IsLimit c₁) (h₂ : IsLimit c₂) (f : X₁ ⟶ X₂) (_ : W.functorCategory J f) : limitsOfShape (h₂.lift (Cone.mk _ (c₁.π ≫ f))) variable {W J} in lemma limitsOfShape.mk' (X₁ X₂ : J ⥤ C) (c₁ : Cone X₁) (c₂ : Cone X₂) (h₁ : IsLimit c₁) (h₂ : IsLimit c₂) (f : X₁ ⟶ X₂) (hf : W.functorCategory J f) (φ : c₁.pt ⟶ c₂.pt) (hφ : ∀ j, φ ≫ c₂.π.app j = c₁.π.app j ≫ f.app j) : W.limitsOfShape J φ := by obtain rfl : φ = h₂.lift (Cone.mk _ (c₁.π ≫ f)) := h₂.hom_ext (fun j ↦ by simp [hφ]) exact ⟨_, _, _, _, h₁, _, _, hf⟩ lemma limitsOfShape_monotone {W₁ W₂ : MorphismProperty C} (h : W₁ ≤ W₂) (J : Type*) [Category J] : W₁.limitsOfShape J ≤ W₂.limitsOfShape J := by rintro _ _ _ ⟨_, _, _, _, h₁, _, f, hf⟩ exact ⟨_, _, _, _, h₁, _, f, fun j ↦ h _ (hf j)⟩ instance : (W.limitsOfShape J).RespectsIso := RespectsIso.of_respects_arrow_iso _ (by rintro ⟨_, _, f⟩ ⟨Y₁, Y₂, g⟩ e ⟨X₁, X₂, c₁, c₂, h₁, h₂, f, hf⟩ let e₁ := Arrow.leftFunc.mapIso e let e₂ := Arrow.rightFunc.mapIso e have fac : g ≫ e₂.inv = e₁.inv ≫ h₂.lift (Cone.mk _ (c₁.π ≫ f)) := e.inv.w.symm let c₁' : Cone X₁ := { pt := Y₁, π := (Functor.const _).map e₁.inv ≫ c₁.π } let c₂' : Cone X₂ := { pt := Y₂, π := (Functor.const _).map e₂.inv ≫ c₂.π } have h₁' : IsLimit c₁' := IsLimit.ofIsoLimit h₁ (Cones.ext e₁) have h₂' : IsLimit c₂' := IsLimit.ofIsoLimit h₂ (Cones.ext e₂) obtain hg : h₂'.lift (Cone.mk _ (c₁'.π ≫ f)) = g := h₂'.hom_ext (fun j ↦ by rw [h₂'.fac] simp [reassoc_of% fac, c₁', c₂']) rw [← hg] exact ⟨_, _, _, _, h₁', _, _, hf⟩) variable {W J} in lemma limitsOfShape_limMap {X Y : J ⥤ C} (f : X ⟶ Y) [HasLimit X] [HasLimit Y] (hf : W.functorCategory _ f) : W.limitsOfShape J (limMap f) := ⟨_, _, _, _, limit.isLimit X, _, _, hf⟩ /-- The property that a morphism property `W` is stable under limits indexed by a category `J`. -/ class IsStableUnderLimitsOfShape : Prop where condition (X₁ X₂ : J ⥤ C) (c₁ : Cone X₁) (c₂ : Cone X₂) (_ : IsLimit c₁) (h₂ : IsLimit c₂) (f : X₁ ⟶ X₂) (_ : W.functorCategory J f) (φ : c₁.pt ⟶ c₂.pt) (hφ : ∀ j, φ ≫ c₂.π.app j = c₁.π.app j ≫ f.app j) : W φ lemma isStableUnderLimitsOfShape_iff_limitsOfShape_le : W.IsStableUnderLimitsOfShape J ↔ W.limitsOfShape J ≤ W := by constructor · rintro h _ _ _ ⟨_, _, _, _, h₁, h₂, f, hf⟩ exact h.condition _ _ _ _ h₁ h₂ f hf _ (by simp) · rintro h constructor intro X₁ X₂ c₁ c₂ h₁ h₂ f hf φ hφ exact h _ (limitsOfShape.mk' X₁ X₂ c₁ c₂ h₁ h₂ f hf φ hφ) variable {W J} lemma limitsOfShape_le [W.IsStableUnderLimitsOfShape J] : W.limitsOfShape J ≤ W := by rwa [← isStableUnderLimitsOfShape_iff_limitsOfShape_le] protected lemma limMap [W.IsStableUnderLimitsOfShape J] {X Y : J ⥤ C} (f : X ⟶ Y) [HasLimit X] [HasLimit Y] (hf : W.functorCategory _ f) : W (limMap f) := limitsOfShape_le _ (limitsOfShape_limMap _ hf) @[deprecated (since := "2025-05-11")] alias IsStableUnderLimitsOfShape.limitsOfShape_le := limitsOfShape_le @[deprecated (since := "2025-05-11")] alias IsStableUnderLimitsOfShape.limMap := MorphismProperty.limMap end LimitsOfShape section ColimitsOfShape variable (W : MorphismProperty C) (J : Type*) [Category J] /-- The class of morphisms in `C` that are colimits of shape `J` of natural transformations involving morphisms in `W`. -/ inductive colimitsOfShape : MorphismProperty C | mk (X₁ X₂ : J ⥤ C) (c₁ : Cocone X₁) (c₂ : Cocone X₂) (h₁ : IsColimit c₁) (h₂ : IsColimit c₂) (f : X₁ ⟶ X₂) (_ : W.functorCategory J f) : colimitsOfShape (h₁.desc (Cocone.mk _ (f ≫ c₂.ι))) variable {W J} in lemma colimitsOfShape.mk' (X₁ X₂ : J ⥤ C) (c₁ : Cocone X₁) (c₂ : Cocone X₂) (h₁ : IsColimit c₁) (h₂ : IsColimit c₂) (f : X₁ ⟶ X₂) (hf : W.functorCategory J f) (φ : c₁.pt ⟶ c₂.pt) (hφ : ∀ j, c₁.ι.app j ≫ φ = f.app j ≫ c₂.ι.app j) : W.colimitsOfShape J φ := by obtain rfl : φ = h₁.desc (Cocone.mk _ (f ≫ c₂.ι)) := h₁.hom_ext (fun j ↦ by simp [hφ]) exact ⟨_, _, _, _, _, h₂, _, hf⟩ lemma colimitsOfShape_monotone {W₁ W₂ : MorphismProperty C} (h : W₁ ≤ W₂) (J : Type*) [Category J] : W₁.colimitsOfShape J ≤ W₂.colimitsOfShape J := by rintro _ _ _ ⟨_, _, _, _, _, h₂, f, hf⟩ exact ⟨_, _, _, _, _, h₂, f, fun j ↦ h _ (hf j)⟩ variable {J} in lemma colimitsOfShape_le_of_final {J' : Type*} [Category J'] (F : J ⥤ J') [F.Final] : W.colimitsOfShape J' ≤ W.colimitsOfShape J := by intro _ _ _ ⟨X₁, X₂, c₁, c₂, h₁, h₂, f, hf⟩ have h₁' : IsColimit (c₁.whisker F) := (Functor.Final.isColimitWhiskerEquiv F c₁).symm h₁ have h₂' : IsColimit (c₂.whisker F) := (Functor.Final.isColimitWhiskerEquiv F c₂).symm h₂ have : h₁.desc (Cocone.mk c₂.pt (f ≫ c₂.ι)) = h₁'.desc (Cocone.mk c₂.pt (Functor.whiskerLeft _ f ≫ (c₂.whisker F).ι)) := h₁'.hom_ext (fun j ↦ by have := h₁'.fac (Cocone.mk c₂.pt (Functor.whiskerLeft F f ≫ Functor.whiskerLeft F c₂.ι)) j dsimp at this ⊢ simp [this]) rw [this] exact ⟨_, _, _, _, h₁', h₂', _, fun _ ↦ hf _⟩ variable {J} in lemma colimitsOfShape_eq_of_equivalence {J' : Type*} [Category J'] (e : J ≌ J') : W.colimitsOfShape J = W.colimitsOfShape J' := le_antisymm (W.colimitsOfShape_le_of_final e.inverse) (W.colimitsOfShape_le_of_final e.functor) instance : (W.colimitsOfShape J).RespectsIso := RespectsIso.of_respects_arrow_iso _ (by rintro ⟨_, _, f⟩ ⟨Y₁, Y₂, g⟩ e ⟨X₁, X₂, c₁, c₂, h₁, h₂, f, hf⟩ let e₁ := Arrow.leftFunc.mapIso e let e₂ := Arrow.rightFunc.mapIso e have fac : e₁.hom ≫ g = h₁.desc (Cocone.mk _ (f ≫ c₂.ι)) ≫ e₂.hom := e.hom.w let c₁' : Cocone X₁ := { pt := Y₁, ι := c₁.ι ≫ (Functor.const _).map e₁.hom} let c₂' : Cocone X₂ := { pt := Y₂, ι := c₂.ι ≫ (Functor.const _).map e₂.hom} have h₁' : IsColimit c₁' := IsColimit.ofIsoColimit h₁ (Cocones.ext e₁) have h₂' : IsColimit c₂' := IsColimit.ofIsoColimit h₂ (Cocones.ext e₂) obtain hg : h₁'.desc (Cocone.mk _ (f ≫ c₂'.ι)) = g := h₁'.hom_ext (fun j ↦ by rw [h₁'.fac] simp [fac, c₁', c₂']) rw [← hg] exact ⟨_, _, _, _, _, h₂', _, hf⟩) variable {W J} in lemma colimitsOfShape_colimMap {X Y : J ⥤ C} (f : X ⟶ Y) [HasColimit X] [HasColimit Y] (hf : W.functorCategory _ f) : W.colimitsOfShape J (colimMap f) := ⟨_, _, _, _, _, colimit.isColimit Y, _, hf⟩ attribute [local instance] IsCofiltered.isConnected in variable {W} in lemma colimitsOfShape.of_isColimit {J : Type*} [Preorder J] [OrderBot J] {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (h : ∀ (j : J), W (F.map (homOfLE bot_le : ⊥ ⟶ j))) : W.colimitsOfShape J (c.ι.app ⊥) := .mk' _ _ _ _ (isColimitConstCocone J (F.obj ⊥)) hc { app k := F.map (homOfLE bot_le) naturality _ _ _ := by dsimp rw [Category.id_comp, ← Functor.map_comp] rfl} h _ (by simp) /-- The property that a morphism property `W` is stable under colimits indexed by a category `J`. -/ class IsStableUnderColimitsOfShape : Prop where condition (X₁ X₂ : J ⥤ C) (c₁ : Cocone X₁) (c₂ : Cocone X₂) (h₁ : IsColimit c₁) (h₁ : IsColimit c₂) (f : X₁ ⟶ X₂) (_ : W.functorCategory J f) (φ : c₁.pt ⟶ c₂.pt) (hφ : ∀ j, c₁.ι.app j ≫ φ = f.app j ≫ c₂.ι.app j) : W φ lemma isStableUnderColimitsOfShape_iff_colimitsOfShape_le : W.IsStableUnderColimitsOfShape J ↔ W.colimitsOfShape J ≤ W := by constructor · rintro h _ _ _ ⟨_, _, _, _, h₁, h₂, f, hf⟩ exact h.condition _ _ _ _ h₁ h₂ f hf _ (by simp) · rintro h constructor intro X₁ X₂ c₁ c₂ h₁ h₂ f hf φ hφ exact h _ (colimitsOfShape.mk' X₁ X₂ c₁ c₂ h₁ h₂ f hf φ hφ) variable {W J} lemma colimitsOfShape_le [W.IsStableUnderColimitsOfShape J] : W.colimitsOfShape J ≤ W := by rwa [← isStableUnderColimitsOfShape_iff_colimitsOfShape_le] protected lemma colimMap [W.IsStableUnderColimitsOfShape J] {X Y : J ⥤ C} (f : X ⟶ Y) [HasColimit X] [HasColimit Y] (hf : W.functorCategory _ f) : W (colimMap f) := colimitsOfShape_le _ (colimitsOfShape_colimMap _ hf) @[deprecated (since := "2025-05-11")] alias IsStableUnderColimitsOfShape.colimMap := MorphismProperty.colimMap @[deprecated (since := "2025-05-11")] alias IsStableUnderColimitsOfShape.colimitsOfShape_le := colimitsOfShape_le variable (C J) in instance IsStableUnderColimitsOfShape.isomorphisms : (isomorphisms C).IsStableUnderColimitsOfShape J where condition F₁ F₂ c₁ c₂ h₁ h₂ f (_ : ∀ j, IsIso (f.app j)) φ hφ := by have := NatIso.isIso_of_isIso_app f exact ⟨h₂.desc (Cocone.mk _ (inv f ≫ c₁.ι)), h₁.hom_ext (fun j ↦ by simp [reassoc_of% (hφ j)]), h₂.hom_ext (by simp [hφ])⟩ end ColimitsOfShape /-- The condition that a property of morphisms is stable by filtered colimits. -/ @[pp_with_univ] class IsStableUnderFilteredColimits (W : MorphismProperty C) : Prop where isStableUnderColimitsOfShape (J : Type w') [Category.{w} J] [IsFiltered J] : W.IsStableUnderColimitsOfShape J := by infer_instance attribute [instance] IsStableUnderFilteredColimits.isStableUnderColimitsOfShape instance : IsStableUnderFilteredColimits.{w, w'} (isomorphisms C) where section Coproducts variable (W : MorphismProperty C) /-- Given `W : MorphismProperty C`, this is class of morphisms that are isomorphic to a coproduct of a family (indexed by some `J : Type w`) of maps in `W`. -/ @[pp_with_univ] def coproducts : MorphismProperty C := ⨆ (J : Type w), W.colimitsOfShape (Discrete J) lemma colimitsOfShape_le_coproducts (J : Type w) : W.colimitsOfShape (Discrete J) ≤ coproducts.{w} W := le_iSup (f := fun (J : Type w) ↦ W.colimitsOfShape (Discrete J)) J lemma coproducts_iff {X Y : C} (f : X ⟶ Y) : coproducts.{w} W f ↔ ∃ (J : Type w), W.colimitsOfShape (Discrete J) f := by simp only [coproducts, iSup_iff] lemma coproducts_of_small {X Y : C} (f : X ⟶ Y) {J : Type w'} (hf : W.colimitsOfShape (Discrete J) f) [Small.{w} J] : coproducts.{w} W f := by rw [coproducts_iff] refine ⟨Shrink J, ?_⟩ rwa [← W.colimitsOfShape_eq_of_equivalence (Discrete.equivalence (equivShrink.{w} J))] lemma le_colimitsOfShape_punit : W ≤ W.colimitsOfShape (Discrete PUnit.{w + 1}) := by intro X₁ X₂ f hf have h := initialIsInitial (C := Discrete (PUnit.{w + 1})) let c₁ := coconeOfDiagramInitial (F := Discrete.functor (fun _ ↦ X₁)) h let c₂ := coconeOfDiagramInitial (F := Discrete.functor (fun _ ↦ X₂)) h have hc₁ : IsColimit c₁ := colimitOfDiagramInitial h _ have hc₂ : IsColimit c₂ := colimitOfDiagramInitial h _ have : hc₁.desc (Cocone.mk _ (Discrete.natTrans (fun _ ↦ by exact f) ≫ c₂.ι)) = f := hc₁.hom_ext (fun x ↦ by obtain rfl : x = ⊥_ _ := by ext rw [IsColimit.fac] simp [c₁, c₂]) rw [← this] exact ⟨_, _, _, _, _, hc₂, _, fun _ ↦ hf⟩ lemma le_coproducts : W ≤ coproducts.{w} W := (le_colimitsOfShape_punit.{w} W).trans (colimitsOfShape_le_coproducts W PUnit.{w + 1}) lemma coproducts_monotone : Monotone (coproducts.{w} (C := C)) := by rintro W₁ W₂ h X Y f hf rw [coproducts_iff] at hf obtain ⟨J, hf⟩ := hf exact W₂.colimitsOfShape_le_coproducts J _ (colimitsOfShape_monotone h _ _ hf) end Coproducts section Products variable (W : MorphismProperty C) /-- The property that a morphism property `W` is stable under products indexed by a type `J`. -/ abbrev IsStableUnderProductsOfShape (J : Type*) := W.IsStableUnderLimitsOfShape (Discrete J) /-- The property that a morphism property `W` is stable under coproducts indexed by a type `J`. -/ abbrev IsStableUnderCoproductsOfShape (J : Type*) := W.IsStableUnderColimitsOfShape (Discrete J) lemma IsStableUnderProductsOfShape.mk (J : Type*) [W.RespectsIso] (hW : ∀ (X₁ X₂ : J → C) [HasProduct X₁] [HasProduct X₂] (f : ∀ j, X₁ j ⟶ X₂ j) (_ : ∀ (j : J), W (f j)), W (Limits.Pi.map f)) : W.IsStableUnderProductsOfShape J where condition X₁ X₂ c₁ c₂ hc₁ hc₂ f hf α hα := by let φ := fun j => f.app (Discrete.mk j) have : HasLimit X₁ := ⟨c₁, hc₁⟩ have : HasLimit X₂ := ⟨c₂, hc₂⟩ have : HasProduct fun j ↦ X₁.obj (Discrete.mk j) := hasLimit_of_iso (Discrete.natIso (fun j ↦ Iso.refl (X₁.obj j))) have : HasProduct fun j ↦ X₂.obj (Discrete.mk j) := hasLimit_of_iso (Discrete.natIso (fun j ↦ Iso.refl (X₂.obj j))) have hf' := hW _ _ φ (fun j => hf (Discrete.mk j)) refine (W.arrow_mk_iso_iff ?_).2 hf' refine Arrow.isoMk (IsLimit.conePointUniqueUpToIso hc₁ (limit.isLimit X₁) ≪≫ (Pi.isoLimit X₁).symm) (IsLimit.conePointUniqueUpToIso hc₂ (limit.isLimit X₂) ≪≫ (Pi.isoLimit _).symm) ?_ apply limit.hom_ext rintro ⟨j⟩ simp [φ, hα] lemma IsStableUnderCoproductsOfShape.mk (J : Type*) [W.RespectsIso] (hW : ∀ (X₁ X₂ : J → C) [HasCoproduct X₁] [HasCoproduct X₂] (f : ∀ j, X₁ j ⟶ X₂ j) (_ : ∀ (j : J), W (f j)), W (Limits.Sigma.map f)) : W.IsStableUnderCoproductsOfShape J where condition X₁ X₂ c₁ c₂ hc₁ hc₂ f hf α hα := by let φ := fun j => f.app (Discrete.mk j) have : HasColimit X₁ := ⟨c₁, hc₁⟩ have : HasColimit X₂ := ⟨c₂, hc₂⟩ have : HasCoproduct fun j ↦ X₁.obj (Discrete.mk j) := hasColimit_of_iso (Discrete.natIso (fun j ↦ Iso.refl (X₁.obj j))) have : HasCoproduct fun j ↦ X₂.obj (Discrete.mk j) := hasColimit_of_iso (Discrete.natIso (fun j ↦ Iso.refl (X₂.obj j))) have hf' := hW _ _ φ (fun j => hf (Discrete.mk j)) refine (W.arrow_mk_iso_iff ?_).1 hf' refine Arrow.isoMk ((Sigma.isoColimit _) ≪≫ IsColimit.coconePointUniqueUpToIso (colimit.isColimit X₁) hc₁) ((Sigma.isoColimit _) ≪≫ IsColimit.coconePointUniqueUpToIso (colimit.isColimit X₂) hc₂) ?_ apply colimit.hom_ext rintro ⟨j⟩ simp [φ, hα] /-- The condition that a property of morphisms is stable by finite products. -/ class IsStableUnderFiniteProducts : Prop where isStableUnderProductsOfShape (J : Type) [Finite J] : W.IsStableUnderProductsOfShape J attribute [instance] IsStableUnderFiniteProducts.isStableUnderProductsOfShape /-- The condition that a property of morphisms is stable by finite coproducts. -/ class IsStableUnderFiniteCoproducts : Prop where isStableUnderCoproductsOfShape (J : Type) [Finite J] : W.IsStableUnderCoproductsOfShape J attribute [instance] IsStableUnderFiniteCoproducts.isStableUnderCoproductsOfShape @[deprecated "This is now an instance." (since := "2025-05-11")] alias isStableUnderProductsOfShape_of_isStableUnderFiniteProducts := IsStableUnderFiniteProducts.isStableUnderProductsOfShape @[deprecated "This is now an instance." (since := "2025-05-11")] alias isStableUnderCoproductsOfShape_of_isStableUnderFiniteCoproducts := IsStableUnderFiniteCoproducts.isStableUnderCoproductsOfShape /-- The condition that a property of morphisms is stable by coproducts. -/ @[pp_with_univ] class IsStableUnderCoproducts : Prop where isStableUnderCoproductsOfShape (J : Type w) : W.IsStableUnderCoproductsOfShape J := by infer_instance attribute [instance] IsStableUnderCoproducts.isStableUnderCoproductsOfShape lemma coproducts_le [IsStableUnderCoproducts.{w} W] : coproducts.{w} W ≤ W := by intro X Y f hf rw [coproducts_iff] at hf obtain ⟨J, hf⟩ := hf exact colimitsOfShape_le _ hf @[simp] lemma coproducts_eq_self [IsStableUnderCoproducts.{w} W] : coproducts.{w} W = W := le_antisymm W.coproducts_le W.le_coproducts @[simp] lemma coproducts_le_iff {P Q : MorphismProperty C} [IsStableUnderCoproducts.{w} Q] : coproducts.{w} P ≤ Q ↔ P ≤ Q := by constructor · exact le_trans P.le_coproducts · intro h exact le_trans (coproducts_monotone h) Q.coproducts_le end Products section Diagonal variable [HasPullbacks C] {P : MorphismProperty C} /-- For `P : MorphismProperty C`, `P.diagonal` is a morphism property that holds for `f : X ⟶ Y` whenever `P` holds for `X ⟶ Y xₓ Y`. -/ def diagonal (P : MorphismProperty C) : MorphismProperty C := fun _ _ f => P (pullback.diagonal f) theorem diagonal_iff {X Y : C} {f : X ⟶ Y} : P.diagonal f ↔ P (pullback.diagonal f) := Iff.rfl instance RespectsIso.diagonal [P.RespectsIso] : P.diagonal.RespectsIso := by apply RespectsIso.mk · introv H rwa [diagonal_iff, pullback.diagonal_comp, P.cancel_left_of_respectsIso, P.cancel_left_of_respectsIso, ← P.cancel_right_of_respectsIso _ (pullback.map (e.hom ≫ f) (e.hom ≫ f) f f e.hom e.hom (𝟙 Z) (by simp) (by simp)), ← pullback.condition, P.cancel_left_of_respectsIso] · introv H delta diagonal rwa [pullback.diagonal_comp, P.cancel_right_of_respectsIso] instance diagonal_isStableUnderComposition [P.IsStableUnderComposition] [RespectsIso P] [IsStableUnderBaseChange P] : P.diagonal.IsStableUnderComposition where comp_mem _ _ h₁ h₂ := by rw [diagonal_iff, pullback.diagonal_comp] exact P.comp_mem _ _ h₁ (by simpa only [cancel_left_of_respectsIso] using P.pullback_snd _ _ h₂) instance IsStableUnderBaseChange.diagonal [IsStableUnderBaseChange P] [P.RespectsIso] : P.diagonal.IsStableUnderBaseChange := IsStableUnderBaseChange.mk' (by introv h rw [diagonal_iff, diagonal_pullback_fst, P.cancel_left_of_respectsIso, P.cancel_right_of_respectsIso] exact P.baseChange_map f _ (by simpa)) lemma diagonal_isomorphisms : (isomorphisms C).diagonal = monomorphisms C := ext _ _ fun _ _ _ ↦ pullback.isIso_diagonal_iff _ /-- If `P` is multiplicative and stable under base change, having the of-postcomp property w.r.t. `Q` is equivalent to `Q` implying `P` on the diagonal. -/ lemma hasOfPostcompProperty_iff_le_diagonal [P.IsStableUnderBaseChange] [P.IsMultiplicative] {Q : MorphismProperty C} [Q.IsStableUnderBaseChange] : P.HasOfPostcompProperty Q ↔ Q ≤ P.diagonal := by refine ⟨fun hP X Y f hf ↦ ?_, fun hP ↦ ⟨fun {Y X S} g f hf hcomp ↦ ?_⟩⟩ · exact hP.of_postcomp _ _ (Q.pullback_fst _ _ hf) (by simpa using P.id_mem X) · set gr : Y ⟶ pullback (g ≫ f) f := pullback.lift (𝟙 Y) g (by simp) have : g = gr ≫ pullback.snd _ _ := by simp [gr] rw [this] apply P.comp_mem · exact P.of_isPullback (pullback_lift_diagonal_isPullback g f) (hP _ hf) · exact P.pullback_snd _ _ hcomp end Diagonal section Universally /-- `P.universally` holds for a morphism `f : X ⟶ Y` iff `P` holds for all `X ×[Y] Y' ⟶ Y'`. -/ def universally (P : MorphismProperty C) : MorphismProperty C := fun X Y f => ∀ ⦃X' Y' : C⦄ (i₁ : X' ⟶ X) (i₂ : Y' ⟶ Y) (f' : X' ⟶ Y') (_ : IsPullback f' i₁ i₂ f), P f' instance universally_respectsIso (P : MorphismProperty C) : P.universally.RespectsIso := by apply RespectsIso.mk · intro X Y Z e f hf X' Z' i₁ i₂ f' H have : IsPullback (𝟙 _) (i₁ ≫ e.hom) i₁ e.inv := IsPullback.of_horiz_isIso ⟨by rw [Category.id_comp, Category.assoc, e.hom_inv_id, Category.comp_id]⟩ exact hf _ _ _ (by simpa only [Iso.inv_hom_id_assoc, Category.id_comp] using this.paste_horiz H) · intro X Y Z e f hf X' Z' i₁ i₂ f' H have : IsPullback (𝟙 _) i₂ (i₂ ≫ e.inv) e.inv := IsPullback.of_horiz_isIso ⟨Category.id_comp _⟩ exact hf _ _ _ (by simpa only [Category.assoc, Iso.hom_inv_id, Category.comp_id, Category.comp_id] using H.paste_horiz this) instance universally_isStableUnderBaseChange (P : MorphismProperty C) : P.universally.IsStableUnderBaseChange where of_isPullback H h₁ _ _ _ _ _ H' := h₁ _ _ _ (H'.paste_vert H.flip) instance IsStableUnderComposition.universally [HasPullbacks C] (P : MorphismProperty C) [hP : P.IsStableUnderComposition] : P.universally.IsStableUnderComposition where comp_mem {X Y Z} f g hf hg X' Z' i₁ i₂ f' H := by have := pullback.lift_fst _ _ (H.w.trans (Category.assoc _ _ _).symm) rw [← this] at H ⊢ apply P.comp_mem _ _ _ (hg _ _ _ <| IsPullback.of_hasPullback _ _) exact hf _ _ _ (H.of_right (pullback.lift_snd _ _ _) (IsPullback.of_hasPullback i₂ g)) theorem universally_le (P : MorphismProperty C) : P.universally ≤ P := by intro X Y f hf exact hf (𝟙 _) (𝟙 _) _ (IsPullback.of_vert_isIso ⟨by rw [Category.comp_id, Category.id_comp]⟩) theorem universally_inf (P Q : MorphismProperty C) : (P ⊓ Q).universally = P.universally ⊓ Q.universally := by ext X Y f change _ ↔ _ ∧ _ simp_rw [universally, ← forall_and] rfl theorem universally_eq_iff {P : MorphismProperty C} : P.universally = P ↔ P.IsStableUnderBaseChange := ⟨(· ▸ P.universally_isStableUnderBaseChange), fun hP ↦ P.universally_le.antisymm fun _ _ _ hf _ _ _ _ _ H => hP.of_isPullback H.flip hf⟩ theorem IsStableUnderBaseChange.universally_eq {P : MorphismProperty C} [hP : P.IsStableUnderBaseChange] : P.universally = P := universally_eq_iff.mpr hP theorem universally_mono : Monotone (universally : MorphismProperty C → MorphismProperty C) := fun _ _ h _ _ _ h₁ _ _ _ _ _ H => h _ (h₁ _ _ _ H) lemma universally_mk' (P : MorphismProperty C) [P.RespectsIso] {X Y : C} (g : X ⟶ Y) (H : ∀ {T : C} (f : T ⟶ Y) [HasPullback f g], P (pullback.fst f g)) : universally P g := by introv X' h have := h.hasPullback rw [← h.isoPullback_hom_fst, P.cancel_left_of_respectsIso] exact H .. end Universally variable (P : MorphismProperty C) /-- `P` has pullbacks if for every `f` satisfying `P`, pullbacks of arbitrary morphisms along `f` exist. -/ protected class HasPullbacks : Prop where hasPullback {X Y S : C} {f : X ⟶ S} (g : Y ⟶ S) : P f → HasPullback f g := by infer_instance instance [HasPullbacks C] : P.HasPullbacks where alias hasPullback := HasPullbacks.hasPullback end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/TransfiniteComposition.lean
import Mathlib.CategoryTheory.Limits.Connected import Mathlib.CategoryTheory.Limits.Shapes.Preorder.TransfiniteCompositionOfShape import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.Order.Interval.Set.SuccOrder import Mathlib.Order.Shrink /-! # Classes of morphisms that are stable under transfinite composition Given a well-ordered type `J`, `W : MorphismProperty C` and a morphism `f : X ⟶ Y`, we define a structure `W.TransfiniteCompositionOfShape J f` which expresses that `f` is a transfinite composition of shape `J` of morphisms in `W`. This structures extends `CategoryTheory.TransfiniteCompositionOfShape` which was defined in the file `CategoryTheory.Limits.Shape.Preorder.TransfiniteCompositionOfShape`. We use this structure in order to define the class of morphisms `W.transfiniteCompositionsOfShape J : MorphismProperty C`, and the type class `W.IsStableUnderTransfiniteCompositionOfShape J`. In particular, if `J := ℕ`, we define `W.IsStableUnderInfiniteComposition`, Finally, we introduce the class `W.IsStableUnderTransfiniteComposition` which says that `W.IsStableUnderTransfiniteCompositionOfShape J` holds for any well-ordered type `J` in a certain universe `w`. -/ universe w w' v v' u u' namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] namespace MorphismProperty variable (W : MorphismProperty C) section variable (J : Type w) [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J] {J' : Type w'} [LinearOrder J'] [SuccOrder J'] [OrderBot J'] [WellFoundedLT J'] /-- Structure expressing that a morphism `f : X ⟶ Y` in a category `C` is a transfinite composition of shape `J` of morphisms in `W : MorphismProperty C`. -/ structure TransfiniteCompositionOfShape {X Y : C} (f : X ⟶ Y) extends CategoryTheory.TransfiniteCompositionOfShape J f where map_mem (j : J) (hj : ¬IsMax j) : W (F.map (homOfLE (Order.le_succ j))) namespace TransfiniteCompositionOfShape section variable {W J} {X Y : C} {f : X ⟶ Y} (h : W.TransfiniteCompositionOfShape J f) /-- If `f` and `f'` are two isomorphic morphisms and `f` is a transfinite composition of morphisms in `W : MorphismProperty C`, then so is `f'`. -/ @[simps toTransfiniteCompositionOfShape] def ofArrowIso {X' Y' : C} {f' : X' ⟶ Y'} (e : Arrow.mk f ≅ Arrow.mk f') : W.TransfiniteCompositionOfShape J f' where __ := h.toTransfiniteCompositionOfShape.ofArrowIso e map_mem := h.map_mem /-- If `W ≤ W'`, then transfinite compositions of shape `J` of morphisms in `W` are also transfinite composition of shape `J` of morphisms in `W'`. -/ @[simps toTransfiniteCompositionOfShape] def ofLE {W' : MorphismProperty C} (hW : W ≤ W') : W'.TransfiniteCompositionOfShape J f where __ := h.toTransfiniteCompositionOfShape map_mem j hj := hW _ (h.map_mem j hj) /-- If `f` is a transfinite composition of shape `J` of morphisms in `W`, then it is also a transfinite composition of shape `J'` of morphisms in `W` if `J' ≃o J`. -/ def ofOrderIso {J' : Type w'} [LinearOrder J'] [OrderBot J'] [SuccOrder J'] [WellFoundedLT J'] (e : J' ≃o J) : W.TransfiniteCompositionOfShape J' f where __ := h.toTransfiniteCompositionOfShape.ofOrderIso e map_mem j hj := by have := h.map_mem (e j) (by simpa only [e.isMax_apply]) rw [← W.arrow_mk_mem_toSet_iff] at this ⊢ have eq : Arrow.mk (homOfLE (e.monotone (Order.le_succ j))) = Arrow.mk (homOfLE (Order.le_succ (e j))) := Arrow.ext rfl (e.map_succ j) rfl replace eq := congr_arg h.F.mapArrow.obj eq convert this using 1 /-- If `f` is a transfinite composition of shape `J` of morphisms in `W.inverseImage F`, then `F` is a transfinite composition of shape `J` of morphisms in `W` provided `F` preserves suitable colimits. -/ @[simps toTransfiniteCompositionOfShape] noncomputable def map {W : MorphismProperty D} {F : C ⥤ D} [PreservesWellOrderContinuousOfShape J F] [PreservesColimitsOfShape J F] (h : (W.inverseImage F).TransfiniteCompositionOfShape J f) : W.TransfiniteCompositionOfShape J (F.map f) where __ := h.toTransfiniteCompositionOfShape.map F map_mem j hj := h.map_mem j hj /-- A transfinite composition of shape `J` of morphisms in `W` induces a transfinite composition of shape `Set.Iic j` (for any `j : J`). -/ noncomputable def iic (j : J) : W.TransfiniteCompositionOfShape (Set.Iic j) (h.F.map (homOfLE bot_le : ⊥ ⟶ j)) where __ := h.toTransfiniteCompositionOfShape.iic j map_mem i hi := by have := h.map_mem i.1 (by rw [not_isMax_iff] at hi ⊢ obtain ⟨i', hi'⟩ := hi exact ⟨j, lt_of_lt_of_le hi' i'.2⟩) rw [← W.arrow_mk_mem_toSet_iff] at this ⊢ have eq : Arrow.mk ((Subtype.mono_coe _).functor.map (homOfLE (Order.le_succ i))) = Arrow.mk (homOfLE (Order.le_succ i.1)) := Arrow.ext rfl (Set.Iic.coe_succ_of_not_isMax hi) rfl replace eq := congr_arg h.F.mapArrow.obj eq convert this using 1 /-- A transfinite composition of shape `J` of morphisms in `W` induces a transfinite composition of shape `Set.Ici j` (for any `j : J`). -/ noncomputable def ici (j : J) : W.TransfiniteCompositionOfShape (Set.Ici j) (h.incl.app j) where __ := h.toTransfiniteCompositionOfShape.ici j map_mem i hi := by have := h.map_mem i.1 (Set.not_isMax_coe _ hi) rw [← W.arrow_mk_mem_toSet_iff] at this ⊢ have eq : Arrow.mk ((Subtype.mono_coe _).functor.map (homOfLE (Order.le_succ i))) = Arrow.mk (homOfLE (Order.le_succ i.1)) := Arrow.ext rfl (coe_succ_of_mem (i.2.trans (Order.le_succ _))) rfl replace eq := congr_arg h.F.mapArrow.obj eq convert this using 1 end /-- If `F : ComposableArrows C n` and all maps `F.obj i.castSucc ⟶ F.obj i.succ` are in `W`, then `F.hom : F.left ⟶ F.right` is a transfinite composition of shape `Fin (n + 1)` of morphisms in `W`. -/ @[simps!] def ofComposableArrows {n : ℕ} (F : ComposableArrows C n) (hF : ∀ (i : Fin n), W (F.map (homOfLE i.castSucc_le_succ))) : W.TransfiniteCompositionOfShape (Fin (n + 1)) F.hom where toTransfiniteCompositionOfShape := .ofComposableArrows F map_mem j hj := by obtain ⟨j, rfl⟩ | rfl := j.eq_castSucc_or_eq_last · replace hF := hF j rw [← W.arrow_mk_mem_toSet_iff] at hF ⊢ have eq : Arrow.mk (homOfLE (Order.le_succ j.castSucc)) = Arrow.mk (homOfLE j.castSucc_le_succ) := Arrow.ext rfl j.orderSucc_castSucc rfl replace eq := congr_arg F.mapArrow.obj eq convert hF using 1 · rw [isMax_iff_eq_top] at hj exact (hj rfl).elim /-- The identity of any object is a transfinite composition of shape `Fin 1`. -/ def id (X : C) : W.TransfiniteCompositionOfShape (Fin 1) (𝟙 X) := ofComposableArrows W (.mk₀ X) (by simp) variable {W} /-- If `f : X ⟶ Y` satisfies `W f`, then `f` is a transfinite composition of shape `Fin 2` of morphisms in `W`. -/ def ofMem {X Y : C} (f : X ⟶ Y) (hf : W f) : W.TransfiniteCompositionOfShape (Fin 2) f := ofComposableArrows W (.mk₁ f) (fun i ↦ by fin_cases i; assumption) /-- If `f : X ⟶ Y` and `g : Y ⟶ Z` satisfy `W f` and `W g`, then `f ≫ g` is a transfinite composition of shape `Fin 3` of morphisms in `W`. -/ def ofComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (hf : W f) (hg : W g) : W.TransfiniteCompositionOfShape (Fin 3) (f ≫ g) := ofComposableArrows W (.mk₂ f g) (fun i ↦ by fin_cases i <;> assumption) end TransfiniteCompositionOfShape /-- Given `W : MorphismProperty C` and a well-ordered type `J`, this is the class of morphisms that are transfinite composition of shape `J` of morphisms in `W`. -/ def transfiniteCompositionsOfShape : MorphismProperty C := fun _ _ f ↦ Nonempty (W.TransfiniteCompositionOfShape J f) lemma transfiniteCompositionsOfShape_monotone : Monotone (transfiniteCompositionsOfShape (C := C) (J := J)) := by rintro _ _ h _ _ _ ⟨t⟩ exact ⟨t.ofLE h⟩ variable {J} in lemma transfiniteCompositionsOfShape_eq_of_orderIso (e : J ≃o J') : W.transfiniteCompositionsOfShape J = W.transfiniteCompositionsOfShape J' := by ext _ _ f exact ⟨fun ⟨h⟩ ↦ ⟨h.ofOrderIso e.symm⟩, fun ⟨h⟩ ↦ ⟨h.ofOrderIso e⟩⟩ instance : RespectsIso (W.transfiniteCompositionsOfShape J) := RespectsIso.of_respects_arrow_iso _ (fun _ _ e ⟨h⟩ ↦ ⟨h.ofArrowIso e⟩) variable {W J} in lemma TransfiniteCompositionOfShape.mem {X Y : C} (f : X ⟶ Y) (h : W.TransfiniteCompositionOfShape J f) : W.transfiniteCompositionsOfShape J f := ⟨h⟩ lemma transfiniteCompositionsOfShape_map_of_preserves (G : C ⥤ D) [PreservesWellOrderContinuousOfShape J G] {X Y : C} (f : X ⟶ Y) {P : MorphismProperty D} [PreservesColimitsOfShape J G] (h : (P.inverseImage G).transfiniteCompositionsOfShape J f) : P.transfiniteCompositionsOfShape J (G.map f) := h.some.map.mem /-- A class of morphisms `W : MorphismProperty C` is stable under transfinite compositions of shape `J` if for any well-order-continuous functor `F : J ⥤ C` such that `F.obj j ⟶ F.obj (Order.succ j)` is in `W`, then `F.obj ⊥ ⟶ c.pt` is in `W` for any colimit cocone `c : Cocone F`. -/ @[mk_iff] class IsStableUnderTransfiniteCompositionOfShape : Prop where le : W.transfiniteCompositionsOfShape J ≤ W lemma transfiniteCompositionsOfShape_le [W.IsStableUnderTransfiniteCompositionOfShape J] : W.transfiniteCompositionsOfShape J ≤ W := IsStableUnderTransfiniteCompositionOfShape.le variable {J} in lemma isStableUnderTransfiniteCompositionOfShape_iff_of_orderIso (e : J ≃o J') : W.IsStableUnderTransfiniteCompositionOfShape J ↔ W.IsStableUnderTransfiniteCompositionOfShape J' := by simp only [isStableUnderTransfiniteCompositionOfShape_iff, W.transfiniteCompositionsOfShape_eq_of_orderIso e] end section variable (J : Type w) [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J] namespace IsStableUnderTransfiniteCompositionOfShape.of_isStableUnderColimitsOfShape variable {W J} {X Y : C} {f : X ⟶ Y} (hf : W.TransfiniteCompositionOfShape J f) [W.IsMultiplicative] (hJ : ∀ (J : Type w) [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J], W.IsStableUnderColimitsOfShape J) attribute [local instance] IsCofiltered.isConnected include hJ in lemma mem_map_bot_le {j : J} (g : ⊥ ⟶ j) : W (hf.F.map g) := by obtain rfl : g = homOfLE bot_le := rfl induction j using SuccOrder.limitRecOn with | isMin j hj => obtain rfl := hj.eq_bot simpa using W.id_mem _ | succ j hj hj' => rw [← homOfLE_comp bot_le (Order.le_succ j), hf.F.map_comp] exact W.comp_mem _ _ hj' (hf.map_mem j hj) | isSuccLimit j hj hj' => letI : OrderBot (Set.Iio j) := { bot := ⟨⊥, Order.IsSuccLimit.bot_lt hj⟩ bot_le j := bot_le } exact MorphismProperty.colimitsOfShape_le _ (.of_isColimit (hf.F.isColimitOfIsWellOrderContinuous j hj) (fun k ↦ hj' _ k.2)) include hf hJ in lemma mem [W.RespectsIso] : W f := (MorphismProperty.arrow_mk_iso_iff _ (Arrow.isoMk hf.isoBot.symm (Iso.refl _))).2 (MorphismProperty.colimitsOfShape_le _ (.of_isColimit hf.isColimit (fun j ↦ mem_map_bot_le _ hJ _))) end IsStableUnderTransfiniteCompositionOfShape.of_isStableUnderColimitsOfShape variable {W J} in open IsStableUnderTransfiniteCompositionOfShape.of_isStableUnderColimitsOfShape in lemma IsStableUnderTransfiniteCompositionOfShape.of_isStableUnderColimitsOfShape [W.IsMultiplicative] [W.RespectsIso] (hJ : ∀ (J : Type w) [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J], W.IsStableUnderColimitsOfShape J) : W.IsStableUnderTransfiniteCompositionOfShape J where le _ _ _ | ⟨hf⟩ => mem hf hJ instance [W.IsMultiplicative] [W.RespectsIso] [MorphismProperty.IsStableUnderFilteredColimits.{w, w} W] : W.IsStableUnderTransfiniteCompositionOfShape J := .of_isStableUnderColimitsOfShape (fun _ _ _ _ _ ↦ by infer_instance) end /-- A class of morphisms `W : MorphismProperty C` is stable under infinite composition if for any functor `F : ℕ ⥤ C` such that `F.obj n ⟶ F.obj (n + 1)` is in `W` for any `n : ℕ`, the map `F.obj 0 ⟶ c.pt` is in `W` for any colimit cocone `c : Cocone F`. -/ abbrev IsStableUnderInfiniteComposition : Prop := W.IsStableUnderTransfiniteCompositionOfShape ℕ /-- A class of morphisms `W : MorphismProperty C` is stable under transfinite composition if it is multiplicative and stable under transfinite composition of any shape (in a certain universe). -/ class IsStableUnderTransfiniteComposition : Prop where isStableUnderTransfiniteCompositionOfShape (J : Type w) [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J] : W.IsStableUnderTransfiniteCompositionOfShape J := by infer_instance namespace IsStableUnderTransfiniteComposition attribute [instance] isStableUnderTransfiniteCompositionOfShape instance [W.IsMultiplicative] [W.RespectsIso] [MorphismProperty.IsStableUnderFilteredColimits.{w, w} W] : IsStableUnderTransfiniteComposition.{w} W where example : (isomorphisms C).IsStableUnderTransfiniteComposition := inferInstance variable [IsStableUnderTransfiniteComposition.{w'} W] lemma shrink [UnivLE.{w, w'}] : IsStableUnderTransfiniteComposition.{w} W where isStableUnderTransfiniteCompositionOfShape J _ _ _ _ := by rw [isStableUnderTransfiniteCompositionOfShape_iff_of_orderIso W (orderIsoShrink.{w'} J)] infer_instance lemma shrink₀ : IsStableUnderTransfiniteComposition.{0} W := shrink.{0, w'} W attribute [local instance] shrink₀ instance : W.IsMultiplicative where id_mem X := transfiniteCompositionsOfShape_le _ _ _ (TransfiniteCompositionOfShape.id W X).mem comp_mem f g hf hg := transfiniteCompositionsOfShape_le _ _ _ (TransfiniteCompositionOfShape.ofComp f g hf hg).mem end IsStableUnderTransfiniteComposition /-- The class of transfinite compositions (for arbitrary well-ordered types `J : Type w`) of a class of morphisms `W`. -/ @[pp_with_univ] def transfiniteCompositions : MorphismProperty C := ⨆ (J : Type w) (_ : LinearOrder J) (_ : SuccOrder J) (_ : OrderBot J) (_ : WellFoundedLT J), W.transfiniteCompositionsOfShape J lemma transfiniteCompositions_iff {X Y : C} (f : X ⟶ Y) : transfiniteCompositions.{w} W f ↔ ∃ (J : Type w) (_ : LinearOrder J) (_ : SuccOrder J) (_ : OrderBot J) (_ : WellFoundedLT J), W.transfiniteCompositionsOfShape J f := by simp only [transfiniteCompositions, iSup_iff] lemma transfiniteCompositionsOfShape_le_transfiniteCompositions (J : Type w) [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J] : W.transfiniteCompositionsOfShape J ≤ transfiniteCompositions.{w} W := by intro A B f hf rw [transfiniteCompositions_iff] exact ⟨_, _, _, _, _, hf⟩ lemma transfiniteCompositions_monotone : Monotone (transfiniteCompositions.{w} (C := C)) := by intro W₁ W₂ h X Y f hf rw [transfiniteCompositions_iff] at hf obtain ⟨J, _, _, _, _, hf⟩ := hf exact transfiniteCompositionsOfShape_le_transfiniteCompositions _ _ _ (transfiniteCompositionsOfShape_monotone J h _ hf) lemma le_transfiniteCompositions : W ≤ transfiniteCompositions.{w} W := le_trans (fun _ _ _ hf ↦ (MorphismProperty.TransfiniteCompositionOfShape.ofOrderIso (.ofMem _ hf) (orderIsoShrink.{w} (Fin 2)).symm).mem) (transfiniteCompositionsOfShape_le_transfiniteCompositions _ _) lemma transfiniteCompositions_le [IsStableUnderTransfiniteComposition.{w} W] : transfiniteCompositions.{w} W ≤ W := by intro _ _ f hf rw [transfiniteCompositions_iff] at hf obtain ⟨J, _, _, _, _, hf⟩ := hf exact W.transfiniteCompositionsOfShape_le J _ hf @[simp] lemma transfiniteCompositions_le_iff {P Q : MorphismProperty C} [IsStableUnderTransfiniteComposition.{w} Q] : transfiniteCompositions.{w} P ≤ Q ↔ P ≤ Q := by constructor · exact (le_transfiniteCompositions P).trans · intro h exact (transfiniteCompositions_monotone.{w} h).trans Q.transfiniteCompositions_le namespace TransfiniteCompositionOfShape variable {W} {J : Type w} [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J] section variable [IsStableUnderTransfiniteComposition.{w} W] {X Y : C} {f : X ⟶ Y} (h : W.TransfiniteCompositionOfShape J f) lemma mem_map {i j : J} (φ : i ⟶ j) : W (h.F.map φ) := W.transfiniteCompositionsOfShape_le _ _ ((h.iic j).ici ⟨i, leOfHom φ⟩).mem lemma mem_incl_app (j : J) : W (h.incl.app j) := W.transfiniteCompositionsOfShape_le _ _ (h.ici j).mem end section isomorphisms example : (isomorphisms C).IsStableUnderTransfiniteCompositionOfShape J := inferInstance variable {X Y : C} {f : X ⟶ Y} (h : (isomorphisms C).TransfiniteCompositionOfShape J f) include h in lemma isIso : IsIso f := (isomorphisms C).transfiniteCompositionsOfShape_le _ _ h.mem instance {i j : J} (f : i ⟶ j) : IsIso (h.F.map f) := h.mem_map f instance (j : J) : IsIso (h.incl.app j) := h.mem_incl_app j end isomorphisms end TransfiniteCompositionOfShape end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/Concrete.lean
import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.MorphismProperty.Composition import Mathlib.CategoryTheory.MorphismProperty.Factorization /-! # Morphism properties defined in concrete categories In this file, we define the class of morphisms `MorphismProperty.injective`, `MorphismProperty.surjective`, `MorphismProperty.bijective` in concrete categories, and show that it is stable under composition and respect isomorphisms. We introduce type-classes `HasSurjectiveInjectiveFactorization` and `HasFunctorialSurjectiveInjectiveFactorization` expressing that in a concrete category `C`, all morphisms can be factored (resp. factored functorially) as a surjective map followed by an injective map. -/ universe v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] {FC : C → C → Type*} {CC : C → Type*} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC] namespace MorphismProperty open Function /-- Injectivity (in a concrete category) as a `MorphismProperty` -/ protected def injective : MorphismProperty C := fun _ _ f => Injective f /-- Surjectiveness (in a concrete category) as a `MorphismProperty` -/ protected def surjective : MorphismProperty C := fun _ _ f => Surjective f /-- Bijectiveness (in a concrete category) as a `MorphismProperty` -/ protected def bijective : MorphismProperty C := fun _ _ f => Bijective f theorem bijective_eq_sup : MorphismProperty.bijective C = MorphismProperty.injective C ⊓ MorphismProperty.surjective C := rfl instance : (MorphismProperty.injective C).IsMultiplicative where id_mem X := by delta MorphismProperty.injective convert injective_id aesop comp_mem f g hf hg := by delta MorphismProperty.injective rw [hom_comp] exact hg.comp hf instance : (MorphismProperty.surjective C).IsMultiplicative where id_mem X := by delta MorphismProperty.surjective convert surjective_id aesop comp_mem f g hf hg := by delta MorphismProperty.surjective rw [hom_comp] exact hg.comp hf instance : (MorphismProperty.bijective C).IsMultiplicative where id_mem X := by delta MorphismProperty.bijective convert bijective_id aesop comp_mem f g hf hg := by delta MorphismProperty.bijective rw [hom_comp] exact hg.comp hf instance injective_respectsIso : (MorphismProperty.injective C).RespectsIso := respectsIso_of_isStableUnderComposition (fun _ _ f (_ : IsIso f) => ((forget C).mapIso (asIso f)).toEquiv.injective) instance surjective_respectsIso : (MorphismProperty.surjective C).RespectsIso := respectsIso_of_isStableUnderComposition (fun _ _ f (_ : IsIso f) => ((forget C).mapIso (asIso f)).toEquiv.surjective) instance bijective_respectsIso : (MorphismProperty.bijective C).RespectsIso := respectsIso_of_isStableUnderComposition (fun _ _ f (_ : IsIso f) => ((forget C).mapIso (asIso f)).toEquiv.bijective) end MorphismProperty namespace ConcreteCategory /-- The property that any morphism in a concrete category can be factored as a surjective map followed by an injective map. -/ abbrev HasSurjectiveInjectiveFactorization := (MorphismProperty.surjective C).HasFactorization (MorphismProperty.injective C) /-- The property that any morphism in a concrete category can be functorially factored as a surjective map followed by an injective map. -/ abbrev HasFunctorialSurjectiveInjectiveFactorization := (MorphismProperty.surjective C).HasFunctorialFactorization (MorphismProperty.injective C) /-- The structure containing the data of a functorial factorization of morphisms as a surjective map followed by an injective map in a concrete category. -/ abbrev FunctorialSurjectiveInjectiveFactorizationData := (MorphismProperty.surjective C).FunctorialFactorizationData (MorphismProperty.injective C) end ConcreteCategory open ConcreteCategory attribute [local instance] Types.instFunLike Types.instConcreteCategory in /-- In the category of types, any map can be functorially factored as a surjective map followed by an injective map. -/ def functorialSurjectiveInjectiveFactorizationData : FunctorialSurjectiveInjectiveFactorizationData (Type u) where Z := { obj := fun f => Subtype (Set.range f.hom) map := fun φ y => ⟨φ.right y.1, by obtain ⟨_, x, rfl⟩ := y exact ⟨φ.left x, congr_fun φ.w x⟩ ⟩ } i := { app := fun f x => ⟨f.hom x, ⟨x, rfl⟩⟩ naturality := fun f g φ => by ext x exact congr_fun φ.w x } p := { app := fun _ y => y.1 naturality := by intros; rfl; } fac := rfl hi := by rintro f ⟨_, x, rfl⟩ exact ⟨x, rfl⟩ hp f x₁ x₂ h := by rw [Subtype.ext_iff] exact h attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance : HasFunctorialSurjectiveInjectiveFactorization (Type u) where nonempty_functorialFactorizationData := ⟨functorialSurjectiveInjectiveFactorizationData⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/FunctorCategory.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.EpiMono import Mathlib.CategoryTheory.MorphismProperty.Retract import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.CategoryTheory.MorphismProperty.TransfiniteComposition /-! # Stability properties of morphism properties on functor categories Given `W : MorphismProperty C` and a category `J`, we study the stability properties of `W.functorCategory J : MorphismProperty (J ⥤ C)`. Under suitable assumptions, we also show that if monomorphisms in `C` are stable under transfinite compositions, then the same holds in the category `J ⥤ C`. -/ universe v v' v'' u u' u'' namespace CategoryTheory open Limits namespace MorphismProperty variable {C : Type u} [Category.{v} C] (W : MorphismProperty C) instance [W.IsStableUnderRetracts] (J : Type u'') [Category.{v''} J] : (W.functorCategory J).IsStableUnderRetracts where of_retract hfg hg j := W.of_retract (hfg.map ((evaluation _ _).obj j).mapArrow) (hg j) variable {W} instance IsStableUnderLimitsOfShape.functorCategory {K : Type u'} [Category.{v'} K] [W.IsStableUnderLimitsOfShape K] (J : Type u'') [Category.{v''} J] [HasLimitsOfShape K C] : (W.functorCategory J).IsStableUnderLimitsOfShape K where condition X₁ X₂ _ _ hc₁ hc₂ f hf φ hφ j := MorphismProperty.limitsOfShape_le _ (limitsOfShape.mk' (X₁ ⋙ (evaluation _ _ ).obj j) (X₂ ⋙ (evaluation _ _ ).obj j) _ _ (isLimitOfPreserves _ hc₁) (isLimitOfPreserves _ hc₂) (Functor.whiskerRight f _) (fun k ↦ hf k j) (φ.app j) (fun k ↦ congr_app (hφ k) j)) instance IsStableUnderColimitsOfShape.functorCategory {K : Type u'} [Category.{v'} K] [W.IsStableUnderColimitsOfShape K] (J : Type u'') [Category.{v''} J] [HasColimitsOfShape K C] : (W.functorCategory J).IsStableUnderColimitsOfShape K where condition X₁ X₂ _ _ hc₁ hc₂ f hf φ hφ j := MorphismProperty.colimitsOfShape_le _ (colimitsOfShape.mk' (X₁ ⋙ (evaluation _ _ ).obj j) (X₂ ⋙ (evaluation _ _ ).obj j) _ _ (isColimitOfPreserves _ hc₁) (isColimitOfPreserves _ hc₂) (Functor.whiskerRight f _) (fun k ↦ hf k j) (φ.app j) (fun k ↦ congr_app (hφ k) j)) instance [W.IsStableUnderBaseChange] (J : Type u'') [Category.{v''} J] [HasPullbacks C] : (W.functorCategory J).IsStableUnderBaseChange where of_isPullback sq hr j := W.of_isPullback (sq.map ((evaluation _ _).obj j)) (hr j) instance [W.IsStableUnderCobaseChange] (J : Type u'') [Category.{v''} J] [HasPushouts C] : (W.functorCategory J).IsStableUnderCobaseChange where of_isPushout sq hr j := W.of_isPushout (sq.map ((evaluation _ _).obj j)) (hr j) instance (K : Type u') [LinearOrder K] [SuccOrder K] [OrderBot K] [WellFoundedLT K] [W.IsStableUnderTransfiniteCompositionOfShape K] (J : Type u'') [Category.{v''} J] [HasIterationOfShape K C] : (W.functorCategory J).IsStableUnderTransfiniteCompositionOfShape K where le := by rintro X Y f ⟨hf⟩ j have : W.functorCategory J ≤ W.inverseImage ((evaluation _ _).obj j) := fun _ _ _ h ↦ h _ exact W.transfiniteCompositionsOfShape_le K _ ⟨(hf.ofLE this).map⟩ variable (J : Type u'') [Category.{v''} J] lemma functorCategory_isomorphisms : (isomorphisms C).functorCategory J = isomorphisms (J ⥤ C) := by ext _ _ f simp only [functorCategory, isomorphisms.iff, NatTrans.isIso_iff_isIso_app] lemma functorCategory_monomorphisms [HasPullbacks C] : (monomorphisms C).functorCategory J = monomorphisms (J ⥤ C) := by ext _ _ f simp only [functorCategory, monomorphisms.iff, NatTrans.mono_iff_mono_app] lemma functorCategory_epimorphisms [HasPushouts C] : (epimorphisms C).functorCategory J = epimorphisms (J ⥤ C) := by ext _ _ f simp only [functorCategory, epimorphisms.iff, NatTrans.epi_iff_epi_app] instance (K : Type u') [LinearOrder K] [SuccOrder K] [OrderBot K] [WellFoundedLT K] [(monomorphisms C).IsStableUnderTransfiniteCompositionOfShape K] [HasPullbacks C] (J : Type u'') [Category.{v''} J] [HasIterationOfShape K C] : (monomorphisms (J ⥤ C)).IsStableUnderTransfiniteCompositionOfShape K := by rw [← functorCategory_monomorphisms] infer_instance end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/MorphismProperty/OverAdjunction.lean
import Mathlib.CategoryTheory.MorphismProperty.Comma import Mathlib.CategoryTheory.Comma.Over.Pullback import Mathlib.CategoryTheory.MorphismProperty.Limits /-! # Adjunction of pushforward and pullback in `P.Over Q X` Under suitable assumptions on `P`, `Q` and `f`, a morphism `f : X ⟶ Y` defines two functors: - `Over.map`: post-composition with `f` - `Over.pullback`: base-change along `f` such that `Over.map` is the left adjoint to `Over.pullback`. -/ namespace CategoryTheory.MorphismProperty open Limits variable {T : Type*} [Category T] (P Q : MorphismProperty T) [Q.IsMultiplicative] variable {X Y Z : T} section Map variable {P} [P.IsStableUnderComposition] /-- If `P` is stable under composition and `f : X ⟶ Y` satisfies `P`, this is the functor `P.Over Q X ⥤ P.Over Q Y` given by composing with `f`. -/ @[simps! obj_left obj_hom map_left] def Over.map {f : X ⟶ Y} (hPf : P f) : P.Over Q X ⥤ P.Over Q Y := Comma.mapRight _ (Discrete.natTrans fun _ ↦ f) <| fun X ↦ P.comp_mem _ _ X.prop hPf lemma Over.map_comp {f : X ⟶ Y} (hf : P f) {g : Y ⟶ Z} (hg : P g) : map Q (P.comp_mem f g hf hg) = map Q hf ⋙ map Q hg := by fapply Functor.ext · simp [map, Comma.mapRight, CategoryTheory.Comma.mapRight, Comma.lift] · intro U V k ext simp /-- `Over.map` commutes with composition. -/ @[simps! hom_app_left inv_app_left] def Over.mapComp {f : X ⟶ Y} (hf : P f) {g : Y ⟶ Z} (hg : P g) [Q.RespectsIso] : map Q (P.comp_mem f g hf hg) ≅ map Q hf ⋙ map Q hg := NatIso.ofComponents (fun X ↦ Over.isoMk (Iso.refl _)) end Map section Pullback variable [P.IsStableUnderBaseChange] [Q.IsStableUnderBaseChange] /-- If `P` and `Q` are stable under base change and pullbacks exist in `T`, this is the functor `P.Over Q Y ⥤ P.Over Q X` given by base change along `f`. -/ @[simps! obj_left obj_hom map_left] noncomputable def Over.pullback (f : X ⟶ Y) [HasPullbacksAlong f] : P.Over Q Y ⥤ P.Over Q X where obj A := { __ := (CategoryTheory.Over.pullback f).obj A.toComma prop := P.pullback_snd _ _ A.prop } map {A B} g := { __ := (CategoryTheory.Over.pullback f).map g.toCommaMorphism prop_hom_left := Q.baseChange_map f g.toCommaMorphism g.prop_hom_left prop_hom_right := trivial } variable {P} {Q} /-- `Over.pullback` commutes with composition. -/ @[simps! hom_app_left inv_app_left] noncomputable def Over.pullbackComp (f : X ⟶ Y) [HasPullbacksAlong f] (g : Y ⟶ Z) [HasPullbacksAlong g] [Q.RespectsIso] : Over.pullback P Q (f ≫ g) ≅ Over.pullback P Q g ⋙ Over.pullback P Q f := NatIso.ofComponents (fun X ↦ Over.isoMk ((pullbackLeftPullbackSndIso X.hom g f).symm) (by simp)) lemma Over.pullbackComp_left_fst_fst (f : X ⟶ Y) [HasPullbacksAlong f] (g : Y ⟶ Z) [HasPullbacksAlong g] [Q.RespectsIso] (A : P.Over Q Z) : ((Over.pullbackComp f g).hom.app A).left ≫ pullback.fst (pullback.snd A.hom g) f ≫ pullback.fst A.hom g = pullback.fst A.hom (f ≫ g) := by simp /-- If `f = g`, then base change along `f` is naturally isomorphic to base change along `g`. -/ noncomputable def Over.pullbackCongr {f : X ⟶ Y} [HasPullbacksAlong f] {g : X ⟶ Y} (h : f = g) : have : HasPullbacksAlong g := by subst h; infer_instance Over.pullback P Q f ≅ Over.pullback P Q g := NatIso.ofComponents (fun X ↦ eqToIso (by simp [h])) @[reassoc (attr := simp)] lemma Over.pullbackCongr_hom_app_left_fst {f : X ⟶ Y} [HasPullbacksAlong f] {g : X ⟶ Y} (h : f = g) (A : P.Over Q Y) : have : HasPullbacksAlong g := by subst h; infer_instance ((Over.pullbackCongr h).hom.app A).left ≫ pullback.fst A.hom g = pullback.fst A.hom f := by subst h simp [pullbackCongr] end Pullback section Adjunction variable [P.IsStableUnderComposition] [P.IsStableUnderBaseChange] [Q.IsStableUnderBaseChange] /-- `P.Over.map` is left adjoint to `P.Over.pullback` if `f` satisfies `P`. -/ noncomputable def Over.mapPullbackAdj (f : X ⟶ Y) [HasPullbacksAlong f] [Q.HasOfPostcompProperty Q] (hPf : P f) (hQf : Q f) : Over.map Q hPf ⊣ Over.pullback P Q f := Adjunction.mkOfHomEquiv { homEquiv := fun A B ↦ { toFun := fun g ↦ Over.homMk (pullback.lift g.left A.hom <| by simp) (by simp) <| by apply Q.of_postcomp (W' := Q) · exact Q.pullback_fst B.hom f hQf · simpa using g.prop_hom_left invFun := fun h ↦ Over.homMk (h.left ≫ pullback.fst B.hom f) (by simp only [map_obj_left, Functor.const_obj_obj, pullback_obj_left, Functor.id_obj, Category.assoc, pullback.condition, map_obj_hom, ← pullback_obj_hom, Over.w_assoc]) (Q.comp_mem _ _ h.prop_hom_left (Q.pullback_fst _ _ hQf)) left_inv := by cat_disch right_inv := fun h ↦ by ext dsimp ext · simp · simpa using h.w.symm } } end Adjunction end CategoryTheory.MorphismProperty
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/TransfiniteCompositionLifting.lean
import Mathlib.CategoryTheory.SmallObject.WellOrderInductionData import Mathlib.CategoryTheory.MorphismProperty.LiftingProperty import Mathlib.CategoryTheory.MorphismProperty.TransfiniteComposition import Mathlib.CategoryTheory.Limits.Shapes.Preorder.WellOrderContinuous /-! # The left lifting property is stable under transfinite composition In this file, we show that if `W : MorphismProperty C`, then `W.llp.IsStableUnderTransfiniteCompositionOfShape J`, i.e. the class of morphisms which have the left lifting property with respect to `W` is stable under transfinite composition. The main technical lemma is `HasLiftingProperty.transfiniteComposition.hasLiftingProperty_ι_app_bot`. It corresponds to the particular case `W` contains only one morphism `p : X ⟶ Y`: it shows that a transfinite composition of morphisms that have the left lifting property with respect to `p` also has the left lifting property with respect to `p`. About the proof, given a colimit cocone `c` for a well-order-continuous functor `F : J ⥤ C` from a well-ordered type `J`, we introduce a projective system `sqFunctor c p f g : Jᵒᵖ ⥤ Type _` which associates to any `j : J` the structure `SqStruct c p f g j` which consists of those morphisms `f'` which makes the diagram below commute. The data of such compatible `f'` for all `j` shall give the expected lifting `c.pt ⟶ X` for the outer square. ``` f F.obj ⊥ --> X | Λ | | f'╱ | v ╱ | F.obj j | p | | | | v g v c.pt ---> Y ``` This is constructed by transfinite induction on `j`: * When `j = ⊥`, this is `f`; * In order to pass from `j` to `Order.succ j`, we use the assumption that `F.obj j ⟶ F.obj (Order.succ j)` has the left lifting property with respect to `p`; * When `j` is a limit element, we use the "continuity" of `F`. -/ universe w v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] namespace HasLiftingProperty variable {J : Type w} [LinearOrder J] [OrderBot J] namespace transfiniteComposition variable {F : J ⥤ C} (c : Cocone F) (hc : IsColimit c) {X Y : C} (p : X ⟶ Y) (f : F.obj ⊥ ⟶ X) (g : c.pt ⟶ Y) /-- Given a cocone `c` for a functor `F : J ⥤ C` from a well-ordered type, and maps `p : X ⟶ Y`, `f : F.obj ⊥ ⟶ X`, `g : c.pt ⟶ Y`, this structure contains the data of a map `F.obj j ⟶ X` such that `F.map (homOfLE bot_le) ≫ f' = f` and `f' ≫ p = c.ι.app j ≫ g`. (This implies that the outer square below commutes, see `SqStruct.w`.) ``` f F.obj ⊥ --> X | Λ | | f'╱ | v ╱ | F.obj j | p | | | | v g v c.pt ---> Y ``` -/ @[ext] structure SqStruct (j : J) where /-- a morphism `F.obj j ⟶ X` -/ f' : F.obj j ⟶ X w₁ : F.map (homOfLE bot_le) ≫ f' = f := by cat_disch w₂ : f' ≫ p = c.ι.app j ≫ g := by cat_disch namespace SqStruct attribute [reassoc (attr := simp)] w₁ w₂ variable {c p f g} {j : J} (sq' : SqStruct c p f g j) include sq' in @[reassoc] lemma w : f ≫ p = c.ι.app ⊥ ≫ g := by rw [← sq'.w₁, assoc, sq'.w₂, Cocone.w_assoc] /-- Given `sq' : SqStruct c p f g j`, this is the commutative square ``` sq'.f' F.obj j --------------------> X | | | |p v g v F.obj (succ j) ---> c.pt ---> Y ``` (Using the lifting property for this square is the key ingredient in the proof that the left lifting property with respect to `p` is stable under transfinite composition.) -/ lemma sq [SuccOrder J] : CommSq sq'.f' (F.map (homOfLE (Order.le_succ j))) p (c.ι.app _ ≫ g) where w := by simp /-- Auxiliary definition for `sqFunctor`. -/ @[simps] def map {j' : J} (α : j' ⟶ j) : SqStruct c p f g j' where f' := F.map α ≫ sq'.f' w₁ := by rw [← F.map_comp_assoc] exact sq'.w₁ end SqStruct /-- The projective system `j ↦ SqStruct c p f g j.unop`. -/ @[simps] def sqFunctor : Jᵒᵖ ⥤ Type _ where obj j := SqStruct c p f g j.unop map α sq' := sq'.map α.unop variable [F.IsWellOrderContinuous] namespace wellOrderInductionData variable {p c f g} {j : J} (hj : Order.IsSuccLimit j) (s : ((OrderHom.Subtype.val (· ∈ Set.Iio j)).monotone.functor.op ⋙ sqFunctor c p f g).sections) /-- Auxiliary definition for `transfiniteComposition.wellOrderInductionData`. -/ noncomputable def liftHom : F.obj j ⟶ X := (F.isColimitOfIsWellOrderContinuous j hj).desc (Cocone.mk _ { app := fun i ↦ (s.1 ⟨i⟩).f' naturality i i' g := by have := congr_arg SqStruct.f' (s.2 g.op) dsimp at this ⊢ rw [this, comp_id] }) @[reassoc] lemma liftHom_fac (i : J) (hi : i < j) : F.map (homOfLE hi.le) ≫ liftHom hj s = (s.1 ⟨⟨i, hi⟩⟩).f' := (F.isColimitOfIsWellOrderContinuous j hj).fac _ ⟨i, hi⟩ /-- Auxiliary definition for `transfiniteComposition.wellOrderInductionData`. -/ @[simps] noncomputable def lift : (sqFunctor c p f g).obj (Opposite.op j) where f' := liftHom hj s w₁ := by have h : ⊥ < j := Ne.bot_lt' (by rintro rfl exact Order.not_isSuccLimit_bot hj) rw [liftHom_fac hj s ⊥ h] simpa using (s.1 ⟨⊥, h⟩).w₁ w₂ := (F.isColimitOfIsWellOrderContinuous j hj).hom_ext (fun ⟨i, hij⟩ ↦ by have := (s.1 ⟨i, hij⟩).w₂ dsimp at this ⊢ rw [liftHom_fac_assoc _ _ _ hij, this, Cocone.w_assoc]) lemma map_lift {i : J} (hij : i < j) : (lift hj s).map (homOfLE hij.le) = s.1 ⟨⟨i, hij⟩⟩ := by ext apply liftHom_fac end wellOrderInductionData variable {p} [SuccOrder J] [WellFoundedLT J] section variable (hF : ∀ (j : J) (_ : ¬IsMax j), HasLiftingPropertyFixedBot (F.map (homOfLE (Order.le_succ j))) p (c.ι.app _ ≫ g)) open wellOrderInductionData in /-- The projective system `sqFunctor c p f g` has a `WellOrderInductionData` structure. -/ noncomputable def wellOrderInductionData : (sqFunctor c p f g).WellOrderInductionData where succ j hj sq' := have := hF j hj sq'.f' have := hF j hj { f' := sq'.sq.lift w₁ := by dsimp simp only [← sq'.w₁] conv_rhs => rw [← sq'.sq.fac_left, ← F.map_comp_assoc] rfl } map_succ j hj sq' := by cat_disch lift j hj s := lift hj s map_lift j hj s i hij := map_lift hj s hij include hF hc variable {c f g} (sq : CommSq f (c.ι.app ⊥) p g) lemma hasLift : sq.HasLift := by obtain ⟨s, hs⟩ := (wellOrderInductionData c f g hF).surjective { w₂ := sq.w, .. } replace hs := congr_arg SqStruct.f' hs dsimp at hs let t : Cocone F := Cocone.mk X { app j := (s.1 ⟨j⟩).f' naturality j j' g := by simpa using congr_arg SqStruct.f' (s.2 g.op) } let l := hc.desc t have hl (j : J) : c.ι.app j ≫ l = (s.1 ⟨j⟩).f' := hc.fac t j exact ⟨⟨{ l := l fac_left := by rw [hl, hs] fac_right := hc.hom_ext (fun j ↦ by rw [reassoc_of% (hl j), SqStruct.w₂])}⟩⟩ lemma hasLiftingPropertyFixedBot_ι_app_bot : HasLiftingPropertyFixedBot (c.ι.app ⊥) p g := fun _ sq ↦ hasLift hc hF sq end variable {c} (hF : ∀ (j : J) (_ : ¬IsMax j), HasLiftingProperty (F.map (homOfLE (Order.le_succ j))) p) include hc hF lemma hasLiftingProperty_ι_app_bot : HasLiftingProperty (c.ι.app ⊥) p where sq_hasLift sq := hasLift hc (fun j hj _ _ ↦ by have := hF j hj; infer_instance) sq end transfiniteComposition end HasLiftingProperty namespace MorphismProperty variable (W : MorphismProperty C) (J : Type w) [LinearOrder J] [SuccOrder J] [OrderBot J] [WellFoundedLT J] instance isStableUnderTransfiniteCompositionOfShape_llp : W.llp.IsStableUnderTransfiniteCompositionOfShape J := by rw [isStableUnderTransfiniteCompositionOfShape_iff] rintro X Y f ⟨h⟩ have : W.llp (h.incl.app ⊥) := fun _ _ p hp ↦ HasLiftingProperty.transfiniteComposition.hasLiftingProperty_ι_app_bot (hc := h.isColimit) (fun j hj ↦ h.map_mem j hj _ hp) exact (MorphismProperty.arrow_mk_iso_iff _ (Arrow.isoMk h.isoBot.symm (Iso.refl _))).2 this lemma transfiniteCompositionsOfShape_le_llp_rlp : W.transfiniteCompositionsOfShape J ≤ W.rlp.llp := by have := W.rlp.isStableUnderTransfiniteCompositionOfShape_llp J rw [isStableUnderTransfiniteCompositionOfShape_iff] at this exact le_trans (transfiniteCompositionsOfShape_monotone J W.le_llp_rlp) this lemma transfiniteCompositionsOfShape_pushouts_coproducts_le_llp_rlp : (coproducts.{w} W).pushouts.transfiniteCompositionsOfShape J ≤ W.rlp.llp := by simpa using transfiniteCompositionsOfShape_le_llp_rlp (coproducts.{w} W).pushouts J lemma retracts_transfiniteCompositionsOfShape_pushouts_coproducts_le_llp_rlp : ((coproducts.{w} W).pushouts.transfiniteCompositionsOfShape J).retracts ≤ W.rlp.llp := by rw [le_llp_iff_le_rlp, rlp_retracts, ← le_llp_iff_le_rlp] apply transfiniteCompositionsOfShape_pushouts_coproducts_le_llp_rlp lemma transfiniteCompositions_le_llp_rlp : transfiniteCompositions.{w} W ≤ W.rlp.llp := by intro _ _ f hf rw [transfiniteCompositions_iff] at hf obtain ⟨_, _, _, _, _, hf⟩ := hf exact W.transfiniteCompositionsOfShape_le_llp_rlp _ _ hf lemma transfiniteCompositions_pushouts_coproducts_le_llp_rlp : (transfiniteCompositions.{w} (coproducts.{w} W).pushouts) ≤ W.rlp.llp := by simpa using transfiniteCompositions_le_llp_rlp (coproducts.{w} W).pushouts lemma retracts_transfiniteComposition_pushouts_coproducts_le_llp_rlp : (transfiniteCompositions.{w} (coproducts.{w} W).pushouts).retracts ≤ W.rlp.llp := by rw [le_llp_iff_le_rlp, rlp_retracts, ← le_llp_iff_le_rlp] apply transfiniteCompositions_pushouts_coproducts_le_llp_rlp end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/TransfiniteIteration.lean
import Mathlib.CategoryTheory.SmallObject.Iteration.Nonempty import Mathlib.CategoryTheory.MorphismProperty.TransfiniteComposition import Mathlib.CategoryTheory.Limits.Shapes.Preorder.WellOrderContinuous /-! # The transfinite iteration of a successor structure Given a successor structure `Φ : SuccStruct C` (see the file `SmallObject.Iteration.Basic`) and a well-ordered type `J`, we define the iteration `Φ.iteration J : C`. It is defined as the colimit of a functor `Φ.iterationFunctor J : J ⥤ C`. -/ universe w v u namespace CategoryTheory.SmallObject.SuccStruct open Category Limits variable {C : Type u} [Category.{v} C] (Φ : SuccStruct C) (J : Type w) [LinearOrder J] [OrderBot J] [SuccOrder J] [WellFoundedLT J] [HasIterationOfShape J C] variable {J} in /-- Given `Φ : SuccStruct C` and an element `j : J` in a well-ordered type, this is the unique element in `Φ.Iteration j`. -/ noncomputable def iter (j : J) : Φ.Iteration j := Classical.arbitrary _ /-- Given `Φ : SuccStruct C` and a well-ordered type `J`, this is the functor `J ⥤ C` which gives the iterations of `Φ` indexed by `J`. -/ noncomputable def iterationFunctor : J ⥤ C where obj j := (Φ.iter j).F.obj ⟨j, by simp⟩ map f := Iteration.mapObj _ _ (leOfHom f) _ _ (leOfHom f) /-- Given `Φ : SuccStruct C` and a well-ordered type `J`, this is an object of `C` which is the iteration of `Φ` to the power `J`: it is defined as the colimit of the functor `Φ.iterationFunctor J : J ⥤ C`. -/ noncomputable def iteration : C := colimit (Φ.iterationFunctor J) /-- The colimit cocone expressing that `Φ.iteration J` is the colimit of `Φ.iterationFunctor J`. -/ noncomputable def iterationCocone : Cocone (Φ.iterationFunctor J) := colimit.cocone _ @[simp] lemma iterationCocone_pt : (Φ.iterationCocone J).pt = Φ.iteration J := rfl /-- `Φ.iteration J` identifies to the colimit of `Φ.iterationFunctor J`. -/ noncomputable def isColimitIterationCocone : IsColimit (Φ.iterationCocone J) := colimit.isColimit _ variable {J} lemma iterationFunctor_obj (i : J) {j : J} (iter : Φ.Iteration j) (hi : i ≤ j) : (Φ.iterationFunctor J).obj i = iter.F.obj ⟨i, hi⟩ := Iteration.congr_obj (Φ.iter i) iter i (by simp) hi lemma arrowMk_iterationFunctor_map (i₁ i₂ : J) (h₁₂ : i₁ ≤ i₂) {j : J} (iter : Φ.Iteration j) (hj : i₂ ≤ j) : Arrow.mk ((Φ.iterationFunctor J).map (homOfLE h₁₂)) = Arrow.mk (iter.F.map (homOfLE h₁₂ : ⟨i₁, h₁₂.trans hj⟩ ⟶ ⟨i₂, hj⟩)) := by dsimp [iterationFunctor] rw [Iteration.arrow_mk_mapObj] exact Arrow.ext (Iteration.congr_obj _ _ _ _ _) (Iteration.congr_obj _ _ _ _ _) (Iteration.congr_map _ _ _ _ _) variable (J) instance : (Φ.iterationFunctor J).IsWellOrderContinuous where nonempty_isColimit i hi := ⟨by let e : (Set.principalSegIio i).monotone.functor ⋙ (Φ.iterationFunctor J) ≅ restrictionLT (Φ.iter i).F (by simp) := NatIso.ofComponents (fun _ ↦ eqToIso (Φ.iterationFunctor_obj _ _ _)) (by rintro ⟨k₁, h₁⟩ ⟨k₂, h₂⟩ f apply Arrow.mk_injective simpa using Φ.arrowMk_iterationFunctor_map k₁ k₂ (leOfHom f) (Φ.iter i) h₂.le) refine (IsColimit.precomposeInvEquiv e _).1 ?_ refine IsColimit.ofIsoColimit ((Φ.iter i).isColimit i hi (by simp)) ?_ refine Cocones.ext (eqToIso (Φ.iterationFunctor_obj i (Φ.iter i) (by simp)).symm) ?_ rintro ⟨k, hk⟩ apply Arrow.mk_injective simp [Φ.arrowMk_iterationFunctor_map k i hk.le (Φ.iter i) (by simp), e]⟩ /-- The isomorphism `(Φ.iterationFunctor J).obj ⊥ ≅ Φ.X₀`. -/ noncomputable def iterationFunctorObjBotIso : (Φ.iterationFunctor J).obj ⊥ ≅ Φ.X₀ := eqToIso (Φ.iter ⊥).obj_bot /-- The natural map `Φ.X₀ ⟶ (Φ.iterationFunctor J).obj j`. -/ noncomputable def ιIterationFunctor : (Functor.const _).obj Φ.X₀ ⟶ Φ.iterationFunctor J where app j := (Φ.iterationFunctorObjBotIso J).inv ≫ (Φ.iterationFunctor J).map (homOfLE bot_le : ⊥ ⟶ j) naturality _ _ f := by dsimp rw [id_comp, assoc, ← Functor.map_comp] rfl /-- The canonical map `Φ.X₀ ⟶ Φ.iteration J` which is the `J`th-transfinite composition of maps `Φ.toSucc`. -/ noncomputable def ιIteration : Φ.X₀ ⟶ Φ.iteration J := (Φ.iterationFunctorObjBotIso J).inv ≫ colimit.ι _ ⊥ /-- The inclusion `Φ.ιIteration J` is a transfinite composition of shape `J` of morphisms in `Φ.prop`. -/ @[simps] noncomputable def transfiniteCompositionOfShapeιIteration : Φ.prop.TransfiniteCompositionOfShape J (Φ.ιIteration J) where isoBot := Φ.iterationFunctorObjBotIso J map_mem j hj := by have := (Φ.iter (Order.succ j)).prop_map_succ j (Order.lt_succ_of_not_isMax hj) rw [prop_iff] at this ⊢ simp only [Φ.iterationFunctor_obj j (Φ.iter (Order.succ j)) (Order.le_succ j), Φ.arrowMk_iterationFunctor_map _ _ (Order.le_succ j) (Φ.iter (Order.succ j)) (by simp), this] F := Φ.iterationFunctor J incl := (Φ.iterationCocone J).ι isColimit := Φ.isColimitIterationCocone J variable {J} lemma prop_iterationFunctor_map_succ (j : J) (hj : ¬ IsMax j) : Φ.prop ((Φ.iterationFunctor J).map (homOfLE (Order.le_succ j))) := (Φ.transfiniteCompositionOfShapeιIteration J).map_mem j hj /-- When `j` is not a maximal element, then `(Φ.iterationFunctor J).obj (Order.succ j)` is isomorphic to `Φ.succ ((Φ.iterationFunctor J).obj j)`. -/ noncomputable def iterationFunctorObjSuccIso (j : J) (hj : ¬ IsMax j) : (Φ.iterationFunctor J).obj (Order.succ j) ≅ Φ.succ ((Φ.iterationFunctor J).obj j) := eqToIso ((Φ.prop_iterationFunctor_map_succ j hj).succ_eq.symm) @[reassoc] lemma iterationFunctor_map_succ (j : J) (hj : ¬ IsMax j) : (Φ.iterationFunctor J).map (homOfLE (Order.le_succ j)) = Φ.toSucc _ ≫ (Φ.iterationFunctorObjSuccIso j hj).inv := (Φ.prop_iterationFunctor_map_succ j hj).fac end CategoryTheory.SmallObject.SuccStruct
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/Construction.lean
import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.AlgebraicTopology.RelativeCellComplex.AttachCells /-! # Construction for the small object argument Given a family of morphisms `f i : A i ⟶ B i` in a category `C`, we define a functor `SmallObject.functor f : Arrow S ⥤ Arrow S` which sends an object given by arrow `πX : X ⟶ S` to the pushout `functorObj f πX`: ``` ∐ functorObjSrcFamily f πX ⟶ X | | | | v v ∐ functorObjTgtFamily f πX ⟶ functorObj f πX ``` where the morphism on the left is a coproduct (of copies of maps `f i`) indexed by a type `FunctorObjIndex f πX` which parametrizes the diagrams of the form ``` A i ⟶ X | | | | v v B i ⟶ S ``` The morphism `ιFunctorObj f πX : X ⟶ functorObj f πX` is part of a natural transformation `SmallObject.ε f : 𝟭 (Arrow C) ⟶ functor f S`. The main idea in this construction is that for any commutative square as above, there may not exist a lifting `B i ⟶ X`, but the construction provides a tautological morphism `B i ⟶ functorObj f πX` (see `SmallObject.ιFunctorObj_extension`). ## References - https://ncatlab.org/nlab/show/small+object+argument -/ universe t w v u namespace CategoryTheory open Category Limits HomotopicalAlgebra namespace SmallObject variable {C : Type u} [Category.{v} C] {I : Type w} {A B : I → C} (f : ∀ i, A i ⟶ B i) section variable {S X : C} (πX : X ⟶ S) /-- Given a family of morphisms `f i : A i ⟶ B i` and a morphism `πX : X ⟶ S`, this type parametrizes the commutative squares with a morphism `f i` on the left and `πX` in the right. -/ structure FunctorObjIndex where /-- an element in the index type -/ i : I /-- the top morphism in the square -/ t : A i ⟶ X /-- the bottom morphism in the square -/ b : B i ⟶ S w : t ≫ πX = f i ≫ b attribute [reassoc (attr := simp)] FunctorObjIndex.w variable [HasColimitsOfShape (Discrete (FunctorObjIndex f πX)) C] /-- The family of objects `A x.i` parametrized by `x : FunctorObjIndex f πX`. -/ abbrev functorObjSrcFamily (x : FunctorObjIndex f πX) : C := A x.i /-- The family of objects `B x.i` parametrized by `x : FunctorObjIndex f πX`. -/ abbrev functorObjTgtFamily (x : FunctorObjIndex f πX) : C := B x.i /-- The family of the morphisms `f x.i : A x.i ⟶ B x.i` parametrized by `x : FunctorObjIndex f πX`. -/ abbrev functorObjLeftFamily (x : FunctorObjIndex f πX) : functorObjSrcFamily f πX x ⟶ functorObjTgtFamily f πX x := f x.i /-- The top morphism in the pushout square in the definition of `pushoutObj f πX`. -/ noncomputable abbrev functorObjTop : ∐ functorObjSrcFamily f πX ⟶ X := Limits.Sigma.desc (fun x => x.t) /-- The left morphism in the pushout square in the definition of `pushoutObj f πX`. -/ noncomputable abbrev functorObjLeft : ∐ functorObjSrcFamily f πX ⟶ ∐ functorObjTgtFamily f πX := Limits.Sigma.map (functorObjLeftFamily f πX) variable [HasPushout (functorObjTop f πX) (functorObjLeft f πX)] /-- The functor `SmallObject.functor f : Arrow C ⥤ Arrow C` that is part of the small object argument for a family of morphisms `f`, on an object given as a morphism `πX : X ⟶ S`. -/ noncomputable abbrev functorObj : C := pushout (functorObjTop f πX) (functorObjLeft f πX) /-- The canonical morphism `X ⟶ functorObj f πX`. -/ noncomputable abbrev ιFunctorObj : X ⟶ functorObj f πX := pushout.inl _ _ /-- The canonical morphism `∐ (functorObjTgtFamily f πX) ⟶ functorObj f πX`. -/ noncomputable abbrev ρFunctorObj : ∐ functorObjTgtFamily f πX ⟶ functorObj f πX := pushout.inr _ _ @[reassoc] lemma functorObj_comm : functorObjTop f πX ≫ ιFunctorObj f πX = functorObjLeft f πX ≫ ρFunctorObj f πX := pushout.condition lemma functorObj_isPushout : IsPushout (functorObjTop f πX) (functorObjLeft f πX) (ιFunctorObj f πX) (ρFunctorObj f πX) := IsPushout.of_hasPushout _ _ @[reassoc] lemma FunctorObjIndex.comm (x : FunctorObjIndex f πX) : f x.i ≫ Sigma.ι (functorObjTgtFamily f πX) x ≫ ρFunctorObj f πX = x.t ≫ ιFunctorObj f πX := by simpa using (Sigma.ι (functorObjSrcFamily f πX) x ≫= functorObj_comm f πX).symm /-- The canonical projection on the base object. -/ noncomputable abbrev π'FunctorObj : ∐ functorObjTgtFamily f πX ⟶ S := Sigma.desc (fun x => x.b) /-- The canonical projection on the base object. -/ noncomputable def πFunctorObj : functorObj f πX ⟶ S := pushout.desc πX (π'FunctorObj f πX) (by ext; simp [π'FunctorObj]) @[reassoc (attr := simp)] lemma ρFunctorObj_π : ρFunctorObj f πX ≫ πFunctorObj f πX = π'FunctorObj f πX := by simp [πFunctorObj] @[reassoc (attr := simp)] lemma ιFunctorObj_πFunctorObj : ιFunctorObj f πX ≫ πFunctorObj f πX = πX := by simp [ιFunctorObj, πFunctorObj] /-- The morphism `ιFunctorObj f πX : X ⟶ functorObj f πX` is obtained by attaching `f`-cells. -/ @[simps] noncomputable def attachCellsιFunctorObj : AttachCells.{max v w} f (ιFunctorObj f πX) where ι := FunctorObjIndex f πX π x := x.i isColimit₁ := coproductIsCoproduct _ isColimit₂ := coproductIsCoproduct _ m := functorObjLeft f πX g₁ := functorObjTop f πX g₂ := ρFunctorObj f πX isPushout := IsPushout.of_hasPushout (functorObjTop f πX) (functorObjLeft f πX) cofan₁ := _ cofan₂ := _ section Small variable [LocallySmall.{t} C] [Small.{t} I] instance : Small.{t} (FunctorObjIndex f πX) := by let φ (x : FunctorObjIndex f πX) : Σ (i : Shrink.{t} I), Shrink.{t} ((A ((equivShrink _).symm i) ⟶ X) × (B ((equivShrink _).symm i) ⟶ S)) := ⟨equivShrink _ x.i, equivShrink _ ⟨eqToHom (by simp) ≫ x.t, eqToHom (by simp) ≫ x.b⟩⟩ have hφ : Function.Injective φ := by rintro ⟨i₁, t₁, b₁, _⟩ ⟨i₂, t₂, b₂, _⟩ h obtain rfl : i₁ = i₂ := by simpa [φ] using congr_arg Sigma.fst h simpa [cancel_epi, φ] using h exact small_of_injective hφ instance : Small.{t} (attachCellsιFunctorObj f πX).ι := by dsimp infer_instance /-- The morphism `ιFunctorObj f πX : X ⟶ functorObj f πX` is obtained by attaching `f`-cells, and the index type can be chosen to be in `Type t` if the category is `t`-locally small and the index type for `f` is `t`-small. -/ noncomputable def attachCellsιFunctorObjOfSmall : AttachCells.{t} f (ιFunctorObj f πX) := (attachCellsιFunctorObj f πX).reindex (equivShrink.{t} _).symm end Small section variable {S T X Y : C} {πX : X ⟶ S} {πY : Y ⟶ T} (τ : Arrow.mk πX ⟶ Arrow.mk πY) [HasColimitsOfShape (Discrete (FunctorObjIndex f πX)) C] [HasColimitsOfShape (Discrete (FunctorObjIndex f πY)) C] /-- The canonical morphism `∐ (functorObjSrcFamily f πX) ⟶ ∐ (functorObjSrcFamily f πY)` induced by a morphism `Arrow.mk πX ⟶ Arrow.mk πY`. -/ noncomputable def functorMapSrc : ∐ (functorObjSrcFamily f πX) ⟶ ∐ functorObjSrcFamily f πY := Sigma.map' (fun x => FunctorObjIndex.mk x.i (x.t ≫ τ.left) (x.b ≫ τ.right) (by simp)) (fun _ => 𝟙 _) @[reassoc] lemma ι_functorMapSrc (i : I) (t : A i ⟶ X) (b : B i ⟶ S) (w : t ≫ πX = f i ≫ b) (b' : B i ⟶ T) (hb' : b ≫ τ.right = b') (t' : A i ⟶ Y) (ht' : t ≫ τ.left = t') : Sigma.ι _ (FunctorObjIndex.mk i t b w) ≫ functorMapSrc f τ = Sigma.ι (functorObjSrcFamily f πY) (FunctorObjIndex.mk i t' b' (by have := τ.w dsimp at this rw [← hb', ← reassoc_of% w, ← ht', assoc, this])) := by subst hb' ht' simp [functorMapSrc] @[reassoc (attr := simp)] lemma functorMapSrc_functorObjTop : functorMapSrc f τ ≫ functorObjTop f πY = functorObjTop f πX ≫ τ.left := by ext ⟨i, t, b, w⟩ simp [ι_functorMapSrc_assoc f τ i t b w _ rfl] /-- The canonical morphism `∐ functorObjTgtFamily f πX ⟶ ∐ functorObjTgtFamily f πY` induced by a morphism `Arrow.mk πX ⟶ Arrow.mk πY`. -/ noncomputable def functorMapTgt : ∐ functorObjTgtFamily f πX ⟶ ∐ functorObjTgtFamily f πY := Sigma.map' (fun x => FunctorObjIndex.mk x.i (x.t ≫ τ.left) (x.b ≫ τ.right) (by simp)) (fun _ => 𝟙 _) @[reassoc] lemma ι_functorMapTgt (i : I) (t : A i ⟶ X) (b : B i ⟶ S) (w : t ≫ πX = f i ≫ b) (b' : B i ⟶ T) (hb' : b ≫ τ.right = b') (t' : A i ⟶ Y) (ht' : t ≫ τ.left = t') : Sigma.ι _ (FunctorObjIndex.mk i t b w) ≫ functorMapTgt f τ = Sigma.ι (functorObjTgtFamily f πY) (FunctorObjIndex.mk i t' b' (by have := τ.w dsimp at this rw [← hb', ← reassoc_of% w, ← ht', assoc, this])) := by subst hb' ht' simp [functorMapTgt] lemma functorMap_comm : functorObjLeft f πX ≫ functorMapTgt f τ = functorMapSrc f τ ≫ functorObjLeft f πY := by ext ⟨i, t, b, w⟩ simp only [ι_colimMap_assoc, Discrete.natTrans_app, ι_colimMap, ι_functorMapTgt f τ i t b w _ rfl, ι_functorMapSrc_assoc f τ i t b w _ rfl] variable [HasPushout (functorObjTop f πX) (functorObjLeft f πX)] [HasPushout (functorObjTop f πY) (functorObjLeft f πY)] /-- The functor `SmallObject.functor f S : Arrow S ⥤ Arrow S` that is part of the small object argument for a family of morphisms `f`, on morphisms. -/ noncomputable def functorMap : functorObj f πX ⟶ functorObj f πY := pushout.map _ _ _ _ τ.left (functorMapTgt f τ) (functorMapSrc f τ) (by simp) (functorMap_comm f τ) @[reassoc (attr := simp)] lemma functorMap_π : functorMap f τ ≫ πFunctorObj f πY = πFunctorObj f πX ≫ τ.right := by ext ⟨i, t, b, w⟩ · simp [functorMap] · simp [functorMap, ι_functorMapTgt_assoc f τ i t b w _ rfl] variable (X) in @[simp] lemma functorMap_id : functorMap f (𝟙 (Arrow.mk πX)) = 𝟙 _ := by ext ⟨i, t, b, w⟩ · simp [functorMap] · simp [functorMap, ι_functorMapTgt_assoc f (𝟙 (Arrow.mk πX)) i t b w b (by simp) t (by simp)] @[reassoc (attr := simp)] lemma ιFunctorObj_naturality : ιFunctorObj f πX ≫ functorMap f τ = τ.left ≫ ιFunctorObj f πY := by simp [ιFunctorObj, functorMap] lemma ιFunctorObj_extension {i : I} (t : A i ⟶ X) (b : B i ⟶ S) (sq : CommSq t (f i) πX b) : ∃ (l : B i ⟶ functorObj f πX), f i ≫ l = t ≫ ιFunctorObj f πX ∧ l ≫ πFunctorObj f πX = b := ⟨Sigma.ι (functorObjTgtFamily f πX) (FunctorObjIndex.mk i t b sq.w) ≫ ρFunctorObj f πX, (FunctorObjIndex.mk i t b _).comm, by simp⟩ /-- Variant of `ιFunctorObj_extension` where the diagram involving `functorObj f πX` is replaced by an isomorphic diagram. -/ lemma ιFunctorObj_extension' {X' S' Z' : C} (πX' : X' ⟶ S') (ι' : X' ⟶ Z') (πZ' : Z' ⟶ S') (fac' : ι' ≫ πZ' = πX') (eX : X' ≅ X) (eS : S' ≅ S) (eZ : Z' ≅ functorObj f πX) (commι : ι' ≫ eZ.hom = eX.hom ≫ ιFunctorObj f πX) (commπ : πZ' ≫ eS.hom = eZ.hom ≫ πFunctorObj f πX) {i : I} (t : A i ⟶ X') (b : B i ⟶ S') (fac : t ≫ πX' = f i ≫ b) : ∃ (l : B i ⟶ Z'), f i ≫ l = t ≫ ι' ∧ l ≫ πZ' = b := by obtain ⟨l, hl₁, hl₂⟩ := ιFunctorObj_extension f (πX := πX) (i := i) (t ≫ eX.hom) (b ≫ eS.hom) ⟨by rw [assoc, ← ιFunctorObj_πFunctorObj f πX, ← reassoc_of% commι, ← commπ, reassoc_of% fac', reassoc_of% fac]⟩ refine ⟨l ≫ eZ.inv, ?_, ?_⟩ · rw [reassoc_of% hl₁, ← reassoc_of% commι, eZ.hom_inv_id, comp_id] · rw [← cancel_mono eS.hom, assoc, assoc, commπ, eZ.inv_hom_id_assoc, hl₂] end variable [HasPushouts C] [∀ {X S : C} (πX : X ⟶ S), HasColimitsOfShape (Discrete (FunctorObjIndex f πX)) C] /-- The functor `Arrow C ⥤ Arrow C` that is constructed in order to apply the small object argument to a family of morphisms `f i : A i ⟶ B i`, see the introduction of the file `Mathlib/CategoryTheory/SmallObject/Construction.lean` -/ @[simps! obj map] noncomputable def functor : Arrow C ⥤ Arrow C where obj π := Arrow.mk (πFunctorObj f π.hom) map {π₁ π₂} τ := Arrow.homMk (functorMap f τ) τ.right map_id g := by ext · apply functorMap_id · dsimp map_comp {π₁ π₂ π₃} τ τ' := by ext · dsimp simp only [functorMap, Arrow.comp_left, Arrow.mk_left] ext ⟨i, t, b, w⟩ · simp · simp [ι_functorMapTgt_assoc f τ i t b w _ rfl _ rfl, ι_functorMapTgt_assoc f (τ ≫ τ') i t b w _ rfl _ rfl, ι_functorMapTgt_assoc f τ' i (t ≫ τ.left) (b ≫ τ.right) (by simp [reassoc_of% w]) (b ≫ τ.right ≫ τ'.right) (by simp) (t ≫ (τ ≫ τ').left) (by simp)] · dsimp /-- The canonical natural transformation `𝟭 (Arrow C) ⟶ functor f`. -/ @[simps app] noncomputable def ε : 𝟭 (Arrow C) ⟶ functor f where app π := Arrow.homMk (ιFunctorObj f π.hom) (𝟙 _) end end SmallObject end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/WellOrderInductionData.lean
import Mathlib.CategoryTheory.Category.Preorder import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.Types.Basic import Mathlib.Order.SuccPred.Limit /-! # Limits of inverse systems indexed by well-ordered types Given a functor `F : Jᵒᵖ ⥤ Type v` where `J` is a well-ordered type, we introduce a structure `F.WellOrderInductionData` which allows to show that the map `F.sections → F.obj (op ⊥)` is surjective. The data and properties in `F.WellOrderInductionData` consist of a section to the maps `F.obj (op (Order.succ j)) → F.obj (op j)` when `j` is not maximal, and, when `j` is limit, a section to the canonical map from `F.obj (op j)` to the type of compatible families of elements in `F.obj (op i)` for `i < j`. In other words, from `val₀ : F.obj (op ⊥)`, a term `d : F.WellOrderInductionData` allows the construction, by transfinite induction, of a section of `F` which restricts to `val₀`. -/ universe v u namespace CategoryTheory open Opposite namespace Functor variable {J : Type u} [LinearOrder J] [SuccOrder J] (F : Jᵒᵖ ⥤ Type v) /-- Given a functor `F : Jᵒᵖ ⥤ Type v` where `J` is a well-ordered type, this data allows to construct a section of `F` from an element in `F.obj (op ⊥)`, see `WellOrderInductionData.sectionsMk`. -/ structure WellOrderInductionData where /-- A section `F.obj (op j) → F.obj (op (Order.succ j))` to the restriction `F.obj (op (Order.succ j)) → F.obj (op j)` when `j` is not maximal. -/ succ (j : J) (hj : ¬IsMax j) (x : F.obj (op j)) : F.obj (op (Order.succ j)) map_succ (j : J) (hj : ¬IsMax j) (x : F.obj (op j)) : F.map (homOfLE (Order.le_succ j)).op (succ j hj x) = x /-- When `j` is a limit element, and `x` is a compatible family of elements in `F.obj (op i)` for all `i < j`, this is a lifting to `F.obj (op j)`. -/ lift (j : J) (hj : Order.IsSuccLimit j) (x : ((OrderHom.Subtype.val (· ∈ Set.Iio j)).monotone.functor.op ⋙ F).sections) : F.obj (op j) map_lift (j : J) (hj : Order.IsSuccLimit j) (x : ((OrderHom.Subtype.val (· ∈ Set.Iio j)).monotone.functor.op ⋙ F).sections) (i : J) (hi : i < j) : F.map (homOfLE hi.le).op (lift j hj x) = x.val (op ⟨i, hi⟩) namespace WellOrderInductionData variable {F} in /-- Given a functor `F : Jᵒᵖ ⥤ Type v` where `J` is a well-ordered type, this is a constructor for `F.WellOrderInductionData` which does not take data as inputs but proofs of the existence of certain elements. -/ noncomputable def ofExists (h₁ : ∀ (j : J) (_ : ¬IsMax j), Function.Surjective (F.map (homOfLE (Order.le_succ j)).op)) (h₂ : ∀ (j : J) (_ : Order.IsSuccLimit j) (x : ((OrderHom.Subtype.val (· ∈ Set.Iio j)).monotone.functor.op ⋙ F).sections), ∃ (y : F.obj (op j)), ∀ (i : J) (hi : i < j), F.map (homOfLE hi.le).op y = x.val (op ⟨i, hi⟩)) : F.WellOrderInductionData where succ j hj x := (h₁ j hj x).choose map_succ j hj x := (h₁ j hj x).choose_spec lift j hj x := (h₂ j hj x).choose map_lift j hj x := (h₂ j hj x).choose_spec variable {F} (d : F.WellOrderInductionData) [OrderBot J] /-- Given `d : F.WellOrderInductionData`, `val₀ : F.obj (op ⊥)` and `j : J`, this is the data of an element `val : F.obj (op j)` such that the induced compatible family of elements in all `F.obj (op i)` for `i ≤ j` is determined by `val₀` and the choice of "liftings" given by `d`. -/ structure Extension (val₀ : F.obj (op ⊥)) (j : J) where /-- An element in `F.obj (op j)`, which, by restriction, induces elements in `F.obj (op i)` for all `i ≤ j`. -/ val : F.obj (op j) map_zero : F.map (homOfLE bot_le).op val = val₀ map_succ (i : J) (hi : i < j) : F.map (homOfLE (Order.succ_le_of_lt hi)).op val = d.succ i (not_isMax_iff.2 ⟨_, hi⟩) (F.map (homOfLE hi.le).op val) map_limit (i : J) (hi : Order.IsSuccLimit i) (hij : i ≤ j) : F.map (homOfLE hij).op val = d.lift i hi { val := fun ⟨⟨k, hk⟩⟩ ↦ F.map (homOfLE (hk.le.trans hij)).op val property := fun f ↦ by dsimp rw [← FunctorToTypes.map_comp_apply] rfl } namespace Extension variable {d} {val₀ : F.obj (op ⊥)} /-- An element in `d.Extension val₀ j` induces an element in `d.Extension val₀ i` when `i ≤ j`. -/ @[simps] def ofLE {j : J} (e : d.Extension val₀ j) {i : J} (hij : i ≤ j) : d.Extension val₀ i where val := F.map (homOfLE hij).op e.val map_zero := by rw [← FunctorToTypes.map_comp_apply] exact e.map_zero map_succ k hk := by rw [← FunctorToTypes.map_comp_apply, ← FunctorToTypes.map_comp_apply, ← op_comp, ← op_comp, homOfLE_comp, homOfLE_comp, e.map_succ k (lt_of_lt_of_le hk hij)] map_limit k hk hki := by rw [← FunctorToTypes.map_comp_apply, ← op_comp, homOfLE_comp, e.map_limit k hk (hki.trans hij)] congr ext ⟨l, hl⟩ dsimp rw [← FunctorToTypes.map_comp_apply] rfl lemma val_injective {j : J} {e e' : d.Extension val₀ j} (h : e.val = e'.val) : e = e' := by cases e cases e' subst h rfl instance [WellFoundedLT J] (j : J) : Subsingleton (d.Extension val₀ j) := by induction j using SuccOrder.limitRecOn with | isMin i hi => obtain rfl : i = ⊥ := by simpa using hi refine Subsingleton.intro (fun e₁ e₂ ↦ val_injective ?_) have h₁ := e₁.map_zero have h₂ := e₂.map_zero simp only [homOfLE_refl, op_id, FunctorToTypes.map_id_apply] at h₁ h₂ rw [h₁, h₂] | succ i hi hi' => refine Subsingleton.intro (fun e₁ e₂ ↦ val_injective ?_) have h₁ := e₁.map_succ i (Order.lt_succ_of_not_isMax hi) have h₂ := e₂.map_succ i (Order.lt_succ_of_not_isMax hi) simp only [homOfLE_refl, op_id, FunctorToTypes.map_id_apply, homOfLE_leOfHom] at h₁ h₂ rw [h₁, h₂] congr exact congr_arg val (Subsingleton.elim (e₁.ofLE (Order.le_succ i)) (e₂.ofLE (Order.le_succ i))) | isSuccLimit i hi hi' => refine Subsingleton.intro (fun e₁ e₂ ↦ val_injective ?_) have h₁ := e₁.map_limit i hi (by rfl) have h₂ := e₂.map_limit i hi (by rfl) simp only [homOfLE_refl, op_id, FunctorToTypes.map_id_apply, OrderHom.Subtype.val_coe, comp_obj, op_obj, Monotone.functor_obj, homOfLE_leOfHom] at h₁ h₂ rw [h₁, h₂] congr ext ⟨⟨l, hl⟩⟩ have := hi' l hl exact congr_arg val (Subsingleton.elim (e₁.ofLE hl.le) (e₂.ofLE hl.le)) lemma compatibility [WellFoundedLT J] {j : J} (e : d.Extension val₀ j) {i : J} (e' : d.Extension val₀ i) (h : i ≤ j) : F.map (homOfLE h).op e.val = e'.val := by obtain rfl : e' = e.ofLE h := Subsingleton.elim _ _ rfl variable (d val₀) in /-- The obvious element in `d.Extension val₀ ⊥`. -/ @[simps] def zero : d.Extension val₀ ⊥ where val := val₀ map_zero := by simp map_succ i hi := by simp at hi map_limit i hi hij := by obtain rfl : i = ⊥ := by simpa using hij simpa using hi.not_isMin /-- The element in `d.Extension val₀ (Order.succ j)` obtained by extending an element in `d.Extension val₀ j` when `j` is not maximal. -/ def succ {j : J} (e : d.Extension val₀ j) (hj : ¬IsMax j) : d.Extension val₀ (Order.succ j) where val := d.succ j hj e.val map_zero := by simp only [← e.map_zero] conv_rhs => rw [← d.map_succ j hj e.val] rw [← FunctorToTypes.map_comp_apply] rfl map_succ i hi := by obtain hij | rfl := ((Order.lt_succ_iff_of_not_isMax hj).mp hi).lt_or_eq · rw [← homOfLE_comp ((Order.lt_succ_iff_of_not_isMax hj).mp hi) (Order.le_succ j), op_comp, FunctorToTypes.map_comp_apply, d.map_succ, ← e.map_succ i hij, ← homOfLE_comp (Order.succ_le_of_lt hij) (Order.le_succ j), op_comp, FunctorToTypes.map_comp_apply, d.map_succ] · simp only [homOfLE_refl, op_id, FunctorToTypes.map_id_apply, homOfLE_leOfHom, d.map_succ] map_limit i hi hij := by obtain hij | rfl := hij.lt_or_eq · have hij' : i ≤ j := (Order.lt_succ_iff_of_not_isMax hj).mp hij have := congr_arg (F.map (homOfLE hij').op) (d.map_succ j hj e.val) rw [e.map_limit i hi, ← FunctorToTypes.map_comp_apply, ← op_comp, homOfLE_comp] at this rw [this] congr ext ⟨⟨l, hl⟩⟩ dsimp conv_lhs => rw [← d.map_succ j hj e.val] rw [← FunctorToTypes.map_comp_apply] rfl · exfalso exact hj hi.isMax variable [WellFoundedLT J] /-- When `j` is a limit element, this is the extension to `d.Extension val₀ j` of a family of elements in `d.Extension val₀ i` for all `i < j`. -/ def limit (j : J) (hj : Order.IsSuccLimit j) (e : ∀ (i : J) (_ : i < j), d.Extension val₀ i) : d.Extension val₀ j where val := d.lift j hj { val := fun ⟨i, hi⟩ ↦ (e i hi).val property := fun f ↦ by apply compatibility } map_zero := by rw [d.map_lift _ _ _ _ (by simpa [bot_lt_iff_ne_bot] using hj.not_isMin)] simpa only [homOfLE_refl, op_id, FunctorToTypes.map_id_apply] using (e ⊥ (by simpa [bot_lt_iff_ne_bot] using hj.not_isMin)).map_zero map_succ i hi := by convert (e (Order.succ i) ((Order.IsSuccLimit.succ_lt_iff hj).mpr hi)).map_succ i (by simp only [Order.lt_succ_iff_not_isMax, not_isMax_iff] exact ⟨_, hi⟩) using 1 · dsimp rw [FunctorToTypes.map_id_apply, d.map_lift _ _ _ _ ((Order.IsSuccLimit.succ_lt_iff hj).mpr hi)] · congr rw [d.map_lift _ _ _ _ hi] symm apply compatibility map_limit i hi hij := by obtain hij' | rfl := hij.lt_or_eq · have := (e i hij').map_limit i hi (by rfl) dsimp at this ⊢ rw [FunctorToTypes.map_id_apply] at this rw [d.map_lift _ _ _ _ hij'] dsimp rw [this] congr dsimp ext ⟨⟨l, hl⟩⟩ rw [map_lift _ _ _ _ _ (hl.trans hij')] apply compatibility · dsimp rw [FunctorToTypes.map_id_apply] congr ext ⟨⟨l, hl⟩⟩ rw [d.map_lift _ _ _ _ hl] instance (j : J) : Nonempty (d.Extension val₀ j) := by induction j using SuccOrder.limitRecOn with | isMin i hi => obtain rfl : i = ⊥ := by simpa using hi exact ⟨zero d val₀⟩ | succ i hi hi' => exact ⟨hi'.some.succ hi⟩ | isSuccLimit i hi hi' => exact ⟨limit i hi (fun l hl ↦ (hi' l hl).some)⟩ noncomputable instance (j : J) : Unique (d.Extension val₀ j) := uniqueOfSubsingleton (Nonempty.some inferInstance) end Extension variable [WellFoundedLT J] /-- When `J` is a well-ordered type, `F : Jᵒᵖ ⥤ Type v`, and `d : F.WellOrderInductionData`, this is the section of `F` that is determined by `val₀ : F.obj (op ⊥)` -/ noncomputable def sectionsMk (val₀ : F.obj (op ⊥)) : F.sections where val j := (default : d.Extension val₀ j.unop).val property := fun f ↦ by apply Extension.compatibility lemma sectionsMk_val_op_bot (val₀ : F.obj (op ⊥)) : (d.sectionsMk val₀).val (op ⊥) = val₀ := by simpa using (default : d.Extension val₀ ⊥).map_zero include d in lemma surjective : Function.Surjective ((fun s ↦ s (op ⊥)) ∘ Subtype.val : F.sections → F.obj (op ⊥)) := fun val₀ ↦ ⟨d.sectionsMk val₀, d.sectionsMk_val_op_bot val₀⟩ end WellOrderInductionData end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/Basic.lean
import Mathlib.CategoryTheory.SmallObject.IsCardinalForSmallObjectArgument /-! # The small object argument Let `C` be a category. A class of morphisms `I : MorphismProperty C` permits the small object argument (typeclass `HasSmallObjectArgument.{w} I` where `w` is an auxiliary universe) if there exists a regular cardinal `κ : Cardinal.{w}` such that `IsCardinalForSmallObjectArgument I κ` holds. This technical condition is defined in the file `Mathlib/CategoryTheory/SmallObject/IsCardinalForSmallObjectArgument.lean`. It involves certain smallness conditions relative to `w`, the existence of certain colimits in `C`, and for each object `A` which is the source of a morphism in `I`, the `Hom(A, -)` functor (`coyoneda.obj (op A)`) should commute to transfinite compositions of pushouts of coproducts of morphisms in `I` (this condition is automatically satisfied for a suitable `κ` when `A` is a presentable object of `C`, see the file `Mathlib/CategoryTheory/Presentable/Basic.lean`). ## Main results Assuming `I` permits the small object argument, the two main results obtained in this file are: * the class `I.rlp.llp` of morphisms that have the left lifting property with respect to the maps that have the right lifting property with respect to `I` are exactly the retracts of transfinite compositions (indexed by a suitable well-ordered type `J`) of pushouts of coproducts of morphisms in `I`; * morphisms in `C` have a functorial factorization as a morphism in `I.rlp.llp` followed by a morphism in `I.rlp`. In the context of model categories, these results are known as Quillen's small object argument (originally for `J := ℕ`). Actually, the more general construction by transfinite induction already appeared in the proof of the existence of enough injectives in abelian categories with AB5 and a generator by Grothendieck, who then wrote that the "proof was essentially known". Indeed, the argument appeared in *Homological algebra* by Cartan and Eilenberg (p. 9-10) in the case of modules, and they mention that the result was initially obtained by Baer. ## Structure of the proof The main part in the proof is the construction of the functorial factorization. This involves a construction by transfinite induction. A general procedure for constructions by transfinite induction in categories (including the iteration of a functor) is done in the file `Mathlib/CategoryTheory/SmallObject/TransfiniteIteration.lean`. The factorization of the small object argument is obtained by doing a transfinite iteration of a specific functor `Arrow C ⥤ Arrow C` which is defined in the file `Mathlib/CategoryTheory/SmallObject/Construction.lean` (this definition involves coproducts and a pushout). These ingredients are combined in the file `Mathlib/CategoryTheory/SmallObject/IsCardinalForSmallObjectArgument.lean` where the main results are obtained under a `IsCardinalForSmallObjectArgument I κ` assumption. The fact that the left lifting property with respect to a class of morphisms is stable by transfinite compositions was obtained in the file `Mathlib/CategoryTheory/SmallObject/TransfiniteCompositionLifting.lean`. ## References - [Henri Cartan and Samuel Eilenberg, *Homological algebra*][cartan-eilenberg-1956] - [Alexander Grothendieck, *Sur quelques points d'algèbre homologique*][grothendieck-1957] - [Daniel G. Quillen, *Homotopical algebra*][Quillen1967] - https://ncatlab.org/nlab/show/small+object+argument -/ universe w v u namespace CategoryTheory open Category Limits SmallObject namespace MorphismProperty variable {C : Type u} [Category.{v} C] (I : MorphismProperty C) /-- A class of morphisms `I : MorphismProperty C` satisfies the property `HasSmallObjectArgument.{w} I` if it permits the small object argument, i.e. there exists a regular cardinal `κ : Cardinal.{w}` such that `IsCardinalForSmallObjectArgument I κ` holds. -/ class HasSmallObjectArgument : Prop where exists_cardinal : ∃ (κ : Cardinal.{w}) (_ : Fact κ.IsRegular) (_ : OrderBot κ.ord.toType), IsCardinalForSmallObjectArgument I κ variable [HasSmallObjectArgument.{w} I] /-- When `I : MorphismProperty C` permits the small object argument, this is a cardinal `κ` such that `IsCardinalForSmallObjectArgument I κ` holds. -/ noncomputable def smallObjectκ : Cardinal.{w} := (HasSmallObjectArgument.exists_cardinal (I := I)).choose local instance smallObjectκ_isRegular : Fact I.smallObjectκ.IsRegular := HasSmallObjectArgument.exists_cardinal.choose_spec.choose noncomputable instance : OrderBot I.smallObjectκ.ord.toType := HasSmallObjectArgument.exists_cardinal.choose_spec.choose_spec.choose instance isCardinalForSmallObjectArgument_smallObjectκ : IsCardinalForSmallObjectArgument.{w} I I.smallObjectκ := HasSmallObjectArgument.exists_cardinal.choose_spec.choose_spec.choose_spec instance : HasFunctorialFactorization I.rlp.llp I.rlp := hasFunctorialFactorization I I.smallObjectκ /-- If `I : MorphismProperty C` permits the small object argument, then the class of morphisms that have the left lifting property with respect to the maps that have the right lifting property with respect to `I` are exactly the retracts of transfinite compositions (indexed by `I.smallObjectκ.ord.toType`) of pushouts of coproducts of morphisms in `C`. -/ lemma llp_rlp_of_hasSmallObjectArgument' : I.rlp.llp = (transfiniteCompositionsOfShape (coproducts.{w} I).pushouts I.smallObjectκ.ord.toType).retracts := llp_rlp_of_isCardinalForSmallObjectArgument' I I.smallObjectκ /-- If `I : MorphismProperty C` permits the small object argument, then the class of morphisms that have the left lifting property with respect to the maps that have the right lifting property with respect to `I` are exactly the retracts of transfinite compositions of pushouts of coproducts of morphisms in `C`. -/ lemma llp_rlp_of_hasSmallObjectArgument : I.rlp.llp = (transfiniteCompositions.{w} (coproducts.{w} I).pushouts).retracts := llp_rlp_of_isCardinalForSmallObjectArgument I I.smallObjectκ end MorphismProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/IsCardinalForSmallObjectArgument.lean
import Mathlib.CategoryTheory.SmallObject.Construction import Mathlib.CategoryTheory.SmallObject.TransfiniteIteration import Mathlib.CategoryTheory.SmallObject.TransfiniteCompositionLifting import Mathlib.CategoryTheory.MorphismProperty.IsSmall import Mathlib.AlgebraicTopology.RelativeCellComplex.Basic import Mathlib.SetTheory.Cardinal.Regular /-! # Cardinals that are suitable for the small object argument In this file, given a class of morphisms `I : MorphismProperty C` and a regular cardinal `κ : Cardinal.{w}`, we define a typeclass `IsCardinalForSmallObjectArgument I κ` which requires certain smallness properties (`I` is `w`-small, `C` is locally `w`-small), the existence of certain colimits (pushouts, coproducts of size `w`, and the condition `HasIterationOfShape κ.ord.toType C` about the existence of colimits indexed by limit ordinal smaller than or equal to `κ.ord`), and the technical assumption that if `A` is the a morphism in `I`, then the functor `Hom(A, _)` should commute with the filtering colimits corresponding to relative `I`-cell complexes. (This last condition shall hold when `κ` is the successor of an infinite cardinal `c` such that all these objects `A` are `c`-presentable, see `Mathlib/CategoryTheory/Presentable/Basic.lean`.) Given `I : MorphismProperty C`, we shall say that `I` permits the small object argument if there exists `κ` such that `IsCardinalForSmallObjectArgument I κ` holds. See the file `Mathlib/CategoryTheory/SmallObject/Basic.lean` for the definition of this typeclass `HasSmallObjectArgument` and an outline of the proof. ## Main results Assuming `IsCardinalForSmallObjectArgument I κ`, any morphism `f : X ⟶ Y` is factored as `ιObj I κ f ≫ πObj I κ f = f`. It is shown that `ιObj I κ f` is a relative `I`-cell complex (see `SmallObject.relativeCellComplexιObj`) and that `πObj I κ f` has the right lifting property with respect to `I` (see `SmallObject.rlp_πObj`). This construction is obtained by iterating to the power `κ.ord.toType` the functor `Arrow C ⥤ Arrow C` defined in the file `Mathlib/CategoryTheory/SmallObject/Construction.lean`. This factorization is functorial in `f` and gives the property `HasFunctorialFactorization I.rlp.llp I.rlp`. Finally, the lemma `llp_rlp_of_isCardinalForSmallObjectArgument` (and its primed version) shows that the morphisms in `I.rlp.llp` are exactly the retracts of the transfinite compositions (of shape `κ.ord.toType`) of pushouts of coproducts of morphisms in `I`. ## References - https://ncatlab.org/nlab/show/small+object+argument -/ universe w v v' u u' namespace CategoryTheory open Category HomotopicalAlgebra Limits SmallObject variable {C : Type u} [Category.{v} C] (I : MorphismProperty C) namespace MorphismProperty /-- Given `I : MorphismProperty C` and a regular cardinal `κ : Cardinal.{w}`, this property asserts the technical conditions which allow to proceed to the small object argument by doing a construction by transfinite induction indexed by the well-ordered type `κ.ord.toType`. -/ class IsCardinalForSmallObjectArgument (κ : Cardinal.{w}) [Fact κ.IsRegular] [OrderBot κ.ord.toType] : Prop where isSmall : IsSmall.{w} I := by infer_instance locallySmall : LocallySmall.{w} C := by infer_instance hasPushouts : HasPushouts C := by infer_instance hasCoproducts : HasCoproducts.{w} C := by infer_instance hasIterationOfShape : HasIterationOfShape κ.ord.toType C := by infer_instance preservesColimit {A B X Y : C} (i : A ⟶ B) (_ : I i) (f : X ⟶ Y) (hf : RelativeCellComplex.{w} (fun (_ : κ.ord.toType) ↦ I.homFamily) f) : PreservesColimit hf.F (coyoneda.obj (Opposite.op A)) end MorphismProperty namespace SmallObject open MorphismProperty variable (κ : Cardinal.{w}) [Fact κ.IsRegular] [OrderBot κ.ord.toType] [I.IsCardinalForSmallObjectArgument κ] include I κ lemma isSmall : IsSmall.{w} I := IsCardinalForSmallObjectArgument.isSmall κ lemma locallySmall : LocallySmall.{w} C := IsCardinalForSmallObjectArgument.locallySmall I κ lemma hasIterationOfShape : HasIterationOfShape κ.ord.toType C := IsCardinalForSmallObjectArgument.hasIterationOfShape I lemma hasPushouts : HasPushouts C := IsCardinalForSmallObjectArgument.hasPushouts I κ lemma hasCoproducts : HasCoproducts.{w} C := IsCardinalForSmallObjectArgument.hasCoproducts I κ lemma preservesColimit {A B X Y : C} (i : A ⟶ B) (hi : I i) (f : X ⟶ Y) (hf : RelativeCellComplex.{w} (fun (_ : κ.ord.toType) ↦ I.homFamily) f) : PreservesColimit hf.F (coyoneda.obj (Opposite.op A)) := IsCardinalForSmallObjectArgument.preservesColimit i hi f hf lemma hasColimitsOfShape_discrete (X Y : C) (p : X ⟶ Y) : HasColimitsOfShape (Discrete (FunctorObjIndex I.homFamily p)) C := by haveI := locallySmall I κ haveI := isSmall I κ haveI := hasCoproducts I κ exact hasColimitsOfShape_of_equivalence (Discrete.equivalence (equivShrink.{w} _)).symm /-- The successor structure on `Arrow C ⥤ Arrow C` corresponding to the iterations of the natural transformation `ε : 𝟭 (Arrow C) ⟶ SmallObject.functor I.homFamily` (see the file `SmallObject.Construction`). -/ noncomputable def succStruct : SuccStruct (Arrow C ⥤ Arrow C) := haveI := hasColimitsOfShape_discrete I κ haveI := hasPushouts I κ SuccStruct.ofNatTrans (ε I.homFamily) /-- For the successor structure `succStruct I κ` on `Arrow C ⥤ Arrow C`, the morphism from an object to its successor induces morphisms in `C` which consists in attaching `I`-cells. -/ noncomputable def attachCellsOfSuccStructProp {F G : Arrow C ⥤ Arrow C} {φ : F ⟶ G} (h : (succStruct I κ).prop φ) (f : Arrow C) : AttachCells.{w} I.homFamily (φ.app f).left := haveI := locallySmall I κ haveI := isSmall I κ haveI := hasColimitsOfShape_discrete I κ haveI := hasPushouts I κ AttachCells.ofArrowIso (attachCellsιFunctorObjOfSmall _ _) ((Functor.mapArrow ((evaluation _ _).obj f ⋙ Arrow.leftFunc)).mapIso h.arrowIso.symm) /-- The class of morphisms in `Arrow C` which on the left side are pushouts of coproducts of morphisms in `I`, and which are isomorphisms on the right side. -/ def propArrow : MorphismProperty (Arrow C) := fun _ _ f ↦ (coproducts.{w} I).pushouts f.left ∧ (isomorphisms C) f.right lemma succStruct_prop_le_propArrow : (succStruct I κ).prop ≤ (propArrow.{w} I).functorCategory (Arrow C) := by haveI := locallySmall I κ haveI := isSmall I κ haveI := hasColimitsOfShape_discrete I κ haveI := hasPushouts I κ intro _ _ _ ⟨F⟩ f constructor · nth_rw 1 [← I.ofHoms_homFamily] apply pushouts_mk _ (functorObj_isPushout I.homFamily (F.obj f).hom) exact coproducts_of_small _ _ (colimitsOfShape_colimMap _ (by rintro ⟨j⟩; constructor)) · rw [MorphismProperty.isomorphisms.iff] dsimp [succStruct] infer_instance /-- The functor `κ.ord.toType ⥤ Arrow C ⥤ Arrow C` corresponding to the iterations of the successor structure `succStruct I κ`. -/ noncomputable def iterationFunctor : κ.ord.toType ⥤ Arrow C ⥤ Arrow C := haveI := hasIterationOfShape I κ (succStruct I κ).iterationFunctor κ.ord.toType /-- The colimit of `iterationFunctor I κ`. -/ noncomputable def iteration : Arrow C ⥤ Arrow C := haveI := hasIterationOfShape I κ (succStruct I κ).iteration κ.ord.toType /-- The natural "inclusion" `𝟭 (Arrow C) ⟶ iteration I κ`. -/ noncomputable def ιIteration : 𝟭 _ ⟶ iteration I κ := haveI := hasIterationOfShape I κ (succStruct I κ).ιIteration κ.ord.toType /-- The morphism `ιIteration I κ` is a transfinite composition of shape `κ.ord.toType` of morphisms satisfying `(succStruct I κ).prop`. -/ noncomputable def transfiniteCompositionOfShapeSuccStructPropιIteration : (succStruct I κ).prop.TransfiniteCompositionOfShape κ.ord.toType (ιIteration I κ) := haveI := hasIterationOfShape I κ (succStruct I κ).transfiniteCompositionOfShapeιIteration κ.ord.toType @[simp] lemma transfiniteCompositionOfShapeSuccStructPropιIteration_F : (transfiniteCompositionOfShapeSuccStructPropιIteration I κ).F = iterationFunctor I κ := rfl /-- For any `f : Arrow C`, the map `((ιIteration I κ).app f).right` is a transfinite composition of isomorphisms. -/ noncomputable def transfiniteCompositionOfShapeιIterationAppRight (f : Arrow C) : (isomorphisms C).TransfiniteCompositionOfShape κ.ord.toType ((ιIteration I κ).app f).right := haveI := hasIterationOfShape I κ let h := transfiniteCompositionOfShapeSuccStructPropιIteration I κ { toTransfiniteCompositionOfShape := h.toTransfiniteCompositionOfShape.map ((evaluation _ _).obj f ⋙ Arrow.rightFunc) map_mem j hj := ((succStruct_prop_le_propArrow I κ _ (h.map_mem j hj)) f).2 } instance (f : Arrow C) : IsIso ((ιIteration I κ).app f).right := (transfiniteCompositionOfShapeιIterationAppRight I κ f).isIso instance {j₁ j₂ : κ.ord.toType} (φ : j₁ ⟶ j₂) (f : Arrow C) : IsIso (((iterationFunctor I κ).map φ).app f).right := inferInstanceAs (IsIso ((transfiniteCompositionOfShapeιIterationAppRight I κ f).F.map φ)) /-- For any `f : Arrow C`, the object `((iteration I κ).obj f).right` identifies to `f.right`. -/ @[simps! hom] noncomputable def iterationObjRightIso (f : Arrow C) : f.right ≅ ((iteration I κ).obj f).right := asIso ((ιIteration I κ).app f).right /-- For any `f : Arrow C` and `j : κ.ord.toType`, the object `(((iterationFunctor I κ).obj j).obj f).right` identifies to `f.right`. -/ noncomputable def iterationFunctorObjObjRightIso (f : Arrow C) (j : κ.ord.toType) : (((iterationFunctor I κ).obj j).obj f).right ≅ f.right := asIso ((transfiniteCompositionOfShapeιIterationAppRight I κ f).incl.app j) ≪≫ (iterationObjRightIso I κ f).symm @[reassoc (attr := simp)] lemma iterationFunctorObjObjRightIso_ιIteration_app_right (f : Arrow C) (j : κ.ord.toType) : (iterationFunctorObjObjRightIso I κ f j).hom ≫ ((ιIteration I κ).app f).right = (transfiniteCompositionOfShapeιIterationAppRight I κ f).incl.app j := by simp [iterationFunctorObjObjRightIso, iterationObjRightIso] lemma prop_iterationFunctor_map_succ (j : κ.ord.toType) : (succStruct I κ).prop ((iterationFunctor I κ).map (homOfLE (Order.le_succ j))) := by have := hasIterationOfShape I κ have := Cardinal.noMaxOrder (Fact.elim inferInstance : κ.IsRegular).aleph0_le exact (succStruct I κ).prop_iterationFunctor_map_succ j (not_isMax j) /-- For any `f : Arrow C` and `j : κ.ord.toType`, the morphism `((iterationFunctor I κ).map (homOfLE (Order.le_succ j))).app f` identifies to a morphism given by `SmallObject.ε I.homFamily`. -/ noncomputable def iterationFunctorMapSuccAppArrowIso (f : Arrow C) (j : κ.ord.toType) : letI := hasColimitsOfShape_discrete I κ letI := hasPushouts I κ Arrow.mk (((iterationFunctor I κ).map (homOfLE (Order.le_succ j))).app f) ≅ (ε I.homFamily).app (((iterationFunctor I κ).obj j).obj f) := have := hasIterationOfShape I κ have := Cardinal.noMaxOrder (Fact.elim inferInstance : κ.IsRegular).aleph0_le Arrow.isoMk (Iso.refl _) (((evaluation _ _).obj f).mapIso ((succStruct I κ).iterationFunctorObjSuccIso j (not_isMax j))) (by have this := NatTrans.congr_app ((succStruct I κ).iterationFunctor_map_succ j (not_isMax j)) f dsimp at this dsimp [iterationFunctor] rw [id_comp, this, assoc, Iso.inv_hom_id_app, comp_id] dsimp [succStruct]) @[simp] lemma iterationFunctorMapSuccAppArrowIso_hom_left (f : Arrow C) (j : κ.ord.toType) : (iterationFunctorMapSuccAppArrowIso I κ f j).hom.left = 𝟙 _ := rfl @[reassoc (attr := simp)] lemma iterationFunctorMapSuccAppArrowIso_hom_right_right_comp (f : Arrow C) (j : κ.ord.toType) : (iterationFunctorMapSuccAppArrowIso I κ f j).hom.right.right ≫ (((iterationFunctor I κ).map (homOfLE (Order.le_succ j))).app f).right = 𝟙 _ := by have := Arrow.rightFunc.congr_map ((iterationFunctorMapSuccAppArrowIso I κ f j).hom.w) dsimp at this ⊢ rw [← cancel_epi (((iterationFunctor I κ).map (homOfLE (Order.le_succ j))).app f).right, ← reassoc_of% this, comp_id] section variable {X Y : C} (f : X ⟶ Y) /-- The intermediate object in the factorization given by the small object argument. -/ noncomputable def obj : C := ((iteration I κ).obj (Arrow.mk f)).left /-- The "inclusion" morphism in the factorization given by the small object argument. -/ noncomputable def ιObj : X ⟶ obj I κ f := ((ιIteration I κ).app (Arrow.mk f)).left /-- The "projection" morphism in the factorization given by the small object argument. -/ noncomputable def πObj : obj I κ f ⟶ Y := ((iteration I κ).obj (Arrow.mk f)).hom ≫ inv ((ιIteration I κ).app f).right @[reassoc (attr := simp)] lemma πObj_ιIteration_app_right : πObj I κ f ≫ ((ιIteration I κ).app f).right = ((iteration I κ).obj (Arrow.mk f)).hom := by simp [πObj] @[reassoc (attr := simp)] lemma ιObj_πObj : ιObj I κ f ≫ πObj I κ f = f := by simp [ιObj, πObj] /-- The morphism `ιObj I κ f` is a relative `I`-cell complex. -/ noncomputable def relativeCellComplexιObj : RelativeCellComplex.{w} (fun (_ : κ.ord.toType) ↦ I.homFamily) (ιObj I κ f) := by have := hasIterationOfShape I κ let h := transfiniteCompositionOfShapeSuccStructPropιIteration I κ exact { toTransfiniteCompositionOfShape := h.toTransfiniteCompositionOfShape.map ((evaluation _ _).obj f ⋙ Arrow.leftFunc) attachCells j hj := attachCellsOfSuccStructProp I κ (h.map_mem j hj) f } lemma transfiniteCompositionsOfShape_ιObj : (coproducts.{w} I).pushouts.transfiniteCompositionsOfShape κ.ord.toType (ιObj I κ f) := ⟨((relativeCellComplexιObj I κ f).transfiniteCompositionOfShape).ofLE (by simp)⟩ lemma llp_rlp_ιObj : I.rlp.llp (ιObj I κ f) := by apply I.transfiniteCompositionsOfShape_pushouts_coproducts_le_llp_rlp κ.ord.toType apply transfiniteCompositionsOfShape_ιObj /-- When `ιObj I κ f` is considered as a relative `I`-cell complex, the object at the `j`th step is obtained by applying the construction `SmallObject.functorObj`. -/ noncomputable def relativeCellComplexιObjFObjSuccIso (j : κ.ord.toType) : letI := hasColimitsOfShape_discrete I κ letI := hasPushouts I κ (relativeCellComplexιObj I κ f).F.obj (Order.succ j) ≅ functorObj I.homFamily (((iterationFunctor I κ).obj j).obj (Arrow.mk f)).hom := (Arrow.rightFunc ⋙ Arrow.leftFunc).mapIso (iterationFunctorMapSuccAppArrowIso I κ f j) lemma ιFunctorObj_eq (j : κ.ord.toType) : letI := hasColimitsOfShape_discrete I κ letI := hasPushouts I κ ιFunctorObj I.homFamily (((iterationFunctor I κ).obj j).obj (Arrow.mk f)).hom = (relativeCellComplexιObj I κ f).F.map (homOfLE (Order.le_succ j)) ≫ (relativeCellComplexιObjFObjSuccIso I κ f j).hom := by simpa using Arrow.leftFunc.congr_map (iterationFunctorMapSuccAppArrowIso I κ f j).hom.w lemma πFunctorObj_eq (j : κ.ord.toType) : letI := hasColimitsOfShape_discrete I κ letI := hasPushouts I κ πFunctorObj I.homFamily (((iterationFunctor I κ).obj j).obj (Arrow.mk f)).hom = (relativeCellComplexιObjFObjSuccIso I κ f j).inv ≫ (relativeCellComplexιObj I κ f).incl.app (Order.succ j) ≫ πObj I κ f ≫ (iterationFunctorObjObjRightIso I κ (Arrow.mk f) j).inv := by have h₁ := (iterationFunctorMapSuccAppArrowIso I κ f j).hom.right.w have h₂ := (transfiniteCompositionOfShapeSuccStructPropιIteration I κ).incl.naturality (homOfLE (Order.le_succ j)) dsimp at h₁ h₂ rw [comp_id] at h₂ rw [← cancel_mono (iterationFunctorObjObjRightIso I κ (Arrow.mk f) j).hom, ← cancel_mono ((ιIteration I κ).app f).right, assoc, assoc, assoc, assoc, assoc, Iso.inv_hom_id_assoc, πObj_ιIteration_app_right, iterationFunctorObjObjRightIso_ιIteration_app_right, ← cancel_epi (relativeCellComplexιObjFObjSuccIso I κ f j).hom, Iso.hom_inv_id_assoc] dsimp [relativeCellComplexιObjFObjSuccIso, relativeCellComplexιObj, transfiniteCompositionOfShapeιIterationAppRight] simp only [reassoc_of% h₁, comp_id, comp_id, Arrow.w_mk_right, ← h₂, NatTrans.comp_app, Arrow.comp_right, iterationFunctorMapSuccAppArrowIso_hom_right_right_comp_assoc] lemma hasRightLiftingProperty_πObj {A B : C} (i : A ⟶ B) (hi : I i) (f : X ⟶ Y) : HasLiftingProperty i (πObj I κ f) := ⟨by haveI := hasColimitsOfShape_discrete I κ haveI := hasPushouts I κ haveI := preservesColimit I κ i hi _ (relativeCellComplexιObj I κ f) intro g b sq obtain ⟨j, t, ht⟩ := Types.jointly_surjective _ (isColimitOfPreserves (coyoneda.obj (Opposite.op A)) (relativeCellComplexιObj I κ f).isColimit) g dsimp at g b sq t ht obtain ⟨l, hl₁, hl₂⟩ := ιFunctorObj_extension' I.homFamily ((relativeCellComplexιObj I κ f).incl.app j ≫ πObj I κ f) ((relativeCellComplexιObj I κ f).F.map (homOfLE (Order.le_succ j))) ((relativeCellComplexιObj I κ f).incl.app (Order.succ j) ≫ πObj I κ f) (by simp) (Iso.refl _) (iterationFunctorObjObjRightIso I κ (Arrow.mk f) j).symm (relativeCellComplexιObjFObjSuccIso I κ f j) (by dsimp; rw [ιFunctorObj_eq, id_comp]) (by dsimp; rw [πFunctorObj_eq, assoc, Iso.hom_inv_id_assoc]) (i := ⟨i, hi⟩) t b (by rw [reassoc_of% ht, sq.w]; dsimp) dsimp at hl₁ exact ⟨⟨{ l := l ≫ (relativeCellComplexιObj I κ f).incl.app (Order.succ j) fac_left := by simp [reassoc_of% hl₁, ← ht] fac_right := by rw [assoc, hl₂] }⟩⟩⟩ lemma rlp_πObj : I.rlp (πObj I κ f) := fun _ _ _ hi ↦ hasRightLiftingProperty_πObj _ _ _ hi _ end /-- The functoriality of the intermediate object in the factorization of the small object argument. -/ noncomputable def objMap {f g : Arrow C} (φ : f ⟶ g) : obj I κ f.hom ⟶ obj I κ g.hom := ((iteration I κ).map φ).left @[simp] lemma objMap_id (f : Arrow C) : objMap I κ (𝟙 f) = 𝟙 _ := by simp only [objMap, Functor.map_id] rfl @[reassoc, simp] lemma objMap_comp {f g h : Arrow C} (φ : f ⟶ g) (ψ : g ⟶ h) : objMap I κ (φ ≫ ψ) = objMap I κ φ ≫ objMap I κ ψ := by simp only [objMap, Functor.map_comp] rfl @[reassoc (attr := simp)] lemma ιObj_naturality {f g : Arrow C} (φ : f ⟶ g) : ιObj I κ f.hom ≫ objMap I κ φ = φ.left ≫ ιObj I κ g.hom := Arrow.leftFunc.congr_map ((ιIteration I κ).naturality φ).symm @[reassoc (attr := simp)] lemma πObj_naturality {f g : Arrow C} (φ : f ⟶ g) : objMap I κ φ ≫ πObj I κ g.hom = πObj I κ f.hom ≫ φ.right := by let e₁ := asIso ((ιIteration I κ).app (Arrow.mk f.hom)).right let e₂ := asIso ((ιIteration I κ).app (Arrow.mk g.hom)).right change _ ≫ _ ≫ e₂.inv = (_ ≫ e₁.inv) ≫ _ have h₁ := ((iteration I κ).map φ).w =≫ e₂.inv have h₂ : φ.right ≫ e₂.hom = e₁.hom ≫ ((iteration I κ).map φ).right := ((Functor.whiskerRight (ιIteration I κ) Arrow.rightFunc).naturality φ) dsimp at h₁ rw [assoc] at h₁ apply h₁.trans simp only [← cancel_mono e₂.hom, assoc, e₂.inv_hom_id, h₂, e₁.inv_hom_id_assoc] rw [← assoc] apply comp_id /-- The functorial factorization `ιObj I κ f ≫ πObj I κ f.hom = f` with `ιObj I κ f` in `I.rlp.llp` and `πObj I κ f.hom` in `I.rlp`. -/ @[simps] noncomputable def functorialFactorizationData : FunctorialFactorizationData I.rlp.llp I.rlp where Z := { obj f := obj I κ f.hom map φ := objMap I κ φ } i := { app f := ιObj I κ f.hom } p := { app f := πObj I κ f.hom } hi f := llp_rlp_ιObj I κ f.hom hp f := rlp_πObj I κ f.hom lemma hasFunctorialFactorization : HasFunctorialFactorization I.rlp.llp I.rlp where nonempty_functorialFactorizationData := ⟨functorialFactorizationData I κ⟩ /-- If `κ` is a suitable cardinal for the small object argument for `I : MorphismProperty C`, then the class `I.rlp.llp` is exactly the class of morphisms that are retracts of transfinite compositions (of shape `κ.ord.toType`) of pushouts of coproducts of maps in `I`. -/ lemma llp_rlp_of_isCardinalForSmallObjectArgument' : I.rlp.llp = (transfiniteCompositionsOfShape (coproducts.{w} I).pushouts κ.ord.toType).retracts := by refine le_antisymm ?_ (retracts_transfiniteCompositionsOfShape_pushouts_coproducts_le_llp_rlp I κ.ord.toType) intro X Y f hf have sq : CommSq (ιObj I κ f) f (πObj I κ f) (𝟙 _) := ⟨by simp⟩ have := hf _ (rlp_πObj I κ f) refine ⟨_, _, _, ?_, transfiniteCompositionsOfShape_ιObj I κ f⟩ exact { i := Arrow.homMk (𝟙 _) sq.lift r := Arrow.homMk (𝟙 _) (πObj I κ f) } /-- If `κ` is a suitable cardinal for the small object argument for `I : MorphismProperty C`, then the class `I.rlp.llp` is exactly the class of morphisms that are retracts of transfinite compositions of pushouts of coproducts of maps in `I`. -/ lemma llp_rlp_of_isCardinalForSmallObjectArgument : I.rlp.llp = (transfiniteCompositions.{w} (coproducts.{w} I).pushouts).retracts := by refine le_antisymm ?_ (retracts_transfiniteComposition_pushouts_coproducts_le_llp_rlp I) rw [llp_rlp_of_isCardinalForSmallObjectArgument' I κ] apply retracts_monotone apply transfiniteCompositionsOfShape_le_transfiniteCompositions end SmallObject end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/Iteration/FunctorOfCocone.lean
import Mathlib.CategoryTheory.SmallObject.Iteration.Basic /-! # The functor from `Set.Iic j` deduced from a cocone Given a functor `F : Set.Iio j ⥤ C` and `c : Cocone F`, we define an extension of `F` as a functor `Set.Iic j ⥤ C` for which the top element is mapped to `c.pt`. -/ universe u namespace CategoryTheory open Category Limits namespace SmallObject namespace SuccStruct variable {C : Type*} [Category C] {J : Type u} [LinearOrder J] {j : J} {F : Set.Iio j ⥤ C} (c : Cocone F) namespace ofCocone /-- Auxiliary definition for `ofCocone`. -/ def obj (i : J) : C := if hi : i < j then F.obj ⟨i, hi⟩ else c.pt /-- Auxiliary definition for `ofCocone`. -/ def objIso (i : J) (hi : i < j) : obj c i ≅ F.obj ⟨i, hi⟩ := eqToIso (dif_pos hi) /-- Auxiliary definition for `ofCocone`. -/ def objIsoPt : obj c j ≅ c.pt := eqToIso (dif_neg (by simp)) /-- Auxiliary definition for `ofCocone`. -/ def map (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : obj c i₁ ⟶ obj c i₂ := if h₂ : i₂ < j then (objIso c i₁ (lt_of_le_of_lt hi h₂)).hom ≫ F.map (homOfLE hi) ≫ (objIso c i₂ h₂).inv else have h₂' : i₂ = j := le_antisymm hi₂ (by simpa using h₂) if h₁ : i₁ < j then (objIso c i₁ h₁).hom ≫ c.ι.app ⟨i₁, h₁⟩ ≫ (objIsoPt c).inv ≫ eqToHom (by subst h₂'; rfl) else have h₁' : i₁ = j := le_antisymm (hi.trans hi₂) (by simpa using h₁) eqToHom (by subst h₁' h₂'; rfl) lemma map_id (i : J) (hi : i ≤ j) : map c i i (by rfl) hi = 𝟙 _:= by dsimp [map] grind lemma map_comp (i₁ i₂ i₃ : J) (hi : i₁ ≤ i₂) (hi' : i₂ ≤ i₃) (hi₃ : i₃ ≤ j) : map c i₁ i₃ (hi.trans hi') hi₃ = map c i₁ i₂ hi (hi'.trans hi₃) ≫ map c i₂ i₃ hi' hi₃ := by obtain hi₁₂ | rfl := hi.lt_or_eq · obtain hi₂₃ | rfl := hi'.lt_or_eq · dsimp [map] obtain hi₃' | rfl := hi₃.lt_or_eq · rw [dif_pos hi₃', dif_pos (hi₂₃.trans hi₃'), dif_pos hi₃', assoc, assoc, Iso.inv_hom_id_assoc, ← Functor.map_comp_assoc, homOfLE_comp] · rw [dif_neg (by simp), dif_pos (hi₁₂.trans hi₂₃), dif_pos hi₂₃, dif_neg (by simp), dif_pos hi₂₃, eqToHom_refl, comp_id, assoc, assoc, Iso.inv_hom_id_assoc, Cocone.w_assoc] · rw [map_id, comp_id] · rw [map_id, id_comp] end ofCocone /-- Given a functor `F : Set.Iio j ⥤ C` and a cocone `c : Cocone F`, where `j : J` and `J` is linearly ordered, this is the functor `Set.Iic j ⥤ C` which extends `F` and sends the top element to `c.pt`. -/ def ofCocone : Set.Iic j ⥤ C where obj i := ofCocone.obj c i.1 map {_ j} f := ofCocone.map c _ _ (leOfHom f) j.2 map_id i := ofCocone.map_id _ _ i.2 map_comp {_ _ i₃} _ _ := ofCocone.map_comp _ _ _ _ _ _ i₃.2 lemma ofCocone_obj_eq (i : J) (hi : i < j) : (ofCocone c).obj ⟨i, hi.le⟩ = F.obj ⟨i, hi⟩ := dif_pos hi /-- The isomorphism `(ofCocone c).obj ⟨i, _⟩ ≅ F.obj ⟨i, _⟩` when `i < j`. -/ def ofCoconeObjIso (i : J) (hi : i < j) : (ofCocone c).obj ⟨i, hi.le⟩ ≅ F.obj ⟨i, hi⟩ := ofCocone.objIso c _ _ lemma ofCocone_obj_eq_pt : (ofCocone c).obj ⟨j, by simp⟩ = c.pt := dif_neg (by simp) /-- The isomorphism `(ofCocone c).obj ⟨j, _⟩ ≅ c.pt`. -/ def ofCoconeObjIsoPt : (ofCocone c).obj ⟨j, by simp⟩ ≅ c.pt := ofCocone.objIsoPt c lemma ofCocone_map_to_top (i : J) (hi : i < j) : (ofCocone c).map (homOfLE hi.le) = (ofCoconeObjIso c i hi).hom ≫ c.ι.app ⟨i, hi⟩ ≫ (ofCoconeObjIsoPt c).inv := by dsimp [ofCocone, ofCocone.map, ofCoconeObjIso, ofCoconeObjIsoPt] rw [dif_neg (by simp), dif_pos hi, comp_id] @[reassoc] lemma ofCocone_map (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ < j) : (ofCocone c).map (homOfLE hi : ⟨i₁, hi.trans hi₂.le⟩ ⟶ ⟨i₂, hi₂.le⟩) = (ofCoconeObjIso c i₁ (lt_of_le_of_lt hi hi₂)).hom ≫ F.map (homOfLE hi) ≫ (ofCoconeObjIso c i₂ hi₂).inv := by dsimp [ofCocone, ofCoconeObjIso, ofCocone.map] rw [dif_pos hi₂] @[reassoc] lemma ofCoconeObjIso_hom_naturality (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ < j) : (ofCocone c).map (homOfLE hi : ⟨i₁, hi.trans hi₂.le⟩ ⟶ ⟨i₂, hi₂.le⟩) ≫ (ofCoconeObjIso c i₂ hi₂).hom = (ofCoconeObjIso c i₁ (lt_of_le_of_lt hi hi₂)).hom ≫ F.map (homOfLE hi) := by rw [ofCocone_map c i₁ i₂ hi hi₂, assoc, assoc, Iso.inv_hom_id, comp_id] /-- The isomorphism expressing that `ofCocone c` extends the functor `F` when `c : Cocone F`. -/ @[simps!] def restrictionLTOfCoconeIso : SmallObject.restrictionLT (ofCocone c) (Preorder.le_refl j) ≅ F := NatIso.ofComponents (fun ⟨i, hi⟩ ↦ ofCoconeObjIso c i hi) (by intros; apply ofCoconeObjIso_hom_naturality) variable {c} in /-- If `c` is a colimit cocone, then so is `coconeOfLE (ofCocone c) (Preorder.le_refl j)`. -/ def isColimitCoconeOfLEOfCocone (hc : IsColimit c) : IsColimit (coconeOfLE (ofCocone c) (Preorder.le_refl j)) := (IsColimit.precomposeInvEquiv (restrictionLTOfCoconeIso c) _).1 (IsColimit.ofIsoColimit hc (Cocones.ext (ofCoconeObjIsoPt c).symm (fun ⟨i, hi⟩ ↦ by dsimp rw [ofCocone_map_to_top _ _ hi, Iso.inv_hom_id_assoc]))) lemma arrowMap_ofCocone (i₁ i₂ : J) (h₁₂ : i₁ ≤ i₂) (h₂ : i₂ < j) : arrowMap (ofCocone c) i₁ i₂ h₁₂ h₂.le = Arrow.mk (F.map (homOfLE h₁₂ : ⟨i₁, lt_of_le_of_lt h₁₂ h₂⟩ ⟶ ⟨i₂, h₂⟩)) := Arrow.ext (ofCocone_obj_eq _ _ _) (ofCocone_obj_eq _ _ _) (ofCocone_map _ _ _ _ _) lemma arrowMap_ofCocone_to_top (i : J) (hi : i < j) : arrowMap (ofCocone c) i j hi.le (by simp) = Arrow.mk (c.ι.app ⟨i, hi⟩) := by rw [arrowMap, ofCocone_map_to_top _ _ hi] exact Arrow.ext (ofCocone_obj_eq _ _ _) (ofCocone_obj_eq_pt _) rfl end SuccStruct end SmallObject end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/Iteration/Nonempty.lean
import Mathlib.CategoryTheory.SmallObject.Iteration.Basic import Mathlib.CategoryTheory.SmallObject.Iteration.ExtendToSucc import Mathlib.CategoryTheory.SmallObject.Iteration.FunctorOfCocone /-! # Existence of the iteration of a successor structure Given `Φ : SuccStruct C`, we show by transfinite induction that for any element `j` in a well-ordered set `J`, the type `Φ.Iteration j` is nonempty. -/ universe u namespace CategoryTheory namespace SmallObject namespace SuccStruct open Category Limits variable {C : Type*} [Category C] (Φ : SuccStruct C) {J : Type u} [LinearOrder J] [OrderBot J] [SuccOrder J] [WellFoundedLT J] [HasIterationOfShape J C] namespace Iteration variable (J) in /-- The obvious term in `Φ.Iteration ε ⊥` that is given by `Φ.X₀`. -/ def mkOfBot : Φ.Iteration (⊥ : J) where F := (Functor.const _).obj Φ.X₀ obj_bot := rfl arrowSucc_eq _ h := by simp at h arrowMap_limit _ h₁ h₂ := (h₁.not_isMin (by simpa using h₂)).elim variable {Φ} open Functor in /-- When `j : J` is not maximal, this is the extension in `Φ.Iteration (Order.succ j)` of any `iter : Φ.Iteration j`. -/ noncomputable def mkOfSucc {j : J} (hj : ¬IsMax j) (iter : Φ.Iteration j) : Φ.Iteration (Order.succ j) where F := extendToSucc hj iter.F (Φ.toSucc _) obj_bot := by rw [extendToSucc_obj_eq _ _ _ _ bot_le, obj_bot] arrowSucc_eq i hi₁ := by rw [Order.lt_succ_iff_of_not_isMax hj] at hi₁ obtain hi₁ | rfl := hi₁.lt_or_eq · rw [arrowSucc_def, arrowMap_extendToSucc _ _ _ _ _ _ (Order.succ_le_of_lt hi₁), ← arrowSucc_def _ _ hi₁, iter.arrowSucc_eq i hi₁, extendToSucc_obj_eq hj iter.F (Φ.toSucc _) i hi₁.le] · rw [arrowSucc_extendToSucc, toSuccArrow, extendToSucc_obj_eq hj iter.F (Φ.toSucc _) i] arrowMap_limit i hi hij k hk := by have hij' := (Order.IsSuccLimit.le_succ_iff hi).1 hij rw [arrowMap_extendToSucc _ _ _ _ _ _ hij', arrowMap_limit _ _ hi _ _ hk] congr 1 apply Arrow.functor_ext rintro ⟨k₁, h₁⟩ ⟨k₂, h₂⟩ f dsimp rw [← arrowMap, ← arrowMap, arrowMap_extendToSucc] rfl namespace mkOfLimit open Functor variable {j : J} (hj : Order.IsSuccLimit j) (iter : ∀ (i : J), i < j → Φ.Iteration i) /-- Assuming `j : J` is a limit element and that we have `∀ (i : J), i < j → Φ.Iteration i`, this is the inductive system `Set.Iio j ⥤ C` which sends `⟨i, _⟩` to `(iter i _).F.obj ⟨i, _⟩`. -/ @[simps] noncomputable def inductiveSystem : Set.Iio j ⥤ C where obj i := (iter i.1 i.2).F.obj ⟨i.1, by simp⟩ map {i₁ i₂} f := mapObj (iter i₁.1 i₁.2) (iter i₂.1 i₂.2) (leOfHom f) (by simp) (by simp) (leOfHom f) /-- The extension of `inductiveSystem iter` to a functor `Set.Iic j ⥤ C` which sends the top element to the colimit of `inductiveSystem iter`. -/ noncomputable def functor : Set.Iic j ⥤ C := letI := hasColimitsOfShape_of_isSuccLimit C j hj ofCocone (colimit.cocone (inductiveSystem iter)) lemma functor_obj (i : J) (hi : i < j) {k : J} (iter' : Φ.Iteration k) (hk : i ≤ k) : (functor hj iter).obj ⟨i, hi.le⟩ = iter'.F.obj ⟨i, hk⟩ := by dsimp only [functor] rw [ofCocone_obj_eq _ _ hi] apply congr_obj lemma arrowMap_functor (i₁ i₂ : J) (h₁₂ : i₁ ≤ i₂) (h₂ : i₂ < j) : arrowMap (functor hj iter) i₁ i₂ h₁₂ h₂.le = Arrow.mk (mapObj (iter i₁ (lt_of_le_of_lt h₁₂ h₂)) (iter i₂ h₂) h₁₂ (by simp) (by simp) h₁₂) := arrowMap_ofCocone _ _ _ _ h₂ lemma arrowMap_functor_to_top (i : J) (hi : i < j) : letI := hasColimitsOfShape_of_isSuccLimit C j hj arrowMap (functor hj iter) i j hi.le (by simp) = Arrow.mk (colimit.ι (inductiveSystem iter) ⟨i, hi⟩) := arrowMap_ofCocone_to_top _ _ _ end mkOfLimit open mkOfLimit in /-- When `j` is a limit element, this is the element in `Φ.Iteration j` that is constructed from elements in `Φ.Iteration i` for all `i < j`. -/ noncomputable def mkOfLimit {j : J} (hj : Order.IsSuccLimit j) (iter : ∀ (i : J), i < j → Φ.Iteration i) : Φ.Iteration j where F := functor hj iter obj_bot := functor_obj hj iter ⊥ (Order.IsSuccLimit.bot_lt hj) (mkOfBot Φ J) (by rfl) arrowSucc_eq i hi := by rw [arrowSucc_def, arrowMap_functor _ _ _ _ (Order.le_succ i) ((Order.IsSuccLimit.succ_lt_iff hj).2 hi), arrow_mk_mapObj, ← arrowSucc_def _ _ ((Order.lt_succ_of_le_of_not_isMax (by rfl) (not_isMax_of_lt hi))), arrowSucc_eq, functor_obj _ _ _ hi] arrowMap_limit i hi hij k hk := by obtain hij | rfl := hij.lt_or_eq · rw [arrowMap_functor _ _ _ _ _ hij, arrow_mk_mapObj, arrowMap_limit _ _ hi _ _ hk] congr 1 apply Arrow.functor_ext rintro ⟨l₁, hl₁⟩ ⟨l₂, hl₂⟩ f dsimp generalize_proofs rw [← arrowMap, ← arrowMap, arrowMap_functor hj iter l₁ l₂ _ (hl₂.trans hij), arrow_mk_mapObj] apply congr_arrowMap · rw [arrowMap_functor_to_top _ _ _ hk, ← arrowι_def _ hi] congr 1 apply Arrow.functor_ext rintro ⟨l₁, hl₁⟩ ⟨l₂, hl₂⟩ f dsimp generalize_proofs rw [← arrowMap, arrow_mk_mapObj, arrowMap_functor _ _ _ _ _ hl₂, arrow_mk_mapObj] variable (Φ) instance nonempty (j : J) : Nonempty (Φ.Iteration j) := by induction j using SuccOrder.limitRecOn with | isMin i hi => obtain rfl : i = ⊥ := by simpa using hi exact ⟨mkOfBot Φ J⟩ | succ i hi hi' => exact ⟨mkOfSucc hi hi'.some⟩ | isSuccLimit i hi hi' => exact ⟨mkOfLimit hi (fun a ha ↦ (hi' a ha).some)⟩ end Iteration end SuccStruct end SmallObject end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/Iteration/Basic.lean
import Mathlib.CategoryTheory.Category.Preorder import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Preorder.HasIterationOfShape import Mathlib.CategoryTheory.Limits.Shapes.Preorder.PrincipalSeg import Mathlib.CategoryTheory.Limits.Comma import Mathlib.CategoryTheory.MorphismProperty.Basic import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.SuccPred.Limit import Mathlib.Order.Interval.Set.InitialSeg /-! # Transfinite iterations of a successor structure In this file, we introduce the structure `SuccStruct` on a category `C`. It consists of the data of an object `X₀ : C`, a successor map `succ : C → C` and a morphism `toSucc : X ⟶ succ X` for any `X : C`. The map `toSucc` does not have to be natural in `X`. For any element `j : J` in a well-ordered type `J`, we would like to define the iteration of `Φ : SuccStruct C`, as a functor `F : J ⥤ C` such that `F.obj ⊥ = X₀`, `F.obj j ⟶ F.obj (Order.succ j)` is `toSucc (F.obj j)` when `j` is not maximal, and when `j` is limit, `F.obj j` should be the colimit of the `F.obj k` for `k < j`. In the small object argument, we shall apply this to the iteration of a functor `F : C ⥤ C` equipped with a natural transformation `ε : 𝟭 C ⟶ F`: this will correspond to the case of `SuccStruct.ofNatTrans ε : SuccStruct (C ⥤ C)`, for which `X₀ := 𝟭 C`, `succ G := G ⋙ F` and `toSucc G : G ⟶ G ⋙ F` is given by `whiskerLeft G ε`. The construction of the iteration of `Φ : SuccStruct C` is done by transfinite induction, under an assumption `HasIterationOfShape C J`. However, for a limit element `j : J`, the definition of `F.obj j` does not involve only the objects `F.obj i` for `i < j`, but it also involves the maps `F.obj i₁ ⟶ F.obj i₂` for `i₁ ≤ i₂ < j`. Then, this is not a straightforward application of definitions by transfinite induction. In order to solve this technical difficulty, we introduce a structure `Φ.Iteration j` for any `j : J`. This structure contains all the expected data and properties for all the indices that are `≤ j`. In this file, we show that `Φ.Iteration j` is a subsingleton. The existence shall be obtained in the file `SmallObject.Iteration.Nonempty`, and the construction of the functor `Φ.iterationFunctor J : J ⥤ C` and of its colimit `Φ.iteration J : C` will done in the file `SmallObject.TransfiniteIteration`. The map `Φ.toSucc X : X ⟶ Φ.succ X` does not have to be natural (and it is not in certain applications). Then, two isomorphic objects `X` and `Y` may have non-isomorphic successors. This is the reason why we make an extensive use of equalities in `C` and in `Arrow C` in the definitions. ## Note The iteration was first introduced in mathlib by Joël Riou, using a different approach as the one described above. After refactoring his code, he found that the approach described above had already been used in the pioneering formalization work in Lean 3 by Reid Barton in 2018 towards the model category structure on topological spaces. -/ universe w v v' u u' namespace CategoryTheory open Category Limits namespace SmallObject variable {C : Type u} [Category.{v} C] {J : Type w} section variable [PartialOrder J] {j : J} (F : Set.Iic j ⥤ C) {i : J} (hi : i ≤ j) /-- The functor `Set.Iio i ⥤ C` obtained by "restriction" of `F : Set.Iic j ⥤ C` when `i ≤ j`. -/ def restrictionLT : Set.Iio i ⥤ C := (Set.principalSegIioIicOfLE hi).monotone.functor ⋙ F @[simp] lemma restrictionLT_obj (k : J) (hk : k < i) : (restrictionLT F hi).obj ⟨k, hk⟩ = F.obj ⟨k, hk.le.trans hi⟩ := rfl @[simp] lemma restrictionLT_map {k₁ k₂ : Set.Iio i} (φ : k₁ ⟶ k₂) : (restrictionLT F hi).map φ = F.map (homOfLE (by simpa using leOfHom φ)) := rfl /-- Given `F : Set.Iic j ⥤ C`, `i : J` such that `hi : i ≤ j`, this is the cocone consisting of all maps `F.obj ⟨k, hk⟩ ⟶ F.obj ⟨i, hi⟩` for `k : J` such that `k < i`. -/ @[simps!] def coconeOfLE : Cocone (restrictionLT F hi) := (Set.principalSegIioIicOfLE hi).cocone F /-- The functor `Set.Iic i ⥤ C` obtained by "restriction" of `F : Set.Iic j ⥤ C` when `i ≤ j`. -/ def restrictionLE : Set.Iic i ⥤ C := (Set.initialSegIicIicOfLE hi).monotone.functor ⋙ F @[simp] lemma restrictionLE_obj (k : J) (hk : k ≤ i) : (restrictionLE F hi).obj ⟨k, hk⟩ = F.obj ⟨k, hk.trans hi⟩ := rfl @[simp] lemma restrictionLE_map {k₁ k₂ : Set.Iic i} (φ : k₁ ⟶ k₂) : (restrictionLE F hi).map φ = F.map (homOfLE (by simpa using leOfHom φ)) := rfl end variable (C) in /-- A successor structure on a category consists of the data of an object `succ X` for any `X : C`, a map `toSucc X : X ⟶ toSucc X` (which does not need to be natural), and a zeroth object `X₀`. -/ structure SuccStruct where /-- the zeroth object -/ X₀ : C /-- the successor of an object -/ succ (X : C) : C /-- the map to the successor -/ toSucc (X : C) : X ⟶ succ X namespace SuccStruct /-- Given a functor `Φ : C ⥤ C`, a natural transformation of the form `𝟭 C ⟶ Φ` induces a successor structure on `C ⥤ C`. -/ @[simps] def ofNatTrans {F : C ⥤ C} (ε : 𝟭 C ⟶ F) : SuccStruct (C ⥤ C) where succ G := G ⋙ F toSucc G := Functor.whiskerLeft G ε X₀ := 𝟭 C variable (Φ : SuccStruct C) /-- The class of morphisms that are of the form `toSucc X : X ⟶ succ X`. -/ def prop : MorphismProperty C := .ofHoms (fun (X : C) ↦ Φ.toSucc X) lemma prop_toSucc (X : C) : Φ.prop (Φ.toSucc X) := ⟨_⟩ /-- The map `Φ.toSucc X : X ⟶ Φ.Succ X`, as an element in `Arrow C`. -/ @[simps!] def toSuccArrow (X : C) : Arrow C := Arrow.mk (Φ.toSucc X) lemma prop_iff {X Y : C} (f : X ⟶ Y) : Φ.prop f ↔ Arrow.mk f = Φ.toSuccArrow X := by constructor · rintro ⟨_⟩ rfl · intro h rw [← Φ.prop.arrow_mk_mem_toSet_iff, h] apply prop_toSucc variable {Φ} lemma prop.succ_eq {X Y : C} {f : X ⟶ Y} (hf : Φ.prop f) : Φ.succ X = Y := by cases hf rfl @[reassoc] lemma prop.fac {X Y : C} {f : X ⟶ Y} (hf : Φ.prop f) : f = Φ.toSucc X ≫ eqToHom hf.succ_eq := by cases hf simp /-- If `Φ : SuccStruct C` and `f` is a morphism in `C` which satisfies `Φ.prop f`, then this is the isomorphism of arrows between `f` and `Φ.toSuccArrow X`. -/ @[simps!] def prop.arrowIso {X Y : C} {f : X ⟶ Y} (hf : Φ.prop f) : Arrow.mk f ≅ Φ.toSuccArrow X := Arrow.isoMk (Iso.refl _) (eqToIso hf.succ_eq.symm) (by simp [hf.fac]) variable (Φ) variable [LinearOrder J] /-- Given a functor `F : Set.Iic ⥤ C`, this is the morphism in `C`, as an element in `Arrow C`, that is obtained by applying `F.map` to an inequality. -/ def arrowMap {j : J} (F : Set.Iic j ⥤ C) (i₁ i₂ : J) (h₁₂ : i₁ ≤ i₂) (h₂ : i₂ ≤ j) : Arrow C := Arrow.mk (F.map (homOfLE h₁₂ : ⟨i₁, h₁₂.trans h₂⟩ ⟶ ⟨i₂, h₂⟩)) @[simp] lemma arrowMap_refl {j : J} (F : Set.Iic j ⥤ C) (i : J) (hi : i ≤ j) : arrowMap F i i (by simp) hi = Arrow.mk (𝟙 (F.obj ⟨i, hi⟩)) := by simp [arrowMap] lemma arrowMap_restrictionLE {j : J} (F : Set.Iic j ⥤ C) {j' : J} (hj' : j' ≤ j) (i₁ i₂ : J) (h₁₂ : i₁ ≤ i₂) (h₂ : i₂ ≤ j') : arrowMap (restrictionLE F hj') i₁ i₂ h₁₂ h₂ = arrowMap F i₁ i₂ h₁₂ (h₂.trans hj') := rfl section variable [SuccOrder J] {j : J} (F : Set.Iic j ⥤ C) (i : J) (hi : i < j) /-- Given a functor `F : Set.Iic j ⥤ C` and `i : J` such that `i < j`, this is the arrow `F.obj ⟨i, _⟩ ⟶ F.obj ⟨Order.succ i, _⟩`. -/ def arrowSucc : Arrow C := arrowMap F i (Order.succ i) (Order.le_succ i) (Order.succ_le_of_lt hi) lemma arrowSucc_def : arrowSucc F i hi = arrowMap F i (Order.succ i) (Order.le_succ i) (Order.succ_le_of_lt hi) := rfl end section variable [HasIterationOfShape J C] {i : J} (F : Set.Iio i ⥤ C) (hi : Order.IsSuccLimit i) (k : J) (hk : k < i) /-- Given `F : Set.Iio i ⥤ C`, with `i` a limit element, and `k` such that `hk : k < i`, this is the map `colimit.ι F ⟨k, hk⟩`, as an element in `Arrow C`. -/ noncomputable def arrowι : Arrow C := letI := hasColimitsOfShape_of_isSuccLimit C i hi Arrow.mk (colimit.ι F ⟨k, hk⟩) lemma arrowι_def : letI := hasColimitsOfShape_of_isSuccLimit C i hi arrowι F hi k hk = Arrow.mk (colimit.ι F ⟨k, hk⟩) := rfl end variable [SuccOrder J] [OrderBot J] [HasIterationOfShape J C] /-- The category of `j`th iterations of a successor structure `Φ : SuccStruct C`. An object consists of the data of all iterations of `Φ` for `i : J` such that `i ≤ j` (this is the field `F`). Such objects are equipped with data and properties which characterizes uniquely the iterations on three types of elements: `⊥`, successors, limit elements. -/ @[ext] structure Iteration [WellFoundedLT J] (j : J) where /-- The data of all `i`th iterations for `i : J` such that `i ≤ j`. -/ F : Set.Iic j ⥤ C /-- The zeroth iteration is the zeroth object . -/ obj_bot : F.obj ⟨⊥, bot_le⟩ = Φ.X₀ /-- The iteration on a successor element is the successor. -/ arrowSucc_eq (i : J) (hi : i < j) : arrowSucc F i hi = Φ.toSuccArrow (F.obj ⟨i, hi.le⟩) /-- The iteration on a limit element identifies to the colimit of the value on smaller elements, see `Iteration.isColimit`. -/ arrowMap_limit (i : J) (hi : Order.IsSuccLimit i) (hij : i ≤ j) (k : J) (hk : k < i) : arrowMap F k i hk.le hij = arrowι (restrictionLT F hij) hi k hk variable [WellFoundedLT J] namespace Iteration variable {Φ} variable {j : J} section variable (iter : Φ.Iteration j) lemma obj_succ (i : J) (hi : i < j) : iter.F.obj ⟨Order.succ i, Order.succ_le_of_lt hi⟩ = Φ.succ (iter.F.obj ⟨i, hi.le⟩) := congr_arg Comma.right (iter.arrowSucc_eq i hi) lemma prop_map_succ (i : J) (hi : i < j) : Φ.prop (iter.F.map (homOfLE (Order.le_succ i) : ⟨i, hi.le⟩ ⟶ ⟨Order.succ i, Order.succ_le_of_lt hi⟩)) := by rw [prop_iff, ← arrowMap, ← arrowSucc_def _ _ hi, iter.arrowSucc_eq] lemma obj_limit (i : J) (hi : Order.IsSuccLimit i) (hij : i ≤ j) : letI := hasColimitsOfShape_of_isSuccLimit C i hi iter.F.obj ⟨i, hij⟩ = colimit (restrictionLT iter.F hij) := congr_arg Comma.right (iter.arrowMap_limit i hi hij ⊥ (Order.IsSuccLimit.bot_lt hi)) /-- The iteration on a limit element identifies to the colimit of the value on smaller elements. -/ noncomputable def isColimit (i : J) (hi : Order.IsSuccLimit i) (hij : i ≤ j) : IsColimit (coconeOfLE iter.F hij) := by letI := hasColimitsOfShape_of_isSuccLimit C i hi refine IsColimit.ofIsoColimit (colimit.isColimit (restrictionLT iter.F hij)) (Cocones.ext (eqToIso (iter.obj_limit i hi hij).symm) ?_) rintro ⟨k, hk⟩ apply Arrow.mk_injective dsimp rw [← arrowMap] simp [iter.arrowMap_limit i hi hij k hk, arrowι_def] /-- The element in `Φ.Iteration i` that is deduced from an element in `Φ.Iteration j` when `i ≤ j`. -/ @[simps F] def trunc (iter : Φ.Iteration j) {j' : J} (hj' : j' ≤ j) : Φ.Iteration j' where F := restrictionLE iter.F hj' obj_bot := iter.obj_bot arrowSucc_eq i hi := iter.arrowSucc_eq i (lt_of_lt_of_le hi hj') arrowMap_limit i hi hij k hk := iter.arrowMap_limit i hi (hij.trans hj') k hk end namespace subsingleton variable {K : Type w} [LinearOrder K] {x : K} (F G : Set.Iic x ⥤ C) section variable (k₁ k₂ : K) (h₁₂ : k₁ ≤ k₂) (h₂ : k₂ ≤ x) /-- Auxiliary definition for the proof of `Subsingleton (Φ.Iteration j)`. -/ def MapEq : Prop := arrowMap F k₁ k₂ h₁₂ h₂ = arrowMap G k₁ k₂ h₁₂ h₂ namespace MapEq variable {k₁ k₂ h₁₂ h₂} (h : MapEq F G k₁ k₂ h₁₂ h₂) include h lemma src : F.obj ⟨k₁, h₁₂.trans h₂⟩ = G.obj ⟨k₁, h₁₂.trans h₂⟩ := congr_arg Comma.left h lemma tgt : F.obj ⟨k₂, h₂⟩ = G.obj ⟨k₂, h₂⟩ := congr_arg Comma.right h lemma w : F.map (homOfLE h₁₂ : ⟨k₁, h₁₂.trans h₂⟩ ⟶ ⟨k₂, h₂⟩) = eqToHom (by rw [h.src]) ≫ G.map (homOfLE h₁₂ : ⟨k₁, h₁₂.trans h₂⟩ ⟶ ⟨k₂, h₂⟩) ≫ eqToHom (by rw [h.tgt]) := by have := (Arrow.mk_eq_mk_iff _ _).1 h tauto end MapEq end variable {F G} lemma mapEq_refl (k : K) (hk : k ≤ x) (h : F.obj ⟨k, hk⟩ = G.obj ⟨k, hk⟩) : MapEq F G k k (by simp) hk := by rw [MapEq, arrowMap_refl, arrowMap_refl, h] lemma mapEq_trans {i₁ i₂ i₃ : K} (h₁₂ : i₁ ≤ i₂) (h₂₃ : i₂ ≤ i₃) {h₃ : i₃ ≤ x} (m₁₂ : MapEq F G i₁ i₂ h₁₂ (h₂₃.trans h₃)) (m₂₃ : MapEq F G i₂ i₃ h₂₃ h₃) : MapEq F G i₁ i₃ (h₁₂.trans h₂₃) h₃ := by simp only [MapEq, arrowMap, Arrow.mk_eq_mk_iff] refine ⟨m₁₂.src, m₂₃.tgt, ?_⟩ rw [← homOfLE_comp (y := ⟨i₂, h₂₃.trans h₃⟩) h₁₂ h₂₃] simp [-homOfLE_comp, m₁₂.w, m₂₃.w] lemma ext (h : ∀ (k₁ k₂ : K) (h₁₂ : k₁ ≤ k₂) (h₂ : k₂ ≤ x), MapEq F G k₁ k₂ h₁₂ h₂) : F = G := by apply Arrow.functor_ext rintro ⟨k₁, _⟩ ⟨k₂, h₂⟩ f apply h end subsingleton open subsingleton in instance subsingleton : Subsingleton (Φ.Iteration j) where allEq iter₁ iter₂ := by suffices iter₁.F = iter₂.F by aesop revert iter₁ iter₂ induction j using SuccOrder.limitRecOn with | isMin j h => obtain rfl := h.eq_bot intro iter₁ iter₂ refine ext (fun k₁ k₂ h₁₂ h₂ ↦ ?_) obtain rfl : k₂ = ⊥ := by simpa using h₂ obtain rfl : k₁ = ⊥ := by simpa using h₁₂ apply mapEq_refl _ _ (by simp only [obj_bot]) | succ j hj₁ hj₂ => intro iter₁ iter₂ refine ext (fun k₁ k₂ h₁₂ h₂ ↦ ?_) have h₀ := Order.le_succ j replace hj₂ := hj₂ (iter₁.trunc h₀) (iter₂.trunc h₀) have hsucc := Functor.congr_obj hj₂ ⟨j, by simp⟩ dsimp at hj₂ hsucc wlog h : k₂ ≤ j generalizing k₁ k₂ · obtain h₂ | rfl := h₂.lt_or_eq · exact this _ _ _ _ ((Order.lt_succ_iff_of_not_isMax hj₁).1 h₂) · by_cases h' : k₁ ≤ j · apply mapEq_trans _ h₀ (this k₁ j h' h₀ (by simp)) simp only [MapEq, ← arrowSucc_def _ _ (Order.lt_succ_of_not_isMax hj₁), arrowSucc_eq, hsucc] · simp only [not_le] at h' obtain rfl : k₁ = Order.succ j := le_antisymm h₁₂ ((Order.succ_le_iff_of_not_isMax hj₁).2 h') rw [MapEq, arrowMap_refl, arrowMap_refl, obj_succ _ _ h', obj_succ _ _ h', hsucc] simp only [MapEq, ← arrowMap_restrictionLE _ (Order.le_succ j) _ _ _ h, hj₂] | isSuccLimit j h₁ h₂ => intro iter₁ iter₂ refine ext (fun k₁ k₂ h₁₂ h₃ ↦ ?_) wlog h₄ : k₂ < j generalizing k₁ k₂; swap · have := h₂ k₂ h₄ (iter₁.trunc h₄.le) (iter₂.trunc h₄.le) simp at this simp only [MapEq, ← arrowMap_restrictionLE _ h₄.le _ _ _ (by rfl), this] · obtain rfl : j = k₂ := le_antisymm (by simpa using h₄) h₃ have : restrictionLT iter₁.F le_rfl = restrictionLT iter₂.F le_rfl := Arrow.functor_ext (fun _ l _ ↦ this _ _ _ _ l.2) by_cases h₅ : k₁ < j · dsimp [MapEq] simp_rw [arrowMap_limit _ _ h₁ _ _ h₅, this] · obtain rfl : k₁ = j := le_antisymm h₁₂ (by simpa using h₅) apply mapEq_refl simp only [obj_limit _ _ h₁, this] lemma congr_obj {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂) (k : J) (h₁ : k ≤ j₁) (h₂ : k ≤ j₂) : iter₁.F.obj ⟨k, h₁⟩ = iter₂.F.obj ⟨k, h₂⟩ := by wlog h : j₁ ≤ j₂ generalizing j₁ j₂ · exact (this iter₂ iter₁ h₂ h₁ (le_of_lt (by simpa using h))).symm rw [Subsingleton.elim iter₁ (iter₂.trunc h)] dsimp lemma congr_arrowMap {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂) {k₁ k₂ : J} (h : k₁ ≤ k₂) (h₁ : k₂ ≤ j₁) (h₂ : k₂ ≤ j₂) : arrowMap iter₁.F k₁ k₂ h h₁ = arrowMap iter₂.F k₁ k₂ h h₂ := by wlog hj : j₁ ≤ j₂ generalizing j₁ j₂ · simp [this iter₂ iter₁ h₂ h₁ ((not_le.1 hj).le)] rw [Subsingleton.elim iter₁ (iter₂.trunc hj)] rfl lemma congr_map {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂) {k₁ k₂ : J} (h : k₁ ≤ k₂) (h₁ : k₂ ≤ j₁) (h₂ : k₂ ≤ j₂) : iter₁.F.map (homOfLE h : ⟨k₁, h.trans h₁⟩ ⟶ ⟨k₂, h₁⟩) = eqToHom (congr_obj iter₁ iter₂ k₁ (h.trans h₁) (h.trans h₂)) ≫ iter₂.F.map (homOfLE h) ≫ eqToHom (congr_obj iter₁ iter₂ k₂ h₁ h₂).symm := by have := (Arrow.mk_eq_mk_iff _ _).1 (congr_arrowMap iter₁ iter₂ h h₁ h₂) tauto /-- Given `iter₁ : Φ.Iteration j₁` and `iter₂ : Φ.Iteration j₂`, with `j₁ ≤ j₂`, if `k₁ ≤ k₂` are elements such that `k₁ ≤ j₁` and `k₂ ≤ k₂`, then this is the canonical map `iter₁.F.obj ⟨k₁, h₁⟩ ⟶ iter₂.F.obj ⟨k₂, h₂⟩`. -/ def mapObj {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂) {k₁ k₂ : J} (h₁₂ : k₁ ≤ k₂) (h₁ : k₁ ≤ j₁) (h₂ : k₂ ≤ j₂) (hj : j₁ ≤ j₂) : iter₁.F.obj ⟨k₁, h₁⟩ ⟶ iter₂.F.obj ⟨k₂, h₂⟩ := eqToHom (congr_obj iter₁ iter₂ k₁ h₁ (h₁.trans hj)) ≫ iter₂.F.map (homOfLE h₁₂) lemma arrow_mk_mapObj {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂) {k₁ k₂ : J} (h₁₂ : k₁ ≤ k₂) (h₁ : k₁ ≤ j₁) (h₂ : k₂ ≤ j₂) (hj : j₁ ≤ j₂) : Arrow.mk (mapObj iter₁ iter₂ h₁₂ h₁ h₂ hj) = arrowMap iter₂.F k₁ k₂ h₁₂ h₂ := by simp [mapObj, arrowMap] @[simp] lemma mapObj_refl {j : J} (iter : Φ.Iteration j) {k l : J} (h : k ≤ l) (h' : l ≤ j) : mapObj iter iter h (h.trans h') h' (by rfl) = iter.F.map (homOfLE h) := by simp [mapObj] @[reassoc (attr := simp)] lemma mapObj_trans {j₁ j₂ j₃ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂) (iter₃ : Φ.Iteration j₃) {k₁ k₂ k₃ : J} (h₁₂ : k₁ ≤ k₂) (h₂₃ : k₂ ≤ k₃) (h₁ : k₁ ≤ j₁) (h₂ : k₂ ≤ j₂) (h₃ : k₃ ≤ j₃) (h₁₂' : j₁ ≤ j₂) (h₂₃' : j₂ ≤ j₃) : mapObj iter₁ iter₂ h₁₂ h₁ h₂ h₁₂' ≫ mapObj iter₂ iter₃ h₂₃ h₂ h₃ h₂₃' = mapObj iter₁ iter₃ (h₁₂.trans h₂₃) h₁ h₃ (h₁₂'.trans h₂₃') := by simp [mapObj, congr_map iter₂ iter₃ h₁₂ h₂ (h₂.trans h₂₃'), ← Functor.map_comp] end Iteration end SuccStruct end SmallObject end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/SmallObject/Iteration/ExtendToSucc.lean
import Mathlib.CategoryTheory.SmallObject.Iteration.Basic /-! # Extension of a functor from `Set.Iic j` to `Set.Iic (Order.succ j)` Given a linearly ordered type `J` with `SuccOrder J`, `j : J` that is not maximal, we define the extension of a functor `F : Set.Iic j ⥤ C` as a functor `Set.Iic (Order.succ j) ⥤ C` when an object `X : C` and a morphism `τ : F.obj ⟨j, _⟩ ⟶ X` is given. -/ universe u namespace CategoryTheory open Category namespace SmallObject variable {C : Type*} [Category C] {J : Type u} [LinearOrder J] [SuccOrder J] {j : J} (hj : ¬IsMax j) (F : Set.Iic j ⥤ C) {X : C} (τ : F.obj ⟨j, by simp⟩ ⟶ X) namespace SuccStruct namespace extendToSucc variable (X) /-- `extendToSucc`, on objects: it coincides with `F.obj` for `i ≤ j`, and it sends `Order.succ j` to the given object `X`. -/ def obj (i : Set.Iic (Order.succ j)) : C := if hij : i.1 ≤ j then F.obj ⟨i.1, hij⟩ else X lemma obj_eq (i : Set.Iic j) : obj F X ⟨i, i.2.trans (Order.le_succ j)⟩ = F.obj i := dif_pos i.2 /-- The isomorphism `obj F X ⟨i, _⟩ ≅ F.obj i` when `i : Set.Iic j`. -/ def objIso (i : Set.Iic j) : obj F X ⟨i, i.2.trans (Order.le_succ j)⟩ ≅ F.obj i := eqToIso (obj_eq _ _ _) include hj in lemma obj_succ_eq : obj F X ⟨Order.succ j, by simp⟩ = X := dif_neg (by simpa only [Order.succ_le_iff_isMax] using hj) /-- The isomorphism `obj F X ⟨Order.succ j, _⟩ ≅ X`. -/ def objSuccIso : obj F X ⟨Order.succ j, by simp⟩ ≅ X := eqToIso (obj_succ_eq hj _ _) variable {X} /-- `extendToSucc`, on morphisms. -/ def map (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ Order.succ j) : obj F X ⟨i₁, hi.trans hi₂⟩ ⟶ obj F X ⟨i₂, hi₂⟩ := if h₁ : i₂ ≤ j then (objIso F X ⟨i₁, hi.trans h₁⟩).hom ≫ F.map (homOfLE hi) ≫ (objIso F X ⟨i₂, h₁⟩).inv else if h₂ : i₁ ≤ j then (objIso F X ⟨i₁, h₂⟩).hom ≫ F.map (homOfLE h₂) ≫ τ ≫ (objSuccIso hj F X).inv ≫ eqToHom (by congr exact le_antisymm (Order.succ_le_of_lt (not_le.1 h₁)) hi₂) else eqToHom (by congr rw [le_antisymm hi₂ (Order.succ_le_of_lt (not_le.1 h₁)), le_antisymm (hi.trans hi₂) (Order.succ_le_of_lt (not_le.1 h₂))]) lemma map_eq (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : map hj F τ i₁ i₂ hi (hi₂.trans (Order.le_succ j)) = (objIso F X ⟨i₁, hi.trans hi₂⟩).hom ≫ F.map (homOfLE hi) ≫ (objIso F X ⟨i₂, hi₂⟩).inv := dif_pos hi₂ lemma map_self_succ : map hj F τ j (Order.succ j) (Order.le_succ j) (by rfl) = (objIso F X ⟨j, by simp⟩).hom ≫ τ ≫ (objSuccIso hj F X).inv := by dsimp [map] rw [dif_neg (by simpa only [Order.succ_le_iff_isMax] using hj), dif_pos (by rfl), Functor.map_id, comp_id, id_comp] @[simp] lemma map_id (i : J) (hi : i ≤ Order.succ j) : map hj F τ i i (by rfl) hi = 𝟙 _ := by dsimp [map] by_cases h₁ : i ≤ j · rw [dif_pos h₁, CategoryTheory.Functor.map_id, id_comp, Iso.hom_inv_id] · obtain rfl : i = Order.succ j := le_antisymm hi (Order.succ_le_of_lt (not_le.1 h₁)) rw [dif_neg (by simpa only [Order.succ_le_iff_isMax] using hj), dif_neg h₁] lemma map_comp (i₁ i₂ i₃ : J) (h₁₂ : i₁ ≤ i₂) (h₂₃ : i₂ ≤ i₃) (h : i₃ ≤ Order.succ j) : map hj F τ i₁ i₃ (h₁₂.trans h₂₃) h = map hj F τ i₁ i₂ h₁₂ (h₂₃.trans h) ≫ map hj F τ i₂ i₃ h₂₃ h := by by_cases h₁ : i₃ ≤ j · rw [map_eq hj F τ i₁ i₂ _ (h₂₃.trans h₁), map_eq hj F τ i₂ i₃ _ h₁, map_eq hj F τ i₁ i₃ _ h₁, assoc, assoc, Iso.inv_hom_id_assoc, ← Functor.map_comp_assoc, homOfLE_comp] · obtain rfl : i₃ = Order.succ j := le_antisymm h (Order.succ_le_of_lt (not_le.1 h₁)) obtain h₂ | rfl := h₂₃.lt_or_eq · rw [Order.lt_succ_iff_of_not_isMax hj] at h₂ rw [map_eq hj F τ i₁ i₂ _ h₂] dsimp [map] rw [dif_neg h₁, dif_pos (h₁₂.trans h₂), dif_neg h₁, dif_pos h₂, assoc, assoc, Iso.inv_hom_id_assoc,comp_id, ← Functor.map_comp_assoc, homOfLE_comp] · rw [map_id, comp_id] end extendToSucc open extendToSucc in include hj in /-- The extension to `Set.Iic (Order.succ j) ⥤ C` of a functor `F : Set.Iic j ⥤ C`, when we specify a morphism `F.obj ⟨j, _⟩ ⟶ X`. -/ def extendToSucc : Set.Iic (Order.succ j) ⥤ C where obj := obj F X map {i₁ i₂} f := map hj F τ i₁ i₂ (leOfHom f) i₂.2 map_id _ := extendToSucc.map_id _ F τ _ _ map_comp {i₁ i₂ i₃} f g := extendToSucc.map_comp hj F τ i₁ i₂ i₃ (leOfHom f) (leOfHom g) i₃.2 lemma extendToSucc_obj_eq (i : J) (hi : i ≤ j) : (extendToSucc hj F τ).obj ⟨i, hi.trans (Order.le_succ j)⟩ = F.obj ⟨i, hi⟩ := extendToSucc.obj_eq F X ⟨i, hi⟩ /-- The isomorphism `(extendToSucc hj F τ).obj ⟨i, _⟩ ≅ F.obj i` when `i ≤ j` -/ def extendToSuccObjIso (i : J) (hi : i ≤ j) : (extendToSucc hj F τ).obj ⟨i, hi.trans (Order.le_succ j)⟩ ≅ F.obj ⟨i, hi⟩ := extendToSucc.objIso F X ⟨i, hi⟩ lemma extendToSucc_obj_succ_eq : (extendToSucc hj F τ).obj ⟨Order.succ j, by simp⟩ = X := extendToSucc.obj_succ_eq hj F X /-- The isomorphism `(extendToSucc hj F τ).obj ⟨Order.succ j, _⟩ ≅ X`. -/ def extendToSuccObjSuccIso : (extendToSucc hj F τ).obj ⟨Order.succ j, by simp⟩ ≅ X := extendToSucc.objSuccIso hj F X @[reassoc] lemma extendToSuccObjIso_hom_naturality (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : (extendToSucc hj F τ).map (homOfLE hi : ⟨i₁, hi.trans (hi₂.trans (Order.le_succ j))⟩ ⟶ ⟨i₂, hi₂.trans (Order.le_succ j)⟩) ≫ (extendToSuccObjIso hj F τ i₂ hi₂).hom = (extendToSuccObjIso hj F τ i₁ (hi.trans hi₂)).hom ≫ F.map (homOfLE hi) := by dsimp [extendToSucc, extendToSuccObjIso] rw [extendToSucc.map_eq _ _ _ _ _ _ hi₂, assoc, assoc, Iso.inv_hom_id, comp_id] /-- The isomorphism expressing that `extendToSucc hj F τ` extends `F`. -/ @[simps!] def extendToSuccRestrictionLEIso : SmallObject.restrictionLE (extendToSucc hj F τ) (Order.le_succ j) ≅ F := NatIso.ofComponents (fun i ↦ extendToSuccObjIso hj F τ i.1 i.2) (by rintro ⟨i₁, h₁⟩ ⟨i₂, h₂⟩ f apply extendToSuccObjIso_hom_naturality) lemma extendToSucc_map (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : (extendToSucc hj F τ).map (homOfLE hi : ⟨i₁, hi.trans (hi₂.trans (Order.le_succ j))⟩ ⟶ ⟨i₂, hi₂.trans (Order.le_succ j)⟩) = (extendToSuccObjIso hj F τ i₁ (hi.trans hi₂)).hom ≫ F.map (homOfLE hi) ≫ (extendToSuccObjIso hj F τ i₂ hi₂).inv := by rw [← extendToSuccObjIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id] lemma extendToSucc_map_le_succ : (extendToSucc hj F τ).map (homOfLE (Order.le_succ j)) = (extendToSuccObjIso hj F τ j (by simp)).hom ≫ τ ≫ (extendToSuccObjSuccIso hj F τ).inv := extendToSucc.map_self_succ _ _ _ lemma arrowMap_extendToSucc (i₁ i₂ : J) (hi : i₁ ≤ i₂) (hi₂ : i₂ ≤ j) : arrowMap (extendToSucc hj F τ) i₁ i₂ hi (hi₂.trans (Order.le_succ j)) = arrowMap F i₁ i₂ hi hi₂ := by simp [arrowMap, extendToSucc_map hj F τ i₁ i₂ hi hi₂, extendToSuccObjIso, extendToSucc.objIso] lemma arrowSucc_extendToSucc : arrowSucc (extendToSucc hj F τ) j (Order.lt_succ_of_not_isMax hj) = Arrow.mk τ := by simp [arrowSucc, arrowMap, extendToSucc_map_le_succ, extendToSuccObjIso, extendToSucc.objIso, extendToSuccObjSuccIso, extendToSucc.objSuccIso] end SuccStruct end SmallObject end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/EffectiveEpi/Extensive.lean
import Mathlib.CategoryTheory.EffectiveEpi.Preserves import Mathlib.CategoryTheory.EffectiveEpi.Coproduct import Mathlib.CategoryTheory.Extensive import Mathlib.CategoryTheory.Limits.Preserves.Finite /-! # Preserving and reflecting effective epis on extensive categories We prove that a functor between `FinitaryPreExtensive` categories preserves (resp. reflects) finite effective epi families if it preserves (resp. reflects) effective epis. -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] [FinitaryPreExtensive C] theorem effectiveEpi_desc_iff_effectiveEpiFamily {α : Type} [Finite α] {B : C} (X : α → C) (π : (a : α) → X a ⟶ B) : EffectiveEpi (Sigma.desc π) ↔ EffectiveEpiFamily X π := by exact ⟨fun h ↦ ⟨⟨@effectiveEpiFamilyStructOfEffectiveEpiDesc _ _ _ _ X π _ h _ _ (fun g ↦ (FinitaryPreExtensive.isIso_sigmaDesc_fst (fun a ↦ Sigma.ι X a) g inferInstance).epi_of_iso)⟩⟩, fun _ ↦ inferInstance⟩ variable {D : Type*} [Category D] [FinitaryPreExtensive D] variable (F : C ⥤ D) [PreservesFiniteCoproducts F] instance [F.ReflectsEffectiveEpis] : F.ReflectsFiniteEffectiveEpiFamilies where reflects {α _ B} X π h := by simp only [← effectiveEpi_desc_iff_effectiveEpiFamily] apply F.effectiveEpi_of_map convert (inferInstance : EffectiveEpi (inv (sigmaComparison F X) ≫ (Sigma.desc (fun a ↦ F.map (π a))))) simp instance [F.PreservesEffectiveEpis] : F.PreservesFiniteEffectiveEpiFamilies where preserves {α _ B} X π h := by simp only [← effectiveEpi_desc_iff_effectiveEpiFamily] convert (inferInstance : EffectiveEpi ((sigmaComparison F X) ≫ (F.map (Sigma.desc π)))) simp end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/EffectiveEpi/Enough.lean
import Mathlib.CategoryTheory.EffectiveEpi.Basic /-! # Effectively enough objects in the image of a functor We define the class `F.EffectivelyEnough` on a functor `F : C ⥤ D` which says that for every object in `D`, there exists an effective epi to it from an object in the image of `F`. -/ namespace CategoryTheory open Limits variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) namespace Functor /-- An effective presentation of an object `X` with respect to a functor `F` is the data of an effective epimorphism of the form `F.obj p ⟶ X`. -/ structure EffectivePresentation (X : D) where /-- The object of `C` giving the source of the effective epi -/ p : C /-- The morphism `F.obj p ⟶ X` -/ f : F.obj p ⟶ X /-- `f` is an effective epi -/ effectiveEpi : EffectiveEpi f /-- `D` has *effectively enough objects with respect to the functor `F` if every object has an effective presentation. -/ class EffectivelyEnough : Prop where /-- For every `X : D`, there exists an object `p` of `C` with an effective epi `F.obj p ⟶ X`. -/ presentation : ∀ (X : D), Nonempty (F.EffectivePresentation X) variable [F.EffectivelyEnough] /-- `F.effectiveEpiOverObj X` provides an arbitrarily chosen object in the image of `F` equipped with an effective epimorphism `F.effectiveEpiOver : F.effectiveEpiOverObj X ⟶ X`. -/ noncomputable def effectiveEpiOverObj (X : D) : D := F.obj (EffectivelyEnough.presentation (F := F) X).some.p /-- The epimorphism `F.effectiveEpiOver : F.effectiveEpiOverObj X ⟶ X` from the arbitrarily chosen object in the image of `F` over `X`. -/ noncomputable def effectiveEpiOver (X : D) : F.effectiveEpiOverObj X ⟶ X := (EffectivelyEnough.presentation X).some.f instance (X : D) : EffectiveEpi (F.effectiveEpiOver X) := (EffectivelyEnough.presentation X).some.effectiveEpi /-- An effective presentation of an object with respect to an equivalence of categories. -/ def equivalenceEffectivePresentation (e : C ≌ D) (X : D) : EffectivePresentation e.functor X where p := e.inverse.obj X f := e.counit.app _ effectiveEpi := inferInstance instance [IsEquivalence F] : EffectivelyEnough F where presentation X := ⟨equivalenceEffectivePresentation F.asEquivalence X⟩ end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/EffectiveEpi/Comp.lean
import Mathlib.CategoryTheory.EffectiveEpi.Basic /-! # Composition of effective epimorphisms This file provides `EffectiveEpi` instances for certain compositions. -/ namespace CategoryTheory open Limits Category variable {C : Type*} [Category C] /-- An effective epi family precomposed by a family of split epis is effective epimorphic. This version takes an explicit section to the split epis, and is mainly used to define `effectiveEpiStructCompOfEffectiveEpiSplitEpi`, which takes a `IsSplitEpi` instance instead. -/ noncomputable def effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi' {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) (i : (a : α) → X a ⟶ Y a) (hi : ∀ a, i a ≫ g a = 𝟙 _) [EffectiveEpiFamily _ f] : EffectiveEpiFamilyStruct _ (fun a ↦ g a ≫ f a) where desc e w := EffectiveEpiFamily.desc _ f (fun a ↦ i a ≫ e a) fun a₁ a₂ g₁ g₂ _ ↦ (by simp only [← Category.assoc] apply w _ _ (g₁ ≫ i a₁) (g₂ ≫ i a₂) simp only [Category.assoc] simp only [← Category.assoc, hi] simpa) fac e w a := by simp only [Category.assoc, EffectiveEpiFamily.fac] rw [← Category.id_comp (e a), ← Category.assoc, ← Category.assoc] apply w simp only [Category.comp_id, Category.id_comp, ← Category.assoc] aesop uniq _ _ _ hm := by apply EffectiveEpiFamily.uniq _ f intro a rw [← hm a, ← Category.assoc, ← Category.assoc, hi, Category.id_comp] /-- An effective epi family precomposed with a family of split epis is effective epimorphic. -/ noncomputable def effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) [∀ a, IsSplitEpi (g a)] [EffectiveEpiFamily _ f] : EffectiveEpiFamilyStruct _ (fun a ↦ g a ≫ f a) := effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi' f g (fun a ↦ section_ (g a)) (fun a ↦ IsSplitEpi.id (g a)) instance {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) [∀ a, IsSplitEpi (g a)] [EffectiveEpiFamily _ f] : EffectiveEpiFamily _ (fun a ↦ g a ≫ f a) := ⟨⟨effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi f g⟩⟩ example {B X Y : C} (f : X ⟶ B) (g : Y ⟶ X) [IsSplitEpi g] [EffectiveEpi f] : EffectiveEpi (g ≫ f) := inferInstance instance IsSplitEpi.EffectiveEpi {B X : C} (f : X ⟶ B) [IsSplitEpi f] : EffectiveEpi f := by rw [← Category.comp_id f] infer_instance /-- If a family of morphisms with fixed target, precomposed by a family of epis is effective epimorphic, then the original family is as well. -/ noncomputable def effectiveEpiFamilyStructOfComp {C : Type*} [Category C] {I : Type*} {Z Y : I → C} {X : C} (g : ∀ i, Z i ⟶ Y i) (f : ∀ i, Y i ⟶ X) [EffectiveEpiFamily _ (fun i => g i ≫ f i)] [∀ i, Epi (g i)] : EffectiveEpiFamilyStruct _ f where desc {W} φ h := EffectiveEpiFamily.desc _ (fun i => g i ≫ f i) (fun i => g i ≫ φ i) (fun {T} i₁ i₂ g₁ g₂ eq => by simpa [assoc] using h i₁ i₂ (g₁ ≫ g i₁) (g₂ ≫ g i₂) (by simpa [assoc] using eq)) fac {W} φ h i := by rw [← cancel_epi (g i), ← assoc, EffectiveEpiFamily.fac _ (fun i => g i ≫ f i)] uniq {W} φ _ m hm := EffectiveEpiFamily.uniq _ (fun i => g i ≫ f i) _ _ _ (fun i => by rw [assoc, hm]) lemma effectiveEpiFamily_of_effectiveEpi_epi_comp {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) [∀ a, Epi (g a)] [EffectiveEpiFamily _ (fun a ↦ g a ≫ f a)] : EffectiveEpiFamily _ f := ⟨⟨effectiveEpiFamilyStructOfComp g f⟩⟩ lemma effectiveEpi_of_effectiveEpi_epi_comp {B X Y : C} (f : X ⟶ B) (g : Y ⟶ X) [Epi g] [EffectiveEpi (g ≫ f)] : EffectiveEpi f := have := (effectiveEpi_iff_effectiveEpiFamily (g ≫ f)).mp inferInstance have := effectiveEpiFamily_of_effectiveEpi_epi_comp (X := fun () ↦ X) (Y := fun () ↦ Y) (fun () ↦ f) (fun () ↦ g) inferInstance section CompIso variable {B B' : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) (i : B ⟶ B') theorem effectiveEpiFamilyStructCompIso_aux {W : C} (e : (a : α) → X a ⟶ W) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π a₁ ≫ i = g₂ ≫ π a₂ ≫ i → g₁ ≫ e a₁ = g₂ ≫ e a₂) {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂) (hg : g₁ ≫ π a₁ = g₂ ≫ π a₂) : g₁ ≫ e a₁ = g₂ ≫ e a₂ := by grind variable [EffectiveEpiFamily X π] [IsIso i] /-- An effective epi family followed by an iso is an effective epi family. -/ noncomputable def effectiveEpiFamilyStructCompIso : EffectiveEpiFamilyStruct X (fun a ↦ π a ≫ i) where desc e h := inv i ≫ EffectiveEpiFamily.desc X π e (effectiveEpiFamilyStructCompIso_aux X π i e h) fac _ _ _ := by simp uniq e h m hm := by simp only [Category.assoc] at hm simp [← EffectiveEpiFamily.uniq X π e (effectiveEpiFamilyStructCompIso_aux X π i e h) (i ≫ m) hm] instance : EffectiveEpiFamily X (fun a ↦ π a ≫ i) := ⟨⟨effectiveEpiFamilyStructCompIso X π i⟩⟩ end CompIso section IsoComp variable {B : C} {α : Type*} (X Y : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] (i : (a : α) → Y a ⟶ X a) [∀ a, IsIso (i a)] example : EffectiveEpiFamily Y (fun a ↦ i a ≫ π a) := inferInstance end IsoComp end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/EffectiveEpi/Preserves.lean
import Mathlib.CategoryTheory.EffectiveEpi.Comp import Mathlib.Data.Fintype.EquivFin /-! # Functors preserving effective epimorphisms This file concerns functors which preserve and/or reflect effective epimorphisms and effective epimorphic families. ## TODO - Find nice sufficient conditions in terms of preserving/reflecting (co)limits, to preserve/reflect effective epis, similar to `CategoryTheory.preserves_epi_of_preservesColimit`. -/ universe u namespace CategoryTheory open Limits variable {C : Type*} [Category C] noncomputable section Equivalence variable {D : Type*} [Category D] (e : C ≌ D) {B : C} variable {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) theorem effectiveEpiFamilyStructOfEquivalence_aux {W : D} (ε : (a : α) → e.functor.obj (X a) ⟶ W) (h : ∀ {Z : D} (a₁ a₂ : α) (g₁ : Z ⟶ e.functor.obj (X a₁)) (g₂ : Z ⟶ e.functor.obj (X a₂)), g₁ ≫ e.functor.map (π a₁) = g₂ ≫ e.functor.map (π a₂) → g₁ ≫ ε a₁ = g₂ ≫ ε a₂) {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂) (hg : g₁ ≫ π a₁ = g₂ ≫ π a₂) : g₁ ≫ (fun a ↦ e.unit.app (X a) ≫ e.inverse.map (ε a)) a₁ = g₂ ≫ (fun a ↦ e.unit.app (X a) ≫ e.inverse.map (ε a)) a₂ := by have := h a₁ a₂ (e.functor.map g₁) (e.functor.map g₂) simp only [← Functor.map_comp, hg] at this simpa using congrArg e.inverse.map (this (by trivial)) variable [EffectiveEpiFamily X π] /-- Equivalences preserve effective epimorphic families -/ def effectiveEpiFamilyStructOfEquivalence : EffectiveEpiFamilyStruct (fun a ↦ e.functor.obj (X a)) (fun a ↦ e.functor.map (π a)) where desc ε h := (e.toAdjunction.homEquiv _ _).symm (EffectiveEpiFamily.desc X π (fun a ↦ e.unit.app _ ≫ e.inverse.map (ε a)) (effectiveEpiFamilyStructOfEquivalence_aux e X π ε h)) fac ε h a := by simp only [Functor.comp_obj, Adjunction.homEquiv_counit, Equivalence.toAdjunction_counit] have := congrArg ((fun f ↦ f ≫ e.counit.app _) ∘ e.functor.map) (EffectiveEpiFamily.fac X π (fun a ↦ e.unit.app _ ≫ e.inverse.map (ε a)) (effectiveEpiFamilyStructOfEquivalence_aux e X π ε h) a) simp only [Functor.id_obj, Functor.comp_obj, Function.comp_apply, Functor.map_comp, Category.assoc, Equivalence.fun_inv_map, Iso.inv_hom_id_app, Category.comp_id] at this simp [this] uniq ε h m hm := by simp only [Functor.comp_obj, Adjunction.homEquiv_counit, Equivalence.toAdjunction_counit] have := EffectiveEpiFamily.uniq X π (fun a ↦ e.unit.app _ ≫ e.inverse.map (ε a)) (effectiveEpiFamilyStructOfEquivalence_aux e X π ε h) specialize this (e.unit.app _ ≫ e.inverse.map m) fun a ↦ ?_ · rw [← congrArg e.inverse.map (hm a)] simp · simp [← this] instance (F : C ⥤ D) [F.IsEquivalence] : EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a)) := ⟨⟨effectiveEpiFamilyStructOfEquivalence F.asEquivalence _ _⟩⟩ example {X B : C} (π : X ⟶ B) (F : C ⥤ D) [F.IsEquivalence] [EffectiveEpi π] : EffectiveEpi <| F.map π := inferInstance end Equivalence namespace Functor variable {D : Type*} [Category D] section Preserves /-- A class describing the property of preserving effective epimorphisms. -/ class PreservesEffectiveEpis (F : C ⥤ D) : Prop where /-- A functor preserves effective epimorphisms if it maps effective epimorphisms to effective epimorphisms. -/ preserves : ∀ {X Y : C} (f : X ⟶ Y) [EffectiveEpi f], EffectiveEpi (F.map f) instance map_effectiveEpi (F : C ⥤ D) [F.PreservesEffectiveEpis] {X Y : C} (f : X ⟶ Y) [EffectiveEpi f] : EffectiveEpi (F.map f) := PreservesEffectiveEpis.preserves f /-- A class describing the property of preserving effective epimorphic families. -/ class PreservesEffectiveEpiFamilies (F : C ⥤ D) : Prop where /-- A functor preserves effective epimorphic families if it maps effective epimorphic families to effective epimorphic families. -/ preserves : ∀ {α : Type u} {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π], EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a)) instance map_effectiveEpiFamily (F : C ⥤ D) [PreservesEffectiveEpiFamilies.{u} F] {α : Type u} {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] : EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a)) := PreservesEffectiveEpiFamilies.preserves X π /-- A class describing the property of preserving finite effective epimorphic families. -/ class PreservesFiniteEffectiveEpiFamilies (F : C ⥤ D) : Prop where /-- A functor preserves finite effective epimorphic families if it maps finite effective epimorphic families to effective epimorphic families. -/ preserves : ∀ {α : Type} [Finite α] {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π], EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a)) instance map_finite_effectiveEpiFamily (F : C ⥤ D) [F.PreservesFiniteEffectiveEpiFamilies] {α : Type} [Finite α] {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] : EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a)) := PreservesFiniteEffectiveEpiFamilies.preserves X π instance (F : C ⥤ D) [PreservesEffectiveEpiFamilies.{0} F] : PreservesFiniteEffectiveEpiFamilies F where preserves _ _ := inferInstance instance (F : C ⥤ D) [PreservesFiniteEffectiveEpiFamilies F] : PreservesEffectiveEpis F where preserves _ := inferInstance instance (F : C ⥤ D) [IsEquivalence F] : F.PreservesEffectiveEpiFamilies where preserves _ _ := inferInstance end Preserves section Reflects /-- A class describing the property of reflecting effective epimorphisms. -/ class ReflectsEffectiveEpis (F : C ⥤ D) : Prop where /-- A functor reflects effective epimorphisms if morphisms that are mapped to epimorphisms are themselves effective epimorphisms. -/ reflects : ∀ {X Y : C} (f : X ⟶ Y), EffectiveEpi (F.map f) → EffectiveEpi f lemma effectiveEpi_of_map (F : C ⥤ D) [F.ReflectsEffectiveEpis] {X Y : C} (f : X ⟶ Y) (h : EffectiveEpi (F.map f)) : EffectiveEpi f := ReflectsEffectiveEpis.reflects f h /-- A class describing the property of reflecting effective epimorphic families. -/ class ReflectsEffectiveEpiFamilies (F : C ⥤ D) : Prop where /-- A functor reflects effective epimorphic families if families that are mapped to effective epimorphic families are themselves effective epimorphic families. -/ reflects : ∀ {α : Type u} {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)), EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a)) → EffectiveEpiFamily X π lemma effectiveEpiFamily_of_map (F : C ⥤ D) [ReflectsEffectiveEpiFamilies.{u} F] {α : Type u} {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)) (h : EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a))) : EffectiveEpiFamily X π := ReflectsEffectiveEpiFamilies.reflects X π h /-- A class describing the property of reflecting finite effective epimorphic families. -/ class ReflectsFiniteEffectiveEpiFamilies (F : C ⥤ D) : Prop where /-- A functor reflects finite effective epimorphic families if finite families that are mapped to effective epimorphic families are themselves effective epimorphic families. -/ reflects : ∀ {α : Type} [Finite α] {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)), EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a)) → EffectiveEpiFamily X π lemma finite_effectiveEpiFamily_of_map (F : C ⥤ D) [ReflectsFiniteEffectiveEpiFamilies F] {α : Type} [Finite α] {B : C} (X : α → C) (π : (a : α) → (X a ⟶ B)) (h : EffectiveEpiFamily (fun a ↦ F.obj (X a)) (fun a ↦ F.map (π a))) : EffectiveEpiFamily X π := ReflectsFiniteEffectiveEpiFamilies.reflects X π h instance (F : C ⥤ D) [ReflectsEffectiveEpiFamilies.{0} F] : ReflectsFiniteEffectiveEpiFamilies F where reflects _ _ h := by have := F.effectiveEpiFamily_of_map _ _ h infer_instance instance (F : C ⥤ D) [ReflectsFiniteEffectiveEpiFamilies F] : ReflectsEffectiveEpis F where reflects _ h := by rw [effectiveEpi_iff_effectiveEpiFamily] at h have := F.finite_effectiveEpiFamily_of_map _ _ h infer_instance instance (F : C ⥤ D) [IsEquivalence F] : F.ReflectsEffectiveEpiFamilies where reflects {α B} X π _ := by let i : (a : α) → X a ⟶ (inv F).obj (F.obj (X a)) := fun a ↦ (asEquivalence F).unit.app _ have : EffectiveEpiFamily X (fun a ↦ (i a) ≫ (inv F).map (F.map (π a))) := inferInstance simp only [inv_fun_map, Iso.hom_inv_id_app_assoc, i] at this have : EffectiveEpiFamily X (fun a ↦ (π a ≫ (asEquivalence F).unit.app B) ≫ (asEquivalence F).unitInv.app _) := inferInstance simpa end Reflects end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/EffectiveEpi/Basic.lean
import Mathlib.CategoryTheory.Limits.Shapes.Products /-! # Effective epimorphisms We define the notion of effective epimorphism and effective epimorphic family of morphisms. A morphism is an *effective epi* if it is a joint coequalizer of all pairs of morphisms which it coequalizes. A family of morphisms with fixed target is *effective epimorphic* if it is initial among families of morphisms with its sources and a general fixed target, coequalizing every pair of morphisms it coequalizes (here, the pair of morphisms coequalized can have different targets among the sources of the family). We have defined the notion of effective epi for morphisms and families of morphisms in such a way that avoids requiring the existence of pullbacks. However, if the relevant pullbacks exist then these definitions are equivalent, see the file `CategoryTheory/EffectiveEpi/RegularEpi.lean` See [nlab: *Effective Epimorphism*](https://ncatlab.org/nlab/show/effective+epimorphism) and [Stacks 00WP](https://stacks.math.columbia.edu/tag/00WP) for the standard definitions. Note that our notion of `EffectiveEpi` is often called "strict epi" in the literature. ## References - [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1, Example 2.1.12. - [nlab: *Effective Epimorphism*](https://ncatlab.org/nlab/show/effective+epimorphism) and - [Stacks 00WP](https://stacks.math.columbia.edu/tag/00WP) for the standard definitions. -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] /-- This structure encodes the data required for a morphism to be an effective epimorphism. -/ structure EffectiveEpiStruct {X Y : C} (f : Y ⟶ X) where /-- For every `W` with a morphism `e : Y ⟶ W` that coequalizes every pair of morphisms `g₁ g₂ : Z ⟶ Y` which `f` coequalizes, `desc e h` is a morphism `X ⟶ W`... -/ desc : ∀ {W : C} (e : Y ⟶ W), (∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) → (X ⟶ W) /-- ...factorizing `e` through `f`... -/ fac : ∀ {W : C} (e : Y ⟶ W) (h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e), f ≫ desc e h = e /-- ...and as such, unique. -/ uniq : ∀ {W : C} (e : Y ⟶ W) (h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) (m : X ⟶ W), f ≫ m = e → m = desc e h /-- A morphism `f : Y ⟶ X` is an effective epimorphism provided that `f` exhibits `X` as a colimit of the diagram of all "relations" `R ⇉ Y`. If `f` has a kernel pair, then this is equivalent to showing that the corresponding cofork is a colimit. -/ class EffectiveEpi {X Y : C} (f : Y ⟶ X) : Prop where /-- `f` is an effective epimorphism if there exists an `EffectiveEpiStruct` for `f`. -/ effectiveEpi : Nonempty (EffectiveEpiStruct f) /-- Some chosen `EffectiveEpiStruct` associated to an effective epi. -/ noncomputable def EffectiveEpi.getStruct {X Y : C} (f : Y ⟶ X) [EffectiveEpi f] : EffectiveEpiStruct f := EffectiveEpi.effectiveEpi.some /-- Descend along an effective epi. -/ noncomputable def EffectiveEpi.desc {X Y W : C} (f : Y ⟶ X) [EffectiveEpi f] (e : Y ⟶ W) (h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) : X ⟶ W := (EffectiveEpi.getStruct f).desc e h @[reassoc (attr := simp)] lemma EffectiveEpi.fac {X Y W : C} (f : Y ⟶ X) [EffectiveEpi f] (e : Y ⟶ W) (h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) : f ≫ EffectiveEpi.desc f e h = e := (EffectiveEpi.getStruct f).fac e h lemma EffectiveEpi.uniq {X Y W : C} (f : Y ⟶ X) [EffectiveEpi f] (e : Y ⟶ W) (h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) (m : X ⟶ W) (hm : f ≫ m = e) : m = EffectiveEpi.desc f e h := (EffectiveEpi.getStruct f).uniq e h _ hm instance epiOfEffectiveEpi {X Y : C} (f : Y ⟶ X) [EffectiveEpi f] : Epi f := by constructor intro W m₁ m₂ h have : m₂ = EffectiveEpi.desc f (f ≫ m₂) (fun {Z} g₁ g₂ h => by simp only [← Category.assoc, h]) := EffectiveEpi.uniq _ _ _ _ rfl rw [this] exact EffectiveEpi.uniq _ _ _ _ h /-- This structure encodes the data required for a family of morphisms to be effective epimorphic. -/ structure EffectiveEpiFamilyStruct {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) where /-- For every `W` with a family of morphisms `e a : Y a ⟶ W` that coequalizes every pair of morphisms `g₁ : Z ⟶ Y a₁`, `g₂ : Z ⟶ Y a₂` which the family `π` coequalizes, `desc e h` is a morphism `X ⟶ W`... -/ desc : ∀ {W} (e : (a : α) → (X a ⟶ W)), (∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) → (B ⟶ W) /-- ...factorizing the components of `e` through the components of `π`... -/ fac : ∀ {W} (e : (a : α) → (X a ⟶ W)) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) (a : α), π a ≫ desc e h = e a /-- ...and as such, unique. -/ uniq : ∀ {W} (e : (a : α) → (X a ⟶ W)) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) (m : B ⟶ W), (∀ (a : α), π a ≫ m = e a) → m = desc e h /-- A family of morphisms `π a : X a ⟶ B` indexed by `α` is effective epimorphic provided that the `π a` exhibit `B` as a colimit of the diagram of all "relations" `R → X a₁`, `R ⟶ X a₂` for all `a₁ a₂ : α`. -/ class EffectiveEpiFamily {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) : Prop where /-- `π` is an effective epimorphic family if there exists an `EffectiveEpiFamilyStruct` for `π` -/ effectiveEpiFamily : Nonempty (EffectiveEpiFamilyStruct X π) /-- Some chosen `EffectiveEpiFamilyStruct` associated to an effective epi family. -/ noncomputable def EffectiveEpiFamily.getStruct {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] : EffectiveEpiFamilyStruct X π := EffectiveEpiFamily.effectiveEpiFamily.some /-- Descend along an effective epi family. -/ noncomputable def EffectiveEpiFamily.desc {B W : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] (e : (a : α) → (X a ⟶ W)) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) : B ⟶ W := (EffectiveEpiFamily.getStruct X π).desc e h @[reassoc (attr := simp)] lemma EffectiveEpiFamily.fac {B W : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] (e : (a : α) → (X a ⟶ W)) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) (a : α) : π a ≫ EffectiveEpiFamily.desc X π e h = e a := (EffectiveEpiFamily.getStruct X π).fac e h a lemma EffectiveEpiFamily.uniq {B W : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] (e : (a : α) → (X a ⟶ W)) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) (m : B ⟶ W) (hm : ∀ a, π a ≫ m = e a) : m = EffectiveEpiFamily.desc X π e h := (EffectiveEpiFamily.getStruct X π).uniq e h m hm -- TODO: Once we have "jointly epimorphic families", we could rephrase this as such a property. lemma EffectiveEpiFamily.hom_ext {B W : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] (m₁ m₂ : B ⟶ W) (h : ∀ a, π a ≫ m₁ = π a ≫ m₂) : m₁ = m₂ := by have : m₂ = EffectiveEpiFamily.desc X π (fun a => π a ≫ m₂) (fun a₁ a₂ g₁ g₂ h => by simp only [← Category.assoc, h]) := by apply EffectiveEpiFamily.uniq; intro; rfl rw [this] exact EffectiveEpiFamily.uniq _ _ _ _ _ h /-- An `EffectiveEpiFamily` consisting of a single `EffectiveEpi` -/ noncomputable def effectiveEpiFamilyStructSingletonOfEffectiveEpi {B X : C} (f : X ⟶ B) [EffectiveEpi f] : EffectiveEpiFamilyStruct (fun () ↦ X) (fun () ↦ f) where desc e h := EffectiveEpi.desc f (e ()) (fun g₁ g₂ hg ↦ h () () g₁ g₂ hg) fac e h := fun _ ↦ EffectiveEpi.fac f (e ()) (fun g₁ g₂ hg ↦ h () () g₁ g₂ hg) uniq e h m hm := by apply EffectiveEpi.uniq f (e ()) (h () ()); exact hm () instance {B X : C} (f : X ⟶ B) [EffectiveEpi f] : EffectiveEpiFamily (fun () ↦ X) (fun () ↦ f) := ⟨⟨effectiveEpiFamilyStructSingletonOfEffectiveEpi f⟩⟩ /-- A single element `EffectiveEpiFamily` consists of an `EffectiveEpi` -/ noncomputable def effectiveEpiStructOfEffectiveEpiFamilySingleton {B X : C} (f : X ⟶ B) [EffectiveEpiFamily (fun () ↦ X) (fun () ↦ f)] : EffectiveEpiStruct f where desc e h := EffectiveEpiFamily.desc (fun () ↦ X) (fun () ↦ f) (fun () ↦ e) (fun _ _ g₁ g₂ hg ↦ h g₁ g₂ hg) fac e h := EffectiveEpiFamily.fac (fun () ↦ X) (fun () ↦ f) (fun () ↦ e) (fun _ _ g₁ g₂ hg ↦ h g₁ g₂ hg) () uniq e h m hm := EffectiveEpiFamily.uniq (fun () ↦ X) (fun () ↦ f) (fun () ↦ e) (fun _ _ g₁ g₂ hg ↦ h g₁ g₂ hg) m (fun _ ↦ hm) instance {B X : C} (f : X ⟶ B) [EffectiveEpiFamily (fun () ↦ X) (fun () ↦ f)] : EffectiveEpi f := ⟨⟨effectiveEpiStructOfEffectiveEpiFamilySingleton f⟩⟩ theorem effectiveEpi_iff_effectiveEpiFamily {B X : C} (f : X ⟶ B) : EffectiveEpi f ↔ EffectiveEpiFamily (fun () ↦ X) (fun () ↦ f) := ⟨fun _ ↦ inferInstance, fun _ ↦ inferInstance⟩ /-- A family of morphisms with the same target inducing an isomorphism from the coproduct to the target is an `EffectiveEpiFamily`. -/ noncomputable def effectiveEpiFamilyStructOfIsIsoDesc {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [HasCoproduct X] [IsIso (Sigma.desc π)] : EffectiveEpiFamilyStruct X π where desc e _ := (asIso (Sigma.desc π)).inv ≫ (Sigma.desc e) fac e h := by intro a have : π a = Sigma.ι X a ≫ (asIso (Sigma.desc π)).hom := by simp only [asIso_hom, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] rw [this, Category.assoc] simp only [asIso_hom, asIso_inv, IsIso.hom_inv_id_assoc, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] uniq e h m hm := by simp only [asIso_inv, IsIso.eq_inv_comp] ext a simp only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app, colimit.ι_desc] exact hm a instance {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [HasCoproduct X] [IsIso (Sigma.desc π)] : EffectiveEpiFamily X π := ⟨⟨effectiveEpiFamilyStructOfIsIsoDesc X π⟩⟩ /-- Any isomorphism is an effective epi. -/ noncomputable def effectiveEpiStructOfIsIso {X Y : C} (f : X ⟶ Y) [IsIso f] : EffectiveEpiStruct f where desc e _ := inv f ≫ e fac _ _ := by simp uniq _ _ _ h := by simpa using h instance {X Y : C} (f : X ⟶ Y) [IsIso f] : EffectiveEpi f := ⟨⟨effectiveEpiStructOfIsIso f⟩⟩ example {X : C} : EffectiveEpiFamily (fun _ => X : Unit → C) (fun _ => 𝟙 X) := inferInstance /-- Reindex the indexing type of an effective epi family struct. -/ def EffectiveEpiFamilyStruct.reindex {B : C} {α α' : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) (e : α' ≃ α) (P : EffectiveEpiFamilyStruct (fun a => X (e a)) (fun a => π (e a))) : EffectiveEpiFamilyStruct X π where desc := fun f h => P.desc (fun _ => f _) (fun _ _ => h _ _) fac _ _ a := by obtain ⟨a,rfl⟩ := e.surjective a apply P.fac uniq _ _ _ hm := P.uniq _ _ _ fun _ => hm _ /-- Reindex the indexing type of an effective epi family. -/ lemma EffectiveEpiFamily.reindex {B : C} {α α' : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) (e : α' ≃ α) (h : EffectiveEpiFamily (fun a => X (e a)) (fun a => π (e a))) : EffectiveEpiFamily X π := .mk <| .intro <| @EffectiveEpiFamily.getStruct _ _ _ _ _ _ h |>.reindex _ _ e end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/EffectiveEpi/RegularEpi.lean
import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.CategoryTheory.EffectiveEpi.Basic /-! # The relationship between effective and regular epimorphisms. This file proves that the notions of regular epi and effective epi are equivalent for morphisms with kernel pairs, and that regular epi implies effective epi in general. -/ namespace CategoryTheory open Limits RegularEpi variable {C : Type*} [Category C] /-- The data of an `EffectiveEpi` structure on a `RegularEpi`. -/ def effectiveEpiStructOfRegularEpi {B X : C} (f : X ⟶ B) [RegularEpi f] : EffectiveEpiStruct f where desc _ h := Cofork.IsColimit.desc isColimit _ (h _ _ w) fac _ _ := Cofork.IsColimit.π_desc' isColimit _ _ uniq _ _ _ hg := Cofork.IsColimit.hom_ext isColimit (hg.trans (Cofork.IsColimit.π_desc' _ _ _).symm) instance {B X : C} (f : X ⟶ B) [RegularEpi f] : EffectiveEpi f := ⟨⟨effectiveEpiStructOfRegularEpi f⟩⟩ /-- A morphism which is a coequalizer for its kernel pair is an effective epi. -/ theorem effectiveEpiOfKernelPair {B X : C} (f : X ⟶ B) [HasPullback f f] (hc : IsColimit (Cofork.ofπ f pullback.condition)) : EffectiveEpi f := let _ := regularEpiOfKernelPair f hc inferInstance /-- An effective epi which has a kernel pair is a regular epi. -/ noncomputable instance regularEpiOfEffectiveEpi {B X : C} (f : X ⟶ B) [HasPullback f f] [EffectiveEpi f] : RegularEpi f where W := pullback f f left := pullback.fst f f right := pullback.snd f f w := pullback.condition isColimit := { desc := fun s ↦ EffectiveEpi.desc f (s.ι.app WalkingParallelPair.one) fun g₁ g₂ hg ↦ (by simp only [Cofork.app_one_eq_π] rw [← pullback.lift_snd g₁ g₂ hg, Category.assoc, ← Cofork.app_zero_eq_comp_π_right] simp) fac := by intro s j have := EffectiveEpi.fac f (s.ι.app WalkingParallelPair.one) fun g₁ g₂ hg ↦ (by simp only [Cofork.app_one_eq_π] rw [← pullback.lift_snd g₁ g₂ hg, Category.assoc, ← Cofork.app_zero_eq_comp_π_right] simp) simp only [Functor.const_obj_obj, Cofork.app_one_eq_π] at this cases j with | zero => simp [this] | one => simp [this] uniq := fun _ _ h ↦ EffectiveEpi.uniq f _ _ _ (h WalkingParallelPair.one) } end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/EffectiveEpi/Coproduct.lean
import Mathlib.CategoryTheory.EffectiveEpi.Basic import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.Tactic.ApplyFun /-! # Effective epimorphic families and coproducts This file proves that an effective epimorphic family induces an effective epi from the coproduct if the coproduct exists, and the converse under some more conditions on the coproduct (that it interacts well with pullbacks). -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] /-- Given an `EffectiveEpiFamily X π` and a corresponding coproduct cocone, the family descends to an `EffectiveEpi` from the coproduct. -/ noncomputable def effectiveEpiStructIsColimitDescOfEffectiveEpiFamily {B : C} {α : Type*} (X : α → C) (c : Cofan X) (hc : IsColimit c) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] : EffectiveEpiStruct (hc.desc (Cofan.mk B π)) where desc e h := EffectiveEpiFamily.desc X π (fun a ↦ c.ι.app ⟨a⟩ ≫ e) (fun a₁ a₂ g₁ g₂ hg ↦ by simp only [← Category.assoc] exact h (g₁ ≫ c.ι.app ⟨a₁⟩) (g₂ ≫ c.ι.app ⟨a₂⟩) (by simpa)) fac e h := hc.hom_ext (fun ⟨j⟩ ↦ (by simp)) uniq e _ m hm := EffectiveEpiFamily.uniq X π (fun a ↦ c.ι.app ⟨a⟩ ≫ e) (fun _ _ _ _ hg ↦ (by simp [← hm, reassoc_of% hg])) m (fun _ ↦ (by simp [← hm])) instance {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [HasCoproduct X] [EffectiveEpiFamily X π] : EffectiveEpi (Sigma.desc π) := by let e := effectiveEpiStructIsColimitDescOfEffectiveEpiFamily X _ (coproductIsCoproduct _) π simp only [Cofan.mk_pt, coproductIsCoproduct, colimit.cocone_x, IsColimit.ofIsoColimit_desc, Cocones.ext_inv_hom, Iso.refl_inv, colimit.isColimit_desc, Category.id_comp] at e exact ⟨⟨e⟩⟩ example {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] [HasCoproduct X] : Epi (Sigma.desc π) := inferInstance /-- This is an auxiliary lemma used twice in the definition of `EffectiveEpiFamilyOfEffectiveEpiDesc`. It is the `h` hypothesis of `EffectiveEpi.desc` and `EffectiveEpi.fac`. -/ theorem effectiveEpiFamilyStructOfEffectiveEpiDesc_aux {B : C} {α : Type*} {X : α → C} {π : (a : α) → X a ⟶ B} [HasCoproduct X] [∀ {Z : C} (g : Z ⟶ ∐ X) (a : α), HasPullback g (Sigma.ι X a)] [∀ {Z : C} (g : Z ⟶ ∐ X), HasCoproduct fun a ↦ pullback g (Sigma.ι X a)] [∀ {Z : C} (g : Z ⟶ ∐ X), Epi (Sigma.desc fun a ↦ pullback.fst g (Sigma.ι X a))] {W : C} {e : (a : α) → X a ⟶ W} (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π a₁ = g₂ ≫ π a₂ → g₁ ≫ e a₁ = g₂ ≫ e a₂) {Z : C} {g₁ g₂ : Z ⟶ ∐ fun b ↦ X b} (hg : g₁ ≫ Sigma.desc π = g₂ ≫ Sigma.desc π) : g₁ ≫ Sigma.desc e = g₂ ≫ Sigma.desc e := by apply_fun ((Sigma.desc fun a ↦ pullback.fst g₁ (Sigma.ι X a)) ≫ ·) using (fun a b ↦ (cancel_epi _).mp) ext a simp only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app] rw [← Category.assoc, pullback.condition] simp only [Category.assoc, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] apply_fun ((Sigma.desc fun a ↦ pullback.fst (pullback.fst _ _ ≫ g₂) (Sigma.ι X a)) ≫ ·) using (fun a b ↦ (cancel_epi _).mp) ext b simp only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app] simp only [← Category.assoc] rw [(Category.assoc _ _ g₂), pullback.condition] simp only [Category.assoc, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] rw [← Category.assoc] apply h apply_fun (pullback.fst g₁ (Sigma.ι X a) ≫ ·) at hg rw [← Category.assoc, pullback.condition] at hg simp only [Category.assoc, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] at hg apply_fun ((Sigma.ι (fun a ↦ pullback _ _) b) ≫ (Sigma.desc fun a ↦ pullback.fst (pullback.fst _ _ ≫ g₂) (Sigma.ι X a)) ≫ ·) at hg simp only [colimit.ι_desc_assoc, Discrete.functor_obj, Cofan.mk_pt, Cofan.mk_ι_app] at hg simp only [← Category.assoc] at hg rw [(Category.assoc _ _ g₂), pullback.condition] at hg simpa using hg /-- If a coproduct interacts well enough with pullbacks, then a family whose domains are the terms of the coproduct is effective epimorphic whenever `Sigma.desc` induces an effective epimorphism from the coproduct itself. -/ noncomputable def effectiveEpiFamilyStructOfEffectiveEpiDesc {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) [HasCoproduct X] [EffectiveEpi (Sigma.desc π)] [∀ {Z : C} (g : Z ⟶ ∐ X) (a : α), HasPullback g (Sigma.ι X a)] [∀ {Z : C} (g : Z ⟶ ∐ X), HasCoproduct (fun a ↦ pullback g (Sigma.ι X a))] [∀ {Z : C} (g : Z ⟶ ∐ X), Epi (Sigma.desc (fun a ↦ pullback.fst g (Sigma.ι X a)))] : EffectiveEpiFamilyStruct X π where desc e h := EffectiveEpi.desc (Sigma.desc π) (Sigma.desc e) fun _ _ hg ↦ effectiveEpiFamilyStructOfEffectiveEpiDesc_aux h hg fac e h a := by rw [(by simp : π a = Sigma.ι X a ≫ Sigma.desc π), (by simp : e a = Sigma.ι X a ≫ Sigma.desc e), Category.assoc, EffectiveEpi.fac (Sigma.desc π) (Sigma.desc e) (fun g₁ g₂ hg ↦ effectiveEpiFamilyStructOfEffectiveEpiDesc_aux h hg)] uniq _ _ _ hm := by apply EffectiveEpi.uniq (Sigma.desc π) ext simpa using hm _ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Yoneda.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Types.Yoneda import Mathlib.CategoryTheory.Limits.Preserves.Ulift 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. -/ assert_not_exists AddCommMonoid open Opposite CategoryTheory Limits universe t w 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 cat_disch } /-- 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 [Functor.flip_obj_obj, yoneda_obj_obj, Functor.const_obj_obj, Functor.flip_obj_map, types_comp_apply, yoneda_map_app, Category.id_comp] uniq s m w := by apply funext; rintro ⟨⟩ 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 instance yoneda_preservesLimit (F : J ⥤ Cᵒᵖ) (X : C) : PreservesLimit F (yoneda.obj X) where preserves {c} hc := 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 yoneda_preservesLimitsOfShape (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 _ := 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 instance coyoneda_preservesLimit (F : J ⥤ C) (X : Cᵒᵖ) : PreservesLimit F (coyoneda.obj X) where preserves {c} hc := 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 _ := 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. -/ instance yoneda_preservesLimits (X : C) : PreservesLimitsOfSize.{t, w} (yoneda.obj X) where /-- The coyoneda embedding `coyoneda.obj X : C ⥤ Type v` for `X : Cᵒᵖ` preserves limits. -/ instance coyoneda_preservesLimits (X : Cᵒᵖ) : PreservesLimitsOfSize.{t, w} (coyoneda.obj X) where instance yonedaFunctor_preservesLimits : PreservesLimitsOfSize.{t, w} (@yoneda C _) := by apply preservesLimits_of_evaluation intro K change PreservesLimitsOfSize (coyoneda.obj K) infer_instance noncomputable instance coyonedaFunctor_preservesLimits : PreservesLimitsOfSize.{t, w} (@coyoneda C _) := by apply preservesLimits_of_evaluation intro K change PreservesLimitsOfSize (yoneda.obj K) infer_instance noncomputable instance yonedaFunctor_reflectsLimits : ReflectsLimitsOfSize.{t, w} (@yoneda C _) := inferInstance noncomputable instance coyonedaFunctor_reflectsLimits : ReflectsLimitsOfSize.{t, w} (@coyoneda C _) := inferInstance instance uliftYonedaFunctor_preservesLimits : PreservesLimitsOfSize.{t, w} (uliftYoneda.{w'} : C ⥤ _) := by apply preservesLimits_of_evaluation intro K change PreservesLimitsOfSize.{t, w} (coyoneda.obj K ⋙ uliftFunctor.{w'}) infer_instance namespace Functor section Representable variable (F : Cᵒᵖ ⥤ Type v) [F.IsRepresentable] {J : Type*} [Category J] instance representable_preservesLimit (G : J ⥤ Cᵒᵖ) : PreservesLimit G F := preservesLimit_of_natIso _ F.reprW variable (J) in instance representable_preservesLimitsOfShape : PreservesLimitsOfShape J F where instance representable_preservesLimits : PreservesLimitsOfSize.{t, w} F where end Representable section Corepresentable variable (F : C ⥤ Type v) [F.IsCorepresentable] {J : Type*} [Category J] instance corepresentable_preservesLimit (G : J ⥤ C) : PreservesLimit G F := preservesLimit_of_natIso _ F.coreprW variable (J) in instance corepresentable_preservesLimitsOfShape : PreservesLimitsOfShape J F where instance corepresentable_preservesLimits : PreservesLimitsOfSize.{t, w} F where end Corepresentable end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FunctorToTypes.lean
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Types.Colimits /-! # 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 ⥤ Type w) theorem jointly_surjective (k : K) {t : Cocone F} (h : IsColimit t) (x : t.pt.obj k) [∀ k, HasColimit (F.flip.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, HasColimit (F.flip.obj k)] (k : K) (x : (colimit F).obj k) : ∃ j y, x = (colimit.ι F j).app k y := jointly_surjective _ _ (colimit.isColimit _) x theorem colimit.map_ι_apply [HasColimit F] (j : J) {k k' : K} {f : k ⟶ k'} {x} : (colimit F).map f ((colimit.ι F j).app _ x) = (colimit.ι F j).app _ ((F.obj j).map f x) := congrFun ((colimit.ι F j).naturality _).symm _ end CategoryTheory.FunctorToTypes
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/HasLimits.lean
import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.CategoryTheory.Functor.EpiMono 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 [category theory 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. -/ 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 @[reassoc] theorem limit.π_comp_eqToHom (F : J ⥤ C) [HasLimit F] {j j' : J} (hj : j = j') : limit.π F j ≫ eqToHom (by subst hj; rfl) = limit.π F j' := by subst hj simp @[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] simp @[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] simp @[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 @[reassoc (attr := 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 cat_disch /-- If a functor `F` has a limit, so does any naturally isomorphic functor. -/ theorem hasLimit_of_iso {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) } theorem hasLimit_iff_of_iso {F G : J ⥤ C} (α : F ≅ G) : HasLimit F ↔ HasLimit G := ⟨fun _ ↦ hasLimit_of_iso α, fun _ ↦ hasLimit_of_iso α.symm⟩ -- 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.ofRepresentableBy ((limit.isLimit F).representableBy.ofIso 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] 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] 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 cat_disch 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 hasLimit_equivalence_comp (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 } -- 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 hasLimit_of_equivalence_comp (e : K ≌ J) [HasLimit (e.functor ⋙ F)] : HasLimit F := by haveI : HasLimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasLimit_equivalence_comp e.symm apply hasLimit_of_iso (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 simp map_comp α β := by apply Limits.limit.hom_ext; intro j simp [assoc] end variable {G : J ⥤ C} (α : F ⟶ G) theorem limMap_eq : limMap α = lim.map α := rfl 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 theorem limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (Functor.leftUnitor F).inv := by cat_disch 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 := Adjunction.mk' { homEquiv := fun c g ↦ { toFun := fun f => limit.lift _ ⟨c, f⟩ invFun := fun f => { app := fun _ => f ≫ limit.π _ _ } left_inv := by cat_disch right_inv := by cat_disch } unit := { app := fun _ => limit.lift _ ⟨_, 𝟙 _⟩ } counit := { app := fun g => { app := limit.π _ } } } 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.lean`: 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 [adj.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 hasLimit_of_equivalence_comp 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.{v₁} 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. -/ 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 @[reassoc] theorem colimit.eqToHom_comp_ι (F : J ⥤ C) [HasColimit F] {j j' : J} (hj : j = j') : eqToHom (by subst hj; rfl) ≫ colimit.ι F j = colimit.ι F j' := by subst hj simp @[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] simp @[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] simp @[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 ext; 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 hasColimit_of_iso {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) } theorem hasColimit_iff_of_iso {F G : J ⥤ C} (α : F ≅ G) : HasColimit F ↔ HasColimit G := ⟨fun _ ↦ hasColimit_of_iso α.symm, fun _ ↦ hasColimit_of_iso α⟩ /-- 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.ofCorepresentableBy ((colimit.isColimit F).corepresentableBy.ofIso 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] @[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.ι_inv_pre [IsIso (pre F E)] (k : K) : colimit.ι F (E.obj k) ≫ inv (colimit.pre F E) = colimit.ι (E ⋙ F) k := by simp [IsIso.comp_inv_eq] @[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 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 cat_disch 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 hasColimit_of_iso (e.invFunIdAssoc F).symm section ColimFunctor variable [HasColimitsOfShape J C] section /-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/ @[simps] def colim : (J ⥤ C) ⥤ C where obj F := colimit F map α := colimMap α end variable {G : J ⥤ C} (α : F ⟶ G) theorem colimMap_eq : colimMap α = colim.map α := rfl @[reassoc] theorem colimit.ι_map (j : J) : colimit.ι F j ≫ colim.map α = α.app j ≫ colimit.ι G j := by simp @[reassoc (attr := simp)] theorem colimit.map_desc (c : Cocone G) : colimMap α ≫ colimit.desc G c = colimit.desc F ((Cocones.precompose α).obj c) := by ext j simp [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 theorem colimit.pre_id (F : J ⥤ C) : colimit.pre F (𝟭 _) = colim.map (Functor.leftUnitor F).hom := by cat_disch 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 := Adjunction.mk' { homEquiv := fun f c ↦ { toFun := fun g => { app := fun _ => colimit.ι _ _ ≫ g } invFun := fun g => colimit.desc _ ⟨_, g⟩ left_inv := by cat_disch right_inv := by cat_disch } unit := { app := fun g => { app := colimit.ι _ } } counit := { app := fun _ => 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.{v₁} 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 (.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 (.op j)) uniq s m w := by dsimp rw [← P.uniq s.op m.op] · rfl · dsimp intro j rw [← w] rfl /-- If `t.op : Cocone F.op` is a colimit cocone, then `t : Cone F` is a limit cone. -/ def isLimitOfOp {t : Cone F} (P : IsColimit t.op) : IsLimit t := P.unop /-- If `t.op : Cone F.op` is a limit cone, then `t : Cocone F` is a colimit cocone. -/ def isColimitOfOp {t : Cocone F} (P : IsLimit t.op) : IsColimit t := P.unop /-- If `t.unop : Cocone F` is a colimit cocone, then `t : Cone F.op` is a limit cone. -/ def isLimitOfUnop {t : Cone F.op} (P : IsColimit t.unop) : IsLimit t := P.op /-- If `t.unop : Cone F` is a limit cone, then `t : Cocone F.op` is a colimit cocone. -/ def isColimitOfUnop {t : Cocone F.op} (P : IsLimit t.unop) : IsColimit t := P.op /-- `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 isLimitOfOp /-- `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 isColimitOfOp end Opposite end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/ColimitLimit.lean
import Mathlib.CategoryTheory.Limits.Types.Colimits import Mathlib.CategoryTheory.Limits.Types.Limits import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic /-! # 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 Functor 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 Prod theorem map_id_left_eq_curry_map {j : J} {k k' : K} {f : k ⟶ k'} : F.map (𝟙 j ×ₘ f) = ((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) = ((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
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/EssentiallySmall.lean
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
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Presentation.lean
import Mathlib.CategoryTheory.Limits.Connected import Mathlib.CategoryTheory.Limits.Final /-! # (Co)limit presentations Let `J` and `C` be categories and `X : C`. We define type `ColimitPresentation J X` that contains the data of objects `Dⱼ` and natural maps `sⱼ : Dⱼ ⟶ X` that make `X` the colimit of the `Dⱼ`. (See `Mathlib/CategoryTheory/Presentable/ColimitPresentation.lean` for the construction of a presentation of a colimit of objects that are equipped with presentations.) ## Main definitions: - `CategoryTheory.Limits.ColimitPresentation`: A colimit presentation of `X` over `J` is a diagram `{Dᵢ}` in `C` and natural maps `sᵢ : Dᵢ ⟶ X` making `X` into the colimit of the `Dᵢ`. - `CategoryTheory.Limits.LimitPresentation`: A limit presentation of `X` over `J` is a diagram `{Dᵢ}` in `C` and natural maps `sᵢ : X ⟶ Dᵢ` making `X` into the limit of the `Dᵢ`. ## TODOs: - Refactor `TransfiniteCompositionOfShape` so that it extends `ColimitPresentation`. -/ universe s t w v u namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] /-- A colimit presentation of `X` over `J` is a diagram `{Dᵢ}` in `C` and natural maps `sᵢ : Dᵢ ⟶ X` making `X` into the colimit of the `Dᵢ`. -/ structure ColimitPresentation (J : Type w) [Category.{t} J] (X : C) where /-- The diagram `{Dᵢ}`. -/ diag : J ⥤ C /-- The natural maps `sᵢ : Dᵢ ⟶ X`. -/ ι : diag ⟶ (Functor.const J).obj X /-- `X` is the colimit of the `Dᵢ` via `sᵢ`. -/ isColimit : IsColimit (Cocone.mk _ ι) variable {J : Type w} [Category.{t} J] {X : C} namespace ColimitPresentation initialize_simps_projections ColimitPresentation (-isColimit) /-- The cocone associated to a colimit presentation. -/ abbrev cocone (pres : ColimitPresentation J X) : Cocone pres.diag := Cocone.mk _ pres.ι lemma hasColimit (pres : ColimitPresentation J X) : HasColimit pres.diag := ⟨_, pres.isColimit⟩ /-- The canonical colimit presentation of any object over a point. -/ @[simps] noncomputable def self (X : C) : ColimitPresentation PUnit.{s + 1} X where diag := (Functor.const _).obj X ι := 𝟙 _ isColimit := isColimitConstCocone _ _ /-- If `F : J ⥤ C` is a functor that has a colimit, then this is the obvious colimit presentation of `colimit F`. -/ noncomputable def colimit (F : J ⥤ C) [HasColimit F] : ColimitPresentation J (colimit F) where diag := F ι := _ isColimit := colimit.isColimit _ /-- If `F` preserves colimits of shape `J`, it maps colimit presentations of `X` to colimit presentations of `F(X)`. -/ @[simps] noncomputable def map (P : ColimitPresentation J X) {D : Type*} [Category D] (F : C ⥤ D) [PreservesColimitsOfShape J F] : ColimitPresentation J (F.obj X) where diag := P.diag ⋙ F ι := Functor.whiskerRight P.ι F ≫ (F.constComp _ _).hom isColimit := (isColimitOfPreserves F P.isColimit).ofIsoColimit (Cocones.ext (.refl _) (by simp)) /-- If `P` is a colimit presentation of `X`, it is possible to define another colimit presentation of `X` where `P.diag` is replaced by an isomorphic functor. -/ @[simps] def changeDiag (P : ColimitPresentation J X) {F : J ⥤ C} (e : F ≅ P.diag) : ColimitPresentation J X where diag := F ι := e.hom ≫ P.ι isColimit := (IsColimit.precomposeHomEquiv e _).2 P.isColimit /-- Map a colimit presentation under an isomorphism. -/ @[simps] def ofIso (P : ColimitPresentation J X) {Y : C} (e : X ≅ Y) : ColimitPresentation J Y where diag := P.diag ι := P.ι ≫ (Functor.const J).map e.hom isColimit := P.isColimit.ofIsoColimit (Cocones.ext e fun _ ↦ rfl) /-- Change the index category of a colimit presentation. -/ @[simps] noncomputable def reindex (P : ColimitPresentation J X) {J' : Type*} [Category J'] (F : J' ⥤ J) [F.Final] : ColimitPresentation J' X where diag := F ⋙ P.diag ι := F.whiskerLeft P.ι isColimit := (Functor.Final.isColimitWhiskerEquiv F _).symm P.isColimit end ColimitPresentation /-- A limit presentation of `X` over `J` is a diagram `{Dᵢ}` in `C` and natural maps `sᵢ : X ⟶ Dᵢ` making `X` into the limit of the `Dᵢ`. -/ structure LimitPresentation (J : Type w) [Category.{t} J] (X : C) where /-- The diagram `{Dᵢ}`. -/ diag : J ⥤ C /-- The natural maps `sᵢ : X ⟶ Dᵢ`. -/ π : (Functor.const J).obj X ⟶ diag /-- `X` is the limit of the `Dᵢ` via `sᵢ`. -/ isLimit : IsLimit (Cone.mk _ π) variable {J : Type w} [Category.{t} J] {X : C} namespace LimitPresentation initialize_simps_projections LimitPresentation (-isLimit) /-- The cone associated to a limit presentation. -/ abbrev cone (pres : LimitPresentation J X) : Cone pres.diag := Cone.mk _ pres.π lemma hasLimit (pres : LimitPresentation J X) : HasLimit pres.diag := ⟨_, pres.isLimit⟩ /-- The canonical limit presentation of any object over a point. -/ @[simps] noncomputable def self (X : C) : LimitPresentation PUnit.{s + 1} X where diag := (Functor.const _).obj X π := 𝟙 _ isLimit := isLimitConstCone _ _ /-- If `F : J ⥤ C` is a functor that has a limit, then this is the obvious limit presentation of `limit F`. -/ noncomputable def limit (F : J ⥤ C) [HasLimit F] : LimitPresentation J (limit F) where diag := F π := _ isLimit := limit.isLimit _ /-- If `F` preserves limits of shape `J`, it maps limit presentations of `X` to limit presentations of `F(X)`. -/ @[simps] noncomputable def map (P : LimitPresentation J X) {D : Type*} [Category D] (F : C ⥤ D) [PreservesLimitsOfShape J F] : LimitPresentation J (F.obj X) where diag := P.diag ⋙ F π := (F.constComp _ _).inv ≫ Functor.whiskerRight P.π F isLimit := (isLimitOfPreserves F P.isLimit).ofIsoLimit (Cones.ext (.refl _) (by simp)) /-- If `P` is a limit presentation of `X`, it is possible to define another limit presentation of `X` where `P.diag` is replaced by an isomorphic functor. -/ @[simps] def changeDiag (P : LimitPresentation J X) {F : J ⥤ C} (e : F ≅ P.diag) : LimitPresentation J X where diag := F π := P.π ≫ e.inv isLimit := (IsLimit.postcomposeHomEquiv e.symm _).2 P.isLimit /-- Map a limit presentation under an isomorphism. -/ @[simps] def ofIso (P : LimitPresentation J X) {Y : C} (e : X ≅ Y) : LimitPresentation J Y where diag := P.diag π := (Functor.const J).map e.inv ≫ P.π isLimit := P.isLimit.ofIsoLimit (Cones.ext e) /-- Change the index category of a limit presentation. -/ @[simps] noncomputable def reindex (P : LimitPresentation J X) {J' : Type*} [Category J'] (F : J' ⥤ J) [F.Initial] : LimitPresentation J' X where diag := F ⋙ P.diag π := F.whiskerLeft P.π isLimit := (Functor.Initial.isLimitWhiskerEquiv F _).symm P.isLimit end LimitPresentation end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FormalCoproducts.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Products import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Formal Coproducts In this file we construct the category of formal coproducts given a category. ## Main definitions * `FormalCoproduct`: the category of formal coproducts, which are indexed sets of objects in a category. A morphism `∐ i : X.I, X.obj i ⟶ ∐ j : Y.I, Y.obj j` is given by a function `f : X.I → Y.I` and maps `X.obj i ⟶ Y.obj (f i)` for each `i : X.I`. * `FormalCoproduct.eval : (Cᵒᵖ ⥤ A) ⥤ ((FormalCoproduct C)ᵒᵖ ⥤ A)`: the universal property that a presheaf on `C` where the target category has arbitrary coproducts, can be extended to a presheaf on `FormalCoproduct C`. ## TODO * `FormalCoproduct.incl C : C ⥤ FormalCoproduct.{w} C` probably preserves every limit? -/ universe w w₁ w₂ w₃ v v₁ v₂ v₃ u u₁ u₂ u₃ open Opposite CategoryTheory Functor namespace CategoryTheory namespace Limits variable {C : Type u} [Category.{v} C] (A : Type u₁) [Category.{v₁} A] variable (C) in /-- A formal coproduct is an indexed set of objects, where ⟨I, f⟩ corresponds to the "formal coproduct" `⨿ (i : I), f i`, where `f i : C` is the `i`ᵗʰ component. -/ structure FormalCoproduct where /-- The indexing type. -/ I : Type w /-- The object in the original category indexed by `x : I`. -/ obj (i : I) : C namespace FormalCoproduct /-- A morphism `(⨿ (i : X.I), X.obj i) ⟶ (⨿ (j : Y.I), Y.obj i)` is given by first a function on the indexing sets `f : X.I → Y.I`, and then for each `i : X.I` a morphism `X.obj i ⟶ Y.obj (f i)`. -/ structure Hom (X Y : FormalCoproduct.{w} C) where /-- The function on the indexing sets. -/ f : X.I → Y.I /-- The map on each component. -/ φ (i : X.I) : X.obj i ⟶ Y.obj (f i) -- this category identifies to the fullsubcategory of the category of -- presheaves of sets on `C` which are coproducts of representable presheaves @[simps!] instance category : Category (FormalCoproduct.{w} C) where Hom := Hom id X := { f := id, φ := fun _ ↦ 𝟙 _ } comp α β := { f := β.f ∘ α.f, φ := fun _ ↦ α.φ _ ≫ β.φ _ } @[ext (iff := false)] lemma hom_ext {X Y : FormalCoproduct.{w} C} {f g : X ⟶ Y} (h₁ : f.f = g.f) (h₂ : ∀ (i : X.I), f.φ i ≫ eqToHom (by rw [h₁]) = g.φ i) : f = g := by obtain ⟨f, F⟩ := f obtain ⟨g, G⟩ := g obtain rfl : f = g := h₁ obtain rfl : F = G := by ext i; simpa using h₂ i rfl lemma hom_ext_iff {X Y : FormalCoproduct.{w} C} (f g : X ⟶ Y) : f = g ↔ ∃ h₁ : f.f = g.f, ∀ (i : X.I), f.φ i ≫ eqToHom (by rw [h₁]) = g.φ i := ⟨(· ▸ by simp), fun ⟨h₁, h₂⟩ ↦ hom_ext h₁ h₂⟩ lemma hom_ext_iff' {X Y : FormalCoproduct.{w} C} (f g : X ⟶ Y) : f = g ↔ ∀ i : X.I, ∃ h₁ : f.f i = g.f i, f.φ i ≫ eqToHom (by rw [h₁]) = g.φ i := ⟨(· ▸ by simp), fun h ↦ hom_ext (funext fun i ↦ (h i).fst) fun i ↦ (h i).snd⟩ /-- A way to create isomorphisms in the category of formal coproducts, by creating an `Equiv` between the indexing sets, and then correspondingly isomorphisms of each component. -/ @[simps!] def isoOfComponents {X Y : FormalCoproduct.{w} C} (e : X.I ≃ Y.I) (h : ∀ i, X.obj i ≅ Y.obj (e i)) : X ≅ Y where hom := { f := e, φ := fun i ↦ (h i).hom } inv := { f := e.symm, φ := fun i ↦ eqToHom (by simp) ≫ (h (e.symm i)).inv } hom_inv_id := by ext <;> aesop inv_hom_id := by ext <;> aesop variable (C) in /-- An object of the original category produces a formal coproduct on that object only, so indexed by `PUnit`, the type with one element. -/ @[simps!] def incl : C ⥤ FormalCoproduct.{w} C where obj X := ⟨PUnit, fun _ ↦ X⟩ map f := ⟨fun _ ↦ PUnit.unit, fun _ ↦ f⟩ section fromIncl variable {X : C} {Y : FormalCoproduct.{w} C} /-- A map `incl(X) ⟶ Y` is specified by an element of `Y`'s indexing set, and then a morphism `X ⟶ Y.obj i` in the original category. -/ @[simps!] def Hom.fromIncl (i : Y.I) (f : X ⟶ Y.obj i) : (incl C).obj X ⟶ Y := ⟨fun _ ↦ i, fun _ ↦ f⟩ /-- A map `incl(X) ⟶ Y` is specified by an element of `Y`'s indexing set, and then a morphism `X ⟶ Y.obj i` in the original category. -/ def Hom.asSigma (f : (incl C).obj X ⟶ Y) : Σ (i : Y.I), X ⟶ Y.obj i := ⟨f.f PUnit.unit, f.φ PUnit.unit⟩ lemma Hom.fromIncl_asSigma (f : (incl C).obj X ⟶ Y) : Hom.fromIncl f.asSigma.fst f.asSigma.snd = f := by ext <;> aesop end fromIncl -- This is probably some form of adjunction? /-- A map `incl(X) ⟶ Y` is specified by an element of `Y`'s indexing set, and then a morphism `X ⟶ Y.obj i` in the original category. -/ @[simps!] def inclHomEquiv (X : C) (Y : FormalCoproduct.{w} C) : ((incl C).obj X ⟶ Y) ≃ (i : Y.I) × (X ⟶ Y.obj i) where toFun f := f.asSigma invFun f := .fromIncl f.1 f.2 left_inv f := f.fromIncl_asSigma right_inv _ := rfl /-- `incl` is fully faithful, which means that `(X ⟶ Y) ≃ (incl(X) ⟶ incl(Y))`. -/ @[simps!] def fullyFaithfulIncl : (incl C).FullyFaithful where preimage f := f.φ PUnit.unit instance : (incl C).Full := fullyFaithfulIncl.full instance : (incl C).Faithful := fullyFaithfulIncl.faithful /-- A family of maps with the same target can be turned into one arrow in the category of formal coproducts. This is used in Čech cohomology. -/ @[simps!] def homOfPiHom (X : C) {J : Type w} (f : (j : J) → C) (φ : (j : J) → f j ⟶ X) : FormalCoproduct.mk _ f ⟶ (incl C).obj X := ⟨fun _ ↦ PUnit.unit, φ⟩ section Coproduct variable (𝒜 : Type w) (f : 𝒜 → FormalCoproduct.{w} C) (t X : FormalCoproduct.{w} C) /-- We construct explicitly the data that specify the coproduct of a given family of formal coproducts. -/ def cofan : Cofan f := Cofan.mk ⟨(i : 𝒜) × (f i).I, fun p ↦ (f p.1).obj p.2⟩ fun i ↦ ⟨fun x ↦ ⟨i, x⟩, fun x ↦ 𝟙 ((f i).obj x)⟩ section simp_lemmas variable {𝒜 f} theorem cofan_inj (i : 𝒜) : (cofan 𝒜 f).inj i = ⟨fun x ↦ ⟨i, x⟩, fun x ↦ 𝟙 ((f i).obj x)⟩ := rfl @[simp] lemma cofan_inj_f_fst (i : 𝒜) (x) : (((cofan 𝒜 f).inj i).f x).1 = i := rfl @[simp] lemma cofan_inj_f_snd (i : 𝒜) (x) : (((cofan 𝒜 f).inj i).f x).2 = x := rfl @[simp] lemma cofan_inj_φ (i : 𝒜) (x) : ((cofan 𝒜 f).inj i).φ x = 𝟙 ((f i).obj x) := rfl end simp_lemmas /-- The explicit `Equiv` between maps from the constructed coproduct `cofan 𝒜 f` and families of maps from each component, which is the universal property of coproducts. -/ @[simps!] def cofanHomEquiv : ((cofan 𝒜 f).pt ⟶ t) ≃ ((i : 𝒜) → (f i ⟶ t)) where toFun m i := (cofan 𝒜 f).inj i ≫ m invFun s := ⟨fun p ↦ (s p.1).f p.2, fun p ↦ (s p.1).φ p.2⟩ left_inv m := hom_ext rfl (fun ⟨i, x⟩ ↦ by simp [cofan_inj]) right_inv p := by ext <;> simp /-- `cofan 𝒜 f` is a coproduct of `f`. -/ @[simps!] def isColimitCofan : IsColimit (cofan 𝒜 f) := mkCofanColimit (cofan 𝒜 f) (fun t ↦ (cofanHomEquiv _ _ _).symm t.inj) (fun t i ↦ congrFun ((cofanHomEquiv _ _ _).right_inv t.inj) i) (fun _ _ h ↦ (Equiv.eq_symm_apply _).2 (funext h)) instance : HasCoproducts.{w} (FormalCoproduct.{w} C) := hasCoproducts_of_colimit_cofans _ (isColimitCofan _) /-- The arbitrary choice of the coproduct is isomorphic to our constructed coproduct `cofan 𝒜 f`. -/ noncomputable def coproductIsoCofanPt : ∐ f ≅ (cofan 𝒜 f).pt := colimit.isoColimitCocone ⟨_, isColimitCofan _ _⟩ variable {𝒜 f} in @[reassoc (attr := simp)] lemma ι_comp_coproductIsoCofanPt (i) : Sigma.ι f i ≫ (coproductIsoCofanPt 𝒜 f).hom = (cofan 𝒜 f).inj i := colimit.isoColimitCocone_ι_hom _ _ /-- Each `X : FormalCoproduct.{w} C` is actually itself a coproduct of objects of the original category (after coercion using `incl C`). This is the function that specifies the family for which `X` is a coproduct of. -/ def toFun (X : FormalCoproduct.{w} C) : X.I → FormalCoproduct.{w} C := (incl C).obj ∘ X.obj /-- The witness that each `X : FormalCoproduct.{w} C` is itself a coproduct of objects of the original category (after coercion using `incl C`), specified by `X.toFun`. -/ def cofanPtIsoSelf : (cofan X.I X.toFun).pt ≅ X := isoOfComponents (Equiv.sigmaPUnit X.I) fun i ↦ Iso.refl (X.obj i.fst) @[reassoc (attr := simp)] lemma inj_comp_cofanPtIsoSelf_hom (i : X.I) : (cofan X.I X.toFun).inj i ≫ (cofanPtIsoSelf X).hom = .fromIncl i (𝟙 (X.obj i)) := hom_ext rfl (fun i => by aesop) @[reassoc (attr := simp)] lemma fromIncl_comp_cofanPtIsoSelf_inv (i : X.I) : Hom.fromIncl i (𝟙 (X.obj i)) ≫ (cofanPtIsoSelf X).inv = (cofan X.I X.toFun).inj i := (Iso.comp_inv_eq _).2 (inj_comp_cofanPtIsoSelf_hom _ _).symm /-- The isomorphism between the coproduct of `X.toFun` and the object `X` itself. -/ @[simps!] noncomputable def coproductIsoSelf : ∐ X.toFun ≅ X := coproductIsoCofanPt _ _ ≪≫ cofanPtIsoSelf X @[reassoc (attr := simp)] lemma ι_comp_coproductIsoSelf_hom (i : X.I) : Sigma.ι _ i ≫ (coproductIsoSelf X).hom = .fromIncl i (𝟙 (X.obj i)) := by simp [coproductIsoSelf] @[reassoc (attr := simp)] lemma fromIncl_comp_coproductIsoSelf_inv (i : X.I) : Hom.fromIncl i (𝟙 (X.obj i)) ≫ (coproductIsoSelf X).inv = Sigma.ι X.toFun i := (Iso.comp_inv_eq _).2 (ι_comp_coproductIsoSelf_hom _ _).symm end Coproduct section Terminal /-- Given a terminal object `T` in the original category, we show that `incl(T)` is a terminal object in the category of formal coproducts. -/ def isTerminalIncl (T : C) (ht : IsTerminal T) : IsTerminal ((incl C).obj T) := IsTerminal.ofUniqueHom (fun _ ↦ ⟨fun _ ↦ PUnit.unit, fun _ ↦ ht.from _⟩) (fun _ _ ↦ hom_ext (funext fun _ ↦ rfl) (fun _ ↦ ht.hom_ext _ _)) instance [HasTerminal C] : HasTerminal (FormalCoproduct.{w} C) := (isTerminalIncl (⊤_ C) terminalIsTerminal).hasTerminal end Terminal section Pullback variable {X Y Z : FormalCoproduct.{w} C} (f : X ⟶ Z) (g : Y ⟶ Z) (pb : ∀ i : Function.Pullback f.f g.f, PullbackCone (f.φ i.1.1 ≫ eqToHom (by rw [i.2])) (g.φ i.1.2)) (hpb : ∀ i, IsLimit (pb i)) (T : FormalCoproduct.{w} C) /-- Given two morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`, given pullback in `C` over each component, construct the pullback in `FormalCategory.{w} C`. -/ def pullbackCone : PullbackCone f g := .mk (W := ⟨Function.Pullback f.f g.f, fun i ↦ (pb i).pt⟩) ⟨fun i ↦ i.1.fst, fun i ↦ (pb i).fst⟩ ⟨fun i ↦ i.1.snd, fun i ↦ (pb i).snd⟩ (hom_ext (funext fun i ↦ i.2) (fun i ↦ by simp [(pb i).condition])) section simp_lemmas @[simp] lemma pullbackCone_fst_f (i) : (pullbackCone f g pb).fst.f i = i.1.1 := rfl @[simp] lemma pullbackCone_fst_φ (i) : (pullbackCone f g pb).fst.φ i = (pb i).fst := rfl @[simp] lemma pullbackCone_snd_f (i) : (pullbackCone f g pb).snd.f i = i.1.2 := rfl @[simp] lemma pullbackCone_snd_φ (i) : (pullbackCone f g pb).snd.φ i = (pb i).snd := rfl @[simp] lemma pullbackCone_condition : (pullbackCone f g pb).fst ≫ f = (pullbackCone f g pb).snd ≫ g := PullbackCone.condition _ end simp_lemmas /-- The `Equiv` that witnesses that `pullbackCone f g pb` is actually a pullback. This is the universal property of pullbacks. -/ @[simps!] def homPullbackEquiv : (T ⟶ (pullbackCone f g pb).pt) ≃ { p : (T ⟶ X) × (T ⟶ Y) // p.1 ≫ f = p.2 ≫ g } where toFun m := ⟨⟨m ≫ (pullbackCone f g pb).fst, m ≫ (pullbackCone f g pb).snd⟩, by simp⟩ invFun s := ⟨fun i ↦ ⟨(s.1.1.f i, s.1.2.f i), congrFun (congrArg Hom.f s.2) i⟩, fun i ↦ (hpb _).lift (PullbackCone.mk (s.1.1.φ i) (s.1.2.φ i) (by simpa using ((hom_ext_iff _ _).1 s.2).2 i))⟩ left_inv m := hom_ext rfl (fun i ↦ by simp only [category_comp_f, category_comp_φ, eqToHom_refl, Category.comp_id] exact (hpb _).hom_ext ((pb _).equalizer_ext (by aesop) (by aesop))) right_inv s := by ext <;> simp /-- `pullbackCone f g pb` is a pullback. -/ def isLimitPullbackCone : IsLimit (pullbackCone f g pb) := by refine PullbackCone.IsLimit.mk (fst := (pullbackCone f g pb).fst) (snd := (pullbackCone f g pb).snd) _ (fun s ↦ (homPullbackEquiv f g pb hpb s.pt).2 ⟨(s.fst, s.snd), s.condition⟩) (fun s ↦ congrArg (·.1.fst) ((homPullbackEquiv f g pb hpb s.pt).right_inv ⟨(s.fst, s.snd), s.condition⟩)) (fun s ↦ congrArg (·.1.snd) ((homPullbackEquiv f g pb hpb s.pt).right_inv ⟨(s.fst, s.snd), s.condition⟩)) (fun s m h₁ h₂ ↦ ?_) convert ((homPullbackEquiv f g pb hpb s.pt).left_inv m).symm using 3 rw [← h₁, ← h₂]; rfl -- Arguments cannot be inferred. include pb hpb in theorem hasPullback_of_pullbackCone : HasPullback f g := ⟨⟨⟨_, isLimitPullbackCone f g pb hpb⟩⟩⟩ include hpb in lemma isPullback : IsPullback (pullbackCone f g pb).fst (pullbackCone f g pb).snd f g := ⟨⟨pullbackCone_condition f g pb⟩, ⟨isLimitPullbackCone f g pb hpb⟩⟩ omit pb variable [HasPullbacks C] instance : HasPullback f g := hasPullback_of_pullbackCone f g (fun _ ↦ pullback.cone _ _) (fun _ ↦ pullback.isLimit _ _) instance : HasPullbacks (FormalCoproduct.{w} C) := hasPullbacks_of_hasLimit_cospan _ end Pullback noncomputable section HasCoproducts variable [HasCoproducts.{w} A] (C) (J : Type w) (f : J → FormalCoproduct.{w} C) (F : C ⥤ A) /-- A copresheaf valued in a category `A` with arbitrary coproducts, can be extended to the category of formal coproducts. -/ @[simps!] def eval : (C ⥤ A) ⥤ (FormalCoproduct.{w} C ⥤ A) where obj F := { obj X := ∐ fun (i : X.I) ↦ F.obj (X.obj i) map {X Y} f := Sigma.desc fun i ↦ F.map (f.φ i) ≫ Sigma.ι (F.obj ∘ Y.obj) (f.f i) map_comp _ _ := Sigma.hom_ext _ _ (fun _ ↦ by simp [Sigma.ι_desc]) } map α := { app f := Sigma.map fun i ↦ α.app (f.obj i) } /-- `eval(F)` restricted to the original category (via `incl`) is the original copresheaf `F`. -/ @[simps!] def evalCompInclIsoId : eval C A ⋙ (whiskeringLeft _ _ A).obj (incl C) ≅ Functor.id (C ⥤ A) := NatIso.ofComponents fun F ↦ NatIso.ofComponents (fun x ↦ ⟨Sigma.desc fun _ ↦ 𝟙 _, Sigma.ι (fun _ ↦ F.obj x) PUnit.unit, by aesop, by simp⟩) (fun f ↦ Sigma.hom_ext _ _ (by simp [Sigma.ι_desc])) variable {C A} /-- `eval(F)` preserves arbitrary coproducts. -/ def isColimitEvalMapCoconeCofan : IsColimit (((eval.{w} C A).obj F).mapCocone (cofan.{w} J f)) where desc s := Sigma.desc fun i ↦ Sigma.ι (F.obj ∘ (f i.1).obj) i.2 ≫ s.ι.app ⟨i.1⟩ fac s i := Sigma.hom_ext _ _ fun i ↦ by simp [cofan, Function.comp_def] uniq s m h := Sigma.hom_ext _ _ fun ⟨i₁, i₂⟩ ↦ by simp [← h, cofan, Function.comp_def] instance : PreservesColimit (Discrete.functor f) ((eval.{w} C A).obj F) := ⟨fun hc ↦ ⟨IsColimit.ofIsoColimit (isColimitEvalMapCoconeCofan J f F) ((Cocones.functoriality _ _).mapIso ((isColimitCofan J f).uniqueUpToIso hc))⟩⟩ instance : PreservesColimitsOfShape (Discrete J) ((eval.{w} C A).obj F) := preservesColimitsOfShape_of_discrete _ end HasCoproducts noncomputable section HasProducts variable [HasProducts.{w} A] (C) (J : Type w) (f : J → FormalCoproduct.{w} C) (F : Cᵒᵖ ⥤ A) /-- A presheaf valued in a category `A` with arbitrary products can be extended to the category of formal coproducts. -/ @[simps!] def evalOp : (Cᵒᵖ ⥤ A) ⥤ ((FormalCoproduct.{w} C)ᵒᵖ ⥤ A) where obj F := { obj X := ∏ᶜ fun (i : X.unop.I) ↦ F.obj (op (X.unop.obj i)) map f := Pi.lift fun i ↦ Pi.π _ (f.unop.f i) ≫ F.map (f.unop.φ i).op } map α := { app f := Pi.map fun i ↦ α.app (op (f.unop.obj i)) } /-- `evalOp(F)` restricted to the original category (via `incl`) is the original presheaf `F`. -/ @[simps!] def evalOpCompInlIsoId : evalOp C A ⋙ (whiskeringLeft _ _ A).obj (incl C).op ≅ Functor.id (Cᵒᵖ ⥤ A) := NatIso.ofComponents fun F ↦ NatIso.ofComponents fun x ↦ ⟨Pi.π _ PUnit.unit, Pi.lift fun _ ↦ 𝟙 _, by aesop, by simp⟩ variable {C A} /-- `evalOp(F)` preserves arbitrary products. -/ def isLimitEvalMapConeCofanOp : IsLimit (((evalOp.{w} C A).obj F).mapCone (cofan.{w} J f).op) where lift s := Pi.lift fun i ↦ s.π.app ⟨i.1⟩ ≫ Pi.π _ i.2 fac s i := Pi.hom_ext _ _ fun i ↦ by simp [cofan] uniq s m h := Pi.hom_ext _ _ fun ⟨i₁, i₂⟩ ↦ by simp [← h, cofan] instance : PreservesLimit (Discrete.functor (op ∘ f)) ((evalOp.{w} C A).obj F) := ⟨fun hc ↦ ⟨IsLimit.ofIsoLimit (isLimitEvalMapConeCofanOp J f F) ((Cones.functoriality _ _).mapIso ((Cofan.IsColimit.op (isColimitCofan J f)).uniqueUpToIso hc))⟩⟩ end HasProducts end FormalCoproduct end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/EpiMono.lean
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φ₁⟩ · simp only [assoc, hφ₁, id_comp, comp_id] · 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 ?_ ?_⟩ · simp only [comp_id, reassoc_of% hφ₁] · 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
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Fubini.lean
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. -/ open CategoryTheory Functor namespace CategoryTheory.Limits variable {J K : Type*} [Category J] [Category K] variable {C : Type*} [Category C] variable (F : J ⥤ K ⥤ C) (G : 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 cat_disch comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by cat_disch /-- 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 cat_disch comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by cat_disch 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 simpa using @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j, k') (𝟙 j, f) } } naturality := fun j j' f => (Q j').hom_ext (fun k => by simpa using @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j', k) (f, 𝟙 k)) } /-- Given a diagram `D` of limit cones over the `curry.obj G j`, and a cone over `G`, we can construct a cone over the diagram consisting of the cone points from `D`. -/ @[simps] def coneOfConeCurry {D : DiagramOfCones (curry.obj G)} (Q : ∀ j, IsLimit (D.obj j)) (c : Cone G) : Cone D.conePoints where pt := c.pt π := { app j := (Q j).lift { pt := c.pt π := { app k := c.π.app (j, k) } } naturality {_ j'} _ := (Q j').hom_ext (by simp) } open scoped Prod in /-- 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)] 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, NatTrans.comp_app, Category.comp_id, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.ι (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.comp_id, CategoryTheory.Functor.map_id] at this exact this) } /-- Given a diagram `D` of colimit cocones under the `curry.obj G j`, and a cocone under `G`, we can construct a cocone under the diagram consisting of the cocone points from `D`. -/ @[simps] def coconeOfCoconeCurry {D : DiagramOfCocones (curry.obj G)} (Q : ∀ j, IsColimit (D.obj j)) (c : Cocone G) : Cocone D.coconePoints where pt := c.pt ι := { app j := (Q j).desc { pt := c.pt ι := { app k := c.ι.app (j, k) } } naturality {j _} _ := (Q j).hom_ext (by simp) } /-- `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 /-- If `coneOfConeUncurry Q c` is a limit cone then `c` is in fact a limit cone. -/ def IsLimit.ofConeOfConeUncurry {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) {c : Cone (uncurry.obj F)} (P : IsLimit (coneOfConeUncurry Q c)) : IsLimit c := -- These constructions are used in various fields of the proof so we abstract them here. letI E (j : J) : Prod.sectR j K ⋙ uncurry.obj F ≅ F.obj j := NatIso.ofComponents (fun _ ↦ Iso.refl _) letI S (s : Cone (uncurry.obj F)) : Cone D.conePoints := { pt := s.pt π := { app j := (Q j).lift <| (Cones.postcompose (E j).hom).obj <| s.whisker (Prod.sectR j K) naturality {j' j} f := (Q j).hom_ext <| fun k ↦ by simpa [E] using s.π.naturality ((Prod.sectL J k).map f) } } { lift s := P.lift (S s) fac s p := by have h1 := (Q p.1).fac ((Cones.postcompose (E p.1).hom).obj <| s.whisker (Prod.sectR p.1 K)) p.2 simp only [Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, Cones.postcompose_obj_pt, Cone.whisker_pt, Cones.postcompose_obj_π, Cone.whisker_π, NatTrans.comp_app, Functor.const_obj_obj, whiskerLeft_app, NatIso.ofComponents_hom_app, Iso.refl_hom, Category.comp_id, E] at h1 have h2 := (P.fac (S s) p.1) dsimp only [Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, NatTrans.id_app, Functor.const_obj_obj, DiagramOfCones.conePoints_obj, DiagramOfCones.conePoints_map, Functor.const_obj_map, id_eq, Cones.postcompose_obj_pt, Cone.whisker_pt, Cones.postcompose_obj_π, Cone.whisker_π, NatTrans.comp_app, whiskerLeft_app, NatIso.ofComponents_hom_app, Iso.refl_hom, Prod.sectL_obj, Prod.sectL_map, eq_mp_eq_cast, eq_mpr_eq_cast, coneOfConeUncurry_pt, coneOfConeUncurry_π_app, S, E] at h2 ⊢ simp [← h1, ← h2] uniq s f hf := P.uniq (s := S s) _ <| fun j ↦ (Q j).hom_ext <| fun k ↦ by simpa [S, E] using hf (j, k) } /-- `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.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.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 /-- If `coconeOfCoconeUncurry Q c` is a colimit cocone then `c` is in fact a colimit cocone. -/ def IsColimit.ofCoconeUncurry {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) {c : Cocone (uncurry.obj F)} (P : IsColimit (coconeOfCoconeUncurry Q c)) : IsColimit c := -- These constructions are used in various fields of the proof so we abstract them here. letI E (j : J) : (Prod.sectR j K ⋙ uncurry.obj F ≅ F.obj j) := NatIso.ofComponents (fun _ ↦ Iso.refl _) letI S (s : Cocone (uncurry.obj F)) : Cocone D.coconePoints := { pt := s.pt ι := { app j := (Q j).desc <| (Cocones.precompose (E j).inv).obj <| s.whisker (Prod.sectR j K) naturality {j j'} f := (Q j).hom_ext <| fun k ↦ by simpa [E] using s.ι.naturality ((Prod.sectL J k).map f) } } { desc s := P.desc (S s) fac s p := by have h1 := (Q p.1).fac ((Cocones.precompose (E p.1).inv).obj <| s.whisker (Prod.sectR p.1 K)) p.2 simp only [Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, Cocones.precompose_obj_pt, Cocone.whisker_pt, Functor.const_obj_obj, Cocones.precompose_obj_ι, Cocone.whisker_ι, NatTrans.comp_app, NatIso.ofComponents_inv_app, Iso.refl_inv, whiskerLeft_app, Category.id_comp, E] at h1 have h2 := (P.fac (S s) p.1) dsimp only [DiagramOfCocones.coconePoints_obj, Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, NatTrans.id_app, Functor.const_obj_obj, DiagramOfCocones.coconePoints_map, Functor.const_obj_map, id_eq, Cocones.precompose_obj_pt, Cocone.whisker_pt, Cocones.precompose_obj_ι, Cocone.whisker_ι, NatTrans.comp_app, NatIso.ofComponents_inv_app, Iso.refl_inv, whiskerLeft_app, Prod.sectL_obj, Prod.sectL_map, eq_mp_eq_cast, eq_mpr_eq_cast, coconeOfCoconeUncurry_pt, coconeOfCoconeUncurry_ι_app, S, E] at h2 ⊢ simp [← h1, ← h2] uniq s f hf := P.uniq (s := S s) _ <| fun j ↦ (Q j).hom_ext <| fun k ↦ by simpa [S, E] using hf (j, k) } 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 section variable [HasLimit (curry.obj G ⋙ lim)] /-- Given a functor `G : J × K ⥤ C` such that `(curry.obj G ⋙ lim)` makes sense and has a limit, we can construct a cone over `G` with `limit (curry.obj G ⋙ lim)` as a cone point -/ noncomputable def coneOfHasLimitCurryCompLim : Cone G := let Q : DiagramOfCones (curry.obj G) := .mkOfHasLimits _ { pt := limit (curry.obj G ⋙ lim), π := { app x := limit.π (curry.obj G ⋙ lim) x.fst ≫ (Q.obj x.fst).π.app x.snd naturality {x y} := fun ⟨f₁, f₂⟩ ↦ by have := (Q.obj x.1).w f₂ dsimp [Q] at this ⊢ rw [← limit.w (F := curry.obj G ⋙ lim) (f := f₁)] dsimp simp only [Category.assoc, Category.id_comp, Prod.fac (f₁, f₂), G.map_comp, limMap_π, curry_obj_map_app, reassoc_of% this] } } /-- The cone `coneOfHasLimitCurryCompLim` is in fact a limit cone. -/ noncomputable def isLimitConeOfHasLimitCurryCompLim : IsLimit (coneOfHasLimitCurryCompLim G) := let Q : DiagramOfCones (curry.obj G) := .mkOfHasLimits _ let Q' : ∀ j, IsLimit (Q.obj j) := fun j => limit.isLimit _ { lift c' := limit.lift (F := curry.obj G ⋙ lim) (coneOfConeCurry G Q' c') fac c' f := by simp [coneOfHasLimitCurryCompLim, Q, Q'] uniq c' f h := by dsimp [coneOfHasLimitCurryCompLim] at f h ⊢ refine limit.hom_ext (F := curry.obj G ⋙ lim) (fun j ↦ limit.hom_ext (fun k ↦ ?_)) simp [h ⟨j, k⟩, Q'] } /-- The functor `G` has a limit if `C` has `K`-shaped limits and `(curry.obj G ⋙ lim)` has a limit. -/ instance : HasLimit G where exists_limit := ⟨ { cone := coneOfHasLimitCurryCompLim G isLimit := isLimitConeOfHasLimitCurryCompLim G }⟩ end variable [HasLimit (uncurry.obj F)] [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 @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_inv_π {j} {k} : (limitUncurryIsoLimitCompLim F).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k) := 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 section variable [HasColimit (curry.obj G ⋙ colim)] /-- Given a functor `G : J × K ⥤ C` such that `(curry.obj G ⋙ colim)` makes sense and has a colimit, we can construct a cocone under `G` with `colimit (curry.obj G ⋙ colim)` as a cocone point -/ noncomputable def coconeOfHasColimitCurryCompColim : Cocone G := let Q : DiagramOfCocones (curry.obj G) := .mkOfHasColimits _ { pt := colimit (curry.obj G ⋙ colim), ι := { app x := (Q.obj x.fst).ι.app x.snd ≫ colimit.ι (curry.obj G ⋙ colim) x.fst naturality {x y} := fun ⟨f₁, f₂⟩ ↦ by have := (Q.obj y.1).w f₂ dsimp [Q] at this ⊢ rw [← colimit.w (F := curry.obj G ⋙ colim) (f := f₁), Category.assoc, Category.comp_id, Prod.fac' (f₁, f₂), G.map_comp_assoc, ← curry_obj_map_app, ← curry_obj_obj_map] dsimp simp [ι_colimMap_assoc, curry_obj_map_app, reassoc_of% this]} } /-- The cocone `coconeOfHasColimitCurryCompColim` is in fact a limit cocone. -/ noncomputable def isColimitCoconeOfHasColimitCurryCompColim : IsColimit (coconeOfHasColimitCurryCompColim G) := let Q : DiagramOfCocones (curry.obj G) := .mkOfHasColimits _ let Q' : ∀ j, IsColimit (Q.obj j) := fun j => colimit.isColimit _ { desc c' := colimit.desc (F := curry.obj G ⋙ colim) (coconeOfCoconeCurry G Q' c') fac c' f := by simp [coconeOfHasColimitCurryCompColim, Q, Q'] uniq c' f h := by dsimp [coconeOfHasColimitCurryCompColim] at f h ⊢ refine colimit.hom_ext (F := curry.obj G ⋙ colim) (fun j ↦ colimit.hom_ext (fun k ↦ ?_)) simp [← h ⟨j, k⟩, Q'] } /-- The functor `G` has a colimit if `C` has `K`-shaped colimits and `(curry.obj G ⋙ colim)` has a colimit. -/ instance : HasColimit G where exists_colimit := ⟨ { cocone := coconeOfHasColimitCurryCompColim G isColimit := isColimitCoconeOfHasColimitCurryCompColim G }⟩ end variable [HasColimit (uncurry.obj F)] [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] /-- 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 _ @[simp, reassoc] theorem limitFlipCompLimIsoLimitCompLim_hom_π_π (j) (k) : (limitFlipCompLimIsoLimitCompLim F).hom ≫ limit.π _ j ≫ limit.π _ k = (limit.π _ k ≫ limit.π _ j) := by dsimp [limitFlipCompLimIsoLimitCompLim] simp [Equivalence.counit] @[simp, reassoc] theorem limitFlipCompLimIsoLimitCompLim_inv_π_π (k) (j) : (limitFlipCompLimIsoLimitCompLim F).inv ≫ limit.π _ k ≫ limit.π _ j = (limit.π _ j ≫ limit.π _ k) := by simp [limitFlipCompLimIsoLimitCompLim] end section variable (F) [HasColimitsOfShape J C] [HasColimitsOfShape K 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 [Equivalence.unit] @[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 [Equivalence.counitInv] end section variable [HasLimitsOfShape K C] [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)) := hasLimit_of_iso 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 simp [limitIsoLimitCurryCompLim, Trans.simple] @[simp, reassoc] theorem limitIsoLimitCurryCompLim_inv_π {j} {k} : (limitIsoLimitCurryCompLim G).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k) := by rw [← cancel_epi (limitIsoLimitCurryCompLim G).hom] simp end section variable [HasColimitsOfShape K C] [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)) := hasColimit_of_iso 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 simp [colimitIsoColimitCurryCompColim, Trans.simple, 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 [HasLimitsOfShape K C] [HasLimitsOfShape J C] [HasLimit (curry.obj G ⋙ lim)] 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 _ @[simp] theorem limitCurrySwapCompLimIsoLimitCurryCompLim_hom_π_π {j} {k} : (limitCurrySwapCompLimIsoLimitCurryCompLim G).hom ≫ limit.π _ j ≫ limit.π _ k = (limit.π _ k ≫ limit.π _ j) := by dsimp [limitCurrySwapCompLimIsoLimitCurryCompLim, Equivalence.counit] rw [Category.assoc, Category.assoc, limitIsoLimitCurryCompLim_hom_π_π, HasLimit.isoOfEquivalence_hom_π] dsimp [Equivalence.counit] rw [← prod_id, G.map_id] simp @[simp] theorem limitCurrySwapCompLimIsoLimitCurryCompLim_inv_π_π {j} {k} : (limitCurrySwapCompLimIsoLimitCurryCompLim G).inv ≫ limit.π _ k ≫ limit.π _ j = (limit.π _ j ≫ limit.π _ k) := by simp [limitCurrySwapCompLimIsoLimitCurryCompLim] end section variable [HasColimitsOfShape K C] [HasColimitsOfShape J C] [HasColimit (curry.obj G ⋙ colim)] 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 [] rw [colimitIsoColimitCurryCompColim_ι_ι_inv, HasColimit.isoOfEquivalence_inv_π] dsimp [Equivalence.counitInv] rw [CategoryTheory.Bifunctor.map_id] simp end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/IndYoneda.lean
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: morphisms 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. -/ 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 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, preservesLimitIso_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⟩ = (yoneda.obj A).map (colimit.ι F i).op := 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_π, Functor.flip_map_app] @[reassoc (attr := simp)] lemma colimitHomIsoLimitYoneda_inv_comp_π [HasLimitsOfShape Iᵒᵖ (Type u₂)] (A : C) (i : I) : (colimitHomIsoLimitYoneda F A).inv ≫ (yoneda.obj A).map (colimit.ι F i).op = 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, preservesLimitIso_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 = (yoneda.obj A).map (colimit.ι F ⟨i⟩).op := 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_π, Functor.flip_map_app] @[reassoc (attr := simp)] lemma colimitHomIsoLimitYoneda'_inv_comp_π [HasLimitsOfShape I (Type u₂)] (A : C) (i : I) : (colimitHomIsoLimitYoneda' F A).inv ≫ (yoneda.obj A).map (colimit.ι F ⟨i⟩).op = 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: morphisms from colimit of coyoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This variant is for contravariant diagrams, see `colimitCoyonedaHomIsoLimit'` for a covariant version. -/ noncomputable def colimitCoyonedaHomIsoLimit : (colimit (D.rightOp ⋙ coyoneda) ⟶ F) ≅ limit (D ⋙ F ⋙ uliftFunctor.{u₁}) := colimitHomIsoLimitYoneda _ F ≪≫ HasLimit.isoOfNatIso (Functor.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] rfl end ProCoyonedaContravariant section ProCoyonedaContravariantLeftOp variable (D : I ⥤ Cᵒᵖ) (F : C ⥤ Type u₂) variable [HasColimit (D ⋙ coyoneda)] [HasLimitsOfShape Iᵒᵖ (Type (max u₁ u₂))] /-- Pro-Coyoneda lemma: morphisms from colimit of coyoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This variant is for contravariant diagrams, see `colimitCoyonedaHomIsoLimit'` for a covariant version. -/ noncomputable def colimitCoyonedaHomIsoLimitLeftOp : (colimit (D ⋙ coyoneda) ⟶ F) ≅ limit (D.leftOp ⋙ F ⋙ uliftFunctor.{u₁}) := haveI : HasColimit (D.leftOp.rightOp ⋙ coyoneda) := inferInstanceAs <| HasColimit (D ⋙ coyoneda) colimitCoyonedaHomIsoLimit D.leftOp F @[simp] lemma colimitCoyonedaHomIsoLimitLeftOp_π_apply (f : colimit (D ⋙ coyoneda) ⟶ F) (i : I) : limit.π (D.leftOp ⋙ F ⋙ uliftFunctor.{u₁}) (op i) ((colimitCoyonedaHomIsoLimitLeftOp D F).hom f) = ⟨f.app (D.obj i).unop ((colimit.ι (D ⋙ coyoneda) i).app (D.obj i).unop (𝟙 (D.obj i).unop))⟩ := haveI : HasColimit (D.leftOp.rightOp ⋙ coyoneda) := inferInstanceAs <| HasColimit (D ⋙ coyoneda) colimitCoyonedaHomIsoLimit_π_apply _ _ _ _ end ProCoyonedaContravariantLeftOp section IndYonedaCovariant variable (D : Iᵒᵖ ⥤ Cᵒᵖ) (F : Cᵒᵖ ⥤ Type u₂) variable [HasColimit (D.unop ⋙ yoneda)] [HasLimitsOfShape Iᵒᵖ (Type (max u₁ u₂))] /-- Ind-Yoneda lemma: morphisms from colimit of yoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This version is for covariant diagrams, see `colimitYonedaHomIsoLimit'` for a contravariant version. -/ noncomputable def colimitYonedaHomIsoLimit : (colimit (D.unop ⋙ yoneda) ⟶ F) ≅ limit (D ⋙ F ⋙ uliftFunctor.{u₁}) := colimitHomIsoLimitYoneda _ _ ≪≫ HasLimit.isoOfNatIso (Functor.isoWhiskerLeft (D ⋙ Prod.sectL _ _) (yonedaLemma C)) @[simp] lemma colimitYonedaHomIsoLimit_π_apply (f : colimit (D.unop ⋙ yoneda) ⟶ F) (i : Iᵒᵖ) : limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) i ((colimitYonedaHomIsoLimit D F).hom f) = ⟨f.app (D.obj i) ((colimit.ι (D.unop ⋙ yoneda) i.unop).app (D.obj i) (𝟙 (D.obj i).unop))⟩ := by change ((colimitYonedaHomIsoLimit D F).hom ≫ (limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) i)) f = _ simp only [colimitYonedaHomIsoLimit, Iso.trans_hom, Category.assoc, HasLimit.isoOfNatIso_hom_π] rw [← Category.assoc, colimitHomIsoLimitYoneda_hom_comp_π] dsimp [yonedaLemma] rfl end IndYonedaCovariant section IndYonedaCovariantOp variable (D : I ⥤ C) (F : Cᵒᵖ ⥤ Type u₂) variable [HasColimit (D ⋙ yoneda)] [HasLimitsOfShape Iᵒᵖ (Type (max u₁ u₂))] /-- Ind-Yoneda lemma: morphisms from colimit of yoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This version is for covariant diagrams, see `colimitYonedaHomIsoLimit'` for a contravariant version. -/ noncomputable def colimitYonedaHomIsoLimitOp : (colimit (D ⋙ yoneda) ⟶ F) ≅ limit (D.op ⋙ F ⋙ uliftFunctor.{u₁}) := haveI : HasColimit (D.op.unop ⋙ yoneda) := inferInstanceAs <| HasColimit (D ⋙ yoneda) colimitYonedaHomIsoLimit D.op F @[simp] lemma colimitYonedaHomIsoLimitOp_π_apply (f : colimit (D ⋙ yoneda) ⟶ F) (i : Iᵒᵖ) : limit.π (D.op ⋙ F ⋙ uliftFunctor.{u₁}) i ((colimitYonedaHomIsoLimitOp D F).hom f) = ⟨f.app (op (D.obj i.unop)) ((colimit.ι (D ⋙ yoneda) i.unop).app (op (D.obj i.unop)) (𝟙 (D.obj i.unop)))⟩ := haveI : HasColimit (D.op.unop ⋙ yoneda) := inferInstanceAs <| HasColimit (D ⋙ yoneda) colimitYonedaHomIsoLimit_π_apply _ _ _ _ end IndYonedaCovariantOp section ProCoyonedaCovariant variable (D : I ⥤ C) (F : C ⥤ Type u₂) variable [HasColimit (D.op ⋙ coyoneda)] [HasLimitsOfShape I (Type (max u₁ u₂))] /-- Pro-Coyoneda lemma: morphisms from colimit of coyoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This variant is for covariant diagrams, see `colimitCoyonedaHomIsoLimit` for a covariant version. -/ noncomputable def colimitCoyonedaHomIsoLimit' : (colimit (D.op ⋙ coyoneda) ⟶ F) ≅ limit (D ⋙ F ⋙ uliftFunctor.{u₁}) := colimitHomIsoLimitYoneda' _ F ≪≫ HasLimit.isoOfNatIso (Functor.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] rfl end ProCoyonedaCovariant section ProCoyonedaCovariantUnop variable (D : Iᵒᵖ ⥤ Cᵒᵖ) (F : C ⥤ Type u₂) variable [HasColimit (D ⋙ coyoneda)] [HasLimitsOfShape I (Type (max u₁ u₂))] /-- Pro-Coyoneda lemma: morphisms from colimit of coyoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This variant is for covariant diagrams, see `colimitCoyonedaHomIsoLimit` for a covariant version. -/ noncomputable def colimitCoyonedaHomIsoLimitUnop : (colimit (D ⋙ coyoneda) ⟶ F) ≅ limit (D.unop ⋙ F ⋙ uliftFunctor.{u₁}) := haveI : HasColimit (D.unop.op ⋙ coyoneda) := inferInstanceAs <| HasColimit (D ⋙ coyoneda) colimitCoyonedaHomIsoLimit' D.unop F @[simp] lemma colimitCoyonedaHomIsoLimitUnop_π_apply (f : colimit (D ⋙ coyoneda) ⟶ F) (i : I) : limit.π (D.unop ⋙ F ⋙ uliftFunctor.{u₁}) i ((colimitCoyonedaHomIsoLimitUnop D F).hom f) = ⟨f.app (D.obj (op i)).unop ((colimit.ι (D ⋙ coyoneda) ⟨i⟩).app (D.obj (op i)).unop (𝟙 (D.obj (op i)).unop))⟩ := haveI : HasColimit (D.unop.op ⋙ coyoneda) := inferInstanceAs <| HasColimit (D ⋙ coyoneda) colimitCoyonedaHomIsoLimit'_π_apply _ _ _ _ end ProCoyonedaCovariantUnop section IndYonedaContravariant variable (D : I ⥤ Cᵒᵖ) (F : Cᵒᵖ ⥤ Type u₂) variable [HasColimit (D.leftOp ⋙ yoneda)] [HasLimitsOfShape I (Type (max u₁ u₂))] /-- Ind-Yoneda lemma: morphisms from colimit of yoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This version is for contravariant diagrams, see `colimitYonedaHomIsoLimit` for a covariant version. -/ noncomputable def colimitYonedaHomIsoLimit' : (colimit (D.leftOp ⋙ yoneda) ⟶ F) ≅ limit (D ⋙ F ⋙ uliftFunctor.{u₁}) := colimitHomIsoLimitYoneda' _ F ≪≫ HasLimit.isoOfNatIso (Functor.isoWhiskerLeft (D ⋙ Prod.sectL _ _) (yonedaLemma C)) @[simp] lemma colimitYonedaHomIsoLimit'_π_apply (f : colimit (D.leftOp ⋙ yoneda) ⟶ F) (i : I) : limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) i ((colimitYonedaHomIsoLimit' D F).hom f) = ⟨f.app (D.obj i) ((colimit.ι (D.leftOp ⋙ yoneda) (op i)).app (D.obj i) (𝟙 (D.obj i).unop))⟩ := by change ((colimitYonedaHomIsoLimit' D F).hom ≫ (limit.π (D ⋙ F ⋙ uliftFunctor.{u₁}) i)) f = _ simp only [colimitYonedaHomIsoLimit', Iso.trans_hom, Category.assoc, HasLimit.isoOfNatIso_hom_π] rw [← Category.assoc, colimitHomIsoLimitYoneda'_hom_comp_π] dsimp [yonedaLemma] rfl end IndYonedaContravariant section IndYonedaContravariantRightOp variable (D : Iᵒᵖ ⥤ C) (F : Cᵒᵖ ⥤ Type u₂) variable [HasColimit (D ⋙ yoneda)] [HasLimitsOfShape I (Type (max u₁ u₂))] /-- Ind-Yoneda lemma: morphisms from colimit of yoneda of diagram `D` to `F` is limit of `F` evaluated at `D`. This version is for contravariant diagrams, see `colimitYonedaHomIsoLimit` for a covariant version. -/ noncomputable def colimitYonedaHomIsoLimitRightOp : (colimit (D ⋙ yoneda) ⟶ F) ≅ limit (D.rightOp ⋙ F ⋙ uliftFunctor.{u₁}) := haveI : HasColimit (D.rightOp.leftOp ⋙ yoneda) := inferInstanceAs <| HasColimit (D ⋙ yoneda) colimitYonedaHomIsoLimit' D.rightOp F @[simp] lemma colimitYonedaHomIsoLimitRightOp_π_apply (f : colimit (D ⋙ yoneda) ⟶ F) (i : I) : limit.π (D.rightOp ⋙ F ⋙ uliftFunctor.{u₁}) i ((colimitYonedaHomIsoLimitRightOp D F).hom f) = ⟨f.app (op (D.obj (op i))) ((colimit.ι (D ⋙ yoneda) (op i)).app (op (D.obj (op i))) (𝟙 (D.obj (op i))))⟩ := haveI : HasColimit (D.rightOp.leftOp ⋙ yoneda) := inferInstanceAs <| HasColimit (D ⋙ yoneda) colimitYonedaHomIsoLimit'_π_apply _ _ _ _ end IndYonedaContravariantRightOp end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Sifted.lean
import Mathlib.CategoryTheory.Monoidal.FunctorCategory import Mathlib.CategoryTheory.Monoidal.ExternalProduct.Basic import Mathlib.CategoryTheory.Closed.Types import Mathlib.CategoryTheory.Monoidal.Limits.Preserves import Mathlib.CategoryTheory.Limits.Preserves.Bifunctor import Mathlib.CategoryTheory.Limits.Preserves.FunctorCategory import Mathlib.CategoryTheory.Limits.IsConnected /-! # Sifted categories A category `C` is sifted if `C` is nonempty and the diagonal functor `C ⥤ C × C` is final. Sifted categories can be characterized as those such that the colimit functor `(C ⥤ Type) ⥤ Type ` preserves finite products. We achieve this characterization in this file. ## Main results - `isSifted_of_hasBinaryCoproducts_and_nonempty`: A nonempty category with binary coproducts is sifted. - `IsSifted.colimPreservesFiniteProductsOfIsSifted`: The `Type`-valued colimit functor for sifted diagrams preserves finite products. - `IsSifted.of_colimit_preservesFiniteProducts`: The converse: if the `Type`-valued colimit functor preserves finite products, the category is sifted. - `IsSifted.of_final_functor_from_sifted`: A category admitting a final functor from a sifted category is itself sifted. ## References - [nLab, *Sifted category*](https://ncatlab.org/nlab/show/sifted+category) - [*Algebraic Theories*, Chapter 2.][Adamek_Rosicky_Vitale_2010] -/ universe w v v₁ v₂ u u₁ u₂ namespace CategoryTheory open Limits Functor section variable (C : Type u) [Category.{v} C] /-- A category `C` `IsSiftedOrEmpty` if the diagonal functor `C ⥤ C × C` is final. -/ abbrev IsSiftedOrEmpty : Prop := Final (diag C) /-- A category `C` `IsSifted` if 1. the diagonal functor `C ⥤ C × C` is final. 2. there exists some object. -/ class IsSifted : Prop extends IsSiftedOrEmpty C where [nonempty : Nonempty C] /- This instance is scoped since - it applies unconditionally (which can be a performance drain), - infers a *very* generic typeclass, - and does so from a *very* specialised class. -/ attribute [scoped instance] IsSifted.nonempty namespace IsSifted variable {C} /-- Being sifted is preserved by equivalences of categories -/ lemma isSifted_of_equiv [IsSifted C] {D : Type u₁} [Category.{v₁} D] (e : D ≌ C) : IsSifted D := letI : Final (diag D) := by letI : D × D ≌ C × C:= Equivalence.prod e e have sq : (e.inverse ⋙ diag D ⋙ this.functor ≅ diag C) := NatIso.ofComponents (fun c ↦ by dsimp [this] exact Iso.prod (e.counitIso.app c) (e.counitIso.app c)) apply_rules [final_iff_comp_equivalence _ this.functor|>.mpr, final_iff_final_comp e.inverse _ |>.mpr, final_of_natIso sq.symm] letI : _root_.Nonempty D := ⟨e.inverse.obj (_root_.Nonempty.some IsSifted.nonempty)⟩ ⟨⟩ /-- In particular a category is sifted iff and only if it is so when viewed as a small category -/ lemma isSifted_iff_asSmallIsSifted : IsSifted C ↔ IsSifted (AsSmall.{w} C) where mp _ := isSifted_of_equiv AsSmall.equiv.symm mpr _ := isSifted_of_equiv AsSmall.equiv /-- A sifted category is connected. -/ instance [IsSifted C] : IsConnected C := isConnected_of_zigzag (by intro c₁ c₂ have X : StructuredArrow (c₁, c₂) (diag C) := letI S : Final (diag C) := by infer_instance Nonempty.some (S.out (c₁, c₂)).is_nonempty use [X.right, c₂] constructor · constructor · exact Zag.of_hom X.hom.fst · simpa using Zag.of_inv X.hom.snd · rfl) /-- A category with binary coproducts is sifted or empty. -/ instance [HasBinaryCoproducts C] : IsSiftedOrEmpty C := by constructor rintro ⟨c₁, c₂⟩ haveI : _root_.Nonempty <| StructuredArrow (c₁,c₂) (diag C) := ⟨.mk ((coprod.inl : c₁ ⟶ c₁ ⨿ c₂), (coprod.inr : c₂ ⟶ c₁ ⨿ c₂))⟩ apply isConnected_of_zigzag rintro ⟨_, c, f⟩ ⟨_, c', g⟩ dsimp only [const_obj_obj, diag_obj, prod_Hom] at f g use [.mk ((coprod.inl : c₁ ⟶ c₁ ⨿ c₂), (coprod.inr : c₂ ⟶ c₁ ⨿ c₂)), .mk (g.fst, g.snd)] simp only [colimit.cocone_x, diag_obj, Prod.mk.eta, List.isChain_cons_cons, List.isChain_singleton, and_true, ne_eq, reduceCtorEq, not_false_eq_true, List.getLast_cons, List.cons_ne_self, List.getLast_singleton] exact ⟨⟨Zag.of_inv <| StructuredArrow.homMk <| coprod.desc f.fst f.snd, Zag.of_hom <| StructuredArrow.homMk <| coprod.desc g.fst g.snd⟩, rfl⟩ /-- A nonempty category with binary coproducts is sifted. -/ instance isSifted_of_hasBinaryCoproducts_and_nonempty [_root_.Nonempty C] [HasBinaryCoproducts C] : IsSifted C where end IsSifted end section variable {C : Type u} [Category.{v} C] [IsSiftedOrEmpty C] {D : Type u₁} [Category.{v₁} D] {D' : Type u₂} [Category.{v₂} D'] (F : C ⥤ D) (G : C ⥤ D') instance [F.Final] [G.Final] : (F.prod' G).Final := show (diag C ⋙ F.prod G).Final from final_comp _ _ end noncomputable section SmallCategory open MonoidalCategory CartesianMonoidalCategory namespace IsSifted variable {C : Type u} [SmallCategory C] section open scoped MonoidalCategory.ExternalProduct variable (X Y : C ⥤ Type u) /-- Through the isomorphisms `PreservesColimit₂.isoColimitUncurryWhiskeringLeft₂` and `externalProductCompDiagIso`, the comparison map `colimit.pre (X ⊠ Y) (diag C)` identifies with the product comparison map for the colimit functor. -/ lemma factorization_prodComparison_colim : (HasColimit.isoOfNatIso ((externalProductCompDiagIso _ _).app (X, Y)).symm).hom ≫ colimit.pre (X ⊠ Y) (diag C) ≫ (PreservesColimit₂.isoColimitUncurryWhiskeringLeft₂ X Y <| curriedTensor <| Type u).hom = CartesianMonoidalCategory.prodComparison colim X Y := by apply colimit.hom_ext intro j dsimp [externalProductBifunctor, CartesianMonoidalCategory.prodComparison, externalProductBifunctorCurried, externalProduct] cat_disch variable [IsSifted C] /-- If `C` is sifted, the canonical product comparison map for the `colim` functor `(C ⥤ Type) ⥤ Type` is an isomorphism. -/ instance : IsIso (CartesianMonoidalCategory.prodComparison colim X Y) := by rw [← factorization_prodComparison_colim] infer_instance instance colim_preservesLimits_pair_of_sSifted {X Y : C ⥤ Type u} : PreservesLimit (pair X Y) colim := preservesLimit_pair_of_isIso_prodComparison _ _ _ /-- Sifted colimits commute with binary products -/ instance colim_preservesBinaryProducts_of_isSifted : PreservesLimitsOfShape (Discrete WalkingPair) (colim : (C ⥤ _) ⥤ Type u) := by constructor intro F apply preservesLimit_of_iso_diagram colim (diagramIsoPair F).symm /-- If `C` is sifted, the `colimit` functor `(C ⥤ Type) ⥤ Type` preserves terminal objects -/ instance colim_preservesTerminal_of_isSifted : PreservesLimit (Functor.empty.{0} (C ⥤ Type u)) colim := by apply preservesTerminal_of_iso symm apply (_ : ⊤_ (Type u) ≅ PUnit.{u +1}).trans · apply_rules [(Types.colimitConstPUnitIsoPUnit C).symm.trans, HasColimit.isoOfNatIso, IsTerminal.uniqueUpToIso _ terminalIsTerminal, evaluationJointlyReflectsLimits] exact fun _ ↦ isLimitChangeEmptyCone _ Types.isTerminalPunit _ <| Iso.refl _ · exact Types.isTerminalEquivIsoPUnit (⊤_ (Type u))|>.toFun terminalIsTerminal instance colim_preservesLimitsOfShape_pempty_of_isSifted : PreservesLimitsOfShape (Discrete PEmpty.{1}) (colim : (C ⥤ _) ⥤ Type u) := preservesLimitsOfShape_pempty_of_preservesTerminal _ /-- If `C` is sifted, the `colim` functor `(C ⥤ Type) ⥤ Type` preserves finite products. -/ instance colim_preservesFiniteProducts_of_isSifted : PreservesFiniteProducts (colim : (C ⥤ _) ⥤ Type u ) := PreservesFiniteProducts.of_preserves_binary_and_terminal colim end section variable (C) open Opposite in open scoped MonoidalCategory.ExternalProduct in /-- If the `colim` functor `(C ⥤ Type) ⥤ Type` preserves binary products, then `C` is sifted or empty. -/ theorem isSiftedOrEmpty_of_colim_preservesBinaryProducts [PreservesLimitsOfShape (Discrete WalkingPair) (colim : (C ⥤ Type u) ⥤ Type u)] : IsSiftedOrEmpty C := by apply final_of_colimit_comp_coyoneda_iso_pUnit rintro ⟨c₁, c₂⟩ calc colimit <| diag C ⋙ coyoneda.obj (op (c₁, c₂)) _ ≅ colimit <| _ ⋙ (coyoneda.obj _) ⊠ (coyoneda.obj _) := HasColimit.isoOfNatIso <| isoWhiskerLeft _ <| .refl _ _ ≅ colimit (_ ⊗ _) := HasColimit.isoOfNatIso <| .refl _ _ ≅ (colimit _) ⊗ (colimit _) := CartesianMonoidalCategory.prodComparisonIso colim _ _ _ ≅ PUnit ⊗ PUnit := (Coyoneda.colimitCoyonedaIso _) ⊗ᵢ (Coyoneda.colimitCoyonedaIso _) _ ≅ PUnit := λ_ _ lemma isSiftedOrEmpty_of_colim_preservesFiniteProducts [h : PreservesFiniteProducts (colim : (C ⥤ Type u) ⥤ Type u)] : IsSiftedOrEmpty C := isSiftedOrEmpty_of_colim_preservesBinaryProducts C lemma nonempty_of_colim_preservesLimitsOfShapeFinZero [PreservesLimitsOfShape (Discrete (Fin 0)) (colim : (C ⥤ Type u) ⥤ Type u)] : Nonempty C := by suffices connected : IsConnected C by infer_instance rw [Types.isConnected_iff_colimit_constPUnitFunctor_iso_pUnit] constructor haveI : PreservesLimitsOfShape (Discrete PEmpty) (colim : (C ⥤ _) ⥤ Type u) := preservesLimitsOfShape_of_equiv (Discrete.equivalence finZeroEquiv') _ apply HasColimit.isoOfNatIso (_: Types.constPUnitFunctor C ≅ (⊤_ (C ⥤ Type u)))|>.trans · apply PreservesTerminal.iso colim |>.trans exact Types.terminalIso · apply_rules [IsTerminal.uniqueUpToIso _ terminalIsTerminal, evaluationJointlyReflectsLimits] intro _ exact isLimitChangeEmptyCone _ Types.isTerminalPunit _ <| Iso.refl _ /-- If the `colim` functor `(C ⥤ Type) ⥤ Type` preserves finite products, then `C` is sifted. -/ theorem of_colim_preservesFiniteProducts [h : PreservesFiniteProducts (colim : (C ⥤ Type u) ⥤ Type u)] : IsSifted C := by have := isSiftedOrEmpty_of_colim_preservesFiniteProducts C have := nonempty_of_colim_preservesLimitsOfShapeFinZero C constructor variable {C} /-- Auxiliary version of `IsSifted.of_final_functor_from_sifted` where everything is a small category. -/ theorem of_final_functor_from_sifted' {D : Type u} [SmallCategory D] [IsSifted C] (F : C ⥤ D) [Final F] : IsSifted D := by have : PreservesFiniteProducts (colim : (D ⥤ Type u) ⥤ _) := ⟨fun n ↦ preservesLimitsOfShape_of_natIso (Final.colimIso F)⟩ exact of_colim_preservesFiniteProducts D end end IsSifted end SmallCategory variable {C : Type u} [Category.{v} C] /-- A functor admitting a final functor from a sifted category is sifted. -/ theorem IsSifted.of_final_functor_from_sifted {D : Type u₁} [Category.{v₁} D] [h₁ : IsSifted C] (F : C ⥤ D) [Final F] : IsSifted D := by rw [isSifted_iff_asSmallIsSifted] at h₁ ⊢ exact of_final_functor_from_sifted' <| AsSmall.equiv.{_, _, max u₁ v₁}.inverse ⋙ F ⋙ AsSmall.equiv.{_, _, max u v}.functor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Skeleton.lean
import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Skeletal /-! # (Co)limits of the skeleton of a category The skeleton of a category inherits all (co)limits the category has. ## Implementation notes Because the category instance of `ThinSkeleton C` comes from its `Preorder` instance, it is not the case that `HasLimits C` iff `HasLimits (ThinSkeleton C)`, as the homs live in different universes. If this is something we really want, we should consider changing the category instance of `ThinSkeleton C`. -/ noncomputable section open CategoryTheory ThinSkeleton namespace CategoryTheory.Limits universe v₁ u₁ v₂ u₂ v₃ u₃ w w' variable {J : Type u₁} [Category.{v₁} J] {C : Type u₂} [Category.{v₂} C] {D : Type u₃} [Category.{v₃} D] instance hasLimitsOfShape_skeleton [HasLimitsOfShape J C] : HasLimitsOfShape J (Skeleton C) := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (fromSkeleton C) instance hasLimitsOfSize_skeleton [HasLimitsOfSize.{w, w'} C] : HasLimitsOfSize.{w, w'} (Skeleton C) := hasLimits_of_hasLimits_createsLimits (fromSkeleton C) example [HasLimits C] : HasLimits (Skeleton C) := by infer_instance instance hasColimitsOfShape_skeleton [HasColimitsOfShape J C] : HasColimitsOfShape J (Skeleton C) := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape (fromSkeleton C) instance hasColimitsOfSize_skeleton [HasColimitsOfSize.{w, w'} C] : HasColimitsOfSize.{w, w'} (Skeleton C) := hasColimits_of_hasColimits_createsColimits (fromSkeleton C) example [HasColimits C] : HasColimits (Skeleton C) := by infer_instance variable [Quiver.IsThin C] instance hasLimitsOfShape_thinSkeleton [HasLimitsOfShape J C] : HasLimitsOfShape J (ThinSkeleton C) := hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (fromThinSkeleton C) instance hasLimitsOfSize_thinSkeleton [HasLimitsOfSize.{w, w'} C] : HasLimitsOfSize.{w, w'} (ThinSkeleton C) := hasLimits_of_hasLimits_createsLimits (fromThinSkeleton C) instance hasColimitsOfShape_thinSkeleton [HasColimitsOfShape J C] : HasColimitsOfShape J (ThinSkeleton C) := hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape (fromThinSkeleton C) instance hasColimitsOfSize_thinSkeleton [HasColimitsOfSize.{w, w'} C] : HasColimitsOfSize.{w, w'} (ThinSkeleton C) := hasColimits_of_hasColimits_createsColimits (fromThinSkeleton C) end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Filtered.lean
import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Types.Yoneda /-! # 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 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 /-- Class for having cofiltered limits. -/ abbrev HasCofilteredLimits := HasCofilteredLimitsOfSize.{v, v} C /-- Class for having filtered colimits. -/ abbrev HasFilteredColimits := HasFilteredColimitsOfSize.{v, v} C end instance (priority := 100) hasFilteredColimitsOfSize_of_hasColimitsOfSize [HasColimitsOfSize.{w', w} C] : HasFilteredColimitsOfSize.{w', w} C where HasColimitsOfShape _ _ _ := inferInstance instance (priority := 100) hasCofilteredLimitsOfSize_of_hasLimitsOfSize [HasLimitsOfSize.{w', w} C] : HasCofilteredLimitsOfSize.{w', w} C where HasLimitsOfShape _ _ _ := inferInstance 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 _ lemma hasCofilteredLimitsOfSize_of_univLE [UnivLE.{w, w₂}] [UnivLE.{w', w₂'}] [HasCofilteredLimitsOfSize.{w₂', w₂} C] : HasCofilteredLimitsOfSize.{w', w} C where HasLimitsOfShape J := haveI := IsCofiltered.of_equivalence ((ShrinkHoms.equivalence.{w₂'} J).trans <| Shrink.equivalence.{w₂, w₂'} (ShrinkHoms.{w} J)) hasLimitsOfShape_of_equivalence ((ShrinkHoms.equivalence.{w₂'} J).trans <| Shrink.equivalence.{w₂, w₂'} (ShrinkHoms.{w} J)).symm lemma hasCofilteredLimitsOfSize_shrink [HasCofilteredLimitsOfSize.{max w' w₂', max w w₂} C] : HasCofilteredLimitsOfSize.{w', w} C := hasCofilteredLimitsOfSize_of_univLE.{w', w, max w' w₂', max w w₂} lemma hasFilteredColimitsOfSize_of_univLE [UnivLE.{w, w₂}] [UnivLE.{w', w₂'}] [HasFilteredColimitsOfSize.{w₂', w₂} C] : HasFilteredColimitsOfSize.{w', w} C where HasColimitsOfShape J := haveI := IsFiltered.of_equivalence ((ShrinkHoms.equivalence.{w₂'} J).trans <| Shrink.equivalence.{w₂, w₂'} (ShrinkHoms.{w} J)) hasColimitsOfShape_of_equivalence ((ShrinkHoms.equivalence.{w₂'} J).trans <| Shrink.equivalence.{w₂, w₂'} (ShrinkHoms.{w} J)).symm lemma hasFilteredColimitsOfSize_shrink [HasFilteredColimitsOfSize.{max w' w₂', max w w₂} C] : HasFilteredColimitsOfSize.{w', w} C := hasFilteredColimitsOfSize_of_univLE.{w', w, max w' w₂', max w w₂} end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Unit.lean
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
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Presheaf.lean
import Mathlib.CategoryTheory.Comma.Presheaf.Basic import Mathlib.CategoryTheory.Elements import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Limits.Over /-! # Colimit of representables In this file, We show that every presheaf of types on a category `C` (with `Category.{v₁} C`) is a colimit of representables. This result is also known as the density theorem, the co-Yoneda lemma and the Ninja Yoneda lemma. Three formulations are given: * `colimitOfRepresentable` uses the category of elements of a functor to types; * `isColimitTautologicalCocone` uses the category of costructured arrows for `yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁`; * `isColimitTautologicalCocone'` uses the category of costructured arrows for `uliftYoneda : C ⥤ Cᵒᵖ ⥤ Type max w v₁`, when the presheaf has values in `Type (max w v₁)`; In this file, we also study the left Kan extensions of functors `A : C ⥤ ℰ` along the Yoneda embedding `uliftYoneda : C ⥤ Cᵒᵖ ⥤ Type max w v₁ v₂` (when `Category.{v₂} ℰ` and `w` is an auxiliary universe). In particular, the definition `uliftYonedaAdjunction` shows that such a pointwise left Kan extension (which exists when `ℰ` has colimits) is a left adjoint to the functor `restrictedULiftYoneda : ℰ ⥤ Cᵒᵖ ⥤ Type (max w v₁ v₂)`. In the lemma `isLeftKanExtension_along_uliftYoneda_iff`, we show that if `L : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ ℰ` and `α : A ⟶ uliftYoneda ⋙ 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. `uniqueExtensionAlongULiftYoneda` shows `uliftYoneda.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 `compULiftYonedaIsoULiftYonedaCompLan : F ⋙ uliftYoneda ≅ uliftYoneda ⋙ F.op.lan`, and show that it makes `F.op.lan` a left Kan extension of `F ⋙ uliftYoneda`. ## 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 Opposite universe w v₁ v₂ v₃ u₁ u₂ u₃ variable {C : Type u₁} [Category.{v₁} C] namespace Presheaf variable {ℰ : Type u₂} [Category.{v₂} ℰ] (A : C ⥤ ℰ) /-- Given a functor `A : C ⥤ ℰ` (with `Category.{v₂} ℰ`) and a auxiliary universe `w`, this is the functor `ℰ ⥤ Cᵒᵖ ⥤ Type (max w v₂)` which sends `(E : ℰ) (c : Cᵒᵖ)` to the homset `A.obj C ⟶ E` (considered in the higher universe `max w v₂`). Under the existence of a suitable pointwise left Kan extension, it is shown in `uliftYonedaAdjunction` that this functor has a left adjoint. Defined as in [MM92], Chapter I, Section 5, Theorem 2. -/ @[simps! obj_map map_app] def restrictedULiftYoneda : ℰ ⥤ Cᵒᵖ ⥤ Type (max w v₂) := uliftYoneda.{w} ⋙ (Functor.whiskeringLeft _ _ _).obj A.op @[reassoc] lemma map_comp_uliftYonedaEquiv_down (E : ℰ) {X Y : C} (f : X ⟶ Y) (g : uliftYoneda.{max w v₂}.obj Y ⟶ (restrictedULiftYoneda.{max w v₁} A).obj E) : A.map f ≫ (uliftYonedaEquiv g).down = (uliftYonedaEquiv (uliftYoneda.map f ≫ g)).down := by have this := congr_fun (g.naturality f.op) (ULift.up (𝟙 Y)) dsimp [uliftYonedaEquiv, uliftYoneda] at this ⊢ simp only [comp_id] at this simp [id_comp, this] /-- Auxiliary definition for `restrictedULiftYonedaHomEquiv`. -/ def restrictedULiftYonedaHomEquiv' (P : Cᵒᵖ ⥤ Type (max w v₁ v₂)) (E : ℰ) : (CostructuredArrow.proj uliftYoneda.{max w v₂} P ⋙ A ⟶ (Functor.const (CostructuredArrow uliftYoneda.{max w v₂} P)).obj E) ≃ (P ⟶ (restrictedULiftYoneda.{max w v₁} A).obj E) where toFun f := { app _ x := ULift.up (f.app (CostructuredArrow.mk (uliftYonedaEquiv.symm x))) naturality _ _ g := by ext x let φ : CostructuredArrow.mk (uliftYonedaEquiv.{max w v₂}.symm (P.map g x)) ⟶ CostructuredArrow.mk (uliftYonedaEquiv.symm x) := CostructuredArrow.homMk g.unop (by dsimp rw [uliftYonedaEquiv_symm_map]) dsimp congr 1 simpa using (f.naturality φ).symm } invFun g := { app y := (uliftYonedaEquiv.{max w v₂} (y.hom ≫ g)).down naturality y y' f := by dsimp rw [comp_id, ← CostructuredArrow.w f, assoc, map_comp_uliftYonedaEquiv_down] } left_inv f := by ext X let e : CostructuredArrow.mk (uliftYonedaEquiv.{max w v₂}.symm (X.hom.app (op X.left) ⟨𝟙 X.left⟩)) ≅ X := CostructuredArrow.isoMk (Iso.refl _) (by ext Y x dsimp rw [← FunctorToTypes.naturality] congr ) simpa [e] using f.naturality e.inv right_inv g := by ext X x apply ULift.down_injective simp [uliftYonedaEquiv] @[reassoc] lemma restrictedULiftYonedaHomEquiv'_symm_naturality_right (P : Cᵒᵖ ⥤ Type (max w v₁ v₂)) {E E' : ℰ} (g : E ⟶ E') (f : (P ⟶ (restrictedULiftYoneda.{max w v₁} A).obj E)) : (restrictedULiftYonedaHomEquiv' A P E').symm (f ≫ (restrictedULiftYoneda A).map g) = (restrictedULiftYonedaHomEquiv' A P E).symm f ≫ (Functor.const _ ).map g := by rfl @[reassoc] lemma restrictedULiftYonedaHomEquiv'_symm_app_naturality_left {P Q : Cᵒᵖ ⥤ Type (max w v₁ v₂)} (f : P ⟶ Q) (E : ℰ) (g : Q ⟶ (restrictedULiftYoneda.{max w v₁} A).obj E) (p : CostructuredArrow uliftYoneda.{max w v₂} P) : ((restrictedULiftYonedaHomEquiv' A P E).symm (f ≫ g)).app p = ((restrictedULiftYonedaHomEquiv' A Q E).symm g).app ((CostructuredArrow.map f).obj p) := rfl section variable (P : ℰᵒᵖ ⥤ Type (max w v₁ v₂)) example [HasColimitsOfSize.{v₁, max u₁ v₁ v₂ w} ℰ] : (uliftYoneda.{max w v₂}).HasPointwiseLeftKanExtension A := by infer_instance variable [(uliftYoneda.{max w v₂}).HasPointwiseLeftKanExtension A] variable {A} variable (L : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ ℰ) (α : A ⟶ uliftYoneda.{max w v₂} ⋙ L) [L.IsLeftKanExtension α] /-- Auxiliary definition for `uliftYonedaAdjunction`. -/ noncomputable def restrictedULiftYonedaHomEquiv (P : Cᵒᵖ ⥤ Type max w v₁ v₂) (E : ℰ) : (L.obj P ⟶ E) ≃ (P ⟶ (restrictedULiftYoneda.{max w v₁} A).obj E) := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ α P).homEquiv.trans (restrictedULiftYonedaHomEquiv' A P E) /-- If `L : (Cᵒᵖ ⥤ Type max v₁ v₂) ⥤ ℰ` is a pointwise left Kan extension of a functor `A : C ⥤ ℰ` along the Yoneda embedding, then `L` is a left adjoint of `restrictedULiftYoneda A : ℰ ⥤ Cᵒᵖ ⥤ Type max v₁ v₂` -/ noncomputable def uliftYonedaAdjunction : L ⊣ restrictedULiftYoneda.{max w v₁} A := Adjunction.mkOfHomEquiv { homEquiv := restrictedULiftYonedaHomEquiv L α homEquiv_naturality_left_symm {P Q X} f g := by apply (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α P).hom_ext intro p have hfg := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α P).comp_homEquiv_symm ((restrictedULiftYonedaHomEquiv' A P X).symm (f ≫ g)) p have hg := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α Q).comp_homEquiv_symm ((restrictedULiftYonedaHomEquiv' A Q X).symm g) ((CostructuredArrow.map f).obj p) dsimp at hfg hg dsimp [restrictedULiftYonedaHomEquiv] simp only [assoc, hfg, ← L.map_comp_assoc, hg, restrictedULiftYonedaHomEquiv'_symm_app_naturality_left] homEquiv_naturality_right {P X Y} f g := by have := @IsColimit.homEquiv_symm_naturality (h := Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α P) dsimp at this apply (restrictedULiftYonedaHomEquiv L α P Y).symm.injective apply (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α P).hom_ext intro simp [restrictedULiftYonedaHomEquiv, restrictedULiftYonedaHomEquiv'_symm_naturality_right, this] } @[simp] lemma uliftYonedaAdjunction_homEquiv_app {P : Cᵒᵖ ⥤ Type max w v₁ v₂} {Y : ℰ} (f : L.obj P ⟶ Y) {Z : Cᵒᵖ} (z : P.obj Z) : ((uliftYonedaAdjunction.{w} L α).homEquiv P Y f).app Z z = ULift.up (α.app Z.unop ≫ L.map (uliftYonedaEquiv.symm z) ≫ f) := by simp [uliftYonedaAdjunction, restrictedULiftYonedaHomEquiv, restrictedULiftYonedaHomEquiv', IsColimit.homEquiv] @[simp] lemma uliftYonedaAdjunction_unit_app_app (P : Cᵒᵖ ⥤ Type max w v₁ v₂) {Z : Cᵒᵖ} (z : P.obj Z) : ((uliftYonedaAdjunction.{w} L α).unit.app P).app Z z = ULift.up (α.app Z.unop ≫ L.map (uliftYonedaEquiv.symm z)) := by have h₁ := (uliftYonedaAdjunction.{w} L α).homEquiv_unit P _ (𝟙 _) simp only [Functor.comp_obj, Functor.map_id, comp_id] at h₁ simp [← h₁] include α in /-- Any left Kan extension along the Yoneda embedding preserves colimits. -/ lemma preservesColimitsOfSize_of_isLeftKanExtension : PreservesColimitsOfSize.{v₃, u₃} L := (uliftYonedaAdjunction L α).leftAdjoint_preservesColimits lemma isIso_of_isLeftKanExtension : IsIso α := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension _ α).isIso_hom variable (A) /-- See Property 2 of https://ncatlab.org/nlab/show/Yoneda+extension#properties. -/ instance preservesColimitsOfSize_leftKanExtension : PreservesColimitsOfSize.{v₃, u₃} (uliftYoneda.{max w v₂}.leftKanExtension A) := (uliftYonedaAdjunction _ (uliftYoneda.leftKanExtensionUnit A)).leftAdjoint_preservesColimits instance : IsIso (uliftYoneda.{max w v₂}.leftKanExtensionUnit A) := isIso_of_isLeftKanExtension _ (uliftYoneda.leftKanExtensionUnit A) /-- A pointwise left Kan extension along the Yoneda embedding is an extension. -/ noncomputable def isExtensionAlongULiftYoneda : uliftYoneda.{max w v₂} ⋙ uliftYoneda.leftKanExtension A ≅ A := (asIso (uliftYoneda.leftKanExtensionUnit A)).symm end /-- Given `P : Cᵒᵖ ⥤ Type max w v₁`, this is the functor from the opposite category of the category of elements of `X` which sends an element in `P.obj (op X)` to the presheaf represented by `X`. The definition`coconeOfRepresentable` gives a cocone for this functor which is a colimit and has point `P`. -/ @[simps! obj map] def functorToRepresentables (P : Cᵒᵖ ⥤ Type max w v₁) : P.Elementsᵒᵖ ⥤ Cᵒᵖ ⥤ Type (max w v₁) := (CategoryOfElements.π P).leftOp ⋙ uliftYoneda.{w} /-- 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] def coconeOfRepresentable (P : Cᵒᵖ ⥤ Type max w v₁) : Cocone (functorToRepresentables P) where pt := P ι := { app x := uliftYonedaEquiv.symm x.unop.2 naturality {x₁ x₂} f := by dsimp rw [comp_id, ← uliftYonedaEquiv_symm_map, f.unop.2] } /-- The legs of the cocone `coconeOfRepresentable` are natural in the choice of presheaf. -/ theorem coconeOfRepresentable_naturality {P₁ P₂ : Cᵒᵖ ⥤ Type max w v₁} (α : P₁ ⟶ P₂) (j : P₁.Elementsᵒᵖ) : (coconeOfRepresentable P₁).ι.app j ≫ α = (coconeOfRepresentable P₂).ι.app ((CategoryOfElements.map α).op.obj j) := by ext T f simp [uliftYonedaEquiv, FunctorToTypes.naturality] /-- 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. -/ def colimitOfRepresentable (P : Cᵒᵖ ⥤ Type max w v₁) : IsColimit (coconeOfRepresentable P) where desc s := { app X x := uliftYonedaEquiv (s.ι.app (Opposite.op (Functor.elementsMk P X x))) naturality X Y f := by ext x have := s.w (Quiver.Hom.op (CategoryOfElements.homMk (P.elementsMk X x) (P.elementsMk Y (P.map f x)) f rfl)) dsimp at this x ⊢ rw [← this, uliftYonedaEquiv_comp] dsimp rw [uliftYonedaEquiv_apply, ← FunctorToTypes.naturality, uliftYonedaEquiv_uliftYoneda_map] simp [uliftYoneda] } fac s j := by ext X x let φ : j.unop ⟶ (Functor.elementsMk P _ ((uliftYonedaEquiv.symm (unop j).snd).app X x)) := ⟨x.down.op, rfl⟩ have := s.w φ.op dsimp [φ] at this x ⊢ rw [← this, uliftYonedaEquiv_apply] dsimp [uliftYoneda] rw [id_comp] uniq s m hm := by ext X x dsimp at hm ⊢ rw [← hm, uliftYonedaEquiv_comp, Equiv.apply_symm_apply] variable {A : C ⥤ ℰ} example [HasColimitsOfSize.{v₁, max w u₁ v₁ v₂} ℰ] : uliftYoneda.{max w v₂}.HasPointwiseLeftKanExtension A := by infer_instance variable [uliftYoneda.{max w v₂}.HasPointwiseLeftKanExtension A] section variable (L : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ ℰ) (α : A ⟶ uliftYoneda.{max w v₂} ⋙ L) instance [L.IsLeftKanExtension α] : IsIso α := (Functor.isPointwiseLeftKanExtensionOfIsLeftKanExtension L α).isIso_hom lemma isLeftKanExtension_along_uliftYoneda_iff : L.IsLeftKanExtension α ↔ (IsIso α ∧ PreservesColimitsOfSize.{v₁, max w u₁ v₁ v₂} L) := by constructor · intro exact ⟨inferInstance, preservesColimits_of_natIso (Functor.leftKanExtensionUnique _ (uliftYoneda.{max w v₂}.leftKanExtensionUnit A) _ α)⟩ · rintro ⟨_, _⟩ apply Functor.LeftExtension.IsPointwiseLeftKanExtension.isLeftKanExtension (E := Functor.LeftExtension.mk _ α) intro P dsimp [Functor.LeftExtension.IsPointwiseLeftKanExtensionAt] apply IsColimit.ofWhiskerEquivalence (CategoryOfElements.costructuredArrowULiftYonedaEquivalence _) let e : (CategoryOfElements.costructuredArrowULiftYonedaEquivalence P).functor ⋙ CostructuredArrow.proj uliftYoneda.{max w v₂} P ⋙ A ≅ functorToRepresentables.{max w v₂} P ⋙ L := Functor.isoWhiskerLeft _ (Functor.isoWhiskerLeft _ (asIso α)) ≪≫ Functor.isoWhiskerLeft _ (Functor.associator _ _ _).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ Functor.isoWhiskerRight (Iso.refl _) L refine (IsColimit.precomposeHomEquiv e.symm _).1 ?_ exact IsColimit.ofIsoColimit (isColimitOfPreserves L (colimitOfRepresentable.{max w v₂} P)) (Cocones.ext (Iso.refl _)) lemma isLeftKanExtension_of_preservesColimits (L : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ ℰ) (e : A ≅ uliftYoneda.{max w v₂} ⋙ L) [PreservesColimitsOfSize.{v₁, max w u₁ v₁ v₂} L] : L.IsLeftKanExtension e.hom := by rw [isLeftKanExtension_along_uliftYoneda_iff] exact ⟨inferInstance, ⟨inferInstance⟩⟩ end /-- Show that `uliftYoneda.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 uniqueExtensionAlongULiftYoneda (L : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ ℰ) (e : A ≅ uliftYoneda.{max w v₂} ⋙ L) [PreservesColimitsOfSize.{v₁, max w u₁ v₁ v₂} L] : L ≅ uliftYoneda.{max w v₂}.leftKanExtension A := have := isLeftKanExtension_of_preservesColimits L e Functor.leftKanExtensionUnique _ e.hom _ (uliftYoneda.leftKanExtensionUnit A) instance (L : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ ℰ) [PreservesColimitsOfSize.{v₁, max w u₁ v₁ v₂} L] [uliftYoneda.{max w v₂}.HasPointwiseLeftKanExtension (uliftYoneda.{max w v₂} ⋙ L)] : L.IsLeftKanExtension (𝟙 _ : uliftYoneda.{max w v₂} ⋙ 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 max w v₁ v₂) ⥤ ℰ) [PreservesColimitsOfSize.{v₁, max w u₁ v₁ v₂} L] [uliftYoneda.{max w v₂}.HasPointwiseLeftKanExtension (uliftYoneda.{max w v₂} ⋙ (opOpEquivalence C).congrLeft.functor.comp L)] : L.IsLeftAdjoint := ⟨_, ⟨((opOpEquivalence C).congrLeft.symm.toAdjunction.comp (uliftYonedaAdjunction _ (𝟙 _))).ofNatIsoLeft ((opOpEquivalence C).congrLeft.invFunIdAssoc L)⟩⟩ section variable {D : Type u₂} [Category.{v₁} D] (F : C ⥤ D) 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 simp [← StructuredArrow.w φ, yonedaEquiv] /-- 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 {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) instance (X : C) (Y : F.op.LeftExtension (uliftYoneda.{max w v₂}.obj X)) : Unique (Functor.LeftExtension.mk _ (uliftYonedaMap.{w} F X) ⟶ Y) where default := StructuredArrow.homMk (uliftYonedaEquiv.symm (uliftYonedaEquiv (F := F.op ⋙ Y.right) Y.hom)) (by ext Z ⟨f⟩ simpa [uliftYonedaEquiv, uliftYoneda] using congr_fun (Y.hom.naturality f.op).symm (ULift.up (𝟙 _)) ) uniq φ := by ext : 1 apply uliftYonedaEquiv.injective simp [← StructuredArrow.w φ, uliftYonedaEquiv, uliftYonedaMap] /-- Given `F : C ⥤ D` and `X : C`, `uliftYoneda.obj (F.obj X) : Dᵒᵖ ⥤ Type (max w v₁ v₂)` is the left Kan extension of `uliftYoneda.obj X : Cᵒᵖ ⥤ Type (max w v₁ v₂)` along `F.op`. -/ instance (X : C) : (uliftYoneda.{max w v₁}.obj (F.obj X)).IsLeftKanExtension (uliftYonedaMap.{w} F X) := ⟨⟨Limits.IsInitial.ofUnique _⟩⟩ section variable [∀ (P : Cᵒᵖ ⥤ Type max w v₁ v₂), F.op.HasLeftKanExtension P] /-- `F ⋙ uliftYoneda` is naturally isomorphic to `uliftYoneda ⋙ F.op.lan`. -/ noncomputable def compULiftYonedaIsoULiftYonedaCompLan : F ⋙ uliftYoneda.{max w v₁} ≅ uliftYoneda.{max w v₂} ⋙ F.op.lan := NatIso.ofComponents (fun X => Functor.leftKanExtensionUnique _ (uliftYonedaMap.{w} F X) (F.op.lan.obj _) (F.op.lanUnit.app (uliftYoneda.obj X))) (fun {X Y} f => by apply uliftYonedaEquiv.injective have eq₁ := congr_fun ((uliftYoneda.{max w v₁}.obj (F.obj Y)).descOfIsLeftKanExtension_fac_app (uliftYonedaMap F Y) (F.op.lan.obj (uliftYoneda.obj Y)) (F.op.lanUnit.app (uliftYoneda.obj Y)) _) ⟨f⟩ have eq₂ := congr_fun (((uliftYoneda.{max w v₁}.obj (F.obj X)).descOfIsLeftKanExtension_fac_app (uliftYonedaMap F X) (F.op.lan.obj (uliftYoneda.obj X)) (F.op.lanUnit.app (uliftYoneda.obj X))) _) ⟨𝟙 _⟩ have eq₃ := congr_fun (congr_app (F.op.lanUnit.naturality (uliftYoneda.{max w v₂}.map f)) _) ⟨𝟙 _⟩ dsimp [uliftYoneda, uliftYonedaMap, uliftYonedaEquiv, Functor.leftKanExtensionUnique] at eq₁ eq₂ eq₃ ⊢ simp only [Functor.map_id] at eq₂ simp only [id_comp] at eq₃ simp [eq₁, eq₂, eq₃]) @[simp] lemma compULiftYonedaIsoULiftYonedaCompLan_inv_app_app_apply_eq_id (X : C) : ((compULiftYonedaIsoULiftYonedaCompLan.{w} F).inv.app X).app (op (F.obj X)) ((F.op.lanUnit.app ((uliftYoneda.{max w v₂}).obj X)).app (op X) (ULift.up (𝟙 X))) = ULift.up (𝟙 (F.obj X)) := (congr_fun (Functor.descOfIsLeftKanExtension_fac_app _ (F.op.lanUnit.app ((uliftYoneda.{max w v₂}).obj X)) _ (uliftYonedaMap.{w} F X) (op X)) (ULift.up (𝟙 X))).trans (by simp [uliftYonedaMap]) end namespace compULiftYonedaIsoULiftYonedaCompLan variable {F} section variable {X : C} {G : (Cᵒᵖ ⥤ Type (max w v₁ v₂)) ⥤ Dᵒᵖ ⥤ Type (max w v₁ v₂)} (φ : F ⋙ uliftYoneda.{max w v₁} ⟶ uliftYoneda.{max w v₂} ⋙ G) /-- Auxiliary definition for `presheafHom`. -/ def coconeApp {P : Cᵒᵖ ⥤ Type max w v₁ v₂} (x : P.Elements) : uliftYoneda.{max w v₂}.obj x.1.unop ⟶ F.op ⋙ G.obj P := uliftYonedaEquiv.symm ((G.map (uliftYonedaEquiv.{max w v₂}.symm x.2)).app _ ((φ.app x.1.unop).app _ (ULift.up (𝟙 _)))) @[reassoc (attr := simp)] lemma coconeApp_naturality {P : Cᵒᵖ ⥤ Type max w v₁ v₂} {x y : P.Elements} (f : x ⟶ y) : uliftYoneda.map f.1.unop ≫ coconeApp.{w} φ x = coconeApp φ y := by have eq₁ : uliftYoneda.map f.1.unop ≫ uliftYonedaEquiv.symm x.2 = uliftYonedaEquiv.{max w v₂}.symm y.2 := uliftYonedaEquiv.injective (by simpa only [Equiv.apply_symm_apply, ← uliftYonedaEquiv_naturality] using f.2) have eq₂ := congr_fun ((G.map (uliftYonedaEquiv.{max w v₂}.symm x.2)).naturality (F.map f.1.unop).op) ((φ.app x.1.unop).app _ (ULift.up (𝟙 _))) have eq₃ := congr_fun (congr_app (φ.naturality f.1.unop) _) (ULift.up (𝟙 _)) have eq₄ := congr_fun ((φ.app x.1.unop).naturality (F.map f.1.unop).op) dsimp at eq₂ eq₃ eq₄ apply uliftYonedaEquiv.{max w v₂}.injective dsimp only [coconeApp] rw [Equiv.apply_symm_apply, ← uliftYonedaEquiv_naturality, Equiv.apply_symm_apply] simp only [← eq₁, ← eq₂, ← eq₃, ← eq₄, op_unop, Functor.comp_obj, Functor.op_obj, yoneda_obj_obj, Functor.comp_map, Functor.op_map, Functor.map_comp, FunctorToTypes.comp,] simp [uliftYoneda] /-- Given functors `F : C ⥤ D` and `G : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ (Dᵒᵖ ⥤ Type max w v₁ v₂)`, and a natural transformation `φ : F ⋙ uliftYoneda ⟶ uliftYoneda ⋙ G`, this is the (natural) morphism `P ⟶ F.op ⋙ G.obj P` for all `P : Cᵒᵖ ⥤ Type max w v₁ v₂` that is determined by `φ`. -/ def presheafHom (P : Cᵒᵖ ⥤ Type max w v₁ v₂) : P ⟶ F.op ⋙ G.obj P := (colimitOfRepresentable P).desc (Cocone.mk _ { app x := coconeApp.{w} φ x.unop }) lemma uliftYonedaEquiv_ι_presheafHom (P : Cᵒᵖ ⥤ Type max w v₁ v₂) {X : C} (f : uliftYoneda.{max w v₂}.obj X ⟶ P) : uliftYonedaEquiv (f ≫ presheafHom.{w} φ P) = (G.map f).app (Opposite.op (F.obj X)) ((φ.app X).app _ (ULift.up (𝟙 _))) := by obtain ⟨x, rfl⟩ := uliftYonedaEquiv.symm.surjective f erw [(colimitOfRepresentable P).fac _ (Opposite.op (P.elementsMk _ x))] dsimp only [coconeApp] apply Equiv.apply_symm_apply lemma uliftYonedaEquiv_presheafHom_uliftYoneda_obj (X : C) : uliftYonedaEquiv.{max w v₂} (presheafHom.{w} φ (uliftYoneda.{max w v₂}.obj X)) = ((φ.app X).app (F.op.obj (Opposite.op X)) (ULift.up (𝟙 _))) := by simpa using uliftYonedaEquiv_ι_presheafHom.{w} φ (uliftYoneda.obj X) (𝟙 _) @[reassoc (attr := simp)] lemma presheafHom_naturality {P Q : Cᵒᵖ ⥤ Type max w v₁ v₂} (f : P ⟶ Q) : presheafHom.{w} φ P ≫ Functor.whiskerLeft F.op (G.map f) = f ≫ presheafHom φ Q := hom_ext_uliftYoneda.{max w v₂} (fun X p ↦ uliftYonedaEquiv.injective (by rw [← assoc p f, uliftYonedaEquiv_ι_presheafHom, ← assoc, uliftYonedaEquiv_comp, uliftYonedaEquiv_ι_presheafHom, Functor.map_comp, FunctorToTypes.comp] dsimp)) variable [∀ (P : Cᵒᵖ ⥤ Type max w v₁ v₂), F.op.HasLeftKanExtension P] /-- Given functors `F : C ⥤ D` and `G : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ (Dᵒᵖ ⥤ Type max w v₁ v₂)`, and a natural transformation `φ : F ⋙ uliftYoneda ⟶ uliftYoneda ⋙ G`, this is the canonical natural transformation `F.op.lan ⟶ G`, which is part of the fact that `F.op.lan : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ Dᵒᵖ ⥤ Type max w v₁ v₂` is the left Kan extension of `F ⋙ uliftYoneda : C ⥤ Dᵒᵖ ⥤ Type max w v₁ v₂` along `uliftYoneda : C ⥤ Cᵒᵖ ⥤ Type max w v₁ 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_uliftYoneda_obj (X : C) : (natTrans.{w} φ).app (uliftYoneda.{max w v₂}.obj X) = (compULiftYonedaIsoULiftYonedaCompLan.{w} F).inv.app X ≫ φ.app X := by dsimp [natTrans] apply (F.op.lan.obj (uliftYoneda.obj X)).hom_ext_of_isLeftKanExtension (F.op.lanUnit.app _) rw [Functor.descOfIsLeftKanExtension_fac] apply uliftYonedaEquiv.injective rw [uliftYonedaEquiv_presheafHom_uliftYoneda_obj] exact congr_arg _ (compULiftYonedaIsoULiftYonedaCompLan_inv_app_app_apply_eq_id F X).symm end variable [∀ (P : Cᵒᵖ ⥤ Type max w v₁ 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 (compULiftYonedaIsoULiftYonedaCompLan F).hom` is universal, i.e. that `F.op.lan : (Cᵒᵖ ⥤ Type max w v₁ v₂) ⥤ Dᵒᵖ ⥤ Type max w v₁ v₂` is the left Kan extension of `F ⋙ uliftYoneda : C ⥤ Dᵒᵖ ⥤ Type max w v₁ v₂` along `uliftYoneda : C ⥤ Cᵒᵖ ⥤ Type max w v₁ v₂`. -/ noncomputable def extensionHom (Φ : uliftYoneda.{max w v₂}.LeftExtension (F ⋙ uliftYoneda.{max w v₁})) : Functor.LeftExtension.mk F.op.lan (compULiftYonedaIsoULiftYonedaCompLan.{w} F).hom ⟶ Φ := StructuredArrow.homMk (natTrans Φ.hom) (by ext X : 2 dsimp rw [natTrans_app_uliftYoneda_obj, Iso.hom_inv_id_app_assoc]) @[ext] lemma hom_ext {Φ : uliftYoneda.{max w v₂}.LeftExtension (F ⋙ uliftYoneda.{max w v₁})} (f g : Functor.LeftExtension.mk F.op.lan (compULiftYonedaIsoULiftYonedaCompLan 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.{max w v₂} P).hom_ext intro x have eq := F.op.lanUnit.naturality (uliftYonedaEquiv.{max w v₂}.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)) (ULift.up (𝟙 _)) have eq₂ := congr_fun (congr_app (congr_app (StructuredArrow.w g) x.unop.1.unop) (F.op.obj x.unop.1)) (ULift.up (𝟙 _)) dsimp at eq₁ eq₂ eq ⊢ simp only [reassoc_of% eq, ← Functor.whiskerLeft_comp] congr 2 simp only [← cancel_epi ((compULiftYonedaIsoULiftYonedaCompLan F).hom.app x.unop.1.unop), NatTrans.naturality] apply uliftYonedaEquiv.injective dsimp [uliftYonedaEquiv_apply] rw [eq₁, eq₂] end compULiftYonedaIsoULiftYonedaCompLan variable [∀ (P : Cᵒᵖ ⥤ Type max w v₁ v₂), F.op.HasLeftKanExtension P] noncomputable instance (Φ : StructuredArrow (F ⋙ uliftYoneda.{max w v₁}) ((Functor.whiskeringLeft C (Cᵒᵖ ⥤ Type max w v₁ v₂) (Dᵒᵖ ⥤ Type max w v₁ v₂)).obj uliftYoneda.{max w v₂})) : Unique (Functor.LeftExtension.mk F.op.lan (compULiftYonedaIsoULiftYonedaCompLan.{w} F).hom ⟶ Φ) where default := compULiftYonedaIsoULiftYonedaCompLan.extensionHom Φ uniq _ := compULiftYonedaIsoULiftYonedaCompLan.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 (compULiftYonedaIsoULiftYonedaCompLan.{w} F).hom := ⟨⟨Limits.IsInitial.ofUnique _⟩⟩ end /-- 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. (In this version, we allow the presheaf `P` to have values in a larger universe.) -/ @[simps] def tautologicalCocone' (P : Cᵒᵖ ⥤ Type max w v₁) : Cocone (CostructuredArrow.proj uliftYoneda.{w} P ⋙ uliftYoneda.{w}) where pt := P ι := { app X := X.hom } /-- The tautological cocone with point `P` is a colimit cocone, exhibiting `P` as a colimit of representables. (In this version, we allow the presheaf `P` to have values in a larger universe.) Proposition 2.6.3(i) in [Kashiwara2006] -/ def isColimitTautologicalCocone' (P : Cᵒᵖ ⥤ Type max w v₁) : IsColimit (tautologicalCocone'.{w} P) := (IsColimit.whiskerEquivalenceEquiv (CategoryOfElements.costructuredArrowULiftYonedaEquivalence.{w} P)).2 (colimitOfRepresentable.{w} P) /-- 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 (P : Cᵒᵖ ⥤ Type v₁) : Cocone (CostructuredArrow.proj yoneda P ⋙ yoneda) where pt := P ι := { app 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 (P : Cᵒᵖ ⥤ Type v₁) : IsColimit (tautologicalCocone P) := let e : functorToRepresentables.{v₁} P ≅ ((CategoryOfElements.costructuredArrowYonedaEquivalence P).functor ⋙ CostructuredArrow.proj yoneda P ⋙ yoneda) := NatIso.ofComponents (fun e ↦ NatIso.ofComponents (fun X ↦ Equiv.ulift.toIso)) (IsColimit.whiskerEquivalenceEquiv (CategoryOfElements.costructuredArrowYonedaEquivalence P)).2 ((IsColimit.precomposeHomEquiv e _).1 (colimitOfRepresentable.{v₁} P)) 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.final_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 Functor.isoWhiskerLeft _ (CostructuredArrow.toOverCompOverEquivPresheafCostructuredArrow c.pt).isoCompInverse apply IsTerminal.ofIso Over.mkIdTerminal let isc : IsColimit ((Over.forget _).mapCocone _) := isColimitOfPreserves _ (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) @[deprecated (since := "2025-08-16")] alias restrictedYoneda := restrictedULiftYoneda @[deprecated (since := "2025-08-16")] alias isExtensionAlongYoneda := isExtensionAlongULiftYoneda @[deprecated (since := "2025-08-16")] alias isLeftKanExtension_along_yoneda_iff := isLeftKanExtension_along_uliftYoneda_iff @[deprecated (since := "2025-08-16")] alias yonedaAdjunction := uliftYonedaAdjunction @[deprecated (since := "2025-08-16")] alias uniqueExtensionAlongYoneda := uniqueExtensionAlongULiftYoneda end Presheaf end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/FilteredColimitCommutesFiniteLimit.lean
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.Types.Filtered 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 MonoidWithZero universe w v₁ v₂ v u₁ u₂ u open CategoryTheory CategoryTheory.Category CategoryTheory.Limits.Types CategoryTheory.Limits.Types.FilteredColimit CategoryTheory.Functor 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 [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) (limit.π ((curry.obj (swap K J ⋙ F)).obj kx) j x) = F.map (𝟙 j ×ₘ g 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, Finset.mem_univ, Finset.mem_image] refine ⟨j, ?_⟩ simp only )) 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, Finset.mem_univ, Finset.mem_image] refine ⟨j, ?_⟩ simp only)) -- 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] rw [← W _ _ (fH j), ← W _ _ (gH j)] simp [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') (y j')) = colimit.ι ((curry.obj F).obj j') k' (F.map (f ×ₘ g j) (y j)) := by intro j j' f simp only [Colimit.w_apply, ← Bifunctor.diagonal', ← curry_obj_obj_map, ← curry_obj_map_app] rw [types_comp_apply, Colimit.w_apply, e, ← Limit.w_apply.{u₁, v, u₁} f, ← e] simp [Types.Colimit.ι_map_apply] -- 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)) (y j') = F.map (f ×ₘ (g j ≫ hf f)) (y j) := fun {j j'} f => by have q : ((curry.obj F).obj j').map (gf f) (F.map (𝟙 j' ×ₘ g j') (y j')) = ((curry.obj F).obj j').map (hf f) (F.map (f ×ₘ g j) (y j)) := (w f).choose_spec.choose_spec.choose_spec dsimp only [curry_obj_obj_map, curry_obj_obj_map] at q 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 intro j₁ j₂ j₃ j₄ f f' rw [s', s'] · 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))) (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))) (y j) = F.map (f ×ₘ (g j ≫ hf f ≫ i f)) (y j) := by rw [s (𝟙 j) f] _ = F.map (𝟙 j' ×ₘ i f) (F.map (f ×ₘ (g j ≫ hf f)) (y j)) := by rw [← FunctorToTypes.map_comp_apply, prod_comp, comp_id, assoc] _ = F.map (𝟙 j' ×ₘ i f) (F.map (𝟙 j' ×ₘ (g j' ≫ gf f)) (y j')) := by rw [← wf f] _ = F.map (𝟙 j' ×ₘ (g j' ≫ gf f ≫ i f)) (y j') := by rw [← FunctorToTypes.map_comp_apply, prod_comp, id_comp, assoc] _ = F.map (𝟙 j' ×ₘ (g j' ≫ gf (𝟙 j') ≫ i (𝟙 j'))) (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), ?_⟩ 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 filtered_colim_preservesFiniteLimits_of_types : PreservesFiniteLimits (colim : (K ⥤ Type v) ⥤ _) := by apply preservesFiniteLimits_of_preservesFiniteLimitsOfSize.{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] [HasForget.{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 filtered_colim_preservesFiniteLimits : PreservesLimitsOfShape J (colim : (K ⥤ C) ⥤ _) := haveI : PreservesLimitsOfShape J ((colim : (K ⥤ C) ⥤ _) ⋙ forget C) := preservesLimitsOfShape_of_natIso (preservesColimitNatIso _).symm preservesLimitsOfShape_of_reflects_of_preserves _ (forget C) end attribute [local instance] reflectsLimitsOfShape_of_reflectsIsomorphisms noncomputable instance [PreservesFiniteLimits (forget C)] [PreservesColimitsOfShape K (forget C)] [HasFiniteLimits C] [HasColimitsOfShape K C] [(forget C).ReflectsIsomorphisms] : PreservesFiniteLimits (colim : (K ⥤ C) ⥤ _) := by apply preservesFiniteLimits_of_preservesFiniteLimitsOfSize.{v} intro J _ _ infer_instance end section variable {C : Type u} [Category.{v} C] variable {J : Type u₁} [Category.{v₁} J] variable {K : Type u₂} [Category.{v₂} K] variable [HasLimitsOfShape J C] [HasColimitsOfShape K C] variable [PreservesLimitsOfShape J (colim : (K ⥤ 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] simp end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Cones.lean
import Mathlib.CategoryTheory.Functor.Const import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.Yoneda import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic /-! # 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 [category theory universes]. universe v₁ v₂ v₃ v₄ v₅ u₁ 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] variable {E : Type u₅} [Category.{v₅} E] 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 => cat_disch } }⟩ @[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 => simp } }⟩ @[reassoc] 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 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 _ 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 _ 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 cat_disch 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 } /- We do not want `simps` automatically generate the lemma for simplifying the hom field of a category. So we need to write the `ext` lemma in terms of the categorical morphism, rather than the underlying structure. -/ @[ext] theorem ConeMorphism.ext {c c' : Cone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr @[reassoc (attr := simp)] lemma ConeMorphism.hom_inv_id {c d : Cone F} (f : c ≅ d) : f.hom.hom ≫ f.inv.hom = 𝟙 _ := by simp [← Cone.category_comp_hom] @[reassoc (attr := simp)] lemma ConeMorphism.inv_hom_id {c d : Cone F} (f : c ≅ d) : f.inv.hom ≫ f.hom.hom = 𝟙 _ := by simp [← Cone.category_comp_hom] instance {c d : Cone F} (f : c ≅ d) : IsIso f.hom.hom := ⟨f.inv.hom, by simp⟩ instance {c d : Cone F} (f : c ≅ d) : IsIso f.inv.hom := ⟨f.hom.hom, by simp⟩ @[reassoc (attr := simp)] lemma ConeMorphism.map_w {c c' : Cone F} (f : c ⟶ c') (G : C ⥤ D) (j : J) : G.map f.hom ≫ G.map (c'.π.app j) = G.map (c.π.app j) := by simp only [← map_comp, ConeMorphism.w] namespace Cones /-- To give an isomorphism between cones, it suffices to give an isomorphism between their vertices which commutes with the cone maps. -/ @[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 cat_disch) : 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 cat_disch⟩⟩ /-- 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 cat_disch⟩ /-- 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]; simp } } map f := { hom := G.map f.hom w := ConeMorphism.map_w f G } /-- Functoriality is functorial. -/ def functorialityCompFunctoriality (H : D ⥤ E) : functoriality F G ⋙ functoriality (F ⋙ G) H ≅ functoriality F (G ⋙ H) := NatIso.ofComponents (fun _ ↦ Iso.refl _) (by simp [functoriality]) 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 cat_disch⟩ 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 cat_disch 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 } /- We do not want `simps` automatically generate the lemma for simplifying the hom field of a category. So we need to write the `ext` lemma in terms of the categorical morphism, rather than the underlying structure. -/ @[ext] theorem CoconeMorphism.ext {c c' : Cocone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr @[reassoc (attr := simp)] lemma CoconeMorphism.hom_inv_id {c d : Cocone F} (f : c ≅ d) : f.hom.hom ≫ f.inv.hom = 𝟙 _ := by simp [← Cocone.category_comp_hom] @[reassoc (attr := simp)] lemma CoconeMorphism.inv_hom_id {c d : Cocone F} (f : c ≅ d) : f.inv.hom ≫ f.hom.hom = 𝟙 _ := by simp [← Cocone.category_comp_hom] instance {c d : Cocone F} (f : c ≅ d) : IsIso f.hom.hom := ⟨f.inv.hom, by simp⟩ instance {c d : Cocone F} (f : c ≅ d) : IsIso f.inv.hom := ⟨f.hom.hom, by simp⟩ @[reassoc (attr := simp)] lemma CoconeMorphism.map_w {c c' : Cocone F} (f : c ⟶ c') (G : C ⥤ D) (j : J) : G.map (c.ι.app j) ≫ G.map f.hom = G.map (c'.ι.app j) := by simp only [← map_comp, CoconeMorphism.w] namespace Cocones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Cocone F} (φ : c.pt ≅ c'.pt) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j := by cat_disch) : 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 cat_disch⟩⟩ /-- 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 cat_disch⟩ /-- 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]; simp } } map f := { hom := G.map f.hom w := CoconeMorphism.map_w f G } /-- Functoriality is functorial. -/ def functorialityCompFunctoriality (H : D ⥤ E) : functoriality F G ⋙ functoriality (F ⋙ G) H ≅ functoriality F (G ⋙ H) := NatIso.ofComponents (fun _ ↦ Iso.refl _) (by simp [functoriality]) 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 cat_disch⟩ 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 construction `mapCone` respects functor composition. -/ @[simps!] noncomputable def mapConeMapCone {F : J ⥤ C} {H : C ⥤ D} {H' : D ⥤ E} (c : Cone F) : H'.mapCone (H.mapCone c) ≅ (H ⋙ H').mapCone c := Cones.ext (Iso.refl _) /-- 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 /-- The construction `mapCocone` respects functor composition. -/ @[simps!] noncomputable def mapCoconeMapCocone {F : J ⥤ C} {H : C ⥤ D} {H' : D ⥤ E} (c : Cocone F) : H'.mapCocone (H.mapCocone c) ≅ (H ⋙ H').mapCocone c := Cocones.ext (Iso.refl _) /-- 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 => (Cones.ext (Iso.refl c.unop.pt)).op) 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. -/ @[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. -/ @[simps!] def mapCoconeOp {t : Cocone F} : (mapCocone G t).op ≅ mapCone G.op t.op := Cones.ext (Iso.refl _) end end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Final.lean
import Mathlib.CategoryTheory.Category.Cat.AsSmall import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Types.Products import Mathlib.CategoryTheory.Limits.Shapes.Grothendieck import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.PUnit import Mathlib.CategoryTheory.Grothendieck /-! # 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 `final_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`. In the end of the file, we characterize the finality of some important induced functors on the (co)structured arrow category (`StructuredArrow.pre` and `CostructuredArrow.pre`) and on the Grothendieck construction (`Grothendieck.pre` and `Grothendieck.map`). ## 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₃ v₄ u₁ 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. -/ @[stacks 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) } attribute [local simp] Adjunction.homEquiv_unit Adjunction.homEquiv_counit /-- 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 final, 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 final, 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 simp · intro j₁ j₂ f a fapply h₂ _ _ _ _ f.right _ a convert f.w.symm 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 only [Category.comp_id] -- 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 } /-- Alternative equational lemma for `(extendCocone c).ι.app` in case a lift of the object is given explicitly. -/ lemma extendCocone_obj_ι_app' (c : Cocone (F ⋙ G)) {X : D} {Y : C} (f : X ⟶ F.obj Y) : (extendCocone.obj c).ι.app X = G.map f ≫ c.ι.app Y := by apply induction (k₀ := f) (z := rfl) F fun Z g => G.map g ≫ c.ι.app Z = G.map f ≫ c.ι.app Y · intro _ _ _ _ _ h₁ h₂ simp [← h₁, ← Functor.comp_map, c.ι.naturality, h₂] · intro _ _ _ _ _ h₁ h₂ simp [← h₂, ← h₁, ← Functor.comp_map, c.ι.naturality] @[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 final, 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 final, 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 final, 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 (priority := 100) comp_preservesColimit {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [PreservesColimit G H] : PreservesColimit (F ⋙ G) H where preserves {c} hc := by refine ⟨isColimitExtendCoconeEquiv (G := G ⋙ H) F (H.mapCocone c) ?_⟩ let hc' := isColimitOfPreserves H ((isColimitExtendCoconeEquiv F c).symm hc) exact IsColimit.ofIsoColimit hc' (Cocones.ext (Iso.refl _) (by simp)) instance (priority := 100) comp_reflectsColimit {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [ReflectsColimit G H] : ReflectsColimit (F ⋙ G) H where reflects {c} hc := by refine ⟨isColimitExtendCoconeEquiv F _ (isColimitOfReflects H ?_)⟩ let hc' := (isColimitExtendCoconeEquiv (G := G ⋙ H) F _).symm hc exact IsColimit.ofIsoColimit hc' (Cocones.ext (Iso.refl _) (by simp)) instance (priority := 100) compCreatesColimit {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [CreatesColimit G H] : CreatesColimit (F ⋙ G) H where lifts {c} hc := by refine ⟨(liftColimit ((isColimitExtendCoconeEquiv F (G := G ⋙ H) _).symm hc)).whisker F, ?_⟩ let i := liftedColimitMapsToOriginal ((isColimitExtendCoconeEquiv F (G := G ⋙ H) _).symm hc) exact (Cocones.whiskering F).mapIso i ≪≫ ((coconesEquiv F (G ⋙ H)).unitIso.app _).symm 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 final, and `G : D ⥤ E` has a colimit, then `F ⋙ G` has a colimit also and `colimit (F ⋙ G) ≅ colimit G`. -/ @[simps! -isSimp, stacks 04E7] def colimitIso [HasColimit G] : colimit (F ⋙ G) ≅ colimit G := asIso (colimit.pre G F) @[reassoc (attr := simp)] theorem ι_colimitIso_hom [HasColimit G] (X : C) : colimit.ι (F ⋙ G) X ≫ (colimitIso F G).hom = colimit.ι G (F.obj X) := by simp [colimitIso] @[reassoc (attr := simp)] theorem ι_colimitIso_inv [HasColimit G] (X : C) : colimit.ι G (F.obj X) ≫ (colimitIso F G).inv = colimit.ι (F ⋙ G) X := by simp [colimitIso] /-- A pointfree version of `colimitIso`, stating that whiskering by `F` followed by taking the colimit is isomorphic to taking the colimit on the codomain of `F`. -/ def colimIso [HasColimitsOfShape D E] [HasColimitsOfShape C E] : (whiskeringLeft _ _ _).obj F ⋙ colim ≅ colim (J := D) (C := E) := NatIso.ofComponents (fun G => colimitIso F G) fun f => by simp only [comp_obj, whiskeringLeft_obj_obj, colim_obj, comp_map, whiskeringLeft_obj_map, colim_map, colimitIso_hom] ext simp only [comp_obj, ι_colimMap_assoc, whiskerLeft_app, colimit.ι_pre, colimit.ι_pre_assoc, ι_colimMap] 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 final, 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))) lemma hasColimit_comp_iff : HasColimit (F ⋙ G) ↔ HasColimit G := ⟨fun _ ↦ Functor.Final.hasColimit_of_comp F, fun _ ↦ inferInstance⟩ theorem preservesColimit_of_comp {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [PreservesColimit (F ⋙ G) H] : PreservesColimit G H where preserves {c} hc := by refine ⟨isColimitWhiskerEquiv F _ ?_⟩ let hc' := isColimitOfPreserves H ((isColimitWhiskerEquiv F _).symm hc) exact IsColimit.ofIsoColimit hc' (Cocones.ext (Iso.refl _) (by simp)) theorem reflectsColimit_of_comp {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [ReflectsColimit (F ⋙ G) H] : ReflectsColimit G H where reflects {c} hc := by refine ⟨isColimitWhiskerEquiv F _ (isColimitOfReflects H ?_)⟩ let hc' := (isColimitWhiskerEquiv F _).symm hc exact IsColimit.ofIsoColimit hc' (Cocones.ext (Iso.refl _) (by simp)) /-- If `F` is final and `F ⋙ G` creates colimits of `H`, then so does `G`. -/ def createsColimitOfComp {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [CreatesColimit (F ⋙ G) H] : CreatesColimit G H where reflects := (reflectsColimit_of_comp F).reflects lifts {c} hc := by refine ⟨(extendCocone (F := F)).obj (liftColimit ((isColimitWhiskerEquiv F _).symm hc)), ?_⟩ let i := liftedColimitMapsToOriginal (K := (F ⋙ G)) ((isColimitWhiskerEquiv F _).symm hc) refine ?_ ≪≫ ((extendCocone (F := F)).mapIso i) ≪≫ ((coconesEquiv F (G ⋙ H)).counitIso.app _) exact Cocones.ext (Iso.refl _) include F in theorem hasColimitsOfShape_of_final [HasColimitsOfShape C E] : HasColimitsOfShape D E where has_colimit := fun _ => hasColimit_of_comp F include F in theorem preservesColimitsOfShape_of_final {B : Type u₄} [Category.{v₄} B] (H : E ⥤ B) [PreservesColimitsOfShape C H] : PreservesColimitsOfShape D H where preservesColimit := preservesColimit_of_comp F include F in theorem reflectsColimitsOfShape_of_final {B : Type u₄} [Category.{v₄} B] (H : E ⥤ B) [ReflectsColimitsOfShape C H] : ReflectsColimitsOfShape D H where reflectsColimit := reflectsColimit_of_comp F include F in /-- If `H` creates colimits of shape `C` and `F : C ⥤ D` is final, then `H` creates colimits of shape `D`. -/ def createsColimitsOfShapeOfFinal {B : Type u₄} [Category.{v₄} B] (H : E ⥤ B) [CreatesColimitsOfShape C H] : CreatesColimitsOfShape D H where CreatesColimit := createsColimitOfComp F 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_colimitTypeRel {F : C ⥤ D} {d : D} {f₁ f₂ : Σ X, d ⟶ F.obj X} (t : Relation.EqvGen (Functor.ColimitTypeRel (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₂ @[deprecated (since := "2025-06-22")] alias zigzag_of_eqvGen_quot_rel := zigzag_of_eqvGen_colimitTypeRel end Final /-- If `colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit` for all `d : D`, then `F` is final. -/ theorem final_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_colimitTypeRel t⟩ /-- A variant of `final_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 final_of_isTerminal_colimit_comp_yoneda (h : IsTerminal (colimit (F ⋙ yoneda))) : Final F := by refine final_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 final), 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 _ => final_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 simp · intro j₁ j₂ f a fapply h₂ _ _ _ _ f.left _ a convert f.w 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 only [Category.id_comp, Category.assoc] -- 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 } /-- Alternative equational lemma for `(extendCone c).π.app` in case a lift of the object is given explicitly. -/ lemma extendCone_obj_π_app' (c : Cone (F ⋙ G)) {X : C} {Y : D} (f : F.obj X ⟶ Y) : (extendCone.obj c).π.app Y = c.π.app X ≫ G.map f := by apply induction (k₀ := f) (z := rfl) F fun Z g => c.π.app Z ≫ G.map g = c.π.app X ≫ G.map f · intro _ _ _ _ _ h₁ h₂ simp [← h₂, ← h₁, ← Functor.comp_map] · intro _ _ _ _ _ h₁ h₂ simp [← h₁, ← Functor.comp_map, h₂] @[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 (priority := 100) comp_preservesLimit {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [PreservesLimit G H] : PreservesLimit (F ⋙ G) H where preserves {c} hc := by refine ⟨isLimitExtendConeEquiv (G := G ⋙ H) F (H.mapCone c) ?_⟩ let hc' := isLimitOfPreserves H ((isLimitExtendConeEquiv F c).symm hc) exact IsLimit.ofIsoLimit hc' (Cones.ext (Iso.refl _) (by simp)) instance (priority := 100) comp_reflectsLimit {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [ReflectsLimit G H] : ReflectsLimit (F ⋙ G) H where reflects {c} hc := by refine ⟨isLimitExtendConeEquiv F _ (isLimitOfReflects H ?_)⟩ let hc' := (isLimitExtendConeEquiv (G := G ⋙ H) F _).symm hc exact IsLimit.ofIsoLimit hc' (Cones.ext (Iso.refl _) (by simp)) instance (priority := 100) compCreatesLimit {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [CreatesLimit G H] : CreatesLimit (F ⋙ G) H where lifts {c} hc := by refine ⟨(liftLimit ((isLimitExtendConeEquiv F (G := G ⋙ H) _).symm hc)).whisker F, ?_⟩ let i := liftedLimitMapsToOriginal ((isLimitExtendConeEquiv F (G := G ⋙ H) _).symm hc) exact (Cones.whiskering F).mapIso i ≪≫ ((conesEquiv F (G ⋙ H)).unitIso.app _).symm 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`. -/ @[simps! -isSimp, stacks 04E7] def limitIso [HasLimit G] : limit (F ⋙ G) ≅ limit G := (asIso (limit.pre G F)).symm /-- A pointfree version of `limitIso`, stating that whiskering by `F` followed by taking the limit is isomorphic to taking the limit on the codomain of `F`. -/ def limIso [HasLimitsOfShape D E] [HasLimitsOfShape C E] : (whiskeringLeft _ _ _).obj F ⋙ lim ≅ lim (J := D) (C := E) := Iso.symm <| NatIso.ofComponents (fun G => (limitIso F G).symm) fun f => by simp only [comp_obj, whiskeringLeft_obj_obj, lim_obj, comp_map, whiskeringLeft_obj_map, lim_map, Iso.symm_hom, limitIso_inv] ext simp 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))) lemma hasLimit_comp_iff : HasLimit (F ⋙ G) ↔ HasLimit G := ⟨fun _ ↦ Functor.Initial.hasLimit_of_comp F, fun _ ↦ inferInstance⟩ theorem preservesLimit_of_comp {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [PreservesLimit (F ⋙ G) H] : PreservesLimit G H where preserves {c} hc := by refine ⟨isLimitWhiskerEquiv F _ ?_⟩ let hc' := isLimitOfPreserves H ((isLimitWhiskerEquiv F _).symm hc) exact IsLimit.ofIsoLimit hc' (Cones.ext (Iso.refl _) (by simp)) theorem reflectsLimit_of_comp {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [ReflectsLimit (F ⋙ G) H] : ReflectsLimit G H where reflects {c} hc := by refine ⟨isLimitWhiskerEquiv F _ (isLimitOfReflects H ?_)⟩ let hc' := (isLimitWhiskerEquiv F _).symm hc exact IsLimit.ofIsoLimit hc' (Cones.ext (Iso.refl _) (by simp)) /-- If `F` is initial and `F ⋙ G` creates limits of `H`, then so does `G`. -/ def createsLimitOfComp {B : Type u₄} [Category.{v₄} B] {H : E ⥤ B} [CreatesLimit (F ⋙ G) H] : CreatesLimit G H where reflects := (reflectsLimit_of_comp F).reflects lifts {c} hc := by refine ⟨(extendCone (F := F)).obj (liftLimit ((isLimitWhiskerEquiv F _).symm hc)), ?_⟩ let i := liftedLimitMapsToOriginal (K := (F ⋙ G)) ((isLimitWhiskerEquiv F _).symm hc) refine ?_ ≪≫ ((extendCone (F := F)).mapIso i) ≪≫ ((conesEquiv F (G ⋙ H)).counitIso.app _) exact Cones.ext (Iso.refl _) include F in theorem hasLimitsOfShape_of_initial [HasLimitsOfShape C E] : HasLimitsOfShape D E where has_limit := fun _ => hasLimit_of_comp F include F in theorem preservesLimitsOfShape_of_initial {B : Type u₄} [Category.{v₄} B] (H : E ⥤ B) [PreservesLimitsOfShape C H] : PreservesLimitsOfShape D H where preservesLimit := preservesLimit_of_comp F include F in theorem reflectsLimitsOfShape_of_initial {B : Type u₄} [Category.{v₄} B] (H : E ⥤ B) [ReflectsLimitsOfShape C H] : ReflectsLimitsOfShape D H where reflectsLimit := reflectsLimit_of_comp F include F in /-- If `H` creates limits of shape `C` and `F : C ⥤ D` is initial, then `H` creates limits of shape `D`. -/ def createsLimitsOfShapeOfInitial {B : Type u₄} [Category.{v₄} B] (H : E ⥤ B) [CreatesLimitsOfShape C H] : CreatesLimitsOfShape D H where CreatesLimit := createsLimitOfComp F 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 `initial_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 section variable {C : Type u₁} [Category.{v₁} C] {c : C} lemma final_fromPUnit_of_isTerminal (hc : Limits.IsTerminal c) : (fromPUnit c).Final where out c' := by letI : Inhabited (StructuredArrow c' (fromPUnit c)) := ⟨.mk (Y := default) (hc.from c')⟩ letI : Subsingleton (StructuredArrow c' (fromPUnit c)) := ⟨fun i j ↦ StructuredArrow.obj_ext _ _ (by cat_disch) (hc.hom_ext _ _)⟩ infer_instance lemma initial_fromPUnit_of_isInitial (hc : Limits.IsInitial c) : (fromPUnit c).Initial where out c' := by letI : Inhabited (CostructuredArrow (fromPUnit c) c') := ⟨.mk (Y := default) (hc.to c')⟩ letI : Subsingleton (CostructuredArrow (fromPUnit c) c') := ⟨fun i j ↦ CostructuredArrow.obj_ext _ _ (by cat_disch) (hc.hom_ext _ _)⟩ infer_instance 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 `initial_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 `initial_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 section variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] open Functor /-- The functor `StructuredArrow.pre X T S` is final if `T` is final. -/ instance StructuredArrow.final_pre (T : C ⥤ D) [Final T] (S : D ⥤ E) (X : E) : Final (pre X T S) := by refine ⟨fun f => ?_⟩ rw [isConnected_iff_of_equivalence (StructuredArrow.preEquivalence T f)] exact Final.out f.right /-- The functor `CostructuredArrow.pre X T S` is initial if `T` is initial. -/ instance CostructuredArrow.initial_pre (T : C ⥤ D) [Initial T] (S : D ⥤ E) (X : E) : Initial (CostructuredArrow.pre T S X) := by refine ⟨fun f => ?_⟩ rw [isConnected_iff_of_equivalence (CostructuredArrow.preEquivalence T f)] exact Initial.out f.left end section Grothendieck variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (F : D ⥤ Cat) (G : C ⥤ D) open Functor /-- A prefunctor mapping structured arrows on `G` to structured arrows on `pre F G` with their action on fibers being the identity. -/ def Grothendieck.structuredArrowToStructuredArrowPre (d : D) (f : F.obj d) : StructuredArrow d G ⥤q StructuredArrow ⟨d, f⟩ (pre F G) where obj := fun X => StructuredArrow.mk (Y := ⟨X.right, (F.map X.hom).obj f⟩) (Grothendieck.Hom.mk (by exact X.hom) (by dsimp; exact 𝟙 _)) map := fun g => StructuredArrow.homMk (Grothendieck.Hom.mk (by exact g.right) (eqToHom (by dsimp; rw [← StructuredArrow.w g, map_comp, Cat.comp_obj]))) (by simp only [StructuredArrow.mk_right] generalize_proofs apply Grothendieck.ext <;> simp) instance Grothendieck.final_pre [hG : Final G] : (Grothendieck.pre F G).Final := by constructor rintro ⟨d, f⟩ let ⟨u, c, g⟩ : Nonempty (StructuredArrow d G) := inferInstance letI : Nonempty (StructuredArrow ⟨d, f⟩ (pre F G)) := ⟨u, ⟨c, (F.map g).obj f⟩, ⟨(by exact g), (by exact 𝟙 _)⟩⟩ apply zigzag_isConnected rintro ⟨⟨⟨⟩⟩, ⟨bi, fi⟩, ⟨gbi, gfi⟩⟩ ⟨⟨⟨⟩⟩, ⟨bj, fj⟩, ⟨gbj, gfj⟩⟩ dsimp at fj fi gfi gbi gbj gfj apply Zigzag.trans (j₂ := StructuredArrow.mk (Y := ⟨bi, ((F.map gbi).obj f)⟩) (Grothendieck.Hom.mk gbi (𝟙 _))) (.of_zag (.inr ⟨StructuredArrow.homMk (Grothendieck.Hom.mk (by dsimp; exact 𝟙 _) (eqToHom (by simp) ≫ gfi)) (by apply Grothendieck.ext <;> simp)⟩)) refine Zigzag.trans (j₂ := StructuredArrow.mk (Y := ⟨bj, ((F.map gbj).obj f)⟩) (Grothendieck.Hom.mk gbj (𝟙 _))) ?_ (.of_zag (.inl ⟨StructuredArrow.homMk (Grothendieck.Hom.mk (by dsimp; exact 𝟙 _) (eqToHom (by simp) ≫ gfj)) (by apply Grothendieck.ext <;> simp)⟩)) exact zigzag_prefunctor_obj_of_zigzag (Grothendieck.structuredArrowToStructuredArrowPre F G d f) (isPreconnected_zigzag (.mk gbi) (.mk gbj)) open Limits /-- A natural transformation `α : F ⟶ G` between functors `F G : C ⥤ Cat` which is final on each fiber `(α.app X)` induces an equivalence of fiberwise colimits of `map α ⋙ H` and `H` for each functor `H : Grothendieck G ⥤ Type`. -/ def Grothendieck.fiberwiseColimitMapCompEquivalence {C : Type u₁} [Category.{v₁} C] {F G : C ⥤ Cat.{v₂, u₂}} (α : F ⟶ G) [∀ X, Final (α.app X)] (H : Grothendieck G ⥤ Type u₂) : fiberwiseColimit (map α ⋙ H) ≅ fiberwiseColimit H := NatIso.ofComponents (fun X => HasColimit.isoOfNatIso ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (ιCompMap α X) H ≪≫ Functor.associator _ _ _) ≪≫ Final.colimitIso (α.app X) (ι G X ⋙ H)) (fun f => colimit.hom_ext <| fun d => by simp only [map, Cat.comp_obj, comp_obj, ι_obj, fiberwiseColimit_obj, fiberwiseColimit_map, ιNatTrans, ιCompMap, Iso.trans_hom, Category.assoc, ι_colimMap_assoc, NatTrans.comp_app, whiskerRight_app, Functor.comp_map, Cat.eqToHom_app, map_id, Category.comp_id, associator_hom_app, colimit.ι_pre_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, Iso.symm_hom, isoWhiskerRight_hom, associator_inv_app, NatIso.ofComponents_hom_app, Iso.refl_hom, Final.ι_colimitIso_hom, Category.id_comp, Final.ι_colimitIso_hom_assoc, colimit.ι_pre] have := Functor.congr_obj (α.naturality f) d dsimp at this congr apply eqToHom_heq_id_dom) /-- This is the small version of the more general lemma `Grothendieck.final_map` below. -/ private lemma Grothendieck.final_map_small {C : Type u₁} [SmallCategory C] {F G : C ⥤ Cat.{u₁, u₁}} (α : F ⟶ G) [hα : ∀ X, Final (α.app X)] : Final (map α) := by rw [final_iff_isIso_colimit_pre] intro H let i := (colimitFiberwiseColimitIso _).symm ≪≫ HasColimit.isoOfNatIso (fiberwiseColimitMapCompEquivalence α H) ≪≫ colimitFiberwiseColimitIso _ convert Iso.isIso_hom i apply colimit.hom_ext intro X simp [i, fiberwiseColimitMapCompEquivalence] /-- The functor `Grothendieck.map α` for a natural transformation `α : F ⟶ G`, with `F G : C ⥤ Cat`, is final if for each `X : C`, the functor `α.app X` is final. -/ lemma Grothendieck.final_map {F G : C ⥤ Cat.{v₂, u₂}} (α : F ⟶ G) [hα : ∀ X, Final (α.app X)] : Final (map α) := by let sC : C ≌ AsSmall.{max u₁ u₂ v₁ v₂} C := AsSmall.equiv let F' : AsSmall C ⥤ Cat := sC.inverse ⋙ F ⋙ Cat.asSmallFunctor.{max v₁ u₁ v₂ u₂} let G' : AsSmall C ⥤ Cat := sC.inverse ⋙ G ⋙ Cat.asSmallFunctor.{max v₁ u₁ v₂ u₂} let α' : F' ⟶ G' := whiskerLeft _ (whiskerRight α _) have : ∀ X, Final (α'.app X) := fun X => inferInstanceAs (AsSmall.equiv.inverse ⋙ _ ⋙ AsSmall.equiv.functor).Final have hα' : (map α').Final := final_map_small _ dsimp only [α', ← Equivalence.symm_functor] at hα' have i := mapWhiskerLeftIsoConjPreMap sC.symm (whiskerRight α Cat.asSmallFunctor) ≪≫ isoWhiskerLeft _ (isoWhiskerRight (mapWhiskerRightAsSmallFunctor α) _) have := final_of_natIso i rwa [← final_iff_equivalence_comp, ← final_iff_comp_equivalence, ← final_iff_equivalence_comp, ← final_iff_comp_equivalence] at this end Grothendieck section Prod variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable {C' : Type u₃} [Category.{v₃} C'] variable {D' : Type u₄} [Category.{v₄} D'] variable (F : C ⥤ D) (G : C' ⥤ D') instance [F.Final] [G.Final] : (F.prod G).Final where out := fun ⟨d, d'⟩ => isConnected_of_equivalent (StructuredArrow.prodEquivalence d d' F G).symm instance [F.Initial] [G.Initial] : (F.prod G).Initial where out := fun ⟨d, d'⟩ => isConnected_of_equivalent (CostructuredArrow.prodEquivalence F G d d').symm end Prod namespace ObjectProperty /-- For the full subcategory induced by an object property `P` on `C`, to show initiality of the inclusion functor it is enough to consider arrows to objects outside of the subcategory. -/ theorem initial_ι {C : Type u₁} [Category.{v₁} C] (P : ObjectProperty C) (h : ∀ d, ¬ P d → IsConnected (CostructuredArrow P.ι d)) : P.ι.Initial := .mk <| fun d => by by_cases hd : P d · have : Nonempty (CostructuredArrow P.ι d) := ⟨⟨d, hd⟩, ⟨⟨⟩⟩, 𝟙 _⟩ refine zigzag_isConnected fun ⟨c₁, ⟨⟨⟩⟩, g₁⟩ ⟨c₂, ⟨⟨⟩⟩, g₂⟩ => Zigzag.trans (j₂ := ⟨⟨d, hd⟩, ⟨⟨⟩⟩, 𝟙 _⟩) (.of_hom ?_) (.of_inv ?_) · apply CostructuredArrow.homMk g₁ · apply CostructuredArrow.homMk g₂ · exact h d hd end ObjectProperty end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Comma.lean
import Mathlib.CategoryTheory.Comma.Arrow import Mathlib.CategoryTheory.Comma.Over.Basic 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 Functor 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] noncomputable 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. -/ noncomputable 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] noncomputable 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. -/ noncomputable 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⟩ instance preservesColimitsOfShape_fst [HasColimitsOfShape J A] [HasColimitsOfShape J B] [PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.fst L R) where preservesColimit := preservesColimit_of_preserves_colimit_cocone (coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _)) (colimit.isColimit _) instance preservesColimitsOfShape_snd [HasColimitsOfShape J A] [HasColimitsOfShape J B] [PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.snd L R) where preservesColimit := preservesColimit_of_preserves_colimit_cocone (coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _)) (colimit.isColimit _) 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⟩ instance preservesColimitsOfShape_leftFunc [HasColimitsOfShape J T] : PreservesColimitsOfShape J (Arrow.leftFunc : _ ⥤ T) := by apply Comma.preservesColimitsOfShape_fst instance preservesColimitsOfShape_rightFunc [HasColimitsOfShape J T] : PreservesColimitsOfShape J (Arrow.rightFunc : _ ⥤ T) := by apply Comma.preservesColimitsOfShape_snd 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 hasTerminal [G.Faithful] [G.Full] {Y : A} : HasTerminal (CostructuredArrow G (G.obj Y)) := CostructuredArrow.mkIdTerminal.hasTerminal 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 namespace Over instance {X : T} : HasTerminal (Over X) := CostructuredArrow.hasTerminal end Over end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Over.lean
import Mathlib.CategoryTheory.Comma.Over.Basic 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 preservesColimitsOfSize_map [HasColimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) : PreservesColimitsOfSize.{w, w'} (map f) := preservesColimits_of_reflects_of_preserves (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 preservesLimitsOfSize_map [HasLimitsOfSize.{w, w'} C] {Y : C} (f : X ⟶ Y) : PreservesLimitsOfSize.{w, w'} (map f) := preservesLimits_of_reflects_of_preserves (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
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/SmallComplete.lean
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_gt (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 [yp] · intro f ext ⟨j⟩ simp [yp] · apply Cardinal.mk_le_of_injective _ · intro f exact ⟨_, _, f⟩ · rintro f g k cases k rfl⟩ end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/MonoCoprod.lean
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 universe u namespace CategoryTheory open CategoryTheory.Category CategoryTheory.Limits 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 simp) (by simp) (fun f₁ f₂ m h₁ h₂ => BinaryCofan.IsColimit.hom_ext hc (by cat_disch) (by cat_disch)) 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₂ _ 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₂) include hc hc₁ hc₂ /-- 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₂) <;> cat_disch) 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₁) include hι include hc in 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 change 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 [HasForget C] [PreservesColimitsOfShape (Discrete WalkingPair) (forget C)] [ReflectsMonomorphisms (forget C)] : MonoCoprod C := monoCoprod_of_preservesCoprod_of_reflectsMono (forget C) end Concrete end MonoCoprod instance (A : C) [HasCoproducts.{u} C] [MonoCoprod C] : (sigmaConst.{u}.obj A).PreservesMonomorphisms where preserves {J I} ι hι := by rw [mono_iff_injective] at hι exact MonoCoprod.mono_map'_of_injective (fun (i : I) ↦ A) ι hι end Limits end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Limits/Pi.lean
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.Types.Products` we can use: ``` attribute [local instance] hasLimit_of_hasLimit_comp_eval example : hasBinaryProducts (I → Type v₁) := ⟨by infer_instance⟩ ``` -/ end CategoryTheory.pi