source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Internal/Types/CommGrp_.lean
import Mathlib.CategoryTheory.Monoidal.Internal.Types.Grp_ import Mathlib.CategoryTheory.Monoidal.CommGrp_ /-! # `CommGrp (Type u) ≌ CommGrpCat.{u}` The category of internal commutative group objects in `Type` is equivalent to the category of "native" bundled commutative groups. Moreover, this equivalence is compatible with the forgetful functors to `Type`. -/ assert_not_exists Field universe v u open CategoryTheory MonObj namespace CommGrpTypeEquivalenceCommGrp instance commGrpCommGroup (A : Type u) [GrpObj A] [IsCommMonObj A] : CommGroup A := { GrpTypeEquivalenceGrp.grpGroup A with mul_comm := fun x y => by convert congr_fun (IsCommMonObj.mul_comm A) (y, x) } /-- Converting a commutative group object in `Type u` into a group. -/ noncomputable def functor : CommGrp (Type u) ⥤ CommGrpCat.{u} where obj A := CommGrpCat.of A.X map f := CommGrpCat.ofHom (GrpTypeEquivalenceGrp.functor.map f).hom /-- Converting a group into a group object in `Type u`. -/ noncomputable def inverse : CommGrpCat.{u} ⥤ CommGrp (Type u) where obj A := { grpTypeEquivalenceGrp.inverse.obj ((forget₂ CommGrpCat GrpCat).obj A) with comm := { mul_comm := by ext ⟨x : A, y : A⟩ exact CommMonoid.mul_comm y x } } map f := GrpTypeEquivalenceGrp.inverse.map ((forget₂ CommGrpCat GrpCat).map f) @[simp] theorem inverse_obj_X {A : CommGrpCat.{u}} : (inverse.obj A).X = A := rfl @[simp] theorem inverse_obj_one {A : CommGrpCat.{u}} {x} : η[(inverse.obj A).X] x = (1 : A) := rfl @[simp] theorem inverse_obj_mul {A : CommGrpCat.{u}} {p} : μ[(inverse.obj A).X] p = (p.1 : A) * p.2 := rfl @[simp] theorem inverse_obj_inv {A : CommGrpCat.{u}} {x} : ι[(inverse.obj A).X] x = (x : A)⁻¹ := rfl end CommGrpTypeEquivalenceCommGrp /-- The category of commutative group objects in `Type u` is equivalent to the category of commutative groups. -/ noncomputable def commGrpTypeEquivalenceCommGrp : CommGrp (Type u) ≌ CommGrpCat.{u} where functor := CommGrpTypeEquivalenceCommGrp.functor inverse := CommGrpTypeEquivalenceCommGrp.inverse unitIso := Iso.refl _ counitIso := NatIso.ofComponents (fun A => MulEquiv.toCommGrpIso { Equiv.refl _ with map_mul' := fun _ _ => rfl }) (by cat_disch) /-- The equivalences `Grp (Type u) ≌ GrpCat.{u}` and `CommGrp (Type u) ≌ CommGrpCat.{u}` are naturally compatible with the forgetful functors to `GrpCat` and `Grp (Type u)`. -/ noncomputable def commGrpTypeEquivalenceCommGrpForgetGrp : CommGrpTypeEquivalenceCommGrp.functor ⋙ forget₂ CommGrpCat GrpCat ≅ CommGrp.forget₂Grp (Type u) ⋙ GrpTypeEquivalenceGrp.functor := Iso.refl _ /-- The equivalences `CommMon (Type u) ≌ CommMonCat.{u}` and `CommGrp (Type u) ≌ CommGrpCat.{u}` are naturally compatible with the forgetful functors to `GrpCat` and `Grp (Type u)`. -/ noncomputable def commGrpTypeEquivalenceCommGrpForgetCommMon : CommGrpTypeEquivalenceCommGrp.functor ⋙ forget₂ CommGrpCat CommMonCat ≅ CommGrp.forget₂CommMon (Type u) ⋙ CommMonTypeEquivalenceCommMon.functor := Iso.refl _
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Internal/Types/Basic.lean
import Mathlib.Algebra.Category.MonCat.Basic import Mathlib.CategoryTheory.Monoidal.CommMon_ import Mathlib.CategoryTheory.Monoidal.Types.Basic /-! # `Mon (Type u) ≌ MonCat.{u}` The category of internal monoid objects in `Type` is equivalent to the category of "native" bundled monoids. Moreover, this equivalence is compatible with the forgetful functors to `Type`. -/ assert_not_exists MonoidWithZero universe v u open CategoryTheory MonObj namespace MonTypeEquivalenceMon instance monMonoid (A : Type u) [MonObj A] : Monoid A where one := η[A] PUnit.unit mul x y := μ[A] (x, y) one_mul x := by convert congr_fun (one_mul A) (PUnit.unit, x) mul_one x := by convert congr_fun (mul_one A) (x, PUnit.unit) mul_assoc x y z := by convert congr_fun (mul_assoc A) ((x, y), z) /-- Converting a monoid object in `Type` to a bundled monoid. -/ noncomputable def functor : Mon (Type u) ⥤ MonCat.{u} where obj A := MonCat.of A.X map f := MonCat.ofHom { toFun := f.hom map_one' := congr_fun (IsMonHom.one_hom f.hom) PUnit.unit map_mul' x y := congr_fun (IsMonHom.mul_hom f.hom) (x, y) } /-- Converting a bundled monoid to a monoid object in `Type`. -/ noncomputable def inverse : MonCat.{u} ⥤ Mon (Type u) where obj A := { X := A mon := { one := fun _ => 1 mul := fun p => p.1 * p.2 one_mul := by ext ⟨_, _⟩; simp mul_one := by ext ⟨_, _⟩; simp mul_assoc := by ext ⟨⟨x, y⟩, z⟩; simp [_root_.mul_assoc] } } map f := .mk' f end MonTypeEquivalenceMon open MonTypeEquivalenceMon /-- The category of internal monoid objects in `Type` is equivalent to the category of "native" bundled monoids. -/ noncomputable def monTypeEquivalenceMon : Mon (Type u) ≌ MonCat.{u} where functor := functor inverse := inverse unitIso := Iso.refl _ counitIso := NatIso.ofComponents (fun A => MulEquiv.toMonCatIso { Equiv.refl _ with map_mul' := fun _ _ => rfl }) (by cat_disch) /-- The equivalence `Mon (Type u) ≌ MonCat.{u}` is naturally compatible with the forgetful functors to `Type u`. -/ noncomputable def monTypeEquivalenceMonForget : MonTypeEquivalenceMon.functor ⋙ forget MonCat ≅ Mon.forget (Type u) := NatIso.ofComponents (fun _ => Iso.refl _) (by cat_disch) noncomputable instance monTypeInhabited : Inhabited (Mon (Type u)) := ⟨MonTypeEquivalenceMon.inverse.obj (MonCat.of PUnit)⟩ namespace CommMonTypeEquivalenceCommMon instance commMonCommMonoid (A : Type u) [MonObj A] [IsCommMonObj A] : CommMonoid A := { MonTypeEquivalenceMon.monMonoid A with mul_comm := fun x y => by convert congr_fun (IsCommMonObj.mul_comm A) (y, x) } /-- Converting a commutative monoid object in `Type` to a bundled commutative monoid. -/ noncomputable def functor : CommMon (Type u) ⥤ CommMonCat.{u} where obj A := CommMonCat.of A.X map f := CommMonCat.ofHom (MonTypeEquivalenceMon.functor.map f).hom /-- Converting a bundled commutative monoid to a commutative monoid object in `Type`. -/ noncomputable def inverse : CommMonCat.{u} ⥤ CommMon (Type u) where obj A := { MonTypeEquivalenceMon.inverse.obj ((forget₂ CommMonCat MonCat).obj A) with comm := { mul_comm := by ext ⟨x : A, y : A⟩ exact CommMonoid.mul_comm y x } } map f := MonTypeEquivalenceMon.inverse.map ((forget₂ CommMonCat MonCat).map f) end CommMonTypeEquivalenceCommMon open CommMonTypeEquivalenceCommMon /-- The category of internal commutative monoid objects in `Type` is equivalent to the category of "native" bundled commutative monoids. -/ noncomputable def commMonTypeEquivalenceCommMon : CommMon (Type u) ≌ CommMonCat.{u} where functor := functor inverse := inverse unitIso := Iso.refl _ counitIso := NatIso.ofComponents (fun A => MulEquiv.toCommMonCatIso { Equiv.refl _ with map_mul' := fun _ _ => rfl }) (by cat_disch) /-- The equivalences `Mon (Type u) ≌ MonCat.{u}` and `CommMon (Type u) ≌ CommMonCat.{u}` are naturally compatible with the forgetful functors to `MonCat` and `Mon (Type u)`. -/ noncomputable def commMonTypeEquivalenceCommMonForget : CommMonTypeEquivalenceCommMon.functor ⋙ forget₂ CommMonCat MonCat ≅ CommMon.forget₂Mon (Type u) ⋙ MonTypeEquivalenceMon.functor := Iso.refl _
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Limits/Preserves.lean
import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic /-! # Miscellany about preservations of (co)limits in monoidal categories This file records some `PreservesColimits` instance on tensors products on monoidal categories. -/ namespace CategoryTheory.MonoidalCategory.Limits open _root_.CategoryTheory.Limits variable {C : Type*} [Category C] [MonoidalCategory C] {J : Type*} [Category J] (F : J ⥤ C) section Colimits /-- When `C` is braided and `tensorLeft c` preserves a colimit, then so does `tensorRight k`. -/ instance preservesColimit_of_braided_and_preservesColimit_tensor_left [BraidedCategory C] (c : C) [PreservesColimit F (tensorLeft c)] : PreservesColimit F (tensorRight c) := preservesColimit_of_natIso F (BraidedCategory.tensorLeftIsoTensorRight c) /-- When `C` is braided and `tensorRight c` preserves a colimit, then so does `tensorLeft k`. We are not making this an instance to avoid an instance loop with `preservesColimit_of_braided_and_preservesColimit_tensor_left`. -/ lemma preservesColimit_of_braided_and_preservesColimit_tensor_right [BraidedCategory C] (c : C) [PreservesColimit F (tensorRight c)] : PreservesColimit F (tensorLeft c) := preservesColimit_of_natIso F (BraidedCategory.tensorLeftIsoTensorRight c).symm lemma preservesCoLimit_curriedTensor [h : ∀ c : C, PreservesColimit F (tensorRight c)] : PreservesColimit F (curriedTensor C) := preservesColimit_of_evaluation _ _ (fun c ↦ inferInstanceAs (PreservesColimit F (tensorRight c))) end Colimits section Limits /-- When `C` is braided and `tensorLeft c` preserves a limit, then so does `tensorRight k`. -/ instance preservesLimit_of_braided_and_preservesLimit_tensor_left [BraidedCategory C] (c : C) [PreservesLimit F (tensorLeft c)] : PreservesLimit F (tensorRight c) := preservesLimit_of_natIso F (BraidedCategory.tensorLeftIsoTensorRight c) /-- When `C` is braided and `tensorRight c` preserves a limit, then so does `tensorLeft k`. We are not making this an instance to avoid an instance loop with `preservesLimit_of_braided_and_preservesLimit_tensor_left`. -/ lemma preservesLimit_of_braided_and_preservesLimit_tensor_right [BraidedCategory C] (c : C) [PreservesLimit F (tensorRight c)] : PreservesLimit F (tensorLeft c) := preservesLimit_of_natIso F (BraidedCategory.tensorLeftIsoTensorRight c).symm lemma preservesLimit_curriedTensor [h : ∀ c : C, PreservesLimit F (tensorRight c)] : PreservesLimit F (curriedTensor C) := preservesLimit_of_evaluation _ _ <| fun c ↦ inferInstanceAs (PreservesLimit F (tensorRight c)) end Limits end CategoryTheory.MonoidalCategory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Limits/Basic.lean
import Mathlib.CategoryTheory.Monoidal.FunctorCategory import Mathlib.CategoryTheory.Limits.HasLimits /-! # `lim : (J ⥤ C) ⥤ C` is lax monoidal when `C` is a monoidal category. When `C` is a monoidal category, the limit functor `lim : (J ⥤ C) ⥤ C` is lax monoidal, i.e. there are morphisms * `(𝟙_ C) → limit (𝟙_ (J ⥤ C))` * `limit F ⊗ limit G ⟶ limit (F ⊗ G)` satisfying the laws of a lax monoidal functor. ## TODO Now that we have oplax monoidal functors, assemble `Limits.colim` into an oplax monoidal functor. -/ namespace CategoryTheory.Limits open MonoidalCategory universe v u w noncomputable section variable {J : Type w} [SmallCategory J] {C : Type u} [Category.{v} C] [HasLimitsOfShape J C] [MonoidalCategory.{v} C] open Functor.LaxMonoidal instance : (lim (J := J) (C := C)).LaxMonoidal := Functor.LaxMonoidal.ofTensorHom (ε := limit.lift _ { pt := _ π := { app := fun _ => 𝟙 _ } }) (μ := fun F G ↦ limit.lift (F ⊗ G) { pt := limit F ⊗ limit G π := { app := fun j => limit.π F j ⊗ₘ limit.π G j naturality := fun j j' f => by dsimp simp only [Category.id_comp, tensorHom_comp_tensorHom, limit.w] } }) (μ_natural := fun f g ↦ limit.hom_ext (fun j ↦ by dsimp simp only [limit.lift_π, Cones.postcompose_obj_π, Monoidal.tensorHom_app, limit.lift_map, NatTrans.comp_app, Category.assoc, tensorHom_comp_tensorHom, limMap_π])) (associativity := fun F G H ↦ limit.hom_ext (fun j ↦ by dsimp simp only [tensorHom_id, limit.lift_map, Category.assoc, limit.lift_π, id_tensorHom] dsimp conv_lhs => rw [tensorHom_def, Category.assoc, ← comp_whiskerRight_assoc, limit.lift_π, tensor_whiskerLeft, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, ← associator_naturality_right, ← tensorHom_def_assoc] dsimp conv_rhs => rw [tensorHom_def, ← whisker_exchange, ← whiskerLeft_comp_assoc, limit.lift_π, whisker_exchange, ← associator_naturality_left_assoc] dsimp only conv_rhs => rw [tensorHom_def, whiskerLeft_comp, ← associator_naturality_middle_assoc, ← associator_naturality_right, ← comp_whiskerRight_assoc, ← tensorHom_def, ← tensorHom_def_assoc])) (left_unitality := fun F ↦ limit.hom_ext (fun j ↦ by dsimp simp only [tensorHom_id, limit.lift_map, Category.assoc, limit.lift_π] dsimp simp only [tensorHom_def, id_whiskerLeft, Category.assoc, Iso.inv_hom_id, Category.comp_id, ← comp_whiskerRight_assoc] erw [limit.lift_π] rw [id_whiskerRight, Category.id_comp])) (right_unitality := fun F ↦ limit.hom_ext (fun j ↦ by dsimp simp only [id_tensorHom, limit.lift_map, Category.assoc, limit.lift_π] dsimp simp only [tensorHom_def, ← whisker_exchange, whiskerRight_id, Category.assoc, Iso.inv_hom_id, Category.comp_id, ← whiskerLeft_comp_assoc] erw [limit.lift_π] rw [whiskerLeft_id, Category.id_comp])) @[reassoc (attr := simp)] lemma lim_ε_π (j : J) : ε (lim (J := J) (C := C)) ≫ limit.π _ j = 𝟙 _ := limit.lift_π _ _ @[reassoc (attr := simp)] lemma lim_μ_π (F G : J ⥤ C) (j : J) : μ lim F G ≫ limit.π _ j = limit.π F j ⊗ₘ limit.π G j := limit.lift_π _ _ end end CategoryTheory.Limits
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Action/LinearFunctor.lean
import Mathlib.CategoryTheory.Monoidal.Action.Basic /-! # Functors that are linear with respect to an action Given a monoidal category `C` acting on the left or on the right on categories `D` and `D'`, we introduce the following typeclasses on functors `F : D ⥤ D'` to express compatibility of `F` with the action of `C`: * `F.LaxLeftLinear C` bundles the "lineator" as a morphism `μₗ : c ⊙ₗ F.obj d ⟶ F.obj (c ⊙ₗ d)`. * `F.LaxRightLinear C` bundles the "lineator" as a morphism `μᵣ : F.obj d ⊙ᵣ c ⟶ F.obj (d ⊙ᵣ c)`. * `F.OplaxLeftLinear C` bundles the "lineator" as a morphism `δₗ : F.obj (c ⊙ₗ d) ⟶ c ⊙ₗ F.obj d `. * `F.OplaxRightLinear C` bundles the "lineator" as a morphism `δᵣ : F.obj (d ⊙ᵣ d) ⟶ F.obj d ⊙ᵣ c`. * `F.LeftLinear C` expresses that `F` has both a `LaxLeftLinear C` and an `F.OplaxLeftLinear C` structure, and that they are compatible, i.e `δₗ F` is a left and right inverse to `μₗ`. * `F.RightLinear C` expresses that `F` has both a `LaxRightLinear C` and an `F.OplaxRightLinear C` structure, and that they are compatible, i.e `δᵣ F` is a left and right inverse to `μᵣ`. -/ namespace CategoryTheory.Functor variable {D D' : Type*} [Category D] [Category D'] open MonoidalCategory section leftAction open MonoidalLeftAction /-- `F.LaxLinear C` equips `F : D ⥤ D'` with a family of morphisms `μₗ F : ∀ (c : C) (d : D), c ⊙ₗ F.obj d ⟶ F.obj (c ⊙ₗ d)` that is natural in each variable and coherent with respect to left actions of `C` on `D` and `D'`. -/ class LaxLeftLinear (F : D ⥤ D') (C : Type*) [Category C] [MonoidalCategory C] [MonoidalLeftAction C D] [MonoidalLeftAction C D'] where /-- The "μₗ" morphism. -/ μₗ (F) (c : C) (d : D) : c ⊙ₗ F.obj d ⟶ F.obj (c ⊙ₗ d) μₗ_naturality_left (F) {c c' : C} (f : c ⟶ c') (d : D) : f ⊵ₗ F.obj d ≫ μₗ c' d = μₗ c d ≫ F.map (f ⊵ₗ d) := by cat_disch μₗ_naturality_right (F) (c : C) {d d' : D} (f : d ⟶ d') : c ⊴ₗ F.map f ≫ μₗ c d' = μₗ c d ≫ F.map (c ⊴ₗ f) := by cat_disch μₗ_associativity (F) (c c' : C) (d : D) : μₗ (c ⊗ c') d ≫ F.map (αₗ _ _ _).hom = (αₗ c c' (F.obj d)).hom ≫ c ⊴ₗ μₗ c' d ≫ μₗ c (c' ⊙ₗ d) := by cat_disch μₗ_unitality (F) (d : D) : (λₗ (F.obj d)).hom = μₗ (𝟙_ C) d ≫ F.map (λₗ d).hom := by cat_disch namespace LaxLeftLinear -- These are [reassoc (attr := simp)] on the basis that analog lemmas for -- lax monoidal functors are also [reassoc (attr := simp)]. attribute [reassoc (attr := simp)] μₗ_naturality_right attribute [reassoc (attr := simp)] μₗ_naturality_left attribute [reassoc (attr := simp)] μₗ_associativity attribute [simp, reassoc] μₗ_unitality variable (F : D ⥤ D') {C : Type*} [Category C] [MonoidalCategory C] [MonoidalLeftAction C D] [MonoidalLeftAction C D'] [F.LaxLeftLinear C] @[reassoc (attr := simp)] lemma μₗ_associativity_inv (c c' : C) (d : D) : c ⊴ₗ μₗ F c' d ≫ μₗ F c (c' ⊙ₗ d) ≫ F.map (αₗ _ _ _).inv = (αₗ c c' (F.obj d)).inv ≫ μₗ F (c ⊗ c') d := by simpa [-μₗ_associativity, -μₗ_associativity_assoc] using (αₗ _ _ _).inv ≫= (μₗ_associativity F c c' d).symm =≫ F.map (αₗ _ _ _).inv @[reassoc (attr := simp)] lemma μₗ_unitality_inv (d : D) : (λₗ (F.obj d)).inv ≫ μₗ F (𝟙_ C) d = F.map (λₗ d).inv := by simpa [-μₗ_unitality] using (λₗ[C] (F.obj d)).inv ≫= (μₗ_unitality F d).symm =≫ F.map (λₗ[C] d).inv end LaxLeftLinear /-- `F.OplaxLinear C` equips `F : D ⥤ D'` with a family of morphisms `δₗ F : ∀ (c : C) (d : D), c ⊙ₗ F.obj d ⟶ F.obj (c ⊙ₗ d)` that is natural in each variable and coherent with respect to left actions of `C` on `D` and `D'`. -/ class OplaxLeftLinear (F : D ⥤ D') (C : Type*) [Category C] [MonoidalCategory C] [MonoidalLeftAction C D] [MonoidalLeftAction C D'] where /-- The oplax lineator morphism. -/ δₗ (F) (c : C) (d : D) : F.obj (c ⊙ₗ d) ⟶ c ⊙ₗ F.obj d δₗ_naturality_left (F) {c c' : C} (f : c ⟶ c') (d : D) : F.map (f ⊵ₗ d) ≫ δₗ c' d = δₗ c d ≫ f ⊵ₗ F.obj d := by cat_disch δₗ_naturality_right (F) (c : C) {d d' : D} (f : d ⟶ d') : F.map (c ⊴ₗ f) ≫ δₗ c d' = δₗ c d ≫ c ⊴ₗ F.map f := by cat_disch δₗ_associativity (F) (c c' : C) (d : D) : δₗ (c ⊗ c') d ≫ (αₗ _ _ _).hom = F.map (αₗ _ _ _).hom ≫ δₗ c (c' ⊙ₗ d) ≫ c ⊴ₗ δₗ c' d := by cat_disch δₗ_unitality_inv (F) (d : D) : (λₗ (F.obj d)).inv = F.map (λₗ d).inv ≫ δₗ (𝟙_ C) d := by cat_disch namespace OplaxLeftLinear -- These are [reassoc (attr := simp)] on the basis that analog lemmas for -- oplax monoidal functors are also [reassoc (attr := simp)]. attribute [reassoc (attr := simp)] δₗ_naturality_right attribute [reassoc (attr := simp)] δₗ_naturality_left attribute [reassoc (attr := simp)] δₗ_associativity attribute [simp, reassoc] δₗ_unitality_inv variable (F : D ⥤ D') {C : Type*} [Category C] [MonoidalCategory C] [MonoidalLeftAction C D] [MonoidalLeftAction C D'] [F.OplaxLeftLinear C] @[reassoc (attr := simp)] lemma δₗ_associativity_inv (c c' : C) (d : D) : δₗ F c (c' ⊙ₗ d) ≫ c ⊴ₗ δₗ F c' d ≫ (αₗ _ _ _).inv = F.map (αₗ _ _ _).inv ≫ δₗ F (c ⊗ c' : C) d := by simpa [-δₗ_associativity, -δₗ_associativity_assoc] using F.map (αₗ _ _ _).inv ≫= (δₗ_associativity F c c' d).symm =≫ (αₗ _ _ _).inv @[reassoc (attr := simp)] lemma δₗ_unitality_hom (d : D) : δₗ F (𝟙_ C) d ≫ (λₗ (F.obj d)).hom = F.map (λₗ d).hom := by simpa [-δₗ_unitality_inv] using F.map (λₗ[C] d).hom ≫= (δₗ_unitality_inv F d).symm =≫ (λₗ[C] (F.obj d)).hom end OplaxLeftLinear /-- `F.LeftLinear C` asserts that `F` is both lax and oplax left-linear, in a compatible way, i.e that `μₗ` is inverse to `δₗ`. -/ class LeftLinear (F : D ⥤ D') (C : Type*) [Category C] [MonoidalCategory C] [MonoidalLeftAction C D] [MonoidalLeftAction C D'] extends F.LaxLeftLinear C, F.OplaxLeftLinear C where μₗ_comp_δₗ (F) (c : C) (d : D) : LaxLeftLinear.μₗ F c d ≫ OplaxLeftLinear.δₗ F c d = 𝟙 _ δₗ_comp_μₗ (F) (c : C) (d : D) : OplaxLeftLinear.δₗ F c d ≫ LaxLeftLinear.μₗ F c d = 𝟙 _ namespace LeftLinear open LaxLeftLinear OplaxLeftLinear variable (F : D ⥤ D') {C : Type*} [Category C] [MonoidalCategory C] [MonoidalLeftAction C D] [MonoidalLeftAction C D'] [F.LeftLinear C] attribute [reassoc (attr := simp)] μₗ_comp_δₗ attribute [reassoc (attr := simp)] δₗ_comp_μₗ /-- A shorthand to bundle the μₗ as an isomorphism -/ abbrev μₗIso (c : C) (d : D) : c ⊙ₗ F.obj d ≅ F.obj (c ⊙ₗ d) where hom := LaxLeftLinear.μₗ F c d inv := OplaxLeftLinear.δₗ F c d variable (c : C) (d : D) instance : IsIso (μₗ F c d) := Iso.isIso_hom (μₗIso F c d) instance : IsIso (δₗ F c d) := Iso.isIso_inv (μₗIso F c d) @[simp] lemma inv_μₗ : CategoryTheory.inv (μₗ F c d) = δₗ F c d := Eq.symm <| IsIso.eq_inv_of_hom_inv_id <| μₗ_comp_δₗ F c d @[simp] lemma inv_δₗ : CategoryTheory.inv (δₗ F c d) = μₗ F c d := Eq.symm <| IsIso.eq_inv_of_hom_inv_id <| δₗ_comp_μₗ F c d end LeftLinear end leftAction section rightAction open MonoidalRightAction /-- `F.LaxLinear C` equips `F : D ⥤ D'` with a family of morphisms `μₗ F : ∀ (c : C) (d : D), c ⊙ₗ F.obj d ⟶ F.obj (c ⊙ₗ d)` that is natural in each variable and coherent with respect to left actions of `C` on `D` and `D'`. -/ class LaxRightLinear (F : D ⥤ D') (C : Type*) [Category C] [MonoidalCategory C] [MonoidalRightAction C D] [MonoidalRightAction C D'] where /-- The "μᵣ" morphism. -/ μᵣ (F) (d : D) (c : C) : F.obj d ⊙ᵣ c ⟶ F.obj (d ⊙ᵣ c) μᵣ_naturality_right (F) (d : D) {c c' : C} (f : c ⟶ c') : F.obj d ⊴ᵣ f ≫ μᵣ d c' = μᵣ d c ≫ F.map (d ⊴ᵣ f) := by cat_disch μᵣ_naturality_left (F) {d d' : D} (f : d ⟶ d') (c : C) : F.map f ⊵ᵣ c ≫ μᵣ d' c = μᵣ d c ≫ F.map (f ⊵ᵣ c) := by cat_disch μᵣ_associativity (F) (d : D) (c c' : C) : μᵣ d (c ⊗ c') ≫ F.map (αᵣ _ _ _).hom = (αᵣ (F.obj d) c c').hom ≫ (μᵣ d c) ⊵ᵣ c' ≫ μᵣ (d ⊙ᵣ c) c' := by cat_disch μᵣ_unitality (F) (d : D) : (ρᵣ (F.obj d)).hom = μᵣ d (𝟙_ C) ≫ F.map (ρᵣ d).hom := by cat_disch namespace LaxRightLinear -- These are [reassoc (attr := simp)] on the basis that analog lemmas for -- lax monoidal functors are also [reassoc (attr := simp)]. attribute [reassoc (attr := simp)] μᵣ_naturality_right attribute [reassoc (attr := simp)] μᵣ_naturality_left attribute [reassoc (attr := simp)] μᵣ_associativity attribute [simp, reassoc] μᵣ_unitality variable (F : D ⥤ D') {C : Type*} [Category C] [MonoidalCategory C] [MonoidalRightAction C D] [MonoidalRightAction C D'] [F.LaxRightLinear C] @[reassoc (attr := simp)] lemma μᵣ_associativity_inv (d : D) (c c' : C) : μᵣ F d c ⊵ᵣ c' ≫ μᵣ F (d ⊙ᵣ c) c' ≫ F.map (αᵣ _ _ _).inv = (αᵣ (F.obj d) c c').inv ≫ μᵣ F d (c ⊗ c') := by simpa [-μᵣ_associativity, -μᵣ_associativity_assoc] using (αᵣ _ _ _).inv ≫= (μᵣ_associativity F d c c').symm =≫ F.map (αᵣ _ _ _).inv @[reassoc (attr := simp)] lemma μᵣ_unitality_inv (d : D) : (ρᵣ (F.obj d)).inv ≫ μᵣ F d (𝟙_ C) = F.map (ρᵣ d).inv := by simpa [-μᵣ_unitality] using (ρᵣ[C] (F.obj d)).inv ≫= (μᵣ_unitality F d).symm =≫ F.map (ρᵣ[C] d).inv end LaxRightLinear /-- `F.OplaxLinear C` equips `F : D ⥤ D'` with a family of morphisms `δₗ F : ∀ (c : C) (d : D), c ⊙ₗ F.obj d ⟶ F.obj (c ⊙ₗ d)` that is natural in each variable and coherent with respect to left actions of `C` on `D` and `D'`. -/ class OplaxRightLinear (F : D ⥤ D') (C : Type*) [Category C] [MonoidalCategory C] [MonoidalRightAction C D] [MonoidalRightAction C D'] where /-- The oplax lineator morphism. -/ δᵣ (F) (d : D) (c : C) : F.obj (d ⊙ᵣ c) ⟶ (F.obj d) ⊙ᵣ c δᵣ_naturality_right (F) (d : D) {c c' : C} (f : c ⟶ c') : F.map (d ⊴ᵣ f) ≫ δᵣ d c' = δᵣ d c ≫ F.obj d ⊴ᵣ f := by cat_disch δᵣ_naturality_left (F) {d d' : D} (f : d ⟶ d') (c : C) : F.map (f ⊵ᵣ c) ≫ δᵣ d' c = δᵣ d c ≫ F.map f ⊵ᵣ c := by cat_disch δᵣ_associativity (F) (d : D) (c c' : C) : δᵣ d (c ⊗ c') ≫ (αᵣ _ _ _).hom = F.map (αᵣ _ _ _).hom ≫ δᵣ (d ⊙ᵣ c) c' ≫ δᵣ d c ⊵ᵣ c' := by cat_disch δᵣ_unitality_inv (F) (d : D) : (ρᵣ (F.obj d)).inv = F.map (ρᵣ d).inv ≫ δᵣ d (𝟙_ C) := by cat_disch namespace OplaxRightLinear -- These are [reassoc (attr := simp)] on the basis that analog lemmas for -- oplax monoidal functors are also [reassoc (attr := simp)]. attribute [reassoc (attr := simp)] δᵣ_naturality_right attribute [reassoc (attr := simp)] δᵣ_naturality_left attribute [reassoc (attr := simp)] δᵣ_associativity attribute [simp, reassoc] δᵣ_unitality_inv variable (F : D ⥤ D') {C : Type*} [Category C] [MonoidalCategory C] [MonoidalRightAction C D] [MonoidalRightAction C D'] [F.OplaxRightLinear C] @[reassoc (attr := simp)] lemma δᵣ_associativity_inv (d : D) (c c' : C) : δᵣ F (d ⊙ᵣ c) c' ≫ δᵣ F d c ⊵ᵣ c' ≫ (αᵣ _ _ _).inv = F.map (αᵣ _ _ _).inv ≫ δᵣ F d (c ⊗ c' : C) := by simpa [-δᵣ_associativity, -δᵣ_associativity_assoc] using F.map (αᵣ _ _ _).inv ≫= (δᵣ_associativity F d c c').symm =≫ (αᵣ _ _ _).inv @[reassoc (attr := simp)] lemma δᵣ_unitality_hom (d : D) : δᵣ F d (𝟙_ C) ≫ (ρᵣ (F.obj d)).hom = F.map (ρᵣ d).hom := by simpa [-δᵣ_unitality_inv] using F.map (ρᵣ[C] d).hom ≫= (δᵣ_unitality_inv F d).symm =≫ (ρᵣ[C] (F.obj d)).hom end OplaxRightLinear /-- `F.RightLinear C` asserts that `F` is both lax and oplax left-linear, in a compatible way, i.e that `μᵣ` is inverse to `δᵣ`. -/ class RightLinear (F : D ⥤ D') (C : Type*) [Category C] [MonoidalCategory C] [MonoidalRightAction C D] [MonoidalRightAction C D'] extends F.LaxRightLinear C, F.OplaxRightLinear C where μᵣ_comp_δᵣ (F) (d : D) (c : C) : LaxRightLinear.μᵣ F d c ≫ OplaxRightLinear.δᵣ F d c = 𝟙 _ δᵣ_comp_μᵣ (F) (d : D) (c : C) : OplaxRightLinear.δᵣ F d c ≫ LaxRightLinear.μᵣ F d c = 𝟙 _ namespace RightLinear open LaxRightLinear OplaxRightLinear variable (F : D ⥤ D') {C : Type*} [Category C] [MonoidalCategory C] [MonoidalRightAction C D] [MonoidalRightAction C D'] [F.RightLinear C] attribute [reassoc (attr := simp)] μᵣ_comp_δᵣ attribute [reassoc (attr := simp)] δᵣ_comp_μᵣ /-- A shorthand to bundle the μᵣ as an isomorphism -/ abbrev μᵣIso (d : D) (c : C) : F.obj d ⊙ᵣ c ≅ F.obj (d ⊙ᵣ c) where hom := LaxRightLinear.μᵣ F d c inv := OplaxRightLinear.δᵣ F d c variable (c : C) (d : D) instance : IsIso (μᵣ F d c) := Iso.isIso_hom (μᵣIso F d c) instance : IsIso (δᵣ F d c) := Iso.isIso_inv (μᵣIso F d c) @[simp] lemma inv_μᵣ : CategoryTheory.inv (μᵣ F d c) = δᵣ F d c := Eq.symm <| IsIso.eq_inv_of_hom_inv_id <| μᵣ_comp_δᵣ F d c @[simp] lemma inv_δᵣ : CategoryTheory.inv (δᵣ F d c) = μᵣ F d c := Eq.symm <| IsIso.eq_inv_of_hom_inv_id <| δᵣ_comp_μᵣ F d c end RightLinear end rightAction end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Action/Basic.lean
import Mathlib.CategoryTheory.Monoidal.Category import Mathlib.CategoryTheory.Functor.Trifunctor /-! # Actions from a monoidal category on a category Given a monoidal category `C`, and a category `D`, we define a left action of `C` on `D` as the data of an object `c ⊙ₗ d` of `D` for every `c : C` and `d : D`, as well as the data required to turn `- ⊙ₗ -` into a bifunctor, along with structure natural isomorphisms `(- ⊗ -) ⊙ₗ - ≅ - ⊙ₗ - ⊙ₗ -` and `𝟙_ C ⊙ₗ - ≅ -`, subject to coherence conditions. We also define right actions, for these, the notation for the action of `c` on `d` is `d ⊙ᵣ c`, and the structure isomorphisms are of the form `- ⊙ᵣ (- ⊗ -) ≅ (- ⊙ᵣ -) ⊙ᵣ -` and `- ⊙ₗ 𝟙_ C ≅ -`. ## References * [Janelidze, G, and Kelly, G.M., *A note on actions of a monoidal category*][JanelidzeKelly2001] ## TODOs/Projects * Equivalence between actions of `C` on `D` and pseudofunctors from the classifying bicategory of `C` to `Cat`. * Left/Right Modules in `D` over a monoid object in `C`. Equivalence with `Mod_` when `D` is `C`. Bimodules objects. * Given a monad `M` on `C`, equivalence between `Algebra M`, and modules in `C` on `M.toMon : Mon (C ⥤ C)`. * Canonical left action of `Type u` on `u`-small cocomplete categories via the copower. -/ namespace CategoryTheory.MonoidalCategory variable (C D : Type*) variable [Category C] [Category D] /-- A class that carries the non-Prop data required to define a left action of a monoidal category `C` on a category `D`, to set up notations. -/ class MonoidalLeftActionStruct [MonoidalCategoryStruct C] where /-- The left action on objects. This is denoted `c ⊙ₗ d`. -/ actionObj : C → D → D /-- The left action of a map `f : c ⟶ c'` in `C` on an object `d` in `D`. If we are to consider the action as a functor `Α : C ⥤ D ⥤ D`, this is `(Α.map f).app d`. This is denoted `f ⊵ₗ d`. -/ actionHomLeft {c c' : C} (f : c ⟶ c') (d : D) : actionObj c d ⟶ actionObj c' d /-- The action of an object `c : C` on a map `f : d ⟶ d'` in `D`. If we are to consider the action as a functor `Α : C ⥤ D ⥤ D`, this is `(Α.obj c).map f`. This is denoted `c ⊴ₗ f`. -/ actionHomRight (c : C) {d d' : D} (f : d ⟶ d') : actionObj c d ⟶ actionObj c d' /-- The action of a pair of maps `f : c ⟶ c'` and `d ⟶ d'`. By default, this is defined in terms of `actionHomLeft` and `actionHomRight`. -/ actionHom {c c' : C} {d d' : D} (f : c ⟶ c') (g : d ⟶ d') : actionObj c d ⟶ actionObj c' d' := actionHomLeft f d ≫ actionHomRight c' g /-- The structural isomorphism `(c ⊗ c') ⊙ₗ d ≅ c ⊙ₗ (c' ⊙ₗ d)`. -/ actionAssocIso (c c' : C) (d : D) : actionObj (c ⊗ c') d ≅ actionObj c (actionObj c' d) /-- The structural isomorphism between `𝟙_ C ⊙ₗ d` and `d`. -/ actionUnitIso (d : D) : actionObj (𝟙_ C) d ≅ d namespace MonoidalLeftAction export MonoidalLeftActionStruct (actionObj actionHomLeft actionHomRight actionHom actionAssocIso actionUnitIso) -- infix priorities are aligned with the ones from `MonoidalCategoryStruct`. /-- Notation for `actionObj`, the action of `C` on `D`. -/ scoped infixr:70 " ⊙ₗ " => MonoidalLeftActionStruct.actionObj /-- Notation for `actionHomLeft`, the action of `C` on morphisms in `D`. -/ scoped infixr:81 " ⊵ₗ " => MonoidalLeftActionStruct.actionHomLeft /-- Notation for `actionHomRight`, the action of morphism in `C` on `D`. -/ scoped infixr:81 " ⊴ₗ " => MonoidalLeftActionStruct.actionHomRight /-- Notation for `actionHom`, the bifunctorial action of morphisms in `C` and `D` on `- ⊙ₗ -`. -/ scoped infixr:70 " ⊙ₗₘ " => MonoidalLeftActionStruct.actionHom /-- Notation for `actionAssocIso`, the structural isomorphism `- ⊗ - ⊙ₗ - ≅ - ⊙ₗ - ⊙ₗ -`. -/ scoped notation "αₗ " => MonoidalLeftActionStruct.actionAssocIso /-- Notation for `actionUnitIso`, the structural isomorphism `𝟙_ C ⊙ₗ - ≅ -`. -/ scoped notation "λₗ " => MonoidalLeftActionStruct.actionUnitIso /-- Notation for `actionUnitIso`, the structural isomorphism `𝟙_ C ⊙ₗ - ≅ -`, allowing one to specify the acting category. -/ scoped notation "λₗ["J"]" => MonoidalLeftActionStruct.actionUnitIso (C := J) end MonoidalLeftAction open scoped MonoidalLeftAction in /-- A `MonoidalLeftAction C D` is the data of: - For every object `c : C` and `d : D`, an object `c ⊙ₗ d` of `D`. - For every morphism `f : (c : C) ⟶ c'` and every `d : D`, a morphism `f ⊵ₗ d : c ⊙ₗ d ⟶ c' ⊙ₗ d`. - For every morphism `f : (d : D) ⟶ d'` and every `c : C`, a morphism `c ⊴ₗ f : c ⊙ₗ d ⟶ c ⊙ₗ d'`. - For every pair of morphisms `f : (c : C) ⟶ c'` and `f : (d : D) ⟶ d'`, a morphism `f ⊙ₗ f' : c ⊙ₗ d ⟶ c' ⊙ₗ d'`. - A structure isomorphism `αₗ c c' d : c ⊗ c' ⊙ₗ d ≅ c ⊙ₗ c' ⊙ₗ d`. - A structure isomorphism `λₗ d : (𝟙_ C) ⊙ₗ d ≅ d`. Furthermore, we require identities that turn `- ⊙ₗ -` into a bifunctor, ensure naturality of `αₗ` and `λₗ`, and ensure compatibilities with the associator and unitor isomorphisms in `C`. -/ class MonoidalLeftAction [MonoidalCategory C] extends MonoidalLeftActionStruct C D where actionHom_def {c c' : C} {d d' : D} (f : c ⟶ c') (g : d ⟶ d') : f ⊙ₗₘ g = f ⊵ₗ d ≫ c' ⊴ₗ g := by cat_disch actionHomRight_id (c : C) (d : D) : c ⊴ₗ 𝟙 d = 𝟙 (c ⊙ₗ d) := by cat_disch id_actionHomLeft (c : C) (d : D) : 𝟙 c ⊵ₗ d = 𝟙 (c ⊙ₗ d) := by cat_disch actionHom_comp {c c' c'' : C} {d d' d'' : D} (f₁ : c ⟶ c') (f₂ : c' ⟶ c'') (g₁ : d ⟶ d') (g₂ : d' ⟶ d'') : (f₁ ≫ f₂) ⊙ₗₘ (g₁ ≫ g₂) = (f₁ ⊙ₗₘ g₁) ≫ (f₂ ⊙ₗₘ g₂) := by cat_disch actionAssocIso_hom_naturality {c₁ c₂ c₃ c₄ : C} {d₁ d₂ : D} (f : c₁ ⟶ c₂) (g : c₃ ⟶ c₄) (h : d₁ ⟶ d₂) : ((f ⊗ₘ g) ⊙ₗₘ h) ≫ (αₗ c₂ c₄ d₂).hom = (αₗ c₁ c₃ d₁).hom ≫ (f ⊙ₗₘ g ⊙ₗₘ h) := by cat_disch actionUnitIso_hom_naturality {d d' : D} (f : d ⟶ d') : (λₗ d).hom ≫ f = (𝟙_ C) ⊴ₗ f ≫ (λₗ d').hom := by cat_disch whiskerLeft_actionHomLeft (c : C) {c' c'' : C} (f : c' ⟶ c'') (d : D) : (c ◁ f) ⊵ₗ d = (αₗ _ _ _).hom ≫ c ⊴ₗ f ⊵ₗ d ≫ (αₗ _ _ _).inv := by cat_disch whiskerRight_actionHomLeft {c c' : C} (c'' : C) (f : c ⟶ c') (d : D) : (f ▷ c'') ⊵ₗ d = (αₗ c c'' d).hom ≫ f ⊵ₗ (c'' ⊙ₗ d : D) ≫ (αₗ c' c'' d).inv := by cat_disch associator_actionHom (c₁ c₂ c₃ : C) (d : D) : (α_ c₁ c₂ c₃).hom ⊵ₗ d ≫ (αₗ c₁ (c₂ ⊗ c₃) d).hom ≫ c₁ ⊴ₗ (αₗ c₂ c₃ d).hom = (αₗ (c₁ ⊗ c₂ : C) c₃ d).hom ≫ (αₗ c₁ c₂ (c₃ ⊙ₗ d)).hom := by cat_disch leftUnitor_actionHom (c : C) (d : D) : (λ_ c).hom ⊵ₗ d = (αₗ _ _ _).hom ≫ (λₗ _).hom := by cat_disch rightUnitor_actionHom (c : C) (d : D) : (ρ_ c).hom ⊵ₗ d = (αₗ _ _ _).hom ≫ c ⊴ₗ (λₗ _).hom := by cat_disch attribute [reassoc] MonoidalLeftAction.actionHom_def attribute [reassoc, simp] MonoidalLeftAction.id_actionHomLeft attribute [reassoc, simp] MonoidalLeftAction.actionHomRight_id attribute [reassoc, simp] MonoidalLeftAction.whiskerLeft_actionHomLeft attribute [simp, reassoc] MonoidalLeftAction.actionHom_comp attribute [reassoc] MonoidalLeftAction.actionAssocIso_hom_naturality attribute [reassoc] MonoidalLeftAction.actionUnitIso_hom_naturality attribute [reassoc (attr := simp)] MonoidalLeftAction.associator_actionHom attribute [simp, reassoc] MonoidalLeftAction.leftUnitor_actionHom attribute [simp, reassoc] MonoidalLeftAction.rightUnitor_actionHom /-- A monoidal category acts on itself on the left through the tensor product. -/ @[simps!] instance selfLeftAction [MonoidalCategory C] : MonoidalLeftAction C C where actionObj x y := x ⊗ y actionHom f g := f ⊗ₘ g actionUnitIso x := λ_ x actionAssocIso x y z := α_ x y z actionHomLeft f x := f ▷ x actionHomRight x _ _ f := x ◁ f actionHom_def := by simp [tensorHom_def] @[deprecated (since := "2025-06-13")] alias selfAction := selfLeftAction namespace MonoidalLeftAction open Category variable {C D} [MonoidalCategory C] [MonoidalLeftAction C D] -- Simp normal forms are aligned with the ones in `MonoidalCategory`. @[simp] lemma id_actionHom (c : C) {d d' : D} (f : d ⟶ d') : (𝟙 c) ⊙ₗₘ f = c ⊴ₗ f := by simp [actionHom_def] @[simp] lemma actionHom_id {c c' : C} (f : c ⟶ c') (d : D) : f ⊙ₗₘ (𝟙 d) = f ⊵ₗ d := by simp [actionHom_def] @[reassoc, simp] theorem actionHomRight_comp (w : C) {x y z : D} (f : x ⟶ y) (g : y ⟶ z) : w ⊴ₗ (f ≫ g) = w ⊴ₗ f ≫ w ⊴ₗ g := by simp [← id_actionHom, ← actionHom_comp] @[reassoc, simp] theorem unit_actionHomRight {x y : D} (f : x ⟶ y) : (𝟙_ C) ⊴ₗ f = (λₗ x).hom ≫ f ≫ (λₗ y).inv := by rw [← Category.assoc, actionUnitIso_hom_naturality] simp @[reassoc, simp] theorem tensor_actionHomRight (x y : C) {z z' : D} (f : z ⟶ z') : (x ⊗ y) ⊴ₗ f = (αₗ x y z).hom ≫ x ⊴ₗ y ⊴ₗ f ≫ (αₗ x y z').inv := by simp only [← id_actionHom] rw [← Category.assoc, ← actionAssocIso_hom_naturality] simp @[reassoc, simp] theorem comp_actionHomLeft {w x y : C} (f : w ⟶ x) (g : x ⟶ y) (z : D) : (f ≫ g) ⊵ₗ z = f ⊵ₗ z ≫ g ⊵ₗ z := by simp only [← actionHom_id, ← actionHom_comp, Category.id_comp] @[reassoc, simp] theorem actionHomLeft_action {x x' : C} (f : x ⟶ x') (y : C) (z : D) : f ⊵ₗ (y ⊙ₗ z) = (αₗ x y z).inv ≫ (f ▷ y) ⊵ₗ z ≫ (αₗ x' y z).hom := by simp [whiskerRight_actionHomLeft] @[reassoc] theorem action_exchange {w x : C} {y z : D} (f : w ⟶ x) (g : y ⟶ z) : w ⊴ₗ g ≫ f ⊵ₗ z = f ⊵ₗ y ≫ x ⊴ₗ g := by simp only [← id_actionHom, ← actionHom_id, ← actionHom_comp, id_comp, comp_id] @[reassoc] theorem actionHom_def' {x₁ y₁ : C} {x₂ y₂ : D} (f : x₁ ⟶ y₁) (g : x₂ ⟶ y₂) : f ⊙ₗₘ g = x₁ ⊴ₗ g ≫ f ⊵ₗ y₂ := action_exchange f g ▸ actionHom_def f g @[reassoc] theorem actionAssocIso_inv_naturality {c₁ c₂ c₃ c₄ : C} {d₁ d₂ : D} (f : c₁ ⟶ c₂) (g : c₃ ⟶ c₄) (h : d₁ ⟶ d₂) : (f ⊙ₗₘ g ⊙ₗₘ h) ≫ (αₗ c₂ c₄ d₂).inv = (αₗ c₁ c₃ d₁).inv ≫ ((f ⊗ₘ g) ⊙ₗₘ h) := by rw [Iso.comp_inv_eq, Category.assoc, Eq.comm, Iso.inv_comp_eq, actionAssocIso_hom_naturality] @[reassoc] theorem actionUnitIso_inv_naturality {d d' : D} (f : d ⟶ d') : (λₗ d).inv ≫ (𝟙_ C) ⊴ₗ f = f ≫ (λₗ d').inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Eq.comm, Iso.comp_inv_eq, actionUnitIso_hom_naturality] @[reassoc (attr := simp)] theorem actionHomRight_hom_inv (x : C) {y z : D} (f : y ≅ z) : x ⊴ₗ f.hom ≫ x ⊴ₗ f.inv = 𝟙 (x ⊙ₗ y : D) := by rw [← actionHomRight_comp, Iso.hom_inv_id, actionHomRight_id] @[reassoc (attr := simp)] theorem hom_inv_actionHomLeft {x y : C} (f : x ≅ y) (z : D) : f.hom ⊵ₗ z ≫ f.inv ⊵ₗ z = 𝟙 (x ⊙ₗ z) := by rw [← comp_actionHomLeft, Iso.hom_inv_id, id_actionHomLeft] @[reassoc (attr := simp)] theorem actionHomRight_inv_hom (x : C) {y z : D} (f : y ≅ z) : x ⊴ₗ f.inv ≫ x ⊴ₗ f.hom = 𝟙 (x ⊙ₗ z) := by rw [← actionHomRight_comp, Iso.inv_hom_id, actionHomRight_id] @[reassoc (attr := simp)] theorem inv_hom_actionHomLeft {x y : C} (f : x ≅ y) (z : D) : f.inv ⊵ₗ z ≫ f.hom ⊵ₗ z = 𝟙 (y ⊙ₗ z) := by rw [← comp_actionHomLeft, Iso.inv_hom_id, id_actionHomLeft] @[reassoc (attr := simp)] theorem actionHomRight_hom_inv' (x : C) {y z : D} (f : y ⟶ z) [IsIso f] : x ⊴ₗ f ≫ x ⊴ₗ inv f = 𝟙 (x ⊙ₗ y) := by rw [← actionHomRight_comp, IsIso.hom_inv_id, actionHomRight_id] @[reassoc (attr := simp)] theorem hom_inv_actionHomLeft' {x y : C} (f : x ⟶ y) [IsIso f] (z : D) : f ⊵ₗ z ≫ inv f ⊵ₗ z = 𝟙 (x ⊙ₗ z) := by rw [← comp_actionHomLeft, IsIso.hom_inv_id, id_actionHomLeft] @[reassoc (attr := simp)] theorem actionHomRight_inv_hom' (x : C) {y z : D} (f : y ⟶ z) [IsIso f] : x ⊴ₗ inv f ≫ x ⊴ₗ f = 𝟙 (x ⊙ₗ z) := by rw [← actionHomRight_comp, IsIso.inv_hom_id, actionHomRight_id] @[reassoc (attr := simp)] theorem inv_hom_actionHomLeft' {x y : C} (f : x ⟶ y) [IsIso f] (z : D) : inv f ⊵ₗ z ≫ f ⊵ₗ z = 𝟙 (y ⊙ₗ z) := by rw [← comp_actionHomLeft, IsIso.inv_hom_id, id_actionHomLeft] instance isIso_actionHomRight (x : C) {y z : D} (f : y ⟶ z) [IsIso f] : IsIso (x ⊴ₗ f) := ⟨x ⊴ₗ inv f, by simp⟩ instance isIso_actionHomLeft {x y : C} (f : x ⟶ y) [IsIso f] (z : D) : IsIso (f ⊵ₗ z) := ⟨inv f ⊵ₗ z, by simp⟩ instance isIso_actionHom {x y : C} {x' y' : D} (f : x ⟶ y) (g : x' ⟶ y') [IsIso f] [IsIso g] : IsIso (f ⊙ₗₘ g) := ⟨(inv f) ⊙ₗₘ (inv g), by simp [← actionHom_comp]⟩ @[simp] lemma inv_actionHomLeft {x y : C} (f : x ⟶ y) [IsIso f] (z : D) : inv (f ⊵ₗ z) = inv f ⊵ₗ z := IsIso.inv_eq_of_hom_inv_id <| hom_inv_actionHomLeft' f z @[simp] lemma inv_actionHomRight (x : C) {y z : D} (f : y ⟶ z) [IsIso f] : inv (x ⊴ₗ f) = x ⊴ₗ inv f := IsIso.inv_eq_of_hom_inv_id <| actionHomRight_hom_inv' x f @[simp] lemma inv_actionHom {x y : C} {x' y' : D} (f : x ⟶ y) (g : x' ⟶ y') [IsIso f] [IsIso g] : inv (f ⊙ₗₘ g) = (inv f) ⊙ₗₘ (inv g) := IsIso.inv_eq_of_hom_inv_id <| by simp [← actionHom_comp] section variable (C D) /-- Bundle the action of `C` on `D` as a functor `C ⥤ D ⥤ D`. -/ @[simps!] def curriedAction : C ⥤ D ⥤ D where obj x := { obj y := x ⊙ₗ y map f := x ⊴ₗ f } map f := { app y := f ⊵ₗ y naturality _ _ _ := by simp [action_exchange] } variable {C} in /-- Bundle `d ↦ c ⊙ₗ d` as a functor. -/ @[simps!] abbrev actionLeft (c : C) : D ⥤ D := curriedAction C D |>.obj c variable {D} in /-- Bundle `c ↦ c ⊙ₗ d` as a functor. -/ @[simps!] abbrev actionRight (d : D) : C ⥤ D := curriedAction C D |>.flip.obj d /-- Bundle `αₗ _ _ _` as an isomorphism of trifunctors. -/ @[simps!] def actionAssocNatIso : bifunctorComp₁₂ (curriedTensor C) (curriedAction C D) ≅ bifunctorComp₂₃ (curriedAction C D) (curriedAction C D) := NatIso.ofComponents fun _ ↦ NatIso.ofComponents fun _ ↦ NatIso.ofComponents fun _ ↦ αₗ _ _ _ /-- Bundle `λₗ _` as an isomorphism of functors. -/ @[simps!] def actionUnitNatIso : actionLeft D (𝟙_ C) ≅ 𝟭 D := NatIso.ofComponents (λₗ ·) end end MonoidalLeftAction /-- A class that carries the non-Prop data required to define a right action of a monoidal category `C` on a category `D`, to set up notations. -/ class MonoidalRightActionStruct [MonoidalCategoryStruct C] where /-- The right action on objects. This is denoted `d ⊙ᵣ c`. -/ actionObj : D → C → D /-- The right action of a map `f : c ⟶ c'` in `C` on an object `d` in `D`. If we are to consider the action as a functor `Α : C ⥤ D ⥤ D`, this is `(Α.map f).app d`. This is denoted `d ⊴ᵣ f`. -/ actionHomRight (d : D) {c c' : C} (f : c ⟶ c') : actionObj d c ⟶ actionObj d c' /-- The action of an object `c : C` on a map `f : d ⟶ d'` in `D`. If we are to consider the action as a functor `Α : C ⥤ D ⥤ D`, this is `(Α.obj c).map f`. This is denoted `f ⊵ᵣ c`. -/ actionHomLeft {d d' : D} (f : d ⟶ d') (c : C) : actionObj d c ⟶ actionObj d' c /-- The action of a pair of maps `f : c ⟶ c'` and `d ⟶ d'`. By default, this is defined in terms of `actionHomLeft` and `actionHomRight`. -/ actionHom {c c' : C} {d d' : D} (f : d ⟶ d') (g : c ⟶ c') : actionObj d c ⟶ actionObj d' c' := actionHomLeft f c ≫ actionHomRight d' g /-- The structural isomorphism `d ⊙ᵣ (c ⊗ c') ≅ (d ⊙ᵣ c) ⊙ᵣ c'`. -/ actionAssocIso (d : D) (c c' : C) : actionObj d (c ⊗ c') ≅ actionObj (actionObj d c) c' /-- The structural isomorphism between `d ⊙ᵣ 𝟙_ C` and `d`. -/ actionUnitIso (d : D) : actionObj d (𝟙_ C) ≅ d namespace MonoidalRightAction export MonoidalRightActionStruct (actionObj actionHomLeft actionHomRight actionHom actionAssocIso actionUnitIso) -- infix priorities are aligned with the ones from `MonoidalCategoryStruct`. /-- Notation for `actionObj`, the action of `C` on `D`. -/ scoped infixr:70 " ⊙ᵣ " => MonoidalRightActionStruct.actionObj /-- Notation for `actionHomLeft`, the action of `D` on morphisms in `C`. -/ scoped infixr:81 " ⊵ᵣ " => MonoidalRightActionStruct.actionHomLeft /-- Notation for `actionHomRight`, the action of morphism in `D` on `C`. -/ scoped infixr:81 " ⊴ᵣ " => MonoidalRightActionStruct.actionHomRight /-- Notation for `actionHom`, the bifunctorial action of morphisms in `C` and `D` on `- ⊙ -`. -/ scoped infixr:70 " ⊙ᵣₘ " => MonoidalRightActionStruct.actionHom /-- Notation for `actionAssocIso`, the structural isomorphism `- ⊙ᵣ (- ⊗ -) ≅ (- ⊙ᵣ -) ⊙ᵣ -`. -/ scoped notation "αᵣ " => MonoidalRightActionStruct.actionAssocIso /-- Notation for `actionUnitIso`, the structural isomorphism `- ⊙ᵣ 𝟙_ C ≅ -`. -/ scoped notation "ρᵣ " => MonoidalRightActionStruct.actionUnitIso /-- Notation for `actionUnitIso`, the structural isomorphism `- ⊙ᵣ 𝟙_ C ≅ -`, allowing one to specify the acting category. -/ scoped notation "ρᵣ["J"]" => MonoidalRightActionStruct.actionUnitIso (C := J) end MonoidalRightAction open scoped MonoidalRightAction in /-- A `MonoidalRightAction C D` is the data of: - For every object `c : C` and `d : D`, an object `c ⊙ᵣ d` of `D`. - For every morphism `f : (c : C) ⟶ c'` and every `d : D`, a morphism `f ⊵ᵣ d : c ⊙ᵣ d ⟶ c' ⊙ᵣ d`. - For every morphism `f : (d : D) ⟶ d'` and every `c : C`, a morphism `c ⊴ᵣ f : c ⊙ᵣ d ⟶ c ⊙ᵣ d'`. - For every pair of morphisms `f : (c : C) ⟶ c'` and `f : (d : D) ⟶ d'`, a morphism `f ⊙ᵣₘ f' : c ⊙ᵣ d ⟶ c' ⊙ᵣ d'`. - A structure isomorphism `αᵣ c c' d : c ⊗ c' ⊙ᵣ d ≅ c ⊙ᵣ c' ⊙ᵣ d`. - A structure isomorphism `ρᵣ d : (𝟙_ C) ⊙ᵣ d ≅ d`. Furthermore, we require identities that turn `- ⊙ᵣ -` into a bifunctor, ensure naturality of `αᵣ` and `ρᵣ`, and ensure compatibilities with the associator and unitor isomorphisms in `C`. -/ class MonoidalRightAction [MonoidalCategory C] extends MonoidalRightActionStruct C D where actionHom_def {c c' : C} {d d' : D} (f : d ⟶ d') (g : c ⟶ c') : f ⊙ᵣₘ g = f ⊵ᵣ c ≫ d' ⊴ᵣ g := by cat_disch actionHomRight_id (c : C) (d : D) : d ⊴ᵣ 𝟙 c = 𝟙 (d ⊙ᵣ c) := by cat_disch id_actionHomLeft (c : C) (d : D) : 𝟙 d ⊵ᵣ c = 𝟙 (d ⊙ᵣ c) := by cat_disch actionHom_comp {c c' c'' : C} {d d' d'' : D} (f₁ : d ⟶ d') (f₂ : d' ⟶ d'') (g₁ : c ⟶ c') (g₂ : c' ⟶ c'') : (f₁ ≫ f₂) ⊙ᵣₘ (g₁ ≫ g₂) = (f₁ ⊙ᵣₘ g₁) ≫ (f₂ ⊙ᵣₘ g₂) := by cat_disch actionAssocIso_hom_naturality {d₁ d₂ : D} {c₁ c₂ c₃ c₄ : C} (f : d₁ ⟶ d₂) (g : c₁ ⟶ c₂) (h : c₃ ⟶ c₄) : (f ⊙ᵣₘ g ⊗ₘ h) ≫ (αᵣ d₂ c₂ c₄).hom = (αᵣ d₁ c₁ c₃).hom ≫ ((f ⊙ᵣₘ g) ⊙ᵣₘ h) := by cat_disch actionUnitIso_hom_naturality {d d' : D} (f : d ⟶ d') : (ρᵣ d).hom ≫ f = f ⊵ᵣ (𝟙_ C) ≫ (ρᵣ d').hom := by cat_disch actionHomRight_whiskerRight {c' c'' : C} (f : c' ⟶ c'') (c : C) (d : D) : d ⊴ᵣ (f ▷ c) = (αᵣ _ _ _).hom ≫ ((d ⊴ᵣ f) ⊵ᵣ c) ≫ (αᵣ _ _ _).inv := by cat_disch whiskerRight_actionHomLeft (c : C) {c' c'' : C} (f : c' ⟶ c'') (d : D) : d ⊴ᵣ (c ◁ f) = (αᵣ d c c').hom ≫ (d ⊙ᵣ c) ⊴ᵣ f ≫ (αᵣ d c c'').inv := by cat_disch actionHom_associator (c₁ c₂ c₃ : C) (d : D) : d ⊴ᵣ (α_ c₁ c₂ c₃).hom ≫ (αᵣ d c₁ (c₂ ⊗ c₃)).hom ≫ (αᵣ (d ⊙ᵣ c₁ : D) c₂ c₃).hom = (αᵣ d (c₁ ⊗ c₂ : C) c₃).hom ≫ (αᵣ d c₁ c₂).hom ⊵ᵣ c₃ := by cat_disch actionHom_leftUnitor (c : C) (d : D) : d ⊴ᵣ (λ_ c).hom = (αᵣ _ _ _).hom ≫ (ρᵣ _).hom ⊵ᵣ c := by cat_disch actionHom_rightUnitor (c : C) (d : D) : d ⊴ᵣ (ρ_ c).hom = (αᵣ _ _ _).hom ≫ (ρᵣ _).hom := by cat_disch attribute [reassoc] MonoidalRightAction.actionHom_def attribute [reassoc, simp] MonoidalRightAction.id_actionHomLeft attribute [reassoc, simp] MonoidalRightAction.actionHomRight_id attribute [reassoc, simp] MonoidalRightAction.actionHomRight_whiskerRight attribute [simp, reassoc] MonoidalRightAction.actionHom_comp attribute [reassoc] MonoidalRightAction.actionAssocIso_hom_naturality attribute [reassoc] MonoidalRightAction.actionUnitIso_hom_naturality attribute [reassoc (attr := simp)] MonoidalRightAction.actionHom_associator attribute [simp, reassoc] MonoidalRightAction.actionHom_leftUnitor attribute [simp, reassoc] MonoidalRightAction.actionHom_rightUnitor /-- A monoidal category acts on itself through the tensor product. -/ @[simps!] instance selRightfAction [MonoidalCategory C] : MonoidalRightAction C C where actionObj x y := x ⊗ y actionHom f g := f ⊗ₘ g actionUnitIso x := ρ_ x actionAssocIso x y z := α_ x y z|>.symm actionHomLeft f x := f ▷ x actionHomRight x _ _ f := x ◁ f actionHom_def := by simp [tensorHom_def] namespace MonoidalRightAction open Category variable {C D} [MonoidalCategory C] [MonoidalRightAction C D] -- Simp normal forms are aligned with the ones in `MonoidalCategory`. @[simp] lemma actionHom_id {d d' : D} (f : d ⟶ d') (c : C) : f ⊙ᵣₘ (𝟙 c) = f ⊵ᵣ c := by simp [actionHom_def] @[simp] lemma id_actionHom (d : D) {c c' : C} (f : c ⟶ c') : (𝟙 d) ⊙ᵣₘ f = d ⊴ᵣ f := by simp [actionHom_def] @[reassoc, simp] theorem actionHomRight_comp (w : D) {x y z : C} (f : x ⟶ y) (g : y ⟶ z) : w ⊴ᵣ (f ≫ g) = w ⊴ᵣ f ≫ w ⊴ᵣ g := by simp [← id_actionHom, ← actionHom_comp] @[reassoc, simp] theorem unit_actionHomRight {x y : D} (f : x ⟶ y) : f ⊵ᵣ (𝟙_ C) = (ρᵣ x).hom ≫ f ≫ (ρᵣ y).inv := by rw [← Category.assoc, actionUnitIso_hom_naturality] simp @[reassoc, simp] theorem actionHomLeft_tensor {z z' : D} (f : z ⟶ z') (x y : C) : (f ⊵ᵣ (x ⊗ y)) = (αᵣ z x y).hom ≫ (f ⊵ᵣ x) ⊵ᵣ y ≫ (αᵣ z' x y).inv := by simp only [← actionHom_id] rw [← Category.assoc, ← actionAssocIso_hom_naturality] simp @[reassoc, simp] theorem comp_actionHomLeft {w x y : D} (f : w ⟶ x) (g : x ⟶ y) (z : C) : (f ≫ g) ⊵ᵣ z = f ⊵ᵣ z ≫ g ⊵ᵣ z := by simp only [← actionHom_id, ← actionHom_comp, Category.id_comp] @[reassoc, simp] theorem action_actionHomRight (y : D) (z : C) {x x' : C} (f : x ⟶ x') : (y ⊙ᵣ z) ⊴ᵣ f = (αᵣ y z x).inv ≫ y ⊴ᵣ (z ◁ f) ≫ (αᵣ y z x').hom := by simp [whiskerRight_actionHomLeft] @[reassoc] theorem action_exchange {w x : D} {y z : C} (f : w ⟶ x) (g : y ⟶ z) : w ⊴ᵣ g ≫ f ⊵ᵣ z = f ⊵ᵣ y ≫ x ⊴ᵣ g := by simp only [← id_actionHom, ← actionHom_id, ← actionHom_comp, id_comp, comp_id] @[reassoc] theorem actionHom_def' {x₁ y₁ : D} {x₂ y₂ : C} (f : x₁ ⟶ y₁) (g : x₂ ⟶ y₂) : f ⊙ᵣₘ g = x₁ ⊴ᵣ g ≫ f ⊵ᵣ y₂ := action_exchange f g ▸ actionHom_def f g @[reassoc] theorem actionAssocIso_inv_naturality {d₁ d₂ : D} {c₁ c₂ c₃ c₄ : C} (f : d₁ ⟶ d₂) (g : c₁ ⟶ c₂) (h : c₃ ⟶ c₄) : ((f ⊙ᵣₘ g) ⊙ᵣₘ h) ≫ (αᵣ d₂ c₂ c₄).inv = (αᵣ d₁ c₁ c₃).inv ≫ (f ⊙ᵣₘ g ⊗ₘ h) := by rw [Iso.comp_inv_eq, Category.assoc, Eq.comm, Iso.inv_comp_eq, actionAssocIso_hom_naturality] @[reassoc] theorem actionUnitIso_inv_naturality {d d' : D} (f : d ⟶ d') : (ρᵣ d).inv ≫ f ⊵ᵣ (𝟙_ C) = f ≫ (ρᵣ d').inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Eq.comm, Iso.comp_inv_eq, actionUnitIso_hom_naturality] @[reassoc (attr := simp)] theorem actionHomRight_hom_inv (x : D) {y z : C} (f : y ≅ z) : x ⊴ᵣ f.hom ≫ x ⊴ᵣ f.inv = 𝟙 (x ⊙ᵣ y : D) := by rw [← actionHomRight_comp, Iso.hom_inv_id, actionHomRight_id] @[reassoc (attr := simp)] theorem hom_inv_actionHomLeft {x y : D} (f : x ≅ y) (z : C) : f.hom ⊵ᵣ z ≫ f.inv ⊵ᵣ z = 𝟙 (x ⊙ᵣ z) := by rw [← comp_actionHomLeft, Iso.hom_inv_id, id_actionHomLeft] @[reassoc (attr := simp)] theorem actionHomRight_inv_hom (x : D) {y z : C} (f : y ≅ z) : x ⊴ᵣ f.inv ≫ x ⊴ᵣ f.hom = 𝟙 (x ⊙ᵣ z) := by rw [← actionHomRight_comp, Iso.inv_hom_id, actionHomRight_id] @[reassoc (attr := simp)] theorem inv_hom_actionHomLeft {x y : D} (f : x ≅ y) (z : C) : f.inv ⊵ᵣ z ≫ f.hom ⊵ᵣ z = 𝟙 (y ⊙ᵣ z) := by rw [← comp_actionHomLeft, Iso.inv_hom_id, id_actionHomLeft] @[reassoc (attr := simp)] theorem actionHomRight_hom_inv' (x : D) {y z : C} (f : y ⟶ z) [IsIso f] : x ⊴ᵣ f ≫ x ⊴ᵣ inv f = 𝟙 (x ⊙ᵣ y) := by rw [← actionHomRight_comp, IsIso.hom_inv_id, actionHomRight_id] @[reassoc (attr := simp)] theorem hom_inv_actionHomLeft' {x y : D} (f : x ⟶ y) [IsIso f] (z : C) : f ⊵ᵣ z ≫ inv f ⊵ᵣ z = 𝟙 (x ⊙ᵣ z) := by rw [← comp_actionHomLeft, IsIso.hom_inv_id, id_actionHomLeft] @[reassoc (attr := simp)] theorem actionHomRight_inv_hom' (x : D) {y z : C} (f : y ⟶ z) [IsIso f] : x ⊴ᵣ inv f ≫ x ⊴ᵣ f = 𝟙 (x ⊙ᵣ z) := by rw [← actionHomRight_comp, IsIso.inv_hom_id, actionHomRight_id] @[reassoc (attr := simp)] theorem inv_hom_actionHomLeft' {x y : D} (f : x ⟶ y) [IsIso f] (z : C) : inv f ⊵ᵣ z ≫ f ⊵ᵣ z = 𝟙 (y ⊙ᵣ z) := by rw [← comp_actionHomLeft, IsIso.inv_hom_id, id_actionHomLeft] instance isIso_actionHomLeft {x y : D} (f : x ⟶ y) [IsIso f] (z : C) : IsIso (f ⊵ᵣ z) := ⟨inv f ⊵ᵣ z, by simp⟩ instance isIso_actionHomRight (x : D) {y z : C} (f : y ⟶ z) [IsIso f] : IsIso (x ⊴ᵣ f) := ⟨x ⊴ᵣ inv f, by simp⟩ instance isIso_actionHom {x y : D} {x' y' : C} (f : x ⟶ y) (g : x' ⟶ y') [IsIso f] [IsIso g] : IsIso (f ⊙ᵣₘ g) := ⟨(inv f) ⊙ᵣₘ (inv g), by simp [← actionHom_comp]⟩ @[simp] lemma inv_actionHomLeft {x y : D} (f : x ⟶ y) [IsIso f] (z : C) : inv (f ⊵ᵣ z) = inv f ⊵ᵣ z := IsIso.inv_eq_of_hom_inv_id <| hom_inv_actionHomLeft' f z @[simp] lemma inv_actionHomRight (x : D) {y z : C} (f : y ⟶ z) [IsIso f] : inv (x ⊴ᵣ f) = x ⊴ᵣ inv f := IsIso.inv_eq_of_hom_inv_id <| actionHomRight_hom_inv' x f @[simp] lemma inv_actionHom {x y : D} {x' y' : C} (f : x ⟶ y) (g : x' ⟶ y') [IsIso f] [IsIso g] : inv (f ⊙ᵣₘ g) = (inv f) ⊙ᵣₘ (inv g) := IsIso.inv_eq_of_hom_inv_id <| by simp [← actionHom_comp] section variable (C D) /-- Bundle the action of `C` on `D` as a functor `C ⥤ D ⥤ D`. -/ @[simps!] def curriedAction : C ⥤ D ⥤ D where obj x := { obj y := y ⊙ᵣ x map f := f ⊵ᵣ x } map f := { app y := y ⊴ᵣ f naturality _ _ _ := by simp [action_exchange] } variable {C} in /-- Bundle `d ↦ d ⊙ᵣ c` as a functor. -/ @[simps!] abbrev actionRight (c : C) : D ⥤ D := curriedAction C D |>.obj c variable {D} in /-- Bundle `c ↦ d ⊙ᵣ c` as a functor. -/ @[simps!] abbrev actionLeft (d : D) : C ⥤ D := curriedAction C D |>.flip.obj d /-- Bundle `αᵣ _ _ _` as an isomorphism of trifunctors. -/ @[simps!] def actionAssocNatIso : bifunctorComp₁₂ (curriedTensor C) (curriedAction C D) ≅ (bifunctorComp₂₃ (curriedAction C D) (curriedAction C D)).flip := NatIso.ofComponents fun _ ↦ NatIso.ofComponents fun _ ↦ NatIso.ofComponents fun _ ↦ αᵣ _ _ _ /-- Bundle `ρᵣ _` as an isomorphism of functors. -/ @[simps!] def actionUnitNatIso : actionRight D (𝟙_ C) ≅ 𝟭 D := NatIso.ofComponents (ρᵣ ·) end end MonoidalRightAction end CategoryTheory.MonoidalCategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Action/End.lean
import Mathlib.CategoryTheory.Monoidal.Action.Basic import Mathlib.CategoryTheory.Monoidal.End import Mathlib.CategoryTheory.Monoidal.Opposite /-! # Actions as monoidal functors to endofunctor categories In this file, we show that given a right action of a monoidal category `C` on a category `D`, the curried action functor `C ⥤ D ⥤ D` is monoidal. Conversely, given a monoidal functor `C ⥤ D ⥤ D`, we can define a right action of `C` on `D`. The corresponding results are also available for left actions: given a left action of `C` on `D`, composing `CategoryTheory.MonoidalCategory.MonoidalLeftAction.curriedAction C D` with `CategoryTheory.MonoidalCategory.MonoidalOpposite.mopFunctor (D ⥤ D)` is monoidal, and conversely one can define a left action of `C` on `D` from a monoidal functor `C ⥤ (D ⥤ D)ᴹᵒᵖ`. -/ namespace CategoryTheory.MonoidalCategory variable (C D : Type*) variable [Category C] [MonoidalCategory C] [Category D] attribute [local instance] endofunctorMonoidalCategory attribute [local aesop safe apply (rule_sets := [CategoryTheory])] MonoidalOpposite.hom_ext namespace MonoidalLeftAction section variable [MonoidalLeftAction C D] /-- A variant of `CategoryTheory.MonoidalCategory.MonoidalLeftAction.curriedAction` that takes value in the monoidal opposite of `D ⥤ D`. -/ @[simps! obj_unmop_obj obj_unmop_map] def curriedActionMop : C ⥤ (D ⥤ D)ᴹᵒᵖ := (curriedAction C D) ⋙ mopFunctor _ -- This simp lemma is necessary because the simps projection generated for -- unmop of a morphism is actually its underlying unmop field, rather than -- the application of `Quiver.Hom.unmop`. variable {C D} in @[simp] lemma curriedActionMop_map_unmop_app {c c' : C} (f : c ⟶ c') (d : D) : ((curriedActionMop C D).map f).unmop.app d = f ⊵ₗ d := rfl open MonoidalOpposite in /-- When `C` acts on the left on `D`, the functor `curriedActionMop : C ⥤ (D ⥤ D)ᴹᵒᵖ` is monoidal, where `D ⥤ D` has the composition monoidal structure. -/ @[simps!] instance curriedActionMopMonoidal : (curriedActionMop C D).Monoidal where ε := .mop <| (actionUnitNatIso C D).inv μ _ _ := .mop <| {app _ := αₗ _ _ _|>.inv} δ _ _ := .mop <| {app _ := αₗ _ _ _|>.hom} η := .mop <| (actionUnitNatIso C D).hom associativity c₁ c₂ c₃ := by apply (mopEquiv (D ⥤ D)).fullyFaithfulInverse.map_injective ext d simpa [-associator_actionHom] using (IsIso.inv_eq_inv.mpr <| associator_actionHom c₁ c₂ c₃ d).symm =≫ (α_ c₁ c₂ c₃).hom ⊵ₗ d oplax_right_unitality x := by apply MonoidalOpposite.hom_ext ext t simpa [-rightUnitor_actionHom] using (ρ_ x).inv ⊵ₗ t ≫= rightUnitor_actionHom x t oplax_left_unitality x := by apply MonoidalOpposite.hom_ext ext t simpa [-leftUnitor_actionHom] using (λ_ x).inv ⊵ₗ t ≫= leftUnitor_actionHom x t end variable {C D} /-- A monoidal functor `F : C ⥤ (D ⥤ D)ᴹᵒᵖ` can be thought of as a left action of `C` on `D`. -/ @[simps!] def actionOfMonoidalFunctorToEndofunctorMop (F : C ⥤ (D ⥤ D)ᴹᵒᵖ) [F.Monoidal] : MonoidalLeftAction C D where actionObj c d := (F.obj c).unmop.obj d actionHomLeft f d := (F.map f).unmop.app d actionHomRight c _ _ f := (F.obj c).unmop.map f actionAssocIso c c' d := Functor.Monoidal.μIso F c c'|>.unmop.app d|>.symm actionUnitIso d := Functor.Monoidal.εIso F|>.unmop.app d|>.symm actionAssocIso_hom_naturality {c₁ c₁' c₂ c₂' c₃ c₃'} f g h := by have e := congrArg (fun t ↦ t.unmop.app c₃) <| Functor.OplaxMonoidal.δ_natural F f g dsimp at e simp [reassoc_of% e] whiskerRight_actionHomLeft {x y} c f d := by have e := congrArg (fun t ↦ t.unmop.app d) <| Functor.LaxMonoidal.μ_natural_left F f c dsimp at e simp [e, ← NatTrans.comp_app, ← unmop_comp] whiskerLeft_actionHomLeft c {x y} f d := by have e := congrArg (fun t ↦ t.unmop.app d) <| Functor.LaxMonoidal.μ_natural_right F c f dsimp at e simp [e, ← NatTrans.comp_app, ← unmop_comp] associator_actionHom c₁ c₂ c₃ d := by have e := congrArg (fun t ↦ t.unmop.app d) <| Functor.OplaxMonoidal.associativity F c₁ c₂ c₃ dsimp at e simp only [Category.comp_id] at e simp [e] leftUnitor_actionHom c d := by have e := (F.map (λ_ c).hom).unmop.app d ≫= (congrArg (fun t ↦ t.unmop.app d) <| Functor.OplaxMonoidal.left_unitality F c) dsimp at e simp only [Category.comp_id, ← NatTrans.comp_app_assoc, ← unmop_comp, ← F.map_comp_assoc, Iso.hom_inv_id, Functor.map_id, Category.id_comp] at e simp [e] rightUnitor_actionHom c d := by have e := (F.map (ρ_ c).hom).unmop.app d ≫= (congrArg (fun t ↦ t.unmop.app d) <| Functor.OplaxMonoidal.right_unitality F c) dsimp at e simp only [Category.comp_id, ← NatTrans.comp_app_assoc, ← unmop_comp, ← F.map_comp_assoc, Iso.hom_inv_id, Functor.map_id, Category.id_comp] at e simp [e] /-- If the (left) action of `C` on `D` comes from a monoidal functor `C ⥤ (D ⥤ D)ᴹᵒᵖ`, then `curriedActionMop C D` is naturally isomorphic to that functor. -/ @[simps!] def curriedActionActionOfMonoidalFunctorToEndofunctorMopIso (F : C ⥤ (D ⥤ D)ᴹᵒᵖ) [F.Monoidal] : letI := actionOfMonoidalFunctorToEndofunctorMop F curriedActionMop C D ≅ F := .refl _ end MonoidalLeftAction namespace MonoidalRightAction variable {C D} open MonoidalOpposite in /-- When `C` acts on the right on `D`, the functor `curriedAction : C ⥤ (D ⥤ D)` is monoidal, where `D ⥤ D` has the composition monoidal structure. -/ @[simps!] instance curriedActionMonoidal [MonoidalRightAction C D] : (curriedAction C D).Monoidal where ε := (actionUnitNatIso C D).inv μ _ _ := {app _ := αᵣ _ _ _|>.inv} δ _ _ := {app _ := αᵣ _ _ _|>.hom} η := (actionUnitNatIso C D).hom associativity c₁ c₂ c₃ := by ext d simpa [-actionHom_associator] using (IsIso.inv_eq_inv.mpr <| actionHom_associator c₁ c₂ c₃ d).symm =≫ d ⊴ᵣ (α_ c₁ c₂ c₃).hom oplax_right_unitality x := by ext t simpa [-actionHom_rightUnitor] using t ⊴ᵣ (ρ_ x).inv ≫= actionHom_rightUnitor x t oplax_left_unitality x := by ext t simpa [-actionHom_leftUnitor] using t ⊴ᵣ (λ_ x).inv ≫= actionHom_leftUnitor x t /-- A monoidal functor `F : C ⥤ D ⥤ D` can be thought of as a right action of `C` on `D`. -/ @[simps!] def actionOfMonoidalFunctorToEndofunctor (F : C ⥤ D ⥤ D) [F.Monoidal] : MonoidalRightAction C D where actionObj d c := (F.obj c).obj d actionHomLeft f c := (F.obj c).map f actionHomRight d _ _ f := (F.map f).app d actionAssocIso d c c' := Functor.Monoidal.μIso F c c'|>.app d|>.symm actionUnitIso d := Functor.Monoidal.εIso F|>.app d|>.symm actionAssocIso_hom_naturality {c₁ c₁' c₂ c₂' c₃ c₃'} f g h := by have e := congrArg (fun t ↦ t.app c₁) <| Functor.OplaxMonoidal.δ_natural F g h dsimp at e simp [reassoc_of% e] /-- If the action of `C` on `D` comes from a monoidal functor `C ⥤ (D ⥤ D)`, then `curriedActionMop C D` is naturally isomorphic to that functor. -/ @[simps!] def curriedActionActionOfMonoidalFunctorToEndofunctorIso (F : C ⥤ (D ⥤ D)) [F.Monoidal] : letI := actionOfMonoidalFunctorToEndofunctor F curriedAction C D ≅ F := .refl _ end MonoidalRightAction namespace endofunctorMonoidalCategory /-- Functor evaluation gives a right action of `C ⥤ C`. Note that in the literature, this is defined as a left action, but mathlib's monoidal structure on `C ⥤ C` is the monoidal opposite of the one usually considered in the literature. -/ @[simps! actionObj actionHomLeft actionHomRight actionAssocIso actionUnitIso] scoped instance evaluationRightAction : MonoidalRightAction (C ⥤ C) C := MonoidalRightAction.actionOfMonoidalFunctorToEndofunctor (𝟭 (C ⥤ C)) end endofunctorMonoidalCategory end CategoryTheory.MonoidalCategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Action/Opposites.lean
import Mathlib.CategoryTheory.Monoidal.Action.Basic import Mathlib.CategoryTheory.Monoidal.Opposite /-! # Actions from the monoidal opposite of a category. In this file, given a monoidal category `C` and a category `D`, we construct a left `C`-action on `D` out of the data of a right `Cᴹᵒᵖ`-action on `D`. We also construct a right `C`-action on `D`from the data of a left `Cᴹᵒᵖ`-action on `D`. Conversely, given left/right `C`-actions on `D`, we construct a`Cᴹᵒᵖ` actions with the conjugate variance. We construct similar actions for `Cᵒᵖ`, namely, left/right `Cᵒᵖ`-actions on `Dᵒᵖ` from left/right-actions of `C` on `D`, and vice-versa. These constructions are not made instances in order to avoid instance loops, you should bring them as local instances if you intend to use them. -/ namespace CategoryTheory.MonoidalCategory variable (C D : Type*) variable [Category C] [MonoidalCategory C] [Category D] namespace MonoidalLeftAction open scoped MonoidalLeftAction MonoidalRightAction open MonoidalOpposite /-- Define a left action of `C` on `D` from a right action of `Cᴹᵒᵖ` on `D` via the formula `c ⊙ₗ d := d ⊙ᵣ (mop c)`. -/ @[simps -isSimp] def leftActionOfMonoidalOppositeRightAction [MonoidalRightAction Cᴹᵒᵖ D] : MonoidalLeftAction C D where actionObj c d := d ⊙ᵣ mop c actionHomLeft {c c'} f d := d ⊴ᵣ f.mop actionHomRight c {d d'} f := f ⊵ᵣ mop c actionHom {c c'} {d d} f g := g ⊙ᵣₘ f.mop actionAssocIso _ _ _ := αᵣ _ _ _ actionUnitIso _ := ρᵣ _ actionHom_def _ _ := MonoidalRightAction.actionHom_def' _ _ actionAssocIso_hom_naturality _ _ _ := MonoidalRightAction.actionAssocIso_hom_naturality _ _ _ actionUnitIso_hom_naturality _ := MonoidalRightAction.actionUnitIso_hom_naturality _ rightUnitor_actionHom c d := MonoidalRightAction.actionHom_leftUnitor _ _ associator_actionHom c₁ c₂ c₃ d := by simpa only [mop_tensorObj, mop_hom_associator, MonoidalRightAction.actionHomRight_inv_hom_assoc] using (d ⊴ᵣ (α_ (mop c₃) (mop c₂) (mop c₁)).inv) ≫= MonoidalRightAction.actionHom_associator (mop c₃) (mop c₂) (mop c₁) d|>.symm /-- Define a left action of `Cᴹᵒᵖ` on `D` from a right action of `C` on `D` via the formula `mop c ⊙ₗ d = d ⊙ᵣ c`. -/ @[simps -isSimp] def monoidalOppositeLeftAction [MonoidalRightAction C D] : MonoidalLeftAction Cᴹᵒᵖ D where actionObj c d := d ⊙ᵣ unmop c actionHomLeft {c c'} f d := d ⊴ᵣ f.unmop actionHomRight c {d d'} f := f ⊵ᵣ unmop c actionHom {c c'} {d d} f g := g ⊙ᵣₘ f.unmop actionAssocIso _ _ _ := αᵣ _ _ _ actionUnitIso _ := ρᵣ _ actionHom_def _ _ := MonoidalRightAction.actionHom_def' _ _ actionAssocIso_hom_naturality _ _ _ := MonoidalRightAction.actionAssocIso_hom_naturality _ _ _ actionUnitIso_hom_naturality _ := MonoidalRightAction.actionUnitIso_hom_naturality _ rightUnitor_actionHom c d := MonoidalRightAction.actionHom_leftUnitor _ _ associator_actionHom c₁ c₂ c₃ d := by simpa only [mop_tensorObj, mop_hom_associator, MonoidalRightAction.actionHomRight_inv_hom_assoc] using (d ⊴ᵣ (α_ (unmop c₃) (unmop c₂) (unmop c₁)).inv) ≫= MonoidalRightAction.actionHom_associator (unmop c₃) (unmop c₂) (unmop c₁) d|>.symm section attribute [local instance] monoidalOppositeLeftAction variable [MonoidalRightAction C D] lemma monoidalOppositeLeftAction_actionObj_mop (c : C) (d : D) : mop c ⊙ₗ d = d ⊙ᵣ c := rfl lemma monoidalOppositeLeftAction_actionHomLeft_mop {c c' : C} (f : c ⟶ c') (d : D) : f.mop ⊵ₗ d = d ⊴ᵣ f := rfl lemma monoidalOppositeLeftAction_actionRight_mop (c : C) {d d' : D} (f : d ⟶ d') : mop c ⊴ₗ f = f ⊵ᵣ c := rfl lemma monoidalOppositeLeftAction_actionHom_mop_mop {c c' : C} {d d' : D} (f : c ⟶ c') (g : d ⟶ d') : f.mop ⊙ₗₘ g = g ⊙ᵣₘ f := rfl lemma monoidalOppositeLeftAction_actionAssocIso_mop_mop (c c' : C) (d : D) : αₗ (mop c) (mop c') d = αᵣ d c' c := rfl end open Opposite /-- Define a left action of `Cᵒᵖ` on `Dᵒᵖ` from a left action of `C` on `D` via the formula `(op c) ⊙ₗ (op d) = op (c ⊙ₗ d)`. -/ @[simps -isSimp] def oppositeLeftAction [MonoidalLeftAction C D] : MonoidalLeftAction Cᵒᵖ Dᵒᵖ where actionObj c d := op <| c.unop ⊙ₗ d.unop actionHomLeft f d := (f.unop ⊵ₗ unop d).op actionHomRight c _ _ f := (unop c ⊴ₗ f.unop).op actionHom f g := (f.unop ⊙ₗₘ g.unop).op actionAssocIso _ _ _ := Iso.op <| (αₗ _ _ _).symm actionUnitIso _ := Iso.op <| (λₗ _).symm actionHom_def | op f, op g => by apply Quiver.Hom.unop_inj simpa [MonoidalLeftAction.action_exchange] using MonoidalLeftAction.actionHom_def f g actionAssocIso_hom_naturality | op f, op g, op h => by apply Quiver.Hom.unop_inj haveI := (αₗ (unop _) (unop _) (unop _)).inv ≫= MonoidalLeftAction.actionAssocIso_hom_naturality f g h simp only [Iso.inv_hom_id_assoc] at this simp [← this] actionUnitIso_hom_naturality _ := by apply Quiver.Hom.unop_inj simp whiskerRight_actionHomLeft _ _ _ := by apply Quiver.Hom.unop_inj simp associator_actionHom _ _ _ _ := by apply Quiver.Hom.unop_inj apply IsIso.inv_eq_inv.mp simp leftUnitor_actionHom _ _ := by apply Quiver.Hom.unop_inj apply IsIso.inv_eq_inv.mp simp rightUnitor_actionHom _ _ := by apply Quiver.Hom.unop_inj apply IsIso.inv_eq_inv.mp simp /-- Define a left action of `C` on `D` from a left action of `Cᵒᵖ` on `Dᵒᵖ` via the formula `c ⊙ₗ d = unop ((op c) ⊙ₗ (op d))`. -/ @[simps -isSimp] def leftActionOfOppositeLeftAction [MonoidalLeftAction Cᵒᵖ Dᵒᵖ] : MonoidalLeftAction C D where actionObj c d := unop <| op c ⊙ₗ op d actionHomLeft {c c'} f d := (f.op ⊵ₗ op d).unop actionHomRight c {d d'} f := (op c ⊴ₗ f.op).unop actionHom {c c'} {d d} f g := (f.op ⊙ₗₘ g.op).unop actionAssocIso _ _ _ := Iso.unop <| (αₗ _ _ _).symm actionUnitIso _ := Iso.unop <| (λₗ _).symm actionHom_def f g := by apply Quiver.Hom.op_inj simpa [MonoidalLeftAction.action_exchange] using MonoidalLeftAction.actionHom_def f.op g.op actionAssocIso_hom_naturality f g h := by apply Quiver.Hom.op_inj haveI := (αₗ (op _) (op _) (op _)).inv ≫= MonoidalLeftAction.actionAssocIso_hom_naturality f.op g.op h.op simp only [Iso.inv_hom_id_assoc] at this simp [← this] actionUnitIso_hom_naturality _ := by apply Quiver.Hom.op_inj simp whiskerRight_actionHomLeft _ _ _ := by apply Quiver.Hom.op_inj simp associator_actionHom _ _ _ _ := by apply Quiver.Hom.op_inj apply IsIso.inv_eq_inv.mp simp leftUnitor_actionHom _ _ := by apply Quiver.Hom.op_inj apply IsIso.inv_eq_inv.mp simp rightUnitor_actionHom _ _ := by apply Quiver.Hom.op_inj apply IsIso.inv_eq_inv.mp simp section attribute [local instance] oppositeLeftAction variable [MonoidalLeftAction C D] lemma oppositeLeftAction_actionObj_op (c : C) (d : D) : (op c) ⊙ₗ (op d) = op (c ⊙ₗ d) := rfl lemma oppositeLeftAction_actionHomLeft_op {c c' : C} (f : c ⟶ c') (d : D) : f.op ⊵ₗ op d = op (f ⊵ₗ d) := rfl lemma oppositeLeftAction_actionRight_op (c : C) {d d' : D} (f : d ⟶ d') : op c ⊴ₗ f.op = op (c ⊴ₗ f) := rfl lemma oppositeLeftAction_actionHom_op {c c' : C} {d d' : D} (f : c ⟶ c') (g : d ⟶ d') : f.op ⊙ₗₘ g.op = op (f ⊙ₗₘ g) := rfl lemma oppositeLeftAction_actionAssocIso_op (c c' : C) (d : D) : αₗ (op c) (op c') (op d) = (αₗ c c' d).symm.op := rfl end section attribute [local instance] leftActionOfOppositeLeftAction variable [MonoidalLeftAction Cᵒᵖ Dᵒᵖ] lemma leftActionOfOppositeLeftAction_actionObj_unop (c : Cᵒᵖ) (d : Dᵒᵖ) : (unop c) ⊙ₗ (unop d) = unop (c ⊙ₗ d) := rfl lemma leftActionOfOppositeLeftAction_actionHomLeft_unop {c c' : Cᵒᵖ} (f : c ⟶ c') (d : Dᵒᵖ) : f.unop ⊵ₗ unop d = unop (f ⊵ₗ d) := rfl lemma leftActionOfOppositeLeftAction_actionRight_unop (c : Cᵒᵖ) {d d' : Dᵒᵖ} (f : d ⟶ d') : unop c ⊴ₗ f.unop = unop (c ⊴ₗ f) := rfl lemma leftActionOfOppositeLeftAction_actionHom_unop {c c' : Cᵒᵖ} {d d' : Dᵒᵖ} (f : c ⟶ c') (g : d ⟶ d') : f.unop ⊙ₗₘ g.unop = unop (f ⊙ₗₘ g) := rfl lemma leftActionOfOppositeLeftAction_actionAssocIso_unop (c c' : Cᵒᵖ) (d : Dᵒᵖ) : αₗ (unop c) (unop c') (unop d) = (αₗ c c' d).symm.unop := rfl end end MonoidalLeftAction namespace MonoidalRightAction open scoped MonoidalLeftAction MonoidalRightAction open MonoidalOpposite /-- Define a right action of `C` on `D` from a left action of `Cᴹᵒᵖ` on `D` via the formula `d ⊙ᵣ c := (mop c) ⊙ₗ d`. -/ @[simps -isSimp] def rightActionOfMonoidalOppositeLeftAction [MonoidalLeftAction Cᴹᵒᵖ D] : MonoidalRightAction C D where actionObj d c := mop c ⊙ₗ d actionHomLeft {d d'} f c := mop c ⊴ₗ f actionHomRight d _ _ f := f.mop ⊵ₗ d actionHom {c c'} {d d'} f g := g.mop ⊙ₗₘ f actionAssocIso _ _ _ := αₗ _ _ _ actionUnitIso _ := λₗ _ actionHom_def _ _ := MonoidalLeftAction.actionHom_def' _ _ actionAssocIso_hom_naturality _ _ _ := MonoidalLeftAction.actionAssocIso_hom_naturality _ _ _ actionUnitIso_hom_naturality _ := MonoidalLeftAction.actionUnitIso_hom_naturality _ actionHom_associator c₁ c₂ c₃ d := by simpa only [mop_tensorObj, mop_hom_associator, MonoidalLeftAction.inv_hom_actionHomLeft_assoc] using (α_ (mop c₃) (mop c₂) (mop c₁)).inv ⊵ₗ d ≫= MonoidalLeftAction.associator_actionHom (mop c₃) (mop c₂) (mop c₁) d|>.symm /-- Define a right action of `Cᴹᵒᵖ` on `D` from a left action of `C` on `D` via the formula `d ⊙ᵣ mop c = c ⊙ₗ d`. -/ @[simps -isSimp] def monoidalOppositeRightAction [MonoidalLeftAction C D] : MonoidalRightAction Cᴹᵒᵖ D where actionObj d c := unmop c ⊙ₗ d actionHomLeft {d d'} f c := unmop c ⊴ₗ f actionHomRight d _ _ f := f.unmop ⊵ₗ d actionHom {c c'} {d d'} f g := g.unmop ⊙ₗₘ f actionAssocIso _ _ _ := αₗ _ _ _ actionUnitIso _ := λₗ _ actionHom_def _ _ := MonoidalLeftAction.actionHom_def' _ _ actionAssocIso_hom_naturality _ _ _ := MonoidalLeftAction.actionAssocIso_hom_naturality _ _ _ actionUnitIso_hom_naturality _ := MonoidalLeftAction.actionUnitIso_hom_naturality _ actionHom_associator c₁ c₂ c₃ d := by simpa only [mop_tensorObj, mop_hom_associator, MonoidalLeftAction.inv_hom_actionHomLeft_assoc] using (α_ (unmop c₃) (unmop c₂) (unmop c₁)).inv ⊵ₗ d ≫= MonoidalLeftAction.associator_actionHom (unmop c₃) (unmop c₂) (unmop c₁) d|>.symm section attribute [local instance] monoidalOppositeRightAction variable [MonoidalLeftAction C D] lemma monoidalOppositeRightAction_actionObj_mop (c : C) (d : D) : d ⊙ᵣ mop c = c ⊙ₗ d := rfl lemma monoidalOppositeRightAction_actionHomRight_mop {c c' : C} (f : c ⟶ c') (d : D) : d ⊴ᵣ f.mop = f ⊵ₗ d := rfl lemma monoidalOppositeRightAction_actionRight_mop (c : C) {d d' : D} (f : d ⟶ d') : f ⊵ᵣ mop c = c ⊴ₗ f := rfl lemma monoidalOppositeRightAction_actionHom_mop_mop {c c' : D} {d d' : C} (f : c ⟶ c') (g : d ⟶ d') : f ⊙ᵣₘ g.mop = g ⊙ₗₘ f := rfl lemma monoidalOppositeRightAction_actionAssocIso_mop_mop (c c' : C) (d : D) : αᵣ d (mop c) (mop c') = αₗ c' c d := rfl end open Opposite /-- Define a right action of `Cᵒᵖ` on `Dᵒᵖ` from a right action of `C` on `D` via the formula `(op d) ⊙ᵣ (op c) = op (d ⊙ᵣ c)`. -/ @[simps -isSimp] def oppositeRightAction [MonoidalRightAction C D] : MonoidalRightAction Cᵒᵖ Dᵒᵖ where actionObj c d := op <| c.unop ⊙ᵣ d.unop actionHomLeft {c c'} f d := (f.unop ⊵ᵣ unop d).op actionHomRight c {d d'} f := (unop c ⊴ᵣ f.unop).op actionHom {c c'} {d d'} f g := (f.unop ⊙ᵣₘ g.unop).op actionAssocIso _ _ _ := Iso.op <| (αᵣ _ _ _).symm actionUnitIso _ := Iso.op <| (ρᵣ _).symm actionHom_def | op f, op g => by apply Quiver.Hom.unop_inj simpa [MonoidalRightAction.action_exchange] using MonoidalRightAction.actionHom_def f g actionAssocIso_hom_naturality | op f, op g, op h => by apply Quiver.Hom.unop_inj haveI := (αᵣ (unop _) (unop _) (unop _)).inv ≫= MonoidalRightAction.actionAssocIso_hom_naturality f g h simp only [Iso.inv_hom_id_assoc] at this simp [← this] actionUnitIso_hom_naturality _ := by apply Quiver.Hom.unop_inj simp whiskerRight_actionHomLeft _ _ _ _ _ := by apply Quiver.Hom.unop_inj simp actionHom_associator _ _ _ _ := by apply Quiver.Hom.unop_inj apply IsIso.inv_eq_inv.mp simp actionHom_leftUnitor _ _ := by apply Quiver.Hom.unop_inj apply IsIso.inv_eq_inv.mp simp actionHom_rightUnitor _ _ := by apply Quiver.Hom.unop_inj apply IsIso.inv_eq_inv.mp simp /-- Define a right action of `C` on `D` from a right action of `Cᵒᵖ` on `Dᵒᵖ` via the formula `d ⊙ᵣ c = unop ((op d) ⊙ᵣ (op c))`. -/ @[simps -isSimp] def rightActionOfOppositeRightAction [MonoidalRightAction Cᵒᵖ Dᵒᵖ] : MonoidalRightAction C D where actionObj c d := unop <| op c ⊙ᵣ op d actionHomLeft {c c'} f d := (f.op ⊵ᵣ op d).unop actionHomRight c {d d'} f := (op c ⊴ᵣ f.op).unop actionHom {c c'} {d d} f g := (f.op ⊙ᵣₘ g.op).unop actionAssocIso _ _ _ := Iso.unop <| (αᵣ _ _ _).symm actionUnitIso _ := Iso.unop <| (ρᵣ _).symm actionHom_def f g := by apply Quiver.Hom.op_inj simpa [MonoidalRightAction.action_exchange] using MonoidalRightAction.actionHom_def f.op g.op actionAssocIso_hom_naturality f g h := by apply Quiver.Hom.op_inj haveI := (αᵣ (op _) (op _) (op _)).inv ≫= MonoidalRightAction.actionAssocIso_hom_naturality f.op g.op h.op simp only [Iso.inv_hom_id_assoc] at this simp [← this] actionUnitIso_hom_naturality _ := by apply Quiver.Hom.op_inj simp whiskerRight_actionHomLeft _ _ _ _ _ := by apply Quiver.Hom.op_inj simp actionHom_associator _ _ _ _ := by apply Quiver.Hom.op_inj apply IsIso.inv_eq_inv.mp simp actionHom_leftUnitor _ _ := by apply Quiver.Hom.op_inj apply IsIso.inv_eq_inv.mp simp actionHom_rightUnitor _ _ := by apply Quiver.Hom.op_inj apply IsIso.inv_eq_inv.mp simp section attribute [local instance] oppositeRightAction variable [MonoidalRightAction C D] lemma oppositeRightAction_actionObj_op (d : D) (c : C) : op d ⊙ᵣ op c = op (d ⊙ᵣ c) := rfl lemma oppositeRightAction_actionHomLeft_op {d d' : D} (f : d ⟶ d') (c : C) : f.op ⊵ᵣ op c = op (f ⊵ᵣ c) := rfl lemma oppositeRightAction_actionRight_op (d : D) {c c' : C} (f : c ⟶ c') : op d ⊴ᵣ f.op = op (d ⊴ᵣ f) := rfl lemma oppositeRightAction_actionHom_op {d d' : D} {c c' : C} (f : d ⟶ d') (g : c ⟶ c') : f.op ⊙ᵣₘ g.op = op (f ⊙ᵣₘ g) := rfl lemma oppositeRightAction_actionAssocIso_op (d : D) (c c' : C) : αᵣ (op d) (op c) (op c') = (αᵣ d c c').symm.op := rfl end section attribute [local instance] rightActionOfOppositeRightAction variable [MonoidalRightAction Cᵒᵖ Dᵒᵖ] lemma rightActionOfOppositeRightAction_actionObj_unop (d : Dᵒᵖ) (c : Cᵒᵖ) : unop d ⊙ᵣ unop c = unop (d ⊙ᵣ c) := rfl lemma rightActionOfOppositeRightAction_actionHomLeft_unop {d d' : Dᵒᵖ} (f : d ⟶ d') (c : Cᵒᵖ) : f.unop ⊵ᵣ unop c = unop (f ⊵ᵣ c) := rfl lemma rightActionOfOppositeRightAction_actionRight_unop (d : Dᵒᵖ) {c c' : Cᵒᵖ} (f : c ⟶ c') : unop d ⊴ᵣ f.unop = unop (d ⊴ᵣ f) := rfl lemma rightActionOfOppositeRightAction_actionHom_unop {d d' : Dᵒᵖ} {c c' : Cᵒᵖ} (f : d ⟶ d') (g : c ⟶ c') : f.unop ⊙ᵣₘ g.unop = unop (f ⊙ᵣₘ g) := rfl lemma rightActionOfOppositeRightAction_actionAssocIso_unop (d : Dᵒᵖ) (c c' : Cᵒᵖ) : αᵣ (unop d) (unop c) (unop c') = (αᵣ d c c').symm.unop := rfl end end MonoidalRightAction end CategoryTheory.MonoidalCategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/OfChosenFiniteProducts/Basic.lean
import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic deprecated_module (since := "2025-05-08")
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/OfChosenFiniteProducts/Symmetric.lean
import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic deprecated_module (since := "2025-05-08")
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Braided/Transport.lean
import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.Transport /-! # Transport a symmetric monoidal structure along an equivalence of categories -/ universe v₁ v₂ u₁ u₂ open CategoryTheory Category Monoidal MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] namespace CategoryTheory.Monoidal open Functor.LaxMonoidal Functor.OplaxMonoidal instance Transported.instBraidedCategory (e : C ≌ D) [MonoidalCategory C] [BraidedCategory C] : BraidedCategory (Transported e) := .ofFaithful e.inverse (fun _ _ ↦ e.functor.mapIso (β_ _ _)) fun _ _ ↦ by simp [fromInducedCoreMonoidal, Functor.CoreMonoidal.toLaxMonoidal] local notation "e'" e => equivalenceTransported e instance (e : C ≌ D) [MonoidalCategory C] [BraidedCategory C] : (e' e).inverse.Braided where braided X Y := by simp [Transported.instBraidedCategory, BraidedCategory.ofFaithful, fromInducedCoreMonoidal, Functor.CoreMonoidal.toLaxMonoidal] noncomputable section /-- This is a def because once we have that both `(e' e).inverse` and `(e' e).functor` are braided, this causes a diamond. -/ def transportedFunctorCompInverseLaxBraided (e : C ≌ D) [MonoidalCategory C] [BraidedCategory C] : ((e' e).functor ⋙ (e' e).inverse).LaxBraided := Functor.LaxBraided.ofNatIso (e' e).unitIso attribute [local instance] transportedFunctorCompInverseLaxBraided in /-- This is a def because once we have that both `(e' e).inverse` and `(e' e).functor` are braided, this causes a diamond. -/ def transportedFunctorCompInverseBraided (e : C ≌ D) [MonoidalCategory C] [BraidedCategory C] : ((e' e).functor ⋙ (e' e).inverse).Braided where attribute [local instance] transportedFunctorCompInverseBraided in instance (e : C ≌ D) [MonoidalCategory C] [BraidedCategory C] : (e' e).functor.Braided where braided X Y := by apply (e' e).inverse.map_injective have : Functor.LaxMonoidal.μ (((e' e).functor ⋙ (e' e).inverse)) X Y ≫ ((e' e).functor ⋙ (e' e).inverse).map (β_ X Y).hom ≫ Functor.OplaxMonoidal.δ ((e' e).functor ⋙ (e' e).inverse) Y X = (β_ (((e' e).functor ⋙ (e' e).inverse).obj X) (((e' e).functor ⋙ (e' e).inverse).obj Y)).hom := by simp only [((e' e).functor ⋙ (e' e).inverse).map_braiding X Y, Functor.CoreMonoidal.toMonoidal_toOplaxMonoidal, assoc, Functor.Monoidal.μ_δ, comp_id, Functor.Monoidal.μ_δ_assoc] simp? [-Adjunction.rightAdjointLaxMonoidal_μ] at this says simp only [Functor.comp_obj, Functor.CoreMonoidal.toMonoidal_toLaxMonoidal, Equivalence.symm_inverse, Equivalence.symm_functor, Functor.CoreMonoidal.toMonoidal_toOplaxMonoidal, comp_μ, Functor.comp_map, Equivalence.inv_fun_map, Functor.id_obj, comp_δ, assoc] at this simp [-Adjunction.rightAdjointLaxMonoidal_μ, ← this] end instance Transported.instSymmetricCategory (e : C ≌ D) [MonoidalCategory C] [SymmetricCategory C] : SymmetricCategory (Transported e) := .ofFaithful (equivalenceTransported e).inverse end CategoryTheory.Monoidal
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Braided/Opposite.lean
import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.Opposite /-! # If `C` is braided, so is `Cᵒᵖ`. Todo: we should also do `Cᵐᵒᵖ`. -/ open CategoryTheory MonoidalCategory BraidedCategory Opposite variable {C : Type*} [Category C] [MonoidalCategory C] [BraidedCategory C] instance : BraidedCategory Cᵒᵖ where braiding X Y := (β_ (unop Y) (unop X)).op namespace CategoryTheory.BraidedCategory @[simp] lemma unop_tensorμ {C : Type*} [Category C] [MonoidalCategory C] [BraidedCategory C] (X Y W Z : Cᵒᵖ) : (tensorμ X W Y Z).unop = tensorμ X.unop Y.unop W.unop Z.unop := by simp only [unop_tensorObj, tensorμ, unop_comp, unop_inv_associator, unop_whiskerLeft, unop_hom_associator, unop_whiskerRight, unop_hom_braiding, Category.assoc] @[simp] lemma op_tensorμ {C : Type*} [Category C] [MonoidalCategory C] [BraidedCategory C] (X Y W Z : C) : (tensorμ X W Y Z).op = tensorμ (op X) (op Y) (op W) (op Z) := by simp only [op_tensorObj, tensorμ, op_comp, op_inv_associator, op_whiskerLeft, op_hom_associator, op_whiskerRight, op_hom_braiding, Category.assoc] end CategoryTheory.BraidedCategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Braided/Reflection.lean
import Mathlib.CategoryTheory.Adjunction.Restrict import Mathlib.CategoryTheory.Closed.Monoidal import Mathlib.CategoryTheory.Monad.Adjunction import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.Tactic.TFAE /-! # Day's reflection theorem Let `D` be a symmetric monoidal closed category and let `C` be a reflective subcategory. Day's reflection theorem proves the equivalence of four conditions, which are all of the form that a map obtained by acting on the unit of the reflective adjunction, with the internal hom and tensor functors, is an isomorphism. Suppose that `C` is itself monoidal and that the reflector is a monoidal functor. Then we can apply Day's reflection theorem to prove that `C` is also closed monoidal. ## References - We follow the proof on nLab, see https://ncatlab.org/nlab/show/Day%27s+reflection+theorem. - The original paper is [day1972] *A reflection theorem for closed categories*, by Day, 1972. -/ namespace CategoryTheory.Monoidal.Reflective open Category MonoidalCategory MonoidalClosed BraidedCategory Functor variable {C D : Type*} [Category C] [Category D] variable [MonoidalCategory D] [SymmetricCategory D] [MonoidalClosed D] section variable {R : C ⥤ D} [R.Faithful] [R.Full] {L : D ⥤ C} (adj : L ⊣ R) /-- The uncurried retraction of the unit in the proof of `4 → 1` in `isIso_tfae` below. -/ private noncomputable def adjRetractionAux (c : C) (d : D) [IsIso (L.map (adj.unit.app ((ihom d).obj (R.obj c)) ⊗ₘ adj.unit.app d))] : d ⊗ ((L ⋙ R).obj ((ihom d).obj (R.obj c))) ⟶ (R.obj c) := (β_ _ _).hom ≫ (_ ◁ adj.unit.app _) ≫ adj.unit.app _ ≫ R.map (inv (L.map (adj.unit.app _ ⊗ₘ adj.unit.app _))) ≫ (L ⋙ R).map (β_ _ _).hom ≫ (L ⋙ R).map ((ihom.ev _).app _) ≫ inv (adj.unit.app _) /-- The retraction of the unit in the proof of `4 → 1` in `isIso_tfae` below. -/ private noncomputable def adjRetraction (c : C) (d : D) [IsIso (L.map (adj.unit.app ((ihom d).obj (R.obj c)) ⊗ₘ adj.unit.app d))] : (L ⋙ R).obj ((ihom d).obj (R.obj c)) ⟶ ((ihom d).obj (R.obj c)) := curry <| adjRetractionAux adj c d private lemma adjRetraction_is_retraction (c : C) (d : D) [IsIso (L.map (adj.unit.app ((ihom d).obj (R.obj c)) ⊗ₘ adj.unit.app d))] : adj.unit.app ((ihom d).obj (R.obj c)) ≫ adjRetraction adj c d = 𝟙 _ := by suffices (_ ◁ adj.unit.app _) ≫ adjRetractionAux adj c d = (ihom.ev _).app _ by simp only [id_obj, comp_obj, adjRetraction, ← curry_natural_left, this] simp [curry_eq] simp only [id_obj, comp_obj, adjRetractionAux, Functor.map_inv, Functor.comp_map, braiding_naturality_right_assoc] slice_lhs 2 3 => simp only [← id_tensorHom, ← tensorHom_id, tensorHom_comp_tensorHom, Category.id_comp, Category.comp_id] slice_lhs 2 4 => rw [← adj.unit_naturality_assoc] simp attribute [local simp] Adjunction.homEquiv_unit Adjunction.homEquiv_counit /-- Day's reflection theorem. Let `D` be a symmetric monoidal closed category and let `C` be a reflective subcategory. Denote by `R : C ⥤ D` the inclusion functor and by `L : D ⥤ C` the reflector. Let `u` denote the unit of the adjunction `L ⊣ R`. Denote the internal hom by `[-,-]`. The following are equivalent: 1. `u : [d, Rc] ⟶ RL[d, Rc]` is an isomorphism, 2. `[u, 𝟙] : [RLd, Rc] ⟶ [d, Rc]` is an isomorphism, 3. `L(u ▷ d') : L(d ⊗ d') ⟶ L(RLd ⊗ d')` is an isomorphism, 4. `L(u ⊗ u) : L(d ⊗ d') ⟶ L(RLd ⊗ RLd')` is an isomorphism, where `c, d, d'` are arbitrary objects of `C`/`D`, quantified over separately in each condition. -/ theorem isIso_tfae : List.TFAE [ ∀ (c : C) (d : D), IsIso (adj.unit.app ((ihom d).obj (R.obj c))) , ∀ (c : C) (d : D), IsIso ((pre (adj.unit.app d)).app (R.obj c)) , ∀ (d d' : D), IsIso (L.map ((adj.unit.app d) ▷ d')) , ∀ (d d' : D), IsIso (L.map ((adj.unit.app d) ⊗ₘ (adj.unit.app d')))] := by tfae_have 3 → 4 | h => by -- We can commute the tensor product in the condition that `L.map ((adj.unit.app d) ▷ d')` is -- an isomorphism: have h' : ∀ d d', IsIso (L.map (d ◁ (adj.unit.app d'))) := by intro d d' have := braiding_naturality (𝟙 d) (adj.unit.app d') rw [← Iso.eq_comp_inv, id_tensorHom] at this rw [this] simp only [map_comp, id_obj, comp_obj, tensorHom_id, Category.assoc] infer_instance intro d d' -- We then write the tensor product of the two units as the composition of the whiskered units, -- and conclude. have : (adj.unit.app d) ⊗ₘ (adj.unit.app d') = (adj.unit.app d ▷ d') ≫ (((L ⋙ R).obj _) ◁ adj.unit.app d') := by simp [← tensorHom_id, ← id_tensorHom, tensorHom_comp_tensorHom] rw [this, map_comp] infer_instance tfae_have 4 → 1 | _, _, _ => by -- It is enough to show that the unit is a split monomorphism, and the retraction is given -- by `adjRetraction` above. let _ : Reflective R := { L := L, adj := adj } have : IsIso adj.toMonad.μ := μ_iso_of_reflective (R := R) erw [← adj.toMonad.isSplitMono_iff_isIso_unit] exact ⟨⟨adjRetraction adj _ _, adjRetraction_is_retraction adj _ _⟩⟩ tfae_have 1 → 3 | h, d, d' => by rw [isIso_iff_isIso_coyoneda_map] intro c -- `w₁, w₃, w₄` are the three stacked commutative squares in the proof on nLab: have w₁ : (coyoneda.map (L.map (adj.unit.app d ▷ d')).op).app c = (adj.homEquiv _ _).symm ∘ (coyoneda.map (adj.unit.app d ▷ d').op).app (R.obj c) ∘ adj.homEquiv _ _ := by ext; simp rw [w₁, isIso_iff_bijective] simp only [comp_obj, flip_obj_obj, yoneda_obj_obj, id_obj, op_tensorObj, unop_tensorObj, EquivLike.comp_bijective, EquivLike.bijective_comp] -- We commute the tensor product using the auxiliary commutative square `w₂`. have w₂ : ((coyoneda.map (adj.unit.app d ▷ d').op).app (R.obj c)) = ((yoneda.obj (R.obj c)).mapIso (β_ _ _)).hom ∘ ((coyoneda.map (d' ◁ adj.unit.app d).op).app (R.obj c)) ∘ ((yoneda.obj (R.obj c)).mapIso (β_ _ _)).hom := by ext; simp rw [w₂, ← types_comp, ← types_comp, ← isIso_iff_bijective] refine IsIso.comp_isIso' (IsIso.comp_isIso' inferInstance ?_) inferInstance have w₃ : ((coyoneda.map (d' ◁ adj.unit.app d).op).app (R.obj c)) = ((ihom.adjunction d').homEquiv _ _).symm ∘ ((coyoneda.map (adj.unit.app _).op).app _) ∘ (ihom.adjunction d').homEquiv _ _ := by ext simp only [id_obj, op_tensorObj, flip_obj_obj, yoneda_obj_obj, unop_tensorObj, comp_obj, flip_map_app, Function.comp_apply, Adjunction.homEquiv_unit, Adjunction.homEquiv_counit] simp rw [w₃, isIso_iff_bijective] simp only [comp_obj, op_tensorObj, flip_obj_obj, yoneda_obj_obj, unop_tensorObj, id_obj, yoneda_obj_obj, curriedTensor_obj_obj, EquivLike.comp_bijective, EquivLike.bijective_comp] have w₄ : (coyoneda.map (adj.unit.app d).op).app ((ihom d').obj (R.obj c)) ≫ (coyoneda.obj ⟨d⟩).map (adj.unit.app ((ihom d').obj (R.obj c))) = (coyoneda.obj ⟨(L ⋙ R).obj d⟩).map (adj.unit.app ((ihom d').obj (R.obj c))) ≫ (coyoneda.map (adj.unit.app d).op).app _ := by simp rw [← isIso_iff_bijective] suffices IsIso ((coyoneda.map (adj.unit.app d).op).app ((ihom d').obj (R.obj c)) ≫ (coyoneda.obj ⟨d⟩).map (adj.unit.app ((ihom d').obj (R.obj c)))) from IsIso.of_isIso_comp_right _ ((coyoneda.obj ⟨d⟩).map (adj.unit.app ((ihom d').obj (R.obj c)))) rw [w₄] refine IsIso.comp_isIso' inferInstance ?_ constructor -- We give the inverse of the bottom map in the stack of commutative squares: refine ⟨fun f ↦ R.map ((adj.homEquiv _ _).symm f), ?_, by ext; simp⟩ ext f simp only [comp_obj, flip_obj_obj, yoneda_obj_obj, id_obj, flip_map_app, Adjunction.homEquiv_counit, map_comp, types_comp_apply, yoneda_obj_map, Quiver.Hom.unop_op, Category.assoc] have : f = R.map (R.preimage f) := by simp rw [this] simp [← map_comp, -map_preimage] tfae_have 2 ↔ 3 := by conv => lhs; intro c d; rw [isIso_iff_isIso_yoneda_map] conv => rhs; intro d d'; rw [isIso_iff_isIso_coyoneda_map] -- bring the quantifiers out of the `↔`: rw [forall_swap]; apply forall_congr'; intro d rw [forall_swap]; apply forall₂_congr; intro d' c -- `w₁, w₂,` are the two stacked commutative squares in the proof on nLab: have w₁ : ((coyoneda.map (L.map (adj.unit.app d ▷ d')).op).app c) = (adj.homEquiv _ _).symm ∘ (coyoneda.map (adj.unit.app d ▷ d').op).app (R.obj c) ∘ (adj.homEquiv _ _) := by ext; simp have w₂ : ((yoneda.map ((pre (adj.unit.app d)).app (R.obj c))).app ⟨d'⟩) = ((ihom.adjunction d).homEquiv _ _) ∘ ((coyoneda.map (adj.unit.app d ▷ d').op).app (R.obj c)) ∘ ((ihom.adjunction ((L ⋙ R).obj d)).homEquiv _ _).symm := by rw [← Function.comp_assoc, ((ihom.adjunction ((L ⋙ R).obj d)).homEquiv _ _).eq_comp_symm] ext simp only [id_obj, yoneda_obj_obj, comp_obj, Function.comp_apply, yoneda_map_app, op_tensorObj, flip_obj_obj, yoneda_obj_obj, unop_tensorObj, op_whiskerRight, flip_map_app] rw [Adjunction.homEquiv_unit, Adjunction.homEquiv_unit] simp rw [w₂, w₁, isIso_iff_bijective, isIso_iff_bijective] simp tfae_finish end section open Functor.OplaxMonoidal Functor.LaxMonoidal Functor.Monoidal variable [MonoidalCategory C] variable {L : D ⥤ C} [L.Monoidal] {R : C ⥤ D} [R.Faithful] [R.Full] (adj : L ⊣ R) instance (d d' : D) : IsIso (L.map ((adj.unit.app d) ⊗ₘ (adj.unit.app d'))) := by have := δ _ _ _ ≫= μ_natural L (adj.unit.app d) (adj.unit.app d') rw [δ_μ_assoc] at this rw [← this] infer_instance instance (c : C) (d : D) : IsIso (adj.unit.app ((ihom d).obj (R.obj c))) := by revert c d rw [((isIso_tfae adj).out 0 3:)] intro d d' infer_instance /-- Auxiliary definition for `monoidalClosed`. -/ noncomputable def closed (c : C) : Closed c where rightAdj := R ⋙ (ihom (R.obj c)) ⋙ L adj := by refine ((ihom.adjunction (R.obj c)).comp adj).restrictFullyFaithful (FullyFaithful.ofFullyFaithful R) (FullyFaithful.id _) ?_ ?_ · refine NatIso.ofComponents (fun _ ↦ (μIso L _ _).symm ≪≫ asIso ((adj.counit.app _) ⊗ₘ (adj.counit.app _))) (fun _ ↦ ?_) dsimp rw [Category.assoc, ← δ_natural_right_assoc, tensorHom_def', ← MonoidalCategory.whiskerLeft_comp_assoc, Adjunction.counit_naturality, whisker_exchange, tensorHom_def_assoc, MonoidalCategory.whiskerLeft_comp] · exact NatIso.ofComponents (fun _ ↦ asIso (adj.unit.app ((ihom _).obj _))) /-- Given a reflective functor `R : C ⥤ D` with a monoidal left adjoint, such that `D` is symmetric monoidal closed, then `C` is monoidal closed. -/ noncomputable def monoidalClosed : MonoidalClosed C where closed c := closed adj c end end CategoryTheory.Monoidal.Reflective
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Braided/Basic.lean
import Mathlib.CategoryTheory.Monoidal.Discrete import Mathlib.CategoryTheory.Monoidal.NaturalTransformation import Mathlib.CategoryTheory.Monoidal.Opposite import Mathlib.Tactic.CategoryTheory.Monoidal.Basic import Mathlib.CategoryTheory.CommSq /-! # Braided and symmetric monoidal categories The basic definitions of braided monoidal categories, and symmetric monoidal categories, as well as braided functors. ## Implementation note We make `BraidedCategory` another typeclass, but then have `SymmetricCategory` extend this. The rationale is that we are not carrying any additional data, just requiring a property. ## Future work * Construct the Drinfeld center of a monoidal category as a braided monoidal category. * Say something about pseudo-natural transformations. ## References * [Pavel Etingof, Shlomo Gelaki, Dmitri Nikshych, Victor Ostrik, *Tensor categories*][egno15] -/ universe v v₁ v₂ v₃ u u₁ u₂ u₃ namespace CategoryTheory open Category MonoidalCategory Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal /-- A braided monoidal category is a monoidal category equipped with a braiding isomorphism `β_ X Y : X ⊗ Y ≅ Y ⊗ X` which is natural in both arguments, and also satisfies the two hexagon identities. -/ class BraidedCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] where /-- The braiding natural isomorphism. -/ braiding : ∀ X Y : C, X ⊗ Y ≅ Y ⊗ X braiding_naturality_right : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), X ◁ f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ f ▷ X := by cat_disch braiding_naturality_left : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ▷ Z ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ Z ◁ f := by cat_disch /-- The first hexagon identity. -/ hexagon_forward : ∀ X Y Z : C, (α_ X Y Z).hom ≫ (braiding X (Y ⊗ Z)).hom ≫ (α_ Y Z X).hom = ((braiding X Y).hom ▷ Z) ≫ (α_ Y X Z).hom ≫ (Y ◁ (braiding X Z).hom) := by cat_disch /-- The second hexagon identity. -/ hexagon_reverse : ∀ X Y Z : C, (α_ X Y Z).inv ≫ (braiding (X ⊗ Y) Z).hom ≫ (α_ Z X Y).inv = (X ◁ (braiding Y Z).hom) ≫ (α_ X Z Y).inv ≫ ((braiding X Z).hom ▷ Y) := by cat_disch attribute [reassoc (attr := simp)] BraidedCategory.braiding_naturality_left BraidedCategory.braiding_naturality_right attribute [reassoc] BraidedCategory.hexagon_forward BraidedCategory.hexagon_reverse open BraidedCategory @[inherit_doc] notation "β_" => BraidedCategory.braiding namespace BraidedCategory variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] [BraidedCategory.{v} C] @[simp, reassoc] theorem braiding_tensor_left_hom (X Y Z : C) : (β_ (X ⊗ Y) Z).hom = (α_ X Y Z).hom ≫ X ◁ (β_ Y Z).hom ≫ (α_ X Z Y).inv ≫ (β_ X Z).hom ▷ Y ≫ (α_ Z X Y).hom := by apply (cancel_epi (α_ X Y Z).inv).1 apply (cancel_mono (α_ Z X Y).inv).1 simp [hexagon_reverse] @[deprecated (since := "2025-06-24")] alias braiding_tensor_left := braiding_tensor_left_hom @[simp, reassoc] theorem braiding_tensor_right_hom (X Y Z : C) : (β_ X (Y ⊗ Z)).hom = (α_ X Y Z).inv ≫ (β_ X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫ Y ◁ (β_ X Z).hom ≫ (α_ Y Z X).inv := by apply (cancel_epi (α_ X Y Z).hom).1 apply (cancel_mono (α_ Y Z X).hom).1 simp [hexagon_forward] @[deprecated (since := "2025-06-24")] alias braiding_tensor_right := braiding_tensor_right_hom @[simp, reassoc] theorem braiding_tensor_left_inv (X Y Z : C) : (β_ (X ⊗ Y) Z).inv = (α_ Z X Y).inv ≫ (β_ X Z).inv ▷ Y ≫ (α_ X Z Y).hom ≫ X ◁ (β_ Y Z).inv ≫ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[deprecated (since := "2025-06-24")] alias braiding_inv_tensor_left := braiding_tensor_left_inv @[simp, reassoc] theorem braiding_tensor_right_inv (X Y Z : C) : (β_ X (Y ⊗ Z)).inv = (α_ Y Z X).hom ≫ Y ◁ (β_ X Z).inv ≫ (α_ Y X Z).inv ≫ (β_ X Y).inv ▷ Z ≫ (α_ X Y Z).hom := eq_of_inv_eq_inv (by simp) @[deprecated (since := "2025-06-24")] alias braiding_inv_tensor_right := braiding_tensor_right_inv @[reassoc (attr := simp)] theorem braiding_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (f ⊗ₘ g) ≫ (braiding Y Y').hom = (braiding X X').hom ≫ (g ⊗ₘ f) := by rw [tensorHom_def' f g, tensorHom_def g f] simp_rw [Category.assoc, braiding_naturality_left, braiding_naturality_right_assoc] @[reassoc (attr := simp)] theorem braiding_inv_naturality_right (X : C) {Y Z : C} (f : Y ⟶ Z) : X ◁ f ≫ (β_ Z X).inv = (β_ Y X).inv ≫ f ▷ X := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_left f X @[reassoc (attr := simp)] theorem braiding_inv_naturality_left {X Y : C} (f : X ⟶ Y) (Z : C) : f ▷ Z ≫ (β_ Z Y).inv = (β_ Z X).inv ≫ Z ◁ f := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_right Z f @[reassoc (attr := simp)] theorem braiding_inv_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (f ⊗ₘ g) ≫ (β_ Y' Y).inv = (β_ X' X).inv ≫ (g ⊗ₘ f) := CommSq.w <| .vert_inv <| .mk <| braiding_naturality g f /-- In a braided monoidal category, the functors `tensorLeft X` and `tensorRight X` are isomorphic. -/ @[simps] def tensorLeftIsoTensorRight (X : C) : tensorLeft X ≅ tensorRight X where hom := { app Y := (β_ X Y).hom } inv := { app Y := (β_ X Y).inv } variable (C) in /-- The braiding isomorphism as a natural isomorphism of bifunctors `C ⥤ C ⥤ C`. -/ @[simps!] def curriedBraidingNatIso : curriedTensor C ≅ (curriedTensor C).flip := NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun Y ↦ β_ X Y)) @[reassoc] theorem yang_baxter (X Y Z : C) : (α_ X Y Z).inv ≫ (β_ X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫ Y ◁ (β_ X Z).hom ≫ (α_ Y Z X).inv ≫ (β_ Y Z).hom ▷ X ≫ (α_ Z Y X).hom = X ◁ (β_ Y Z).hom ≫ (α_ X Z Y).inv ≫ (β_ X Z).hom ▷ Y ≫ (α_ Z X Y).hom ≫ Z ◁ (β_ X Y).hom := by rw [← braiding_tensor_right_hom_assoc X Y Z, ← cancel_mono (α_ Z Y X).inv] repeat rw [assoc] rw [Iso.hom_inv_id, comp_id, ← braiding_naturality_right, braiding_tensor_right_hom] theorem yang_baxter' (X Y Z : C) : (β_ X Y).hom ▷ Z ⊗≫ Y ◁ (β_ X Z).hom ⊗≫ (β_ Y Z).hom ▷ X = 𝟙 _ ⊗≫ (X ◁ (β_ Y Z).hom ⊗≫ (β_ X Z).hom ▷ Y ⊗≫ Z ◁ (β_ X Y).hom) ⊗≫ 𝟙 _ := by rw [← cancel_epi (α_ X Y Z).inv, ← cancel_mono (α_ Z Y X).hom] convert yang_baxter X Y Z using 1 all_goals monoidal theorem yang_baxter_iso (X Y Z : C) : (α_ X Y Z).symm ≪≫ whiskerRightIso (β_ X Y) Z ≪≫ α_ Y X Z ≪≫ whiskerLeftIso Y (β_ X Z) ≪≫ (α_ Y Z X).symm ≪≫ whiskerRightIso (β_ Y Z) X ≪≫ (α_ Z Y X) = whiskerLeftIso X (β_ Y Z) ≪≫ (α_ X Z Y).symm ≪≫ whiskerRightIso (β_ X Z) Y ≪≫ α_ Z X Y ≪≫ whiskerLeftIso Z (β_ X Y) := Iso.ext (yang_baxter X Y Z) theorem hexagon_forward_iso (X Y Z : C) : α_ X Y Z ≪≫ β_ X (Y ⊗ Z) ≪≫ α_ Y Z X = whiskerRightIso (β_ X Y) Z ≪≫ α_ Y X Z ≪≫ whiskerLeftIso Y (β_ X Z) := Iso.ext (hexagon_forward X Y Z) theorem hexagon_reverse_iso (X Y Z : C) : (α_ X Y Z).symm ≪≫ β_ (X ⊗ Y) Z ≪≫ (α_ Z X Y).symm = whiskerLeftIso X (β_ Y Z) ≪≫ (α_ X Z Y).symm ≪≫ whiskerRightIso (β_ X Z) Y := Iso.ext (hexagon_reverse X Y Z) @[reassoc] theorem hexagon_forward_inv (X Y Z : C) : (α_ Y Z X).inv ≫ (β_ X (Y ⊗ Z)).inv ≫ (α_ X Y Z).inv = Y ◁ (β_ X Z).inv ≫ (α_ Y X Z).inv ≫ (β_ X Y).inv ▷ Z := by simp @[reassoc] theorem hexagon_reverse_inv (X Y Z : C) : (α_ Z X Y).hom ≫ (β_ (X ⊗ Y) Z).inv ≫ (α_ X Y Z).hom = (β_ X Z).inv ▷ Y ≫ (α_ X Z Y).hom ≫ X ◁ (β_ Y Z).inv := by simp end BraidedCategory -- FIXME: `reassoc_of%` should unfold `autoParam`. /-- Verifying the axioms for a braiding by checking that the candidate braiding is sent to a braiding by a faithful monoidal functor. -/ def BraidedCategory.ofFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] (F : C ⥤ D) [F.Monoidal] [F.Faithful] [BraidedCategory D] (β : ∀ X Y : C, X ⊗ Y ≅ Y ⊗ X) (w : ∀ X Y, μ F _ _ ≫ F.map (β X Y).hom = (β_ _ _).hom ≫ μ F _ _ := by cat_disch) : BraidedCategory C where braiding := β braiding_naturality_left := by intros apply F.map_injective refine (cancel_epi (μ F ?_ ?_)).1 ?_ rw [Functor.map_comp, ← μ_natural_left_assoc, w, Functor.map_comp, reassoc_of% w, braiding_naturality_left_assoc, μ_natural_right] braiding_naturality_right := by intros apply F.map_injective refine (cancel_epi (μ F ?_ ?_)).1 ?_ rw [Functor.map_comp, ← μ_natural_right_assoc, w, Functor.map_comp, reassoc_of% w, braiding_naturality_right_assoc, μ_natural_left] hexagon_forward := by intros apply F.map_injective refine (cancel_epi (μ F _ _)).1 ?_ refine (cancel_epi (μ F _ _ ▷ _)).1 ?_ rw [Functor.map_comp, Functor.map_comp, Functor.map_comp, Functor.map_comp, ← μ_natural_left_assoc, ← comp_whiskerRight_assoc, w, comp_whiskerRight_assoc, Functor.LaxMonoidal.associativity_assoc, Functor.LaxMonoidal.associativity_assoc, ← μ_natural_right, ← whiskerLeft_comp_assoc, w, whiskerLeft_comp_assoc, reassoc_of% w, braiding_naturality_right_assoc, Functor.LaxMonoidal.associativity, hexagon_forward_assoc] hexagon_reverse := by intros apply F.map_injective refine (cancel_epi (μ F _ _)).1 ?_ refine (cancel_epi (_ ◁ μ F _ _)).1 ?_ rw [Functor.map_comp, Functor.map_comp, Functor.map_comp, Functor.map_comp, ← μ_natural_right_assoc, ← whiskerLeft_comp_assoc, w, whiskerLeft_comp_assoc, Functor.LaxMonoidal.associativity_inv_assoc, Functor.LaxMonoidal.associativity_inv_assoc, ← μ_natural_left, ← comp_whiskerRight_assoc, w, comp_whiskerRight_assoc, reassoc_of% w, braiding_naturality_left_assoc, Functor.LaxMonoidal.associativity_inv, hexagon_reverse_assoc] @[deprecated (since := "2025-07-12")] alias braidedCategoryOfFaithful := BraidedCategory.ofFaithful /-- Pull back a braiding along a fully faithful monoidal functor. -/ noncomputable def BraidedCategory.ofFullyFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] (F : C ⥤ D) [F.Monoidal] [F.Full] [F.Faithful] [BraidedCategory D] : BraidedCategory C := .ofFaithful F fun X Y ↦ F.preimageIso ((μIso F _ _).symm ≪≫ β_ (F.obj X) (F.obj Y) ≪≫ μIso F _ _) @[deprecated (since := "2025-07-12")] alias braidedCategoryOfFullyFaithful := BraidedCategory.ofFullyFaithful section /-! We now establish how the braiding interacts with the unitors. I couldn't find a detailed proof in print, but this is discussed in: * Proposition 1 of André Joyal and Ross Street, "Braided monoidal categories", Macquarie Math Reports 860081 (1986). * Proposition 2.1 of André Joyal and Ross Street, "Braided tensor categories", Adv. Math. 102 (1993), 20–78. * Exercise 8.1.6 of Etingof, Gelaki, Nikshych, Ostrik, "Tensor categories", vol 25, Mathematical Surveys and Monographs (2015), AMS. -/ variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [BraidedCategory C] theorem braiding_leftUnitor_aux₁ (X : C) : (α_ (𝟙_ C) (𝟙_ C) X).hom ≫ (𝟙_ C ◁ (β_ X (𝟙_ C)).inv) ≫ (α_ _ X _).inv ≫ ((λ_ X).hom ▷ _) = ((λ_ _).hom ▷ X) ≫ (β_ X (𝟙_ C)).inv := by monoidal theorem braiding_leftUnitor_aux₂ (X : C) : ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ ((λ_ X).hom ▷ 𝟙_ C) = (ρ_ X).hom ▷ 𝟙_ C := calc ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ ((λ_ X).hom ▷ 𝟙_ C) = ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ (α_ _ _ _).hom ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ▷ 𝟙_ C) := by simp _ = ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ (α_ _ _ _).hom ≫ (_ ◁ (β_ X _).hom) ≫ (_ ◁ (β_ X _).inv) ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ▷ 𝟙_ C) := by simp _ = (α_ _ _ _).hom ≫ (β_ _ _).hom ≫ (α_ _ _ _).hom ≫ (_ ◁ (β_ X _).inv) ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ▷ 𝟙_ C) := by simp _ = (α_ _ _ _).hom ≫ (β_ _ _).hom ≫ ((λ_ _).hom ▷ X) ≫ (β_ X _).inv := by rw [braiding_leftUnitor_aux₁] _ = (α_ _ _ _).hom ≫ (_ ◁ (λ_ _).hom) ≫ (β_ _ _).hom ≫ (β_ X _).inv := by (slice_lhs 2 3 => rw [← braiding_naturality_right]); simp only [assoc] _ = (α_ _ _ _).hom ≫ (_ ◁ (λ_ _).hom) := by rw [Iso.hom_inv_id, comp_id] _ = (ρ_ X).hom ▷ 𝟙_ C := by rw [triangle] @[reassoc] theorem braiding_leftUnitor (X : C) : (β_ X (𝟙_ C)).hom ≫ (λ_ X).hom = (ρ_ X).hom := by rw [← whiskerRight_iff, comp_whiskerRight, braiding_leftUnitor_aux₂] theorem braiding_rightUnitor_aux₁ (X : C) : (α_ X (𝟙_ C) (𝟙_ C)).inv ≫ ((β_ (𝟙_ C) X).inv ▷ 𝟙_ C) ≫ (α_ _ X _).hom ≫ (_ ◁ (ρ_ X).hom) = (X ◁ (ρ_ _).hom) ≫ (β_ (𝟙_ C) X).inv := by simp theorem braiding_rightUnitor_aux₂ (X : C) : (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (𝟙_ C ◁ (ρ_ X).hom) = 𝟙_ C ◁ (λ_ X).hom := calc (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (𝟙_ C ◁ (ρ_ X).hom) = (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (α_ _ _ _).inv ≫ (α_ _ _ _).hom ≫ (𝟙_ C ◁ (ρ_ X).hom) := by simp _ = (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (α_ _ _ _).inv ≫ ((β_ _ X).hom ▷ _) ≫ ((β_ _ X).inv ▷ _) ≫ (α_ _ _ _).hom ≫ (𝟙_ C ◁ (ρ_ X).hom) := by simp _ = (α_ _ _ _).inv ≫ (β_ _ _).hom ≫ (α_ _ _ _).inv ≫ ((β_ _ X).inv ▷ _) ≫ (α_ _ _ _).hom ≫ (𝟙_ C ◁ (ρ_ X).hom) := by (slice_lhs 1 3 => rw [← hexagon_reverse]); simp only [assoc] _ = (α_ _ _ _).inv ≫ (β_ _ _).hom ≫ (X ◁ (ρ_ _).hom) ≫ (β_ _ X).inv := by simp _ = (α_ _ _ _).inv ≫ ((ρ_ _).hom ▷ _) ≫ (β_ _ X).hom ≫ (β_ _ _).inv := by (slice_lhs 2 3 => rw [← braiding_naturality_left]); simp only [assoc] _ = (α_ _ _ _).inv ≫ ((ρ_ _).hom ▷ _) := by rw [Iso.hom_inv_id, comp_id] _ = 𝟙_ C ◁ (λ_ X).hom := by rw [triangle_assoc_comp_right] @[reassoc] theorem braiding_rightUnitor (X : C) : (β_ (𝟙_ C) X).hom ≫ (ρ_ X).hom = (λ_ X).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, braiding_rightUnitor_aux₂] @[reassoc, simp] theorem braiding_tensorUnit_left (X : C) : (β_ (𝟙_ C) X).hom = (λ_ X).hom ≫ (ρ_ X).inv := by simp [← braiding_rightUnitor] @[reassoc, simp] theorem braiding_inv_tensorUnit_left (X : C) : (β_ (𝟙_ C) X).inv = (ρ_ X).hom ≫ (λ_ X).inv := by rw [Iso.inv_ext] rw [braiding_tensorUnit_left] monoidal @[reassoc] theorem leftUnitor_inv_braiding (X : C) : (λ_ X).inv ≫ (β_ (𝟙_ C) X).hom = (ρ_ X).inv := by simp @[reassoc] theorem rightUnitor_inv_braiding (X : C) : (ρ_ X).inv ≫ (β_ X (𝟙_ C)).hom = (λ_ X).inv := by apply (cancel_mono (λ_ X).hom).1 simp only [assoc, braiding_leftUnitor, Iso.inv_hom_id] @[reassoc, simp] theorem braiding_tensorUnit_right (X : C) : (β_ X (𝟙_ C)).hom = (ρ_ X).hom ≫ (λ_ X).inv := by simp [← rightUnitor_inv_braiding] @[reassoc, simp] theorem braiding_inv_tensorUnit_right (X : C) : (β_ X (𝟙_ C)).inv = (λ_ X).hom ≫ (ρ_ X).inv := by rw [Iso.inv_ext] rw [braiding_tensorUnit_right] monoidal end /-- A symmetric monoidal category is a braided monoidal category for which the braiding is symmetric. -/ @[stacks 0FFW] class SymmetricCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] extends BraidedCategory.{v} C where -- braiding symmetric: symmetry : ∀ X Y : C, (β_ X Y).hom ≫ (β_ Y X).hom = 𝟙 (X ⊗ Y) := by cat_disch attribute [reassoc (attr := simp)] SymmetricCategory.symmetry lemma SymmetricCategory.braiding_swap_eq_inv_braiding {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [SymmetricCategory C] (X Y : C) : (β_ Y X).hom = (β_ X Y).inv := Iso.inv_ext' (symmetry X Y) variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [BraidedCategory C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory D] [BraidedCategory D] variable {E : Type u₃} [Category.{v₃} E] [MonoidalCategory E] [BraidedCategory E] /-- A lax braided functor between braided monoidal categories is a lax monoidal functor which preserves the braiding. -/ class Functor.LaxBraided (F : C ⥤ D) extends F.LaxMonoidal where braided : ∀ X Y : C, μ X Y ≫ F.map (β_ X Y).hom = (β_ (F.obj X) (F.obj Y)).hom ≫ μ Y X := by cat_disch namespace Functor.LaxBraided attribute [reassoc] braided instance id : (𝟭 C).LaxBraided where instance (F : C ⥤ D) (G : D ⥤ E) [F.LaxBraided] [G.LaxBraided] : (F ⋙ G).LaxBraided where braided X Y := by dsimp slice_lhs 2 3 => rw [← CategoryTheory.Functor.map_comp, braided, CategoryTheory.Functor.map_comp] slice_lhs 1 2 => rw [braided] simp only [Category.assoc] /-- Given two lax monoidal, monoidally isomorphic functors, if one is lax braided, so is the other. -/ def ofNatIso {F G : C ⥤ D} (i : F ≅ G) [F.LaxBraided] [G.LaxMonoidal] [NatTrans.IsMonoidal i.hom] : G.LaxBraided where braided X Y := by have (X Y : C) : μ G X Y = (i.inv.app X ⊗ₘ i.inv.app Y) ≫ μ F X Y ≫ i.hom.app _ := by simp [NatTrans.IsMonoidal.tensor X Y, tensorHom_comp_tensorHom_assoc] rw [this X Y, this Y X, ← braiding_naturality_assoc, ← Functor.LaxBraided.braided_assoc] simp end Functor.LaxBraided section variable (C D) /-- Bundled version of lax braided functors. -/ structure LaxBraidedFunctor extends C ⥤ D where laxBraided : toFunctor.LaxBraided := by infer_instance namespace LaxBraidedFunctor variable {C D} attribute [instance] laxBraided /-- Constructor for `LaxBraidedFunctor C D`. -/ @[simps toFunctor] def of (F : C ⥤ D) [F.LaxBraided] : LaxBraidedFunctor C D where toFunctor := F /-- The lax monoidal functor induced by a lax braided functor. -/ @[simps toFunctor] def toLaxMonoidalFunctor (F : LaxBraidedFunctor C D) : LaxMonoidalFunctor C D where toFunctor := F.toFunctor instance : Category (LaxBraidedFunctor C D) := InducedCategory.category (toLaxMonoidalFunctor) @[simp] lemma id_hom (F : LaxBraidedFunctor C D) : LaxMonoidalFunctor.Hom.hom (𝟙 F) = 𝟙 _ := rfl @[reassoc, simp] lemma comp_hom {F G H : LaxBraidedFunctor C D} (α : F ⟶ G) (β : G ⟶ H) : (α ≫ β).hom = α.hom ≫ β.hom := rfl @[ext] lemma hom_ext {F G : LaxBraidedFunctor C D} {α β : F ⟶ G} (h : α.hom = β.hom) : α = β := LaxMonoidalFunctor.hom_ext h /-- Constructor for morphisms in the category `LaxBraiededFunctor C D`. -/ @[simps] def homMk {F G : LaxBraidedFunctor C D} (f : F.toFunctor ⟶ G.toFunctor) [NatTrans.IsMonoidal f] : F ⟶ G := ⟨f, inferInstance⟩ /-- Constructor for isomorphisms in the category `LaxBraidedFunctor C D`. -/ @[simps] def isoMk {F G : LaxBraidedFunctor C D} (e : F.toFunctor ≅ G.toFunctor) [NatTrans.IsMonoidal e.hom] : F ≅ G where hom := homMk e.hom inv := homMk e.inv /-- The forgetful functor from lax braided functors to lax monoidal functors. -/ @[simps! obj map] def forget : LaxBraidedFunctor C D ⥤ LaxMonoidalFunctor C D := inducedFunctor _ /-- The forgetful functor from lax braided functors to lax monoidal functors is fully faithful. -/ def fullyFaithfulForget : (forget (C := C) (D := D)).FullyFaithful := fullyFaithfulInducedFunctor _ section variable {F G : LaxBraidedFunctor C D} (e : ∀ X, F.obj X ≅ G.obj X) (naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (e Y).hom = (e X).hom ≫ G.map f := by cat_disch) (unit : ε F.toFunctor ≫ (e (𝟙_ C)).hom = ε G.toFunctor := by cat_disch) (tensor : ∀ X Y, μ F.toFunctor X Y ≫ (e (X ⊗ Y)).hom = ((e X).hom ⊗ₘ (e Y).hom) ≫ μ G.toFunctor X Y := by cat_disch) /-- Constructor for isomorphisms between lax braided functors. -/ def isoOfComponents : F ≅ G := fullyFaithfulForget.preimageIso (LaxMonoidalFunctor.isoOfComponents e naturality unit tensor) @[simp] lemma isoOfComponents_hom_hom_app (X : C) : (isoOfComponents e naturality unit tensor).hom.hom.app X = (e X).hom := rfl @[simp] lemma isoOfComponents_inv_hom_app (X : C) : (isoOfComponents e naturality unit tensor).inv.hom.app X = (e X).inv := rfl end end LaxBraidedFunctor end /-- A braided functor between braided monoidal categories is a monoidal functor which preserves the braiding. -/ @[ext] class Functor.Braided (F : C ⥤ D) extends F.Monoidal, F.LaxBraided where @[simp, reassoc] lemma Functor.map_braiding (F : C ⥤ D) (X Y : C) [F.Braided] : F.map (β_ X Y).hom = δ F X Y ≫ (β_ (F.obj X) (F.obj Y)).hom ≫ μ F Y X := by rw [← Functor.Braided.braided, δ_μ_assoc] /-- A braided category with a faithful braided functor to a symmetric category is itself symmetric. -/ def SymmetricCategory.ofFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] [BraidedCategory C] [SymmetricCategory D] (F : C ⥤ D) [F.Braided] [F.Faithful] : SymmetricCategory C where symmetry X Y := F.map_injective (by simp) /-- Pull back a symmetric braiding along a fully faithful monoidal functor. -/ noncomputable def SymmetricCategory.ofFullyFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] (F : C ⥤ D) [F.Monoidal] [F.Full] [F.Faithful] [SymmetricCategory D] : SymmetricCategory C := let h : BraidedCategory C := BraidedCategory.ofFullyFaithful F let _ : F.Braided := { braided X Y := by simp [h, BraidedCategory.ofFullyFaithful, BraidedCategory.ofFaithful] } .ofFaithful F @[deprecated (since := "2025-10-17")] alias symmetricCategoryOfFaithful := SymmetricCategory.ofFaithful @[deprecated (since := "2025-10-17")] alias symmetricCategoryOfFullyFaithful := SymmetricCategory.ofFullyFaithful namespace Functor.Braided instance : (𝟭 C).Braided where instance (F : C ⥤ D) (G : D ⥤ E) [F.Braided] [G.Braided] : (F ⋙ G).Braided where lemma toMonoidal_injective (F : C ⥤ D) : Function.Injective (@Braided.toMonoidal _ _ _ _ _ _ _ _ _ : F.Braided → F.Monoidal) := by rintro ⟨⟩ ⟨⟩ rfl; rfl end Functor.Braided section CommMonoid variable (M : Type u) [CommMonoid M] instance : BraidedCategory (Discrete M) where braiding X Y := Discrete.eqToIso (mul_comm X.as Y.as) variable {M} {N : Type u} [CommMonoid N] /-- A multiplicative morphism between commutative monoids gives a braided functor between the corresponding discrete braided monoidal categories. -/ instance Discrete.monoidalFunctorBraided (F : M →* N) : (Discrete.monoidalFunctor F).Braided where end CommMonoid namespace MonoidalCategory section Tensor /-- Swap the second and third objects in `(X₁ ⊗ X₂) ⊗ (Y₁ ⊗ Y₂)`. This is used to strength the tensor product functor from `C × C` to `C` as a monoidal functor. -/ def tensorμ (X₁ X₂ Y₁ Y₂ : C) : (X₁ ⊗ X₂) ⊗ Y₁ ⊗ Y₂ ⟶ (X₁ ⊗ Y₁) ⊗ X₂ ⊗ Y₂ := (α_ X₁ X₂ (Y₁ ⊗ Y₂)).hom ≫ (X₁ ◁ (α_ X₂ Y₁ Y₂).inv) ≫ (X₁ ◁ (β_ X₂ Y₁).hom ▷ Y₂) ≫ (X₁ ◁ (α_ Y₁ X₂ Y₂).hom) ≫ (α_ X₁ Y₁ (X₂ ⊗ Y₂)).inv /-- The inverse of `tensorμ`. -/ def tensorδ (X₁ X₂ Y₁ Y₂ : C) : (X₁ ⊗ Y₁) ⊗ X₂ ⊗ Y₂ ⟶ (X₁ ⊗ X₂) ⊗ Y₁ ⊗ Y₂ := (α_ X₁ Y₁ (X₂ ⊗ Y₂)).hom ≫ (X₁ ◁ (α_ Y₁ X₂ Y₂).inv) ≫ (X₁ ◁ (β_ X₂ Y₁).inv ▷ Y₂) ≫ (X₁ ◁ (α_ X₂ Y₁ Y₂).hom) ≫ (α_ X₁ X₂ (Y₁ ⊗ Y₂)).inv @[reassoc (attr := simp)] lemma tensorμ_tensorδ (X₁ X₂ Y₁ Y₂ : C) : tensorμ X₁ X₂ Y₁ Y₂ ≫ tensorδ X₁ X₂ Y₁ Y₂ = 𝟙 _ := by simp only [tensorμ, ← whiskerLeft_comp_assoc, tensorδ, assoc, Iso.inv_hom_id_assoc, Iso.hom_inv_id_assoc, hom_inv_whiskerRight_assoc, Iso.inv_hom_id, whiskerLeft_id, id_comp, Iso.hom_inv_id] @[reassoc (attr := simp)] lemma tensorδ_tensorμ (X₁ X₂ Y₁ Y₂ : C) : tensorδ X₁ X₂ Y₁ Y₂ ≫ tensorμ X₁ X₂ Y₁ Y₂ = 𝟙 _ := by simp only [tensorδ, ← whiskerLeft_comp_assoc, tensorμ, assoc, Iso.inv_hom_id_assoc, Iso.hom_inv_id_assoc, inv_hom_whiskerRight_assoc, Iso.inv_hom_id, whiskerLeft_id, id_comp, Iso.hom_inv_id] @[reassoc] theorem tensorμ_natural {X₁ X₂ Y₁ Y₂ U₁ U₂ V₁ V₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : U₁ ⟶ V₁) (g₂ : U₂ ⟶ V₂) : ((f₁ ⊗ₘ f₂) ⊗ₘ g₁ ⊗ₘ g₂) ≫ tensorμ Y₁ Y₂ V₁ V₂ = tensorμ X₁ X₂ U₁ U₂ ≫ ((f₁ ⊗ₘ g₁) ⊗ₘ f₂ ⊗ₘ g₂) := by dsimp only [tensorμ] simp_rw [← id_tensorHom, ← tensorHom_id] slice_lhs 1 2 => rw [associator_naturality] slice_lhs 2 3 => rw [tensorHom_comp_tensorHom, comp_id f₁, ← id_comp f₁, associator_inv_naturality, ← tensorHom_comp_tensorHom] slice_lhs 3 4 => rw [tensorHom_comp_tensorHom, tensorHom_comp_tensorHom, comp_id f₁, ← id_comp f₁, comp_id g₂, ← id_comp g₂, braiding_naturality, ← tensorHom_comp_tensorHom, ← tensorHom_comp_tensorHom] slice_lhs 4 5 => rw [tensorHom_comp_tensorHom, comp_id f₁, ← id_comp f₁, associator_naturality, ← tensorHom_comp_tensorHom] slice_lhs 5 6 => rw [associator_inv_naturality] simp only [assoc] @[reassoc] theorem tensorμ_natural_left {X₁ X₂ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (Z₁ Z₂ : C) : (f₁ ⊗ₘ f₂) ▷ (Z₁ ⊗ Z₂) ≫ tensorμ Y₁ Y₂ Z₁ Z₂ = tensorμ X₁ X₂ Z₁ Z₂ ≫ (f₁ ▷ Z₁ ⊗ₘ f₂ ▷ Z₂) := by convert tensorμ_natural f₁ f₂ (𝟙 Z₁) (𝟙 Z₂) using 1 <;> simp @[reassoc] theorem tensorμ_natural_right (Z₁ Z₂ : C) {X₁ X₂ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) : (Z₁ ⊗ Z₂) ◁ (f₁ ⊗ₘ f₂) ≫ tensorμ Z₁ Z₂ Y₁ Y₂ = tensorμ Z₁ Z₂ X₁ X₂ ≫ (Z₁ ◁ f₁ ⊗ₘ Z₂ ◁ f₂) := by convert tensorμ_natural (𝟙 Z₁) (𝟙 Z₂) f₁ f₂ using 1 <;> simp @[reassoc] theorem tensor_left_unitality (X₁ X₂ : C) : (λ_ (X₁ ⊗ X₂)).hom = ((λ_ (𝟙_ C)).inv ▷ (X₁ ⊗ X₂)) ≫ tensorμ (𝟙_ C) (𝟙_ C) X₁ X₂ ≫ ((λ_ X₁).hom ⊗ₘ (λ_ X₂).hom) := by dsimp only [tensorμ] have : ((λ_ (𝟙_ C)).inv ▷ (X₁ ⊗ X₂)) ≫ (α_ (𝟙_ C) (𝟙_ C) (X₁ ⊗ X₂)).hom ≫ (𝟙_ C ◁ (α_ (𝟙_ C) X₁ X₂).inv) = 𝟙_ C ◁ (λ_ X₁).inv ▷ X₂ := by simp slice_rhs 1 3 => rw [this] clear this slice_rhs 1 2 => rw [← whiskerLeft_comp, ← comp_whiskerRight, leftUnitor_inv_braiding] simp [tensorHom_def] @[reassoc] theorem tensor_right_unitality (X₁ X₂ : C) : (ρ_ (X₁ ⊗ X₂)).hom = ((X₁ ⊗ X₂) ◁ (λ_ (𝟙_ C)).inv) ≫ tensorμ X₁ X₂ (𝟙_ C) (𝟙_ C) ≫ ((ρ_ X₁).hom ⊗ₘ (ρ_ X₂).hom) := by dsimp only [tensorμ] have : ((X₁ ⊗ X₂) ◁ (λ_ (𝟙_ C)).inv) ≫ (α_ X₁ X₂ (𝟙_ C ⊗ 𝟙_ C)).hom ≫ (X₁ ◁ (α_ X₂ (𝟙_ C) (𝟙_ C)).inv) = (α_ X₁ X₂ (𝟙_ C)).hom ≫ (X₁ ◁ (ρ_ X₂).inv ▷ 𝟙_ C) := by monoidal slice_rhs 1 3 => rw [this] clear this slice_rhs 2 3 => rw [← whiskerLeft_comp, ← comp_whiskerRight, rightUnitor_inv_braiding] simp [tensorHom_def] @[reassoc] theorem tensor_associativity (X₁ X₂ Y₁ Y₂ Z₁ Z₂ : C) : (tensorμ X₁ X₂ Y₁ Y₂ ▷ (Z₁ ⊗ Z₂)) ≫ tensorμ (X₁ ⊗ Y₁) (X₂ ⊗ Y₂) Z₁ Z₂ ≫ ((α_ X₁ Y₁ Z₁).hom ⊗ₘ (α_ X₂ Y₂ Z₂).hom) = (α_ (X₁ ⊗ X₂) (Y₁ ⊗ Y₂) (Z₁ ⊗ Z₂)).hom ≫ ((X₁ ⊗ X₂) ◁ tensorμ Y₁ Y₂ Z₁ Z₂) ≫ tensorμ X₁ X₂ (Y₁ ⊗ Z₁) (Y₂ ⊗ Z₂) := by dsimp only [tensor_obj, prodMonoidal_tensorObj, tensorμ] simp only [braiding_tensor_left_hom, braiding_tensor_right_hom] calc _ = 𝟙 _ ⊗≫ X₁ ◁ ((β_ X₂ Y₁).hom ▷ (Y₂ ⊗ Z₁) ≫ (Y₁ ⊗ X₂) ◁ (β_ Y₂ Z₁).hom) ▷ Z₂ ⊗≫ X₁ ◁ Y₁ ◁ (β_ X₂ Z₁).hom ▷ Y₂ ▷ Z₂ ⊗≫ 𝟙 _ := by monoidal _ = _ := by rw [← whisker_exchange]; monoidal instance tensorMonoidal : (tensor C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := (λ_ (𝟙_ C)).symm μIso := fun X Y ↦ { hom := tensorμ X.1 X.2 Y.1 Y.2 inv := tensorδ X.1 X.2 Y.1 Y.2 } μIso_hom_natural_left := fun f Z ↦ tensorμ_natural_left f.1 f.2 Z.1 Z.2 μIso_hom_natural_right := fun Z f ↦ tensorμ_natural_right Z.1 Z.2 f.1 f.2 associativity := fun X Y Z ↦ tensor_associativity X.1 X.2 Y.1 Y.2 Z.1 Z.2 left_unitality := fun ⟨X₁, X₂⟩ ↦ tensor_left_unitality X₁ X₂ right_unitality := fun ⟨X₁, X₂⟩ ↦ tensor_right_unitality X₁ X₂ } @[simp] lemma tensor_ε : ε (tensor C) = (λ_ (𝟙_ C)).inv := rfl @[simp] lemma tensor_η : η (tensor C) = (λ_ (𝟙_ C)).hom := rfl @[simp] lemma tensor_μ (X Y : C × C) : μ (tensor C) X Y = tensorμ X.1 X.2 Y.1 Y.2 := rfl @[simp] lemma tensor_δ (X Y : C × C) : δ (tensor C) X Y = tensorδ X.1 X.2 Y.1 Y.2 := rfl @[reassoc] theorem leftUnitor_monoidal (X₁ X₂ : C) : (λ_ X₁).hom ⊗ₘ (λ_ X₂).hom = tensorμ (𝟙_ C) X₁ (𝟙_ C) X₂ ≫ ((λ_ (𝟙_ C)).hom ▷ (X₁ ⊗ X₂)) ≫ (λ_ (X₁ ⊗ X₂)).hom := by dsimp only [tensorμ] have : (λ_ X₁).hom ⊗ₘ (λ_ X₂).hom = (α_ (𝟙_ C) X₁ (𝟙_ C ⊗ X₂)).hom ≫ (𝟙_ C ◁ (α_ X₁ (𝟙_ C) X₂).inv) ≫ (λ_ ((X₁ ⊗ 𝟙_ C) ⊗ X₂)).hom ≫ ((ρ_ X₁).hom ▷ X₂) := by monoidal rw [this]; clear this rw [← braiding_leftUnitor] monoidal @[reassoc] theorem rightUnitor_monoidal (X₁ X₂ : C) : (ρ_ X₁).hom ⊗ₘ (ρ_ X₂).hom = tensorμ X₁ (𝟙_ C) X₂ (𝟙_ C) ≫ ((X₁ ⊗ X₂) ◁ (λ_ (𝟙_ C)).hom) ≫ (ρ_ (X₁ ⊗ X₂)).hom := by dsimp only [tensorμ] have : (ρ_ X₁).hom ⊗ₘ (ρ_ X₂).hom = (α_ X₁ (𝟙_ C) (X₂ ⊗ 𝟙_ C)).hom ≫ (X₁ ◁ (α_ (𝟙_ C) X₂ (𝟙_ C)).inv) ≫ (X₁ ◁ (ρ_ (𝟙_ C ⊗ X₂)).hom) ≫ (X₁ ◁ (λ_ X₂).hom) := by monoidal rw [this]; clear this rw [← braiding_rightUnitor] monoidal @[reassoc] theorem associator_monoidal (X₁ X₂ X₃ Y₁ Y₂ Y₃ : C) : tensorμ (X₁ ⊗ X₂) X₃ (Y₁ ⊗ Y₂) Y₃ ≫ (tensorμ X₁ X₂ Y₁ Y₂ ▷ (X₃ ⊗ Y₃)) ≫ (α_ (X₁ ⊗ Y₁) (X₂ ⊗ Y₂) (X₃ ⊗ Y₃)).hom = ((α_ X₁ X₂ X₃).hom ⊗ₘ (α_ Y₁ Y₂ Y₃).hom) ≫ tensorμ X₁ (X₂ ⊗ X₃) Y₁ (Y₂ ⊗ Y₃) ≫ ((X₁ ⊗ Y₁) ◁ tensorμ X₂ X₃ Y₂ Y₃) := by dsimp only [tensorμ] calc _ = 𝟙 _ ⊗≫ X₁ ◁ X₂ ◁ (β_ X₃ Y₁).hom ▷ Y₂ ▷ Y₃ ⊗≫ X₁ ◁ ((X₂ ⊗ Y₁) ◁ (β_ X₃ Y₂).hom ≫ (β_ X₂ Y₁).hom ▷ (Y₂ ⊗ X₃)) ▷ Y₃ ⊗≫ 𝟙 _ := by rw [braiding_tensor_right_hom]; monoidal _ = _ := by rw [whisker_exchange, braiding_tensor_left_hom]; monoidal @[reassoc] lemma tensorμ_comp_μ_tensorHom_μ_comp_μ (F : C ⥤ D) [F.LaxBraided] (W X Y Z : C) : tensorμ (F.obj W) (F.obj X) (F.obj Y) (F.obj Z) ≫ (μ F W Y ⊗ₘ μ F X Z) ≫ μ F (W ⊗ Y) (X ⊗ Z) = (μ F W X ⊗ₘ μ F Y Z) ≫ μ F (W ⊗ X) (Y ⊗ Z) ≫ F.map (tensorμ W X Y Z) := by rw [tensorHom_def] simp only [tensorμ, Category.assoc] rw [whiskerLeft_μ_comp_μ, associator_inv_naturality_left_assoc, ← pentagon_inv_assoc, ← comp_whiskerRight_assoc, ← comp_whiskerRight_assoc, Category.assoc, μ_whiskerRight_comp_μ, whiskerLeft_hom_inv_assoc, Iso.inv_hom_id_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, μ_natural_left_assoc, associator_inv_naturality_middle_assoc, ← comp_whiskerRight_assoc, ← comp_whiskerRight_assoc, ← MonoidalCategory.whiskerLeft_comp, ← Functor.LaxBraided.braided, MonoidalCategory.whiskerLeft_comp_assoc, μ_natural_right, whiskerLeft_μ_comp_μ_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, pentagon_inv_assoc, μ_natural_left_assoc, μ_natural_left_assoc, Iso.hom_inv_id_assoc, ← associator_inv_naturality_left_assoc, μ_whiskerRight_comp_μ_assoc, Iso.inv_hom_id_assoc, ← tensorHom_def_assoc] simp only [← Functor.map_comp, whisker_assoc, Category.assoc, pentagon_inv_inv_hom_hom_inv, pentagon_inv_hom_hom_hom_inv_assoc] end Tensor end MonoidalCategory instance : BraidedCategory Cᵒᵖ where braiding X Y := (β_ Y.unop X.unop).op braiding_naturality_right X {_ _} f := Quiver.Hom.unop_inj <| by simp braiding_naturality_left {_ _} f Z := Quiver.Hom.unop_inj <| by simp section OppositeLemmas open Opposite @[simp] lemma op_braiding (X Y : C) : (β_ X Y).op = β_ (op Y) (op X) := rfl @[simp] lemma unop_braiding (X Y : Cᵒᵖ) : (β_ X Y).unop = β_ (unop Y) (unop X) := rfl @[simp] lemma op_hom_braiding (X Y : C) : (β_ X Y).hom.op = (β_ (op Y) (op X)).hom := rfl @[simp] lemma unop_hom_braiding (X Y : Cᵒᵖ) : (β_ X Y).hom.unop = (β_ (unop Y) (unop X)).hom := rfl @[simp] lemma op_inv_braiding (X Y : C) : (β_ X Y).inv.op = (β_ (op Y) (op X)).inv := rfl @[simp] lemma unop_inv_braiding (X Y : Cᵒᵖ) : (β_ X Y).inv.unop = (β_ (unop Y) (unop X)).inv := rfl end OppositeLemmas namespace MonoidalOpposite instance instBraiding : BraidedCategory Cᴹᵒᵖ where braiding X Y := (β_ Y.unmop X.unmop).mop braiding_naturality_right X {_ _} f := Quiver.Hom.unmop_inj <| by simp braiding_naturality_left {_ _} f Z := Quiver.Hom.unmop_inj <| by simp section MonoidalOppositeLemmas @[simp] lemma mop_braiding (X Y : C) : (β_ X Y).mop = β_ (mop Y) (mop X) := rfl @[simp] lemma unmop_braiding (X Y : Cᴹᵒᵖ) : (β_ X Y).unmop = β_ (unmop Y) (unmop X) := rfl @[simp] lemma mop_hom_braiding (X Y : C) : (β_ X Y).hom.mop = (β_ (mop Y) (mop X)).hom := rfl @[simp] lemma unmop_hom_braiding (X Y : Cᴹᵒᵖ) : (β_ X Y).hom.unmop = (β_ (unmop Y) (unmop X)).hom := rfl @[simp] lemma mop_inv_braiding (X Y : C) : (β_ X Y).inv.mop = (β_ (mop Y) (mop X)).inv := rfl @[simp] lemma unmop_inv_braiding (X Y : Cᴹᵒᵖ) : (β_ X Y).inv.unmop = (β_ (unmop Y) (unmop X)).inv := rfl end MonoidalOppositeLemmas instance : (mopFunctor C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := Iso.refl _ μIso := fun X Y ↦ β_ (mop X) (mop Y) associativity := fun X Y Z ↦ by simp [← yang_baxter_assoc] } @[simp] lemma mopFunctor_ε : ε (mopFunctor C) = 𝟙 _ := rfl @[simp] lemma mopFunctor_η : η (mopFunctor C) = 𝟙 _ := rfl @[simp] lemma mopFunctor_μ (X Y : C) : μ (mopFunctor C) X Y = (β_ (mop X) (mop Y)).hom := rfl @[simp] lemma mopFunctor_δ (X Y : C) : δ (mopFunctor C) X Y = (β_ (mop X) (mop Y)).inv := rfl instance : (unmopFunctor C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := Iso.refl _ μIso := fun X Y ↦ β_ (unmop X) (unmop Y) associativity := fun X Y Z ↦ by simp [← yang_baxter_assoc] } @[simp] lemma unmopFunctor_ε : ε (unmopFunctor C) = 𝟙 _ := rfl @[simp] lemma unmopFunctor_η : η (unmopFunctor C) = 𝟙 _ := rfl @[simp] lemma unmopFunctor_μ (X Y : Cᴹᵒᵖ) : μ (unmopFunctor C) X Y = (β_ (unmop X) (unmop Y)).hom := rfl @[simp] lemma unmopFunctor_δ (X Y : Cᴹᵒᵖ) : δ (unmopFunctor C) X Y = (β_ (unmop X) (unmop Y)).inv := rfl /-- The identity functor on `C`, viewed as a functor from `C` to its monoidal opposite, upgraded to a braided functor. -/ instance : (mopFunctor C).Braided where /-- The identity functor on `C`, viewed as a functor from the monoidal opposite of `C` to `C`, upgraded to a braided functor. -/ instance : (unmopFunctor C).Braided where end MonoidalOpposite variable (C) /-- The braided monoidal category obtained from `C` by replacing its braiding `β_ X Y : X ⊗ Y ≅ Y ⊗ X` with the inverse `(β_ Y X)⁻¹ : X ⊗ Y ≅ Y ⊗ X`. This corresponds to the automorphism of the braid group swapping over-crossings and under-crossings. -/ abbrev reverseBraiding : BraidedCategory C where braiding X Y := (β_ Y X).symm braiding_naturality_right X {_ _} f := by simp braiding_naturality_left {_ _} f Z := by simp lemma SymmetricCategory.reverseBraiding_eq (C : Type u₁) [Category.{v₁} C] [MonoidalCategory C] [i : SymmetricCategory C] : reverseBraiding C = i.toBraidedCategory := by dsimp only [reverseBraiding] congr funext X Y exact Iso.ext (braiding_swap_eq_inv_braiding Y X).symm /-- The identity functor from `C` to `C`, where the codomain is given the reversed braiding, upgraded to a braided functor. -/ def SymmetricCategory.equivReverseBraiding (C : Type u₁) [Category.{v₁} C] [MonoidalCategory C] [SymmetricCategory C] := @Functor.Braided.mk C _ _ _ C _ _ (reverseBraiding C) (𝟭 C) _ <| by simp [reverseBraiding, braiding_swap_eq_inv_braiding] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monoidal/Braided/Multifunctor.lean
import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Functor.CurryingThree /-! # Constructing braided categories from natural transformations between multifunctors This file provides an alternative constructor for braided categories, given a braiding `β : -₁ ⊗ -₂ ≅ -₂ ⊗ -₁` as a natural isomorphism between bifunctors. The hexagon identities are phrased as equalities of natural transformations between trifunctors `(-₁ ⊗ -₂) ⊗ -₃ ⟶ -₂ ⊗ (-₃ ⊗ -₁)` and `-₁ ⊗ (-₂ ⊗ -₃) ⟶ (-₃ ⊗ -₁) ⊗ -₂`. -/ namespace CategoryTheory variable {C : Type*} [Category C] [MonoidalCategory C] open MonoidalCategory Functor namespace BraidedCategory namespace Hexagon variable (C) /-- The trifunctor `X₁ X₂ X₃ ↦ (X₁ ⊗ X₂) ⊗ X₃` -/ @[simps!] def functor₁₂₃ : C ⥤ C ⥤ C ⥤ C := bifunctorComp₁₂ (curriedTensor C) (curriedTensor C) /-- The trifunctor `X₁ X₂ X₃ ↦ X₁ ⊗ (X₂ ⊗ X₃)` -/ @[simps!] def functor₁₂₃' : C ⥤ C ⥤ C ⥤ C := bifunctorComp₂₃ (curriedTensor C) (curriedTensor C) /-- The trifunctor `X₁ X₂ X₃ ↦ (X₂ ⊗ X₃) ⊗ X₁` -/ @[simps!] def functor₂₃₁ : C ⥤ C ⥤ C ⥤ C := (bifunctorComp₂₃ (curriedTensor C).flip (curriedTensor C)) /-- The trifunctor `X₁ X₂ X₃ ↦ X₂ ⊗ (X₃ ⊗ X₁)` -/ @[simps!] def functor₂₃₁' : C ⥤ C ⥤ C ⥤ C := (bifunctorComp₂₃ (curriedTensor C) (curriedTensor C)).flip.flip₁₃ /-- The trifunctor `X₁ X₂ X₃ ↦ (X₂ ⊗ X₁) ⊗ X₃` -/ @[simps!] def functor₂₁₃ : C ⥤ C ⥤ C ⥤ C := bifunctorComp₁₂ (curriedTensor C).flip (curriedTensor C) /-- The trifunctor `X₁ X₂ X₃ ↦ X₂ ⊗ (X₁ ⊗ X₃)` -/ @[simps!] def functor₂₁₃' : C ⥤ C ⥤ C ⥤ C := (bifunctorComp₂₃ (curriedTensor C) (curriedTensor C)).flip /-- The trifunctor `X₁ X₂ X₃ ↦ X₃ ⊗ (X₁ ⊗ X₂)` -/ @[simps!] def functor₃₁₂' : C ⥤ C ⥤ C ⥤ C := (bifunctorComp₂₃ (curriedTensor C) (curriedTensor C)).flip.flip₂₃ /-- The trifunctor `X₁ X₂ X₃ ↦ (X₃ ⊗ X₁) ⊗ X₂` -/ @[simps!] def functor₃₁₂ : C ⥤ C ⥤ C ⥤ C := (bifunctorComp₁₂ (curriedTensor C) (curriedTensor C)).flip.flip₂₃ /-- The trifunctor `X₁ X₂ X₃ ↦ X₁ ⊗ (X₃ ⊗ X₂)` -/ @[simps!] def functor₁₃₂' : C ⥤ C ⥤ C ⥤ C := (bifunctorComp₂₃ (curriedTensor C) (curriedTensor C).flip) /-- The trifunctor `X₁ X₂ X₃ ↦ (X₁ ⊗ X₃) ⊗ X₂` -/ @[simps!] def functor₁₃₂ : C ⥤ C ⥤ C ⥤ C := (bifunctorComp₁₂ (curriedTensor C) (curriedTensor C)).flip₂₃ end Hexagon open Hexagon namespace ofBifunctor -- We use the following three defeq abuses, together with `F.flip.flip = F` example : (bifunctorComp₁₂ (curriedTensor C) (curriedTensor C)).flip = (bifunctorComp₁₂ (curriedTensor C).flip (curriedTensor C)) := by rfl example : (bifunctorComp₂₃ (curriedTensor C) (curriedTensor C)).flip = (bifunctorComp₂₃ (curriedTensor C) (curriedTensor C).flip).flip.flip₁₃ := by rfl example : (bifunctorComp₁₂ (curriedTensor C) (curriedTensor C)) = (bifunctorComp₂₃ (curriedTensor C).flip (curriedTensor C)).flip.flip₂₃ := by rfl namespace Forward /-! ### The forward hexagon identity Given a braiding in the form of a natural isomorphism of bifunctors `β : curriedTensor C ≅ (curriedTensor C).flip` (i.e. `(β.app X₁).app X₂ : X₁ ⊗ X₂ ≅ X₂ ⊗ X₁`), we phrase the forward hexagon identity as an equality of natural transformations between trifunctors (the hexagon on the left is the diagram we require to commute, the hexagon on the right is the same on the object level on three objects `X₁ X₂ X₃`). ``` functor₁₂₃ (X₁ ⊗ X₂) ⊗ X₃ associator / \ secondMap₁ / \ v v v v functor₁₂₃' functor₂₁₃ X₁ ⊗ (X₂ ⊗ X₃) (X₂ ⊗ X₁) ⊗ X₃ firstMap₂ | |secondMap₂ | | v v v v functor₂₃₁ functor₂₁₃' (X₂ ⊗ X₃) ⊗ X₁ X₂ ⊗ (X₁ ⊗ X₃) firstMap₃\ / secondMap₃ \ / v v v v functor₂₃₁' X₂ ⊗ (X₃ ⊗ X₁) ``` -/ /-- The middle left map in the forward hexagon identity. -/ @[simps!] def firstMap₂ (β : curriedTensor C ≅ (curriedTensor C).flip) : functor₁₂₃' C ⟶ functor₂₃₁ C := (bifunctorComp₂₃Functor.map β.hom).app _ variable (C) in /-- The bottom left map in the forward hexagon identity. -/ @[simps!] def firstMap₃ : functor₂₃₁ C ⟶ functor₂₃₁' C where app _ := { app _ := { app _ := (α_ _ _ _).hom } } /-- The top right map in the forward hexagon identity. -/ @[simps!] def secondMap₁ (β : curriedTensor C ≅ (curriedTensor C).flip) : functor₁₂₃ C ⟶ functor₂₁₃ C := (bifunctorComp₁₂Functor.map β.hom).app _ variable (C) in /-- The middle right map in the forward hexagon identity. -/ @[simps!] def secondMap₂ : functor₂₁₃ C ⟶ functor₂₁₃' C where app _ := { app _ := { app _ := (α_ _ _ _).hom } } /-- The bottom right map in the forward hexagon identity. -/ @[simps!] def secondMap₃ (β : curriedTensor C ≅ (curriedTensor C).flip) : functor₂₁₃' C ⟶ functor₂₃₁' C := flip₁₃Functor.map ((flipFunctor _ _ _).map ((bifunctorComp₂₃Functor.obj (curriedTensor C)).map ((flipFunctor _ _ _).map β.hom))) end Forward namespace Reverse /-! ### The reverse hexagon identity Given a braiding in the form of a natural isomorphism of bifunctors `β : curriedTensor C ≅ (curriedTensor C).flip` (i.e. `(β.app X₁).app X₂ : X₁ ⊗ X₂ ≅ X₂ ⊗ X₁`), we phrase the reverse hexagon identity as an equality of natural transformations between trifunctors (the hexagon on the left is the diagram we require to commute, the hexagon on the right is the same on the object level on three objects `X₁ X₂ X₃`). ``` functor₁₂₃' X₁ ⊗ (X₂ ⊗ X₃) associator / \ secondMap₁ / \ v v v v functor₁₂₃ functor₁₃₂' (X₁ ⊗ X₂) ⊗ X₃ X₁ ⊗ (X₃ ⊗ X₂) firstMap₂ | |secondMap₂ | | v v v v functor₃₁₂' functor₁₃₂ X₃ ⊗ (X₁ ⊗ X₂) (X₁ ⊗ X₃) ⊗ X₂ firstMap₃\ / secondMap₃ \ / v v v v functor₃₁₂ (X₃ ⊗ X₁) ⊗ X₂ ``` -/ /-- The middle left map in the reverse hexagon identity. -/ @[simps!] def firstMap₂ (β : curriedTensor C ≅ (curriedTensor C).flip) : functor₁₂₃ C ⟶ functor₃₁₂' C := flip₂₃Functor.map ((flipFunctor _ _ _).map ((bifunctorComp₂₃Functor.map ((flipFunctor _ _ _).map β.hom)).app _)) variable (C) in /-- The bottom left map in the reverse hexagon identity. -/ @[simps!] def firstMap₃ : functor₃₁₂' C ⟶ functor₃₁₂ C := flip₂₃Functor.map ((flipFunctor _ _ _).map (curriedAssociatorNatIso C).inv) /-- The top right map in the reverse hexagon identity. -/ @[simps!] def secondMap₁ (β : curriedTensor C ≅ (curriedTensor C).flip) : functor₁₂₃' C ⟶ functor₁₃₂' C := (bifunctorComp₂₃Functor.obj _).map β.hom variable (C) in /-- The middle right map in the reverse hexagon identity. -/ @[simps!] def secondMap₂ : functor₁₃₂' C ⟶ functor₁₃₂ C where app _ := { app _ := { app _ := (α_ _ _ _).inv } } /-- The bottom right map in the reverse hexagon identity. -/ @[simps!] def secondMap₃ (β : curriedTensor C ≅ (curriedTensor C).flip) : functor₁₃₂ C ⟶ functor₃₁₂ C := flip₂₃Functor.map ((bifunctorComp₁₂Functor.map β.hom).app _) end Reverse end ofBifunctor open ofBifunctor variable (β : curriedTensor C ≅ (curriedTensor C).flip) (hexagon_forward : (curriedAssociatorNatIso C).hom ≫ Forward.firstMap₂ β ≫ Forward.firstMap₃ C = Forward.secondMap₁ β ≫ Forward.secondMap₂ C ≫ Forward.secondMap₃ β) (hexagon_reverse : (curriedAssociatorNatIso C).inv ≫ Reverse.firstMap₂ β ≫ Reverse.firstMap₃ C = Reverse.secondMap₁ β ≫ Reverse.secondMap₂ C ≫ Reverse.secondMap₃ β) /-- Given a braiding `β : curriedTensor C ≅ (curriedTensor C).flip` as a natural isomorphism between bifunctors, and the two equalities `hexagon_forward` and `hexagon_reverse` of natural transformations between trifunctors, we obtain a braided category structure. -/ def ofBifunctor : BraidedCategory C where braiding X Y := (β.app X).app Y braiding_naturality_right _ _ _ _ := (β.app _).hom.naturality _ braiding_naturality_left _ _ := NatTrans.congr_app (β.hom.naturality _) _ hexagon_forward X Y Z := NatTrans.congr_app (NatTrans.congr_app (NatTrans.congr_app hexagon_forward X) Y) Z hexagon_reverse X Y Z := (NatTrans.congr_app (NatTrans.congr_app (NatTrans.congr_app hexagon_reverse X) Y) Z) end BraidedCategory open BraidedCategory /-- Alternative constructor for symmetric categories, where the symmetry of the braiding is phrased as an equality of natural transformation of bifunctors. -/ def SymmetricCategory.ofCurried [BraidedCategory C] (h : (curriedBraidingNatIso C).hom ≫ (flipFunctor _ _ _).map (curriedBraidingNatIso C).hom = 𝟙 _) : SymmetricCategory C where symmetry X Y := NatTrans.congr_app (NatTrans.congr_app h X) Y end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Pi/Basic.lean
import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.Products.Basic /-! # Categories of indexed families of objects. We define the pointwise category structure on indexed families of objects in a category (and also the dependent generalization). -/ namespace CategoryTheory open Functor universe w₀ w₁ w₂ v₁ v₂ v₃ u₁ u₂ u₃ variable {I : Type w₀} {J : Type w₁} (C : I → Type u₁) [∀ i, Category.{v₁} (C i)] /-- `pi C` gives the Cartesian product of an indexed family of categories. -/ instance pi : Category.{max w₀ v₁} (∀ i, C i) where Hom X Y := ∀ i, X i ⟶ Y i id X i := 𝟙 (X i) comp f g i := f i ≫ g i namespace Pi @[simp] theorem id_apply (X : ∀ i, C i) (i) : (𝟙 X : ∀ i, X i ⟶ X i) i = 𝟙 (X i) := rfl @[simp] theorem comp_apply {X Y Z : ∀ i, C i} (f : X ⟶ Y) (g : Y ⟶ Z) (i) : (f ≫ g : ∀ i, X i ⟶ Z i) i = f i ≫ g i := rfl @[ext] lemma ext {X Y : ∀ i, C i} {f g : X ⟶ Y} (w : ∀ i, f i = g i) : f = g := funext (w ·) /-- The evaluation functor at `i : I`, sending an `I`-indexed family of objects to the object over `i`. -/ @[simps] def eval (i : I) : (∀ i, C i) ⥤ C i where obj f := f i map α := α i section variable {J : Type w₁} instance (f : J → I) : (j : J) → Category ((C ∘ f) j) := inferInstanceAs <| (j : J) → Category (C (f j)) /-- Pull back an `I`-indexed family of objects to a `J`-indexed family, along a function `J → I`. -/ @[simps] def comap (h : J → I) : (∀ i, C i) ⥤ (∀ j, C (h j)) where obj f i := f (h i) map α i := α (h i) variable (I) /-- The natural isomorphism between pulling back a grading along the identity function, and the identity functor. -/ @[simps] def comapId : comap C (id : I → I) ≅ 𝟭 (∀ i, C i) where hom := { app := fun X => 𝟙 X } inv := { app := fun X => 𝟙 X } example (g : J → I) : (j : J) → Category (C (g j)) := by infer_instance variable {I} variable {K : Type w₂} /-- The natural isomorphism comparing between pulling back along two successive functions, and pulling back along their composition -/ @[simps!] def comapComp (f : K → J) (g : J → I) : comap C g ⋙ comap (C ∘ g) f ≅ comap C (g ∘ f) where hom := { app := fun X b => 𝟙 (X (g (f b))) naturality := fun X Y f' => by simp only [comap, Function.comp]; funext; simp } inv := { app := fun X b => 𝟙 (X (g (f b))) naturality := fun X Y f' => by simp only [comap, Function.comp]; funext; simp } /-- The natural isomorphism between pulling back then evaluating, and just evaluating. -/ @[simps!] def comapEvalIsoEval (h : J → I) (j : J) : comap C h ⋙ eval (C ∘ h) j ≅ eval C (h j) := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) end section variable {J : Type w₀} {D : J → Type u₁} [∀ j, Category.{v₁} (D j)] instance sumElimCategory : ∀ s : I ⊕ J, Category.{v₁} (Sum.elim C D s) | Sum.inl i => by dsimp infer_instance | Sum.inr j => by dsimp infer_instance /-- The bifunctor combining an `I`-indexed family of objects with a `J`-indexed family of objects to obtain an `I ⊕ J`-indexed family of objects. -/ @[simps] def sum : (∀ i, C i) ⥤ (∀ j, D j) ⥤ ∀ s : I ⊕ J, Sum.elim C D s where obj X := { obj := fun Y s => match s with | .inl i => X i | .inr j => Y j map := fun {_} {_} f s => match s with | .inl i => 𝟙 (X i) | .inr j => f j } map {X} {X'} f := { app := fun Y s => match s with | .inl i => f i | .inr j => 𝟙 (Y j) } end variable {C} /-- An isomorphism between `I`-indexed objects gives an isomorphism between each pair of corresponding components. -/ @[simps] def isoApp {X Y : ∀ i, C i} (f : X ≅ Y) (i : I) : X i ≅ Y i := ⟨f.hom i, f.inv i, by rw [← comp_apply, Iso.hom_inv_id, id_apply], by rw [← comp_apply, Iso.inv_hom_id, id_apply]⟩ @[simp] theorem isoApp_refl (X : ∀ i, C i) (i : I) : isoApp (Iso.refl X) i = Iso.refl (X i) := rfl @[simp] theorem isoApp_symm {X Y : ∀ i, C i} (f : X ≅ Y) (i : I) : isoApp f.symm i = (isoApp f i).symm := rfl @[simp] theorem isoApp_trans {X Y Z : ∀ i, C i} (f : X ≅ Y) (g : Y ≅ Z) (i : I) : isoApp (f ≪≫ g) i = isoApp f i ≪≫ isoApp g i := rfl end Pi namespace Functor variable {C} variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)] {A : Type u₃} [Category.{v₃} A] /-- Assemble an `I`-indexed family of functors into a functor between the pi types. -/ @[simps] def pi (F : ∀ i, C i ⥤ D i) : (∀ i, C i) ⥤ ∀ i, D i where obj f i := (F i).obj (f i) map α i := (F i).map (α i) /-- Similar to `pi`, but all functors come from the same category `A` -/ @[simps] def pi' (f : ∀ i, A ⥤ C i) : A ⥤ ∀ i, C i where obj a i := (f i).obj a map h i := (f i).map h /-- The projections of `Functor.pi' F` are isomorphic to the functors of the family `F` -/ @[simps!] def pi'CompEval {A : Type*} [Category A] (F : ∀ i, A ⥤ C i) (i : I) : pi' F ⋙ Pi.eval C i ≅ F i := Iso.refl _ section EqToHom @[simp] theorem eqToHom_proj {x x' : ∀ i, C i} (h : x = x') (i : I) : (eqToHom h : x ⟶ x') i = eqToHom (funext_iff.mp h i) := by subst h rfl end EqToHom -- One could add some natural isomorphisms showing -- how `Functor.pi` commutes with `Pi.eval` and `Pi.comap`. @[simp] theorem pi'_eval (f : ∀ i, A ⥤ C i) (i : I) : pi' f ⋙ Pi.eval C i = f i := rfl /-- Two functors to a product category are equal iff they agree on every coordinate. -/ theorem pi_ext (f f' : A ⥤ ∀ i, C i) (h : ∀ i, f ⋙ (Pi.eval C i) = f' ⋙ (Pi.eval C i)) : f = f' := by apply Functor.ext; rotate_left · intro X ext i specialize h i have := congr_obj h X simpa · intro X Y g funext i specialize h i have := congr_hom h g simpa end Functor namespace NatTrans variable {C} variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)] variable {F G : ∀ i, C i ⥤ D i} /-- Assemble an `I`-indexed family of natural transformations into a single natural transformation. -/ @[simps!] def pi (α : ∀ i, F i ⟶ G i) : Functor.pi F ⟶ Functor.pi G where app f i := (α i).app (f i) /-- Assemble an `I`-indexed family of natural transformations into a single natural transformation. -/ @[simps] def pi' {E : Type*} [Category E] {F G : E ⥤ ∀ i, C i} (τ : ∀ i, F ⋙ Pi.eval C i ⟶ G ⋙ Pi.eval C i) : F ⟶ G where app := fun X i => (τ i).app X naturality _ _ f := by ext i exact (τ i).naturality f end NatTrans namespace NatIso variable {C} variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)] variable {F G : ∀ i, C i ⥤ D i} /-- Assemble an `I`-indexed family of natural isomorphisms into a single natural isomorphism. -/ @[simps] def pi (e : ∀ i, F i ≅ G i) : Functor.pi F ≅ Functor.pi G where hom := NatTrans.pi (fun i => (e i).hom) inv := NatTrans.pi (fun i => (e i).inv) /-- Assemble an `I`-indexed family of natural isomorphisms into a single natural isomorphism. -/ @[simps] def pi' {E : Type*} [Category E] {F G : E ⥤ ∀ i, C i} (e : ∀ i, F ⋙ Pi.eval C i ≅ G ⋙ Pi.eval C i) : F ≅ G where hom := NatTrans.pi' (fun i => (e i).hom) inv := NatTrans.pi' (fun i => (e i).inv) end NatIso variable {C} lemma isIso_pi_iff {X Y : ∀ i, C i} (f : X ⟶ Y) : IsIso f ↔ ∀ i, IsIso (f i) := by constructor · intro _ i exact (Pi.isoApp (asIso f) i).isIso_hom · intro exact ⟨fun i => inv (f i), by cat_disch, by cat_disch⟩ variable (C) /-- For a family of categories `C i` indexed by `I`, an equality `i = j` in `I` induces an equivalence `C i ≌ C j`. -/ def Pi.eqToEquivalence {i j : I} (h : i = j) : C i ≌ C j := by subst h; rfl /-- When `i = j`, projections `Pi.eval C i` and `Pi.eval C j` are related by the equivalence `Pi.eqToEquivalence C h : C i ≌ C j`. -/ @[simps!] def Pi.evalCompEqToEquivalenceFunctor {i j : I} (h : i = j) : Pi.eval C i ⋙ (Pi.eqToEquivalence C h).functor ≅ Pi.eval C j := eqToIso (by subst h; rfl) /-- The equivalences given by `Pi.eqToEquivalence` are compatible with reindexing. -/ @[simps!] def Pi.eqToEquivalenceFunctorIso (f : J → I) {i' j' : J} (h : i' = j') : (Pi.eqToEquivalence C (congr_arg f h)).functor ≅ (Pi.eqToEquivalence (fun i' => C (f i')) h).functor := eqToIso (by subst h; rfl) attribute [local simp] eqToHom_map /-- Reindexing a family of categories gives equivalent `Pi` categories. -/ @[simps] noncomputable def Pi.equivalenceOfEquiv (e : J ≃ I) : (∀ j, C (e j)) ≌ (∀ i, C i) where functor := pi' (fun i => Pi.eval _ (e.symm i) ⋙ (Pi.eqToEquivalence C (by simp)).functor) inverse := Functor.pi' (fun i' => Pi.eval _ (e i')) unitIso := NatIso.pi' (fun i' => leftUnitor _ ≪≫ (Pi.evalCompEqToEquivalenceFunctor (fun j => C (e j)) (e.symm_apply_apply i')).symm ≪≫ isoWhiskerLeft _ ((Pi.eqToEquivalenceFunctorIso C e (e.symm_apply_apply i')).symm) ≪≫ (pi'CompEval _ _).symm ≪≫ isoWhiskerLeft _ (pi'CompEval _ _).symm ≪≫ (associator _ _ _).symm) counitIso := NatIso.pi' (fun i => (associator _ _ _).symm ≪≫ isoWhiskerRight (pi'CompEval _ _) _ ≪≫ Pi.evalCompEqToEquivalenceFunctor C (e.apply_symm_apply i) ≪≫ (leftUnitor _).symm) /-- A product of categories indexed by `Option J` identifies to a binary product. -/ @[simps] def Pi.optionEquivalence (C' : Option J → Type u₁) [∀ i, Category.{v₁} (C' i)] : (∀ i, C' i) ≌ C' none × (∀ (j : J), C' (some j)) where functor := Functor.prod' (Pi.eval C' none) (Functor.pi' (fun i => (Pi.eval _ (some i)))) inverse := Functor.pi' (fun i => match i with | none => Prod.fst _ _ | some i => Prod.snd _ _ ⋙ (Pi.eval _ i)) unitIso := NatIso.pi' (fun i => match i with | none => Iso.refl _ | some _ => Iso.refl _) counitIso := by exact Iso.refl _ namespace Equivalence variable {C} variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)] /-- Assemble an `I`-indexed family of equivalences of categories into a single equivalence. -/ @[simps] def pi (E : ∀ i, C i ≌ D i) : (∀ i, C i) ≌ (∀ i, D i) where functor := Functor.pi (fun i => (E i).functor) inverse := Functor.pi (fun i => (E i).inverse) unitIso := NatIso.pi (fun i => (E i).unitIso) counitIso := NatIso.pi (fun i => (E i).counitIso) instance (F : ∀ i, C i ⥤ D i) [∀ i, (F i).IsEquivalence] : (Functor.pi F).IsEquivalence := (pi (fun i => (F i).asEquivalence)).isEquivalence_functor end Equivalence end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Action/Monoidal.lean
import Mathlib.Algebra.BigOperators.Fin import Mathlib.CategoryTheory.Monoidal.Linear import Mathlib.CategoryTheory.Monoidal.Rigid.FunctorCategory import Mathlib.CategoryTheory.Monoidal.Rigid.OfEquivalence import Mathlib.CategoryTheory.Monoidal.Transport import Mathlib.CategoryTheory.Monoidal.Types.Basic import Mathlib.CategoryTheory.Action.Concrete import Mathlib.CategoryTheory.Action.Limits /-! # Induced monoidal structure on `Action V G` We show: * When `V` is monoidal, braided, or symmetric, so is `Action V G`. -/ universe u open CategoryTheory Limits MonoidalCategory variable {V : Type*} [Category V] {G : Type*} [Monoid G] namespace Action section Monoidal open MonoidalCategory variable [MonoidalCategory V] @[simps! tensorUnit_V tensorObj_V tensorHom_hom whiskerLeft_hom whiskerRight_hom associator_hom_hom associator_inv_hom leftUnitor_hom_hom leftUnitor_inv_hom rightUnitor_hom_hom rightUnitor_inv_hom] instance instMonoidalCategory : MonoidalCategory (Action V G) := Monoidal.transport (Action.functorCategoryEquivalence _ _).symm @[simp] theorem tensorUnit_ρ {g : G} : @DFunLike.coe (G →* End (𝟙_ V)) _ _ _ (𝟙_ (Action V G)).ρ g = 𝟙 (𝟙_ V) := rfl @[simp] theorem tensor_ρ {X Y : Action V G} {g : G} : @DFunLike.coe (G →* End (X.V ⊗ Y.V)) _ _ _ (X ⊗ Y).ρ g = X.ρ g ⊗ₘ Y.ρ g := rfl /-- Given an object `X` isomorphic to the tensor unit of `V`, `X` equipped with the trivial action is isomorphic to the tensor unit of `Action V G`. -/ def tensorUnitIso {X : V} (f : 𝟙_ V ≅ X) : 𝟙_ (Action V G) ≅ Action.mk X 1 := Action.mkIso f variable (V G) instance : (Action.forget V G).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := Iso.refl _ μIso := fun _ _ ↦ Iso.refl _ } open Functor.LaxMonoidal Functor.OplaxMonoidal @[simp] lemma forget_ε : ε (Action.forget V G) = 𝟙 _ := rfl @[simp] lemma forget_η : ε (Action.forget V G) = 𝟙 _ := rfl variable {V G} @[simp] lemma forget_μ (X Y : Action V G) : μ (Action.forget V G) X Y = 𝟙 _ := rfl @[simp] lemma forget_δ (X Y : Action V G) : δ (Action.forget V G) X Y = 𝟙 _ := rfl variable (V G) section variable [BraidedCategory V] instance : BraidedCategory (Action V G) := .ofFaithful (Action.forget V G) fun X Y ↦ mkIso (β_ _ _) fun g ↦ by simp @[simp] theorem β_hom_hom {X Y : Action V G} : (β_ X Y).hom.hom = (β_ X.V Y.V).hom := rfl @[simp] theorem β_inv_hom {X Y : Action V G} : (β_ X Y).inv.hom = (β_ X.V Y.V).inv := rfl /-- When `V` is braided the forgetful functor `Action V G` to `V` is braided. -/ instance : (Action.forget V G).Braided where end instance [SymmetricCategory V] : SymmetricCategory (Action V G) := .ofFaithful (Action.forget V G) section variable [Preadditive V] [MonoidalPreadditive V] attribute [local simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight instance : MonoidalPreadditive (Action V G) where variable {R : Type*} [Semiring R] [Linear R V] [MonoidalLinear R V] instance : MonoidalLinear R (Action V G) where end noncomputable section /-- Upgrading the functor `Action V G ⥤ (SingleObj G ⥤ V)` to a monoidal functor. -/ instance FunctorCategoryEquivalence.functorMonoidal : (FunctorCategoryEquivalence.functor (V := V) (G := G)).Monoidal := inferInstanceAs (Monoidal.equivalenceTransported (Action.functorCategoryEquivalence V G).symm).inverse.Monoidal instance functorCategoryEquivalenceFunctorMonoidal : (functorCategoryEquivalence V G).functor.Monoidal := by dsimp only [functorCategoryEquivalence_functor]; infer_instance /-- Upgrading the functor `(SingleObj G ⥤ V) ⥤ Action V G` to a monoidal functor. -/ instance FunctorCategoryEquivalence.inverseMonoidal : (FunctorCategoryEquivalence.inverse (V := V) (G := G)).Monoidal := inferInstanceAs (Monoidal.equivalenceTransported (Action.functorCategoryEquivalence V G).symm).functor.Monoidal instance functorCategoryEquivalenceInverseMonoidal : (functorCategoryEquivalence V G).inverse.Monoidal := by dsimp only [functorCategoryEquivalence_inverse]; infer_instance @[simp] lemma FunctorCategoryEquivalence.functor_ε : ε (FunctorCategoryEquivalence.functor (V := V) (G := G)) = 𝟙 _ := rfl @[simp] lemma FunctorCategoryEquivalence.functor_η : η (FunctorCategoryEquivalence.functor (V := V) (G := G)) = 𝟙 _ := rfl @[simp] lemma FunctorCategoryEquivalence.functor_μ (A B : Action V G) : μ FunctorCategoryEquivalence.functor A B = 𝟙 _ := rfl @[simp] lemma FunctorCategoryEquivalence.functor_δ (A B : Action V G) : δ FunctorCategoryEquivalence.functor A B = 𝟙 _ := rfl variable (H : Type*) [Group H] instance [RightRigidCategory V] : RightRigidCategory (SingleObj H ⥤ V) := by infer_instance /-- If `V` is right rigid, so is `Action V G`. -/ instance [RightRigidCategory V] : RightRigidCategory (Action V H) := rightRigidCategoryOfEquivalence (functorCategoryEquivalence V H).toAdjunction instance [LeftRigidCategory V] : LeftRigidCategory (SingleObj H ⥤ V) := by infer_instance /-- If `V` is left rigid, so is `Action V G`. -/ instance [LeftRigidCategory V] : LeftRigidCategory (Action V H) := leftRigidCategoryOfEquivalence (functorCategoryEquivalence V H).toAdjunction instance [RigidCategory V] : RigidCategory (SingleObj H ⥤ V) := by infer_instance /-- If `V` is rigid, so is `Action V G`. -/ instance [RigidCategory V] : RigidCategory (Action V H) := rigidCategoryOfEquivalence (functorCategoryEquivalence V H).toAdjunction variable {V H} variable (X : Action V H) @[simp] theorem rightDual_v [RightRigidCategory V] : Xᘁ.V = X.Vᘁ := rfl @[simp] theorem leftDual_v [LeftRigidCategory V] : (ᘁX).V = ᘁX.V := rfl theorem rightDual_ρ [RightRigidCategory V] (h : H) : Xᘁ.ρ h = (X.ρ (h⁻¹ : H))ᘁ := by rw [← SingleObj.inv_as_inv]; rfl theorem leftDual_ρ [LeftRigidCategory V] (h : H) : (ᘁX).ρ h = ᘁX.ρ (h⁻¹ : H) := by rw [← SingleObj.inv_as_inv]; rfl end end Monoidal section open MonoidalCategory variable (G : Type u) /-- The natural isomorphism of `G`-sets `Gⁿ⁺¹ ≅ G × Gⁿ`, where `G` acts by left multiplication on each factor. -/ @[simps!] noncomputable def diagonalSuccIsoTensorDiagonal [Monoid G] (n : ℕ) : diagonal G (n + 1) ≅ leftRegular G ⊗ diagonal G n := mkIso (Fin.consEquiv _).symm.toIso fun _ => rfl @[deprecated (since := "2025-06-02")] alias diagonalSucc := diagonalSuccIsoTensorDiagonal variable [Group G] /-- Given `X : Action (Type u) G` for `G` a group, then `G × X` (with `G` acting as left multiplication on the first factor and by `X.ρ` on the second) is isomorphic as a `G`-set to `G × X` (with `G` acting as left multiplication on the first factor and trivially on the second). The isomorphism is given by `(g, x) ↦ (g, g⁻¹ • x)`. -/ @[simps!] noncomputable def leftRegularTensorIso (X : Action (Type u) G) : leftRegular G ⊗ X ≅ leftRegular G ⊗ trivial G X.V := mkIso (Equiv.toIso { toFun g := ⟨g.1, (X.ρ (g.1⁻¹ : G) g.2 : X.V)⟩ invFun g := ⟨g.1, X.ρ g.1 g.2⟩ left_inv _ := Prod.ext rfl <| by simp right_inv _ := Prod.ext rfl <| by simp }) <| fun _ => by ext _ simp only [tensorObj_V, tensor_ρ, types_comp_apply, tensor_apply, ofMulAction_apply] simp /-- An isomorphism of `G`-sets `Gⁿ⁺¹ ≅ G × Gⁿ`, where `G` acts by left multiplication on `Gⁿ⁺¹` and `G` but trivially on `Gⁿ`. The map sends `(g₀, ..., gₙ) ↦ (g₀, (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ))`, and the inverse is `(g₀, (g₁, ..., gₙ)) ↦ (g₀, g₀g₁, g₀g₁g₂, ..., g₀g₁...gₙ).` -/ noncomputable def diagonalSuccIsoTensorTrivial : ∀ n : ℕ, diagonal G (n + 1) ≅ leftRegular G ⊗ trivial G (Fin n → G) | 0 => diagonalOneIsoLeftRegular G ≪≫ (ρ_ _).symm ≪≫ tensorIso (Iso.refl _) (tensorUnitIso (Equiv.ofUnique PUnit _).toIso) | n + 1 => diagonalSuccIsoTensorDiagonal _ _ ≪≫ tensorIso (Iso.refl _) (diagonalSuccIsoTensorTrivial n) ≪≫ leftRegularTensorIso _ _ ≪≫ tensorIso (Iso.refl _) (mkIso (Fin.insertNthEquiv (fun _ => G) 0).toIso fun _ => rfl) variable {G} @[simp] theorem diagonalSuccIsoTensorTrivial_hom_hom_apply {n : ℕ} (f : Fin (n + 1) → G) : (diagonalSuccIsoTensorTrivial G n).hom.hom f = (f 0, fun i => (f (Fin.castSucc i))⁻¹ * f i.succ) := by induction n with | zero => exact Prod.ext rfl (funext fun x => Fin.elim0 x) | succ n hn => refine Prod.ext rfl (funext fun x => ?_) induction x using Fin.cases <;> simp_all only [tensorObj_V, diagonalSuccIsoTensorTrivial, Iso.trans_hom, tensorIso_hom, Iso.refl_hom, id_tensorHom, comp_hom, whiskerLeft_hom, types_comp_apply, whiskerLeft_apply, leftRegularTensorIso_hom_hom, tensor_ρ, tensor_apply, ofMulAction_apply] <;> simp [ofMulAction_V, types_tensorObj_def, Fin.tail] @[simp] theorem diagonalSuccIsoTensorTrivial_inv_hom_apply {n : ℕ} (g : G) (f : Fin n → G) : (diagonalSuccIsoTensorTrivial G n).inv.hom (g, f) = (g • Fin.partialProd f : Fin (n + 1) → G) := by induction n generalizing g with | zero => funext (x : Fin 1) simp [diagonalSuccIsoTensorTrivial, diagonalOneIsoLeftRegular, Subsingleton.elim x 0, ofMulAction_V] | succ n hn => funext x induction x using Fin.cases <;> simp_all only [diagonalSuccIsoTensorTrivial, Iso.trans_inv, comp_hom, tensorObj_V, types_comp_apply, leftRegularTensorIso_inv_hom, tensor_ρ, tensor_apply, ofMulAction_apply] <;> simp_all [types_tensorObj_def, mul_assoc, Fin.partialProd_succ', ofMulAction_V] end end Action namespace CategoryTheory.Functor open Action variable {W : Type*} [Category W] [MonoidalCategory V] [MonoidalCategory W] (F : V ⥤ W) open Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal /-- A lax monoidal functor induces a lax monoidal functor between the categories of `G`-actions within those categories. -/ instance [F.LaxMonoidal] : (F.mapAction G).LaxMonoidal where ε := { hom := ε F comm := fun g => by dsimp [FunctorCategoryEquivalence.inverse, Functor.mapAction] rw [Category.id_comp, F.map_id, Category.comp_id] } μ X Y := { hom := μ F X.V Y.V comm := fun g => μ_natural F (X.ρ g) (Y.ρ g) } μ_natural_left _ _ := by ext; simp μ_natural_right _ _ := by ext; simp associativity _ _ _ := by ext; simp left_unitality _ := by ext; simp right_unitality _ := by ext; simp @[simp] lemma mapAction_ε_hom [F.LaxMonoidal] : (ε (F.mapAction G)).hom = ε F := rfl @[simp] lemma mapAction_μ_hom [F.LaxMonoidal] (X Y : Action V G) : (μ (F.mapAction G) X Y).hom = μ F X.V Y.V := rfl /-- An oplax monoidal functor induces an oplax monoidal functor between the categories of `G`-actions within those categories. -/ instance [F.OplaxMonoidal] : (F.mapAction G).OplaxMonoidal where η := { hom := η F comm := fun g => by dsimp [FunctorCategoryEquivalence.inverse, Functor.mapAction] rw [map_id, Category.id_comp, Category.comp_id] } δ X Y := { hom := δ F X.V Y.V comm := fun g => (δ_natural F (X.ρ g) (Y.ρ g)).symm } δ_natural_left _ _ := by ext; simp δ_natural_right _ _ := by ext; simp oplax_associativity _ _ _ := by ext; simp oplax_left_unitality _ := by ext; simp oplax_right_unitality _ := by ext; simp @[simp] lemma mapAction_η_hom [F.OplaxMonoidal] : (η (F.mapAction G)).hom = η F := rfl @[simp] lemma mapAction_δ_hom [F.OplaxMonoidal] (X Y : Action V G) : (δ (F.mapAction G) X Y).hom = δ F X.V Y.V := rfl /-- A monoidal functor induces a monoidal functor between the categories of `G`-actions within those categories. -/ instance [F.Monoidal] : (F.mapAction G).Monoidal where η_ε := by ext; dsimp; rw [η_ε] ε_η := by ext; dsimp; rw [ε_η] μ_δ _ _ := by ext; dsimp; rw [μ_δ] δ_μ _ _ := by ext; dsimp; rw [δ_μ] end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Action/Basic.lean
import Mathlib.Algebra.Category.Grp.Basic import Mathlib.Algebra.Ring.PUnit import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Conj import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.SingleObj import Mathlib.Tactic.ApplyFun /-! # `Action V G`, the category of actions of a monoid `G` inside some category `V`. The prototypical example is `V = ModuleCat R`, where `Action (ModuleCat R) G` is the category of `R`-linear representations of `G`. We check `Action V G ≌ (CategoryTheory.singleObj G ⥤ V)`, and construct the restriction functors `res {G H} [Monoid G] [Monoid H] (f : G →* H) : Action V H ⥤ Action V G`. -/ universe u v open CategoryTheory Limits variable (V : Type*) [Category V] -- Note: this is _not_ a categorical action of `G` on `V`. /-- An `Action V G` represents a bundled action of the monoid `G` on an object of some category `V`. As an example, when `V = ModuleCat R`, this is an `R`-linear representation of `G`, while when `V = Type` this is a `G`-action. -/ structure Action (G : Type*) [Monoid G] where /-- The object this action acts on -/ V : V /-- The underlying monoid homomorphism of this action -/ ρ : G →* End V namespace Action variable {V} theorem ρ_one {G : Type*} [Monoid G] (A : Action V G) : A.ρ 1 = 𝟙 A.V := by simp /-- When a group acts, we can lift the action to the group of automorphisms. -/ @[simps] def ρAut {G : Type*} [Group G] (A : Action V G) : G →* Aut A.V where toFun g := { hom := A.ρ g inv := A.ρ (g⁻¹ : G) hom_inv_id := (A.ρ.map_mul (g⁻¹ : G) g).symm.trans (by rw [inv_mul_cancel, ρ_one]) inv_hom_id := (A.ρ.map_mul g (g⁻¹ : G)).symm.trans (by rw [mul_inv_cancel, ρ_one]) } map_one' := Aut.ext A.ρ.map_one map_mul' x y := Aut.ext (A.ρ.map_mul x y) variable (G : Type*) [Monoid G] section /-- The action defined by sending every group element to the identity. -/ @[simps] def trivial (X : V) : Action V G := { V := X, ρ := 1 } instance inhabited' : Inhabited (Action (Type*) G) := ⟨⟨PUnit, 1⟩⟩ instance : Inhabited (Action AddCommGrpCat G) := ⟨trivial G <| AddCommGrpCat.of PUnit⟩ end variable {G} /-- A homomorphism of `Action V G`s is a morphism between the underlying objects, commuting with the action of `G`. -/ @[ext] structure Hom (M N : Action V G) where /-- The morphism between the underlying objects of this action -/ hom : M.V ⟶ N.V comm : ∀ g : G, M.ρ g ≫ hom = hom ≫ N.ρ g := by cat_disch namespace Hom attribute [reassoc] comm attribute [local simp] comm comm_assoc /-- The identity morphism on an `Action V G`. -/ @[simps] def id (M : Action V G) : Action.Hom M M where hom := 𝟙 M.V instance (M : Action V G) : Inhabited (Action.Hom M M) := ⟨id M⟩ /-- The composition of two `Action V G` homomorphisms is the composition of the underlying maps. -/ @[simps] def comp {M N K : Action V G} (p : Action.Hom M N) (q : Action.Hom N K) : Action.Hom M K where hom := p.hom ≫ q.hom end Hom instance : Category (Action V G) where Hom M N := Hom M N id M := Hom.id M comp f g := Hom.comp f g lemma hom_injective {M N : Action V G} : Function.Injective (Hom.hom : (M ⟶ N) → (M.V ⟶ N.V)) := fun _ _ ↦ Hom.ext @[ext] lemma hom_ext {M N : Action V G} (φ₁ φ₂ : M ⟶ N) (h : φ₁.hom = φ₂.hom) : φ₁ = φ₂ := Hom.ext h @[simp] theorem id_hom (M : Action V G) : (𝟙 M : Hom M M).hom = 𝟙 M.V := rfl @[simp, reassoc] theorem comp_hom {M N K : Action V G} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : Hom M K).hom = f.hom ≫ g.hom := rfl @[reassoc (attr := simp)] theorem hom_inv_hom {M N : Action V G} (f : M ≅ N) : f.hom.hom ≫ f.inv.hom = 𝟙 M.V := by rw [← comp_hom, Iso.hom_inv_id, id_hom] @[reassoc (attr := simp)] theorem inv_hom_hom {M N : Action V G} (f : M ≅ N) : f.inv.hom ≫ f.hom.hom = 𝟙 N.V := by rw [← comp_hom, Iso.inv_hom_id, id_hom] /-- Construct an isomorphism of `G` actions/representations from an isomorphism of the underlying objects, where the forward direction commutes with the group action. -/ @[simps] def mkIso {M N : Action V G} (f : M.V ≅ N.V) (comm : ∀ g : G, M.ρ g ≫ f.hom = f.hom ≫ N.ρ g := by cat_disch) : M ≅ N where hom := { hom := f.hom comm := comm } inv := { hom := f.inv comm := fun g => by have w := comm g =≫ f.inv; simp at w; simp [w] } instance (priority := 100) isIso_of_hom_isIso {M N : Action V G} (f : M ⟶ N) [IsIso f.hom] : IsIso f := (mkIso (asIso f.hom) f.comm).isIso_hom instance isIso_hom_mk {M N : Action V G} (f : M.V ⟶ N.V) [IsIso f] (w) : @IsIso _ _ M N (Hom.mk f w) := (mkIso (asIso f) w).isIso_hom instance {M N : Action V G} (f : M ≅ N) : IsIso f.hom.hom where out := ⟨f.inv.hom, by simp⟩ instance {M N : Action V G} (f : M ≅ N) : IsIso f.inv.hom where out := ⟨f.hom.hom, by simp⟩ namespace FunctorCategoryEquivalence /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps] def functor : Action V G ⥤ SingleObj G ⥤ V where obj M := { obj := fun _ => M.V map := fun g => M.ρ g map_id := fun _ => M.ρ.map_one map_comp := fun g h => M.ρ.map_mul h g } map f := { app := fun _ => f.hom naturality := fun _ _ g => f.comm g } /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps] def inverse : (SingleObj G ⥤ V) ⥤ Action V G where obj F := { V := F.obj PUnit.unit ρ := { toFun := fun g => F.map g map_one' := F.map_id PUnit.unit map_mul' := fun g h => F.map_comp h g } } map f := { hom := f.app PUnit.unit comm := fun g => f.naturality g } /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps!] def unitIso : 𝟭 (Action V G) ≅ functor ⋙ inverse := NatIso.ofComponents fun M => mkIso (Iso.refl _) /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps!] def counitIso : inverse ⋙ functor ≅ 𝟭 (SingleObj G ⥤ V) := NatIso.ofComponents fun M => NatIso.ofComponents fun _ => Iso.refl _ end FunctorCategoryEquivalence section open FunctorCategoryEquivalence variable (V G) /-- The category of actions of `G` in the category `V` is equivalent to the functor category `singleObj G ⥤ V`. -/ @[simps] def functorCategoryEquivalence : Action V G ≌ SingleObj G ⥤ V where functor := functor inverse := inverse unitIso := unitIso counitIso := counitIso instance : (FunctorCategoryEquivalence.functor (V := V) (G := G)).IsEquivalence := (functorCategoryEquivalence V G).isEquivalence_functor instance : (FunctorCategoryEquivalence.inverse (V := V) (G := G)).IsEquivalence := (functorCategoryEquivalence V G).isEquivalence_inverse end section Forget variable (V G) /-- (implementation) The forgetful functor from bundled actions to the underlying objects. Use the `CategoryTheory.forget` API provided by the `HasForget` instance below, rather than using this directly. -/ @[simps] def forget : Action V G ⥤ V where obj M := M.V map f := f.hom instance : (forget V G).Faithful where map_injective w := Hom.ext w instance [HasForget V] : HasForget (Action V G) where forget := forget V G ⋙ HasForget.forget /-- The type of `V`-morphisms that can be lifted back to morphisms in the category `Action`. -/ abbrev HomSubtype {FV : V → V → Type*} {CV : V → Type*} [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] (M N : Action V G) := { f : FV M.V N.V // ∀ g : G, f ∘ ConcreteCategory.hom (M.ρ g) = ConcreteCategory.hom (N.ρ g) ∘ f } instance {FV : V → V → Type*} {CV : V → Type*} [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] (M N : Action V G) : FunLike (HomSubtype V G M N) (CV M.V) (CV N.V) where coe f := f.1 coe_injective' _ _ h := Subtype.ext (DFunLike.coe_injective h) instance {FV : V → V → Type*} {CV : V → Type*} [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] : ConcreteCategory (Action V G) (HomSubtype V G) where hom f := ⟨ConcreteCategory.hom (C := V) f.1, fun g => by ext simpa using CategoryTheory.congr_fun (f.2 g) _⟩ ofHom f := ⟨ConcreteCategory.ofHom (C := V) f, fun g => ConcreteCategory.ext_apply fun x => by simpa [ConcreteCategory.hom_ofHom] using congr_fun (f.2 g) x⟩ hom_ofHom _ := by dsimp; ext; simp [ConcreteCategory.hom_ofHom] ofHom_hom _ := by ext; simp [ConcreteCategory.ofHom_hom] id_apply := ConcreteCategory.id_apply (C := V) comp_apply _ _ := ConcreteCategory.comp_apply (C := V) _ _ instance hasForgetToV [HasForget V] : HasForget₂ (Action V G) V where forget₂ := forget V G /-- The forgetful functor is intertwined by `functorCategoryEquivalence` with evaluation at `PUnit.star`. -/ def functorCategoryEquivalenceCompEvaluation : (functorCategoryEquivalence V G).functor ⋙ (evaluation _ _).obj PUnit.unit ≅ forget V G := Iso.refl _ noncomputable instance preservesLimits_forget [HasLimits V] : PreservesLimits (forget V G) := Limits.preservesLimits_of_natIso (Action.functorCategoryEquivalenceCompEvaluation V G) noncomputable instance preservesColimits_forget [HasColimits V] : PreservesColimits (forget V G) := preservesColimits_of_natIso (Action.functorCategoryEquivalenceCompEvaluation V G) -- TODO construct categorical images? end Forget theorem Iso.conj_ρ {M N : Action V G} (f : M ≅ N) (g : G) : N.ρ g = ((forget V G).mapIso f).conj (M.ρ g) := by rw [Iso.conj_apply, Iso.eq_inv_comp]; simp [f.hom.comm] /-- Actions/representations of the trivial group are just objects in the ambient category. -/ def actionPunitEquivalence : Action V PUnit ≌ V where functor := forget V _ inverse := { obj := fun X => ⟨X, 1⟩ map := fun f => ⟨f, fun ⟨⟩ => by simp⟩ } unitIso := NatIso.ofComponents fun X => mkIso (Iso.refl _) fun ⟨⟩ => by simp only [Functor.id_obj, MonoidHom.one_apply, End.one_def, Functor.comp_obj, forget_obj, Iso.refl_hom, Category.comp_id] exact ρ_one X counitIso := NatIso.ofComponents fun _ => Iso.refl _ variable (V) /-- The "restriction" functor along a monoid homomorphism `f : G ⟶ H`, taking actions of `H` to actions of `G`. (This makes sense for any homomorphism, but the name is natural when `f` is a monomorphism.) -/ @[simps] def res {G H : Type*} [Monoid G] [Monoid H] (f : G →* H) : Action V H ⥤ Action V G where obj M := { V := M.V ρ := M.ρ.comp f } map p := { hom := p.hom comm := fun g => p.comm (f g) } /-- The natural isomorphism from restriction along the identity homomorphism to the identity functor on `Action V G`. -/ @[simps!] def resId {G : Type*} [Monoid G] : res V (MonoidHom.id G) ≅ 𝟭 (Action V G) := NatIso.ofComponents fun M => mkIso (Iso.refl _) /-- The natural isomorphism from the composition of restrictions along homomorphisms to the restriction along the composition of homomorphism. -/ @[simps!] def resComp {G H K : Type*} [Monoid G] [Monoid H] [Monoid K] (f : G →* H) (g : H →* K) : res V g ⋙ res V f ≅ res V (g.comp f) := NatIso.ofComponents fun M => mkIso (Iso.refl _) /-- Restricting scalars along equal maps is naturally isomorphic. -/ @[simps! hom inv] def resCongr {G H : Type*} [Monoid G] [Monoid H] {f f' : G →* H} (h : f = f') : Action.res V f ≅ Action.res V f' := NatIso.ofComponents (fun _ ↦ Action.mkIso (Iso.refl _)) /-- Restricting scalars along a monoid isomorphism induces an equivalence of categories. -/ @[simps! functor inverse] def resEquiv {G H : Type*} [Monoid G] [Monoid H] (f : G ≃* H) : Action V H ≌ Action V G where functor := Action.res _ f inverse := Action.res _ f.symm unitIso := Action.resCongr (f := MonoidHom.id H) V (by ext; simp) ≪≫ (Action.resComp _ _ _).symm counitIso := Action.resComp _ _ _ ≪≫ Action.resCongr (f' := MonoidHom.id G) V (by ext; simp) -- TODO promote `res` to a pseudofunctor from -- the locally discrete bicategory constructed from `Monᵒᵖ` to `Cat`, sending `G` to `Action V G`. variable {G H : Type*} [Monoid G] [Monoid H] (f : G →* H) /-- The functor from `Action V H` to `Action V G` induced by a morphism `f : G → H` is faithful. -/ instance : (res V f).Faithful where map_injective {X} {Y} g₁ g₂ h := by ext rw [← res_map_hom _ f g₁, ← res_map_hom _ f g₂, h] /-- The functor from `Action V H` to `Action V G` induced by a morphism `f : G → H` is full if `f` is surjective. -/ lemma full_res (f_surj : Function.Surjective f) : (res V f).Full where map_surjective {X} {Y} g := by use ⟨g.hom, fun h ↦ ?_⟩ · ext simp · obtain ⟨a, rfl⟩ := f_surj h have : X.ρ (f a) = ((res V f).obj X).ρ a := rfl rw [this, g.comm a] simp end Action namespace CategoryTheory.Functor variable {V} {W : Type*} [Category W] /-- A functor between categories induces a functor between the categories of `G`-actions within those categories. -/ @[simps] def mapAction (F : V ⥤ W) (G : Type*) [Monoid G] : Action V G ⥤ Action W G where obj M := { V := F.obj M.V ρ := { toFun := fun g => F.map (M.ρ g) map_one' := by simp map_mul' := fun g h => by dsimp rw [map_mul, End.mul_def, F.map_comp] } } map f := { hom := F.map f.hom comm := fun g => by dsimp; rw [← F.map_comp, f.comm, F.map_comp] } map_id M := by ext; simp only [Action.id_hom, F.map_id] map_comp f g := by ext; simp only [Action.comp_hom, F.map_comp] instance (F : V ⥤ W) (G : Type*) [Monoid G] [F.Faithful] : (F.mapAction G).Faithful where map_injective eq := by ext apply_fun (fun f ↦ f.hom) at eq exact F.map_injective eq /-- A fully faithful functor between categories induces a fully faithful functor between the categories of `G`-actions within those categories. -/ def FullyFaithful.mapAction {F : V ⥤ W} (h : F.FullyFaithful) (G : Type*) [Monoid G] : (F.mapAction G).FullyFaithful where preimage f := by refine ⟨h.preimage f.hom, fun _ ↦ h.map_injective ?_⟩ simp only [map_comp, map_preimage] exact f.comm _ instance (F : V ⥤ W) (G : Type*) [Monoid G] [F.Faithful] [F.Full] : (F.mapAction G).Full := ((Functor.FullyFaithful.ofFullyFaithful F).mapAction G).full variable (G : Type*) [Monoid G] /-- `Functor.mapAction` is functorial in the functor. -/ @[simps! hom inv] def mapActionComp {T : Type*} [Category T] (F : V ⥤ W) (F' : W ⥤ T) : (F ⋙ F').mapAction G ≅ F.mapAction G ⋙ F'.mapAction G := NatIso.ofComponents (fun X ↦ Iso.refl _) /-- `Functor.mapAction` preserves isomorphisms of functors. -/ @[simps! hom inv] def mapActionCongr {F F' : V ⥤ W} (e : F ≅ F') : F.mapAction G ≅ F'.mapAction G := NatIso.ofComponents (fun X ↦ Action.mkIso (e.app X.V)) end Functor /-- An equivalence of categories induces an equivalence of the categories of `G`-actions within those categories. -/ @[simps functor inverse] def Equivalence.mapAction {V W : Type*} [Category V] [Category W] (G : Type*) [Monoid G] (E : V ≌ W) : Action V G ≌ Action W G where functor := E.functor.mapAction G inverse := E.inverse.mapAction G unitIso := Functor.mapActionCongr G E.unitIso ≪≫ Functor.mapActionComp G _ _ counitIso := (Functor.mapActionComp G _ _).symm ≪≫ Functor.mapActionCongr G E.counitIso functor_unitIso_comp X := by ext; simp end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Action/Continuous.lean
import Mathlib.CategoryTheory.Action.Basic import Mathlib.Topology.Algebra.MulAction import Mathlib.Topology.Category.TopCat.Basic import Mathlib.Topology.Algebra.ContinuousMonoidHom /-! # Topological subcategories of `Action V G` For a concrete category `V`, where the forgetful functor factors via `TopCat`, and a monoid `G`, equipped with a topological space instance, we define the full subcategory `ContAction V G` of all objects of `Action V G` where the induced action is continuous. We also define a category `DiscreteContAction V G` as the full subcategory of `ContAction V G`, where the underlying topological space is discrete. Finally we define inclusion functors into `Action V G` and `TopCat` in terms of `HasForget₂` instances. -/ open CategoryTheory Limits variable (V : Type*) [Category V] [HasForget V] [HasForget₂ V TopCat] variable (G : Type*) [Monoid G] [TopologicalSpace G] namespace Action instance : HasForget₂ (Action V G) TopCat := HasForget₂.trans (Action V G) V TopCat instance (X : Action V G) : MulAction G ((CategoryTheory.forget₂ _ TopCat).obj X) where smul g x := ((CategoryTheory.forget₂ _ TopCat).map (X.ρ g)) x one_smul x := by change ((CategoryTheory.forget₂ _ TopCat).map (X.ρ 1)) x = x simp mul_smul g h x := by change (CategoryTheory.forget₂ _ TopCat).map (X.ρ (g * h)) x = ((CategoryTheory.forget₂ _ TopCat).map (X.ρ h) ≫ (CategoryTheory.forget₂ _ TopCat).map (X.ρ g)) x rw [← Functor.map_comp, map_mul] rfl variable {V G} /-- For `HasForget₂ V TopCat` a predicate on an `X : Action V G` saying that the induced action on the underlying topological space is continuous. -/ abbrev IsContinuous (X : Action V G) : Prop := ContinuousSMul G ((CategoryTheory.forget₂ _ TopCat).obj X) lemma isContinuous_def (X : Action V G) : X.IsContinuous ↔ Continuous (fun p : G × (forget₂ _ TopCat).obj X ↦ (forget₂ _ TopCat).map (X.ρ p.1) p.2) := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩ end Action open Action /-- For `HasForget₂ V TopCat`, this is the full subcategory of `Action V G` where the induced action is continuous. -/ def ContAction : Type _ := ObjectProperty.FullSubcategory (IsContinuous (V := V) (G := G)) namespace ContAction instance : Category (ContAction V G) := ObjectProperty.FullSubcategory.category (IsContinuous (V := V) (G := G)) instance : HasForget (ContAction V G) := FullSubcategory.hasForget (IsContinuous (V := V) (G := G)) instance {FV : V → V → Type*} {CV : V → Type*} [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] : ConcreteCategory (ContAction V G) (fun X Y => Action.HomSubtype V G X.1 Y.1) := FullSubcategory.concreteCategory (IsContinuous (V := V) (G := G)) instance : HasForget₂ (ContAction V G) (Action V G) := FullSubcategory.hasForget₂ (IsContinuous (V := V) (G := G)) instance : HasForget₂ (ContAction V G) V := HasForget₂.trans (ContAction V G) (Action V G) V instance : HasForget₂ (ContAction V G) TopCat := HasForget₂.trans (ContAction V G) (Action V G) TopCat instance : Coe (ContAction V G) (Action V G) where coe X := X.obj variable {V G} /-- A predicate on an `X : ContAction V G` saying that the topology on the underlying type of `X` is discrete. -/ abbrev IsDiscrete (X : ContAction V G) : Prop := DiscreteTopology ((CategoryTheory.forget₂ _ TopCat).obj X) variable (V) {H : Type*} [Monoid H] [TopologicalSpace H] /-- The "restriction" functor along a monoid homomorphism `f : G →* H`, taking actions of `H` to actions of `G`. This is the analogue of `Action.res` in the continuous setting. -/ @[simps! obj_obj map] def res (f : G →ₜ* H) : ContAction V H ⥤ ContAction V G := ObjectProperty.lift _ (ObjectProperty.ι _ ⋙ Action.res _ f) fun X ↦ by constructor let v : G × (forget₂ _ TopCat).obj X → H × (forget₂ _ TopCat).obj X := fun p ↦ (f p.1, p.2) have : Continuous v := by fun_prop let u : H × (forget₂ _ TopCat).obj X → (forget₂ _ TopCat).obj X := fun p ↦ (forget₂ _ TopCat).map (X.obj.ρ p.1) p.2 have : Continuous u := X.2.1 change Continuous (u ∘ v) fun_prop /-- Restricting scalars along a composition is naturally isomorphic to restricting scalars twice. -/ @[simps! hom inv] def resComp {K : Type*} [Monoid K] [TopologicalSpace K] (f : G →ₜ* H) (h : H →ₜ* K) : ContAction.res V (h.comp f) ≅ ContAction.res V h ⋙ ContAction.res V f := NatIso.ofComponents (fun _ ↦ Iso.refl _) /-- If `f = f'`, restriction of scalars along `f` and `f'` is the same. -/ @[simps! hom inv] def resCongr (f f' : G →ₜ* H) (h : f = f') : ContAction.res V f ≅ ContAction.res V f' := NatIso.ofComponents (fun _ ↦ ObjectProperty.isoMk _ (Action.mkIso (Iso.refl _) (by subst h; simp))) fun f ↦ by apply Action.Hom.ext rw [ObjectProperty.FullSubcategory.comp_def, ObjectProperty.FullSubcategory.comp_def] simp /-- Restriction of scalars along a topological monoid isomorphism induces an equivalence of categories. -/ @[simps! functor inverse] def resEquiv (f : G ≃ₜ* H) : ContAction V H ≌ ContAction V G where functor := res _ f inverse := res _ f.symm unitIso := resCongr V (ContinuousMonoidHom.id H) _ (by ext; simp) ≪≫ ContAction.resComp _ _ _ counitIso := (ContAction.resComp _ _ _).symm ≪≫ ContAction.resCongr V _ (ContinuousMonoidHom.id G) (by ext; simp) functor_unitIso_comp X := (Action.resEquiv V f.toMulEquiv).functor_unitIso_comp X.obj end ContAction open ContAction /-- The subcategory of `ContAction V G` where the topology is discrete. -/ def DiscreteContAction : Type _ := ObjectProperty.FullSubcategory (IsDiscrete (V := V) (G := G)) namespace DiscreteContAction instance : Category (DiscreteContAction V G) := ObjectProperty.FullSubcategory.category (IsDiscrete (V := V) (G := G)) instance : HasForget (DiscreteContAction V G) := FullSubcategory.hasForget (IsDiscrete (V := V) (G := G)) instance {FV : V → V → Type*} {CV : V → Type*} [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] : ConcreteCategory (DiscreteContAction V G) (fun X Y => Action.HomSubtype V G X.1 Y.1) := FullSubcategory.concreteCategory (IsDiscrete (V := V) (G := G)) instance : HasForget₂ (DiscreteContAction V G) (ContAction V G) := FullSubcategory.hasForget₂ (IsDiscrete (V := V) (G := G)) instance : HasForget₂ (DiscreteContAction V G) TopCat := HasForget₂.trans (DiscreteContAction V G) (ContAction V G) TopCat variable {V G} instance (X : DiscreteContAction V G) : DiscreteTopology ((CategoryTheory.forget₂ _ TopCat).obj X) := X.property end DiscreteContAction namespace CategoryTheory variable {V W : Type*} [Category V] [HasForget V] [HasForget₂ V TopCat] [Category W] [HasForget W] [HasForget₂ W TopCat] (G : Type*) [Monoid G] [TopologicalSpace G] namespace Functor /-- Continuous version of `Functor.mapAction`. -/ @[simps! obj_obj map] def mapContAction (F : V ⥤ W) (H : ∀ X : ContAction V G, ((F.mapAction G).obj X.obj).IsContinuous) : ContAction V G ⥤ ContAction W G := ObjectProperty.lift _ (ObjectProperty.ι _ ⋙ F.mapAction G) H /-- Continuous version of `Functor.mapActionComp`. -/ @[simps! hom inv] def mapContActionComp {T : Type*} [Category T] [HasForget T] [HasForget₂ T TopCat] (F : V ⥤ W) (H : ∀ X : ContAction V G, ((F.mapAction G).obj X.obj).IsContinuous) (F' : W ⥤ T) (H' : ∀ X : ContAction W G, ((F'.mapAction G).obj X.obj).IsContinuous) : Functor.mapContAction G (F ⋙ F') (fun X ↦ H' ((F.mapContAction G H).obj X)) ≅ Functor.mapContAction G F H ⋙ Functor.mapContAction G F' H' := NatIso.ofComponents (fun _ ↦ Iso.refl _) /-- Continuous version of `Functor.mapActionCongr`. -/ @[simps! hom inv] def mapContActionCongr {F : V ⥤ W} {F' : V ⥤ W} (e : F ≅ F') (H : ∀ X : ContAction V G, ((F.mapAction G).obj X.obj).IsContinuous) (H' : ∀ X : ContAction V G, ((F'.mapAction G).obj X.obj).IsContinuous) : Functor.mapContAction G F H ≅ Functor.mapContAction G F' H' := NatIso.ofComponents (fun X ↦ ObjectProperty.isoMk _ (Action.mkIso (e.app X.obj.V) (by simp))) <| (fun f ↦ (Functor.mapActionCongr G e).hom.naturality f) end Functor /-- Continuous version of `Equivalence.mapAction`. -/ @[simps functor inverse] def Equivalence.mapContAction (E : V ≌ W) (H₁ : ∀ X : ContAction V G, ((E.functor.mapAction G).obj X.obj).IsContinuous) (H₂ : ∀ X : ContAction W G, ((E.inverse.mapAction G).obj X.obj).IsContinuous) : ContAction V G ≌ ContAction W G where functor := E.functor.mapContAction G H₁ inverse := E.inverse.mapContAction G H₂ unitIso := Functor.mapContActionCongr G E.unitIso (fun X ↦ X.2) (fun X ↦ H₂ ((E.functor.mapContAction G H₁).obj X)) ≪≫ Functor.mapContActionComp G _ _ _ _ counitIso := (Functor.mapContActionComp G _ _ _ _).symm ≪≫ Functor.mapContActionCongr G E.counitIso _ (fun X ↦ X.2) functor_unitIso_comp X := (E.mapAction G).functor_unitIso_comp X.obj end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Action/Limits.lean
import Mathlib.CategoryTheory.Abelian.FunctorCategory import Mathlib.CategoryTheory.Abelian.Transfer import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.CategoryTheory.Linear.FunctorCategory import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Action.Basic /-! # Categorical properties of `Action V G` We show: * When `V` has (co)limits so does `Action V G`. * When `V` is preadditive, linear, or abelian so is `Action V G`. -/ universe u v w₁ w₂ t₁ t₂ open CategoryTheory Limits variable {V : Type*} [Category V] {G : Type*} [Monoid G] namespace Action section Limits instance [HasFiniteProducts V] : HasFiniteProducts (Action V G) where out _ := Adjunction.hasLimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasFiniteLimits V] : HasFiniteLimits (Action V G) where out _ _ _ := Adjunction.hasLimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasLimits V] : HasLimits (Action V G) := Adjunction.has_limits_of_equivalence (Action.functorCategoryEquivalence _ _).functor /-- If `V` has limits of shape `J`, so does `Action V G`. -/ instance hasLimitsOfShape {J : Type*} [Category J] [HasLimitsOfShape J V] : HasLimitsOfShape J (Action V G) := Adjunction.hasLimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasFiniteCoproducts V] : HasFiniteCoproducts (Action V G) where out _ := Adjunction.hasColimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasFiniteColimits V] : HasFiniteColimits (Action V G) where out _ _ _ := Adjunction.hasColimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasColimits V] : HasColimits (Action V G) := Adjunction.has_colimits_of_equivalence (Action.functorCategoryEquivalence _ _).functor /-- If `V` has colimits of shape `J`, so does `Action V G`. -/ instance hasColimitsOfShape {J : Type*} [Category J] [HasColimitsOfShape J V] : HasColimitsOfShape J (Action V G) := Adjunction.hasColimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor end Limits section Preservation variable {C : Type*} [Category C] /-- `F : C ⥤ SingleObj G ⥤ V` preserves the limit of some `K : J ⥤ C` if it does evaluated at `SingleObj.star G`. -/ private lemma SingleObj.preservesLimit (F : C ⥤ SingleObj G ⥤ V) {J : Type*} [Category J] (K : J ⥤ C) (h : PreservesLimit K (F ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G))) : PreservesLimit K F := by apply preservesLimit_of_evaluation intro _ exact h /-- `F : C ⥤ Action V G` preserves the limit of some `K : J ⥤ C` if if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ lemma preservesLimit_of_preserves (F : C ⥤ Action V G) {J : Type*} [Category J] (K : J ⥤ C) (h : PreservesLimit K (F ⋙ Action.forget V G)) : PreservesLimit K F := by let F' : C ⥤ SingleObj G ⥤ V := F ⋙ (Action.functorCategoryEquivalence V G).functor have : PreservesLimit K F' := SingleObj.preservesLimit _ _ h apply preservesLimit_of_reflects_of_preserves F (Action.functorCategoryEquivalence V G).functor /-- `F : C ⥤ Action V G` preserves limits of some shape `J` if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ lemma preservesLimitsOfShape_of_preserves (F : C ⥤ Action V G) {J : Type*} [Category J] (h : PreservesLimitsOfShape J (F ⋙ Action.forget V G)) : PreservesLimitsOfShape J F := by constructor intro K apply Action.preservesLimit_of_preserves exact PreservesLimitsOfShape.preservesLimit /-- `F : C ⥤ Action V G` preserves limits of some size if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ lemma preservesLimitsOfSize_of_preserves (F : C ⥤ Action V G) (h : PreservesLimitsOfSize.{w₂, w₁} (F ⋙ Action.forget V G)) : PreservesLimitsOfSize.{w₂, w₁} F := by constructor intro J _ apply Action.preservesLimitsOfShape_of_preserves exact PreservesLimitsOfSize.preservesLimitsOfShape /-- `F : C ⥤ SingleObj G ⥤ V` preserves the colimit of some `K : J ⥤ C` if it does evaluated at `SingleObj.star G`. -/ private lemma SingleObj.preservesColimit (F : C ⥤ SingleObj G ⥤ V) {J : Type*} [Category J] (K : J ⥤ C) (h : PreservesColimit K (F ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G))) : PreservesColimit K F := by apply preservesColimit_of_evaluation intro _ exact h /-- `F : C ⥤ Action V G` preserves the colimit of some `K : J ⥤ C` if if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ lemma preservesColimit_of_preserves (F : C ⥤ Action V G) {J : Type*} [Category J] (K : J ⥤ C) (h : PreservesColimit K (F ⋙ Action.forget V G)) : PreservesColimit K F := by let F' : C ⥤ SingleObj G ⥤ V := F ⋙ (Action.functorCategoryEquivalence V G).functor have : PreservesColimit K F' := SingleObj.preservesColimit _ _ h apply preservesColimit_of_reflects_of_preserves F (Action.functorCategoryEquivalence V G).functor /-- `F : C ⥤ Action V G` preserves colimits of some shape `J` if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ lemma preservesColimitsOfShape_of_preserves (F : C ⥤ Action V G) {J : Type*} [Category J] (h : PreservesColimitsOfShape J (F ⋙ Action.forget V G)) : PreservesColimitsOfShape J F := by constructor intro K apply Action.preservesColimit_of_preserves exact PreservesColimitsOfShape.preservesColimit /-- `F : C ⥤ Action V G` preserves colimits of some size if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ lemma preservesColimitsOfSize_of_preserves (F : C ⥤ Action V G) (h : PreservesColimitsOfSize.{w₂, w₁} (F ⋙ Action.forget V G)) : PreservesColimitsOfSize.{w₂, w₁} F := by constructor intro J _ apply Action.preservesColimitsOfShape_of_preserves exact PreservesColimitsOfSize.preservesColimitsOfShape end Preservation section Forget /-- `Action.forget V G : Action V G ⥤ V` preserves the limit of some `K : J ⥤ Action V G` if `K ⋙ Action.forget V G` has a limit. -/ noncomputable instance {J : Type*} [Category J] (K : J ⥤ Action V G) [HasLimit (K ⋙ forget V G)] : PreservesLimit K (Action.forget V G) := by change PreservesLimit K ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) have (k : SingleObj G) : HasLimit ((K ⋙ (functorCategoryEquivalence V G).functor).flip.obj k) := inferInstanceAs (HasLimit (K ⋙ forget V G)) infer_instance noncomputable instance {J : Type*} [Category J] [HasLimitsOfShape J V] : PreservesLimitsOfShape J (Action.forget V G) where /-- `Action.forget V G : Action V G ⥤ V` preserves the colimit of some `K : J ⥤ Action V G` if `K ⋙ Action.forget V G` has a colimit. -/ noncomputable instance {J : Type*} [Category J] (K : J ⥤ Action V G) [HasColimit (K ⋙ forget V G)] : PreservesColimit K (Action.forget V G) := by change PreservesColimit K ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) have (k : SingleObj G) : HasColimit ((K ⋙ (functorCategoryEquivalence V G).functor).flip.obj k) := inferInstanceAs (HasColimit (K ⋙ forget V G)) infer_instance noncomputable instance {J : Type*} [Category J] [HasColimitsOfShape J V] : PreservesColimitsOfShape J (Action.forget V G) where noncomputable instance [HasFiniteLimits V] : PreservesFiniteLimits (Action.forget V G) := by change PreservesFiniteLimits ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) have : PreservesFiniteLimits ((evaluation (SingleObj G) V).obj (SingleObj.star G)) := by constructor intro _ _ _ infer_instance apply comp_preservesFiniteLimits noncomputable instance [HasFiniteColimits V] : PreservesFiniteColimits (Action.forget V G) := by change PreservesFiniteColimits ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) have : PreservesFiniteColimits ((evaluation (SingleObj G) V).obj (SingleObj.star G)) := by constructor intro _ _ _ infer_instance apply comp_preservesFiniteColimits instance {J : Type*} [Category J] (F : J ⥤ Action V G) : ReflectsLimit F (Action.forget V G) where reflects h := ⟨by apply isLimitOfReflects ((Action.functorCategoryEquivalence V G).functor) exact evaluationJointlyReflectsLimits _ (fun _ => h)⟩ instance {J : Type*} [Category J] : ReflectsLimitsOfShape J (Action.forget V G) where instance : ReflectsLimits (Action.forget V G) where instance {J : Type*} [Category J] (F : J ⥤ Action V G) : ReflectsColimit F (Action.forget V G) where reflects h := ⟨by apply isColimitOfReflects ((Action.functorCategoryEquivalence V G).functor) exact evaluationJointlyReflectsColimits _ (fun _ => h)⟩ noncomputable instance {J : Type*} [Category J] : ReflectsColimitsOfShape J (Action.forget V G) where noncomputable instance : ReflectsColimits (Action.forget V G) where end Forget namespace Functor variable {W : Type*} [Category W] (F : V ⥤ W) (G : Type*) [Monoid G] {J : Type*} [Category J] /-- `F.mapAction : Action V G ⥤ Action W G` preserves the limit of some `K : J ⥤ Action V G` if `K ⋙ forget V G` has a limit and `F` preserves the limit of `K ⋙ forget V G`. -/ instance mapActionPreservesLimit_of_preserves (K : J ⥤ Action V G) [HasLimit (K ⋙ forget V G)] [PreservesLimit (K ⋙ Action.forget V G) F] : PreservesLimit K (F.mapAction G) := Action.preservesLimit_of_preserves (F.mapAction G) K <| inferInstanceAs (PreservesLimit K (forget V G ⋙ F)) /-- `F.mapAction : Action V G ⥤ Action W G` preserves limits of some shape `J` if `V` has limits of shape `J` and `F` preserves limits of shape `J`. -/ instance mapActionPreservesLimitsOfShapeOfPreserves [PreservesLimitsOfShape J F] [HasLimitsOfShape J V] : PreservesLimitsOfShape J (F.mapAction G) where /-- `F.mapAction : Action V G ⥤ Action W G` preserves limits of some size if `V` has limits of that size and `F` preserves limits of that size. -/ instance preservesLimitsOfSize_of_preserves [PreservesLimitsOfSize.{w₂, w₁} F] [HasLimitsOfSize.{w₂, w₁} V] : PreservesLimitsOfSize.{w₂, w₁} (F.mapAction G) where /-- `F.mapAction : Action V G ⥤ Action W G` preserves finite limits if `V` has finite limits and `F` preserves finite limits. -/ instance [PreservesFiniteLimits F] [HasFiniteLimits V] : PreservesFiniteLimits (F.mapAction G) where preservesFiniteLimits _ _ _ := inferInstance /-- `F.mapAction : Action V G ⥤ Action W G` preserves the colimit of some `K : J ⥤ Action V G` if `K ⋙ forget V G` has a colimit and `F` preserves the colimit of `K ⋙ forget V G`. -/ instance mapActionPreservesColimit_of_preserves (K : J ⥤ Action V G) [HasColimit (K ⋙ forget V G)] [PreservesColimit (K ⋙ Action.forget V G) F] : PreservesColimit K (F.mapAction G) := Action.preservesColimit_of_preserves (F.mapAction G) K <| inferInstanceAs (PreservesColimit K (forget V G ⋙ F)) /-- `F.mapAction : Action V G ⥤ Action W G` preserves colimits of some shape `J` if `V` has colimits of shape `J` and `F` preserves colimits of shape `J`. -/ instance mapActionPreservesColimitsOfShapeOfPreserves [PreservesColimitsOfShape J F] [HasColimitsOfShape J V] : PreservesColimitsOfShape J (F.mapAction G) where /-- `F.mapAction : Action V G ⥤ Action W G` preserves colimits of some size if `V` has colimits of that size and `F` preserves colimits of that size. -/ instance preservesColimitsOfSize_of_preserves [PreservesColimitsOfSize.{w₂, w₁} F] [HasColimitsOfSize.{w₂, w₁} V] : PreservesColimitsOfSize.{w₂, w₁} (F.mapAction G) where /-- `F.mapAction : Action V G ⥤ Action W G` preserves finite colimits if `V` has finite colimits and `F` preserves finite colimits. -/ instance [PreservesFiniteColimits F] [HasFiniteColimits V] : PreservesFiniteColimits (F.mapAction G) where preservesFiniteColimits _ _ _ := inferInstance end Functor section HasZeroMorphisms variable [HasZeroMorphisms V] instance {X Y : Action V G} : Zero (X ⟶ Y) := ⟨0, by simp⟩ @[simp] theorem zero_hom {X Y : Action V G} : (0 : X ⟶ Y).hom = 0 := rfl instance : HasZeroMorphisms (Action V G) where instance forget_preservesZeroMorphisms : Functor.PreservesZeroMorphisms (forget V G) where instance forget₂_preservesZeroMorphisms [HasForget V] : Functor.PreservesZeroMorphisms (forget₂ (Action V G) V) where instance functorCategoryEquivalence_preservesZeroMorphisms : Functor.PreservesZeroMorphisms (functorCategoryEquivalence V G).functor where end HasZeroMorphisms section Preadditive variable [Preadditive V] {X Y : Action V G} instance : Add (X ⟶ Y) where add f g := ⟨f.hom + g.hom, by simp [f.comm, g.comm]⟩ instance : Neg (X ⟶ Y) where neg f := ⟨-f.hom, by simp [f.comm]⟩ instance : Sub (X ⟶ Y) where sub f g := ⟨f.hom - g.hom, by simp [f.comm, g.comm]⟩ instance : SMul ℕ (X ⟶ Y) where smul n f := ⟨n • f.hom, by simp [f.comm]⟩ instance : SMul ℤ (X ⟶ Y) where smul n f := ⟨n • f.hom, by simp [f.comm]⟩ @[simp] lemma add_hom (f g : X ⟶ Y) : (f + g).hom = f.hom + g.hom := rfl @[simp] lemma neg_hom (f : X ⟶ Y) : (-f).hom = -f.hom := rfl @[simp] lemma sub_hom (f g : X ⟶ Y) : (f - g).hom = f.hom - g.hom := rfl @[simp] lemma nsmul_hom (n : ℕ) (f : X ⟶ Y) : (n • f).hom = n • f.hom := rfl @[simp] lemma zsmul_hom (n : ℤ) (f : X ⟶ Y) : (n • f).hom = n • f.hom := rfl instance : Preadditive (Action V G) where homGroup X Y := hom_injective.addCommGroup (M₂ := X.V ⟶ Y.V) _ zero_hom add_hom neg_hom sub_hom (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) add_comp := by intros; ext; exact Preadditive.add_comp _ _ _ _ _ _ comp_add := by intros; ext; exact Preadditive.comp_add _ _ _ _ _ _ instance forget_additive : Functor.Additive (forget V G) where instance forget₂_additive [HasForget V] : Functor.Additive (forget₂ (Action V G) V) where instance functorCategoryEquivalence_additive : Functor.Additive (functorCategoryEquivalence V G).functor where @[simp] theorem sum_hom {ι : Type*} (f : ι → (X ⟶ Y)) (s : Finset ι) : (s.sum f).hom = s.sum fun i => (f i).hom := (forget V G).map_sum f s end Preadditive section Linear variable [Preadditive V] {R : Type*} [Semiring R] [Linear R V] instance : Linear R (Action V G) where homModule X Y := { smul := fun r f => ⟨r • f.hom, by simp [f.comm]⟩ one_smul := by intros; ext; exact one_smul _ _ smul_zero := by intros; ext; exact smul_zero _ zero_smul := by intros; ext; exact zero_smul _ _ add_smul := by intros; ext; exact add_smul _ _ _ smul_add := by intros; ext; exact smul_add _ _ _ mul_smul := by intros; ext; exact mul_smul _ _ _ } smul_comp := by intros; ext; exact Linear.smul_comp _ _ _ _ _ _ comp_smul := by intros; ext; exact Linear.comp_smul _ _ _ _ _ _ instance forget_linear : Functor.Linear R (forget V G) where instance forget₂_linear [HasForget V] : Functor.Linear R (forget₂ (Action V G) V) where instance functorCategoryEquivalence_linear : Functor.Linear R (functorCategoryEquivalence V G).functor where @[simp] theorem smul_hom {X Y : Action V G} (r : R) (f : X ⟶ Y) : (r • f).hom = r • f.hom := rfl variable {H : Type*} [Monoid H] (f : G →* H) instance res_additive : (res V f).Additive where instance res_linear : (res V f).Linear R where end Linear section Abelian /-- Auxiliary construction for the `Abelian (Action V G)` instance. -/ def abelianAux : Action V G ≌ (SingleObj G) ⥤ V := functorCategoryEquivalence V G noncomputable instance [Abelian V] : Abelian (Action V G) := abelianOfEquivalence abelianAux.functor end Abelian end Action namespace CategoryTheory.Functor variable {W : Type*} [Category W] (F : V ⥤ W) (G : Type*) [Monoid G] [Preadditive V] [Preadditive W] instance mapAction_preadditive [F.Additive] : (F.mapAction G).Additive where variable {R : Type*} [Semiring R] [CategoryTheory.Linear R V] [CategoryTheory.Linear R W] instance mapAction_linear [F.Linear R] : (F.mapAction G).Linear R where end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/CategoryTheory/Action/Concrete.lean
import Mathlib.Algebra.Group.Action.End import Mathlib.Algebra.Group.Action.Pi import Mathlib.CategoryTheory.Action.Basic import Mathlib.CategoryTheory.FintypeCat import Mathlib.GroupTheory.GroupAction.Quotient import Mathlib.GroupTheory.QuotientGroup.Defs /-! # Constructors for `Action V G` for some concrete categories We construct `Action (Type*) G` from a `[MulAction G X]` instance and give some applications. -/ assert_not_exists Field universe u v open CategoryTheory Limits namespace Action section variable {G : Type u} [Group G] {A : Action (Type u) G} @[simp] theorem ρ_inv_self_apply (g : G) (x : A.V) : A.ρ g⁻¹ (A.ρ g x) = x := show (A.ρ g⁻¹ * A.ρ g) x = x by simp [← map_mul] @[simp] theorem ρ_self_inv_apply (g : G) (x : A.V) : A.ρ g (A.ρ g⁻¹ x) = x := show (A.ρ g * A.ρ g⁻¹) x = x by simp [← map_mul] end /-- Bundles a type `H` with a multiplicative action of `G` as an `Action`. -/ @[simps -isSimp] def ofMulAction (G : Type*) (H : Type u) [Monoid G] [MulAction G H] : Action (Type u) G where V := H ρ := @MulAction.toEndHom _ _ _ (by assumption) @[simp] theorem ofMulAction_apply {G H : Type*} [Monoid G] [MulAction G H] (g : G) (x : H) : (ofMulAction G H).ρ g x = (g • x : H) := rfl /-- Given a family `F` of types with `G`-actions, this is the limit cone demonstrating that the product of `F` as types is a product in the category of `G`-sets. -/ def ofMulActionLimitCone {ι : Type v} (G : Type max v u) [Monoid G] (F : ι → Type max v u) [∀ i : ι, MulAction G (F i)] : LimitCone (Discrete.functor fun i : ι => Action.ofMulAction G (F i)) where cone := { pt := Action.ofMulAction G (∀ i : ι, F i) π := Discrete.natTrans (fun i => ⟨fun x => x i.as, fun _ => rfl⟩) } isLimit := { lift := fun s => { hom := fun x i => (s.π.app ⟨i⟩).hom x comm := fun g => by ext x funext j exact congr_fun ((s.π.app ⟨j⟩).comm g) x } fac := fun _ _ => rfl uniq := fun s f h => by ext x funext j dsimp at * rw [← h ⟨j⟩] rfl } /-- The `G`-set `G`, acting on itself by left multiplication. -/ abbrev leftRegular (G : Type u) [Monoid G] : Action (Type u) G := Action.ofMulAction G G /-- The `G`-set `Gⁿ`, acting on itself by left multiplication. -/ abbrev diagonal (G : Type u) [Monoid G] (n : ℕ) : Action (Type u) G := Action.ofMulAction G (Fin n → G) /-- We have `Fin 1 → G ≅ G` as `G`-sets, with `G` acting by left multiplication. -/ def diagonalOneIsoLeftRegular (G : Type*) [Monoid G] : diagonal G 1 ≅ leftRegular G := Action.mkIso (Equiv.funUnique _ _).toIso fun _ => rfl namespace FintypeCat /-- If `X` is a type with `[Fintype X]` and `G` acts on `X`, then `G` also acts on `FintypeCat.of X`. -/ instance (G : Type*) (X : Type*) [Monoid G] [MulAction G X] [Fintype X] : MulAction G (FintypeCat.of X) := inferInstanceAs <| MulAction G X /-- Bundles a finite type `H` with a multiplicative action of `G` as an `Action`. -/ def ofMulAction (G : Type*) (H : FintypeCat.{u}) [Monoid G] [MulAction G H] : Action FintypeCat G where V := H ρ := @MulAction.toEndHom _ _ _ (by assumption) @[simp] theorem ofMulAction_apply {G : Type*} {H : FintypeCat.{u}} [Monoid G] [MulAction G H] (g : G) (x : H) : (FintypeCat.ofMulAction G H).ρ g x = (g • x : H) := rfl section /-- Shorthand notation for the quotient of `G` by `H` as a finite `G`-set. -/ notation:10 G:10 " ⧸ₐ " H:10 => Action.FintypeCat.ofMulAction G (FintypeCat.of <| G ⧸ H) variable {G : Type*} [Group G] (H N : Subgroup G) [Fintype (G ⧸ N)] /-- If `N` is a normal subgroup of `G`, then this is the group homomorphism sending an element `g` of `G` to the `G`-endomorphism of `G ⧸ₐ N` given by multiplication with `g⁻¹` on the right. -/ def toEndHom [N.Normal] : G →* End (G ⧸ₐ N) where toFun v := { hom := Quotient.lift (fun σ ↦ ⟦σ * v⁻¹⟧) <| fun a b h ↦ Quotient.sound <| by apply (QuotientGroup.leftRel_apply).mpr -- We avoid `group` here to minimize imports while low in the hierarchy; -- typically it would be better to invoke the tactic. simpa [mul_assoc] using Subgroup.Normal.conj_mem ‹_› _ (QuotientGroup.leftRel_apply.mp h) _ comm := fun (g : G) ↦ by ext (x : G ⧸ N) induction x using Quotient.inductionOn with | _ x simp only [FintypeCat.comp_apply, Action.FintypeCat.ofMulAction_apply, Quotient.lift_mk] change Quotient.lift (fun σ ↦ ⟦σ * v⁻¹⟧) _ (⟦g • x⟧) = _ simp only [smul_eq_mul, Quotient.lift_mk, mul_assoc] rfl } map_one' := by apply Action.hom_ext ext (x : G ⧸ N) induction x using Quotient.inductionOn simp map_mul' σ τ := by apply Action.hom_ext ext (x : G ⧸ N) induction x using Quotient.inductionOn with | _ x change ⟦x * (σ * τ)⁻¹⟧ = ⟦x * τ⁻¹ * σ⁻¹⟧ rw [mul_inv_rev, mul_assoc] @[simp] lemma toEndHom_apply [N.Normal] (g h : G) : (toEndHom N g).hom ⟦h⟧ = ⟦h * g⁻¹⟧ := rfl variable {N} in lemma toEndHom_trivial_of_mem [N.Normal] {n : G} (hn : n ∈ N) : toEndHom N n = 𝟙 (G ⧸ₐ N) := by apply Action.hom_ext ext (x : G ⧸ N) induction x using Quotient.inductionOn exact Quotient.sound ((QuotientGroup.leftRel_apply).mpr <| by simpa) /-- If `H` and `N` are subgroups of a group `G` with `N` normal, there is a canonical group homomorphism `H ⧸ N ⊓ H` to the `G`-endomorphisms of `G ⧸ N`. -/ def quotientToEndHom [N.Normal] : H ⧸ Subgroup.subgroupOf N H →* End (G ⧸ₐ N) := QuotientGroup.lift (Subgroup.subgroupOf N H) ((toEndHom N).comp H.subtype) <| fun _ uinU' ↦ toEndHom_trivial_of_mem uinU' @[simp] lemma quotientToEndHom_mk [N.Normal] (x : H) (g : G) : (quotientToEndHom H N ⟦x⟧).hom ⟦g⟧ = ⟦g * x⁻¹⟧ := rfl /-- If `N` and `H` are subgroups of a group `G` with `N ≤ H`, this is the canonical `G`-morphism `G ⧸ N ⟶ G ⧸ H`. -/ def quotientToQuotientOfLE [Fintype (G ⧸ H)] (h : N ≤ H) : (G ⧸ₐ N) ⟶ (G ⧸ₐ H) where hom := Quotient.lift _ <| fun _ _ hab ↦ Quotient.sound <| (QuotientGroup.leftRel_apply).mpr (h <| (QuotientGroup.leftRel_apply).mp hab) comm g := by ext (x : G ⧸ N) induction x using Quotient.inductionOn rfl @[simp] lemma quotientToQuotientOfLE_hom_mk [Fintype (G ⧸ H)] (h : N ≤ H) (x : G) : (quotientToQuotientOfLE H N h).hom ⟦x⟧ = ⟦x⟧ := rfl end end FintypeCat section ToMulAction variable {V : Type (u + 1)} [LargeCategory V] {FV : V → V → Type*} {CV : V → Type*} variable [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] instance instMulAction {G : Type*} [Monoid G] (X : Action V G) : MulAction G (ToType X) where smul g x := ConcreteCategory.hom (X.ρ g) x one_smul x := by change ConcreteCategory.hom (X.ρ 1) x = x simp mul_smul g h x := by change ConcreteCategory.hom (X.ρ (g * h)) x = ConcreteCategory.hom (X.ρ g) ((ConcreteCategory.hom (X.ρ h)) x) simp /- Specialize `instMulAction` to assist typeclass inference. -/ instance {G : Type*} [Monoid G] (X : Action FintypeCat G) : MulAction G X.V := Action.instMulAction X end ToMulAction end Action
.lake/packages/mathlib/Mathlib/CategoryTheory/Equivalence/Symmetry.lean
import Mathlib.CategoryTheory.Equivalence import Mathlib.CategoryTheory.Adjunction.Mates /-! # Functoriality of the symmetry of equivalences Using the calculus of mates in `Mathlib.CategoryTheory.Adjunction.Mates`, we prove that passing to the symmetric equivalence defines an equivalence between `C ≌ D` and `(D ≌ C)ᵒᵖ`, and provides the definition of the functor that takes an equivalence to its inverse. ## Main definitions - `Equivalence.symmEquiv C D`: the equivalence `(C ≌ D) ≌ (D ≌ C)ᵒᵖ` obtained by taking `Equivalence.symm` on objects, and `conjugateEquiv` on maps. - `Equivalence.inverseFunctor C D`: The functor `(C ≌ D) ⥤ (D ⥤ C)ᵒᵖ` sending an equivalence `e` to the functor `e.inverse`. - `congrLeftFunctor C D E`: the functor (C ≌ D) ⥤ ((C ⥤ E) ≌ (D ⥤ E))ᵒᵖ that applies `Equivalence.congrLeft` on objects, and whiskers left by `conjugateEquiv` on maps. -/ namespace CategoryTheory open CategoryTheory.Functor NatIso Category namespace Equivalence variable (C : Type*) [Category C] (D : Type*) [Category D] /-- The forward functor of the equivalence `(C ≌ D) ≌ (D ≌ C)ᵒᵖ`. -/ @[simps] def symmEquivFunctor : (C ≌ D) ⥤ (D ≌ C)ᵒᵖ where obj e := Opposite.op e.symm map {e f} α := (mkHom <| conjugateEquiv f.toAdjunction e.toAdjunction <| asNatTrans α).op map_comp _ _ := Quiver.Hom.unop_inj (by cat_disch) /-- The inverse functor of the equivalence `(C ≌ D) ≌ (D ≌ C)ᵒᵖ`. -/ @[simps!] def symmEquivInverse : (D ≌ C)ᵒᵖ ⥤ (C ≌ D) := Functor.leftOp { obj e := Opposite.op e.symm map {e f} α := Quiver.Hom.op <| mkHom <| conjugateEquiv e.symm.toAdjunction f.symm.toAdjunction |>.invFun <| asNatTrans α map_comp _ _ := Quiver.Hom.unop_inj (by cat_disch) } /-- Taking the symmetric of an equivalence induces an equivalence of categories `(C ≌ D) ≌ (D ≌ C)ᵒᵖ`. -/ @[simps] def symmEquiv : (C ≌ D) ≌ (D ≌ C)ᵒᵖ where functor := symmEquivFunctor _ _ inverse := symmEquivInverse _ _ counitIso := NatIso.ofComponents (fun e ↦ Iso.op <| Iso.refl _) <| fun _ ↦ (by simp [symm, symmEquivInverse]) unitIso := NatIso.ofComponents (fun e ↦ Iso.refl _) <| fun _ ↦ by ext c simp [symm, symmEquivInverse] functor_unitIso_comp X := by simp [symm, symmEquivInverse] /-- The `inverse` functor that sends a functor to its inverse. -/ @[simps!] def inverseFunctor : (C ≌ D) ⥤ (D ⥤ C)ᵒᵖ := (symmEquiv C D).functor ⋙ (Functor.op <| functorFunctor D C) variable {C D} /-- The `inverse` functor sends an equivalence to its inverse. -/ @[simps!] def inverseFunctorObjIso (e : C ≌ D) : (inverseFunctor C D).obj e ≅ Opposite.op e.inverse := Iso.refl _ /-- We can compare the way we obtain a natural isomorphism `e.inverse ≅ f.inverse` from an isomorphism `e ≌ f` via `inverseFunctor` with the way we get one through `Iso.isoInverseOfIsoFunctor`. -/ lemma inverseFunctorMapIso_symm_eq_isoInverseOfIsoFunctor {e f : C ≌ D} (α : e ≅ f) : Iso.unop ((inverseFunctor C D).mapIso α.symm) = Iso.isoInverseOfIsoFunctor ((functorFunctor _ _).mapIso α) := by cat_disch /-- An "unopped" version of the equivalence `inverseFunctorObj'`. -/ @[simps!] def inverseFunctorObj' (e : C ≌ D) : Opposite.unop ((inverseFunctor C D).obj e) ≅ e.inverse := Iso.refl _ variable (C D) in /-- Promoting `Equivalence.congrLeft` to a functor. -/ @[simps!] def congrLeftFunctor (E : Type*) [Category E] : (C ≌ D) ⥤ ((C ⥤ E) ≌ (D ⥤ E))ᵒᵖ := Functor.rightOp { obj f := f.unop.congrLeft map {e f} α := mkHom <| (whiskeringLeft _ _ _).map <| conjugateEquiv e.unop.toAdjunction f.unop.toAdjunction <| asNatTrans <| Quiver.Hom.unop α map_comp _ _ := by ext simp [← map_comp] } end Equivalence end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/Opposite.lean
import Mathlib.CategoryTheory.Enriched.Ordinary.Basic import Mathlib.CategoryTheory.Monoidal.Braided.Basic /-! # The opposite category of an enriched category When a monoidal category `V` is braided, we may define the opposite `V`-category of a `V`-category. The symmetry map is required to define the composition morphism. This file constructs the opposite `V`-category as an instance on the type `Cᵒᵖ` and constructs an equivalence between * `ForgetEnrichment V (Cᵒᵖ)`, the underlying category of the `V`-category `Cᵒᵖ`; and * `(ForgetEnrichment V C)ᵒᵖ`, the opposite category of the underlying category of `C`. We also show that if `C` is an enriched ordinary category (i.e. a category enriched in `V` equipped with an identification `(X ⟶ Y) ≃ (𝟙_ V ⟶ (X ⟶[V] Y))`) then `Cᵒᵖ` is again an enriched ordinary category. -/ universe v₁ u₁ v u namespace CategoryTheory open MonoidalCategory BraidedCategory variable (V : Type u₁) [Category.{v₁} V] [MonoidalCategory V] [BraidedCategory V] section variable (C : Type u) [EnrichedCategory V C] /-- For a `V`-category `C`, construct the opposite `V`-category structure on the type `Cᵒᵖ` using the braiding in `V`. -/ instance EnrichedCategory.opposite : EnrichedCategory V Cᵒᵖ where Hom y x := EnrichedCategory.Hom x.unop y.unop id x := EnrichedCategory.id x.unop comp z y x := (β_ _ _).hom ≫ EnrichedCategory.comp (x.unop) (y.unop) (z.unop) id_comp _ _ := by simp only [braiding_naturality_left_assoc, braiding_tensorUnit_left, Category.assoc, Iso.inv_hom_id_assoc] exact EnrichedCategory.comp_id _ _ comp_id _ _ := by simp only [braiding_naturality_right_assoc, braiding_tensorUnit_right, Category.assoc, Iso.inv_hom_id_assoc] exact EnrichedCategory.id_comp _ _ assoc _ _ _ _ := by simp only [braiding_naturality_left_assoc, MonoidalCategory.whiskerLeft_comp, Category.assoc] rw [← EnrichedCategory.assoc] simp only [braiding_tensor_left_hom, Category.assoc, Iso.inv_hom_id_assoc, braiding_naturality_right_assoc, braiding_tensor_right_hom] end /-- Unfold the definition of composition in the enriched opposite category. -/ @[reassoc] lemma eComp_op_eq {C : Type u} [EnrichedCategory V C] (x y z : Cᵒᵖ) : eComp V z y x = (β_ _ _).hom ≫ eComp V x.unop y.unop z.unop := rfl /-- When composing a tensor product of morphisms with the `V`-composition morphism in `Cᵒᵖ`, this re-writes the `V`-composition to be in `C` and moves the braiding to the left. -/ @[reassoc] lemma tensorHom_eComp_op_eq {C : Type u} [EnrichedCategory V C] {x y z : Cᵒᵖ} {v w : V} (f : v ⟶ EnrichedCategory.Hom z y) (g : w ⟶ EnrichedCategory.Hom y x) : (f ⊗ₘ g) ≫ eComp V z y x = (β_ v w).hom ≫ (g ⊗ₘ f) ≫ eComp V x.unop y.unop z.unop := by rw [eComp_op_eq] exact braiding_naturality_assoc f g _ -- This section establishes the equivalence on underlying categories section open ForgetEnrichment variable (C : Type u) [EnrichedCategory V C] /-- The functor going from the underlying category of the enriched category `Cᵒᵖ` to the opposite of the underlying category of the enriched category `C`. -/ def forgetEnrichmentOppositeEquivalence.functor : ForgetEnrichment V Cᵒᵖ ⥤ (ForgetEnrichment V C)ᵒᵖ where obj x := x map {x y} f := f.op map_comp {x y z} f g := by have : (f ≫ g) = homTo V (f ≫ g) := rfl rw [this, ForgetEnrichment.homTo_comp, Category.assoc, tensorHom_eComp_op_eq, leftUnitor_inv_braiding_assoc, ← unitors_inv_equal, ← Category.assoc] congr 1 /-- The functor going from the opposite of the underlying category of the enriched category `C` to the underlying category of the enriched category `Cᵒᵖ`. -/ def forgetEnrichmentOppositeEquivalence.inverse : (ForgetEnrichment V C)ᵒᵖ ⥤ ForgetEnrichment V Cᵒᵖ where obj x := x map {x y} f := f.unop map_comp {x y z} f g := by have : g.unop ≫ f.unop = homTo V (g.unop ≫ f.unop) := rfl dsimp rw [this, ForgetEnrichment.homTo_comp, Category.assoc, unitors_inv_equal, ← leftUnitor_inv_braiding_assoc] have : (β_ _ _).hom ≫ (homTo V g.unop ⊗ₘ homTo V f.unop) ≫ eComp V («to» V z.unop) («to» V y.unop) («to» V x.unop) = ((homTo V f.unop) ⊗ₘ (homTo V g.unop)) ≫ eComp V x y z := (tensorHom_eComp_op_eq V _ _).symm rw [this, ← Category.assoc] congr 1 /-- The equivalence between the underlying category of the enriched category `Cᵒᵖ` and the opposite of the underlying category of the enriched category `C`. -/ @[simps] def forgetEnrichmentOppositeEquivalence : ForgetEnrichment V Cᵒᵖ ≌ (ForgetEnrichment V C)ᵒᵖ where functor := forgetEnrichmentOppositeEquivalence.functor V C inverse := forgetEnrichmentOppositeEquivalence.inverse V C unitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _) counitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _) /-- If `D` is an enriched ordinary category then `Dᵒᵖ` is an enriched ordinary category. -/ instance EnrichedOrdinaryCategory.opposite {D : Type u} [Category.{v} D] [EnrichedOrdinaryCategory V D] : EnrichedOrdinaryCategory V Dᵒᵖ where homEquiv := Quiver.Hom.opEquiv.symm.trans homEquiv homEquiv_id x := homEquiv_id (x.unop) homEquiv_comp f g := by simp only [tensorHom_eComp_op_eq, leftUnitor_inv_braiding_assoc, ← unitors_inv_equal] exact homEquiv_comp g.unop f.unop end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/HomCongr.lean
import Mathlib.CategoryTheory.Enriched.Ordinary.Basic /-! # Congruence of enriched homs Recall that when `C` is both a category and a `V`-enriched category, we say it is an `EnrichedOrdinaryCategory` if it comes equipped with a sufficiently compatible equivalence between morphisms `X ⟶ Y` in `C` and morphisms `𝟙_ V ⟶ (X ⟶[V] Y)` in `V`. In such a `V`-enriched ordinary category `C`, isomorphisms in `C` induce isomorphisms between hom-objects in `V`. We define this isomorphism in `CategoryTheory.Iso.eHomCongr` and prove that it respects composition in `C`. The treatment here parallels that for unenriched categories in `Mathlib/CategoryTheory/HomCongr.lean` and that for sorts in `Mathlib/Logic/Equiv/Defs.lean` (cf. `Equiv.arrowCongr`). Note, however, that they construct equivalences between `Type`s and `Sort`s, respectively, while in this file we construct isomorphisms between objects in `V`. -/ universe v' v u u' namespace CategoryTheory namespace Iso open Category MonoidalCategory variable (V : Type u') [Category.{v'} V] [MonoidalCategory V] {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory V C] /-- Given isomorphisms `α : X ≅ X₁` and `β : Y ≅ Y₁` in `C`, we can construct an isomorphism between `V` objects `X ⟶[V] Y` and `X₁ ⟶[V] Y₁`. -/ @[simps] def eHomCongr {X Y X₁ Y₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) : (X ⟶[V] Y) ≅ (X₁ ⟶[V] Y₁) where hom := eHomWhiskerRight V α.inv Y ≫ eHomWhiskerLeft V X₁ β.hom inv := eHomWhiskerRight V α.hom Y₁ ≫ eHomWhiskerLeft V X β.inv hom_inv_id := by rw [← eHom_whisker_exchange] slice_lhs 2 3 => rw [← eHomWhiskerRight_comp] simp [← eHomWhiskerLeft_comp] inv_hom_id := by rw [← eHom_whisker_exchange] slice_lhs 2 3 => rw [← eHomWhiskerRight_comp] simp [← eHomWhiskerLeft_comp] lemma eHomCongr_refl (X Y : C) : eHomCongr V (Iso.refl X) (Iso.refl Y) = Iso.refl (X ⟶[V] Y) := by aesop lemma eHomCongr_trans {X₁ Y₁ X₂ Y₂ X₃ Y₃ : C} (α₁ : X₁ ≅ X₂) (β₁ : Y₁ ≅ Y₂) (α₂ : X₂ ≅ X₃) (β₂ : Y₂ ≅ Y₃) : eHomCongr V (α₁ ≪≫ α₂) (β₁ ≪≫ β₂) = eHomCongr V α₁ β₁ ≪≫ eHomCongr V α₂ β₂ := by ext; simp [eHom_whisker_exchange_assoc] lemma eHomCongr_symm {X Y X₁ Y₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) : (eHomCongr V α β).symm = eHomCongr V α.symm β.symm := rfl /-- `eHomCongr` respects composition of morphisms. Recall that for any composable pair of arrows `f : X ⟶ Y` and `g : Y ⟶ Z` in `C`, the composite `f ≫ g` in `C` defines a morphism `𝟙_ V ⟶ (X ⟶[V] Z)` in `V`. Composing with the isomorphism `eHomCongr V α γ` yields a morphism in `V` that can be factored through the enriched composition map as shown: `𝟙_ V ⟶ 𝟙_ V ⊗ 𝟙_ V ⟶ (X₁ ⟶[V] Y₁) ⊗ (Y₁ ⟶[V] Z₁) ⟶ (X₁ ⟶[V] Z₁)`. -/ @[reassoc] lemma eHomCongr_comp {X Y Z X₁ Y₁ Z₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) (γ : Z ≅ Z₁) (f : X ⟶ Y) (g : Y ⟶ Z) : eHomEquiv V (f ≫ g) ≫ (eHomCongr V α γ).hom = (λ_ _).inv ≫ (eHomEquiv V f ≫ (eHomCongr V α β).hom) ▷ _ ≫ _ ◁ (eHomEquiv V g ≫ (eHomCongr V β γ).hom) ≫ eComp V X₁ Y₁ Z₁ := by simp only [eHomCongr, MonoidalCategory.whiskerRight_id, assoc, MonoidalCategory.whiskerLeft_comp] rw [rightUnitor_inv_naturality_assoc, rightUnitor_inv_naturality_assoc, rightUnitor_inv_naturality_assoc, hom_inv_id_assoc, ← whisker_exchange_assoc, ← whisker_exchange_assoc, ← eComp_eHomWhiskerLeft, eHom_whisker_cancel_assoc, ← eComp_eHomWhiskerRight_assoc, ← tensorHom_def_assoc, ← eHomEquiv_comp_assoc] /-- The inverse map defined by `eHomCongr` respects composition of morphisms. -/ @[reassoc] lemma eHomCongr_inv_comp {X Y Z X₁ Y₁ Z₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) (γ : Z ≅ Z₁) (f : X₁ ⟶ Y₁) (g : Y₁ ⟶ Z₁) : eHomEquiv V (f ≫ g) ≫ (eHomCongr V α γ).inv = (λ_ _).inv ≫ (eHomEquiv V f ≫ (eHomCongr V α β).inv) ▷ _ ≫ _ ◁ (eHomEquiv V g ≫ (eHomCongr V β γ).inv) ≫ eComp V X Y Z := eHomCongr_comp V α.symm β.symm γ.symm f g end Iso end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/Basic.lean
import Mathlib.CategoryTheory.Monoidal.Types.Coyoneda import Mathlib.CategoryTheory.Monoidal.Center import Mathlib.Tactic.ApplyFun /-! # Enriched categories We set up the basic theory of `V`-enriched categories, for `V` an arbitrary monoidal category. We do not assume here that `V` is a concrete category, so there does not need to be an "honest" underlying category! Use `X ⟶[V] Y` to obtain the `V` object of morphisms from `X` to `Y`. This file contains the definitions of `V`-enriched categories and `V`-functors. We don't yet define the `V`-object of natural transformations between a pair of `V`-functors (this requires limits in `V`), but we do provide a presheaf isomorphic to the Yoneda embedding of this object. We verify that when `V = Type v`, all these notion reduce to the usual ones. ## References * [Kim Morrison, David Penneys, _Monoidal Categories Enriched in Braided Monoidal Categories_] [morrison-penney-enriched] -/ universe w w' v v' u₁ u₂ u₃ noncomputable section namespace CategoryTheory open Opposite open MonoidalCategory variable (V : Type v) [Category.{w} V] [MonoidalCategory V] /-- A `V`-category is a category enriched in a monoidal category `V`. Note that we do not assume that `V` is a concrete category, so there may not be an "honest" underlying category at all! -/ class EnrichedCategory (C : Type u₁) where /-- `X ⟶[V] Y` is the `V` object of morphisms from `X` to `Y`. -/ Hom : C → C → V /-- The identity morphism of this category -/ id (X : C) : 𝟙_ V ⟶ Hom X X /-- Composition of two morphisms in this category -/ comp (X Y Z : C) : Hom X Y ⊗ Hom Y Z ⟶ Hom X Z id_comp (X Y : C) : (λ_ (Hom X Y)).inv ≫ id X ▷ _ ≫ comp X X Y = 𝟙 _ := by cat_disch comp_id (X Y : C) : (ρ_ (Hom X Y)).inv ≫ _ ◁ id Y ≫ comp X Y Y = 𝟙 _ := by cat_disch assoc (W X Y Z : C) : (α_ _ _ _).inv ≫ comp W X Y ▷ _ ≫ comp W Y Z = _ ◁ comp X Y Z ≫ comp W X Z := by cat_disch @[inherit_doc EnrichedCategory.Hom] notation3 X " ⟶[" V "] " Y:10 => (EnrichedCategory.Hom X Y : V) variable {C : Type u₁} [EnrichedCategory V C] /-- The `𝟙_ V`-shaped generalized element giving the identity in a `V`-enriched category. -/ def eId (X : C) : 𝟙_ V ⟶ X ⟶[V] X := EnrichedCategory.id X /-- The composition `V`-morphism for a `V`-enriched category. -/ def eComp (X Y Z : C) : ((X ⟶[V] Y) ⊗ Y ⟶[V] Z) ⟶ X ⟶[V] Z := EnrichedCategory.comp X Y Z @[reassoc (attr := simp)] theorem e_id_comp (X Y : C) : (λ_ (X ⟶[V] Y)).inv ≫ eId V X ▷ _ ≫ eComp V X X Y = 𝟙 (X ⟶[V] Y) := EnrichedCategory.id_comp X Y @[reassoc (attr := simp)] theorem e_comp_id (X Y : C) : (ρ_ (X ⟶[V] Y)).inv ≫ _ ◁ eId V Y ≫ eComp V X Y Y = 𝟙 (X ⟶[V] Y) := EnrichedCategory.comp_id X Y @[reassoc (attr := simp)] theorem e_assoc (W X Y Z : C) : (α_ _ _ _).inv ≫ eComp V W X Y ▷ _ ≫ eComp V W Y Z = _ ◁ eComp V X Y Z ≫ eComp V W X Z := EnrichedCategory.assoc W X Y Z @[reassoc] theorem e_assoc' (W X Y Z : C) : (α_ _ _ _).hom ≫ _ ◁ eComp V X Y Z ≫ eComp V W X Z = eComp V W X Y ▷ _ ≫ eComp V W Y Z := by rw [← e_assoc V W X Y Z, Iso.hom_inv_id_assoc] section variable {V} {W : Type v'} [Category.{w'} W] [MonoidalCategory W] /-- A type synonym for `C`, which should come equipped with a `V`-enriched category structure. In a moment we will equip this with the `W`-enriched category structure obtained by applying the functor `F : LaxMonoidalFunctor V W` to each hom object. -/ @[nolint unusedArguments] def TransportEnrichment (F : V ⥤ W) [F.LaxMonoidal] (C : Type u₁) := C variable (F : V ⥤ W) [F.LaxMonoidal] open Functor.LaxMonoidal instance : EnrichedCategory W (TransportEnrichment F C) where Hom := fun X Y : C => F.obj (X ⟶[V] Y) id := fun X : C => ε F ≫ F.map (eId V X) comp := fun X Y Z : C => μ F _ _ ≫ F.map (eComp V X Y Z) id_comp X Y := by simp only [comp_whiskerRight, Category.assoc, Functor.LaxMonoidal.μ_natural_left_assoc, Functor.LaxMonoidal.left_unitality_inv_assoc] simp_rw [← F.map_comp] convert F.map_id _ simp comp_id X Y := by simp only [MonoidalCategory.whiskerLeft_comp, Category.assoc, Functor.LaxMonoidal.μ_natural_right_assoc, Functor.LaxMonoidal.right_unitality_inv_assoc] simp_rw [← F.map_comp] convert F.map_id _ simp assoc P Q R S := by rw [comp_whiskerRight, Category.assoc, μ_natural_left_assoc, ← associativity_inv_assoc, ← F.map_comp, ← F.map_comp, e_assoc, F.map_comp, MonoidalCategory.whiskerLeft_comp, Category.assoc, Functor.LaxMonoidal.μ_natural_right_assoc] lemma TransportEnrichment.eId_eq (X : TransportEnrichment F C) : eId W X = ε F ≫ F.map (eId (C := C) V X) := rfl lemma TransportEnrichment.eComp_eq (X Y Z : TransportEnrichment F C) : eComp W X Y Z = μ F _ _ ≫ F.map (eComp V _ _ _) := rfl end /-- Construct an honest category from a `Type v`-enriched category. -/ def categoryOfEnrichedCategoryType (C : Type u₁) [𝒞 : EnrichedCategory (Type v) C] : Category.{v} C where Hom := 𝒞.Hom id X := eId (Type v) X PUnit.unit comp f g := eComp (Type v) _ _ _ ⟨f, g⟩ id_comp f := congr_fun (e_id_comp (Type v) _ _) f comp_id f := congr_fun (e_comp_id (Type v) _ _) f assoc f g h := (congr_fun (e_assoc (Type v) _ _ _ _) ⟨f, g, h⟩ :) /-- Construct a `Type v`-enriched category from an honest category. -/ def enrichedCategoryTypeOfCategory (C : Type u₁) [𝒞 : Category.{v} C] : EnrichedCategory (Type v) C where Hom := 𝒞.Hom id X _ := 𝟙 X comp _ _ _ p := p.1 ≫ p.2 id_comp X Y := by ext; simp comp_id X Y := by ext; simp assoc W X Y Z := by ext ⟨f, g, h⟩; simp /-- We verify that an enriched category in `Type u` is just the same thing as an honest category. -/ def enrichedCategoryTypeEquivCategory (C : Type u₁) : EnrichedCategory (Type v) C ≃ Category.{v} C where toFun _ := categoryOfEnrichedCategoryType C invFun _ := enrichedCategoryTypeOfCategory C section variable {W : Type v} [Category.{w} W] [MonoidalCategory W] [EnrichedCategory W C] /-- A type synonym for `C`, which should come equipped with a `V`-enriched category structure. In a moment we will equip this with the (honest) category structure so that `X ⟶ Y` is `(𝟙_ W) ⟶ (X ⟶[W] Y)`. We obtain this category by transporting the enrichment in `V` along the lax monoidal functor `coyonedaTensorUnit`, then using the equivalence of `Type`-enriched categories with honest categories. This is sometimes called the "underlying" category of an enriched category, although some care is needed as the functor `coyonedaTensorUnit`, which always exists, does not necessarily coincide with "the forgetful functor" from `V` to `Type`, if such exists. When `V` is any of `Type`, `Top`, `AddCommGroup`, or `Module R`, `coyonedaTensorUnit` is just the usual forgetful functor, however. For `V = Algebra R`, the usual forgetful functor is coyoneda of `R[X]`, not of `R`. (Perhaps we should have a typeclass for this situation: `ConcreteMonoidal`?) -/ @[nolint unusedArguments] def ForgetEnrichment (W : Type v) [Category.{w} W] [MonoidalCategory W] (C : Type u₁) [EnrichedCategory W C] := C variable (W) /-- Typecheck an object of `C` as an object of `ForgetEnrichment W C`. -/ def ForgetEnrichment.of (X : C) : ForgetEnrichment W C := X /-- Typecheck an object of `ForgetEnrichment W C` as an object of `C`. -/ def ForgetEnrichment.to (X : ForgetEnrichment W C) : C := X @[simp] theorem ForgetEnrichment.to_of (X : C) : ForgetEnrichment.to W (ForgetEnrichment.of W X) = X := rfl @[simp] theorem ForgetEnrichment.of_to (X : ForgetEnrichment W C) : ForgetEnrichment.of W (ForgetEnrichment.to W X) = X := rfl instance categoryForgetEnrichment : Category (ForgetEnrichment W C) := enrichedCategoryTypeEquivCategory C (inferInstanceAs (EnrichedCategory (Type w) (TransportEnrichment (coyoneda.obj (op (𝟙_ W))) C))) /-- We verify that the morphism types in `ForgetEnrichment W C` are `(𝟙_ W) ⟶ (X ⟶[W] Y)`. -/ example (X Y : ForgetEnrichment W C) : (X ⟶ Y) = (𝟙_ W ⟶ ForgetEnrichment.to W X ⟶[W] ForgetEnrichment.to W Y) := rfl /-- Typecheck a `(𝟙_ W)`-shaped `W`-morphism as a morphism in `ForgetEnrichment W C`. -/ def ForgetEnrichment.homOf {X Y : C} (f : 𝟙_ W ⟶ X ⟶[W] Y) : ForgetEnrichment.of W X ⟶ ForgetEnrichment.of W Y := f /-- Typecheck a morphism in `ForgetEnrichment W C` as a `(𝟙_ W)`-shaped `W`-morphism. -/ def ForgetEnrichment.homTo {X Y : ForgetEnrichment W C} (f : X ⟶ Y) : 𝟙_ W ⟶ ForgetEnrichment.to W X ⟶[W] ForgetEnrichment.to W Y := f @[simp] theorem ForgetEnrichment.homTo_homOf {X Y : C} (f : 𝟙_ W ⟶ X ⟶[W] Y) : ForgetEnrichment.homTo W (ForgetEnrichment.homOf W f) = f := rfl @[simp] theorem ForgetEnrichment.homOf_homTo {X Y : ForgetEnrichment W C} (f : X ⟶ Y) : ForgetEnrichment.homOf W (ForgetEnrichment.homTo W f) = f := rfl /-- The identity in the "underlying" category of an enriched category. -/ @[simp] theorem ForgetEnrichment.homTo_id (X : ForgetEnrichment W C) : ForgetEnrichment.homTo W (𝟙 X) = eId W (ForgetEnrichment.to W X : C) := Category.id_comp _ @[deprecated (since := "2025-08-11")] alias forgetEnrichment_id := ForgetEnrichment.homTo_id @[simp] theorem ForgetEnrichment.homOf_eId (X : C) : ForgetEnrichment.homOf W (eId W X) = 𝟙 (of W X : C) := (homTo_id W (ForgetEnrichment.of W X)).symm @[deprecated (since := "2025-08-11")] alias forgetEnrichment_id' := ForgetEnrichment.homOf_eId /-- Composition in the "underlying" category of an enriched category. -/ @[simp] theorem ForgetEnrichment.homTo_comp {X Y Z : ForgetEnrichment W C} (f : X ⟶ Y) (g : Y ⟶ Z) : homTo W (f ≫ g) = ((λ_ (𝟙_ W)).inv ≫ (homTo W f ⊗ₘ homTo W g)) ≫ eComp W _ _ _ := rfl @[deprecated (since := "2025-08-11")] alias forgetEnrichment_comp := ForgetEnrichment.homTo_comp @[simp] theorem ForgetEnrichment.homOf_comp {X Y Z : C} (f : 𝟙_ W ⟶ (X ⟶[W] Y)) (g : 𝟙_ W ⟶ (Y ⟶[W] Z)) : homOf W ((λ_ _).inv ≫ (f ⊗ₘ g) ≫ eComp W ..) = homOf W f ≫ homOf W g := by rw [← Category.assoc] rfl end /-- A `V`-functor `F` between `V`-enriched categories has a `V`-morphism from `X ⟶[V] Y` to `F.obj X ⟶[V] F.obj Y`, satisfying the usual axioms. -/ structure EnrichedFunctor (C : Type u₁) [EnrichedCategory V C] (D : Type u₂) [EnrichedCategory V D] where /-- The application of this functor to an object -/ obj : C → D /-- The `V`-morphism from `X ⟶[V] Y` to `F.obj X ⟶[V] F.obj Y`, for all `X Y : C` -/ map : ∀ X Y : C, (X ⟶[V] Y) ⟶ obj X ⟶[V] obj Y map_id : ∀ X : C, eId V X ≫ map X X = eId V (obj X) := by cat_disch map_comp : ∀ X Y Z : C, eComp V X Y Z ≫ map X Z = (map X Y ⊗ₘ map Y Z) ≫ eComp V (obj X) (obj Y) (obj Z) := by cat_disch attribute [reassoc (attr := simp)] EnrichedFunctor.map_id attribute [reassoc (attr := simp)] EnrichedFunctor.map_comp namespace EnrichedFunctor /-- The identity enriched functor. -/ @[simps] def id (C : Type u₁) [EnrichedCategory V C] : EnrichedFunctor V C C where obj X := X map _ _ := 𝟙 _ instance : Inhabited (EnrichedFunctor V C C) := ⟨EnrichedFunctor.id V C⟩ /-- Composition of enriched functors. -/ @[simps] def comp {C : Type u₁} {D : Type u₂} {E : Type u₃} [EnrichedCategory V C] [EnrichedCategory V D] [EnrichedCategory V E] (F : EnrichedFunctor V C D) (G : EnrichedFunctor V D E) : EnrichedFunctor V C E where obj X := G.obj (F.obj X) map _ _ := F.map _ _ ≫ G.map _ _ lemma ext {C : Type u₁} {D : Type u₂} [EnrichedCategory V C] [EnrichedCategory V D] {F G : EnrichedFunctor V C D} (h_obj : ∀ X, F.obj X = G.obj X) (h_map : ∀ (X Y : C), F.map X Y ≫ eqToHom (by rw [h_obj, h_obj]) = G.map X Y) : F = G := by match F, G with | mk F_obj F_map _ _, mk G_obj G_map _ _ => obtain rfl : F_obj = G_obj := funext fun X ↦ h_obj X congr ext X Y simpa using h_map X Y section variable {W : Type v'} [Category.{w'} W] [MonoidalCategory W] {C : Type u₁} [EnrichedCategory W C] {D : Type u₂} [EnrichedCategory W D] {E : Type u₃} [EnrichedCategory W E] /-- An enriched functor induces an honest functor of the underlying categories, by mapping the `(𝟙_ W)`-shaped morphisms. -/ @[simps] def forget (F : EnrichedFunctor W C D) : ForgetEnrichment W C ⥤ ForgetEnrichment W D where obj X := ForgetEnrichment.of W (F.obj (ForgetEnrichment.to W X)) map f := ForgetEnrichment.homOf W (ForgetEnrichment.homTo W f ≫ F.map (ForgetEnrichment.to W _) (ForgetEnrichment.to W _)) map_comp f g := by dsimp apply_fun ForgetEnrichment.homTo W · simp only [Iso.cancel_iso_inv_left, Category.assoc, ← tensorHom_comp_tensorHom, ForgetEnrichment.homTo_homOf, EnrichedFunctor.map_comp, ForgetEnrichment.homTo_comp] rfl · intro f g w; apply_fun ForgetEnrichment.homOf W at w; simpa using w /-- `EnrichedFunctor.forget` distributes over composition of enriched functors up to isomorphism. -/ @[simps!] def forgetComp (F : EnrichedFunctor W C D) (G : EnrichedFunctor W D E) : (F.comp W G).forget ≅ F.forget ⋙ G.forget := NatIso.ofComponents (fun _ => Iso.refl _) (fun f => by simp [comp, forget]) variable (W) (C) in /-- `EnrichedFunctor.forget` maps the identity enriched functor to a functor isomorphic to `Functor.id`. -/ @[simps!] def forgetId : (EnrichedFunctor.id W C).forget ≅ Functor.id _ := NatIso.ofComponents (fun _ => Iso.refl _) (fun f => by simp [forget]) end end EnrichedFunctor section variable {V} variable {D : Type u₂} [EnrichedCategory V D] /-! We now turn to natural transformations between `V`-functors. The mostly commonly encountered definition of an enriched natural transformation is a collection of morphisms ``` (𝟙_ W) ⟶ (F.obj X ⟶[V] G.obj X) ``` satisfying an appropriate analogue of the naturality square. (c.f. https://ncatlab.org/nlab/show/enriched+natural+transformation) This is the same thing as a natural transformation `F.forget ⟶ G.forget`. We formalize this as `EnrichedNatTrans F G`, which is a `Type`. However, there's also something much nicer: with appropriate additional hypotheses, there is a `V`-object `EnrichedNatTransObj F G` which contains more information, and from which one can recover `EnrichedNatTrans F G ≃ (𝟙_ V) ⟶ EnrichedNatTransObj F G`. Using these as the hom-objects, we can build a `V`-enriched category with objects the `V`-functors. For `EnrichedNatTransObj` to exist, it suffices to have `V` braided and complete. Before assuming `V` is complete, we assume it is braided and define a presheaf `enrichedNatTransYoneda F G` which is isomorphic to the Yoneda embedding of `EnrichedNatTransObj F G` whether or not that object actually exists. This presheaf has components `(enrichedNatTransYoneda F G).obj A` what we call the `A`-graded enriched natural transformations, which are collections of morphisms ``` A ⟶ (F.obj X ⟶[V] G.obj X) ``` satisfying a similar analogue of the naturality square, this time incorporating a half-braiding on `A`. (We actually define `EnrichedNatTrans F G` as the special case `A := 𝟙_ V` with the trivial half-braiding, and when defining `enrichedNatTransYoneda F G` we use the half-braidings coming from the ambient braiding on `V`.) -/ /-- The type of `A`-graded natural transformations between `V`-functors `F` and `G`. This is the type of morphisms in `V` from `A` to the `V`-object of natural transformations. -/ @[ext] structure GradedNatTrans (A : Center V) (F G : EnrichedFunctor V C D) where /-- The `A`-graded transformation from `F` to `G` -/ app : ∀ X : C, A.1 ⟶ F.obj X ⟶[V] G.obj X /-- `app` is a natural transformation. -/ naturality : ∀ X Y : C, (A.2.β (X ⟶[V] Y)).hom ≫ (F.map X Y ⊗ₘ app Y) ≫ eComp V _ _ _ = (app X ⊗ₘ G.map X Y) ≫ eComp V _ _ _ attribute [reassoc] GradedNatTrans.naturality /-- A natural transformation between two enriched functors is a `𝟙_ V`-graded natural transformation. -/ structure EnrichedNatTrans (F G : EnrichedFunctor V C D) where /-- The underlying natural transformation of an enriched transformation. -/ out : F.forget ⟶ G.forget namespace EnrichedFunctor /-- Enriched functors form a category with the morphisms between functors `F` and `G` being enriched natural transformations, i.e. natural transformations `F.forget ⟶ G.forget`. -/ @[simps] instance category : Category (EnrichedFunctor V C D) where Hom F G := EnrichedNatTrans F G id F := ⟨𝟙 _⟩ comp F G := ⟨F.out ≫ G.out⟩ @[ext] lemma hom_ext {F G : EnrichedFunctor V C D} {α β : F ⟶ G} (h : ∀ X : C, α.out.app X = β.out.app X) : α = β := by rcases α with ⟨α⟩ rcases β with ⟨β⟩ congr ext apply h /-- To construct an isomorphism between enriched functors `F` and `G`, it suffices to construct a natural isomorphism between `F.forget` and `G.forget`. -/ @[simps] def isoMk {F G : EnrichedFunctor V C D} (h : F.forget ≅ G.forget) : F ≅ G where hom := ⟨h.hom⟩ inv := ⟨h.inv⟩ end EnrichedFunctor variable [BraidedCategory V] open BraidedCategory /-- A presheaf isomorphic to the Yoneda embedding of the `V`-object of natural transformations from `F` to `G`. -/ @[simps] def enrichedNatTransYoneda (F G : EnrichedFunctor V C D) : Vᵒᵖ ⥤ Type max u₁ w where obj A := GradedNatTrans ((Center.ofBraided V).obj (unop A)) F G map f σ := { app := fun X => f.unop ≫ σ.app X naturality := fun X Y => by have p := σ.naturality X Y dsimp at p ⊢ rw [← id_tensor_comp_tensor_id (f.unop ≫ σ.app Y) _, id_tensor_comp, Category.assoc, Category.assoc, ← braiding_naturality_assoc, id_tensor_comp_tensor_id_assoc, p, tensorHom_comp_tensorHom_assoc, Category.id_comp] } -- TODO assuming `[HasLimits C]` construct the actual object of natural transformations -- and show that the functor category is `V`-enriched. end section attribute [local instance] categoryOfEnrichedCategoryType /-- We verify that an enriched functor between `Type v` enriched categories is just the same thing as an honest functor. -/ @[simps] def enrichedFunctorTypeEquivFunctor {C : Type u₁} [𝒞 : EnrichedCategory (Type v) C] {D : Type u₂} [𝒟 : EnrichedCategory (Type v) D] : EnrichedFunctor (Type v) C D ≃ C ⥤ D where toFun F := { obj := fun X => F.obj X map := fun f => F.map _ _ f map_id := fun X => congr_fun (F.map_id X) PUnit.unit map_comp := fun f g => congr_fun (F.map_comp _ _ _) ⟨f, g⟩ } invFun F := { obj := fun X => F.obj X map := fun _ _ f => F.map f map_id := fun X => by ext ⟨⟩; exact F.map_id X map_comp := fun X Y Z => by ext ⟨f, g⟩; exact F.map_comp f g } /-- We verify that the presheaf representing natural transformations between `Type v`-enriched functors is actually represented by the usual type of natural transformations! -/ def enrichedNatTransYonedaTypeIsoYonedaNatTrans {C : Type v} [EnrichedCategory (Type v) C] {D : Type v} [EnrichedCategory (Type v) D] (F G : EnrichedFunctor (Type v) C D) : enrichedNatTransYoneda F G ≅ yoneda.obj (enrichedFunctorTypeEquivFunctor F ⟶ enrichedFunctorTypeEquivFunctor G) := NatIso.ofComponents (fun α => { hom := fun σ x => { app := fun X => σ.app X x naturality := fun X Y f => congr_fun (σ.naturality X Y) ⟨x, f⟩ } inv := fun σ => { app := fun X x => (σ x).app X naturality := fun X Y => by ext ⟨x, f⟩; exact (σ x).naturality f } }) (by cat_disch) end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/EnrichedCat.lean
import Mathlib.CategoryTheory.Enriched.Basic import Mathlib.CategoryTheory.Bicategory.Basic /-! # The bicategory of `V`-enriched categories We define the bicategory `EnrichedCat V` of (bundled) `V`-enriched categories for a fixed monoidal category `V`. ## Future work * Define change of base and `ForgetEnrichment` as 2-functors. * Define the bicategory of enriched ordinary categories. -/ universe w v u u₁ u₂ u₃ namespace CategoryTheory open MonoidalCategory variable (V : Type v) [Category.{w} V] [MonoidalCategory V] /-- Category of `V`-enriched categories for a monoidal category `V`. -/ def EnrichedCat := Bundled (EnrichedCategory.{w, v, u} V) namespace EnrichedCat instance : CoeSort (EnrichedCat V) (Type u) := ⟨Bundled.α⟩ instance str (C : EnrichedCat.{w, v, u} V) : EnrichedCategory.{w, v, u} V C := Bundled.str C /-- Construct a bundled `EnrichedCat` from the underlying type and the typeclass. -/ def of (C : Type u) [EnrichedCategory.{w} V C] : EnrichedCat.{w, v, u} V := Bundled.of C open EnrichedCategory ForgetEnrichment variable {V} {C : Type u} [EnrichedCategory V C] {D : Type u₁} [EnrichedCategory V D] {E : Type u₂} [EnrichedCategory V E] {E' : Type u₃} [EnrichedCategory V E'] /-- Whisker a `V`-enriched natural transformation on the left. -/ @[simps!] def whiskerLeft (F : EnrichedFunctor V C D) {G H : EnrichedFunctor V D E} (α : G ⟶ H) : F.comp V G ⟶ F.comp V H := ⟨(F.forgetComp G).hom ≫ F.forget.whiskerLeft α.out ≫ (F.forgetComp H).inv⟩ /-- Whisker a `V`-enriched natural transformation on the right. -/ @[simps!] def whiskerRight {F G : EnrichedFunctor V C D} (α : F ⟶ G) (H : EnrichedFunctor V D E) : F.comp V H ⟶ G.comp V H := ⟨(F.forgetComp H).hom ≫ Functor.whiskerRight α.out H.forget ≫ (G.forgetComp H).inv⟩ /-- Composing the `V`-enriched identity functor with any functor is isomorphic to that functor. -/ @[simps!] def leftUnitor (F : EnrichedFunctor V C D) : (EnrichedFunctor.id V _).comp V F ≅ F := EnrichedFunctor.isoMk <| (EnrichedFunctor.id V C).forgetComp F ≪≫ Functor.isoWhiskerRight (EnrichedFunctor.forgetId V C) _ ≪≫ Functor.leftUnitor F.forget /-- Composing any `V`-enriched functor with the identity functor is isomorphic to the former functor. -/ @[simps!] def rightUnitor (F : EnrichedFunctor V C D) : EnrichedFunctor.comp V F (EnrichedFunctor.id V _) ≅ F := EnrichedFunctor.isoMk <| F.forgetComp _ ≪≫ Functor.isoWhiskerLeft _ (EnrichedFunctor.forgetId V D) ≪≫ Functor.rightUnitor F.forget /-- Composition of `V`-enriched functors is associative up to isomorphism. -/ @[simps!] def associator (F : EnrichedFunctor V C D) (G : EnrichedFunctor V D E) (H : EnrichedFunctor V E E') : EnrichedFunctor.comp V (EnrichedFunctor.comp V F G) H ≅ EnrichedFunctor.comp V F (EnrichedFunctor.comp V G H) := EnrichedFunctor.isoMk <| (F.comp V G).forgetComp H ≪≫ Functor.isoWhiskerRight (F.forgetComp G) _ ≪≫ Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft _ (G.forgetComp H).symm ≪≫ (F.forgetComp _).symm lemma comp_whiskerRight {F G H : EnrichedFunctor V C D} (α : F ⟶ G) (β : G ⟶ H) (I : EnrichedFunctor V D E) : whiskerRight ⟨α.out ≫ β.out⟩ I = whiskerRight α I ≫ whiskerRight β I := by ext X simp only [whiskerRight_out_app, NatTrans.comp_app, EnrichedFunctor.category_comp_out, EnrichedFunctor.forget, EnrichedFunctor.comp_obj, EnrichedFunctor.comp_map] simp [← ForgetEnrichment.homOf_comp] lemma whisker_exchange {F G : EnrichedFunctor V C D} {H I : EnrichedFunctor V D E} (α : F ⟶ G) (β : H ⟶ I) : whiskerLeft F β ≫ whiskerRight α I = whiskerRight α H ≫ whiskerLeft G β := by ext X simp only [EnrichedFunctor.forget_obj, EnrichedFunctor.comp_obj, EnrichedFunctor.category_comp_out, NatTrans.comp_app, whiskerLeft_out_app, whiskerRight_out_app] exact (β.out.naturality (α.out.app (ForgetEnrichment.of V X))).symm /-- The bicategory structure on `EnrichedCat V` for a monoidal category `V`. -/ instance bicategory : Bicategory (EnrichedCat.{w, v, u} V) where Hom C D := EnrichedFunctor V C D id C := EnrichedFunctor.id V C comp F G := EnrichedFunctor.comp V F G whiskerLeft F G H := whiskerLeft F whiskerRight := whiskerRight associator := associator leftUnitor := leftUnitor rightUnitor := rightUnitor comp_whiskerRight := comp_whiskerRight whisker_exchange := whisker_exchange end EnrichedCat end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/FunctorCategory.lean
import Mathlib.CategoryTheory.Monoidal.FunctorCategory import Mathlib.CategoryTheory.Enriched.Ordinary.Basic import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.Limits.Shapes.End /-! # Functor categories are enriched If `C` is a `V`-enriched ordinary category, then `J ⥤ C` is also both a `V`-enriched ordinary category and a `J ⥤ V`-enriched ordinary category, provided `C` has suitable limits. We first define the `V`-enriched structure on `J ⥤ C` by saying that if `F₁` and `F₂` are in `J ⥤ C`, then `enrichedHom V F₁ F₂ : V` is a suitable limit involving `F₁.obj j ⟶[V] F₂.obj j` for all `j : C`. The `J ⥤ V` object of morphisms `functorEnrichedHom V F₁ F₂ : J ⥤ V` is defined by sending `j : J` to the previously defined `enrichedHom` for the "restriction" of `F₁` and `F₂` to the category `Under j`. The definition `isLimitConeFunctorEnrichedHom` shows that `enriched V F₁ F₂` is the limit of the functor `functorEnrichedHom V F₁ F₂`. -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace CategoryTheory.Enriched.FunctorCategory open Category MonoidalCategory Limits Functor variable (V : Type u₁) [Category.{v₁} V] [MonoidalCategory V] {C : Type u₂} [Category.{v₂} C] {J : Type u₃} [Category.{v₃} J] {K : Type u₄} [Category.{v₄} K] [EnrichedOrdinaryCategory V C] variable (F₁ F₂ F₃ F₄ : J ⥤ C) /-- Given two functors `F₁` and `F₂` from a category `J` to a `V`-enriched ordinary category `C`, this is the diagram `Jᵒᵖ ⥤ J ⥤ V` whose end shall be the `V`-morphisms in `J ⥤ V` from `F₁` to `F₂`. -/ @[simps!] def diagram : Jᵒᵖ ⥤ J ⥤ V := F₁.op ⋙ eHomFunctor V C ⋙ (whiskeringLeft J C V).obj F₂ /-- The condition that the end `diagram V F₁ F₂` exists, see `enrichedHom`. -/ abbrev HasEnrichedHom := HasEnd (diagram V F₁ F₂) section variable [HasEnrichedHom V F₁ F₂] /-- The `V`-enriched hom from `F₁` to `F₂` when `F₁` and `F₂` are functors `J ⥤ C` and `C` is a `V`-enriched category. -/ noncomputable abbrev enrichedHom : V := end_ (diagram V F₁ F₂) /-- The projection `enrichedHom V F₁ F₂ ⟶ F₁.obj j ⟶[V] F₂.obj j` in the category `V` for any `j : J` when `F₁` and `F₂` are functors `J ⥤ C` and `C` is a `V`-enriched category. -/ noncomputable abbrev enrichedHomπ (j : J) : enrichedHom V F₁ F₂ ⟶ F₁.obj j ⟶[V] F₂.obj j := end_.π _ j @[reassoc] lemma enrichedHom_condition {i j : J} (f : i ⟶ j) : enrichedHomπ V F₁ F₂ i ≫ eHomWhiskerLeft V (F₁.obj i) (F₂.map f) = enrichedHomπ V F₁ F₂ j ≫ eHomWhiskerRight V (F₁.map f) (F₂.obj j) := end_.condition (diagram V F₁ F₂) f @[reassoc] lemma enrichedHom_condition' {i j : J} (f : i ⟶ j) : enrichedHomπ V F₁ F₂ i ≫ (ρ_ _).inv ≫ _ ◁ (eHomEquiv V) (F₂.map f) ≫ eComp V _ _ _ = enrichedHomπ V F₁ F₂ j ≫ (λ_ _).inv ≫ (eHomEquiv V) (F₁.map f) ▷ _ ≫ eComp V _ _ _ := end_.condition (diagram V F₁ F₂) f variable {F₁ F₂} /-- Given functors `F₁` and `F₂` in `J ⥤ C`, where `C` is a `V`-enriched ordinary category, this is the bijection `(F₁ ⟶ F₂) ≃ (𝟙_ V ⟶ enrichedHom V F₁ F₂)`. -/ noncomputable def homEquiv : (F₁ ⟶ F₂) ≃ (𝟙_ V ⟶ enrichedHom V F₁ F₂) where toFun τ := end_.lift (fun j ↦ eHomEquiv V (τ.app j)) (fun i j f ↦ by trans eHomEquiv V (τ.app i ≫ F₂.map f) · dsimp simp only [eHomEquiv_comp, tensorHom_def_assoc, MonoidalCategory.whiskerRight_id, ← unitors_equal, assoc, Iso.inv_hom_id_assoc, eHomWhiskerLeft] · dsimp simp only [← NatTrans.naturality, eHomEquiv_comp, tensorHom_def', id_whiskerLeft, assoc, Iso.inv_hom_id_assoc, eHomWhiskerRight]) invFun g := { app := fun j ↦ (eHomEquiv V).symm (g ≫ end_.π _ j) naturality := fun i j f ↦ (eHomEquiv V).injective (by simp only [eHomEquiv_comp, Equiv.apply_symm_apply, Iso.cancel_iso_inv_left] conv_rhs => rw [tensorHom_def_assoc, MonoidalCategory.whiskerRight_id_assoc, assoc, enrichedHom_condition' V F₁ F₂ f] conv_lhs => rw [tensorHom_def'_assoc, MonoidalCategory.whiskerLeft_comp_assoc, id_whiskerLeft_assoc, id_whiskerLeft_assoc, Iso.inv_hom_id_assoc, unitors_equal]) } left_inv τ := by aesop right_inv g := by aesop @[reassoc (attr := simp)] lemma homEquiv_apply_π (τ : F₁ ⟶ F₂) (j : J) : homEquiv V τ ≫ enrichedHomπ V _ _ j = eHomEquiv V (τ.app j) := by simp [homEquiv] end section variable [HasEnrichedHom V F₁ F₁] /-- The identity for the `V`-enrichment of the category `J ⥤ C`. -/ noncomputable def enrichedId : 𝟙_ V ⟶ enrichedHom V F₁ F₁ := homEquiv _ (𝟙 F₁) @[reassoc (attr := simp)] lemma enrichedId_π (j : J) : enrichedId V F₁ ≫ end_.π _ j = eId V (F₁.obj j) := by simp [enrichedId] @[simp] lemma homEquiv_id : homEquiv V (𝟙 F₁) = enrichedId V F₁ := rfl end section variable [HasEnrichedHom V F₁ F₂] [HasEnrichedHom V F₂ F₃] [HasEnrichedHom V F₁ F₃] /-- The composition for the `V`-enrichment of the category `J ⥤ C`. -/ noncomputable def enrichedComp : enrichedHom V F₁ F₂ ⊗ enrichedHom V F₂ F₃ ⟶ enrichedHom V F₁ F₃ := end_.lift (fun j ↦ (end_.π _ j ⊗ₘ end_.π _ j) ≫ eComp V _ _ _) (fun i j f ↦ by dsimp trans (end_.π (diagram V F₁ F₂) i ⊗ₘ end_.π (diagram V F₂ F₃) j) ≫ (ρ_ _).inv ▷ _ ≫ (_ ◁ (eHomEquiv V (F₂.map f))) ▷ _ ≫ eComp V _ (F₂.obj i) _ ▷ _ ≫ eComp V _ (F₂.obj j) _ · have := end_.condition (diagram V F₂ F₃) f dsimp [eHomWhiskerLeft, eHomWhiskerRight] at this ⊢ conv_lhs => rw [assoc, tensorHom_def_assoc] conv_rhs => rw [tensorHom_def_assoc, whisker_assoc_assoc, e_assoc, triangle_assoc_comp_right_inv_assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, assoc, assoc, ← this, MonoidalCategory.whiskerLeft_comp_assoc, MonoidalCategory.whiskerLeft_comp_assoc, MonoidalCategory.whiskerLeft_comp_assoc, ← e_assoc, whiskerLeft_rightUnitor_inv_assoc, associator_inv_naturality_right_assoc, Iso.hom_inv_id_assoc, whisker_exchange_assoc, MonoidalCategory.whiskerRight_id_assoc, Iso.inv_hom_id_assoc] · have := end_.condition (diagram V F₁ F₂) f dsimp [eHomWhiskerLeft, eHomWhiskerRight] at this ⊢ conv_lhs => rw [tensorHom_def'_assoc, ← comp_whiskerRight_assoc, ← comp_whiskerRight_assoc, ← comp_whiskerRight_assoc, assoc, assoc, this, comp_whiskerRight_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, leftUnitor_inv_whiskerRight_assoc, ← associator_inv_naturality_left_assoc, ← e_assoc', Iso.inv_hom_id_assoc, ← whisker_exchange_assoc, id_whiskerLeft_assoc, Iso.inv_hom_id_assoc] conv_rhs => rw [assoc, tensorHom_def'_assoc]) @[reassoc (attr := simp)] lemma enrichedComp_π (j : J) : enrichedComp V F₁ F₂ F₃ ≫ end_.π _ j = (end_.π (diagram V F₁ F₂) j ⊗ₘ end_.π (diagram V F₂ F₃) j) ≫ eComp V _ _ _ := by simp [enrichedComp] variable {F₁ F₂ F₃} @[reassoc] lemma homEquiv_comp (f : F₁ ⟶ F₂) (g : F₂ ⟶ F₃) : (homEquiv V) (f ≫ g) = (λ_ (𝟙_ V)).inv ≫ ((homEquiv V) f ⊗ₘ (homEquiv V) g) ≫ enrichedComp V F₁ F₂ F₃ := by ext j simp only [homEquiv_apply_π, NatTrans.comp_app, eHomEquiv_comp, assoc, enrichedComp_π, Functor.op_obj, tensorHom_comp_tensorHom_assoc] end @[reassoc (attr := simp)] lemma enriched_id_comp [HasEnrichedHom V F₁ F₁] [HasEnrichedHom V F₁ F₂] : (λ_ (enrichedHom V F₁ F₂)).inv ≫ enrichedId V F₁ ▷ enrichedHom V F₁ F₂ ≫ enrichedComp V F₁ F₁ F₂ = 𝟙 _ := by ext j rw [assoc, assoc, enrichedComp_π, id_comp, tensorHom_def, assoc, ← comp_whiskerRight_assoc, enrichedId_π, ← whisker_exchange_assoc, id_whiskerLeft, assoc, assoc, Iso.inv_hom_id_assoc] dsimp rw [e_id_comp, comp_id] @[reassoc (attr := simp)] lemma enriched_comp_id [HasEnrichedHom V F₁ F₂] [HasEnrichedHom V F₂ F₂] : (ρ_ (enrichedHom V F₁ F₂)).inv ≫ enrichedHom V F₁ F₂ ◁ enrichedId V F₂ ≫ enrichedComp V F₁ F₂ F₂ = 𝟙 _ := by ext j rw [assoc, assoc, enrichedComp_π, id_comp, tensorHom_def', assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, enrichedId_π, whisker_exchange_assoc, MonoidalCategory.whiskerRight_id, assoc, assoc, Iso.inv_hom_id_assoc] dsimp rw [e_comp_id, comp_id] @[reassoc] lemma enriched_assoc [HasEnrichedHom V F₁ F₂] [HasEnrichedHom V F₁ F₃] [HasEnrichedHom V F₁ F₄] [HasEnrichedHom V F₂ F₃] [HasEnrichedHom V F₂ F₄] [HasEnrichedHom V F₃ F₄] : (α_ (enrichedHom V F₁ F₂) (enrichedHom V F₂ F₃) (enrichedHom V F₃ F₄)).inv ≫ enrichedComp V F₁ F₂ F₃ ▷ enrichedHom V F₃ F₄ ≫ enrichedComp V F₁ F₃ F₄ = enrichedHom V F₁ F₂ ◁ enrichedComp V F₂ F₃ F₄ ≫ enrichedComp V F₁ F₂ F₄ := by ext j conv_lhs => rw [assoc, assoc, enrichedComp_π, tensorHom_def_assoc, ← comp_whiskerRight_assoc, enrichedComp_π, comp_whiskerRight_assoc, ← whisker_exchange_assoc, ← whisker_exchange_assoc, ← tensorHom_def'_assoc, ← associator_inv_naturality_assoc] conv_rhs => rw [assoc, enrichedComp_π, tensorHom_def'_assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, enrichedComp_π, MonoidalCategory.whiskerLeft_comp_assoc, whisker_exchange_assoc, whisker_exchange_assoc, ← tensorHom_def_assoc] dsimp rw [e_assoc] variable (J C) /-- If `C` is a `V`-enriched ordinary category, and `C` has suitable limits, then `J ⥤ C` is also a `V`-enriched ordinary category. -/ noncomputable def enrichedOrdinaryCategory [∀ (F₁ F₂ : J ⥤ C), HasEnrichedHom V F₁ F₂] : EnrichedOrdinaryCategory V (J ⥤ C) where Hom F₁ F₂ := enrichedHom V F₁ F₂ id F := enrichedId V F comp F₁ F₂ F₃ := enrichedComp V F₁ F₂ F₃ assoc _ _ _ _ := enriched_assoc _ _ _ _ _ homEquiv := homEquiv V homEquiv_id _ := homEquiv_id V _ homEquiv_comp f g := homEquiv_comp V f g variable {J C} section variable (G : K ⥤ J) [HasEnrichedHom V F₁ F₂] variable {F₁ F₂} in /-- If `F₁` and `F₂` are functors `J ⥤ C`, `G : K ⥤ J`, and `F₁'` and `F₂'` are functors `K ⥤ C` that are respectively isomorphic to `G ⋙ F₁` and `G ⋙ F₂`, then this is the induced morphism `enrichedHom V F₁ F₂ ⟶ enrichedHom V F₁' F₂'` in `V` when `C` is a category enriched in `V`. -/ noncomputable abbrev precompEnrichedHom' {F₁' F₂' : K ⥤ C} [HasEnrichedHom V F₁' F₂'] (e₁ : G ⋙ F₁ ≅ F₁') (e₂ : G ⋙ F₂ ≅ F₂') : enrichedHom V F₁ F₂ ⟶ enrichedHom V F₁' F₂' := end_.lift (fun x ↦ enrichedHomπ V F₁ F₂ (G.obj x) ≫ (eHomWhiskerRight _ (e₁.inv.app x) _ ≫ eHomWhiskerLeft _ _ (e₂.hom.app x))) (fun i j f ↦ by dsimp rw [assoc, assoc, assoc, assoc, ← eHomWhiskerLeft_comp, ← eHom_whisker_exchange, ← e₂.hom.naturality f, eHomWhiskerLeft_comp_assoc] dsimp rw [enrichedHom_condition_assoc, eHom_whisker_exchange, eHom_whisker_exchange, ← eHomWhiskerRight_comp_assoc, ← eHomWhiskerRight_comp_assoc, NatTrans.naturality] dsimp ) /-- If `F₁` and `F₂` are functors `J ⥤ C`, and `G : K ⥤ J`, then this is the induced morphism `enrichedHom V F₁ F₂ ⟶ enrichedHom V (G ⋙ F₁) (G ⋙ F₂)` in `V` when `C` is a category enriched in `V`. -/ noncomputable abbrev precompEnrichedHom [HasEnrichedHom V (G ⋙ F₁) (G ⋙ F₂)] : enrichedHom V F₁ F₂ ⟶ enrichedHom V (G ⋙ F₁) (G ⋙ F₂) := precompEnrichedHom' V G (Iso.refl _) (Iso.refl _) end section /-- Given functors `F₁` and `F₂` in `J ⥤ C`, where `C` is a category enriched in `V`, this condition allows the definition of `functorEnrichedHom V F₁ F₂ : J ⥤ V`. -/ abbrev HasFunctorEnrichedHom := ∀ (j : J), HasEnrichedHom V (Under.forget j ⋙ F₁) (Under.forget j ⋙ F₂) variable [HasFunctorEnrichedHom V F₁ F₂] instance {j j' : J} (f : j ⟶ j') : HasEnrichedHom V (Under.map f ⋙ Under.forget j ⋙ F₁) (Under.map f ⋙ Under.forget j ⋙ F₂) := inferInstanceAs (HasEnrichedHom V (Under.forget j' ⋙ F₁) (Under.forget j' ⋙ F₂)) /-- Given functors `F₁` and `F₂` in `J ⥤ C`, where `C` is a category enriched in `V`, this is the enriched hom functor from `F₁` to `F₂` in `J ⥤ V`. -/ @[simps!] noncomputable def functorEnrichedHom : J ⥤ V where obj j := enrichedHom V (Under.forget j ⋙ F₁) (Under.forget j ⋙ F₂) map f := precompEnrichedHom' V (Under.map f) (Iso.refl _) (Iso.refl _) map_id X := by ext j -- this was produced by `simp?` simp only [diagram_obj_obj, Functor.comp_obj, Under.forget_obj, end_.lift_π, Under.map_obj_right, Iso.refl_inv, NatTrans.id_app, eHomWhiskerRight_id, Iso.refl_hom, eHomWhiskerLeft_id, comp_id, id_comp] congr 1 simp [Under.map, Comma.mapLeft] rfl map_comp f g := by ext j -- this was produced by `simp?` simp only [diagram_obj_obj, Functor.comp_obj, Under.forget_obj, end_.lift_π, Under.map_obj_right, Iso.refl_inv, NatTrans.id_app, eHomWhiskerRight_id, Iso.refl_hom, eHomWhiskerLeft_id, comp_id, assoc] congr 1 simp [Under.map, Comma.mapLeft] variable [HasEnrichedHom V F₁ F₂] /-- The (limit) cone expressing that the limit of `functorEnrichedHom V F₁ F₂` is `enrichedHom V F₁ F₂`. -/ @[simps] noncomputable def coneFunctorEnrichedHom : Cone (functorEnrichedHom V F₁ F₂) where pt := enrichedHom V F₁ F₂ π := { app := fun j ↦ precompEnrichedHom V F₁ F₂ (Under.forget j) } namespace isLimitConeFunctorEnrichedHom variable {V F₁ F₂} (s : Cone (functorEnrichedHom V F₁ F₂)) /-- Auxiliary definition for `Enriched.FunctorCategory.isLimitConeFunctorEnrichedHom`. -/ noncomputable def lift : s.pt ⟶ enrichedHom V F₁ F₂ := end_.lift (fun j ↦ s.π.app j ≫ enrichedHomπ V _ _ (Under.mk (𝟙 j))) (fun j j' f ↦ by dsimp rw [← s.w f, assoc, assoc, assoc] -- this was produced by `simp?` simp only [functorEnrichedHom_obj, functorEnrichedHom_map, end_.lift_π_assoc, diagram_obj_obj, Functor.comp_obj, Under.forget_obj, Under.mk_right, Under.map_obj_right, Iso.refl_inv, NatTrans.id_app, eHomWhiskerRight_id, Iso.refl_hom, eHomWhiskerLeft_id, comp_id] have := enrichedHom_condition V (Under.forget j ⋙ F₁) (Under.forget j ⋙ F₂) (Under.homMk f : Under.mk (𝟙 j) ⟶ Under.mk f) dsimp at this rw [this] congr 3 simp [Under.map, Comma.mapLeft] rfl) lemma fac (j : J) : lift s ≫ (coneFunctorEnrichedHom V F₁ F₂).π.app j = s.π.app j := by dsimp [coneFunctorEnrichedHom] ext k have := s.w k.hom dsimp at this -- this was produced by `simp? [lift, ← this]` simp only [diagram_obj_obj, Functor.comp_obj, Under.forget_obj, lift, functorEnrichedHom_obj, assoc, end_.lift_π, Iso.refl_inv, NatTrans.id_app, eHomWhiskerRight_id, Iso.refl_hom, eHomWhiskerLeft_id, comp_id, ← this, Under.map_obj_right, Under.mk_right] congr simp [Under.map, Comma.mapLeft] rfl end isLimitConeFunctorEnrichedHom open isLimitConeFunctorEnrichedHom in /-- The limit of `functorEnrichedHom V F₁ F₂` is `enrichedHom V F₁ F₂`. -/ noncomputable def isLimitConeFunctorEnrichedHom : IsLimit (coneFunctorEnrichedHom V F₁ F₂) where lift := lift fac := fac uniq s m hm := by dsimp ext j simpa using ((hm j).trans (fac s j).symm) =≫ enrichedHomπ V _ _ (Under.mk (𝟙 j)) end /-- The identity for the `J ⥤ V`-enrichment of the category `J ⥤ C`. -/ @[simps] noncomputable def functorEnrichedId [HasFunctorEnrichedHom V F₁ F₁] : 𝟙_ (J ⥤ V) ⟶ functorEnrichedHom V F₁ F₁ where app j := enrichedId V _ /-- The composition for the `J ⥤ V`-enrichment of the category `J ⥤ C`. -/ @[simps] noncomputable def functorEnrichedComp [HasFunctorEnrichedHom V F₁ F₂] [HasFunctorEnrichedHom V F₂ F₃] [HasFunctorEnrichedHom V F₁ F₃] : functorEnrichedHom V F₁ F₂ ⊗ functorEnrichedHom V F₂ F₃ ⟶ functorEnrichedHom V F₁ F₃ where app j := enrichedComp V _ _ _ naturality j j' f := by dsimp ext k dsimp rw [assoc, assoc, enrichedComp_π] dsimp rw [tensorHom_comp_tensorHom_assoc] simp @[reassoc (attr := simp)] lemma functorEnriched_id_comp [HasFunctorEnrichedHom V F₁ F₂] [HasFunctorEnrichedHom V F₁ F₁] : (λ_ (functorEnrichedHom V F₁ F₂)).inv ≫ functorEnrichedId V F₁ ▷ functorEnrichedHom V F₁ F₂ ≫ functorEnrichedComp V F₁ F₁ F₂ = 𝟙 (functorEnrichedHom V F₁ F₂) := by cat_disch @[reassoc (attr := simp)] lemma functorEnriched_comp_id [HasFunctorEnrichedHom V F₁ F₂] [HasFunctorEnrichedHom V F₂ F₂] : (ρ_ (functorEnrichedHom V F₁ F₂)).inv ≫ functorEnrichedHom V F₁ F₂ ◁ functorEnrichedId V F₂ ≫ functorEnrichedComp V F₁ F₂ F₂ = 𝟙 (functorEnrichedHom V F₁ F₂) := by cat_disch @[reassoc] lemma functorEnriched_assoc [HasFunctorEnrichedHom V F₁ F₂] [HasFunctorEnrichedHom V F₂ F₃] [HasFunctorEnrichedHom V F₃ F₄] [HasFunctorEnrichedHom V F₁ F₃] [HasFunctorEnrichedHom V F₂ F₄] [HasFunctorEnrichedHom V F₁ F₄] : (α_ _ _ _).inv ≫ functorEnrichedComp V F₁ F₂ F₃ ▷ functorEnrichedHom V F₃ F₄ ≫ functorEnrichedComp V F₁ F₃ F₄ = functorEnrichedHom V F₁ F₂ ◁ functorEnrichedComp V F₂ F₃ F₄ ≫ functorEnrichedComp V F₁ F₂ F₄ := by ext j dsimp rw [enriched_assoc] variable (J C) in /-- If `C` is a `V`-enriched ordinary category, and `C` has suitable limits, then `J ⥤ C` is also a `J ⥤ V`-enriched ordinary category. -/ noncomputable def functorEnrichedCategory [∀ (F₁ F₂ : J ⥤ C), HasFunctorEnrichedHom V F₁ F₂] : EnrichedCategory (J ⥤ V) (J ⥤ C) where Hom F₁ F₂ := functorEnrichedHom V F₁ F₂ id F := functorEnrichedId V F comp F₁ F₂ F₃ := functorEnrichedComp V F₁ F₂ F₃ assoc F₁ F₂ F₃ F₄ := functorEnriched_assoc V F₁ F₂ F₃ F₄ variable {F₁ F₂} in /-- Given functors `F₁` and `F₂` in `J ⥤ C`, where `C` is a `V`-enriched ordinary category, this is the bijection `(F₁ ⟶ F₂) ≃ (𝟙_ (J ⥤ V) ⟶ functorEnrichedHom V F₁ F₂)`. -/ @[simps! apply_app] noncomputable def functorHomEquiv [HasFunctorEnrichedHom V F₁ F₂] [HasEnrichedHom V F₁ F₂] : (F₁ ⟶ F₂) ≃ (𝟙_ (J ⥤ V) ⟶ functorEnrichedHom V F₁ F₂) := (homEquiv V).trans (isLimitConeFunctorEnrichedHom V F₁ F₂).homEquiv lemma functorHomEquiv_id [HasFunctorEnrichedHom V F₁ F₁] [HasEnrichedHom V F₁ F₁] : (functorHomEquiv V) (𝟙 F₁) = functorEnrichedId V F₁ := by cat_disch variable {F₁ F₂ F₃} in lemma functorHomEquiv_comp [HasFunctorEnrichedHom V F₁ F₂] [HasEnrichedHom V F₁ F₂] [HasFunctorEnrichedHom V F₂ F₃] [HasEnrichedHom V F₂ F₃] [HasFunctorEnrichedHom V F₁ F₃] [HasEnrichedHom V F₁ F₃] (f : F₁ ⟶ F₂) (g : F₂ ⟶ F₃) : (functorHomEquiv V) (f ≫ g) = (λ_ (𝟙_ (J ⥤ V))).inv ≫ ((functorHomEquiv V) f ⊗ₘ (functorHomEquiv V) g) ≫ functorEnrichedComp V F₁ F₂ F₃ := by ext j dsimp ext k rw [homEquiv_comp, assoc, assoc, assoc, assoc, assoc, end_.lift_π, enrichedComp_π] simp [tensorHom_comp_tensorHom_assoc] attribute [local instance] functorEnrichedCategory variable (J C) in /-- If `C` is a `V`-enriched ordinary category, and `C` has suitable limits, then `J ⥤ C` is also a `J ⥤ V`-enriched ordinary category. -/ noncomputable def functorEnrichedOrdinaryCategory [∀ (F₁ F₂ : J ⥤ C), HasFunctorEnrichedHom V F₁ F₂] [∀ (F₁ F₂ : J ⥤ C), HasEnrichedHom V F₁ F₂] : EnrichedOrdinaryCategory (J ⥤ V) (J ⥤ C) where homEquiv := functorHomEquiv V homEquiv_id F := functorHomEquiv_id V F homEquiv_comp f g := functorHomEquiv_comp V f g end CategoryTheory.Enriched.FunctorCategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/Ordinary/Basic.lean
import Mathlib.CategoryTheory.Enriched.Basic import Mathlib.CategoryTheory.Monoidal.Types.Coyoneda /-! # Enriched ordinary categories If `V` is a monoidal category, a `V`-enriched category `C` does not need to be a category. However, when we have both `Category C` and `EnrichedCategory V C`, we may require that the type of morphisms `X ⟶ Y` in `C` identify to `𝟙_ V ⟶ EnrichedCategory.Hom X Y`. This data shall be packaged in the typeclass `EnrichedOrdinaryCategory V C`. In particular, if `C` is a `V`-enriched category, it is shown that the "underlying" category `ForgetEnrichment V C` is equipped with a `EnrichedOrdinaryCategory V C` instance. Simplicial categories are implemented in `AlgebraicTopology.SimplicialCategory.Basic` using an abbreviation for `EnrichedOrdinaryCategory SSet C`. -/ universe v' v v'' u u' u'' open CategoryTheory Category MonoidalCategory Opposite namespace CategoryTheory variable (V : Type u') [Category.{v'} V] [MonoidalCategory V] (C : Type u) [Category.{v} C] /-- An enriched ordinary category is a category `C` that is also enriched over a category `V` in such a way that morphisms `X ⟶ Y` in `C` identify to morphisms `𝟙_ V ⟶ (X ⟶[V] Y)` in `V`. -/ class EnrichedOrdinaryCategory extends EnrichedCategory V C where /-- morphisms `X ⟶ Y` in the category identify morphisms `𝟙_ V ⟶ (X ⟶[V] Y)` in `V` -/ homEquiv {X Y : C} : (X ⟶ Y) ≃ (𝟙_ V ⟶ (X ⟶[V] Y)) homEquiv_id (X : C) : homEquiv (𝟙 X) = eId V X := by cat_disch homEquiv_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : homEquiv (f ≫ g) = (λ_ _).inv ≫ (homEquiv f ⊗ₘ homEquiv g) ≫ eComp V X Y Z := by cat_disch variable [EnrichedOrdinaryCategory V C] {C} /-- The bijection `(X ⟶ Y) ≃ (𝟙_ V ⟶ (X ⟶[V] Y))` given by a `EnrichedOrdinaryCategory` instance. -/ def eHomEquiv {X Y : C} : (X ⟶ Y) ≃ (𝟙_ V ⟶ (X ⟶[V] Y)) := EnrichedOrdinaryCategory.homEquiv @[simp] lemma eHomEquiv_id (X : C) : eHomEquiv V (𝟙 X) = eId V X := EnrichedOrdinaryCategory.homEquiv_id _ @[reassoc] lemma eHomEquiv_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : eHomEquiv V (f ≫ g) = (λ_ _).inv ≫ (eHomEquiv V f ⊗ₘ eHomEquiv V g) ≫ eComp V X Y Z := EnrichedOrdinaryCategory.homEquiv_comp _ _ /-- The morphism `(X' ⟶[V] Y) ⟶ (X ⟶[V] Y)` induced by a morphism `X ⟶ X'`. -/ def eHomWhiskerRight {X X' : C} (f : X ⟶ X') (Y : C) : (X' ⟶[V] Y) ⟶ (X ⟶[V] Y) := (λ_ _).inv ≫ eHomEquiv V f ▷ _ ≫ eComp V X X' Y @[simp] lemma eHomWhiskerRight_id (X Y : C) : eHomWhiskerRight V (𝟙 X) Y = 𝟙 _ := by simp [eHomWhiskerRight] @[simp, reassoc] lemma eHomWhiskerRight_comp {X X' X'' : C} (f : X ⟶ X') (f' : X' ⟶ X'') (Y : C) : eHomWhiskerRight V (f ≫ f') Y = eHomWhiskerRight V f' Y ≫ eHomWhiskerRight V f Y := by dsimp [eHomWhiskerRight] rw [assoc, assoc, eHomEquiv_comp, comp_whiskerRight_assoc, comp_whiskerRight_assoc, ← e_assoc', tensorHom_def', comp_whiskerRight_assoc, id_whiskerLeft, comp_whiskerRight_assoc, ← comp_whiskerRight_assoc, Iso.inv_hom_id, id_whiskerRight_assoc, comp_whiskerRight_assoc, leftUnitor_inv_whiskerRight_assoc, ← associator_inv_naturality_left_assoc, Iso.inv_hom_id_assoc, ← whisker_exchange_assoc, id_whiskerLeft_assoc, Iso.inv_hom_id_assoc] /-- Whiskering commutes with the enriched composition. -/ @[reassoc] lemma eComp_eHomWhiskerRight {X X' : C} (f : X ⟶ X') (Y Z : C) : eComp V X' Y Z ≫ eHomWhiskerRight V f Z = eHomWhiskerRight V f Y ▷ _ ≫ eComp V X Y Z := by dsimp [eHomWhiskerRight] rw [leftUnitor_inv_naturality_assoc, whisker_exchange_assoc] simp [e_assoc'] /-- The morphism `(X ⟶[V] Y) ⟶ (X ⟶[V] Y')` induced by a morphism `Y ⟶ Y'`. -/ def eHomWhiskerLeft (X : C) {Y Y' : C} (g : Y ⟶ Y') : (X ⟶[V] Y) ⟶ (X ⟶[V] Y') := (ρ_ _).inv ≫ _ ◁ eHomEquiv V g ≫ eComp V X Y Y' @[simp] lemma eHomWhiskerLeft_id (X Y : C) : eHomWhiskerLeft V X (𝟙 Y) = 𝟙 _ := by simp [eHomWhiskerLeft] @[simp, reassoc] lemma eHomWhiskerLeft_comp (X : C) {Y Y' Y'' : C} (g : Y ⟶ Y') (g' : Y' ⟶ Y'') : eHomWhiskerLeft V X (g ≫ g') = eHomWhiskerLeft V X g ≫ eHomWhiskerLeft V X g' := by dsimp [eHomWhiskerLeft] rw [assoc, assoc, eHomEquiv_comp, MonoidalCategory.whiskerLeft_comp_assoc, MonoidalCategory.whiskerLeft_comp_assoc, ← e_assoc, tensorHom_def, MonoidalCategory.whiskerRight_id_assoc, MonoidalCategory.whiskerLeft_comp_assoc, MonoidalCategory.whiskerLeft_comp_assoc, MonoidalCategory.whiskerLeft_comp_assoc, whiskerLeft_rightUnitor_assoc, whiskerLeft_rightUnitor_inv_assoc, triangle_assoc_comp_left_inv_assoc, MonoidalCategory.whiskerRight_id_assoc, Iso.hom_inv_id_assoc, Iso.inv_hom_id_assoc, associator_inv_naturality_right_assoc, Iso.hom_inv_id_assoc, whisker_exchange_assoc, MonoidalCategory.whiskerRight_id_assoc, Iso.inv_hom_id_assoc] /-- Whiskering commutes with the enriched composition. -/ @[reassoc] lemma eComp_eHomWhiskerLeft (X Y : C) {Z Z' : C} (g : Z ⟶ Z') : eComp V X Y Z ≫ eHomWhiskerLeft V X g = _ ◁ eHomWhiskerLeft V Y g ≫ eComp V X Y Z' := by dsimp [eHomWhiskerLeft] rw [rightUnitor_inv_naturality_assoc, ← whisker_exchange_assoc] simp /-- Given an isomorphism `α : Y ≅ Y₁` in C, the enriched composition map `eComp V X Y Z : (X ⟶[V] Y) ⊗ (Y ⟶[V] Z) ⟶ (X ⟶[V] Z)` factors through the `V` object `(X ⟶[V] Y₁) ⊗ (Y₁ ⟶[V] Z)` via the map defined by whiskering in the middle with `α.hom` and `α.inv`. -/ @[reassoc] lemma eHom_whisker_cancel {X Y Y₁ Z : C} (α : Y ≅ Y₁) : eHomWhiskerLeft V X α.hom ▷ _ ≫ _ ◁ eHomWhiskerRight V α.inv Z ≫ eComp V X Y₁ Z = eComp V X Y Z := by dsimp [eHomWhiskerLeft, eHomWhiskerRight] simp only [MonoidalCategory.whiskerLeft_comp_assoc, whisker_assoc_symm, triangle_assoc_comp_left_inv_assoc, e_assoc', assoc] simp only [← comp_whiskerRight_assoc] change (eHomWhiskerLeft V X α.hom ≫ eHomWhiskerLeft V X α.inv) ▷ _ ≫ _ = _ simp [← eHomWhiskerLeft_comp] @[reassoc] lemma eHom_whisker_cancel_inv {X Y Y₁ Z : C} (α : Y ≅ Y₁) : eHomWhiskerLeft V X α.inv ▷ _ ≫ _ ◁ eHomWhiskerRight V α.hom Z ≫ eComp V X Y Z = eComp V X Y₁ Z := eHom_whisker_cancel V α.symm @[reassoc] lemma eHom_whisker_exchange {X X' Y Y' : C} (f : X ⟶ X') (g : Y ⟶ Y') : eHomWhiskerLeft V X' g ≫ eHomWhiskerRight V f Y' = eHomWhiskerRight V f Y ≫ eHomWhiskerLeft V X g := by dsimp [eHomWhiskerLeft, eHomWhiskerRight] rw [assoc, assoc, assoc, assoc, leftUnitor_inv_naturality_assoc, whisker_exchange_assoc, ← e_assoc, leftUnitor_tensor_inv_assoc, associator_inv_naturality_left_assoc, Iso.hom_inv_id_assoc, ← comp_whiskerRight_assoc, whisker_exchange_assoc, MonoidalCategory.whiskerRight_id_assoc, assoc, Iso.inv_hom_id_assoc, whisker_exchange_assoc, MonoidalCategory.whiskerRight_id_assoc, Iso.inv_hom_id_assoc] attribute [local simp] eHom_whisker_exchange variable (C) in /-- The bifunctor `Cᵒᵖ ⥤ C ⥤ V` which sends `X : Cᵒᵖ` and `Y : C` to `X ⟶[V] Y`. -/ @[simps] def eHomFunctor : Cᵒᵖ ⥤ C ⥤ V where obj X := { obj := fun Y => X.unop ⟶[V] Y map := fun φ => eHomWhiskerLeft V X.unop φ } map φ := { app := fun Y => eHomWhiskerRight V φ.unop Y } instance ForgetEnrichment.enrichedOrdinaryCategory {D : Type*} [EnrichedCategory V D] : EnrichedOrdinaryCategory V (ForgetEnrichment V D) where toEnrichedCategory := inferInstanceAs (EnrichedCategory V D) homEquiv := Equiv.refl _ homEquiv_id _ := Category.id_comp _ homEquiv_comp _ _ := Category.assoc _ _ _ /-- If `D` is already an enriched ordinary category, there is a canonical functor from `D` to `ForgetEnrichment V D`. -/ @[simps] def ForgetEnrichment.equivInverse (D : Type u') [Category.{v'} D] [EnrichedOrdinaryCategory V D] : D ⥤ ForgetEnrichment V D where obj X := .of V X map f := ForgetEnrichment.homOf V (eHomEquiv V f) map_comp f g := by simp [eHomEquiv_comp] /-- If `D` is already an enriched ordinary category, there is a canonical functor from `ForgetEnrichment V D` to `D`. -/ @[simps] def ForgetEnrichment.equivFunctor (D : Type u') [Category.{v'} D] [EnrichedOrdinaryCategory V D] : ForgetEnrichment V D ⥤ D where obj X := ForgetEnrichment.to V X map f := (eHomEquiv V).symm (ForgetEnrichment.homTo V f) map_id X := by rw [ForgetEnrichment.homTo_id, ← eHomEquiv_id, Equiv.symm_apply_apply] map_comp {X} {Y} {Z} f g := Equiv.injective (eHomEquiv V (X := ForgetEnrichment.to V X) (Y := ForgetEnrichment.to V Z)) (by simp [eHomEquiv_comp]) /-- If `D` is already an enriched ordinary category, it is equivalent to `ForgetEnrichment V D`. -/ @[simps] def ForgetEnrichment.equiv {D : Type u'} [Category.{v'} D] [EnrichedOrdinaryCategory V D] : ForgetEnrichment V D ≌ D where functor := equivFunctor V D inverse := equivInverse V D unitIso := NatIso.ofComponents (fun X => Iso.refl _) counitIso := NatIso.ofComponents (fun X => Iso.refl _) functor_unitIso_comp X := Equiv.injective (eHomEquiv V (X := ForgetEnrichment.to V X) (Y := ForgetEnrichment.to V X)) (by simp) /-- enriched coyoneda functor `(X ⟶[V] _) : C ⥤ V`. -/ abbrev eCoyoneda (X : C) := (eHomFunctor V C).obj (op X) section TransportEnrichment variable {V} {W : Type u''} [Category.{v''} W] [MonoidalCategory W] (F : V ⥤ W) [F.LaxMonoidal] (C) instance : Category (TransportEnrichment F C) := inferInstanceAs (Category C) /-- If `C` is an ordinary enriched category, the category structure on `TransportEnrichment F C` is trivially equivalent to the one on `C` itself. -/ def TransportEnrichment.ofOrdinaryEnrichedCategoryEquiv : TransportEnrichment F C ≌ C := Equivalence.refl open EnrichedCategory /-- If for a lax monoidal functor `F : V ⥤ W` the canonical function `(𝟙_ V ⟶ v) → (𝟙_ W ⟶ F.obj v)` is bijective, and `C` is an enriched ordinary category on `V`, then `F` induces the structure of a `W`-enriched ordinary category on `TransportEnrichment F C`, i.e. on the same underlying category `C`. -/ noncomputable def TransportEnrichment.enrichedOrdinaryCategory (h : ∀ v : V, Function.Bijective fun (f : 𝟙_ V ⟶ v) => Functor.LaxMonoidal.ε F ≫ F.map f) : EnrichedOrdinaryCategory W (TransportEnrichment F C) where homEquiv {X Y} := (eHomEquiv V (C := C)).trans <| Equiv.ofBijective _ (h (Hom (C := C) X Y)) homEquiv_comp f g := by simp [← tensorHom_comp_tensorHom, eHomEquiv_comp, eComp_eq, tensorHom_def (Functor.LaxMonoidal.ε F), unitors_inv_equal] section Equiv variable {W : Type u''} [Category.{v''} W] [MonoidalCategory W] (F : V ⥤ W) [F.LaxMonoidal] (D : Type u) [EnrichedCategory V D] (e : ∀ v : V, (𝟙_ V ⟶ v) ≃ (𝟙_ W ⟶ F.obj v)) (h : ∀ (v : V) (f : 𝟙_ V ⟶ v), (e v) f = Functor.LaxMonoidal.ε F ≫ F.map f) /-- The functor that makes up `TransportEnrichment.forgetEnrichmentEquiv`. -/ @[simps] def TransportEnrichment.forgetEnrichmentEquivFunctor : TransportEnrichment F (ForgetEnrichment V D) ⥤ ForgetEnrichment W (TransportEnrichment F D) where obj X := ForgetEnrichment.of W X map {X} {Y} f := ForgetEnrichment.homOf W <| (e (Hom (C := ForgetEnrichment V D) X Y)) <| ForgetEnrichment.homTo V f map_id X := by rw [h, ForgetEnrichment.homTo_id, ← TransportEnrichment.eId_eq] simp [ForgetEnrichment.to] map_comp f g := by rw [h, h, h, ForgetEnrichment.homTo_comp, F.map_comp, F.map_comp, ← Category.assoc, ← Functor.LaxMonoidal.left_unitality_inv, Category.assoc, Category.assoc, Category.assoc, Category.assoc, ← Functor.LaxMonoidal.μ_natural_assoc, ← TransportEnrichment.eComp_eq, ← ForgetEnrichment.homOf_comp, leftUnitor_inv_naturality_assoc, ← tensorHom_def'_assoc, tensorHom_comp_tensorHom_assoc] rfl /-- The inverse functor that makes up `TransportEnrichment.forgetEnrichmentEquiv`. -/ @[simps] def TransportEnrichment.forgetEnrichmentEquivInverse : ForgetEnrichment W (TransportEnrichment F D) ⥤ TransportEnrichment F (ForgetEnrichment V D) where obj X := ForgetEnrichment.of V (ForgetEnrichment.to (C := TransportEnrichment F D) W X) map f := ForgetEnrichment.homOf V ((e _).symm (ForgetEnrichment.homTo W f)) map_id X := by rw [← ForgetEnrichment.homOf_eId] congr 1 apply Equiv.injective (e _) rw [ForgetEnrichment.homTo_id, Equiv.apply_symm_apply, h, TransportEnrichment.eId_eq] map_comp f g := by rw [← ForgetEnrichment.homOf_comp] congr apply Equiv.injective (e _) rw [Equiv.apply_symm_apply, h] simp only [ForgetEnrichment.homTo_comp, eComp_eq, Category.assoc, Functor.map_comp] slice_rhs 1 3 => rw [← Functor.LaxMonoidal.left_unitality_inv, Category.assoc, Category.assoc, ← Functor.LaxMonoidal.μ_natural, ← leftUnitor_inv_comp_tensorHom_assoc, tensorHom_comp_tensorHom_assoc] simp [← h] /-- If `D` is a `V`-enriched category, then forgetting the enrichment and transporting the resulting enriched ordinary category along a functor `F : V ⥤ W`, for which `f ↦ Functor.LaxMonoidal.ε F ≫ F.map f` has an inverse, results in a category equivalent to transporting along `F` and then forgetting about the resulting `W`-enrichment. -/ @[simps] def TransportEnrichment.forgetEnrichmentEquiv : TransportEnrichment F (ForgetEnrichment V D) ≌ ForgetEnrichment W (TransportEnrichment F D) where functor := forgetEnrichmentEquivFunctor _ _ e h inverse := forgetEnrichmentEquivInverse _ _ e h unitIso := NatIso.ofComponents (fun _ => Iso.refl _) (by simp) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) fun f => by simp [ForgetEnrichment.to, ForgetEnrichment.of] functor_unitIso_comp X := by simp only [Functor.id_obj, forgetEnrichmentEquivFunctor_obj, Functor.comp_obj, forgetEnrichmentEquivInverse_obj, ForgetEnrichment.to_of, NatIso.ofComponents_hom_app, Iso.refl_hom, forgetEnrichmentEquivFunctor_map, h, Category.comp_id] rw [← ForgetEnrichment.homOf_eId, TransportEnrichment.eId_eq, ForgetEnrichment.homTo_id] rfl end Equiv end TransportEnrichment end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/Limits/HasConicalProducts.lean
import Mathlib.CategoryTheory.Enriched.Limits.HasConicalLimits /-! # Existence of conical products -/ universe w v' v u u' namespace CategoryTheory.Enriched open Limits /-- Has conical products if all discrete diagrams of bounded size have conical products. -/ class HasConicalProducts (V : outParam <| Type u') [Category.{v'} V] [MonoidalCategory V] (C : Type u) [Category.{v} C] [EnrichedOrdinaryCategory V C] : Prop where /-- A family of objects (parametrized by any `J : Type w`) has a conical product. -/ hasConicalLimitsOfShape : ∀ J : Type w, HasConicalLimitsOfShape (Discrete J) V C := by infer_instance attribute [instance] HasConicalProducts.hasConicalLimitsOfShape variable (V : Type u') [Category.{v'} V] [MonoidalCategory V] variable {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory V C] /-- An abbreviation for `HasConicalLimit V (Discrete.functor f)`. -/ abbrev HasConicalProduct {I : Type w} (f : I → C) := HasConicalLimit V (Discrete.functor f) /-- ensure products exists from the existence of conical products -/ example [HasConicalProducts.{w} V C] : HasProducts.{w} C := inferInstance end CategoryTheory.Enriched
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/Limits/HasConicalPullbacks.lean
import Mathlib.CategoryTheory.Enriched.Limits.HasConicalLimits /-! # Existence of conical pullbacks -/ universe w v' v u u' namespace CategoryTheory.Enriched open Limits variable (V : Type u') [Category.{v'} V] [MonoidalCategory V] variable {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory V C] /-- `HasPullback f g` represents the mere existence of a conical limit cone for the pair of morphisms `f : X ⟶ Z` and `g : Y ⟶ Z` -/ abbrev HasConicalPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) := HasConicalLimit V (cospan f g) /-- ensure conical pullbacks are pullbacks -/ example {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasConicalPullback V f g] : HasPullback f g := inferInstance variable (C) /-- `HasConicalPullbacks` represents the existence of conical pullback for every pair of morphisms -/ abbrev HasConicalPullbacks : Prop := HasConicalLimitsOfShape WalkingCospan V C /-- ensure pullbacks exist of existence of conical pullbacks -/ example [HasConicalPullbacks V C] : HasPullbacks C := inferInstance end CategoryTheory.Enriched
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/Limits/HasConicalTerminal.lean
import Mathlib.CategoryTheory.Enriched.Limits.HasConicalProducts /-! # Existence of conical terminal objects -/ universe w v' v u u' namespace CategoryTheory.Enriched open Limits HasConicalLimit /-- A category has a conical terminal object if it has a conical limit over the empty diagram. -/ abbrev HasConicalTerminal := HasConicalLimitsOfShape (Discrete.{0} PEmpty) variable (V : Type u') [Category.{v'} V] [MonoidalCategory V] variable (C : Type u) [Category.{v} C] [EnrichedOrdinaryCategory V C] example [HasConicalTerminal V C] : HasTerminal C := inferInstance instance HasConicalProducts.hasConicalTerminal [HasConicalProducts.{w} V C] : HasConicalTerminal V C := HasConicalLimitsOfShape.of_equiv V C emptyEquivalence.functor end CategoryTheory.Enriched
.lake/packages/mathlib/Mathlib/CategoryTheory/Enriched/Limits/HasConicalLimits.lean
import Mathlib.CategoryTheory.Enriched.Ordinary.Basic import Mathlib.CategoryTheory.Limits.Final /-! # Existence of conical limits This file contains different statements about the (non-constructive) existence of conical limits. The main constructions are the following. - `HasConicalLimit`: there exists a conical limit for `F : J ⥤ C`. - `HasConicalLimitsOfShape J`: All functors `F : J ⥤ C` have conical limits. - `HasConicalLimitsOfSize.{v₁, u₁}`: For all small `J` all functors `F : J ⥤ C` have conical limits. - `HasConicalLimits `: `C` has all (small) conical limits. ## References * [Kelly G.M., *Basic concepts of enriched category theory*][kelly2005]: See section 3.8 for a similar treatment, although the content of this file is not directly adapted from there. ## Implementation notes `V` has been made an `(V : outParam <| Type u')` in the classes below as it seems instance inference prefers this. Otherwise it failed with `cannot find synthesization order` on the instances below. However, it is not fully clear yet whether this could lead to potential issues, for example if there are multiple `MonoidalCategory _` instances in scope. -/ universe v₁ u₁ v₂ u₂ w v' v u u' namespace CategoryTheory.Enriched open Limits section Definitions variable {J : Type u₁} [Category.{v₁} J] variable (V : outParam <| Type u') [Category.{v'} V] [MonoidalCategory V] variable (C : Type u) [Category.{v} C] [EnrichedOrdinaryCategory V C] variable {C} in /-- `HasConicalLimit F` represents the mere existence of a conical limit for `F`. -/ class HasConicalLimit (F : J ⥤ C) : Prop extends HasLimit F where preservesLimit_eCoyoneda (X : C) : PreservesLimit F (eCoyoneda V X) := by infer_instance attribute [instance] HasConicalLimit.preservesLimit_eCoyoneda variable (J) in /-- `C` has conical limits of shape `J` if there exists a conical limit for every functor `F : J ⥤ C`. -/ class HasConicalLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits. -/ hasConicalLimit : ∀ F : J ⥤ C, HasConicalLimit V F := by infer_instance attribute [instance] HasConicalLimitsOfShape.hasConicalLimit /-- `C` has all conical limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has conical limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasConicalLimitsOfSize : Prop where /-- All functors `F : J ⥤ C` from all small `J` have conical limits -/ hasConicalLimitsOfShape : ∀ (J : Type u₁) [Category.{v₁} J], HasConicalLimitsOfShape J V C := by infer_instance attribute [instance] HasConicalLimitsOfSize.hasConicalLimitsOfShape /-- `C` has all (small) conical limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasConicalLimits : Prop := HasConicalLimitsOfSize.{v, v} V C end Definitions section Results variable {J : Type u₁} [Category.{v₁} J] {J' : Type u₂} [Category.{v₂} J'] variable (V : Type u') [Category.{v'} V] [MonoidalCategory V] variable {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory V C] /-- ensure existence of a conical limit implies existence of a limit -/ example (F : J ⥤ C) [HasConicalLimit V F] : HasLimit F := inferInstance /-- If a functor `F` has a conical limit, so does any naturally isomorphic functor. -/ lemma HasConicalLimit.of_iso {F G : J ⥤ C} [HasConicalLimit V F] (e : F ≅ G) : HasConicalLimit V G where toHasLimit := hasLimit_of_iso e preservesLimit_eCoyoneda X := preservesLimit_of_iso_diagram (eCoyoneda V X) e instance HasConicalLimit.of_equiv (F : J ⥤ C) [HasConicalLimit V F] (G : J' ⥤ J) [G.IsEquivalence] : HasConicalLimit V (G ⋙ F) where /-- If a `G ⋙ F` has a limit, and `G` is an equivalence, we can construct a limit of `F`. -/ lemma HasConicalLimit.of_equiv_comp (F : J ⥤ C) (G : J' ⥤ J) [G.IsEquivalence] [HasConicalLimit V (G ⋙ F)] : HasConicalLimit V F := have e : G.inv ⋙ G ⋙ F ≅ F := G.asEquivalence.invFunIdAssoc F HasConicalLimit.of_iso V e variable (C) variable (J) in /-- existence of conical limits (of shape) implies existence of limits (of shape) -/ instance HasConicalLimitsOfShape.hasLimitsOfShape [HasConicalLimitsOfShape J V C] : HasLimitsOfShape J C where /-- We can transport conical limits of shape `J'` along an equivalence `J' ≌ J`. -/ lemma HasConicalLimitsOfShape.of_equiv [HasConicalLimitsOfShape J' V C] (G : J' ⥤ J) [G.IsEquivalence] : HasConicalLimitsOfShape J V C where hasConicalLimit F := HasConicalLimit.of_equiv_comp V F G /-- existence of conical limits (of size) implies existence of limits (of size) -/ instance HasConicalLimitsOfSize.hasLimitsOfSize [HasConicalLimitsOfSize.{v₁, u₁} V C] : HasLimitsOfSize.{v₁, u₁} C where /-- ensure existence of (small) conical limits implies existence of (small) limits -/ example [HasConicalLimits V C] : HasLimits C := inferInstance end Results end CategoryTheory.Enriched
.lake/packages/mathlib/Mathlib/CategoryTheory/PathCategory/Basic.lean
import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Quotient import Mathlib.Combinatorics.Quiver.Path /-! # The category paths on a quiver. When `C` is a quiver, `paths C` is the category of paths. ## When the quiver is itself a category We provide `path_composition : paths C ⥤ C`. We check that the quotient of the path category of a category by the canonical relation (paths are related if they compose to the same path) is equivalent to the original category. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory section /-- A type synonym for the category of paths in a quiver. -/ def Paths (V : Type u₁) : Type u₁ := V instance (V : Type u₁) [Inhabited V] : Inhabited (Paths V) := ⟨(default : V)⟩ variable (V : Type u₁) [Quiver.{v₁ + 1} V] namespace Paths instance categoryPaths : Category.{max u₁ v₁} (Paths V) where Hom := fun X Y : V => Quiver.Path X Y id _ := Quiver.Path.nil comp f g := Quiver.Path.comp f g /-- The inclusion of a quiver `V` into its path category, as a prefunctor. -/ @[simps] def of : V ⥤q Paths V where obj X := X map f := f.toPath variable {V} /-- To prove a property on morphisms of a path category with given source `a`, it suffices to prove it for the identity and prove that the property is preserved under composition on the right with length 1 paths. -/ lemma induction_fixed_source {a : Paths V} (P : ∀ {b : Paths V}, (a ⟶ b) → Prop) (id : P (𝟙 a)) (comp : ∀ {u v : V} (p : a ⟶ (of V).obj u) (q : u ⟶ v), P p → P (p ≫ (of V).map q)) : ∀ {b : Paths V} (f : a ⟶ b), P f := by intro _ f induction f with | nil => exact id | cons _ w h => exact comp _ w h /-- To prove a property on morphisms of a path category with given target `b`, it suffices to prove it for the identity and prove that the property is preserved under composition on the left with length 1 paths. -/ lemma induction_fixed_target {b : Paths V} (P : ∀ {a : Paths V}, (a ⟶ b) → Prop) (id : P (𝟙 b)) (comp : ∀ {u v : V} (p : (of V).obj v ⟶ b) (q : u ⟶ v), P p → P ((of V).map q ≫ p)) : ∀ {a : Paths V} (f : a ⟶ b), P f := by intro a f generalize h : f.length = k induction k generalizing f a with | zero => cases f with | nil => exact id | cons _ _ => simp at h | succ k h' => obtain ⟨c, f, q, hq, rfl⟩ := f.eq_toPath_comp_of_length_eq_succ h exact comp _ _ (h' _ hq) /-- To prove a property on morphisms of a path category, it suffices to prove it for the identity and prove that the property is preserved under composition on the right with length 1 paths. -/ lemma induction (P : ∀ {a b : Paths V}, (a ⟶ b) → Prop) (id : ∀ {v : V}, P (𝟙 ((of V).obj v))) (comp : ∀ {u v w : V} (p : (of V).obj u ⟶ (of V).obj v) (q : v ⟶ w), P p → P (p ≫ (of V).map q)) : ∀ {a b : Paths V} (f : a ⟶ b), P f := fun {_} ↦ induction_fixed_source _ id comp /-- To prove a property on morphisms of a path category, it suffices to prove it for the identity and prove that the property is preserved under composition on the left with length 1 paths. -/ lemma induction' (P : ∀ {a b : Paths V}, (a ⟶ b) → Prop) (id : ∀ {v : V}, P (𝟙 ((of V).obj v))) (comp : ∀ {u v w : V} (p : u ⟶ v) (q : (of V).obj v ⟶ (of V).obj w), P q → P ((of V).map p ≫ q)) : ∀ {a b : Paths V} (f : a ⟶ b), P f := by intro a b revert a exact induction_fixed_target (P := fun f ↦ P f) id (fun _ _ ↦ comp _ _) attribute [local ext (iff := false)] Functor.ext /-- Any prefunctor from `V` lifts to a functor from `paths V` -/ def lift {C} [Category C] (φ : V ⥤q C) : Paths V ⥤ C where obj := φ.obj map {X} {Y} f := @Quiver.Path.rec V _ X (fun Y _ => φ.obj X ⟶ φ.obj Y) (𝟙 <| φ.obj X) (fun _ f ihp => ihp ≫ φ.map f) Y f map_id _ := rfl map_comp f g := by induction g with | nil => rw [Category.comp_id] rfl | cons g' p ih => have : f ≫ Quiver.Path.cons g' p = (f ≫ g').cons p := by apply Quiver.Path.comp_cons rw [this] simp only at ih ⊢ rw [ih, Category.assoc] @[simp] theorem lift_nil {C} [Category C] (φ : V ⥤q C) (X : V) : (lift φ).map Quiver.Path.nil = 𝟙 (φ.obj X) := rfl @[simp] theorem lift_cons {C} [Category C] (φ : V ⥤q C) {X Y Z : V} (p : Quiver.Path X Y) (f : Y ⟶ Z) : (lift φ).map (p.cons f) = (lift φ).map p ≫ φ.map f := rfl @[simp] theorem lift_toPath {C} [Category C] (φ : V ⥤q C) {X Y : V} (f : X ⟶ Y) : (lift φ).map f.toPath = φ.map f := by dsimp [Quiver.Hom.toPath, lift] simp theorem lift_spec {C} [Category C] (φ : V ⥤q C) : of V ⋙q (lift φ).toPrefunctor = φ := by fapply Prefunctor.ext · rintro X rfl · rintro X Y f rcases φ with ⟨φo, φm⟩ dsimp [lift, Quiver.Hom.toPath] simp theorem lift_unique {C} [Category C] (φ : V ⥤q C) (Φ : Paths V ⥤ C) (hΦ : of V ⋙q Φ.toPrefunctor = φ) : Φ = lift φ := by subst_vars fapply Functor.ext · rintro X rfl · rintro X Y f dsimp [lift] induction f with | nil => simp only [Category.comp_id] apply Functor.map_id | cons p f' ih => simp only [Category.comp_id, Category.id_comp] at ih ⊢ -- Porting note: Had to do substitute `p.cons f'` and `f'.toPath` by their fully qualified -- versions in this `have` clause (elsewhere too). have : Φ.map (Quiver.Path.cons p f') = Φ.map p ≫ Φ.map (Quiver.Hom.toPath f') := by convert Functor.map_comp Φ p (Quiver.Hom.toPath f') rw [this, ih] /-- Two functors out of a path category are equal when they agree on singleton paths. -/ @[ext (iff := false)] theorem ext_functor {C} [Category C] {F G : Paths V ⥤ C} (h_obj : F.obj = G.obj) (h : ∀ (a b : V) (e : a ⟶ b), F.map e.toPath = eqToHom (congr_fun h_obj a) ≫ G.map e.toPath ≫ eqToHom (congr_fun h_obj.symm b)) : F = G := by fapply Functor.ext · intro X rw [h_obj] · intro X Y f induction f with | nil => erw [F.map_id, G.map_id, Category.id_comp, eqToHom_trans, eqToHom_refl] | cons g e ih => erw [F.map_comp g (Quiver.Hom.toPath e), G.map_comp g (Quiver.Hom.toPath e), ih, h] simp only [Category.id_comp, eqToHom_refl, eqToHom_trans_assoc, Category.assoc] end Paths variable (W : Type u₂) [Quiver.{v₂ + 1} W] -- A restatement of `Prefunctor.mapPath_comp` using `f ≫ g` instead of `f.comp g`. @[simp] theorem Prefunctor.mapPath_comp' (F : V ⥤q W) {X Y Z : Paths V} (f : X ⟶ Y) (g : Y ⟶ Z) : F.mapPath (f ≫ g) = (F.mapPath f).comp (F.mapPath g) := Prefunctor.mapPath_comp _ _ _ end section variable {C : Type u₁} [Category.{v₁} C] open Quiver /-- A path in a category can be composed to a single morphism. -/ @[simp] def composePath {X : C} : ∀ {Y : C} (_ : Path X Y), X ⟶ Y | _, .nil => 𝟙 X | _, .cons p e => composePath p ≫ e -- This lemma was marked as `@[simp]` but it is generated by `@[simp]` on `composePath`. lemma composePath_nil {X : C} : composePath (Path.nil : Path X X) = 𝟙 X := rfl -- This lemma was marked as `@[simp]` but it is generated by `@[simp]` on `composePath`. lemma composePath_cons {X Y Z : C} (p : Path X Y) (e : Y ⟶ Z) : composePath (p.cons e) = composePath p ≫ e := rfl @[simp] theorem composePath_toPath {X Y : C} (f : X ⟶ Y) : composePath f.toPath = f := Category.id_comp _ @[simp] theorem composePath_comp {X Y Z : C} (f : Path X Y) (g : Path Y Z) : composePath (f.comp g) = composePath f ≫ composePath g := by induction g with | nil => simp | cons g e ih => simp [ih] @[simp] -- TODO get rid of `(id X : C)` somehow? theorem composePath_id {X : Paths C} : composePath (𝟙 X) = 𝟙 (show C from X) := rfl @[simp] theorem composePath_comp' {X Y Z : Paths C} (f : X ⟶ Y) (g : Y ⟶ Z) : composePath (f ≫ g) = composePath f ≫ composePath g := composePath_comp f g variable (C) /-- Composition of paths as functor from the path category of a category to the category. -/ @[simps] def pathComposition : Paths C ⥤ C where obj X := X map f := composePath f -- TODO: This, and what follows, should be generalized to -- the `HomRel` for the kernel of any functor. -- Indeed, this should be part of an equivalence between congruence relations on a category `C` -- and full, essentially surjective functors out of `C`. /-- The canonical relation on the path category of a category: two paths are related if they compose to the same morphism. -/ @[simp] def pathsHomRel : HomRel (Paths C) := fun _ _ p q => (pathComposition C).map p = (pathComposition C).map q /-- The functor from a category to the canonical quotient of its path category. -/ @[simps] def toQuotientPaths : C ⥤ Quotient (pathsHomRel C) where obj X := Quotient.mk X map f := Quot.mk _ f.toPath map_id X := Quot.sound (Quotient.CompClosure.of _ _ _ (by simp)) map_comp f g := Quot.sound (Quotient.CompClosure.of _ _ _ (by simp)) /-- The functor from the canonical quotient of a path category of a category to the original category. -/ @[simps!] def quotientPathsTo : Quotient (pathsHomRel C) ⥤ C := Quotient.lift _ (pathComposition C) fun _ _ _ _ w => w /-- The canonical quotient of the path category of a category is equivalent to the original category. -/ def quotientPathsEquiv : Quotient (pathsHomRel C) ≌ C where functor := quotientPathsTo C inverse := toQuotientPaths C unitIso := NatIso.ofComponents (fun X => by cases X; rfl) (Quot.ind fun f => by apply Quot.sound apply Quotient.CompClosure.of simp [Category.comp_id, Category.id_comp, pathsHomRel]) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) (fun f => by simp) functor_unitIso_comp X := by cases X simp only [Functor.id_obj, quotientPathsTo_obj, Functor.comp_obj, toQuotientPaths_obj_as, NatIso.ofComponents_hom_app, Iso.refl_hom, quotientPathsTo_map, Category.comp_id] rfl end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/PathCategory/MorphismProperty.lean
import Mathlib.CategoryTheory.PathCategory.Basic import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Properties of morphisms in a path category. We provide a formulation of induction principles for morphisms in a path category in terms of `MorphismProperty`. This file is separate from `CategoryTheory.PathCategory.Basic` in order to reduce transitive imports. -/ universe v₁ u₁ namespace CategoryTheory.Paths section variable (V : Type u₁) [Quiver.{v₁ + 1} V] /-- A reformulation of `CategoryTheory.Paths.induction` in terms of `MorphismProperty`. -/ lemma morphismProperty_eq_top (P : MorphismProperty (Paths V)) (id : ∀ {v : V}, P (𝟙 ((of V).obj v))) (comp : ∀ {u v w : V} (p : (of V).obj u ⟶ (of V).obj v) (q : v ⟶ w), P p → P (p ≫ (of V).map q)) : P = ⊤ := by ext; constructor · simp · exact fun _ ↦ induction (fun f ↦ P f) id comp _ /-- A reformulation of `CategoryTheory.Paths.induction'` in terms of `MorphismProperty`. -/ lemma morphismProperty_eq_top' (P : MorphismProperty (Paths V)) (id : ∀ {v : V}, P (𝟙 ((of V).obj v))) (comp : ∀ {u v w : V} (p : u ⟶ v) (q : (of V).obj v ⟶ (of V).obj w), P q → P ((of V).map p ≫ q)) : P = ⊤ := by ext; constructor · simp · exact fun _ ↦ induction' (fun f ↦ P f) id comp _ lemma morphismProperty_eq_top_of_isMultiplicative (P : MorphismProperty (Paths V)) [P.IsMultiplicative] (hP : ∀ {u v : V} (p : u ⟶ v), P ((of V).map p)) : P = ⊤ := morphismProperty_eq_top _ _ (P.id_mem _) (fun _ q hp ↦ P.comp_mem _ _ hp (hP q)) end section variable {C : Type*} [Category C] {V : Type u₁} [Quiver.{v₁ + 1} V] /-- A natural transformation between `F G : Paths V ⥤ C` is defined by its components and its unary naturality squares. -/ @[simps] def liftNatTrans {F G : Paths V ⥤ C} (α_app : (v : V) → (F.obj v ⟶ G.obj v)) (α_nat : {X Y : V} → (f : X ⟶ Y) → F.map (Quiver.Hom.toPath f) ≫ α_app Y = α_app X ≫ G.map (Quiver.Hom.toPath f)) : F ⟶ G where app := α_app naturality := by apply MorphismProperty.of_eq_top (P := MorphismProperty.naturalityProperty (F₁ := F) α_app) exact morphismProperty_eq_top_of_isMultiplicative _ _ α_nat /-- A natural isomorphism between `F G : Paths V ⥤ C` is defined by its components and its unary naturality squares. -/ @[simps!] def liftNatIso {C} [Category C] {F G : Paths V ⥤ C} (α_app : (v : V) → (F.obj v ≅ G.obj v)) (α_nat : {X Y : V} → (f : X ⟶ Y) → F.map (Quiver.Hom.toPath f) ≫ (α_app Y).hom = (α_app X).hom ≫ G.map (Quiver.Hom.toPath f)) : F ≅ G := NatIso.ofComponents α_app (fun f ↦ (liftNatTrans (fun v ↦ (α_app v).hom) α_nat).naturality f) end end CategoryTheory.Paths
.lake/packages/mathlib/Mathlib/CategoryTheory/Quotient/Linear.lean
import Mathlib.CategoryTheory.Quotient import Mathlib.CategoryTheory.Linear.LinearFunctor /-! # The quotient category is linear If `r : HomRel C` is a congruence on a preadditive category `C` which satisfies certain compatibilities, we have already defined a preadditive structure on `Quotient r` in the file `CategoryTheory.Quotient.Preadditive` such that `functor r : C ⥤ Quotient r` is an additive functor. In this file, assuming moreover that `C` is a `R`-linear category and that the relation `r` is compatible with the scalar multiplication by any `a : R`, we show that `Quotient r` is a `R`-linear category and that `functor r : C ⥤ Quotient r` is a `R`-linear functor. -/ namespace CategoryTheory namespace Quotient variable {R C : Type*} [Semiring R] [Category C] [Preadditive C] [Linear R C] (r : HomRel C) [Congruence r] namespace Linear /-- The scalar multiplications on morphisms in `Quotient R`. -/ def smul (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) (X Y : Quotient r) : SMul R (X ⟶ Y) where smul a := Quot.lift (fun g => Quot.mk _ (a • g)) (fun f₁ f₂ h₁₂ => by dsimp simp only [compClosure_eq_self] at h₁₂ apply Quot.sound rw [compClosure_eq_self] exact hr _ _ _ h₁₂) @[simp] lemma smul_eq (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) (a : R) {X Y : C} (f : X ⟶ Y) : letI := smul r hr a • (functor r).map f = (functor r).map (a • f) := rfl /-- Auxiliary definition for `Quotient.Linear.module`. -/ def module' (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] (X Y : C) : Module R ((functor r).obj X ⟶ (functor r).obj Y) := letI smul := smul r hr ((functor r).obj X) ((functor r).obj Y) { smul_zero := fun a => by rw [← (functor r).map_zero X Y, smul_eq, smul_zero] zero_smul := fun f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [zero_smul, Functor.map_zero] one_smul := fun f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [one_smul] mul_smul := fun a b f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [mul_smul] smul_add := fun a f g => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f obtain ⟨g, rfl⟩ := (functor r).map_surjective g dsimp [smul] rw [← (functor r).map_add, smul_eq, ← (functor r).map_add, smul_add] add_smul := fun a b f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [add_smul, Functor.map_add] } /-- Auxiliary definition for `Quotient.linear`. -/ def module (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] (X Y : Quotient r) : Module R (X ⟶ Y) := module' r hr X.as Y.as end Linear variable (R) /-- Assuming `Quotient r` has already been endowed with a preadditive category structure such that `functor r : C ⥤ Quotient r` is additive, and that `C` has a `R`-linear category structure compatible with `r`, this is the induced `R`-linear category structure on `Quotient r`. -/ def linear (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] : Linear R (Quotient r) := by letI := Linear.module r hr exact { smul_comp := by rintro ⟨X⟩ ⟨Y⟩ ⟨Z⟩ a f g obtain ⟨f, rfl⟩ := (functor r).map_surjective f obtain ⟨g, rfl⟩ := (functor r).map_surjective g rw [Linear.smul_eq, ← Functor.map_comp, ← Functor.map_comp, Linear.smul_eq, Linear.smul_comp] comp_smul := by rintro ⟨X⟩ ⟨Y⟩ ⟨Z⟩ f a g obtain ⟨f, rfl⟩ := (functor r).map_surjective f obtain ⟨g, rfl⟩ := (functor r).map_surjective g rw [Linear.smul_eq, ← Functor.map_comp, ← Functor.map_comp, Linear.smul_eq, Linear.comp_smul] } instance linear_functor (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] : letI := linear R r hr; Functor.Linear R (functor r) := by letI := linear R r hr; exact { } end Quotient end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Quotient/Preadditive.lean
import Mathlib.CategoryTheory.Quotient import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! # The quotient category is preadditive If an equivalence relation `r : HomRel C` on the morphisms of a preadditive category is compatible with the addition, then the quotient category `Quotient r` is also preadditive. -/ namespace CategoryTheory namespace Quotient variable {C : Type _} [Category C] [Preadditive C] (r : HomRel C) [Congruence r] namespace Preadditive /-- The addition on the morphisms in the category `Quotient r` when `r` is compatible with the addition. -/ def add (hr : ∀ ⦃X Y : C⦄ (f₁ f₂ g₁ g₂ : X ⟶ Y) (_ : r f₁ f₂) (_ : r g₁ g₂), r (f₁ + g₁) (f₂ + g₂)) {X Y : Quotient r} (f g : X ⟶ Y) : X ⟶ Y := Quot.liftOn₂ f g (fun a b => Quot.mk _ (a + b)) (fun f g₁ g₂ h₁₂ => by simp only [compClosure_iff_self] at h₁₂ erw [functor_map_eq_iff] exact hr _ _ _ _ (Congruence.equivalence.refl f) h₁₂) (fun f₁ f₂ g h₁₂ => by simp only [compClosure_iff_self] at h₁₂ erw [functor_map_eq_iff] exact hr _ _ _ _ h₁₂ (Congruence.equivalence.refl g)) /-- The negation on the morphisms in the category `Quotient r` when `r` is compatible with the addition. -/ def neg (hr : ∀ ⦃X Y : C⦄ (f₁ f₂ g₁ g₂ : X ⟶ Y) (_ : r f₁ f₂) (_ : r g₁ g₂), r (f₁ + g₁) (f₂ + g₂)) {X Y : Quotient r} (f : X ⟶ Y) : X ⟶ Y := Quot.liftOn f (fun a => Quot.mk _ (-a)) (fun f g => by intro hfg simp only [compClosure_iff_self] at hfg erw [functor_map_eq_iff] apply Congruence.equivalence.symm convert hr f g _ _ hfg (Congruence.equivalence.refl (-f-g)) using 1 <;> abel) end Preadditive /-- The preadditive structure on the category `Quotient r` when `r` is compatible with the addition. -/ def preadditive (hr : ∀ ⦃X Y : C⦄ (f₁ f₂ g₁ g₂ : X ⟶ Y) (_ : r f₁ f₂) (_ : r g₁ g₂), r (f₁ + g₁) (f₂ + g₂)) : Preadditive (Quotient r) where homGroup P Q := let iZ : Zero (P ⟶ Q) := { zero := Quot.mk _ 0 } let iA : Add (P ⟶ Q) := { add := Preadditive.add r hr } let iN : Neg (P ⟶ Q) := { neg := Preadditive.neg r hr } { add_assoc := by rintro ⟨_⟩ ⟨_⟩ ⟨_⟩; exact congr_arg (functor r).map (add_assoc _ _ _) zero_add := by rintro ⟨_⟩; exact congr_arg (functor r).map (zero_add _) add_zero := by rintro ⟨_⟩; exact congr_arg (functor r).map (add_zero _) add_comm := by rintro ⟨_⟩ ⟨_⟩; exact congr_arg (functor r).map (add_comm _ _) neg_add_cancel := by rintro ⟨_⟩; exact congr_arg (functor r).map (neg_add_cancel _) -- todo: use a better defeq nsmul := nsmulRec zsmul := zsmulRec } add_comp := by rintro _ _ _ ⟨_⟩ ⟨_⟩ ⟨_⟩ exact congr_arg (functor r).map (by apply Preadditive.add_comp) comp_add := by rintro _ _ _ ⟨_⟩ ⟨_⟩ ⟨_⟩ exact congr_arg (functor r).map (by apply Preadditive.comp_add) lemma functor_additive (hr : ∀ ⦃X Y : C⦄ (f₁ f₂ g₁ g₂ : X ⟶ Y) (_ : r f₁ f₂) (_ : r g₁ g₂), r (f₁ + g₁) (f₂ + g₂)) : letI := preadditive r hr (functor r).Additive := letI := preadditive r hr { map_add := rfl } end Quotient end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sums/Products.lean
import Mathlib.CategoryTheory.Sums.Associator import Mathlib.CategoryTheory.Products.Associator /-! # Functors out of sums of categories. This file records the universal property of sums of categories as an equivalence of categories `Sum.functorEquiv : A ⊕ A' ⥤ B ≌ (A ⥤ B) × (A' ⥤ B)`, and characterizes its precompositions with the left and right inclusion as corresponding to the projections on the product side. -/ namespace CategoryTheory open Functor universe v u variable (A : Type*) [Category A] (A' : Type*) [Category A'] (B : Type u) [Category.{v} B] namespace Sum /-- The equivalence between functors from a sum and the product of the functor categories. -/ @[simps] def functorEquiv : A ⊕ A' ⥤ B ≌ (A ⥤ B) × (A' ⥤ B) where functor := { obj F := ⟨inl_ A A' ⋙ F, inr_ A A' ⋙ F⟩ map η := ⟨whiskerLeft (inl_ A A') η, whiskerLeft (inr_ A A') η⟩ } inverse := { obj F := Functor.sum' F.1 F.2 map η := NatTrans.sum' η.1 η.2 } unitIso := NatIso.ofComponents <| fun F ↦ F.isoSum counitIso := NatIso.ofComponents <| fun F ↦ (Functor.inlCompSum' _ _).prod (Functor.inrCompSum' _ _) ≪≫ prod.etaIso F variable {A A' B} @[simp] lemma functorEquiv_unit_app_app_inl (X : A ⊕ A' ⥤ B) (a : A) : ((functorEquiv A A' B).unit.app X).app (.inl a) = 𝟙 (X.obj (.inl a)) := rfl @[simp] lemma functorEquiv_unit_app_app_inr (X : A ⊕ A' ⥤ B) (a' : A') : ((functorEquiv A A' B).unit.app X).app (.inr a') = 𝟙 (X.obj (.inr a')) := rfl @[simp] lemma functorEquiv_unitIso_inv_app_app_inl (X : A ⊕ A' ⥤ B) (a : A) : ((functorEquiv A A' B).unitIso.inv.app X).app (.inl a) = 𝟙 (X.obj (.inl a)) := rfl @[simp] lemma functorEquiv_unitIso_inv_app_app_inr (X : A ⊕ A' ⥤ B) (a' : A') : ((functorEquiv A A' B).unitIso.inv.app X).app (.inr a') = 𝟙 (X.obj (.inr a')) := rfl /-- Composing the forward direction of `functorEquiv` with the first projection is the same as precomposition with `inl_ A A'`. -/ @[simps!] def functorEquivFunctorCompFstIso : (functorEquiv A A' B).functor ⋙ Prod.fst (A ⥤ B) (A' ⥤ B) ≅ (whiskeringLeft A (A ⊕ A') B).obj (inl_ A A') := NatIso.ofComponents (fun _ ↦ Iso.refl _) /-- Composing the forward direction of `functorEquiv` with the second projection is the same as precomposition with `inr_ A A'`. -/ @[simps!] def functorEquivFunctorCompSndIso : (functorEquiv A A' B).functor ⋙ Prod.snd (A ⥤ B) (A' ⥤ B) ≅ (whiskeringLeft A' (A ⊕ A') B).obj (inr_ A A') := NatIso.ofComponents (fun _ ↦ Iso.refl _) /-- Composing the backward direction of `functorEquiv` with precomposition with `inl_ A A'`. is naturally isomorphic to the first projection. -/ @[simps!] def functorEquivInverseCompWhiskeringLeftInlIso : (functorEquiv A A' B).inverse ⋙ (whiskeringLeft A (A ⊕ A') B).obj (inl_ A A') ≅ Prod.fst (A ⥤ B) (A' ⥤ B) := NatIso.ofComponents (fun _ ↦ Functor.inlCompSum' _ _) /-- Composing the backward direction of `functorEquiv` with the second projection is the same as precomposition with `inr_ A A'`. -/ @[simps!] def functorEquivInverseCompWhiskeringLeftInrIso : (functorEquiv A A' B).inverse ⋙ (whiskeringLeft A' (A ⊕ A') B).obj (inr_ A A') ≅ Prod.snd (A ⥤ B) (A' ⥤ B) := NatIso.ofComponents (fun _ ↦ Functor.inrCompSum' _ _) /-- A consequence of `functorEquiv`: we can construct a natural transformation of functors `A ⊕ A' ⥤ B` from the data of natural transformations of their whiskering with `inl_` and `inr_`. -/ @[simps!] def natTransOfWhiskerLeftInlInr {F G : A ⊕ A' ⥤ B} (η₁ : Sum.inl_ A A' ⋙ F ⟶ Sum.inl_ A A' ⋙ G) (η₂ : Sum.inr_ A A' ⋙ F ⟶ Sum.inr_ A A' ⋙ G) : F ⟶ G := (Sum.functorEquiv A A' B).unit.app F ≫ (Sum.functorEquiv A A' B).inverse.map ((η₁, η₂) :) ≫ (Sum.functorEquiv A A' B).unitInv.app G @[simp] lemma natTransOfWhiskerLeftInlInr_id {F : A ⊕ A' ⥤ B} : natTransOfWhiskerLeftInlInr (𝟙 (Sum.inl_ A A' ⋙ F)) (𝟙 (Sum.inr_ A A' ⋙ F)) = 𝟙 F := by cat_disch @[simp] lemma natTransOfWhiskerLeftInlInr_comp {F G H : A ⊕ A' ⥤ B} (η₁ : Sum.inl_ A A' ⋙ F ⟶ Sum.inl_ A A' ⋙ G) (η₂ : Sum.inr_ A A' ⋙ F ⟶ Sum.inr_ A A' ⋙ G) (ν₁ : Sum.inl_ A A' ⋙ G ⟶ Sum.inl_ A A' ⋙ H) (ν₂ : Sum.inr_ A A' ⋙ G ⟶ Sum.inr_ A A' ⋙ H) : natTransOfWhiskerLeftInlInr (η₁ ≫ ν₁) (η₂ ≫ ν₂) = natTransOfWhiskerLeftInlInr η₁ η₂ ≫ natTransOfWhiskerLeftInlInr ν₁ ν₂ := by cat_disch /-- A consequence of `functorEquiv`: we can construct a natural isomorphism of functors `A ⊕ A' ⥤ B` from the data of natural isomorphisms of their whiskering with `inl_` and `inr_`. -/ @[simps] def natIsoOfWhiskerLeftInlInr {F G : A ⊕ A' ⥤ B} (η₁ : Sum.inl_ A A' ⋙ F ≅ Sum.inl_ A A' ⋙ G) (η₂ : Sum.inr_ A A' ⋙ F ≅ Sum.inr_ A A' ⋙ G) : F ≅ G where hom := natTransOfWhiskerLeftInlInr η₁.hom η₂.hom inv := natTransOfWhiskerLeftInlInr η₁.inv η₂.inv lemma natIsoOfWhiskerLeftInlInr_eq {F G : A ⊕ A' ⥤ B} (η₁ : Sum.inl_ A A' ⋙ F ≅ Sum.inl_ A A' ⋙ G) (η₂ : Sum.inr_ A A' ⋙ F ≅ Sum.inr_ A A' ⋙ G) : natIsoOfWhiskerLeftInlInr η₁ η₂ = (Sum.functorEquiv A A' B).unitIso.app _ ≪≫ (Sum.functorEquiv A A' B).inverse.mapIso (Iso.prod η₁ η₂) ≪≫ (Sum.functorEquiv A A' B).unitIso.symm.app _ := by cat_disch namespace Swap /-- `functorEquiv A A' B` transforms `Swap.equivalence` into `Prod.braiding`. -/ @[simps! hom_app_fst hom_app_snd inv_app_fst inv_app_snd] def equivalenceFunctorEquivFunctorIso : ((equivalence A A').congrLeft.trans <| functorEquiv A' A B).functor ≅ ((functorEquiv A A' B).trans <| Prod.braiding (A ⥤ B) (A' ⥤ B)).functor := NatIso.ofComponents (fun E ↦ Iso.prod ((Functor.associator _ _ E).symm ≪≫ isoWhiskerRight (Sum.swapCompInl A' A) _) ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (Sum.swapCompInr A' A) _)) end Swap section CompatibilityWithProductAssociator variable (T : Type*) [Category T] /-- The equivalence `Sum.functorEquiv` sends associativity of sums to associativity of products -/ @[simps! hom_app_fst hom_app_snd_fst hom_app_snd_snd inv_app_fst inv_app_snd_fst inv_app_snd_snd] def associativityFunctorEquivNaturalityFunctorIso : ((sum.associativity A A' T).congrLeft.trans <| (Sum.functorEquiv A (A' ⊕ T) B).trans <| Equivalence.refl.prod <| Sum.functorEquiv _ _ B).functor ≅ (Sum.functorEquiv (A ⊕ A') T B).trans ((Sum.functorEquiv A A' B).prod Equivalence.refl) |>.trans (prod.associativity _ _ _) |>.functor := NatIso.ofComponents (fun E ↦ Iso.prod ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (sum.inlCompInverseAssociator A A' T) E ≪≫ Functor.associator _ _ _) (Iso.prod (isoWhiskerLeft _ (Functor.associator _ _ E).symm ≪≫ (Functor.associator _ _ E).symm ≪≫ isoWhiskerRight (sum.inlCompInrCompInverseAssociator A A' T) E ≪≫ Functor.associator _ _ E) (isoWhiskerLeft _ (Functor.associator _ _ E).symm ≪≫ (Functor.associator _ _ E).symm ≪≫ isoWhiskerRight (sum.inrCompInrCompInverseAssociator A A' T) E))) (by intros ext all_goals dsimp simp only [Category.comp_id, Category.id_comp, NatTrans.naturality]) end CompatibilityWithProductAssociator end Sum end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sums/Basic.lean
import Mathlib.CategoryTheory.Equivalence /-! # Binary disjoint unions of categories We define the category instance on `C ⊕ D` when `C` and `D` are categories. We define: * `inl_` : the functor `C ⥤ C ⊕ D` * `inr_` : the functor `D ⥤ C ⊕ D` * `swap` : the functor `C ⊕ D ⥤ D ⊕ C` (and the fact this is an equivalence) We provide an induction principle `Sum.homInduction` to reason and work with morphisms in this category. The sum of two functors `F : A ⥤ C` and `G : B ⥤ C` is a functor `A ⊕ B ⥤ C`, written `F.sum' G`. This construction should be preferred when defining functors out of a sum. We provide natural isomorphisms `inlCompSum' : inl_ ⋙ F.sum' G ≅ F` and `inrCompSum' : inl_ ⋙ F.sum' G ≅ G`. Furthermore, we provide `Functor.sumIsoExt`, which constructs a natural isomorphism of functors out of a sum out of natural isomorphism with their precomposition with the inclusion. This construction should be preferred when trying to construct isomorphisms between functors out of a sum. We further define sums of functors and natural transformations, written `F.sum G` and `α.sum β`. -/ namespace CategoryTheory universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ -- morphism levels before object levels. See note [category_theory universes]. open Sum Functor section variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D] /-- `sum C D` gives the direct sum of two categories. -/ instance sum : Category.{max v₁ v₂} (C ⊕ D) where Hom X Y := match X, Y with | inl X, inl Y => ULift.{max v₁ v₂} (X ⟶ Y) | inl _, inr _ => PEmpty | inr _, inl _ => PEmpty | inr X, inr Y => ULift.{max v₁ v₂} (X ⟶ Y) id X := match X with | inl X => ULift.up (𝟙 X) | inr X => ULift.up (𝟙 X) comp {X Y Z} f g := match X, Y, Z, f, g with | inl _, inl _, inl _, f, g => ULift.up <|f.down ≫ g.down | inr _, inr _, inr _, f, g => ULift.up <| f.down ≫ g.down @[aesop norm -10 destruct (rule_sets := [CategoryTheory])] theorem hom_inl_inr_false {X : C} {Y : D} (f : Sum.inl X ⟶ Sum.inr Y) : False := by cases f @[aesop norm -10 destruct (rule_sets := [CategoryTheory])] theorem hom_inr_inl_false {X : C} {Y : D} (f : Sum.inr X ⟶ Sum.inl Y) : False := by cases f end namespace Sum variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D] -- Unfortunate naming here, suggestions welcome. /-- `inl_` is the functor `X ↦ inl X`. -/ @[simps! obj] def inl_ : C ⥤ C ⊕ D where obj X := inl X map f := ULift.up f /-- `inr_` is the functor `X ↦ inr X`. -/ @[simps! obj] def inr_ : D ⥤ C ⊕ D where obj X := inr X map f := ULift.up f variable {C D} /-- An induction principle for morphisms in a sum of category: a morphism is either of the form `(inl_ _ _).map _` or of the form `(inr_ _ _).map _)`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] def homInduction {P : {x y : C ⊕ D} → (x ⟶ y) → Sort*} (inl : ∀ x y : C, (f : x ⟶ y) → P ((inl_ C D).map f)) (inr : ∀ x y : D, (f : x ⟶ y) → P ((inr_ C D).map f)) {x y : C ⊕ D} (f : x ⟶ y) : P f := match x, y, f with | .inl x, .inl y, f => inl x y f.down | .inr x, .inr y, f => inr x y f.down @[simp] lemma homInduction_left {P : {x y : C ⊕ D} → (x ⟶ y) → Sort*} (inl : ∀ x y : C, (f : x ⟶ y) → P ((inl_ C D).map f)) (inr : ∀ x y : D, (f : x ⟶ y) → P ((inr_ C D).map f)) {x y : C} (f : x ⟶ y) : homInduction inl inr ((inl_ C D).map f) = inl x y f := rfl @[simp] lemma homInduction_right {P : {x y : C ⊕ D} → (x ⟶ y) → Sort*} (inl : ∀ x y : C, (f : x ⟶ y) → P ((inl_ C D).map f)) (inr : ∀ x y : D, (f : x ⟶ y) → P ((inr_ C D).map f)) {x y : D} (f : x ⟶ y) : homInduction inl inr ((inr_ C D).map f) = inr x y f := rfl end Sum namespace Functor variable {A : Type u₁} [Category.{v₁} A] {B : Type u₂} [Category.{v₂} B] {C : Type u₃} [Category.{v₃} C] {D : Type u₄} [Category.{v₄} D] section Sum' variable (F : A ⥤ C) (G : B ⥤ C) /-- The sum of two functors that land in a given category `C`. -/ def sum' : A ⊕ B ⥤ C where obj | inl X => F.obj X | inr X => G.obj X map {X Y} f := Sum.homInduction (inl := fun _ _ f ↦ F.map f) (inr := fun _ _ g ↦ G.map g) f map_comp {x y z} f g := by cases f <;> cases g <;> simp [← Functor.map_comp] map_id x := by cases x <;> (simp only [← map_id]; rfl) /-- The sum `F.sum' G` precomposed with the left inclusion functor is isomorphic to `F` -/ @[simps!] def inlCompSum' : Sum.inl_ A B ⋙ F.sum' G ≅ F := NatIso.ofComponents fun _ => Iso.refl _ /-- The sum `F.sum' G` precomposed with the right inclusion functor is isomorphic to `G` -/ @[simps!] def inrCompSum' : Sum.inr_ A B ⋙ F.sum' G ≅ G := NatIso.ofComponents fun _ => Iso.refl _ @[simp] theorem sum'_obj_inl (a : A) : (F.sum' G).obj (inl a) = (F.obj a) := rfl @[simp] theorem sum'_obj_inr (b : B) : (F.sum' G).obj (inr b) = (G.obj b) := rfl @[simp] theorem sum'_map_inl {a a' : A} (f : a ⟶ a') : (F.sum' G).map ((Sum.inl_ _ _).map f) = F.map f := rfl @[simp] theorem sum'_map_inr {b b' : B} (f : b ⟶ b') : (F.sum' G).map ((Sum.inr_ _ _).map f) = G.map f := rfl end Sum' /-- The sum of two functors. -/ def sum (F : A ⥤ B) (G : C ⥤ D) : A ⊕ C ⥤ B ⊕ D := (F ⋙ Sum.inl_ _ _).sum' (G ⋙ Sum.inr_ _ _) @[simp] theorem sum_obj_inl (F : A ⥤ B) (G : C ⥤ D) (a : A) : (F.sum G).obj (inl a) = inl (F.obj a) := rfl @[simp] theorem sum_obj_inr (F : A ⥤ B) (G : C ⥤ D) (c : C) : (F.sum G).obj (inr c) = inr (G.obj c) := rfl @[simp] theorem sum_map_inl (F : A ⥤ B) (G : C ⥤ D) {a a' : A} (f : a ⟶ a') : (F.sum G).map ((Sum.inl_ _ _).map f) = (Sum.inl_ _ _).map (F.map f) := by simp [sum] @[simp] theorem sum_map_inr (F : A ⥤ B) (G : C ⥤ D) {c c' : C} (f : c ⟶ c') : (F.sum G).map ((Sum.inr_ _ _).map f) = (Sum.inr_ _ _).map (G.map f) := by simp [sum] section variable {F G : A ⊕ B ⥤ C} (e₁ : Sum.inl_ A B ⋙ F ≅ Sum.inl_ A B ⋙ G) (e₂ : Sum.inr_ A B ⋙ F ≅ Sum.inr_ A B ⋙ G) /-- A functor out of a sum is uniquely characterized by its precompositions with `inl_` and `inr_`. -/ def sumIsoExt : F ≅ G := NatIso.ofComponents (fun x ↦ match x with | inl x => e₁.app x | inr x => e₂.app x) (fun {x y} f ↦ by cases f · simpa using e₁.hom.naturality _ · simpa using e₂.hom.naturality _) @[simp] lemma sumIsoExt_hom_app_inl (a : A) : (sumIsoExt e₁ e₂).hom.app (inl a) = e₁.hom.app a := rfl @[simp] lemma sumIsoExt_hom_app_inr (b : B) : (sumIsoExt e₁ e₂).hom.app (inr b) = e₂.hom.app b := rfl @[simp] lemma sumIsoExt_inv_app_inl (a : A) : (sumIsoExt e₁ e₂).inv.app (inl a) = e₁.inv.app a := rfl @[simp] lemma sumIsoExt_inv_app_inr (b : B) : (sumIsoExt e₁ e₂).inv.app (inr b) = e₂.inv.app b := rfl end section variable (F : A ⊕ B ⥤ C) /-- Any functor out of a sum is the sum of its precomposition with the inclusions. -/ def isoSum : F ≅ (Sum.inl_ A B ⋙ F).sum' (Sum.inr_ A B ⋙ F) := sumIsoExt (inlCompSum' _ _).symm (inrCompSum' _ _).symm variable (a : A) (b : B) @[simp] lemma isoSum_hom_app_inl : (isoSum F).hom.app (inl a) = 𝟙 (F.obj (inl a)) := rfl @[simp] lemma isoSum_hom_app_inr : (isoSum F).hom.app (inr b) = 𝟙 (F.obj (inr b)) := rfl @[simp] lemma isoSum_inv_app_inl : (isoSum F).inv.app (inl a) = 𝟙 (F.obj (inl a)) := rfl @[simp] lemma isoSum_inv_app_inr : (isoSum F).inv.app (inr b) = 𝟙 (F.obj (inr b)) := rfl end end Functor namespace NatTrans variable {A : Type u₁} [Category.{v₁} A] {B : Type u₂} [Category.{v₂} B] {C : Type u₃} [Category.{v₃} C] {D : Type u₄} [Category.{v₄} D] /-- The sum of two natural transformations, where all functors have the same target category. -/ def sum' {F G : A ⥤ C} {H I : B ⥤ C} (α : F ⟶ G) (β : H ⟶ I) : F.sum' H ⟶ G.sum' I where app X := match X with | inl X => α.app X | inr X => β.app X naturality X Y f := by cases f <;> simp @[simp] theorem sum'_app_inl {F G : A ⥤ C} {H I : B ⥤ C} (α : F ⟶ G) (β : H ⟶ I) (a : A) : (sum' α β).app (inl a) = α.app a := rfl @[simp] theorem sum'_app_inr {F G : A ⥤ C} {H I : B ⥤ C} (α : F ⟶ G) (β : H ⟶ I) (b : B) : (sum' α β).app (inr b) = β.app b := rfl /-- The sum of two natural transformations. -/ def sum {F G : A ⥤ B} {H I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) : F.sum H ⟶ G.sum I where app X := match X with | inl X => (Sum.inl_ B D).map (α.app X) | inr X => (Sum.inr_ B D).map (β.app X) naturality X Y f := by cases f <;> simp [← Functor.map_comp] @[simp] theorem sum_app_inl {F G : A ⥤ B} {H I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) (a : A) : (sum α β).app (inl a) = (Sum.inl_ _ _).map (α.app a) := rfl @[simp] theorem sum_app_inr {F G : A ⥤ B} {H I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) (c : C) : (sum α β).app (inr c) = (Sum.inr_ _ _).map (β.app c) := rfl end NatTrans namespace Sum variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D] /-- The functor exchanging two direct summand categories. -/ def swap : C ⊕ D ⥤ D ⊕ C := (inr_ D C).sum' (inl_ D C) @[simp] theorem swap_obj_inl (X : C) : (swap C D).obj (inl X) = inr X := rfl @[simp] theorem swap_obj_inr (X : D) : (swap C D).obj (inr X) = inl X := rfl @[simp] theorem swap_map_inl {X Y : C} {f : inl X ⟶ inl Y} : (swap C D).map f = f := rfl @[simp] theorem swap_map_inr {X Y : D} {f : inr X ⟶ inr Y} : (swap C D).map f = f := rfl /-- Precomposing `swap` with the left inclusion gives the right inclusion. -/ @[simps! hom_app inv_app] def swapCompInl : inl_ C D ⋙ swap C D ≅ inr_ D C := Functor.inlCompSum' (inr_ _ _) (inl_ _ _) /-- Precomposing `swap` with the right inclusion gives the left inclusion. -/ @[simps! hom_app inv_app] def swapCompInr : inr_ C D ⋙ swap C D ≅ inl_ D C := Functor.inrCompSum' (inr_ _ _) (inl_ _ _) namespace Swap /-- `swap` gives an equivalence between `C ⊕ D` and `D ⊕ C`. -/ @[simps functor inverse] def equivalence : C ⊕ D ≌ D ⊕ C where functor := swap C D inverse := swap D C unitIso := Functor.sumIsoExt (calc inl_ C D ⋙ 𝟭 (C ⊕ D) ≅ inl_ C D := rightUnitor _ _ ≅ inr_ D C ⋙ swap D C := (swapCompInr D C).symm _ ≅ (inl_ C D ⋙ swap C D) ⋙ swap D C := isoWhiskerRight (swapCompInl C D).symm _ _ ≅ inl_ C D ⋙ swap C D ⋙ swap D C := associator _ _ _) (calc inr_ C D ⋙ 𝟭 (C ⊕ D) ≅ inr_ C D := rightUnitor _ _ ≅ inl_ D C ⋙ swap D C := (swapCompInl D C).symm _ ≅ (inr_ C D ⋙ swap C D) ⋙ swap D C := isoWhiskerRight (swapCompInr C D).symm _ _ ≅ inr_ C D ⋙ swap C D ⋙ swap D C := associator _ _ _) counitIso := Functor.sumIsoExt (calc inl_ D C ⋙ swap D C ⋙ swap C D ≅ (inl_ D C ⋙ swap D C) ⋙ swap C D := (associator _ _ _).symm _ ≅ inr_ C D ⋙ swap C D := isoWhiskerRight (swapCompInl D C) _ _ ≅ inl_ D C := swapCompInr C D _ ≅ inl_ D C ⋙ 𝟭 (D ⊕ C) := (rightUnitor _).symm) (calc inr_ D C ⋙ swap D C ⋙ swap C D ≅ (inr_ D C ⋙ swap D C) ⋙ swap C D := (associator _ _ _).symm _ ≅ inl_ C D ⋙ swap C D := isoWhiskerRight (swapCompInr D C) _ _ ≅ inr_ D C := swapCompInl C D _ ≅ inr_ D C ⋙ 𝟭 (D ⊕ C) := (rightUnitor _).symm) instance isEquivalence : (swap C D).IsEquivalence := (by infer_instance : (equivalence C D).functor.IsEquivalence) /-- The double swap on `C ⊕ D` is naturally isomorphic to the identity functor. -/ def symmetry : swap C D ⋙ swap D C ≅ 𝟭 (C ⊕ D) := (equivalence C D).unitIso.symm end Swap end Sum end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Sums/Associator.lean
import Mathlib.CategoryTheory.Sums.Basic /-! # Associator for binary disjoint union of categories. The associator functor `((C ⊕ D) ⊕ E) ⥤ (C ⊕ (D ⊕ E))` and its inverse form an equivalence. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory open Sum Functor namespace CategoryTheory.sum variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D] (E : Type u₃) [Category.{v₃} E] /-- The associator functor `(C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E)` for sums of categories. -/ def associator : (C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E) := (inl_ C (D ⊕ E) |>.sum' <| inl_ D E ⋙ inr_ C (D ⊕ E)).sum' <| inr_ D E ⋙ inr_ C (D ⊕ E) @[simp] theorem associator_obj_inl_inl (X) : (associator C D E).obj (inl (inl X)) = inl X := rfl @[simp] theorem associator_obj_inl_inr (X) : (associator C D E).obj (inl (inr X)) = inr (inl X) := rfl @[simp] theorem associator_obj_inr (X) : (associator C D E).obj (inr X) = inr (inr X) := rfl @[simp] theorem associator_map_inl_inl {X Y : C} (f : X ⟶ Y) : (associator C D E).map ((inl_ _ _).map ((inl_ _ _).map f)) = (inl_ _ _).map f := rfl @[simp] theorem associator_map_inl_inr {X Y : D} (f : X ⟶ Y) : (associator C D E).map ((inl_ _ _).map ((inr_ _ _).map f)) = (inr_ _ _).map ((inl_ _ _).map f) := by simp [associator] @[simp] theorem associator_map_inr {X Y : E} (f : X ⟶ Y) : (associator C D E).map ((inr_ _ _).map f) = (inr_ _ _).map ((inr_ _ _).map f) := by simp [associator] /-- Characterizing the composition of the associator and the left inclusion. -/ @[simps!] def inlCompAssociator : inl_ (C ⊕ D) E ⋙ associator C D E ≅ inl_ C (D ⊕ E) |>.sum' <| inl_ D E ⋙ inr_ C (D ⊕ E) := (Functor.inlCompSum' _ _) /-- Characterizing the composition of the associator and the right inclusion. -/ @[simps!] def inrCompAssociator : inr_ (C ⊕ D) E ⋙ associator C D E ≅ inr_ D E ⋙ inr_ C (D ⊕ E) := (Functor.inrCompSum' _ _) /-- Further characterizing the composition of the associator and the left inclusion. -/ @[simps!] def inlCompInlCompAssociator : inl_ C D ⋙ inl_ (C ⊕ D) E ⋙ associator C D E ≅ inl_ C (D ⊕ E) := isoWhiskerLeft (inl_ _ _) (inlCompAssociator C D E) ≪≫ Functor.inlCompSum' _ _ /-- Further characterizing the composition of the associator and the left inclusion. -/ @[simps!] def inrCompInlCompAssociator : inr_ C D ⋙ inl_ (C ⊕ D) E ⋙ associator C D E ≅ inl_ D E ⋙ inr_ C (D ⊕ E) := isoWhiskerLeft (inr_ _ _) (inlCompAssociator C D E) ≪≫ Functor.inrCompSum' _ _ /-- The inverse associator functor `C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E` for sums of categories. -/ def inverseAssociator : C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E := inl_ C D ⋙ inl_ (C ⊕ D) E |>.sum' <| (inr_ C D ⋙ inl_ (C ⊕ D) E).sum' <| inr_ (C ⊕ D) E @[simp] theorem inverseAssociator_obj_inl (X) : (inverseAssociator C D E).obj (inl X) = inl (inl X) := rfl @[simp] theorem inverseAssociator_obj_inr_inl (X) : (inverseAssociator C D E).obj (inr (inl X)) = inl (inr X) := rfl @[simp] theorem inverseAssociator_obj_inr_inr (X) : (inverseAssociator C D E).obj (inr (inr X)) = inr X := rfl @[simp] theorem inverseAssociator_map_inl {X Y : C} (f : X ⟶ Y) : (inverseAssociator C D E).map ((inl_ _ _).map f) = (inl_ _ _).map ((inl_ _ _).map f) := by simp [inverseAssociator] @[simp] theorem inverseAssociator_map_inr_inl {X Y : D} (f : X ⟶ Y) : (inverseAssociator C D E).map ((inr_ _ _).map ((inl_ _ _).map f)) = (inl_ _ _).map ((inr_ _ _).map f) := by simp [inverseAssociator] @[simp] theorem inverseAssociator_map_inr_inr {X Y : E} (f : X ⟶ Y) : (inverseAssociator C D E).map ((inr_ _ _).map ((inr_ _ _).map f)) = (inr_ _ _).map f := rfl /-- Characterizing the composition of the inverse of the associator and the left inclusion. -/ @[simps!] def inlCompInverseAssociator : inl_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ inl_ C D ⋙ inl_ (C ⊕ D) E := Functor.inlCompSum' _ _ /-- Characterizing the composition of the inverse of the associator and the right inclusion. -/ @[simps!] def inrCompInverseAssociator : inr_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ (inr_ C D ⋙ inl_ (C ⊕ D) E).sum' <| inr_ (C ⊕ D) E := Functor.inrCompSum' _ _ /-- Further characterizing the composition of the inverse of the associator and the right inclusion. -/ @[simps!] def inlCompInrCompInverseAssociator : inl_ D E ⋙ inr_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ inr_ C D ⋙ inl_ (C ⊕ D) E := isoWhiskerLeft (inl_ _ _) (inrCompInverseAssociator C D E) ≪≫ Functor.inlCompSum' _ _ /-- Further characterizing the composition of the inverse of the associator and the right inclusion. -/ @[simps!] def inrCompInrCompInverseAssociator : inr_ D E ⋙ inr_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ inr_ (C ⊕ D) E := isoWhiskerLeft (inr_ _ _) (inrCompInverseAssociator C D E) ≪≫ Functor.inrCompSum' _ _ /-- The equivalence of categories expressing associativity of sums of categories. -/ @[simps functor inverse] def associativity : (C ⊕ D) ⊕ E ≌ C ⊕ (D ⊕ E) where functor := associator C D E inverse := inverseAssociator C D E unitIso := Functor.sumIsoExt (Functor.sumIsoExt ((Functor.associator _ _ _).symm ≪≫ Functor.rightUnitor _ ≪≫ (isoWhiskerRight (inlCompInlCompAssociator C D E) (inverseAssociator C D E) ≪≫ inlCompInverseAssociator C D E).symm ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Functor.associator _ _ _)) ((Functor.associator _ _ _).symm ≪≫ Functor.rightUnitor _ ≪≫ (isoWhiskerRight (inrCompInlCompAssociator C D E) (inverseAssociator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inlCompInrCompInverseAssociator C D E).symm ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Functor.associator _ _ _))) (Functor.rightUnitor _ ≪≫ (isoWhiskerRight (inrCompAssociator C D E) (inverseAssociator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inrCompInrCompInverseAssociator C D E).symm ≪≫ Functor.associator _ _ _) counitIso := Functor.sumIsoExt ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (inlCompInverseAssociator C D E) (associator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inlCompInlCompAssociator C D E ≪≫ (Functor.rightUnitor _).symm) (Functor.sumIsoExt ((Functor.associator _ _ _).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (Functor.associator _ _ _ ≪≫ inlCompInrCompInverseAssociator C D E) (associator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inrCompInlCompAssociator C D E ≪≫ (Functor.rightUnitor _).symm ≪≫ Functor.associator _ _ _) ((Functor.associator _ _ _).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (Functor.associator _ _ _ ≪≫ inrCompInrCompInverseAssociator C D E) (associator C D E) ≪≫ inrCompAssociator C D E ≪≫ isoWhiskerLeft _ (Functor.rightUnitor _).symm)) functor_unitIso_comp x := match x with | inl (inl c) => by simp [inlCompInlCompAssociator, inlCompInverseAssociator] | inl (inr d) => by simp [inrCompInlCompAssociator, inlCompInrCompInverseAssociator] | inr e => by simp [inrCompAssociator, inrCompInrCompInverseAssociator] instance associatorIsEquivalence : (associator C D E).IsEquivalence := (by infer_instance : (associativity C D E).functor.IsEquivalence) instance inverseAssociatorIsEquivalence : (inverseAssociator C D E).IsEquivalence := (by infer_instance : (associativity C D E).inverse.IsEquivalence) -- TODO unitors? -- TODO pentagon natural transformation? ...satisfying? end CategoryTheory.sum
.lake/packages/mathlib/Mathlib/CategoryTheory/Dialectica/Monoidal.lean
import Mathlib.CategoryTheory.Subobject.Lattice import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Dialectica.Basic /-! # The Dialectica category is symmetric monoidal We show that the category `Dial` has a symmetric monoidal category structure. -/ noncomputable section namespace CategoryTheory open MonoidalCategory Limits universe v u variable {C : Type u} [Category.{v} C] [HasFiniteProducts C] [HasPullbacks C] namespace Dial local notation "π₁" => prod.fst local notation "π₂" => prod.snd local notation "π(" a ", " b ")" => prod.lift a b /-- The object `X ⊗ Y` in the `Dial C` category just tuples the left and right components. -/ @[simps] def tensorObjImpl (X Y : Dial C) : Dial C where src := X.src ⨯ Y.src tgt := X.tgt ⨯ Y.tgt rel := (Subobject.pullback (prod.map π₁ π₁)).obj X.rel ⊓ (Subobject.pullback (prod.map π₂ π₂)).obj Y.rel /-- The functorial action of `X ⊗ Y` in `Dial C`. -/ @[simps] def tensorHomImpl {X₁ X₂ Y₁ Y₂ : Dial C} (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) : tensorObjImpl X₁ Y₁ ⟶ tensorObjImpl X₂ Y₂ where f := prod.map f.f g.f F := π(prod.map π₁ π₁ ≫ f.F, prod.map π₂ π₂ ≫ g.F) le := by simp only [tensorObjImpl, Subobject.inf_pullback] apply inf_le_inf <;> rw [← Subobject.pullback_comp, ← Subobject.pullback_comp] · have := (Subobject.pullback (prod.map π₁ π₁ : (X₁.src ⨯ Y₁.src) ⨯ X₂.tgt ⨯ Y₂.tgt ⟶ _)).monotone (Hom.le f) rw [← Subobject.pullback_comp, ← Subobject.pullback_comp] at this convert this using 3 <;> simp · have := (Subobject.pullback (prod.map π₂ π₂ : (X₁.src ⨯ Y₁.src) ⨯ X₂.tgt ⨯ Y₂.tgt ⟶ _)).monotone (Hom.le g) rw [← Subobject.pullback_comp, ← Subobject.pullback_comp] at this convert this using 3 <;> simp /-- The unit for the tensor `X ⊗ Y` in `Dial C`. -/ @[simps] def tensorUnitImpl : Dial C := { src := ⊤_ _, tgt := ⊤_ _, rel := ⊤ } /-- Left unit cancellation `1 ⊗ X ≅ X` in `Dial C`. -/ @[simps!] def leftUnitorImpl (X : Dial C) : tensorObjImpl tensorUnitImpl X ≅ X := isoMk (Limits.prod.leftUnitor _) (Limits.prod.leftUnitor _) <| by simp [Subobject.pullback_top] /-- Right unit cancellation `X ⊗ 1 ≅ X` in `Dial C`. -/ @[simps!] def rightUnitorImpl (X : Dial C) : tensorObjImpl X tensorUnitImpl ≅ X := isoMk (Limits.prod.rightUnitor _) (Limits.prod.rightUnitor _) <| by simp [Subobject.pullback_top] /-- The associator for tensor, `(X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)` in `Dial C`. -/ @[simps!] def associatorImpl (X Y Z : Dial C) : tensorObjImpl (tensorObjImpl X Y) Z ≅ tensorObjImpl X (tensorObjImpl Y Z) := isoMk (prod.associator ..) (prod.associator ..) <| by simp [Subobject.inf_pullback, ← Subobject.pullback_comp, inf_assoc] @[simps!] instance : MonoidalCategoryStruct (Dial C) where tensorUnit := tensorUnitImpl tensorObj := tensorObjImpl whiskerLeft X _ _ f := tensorHomImpl (𝟙 X) f whiskerRight f Y := tensorHomImpl f (𝟙 Y) tensorHom := tensorHomImpl leftUnitor := leftUnitorImpl rightUnitor := rightUnitorImpl associator := associatorImpl theorem id_tensorHom_id (X₁ X₂ : Dial C) : (𝟙 X₁ ⊗ₘ 𝟙 X₂ : _ ⟶ _) = 𝟙 (X₁ ⊗ X₂ : Dial C) := by cat_disch @[deprecated (since := "2025-07-14")] alias tensor_id := id_tensorHom_id theorem tensorHom_comp_tensorHom {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Dial C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂) : (f₁ ⊗ₘ f₂) ≫ (g₁ ⊗ₘ g₂) = (f₁ ≫ g₁) ⊗ₘ (f₂ ≫ g₂) := by ext <;> simp; ext <;> simp <;> (rw [← Category.assoc]; congr 1; simp) theorem associator_naturality {X₁ X₂ X₃ Y₁ Y₂ Y₃ : Dial C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) : tensorHom (tensorHom f₁ f₂) f₃ ≫ (associator Y₁ Y₂ Y₃).hom = (associator X₁ X₂ X₃).hom ≫ tensorHom f₁ (tensorHom f₂ f₃) := by cat_disch theorem leftUnitor_naturality {X Y : Dial C} (f : X ⟶ Y) : (𝟙 (𝟙_ (Dial C)) ⊗ₘ f) ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by ext <;> simp; ext; simp; congr 1; ext <;> simp theorem rightUnitor_naturality {X Y : Dial C} (f : X ⟶ Y) : (f ⊗ₘ 𝟙 (𝟙_ (Dial C))) ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by ext <;> simp; ext; simp; congr 1; ext <;> simp theorem pentagon (W X Y Z : Dial C) : (tensorHom (associator W X Y).hom (𝟙 Z)) ≫ (associator W (tensorObj X Y) Z).hom ≫ (tensorHom (𝟙 W) (associator X Y Z).hom) = (associator (tensorObj W X) Y Z).hom ≫ (associator W X (tensorObj Y Z)).hom := by ext <;> simp theorem triangle (X Y : Dial C) : (associator X (𝟙_ (Dial C)) Y).hom ≫ tensorHom (𝟙 X) (leftUnitor Y).hom = tensorHom (rightUnitor X).hom (𝟙 Y) := by cat_disch instance : MonoidalCategory (Dial C) := .ofTensorHom (id_tensorHom_id := id_tensorHom_id) (tensorHom_comp_tensorHom := tensorHom_comp_tensorHom) (associator_naturality := associator_naturality) (leftUnitor_naturality := leftUnitor_naturality) (rightUnitor_naturality := rightUnitor_naturality) (pentagon := pentagon) (triangle := triangle) /-- The braiding isomorphism `X ⊗ Y ≅ Y ⊗ X` in `Dial C`. -/ @[simps!] def braiding (X Y : Dial C) : tensorObj X Y ≅ tensorObj Y X := isoMk (prod.braiding ..) (prod.braiding ..) <| by simp [Subobject.inf_pullback, ← Subobject.pullback_comp, inf_comm] theorem symmetry (X Y : Dial C) : (braiding X Y).hom ≫ (braiding Y X).hom = 𝟙 (tensorObj X Y) := by cat_disch theorem braiding_naturality_right (X : Dial C) {Y Z : Dial C} (f : Y ⟶ Z) : tensorHom (𝟙 X) f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ tensorHom f (𝟙 X) := by cat_disch theorem braiding_naturality_left {X Y : Dial C} (f : X ⟶ Y) (Z : Dial C) : tensorHom f (𝟙 Z) ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ tensorHom (𝟙 Z) f := by cat_disch theorem hexagon_forward (X Y Z : Dial C) : (associator X Y Z).hom ≫ (braiding X (Y ⊗ Z)).hom ≫ (associator Y Z X).hom = tensorHom (braiding X Y).hom (𝟙 Z) ≫ (associator Y X Z).hom ≫ tensorHom (𝟙 Y) (braiding X Z).hom := by cat_disch theorem hexagon_reverse (X Y Z : Dial C) : (associator X Y Z).inv ≫ (braiding (X ⊗ Y) Z).hom ≫ (associator Z X Y).inv = tensorHom (𝟙 X) (braiding Y Z).hom ≫ (associator X Z Y).inv ≫ tensorHom (braiding X Z).hom (𝟙 Y) := by cat_disch instance : SymmetricCategory (Dial C) where braiding := braiding braiding_naturality_right := braiding_naturality_right braiding_naturality_left := braiding_naturality_left hexagon_forward := hexagon_forward hexagon_reverse := hexagon_reverse symmetry := symmetry end Dial end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Dialectica/Basic.lean
import Mathlib.CategoryTheory.Subobject.Basic import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Dialectica category We define the category `Dial` of the Dialectica interpretation, after [dialectica1989]. ## Background Dialectica categories are important models of linear type theory. They satisfy most of the distinctions that linear logic was meant to introduce and many models do not satisfy, like the independence of constants. Many linear type theories are being used at the moment--[nLab] describes some of them: for quantum systems, for effects in programming, for linear dependent types. In particular, dialectica categories are connected to polynomial functors, being a slightly more sophisticated version of polynomial types, as discussed, for instance, in Moss and von Glehn's [*Dialectica models of type theory*]. As such they are related to the polynomial constructions being [developed][Poly] by Awodey, Riehl, and Hazratpour. For the non-dependent version developed here several applications are known to Petri Nets, small cardinals in Set Theory, state in imperative programming, and others, see [Dialectica Categories]. ## References * [Valeria de Paiva, The Dialectica Categories.][dialectica1989] ([pdf](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-213.pdf)) [nLab]: https://ncatlab.org/nlab/show/linear+type+theory [*Dialectica models of type theory*]: https://arxiv.org/abs/2105.00283 [Poly]: https://github.com/sinhp/Poly [Dialectica Categories]: https://github.com/vcvpaiva/DialecticaCategories -/ noncomputable section namespace CategoryTheory open Limits universe v u variable {C : Type u} [Category.{v} C] [HasFiniteProducts C] [HasPullbacks C] variable (C) in /-- The Dialectica category. An object of the category is a triple `⟨U, X, α ⊆ U × X⟩`, and a morphism from `⟨U, X, α⟩` to `⟨V, Y, β⟩` is a pair `(f : U ⟶ V, F : U ⨯ Y ⟶ X)` such that `{(u,y) | α(u, F(u, y))} ⊆ {(u,y) | β(f(u), y)}`. The subset `α` is actually encoded as an element of `Subobject (U × X)`, and the above inequality is expressed using pullbacks. -/ structure Dial where /-- The source object -/ src : C /-- The target object -/ tgt : C /-- A subobject of `src ⨯ tgt`, interpreted as a relation -/ rel : Subobject (src ⨯ tgt) namespace Dial local notation "π₁" => prod.fst local notation "π₂" => prod.snd local notation "π(" a ", " b ")" => prod.lift a b /-- A morphism in the `Dial C` category from `⟨U, X, α⟩` to `⟨V, Y, β⟩` is a pair `(f : U ⟶ V, F : U ⨯ Y ⟶ X)` such that `{(u,y) | α(u, F(u, y))} ≤ {(u,y) | β(f(u), y)}`. -/ @[ext] structure Hom (X Y : Dial C) where /-- Maps the sources -/ f : X.src ⟶ Y.src /-- Maps the targets (contravariantly) -/ F : X.src ⨯ Y.tgt ⟶ X.tgt /-- This says `{(u, y) | α(u, F(u, y))} ⊆ {(u, y) | β(f(u), y)}` using subobject pullbacks -/ le : (Subobject.pullback π(π₁, F)).obj X.rel ≤ (Subobject.pullback (prod.map f (𝟙 _))).obj Y.rel theorem comp_le_lemma {X Y Z : Dial C} (F : Dial.Hom X Y) (G : Dial.Hom Y Z) : (Subobject.pullback π(π₁, π(π₁, prod.map F.f (𝟙 _) ≫ G.F) ≫ F.F)).obj X.rel ≤ (Subobject.pullback (prod.map (F.f ≫ G.f) (𝟙 Z.tgt))).obj Z.rel := by refine le_trans ?_ <| ((Subobject.pullback (π(π₁, prod.map F.f (𝟙 _) ≫ G.F))).monotone F.le).trans <| le_trans ?_ <| ((Subobject.pullback (prod.map F.f (𝟙 Z.tgt))).monotone G.le).trans ?_ <;> simp [← Subobject.pullback_comp] @[simps] instance : Category (Dial C) where Hom := Dial.Hom id X := { f := 𝟙 _ F := π₂ le := by simp } comp {_ _ _} (F G : Dial.Hom ..) := { f := F.f ≫ G.f F := π(π₁, prod.map F.f (𝟙 _) ≫ G.F) ≫ F.F le := comp_le_lemma F G } assoc f g h := by simp only [Category.assoc, Hom.mk.injEq, true_and] rw [← Category.assoc, ← Category.assoc]; congr 1 ext <;> simp @[ext] theorem hom_ext {X Y : Dial C} {x y : X ⟶ Y} (hf : x.f = y.f) (hF : x.F = y.F) : x = y := Hom.ext hf hF /-- An isomorphism in `Dial C` can be induced by isomorphisms on the source and target, which respect the respective relations on `X` and `Y`. -/ @[simps] def isoMk {X Y : Dial C} (e₁ : X.src ≅ Y.src) (e₂ : X.tgt ≅ Y.tgt) (eq : X.rel = (Subobject.pullback (prod.map e₁.hom e₂.hom)).obj Y.rel) : X ≅ Y where hom := { f := e₁.hom F := π₂ ≫ e₂.inv le := by rw [eq, ← Subobject.pullback_comp]; apply le_of_eq; congr; ext <;> simp } inv := { f := e₁.inv F := π₂ ≫ e₂.hom le := by rw [eq, ← Subobject.pullback_comp]; apply le_of_eq; congr; ext <;> simp } end Dial end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Full.lean
import Mathlib.CategoryTheory.Galois.Action /-! # Fiber functors are (faithfully) full Any (fiber) functor `F : C ⥤ FintypeCat` factors via the forgetful functor from finite `Aut F`-sets to finite sets. The induced functor `H : C ⥤ Action FintypeCat (Aut F)` is faithfully full. The faithfulness follows easily from the faithfulness of `F`. In this file we show that `H` is also full. ## Main results - `PreGaloisCategory.exists_lift_of_mono`: If `Y` is a sub-`Aut F`-set of `F.obj X`, there exists a sub-object `Z` of `X` such that `F.obj Z ≅ Y` as `Aut F`-sets. - `PreGaloisCategory.functorToAction_full`: The induced functor `H` from above is full. The main input for this is that the induced functor `H : C ⥤ Action FintypeCat (Aut F)` preserves connectedness, which translates to the fact that `Aut F` acts transitively on the fibers of connected objects. -/ universe u namespace CategoryTheory namespace PreGaloisCategory open Limits Functor variable {C : Type*} [Category C] (F : C ⥤ FintypeCat.{u}) [GaloisCategory C] [FiberFunctor F] /-- Let `X` be an object of a Galois category with fiber functor `F` and `Y` a sub-`Aut F`-set of `F.obj X`, on which `Aut F` acts transitively (i.e. which is connected in the Galois category of finite `Aut F`-sets). Then there exists a connected sub-object `Z` of `X` and an isomorphism `Y ≅ F.obj X` as `Aut F`-sets such that the obvious triangle commutes. For a version without the connectedness assumption, see `exists_lift_of_mono`. -/ lemma exists_lift_of_mono_of_isConnected (X : C) (Y : Action FintypeCat.{u} (Aut F)) (i : Y ⟶ (functorToAction F).obj X) [Mono i] [IsConnected Y] : ∃ (Z : C) (f : Z ⟶ X) (u : Y ≅ (functorToAction F).obj Z), IsConnected Z ∧ Mono f ∧ i = u.hom ≫ (functorToAction F).map f := by obtain ⟨y⟩ := nonempty_fiber_of_isConnected (forget₂ _ FintypeCat) Y obtain ⟨Z, f, z, hz, hc, hm⟩ := fiber_in_connected_component F X (i.hom y) have : IsConnected ((functorToAction F).obj Z) := PreservesIsConnected.preserves obtain ⟨u, hu⟩ := connected_component_unique (forget₂ (Action FintypeCat (Aut F)) FintypeCat) (B := (functorToAction F).obj Z) y z i ((functorToAction F).map f) hz.symm refine ⟨Z, f, u, hc, hm, ?_⟩ apply evaluation_injective_of_isConnected (forget₂ (Action FintypeCat (Aut F)) FintypeCat) Y ((functorToAction F).obj X) y suffices h : i.hom y = F.map f z by simpa [hu] exact hz.symm /-- Let `X` be an object of a Galois category with fiber functor `F` and `Y` a sub-`Aut F`-set of `F.obj X`. Then there exists a sub-object `Z` of `X` and an isomorphism `Y ≅ F.obj X` as `Aut F`-sets such that the obvious triangle commutes. -/ lemma exists_lift_of_mono (X : C) (Y : Action FintypeCat.{u} (Aut F)) (i : Y ⟶ (functorToAction F).obj X) [Mono i] : ∃ (Z : C) (f : Z ⟶ X) (u : Y ≅ (functorToAction F).obj Z), Mono f ∧ u.hom ≫ (functorToAction F).map f = i := by obtain ⟨ι, hf, f, t, hc⟩ := has_decomp_connected_components' Y let i' (j : ι) : f j ⟶ (functorToAction F).obj X := Sigma.ι f j ≫ t.hom ≫ i choose gZ gf gu _ _ h using fun i ↦ exists_lift_of_mono_of_isConnected F X (f i) (i' i) let is2 : (functorToAction F).obj (∐ gZ) ≅ ∐ fun i => (functorToAction F).obj (gZ i) := PreservesCoproduct.iso (functorToAction F) gZ let u' : ∐ f ≅ ∐ fun i => (functorToAction F).obj (gZ i) := Sigma.mapIso gu have heq : (functorToAction F).map (Sigma.desc gf) = (t.symm ≪≫ u' ≪≫ is2.symm).inv ≫ i := by simp only [Iso.trans_inv, Iso.symm_inv, Category.assoc] rw [← Iso.inv_comp_eq] refine Sigma.hom_ext _ _ (fun j ↦ ?_) suffices (functorToAction F).map (gf j) = (gu j).inv ≫ i' j by simpa [is2, u'] simp only [h, Iso.inv_hom_id_assoc] refine ⟨∐ gZ, Sigma.desc gf, t.symm ≪≫ u' ≪≫ is2.symm, ?_, by simp [heq]⟩ · exact mono_of_mono_map (functorToAction F) (heq ▸ mono_comp _ _) /-- The by a fiber functor `F : C ⥤ FintypeCat` induced functor `functorToAction F` to finite `Aut F`-sets is full. -/ instance functorToAction_full : Functor.Full (functorToAction F) where map_surjective {X Y} f := by let u : (functorToAction F).obj X ⟶ (functorToAction F).obj X ⨯ (functorToAction F).obj Y := prod.lift (𝟙 _) f let i : (functorToAction F).obj X ⟶ (functorToAction F).obj (X ⨯ Y) := u ≫ (PreservesLimitPair.iso (functorToAction F) X Y).inv have : Mono i := by have : Mono (u ≫ prod.fst) := prod.lift_fst (𝟙 _) f ▸ inferInstance have : Mono u := mono_of_mono u prod.fst apply mono_comp u _ obtain ⟨Z, g, v, _, hvgi⟩ := exists_lift_of_mono F (Limits.prod X Y) ((functorToAction F).obj X) i let ψ : Z ⟶ X := g ≫ prod.fst have hgvi : (functorToAction F).map g = v.inv ≫ i := by simp [← hvgi] have : IsIso ((functorToAction F).map ψ) := by simp only [map_comp, hgvi, Category.assoc, ψ] have : IsIso (i ≫ (functorToAction F).map prod.fst) := by suffices h : IsIso (𝟙 ((functorToAction F).obj X)) by simpa [i, u] infer_instance apply IsIso.comp_isIso have : IsIso ψ := isIso_of_reflects_iso ψ (functorToAction F) use inv ψ ≫ g ≫ prod.snd rw [← cancel_epi ((functorToAction F).map ψ)] ext (z : F.obj Z) simp [-FintypeCat.comp_apply, -Action.comp_hom, i, u, ψ, hgvi] end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Decomposition.lean
import Mathlib.CategoryTheory.Galois.GaloisObjects import Mathlib.CategoryTheory.Limits.Shapes.CombinedProducts import Mathlib.Data.Finite.Sum /-! # Decomposition of objects into connected components and applications We show that in a Galois category every object is the (finite) coproduct of connected subobjects. This has many useful corollaries, in particular that the fiber of every object is represented by a Galois object. ## Main results * `has_decomp_connected_components`: Every object is the sum of its (finitely many) connected components. * `fiber_in_connected_component`: An element of the fiber of `X` lies in the fiber of some connected component. * `connected_component_unique`: Up to isomorphism, for each element `x` in the fiber of `X` there is only one connected component whose fiber contains `x`. * `exists_galois_representative`: The fiber of `X` is represented by some Galois object `A`: Evaluation at some `a` in the fiber of `A` induces a bijection `A ⟶ X` to `F.obj X`. ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ w namespace CategoryTheory open Limits Functor variable {C : Type u₁} [Category.{u₂} C] namespace PreGaloisCategory section Decomposition /-! ### Decomposition in connected components To show that an object `X` of a Galois category admits a decomposition into connected objects, we proceed by induction on the cardinality of the fiber under an arbitrary fiber functor. If `X` is connected, there is nothing to show. If not, we can write `X` as the sum of two non-trivial subobjects which have strictly smaller fiber and conclude by the induction hypothesis. -/ /-- The trivial case if `X` is connected. -/ private lemma has_decomp_connected_components_aux_conn (X : C) [IsConnected X] : ∃ (ι : Type) (f : ι → C) (g : (i : ι) → (f i) ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by refine ⟨Unit, fun _ ↦ X, fun _ ↦ 𝟙 X, mkCofanColimit _ (fun s ↦ s.inj ()), ?_⟩ exact ⟨fun _ ↦ inferInstance, inferInstance⟩ /-- The trivial case if `X` is initial. -/ private lemma has_decomp_connected_components_aux_initial (X : C) (h : IsInitial X) : ∃ (ι : Type) (f : ι → C) (g : (i : ι) → (f i) ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by refine ⟨Empty, fun _ ↦ X, fun _ ↦ 𝟙 X, ?_⟩ use mkCofanColimit _ (fun s ↦ IsInitial.to h s.pt) (fun s ↦ by simp) (fun s m _ ↦ IsInitial.hom_ext h m _) exact ⟨by simp only [IsEmpty.forall_iff], inferInstance⟩ variable [GaloisCategory C] /- Show decomposition by inducting on `Nat.card (F.obj X)`. -/ private lemma has_decomp_connected_components_aux (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] (n : ℕ) : ∀ (X : C), n = Nat.card (F.obj X) → ∃ (ι : Type) (f : ι → C) (g : (i : ι) → (f i) ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by induction n using Nat.strongRecOn with | _ n hi intro X hn by_cases h : IsConnected X · exact has_decomp_connected_components_aux_conn X by_cases nhi : IsInitial X → False · obtain ⟨Y, v, hni, hvmono, hvnoiso⟩ := has_non_trivial_subobject_of_not_isConnected_of_not_initial X h nhi obtain ⟨Z, u, ⟨c⟩⟩ := PreGaloisCategory.monoInducesIsoOnDirectSummand v let t : ColimitCocone (pair Y Z) := { cocone := BinaryCofan.mk v u, isColimit := c } have hn1 : Nat.card (F.obj Y) < n := by rw [hn] exact lt_card_fiber_of_mono_of_notIso F v hvnoiso have i : X ≅ Y ⨿ Z := (colimit.isoColimitCocone t).symm have hnn : Nat.card (F.obj X) = Nat.card (F.obj Y) + Nat.card (F.obj Z) := by rw [card_fiber_eq_of_iso F i] exact card_fiber_coprod_eq_sum F Y Z have hn2 : Nat.card (F.obj Z) < n := by rw [hn, hnn, lt_add_iff_pos_left] exact Nat.pos_of_ne_zero (non_zero_card_fiber_of_not_initial F Y hni) let ⟨ι₁, f₁, g₁, hc₁, hf₁, he₁⟩ := hi (Nat.card (F.obj Y)) hn1 Y rfl let ⟨ι₂, f₂, g₂, hc₂, hf₂, he₂⟩ := hi (Nat.card (F.obj Z)) hn2 Z rfl refine ⟨ι₁ ⊕ ι₂, Sum.elim f₁ f₂, Cofan.combPairHoms (Cofan.mk Y g₁) (Cofan.mk Z g₂) (BinaryCofan.mk v u), ?_⟩ use Cofan.combPairIsColimit hc₁ hc₂ c refine ⟨fun i ↦ ?_, inferInstance⟩ cases i · exact hf₁ _ · exact hf₂ _ · simp only [not_forall, not_false_eq_true] at nhi obtain ⟨hi⟩ := nhi exact has_decomp_connected_components_aux_initial X hi /-- In a Galois category, every object is the sum of connected objects. -/ theorem has_decomp_connected_components (X : C) : ∃ (ι : Type) (f : ι → C) (g : (i : ι) → f i ⟶ X) (_ : IsColimit (Cofan.mk X g)), (∀ i, IsConnected (f i)) ∧ Finite ι := by let F := GaloisCategory.getFiberFunctor C exact has_decomp_connected_components_aux F (Nat.card <| F.obj X) X rfl /-- In a Galois category, every object is the sum of connected objects. -/ theorem has_decomp_connected_components' (X : C) : ∃ (ι : Type) (_ : Finite ι) (f : ι → C) (_ : ∐ f ≅ X), ∀ i, IsConnected (f i) := by obtain ⟨ι, f, g, hl, hc, hf⟩ := has_decomp_connected_components X exact ⟨ι, hf, f, colimit.isoColimitCocone ⟨Cofan.mk X g, hl⟩, hc⟩ variable (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] /-- Every element in the fiber of `X` lies in some connected component of `X`. -/ lemma fiber_in_connected_component (X : C) (x : F.obj X) : ∃ (Y : C) (i : Y ⟶ X) (y : F.obj Y), F.map i y = x ∧ IsConnected Y ∧ Mono i := by obtain ⟨ι, f, g, hl, hc, he⟩ := has_decomp_connected_components X let s : Cocone (Discrete.functor f ⋙ F) := F.mapCocone (Cofan.mk X g) let s' : IsColimit s := isColimitOfPreserves F hl obtain ⟨⟨j⟩, z, h⟩ := Concrete.isColimit_exists_rep _ s' x refine ⟨f j, g j, z, ⟨?_, hc j, MonoCoprod.mono_inj _ (Cofan.mk X g) hl j⟩⟩ subst h rfl /-- Up to isomorphism an element of the fiber of `X` only lies in one connected component. -/ lemma connected_component_unique {X A B : C} [IsConnected A] [IsConnected B] (a : F.obj A) (b : F.obj B) (i : A ⟶ X) (j : B ⟶ X) (h : F.map i a = F.map j b) [Mono i] [Mono j] : ∃ (f : A ≅ B), F.map f.hom a = b := by /- We consider the fiber product of A and B over X. This is a non-empty (because of `h`) subobject of `A` and `B` and hence isomorphic to `A` and `B` by connectedness. -/ let Y : C := pullback i j let u : Y ⟶ A := pullback.fst i j let v : Y ⟶ B := pullback.snd i j let G := F ⋙ FintypeCat.incl let e : F.obj Y ≃ { p : F.obj A × F.obj B // F.map i p.1 = F.map j p.2 } := fiberPullbackEquiv F i j let y : F.obj Y := e.symm ⟨(a, b), h⟩ have hn : IsInitial Y → False := not_initial_of_inhabited F y have : IsIso u := IsConnected.noTrivialComponent Y u hn have : IsIso v := IsConnected.noTrivialComponent Y v hn use (asIso u).symm ≪≫ asIso v have hu : G.map u y = a := by simp only [u, G, y, e, ← PreservesPullback.iso_hom_fst G, fiberPullbackEquiv, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun, types_comp_apply, inv_hom_id_apply] erw [Types.pullbackIsoPullback_inv_fst_apply (F.map i) (F.map j)] have hv : G.map v y = b := by simp only [v, G, y, e, ← PreservesPullback.iso_hom_snd G, fiberPullbackEquiv, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun, types_comp_apply, inv_hom_id_apply] erw [Types.pullbackIsoPullback_inv_snd_apply (F.map i) (F.map j)] rw [← hu, ← hv] change (F.map u ≫ F.map _) y = F.map v y simp only [← F.map_comp, Iso.trans_hom, Iso.symm_hom, asIso_inv, asIso_hom, IsIso.hom_inv_id_assoc] end Decomposition section GaloisRep /-! ### Galois representative of fiber If `X` is any object, then its fiber is represented by some Galois object: There exists a Galois object `A` and an element `a` in the fiber of `A` such that the evaluation at `a` from `A ⟶ X` to `F.obj X` is bijective. To show this we consider the product `∏ᶜ (fun _ : F.obj X ↦ X)` and let `A` be the connected component whose fiber contains the element `a` in the fiber of the self product that has at each index `x : F.obj X` the element `x`. This `A` is Galois and evaluation at `a` is bijective. Reference: [lenstraGSchemes, 3.14] -/ variable [GaloisCategory C] (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] section GaloisRepAux variable (X : C) /-- The self product of `X` indexed by its fiber. -/ @[simp] private noncomputable def selfProd : C := ∏ᶜ (fun _ : F.obj X ↦ X) /-- For `g : F.obj X → F.obj X`, this is the element in the fiber of the self product, which has at index `x : F.obj X` the element `g x`. -/ private noncomputable def mkSelfProdFib : F.obj (selfProd F X) := (PreservesProduct.iso F _).inv ((Concrete.productEquiv (fun _ : F.obj X ↦ F.obj X)).symm id) @[simp] private lemma mkSelfProdFib_map_π (t : F.obj X) : F.map (Pi.π _ t) (mkSelfProdFib F X) = t := by rw [← congrFun (piComparison_comp_π F _ t), FintypeCat.comp_apply, ← PreservesProduct.iso_hom] simp only [mkSelfProdFib, FintypeCat.inv_hom_id_apply] exact Concrete.productEquiv_symm_apply_π.{w, w, w+1} (fun _ : F.obj X ↦ F.obj X) id t variable {X} {A : C} (u : A ⟶ selfProd F X) (a : F.obj A) (h : F.map u a = mkSelfProdFib F X) {F} include h /-- For each `x : F.obj X`, this is the composition of `u` with the projection at `x`. -/ @[simp] private noncomputable def selfProdProj (x : F.obj X) : A ⟶ X := u ≫ Pi.π _ x variable {u a} private lemma selfProdProj_fiber (x : F.obj X) : F.map (selfProdProj u x) a = x := by simp only [selfProdProj, selfProd, F.map_comp, FintypeCat.comp_apply, h] rw [mkSelfProdFib_map_π F X x] variable [IsConnected A] /-- An element `b : F.obj A` defines a permutation of the fiber of `X` by projecting onto the `F.map u b` factor. -/ private noncomputable def fiberPerm (b : F.obj A) : F.obj X ≃ F.obj X := by let σ (t : F.obj X) : F.obj X := F.map (selfProdProj u t) b apply Equiv.ofBijective σ apply Finite.injective_iff_bijective.mp intro t s (hs : F.map (selfProdProj u t) b = F.map (selfProdProj u s) b) change id t = id s have h' : selfProdProj u t = selfProdProj u s := evaluation_injective_of_isConnected F A X b hs rw [← selfProdProj_fiber h s, ← selfProdProj_fiber h t, h'] /-- Twisting `u` by `fiberPerm h b` yields an inclusion of `A` into `selfProd F X`. -/ private noncomputable def selfProdPermIncl (b : F.obj A) : A ⟶ selfProd F X := u ≫ (Pi.whiskerEquiv (fiberPerm h b) (fun _ => Iso.refl X)).inv private instance [Mono u] (b : F.obj A) : Mono (selfProdPermIncl h b) := mono_comp _ _ /-- Key technical lemma: the twisted inclusion `selfProdPermIncl h b` maps `a` to `F.map u b`. -/ private lemma selfProdTermIncl_fib_eq (b : F.obj A) : F.map u b = F.map (selfProdPermIncl h b) a := by apply Concrete.Pi.map_ext _ F intro (t : F.obj X) convert_to F.map (selfProdProj u t) b = _ · simp only [selfProdProj, map_comp, FintypeCat.comp_apply]; rfl · dsimp only [selfProdPermIncl, Pi.whiskerEquiv] rw [map_comp, FintypeCat.comp_apply, h] convert_to F.map (selfProdProj u t) b = (F.map (Pi.map' (fiberPerm h b) fun _ ↦ 𝟙 X) ≫ F.map (Pi.π (fun _ ↦ X) t)) (mkSelfProdFib F X) rw [← map_comp, Pi.map'_comp_π, Category.comp_id, mkSelfProdFib_map_π F X (fiberPerm h b t)] rfl /-- There exists an automorphism `f` of `A` that maps `b` to `a`. `f` is obtained by considering `u` and `selfProdPermIncl h b`. Both are inclusions of `A` into `selfProd F X` mapping `b` respectively `a` to the same element in the fiber of `selfProd F X`. Applying `connected_component_unique` yields the result. -/ private lemma subobj_selfProd_trans [Mono u] (b : F.obj A) : ∃ (f : A ≅ A), F.map f.hom b = a := by apply connected_component_unique F b a u (selfProdPermIncl h b) exact selfProdTermIncl_fib_eq h b end GaloisRepAux /-- The fiber of any object in a Galois category is represented by a Galois object. -/ lemma exists_galois_representative (X : C) : ∃ (A : C) (a : F.obj A), IsGalois A ∧ Function.Bijective (fun (f : A ⟶ X) ↦ F.map f a) := by obtain ⟨A, u, a, h1, h2, h3⟩ := fiber_in_connected_component F (selfProd F X) (mkSelfProdFib F X) use A use a constructor · refine (isGalois_iff_pretransitive F A).mpr ⟨fun x y ↦ ?_⟩ obtain ⟨fi1, hfi1⟩ := subobj_selfProd_trans h1 x obtain ⟨fi2, hfi2⟩ := subobj_selfProd_trans h1 y use fi1 ≪≫ fi2.symm change F.map (fi1.hom ≫ fi2.inv) x = y simp only [map_comp, FintypeCat.comp_apply] rw [hfi1, ← hfi2] exact congr_fun (F.mapIso fi2).hom_inv_id y · refine ⟨evaluation_injective_of_isConnected F A X a, ?_⟩ intro x use u ≫ Pi.π _ x exact (selfProdProj_fiber h1) x /-- Any element in the fiber of an object `X` is the evaluation of a morphism from a Galois object. -/ lemma exists_hom_from_galois_of_fiber (X : C) (x : F.obj X) : ∃ (A : C) (f : A ⟶ X) (a : F.obj A), IsGalois A ∧ F.map f a = x := by obtain ⟨A, a, h1, h2⟩ := exists_galois_representative F X obtain ⟨f, hf⟩ := h2.surjective x exact ⟨A, f, a, h1, hf⟩ /-- Any object with non-empty fiber admits a hom from a Galois object. -/ lemma exists_hom_from_galois_of_fiber_nonempty (X : C) (h : Nonempty (F.obj X)) : ∃ (A : C) (_ : A ⟶ X), IsGalois A := by obtain ⟨x⟩ := h obtain ⟨A, f, a, h1, _⟩ := exists_hom_from_galois_of_fiber F X x exact ⟨A, f, h1⟩ include F in /-- Any connected object admits a hom from a Galois object. -/ lemma exists_hom_from_galois_of_connected (X : C) [IsConnected X] : ∃ (A : C) (_ : A ⟶ X), IsGalois A := exists_hom_from_galois_of_fiber_nonempty F X inferInstance /-- To check equality of natural transformations `F ⟶ G`, it suffices to check it on Galois objects. -/ lemma natTrans_ext_of_isGalois {G : C ⥤ FintypeCat.{w}} {t s : F ⟶ G} (h : ∀ (X : C) [IsGalois X], t.app X = s.app X) : t = s := by ext X x obtain ⟨A, f, a, _, rfl⟩ := exists_hom_from_galois_of_fiber F X x rw [FunctorToFintypeCat.naturality, FunctorToFintypeCat.naturality, h A] end GaloisRep end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Topology.lean
import Mathlib.CategoryTheory.Galois.Prorepresentability import Mathlib.Topology.Algebra.ContinuousMonoidHom import Mathlib.Topology.Algebra.Group.Basic /-! # Topology of fundamental group In this file we define a natural topology on the automorphism group of a functor `F : C ⥤ FintypeCat`: It is defined as the subspace topology induced by the natural embedding of `Aut F` into `∀ X, Aut (F.obj X)` where `Aut (F.obj X)` carries the discrete topology. ## References - [Stacks 0BMQ](https://stacks.math.columbia.edu/tag/0BMQ) -/ open Topology universe u₁ u₂ v₁ v₂ v w namespace CategoryTheory namespace PreGaloisCategory open Functor variable {C : Type u₁} [Category.{u₂} C] (F : C ⥤ FintypeCat.{w}) /-- For a functor `F : C ⥤ FintypeCat`, the canonical embedding of `Aut F` into the product over `Aut (F.obj X)` for all objects `X`. -/ def autEmbedding : Aut F →* ∀ X, Aut (F.obj X) := MonoidHom.mk' (fun σ X ↦ σ.app X) (fun _ _ ↦ rfl) @[simp] lemma autEmbedding_apply (σ : Aut F) (X : C) : autEmbedding F σ X = σ.app X := rfl lemma autEmbedding_injective : Function.Injective (autEmbedding F) := by intro σ τ h ext X x have : σ.app X = τ.app X := congr_fun h X rw [← Iso.app_hom, ← Iso.app_hom, this] /-- We put the discrete topology on `F.obj X`. -/ scoped instance (X : C) : TopologicalSpace (F.obj X) := ⊥ @[scoped instance] lemma obj_discreteTopology (X : C) : DiscreteTopology (F.obj X) := ⟨rfl⟩ /-- We put the discrete topology on `Aut (F.obj X)`. -/ scoped instance (X : C) : TopologicalSpace (Aut (F.obj X)) := ⊥ @[scoped instance] lemma aut_discreteTopology (X : C) : DiscreteTopology (Aut (F.obj X)) := ⟨rfl⟩ /-- `Aut F` is equipped with the by the embedding into `∀ X, Aut (F.obj X)` induced embedding. -/ instance : TopologicalSpace (Aut F) := TopologicalSpace.induced (autEmbedding F) inferInstance /-- The image of `Aut F` in `∀ X, Aut (F.obj X)` are precisely the compatible families of automorphisms. -/ lemma autEmbedding_range : Set.range (autEmbedding F) = ⋂ (f : Arrow C), { a | F.map f.hom ≫ (a f.right).hom = (a f.left).hom ≫ F.map f.hom } := by ext a simp only [Set.mem_range, id_obj, Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun ⟨σ, h⟩ i ↦ h.symm ▸ σ.hom.naturality i.hom, fun h ↦ ?_⟩ · use NatIso.ofComponents a (fun {X Y} f ↦ h ⟨X, Y, f⟩) rfl /-- The image of `Aut F` in `∀ X, Aut (F.obj X)` is closed. -/ lemma autEmbedding_range_isClosed : IsClosed (Set.range (autEmbedding F)) := by rw [autEmbedding_range] refine isClosed_iInter (fun f ↦ isClosed_eq (X := F.obj f.left → F.obj f.right) ?_ ?_) · fun_prop · fun_prop lemma autEmbedding_isClosedEmbedding : IsClosedEmbedding (autEmbedding F) where eq_induced := rfl injective := autEmbedding_injective F isClosed_range := autEmbedding_range_isClosed F instance : CompactSpace (Aut F) := (autEmbedding_isClosedEmbedding F).compactSpace instance : T2Space (Aut F) := T2Space.of_injective_continuous (autEmbedding_injective F) continuous_induced_dom instance : TotallyDisconnectedSpace (Aut F) := (autEmbedding_isClosedEmbedding F).isEmbedding.isTotallyDisconnected_range.mp (isTotallyDisconnected_of_totallyDisconnectedSpace _) instance : ContinuousMul (Aut F) := (autEmbedding_isClosedEmbedding F).isInducing.continuousMul (autEmbedding F) instance : ContinuousInv (Aut F) := (autEmbedding_isClosedEmbedding F).isInducing.continuousInv fun _ ↦ rfl instance : IsTopologicalGroup (Aut F) := ⟨⟩ instance (X : C) : SMul (Aut (F.obj X)) (F.obj X) := ⟨fun σ a => σ.hom a⟩ instance (X : C) : ContinuousSMul (Aut (F.obj X)) (F.obj X) := by constructor fun_prop instance continuousSMul_aut_fiber (X : C) : ContinuousSMul (Aut F) (F.obj X) where continuous_smul := by let g : Aut (F.obj X) × F.obj X → F.obj X := fun ⟨σ, x⟩ ↦ σ.hom x let h (q : Aut F × F.obj X) : Aut (F.obj X) × F.obj X := ⟨((fun p ↦ p X) ∘ autEmbedding F) q.1, q.2⟩ change Continuous (g ∘ h) fun_prop /-- If `G` is a functor of categories of finite types, the induced map `Aut F → Aut (F ⋙ G)` is continuous. -/ lemma continuous_mapAut_whiskeringRight (G : FintypeCat.{w} ⥤ FintypeCat.{v}) : Continuous (((whiskeringRight _ _ _).obj G).mapAut F) := by rw [Topology.IsInducing.continuous_iff (autEmbedding_isClosedEmbedding _).isInducing, continuous_pi_iff] intro X change Continuous fun a ↦ G.mapAut (F.obj X) (autEmbedding F a X) fun_prop /-- If `G` is a fully faithful functor of categories finite types, this is the automorphism of topological groups `Aut F ≃ Aut (F ⋙ G)`. -/ noncomputable def autEquivAutWhiskerRight {G : FintypeCat.{w} ⥤ FintypeCat.{v}} (h : G.FullyFaithful) : Aut F ≃ₜ* Aut (F ⋙ G) where __ := (h.whiskeringRight C).autMulEquivOfFullyFaithful F continuous_toFun := continuous_mapAut_whiskeringRight F G continuous_invFun := Continuous.continuous_symm_of_equiv_compact_to_t2 (f := ((h.whiskeringRight C).autMulEquivOfFullyFaithful F).toEquiv) (continuous_mapAut_whiskeringRight F G) variable [GaloisCategory C] [FiberFunctor F] /-- If `H` is an open subset of `Aut F` such that `1 ∈ H`, there exists a finite set `I` of connected objects of `C` such that every `σ : Aut F` that induces the identity on `F.obj X` for all `X ∈ I` is contained in `H`. In other words: The kernel of the evaluation map `Aut F →* ∏ X : I ↦ Aut (F.obj X)` is contained in `H`. -/ lemma exists_set_ker_evaluation_subset_of_isOpen {H : Set (Aut F)} (h1 : 1 ∈ H) (h : IsOpen H) : ∃ (I : Set C) (_ : Fintype I), (∀ X ∈ I, IsConnected X) ∧ (∀ σ : Aut F, (∀ X : I, σ.hom.app X = 𝟙 (F.obj X)) → σ ∈ H) := by obtain ⟨U, hUopen, rfl⟩ := isOpen_induced_iff.mp h obtain ⟨I, u, ho, ha⟩ := isOpen_pi_iff.mp hUopen 1 h1 choose fι ff fc h4 h5 h6 using (fun X : I => has_decomp_connected_components X.val) refine ⟨⋃ X, Set.range (ff X), Fintype.ofFinite _, ?_, ?_⟩ · rintro X ⟨A, ⟨Y, rfl⟩, hA2⟩ obtain ⟨i, rfl⟩ := hA2 exact h5 Y i · refine fun σ h ↦ ha (fun X XinI ↦ ?_) suffices h : autEmbedding F σ X = 1 by rw [h] exact (ho X XinI).right have h : σ.hom.app X = 𝟙 (F.obj X) := by have : Fintype (fι ⟨X, XinI⟩) := Fintype.ofFinite _ ext x obtain ⟨⟨j⟩, a, ha : F.map _ a = x⟩ := Limits.FintypeCat.jointly_surjective (Discrete.functor (ff ⟨X, XinI⟩) ⋙ F) _ (Limits.isColimitOfPreserves F (h4 ⟨X, XinI⟩)) x rw [FintypeCat.id_apply, ← ha, FunctorToFintypeCat.naturality] simp [h ⟨(ff _) j, ⟨Set.range (ff ⟨X, XinI⟩), ⟨⟨_, rfl⟩, ⟨j, rfl⟩⟩⟩⟩] exact Iso.ext h open Limits /-- The stabilizers of points in the fibers of Galois objects form a neighbourhood basis of the identity in `Aut F`. -/ lemma nhds_one_has_basis_stabilizers : (nhds (1 : Aut F)).HasBasis (fun _ ↦ True) (fun X : PointedGaloisObject F ↦ MulAction.stabilizer (Aut F) X.pt) where mem_iff' S := by rw [mem_nhds_iff] refine ⟨?_, ?_⟩ · intro ⟨U, hU, hUopen, hUone⟩ obtain ⟨I, _, hc, hmem⟩ := exists_set_ker_evaluation_subset_of_isOpen F hUone hUopen let P : C := ∏ᶜ fun X : I ↦ X.val obtain ⟨A, a, hgal, hbij⟩ := exists_galois_representative F P refine ⟨⟨A, a, hgal⟩, trivial, ?_⟩ intro t (ht : t.hom.app A a = a) apply hU apply hmem haveI (X : I) : IsConnected X.val := hc X.val X.property haveI (X : I) : Nonempty (F.obj X.val) := nonempty_fiber_of_isConnected F X intro X ext x simp only [FintypeCat.id_apply] obtain ⟨z, rfl⟩ := surjective_of_nonempty_fiber_of_isConnected F (Pi.π (fun X : I ↦ X.val) X) x obtain ⟨f, rfl⟩ := hbij.surjective z rw [FunctorToFintypeCat.naturality, FunctorToFintypeCat.naturality, ht] · intro ⟨X, _, h⟩ exact ⟨MulAction.stabilizer (Aut F) X.pt, h, stabilizer_isOpen (Aut F) X.pt, Subgroup.one_mem _⟩ end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Basic.lean
import Mathlib.Algebra.Group.TransferInstance import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Limits.FintypeCat import Mathlib.CategoryTheory.Limits.MonoCoprod import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory import Mathlib.CategoryTheory.Limits.Shapes.Diagonal import Mathlib.CategoryTheory.Limits.Types.Equalizers import Mathlib.CategoryTheory.SingleObj import Mathlib.Data.Finite.Card /-! # Definition and basic properties of Galois categories We define the notion of a Galois category and a fiber functor as in SGA1, following the definitions in Lenstras notes (see below for a reference). ## Main definitions * `PreGaloisCategory` : defining properties of Galois categories not involving a fiber functor * `FiberFunctor` : a fiber functor from a `PreGaloisCategory` to `FintypeCat` * `GaloisCategory` : a `PreGaloisCategory` that admits a `FiberFunctor` * `IsConnected` : an object of a category is connected if it is not initial and does not have non-trivial subobjects Any fiber functor `F` induces an equivalence with the category of finite, discrete `Aut F`-types. This is proven in `Mathlib/CategoryTheory/Galois/Equivalence.lean`. ## Implementation details We mostly follow Def 3.1 in Lenstras notes. In axiom (G3) we omit the factorisation of morphisms in epimorphisms and monomorphisms as this is not needed for the proof of the fundamental theorem on Galois categories (and then follows from it). ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ v₁ v₂ w t namespace CategoryTheory open Limits Functor /-! A category `C` is a PreGalois category if it satisfies all properties of a Galois category in the sense of SGA1 that do not involve a fiber functor. A Galois category should furthermore admit a fiber functor. The only difference between `[PreGaloisCategory C] (F : C ⥤ FintypeCat) [FiberFunctor F]` and `[GaloisCategory C]` is that the former fixes one fiber functor `F`. -/ /-- Definition of a (Pre)Galois category. Lenstra, Def 3.1, (G1)-(G3) -/ class PreGaloisCategory (C : Type u₁) [Category.{u₂, u₁} C] : Prop where /-- `C` has a terminal object (G1). -/ hasTerminal : HasTerminal C := by infer_instance /-- `C` has pullbacks (G1). -/ hasPullbacks : HasPullbacks C := by infer_instance /-- `C` has finite coproducts (G2). -/ hasFiniteCoproducts : HasFiniteCoproducts C := by infer_instance /-- `C` has quotients by finite groups (G2). -/ hasQuotientsByFiniteGroups (G : Type u₂) [Group G] [Finite G] : HasColimitsOfShape (SingleObj G) C := by infer_instance /-- Every monomorphism in `C` induces an isomorphism on a direct summand (G3). -/ monoInducesIsoOnDirectSummand {X Y : C} (i : X ⟶ Y) [Mono i] : ∃ (Z : C) (u : Z ⟶ Y), Nonempty (IsColimit (BinaryCofan.mk i u)) namespace PreGaloisCategory /-- Definition of a fiber functor from a Galois category. Lenstra, Def 3.1, (G4)-(G6) -/ class FiberFunctor {C : Type u₁} [Category.{u₂, u₁} C] [PreGaloisCategory C] (F : C ⥤ FintypeCat.{w}) where /-- `F` preserves terminal objects (G4). -/ preservesTerminalObjects : PreservesLimitsOfShape (CategoryTheory.Discrete PEmpty.{1}) F := by infer_instance /-- `F` preserves pullbacks (G4). -/ preservesPullbacks : PreservesLimitsOfShape WalkingCospan F := by infer_instance /-- `F` preserves finite coproducts (G5). -/ preservesFiniteCoproducts : PreservesFiniteCoproducts F := by infer_instance /-- `F` preserves epimorphisms (G5). -/ preservesEpis : Functor.PreservesEpimorphisms F := by infer_instance /-- `F` preserves quotients by finite groups (G5). -/ preservesQuotientsByFiniteGroups (G : Type u₂) [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) F := by infer_instance /-- `F` reflects isomorphisms (G6). -/ reflectsIsos : F.ReflectsIsomorphisms := by infer_instance /-- An object of a category `C` is connected if it is not initial and has no non-trivial subobjects. Lenstra, 3.12. -/ class IsConnected {C : Type u₁} [Category.{u₂, u₁} C] (X : C) : Prop where /-- `X` is not an initial object. -/ notInitial : IsInitial X → False /-- `X` has no non-trivial subobjects. -/ noTrivialComponent (Y : C) (i : Y ⟶ X) [Mono i] : (IsInitial Y → False) → IsIso i /-- A functor is said to preserve connectedness if whenever `X : C` is connected, also `F.obj X` is connected. -/ class PreservesIsConnected {C : Type u₁} [Category.{u₂, u₁} C] {D : Type v₁} [Category.{v₂, v₁} D] (F : C ⥤ D) : Prop where /-- `F.obj X` is connected if `X` is connected. -/ preserves : ∀ {X : C} [IsConnected X], IsConnected (F.obj X) section variable {C : Type u₁} [Category.{u₂, u₁} C] [PreGaloisCategory C] attribute [instance] hasTerminal hasPullbacks hasFiniteCoproducts hasQuotientsByFiniteGroups instance : HasFiniteLimits C := hasFiniteLimits_of_hasTerminal_and_pullbacks instance : HasBinaryProducts C := hasBinaryProducts_of_hasTerminal_and_pullbacks C instance : HasEqualizers C := hasEqualizers_of_hasPullbacks_and_binary_products -- A `PreGaloisCategory` has quotients by finite groups in arbitrary universes. -/ instance {G : Type*} [Group G] [Finite G] : HasColimitsOfShape (SingleObj G) C := by obtain ⟨G', hg, hf, ⟨e⟩⟩ := Finite.exists_type_univ_nonempty_mulEquiv G exact Limits.hasColimitsOfShape_of_equivalence e.toSingleObjEquiv.symm end namespace FiberFunctor variable {C : Type u₁} [Category.{u₂, u₁} C] {F : C ⥤ FintypeCat.{w}} [PreGaloisCategory C] [FiberFunctor F] attribute [instance] preservesTerminalObjects preservesPullbacks preservesEpis preservesFiniteCoproducts reflectsIsos preservesQuotientsByFiniteGroups noncomputable instance : ReflectsLimitsOfShape (Discrete PEmpty.{1}) F := reflectsLimitsOfShape_of_reflectsIsomorphisms noncomputable instance : ReflectsColimitsOfShape (Discrete PEmpty.{1}) F := reflectsColimitsOfShape_of_reflectsIsomorphisms noncomputable instance : PreservesFiniteLimits F := preservesFiniteLimits_of_preservesTerminal_and_pullbacks F /-- Fiber functors preserve quotients by finite groups in arbitrary universes. -/ instance {G : Type*} [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) F := by choose G' hg hf he using Finite.exists_type_univ_nonempty_mulEquiv G exact Limits.preservesColimitsOfShape_of_equiv he.some.toSingleObjEquiv.symm F /-- Fiber functors reflect monomorphisms. -/ instance : ReflectsMonomorphisms F := ReflectsMonomorphisms.mk <| by intro X Y f _ haveI : IsIso (pullback.fst (F.map f) (F.map f)) := isIso_fst_of_mono (F.map f) haveI : IsIso (F.map (pullback.fst f f)) := by rw [← PreservesPullback.iso_hom_fst] exact IsIso.comp_isIso haveI : IsIso (pullback.fst f f) := isIso_of_reflects_iso (pullback.fst _ _) F exact (pullback.diagonal_isKernelPair f).mono_of_isIso_fst /-- Fiber functors are faithful. -/ instance : F.Faithful where map_injective {X Y} f g h := by haveI : IsIso (equalizer.ι (F.map f) (F.map g)) := equalizer.ι_of_eq h haveI : IsIso (F.map (equalizer.ι f g)) := by rw [← equalizerComparison_comp_π f g F] exact IsIso.comp_isIso haveI : IsIso (equalizer.ι f g) := isIso_of_reflects_iso _ F exact eq_of_epi_equalizer section /-- If `F` is a fiber functor and `E` is an equivalence between categories of finite types, then `F ⋙ E` is again a fiber functor. -/ instance comp_right (E : FintypeCat.{w} ⥤ FintypeCat.{t}) [E.IsEquivalence] : FiberFunctor (F ⋙ E) where preservesQuotientsByFiniteGroups _ := comp_preservesColimitsOfShape F E end end FiberFunctor variable {C : Type u₁} [Category.{u₂, u₁} C] (F : C ⥤ FintypeCat.{w}) /-- The canonical action of `Aut F` on the fiber of each object. -/ instance (X : C) : MulAction (Aut F) (F.obj X) where smul σ x := σ.hom.app X x one_smul _ := rfl mul_smul _ _ _ := rfl lemma mulAction_def {X : C} (σ : Aut F) (x : F.obj X) : σ • x = σ.hom.app X x := rfl lemma mulAction_naturality {X Y : C} (σ : Aut F) (f : X ⟶ Y) (x : F.obj X) : σ • F.map f x = F.map f (σ • x) := FunctorToFintypeCat.naturality F F σ.hom f x /-- An object that is neither initial or connected has a non-trivial subobject. -/ lemma has_non_trivial_subobject_of_not_isConnected_of_not_initial (X : C) (hc : ¬ IsConnected X) (hi : IsInitial X → False) : ∃ (Y : C) (v : Y ⟶ X), (IsInitial Y → False) ∧ Mono v ∧ (¬ IsIso v) := by contrapose! hc exact ⟨hi, fun Y i hm hni ↦ hc Y i hni hm⟩ /-- The cardinality of the fiber is preserved under isomorphisms. -/ lemma card_fiber_eq_of_iso {X Y : C} (i : X ≅ Y) : Nat.card (F.obj X) = Nat.card (F.obj Y) := by have e : F.obj X ≃ F.obj Y := Iso.toEquiv (mapIso (F ⋙ FintypeCat.incl) i) exact Nat.card_eq_of_bijective e (Equiv.bijective e) variable [PreGaloisCategory C] [FiberFunctor F] /-- An object is initial if and only if its fiber is empty. -/ lemma initial_iff_fiber_empty (X : C) : Nonempty (IsInitial X) ↔ IsEmpty (F.obj X) := by rw [(IsInitial.isInitialIffObj F X).nonempty_congr] haveI : PreservesFiniteColimits (forget FintypeCat) := by change PreservesFiniteColimits FintypeCat.incl infer_instance haveI : ReflectsColimit (Functor.empty.{0} _) (forget FintypeCat) := by change ReflectsColimit (Functor.empty.{0} _) FintypeCat.incl infer_instance exact Concrete.initial_iff_empty_of_preserves_of_reflects (F.obj X) /-- An object is not initial if and only if its fiber is nonempty. -/ lemma not_initial_iff_fiber_nonempty (X : C) : (IsInitial X → False) ↔ Nonempty (F.obj X) := by rw [← not_isEmpty_iff] refine ⟨fun h he ↦ ?_, fun h hin ↦ h <| (initial_iff_fiber_empty F X).mp ⟨hin⟩⟩ exact Nonempty.elim ((initial_iff_fiber_empty F X).mpr he) h /-- An object whose fiber is inhabited is not initial. -/ lemma not_initial_of_inhabited {X : C} (x : F.obj X) (h : IsInitial X) : False := ((initial_iff_fiber_empty F X).mp ⟨h⟩).false x /-- The fiber of a connected object is nonempty. -/ instance nonempty_fiber_of_isConnected (X : C) [IsConnected X] : Nonempty (F.obj X) := by by_contra h have ⟨hin⟩ : Nonempty (IsInitial X) := (initial_iff_fiber_empty F X).mpr (not_nonempty_iff.mp h) exact IsConnected.notInitial hin /-- The fiber of the equalizer of `f g : X ⟶ Y` is equivalent to the set of agreement of `f` and `g`. -/ noncomputable def fiberEqualizerEquiv {X Y : C} (f g : X ⟶ Y) : F.obj (equalizer f g) ≃ { x : F.obj X // F.map f x = F.map g x } := (PreservesEqualizer.iso (F ⋙ FintypeCat.incl) f g ≪≫ Types.equalizerIso (F.map f) (F.map g)).toEquiv @[simp] lemma fiberEqualizerEquiv_symm_ι_apply {X Y : C} {f g : X ⟶ Y} (x : F.obj X) (h : F.map f x = F.map g x) : F.map (equalizer.ι f g) ((fiberEqualizerEquiv F f g).symm ⟨x, h⟩) = x := by simp [fiberEqualizerEquiv] change ((Types.equalizerIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (equalizer.ι f g)) _ = _ erw [PreservesEqualizer.iso_inv_ι, Types.equalizerIso_inv_comp_ι] /-- The fiber of the pullback is the fiber product of the fibers. -/ noncomputable def fiberPullbackEquiv {X A B : C} (f : A ⟶ X) (g : B ⟶ X) : F.obj (pullback f g) ≃ { p : F.obj A × F.obj B // F.map f p.1 = F.map g p.2 } := (PreservesPullback.iso (F ⋙ FintypeCat.incl) f g ≪≫ Types.pullbackIsoPullback (F.map f) (F.map g)).toEquiv @[simp] lemma fiberPullbackEquiv_symm_fst_apply {X A B : C} {f : A ⟶ X} {g : B ⟶ X} (a : F.obj A) (b : F.obj B) (h : F.map f a = F.map g b) : F.map (pullback.fst f g) ((fiberPullbackEquiv F f g).symm ⟨(a, b), h⟩) = a := by simp [fiberPullbackEquiv] change ((Types.pullbackIsoPullback _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (pullback.fst f g)) _ = _ erw [PreservesPullback.iso_inv_fst, Types.pullbackIsoPullback_inv_fst] @[simp] lemma fiberPullbackEquiv_symm_snd_apply {X A B : C} {f : A ⟶ X} {g : B ⟶ X} (a : F.obj A) (b : F.obj B) (h : F.map f a = F.map g b) : F.map (pullback.snd f g) ((fiberPullbackEquiv F f g).symm ⟨(a, b), h⟩) = b := by simp [fiberPullbackEquiv] change ((Types.pullbackIsoPullback _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (pullback.snd f g)) _ = _ erw [PreservesPullback.iso_inv_snd, Types.pullbackIsoPullback_inv_snd] /-- The fiber of the binary product is the binary product of the fibers. -/ noncomputable def fiberBinaryProductEquiv (X Y : C) : F.obj (X ⨯ Y) ≃ F.obj X × F.obj Y := (PreservesLimitPair.iso (F ⋙ FintypeCat.incl) X Y ≪≫ Types.binaryProductIso (F.obj X) (F.obj Y)).toEquiv @[simp] lemma fiberBinaryProductEquiv_symm_fst_apply {X Y : C} (x : F.obj X) (y : F.obj Y) : F.map prod.fst ((fiberBinaryProductEquiv F X Y).symm (x, y)) = x := by simp only [fiberBinaryProductEquiv, comp_obj, FintypeCat.incl_obj, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun] change ((Types.binaryProductIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map prod.fst) _ = _ erw [PreservesLimitPair.iso_inv_fst, Types.binaryProductIso_inv_comp_fst] @[simp] lemma fiberBinaryProductEquiv_symm_snd_apply {X Y : C} (x : F.obj X) (y : F.obj Y) : F.map prod.snd ((fiberBinaryProductEquiv F X Y).symm (x, y)) = y := by simp only [fiberBinaryProductEquiv, comp_obj, FintypeCat.incl_obj, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun] change ((Types.binaryProductIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map prod.snd) _ = _ erw [PreservesLimitPair.iso_inv_snd, Types.binaryProductIso_inv_comp_snd] /-- The evaluation map is injective for connected objects. -/ lemma evaluation_injective_of_isConnected (A X : C) [IsConnected A] (a : F.obj A) : Function.Injective (fun (f : A ⟶ X) ↦ F.map f a) := by intro f g (h : F.map f a = F.map g a) haveI : IsIso (equalizer.ι f g) := by apply IsConnected.noTrivialComponent _ (equalizer.ι f g) exact not_initial_of_inhabited F ((fiberEqualizerEquiv F f g).symm ⟨a, h⟩) exact eq_of_epi_equalizer /-- The evaluation map on automorphisms is injective for connected objects. -/ lemma evaluation_aut_injective_of_isConnected (A : C) [IsConnected A] (a : F.obj A) : Function.Injective (fun f : Aut A ↦ F.map (f.hom) a) := by change Function.Injective ((fun f : A ⟶ A ↦ F.map f a) ∘ (fun f : Aut A ↦ f.hom)) apply Function.Injective.comp · exact evaluation_injective_of_isConnected F A A a · exact @Aut.ext _ _ A /-- A morphism from an object `X` with non-empty fiber to a connected object `A` is an epimorphism. -/ lemma epi_of_nonempty_of_isConnected {X A : C} [IsConnected A] [h : Nonempty (F.obj X)] (f : X ⟶ A) : Epi f := Epi.mk <| fun {Z} u v huv ↦ by apply evaluation_injective_of_isConnected F A Z (F.map f (Classical.arbitrary _)) simpa using congr_fun (F.congr_map huv) _ /-- An epimorphism induces a surjective map on fibers. -/ lemma surjective_on_fiber_of_epi {X Y : C} (f : X ⟶ Y) [Epi f] : Function.Surjective (F.map f) := surjective_of_epi (FintypeCat.incl.map (F.map f)) /- A morphism from an object with non-empty fiber to a connected object is surjective on fibers. -/ lemma surjective_of_nonempty_fiber_of_isConnected {X A : C} [Nonempty (F.obj X)] [IsConnected A] (f : X ⟶ A) : Function.Surjective (F.map f) := by have : Epi f := epi_of_nonempty_of_isConnected F f exact surjective_on_fiber_of_epi F f /-- If `X : ι → C` is a finite family of objects with non-empty fiber, then also `∏ᶜ X` has non-empty fiber. -/ instance nonempty_fiber_pi_of_nonempty_of_finite {ι : Type*} [Finite ι] (X : ι → C) [∀ i, Nonempty (F.obj (X i))] : Nonempty (F.obj (∏ᶜ X)) := by cases nonempty_fintype ι let f (i : ι) : FintypeCat.{w} := F.obj (X i) let i : F.obj (∏ᶜ X) ≅ ∏ᶜ f := PreservesProduct.iso F _ exact Nonempty.elim inferInstance fun x : (∏ᶜ f : FintypeCat.{w}) ↦ ⟨i.inv x⟩ section CardFiber open ConcreteCategory /-- A mono between objects with equally sized fibers is an iso. -/ lemma isIso_of_mono_of_eq_card_fiber {X Y : C} (f : X ⟶ Y) [Mono f] (h : Nat.card (F.obj X) = Nat.card (F.obj Y)) : IsIso f := by have : IsIso (F.map f) := by apply (ConcreteCategory.isIso_iff_bijective (F.map f)).mpr apply (Fintype.bijective_iff_injective_and_card (F.map f)).mpr refine ⟨injective_of_mono_of_preservesPullback (F.map f), ?_⟩ simp only [← Nat.card_eq_fintype_card, h] exact isIso_of_reflects_iso f F /-- Along a mono that is not an iso, the cardinality of the fiber strictly increases. -/ lemma lt_card_fiber_of_mono_of_notIso {X Y : C} (f : X ⟶ Y) [Mono f] (h : ¬ IsIso f) : Nat.card (F.obj X) < Nat.card (F.obj Y) := by by_contra hlt apply h apply isIso_of_mono_of_eq_card_fiber F f simp only [not_lt] at hlt exact Nat.le_antisymm (Nat.card_le_card_of_injective (F.map f) (injective_of_mono_of_preservesPullback (F.map f))) hlt /-- The cardinality of the fiber of a not-initial object is non-zero. -/ lemma non_zero_card_fiber_of_not_initial (X : C) (h : IsInitial X → False) : Nat.card (F.obj X) ≠ 0 := by intro hzero refine Nonempty.elim ?_ h rw [initial_iff_fiber_empty F] exact Finite.card_eq_zero_iff.mp hzero /-- The cardinality of the fiber of a coproduct is the sum of the cardinalities of the fibers. -/ lemma card_fiber_coprod_eq_sum (X Y : C) : Nat.card (F.obj (X ⨿ Y)) = Nat.card (F.obj X) + Nat.card (F.obj Y) := by let e : F.obj (X ⨿ Y) ≃ F.obj X ⊕ F.obj Y := Iso.toEquiv <| (PreservesColimitPair.iso (F ⋙ FintypeCat.incl) X Y).symm.trans <| Types.binaryCoproductIso (FintypeCat.incl.obj (F.obj X)) (FintypeCat.incl.obj (F.obj Y)) rw [← Nat.card_sum] exact Nat.card_eq_of_bijective e.toFun (Equiv.bijective e) /-- The cardinality of morphisms `A ⟶ X` is smaller than the cardinality of the fiber of the target if the source is connected. -/ lemma card_hom_le_card_fiber_of_connected (A X : C) [IsConnected A] : Nat.card (A ⟶ X) ≤ Nat.card (F.obj X) := by apply Nat.card_le_card_of_injective exact evaluation_injective_of_isConnected F A X (Classical.arbitrary _) /-- If `A` is connected, the cardinality of `Aut A` is smaller than the cardinality of the fiber of `A`. -/ lemma card_aut_le_card_fiber_of_connected (A : C) [IsConnected A] : Nat.card (Aut A) ≤ Nat.card (F.obj A) := by have h : Nonempty (F.obj A) := inferInstance obtain ⟨a⟩ := h apply Nat.card_le_card_of_injective exact evaluation_aut_injective_of_isConnected _ _ a end CardFiber end PreGaloisCategory /-- A `PreGaloisCategory` is a `GaloisCategory` if it admits a fiber functor. -/ class GaloisCategory (C : Type u₁) [Category.{u₂, u₁} C] : Prop extends PreGaloisCategory C where hasFiberFunctor : ∃ F : C ⥤ FintypeCat.{u₂}, Nonempty (PreGaloisCategory.FiberFunctor F) namespace PreGaloisCategory variable (C : Type u₁) [Category.{u₂, u₁} C] [GaloisCategory C] /-- Arbitrarily choose a fiber functor for a Galois category using choice. -/ noncomputable def GaloisCategory.getFiberFunctor : C ⥤ FintypeCat.{u₂} := Classical.choose <| @GaloisCategory.hasFiberFunctor C _ _ /-- The arbitrarily chosen fiber functor `GaloisCategory.getFiberFunctor` is a fiber functor. -/ noncomputable instance : FiberFunctor (GaloisCategory.getFiberFunctor C) := Classical.choice <| Classical.choose_spec (@GaloisCategory.hasFiberFunctor C _ _) variable {C} /-- In a `GaloisCategory` the set of morphisms out of a connected object is finite. -/ instance (A X : C) [IsConnected A] : Finite (A ⟶ X) := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A apply Finite.of_injective (fun f ↦ F.map f a) exact evaluation_injective_of_isConnected F A X a /-- In a `GaloisCategory` the set of automorphism of a connected object is finite. -/ instance (A : C) [IsConnected A] : Finite (Aut A) := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A apply Finite.of_injective (fun f ↦ F.map f.hom a) exact evaluation_aut_injective_of_isConnected F A a /-- Coproduct inclusions are monic in Galois categories. -/ instance : MonoCoprod C := by let F := GaloisCategory.getFiberFunctor C exact MonoCoprod.monoCoprod_of_preservesCoprod_of_reflectsMono F end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Prorepresentability.lean
import Mathlib.Algebra.Category.Grp.Limits import Mathlib.CategoryTheory.CofilteredSystem import Mathlib.CategoryTheory.Galois.Decomposition import Mathlib.CategoryTheory.Limits.IndYoneda import Mathlib.CategoryTheory.Limits.Preserves.Ulift /-! # Pro-Representability of fiber functors We show that any fiber functor is pro-representable, i.e. there exists a pro-object `X : I ⥤ C` such that `F` is naturally isomorphic to the colimit of `X ⋙ coyoneda`. From this we deduce the canonical isomorphism of `Aut F` with the limit over the automorphism groups of all Galois objects. ## Main definitions - `PointedGaloisObject`: the category of pointed Galois objects - `PointedGaloisObject.cocone`: a cocone on `(PointedGaloisObject.incl F).op ≫ coyoneda` with point `F ⋙ FintypeCat.incl`. - `autGaloisSystem`: the system of automorphism groups indexed by the pointed Galois objects. ## Main results - `PointedGaloisObject.isColimit`: the cocone `PointedGaloisObject.cocone` is a colimit cocone. - `autMulEquivAutGalois`: `Aut F` is canonically isomorphic to the limit over the automorphism groups of all Galois objects. - `FiberFunctor.isPretransitive_of_isConnected`: The `Aut F` action on the fiber of a connected object is transitive. ## Implementation details The pro-representability statement and the isomorphism of `Aut F` with the limit over the automorphism groups of all Galois objects naturally forces `F` to take values in `FintypeCat.{u₂}` where `u₂` is the `Hom`-universe of `C`. Since this is used to show that `Aut F` acts transitively on `F.obj X` for connected `X`, we a priori only obtain this result for the mentioned specialized universe setup. To obtain the result for `F` taking values in an arbitrary `FintypeCat.{w}`, we postcompose with an equivalence `FintypeCat.{w} ≌ FintypeCat.{u₂}` and apply the specialized result. In the following the section `Specialized` is reserved for the setup where `F` takes values in `FintypeCat.{u₂}` and the section `General` contains results holding for `F` taking values in an arbitrary `FintypeCat.{w}`. ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ w namespace CategoryTheory namespace PreGaloisCategory open Limits Functor variable {C : Type u₁} [Category.{u₂} C] [GaloisCategory C] /-- A pointed Galois object is a Galois object with a fixed point of its fiber. -/ structure PointedGaloisObject (F : C ⥤ FintypeCat.{w}) : Type (max u₁ u₂ w) where /-- The underlying object of `C`. -/ obj : C /-- An element of the fiber of `obj`. -/ pt : F.obj obj /-- `obj` is Galois. -/ isGalois : IsGalois obj := by infer_instance namespace PointedGaloisObject section General variable (F : C ⥤ FintypeCat.{w}) attribute [instance] isGalois instance (X : PointedGaloisObject F) : CoeDep (PointedGaloisObject F) X C where coe := X.obj variable {F} in /-- The type of homomorphisms between two pointed Galois objects. This is a homomorphism of the underlying objects of `C` that maps the distinguished points to each other. -/ @[ext] structure Hom (A B : PointedGaloisObject F) where /-- The underlying homomorphism of `C`. -/ val : A.obj ⟶ B.obj /-- The distinguished point of `A` is mapped to the distinguished point of `B`. -/ comp : F.map val A.pt = B.pt := by simp attribute [simp] Hom.comp /-- The category of pointed Galois objects. -/ instance : Category.{u₂} (PointedGaloisObject F) where Hom A B := Hom A B id A := { val := 𝟙 (A : C) } comp {A B C} f g := { val := f.val ≫ g.val } instance {A B : PointedGaloisObject F} : Coe (Hom A B) (A.obj ⟶ B.obj) where coe f := f.val variable {F} @[ext] lemma hom_ext {A B : PointedGaloisObject F} {f g : A ⟶ B} (h : f.val = g.val) : f = g := Hom.ext h @[simp] lemma id_val (A : PointedGaloisObject F) : 𝟙 A = 𝟙 A.obj := rfl @[simp, reassoc] lemma comp_val {A B C : PointedGaloisObject F} (f : A ⟶ B) (g : B ⟶ C) : (f ≫ g).val = f.val ≫ g.val := rfl variable (F) /-- The canonical functor from pointed Galois objects to `C`. -/ def incl : PointedGaloisObject F ⥤ C where obj := fun A ↦ A map := fun ⟨f, _⟩ ↦ f @[simp] lemma incl_obj (A : PointedGaloisObject F) : (incl F).obj A = A := rfl @[simp] lemma incl_map {A B : PointedGaloisObject F} (f : A ⟶ B) : (incl F).map f = f.val := rfl end General section Specialized variable (F : C ⥤ FintypeCat.{u₂}) /-- `F ⋙ FintypeCat.incl` as a cocone over `(can F).op ⋙ coyoneda`. This is a colimit cocone (see `PreGaloisCategory.isColimìt`) -/ def cocone : Cocone ((incl F).op ⋙ coyoneda) where pt := F ⋙ FintypeCat.incl ι := { app := fun ⟨A, a, _⟩ ↦ { app := fun X (f : (A : C) ⟶ X) ↦ F.map f a } naturality := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ⟨f, (hf : F.map f b = a)⟩ ↦ by ext Y (g : (A : C) ⟶ Y) suffices h : F.map g (F.map f b) = F.map g a by simpa rw [hf] } @[simp] lemma cocone_app (A : PointedGaloisObject F) (B : C) (f : (A : C) ⟶ B) : ((cocone F).ι.app ⟨A⟩).app B f = F.map f A.pt := rfl variable [FiberFunctor F] /-- The category of pointed Galois objects is cofiltered. -/ instance : IsCofilteredOrEmpty (PointedGaloisObject F) where cone_objs := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ↦ by obtain ⟨Z, f, z, hgal, hfz⟩ := exists_hom_from_galois_of_fiber F (A ⨯ B) <| (fiberBinaryProductEquiv F A B).symm (a, b) refine ⟨⟨Z, z, hgal⟩, ⟨f ≫ prod.fst, ?_⟩, ⟨f ≫ prod.snd, ?_⟩, trivial⟩ · simp only [F.map_comp, hfz, FintypeCat.comp_apply, fiberBinaryProductEquiv_symm_fst_apply] · simp only [F.map_comp, hfz, FintypeCat.comp_apply, fiberBinaryProductEquiv_symm_snd_apply] cone_maps := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ⟨f, hf⟩ ⟨g, hg⟩ ↦ by obtain ⟨Z, h, z, hgal, hhz⟩ := exists_hom_from_galois_of_fiber F A a refine ⟨⟨Z, z, hgal⟩, ⟨h, hhz⟩, hom_ext ?_⟩ apply evaluation_injective_of_isConnected F Z B z simp [hhz, hf, hg] /-- `cocone F` is a colimit cocone, i.e. `F` is pro-represented by `incl F`. -/ noncomputable def isColimit : IsColimit (cocone F) := by refine evaluationJointlyReflectsColimits _ (fun X ↦ ?_) refine Types.FilteredColimit.isColimitOf _ _ ?_ ?_ · intro (x : F.obj X) obtain ⟨Y, i, y, h1, _, _⟩ := fiber_in_connected_component F X x obtain ⟨Z, f, z, hgal, hfz⟩ := exists_hom_from_galois_of_fiber F Y y refine ⟨⟨Z, z, hgal⟩, f ≫ i, ?_⟩ simp only [mapCocone_ι_app, evaluation_obj_map, cocone_app, map_comp, ← h1, FintypeCat.comp_apply, hfz] · intro ⟨A, a, _⟩ ⟨B, b, _⟩ (u : (A : C) ⟶ X) (v : (B : C) ⟶ X) (h : F.map u a = F.map v b) obtain ⟨⟨Z, z, _⟩, ⟨f, hf⟩, ⟨g, hg⟩, _⟩ := IsFilteredOrEmpty.cocone_objs (C := (PointedGaloisObject F)ᵒᵖ) ⟨{ obj := A, pt := a}⟩ ⟨{obj := B, pt := b}⟩ refine ⟨⟨{ obj := Z, pt := z }⟩, ⟨f, hf⟩, ⟨g, hg⟩, ?_⟩ apply evaluation_injective_of_isConnected F Z X z change F.map (f ≫ u) z = F.map (g ≫ v) z rw [map_comp, FintypeCat.comp_apply, hf, map_comp, FintypeCat.comp_apply, hg, h] instance : HasColimit ((incl F).op ⋙ coyoneda) where exists_colimit := ⟨cocone F, isColimit F⟩ end Specialized end PointedGaloisObject open PointedGaloisObject section Specialized variable (F : C ⥤ FintypeCat.{u₂}) /-- The diagram sending each pointed Galois object to its automorphism group as an object of `C`. -/ @[simps] noncomputable def autGaloisSystem : PointedGaloisObject F ⥤ GrpCat.{u₂} where obj := fun A ↦ GrpCat.of <| Aut (A : C) map := fun {A B} f ↦ GrpCat.ofHom (autMapHom f) /-- The limit of `autGaloisSystem`. -/ noncomputable def AutGalois : Type (max u₁ u₂) := (autGaloisSystem F ⋙ forget _).sections noncomputable instance : Group (AutGalois F) := inferInstanceAs <| Group (autGaloisSystem F ⋙ forget _).sections /-- The canonical projection from `AutGalois F` to the `C`-automorphism group of each pointed Galois object. -/ noncomputable def AutGalois.π (A : PointedGaloisObject F) : AutGalois F →* Aut (A : C) := GrpCat.sectionsπMonoidHom (autGaloisSystem F) A /- Not a `simp` lemma, because we usually don't want to expose the internals here. -/ lemma AutGalois.π_apply (A : PointedGaloisObject F) (x : AutGalois F) : AutGalois.π F A x = x.val A := rfl lemma autGaloisSystem_map_surjective ⦃A B : PointedGaloisObject F⦄ (f : A ⟶ B) : Function.Surjective ((autGaloisSystem F).map f) := by intro (φ : Aut B.obj) obtain ⟨ψ, hψ⟩ := autMap_surjective_of_isGalois f.val φ use ψ simp only [autGaloisSystem_map] exact hψ /-- Equality of elements of `AutGalois F` can be checked on the projections on each pointed Galois object. -/ lemma AutGalois.ext {f g : AutGalois F} (h : ∀ (A : PointedGaloisObject F), AutGalois.π F A f = AutGalois.π F A g) : f = g := by dsimp only [AutGalois] ext A exact h A variable [FiberFunctor F] /-- `autGalois.π` is surjective for every pointed Galois object. -/ theorem AutGalois.π_surjective (A : PointedGaloisObject F) : Function.Surjective (AutGalois.π F A) := fun (σ : Aut A.obj) ↦ by have (i : PointedGaloisObject F) : Finite ((autGaloisSystem F ⋙ forget _).obj i) := inferInstanceAs <| Finite (Aut (i.obj)) exact eval_section_surjective_of_surjective (autGaloisSystem F ⋙ forget _) (autGaloisSystem_map_surjective F) A σ section EndAutGaloisIsomorphism /-! ### Isomorphism between `Aut F` and `AutGalois F` In this section we establish the isomorphism between the automorphism group of `F` and the limit over the automorphism groups of all Galois objects. We first establish the isomorphism between `End F` and `AutGalois F`, from which we deduce that `End F` is a group, hence `End F = Aut F`. The isomorphism is built in multiple steps: - `endEquivSectionsFibers : End F ≅ (incl F ⋙ F').sections`: the endomorphisms of `F` are isomorphic to the limit over `F.obj A` for all Galois objects `A`. This is obtained as the composition (slightly simplified): `End F ≅ (colimit ((incl F).op ⋙ coyoneda) ⟶ F) ≅ (incl F ⋙ F).sections` Where the first isomorphism is induced from the pro-representability of `F` and the second one from the pro-coyoneda lemma. - `endEquivAutGalois : End F ≅ AutGalois F`: this is the composition of `endEquivSectionsFibers` with: `(incl F ⋙ F).sections ≅ (autGaloisSystem F ⋙ forget GrpCat).sections` which is induced from the level-wise equivalence `Aut A ≃ F.obj A` for a Galois object `A`. -/ -- Local notation for `F` considered as a functor to types instead of finite types. local notation "F'" => F ⋙ FintypeCat.incl /-- The endomorphisms of `F` are isomorphic to the limit over the fibers of `F` on all Galois objects. -/ noncomputable def endEquivSectionsFibers : End F ≃ (incl F ⋙ F').sections := let i1 : End F ≃ End F' := (FullyFaithful.whiskeringRight (FullyFaithful.ofFullyFaithful FintypeCat.incl) C).homEquiv let i2 : End F' ≅ (colimit ((incl F).op ⋙ coyoneda) ⟶ F') := (yoneda.obj (F ⋙ FintypeCat.incl)).mapIso (colimit.isoColimitCocone ⟨cocone F, isColimit F⟩).op let i3 : (colimit ((incl F).op ⋙ coyoneda) ⟶ F') ≅ limit ((incl F ⋙ F') ⋙ uliftFunctor.{u₁}) := colimitCoyonedaHomIsoLimit' (incl F) F' let i4 : limit (incl F ⋙ F' ⋙ uliftFunctor.{u₁}) ≃ ((incl F ⋙ F') ⋙ uliftFunctor.{u₁}).sections := Types.limitEquivSections (incl F ⋙ (F ⋙ FintypeCat.incl) ⋙ uliftFunctor.{u₁, u₂}) let i5 : ((incl F ⋙ F') ⋙ uliftFunctor.{u₁}).sections ≃ (incl F ⋙ F').sections := (Types.sectionsEquiv (incl F ⋙ F')).symm i1.trans <| i2.toEquiv.trans <| i3.toEquiv.trans <| i4.trans i5 @[simp] lemma endEquivSectionsFibers_π (f : End F) (A : PointedGaloisObject F) : (endEquivSectionsFibers F f).val A = f.app A A.pt := by dsimp [endEquivSectionsFibers, Types.sectionsEquiv] erw [Types.limitEquivSections_apply] simp only [colimitCoyonedaHomIsoLimit'_π_apply, incl_obj, comp_obj, FintypeCat.incl_obj, op_obj, FunctorToTypes.comp] change (((FullyFaithful.whiskeringRight (FullyFaithful.ofFullyFaithful FintypeCat.incl) C).homEquiv) f).app A (((colimit.ι _ _) ≫ (colimit.isoColimitCocone ⟨cocone F, isColimit F⟩).hom).app A _) = f.app A A.pt simp rfl /-- Functorial isomorphism `Aut A ≅ F.obj A` for Galois objects `A`. -/ noncomputable def autIsoFibers : autGaloisSystem F ⋙ forget GrpCat ≅ incl F ⋙ F' := NatIso.ofComponents (fun A ↦ ((evaluationEquivOfIsGalois F A A.pt).toIso)) (fun {A B} f ↦ by ext (φ : Aut A.obj) dsimp erw [evaluationEquivOfIsGalois_apply, evaluationEquivOfIsGalois_apply] simp [-Hom.comp, ← f.comp]) lemma autIsoFibers_inv_app (A : PointedGaloisObject F) (b : F.obj A) : (autIsoFibers F).inv.app A b = (evaluationEquivOfIsGalois F A A.pt).symm b := rfl /-- The equivalence between endomorphisms of `F` and the limit over the automorphism groups of all Galois objects. -/ noncomputable def endEquivAutGalois : End F ≃ AutGalois F := let e1 := endEquivSectionsFibers F let e2 := ((Functor.sectionsFunctor _).mapIso (autIsoFibers F).symm).toEquiv e1.trans e2 lemma endEquivAutGalois_π (f : End F) (A : PointedGaloisObject F) : F.map (AutGalois.π F A (endEquivAutGalois F f)).hom A.pt = f.app A A.pt := by dsimp [endEquivAutGalois, AutGalois.π_apply] change F.map ((((sectionsFunctor _).map (autIsoFibers F).inv) _).val A).hom A.pt = _ dsimp [autIsoFibers] simp only [endEquivSectionsFibers_π] erw [evaluationEquivOfIsGalois_symm_fiber] @[simp] theorem endEquivAutGalois_mul (f g : End F) : (endEquivAutGalois F) (g ≫ f) = (endEquivAutGalois F g) * (endEquivAutGalois F f) := by refine AutGalois.ext F (fun A ↦ evaluation_aut_injective_of_isConnected F A A.pt ?_) simp only [map_mul, endEquivAutGalois_π, Aut.Aut_mul_def, NatTrans.comp_app, Iso.trans_hom] simp only [map_comp, FintypeCat.comp_apply, endEquivAutGalois_π] change f.app A (g.app A A.pt) = (f.app A ≫ F.map ((AutGalois.π F A) ((endEquivAutGalois F) g)).hom) A.pt rw [← f.naturality, FintypeCat.comp_apply, endEquivAutGalois_π] /-- The monoid isomorphism between endomorphisms of `F` and the (multiplicative opposite of the) limit of automorphism groups of all Galois objects. -/ noncomputable def endMulEquivAutGalois : End F ≃* (AutGalois F)ᵐᵒᵖ := MulEquiv.mk (Equiv.trans (endEquivAutGalois F) MulOpposite.opEquiv) (by simp) lemma endMulEquivAutGalois_pi (f : End F) (A : PointedGaloisObject F) : F.map (AutGalois.π F A (endMulEquivAutGalois F f).unop).hom A.2 = f.app A A.pt := endEquivAutGalois_π F f A /-- Any endomorphism of a fiber functor is a unit. -/ theorem FibreFunctor.end_isUnit (f : End F) : IsUnit f := (isUnit_map_iff (endMulEquivAutGalois F) _).mp (Group.isUnit ((endMulEquivAutGalois F) f)) /-- Any endomorphism of a fiber functor is an isomorphism. -/ instance FibreFunctor.end_isIso (f : End F) : IsIso f := by rw [← isUnit_iff_isIso] exact FibreFunctor.end_isUnit F f /-- The automorphism group of `F` is multiplicatively isomorphic to (the multiplicative opposite of) the limit over the automorphism groups of the Galois objects. -/ noncomputable def autMulEquivAutGalois : Aut F ≃* (AutGalois F)ᵐᵒᵖ where toFun := MonoidHom.comp (endMulEquivAutGalois F) (Aut.toEnd F) invFun t := asIso ((endMulEquivAutGalois F).symm t) left_inv t := by simp only [MonoidHom.coe_comp, MonoidHom.coe_coe, Function.comp_apply, MulEquiv.symm_apply_apply] exact Aut.ext rfl right_inv t := by simp only [MonoidHom.coe_comp, MonoidHom.coe_coe, Function.comp_apply, Aut.toEnd_apply] exact (MulEquiv.eq_symm_apply (endMulEquivAutGalois F)).mp rfl map_mul' := by simp [map_mul] lemma autMulEquivAutGalois_π (f : Aut F) (A : C) [IsGalois A] (a : F.obj A) : F.map (AutGalois.π F { obj := A, pt := a } (autMulEquivAutGalois F f).unop).hom a = f.hom.app A a := by dsimp [autMulEquivAutGalois, endMulEquivAutGalois] rw [endEquivAutGalois_π] rfl @[simp] lemma autMulEquivAutGalois_symm_app (x : AutGalois F) (A : C) [IsGalois A] (a : F.obj A) : ((autMulEquivAutGalois F).symm ⟨x⟩).hom.app A a = F.map (AutGalois.π F ⟨A, a, inferInstance⟩ x).hom a := by rw [← autMulEquivAutGalois_π, MulEquiv.apply_symm_apply] rfl end EndAutGaloisIsomorphism /-- The `Aut F` action on the fiber of a Galois object is transitive. See `pretransitive_of_isConnected` for the same result for connected objects. -/ theorem FiberFunctor.isPretransitive_of_isGalois (X : C) [IsGalois X] : MulAction.IsPretransitive (Aut F) (F.obj X) := by refine ⟨fun x y ↦ ?_⟩ obtain ⟨(φ : Aut X), h⟩ := MulAction.IsPretransitive.exists_smul_eq (M := Aut X) x y obtain ⟨a, ha⟩ := AutGalois.π_surjective F ⟨X, x, inferInstance⟩ φ use (autMulEquivAutGalois F).symm ⟨a⟩ simpa [mulAction_def, ha] /-- The `Aut F` action on the fiber of a connected object is transitive. For a version with less restrictive universe assumptions, see `FiberFunctor.isPretransitive_of_isConnected`. -/ private instance FiberFunctor.isPretransitive_of_isConnected' (X : C) [IsConnected X] : MulAction.IsPretransitive (Aut F) (F.obj X) := by obtain ⟨A, f, hgal⟩ := exists_hom_from_galois_of_connected F X have hs : Function.Surjective (F.map f) := surjective_of_nonempty_fiber_of_isConnected F f refine ⟨fun x y ↦ ?_⟩ obtain ⟨a, ha⟩ := hs x obtain ⟨b, hb⟩ := hs y have : MulAction.IsPretransitive (Aut F) (F.obj A) := isPretransitive_of_isGalois F A obtain ⟨σ, (hσ : σ.hom.app A a = b)⟩ := MulAction.exists_smul_eq (Aut F) a b use σ rw [← ha, ← hb] change (F.map f ≫ σ.hom.app X) a = F.map f b rw [σ.hom.naturality, FintypeCat.comp_apply, hσ] end Specialized section General variable (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] /-- The `Aut F` action on the fiber of a connected object is transitive. -/ instance FiberFunctor.isPretransitive_of_isConnected (X : C) [IsConnected X] : MulAction.IsPretransitive (Aut F) (F.obj X) where exists_smul_eq x y := by let F' : C ⥤ FintypeCat.{u₂} := F ⋙ FintypeCat.uSwitch.{w, u₂} letI : FiberFunctor F' := FiberFunctor.comp_right _ let e (Y : C) : F'.obj Y ≃ F.obj Y := (F.obj Y).uSwitchEquiv set x' : F'.obj X := (e X).symm x with hx' set y' : F'.obj X := (e X).symm y with hy' obtain ⟨g', (hg' : g'.hom.app X x' = y')⟩ := MulAction.exists_smul_eq (Aut F') x' y' let gapp (Y : C) : F.obj Y ≅ F.obj Y := FintypeCat.equivEquivIso <| (e Y).symm.trans <| (FintypeCat.equivEquivIso.symm (g'.app Y)).trans (e Y) let g : F ≅ F := NatIso.ofComponents gapp <| fun {X Y} f ↦ by ext x simp only [FintypeCat.comp_apply, FintypeCat.equivEquivIso_apply_hom, Equiv.trans_apply, FintypeCat.equivEquivIso_symm_apply_apply, Iso.app_hom, gapp, e] erw [FintypeCat.uSwitchEquiv_naturality (F.map f)] rw [← Functor.comp_map, ← FunctorToFintypeCat.naturality] simp only [comp_obj, Functor.comp_map, F'] rw [FintypeCat.uSwitchEquiv_symm_naturality (F.map f)] refine ⟨g, show (gapp X).hom x = y from ?_⟩ simp only [FintypeCat.equivEquivIso_apply_hom, Equiv.trans_apply, FintypeCat.equivEquivIso_symm_apply_apply, Iso.app_hom, gapp] rw [← hx', hg', hy', Equiv.apply_symm_apply] end General end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/EssSurj.lean
import Mathlib.CategoryTheory.Galois.Full import Mathlib.CategoryTheory.Galois.Topology import Mathlib.Topology.Algebra.OpenSubgroup /-! # Essential surjectivity of fiber functors Let `F : C ⥤ FintypeCat` be a fiber functor of a Galois category `C` and denote by `H` the induced functor `C ⥤ Action FintypeCat (Aut F)`. In this file we show that the essential image of `H` consists of the finite `Aut F`-sets where the `Aut F` action is continuous. ## Main results - `exists_lift_of_quotient_openSubgroup`: If `U` is an open subgroup of `Aut F`, then there exists an object `X` such that `F.obj X` is isomorphic to `Aut F ⧸ U` as `Aut F`-sets. - `exists_lift_of_continuous`: If `X` is a finite, discrete `Aut F`-set, then there exists an object `A` such that `F.obj A` is isomorphic to `X` as `Aut F`-sets. ## Strategy We first show that every finite, discrete `Aut F`-set `Y` has a decomposition into connected components and each connected component is of the form `Aut F ⧸ U` for an open subgroup `U`. Since `H` preserves finite coproducts, it hence suffices to treat the case `Y = Aut F ⧸ U`. For the case `Y = Aut F ⧸ U` we closely follow the second part of Stacks Project Tag 0BN4. -/ noncomputable section universe u₁ u₂ namespace CategoryTheory namespace PreGaloisCategory variable {C : Type u₁} [Category.{u₂} C] {F : C ⥤ FintypeCat.{u₁}} open Limits Functor variable [GaloisCategory C] [FiberFunctor F] variable {G : Type*} [Group G] [TopologicalSpace G] [IsTopologicalGroup G] [CompactSpace G] private local instance fintypeQuotient (H : OpenSubgroup (G)) : Fintype (G ⧸ (H : Subgroup (G))) := have : Finite (G ⧸ H.toSubgroup) := H.toSubgroup.quotient_finite_of_isOpen H.isOpen' Fintype.ofFinite _ private local instance fintypeQuotientStabilizer {X : Type*} [MulAction G X] [TopologicalSpace X] [ContinuousSMul G X] [DiscreteTopology X] (x : X) : Fintype (G ⧸ (MulAction.stabilizer (G) x)) := fintypeQuotient ⟨MulAction.stabilizer (G) x, stabilizer_isOpen (G) x⟩ /-- If `X` is a finite discrete `G`-set, it can be written as the finite disjoint union of quotients of the form `G ⧸ Uᵢ` for open subgroups `(Uᵢ)`. Note that this is simply the decomposition into orbits. -/ lemma has_decomp_quotients (X : Action FintypeCat G) [TopologicalSpace X.V] [DiscreteTopology X.V] [ContinuousSMul G X.V] : ∃ (ι : Type) (_ : Finite ι) (f : ι → OpenSubgroup (G)), Nonempty ((∐ fun i ↦ G ⧸ₐ (f i).toSubgroup) ≅ X) := by obtain ⟨ι, hf, f, u, hc⟩ := has_decomp_connected_components' X letI (i : ι) : TopologicalSpace (f i).V := ⊥ haveI (i : ι) : DiscreteTopology (f i).V := ⟨rfl⟩ have (i : ι) : ContinuousSMul G (f i).V := ContinuousSMul.mk <| by let r : f i ⟶ X := Sigma.ι f i ≫ u.hom let r'' (p : G × (f i).V) : G × X.V := (p.1, r.hom p.2) let q (p : G × X.V) : X.V := X.ρ p.1 p.2 let q' (p : G × (f i).V) : (f i).V := (f i).ρ p.1 p.2 have heq : q ∘ r'' = r.hom ∘ q' := by ext (p : G × (f i).V) exact (congr_fun (r.comm p.1) p.2).symm have hrinj : Function.Injective r.hom := (ConcreteCategory.mono_iff_injective_of_preservesPullback r).mp <| mono_comp _ _ let t₁ : TopologicalSpace (G × (f i).V) := inferInstance change @Continuous _ _ _ ⊥ q' have : TopologicalSpace.induced r.hom inferInstance = ⊥ := by rw [← le_bot_iff] exact fun s _ ↦ ⟨r.hom '' s, ⟨isOpen_discrete (r.hom '' s), Set.preimage_image_eq s hrinj⟩⟩ rw [← this, continuous_induced_rng, ← heq] exact Continuous.comp continuous_smul (by fun_prop) have (i : ι) : ∃ (U : OpenSubgroup (G)), (Nonempty ((f i) ≅ G ⧸ₐ U.toSubgroup)) := by obtain ⟨(x : (f i).V)⟩ := nonempty_fiber_of_isConnected (forget₂ _ _) (f i) let U : OpenSubgroup (G) := ⟨MulAction.stabilizer (G) x, stabilizer_isOpen (G) x⟩ letI : Fintype (G ⧸ MulAction.stabilizer (G) x) := fintypeQuotient U exact ⟨U, ⟨FintypeCat.isoQuotientStabilizerOfIsConnected (f i) x⟩⟩ choose g ui using this exact ⟨ι, hf, g, ⟨(Sigma.mapIso (fun i ↦ (ui i).some)).symm ≪≫ u⟩⟩ /-- If `X` is connected and `x` is in the fiber of `X`, `F.obj X` is isomorphic to the quotient of `Aut F` by the stabilizer of `x` as `Aut F`-sets. -/ def fiberIsoQuotientStabilizer (X : C) [IsConnected X] (x : F.obj X) : (functorToAction F).obj X ≅ Aut F ⧸ₐ MulAction.stabilizer (Aut F) x := haveI : IsConnected ((functorToAction F).obj X) := PreservesIsConnected.preserves letI : Fintype (Aut F ⧸ MulAction.stabilizer (Aut F) x) := fintypeQuotientStabilizer x FintypeCat.isoQuotientStabilizerOfIsConnected ((functorToAction F).obj X) x section open Action.FintypeCat variable (V : OpenSubgroup (Aut F)) {U : OpenSubgroup (Aut F)} (h : Subgroup.Normal U.toSubgroup) {A : C} (u : (functorToAction F).obj A ≅ Aut F ⧸ₐ U.toSubgroup) /- ### Strategy outline Let `A` be an object of `C` with fiber `Aut F`-isomorphic to `Aut F ⧸ U` for an open normal subgroup `U`. Then for any open subgroup `V` of `Aut F`, `V ⧸ (U ⊓ V)` acts on `A`. This induces the diagram `quotientDiag`. Now assume `U ≤ V`. Then we can also postcompose the diagram `quotientDiag` with `F`. The goal of this section is to compute that the colimit of this composed diagram is `Aut F ⧸ V`. Finally, we obtain `F.obj (A ⧸ V) ≅ Aut F ⧸ V` as `Aut F`-sets. -/ private def quotientToEndObjectHom : V.toSubgroup ⧸ Subgroup.subgroupOf U.toSubgroup V.toSubgroup →* End A := let ff : (functorToAction F).FullyFaithful := FullyFaithful.ofFullyFaithful (functorToAction F) let e : End A ≃* End (Aut F ⧸ₐ U.toSubgroup) := (ff.mulEquivEnd A).trans (Iso.conj u) e.symm.toMonoidHom.comp (quotientToEndHom V.toSubgroup U.toSubgroup) private lemma functorToAction_map_quotientToEndObjectHom (m : SingleObj.star (V ⧸ Subgroup.subgroupOf U.toSubgroup V.toSubgroup) ⟶ SingleObj.star (V ⧸ Subgroup.subgroupOf U.toSubgroup V.toSubgroup)) : (functorToAction F).map (quotientToEndObjectHom V h u m) = u.hom ≫ quotientToEndHom V.toSubgroup U.toSubgroup m ≫ u.inv := by simp [← cancel_epi u.inv, ← cancel_mono u.hom, ← Iso.conj_apply, quotientToEndObjectHom] @[simps!] private def quotientDiag : SingleObj (V.toSubgroup ⧸ Subgroup.subgroupOf U V) ⥤ C := SingleObj.functor (quotientToEndObjectHom V h u) variable {V} (hUinV : U ≤ V) @[simps] private def coconeQuotientDiag : Cocone (quotientDiag V h u ⋙ functorToAction F) where pt := Aut F ⧸ₐ V.toSubgroup ι := SingleObj.natTrans (u.hom ≫ quotientToQuotientOfLE V.toSubgroup U.toSubgroup hUinV) <| by intro (m : V ⧸ Subgroup.subgroupOf U V) simp only [const_obj_obj, Functor.comp_map, const_obj_map, Category.comp_id] rw [← cancel_epi (u.inv), Iso.inv_hom_id_assoc] apply Action.hom_ext ext (x : Aut F ⧸ U.toSubgroup) induction m, x using Quotient.inductionOn₂ with | _ σ μ suffices h : ⟦μ * σ⁻¹⟧ = ⟦μ⟧ by simp only [quotientToQuotientOfLE_hom_mk, quotientDiag_map, functorToAction_map_quotientToEndObjectHom V _ u] simpa apply Quotient.sound apply (QuotientGroup.leftRel_apply).mpr simp @[simps] private def coconeQuotientDiagDesc (s : Cocone (quotientDiag V h u ⋙ functorToAction F)) : (coconeQuotientDiag h u hUinV).pt ⟶ s.pt where hom := Quotient.lift (fun σ ↦ (u.inv ≫ s.ι.app (SingleObj.star _)).hom ⟦σ⟧) <| fun σ τ hst ↦ by let J' := quotientDiag V h u ⋙ functorToAction F let m : End (SingleObj.star (V.toSubgroup ⧸ Subgroup.subgroupOf U V)) := ⟦⟨σ⁻¹ * τ, (QuotientGroup.leftRel_apply).mp hst⟩⟧ have h1 : J'.map m ≫ s.ι.app (SingleObj.star _) = s.ι.app (SingleObj.star _) := s.ι.naturality m conv_rhs => rw [← h1] have h2 : (J'.map m).hom (u.inv.hom ⟦τ⟧) = u.inv.hom ⟦σ⟧ := by simp only [comp_obj, quotientDiag_obj, Functor.comp_map, quotientDiag_map, J', functorToAction_map_quotientToEndObjectHom V h u m] change (u.inv ≫ u.hom ≫ _ ≫ u.inv).hom ⟦τ⟧ = u.inv.hom ⟦σ⟧ simp [m] simp only [← h2, const_obj_obj, Action.comp_hom, FintypeCat.comp_apply] comm g := by ext (x : Aut F ⧸ V.toSubgroup) induction x using Quotient.inductionOn with | _ σ simp only [const_obj_obj] change (((Aut F ⧸ₐ U.toSubgroup).ρ g ≫ u.inv.hom) ≫ (s.ι.app (SingleObj.star _)).hom) ⟦σ⟧ = ((s.ι.app (SingleObj.star _)).hom ≫ s.pt.ρ g) (u.inv.hom ⟦σ⟧) have : ((functorToAction F).obj A).ρ g ≫ (s.ι.app (SingleObj.star _)).hom = (s.ι.app (SingleObj.star _)).hom ≫ s.pt.ρ g := (s.ι.app (SingleObj.star _)).comm g rw [← this, u.inv.comm g] rfl /-- The constructed cocone `coconeQuotientDiag` on the diagram `quotientDiag` is colimiting. -/ private def coconeQuotientDiagIsColimit : IsColimit (coconeQuotientDiag h u hUinV) where desc := coconeQuotientDiagDesc h u hUinV fac s j := by apply (cancel_epi u.inv).mp apply Action.hom_ext ext (x : Aut F ⧸ U.toSubgroup) induction x using Quotient.inductionOn simp rfl uniq s f hf := by apply Action.hom_ext ext (x : Aut F ⧸ V.toSubgroup) induction x using Quotient.inductionOn simp [← hf (SingleObj.star _)] end /-- For every open subgroup `V` of `Aut F`, there exists an `X : C` such that `F.obj X ≅ Aut F ⧸ V` as `Aut F`-sets. -/ lemma exists_lift_of_quotient_openSubgroup (V : OpenSubgroup (Aut F)) : ∃ (X : C), Nonempty ((functorToAction F).obj X ≅ Aut F ⧸ₐ V.toSubgroup) := by obtain ⟨I, hf, hc, hi⟩ := exists_set_ker_evaluation_subset_of_isOpen F (one_mem V) V.isOpen' haveI (X : I) : IsConnected X.val := hc X X.property haveI (X : I) : Nonempty (F.obj X.val) := nonempty_fiber_of_isConnected F X have hn : Nonempty (F.obj <| (∏ᶜ fun X : I => X)) := nonempty_fiber_pi_of_nonempty_of_finite F _ obtain ⟨A, f, hgal⟩ := exists_hom_from_galois_of_fiber_nonempty F (∏ᶜ fun X : I => X) hn obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A let U : OpenSubgroup (Aut F) := ⟨MulAction.stabilizer (Aut F) a, stabilizer_isOpen (Aut F) a⟩ let u := fiberIsoQuotientStabilizer A a have hUnormal : U.toSubgroup.Normal := stabilizer_normal_of_isGalois F A a have h1 (σ : Aut F) (σinU : σ ∈ U) : σ.hom.app A = 𝟙 (F.obj A) := by have hi : (Aut F ⧸ₐ MulAction.stabilizer (Aut F) a).ρ σ = 𝟙 _ := by refine FintypeCat.hom_ext _ _ (fun x ↦ ?_) induction x using Quotient.inductionOn with | _ τ change ⟦σ * τ⟧ = ⟦τ⟧ apply Quotient.sound apply (QuotientGroup.leftRel_apply).mpr simp only [mul_inv_rev] exact Subgroup.Normal.conj_mem hUnormal _ (Subgroup.inv_mem U.toSubgroup σinU) _ simp [← cancel_mono u.hom.hom, show σ.hom.app A ≫ u.hom.hom = _ from u.hom.comm σ, hi] have h2 (σ : Aut F) (σinU : σ ∈ U) : ∀ X : I, σ.hom.app X = 𝟙 (F.obj X) := by intro ⟨X, hX⟩ ext (x : F.obj X) let p : A ⟶ X := f ≫ Pi.π (fun Z : I => (Z : C)) ⟨X, hX⟩ have : IsConnected X := hc X hX obtain ⟨a, rfl⟩ := surjective_of_nonempty_fiber_of_isConnected F p x simp only [FintypeCat.id_apply, FunctorToFintypeCat.naturality, h1 σ σinU] have hUinV : (U : Set (Aut F)) ≤ V := fun u uinU ↦ hi u (h2 u uinU) have := V.quotient_finite_of_isOpen' (U.subgroupOf V) V.isOpen (V.subgroupOf_isOpen U U.isOpen) exact ⟨colimit (quotientDiag V hUnormal u), ⟨preservesColimitIso (functorToAction F) (quotientDiag V hUnormal u) ≪≫ colimit.isoColimitCocone ⟨coconeQuotientDiag hUnormal u hUinV, coconeQuotientDiagIsColimit hUnormal u hUinV⟩⟩⟩ /-- If `X` is a finite, discrete `Aut F`-set with continuous `Aut F`-action, then there exists `A : C` such that `F.obj A ≅ X` as `Aut F`-sets. -/ @[stacks 0BN4 "Essential surjectivity part"] theorem exists_lift_of_continuous (X : Action FintypeCat (Aut F)) [TopologicalSpace X.V] [DiscreteTopology X.V] [ContinuousSMul (Aut F) X.V] : ∃ A, Nonempty ((functorToAction F).obj A ≅ X) := by obtain ⟨ι, hfin, f, ⟨u⟩⟩ := has_decomp_quotients X choose g gu using (fun i ↦ exists_lift_of_quotient_openSubgroup (f i)) exact ⟨∐ g, ⟨PreservesCoproduct.iso (functorToAction F) g ≪≫ Sigma.mapIso (fun i ↦ (gu i).some) ≪≫ u⟩⟩ end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Action.lean
import Mathlib.CategoryTheory.Galois.Examples import Mathlib.CategoryTheory.Galois.Prorepresentability /-! # Induced functor to finite `Aut F`-sets Any (fiber) functor `F : C ⥤ FintypeCat` factors via the forgetful functor from finite `Aut F`-sets to finite sets. In this file we collect basic properties of the induced functor `H : C ⥤ Action FintypeCat (Aut F)`. See `Mathlib/CategoryTheory/Galois/Full.lean` for the proof that `H` is (faithfully) full. -/ universe u namespace CategoryTheory namespace PreGaloisCategory open Limits Functor variable {C : Type*} [Category C] (F : C ⥤ FintypeCat.{u}) /-- Any (fiber) functor `F : C ⥤ FintypeCat` naturally factors via the forgetful functor from `Action FintypeCat (Aut F)` to `FintypeCat`. -/ def functorToAction : C ⥤ Action FintypeCat.{u} (Aut F) where obj X := Action.FintypeCat.ofMulAction (Aut F) (F.obj X) map f := { hom := F.map f comm := fun g ↦ symm <| g.hom.naturality f } lemma functorToAction_comp_forget₂_eq : functorToAction F ⋙ forget₂ _ FintypeCat = F := rfl @[simp] lemma functorToAction_map {X Y : C} (f : X ⟶ Y) : ((functorToAction F).map f).hom = F.map f := rfl instance (X : C) : MulAction (Aut X) ((functorToAction F).obj X).V := inferInstanceAs <| MulAction (Aut X) (F.obj X) variable [GaloisCategory C] [FiberFunctor F] instance (X : C) [IsGalois X] : MulAction.IsPretransitive (Aut X) ((functorToAction F).obj X).V := isPretransitive_of_isGalois F X instance : Functor.Faithful (functorToAction F) := have : Functor.Faithful (functorToAction F ⋙ forget₂ _ FintypeCat) := inferInstanceAs <| Functor.Faithful F Functor.Faithful.of_comp (functorToAction F) (forget₂ _ FintypeCat) instance : PreservesMonomorphisms (functorToAction F) := have : PreservesMonomorphisms (functorToAction F ⋙ forget₂ _ FintypeCat) := inferInstanceAs <| PreservesMonomorphisms F preservesMonomorphisms_of_preserves_of_reflects (functorToAction F) (forget₂ _ FintypeCat) instance : ReflectsMonomorphisms (functorToAction F) := reflectsMonomorphisms_of_faithful _ instance : Functor.ReflectsIsomorphisms (functorToAction F) where reflects f _ := have : IsIso (F.map f) := (forget₂ _ FintypeCat).map_isIso ((functorToAction F).map f) isIso_of_reflects_iso f F noncomputable instance : PreservesFiniteCoproducts (functorToAction F) := ⟨fun _ ↦ Action.preservesColimitsOfShape_of_preserves (functorToAction F) (inferInstanceAs <| PreservesColimitsOfShape (Discrete _) F)⟩ noncomputable instance : PreservesFiniteProducts (functorToAction F) := ⟨fun _ ↦ Action.preservesLimitsOfShape_of_preserves (functorToAction F) (inferInstanceAs <| PreservesLimitsOfShape (Discrete _) F)⟩ noncomputable instance (G : Type*) [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) (functorToAction F) := Action.preservesColimitsOfShape_of_preserves _ <| inferInstanceAs <| PreservesColimitsOfShape (SingleObj G) F instance : PreservesIsConnected (functorToAction F) := ⟨fun {X} _ ↦ FintypeCat.Action.isConnected_of_transitive (Aut F) (F.obj X)⟩ end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/IsFundamentalgroup.lean
import Mathlib.CategoryTheory.Galois.Basic import Mathlib.CategoryTheory.Galois.Topology import Mathlib.CategoryTheory.Galois.Prorepresentability import Mathlib.Topology.Algebra.OpenSubgroup /-! # Universal property of fundamental group Let `C` be a Galois category with fiber functor `F`. While in informal mathematics, we tend to identify known groups from other contexts (e.g. the absolute Galois group of a field) with the automorphism group `Aut F` of certain fiber functors `F`, this causes friction in formalization. Hence, in this file we develop conditions when a topological group `G` is canonically isomorphic to the automorphism group `Aut F` of `F`. Consequently, the API for Galois categories and their fiber functors should be stated in terms of an abstract topological group `G` satisfying `IsFundamentalGroup` in the places where `Aut F` would appear. ## Main definition Given a compact, topological group `G` with an action on `F.obj X` on each `X`, we say that `G` is a fundamental group of `F` (`IsFundamentalGroup F G`), if - `naturality`: the `G`-action on `F.obj X` is compatible with morphisms in `C` - `transitive_of_isGalois`: `G` acts transitively on `F.obj X` for all Galois objects `X : C` - `continuous_smul`: the action of `G` on `F.obj X` is continuous if `F.obj X` is equipped with the discrete topology for all `X : C`. - `non_trivial'`: if `g : G` acts trivially on all `F.obj X`, then `g = 1`. Given this data, we define `toAut F G : G →* Aut F` in the natural way. ## Main results - `toAut_bijective`: `toAut F G` is a group isomorphism given `IsFundamentalGroup F G`. - `toAut_isHomeomorph`: `toAut F G` is a homeomorphism given `IsFundamentalGroup F G`. ## TODO - Develop further equivalent conditions, in particular, relate the condition `non_trivial` with `G` being a `T2Space`. -/ universe u₁ u₂ w namespace CategoryTheory namespace PreGaloisCategory open Limits Functor variable {C : Type u₁} [Category.{u₂} C] (F : C ⥤ FintypeCat.{w}) section variable (G : Type*) [Group G] [∀ X, MulAction G (F.obj X)] /-- We say `G` acts naturally on the fibers of `F` if for every `f : X ⟶ Y`, the `G`-actions on `F.obj X` and `F.obj Y` are compatible with `F.map f`. -/ class IsNaturalSMul : Prop where naturality (g : G) {X Y : C} (f : X ⟶ Y) (x : F.obj X) : F.map f (g • x) = g • F.map f x variable {G} in @[simps!] private def isoOnObj (g : G) (X : C) : F.obj X ≅ F.obj X := FintypeCat.equivEquivIso <| { toFun := fun x ↦ g • x invFun := fun x ↦ g⁻¹ • x left_inv := fun _ ↦ by simp right_inv := fun _ ↦ by simp } variable [IsNaturalSMul F G] /-- If `G` acts naturally on `F.obj X` for each `X : C`, this is the canonical group homomorphism into the automorphism group of `F`. -/ def toAut : G →* Aut F where toFun g := NatIso.ofComponents (isoOnObj F g) <| by intro X Y f ext simp [IsNaturalSMul.naturality] map_one' := by ext simp only [NatIso.ofComponents_hom_app, isoOnObj_hom, one_smul] rfl map_mul' := by intro g h ext X x simp only [NatIso.ofComponents_hom_app, isoOnObj_hom, mul_smul] rfl variable {G} in @[simp] lemma toAut_hom_app_apply (g : G) {X : C} (x : F.obj X) : (toAut F G g).hom.app X x = g • x := rfl /-- `toAut` is injective, if only the identity acts trivially on every fiber. -/ lemma toAut_injective_of_non_trivial (h : ∀ (g : G), (∀ (X : C) (x : F.obj X), g • x = x) → g = 1) : Function.Injective (toAut F G) := by rw [← MonoidHom.ker_eq_bot_iff, eq_bot_iff] intro g (hg : toAut F G g = 1) refine h g (fun X x ↦ ?_) have : (toAut F G g).hom.app X = 𝟙 (F.obj X) := by rw [hg] rfl rw [← toAut_hom_app_apply, this, FintypeCat.id_apply] variable [GaloisCategory C] [FiberFunctor F] lemma toAut_continuous [TopologicalSpace G] [IsTopologicalGroup G] [∀ (X : C), ContinuousSMul G (F.obj X)] : Continuous (toAut F G) := by apply continuous_of_continuousAt_one rw [continuousAt_def, map_one] intro A hA obtain ⟨X, _, hX⟩ := ((nhds_one_has_basis_stabilizers F).mem_iff' A).mp hA rw [mem_nhds_iff] exact ⟨MulAction.stabilizer G X.pt, Set.preimage_mono (f := toAut F G) hX, stabilizer_isOpen G X.pt, one_mem _⟩ variable {G} lemma action_ext_of_isGalois {t : F ⟶ F} {X : C} [IsGalois X] {g : G} (x : F.obj X) (hg : g • x = t.app X x) (y : F.obj X) : g • y = t.app X y := by obtain ⟨φ, (rfl : F.map φ.hom y = x)⟩ := MulAction.exists_smul_eq (Aut X) y x have : Function.Injective (F.map φ.hom) := ConcreteCategory.injective_of_mono_of_preservesPullback (F.map φ.hom) apply this rw [IsNaturalSMul.naturality, hg, FunctorToFintypeCat.naturality] variable (G) lemma toAut_surjective_isGalois (t : Aut F) (X : C) [IsGalois X] [MulAction.IsPretransitive G (F.obj X)] : ∃ (g : G), ∀ (x : F.obj X), g • x = t.hom.app X x := by obtain ⟨a⟩ := nonempty_fiber_of_isConnected F X obtain ⟨g, hg⟩ := MulAction.exists_smul_eq G a (t.hom.app X a) exact ⟨g, action_ext_of_isGalois F _ hg⟩ lemma toAut_surjective_isGalois_finite_family (t : Aut F) {ι : Type*} [Finite ι] (X : ι → C) [∀ i, IsGalois (X i)] (h : ∀ (X : C) [IsGalois X], MulAction.IsPretransitive G (F.obj X)) : ∃ (g : G), ∀ (i : ι) (x : F.obj (X i)), g • x = t.hom.app (X i) x := by let x (i : ι) : F.obj (X i) := (nonempty_fiber_of_isConnected F (X i)).some let P : C := ∏ᶜ X letI : Fintype ι := Fintype.ofFinite ι let is₁ : F.obj P ≅ ∏ᶜ fun i ↦ (F.obj (X i)) := PreservesProduct.iso F X let is₂ : (∏ᶜ fun i ↦ F.obj (X i) : FintypeCat) ≃ ∀ i, F.obj (X i) := Limits.FintypeCat.productEquiv (fun i ↦ (F.obj (X i))) let px : F.obj P := is₁.inv (is₂.symm x) have hpx (i : ι) : F.map (Pi.π X i) px = x i := by simp only [px, is₁, is₂, ← piComparison_comp_π, ← PreservesProduct.iso_hom] simp only [FintypeCat.comp_apply, FintypeCat.inv_hom_id_apply, FintypeCat.productEquiv_symm_comp_π_apply] obtain ⟨A, f, a, _, hfa⟩ := exists_hom_from_galois_of_fiber F P px obtain ⟨g, hg⟩ := toAut_surjective_isGalois F G t A refine ⟨g, fun i y ↦ action_ext_of_isGalois F (x i) ?_ _⟩ rw [← hpx i, ← IsNaturalSMul.naturality, FunctorToFintypeCat.naturality, ← hfa, FunctorToFintypeCat.naturality, ← IsNaturalSMul.naturality, hg] open Pointwise /-- If `G` is a compact, topological group that acts continuously and naturally on the fibers of `F`, `toAut F G` is surjective if and only if it acts transitively on the fibers of all Galois objects. This is the `if` direction. For the `only if` see `isPretransitive_of_surjective`. -/ lemma toAut_surjective_of_isPretransitive [TopologicalSpace G] [IsTopologicalGroup G] [CompactSpace G] [∀ (X : C), ContinuousSMul G (F.obj X)] (h : ∀ (X : C) [IsGalois X], MulAction.IsPretransitive G (F.obj X)) : Function.Surjective (toAut F G) := by intro t choose gi hgi using (fun X : PointedGaloisObject F ↦ toAut_surjective_isGalois F G t X) let cl (X : PointedGaloisObject F) : Set G := gi X • MulAction.stabilizer G X.pt let c : Set G := ⋂ i, cl i have hne : c.Nonempty := by rw [← Set.univ_inter c] apply CompactSpace.isCompact_univ.inter_iInter_nonempty · intro X apply IsClosed.leftCoset exact Subgroup.isClosed_of_isOpen _ (stabilizer_isOpen G X.pt) · intro s rw [Set.univ_inter] obtain ⟨gs, hgs⟩ := toAut_surjective_isGalois_finite_family F G t (fun X : s ↦ X.val.obj) h use gs simp only [Set.mem_iInter] intro X hXmem rw [mem_leftCoset_iff, SetLike.mem_coe, MulAction.mem_stabilizer_iff, mul_smul, hgs ⟨X, hXmem⟩, ← hgi X, inv_smul_smul] obtain ⟨g, hg⟩ := hne refine ⟨g, Iso.ext <| natTrans_ext_of_isGalois _ <| fun X _ ↦ ?_⟩ ext x simp only [toAut_hom_app_apply] have : g ∈ (gi ⟨X, x, inferInstance⟩ • MulAction.stabilizer G x : Set G) := by simp only [Set.mem_iInter, c] at hg exact hg _ obtain ⟨s, (hsmem : s • x = x), (rfl : gi ⟨X, x, inferInstance⟩ • s = _)⟩ := this rw [smul_eq_mul, mul_smul, hsmem] exact hgi ⟨X, x, inferInstance⟩ x /-- If `toAut F G` is surjective, then `G` acts transitively on the fibers of connected objects. For a converse see `toAut_surjective`. -/ lemma isPretransitive_of_surjective (h : Function.Surjective (toAut F G)) (X : C) [IsConnected X] : MulAction.IsPretransitive G (F.obj X) where exists_smul_eq x y := by obtain ⟨t, ht⟩ := MulAction.exists_smul_eq (Aut F) x y obtain ⟨g, rfl⟩ := h t exact ⟨g, ht⟩ end section variable [GaloisCategory C] variable (G : Type*) [Group G] [∀ (X : C), MulAction G (F.obj X)] /-- A compact, topological group `G` with a natural action on `F.obj X` for each `X : C` is a fundamental group of `F`, if `G` acts transitively on the fibers of Galois objects, the action on `F.obj X` is continuous for all `X : C` and the only trivially acting element of `G` is the identity. -/ class IsFundamentalGroup [TopologicalSpace G] [IsTopologicalGroup G] [CompactSpace G] : Prop extends IsNaturalSMul F G where transitive_of_isGalois (X : C) [IsGalois X] : MulAction.IsPretransitive G (F.obj X) continuous_smul (X : C) : ContinuousSMul G (F.obj X) non_trivial' (g : G) : (∀ (X : C) (x : F.obj X), g • x = x) → g = 1 namespace IsFundamentalGroup attribute [instance] continuous_smul transitive_of_isGalois variable {G} [TopologicalSpace G] [IsTopologicalGroup G] [CompactSpace G] [IsFundamentalGroup F G] lemma non_trivial (g : G) (h : ∀ (X : C) (x : F.obj X), g • x = x) : g = 1 := IsFundamentalGroup.non_trivial' g h end IsFundamentalGroup variable [FiberFunctor F] /-- `Aut F` is a fundamental group for `F`. -/ instance : IsFundamentalGroup F (Aut F) where naturality g _ _ f x := (FunctorToFintypeCat.naturality F F g.hom f x).symm transitive_of_isGalois X := FiberFunctor.isPretransitive_of_isConnected F X continuous_smul X := continuousSMul_aut_fiber F X non_trivial' g h := by ext X x exact h X x variable [TopologicalSpace G] [IsTopologicalGroup G] [CompactSpace G] [IsFundamentalGroup F G] lemma toAut_bijective : Function.Bijective (toAut F G) where left := toAut_injective_of_non_trivial F G IsFundamentalGroup.non_trivial' right := toAut_surjective_of_isPretransitive F G IsFundamentalGroup.transitive_of_isGalois instance (X : C) [IsConnected X] : MulAction.IsPretransitive G (F.obj X) := isPretransitive_of_surjective F G (toAut_bijective F G).surjective X /-- If `G` is the fundamental group for `F`, it is isomorphic to `Aut F` as groups and this isomorphism is also a homeomorphism (see `toAutMulEquiv_isHomeomorph`). -/ noncomputable def toAutMulEquiv : G ≃* Aut F := MulEquiv.ofBijective (toAut F G) (toAut_bijective F G) lemma toAut_isHomeomorph : IsHomeomorph (toAut F G) := by rw [isHomeomorph_iff_continuous_bijective] exact ⟨toAut_continuous F G, toAut_bijective F G⟩ lemma toAutMulEquiv_isHomeomorph : IsHomeomorph (toAutMulEquiv F G) := toAut_isHomeomorph F G /-- If `G` is a fundamental group for `F`, it is canonically homeomorphic to `Aut F`. -/ noncomputable def toAutHomeo : G ≃ₜ Aut F := (toAut_isHomeomorph F G).homeomorph variable {G} @[simp] lemma toAutMulEquiv_apply (g : G) : toAutMulEquiv F G g = toAut F G g := rfl @[simp] lemma toAutHomeo_apply (g : G) : toAutHomeo F G g = toAut F G g := rfl end end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Examples.lean
import Mathlib.CategoryTheory.Galois.Basic import Mathlib.CategoryTheory.Action.Concrete import Mathlib.CategoryTheory.Action.Limits /-! # Examples of Galois categories and fiber functors We show that for a group `G` the category of finite `G`-sets is a `PreGaloisCategory` and that the forgetful functor to `FintypeCat` is a `FiberFunctor`. The connected finite `G`-sets are precisely the ones with transitive `G`-action. -/ universe u v w namespace CategoryTheory open Limits Functor PreGaloisCategory namespace FintypeCat /-- Complement of the image of a morphism `f : X ⟶ Y` in `FintypeCat`. -/ noncomputable def imageComplement {X Y : FintypeCat.{u}} (f : X ⟶ Y) : FintypeCat.{u} := by haveI : Fintype (↑(Set.range f)ᶜ) := Fintype.ofFinite _ exact FintypeCat.of (↑(Set.range f)ᶜ) /-- The inclusion from the complement of the image of `f : X ⟶ Y` into `Y`. -/ def imageComplementIncl {X Y : FintypeCat.{u}} (f : X ⟶ Y) : imageComplement f ⟶ Y := Subtype.val variable (G : Type u) [Group G] /-- Given `f : X ⟶ Y` for `X Y : Action FintypeCat G`, the complement of the image of `f` has a natural `G`-action. -/ noncomputable def Action.imageComplement {X Y : Action FintypeCat G} (f : X ⟶ Y) : Action FintypeCat G where V := FintypeCat.imageComplement f.hom ρ := { toFun := fun g y ↦ Subtype.mk (Y.ρ g y.val) <| by intro ⟨x, h⟩ apply y.property use X.ρ g⁻¹ x calc (X.ρ g⁻¹ ≫ f.hom) x = (Y.ρ g⁻¹ * Y.ρ g) y.val := by rw [f.comm, FintypeCat.comp_apply, h]; rfl _ = y.val := by rw [← map_mul, inv_mul_cancel, Action.ρ_one, FintypeCat.id_apply] map_one' := by simp only [map_one, End.one_def, FintypeCat.id_apply, Subtype.coe_eta]; rfl map_mul' := by intro g h congr! 1 with ⟨x, hx⟩ apply Subtype.ext simp only [map_mul, End.mul_def, FintypeCat.comp_apply] rfl } /-- The inclusion from the complement of the image of `f : X ⟶ Y` into `Y`. -/ noncomputable def Action.imageComplementIncl {X Y : Action FintypeCat G} (f : X ⟶ Y) : Action.imageComplement G f ⟶ Y where hom := FintypeCat.imageComplementIncl f.hom comm _ := rfl attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance {X Y : Action FintypeCat G} (f : X ⟶ Y) : Mono (Action.imageComplementIncl G f) := by apply Functor.mono_of_mono_map (forget _) apply ConcreteCategory.mono_of_injective exact Subtype.val_injective /-- The category of finite sets has quotients by finite groups in arbitrary universes. -/ instance [Finite G] : HasColimitsOfShape (SingleObj G) FintypeCat.{w} := by obtain ⟨G', hg, hf, ⟨e⟩⟩ := Finite.exists_type_univ_nonempty_mulEquiv G exact Limits.hasColimitsOfShape_of_equivalence e.toSingleObjEquiv.symm noncomputable instance : PreservesFiniteLimits (forget (Action FintypeCat G)) := by change PreservesFiniteLimits (Action.forget FintypeCat _ ⋙ FintypeCat.incl) apply comp_preservesFiniteLimits /-- The category of finite `G`-sets is a `PreGaloisCategory`. -/ instance : PreGaloisCategory (Action FintypeCat G) where hasQuotientsByFiniteGroups _ _ _ := inferInstance monoInducesIsoOnDirectSummand {_ _} i _ := ⟨Action.imageComplement G i, Action.imageComplementIncl G i, ⟨isColimitOfReflects (Action.forget _ _ ⋙ FintypeCat.incl) <| (isColimitMapCoconeBinaryCofanEquiv (forget _) i _).symm (Types.isCoprodOfMono ((forget _).map i))⟩⟩ /-- The forgetful functor from finite `G`-sets to sets is a `FiberFunctor`. -/ noncomputable instance : FiberFunctor (Action.forget FintypeCat G) where preservesFiniteCoproducts := ⟨fun _ ↦ inferInstance⟩ preservesQuotientsByFiniteGroups _ _ _ := inferInstance reflectsIsos := ⟨fun f (_ : IsIso f.hom) => inferInstance⟩ /-- The forgetful functor from finite `G`-sets to sets is a `FiberFunctor`. -/ noncomputable instance : FiberFunctor (forget₂ (Action FintypeCat G) FintypeCat) := inferInstanceAs <| FiberFunctor (Action.forget FintypeCat G) /-- The category of finite `G`-sets is a `GaloisCategory`. -/ instance : GaloisCategory (Action FintypeCat G) where hasFiberFunctor := ⟨Action.forget FintypeCat G, ⟨inferInstance⟩⟩ /-- The `G`-action on a connected finite `G`-set is transitive. -/ theorem Action.pretransitive_of_isConnected (X : Action FintypeCat G) [IsConnected X] : MulAction.IsPretransitive G X.V where exists_smul_eq x y := by /- We show that the `G`-orbit of `x` is a non-initial subobject of `X` and hence by connectedness, the orbit equals `X.V`. -/ let T : Set X.V := MulAction.orbit G x have : Fintype T := Fintype.ofFinite T letI : MulAction G (FintypeCat.of T) := inferInstanceAs <| MulAction G ↑(MulAction.orbit G x) let T' : Action FintypeCat G := Action.FintypeCat.ofMulAction G (FintypeCat.of T) let i : T' ⟶ X := ⟨Subtype.val, fun _ ↦ rfl⟩ have : Mono i := ConcreteCategory.mono_of_injective _ (Subtype.val_injective) have : IsIso i := by apply IsConnected.noTrivialComponent T' i apply (not_initial_iff_fiber_nonempty (Action.forget _ _) T').mpr exact Set.Nonempty.coe_sort (MulAction.nonempty_orbit x) have hb : Function.Bijective i.hom := by apply (ConcreteCategory.isIso_iff_bijective i.hom).mp exact map_isIso (forget₂ _ FintypeCat) i obtain ⟨⟨y', ⟨g, (hg : g • x = y')⟩⟩, (hy' : y' = y)⟩ := hb.surjective y use g exact hg.trans hy' /-- A nonempty `G`-set with transitive `G`-action is connected. -/ theorem Action.isConnected_of_transitive (X : FintypeCat) [MulAction G X] [MulAction.IsPretransitive G X] [h : Nonempty X] : IsConnected (Action.FintypeCat.ofMulAction G X) where notInitial := not_initial_of_inhabited (Action.forget _ _) h.some noTrivialComponent Y i hm hni := by /- We show that the induced inclusion `i.hom` of finite sets is surjective, using the transitivity of the `G`-action. -/ obtain ⟨(y : Y.V)⟩ := (not_initial_iff_fiber_nonempty (Action.forget _ _) Y).mp hni have : IsIso i.hom := by refine (ConcreteCategory.isIso_iff_bijective i.hom).mpr ⟨?_, fun x' ↦ ?_⟩ · haveI : Mono i.hom := map_mono (forget₂ _ _) i exact ConcreteCategory.injective_of_mono_of_preservesPullback i.hom · letI x : X := i.hom y obtain ⟨σ, hσ⟩ := MulAction.exists_smul_eq G x x' use σ • y change (Y.ρ σ ≫ i.hom) y = x' rw [i.comm, FintypeCat.comp_apply] exact hσ apply isIso_of_reflects_iso i (Action.forget _ _) /-- A nonempty finite `G`-set is connected if and only if the `G`-action is transitive. -/ theorem Action.isConnected_iff_transitive (X : Action FintypeCat G) [Nonempty X.V] : IsConnected X ↔ MulAction.IsPretransitive G X.V := ⟨fun _ ↦ pretransitive_of_isConnected G X, fun _ ↦ isConnected_of_transitive G X.V⟩ variable {G} /-- If `X` is a connected `G`-set and `x` is an element of `X`, `X` is isomorphic to the quotient of `G` by the stabilizer of `x` as `G`-sets. -/ noncomputable def isoQuotientStabilizerOfIsConnected (X : Action FintypeCat G) [IsConnected X] (x : X.V) [Fintype (G ⧸ (MulAction.stabilizer G x))] : X ≅ G ⧸ₐ MulAction.stabilizer G x := haveI : MulAction.IsPretransitive G X.V := Action.pretransitive_of_isConnected G X let e : X.V ≃ G ⧸ MulAction.stabilizer G x := (Equiv.Set.univ X.V).symm.trans <| (Equiv.setCongr ((MulAction.orbit_eq_univ G x).symm)).trans <| MulAction.orbitEquivQuotientStabilizer G x Iso.symm <| Action.mkIso (FintypeCat.equivEquivIso e.symm) <| fun σ : G ↦ by ext (a : G ⧸ MulAction.stabilizer G x) obtain ⟨τ, rfl⟩ := Quotient.exists_rep a exact mul_smul σ τ x end FintypeCat end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/Equivalence.lean
import Mathlib.CategoryTheory.Galois.EssSurj import Mathlib.CategoryTheory.Action.Continuous import Mathlib.Topology.Category.FinTopCat /-! # Fiber functors induce an equivalence of categories Let `C` be a Galois category with fiber functor `F`. In this file we conclude that the induced functor from `C` to the category of finite, discrete `Aut F`-sets is an equivalence of categories. -/ universe u₂ u₁ w open CategoryTheory namespace CategoryTheory variable {C : Type u₁} [Category.{u₂} C] {F : C ⥤ FintypeCat.{w}} namespace PreGaloisCategory variable [GaloisCategory C] [FiberFunctor F] open scoped FintypeCatDiscrete variable (F) in /-- The induced functor from `C` to the category of finite, discrete `Aut F`-sets. -/ @[simps! obj_obj map] def functorToContAction : C ⥤ ContAction FintypeCat (Aut F) := ObjectProperty.lift _ (functorToAction F) (fun X ↦ continuousSMul_aut_fiber F X) instance : (functorToContAction F).Faithful := inferInstanceAs <| (ObjectProperty.lift _ _ _).Faithful instance : (functorToContAction F).Full := inferInstanceAs <| (ObjectProperty.lift _ _ _).Full instance {F : C ⥤ FintypeCat.{u₁}} [FiberFunctor F] : (functorToContAction F).EssSurj where mem_essImage X := by have : ContinuousSMul (Aut F) X.obj.V.carrier := X.2 obtain ⟨A, ⟨i⟩⟩ := exists_lift_of_continuous (F := F) X exact ⟨A, ⟨ObjectProperty.isoMk _ i⟩⟩ instance : (functorToContAction F).EssSurj := by let F' : C ⥤ FintypeCat.{u₁} := F ⋙ FintypeCat.uSwitch.{w, u₁} letI : FiberFunctor F' := FiberFunctor.comp_right _ have : (functorToContAction F').EssSurj := inferInstance let f : Aut F ≃ₜ* Aut F' := (autEquivAutWhiskerRight F (FintypeCat.uSwitchEquivalence.{w, u₁}).fullyFaithfulFunctor) let equiv : ContAction FintypeCat.{u₁} (Aut F') ≌ ContAction FintypeCat.{w} (Aut F) := (FintypeCat.uSwitchEquivalence.{u₁, w}.mapContAction (Aut F') (fun X ↦ by rw [Action.isContinuous_def] change Continuous ((fun p ↦ (FintypeCat.uSwitchEquiv X.obj.V).symm p) ∘ (fun p : Aut F' × _ ↦ (X.obj.ρ p.1) p.2) ∘ (fun p : Aut F' × _ ↦ (p.1, FintypeCat.uSwitchEquiv _ p.2))) have : Continuous (fun p : Aut F' × _ ↦ (X.obj.ρ p.1) p.2) := X.2.1 fun_prop) (fun X ↦ by rw [Action.isContinuous_def] change Continuous ((fun p ↦ (FintypeCat.uSwitchEquiv X.obj.V).symm p) ∘ (fun p : Aut F' × _ ↦ (X.obj.ρ p.1) p.2) ∘ (fun p : Aut F' × _ ↦ (p.1, FintypeCat.uSwitchEquiv _ p.2))) have : Continuous (fun p : Aut F' × _ ↦ (X.obj.ρ p.1) p.2) := X.2.1 fun_prop)).trans <| ContAction.resEquiv _ f have : functorToContAction F ≅ functorToContAction F' ⋙ equiv.functor := NatIso.ofComponents (fun X ↦ ObjectProperty.isoMk _ (Action.mkIso (FintypeCat.uSwitchEquivalence.unitIso.app _) (fun g ↦ FintypeCat.uSwitchEquivalence.unitIso.hom.naturality (g.hom.app X)))) (fun f ↦ by ext : 2 exact FintypeCat.uSwitchEquivalence.unitIso.hom.naturality (F.map f)) exact Functor.essSurj_of_iso this.symm /-- Any fiber functor `F` induces an equivalence of categories with the category of finite and discrete `Aut F`-sets. -/ @[stacks 0BN4] instance : (functorToContAction F).IsEquivalence where end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Galois/GaloisObjects.lean
import Mathlib.CategoryTheory.Galois.Basic import Mathlib.CategoryTheory.Limits.FintypeCat import Mathlib.CategoryTheory.Limits.Preserves.Limits import Mathlib.CategoryTheory.Limits.Shapes.SingleObj import Mathlib.GroupTheory.GroupAction.Basic /-! # Galois objects in Galois categories We define when a connected object of a Galois category `C` is Galois in a fiber functor independent way and show equivalent characterisations. ## Main definitions * `IsGalois` : Connected object `X` of `C` such that `X / Aut X` is terminal. ## Main results * `galois_iff_pretransitive` : A connected object `X` is Galois if and only if `Aut X` acts transitively on `F.obj X` for a fiber functor `F`. -/ universe u₁ u₂ v₁ v₂ v w namespace CategoryTheory namespace PreGaloisCategory open Limits Functor noncomputable instance {G : Type v} [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) FintypeCat.incl.{w} := by choose G' hg hf e using Finite.exists_type_univ_nonempty_mulEquiv G exact Limits.preservesColimitsOfShape_of_equiv (Classical.choice e).toSingleObjEquiv.symm _ /-- A connected object `X` of `C` is Galois if the quotient `X / Aut X` is terminal. -/ class IsGalois {C : Type u₁} [Category.{u₂, u₁} C] [GaloisCategory C] (X : C) : Prop extends IsConnected X where quotientByAutTerminal : Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X) variable {C : Type u₁} [Category.{u₂, u₁} C] /-- The natural action of `Aut X` on `F.obj X`. -/ instance autMulFiber (F : C ⥤ FintypeCat.{w}) (X : C) : MulAction (Aut X) (F.obj X) where smul σ a := F.map σ.hom a one_smul a := by change F.map (𝟙 X) a = a simp only [map_id, FintypeCat.id_apply] mul_smul g h a := by change F.map (h.hom ≫ g.hom) a = (F.map h.hom ≫ F.map g.hom) a simp only [map_comp, FintypeCat.comp_apply] variable [GaloisCategory C] (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] /-- For a connected object `X` of `C`, the quotient `X / Aut X` is terminal if and only if the quotient `F.obj X / Aut X` has exactly one element. -/ noncomputable def quotientByAutTerminalEquivUniqueQuotient (X : C) [IsConnected X] : IsTerminal (colimit <| SingleObj.functor <| Aut.toEnd X) ≃ Unique (MulAction.orbitRel.Quotient (Aut X) (F.obj X)) := by let J : SingleObj (Aut X) ⥤ C := SingleObj.functor (Aut.toEnd X) let e : (F ⋙ FintypeCat.incl).obj (colimit J) ≅ _ := preservesColimitIso (F ⋙ FintypeCat.incl) J ≪≫ (Equiv.toIso <| SingleObj.Types.colimitEquivQuotient (J ⋙ F ⋙ FintypeCat.incl)) apply Equiv.trans · apply (IsTerminal.isTerminalIffObj (F ⋙ FintypeCat.incl) _).trans (isLimitEmptyConeEquiv _ (asEmptyCone _) (asEmptyCone _) e) exact Types.isTerminalEquivUnique _ lemma isGalois_iff_aux (X : C) [IsConnected X] : IsGalois X ↔ Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X) := ⟨fun h ↦ h.quotientByAutTerminal, fun h ↦ ⟨h⟩⟩ /-- Given a fiber functor `F` and a connected object `X` of `C`. Then `X` is Galois if and only if the natural action of `Aut X` on `F.obj X` is transitive. -/ theorem isGalois_iff_pretransitive (X : C) [IsConnected X] : IsGalois X ↔ MulAction.IsPretransitive (Aut X) (F.obj X) := by rw [isGalois_iff_aux, Equiv.nonempty_congr <| quotientByAutTerminalEquivUniqueQuotient F X] exact (MulAction.pretransitive_iff_unique_quotient_of_nonempty (Aut X) (F.obj X)).symm /-- If `X` is Galois, the quotient `X / Aut X` is terminal. -/ noncomputable def isTerminalQuotientOfIsGalois (X : C) [IsGalois X] : IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X := Nonempty.some IsGalois.quotientByAutTerminal /-- If `X` is Galois, then the action of `Aut X` on `F.obj X` is transitive for every fiber functor `F`. -/ instance isPretransitive_of_isGalois (X : C) [IsGalois X] : MulAction.IsPretransitive (Aut X) (F.obj X) := by rw [← isGalois_iff_pretransitive] infer_instance lemma stabilizer_normal_of_isGalois (X : C) [IsGalois X] (x : F.obj X) : Subgroup.Normal (MulAction.stabilizer (Aut F) x) where conj_mem n ninstab g := by rw [MulAction.mem_stabilizer_iff] change g • n • (g⁻¹ • x) = x have : ∃ (φ : Aut X), F.map φ.hom x = g⁻¹ • x := MulAction.IsPretransitive.exists_smul_eq x (g⁻¹ • x) obtain ⟨φ, h⟩ := this rw [← h, mulAction_naturality, ninstab, h] simp theorem evaluation_aut_surjective_of_isGalois (A : C) [IsGalois A] (a : F.obj A) : Function.Surjective (fun f : Aut A ↦ F.map f.hom a) := MulAction.IsPretransitive.exists_smul_eq a theorem evaluation_aut_bijective_of_isGalois (A : C) [IsGalois A] (a : F.obj A) : Function.Bijective (fun f : Aut A ↦ F.map f.hom a) := ⟨evaluation_aut_injective_of_isConnected F A a, evaluation_aut_surjective_of_isGalois F A a⟩ /-- For Galois `A` and a point `a` of the fiber of `A`, the evaluation at `A` as an equivalence. -/ noncomputable def evaluationEquivOfIsGalois (A : C) [IsGalois A] (a : F.obj A) : Aut A ≃ F.obj A := Equiv.ofBijective _ (evaluation_aut_bijective_of_isGalois F A a) @[simp] lemma evaluationEquivOfIsGalois_apply (A : C) [IsGalois A] (a : F.obj A) (φ : Aut A) : evaluationEquivOfIsGalois F A a φ = F.map φ.hom a := rfl @[simp] lemma evaluationEquivOfIsGalois_symm_fiber (A : C) [IsGalois A] (a b : F.obj A) : F.map ((evaluationEquivOfIsGalois F A a).symm b).hom a = b := by change (evaluationEquivOfIsGalois F A a) _ = _ simp section AutMap /-- For a morphism from a connected object `A` to a Galois object `B` and an automorphism of `A`, there exists a unique automorphism of `B` making the canonical diagram commute. -/ lemma exists_autMap {A B : C} (f : A ⟶ B) [IsConnected A] [IsGalois B] (σ : Aut A) : ∃! (τ : Aut B), f ≫ τ.hom = σ.hom ≫ f := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A refine ⟨?_, ?_, ?_⟩ · exact (evaluationEquivOfIsGalois F B (F.map f a)).symm (F.map (σ.hom ≫ f) a) · apply evaluation_injective_of_isConnected F A B a simp · intro τ hτ apply evaluation_aut_injective_of_isConnected F B (F.map f a) simpa using congr_fun (F.congr_map hτ) a /-- A morphism from a connected object to a Galois object induces a map on automorphism groups. This is a group homomorphism (see `autMapHom`). -/ noncomputable def autMap {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) : Aut B := (exists_autMap f σ).choose @[simp] lemma comp_autMap {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) : f ≫ (autMap f σ).hom = σ.hom ≫ f := (exists_autMap f σ).choose_spec.left @[simp] lemma comp_autMap_apply (F : C ⥤ FintypeCat.{w}) {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) (a : F.obj A) : F.map (autMap f σ).hom (F.map f a) = F.map f (F.map σ.hom a) := by simpa [-comp_autMap] using congrFun (F.congr_map (comp_autMap f σ)) a /-- `autMap` is uniquely characterized by making the canonical diagram commute. -/ lemma autMap_unique {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) (τ : Aut B) (h : f ≫ τ.hom = σ.hom ≫ f) : autMap f σ = τ := ((exists_autMap f σ).choose_spec.right τ h).symm @[simp] lemma autMap_id {A : C} [IsGalois A] : autMap (𝟙 A) = id := funext fun σ ↦ autMap_unique (𝟙 A) σ _ (by simp) @[simp] lemma autMap_comp {X Y Z : C} [IsConnected X] [IsGalois Y] [IsGalois Z] (f : X ⟶ Y) (g : Y ⟶ Z) : autMap (f ≫ g) = autMap g ∘ autMap f := by refine funext fun σ ↦ autMap_unique _ σ _ ?_ rw [Function.comp_apply, Category.assoc, comp_autMap, ← Category.assoc] simp /-- `autMap` is surjective, if the source is also Galois. -/ lemma autMap_surjective_of_isGalois {A B : C} [IsGalois A] [IsGalois B] (f : A ⟶ B) : Function.Surjective (autMap f) := by intro σ let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A obtain ⟨a', ha'⟩ := surjective_of_nonempty_fiber_of_isConnected F f (F.map σ.hom (F.map f a)) obtain ⟨τ, (hτ : F.map τ.hom a = a')⟩ := MulAction.exists_smul_eq (Aut A) a a' use τ apply evaluation_aut_injective_of_isConnected F B (F.map f a) simp [hτ, ha'] @[simp] lemma autMap_apply_mul {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ τ : Aut A) : autMap f (σ * τ) = autMap f σ * autMap f τ := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A apply evaluation_aut_injective_of_isConnected F (B : C) (F.map f a) simp [Aut.Aut_mul_def] /-- `MonoidHom` version of `autMap`. -/ @[simps!] noncomputable def autMapHom {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) : Aut A →* Aut B := MonoidHom.mk' (autMap f) (autMap_apply_mul f) end AutMap end PreGaloisCategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Coherence.lean
import Mathlib.CategoryTheory.PathCategory.Basic import Mathlib.CategoryTheory.Functor.FullyFaithful import Mathlib.CategoryTheory.Bicategory.Free import Mathlib.CategoryTheory.Bicategory.LocallyDiscrete /-! # The coherence theorem for bicategories In this file, we prove the coherence theorem for bicategories, stated in the following form: the free bicategory over any quiver is locally thin. The proof is almost the same as the proof of the coherence theorem for monoidal categories that has been previously formalized in mathlib, which is based on the proof described by Ilya Beylin and Peter Dybjer. The idea is to view a path on a quiver as a normal form of a 1-morphism in the free bicategory on the same quiver. A normalization procedure is then described by `normalize : FreeBicategory B ⥤ᵖ (LocallyDiscrete (Paths B))`, which is a pseudofunctor from the free bicategory to the locally discrete bicategory on the path category. It turns out that this pseudofunctor is locally an equivalence of categories, and the coherence theorem follows immediately from this fact. ## Main statements * `locally_thin` : the free bicategory is locally thin, that is, there is at most one 2-morphism between two fixed 1-morphisms. ## References * [Ilya Beylin and Peter Dybjer, Extracting a proof of coherence for monoidal categories from a proof of normalization for monoids][beylin1996] -/ open Quiver (Path) open Quiver.Path namespace CategoryTheory open Bicategory Category universe v u namespace FreeBicategory variable {B : Type u} [Quiver.{v + 1} B] /-- Auxiliary definition for `inclusionPath`. -/ @[simp] def inclusionPathAux {a : B} : ∀ {b : B}, Path a b → Hom a b | _, nil => Hom.id a | _, cons p f => (inclusionPathAux p).comp (Hom.of f) /-- Category structure on `Hom a b`. In this file, we will use `Hom a b` for `a b : B` (precisely, `FreeBicategory.Hom a b`) instead of the definitionally equal expression `a ⟶ b` for `a b : FreeBicategory B`. The main reason is that we have to annoyingly write `@Quiver.Hom (FreeBicategory B) _ a b` to get the latter expression when given `a b : B`. -/ local instance homCategory' (a b : B) : Category (Hom a b) := homCategory a b /-- The discrete category on the paths includes into the category of 1-morphisms in the free bicategory. -/ def inclusionPath (a b : B) : Discrete (Path.{v + 1} a b) ⥤ Hom a b := Discrete.functor inclusionPathAux /-- The inclusion from the locally discrete bicategory on the path category into the free bicategory as a prelax functor. This will be promoted to a pseudofunctor after proving the coherence theorem. See `inclusion`. -/ def preinclusion (B : Type u) [Quiver.{v + 1} B] : PrelaxFunctor (LocallyDiscrete (Paths B)) (FreeBicategory B) where obj a := a.as map {a b} f := (@inclusionPath B _ a.as b.as).obj f map₂ η := (inclusionPath _ _).map η @[simp] theorem preinclusion_obj (a : B) : (preinclusion B).obj ⟨a⟩ = a := rfl @[simp] theorem preinclusion_map₂ {a b : B} (f g : Discrete (Path.{v + 1} a b)) (η : f ⟶ g) : (preinclusion B).map₂ η = eqToHom (congr_arg _ (Discrete.ext (Discrete.eq_of_hom η))) := rfl /-- The normalization of the composition of `p : Path a b` and `f : Hom b c`. `p` will eventually be taken to be `nil` and we then get the normalization of `f` alone, but the auxiliary `p` is necessary for Lean to accept the definition of `normalizeIso` and the `whisker_left` case of `normalizeAux_congr` and `normalize_naturality`. -/ @[simp] def normalizeAux {a : B} : ∀ {b c : B}, Path a b → Hom b c → Path a c | _, _, p, Hom.of f => p.cons f | _, _, p, Hom.id _ => p | _, _, p, Hom.comp f g => normalizeAux (normalizeAux p f) g /- We may define ``` def normalizeAux' : ∀ {a b : B}, Hom a b → Path a b | _, _, (Hom.of f) => f.toPath | _, _, (Hom.id b) => nil | _, _, (Hom.comp f g) => (normalizeAux' f).comp (normalizeAux' g) ``` and define `normalizeAux p f` to be `p.comp (normalizeAux' f)` and this will be equal to the above definition, but the equality proof requires `comp_assoc`, and it thus lacks the correct definitional property to make the definition of `normalizeIso` typecheck. ``` example {a b c : B} (p : Path a b) (f : Hom b c) : normalizeAux p f = p.comp (normalizeAux' f) := by induction f; rfl; rfl; case comp _ _ _ _ _ ihf ihg => rw [normalizeAux, ihf, ihg]; apply comp_assoc ``` -/ /-- A 2-isomorphism between a partially-normalized 1-morphism in the free bicategory to the fully-normalized 1-morphism. -/ @[simp] def normalizeIso {a : B} : ∀ {b c : B} (p : Path a b) (f : Hom b c), (preinclusion B).map ⟨p⟩ ≫ f ≅ (preinclusion B).map ⟨normalizeAux p f⟩ | _, _, _, Hom.of _ => Iso.refl _ | _, _, _, Hom.id b => ρ_ _ | _, _, p, Hom.comp f g => (α_ _ _ _).symm ≪≫ whiskerRightIso (normalizeIso p f) g ≪≫ normalizeIso (normalizeAux p f) g /-- Given a 2-morphism between `f` and `g` in the free bicategory, we have the equality `normalizeAux p f = normalizeAux p g`. -/ theorem normalizeAux_congr {a b c : B} (p : Path a b) {f g : Hom b c} (η : f ⟶ g) : normalizeAux p f = normalizeAux p g := by rcases η with ⟨η'⟩ apply @congr_fun _ _ fun p => normalizeAux p f clear p η induction η' with | vcomp _ _ _ _ => apply Eq.trans <;> assumption | whisker_left _ _ ih => funext; apply congr_fun ih | whisker_right _ _ ih => funext; apply congr_arg₂ _ (congr_fun ih _) rfl | _ => funext; rfl /-- The 2-isomorphism `normalizeIso p f` is natural in `f`. -/ theorem normalize_naturality {a b c : B} (p : Path a b) {f g : Hom b c} (η : f ⟶ g) : (preinclusion B).map ⟨p⟩ ◁ η ≫ (normalizeIso p g).hom = (normalizeIso p f).hom ≫ (preinclusion B).map₂ (eqToHom (Discrete.ext (normalizeAux_congr p η))) := by rcases η with ⟨η'⟩; clear η induction η' with | id => simp | vcomp η θ ihf ihg => simp only [mk_vcomp, whiskerLeft_comp] slice_lhs 2 3 => rw [ihg] slice_lhs 1 2 => rw [ihf] simp -- p ≠ nil required! See the docstring of `normalizeAux`. | whisker_left _ _ ih => dsimp rw [associator_inv_naturality_right_assoc, whisker_exchange_assoc, ih] simp | whisker_right h η' ih => dsimp rw [associator_inv_naturality_middle_assoc, ← comp_whiskerRight_assoc, ih, comp_whiskerRight] have := dcongr_arg (fun x => (normalizeIso x h).hom) (normalizeAux_congr p (Quot.mk _ η')) dsimp at this; simp [this] | _ => simp -- Not `@[simp]` because it is not in `simp`-normal form. theorem normalizeAux_nil_comp {a b c : B} (f : Hom a b) (g : Hom b c) : normalizeAux nil (f.comp g) = (normalizeAux nil f).comp (normalizeAux nil g) := by induction g generalizing a with | id => rfl | of => rfl | comp g _ ihf ihg => erw [ihg (f.comp g), ihf f, ihg g, comp_assoc] /-- The normalization pseudofunctor for the free bicategory on a quiver `B`. -/ def normalize (B : Type u) [Quiver.{v + 1} B] : FreeBicategory B ⥤ᵖ (LocallyDiscrete (Paths B)) where obj a := ⟨a⟩ map f := ⟨normalizeAux nil f⟩ map₂ η := eqToHom <| Discrete.ext <| normalizeAux_congr nil η mapId _ := eqToIso <| Discrete.ext rfl mapComp f g := eqToIso <| Discrete.ext <| normalizeAux_nil_comp f g /-- Auxiliary definition for `normalizeEquiv`. -/ def normalizeUnitIso (a b : FreeBicategory B) : 𝟭 (a ⟶ b) ≅ (normalize B).mapFunctor a b ⋙ @inclusionPath B _ a b := NatIso.ofComponents (fun f => (λ_ f).symm ≪≫ normalizeIso nil f) (by intro f g η erw [leftUnitor_inv_naturality_assoc, assoc] congr 1 exact normalize_naturality nil η) /-- Normalization as an equivalence of categories. -/ def normalizeEquiv (a b : B) : Hom a b ≌ Discrete (Path.{v + 1} a b) := Equivalence.mk ((normalize _).mapFunctor a b) (inclusionPath a b) (normalizeUnitIso a b) (Discrete.natIso fun f => eqToIso (by obtain ⟨f⟩ := f induction f with | nil => rfl | cons _ _ ih => ext1 -- Porting note: `tidy` closes the goal in mathlib3 but `aesop` doesn't here. injection ih with ih conv_rhs => rw [← ih] rfl)) /-- The coherence theorem for bicategories. -/ instance locally_thin {a b : FreeBicategory B} : Quiver.IsThin (a ⟶ b) := fun _ _ => ⟨fun _ _ => (@normalizeEquiv B _ a b).functor.map_injective (Subsingleton.elim _ _)⟩ /-- Auxiliary definition for `inclusion`. -/ def inclusionMapCompAux {a b : B} : ∀ {c : B} (f : Path a b) (g : Path b c), (preinclusion _).map (⟨f⟩ ≫ ⟨g⟩) ≅ (preinclusion _).map ⟨f⟩ ≫ (preinclusion _).map ⟨g⟩ | _, f, nil => (ρ_ ((preinclusion _).map ⟨f⟩)).symm | _, f, cons g₁ g₂ => whiskerRightIso (inclusionMapCompAux f g₁) (Hom.of g₂) ≪≫ α_ _ _ _ /-- The inclusion pseudofunctor from the locally discrete bicategory on the path category into the free bicategory. -/ def inclusion (B : Type u) [Quiver.{v + 1} B] : LocallyDiscrete (Paths B) ⥤ᵖ (FreeBicategory B) := { -- All the conditions for 2-morphisms are trivial thanks to the coherence theorem! preinclusion B with mapId := fun _ => Iso.refl _ mapComp := fun f g => inclusionMapCompAux f.as g.as } end FreeBicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Extension.lean
import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic /-! # Extensions and lifts in bicategories We introduce the concept of extensions and lifts within the bicategorical framework. These concepts are defined by commutative diagrams in the (1-)categorical context. Within the bicategorical framework, commutative diagrams are replaced by 2-morphisms. Depending on the orientation of the 2-morphisms, we define both left and right extensions (likewise for lifts). The use of left and right here is a common one in the theory of Kan extensions. ## Implementation notes We define extensions and lifts as objects in certain comma categories (`StructuredArrow` for left, and `CostructuredArrow` for right). See the file `CategoryTheory.StructuredArrow` for properties about these categories. We introduce some intuitive aliases. For example, `LeftExtension.extension` is an alias for `Comma.right`. ## References * https://ncatlab.org/nlab/show/lifts+and+extensions * https://ncatlab.org/nlab/show/Kan+extension -/ namespace CategoryTheory namespace Bicategory universe w v u variable {B : Type u} [Bicategory.{w, v} B] {a b c : B} /-- Triangle diagrams for (left) extensions. ``` b △ \ | \ extension △ f | \ | unit | ◿ a - - - ▷ c g ``` -/ abbrev LeftExtension (f : a ⟶ b) (g : a ⟶ c) := StructuredArrow g (precomp _ f) namespace LeftExtension variable {f : a ⟶ b} {g : a ⟶ c} /-- The extension of `g` along `f`. -/ abbrev extension (t : LeftExtension f g) : b ⟶ c := t.right /-- The 2-morphism filling the triangle diagram. -/ abbrev unit (t : LeftExtension f g) : g ⟶ f ≫ t.extension := t.hom /-- Construct a left extension from a 1-morphism and a 2-morphism. -/ abbrev mk (h : b ⟶ c) (unit : g ⟶ f ≫ h) : LeftExtension f g := StructuredArrow.mk unit variable {s t : LeftExtension f g} /-- To construct a morphism between left extensions, we need a 2-morphism between the extensions, and to check that it is compatible with the units. -/ abbrev homMk (η : s.extension ⟶ t.extension) (w : s.unit ≫ f ◁ η = t.unit := by cat_disch) : s ⟶ t := StructuredArrow.homMk η w @[reassoc (attr := simp)] theorem w (η : s ⟶ t) : s.unit ≫ f ◁ η.right = t.unit := StructuredArrow.w η /-- The left extension along the identity. -/ def alongId (g : a ⟶ c) : LeftExtension (𝟙 a) g := .mk _ (λ_ g).inv instance : Inhabited (LeftExtension (𝟙 a) g) := ⟨alongId g⟩ /-- Construct a left extension of `g : a ⟶ c` from a left extension of `g ≫ 𝟙 c`. -/ @[simps!] def ofCompId (t : LeftExtension f (g ≫ 𝟙 c)) : LeftExtension f g := mk (extension t) ((ρ_ g).inv ≫ unit t) /-- Whisker a 1-morphism to an extension. ``` b △ \ | \ extension △ f | \ | unit | ◿ a - - - ▷ c - - - ▷ x g h ``` -/ def whisker (t : LeftExtension f g) {x : B} (h : c ⟶ x) : LeftExtension f (g ≫ h) := .mk _ <| t.unit ▷ h ≫ (α_ _ _ _).hom @[simp] theorem whisker_extension (t : LeftExtension f g) {x : B} (h : c ⟶ x) : (t.whisker h).extension = t.extension ≫ h := rfl @[simp] theorem whisker_unit (t : LeftExtension f g) {x : B} (h : c ⟶ x) : (t.whisker h).unit = t.unit ▷ h ≫ (α_ f t.extension h).hom := rfl /-- Whiskering a 1-morphism is a functor. -/ @[simps] def whiskering {x : B} (h : c ⟶ x) : LeftExtension f g ⥤ LeftExtension f (g ≫ h) where obj t := t.whisker h map η := LeftExtension.homMk (η.right ▷ h) <| by simp [- LeftExtension.w, ← LeftExtension.w η] /-- Define a morphism between left extensions by cancelling the whiskered identities. -/ @[simps! right] def whiskerIdCancel (s : LeftExtension f (g ≫ 𝟙 c)) {t : LeftExtension f g} (τ : s ⟶ t.whisker (𝟙 c)) : s.ofCompId ⟶ t := LeftExtension.homMk (τ.right ≫ (ρ_ _).hom) /-- Construct a morphism between whiskered extensions. -/ @[simps! right] def whiskerHom (i : s ⟶ t) {x : B} (h : c ⟶ x) : s.whisker h ⟶ t.whisker h := StructuredArrow.homMk (i.right ▷ h) <| by rw [← cancel_mono (α_ _ _ _).inv] calc _ = (unit s ≫ f ◁ i.right) ▷ h := by simp [- LeftExtension.w] _ = unit t ▷ h := congrArg (· ▷ h) (LeftExtension.w i) _ = _ := by simp /-- Construct an isomorphism between whiskered extensions. -/ def whiskerIso (i : s ≅ t) {x : B} (h : c ⟶ x) : s.whisker h ≅ t.whisker h := Iso.mk (whiskerHom i.hom h) (whiskerHom i.inv h) (StructuredArrow.hom_ext _ _ <| calc _ = (i.hom ≫ i.inv).right ▷ h := by simp [- Iso.hom_inv_id] _ = 𝟙 _ := by simp [Iso.hom_inv_id]) (StructuredArrow.hom_ext _ _ <| calc _ = (i.inv ≫ i.hom).right ▷ h := by simp [- Iso.inv_hom_id] _ = 𝟙 _ := by simp [Iso.inv_hom_id]) /-- The isomorphism between left extensions induced by a right unitor. -/ @[simps! hom_right inv_right] def whiskerOfCompIdIsoSelf (t : LeftExtension f g) : (t.whisker (𝟙 c)).ofCompId ≅ t := StructuredArrow.isoMk (ρ_ (t.extension)) end LeftExtension /-- Triangle diagrams for (left) lifts. ``` b ◹ | lift / | △ / | f | unit / ▽ c - - - ▷ a g ``` -/ abbrev LeftLift (f : b ⟶ a) (g : c ⟶ a) := StructuredArrow g (postcomp _ f) namespace LeftLift variable {f : b ⟶ a} {g : c ⟶ a} /-- The lift of `g` along `f`. -/ abbrev lift (t : LeftLift f g) : c ⟶ b := t.right /-- The 2-morphism filling the triangle diagram. -/ abbrev unit (t : LeftLift f g) : g ⟶ t.lift ≫ f := t.hom /-- Construct a left lift from a 1-morphism and a 2-morphism. -/ abbrev mk (h : c ⟶ b) (unit : g ⟶ h ≫ f) : LeftLift f g := StructuredArrow.mk unit variable {s t : LeftLift f g} /-- To construct a morphism between left lifts, we need a 2-morphism between the lifts, and to check that it is compatible with the units. -/ abbrev homMk (η : s.lift ⟶ t.lift) (w : s.unit ≫ η ▷ f = t.unit := by cat_disch) : s ⟶ t := StructuredArrow.homMk η w @[reassoc (attr := simp)] theorem w (h : s ⟶ t) : s.unit ≫ h.right ▷ f = t.unit := StructuredArrow.w h /-- The left lift along the identity. -/ def alongId (g : c ⟶ a) : LeftLift (𝟙 a) g := .mk _ (ρ_ g).inv instance : Inhabited (LeftLift (𝟙 a) g) := ⟨alongId g⟩ /-- Construct a left lift along `g : c ⟶ a` from a left lift along `𝟙 c ≫ g`. -/ @[simps!] def ofIdComp (t : LeftLift f (𝟙 c ≫ g)) : LeftLift f g := mk (lift t) ((λ_ _).inv ≫ unit t) /-- Whisker a 1-morphism to a lift. ``` b ◹ | lift / | △ / | f | unit / ▽ x - - - ▷ c - - - ▷ a h g ``` -/ def whisker (t : LeftLift f g) {x : B} (h : x ⟶ c) : LeftLift f (h ≫ g) := .mk _ <| h ◁ t.unit ≫ (α_ _ _ _).inv @[simp] theorem whisker_lift (t : LeftLift f g) {x : B} (h : x ⟶ c) : (t.whisker h).lift = h ≫ t.lift := rfl @[simp] theorem whisker_unit (t : LeftLift f g) {x : B} (h : x ⟶ c) : (t.whisker h).unit = h ◁ t.unit ≫ (α_ h t.lift f).inv := rfl /-- Whiskering a 1-morphism is a functor. -/ @[simps] def whiskering {x : B} (h : x ⟶ c) : LeftLift f g ⥤ LeftLift f (h ≫ g) where obj t := t.whisker h map η := LeftLift.homMk (h ◁ η.right) <| by dsimp only [whisker_lift, whisker_unit] rw [← LeftLift.w η] simp [- LeftLift.w] /-- Define a morphism between left lifts by cancelling the whiskered identities. -/ @[simps! right] def whiskerIdCancel (s : LeftLift f (𝟙 c ≫ g)) {t : LeftLift f g} (τ : s ⟶ t.whisker (𝟙 c)) : s.ofIdComp ⟶ t := LeftLift.homMk (τ.right ≫ (λ_ _).hom) /-- Construct a morphism between whiskered lifts. -/ @[simps! right] def whiskerHom (i : s ⟶ t) {x : B} (h : x ⟶ c) : s.whisker h ⟶ t.whisker h := StructuredArrow.homMk (h ◁ i.right) <| by rw [← cancel_mono (α_ h _ _).hom] calc _ = h ◁ (unit s ≫ i.right ▷ f) := by simp [- LeftLift.w] _ = h ◁ unit t := congrArg (h ◁ ·) (LeftLift.w i) _ = _ := by simp /-- Construct an isomorphism between whiskered lifts. -/ def whiskerIso (i : s ≅ t) {x : B} (h : x ⟶ c) : s.whisker h ≅ t.whisker h := Iso.mk (whiskerHom i.hom h) (whiskerHom i.inv h) (StructuredArrow.hom_ext _ _ <| calc _ = h ◁ (i.hom ≫ i.inv).right := by simp [- Iso.hom_inv_id] _ = 𝟙 _ := by simp [Iso.hom_inv_id]) (StructuredArrow.hom_ext _ _ <| calc _ = h ◁ (i.inv ≫ i.hom).right := by simp [- Iso.inv_hom_id] _ = 𝟙 _ := by simp [Iso.inv_hom_id]) /-- The isomorphism between left lifts induced by a left unitor. -/ @[simps! hom_right inv_right] def whiskerOfIdCompIsoSelf (t : LeftLift f g) : (t.whisker (𝟙 c)).ofIdComp ≅ t := StructuredArrow.isoMk (λ_ (lift t)) end LeftLift /-- Triangle diagrams for (right) extensions. ``` b △ \ | \ extension | counit f | \ ▽ | ◿ a - - - ▷ c g ``` -/ abbrev RightExtension (f : a ⟶ b) (g : a ⟶ c) := CostructuredArrow (precomp _ f) g namespace RightExtension variable {f : a ⟶ b} {g : a ⟶ c} /-- The extension of `g` along `f`. -/ abbrev extension (t : RightExtension f g) : b ⟶ c := t.left /-- The 2-morphism filling the triangle diagram. -/ abbrev counit (t : RightExtension f g) : f ≫ t.extension ⟶ g := t.hom /-- Construct a right extension from a 1-morphism and a 2-morphism. -/ abbrev mk (h : b ⟶ c) (counit : f ≫ h ⟶ g) : RightExtension f g := CostructuredArrow.mk counit /-- To construct a morphism between right extensions, we need a 2-morphism between the extensions, and to check that it is compatible with the counits. -/ abbrev homMk {s t : RightExtension f g} (η : s.extension ⟶ t.extension) (w : f ◁ η ≫ t.counit = s.counit) : s ⟶ t := CostructuredArrow.homMk η w @[reassoc (attr := simp)] theorem w {s t : RightExtension f g} (η : s ⟶ t) : f ◁ η.left ≫ t.counit = s.counit := CostructuredArrow.w η /-- The right extension along the identity. -/ def alongId (g : a ⟶ c) : RightExtension (𝟙 a) g := .mk _ (λ_ g).hom instance : Inhabited (RightExtension (𝟙 a) g) := ⟨alongId g⟩ end RightExtension /-- Triangle diagrams for (right) lifts. ``` b ◹ | lift / | | counit / | f ▽ / ▽ c - - - ▷ a g ``` -/ abbrev RightLift (f : b ⟶ a) (g : c ⟶ a) := CostructuredArrow (postcomp _ f) g namespace RightLift variable {f : b ⟶ a} {g : c ⟶ a} /-- The lift of `g` along `f`. -/ abbrev lift (t : RightLift f g) : c ⟶ b := t.left /-- The 2-morphism filling the triangle diagram. -/ abbrev counit (t : RightLift f g) : t.lift ≫ f ⟶ g := t.hom /-- Construct a right lift from a 1-morphism and a 2-morphism. -/ abbrev mk (h : c ⟶ b) (counit : h ≫ f ⟶ g) : RightLift f g := CostructuredArrow.mk counit /-- To construct a morphism between right lifts, we need a 2-morphism between the lifts, and to check that it is compatible with the counits. -/ abbrev homMk {s t : RightLift f g} (η : s.lift ⟶ t.lift) (w : η ▷ f ≫ t.counit = s.counit) : s ⟶ t := CostructuredArrow.homMk η w @[reassoc (attr := simp)] theorem w {s t : RightLift f g} (h : s ⟶ t) : h.left ▷ f ≫ t.counit = s.counit := CostructuredArrow.w h /-- The right lift along the identity. -/ def alongId (g : c ⟶ a) : RightLift (𝟙 a) g := .mk _ (ρ_ g).hom instance : Inhabited (RightLift (𝟙 a) g) := ⟨alongId g⟩ end RightLift end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Basic.lean
import Mathlib.CategoryTheory.NatIso /-! # Bicategories In this file we define typeclass for bicategories. A bicategory `B` consists of * objects `a : B`, * 1-morphisms `f : a ⟶ b` between objects `a b : B`, and * 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`. We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms, respectively. A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that we have * a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and * an identity `𝟙 a : a ⟶ a` for each object `a : B`. For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The 2-morphisms in the bicategory are implemented as the morphisms in this family of categories. The composition of 1-morphisms is in fact an object part of a functor `(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism `f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a 2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism `whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law `whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`, which is required as an axiom in the definition here. -/ namespace CategoryTheory universe w v u open Category Iso -- intended to be used with explicit universe parameters /-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative, but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`. There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`. These associators and unitors satisfy the pentagon and triangle equations. See https://ncatlab.org/nlab/show/bicategory. -/ @[nolint checkUnivs] class Bicategory (B : Type u) extends CategoryStruct.{v} B where /-- The category structure on the collection of 1-morphisms -/ homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance /-- Left whiskering for morphisms -/ whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h /-- Right whiskering for morphisms -/ whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h /-- The associator isomorphism: `(f ≫ g) ≫ h ≅ f ≫ g ≫ h` -/ associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h /-- The left unitor: `𝟙 a ≫ f ≅ f` -/ leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f /-- The right unitor: `f ≫ 𝟙 b ≅ f` -/ rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f -- axioms for left whiskering: whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by cat_disch whiskerLeft_comp : ∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i), whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by cat_disch id_whiskerLeft : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by cat_disch comp_whiskerLeft : ∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'), whiskerLeft (f ≫ g) η = (associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by cat_disch -- axioms for right whiskering: id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by cat_disch comp_whiskerRight : ∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c), whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by cat_disch whiskerRight_id : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by cat_disch whiskerRight_comp : ∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d), whiskerRight η (g ≫ h) = (associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by cat_disch -- associativity of whiskerings: whisker_assoc : ∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d), whiskerRight (whiskerLeft f η) h = (associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by cat_disch -- exchange law of left and right whiskerings: whisker_exchange : ∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i), whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by cat_disch -- pentagon identity: pentagon : ∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e), whiskerRight (associator f g h).hom i ≫ (associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom = (associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by cat_disch -- triangle identity: triangle : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), (associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom = whiskerRight (rightUnitor f).hom g := by cat_disch namespace Bicategory @[inherit_doc] scoped infixr:81 " ◁ " => Bicategory.whiskerLeft @[inherit_doc] scoped infixl:81 " ▷ " => Bicategory.whiskerRight @[inherit_doc] scoped notation "α_" => Bicategory.associator @[inherit_doc] scoped notation "λ_" => Bicategory.leftUnitor @[inherit_doc] scoped notation "ρ_" => Bicategory.rightUnitor /-! ### Simp-normal form for 2-morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any 2-morphisms into simp-normal form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming) `coherence` tactic. The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors) or non-structural 2-morphisms, and 2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`, where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a non-structural 2-morphisms that is also not the identity or a composite. Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`. -/ attribute [instance] homCategory attribute [reassoc] whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc whisker_exchange attribute [reassoc (attr := simp)] pentagon triangle /- The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`), which at first glance look more complicated than the LHS, but they will be eventually reduced by the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic. -/ attribute [simp] whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B} @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_whiskerLeft_hom_inv (f : a ⟶ b) (g : b ⟶ c) {h k : c ⟶ d} (η : h ≅ k) : f ◁ g ◁ η.hom ≫ f ◁ g ◁ η.inv = 𝟙 (f ≫ g ≫ h) := by simp [← whiskerLeft_comp] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) (k : c ⟶ d) : η.hom ▷ h ▷ k ≫ η.inv ▷ h ▷ k = 𝟙 ((f ≫ h) ≫ k) := by simp [← comp_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_whiskerLeft_inv_hom (f : a ⟶ b) (g : b ⟶ c) {h k : c ⟶ d} (η : h ≅ k) : f ◁ g ◁ η.inv ≫ f ◁ g ◁ η.hom = 𝟙 (f ≫ g ≫ k) := by simp [← whiskerLeft_comp] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) (k : c ⟶ d) : η.inv ▷ h ▷ k ≫ η.hom ▷ h ▷ k = 𝟙 ((g ≫ h) ≫ k) := by simp [← comp_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv_whiskerRight (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) (k : c ⟶ d) : f ◁ η.hom ▷ k ≫ f ◁ η.inv ▷ k = 𝟙 (f ≫ g ≫ k) := by simp [← whiskerLeft_comp] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom_whiskerRight (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) (k : c ⟶ d) : f ◁ η.inv ▷ k ≫ f ◁ η.hom ▷ k = 𝟙 (f ≫ h ≫ k) := by simp [← whiskerLeft_comp] /-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps] def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where hom := f ◁ η.hom inv := f ◁ η.inv instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) := (whiskerLeftIso f (asIso η)).isIso_hom @[simp] theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : inv (f ◁ η) = f ◁ inv η := by apply IsIso.inv_eq_of_hom_inv_id simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id] /-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps!] def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where hom := η.hom ▷ h inv := η.inv ▷ h instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) := (whiskerRightIso (asIso η) h).isIso_hom @[simp] theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : inv (η ▷ h) = inv η ▷ h := by apply IsIso.inv_eq_of_hom_inv_id simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id] @[reassoc (attr := simp)] theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i = (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom = f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom = (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv = (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by simp [← cancel_epi (f ◁ (α_ g h i).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv = (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv = (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv = (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom = (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by simp [← cancel_epi ((α_ f g h).hom ▷ i)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i = f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv := eq_of_inv_eq_inv (by simp) theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g := triangle f g @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) : (ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by simp [← cancel_mono (f ◁ (λ_ g).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by simp [← cancel_mono ((ρ_ f).hom ▷ g)] @[reassoc] theorem associator_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h ≫ (α_ f' g h).hom = (α_ f g h).hom ≫ η ▷ (g ≫ h) := by simp @[reassoc] theorem associator_inv_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ (g ≫ h) ≫ (α_ f' g h).inv = (α_ f g h).inv ≫ η ▷ g ▷ h := by simp @[reassoc] theorem whiskerRight_comp_symm {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h = (α_ f g h).hom ≫ η ▷ (g ≫ h) ≫ (α_ f' g h).inv := by simp @[reassoc] theorem associator_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : (f ◁ η) ▷ h ≫ (α_ f g' h).hom = (α_ f g h).hom ≫ f ◁ η ▷ h := by simp @[reassoc] theorem associator_inv_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h ≫ (α_ f g' h).inv = (α_ f g h).inv ≫ (f ◁ η) ▷ h := by simp @[reassoc] theorem whisker_assoc_symm (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h = (α_ f g h).inv ≫ (f ◁ η) ▷ h ≫ (α_ f g' h).hom := by simp @[reassoc] theorem associator_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : (f ≫ g) ◁ η ≫ (α_ f g h').hom = (α_ f g h).hom ≫ f ◁ g ◁ η := by simp @[reassoc] theorem associator_inv_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η ≫ (α_ f g h').inv = (α_ f g h).inv ≫ (f ≫ g) ◁ η := by simp @[reassoc] theorem comp_whiskerLeft_symm (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η = (α_ f g h).inv ≫ (f ≫ g) ◁ η ≫ (α_ f g h').hom := by simp @[reassoc] theorem leftUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : 𝟙 a ◁ η ≫ (λ_ g).hom = (λ_ f).hom ≫ η := by simp @[reassoc] theorem leftUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (λ_ g).inv = (λ_ f).inv ≫ 𝟙 a ◁ η := by simp theorem id_whiskerLeft_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (λ_ f).inv ≫ 𝟙 a ◁ η ≫ (λ_ g).hom := by simp @[reassoc] theorem rightUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ▷ 𝟙 b ≫ (ρ_ g).hom = (ρ_ f).hom ≫ η := by simp @[reassoc] theorem rightUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (ρ_ g).inv = (ρ_ f).inv ≫ η ▷ 𝟙 b := by simp theorem whiskerRight_id_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (ρ_ f).inv ≫ η ▷ 𝟙 b ≫ (ρ_ g).hom := by simp theorem whiskerLeft_iff {f g : a ⟶ b} (η θ : f ⟶ g) : 𝟙 a ◁ η = 𝟙 a ◁ θ ↔ η = θ := by simp theorem whiskerRight_iff {f g : a ⟶ b} (η θ : f ⟶ g) : η ▷ 𝟙 b = θ ▷ 𝟙 b ↔ η = θ := by simp /-- We state it as a simp lemma, which is regarded as an involved version of `id_whiskerRight f g : 𝟙 f ▷ g = 𝟙 (f ≫ g)`. -/ @[reassoc, simp] theorem leftUnitor_whiskerRight (f : a ⟶ b) (g : b ⟶ c) : (λ_ f).hom ▷ g = (α_ (𝟙 a) f g).hom ≫ (λ_ (f ≫ g)).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ← cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ← comp_whiskerRight_assoc, triangle, associator_naturality_left] @[reassoc, simp] theorem leftUnitor_inv_whiskerRight (f : a ⟶ b) (g : b ⟶ c) : (λ_ f).inv ▷ g = (λ_ (f ≫ g)).inv ≫ (α_ (𝟙 a) f g).inv := eq_of_inv_eq_inv (by simp) @[reassoc, simp] theorem whiskerLeft_rightUnitor (f : a ⟶ b) (g : b ⟶ c) : f ◁ (ρ_ g).hom = (α_ f g (𝟙 c)).inv ≫ (ρ_ (f ≫ g)).hom := by rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ← cancel_epi (f ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ← associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right, associator_inv_naturality_right] @[reassoc, simp] theorem whiskerLeft_rightUnitor_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (ρ_ g).inv = (ρ_ (f ≫ g)).inv ≫ (α_ f g (𝟙 c)).hom := eq_of_inv_eq_inv (by simp) /- It is not so obvious whether `leftUnitor_whiskerRight` or `leftUnitor_comp` should be a simp lemma. Our choice is the former. One reason is that the latter yields the following loop: [id_whiskerLeft] : 𝟙 a ◁ (ρ_ f).hom ==> (λ_ (f ≫ 𝟙 b)).hom ≫ (ρ_ f).hom ≫ (λ_ f).inv [leftUnitor_comp] : (λ_ (f ≫ 𝟙 b)).hom ==> (α_ (𝟙 a) f (𝟙 b)).inv ≫ (λ_ f).hom ▷ 𝟙 b [whiskerRight_id] : (λ_ f).hom ▷ 𝟙 b ==> (ρ_ (𝟙 a ≫ f)).hom ≫ (λ_ f).hom ≫ (ρ_ f).inv [rightUnitor_comp] : (ρ_ (𝟙 a ≫ f)).hom ==> (α_ (𝟙 a) f (𝟙 b)).hom ≫ 𝟙 a ◁ (ρ_ f).hom -/ @[reassoc] theorem leftUnitor_comp (f : a ⟶ b) (g : b ⟶ c) : (λ_ (f ≫ g)).hom = (α_ (𝟙 a) f g).inv ≫ (λ_ f).hom ▷ g := by simp @[reassoc] theorem leftUnitor_comp_inv (f : a ⟶ b) (g : b ⟶ c) : (λ_ (f ≫ g)).inv = (λ_ f).inv ▷ g ≫ (α_ (𝟙 a) f g).hom := by simp @[reassoc] theorem rightUnitor_comp (f : a ⟶ b) (g : b ⟶ c) : (ρ_ (f ≫ g)).hom = (α_ f g (𝟙 c)).hom ≫ f ◁ (ρ_ g).hom := by simp @[reassoc] theorem rightUnitor_comp_inv (f : a ⟶ b) (g : b ⟶ c) : (ρ_ (f ≫ g)).inv = f ◁ (ρ_ g).inv ≫ (α_ f g (𝟙 c)).inv := by simp @[simp] theorem unitors_equal : (λ_ (𝟙 a)).hom = (ρ_ (𝟙 a)).hom := by rw [← whiskerLeft_iff, ← cancel_epi (α_ _ _ _).hom, ← cancel_mono (ρ_ _).hom, triangle, ← rightUnitor_comp, rightUnitor_naturality] @[simp] theorem unitors_inv_equal : (λ_ (𝟙 a)).inv = (ρ_ (𝟙 a)).inv := by simp [Iso.inv_eq_inv] section attribute [local simp] whisker_exchange /-- Precomposition of a 1-morphism as a functor. -/ @[simps] def precomp (c : B) (f : a ⟶ b) : (b ⟶ c) ⥤ (a ⟶ c) where obj := (f ≫ ·) map := (f ◁ ·) /-- Precomposition of a 1-morphism as a functor from the category of 1-morphisms `a ⟶ b` into the category of functors `(b ⟶ c) ⥤ (a ⟶ c)`. -/ @[simps] def precomposing (a b c : B) : (a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c) where obj f := precomp c f map η := { app := (η ▷ ·) } /-- Postcomposition of a 1-morphism as a functor. -/ @[simps] def postcomp (a : B) (f : b ⟶ c) : (a ⟶ b) ⥤ (a ⟶ c) where obj := (· ≫ f) map := (· ▷ f) /-- Postcomposition of a 1-morphism as a functor from the category of 1-morphisms `b ⟶ c` into the category of functors `(a ⟶ b) ⥤ (a ⟶ c)`. -/ @[simps] def postcomposing (a b c : B) : (b ⟶ c) ⥤ (a ⟶ b) ⥤ (a ⟶ c) where obj f := postcomp a f map η := { app := (· ◁ η) } /-- Left component of the associator as a natural isomorphism. -/ @[simps!] def associatorNatIsoLeft (a : B) (g : b ⟶ c) (h : c ⟶ d) : (postcomposing a ..).obj g ⋙ (postcomposing ..).obj h ≅ (postcomposing ..).obj (g ≫ h) := NatIso.ofComponents (α_ · g h) /-- Middle component of the associator as a natural isomorphism. -/ @[simps!] def associatorNatIsoMiddle (f : a ⟶ b) (h : c ⟶ d) : (precomposing ..).obj f ⋙ (postcomposing ..).obj h ≅ (postcomposing ..).obj h ⋙ (precomposing ..).obj f := NatIso.ofComponents (α_ f · h) /-- Right component of the associator as a natural isomorphism. -/ @[simps!] def associatorNatIsoRight (f : a ⟶ b) (g : b ⟶ c) (d : B) : (precomposing _ _ d).obj (f ≫ g) ≅ (precomposing ..).obj g ⋙ (precomposing ..).obj f := NatIso.ofComponents (α_ f g ·) /-- Left unitor as a natural isomorphism. -/ @[simps!] def leftUnitorNatIso (a b : B) : (precomposing _ _ b).obj (𝟙 a) ≅ 𝟭 (a ⟶ b) := NatIso.ofComponents (λ_ ·) /-- Right unitor as a natural isomorphism. -/ @[simps!] def rightUnitorNatIso (a b : B) : (postcomposing a _ _).obj (𝟙 b) ≅ 𝟭 (a ⟶ b) := NatIso.ofComponents (ρ_ ·) end end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/End.lean
import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.Monoidal.Category /-! # Endomorphisms of an object in a bicategory, as a monoidal category. -/ universe w v u namespace CategoryTheory variable {C : Type u} [Bicategory.{w, v} C] /-- The endomorphisms of an object in a bicategory can be considered as a monoidal category. -/ abbrev EndMonoidal (X : C) := X ⟶ X -- The `Category` instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance (X : C) : Category (EndMonoidal X) := show Category (X ⟶ X) from inferInstance instance (X : C) : Inhabited (EndMonoidal X) := ⟨𝟙 X⟩ open Bicategory open MonoidalCategory @[simps] instance (X : C) : MonoidalCategory (X ⟶ X) where tensorObj f g := f ≫ g whiskerLeft {f _ _} η := f ◁ η whiskerRight {_ _} η h := η ▷ h tensorUnit := 𝟙 _ associator f g h := α_ f g h leftUnitor f := λ_ f rightUnitor f := ρ_ f tensorHom_comp_tensorHom := by intros dsimp only rw [Bicategory.whiskerLeft_comp, Bicategory.comp_whiskerRight, Category.assoc, Category.assoc, Bicategory.whisker_exchange_assoc] end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/SingleObj.lean
import Mathlib.CategoryTheory.Bicategory.End import Mathlib.CategoryTheory.Monoidal.Functor /-! # Promoting a monoidal category to a single object bicategory. A monoidal category can be thought of as a bicategory with a single object. The objects of the monoidal category become the 1-morphisms, with composition given by tensor product, and the morphisms of the monoidal category become the 2-morphisms. We verify that the endomorphisms of that single object recovers the original monoidal category. One could go much further: the bicategory of monoidal categories (equipped with monoidal functors and monoidal natural transformations) is equivalent to the bicategory consisting of * single object bicategories, * pseudofunctors, and * (oplax) natural transformations `η` such that `η.app Unit.unit = 𝟙 _`. -/ universe v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] [MonoidalCategory C] /-- Promote a monoidal category to a bicategory with a single object. (The objects of the monoidal category become the 1-morphisms, with composition given by tensor product, and the morphisms of the monoidal category become the 2-morphisms.) -/ @[nolint unusedArguments] def MonoidalSingleObj (C : Type u) [Category.{v} C] [MonoidalCategory C] := Unit deriving Inhabited open MonoidalCategory instance : Bicategory (MonoidalSingleObj C) where Hom _ _ := C id _ := 𝟙_ C comp X Y := tensorObj X Y whiskerLeft X _ _ f := X ◁ f whiskerRight f Z := f ▷ Z associator X Y Z := α_ X Y Z leftUnitor X := λ_ X rightUnitor X := ρ_ X whisker_exchange := whisker_exchange namespace MonoidalSingleObj /-- The unique object in the bicategory obtained by "promoting" a monoidal category. -/ @[nolint unusedArguments] protected def star : MonoidalSingleObj C := Unit.unit /-- The monoidal functor from the endomorphisms of the single object when we promote a monoidal category to a single object bicategory, to the original monoidal category. We subsequently show this is an equivalence. -/ @[simps] def endMonoidalStarFunctor : (EndMonoidal (MonoidalSingleObj.star C)) ⥤ C where obj X := X map f := f instance : (endMonoidalStarFunctor C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := Iso.refl _ μIso := fun _ _ ↦ Iso.refl _ } /-- The equivalence between the endomorphisms of the single object when we promote a monoidal category to a single object bicategory, and the original monoidal category. -/ @[simps] noncomputable def endMonoidalStarFunctorEquivalence : EndMonoidal (MonoidalSingleObj.star C) ≌ C where functor := endMonoidalStarFunctor C inverse := { obj := fun X => X map := fun f => f } unitIso := Iso.refl _ counitIso := Iso.refl _ instance endMonoidalStarFunctor_isEquivalence : (endMonoidalStarFunctor C).IsEquivalence := (endMonoidalStarFunctorEquivalence C).isEquivalence_functor end MonoidalSingleObj end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Opposites.lean
import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.Opposites /-! # Opposite bicategories We construct the 1-cell opposite of a bicategory `B`, called `Bᵒᵖ`. It is defined as follows * The objects of `Bᵒᵖ` correspond to objects of `B`. * The morphisms `X ⟶ Y` in `Bᵒᵖ` are the morphisms `Y ⟶ X` in `B`. * The 2-morphisms `f ⟶ g` in `Bᵒᵖ` are the 2-morphisms `f ⟶ g` in `B`. In other words, the directions of the 2-morphisms are preserved. ## Remarks There are multiple notions of opposite categories for bicategories. - There is 1-cell dual `Bᵒᵖ` as defined above. - There is the 2-cell dual, `Cᶜᵒ` where only the natural transformations are reversed - There is the bi-dual `Cᶜᵒᵒᵖ` where the directions of both the morphisms and the natural transformations are reversed. ## TODO * Define the 2-cell dual `Cᶜᵒ`. * Provide various lemmas for going between `LocallyDiscrete Cᵒᵖ` and `(LocallyDiscrete C)ᵒᵖ`. Note: `Cᶜᵒᵒᵖ` is WIP by Christian Merten. -/ universe w v u open CategoryTheory Bicategory Opposite namespace Bicategory.Opposite variable {B : Type u} [Bicategory.{w, v} B] /-- Type synonym for 2-morphisms in the opposite bicategory. -/ structure Hom2 {a b : Bᵒᵖ} (f g : a ⟶ b) where op2' :: /-- `Bᵒᵖ` preserves the direction of all 2-morphisms in `B` -/ unop2 : f.unop ⟶ g.unop open Hom2 @[simps!] instance homCategory (a b : Bᵒᵖ) : Category.{w} (a ⟶ b) where Hom f g := Hom2 f g id f := op2' (𝟙 f.unop) comp η θ := op2' (η.unop2 ≫ θ.unop2) /-- Synonym for constructor of `Hom2` where the 1-morphisms `f` and `g` lie in `B` and not `Bᵒᵖ`. -/ def op2 {a b : B} {f g : a ⟶ b} (η : f ⟶ g) : f.op ⟶ g.op := op2' η @[simp] theorem unop2_op2 {a b : B} {f g : a ⟶ b} (η : f ⟶ g) : (op2 η).unop2 = η := rfl @[simp] theorem op2_unop2 {a b : Bᵒᵖ} {f g : a ⟶ b} (η : f ⟶ g) : op2 η.unop2 = η := rfl @[simp] theorem op2_comp {a b : B} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) : op2 (η ≫ θ) = (op2 η) ≫ (op2 θ) := rfl @[simp] theorem op2_id {a b : B} {f : a ⟶ b} : op2 (𝟙 f) = 𝟙 f.op := rfl @[simp] theorem unop2_comp {a b : Bᵒᵖ} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) : unop2 (η ≫ θ) = unop2 η ≫ unop2 θ := rfl @[simp] theorem unop2_id {a b : Bᵒᵖ} {f : a ⟶ b} : unop2 (𝟙 f) = 𝟙 f.unop := rfl @[simp] theorem unop2_id_bop {a b : B} {f : a ⟶ b} : unop2 (𝟙 f.op) = 𝟙 f := rfl @[simp] theorem op2_id_unbop {a b : Bᵒᵖ} {f : a ⟶ b} : op2 (𝟙 f.unop) = 𝟙 f := rfl /-- The natural functor from the hom-category `a ⟶ b` in `B` to its bicategorical opposite `bop b ⟶ bop a`. -/ @[simps] def opFunctor (a b : B) : (a ⟶ b) ⥤ (op b ⟶ op a) where obj f := f.op map η := op2 η /-- The functor from the hom-category `a ⟶ b` in `Bᵒᵖ` to its bicategorical opposite `unop b ⟶ unop a`. -/ @[simps] def unopFunctor (a b : Bᵒᵖ) : (a ⟶ b) ⥤ (unop b ⟶ unop a) where obj f := f.unop map η := unop2 η end Bicategory.Opposite namespace CategoryTheory.Iso open Bicategory.Opposite variable {B : Type u} [Bicategory.{w, v} B] /-- A 2-isomorphism in `B` gives a 2-isomorphism in `Bᵒᵖ` -/ @[simps!] abbrev op2 {a b : B} {f g : a ⟶ b} (η : f ≅ g) : f.op ≅ g.op := (opFunctor a b).mapIso η /-- A 2-isomorphism in `B` gives a 2-isomorphism in `Bᵒᵖ` -/ @[simps!] abbrev op2_unop {a b : Bᵒᵖ} {f g : a ⟶ b} (η : f.unop ≅ g.unop) : f ≅ g := (opFunctor b.unop a.unop).mapIso η /-- A 2-isomorphism in `Bᵒᵖ` gives a 2-isomorphism in `B` -/ @[simps!] abbrev unop2 {a b : Bᵒᵖ} {f g : a ⟶ b} (η : f ≅ g) : f.unop ≅ g.unop := (unopFunctor a b).mapIso η /-- A 2-isomorphism in `Bᵒᵖ` gives a 2-isomorphism in `B` -/ @[simps!] abbrev unop2_op {a b : B} {f g : a ⟶ b} (η : f.op ≅ g.op) : f ≅ g := (unopFunctor (op b) (op a)).mapIso η @[simp] theorem unop2_op2 {a b : Bᵒᵖ} {f g : a ⟶ b} (η : f ≅ g) : η.unop2.op2 = η := rfl end CategoryTheory.Iso namespace Bicategory.Opposite open Hom2 variable {B : Type u} [Bicategory.{w, v} B] /-- The 1-cell dual bicategory `Bᵒᵖ`. It is defined as follows. * The objects of `Bᵒᵖ` correspond to objects of `B`. * The morphisms `X ⟶ Y` in `Bᵒᵖ` are the morphisms `Y ⟶ X` in `B`. * The 2-morphisms `f ⟶ g` in `Bᵒᵖ` are the 2-morphisms `f ⟶ g` in `B`. In other words, the directions of the 2-morphisms are preserved. -/ @[simps! homCategory_id_unop2 homCategory_comp_unop2 whiskerLeft_unop2 whiskerRight_unop2 associator_hom_unop2 associator_inv_unop2 leftUnitor_hom_unop2 leftUnitor_inv_unop2 rightUnitor_hom_unop2 rightUnitor_inv_unop2] instance bicategory : Bicategory.{w, v} Bᵒᵖ where homCategory := homCategory whiskerLeft f g h η := op2 <| (unop2 η) ▷ f.unop whiskerRight η h := op2 <| h.unop ◁ unop2 η associator f g h := (associator h.unop g.unop f.unop).op2_unop.symm leftUnitor f := (rightUnitor f.unop).op2_unop rightUnitor f := (leftUnitor f.unop).op2_unop whisker_exchange η θ := congrArg op2 <| (whisker_exchange _ _).symm whisker_assoc f g g' η i := congrArg op2 <| by simp pentagon f g h i := congrArg op2 <| by simp triangle f g := congrArg op2 <| by simp @[simp] lemma op2_whiskerLeft {a b c : B} {f : a ⟶ b} {g g' : b ⟶ c} (η : g ⟶ g') : op2 (f ◁ η) = (op2 η) ▷ f.op := rfl @[simp] lemma op2_whiskerRight {a b c : B} {f f' : a ⟶ b} {g : b ⟶ c} (η : f ⟶ f') : op2 (η ▷ g) = g.op ◁ (op2 η) := rfl @[simp] lemma op2_associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (α_ f g h).op2 = (α_ h.op g.op f.op).symm := rfl @[simp] lemma op2_associator_hom {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : op2 (α_ f g h).hom = (α_ h.op g.op f.op).symm.hom := rfl @[simp] lemma op2_associator_inv {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : op2 (α_ f g h).inv = (α_ h.op g.op f.op).symm.inv := rfl @[simp] lemma op2_leftUnitor {a b : B} (f : a ⟶ b) : (λ_ f).op2 = ρ_ f.op := rfl @[simp] lemma op2_leftUnitor_hom {a b : B} (f : a ⟶ b) : op2 (λ_ f).hom = (ρ_ f.op).hom := rfl @[simp] lemma op2_leftUnitor_inv {a b : B} (f : a ⟶ b) : op2 (λ_ f).inv = (ρ_ f.op).inv := rfl @[simp] lemma op2_rightUnitor {a b : B} (f : a ⟶ b) : (ρ_ f).op2 = λ_ f.op := rfl @[simp] lemma op2_rightUnitor_hom {a b : B} (f : a ⟶ b) : op2 (ρ_ f).hom = (λ_ f.op).hom := rfl @[simp] lemma op2_rightUnitor_inv {a b : B} (f : a ⟶ b) : op2 (ρ_ f).inv = (λ_ f.op).inv := rfl end Opposite end Bicategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Grothendieck.lean
import Mathlib.CategoryTheory.Bicategory.LocallyDiscrete import Mathlib.CategoryTheory.Bicategory.NaturalTransformation.Pseudo /-! # The Grothendieck and CoGrothendieck constructions ## The Grothendieck construction Given a category `𝒮` and any pseudofunctor `F` from `𝒮` to `Cat`, we associate to it a category `∫ F`, defined as follows: * Objects: pairs `(S, a)` where `S` is an object of the base category and `a` is an object of the category `F(S)`. * Morphisms: morphisms `(R, b) ⟶ (S, a)` are defined as pairs `(f, h)` where `f : R ⟶ S` is a morphism in `𝒮` and `h : F(f)(a) ⟶ b` The category `∫ F` is equipped with a projection functor `∫ F ⥤ 𝒮`, given by projecting to the first factors, i.e. * On objects, it sends `(S, a)` to `S` * On morphisms, it sends `(f, h)` to `f` ## The CoGrothendieck construction Given a category `𝒮` and any pseudofunctor `F` from `𝒮ᵒᵖ` to `Cat`, we associate to it a category `∫ᶜ F` (TODO: promote `CategoryStruct` to `Category` instance), defined as follows: * Objects: pairs `(S, a)` where `S` is an object of the base category and `a` is an object of the category `F(S)`. * Morphisms: morphisms `(R, b) ⟶ (S, a)` are defined as pairs `(f, h)` where `f : R ⟶ S` is a morphism in `𝒮` and `h : b ⟶ F(f)(a)` The category `∫ᶜ F` is equipped with a functor `∫ᶜ F ⥤ 𝒮` (TODO: define this functor), given by projecting to the first factors, i.e. * On objects, it sends `(S, a)` to `S` * On morphisms, it sends `(f, h)` to `f` ## Naming conventions The name `Grothendieck` is reserved for the construction on covariant pseudofunctors from `𝒮` to `Cat`, whereas the word `CoGrothendieck` is used for the contravariant construction. This is consistent with the convention for the Grothendieck construction on 1-functors `CategoryTheory.Grothendieck`. ## Future work / TODO 1. Once the bicategory of pseudofunctors has been defined, show that this construction forms a pseudofunctor from `LocallyDiscrete 𝒮 ⥤ᵖ Catᵒᵖ` to `Cat`. 2. Deduce the results in `CategoryTheory.Grothendieck` as a specialization of `Pseudofunctor.Grothendieck`. 3. Dualize all `CoGrothendieck` results to `Grothendieck`. ## References [Vistoli2008] "Notes on Grothendieck Topologies, Fibered Categories and Descent Theory" by Angelo Vistoli -/ namespace CategoryTheory.Pseudofunctor universe w v₁ v₂ v₃ u₁ u₂ u₃ open Functor Category Opposite Discrete Bicategory StrongTrans variable {𝒮 : Type u₁} [Category.{v₁} 𝒮] /-- The type of objects in the fibered category associated to a pseudofunctor from a 1-category to Cat. -/ @[ext] structure Grothendieck (F : LocallyDiscrete 𝒮 ⥤ᵖ Cat.{v₂, u₂}) where /-- The underlying object in the base category. -/ base : 𝒮 /-- The object in the fiber of the base object. -/ fiber : F.obj ⟨base⟩ namespace Grothendieck variable {F : LocallyDiscrete 𝒮 ⥤ᵖ Cat.{v₂, u₂}} /-- Notation for the Grothendieck category associated to a pseudofunctor `F`. -/ scoped prefix:75 "∫ " => Grothendieck /-- A morphism in the Grothendieck construction `∫ F` between two points `X Y : ∫ F` consists of a morphism in the base category `base : X.base ⟶ Y.base` and a morphism in a fiber `f.fiber : (F.map base).obj X.fiber ⟶ Y.fiber`. -/ structure Hom (X Y : ∫ F) where /-- The morphism between base objects. -/ base : X.base ⟶ Y.base /-- The morphism in the fiber over the domain. -/ fiber : (F.map base.toLoc).obj X.fiber ⟶ Y.fiber @[simps! id_base id_fiber comp_base comp_fiber] instance categoryStruct : CategoryStruct (∫ F) where Hom X Y := Hom X Y id X := { base := 𝟙 X.base fiber := (F.mapId ⟨X.base⟩).hom.app X.fiber } comp {X _ _} f g := { base := f.base ≫ g.base fiber := (F.mapComp f.base.toLoc g.base.toLoc).hom.app X.fiber ≫ (F.map g.base.toLoc).map f.fiber ≫ g.fiber } instance (X : ∫ F) : Inhabited (Hom X X) := ⟨𝟙 X⟩ end Grothendieck /-- The type of objects in the fibered category associated to a contravariant pseudofunctor from a 1-category to Cat. -/ @[ext] structure CoGrothendieck (F : LocallyDiscrete 𝒮ᵒᵖ ⥤ᵖ Cat.{v₂, u₂}) where /-- The underlying object in the base category. -/ base : 𝒮 /-- The object in the fiber of the base object. -/ fiber : F.obj ⟨op base⟩ namespace CoGrothendieck variable {F : LocallyDiscrete 𝒮ᵒᵖ ⥤ᵖ Cat.{v₂, u₂}} /-- Notation for the CoGrothendieck category associated to a pseudofunctor `F`. -/ scoped prefix:75 "∫ᶜ " => CoGrothendieck /-- A morphism in the CoGrothendieck construction `∫ᶜ F` between two points `X Y : ∫ᶜ F` consists of a morphism in the base category `base : X.base ⟶ Y.base` and a morphism in a fiber `f.fiber : X.fiber ⟶ (F.map base.op.toLoc).obj Y.fiber`. -/ structure Hom (X Y : ∫ᶜ F) where /-- The morphism between base objects. -/ base : X.base ⟶ Y.base /-- The morphism in the fiber over the domain. -/ fiber : X.fiber ⟶ (F.map base.op.toLoc).obj Y.fiber @[simps! id_base id_fiber comp_base comp_fiber] instance categoryStruct : CategoryStruct (∫ᶜ F) where Hom X Y := Hom X Y id X := { base := 𝟙 X.base fiber := (F.mapId ⟨op X.base⟩).inv.app X.fiber } comp {_ _ Z} f g := { base := f.base ≫ g.base fiber := f.fiber ≫ (F.map f.base.op.toLoc).map g.fiber ≫ (F.mapComp g.base.op.toLoc f.base.op.toLoc).inv.app Z.fiber } section variable {a b : ∫ᶜ F} @[ext (iff := false)] lemma Hom.ext (f g : a ⟶ b) (hfg₁ : f.base = g.base) (hfg₂ : f.fiber = g.fiber ≫ eqToHom (hfg₁ ▸ rfl)) : f = g := by cases f; cases g congr dsimp at hfg₁ rw [← conj_eqToHom_iff_heq _ _ rfl (hfg₁ ▸ rfl)] simpa only [eqToHom_refl, id_comp] using hfg₂ lemma Hom.ext_iff (f g : a ⟶ b) : f = g ↔ ∃ (hfg : f.base = g.base), f.fiber = g.fiber ≫ eqToHom (hfg ▸ rfl) where mp hfg := ⟨by rw [hfg], by simp [hfg]⟩ mpr := fun ⟨hfg₁, hfg₂⟩ => Hom.ext f g hfg₁ hfg₂ lemma Hom.congr {a b : ∫ᶜ F} {f g : a ⟶ b} (h : f = g) : f.fiber = g.fiber ≫ eqToHom (h ▸ rfl) := by simp [h] end attribute [local simp] PrelaxFunctor.map₂_eqToHom in /-- The category structure on `∫ᶜ F`. -/ instance category : Category (∫ᶜ F) where toCategoryStruct := Pseudofunctor.CoGrothendieck.categoryStruct id_comp {a b} f := by ext · simp · simp [F.mapComp_id_right_inv_app, Strict.rightUnitor_eqToIso, ← NatTrans.naturality_assoc] comp_id {a b} f := by ext · simp · simp [F.mapComp_id_left_inv_app, ← Functor.map_comp_assoc, Strict.leftUnitor_eqToIso] assoc f g h := by ext · simp · simp [← NatTrans.naturality_assoc, F.mapComp_assoc_right_inv_app, Strict.associator_eqToIso] variable (F) /-- The projection `∫ᶜ F ⥤ 𝒮` given by projecting both objects and homs to the first factor. -/ @[simps] def forget (F : LocallyDiscrete 𝒮ᵒᵖ ⥤ᵖ Cat.{v₂, u₂}) : ∫ᶜ F ⥤ 𝒮 where obj X := X.base map f := f.base section attribute [local simp] Strict.leftUnitor_eqToIso Strict.rightUnitor_eqToIso Strict.associator_eqToIso variable {F} {G : LocallyDiscrete 𝒮ᵒᵖ ⥤ᵖ Cat.{v₂, u₂}} {H : LocallyDiscrete 𝒮ᵒᵖ ⥤ᵖ Cat.{v₂, u₂}} /-- The CoGrothendieck construction is functorial: a strong natural transformation `α : F ⟶ G` induces a functor `CoGrothendieck.map : ∫ᶜ F ⥤ ∫ᶜ G`. -/ @[simps!] def map (α : F ⟶ G) : ∫ᶜ F ⥤ ∫ᶜ G where obj a := { base := a.base fiber := (α.app ⟨op a.base⟩).obj a.fiber } map {a b} f := { base := f.1 fiber := (α.app ⟨op a.base⟩).map f.2 ≫ (α.naturality f.1.op.toLoc).hom.app b.fiber } map_id a := by ext1 · dsimp · simp [StrongTrans.naturality_id_hom_app, ← Functor.map_comp_assoc] map_comp {a b c} f g := by ext · dsimp · dsimp simp only [StrongTrans.naturality_comp_hom_app, map_comp, assoc, comp_id] slice_lhs 2 4 => simp only [← Functor.map_comp, Iso.inv_hom_id_app, Cat.comp_obj, comp_id] simp [← Functor.comp_map] @[simp] lemma map_id_map {x y : ∫ᶜ F} (f : x ⟶ y) : (map (𝟙 F)).map f = f := by ext <;> simp @[simp] theorem map_comp_forget (α : F ⟶ G) : map α ⋙ forget G = forget F := rfl section variable (F) /-- The natural isomorphism witnessing the pseudo-unity constraint of `CoGrothendieck.map`. -/ def mapIdIso : map (𝟙 F) ≅ 𝟭 (∫ᶜ F) := NatIso.ofComponents (fun _ ↦ eqToIso (by cat_disch)) lemma map_id_eq : map (𝟙 F) = 𝟭 (∫ᶜ F) := Functor.ext_of_iso (mapIdIso F) (fun x ↦ by simp [map]) (fun x ↦ by simp [mapIdIso]) end /-- The natural isomorphism witnessing the pseudo-functoriality of `CoGrothendieck.map`. -/ def mapCompIso (α : F ⟶ G) (β : G ⟶ H) : map (α ≫ β) ≅ map α ⋙ map β := NatIso.ofComponents (fun _ ↦ eqToIso (by cat_disch)) (fun f ↦ by dsimp simp only [comp_id, id_comp] ext <;> simp) lemma map_comp_eq (α : F ⟶ G) (β : G ⟶ H) : map (α ≫ β) = map α ⋙ map β := Functor.ext_of_iso (mapCompIso α β) (fun _ ↦ by simp [map]) (fun _ ↦ by simp [mapCompIso]) end end Pseudofunctor.CoGrothendieck end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/EqToHom.lean
import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Bicategory.Basic /-! # `eqToHom` in bicategories This file records some of the behavior of `eqToHom` 1-morphisms and 2-morphisms in bicategories. Given an equality of objects `h : x = y` in a bicategory, there is a 1-morphism `eqToHom h : x ⟶ y` just like in an ordinary category. The definitional property of this morphism is that if `h : x = x`, `eqToHom h = 𝟙 x`. This is implemented as the `eqToHom` morphism in the `CategoryStruct` underlying the bicategory. Unlike the situation in ordinary category theory, these 1-morphisms do not compose strictly: `eqToHom h.trans h'` is merely isomorphic to `eqToHom h ≫ eqToHom h'`. We define this isomorphism as `CategoryTheory.Bicategory.eqToHomTransIso`. Given an equality of 1-morphisms, we show that various bicategorical structure morphisms such as unitors, associators and whiskering conjugate well under `eqToHom`s. ## TODO * Define `eqToEquiv` that puts the `eqToHom`s in an `Equivalence` between objects. -/ universe w v u namespace CategoryTheory.Bicategory variable {B : Type u} [Bicategory.{w, v} B] /-- In a bicategory, `eqToHom`s do not compose strictly, but they do up to isomorphism. -/ def eqToHomTransIso {x y z : B} (e₁ : x = y) (e₂ : y = z) : eqToHom (e₁.trans e₂) ≅ eqToHom e₁ ≫ eqToHom e₂ := e₂ ▸ e₁ ▸ (λ_ (𝟙 x)).symm @[simp] lemma eqToHomTransIso_refl_refl (x : B) : eqToHomTransIso (rfl : x = x) rfl = (λ_ (𝟙 x)).symm := rfl lemma eqToHomTransIso_refl_right {x y : B} (e₁ : x = y) : eqToHomTransIso e₁ rfl = (ρ_ (eqToHom e₁)).symm := by ext subst e₁ simp lemma eqToHomTransIso_refl_left {x y : B} (e₁ : x = y) : eqToHomTransIso rfl e₁ = (λ_ (eqToHom e₁)).symm := by ext subst e₁ simp @[reassoc] lemma associator_eqToHom_hom {x y z t : B} (e₁ : x = y) (e₂ : y = z) (e₃ : z = t) : (α_ (eqToHom e₁) (eqToHom e₂) (eqToHom e₃)).hom = (eqToHomTransIso e₁ e₂).inv ▷ eqToHom e₃ ≫ (eqToHomTransIso (e₁.trans e₂) e₃).inv ≫ (eqToHomTransIso e₁ (e₂.trans e₃)).hom ≫ eqToHom e₁ ◁ (eqToHomTransIso e₂ e₃).hom := by subst_vars simp @[reassoc] lemma associator_eqToHom_inv {x y z t : B} (e₁ : x = y) (e₂ : y = z) (e₃ : z = t) : (α_ (eqToHom e₁) (eqToHom e₂) (eqToHom e₃)).inv = eqToHom e₁ ◁ (eqToHomTransIso e₂ e₃).inv ≫ (eqToHomTransIso e₁ (e₂.trans e₃)).inv ≫ (eqToHomTransIso (e₁.trans e₂) e₃).hom ≫ (eqToHomTransIso e₁ e₂).hom ▷ eqToHom e₃ := by subst_vars simp lemma associator_hom_congr {x y z t : B} {f f' : x ⟶ y} {g g' : y ⟶ z} {h h' : z ⟶ t} (ef : f = f') (eg : g = g') (eh : h = h') : (α_ f g h).hom = eqToHom (by grind) ≫ (α_ f' g' h').hom ≫ eqToHom (by grind) := by subst_vars simp lemma associator_inv_congr {x y z t : B} {f f' : x ⟶ y} {g g' : y ⟶ z} {h h' : z ⟶ t} (ef : f = f') (eg : g = g') (eh : h = h') : (α_ f g h).inv = eqToHom (by grind) ≫ (α_ f' g' h').inv ≫ eqToHom (by grind) := by subst_vars simp lemma congr_whiskerLeft {x y : B} {f f' : x ⟶ y} (h : f = f') {z : B} {g g' : y ⟶ z} (η : g ⟶ g') : f ◁ η = eqToHom (by rw [h]) ≫ f' ◁ η ≫ eqToHom (by rw [h]) := by subst h simp lemma whiskerRight_congr {y z : B} {g g' : y ⟶ z} (h : g = g') {x : B} {f f' : x ⟶ y} (η : f ⟶ f') : η ▷ g = eqToHom (by rw [h]) ≫ η ▷ g' ≫ eqToHom (by rw [h]) := by subst h simp lemma leftUnitor_hom_congr {x y : B} {f f' : x ⟶ y} (h : f = f') : (λ_ f).hom = 𝟙 _ ◁ (eqToHom h) ≫ (λ_ f').hom ≫ eqToHom h.symm := by subst h simp lemma leftUnitor_inv_congr {x y : B} {f f' : x ⟶ y} (h : f = f') : (λ_ f).inv = (eqToHom h) ≫ (λ_ f').inv ≫ 𝟙 _ ◁ eqToHom h.symm := by subst h simp lemma rightUnitor_hom_congr {x y : B} {f f' : x ⟶ y} (h : f = f') : (ρ_ f).hom = (eqToHom h) ▷ 𝟙 _ ≫ (ρ_ f').hom ≫ eqToHom h.symm := by subst h simp lemma rightUnitor_inv_congr {x y : B} {f f' : x ⟶ y} (h : f = f') : (ρ_ f).inv = (eqToHom h) ≫ (ρ_ f').inv ≫ eqToHom h.symm ▷ 𝟙 _ := by subst h simp end CategoryTheory.Bicategory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Free.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor /-! # Free bicategories We define the free bicategory over a quiver. In this bicategory, the 1-morphisms are freely generated by the arrows in the quiver, and the 2-morphisms are freely generated by the formal identities, the formal unitors, and the formal associators modulo the relation derived from the axioms of a bicategory. ## Main definitions * `FreeBicategory B`: the free bicategory over a quiver `B`. * `FreeBicategory.lift F`: the pseudofunctor from `FreeBicategory B` to `C` associated with a prefunctor `F` from `B` to `C`. -/ universe w w₁ w₂ v v₁ v₂ u u₁ u₂ namespace CategoryTheory open Category Bicategory open Bicategory /-- Free bicategory over a quiver. Its objects are the same as those in the underlying quiver. -/ def FreeBicategory (B : Type u) := B instance (B : Type u) : ∀ [Inhabited B], Inhabited (FreeBicategory B) := by intro h exact id h namespace FreeBicategory section variable {B : Type u} [Quiver.{v + 1} B] /-- 1-morphisms in the free bicategory. -/ inductive Hom : B → B → Type max u v | of {a b : B} (f : a ⟶ b) : Hom a b | id (a : B) : Hom a a | comp {a b c : B} (f : Hom a b) (g : Hom b c) : Hom a c instance (a b : B) [Inhabited (a ⟶ b)] : Inhabited (Hom a b) := ⟨Hom.of default⟩ instance quiver : Quiver.{max u v + 1} (FreeBicategory B) where Hom := fun a b : B => Hom a b instance categoryStruct : CategoryStruct.{max u v} (FreeBicategory B) where id := fun a : B => Hom.id a comp := @fun _ _ _ => Hom.comp /-- Representatives of 2-morphisms in the free bicategory. -/ inductive Hom₂ : ∀ {a b : FreeBicategory B}, (a ⟶ b) → (a ⟶ b) → Type max u v | id {a b} (f : a ⟶ b) : Hom₂ f f | vcomp {a b} {f g h : a ⟶ b} (η : Hom₂ f g) (θ : Hom₂ g h) : Hom₂ f h | whisker_left {a b c} (f : a ⟶ b) {g h : b ⟶ c} (η : Hom₂ g h) : Hom₂ (f ≫ g) (f ≫ h)-- `η` cannot be earlier than `h` since it is a recursive argument. | whisker_right {a b c} {f g : a ⟶ b} (h : b ⟶ c) (η : Hom₂ f g) : Hom₂ (f.comp h) (g.comp h) | associator {a b c d} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : Hom₂ ((f ≫ g) ≫ h) (f ≫ (g ≫ h)) | associator_inv {a b c d} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : Hom₂ (f ≫ (g ≫ h)) ((f ≫ g) ≫ h) | right_unitor {a b} (f : a ⟶ b) : Hom₂ (f ≫ (𝟙 b)) f | right_unitor_inv {a b} (f : a ⟶ b) : Hom₂ f (f ≫ (𝟙 b)) | left_unitor {a b} (f : a ⟶ b) : Hom₂ ((𝟙 a) ≫ f) f | left_unitor_inv {a b} (f : a ⟶ b) : Hom₂ f ((𝟙 a) ≫ f) section -- The following notations are only used in the definition of `Rel` to simplify the notation. local infixr:0 " ≫ " => Hom₂.vcomp local notation "𝟙" => Hom₂.id local notation f " ◁ " η => Hom₂.whisker_left f η local notation η " ▷ " h => Hom₂.whisker_right h η local notation "α_" => Hom₂.associator local notation "λ_" => Hom₂.left_unitor local notation "ρ_" => Hom₂.right_unitor local notation "α⁻¹_" => Hom₂.associator_inv local notation "λ⁻¹_" => Hom₂.left_unitor_inv local notation "ρ⁻¹_" => Hom₂.right_unitor_inv /-- Relations between 2-morphisms in the free bicategory. -/ inductive Rel : ∀ {a b : FreeBicategory B} {f g : a ⟶ b}, Hom₂ f g → Hom₂ f g → Prop | vcomp_right {a b} {f g h : Hom a b} (η : Hom₂ f g) (θ₁ θ₂ : Hom₂ g h) : Rel θ₁ θ₂ → Rel (η ≫ θ₁) (η ≫ θ₂) | vcomp_left {a b} {f g h : Hom a b} (η₁ η₂ : Hom₂ f g) (θ : Hom₂ g h) : Rel η₁ η₂ → Rel (η₁ ≫ θ) (η₂ ≫ θ) | id_comp {a b} {f g : Hom a b} (η : Hom₂ f g) : Rel (𝟙 f ≫ η) η | comp_id {a b} {f g : Hom a b} (η : Hom₂ f g) : Rel (η ≫ 𝟙 g) η | assoc {a b} {f g h i : Hom a b} (η : Hom₂ f g) (θ : Hom₂ g h) (ι : Hom₂ h i) : Rel ((η ≫ θ) ≫ ι) (η ≫ θ ≫ ι) | whisker_left {a b c} (f : Hom a b) (g h : Hom b c) (η η' : Hom₂ g h) : Rel η η' → Rel (f ◁ η) (f ◁ η') | whisker_left_id {a b c} (f : Hom a b) (g : Hom b c) : Rel (f ◁ 𝟙 g) (𝟙 (f.comp g)) | whisker_left_comp {a b c} (f : Hom a b) {g h i : Hom b c} (η : Hom₂ g h) (θ : Hom₂ h i) : Rel (f ◁ η ≫ θ) ((f ◁ η) ≫ f ◁ θ) | id_whisker_left {a b} {f g : Hom a b} (η : Hom₂ f g) : Rel (Hom.id a ◁ η) (λ_ f ≫ η ≫ λ⁻¹_ g) | comp_whisker_left {a b c d} (f : Hom a b) (g : Hom b c) {h h' : Hom c d} (η : Hom₂ h h') : Rel (f.comp g ◁ η) (α_ f g h ≫ (f ◁ g ◁ η) ≫ α⁻¹_ f g h') | whisker_right {a b c} (f g : Hom a b) (h : Hom b c) (η η' : Hom₂ f g) : Rel η η' → Rel (η ▷ h) (η' ▷ h) | id_whisker_right {a b c} (f : Hom a b) (g : Hom b c) : Rel (𝟙 f ▷ g) (𝟙 (f.comp g)) | comp_whisker_right {a b c} {f g h : Hom a b} (i : Hom b c) (η : Hom₂ f g) (θ : Hom₂ g h) : Rel ((η ≫ θ) ▷ i) ((η ▷ i) ≫ θ ▷ i) | whisker_right_id {a b} {f g : Hom a b} (η : Hom₂ f g) : Rel (η ▷ Hom.id b) (ρ_ f ≫ η ≫ ρ⁻¹_ g) | whisker_right_comp {a b c d} {f f' : Hom a b} (g : Hom b c) (h : Hom c d) (η : Hom₂ f f') : Rel (η ▷ g.comp h) (α⁻¹_ f g h ≫ ((η ▷ g) ▷ h) ≫ α_ f' g h) | whisker_assoc {a b c d} (f : Hom a b) {g g' : Hom b c} (η : Hom₂ g g') (h : Hom c d) : Rel ((f ◁ η) ▷ h) (α_ f g h ≫ (f ◁ η ▷ h) ≫ α⁻¹_ f g' h) | whisker_exchange {a b c} {f g : Hom a b} {h i : Hom b c} (η : Hom₂ f g) (θ : Hom₂ h i) : Rel ((f ◁ θ) ≫ η ▷ i) ((η ▷ h) ≫ g ◁ θ) | associator_hom_inv {a b c d} (f : Hom a b) (g : Hom b c) (h : Hom c d) : Rel (α_ f g h ≫ α⁻¹_ f g h) (𝟙 ((f.comp g).comp h)) | associator_inv_hom {a b c d} (f : Hom a b) (g : Hom b c) (h : Hom c d) : Rel (α⁻¹_ f g h ≫ α_ f g h) (𝟙 (f.comp (g.comp h))) | left_unitor_hom_inv {a b} (f : Hom a b) : Rel (λ_ f ≫ λ⁻¹_ f) (𝟙 ((Hom.id a).comp f)) | left_unitor_inv_hom {a b} (f : Hom a b) : Rel (λ⁻¹_ f ≫ λ_ f) (𝟙 f) | right_unitor_hom_inv {a b} (f : Hom a b) : Rel (ρ_ f ≫ ρ⁻¹_ f) (𝟙 (f.comp (Hom.id b))) | right_unitor_inv_hom {a b} (f : Hom a b) : Rel (ρ⁻¹_ f ≫ ρ_ f) (𝟙 f) | pentagon {a b c d e} (f : Hom a b) (g : Hom b c) (h : Hom c d) (i : Hom d e) : Rel ((α_ f g h ▷ i) ≫ α_ f (g.comp h) i ≫ f ◁ α_ g h i) (α_ (f.comp g) h i ≫ α_ f g (h.comp i)) | triangle {a b c} (f : Hom a b) (g : Hom b c) : Rel (α_ f (Hom.id b) g ≫ f ◁ λ_ g) (ρ_ f ▷ g) end instance homCategory (a b : FreeBicategory B) : Category (a ⟶ b) where Hom f g := Quot (@Rel _ _ a b f g) id f := Quot.mk Rel (Hom₂.id f) comp := @fun _ _ _ => Quot.map₂ Hom₂.vcomp Rel.vcomp_right Rel.vcomp_left id_comp := by rintro f g ⟨η⟩ exact Quot.sound (Rel.id_comp η) comp_id := by rintro f g ⟨η⟩ exact Quot.sound (Rel.comp_id η) assoc := by rintro f g h i ⟨η⟩ ⟨θ⟩ ⟨ι⟩ exact Quot.sound (Rel.assoc η θ ι) /-- Bicategory structure on the free bicategory. -/ instance bicategory : Bicategory (FreeBicategory B) where homCategory := @fun (a b : B) => FreeBicategory.homCategory a b whiskerLeft := @fun _ _ _ f g h η => Quot.map (Hom₂.whisker_left f) (Rel.whisker_left f g h) η whiskerLeft_id := @fun _ _ _ f g => Quot.sound (Rel.whisker_left_id f g) associator := @fun _ _ _ _ f g h => { hom := Quot.mk Rel (Hom₂.associator f g h) inv := Quot.mk Rel (Hom₂.associator_inv f g h) hom_inv_id := Quot.sound (Rel.associator_hom_inv f g h) inv_hom_id := Quot.sound (Rel.associator_inv_hom f g h) } leftUnitor := @fun _ _ f => { hom := Quot.mk Rel (Hom₂.left_unitor f) inv := Quot.mk Rel (Hom₂.left_unitor_inv f) hom_inv_id := Quot.sound (Rel.left_unitor_hom_inv f) inv_hom_id := Quot.sound (Rel.left_unitor_inv_hom f) } rightUnitor := @fun _ _ f => { hom := Quot.mk Rel (Hom₂.right_unitor f) inv := Quot.mk Rel (Hom₂.right_unitor_inv f) hom_inv_id := Quot.sound (Rel.right_unitor_hom_inv f) inv_hom_id := Quot.sound (Rel.right_unitor_inv_hom f) } whiskerLeft_comp := by rintro a b c f g h i ⟨η⟩ ⟨θ⟩ exact Quot.sound (Rel.whisker_left_comp f η θ) id_whiskerLeft := by rintro a b f g ⟨η⟩ exact Quot.sound (Rel.id_whisker_left η) comp_whiskerLeft := by rintro a b c d f g h h' ⟨η⟩ exact Quot.sound (Rel.comp_whisker_left f g η) whiskerRight := @fun _ _ _ f g η h => Quot.map (Hom₂.whisker_right h) (Rel.whisker_right f g h) η id_whiskerRight := @fun _ _ _ f g => Quot.sound (Rel.id_whisker_right f g) comp_whiskerRight := by rintro a b c f g h ⟨η⟩ ⟨θ⟩ i exact Quot.sound (Rel.comp_whisker_right i η θ) whiskerRight_id := by rintro a b f g ⟨η⟩ exact Quot.sound (Rel.whisker_right_id η) whiskerRight_comp := by rintro a b c d f f' ⟨η⟩ g h exact Quot.sound (Rel.whisker_right_comp g h η) whisker_assoc := by rintro a b c d f g g' ⟨η⟩ h exact Quot.sound (Rel.whisker_assoc f η h) whisker_exchange := by rintro a b c f g h i ⟨η⟩ ⟨θ⟩ exact Quot.sound (Rel.whisker_exchange η θ) pentagon := @fun _ _ _ _ _ f g h i => Quot.sound (Rel.pentagon f g h i) triangle := @fun _ _ _ f g => Quot.sound (Rel.triangle f g) variable {a b c d : FreeBicategory B} /-- `Hom₂.mk η` is an abbreviation for `Quot.mk Rel η`. -/ abbrev Hom₂.mk {f g : a ⟶ b} (η : Hom₂ f g) : f ⟶ g := Quot.mk Rel η @[simp] theorem mk_vcomp {f g h : a ⟶ b} (η : Hom₂ f g) (θ : Hom₂ g h) : (η.vcomp θ).mk = (η.mk ≫ θ.mk : f ⟶ h) := rfl @[simp] theorem mk_whisker_left (f : a ⟶ b) {g h : b ⟶ c} (η : Hom₂ g h) : (Hom₂.whisker_left f η).mk = (f ◁ η.mk : f ≫ g ⟶ f ≫ h) := rfl @[simp] theorem mk_whisker_right {f g : a ⟶ b} (η : Hom₂ f g) (h : b ⟶ c) : (Hom₂.whisker_right h η).mk = (η.mk ▷ h : f ≫ h ⟶ g ≫ h) := rfl variable (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) theorem id_def : Hom.id (B := B) a = 𝟙 a := rfl theorem comp_def : Hom.comp f g = f ≫ g := rfl @[simp] theorem mk_id : Quot.mk _ (Hom₂.id f) = 𝟙 f := rfl @[simp] theorem mk_associator_hom : Quot.mk _ (Hom₂.associator f g h) = (α_ f g h).hom := rfl @[simp] theorem mk_associator_inv : Quot.mk _ (Hom₂.associator_inv f g h) = (α_ f g h).inv := rfl @[simp] theorem mk_left_unitor_hom : Quot.mk _ (Hom₂.left_unitor f) = (λ_ f).hom := rfl @[simp] theorem mk_left_unitor_inv : Quot.mk _ (Hom₂.left_unitor_inv f) = (λ_ f).inv := rfl @[simp] theorem mk_right_unitor_hom : Quot.mk _ (Hom₂.right_unitor f) = (ρ_ f).hom := rfl @[simp] theorem mk_right_unitor_inv : Quot.mk _ (Hom₂.right_unitor_inv f) = (ρ_ f).inv := rfl /-- Canonical prefunctor from `B` to `free_bicategory B`. -/ @[simps] def of : Prefunctor B (FreeBicategory B) where obj := id map := @fun _ _ => Hom.of end section variable {B : Type u₁} [Quiver.{v₁ + 1} B] {C : Type u₂} [CategoryStruct.{v₂} C] variable (F : Prefunctor B C) /-- Auxiliary definition for `lift`. -/ @[simp] def liftHom : ∀ {a b : FreeBicategory B}, (a ⟶ b) → (F.obj a ⟶ F.obj b) | _, _, Hom.of f => F.map f | _, _, Hom.id a => 𝟙 (F.obj a) | _, _, Hom.comp f g => liftHom f ≫ liftHom g @[simp] theorem liftHom_id (a : FreeBicategory B) : liftHom F (𝟙 a) = 𝟙 (F.obj a) := rfl @[simp] theorem liftHom_comp {a b c : FreeBicategory B} (f : a ⟶ b) (g : b ⟶ c) : liftHom F (f ≫ g) = liftHom F f ≫ liftHom F g := rfl end section variable {B : Type u₁} [Quiver.{v₁ + 1} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] variable (F : Prefunctor B C) /-- Auxiliary definition for `lift`. -/ def liftHom₂ : ∀ {a b : FreeBicategory B} {f g : a ⟶ b}, Hom₂ f g → (liftHom F f ⟶ liftHom F g) | _, _, _, _, Hom₂.id _ => 𝟙 _ | _, _, _, _, Hom₂.associator _ _ _ => (α_ _ _ _).hom | _, _, _, _, Hom₂.associator_inv _ _ _ => (α_ _ _ _).inv | _, _, _, _, Hom₂.left_unitor _ => (λ_ _).hom | _, _, _, _, Hom₂.left_unitor_inv _ => (λ_ _).inv | _, _, _, _, Hom₂.right_unitor _ => (ρ_ _).hom | _, _, _, _, Hom₂.right_unitor_inv _ => (ρ_ _).inv | _, _, _, _, Hom₂.vcomp η θ => liftHom₂ η ≫ liftHom₂ θ | _, _, _, _, Hom₂.whisker_left f η => liftHom F f ◁ liftHom₂ η | _, _, _, _, Hom₂.whisker_right h η => liftHom₂ η ▷ liftHom F h attribute [local simp] whisker_exchange in theorem liftHom₂_congr {a b : FreeBicategory B} {f g : a ⟶ b} {η θ : Hom₂ f g} (H : Rel η θ) : liftHom₂ F η = liftHom₂ F θ := by induction H <;> (dsimp [liftHom₂]; cat_disch) /-- A prefunctor from a quiver `B` to a bicategory `C` can be lifted to a pseudofunctor from `free_bicategory B` to `C`. -/ @[simps] def lift : FreeBicategory B ⥤ᵖ C where obj := F.obj map := liftHom F mapId _ := Iso.refl _ mapComp _ _ := Iso.refl _ map₂ := Quot.lift (liftHom₂ F) fun _ _ H => liftHom₂_congr F H -- Porting note: We'd really prefer not to be doing this by hand. -- in mathlib3 `tidy` did these inductions for us. map₂_comp := by intro a b f g h η θ induction η using Quot.rec · induction θ using Quot.rec <;> rfl · rfl map₂_whisker_left := by intro a b c f g h η induction η using Quot.rec · cat_disch · rfl map₂_whisker_right := by intro _ _ _ _ _ η h; dsimp; induction η using Quot.rec <;> cat_disch end end FreeBicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/LocallyDiscrete.lean
import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.Bicategory.Strict.Basic /-! # Locally discrete bicategories A category `C` can be promoted to a strict bicategory `LocallyDiscrete C`. The objects and the 1-morphisms in `LocallyDiscrete C` are the same as the objects and the morphisms, respectively, in `C`, and the 2-morphisms in `LocallyDiscrete C` are the equalities between 1-morphisms. In other words, the category consisting of the 1-morphisms between each pair of objects `X` and `Y` in `LocallyDiscrete C` is defined as the discrete category associated with the type `X ⟶ Y`. -/ namespace CategoryTheory open Bicategory Discrete universe w₂ w₁ v₂ v₁ v u₂ u₁ u section variable {C : Type u} /-- A wrapper for promoting any category to a bicategory, with the only 2-morphisms being equalities. -/ @[ext] structure LocallyDiscrete (C : Type u) where /-- A wrapper for promoting any category to a bicategory, with the only 2-morphisms being equalities. -/ as : C namespace LocallyDiscrete @[simp] theorem mk_as (a : LocallyDiscrete C) : mk a.as = a := rfl /-- `LocallyDiscrete C` is equivalent to the original type `C`. -/ @[simps] def locallyDiscreteEquiv : LocallyDiscrete C ≃ C where toFun := LocallyDiscrete.as invFun := LocallyDiscrete.mk left_inv := by cat_disch right_inv := by cat_disch instance [DecidableEq C] : DecidableEq (LocallyDiscrete C) := locallyDiscreteEquiv.decidableEq instance [Inhabited C] : Inhabited (LocallyDiscrete C) := ⟨⟨default⟩⟩ instance categoryStruct [CategoryStruct.{v} C] : CategoryStruct (LocallyDiscrete C) where Hom a b := Discrete (a.as ⟶ b.as) id a := ⟨𝟙 a.as⟩ comp f g := ⟨f.as ≫ g.as⟩ variable [CategoryStruct.{v} C] @[simp] lemma id_as (a : LocallyDiscrete C) : (𝟙 a : Discrete (a.as ⟶ a.as)).as = 𝟙 a.as := rfl @[simp] lemma comp_as {a b c : LocallyDiscrete C} (f : a ⟶ b) (g : b ⟶ c) : (f ≫ g).as = f.as ≫ g.as := rfl instance (priority := 900) homSmallCategory (a b : LocallyDiscrete C) : SmallCategory (a ⟶ b) := CategoryTheory.discreteCategory (a.as ⟶ b.as) /-- This instance is used to see through the synonym `a ⟶ b = Discrete (a.as ⟶ b.as)`. -/ instance subsingleton2Hom {a b : LocallyDiscrete C} (f g : a ⟶ b) : Subsingleton (f ⟶ g) := instSubsingletonDiscreteHom f g /-- Extract the equation from a 2-morphism in a locally discrete 2-category. -/ theorem eq_of_hom {X Y : LocallyDiscrete C} {f g : X ⟶ Y} (η : f ⟶ g) : f = g := Discrete.ext η.1.1 end LocallyDiscrete variable (C) variable [Category.{v} C] /-- The locally discrete bicategory on a category is a bicategory in which the objects and the 1-morphisms are the same as those in the underlying category, and the 2-morphisms are the equalities between 1-morphisms. -/ instance locallyDiscreteBicategory : Bicategory (LocallyDiscrete C) where whiskerLeft _ _ _ η := eqToHom (congr_arg₂ (· ≫ ·) rfl (LocallyDiscrete.eq_of_hom η)) whiskerRight η _ := eqToHom (congr_arg₂ (· ≫ ·) (LocallyDiscrete.eq_of_hom η) rfl) associator f g h := eqToIso <| by apply Discrete.ext; simp leftUnitor f := eqToIso <| by apply Discrete.ext; simp rightUnitor f := eqToIso <| by apply Discrete.ext; simp /-- A locally discrete bicategory is strict. -/ instance locallyDiscreteBicategory.strict : Strict (LocallyDiscrete C) where id_comp _ := Discrete.ext (Category.id_comp _) comp_id _ := Discrete.ext (Category.comp_id _) assoc _ _ _ := Discrete.ext (Category.assoc _ _ _) end namespace Bicategory /-- A bicategory is locally discrete if the categories of 1-morphisms are discrete. -/ abbrev IsLocallyDiscrete (B : Type*) [Bicategory B] := ∀ (b c : B), IsDiscrete (b ⟶ c) instance (C : Type*) [Category C] : IsLocallyDiscrete (LocallyDiscrete C) := fun _ _ ↦ Discrete.isDiscrete _ instance (B : Type*) [Bicategory B] [IsLocallyDiscrete B] : Strict B where id_comp f := obj_ext_of_isDiscrete (leftUnitor f).hom comp_id f := obj_ext_of_isDiscrete (rightUnitor f).hom assoc f g h := obj_ext_of_isDiscrete (associator f g h).hom end Bicategory end CategoryTheory section open CategoryTheory LocallyDiscrete universe v u namespace Quiver.Hom variable {C : Type u} [CategoryStruct.{v} C] /-- The 1-morphism in `LocallyDiscrete C` associated to a given morphism `f : a ⟶ b` in `C` -/ @[simps] def toLoc {a b : C} (f : a ⟶ b) : LocallyDiscrete.mk a ⟶ LocallyDiscrete.mk b := ⟨f⟩ @[simp] lemma id_toLoc (a : C) : (𝟙 a).toLoc = 𝟙 (LocallyDiscrete.mk a) := rfl @[simp, grind _=_] lemma comp_toLoc {a b c : C} (f : a ⟶ b) (g : b ⟶ c) : (f ≫ g).toLoc = f.toLoc ≫ g.toLoc := rfl end Quiver.Hom @[simp] lemma CategoryTheory.LocallyDiscrete.eqToHom_toLoc {C : Type u} [Category.{v} C] {a b : C} (h : a = b) : (eqToHom h).toLoc = eqToHom (congrArg LocallyDiscrete.mk h) := by subst h; rfl end
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/CatEnriched.lean
import Mathlib.CategoryTheory.Monoidal.Cartesian.Cat import Mathlib.CategoryTheory.Enriched.Basic import Mathlib.CategoryTheory.Enriched.Ordinary.Basic /-! # The strict bicategory associated to a Cat-enriched category If `C` is a type with a `EnrichedCategory Cat C` structure, then it has hom-categories, whose objects define 1-dimensional arrows on `C` and whose morphisms define 2-dimensional arrows between these. The enriched category axioms equip this data with the structure of a strict bicategory. We define a type alias `CatEnriched C` for a type `C` with a `EnrichedCategory Cat C` structure. We provide this with an instance of a strict bicategory structure constructing `Bicategory.Strict (CatEnriched C)`. If `C` is a type with a `EnrichedOrdinaryCategory Cat C` structure, then it has an `Enrichred Cat C` structure, so the previous construction would again produce a strict bicategory. However, in this setting `C` is also given a `Category C` structure, together with an equivalence between this category and the underlying category of the `Enriched Cat C`, and in examples the given category structure is the preferred one. Thus, we define a type alias `CatEnrichedOrdinary C` for a type `C` with an `EnrichedOrdinaryCategory Cat C` structure. We provide this with an instance of a strict bicategory structure extending the category structure provided by the given instance `Category C` constructing `Bicategory.Strict (CatEnrichedOrdinary C)`. -/ universe u v u' v' namespace CategoryTheory open Category section variable {C : Type*} [EnrichedCategory Cat C] /-- A type synonym for `C`, which should come equipped with a `Cat`-enriched category structure. This converts it to a strict bicategory where `Category (X ⟶ Y)` is `(X ⟶[Cat] Y)`. -/ def CatEnriched (C : Type*) := C namespace CatEnriched instance : EnrichedCategory Cat (CatEnriched C) := inferInstanceAs (EnrichedCategory Cat C) /-- Any enriched category has an underlying category structure defined by `ForgetEnrichment`. This is equivalent but not definitionally equal the category structure constructed here, which is more canonically associated to the data of an `EnrichedCategory Cat` structure. -/ instance : CategoryStruct (CatEnriched C) where Hom X Y := X ⟶[Cat] Y id X := (eId Cat X).obj ⟨⟨()⟩⟩ comp {X Y Z} f g := (eComp Cat X Y Z).obj (f, g) theorem id_eq (X : CatEnriched C) : 𝟙 X = (eId Cat X).obj ⟨⟨()⟩⟩ := rfl theorem comp_eq {X Y Z : CatEnriched C} (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ g = (eComp Cat X Y Z).obj (f, g) := rfl instance {X Y : CatEnriched C} : Category (X ⟶ Y) := inferInstanceAs (Category (X ⟶[Cat] Y).α) /-- The horizontal composition on 2-morphisms is defined using the action on arrows of the composition bifunctor from the enriched category structure. -/ def hComp {a b c : CatEnriched C} {f f' : a ⟶ b} {g g' : b ⟶ c} (η : f ⟶ f') (θ : g ⟶ g') : f ≫ g ⟶ f' ≫ g' := (eComp Cat a b c).map (η, θ) @[simp] theorem id_hComp_id {a b c : CatEnriched C} (f : a ⟶ b) (g : b ⟶ c) : hComp (𝟙 f) (𝟙 g) = 𝟙 (f ≫ g) := Functor.map_id .. @[simp] theorem eqToHom_hComp_eqToHom {a b c : CatEnriched C} {f f' : a ⟶ b} (α : f = f') {g g' : b ⟶ c} (β : g = g') : hComp (eqToHom α) (eqToHom β) = eqToHom (α ▸ β ▸ rfl) := by cases α; cases β; simp /-- The interchange law for horizontal and vertical composition of 2-cells in a bicategory. -/ @[simp] theorem hComp_comp {a b c : CatEnriched C} {f₁ f₂ f₃ : a ⟶ b} {g₁ g₂ g₃ : b ⟶ c} (η : f₁ ⟶ f₂) (η' : f₂ ⟶ f₃) (θ : g₁ ⟶ g₂) (θ' : g₂ ⟶ g₃) : hComp η θ ≫ hComp η' θ' = hComp (η ≫ η') (θ ≫ θ') := ((eComp Cat a b c).map_comp (Y := (_, _)) (_, _) (_, _)).symm /-- The action on objects of the `EnrichedCategory Cat` coherences proves the category axioms. -/ instance : Category (CatEnriched C) where id_comp {X Y} f := congrArg (·.obj f) (e_id_comp (V := Cat) X Y) comp_id {X Y} f := congrArg (·.obj f) (e_comp_id (V := Cat) X Y) assoc {X Y Z W} f g h := congrArg (·.obj (f, g, h)) (e_assoc (V := Cat) X Y Z W) /-- The category instance on `CatEnriched C` promotes it to a `Cat` enriched ordinary category. -/ instance : EnrichedOrdinaryCategory Cat (CatEnriched C) where homEquiv := Cat.fromChosenTerminalEquiv.symm homEquiv_comp _ _ := (Equiv.symm_apply_eq Cat.fromChosenTerminalEquiv).mpr rfl homEquiv_id _ := (Equiv.symm_apply_eq Cat.fromChosenTerminalEquiv).mpr rfl theorem id_hComp_heq {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') : HEq (hComp (𝟙 (𝟙 a)) η) η := by rw [id_eq, ← Functor.map_id] exact congr_arg_heq (·.map η) (e_id_comp (V := Cat) a b) theorem id_hComp {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') : hComp (𝟙 (𝟙 a)) η = eqToHom (id_comp f) ≫ η ≫ eqToHom (id_comp f').symm := by simp [← heq_eq_eq, id_hComp_heq] theorem hComp_id_heq {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') : HEq (hComp η (𝟙 (𝟙 b))) η := by rw [id_eq, ← Functor.map_id] exact congr_arg_heq (·.map η) (e_comp_id (V := Cat) a b) theorem hComp_id {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') : hComp η (𝟙 (𝟙 b)) = eqToHom (comp_id f) ≫ η ≫ eqToHom (comp_id f').symm := by simp [← heq_eq_eq, hComp_id_heq] theorem hComp_assoc_heq {a b c d : CatEnriched C} {f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d} (η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') : HEq (hComp (hComp η θ) κ) (hComp η (hComp θ κ)) := congr_arg_heq (·.map (X := (_, _, _)) (Y := (_, _, _)) (η, θ, κ)) (e_assoc (V := Cat) a b c d) theorem hComp_assoc {a b c d : CatEnriched C} {f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d} (η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') : hComp (hComp η θ) κ = eqToHom (assoc f g h) ≫ hComp η (hComp θ κ) ≫ eqToHom (assoc f' g' h').symm := by simp [← heq_eq_eq, hComp_assoc_heq] instance : Bicategory (CatEnriched C) where homCategory := inferInstance whiskerLeft {_ _ _} f {_ _} η := hComp (𝟙 f) η whiskerRight η h := hComp η (𝟙 h) associator f g h := eqToIso (assoc f g h) leftUnitor f := eqToIso (id_comp f) rightUnitor f := eqToIso (comp_id f) id_whiskerLeft := id_hComp comp_whiskerLeft := by simp [← id_hComp_id, hComp_assoc] whiskerRight_id := hComp_id whiskerRight_comp := by simp [hComp_assoc] whisker_assoc := by simp [hComp_assoc] pentagon f g h i := by generalize_proofs h1 h2 h3 h4; revert h1 h2 h3 h4 generalize (f ≫ g) ≫ h = x, (g ≫ h) ≫ i = w rintro rfl _ rfl _; simp triangle f g := by generalize_proofs h1 h2 h3; revert h1 h2 h3 generalize 𝟙 _ ≫ g = g, f ≫ 𝟙 _ = f rintro _ rfl rfl; simp /-- As the associator and left and right unitors are defined as eqToIso of category axioms, the bicategory structure on `CatEnriched C` is strict. -/ instance : Bicategory.Strict (CatEnriched C) where end CatEnriched end section variable {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory Cat.{v', u'} C] /-- A type synonym for `C`, which should come equipped with a `Cat`-enriched category structure. This converts it to a strict bicategory where `Category (X ⟶ Y)` is `(X ⟶[Cat] Y)`. -/ def CatEnrichedOrdinary (C : Type*) := C namespace CatEnrichedOrdinary instance : Category (CatEnrichedOrdinary C) := inferInstanceAs (Category C) instance : EnrichedCategory Cat (CatEnrichedOrdinary C) := inferInstanceAs (EnrichedCategory Cat C) instance : EnrichedOrdinaryCategory Cat (CatEnrichedOrdinary C) := inferInstanceAs (EnrichedOrdinaryCategory Cat C) /-- The forgetful map from the type alias associated to `EnrichedOrdinaryCategory Cat C` and the type alias associated to `EnrichedCategory Cat C` is the identity on underlying types. -/ def toBase (a : CatEnrichedOrdinary C) : CatEnriched C := a /-- The hom-types in a `Cat`-enriched ordinary category are equivalent to the types underlying the hom-categories. -/ def homEquiv {a b : CatEnrichedOrdinary C} : (a ⟶ b) ≃ (a.toBase ⟶ b.toBase) := (eHomEquiv (V := Cat)).trans Cat.fromChosenTerminalEquiv theorem homEquiv_id {a : CatEnrichedOrdinary C} : homEquiv (𝟙 a) = 𝟙 a.toBase := by unfold homEquiv simp only [Equiv.trans_apply] rw [eHomEquiv_id] rfl theorem homEquiv_comp {a b c : CatEnrichedOrdinary C} (f : a ⟶ b) (g : b ⟶ c) : homEquiv (f ≫ g) = homEquiv f ≫ homEquiv g := by unfold homEquiv simp only [Equiv.trans_apply] rw [eHomEquiv_comp] rfl /-- The 2-cells between a parallel pair of 1-cells `f g` in `CatEnrichedOrdinary C` are defined to be the morphisms in the hom-categories provided by the `EnrichedCategory Cat C` structure between the corresponding objects. -/ structure Hom {X Y : CatEnrichedOrdinary C} (f g : X ⟶ Y) where mk' :: /-- A 2-cell from `f` to `g` is a 2-cell from `homEquiv f` to `homEquiv g`. -/ base' : homEquiv f ⟶ homEquiv g instance {X Y : CatEnrichedOrdinary C} : Quiver (X ⟶ Y) where Hom f g := Hom f g /-- A 2-cell in `CatEnrichedOrdinary C` has a corresponding "base" 2-cell in `CatEnriched C`. -/ def Hom.base {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : f ⟶ g) : homEquiv f ⟶ homEquiv g := α.base' /-- A 2-cell in `CatEnriched C` can be "made" into a 2-cell in `CatEnrichedOrdinary C`. -/ def Hom.mk {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : homEquiv f ⟶ homEquiv g) : f ⟶ g := .mk' α @[simp] theorem mk_base {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : f ⟶ g) : Hom.mk (Hom.base α) = α := rfl @[simp] theorem base_mk {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : homEquiv f ⟶ homEquiv g) : Hom.base (Hom.mk α) = α := rfl instance {X Y : CatEnrichedOrdinary C} : CategoryStruct (X ⟶ Y) where id f := Hom.mk (𝟙 (homEquiv f)) comp α β := Hom.mk (Hom.base α ≫ Hom.base β) theorem Hom.id_eq {X Y : CatEnrichedOrdinary C} (f : X ⟶ Y) : 𝟙 f = Hom.mk (𝟙 (homEquiv f)) := rfl @[simp] theorem Hom.base_id {X Y : CatEnrichedOrdinary C} (f : X ⟶ Y) : Hom.base (𝟙 f) = 𝟙 (homEquiv f) := rfl theorem Hom.comp_eq {X Y : CatEnrichedOrdinary C} {f g h : X ⟶ Y} (α : f ⟶ g) (β : g ⟶ h) : (α ≫ β) = Hom.mk (Hom.base α ≫ Hom.base β) := rfl @[simp] theorem Hom.base_comp {X Y : CatEnrichedOrdinary C} {f g h : X ⟶ Y} (α : f ⟶ g) (β : g ⟶ h) : Hom.base (α ≫ β) = Hom.base α ≫ Hom.base β := rfl theorem Hom.mk_comp {X Y : CatEnrichedOrdinary C} {f g h : X ⟶ Y} (α : homEquiv f ⟶ homEquiv g) (β : homEquiv g ⟶ homEquiv h) : Hom.mk (α ≫ β) = Hom.mk α ≫ Hom.mk β := rfl @[ext] theorem Hom.ext {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α β : f ⟶ g) (H : Hom.base α = Hom.base β) : α = β := by cases α; cases β; cases H; rfl /-- A `Cat`-enriched ordinary category comes with hom-categories `X ⟶[Cat] Y` whose underlying type of objects is equivalent to the type `X ⟶ Y` defined by the category structure on `C`. The following definition transfers the category structure to the latter type of objects. -/ instance {X Y : CatEnrichedOrdinary C} : Category (X ⟶ Y) where @[simp] theorem Hom.base_eqToHom {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : f = g) : Hom.base (eqToHom α) = eqToHom (congrArg _ α) := by cases α; rfl /-- The horizontal composition on 2-morphisms is defined using the action on arrows of the composition bifunctor from the enriched category structure. -/ def hComp {a b c : CatEnrichedOrdinary C} {f f' : a ⟶ b} {g g' : b ⟶ c} (η : f ⟶ f') (θ : g ⟶ g') : f ≫ g ⟶ f' ≫ g' := .mk <| eqToHom (homEquiv_comp f g) ≫ CatEnriched.hComp (Hom.base η) (Hom.base θ) ≫ eqToHom (homEquiv_comp f' g').symm @[simp] theorem id_hComp_id {a b c : CatEnrichedOrdinary C} (f : a ⟶ b) (g : b ⟶ c) : hComp (𝟙 f) (𝟙 g) = 𝟙 (f ≫ g) := by simp [hComp, Hom.id_eq] @[simp] theorem eqToHom_hComp_eqToHom {a b c : CatEnrichedOrdinary C} {f f' : a ⟶ b} (α : f = f') {g g' : b ⟶ c} (β : g = g') : hComp (eqToHom α) (eqToHom β) = eqToHom (α ▸ β ▸ rfl) := by cases α; cases β; simp /-- The interchange law for horizontal and vertical composition of 2-cells in a bicategory. -/ @[simp] theorem hComp_comp {a b c : CatEnrichedOrdinary C} {f₁ f₂ f₃ : a ⟶ b} {g₁ g₂ g₃ : b ⟶ c} (η : f₁ ⟶ f₂) (η' : f₂ ⟶ f₃) (θ : g₁ ⟶ g₂) (θ' : g₂ ⟶ g₃) : hComp η θ ≫ hComp η' θ' = hComp (η ≫ η') (θ ≫ θ') := by simp [hComp, ← CatEnriched.hComp_comp, Hom.comp_eq] theorem id_hComp {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') : hComp (𝟙 (𝟙 a)) η = eqToHom (id_comp f) ≫ η ≫ eqToHom (id_comp f').symm := by ext simp only [hComp, Hom.base_id, base_mk, ← heq_eq_eq, eqToHom_comp_heq_iff, comp_eqToHom_heq_iff] rw [homEquiv_id]; simp [CatEnriched.id_hComp_heq] theorem id_hComp_heq {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') : HEq (hComp (𝟙 (𝟙 a)) η) η := by simp [id_hComp] theorem hComp_id {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') : hComp η (𝟙 (𝟙 b)) = eqToHom (comp_id f) ≫ η ≫ eqToHom (comp_id f').symm := by ext simp only [hComp, Hom.base_id, base_mk, ← heq_eq_eq, eqToHom_comp_heq_iff, comp_eqToHom_heq_iff] rw [homEquiv_id] simp [CatEnriched.hComp_id_heq] theorem hComp_id_heq {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') : HEq (hComp η (𝟙 (𝟙 b))) η := by simp [hComp_id] theorem id_eq_eqToHom {C} [Category C] (X : C) : 𝟙 X = eqToHom rfl := rfl theorem hComp_assoc {a b c d : CatEnrichedOrdinary C} {f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d} (η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') : hComp (hComp η θ) κ = eqToHom (assoc f g h) ≫ hComp η (hComp θ κ) ≫ eqToHom (assoc f' g' h').symm := by ext simp only [hComp, base_mk, Hom.base_comp, Hom.base_eqToHom, ← heq_eq_eq, heq_eqToHom_comp_iff, heq_comp_eqToHom_iff, eqToHom_comp_heq_iff, comp_eqToHom_heq_iff] conv => enter [1,2]; exact ((id_comp _).trans (comp_id _)).symm conv => enter [2,1]; exact ((id_comp _).trans (comp_id _)).symm iterate 4 rw [← CatEnriched.hComp_comp, id_eq_eqToHom, CatEnriched.eqToHom_hComp_eqToHom] simp [CatEnriched.hComp_assoc_heq] theorem hComp_assoc_heq {a b c d : CatEnrichedOrdinary C} {f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d} (η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') : HEq (hComp (hComp η θ) κ) (hComp η (hComp θ κ)) := by simp [hComp_assoc] instance : Bicategory (CatEnrichedOrdinary C) where homCategory := inferInstance whiskerLeft {_ _ _} f {_ _} η := hComp (𝟙 f) η whiskerRight η h := hComp η (𝟙 h) associator f g h := eqToIso (assoc f g h) leftUnitor f := eqToIso (id_comp f) rightUnitor f := eqToIso (comp_id f) id_whiskerLeft := by simp [id_hComp] comp_whiskerLeft := by simp [← hComp_assoc] whiskerRight_id := by simp [hComp_id] whiskerRight_comp := by simp [hComp_assoc] whisker_assoc := by simp [hComp_assoc] pentagon := by simp [id_eq_eqToHom, -eqToHom_refl] triangle := by simp [id_eq_eqToHom, -eqToHom_refl] /-- As the associator and left and right unitors are defined as eqToIso of category axioms, the bicategory structure on `CatEnrichedOrdinary C` is strict. -/ instance : Bicategory.Strict (CatEnrichedOrdinary C) where end CatEnrichedOrdinary end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Strict.lean
import Mathlib.CategoryTheory.Bicategory.Strict.Basic deprecated_module (since := "2025-10-02")
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/Oplax.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Prelax import Mathlib.Tactic.CategoryTheory.ToApp /-! # Oplax functors An oplax functor `F` between bicategories `B` and `C` consists of * a function between objects `F.obj : B ⟶ C`, * a family of functions between 1-morphisms `F.map : (a ⟶ b) → (F.obj a ⟶ F.obj b)`, * a family of functions between 2-morphisms `F.map₂ : (f ⟶ g) → (F.map f ⟶ F.map g)`, * a family of 2-morphisms `F.mapId a : F.map (𝟙 a) ⟶ 𝟙 (F.obj a)`, * a family of 2-morphisms `F.mapComp f g : F.map (f ≫ g) ⟶ F.map f ≫ F.map g`, and * certain consistency conditions on them. ## Main definitions * `CategoryTheory.OplaxFunctor B C` : an oplax functor between bicategories `B` and `C`, which we denote by `B ⥤ᵒᵖᴸ C`. * `CategoryTheory.OplaxFunctor.comp F G` : the composition of oplax functors -/ namespace CategoryTheory open Category Bicategory open Bicategory universe w₁ w₂ w₃ v₁ v₂ v₃ u₁ u₂ u₃ section variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] variable {D : Type u₃} [Bicategory.{w₃, v₃} D] /-- An oplax functor `F` between bicategories `B` and `C` consists of a function between objects `F.obj`, a function between 1-morphisms `F.map`, and a function between 2-morphisms `F.map₂`. Unlike functors between categories, `F.map` do not need to strictly commute with the composition, and do not need to strictly preserve the identity. Instead, there are specified 2-morphisms `F.map (𝟙 a) ⟶ 𝟙 (F.obj a)` and `F.map (f ≫ g) ⟶ F.map f ≫ F.map g`. `F.map₂` strictly commute with compositions and preserve the identity. They also preserve the associator, the left unitor, and the right unitor modulo some adjustments of domains and codomains of 2-morphisms. -/ structure OplaxFunctor (B : Type u₁) [Bicategory.{w₁, v₁} B] (C : Type u₂) [Bicategory.{w₂, v₂} C] extends PrelaxFunctor B C where /-- The 2-morphism underlying the oplax unity constraint. -/ mapId (a : B) : map (𝟙 a) ⟶ 𝟙 (obj a) /-- The 2-morphism underlying the oplax functoriality constraint. -/ mapComp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : map (f ≫ g) ⟶ map f ≫ map g /-- Naturality of the oplax functoriality constraint, on the left. -/ mapComp_naturality_left : ∀ {a b c : B} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c), map₂ (η ▷ g) ≫ mapComp f' g = mapComp f g ≫ map₂ η ▷ map g := by cat_disch /-- Naturality of the lax functoriality constraint, on the right. -/ mapComp_naturality_right : ∀ {a b c : B} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g'), map₂ (f ◁ η) ≫ mapComp f g' = mapComp f g ≫ map f ◁ map₂ η := by cat_disch /-- Oplax associativity. -/ map₂_associator : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), map₂ (α_ f g h).hom ≫ mapComp f (g ≫ h) ≫ map f ◁ mapComp g h = mapComp (f ≫ g) h ≫ mapComp f g ▷ map h ≫ (α_ (map f) (map g) (map h)).hom := by cat_disch /-- Oplax left unity. -/ map₂_leftUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (λ_ f).hom = mapComp (𝟙 a) f ≫ mapId a ▷ map f ≫ (λ_ (map f)).hom := by cat_disch /-- Oplax right unity. -/ map₂_rightUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (ρ_ f).hom = mapComp f (𝟙 b) ≫ map f ◁ mapId b ≫ (ρ_ (map f)).hom := by cat_disch /-- Notation for a pseudofunctor between bicategories. -/ -- Given similar precedence as ⥤ (26). scoped[CategoryTheory.Bicategory] infixr:26 " ⥤ᵒᵖᴸ " => OplaxFunctor -- type as \func\op\^L initialize_simps_projections OplaxFunctor (+toPrelaxFunctor, -obj, -map, -map₂) namespace OplaxFunctor attribute [reassoc (attr := simp), to_app (attr := simp)] mapComp_naturality_left mapComp_naturality_right map₂_associator attribute [simp, reassoc, to_app] map₂_leftUnitor map₂_rightUnitor section /-- The underlying prelax functor. -/ add_decl_doc OplaxFunctor.toPrelaxFunctor variable (F : B ⥤ᵒᵖᴸ C) @[reassoc, to_app] lemma mapComp_assoc_right {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : F.mapComp f (g ≫ h) ≫ F.map f ◁ F.mapComp g h = F.map₂ (α_ f g h).inv ≫ F.mapComp (f ≫ g) h ≫ F.mapComp f g ▷ F.map h ≫ (α_ (F.map f) (F.map g) (F.map h)).hom := by rw [← F.map₂_associator, ← F.map₂_comp_assoc] simp @[reassoc, to_app] lemma mapComp_assoc_left {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : F.mapComp (f ≫ g) h ≫ F.mapComp f g ▷ F.map h = F.map₂ (α_ f g h).hom ≫ F.mapComp f (g ≫ h) ≫ F.map f ◁ F.mapComp g h ≫ (α_ (F.map f) (F.map g) (F.map h)).inv := by simp @[reassoc] theorem mapComp_id_left {a b : B} (f : a ⟶ b) : F.mapComp (𝟙 a) f ≫ F.mapId a ▷ F.map f = F.map₂ (λ_ f).hom ≫ (λ_ (F.map f)).inv := by rw [Iso.eq_comp_inv] simp only [Category.assoc] rw [← F.map₂_leftUnitor] @[reassoc] theorem mapComp_id_right {a b : B} (f : a ⟶ b) : F.mapComp f (𝟙 b) ≫ F.map f ◁ F.mapId b = F.map₂ (ρ_ f).hom ≫ (ρ_ (F.map f)).inv := by rw [Iso.eq_comp_inv] simp only [Category.assoc] rw [← F.map₂_rightUnitor] /-- The identity oplax functor. -/ @[simps] def id (B : Type u₁) [Bicategory.{w₁, v₁} B] : B ⥤ᵒᵖᴸ B where toPrelaxFunctor := PrelaxFunctor.id B mapId := fun a => 𝟙 (𝟙 a) mapComp := fun f g => 𝟙 (f ≫ g) instance : Inhabited (B ⥤ᵒᵖᴸ B) := ⟨id B⟩ /-- More flexible variant of `mapId`. (See the file `Bicategory.Functor.Strict` for applications to strict bicategories.) -/ def mapId' {b : B} (f : b ⟶ b) (hf : f = 𝟙 b := by cat_disch) : F.map f ⟶ 𝟙 (F.obj b) := F.map₂ (eqToHom (by rw [hf])) ≫ F.mapId _ lemma mapId'_eq_mapId (b : B) : F.mapId' (𝟙 b) rfl = F.mapId b := by simp [mapId'] /-- More flexible variant of `mapComp`. (See `Bicategory.Functor.Strict` for applications to strict bicategories.) -/ def mapComp' {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (fg : b₀ ⟶ b₂) (h : f ≫ g = fg := by cat_disch) : F.map fg ⟶ F.map f ≫ F.map g := F.map₂ (eqToHom (by rw [h])) ≫ F.mapComp f g lemma mapComp'_eq_mapComp {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) : F.mapComp' f g _ rfl = F.mapComp f g := by simp [mapComp'] /-- Composition of oplax functors. -/ --@[simps] def comp (F : B ⥤ᵒᵖᴸ C) (G : C ⥤ᵒᵖᴸ D) : B ⥤ᵒᵖᴸ D where toPrelaxFunctor := F.toPrelaxFunctor.comp G.toPrelaxFunctor mapId := fun a => (G.mapFunctor _ _).map (F.mapId a) ≫ G.mapId (F.obj a) mapComp := fun f g => (G.mapFunctor _ _).map (F.mapComp f g) ≫ G.mapComp (F.map f) (F.map g) mapComp_naturality_left := fun η g => by dsimp rw [← G.map₂_comp_assoc, mapComp_naturality_left, G.map₂_comp_assoc, mapComp_naturality_left, assoc] mapComp_naturality_right := fun η => by dsimp intros rw [← G.map₂_comp_assoc, mapComp_naturality_right, G.map₂_comp_assoc, mapComp_naturality_right, assoc] map₂_associator := fun f g h => by dsimp simp only [map₂_associator, ← PrelaxFunctor.map₂_comp_assoc, ← mapComp_naturality_right_assoc, whiskerLeft_comp, assoc] simp only [map₂_associator, PrelaxFunctor.map₂_comp, mapComp_naturality_left_assoc, comp_whiskerRight, assoc] map₂_leftUnitor := fun f => by dsimp simp only [map₂_leftUnitor, PrelaxFunctor.map₂_comp, mapComp_naturality_left_assoc, comp_whiskerRight, assoc] map₂_rightUnitor := fun f => by dsimp simp only [map₂_rightUnitor, PrelaxFunctor.map₂_comp, mapComp_naturality_right_assoc, whiskerLeft_comp, assoc] /-- A structure on an oplax functor that promotes an oplax functor to a pseudofunctor. See `Pseudofunctor.mkOfOplax`. -/ structure PseudoCore (F : B ⥤ᵒᵖᴸ C) where /-- The isomorphism giving rise to the oplax unity constraint -/ mapIdIso (a : B) : F.map (𝟙 a) ≅ 𝟙 (F.obj a) /-- The isomorphism giving rise to the oplax functoriality constraint -/ mapCompIso {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : F.map (f ≫ g) ≅ F.map f ≫ F.map g /-- `mapIdIso` gives rise to the oplax unity constraint -/ mapIdIso_hom : ∀ {a : B}, (mapIdIso a).hom = F.mapId a := by cat_disch /-- `mapCompIso` gives rise to the oplax functoriality constraint -/ mapCompIso_hom : ∀ {a b c : B} (f : a ⟶ b) (g : b ⟶ c), (mapCompIso f g).hom = F.mapComp f g := by cat_disch attribute [simp] PseudoCore.mapIdIso_hom PseudoCore.mapCompIso_hom end end OplaxFunctor end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/Pseudofunctor.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Oplax import Mathlib.CategoryTheory.Bicategory.Functor.Lax import Mathlib.Tactic.CategoryTheory.ToApp /-! # Pseudofunctors A pseudofunctor is an oplax (or lax) functor whose `mapId` and `mapComp` are isomorphisms. We provide several constructors for pseudofunctors: * `Pseudofunctor.mk` : the default constructor, which requires `map₂_whiskerLeft` and `map₂_whiskerRight` instead of naturality of `mapComp`. * `Pseudofunctor.mkOfOplax` : construct a pseudofunctor from an oplax functor whose `mapId` and `mapComp` are isomorphisms. This constructor uses `Iso` to describe isomorphisms. * `pseudofunctor.mkOfOplax'` : similar to `mkOfOplax`, but uses `IsIso` to describe isomorphisms. * `Pseudofunctor.mkOfLax` : construct a pseudofunctor from a lax functor whose `mapId` and `mapComp` are isomorphisms. This constructor uses `Iso` to describe isomorphisms. * `pseudofunctor.mkOfLax'` : similar to `mkOfLax`, but uses `IsIso` to describe isomorphisms. ## Main definitions * `CategoryTheory.Pseudofunctor B C` : a pseudofunctor between bicategories `B` and `C`, which we denote by `B ⥤ᵖ C`. * `CategoryTheory.Pseudofunctor.comp F G` : the composition of pseudofunctors -/ namespace CategoryTheory open Category Bicategory universe w₁ w₂ w₃ v₁ v₂ v₃ u₁ u₂ u₃ variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] variable {D : Type u₃} [Bicategory.{w₃, v₃} D] /-- A pseudofunctor `F` between bicategories `B` and `C` consists of a function between objects `F.obj`, a function between 1-morphisms `F.map`, and a function between 2-morphisms `F.map₂`. Unlike functors between categories, `F.map` do not need to strictly commute with the compositions, and do not need to strictly preserve the identity. Instead, there are specified 2-isomorphisms `F.map (𝟙 a) ≅ 𝟙 (F.obj a)` and `F.map (f ≫ g) ≅ F.map f ≫ F.map g`. `F.map₂` strictly commute with compositions and preserve the identity. They also preserve the associator, the left unitor, and the right unitor modulo some adjustments of domains and codomains of 2-morphisms. -/ structure Pseudofunctor (B : Type u₁) [Bicategory.{w₁, v₁} B] (C : Type u₂) [Bicategory.{w₂, v₂} C] extends PrelaxFunctor B C where mapId (a : B) : map (𝟙 a) ≅ 𝟙 (obj a) mapComp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : map (f ≫ g) ≅ map f ≫ map g map₂_whisker_left : ∀ {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h), map₂ (f ◁ η) = (mapComp f g).hom ≫ map f ◁ map₂ η ≫ (mapComp f h).inv := by cat_disch map₂_whisker_right : ∀ {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c), map₂ (η ▷ h) = (mapComp f h).hom ≫ map₂ η ▷ map h ≫ (mapComp g h).inv := by cat_disch map₂_associator : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), map₂ (α_ f g h).hom = (mapComp (f ≫ g) h).hom ≫ (mapComp f g).hom ▷ map h ≫ (α_ (map f) (map g) (map h)).hom ≫ map f ◁ (mapComp g h).inv ≫ (mapComp f (g ≫ h)).inv := by cat_disch map₂_left_unitor : ∀ {a b : B} (f : a ⟶ b), map₂ (λ_ f).hom = (mapComp (𝟙 a) f).hom ≫ (mapId a).hom ▷ map f ≫ (λ_ (map f)).hom := by cat_disch map₂_right_unitor : ∀ {a b : B} (f : a ⟶ b), map₂ (ρ_ f).hom = (mapComp f (𝟙 b)).hom ≫ map f ◁ (mapId b).hom ≫ (ρ_ (map f)).hom := by cat_disch /-- Notation for a pseudofunctor between bicategories. -/ -- Given similar precedence as ⥤ (26). scoped[CategoryTheory.Bicategory] infixr:26 " ⥤ᵖ " => Pseudofunctor -- type as \func\^p initialize_simps_projections Pseudofunctor (+toPrelaxFunctor, -obj, -map, -map₂) namespace Pseudofunctor attribute [simp, reassoc, to_app] map₂_whisker_left map₂_whisker_right map₂_associator map₂_left_unitor map₂_right_unitor section open Iso /-- The underlying prelax functor. -/ add_decl_doc Pseudofunctor.toPrelaxFunctor attribute [nolint docBlame] CategoryTheory.Pseudofunctor.mapId CategoryTheory.Pseudofunctor.mapComp CategoryTheory.Pseudofunctor.map₂_whisker_left CategoryTheory.Pseudofunctor.map₂_whisker_right CategoryTheory.Pseudofunctor.map₂_associator CategoryTheory.Pseudofunctor.map₂_left_unitor CategoryTheory.Pseudofunctor.map₂_right_unitor variable (F : B ⥤ᵖ C) /-- The oplax functor associated with a pseudofunctor. -/ @[simps] def toOplax : B ⥤ᵒᵖᴸ C where toPrelaxFunctor := F.toPrelaxFunctor mapId := fun a => (F.mapId a).hom mapComp := fun f g => (F.mapComp f g).hom instance hasCoeToOplax : Coe (B ⥤ᵖ C) (B ⥤ᵒᵖᴸ C) := ⟨toOplax⟩ /-- The Lax functor associated with a pseudofunctor. -/ @[simps] def toLax : B ⥤ᴸ C where toPrelaxFunctor := F.toPrelaxFunctor mapId := fun a => (F.mapId a).inv mapComp := fun f g => (F.mapComp f g).inv map₂_leftUnitor f := by rw [← F.map₂Iso_inv, eq_inv_comp, comp_inv_eq] simp map₂_rightUnitor f := by rw [← F.map₂Iso_inv, eq_inv_comp, comp_inv_eq] simp instance hasCoeToLax : Coe (B ⥤ᵖ C) (B ⥤ᴸ C) := ⟨toLax⟩ /-- The identity pseudofunctor. -/ @[simps] def id (B : Type u₁) [Bicategory.{w₁, v₁} B] : B ⥤ᵖ B where toPrelaxFunctor := PrelaxFunctor.id B mapId := fun a => Iso.refl (𝟙 a) mapComp := fun f g => Iso.refl (f ≫ g) instance : Inhabited (B ⥤ᵖ B) := ⟨id B⟩ /-- Composition of pseudofunctors. -/ @[simps] def comp (F : B ⥤ᵖ C) (G : C ⥤ᵖ D) : B ⥤ᵖ D where toPrelaxFunctor := F.toPrelaxFunctor.comp G.toPrelaxFunctor mapId := fun a => G.map₂Iso (F.mapId a) ≪≫ G.mapId (F.obj a) mapComp := fun f g => (G.map₂Iso (F.mapComp f g)) ≪≫ G.mapComp (F.map f) (F.map g) -- Note: whilst these are all provable by `cat_disch`, the proof is very slow map₂_whisker_left f η := by simp map₂_whisker_right η h := by simp map₂_associator f g h := by simp map₂_left_unitor f := by simp map₂_right_unitor f := by simp section variable (F : B ⥤ᵖ C) {a b : B} @[to_app (attr := reassoc)] lemma mapComp_assoc_right_hom {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (F.mapComp f (g ≫ h)).hom ≫ F.map f ◁ (F.mapComp g h).hom = F.map₂ (α_ f g h).inv ≫ (F.mapComp (f ≫ g) h).hom ≫ (F.mapComp f g).hom ▷ F.map h ≫ (α_ (F.map f) (F.map g) (F.map h)).hom := F.toOplax.mapComp_assoc_right _ _ _ @[to_app (attr := reassoc)] lemma mapComp_assoc_left_hom {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (F.mapComp (f ≫ g) h).hom ≫ (F.mapComp f g).hom ▷ F.map h = F.map₂ (α_ f g h).hom ≫ (F.mapComp f (g ≫ h)).hom ≫ F.map f ◁ (F.mapComp g h).hom ≫ (α_ (F.map f) (F.map g) (F.map h)).inv := F.toOplax.mapComp_assoc_left _ _ _ @[to_app (attr := reassoc)] lemma mapComp_assoc_right_inv {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : F.map f ◁ (F.mapComp g h).inv ≫ (F.mapComp f (g ≫ h)).inv = (α_ (F.map f) (F.map g) (F.map h)).inv ≫ (F.mapComp f g).inv ▷ F.map h ≫ (F.mapComp (f ≫ g) h).inv ≫ F.map₂ (α_ f g h).hom := F.toLax.mapComp_assoc_right _ _ _ @[to_app (attr := reassoc)] lemma mapComp_assoc_left_inv {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (F.mapComp f g).inv ▷ F.map h ≫ (F.mapComp (f ≫ g) h).inv = (α_ (F.map f) (F.map g) (F.map h)).hom ≫ F.map f ◁ (F.mapComp g h).inv ≫ (F.mapComp f (g ≫ h)).inv ≫ F.map₂ (α_ f g h).inv := F.toLax.mapComp_assoc_left _ _ _ @[reassoc, to_app] lemma mapComp_id_left_hom (f : a ⟶ b) : (F.mapComp (𝟙 a) f).hom = F.map₂ (λ_ f).hom ≫ (λ_ (F.map f)).inv ≫ (F.mapId a).inv ▷ F.map f := by simp lemma mapComp_id_left (f : a ⟶ b) : (F.mapComp (𝟙 a) f) = F.map₂Iso (λ_ f) ≪≫ (λ_ (F.map f)).symm ≪≫ (whiskerRightIso (F.mapId a) (F.map f)).symm := Iso.ext <| F.mapComp_id_left_hom f @[reassoc, to_app] lemma mapComp_id_left_inv (f : a ⟶ b) : (F.mapComp (𝟙 a) f).inv = (F.mapId a).hom ▷ F.map f ≫ (λ_ (F.map f)).hom ≫ F.map₂ (λ_ f).inv := by simp [mapComp_id_left] lemma whiskerRightIso_mapId (f : a ⟶ b) : whiskerRightIso (F.mapId a) (F.map f) = (F.mapComp (𝟙 a) f).symm ≪≫ F.map₂Iso (λ_ f) ≪≫ (λ_ (F.map f)).symm := by simp [mapComp_id_left] @[reassoc, to_app] lemma whiskerRight_mapId_hom (f : a ⟶ b) : (F.mapId a).hom ▷ F.map f = (F.mapComp (𝟙 a) f).inv ≫ F.map₂ (λ_ f).hom ≫ (λ_ (F.map f)).inv := by simp @[reassoc, to_app] lemma whiskerRight_mapId_inv (f : a ⟶ b) : (F.mapId a).inv ▷ F.map f = (λ_ (F.map f)).hom ≫ F.map₂ (λ_ f).inv ≫ (F.mapComp (𝟙 a) f).hom := by simpa using congrArg (·.inv) (F.whiskerRightIso_mapId f) @[reassoc, to_app] lemma mapComp_id_right_hom (f : a ⟶ b) : (F.mapComp f (𝟙 b)).hom = F.map₂ (ρ_ f).hom ≫ (ρ_ (F.map f)).inv ≫ F.map f ◁ (F.mapId b).inv := by simp lemma mapComp_id_right (f : a ⟶ b) : (F.mapComp f (𝟙 b)) = F.map₂Iso (ρ_ f) ≪≫ (ρ_ (F.map f)).symm ≪≫ (whiskerLeftIso (F.map f) (F.mapId b)).symm := Iso.ext <| F.mapComp_id_right_hom f @[reassoc, to_app] lemma mapComp_id_right_inv (f : a ⟶ b) : (F.mapComp f (𝟙 b)).inv = F.map f ◁ (F.mapId b).hom ≫ (ρ_ (F.map f)).hom ≫ F.map₂ (ρ_ f).inv := by simp [mapComp_id_right] lemma whiskerLeftIso_mapId (f : a ⟶ b) : whiskerLeftIso (F.map f) (F.mapId b) = (F.mapComp f (𝟙 b)).symm ≪≫ F.map₂Iso (ρ_ f) ≪≫ (ρ_ (F.map f)).symm := by simp [mapComp_id_right] @[reassoc, to_app] lemma whiskerLeft_mapId_hom (f : a ⟶ b) : F.map f ◁ (F.mapId b).hom = (F.mapComp f (𝟙 b)).inv ≫ F.map₂ (ρ_ f).hom ≫ (ρ_ (F.map f)).inv := by simp @[reassoc, to_app] lemma whiskerLeft_mapId_inv (f : a ⟶ b) : F.map f ◁ (F.mapId b).inv = (ρ_ (F.map f)).hom ≫ F.map₂ (ρ_ f).inv ≫ (F.mapComp f (𝟙 b)).hom := by simpa using congrArg (·.inv) (F.whiskerLeftIso_mapId f) /-- More flexible variant of `mapId`. (See the file `Bicategory.Functor.Strict` for applications to strict bicategories.) -/ def mapId' {b : B} (f : b ⟶ b) (hf : f = 𝟙 b := by cat_disch) : F.map f ≅ 𝟙 (F.obj b) := F.map₂Iso (eqToIso (by rw [hf])) ≪≫ F.mapId _ lemma mapId'_eq_mapId (b : B) : F.mapId' (𝟙 b) rfl = F.mapId b := by simp [mapId'] @[simp] lemma toLax_mapId' {b : B} (f : b ⟶ b) (hf : f = 𝟙 b := by cat_disch) : F.toLax.mapId' f hf = (F.mapId' f hf).inv := rfl @[simp] lemma toOplax_mapId' {b : B} (f : b ⟶ b) (hf : f = 𝟙 b := by cat_disch) : F.toOplax.mapId' f hf = (F.mapId' f hf).hom := rfl /-- More flexible variant of `mapComp`. (See `Bicategory.Functor.Strict` for applications to strict bicategories.) -/ def mapComp' {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (fg : b₀ ⟶ b₂) (h : f ≫ g = fg := by cat_disch) : F.map fg ≅ F.map f ≫ F.map g := F.map₂Iso (eqToIso (by rw [h])) ≪≫ F.mapComp f g lemma mapComp'_eq_mapComp {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) : F.mapComp' f g _ rfl = F.mapComp f g := by simp [mapComp'] @[simp] lemma toLax_mapComp' {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (fg : b₀ ⟶ b₂) (h : f ≫ g = fg := by cat_disch) : F.toLax.mapComp' f g fg h = (F.mapComp' f g fg h).inv := rfl @[simp] lemma toOplax_mapComp' {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (fg : b₀ ⟶ b₂) (h : f ≫ g = fg := by cat_disch) : F.toOplax.mapComp' f g fg h = (F.mapComp' f g fg h).hom := rfl end /-- Construct a pseudofunctor from an oplax functor whose `mapId` and `mapComp` are isomorphisms. -/ @[simps] def mkOfOplax (F : B ⥤ᵒᵖᴸ C) (F' : F.PseudoCore) : B ⥤ᵖ C where toPrelaxFunctor := F.toPrelaxFunctor mapId := F'.mapIdIso mapComp := F'.mapCompIso map₂_whisker_left := fun f g h η => by rw [F'.mapCompIso_hom f g, ← F.mapComp_naturality_right_assoc, ← F'.mapCompIso_hom f h, hom_inv_id, comp_id] map₂_whisker_right := fun η h => by rw [F'.mapCompIso_hom _ h, ← F.mapComp_naturality_left_assoc, ← F'.mapCompIso_hom _ h, hom_inv_id, comp_id] map₂_associator := fun f g h => by rw [F'.mapCompIso_hom (f ≫ g) h, F'.mapCompIso_hom f g, ← F.map₂_associator_assoc, ← F'.mapCompIso_hom f (g ≫ h), ← F'.mapCompIso_hom g h, whiskerLeft_hom_inv_assoc, hom_inv_id, comp_id] /-- Construct a pseudofunctor from an oplax functor whose `mapId` and `mapComp` are isomorphisms. -/ @[simps!] noncomputable def mkOfOplax' (F : B ⥤ᵒᵖᴸ C) [∀ a, IsIso (F.mapId a)] [∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), IsIso (F.mapComp f g)] : B ⥤ᵖ C where toPrelaxFunctor := F.toPrelaxFunctor mapId := fun a => asIso (F.mapId a) mapComp := fun f g => asIso (F.mapComp f g) map₂_whisker_left := fun f g h η => by dsimp rw [← assoc, IsIso.eq_comp_inv, F.mapComp_naturality_right] map₂_whisker_right := fun η h => by dsimp rw [← assoc, IsIso.eq_comp_inv, F.mapComp_naturality_left] map₂_associator := fun f g h => by dsimp simp only [← assoc] rw [IsIso.eq_comp_inv, ← Bicategory.inv_whiskerLeft, IsIso.eq_comp_inv] simp only [assoc, F.map₂_associator] /-- Construct a pseudofunctor from a lax functor whose `mapId` and `mapComp` are isomorphisms. -/ @[simps] def mkOfLax (F : B ⥤ᴸ C) (F' : F.PseudoCore) : B ⥤ᵖ C where toPrelaxFunctor := F.toPrelaxFunctor mapId := F'.mapIdIso mapComp := F'.mapCompIso map₂_whisker_left f g h η := by rw [F'.mapCompIso_inv, ← LaxFunctor.mapComp_naturality_right, ← F'.mapCompIso_inv, hom_inv_id_assoc] map₂_whisker_right η h := by rw [F'.mapCompIso_inv, ← LaxFunctor.mapComp_naturality_left, ← F'.mapCompIso_inv, hom_inv_id_assoc] map₂_associator {a b c d} f g h := by rw [F'.mapCompIso_inv, F'.mapCompIso_inv, ← inv_comp_eq, ← IsIso.inv_comp_eq] simp map₂_left_unitor {a b} f := by rw [← IsIso.inv_eq_inv, ← F.map₂_inv]; simp map₂_right_unitor {a b} f := by rw [← IsIso.inv_eq_inv, ← F.map₂_inv]; simp /-- Construct a pseudofunctor from a lax functor whose `mapId` and `mapComp` are isomorphisms. -/ @[simps!] noncomputable def mkOfLax' (F : B ⥤ᴸ C) [∀ a, IsIso (F.mapId a)] [∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), IsIso (F.mapComp f g)] : B ⥤ᵖ C := mkOfLax F { mapIdIso := fun a => (asIso (F.mapId a)).symm mapCompIso := fun f g => (asIso (F.mapComp f g)).symm } end end Pseudofunctor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/Lax.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Prelax import Mathlib.Tactic.CategoryTheory.Slice import Mathlib.Tactic.CategoryTheory.ToApp /-! # Lax functors A lax functor `F` between bicategories `B` and `C` consists of * a function between objects `F.obj : B ⟶ C`, * a family of functions between 1-morphisms `F.map : (a ⟶ b) → (F.obj a ⟶ F.obj b)`, * a family of functions between 2-morphisms `F.map₂ : (f ⟶ g) → (F.map f ⟶ F.map g)`, * a family of 2-morphisms `F.mapId a : 𝟙 (F.obj a) ⟶ F.map (𝟙 a)`, * a family of 2-morphisms `F.mapComp f g : F.map f ≫ F.map g ⟶ F.map (f ≫ g)`, and * certain consistency conditions on them. ## Main definitions * `CategoryTheory.LaxFunctor B C` : an lax functor between bicategories `B` and `C`, which we denote by `B ⥤ᴸ C`. * `CategoryTheory.LaxFunctor.comp F G` : the composition of lax functors * `CategoryTheory.LaxFunctor.Pseudocore` : a structure on an Lax functor that promotes a Lax functor to a pseudofunctor ## Future work Some constructions in the bicategory library have only been done in terms of oplax functors, since lax functors had not yet been added (e.g `FunctorBicategory.lean`). A possible project would be to mirror these constructions for lax functors. -/ namespace CategoryTheory open Category Bicategory open Bicategory universe w₁ w₂ w₃ v₁ v₂ v₃ u₁ u₂ u₃ /-- A lax functor `F` between bicategories `B` and `C` consists of a function between objects `F.obj`, a function between 1-morphisms `F.map`, and a function between 2-morphisms `F.map₂`. Unlike functors between categories, `F.map` do not need to strictly commute with the composition, and do not need to strictly preserve the identity. Instead, there are specified 2-morphisms `𝟙 (F.obj a) ⟶ F.map (𝟙 a)` and `F.map f ≫ F.map g ⟶ F.map (f ≫ g)`. `F.map₂` strictly commute with compositions and preserve the identity. They also preserve the associator, the left unitor, and the right unitor modulo some adjustments of domains and codomains of 2-morphisms. -/ structure LaxFunctor (B : Type u₁) [Bicategory.{w₁, v₁} B] (C : Type u₂) [Bicategory.{w₂, v₂} C] extends PrelaxFunctor B C where /-- The 2-morphism underlying the lax unity constraint. -/ mapId (a : B) : 𝟙 (obj a) ⟶ map (𝟙 a) /-- The 2-morphism underlying the lax functoriality constraint. -/ mapComp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : map f ≫ map g ⟶ map (f ≫ g) /-- Naturality of the lax functoriality constraint, on the left. -/ mapComp_naturality_left : ∀ {a b c : B} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c), mapComp f g ≫ map₂ (η ▷ g) = map₂ η ▷ map g ≫ mapComp f' g:= by cat_disch /-- Naturality of the lax functoriality constraint, on the right. -/ mapComp_naturality_right : ∀ {a b c : B} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g'), mapComp f g ≫ map₂ (f ◁ η) = map f ◁ map₂ η ≫ mapComp f g' := by cat_disch /-- Lax associativity. -/ map₂_associator : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), mapComp f g ▷ map h ≫ mapComp (f ≫ g) h ≫ map₂ (α_ f g h).hom = (α_ (map f) (map g) (map h)).hom ≫ map f ◁ mapComp g h ≫ mapComp f (g ≫ h) := by cat_disch /-- Lax left unity. -/ map₂_leftUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (λ_ f).inv = (λ_ (map f)).inv ≫ mapId a ▷ map f ≫ mapComp (𝟙 a) f := by cat_disch /-- Lax right unity. -/ map₂_rightUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (ρ_ f).inv = (ρ_ (map f)).inv ≫ map f ◁ mapId b ≫ mapComp f (𝟙 b) := by cat_disch /-- Notation for a lax functor between bicategories. -/ -- Given similar precedence as ⥤ (26). scoped[CategoryTheory.Bicategory] infixr:26 " ⥤ᴸ " => LaxFunctor -- type as \func\^L initialize_simps_projections LaxFunctor (+toPrelaxFunctor, -obj, -map, -map₂) namespace LaxFunctor variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] attribute [reassoc (attr := simp), to_app (attr := simp)] mapComp_naturality_left mapComp_naturality_right map₂_associator attribute [simp, reassoc, to_app] map₂_leftUnitor map₂_rightUnitor /-- The underlying prelax functor. -/ add_decl_doc LaxFunctor.toPrelaxFunctor variable (F : B ⥤ᴸ C) @[reassoc, to_app] lemma mapComp_assoc_left {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : F.mapComp f g ▷ F.map h ≫ F.mapComp (f ≫ g) h = (α_ (F.map f) (F.map g) (F.map h)).hom ≫ F.map f ◁ F.mapComp g h ≫ F.mapComp f (g ≫ h) ≫ F.map₂ (α_ f g h).inv := by rw [← F.map₂_associator_assoc, ← F.map₂_comp] simp only [Iso.hom_inv_id, PrelaxFunctor.map₂_id, comp_id] @[reassoc, to_app] lemma mapComp_assoc_right {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : F.map f ◁ F.mapComp g h ≫ F.mapComp f (g ≫ h) = (α_ (F.map f) (F.map g) (F.map h)).inv ≫ F.mapComp f g ▷ F.map h ≫ F.mapComp (f ≫ g) h ≫ F.map₂ (α_ f g h).hom := by simp only [map₂_associator, Iso.inv_hom_id_assoc] @[reassoc, to_app] lemma map₂_leftUnitor_hom {a b : B} (f : a ⟶ b) : (λ_ (F.map f)).hom = F.mapId a ▷ F.map f ≫ F.mapComp (𝟙 a) f ≫ F.map₂ (λ_ f).hom := by rw [← PrelaxFunctor.map₂Iso_hom, ← assoc, ← Iso.comp_inv_eq, ← Iso.eq_inv_comp] simp only [Functor.mapIso_inv, PrelaxFunctor.mapFunctor_map, map₂_leftUnitor] @[reassoc, to_app] lemma map₂_rightUnitor_hom {a b : B} (f : a ⟶ b) : (ρ_ (F.map f)).hom = F.map f ◁ F.mapId b ≫ F.mapComp f (𝟙 b) ≫ F.map₂ (ρ_ f).hom := by rw [← PrelaxFunctor.map₂Iso_hom, ← assoc, ← Iso.comp_inv_eq, ← Iso.eq_inv_comp] simp only [Functor.mapIso_inv, PrelaxFunctor.mapFunctor_map, map₂_rightUnitor] /-- The identity lax functor. -/ @[simps] def id (B : Type u₁) [Bicategory.{w₁, v₁} B] : B ⥤ᴸ B where toPrelaxFunctor := PrelaxFunctor.id B mapId := fun a => 𝟙 (𝟙 a) mapComp := fun f g => 𝟙 (f ≫ g) instance : Inhabited (B ⥤ᴸ B) := ⟨id B⟩ /-- More flexible variant of `mapId`. (See the file `Bicategory.Functor.Strict` for applications to strict bicategories.) -/ def mapId' {b : B} (f : b ⟶ b) (hf : f = 𝟙 b := by cat_disch) : 𝟙 (F.obj b) ⟶ F.map f := F.mapId _ ≫ F.map₂ (eqToHom (by rw [hf])) lemma mapId'_eq_mapId (b : B) : F.mapId' (𝟙 b) rfl = F.mapId b := by simp [mapId'] /-- More flexible variant of `mapComp`. (See `Bicategory.Functor.Strict` for applications to strict bicategories.) -/ def mapComp' {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (fg : b₀ ⟶ b₂) (h : f ≫ g = fg := by cat_disch) : F.map f ≫ F.map g ⟶ F.map fg := F.mapComp f g ≫ F.map₂ (eqToHom (by rw [h])) lemma mapComp'_eq_mapComp {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) : F.mapComp' f g _ rfl = F.mapComp f g := by simp [mapComp'] /-- Composition of lax functors. -/ @[simps] def comp {D : Type u₃} [Bicategory.{w₃, v₃} D] (F : B ⥤ᴸ C) (G : C ⥤ᴸ D) : B ⥤ᴸ D where toPrelaxFunctor := PrelaxFunctor.comp F.toPrelaxFunctor G.toPrelaxFunctor mapId := fun a => G.mapId (F.obj a) ≫ G.map₂ (F.mapId a) mapComp := fun f g => G.mapComp (F.map f) (F.map g) ≫ G.map₂ (F.mapComp f g) mapComp_naturality_left := fun η g => by dsimp rw [assoc, ← G.map₂_comp, mapComp_naturality_left, G.map₂_comp, mapComp_naturality_left_assoc] mapComp_naturality_right := fun f _ _ η => by dsimp rw [assoc, ← G.map₂_comp, mapComp_naturality_right, G.map₂_comp, mapComp_naturality_right_assoc] map₂_associator := fun f g h => by dsimp slice_rhs 1 3 => rw [Bicategory.whiskerLeft_comp, assoc, ← mapComp_naturality_right, ← map₂_associator_assoc] slice_rhs 3 5 => rw [← G.map₂_comp, ← G.map₂_comp, ← F.map₂_associator, G.map₂_comp, G.map₂_comp] slice_lhs 1 3 => rw [comp_whiskerRight, assoc, ← G.mapComp_naturality_left_assoc] simp only [assoc] map₂_leftUnitor := fun f => by dsimp simp only [map₂_leftUnitor, PrelaxFunctor.map₂_comp, assoc, mapComp_naturality_left_assoc, comp_whiskerRight] map₂_rightUnitor := fun f => by dsimp simp only [map₂_rightUnitor, PrelaxFunctor.map₂_comp, assoc, mapComp_naturality_right_assoc, Bicategory.whiskerLeft_comp] /-- A structure on an Lax functor that promotes an Lax functor to a pseudofunctor. See `Pseudofunctor.mkOfLax`. -/ structure PseudoCore (F : B ⥤ᴸ C) where /-- The isomorphism giving rise to the lax unity constraint -/ mapIdIso (a : B) : F.map (𝟙 a) ≅ 𝟙 (F.obj a) /-- The isomorphism giving rise to the lax functoriality constraint -/ mapCompIso {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : F.map (f ≫ g) ≅ F.map f ≫ F.map g /-- `mapIdIso` gives rise to the lax unity constraint -/ mapIdIso_inv {a : B} : (mapIdIso a).inv = F.mapId a := by cat_disch /-- `mapCompIso` gives rise to the lax functoriality constraint -/ mapCompIso_inv {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : (mapCompIso f g).inv = F.mapComp f g := by cat_disch attribute [simp] PseudoCore.mapIdIso_inv PseudoCore.mapCompIso_inv end LaxFunctor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/Prelax.lean
import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.EqToHom /-! # Prelax functors This file defines lax prefunctors and prelax functors between bicategories. The point of these definitions is to provide some common API that will be helpful in the development of both lax and oplax functors. ## Main definitions `PrelaxFunctorStruct B C`: A PrelaxFunctorStruct `F` between quivers `B` and `C`, such that both have been equipped with quiver structures on the hom-types, consists of * a function between objects `F.obj : B ⟶ C`, * a family of functions between 1-morphisms `F.map : (a ⟶ b) → (F.obj a ⟶ F.obj b)`, * a family of functions between 2-morphisms `F.map₂ : (f ⟶ g) → (F.map f ⟶ F.map g)`, `PrelaxFunctor B C`: A prelax functor `F` between bicategories `B` and `C` is a `PrelaxFunctorStruct` such that the associated prefunctors between the hom types are all functors. In other words, it is a `PrelaxFunctorStruct` that satisfies * `F.map₂ (𝟙 f) = 𝟙 (F.map f)`, * `F.map₂ (η ≫ θ) = F.map₂ η ≫ F.map₂ θ`. `mkOfHomFunctor`: constructs a `PrelaxFunctor` from a map on objects and functors between the corresponding hom types. -/ namespace CategoryTheory open Category Bicategory universe w₁ w₂ w₃ v₁ v₂ v₃ u₁ u₂ u₃ section variable (B : Type u₁) [Quiver.{v₁ + 1} B] [∀ a b : B, Quiver.{w₁ + 1} (a ⟶ b)] variable (C : Type u₂) [Quiver.{v₂ + 1} C] [∀ a b : C, Quiver.{w₂ + 1} (a ⟶ b)] variable {D : Type u₃} [Quiver.{v₃ + 1} D] [∀ a b : D, Quiver.{w₃ + 1} (a ⟶ b)] /-- A `PrelaxFunctorStruct` between bicategories consists of functions between objects, 1-morphisms, and 2-morphisms. This structure will be extended to define `PrelaxFunctor`. -/ structure PrelaxFunctorStruct extends Prefunctor B C where /-- The action of a lax prefunctor on 2-morphisms. -/ map₂ {a b : B} {f g : a ⟶ b} : (f ⟶ g) → (map f ⟶ map g) initialize_simps_projections PrelaxFunctorStruct (+toPrefunctor, -obj, -map) /-- The prefunctor between the underlying quivers. -/ add_decl_doc PrelaxFunctorStruct.toPrefunctor variable {B} {C} namespace PrelaxFunctorStruct /-- Construct a lax prefunctor from a map on objects, and prefunctors between the corresponding hom types. -/ @[simps] def mkOfHomPrefunctors (F : B → C) (F' : (a : B) → (b : B) → Prefunctor (a ⟶ b) (F a ⟶ F b)) : PrelaxFunctorStruct B C where obj := F map {a b} := (F' a b).obj map₂ {a b} := (F' a b).map /-- The identity lax prefunctor. -/ @[simps] def id (B : Type u₁) [Quiver.{v₁ + 1} B] [∀ a b : B, Quiver.{w₁ + 1} (a ⟶ b)] : PrelaxFunctorStruct B B := { Prefunctor.id B with map₂ := fun η => η } instance : Inhabited (PrelaxFunctorStruct B B) := ⟨PrelaxFunctorStruct.id B⟩ /-- Composition of lax prefunctors. -/ @[simps] def comp (F : PrelaxFunctorStruct B C) (G : PrelaxFunctorStruct C D) : PrelaxFunctorStruct B D where toPrefunctor := F.toPrefunctor.comp G.toPrefunctor map₂ := fun η => G.map₂ (F.map₂ η) end PrelaxFunctorStruct end /-- A prelax functor between bicategories is a lax prefunctor such that `map₂` is a functor. This structure will be extended to define `LaxFunctor` and `OplaxFunctor`. -/ structure PrelaxFunctor (B : Type u₁) [Bicategory.{w₁, v₁} B] (C : Type u₂) [Bicategory.{w₂, v₂} C] extends PrelaxFunctorStruct B C where /-- Prelax functors preserves identity 2-morphisms. -/ map₂_id : ∀ {a b : B} (f : a ⟶ b), map₂ (𝟙 f) = 𝟙 (map f) := by aesop -- TODO: why not cat_disch? /-- Prelax functors preserves compositions of 2-morphisms. -/ map₂_comp : ∀ {a b : B} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h), map₂ (η ≫ θ) = map₂ η ≫ map₂ θ := by cat_disch namespace PrelaxFunctor initialize_simps_projections PrelaxFunctor (+toPrelaxFunctorStruct, -obj, -map, -map₂) attribute [simp] map₂_id attribute [reassoc] map₂_comp attribute [simp] map₂_comp /-- The underlying lax prefunctor. -/ add_decl_doc PrelaxFunctor.toPrelaxFunctorStruct variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] variable {D : Type u₃} [Bicategory.{w₃, v₃} D] /-- Construct a prelax functor from a map on objects, and functors between the corresponding hom types. -/ @[simps] def mkOfHomFunctors (F : B → C) (F' : (a : B) → (b : B) → (a ⟶ b) ⥤ (F a ⟶ F b)) : PrelaxFunctor B C where toPrelaxFunctorStruct := PrelaxFunctorStruct.mkOfHomPrefunctors F fun a b => (F' a b).toPrefunctor map₂_id {a b} := (F' a b).map_id map₂_comp {a b} := (F' a b).map_comp /-- The identity prelax functor. -/ @[simps] def id (B : Type u₁) [Bicategory.{w₁, v₁} B] : PrelaxFunctor B B where toPrelaxFunctorStruct := PrelaxFunctorStruct.id B instance : Inhabited (PrelaxFunctorStruct B B) := ⟨PrelaxFunctorStruct.id B⟩ variable (F : PrelaxFunctor B C) /-- Composition of prelax functors. -/ @[simps] def comp (G : PrelaxFunctor C D) : PrelaxFunctor B D where toPrelaxFunctorStruct := PrelaxFunctorStruct.comp F.toPrelaxFunctorStruct G.toPrelaxFunctorStruct /-- Function between 1-morphisms as a functor. -/ @[simps] def mapFunctor (a b : B) : (a ⟶ b) ⥤ (F.obj a ⟶ F.obj b) where obj f := F.map f map η := F.map₂ η @[simp] lemma mkOfHomFunctors_mapFunctor (F : B → C) (F' : (a : B) → (b : B) → (a ⟶ b) ⥤ (F a ⟶ F b)) (a b : B) : (mkOfHomFunctors F F').mapFunctor a b = F' a b := rfl section variable {a b : B} /-- A prelaxfunctor `F` sends 2-isomorphisms `η : f ≅ f` to 2-isomorphisms `F.map f ≅ F.map g`. -/ @[simps!] abbrev map₂Iso {f g : a ⟶ b} (η : f ≅ g) : F.map f ≅ F.map g := (F.mapFunctor a b).mapIso η instance map₂_isIso {f g : a ⟶ b} (η : f ⟶ g) [IsIso η] : IsIso (F.map₂ η) := (F.map₂Iso (asIso η)).isIso_hom @[simp] lemma map₂_inv {f g : a ⟶ b} (η : f ⟶ g) [IsIso η] : F.map₂ (inv η) = inv (F.map₂ η) := by apply IsIso.eq_inv_of_hom_inv_id simp [← F.map₂_comp η (inv η)] @[reassoc, simp] lemma map₂_hom_inv {f g : a ⟶ b} (η : f ≅ g) : F.map₂ η.hom ≫ F.map₂ η.inv = 𝟙 (F.map f) := by rw [← F.map₂_comp, Iso.hom_inv_id, F.map₂_id] @[reassoc] lemma map₂_hom_inv_isIso {f g : a ⟶ b} (η : f ⟶ g) [IsIso η] : F.map₂ η ≫ F.map₂ (inv η) = 𝟙 (F.map f) := by simp @[reassoc, simp] lemma map₂_inv_hom {f g : a ⟶ b} (η : f ≅ g) : F.map₂ η.inv ≫ F.map₂ η.hom = 𝟙 (F.map g) := by rw [← F.map₂_comp, Iso.inv_hom_id, F.map₂_id] @[reassoc] lemma map₂_inv_hom_isIso {f g : a ⟶ b} (η : f ⟶ g) [IsIso η] : F.map₂ (inv η) ≫ F.map₂ η = 𝟙 (F.map g) := by simp end lemma map₂_eqToHom {x y : B} (f g : x ⟶ y) (hfg : f = g) : F.map₂ (eqToHom hfg) = eqToHom (by rw [← hfg]) := by subst hfg simp lemma map₂Iso_eqToIso {x y : B} (f g : x ⟶ y) (hfg : f = g) : F.map₂Iso (eqToIso hfg) = eqToIso (by rw [← hfg]) := by subst hfg simp end PrelaxFunctor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/Cat.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor /-! # Pseudofunctors to Cat In this file, we state naturality properties of `mapId'` and `mapComp'` for pseudofunctors to `Cat`. -/ universe w v v' u u' namespace CategoryTheory open Bicategory namespace Pseudofunctor variable {B : Type u} [Bicategory.{w, v} B] (F : B ⥤ᵖ Cat.{v', u'}) section naturality variable {b₀ b₁ b₂ : B} {X Y : F.obj b₀} section variable (f : b₀ ⟶ b₀) (hf : f = 𝟙 b₀) (a : X ⟶ Y) @[reassoc] lemma mapId'_hom_naturality : (F.map f).map a ≫ (F.mapId' f hf).hom.app Y = (F.mapId' f hf).hom.app X ≫ a := (F.mapId' f hf).hom.naturality a @[reassoc] lemma mapId'_inv_naturality : (F.mapId' f hf).inv.app X ≫ (F.map f).map a = a ≫ (F.mapId' f hf).inv.app Y := ((F.mapId' f hf).inv.naturality a).symm end section variable (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (fg : b₀ ⟶ b₂) (hfg : f ≫ g = fg) (a : X ⟶ Y) @[reassoc] lemma mapComp'_hom_naturality : (F.map fg).map a ≫ (F.mapComp' f g fg hfg).hom.app Y = (F.mapComp' f g fg hfg).hom.app X ≫ (F.map g).map ((F.map f).map a) := (F.mapComp' f g fg hfg).hom.naturality a @[reassoc] lemma mapComp'_inv_naturality : (F.map g).map ((F.map f).map a) ≫ (F.mapComp' f g fg hfg).inv.app Y = (F.mapComp' f g fg hfg).inv.app X ≫ (F.map fg).map a := (F.mapComp' f g fg hfg).inv.naturality a @[reassoc] lemma mapComp'_naturality_1 : (F.mapComp' f g fg hfg).inv.app X ≫ (F.map fg).map a ≫ (F.mapComp' f g fg hfg).hom.app Y = (F.map g).map ((F.map f).map a) := NatIso.naturality_1 (F.mapComp' f g fg hfg) a @[reassoc] lemma mapComp'_naturality_2 : (F.mapComp' f g fg hfg).hom.app X ≫ (F.map g).map ((F.map f).map a) ≫ (F.mapComp' f g fg hfg).inv.app Y = (F.map fg).map a := NatIso.naturality_2 (F.mapComp' f g fg hfg) a end end naturality end Pseudofunctor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/LocallyDiscrete.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor import Mathlib.CategoryTheory.Bicategory.LocallyDiscrete /-! # Pseudofunctors from locally discrete bicategories This file provides various ways of constructing pseudofunctors from locally discrete bicategories. Firstly, we define the constructors `pseudofunctorOfIsLocallyDiscrete` and `oplaxFunctorOfIsLocallyDiscrete` for defining pseudofunctors and oplax functors from a locally discrete bicategories. In this situation, we do not need to care about the field `map₂`, because all the `2`-morphisms in `B` are identities. We also define a specialized constructor `LocallyDiscrete.mkPseudofunctor` when the source bicategory is of the form `B := LocallyDiscrete B₀` for a category `B₀`. We also prove that a functor `F : I ⥤ B` with `B` a strict bicategory can be promoted to a pseudofunctor (or oplax functor) (`Functor.toPseudofunctor`) with domain `LocallyDiscrete I`. -/ namespace CategoryTheory open Bicategory /-- Constructor for pseudofunctors from a locally discrete bicategory. In that case, we do not need to provide the `map₂` field of pseudofunctors. -/ @[simps obj map mapId mapComp] def pseudofunctorOfIsLocallyDiscrete {B C : Type*} [Bicategory B] [IsLocallyDiscrete B] [Bicategory C] (obj : B → C) (map : ∀ {b b' : B}, (b ⟶ b') → (obj b ⟶ obj b')) (mapId : ∀ (b : B), map (𝟙 b) ≅ 𝟙 _) (mapComp : ∀ {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂), map (f ≫ g) ≅ map f ≫ map g) (map₂_associator : ∀ {b₀ b₁ b₂ b₃ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (h : b₂ ⟶ b₃), (mapComp (f ≫ g) h).hom ≫ (mapComp f g).hom ▷ map h ≫ (α_ (map f) (map g) (map h)).hom ≫ map f ◁ (mapComp g h).inv ≫ (mapComp f (g ≫ h)).inv = eqToHom (by simp) := by cat_disch) (map₂_left_unitor : ∀ {b₀ b₁ : B} (f : b₀ ⟶ b₁), (mapComp (𝟙 b₀) f).hom ≫ (mapId b₀).hom ▷ map f ≫ (λ_ (map f)).hom = eqToHom (by simp) := by cat_disch) (map₂_right_unitor : ∀ {b₀ b₁ : B} (f : b₀ ⟶ b₁), (mapComp f (𝟙 b₁)).hom ≫ map f ◁ (mapId b₁).hom ≫ (ρ_ (map f)).hom = eqToHom (by simp) := by cat_disch) : B ⥤ᵖ C where obj := obj map := map map₂ φ := eqToHom (by obtain rfl := obj_ext_of_isDiscrete φ dsimp) mapId := mapId mapComp := mapComp map₂_whisker_left _ _ _ η := by obtain rfl := obj_ext_of_isDiscrete η simp map₂_whisker_right η _ := by obtain rfl := obj_ext_of_isDiscrete η simp /-- Constructor for oplax functors from a locally discrete bicategory. In that case, we do not need to provide the `map₂` field of oplax functors. -/ @[simps obj map mapId mapComp] def oplaxFunctorOfIsLocallyDiscrete {B C : Type*} [Bicategory B] [IsLocallyDiscrete B] [Bicategory C] (obj : B → C) (map : ∀ {b b' : B}, (b ⟶ b') → (obj b ⟶ obj b')) (mapId : ∀ (b : B), map (𝟙 b) ⟶ 𝟙 _) (mapComp : ∀ {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂), map (f ≫ g) ⟶ map f ≫ map g) (map₂_associator : ∀ {b₀ b₁ b₂ b₃ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (h : b₂ ⟶ b₃), eqToHom (by simp) ≫ mapComp f (g ≫ h) ≫ map f ◁ mapComp g h = mapComp (f ≫ g) h ≫ mapComp f g ▷ map h ≫ (α_ (map f) (map g) (map h)).hom := by cat_disch) (map₂_left_unitor : ∀ {b₀ b₁ : B} (f : b₀ ⟶ b₁), mapComp (𝟙 b₀) f ≫ mapId b₀ ▷ map f ≫ (λ_ (map f)).hom = eqToHom (by simp) := by cat_disch) (map₂_right_unitor : ∀ {b₀ b₁ : B} (f : b₀ ⟶ b₁), mapComp f (𝟙 b₁) ≫ map f ◁ mapId b₁ ≫ (ρ_ (map f)).hom = eqToHom (by simp) := by cat_disch) : B ⥤ᵒᵖᴸ C where obj := obj map := map map₂ φ := eqToHom (by obtain rfl := obj_ext_of_isDiscrete φ dsimp) mapId := mapId mapComp := mapComp mapComp_naturality_left η := by obtain rfl := obj_ext_of_isDiscrete η simp mapComp_naturality_right _ _ _ η := by obtain rfl := obj_ext_of_isDiscrete η simp section variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) /-- A functor between two categories `C` and `D` can be lifted to a pseudofunctor between the corresponding locally discrete bicategories. -/ @[simps! obj map mapId mapComp] def Functor.toPseudoFunctor : LocallyDiscrete C ⥤ᵖ (LocallyDiscrete D) := pseudofunctorOfIsLocallyDiscrete (fun ⟨X⟩ ↦.mk <| F.obj X) (fun ⟨f⟩ ↦ (F.map f).toLoc) (fun ⟨X⟩ ↦ eqToIso (by simp)) (fun f g ↦ eqToIso (by simp)) /-- A functor between two categories `C` and `D` can be lifted to an oplax functor between the corresponding locally discrete bicategories. This is just an abbreviation of `Functor.toPseudoFunctor.toOplax`. -/ @[simps! obj map mapId mapComp] abbrev Functor.toOplaxFunctor : LocallyDiscrete C ⥤ᵒᵖᴸ (LocallyDiscrete D) := F.toPseudoFunctor.toOplax end section variable {I B : Type*} [Category I] [Bicategory B] [Strict B] (F : I ⥤ B) attribute [local simp] Strict.leftUnitor_eqToIso Strict.rightUnitor_eqToIso Strict.associator_eqToIso /-- If `B` is a strict bicategory and `I` is a (1-)category, any functor (of 1-categories) `I ⥤ B` can be promoted to a pseudofunctor from `LocallyDiscrete I` to `B`. -/ @[simps! obj map mapId mapComp] def Functor.toPseudoFunctor' : LocallyDiscrete I ⥤ᵖ B := pseudofunctorOfIsLocallyDiscrete (fun ⟨X⟩ ↦ F.obj X) (fun ⟨f⟩ ↦ F.map f) (fun ⟨X⟩ ↦ eqToIso (by simp)) (fun f g ↦ eqToIso (by simp)) /-- If `B` is a strict bicategory and `I` is a (1-)category, any functor (of 1-categories) `I ⥤ B` can be promoted to an oplax functor from `LocallyDiscrete I` to `B`. -/ @[simps! obj map mapId mapComp] abbrev Functor.toOplaxFunctor' : LocallyDiscrete I ⥤ᵒᵖᴸ B := F.toPseudoFunctor'.toOplax end namespace LocallyDiscrete /-- Constructor for pseudofunctors from a locally discrete bicategory. In that case, we do not need to provide the `map₂` field of pseudofunctors. -/ @[simps! obj map mapId mapComp] def mkPseudofunctor {B₀ C : Type*} [Category B₀] [Bicategory C] (obj : B₀ → C) (map : ∀ {b b' : B₀}, (b ⟶ b') → (obj b ⟶ obj b')) (mapId : ∀ (b : B₀), map (𝟙 b) ≅ 𝟙 _) (mapComp : ∀ {b₀ b₁ b₂ : B₀} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂), map (f ≫ g) ≅ map f ≫ map g) (map₂_associator : ∀ {b₀ b₁ b₂ b₃ : B₀} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (h : b₂ ⟶ b₃), (mapComp (f ≫ g) h).hom ≫ (mapComp f g).hom ▷ map h ≫ (α_ (map f) (map g) (map h)).hom ≫ map f ◁ (mapComp g h).inv ≫ (mapComp f (g ≫ h)).inv = eqToHom (by simp) := by cat_disch) (map₂_left_unitor : ∀ {b₀ b₁ : B₀} (f : b₀ ⟶ b₁), (mapComp (𝟙 b₀) f).hom ≫ (mapId b₀).hom ▷ map f ≫ (λ_ (map f)).hom = eqToHom (by simp) := by cat_disch) (map₂_right_unitor : ∀ {b₀ b₁ : B₀} (f : b₀ ⟶ b₁), (mapComp f (𝟙 b₁)).hom ≫ map f ◁ (mapId b₁).hom ≫ (ρ_ (map f)).hom = eqToHom (by simp) := by cat_disch) : LocallyDiscrete B₀ ⥤ᵖ C := pseudofunctorOfIsLocallyDiscrete (fun b ↦ obj b.as) (fun f ↦ map f.as) (fun _ ↦ mapId _) (fun _ _ ↦ mapComp _ _) (fun _ _ _ ↦ map₂_associator _ _ _) (fun _ ↦ map₂_left_unitor _) (fun _ ↦ map₂_right_unitor _) end LocallyDiscrete end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/Strict.lean
import Mathlib.CategoryTheory.Bicategory.Strict.Pseudofunctor deprecated_module (since := "2025-10-02")
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Functor/StrictlyUnitary.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor /-! # Strictly unitary lax functors and pseudofunctors In this file, we define strictly unitary Lax functors and strictly unitary pseudofunctors between bicategories. A lax functor `F` is said to be *strictly unitary* (sometimes, they are also called *normal*) if there is an equality `F.obj (𝟙 _) = 𝟙 (F.obj x)` and if the unit 2-morphism `F.obj (𝟙 _) → 𝟙 (F.obj _)` is the identity 2-morphism induced by this equality. A pseudofunctor is called *strictly unitary* (or a *normal homomorphism*) if it satisfies the same condition (i.e its "underlying" lax functor is strictly unitary). ## References - [Kerodon, section 2.2.2.4](https://kerodon.net/tag/008G) ## TODOs * Define lax-composable (resp. pseudo-composable) arrows as strictly unitary lax (resp. pseudo-) functors out of `LocallyDiscrete Fin n`. * Define identity-component oplax natural transformations ("icons") between strictly unitary pseudofunctors and construct a bicategory structure on bicategories, strictly unitary pseudofunctors and icons. * Construct the Duskin of a bicategory using lax-composable arrows * Construct the 2-nerve of a bicategory using pseudo-composable arrows -/ namespace CategoryTheory open Category Bicategory open Bicategory universe w₁ w₂ w₃ w₄ v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] {D : Type u₃} [Bicategory.{w₃, v₃} D] variable (B C) /-- A strictly unitary lax functor `F` between bicategories `B` and `C` is a lax functor `F` from `B` to `C` such that the structure 1-cell `𝟙 (obj X) ⟶ map (𝟙 X)` is in fact an identity 1-cell for every `X : B`. -/ @[kerodon 008R] structure StrictlyUnitaryLaxFunctor extends B ⥤ᴸ C where map_id (X : B) : map (𝟙 X) = 𝟙 (obj X) := by rfl_cat mapId_eq_eqToHom (X : B) : (mapId X) = eqToHom (map_id X).symm := by cat_disch /-- A helper structure that bundles the necessary data to construct a `StrictlyUnitaryLaxFunctor` without specifying the redundant field `mapId`. -/ structure StrictlyUnitaryLaxFunctorCore where /-- action on objects -/ obj : B → C /-- action on 1-morphisms -/ map : ∀ {X Y : B}, (X ⟶ Y) → (obj X ⟶ obj Y) map_id : ∀ (X : B), map (𝟙 X) = 𝟙 (obj X) := by cat_disch /-- action on 2-morphisms -/ map₂ : ∀ {a b : B} {f g : a ⟶ b}, (f ⟶ g) → (map f ⟶ map g) map₂_id : ∀ {a b : B} (f : a ⟶ b), map₂ (𝟙 f) = 𝟙 (map f) := by cat_disch map₂_comp : ∀ {a b : B} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h), map₂ (η ≫ θ) = map₂ η ≫ map₂ θ := by cat_disch /-- structure 2-morphism for composition of 1-morphism -/ mapComp : ∀ {a b c : B} (f : a ⟶ b) (g : b ⟶ c), map f ≫ map g ⟶ map (f ≫ g) mapComp_naturality_left : ∀ {a b c : B} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c), mapComp f g ≫ map₂ (η ▷ g) = map₂ η ▷ map g ≫ mapComp f' g := by cat_disch mapComp_naturality_right : ∀ {a b c : B} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g'), mapComp f g ≫ map₂ (f ◁ η) = map f ◁ map₂ η ≫ mapComp f g' := by cat_disch map₂_leftUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (λ_ f).inv = (λ_ (map f)).inv ≫ eqToHom (by rw [map_id a]) ≫ mapComp (𝟙 a) f := by cat_disch map₂_rightUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (ρ_ f).inv = (ρ_ (map f)).inv ≫ eqToHom (by rw [map_id b]) ≫ mapComp f (𝟙 b) := by cat_disch map₂_associator : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), mapComp f g ▷ map h ≫ mapComp (f ≫ g) h ≫ map₂ (α_ f g h).hom = (α_ (map f) (map g) (map h)).hom ≫ map f ◁ mapComp g h ≫ mapComp f (g ≫ h) := by cat_disch namespace StrictlyUnitaryLaxFunctor variable {B C} /-- An alternate constructor for strictly unitary lax functors that does not require the `mapId` fields, and that adapts the `map₂_leftUnitor` and `map₂_rightUnitor` to the fact that the functor is strictly unitary. -/ @[simps] def mk' (S : StrictlyUnitaryLaxFunctorCore B C) : StrictlyUnitaryLaxFunctor B C where obj := S.obj map := S.map map_id := S.map_id mapId x := eqToHom (S.map_id x).symm mapId_eq_eqToHom x := rfl map₂ := S.map₂ map₂_id := S.map₂_id map₂_comp := S.map₂_comp mapComp := S.mapComp mapComp_naturality_left := S.mapComp_naturality_left mapComp_naturality_right := S.mapComp_naturality_right map₂_leftUnitor f := by simpa using S.map₂_leftUnitor f map₂_rightUnitor f := by simpa using S.map₂_rightUnitor f map₂_associator f g h := by simpa using S.map₂_associator f g h instance mapId_isIso (F : StrictlyUnitaryLaxFunctor B C) (x : B) : IsIso (F.mapId x) := by rw [mapId_eq_eqToHom] infer_instance /-- Promote the morphism `F.mapId x : 𝟙 (F.obj x) ⟶ F.map (𝟙 x)` to an isomorphism when `F` is strictly unitary. -/ @[simps] def mapIdIso (F : StrictlyUnitaryLaxFunctor B C) (x : B) : 𝟙 (F.obj x) ≅ F.map (𝟙 x) where hom := F.mapId x inv := eqToHom (F.map_id x) hom_inv_id := by simp [F.mapId_eq_eqToHom] inv_hom_id := by simp [F.mapId_eq_eqToHom] variable (B) in /-- The identity `StrictlyUnitaryLaxFunctor`. -/ @[simps!] def id : StrictlyUnitaryLaxFunctor B B where __ := LaxFunctor.id B map_id _ := rfl mapId_eq_eqToHom _ := rfl /-- Composition of `StrictlyUnitaryLaxFunctor`. -/ @[simps!] def comp (F : StrictlyUnitaryLaxFunctor B C) (G : StrictlyUnitaryLaxFunctor C D) : StrictlyUnitaryLaxFunctor B D where __ := LaxFunctor.comp F.toLaxFunctor G.toLaxFunctor map_id _ := by simp [StrictlyUnitaryLaxFunctor.map_id] mapId_eq_eqToHom _ := by simp [StrictlyUnitaryLaxFunctor.mapId_eq_eqToHom, PrelaxFunctor.map₂_eqToHom] section attribute [local ext] StrictlyUnitaryLaxFunctor /-- Composition of `StrictlyUnitaryLaxFunctor` is strictly right unitary -/ lemma comp_id (F : StrictlyUnitaryLaxFunctor B C) : F.comp (.id C) = F := by ext · simp all_goals · rw [heq_iff_eq] ext simp /-- Composition of `StrictlyUnitaryLaxFunctor` is strictly left unitary -/ lemma id_comp (F : StrictlyUnitaryLaxFunctor B C) : (StrictlyUnitaryLaxFunctor.id B).comp F = F := by ext · simp all_goals · rw [heq_iff_eq] ext simp /-- Composition of `StrictlyUnitaryLaxFunctor` is strictly associative -/ lemma comp_assoc {E : Type u₄} [Bicategory.{w₄, v₄} E] (F : StrictlyUnitaryLaxFunctor B C) (G : StrictlyUnitaryLaxFunctor C D) (H : StrictlyUnitaryLaxFunctor D E) : (F.comp G).comp H = F.comp (G.comp H) := by ext · simp all_goals · rw [heq_iff_eq] ext simp end end StrictlyUnitaryLaxFunctor /-- A strictly unitary pseudofunctor (sometimes called a "normal homomorphism) `F` between bicategories `B` and `C` is a lax functor `F` from `B` to `C` such that the structure isomorphism `map (𝟙 X) ≅ 𝟙 (F.obj X)` is in fact an identity 1-cell for every `X : B` (in particular, there is an equality `F.map (𝟙 X) = 𝟙 (F.obj x)`). -/ @[kerodon 008R] structure StrictlyUnitaryPseudofunctor extends Pseudofunctor B C where map_id (X : B) : map (𝟙 X) = 𝟙 (obj X) := by rfl_cat mapId_eq_eqToIso (X : B) : (mapId X) = eqToIso (map_id X) := by cat_disch /-- A helper structure that bundles the necessary data to construct a `StrictlyUnitaryPseudofunctor` without specifying the redundant field `mapId` -/ structure StrictlyUnitaryPseudofunctorCore where /-- action on objects -/ obj : B → C /-- action on 1-morphisms -/ map : ∀ {X Y : B}, (X ⟶ Y) → (obj X ⟶ obj Y) map_id : ∀ (X : B), map (𝟙 X) = 𝟙 (obj X) := by rfl_cat /-- action on 2-morphisms -/ map₂ : ∀ {a b : B} {f g : a ⟶ b}, (f ⟶ g) → (map f ⟶ map g) map₂_id : ∀ {a b : B} (f : a ⟶ b), map₂ (𝟙 f) = 𝟙 (map f) := by cat_disch map₂_comp : ∀ {a b : B} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h), map₂ (η ≫ θ) = map₂ η ≫ map₂ θ := by cat_disch /-- structure 2-isomorphism for composition of 1-morphisms -/ mapComp : ∀ {a b c : B} (f : a ⟶ b) (g : b ⟶ c), map (f ≫ g) ≅ map f ≫ map g map₂_whisker_left : ∀ {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h), map₂ (f ◁ η) = (mapComp f g).hom ≫ map f ◁ map₂ η ≫ (mapComp f h).inv := by cat_disch map₂_whisker_right : ∀ {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c), map₂ (η ▷ h) = (mapComp f h).hom ≫ map₂ η ▷ map h ≫ (mapComp g h).inv := by cat_disch map₂_left_unitor : ∀ {a b : B} (f : a ⟶ b), map₂ (λ_ f).hom = (mapComp (𝟙 a) f).hom ≫ eqToHom (by rw [map_id a]) ≫ (λ_ (map f)).hom := by cat_disch map₂_right_unitor : ∀ {a b : B} (f : a ⟶ b), map₂ (ρ_ f).hom = (mapComp f (𝟙 b)).hom ≫ eqToHom (by rw [map_id b]) ≫ (ρ_ (map f)).hom := by cat_disch map₂_associator : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), map₂ (α_ f g h).hom = (mapComp (f ≫ g) h).hom ≫ (mapComp f g).hom ▷ map h ≫ (α_ (map f) (map g) (map h)).hom ≫ map f ◁ (mapComp g h).inv ≫ (mapComp f (g ≫ h)).inv := by cat_disch namespace StrictlyUnitaryPseudofunctor variable {B C} /-- An alternate constructor for strictly unitary lax functors that does not require the `mapId` fields, and that adapts the `map₂_leftUnitor` and `map₂_rightUnitor` to the fact that the functor is strictly unitary. -/ @[simps] def mk' (S : StrictlyUnitaryPseudofunctorCore B C) : StrictlyUnitaryPseudofunctor B C where obj := S.obj map := S.map map_id := S.map_id mapId x := eqToIso (S.map_id x) mapId_eq_eqToIso x := rfl map₂ := S.map₂ map₂_id := S.map₂_id map₂_comp := S.map₂_comp mapComp := S.mapComp map₂_left_unitor f := by simpa using S.map₂_left_unitor f map₂_right_unitor f := by simpa using S.map₂_right_unitor f map₂_associator f g h := by simpa using S.map₂_associator f g h map₂_whisker_left f _ _ η := by simpa using S.map₂_whisker_left f η map₂_whisker_right η f := by simpa using S.map₂_whisker_right η f /-- By forgetting the inverse to `mapComp`, a `StrictlyUnitaryPseudofunctor` is a `StrictlyUnitaryLaxFunctor`. -/ def toStrictlyUnitaryLaxFunctor (F : StrictlyUnitaryPseudofunctor B C) : StrictlyUnitaryLaxFunctor B C where __ := F.toPseudofunctor.toLax map_id x := by simp [F.map_id] mapId_eq_eqToHom x := by simp [F.mapId_eq_eqToIso] section variable (F : StrictlyUnitaryPseudofunctor B C) @[simp] lemma toStrictlyUnitaryLaxFunctor_obj (x : B) : F.toStrictlyUnitaryLaxFunctor.obj x = F.obj x := rfl @[simp] lemma toStrictlyUnitaryLaxFunctor_map {x y : B} (f : x ⟶ y) : F.toStrictlyUnitaryLaxFunctor.map f = F.map f := rfl @[simp] lemma toStrictlyUnitaryLaxFunctor_map₂ {x y : B} {f g : x ⟶ y} (η : f ⟶ g) : F.toStrictlyUnitaryLaxFunctor.map₂ η = F.map₂ η := rfl @[simp] lemma toStrictlyUnitaryLaxFunctor_mapComp {x y z : B} (f : x ⟶ y) (g : y ⟶ z) : F.toStrictlyUnitaryLaxFunctor.mapComp f g = (F.mapComp f g).inv := rfl @[simp] lemma toStrictlyUnitaryLaxFunctor_mapId {x : B} : F.toStrictlyUnitaryLaxFunctor.mapId x = (F.mapId x).inv := rfl variable (B) in /-- The identity `StrictlyUnitaryPseudofunctor`. -/ @[simps!] def id : StrictlyUnitaryPseudofunctor B B where __ := Pseudofunctor.id B map_id _ := rfl mapId_eq_eqToIso _ := rfl /-- Composition of `StrictlyUnitaryPseudofunctor`. -/ @[simps!] def comp (F : StrictlyUnitaryPseudofunctor B C) (G : StrictlyUnitaryPseudofunctor C D) : StrictlyUnitaryPseudofunctor B D where __ := Pseudofunctor.comp F.toPseudofunctor G.toPseudofunctor map_id _ := by simp [StrictlyUnitaryPseudofunctor.map_id] mapId_eq_eqToIso _ := by ext simp [StrictlyUnitaryPseudofunctor.mapId_eq_eqToIso, PrelaxFunctor.map₂_eqToHom] end end StrictlyUnitaryPseudofunctor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/NaturalTransformation/Oplax.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Oplax /-! # Transformations between oplax functors Just as there are natural transformations between functors, there are transformations between oplax functors. The equality in the naturality condition of a natural transformation gets replaced by a specified 2-morphism. Now, there are three possible types of transformations (between oplax functors): * Oplax natural transformations; * Lax natural transformations; * Strong natural transformations. These differ in the direction (and invertibility) of the 2-morphisms involved in the naturality condition. ## Main definitions * `Oplax.OplaxTrans F G`: oplax transformations between oplax functors `F` and `G`. The naturality condition is given by a 2-morphism `F.map f ≫ app b ⟶ app a ≫ G.map f` for each 1-morphism `f : a ⟶ b`. * `Oplax.StrongTrans F G`: Strong transformations between oplax functors `F` and `G`. Using these, we define two `CategoryStruct` (scoped) instances on `B ⥤ᵒᵖᴸ C`, one in the `Oplax.OplaxTrans` namespace and one in the `Oplax.StrongTrans` namespace. The arrows in these CategoryStruct's are given by oplax transformations and strong transformations respectively. We also provide API for going between oplax transformations and strong transformations: * `Oplax.StrongCore F G`: a structure on an oplax transformation between oplax functors that promotes it to a strong transformation. * `Oplax.mkOfOplax η η'`: given an oplax transformation `η` such that each component 2-morphism is an isomorphism, `mkOfOplax` gives the corresponding strong transformation. ## TODO This file could also include lax transformations between oplax functors. ## References * [Niles Johnson, Donald Yau, *2-Dimensional Categories*](https://arxiv.org/abs/2002.06055) -/ namespace CategoryTheory.Oplax open Category Bicategory universe w₁ w₂ v₁ v₂ u₁ u₂ variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] /-- If `η` is an oplax transformation between `F` and `G`, we have a 1-morphism `η.app a : F.obj a ⟶ G.obj a` for each object `a : B`. We also have a 2-morphism `η.naturality f : F.map f ≫ app b ⟶ app a ≫ G.map f` for each 1-morphism `f : a ⟶ b`. These 2-morphisms satisfies the naturality condition, and preserve the identities and the compositions modulo some adjustments of domains and codomains of 2-morphisms. -/ structure OplaxTrans (F G : B ⥤ᵒᵖᴸ C) where /-- The component 1-morphisms of an oplax transformation. -/ app (a : B) : F.obj a ⟶ G.obj a /-- The 2-morphisms underlying the oplax naturality constraint. -/ naturality {a b : B} (f : a ⟶ b) : F.map f ≫ app b ⟶ app a ≫ G.map f /-- Naturality of the oplax naturality constraint. -/ naturality_naturality {a b : B} {f g : a ⟶ b} (η : f ⟶ g) : F.map₂ η ▷ app b ≫ naturality g = naturality f ≫ app a ◁ G.map₂ η := by cat_disch /-- Oplax unity. -/ naturality_id (a : B) : naturality (𝟙 a) ≫ app a ◁ G.mapId a = F.mapId a ▷ app a ≫ (λ_ (app a)).hom ≫ (ρ_ (app a)).inv := by cat_disch /-- Oplax functoriality. -/ naturality_comp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : naturality (f ≫ g) ≫ app a ◁ G.mapComp f g = F.mapComp f g ▷ app c ≫ (α_ _ _ _).hom ≫ F.map f ◁ naturality g ≫ (α_ _ _ _).inv ≫ naturality f ▷ G.map g ≫ (α_ _ _ _).hom := by cat_disch attribute [reassoc (attr := simp)] OplaxTrans.naturality_naturality OplaxTrans.naturality_id OplaxTrans.naturality_comp @[deprecated (since := "2025-04-23")] alias _root_.CategoryTheory.OplaxNatTrans := OplaxTrans namespace OplaxTrans variable {F : B ⥤ᵒᵖᴸ C} {G H : B ⥤ᵒᵖᴸ C} (η : OplaxTrans F G) (θ : OplaxTrans G H) section variable {a b c : B} {a' : C} @[reassoc (attr := simp)] theorem whiskerLeft_naturality_naturality (f : a' ⟶ G.obj a) {g h : a ⟶ b} (β : g ⟶ h) : f ◁ G.map₂ β ▷ θ.app b ≫ f ◁ θ.naturality h = f ◁ θ.naturality g ≫ f ◁ θ.app a ◁ H.map₂ β := by simp_rw [← whiskerLeft_comp, naturality_naturality] @[reassoc (attr := simp)] theorem whiskerRight_naturality_naturality {f g : a ⟶ b} (β : f ⟶ g) (h : G.obj b ⟶ a') : F.map₂ β ▷ η.app b ▷ h ≫ η.naturality g ▷ h = η.naturality f ▷ h ≫ (α_ _ _ _).hom ≫ η.app a ◁ G.map₂ β ▷ h ≫ (α_ _ _ _).inv := by rw [← comp_whiskerRight, naturality_naturality, comp_whiskerRight, whisker_assoc] @[reassoc (attr := simp)] theorem whiskerLeft_naturality_comp (f : a' ⟶ G.obj a) (g : a ⟶ b) (h : b ⟶ c) : f ◁ θ.naturality (g ≫ h) ≫ f ◁ θ.app a ◁ H.mapComp g h = f ◁ G.mapComp g h ▷ θ.app c ≫ f ◁ (α_ _ _ _).hom ≫ f ◁ G.map g ◁ θ.naturality h ≫ f ◁ (α_ _ _ _).inv ≫ f ◁ θ.naturality g ▷ H.map h ≫ f ◁ (α_ _ _ _).hom := by simp_rw [← whiskerLeft_comp, naturality_comp] @[reassoc (attr := simp)] theorem whiskerRight_naturality_comp (f : a ⟶ b) (g : b ⟶ c) (h : G.obj c ⟶ a') : η.naturality (f ≫ g) ▷ h ≫ (α_ _ _ _).hom ≫ η.app a ◁ G.mapComp f g ▷ h = F.mapComp f g ▷ η.app c ▷ h ≫ (α_ _ _ _).hom ▷ h ≫ (α_ _ _ _).hom ≫ F.map f ◁ η.naturality g ▷ h ≫ (α_ _ _ _).inv ≫ (α_ _ _ _).inv ▷ h ≫ η.naturality f ▷ G.map g ▷ h ≫ (α_ _ _ _).hom ▷ h ≫ (α_ _ _ _).hom := by rw [← associator_naturality_middle, ← comp_whiskerRight_assoc, naturality_comp]; simp @[reassoc (attr := simp)] theorem whiskerLeft_naturality_id (f : a' ⟶ G.obj a) : f ◁ θ.naturality (𝟙 a) ≫ f ◁ θ.app a ◁ H.mapId a = f ◁ G.mapId a ▷ θ.app a ≫ f ◁ (λ_ (θ.app a)).hom ≫ f ◁ (ρ_ (θ.app a)).inv := by simp_rw [← whiskerLeft_comp, naturality_id] @[reassoc (attr := simp)] theorem whiskerRight_naturality_id (f : G.obj a ⟶ a') : η.naturality (𝟙 a) ▷ f ≫ (α_ _ _ _).hom ≫ η.app a ◁ G.mapId a ▷ f = F.mapId a ▷ η.app a ▷ f ≫ (λ_ (η.app a)).hom ▷ f ≫ (ρ_ (η.app a)).inv ▷ f ≫ (α_ _ _ _).hom := by rw [← associator_naturality_middle, ← comp_whiskerRight_assoc, naturality_id]; simp end variable (F) in /-- The identity oplax transformation. -/ def id : OplaxTrans F F where app a := 𝟙 (F.obj a) naturality {_ _} f := (ρ_ (F.map f)).hom ≫ (λ_ (F.map f)).inv instance : Inhabited (OplaxTrans F F) := ⟨id F⟩ /-- Vertical composition of oplax transformations. -/ def vcomp : OplaxTrans F H where app a := η.app a ≫ θ.app a naturality {a b} f := (α_ _ _ _).inv ≫ η.naturality f ▷ θ.app b ≫ (α_ _ _ _).hom ≫ η.app a ◁ θ.naturality f ≫ (α_ _ _ _).inv naturality_comp {a b c} f g := calc _ = (α_ _ _ _).inv ≫ F.mapComp f g ▷ η.app c ▷ θ.app c ≫ (α_ _ _ _).hom ▷ _ ≫ (α_ _ _ _).hom ≫ F.map f ◁ η.naturality g ▷ θ.app c ≫ _ ◁ (α_ _ _ _).hom ≫ (α_ _ _ _).inv ≫ (F.map f ≫ η.app b) ◁ θ.naturality g ≫ η.naturality f ▷ (θ.app b ≫ H.map g) ≫ (α_ _ _ _).hom ≫ _ ◁ (α_ _ _ _).inv ≫ η.app a ◁ θ.naturality f ▷ H.map g ≫ _ ◁ (α_ _ _ _).hom ≫ (α_ _ _ _).inv := by rw [whisker_exchange_assoc]; simp _ = _ := by simp /-- `CategoryStruct` on `B ⥤ᵒᵖᴸ C` where the (1-)morphisms are given by oplax transformations. -/ @[simps! id_app id_naturality comp_app comp_naturality] scoped instance : CategoryStruct (B ⥤ᵒᵖᴸ C) where Hom := OplaxTrans id := OplaxTrans.id comp := OplaxTrans.vcomp end OplaxTrans /-- A strong natural transformation between oplax functors `F` and `G` is a natural transformation that is "natural up to 2-isomorphisms". More precisely, it consists of the following: * a 1-morphism `η.app a : F.obj a ⟶ G.obj a` for each object `a : B`. * a 2-isomorphism `η.naturality f : F.map f ≫ app b ⟶ app a ≫ G.map f` for each 1-morphism `f : a ⟶ b`. * These 2-isomorphisms satisfy the naturality condition, and preserve the identities and the compositions modulo some adjustments of domains and codomains of 2-morphisms. -/ structure StrongTrans (F G : B ⥤ᵒᵖᴸ C) where app (a : B) : F.obj a ⟶ G.obj a naturality {a b : B} (f : a ⟶ b) : F.map f ≫ app b ≅ app a ≫ G.map f naturality_naturality {a b : B} {f g : a ⟶ b} (η : f ⟶ g) : F.map₂ η ▷ app b ≫ (naturality g).hom = (naturality f).hom ≫ app a ◁ G.map₂ η := by cat_disch naturality_id (a : B) : (naturality (𝟙 a)).hom ≫ app a ◁ G.mapId a = F.mapId a ▷ app a ≫ (λ_ (app a)).hom ≫ (ρ_ (app a)).inv := by cat_disch naturality_comp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : (naturality (f ≫ g)).hom ≫ app a ◁ G.mapComp f g = F.mapComp f g ▷ app c ≫ (α_ _ _ _).hom ≫ F.map f ◁ (naturality g).hom ≫ (α_ _ _ _).inv ≫ (naturality f).hom ▷ G.map g ≫ (α_ _ _ _).hom := by cat_disch @[deprecated (since := "2025-04-23")] alias StrongOplaxNatTrans := StrongTrans attribute [nolint docBlame] CategoryTheory.Oplax.StrongTrans.app CategoryTheory.Oplax.StrongTrans.naturality attribute [reassoc (attr := simp)] StrongTrans.naturality_naturality StrongTrans.naturality_id StrongTrans.naturality_comp /-- A structure on an oplax transformation that promotes it to a strong transformation. See `Pseudofunctor.StrongTrans.mkOfOplax`. -/ structure OplaxTrans.StrongCore {F G : B ⥤ᵒᵖᴸ C} (η : F ⟶ G) where /-- The underlying 2-isomorphisms of the naturality constraint. -/ naturality {a b : B} (f : a ⟶ b) : F.map f ≫ η.app b ≅ η.app a ≫ G.map f /-- The 2-isomorphisms agree with the underlying 2-morphism of the oplax transformation. -/ naturality_hom {a b : B} (f : a ⟶ b) : (naturality f).hom = η.naturality f := by cat_disch attribute [simp] OplaxTrans.StrongCore.naturality_hom namespace StrongTrans /-- The underlying oplax natural transformation of a strong natural transformation. -/ @[simps] def toOplax {F G : B ⥤ᵒᵖᴸ C} (η : StrongTrans F G) : OplaxTrans F G where app := η.app naturality f := (η.naturality f).hom /-- Construct a strong natural transformation from an oplax natural transformation whose naturality 2-morphism is an isomorphism. -/ def mkOfOplax {F G : B ⥤ᵒᵖᴸ C} (η : OplaxTrans F G) (η' : OplaxTrans.StrongCore η) : StrongTrans F G where app := η.app naturality := η'.naturality /-- Construct a strong natural transformation from an oplax natural transformation whose naturality 2-morphism is an isomorphism. -/ noncomputable def mkOfOplax' {F G : B ⥤ᵒᵖᴸ C} (η : OplaxTrans F G) [∀ a b (f : a ⟶ b), IsIso (η.naturality f)] : StrongTrans F G where app := η.app naturality _ := asIso (η.naturality _) variable (F : B ⥤ᵒᵖᴸ C) /-- The identity strong natural transformation. -/ @[simps!] def id : StrongTrans F F := mkOfOplax (OplaxTrans.id F) { naturality := fun f ↦ (ρ_ (F.map f)) ≪≫ (λ_ (F.map f)).symm } @[simp] lemma id.toOplax : (id F).toOplax = OplaxTrans.id F := rfl instance : Inhabited (StrongTrans F F) := ⟨id F⟩ variable {F} {G H : B ⥤ᵒᵖᴸ C} (η : StrongTrans F G) (θ : StrongTrans G H) /-- Vertical composition of strong natural transformations. -/ @[simps!] def vcomp : StrongTrans F H := mkOfOplax (OplaxTrans.vcomp η.toOplax θ.toOplax) { naturality := fun {a b} f ↦ (α_ _ _ _).symm ≪≫ whiskerRightIso (η.naturality f) (θ.app b) ≪≫ (α_ _ _ _) ≪≫ whiskerLeftIso (η.app a) (θ.naturality f) ≪≫ (α_ _ _ _).symm } /-- `CategoryStruct` on `B ⥤ᵒᵖᴸ C` where the (1-)morphisms are given by strong transformations. -/ @[simps! id_app id_naturality comp_app comp_naturality] scoped instance OplaxFunctor.instCategoryStruct : CategoryStruct (B ⥤ᵒᵖᴸ C) where Hom := StrongTrans id := StrongTrans.id comp := StrongTrans.vcomp section variable {a b c : B} {a' : C} @[reassoc (attr := simp), to_app] theorem whiskerLeft_naturality_naturality (f : a' ⟶ G.obj a) {g h : a ⟶ b} (β : g ⟶ h) : f ◁ G.map₂ β ▷ θ.app b ≫ f ◁ (θ.naturality h).hom = f ◁ (θ.naturality g).hom ≫ f ◁ θ.app a ◁ H.map₂ β := by apply θ.toOplax.whiskerLeft_naturality_naturality @[reassoc (attr := simp), to_app] theorem whiskerRight_naturality_naturality {f g : a ⟶ b} (β : f ⟶ g) (h : G.obj b ⟶ a') : F.map₂ β ▷ η.app b ▷ h ≫ (η.naturality g).hom ▷ h = (η.naturality f).hom ▷ h ≫ (α_ _ _ _).hom ≫ η.app a ◁ G.map₂ β ▷ h ≫ (α_ _ _ _).inv := η.toOplax.whiskerRight_naturality_naturality _ _ @[reassoc (attr := simp), to_app] theorem whiskerLeft_naturality_comp (f : a' ⟶ G.obj a) (g : a ⟶ b) (h : b ⟶ c) : f ◁ (θ.naturality (g ≫ h)).hom ≫ f ◁ θ.app a ◁ H.mapComp g h = f ◁ G.mapComp g h ▷ θ.app c ≫ f ◁ (α_ _ _ _).hom ≫ f ◁ G.map g ◁ (θ.naturality h).hom ≫ f ◁ (α_ _ _ _).inv ≫ f ◁ (θ.naturality g).hom ▷ H.map h ≫ f ◁ (α_ _ _ _).hom := θ.toOplax.whiskerLeft_naturality_comp _ _ _ @[reassoc (attr := simp), to_app] theorem whiskerRight_naturality_comp (f : a ⟶ b) (g : b ⟶ c) (h : G.obj c ⟶ a') : (η.naturality (f ≫ g)).hom ▷ h ≫ (α_ _ _ _).hom ≫ η.app a ◁ G.mapComp f g ▷ h = F.mapComp f g ▷ η.app c ▷ h ≫ (α_ _ _ _).hom ▷ h ≫ (α_ _ _ _).hom ≫ F.map f ◁ (η.naturality g).hom ▷ h ≫ (α_ _ _ _).inv ≫ (α_ _ _ _).inv ▷ h ≫ (η.naturality f).hom ▷ G.map g ▷ h ≫ (α_ _ _ _).hom ▷ h ≫ (α_ _ _ _).hom := η.toOplax.whiskerRight_naturality_comp _ _ _ @[reassoc (attr := simp), to_app] theorem whiskerLeft_naturality_id (f : a' ⟶ G.obj a) : f ◁ (θ.naturality (𝟙 a)).hom ≫ f ◁ θ.app a ◁ H.mapId a = f ◁ G.mapId a ▷ θ.app a ≫ f ◁ (λ_ (θ.app a)).hom ≫ f ◁ (ρ_ (θ.app a)).inv := θ.toOplax.whiskerLeft_naturality_id _ @[reassoc (attr := simp), to_app] theorem whiskerRight_naturality_id (f : G.obj a ⟶ a') : (η.naturality (𝟙 a)).hom ▷ f ≫ (α_ _ _ _).hom ≫ η.app a ◁ G.mapId a ▷ f = F.mapId a ▷ η.app a ▷ f ≫ (λ_ (η.app a)).hom ▷ f ≫ (ρ_ (η.app a)).inv ▷ f ≫ (α_ _ _ _).hom := η.toOplax.whiskerRight_naturality_id _ end end StrongTrans end CategoryTheory.Oplax
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/NaturalTransformation/Strong.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor import Mathlib.CategoryTheory.Bicategory.NaturalTransformation.Oplax deprecated_module (since := "2025-05-11")
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/NaturalTransformation/Pseudo.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor import Mathlib.CategoryTheory.Bicategory.NaturalTransformation.Oplax /-! # Strong transformations of pseudofunctors There are three types of transformations between pseudofunctors, depending on the direction or invertibility of the 2-morphism witnessing the naturality condition. In this file we define strong transformations, which require the 2-morphism to be invertible. ## Main definitions * `Pseudofunctor.StrongTrans F G`: strong transformations between pseudofunctors `F` and `G`. * `Pseudofunctor.mkOfOplax η η'`: Given two pseudofunctors, and a strong transformation `η` between their underlying oplax functors, `mkOfOplax` lifts this to a strong transformation between the pseudofunctors. * `Pseudofunctor.StrongTrans.vcomp η θ`: the vertical composition of strong transformations `η` and `θ`. Using this we obtain a `CategoryStruct` on pseudofunctors, where the arrows are given by strong transformations. See `Pseudofunctor.categoryStruct`. ## References * [Niles Johnson, Donald Yau, *2-Dimensional Categories*](https://arxiv.org/abs/2002.06055) -/ namespace CategoryTheory.Pseudofunctor open Category Bicategory Oplax universe w₁ w₂ v₁ v₂ u₁ u₂ variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] /-- A strong transformation between pseudofunctors `F` and `G` is a natural transformation that is "natural up to 2-isomorphisms". More precisely, it consists of the following: * a 1-morphism `η.app a : F.obj a ⟶ G.obj a` for each object `a : B`. * a 2-isomorphism `η.naturality f : F.map f ≫ app b ≅ app a ≫ G.map f` for each 1-morphism `f : a ⟶ b`. * These 2-isomorphisms satisfy the naturality condition, and preserve the identities and the compositions modulo some adjustments of domains and codomains of 2-morphisms. -/ structure StrongTrans (F G : Pseudofunctor B C) where /-- The component 1-morphisms of a strong transformation. -/ app (a : B) : F.obj a ⟶ G.obj a /-- The 2-isomorphisms underlying the strong naturality constraint. -/ naturality {a b : B} (f : a ⟶ b) : F.map f ≫ app b ≅ app a ≫ G.map f /-- Naturality of the strong naturality constraint. -/ naturality_naturality {a b : B} {f g : a ⟶ b} (η : f ⟶ g) : F.map₂ η ▷ app b ≫ (naturality g).hom = (naturality f).hom ≫ app a ◁ G.map₂ η := by cat_disch /-- Oplax unity. -/ naturality_id (a : B) : (naturality (𝟙 a)).hom ≫ app a ◁ (G.mapId a).hom = (F.mapId a).hom ▷ app a ≫ (λ_ (app a)).hom ≫ (ρ_ (app a)).inv := by cat_disch /-- Oplax functoriality. -/ naturality_comp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : (naturality (f ≫ g)).hom ≫ app a ◁ (G.mapComp f g).hom = (F.mapComp f g).hom ▷ app c ≫ (α_ _ _ _).hom ≫ F.map f ◁ (naturality g).hom ≫ (α_ _ _ _).inv ≫ (naturality f).hom ▷ G.map g ≫ (α_ _ _ _).hom := by cat_disch attribute [reassoc (attr := simp)] StrongTrans.naturality_naturality StrongTrans.naturality_id StrongTrans.naturality_comp namespace StrongTrans variable {F G : B ⥤ᵖ C} /-- The underlying oplax transformation of a strong transformation. -/ @[simps] def toOplax (η : StrongTrans F G) : Oplax.StrongTrans F.toOplax G.toOplax where app := η.app naturality f := η.naturality f instance hasCoeToOplax : Coe (StrongTrans F G) (Oplax.StrongTrans F.toOplax G.toOplax) := ⟨toOplax⟩ /-- Construct a strong transformation of pseudofunctors from a strong transformation of the underlying oplax functors. -/ @[simps] def mkOfOplax (η : Oplax.StrongTrans F.toOplax G.toOplax) : StrongTrans F G where app := η.app naturality := η.naturality naturality_naturality θ := η.naturality_naturality θ naturality_id a := η.naturality_id a naturality_comp f g := η.naturality_comp f g variable (F) in /-- The identity strong transformation. -/ def id : StrongTrans F F where app a := 𝟙 (F.obj a) naturality {a b} f := (ρ_ (F.map f)) ≪≫ (λ_ (F.map f)).symm instance : Inhabited (StrongTrans F F) := ⟨id F⟩ variable {H : B ⥤ᵖ C} /-- Vertical composition of strong transformations. -/ def vcomp (η : StrongTrans F G) (θ : StrongTrans G H) : StrongTrans F H := mkOfOplax (Oplax.StrongTrans.vcomp η.toOplax θ.toOplax) /-- `CategoryStruct` on `B ⥤ᵖ C` where the (1-)morphisms are given by strong transformations. -/ @[simps! id_app id_naturality_hom id_naturality_inv comp_naturality_hom comp_naturality_inv] scoped instance categoryStruct : CategoryStruct (B ⥤ᵖ C) where Hom F G := StrongTrans F G id F := StrongTrans.id F comp := StrongTrans.vcomp variable (η : F ⟶ G) (θ : G ⟶ H) @[simp] lemma comp_app (η : F ⟶ G) (θ : G ⟶ H) (a : B) : (η ≫ θ).app a = η.app a ≫ θ.app a := rfl variable (F) in @[simp] lemma id.toOplax : Oplax.StrongTrans.id F.toOplax = 𝟙 F := rfl section variable {a b c : B} {a' : C} @[reassoc (attr := simp), to_app] theorem whiskerLeft_naturality_naturality (f : a' ⟶ G.obj a) {g h : a ⟶ b} (β : g ⟶ h) : f ◁ G.map₂ β ▷ θ.app b ≫ f ◁ (θ.naturality h).hom = f ◁ (θ.naturality g).hom ≫ f ◁ θ.app a ◁ H.map₂ β := θ.toOplax.whiskerLeft_naturality_naturality _ _ @[reassoc (attr := simp), to_app] theorem whiskerRight_naturality_naturality {f g : a ⟶ b} (β : f ⟶ g) (h : G.obj b ⟶ a') : F.map₂ β ▷ η.app b ▷ h ≫ (η.naturality g).hom ▷ h = (η.naturality f).hom ▷ h ≫ (α_ _ _ _).hom ≫ η.app a ◁ G.map₂ β ▷ h ≫ (α_ _ _ _).inv := η.toOplax.whiskerRight_naturality_naturality _ _ @[reassoc (attr := simp), to_app] theorem whiskerLeft_naturality_comp (f : a' ⟶ G.obj a) (g : a ⟶ b) (h : b ⟶ c) : f ◁ (θ.naturality (g ≫ h)).hom ≫ f ◁ θ.app a ◁ (H.mapComp g h).hom = f ◁ (G.mapComp g h).hom ▷ θ.app c ≫ f ◁ (α_ _ _ _).hom ≫ f ◁ G.map g ◁ (θ.naturality h).hom ≫ f ◁ (α_ _ _ _).inv ≫ f ◁ (θ.naturality g).hom ▷ H.map h ≫ f ◁ (α_ _ _ _).hom := θ.toOplax.whiskerLeft_naturality_comp _ _ _ @[reassoc (attr := simp), to_app] theorem whiskerRight_naturality_comp (f : a ⟶ b) (g : b ⟶ c) (h : G.obj c ⟶ a') : (η.naturality (f ≫ g)).hom ▷ h ≫ (α_ _ _ _).hom ≫ η.app a ◁ (G.mapComp f g).hom ▷ h = (F.mapComp f g).hom ▷ η.app c ▷ h ≫ (α_ _ _ _).hom ▷ h ≫ (α_ _ _ _).hom ≫ F.map f ◁ (η.naturality g).hom ▷ h ≫ (α_ _ _ _).inv ≫ (α_ _ _ _).inv ▷ h ≫ (η.naturality f).hom ▷ G.map g ▷ h ≫ (α_ _ _ _).hom ▷ h ≫ (α_ _ _ _).hom := η.toOplax.whiskerRight_naturality_comp _ _ _ @[reassoc (attr := simp), to_app] theorem whiskerLeft_naturality_id (f : a' ⟶ G.obj a) : f ◁ (θ.naturality (𝟙 a)).hom ≫ f ◁ θ.app a ◁ (H.mapId a).hom = f ◁ (G.mapId a).hom ▷ θ.app a ≫ f ◁ (λ_ (θ.app a)).hom ≫ f ◁ (ρ_ (θ.app a)).inv := θ.toOplax.whiskerLeft_naturality_id _ @[reassoc (attr := simp), to_app] theorem whiskerRight_naturality_id (f : G.obj a ⟶ a') : (η.naturality (𝟙 a)).hom ▷ f ≫ (α_ _ _ _).hom ≫ η.app a ◁ (G.mapId a).hom ▷ f = (F.mapId a).hom ▷ η.app a ▷ f ≫ (λ_ (η.app a)).hom ▷ f ≫ (ρ_ (η.app a)).inv ▷ f ≫ (α_ _ _ _).hom := η.toOplax.whiskerRight_naturality_id _ @[reassoc, to_app] lemma naturality_id_hom (α : F ⟶ G) (a : B) : (α.naturality (𝟙 a)).hom = (F.mapId a).hom ▷ α.app a ≫ (λ_ (α.app a)).hom ≫ (ρ_ (α.app a)).inv ≫ α.app a ◁ (G.mapId a).inv := by simp [← assoc, ← IsIso.comp_inv_eq] lemma naturality_id_iso (α : F ⟶ G) (a : B) : α.naturality (𝟙 a) = whiskerRightIso (F.mapId a) (α.app a) ≪≫ (λ_ (α.app a)) ≪≫ (ρ_ (α.app a)).symm ≪≫ whiskerLeftIso (α.app a) (G.mapId a).symm := by ext simp [naturality_id_hom] @[reassoc, to_app] lemma naturality_id_inv (α : F ⟶ G) (a : B) : (α.naturality (𝟙 a)).inv = α.app a ◁ (G.mapId a).hom ≫ (ρ_ (α.app a)).hom ≫ (λ_ (α.app a)).inv ≫ (F.mapId a).inv ▷ α.app a := by simp [naturality_id_iso] @[reassoc, to_app] lemma naturality_naturality_hom (α : F ⟶ G) {a b : B} {f g : a ⟶ b} (η : f ≅ g) : (α.naturality g).hom = (F.map₂ η.inv) ▷ α.app b ≫ (α.naturality f).hom ≫ α.app a ◁ G.map₂ η.hom := by simp [← IsIso.inv_comp_eq, ← G.map₂_inv η.inv] lemma naturality_naturality_iso (α : F ⟶ G) {a b : B} {f g : a ⟶ b} (η : f ≅ g) : α.naturality g = whiskerRightIso (F.map₂Iso η.symm) (α.app b) ≪≫ (α.naturality f) ≪≫ whiskerLeftIso (α.app a) (G.map₂Iso η) := by ext rw [naturality_naturality_hom α η] simp lemma naturality_naturality_inv (α : F ⟶ G) {a b : B} {f g : a ⟶ b} (η : f ≅ g) : (α.naturality g).inv = α.app a ◁ G.map₂ η.inv ≫ (α.naturality f).inv ≫ F.map₂ η.hom ▷ α.app b := by simp [naturality_naturality_iso α η] @[reassoc, to_app] lemma naturality_comp_hom (α : F ⟶ G) {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : (α.naturality (f ≫ g)).hom = (F.mapComp f g).hom ▷ α.app c ≫ (α_ _ _ _).hom ≫ F.map f ◁ (α.naturality g).hom ≫ (α_ _ _ _).inv ≫ (α.naturality f).hom ▷ G.map g ≫ (α_ _ _ _).hom ≫ α.app a ◁ (G.mapComp f g).inv := by simp [← assoc, ← IsIso.comp_inv_eq] lemma naturality_comp_iso (α : F ⟶ G) {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : α.naturality (f ≫ g) = whiskerRightIso (F.mapComp f g) (α.app c) ≪≫ (α_ _ _ _) ≪≫ whiskerLeftIso (F.map f) (α.naturality g) ≪≫ (α_ _ _ _).symm ≪≫ whiskerRightIso (α.naturality f) (G.map g) ≪≫ α_ _ _ _ ≪≫ whiskerLeftIso (α.app a) (G.mapComp f g).symm := by ext simp [naturality_comp_hom α f g] @[reassoc, to_app] lemma naturality_comp_inv (α : F ⟶ G) {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : (α.naturality (f ≫ g)).inv = α.app a ◁ (G.mapComp f g).hom ≫ (α_ _ _ _).inv ≫ (α.naturality f).inv ▷ G.map g ≫ (α_ _ _ _).hom ≫ F.map f ◁ (α.naturality g).inv ≫ (α_ _ _ _).inv ≫ (F.mapComp f g).inv ▷ α.app c := by simp [naturality_comp_iso α f g] end end CategoryTheory.Pseudofunctor.StrongTrans
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Modification/Oplax.lean
import Mathlib.CategoryTheory.Bicategory.NaturalTransformation.Oplax /-! # Modifications between oplax transformations A modification `Γ` between oplax transformations `η` and `θ` consists of a family of 2-morphisms `Γ.app a : η.app a ⟶ θ.app a`, which for all 1-morphisms `f : a ⟶ b` satisfies the equation `(F.map f ◁ app b) ≫ θ.naturality f = η.naturality f ≫ app a ▷ G.map f`. ## Main definitions * `Modification η θ`: modifications between oplax transformations `η` and `θ` * `Modification.vcomp η θ`: the vertical composition of oplax transformations `η` and `θ` * `OplaxTrans.category F G`: the category structure on the oplax transformations between `F` and `G` -/ namespace CategoryTheory.Oplax.OplaxTrans open Category Bicategory universe w₁ w₂ v₁ v₂ u₁ u₂ variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] {F G : B ⥤ᵒᵖᴸ C} (η θ : F ⟶ G) variable {F G : B ⥤ᵒᵖᴸ C} /-- A modification `Γ` between oplax natural transformations `η` and `θ` consists of a family of 2-morphisms `Γ.app a : η.app a ⟶ θ.app a`, which satisfies the equation `(F.map f ◁ app b) ≫ θ.naturality f = η.naturality f ≫ (app a ▷ G.map f)` for each 1-morphism `f : a ⟶ b`. -/ @[ext] structure Modification (η θ : F ⟶ G) where /-- The underlying family of 2-morphisms. -/ app (a : B) : η.app a ⟶ θ.app a /-- The naturality condition. -/ naturality : ∀ {a b : B} (f : a ⟶ b), F.map f ◁ app b ≫ θ.naturality f = η.naturality f ≫ app a ▷ G.map f := by cat_disch attribute [reassoc (attr := simp)] Modification.naturality variable {η θ ι : F ⟶ G} namespace Modification variable (η) /-- The identity modification. -/ @[simps] def id : Modification η η where app a := 𝟙 (η.app a) instance : Inhabited (Modification η η) := ⟨Modification.id η⟩ variable {η} section variable (Γ : Modification η θ) {a b c : B} {a' : C} @[reassoc (attr := simp)] theorem whiskerLeft_naturality (f : a' ⟶ F.obj b) (g : b ⟶ c) : f ◁ F.map g ◁ Γ.app c ≫ f ◁ θ.naturality g = f ◁ η.naturality g ≫ f ◁ Γ.app b ▷ G.map g := by simp_rw [← Bicategory.whiskerLeft_comp, naturality] @[reassoc (attr := simp)] theorem whiskerRight_naturality (f : a ⟶ b) (g : G.obj b ⟶ a') : F.map f ◁ Γ.app b ▷ g ≫ (α_ _ _ _).inv ≫ θ.naturality f ▷ g = (α_ _ _ _).inv ≫ η.naturality f ▷ g ≫ Γ.app a ▷ G.map f ▷ g := by simp_rw [associator_inv_naturality_middle_assoc, ← comp_whiskerRight, naturality] end /-- Vertical composition of modifications. -/ @[simps] def vcomp (Γ : Modification η θ) (Δ : Modification θ ι) : Modification η ι where app a := Γ.app a ≫ Δ.app a end Modification /-- Category structure on the oplax natural transformations between OplaxFunctors. -/ @[simps] scoped instance category (F G : B ⥤ᵒᵖᴸ C) : Category (F ⟶ G) where Hom := Modification id := Modification.id comp := Modification.vcomp @[ext] lemma ext {F G : B ⥤ᵒᵖᴸ C} {α β : F ⟶ G} {m n : α ⟶ β} (w : ∀ b, m.app b = n.app b) : m = n := by apply Modification.ext ext apply w /-- Version of `Modification.id_app` using category notation -/ @[simp] lemma Modification.id_app' {X : B} {F G : B ⥤ᵒᵖᴸ C} (α : F ⟶ G) : Modification.app (𝟙 α) X = 𝟙 (α.app X) := rfl /-- Version of `Modification.comp_app` using category notation -/ @[simp] lemma Modification.comp_app' {X : B} {F G : B ⥤ᵒᵖᴸ C} {α β γ : F ⟶ G} (m : α ⟶ β) (n : β ⟶ γ) : (m ≫ n).app X = m.app X ≫ n.app X := rfl /-- Construct a modification isomorphism between oplax natural transformations by giving object level isomorphisms, and checking naturality only in the forward direction. -/ @[simps] def ModificationIso.ofComponents (app : ∀ a, η.app a ≅ θ.app a) (naturality : ∀ {a b} (f : a ⟶ b), F.map f ◁ (app b).hom ≫ θ.naturality f = η.naturality f ≫ (app a).hom ▷ G.map f) : η ≅ θ where hom := { app := fun a => (app a).hom } inv := { app := fun a => (app a).inv naturality := fun {a b} f => by simpa using congr_arg (fun f => _ ◁ (app b).inv ≫ f ≫ (app a).inv ▷ _) (naturality f).symm } end CategoryTheory.Oplax.OplaxTrans
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Kan/IsKan.lean
import Mathlib.CategoryTheory.Bicategory.Extension /-! # Kan extensions and Kan lifts in bicategories The left Kan extension of a 1-morphism `g : a ⟶ c` along a 1-morphism `f : a ⟶ b` is the initial object in the category of left extensions `LeftExtension f g`. The universal property can be accessed by the following definition and lemmas: * `LeftExtension.IsKan.desc`: the family of 2-morphisms out of the left Kan extension. * `LeftExtension.IsKan.fac`: the unit of any left extension factors through the left Kan extension. * `LeftExtension.IsKan.hom_ext`: two 2-morphisms out of the left Kan extension are equal if their compositions with each unit are equal. We also define left Kan lifts, right Kan extensions, and right Kan lifts. ## Implementation Notes We use the Is-Has design pattern, which is used for the implementation of limits and colimits in the category theory library. This means that `IsKan t` is a structure containing the data of 2-morphisms which ensure that `t` is a Kan extension, while `HasKan f g` defined in `CategoryTheory.Bicategory.Kan.HasKan` is a `Prop`-valued typeclass asserting that a Kan extension of `g` along `f` exists. We define `LeftExtension.IsKan t` for an extension `t : LeftExtension f g` (which is an abbreviation of `t : StructuredArrow g (precomp _ f)`) to be an abbreviation for `StructuredArrow.IsUniversal t`. This means that we can use the definitions and lemmas living in the namespace `StructuredArrow.IsUniversal`. ## References https://ncatlab.org/nlab/show/Kan+extension -/ namespace CategoryTheory namespace Bicategory universe w v u variable {B : Type u} [Bicategory.{w, v} B] {a b c : B} namespace LeftExtension variable {f : a ⟶ b} {g : a ⟶ c} /-- A left Kan extension of `g` along `f` is an initial object in `LeftExtension f g`. -/ abbrev IsKan (t : LeftExtension f g) := t.IsUniversal /-- An absolute left Kan extension is a Kan extension that commutes with any 1-morphism. -/ abbrev IsAbsKan (t : LeftExtension f g) := ∀ {x : B} (h : c ⟶ x), IsKan (t.whisker h) namespace IsKan variable {s t : LeftExtension f g} /-- To show that a left extension `t` is a Kan extension, we need to show that for every left extension `s` there is a unique morphism `t ⟶ s`. -/ abbrev mk (desc : ∀ s, t ⟶ s) (w : ∀ s τ, τ = desc s) : IsKan t := .ofUniqueHom desc w /-- The family of 2-morphisms out of a left Kan extension. -/ abbrev desc (H : IsKan t) (s : LeftExtension f g) : t.extension ⟶ s.extension := StructuredArrow.IsUniversal.desc H s @[reassoc (attr := simp)] theorem fac (H : IsKan t) (s : LeftExtension f g) : t.unit ≫ f ◁ H.desc s = s.unit := StructuredArrow.IsUniversal.fac H s /-- Two 2-morphisms out of a left Kan extension are equal if their compositions with each triangle 2-morphism are equal. -/ theorem hom_ext (H : IsKan t) {k : b ⟶ c} {τ τ' : t.extension ⟶ k} (w : t.unit ≫ f ◁ τ = t.unit ≫ f ◁ τ') : τ = τ' := StructuredArrow.IsUniversal.hom_ext H w /-- Kan extensions on `g` along `f` are unique up to isomorphism. -/ def uniqueUpToIso (P : IsKan s) (Q : IsKan t) : s ≅ t := Limits.IsInitial.uniqueUpToIso P Q @[simp] theorem uniqueUpToIso_hom_right (P : IsKan s) (Q : IsKan t) : (uniqueUpToIso P Q).hom.right = P.desc t := rfl @[simp] theorem uniqueUpToIso_inv_right (P : IsKan s) (Q : IsKan t) : (uniqueUpToIso P Q).inv.right = Q.desc s := rfl /-- Transport evidence that a left extension is a Kan extension across an isomorphism of extensions. -/ def ofIsoKan (P : IsKan s) (i : s ≅ t) : IsKan t := Limits.IsInitial.ofIso P i /-- If `t : LeftExtension f (g ≫ 𝟙 c)` is a Kan extension, then `t.ofCompId : LeftExtension f g` is also a Kan extension. -/ def ofCompId (t : LeftExtension f (g ≫ 𝟙 c)) (P : IsKan t) : IsKan t.ofCompId := .mk (fun s ↦ t.whiskerIdCancel <| P.to (s.whisker (𝟙 c))) <| by intro s τ ext apply P.hom_ext simp [← LeftExtension.w τ] /-- If `s ≅ t` and `IsKan (s.whisker h)`, then `IsKan (t.whisker h)`. -/ def whiskerOfCommute (s t : LeftExtension f g) (i : s ≅ t) {x : B} (h : c ⟶ x) (P : IsKan (s.whisker h)) : IsKan (t.whisker h) := P.ofIsoKan <| whiskerIso i h end IsKan namespace IsAbsKan variable {s t : LeftExtension f g} /-- The family of 2-morphisms out of an absolute left Kan extension. -/ abbrev desc (H : IsAbsKan t) {x : B} {h : c ⟶ x} (s : LeftExtension f (g ≫ h)) : t.extension ≫ h ⟶ s.extension := (H h).desc s /-- An absolute left Kan extension is a left Kan extension. -/ def isKan (H : IsAbsKan t) : IsKan t := ((H (𝟙 c)).ofCompId _).ofIsoKan <| whiskerOfCompIdIsoSelf t /-- Transport evidence that a left extension is a Kan extension across an isomorphism of extensions. -/ def ofIsoAbsKan (P : IsAbsKan s) (i : s ≅ t) : IsAbsKan t := fun h ↦ (P h).ofIsoKan (whiskerIso i h) end IsAbsKan end LeftExtension namespace LeftLift variable {f : b ⟶ a} {g : c ⟶ a} /-- A left Kan lift of `g` along `f` is an initial object in `LeftLift f g`. -/ abbrev IsKan (t : LeftLift f g) := t.IsUniversal /-- An absolute left Kan lift is a Kan lift such that every 1-morphism commutes with it. -/ abbrev IsAbsKan (t : LeftLift f g) := ∀ {x : B} (h : x ⟶ c), IsKan (t.whisker h) namespace IsKan variable {s t : LeftLift f g} /-- To show that a left lift `t` is a Kan lift, we need to show that for every left lift `s` there is a unique morphism `t ⟶ s`. -/ abbrev mk (desc : ∀ s, t ⟶ s) (w : ∀ s τ, τ = desc s) : IsKan t := .ofUniqueHom desc w /-- The family of 2-morphisms out of a left Kan lift. -/ abbrev desc (H : IsKan t) (s : LeftLift f g) : t.lift ⟶ s.lift := StructuredArrow.IsUniversal.desc H s @[reassoc (attr := simp)] theorem fac (H : IsKan t) (s : LeftLift f g) : t.unit ≫ H.desc s ▷ f = s.unit := StructuredArrow.IsUniversal.fac H s /-- Two 2-morphisms out of a left Kan lift are equal if their compositions with each triangle 2-morphism are equal. -/ theorem hom_ext (H : IsKan t) {k : c ⟶ b} {τ τ' : t.lift ⟶ k} (w : t.unit ≫ τ ▷ f = t.unit ≫ τ' ▷ f) : τ = τ' := StructuredArrow.IsUniversal.hom_ext H w /-- Kan lifts on `g` along `f` are unique up to isomorphism. -/ def uniqueUpToIso (P : IsKan s) (Q : IsKan t) : s ≅ t := Limits.IsInitial.uniqueUpToIso P Q @[simp] theorem uniqueUpToIso_hom_right (P : IsKan s) (Q : IsKan t) : (uniqueUpToIso P Q).hom.right = P.desc t := rfl @[simp] theorem uniqueUpToIso_inv_right (P : IsKan s) (Q : IsKan t) : (uniqueUpToIso P Q).inv.right = Q.desc s := rfl /-- Transport evidence that a left lift is a Kan lift across an isomorphism of lifts. -/ def ofIsoKan (P : IsKan s) (i : s ≅ t) : IsKan t := Limits.IsInitial.ofIso P i /-- If `t : LeftLift f (𝟙 c ≫ g)` is a Kan lift, then `t.ofIdComp : LeftLift f g` is also a Kan lift. -/ def ofIdComp (t : LeftLift f (𝟙 c ≫ g)) (P : IsKan t) : IsKan t.ofIdComp := .mk (fun s ↦ t.whiskerIdCancel <| P.to (s.whisker (𝟙 c))) <| by intro s τ ext apply P.hom_ext simp [← LeftLift.w τ] /-- If `s ≅ t` and `IsKan (s.whisker h)`, then `IsKan (t.whisker h)`. -/ def whiskerOfCommute (s t : LeftLift f g) (i : s ≅ t) {x : B} (h : x ⟶ c) (P : IsKan (s.whisker h)) : IsKan (t.whisker h) := P.ofIsoKan <| whiskerIso i h end IsKan namespace IsAbsKan variable {s t : LeftLift f g} /-- The family of 2-morphisms out of an absolute left Kan lift. -/ abbrev desc (H : IsAbsKan t) {x : B} {h : x ⟶ c} (s : LeftLift f (h ≫ g)) : h ≫ t.lift ⟶ s.lift := (H h).desc s /-- An absolute left Kan lift is a left Kan lift. -/ def isKan (H : IsAbsKan t) : IsKan t := ((H (𝟙 c)).ofIdComp _).ofIsoKan <| whiskerOfIdCompIsoSelf t /-- Transport evidence that a left lift is a Kan lift across an isomorphism of lifts. -/ def ofIsoAbsKan (P : IsAbsKan s) (i : s ≅ t) : IsAbsKan t := fun h ↦ (P h).ofIsoKan (whiskerIso i h) end IsAbsKan end LeftLift namespace RightExtension variable {f : a ⟶ b} {g : a ⟶ c} /-- A right Kan extension of `g` along `f` is a terminal object in `RightExtension f g`. -/ abbrev IsKan (t : RightExtension f g) := t.IsUniversal end RightExtension namespace RightLift variable {f : b ⟶ a} {g : c ⟶ a} /-- A right Kan lift of `g` along `f` is a terminal object in `RightLift f g`. -/ abbrev IsKan (t : RightLift f g) := t.IsUniversal end RightLift end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Kan/Adjunction.lean
import Mathlib.CategoryTheory.Bicategory.Kan.HasKan import Mathlib.CategoryTheory.Bicategory.Adjunction.Basic import Mathlib.Tactic.TFAE /-! # Adjunctions as Kan extensions We show that adjunctions are realized as Kan extensions or Kan lifts. We also show that a left adjoint commutes with a left Kan extension. Under the assumption that `IsLeftAdjoint h`, the isomorphism `f⁺ (g ≫ h) ≅ f⁺ g ≫ h` can be accessed by `Lan.CommuteWith.lanCompIso f g h`. ## References * [Riehl, *Category theory in context*, Proposition 6.5.2][riehl2017] ## TODO At the moment, the results are stated for left Kan extensions and left Kan lifts. We can prove the similar results for right Kan extensions and right Kan lifts. -/ namespace CategoryTheory namespace Bicategory universe w v u variable {B : Type u} [Bicategory.{w, v} B] {a b c : B} section LeftExtension open LeftExtension /-- For an adjunction `f ⊣ u`, `u` is an absolute left Kan extension of the identity along `f`. The unit of this Kan extension is given by the unit of the adjunction. -/ def Adjunction.isAbsoluteLeftKan {f : a ⟶ b} {u : b ⟶ a} (adj : f ⊣ u) : IsAbsKan (.mk u adj.unit) := fun {x} h ↦ .mk (fun s ↦ LeftExtension.homMk (𝟙 _ ⊗≫ u ◁ s.unit ⊗≫ adj.counit ▷ s.extension ⊗≫ 𝟙 _ : u ≫ h ⟶ s.extension) <| calc _ _ = 𝟙 _ ⊗≫ (adj.unit ▷ _ ≫ _ ◁ s.unit) ⊗≫ f ◁ adj.counit ▷ s.extension ⊗≫ 𝟙 _ := by dsimp only [whisker_extension, StructuredArrow.mk_right, whisker_unit, StructuredArrow.mk_hom_eq_self] bicategory _ = 𝟙 _ ⊗≫ s.unit ⊗≫ leftZigzag adj.unit adj.counit ▷ s.extension ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; bicategory _ = s.unit := by rw [adj.left_triangle]; bicategory) <| by intro s τ₀ ext /- We need to specify the type of `τ` to use the notation `⊗≫`. -/ let τ : u ≫ h ⟶ s.extension := τ₀.right have hτ : adj.unit ▷ h ⊗≫ f ◁ τ = s.unit := by simpa [bicategoricalComp] using LeftExtension.w τ₀ calc τ _ = 𝟙 _ ⊗≫ rightZigzag adj.unit adj.counit ▷ h ⊗≫ τ ⊗≫ 𝟙 _ := by rw [adj.right_triangle]; bicategory _ = 𝟙 _ ⊗≫ u ◁ adj.unit ▷ h ⊗≫ (adj.counit ▷ _ ≫ _ ◁ τ) ⊗≫ 𝟙 _ := by rw [rightZigzag]; bicategory _ = 𝟙 _ ⊗≫ u ◁ (adj.unit ▷ h ⊗≫ f ◁ τ) ⊗≫ adj.counit ▷ s.extension ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; bicategory _ = _ := by rw [hτ]; dsimp only [StructuredArrow.homMk_right] /-- A left Kan extension of the identity along `f` such that `f` commutes with is a right adjoint to `f`. The unit of this adjoint is given by the unit of the Kan extension. -/ def LeftExtension.IsKan.adjunction {f : a ⟶ b} {t : LeftExtension f (𝟙 a)} (H : IsKan t) (H' : IsKan (t.whisker f)) : f ⊣ t.extension := let ε : t.extension ≫ f ⟶ 𝟙 b := H'.desc <| .mk _ <| (λ_ f).hom ≫ (ρ_ f).inv have Hε : leftZigzag t.unit ε = (λ_ f).hom ≫ (ρ_ f).inv := by simpa [leftZigzag, bicategoricalComp] using H'.fac <| .mk _ <| (λ_ f).hom ≫ (ρ_ f).inv { unit := t.unit counit := ε left_triangle := Hε right_triangle := by apply (cancel_epi (ρ_ _).inv).mp apply H.hom_ext calc _ _ = 𝟙 _ ⊗≫ t.unit ⊗≫ f ◁ rightZigzag t.unit ε ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 _ ⊗≫ (t.unit ▷ _ ≫ _ ◁ t.unit) ⊗≫ f ◁ ε ▷ t.extension ⊗≫ 𝟙 _ := by rw [rightZigzag]; bicategory _ = 𝟙 _ ⊗≫ t.unit ⊗≫ (t.unit ▷ f ⊗≫ f ◁ ε) ▷ t.extension ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; bicategory _ = _ := by rw [← leftZigzag, Hε]; bicategory } /-- For an adjunction `f ⊣ u`, `u` is a left Kan extension of the identity along `f`. The unit of this Kan extension is given by the unit of the adjunction. -/ def LeftExtension.IsAbsKan.adjunction {f : a ⟶ b} (t : LeftExtension f (𝟙 a)) (H : IsAbsKan t) : f ⊣ t.extension := H.isKan.adjunction (H f) theorem isLeftAdjoint_TFAE (f : a ⟶ b) : List.TFAE [ IsLeftAdjoint f, HasAbsLeftKanExtension f (𝟙 a), ∃ _ : HasLeftKanExtension f (𝟙 a), Lan.CommuteWith f (𝟙 a) f] := by tfae_have 1 → 2 | h => IsAbsKan.hasAbsLeftKanExtension (Adjunction.ofIsLeftAdjoint f).isAbsoluteLeftKan tfae_have 2 → 3 | h => ⟨inferInstance, inferInstance⟩ tfae_have 3 → 1 | ⟨h, h'⟩ => .mk <| (lanIsKan f (𝟙 a)).adjunction <| Lan.CommuteWith.isKan f (𝟙 a) f tfae_finish end LeftExtension section LeftLift open LeftLift /-- For an adjunction `f ⊣ u`, `f` is an absolute left Kan lift of the identity along `u`. The unit of this Kan lift is given by the unit of the adjunction. -/ def Adjunction.isAbsoluteLeftKanLift {f : a ⟶ b} {u : b ⟶ a} (adj : f ⊣ u) : IsAbsKan (.mk f adj.unit) := fun {x} h ↦ .mk (fun s ↦ LeftLift.homMk (𝟙 _ ⊗≫ s.unit ▷ f ⊗≫ s.lift ◁ adj.counit ⊗≫ 𝟙 _ : h ≫ f ⟶ s.lift) <| calc _ _ = 𝟙 _ ⊗≫ (_ ◁ adj.unit ≫ s.unit ▷ _) ⊗≫ s.lift ◁ adj.counit ▷ u ⊗≫ 𝟙 _ := by dsimp only [whisker_lift, StructuredArrow.mk_right, whisker_unit, StructuredArrow.mk_hom_eq_self] bicategory _ = s.unit ⊗≫ s.lift ◁ (rightZigzag adj.unit adj.counit) ⊗≫ 𝟙 _ := by rw [whisker_exchange, rightZigzag]; bicategory _ = s.unit := by rw [adj.right_triangle]; bicategory) <| by intro s τ₀ ext /- We need to specify the type of `τ` to use the notation `⊗≫`. -/ let τ : h ≫ f ⟶ s.lift := τ₀.right have hτ : h ◁ adj.unit ⊗≫ τ ▷ u = s.unit := by simpa [bicategoricalComp] using LeftLift.w τ₀ calc τ _ = 𝟙 _ ⊗≫ h ◁ leftZigzag adj.unit adj.counit ⊗≫ τ ⊗≫ 𝟙 _ := by rw [adj.left_triangle]; bicategory _ = 𝟙 _ ⊗≫ h ◁ adj.unit ▷ f ⊗≫ (_ ◁ adj.counit ≫ τ ▷ _) ⊗≫ 𝟙 _ := by rw [leftZigzag]; bicategory _ = 𝟙 _ ⊗≫ (h ◁ adj.unit ⊗≫ τ ▷ u) ▷ f ⊗≫ s.lift ◁ adj.counit ⊗≫ 𝟙 _ := by rw [whisker_exchange]; bicategory _ = _ := by rw [hτ]; dsimp only [StructuredArrow.homMk_right] /-- A left Kan lift of the identity along `u` such that `u` commutes with is a left adjoint to `u`. The unit of this adjoint is given by the unit of the Kan lift. -/ def LeftLift.IsKan.adjunction {u : b ⟶ a} {t : LeftLift u (𝟙 a)} (H : IsKan t) (H' : IsKan (t.whisker u)) : t.lift ⊣ u := let ε : u ≫ t.lift ⟶ 𝟙 b := H'.desc <| .mk _ <| (ρ_ u).hom ≫ (λ_ u).inv have Hε : rightZigzag t.unit ε = (ρ_ u).hom ≫ (λ_ u).inv := by simpa [rightZigzag, bicategoricalComp] using H'.fac <| .mk _ <| (ρ_ u).hom ≫ (λ_ u).inv { unit := t.unit counit := ε left_triangle := by apply (cancel_epi (λ_ _).inv).mp apply H.hom_ext calc _ _ = 𝟙 _ ⊗≫ t.unit ⊗≫ leftZigzag t.unit ε ▷ u ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 _ ⊗≫ (_ ◁ t.unit ≫ t.unit ▷ _) ⊗≫ t.lift ◁ ε ▷ u ⊗≫ 𝟙 _ := by rw [leftZigzag]; bicategory _ = 𝟙 _ ⊗≫ t.unit ⊗≫ t.lift ◁ (u ◁ t.unit ⊗≫ ε ▷ u) ⊗≫ 𝟙 _ := by rw [whisker_exchange]; bicategory _ = _ := by rw [← rightZigzag, Hε]; bicategory right_triangle := Hε } /-- For an adjunction `f ⊣ u`, `f` is a left Kan lift of the identity along `u`. The unit of this Kan lift is given by the unit of the adjunction. -/ def LeftLift.IsAbsKan.adjunction {u : b ⟶ a} (t : LeftLift u (𝟙 a)) (H : IsAbsKan t) : t.lift ⊣ u := H.isKan.adjunction (H u) theorem isRightAdjoint_TFAE (u : b ⟶ a) : List.TFAE [ IsRightAdjoint u, HasAbsLeftKanLift u (𝟙 a), ∃ _ : HasLeftKanLift u (𝟙 a), LanLift.CommuteWith u (𝟙 a) u] := by tfae_have 1 → 2 | h => IsAbsKan.hasAbsLeftKanLift (Adjunction.ofIsRightAdjoint u).isAbsoluteLeftKanLift tfae_have 2 → 3 | h => ⟨inferInstance, inferInstance⟩ tfae_have 3 → 1 | ⟨h, h'⟩ => .mk <| (lanLiftIsKan u (𝟙 a)).adjunction <| LanLift.CommuteWith.isKan u (𝟙 a) u tfae_finish end LeftLift namespace LeftExtension /-- A left adjoint commutes with a left Kan extension. -/ def isKanOfWhiskerLeftAdjoint {f : a ⟶ b} {g : a ⟶ c} {t : LeftExtension f g} (H : LeftExtension.IsKan t) {x : B} {h : c ⟶ x} {u : x ⟶ c} (adj : h ⊣ u) : LeftExtension.IsKan (t.whisker h) := let η' := adj.unit let H' : LeftLift.IsAbsKan (.mk _ η') := adj.isAbsoluteLeftKanLift .mk (fun s ↦ let k := s.extension let θ := s.unit let sτ := LeftExtension.mk _ <| 𝟙 _ ⊗≫ g ◁ η' ⊗≫ θ ▷ u ⊗≫ 𝟙 _ let τ : t.extension ⟶ k ≫ u := H.desc sτ let sσ := LeftLift.mk _ <| (ρ_ _).hom ≫ τ let σ : t.extension ≫ h ⟶ k := H'.desc sσ LeftExtension.homMk σ <| (H' g).hom_ext <| by have Hσ : t.extension ◁ η' ⊗≫ σ ▷ u = 𝟙 _ ⊗≫ τ := by simpa [bicategoricalComp] using (H' _).fac (.mk _ <| (ρ_ _).hom ≫ τ) dsimp only [LeftLift.whisker_lift, StructuredArrow.mk_right, LeftLift.whisker_unit, StructuredArrow.mk_hom_eq_self, whisker_extension, whisker_unit] calc _ _ = (g ◁ η' ≫ t.unit ▷ (h ≫ u)) ⊗≫ f ◁ σ ▷ u ⊗≫ 𝟙 _ := by bicategory _ = t.unit ▷ (𝟙 c) ⊗≫ f ◁ (t.extension ◁ η' ⊗≫ σ ▷ u) ⊗≫ 𝟙 _ := by rw [whisker_exchange]; bicategory _ = (ρ_ g).hom ≫ t.unit ≫ f ◁ H.desc sτ ≫ (α_ f s.extension u).inv := by rw [Hσ] dsimp only [τ] bicategory _ = _ := by rw [IsKan.fac_assoc] dsimp only [StructuredArrow.mk_right, StructuredArrow.mk_hom_eq_self, sτ] bicategory) <| by intro s' τ₀' let τ' : t.extension ≫ h ⟶ s'.extension := τ₀'.right have Hτ' : t.unit ▷ h ⊗≫ f ◁ τ' = s'.unit := by simpa [bicategoricalComp] using τ₀'.w.symm ext apply (H' _).hom_ext dsimp only [StructuredArrow.homMk_right] rw [(H' _).fac] apply (cancel_epi (ρ_ _).inv).mp apply H.hom_ext dsimp only [LeftLift.whisker_lift, StructuredArrow.mk_right, LeftLift.whisker_unit, StructuredArrow.mk_hom_eq_self] let σs' := LeftExtension.mk (s'.extension ≫ u) (𝟙 g ⊗≫ g ◁ η' ⊗≫ s'.unit ▷ u ⊗≫ 𝟙 (f ≫ s'.extension ≫ u)) calc _ _ = 𝟙 _ ⊗≫ (t.unit ▷ (𝟙 c) ≫ (f ≫ t.extension) ◁ η') ⊗≫ f ◁ τ' ▷ u := by bicategory _ = 𝟙 g ⊗≫ g ◁ η' ⊗≫ (t.unit ▷ h ⊗≫ f ◁ τ') ▷ u ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; bicategory _ = t.unit ≫ f ◁ H.desc σs' := by rw [Hτ', IsKan.fac] dsimp only [StructuredArrow.mk_hom_eq_self, σs'] _ = _ := by bicategory instance {f : a ⟶ b} {g : a ⟶ c} {x : B} {h : c ⟶ x} [IsLeftAdjoint h] [HasLeftKanExtension f g] : Lan.CommuteWith f g h := ⟨⟨isKanOfWhiskerLeftAdjoint (lanIsKan f g) (Adjunction.ofIsLeftAdjoint h)⟩⟩ end LeftExtension end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Kan/HasKan.lean
import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Bicategory.Kan.IsKan /-! # Existence of Kan extensions and Kan lifts in bicategories We provide the propositional typeclass `HasLeftKanExtension f g`, which asserts that there exists a left Kan extension of `g` along `f`. See `CategoryTheory.Bicategory.Kan.IsKan` for the definition of left Kan extensions. Under the assumption that `HasLeftKanExtension f g`, we define the left Kan extension `lan f g` by using the axiom of choice. ## Main definitions * `lan f g` is the left Kan extension of `g` along `f`, and is denoted by `f⁺ g`. * `lanLift f g` is the left Kan lift of `g` along `f`, and is denoted by `f₊ g`. These notations are inspired by [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006]. ## TODO * `ran f g` is the right Kan extension of `g` along `f`, and is denoted by `f⁺⁺ g`. * `ranLift f g` is the right Kan lift of `g` along `f`, and is denoted by `f₊₊ g`. -/ noncomputable section namespace CategoryTheory namespace Bicategory universe w v u variable {B : Type u} [Bicategory.{w, v} B] {a b c : B} open Limits section LeftKan open LeftExtension variable {f : a ⟶ b} {g : a ⟶ c} /-- The existence of a left Kan extension of `g` along `f`. -/ class HasLeftKanExtension (f : a ⟶ b) (g : a ⟶ c) : Prop where hasInitial : HasInitial <| LeftExtension f g theorem LeftExtension.IsKan.hasLeftKanExtension {t : LeftExtension f g} (H : IsKan t) : HasLeftKanExtension f g := ⟨IsInitial.hasInitial H⟩ instance [HasLeftKanExtension f g] : HasInitial <| LeftExtension f g := HasLeftKanExtension.hasInitial /-- The left Kan extension of `g` along `f` at the level of structured arrows. -/ def lanLeftExtension (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] : LeftExtension f g := ⊥_ (LeftExtension f g) /-- The left Kan extension of `g` along `f`. -/ def lan (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] : b ⟶ c := (lanLeftExtension f g).extension /-- `f⁺ g` is the left Kan extension of `g` along `f`. ``` b △ \ | \ f⁺ g f | \ | ◿ a - - - ▷ c g ``` -/ scoped infixr:90 "⁺ " => lan @[simp] theorem lanLeftExtension_extension (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] : (lanLeftExtension f g).extension = f⁺ g := rfl /-- The unit for the left Kan extension `f⁺ g`. -/ def lanUnit (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] : g ⟶ f ≫ f⁺ g := (lanLeftExtension f g).unit @[simp] theorem lanLeftExtension_unit (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] : (lanLeftExtension f g).unit = lanUnit f g := rfl /-- Evidence that the `Lan.extension f g` is a Kan extension. -/ def lanIsKan (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] : (lanLeftExtension f g).IsKan := initialIsInitial variable {f : a ⟶ b} {g : a ⟶ c} /-- The family of 2-morphisms out of the left Kan extension `f⁺ g`. -/ def lanDesc [HasLeftKanExtension f g] (s : LeftExtension f g) : f⁺ g ⟶ s.extension := (lanIsKan f g).desc s @[reassoc (attr := simp)] theorem lanUnit_desc [HasLeftKanExtension f g] (s : LeftExtension f g) : lanUnit f g ≫ f ◁ lanDesc s = s.unit := (lanIsKan f g).fac s @[simp] theorem lanIsKan_desc [HasLeftKanExtension f g] (s : LeftExtension f g) : (lanIsKan f g).desc s = lanDesc s := rfl theorem Lan.existsUnique [HasLeftKanExtension f g] (s : LeftExtension f g) : ∃! τ, lanUnit f g ≫ f ◁ τ = s.unit := (lanIsKan f g).existsUnique _ /-- We say that a 1-morphism `h` commutes with the left Kan extension `f⁺ g` if the whiskered left extension for `f⁺ g` by `h` is a Kan extension of `g ≫ h` along `f`. -/ class Lan.CommuteWith (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] {x : B} (h : c ⟶ x) : Prop where commute : Nonempty <| IsKan <| (lanLeftExtension f g).whisker h namespace Lan.CommuteWith theorem of_isKan_whisker [HasLeftKanExtension f g] (t : LeftExtension f g) {x : B} (h : c ⟶ x) (H : IsKan (t.whisker h)) (i : t.whisker h ≅ (lanLeftExtension f g).whisker h) : Lan.CommuteWith f g h := ⟨⟨IsKan.ofIsoKan H i⟩⟩ theorem of_lan_comp_iso [HasLeftKanExtension f g] {x : B} {h : c ⟶ x} [HasLeftKanExtension f (g ≫ h)] (i : f⁺ (g ≫ h) ≅ f⁺ g ≫ h) (w : lanUnit f (g ≫ h) ≫ f ◁ i.hom = lanUnit f g ▷ h ≫ (α_ _ _ _).hom) : Lan.CommuteWith f g h := ⟨⟨(lanIsKan f (g ≫ h)).ofIsoKan <| StructuredArrow.isoMk i⟩⟩ variable (f : a ⟶ b) (g : a ⟶ c) [HasLeftKanExtension f g] variable {x : B} (h : c ⟶ x) [Lan.CommuteWith f g h] /-- Evidence that `h` commutes with the left Kan extension `f⁺ g`. -/ def isKan : IsKan <| (lanLeftExtension f g).whisker h := Classical.choice Lan.CommuteWith.commute instance : HasLeftKanExtension f (g ≫ h) := (Lan.CommuteWith.isKan f g h).hasLeftKanExtension /-- If `h` commutes with `f⁺ g` and `t` is another left Kan extension of `g` along `f`, then `t.whisker h` is a left Kan extension of `g ≫ h` along `f`. -/ def isKanWhisker (t : LeftExtension f g) (H : IsKan t) {x : B} (h : c ⟶ x) [Lan.CommuteWith f g h] : IsKan (t.whisker h) := IsKan.whiskerOfCommute (lanLeftExtension f g) t (IsKan.uniqueUpToIso (lanIsKan f g) H) h (isKan f g h) /-- The isomorphism `f⁺ (g ≫ h) ≅ f⁺ g ≫ h` at the level of structured arrows. -/ def lanCompIsoWhisker : lanLeftExtension f (g ≫ h) ≅ (lanLeftExtension f g).whisker h := IsKan.uniqueUpToIso (lanIsKan f (g ≫ h)) (Lan.CommuteWith.isKan f g h) @[simp] theorem lanCompIsoWhisker_hom_right : (lanCompIsoWhisker f g h).hom.right = lanDesc ((lanLeftExtension f g).whisker h) := rfl @[simp] theorem lanCompIsoWhisker_inv_right : (lanCompIsoWhisker f g h).inv.right = (isKan f g h).desc (lanLeftExtension f (g ≫ h)) := rfl /-- The 1-morphism `h` commutes with the left Kan extension `f⁺ g`. -/ @[simps!] def lanCompIso : f⁺ (g ≫ h) ≅ f⁺ g ≫ h := Comma.rightIso <| lanCompIsoWhisker f g h end Lan.CommuteWith /-- We say that there exists an absolute left Kan extension of `g` along `f` if any 1-morphism `h` commutes with the left Kan extension `f⁺ g`. -/ class HasAbsLeftKanExtension (f : a ⟶ b) (g : a ⟶ c) : Prop extends HasLeftKanExtension f g where commute {x : B} (h : c ⟶ x) : Lan.CommuteWith f g h instance [HasAbsLeftKanExtension f g] {x : B} (h : c ⟶ x) : Lan.CommuteWith f g h := HasAbsLeftKanExtension.commute h theorem LeftExtension.IsAbsKan.hasAbsLeftKanExtension {t : LeftExtension f g} (H : IsAbsKan t) : HasAbsLeftKanExtension f g := have : HasLeftKanExtension f g := H.isKan.hasLeftKanExtension ⟨fun h ↦ ⟨⟨H.ofIsoAbsKan (IsKan.uniqueUpToIso H.isKan (lanIsKan f g)) h⟩⟩⟩ end LeftKan section LeftLift open LeftLift variable {f : b ⟶ a} {g : c ⟶ a} /-- The existence of a left kan lift of `g` along `f`. -/ class HasLeftKanLift (f : b ⟶ a) (g : c ⟶ a) : Prop where mk' :: hasInitial : HasInitial <| LeftLift f g theorem LeftLift.IsKan.hasLeftKanLift {t : LeftLift f g} (H : IsKan t) : HasLeftKanLift f g := ⟨IsInitial.hasInitial H⟩ instance [HasLeftKanLift f g] : HasInitial <| LeftLift f g := HasLeftKanLift.hasInitial /-- The left Kan lift of `g` along `f` at the level of structured arrows. -/ def lanLiftLeftLift (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] : LeftLift f g := ⊥_ (LeftLift f g) /-- The left Kan lift of `g` along `f`. -/ def lanLift (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] : c ⟶ b := (lanLiftLeftLift f g).lift /-- `f₊ g` is the left Kan lift of `g` along `f`. ``` b ◹ | f₊ g / | / | f / ▽ c - - - ▷ a g ``` -/ scoped infixr:90 "₊ " => lanLift @[simp] theorem lanLiftLeftLift_lift (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] : (lanLiftLeftLift f g).lift = f₊ g := rfl /-- The unit for the left Kan lift `f₊ g`. -/ def lanLiftUnit (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] : g ⟶ f₊ g ≫ f := (lanLiftLeftLift f g).unit @[simp] theorem lanLiftLeftLift_unit (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] : (lanLiftLeftLift f g).unit = lanLiftUnit f g := rfl /-- Evidence that the `LanLift.lift f g` is a Kan lift. -/ def lanLiftIsKan (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] : (lanLiftLeftLift f g).IsKan := initialIsInitial variable {f : b ⟶ a} {g : c ⟶ a} /-- The family of 2-morphisms out of the left Kan lift `f₊ g`. -/ def lanLiftDesc [HasLeftKanLift f g] (s : LeftLift f g) : f ₊ g ⟶ s.lift := (lanLiftIsKan f g).desc s @[reassoc (attr := simp)] theorem lanLiftUnit_desc [HasLeftKanLift f g] (s : LeftLift f g) : lanLiftUnit f g ≫ lanLiftDesc s ▷ f = s.unit := (lanLiftIsKan f g).fac s @[simp] theorem lanLiftIsKan_desc [HasLeftKanLift f g] (s : LeftLift f g) : (lanLiftIsKan f g).desc s = lanLiftDesc s := rfl theorem LanLift.existsUnique [HasLeftKanLift f g] (s : LeftLift f g) : ∃! τ, lanLiftUnit f g ≫ τ ▷ f = s.unit := (lanLiftIsKan f g).existsUnique _ /-- We say that a 1-morphism `h` commutes with the left Kan lift `f₊ g` if the whiskered left lift for `f₊ g` by `h` is a Kan lift of `h ≫ g` along `f`. -/ class LanLift.CommuteWith (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] {x : B} (h : x ⟶ c) : Prop where commute : Nonempty <| IsKan <| (lanLiftLeftLift f g).whisker h namespace LanLift.CommuteWith theorem of_isKan_whisker [HasLeftKanLift f g] (t : LeftLift f g) {x : B} (h : x ⟶ c) (H : IsKan (t.whisker h)) (i : t.whisker h ≅ (lanLiftLeftLift f g).whisker h) : LanLift.CommuteWith f g h := ⟨⟨IsKan.ofIsoKan H i⟩⟩ theorem of_lanLift_comp_iso [HasLeftKanLift f g] {x : B} {h : x ⟶ c} [HasLeftKanLift f (h ≫ g)] (i : f₊ (h ≫ g) ≅ h ≫ f₊ g) (w : lanLiftUnit f (h ≫ g) ≫ i.hom ▷ f = h ◁ lanLiftUnit f g ≫ (α_ _ _ _).inv) : LanLift.CommuteWith f g h := ⟨⟨(lanLiftIsKan f (h ≫ g)).ofIsoKan <| StructuredArrow.isoMk i⟩⟩ variable (f : b ⟶ a) (g : c ⟶ a) [HasLeftKanLift f g] variable {x : B} (h : x ⟶ c) [LanLift.CommuteWith f g h] /-- Evidence that `h` commutes with the left Kan lift `f₊ g`. -/ def isKan : IsKan <| (lanLiftLeftLift f g).whisker h := Classical.choice LanLift.CommuteWith.commute instance : HasLeftKanLift f (h ≫ g) := (LanLift.CommuteWith.isKan f g h).hasLeftKanLift /-- If `h` commutes with `f₊ g` and `t` is another left Kan lift of `g` along `f`, then `t.whisker h` is a left Kan lift of `h ≫ g` along `f`. -/ def isKanWhisker (t : LeftLift f g) (H : IsKan t) {x : B} (h : x ⟶ c) [LanLift.CommuteWith f g h] : IsKan (t.whisker h) := IsKan.whiskerOfCommute (lanLiftLeftLift f g) t (IsKan.uniqueUpToIso (lanLiftIsKan f g) H) h (isKan f g h) /-- The isomorphism `f₊ (h ≫ g) ≅ h ≫ f₊ g` at the level of structured arrows. -/ def lanLiftCompIsoWhisker : lanLiftLeftLift f (h ≫ g) ≅ (lanLiftLeftLift f g).whisker h := IsKan.uniqueUpToIso (lanLiftIsKan f (h ≫ g)) (LanLift.CommuteWith.isKan f g h) @[simp] theorem lanLiftCompIsoWhisker_hom_right : (lanLiftCompIsoWhisker f g h).hom.right = lanLiftDesc ((lanLiftLeftLift f g).whisker h) := rfl @[simp] theorem lanLiftCompIsoWhisker_inv_right : (lanLiftCompIsoWhisker f g h).inv.right = (isKan f g h).desc (lanLiftLeftLift f (h ≫ g)) := rfl /-- The 1-morphism `h` commutes with the left Kan lift `f₊ g`. -/ @[simps!] def lanLiftCompIso : f₊ (h ≫ g) ≅ h ≫ f₊ g := Comma.rightIso <| lanLiftCompIsoWhisker f g h end LanLift.CommuteWith /-- We say that there exists an absolute left Kan lift of `g` along `f` if any 1-morphism `h` commutes with the left Kan lift `f₊ g`. -/ class HasAbsLeftKanLift (f : b ⟶ a) (g : c ⟶ a) : Prop extends HasLeftKanLift f g where commute : ∀ {x : B} (h : x ⟶ c), LanLift.CommuteWith f g h instance [HasAbsLeftKanLift f g] {x : B} (h : x ⟶ c) : LanLift.CommuteWith f g h := HasAbsLeftKanLift.commute h theorem LeftLift.IsAbsKan.hasAbsLeftKanLift {t : LeftLift f g} (H : IsAbsKan t) : HasAbsLeftKanLift f g := have : HasLeftKanLift f g := H.isKan.hasLeftKanLift ⟨fun h ↦ ⟨⟨H.ofIsoAbsKan (IsKan.uniqueUpToIso H.isKan (lanLiftIsKan f g)) h⟩⟩⟩ end LeftLift end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Strict/Pseudofunctor.lean
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor import Mathlib.CategoryTheory.CommSq /-! # Pseudofunctors from strict bicategory This file provides an API for pseudofunctors `F` from a strict bicategory `B`. In particular, this shall apply to pseudofunctors from locally discrete bicategories. Firstly, we study the compatibilities of the flexible variants `mapId'` and `mapComp'` of `mapId` and `mapComp` with respect to the composition with identities and the associativity. Secondly, given a commutative square `t ≫ r = l ≫ b` in `B`, we construct an isomorphism `F.map t ≫ F.map r ≅ F.map l ≫ F.map b` (see `Pseudofunctor.isoMapOfCommSq`). -/ namespace CategoryTheory universe w₁ w₂ v₁ v₂ u₁ u₂ open Bicategory namespace Pseudofunctor variable {B : Type u₁} {C : Type u₂} [Bicategory.{w₁, v₁} B] [Strict B] [Bicategory.{w₂, v₂} C] (F : B ⥤ᵖ C) lemma mapComp'_comp_id {b₀ b₁ : B} (f : b₀ ⟶ b₁) : F.mapComp' f (𝟙 b₁) f = (ρ_ _).symm ≪≫ whiskerLeftIso _ (F.mapId b₁).symm := by ext rw [mapComp'] dsimp rw [F.mapComp_id_right_hom f, Strict.rightUnitor_eqToIso, eqToIso.hom, ← F.map₂_comp_assoc, eqToHom_trans, eqToHom_refl, PrelaxFunctor.map₂_id, Category.id_comp] @[to_app (attr := reassoc)] lemma mapComp'_comp_id_hom {b₀ b₁ : B} (f : b₀ ⟶ b₁) : (F.mapComp' f (𝟙 b₁) f).hom = (ρ_ _).inv ≫ _ ◁ (F.mapId b₁).inv := by simp [mapComp'_comp_id] @[to_app (attr := reassoc)] lemma mapComp'_comp_id_inv {b₀ b₁ : B} (f : b₀ ⟶ b₁) : (F.mapComp' f (𝟙 b₁) f).inv = _ ◁ (F.mapId b₁).hom ≫ (ρ_ _).hom := by simp [mapComp'_comp_id] lemma mapComp'_id_comp {b₀ b₁ : B} (f : b₀ ⟶ b₁) : F.mapComp' (𝟙 b₀) f f = (λ_ _).symm ≪≫ whiskerRightIso (F.mapId b₀).symm _ := by ext rw [mapComp'] dsimp rw [F.mapComp_id_left_hom f, Strict.leftUnitor_eqToIso, eqToIso.hom, ← F.map₂_comp_assoc, eqToHom_trans, eqToHom_refl, PrelaxFunctor.map₂_id, Category.id_comp] @[to_app (attr := reassoc)] lemma mapComp'_id_comp_hom {b₀ b₁ : B} (f : b₀ ⟶ b₁) : (F.mapComp' (𝟙 b₀) f f).hom = (λ_ _).inv ≫ (F.mapId b₀).inv ▷ _ := by simp [mapComp'_id_comp] @[to_app (attr := reassoc)] lemma mapComp'_id_comp_inv {b₀ b₁ : B} (f : b₀ ⟶ b₁) : (F.mapComp' (𝟙 b₀) f f).inv = (F.mapId b₀).hom ▷ _ ≫ (λ_ _).hom := by simp [mapComp'_id_comp] section associativity variable {b₀ b₁ b₂ b₃ : B} (f₀₁ : b₀ ⟶ b₁) (f₁₂ : b₁ ⟶ b₂) (f₂₃ : b₂ ⟶ b₃) (f₀₂ : b₀ ⟶ b₂) (f₁₃ : b₁ ⟶ b₃) (f : b₀ ⟶ b₃) (h₀₂ : f₀₁ ≫ f₁₂ = f₀₂) (h₁₃ : f₁₂ ≫ f₂₃ = f₁₃) @[to_app (attr := reassoc)] lemma mapComp'₀₁₃_hom_comp_whiskerLeft_mapComp'_hom (hf : f₀₁ ≫ f₁₃ = f) : (F.mapComp' f₀₁ f₁₃ f).hom ≫ F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃).hom = (F.mapComp' f₀₂ f₂₃ f).hom ≫ (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).hom ▷ F.map f₂₃ ≫ (α_ _ _ _).hom := by subst h₀₂ h₁₃ hf simp [mapComp_assoc_right_hom, Strict.associator_eqToIso, mapComp'] @[deprecated (since := "2025-10-02")] alias mapComp'_hom_comp_whiskerLeft_mapComp'_hom := mapComp'₀₁₃_hom_comp_whiskerLeft_mapComp'_hom @[to_app (attr := reassoc)] lemma mapComp'₀₁₃_inv_comp_mapComp'₀₂₃_hom (hf : f₀₁ ≫ f₁₃ = f) : (F.mapComp' f₀₁ f₁₃ f).inv ≫ (F.mapComp' f₀₂ f₂₃ f).hom = F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).hom ≫ (α_ _ _ _).inv ≫ (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).inv ▷ F.map f₂₃ := by rw [← cancel_epi (F.mapComp' f₀₁ f₁₃ f hf).hom, Iso.hom_inv_id_assoc, F.mapComp'₀₁₃_hom_comp_whiskerLeft_mapComp'_hom_assoc _ _ _ _ _ _ h₀₂ h₁₃ hf] simp @[deprecated (since := "2025-10-02")] alias mapComp'_inv_comp_mapComp'_hom := mapComp'₀₁₃_inv_comp_mapComp'₀₂₃_hom @[to_app (attr := reassoc)] lemma whiskerLeft_mapComp'_inv_comp_mapComp'₀₁₃_inv (hf : f₀₁ ≫ f₁₃ = f) : F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).inv ≫ (F.mapComp' f₀₁ f₁₃ f hf).inv = (α_ _ _ _).inv ≫ (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).inv ▷ F.map f₂₃ ≫ (F.mapComp' f₀₂ f₂₃ f).inv := by simp [← cancel_mono (F.mapComp' f₀₂ f₂₃ f).hom, F.mapComp'₀₁₃_inv_comp_mapComp'₀₂₃_hom _ _ _ _ _ _ h₀₂ h₁₃ hf] @[deprecated (since := "2025-10-02")] alias whiskerLeft_mapComp'_inv_comp_mapComp'_inv := whiskerLeft_mapComp'_inv_comp_mapComp'₀₁₃_inv @[to_app (attr := reassoc)] lemma mapComp'₀₂₃_hom_comp_mapComp'_hom_whiskerRight (hf : f₀₂ ≫ f₂₃ = f) : (F.mapComp' f₀₂ f₂₃ f).hom ≫ (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).hom ▷ F.map f₂₃ = (F.mapComp' f₀₁ f₁₃ f).hom ≫ F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).hom ≫ (α_ _ _ _).inv := by rw [F.mapComp'₀₁₃_hom_comp_whiskerLeft_mapComp'_hom_assoc _ _ _ _ _ f h₀₂ h₁₃ (by cat_disch)] simp @[deprecated (since := "2025-10-02")] alias mapComp'_hom_comp_mapComp'_hom_whiskerRight := mapComp'₀₂₃_hom_comp_mapComp'_hom_whiskerRight @[to_app (attr := reassoc)] lemma mapComp'_inv_whiskerRight_mapComp'₀₂₃_inv (hf : f₀₂ ≫ f₂₃ = f) : (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).inv ▷ F.map f₂₃ ≫ (F.mapComp' f₀₂ f₂₃ f).inv = (α_ _ _ _).hom ≫ F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).inv ≫ (F.mapComp' f₀₁ f₁₃ f).inv := by rw [whiskerLeft_mapComp'_inv_comp_mapComp'₀₁₃_inv _ _ _ _ _ _ f h₀₂ h₁₃, Iso.hom_inv_id_assoc] @[deprecated (since := "2025-10-02")] alias mapComp'_inv_whiskerRight_comp_mapComp'_inv := mapComp'_inv_whiskerRight_mapComp'₀₂₃_inv @[to_app (attr := reassoc)] lemma mapComp'₀₁₃_inv (hf : f₀₁ ≫ f₁₃ = f) : (F.mapComp' f₀₁ f₁₃ f).inv = F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).hom ≫ (α_ _ _ _).inv ≫ (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).inv ▷ F.map f₂₃ ≫ (F.mapComp' f₀₂ f₂₃ f).inv := by simp [← whiskerLeft_mapComp'_inv_comp_mapComp'₀₁₃_inv _ _ _ _ _ _ f h₀₂ h₁₃ hf] @[to_app (attr := reassoc)] lemma mapComp'₀₁₃_hom (hf : f₀₁ ≫ f₁₃ = f) : (F.mapComp' f₀₁ f₁₃ f).hom = (F.mapComp' f₀₂ f₂₃ f).hom ≫ (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).hom ▷ F.map f₂₃ ≫ (α_ _ _ _).hom ≫ F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).inv := by rw [← cancel_epi (F.mapComp' f₀₁ f₁₃ f).inv, Iso.inv_hom_id] simp [mapComp'₀₁₃_inv _ _ _ _ _ _ f h₀₂ h₁₃ hf] @[to_app (attr := reassoc)] lemma mapComp'₀₂₃_hom (hf : f₀₂ ≫ f₂₃ = f) : (F.mapComp' f₀₂ f₂₃ f).hom = (F.mapComp' f₀₁ f₁₃ f).hom ≫ F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).hom ≫ (α_ _ _ _).inv ≫ (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).inv ▷ F.map f₂₃:= by simp [← mapComp'₀₂₃_hom_comp_mapComp'_hom_whiskerRight_assoc _ _ _ _ _ _ f h₀₂ h₁₃ hf] @[to_app (attr := reassoc)] lemma mapComp'₀₂₃_inv (hf : f₀₂ ≫ f₂₃ = f) : (F.mapComp' f₀₂ f₂₃ f).inv = (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).hom ▷ F.map f₂₃ ≫ (α_ _ _ _).hom ≫ F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).inv ≫ (F.mapComp' f₀₁ f₁₃ f).inv := by rw [← cancel_epi (F.mapComp' f₀₂ f₂₃ f).hom, Iso.hom_inv_id] simp [mapComp'₀₂₃_hom _ _ _ _ _ _ f h₀₂ h₁₃ hf] @[to_app (attr := reassoc)] lemma mapComp'₀₂₃_inv_comp_mapComp'₀₁₃_hom (hf : f₀₂ ≫ f₂₃ = f) : (F.mapComp' f₀₂ f₂₃ f).inv ≫ (F.mapComp' f₀₁ f₁₃ f).hom = (F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂).hom ▷ F.map f₂₃ ≫ (α_ _ _ _).hom ≫ F.map f₀₁ ◁ (F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃).inv := by simp [mapComp'₀₂₃_inv _ _ _ _ _ _ _ h₀₂ h₁₃ hf] end associativity section CommSq variable {X₁ X₂ Y₁ Y₂ Z₁ Z₂ : B} section variable {t : X₁ ⟶ Y₁} {l : X₁ ⟶ X₂} {r : Y₁ ⟶ Y₂} {b : X₂ ⟶ Y₂} (sq : CommSq t l r b) /-- Given a commutative square `CommSq t l r b` in a strict bicategory `B` and a pseudofunctor from `B`, this is the natural isomorphism `F.map t ≫ F.map r ≅ F.map l ≫ F.map b`. -/ def isoMapOfCommSq : F.map t ≫ F.map r ≅ F.map l ≫ F.map b := (F.mapComp t r).symm ≪≫ F.mapComp' _ _ _ (by rw [sq.w]) lemma isoMapOfCommSq_eq (φ : X₁ ⟶ Y₂) (hφ : t ≫ r = φ) : F.isoMapOfCommSq sq = (F.mapComp' t r φ (by rw [hφ])).symm ≪≫ F.mapComp' l b φ (by rw [← hφ, sq.w]) := by subst hφ simp [isoMapOfCommSq, mapComp'_eq_mapComp] end /-- Equational lemma for `Pseudofunctor.isoMapOfCommSq` when both vertical maps of the square are the same and horizontal maps are identities. -/ lemma isoMapOfCommSq_horiz_id (f : X₁ ⟶ X₂) : F.isoMapOfCommSq (t := 𝟙 _) (l := f) (r := f) (b := 𝟙 _) ⟨by simp⟩ = whiskerRightIso (F.mapId X₁) (F.map f) ≪≫ λ_ _ ≪≫ (ρ_ _).symm ≪≫ (whiskerLeftIso (F.map f) (F.mapId X₂)).symm := by ext rw [isoMapOfCommSq_eq _ _ f (by simp), mapComp'_comp_id, mapComp'_id_comp] simp /-- Equational lemma for `Pseudofunctor.isoMapOfCommSq` when both horizontal maps of the square are the same and vertical maps are identities. -/ lemma isoMapOfCommSq_vert_id (f : X₁ ⟶ X₂) : F.isoMapOfCommSq (t := f) (l := 𝟙 _) (r := 𝟙 _) (b := f) ⟨by simp⟩ = whiskerLeftIso (F.map f) (F.mapId X₂) ≪≫ ρ_ _ ≪≫ (λ_ _).symm ≪≫ (whiskerRightIso (F.mapId X₁) (F.map f)).symm := by ext rw [isoMapOfCommSq_eq _ _ f (by simp), mapComp'_comp_id, mapComp'_id_comp] simp end CommSq end Pseudofunctor namespace LaxFunctor variable {B : Type u₁} {C : Type u₂} [Bicategory.{w₁, v₁} B] [Strict B] [Bicategory.{w₂, v₂} C] (F : B ⥤ᴸ C) section associativity variable {b₀ b₁ b₂ b₃ : B} (f₀₁ : b₀ ⟶ b₁) (f₁₂ : b₁ ⟶ b₂) (f₂₃ : b₂ ⟶ b₃) (f₀₂ : b₀ ⟶ b₂) (f₁₃ : b₁ ⟶ b₃) (f : b₀ ⟶ b₃) (h₀₂ : f₀₁ ≫ f₁₂ = f₀₂) (h₁₃ : f₁₂ ≫ f₂₃ = f₁₃) @[reassoc] lemma whiskerLeft_mapComp'_comp_mapComp' (hf : f₀₁ ≫ f₁₃ = f) : F.map f₀₁ ◁ F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃ ≫ F.mapComp' f₀₁ f₁₃ f hf = (α_ _ _ _).inv ≫ F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂ ▷ F.map f₂₃ ≫ F.mapComp' f₀₂ f₂₃ f := by subst hf h₀₂ h₁₃ have := F.map₂_associator f₀₁ f₁₂ f₂₃ simp only [Strict.associator_eqToIso, eqToIso.hom] at this simp [LaxFunctor.mapComp', this] @[reassoc] lemma mapComp'_whiskerRight_comp_mapComp' (hf : f₀₂ ≫ f₂₃ = f) : F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂ ▷ F.map f₂₃ ≫ F.mapComp' f₀₂ f₂₃ f = (α_ _ _ _).hom ≫ F.map f₀₁ ◁ F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃ ≫ F.mapComp' f₀₁ f₁₃ f := by rw [whiskerLeft_mapComp'_comp_mapComp' _ _ _ _ _ _ f h₀₂ h₁₃, Iso.hom_inv_id_assoc] end associativity end LaxFunctor namespace OplaxFunctor variable {B : Type u₁} {C : Type u₂} [Bicategory.{w₁, v₁} B] [Strict B] [Bicategory.{w₂, v₂} C] (F : B ⥤ᵒᵖᴸ C) section associativity variable {b₀ b₁ b₂ b₃ : B} (f₀₁ : b₀ ⟶ b₁) (f₁₂ : b₁ ⟶ b₂) (f₂₃ : b₂ ⟶ b₃) (f₀₂ : b₀ ⟶ b₂) (f₁₃ : b₁ ⟶ b₃) (f : b₀ ⟶ b₃) (h₀₂ : f₀₁ ≫ f₁₂ = f₀₂) (h₁₃ : f₁₂ ≫ f₂₃ = f₁₃) @[reassoc] lemma mapComp'_comp_whiskerLeft_mapComp' (hf : f₀₁ ≫ f₁₃ = f) : F.mapComp' f₀₁ f₁₃ f ≫ F.map f₀₁ ◁ F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃ = F.mapComp' f₀₂ f₂₃ f ≫ F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂ ▷ F.map f₂₃ ≫ (α_ _ _ _).hom := by subst h₀₂ h₁₃ hf have := F.map₂_associator f₀₁ f₁₂ f₂₃ simp only [Strict.associator_eqToIso, eqToIso.hom] at this simp [OplaxFunctor.mapComp', ← this, PrelaxFunctor.map₂_eqToHom] @[reassoc] lemma mapComp'_comp_mapComp'_whiskerRight (hf : f₀₂ ≫ f₂₃ = f) : F.mapComp' f₀₂ f₂₃ f ≫ F.mapComp' f₀₁ f₁₂ f₀₂ h₀₂ ▷ F.map f₂₃ = F.mapComp' f₀₁ f₁₃ f ≫ F.map f₀₁ ◁ F.mapComp' f₁₂ f₂₃ f₁₃ h₁₃ ≫ (α_ _ _ _).inv := by rw [F.mapComp'_comp_whiskerLeft_mapComp'_assoc _ _ _ _ _ f h₀₂ h₁₃ (by cat_disch)] simp end associativity end OplaxFunctor end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Strict/Basic.lean
import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Bicategory.Basic /-! # Strict bicategories A bicategory is called `Strict` if the left unitors, the right unitors, and the associators are isomorphisms given by equalities. ## Implementation notes In the literature of category theory, a strict bicategory (usually called a strict 2-category) is often defined as a bicategory whose left unitors, right unitors, and associators are identities. We cannot use this definition directly here since the types of 2-morphisms depend on 1-morphisms. For this reason, we use `eqToIso`, which gives isomorphisms from equalities, instead of identities. -/ namespace CategoryTheory open Bicategory universe w v u variable (B : Type u) [Bicategory.{w, v} B] /-- A bicategory is called `Strict` if the left unitors, the right unitors, and the associators are isomorphisms given by equalities. -/ class Bicategory.Strict : Prop where /-- Identity morphisms are left identities for composition. -/ id_comp : ∀ {a b : B} (f : a ⟶ b), 𝟙 a ≫ f = f := by cat_disch /-- Identity morphisms are right identities for composition. -/ comp_id : ∀ {a b : B} (f : a ⟶ b), f ≫ 𝟙 b = f := by cat_disch /-- Composition in a bicategory is associative. -/ assoc : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), (f ≫ g) ≫ h = f ≫ g ≫ h := by cat_disch /-- The left unitors are given by equalities -/ leftUnitor_eqToIso : ∀ {a b : B} (f : a ⟶ b), λ_ f = eqToIso (id_comp f) := by cat_disch /-- The right unitors are given by equalities -/ rightUnitor_eqToIso : ∀ {a b : B} (f : a ⟶ b), ρ_ f = eqToIso (comp_id f) := by cat_disch /-- The associators are given by equalities -/ associator_eqToIso : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), α_ f g h = eqToIso (assoc f g h) := by cat_disch -- see Note [lower instance priority] /-- Category structure on a strict bicategory -/ instance (priority := 100) StrictBicategory.category [Bicategory.Strict B] : Category B where id_comp := Bicategory.Strict.id_comp comp_id := Bicategory.Strict.comp_id assoc := Bicategory.Strict.assoc namespace Bicategory variable {B} @[simp] theorem whiskerLeft_eqToHom {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g = h) : f ◁ eqToHom η = eqToHom (congr_arg₂ (· ≫ ·) rfl η) := by cases η simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {a b c : B} {f g : a ⟶ b} (η : f = g) (h : b ⟶ c) : eqToHom η ▷ h = eqToHom (congr_arg₂ (· ≫ ·) η rfl) := by cases η simp only [id_whiskerRight, eqToHom_refl] end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Monad/Basic.lean
import Mathlib.CategoryTheory.Bicategory.LocallyDiscrete import Mathlib.CategoryTheory.Bicategory.FunctorBicategory.Oplax import Mathlib.CategoryTheory.Bicategory.End import Mathlib.CategoryTheory.Monoidal.Comon_ /-! # Comonads in a bicategory We define comonads in a bicategory `B` as comonoid objects in an endomorphism monoidal category. We show that this is equivalent to oplax functors from the trivial bicategory to `B`. From this, we show that comonads in `B` form a bicategory. ## TODO We can also define monads in a bicategory. This is not yet done as we don't have the bicategory structure on the set of lax functors at this point, which is needed to show that monads form a bicategory. -/ namespace CategoryTheory namespace Bicategory universe w v u variable {B : Type u} [Bicategory.{w, v} B] /-- A comonad in a bicategory `B` is a 1-morphism `t : a ⟶ a` together with 2-morphisms `Δ : t ⟶ t ≫ t` and `ε : t ⟶ 𝟙 a` satisfying the comonad laws. -/ abbrev Comonad {a : B} (t : a ⟶ a) := ComonObj t /-- The counit 2-morphism of the comonad. -/ abbrev Comonad.counit {a : B} {t : a ⟶ a} [Comonad t] : t ⟶ 𝟙 a := ComonObj.counit /-- The comultiplication 2-morphism of the comonad. -/ abbrev Comonad.comul {a : B} {t : a ⟶ a} [Comonad t] : t ⟶ t ≫ t := ComonObj.comul @[inherit_doc] scoped notation "ε" => Comonad.counit @[inherit_doc] scoped notation "ε["x"]" => Comonad.counit (t := x) @[inherit_doc] scoped notation "Δ" => Comonad.comul @[inherit_doc] scoped notation "Δ["x"]" => Comonad.comul (t := x) namespace Comonad variable {a : B} /- Comonad laws -/ section variable (t : a ⟶ a) [Comonad t] @[reassoc (attr := simp)] theorem counit_comul : Δ ≫ ε ▷ t = (λ_ t).inv := ComonObj.counit_comul t @[reassoc (attr := simp)] theorem comul_counit : Δ ≫ t ◁ ε = (ρ_ t).inv := ComonObj.comul_counit t @[reassoc (attr := simp)] theorem comul_assoc : Δ ≫ t ◁ Δ = Δ ≫ Δ ▷ t ≫ (α_ t t t).hom := ComonObj.comul_assoc t @[reassoc] theorem comul_assoc_flip : Δ ≫ Δ ▷ t = Δ ≫ t ◁ Δ ≫ (α_ t t t).inv := ComonObj.comul_assoc_flip t end @[simps! counit] instance {a : B} : Comonad (𝟙 a) := ComonObj.instTensorUnit (a ⟶ a) /-- An oplax functor from the trivial bicategory to `B` defines a comonad in `B`. -/ def ofOplaxFromUnit (F : LocallyDiscrete (Discrete Unit) ⥤ᵒᵖᴸ B) : Comonad (F.map (𝟙 ⟨⟨Unit.unit⟩⟩)) where comul := F.map₂ (ρ_ _).inv ≫ F.mapComp _ _ counit := F.mapId _ comul_assoc := by simp only [tensorObj_def, MonoidalCategory.whiskerLeft_comp, whiskerLeft_def, Category.assoc, MonoidalCategory.comp_whiskerRight, whiskerRight_def, associator_def] rw [← F.mapComp_naturality_left_assoc, ← F.mapComp_naturality_right_assoc] simp only [whiskerLeft_rightUnitor_inv, PrelaxFunctor.map₂_comp, Category.assoc, OplaxFunctor.map₂_associator, whiskerRight_id, Iso.hom_inv_id_assoc] counit_comul := by simp only [tensorUnit_def, tensorObj_def, whiskerRight_def, Category.assoc, leftUnitor_def] rw [F.mapComp_id_left, unitors_equal, F.map₂_inv_hom_assoc] comul_counit := by simp only [tensorUnit_def, tensorObj_def, whiskerLeft_def, rightUnitor_def] rw [Category.assoc, F.mapComp_id_right, F.map₂_inv_hom_assoc] /-- A comonad in `B` defines an oplax functor from the trivial bicategory to `B`. -/ def toOplax {a : B} (t : a ⟶ a) [Comonad t] : LocallyDiscrete (Discrete Unit) ⥤ᵒᵖᴸ B where obj _ := a map _ := t map₂ _ := 𝟙 _ mapId _ := ε mapComp _ _ := Δ map₂_associator _ _ _ := by rw [Category.id_comp] apply Comonad.comul_assoc end Comonad /- In this section, we define bicategory structure on comonads by using the bicategory structure on oplax functors. We may use oplax, lax, or pseudonatural transformations to provide the bicategory structure, and the namespace below indicates that we use oplax transformations here. The constructions for the other two cases would be given in the corresponding namespaces. -/ namespace OplaxTrans /-- The bicategory of comonads in `B`. -/ def ComonadBicat (B : Type u) [Bicategory.{w, v} B] := LocallyDiscrete (Discrete Unit) ⥤ᵒᵖᴸ B namespace ComonadBicat open scoped Oplax.OplaxTrans.OplaxFunctor in /-- The bicategory of comonads in `B`. -/ scoped instance : Bicategory (ComonadBicat B) := inferInstanceAs <| Bicategory (LocallyDiscrete (Discrete PUnit) ⥤ᵒᵖᴸ B) /-- The oplax functor from the trivial bicategory to `B` associated with the comonad. -/ def toOplax (m : ComonadBicat B) : LocallyDiscrete (Discrete PUnit) ⥤ᵒᵖᴸ B := m /-- The object in `B` associated with the comonad. -/ def obj (m : ComonadBicat B) := m.toOplax.obj ⟨⟨PUnit.unit⟩⟩ /-- The morphism in `B` associated with the comonad. -/ def hom (m : ComonadBicat B) : m.obj ⟶ m.obj := m.toOplax.map (𝟙 (⟨⟨PUnit.unit⟩⟩ : LocallyDiscrete (Discrete PUnit))) instance (m : ComonadBicat B) : Comonad m.hom := Comonad.ofOplaxFromUnit <| m.toOplax /-- Construct a comonad as an object in `ComonadBicat B`. -/ def mkOfComonad {a : B} (t : a ⟶ a) [Comonad t] : ComonadBicat B := Comonad.toOplax t open Comonad section variable {a : B} (t : a ⟶ a) [Comonad t] theorem mkOfComonad_hom : (mkOfComonad t).hom = t := rfl theorem mkOfComonad_counit : ε[(mkOfComonad t).hom] = ε[t] := rfl theorem mkOfComonad_comul : Δ[(mkOfComonad t).hom] = Δ[t] := by change 𝟙 t ≫ Δ = Δ apply Category.id_comp end end ComonadBicat end OplaxTrans end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Adjunction/Basic.lean
import Mathlib.Tactic.CategoryTheory.Bicategory.Basic /-! # Adjunctions in bicategories For 1-morphisms `f : a ⟶ b` and `g : b ⟶ a` in a bicategory, an adjunction between `f` and `g` consists of a pair of 2-morphism `η : 𝟙 a ⟶ f ≫ g` and `ε : g ≫ f ⟶ 𝟙 b` satisfying the triangle identities. The 2-morphism `η` is called the unit and `ε` is called the counit. ## Main definitions * `Bicategory.Adjunction`: adjunctions between two 1-morphisms. * `Bicategory.Equivalence`: adjoint equivalences between two objects. * `Bicategory.mkOfAdjointifyCounit`: construct an adjoint equivalence from 2-isomorphisms `η : 𝟙 a ≅ f ≫ g` and `ε : g ≫ f ≅ 𝟙 b`, by upgrading `ε` to a counit. ## TODO * `Bicategory.mkOfAdjointifyUnit`: construct an adjoint equivalence from 2-isomorphisms `η : 𝟙 a ≅ f ≫ g` and `ε : g ≫ f ≅ 𝟙 b`, by upgrading `η` to a unit. -/ namespace CategoryTheory namespace Bicategory open Category open scoped Bicategory universe w v u variable {B : Type u} [Bicategory.{w, v} B] {a b c : B} {f : a ⟶ b} {g : b ⟶ a} /-- The 2-morphism defined by the following pasting diagram: ``` a ------ ▸ a \ η ◥ \ f \ g / \ f ◢ / ε ◢ b ------ ▸ b ``` -/ abbrev leftZigzag (η : 𝟙 a ⟶ f ≫ g) (ε : g ≫ f ⟶ 𝟙 b) := η ▷ f ⊗≫ f ◁ ε /-- The 2-morphism defined by the following pasting diagram: ``` a ------ ▸ a ◥ \ η ◥ g / \ f / g / ε ◢ / b ------ ▸ b ``` -/ abbrev rightZigzag (η : 𝟙 a ⟶ f ≫ g) (ε : g ≫ f ⟶ 𝟙 b) := g ◁ η ⊗≫ ε ▷ g theorem rightZigzag_idempotent_of_left_triangle (η : 𝟙 a ⟶ f ≫ g) (ε : g ≫ f ⟶ 𝟙 b) (h : leftZigzag η ε = (λ_ _).hom ≫ (ρ_ _).inv) : rightZigzag η ε ⊗≫ rightZigzag η ε = rightZigzag η ε := by dsimp only [rightZigzag] calc _ = g ◁ η ⊗≫ ((ε ▷ g ▷ 𝟙 a) ≫ (𝟙 b ≫ g) ◁ η) ⊗≫ ε ▷ g := by bicategory _ = 𝟙 _ ⊗≫ g ◁ (η ▷ 𝟙 a ≫ (f ≫ g) ◁ η) ⊗≫ (ε ▷ (g ≫ f) ≫ 𝟙 b ◁ ε) ▷ g ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; bicategory _ = g ◁ η ⊗≫ g ◁ leftZigzag η ε ▷ g ⊗≫ ε ▷ g := by rw [← whisker_exchange, ← whisker_exchange, leftZigzag]; bicategory _ = g ◁ η ⊗≫ ε ▷ g := by rw [h]; bicategory /-- Adjunction between two 1-morphisms. -/ structure Adjunction (f : a ⟶ b) (g : b ⟶ a) where /-- The unit of an adjunction. -/ unit : 𝟙 a ⟶ f ≫ g /-- The counit of an adjunction. -/ counit : g ≫ f ⟶ 𝟙 b /-- The composition of the unit and the counit is equal to the identity up to unitors. -/ left_triangle : leftZigzag unit counit = (λ_ _).hom ≫ (ρ_ _).inv := by cat_disch /-- The composition of the unit and the counit is equal to the identity up to unitors. -/ right_triangle : rightZigzag unit counit = (ρ_ _).hom ≫ (λ_ _).inv := by cat_disch @[inherit_doc] scoped infixr:15 " ⊣ " => Bicategory.Adjunction namespace Adjunction attribute [simp] left_triangle right_triangle /-- Adjunction between identities. -/ def id (a : B) : 𝟙 a ⊣ 𝟙 a where unit := (ρ_ _).inv counit := (ρ_ _).hom left_triangle := by bicategory_coherence right_triangle := by bicategory_coherence instance : Inhabited (Adjunction (𝟙 a) (𝟙 a)) := ⟨id a⟩ section Composition variable {f₁ : a ⟶ b} {g₁ : b ⟶ a} {f₂ : b ⟶ c} {g₂ : c ⟶ b} /-- Auxiliary definition for `adjunction.comp`. -/ @[simp] def compUnit (adj₁ : f₁ ⊣ g₁) (adj₂ : f₂ ⊣ g₂) : 𝟙 a ⟶ (f₁ ≫ f₂) ≫ g₂ ≫ g₁ := adj₁.unit ⊗≫ f₁ ◁ adj₂.unit ▷ g₁ ⊗≫ 𝟙 _ /-- Auxiliary definition for `adjunction.comp`. -/ @[simp] def compCounit (adj₁ : f₁ ⊣ g₁) (adj₂ : f₂ ⊣ g₂) : (g₂ ≫ g₁) ≫ f₁ ≫ f₂ ⟶ 𝟙 c := 𝟙 _ ⊗≫ g₂ ◁ adj₁.counit ▷ f₂ ⊗≫ adj₂.counit theorem comp_left_triangle_aux (adj₁ : f₁ ⊣ g₁) (adj₂ : f₂ ⊣ g₂) : leftZigzag (compUnit adj₁ adj₂) (compCounit adj₁ adj₂) = (λ_ _).hom ≫ (ρ_ _).inv := by calc _ = 𝟙 _ ⊗≫ adj₁.unit ▷ (f₁ ≫ f₂) ⊗≫ f₁ ◁ (adj₂.unit ▷ (g₁ ≫ f₁) ≫ (f₂ ≫ g₂) ◁ adj₁.counit) ▷ f₂ ⊗≫ (f₁ ≫ f₂) ◁ adj₂.counit ⊗≫ 𝟙 _ := by dsimp only [compUnit, compCounit]; bicategory _ = 𝟙 _ ⊗≫ (leftZigzag adj₁.unit adj₁.counit) ▷ f₂ ⊗≫ f₁ ◁ (leftZigzag adj₂.unit adj₂.counit) ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; bicategory _ = _ := by simp_rw [left_triangle]; bicategory theorem comp_right_triangle_aux (adj₁ : f₁ ⊣ g₁) (adj₂ : f₂ ⊣ g₂) : rightZigzag (compUnit adj₁ adj₂) (compCounit adj₁ adj₂) = (ρ_ _).hom ≫ (λ_ _).inv := by calc _ = 𝟙 _ ⊗≫ (g₂ ≫ g₁) ◁ adj₁.unit ⊗≫ g₂ ◁ ((g₁ ≫ f₁) ◁ adj₂.unit ≫ adj₁.counit ▷ (f₂ ≫ g₂)) ▷ g₁ ⊗≫ adj₂.counit ▷ (g₂ ≫ g₁) ⊗≫ 𝟙 _ := by dsimp only [compUnit, compCounit]; bicategory _ = 𝟙 _ ⊗≫ g₂ ◁ (rightZigzag adj₁.unit adj₁.counit) ⊗≫ (rightZigzag adj₂.unit adj₂.counit) ▷ g₁ ⊗≫ 𝟙 _ := by rw [whisker_exchange]; bicategory _ = _ := by simp_rw [right_triangle]; bicategory /-- Composition of adjunctions. -/ @[simps] def comp (adj₁ : f₁ ⊣ g₁) (adj₂ : f₂ ⊣ g₂) : f₁ ≫ f₂ ⊣ g₂ ≫ g₁ where unit := compUnit adj₁ adj₂ counit := compCounit adj₁ adj₂ left_triangle := by apply comp_left_triangle_aux right_triangle := by apply comp_right_triangle_aux end Composition end Adjunction noncomputable section variable (η : 𝟙 a ≅ f ≫ g) (ε : g ≫ f ≅ 𝟙 b) /-- The isomorphism version of `leftZigzag`. -/ abbrev leftZigzagIso (η : 𝟙 a ≅ f ≫ g) (ε : g ≫ f ≅ 𝟙 b) := whiskerRightIso η f ≪⊗≫ whiskerLeftIso f ε /-- The isomorphism version of `rightZigzag`. -/ abbrev rightZigzagIso (η : 𝟙 a ≅ f ≫ g) (ε : g ≫ f ≅ 𝟙 b) := whiskerLeftIso g η ≪⊗≫ whiskerRightIso ε g @[simp] theorem leftZigzagIso_hom : (leftZigzagIso η ε).hom = leftZigzag η.hom ε.hom := rfl @[simp] theorem rightZigzagIso_hom : (rightZigzagIso η ε).hom = rightZigzag η.hom ε.hom := rfl @[simp] theorem leftZigzagIso_inv : (leftZigzagIso η ε).inv = rightZigzag ε.inv η.inv := by simp [bicategoricalComp, bicategoricalIsoComp] @[simp] theorem rightZigzagIso_inv : (rightZigzagIso η ε).inv = leftZigzag ε.inv η.inv := by simp [bicategoricalComp, bicategoricalIsoComp] @[simp] theorem leftZigzagIso_symm : (leftZigzagIso η ε).symm = rightZigzagIso ε.symm η.symm := Iso.ext (leftZigzagIso_inv η ε) @[simp] theorem rightZigzagIso_symm : (rightZigzagIso η ε).symm = leftZigzagIso ε.symm η.symm := Iso.ext (rightZigzagIso_inv η ε) instance : IsIso (leftZigzag η.hom ε.hom) := inferInstanceAs <| IsIso (leftZigzagIso η ε).hom instance : IsIso (rightZigzag η.hom ε.hom) := inferInstanceAs <| IsIso (rightZigzagIso η ε).hom theorem right_triangle_of_left_triangle (h : leftZigzag η.hom ε.hom = (λ_ f).hom ≫ (ρ_ f).inv) : rightZigzag η.hom ε.hom = (ρ_ g).hom ≫ (λ_ g).inv := by rw [← cancel_epi (rightZigzag η.hom ε.hom ≫ (λ_ g).hom ≫ (ρ_ g).inv)] calc _ = rightZigzag η.hom ε.hom ⊗≫ rightZigzag η.hom ε.hom := by bicategory _ = rightZigzag η.hom ε.hom := rightZigzag_idempotent_of_left_triangle _ _ h _ = _ := by simp /-- An auxiliary definition for `mkOfAdjointifyCounit`. -/ def adjointifyCounit (η : 𝟙 a ≅ f ≫ g) (ε : g ≫ f ≅ 𝟙 b) : g ≫ f ≅ 𝟙 b := whiskerLeftIso g ((ρ_ f).symm ≪≫ rightZigzagIso ε.symm η.symm ≪≫ λ_ f) ≪≫ ε theorem adjointifyCounit_left_triangle (η : 𝟙 a ≅ f ≫ g) (ε : g ≫ f ≅ 𝟙 b) : leftZigzagIso η (adjointifyCounit η ε) = λ_ f ≪≫ (ρ_ f).symm := by apply Iso.ext dsimp [adjointifyCounit, bicategoricalIsoComp] calc _ = 𝟙 _ ⊗≫ (η.hom ▷ (f ≫ 𝟙 b) ≫ (f ≫ g) ◁ f ◁ ε.inv) ⊗≫ f ◁ g ◁ η.inv ▷ f ⊗≫ f ◁ ε.hom := by bicategory _ = 𝟙 _ ⊗≫ f ◁ ε.inv ⊗≫ (η.hom ▷ (f ≫ g) ≫ (f ≫ g) ◁ η.inv) ▷ f ⊗≫ f ◁ ε.hom := by rw [← whisker_exchange η.hom (f ◁ ε.inv)]; bicategory _ = 𝟙 _ ⊗≫ f ◁ ε.inv ⊗≫ (η.inv ≫ η.hom) ▷ f ⊗≫ f ◁ ε.hom := by rw [← whisker_exchange η.hom η.inv]; bicategory _ = 𝟙 _ ⊗≫ f ◁ (ε.inv ≫ ε.hom) := by rw [Iso.inv_hom_id]; bicategory _ = _ := by rw [Iso.inv_hom_id]; bicategory /-- Adjoint equivalences between two objects. -/ structure Equivalence (a b : B) where /-- A 1-morphism in one direction. -/ hom : a ⟶ b /-- A 1-morphism in the other direction. -/ inv : b ⟶ a /-- The composition `hom ≫ inv` is isomorphic to the identity. -/ unit : 𝟙 a ≅ hom ≫ inv /-- The composition `inv ≫ hom` is isomorphic to the identity. -/ counit : inv ≫ hom ≅ 𝟙 b /-- The composition of the unit and the counit is equal to the identity up to unitors. -/ left_triangle : leftZigzagIso unit counit = λ_ hom ≪≫ (ρ_ hom).symm := by cat_disch @[inherit_doc] scoped infixr:10 " ≌ " => Bicategory.Equivalence namespace Equivalence /-- The identity 1-morphism is an equivalence. -/ def id (a : B) : a ≌ a := ⟨_, _, (ρ_ _).symm, ρ_ _, by ext; simp [bicategoricalIsoComp]⟩ instance : Inhabited (Equivalence a a) := ⟨id a⟩ theorem left_triangle_hom (e : a ≌ b) : leftZigzag e.unit.hom e.counit.hom = (λ_ e.hom).hom ≫ (ρ_ e.hom).inv := congrArg Iso.hom e.left_triangle theorem right_triangle (e : a ≌ b) : rightZigzagIso e.unit e.counit = ρ_ e.inv ≪≫ (λ_ e.inv).symm := Iso.ext (right_triangle_of_left_triangle e.unit e.counit e.left_triangle_hom) theorem right_triangle_hom (e : a ≌ b) : rightZigzag e.unit.hom e.counit.hom = (ρ_ e.inv).hom ≫ (λ_ e.inv).inv := congrArg Iso.hom e.right_triangle /-- Construct an adjoint equivalence from 2-isomorphisms by upgrading `ε` to a counit. -/ def mkOfAdjointifyCounit (η : 𝟙 a ≅ f ≫ g) (ε : g ≫ f ≅ 𝟙 b) : a ≌ b where hom := f inv := g unit := η counit := adjointifyCounit η ε left_triangle := adjointifyCounit_left_triangle η ε end Equivalence end noncomputable section /-- A structure giving a chosen right adjoint of a 1-morphism `left`. -/ structure RightAdjoint (left : a ⟶ b) where /-- The right adjoint to `left`. -/ right : b ⟶ a /-- The adjunction between `left` and `right`. -/ adj : left ⊣ right /-- The existence of a right adjoint of `f`. -/ class IsLeftAdjoint (left : a ⟶ b) : Prop where mk' :: nonempty : Nonempty (RightAdjoint left) theorem IsLeftAdjoint.mk (adj : f ⊣ g) : IsLeftAdjoint f := ⟨⟨g, adj⟩⟩ /-- Use the axiom of choice to extract a right adjoint from an `IsLeftAdjoint` instance. -/ def getRightAdjoint (f : a ⟶ b) [IsLeftAdjoint f] : RightAdjoint f := Classical.choice IsLeftAdjoint.nonempty /-- The right adjoint of a 1-morphism. -/ def rightAdjoint (f : a ⟶ b) [IsLeftAdjoint f] : b ⟶ a := (getRightAdjoint f).right /-- Evidence that `f⁺⁺` is a right adjoint of `f`. -/ def Adjunction.ofIsLeftAdjoint (f : a ⟶ b) [IsLeftAdjoint f] : f ⊣ rightAdjoint f := (getRightAdjoint f).adj /-- A structure giving a chosen left adjoint of a 1-morphism `right`. -/ structure LeftAdjoint (right : b ⟶ a) where /-- The left adjoint to `right`. -/ left : a ⟶ b /-- The adjunction between `left` and `right`. -/ adj : left ⊣ right /-- The existence of a left adjoint of `f`. -/ class IsRightAdjoint (right : b ⟶ a) : Prop where mk' :: nonempty : Nonempty (LeftAdjoint right) theorem IsRightAdjoint.mk (adj : f ⊣ g) : IsRightAdjoint g := ⟨⟨f, adj⟩⟩ /-- Use the axiom of choice to extract a left adjoint from an `IsRightAdjoint` instance. -/ def getLeftAdjoint (f : b ⟶ a) [IsRightAdjoint f] : LeftAdjoint f := Classical.choice IsRightAdjoint.nonempty /-- The left adjoint of a 1-morphism. -/ def leftAdjoint (f : b ⟶ a) [IsRightAdjoint f] : a ⟶ b := (getLeftAdjoint f).left /-- Evidence that `f⁺` is a left adjoint of `f`. -/ def Adjunction.ofIsRightAdjoint (f : b ⟶ a) [IsRightAdjoint f] : leftAdjoint f ⊣ f := (getLeftAdjoint f).adj end end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Adjunction/Mate.lean
import Mathlib.CategoryTheory.Bicategory.Adjunction.Basic import Mathlib.CategoryTheory.HomCongr /-! # Mates in bicategories This file establishes the bijection between the 2-cells ``` l₁ r₁ c --→ d c ←-- d g ↓ ↗ ↓ h g ↓ ↘ ↓ h e --→ f e ←-- f l₂ r₂ ``` where `l₁ ⊣ r₁` and `l₂ ⊣ r₂`. The corresponding natural transformations are called mates. For the bicategory `Cat`, the definitions in this file are provided in `Mathlib/CategoryTheory/Adjunction/Mates.lean`, where you can find more detailed documentation about mates. ## Implementation The correspondence between mates is obtained by combining bijections of the form `(g ⟶ l ≫ h) ≃ (r ≫ g ⟶ h)` and `(g ≫ l ⟶ h) ≃ (g ⟶ h ≫ r)` when `l ⊣ r` is an adjunction. Indeed, `g ≫ l₂ ⟶ l₁ ≫ h` identifies to `g ⟶ (l₁ ≫ h) ≫ r₂` by using the second bijection applied to `l₂ ⊣ r₂`, and this identifies to `r₁ ≫ g ⟶ h ≫ r₂` by using the first bijection applied to `l₁ ⊣ r₁`. ## Remarks To be precise, the definitions in `Mathlib/CategoryTheory/Adjunction/Mates.lean` are universe polymorphic, so they are not simple specializations of the definitions in this file. -/ universe w v u namespace CategoryTheory namespace Bicategory open Bicategory variable {B : Type u} [Bicategory.{w, v} B] namespace Adjunction variable {a b c d : B} {l : b ⟶ c} {r : c ⟶ b} (adj : l ⊣ r) /-- The bijection `(g ⟶ l ≫ h) ≃ (r ≫ g ⟶ h)` induced by an adjunction `l ⊣ r` in a bicategory. -/ @[simps -isSimp] def homEquiv₁ {g : b ⟶ d} {h : c ⟶ d} : (g ⟶ l ≫ h) ≃ (r ≫ g ⟶ h) where toFun γ := r ◁ γ ≫ (α_ _ _ _).inv ≫ adj.counit ▷ h ≫ (λ_ _).hom invFun β := (λ_ _).inv ≫ adj.unit ▷ _ ≫ (α_ _ _ _).hom ≫ l ◁ β left_inv γ := calc _ = 𝟙 _ ⊗≫ (adj.unit ▷ g ≫ (l ≫ r) ◁ γ) ⊗≫ l ◁ adj.counit ▷ h ⊗≫ 𝟙 _:= by bicategory _ = γ ⊗≫ leftZigzag adj.unit adj.counit ▷ h ⊗≫ 𝟙 _ := by rw [← whisker_exchange] bicategory _ = γ := by rw [adj.left_triangle] bicategory right_inv β := by calc _ = 𝟙 _ ⊗≫ r ◁ adj.unit ▷ g ⊗≫ ((r ≫ l) ◁ β ≫ adj.counit ▷ h) ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 _ ⊗≫ rightZigzag adj.unit adj.counit ▷ g ⊗≫ β := by rw [whisker_exchange] bicategory _ = β := by rw [adj.right_triangle] bicategory /-- The bijection `(g ≫ l ⟶ h) ≃ (g ⟶ h ≫ r)` induced by an adjunction `l ⊣ r` in a bicategory. -/ @[simps -isSimp] def homEquiv₂ {g : a ⟶ b} {h : a ⟶ c} : (g ≫ l ⟶ h) ≃ (g ⟶ h ≫ r) where toFun α := (ρ_ _).inv ≫ g ◁ adj.unit ≫ (α_ _ _ _).inv ≫ α ▷ r invFun γ := γ ▷ l ≫ (α_ _ _ _ ).hom ≫ h ◁ adj.counit ≫ (ρ_ _).hom left_inv α := calc _ = 𝟙 _ ⊗≫ g ◁ adj.unit ▷ l ⊗≫ (α ▷ (r ≫ l) ≫ h ◁ adj.counit) ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 _ ⊗≫ g ◁ leftZigzag adj.unit adj.counit ⊗≫ α := by rw [← whisker_exchange] bicategory _ = α := by rw [adj.left_triangle] bicategory right_inv γ := calc _ = 𝟙 _ ⊗≫ (g ◁ adj.unit ≫ γ ▷ (l ≫ r)) ⊗≫ h ◁ adj.counit ▷ r ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 _ ⊗≫ γ ⊗≫ h ◁ rightZigzag adj.unit adj.counit ⊗≫ 𝟙 _ := by rw [whisker_exchange] bicategory _ = γ := by rw [adj.right_triangle] bicategory end Adjunction section mateEquiv section variable {c d e f : B} {g : c ⟶ e} {h : d ⟶ f} {l₁ : c ⟶ d} {r₁ : d ⟶ c} {l₂ : e ⟶ f} {r₂ : f ⟶ e} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) /-- Suppose we have a square of 1-morphisms (where the top and bottom are adjunctions `l₁ ⊣ r₁` and `l₂ ⊣ r₂` respectively). ``` c ↔ d g ↓ ↓ h e ↔ f ``` Then we have a bijection between natural transformations `g ≫ l₂ ⟶ l₁ ≫ h` and `r₁ ≫ g ⟶ h ≫ r₂`. This can be seen as a bijection of the 2-cells: ``` l₁ r₁ c --→ d c ←-- d g ↓ ↗ ↓ h g ↓ ↘ ↓ h e --→ f e ←-- f L₂ R₂ ``` Note that if one of the transformations is an iso, it does not imply the other is an iso. -/ @[simps! -isSimp] def mateEquiv : (g ≫ l₂ ⟶ l₁ ≫ h) ≃ (r₁ ≫ g ⟶ h ≫ r₂) := adj₂.homEquiv₂.trans ((Iso.homCongr (Iso.refl _) (α_ _ _ _)).trans adj₁.homEquiv₁) lemma mateEquiv_eq_iff (α : g ≫ l₂ ⟶ l₁ ≫ h) (β : r₁ ≫ g ⟶ h ≫ r₂) : mateEquiv adj₁ adj₂ α = β ↔ adj₁.homEquiv₁.symm β = adj₂.homEquiv₂ α ≫ (α_ _ _ _).hom := by conv_lhs => rw [eq_comm, ← adj₁.homEquiv₁.symm.injective.eq_iff'] rw [mateEquiv_apply, Equiv.symm_apply_apply] lemma mateEquiv_apply' (α : g ≫ l₂ ⟶ l₁ ≫ h) : mateEquiv adj₁ adj₂ α = 𝟙 _ ⊗≫ r₁ ◁ g ◁ adj₂.unit ⊗≫ r₁ ◁ α ▷ r₂ ⊗≫ adj₁.counit ▷ h ▷ r₂ ⊗≫ 𝟙 _ := by rw [mateEquiv_apply, Adjunction.homEquiv₂_apply, Adjunction.homEquiv₁_apply] bicategory lemma mateEquiv_symm_apply' (β : r₁ ≫ g ⟶ h ≫ r₂) : (mateEquiv adj₁ adj₂).symm β = 𝟙 _ ⊗≫ adj₁.unit ▷ g ▷ l₂ ⊗≫ l₁ ◁ β ▷ l₂ ⊗≫ l₁ ◁ h ◁ adj₂.counit ⊗≫ 𝟙 _ := by rw [mateEquiv_symm_apply, Adjunction.homEquiv₂_symm_apply, Adjunction.homEquiv₁_symm_apply] bicategory end section variable {a b c d : B} {l₁ : a ⟶ b} {r₁ : b ⟶ a} (adj₁ : l₁ ⊣ r₁) {l₂ : c ⟶ d} {r₂ : d ⟶ c} (adj₂ : l₂ ⊣ r₂) {f : a ⟶ c} {g : b ⟶ d} lemma mateEquiv_id_comp_right (φ : f ≫ 𝟙 _ ≫ l₂ ⟶ l₁ ≫ g) : mateEquiv adj₁ ((Adjunction.id _).comp adj₂) φ = mateEquiv adj₁ adj₂ (f ◁ (λ_ l₂).inv ≫ φ) ≫ (ρ_ _).inv ≫ (α_ _ _ _).hom := by simp only [mateEquiv_apply, Adjunction.homEquiv₁_apply, Adjunction.homEquiv₂_apply, Adjunction.id] dsimp bicategory lemma mateEquiv_comp_id_right (φ : f ≫ l₂ ≫ 𝟙 d ⟶ l₁ ≫ g) : mateEquiv adj₁ (adj₂.comp (Adjunction.id _)) φ = mateEquiv adj₁ adj₂ ((ρ_ _).inv ≫ (α_ _ _ _).hom ≫ φ) ≫ g ◁ (λ_ r₂).inv := by simp only [mateEquiv_apply, Adjunction.homEquiv₁_apply, Adjunction.homEquiv₂_apply, Adjunction.id] dsimp bicategory end end mateEquiv section mateEquivVComp variable {a b c d e f : B} {g₁ : a ⟶ c} {g₂ : c ⟶ e} {h₁ : b ⟶ d} {h₂ : d ⟶ f} variable {l₁ : a ⟶ b} {r₁ : b ⟶ a} {l₂ : c ⟶ d} {r₂ : d ⟶ c} {l₃ : e ⟶ f} {r₃ : f ⟶ e} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) (adj₃ : l₃ ⊣ r₃) /-- Squares between left adjoints can be composed "vertically" by pasting. -/ def leftAdjointSquare.vcomp (α : g₁ ≫ l₂ ⟶ l₁ ≫ h₁) (β : g₂ ≫ l₃ ⟶ l₂ ≫ h₂) : (g₁ ≫ g₂) ≫ l₃ ⟶ l₁ ≫ (h₁ ≫ h₂) := (α_ _ _ _).hom ≫ g₁ ◁ β ≫ (α_ _ _ _).inv ≫ α ▷ h₂ ≫ (α_ _ _ _).hom /-- Squares between right adjoints can be composed "vertically" by pasting. -/ def rightAdjointSquare.vcomp (α : r₁ ≫ g₁ ⟶ h₁ ≫ r₂) (β : r₂ ≫ g₂ ⟶ h₂ ≫ r₃) : r₁ ≫ (g₁ ≫ g₂) ⟶ (h₁ ≫ h₂) ≫ r₃ := (α_ _ _ _).inv ≫ α ▷ g₂ ≫ (α_ _ _ _).hom ≫ h₁ ◁ β ≫ (α_ _ _ _).inv /-- The mates equivalence commutes with vertical composition. -/ theorem mateEquiv_vcomp (α : g₁ ≫ l₂ ⟶ l₁ ≫ h₁) (β : g₂ ≫ l₃ ⟶ l₂ ≫ h₂) : mateEquiv adj₁ adj₃ (leftAdjointSquare.vcomp α β) = rightAdjointSquare.vcomp (mateEquiv adj₁ adj₂ α) (mateEquiv adj₂ adj₃ β) := by simp only [leftAdjointSquare.vcomp, mateEquiv_apply', rightAdjointSquare.vcomp] symm calc _ = 𝟙 _ ⊗≫ r₁ ◁ g₁ ◁ adj₂.unit ▷ g₂ ⊗≫ r₁ ◁ α ▷ r₂ ▷ g₂ ⊗≫ ((adj₁.counit ▷ (h₁ ≫ r₂ ≫ g₂ ≫ 𝟙 e)) ≫ 𝟙 b ◁ (h₁ ◁ r₂ ◁ g₂ ◁ adj₃.unit)) ⊗≫ h₁ ◁ r₂ ◁ β ▷ r₃ ⊗≫ h₁ ◁ adj₂.counit ▷ h₂ ▷ r₃ ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 _ ⊗≫ r₁ ◁ g₁ ◁ adj₂.unit ▷ g₂ ⊗≫ (r₁ ◁ (α ▷ (r₂ ≫ g₂ ≫ 𝟙 e) ≫ (l₁ ≫ h₁) ◁ r₂ ◁ g₂ ◁ adj₃.unit)) ⊗≫ ((adj₁.counit ▷ (h₁ ≫ r₂) ▷ (g₂ ≫ l₃) ≫ (𝟙 b ≫ h₁ ≫ r₂) ◁ β) ▷ r₃) ⊗≫ h₁ ◁ adj₂.counit ▷ h₂ ▷ r₃ ⊗≫ 𝟙 _ := by rw [← whisker_exchange] bicategory _ = 𝟙 _ ⊗≫ r₁ ◁ g₁ ◁ (adj₂.unit ▷ (g₂ ≫ 𝟙 e) ≫ (l₂ ≫ r₂) ◁ g₂ ◁ adj₃.unit) ⊗≫ (r₁ ◁ (α ▷ (r₂ ≫ g₂ ≫ l₃) ≫ (l₁ ≫ h₁) ◁ r₂ ◁ β) ▷ r₃) ⊗≫ (adj₁.counit ▷ h₁ ▷ (r₂ ≫ l₂) ≫ (𝟙 b ≫ h₁) ◁ adj₂.counit) ▷ h₂ ▷ r₃ ⊗≫ 𝟙 _ := by rw [← whisker_exchange, ← whisker_exchange] bicategory _ = 𝟙 _ ⊗≫ r₁ ◁ g₁ ◁ g₂ ◁ adj₃.unit ⊗≫ r₁ ◁ g₁ ◁ (adj₂.unit ▷ (g₂ ≫ l₃) ≫ (l₂ ≫ r₂) ◁ β) ▷ r₃ ⊗≫ r₁ ◁ (α ▷ (r₂ ≫ l₂) ≫ (l₁ ≫ h₁) ◁ adj₂.counit) ▷ h₂ ▷ r₃ ⊗≫ adj₁.counit ▷ h₁ ▷ h₂ ▷ r₃ ⊗≫ 𝟙 _ := by rw [← whisker_exchange, ← whisker_exchange, ← whisker_exchange] bicategory _ = 𝟙 _ ⊗≫ r₁ ◁ g₁ ◁ g₂ ◁ adj₃.unit ⊗≫ r₁ ◁ g₁ ◁ β ▷ r₃ ⊗≫ ((r₁ ≫ g₁) ◁ leftZigzag adj₂.unit adj₂.counit ▷ (h₂ ≫ r₃)) ⊗≫ r₁ ◁ α ▷ h₂ ▷ r₃ ⊗≫ adj₁.counit ▷ h₁ ▷ h₂ ▷ r₃ ⊗≫ 𝟙 _ := by rw [← whisker_exchange, ← whisker_exchange] bicategory _ = _ := by rw [adj₂.left_triangle] bicategory end mateEquivVComp section mateEquivHComp variable {a : B} {b : B} {c : B} {d : B} {e : B} {f : B} variable {g : a ⟶ d} {h : b ⟶ e} {k : c ⟶ f} variable {l₁ : a ⟶ b} {r₁ : b ⟶ a} {l₂ : d ⟶ e} {r₂ : e ⟶ d} variable {l₃ : b ⟶ c} {r₃ : c ⟶ b} {l₄ : e ⟶ f} {r₄ : f ⟶ e} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) (adj₃ : l₃ ⊣ r₃) (adj₄ : l₄ ⊣ r₄) /-- Squares between left adjoints can be composed "horizontally" by pasting. -/ def leftAdjointSquare.hcomp (α : g ≫ l₂ ⟶ l₁ ≫ h) (β : h ≫ l₄ ⟶ l₃ ≫ k) : g ≫ (l₂ ≫ l₄) ⟶ (l₁ ≫ l₃) ≫ k := (α_ _ _ _).inv ≫ α ▷ l₄ ≫ (α_ _ _ _).hom ≫ l₁ ◁ β ≫ (α_ _ _ _).inv /-- Squares between right adjoints can be composed "horizontally" by pasting. -/ def rightAdjointSquare.hcomp (α : r₁ ≫ g ⟶ h ≫ r₂) (β : r₃ ≫ h ⟶ k ≫ r₄) : (r₃ ≫ r₁) ≫ g ⟶ k ≫ (r₄ ≫ r₂) := (α_ _ _ _).hom ≫ r₃ ◁ α ≫ (α_ _ _ _).inv ≫ β ▷ r₂ ≫ (α_ _ _ _).hom /-- The mates equivalence commutes with horizontal composition of squares. -/ theorem mateEquiv_hcomp (α : g ≫ l₂ ⟶ l₁ ≫ h) (β : h ≫ l₄ ⟶ l₃ ≫ k) : (mateEquiv (adj₁.comp adj₃) (adj₂.comp adj₄)) (leftAdjointSquare.hcomp α β) = rightAdjointSquare.hcomp (mateEquiv adj₁ adj₂ α) (mateEquiv adj₃ adj₄ β) := by simp only [mateEquiv_apply'] dsimp [leftAdjointSquare.hcomp, rightAdjointSquare.hcomp] calc _ = 𝟙 _ ⊗≫ r₃ ◁ r₁ ◁ g ◁ adj₂.unit ⊗≫ r₃ ◁ r₁ ◁ ((g ≫ l₂) ◁ adj₄.unit ≫ α ▷ (l₄ ≫ r₄)) ▷ r₂ ⊗≫ r₃ ◁ ((r₁ ≫ l₁) ◁ β ≫ adj₁.counit ▷ (l₃ ≫ k)) ▷ r₄ ▷ r₂ ⊗≫ adj₃.counit ▷ k ▷ r₄ ▷ r₂ ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 _ ⊗≫ r₃ ◁ r₁ ◁ g ◁ adj₂.unit ⊗≫ r₃ ◁ r₁ ◁ α ▷ r₂ ⊗≫ r₃ ◁ ((r₁ ≫ l₁) ◁ h ◁ adj₄.unit ≫ adj₁.counit ▷ (h ≫ l₄ ≫ r₄)) ▷ r₂ ⊗≫ r₃ ◁ β ▷ r₄ ▷ r₂ ⊗≫ adj₃.counit ▷ k ▷ r₄ ▷ r₂ ⊗≫ 𝟙 _ := by rw [whisker_exchange, whisker_exchange] bicategory _ = _ := by rw [whisker_exchange] bicategory end mateEquivHComp section mateEquivSquareComp variable {a b c d e f x y z : B} variable {g₁ : a ⟶ d} {h₁ : b ⟶ e} {k₁ : c ⟶ f} {g₂ : d ⟶ x} {h₂ : e ⟶ y} {k₂ : f ⟶ z} variable {l₁ : a ⟶ b} {r₁ : b ⟶ a} {l₂ : b ⟶ c} {r₂ : c ⟶ b} {l₃ : d ⟶ e} {r₃ : e ⟶ d} variable {l₄ : e ⟶ f} {r₄ : f ⟶ e} {l₅ : x ⟶ y} {r₅ : y ⟶ x} {l₆ : y ⟶ z} {r₆ : z ⟶ y} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) (adj₃ : l₃ ⊣ r₃) variable (adj₄ : l₄ ⊣ r₄) (adj₅ : l₅ ⊣ r₅) (adj₆ : l₆ ⊣ r₆) section leftAdjointSquare.comp variable (α : g₁ ≫ l₃ ⟶ l₁ ≫ h₁) (β : h₁ ≫ l₄ ⟶ l₂ ≫ k₁) variable (γ : g₂ ≫ l₅ ⟶ l₃ ≫ h₂) (δ : h₂ ≫ l₆ ⟶ l₄ ≫ k₂) /-- Squares of squares between left adjoints can be composed by iterating vertical and horizontal composition. -/ def leftAdjointSquare.comp : ((g₁ ≫ g₂) ≫ (l₅ ≫ l₆)) ⟶ ((l₁ ≫ l₂) ≫ (k₁ ≫ k₂)) := vcomp (hcomp α β) (hcomp γ δ) theorem leftAdjointSquare.comp_vhcomp : comp α β γ δ = vcomp (hcomp α β) (hcomp γ δ) := rfl /-- Horizontal and vertical composition of squares commutes. -/ theorem leftAdjointSquare.comp_hvcomp : comp α β γ δ = hcomp (vcomp α γ) (vcomp β δ) := by dsimp only [comp, vcomp, hcomp] calc _ = 𝟙 _ ⊗≫ g₁ ◁ γ ▷ l₆ ⊗≫ ((g₁ ≫ l₃) ◁ δ ≫ α ▷ (l₄ ≫ k₂)) ⊗≫ l₁ ◁ β ▷ k₂ ⊗≫ 𝟙 _ := by bicategory _ = _ := by rw [whisker_exchange] bicategory end leftAdjointSquare.comp section rightAdjointSquare.comp variable (α : r₁ ≫ g₁ ⟶ h₁ ≫ r₃) (β : r₂ ≫ h₁ ⟶ k₁ ≫ r₄) variable (γ : r₃ ≫ g₂ ⟶ h₂ ≫ r₅) (δ : r₄ ≫ h₂ ⟶ k₂ ≫ r₆) /-- Squares of squares between right adjoints can be composed by iterating vertical and horizontal composition. -/ def rightAdjointSquare.comp : ((r₂ ≫ r₁) ≫ (g₁ ≫ g₂) ⟶ (k₁ ≫ k₂) ≫ (r₆ ≫ r₅)) := vcomp (hcomp α β) (hcomp γ δ) theorem rightAdjointSquare.comp_vhcomp : comp α β γ δ = vcomp (hcomp α β) (hcomp γ δ) := rfl /-- Horizontal and vertical composition of squares commutes. -/ theorem rightAdjointSquare.comp_hvcomp : comp α β γ δ = hcomp (vcomp α γ) (vcomp β δ) := by dsimp only [comp, vcomp, hcomp] calc _ = 𝟙 _ ⊗≫ r₂ ◁ α ▷ g₂ ⊗≫ (β ▷ (r₃ ≫ g₂) ≫ (k₁ ≫ r₄) ◁ γ) ⊗≫ k₁ ◁ δ ▷ r₅ ⊗≫ 𝟙 _ := by bicategory _ = _ := by rw [← whisker_exchange] bicategory end rightAdjointSquare.comp /-- The mates equivalence commutes with composition of squares of squares. These results form the basis for an isomorphism of double categories to be proven later. -/ theorem mateEquiv_square (α : g₁ ≫ l₃ ⟶ l₁ ≫ h₁) (β : h₁ ≫ l₄ ⟶ l₂ ≫ k₁) (γ : g₂ ≫ l₅ ⟶ l₃ ≫ h₂) (δ : h₂ ≫ l₆ ⟶ l₄ ≫ k₂) : (mateEquiv (adj₁.comp adj₂) (adj₅.comp adj₆)) (leftAdjointSquare.comp α β γ δ) = rightAdjointSquare.comp (mateEquiv adj₁ adj₃ α) (mateEquiv adj₂ adj₄ β) (mateEquiv adj₃ adj₅ γ) (mateEquiv adj₄ adj₆ δ) := by have vcomp := mateEquiv_vcomp (adj₁.comp adj₂) (adj₃.comp adj₄) (adj₅.comp adj₆) (leftAdjointSquare.hcomp α β) (leftAdjointSquare.hcomp γ δ) have hcomp1 := mateEquiv_hcomp adj₁ adj₃ adj₂ adj₄ α β have hcomp2 := mateEquiv_hcomp adj₃ adj₅ adj₄ adj₆ γ δ rw [hcomp1, hcomp2] at vcomp exact vcomp end mateEquivSquareComp section conjugateEquiv section variable {c d : B} variable {l₁ l₂ : c ⟶ d} {r₁ r₂ : d ⟶ c} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) /-- Given two adjunctions `l₁ ⊣ r₁` and `l₂ ⊣ r₂` both between objects `c`, `d`, there is a bijection between 2-morphisms `l₂ ⟶ l₁` and 2-morphisms `r₁ ⟶ r₂`. This is defined as a special case of `mateEquiv`, where the two "vertical" 1-morphisms are identities. Corresponding 2-morphisms are called `conjugateEquiv`. Furthermore, this bijection preserves (and reflects) isomorphisms, i.e. a 2-morphism is an iso iff its image under the bijection is an iso. -/ def conjugateEquiv : (l₂ ⟶ l₁) ≃ (r₁ ⟶ r₂) := calc (l₂ ⟶ l₁) ≃ _ := (Iso.homCongr (λ_ l₂) (ρ_ l₁)).symm _ ≃ _ := mateEquiv adj₁ adj₂ _ ≃ (r₁ ⟶ r₂) := Iso.homCongr (ρ_ r₁) (λ_ r₂) theorem conjugateEquiv_apply (α : l₂ ⟶ l₁) : conjugateEquiv adj₁ adj₂ α = (ρ_ r₁).inv ≫ mateEquiv adj₁ adj₂ ((λ_ l₂).hom ≫ α ≫ (ρ_ l₁).inv) ≫ (λ_ r₂).hom := rfl theorem conjugateEquiv_apply' (α : l₂ ⟶ l₁) : conjugateEquiv adj₁ adj₂ α = (ρ_ _).inv ≫ r₁ ◁ adj₂.unit ≫ r₁ ◁ α ▷ r₂ ≫ (α_ _ _ _).inv ≫ adj₁.counit ▷ r₂ ≫ (λ_ _).hom := by rw [conjugateEquiv_apply, mateEquiv_apply'] bicategory theorem conjugateEquiv_symm_apply (α : r₁ ⟶ r₂) : (conjugateEquiv adj₁ adj₂).symm α = (λ_ l₂).inv ≫ (mateEquiv adj₁ adj₂).symm ((ρ_ r₁).hom ≫ α ≫ (λ_ r₂).inv) ≫ (ρ_ l₁).hom := rfl theorem conjugateEquiv_symm_apply' (α : r₁ ⟶ r₂) : (conjugateEquiv adj₁ adj₂).symm α = (λ_ _).inv ≫ adj₁.unit ▷ l₂ ≫ (α_ _ _ _).hom ≫ l₁ ◁ α ▷ l₂ ≫ l₁ ◁ adj₂.counit ≫ (ρ_ _).hom := by rw [conjugateEquiv_symm_apply, mateEquiv_symm_apply'] bicategory @[simp] theorem conjugateEquiv_id : conjugateEquiv adj₁ adj₁ (𝟙 _) = 𝟙 _ := by rw [conjugateEquiv_apply, mateEquiv_apply'] calc _ = 𝟙 _ ⊗≫ rightZigzag adj₁.unit adj₁.counit ⊗≫ 𝟙 _ := by bicategory _ = 𝟙 r₁ := by rw [adj₁.right_triangle] bicategory @[simp] theorem conjugateEquiv_symm_id : (conjugateEquiv adj₁ adj₁).symm (𝟙 _) = 𝟙 _ := by rw [Equiv.symm_apply_eq, conjugateEquiv_id] theorem conjugateEquiv_adjunction_id {l r : c ⟶ c} (adj : l ⊣ r) (α : 𝟙 c ⟶ l) : (conjugateEquiv adj (Adjunction.id c) α) = (ρ_ _).inv ≫ r ◁ α ≫ adj.counit := by rw [conjugateEquiv_apply, mateEquiv_apply'] dsimp [Adjunction.id] bicategory theorem conjugateEquiv_adjunction_id_symm {l r : c ⟶ c} (adj : l ⊣ r) (α : r ⟶ 𝟙 c) : (conjugateEquiv adj (Adjunction.id c)).symm α = adj.unit ≫ l ◁ α ≫ (ρ_ _).hom := by rw [conjugateEquiv_symm_apply, mateEquiv_symm_apply'] dsimp [Adjunction.id] bicategory end @[simp] lemma mateEquiv_leftUnitor_hom_rightUnitor_inv {a b : B} {l : a ⟶ b} {r : b ⟶ a} (adj : l ⊣ r) : mateEquiv adj adj ((λ_ _).hom ≫ (ρ_ _).inv) = (ρ_ _).hom ≫ (λ_ _).inv := by simp [← cancel_mono (λ_ r).hom, ← conjugateEquiv_id adj, conjugateEquiv_apply] section variable {a b : B} {l : a ⟶ b} {r : b ⟶ a} (adj : l ⊣ r) {l' : a ⟶ b} {r' : b ⟶ a} (adj' : l' ⊣ r') (φ : l' ⟶ l) lemma conjugateEquiv_id_comp_right_apply : conjugateEquiv adj ((Adjunction.id _).comp adj') ((λ_ _).hom ≫ φ) = conjugateEquiv adj adj' φ ≫ (ρ_ _).inv := by simp only [conjugateEquiv_apply, mateEquiv_id_comp_right, id_whiskerLeft, Category.assoc, Iso.inv_hom_id_assoc] bicategory lemma conjugateEquiv_comp_id_right_apply : conjugateEquiv adj (adj'.comp (Adjunction.id _)) ((ρ_ _).hom ≫ φ) = conjugateEquiv adj adj' φ ≫ (λ_ _).inv := by simp only [conjugateEquiv_apply, Category.assoc, mateEquiv_comp_id_right, id_whiskerLeft, Iso.inv_hom_id, Category.comp_id, Iso.hom_inv_id, Iso.cancel_iso_inv_left, EmbeddingLike.apply_eq_iff_eq] bicategory end lemma conjugateEquiv_whiskerLeft {a b c : B} {l₁ : a ⟶ b} {r₁ : b ⟶ a} (adj₁ : l₁ ⊣ r₁) {l₂ : b ⟶ c} {r₂ : c ⟶ b} (adj₂ : l₂ ⊣ r₂) {l₂' : b ⟶ c} {r₂' : c ⟶ b} (adj₂' : l₂' ⊣ r₂') (φ : l₂' ⟶ l₂) : conjugateEquiv (adj₁.comp adj₂) (adj₁.comp adj₂') (l₁ ◁ φ) = conjugateEquiv adj₂ adj₂' φ ▷ r₁ := by have := mateEquiv_hcomp adj₁ adj₁ adj₂ adj₂' ((λ_ _).hom ≫ (ρ_ _).inv) ((λ_ _).hom ≫ φ ≫ (ρ_ _).inv) dsimp [leftAdjointSquare.hcomp, rightAdjointSquare.hcomp] at this simp only [comp_whiskerRight, leftUnitor_whiskerRight, Category.assoc, whiskerLeft_comp, whiskerLeft_rightUnitor_inv, Iso.hom_inv_id, Category.comp_id, triangle_assoc, inv_hom_whiskerRight_assoc, Iso.inv_hom_id_assoc, mateEquiv_leftUnitor_hom_rightUnitor_inv, whiskerLeft_rightUnitor, triangle_assoc_comp_left_inv_assoc, Iso.hom_inv_id_assoc] at this simp [conjugateEquiv_apply, this] lemma conjugateEquiv_whiskerRight {a b c : B} {l₁ : a ⟶ b} {r₁ : b ⟶ a} (adj₁ : l₁ ⊣ r₁) {l₁' : a ⟶ b} {r₁' : b ⟶ a} (adj₁' : l₁' ⊣ r₁') {l₂ : b ⟶ c} {r₂ : c ⟶ b} (adj₂ : l₂ ⊣ r₂) (φ : l₁' ⟶ l₁) : conjugateEquiv (adj₁.comp adj₂) (adj₁'.comp adj₂) (φ ▷ l₂) = r₂ ◁ conjugateEquiv adj₁ adj₁' φ := by have := mateEquiv_hcomp adj₁ adj₁' adj₂ adj₂ ((λ_ _).hom ≫ φ ≫ (ρ_ _).inv) ((λ_ _).hom ≫ (ρ_ _).inv) dsimp [leftAdjointSquare.hcomp, rightAdjointSquare.hcomp] at this simp only [comp_whiskerRight, leftUnitor_whiskerRight, Category.assoc, whiskerLeft_comp, whiskerLeft_rightUnitor_inv, Iso.hom_inv_id, Category.comp_id, triangle_assoc, inv_hom_whiskerRight_assoc, Iso.inv_hom_id_assoc, mateEquiv_leftUnitor_hom_rightUnitor_inv, leftUnitor_inv_whiskerRight, Iso.inv_hom_id, triangle_assoc_comp_right_assoc] at this simp [conjugateEquiv_apply, this] lemma conjugateEquiv_associator_hom {a b c d : B} {l₁ : a ⟶ b} {r₁ : b ⟶ a} (adj₁ : l₁ ⊣ r₁) {l₂ : b ⟶ c} {r₂ : c ⟶ b} (adj₂ : l₂ ⊣ r₂) {l₃ : c ⟶ d} {r₃ : d ⟶ c} (adj₃ : l₃ ⊣ r₃) : conjugateEquiv (adj₁.comp (adj₂.comp adj₃)) ((adj₁.comp adj₂).comp adj₃) (α_ _ _ _).hom = (α_ _ _ _).hom := by simp [← cancel_epi (ρ_ ((r₃ ≫ r₂) ≫ r₁)).hom, ← cancel_mono (λ_ (r₃ ≫ r₂ ≫ r₁)).inv, conjugateEquiv_apply, mateEquiv_eq_iff, Adjunction.homEquiv₁_symm_apply, Adjunction.homEquiv₂_apply] bicategory end conjugateEquiv section ConjugateComposition variable {c d : B} variable {l₁ l₂ l₃ : c ⟶ d} {r₁ r₂ r₃ : d ⟶ c} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) (adj₃ : l₃ ⊣ r₃) @[simp] theorem conjugateEquiv_comp (α : l₂ ⟶ l₁) (β : l₃ ⟶ l₂) : conjugateEquiv adj₁ adj₂ α ≫ conjugateEquiv adj₂ adj₃ β = conjugateEquiv adj₁ adj₃ (β ≫ α) := by simp only [conjugateEquiv_apply] calc _ = 𝟙 r₁ ⊗≫ rightAdjointSquare.vcomp (mateEquiv adj₁ adj₂ ((λ_ _).hom ≫ α ≫ (ρ_ _).inv)) (mateEquiv adj₂ adj₃ ((λ_ _).hom ≫ β ≫ (ρ_ _).inv)) ⊗≫ 𝟙 r₃ := by dsimp only [rightAdjointSquare.vcomp] bicategory _ = _ := by rw [← mateEquiv_vcomp] simp only [leftAdjointSquare.vcomp, mateEquiv_apply'] bicategory @[simp] theorem conjugateEquiv_symm_comp (α : r₁ ⟶ r₂) (β : r₂ ⟶ r₃) : (conjugateEquiv adj₂ adj₃).symm β ≫ (conjugateEquiv adj₁ adj₂).symm α = (conjugateEquiv adj₁ adj₃).symm (α ≫ β) := by rw [Equiv.eq_symm_apply, ← conjugateEquiv_comp _ adj₂] simp only [Equiv.apply_symm_apply] theorem conjugateEquiv_comm {α : l₂ ⟶ l₁} {β : l₁ ⟶ l₂} (βα : β ≫ α = 𝟙 _) : conjugateEquiv adj₁ adj₂ α ≫ conjugateEquiv adj₂ adj₁ β = 𝟙 _ := by rw [conjugateEquiv_comp, βα, conjugateEquiv_id] theorem conjugateEquiv_symm_comm {α : r₁ ⟶ r₂} {β : r₂ ⟶ r₁} (αβ : α ≫ β = 𝟙 _) : (conjugateEquiv adj₂ adj₁).symm β ≫ (conjugateEquiv adj₁ adj₂).symm α = 𝟙 _ := by rw [conjugateEquiv_symm_comp, αβ, conjugateEquiv_symm_id] end ConjugateComposition section ConjugateIsomorphism variable {c d : B} variable {l₁ l₂ : c ⟶ d} {r₁ r₂ : d ⟶ c} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) /-- If `α` is an isomorphism between left adjoints, then its conjugate transformation is an isomorphism. The converse is given in `conjugateEquiv_of_iso`. -/ instance conjugateEquiv_iso (α : l₂ ⟶ l₁) [IsIso α] : IsIso (conjugateEquiv adj₁ adj₂ α) := ⟨⟨conjugateEquiv adj₂ adj₁ (inv α), ⟨conjugateEquiv_comm _ _ (by simp), conjugateEquiv_comm _ _ (by simp)⟩⟩⟩ /-- If `α` is an isomorphism between right adjoints, then its conjugate transformation is an isomorphism. The converse is given in `conjugateEquiv_symm_of_iso`. -/ instance conjugateEquiv_symm_iso (α : r₁ ⟶ r₂) [IsIso α] : IsIso ((conjugateEquiv adj₁ adj₂).symm α) := ⟨⟨(conjugateEquiv adj₂ adj₁).symm (inv α), ⟨conjugateEquiv_symm_comm _ _ (by simp), conjugateEquiv_symm_comm _ _ (by simp)⟩⟩⟩ /-- If `α` is a natural transformation between left adjoints whose conjugate natural transformation is an isomorphism, then `α` is an isomorphism. The converse is given in `Conjugate_iso`. -/ theorem conjugateEquiv_of_iso (α : l₂ ⟶ l₁) [IsIso (conjugateEquiv adj₁ adj₂ α)] : IsIso α := by suffices IsIso ((conjugateEquiv adj₁ adj₂).symm (conjugateEquiv adj₁ adj₂ α)) by simpa only [Equiv.symm_apply_apply] using this infer_instance /-- If `α` is a natural transformation between right adjoints whose conjugate natural transformation is an isomorphism, then `α` is an isomorphism. The converse is given in `conjugateEquiv_symm_iso`. -/ theorem conjugateEquiv_symm_of_iso (α : r₁ ⟶ r₂) [IsIso ((conjugateEquiv adj₁ adj₂).symm α)] : IsIso α := by suffices IsIso ((conjugateEquiv adj₁ adj₂) ((conjugateEquiv adj₁ adj₂).symm α)) by simpa only [Equiv.apply_symm_apply] using this infer_instance /-- Thus conjugation defines an equivalence between natural isomorphisms. -/ @[simps] def conjugateIsoEquiv : (l₂ ≅ l₁) ≃ (r₁ ≅ r₂) where toFun α := { hom := conjugateEquiv adj₁ adj₂ α.hom inv := conjugateEquiv adj₂ adj₁ α.inv hom_inv_id := by rw [conjugateEquiv_comp, Iso.inv_hom_id, conjugateEquiv_id] inv_hom_id := by rw [conjugateEquiv_comp, Iso.hom_inv_id, conjugateEquiv_id] } invFun β := { hom := (conjugateEquiv adj₁ adj₂).symm β.hom inv := (conjugateEquiv adj₂ adj₁).symm β.inv hom_inv_id := by rw [conjugateEquiv_symm_comp, Iso.inv_hom_id, conjugateEquiv_symm_id] inv_hom_id := by rw [conjugateEquiv_symm_comp, Iso.hom_inv_id, conjugateEquiv_symm_id] } left_inv := by intro α simp only [Equiv.symm_apply_apply] right_inv := by intro α simp only [Equiv.apply_symm_apply] end ConjugateIsomorphism section IteratedMateEquiv variable {a b c d : B} variable {f₁ : a ⟶ c} {u₁ : c ⟶ a} {f₂ : b ⟶ d} {u₂ : d ⟶ b} variable {l₁ : a ⟶ b} {r₁ : b ⟶ a} {l₂ : c ⟶ d} {r₂ : d ⟶ c} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) (adj₃ : f₁ ⊣ u₁) (adj₄ : f₂ ⊣ u₂) /-- When all four morphisms in a square are left adjoints, the mates operation can be iterated: ``` l₁ r₁ r₁ c --→ d c ←-- d c ←-- d f₁ ↓ ↗ ↓ f₂ f₁ ↓ ↘ ↓ f₂ u₁ ↑ ↙ ↑ u₂ a --→ b a ←-- b a ←-- b l₂ r₂ r₂ ``` In this case the iterated mate equals the conjugate of the original 2-morphism and is thus an isomorphism if and only if the original 2-morphism is. This explains why some Beck-Chevalley 2-morphisms are isomorphisms. -/ theorem iterated_mateEquiv_conjugateEquiv (α : f₁ ≫ l₂ ⟶ l₁ ≫ f₂) : mateEquiv adj₄ adj₃ (mateEquiv adj₁ adj₂ α) = conjugateEquiv (adj₁.comp adj₄) (adj₃.comp adj₂) α := by simp only [conjugateEquiv_apply, mateEquiv_apply'] dsimp [Adjunction.comp] bicategory theorem iterated_mateEquiv_conjugateEquiv_symm (α : u₂ ≫ r₁ ⟶ r₂ ≫ u₁) : (mateEquiv adj₁ adj₂).symm ((mateEquiv adj₄ adj₃).symm α) = (conjugateEquiv (adj₁.comp adj₄) (adj₃.comp adj₂)).symm α := by rw [Equiv.eq_symm_apply, ← iterated_mateEquiv_conjugateEquiv] simp only [Equiv.apply_symm_apply] end IteratedMateEquiv section mateEquiv_conjugateEquiv_vcomp variable {a b c d : B} variable {g : a ⟶ c} {h : b ⟶ d} variable {l₁ : a ⟶ b} {r₁ : b ⟶ a} {l₂ : c ⟶ d} {r₂ : d ⟶ c} {l₃ : c ⟶ d} {r₃ : d ⟶ c} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) (adj₃ : l₃ ⊣ r₃) /-- Composition of a squares between left adjoints with a conjugate square. -/ def leftAdjointSquareConjugate.vcomp (α : g ≫ l₂ ⟶ l₁ ≫ h) (β : l₃ ⟶ l₂) : g ≫ l₃ ⟶ l₁ ≫ h := g ◁ β ≫ α /-- Composition of a squares between right adjoints with a conjugate square. -/ def rightAdjointSquareConjugate.vcomp (α : r₁ ≫ g ⟶ h ≫ r₂) (β : r₂ ⟶ r₃) : r₁ ≫ g ⟶ h ≫ r₃ := α ≫ h ◁ β /-- The mates equivalence commutes with this composition, essentially by `mateEquiv_vcomp`. -/ theorem mateEquiv_conjugateEquiv_vcomp (α : g ≫ l₂ ⟶ l₁ ≫ h) (β : l₃ ⟶ l₂) : (mateEquiv adj₁ adj₃) (leftAdjointSquareConjugate.vcomp α β) = rightAdjointSquareConjugate.vcomp (mateEquiv adj₁ adj₂ α) (conjugateEquiv adj₂ adj₃ β) := by symm calc _ = 𝟙 _ ⊗≫ rightAdjointSquare.vcomp (mateEquiv adj₁ adj₂ α) (mateEquiv adj₂ adj₃ ((λ_ l₃).hom ≫ β ≫ (ρ_ l₂).inv)) ⊗≫ 𝟙 _ := by dsimp only [conjugateEquiv_apply, rightAdjointSquareConjugate.vcomp, rightAdjointSquare.vcomp] bicategory _ = _ := by rw [← mateEquiv_vcomp] simp only [leftAdjointSquare.vcomp, mateEquiv_apply', leftAdjointSquareConjugate.vcomp] bicategory end mateEquiv_conjugateEquiv_vcomp section conjugateEquiv_mateEquiv_vcomp variable {a b c d : B} variable {g : a ⟶ c} {h : b ⟶ d} variable {l₁ : a ⟶ b} {r₁ : b ⟶ a} {l₂ : a ⟶ b} {r₂ : b ⟶ a} {l₃ : c ⟶ d} {r₃ : d ⟶ c} variable (adj₁ : l₁ ⊣ r₁) (adj₂ : l₂ ⊣ r₂) (adj₃ : l₃ ⊣ r₃) /-- Composition of a conjugate square with a squares between left adjoints. -/ def leftAdjointConjugateSquare.vcomp (α : l₂ ⟶ l₁) (β : g ≫ l₃ ⟶ l₂ ≫ h) : g ≫ l₃ ⟶ l₁ ≫ h := β ≫ α ▷ h /-- Composition of a conjugate square with a squares between right adjoints. -/ def rightAdjointConjugateSquare.vcomp (α : r₁ ⟶ r₂) (β : r₂ ≫ g ⟶ h ≫ r₃) : r₁ ≫ g ⟶ h ≫ r₃ := α ▷ g ≫ β /-- The mates equivalence commutes with this composition, essentially by `mateEquiv_vcomp`. -/ theorem conjugateEquiv_mateEquiv_vcomp (α : l₂ ⟶ l₁) (β : g ≫ l₃ ⟶ l₂ ≫ h) : (mateEquiv adj₁ adj₃) (leftAdjointConjugateSquare.vcomp α β) = rightAdjointConjugateSquare.vcomp (conjugateEquiv adj₁ adj₂ α) (mateEquiv adj₂ adj₃ β) := by symm calc _ = 𝟙 _ ⊗≫ rightAdjointSquare.vcomp (mateEquiv adj₁ adj₂ ((λ_ l₂).hom ≫ α ≫ (ρ_ l₁).inv)) (mateEquiv adj₂ adj₃ β) ⊗≫ 𝟙 _ := by dsimp only [conjugateEquiv_apply, rightAdjointConjugateSquare.vcomp, rightAdjointSquare.vcomp] bicategory _ = _ := by rw [← mateEquiv_vcomp] simp only [leftAdjointSquare.vcomp, mateEquiv_apply', leftAdjointConjugateSquare.vcomp] bicategory end conjugateEquiv_mateEquiv_vcomp end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/Adjunction/Adj.lean
import Mathlib.CategoryTheory.Bicategory.Adjunction.Mate import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor /-! # The bicategory of adjunctions in a bicategory Given a bicategory `B`, we construct a bicategory `Adj B` that has essentially the same objects as `B` but whose `1`-morphisms are adjunctions (in the same direction as the left adjoints), and `2`-morphisms are tuples of mate maps between the left and right adjoints (where the map between right adjoints is in the opposite direction). Certain pseudofunctors to the bicategory `Adj Cat` are analogous to bifibered categories: in various contexts, this may be used in order to formalize the properties of both pullback and pushforward functors. ## References * https://ncatlab.org/nlab/show/2-category+of+adjunctions * https://ncatlab.org/nlab/show/transformation+of+adjoints * https://ncatlab.org/nlab/show/mate -/ universe w v u namespace CategoryTheory namespace Bicategory /-- The bicategory that has the same objects as a bicategory `B`, in which `1`-morphisms are adjunctions (in the same direction as the left adjoints), and `2`-morphisms are tuples of mate maps between the left and right adjoints (where the map between right adjoints is in the opposite direction). -/ structure Adj (B : Type u) [Bicategory.{w, v} B] where /-- If `a : Adj B`, `a.obj : B` is the underlying object of the bicategory `B`. -/ obj : B variable {B : Type u} [Bicategory.{w, v} B] namespace Adj @[simp] lemma mk_obj (b : Adj B) : mk b.obj = b := rfl section variable (a b : B) /-- Given two objects `a` and `b` in a bicategory, this is the type of adjunctions between `a` and `b`. -/ structure Hom where /-- the left adjoint -/ {l : a ⟶ b} /-- the right adjoint -/ {r : b ⟶ a} /-- the adjunction -/ adj : l ⊣ r end @[simps! id_l id_r id_adj comp_l comp_r comp_adj] instance : CategoryStruct (Adj B) where Hom a b := Hom a.obj b.obj id a := .mk (Adjunction.id a.obj) comp f g := .mk (f.adj.comp g.adj) variable {a b c d : Adj B} /-- A morphism between two adjunctions consists of a tuple of mate maps. -/ @[ext] structure Hom₂ (α β : a ⟶ b) where /-- the morphism between left adjoints -/ τl : α.l ⟶ β.l /-- the morphism in the opposite direction between right adjoints -/ τr : β.r ⟶ α.r conjugateEquiv_τl : conjugateEquiv β.adj α.adj τl = τr := by cat_disch lemma Hom₂.conjugateEquiv_symm_τr {α β : a ⟶ b} (p : Hom₂ α β) : (conjugateEquiv β.adj α.adj).symm p.τr = p.τl := by rw [← Hom₂.conjugateEquiv_τl, Equiv.symm_apply_apply] @[simps!] instance : CategoryStruct (a ⟶ b) where Hom α β := Hom₂ α β id α := { τl := 𝟙 _ τr := 𝟙 _ } comp {a b c} x y := { τl := x.τl ≫ y.τl τr := y.τr ≫ x.τr conjugateEquiv_τl := by simp [← conjugateEquiv_comp c.adj b.adj a.adj y.τl x.τl, Hom₂.conjugateEquiv_τl] } attribute [reassoc] comp_τl comp_τr @[ext] lemma hom₂_ext {α β : a ⟶ b} {x y : α ⟶ β} (hl : x.τl = y.τl) : x = y := Hom₂.ext hl (by simp only [← Hom₂.conjugateEquiv_τl, hl]) instance : Category (a ⟶ b) where /-- Constructor for isomorphisms between 1-morphisms in the bicategory `Adj B`. -/ @[simps] def iso₂Mk {α β : a ⟶ b} (el : α.l ≅ β.l) (er : β.r ≅ α.r) (h : conjugateEquiv β.adj α.adj el.hom = er.hom) : α ≅ β where hom := { τl := el.hom τr := er.hom conjugateEquiv_τl := h } inv := { τl := el.inv τr := er.inv conjugateEquiv_τl := by rw [← cancel_mono er.hom, Iso.inv_hom_id, ← h, conjugateEquiv_comp, Iso.hom_inv_id, conjugateEquiv_id] } namespace Bicategory /-- The associator in the bicategory `Adj B`. -/ @[simps!] def associator (α : a ⟶ b) (β : b ⟶ c) (γ : c ⟶ d) : (α ≫ β) ≫ γ ≅ α ≫ β ≫ γ := iso₂Mk (α_ _ _ _) (α_ _ _ _) (conjugateEquiv_associator_hom _ _ _) /-- The left unitor in the bicategory `Adj B`. -/ @[simps!] def leftUnitor (α : a ⟶ b) : 𝟙 a ≫ α ≅ α := iso₂Mk (λ_ _) (ρ_ _).symm (by simpa using conjugateEquiv_id_comp_right_apply α.adj α.adj (𝟙 _)) /-- The right unitor in the bicategory `Adj B`. -/ @[simps!] def rightUnitor (α : a ⟶ b) : α ≫ 𝟙 b ≅ α := iso₂Mk (ρ_ _) (λ_ _).symm (by simpa using conjugateEquiv_comp_id_right_apply α.adj α.adj (𝟙 _)) /-- The left whiskering in the bicategory `Adj B`. -/ @[simps] def whiskerLeft (α : a ⟶ b) {β β' : b ⟶ c} (y : β ⟶ β') : α ≫ β ⟶ α ≫ β' where τl := _ ◁ y.τl τr := y.τr ▷ _ conjugateEquiv_τl := by simp [conjugateEquiv_whiskerLeft, Hom₂.conjugateEquiv_τl] /-- The right whiskering in the bicategory `Adj B`. -/ @[simps] def whiskerRight {α α' : a ⟶ b} (x : α ⟶ α') (β : b ⟶ c) : α ≫ β ⟶ α' ≫ β where τl := x.τl ▷ _ τr := _ ◁ x.τr conjugateEquiv_τl := by simp [conjugateEquiv_whiskerRight, Hom₂.conjugateEquiv_τl] end Bicategory attribute [local simp] whisker_exchange @[simps! whiskerRight_τr whiskerRight_τl whiskerLeft_τr whiskerLeft_τl associator_hom_τr associator_inv_τr associator_hom_τl associator_inv_τl leftUnitor_hom_τr leftUnitor_inv_τr leftUnitor_hom_τl leftUnitor_inv_τl rightUnitor_hom_τr rightUnitor_inv_τr rightUnitor_hom_τl rightUnitor_inv_τl] instance : Bicategory (Adj B) where whiskerLeft := Bicategory.whiskerLeft whiskerRight := Bicategory.whiskerRight associator := Bicategory.associator leftUnitor := Bicategory.leftUnitor rightUnitor := Bicategory.rightUnitor /-- The forget pseudofunctor from `Adj B` to `B`. -/ @[simps] def forget₁ : Adj B ⥤ᵖ B where obj a := a.obj map x := x.l map₂ α := α.τl mapId _ := Iso.refl _ mapComp _ _ := Iso.refl _ -- TODO: define `forget₂` which sends an adjunction to its right adjoint functor /-- Given an isomorphism between two 1-morphisms in `Adj B`, this is the underlying isomorphisms between the left adjoints. -/ @[simps] def lIso {a b : Adj B} {adj₁ adj₂ : a ⟶ b} (e : adj₁ ≅ adj₂) : adj₁.l ≅ adj₂.l where hom := e.hom.τl inv := e.inv.τl hom_inv_id := by rw [← comp_τl, e.hom_inv_id, id_τl] inv_hom_id := by rw [← comp_τl, e.inv_hom_id, id_τl] /-- Given an isomorphism between two 1-morphisms in `Adj B`, this is the underlying isomorphisms between the right adjoints. -/ @[simps] def rIso {a b : Adj B} {adj₁ adj₂ : a ⟶ b} (e : adj₁ ≅ adj₂) : adj₁.r ≅ adj₂.r where hom := e.inv.τr inv := e.hom.τr hom_inv_id := by rw [← comp_τr, e.hom_inv_id, id_τr] inv_hom_id := by rw [← comp_τr, e.inv_hom_id, id_τr] end Adj end Bicategory end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Bicategory/FunctorBicategory/Oplax.lean
import Mathlib.CategoryTheory.Bicategory.Modification.Oplax /-! # The bicategory of oplax functors between two bicategories Given bicategories `B` and `C`, we give a bicategory structure on `B ⥤ᵒᵖᴸ C` whose * objects are oplax functors, * 1-morphisms are oplax natural transformations, and * 2-morphisms are modifications. -/ namespace CategoryTheory.Oplax open Category Bicategory open scoped Bicategory universe w₁ w₂ v₁ v₂ u₁ u₂ variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] variable {F G H I : B ⥤ᵒᵖᴸ C} namespace OplaxTrans /-- Left whiskering of an oplax natural transformation and a modification. -/ @[simps] def whiskerLeft (η : F ⟶ G) {θ ι : G ⟶ H} (Γ : θ ⟶ ι) : η ≫ θ ⟶ η ≫ ι where app a := η.app a ◁ Γ.app a naturality {a b} f := by dsimp rw [associator_inv_naturality_right_assoc, whisker_exchange_assoc] simp /-- Right whiskering of an oplax natural transformation and a modification. -/ @[simps] def whiskerRight {η θ : F ⟶ G} (Γ : η ⟶ θ) (ι : G ⟶ H) : η ≫ ι ⟶ θ ≫ ι where app a := Γ.app a ▷ ι.app a naturality {a b} f := by dsimp simp_rw [assoc, ← associator_inv_naturality_left, whisker_exchange_assoc] simp /-- Associator for the vertical composition of oplax natural transformations. -/ @[simps!] def associator (η : F ⟶ G) (θ : G ⟶ H) (ι : H ⟶ I) : (η ≫ θ) ≫ ι ≅ η ≫ θ ≫ ι := ModificationIso.ofComponents (fun a => α_ (η.app a) (θ.app a) (ι.app a)) (by simp) /-- Left unitor for the vertical composition of oplax natural transformations. -/ @[simps!] def leftUnitor (η : F ⟶ G) : 𝟙 F ≫ η ≅ η := ModificationIso.ofComponents (fun a => λ_ (η.app a)) (by simp) /-- Right unitor for the vertical composition of oplax natural transformations. -/ @[simps!] def rightUnitor (η : F ⟶ G) : η ≫ 𝟙 G ≅ η := ModificationIso.ofComponents (fun a => ρ_ (η.app a)) (by simp) variable (B C) /-- A bicategory structure on the oplax functors between bicategories. -/ @[simps!] scoped instance OplaxFunctor.bicategory : Bicategory (B ⥤ᵒᵖᴸ C) where whiskerLeft {_ _ _} η _ _ Γ := whiskerLeft η Γ whiskerRight {_ _ _} _ _ Γ η := whiskerRight Γ η associator {_ _ _} _ := associator leftUnitor {_ _} := leftUnitor rightUnitor {_ _} := rightUnitor whisker_exchange {a b c f g h i} η θ := by ext exact whisker_exchange _ _ end OplaxTrans end CategoryTheory.Oplax
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Monadicity.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Reflexive import Mathlib.CategoryTheory.Monad.Coequalizer import Mathlib.CategoryTheory.Monad.Limits /-! # Monadicity theorems We prove monadicity theorems which can establish a given functor is monadic. In particular, we show three versions of Beck's monadicity theorem, and the reflexive (crude) monadicity theorem: `G` is a monadic right adjoint if it has a left adjoint, and: * `D` has, `G` preserves and reflects `G`-split coequalizers, see `CategoryTheory.Monad.monadicOfHasPreservesReflectsGSplitCoequalizers` * `G` creates `G`-split coequalizers, see `CategoryTheory.Monad.monadicOfCreatesGSplitCoequalizers` (The converse of this is also shown, see `CategoryTheory.Monad.createsGSplitCoequalizersOfMonadic`) * `D` has and `G` preserves `G`-split coequalizers, and `G` reflects isomorphisms, see `CategoryTheory.Monad.monadicOfHasPreservesGSplitCoequalizersOfReflectsIsomorphisms` * `D` has and `G` preserves reflexive coequalizers, and `G` reflects isomorphisms, see `CategoryTheory.Monad.monadicOfHasPreservesReflexiveCoequalizersOfReflectsIsomorphisms` This file has been adapted to `Mathlib/CategoryTheory/Monad/Comonadicity.lean`. Please try to keep them in sync. ## Tags Beck, monadicity, descent -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory namespace Monad open Limits noncomputable section -- Hide the implementation details in this namespace. namespace MonadicityInternal variable {C : Type u₁} {D : Type u₂} variable [Category.{v₁} C] [Category.{v₁} D] variable {G : D ⥤ C} {F : C ⥤ D} (adj : F ⊣ G) /-- The "main pair" for an algebra `(A, α)` is the pair of morphisms `(F α, ε_FA)`. It is always a reflexive pair, and will be used to construct the left adjoint to the comparison functor and show it is an equivalence. -/ instance main_pair_reflexive (A : adj.toMonad.Algebra) : IsReflexivePair (F.map A.a) (adj.counit.app (F.obj A.A)) := by apply IsReflexivePair.mk' (F.map (adj.unit.app _)) _ _ · rw [← F.map_comp, ← F.map_id] exact congr_arg F.map A.unit · rw [adj.left_triangle_components] rfl /-- The "main pair" for an algebra `(A, α)` is the pair of morphisms `(F α, ε_FA)`. It is always a `G`-split pair, and will be used to construct the left adjoint to the comparison functor and show it is an equivalence. -/ instance main_pair_G_split (A : adj.toMonad.Algebra) : G.IsSplitPair (F.map A.a) (adj.counit.app (F.obj A.A)) where splittable := ⟨_, _, ⟨beckSplitCoequalizer A⟩⟩ /-- The object function for the left adjoint to the comparison functor. -/ def comparisonLeftAdjointObj (A : adj.toMonad.Algebra) [HasCoequalizer (F.map A.a) (adj.counit.app _)] : D := coequalizer (F.map A.a) (adj.counit.app _) /-- We have a bijection of homsets which will be used to construct the left adjoint to the comparison functor. -/ @[simps!] def comparisonLeftAdjointHomEquiv (A : adj.toMonad.Algebra) (B : D) [HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] : (comparisonLeftAdjointObj adj A ⟶ B) ≃ (A ⟶ (comparison adj).obj B) := calc (comparisonLeftAdjointObj adj A ⟶ B) ≃ { f : F.obj A.A ⟶ B // _ } := Cofork.IsColimit.homIso (colimit.isColimit _) B _ ≃ { g : A.A ⟶ G.obj B // G.map (F.map g) ≫ G.map (adj.counit.app B) = A.a ≫ g } := by refine (adj.homEquiv _ _).subtypeEquiv ?_ intro f rw [← (adj.homEquiv _ _).injective.eq_iff, Adjunction.homEquiv_naturality_left, adj.homEquiv_unit, adj.homEquiv_unit, G.map_comp] dsimp rw [adj.right_triangle_components_assoc, ← G.map_comp, F.map_comp, Category.assoc, adj.counit_naturality, adj.left_triangle_components_assoc] apply eq_comm _ ≃ (A ⟶ (comparison adj).obj B) := { toFun := fun g => { f := _ h := g.prop } invFun := fun f => ⟨f.f, f.h⟩ } /-- Construct the adjunction to the comparison functor. -/ def leftAdjointComparison [∀ A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] : adj.toMonad.Algebra ⥤ D := by refine Adjunction.leftAdjointOfEquiv (G := comparison adj) (F_obj := fun A => comparisonLeftAdjointObj adj A) (fun A B => ?_) ?_ · apply comparisonLeftAdjointHomEquiv · intro A B B' g h ext1 simp [Cofork.IsColimit.homIso, Adjunction.homEquiv_unit] /-- Provided we have the appropriate coequalizers, we have an adjunction to the comparison functor. -/ @[simps! counit] def comparisonAdjunction [∀ A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] : leftAdjointComparison adj ⊣ comparison adj := Adjunction.adjunctionOfEquivLeft _ _ variable {adj} theorem comparisonAdjunction_unit_f_aux [∀ A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] (A : adj.toMonad.Algebra) : ((comparisonAdjunction adj).unit.app A).f = adj.homEquiv A.A _ (coequalizer.π (F.map A.a) (adj.counit.app (F.obj A.A))) := congr_arg (adj.homEquiv _ _) (Category.comp_id _) /-- This is a cofork which is helpful for establishing monadicity: the morphism from the Beck coequalizer to this cofork is the unit for the adjunction on the comparison functor. -/ @[simps! pt] def unitCofork (A : adj.toMonad.Algebra) [HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] : Cofork (G.map (F.map A.a)) (G.map (adj.counit.app (F.obj A.A))) := Cofork.ofπ (G.map (coequalizer.π (F.map A.a) (adj.counit.app (F.obj A.A)))) (by rw [← G.map_comp, coequalizer.condition, G.map_comp]) @[simp] theorem unitCofork_π (A : adj.toMonad.Algebra) [HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] : (unitCofork A).π = G.map (coequalizer.π (F.map A.a) (adj.counit.app (F.obj A.A))) := rfl theorem comparisonAdjunction_unit_f [∀ A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] (A : adj.toMonad.Algebra) : ((comparisonAdjunction adj).unit.app A).f = (beckCoequalizer A).desc (unitCofork A) := by apply Limits.Cofork.IsColimit.hom_ext (beckCoequalizer A) rw [Cofork.IsColimit.π_desc] dsimp only [beckCofork_π, unitCofork_π] rw [comparisonAdjunction_unit_f_aux, ← adj.homEquiv_naturality_left A.a, coequalizer.condition, adj.homEquiv_naturality_right, adj.homEquiv_unit, Category.assoc] apply adj.right_triangle_components_assoc variable (adj) /-- The cofork which describes the counit of the adjunction: the morphism from the coequalizer of this pair to this morphism is the counit. -/ @[simps!] def counitCofork (B : D) : Cofork (F.map (G.map (adj.counit.app B))) (adj.counit.app (F.obj (G.obj B))) := Cofork.ofπ (adj.counit.app B) (adj.counit_naturality _) variable {adj} in /-- The unit cofork is a colimit provided `G` preserves it. -/ def unitColimitOfPreservesCoequalizer (A : adj.toMonad.Algebra) [HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] [PreservesColimit (parallelPair (F.map A.a) (adj.counit.app (F.obj A.A))) G] : IsColimit (unitCofork (G := G) A) := isColimitOfHasCoequalizerOfPreservesColimit G _ _ /-- The counit cofork is a colimit provided `G` reflects it. -/ def counitCoequalizerOfReflectsCoequalizer (B : D) [ReflectsColimit (parallelPair (F.map (G.map (adj.counit.app B))) (adj.counit.app (F.obj (G.obj B)))) G] : IsColimit (counitCofork (adj := adj) B) := isColimitOfIsColimitCoforkMap G _ (beckCoequalizer ((comparison adj).obj B)) instance [∀ A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] (B : D) : HasColimit (parallelPair (F.map (G.map (NatTrans.app adj.counit B))) (NatTrans.app adj.counit (F.obj (G.obj B)))) := inferInstanceAs <| HasCoequalizer (F.map ((comparison adj).obj B).a) (adj.counit.app (F.obj ((comparison adj).obj B).A)) theorem comparisonAdjunction_counit_app [∀ A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] (B : D) : (comparisonAdjunction adj).counit.app B = colimit.desc _ (counitCofork adj B) := by apply coequalizer.hom_ext change coequalizer.π _ _ ≫ coequalizer.desc ((adj.homEquiv _ B).symm (𝟙 _)) _ = coequalizer.π _ _ ≫ coequalizer.desc _ _ simp [Adjunction.homEquiv_counit] end MonadicityInternal open MonadicityInternal variable {C : Type u₁} {D : Type u₂} variable [Category.{v₁} C] [Category.{v₁} D] variable {G : D ⥤ C} {F : C ⥤ D} (adj : F ⊣ G) variable (G) in /-- If `G` is monadic, it creates colimits of `G`-split pairs. This is the "boring" direction of Beck's monadicity theorem, the converse is given in `monadicOfCreatesGSplitCoequalizers`. -/ def createsGSplitCoequalizersOfMonadic [MonadicRightAdjoint G] ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g] : CreatesColimit (parallelPair f g) G := by apply (config := {allowSynthFailures := true}) monadicCreatesColimitOfPreservesColimit -- Porting note: oddly (config := {allowSynthFailures := true}) had no effect here and below all_goals apply @preservesColimit_of_iso_diagram _ _ _ _ _ _ _ _ _ (diagramIsoParallelPair.{v₁} _).symm ?_ dsimp infer_instance section BeckMonadicity -- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311 -- When this is fixed the proofs below that struggle with instances should be reviewed. -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g], HasCoequalizer f g] /-- Typeclass expressing that for all `G`-split pairs `f,g`, `f` and `g` have a coequalizer. -/ class HasCoequalizerOfIsSplitPair (G : D ⥤ C) : Prop where out : ∀ {A B} (f g : A ⟶ B) [G.IsSplitPair f g], HasCoequalizer f g -- Porting note: cannot find synth order -- instance {A B} (f g : A ⟶ B) [G.IsSplitPair f g] [HasCoequalizerOfIsSplitPair G] : -- HasCoequalizer f g := HasCoequalizerOfIsSplitPair.out f g instance [HasCoequalizerOfIsSplitPair G] : ∀ (A : Algebra adj.toMonad), HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A)) := fun _ => HasCoequalizerOfIsSplitPair.out G _ _ -- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g], PreservesColimit (parallelPair f g) G] /-- Typeclass expressing that for all `G`-split pairs `f,g`, `G` preserves colimits of `parallelPair f g`. -/ class PreservesColimitOfIsSplitPair (G : D ⥤ C) where out : ∀ {A B} (f g : A ⟶ B) [G.IsSplitPair f g], PreservesColimit (parallelPair f g) G instance {A B} (f g : A ⟶ B) [G.IsSplitPair f g] [PreservesColimitOfIsSplitPair G] : PreservesColimit (parallelPair f g) G := PreservesColimitOfIsSplitPair.out f g instance [PreservesColimitOfIsSplitPair G] : ∀ (A : Algebra adj.toMonad), PreservesColimit (parallelPair (F.map A.a) (NatTrans.app adj.counit (F.obj A.A))) G := fun _ => PreservesColimitOfIsSplitPair.out _ _ -- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g], ReflectsColimit (parallelPair f g) G] : /-- Typeclass expressing that for all `G`-split pairs `f,g`, `G` reflects colimits for `parallelPair f g`. -/ class ReflectsColimitOfIsSplitPair (G : D ⥤ C) where out : ∀ {A B} (f g : A ⟶ B) [G.IsSplitPair f g], ReflectsColimit (parallelPair f g) G instance {A B} (f g : A ⟶ B) [G.IsSplitPair f g] [ReflectsColimitOfIsSplitPair G] : ReflectsColimit (parallelPair f g) G := ReflectsColimitOfIsSplitPair.out f g instance [ReflectsColimitOfIsSplitPair G] : ∀ (A : Algebra adj.toMonad), ReflectsColimit (parallelPair (F.map A.a) (NatTrans.app adj.counit (F.obj A.A))) G := fun _ => ReflectsColimitOfIsSplitPair.out _ _ /-- To show `G` is a monadic right adjoint, we can show it preserves and reflects `G`-split coequalizers, and `D` has them. -/ def monadicOfHasPreservesReflectsGSplitCoequalizers [HasCoequalizerOfIsSplitPair G] [PreservesColimitOfIsSplitPair G] [ReflectsColimitOfIsSplitPair G] : MonadicRightAdjoint G where L := F adj := adj eqv := by have : ∀ (X : Algebra adj.toMonad), IsIso ((comparisonAdjunction adj).unit.app X) := by intro X apply @isIso_of_reflects_iso _ _ _ _ _ _ _ (Monad.forget adj.toMonad) ?_ _ · change IsIso ((comparisonAdjunction adj).unit.app X).f rw [comparisonAdjunction_unit_f] change IsIso (IsColimit.coconePointUniqueUpToIso (beckCoequalizer X) (unitColimitOfPreservesCoequalizer X)).hom exact (IsColimit.coconePointUniqueUpToIso _ _).isIso_hom have : ∀ (Y : D), IsIso ((comparisonAdjunction adj).counit.app Y) := by intro Y rw [comparisonAdjunction_counit_app] -- Porting note: passing instances through change IsIso (IsColimit.coconePointUniqueUpToIso _ ?_).hom · infer_instance -- Porting note: passing instances through apply @counitCoequalizerOfReflectsCoequalizer _ _ _ _ _ _ _ _ ?_ letI _ : G.IsSplitPair (F.map (G.map (adj.counit.app Y))) (adj.counit.app (F.obj (G.obj Y))) := MonadicityInternal.main_pair_G_split _ ((comparison adj).obj Y) infer_instance exact (comparisonAdjunction adj).toEquivalence.isEquivalence_inverse -- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g], CreatesColimit (parallelPair f g) G] : /-- Typeclass expressing that for all `G`-split pairs `f,g`, `G` creates colimits of `parallelPair f g`. -/ class CreatesColimitOfIsSplitPair (G : D ⥤ C) where /-- For all `G`-split pairs `f,g`, `G` creates colimits of `parallelPair f g`. -/ out : ∀ {A B} (f g : A ⟶ B) [G.IsSplitPair f g], CreatesColimit (parallelPair f g) G instance {A B} (f g : A ⟶ B) [G.IsSplitPair f g] [CreatesColimitOfIsSplitPair G] : CreatesColimit (parallelPair f g) G := CreatesColimitOfIsSplitPair.out f g instance [CreatesColimitOfIsSplitPair G] : ∀ (A : Algebra adj.toMonad), CreatesColimit (parallelPair (F.map A.a) (NatTrans.app adj.counit (F.obj A.A))) G := fun _ => CreatesColimitOfIsSplitPair.out _ _ /-- **Beck's monadicity theorem**: if `G` has a left adjoint and creates coequalizers of `G`-split pairs, then it is monadic. This is the converse of `createsGSplitCoequalizersOfMonadic`. -/ def monadicOfCreatesGSplitCoequalizers [CreatesColimitOfIsSplitPair G] : MonadicRightAdjoint G := by have I {A B} (f g : A ⟶ B) [G.IsSplitPair f g] : HasColimit (parallelPair f g ⋙ G) := by rw [hasColimit_iff_of_iso (diagramIsoParallelPair.{v₁} _)] exact inferInstanceAs <| HasCoequalizer (G.map f) (G.map g) have : HasCoequalizerOfIsSplitPair G := ⟨fun _ _ => hasColimit_of_created (parallelPair _ _) G⟩ have : PreservesColimitOfIsSplitPair G := ⟨by intros; infer_instance⟩ have : ReflectsColimitOfIsSplitPair G := ⟨by intros; infer_instance⟩ exact monadicOfHasPreservesReflectsGSplitCoequalizers adj /-- An alternate version of **Beck's monadicity theorem**: if `G` reflects isomorphisms, preserves coequalizers of `G`-split pairs and `C` has coequalizers of `G`-split pairs, then it is monadic. -/ def monadicOfHasPreservesGSplitCoequalizersOfReflectsIsomorphisms [G.ReflectsIsomorphisms] [HasCoequalizerOfIsSplitPair G] [PreservesColimitOfIsSplitPair G] : MonadicRightAdjoint G := by have : ReflectsColimitOfIsSplitPair G := ⟨fun f g _ => by have := HasCoequalizerOfIsSplitPair.out G f g apply reflectsColimit_of_reflectsIsomorphisms⟩ apply monadicOfHasPreservesReflectsGSplitCoequalizers adj end BeckMonadicity section ReflexiveMonadicity variable [HasReflexiveCoequalizers D] [G.ReflectsIsomorphisms] -- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsReflexivePair f g], PreservesColimit (parallelPair f g) G] : /-- Typeclass expressing that for all reflexive pairs `f,g`, `G` preserves colimits of `parallelPair f g`. -/ class PreservesColimitOfIsReflexivePair (G : C ⥤ D) where out : ∀ ⦃A B⦄ (f g : A ⟶ B) [IsReflexivePair f g], PreservesColimit (parallelPair f g) G instance {A B} (f g : A ⟶ B) [IsReflexivePair f g] [PreservesColimitOfIsReflexivePair G] : PreservesColimit (parallelPair f g) G := PreservesColimitOfIsReflexivePair.out f g instance [PreservesColimitOfIsReflexivePair G] : ∀ X : Algebra adj.toMonad, PreservesColimit (parallelPair (F.map X.a) (NatTrans.app adj.counit (F.obj X.A))) G := fun _ => PreservesColimitOfIsReflexivePair.out _ _ variable [PreservesColimitOfIsReflexivePair G] /-- Reflexive (crude) monadicity theorem. If `G` has a right adjoint, `D` has and `G` preserves reflexive coequalizers and `G` reflects isomorphisms, then `G` is monadic. -/ def monadicOfHasPreservesReflexiveCoequalizersOfReflectsIsomorphisms : MonadicRightAdjoint G where L := F adj := adj eqv := by have : ∀ (X : Algebra adj.toMonad), IsIso ((comparisonAdjunction adj).unit.app X) := by intro X apply @isIso_of_reflects_iso _ _ _ _ _ _ _ (Monad.forget adj.toMonad) ?_ _ · change IsIso ((comparisonAdjunction adj).unit.app X).f rw [comparisonAdjunction_unit_f] exact (IsColimit.coconePointUniqueUpToIso (beckCoequalizer X) (unitColimitOfPreservesCoequalizer X)).isIso_hom have : ∀ (Y : D), IsIso ((comparisonAdjunction adj).counit.app Y) := by intro Y rw [comparisonAdjunction_counit_app] -- Porting note: passing instances through change IsIso (IsColimit.coconePointUniqueUpToIso _ ?_).hom · infer_instance -- Porting note: passing instances through apply @counitCoequalizerOfReflectsCoequalizer _ _ _ _ _ _ _ _ ?_ apply reflectsColimit_of_reflectsIsomorphisms exact (comparisonAdjunction adj).toEquivalence.isEquivalence_inverse end ReflexiveMonadicity end end Monad end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Products.lean
import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Monad.Algebra /-! # Algebras for the coproduct monad The functor `Y ↦ X ⨿ Y` forms a monad, whose category of monads is equivalent to the under category of `X`. Similarly, `Y ↦ X ⨯ Y` forms a comonad, whose category of comonads is equivalent to the over category of `X`. ## TODO Show that `Over.forget X : Over X ⥤ C` is a comonadic left adjoint and `Under.forget : Under X ⥤ C` is a monadic right adjoint. -/ noncomputable section universe v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] (X : C) section open Comonad variable [HasBinaryProducts C] /-- `X ⨯ -` has a comonad structure. This is sometimes called the writer comonad. -/ @[simps!] def prodComonad : Comonad C where toFunctor := prod.functor.obj X ε := { app := fun _ => Limits.prod.snd } δ := { app := fun _ => prod.lift Limits.prod.fst (𝟙 _) } /-- The forward direction of the equivalence from coalgebras for the product comonad to the over category. -/ @[simps] def coalgebraToOver : Coalgebra (prodComonad X) ⥤ Over X where obj A := Over.mk (A.a ≫ Limits.prod.fst) map f := Over.homMk f.f (by rw [Over.mk_hom, ← f.h_assoc] simp) /-- The backward direction of the equivalence from coalgebras for the product comonad to the over category. -/ @[simps] def overToCoalgebra : Over X ⥤ Coalgebra (prodComonad X) where obj f := { A := f.left a := prod.lift f.hom (𝟙 _) } map g := { f := g.left } /-- The equivalence from coalgebras for the product comonad to the over category. -/ @[simps] def coalgebraEquivOver : Coalgebra (prodComonad X) ≌ Over X where functor := coalgebraToOver X inverse := overToCoalgebra X unitIso := NatIso.ofComponents fun A => Coalgebra.isoMk (Iso.refl _) (Limits.prod.hom_ext (by simp) (by simpa using A.counit)) counitIso := NatIso.ofComponents fun f => Over.isoMk (Iso.refl _) end section open Monad variable [HasBinaryCoproducts C] /-- `X ⨿ -` has a monad structure. This is sometimes called the either monad. -/ @[simps!] def coprodMonad : Monad C where toFunctor := coprod.functor.obj X η := { app := fun _ => coprod.inr } μ := { app := fun _ => coprod.desc coprod.inl (𝟙 _) } /-- The forward direction of the equivalence from algebras for the coproduct monad to the under category. -/ @[simps] def algebraToUnder : Monad.Algebra (coprodMonad X) ⥤ Under X where obj A := Under.mk (coprod.inl ≫ A.a) map f := Under.homMk f.f (by rw [Under.mk_hom, Category.assoc, ← f.h] simp) /-- The backward direction of the equivalence from algebras for the coproduct monad to the under category. -/ @[simps] def underToAlgebra : Under X ⥤ Monad.Algebra (coprodMonad X) where obj f := { A := f.right a := coprod.desc f.hom (𝟙 _) } map g := { f := g.right } /-- The equivalence from algebras for the coproduct monad to the under category. -/ @[simps] def algebraEquivUnder : Monad.Algebra (coprodMonad X) ≌ Under X where functor := algebraToUnder X inverse := underToAlgebra X unitIso := NatIso.ofComponents fun A => Monad.Algebra.isoMk (Iso.refl _) (coprod.hom_ext (by simp) (by simpa using A.unit.symm)) counitIso := NatIso.ofComponents fun f => Under.isoMk (Iso.refl _) end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Basic.lean
import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.Functor.FullyFaithful import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi /-! # Monads We construct the categories of monads and comonads, and their forgetful functors to endofunctors. (Note that these are the category theorist's monads, not the programmers monads. For the translation, see the file `CategoryTheory.Monad.Types`.) For the fact that monads are "just" monoids in the category of endofunctors, see the file `CategoryTheory.Monad.EquivMon`. -/ namespace CategoryTheory open Category universe v₁ u₁ -- morphism levels before object levels. See note [category theory universes]. variable (C : Type u₁) [Category.{v₁} C] /-- The data of a monad on C consists of an endofunctor T together with natural transformations η : 𝟭 C ⟶ T and μ : T ⋙ T ⟶ T satisfying three equations: - T μ_X ≫ μ_X = μ_(TX) ≫ μ_X (associativity) - η_(TX) ≫ μ_X = 1_X (left unit) - Tη_X ≫ μ_X = 1_X (right unit) -/ structure Monad extends C ⥤ C where /-- The unit for the monad. -/ η : 𝟭 _ ⟶ toFunctor /-- The multiplication for the monad. -/ μ : toFunctor ⋙ toFunctor ⟶ toFunctor assoc : ∀ X, toFunctor.map (NatTrans.app μ X) ≫ μ.app _ = μ.app _ ≫ μ.app _ := by cat_disch left_unit : ∀ X : C, η.app (toFunctor.obj X) ≫ μ.app _ = 𝟙 _ := by cat_disch right_unit : ∀ X : C, toFunctor.map (η.app X) ≫ μ.app _ = 𝟙 _ := by cat_disch @[reassoc] lemma Monad.unit_naturality (T : Monad C) ⦃X Y : C⦄ (f : X ⟶ Y) : f ≫ T.η.app Y = T.η.app X ≫ T.map f := T.η.naturality _ @[reassoc] lemma Monad.mu_naturality (T : Monad C) ⦃X Y : C⦄ (f : X ⟶ Y) : T.map (T.map f) ≫ T.μ.app Y = T.μ.app X ≫ T.map f := T.μ.naturality _ /-- The data of a comonad on C consists of an endofunctor G together with natural transformations ε : G ⟶ 𝟭 C and δ : G ⟶ G ⋙ G satisfying three equations: - δ_X ≫ G δ_X = δ_X ≫ δ_(GX) (coassociativity) - δ_X ≫ ε_(GX) = 1_X (left counit) - δ_X ≫ G ε_X = 1_X (right counit) -/ structure Comonad extends C ⥤ C where /-- The counit for the comonad. -/ ε : toFunctor ⟶ 𝟭 _ /-- The comultiplication for the comonad. -/ δ : toFunctor ⟶ toFunctor ⋙ toFunctor coassoc : ∀ X, NatTrans.app δ _ ≫ toFunctor.map (δ.app X) = δ.app _ ≫ δ.app _ := by cat_disch left_counit : ∀ X : C, δ.app X ≫ ε.app (toFunctor.obj X) = 𝟙 _ := by cat_disch right_counit : ∀ X : C, δ.app X ≫ toFunctor.map (ε.app X) = 𝟙 _ := by cat_disch @[reassoc] lemma Comonad.counit_naturality (T : Comonad C) ⦃X Y : C⦄ (f : X ⟶ Y) : T.map f ≫ T.ε.app Y = T.ε.app X ≫ f := T.ε.naturality _ @[reassoc] lemma Comonad.delta_naturality (T : Comonad C) ⦃X Y : C⦄ (f : X ⟶ Y) : T.map f ≫ T.δ.app Y = T.δ.app X ≫ T.map (T.map f) := T.δ.naturality _ variable {C} variable (T : Monad C) (G : Comonad C) instance coeMonad : Coe (Monad C) (C ⥤ C) := ⟨fun T => T.toFunctor⟩ instance coeComonad : Coe (Comonad C) (C ⥤ C) := ⟨fun G => G.toFunctor⟩ initialize_simps_projections CategoryTheory.Monad (toFunctor → coe) initialize_simps_projections CategoryTheory.Comonad (toFunctor → coe) -- TODO: investigate whether `Monad.assoc` can be a `simp` lemma? attribute [reassoc (attr := simp)] Monad.left_unit Monad.right_unit attribute [reassoc (attr := simp)] Comonad.coassoc Comonad.left_counit Comonad.right_counit /-- A morphism of monads is a natural transformation compatible with η and μ. -/ @[ext] structure MonadHom (T₁ T₂ : Monad C) extends NatTrans (T₁ : C ⥤ C) T₂ where app_η : ∀ X, T₁.η.app X ≫ app X = T₂.η.app X := by cat_disch app_μ : ∀ X, T₁.μ.app X ≫ app X = (T₁.map (app X) ≫ app _) ≫ T₂.μ.app X := by cat_disch initialize_simps_projections MonadHom (+toNatTrans, -app) /-- A morphism of comonads is a natural transformation compatible with ε and δ. -/ @[ext] structure ComonadHom (M N : Comonad C) extends NatTrans (M : C ⥤ C) N where app_ε : ∀ X, app X ≫ N.ε.app X = M.ε.app X := by cat_disch app_δ : ∀ X, app X ≫ N.δ.app X = M.δ.app X ≫ app _ ≫ N.map (app X) := by cat_disch initialize_simps_projections ComonadHom (+toNatTrans, -app) attribute [reassoc (attr := simp)] MonadHom.app_η MonadHom.app_μ attribute [reassoc (attr := simp)] ComonadHom.app_ε ComonadHom.app_δ instance : Quiver (Monad C) where Hom := MonadHom instance : Quiver (Comonad C) where Hom := ComonadHom @[ext] lemma MonadHom.ext' {T₁ T₂ : Monad C} (f g : T₁ ⟶ T₂) (h : f.app = g.app) : f = g := MonadHom.ext h @[ext] lemma ComonadHom.ext' {T₁ T₂ : Comonad C} (f g : T₁ ⟶ T₂) (h : f.app = g.app) : f = g := ComonadHom.ext h instance : Category (Monad C) where id M := { toNatTrans := 𝟙 (M : C ⥤ C) } comp f g := { toNatTrans := { app := fun X => f.app X ≫ g.app X naturality := fun X Y h => by rw [assoc, f.1.naturality_assoc, g.1.naturality] } } -- `cat_disch` can fill in these proofs, but is unfortunately slightly slow. id_comp _ := MonadHom.ext (by funext; simp only [NatTrans.id_app, id_comp]) comp_id _ := MonadHom.ext (by funext; simp only [NatTrans.id_app, comp_id]) assoc _ _ _ := MonadHom.ext (by funext; simp only [assoc]) instance : Category (Comonad C) where id M := { toNatTrans := 𝟙 (M : C ⥤ C) } comp f g := { toNatTrans := { app := fun X => f.app X ≫ g.app X naturality := fun X Y h => by rw [assoc, f.1.naturality_assoc, g.1.naturality] } } -- `cat_disch` can fill in these proofs, but is unfortunately slightly slow. id_comp _ := ComonadHom.ext (by funext; simp only [NatTrans.id_app, id_comp]) comp_id _ := ComonadHom.ext (by funext; simp only [NatTrans.id_app, comp_id]) assoc _ _ _ := ComonadHom.ext (by funext; simp only [assoc]) instance {T : Monad C} : Inhabited (MonadHom T T) := ⟨𝟙 T⟩ @[simp] theorem MonadHom.id_toNatTrans (T : Monad C) : (𝟙 T : T ⟶ T).toNatTrans = 𝟙 (T : C ⥤ C) := rfl @[simp] theorem MonadHom.comp_toNatTrans {T₁ T₂ T₃ : Monad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) : (f ≫ g).toNatTrans = ((f.toNatTrans : _ ⟶ (T₂ : C ⥤ C)) ≫ g.toNatTrans : (T₁ : C ⥤ C) ⟶ T₃) := rfl instance {G : Comonad C} : Inhabited (ComonadHom G G) := ⟨𝟙 G⟩ @[simp] theorem ComonadHom.id_toNatTrans (T : Comonad C) : (𝟙 T : T ⟶ T).toNatTrans = 𝟙 (T : C ⥤ C) := rfl @[simp] theorem comp_toNatTrans {T₁ T₂ T₃ : Comonad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) : (f ≫ g).toNatTrans = ((f.toNatTrans : _ ⟶ (T₂ : C ⥤ C)) ≫ g.toNatTrans : (T₁ : C ⥤ C) ⟶ T₃) := rfl /-- Construct a monad isomorphism from a natural isomorphism of functors where the forward direction is a monad morphism. -/ @[simps] def MonadIso.mk {M N : Monad C} (f : (M : C ⥤ C) ≅ N) (f_η : ∀ (X : C), M.η.app X ≫ f.hom.app X = N.η.app X := by cat_disch) (f_μ : ∀ (X : C), M.μ.app X ≫ f.hom.app X = (M.map (f.hom.app X) ≫ f.hom.app (N.obj X)) ≫ N.μ.app X := by cat_disch) : M ≅ N where hom := { toNatTrans := f.hom app_η := f_η app_μ := f_μ } inv := { toNatTrans := f.inv app_η := fun X => by simp [← f_η] app_μ := fun X => by rw [← NatIso.cancel_natIso_hom_right f] simp only [NatTrans.naturality, Iso.inv_hom_id_app, assoc, comp_id, f_μ, NatTrans.naturality_assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp_assoc] simp } /-- Construct a comonad isomorphism from a natural isomorphism of functors where the forward direction is a comonad morphism. -/ @[simps] def ComonadIso.mk {M N : Comonad C} (f : (M : C ⥤ C) ≅ N) (f_ε : ∀ (X : C), f.hom.app X ≫ N.ε.app X = M.ε.app X := by cat_disch) (f_δ : ∀ (X : C), f.hom.app X ≫ N.δ.app X = M.δ.app X ≫ f.hom.app (M.obj X) ≫ N.map (f.hom.app X) := by cat_disch) : M ≅ N where hom := { toNatTrans := f.hom app_ε := f_ε app_δ := f_δ } inv := { toNatTrans := f.inv app_ε := fun X => by simp [← f_ε] app_δ := fun X => by rw [← NatIso.cancel_natIso_hom_left f] simp only [reassoc_of% (f_δ X), Iso.hom_inv_id_app_assoc, NatTrans.naturality_assoc] rw [← Functor.map_comp, Iso.hom_inv_id_app, Functor.map_id] apply (comp_id _).symm } variable (C) /-- The forgetful functor from the category of monads to the category of endofunctors. -/ @[simps!] def monadToFunctor : Monad C ⥤ C ⥤ C where obj T := T map f := f.toNatTrans instance : (monadToFunctor C).Faithful where theorem monadToFunctor_mapIso_monad_iso_mk {M N : Monad C} (f : (M : C ⥤ C) ≅ N) (f_η f_μ) : (monadToFunctor _).mapIso (MonadIso.mk f f_η f_μ) = f := by ext rfl instance : (monadToFunctor C).ReflectsIsomorphisms where reflects f _ := (MonadIso.mk (asIso ((monadToFunctor C).map f)) f.app_η f.app_μ).isIso_hom /-- The forgetful functor from the category of comonads to the category of endofunctors. -/ @[simps!] def comonadToFunctor : Comonad C ⥤ C ⥤ C where obj G := G map f := f.toNatTrans instance : (comonadToFunctor C).Faithful where theorem comonadToFunctor_mapIso_comonad_iso_mk {M N : Comonad C} (f : (M : C ⥤ C) ≅ N) (f_ε f_δ) : (comonadToFunctor _).mapIso (ComonadIso.mk f f_ε f_δ) = f := by ext rfl instance : (comonadToFunctor C).ReflectsIsomorphisms where reflects f _ := (ComonadIso.mk (asIso ((comonadToFunctor C).map f)) f.app_ε f.app_δ).isIso_hom variable {C} /-- An isomorphism of monads gives a natural isomorphism of the underlying functors. -/ @[simps (rhsMd := .default)] def MonadIso.toNatIso {M N : Monad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N := (monadToFunctor C).mapIso h /-- An isomorphism of comonads gives a natural isomorphism of the underlying functors. -/ @[simps (rhsMd := .default)] def ComonadIso.toNatIso {M N : Comonad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N := (comonadToFunctor C).mapIso h variable (C) namespace Monad /-- The identity monad. -/ @[simps!] def id : Monad C where toFunctor := 𝟭 C η := 𝟙 (𝟭 C) μ := 𝟙 (𝟭 C) instance : Inhabited (Monad C) := ⟨Monad.id C⟩ end Monad namespace Comonad /-- The identity comonad. -/ @[simps!] def id : Comonad C where toFunctor := 𝟭 _ ε := 𝟙 (𝟭 C) δ := 𝟙 (𝟭 C) instance : Inhabited (Comonad C) := ⟨Comonad.id C⟩ end Comonad open Iso Functor variable {C} namespace Monad /-- Transport a monad structure on a functor along an isomorphism of functors. -/ def transport {F : C ⥤ C} (T : Monad C) (i : (T : C ⥤ C) ≅ F) : Monad C where toFunctor := F η := T.η ≫ i.hom μ := (i.inv ◫ i.inv) ≫ T.μ ≫ i.hom left_unit X := by simp only [Functor.id_obj, NatTrans.comp_app, comp_obj, NatTrans.hcomp_app, Category.assoc, hom_inv_id_app_assoc] slice_lhs 1 2 => rw [← T.η.naturality (i.inv.app X), ] simp right_unit X := by simp only [NatTrans.comp_app, Functor.map_comp, comp_obj, NatTrans.hcomp_app, Category.assoc, NatTrans.naturality_assoc] slice_lhs 2 4 => simp only [← T.map_comp] simp assoc X := by simp only [comp_obj, NatTrans.comp_app, NatTrans.hcomp_app, Category.assoc, Functor.map_comp, NatTrans.naturality_assoc, hom_inv_id_app_assoc, NatIso.cancel_natIso_inv_left] slice_lhs 4 5 => rw [← T.map_comp] simp only [hom_inv_id_app, Functor.map_id, id_comp] slice_lhs 1 2 => rw [← T.map_comp] simp only [Functor.map_comp, Category.assoc] congr 1 simp only [← Category.assoc, NatIso.cancel_natIso_hom_right] rw [← T.μ.naturality] simp [T.assoc X] end Monad namespace Comonad /-- Transport a comonad structure on a functor along an isomorphism of functors. -/ def transport {F : C ⥤ C} (T : Comonad C) (i : (T : C ⥤ C) ≅ F) : Comonad C where toFunctor := F ε := i.inv ≫ T.ε δ := i.inv ≫ T.δ ≫ (i.hom ◫ i.hom) right_counit X := by simp only [comp_obj, NatTrans.comp_app, NatTrans.hcomp_app, Functor.map_comp, assoc] slice_lhs 4 5 => rw [← F.map_comp] simp only [hom_inv_id_app, Functor.map_id, id_comp, ← i.hom.naturality] slice_lhs 2 3 => rw [T.right_counit] simp coassoc X := by simp only [comp_obj, NatTrans.comp_app, NatTrans.hcomp_app, Functor.map_comp, assoc, NatTrans.naturality_assoc, Functor.comp_map, hom_inv_id_app_assoc, NatIso.cancel_natIso_inv_left] slice_lhs 3 4 => rw [← F.map_comp] simp only [hom_inv_id_app, Functor.map_id, id_comp, assoc] rw [← i.hom.naturality_assoc, ← T.coassoc_assoc] simp only [NatTrans.naturality_assoc] congr 3 simp only [← Functor.map_comp, i.hom.naturality] end Comonad namespace Monad lemma map_unit_app (T : Monad C) (X : C) [IsIso T.μ] : T.map (T.η.app X) = T.η.app (T.obj X) := by simp [← cancel_mono (T.μ.app _)] lemma isSplitMono_iff_isIso_unit (T : Monad C) (X : C) [IsIso T.μ] : IsSplitMono (T.η.app X) ↔ IsIso (T.η.app X) := by refine ⟨fun _ ↦ ⟨retraction (T.η.app X), by simp, ?_⟩, fun _ ↦ inferInstance⟩ rw [← map_id, ← show T.η.app X ≫ retraction (T.η.app X) = 𝟙 X from IsSplitMono.id _, map_comp, T.map_unit_app X, ← T.unit_naturality] end Monad namespace Comonad lemma map_counit_app (T : Comonad C) (X : C) [IsIso T.δ] : T.map (T.ε.app X) = T.ε.app (T.obj X) := by simp [← cancel_epi (T.δ.app _)] lemma isSplitEpi_iff_isIso_counit (T : Comonad C) (X : C) [IsIso T.δ] : IsSplitEpi (T.ε.app X) ↔ IsIso (T.ε.app X) := by refine ⟨fun _ ↦ ⟨section_ (T.ε.app X), ?_, by simp⟩, fun _ ↦ inferInstance⟩ rw [← map_id, ← show section_ (T.ε.app X) ≫ T.ε.app X = 𝟙 X from IsSplitEpi.id (T.ε.app X), map_comp, T.map_counit_app X, T.counit_naturality] end Comonad end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Comonadicity.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Reflexive import Mathlib.CategoryTheory.Monad.Equalizer import Mathlib.CategoryTheory.Monad.Limits /-! # Comonadicity theorems We prove comonadicity theorems which can establish a given functor is comonadic. In particular, we show three versions of Beck's comonadicity theorem, and the coreflexive (crude) comonadicity theorem: `F` is a comonadic left adjoint if it has a right adjoint, and: * `C` has, `F` preserves and reflects `F`-split equalizers, see `CategoryTheory.Monad.comonadicOfHasPreservesReflectsFSplitEqualizers` * `F` creates `F`-split coequalizers, see `CategoryTheory.Monad.comonadicOfCreatesFSplitEqualizers` (The converse of this is also shown, see `CategoryTheory.Monad.createsFSplitEqualizersOfComonadic`) * `C` has and `F` preserves `F`-split equalizers, and `F` reflects isomorphisms, see `CategoryTheory.Monad.comonadicOfHasPreservesFSplitEqualizersOfReflectsIsomorphisms` * `C` has and `F` preserves coreflexive equalizers, and `F` reflects isomorphisms, see `CategoryTheory.Monad.comonadicOfHasPreservesCoreflexiveEqualizersOfReflectsIsomorphisms` This file has been adapted from `Mathlib/CategoryTheory/Monad/Monadicity.lean`. Please try to keep them in sync. ## Tags Beck, comonadicity, descent -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory namespace Comonad open Limits noncomputable section -- Hide the implementation details in this namespace. namespace ComonadicityInternal variable {C : Type u₁} {D : Type u₂} variable [Category.{v₁} C] [Category.{v₁} D] variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) /-- The "main pair" for a coalgebra `(A, α)` is the pair of morphisms `(G α, η_GA)`. It is always a coreflexive pair, and will be used to construct the left adjoint to the comparison functor and show it is an equivalence. -/ instance main_pair_coreflexive (A : adj.toComonad.Coalgebra) : IsCoreflexivePair (G.map A.a) (adj.unit.app (G.obj A.A)) := by apply IsCoreflexivePair.mk' (G.map (adj.counit.app _)) _ _ · rw [← G.map_comp, ← G.map_id] exact congr_arg G.map A.counit · rw [adj.right_triangle_components] rfl /-- The "main pair" for a coalgebra `(A, α)` is the pair of morphisms `(G α, η_GA)`. It is always a `G`-cosplit pair, and will be used to construct the right adjoint to the comparison functor and show it is an equivalence. -/ instance main_pair_F_cosplit (A : adj.toComonad.Coalgebra) : F.IsCosplitPair (G.map A.a) (adj.unit.app (G.obj A.A)) where splittable := ⟨_, _, ⟨beckSplitEqualizer A⟩⟩ /-- The object function for the right adjoint to the comparison functor. -/ def comparisonRightAdjointObj (A : adj.toComonad.Coalgebra) [HasEqualizer (G.map A.a) (adj.unit.app _)] : C := equalizer (G.map A.a) (adj.unit.app _) /-- We have a bijection of homsets which will be used to construct the right adjoint to the comparison functor. -/ @[simps!] def comparisonRightAdjointHomEquiv (A : adj.toComonad.Coalgebra) (B : C) [HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] : ((comparison adj).obj B ⟶ A) ≃ (B ⟶ comparisonRightAdjointObj adj A) where toFun f := by refine equalizer.lift (adj.homEquiv _ _ f.f) ?_ simp only [Adjunction.toComonad_coe, Functor.comp_obj, Adjunction.homEquiv_unit, Category.assoc, ← G.map_comp, ← f.h, comparison_obj_A, comparison_obj_a] rw [Functor.comp_map, Functor.map_comp, Adjunction.unit_naturality_assoc, Adjunction.unit_naturality] invFun f := by refine ⟨(adj.homEquiv _ _).symm (f ≫ (equalizer.ι _ _)), (adj.homEquiv _ _).injective ?_⟩ simp only [Adjunction.toComonad_coe, Functor.comp_obj, comparison_obj_A, comparison_obj_a, Adjunction.homEquiv_counit, Functor.map_comp, Category.assoc, Functor.comp_map, Adjunction.homEquiv_unit, Adjunction.unit_naturality_assoc, Adjunction.unit_naturality, Adjunction.right_triangle_components_assoc] congr 1 exact (equalizer.condition _ _).symm left_inv f := by aesop right_inv f := by apply equalizer.hom_ext; simp /-- Construct the adjunction to the comparison functor. -/ def rightAdjointComparison [∀ A : adj.toComonad.Coalgebra, HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] : adj.toComonad.Coalgebra ⥤ C := by refine Adjunction.rightAdjointOfEquiv (F := comparison adj) (G_obj := fun A => comparisonRightAdjointObj adj A) (fun A B => ?_) ?_ · apply comparisonRightAdjointHomEquiv · intro A B B' g h apply equalizer.hom_ext simp [Adjunction.homEquiv_unit] /-- Provided we have the appropriate equalizers, we have an adjunction to the comparison functor. -/ @[simps! counit] def comparisonAdjunction [∀ A : adj.toComonad.Coalgebra, HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] : comparison adj ⊣ rightAdjointComparison adj := Adjunction.adjunctionOfEquivRight _ _ variable {adj} theorem comparisonAdjunction_counit_f_aux [∀ A : adj.toComonad.Coalgebra, HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] (A : adj.toComonad.Coalgebra) : ((comparisonAdjunction adj).counit.app A).f = (adj.homEquiv _ A.A).symm (equalizer.ι (G.map A.a) (adj.unit.app (G.obj A.A))) := congr_arg (adj.homEquiv _ _).symm (Category.id_comp _) /-- This is a fork which is helpful for establishing comonadicity: the morphism from this fork to the Beck equalizer is the counit for the adjunction on the comparison functor. -/ @[simps! pt] def counitFork (A : adj.toComonad.Coalgebra) [HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] : Fork (F.map (G.map A.a)) (F.map (adj.unit.app (G.obj A.A))) := Fork.ofι (F.map (equalizer.ι (G.map A.a) (adj.unit.app (G.obj A.A)))) (by rw [← F.map_comp, equalizer.condition, F.map_comp]) @[simp] theorem unitFork_ι (A : adj.toComonad.Coalgebra) [HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] : (counitFork A).ι = F.map (equalizer.ι (G.map A.a) (adj.unit.app (G.obj A.A))) := rfl theorem comparisonAdjunction_counit_f [∀ A : adj.toComonad.Coalgebra, HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] (A : adj.toComonad.Coalgebra) : ((comparisonAdjunction adj).counit.app A).f = (beckEqualizer A).lift (counitFork A) := by simp [Adjunction.homEquiv_counit] variable (adj) /-- The fork which describes the unit of the adjunction: the morphism from this fork to the the equalizer of this pair is the unit. -/ @[simps!] def unitFork (B : C) : Fork (G.map (F.map (adj.unit.app B))) (adj.unit.app (G.obj (F.obj B))) := Fork.ofι (adj.unit.app B) (adj.unit_naturality _) variable {adj} in /-- The counit fork is a limit provided `F` preserves it. -/ def counitLimitOfPreservesEqualizer (A : adj.toComonad.Coalgebra) [HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] [PreservesLimit (parallelPair (G.map A.a) (adj.unit.app (G.obj A.A))) F] : IsLimit (counitFork (G := G) A) := isLimitOfHasEqualizerOfPreservesLimit F _ _ /-- The unit fork is a limit provided `F` coreflects it. -/ def unitEqualizerOfCoreflectsEqualizer (B : C) [ReflectsLimit (parallelPair (G.map (F.map (adj.unit.app B))) (adj.unit.app (G.obj (F.obj B)))) F] : IsLimit (unitFork (adj := adj) B) := isLimitOfIsLimitForkMap F _ (beckEqualizer ((comparison adj).obj B)) instance [∀ A : adj.toComonad.Coalgebra, HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] (B : C) : HasLimit (parallelPair (G.map (F.map (NatTrans.app adj.unit B))) (NatTrans.app adj.unit (G.obj (F.obj B)))) := inferInstanceAs <| HasEqualizer (G.map ((comparison adj).obj B).a) (adj.unit.app (G.obj ((comparison adj).obj B).A)) theorem comparisonAdjunction_unit_app [∀ A : adj.toComonad.Coalgebra, HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A))] (B : C) : (comparisonAdjunction adj).unit.app B = limit.lift _ (unitFork adj B) := by apply equalizer.hom_ext change equalizer.lift ((adj.homEquiv B _) (𝟙 _)) _ ≫ equalizer.ι _ _ = equalizer.lift _ _ ≫ equalizer.ι _ _ simp [Adjunction.homEquiv_unit] end ComonadicityInternal open CategoryTheory Adjunction Comonad ComonadicityInternal variable {C : Type u₁} {D : Type u₂} variable [Category.{v₁} C] [Category.{v₁} D] variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) variable (G) in /-- If `F` is comonadic, it creates limits of `F`-cosplit pairs. This is the "boring" direction of Beck's comonadicity theorem, the converse is given in `comonadicOfCreatesFSplitEqualizers`. -/ def createsFSplitEqualizersOfComonadic [ComonadicLeftAdjoint F] ⦃A B⦄ (f g : A ⟶ B) [F.IsCosplitPair f g] : CreatesLimit (parallelPair f g) F := by apply (config := {allowSynthFailures := true}) comonadicCreatesLimitOfPreservesLimit all_goals apply @preservesLimit_of_iso_diagram _ _ _ _ _ _ _ _ _ (diagramIsoParallelPair.{v₁} _).symm ?_ dsimp infer_instance section BeckComonadicity /-- Dual to `Monad.HasCoequalizerOfIsSplitPair`. -/ class HasEqualizerOfIsCosplitPair (F : C ⥤ D) : Prop where /-- If `f, g` is an `F`-cosplit pair, then they have an equalizer. -/ out : ∀ {A B} (f g : A ⟶ B) [F.IsCosplitPair f g], HasEqualizer f g instance [HasEqualizerOfIsCosplitPair F] : ∀ (A : Coalgebra adj.toComonad), HasEqualizer (G.map A.a) (adj.unit.app (G.obj A.A)) := fun _ => HasEqualizerOfIsCosplitPair.out F _ _ /-- Dual to `Monad.PreservesColimitOfIsSplitPair`. -/ class PreservesLimitOfIsCosplitPair (F : C ⥤ D) where /-- If `f, g` is an `F`-cosplit pair, then `F` preserves limits of `parallelPair f g`. -/ out : ∀ {A B} (f g : A ⟶ B) [F.IsCosplitPair f g], PreservesLimit (parallelPair f g) F instance {A B} (f g : A ⟶ B) [F.IsCosplitPair f g] [PreservesLimitOfIsCosplitPair F] : PreservesLimit (parallelPair f g) F := PreservesLimitOfIsCosplitPair.out f g instance [PreservesLimitOfIsCosplitPair F] : ∀ (A : Coalgebra adj.toComonad), PreservesLimit (parallelPair (G.map A.a) (NatTrans.app adj.unit (G.obj A.A))) F := fun _ => PreservesLimitOfIsCosplitPair.out _ _ /-- Dual to `Monad.ReflectsColimitOfIsSplitPair`. -/ class ReflectsLimitOfIsCosplitPair (F : C ⥤ D) where /-- If `f, g` is an `F`-cosplit pair, then `F` reflects limits for `parallelPair f g`. -/ out : ∀ {A B} (f g : A ⟶ B) [F.IsCosplitPair f g], ReflectsLimit (parallelPair f g) F instance {A B} (f g : A ⟶ B) [F.IsCosplitPair f g] [ReflectsLimitOfIsCosplitPair F] : ReflectsLimit (parallelPair f g) F := ReflectsLimitOfIsCosplitPair.out f g instance [ReflectsLimitOfIsCosplitPair F] : ∀ (A : Coalgebra adj.toComonad), ReflectsLimit (parallelPair (G.map A.a) (NatTrans.app adj.unit (G.obj A.A))) F := fun _ => ReflectsLimitOfIsCosplitPair.out _ _ /-- To show `F` is a comonadic left adjoint, we can show it preserves and reflects `F`-split equalizers, and `C` has them. -/ def comonadicOfHasPreservesReflectsFSplitEqualizers [HasEqualizerOfIsCosplitPair F] [PreservesLimitOfIsCosplitPair F] [ReflectsLimitOfIsCosplitPair F] : ComonadicLeftAdjoint F where R := G adj := adj eqv := by have : ∀ (X : Coalgebra adj.toComonad), IsIso ((comparisonAdjunction adj).counit.app X) := by intro X apply @isIso_of_reflects_iso _ _ _ _ _ _ _ (Comonad.forget adj.toComonad) ?_ _ · change IsIso ((comparisonAdjunction adj).counit.app X).f rw [comparisonAdjunction_counit_f] change IsIso (IsLimit.conePointUniqueUpToIso (beckEqualizer X) (counitLimitOfPreservesEqualizer X)).inv exact (IsLimit.conePointUniqueUpToIso _ _).isIso_inv have : ∀ (Y : C), IsIso ((comparisonAdjunction adj).unit.app Y) := by intro Y rw [comparisonAdjunction_unit_app] change IsIso (IsLimit.conePointUniqueUpToIso _ ?_).inv · infer_instance apply @unitEqualizerOfCoreflectsEqualizer _ _ _ _ _ _ _ _ ?_ letI _ : F.IsCosplitPair (G.map (F.map (adj.unit.app Y))) (adj.unit.app (G.obj (F.obj Y))) := ComonadicityInternal.main_pair_F_cosplit _ ((comparison adj).obj Y) infer_instance exact (comparisonAdjunction adj).toEquivalence.symm.isEquivalence_inverse /-- Dual to `Monad.CreatesColimitOfIsSplitPair`. -/ class CreatesLimitOfIsCosplitPair (F : C ⥤ D) where /-- If `f, g` is an `F`-cosplit pair, then `F` creates limits of `parallelPair f g`. -/ out : ∀ {A B} (f g : A ⟶ B) [F.IsCosplitPair f g], CreatesLimit (parallelPair f g) F instance {A B} (f g : A ⟶ B) [F.IsCosplitPair f g] [CreatesLimitOfIsCosplitPair F] : CreatesLimit (parallelPair f g) F := CreatesLimitOfIsCosplitPair.out f g instance [CreatesLimitOfIsCosplitPair F] : ∀ (A : Coalgebra adj.toComonad), CreatesLimit (parallelPair (G.map A.a) (NatTrans.app adj.unit (G.obj A.A))) F := fun _ => CreatesLimitOfIsCosplitPair.out _ _ /-- Beck's comonadicity theorem. If `F` has a right adjoint and creates equalizers of `F`-cosplit pairs, then it is comonadic. This is the converse of `createsFSplitEqualizersOfComonadic`. -/ def comonadicOfCreatesFSplitEqualizers [CreatesLimitOfIsCosplitPair F] : ComonadicLeftAdjoint F := by have I {A B} (f g : A ⟶ B) [F.IsCosplitPair f g] : HasLimit (parallelPair f g ⋙ F) := by rw [hasLimit_iff_of_iso (diagramIsoParallelPair _)] exact inferInstanceAs <| HasEqualizer (F.map f) (F.map g) have : HasEqualizerOfIsCosplitPair F := ⟨fun _ _ => hasLimit_of_created (parallelPair _ _) F⟩ have : PreservesLimitOfIsCosplitPair F := ⟨by intros; infer_instance⟩ have : ReflectsLimitOfIsCosplitPair F := ⟨by intros; infer_instance⟩ exact comonadicOfHasPreservesReflectsFSplitEqualizers adj /-- An alternate version of Beck's comonadicity theorem. If `F` reflects isomorphisms, preserves equalizers of `F`-cosplit pairs and `C` has equalizers of `F`-cosplit pairs, then it is comonadic. -/ def comonadicOfHasPreservesFSplitEqualizersOfReflectsIsomorphisms [F.ReflectsIsomorphisms] [HasEqualizerOfIsCosplitPair F] [PreservesLimitOfIsCosplitPair F] : ComonadicLeftAdjoint F := by have : ReflectsLimitOfIsCosplitPair F := ⟨fun f g _ => by have := HasEqualizerOfIsCosplitPair.out F f g apply reflectsLimit_of_reflectsIsomorphisms⟩ apply comonadicOfHasPreservesReflectsFSplitEqualizers adj end BeckComonadicity section CoreflexiveComonadicity variable [HasCoreflexiveEqualizers C] [F.ReflectsIsomorphisms] /-- Dual to `Monad.PreservesColimitOfIsReflexivePair`. -/ class PreservesLimitOfIsCoreflexivePair (F : C ⥤ D) where /-- `f, g` is a coreflexive pair, then `F` preserves limits of `parallelPair f g`. -/ out : ∀ ⦃A B⦄ (f g : A ⟶ B) [IsCoreflexivePair f g], PreservesLimit (parallelPair f g) F instance {A B} (f g : A ⟶ B) [IsCoreflexivePair f g] [PreservesLimitOfIsCoreflexivePair F] : PreservesLimit (parallelPair f g) F := PreservesLimitOfIsCoreflexivePair.out f g instance [PreservesLimitOfIsCoreflexivePair F] : ∀ X : Coalgebra adj.toComonad, PreservesLimit (parallelPair (G.map X.a) (NatTrans.app adj.unit (G.obj X.A))) F := fun _ => PreservesLimitOfIsCoreflexivePair.out _ _ variable [PreservesLimitOfIsCoreflexivePair F] /-- Coreflexive (crude) comonadicity theorem. If `F` has a right adjoint, `C` has and `F` preserves coreflexive equalizers and `F` reflects isomorphisms, then `F` is comonadic. -/ def comonadicOfHasPreservesCoreflexiveEqualizersOfReflectsIsomorphisms : ComonadicLeftAdjoint F where R := G adj := adj eqv := by have : ∀ (X : adj.toComonad.Coalgebra), IsIso ((comparisonAdjunction adj).counit.app X) := by intro X apply @isIso_of_reflects_iso _ _ _ _ _ _ _ (Comonad.forget adj.toComonad) ?_ _ · change IsIso ((comparisonAdjunction adj).counit.app X).f rw [comparisonAdjunction_counit_f] exact (IsLimit.conePointUniqueUpToIso (beckEqualizer X) (counitLimitOfPreservesEqualizer X)).isIso_inv have : ∀ (Y : C), IsIso ((comparisonAdjunction adj).unit.app Y) := by intro Y rw [comparisonAdjunction_unit_app] change IsIso (IsLimit.conePointUniqueUpToIso _ ?_).inv · infer_instance have : IsCoreflexivePair (G.map (F.map (adj.unit.app Y))) (adj.unit.app (G.obj (F.obj Y))) := by apply IsCoreflexivePair.mk' (G.map (adj.counit.app _)) _ _ · rw [← G.map_comp, ← G.map_id] exact congr_arg G.map (adj.left_triangle_components Y) · rw [← G.map_id] simp apply @unitEqualizerOfCoreflectsEqualizer _ _ _ _ _ _ _ _ ?_ apply reflectsLimit_of_reflectsIsomorphisms exact (comparisonAdjunction adj).toEquivalence.symm.isEquivalence_inverse end CoreflexiveComonadicity end end Comonad end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/EquivMon.lean
import Mathlib.CategoryTheory.Monad.Basic import Mathlib.CategoryTheory.Monoidal.End import Mathlib.CategoryTheory.Monoidal.Mon_ /-! # The equivalence between `Monad C` and `Mon (C ⥤ C)`. A monad "is just" a monoid in the category of endofunctors. ## Definitions/Theorems 1. `toMon` associates a monoid object in `C ⥤ C` to any monad on `C`. 2. `monadToMon` is the functorial version of `toMon`. 3. `ofMon` associates a monad on `C` to any monoid object in `C ⥤ C`. 4. `monadMonEquiv` is the equivalence between `Monad C` and `Mon (C ⥤ C)`. -/ namespace CategoryTheory open Category MonObj universe v u -- morphism levels before object levels. See note [category_theory universes]. variable {C : Type u} [Category.{v} C] namespace Monad attribute [local instance] endofunctorMonoidalCategory @[simps] instance (M : Monad C) : MonObj (M : C ⥤ C) where one := M.η mul := M.μ mul_assoc := by ext; simp [M.assoc] /-- To every `Monad C` we associated a monoid object in `C ⥤ C`. -/ @[simps] def toMon (M : Monad C) : Mon (C ⥤ C) where X := (M : C ⥤ C) variable (C) in /-- Passing from `Monad C` to `Mon (C ⥤ C)` is functorial. -/ @[simps] def monadToMon : Monad C ⥤ Mon (C ⥤ C) where obj := toMon map f := .mk' f.toNatTrans /-- To every monoid object in `C ⥤ C` we associate a `Monad C`. -/ @[simps «η» «μ»] def ofMon (M : Mon (C ⥤ C)) : Monad C where toFunctor := M.X «η» := η[M.X] «μ» := μ[M.X] left_unit := fun X => by simpa [-MonObj.mul_one] using congrArg (fun t ↦ t.app X) (mul_one M.X) right_unit := fun X => by simpa [-MonObj.one_mul] using congrArg (fun t ↦ t.app X) (one_mul M.X) assoc := fun X => by simpa [-MonObj.mul_assoc] using congrArg (fun t ↦ t.app X) (mul_assoc M.X) -- Porting note: `@[simps]` fails to generate `ofMon_obj`: @[simp] lemma ofMon_obj (M : Mon (C ⥤ C)) (X : C) : (ofMon M).obj X = M.X.obj X := rfl variable (C) /-- Passing from `Mon (C ⥤ C)` to `Monad C` is functorial. -/ @[simps] def monToMonad : Mon (C ⥤ C) ⥤ Monad C where obj := ofMon map {X Y} f := { f.hom with app_η X := by simpa [-IsMonHom.one_hom] using congrArg (fun t ↦ t.app X) (IsMonHom.one_hom f.hom) app_μ Z := by simpa [-IsMonHom.mul_hom] using congrArg (fun t ↦ t.app Z) (IsMonHom.mul_hom f.hom) } /-- Oh, monads are just monoids in the category of endofunctors (equivalence of categories). -/ @[simps] def monadMonEquiv : Monad C ≌ Mon (C ⥤ C) where functor := monadToMon _ inverse := monToMonad _ unitIso := { hom := { app := fun _ => { app := fun _ => 𝟙 _ } } inv := { app := fun _ => { app := fun _ => 𝟙 _ } } } counitIso := { hom := { app := fun _ => { hom := 𝟙 _ } } inv := { app := fun _ => { hom := 𝟙 _ } } } -- Sanity check example (A : Monad C) {X : C} : ((monadMonEquiv C).unitIso.app A).hom.app X = 𝟙 _ := rfl end Monad end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Adjunction.lean
import Mathlib.CategoryTheory.Adjunction.Reflective import Mathlib.CategoryTheory.Monad.Algebra /-! # Adjunctions and (co)monads We develop the basic relationship between adjunctions and (co)monads. Given an adjunction `h : L ⊣ R`, we have `h.toMonad : Monad C` and `h.toComonad : Comonad D`. We then have `Monad.comparison (h : L ⊣ R) : D ⥤ h.toMonad.algebra` sending `Y : D` to the Eilenberg-Moore algebra for `L ⋙ R` with underlying object `R.obj X`, and dually `Comonad.comparison`. We say `R : D ⥤ C` is `MonadicRightAdjoint`, if it is a right adjoint and its `Monad.comparison` is an equivalence of categories. (Similarly for `ComonadicLeftAdjoint`.) Finally we prove that reflective functors are `MonadicRightAdjoint` and coreflective functors are `ComonadicLeftAdjoint`. -/ namespace CategoryTheory open Category Functor universe v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes]. variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] variable {L : C ⥤ D} {R : D ⥤ C} namespace Adjunction /-- For a pair of functors `L : C ⥤ D`, `R : D ⥤ C`, an adjunction `h : L ⊣ R` induces a monad on the category `C`. -/ @[simps! coe η μ] def toMonad (h : L ⊣ R) : Monad C where toFunctor := L ⋙ R η := h.unit μ := whiskerRight (whiskerLeft L h.counit) R assoc X := by dsimp rw [← R.map_comp] simp right_unit X := by dsimp rw [← R.map_comp] simp /-- For a pair of functors `L : C ⥤ D`, `R : D ⥤ C`, an adjunction `h : L ⊣ R` induces a comonad on the category `D`. -/ @[simps coe ε δ] def toComonad (h : L ⊣ R) : Comonad D where toFunctor := R ⋙ L ε := h.counit δ := whiskerRight (whiskerLeft R h.unit) L coassoc X := by dsimp rw [← L.map_comp] simp right_counit X := by dsimp rw [← L.map_comp] simp /-- The monad induced by the Eilenberg-Moore adjunction is the original monad. -/ @[simps!] def adjToMonadIso (T : Monad C) : T.adj.toMonad ≅ T := MonadIso.mk (NatIso.ofComponents fun _ => Iso.refl _) /-- The comonad induced by the Eilenberg-Moore adjunction is the original comonad. -/ @[simps!] def adjToComonadIso (G : Comonad C) : G.adj.toComonad ≅ G := ComonadIso.mk (NatIso.ofComponents fun _ => Iso.refl _) /-- Given an adjunction `L ⊣ R`, if `L ⋙ R` is abstractly isomorphic to the identity functor, then the unit is an isomorphism. -/ def unitAsIsoOfIso (adj : L ⊣ R) (i : L ⋙ R ≅ 𝟭 C) : 𝟭 C ≅ L ⋙ R where hom := adj.unit inv := i.hom ≫ (adj.toMonad.transport i).μ hom_inv_id := by rw [← assoc] ext X exact (adj.toMonad.transport i).right_unit X inv_hom_id := by rw [assoc, ← Iso.eq_inv_comp, comp_id, ← id_comp i.inv, Iso.eq_comp_inv, assoc, NatTrans.id_comm] ext X exact (adj.toMonad.transport i).right_unit X lemma isIso_unit_of_iso (adj : L ⊣ R) (i : L ⋙ R ≅ 𝟭 C) : IsIso adj.unit := (inferInstanceAs (IsIso (unitAsIsoOfIso adj i).hom)) /-- Given an adjunction `L ⊣ R`, if `L ⋙ R` is isomorphic to the identity functor, then `L` is fully faithful. -/ noncomputable def fullyFaithfulLOfCompIsoId (adj : L ⊣ R) (i : L ⋙ R ≅ 𝟭 C) : L.FullyFaithful := haveI := adj.isIso_unit_of_iso i adj.fullyFaithfulLOfIsIsoUnit /-- Given an adjunction `L ⊣ R`, if `R ⋙ L` is abstractly isomorphic to the identity functor, then the counit is an isomorphism. -/ def counitAsIsoOfIso (adj : L ⊣ R) (j : R ⋙ L ≅ 𝟭 D) : R ⋙ L ≅ 𝟭 D where hom := adj.counit inv := (adj.toComonad.transport j).δ ≫ j.inv hom_inv_id := by rw [← assoc, Iso.comp_inv_eq, id_comp, ← comp_id j.hom, ← Iso.inv_comp_eq, ← assoc, NatTrans.id_comm] ext X exact (adj.toComonad.transport j).right_counit X inv_hom_id := by rw [assoc] ext X exact (adj.toComonad.transport j).right_counit X lemma isIso_counit_of_iso (adj : L ⊣ R) (j : R ⋙ L ≅ 𝟭 D) : IsIso adj.counit := inferInstanceAs (IsIso (counitAsIsoOfIso adj j).hom) /-- Given an adjunction `L ⊣ R`, if `R ⋙ L` is isomorphic to the identity functor, then `R` is fully faithful. -/ noncomputable def fullyFaithfulROfCompIsoId (adj : L ⊣ R) (j : R ⋙ L ≅ 𝟭 D) : R.FullyFaithful := haveI := adj.isIso_counit_of_iso j adj.fullyFaithfulROfIsIsoCounit end Adjunction /-- Given any adjunction `L ⊣ R`, there is a comparison functor `CategoryTheory.Monad.comparison R` sending objects `Y : D` to Eilenberg-Moore algebras for `L ⋙ R` with underlying object `R.obj X`. We later show that this is full when `R` is full, faithful when `R` is faithful, and essentially surjective when `R` is reflective. -/ @[simps] def Monad.comparison (h : L ⊣ R) : D ⥤ h.toMonad.Algebra where obj X := { A := R.obj X a := R.map (h.counit.app X) assoc := by dsimp rw [← R.map_comp, ← Adjunction.counit_naturality, R.map_comp] } map f := { f := R.map f h := by dsimp rw [← R.map_comp, Adjunction.counit_naturality, R.map_comp] } /-- The underlying object of `(Monad.comparison R).obj X` is just `R.obj X`. -/ @[simps] def Monad.comparisonForget (h : L ⊣ R) : Monad.comparison h ⋙ h.toMonad.forget ≅ R where hom := { app := fun _ => 𝟙 _ } inv := { app := fun _ => 𝟙 _ } theorem Monad.left_comparison (h : L ⊣ R) : L ⋙ Monad.comparison h = h.toMonad.free := rfl instance [R.Faithful] (h : L ⊣ R) : (Monad.comparison h).Faithful where map_injective {_ _} _ _ w := R.map_injective (congr_arg Monad.Algebra.Hom.f w :) instance (T : Monad C) : (Monad.comparison T.adj).Full where map_surjective {_ _} f := ⟨⟨f.f, by simpa using f.h⟩, rfl⟩ instance (T : Monad C) : (Monad.comparison T.adj).EssSurj where mem_essImage X := ⟨{ A := X.A a := X.a unit := by simpa using X.unit assoc := by simpa using X.assoc }, ⟨Monad.Algebra.isoMk (Iso.refl _)⟩⟩ /-- Given any adjunction `L ⊣ R`, there is a comparison functor `CategoryTheory.Comonad.comparison L` sending objects `X : C` to Eilenberg-Moore coalgebras for `L ⋙ R` with underlying object `L.obj X`. -/ @[simps] def Comonad.comparison (h : L ⊣ R) : C ⥤ h.toComonad.Coalgebra where obj X := { A := L.obj X a := L.map (h.unit.app X) coassoc := by dsimp rw [← L.map_comp, ← Adjunction.unit_naturality, L.map_comp] } map f := { f := L.map f h := by dsimp rw [← L.map_comp] simp } /-- The underlying object of `(Comonad.comparison L).obj X` is just `L.obj X`. -/ @[simps] def Comonad.comparisonForget {L : C ⥤ D} {R : D ⥤ C} (h : L ⊣ R) : Comonad.comparison h ⋙ h.toComonad.forget ≅ L where hom := { app := fun _ => 𝟙 _ } inv := { app := fun _ => 𝟙 _ } theorem Comonad.left_comparison (h : L ⊣ R) : R ⋙ Comonad.comparison h = h.toComonad.cofree := rfl instance Comonad.comparison_faithful_of_faithful [L.Faithful] (h : L ⊣ R) : (Comonad.comparison h).Faithful where map_injective {_ _} _ _ w := L.map_injective (congr_arg Comonad.Coalgebra.Hom.f w :) instance (G : Comonad C) : (Comonad.comparison G.adj).Full where map_surjective f := ⟨⟨f.f, by simpa using f.h⟩, rfl⟩ instance (G : Comonad C) : (Comonad.comparison G.adj).EssSurj where mem_essImage X := ⟨{ A := X.A a := X.a counit := by simpa using X.counit coassoc := by simpa using X.coassoc }, ⟨Comonad.Coalgebra.isoMk (Iso.refl _)⟩⟩ /-- A right adjoint functor `R : D ⥤ C` is *monadic* if the comparison functor `Monad.comparison R` from `D` to the category of Eilenberg-Moore algebras for the adjunction is an equivalence. -/ class MonadicRightAdjoint (R : D ⥤ C) where /-- a choice of left adjoint for `R` -/ L : C ⥤ D /-- `R` is a right adjoint -/ adj : L ⊣ R eqv : (Monad.comparison adj).IsEquivalence /-- The left adjoint functor to `R` given by `[MonadicRightAdjoint R]`. -/ def monadicLeftAdjoint (R : D ⥤ C) [MonadicRightAdjoint R] : C ⥤ D := MonadicRightAdjoint.L (R := R) /-- The adjunction `monadicLeftAdjoint R ⊣ R` given by `[MonadicRightAdjoint R]`. -/ def monadicAdjunction (R : D ⥤ C) [MonadicRightAdjoint R] : monadicLeftAdjoint R ⊣ R := MonadicRightAdjoint.adj instance (R : D ⥤ C) [MonadicRightAdjoint R] : (Monad.comparison (monadicAdjunction R)).IsEquivalence := MonadicRightAdjoint.eqv instance (R : D ⥤ C) [MonadicRightAdjoint R] : R.IsRightAdjoint := (monadicAdjunction R).isRightAdjoint noncomputable instance (T : Monad C) : MonadicRightAdjoint T.forget where L := T.free adj := T.adj eqv := { } /-- A left adjoint functor `L : C ⥤ D` is *comonadic* if the comparison functor `Comonad.comparison L` from `C` to the category of Eilenberg-Moore algebras for the adjunction is an equivalence. -/ class ComonadicLeftAdjoint (L : C ⥤ D) where /-- a choice of right adjoint for `L` -/ R : D ⥤ C /-- `L` is a left adjoint -/ adj : L ⊣ R eqv : (Comonad.comparison adj).IsEquivalence /-- The right adjoint functor to `L` given by `[ComonadicLeftAdjoint L]`. -/ def comonadicRightAdjoint (L : C ⥤ D) [ComonadicLeftAdjoint L] : D ⥤ C := ComonadicLeftAdjoint.R (L := L) /-- The adjunction `L ⊣ comonadicRightAdjoint L` given by `[ComonadicLeftAdjoint L]`. -/ def comonadicAdjunction (L : C ⥤ D) [ComonadicLeftAdjoint L] : L ⊣ comonadicRightAdjoint L := ComonadicLeftAdjoint.adj instance (L : C ⥤ D) [ComonadicLeftAdjoint L] : (Comonad.comparison (comonadicAdjunction L)).IsEquivalence := ComonadicLeftAdjoint.eqv instance (L : C ⥤ D) [ComonadicLeftAdjoint L] : L.IsLeftAdjoint := (comonadicAdjunction L).isLeftAdjoint noncomputable instance (G : Comonad C) : ComonadicLeftAdjoint G.forget where R := G.cofree adj := G.adj eqv := { } -- TODO: This holds more generally for idempotent adjunctions, not just reflective adjunctions. instance μ_iso_of_reflective [Reflective R] : IsIso (reflectorAdjunction R).toMonad.μ := by dsimp infer_instance instance δ_iso_of_coreflective [Coreflective R] : IsIso (coreflectorAdjunction R).toComonad.δ := by dsimp infer_instance attribute [instance] MonadicRightAdjoint.eqv attribute [instance] ComonadicLeftAdjoint.eqv namespace Reflective instance [Reflective R] (X : (reflectorAdjunction R).toMonad.Algebra) : IsIso ((reflectorAdjunction R).unit.app X.A) := ⟨⟨X.a, ⟨X.unit, by dsimp only [Functor.id_obj] rw [← (reflectorAdjunction R).unit_naturality] dsimp only [Functor.comp_obj, Adjunction.toMonad_coe] rw [unit_obj_eq_map_unit, ← Functor.map_comp, ← Functor.map_comp] dsimp [X.unit] simpa using congrArg (fun t ↦ R.map ((reflector R).map t)) X.unit ⟩⟩⟩ instance comparison_essSurj [Reflective R] : (Monad.comparison (reflectorAdjunction R)).EssSurj := by refine ⟨fun X => ⟨(reflector R).obj X.A, ⟨?_⟩⟩⟩ symm refine Monad.Algebra.isoMk ?_ ?_ · exact asIso ((reflectorAdjunction R).unit.app X.A) dsimp only [Functor.comp_map, Monad.comparison_obj_a, asIso_hom, Functor.comp_obj, Monad.comparison_obj_A, Adjunction.toMonad_coe] rw [← cancel_epi ((reflectorAdjunction R).unit.app X.A)] dsimp only [Functor.id_obj, Functor.comp_obj] rw [Adjunction.unit_naturality_assoc, Adjunction.right_triangle_components, comp_id] apply (X.unit_assoc _).symm lemma comparison_full [R.Full] {L : C ⥤ D} (adj : L ⊣ R) : (Monad.comparison adj).Full where map_surjective f := ⟨R.preimage f.f, by cat_disch⟩ end Reflective namespace Coreflective instance [Coreflective R] (X : (coreflectorAdjunction R).toComonad.Coalgebra) : IsIso ((coreflectorAdjunction R).counit.app X.A) := ⟨⟨X.a, ⟨by dsimp only [Functor.id_obj] rw [← (coreflectorAdjunction R).counit_naturality] dsimp only [Functor.comp_obj, Adjunction.toMonad_coe] rw [counit_obj_eq_map_counit, ← Functor.map_comp, ← Functor.map_comp] simpa using congrArg (fun t ↦ R.map ((coreflector R).map t)) X.counit, X.counit⟩⟩⟩ instance comparison_essSurj [Coreflective R] : (Comonad.comparison (coreflectorAdjunction R)).EssSurj := by refine ⟨fun X => ⟨(coreflector R).obj X.A, ⟨?_⟩⟩⟩ refine Comonad.Coalgebra.isoMk ?_ ?_ · exact (asIso ((coreflectorAdjunction R).counit.app X.A)) rw [← cancel_mono ((coreflectorAdjunction R).counit.app X.A)] simp only [Functor.comp_obj, Functor.id_obj, assoc] simpa using (coreflectorAdjunction R).counit.app X.A ≫= X.counit.symm lemma comparison_full [R.Full] {L : C ⥤ D} (adj : R ⊣ L) : (Comonad.comparison adj).Full where map_surjective f := ⟨R.preimage f.f, by cat_disch⟩ end Coreflective -- It is possible to do this computably since the construction gives the data of the inverse, not -- just the existence of an inverse on each object. -- see Note [lower instance priority] /-- Any reflective inclusion has a monadic right adjoint. cf Prop 5.3.3 of [Riehl][riehl2017] -/ instance (priority := 100) monadicOfReflective [Reflective R] : MonadicRightAdjoint R where L := reflector R adj := reflectorAdjunction R eqv := { full := Reflective.comparison_full _ } /-- Any coreflective inclusion has a comonadic left adjoint. cf Dual statement of Prop 5.3.3 of [Riehl][riehl2017] -/ instance (priority := 100) comonadicOfCoreflective [Coreflective R] : ComonadicLeftAdjoint R where R := coreflector R adj := coreflectorAdjunction R eqv := { full := Coreflective.comparison_full _ } end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Types.lean
import Mathlib.CategoryTheory.Category.KleisliCat import Mathlib.CategoryTheory.Monad.Basic import Mathlib.CategoryTheory.Monad.Kleisli import Mathlib.CategoryTheory.Types.Basic import Mathlib.Control.Basic /-! # Convert from `Monad` (i.e. Lean's `Type`-based monads) to `CategoryTheory.Monad` This allows us to use these monads in category theory. -/ namespace CategoryTheory section universe u variable (m : Type u → Type u) [_root_.Monad m] [LawfulMonad m] /-- A lawful `Control.Monad` gives a category theory `Monad` on the category of types. -/ @[simps!] def ofTypeMonad : Monad (Type u) where toFunctor := ofTypeFunctor m η := ⟨@pure m _, fun _ _ f => funext fun x => (LawfulApplicative.map_pure f x).symm⟩ μ := ⟨@joinM m _, fun _ _ _ => funext fun _ => joinM_map_map _ _⟩ assoc _ := funext fun _ => joinM_map_joinM _ left_unit _ := funext fun _ => joinM_pure _ right_unit _ := funext fun _ => joinM_map_pure _ /-- The `Kleisli` category of a `Control.Monad` is equivalent to the `Kleisli` category of its category-theoretic version, provided the monad is lawful. -/ @[simps] def eq : KleisliCat m ≌ Kleisli (ofTypeMonad m) where functor := { obj := fun X => X map := fun f => f map_id := fun _ => rfl map_comp := fun f g => by unfold_projs funext t simp only [ofTypeMonad_obj, Function.comp_apply, ofTypeMonad_map, ofTypeMonad_μ_app, joinM, bind_map_left, id_eq] rfl } inverse := { obj := fun X => X map := fun f => f map_id := fun _ => rfl map_comp := fun f g => by unfold_projs -- Porting note: Need these instances for some lemmas below. --Should they be added as actual instances elsewhere? letI : _root_.Monad (ofTypeMonad m).obj := show _root_.Monad m from inferInstance letI : LawfulMonad (ofTypeMonad m).obj := show LawfulMonad m from inferInstance funext t simp only [ofTypeMonad_obj, Function.comp_apply, ofTypeMonad_map, ofTypeMonad_μ_app, joinM, bind_map_left, id_eq] rfl } unitIso := by refine NatIso.ofComponents (fun X => Iso.refl X) fun f => ?_ change f >=> pure = pure >=> f simp [functor_norm] counitIso := NatIso.ofComponents fun X => Iso.refl X end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Limits.lean
import Mathlib.CategoryTheory.Monad.Adjunction import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.IsTerminal /-! # Limits and colimits in the category of (co)algebras This file shows that the forgetful functor `forget T : Algebra T ⥤ C` for a monad `T : C ⥤ C` creates limits and creates any colimits which `T` preserves. This is used to show that `Algebra T` has any limits which `C` has, and any colimits which `C` has and `T` preserves. This is generalised to the case of a monadic functor `D ⥤ C`. Dually, this file shows that the forgetful functor `forget T : Coalgebra T ⥤ C` for a comonad `T : C ⥤ C` creates colimits and creates any limits which `T` preserves. This is used to show that `Coalgebra T` has any colimits which `C` has, and any limits which `C` has and `T` preserves. This is generalised to the case of a comonadic functor `D ⥤ C`. -/ namespace CategoryTheory open Category Functor open CategoryTheory.Limits universe v u v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes]. namespace Monad variable {C : Type u₁} [Category.{v₁} C] variable {T : Monad C} variable {J : Type u} [Category.{v} J] namespace ForgetCreatesLimits variable (D : J ⥤ Algebra T) (c : Cone (D ⋙ T.forget)) (t : IsLimit c) /-- (Impl) The natural transformation used to define the new cone -/ @[simps] def γ : D ⋙ T.forget ⋙ ↑T ⟶ D ⋙ T.forget where app j := (D.obj j).a /-- (Impl) This new cone is used to construct the algebra structure -/ @[simps! π_app] def newCone : Cone (D ⋙ forget T) where pt := T.obj c.pt π := (Functor.constComp _ _ (T : C ⥤ C)).inv ≫ whiskerRight c.π (T : C ⥤ C) ≫ γ D /-- The algebra structure which will be the apex of the new limit cone for `D`. -/ @[simps] def conePoint : Algebra T where A := c.pt a := t.lift (newCone D c) unit := t.hom_ext fun j => by rw [Category.assoc, t.fac, newCone_π_app, ← T.η.naturality_assoc, Functor.id_map, (D.obj j).unit] simp assoc := t.hom_ext fun j => by rw [Category.assoc, Category.assoc, t.fac (newCone D c), newCone_π_app, ← Functor.map_comp_assoc, t.fac (newCone D c), newCone_π_app, ← T.μ.naturality_assoc, (D.obj j).assoc, Functor.map_comp, Category.assoc] rfl /-- (Impl) Construct the lifted cone in `Algebra T` which will be limiting. -/ @[simps] def liftedCone : Cone D where pt := conePoint D c t π := { app := fun j => { f := c.π.app j } naturality := fun X Y f => by ext1 simpa using (c.w f).symm } /-- (Impl) Prove that the lifted cone is limiting. -/ @[simps] def liftedConeIsLimit : IsLimit (liftedCone D c t) where lift s := { f := t.lift ((forget T).mapCone s) h := t.hom_ext fun j => by dsimp rw [Category.assoc, Category.assoc, t.fac, newCone_π_app, ← Functor.map_comp_assoc, t.fac, Functor.mapCone_π_app] apply (s.π.app j).h } uniq s m J := by ext1 apply t.hom_ext intro j simpa [t.fac ((forget T).mapCone s) j] using congr_arg Algebra.Hom.f (J j) end ForgetCreatesLimits -- Theorem 5.6.5 from [Riehl][riehl2017] /-- The forgetful functor from the Eilenberg-Moore category creates limits. -/ noncomputable instance forgetCreatesLimits : CreatesLimitsOfSize (forget T) where CreatesLimitsOfShape := { CreatesLimit := fun {D} => createsLimitOfReflectsIso fun c t => { liftedCone := ForgetCreatesLimits.liftedCone D c t validLift := Cones.ext (Iso.refl _) fun _ => (id_comp _).symm makesLimit := ForgetCreatesLimits.liftedConeIsLimit _ _ _ } } /-- `D ⋙ forget T` has a limit, then `D` has a limit. -/ theorem hasLimit_of_comp_forget_hasLimit (D : J ⥤ Algebra T) [HasLimit (D ⋙ forget T)] : HasLimit D := hasLimit_of_created D (forget T) namespace ForgetCreatesColimits -- Let's hide the implementation details in a namespace variable {D : J ⥤ Algebra T} (c : Cocone (D ⋙ forget T)) (t : IsColimit c) -- We have a diagram D of shape J in the category of algebras, and we assume that we are given a -- colimit for its image D ⋙ forget T under the forgetful functor, say its point is L. -- We'll construct a colimiting coalgebra for D, whose carrier will also be L. -- To do this, we must find a map TL ⟶ L. Since T preserves colimits, TL is also a colimit. -- In particular, it is a colimit for the diagram `(D ⋙ forget T) ⋙ T` -- so to construct a map TL ⟶ L it suffices to show that L is the point of a cocone for this -- diagram. In other words, we need a natural transformation from const L to `(D ⋙ forget T) ⋙ T`. -- But we already know that L is the point of a cocone for the diagram `D ⋙ forget T`, so it -- suffices to give a natural transformation `((D ⋙ forget T) ⋙ T) ⟶ (D ⋙ forget T)`: /-- (Impl) The natural transformation given by the algebra structure maps, used to construct a cocone `c` with point `colimit (D ⋙ forget T)`. -/ @[simps] def γ : (D ⋙ forget T) ⋙ ↑T ⟶ D ⋙ forget T where app j := (D.obj j).a /-- (Impl) A cocone for the diagram `(D ⋙ forget T) ⋙ T` found by composing the natural transformation `γ` with the colimiting cocone for `D ⋙ forget T`. -/ @[simps] def newCocone : Cocone ((D ⋙ forget T) ⋙ (T : C ⥤ C)) where pt := c.pt ι := γ ≫ c.ι variable [PreservesColimit (D ⋙ forget T) (T : C ⥤ C)] /-- (Impl) Define the map `λ : TL ⟶ L`, which will serve as the structure of the coalgebra on `L`, and we will show is the colimiting object. We use the cocone constructed by `c` and the fact that `T` preserves colimits to produce this morphism. -/ noncomputable abbrev lambda : ((T : C ⥤ C).mapCocone c).pt ⟶ c.pt := (isColimitOfPreserves _ t).desc (newCocone c) /-- (Impl) The key property defining the map `λ : TL ⟶ L`. -/ theorem commuting (j : J) : (T : C ⥤ C).map (c.ι.app j) ≫ lambda c t = (D.obj j).a ≫ c.ι.app j := (isColimitOfPreserves _ t).fac (newCocone c) j variable [PreservesColimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)] /-- (Impl) Construct the colimiting algebra from the map `λ : TL ⟶ L` given by `lambda`. We are required to show it satisfies the two algebra laws, which follow from the algebra laws for the image of `D` and our `commuting` lemma. -/ @[simps] noncomputable def coconePoint : Algebra T where A := c.pt a := lambda c t unit := by apply t.hom_ext intro j rw [show c.ι.app j ≫ T.η.app c.pt ≫ _ = T.η.app (D.obj j).A ≫ _ ≫ _ from T.η.naturality_assoc _ _, commuting, Algebra.unit_assoc (D.obj j)] simp assoc := by refine (isColimitOfPreserves _ (isColimitOfPreserves _ t)).hom_ext fun j => ?_ rw [Functor.mapCocone_ι_app, Functor.mapCocone_ι_app, show (T : C ⥤ C).map ((T : C ⥤ C).map _) ≫ _ ≫ _ = _ from T.μ.naturality_assoc _ _, ← Functor.map_comp_assoc, commuting, Functor.map_comp, Category.assoc, commuting] apply (D.obj j).assoc_assoc _ /-- (Impl) Construct the lifted cocone in `Algebra T` which will be colimiting. -/ @[simps] noncomputable def liftedCocone : Cocone D where pt := coconePoint c t ι := { app := fun j => { f := c.ι.app j h := commuting _ _ _ } naturality := fun A B f => by ext1 dsimp rw [comp_id] apply c.w } /-- (Impl) Prove that the lifted cocone is colimiting. -/ @[simps] noncomputable def liftedCoconeIsColimit : IsColimit (liftedCocone c t) where desc s := { f := t.desc ((forget T).mapCocone s) h := (isColimitOfPreserves (T : C ⥤ C) t).hom_ext fun j => by dsimp rw [← Functor.map_comp_assoc, ← Category.assoc, t.fac, commuting, Category.assoc, t.fac] apply Algebra.Hom.h } uniq s m J := by ext1 apply t.hom_ext intro j simpa using congr_arg Algebra.Hom.f (J j) end ForgetCreatesColimits open ForgetCreatesColimits -- TODO: the converse of this is true as well /-- The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit which the monad itself preserves. -/ noncomputable instance forgetCreatesColimit (D : J ⥤ Algebra T) [PreservesColimit (D ⋙ forget T) (T : C ⥤ C)] [PreservesColimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)] : CreatesColimit D (forget T) := createsColimitOfReflectsIso fun c t => { liftedCocone := { pt := coconePoint c t ι := { app := fun j => { f := c.ι.app j h := commuting _ _ _ } naturality := fun A B f => by ext1 simpa using (c.w f) } } validLift := Cocones.ext (Iso.refl _) makesColimit := liftedCoconeIsColimit _ _ } noncomputable instance forgetCreatesColimitsOfShape [PreservesColimitsOfShape J (T : C ⥤ C)] : CreatesColimitsOfShape J (forget T) where CreatesColimit := by infer_instance noncomputable instance forgetCreatesColimits [PreservesColimitsOfSize.{v, u} (T : C ⥤ C)] : CreatesColimitsOfSize.{v, u} (forget T) where CreatesColimitsOfShape := by infer_instance /-- For `D : J ⥤ Algebra T`, `D ⋙ forget T` has a colimit, then `D` has a colimit provided colimits of shape `J` are preserved by `T`. -/ theorem forget_creates_colimits_of_monad_preserves [PreservesColimitsOfShape J (T : C ⥤ C)] (D : J ⥤ Algebra T) [HasColimit (D ⋙ forget T)] : HasColimit D := hasColimit_of_created D (forget T) end Monad variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] variable {J : Type u} [Category.{v} J] instance comp_comparison_forget_hasLimit (F : J ⥤ D) (R : D ⥤ C) [MonadicRightAdjoint R] [HasLimit (F ⋙ R)] : HasLimit ((F ⋙ Monad.comparison (monadicAdjunction R)) ⋙ Monad.forget _) := by assumption instance comp_comparison_hasLimit (F : J ⥤ D) (R : D ⥤ C) [MonadicRightAdjoint R] [HasLimit (F ⋙ R)] : HasLimit (F ⋙ Monad.comparison (monadicAdjunction R)) := Monad.hasLimit_of_comp_forget_hasLimit (F ⋙ Monad.comparison (monadicAdjunction R)) /-- Any monadic functor creates limits. -/ noncomputable def monadicCreatesLimits (R : D ⥤ C) [MonadicRightAdjoint R] : CreatesLimitsOfSize.{v, u} R := createsLimitsOfNatIso (Monad.comparisonForget (monadicAdjunction R)) /-- The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit which the monad itself preserves. -/ noncomputable def monadicCreatesColimitOfPreservesColimit (R : D ⥤ C) (K : J ⥤ D) [MonadicRightAdjoint R] [PreservesColimit (K ⋙ R) (monadicLeftAdjoint R ⋙ R)] [PreservesColimit ((K ⋙ R) ⋙ monadicLeftAdjoint R ⋙ R) (monadicLeftAdjoint R ⋙ R)] : CreatesColimit K R := by -- Porting note: It would be nice to have a variant of apply which introduces goals for missing -- instances. letI A := Monad.comparison (monadicAdjunction R) letI B := Monad.forget (Adjunction.toMonad (monadicAdjunction R)) let i : (K ⋙ Monad.comparison (monadicAdjunction R)) ⋙ Monad.forget _ ≅ K ⋙ R := Functor.associator _ _ _ ≪≫ isoWhiskerLeft K (Monad.comparisonForget (monadicAdjunction R)) letI : PreservesColimit ((K ⋙ A) ⋙ Monad.forget (Adjunction.toMonad (monadicAdjunction R))) (Adjunction.toMonad (monadicAdjunction R)).toFunctor := by dsimp exact preservesColimit_of_iso_diagram _ i.symm letI : PreservesColimit (((K ⋙ A) ⋙ Monad.forget (Adjunction.toMonad (monadicAdjunction R))) ⋙ (Adjunction.toMonad (monadicAdjunction R)).toFunctor) (Adjunction.toMonad (monadicAdjunction R)).toFunctor := by dsimp exact preservesColimit_of_iso_diagram _ (isoWhiskerRight i (monadicLeftAdjoint R ⋙ R)).symm letI : CreatesColimit (K ⋙ A) B := CategoryTheory.Monad.forgetCreatesColimit _ letI : CreatesColimit K (A ⋙ B) := CategoryTheory.compCreatesColimit _ _ let e := Monad.comparisonForget (monadicAdjunction R) apply createsColimitOfNatIso e /-- A monadic functor creates any colimits of shapes it preserves. -/ noncomputable def monadicCreatesColimitsOfShapeOfPreservesColimitsOfShape (R : D ⥤ C) [MonadicRightAdjoint R] [PreservesColimitsOfShape J R] : CreatesColimitsOfShape J R := letI : PreservesColimitsOfShape J (monadicLeftAdjoint R) := by apply (Adjunction.leftAdjoint_preservesColimits (monadicAdjunction R)).1 letI : PreservesColimitsOfShape J (monadicLeftAdjoint R ⋙ R) := by apply CategoryTheory.Limits.comp_preservesColimitsOfShape _ _ ⟨monadicCreatesColimitOfPreservesColimit _ _⟩ /-- A monadic functor creates colimits if it preserves colimits. -/ noncomputable def monadicCreatesColimitsOfPreservesColimits (R : D ⥤ C) [MonadicRightAdjoint R] [PreservesColimitsOfSize.{v, u} R] : CreatesColimitsOfSize.{v, u} R where CreatesColimitsOfShape := monadicCreatesColimitsOfShapeOfPreservesColimitsOfShape _ section theorem hasLimit_of_reflective (F : J ⥤ D) (R : D ⥤ C) [HasLimit (F ⋙ R)] [Reflective R] : HasLimit F := haveI := monadicCreatesLimits.{v, u} R hasLimit_of_created F R /-- If `C` has limits of shape `J` then any reflective subcategory has limits of shape `J`. -/ theorem hasLimitsOfShape_of_reflective [HasLimitsOfShape J C] (R : D ⥤ C) [Reflective R] : HasLimitsOfShape J D := ⟨fun F => hasLimit_of_reflective F R⟩ /-- If `C` has limits then any reflective subcategory has limits. -/ theorem hasLimits_of_reflective (R : D ⥤ C) [HasLimitsOfSize.{v, u} C] [Reflective R] : HasLimitsOfSize.{v, u} D := ⟨fun _ => hasLimitsOfShape_of_reflective R⟩ /-- If `C` has colimits of shape `J` then any reflective subcategory has colimits of shape `J`. -/ theorem hasColimitsOfShape_of_reflective (R : D ⥤ C) [Reflective R] [HasColimitsOfShape J C] : HasColimitsOfShape J D where has_colimit := fun F => by let c := (monadicLeftAdjoint R).mapCocone (colimit.cocone (F ⋙ R)) letI : PreservesColimitsOfShape J _ := (monadicAdjunction R).leftAdjoint_preservesColimits.1 let t : IsColimit c := isColimitOfPreserves (monadicLeftAdjoint R) (colimit.isColimit _) apply HasColimit.mk ⟨_, (IsColimit.precomposeInvEquiv _ _).symm t⟩ apply (isoWhiskerLeft F (asIso (monadicAdjunction R).counit) :) ≪≫ F.rightUnitor /-- If `C` has colimits then any reflective subcategory has colimits. -/ theorem hasColimits_of_reflective (R : D ⥤ C) [Reflective R] [HasColimitsOfSize.{v, u} C] : HasColimitsOfSize.{v, u} D := ⟨fun _ => hasColimitsOfShape_of_reflective R⟩ /-- The reflector always preserves terminal objects. Note this in general doesn't apply to any other limit. -/ lemma leftAdjoint_preservesTerminal_of_reflective (R : D ⥤ C) [Reflective R] : PreservesLimitsOfShape (Discrete.{v} PEmpty) (monadicLeftAdjoint R) where preservesLimit {K} := by let F := Functor.empty.{v} D letI : PreservesLimit (F ⋙ R) (monadicLeftAdjoint R) := by constructor intro c h haveI : HasLimit (F ⋙ R) := ⟨⟨⟨c, h⟩⟩⟩ haveI : HasLimit F := hasLimit_of_reflective F R constructor apply isLimitChangeEmptyCone D (limit.isLimit F) apply (asIso ((monadicAdjunction R).counit.app _)).symm.trans apply (monadicLeftAdjoint R).mapIso letI := monadicCreatesLimits.{v, v} R let A := CategoryTheory.preservesLimit_of_createsLimit_and_hasLimit F R apply (isLimitOfPreserves _ (limit.isLimit F)).conePointUniqueUpToIso h apply preservesLimit_of_iso_diagram _ (Functor.emptyExt (F ⋙ R) _) end -- We dualise all of the above for comonads. namespace Comonad variable {T : Comonad C} namespace ForgetCreatesColimits' variable (D : J ⥤ Coalgebra T) (c : Cocone (D ⋙ T.forget)) (t : IsColimit c) /-- (Impl) The natural transformation used to define the new cocone -/ @[simps] def γ : D ⋙ T.forget ⟶ D ⋙ T.forget ⋙ ↑T where app j := (D.obj j).a /-- (Impl) This new cocone is used to construct the coalgebra structure -/ @[simps! ι_app] def newCocone : Cocone (D ⋙ forget T) where pt := T.obj c.pt ι := γ D ≫ whiskerRight c.ι (T : C ⥤ C) ≫ (Functor.constComp J _ (T : C ⥤ C)).hom /-- The coalgebra structure which will be the point of the new colimit cone for `D`. -/ @[simps] def coconePoint : Coalgebra T where A := c.pt a := t.desc (newCocone D c) counit := t.hom_ext fun j ↦ by simp only [Functor.comp_obj, forget_obj, Functor.id_obj, Functor.const_obj_obj, IsColimit.fac_assoc, newCocone_ι_app, assoc, NatTrans.naturality, Functor.id_map, comp_id] rw [← Category.assoc, (D.obj j).counit, Category.id_comp] coassoc := t.hom_ext fun j ↦ by simp only [Functor.comp_obj, forget_obj, Functor.const_obj_obj, IsColimit.fac_assoc, newCocone_ι_app, assoc, NatTrans.naturality, Functor.comp_map] rw [← Category.assoc, (D.obj j).coassoc, ← Functor.map_comp, t.fac (newCocone D c) j, newCocone_ι_app, Functor.map_comp, assoc] /-- (Impl) Construct the lifted cocone in `Coalgebra T` which will be colimiting. -/ @[simps] def liftedCocone : Cocone D where pt := coconePoint D c t ι := { app := fun j => { f := c.ι.app j } naturality := fun X Y f => by ext1 simpa using (c.w f) } /-- (Impl) Prove that the lifted cocone is colimiting. -/ @[simps] def liftedCoconeIsColimit : IsColimit (liftedCocone D c t) where desc s := { f := t.desc ((forget T).mapCocone s) h := t.hom_ext fun j => by dsimp rw [← Category.assoc, ← Category.assoc, t.fac, newCocone_ι_app, t.fac, Functor.mapCocone_ι_app, Category.assoc, ← Functor.map_comp, t.fac] apply (s.ι.app j).h } uniq s m J := by ext1 apply t.hom_ext intro j simpa [t.fac ((forget T).mapCocone s) j] using congr_arg Coalgebra.Hom.f (J j) end ForgetCreatesColimits' -- Dual to theorem 5.6.5 from [Riehl][riehl2017] /-- The forgetful functor from the Eilenberg-Moore category creates colimits. -/ noncomputable instance forgetCreatesColimit : CreatesColimitsOfSize (forget T) where CreatesColimitsOfShape := { CreatesColimit := fun {D} => createsColimitOfReflectsIso fun c t => { liftedCocone := ForgetCreatesColimits'.liftedCocone D c t validLift := Cocones.ext (Iso.refl _) fun _ => (comp_id _) makesColimit := ForgetCreatesColimits'.liftedCoconeIsColimit _ _ _ } } /-- If `D ⋙ forget T` has a colimit, then `D` has a colimit. -/ theorem hasColimit_of_comp_forget_hasColimit (D : J ⥤ Coalgebra T) [HasColimit (D ⋙ forget T)] : HasColimit D := hasColimit_of_created D (forget T) namespace ForgetCreatesLimits' -- Let's hide the implementation details in a namespace variable {D : J ⥤ Coalgebra T} (c : Cone (D ⋙ forget T)) (t : IsLimit c) /-- (Impl) The natural transformation given by the coalgebra structure maps, used to construct a cone `c` with point `limit (D ⋙ forget T)`. -/ @[simps] def γ : D ⋙ forget T ⟶ (D ⋙ forget T) ⋙ ↑T where app j := (D.obj j).a /-- (Impl) A cone for the diagram `(D ⋙ forget T) ⋙ T` found by composing the natural transformation `γ` with the limiting cone for `D ⋙ forget T`. -/ @[simps] def newCone : Cone ((D ⋙ forget T) ⋙ (T : C ⥤ C)) where pt := c.pt π := c.π ≫ γ variable [PreservesLimit (D ⋙ forget T) (T : C ⥤ C)] /-- (Impl) Define the map `λ : L ⟶ TL`, which will serve as the structure of the algebra on `L`, and we will show is the limiting object. We use the cone constructed by `c` and the fact that `T` preserves limits to produce this morphism. -/ noncomputable abbrev lambda : c.pt ⟶ ((T : C ⥤ C).mapCone c).pt := (isLimitOfPreserves _ t).lift (newCone c) /-- (Impl) The key property defining the map `λ : L ⟶ TL`. -/ theorem commuting (j : J) : lambda c t ≫ (T : C ⥤ C).map (c.π.app j) = c.π.app j ≫ (D.obj j).a := (isLimitOfPreserves _ t).fac (newCone c) j variable [PreservesLimit ((D ⋙ forget T) ⋙ T.toFunctor) T.toFunctor] variable [PreservesColimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)] /-- (Impl) Construct the limiting coalgebra from the map `λ : L ⟶ TL` given by `lambda`. We are required to show it satisfies the two coalgebra laws, which follow from the coalgebra laws for the image of `D` and our `commuting` lemma. -/ @[simps] noncomputable def conePoint : Coalgebra T where A := c.pt a := lambda c t counit := t.hom_ext fun j ↦ by rw [assoc, ← show _ = _ ≫ c.π.app j from T.ε.naturality _, ← assoc, commuting, assoc] simp [Coalgebra.counit (D.obj j)] coassoc := by refine (isLimitOfPreserves _ (isLimitOfPreserves _ t)).hom_ext fun j => ?_ rw [Functor.mapCone_π_app, Functor.mapCone_π_app, assoc, ← show _ = _ ≫ T.map (T.map _) from T.δ.naturality _, assoc, ← Functor.map_comp, commuting, Functor.map_comp, ← assoc, commuting] simp only [Functor.comp_obj, forget_obj, Functor.const_obj_obj, assoc] rw [(D.obj j).coassoc, ← assoc, ← assoc, commuting] /-- (Impl) Construct the lifted cone in `Coalgebra T` which will be limiting. -/ @[simps] noncomputable def liftedCone : Cone D where pt := conePoint c t π := { app := fun j => { f := c.π.app j h := commuting _ _ _ } naturality := fun A B f => by ext1 dsimp rw [id_comp, ← c.w] rfl } /-- (Impl) Prove that the lifted cone is limiting. -/ @[simps] noncomputable def liftedConeIsLimit : IsLimit (liftedCone c t) where lift s := { f := t.lift ((forget T).mapCone s) h := (isLimitOfPreserves (T : C ⥤ C) t).hom_ext fun j => by dsimp rw [Category.assoc, ← t.fac, Category.assoc, t.fac, commuting, ← assoc, ← assoc, t.fac, assoc, ← Functor.map_comp, t.fac] exact (s.π.app j).h } uniq s m J := by ext1 apply t.hom_ext intro j simpa using congr_arg Coalgebra.Hom.f (J j) end ForgetCreatesLimits' open ForgetCreatesLimits' -- TODO: the converse of this is true as well /-- The forgetful functor from the Eilenberg-Moore category for a comonad creates any limit which the comonad itself preserves. -/ noncomputable instance forgetCreatesLimit (D : J ⥤ Coalgebra T) [PreservesLimit (D ⋙ forget T) (T : C ⥤ C)] [PreservesLimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)] : CreatesLimit D (forget T) := createsLimitOfReflectsIso fun c t => { liftedCone := { pt := conePoint c t π := { app := fun j => { f := c.π.app j h := commuting _ _ _ } naturality := fun A B f => by ext1 simpa using (c.w f).symm } } validLift := Cones.ext (Iso.refl _) makesLimit := liftedConeIsLimit _ _ } noncomputable instance forgetCreatesLimitsOfShape [PreservesLimitsOfShape J (T : C ⥤ C)] : CreatesLimitsOfShape J (forget T) where CreatesLimit := by infer_instance noncomputable instance forgetCreatesLimits [PreservesLimitsOfSize.{v, u} (T : C ⥤ C)] : CreatesLimitsOfSize.{v, u} (forget T) where CreatesLimitsOfShape := by infer_instance /-- For `D : J ⥤ Coalgebra T`, `D ⋙ forget T` has a limit, then `D` has a limit provided limits of shape `J` are preserved by `T`. -/ theorem forget_creates_limits_of_comonad_preserves [PreservesLimitsOfShape J (T : C ⥤ C)] (D : J ⥤ Coalgebra T) [HasLimit (D ⋙ forget T)] : HasLimit D := hasLimit_of_created D (forget T) end Comonad instance comp_comparison_forget_hasColimit (F : J ⥤ D) (R : D ⥤ C) [ComonadicLeftAdjoint R] [HasColimit (F ⋙ R)] : HasColimit ((F ⋙ Comonad.comparison (comonadicAdjunction R)) ⋙ Comonad.forget _) := by assumption instance comp_comparison_hasColimit (F : J ⥤ D) (R : D ⥤ C) [ComonadicLeftAdjoint R] [HasColimit (F ⋙ R)] : HasColimit (F ⋙ Comonad.comparison (comonadicAdjunction R)) := Comonad.hasColimit_of_comp_forget_hasColimit (F ⋙ Comonad.comparison (comonadicAdjunction R)) /-- Any comonadic functor creates colimits. -/ noncomputable def comonadicCreatesColimits (R : D ⥤ C) [ComonadicLeftAdjoint R] : CreatesColimitsOfSize.{v, u} R := createsColimitsOfNatIso (Comonad.comparisonForget (comonadicAdjunction R)) /-- The forgetful functor from the Eilenberg-Moore category for a comonad creates any limit which the comonad itself preserves. -/ noncomputable def comonadicCreatesLimitOfPreservesLimit (R : D ⥤ C) (K : J ⥤ D) [ComonadicLeftAdjoint R] [PreservesLimit (K ⋙ R) (comonadicRightAdjoint R ⋙ R)] [PreservesLimit ((K ⋙ R) ⋙ comonadicRightAdjoint R ⋙ R) (comonadicRightAdjoint R ⋙ R)] : CreatesLimit K R := by letI A := Comonad.comparison (comonadicAdjunction R) letI B := Comonad.forget (Adjunction.toComonad (comonadicAdjunction R)) let i : (K ⋙ Comonad.comparison (comonadicAdjunction R)) ⋙ Comonad.forget _ ≅ K ⋙ R := Functor.associator _ _ _ ≪≫ isoWhiskerLeft K (Comonad.comparisonForget (comonadicAdjunction R)) letI : PreservesLimit ((K ⋙ A) ⋙ Comonad.forget (Adjunction.toComonad (comonadicAdjunction R))) (Adjunction.toComonad (comonadicAdjunction R)).toFunctor := by dsimp exact preservesLimit_of_iso_diagram _ i.symm letI : PreservesLimit (((K ⋙ A) ⋙ Comonad.forget (Adjunction.toComonad (comonadicAdjunction R))) ⋙ (Adjunction.toComonad (comonadicAdjunction R)).toFunctor) (Adjunction.toComonad (comonadicAdjunction R)).toFunctor := by dsimp exact preservesLimit_of_iso_diagram _ (isoWhiskerRight i (comonadicRightAdjoint R ⋙ R)).symm letI : CreatesLimit (K ⋙ A) B := CategoryTheory.Comonad.forgetCreatesLimit _ letI : CreatesLimit K (A ⋙ B) := CategoryTheory.compCreatesLimit _ _ let e := Comonad.comparisonForget (comonadicAdjunction R) apply createsLimitOfNatIso e /-- A comonadic functor creates any limits of shapes it preserves. -/ noncomputable def comonadicCreatesLimitsOfShapeOfPreservesLimitsOfShape (R : D ⥤ C) [ComonadicLeftAdjoint R] [PreservesLimitsOfShape J R] : CreatesLimitsOfShape J R := letI : PreservesLimitsOfShape J (comonadicRightAdjoint R) := by apply (Adjunction.rightAdjoint_preservesLimits (comonadicAdjunction R)).1 letI : PreservesLimitsOfShape J (comonadicRightAdjoint R ⋙ R) := by apply CategoryTheory.Limits.comp_preservesLimitsOfShape _ _ ⟨comonadicCreatesLimitOfPreservesLimit _ _⟩ /-- A comonadic functor creates limits if it preserves limits. -/ noncomputable def comonadicCreatesLimitsOfPreservesLimits (R : D ⥤ C) [ComonadicLeftAdjoint R] [PreservesLimitsOfSize.{v, u} R] : CreatesLimitsOfSize.{v, u} R where CreatesLimitsOfShape := comonadicCreatesLimitsOfShapeOfPreservesLimitsOfShape _ section theorem hasColimit_of_coreflective (F : J ⥤ D) (R : D ⥤ C) [HasColimit (F ⋙ R)] [Coreflective R] : HasColimit F := haveI := comonadicCreatesColimits.{v, u} R hasColimit_of_created F R /-- If `C` has colimits of shape `J` then any coreflective subcategory has colimits of shape `J`. -/ theorem hasColimitsOfShape_of_coreflective [HasColimitsOfShape J C] (R : D ⥤ C) [Coreflective R] : HasColimitsOfShape J D := ⟨fun F => hasColimit_of_coreflective F R⟩ /-- If `C` has colimits then any coreflective subcategory has colimits. -/ theorem hasColimits_of_coreflective (R : D ⥤ C) [HasColimitsOfSize.{v, u} C] [Coreflective R] : HasColimitsOfSize.{v, u} D := ⟨fun _ => hasColimitsOfShape_of_coreflective R⟩ /-- If `C` has limits of shape `J` then any coreflective subcategory has limits of shape `J`. -/ theorem hasLimitsOfShape_of_coreflective (R : D ⥤ C) [Coreflective R] [HasLimitsOfShape J C] : HasLimitsOfShape J D where has_limit := fun F => by let c := (comonadicRightAdjoint R).mapCone (limit.cone (F ⋙ R)) letI : PreservesLimitsOfShape J _ := (comonadicAdjunction R).rightAdjoint_preservesLimits.1 let t : IsLimit c := isLimitOfPreserves (comonadicRightAdjoint R) (limit.isLimit _) apply HasLimit.mk ⟨_, (IsLimit.postcomposeHomEquiv _ _).symm t⟩ apply (F.rightUnitor ≪≫ (isoWhiskerLeft F ((asIso (comonadicAdjunction R).unit) :) )).symm /-- If `C` has limits then any coreflective subcategory has limits. -/ theorem hasLimits_of_coreflective (R : D ⥤ C) [Coreflective R] [HasLimitsOfSize.{v, u} C] : HasLimitsOfSize.{v, u} D := ⟨fun _ => hasLimitsOfShape_of_coreflective R⟩ /-- The coreflector always preserves initial objects. Note this in general doesn't apply to any other colimit. -/ lemma rightAdjoint_preservesInitial_of_coreflective (R : D ⥤ C) [Coreflective R] : PreservesColimitsOfShape (Discrete.{v} PEmpty) (comonadicRightAdjoint R) where preservesColimit {K} := by let F := Functor.empty.{v} D letI : PreservesColimit (F ⋙ R) (comonadicRightAdjoint R) := by constructor intro c h haveI : HasColimit (F ⋙ R) := ⟨⟨⟨c, h⟩⟩⟩ haveI : HasColimit F := hasColimit_of_coreflective F R constructor apply isColimitChangeEmptyCocone D (colimit.isColimit F) apply (asIso ((comonadicAdjunction R).unit.app _)).trans apply (comonadicRightAdjoint R).mapIso letI := comonadicCreatesColimits.{v, v} R let A := CategoryTheory.preservesColimit_of_createsColimit_and_hasColimit F R apply (isColimitOfPreserves _ (colimit.isColimit F)).coconePointUniqueUpToIso h apply preservesColimit_of_iso_diagram _ (Functor.emptyExt (F ⋙ R) _) end end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Algebra.lean
import Mathlib.CategoryTheory.Monad.Basic import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Functor.EpiMono /-! # Eilenberg-Moore (co)algebras for a (co)monad This file defines Eilenberg-Moore (co)algebras for a (co)monad, and provides the category instance for them. Further it defines the adjoint pair of free and forgetful functors, respectively from and to the original category, as well as the adjoint pair of forgetful and cofree functors, respectively from and to the original category. ## References * [Riehl, *Category theory in context*, Section 5.2.4][riehl2017] -/ namespace CategoryTheory open Category universe v₁ u₁ -- morphism levels before object levels. See note [category_theory universes]. variable {C : Type u₁} [Category.{v₁} C] namespace Monad /-- An Eilenberg-Moore algebra for a monad `T`. cf Definition 5.2.3 in [Riehl][riehl2017]. -/ structure Algebra (T : Monad C) : Type max u₁ v₁ where /-- The underlying object associated to an algebra. -/ A : C /-- The structure morphism associated to an algebra. -/ a : (T : C ⥤ C).obj A ⟶ A /-- The unit axiom associated to an algebra. -/ unit : T.η.app A ≫ a = 𝟙 A := by cat_disch /-- The associativity axiom associated to an algebra. -/ assoc : T.μ.app A ≫ a = (T : C ⥤ C).map a ≫ a := by cat_disch attribute [reassoc] Algebra.unit Algebra.assoc namespace Algebra variable {T : Monad C} /-- A morphism of Eilenberg–Moore algebras for the monad `T`. -/ @[ext] structure Hom (A B : Algebra T) where /-- The underlying morphism associated to a morphism of algebras. -/ f : A.A ⟶ B.A /-- Compatibility with the structure morphism, for a morphism of algebras. -/ h : (T : C ⥤ C).map f ≫ B.a = A.a ≫ f := by cat_disch attribute [reassoc (attr := simp)] Hom.h namespace Hom /-- The identity homomorphism for an Eilenberg–Moore algebra. -/ def id (A : Algebra T) : Hom A A where f := 𝟙 A.A instance (A : Algebra T) : Inhabited (Hom A A) := ⟨{ f := 𝟙 _ }⟩ /-- Composition of Eilenberg–Moore algebra homomorphisms. -/ def comp {P Q R : Algebra T} (f : Hom P Q) (g : Hom Q R) : Hom P R where f := f.f ≫ g.f end Hom instance : CategoryStruct (Algebra T) where Hom := Hom id := Hom.id comp := @Hom.comp _ _ _ @[ext] lemma Hom.ext' (X Y : Algebra T) (f g : X ⟶ Y) (h : f.f = g.f) : f = g := Hom.ext h @[simp] theorem comp_eq_comp {A A' A'' : Algebra T} (f : A ⟶ A') (g : A' ⟶ A'') : Algebra.Hom.comp f g = f ≫ g := rfl @[simp] theorem id_eq_id (A : Algebra T) : Algebra.Hom.id A = 𝟙 A := rfl @[simp] theorem id_f (A : Algebra T) : (𝟙 A : A ⟶ A).f = 𝟙 A.A := rfl @[simp] theorem comp_f {A A' A'' : Algebra T} (f : A ⟶ A') (g : A' ⟶ A'') : (f ≫ g).f = f.f ≫ g.f := rfl /-- The category of Eilenberg-Moore algebras for a monad. cf Definition 5.2.4 in [Riehl][riehl2017]. -/ instance eilenbergMoore : Category (Algebra T) where /-- To construct an isomorphism of algebras, it suffices to give an isomorphism of the carriers which commutes with the structure morphisms. -/ @[simps] def isoMk {A B : Algebra T} (h : A.A ≅ B.A) (w : (T : C ⥤ C).map h.hom ≫ B.a = A.a ≫ h.hom := by cat_disch) : A ≅ B where hom := { f := h.hom } inv := { f := h.inv h := by rw [h.eq_comp_inv, Category.assoc, ← w, ← Functor.map_comp_assoc] simp } end Algebra variable (T : Monad C) /-- The forgetful functor from the Eilenberg-Moore category, forgetting the algebraic structure. -/ @[simps] def forget : Algebra T ⥤ C where obj A := A.A map f := f.f /-- The free functor from the Eilenberg-Moore category, constructing an algebra for any object. -/ @[simps] def free : C ⥤ Algebra T where obj X := { A := T.obj X a := T.μ.app X assoc := (T.assoc _).symm } map f := { f := T.map f h := T.μ.naturality _ } instance [Inhabited C] : Inhabited (Algebra T) := ⟨(free T).obj default⟩ -- The other two `simps` projection lemmas can be derived from these two, so `simp_nf` complains if -- those are added too /-- The adjunction between the free and forgetful constructions for Eilenberg-Moore algebras for a monad. cf Lemma 5.2.8 of [Riehl][riehl2017]. -/ @[simps! unit counit] def adj : T.free ⊣ T.forget := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => { toFun := fun f => T.η.app X ≫ f.f invFun := fun f => { f := T.map f ≫ Y.a h := by simp [← Y.assoc, ← T.μ.naturality_assoc] } left_inv := fun f => by ext simp right_inv := fun f => by dsimp only [forget_obj] rw [← T.η.naturality_assoc, Y.unit] apply Category.comp_id } } /-- Given an algebra morphism whose carrier part is an isomorphism, we get an algebra isomorphism. -/ theorem algebra_iso_of_iso {A B : Algebra T} (f : A ⟶ B) [IsIso f.f] : IsIso f := ⟨⟨{ f := inv f.f, h := by simp }, by cat_disch⟩⟩ instance forget_reflects_iso : T.forget.ReflectsIsomorphisms where reflects {_ _} f [IsIso f.f] := algebra_iso_of_iso T f instance forget_faithful : T.forget.Faithful where /-- Given an algebra morphism whose carrier part is an epimorphism, we get an algebra epimorphism. -/ theorem algebra_epi_of_epi {X Y : Algebra T} (f : X ⟶ Y) [h : Epi f.f] : Epi f := (forget T).epi_of_epi_map h /-- Given an algebra morphism whose carrier part is a monomorphism, we get an algebra monomorphism. -/ theorem algebra_mono_of_mono {X Y : Algebra T} (f : X ⟶ Y) [h : Mono f.f] : Mono f := (forget T).mono_of_mono_map h instance : T.forget.IsRightAdjoint := ⟨T.free, ⟨T.adj⟩⟩ /-- Given a monad morphism from `T₂` to `T₁`, we get a functor from the algebras of `T₁` to algebras of `T₂`. -/ @[simps] def algebraFunctorOfMonadHom {T₁ T₂ : Monad C} (h : T₂ ⟶ T₁) : Algebra T₁ ⥤ Algebra T₂ where obj A := { A := A.A a := h.app A.A ≫ A.a unit := by simp [A.unit] assoc := by simp [A.assoc] } map f := { f := f.f } /-- The identity monad morphism induces the identity functor from the category of algebras to itself. -/ @[simps (rhsMd := .default)] def algebraFunctorOfMonadHomId {T₁ : Monad C} : algebraFunctorOfMonadHom (𝟙 T₁) ≅ 𝟭 _ := NatIso.ofComponents fun X => Algebra.isoMk (Iso.refl _) /-- A composition of monad morphisms gives the composition of corresponding functors. -/ @[simps (rhsMd := .default)] def algebraFunctorOfMonadHomComp {T₁ T₂ T₃ : Monad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) : algebraFunctorOfMonadHom (f ≫ g) ≅ algebraFunctorOfMonadHom g ⋙ algebraFunctorOfMonadHom f := NatIso.ofComponents fun X => Algebra.isoMk (Iso.refl _) /-- If `f` and `g` are two equal morphisms of monads, then the functors of algebras induced by them are isomorphic. We define it like this as opposed to using `eqToIso` so that the components are nicer to prove lemmas about. -/ @[simps (rhsMd := .default)] def algebraFunctorOfMonadHomEq {T₁ T₂ : Monad C} {f g : T₁ ⟶ T₂} (h : f = g) : algebraFunctorOfMonadHom f ≅ algebraFunctorOfMonadHom g := NatIso.ofComponents fun X => Algebra.isoMk (Iso.refl _) /-- Isomorphic monads give equivalent categories of algebras. Furthermore, they are equivalent as categories over `C`, that is, we have `algebraEquivOfIsoMonads h ⋙ forget = forget`. -/ @[simps] def algebraEquivOfIsoMonads {T₁ T₂ : Monad C} (h : T₁ ≅ T₂) : Algebra T₁ ≌ Algebra T₂ where functor := algebraFunctorOfMonadHom h.inv inverse := algebraFunctorOfMonadHom h.hom unitIso := algebraFunctorOfMonadHomId.symm ≪≫ algebraFunctorOfMonadHomEq (by simp) ≪≫ algebraFunctorOfMonadHomComp _ _ counitIso := (algebraFunctorOfMonadHomComp _ _).symm ≪≫ algebraFunctorOfMonadHomEq (by simp) ≪≫ algebraFunctorOfMonadHomId @[simp] theorem algebra_equiv_of_iso_monads_comp_forget {T₁ T₂ : Monad C} (h : T₁ ⟶ T₂) : algebraFunctorOfMonadHom h ⋙ forget _ = forget _ := rfl end Monad namespace Comonad /-- An Eilenberg-Moore coalgebra for a comonad `T`. -/ structure Coalgebra (G : Comonad C) : Type max u₁ v₁ where /-- The underlying object associated to a coalgebra. -/ A : C /-- The structure morphism associated to a coalgebra. -/ a : A ⟶ (G : C ⥤ C).obj A /-- The counit axiom associated to a coalgebra. -/ counit : a ≫ G.ε.app A = 𝟙 A := by cat_disch /-- The coassociativity axiom associated to a coalgebra. -/ coassoc : a ≫ G.δ.app A = a ≫ G.map a := by cat_disch attribute [reassoc] Coalgebra.counit Coalgebra.coassoc namespace Coalgebra variable {G : Comonad C} /-- A morphism of Eilenberg-Moore coalgebras for the comonad `G`. -/ @[ext] structure Hom (A B : Coalgebra G) where /-- The underlying morphism associated to a morphism of coalgebras. -/ f : A.A ⟶ B.A /-- Compatibility with the structure morphism, for a morphism of coalgebras. -/ h : A.a ≫ (G : C ⥤ C).map f = f ≫ B.a := by cat_disch attribute [reassoc (attr := simp)] Hom.h namespace Hom /-- The identity homomorphism for an Eilenberg–Moore coalgebra. -/ def id (A : Coalgebra G) : Hom A A where f := 𝟙 A.A /-- Composition of Eilenberg–Moore coalgebra homomorphisms. -/ def comp {P Q R : Coalgebra G} (f : Hom P Q) (g : Hom Q R) : Hom P R where f := f.f ≫ g.f end Hom /-- The category of Eilenberg-Moore coalgebras for a comonad. -/ instance : CategoryStruct (Coalgebra G) where Hom := Hom id := Hom.id comp := @Hom.comp _ _ _ @[ext] lemma Hom.ext' (X Y : Coalgebra G) (f g : X ⟶ Y) (h : f.f = g.f) : f = g := Hom.ext h @[simp] theorem comp_eq_comp {A A' A'' : Coalgebra G} (f : A ⟶ A') (g : A' ⟶ A'') : Coalgebra.Hom.comp f g = f ≫ g := rfl @[simp] theorem id_eq_id (A : Coalgebra G) : Coalgebra.Hom.id A = 𝟙 A := rfl @[simp] theorem id_f (A : Coalgebra G) : (𝟙 A : A ⟶ A).f = 𝟙 A.A := rfl @[simp] theorem comp_f {A A' A'' : Coalgebra G} (f : A ⟶ A') (g : A' ⟶ A'') : (f ≫ g).f = f.f ≫ g.f := rfl /-- The category of Eilenberg-Moore coalgebras for a comonad. -/ instance eilenbergMoore : Category (Coalgebra G) where /-- To construct an isomorphism of coalgebras, it suffices to give an isomorphism of the carriers which commutes with the structure morphisms. -/ @[simps] def isoMk {A B : Coalgebra G} (h : A.A ≅ B.A) (w : A.a ≫ (G : C ⥤ C).map h.hom = h.hom ≫ B.a := by cat_disch) : A ≅ B where hom := { f := h.hom } inv := { f := h.inv h := by rw [h.eq_inv_comp, ← reassoc_of% w, ← Functor.map_comp] simp } end Coalgebra variable (G : Comonad C) /-- The forgetful functor from the Eilenberg-Moore category, forgetting the coalgebraic structure. -/ @[simps] def forget : Coalgebra G ⥤ C where obj A := A.A map f := f.f /-- The cofree functor from the Eilenberg-Moore category, constructing a coalgebra for any object. -/ @[simps] def cofree : C ⥤ Coalgebra G where obj X := { A := G.obj X a := G.δ.app X coassoc := (G.coassoc _).symm } map f := { f := G.map f h := (G.δ.naturality _).symm } -- The other two `simps` projection lemmas can be derived from these two, so `simp_nf` complains if -- those are added too /-- The adjunction between the cofree and forgetful constructions for Eilenberg-Moore coalgebras for a comonad. -/ @[simps! unit counit] def adj : G.forget ⊣ G.cofree := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => { toFun := fun f => { f := X.a ≫ G.map f h := by simp [← Coalgebra.coassoc_assoc] } invFun := fun g => g.f ≫ G.ε.app Y left_inv := fun f => by dsimp rw [Category.assoc, G.ε.naturality, Functor.id_map, X.counit_assoc] right_inv := fun g => by ext1; dsimp rw [Functor.map_comp, g.h_assoc, cofree_obj_a, Comonad.right_counit] apply comp_id } } /-- Given a coalgebra morphism whose carrier part is an isomorphism, we get a coalgebra isomorphism. -/ theorem coalgebra_iso_of_iso {A B : Coalgebra G} (f : A ⟶ B) [IsIso f.f] : IsIso f := ⟨⟨{ f := inv f.f h := by rw [IsIso.eq_inv_comp f.f, ← f.h_assoc] simp }, by cat_disch⟩⟩ instance forget_reflects_iso : G.forget.ReflectsIsomorphisms where reflects {_ _} f [IsIso f.f] := coalgebra_iso_of_iso G f instance forget_faithful : (forget G).Faithful where /-- Given a coalgebra morphism whose carrier part is an epimorphism, we get an algebra epimorphism. -/ theorem algebra_epi_of_epi {X Y : Coalgebra G} (f : X ⟶ Y) [h : Epi f.f] : Epi f := (forget G).epi_of_epi_map h /-- Given a coalgebra morphism whose carrier part is a monomorphism, we get an algebra monomorphism. -/ theorem algebra_mono_of_mono {X Y : Coalgebra G} (f : X ⟶ Y) [h : Mono f.f] : Mono f := (forget G).mono_of_mono_map h instance : G.forget.IsLeftAdjoint := ⟨_, ⟨G.adj⟩⟩ end Comonad end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Coequalizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Reflexive import Mathlib.CategoryTheory.Limits.Shapes.SplitCoequalizer import Mathlib.CategoryTheory.Monad.Algebra /-! # Special coequalizers associated to a monad Associated to a monad `T : C ⥤ C` we have important coequalizer constructions: Any algebra is a coequalizer (in the category of algebras) of free algebras. Furthermore, this coequalizer is reflexive. In `C`, this cofork diagram is a split coequalizer (in particular, it is still a coequalizer). This split coequalizer is known as the Beck coequalizer (as it features heavily in Beck's monadicity theorem). This file has been adapted to `Mathlib/CategoryTheory/Monad/Equalizer.lean`. Please try to keep them in sync. -/ universe v₁ u₁ namespace CategoryTheory namespace Monad open Limits variable {C : Type u₁} variable [Category.{v₁} C] variable {T : Monad C} (X : Algebra T) /-! Show that any algebra is a coequalizer of free algebras. -/ /-- The top map in the coequalizer diagram we will construct. -/ @[simps!] def FreeCoequalizer.topMap : (Monad.free T).obj (T.obj X.A) ⟶ (Monad.free T).obj X.A := (Monad.free T).map X.a /-- The bottom map in the coequalizer diagram we will construct. -/ @[simps] def FreeCoequalizer.bottomMap : (Monad.free T).obj (T.obj X.A) ⟶ (Monad.free T).obj X.A where f := T.μ.app X.A h := T.assoc X.A /-- The cofork map in the coequalizer diagram we will construct. -/ @[simps] def FreeCoequalizer.π : (Monad.free T).obj X.A ⟶ X where f := X.a h := X.assoc.symm theorem FreeCoequalizer.condition : FreeCoequalizer.topMap X ≫ FreeCoequalizer.π X = FreeCoequalizer.bottomMap X ≫ FreeCoequalizer.π X := Algebra.Hom.ext X.assoc.symm instance : IsReflexivePair (FreeCoequalizer.topMap X) (FreeCoequalizer.bottomMap X) := by apply IsReflexivePair.mk' _ _ _ · apply (free T).map (T.η.app X.A) · ext dsimp rw [← Functor.map_comp, X.unit, Functor.map_id] · ext apply Monad.right_unit /-- Construct the Beck cofork in the category of algebras. This cofork is reflexive as well as a coequalizer. -/ @[simps!] def beckAlgebraCofork : Cofork (FreeCoequalizer.topMap X) (FreeCoequalizer.bottomMap X) := Cofork.ofπ _ (FreeCoequalizer.condition X) /-- The cofork constructed is a colimit. This shows that any algebra is a (reflexive) coequalizer of free algebras. -/ def beckAlgebraCoequalizer : IsColimit (beckAlgebraCofork X) := Cofork.IsColimit.mk' _ fun s => by have h₁ : (T : C ⥤ C).map X.a ≫ s.π.f = T.μ.app X.A ≫ s.π.f := congr_arg Monad.Algebra.Hom.f s.condition have h₂ : (T : C ⥤ C).map s.π.f ≫ s.pt.a = T.μ.app X.A ≫ s.π.f := s.π.h refine ⟨⟨T.η.app _ ≫ s.π.f, ?_⟩, ?_, ?_⟩ · dsimp rw [Functor.map_comp, Category.assoc, h₂, Monad.right_unit_assoc, show X.a ≫ _ ≫ _ = _ from T.η.naturality_assoc _ _, h₁, Monad.left_unit_assoc] · ext simpa [← T.η.naturality_assoc, T.left_unit_assoc] using T.η.app ((T : C ⥤ C).obj X.A) ≫= h₁ · intro m hm ext dsimp only rw [← hm] apply (X.unit_assoc _).symm /-- The Beck cofork is a split coequalizer. -/ def beckSplitCoequalizer : IsSplitCoequalizer (T.map X.a) (T.μ.app _) X.a := ⟨T.η.app _, T.η.app _, X.assoc.symm, X.unit, T.left_unit _, (T.η.naturality _).symm⟩ /-- This is the Beck cofork. It is a split coequalizer, in particular a coequalizer. -/ @[simps! pt] def beckCofork : Cofork (T.map X.a) (T.μ.app _) := (beckSplitCoequalizer X).asCofork @[simp] theorem beckCofork_π : (beckCofork X).π = X.a := rfl /-- The Beck cofork is a coequalizer. -/ def beckCoequalizer : IsColimit (beckCofork X) := (beckSplitCoequalizer X).isCoequalizer @[simp] theorem beckCoequalizer_desc (s : Cofork (T.toFunctor.map X.a) (T.μ.app X.A)) : (beckCoequalizer X).desc s = T.η.app _ ≫ s.π := rfl end Monad end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Equalizer.lean
import Mathlib.CategoryTheory.Limits.Shapes.Reflexive import Mathlib.CategoryTheory.Limits.Shapes.SplitEqualizer import Mathlib.CategoryTheory.Monad.Algebra /-! # Special equalizers associated to a comonad Associated to a comonad `T : C ⥤ C` we have important equalizer constructions: Any coalgebra is an equalizer (in the category of coalgebras) of cofree coalgebras. Furthermore, this equalizer is coreflexive. In `C`, this fork diagram is a split equalizer (in particular, it is still an equalizer). This split equalizer is known as the Beck equalizer (as it features heavily in Beck's comonadicity theorem). This file is adapted from `Mathlib/CategoryTheory/Monad/Coequalizer.lean`. Please try to keep them in sync. -/ universe v₁ u₁ namespace CategoryTheory namespace Comonad open Limits variable {C : Type u₁} variable [Category.{v₁} C] variable {T : Comonad C} (X : Coalgebra T) /-! Show that any coalgebra is an equalizer of cofree coalgebras. -/ /-- The top map in the equalizer diagram we will construct. -/ @[simps!] def CofreeEqualizer.topMap : (Comonad.cofree T).obj X.A ⟶ (Comonad.cofree T).obj (T.obj X.A) := (Comonad.cofree T).map X.a /-- The bottom map in the equalizer diagram we will construct. -/ @[simps] def CofreeEqualizer.bottomMap : (Comonad.cofree T).obj X.A ⟶ (Comonad.cofree T).obj (T.obj X.A) where f := T.δ.app X.A h := T.coassoc X.A /-- The fork map in the equalizer diagram we will construct. -/ @[simps] def CofreeEqualizer.ι : X ⟶ (Comonad.cofree T).obj X.A where f := X.a h := X.coassoc.symm theorem CofreeEqualizer.condition : CofreeEqualizer.ι X ≫ CofreeEqualizer.topMap X = CofreeEqualizer.ι X ≫ CofreeEqualizer.bottomMap X := Coalgebra.Hom.ext X.coassoc.symm instance : IsCoreflexivePair (CofreeEqualizer.topMap X) (CofreeEqualizer.bottomMap X) := by apply IsCoreflexivePair.mk' _ _ _ · apply (cofree T).map (T.ε.app X.A) · ext dsimp rw [← Functor.map_comp, X.counit, Functor.map_id] · ext apply Comonad.right_counit /-- Construct the Beck fork in the category of coalgebras. This fork is coreflexive as well as an equalizer. -/ @[simps!] def beckCoalgebraFork : Fork (CofreeEqualizer.topMap X) (CofreeEqualizer.bottomMap X) := Fork.ofι _ (CofreeEqualizer.condition X) /-- The fork constructed is a limit. This shows that any coalgebra is a (coreflexive) equalizer of cofree coalgebras. -/ def beckCoalgebraEqualizer : IsLimit (beckCoalgebraFork X) := Fork.IsLimit.mk' _ fun s => by have h₁ : s.ι.f ≫ (T : C ⥤ C).map X.a = s.ι.f ≫ T.δ.app X.A := congr_arg Comonad.Coalgebra.Hom.f s.condition have h₂ : s.pt.a ≫ (T : C ⥤ C).map s.ι.f = s.ι.f ≫ T.δ.app X.A := s.ι.h refine ⟨⟨s.ι.f ≫ T.ε.app _, ?_⟩, ?_, ?_⟩ · dsimp rw [Functor.map_comp, reassoc_of% h₂, Comonad.right_counit] dsimp rw [Category.comp_id, Category.assoc, ← T.counit_naturality, reassoc_of% h₁, Comonad.left_counit] simp · ext simpa [← T.ε.naturality_assoc, T.left_counit_assoc] using h₁ =≫ T.ε.app ((T : C ⥤ C).obj X.A) · intro m hm ext dsimp only rw [← hm] simp [beckCoalgebraFork, X.counit] /-- The Beck fork is a split equalizer. -/ def beckSplitEqualizer : IsSplitEqualizer (T.map X.a) (T.δ.app _) X.a := ⟨T.ε.app _, T.ε.app _, X.coassoc.symm, X.counit, T.left_counit _, (T.ε.naturality _)⟩ /-- This is the Beck fork. It is a split equalizer, in particular a equalizer. -/ @[simps! pt] def beckFork : Fork (T.map X.a) (T.δ.app _) := (beckSplitEqualizer X).asFork @[simp] theorem beckFork_ι : (beckFork X).ι = X.a := rfl /-- The Beck fork is a equalizer. -/ def beckEqualizer : IsLimit (beckFork X) := (beckSplitEqualizer X).isEqualizer @[simp] theorem beckEqualizer_lift (s : Fork (T.toFunctor.map X.a) (T.δ.app X.A)) : (beckEqualizer X).lift s = s.ι ≫ T.ε.app _ := rfl end Comonad end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Monad/Kleisli.lean
import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Monad.Basic /-! # Kleisli category on a (co)monad This file defines the Kleisli category on a monad `(T, η_ T, μ_ T)` as well as the co-Kleisli category on a comonad `(U, ε_ U, δ_ U)`. It also defines the Kleisli adjunction which gives rise to the monad `(T, η_ T, μ_ T)` as well as the co-Kleisli adjunction which gives rise to the comonad `(U, ε_ U, δ_ U)`. ## References * [Riehl, *Category theory in context*, Definition 5.2.9][riehl2017] -/ namespace CategoryTheory universe v u -- morphism levels before object levels. See note [category theory universes]. variable {C : Type u} [Category.{v} C] /-- The objects for the Kleisli category of the monad `T : Monad C`, which are the same thing as objects of the base category `C`. -/ @[nolint unusedArguments] def Kleisli (_T : Monad C) := C namespace Kleisli variable (T : Monad C) instance [Inhabited C] (T : Monad C) : Inhabited (Kleisli T) := ⟨(default : C)⟩ /-- The Kleisli category on a monad `T`. cf Definition 5.2.9 in [Riehl][riehl2017]. -/ instance category : Category (Kleisli T) where Hom := fun X Y : C => X ⟶ (T : C ⥤ C).obj Y id X := T.η.app X comp {_} {_} {Z} f g := f ≫ (T : C ⥤ C).map g ≫ T.μ.app Z id_comp {X} {Y} f := by rw [← T.η.naturality_assoc f, T.left_unit] apply Category.comp_id assoc f g h := by simp [Monad.assoc, T.mu_naturality_assoc] namespace Adjunction /-- The left adjoint of the adjunction which induces the monad `(T, η_ T, μ_ T)`. -/ @[simps] def toKleisli : C ⥤ Kleisli T where obj X := (X : Kleisli T) map {X} {Y} f := (f ≫ T.η.app Y : X ⟶ T.obj Y) map_comp {X} {Y} {Z} f g := by unfold_projs simp [← T.η.naturality g] /-- The right adjoint of the adjunction which induces the monad `(T, η_ T, μ_ T)`. -/ @[simps] def fromKleisli : Kleisli T ⥤ C where obj X := T.obj X map {_} {Y} f := T.map f ≫ T.μ.app Y map_id _ := T.right_unit _ map_comp {X} {Y} {Z} f g := by unfold_projs simp only [Functor.map_comp, Category.assoc] rw [← T.μ.naturality_assoc g, T.assoc] rfl /-- The Kleisli adjunction which gives rise to the monad `(T, η_ T, μ_ T)`. cf Lemma 5.2.11 of [Riehl][riehl2017]. -/ def adj : toKleisli T ⊣ fromKleisli T := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => Equiv.refl (X ⟶ T.obj Y) homEquiv_naturality_left_symm := fun {X} {Y} {Z} f g => by unfold_projs change f ≫ g = (f ≫ T.η.app Y) ≫ T.map g ≫ T.μ.app Z simp [← T.η.naturality_assoc g] } /-- The composition of the adjunction gives the original functor. -/ def toKleisliCompFromKleisliIsoSelf : toKleisli T ⋙ fromKleisli T ≅ T := NatIso.ofComponents fun _ => Iso.refl _ end Adjunction end Kleisli /-- The objects for the co-Kleisli category of the comonad `U : Comonad C`, which are the same thing as objects of the base category `C`. -/ @[nolint unusedArguments] def Cokleisli (_U : Comonad C) := C namespace Cokleisli variable (U : Comonad C) instance [Inhabited C] (U : Comonad C) : Inhabited (Cokleisli U) := ⟨(default : C)⟩ /-- The co-Kleisli category on a comonad `U`. -/ instance category : Category (Cokleisli U) where Hom := fun X Y : C => (U : C ⥤ C).obj X ⟶ Y id X := U.ε.app X comp f g := U.δ.app _ ≫ (U : C ⥤ C).map f ≫ g namespace Adjunction /-- The right adjoint of the adjunction which induces the comonad `(U, ε_ U, δ_ U)`. -/ @[simps] def toCokleisli : C ⥤ Cokleisli U where obj X := (X : Cokleisli U) map {X} {_} f := (U.ε.app X ≫ f :) map_comp {X} {Y} {_} f g := by unfold_projs simp /-- The left adjoint of the adjunction which induces the comonad `(U, ε_ U, δ_ U)`. -/ @[simps] def fromCokleisli : Cokleisli U ⥤ C where obj X := U.obj X map {X} {_} f := U.δ.app X ≫ U.map f map_id _ := U.right_counit _ map_comp {X} {Y} {_} f g := by unfold_projs simp only [Functor.map_comp, ← Category.assoc] rw [Comonad.coassoc] simp only [Category.assoc, NatTrans.naturality, Functor.comp_map] /-- The co-Kleisli adjunction which gives rise to the monad `(U, ε_ U, δ_ U)`. -/ def adj : fromCokleisli U ⊣ toCokleisli U := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => Equiv.refl (U.obj X ⟶ Y) homEquiv_naturality_right := fun {X} {Y} {_} f g => by unfold_projs simp } /-- The composition of the adjunction gives the original functor. -/ def toCokleisliCompFromCokleisliIsoSelf : toCokleisli U ⋙ fromCokleisli U ≅ U := NatIso.ofComponents fun _ => Iso.refl _ end Adjunction end Cokleisli end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Triangulated/Yoneda.lean
import Mathlib.Algebra.Homology.ShortComplex.Ab import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic import Mathlib.CategoryTheory.Shift.ShiftedHomOpposite import Mathlib.CategoryTheory.Triangulated.HomologicalFunctor import Mathlib.CategoryTheory.Triangulated.Opposite.Pretriangulated /-! # The Yoneda functors are homological Let `C` be a pretriangulated category. In this file, we show that the functors `preadditiveCoyoneda.obj A : C ⥤ AddCommGrpCat` for `A : Cᵒᵖ` and `preadditiveYoneda.obj B : Cᵒᵖ ⥤ AddCommGrpCat` for `B : C` are homological functors. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Limits variable {C : Type*} [Category C] [Preadditive C] [HasShift C ℤ] namespace CategoryTheory open Limits Opposite Pretriangulated.Opposite namespace Pretriangulated section variable [HasZeroObject C] [∀ (n : ℤ), (shiftFunctor C n).Additive] [Pretriangulated C] instance (A : Cᵒᵖ) : (preadditiveCoyoneda.obj A).IsHomological where exact T hT := by rw [ShortComplex.ab_exact_iff] intro (x₂ : A.unop ⟶ T.obj₂) (hx₂ : x₂ ≫ T.mor₂ = 0) obtain ⟨x₁, hx₁⟩ := T.coyoneda_exact₂ hT x₂ hx₂ exact ⟨x₁, hx₁.symm⟩ instance (B : C) : (preadditiveYoneda.obj B).IsHomological where exact T hT := by rw [ShortComplex.ab_exact_iff] intro (x₂ : T.obj₂.unop ⟶ B) (hx₂ : T.mor₂.unop ≫ x₂ = 0) obtain ⟨x₃, hx₃⟩ := Triangle.yoneda_exact₂ _ (unop_distinguished T hT) x₂ hx₂ exact ⟨x₃, hx₃.symm⟩ lemma preadditiveYoneda_map_distinguished (T : Triangle C) (hT : T ∈ distTriang C) (B : C) : ((shortComplexOfDistTriangle T hT).op.map (preadditiveYoneda.obj B)).Exact := (preadditiveYoneda.obj B).map_distinguished_op_exact T hT end noncomputable instance (A : Cᵒᵖ) : (preadditiveCoyoneda.obj A).ShiftSequence ℤ := Functor.ShiftSequence.tautological _ _ lemma preadditiveCoyoneda_homologySequenceδ_apply (T : Triangle C) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) {A : Cᵒᵖ} (x : A.unop ⟶ T.obj₃⟦n₀⟧) : (preadditiveCoyoneda.obj A).homologySequenceδ T n₀ n₁ h x = x ≫ T.mor₃⟦n₀⟧' ≫ (shiftFunctorAdd' C 1 n₀ n₁ (by cutsat)).inv.app _ := by apply Category.assoc section variable [∀ (n : ℤ), (shiftFunctor C n).Additive] noncomputable instance (B : C) : (preadditiveYoneda.obj B).ShiftSequence ℤ where sequence n := preadditiveYoneda.obj (B⟦n⟧) isoZero := preadditiveYoneda.mapIso ((shiftFunctorZero C ℤ).app B) shiftIso n a a' h := NatIso.ofComponents (fun A ↦ AddEquiv.toAddCommGrpIso { toEquiv := Quiver.Hom.opEquiv.trans (ShiftedHom.opEquiv' n a a' h).symm map_add' := fun _ _ ↦ ShiftedHom.opEquiv'_symm_add _ _ _ h }) (by intros; ext; apply ShiftedHom.opEquiv'_symm_comp _ _ _ h) shiftIso_zero a := by ext; apply ShiftedHom.opEquiv'_zero_add_symm shiftIso_add n m a a' a'' ha' ha'' := by ext _ x exact ShiftedHom.opEquiv'_add_symm n m a a' a'' ha' ha'' x.op lemma preadditiveYoneda_shiftMap_apply (B : C) {X Y : Cᵒᵖ} (n : ℤ) (f : X ⟶ Y⟦n⟧) (a a' : ℤ) (h : n + a = a') (z : X.unop ⟶ B⟦a⟧) : (preadditiveYoneda.obj B).shiftMap f a a' h z = ((ShiftedHom.opEquiv _).symm f).comp z (show a + n = a' by cutsat) := by symm apply ShiftedHom.opEquiv_symm_apply_comp lemma preadditiveYoneda_homologySequenceδ_apply (T : Triangle C) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) {B : C} (x : T.obj₁ ⟶ B⟦n₀⟧) : (preadditiveYoneda.obj B).homologySequenceδ ((triangleOpEquivalence _).functor.obj (op T)) n₀ n₁ h x = T.mor₃ ≫ x⟦(1 : ℤ)⟧' ≫ (shiftFunctorAdd' C n₀ 1 n₁ h).inv.app B := by simp only [Functor.homologySequenceδ, preadditiveYoneda_shiftMap_apply, ShiftedHom.comp, ← Category.assoc] congr 2 apply (ShiftedHom.opEquiv _).injective rw [Equiv.apply_symm_apply] rfl end end Pretriangulated end CategoryTheory
.lake/packages/mathlib/Mathlib/CategoryTheory/Triangulated/HomologicalFunctor.lean
import Mathlib.Algebra.Homology.ShortComplex.Exact import Mathlib.CategoryTheory.Shift.ShiftSequence import Mathlib.CategoryTheory.Triangulated.Functor import Mathlib.CategoryTheory.Triangulated.Subcategory import Mathlib.Algebra.Homology.ExactSequence /-! # Homological functors In this file, given a functor `F : C ⥤ A` from a pretriangulated category to an abelian category, we define the type class `F.IsHomological`, which is the property that `F` sends distinguished triangles in `C` to exact sequences in `A`. If `F` has been endowed with `[F.ShiftSequence ℤ]`, then we may think of the functor `F` as a `H^0`, and then the `H^n` functors are the functors `F.shift n : C ⥤ A`: we have isomorphisms `(F.shift n).obj X ≅ F.obj (X⟦n⟧)`, but through the choice of this "shift sequence", the user may provide functors with better definitional properties. Given a triangle `T` in `C`, we define a connecting homomorphism `F.homologySequenceδ T n₀ n₁ h : (F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁` under the assumption `h : n₀ + 1 = n₁`. When `T` is distinguished, this connecting homomorphism is part of a long exact sequence `... ⟶ (F.shift n₀).obj T.obj₁ ⟶ (F.shift n₀).obj T.obj₂ ⟶ (F.shift n₀).obj T.obj₃ ⟶ ...` The exactness of this long exact sequence is given by three lemmas `F.homologySequence_exact₁`, `F.homologySequence_exact₂` and `F.homologySequence_exact₃`. If `F` is a homological functor, we define the strictly full triangulated subcategory `F.homologicalKernel`: it consists of objects `X : C` such that for all `n : ℤ`, `(F.shift n).obj X` (or `F.obj (X⟦n⟧)`) is zero. We show that a morphism `f` in `C` belongs to `F.homologicalKernel.trW` (i.e. the cone of `f` is in this kernel) iff `(F.shift n).map f` is an isomorphism for all `n : ℤ`. Note: depending on the sources, homological functors are sometimes called cohomological functors, while certain authors use "cohomological functors" for "contravariant" functors (i.e. functors `Cᵒᵖ ⥤ A`). ## References * [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996] -/ namespace CategoryTheory open Category Limits Pretriangulated ZeroObject Preadditive variable {C D A : Type*} [Category C] [HasShift C ℤ] [Category D] [HasZeroObject D] [HasShift D ℤ] [Preadditive D] [∀ (n : ℤ), (CategoryTheory.shiftFunctor D n).Additive] [Pretriangulated D] [Category A] namespace Functor variable (F : C ⥤ A) /-- The kernel of a homological functor `F : C ⥤ A` is the strictly full triangulated subcategory consisting of objects `X` such that for all `n : ℤ`, `F.obj (X⟦n⟧)` is zero. -/ def homologicalKernel : ObjectProperty C := fun X ↦ ∀ (n : ℤ), IsZero (F.obj (X⟦n⟧)) lemma mem_homologicalKernel_iff [F.ShiftSequence ℤ] (X : C) : F.homologicalKernel X ↔ ∀ (n : ℤ), IsZero ((F.shift n).obj X) := by simp only [← fun (n : ℤ) => Iso.isZero_iff ((F.isoShift n).app X), homologicalKernel, comp_obj] section Pretriangulated variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive] [Pretriangulated C] [Abelian A] /-- A functor from a pretriangulated category to an abelian category is an homological functor if it sends distinguished triangles to exact sequences. -/ class IsHomological : Prop extends F.PreservesZeroMorphisms where exact (T : Triangle C) (hT : T ∈ distTriang C) : ((shortComplexOfDistTriangle T hT).map F).Exact lemma map_distinguished_exact [F.IsHomological] (T : Triangle C) (hT : T ∈ distTriang C) : ((shortComplexOfDistTriangle T hT).map F).Exact := IsHomological.exact _ hT instance (L : C ⥤ D) (F : D ⥤ A) [L.CommShift ℤ] [L.IsTriangulated] [F.IsHomological] : (L ⋙ F).IsHomological where exact T hT := F.map_distinguished_exact _ (L.map_distinguished T hT) lemma IsHomological.mk' [F.PreservesZeroMorphisms] (hF : ∀ (T : Pretriangulated.Triangle C) (hT : T ∈ distTriang C), ∃ (T' : Pretriangulated.Triangle C) (e : T ≅ T'), ((shortComplexOfDistTriangle T' (isomorphic_distinguished _ hT _ e.symm)).map F).Exact) : F.IsHomological where exact T hT := by obtain ⟨T', e, h'⟩ := hF T hT exact (ShortComplex.exact_iff_of_iso (F.mapShortComplex.mapIso ((shortComplexOfDistTriangleIsoOfIso e hT)))).2 h' lemma IsHomological.of_iso {F₁ F₂ : C ⥤ A} [F₁.IsHomological] (e : F₁ ≅ F₂) : F₂.IsHomological := have := preservesZeroMorphisms_of_iso e ⟨fun T hT => ShortComplex.exact_of_iso (ShortComplex.mapNatIso _ e) (F₁.map_distinguished_exact T hT)⟩ section variable [F.IsHomological] instance : F.homologicalKernel.IsClosedUnderIsomorphisms where of_iso e hX n := (hX n).of_iso ((shiftFunctor C n ⋙ F).mapIso e.symm) instance : F.homologicalKernel.IsTriangulated where exists_zero := ⟨0, isZero_zero C, fun n ↦ (shiftFunctor C n ⋙ F).map_isZero (isZero_zero C)⟩ toIsStableUnderShift := ⟨fun a ↦ ⟨fun X hX b ↦ (hX (a + b)).of_iso (F.mapIso ((shiftFunctorAdd C a b).app X).symm)⟩⟩ toIsTriangulatedClosed₂ := ObjectProperty.IsTriangulatedClosed₂.mk' (fun T hT h₁ h₃ n ↦ (F.map_distinguished_exact _ (Triangle.shift_distinguished T hT n)).isZero_of_both_zeros ((h₁ n).eq_of_src _ _) ((h₃ n).eq_of_tgt _ _)) end noncomputable instance (priority := 100) [F.IsHomological] : PreservesLimitsOfShape (Discrete WalkingPair) F := by suffices ∀ (X₁ X₂ : C), PreservesLimit (pair X₁ X₂) F from ⟨fun {X} => preservesLimit_of_iso_diagram F (diagramIsoPair X).symm⟩ intro X₁ X₂ have : HasBinaryBiproduct (F.obj X₁) (F.obj X₂) := HasBinaryBiproducts.has_binary_biproduct _ _ have : Mono (F.biprodComparison X₁ X₂) := by rw [mono_iff_cancel_zero] intro Z f hf let S := (ShortComplex.mk _ _ (biprod.inl_snd (X := X₁) (Y := X₂))).map F have : Mono S.f := by dsimp [S]; infer_instance have ex : S.Exact := F.map_distinguished_exact _ (binaryBiproductTriangle_distinguished X₁ X₂) obtain ⟨g, rfl⟩ := ex.lift' f (by simpa using hf =≫ biprod.snd) dsimp [S] at hf ⊢ replace hf := hf =≫ biprod.fst simp only [assoc, biprodComparison_fst, zero_comp, ← F.map_comp, biprod.inl_fst, F.map_id, comp_id] at hf rw [hf, zero_comp] have : PreservesBinaryBiproduct X₁ X₂ F := preservesBinaryBiproduct_of_mono_biprodComparison _ apply Limits.preservesBinaryProduct_of_preservesBinaryBiproduct instance (priority := 100) [F.IsHomological] : F.Additive := F.additive_of_preserves_binary_products lemma isHomological_of_localization (L : C ⥤ D) [L.CommShift ℤ] [L.IsTriangulated] [L.mapArrow.EssSurj] (F : D ⥤ A) (G : C ⥤ A) (e : L ⋙ F ≅ G) [G.IsHomological] : F.IsHomological := by have : F.PreservesZeroMorphisms := preservesZeroMorphisms_of_map_zero_object (F.mapIso L.mapZeroObject.symm ≪≫ e.app _ ≪≫ G.mapZeroObject) have : (L ⋙ F).IsHomological := IsHomological.of_iso e.symm refine IsHomological.mk' _ (fun T hT => ?_) rw [L.distTriang_iff] at hT obtain ⟨T₀, e, hT₀⟩ := hT exact ⟨L.mapTriangle.obj T₀, e, (L ⋙ F).map_distinguished_exact _ hT₀⟩ end Pretriangulated section /-- The connecting homomorphism in the long exact sequence attached to an homological functor and a distinguished triangle. -/ noncomputable def homologySequenceδ [F.ShiftSequence ℤ] (T : Triangle C) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) : (F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁ := F.shiftMap T.mor₃ n₀ n₁ (by rw [add_comm 1, h]) variable {T T'} @[reassoc] lemma homologySequenceδ_naturality [F.ShiftSequence ℤ] (T T' : Triangle C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) : (F.shift n₀).map φ.hom₃ ≫ F.homologySequenceδ T' n₀ n₁ h = F.homologySequenceδ T n₀ n₁ h ≫ (F.shift n₁).map φ.hom₁ := by dsimp only [homologySequenceδ] rw [← shiftMap_comp', ← φ.comm₃, shiftMap_comp] variable (T) variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive] [Pretriangulated C] [Abelian A] [F.IsHomological] variable [F.ShiftSequence ℤ] (T T' : Triangle C) (hT : T ∈ distTriang C) (hT' : T' ∈ distTriang C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) section include hT @[reassoc] lemma comp_homologySequenceδ : (F.shift n₀).map T.mor₂ ≫ F.homologySequenceδ T n₀ n₁ h = 0 := by dsimp only [homologySequenceδ] rw [← F.shiftMap_comp', comp_distTriang_mor_zero₂₃ _ hT, shiftMap_zero] @[reassoc] lemma homologySequenceδ_comp : F.homologySequenceδ T n₀ n₁ h ≫ (F.shift n₁).map T.mor₁ = 0 := by dsimp only [homologySequenceδ] rw [← F.shiftMap_comp, comp_distTriang_mor_zero₃₁ _ hT, shiftMap_zero] @[reassoc] lemma homologySequence_comp : (F.shift n₀).map T.mor₁ ≫ (F.shift n₀).map T.mor₂ = 0 := by rw [← Functor.map_comp, comp_distTriang_mor_zero₁₂ _ hT, Functor.map_zero] attribute [local simp] smul_smul lemma homologySequence_exact₂ : (ShortComplex.mk _ _ (F.homologySequence_comp T hT n₀)).Exact := by refine ShortComplex.exact_of_iso ?_ (F.map_distinguished_exact _ (Triangle.shift_distinguished _ hT n₀)) exact ShortComplex.isoMk ((F.isoShift n₀).app _) (n₀.negOnePow • ((F.isoShift n₀).app _)) ((F.isoShift n₀).app _) (by simp) (by simp) lemma homologySequence_exact₃ : (ShortComplex.mk _ _ (F.comp_homologySequenceδ T hT _ _ h)).Exact := by refine ShortComplex.exact_of_iso ?_ (F.homologySequence_exact₂ _ (rot_of_distTriang _ hT) n₀) exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _) ((F.shiftIso 1 n₀ n₁ (by cutsat)).app _) (by simp) (by simp [homologySequenceδ, shiftMap]) lemma homologySequence_exact₁ : (ShortComplex.mk _ _ (F.homologySequenceδ_comp T hT _ _ h)).Exact := by refine ShortComplex.exact_of_iso ?_ (F.homologySequence_exact₂ _ (inv_rot_of_distTriang _ hT) n₁) refine ShortComplex.isoMk (-((F.shiftIso (-1) n₁ n₀ (by cutsat)).app _)) (Iso.refl _) (Iso.refl _) ?_ (by simp) dsimp simp only [homologySequenceδ, neg_comp, map_neg, comp_id, F.shiftIso_hom_app_comp_shiftMap_of_add_eq_zero T.mor₃ (-1) (neg_add_cancel 1) n₀ n₁ (by cutsat)] lemma homologySequence_epi_shift_map_mor₁_iff : Epi ((F.shift n₀).map T.mor₁) ↔ (F.shift n₀).map T.mor₂ = 0 := (F.homologySequence_exact₂ T hT n₀).epi_f_iff lemma homologySequence_mono_shift_map_mor₁_iff : Mono ((F.shift n₁).map T.mor₁) ↔ F.homologySequenceδ T n₀ n₁ h = 0 := (F.homologySequence_exact₁ T hT n₀ n₁ h).mono_g_iff lemma homologySequence_epi_shift_map_mor₂_iff : Epi ((F.shift n₀).map T.mor₂) ↔ F.homologySequenceδ T n₀ n₁ h = 0 := (F.homologySequence_exact₃ T hT n₀ n₁ h).epi_f_iff lemma homologySequence_mono_shift_map_mor₂_iff : Mono ((F.shift n₀).map T.mor₂) ↔ (F.shift n₀).map T.mor₁ = 0 := (F.homologySequence_exact₂ T hT n₀).mono_g_iff end lemma mem_homologicalKernel_trW_iff {X Y : C} (f : X ⟶ Y) : F.homologicalKernel.trW f ↔ ∀ (n : ℤ), IsIso ((F.shift n).map f) := by obtain ⟨Z, g, h, hT⟩ := distinguished_cocone_triangle f apply (F.homologicalKernel.trW_iff_of_distinguished _ hT).trans have h₁ := fun n => (F.homologySequence_exact₃ _ hT n _ rfl).isZero_X₂_iff have h₂ := fun n => F.homologySequence_mono_shift_map_mor₁_iff _ hT n _ rfl have h₃ := fun n => F.homologySequence_epi_shift_map_mor₁_iff _ hT n dsimp at h₁ h₂ h₃ ⊢ simp only [mem_homologicalKernel_iff, h₁, ← h₂, ← h₃] constructor · intro h n obtain ⟨m, rfl⟩ : ∃ (m : ℤ), n = m + 1 := ⟨n - 1, by simp⟩ have := (h (m + 1)).1 have := (h m).2 apply isIso_of_mono_of_epi · intros constructor <;> infer_instance @[deprecated (since := "2025-07-21")] alias mem_homologicalKernel_W_iff := mem_homologicalKernel_trW_iff open ComposableArrows /-- The exact sequence with six terms starting from `(F.shift n₀).obj T.obj₁` until `(F.shift n₁).obj T.obj₃` when `T` is a distinguished triangle and `F` a homological functor. -/ @[simp] noncomputable def homologySequenceComposableArrows₅ : ComposableArrows A 5 := mk₅ ((F.shift n₀).map T.mor₁) ((F.shift n₀).map T.mor₂) (F.homologySequenceδ T n₀ n₁ h) ((F.shift n₁).map T.mor₁) ((F.shift n₁).map T.mor₂) include hT in lemma homologySequenceComposableArrows₅_exact : (F.homologySequenceComposableArrows₅ T n₀ n₁ h).Exact := exact_of_δ₀ (F.homologySequence_exact₂ T hT n₀).exact_toComposableArrows (exact_of_δ₀ (F.homologySequence_exact₃ T hT n₀ n₁ h).exact_toComposableArrows (exact_of_δ₀ (F.homologySequence_exact₁ T hT n₀ n₁ h).exact_toComposableArrows (F.homologySequence_exact₂ T hT n₁).exact_toComposableArrows)) end end Functor end CategoryTheory