path
stringlengths
11
71
content
stringlengths
75
124k
CategoryTheory\Limits\Shapes\ConcreteCategory.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Scott Morrison, Adam Topaz -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Types import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.ConcreteCategory.EpiMono import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Limits in concrete categories In this file, we combine the description of limits in `Types` and the API about the preservation of products and pullbacks in order to describe these limits in a concrete category `C`. If `F : J → C` is a family of objects in `C`, we define a bijection `Limits.Concrete.productEquiv F : (forget C).obj (∏ᶜ F) ≃ ∀ j, F j`. Similarly, if `f₁ : X₁ ⟶ S` and `f₂ : X₂ ⟶ S` are two morphisms, the elements in `pullback f₁ f₂` are identified by `Limits.Concrete.pullbackEquiv` to compatible tuples of elements in `X₁ × X₂`. Some results are also obtained for the terminal object, binary products, wide-pullbacks, wide-pushouts, multiequalizers and cokernels. -/ universe w v u t r namespace CategoryTheory.Limits.Concrete attribute [local instance] ConcreteCategory.instFunLike ConcreteCategory.hasCoeToSort variable {C : Type u} [Category.{v} C] section Products section ProductEquiv variable [ConcreteCategory.{max w v} C] {J : Type w} (F : J → C) [HasProduct F] [PreservesLimit (Discrete.functor F) (forget C)] /-- The equivalence `(forget C).obj (∏ᶜ F) ≃ ∀ j, F j` if `F : J → C` is a family of objects in a concrete category `C`. -/ noncomputable def productEquiv : (forget C).obj (∏ᶜ F) ≃ ∀ j, F j := ((PreservesProduct.iso (forget C) F) ≪≫ (Types.productIso.{w, v} (fun j => F j))).toEquiv @[simp] lemma productEquiv_apply_apply (x : (forget C).obj (∏ᶜ F)) (j : J) : productEquiv F x j = Pi.π F j x := congr_fun (piComparison_comp_π (forget C) F j) x @[simp] lemma productEquiv_symm_apply_π (x : ∀ j, F j) (j : J) : Pi.π F j ((productEquiv F).symm x) = x j := by rw [← productEquiv_apply_apply, Equiv.apply_symm_apply] end ProductEquiv section ProductExt variable {J : Type w} (f : J → C) [HasProduct f] {D : Type t} [Category.{r} D] [ConcreteCategory.{max w r} D] (F : C ⥤ D) [PreservesLimit (Discrete.functor f) F] [HasProduct fun j => F.obj (f j)] [PreservesLimitsOfShape WalkingCospan (forget D)] [PreservesLimit (Discrete.functor fun b ↦ F.toPrefunctor.obj (f b)) (forget D)] lemma Pi.map_ext (x y : F.obj (∏ᶜ f : C)) (h : ∀ i, F.map (Pi.π f i) x = F.map (Pi.π f i) y) : x = y := by apply ConcreteCategory.injective_of_mono_of_preservesPullback (PreservesProduct.iso F f).hom apply @Concrete.limit_ext.{w, w, r, t} D _ _ (Discrete J) _ _ _ _ (piComparison F _ x) (piComparison F _ y) intro ⟨(j : J)⟩ show ((forget D).map (piComparison F f) ≫ (forget D).map (limit.π _ _)) x = ((forget D).map (piComparison F f) ≫ (forget D).map _) y rw [← (forget D).map_comp, piComparison_comp_π] exact h j end ProductExt end Products section Terminal variable [ConcreteCategory.{w} C] /-- If `forget C` preserves terminals and `X` is terminal, then `(forget C).obj X` is a singleton. -/ noncomputable def uniqueOfTerminalOfPreserves [PreservesLimit (Functor.empty.{0} C) (forget C)] (X : C) (h : IsTerminal X) : Unique ((forget C).obj X) := Types.isTerminalEquivUnique ((forget C).obj X) <| IsTerminal.isTerminalObj (forget C) X h /-- If `forget C` reflects terminals and `(forget C).obj X` is a singleton, then `X` is terminal. -/ noncomputable def terminalOfUniqueOfReflects [ReflectsLimit (Functor.empty.{0} C) (forget C)] (X : C) (h : Unique ((forget C).obj X)) : IsTerminal X := IsTerminal.isTerminalOfObj (forget C) X <| (Types.isTerminalEquivUnique ((forget C).obj X)).symm h /-- The equivalence `IsTerminal X ≃ Unique ((forget C).obj X)` if the forgetful functor preserves and reflects terminals. -/ noncomputable def terminalIffUnique [PreservesLimit (Functor.empty.{0} C) (forget C)] [ReflectsLimit (Functor.empty.{0} C) (forget C)] (X : C) : IsTerminal X ≃ Unique ((forget C).obj X) := (IsTerminal.isTerminalIffObj (forget C) X).trans <| Types.isTerminalEquivUnique _ variable (C) variable [HasTerminal C] [PreservesLimit (Functor.empty.{0} C) (forget C)] /-- The equivalence `(forget C).obj (⊤_ C) ≃ PUnit` when `C` is a concrete category. -/ noncomputable def terminalEquiv : (forget C).obj (⊤_ C) ≃ PUnit := (PreservesTerminal.iso (forget C) ≪≫ Types.terminalIso).toEquiv noncomputable instance : Unique ((forget C).obj (⊤_ C)) where default := (terminalEquiv C).symm PUnit.unit uniq _ := (terminalEquiv C).injective (Subsingleton.elim _ _) end Terminal section Initial variable [ConcreteCategory.{w} C] /-- If `forget C` preserves initials and `X` is initial, then `(forget C).obj X` is empty. -/ lemma empty_of_initial_of_preserves [PreservesColimit (Functor.empty.{0} C) (forget C)] (X : C) (h : Nonempty (IsInitial X)) : IsEmpty ((forget C).obj X) := by rw [← Types.initial_iff_empty] exact Nonempty.map (IsInitial.isInitialObj (forget C) _) h /-- If `forget C` reflects initials and `(forget C).obj X` is empty, then `X` is initial. -/ lemma initial_of_empty_of_reflects [ReflectsColimit (Functor.empty.{0} C) (forget C)] (X : C) (h : IsEmpty ((forget C).obj X)) : Nonempty (IsInitial X) := Nonempty.map (IsInitial.isInitialOfObj (forget C) _) <| (Types.initial_iff_empty ((forget C).obj X)).mpr h /-- If `forget C` preserves and reflects initials, then `X` is initial if and only if `(forget C).obj X` is empty. -/ lemma initial_iff_empty_of_preserves_of_reflects [PreservesColimit (Functor.empty.{0} C) (forget C)] [ReflectsColimit (Functor.empty.{0} C) (forget C)] (X : C) : Nonempty (IsInitial X) ↔ IsEmpty ((forget C).obj X) := by rw [← Types.initial_iff_empty, (IsInitial.isInitialIffObj (forget C) X).nonempty_congr] end Initial section BinaryProducts variable [ConcreteCategory.{w} C] (X₁ X₂ : C) [HasBinaryProduct X₁ X₂] [PreservesLimit (pair X₁ X₂) (forget C)] /-- The equivalence `(forget C).obj (X₁ ⨯ X₂) ≃ ((forget C).obj X₁) × ((forget C).obj X₂)` if `X₁` and `X₂` are objects in a concrete category `C`. -/ noncomputable def prodEquiv : (forget C).obj (X₁ ⨯ X₂) ≃ X₁ × X₂ := (PreservesLimitPair.iso (forget C) X₁ X₂ ≪≫ Types.binaryProductIso _ _).toEquiv @[simp] lemma prodEquiv_apply_fst (x : (forget C).obj (X₁ ⨯ X₂)) : (prodEquiv X₁ X₂ x).fst = (Limits.prod.fst : X₁ ⨯ X₂ ⟶ X₁) x := congr_fun (prodComparison_fst (forget C) X₁ X₂) x @[simp] lemma prodEquiv_apply_snd (x : (forget C).obj (X₁ ⨯ X₂)) : (prodEquiv X₁ X₂ x).snd = (Limits.prod.snd : X₁ ⨯ X₂ ⟶ X₂) x := congr_fun (prodComparison_snd (forget C) X₁ X₂) x @[simp] lemma prodEquiv_symm_apply_fst (x : X₁ × X₂) : (Limits.prod.fst : X₁ ⨯ X₂ ⟶ X₁) ((prodEquiv X₁ X₂).symm x) = x.1 := by obtain ⟨y, rfl⟩ := (prodEquiv X₁ X₂).surjective x simp @[simp] lemma prodEquiv_symm_apply_snd (x : X₁ × X₂) : (Limits.prod.snd : X₁ ⨯ X₂ ⟶ X₂) ((prodEquiv X₁ X₂).symm x) = x.2 := by obtain ⟨y, rfl⟩ := (prodEquiv X₁ X₂).surjective x simp end BinaryProducts section Pullbacks variable [ConcreteCategory.{v} C] {X₁ X₂ S : C} (f₁ : X₁ ⟶ S) (f₂ : X₂ ⟶ S) [HasPullback f₁ f₂] [PreservesLimit (cospan f₁ f₂) (forget C)] /-- In a concrete category `C`, given two morphisms `f₁ : X₁ ⟶ S` and `f₂ : X₂ ⟶ S`, the elements in `pullback f₁ f₁` can be identified to compatible tuples of elements in `X₁` and `X₂`. -/ noncomputable def pullbackEquiv : (forget C).obj (pullback f₁ f₂) ≃ { p : X₁ × X₂ // f₁ p.1 = f₂ p.2 } := (PreservesPullback.iso (forget C) f₁ f₂ ≪≫ Types.pullbackIsoPullback ((forget C).map f₁) ((forget C).map f₂)).toEquiv /-- Constructor for elements in a pullback in a concrete category. -/ noncomputable def pullbackMk (x₁ : X₁) (x₂ : X₂) (h : f₁ x₁ = f₂ x₂) : (forget C).obj (pullback f₁ f₂) := (pullbackEquiv f₁ f₂).symm ⟨⟨x₁, x₂⟩, h⟩ lemma pullbackMk_surjective (x : (forget C).obj (pullback f₁ f₂)) : ∃ (x₁ : X₁) (x₂ : X₂) (h : f₁ x₁ = f₂ x₂), x = pullbackMk f₁ f₂ x₁ x₂ h := by obtain ⟨⟨⟨x₁, x₂⟩, h⟩, rfl⟩ := (pullbackEquiv f₁ f₂).symm.surjective x exact ⟨x₁, x₂, h, rfl⟩ @[simp] lemma pullbackMk_fst (x₁ : X₁) (x₂ : X₂) (h : f₁ x₁ = f₂ x₂) : pullback.fst f₁ f₂ (pullbackMk f₁ f₂ x₁ x₂ h) = x₁ := (congr_fun (PreservesPullback.iso_inv_fst (forget C) f₁ f₂) _).trans (congr_fun (Types.pullbackIsoPullback_inv_fst ((forget C).map f₁) ((forget C).map f₂)) _) @[simp] lemma pullbackMk_snd (x₁ : X₁) (x₂ : X₂) (h : f₁ x₁ = f₂ x₂) : pullback.snd f₁ f₂ (pullbackMk f₁ f₂ x₁ x₂ h) = x₂ := (congr_fun (PreservesPullback.iso_inv_snd (forget C) f₁ f₂) _).trans (congr_fun (Types.pullbackIsoPullback_inv_snd ((forget C).map f₁) ((forget C).map f₂)) _) end Pullbacks section WidePullback variable [ConcreteCategory.{max w v} C] open WidePullback open WidePullbackShape theorem widePullback_ext {B : C} {ι : Type w} {X : ι → C} (f : ∀ j : ι, X j ⟶ B) [HasWidePullback B X f] [PreservesLimit (wideCospan B X f) (forget C)] (x y : ↑(widePullback B X f)) (h₀ : base f x = base f y) (h : ∀ j, π f j x = π f j y) : x = y := by apply Concrete.limit_ext rintro (_ | j) · exact h₀ · apply h theorem widePullback_ext' {B : C} {ι : Type w} [Nonempty ι] {X : ι → C} (f : ∀ j : ι, X j ⟶ B) [HasWidePullback.{w} B X f] [PreservesLimit (wideCospan B X f) (forget C)] (x y : ↑(widePullback B X f)) (h : ∀ j, π f j x = π f j y) : x = y := by apply Concrete.widePullback_ext _ _ _ _ h inhabit ι simp only [← π_arrow f default, comp_apply, h] end WidePullback section Multiequalizer variable [ConcreteCategory.{max w v} C] theorem multiequalizer_ext {I : MulticospanIndex.{w} C} [HasMultiequalizer I] [PreservesLimit I.multicospan (forget C)] (x y : ↑(multiequalizer I)) (h : ∀ t : I.L, Multiequalizer.ι I t x = Multiequalizer.ι I t y) : x = y := by apply Concrete.limit_ext rintro (a | b) · apply h · rw [← limit.w I.multicospan (WalkingMulticospan.Hom.fst b), comp_apply, comp_apply] simp [h] /-- An auxiliary equivalence to be used in `multiequalizerEquiv` below. -/ def multiequalizerEquivAux (I : MulticospanIndex C) : (I.multicospan ⋙ forget C).sections ≃ { x : ∀ i : I.L, I.left i // ∀ i : I.R, I.fst i (x _) = I.snd i (x _) } where toFun x := ⟨fun i => x.1 (WalkingMulticospan.left _), fun i => by have a := x.2 (WalkingMulticospan.Hom.fst i) have b := x.2 (WalkingMulticospan.Hom.snd i) rw [← b] at a exact a⟩ invFun x := { val := fun j => match j with | WalkingMulticospan.left a => x.1 _ | WalkingMulticospan.right b => I.fst b (x.1 _) property := by rintro (a | b) (a' | b') (f | f | f) · simp · rfl · dsimp exact (x.2 b').symm · simp } left_inv := by intro x; ext (a | b) · rfl · rw [← x.2 (WalkingMulticospan.Hom.fst b)] rfl right_inv := by intro x ext i rfl /-- The equivalence between the noncomputable multiequalizer and the concrete multiequalizer. -/ noncomputable def multiequalizerEquiv (I : MulticospanIndex.{w} C) [HasMultiequalizer I] [PreservesLimit I.multicospan (forget C)] : (multiequalizer I : C) ≃ { x : ∀ i : I.L, I.left i // ∀ i : I.R, I.fst i (x _) = I.snd i (x _) } := letI h1 := limit.isLimit I.multicospan letI h2 := isLimitOfPreserves (forget C) h1 letI E := h2.conePointUniqueUpToIso (Types.limitConeIsLimit.{w, v} _) Equiv.trans E.toEquiv (Concrete.multiequalizerEquivAux.{w, v} I) @[simp] theorem multiequalizerEquiv_apply (I : MulticospanIndex.{w} C) [HasMultiequalizer I] [PreservesLimit I.multicospan (forget C)] (x : ↑(multiequalizer I)) (i : I.L) : ((Concrete.multiequalizerEquiv I) x : ∀ i : I.L, I.left i) i = Multiequalizer.ι I i x := rfl end Multiequalizer section WidePushout open WidePushout open WidePushoutShape variable [ConcreteCategory.{v} C] theorem widePushout_exists_rep {B : C} {α : Type _} {X : α → C} (f : ∀ j : α, B ⟶ X j) [HasWidePushout.{v} B X f] [PreservesColimit (wideSpan B X f) (forget C)] (x : ↑(widePushout B X f)) : (∃ y : B, head f y = x) ∨ ∃ (i : α) (y : X i), ι f i y = x := by obtain ⟨_ | j, y, rfl⟩ := Concrete.colimit_exists_rep _ x · left use y rfl · right use j, y rfl theorem widePushout_exists_rep' {B : C} {α : Type _} [Nonempty α] {X : α → C} (f : ∀ j : α, B ⟶ X j) [HasWidePushout.{v} B X f] [PreservesColimit (wideSpan B X f) (forget C)] (x : ↑(widePushout B X f)) : ∃ (i : α) (y : X i), ι f i y = x := by rcases Concrete.widePushout_exists_rep f x with (⟨y, rfl⟩ | ⟨i, y, rfl⟩) · inhabit α use default, f _ y simp only [← arrow_ι _ default, comp_apply] · use i, y end WidePushout -- We don't mark this as an `@[ext]` lemma as we don't always want to work elementwise. theorem cokernel_funext {C : Type*} [Category C] [HasZeroMorphisms C] [ConcreteCategory C] {M N K : C} {f : M ⟶ N} [HasCokernel f] {g h : cokernel f ⟶ K} (w : ∀ n : N, g (cokernel.π f n) = h (cokernel.π f n)) : g = h := by ext x simpa using w x -- TODO: Add analogous lemmas about coproducts and coequalizers. end CategoryTheory.Limits.Concrete
CategoryTheory\Limits\Shapes\Countable.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Countable import Mathlib.Data.Countable.Defs /-! # Countable limits and colimits A typeclass for categories with all countable (co)limits. We also prove that all cofiltered limits over countable preorders are isomorphic to sequential limits, see `sequentialFunctor_initial`. ## Projects * There is a series of `proof_wanted` at the bottom of this file, implying that all cofiltered limits over countable categories are isomorphic to sequential limits. * Prove the dual result for filtered colimits. -/ open CategoryTheory Opposite CountableCategory variable (C : Type*) [Category C] (J : Type*) [Countable J] namespace CategoryTheory.Limits /-- A category has all countable limits if every functor `J ⥤ C` with a `CountableCategory J` instance and `J : Type` has a limit. -/ class HasCountableLimits : Prop where /-- `C` has all limits over any type `J` whose objects and morphisms lie in the same universe and which has countably many objects and morphisms-/ out (J : Type) [SmallCategory J] [CountableCategory J] : HasLimitsOfShape J C instance (priority := 100) hasFiniteLimits_of_hasCountableLimits [HasCountableLimits C] : HasFiniteLimits C where out J := HasCountableLimits.out J instance (priority := 100) hasCountableLimits_of_hasLimits [HasLimits C] : HasCountableLimits C where out := inferInstance universe v in instance [Category.{v} J] [CountableCategory J] [HasCountableLimits C] : HasLimitsOfShape J C := have : HasLimitsOfShape (HomAsType J) C := HasCountableLimits.out (HomAsType J) hasLimitsOfShape_of_equivalence (homAsTypeEquiv J) /-- A category has all countable colimits if every functor `J ⥤ C` with a `CountableCategory J` instance and `J : Type` has a colimit. -/ class HasCountableColimits : Prop where /-- `C` has all limits over any type `J` whose objects and morphisms lie in the same universe and which has countably many objects and morphisms-/ out (J : Type) [SmallCategory J] [CountableCategory J] : HasColimitsOfShape J C instance (priority := 100) hasFiniteColimits_of_hasCountableColimits [HasCountableColimits C] : HasFiniteColimits C where out J := HasCountableColimits.out J instance (priority := 100) hasCountableColimits_of_hasColimits [HasColimits C] : HasCountableColimits C where out := inferInstance universe v in instance [Category.{v} J] [CountableCategory J] [HasCountableColimits C] : HasColimitsOfShape J C := have : HasColimitsOfShape (HomAsType J) C := HasCountableColimits.out (HomAsType J) hasColimitsOfShape_of_equivalence (homAsTypeEquiv J) section Preorder attribute [local instance] IsCofiltered.nonempty variable {C} [Preorder J] [IsCofiltered J] /-- The object part of the initial functor `ℕᵒᵖ ⥤ J` -/ noncomputable def sequentialFunctor_obj : ℕ → J := fun | .zero => (exists_surjective_nat _).choose 0 | .succ n => (IsCofilteredOrEmpty.cone_objs ((exists_surjective_nat _).choose n) (sequentialFunctor_obj n)).choose theorem sequentialFunctor_map : Antitone (sequentialFunctor_obj J) := antitone_nat_of_succ_le fun n ↦ leOfHom (IsCofilteredOrEmpty.cone_objs ((exists_surjective_nat _).choose n) (sequentialFunctor_obj J n)).choose_spec.choose_spec.choose /-- The initial functor `ℕᵒᵖ ⥤ J`, which allows us to turn cofiltered limits over countable preorders into sequential limits. -/ noncomputable def sequentialFunctor : ℕᵒᵖ ⥤ J where obj n := sequentialFunctor_obj J (unop n) map h := homOfLE (sequentialFunctor_map J (leOfHom h.unop)) theorem sequentialFunctor_initial_aux (j : J) : ∃ (n : ℕ), sequentialFunctor_obj J n ≤ j := by obtain ⟨m, h⟩ := (exists_surjective_nat _).choose_spec j refine ⟨m + 1, ?_⟩ simpa [h] using leOfHom (IsCofilteredOrEmpty.cone_objs ((exists_surjective_nat _).choose m) (sequentialFunctor_obj J m)).choose_spec.choose instance sequentialFunctor_initial : (sequentialFunctor J).Initial where out d := by obtain ⟨n, (g : (sequentialFunctor J).obj ⟨n⟩ ≤ d)⟩ := sequentialFunctor_initial_aux J d have : Nonempty (CostructuredArrow (sequentialFunctor J) d) := ⟨CostructuredArrow.mk (homOfLE g)⟩ apply isConnected_of_zigzag refine fun i j ↦ ⟨[j], ?_⟩ simp only [List.chain_cons, Zag, List.Chain.nil, and_true, ne_eq, not_false_eq_true, List.getLast_cons, not_true_eq_false, List.getLast_singleton'] wlog h : (unop i.left) ≤ (unop j.left) · exact or_comm.1 (this (C := C) J d n g inferInstance j i (le_of_lt (not_le.mp h))) · right exact ⟨CostructuredArrow.homMk (homOfLE h).op rfl⟩ /-- This is proved in https://stacks.math.columbia.edu/tag/0032 -/ proof_wanted preorder_of_cofiltered (J : Type*) [Category J] [IsCofiltered J] : ∃ (I : Type*) (_ : Preorder I) (_ : IsCofiltered I) (F : I ⥤ J), F.Initial /-- The proof of `preorder_of_cofiltered` should give a countable `I` in the case that `J` is a countable category. -/ proof_wanted preorder_of_cofiltered_countable (J : Type*) [SmallCategory J] [IsCofiltered J] [CountableCategory J] : ∃ (I : Type) (_ : Preorder I) (_ : Countable I) (_ : IsCofiltered I) (F : I ⥤ J), F.Initial /-- Put together `sequentialFunctor_initial` and `preorder_of_cofiltered_countable`. -/ proof_wanted hasCofilteredCountableLimits_of_hasSequentialLimits [HasLimitsOfShape ℕᵒᵖ C] : ∀ (J : Type) [SmallCategory J] [IsCofiltered J] [CountableCategory J], HasLimitsOfShape J C /-- This is the countable version of `CategoryTheory.Limits.has_limits_of_finite_and_cofiltered`, given all of the above. -/ proof_wanted hasCountableLimits_of_hasFiniteLimits_and_hasSequentialLimits [HasFiniteLimits C] [HasLimitsOfShape ℕᵒᵖ C] : HasCountableLimits C /-- For this we need to dualize this whole section. -/ proof_wanted hasCountableColimits_of_hasFiniteColimits_and_hasSequentialColimits [HasFiniteColimits C] [HasLimitsOfShape ℕ C] : HasCountableColimits C end Preorder end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Diagonal.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Adjunction.Over import Mathlib.CategoryTheory.Limits.Shapes.KernelPair import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Assoc /-! # The diagonal object of a morphism. We provide various API and isomorphisms considering the diagonal object `Δ_{Y/X} := pullback f f` of a morphism `f : X ⟶ Y`. -/ open CategoryTheory noncomputable section namespace CategoryTheory.Limits variable {C : Type*} [Category C] {X Y Z : C} namespace pullback section Diagonal variable (f : X ⟶ Y) [HasPullback f f] /-- The diagonal object of a morphism `f : X ⟶ Y` is `Δ_{X/Y} := pullback f f`. -/ abbrev diagonalObj : C := pullback f f /-- The diagonal morphism `X ⟶ Δ_{X/Y}` for a morphism `f : X ⟶ Y`. -/ def diagonal : X ⟶ diagonalObj f := pullback.lift (𝟙 _) (𝟙 _) rfl @[reassoc (attr := simp)] theorem diagonal_fst : diagonal f ≫ pullback.fst _ _ = 𝟙 _ := pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem diagonal_snd : diagonal f ≫ pullback.snd _ _ = 𝟙 _ := pullback.lift_snd _ _ _ instance : IsSplitMono (diagonal f) := ⟨⟨⟨pullback.fst _ _, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.fst f f) := ⟨⟨⟨diagonal f, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.snd f f) := ⟨⟨⟨diagonal f, diagonal_snd f⟩⟩⟩ instance [Mono f] : IsIso (diagonal f) := by rw [(IsIso.inv_eq_of_inv_hom_id (diagonal_fst f)).symm] infer_instance /-- The two projections `Δ_{X/Y} ⟶ X` form a kernel pair for `f : X ⟶ Y`. -/ theorem diagonal_isKernelPair : IsKernelPair f (pullback.fst f f) (pullback.snd f f) := IsPullback.of_hasPullback f f end Diagonal end pullback variable [HasPullbacks C] open pullback section variable {U V₁ V₂ : C} (f : X ⟶ Y) (i : U ⟶ Y) variable (i₁ : V₁ ⟶ pullback f i) (i₂ : V₂ ⟶ pullback f i) @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_fst_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (i₂ ≫ snd f i) f f (i₁ ≫ fst f i) (i₂ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ fst _ _ ≫ i₁ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_fst f, pullback.condition_assoc, pullback.lift_fst] @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_snd_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (i₂ ≫ snd f i) f f (i₁ ≫ fst f i) (i₂ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ snd _ _ ≫ i₂ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_snd f, pullback.condition_assoc, pullback.lift_snd] variable [HasPullback i₁ i₂] /-- The underlying map of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.hom : pullback (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) ⟶ pullback i₁ i₂ := pullback.lift (pullback.snd _ _ ≫ pullback.fst _ _) (pullback.snd _ _ ≫ pullback.snd _ _) (by ext · simp only [Category.assoc, pullback_diagonal_map_snd_fst_fst, pullback_diagonal_map_snd_snd_fst] · simp only [Category.assoc, condition]) /-- The underlying inverse of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.inv : pullback i₁ i₂ ⟶ pullback (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) := pullback.lift (pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _) (pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (pullback.snd _ _) (Category.id_comp _).symm (Category.id_comp _).symm) (by ext · simp only [Category.assoc, diagonal_fst, Category.comp_id, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, limit.lift_π_assoc, cospan_left] · simp only [condition_assoc, Category.assoc, diagonal_snd, Category.comp_id, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, limit.lift_π_assoc, cospan_right]) /-- This iso witnesses the fact that given `f : X ⟶ Y`, `i : U ⟶ Y`, and `i₁ : V₁ ⟶ X ×[Y] U`, `i₂ : V₂ ⟶ X ×[Y] U`, the diagram ``` V₁ ×[X ×[Y] U] V₂ ⟶ V₁ ×[U] V₂ | | | | ↓ ↓ X ⟶ X ×[Y] X ``` is a pullback square. Also see `pullback_fst_map_snd_isPullback`. -/ def pullbackDiagonalMapIso : pullback (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) ≅ pullback i₁ i₂ where hom := pullbackDiagonalMapIso.hom f i i₁ i₂ inv := pullbackDiagonalMapIso.inv f i i₁ i₂ @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.hom_fst : (pullbackDiagonalMapIso f i i₁ i₂).hom ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by delta pullbackDiagonalMapIso simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.hom_snd : (pullbackDiagonalMapIso f i i₁ i₂).hom ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta pullbackDiagonalMapIso simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.inv_fst : (pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.fst _ _ = pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _ := by delta pullbackDiagonalMapIso simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.inv_snd_fst : (pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := by delta pullbackDiagonalMapIso simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.inv_snd_snd : (pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := by delta pullbackDiagonalMapIso simp theorem pullback_fst_map_snd_isPullback : IsPullback (fst _ _ ≫ i₁ ≫ fst _ _) (map i₁ i₂ (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) _ _ _ (Category.id_comp _).symm (Category.id_comp _).symm) (diagonal f) (map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp [condition]) (by simp [condition])) := IsPullback.of_iso_pullback ⟨by ext <;> simp [condition_assoc]⟩ (pullbackDiagonalMapIso f i i₁ i₂).symm (pullbackDiagonalMapIso.inv_fst f i i₁ i₂) (by aesop_cat) end section variable {S T : C} (f : X ⟶ T) (g : Y ⟶ T) (i : T ⟶ S) variable [HasPullback i i] [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] variable [HasPullback (diagonal i) (pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _))] /-- This iso witnesses the fact that given `f : X ⟶ T`, `g : Y ⟶ T`, and `i : T ⟶ S`, the diagram ``` X ×ₜ Y ⟶ X ×ₛ Y | | | | ↓ ↓ T ⟶ T ×ₛ T ``` is a pullback square. Also see `pullback_map_diagonal_isPullback`. -/ def pullbackDiagonalMapIdIso : pullback (diagonal i) (pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _)) ≅ pullback f g := by refine ?_ ≪≫ pullbackDiagonalMapIso i (𝟙 _) (f ≫ inv (pullback.fst _ _)) (g ≫ inv (pullback.fst _ _)) ≪≫ ?_ · refine @asIso _ _ _ _ (pullback.map _ _ _ _ (𝟙 T) ((pullback.congrHom ?_ ?_).hom) (𝟙 _) ?_ ?_) ?_ · rw [← Category.comp_id (pullback.snd ..), ← condition, Category.assoc, IsIso.inv_hom_id_assoc] · rw [← Category.comp_id (pullback.snd ..), ← condition, Category.assoc, IsIso.inv_hom_id_assoc] · rw [Category.comp_id, Category.id_comp] · ext <;> simp · infer_instance · refine @asIso _ _ _ _ (pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (pullback.fst _ _) ?_ ?_) ?_ · rw [Category.assoc, IsIso.inv_hom_id, Category.comp_id, Category.id_comp] · rw [Category.assoc, IsIso.inv_hom_id, Category.comp_id, Category.id_comp] · infer_instance @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_hom_fst : (pullbackDiagonalMapIdIso f g i).hom ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by delta pullbackDiagonalMapIdIso simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_hom_snd : (pullbackDiagonalMapIdIso f g i).hom ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta pullbackDiagonalMapIdIso simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_inv_fst : (pullbackDiagonalMapIdIso f g i).inv ≫ pullback.fst _ _ = pullback.fst _ _ ≫ f := by rw [Iso.inv_comp_eq, ← Category.comp_id (pullback.fst _ _), ← diagonal_fst i, pullback.condition_assoc] simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_inv_snd_fst : (pullbackDiagonalMapIdIso f g i).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := by rw [Iso.inv_comp_eq] simp @[reassoc (attr := simp)] theorem pullbackDiagonalMapIdIso_inv_snd_snd : (pullbackDiagonalMapIdIso f g i).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := by rw [Iso.inv_comp_eq] simp theorem pullback.diagonal_comp (f : X ⟶ Y) (g : Y ⟶ Z) [HasPullback f f] [HasPullback g g] [HasPullback (f ≫ g) (f ≫ g)] : diagonal (f ≫ g) = diagonal f ≫ (pullbackDiagonalMapIdIso f f g).inv ≫ pullback.snd _ _ := by ext <;> simp theorem pullback_map_diagonal_isPullback : IsPullback (pullback.fst _ _ ≫ f) (pullback.map f g (f ≫ i) (g ≫ i) _ _ i (Category.id_comp _).symm (Category.id_comp _).symm) (diagonal i) (pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _)) := by apply IsPullback.of_iso_pullback _ (pullbackDiagonalMapIdIso f g i).symm · simp · ext <;> simp · constructor ext <;> simp [condition] /-- The diagonal object of `X ×[Z] Y ⟶ X` is isomorphic to `Δ_{Y/Z} ×[Z] X`. -/ def diagonalObjPullbackFstIso {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : diagonalObj (pullback.fst f g) ≅ pullback (pullback.snd _ _ ≫ g : diagonalObj g ⟶ Z) f := pullbackRightPullbackFstIso _ _ _ ≪≫ pullback.congrHom pullback.condition rfl ≪≫ pullbackAssoc _ _ _ _ ≪≫ pullbackSymmetry _ _ ≪≫ pullback.congrHom pullback.condition rfl @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_hom_fst_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).hom ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_hom_fst_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).hom ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_hom_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).hom ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_fst_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_fst_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_snd_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp @[reassoc (attr := simp)] theorem diagonalObjPullbackFstIso_inv_snd_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (diagonalObjPullbackFstIso f g).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta diagonalObjPullbackFstIso simp theorem diagonal_pullback_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : diagonal (pullback.fst f g) = (pullbackSymmetry _ _).hom ≫ ((Over.pullback f).map (Over.homMk (diagonal g) : Over.mk g ⟶ Over.mk (pullback.snd _ _ ≫ g))).left ≫ (diagonalObjPullbackFstIso f g).inv := by ext <;> dsimp <;> simp end /-- Given the following diagram with `S ⟶ S'` a monomorphism, ``` X ⟶ X' ↘ ↘ S ⟶ S' ↗ ↗ Y ⟶ Y' ``` This iso witnesses the fact that ``` X ×[S] Y ⟶ (X' ×[S'] Y') ×[Y'] Y | | | | ↓ ↓ (X' ×[S'] Y') ×[X'] X ⟶ X' ×[S'] Y' ``` is a pullback square. The diagonal map of this square is `pullback.map`. Also see `pullback_lift_map_is_pullback`. -/ @[simps] def pullbackFstFstIso {X Y S X' Y' S' : C} (f : X ⟶ S) (g : Y ⟶ S) (f' : X' ⟶ S') (g' : Y' ⟶ S') (i₁ : X ⟶ X') (i₂ : Y ⟶ Y') (i₃ : S ⟶ S') (e₁ : f ≫ i₃ = i₁ ≫ f') (e₂ : g ≫ i₃ = i₂ ≫ g') [Mono i₃] : pullback (pullback.fst _ _ : pullback (pullback.fst _ _ : pullback f' g' ⟶ _) i₁ ⟶ _) (pullback.fst _ _ : pullback (pullback.snd _ _ : pullback f' g' ⟶ _) i₂ ⟶ _) ≅ pullback f g where hom := pullback.lift (pullback.fst _ _ ≫ pullback.snd _ _) (pullback.snd _ _ ≫ pullback.snd _ _) (by rw [← cancel_mono i₃, Category.assoc, Category.assoc, Category.assoc, Category.assoc, e₁, e₂, ← pullback.condition_assoc, pullback.condition_assoc, pullback.condition, pullback.condition_assoc]) inv := pullback.lift (pullback.lift (pullback.map _ _ _ _ _ _ _ e₁ e₂) (pullback.fst _ _) (pullback.lift_fst ..)) (pullback.lift (pullback.map _ _ _ _ _ _ _ e₁ e₂) (pullback.snd _ _) (pullback.lift_snd ..)) (by rw [pullback.lift_fst, pullback.lift_fst]) hom_inv_id := by -- We could use `ext` here to immediately descend to the leaf goals, -- but it only obscures the structure. apply pullback.hom_ext · apply pullback.hom_ext · apply pullback.hom_ext · simp only [Category.assoc, lift_fst, lift_fst_assoc, Category.id_comp] rw [condition] · simp [Category.assoc, lift_snd, condition_assoc, condition] · simp only [Category.assoc, lift_fst_assoc, lift_snd, lift_fst, Category.id_comp] · apply pullback.hom_ext · apply pullback.hom_ext · simp only [Category.assoc, lift_snd_assoc, lift_fst_assoc, lift_fst, Category.id_comp] rw [← condition_assoc, condition] · simp only [Category.assoc, lift_snd, lift_fst_assoc, lift_snd_assoc, Category.id_comp] rw [condition] · simp only [Category.assoc, lift_snd_assoc, lift_snd, Category.id_comp] inv_hom_id := by apply pullback.hom_ext · simp only [Category.assoc, lift_fst, lift_fst_assoc, lift_snd, Category.id_comp] · simp only [Category.assoc, lift_snd, lift_snd_assoc, Category.id_comp] theorem pullback_map_eq_pullbackFstFstIso_inv {X Y S X' Y' S' : C} (f : X ⟶ S) (g : Y ⟶ S) (f' : X' ⟶ S') (g' : Y' ⟶ S') (i₁ : X ⟶ X') (i₂ : Y ⟶ Y') (i₃ : S ⟶ S') (e₁ : f ≫ i₃ = i₁ ≫ f') (e₂ : g ≫ i₃ = i₂ ≫ g') [Mono i₃] : pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂ = (pullbackFstFstIso f g f' g' i₁ i₂ i₃ e₁ e₂).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ := by simp only [pullbackFstFstIso_inv, lift_snd_assoc, lift_fst] theorem pullback_lift_map_isPullback {X Y S X' Y' S' : C} (f : X ⟶ S) (g : Y ⟶ S) (f' : X' ⟶ S') (g' : Y' ⟶ S') (i₁ : X ⟶ X') (i₂ : Y ⟶ Y') (i₃ : S ⟶ S') (e₁ : f ≫ i₃ = i₁ ≫ f') (e₂ : g ≫ i₃ = i₂ ≫ g') [Mono i₃] : IsPullback (pullback.lift (pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂) (fst _ _) (lift_fst _ _ _)) (pullback.lift (pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂) (snd _ _) (lift_snd _ _ _)) (pullback.fst _ _) (pullback.fst _ _) := IsPullback.of_iso_pullback ⟨by rw [lift_fst, lift_fst]⟩ (pullbackFstFstIso f g f' g' i₁ i₂ i₃ e₁ e₂).symm (by simp) (by simp) end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\DisjointCoproduct.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Disjoint coproducts Defines disjoint coproducts: coproducts where the intersection is initial and the coprojections are monic. Shows that a category with disjoint coproducts is `InitialMonoClass`. ## TODO * Adapt this to the infinitary (small) version: This is one of the conditions in Giraud's theorem characterising sheaf topoi. * Construct examples (and counterexamples?), eg Type, Vec. * Define extensive categories, and show every extensive category has disjoint coproducts. * Define coherent categories and use this to define positive coherent categories. -/ universe v u u₂ namespace CategoryTheory namespace Limits open Category variable {C : Type u} [Category.{v} C] /-- Given any pullback diagram of the form ``` Z ⟶ X₁ ↓ ↓ X₂ ⟶ X ``` where `X₁ ⟶ X ← X₂` is a coproduct diagram, then `Z` is initial, and both `X₁ ⟶ X` and `X₂ ⟶ X` are mono. -/ class CoproductDisjoint (X₁ X₂ : C) where isInitialOfIsPullbackOfIsCoproduct : ∀ {X Z} {pX₁ : X₁ ⟶ X} {pX₂ : X₂ ⟶ X} {f : Z ⟶ X₁} {g : Z ⟶ X₂} (_cX : IsColimit (BinaryCofan.mk pX₁ pX₂)) {comm : f ≫ pX₁ = g ≫ pX₂}, IsLimit (PullbackCone.mk _ _ comm) → IsInitial Z mono_inl : ∀ (X) (X₁ : X₁ ⟶ X) (X₂ : X₂ ⟶ X) (_cX : IsColimit (BinaryCofan.mk X₁ X₂)), Mono X₁ mono_inr : ∀ (X) (X₁ : X₁ ⟶ X) (X₂ : X₂ ⟶ X) (_cX : IsColimit (BinaryCofan.mk X₁ X₂)), Mono X₂ /-- If the coproduct of `X₁` and `X₂` is disjoint, then given any pullback square ``` Z ⟶ X₁ ↓ ↓ X₂ ⟶ X ``` where `X₁ ⟶ X ← X₂` is a coproduct, then `Z` is initial. -/ def isInitialOfIsPullbackOfIsCoproduct {Z X₁ X₂ X : C} [CoproductDisjoint X₁ X₂] {pX₁ : X₁ ⟶ X} {pX₂ : X₂ ⟶ X} (cX : IsColimit (BinaryCofan.mk pX₁ pX₂)) {f : Z ⟶ X₁} {g : Z ⟶ X₂} {comm : f ≫ pX₁ = g ≫ pX₂} (cZ : IsLimit (PullbackCone.mk _ _ comm)) : IsInitial Z := CoproductDisjoint.isInitialOfIsPullbackOfIsCoproduct cX cZ /-- If the coproduct of `X₁` and `X₂` is disjoint, then given any pullback square ``` Z ⟶ X₁ ↓ ↓ X₂ ⟶ X₁ ⨿ X₂ ``` `Z` is initial. -/ noncomputable def isInitialOfIsPullbackOfCoproduct {Z X₁ X₂ : C} [HasBinaryCoproduct X₁ X₂] [CoproductDisjoint X₁ X₂] {f : Z ⟶ X₁} {g : Z ⟶ X₂} {comm : f ≫ (coprod.inl : X₁ ⟶ _ ⨿ X₂) = g ≫ coprod.inr} (cZ : IsLimit (PullbackCone.mk _ _ comm)) : IsInitial Z := CoproductDisjoint.isInitialOfIsPullbackOfIsCoproduct (coprodIsCoprod _ _) cZ /-- If the coproduct of `X₁` and `X₂` is disjoint, then provided `X₁ ⟶ X ← X₂` is a coproduct the pullback is an initial object: ``` X₁ ↓ X₂ ⟶ X ``` -/ noncomputable def isInitialOfPullbackOfIsCoproduct {X X₁ X₂ : C} [CoproductDisjoint X₁ X₂] {pX₁ : X₁ ⟶ X} {pX₂ : X₂ ⟶ X} [HasPullback pX₁ pX₂] (cX : IsColimit (BinaryCofan.mk pX₁ pX₂)) : IsInitial (pullback pX₁ pX₂) := CoproductDisjoint.isInitialOfIsPullbackOfIsCoproduct cX (pullbackIsPullback _ _) /-- If the coproduct of `X₁` and `X₂` is disjoint, the pullback of `X₁ ⟶ X₁ ⨿ X₂` and `X₂ ⟶ X₁ ⨿ X₂` is initial. -/ noncomputable def isInitialOfPullbackOfCoproduct {X₁ X₂ : C} [HasBinaryCoproduct X₁ X₂] [CoproductDisjoint X₁ X₂] [HasPullback (coprod.inl : X₁ ⟶ _ ⨿ X₂) coprod.inr] : IsInitial (pullback (coprod.inl : X₁ ⟶ _ ⨿ X₂) coprod.inr) := isInitialOfIsPullbackOfCoproduct (pullbackIsPullback _ _) instance {X₁ X₂ : C} [HasBinaryCoproduct X₁ X₂] [CoproductDisjoint X₁ X₂] : Mono (coprod.inl : X₁ ⟶ X₁ ⨿ X₂) := CoproductDisjoint.mono_inl _ _ _ (coprodIsCoprod _ _) instance {X₁ X₂ : C} [HasBinaryCoproduct X₁ X₂] [CoproductDisjoint X₁ X₂] : Mono (coprod.inr : X₂ ⟶ X₁ ⨿ X₂) := CoproductDisjoint.mono_inr _ _ _ (coprodIsCoprod _ _) /-- `C` has disjoint coproducts if every coproduct is disjoint. -/ class CoproductsDisjoint (C : Type u) [Category.{v} C] where CoproductDisjoint : ∀ X Y : C, CoproductDisjoint X Y attribute [instance 999] CoproductsDisjoint.CoproductDisjoint /-- If `C` has disjoint coproducts, any morphism out of initial is mono. Note it isn't true in general that `C` has strict initial objects, for instance consider the category of types and partial functions. -/ theorem initialMonoClass_of_disjoint_coproducts [CoproductsDisjoint C] : InitialMonoClass C where isInitial_mono_from X hI := CoproductDisjoint.mono_inl X (IsInitial.to hI X) (CategoryTheory.CategoryStruct.id X) { desc := fun s : BinaryCofan _ _ => s.inr fac := fun _s j => Discrete.casesOn j fun j => WalkingPair.casesOn j (hI.hom_ext _ _) (id_comp _) uniq := fun (_s : BinaryCofan _ _) _m w => (id_comp _).symm.trans (w ⟨WalkingPair.right⟩) } end Limits end CategoryTheory
CategoryTheory\Limits\Shapes\Equalizers.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.HasLimits /-! # Equalizers and coequalizers This file defines (co)equalizers as special cases of (co)limits. An equalizer is the categorical generalization of the subobject {a ∈ A | f(a) = g(a)} known from abelian groups or modules. It is a limit cone over the diagram formed by `f` and `g`. A coequalizer is the dual concept. ## Main definitions * `WalkingParallelPair` is the indexing category used for (co)equalizer_diagrams * `parallelPair` is a functor from `WalkingParallelPair` to our category `C`. * a `fork` is a cone over a parallel pair. * there is really only one interesting morphism in a fork: the arrow from the vertex of the fork to the domain of f and g. It is called `fork.ι`. * an `equalizer` is now just a `limit (parallelPair f g)` Each of these has a dual. ## Main statements * `equalizer.ι_mono` states that every equalizer map is a monomorphism * `isIso_limit_cone_parallelPair_of_self` states that the identity on the domain of `f` is an equalizer of `f` and `f`. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ /- Porting note: removed global noncomputable since there are things that might be computable value like WalkingPair -/ section open CategoryTheory Opposite namespace CategoryTheory.Limits -- attribute [local tidy] tactic.case_bash -- Porting note: no tidy nor cases_bash universe v v₂ u u₂ /-- The type of objects for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPair : Type | zero | one deriving DecidableEq, Inhabited open WalkingParallelPair /-- The type family of morphisms for the diagram indexing a (co)equalizer. -/ inductive WalkingParallelPairHom : WalkingParallelPair → WalkingParallelPair → Type | left : WalkingParallelPairHom zero one | right : WalkingParallelPairHom zero one | id (X : WalkingParallelPair) : WalkingParallelPairHom X X deriving DecidableEq /- Porting note: this simplifies using walkingParallelPairHom_id; replacement is below; simpNF still complains of striking this from the simp list -/ attribute [-simp, nolint simpNF] WalkingParallelPairHom.id.sizeOf_spec /-- Satisfying the inhabited linter -/ instance : Inhabited (WalkingParallelPairHom zero one) where default := WalkingParallelPairHom.left open WalkingParallelPairHom /-- Composition of morphisms in the indexing diagram for (co)equalizers. -/ def WalkingParallelPairHom.comp : -- Porting note: changed X Y Z to implicit to match comp fields in precategory ∀ {X Y Z : WalkingParallelPair} (_ : WalkingParallelPairHom X Y) (_ : WalkingParallelPairHom Y Z), WalkingParallelPairHom X Z | _, _, _, id _, h => h | _, _, _, left, id one => left | _, _, _, right, id one => right -- Porting note: adding these since they are simple and aesop couldn't directly prove them theorem WalkingParallelPairHom.id_comp {X Y : WalkingParallelPair} (g : WalkingParallelPairHom X Y) : comp (id X) g = g := rfl theorem WalkingParallelPairHom.comp_id {X Y : WalkingParallelPair} (f : WalkingParallelPairHom X Y) : comp f (id Y) = f := by cases f <;> rfl theorem WalkingParallelPairHom.assoc {X Y Z W : WalkingParallelPair} (f : WalkingParallelPairHom X Y) (g : WalkingParallelPairHom Y Z) (h : WalkingParallelPairHom Z W) : comp (comp f g) h = comp f (comp g h) := by cases f <;> cases g <;> cases h <;> rfl instance walkingParallelPairHomCategory : SmallCategory WalkingParallelPair where Hom := WalkingParallelPairHom id := id comp := comp comp_id := comp_id id_comp := id_comp assoc := assoc @[simp] theorem walkingParallelPairHom_id (X : WalkingParallelPair) : WalkingParallelPairHom.id X = 𝟙 X := rfl -- Porting note: simpNF asked me to do this because the LHS of the non-primed version reduced @[simp] theorem WalkingParallelPairHom.id.sizeOf_spec' (X : WalkingParallelPair) : (WalkingParallelPairHom._sizeOf_inst X X).sizeOf (𝟙 X) = 1 + sizeOf X := by cases X <;> rfl /-- The functor `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ def walkingParallelPairOp : WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ where obj x := op <| by cases x; exacts [one, zero] map f := by cases f <;> apply Quiver.Hom.op exacts [left, right, WalkingParallelPairHom.id _] map_comp := by rintro _ _ _ (_|_|_) g <;> cases g <;> rfl @[simp] theorem walkingParallelPairOp_zero : walkingParallelPairOp.obj zero = op one := rfl @[simp] theorem walkingParallelPairOp_one : walkingParallelPairOp.obj one = op zero := rfl @[simp] theorem walkingParallelPairOp_left : walkingParallelPairOp.map left = @Quiver.Hom.op _ _ zero one left := rfl @[simp] theorem walkingParallelPairOp_right : walkingParallelPairOp.map right = @Quiver.Hom.op _ _ zero one right := rfl /-- The equivalence `WalkingParallelPair ⥤ WalkingParallelPairᵒᵖ` sending left to left and right to right. -/ @[simps functor inverse] def walkingParallelPairOpEquiv : WalkingParallelPair ≌ WalkingParallelPairᵒᵖ where functor := walkingParallelPairOp inverse := walkingParallelPairOp.leftOp unitIso := NatIso.ofComponents (fun j => eqToIso (by cases j <;> rfl)) (by rintro _ _ (_ | _ | _) <;> simp) counitIso := NatIso.ofComponents (fun j => eqToIso (by induction' j with X cases X <;> rfl)) (fun {i} {j} f => by induction' i with i induction' j with j let g := f.unop have : f = g.op := rfl rw [this] cases i <;> cases j <;> cases g <;> rfl) functor_unitIso_comp := fun j => by cases j <;> rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_zero : walkingParallelPairOpEquiv.unitIso.app zero = Iso.refl zero := rfl @[simp] theorem walkingParallelPairOpEquiv_unitIso_one : walkingParallelPairOpEquiv.unitIso.app one = Iso.refl one := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_zero : walkingParallelPairOpEquiv.counitIso.app (op zero) = Iso.refl (op zero) := rfl @[simp] theorem walkingParallelPairOpEquiv_counitIso_one : walkingParallelPairOpEquiv.counitIso.app (op one) = Iso.refl (op one) := rfl variable {C : Type u} [Category.{v} C] variable {X Y : C} /-- `parallelPair f g` is the diagram in `C` consisting of the two morphisms `f` and `g` with common domain and codomain. -/ def parallelPair (f g : X ⟶ Y) : WalkingParallelPair ⥤ C where obj x := match x with | zero => X | one => Y map h := match h with | WalkingParallelPairHom.id _ => 𝟙 _ | left => f | right => g -- `sorry` can cope with this, but it's too slow: map_comp := by rintro _ _ _ ⟨⟩ g <;> cases g <;> {dsimp; simp} @[simp] theorem parallelPair_obj_zero (f g : X ⟶ Y) : (parallelPair f g).obj zero = X := rfl @[simp] theorem parallelPair_obj_one (f g : X ⟶ Y) : (parallelPair f g).obj one = Y := rfl @[simp] theorem parallelPair_map_left (f g : X ⟶ Y) : (parallelPair f g).map left = f := rfl @[simp] theorem parallelPair_map_right (f g : X ⟶ Y) : (parallelPair f g).map right = g := rfl @[simp] theorem parallelPair_functor_obj {F : WalkingParallelPair ⥤ C} (j : WalkingParallelPair) : (parallelPair (F.map left) (F.map right)).obj j = F.obj j := by cases j <;> rfl /-- Every functor indexing a (co)equalizer is naturally isomorphic (actually, equal) to a `parallelPair` -/ @[simps!] def diagramIsoParallelPair (F : WalkingParallelPair ⥤ C) : F ≅ parallelPair (F.map left) (F.map right) := NatIso.ofComponents (fun j => eqToIso <| by cases j <;> rfl) (by rintro _ _ (_|_|_) <;> simp) /-- Construct a morphism between parallel pairs. -/ def parallelPairHom {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : parallelPair f g ⟶ parallelPair f' g' where app j := match j with | zero => p | one => q naturality := by rintro _ _ ⟨⟩ <;> {dsimp; simp [wf,wg]} @[simp] theorem parallelPairHom_app_zero {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app zero = p := rfl @[simp] theorem parallelPairHom_app_one {X' Y' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') : (parallelPairHom f g f' g' p q wf wg).app one = q := rfl /-- Construct a natural isomorphism between functors out of the walking parallel pair from its components. -/ @[simps!] def parallelPair.ext {F G : WalkingParallelPair ⥤ C} (zero : F.obj zero ≅ G.obj zero) (one : F.obj one ≅ G.obj one) (left : F.map left ≫ one.hom = zero.hom ≫ G.map left) (right : F.map right ≫ one.hom = zero.hom ≫ G.map right) : F ≅ G := NatIso.ofComponents (by rintro ⟨j⟩ exacts [zero, one]) (by rintro _ _ ⟨_⟩ <;> simp [left, right]) /-- Construct a natural isomorphism between `parallelPair f g` and `parallelPair f' g'` given equalities `f = f'` and `g = g'`. -/ @[simps!] def parallelPair.eqOfHomEq {f g f' g' : X ⟶ Y} (hf : f = f') (hg : g = g') : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simp [hf]) (by simp [hg]) /-- A fork on `f` and `g` is just a `Cone (parallelPair f g)`. -/ abbrev Fork (f g : X ⟶ Y) := Cone (parallelPair f g) /-- A cofork on `f` and `g` is just a `Cocone (parallelPair f g)`. -/ abbrev Cofork (f g : X ⟶ Y) := Cocone (parallelPair f g) variable {f g : X ⟶ Y} /-- A fork `t` on the parallel pair `f g : X ⟶ Y` consists of two morphisms `t.π.app zero : t.pt ⟶ X` and `t.π.app one : t.pt ⟶ Y`. Of these, only the first one is interesting, and we give it the shorter name `Fork.ι t`. -/ def Fork.ι (t : Fork f g) := t.π.app zero @[simp] theorem Fork.app_zero_eq_ι (t : Fork f g) : t.π.app zero = t.ι := rfl /-- A cofork `t` on the parallelPair `f g : X ⟶ Y` consists of two morphisms `t.ι.app zero : X ⟶ t.pt` and `t.ι.app one : Y ⟶ t.pt`. Of these, only the second one is interesting, and we give it the shorter name `Cofork.π t`. -/ def Cofork.π (t : Cofork f g) := t.ι.app one @[simp] theorem Cofork.app_one_eq_π (t : Cofork f g) : t.ι.app one = t.π := rfl @[simp] theorem Fork.app_one_eq_ι_comp_left (s : Fork f g) : s.π.app one = s.ι ≫ f := by rw [← s.app_zero_eq_ι, ← s.w left, parallelPair_map_left] @[reassoc] theorem Fork.app_one_eq_ι_comp_right (s : Fork f g) : s.π.app one = s.ι ≫ g := by rw [← s.app_zero_eq_ι, ← s.w right, parallelPair_map_right] @[simp] theorem Cofork.app_zero_eq_comp_π_left (s : Cofork f g) : s.ι.app zero = f ≫ s.π := by rw [← s.app_one_eq_π, ← s.w left, parallelPair_map_left] @[reassoc] theorem Cofork.app_zero_eq_comp_π_right (s : Cofork f g) : s.ι.app zero = g ≫ s.π := by rw [← s.app_one_eq_π, ← s.w right, parallelPair_map_right] /-- A fork on `f g : X ⟶ Y` is determined by the morphism `ι : P ⟶ X` satisfying `ι ≫ f = ι ≫ g`. -/ @[simps] def Fork.ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : Fork f g where pt := P π := { app := fun X => by cases X · exact ι · exact ι ≫ f naturality := fun {X} {Y} f => by cases X <;> cases Y <;> cases f <;> dsimp <;> simp; assumption } /-- A cofork on `f g : X ⟶ Y` is determined by the morphism `π : Y ⟶ P` satisfying `f ≫ π = g ≫ π`. -/ @[simps] def Cofork.ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : Cofork f g where pt := P ι := { app := fun X => WalkingParallelPair.casesOn X (f ≫ π) π naturality := fun i j f => by cases f <;> dsimp <;> simp [w] } -- See note [dsimp, simp] @[simp] theorem Fork.ι_ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : (Fork.ofι ι w).ι = ι := rfl @[simp] theorem Cofork.π_ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : (Cofork.ofπ π w).π = π := rfl @[reassoc (attr := simp)] theorem Fork.condition (t : Fork f g) : t.ι ≫ f = t.ι ≫ g := by rw [← t.app_one_eq_ι_comp_left, ← t.app_one_eq_ι_comp_right] @[reassoc (attr := simp)] theorem Cofork.condition (t : Cofork f g) : f ≫ t.π = g ≫ t.π := by rw [← t.app_zero_eq_comp_π_left, ← t.app_zero_eq_comp_π_right] /-- To check whether two maps are equalized by both maps of a fork, it suffices to check it for the first map -/ theorem Fork.equalizer_ext (s : Fork f g) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelPair, k ≫ s.π.app j = l ≫ s.π.app j | zero => h | one => by have : k ≫ ι s ≫ f = l ≫ ι s ≫ f := by simp only [← Category.assoc]; exact congrArg (· ≫ f) h rw [s.app_one_eq_ι_comp_left, this] /-- To check whether two maps are coequalized by both maps of a cofork, it suffices to check it for the second map -/ theorem Cofork.coequalizer_ext (s : Cofork f g) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : ∀ j : WalkingParallelPair, s.ι.app j ≫ k = s.ι.app j ≫ l | zero => by simp only [s.app_zero_eq_comp_π_left, Category.assoc, h] | one => h theorem Fork.IsLimit.hom_ext {s : Fork f g} (hs : IsLimit s) {W : C} {k l : W ⟶ s.pt} (h : k ≫ Fork.ι s = l ≫ Fork.ι s) : k = l := hs.hom_ext <| Fork.equalizer_ext _ h theorem Cofork.IsColimit.hom_ext {s : Cofork f g} (hs : IsColimit s) {W : C} {k l : s.pt ⟶ W} (h : Cofork.π s ≫ k = Cofork.π s ≫ l) : k = l := hs.hom_ext <| Cofork.coequalizer_ext _ h @[reassoc (attr := simp)] theorem Fork.IsLimit.lift_ι {s t : Fork f g} (hs : IsLimit s) : hs.lift t ≫ s.ι = t.ι := hs.fac _ _ @[reassoc (attr := simp)] theorem Cofork.IsColimit.π_desc {s t : Cofork f g} (hs : IsColimit s) : s.π ≫ hs.desc t = t.π := hs.fac _ _ -- Porting note: `Fork.IsLimit.lift` was added in order to ease the port /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/ def Fork.IsLimit.lift {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : W ⟶ s.pt := hs.lift (Fork.ofι _ h) @[reassoc (attr := simp)] lemma Fork.IsLimit.lift_ι' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : Fork.IsLimit.lift hs k h ≫ Fork.ι s = k := hs.fac _ _ /-- If `s` is a limit fork over `f` and `g`, then a morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ s.pt` such that `l ≫ fork.ι s = k`. -/ def Fork.IsLimit.lift' {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : { l : W ⟶ s.pt // l ≫ Fork.ι s = k } := ⟨Fork.IsLimit.lift hs k h, by simp⟩ -- Porting note: `Cofork.IsColimit.desc` was added in order to ease the port /-- If `s` is a colimit cofork over `f` and `g`, then a morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : s.pt ⟶ W` such that `cofork.π s ≫ l = k`. -/ def Cofork.IsColimit.desc {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : s.pt ⟶ W := hs.desc (Cofork.ofπ _ h) @[reassoc (attr := simp)] lemma Cofork.IsColimit.π_desc' {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : Cofork.π s ≫ Cofork.IsColimit.desc hs k h = k := hs.fac _ _ /-- If `s` is a colimit cofork over `f` and `g`, then a morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : s.pt ⟶ W` such that `cofork.π s ≫ l = k`. -/ def Cofork.IsColimit.desc' {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : { l : s.pt ⟶ W // Cofork.π s ≫ l = k } := ⟨Cofork.IsColimit.desc hs k h, by simp⟩ theorem Fork.IsLimit.existsUnique {s : Fork f g} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : ∃! l : W ⟶ s.pt, l ≫ Fork.ι s = k := ⟨hs.lift <| Fork.ofι _ h, hs.fac _ _, fun _ hm => Fork.IsLimit.hom_ext hs <| hm.symm ▸ (hs.fac (Fork.ofι _ h) WalkingParallelPair.zero).symm⟩ theorem Cofork.IsColimit.existsUnique {s : Cofork f g} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : ∃! d : s.pt ⟶ W, Cofork.π s ≫ d = k := ⟨hs.desc <| Cofork.ofπ _ h, hs.fac _ _, fun _ hm => Cofork.IsColimit.hom_ext hs <| hm.symm ▸ (hs.fac (Cofork.ofπ _ h) WalkingParallelPair.one).symm⟩ /-- This is a slightly more convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ @[simps] def Fork.IsLimit.mk (t : Fork f g) (lift : ∀ s : Fork f g, s.pt ⟶ t.pt) (fac : ∀ s : Fork f g, lift s ≫ Fork.ι t = Fork.ι s) (uniq : ∀ (s : Fork f g) (m : s.pt ⟶ t.pt) (_ : m ≫ t.ι = s.ι), m = lift s) : IsLimit t := { lift fac := fun s j => WalkingParallelPair.casesOn j (fac s) <| by erw [← s.w left, ← t.w left, ← Category.assoc, fac]; rfl uniq := fun s m j => by aesop} /-- This is another convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Fork.IsLimit.mk' {X Y : C} {f g : X ⟶ Y} (t : Fork f g) (create : ∀ s : Fork f g, { l // l ≫ t.ι = s.ι ∧ ∀ {m}, m ≫ t.ι = s.ι → m = l }) : IsLimit t := Fork.IsLimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 w /-- This is a slightly more convenient method to verify that a cofork is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def Cofork.IsColimit.mk (t : Cofork f g) (desc : ∀ s : Cofork f g, t.pt ⟶ s.pt) (fac : ∀ s : Cofork f g, Cofork.π t ≫ desc s = Cofork.π s) (uniq : ∀ (s : Cofork f g) (m : t.pt ⟶ s.pt) (_ : t.π ≫ m = s.π), m = desc s) : IsColimit t := { desc fac := fun s j => WalkingParallelPair.casesOn j (by erw [← s.w left, ← t.w left, Category.assoc, fac]; rfl) (fac s) uniq := by aesop } /-- This is another convenient method to verify that a fork is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Cofork.IsColimit.mk' {X Y : C} {f g : X ⟶ Y} (t : Cofork f g) (create : ∀ s : Cofork f g, { l : t.pt ⟶ s.pt // t.π ≫ l = s.π ∧ ∀ {m}, t.π ≫ m = s.π → m = l }) : IsColimit t := Cofork.IsColimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 w /-- Noncomputably make a limit cone from the existence of unique factorizations. -/ noncomputable def Fork.IsLimit.ofExistsUnique {t : Fork f g} (hs : ∀ s : Fork f g, ∃! l : s.pt ⟶ t.pt, l ≫ Fork.ι t = Fork.ι s) : IsLimit t := by choose d hd hd' using hs exact Fork.IsLimit.mk _ d hd fun s m hm => hd' _ _ hm /-- Noncomputably make a colimit cocone from the existence of unique factorizations. -/ noncomputable def Cofork.IsColimit.ofExistsUnique {t : Cofork f g} (hs : ∀ s : Cofork f g, ∃! d : t.pt ⟶ s.pt, Cofork.π t ≫ d = Cofork.π s) : IsColimit t := by choose d hd hd' using hs exact Cofork.IsColimit.mk _ d hd fun s m hm => hd' _ _ hm /-- Given a limit cone for the pair `f g : X ⟶ Y`, for any `Z`, morphisms from `Z` to its point are in bijection with morphisms `h : Z ⟶ X` such that `h ≫ f = h ≫ g`. Further, this bijection is natural in `Z`: see `Fork.IsLimit.homIso_natural`. This is a special case of `IsLimit.homIso'`, often useful to construct adjunctions. -/ @[simps] def Fork.IsLimit.homIso {X Y : C} {f g : X ⟶ Y} {t : Fork f g} (ht : IsLimit t) (Z : C) : (Z ⟶ t.pt) ≃ { h : Z ⟶ X // h ≫ f = h ≫ g } where toFun k := ⟨k ≫ t.ι, by simp only [Category.assoc, t.condition]⟩ invFun h := (Fork.IsLimit.lift' ht _ h.prop).1 left_inv k := Fork.IsLimit.hom_ext ht (Fork.IsLimit.lift' _ _ _).prop right_inv h := Subtype.ext (Fork.IsLimit.lift' ht _ _).prop /-- The bijection of `Fork.IsLimit.homIso` is natural in `Z`. -/ theorem Fork.IsLimit.homIso_natural {X Y : C} {f g : X ⟶ Y} {t : Fork f g} (ht : IsLimit t) {Z Z' : C} (q : Z' ⟶ Z) (k : Z ⟶ t.pt) : (Fork.IsLimit.homIso ht _ (q ≫ k) : Z' ⟶ X) = q ≫ (Fork.IsLimit.homIso ht _ k : Z ⟶ X) := Category.assoc _ _ _ /-- Given a colimit cocone for the pair `f g : X ⟶ Y`, for any `Z`, morphisms from the cocone point to `Z` are in bijection with morphisms `h : Y ⟶ Z` such that `f ≫ h = g ≫ h`. Further, this bijection is natural in `Z`: see `Cofork.IsColimit.homIso_natural`. This is a special case of `IsColimit.homIso'`, often useful to construct adjunctions. -/ @[simps] def Cofork.IsColimit.homIso {X Y : C} {f g : X ⟶ Y} {t : Cofork f g} (ht : IsColimit t) (Z : C) : (t.pt ⟶ Z) ≃ { h : Y ⟶ Z // f ≫ h = g ≫ h } where toFun k := ⟨t.π ≫ k, by simp only [← Category.assoc, t.condition]⟩ invFun h := (Cofork.IsColimit.desc' ht _ h.prop).1 left_inv k := Cofork.IsColimit.hom_ext ht (Cofork.IsColimit.desc' _ _ _).prop right_inv h := Subtype.ext (Cofork.IsColimit.desc' ht _ _).prop /-- The bijection of `Cofork.IsColimit.homIso` is natural in `Z`. -/ theorem Cofork.IsColimit.homIso_natural {X Y : C} {f g : X ⟶ Y} {t : Cofork f g} {Z Z' : C} (q : Z ⟶ Z') (ht : IsColimit t) (k : t.pt ⟶ Z) : (Cofork.IsColimit.homIso ht _ (k ≫ q) : Y ⟶ Z') = (Cofork.IsColimit.homIso ht _ k : Y ⟶ Z) ≫ q := (Category.assoc _ _ _).symm /-- This is a helper construction that can be useful when verifying that a category has all equalizers. Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)`, and a fork on `F.map left` and `F.map right`, we get a cone on `F`. If you're thinking about using this, have a look at `hasEqualizers_of_hasLimit_parallelPair`, which you may find to be an easier way of achieving your goal. -/ def Cone.ofFork {F : WalkingParallelPair ⥤ C} (t : Fork (F.map left) (F.map right)) : Cone F where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by aesop) naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp [t.condition]}} /-- This is a helper construction that can be useful when verifying that a category has all coequalizers. Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)`, and a cofork on `F.map left` and `F.map right`, we get a cocone on `F`. If you're thinking about using this, have a look at `hasCoequalizers_of_hasColimit_parallelPair`, which you may find to be an easier way of achieving your goal. -/ def Cocone.ofCofork {F : WalkingParallelPair ⥤ C} (t : Cofork (F.map left) (F.map right)) : Cocone F where pt := t.pt ι := { app := fun X => eqToHom (by aesop) ≫ t.ι.app X naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp [t.condition]}} @[simp] theorem Cone.ofFork_π {F : WalkingParallelPair ⥤ C} (t : Fork (F.map left) (F.map right)) (j) : (Cone.ofFork t).π.app j = t.π.app j ≫ eqToHom (by aesop) := rfl @[simp] theorem Cocone.ofCofork_ι {F : WalkingParallelPair ⥤ C} (t : Cofork (F.map left) (F.map right)) (j) : (Cocone.ofCofork t).ι.app j = eqToHom (by aesop) ≫ t.ι.app j := rfl /-- Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)` and a cone on `F`, we get a fork on `F.map left` and `F.map right`. -/ def Fork.ofCone {F : WalkingParallelPair ⥤ C} (t : Cone F) : Fork (F.map left) (F.map right) where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by aesop) naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp}} /-- Given `F : WalkingParallelPair ⥤ C`, which is really the same as `parallelPair (F.map left) (F.map right)` and a cocone on `F`, we get a cofork on `F.map left` and `F.map right`. -/ def Cofork.ofCocone {F : WalkingParallelPair ⥤ C} (t : Cocone F) : Cofork (F.map left) (F.map right) where pt := t.pt ι := { app := fun X => eqToHom (by aesop) ≫ t.ι.app X naturality := by rintro _ _ (_|_|_) <;> {dsimp; simp}} @[simp] theorem Fork.ofCone_π {F : WalkingParallelPair ⥤ C} (t : Cone F) (j) : (Fork.ofCone t).π.app j = t.π.app j ≫ eqToHom (by aesop) := rfl @[simp] theorem Cofork.ofCocone_ι {F : WalkingParallelPair ⥤ C} (t : Cocone F) (j) : (Cofork.ofCocone t).ι.app j = eqToHom (by aesop) ≫ t.ι.app j := rfl @[simp] theorem Fork.ι_postcompose {f' g' : X ⟶ Y} {α : parallelPair f g ⟶ parallelPair f' g'} {c : Fork f g} : Fork.ι ((Cones.postcompose α).obj c) = c.ι ≫ α.app _ := rfl @[simp] theorem Cofork.π_precompose {f' g' : X ⟶ Y} {α : parallelPair f g ⟶ parallelPair f' g'} {c : Cofork f' g'} : Cofork.π ((Cocones.precompose α).obj c) = α.app _ ≫ c.π := rfl /-- Helper function for constructing morphisms between equalizer forks. -/ @[simps] def Fork.mkHom {s t : Fork f g} (k : s.pt ⟶ t.pt) (w : k ≫ t.ι = s.ι) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · exact w · simp only [Fork.app_one_eq_ι_comp_left,← Category.assoc] congr /-- To construct an isomorphism between forks, it suffices to give an isomorphism between the cone points and check that it commutes with the `ι` morphisms. -/ @[simps] def Fork.ext {s t : Fork f g} (i : s.pt ≅ t.pt) (w : i.hom ≫ t.ι = s.ι := by aesop_cat) : s ≅ t where hom := Fork.mkHom i.hom w inv := Fork.mkHom i.inv (by rw [← w, Iso.inv_hom_id_assoc]) /-- Two forks of the form `ofι` are isomorphic whenever their `ι`'s are equal. -/ def ForkOfι.ext {P : C} {ι ι' : P ⟶ X} (w : ι ≫ f = ι ≫ g) (w' : ι' ≫ f = ι' ≫ g) (h : ι = ι') : Fork.ofι ι w ≅ Fork.ofι ι' w' := Fork.ext (Iso.refl _) (by simp [h]) /-- Every fork is isomorphic to one of the form `Fork.of_ι _ _`. -/ def Fork.isoForkOfι (c : Fork f g) : c ≅ Fork.ofι c.ι c.condition := Fork.ext (by simp only [Fork.ofι_pt, Functor.const_obj_obj]; rfl) (by simp) /-- Given two forks with isomorphic components in such a way that the natural diagrams commute, then if one is a limit, then the other one is as well. -/ def Fork.isLimitOfIsos {X' Y' : C} (c : Fork f g) (hc : IsLimit c) {f' g' : X' ⟶ Y'} (c' : Fork f' g') (e₀ : X ≅ X') (e₁ : Y ≅ Y') (e : c.pt ≅ c'.pt) (comm₁ : e₀.hom ≫ f' = f ≫ e₁.hom := by aesop_cat) (comm₂ : e₀.hom ≫ g' = g ≫ e₁.hom := by aesop_cat) (comm₃ : e.hom ≫ c'.ι = c.ι ≫ e₀.hom := by aesop_cat) : IsLimit c' := let i : parallelPair f g ≅ parallelPair f' g' := parallelPair.ext e₀ e₁ comm₁.symm comm₂.symm (IsLimit.equivOfNatIsoOfIso i c c' (Fork.ext e comm₃)) hc /-- Helper function for constructing morphisms between coequalizer coforks. -/ @[simps] def Cofork.mkHom {s t : Cofork f g} (k : s.pt ⟶ t.pt) (w : s.π ≫ k = t.π) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · simp [Cofork.app_zero_eq_comp_π_left, w] · exact w @[reassoc (attr := simp)] theorem Fork.hom_comp_ι {s t : Fork f g} (f : s ⟶ t) : f.hom ≫ t.ι = s.ι := by cases s; cases t; cases f; aesop @[reassoc (attr := simp)] theorem Fork.π_comp_hom {s t : Cofork f g} (f : s ⟶ t) : s.π ≫ f.hom = t.π := by cases s; cases t; cases f; aesop /-- To construct an isomorphism between coforks, it suffices to give an isomorphism between the cocone points and check that it commutes with the `π` morphisms. -/ @[simps] def Cofork.ext {s t : Cofork f g} (i : s.pt ≅ t.pt) (w : s.π ≫ i.hom = t.π := by aesop_cat) : s ≅ t where hom := Cofork.mkHom i.hom w inv := Cofork.mkHom i.inv (by rw [Iso.comp_inv_eq, w]) /-- Every cofork is isomorphic to one of the form `Cofork.ofπ _ _`. -/ def Cofork.isoCoforkOfπ (c : Cofork f g) : c ≅ Cofork.ofπ c.π c.condition := Cofork.ext (by simp only [Cofork.ofπ_pt, Functor.const_obj_obj]; rfl) (by dsimp; simp) variable (f g) section /-- `HasEqualizer f g` represents a particular choice of limiting cone for the parallel pair of morphisms `f` and `g`. -/ abbrev HasEqualizer := HasLimit (parallelPair f g) variable [HasEqualizer f g] /-- If an equalizer of `f` and `g` exists, we can access an arbitrary choice of such by saying `equalizer f g`. -/ noncomputable abbrev equalizer : C := limit (parallelPair f g) /-- If an equalizer of `f` and `g` exists, we can access the inclusion `equalizer f g ⟶ X` by saying `equalizer.ι f g`. -/ noncomputable abbrev equalizer.ι : equalizer f g ⟶ X := limit.π (parallelPair f g) zero /-- An equalizer cone for a parallel pair `f` and `g` -/ noncomputable abbrev equalizer.fork : Fork f g := limit.cone (parallelPair f g) @[simp] theorem equalizer.fork_ι : (equalizer.fork f g).ι = equalizer.ι f g := rfl @[simp] theorem equalizer.fork_π_app_zero : (equalizer.fork f g).π.app zero = equalizer.ι f g := rfl @[reassoc] theorem equalizer.condition : equalizer.ι f g ≫ f = equalizer.ι f g ≫ g := Fork.condition <| limit.cone <| parallelPair f g /-- The equalizer built from `equalizer.ι f g` is limiting. -/ noncomputable def equalizerIsEqualizer : IsLimit (Fork.ofι (equalizer.ι f g) (equalizer.condition f g)) := IsLimit.ofIsoLimit (limit.isLimit _) (Fork.ext (Iso.refl _) (by aesop)) variable {f g} /-- A morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` factors through the equalizer of `f` and `g` via `equalizer.lift : W ⟶ equalizer f g`. -/ noncomputable abbrev equalizer.lift {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : W ⟶ equalizer f g := limit.lift (parallelPair f g) (Fork.ofι k h) -- Porting note (#10618): removed simp since simp can prove this and the reassoc version @[reassoc] theorem equalizer.lift_ι {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : equalizer.lift k h ≫ equalizer.ι f g = k := limit.lift_π _ _ /-- A morphism `k : W ⟶ X` satisfying `k ≫ f = k ≫ g` induces a morphism `l : W ⟶ equalizer f g` satisfying `l ≫ equalizer.ι f g = k`. -/ noncomputable def equalizer.lift' {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : { l : W ⟶ equalizer f g // l ≫ equalizer.ι f g = k } := ⟨equalizer.lift k h, equalizer.lift_ι _ _⟩ /-- Two maps into an equalizer are equal if they are equal when composed with the equalizer map. -/ @[ext] theorem equalizer.hom_ext {W : C} {k l : W ⟶ equalizer f g} (h : k ≫ equalizer.ι f g = l ≫ equalizer.ι f g) : k = l := Fork.IsLimit.hom_ext (limit.isLimit _) h theorem equalizer.existsUnique {W : C} (k : W ⟶ X) (h : k ≫ f = k ≫ g) : ∃! l : W ⟶ equalizer f g, l ≫ equalizer.ι f g = k := Fork.IsLimit.existsUnique (limit.isLimit _) _ h /-- An equalizer morphism is a monomorphism -/ instance equalizer.ι_mono : Mono (equalizer.ι f g) where right_cancellation _ _ w := equalizer.hom_ext w end section variable {f g} /-- The equalizer morphism in any limit cone is a monomorphism. -/ theorem mono_of_isLimit_fork {c : Fork f g} (i : IsLimit c) : Mono (Fork.ι c) := { right_cancellation := fun _ _ w => Fork.IsLimit.hom_ext i w } end section variable {f g} /-- The identity determines a cone on the equalizer diagram of `f` and `g` if `f = g`. -/ def idFork (h : f = g) : Fork f g := Fork.ofι (𝟙 X) <| h ▸ rfl /-- The identity on `X` is an equalizer of `(f, g)`, if `f = g`. -/ def isLimitIdFork (h : f = g) : IsLimit (idFork h) := Fork.IsLimit.mk _ (fun s => Fork.ι s) (fun s => Category.comp_id _) fun s m h => by convert h exact (Category.comp_id _).symm /-- Every equalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_eq (h₀ : f = g) {c : Fork f g} (h : IsLimit c) : IsIso c.ι := Iso.isIso_hom <| IsLimit.conePointUniqueUpToIso h <| isLimitIdFork h₀ /-- The equalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem equalizer.ι_of_eq [HasEqualizer f g] (h : f = g) : IsIso (equalizer.ι f g) := isIso_limit_cone_parallelPair_of_eq h <| limit.isLimit _ /-- Every equalizer of `(f, f)` is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_self {c : Fork f f} (h : IsLimit c) : IsIso c.ι := isIso_limit_cone_parallelPair_of_eq rfl h /-- An equalizer that is an epimorphism is an isomorphism. -/ theorem isIso_limit_cone_parallelPair_of_epi {c : Fork f g} (h : IsLimit c) [Epi c.ι] : IsIso c.ι := isIso_limit_cone_parallelPair_of_eq ((cancel_epi _).1 (Fork.condition c)) h /-- Two morphisms are equal if there is a fork whose inclusion is epi. -/ theorem eq_of_epi_fork_ι (t : Fork f g) [Epi (Fork.ι t)] : f = g := (cancel_epi (Fork.ι t)).1 <| Fork.condition t /-- If the equalizer of two morphisms is an epimorphism, then the two morphisms are equal. -/ theorem eq_of_epi_equalizer [HasEqualizer f g] [Epi (equalizer.ι f g)] : f = g := (cancel_epi (equalizer.ι f g)).1 <| equalizer.condition _ _ end instance hasEqualizer_of_self : HasEqualizer f f := HasLimit.mk { cone := idFork rfl isLimit := isLimitIdFork rfl } /-- The equalizer inclusion for `(f, f)` is an isomorphism. -/ instance equalizer.ι_of_self : IsIso (equalizer.ι f f) := equalizer.ι_of_eq rfl /-- The equalizer of a morphism with itself is isomorphic to the source. -/ noncomputable def equalizer.isoSourceOfSelf : equalizer f f ≅ X := asIso (equalizer.ι f f) @[simp] theorem equalizer.isoSourceOfSelf_hom : (equalizer.isoSourceOfSelf f).hom = equalizer.ι f f := rfl @[simp] theorem equalizer.isoSourceOfSelf_inv : (equalizer.isoSourceOfSelf f).inv = equalizer.lift (𝟙 X) (by simp) := by ext simp [equalizer.isoSourceOfSelf] section /-- `HasCoequalizer f g` represents a particular choice of colimiting cocone for the parallel pair of morphisms `f` and `g`. -/ abbrev HasCoequalizer := HasColimit (parallelPair f g) variable [HasCoequalizer f g] /-- If a coequalizer of `f` and `g` exists, we can access an arbitrary choice of such by saying `coequalizer f g`. -/ noncomputable abbrev coequalizer : C := colimit (parallelPair f g) /-- If a coequalizer of `f` and `g` exists, we can access the corresponding projection by saying `coequalizer.π f g`. -/ noncomputable abbrev coequalizer.π : Y ⟶ coequalizer f g := colimit.ι (parallelPair f g) one /-- An arbitrary choice of coequalizer cocone for a parallel pair `f` and `g`. -/ noncomputable abbrev coequalizer.cofork : Cofork f g := colimit.cocone (parallelPair f g) @[simp] theorem coequalizer.cofork_π : (coequalizer.cofork f g).π = coequalizer.π f g := rfl -- Porting note (#10618): simp can prove this, simp removed theorem coequalizer.cofork_ι_app_one : (coequalizer.cofork f g).ι.app one = coequalizer.π f g := rfl @[reassoc] theorem coequalizer.condition : f ≫ coequalizer.π f g = g ≫ coequalizer.π f g := Cofork.condition <| colimit.cocone <| parallelPair f g /-- The cofork built from `coequalizer.π f g` is colimiting. -/ noncomputable def coequalizerIsCoequalizer : IsColimit (Cofork.ofπ (coequalizer.π f g) (coequalizer.condition f g)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cofork.ext (Iso.refl _) (by aesop)) variable {f g} /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` factors through the coequalizer of `f` and `g` via `coequalizer.desc : coequalizer f g ⟶ W`. -/ noncomputable abbrev coequalizer.desc {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : coequalizer f g ⟶ W := colimit.desc (parallelPair f g) (Cofork.ofπ k h) -- Porting note (#10618): removing simp since simp can prove this and reassoc version @[reassoc] theorem coequalizer.π_desc {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : coequalizer.π f g ≫ coequalizer.desc k h = k := colimit.ι_desc _ _ theorem coequalizer.π_colimMap_desc {X' Y' Z : C} (f' g' : X' ⟶ Y') [HasCoequalizer f' g'] (p : X ⟶ X') (q : Y ⟶ Y') (wf : f ≫ q = p ≫ f') (wg : g ≫ q = p ≫ g') (h : Y' ⟶ Z) (wh : f' ≫ h = g' ≫ h) : coequalizer.π f g ≫ colimMap (parallelPairHom f g f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := by rw [ι_colimMap_assoc, parallelPairHom_app_one, coequalizer.π_desc] /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = g ≫ k` induces a morphism `l : coequalizer f g ⟶ W` satisfying `coequalizer.π ≫ g = l`. -/ noncomputable def coequalizer.desc' {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : { l : coequalizer f g ⟶ W // coequalizer.π f g ≫ l = k } := ⟨coequalizer.desc k h, coequalizer.π_desc _ _⟩ /-- Two maps from a coequalizer are equal if they are equal when composed with the coequalizer map -/ @[ext] theorem coequalizer.hom_ext {W : C} {k l : coequalizer f g ⟶ W} (h : coequalizer.π f g ≫ k = coequalizer.π f g ≫ l) : k = l := Cofork.IsColimit.hom_ext (colimit.isColimit _) h theorem coequalizer.existsUnique {W : C} (k : Y ⟶ W) (h : f ≫ k = g ≫ k) : ∃! d : coequalizer f g ⟶ W, coequalizer.π f g ≫ d = k := Cofork.IsColimit.existsUnique (colimit.isColimit _) _ h /-- A coequalizer morphism is an epimorphism -/ instance coequalizer.π_epi : Epi (coequalizer.π f g) where left_cancellation _ _ w := coequalizer.hom_ext w end section variable {f g} /-- The coequalizer morphism in any colimit cocone is an epimorphism. -/ theorem epi_of_isColimit_cofork {c : Cofork f g} (i : IsColimit c) : Epi c.π := { left_cancellation := fun _ _ w => Cofork.IsColimit.hom_ext i w } end section variable {f g} /-- The identity determines a cocone on the coequalizer diagram of `f` and `g`, if `f = g`. -/ def idCofork (h : f = g) : Cofork f g := Cofork.ofπ (𝟙 Y) <| h ▸ rfl /-- The identity on `Y` is a coequalizer of `(f, g)`, where `f = g`. -/ def isColimitIdCofork (h : f = g) : IsColimit (idCofork h) := Cofork.IsColimit.mk _ (fun s => Cofork.π s) (fun s => Category.id_comp _) fun s m h => by convert h exact (Category.id_comp _).symm /-- Every coequalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem isIso_colimit_cocone_parallelPair_of_eq (h₀ : f = g) {c : Cofork f g} (h : IsColimit c) : IsIso c.π := Iso.isIso_hom <| IsColimit.coconePointUniqueUpToIso (isColimitIdCofork h₀) h /-- The coequalizer of `(f, g)`, where `f = g`, is an isomorphism. -/ theorem coequalizer.π_of_eq [HasCoequalizer f g] (h : f = g) : IsIso (coequalizer.π f g) := isIso_colimit_cocone_parallelPair_of_eq h <| colimit.isColimit _ /-- Every coequalizer of `(f, f)` is an isomorphism. -/ theorem isIso_colimit_cocone_parallelPair_of_self {c : Cofork f f} (h : IsColimit c) : IsIso c.π := isIso_colimit_cocone_parallelPair_of_eq rfl h /-- A coequalizer that is a monomorphism is an isomorphism. -/ theorem isIso_limit_cocone_parallelPair_of_epi {c : Cofork f g} (h : IsColimit c) [Mono c.π] : IsIso c.π := isIso_colimit_cocone_parallelPair_of_eq ((cancel_mono _).1 (Cofork.condition c)) h /-- Two morphisms are equal if there is a cofork whose projection is mono. -/ theorem eq_of_mono_cofork_π (t : Cofork f g) [Mono (Cofork.π t)] : f = g := (cancel_mono (Cofork.π t)).1 <| Cofork.condition t /-- If the coequalizer of two morphisms is a monomorphism, then the two morphisms are equal. -/ theorem eq_of_mono_coequalizer [HasCoequalizer f g] [Mono (coequalizer.π f g)] : f = g := (cancel_mono (coequalizer.π f g)).1 <| coequalizer.condition _ _ end instance hasCoequalizer_of_self : HasCoequalizer f f := HasColimit.mk { cocone := idCofork rfl isColimit := isColimitIdCofork rfl } /-- The coequalizer projection for `(f, f)` is an isomorphism. -/ instance coequalizer.π_of_self : IsIso (coequalizer.π f f) := coequalizer.π_of_eq rfl /-- The coequalizer of a morphism with itself is isomorphic to the target. -/ noncomputable def coequalizer.isoTargetOfSelf : coequalizer f f ≅ Y := (asIso (coequalizer.π f f)).symm @[simp] theorem coequalizer.isoTargetOfSelf_hom : (coequalizer.isoTargetOfSelf f).hom = coequalizer.desc (𝟙 Y) (by simp) := by ext simp [coequalizer.isoTargetOfSelf] @[simp] theorem coequalizer.isoTargetOfSelf_inv : (coequalizer.isoTargetOfSelf f).inv = coequalizer.π f f := rfl section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) /-- The comparison morphism for the equalizer of `f,g`. This is an isomorphism iff `G` preserves the equalizer of `f,g`; see `CategoryTheory/Limits/Preserves/Shapes/Equalizers.lean` -/ noncomputable def equalizerComparison [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] : G.obj (equalizer f g) ⟶ equalizer (G.map f) (G.map g) := equalizer.lift (G.map (equalizer.ι _ _)) (by simp only [← G.map_comp]; rw [equalizer.condition]) @[reassoc (attr := simp)] theorem equalizerComparison_comp_π [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] : equalizerComparison f g G ≫ equalizer.ι (G.map f) (G.map g) = G.map (equalizer.ι f g) := equalizer.lift_ι _ _ @[reassoc (attr := simp)] theorem map_lift_equalizerComparison [HasEqualizer f g] [HasEqualizer (G.map f) (G.map g)] {Z : C} {h : Z ⟶ X} (w : h ≫ f = h ≫ g) : G.map (equalizer.lift h w) ≫ equalizerComparison f g G = equalizer.lift (G.map h) (by simp only [← G.map_comp, w]) := by apply equalizer.hom_ext simp [← G.map_comp] /-- The comparison morphism for the coequalizer of `f,g`. -/ noncomputable def coequalizerComparison [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] : coequalizer (G.map f) (G.map g) ⟶ G.obj (coequalizer f g) := coequalizer.desc (G.map (coequalizer.π _ _)) (by simp only [← G.map_comp]; rw [coequalizer.condition]) @[reassoc (attr := simp)] theorem ι_comp_coequalizerComparison [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] : coequalizer.π _ _ ≫ coequalizerComparison f g G = G.map (coequalizer.π _ _) := coequalizer.π_desc _ _ @[reassoc (attr := simp)] theorem coequalizerComparison_map_desc [HasCoequalizer f g] [HasCoequalizer (G.map f) (G.map g)] {Z : C} {h : Y ⟶ Z} (w : f ≫ h = g ≫ h) : coequalizerComparison f g G ≫ G.map (coequalizer.desc h w) = coequalizer.desc (G.map h) (by simp only [← G.map_comp, w]) := by apply coequalizer.hom_ext simp [← G.map_comp] end Comparison variable (C) /-- `HasEqualizers` represents a choice of equalizer for every pair of morphisms -/ abbrev HasEqualizers := HasLimitsOfShape WalkingParallelPair C /-- `HasCoequalizers` represents a choice of coequalizer for every pair of morphisms -/ abbrev HasCoequalizers := HasColimitsOfShape WalkingParallelPair C /-- If `C` has all limits of diagrams `parallelPair f g`, then it has all equalizers -/ theorem hasEqualizers_of_hasLimit_parallelPair [∀ {X Y : C} {f g : X ⟶ Y}, HasLimit (parallelPair f g)] : HasEqualizers C := { has_limit := fun F => hasLimitOfIso (diagramIsoParallelPair F).symm } /-- If `C` has all colimits of diagrams `parallelPair f g`, then it has all coequalizers -/ theorem hasCoequalizers_of_hasColimit_parallelPair [∀ {X Y : C} {f g : X ⟶ Y}, HasColimit (parallelPair f g)] : HasCoequalizers C := { has_colimit := fun F => hasColimitOfIso (diagramIsoParallelPair F) } section -- In this section we show that a split mono `f` equalizes `(retraction f ≫ f)` and `(𝟙 Y)`. variable {C} [IsSplitMono f] /-- A split mono `f` equalizes `(retraction f ≫ f)` and `(𝟙 Y)`. Here we build the cone, and show in `isSplitMonoEqualizes` that it is a limit cone. -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] noncomputable def coneOfIsSplitMono : Fork (𝟙 Y) (retraction f ≫ f) := Fork.ofι f (by simp) @[simp] theorem coneOfIsSplitMono_ι : (coneOfIsSplitMono f).ι = f := rfl /-- A split mono `f` equalizes `(retraction f ≫ f)` and `(𝟙 Y)`. -/ noncomputable def isSplitMonoEqualizes {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsLimit (coneOfIsSplitMono f) := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ retraction f, by dsimp rw [Category.assoc, ← s.condition] apply Category.comp_id, fun hm => by simp [← hm]⟩ end /-- We show that the converse to `isSplitMonoEqualizes` is true: Whenever `f` equalizes `(r ≫ f)` and `(𝟙 Y)`, then `r` is a retraction of `f`. -/ def splitMonoOfEqualizer {X Y : C} {f : X ⟶ Y} {r : Y ⟶ X} (hr : f ≫ r ≫ f = f) (h : IsLimit (Fork.ofι f (hr.trans (Category.comp_id _).symm : f ≫ r ≫ f = f ≫ 𝟙 Y))) : SplitMono f where retraction := r id := Fork.IsLimit.hom_ext h ((Category.assoc _ _ _).trans <| hr.trans (Category.id_comp _).symm) variable {C f g} /-- The fork obtained by postcomposing an equalizer fork with a monomorphism is an equalizer. -/ def isEqualizerCompMono {c : Fork f g} (i : IsLimit c) {Z : C} (h : Y ⟶ Z) [hm : Mono h] : have : Fork.ι c ≫ f ≫ h = Fork.ι c ≫ g ≫ h := by simp only [← Category.assoc] exact congrArg (· ≫ h) c.condition IsLimit (Fork.ofι c.ι (by simp [this]) : Fork (f ≫ h) (g ≫ h)) := Fork.IsLimit.mk' _ fun s => let s' : Fork f g := Fork.ofι s.ι (by apply hm.right_cancellation; simp [s.condition]) let l := Fork.IsLimit.lift' i s'.ι s'.condition ⟨l.1, l.2, fun hm => by apply Fork.IsLimit.hom_ext i; rw [Fork.ι_ofι] at hm; rw [hm]; exact l.2.symm⟩ variable (C f g) @[instance] theorem hasEqualizer_comp_mono [HasEqualizer f g] {Z : C} (h : Y ⟶ Z) [Mono h] : HasEqualizer (f ≫ h) (g ≫ h) := ⟨⟨{ cone := _ isLimit := isEqualizerCompMono (limit.isLimit _) h }⟩⟩ /-- An equalizer of an idempotent morphism and the identity is split mono. -/ @[simps] def splitMonoOfIdempotentOfIsLimitFork {X : C} {f : X ⟶ X} (hf : f ≫ f = f) {c : Fork (𝟙 X) f} (i : IsLimit c) : SplitMono c.ι where retraction := i.lift (Fork.ofι f (by simp [hf])) id := by letI := mono_of_isLimit_fork i rw [← cancel_mono_id c.ι, Category.assoc, Fork.IsLimit.lift_ι, Fork.ι_ofι, ← c.condition] exact Category.comp_id c.ι /-- The equalizer of an idempotent morphism and the identity is split mono. -/ noncomputable def splitMonoOfIdempotentEqualizer {X : C} {f : X ⟶ X} (hf : f ≫ f = f) [HasEqualizer (𝟙 X) f] : SplitMono (equalizer.ι (𝟙 X) f) := splitMonoOfIdempotentOfIsLimitFork _ hf (limit.isLimit _) section -- In this section we show that a split epi `f` coequalizes `(f ≫ section_ f)` and `(𝟙 X)`. variable {C} [IsSplitEpi f] /-- A split epi `f` coequalizes `(f ≫ section_ f)` and `(𝟙 X)`. Here we build the cocone, and show in `isSplitEpiCoequalizes` that it is a colimit cocone. -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] noncomputable def coconeOfIsSplitEpi : Cofork (𝟙 X) (f ≫ section_ f) := Cofork.ofπ f (by simp) @[simp] theorem coconeOfIsSplitEpi_π : (coconeOfIsSplitEpi f).π = f := rfl /-- A split epi `f` coequalizes `(f ≫ section_ f)` and `(𝟙 X)`. -/ noncomputable def isSplitEpiCoequalizes {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsColimit (coconeOfIsSplitEpi f) := Cofork.IsColimit.mk' _ fun s => ⟨section_ f ≫ s.π, by dsimp rw [← Category.assoc, ← s.condition, Category.id_comp], fun hm => by simp [← hm]⟩ end /-- We show that the converse to `isSplitEpiEqualizes` is true: Whenever `f` coequalizes `(f ≫ s)` and `(𝟙 X)`, then `s` is a section of `f`. -/ def splitEpiOfCoequalizer {X Y : C} {f : X ⟶ Y} {s : Y ⟶ X} (hs : f ≫ s ≫ f = f) (h : IsColimit (Cofork.ofπ f ((Category.assoc _ _ _).trans <| hs.trans (Category.id_comp f).symm : (f ≫ s) ≫ f = 𝟙 X ≫ f))) : SplitEpi f where section_ := s id := Cofork.IsColimit.hom_ext h (hs.trans (Category.comp_id _).symm) variable {C f g} /-- The cofork obtained by precomposing a coequalizer cofork with an epimorphism is a coequalizer. -/ def isCoequalizerEpiComp {c : Cofork f g} (i : IsColimit c) {W : C} (h : W ⟶ X) [hm : Epi h] : have : (h ≫ f) ≫ Cofork.π c = (h ≫ g) ≫ Cofork.π c := by simp only [Category.assoc] exact congrArg (h ≫ ·) c.condition IsColimit (Cofork.ofπ c.π (this) : Cofork (h ≫ f) (h ≫ g)) := Cofork.IsColimit.mk' _ fun s => let s' : Cofork f g := Cofork.ofπ s.π (by apply hm.left_cancellation; simp_rw [← Category.assoc, s.condition]) let l := Cofork.IsColimit.desc' i s'.π s'.condition ⟨l.1, l.2, fun hm => by apply Cofork.IsColimit.hom_ext i; rw [Cofork.π_ofπ] at hm; rw [hm]; exact l.2.symm⟩ theorem hasCoequalizer_epi_comp [HasCoequalizer f g] {W : C} (h : W ⟶ X) [Epi h] : HasCoequalizer (h ≫ f) (h ≫ g) := ⟨⟨{ cocone := _ isColimit := isCoequalizerEpiComp (colimit.isColimit _) h }⟩⟩ variable (C f g) /-- A coequalizer of an idempotent morphism and the identity is split epi. -/ @[simps] def splitEpiOfIdempotentOfIsColimitCofork {X : C} {f : X ⟶ X} (hf : f ≫ f = f) {c : Cofork (𝟙 X) f} (i : IsColimit c) : SplitEpi c.π where section_ := i.desc (Cofork.ofπ f (by simp [hf])) id := by letI := epi_of_isColimit_cofork i rw [← cancel_epi_id c.π, ← Category.assoc, Cofork.IsColimit.π_desc, Cofork.π_ofπ, ← c.condition] exact Category.id_comp _ /-- The coequalizer of an idempotent morphism and the identity is split epi. -/ noncomputable def splitEpiOfIdempotentCoequalizer {X : C} {f : X ⟶ X} (hf : f ≫ f = f) [HasCoequalizer (𝟙 X) f] : SplitEpi (coequalizer.π (𝟙 X) f) := splitEpiOfIdempotentOfIsColimitCofork _ hf (colimit.isColimit _) end CategoryTheory.Limits end
CategoryTheory\Limits\Shapes\Equivalence.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Transporting existence of specific limits across equivalences For now, we only treat the case of initial and terminal objects, but other special shapes can be added in the future. -/ open CategoryTheory CategoryTheory.Limits namespace CategoryTheory universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] theorem hasInitial_of_equivalence (e : D ⥤ C) [e.IsEquivalence] [HasInitial C] : HasInitial D := Adjunction.hasColimitsOfShape_of_equivalence e theorem Equivalence.hasInitial_iff (e : C ≌ D) : HasInitial C ↔ HasInitial D := ⟨fun (_ : HasInitial C) => hasInitial_of_equivalence e.inverse, fun (_ : HasInitial D) => hasInitial_of_equivalence e.functor⟩ theorem hasTerminal_of_equivalence (e : D ⥤ C) [e.IsEquivalence] [HasTerminal C] : HasTerminal D := Adjunction.hasLimitsOfShape_of_equivalence e theorem Equivalence.hasTerminal_iff (e : C ≌ D) : HasTerminal C ↔ HasTerminal D := ⟨fun (_ : HasTerminal C) => hasTerminal_of_equivalence e.inverse, fun (_ : HasTerminal D) => hasTerminal_of_equivalence e.functor⟩ end CategoryTheory
CategoryTheory\Limits\Shapes\FiniteLimits.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.FinCategory.AsType import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.Data.Fintype.Option /-! # Categories with finite limits. A typeclass for categories with all finite (co)limits. -/ universe w' w v' u' v u noncomputable section open CategoryTheory namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] -- We can't just made this an `abbreviation` -- because of https://github.com/leanprover-community/lean/issues/429 /-- A category has all finite limits if every functor `J ⥤ C` with a `FinCategory J` instance and `J : Type` has a limit. This is often called 'finitely complete'. -/ class HasFiniteLimits : Prop where /-- `C` has all limits over any type `J` whose objects and morphisms lie in the same universe and which has `FinType` objects and morphisms-/ out (J : Type) [𝒥 : SmallCategory J] [@FinCategory J 𝒥] : @HasLimitsOfShape J 𝒥 C _ instance (priority := 100) hasLimitsOfShape_of_hasFiniteLimits (J : Type w) [SmallCategory J] [FinCategory J] [HasFiniteLimits C] : HasLimitsOfShape J C := by apply @hasLimitsOfShape_of_equivalence _ _ _ _ _ _ (FinCategory.equivAsType J) ?_ apply HasFiniteLimits.out lemma hasFiniteLimits_of_hasLimitsOfSize [HasLimitsOfSize.{v', u'} C] : HasFiniteLimits C where out := fun J hJ hJ' => haveI := hasLimitsOfSizeShrink.{0, 0} C let F := @FinCategory.equivAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ' @hasLimitsOfShape_of_equivalence (@FinCategory.AsType J (@FinCategory.fintypeObj J hJ hJ')) (@FinCategory.categoryAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ') _ _ J hJ F _ /-- If `C` has all limits, it has finite limits. -/ instance (priority := 100) hasFiniteLimits_of_hasLimits [HasLimits C] : HasFiniteLimits C := hasFiniteLimits_of_hasLimitsOfSize C instance (priority := 90) hasFiniteLimits_of_hasLimitsOfSize₀ [HasLimitsOfSize.{0, 0} C] : HasFiniteLimits C := hasFiniteLimits_of_hasLimitsOfSize C /-- We can always derive `HasFiniteLimits C` by providing limits at an arbitrary universe. -/ theorem hasFiniteLimits_of_hasFiniteLimits_of_size (h : ∀ (J : Type w) {𝒥 : SmallCategory J} (_ : @FinCategory J 𝒥), HasLimitsOfShape J C) : HasFiniteLimits C where out := fun J hJ hhJ => by haveI := h (ULiftHom.{w} (ULift.{w} J)) <| @CategoryTheory.finCategoryUlift J hJ hhJ have l : @Equivalence J (ULiftHom (ULift J)) hJ (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) := @ULiftHomULiftCategory.equiv J hJ apply @hasLimitsOfShape_of_equivalence (ULiftHom (ULift J)) (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) C _ J hJ (@Equivalence.symm J hJ (ULiftHom (ULift J)) (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) l) _ /- Porting note: tried to factor out (@instCategoryULiftHom (ULift J) (@uliftCategory J hJ) but when doing that would then find the instance and say it was not definitionally equal to the provided one (the same thing factored out) -/ /-- A category has all finite colimits if every functor `J ⥤ C` with a `FinCategory J` instance and `J : Type` has a colimit. This is often called 'finitely cocomplete'. -/ class HasFiniteColimits : Prop where /-- `C` has all colimits over any type `J` whose objects and morphisms lie in the same universe and which has `Fintype` objects and morphisms-/ out (J : Type) [𝒥 : SmallCategory J] [@FinCategory J 𝒥] : @HasColimitsOfShape J 𝒥 C _ instance (priority := 100) hasColimitsOfShape_of_hasFiniteColimits (J : Type w) [SmallCategory J] [FinCategory J] [HasFiniteColimits C] : HasColimitsOfShape J C := by refine @hasColimitsOfShape_of_equivalence _ _ _ _ _ _ (FinCategory.equivAsType J) ?_ apply HasFiniteColimits.out lemma hasFiniteColimits_of_hasColimitsOfSize [HasColimitsOfSize.{v', u'} C] : HasFiniteColimits C where out := fun J hJ hJ' => haveI := hasColimitsOfSizeShrink.{0, 0} C let F := @FinCategory.equivAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ' @hasColimitsOfShape_of_equivalence (@FinCategory.AsType J (@FinCategory.fintypeObj J hJ hJ')) (@FinCategory.categoryAsType J (@FinCategory.fintypeObj J hJ hJ') hJ hJ') _ _ J hJ F _ instance (priority := 100) hasFiniteColimits_of_hasColimits [HasColimits C] : HasFiniteColimits C := hasFiniteColimits_of_hasColimitsOfSize C instance (priority := 90) hasFiniteColimits_of_hasColimitsOfSize₀ [HasColimitsOfSize.{0, 0} C] : HasFiniteColimits C := hasFiniteColimits_of_hasColimitsOfSize C /-- We can always derive `HasFiniteColimits C` by providing colimits at an arbitrary universe. -/ theorem hasFiniteColimits_of_hasFiniteColimits_of_size (h : ∀ (J : Type w) {𝒥 : SmallCategory J} (_ : @FinCategory J 𝒥), HasColimitsOfShape J C) : HasFiniteColimits C where out := fun J hJ hhJ => by haveI := h (ULiftHom.{w} (ULift.{w} J)) <| @CategoryTheory.finCategoryUlift J hJ hhJ have l : @Equivalence J (ULiftHom (ULift J)) hJ (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) := @ULiftHomULiftCategory.equiv J hJ apply @hasColimitsOfShape_of_equivalence (ULiftHom (ULift J)) (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) C _ J hJ (@Equivalence.symm J hJ (ULiftHom (ULift J)) (@ULiftHom.category (ULift J) (@uliftCategory J hJ)) l) _ section open WalkingParallelPair WalkingParallelPairHom instance fintypeWalkingParallelPair : Fintype WalkingParallelPair where elems := [WalkingParallelPair.zero, WalkingParallelPair.one].toFinset complete x := by cases x <;> simp -- attribute [local tidy] tactic.case_bash Porting note: no tidy; no case_bash instance instFintypeWalkingParallelPairHom (j j' : WalkingParallelPair) : Fintype (WalkingParallelPairHom j j') where elems := WalkingParallelPair.recOn j (WalkingParallelPair.recOn j' [WalkingParallelPairHom.id zero].toFinset [left, right].toFinset) (WalkingParallelPair.recOn j' ∅ [WalkingParallelPairHom.id one].toFinset) complete := by rintro (_|_) <;> simp cases j <;> simp end instance : FinCategory WalkingParallelPair where fintypeObj := fintypeWalkingParallelPair fintypeHom := instFintypeWalkingParallelPairHom -- Porting note: could not be inferred /-- Equalizers are finite limits, so if `C` has all finite limits, it also has all equalizers -/ example [HasFiniteLimits C] : HasEqualizers C := by infer_instance /-- Coequalizers are finite colimits, of if `C` has all finite colimits, it also has all coequalizers -/ example [HasFiniteColimits C] : HasCoequalizers C := by infer_instance variable {J : Type v} -- attribute [local tidy] tactic.case_bash Porting note: no tidy; no case_bash namespace WidePullbackShape instance fintypeObj [Fintype J] : Fintype (WidePullbackShape J) := inferInstanceAs <| Fintype (Option _) instance fintypeHom (j j' : WidePullbackShape J) : Fintype (j ⟶ j') where elems := by cases' j' with j' · cases' j with j · exact {Hom.id none} · exact {Hom.term j} · by_cases h : some j' = j · rw [h] exact {Hom.id j} · exact ∅ complete := by rintro (_|_) · cases j <;> simp · simp end WidePullbackShape namespace WidePushoutShape instance fintypeObj [Fintype J] : Fintype (WidePushoutShape J) := by rw [WidePushoutShape]; infer_instance instance fintypeHom (j j' : WidePushoutShape J) : Fintype (j ⟶ j') where elems := by cases' j with j · cases' j' with j' · exact {Hom.id none} · exact {Hom.init j'} · by_cases h : some j = j' · rw [h] exact {Hom.id j'} · exact ∅ complete := by rintro (_|_) · cases j <;> simp · simp end WidePushoutShape instance finCategoryWidePullback [Fintype J] : FinCategory (WidePullbackShape J) where fintypeHom := WidePullbackShape.fintypeHom instance finCategoryWidePushout [Fintype J] : FinCategory (WidePushoutShape J) where fintypeHom := WidePushoutShape.fintypeHom -- We can't just made this an `abbreviation` -- because of https://github.com/leanprover-community/lean/issues/429 /-- `HasFiniteWidePullbacks` represents a choice of wide pullback for every finite collection of morphisms -/ class HasFiniteWidePullbacks : Prop where /-- `C` has all wide pullbacks any Fintype `J`-/ out (J : Type) [Finite J] : HasLimitsOfShape (WidePullbackShape J) C instance hasLimitsOfShape_widePullbackShape (J : Type) [Finite J] [HasFiniteWidePullbacks C] : HasLimitsOfShape (WidePullbackShape J) C := by haveI := @HasFiniteWidePullbacks.out C _ _ J infer_instance /-- `HasFiniteWidePushouts` represents a choice of wide pushout for every finite collection of morphisms -/ class HasFiniteWidePushouts : Prop where /-- `C` has all wide pushouts any Fintype `J`-/ out (J : Type) [Finite J] : HasColimitsOfShape (WidePushoutShape J) C instance hasColimitsOfShape_widePushoutShape (J : Type) [Finite J] [HasFiniteWidePushouts C] : HasColimitsOfShape (WidePushoutShape J) C := by haveI := @HasFiniteWidePushouts.out C _ _ J infer_instance /-- Finite wide pullbacks are finite limits, so if `C` has all finite limits, it also has finite wide pullbacks -/ theorem hasFiniteWidePullbacks_of_hasFiniteLimits [HasFiniteLimits C] : HasFiniteWidePullbacks C := ⟨fun J _ => by cases nonempty_fintype J; exact HasFiniteLimits.out _⟩ /-- Finite wide pushouts are finite colimits, so if `C` has all finite colimits, it also has finite wide pushouts -/ theorem hasFiniteWidePushouts_of_has_finite_limits [HasFiniteColimits C] : HasFiniteWidePushouts C := ⟨fun J _ => by cases nonempty_fintype J; exact HasFiniteColimits.out _⟩ instance fintypeWalkingPair : Fintype WalkingPair where elems := {WalkingPair.left, WalkingPair.right} complete x := by cases x <;> simp /-- Pullbacks are finite limits, so if `C` has all finite limits, it also has all pullbacks -/ example [HasFiniteWidePullbacks C] : HasPullbacks C := by infer_instance /-- Pushouts are finite colimits, so if `C` has all finite colimits, it also has all pushouts -/ example [HasFiniteWidePushouts C] : HasPushouts C := by infer_instance end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\FiniteProducts.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Shapes.Products /-! # Categories with finite (co)products Typeclasses representing categories with (co)products over finite indexing types. -/ universe w v u open CategoryTheory open scoped Classical namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] /-- A category has finite products if there exists a limit for every diagram with shape `Discrete J`, where we have `[Finite J]`. We require this condition only for `J = Fin n` in the definition, then deduce a version for any `J : Type*` as a corollary of this definition. -/ class HasFiniteProducts : Prop where /-- `C` has finite products -/ out (n : ℕ) : HasLimitsOfShape (Discrete (Fin n)) C /-- If `C` has finite limits then it has finite products. -/ instance (priority := 10) hasFiniteProducts_of_hasFiniteLimits [HasFiniteLimits C] : HasFiniteProducts C := ⟨fun _ => inferInstance⟩ instance hasLimitsOfShape_discrete [HasFiniteProducts C] (ι : Type w) [Finite ι] : HasLimitsOfShape (Discrete ι) C := by rcases Finite.exists_equiv_fin ι with ⟨n, ⟨e⟩⟩ haveI : HasLimitsOfShape (Discrete (Fin n)) C := HasFiniteProducts.out n exact hasLimitsOfShape_of_equivalence (Discrete.equivalence e.symm) /-- We can now write this for powers. -/ noncomputable example [HasFiniteProducts C] (X : C) : C := ∏ᶜ fun _ : Fin 5 => X /-- If a category has all products then in particular it has finite products. -/ theorem hasFiniteProducts_of_hasProducts [HasProducts.{w} C] : HasFiniteProducts C := ⟨fun _ => hasLimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift.{w})⟩ /-- A category has finite coproducts if there exists a colimit for every diagram with shape `Discrete J`, where we have `[Fintype J]`. We require this condition only for `J = Fin n` in the definition, then deduce a version for any `J : Type*` as a corollary of this definition. -/ class HasFiniteCoproducts : Prop where /-- `C` has all finite coproducts -/ out (n : ℕ) : HasColimitsOfShape (Discrete (Fin n)) C -- attribute [class] HasFiniteCoproducts Porting note: this doesn't seem necessary in Lean 4 instance hasColimitsOfShape_discrete [HasFiniteCoproducts C] (ι : Type w) [Finite ι] : HasColimitsOfShape (Discrete ι) C := by rcases Finite.exists_equiv_fin ι with ⟨n, ⟨e⟩⟩ haveI : HasColimitsOfShape (Discrete (Fin n)) C := HasFiniteCoproducts.out n exact hasColimitsOfShape_of_equivalence (Discrete.equivalence e.symm) /-- If `C` has finite colimits then it has finite coproducts. -/ instance (priority := 10) hasFiniteCoproducts_of_hasFiniteColimits [HasFiniteColimits C] : HasFiniteCoproducts C := ⟨fun J => by infer_instance⟩ /-- If a category has all coproducts then in particular it has finite coproducts. -/ theorem hasFiniteCoproducts_of_hasCoproducts [HasCoproducts.{w} C] : HasFiniteCoproducts C := ⟨fun _ => hasColimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift.{w})⟩ end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\FunctorCategory.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.FunctorCategory /-! # If `D` has finite (co)limits, so do the functor categories `C ⥤ D`. These are boiler-plate instances, in their own file as neither import otherwise needs the other. -/ open CategoryTheory namespace CategoryTheory.Limits universe v₁ v₂ u₁ u₂ w variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] instance functor_category_hasFiniteLimits [HasFiniteLimits D] : HasFiniteLimits (C ⥤ D) where out _ _ _ := inferInstance instance functor_category_hasFiniteColimits [HasFiniteColimits D] : HasFiniteColimits (C ⥤ D) where out _ _ _ := inferInstance end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\FunctorToTypes.lean
/- Copyright (c) 2024 Jack McKoen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jack McKoen -/ import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Types /-! # Binary (co)products of type-valued functors Defines an explicit construction of binary products and coproducts of type-valued functors. Also defines isomorphisms to the categorical product and coproduct, respectively. -/ open CategoryTheory.Limits universe w v u namespace CategoryTheory.FunctorToTypes variable {C : Type u} [Category.{v} C] variable (F G : C ⥤ Type w) section prod /-- `prod F G` is the explicit binary product of type-valued functors `F` and `G`. -/ def prod : C ⥤ Type w where obj a := F.obj a × G.obj a map f a := (F.map f a.1, G.map f a.2) variable {F G} /-- The first projection of `prod F G`, onto `F`. -/ @[simps] def prod.fst : prod F G ⟶ F where app _ a := a.1 /-- The second projection of `prod F G`, onto `G`. -/ @[simps] def prod.snd : prod F G ⟶ G where app _ a := a.2 /-- Given natural transformations `F ⟶ F₁` and `F ⟶ F₂`, construct a natural transformation `F ⟶ prod F₁ F₂`. -/ @[simps] def prod.lift {F₁ F₂ : C ⥤ Type w} (τ₁ : F ⟶ F₁) (τ₂ : F ⟶ F₂) : F ⟶ prod F₁ F₂ where app x y := ⟨τ₁.app x y, τ₂.app x y⟩ naturality _ _ _ := by ext a simp only [types_comp_apply, FunctorToTypes.naturality] aesop @[simp] lemma prod.lift_fst {F₁ F₂ : C ⥤ Type w} (τ₁ : F ⟶ F₁) (τ₂ : F ⟶ F₂) : prod.lift τ₁ τ₂ ≫ prod.fst = τ₁ := rfl @[simp] lemma prod.lift_snd {F₁ F₂ : C ⥤ Type w} (τ₁ : F ⟶ F₁) (τ₂ : F ⟶ F₂) : prod.lift τ₁ τ₂ ≫ prod.snd = τ₂ := rfl variable (F G) /-- The binary fan whose point is `prod F G`. -/ @[simps!] def binaryProductCone : BinaryFan F G := BinaryFan.mk prod.fst prod.snd /-- `prod F G` is a limit cone. -/ @[simps] def binaryProductLimit : IsLimit (binaryProductCone F G) where lift (s : BinaryFan F G) := prod.lift s.fst s.snd fac _ := fun ⟨j⟩ ↦ WalkingPair.casesOn j rfl rfl uniq _ _ h := by simp only [← h ⟨WalkingPair.right⟩, ← h ⟨WalkingPair.left⟩] congr /-- `prod F G` is a binary product for `F` and `G`. -/ def binaryProductLimitCone : Limits.LimitCone (pair F G) := ⟨_, binaryProductLimit F G⟩ /-- The categorical binary product of type-valued functors is `prod F G`. -/ noncomputable def binaryProductIso : F ⨯ G ≅ prod F G := limit.isoLimitCone (binaryProductLimitCone F G) @[simp] lemma binaryProductIso_hom_comp_fst : (binaryProductIso F G).hom ≫ prod.fst = Limits.prod.fst := rfl @[simp] lemma binaryProductIso_hom_comp_snd : (binaryProductIso F G).hom ≫ prod.snd = Limits.prod.snd := rfl @[simp] lemma binaryProductIso_inv_comp_fst : (binaryProductIso F G).inv ≫ Limits.prod.fst = prod.fst := by simp [binaryProductIso, binaryProductLimitCone] @[simp] lemma binaryProductIso_inv_comp_fst_apply (a : C) (z : (prod F G).obj a) : (Limits.prod.fst (X := F)).app a ((binaryProductIso F G).inv.app a z) = z.1 := congr_fun (congr_app (binaryProductIso_inv_comp_fst F G) a) z @[simp] lemma binaryProductIso_inv_comp_snd : (binaryProductIso F G).inv ≫ Limits.prod.snd = prod.snd := by simp [binaryProductIso, binaryProductLimitCone] @[simp] lemma binaryProductIso_inv_comp_snd_apply (a : C) (z : (prod F G).obj a) : (Limits.prod.snd (X := F)).app a ((binaryProductIso F G).inv.app a z) = z.2 := congr_fun (congr_app (binaryProductIso_inv_comp_snd F G) a) z variable {F G} /-- Construct an element of `(F ⨯ G).obj a` from an element of `F.obj a` and an element of `G.obj a`. -/ noncomputable def prodMk {a : C} (x : F.obj a) (y : G.obj a) : (F ⨯ G).obj a := ((binaryProductIso F G).inv).app a ⟨x, y⟩ @[simp] lemma prodMk_fst {a : C} (x : F.obj a) (y : G.obj a) : (Limits.prod.fst (X := F)).app a (prodMk x y) = x := by simp only [prodMk, binaryProductIso_inv_comp_fst_apply] @[simp] lemma prodMk_snd {a : C} (x : F.obj a) (y : G.obj a) : (Limits.prod.snd (X := F)).app a (prodMk x y) = y := by simp only [prodMk, binaryProductIso_inv_comp_snd_apply] @[ext] lemma prod_ext {a : C} (z w : (prod F G).obj a) (h1 : z.1 = w.1) (h2 : z.2 = w.2) : z = w := Prod.ext h1 h2 variable (F G) /-- `(F ⨯ G).obj a` is in bijection with the product of `F.obj a` and `G.obj a`. -/ @[simps] noncomputable def binaryProductEquiv (a : C) : (F ⨯ G).obj a ≃ (F.obj a) × (G.obj a) where toFun z := ⟨((binaryProductIso F G).hom.app a z).1, ((binaryProductIso F G).hom.app a z).2⟩ invFun z := prodMk z.1 z.2 left_inv _ := by simp [prodMk] right_inv _ := by simp [prodMk] @[ext] lemma prod_ext' (a : C) (z w : (F ⨯ G).obj a) (h1 : (Limits.prod.fst (X := F)).app a z = (Limits.prod.fst (X := F)).app a w) (h2 : (Limits.prod.snd (X := F)).app a z = (Limits.prod.snd (X := F)).app a w) : z = w := by apply Equiv.injective (binaryProductEquiv F G a) aesop end prod section coprod /-- `coprod F G` is the explicit binary coproduct of type-valued functors `F` and `G`. -/ def coprod : C ⥤ Type w where obj a := F.obj a ⊕ G.obj a map f x := by cases x with | inl x => exact .inl (F.map f x) | inr x => exact .inr (G.map f x) variable {F G} /-- The left inclusion of `F` into `coprod F G`. -/ @[simps] def coprod.inl : F ⟶ coprod F G where app _ x := .inl x /-- The right inclusion of `G` into `coprod F G`. -/ @[simps] def coprod.inr : G ⟶ coprod F G where app _ x := .inr x /-- Given natural transformations `F₁ ⟶ F` and `F₂ ⟶ F`, construct a natural transformation `coprod F₁ F₂ ⟶ F`. -/ @[simps] def coprod.desc {F₁ F₂ : C ⥤ Type w} (τ₁ : F₁ ⟶ F) (τ₂ : F₂ ⟶ F) : coprod F₁ F₂ ⟶ F where app a x := by cases x with | inl x => exact τ₁.app a x | inr x => exact τ₂.app a x naturality _ _ _ := by ext x cases x with | _ => simp only [coprod, types_comp_apply, FunctorToTypes.naturality] @[simp] lemma coprod.desc_inl {F₁ F₂ : C ⥤ Type w} (τ₁ : F₁ ⟶ F) (τ₂ : F₂ ⟶ F) : coprod.inl ≫ coprod.desc τ₁ τ₂ = τ₁ := rfl @[simp] lemma coprod.desc_inr {F₁ F₂ : C ⥤ Type w} (τ₁ : F₁ ⟶ F) (τ₂ : F₂ ⟶ F) : coprod.inr ≫ coprod.desc τ₁ τ₂ = τ₂ := rfl variable (F G) /-- The binary cofan whose point is `coprod F G`. -/ @[simps!] def binaryCoproductCocone : BinaryCofan F G := BinaryCofan.mk coprod.inl coprod.inr /-- `coprod F G` is a colimit cocone. -/ @[simps] def binaryCoproductColimit : IsColimit (binaryCoproductCocone F G) where desc (s : BinaryCofan F G) := coprod.desc s.inl s.inr fac _ := fun ⟨j⟩ ↦ WalkingPair.casesOn j rfl rfl uniq _ _ h := by ext _ x cases x with | _ => simp [← h ⟨WalkingPair.right⟩, ← h ⟨WalkingPair.left⟩] /-- `coprod F G` is a binary coproduct for `F` and `G`. -/ def binaryCoproductColimitCocone : Limits.ColimitCocone (pair F G) := ⟨_, binaryCoproductColimit F G⟩ /-- The categorical binary coproduct of type-valued functors is `coprod F G`. -/ noncomputable def binaryCoproductIso : F ⨿ G ≅ coprod F G := colimit.isoColimitCocone (binaryCoproductColimitCocone F G) @[simp] lemma inl_comp_binaryCoproductIso_hom : Limits.coprod.inl ≫ (binaryCoproductIso F G).hom = coprod.inl := by simp only [binaryCoproductIso] aesop @[simp] lemma inl_comp_binaryCoproductIso_hom_apply (a : C) (x : F.obj a) : (binaryCoproductIso F G).hom.app a ((Limits.coprod.inl (X := F)).app a x) = .inl x := congr_fun (congr_app (inl_comp_binaryCoproductIso_hom F G) a) x @[simp] lemma inr_comp_binaryCoproductIso_hom : Limits.coprod.inr ≫ (binaryCoproductIso F G).hom = coprod.inr := by simp [binaryCoproductIso] aesop @[simp] lemma inr_comp_binaryCoproductIso_hom_apply (a : C) (x : G.obj a) : (binaryCoproductIso F G).hom.app a ((Limits.coprod.inr (X := F)).app a x) = .inr x := congr_fun (congr_app (inr_comp_binaryCoproductIso_hom F G) a) x @[simp] lemma inl_comp_binaryCoproductIso_inv : coprod.inl ≫ (binaryCoproductIso F G).inv = (Limits.coprod.inl (X := F)) := rfl @[simp] lemma inl_comp_binaryCoproductIso_inv_apply (a : C) (x : F.obj a) : (binaryCoproductIso F G).inv.app a (.inl x) = (Limits.coprod.inl (X := F)).app a x := rfl @[simp] lemma inr_comp_binaryCoproductIso_inv : coprod.inr ≫ (binaryCoproductIso F G).inv = (Limits.coprod.inr (X := F)) := rfl @[simp] lemma inr_comp_binaryCoproductIso_inv_apply (a : C) (x : G.obj a) : (binaryCoproductIso F G).inv.app a (.inr x) = (Limits.coprod.inr (X := F)).app a x := rfl variable {F G} /-- Construct an element of `(F ⨿ G).obj a` from an element of `F.obj a` -/ noncomputable abbrev coprodInl {a : C} (x : F.obj a) : (F ⨿ G).obj a := (binaryCoproductIso F G).inv.app a (.inl x) /-- Construct an element of `(F ⨿ G).obj a` from an element of `G.obj a` -/ noncomputable abbrev coprodInr {a : C} (x : G.obj a) : (F ⨿ G).obj a := (binaryCoproductIso F G).inv.app a (.inr x) variable (F G) /-- `(F ⨿ G).obj a` is in bijection with disjoint union of `F.obj a` and `G.obj a`. -/ @[simps] noncomputable def binaryCoproductEquiv (a : C) : (F ⨿ G).obj a ≃ (F.obj a) ⊕ (G.obj a) where toFun z := (binaryCoproductIso F G).hom.app a z invFun z := (binaryCoproductIso F G).inv.app a z left_inv _ := by simp only [hom_inv_id_app_apply] right_inv _ := by simp only [inv_hom_id_app_apply] end coprod end CategoryTheory.FunctorToTypes
CategoryTheory\Limits\Shapes\Images.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.MorphismProperty.Factorization /-! # Categorical images We define the categorical image of `f` as a factorisation `f = e ≫ m` through a monomorphism `m`, so that `m` factors through the `m'` in any other such factorisation. ## Main definitions * A `MonoFactorisation` is a factorisation `f = e ≫ m`, where `m` is a monomorphism * `IsImage F` means that a given mono factorisation `F` has the universal property of the image. * `HasImage f` means that there is some image factorization for the morphism `f : X ⟶ Y`. * In this case, `image f` is some image object (selected with choice), `image.ι f : image f ⟶ Y` is the monomorphism `m` of the factorisation and `factorThruImage f : X ⟶ image f` is the morphism `e`. * `HasImages C` means that every morphism in `C` has an image. * Let `f : X ⟶ Y` and `g : P ⟶ Q` be morphisms in `C`, which we will represent as objects of the arrow category `arrow C`. Then `sq : f ⟶ g` is a commutative square in `C`. If `f` and `g` have images, then `HasImageMap sq` represents the fact that there is a morphism `i : image f ⟶ image g` making the diagram X ----→ image f ----→ Y | | | | | | ↓ ↓ ↓ P ----→ image g ----→ Q commute, where the top row is the image factorisation of `f`, the bottom row is the image factorisation of `g`, and the outer rectangle is the commutative square `sq`. * If a category `HasImages`, then `HasImageMaps` means that every commutative square admits an image map. * If a category `HasImages`, then `HasStrongEpiImages` means that the morphism to the image is always a strong epimorphism. ## Main statements * When `C` has equalizers, the morphism `e` appearing in an image factorisation is an epimorphism. * When `C` has strong epi images, then these images admit image maps. ## Future work * TODO: coimages, and abelian categories. * TODO: connect this with existing working in the group theory and ring theory libraries. -/ noncomputable section universe v u open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {X Y : C} (f : X ⟶ Y) /-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/ structure MonoFactorisation (f : X ⟶ Y) where I : C -- Porting note: violates naming conventions but can't think a better replacement m : I ⟶ Y [m_mono : Mono m] e : X ⟶ I fac : e ≫ m = f := by aesop_cat attribute [inherit_doc MonoFactorisation] MonoFactorisation.I MonoFactorisation.m MonoFactorisation.m_mono MonoFactorisation.e MonoFactorisation.fac attribute [reassoc (attr := simp)] MonoFactorisation.fac attribute [instance] MonoFactorisation.m_mono attribute [instance] MonoFactorisation.m_mono namespace MonoFactorisation /-- The obvious factorisation of a monomorphism through itself. -/ def self [Mono f] : MonoFactorisation f where I := X m := f e := 𝟙 X -- I'm not sure we really need this, but the linter says that an inhabited instance -- ought to exist... instance [Mono f] : Inhabited (MonoFactorisation f) := ⟨self f⟩ variable {f} /-- The morphism `m` in a factorisation `f = e ≫ m` through a monomorphism is uniquely determined. -/ @[ext (iff := false)] theorem ext {F F' : MonoFactorisation f} (hI : F.I = F'.I) (hm : F.m = eqToHom hI ≫ F'.m) : F = F' := by cases' F with _ Fm _ _ Ffac; cases' F' with _ Fm' _ _ Ffac' cases' hI simp? at hm says simp only [eqToHom_refl, Category.id_comp] at hm congr apply (cancel_mono Fm).1 rw [Ffac, hm, Ffac'] /-- Any mono factorisation of `f` gives a mono factorisation of `f ≫ g` when `g` is a mono. -/ @[simps] def compMono (F : MonoFactorisation f) {Y' : C} (g : Y ⟶ Y') [Mono g] : MonoFactorisation (f ≫ g) where I := F.I m := F.m ≫ g m_mono := mono_comp _ _ e := F.e /-- A mono factorisation of `f ≫ g`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofCompIso {Y' : C} {g : Y ⟶ Y'} [IsIso g] (F : MonoFactorisation (f ≫ g)) : MonoFactorisation f where I := F.I m := F.m ≫ inv g m_mono := mono_comp _ _ e := F.e /-- Any mono factorisation of `f` gives a mono factorisation of `g ≫ f`. -/ @[simps] def isoComp (F : MonoFactorisation f) {X' : C} (g : X' ⟶ X) : MonoFactorisation (g ≫ f) where I := F.I m := F.m e := g ≫ F.e /-- A mono factorisation of `g ≫ f`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofIsoComp {X' : C} (g : X' ⟶ X) [IsIso g] (F : MonoFactorisation (g ≫ f)) : MonoFactorisation f where I := F.I m := F.m e := inv g ≫ F.e /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` gives a mono factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : MonoFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : MonoFactorisation g.hom where I := F.I m := F.m ≫ sq.right e := inv sq.left ≫ F.e m_mono := mono_comp _ _ fac := by simp only [fac_assoc, Arrow.w, IsIso.inv_comp_eq, Category.assoc] end MonoFactorisation variable {f} /-- Data exhibiting that a given factorisation through a mono is initial. -/ structure IsImage (F : MonoFactorisation f) where lift : ∀ F' : MonoFactorisation f, F.I ⟶ F'.I lift_fac : ∀ F' : MonoFactorisation f, lift F' ≫ F'.m = F.m := by aesop_cat attribute [inherit_doc IsImage] IsImage.lift IsImage.lift_fac attribute [reassoc (attr := simp)] IsImage.lift_fac namespace IsImage @[reassoc (attr := simp)] theorem fac_lift {F : MonoFactorisation f} (hF : IsImage F) (F' : MonoFactorisation f) : F.e ≫ hF.lift F' = F'.e := (cancel_mono F'.m).1 <| by simp variable (f) /-- The trivial factorisation of a monomorphism satisfies the universal property. -/ @[simps] def self [Mono f] : IsImage (MonoFactorisation.self f) where lift F' := F'.e instance [Mono f] : Inhabited (IsImage (MonoFactorisation.self f)) := ⟨self f⟩ variable {f} -- TODO this is another good candidate for a future `UniqueUpToCanonicalIso`. /-- Two factorisations through monomorphisms satisfying the universal property must factor through isomorphic objects. -/ @[simps] def isoExt {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') : F.I ≅ F'.I where hom := hF.lift F' inv := hF'.lift F hom_inv_id := (cancel_mono F.m).1 (by simp) inv_hom_id := (cancel_mono F'.m).1 (by simp) variable {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') theorem isoExt_hom_m : (isoExt hF hF').hom ≫ F'.m = F.m := by simp theorem isoExt_inv_m : (isoExt hF hF').inv ≫ F.m = F'.m := by simp theorem e_isoExt_hom : F.e ≫ (isoExt hF hF').hom = F'.e := by simp theorem e_isoExt_inv : F'.e ≫ (isoExt hF hF').inv = F.e := by simp /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` that is an image gives a mono factorisation of `g` that is an image -/ @[simps] def ofArrowIso {f g : Arrow C} {F : MonoFactorisation f.hom} (hF : IsImage F) (sq : f ⟶ g) [IsIso sq] : IsImage (F.ofArrowIso sq) where lift F' := hF.lift (F'.ofArrowIso (inv sq)) lift_fac F' := by simpa only [MonoFactorisation.ofArrowIso_m, Arrow.inv_right, ← Category.assoc, IsIso.comp_inv_eq] using hF.lift_fac (F'.ofArrowIso (inv sq)) end IsImage variable (f) /-- Data exhibiting that a morphism `f` has an image. -/ structure ImageFactorisation (f : X ⟶ Y) where F : MonoFactorisation f -- Porting note: another violation of the naming convention isImage : IsImage F attribute [inherit_doc ImageFactorisation] ImageFactorisation.F ImageFactorisation.isImage namespace ImageFactorisation instance [Mono f] : Inhabited (ImageFactorisation f) := ⟨⟨_, IsImage.self f⟩⟩ /-- If `f` and `g` are isomorphic arrows, then an image factorisation of `f` gives an image factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : ImageFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : ImageFactorisation g.hom where F := F.F.ofArrowIso sq isImage := F.isImage.ofArrowIso sq end ImageFactorisation /-- `has_image f` means that there exists an image factorisation of `f`. -/ class HasImage (f : X ⟶ Y) : Prop where mk' :: exists_image : Nonempty (ImageFactorisation f) attribute [inherit_doc HasImage] HasImage.exists_image theorem HasImage.mk {f : X ⟶ Y} (F : ImageFactorisation f) : HasImage f := ⟨Nonempty.intro F⟩ theorem HasImage.of_arrow_iso {f g : Arrow C} [h : HasImage f.hom] (sq : f ⟶ g) [IsIso sq] : HasImage g.hom := ⟨⟨h.exists_image.some.ofArrowIso sq⟩⟩ instance (priority := 100) mono_hasImage (f : X ⟶ Y) [Mono f] : HasImage f := HasImage.mk ⟨_, IsImage.self f⟩ section variable [HasImage f] /-- Some factorisation of `f` through a monomorphism (selected with choice). -/ def Image.monoFactorisation : MonoFactorisation f := (Classical.choice HasImage.exists_image).F /-- The witness of the universal property for the chosen factorisation of `f` through a monomorphism. -/ def Image.isImage : IsImage (Image.monoFactorisation f) := (Classical.choice HasImage.exists_image).isImage /-- The categorical image of a morphism. -/ def image : C := (Image.monoFactorisation f).I /-- The inclusion of the image of a morphism into the target. -/ def image.ι : image f ⟶ Y := (Image.monoFactorisation f).m @[simp] theorem image.as_ι : (Image.monoFactorisation f).m = image.ι f := rfl instance : Mono (image.ι f) := (Image.monoFactorisation f).m_mono /-- The map from the source to the image of a morphism. -/ def factorThruImage : X ⟶ image f := (Image.monoFactorisation f).e /-- Rewrite in terms of the `factorThruImage` interface. -/ @[simp] theorem as_factorThruImage : (Image.monoFactorisation f).e = factorThruImage f := rfl @[reassoc (attr := simp)] theorem image.fac : factorThruImage f ≫ image.ι f = f := (Image.monoFactorisation f).fac variable {f} /-- Any other factorisation of the morphism `f` through a monomorphism receives a map from the image. -/ def image.lift (F' : MonoFactorisation f) : image f ⟶ F'.I := (Image.isImage f).lift F' @[reassoc (attr := simp)] theorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' ≫ F'.m = image.ι f := (Image.isImage f).lift_fac F' @[reassoc (attr := simp)] theorem image.fac_lift (F' : MonoFactorisation f) : factorThruImage f ≫ image.lift F' = F'.e := (Image.isImage f).fac_lift F' @[simp] theorem image.isImage_lift (F : MonoFactorisation f) : (Image.isImage f).lift F = image.lift F := rfl @[reassoc (attr := simp)] theorem IsImage.lift_ι {F : MonoFactorisation f} (hF : IsImage F) : hF.lift (Image.monoFactorisation f) ≫ image.ι f = F.m := hF.lift_fac _ -- TODO we could put a category structure on `MonoFactorisation f`, -- with the morphisms being `g : I ⟶ I'` commuting with the `m`s -- (they then automatically commute with the `e`s) -- and show that an `imageOf f` gives an initial object there -- (uniqueness of the lift comes for free). instance image.lift_mono (F' : MonoFactorisation f) : Mono (image.lift F') := by refine @mono_of_mono _ _ _ _ _ _ F'.m ?_ simpa using MonoFactorisation.m_mono _ theorem HasImage.uniq (F' : MonoFactorisation f) (l : image f ⟶ F'.I) (w : l ≫ F'.m = image.ι f) : l = image.lift F' := (cancel_mono F'.m).1 (by simp [w]) /-- If `has_image g`, then `has_image (f ≫ g)` when `f` is an isomorphism. -/ instance {X Y Z : C} (f : X ⟶ Y) [IsIso f] (g : Y ⟶ Z) [HasImage g] : HasImage (f ≫ g) where exists_image := ⟨{ F := { I := image g m := image.ι g e := f ≫ factorThruImage g } isImage := { lift := fun F' => image.lift { I := F'.I m := F'.m e := inv f ≫ F'.e } } }⟩ end section variable (C) /-- `HasImages` asserts that every morphism has an image. -/ class HasImages : Prop where has_image : ∀ {X Y : C} (f : X ⟶ Y), HasImage f attribute [inherit_doc HasImages] HasImages.has_image attribute [instance 100] HasImages.has_image end section /-- The image of a monomorphism is isomorphic to the source. -/ def imageMonoIsoSource [Mono f] : image f ≅ X := IsImage.isoExt (Image.isImage f) (IsImage.self f) @[reassoc (attr := simp)] theorem imageMonoIsoSource_inv_ι [Mono f] : (imageMonoIsoSource f).inv ≫ image.ι f = f := by simp [imageMonoIsoSource] @[reassoc (attr := simp)] theorem imageMonoIsoSource_hom_self [Mono f] : (imageMonoIsoSource f).hom ≫ f = image.ι f := by simp only [← imageMonoIsoSource_inv_ι f] rw [← Category.assoc, Iso.hom_inv_id, Category.id_comp] -- This is the proof that `factorThruImage f` is an epimorphism -- from https://en.wikipedia.org/wiki/Image_%28category_theory%29, which is in turn taken from: -- Mitchell, Barry (1965), Theory of categories, MR 0202787, p.12, Proposition 10.1 @[ext (iff := false)] theorem image.ext [HasImage f] {W : C} {g h : image f ⟶ W} [HasLimit (parallelPair g h)] (w : factorThruImage f ≫ g = factorThruImage f ≫ h) : g = h := by let q := equalizer.ι g h let e' := equalizer.lift _ w let F' : MonoFactorisation f := { I := equalizer g h m := q ≫ image.ι f m_mono := by apply mono_comp e := e' } let v := image.lift F' have t₀ : v ≫ q ≫ image.ι f = image.ι f := image.lift_fac F' have t : v ≫ q = 𝟙 (image f) := (cancel_mono_id (image.ι f)).1 (by convert t₀ using 1 rw [Category.assoc]) -- The proof from wikipedia next proves `q ≫ v = 𝟙 _`, -- and concludes that `equalizer g h ≅ image f`, -- but this isn't necessary. calc g = 𝟙 (image f) ≫ g := by rw [Category.id_comp] _ = v ≫ q ≫ g := by rw [← t, Category.assoc] _ = v ≫ q ≫ h := by rw [equalizer.condition g h] _ = 𝟙 (image f) ≫ h := by rw [← Category.assoc, t] _ = h := by rw [Category.id_comp] instance [HasImage f] [∀ {Z : C} (g h : image f ⟶ Z), HasLimit (parallelPair g h)] : Epi (factorThruImage f) := ⟨fun _ _ w => image.ext f w⟩ theorem epi_image_of_epi {X Y : C} (f : X ⟶ Y) [HasImage f] [E : Epi f] : Epi (image.ι f) := by rw [← image.fac f] at E exact epi_of_epi (factorThruImage f) (image.ι f) theorem epi_of_epi_image {X Y : C} (f : X ⟶ Y) [HasImage f] [Epi (image.ι f)] [Epi (factorThruImage f)] : Epi f := by rw [← image.fac f] apply epi_comp end section variable {f} variable {f' : X ⟶ Y} [HasImage f] [HasImage f'] /-- An equation between morphisms gives a comparison map between the images (which momentarily we prove is an iso). -/ def image.eqToHom (h : f = f') : image f ⟶ image f' := image.lift { I := image f' m := image.ι f' e := factorThruImage f' fac := by rw [h]; simp only [image.fac]} instance (h : f = f') : IsIso (image.eqToHom h) := ⟨⟨image.eqToHom h.symm, ⟨(cancel_mono (image.ι f)).1 (by -- Porting note: added let's for used to be a simp [image.eqToHom] let F : MonoFactorisation f' := ⟨image f, image.ι f, factorThruImage f, (by aesop_cat)⟩ dsimp [image.eqToHom] rw [Category.id_comp,Category.assoc,image.lift_fac F] let F' : MonoFactorisation f := ⟨image f', image.ι f', factorThruImage f', (by aesop_cat)⟩ rw [image.lift_fac F'] ), (cancel_mono (image.ι f')).1 (by -- Porting note: added let's for used to be a simp [image.eqToHom] let F' : MonoFactorisation f := ⟨image f', image.ι f', factorThruImage f', (by aesop_cat)⟩ dsimp [image.eqToHom] rw [Category.id_comp,Category.assoc,image.lift_fac F'] let F : MonoFactorisation f' := ⟨image f, image.ι f, factorThruImage f, (by aesop_cat)⟩ rw [image.lift_fac F])⟩⟩⟩ /-- An equation between morphisms gives an isomorphism between the images. -/ def image.eqToIso (h : f = f') : image f ≅ image f' := asIso (image.eqToHom h) /-- As long as the category has equalizers, the image inclusion maps commute with `image.eqToIso`. -/ theorem image.eq_fac [HasEqualizers C] (h : f = f') : image.ι f = (image.eqToIso h).hom ≫ image.ι f' := by apply image.ext dsimp [asIso,image.eqToIso, image.eqToHom] rw [image.lift_fac] -- Porting note: simp did not fire with this it seems end section variable {Z : C} (g : Y ⟶ Z) /-- The comparison map `image (f ≫ g) ⟶ image g`. -/ def image.preComp [HasImage g] [HasImage (f ≫ g)] : image (f ≫ g) ⟶ image g := image.lift { I := image g m := image.ι g e := f ≫ factorThruImage g } @[reassoc (attr := simp)] theorem image.preComp_ι [HasImage g] [HasImage (f ≫ g)] : image.preComp f g ≫ image.ι g = image.ι (f ≫ g) := by dsimp [image.preComp] rw [image.lift_fac] -- Porting note: also here, see image.eq_fac @[reassoc (attr := simp)] theorem image.factorThruImage_preComp [HasImage g] [HasImage (f ≫ g)] : factorThruImage (f ≫ g) ≫ image.preComp f g = f ≫ factorThruImage g := by simp [image.preComp] /-- `image.preComp f g` is a monomorphism. -/ instance image.preComp_mono [HasImage g] [HasImage (f ≫ g)] : Mono (image.preComp f g) := by refine @mono_of_mono _ _ _ _ _ _ (image.ι g) ?_ simp only [image.preComp_ι] infer_instance /-- The two step comparison map `image (f ≫ (g ≫ h)) ⟶ image (g ≫ h) ⟶ image h` agrees with the one step comparison map `image (f ≫ (g ≫ h)) ≅ image ((f ≫ g) ≫ h) ⟶ image h`. -/ theorem image.preComp_comp {W : C} (h : Z ⟶ W) [HasImage (g ≫ h)] [HasImage (f ≫ g ≫ h)] [HasImage h] [HasImage ((f ≫ g) ≫ h)] : image.preComp f (g ≫ h) ≫ image.preComp g h = image.eqToHom (Category.assoc f g h).symm ≫ image.preComp (f ≫ g) h := by apply (cancel_mono (image.ι h)).1 dsimp [image.preComp, image.eqToHom] repeat (rw [Category.assoc,image.lift_fac]) rw [image.lift_fac,image.lift_fac] variable [HasEqualizers C] /-- `image.preComp f g` is an epimorphism when `f` is an epimorphism (we need `C` to have equalizers to prove this). -/ instance image.preComp_epi_of_epi [HasImage g] [HasImage (f ≫ g)] [Epi f] : Epi (image.preComp f g) := by apply @epi_of_epi_fac _ _ _ _ _ _ _ _ ?_ (image.factorThruImage_preComp _ _) exact epi_comp _ _ instance hasImage_iso_comp [IsIso f] [HasImage g] : HasImage (f ≫ g) := HasImage.mk { F := (Image.monoFactorisation g).isoComp f isImage := { lift := fun F' => image.lift (F'.ofIsoComp f) lift_fac := fun F' => by dsimp have : (MonoFactorisation.ofIsoComp f F').m = F'.m := rfl rw [← this,image.lift_fac (MonoFactorisation.ofIsoComp f F')] } } /-- `image.preComp f g` is an isomorphism when `f` is an isomorphism (we need `C` to have equalizers to prove this). -/ instance image.isIso_precomp_iso (f : X ⟶ Y) [IsIso f] [HasImage g] : IsIso (image.preComp f g) := ⟨⟨image.lift { I := image (f ≫ g) m := image.ι (f ≫ g) e := inv f ≫ factorThruImage (f ≫ g) }, ⟨by ext simp [image.preComp], by ext simp [image.preComp]⟩⟩⟩ -- Note that in general we don't have the other comparison map you might expect -- `image f ⟶ image (f ≫ g)`. instance hasImage_comp_iso [HasImage f] [IsIso g] : HasImage (f ≫ g) := HasImage.mk { F := (Image.monoFactorisation f).compMono g isImage := { lift := fun F' => image.lift F'.ofCompIso lift_fac := fun F' => by rw [← Category.comp_id (image.lift (MonoFactorisation.ofCompIso F') ≫ F'.m), ← IsIso.inv_hom_id g,← Category.assoc] refine congrArg (· ≫ g) ?_ have : (image.lift (MonoFactorisation.ofCompIso F') ≫ F'.m) ≫ inv g = image.lift (MonoFactorisation.ofCompIso F') ≫ ((MonoFactorisation.ofCompIso F').m) := by simp only [MonoFactorisation.ofCompIso_I, Category.assoc, MonoFactorisation.ofCompIso_m] rw [this, image.lift_fac (MonoFactorisation.ofCompIso F'),image.as_ι] }} /-- Postcomposing by an isomorphism induces an isomorphism on the image. -/ def image.compIso [HasImage f] [IsIso g] : image f ≅ image (f ≫ g) where hom := image.lift (Image.monoFactorisation (f ≫ g)).ofCompIso inv := image.lift ((Image.monoFactorisation f).compMono g) @[reassoc (attr := simp)] theorem image.compIso_hom_comp_image_ι [HasImage f] [IsIso g] : (image.compIso f g).hom ≫ image.ι (f ≫ g) = image.ι f ≫ g := by ext simp [image.compIso] @[reassoc (attr := simp)] theorem image.compIso_inv_comp_image_ι [HasImage f] [IsIso g] : (image.compIso f g).inv ≫ image.ι f = image.ι (f ≫ g) ≫ inv g := by ext simp [image.compIso] end end CategoryTheory.Limits namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] section instance {X Y : C} (f : X ⟶ Y) [HasImage f] : HasImage (Arrow.mk f).hom := show HasImage f by infer_instance end section HasImageMap /-- An image map is a morphism `image f → image g` fitting into a commutative square and satisfying the obvious commutativity conditions. -/ structure ImageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) where map : image f.hom ⟶ image g.hom map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by aesop attribute [inherit_doc ImageMap] ImageMap.map ImageMap.map_ι -- Porting note: LHS of this simplifies, simpNF still complains after blacklisting attribute [-simp, nolint simpNF] ImageMap.mk.injEq instance inhabitedImageMap {f : Arrow C} [HasImage f.hom] : Inhabited (ImageMap (𝟙 f)) := ⟨⟨𝟙 _, by aesop⟩⟩ attribute [reassoc (attr := simp)] ImageMap.map_ι @[reassoc (attr := simp)] theorem ImageMap.factor_map {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (m : ImageMap sq) : factorThruImage f.hom ≫ m.map = sq.left ≫ factorThruImage g.hom := (cancel_mono (image.ι g.hom)).1 <| by simp /-- To give an image map for a commutative square with `f` at the top and `g` at the bottom, it suffices to give a map between any mono factorisation of `f` and any image factorisation of `g`. -/ def ImageMap.transport {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (F : MonoFactorisation f.hom) {F' : MonoFactorisation g.hom} (hF' : IsImage F') {map : F.I ⟶ F'.I} (map_ι : map ≫ F'.m = F.m ≫ sq.right) : ImageMap sq where map := image.lift F ≫ map ≫ hF'.lift (Image.monoFactorisation g.hom) map_ι := by simp [map_ι] /-- `HasImageMap sq` means that there is an `ImageMap` for the square `sq`. -/ class HasImageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) : Prop where mk' :: has_image_map : Nonempty (ImageMap sq) attribute [inherit_doc HasImageMap] HasImageMap.has_image_map theorem HasImageMap.mk {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (m : ImageMap sq) : HasImageMap sq := ⟨Nonempty.intro m⟩ theorem HasImageMap.transport {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) (F : MonoFactorisation f.hom) {F' : MonoFactorisation g.hom} (hF' : IsImage F') (map : F.I ⟶ F'.I) (map_ι : map ≫ F'.m = F.m ≫ sq.right) : HasImageMap sq := HasImageMap.mk <| ImageMap.transport sq F hF' map_ι /-- Obtain an `ImageMap` from a `HasImageMap` instance. -/ def HasImageMap.imageMap {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) [HasImageMap sq] : ImageMap sq := Classical.choice <| @HasImageMap.has_image_map _ _ _ _ _ _ sq _ -- see Note [lower instance priority] instance (priority := 100) hasImageMapOfIsIso {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) [IsIso sq] : HasImageMap sq := HasImageMap.mk { map := image.lift ((Image.monoFactorisation g.hom).ofArrowIso (inv sq)) map_ι := by erw [← cancel_mono (inv sq).right, Category.assoc, ← MonoFactorisation.ofArrowIso_m, image.lift_fac, Category.assoc, ← Comma.comp_right, IsIso.hom_inv_id, Comma.id_right, Category.comp_id] } instance HasImageMap.comp {f g h : Arrow C} [HasImage f.hom] [HasImage g.hom] [HasImage h.hom] (sq1 : f ⟶ g) (sq2 : g ⟶ h) [HasImageMap sq1] [HasImageMap sq2] : HasImageMap (sq1 ≫ sq2) := HasImageMap.mk { map := (HasImageMap.imageMap sq1).map ≫ (HasImageMap.imageMap sq2).map map_ι := by rw [Category.assoc,ImageMap.map_ι, ImageMap.map_ι_assoc, Comma.comp_right] } variable {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] (sq : f ⟶ g) section attribute [local ext] ImageMap /- Porting note: ImageMap.mk.injEq has LHS simplify to True due to the next instance We make a replacement -/ theorem ImageMap.map_uniq_aux {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (map : image f.hom ⟶ image g.hom) (map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by aesop_cat) (map' : image f.hom ⟶ image g.hom) (map_ι' : map' ≫ image.ι g.hom = image.ι f.hom ≫ sq.right) : (map = map') := by have : map ≫ image.ι g.hom = map' ≫ image.ι g.hom := by rw [map_ι,map_ι'] apply (cancel_mono (image.ι g.hom)).1 this -- Porting note: added to get variant on ImageMap.mk.injEq below theorem ImageMap.map_uniq {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (F G : ImageMap sq) : F.map = G.map := by apply ImageMap.map_uniq_aux _ F.map_ι _ G.map_ι @[simp] theorem ImageMap.mk.injEq' {f g : Arrow C} [HasImage f.hom] [HasImage g.hom] {sq : f ⟶ g} (map : image f.hom ⟶ image g.hom) (map_ι : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by aesop_cat) (map' : image f.hom ⟶ image g.hom) (map_ι' : map' ≫ image.ι g.hom = image.ι f.hom ≫ sq.right) : (map = map') = True := by simp only [Functor.id_obj, eq_iff_iff, iff_true] apply ImageMap.map_uniq_aux _ map_ι _ map_ι' instance : Subsingleton (ImageMap sq) := Subsingleton.intro fun a b => ImageMap.ext <| ImageMap.map_uniq a b end variable [HasImageMap sq] /-- The map on images induced by a commutative square. -/ abbrev image.map : image f.hom ⟶ image g.hom := (HasImageMap.imageMap sq).map theorem image.factor_map : factorThruImage f.hom ≫ image.map sq = sq.left ≫ factorThruImage g.hom := by simp theorem image.map_ι : image.map sq ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by simp theorem image.map_homMk'_ι {X Y P Q : C} {k : X ⟶ Y} [HasImage k] {l : P ⟶ Q} [HasImage l] {m : X ⟶ P} {n : Y ⟶ Q} (w : m ≫ l = k ≫ n) [HasImageMap (Arrow.homMk' w)] : image.map (Arrow.homMk' w) ≫ image.ι l = image.ι k ≫ n := image.map_ι _ section variable {h : Arrow C} [HasImage h.hom] (sq' : g ⟶ h) variable [HasImageMap sq'] /-- Image maps for composable commutative squares induce an image map in the composite square. -/ def imageMapComp : ImageMap (sq ≫ sq') where map := image.map sq ≫ image.map sq' @[simp] theorem image.map_comp [HasImageMap (sq ≫ sq')] : image.map (sq ≫ sq') = image.map sq ≫ image.map sq' := show (HasImageMap.imageMap (sq ≫ sq')).map = (imageMapComp sq sq').map by congr; simp only [eq_iff_true_of_subsingleton] end section variable (f) /-- The identity `image f ⟶ image f` fits into the commutative square represented by the identity morphism `𝟙 f` in the arrow category. -/ def imageMapId : ImageMap (𝟙 f) where map := 𝟙 (image f.hom) @[simp] theorem image.map_id [HasImageMap (𝟙 f)] : image.map (𝟙 f) = 𝟙 (image f.hom) := show (HasImageMap.imageMap (𝟙 f)).map = (imageMapId f).map by congr; simp only [eq_iff_true_of_subsingleton] end end HasImageMap section variable (C) [Category.{v} C] [HasImages C] /-- If a category `has_image_maps`, then all commutative squares induce morphisms on images. -/ class HasImageMaps : Prop where has_image_map : ∀ {f g : Arrow C} (st : f ⟶ g), HasImageMap st attribute [instance 100] HasImageMaps.has_image_map end section HasImageMaps variable [HasImages C] [HasImageMaps C] /-- The functor from the arrow category of `C` to `C` itself that maps a morphism to its image and a commutative square to the induced morphism on images. -/ @[simps] def im : Arrow C ⥤ C where obj f := image f.hom map st := image.map st end HasImageMaps section StrongEpiMonoFactorisation /-- A strong epi-mono factorisation is a decomposition `f = e ≫ m` with `e` a strong epimorphism and `m` a monomorphism. -/ structure StrongEpiMonoFactorisation {X Y : C} (f : X ⟶ Y) extends MonoFactorisation f where [e_strong_epi : StrongEpi e] attribute [inherit_doc StrongEpiMonoFactorisation] StrongEpiMonoFactorisation.e_strong_epi attribute [instance] StrongEpiMonoFactorisation.e_strong_epi /-- Satisfying the inhabited linter -/ instance strongEpiMonoFactorisationInhabited {X Y : C} (f : X ⟶ Y) [StrongEpi f] : Inhabited (StrongEpiMonoFactorisation f) := ⟨⟨⟨Y, 𝟙 Y, f, by simp⟩⟩⟩ /-- A mono factorisation coming from a strong epi-mono factorisation always has the universal property of the image. -/ def StrongEpiMonoFactorisation.toMonoIsImage {X Y : C} {f : X ⟶ Y} (F : StrongEpiMonoFactorisation f) : IsImage F.toMonoFactorisation where lift G := (CommSq.mk (show G.e ≫ G.m = F.e ≫ F.m by rw [F.toMonoFactorisation.fac, G.fac])).lift variable (C) /-- A category has strong epi-mono factorisations if every morphism admits a strong epi-mono factorisation. -/ class HasStrongEpiMonoFactorisations : Prop where mk' :: has_fac : ∀ {X Y : C} (f : X ⟶ Y), Nonempty (StrongEpiMonoFactorisation f) attribute [inherit_doc HasStrongEpiMonoFactorisations] HasStrongEpiMonoFactorisations.has_fac variable {C} theorem HasStrongEpiMonoFactorisations.mk (d : ∀ {X Y : C} (f : X ⟶ Y), StrongEpiMonoFactorisation f) : HasStrongEpiMonoFactorisations C := ⟨fun f => Nonempty.intro <| d f⟩ instance (priority := 100) hasImages_of_hasStrongEpiMonoFactorisations [HasStrongEpiMonoFactorisations C] : HasImages C where has_image f := let F' := Classical.choice (HasStrongEpiMonoFactorisations.has_fac f) HasImage.mk { F := F'.toMonoFactorisation isImage := F'.toMonoIsImage } end StrongEpiMonoFactorisation section HasStrongEpiImages variable (C) [Category.{v} C] [HasImages C] /-- A category has strong epi images if it has all images and `factorThruImage f` is a strong epimorphism for all `f`. -/ class HasStrongEpiImages : Prop where strong_factorThruImage : ∀ {X Y : C} (f : X ⟶ Y), StrongEpi (factorThruImage f) attribute [instance] HasStrongEpiImages.strong_factorThruImage end HasStrongEpiImages section HasStrongEpiImages /-- If there is a single strong epi-mono factorisation of `f`, then every image factorisation is a strong epi-mono factorisation. -/ theorem strongEpi_of_strongEpiMonoFactorisation {X Y : C} {f : X ⟶ Y} (F : StrongEpiMonoFactorisation f) {F' : MonoFactorisation f} (hF' : IsImage F') : StrongEpi F'.e := by rw [← IsImage.e_isoExt_hom F.toMonoIsImage hF'] apply strongEpi_comp theorem strongEpi_factorThruImage_of_strongEpiMonoFactorisation {X Y : C} {f : X ⟶ Y} [HasImage f] (F : StrongEpiMonoFactorisation f) : StrongEpi (factorThruImage f) := strongEpi_of_strongEpiMonoFactorisation F <| Image.isImage f /-- If we constructed our images from strong epi-mono factorisations, then these images are strong epi images. -/ instance (priority := 100) hasStrongEpiImages_of_hasStrongEpiMonoFactorisations [HasStrongEpiMonoFactorisations C] : HasStrongEpiImages C where strong_factorThruImage f := strongEpi_factorThruImage_of_strongEpiMonoFactorisation <| Classical.choice <| HasStrongEpiMonoFactorisations.has_fac f end HasStrongEpiImages section HasStrongEpiImages variable [HasImages C] /-- A category with strong epi images has image maps. -/ instance (priority := 100) hasImageMapsOfHasStrongEpiImages [HasStrongEpiImages C] : HasImageMaps C where has_image_map {f} {g} st := HasImageMap.mk { map := (CommSq.mk (show (st.left ≫ factorThruImage g.hom) ≫ image.ι g.hom = factorThruImage f.hom ≫ image.ι f.hom ≫ st.right by simp)).lift } /-- If a category has images, equalizers and pullbacks, then images are automatically strong epi images. -/ instance (priority := 100) hasStrongEpiImages_of_hasPullbacks_of_hasEqualizers [HasPullbacks C] [HasEqualizers C] : HasStrongEpiImages C where strong_factorThruImage f := StrongEpi.mk' fun {A} {B} h h_mono x y sq => CommSq.HasLift.mk' { l := image.lift { I := pullback h y m := pullback.snd h y ≫ image.ι f m_mono := mono_comp _ _ e := pullback.lift _ _ sq.w } ≫ pullback.fst h y fac_left := by simp only [image.fac_lift_assoc, pullback.lift_fst] fac_right := by apply image.ext simp only [sq.w, Category.assoc, image.fac_lift_assoc, pullback.lift_fst_assoc] } end HasStrongEpiImages variable [HasStrongEpiMonoFactorisations C] variable {X Y : C} {f : X ⟶ Y} /-- If `C` has strong epi mono factorisations, then the image is unique up to isomorphism, in that if `f` factors as a strong epi followed by a mono, this factorisation is essentially the image factorisation. -/ def image.isoStrongEpiMono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : I' ≅ image f := let F : StrongEpiMonoFactorisation f := { I := I', m := m, e := e} IsImage.isoExt F.toMonoIsImage <| Image.isImage f @[simp] theorem image.isoStrongEpiMono_hom_comp_ι {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : (image.isoStrongEpiMono e m comm).hom ≫ image.ι f = m := by dsimp [isoStrongEpiMono] apply IsImage.lift_fac @[simp] theorem image.isoStrongEpiMono_inv_comp_mono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [StrongEpi e] [Mono m] : (image.isoStrongEpiMono e m comm).inv ≫ m = image.ι f := image.lift_fac _ open MorphismProperty variable (C) /-- A category with strong epi mono factorisations admits functorial epi/mono factorizations. -/ noncomputable def functorialEpiMonoFactorizationData : FunctorialFactorizationData (epimorphisms C) (monomorphisms C) where Z := im i := { app := fun f => factorThruImage f.hom } p := { app := fun f => image.ι f.hom } hi _ := epimorphisms.infer_property _ hp _ := monomorphisms.infer_property _ end CategoryTheory.Limits namespace CategoryTheory.Functor open CategoryTheory.Limits variable {C D : Type*} [Category C] [Category D] theorem hasStrongEpiMonoFactorisations_imp_of_isEquivalence (F : C ⥤ D) [IsEquivalence F] [h : HasStrongEpiMonoFactorisations C] : HasStrongEpiMonoFactorisations D := ⟨fun {X} {Y} f => by let em : StrongEpiMonoFactorisation (F.inv.map f) := (HasStrongEpiMonoFactorisations.has_fac (F.inv.map f)).some haveI : Mono (F.map em.m ≫ F.asEquivalence.counitIso.hom.app Y) := mono_comp _ _ haveI : StrongEpi (F.asEquivalence.counitIso.inv.app X ≫ F.map em.e) := strongEpi_comp _ _ exact Nonempty.intro { I := F.obj em.I e := F.asEquivalence.counitIso.inv.app X ≫ F.map em.e m := F.map em.m ≫ F.asEquivalence.counitIso.hom.app Y fac := by simp only [asEquivalence_functor, Category.assoc, ← F.map_comp_assoc, MonoFactorisation.fac, fun_inv_map, id_obj, Iso.inv_hom_id_app, Category.comp_id, Iso.inv_hom_id_app_assoc] }⟩ end CategoryTheory.Functor
CategoryTheory\Limits\Shapes\KernelPair.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.RegularMono /-! # Kernel pairs This file defines what it means for a parallel pair of morphisms `a b : R ⟶ X` to be the kernel pair for a morphism `f`. Some properties of kernel pairs are given, namely allowing one to transfer between the kernel pair of `f₁ ≫ f₂` to the kernel pair of `f₁`. It is also proved that if `f` is a coequalizer of some pair, and `a`,`b` is a kernel pair for `f` then it is a coequalizer of `a`,`b`. ## Implementation The definition is essentially just a wrapper for `IsLimit (PullbackCone.mk _ _ _)`, but the constructions given here are useful, yet awkward to present in that language, so a basic API is developed here. ## TODO - Internal equivalence relations (or congruences) and the fact that every kernel pair induces one, and the converse in an effective regular category (WIP by b-mehta). -/ universe v u u₂ namespace CategoryTheory open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {R X Y Z : C} (f : X ⟶ Y) (a b : R ⟶ X) /-- `IsKernelPair f a b` expresses that `(a, b)` is a kernel pair for `f`, i.e. `a ≫ f = b ≫ f` and the square R → X ↓ ↓ X → Y is a pullback square. This is just an abbreviation for `IsPullback a b f f`. -/ abbrev IsKernelPair := IsPullback a b f f namespace IsKernelPair /-- The data expressing that `(a, b)` is a kernel pair is subsingleton. -/ instance : Subsingleton (IsKernelPair f a b) := ⟨fun P Q => by cases P cases Q congr ⟩ /-- If `f` is a monomorphism, then `(𝟙 _, 𝟙 _)` is a kernel pair for `f`. -/ theorem id_of_mono [Mono f] : IsKernelPair f (𝟙 _) (𝟙 _) := ⟨⟨rfl⟩, ⟨PullbackCone.isLimitMkIdId _⟩⟩ instance [Mono f] : Inhabited (IsKernelPair f (𝟙 _) (𝟙 _)) := ⟨id_of_mono f⟩ variable {f a b} -- Porting note: `lift` and the two following simp lemmas were introduced to ease the port /-- Given a pair of morphisms `p`, `q` to `X` which factor through `f`, they factor through any kernel pair of `f`. -/ noncomputable def lift {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : S ⟶ R := PullbackCone.IsLimit.lift k.isLimit _ _ w @[reassoc (attr := simp)] lemma lift_fst {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : k.lift p q w ≫ a = p := PullbackCone.IsLimit.lift_fst _ _ _ _ @[reassoc (attr := simp)] lemma lift_snd {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : k.lift p q w ≫ b = q := PullbackCone.IsLimit.lift_snd _ _ _ _ /-- Given a pair of morphisms `p`, `q` to `X` which factor through `f`, they factor through any kernel pair of `f`. -/ noncomputable def lift' {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) : { t : S ⟶ R // t ≫ a = p ∧ t ≫ b = q } := ⟨k.lift p q w, by simp⟩ /-- If `(a,b)` is a kernel pair for `f₁ ≫ f₂` and `a ≫ f₁ = b ≫ f₁`, then `(a,b)` is a kernel pair for just `f₁`. That is, to show that `(a,b)` is a kernel pair for `f₁` it suffices to only show the square commutes, rather than to additionally show it's a pullback. -/ theorem cancel_right {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} (comm : a ≫ f₁ = b ≫ f₁) (big_k : IsKernelPair (f₁ ≫ f₂) a b) : IsKernelPair f₁ a b := { w := comm isLimit' := ⟨PullbackCone.isLimitAux' _ fun s => by let s' : PullbackCone (f₁ ≫ f₂) (f₁ ≫ f₂) := PullbackCone.mk s.fst s.snd (s.condition_assoc _) refine ⟨big_k.isLimit.lift s', big_k.isLimit.fac _ WalkingCospan.left, big_k.isLimit.fac _ WalkingCospan.right, fun m₁ m₂ => ?_⟩ apply big_k.isLimit.hom_ext refine (PullbackCone.mk a b ?_ : PullbackCone (f₁ ≫ f₂) _).equalizer_ext ?_ ?_ · apply reassoc_of% comm · apply m₁.trans (big_k.isLimit.fac s' WalkingCospan.left).symm · apply m₂.trans (big_k.isLimit.fac s' WalkingCospan.right).symm⟩ } /-- If `(a,b)` is a kernel pair for `f₁ ≫ f₂` and `f₂` is mono, then `(a,b)` is a kernel pair for just `f₁`. The converse of `comp_of_mono`. -/ theorem cancel_right_of_mono {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} [Mono f₂] (big_k : IsKernelPair (f₁ ≫ f₂) a b) : IsKernelPair f₁ a b := cancel_right (by rw [← cancel_mono f₂, assoc, assoc, big_k.w]) big_k /-- If `(a,b)` is a kernel pair for `f₁` and `f₂` is mono, then `(a,b)` is a kernel pair for `f₁ ≫ f₂`. The converse of `cancel_right_of_mono`. -/ theorem comp_of_mono {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} [Mono f₂] (small_k : IsKernelPair f₁ a b) : IsKernelPair (f₁ ≫ f₂) a b := { w := by rw [small_k.w_assoc] isLimit' := ⟨by refine PullbackCone.isLimitAux _ (fun s => small_k.lift s.fst s.snd (by rw [← cancel_mono f₂, assoc, s.condition, assoc])) (by simp) (by simp) ?_ intro s m hm apply small_k.isLimit.hom_ext apply PullbackCone.equalizer_ext small_k.cone _ _ · exact (hm WalkingCospan.left).trans (by simp) · exact (hm WalkingCospan.right).trans (by simp)⟩ } /-- If `(a,b)` is the kernel pair of `f`, and `f` is a coequalizer morphism for some parallel pair, then `f` is a coequalizer morphism of `a` and `b`. -/ def toCoequalizer (k : IsKernelPair f a b) [r : RegularEpi f] : IsColimit (Cofork.ofπ f k.w) := by let t := k.isLimit.lift (PullbackCone.mk _ _ r.w) have ht : t ≫ a = r.left := k.isLimit.fac _ WalkingCospan.left have kt : t ≫ b = r.right := k.isLimit.fac _ WalkingCospan.right refine Cofork.IsColimit.mk _ (fun s => Cofork.IsColimit.desc r.isColimit s.π (by rw [← ht, assoc, s.condition, reassoc_of% kt])) (fun s => ?_) (fun s m w => ?_) · apply Cofork.IsColimit.π_desc' r.isColimit · apply Cofork.IsColimit.hom_ext r.isColimit exact w.trans (Cofork.IsColimit.π_desc' r.isColimit _ _).symm /-- If `a₁ a₂ : A ⟶ Y` is a kernel pair for `g : Y ⟶ Z`, then `a₁ ×[Z] X` and `a₂ ×[Z] X` (`A ×[Z] X ⟶ Y ×[Z] X`) is a kernel pair for `Y ×[Z] X ⟶ X`. -/ protected theorem pullback {X Y Z A : C} {g : Y ⟶ Z} {a₁ a₂ : A ⟶ Y} (h : IsKernelPair g a₁ a₂) (f : X ⟶ Z) [HasPullback f g] [HasPullback f (a₁ ≫ g)] : IsKernelPair (pullback.fst f g) (pullback.map f _ f _ (𝟙 X) a₁ (𝟙 Z) (by simp) <| Category.comp_id _) (pullback.map _ _ _ _ (𝟙 X) a₂ (𝟙 Z) (by simp) <| (Category.comp_id _).trans h.1.1) := by refine ⟨⟨by rw [pullback.lift_fst, pullback.lift_fst]⟩, ⟨PullbackCone.isLimitAux _ (fun s => pullback.lift (s.fst ≫ pullback.fst _ _) (h.lift (s.fst ≫ pullback.snd _ _) (s.snd ≫ pullback.snd _ _) ?_ ) ?_) (fun s => ?_) (fun s => ?_) (fun s m hm => ?_)⟩⟩ · simp_rw [Category.assoc, ← pullback.condition, ← Category.assoc, s.condition] · simp only [assoc, lift_fst_assoc, pullback.condition] · ext <;> simp · ext · simp [s.condition] · simp · #adaptation_note /-- nightly-2024-04-01 This `symm` (or the following ones that undo it) wasn't previously necessary. -/ symm apply pullback.hom_ext · symm simpa using hm WalkingCospan.left =≫ pullback.fst f g · symm apply PullbackCone.IsLimit.hom_ext h.isLimit · simpa using hm WalkingCospan.left =≫ pullback.snd f g · simpa using hm WalkingCospan.right =≫ pullback.snd f g theorem mono_of_isIso_fst (h : IsKernelPair f a b) [IsIso a] : Mono f := by obtain ⟨l, h₁, h₂⟩ := Limits.PullbackCone.IsLimit.lift' h.isLimit (𝟙 _) (𝟙 _) (by simp [h.w]) rw [IsPullback.cone_fst, ← IsIso.eq_comp_inv, Category.id_comp] at h₁ rw [h₁, IsIso.inv_comp_eq, Category.comp_id] at h₂ constructor intro Z g₁ g₂ e obtain ⟨l', rfl, rfl⟩ := Limits.PullbackCone.IsLimit.lift' h.isLimit _ _ e rw [IsPullback.cone_fst, h₂] theorem isIso_of_mono (h : IsKernelPair f a b) [Mono f] : IsIso a := by rw [← show _ = a from (Category.comp_id _).symm.trans ((IsKernelPair.id_of_mono f).isLimit.conePointUniqueUpToIso_inv_comp h.isLimit WalkingCospan.left)] infer_instance theorem of_isIso_of_mono [IsIso a] [Mono f] : IsKernelPair f a a := by change IsPullback _ _ _ _ convert (IsPullback.of_horiz_isIso ⟨(rfl : a ≫ 𝟙 X = _ )⟩).paste_vert (IsKernelPair.id_of_mono f) all_goals { simp } end IsKernelPair end CategoryTheory
CategoryTheory\Limits\Shapes\Kernels.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero /-! # Kernels and cokernels In a category with zero morphisms, the kernel of a morphism `f : X ⟶ Y` is the equalizer of `f` and `0 : X ⟶ Y`. (Similarly the cokernel is the coequalizer.) The basic definitions are * `kernel : (X ⟶ Y) → C` * `kernel.ι : kernel f ⟶ X` * `kernel.condition : kernel.ι f ≫ f = 0` and * `kernel.lift (k : W ⟶ X) (h : k ≫ f = 0) : W ⟶ kernel f` (as well as the dual versions) ## Main statements Besides the definition and lifts, we prove * `kernel.ιZeroIsIso`: a kernel map of a zero morphism is an isomorphism * `kernel.eq_zero_of_epi_kernel`: if `kernel.ι f` is an epimorphism, then `f = 0` * `kernel.ofMono`: the kernel of a monomorphism is the zero object * `kernel.liftMono`: the lift of a monomorphism `k : W ⟶ X` such that `k ≫ f = 0` is still a monomorphism * `kernel.isLimitConeZeroCone`: if our category has a zero object, then the map from the zero object is a kernel map of any monomorphism * `kernel.ιOfZero`: `kernel.ι (0 : X ⟶ Y)` is an isomorphism and the corresponding dual statements. ## Future work * TODO: connect this with existing work in the group theory and ring theory libraries. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v v₂ u u' u₂ open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable [HasZeroMorphisms C] /-- A morphism `f` has a kernel if the functor `ParallelPair f 0` has a limit. -/ abbrev HasKernel {X Y : C} (f : X ⟶ Y) : Prop := HasLimit (parallelPair f 0) /-- A morphism `f` has a cokernel if the functor `ParallelPair f 0` has a colimit. -/ abbrev HasCokernel {X Y : C} (f : X ⟶ Y) : Prop := HasColimit (parallelPair f 0) variable {X Y : C} (f : X ⟶ Y) section /-- A kernel fork is just a fork where the second morphism is a zero morphism. -/ abbrev KernelFork := Fork f 0 variable {f} @[reassoc (attr := simp)] theorem KernelFork.condition (s : KernelFork f) : Fork.ι s ≫ f = 0 := by erw [Fork.condition, HasZeroMorphisms.comp_zero] -- Porting note (#10618): simp can prove this, removed simp tag theorem KernelFork.app_one (s : KernelFork f) : s.π.app one = 0 := by simp [Fork.app_one_eq_ι_comp_right] /-- A morphism `ι` satisfying `ι ≫ f = 0` determines a kernel fork over `f`. -/ abbrev KernelFork.ofι {Z : C} (ι : Z ⟶ X) (w : ι ≫ f = 0) : KernelFork f := Fork.ofι ι <| by rw [w, HasZeroMorphisms.comp_zero] @[simp] theorem KernelFork.ι_ofι {X Y P : C} (f : X ⟶ Y) (ι : P ⟶ X) (w : ι ≫ f = 0) : Fork.ι (KernelFork.ofι ι w) = ι := rfl section -- attribute [local tidy] tactic.case_bash Porting note: no tidy nor case_bash /-- Every kernel fork `s` is isomorphic (actually, equal) to `fork.ofι (fork.ι s) _`. -/ def isoOfι (s : Fork f 0) : s ≅ Fork.ofι (Fork.ι s) (Fork.condition s) := Cones.ext (Iso.refl _) <| by rintro ⟨j⟩ <;> simp /-- If `ι = ι'`, then `fork.ofι ι _` and `fork.ofι ι' _` are isomorphic. -/ def ofιCongr {P : C} {ι ι' : P ⟶ X} {w : ι ≫ f = 0} (h : ι = ι') : KernelFork.ofι ι w ≅ KernelFork.ofι ι' (by rw [← h, w]) := Cones.ext (Iso.refl _) /-- If `F` is an equivalence, then applying `F` to a diagram indexing a (co)kernel of `f` yields the diagram indexing the (co)kernel of `F.map f`. -/ def compNatIso {D : Type u'} [Category.{v} D] [HasZeroMorphisms D] (F : C ⥤ D) [F.IsEquivalence] : parallelPair f 0 ⋙ F ≅ parallelPair (F.map f) 0 := let app (j : WalkingParallelPair) : (parallelPair f 0 ⋙ F).obj j ≅ (parallelPair (F.map f) 0).obj j := match j with | zero => Iso.refl _ | one => Iso.refl _ NatIso.ofComponents app <| by rintro ⟨i⟩ ⟨j⟩ <;> intro g <;> cases g <;> simp [app] end /-- If `s` is a limit kernel fork and `k : W ⟶ X` satisfies `k ≫ f = 0`, then there is some `l : W ⟶ s.X` such that `l ≫ fork.ι s = k`. -/ def KernelFork.IsLimit.lift' {s : KernelFork f} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : { l : W ⟶ s.pt // l ≫ Fork.ι s = k } := ⟨hs.lift <| KernelFork.ofι _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a kernel fork is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : KernelFork f) (lift : ∀ s : KernelFork f, s.pt ⟶ t.pt) (fac : ∀ s : KernelFork f, lift s ≫ t.ι = s.ι) (uniq : ∀ (s : KernelFork f) (m : s.pt ⟶ t.pt) (_ : m ≫ t.ι = s.ι), m = lift s) : IsLimit t := { lift fac := fun s j => by cases j · exact fac s · simp uniq := fun s m w => uniq s m (w Limits.WalkingParallelPair.zero) } /-- This is a more convenient formulation to show that a `KernelFork` constructed using `KernelFork.ofι` is a limit cone. -/ def KernelFork.IsLimit.ofι {W : C} (g : W ⟶ X) (eq : g ≫ f = 0) (lift : ∀ {W' : C} (g' : W' ⟶ X) (_ : g' ≫ f = 0), W' ⟶ W) (fac : ∀ {W' : C} (g' : W' ⟶ X) (eq' : g' ≫ f = 0), lift g' eq' ≫ g = g') (uniq : ∀ {W' : C} (g' : W' ⟶ X) (eq' : g' ≫ f = 0) (m : W' ⟶ W) (_ : m ≫ g = g'), m = lift g' eq') : IsLimit (KernelFork.ofι g eq) := isLimitAux _ (fun s => lift s.ι s.condition) (fun s => fac s.ι s.condition) fun s => uniq s.ι s.condition /-- This is a more convenient formulation to show that a `KernelFork` of the form `KernelFork.ofι i _` is a limit cone when we know that `i` is a monomorphism. -/ def KernelFork.IsLimit.ofι' {X Y K : C} {f : X ⟶ Y} (i : K ⟶ X) (w : i ≫ f = 0) (h : ∀ {A : C} (k : A ⟶ X) (_ : k ≫ f = 0), { l : A ⟶ K // l ≫ i = k}) [hi : Mono i] : IsLimit (KernelFork.ofι i w) := ofι _ _ (fun {A} k hk => (h k hk).1) (fun {A} k hk => (h k hk).2) (fun {A} k hk m hm => by rw [← cancel_mono i, (h k hk).2, hm]) /-- Every kernel of `f` induces a kernel of `f ≫ g` if `g` is mono. -/ def isKernelCompMono {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟶ Z) [hg : Mono g] {h : X ⟶ Z} (hh : h = f ≫ g) : IsLimit (KernelFork.ofι c.ι (by simp [hh]) : KernelFork h) := Fork.IsLimit.mk' _ fun s => let s' : KernelFork f := Fork.ofι s.ι (by rw [← cancel_mono g]; simp [← hh, s.condition]) let l := KernelFork.IsLimit.lift' i s'.ι s'.condition ⟨l.1, l.2, fun hm => by apply Fork.IsLimit.hom_ext i; rw [Fork.ι_ofι] at hm; rw [hm]; exact l.2.symm⟩ theorem isKernelCompMono_lift {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟶ Z) [hg : Mono g] {h : X ⟶ Z} (hh : h = f ≫ g) (s : KernelFork h) : (isKernelCompMono i g hh).lift s = i.lift (Fork.ofι s.ι (by rw [← cancel_mono g, Category.assoc, ← hh] simp)) := rfl /-- Every kernel of `f ≫ g` is also a kernel of `f`, as long as `c.ι ≫ f` vanishes. -/ def isKernelOfComp {W : C} (g : Y ⟶ W) (h : X ⟶ W) {c : KernelFork h} (i : IsLimit c) (hf : c.ι ≫ f = 0) (hfg : f ≫ g = h) : IsLimit (KernelFork.ofι c.ι hf) := Fork.IsLimit.mk _ (fun s => i.lift (KernelFork.ofι s.ι (by simp [← hfg]))) (fun s => by simp only [KernelFork.ι_ofι, Fork.IsLimit.lift_ι]) fun s m h => by apply Fork.IsLimit.hom_ext i; simpa using h /-- `X` identifies to the kernel of a zero map `X ⟶ Y`. -/ def KernelFork.IsLimit.ofId {X Y : C} (f : X ⟶ Y) (hf : f = 0) : IsLimit (KernelFork.ofι (𝟙 X) (show 𝟙 X ≫ f = 0 by rw [hf, comp_zero])) := KernelFork.IsLimit.ofι _ _ (fun x _ => x) (fun _ _ => Category.comp_id _) (fun _ _ _ hb => by simp only [← hb, Category.comp_id]) /-- Any zero object identifies to the kernel of a given monomorphisms. -/ def KernelFork.IsLimit.ofMonoOfIsZero {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hf : Mono f) (h : IsZero c.pt) : IsLimit c := isLimitAux _ (fun s => 0) (fun s => by rw [zero_comp, ← cancel_mono f, zero_comp, s.condition]) (fun _ _ _ => h.eq_of_tgt _ _) lemma KernelFork.IsLimit.isIso_ι {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hc : IsLimit c) (hf : f = 0) : IsIso c.ι := by let e : c.pt ≅ X := IsLimit.conePointUniqueUpToIso hc (KernelFork.IsLimit.ofId (f : X ⟶ Y) hf) have eq : e.inv ≫ c.ι = 𝟙 X := Fork.IsLimit.lift_ι hc haveI : IsIso (e.inv ≫ c.ι) := by rw [eq] infer_instance exact IsIso.of_isIso_comp_left e.inv c.ι end namespace KernelFork variable {f} {X' Y' : C} {f' : X' ⟶ Y'} /-- The morphism between points of kernel forks induced by a morphism in the category of arrows. -/ def mapOfIsLimit (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (φ : Arrow.mk f ⟶ Arrow.mk f') : kf.pt ⟶ kf'.pt := hf'.lift (KernelFork.ofι (kf.ι ≫ φ.left) (by simp)) @[reassoc (attr := simp)] lemma mapOfIsLimit_ι (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (φ : Arrow.mk f ⟶ Arrow.mk f') : kf.mapOfIsLimit hf' φ ≫ kf'.ι = kf.ι ≫ φ.left := hf'.fac _ _ /-- The isomorphism between points of limit kernel forks induced by an isomorphism in the category of arrows. -/ @[simps] def mapIsoOfIsLimit {kf : KernelFork f} {kf' : KernelFork f'} (hf : IsLimit kf) (hf' : IsLimit kf') (φ : Arrow.mk f ≅ Arrow.mk f') : kf.pt ≅ kf'.pt where hom := kf.mapOfIsLimit hf' φ.hom inv := kf'.mapOfIsLimit hf φ.inv hom_inv_id := Fork.IsLimit.hom_ext hf (by simp) inv_hom_id := Fork.IsLimit.hom_ext hf' (by simp) end KernelFork section variable [HasKernel f] /-- The kernel of a morphism, expressed as the equalizer with the 0 morphism. -/ abbrev kernel (f : X ⟶ Y) [HasKernel f] : C := equalizer f 0 /-- The map from `kernel f` into the source of `f`. -/ abbrev kernel.ι : kernel f ⟶ X := equalizer.ι f 0 @[simp] theorem equalizer_as_kernel : equalizer.ι f 0 = kernel.ι f := rfl @[reassoc (attr := simp)] theorem kernel.condition : kernel.ι f ≫ f = 0 := KernelFork.condition _ /-- The kernel built from `kernel.ι f` is limiting. -/ def kernelIsKernel : IsLimit (Fork.ofι (kernel.ι f) ((kernel.condition f).trans comp_zero.symm)) := IsLimit.ofIsoLimit (limit.isLimit _) (Fork.ext (Iso.refl _) (by aesop_cat)) /-- Given any morphism `k : W ⟶ X` satisfying `k ≫ f = 0`, `k` factors through `kernel.ι f` via `kernel.lift : W ⟶ kernel f`. -/ abbrev kernel.lift {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : W ⟶ kernel f := (kernelIsKernel f).lift (KernelFork.ofι k h) @[reassoc (attr := simp)] theorem kernel.lift_ι {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : kernel.lift f k h ≫ kernel.ι f = k := (kernelIsKernel f).fac (KernelFork.ofι k h) WalkingParallelPair.zero @[simp] theorem kernel.lift_zero {W : C} {h} : kernel.lift f (0 : W ⟶ X) h = 0 := by ext; simp instance kernel.lift_mono {W : C} (k : W ⟶ X) (h : k ≫ f = 0) [Mono k] : Mono (kernel.lift f k h) := ⟨fun {Z} g g' w => by replace w := w =≫ kernel.ι f simp only [Category.assoc, kernel.lift_ι] at w exact (cancel_mono k).1 w⟩ /-- Any morphism `k : W ⟶ X` satisfying `k ≫ f = 0` induces a morphism `l : W ⟶ kernel f` such that `l ≫ kernel.ι f = k`. -/ def kernel.lift' {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : { l : W ⟶ kernel f // l ≫ kernel.ι f = k } := ⟨kernel.lift f k h, kernel.lift_ι _ _ _⟩ /-- A commuting square induces a morphism of kernels. -/ abbrev kernel.map {X' Y' : C} (f' : X' ⟶ Y') [HasKernel f'] (p : X ⟶ X') (q : Y ⟶ Y') (w : f ≫ q = p ≫ f') : kernel f ⟶ kernel f' := kernel.lift f' (kernel.ι f ≫ p) (by simp [← w]) /-- Given a commutative diagram X --f--> Y --g--> Z | | | | | | v v v X' -f'-> Y' -g'-> Z' with horizontal arrows composing to zero, then we obtain a commutative square X ---> kernel g | | | | kernel.map | | v v X' --> kernel g' -/ theorem kernel.lift_map {X Y Z X' Y' Z' : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasKernel g] (w : f ≫ g = 0) (f' : X' ⟶ Y') (g' : Y' ⟶ Z') [HasKernel g'] (w' : f' ≫ g' = 0) (p : X ⟶ X') (q : Y ⟶ Y') (r : Z ⟶ Z') (h₁ : f ≫ q = p ≫ f') (h₂ : g ≫ r = q ≫ g') : kernel.lift g f w ≫ kernel.map g g' q r h₂ = p ≫ kernel.lift g' f' w' := by ext; simp [h₁] /-- A commuting square of isomorphisms induces an isomorphism of kernels. -/ @[simps] def kernel.mapIso {X' Y' : C} (f' : X' ⟶ Y') [HasKernel f'] (p : X ≅ X') (q : Y ≅ Y') (w : f ≫ q.hom = p.hom ≫ f') : kernel f ≅ kernel f' where hom := kernel.map f f' p.hom q.hom w inv := kernel.map f' f p.inv q.inv (by refine (cancel_mono q.hom).1 ?_ simp [w]) /-- Every kernel of the zero morphism is an isomorphism -/ instance kernel.ι_zero_isIso : IsIso (kernel.ι (0 : X ⟶ Y)) := equalizer.ι_of_self _ theorem eq_zero_of_epi_kernel [Epi (kernel.ι f)] : f = 0 := (cancel_epi (kernel.ι f)).1 (by simp) /-- The kernel of a zero morphism is isomorphic to the source. -/ def kernelZeroIsoSource : kernel (0 : X ⟶ Y) ≅ X := equalizer.isoSourceOfSelf 0 @[simp] theorem kernelZeroIsoSource_hom : kernelZeroIsoSource.hom = kernel.ι (0 : X ⟶ Y) := rfl @[simp] theorem kernelZeroIsoSource_inv : kernelZeroIsoSource.inv = kernel.lift (0 : X ⟶ Y) (𝟙 X) (by simp) := by ext simp [kernelZeroIsoSource] /-- If two morphisms are known to be equal, then their kernels are isomorphic. -/ def kernelIsoOfEq {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : kernel f ≅ kernel g := HasLimit.isoOfNatIso (by rw [h]) @[simp] theorem kernelIsoOfEq_refl {h : f = f} : kernelIsoOfEq h = Iso.refl (kernel f) := by ext simp [kernelIsoOfEq] /- Porting note: induction on Eq is trying instantiate another g... -/ @[reassoc (attr := simp)] theorem kernelIsoOfEq_hom_comp_ι {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).hom ≫ kernel.ι g = kernel.ι f := by cases h; simp @[reassoc (attr := simp)] theorem kernelIsoOfEq_inv_comp_ι {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).inv ≫ kernel.ι _ = kernel.ι _ := by cases h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_hom {Z} {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟶ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).hom = kernel.lift _ e (by simp [← h, he]) := by cases h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_inv {Z} {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟶ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).inv = kernel.lift _ e (by simp [h, he]) := by cases h; simp @[simp] theorem kernelIsoOfEq_trans {f g h : X ⟶ Y} [HasKernel f] [HasKernel g] [HasKernel h] (w₁ : f = g) (w₂ : g = h) : kernelIsoOfEq w₁ ≪≫ kernelIsoOfEq w₂ = kernelIsoOfEq (w₁.trans w₂) := by cases w₁; cases w₂; ext; simp [kernelIsoOfEq] variable {f} theorem kernel_not_epi_of_nonzero (w : f ≠ 0) : ¬Epi (kernel.ι f) := fun _ => w (eq_zero_of_epi_kernel f) theorem kernel_not_iso_of_nonzero (w : f ≠ 0) : IsIso (kernel.ι f) → False := fun _ => kernel_not_epi_of_nonzero w inferInstance instance hasKernel_comp_mono {X Y Z : C} (f : X ⟶ Y) [HasKernel f] (g : Y ⟶ Z) [Mono g] : HasKernel (f ≫ g) := ⟨⟨{ cone := _ isLimit := isKernelCompMono (limit.isLimit _) g rfl }⟩⟩ /-- When `g` is a monomorphism, the kernel of `f ≫ g` is isomorphic to the kernel of `f`. -/ @[simps] def kernelCompMono {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasKernel f] [Mono g] : kernel (f ≫ g) ≅ kernel f where hom := kernel.lift _ (kernel.ι _) (by rw [← cancel_mono g] simp) inv := kernel.lift _ (kernel.ι _) (by simp) #adaptation_note /-- nightly-2024-04-01 The `symm` wasn't previously necessary. -/ instance hasKernel_iso_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [HasKernel g] : HasKernel (f ≫ g) where exists_limit := ⟨{ cone := KernelFork.ofι (kernel.ι g ≫ inv f) (by simp) isLimit := isLimitAux _ (fun s => kernel.lift _ (s.ι ≫ f) (by aesop_cat)) (by aesop_cat) fun s m w => by simp_rw [← w] symm apply equalizer.hom_ext simp }⟩ /-- When `f` is an isomorphism, the kernel of `f ≫ g` is isomorphic to the kernel of `g`. -/ @[simps] def kernelIsIsoComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [HasKernel g] : kernel (f ≫ g) ≅ kernel g where hom := kernel.lift _ (kernel.ι _ ≫ f) (by simp) inv := kernel.lift _ (kernel.ι _ ≫ inv f) (by simp) end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The morphism from the zero object determines a cone on a kernel diagram -/ def kernel.zeroKernelFork : KernelFork f where pt := 0 π := { app := fun j => 0 } /-- The map from the zero object is a kernel of a monomorphism -/ def kernel.isLimitConeZeroCone [Mono f] : IsLimit (kernel.zeroKernelFork f) := Fork.IsLimit.mk _ (fun s => 0) (fun s => by erw [zero_comp] refine (zero_of_comp_mono f ?_).symm exact KernelFork.condition _) fun _ _ _ => zero_of_to_zero _ /-- The kernel of a monomorphism is isomorphic to the zero object -/ def kernel.ofMono [HasKernel f] [Mono f] : kernel f ≅ 0 := Functor.mapIso (Cones.forget _) <| IsLimit.uniqueUpToIso (limit.isLimit (parallelPair f 0)) (kernel.isLimitConeZeroCone f) /-- The kernel morphism of a monomorphism is a zero morphism -/ theorem kernel.ι_of_mono [HasKernel f] [Mono f] : kernel.ι f = 0 := zero_of_source_iso_zero _ (kernel.ofMono f) /-- If `g ≫ f = 0` implies `g = 0` for all `g`, then `0 : 0 ⟶ X` is a kernel of `f`. -/ def zeroKernelOfCancelZero {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Z ⟶ X) (_ : g ≫ f = 0), g = 0) : IsLimit (KernelFork.ofι (0 : 0 ⟶ X) (show 0 ≫ f = 0 by simp)) := Fork.IsLimit.mk _ (fun s => 0) (fun s => by rw [hf _ _ (KernelFork.condition s), zero_comp]) fun s m _ => by dsimp; apply HasZeroObject.to_zero_ext end HasZeroObject section Transport /-- If `i` is an isomorphism such that `l ≫ i.hom = f`, any kernel of `f` is a kernel of `l`. -/ def IsKernel.ofCompIso {Z : C} (l : X ⟶ Z) (i : Z ≅ Y) (h : l ≫ i.hom = f) {s : KernelFork f} (hs : IsLimit s) : IsLimit (KernelFork.ofι (Fork.ι s) <| show Fork.ι s ≫ l = 0 by simp [← i.comp_inv_eq.2 h.symm]) := Fork.IsLimit.mk _ (fun s => hs.lift <| KernelFork.ofι (Fork.ι s) <| by simp [← h]) (fun s => by simp) fun s m h => by apply Fork.IsLimit.hom_ext hs simpa using h /-- If `i` is an isomorphism such that `l ≫ i.hom = f`, the kernel of `f` is a kernel of `l`. -/ def kernel.ofCompIso [HasKernel f] {Z : C} (l : X ⟶ Z) (i : Z ≅ Y) (h : l ≫ i.hom = f) : IsLimit (KernelFork.ofι (kernel.ι f) <| show kernel.ι f ≫ l = 0 by simp [← i.comp_inv_eq.2 h.symm]) := IsKernel.ofCompIso f l i h <| limit.isLimit _ /-- If `s` is any limit kernel cone over `f` and if `i` is an isomorphism such that `i.hom ≫ s.ι = l`, then `l` is a kernel of `f`. -/ def IsKernel.isoKernel {Z : C} (l : Z ⟶ X) {s : KernelFork f} (hs : IsLimit s) (i : Z ≅ s.pt) (h : i.hom ≫ Fork.ι s = l) : IsLimit (KernelFork.ofι l <| show l ≫ f = 0 by simp [← h]) := IsLimit.ofIsoLimit hs <| Cones.ext i.symm fun j => by cases j · exact (Iso.eq_inv_comp i).2 h · dsimp; rw [← h]; simp /-- If `i` is an isomorphism such that `i.hom ≫ kernel.ι f = l`, then `l` is a kernel of `f`. -/ def kernel.isoKernel [HasKernel f] {Z : C} (l : Z ⟶ X) (i : Z ≅ kernel f) (h : i.hom ≫ kernel.ι f = l) : IsLimit (@KernelFork.ofι _ _ _ _ _ f _ l <| by simp [← h]) := IsKernel.isoKernel f l (limit.isLimit _) i h end Transport section variable (X Y) /-- The kernel morphism of a zero morphism is an isomorphism -/ theorem kernel.ι_of_zero : IsIso (kernel.ι (0 : X ⟶ Y)) := equalizer.ι_of_self _ end section /-- A cokernel cofork is just a cofork where the second morphism is a zero morphism. -/ abbrev CokernelCofork := Cofork f 0 variable {f} @[reassoc (attr := simp)] theorem CokernelCofork.condition (s : CokernelCofork f) : f ≫ s.π = 0 := by rw [Cofork.condition, zero_comp] -- Porting note (#10618): simp can prove this, removed simp tag theorem CokernelCofork.π_eq_zero (s : CokernelCofork f) : s.ι.app zero = 0 := by simp [Cofork.app_zero_eq_comp_π_right] /-- A morphism `π` satisfying `f ≫ π = 0` determines a cokernel cofork on `f`. -/ abbrev CokernelCofork.ofπ {Z : C} (π : Y ⟶ Z) (w : f ≫ π = 0) : CokernelCofork f := Cofork.ofπ π <| by rw [w, zero_comp] @[simp] theorem CokernelCofork.π_ofπ {X Y P : C} (f : X ⟶ Y) (π : Y ⟶ P) (w : f ≫ π = 0) : Cofork.π (CokernelCofork.ofπ π w) = π := rfl /-- Every cokernel cofork `s` is isomorphic (actually, equal) to `cofork.ofπ (cofork.π s) _`. -/ def isoOfπ (s : Cofork f 0) : s ≅ Cofork.ofπ (Cofork.π s) (Cofork.condition s) := Cocones.ext (Iso.refl _) fun j => by cases j <;> aesop_cat /-- If `π = π'`, then `CokernelCofork.of_π π _` and `CokernelCofork.of_π π' _` are isomorphic. -/ def ofπCongr {P : C} {π π' : Y ⟶ P} {w : f ≫ π = 0} (h : π = π') : CokernelCofork.ofπ π w ≅ CokernelCofork.ofπ π' (by rw [← h, w]) := Cocones.ext (Iso.refl _) fun j => by cases j <;> aesop_cat /-- If `s` is a colimit cokernel cofork, then every `k : Y ⟶ W` satisfying `f ≫ k = 0` induces `l : s.X ⟶ W` such that `cofork.π s ≫ l = k`. -/ def CokernelCofork.IsColimit.desc' {s : CokernelCofork f} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : { l : s.pt ⟶ W // Cofork.π s ≫ l = k } := ⟨hs.desc <| CokernelCofork.ofπ _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a cokernel cofork is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def isColimitAux (t : CokernelCofork f) (desc : ∀ s : CokernelCofork f, t.pt ⟶ s.pt) (fac : ∀ s : CokernelCofork f, t.π ≫ desc s = s.π) (uniq : ∀ (s : CokernelCofork f) (m : t.pt ⟶ s.pt) (_ : t.π ≫ m = s.π), m = desc s) : IsColimit t := { desc fac := fun s j => by cases j · simp · exact fac s uniq := fun s m w => uniq s m (w Limits.WalkingParallelPair.one) } /-- This is a more convenient formulation to show that a `CokernelCofork` constructed using `CokernelCofork.ofπ` is a limit cone. -/ def CokernelCofork.IsColimit.ofπ {Z : C} (g : Y ⟶ Z) (eq : f ≫ g = 0) (desc : ∀ {Z' : C} (g' : Y ⟶ Z') (_ : f ≫ g' = 0), Z ⟶ Z') (fac : ∀ {Z' : C} (g' : Y ⟶ Z') (eq' : f ≫ g' = 0), g ≫ desc g' eq' = g') (uniq : ∀ {Z' : C} (g' : Y ⟶ Z') (eq' : f ≫ g' = 0) (m : Z ⟶ Z') (_ : g ≫ m = g'), m = desc g' eq') : IsColimit (CokernelCofork.ofπ g eq) := isColimitAux _ (fun s => desc s.π s.condition) (fun s => fac s.π s.condition) fun s => uniq s.π s.condition /-- This is a more convenient formulation to show that a `CokernelCofork` of the form `CokernelCofork.ofπ p _` is a colimit cocone when we know that `p` is an epimorphism. -/ def CokernelCofork.IsColimit.ofπ' {X Y Q : C} {f : X ⟶ Y} (p : Y ⟶ Q) (w : f ≫ p = 0) (h : ∀ {A : C} (k : Y ⟶ A) (_ : f ≫ k = 0), { l : Q ⟶ A // p ≫ l = k}) [hp : Epi p] : IsColimit (CokernelCofork.ofπ p w) := ofπ _ _ (fun {A} k hk => (h k hk).1) (fun {A} k hk => (h k hk).2) (fun {A} k hk m hm => by rw [← cancel_epi p, (h k hk).2, hm]) /-- Every cokernel of `f` induces a cokernel of `g ≫ f` if `g` is epi. -/ def isCokernelEpiComp {c : CokernelCofork f} (i : IsColimit c) {W} (g : W ⟶ X) [hg : Epi g] {h : W ⟶ Y} (hh : h = g ≫ f) : IsColimit (CokernelCofork.ofπ c.π (by rw [hh]; simp) : CokernelCofork h) := Cofork.IsColimit.mk' _ fun s => let s' : CokernelCofork f := Cofork.ofπ s.π (by apply hg.left_cancellation rw [← Category.assoc, ← hh, s.condition] simp) let l := CokernelCofork.IsColimit.desc' i s'.π s'.condition ⟨l.1, l.2, fun hm => by apply Cofork.IsColimit.hom_ext i; rw [Cofork.π_ofπ] at hm; rw [hm]; exact l.2.symm⟩ @[simp] theorem isCokernelEpiComp_desc {c : CokernelCofork f} (i : IsColimit c) {W} (g : W ⟶ X) [hg : Epi g] {h : W ⟶ Y} (hh : h = g ≫ f) (s : CokernelCofork h) : (isCokernelEpiComp i g hh).desc s = i.desc (Cofork.ofπ s.π (by rw [← cancel_epi g, ← Category.assoc, ← hh] simp)) := rfl /-- Every cokernel of `g ≫ f` is also a cokernel of `f`, as long as `f ≫ c.π` vanishes. -/ def isCokernelOfComp {W : C} (g : W ⟶ X) (h : W ⟶ Y) {c : CokernelCofork h} (i : IsColimit c) (hf : f ≫ c.π = 0) (hfg : g ≫ f = h) : IsColimit (CokernelCofork.ofπ c.π hf) := Cofork.IsColimit.mk _ (fun s => i.desc (CokernelCofork.ofπ s.π (by simp [← hfg]))) (fun s => by simp only [CokernelCofork.π_ofπ, Cofork.IsColimit.π_desc]) fun s m h => by apply Cofork.IsColimit.hom_ext i simpa using h /-- `Y` identifies to the cokernel of a zero map `X ⟶ Y`. -/ def CokernelCofork.IsColimit.ofId {X Y : C} (f : X ⟶ Y) (hf : f = 0) : IsColimit (CokernelCofork.ofπ (𝟙 Y) (show f ≫ 𝟙 Y = 0 by rw [hf, zero_comp])) := CokernelCofork.IsColimit.ofπ _ _ (fun x _ => x) (fun _ _ => Category.id_comp _) (fun _ _ _ hb => by simp only [← hb, Category.id_comp]) /-- Any zero object identifies to the cokernel of a given epimorphisms. -/ def CokernelCofork.IsColimit.ofEpiOfIsZero {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (hf : Epi f) (h : IsZero c.pt) : IsColimit c := isColimitAux _ (fun s => 0) (fun s => by rw [comp_zero, ← cancel_epi f, comp_zero, s.condition]) (fun _ _ _ => h.eq_of_src _ _) lemma CokernelCofork.IsColimit.isIso_π {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (hc : IsColimit c) (hf : f = 0) : IsIso c.π := by let e : c.pt ≅ Y := IsColimit.coconePointUniqueUpToIso hc (CokernelCofork.IsColimit.ofId (f : X ⟶ Y) hf) have eq : c.π ≫ e.hom = 𝟙 Y := Cofork.IsColimit.π_desc hc haveI : IsIso (c.π ≫ e.hom) := by rw [eq] dsimp infer_instance exact IsIso.of_isIso_comp_right c.π e.hom end namespace CokernelCofork variable {f} {X' Y' : C} {f' : X' ⟶ Y'} /-- The morphism between points of cokernel coforks induced by a morphism in the category of arrows. -/ def mapOfIsColimit {cc : CokernelCofork f} (hf : IsColimit cc) (cc' : CokernelCofork f') (φ : Arrow.mk f ⟶ Arrow.mk f') : cc.pt ⟶ cc'.pt := hf.desc (CokernelCofork.ofπ (φ.right ≫ cc'.π) (by erw [← Arrow.w_assoc φ, condition, comp_zero])) @[reassoc (attr := simp)] lemma π_mapOfIsColimit {cc : CokernelCofork f} (hf : IsColimit cc) (cc' : CokernelCofork f') (φ : Arrow.mk f ⟶ Arrow.mk f') : cc.π ≫ mapOfIsColimit hf cc' φ = φ.right ≫ cc'.π := hf.fac _ _ /-- The isomorphism between points of limit cokernel coforks induced by an isomorphism in the category of arrows. -/ @[simps] def mapIsoOfIsColimit {cc : CokernelCofork f} {cc' : CokernelCofork f'} (hf : IsColimit cc) (hf' : IsColimit cc') (φ : Arrow.mk f ≅ Arrow.mk f') : cc.pt ≅ cc'.pt where hom := mapOfIsColimit hf cc' φ.hom inv := mapOfIsColimit hf' cc φ.inv hom_inv_id := Cofork.IsColimit.hom_ext hf (by simp) inv_hom_id := Cofork.IsColimit.hom_ext hf' (by simp) end CokernelCofork section variable [HasCokernel f] /-- The cokernel of a morphism, expressed as the coequalizer with the 0 morphism. -/ abbrev cokernel : C := coequalizer f 0 /-- The map from the target of `f` to `cokernel f`. -/ abbrev cokernel.π : Y ⟶ cokernel f := coequalizer.π f 0 @[simp] theorem coequalizer_as_cokernel : coequalizer.π f 0 = cokernel.π f := rfl @[reassoc (attr := simp)] theorem cokernel.condition : f ≫ cokernel.π f = 0 := CokernelCofork.condition _ /-- The cokernel built from `cokernel.π f` is colimiting. -/ def cokernelIsCokernel : IsColimit (Cofork.ofπ (cokernel.π f) ((cokernel.condition f).trans zero_comp.symm)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cofork.ext (Iso.refl _)) /-- Given any morphism `k : Y ⟶ W` such that `f ≫ k = 0`, `k` factors through `cokernel.π f` via `cokernel.desc : cokernel f ⟶ W`. -/ abbrev cokernel.desc {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : cokernel f ⟶ W := (cokernelIsCokernel f).desc (CokernelCofork.ofπ k h) @[reassoc (attr := simp)] theorem cokernel.π_desc {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : cokernel.π f ≫ cokernel.desc f k h = k := (cokernelIsCokernel f).fac (CokernelCofork.ofπ k h) WalkingParallelPair.one -- Porting note: added to ease the port of `Abelian.Exact` @[reassoc (attr := simp)] lemma colimit_ι_zero_cokernel_desc {C : Type*} [Category C] [HasZeroMorphisms C] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : f ≫ g = 0) [HasCokernel f] : colimit.ι (parallelPair f 0) WalkingParallelPair.zero ≫ cokernel.desc f g h = 0 := by rw [(colimit.w (parallelPair f 0) WalkingParallelPairHom.left).symm] aesop_cat @[simp] theorem cokernel.desc_zero {W : C} {h} : cokernel.desc f (0 : Y ⟶ W) h = 0 := by ext; simp instance cokernel.desc_epi {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) [Epi k] : Epi (cokernel.desc f k h) := ⟨fun {Z} g g' w => by replace w := cokernel.π f ≫= w simp only [cokernel.π_desc_assoc] at w exact (cancel_epi k).1 w⟩ /-- Any morphism `k : Y ⟶ W` satisfying `f ≫ k = 0` induces `l : cokernel f ⟶ W` such that `cokernel.π f ≫ l = k`. -/ def cokernel.desc' {W : C} (k : Y ⟶ W) (h : f ≫ k = 0) : { l : cokernel f ⟶ W // cokernel.π f ≫ l = k } := ⟨cokernel.desc f k h, cokernel.π_desc _ _ _⟩ /-- A commuting square induces a morphism of cokernels. -/ abbrev cokernel.map {X' Y' : C} (f' : X' ⟶ Y') [HasCokernel f'] (p : X ⟶ X') (q : Y ⟶ Y') (w : f ≫ q = p ≫ f') : cokernel f ⟶ cokernel f' := cokernel.desc f (q ≫ cokernel.π f') (by have : f ≫ q ≫ π f' = p ≫ f' ≫ π f' := by simp only [← Category.assoc] apply congrArg (· ≫ π f') w simp [this]) /-- Given a commutative diagram X --f--> Y --g--> Z | | | | | | v v v X' -f'-> Y' -g'-> Z' with horizontal arrows composing to zero, then we obtain a commutative square cokernel f ---> Z | | | cokernel.map | | | v v cokernel f' --> Z' -/ theorem cokernel.map_desc {X Y Z X' Y' Z' : C} (f : X ⟶ Y) [HasCokernel f] (g : Y ⟶ Z) (w : f ≫ g = 0) (f' : X' ⟶ Y') [HasCokernel f'] (g' : Y' ⟶ Z') (w' : f' ≫ g' = 0) (p : X ⟶ X') (q : Y ⟶ Y') (r : Z ⟶ Z') (h₁ : f ≫ q = p ≫ f') (h₂ : g ≫ r = q ≫ g') : cokernel.map f f' p q h₁ ≫ cokernel.desc f' g' w' = cokernel.desc f g w ≫ r := by ext; simp [h₂] /-- A commuting square of isomorphisms induces an isomorphism of cokernels. -/ @[simps] def cokernel.mapIso {X' Y' : C} (f' : X' ⟶ Y') [HasCokernel f'] (p : X ≅ X') (q : Y ≅ Y') (w : f ≫ q.hom = p.hom ≫ f') : cokernel f ≅ cokernel f' where hom := cokernel.map f f' p.hom q.hom w inv := cokernel.map f' f p.inv q.inv (by refine (cancel_mono q.hom).1 ?_ simp [w]) /-- The cokernel of the zero morphism is an isomorphism -/ instance cokernel.π_zero_isIso : IsIso (cokernel.π (0 : X ⟶ Y)) := coequalizer.π_of_self _ theorem eq_zero_of_mono_cokernel [Mono (cokernel.π f)] : f = 0 := (cancel_mono (cokernel.π f)).1 (by simp) /-- The cokernel of a zero morphism is isomorphic to the target. -/ def cokernelZeroIsoTarget : cokernel (0 : X ⟶ Y) ≅ Y := coequalizer.isoTargetOfSelf 0 @[simp] theorem cokernelZeroIsoTarget_hom : cokernelZeroIsoTarget.hom = cokernel.desc (0 : X ⟶ Y) (𝟙 Y) (by simp) := by ext; simp [cokernelZeroIsoTarget] @[simp] theorem cokernelZeroIsoTarget_inv : cokernelZeroIsoTarget.inv = cokernel.π (0 : X ⟶ Y) := rfl /-- If two morphisms are known to be equal, then their cokernels are isomorphic. -/ def cokernelIsoOfEq {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel f ≅ cokernel g := HasColimit.isoOfNatIso (by simp [h]; rfl) @[simp] theorem cokernelIsoOfEq_refl {h : f = f} : cokernelIsoOfEq h = Iso.refl (cokernel f) := by ext; simp [cokernelIsoOfEq] @[reassoc (attr := simp)] theorem π_comp_cokernelIsoOfEq_hom {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel.π f ≫ (cokernelIsoOfEq h).hom = cokernel.π g := by cases h; simp @[reassoc (attr := simp)] theorem π_comp_cokernelIsoOfEq_inv {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel.π _ ≫ (cokernelIsoOfEq h).inv = cokernel.π _ := by cases h; simp @[reassoc (attr := simp)] theorem cokernelIsoOfEq_hom_comp_desc {Z} {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) (e : Y ⟶ Z) (he) : (cokernelIsoOfEq h).hom ≫ cokernel.desc _ e he = cokernel.desc _ e (by simp [h, he]) := by cases h; simp @[reassoc (attr := simp)] theorem cokernelIsoOfEq_inv_comp_desc {Z} {f g : X ⟶ Y} [HasCokernel f] [HasCokernel g] (h : f = g) (e : Y ⟶ Z) (he) : (cokernelIsoOfEq h).inv ≫ cokernel.desc _ e he = cokernel.desc _ e (by simp [← h, he]) := by cases h; simp @[simp] theorem cokernelIsoOfEq_trans {f g h : X ⟶ Y} [HasCokernel f] [HasCokernel g] [HasCokernel h] (w₁ : f = g) (w₂ : g = h) : cokernelIsoOfEq w₁ ≪≫ cokernelIsoOfEq w₂ = cokernelIsoOfEq (w₁.trans w₂) := by cases w₁; cases w₂; ext; simp [cokernelIsoOfEq] variable {f} theorem cokernel_not_mono_of_nonzero (w : f ≠ 0) : ¬Mono (cokernel.π f) := fun _ => w (eq_zero_of_mono_cokernel f) theorem cokernel_not_iso_of_nonzero (w : f ≠ 0) : IsIso (cokernel.π f) → False := fun _ => cokernel_not_mono_of_nonzero w inferInstance #adaptation_note /-- nightly-2024-04-01 The `symm` wasn't previously necessary. -/ -- TODO the remainder of this section has obvious generalizations to `HasCoequalizer f g`. instance hasCokernel_comp_iso {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasCokernel f] [IsIso g] : HasCokernel (f ≫ g) where exists_colimit := ⟨{ cocone := CokernelCofork.ofπ (inv g ≫ cokernel.π f) (by simp) isColimit := isColimitAux _ (fun s => cokernel.desc _ (g ≫ s.π) (by rw [← Category.assoc, CokernelCofork.condition])) (by aesop_cat) fun s m w => by simp_rw [← w] symm apply coequalizer.hom_ext simp }⟩ /-- When `g` is an isomorphism, the cokernel of `f ≫ g` is isomorphic to the cokernel of `f`. -/ @[simps] def cokernelCompIsIso {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasCokernel f] [IsIso g] : cokernel (f ≫ g) ≅ cokernel f where hom := cokernel.desc _ (inv g ≫ cokernel.π f) (by simp) inv := cokernel.desc _ (g ≫ cokernel.π (f ≫ g)) (by rw [← Category.assoc, cokernel.condition]) instance hasCokernel_epi_comp {X Y : C} (f : X ⟶ Y) [HasCokernel f] {W} (g : W ⟶ X) [Epi g] : HasCokernel (g ≫ f) := ⟨⟨{ cocone := _ isColimit := isCokernelEpiComp (colimit.isColimit _) g rfl }⟩⟩ /-- When `f` is an epimorphism, the cokernel of `f ≫ g` is isomorphic to the cokernel of `g`. -/ @[simps] def cokernelEpiComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [Epi f] [HasCokernel g] : cokernel (f ≫ g) ≅ cokernel g where hom := cokernel.desc _ (cokernel.π g) (by simp) inv := cokernel.desc _ (cokernel.π (f ≫ g)) (by rw [← cancel_epi f, ← Category.assoc] simp) end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The morphism to the zero object determines a cocone on a cokernel diagram -/ def cokernel.zeroCokernelCofork : CokernelCofork f where pt := 0 ι := { app := fun j => 0 } /-- The morphism to the zero object is a cokernel of an epimorphism -/ def cokernel.isColimitCoconeZeroCocone [Epi f] : IsColimit (cokernel.zeroCokernelCofork f) := Cofork.IsColimit.mk _ (fun s => 0) (fun s => by erw [zero_comp] refine (zero_of_epi_comp f ?_).symm exact CokernelCofork.condition _) fun _ _ _ => zero_of_from_zero _ /-- The cokernel of an epimorphism is isomorphic to the zero object -/ def cokernel.ofEpi [HasCokernel f] [Epi f] : cokernel f ≅ 0 := Functor.mapIso (Cocones.forget _) <| IsColimit.uniqueUpToIso (colimit.isColimit (parallelPair f 0)) (cokernel.isColimitCoconeZeroCocone f) /-- The cokernel morphism of an epimorphism is a zero morphism -/ theorem cokernel.π_of_epi [HasCokernel f] [Epi f] : cokernel.π f = 0 := zero_of_target_iso_zero _ (cokernel.ofEpi f) end HasZeroObject section MonoFactorisation variable {f} @[simp] theorem MonoFactorisation.kernel_ι_comp [HasKernel f] (F : MonoFactorisation f) : kernel.ι f ≫ F.e = 0 := by rw [← cancel_mono F.m, zero_comp, Category.assoc, F.fac, kernel.condition] end MonoFactorisation section HasImage /-- The cokernel of the image inclusion of a morphism `f` is isomorphic to the cokernel of `f`. (This result requires that the factorisation through the image is an epimorphism. This holds in any category with equalizers.) -/ @[simps] def cokernelImageι {X Y : C} (f : X ⟶ Y) [HasImage f] [HasCokernel (image.ι f)] [HasCokernel f] [Epi (factorThruImage f)] : cokernel (image.ι f) ≅ cokernel f where hom := cokernel.desc _ (cokernel.π f) (by have w := cokernel.condition f conv at w => lhs congr rw [← image.fac f] rw [← HasZeroMorphisms.comp_zero (Limits.factorThruImage f), Category.assoc, cancel_epi] at w exact w) inv := cokernel.desc _ (cokernel.π _) (by conv => lhs congr rw [← image.fac f] rw [Category.assoc, cokernel.condition, HasZeroMorphisms.comp_zero]) end HasImage section variable (X Y) /-- The cokernel of a zero morphism is an isomorphism -/ theorem cokernel.π_of_zero : IsIso (cokernel.π (0 : X ⟶ Y)) := coequalizer.π_of_self _ end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The kernel of the cokernel of an epimorphism is an isomorphism -/ instance kernel.of_cokernel_of_epi [HasCokernel f] [HasKernel (cokernel.π f)] [Epi f] : IsIso (kernel.ι (cokernel.π f)) := equalizer.ι_of_eq <| cokernel.π_of_epi f /-- The cokernel of the kernel of a monomorphism is an isomorphism -/ instance cokernel.of_kernel_of_mono [HasKernel f] [HasCokernel (kernel.ι f)] [Mono f] : IsIso (cokernel.π (kernel.ι f)) := coequalizer.π_of_eq <| kernel.ι_of_mono f /-- If `f ≫ g = 0` implies `g = 0` for all `g`, then `0 : Y ⟶ 0` is a cokernel of `f`. -/ def zeroCokernelOfZeroCancel {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Y ⟶ Z) (_ : f ≫ g = 0), g = 0) : IsColimit (CokernelCofork.ofπ (0 : Y ⟶ 0) (show f ≫ 0 = 0 by simp)) := Cofork.IsColimit.mk _ (fun s => 0) (fun s => by rw [hf _ _ (CokernelCofork.condition s), comp_zero]) fun s m _ => by apply HasZeroObject.from_zero_ext end HasZeroObject section Transport /-- If `i` is an isomorphism such that `i.hom ≫ l = f`, then any cokernel of `f` is a cokernel of `l`. -/ def IsCokernel.ofIsoComp {Z : C} (l : Z ⟶ Y) (i : X ≅ Z) (h : i.hom ≫ l = f) {s : CokernelCofork f} (hs : IsColimit s) : IsColimit (CokernelCofork.ofπ (Cofork.π s) <| show l ≫ Cofork.π s = 0 by simp [i.eq_inv_comp.2 h]) := Cofork.IsColimit.mk _ (fun s => hs.desc <| CokernelCofork.ofπ (Cofork.π s) <| by simp [← h]) (fun s => by simp) fun s m h => by apply Cofork.IsColimit.hom_ext hs simpa using h /-- If `i` is an isomorphism such that `i.hom ≫ l = f`, then the cokernel of `f` is a cokernel of `l`. -/ def cokernel.ofIsoComp [HasCokernel f] {Z : C} (l : Z ⟶ Y) (i : X ≅ Z) (h : i.hom ≫ l = f) : IsColimit (CokernelCofork.ofπ (cokernel.π f) <| show l ≫ cokernel.π f = 0 by simp [i.eq_inv_comp.2 h]) := IsCokernel.ofIsoComp f l i h <| colimit.isColimit _ /-- If `s` is any colimit cokernel cocone over `f` and `i` is an isomorphism such that `s.π ≫ i.hom = l`, then `l` is a cokernel of `f`. -/ def IsCokernel.cokernelIso {Z : C} (l : Y ⟶ Z) {s : CokernelCofork f} (hs : IsColimit s) (i : s.pt ≅ Z) (h : Cofork.π s ≫ i.hom = l) : IsColimit (CokernelCofork.ofπ l <| show f ≫ l = 0 by simp [← h]) := IsColimit.ofIsoColimit hs <| Cocones.ext i fun j => by cases j · dsimp; rw [← h]; simp · exact h /-- If `i` is an isomorphism such that `cokernel.π f ≫ i.hom = l`, then `l` is a cokernel of `f`. -/ def cokernel.cokernelIso [HasCokernel f] {Z : C} (l : Y ⟶ Z) (i : cokernel f ≅ Z) (h : cokernel.π f ≫ i.hom = l) : IsColimit (@CokernelCofork.ofπ _ _ _ _ _ f _ l <| by simp [← h]) := IsCokernel.cokernelIso f l (colimit.isColimit _) i h end Transport section Comparison variable {D : Type u₂} [Category.{v₂} D] [HasZeroMorphisms D] variable (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] /-- The comparison morphism for the kernel of `f`. This is an isomorphism iff `G` preserves the kernel of `f`; see `CategoryTheory/Limits/Preserves/Shapes/Kernels.lean` -/ def kernelComparison [HasKernel f] [HasKernel (G.map f)] : G.obj (kernel f) ⟶ kernel (G.map f) := kernel.lift _ (G.map (kernel.ι f)) (by simp only [← G.map_comp, kernel.condition, Functor.map_zero]) @[reassoc (attr := simp)] theorem kernelComparison_comp_ι [HasKernel f] [HasKernel (G.map f)] : kernelComparison f G ≫ kernel.ι (G.map f) = G.map (kernel.ι f) := kernel.lift_ι _ _ _ @[reassoc (attr := simp)] theorem map_lift_kernelComparison [HasKernel f] [HasKernel (G.map f)] {Z : C} {h : Z ⟶ X} (w : h ≫ f = 0) : G.map (kernel.lift _ h w) ≫ kernelComparison f G = kernel.lift _ (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) := by ext; simp [← G.map_comp] @[reassoc] theorem kernelComparison_comp_kernel_map {X' Y' : C} [HasKernel f] [HasKernel (G.map f)] (g : X' ⟶ Y') [HasKernel g] [HasKernel (G.map g)] (p : X ⟶ X') (q : Y ⟶ Y') (hpq : f ≫ q = p ≫ g) : kernelComparison f G ≫ kernel.map (G.map f) (G.map g) (G.map p) (G.map q) (by rw [← G.map_comp, hpq, G.map_comp]) = G.map (kernel.map f g p q hpq) ≫ kernelComparison g G := kernel.lift_map _ _ (by rw [← G.map_comp, kernel.condition, G.map_zero]) _ _ (by rw [← G.map_comp, kernel.condition, G.map_zero]) _ _ _ (by simp only [← G.map_comp]; exact G.congr_map (kernel.lift_ι _ _ _).symm) _ /-- The comparison morphism for the cokernel of `f`. -/ def cokernelComparison [HasCokernel f] [HasCokernel (G.map f)] : cokernel (G.map f) ⟶ G.obj (cokernel f) := cokernel.desc _ (G.map (coequalizer.π _ _)) (by simp only [← G.map_comp, cokernel.condition, Functor.map_zero]) @[reassoc (attr := simp)] theorem π_comp_cokernelComparison [HasCokernel f] [HasCokernel (G.map f)] : cokernel.π (G.map f) ≫ cokernelComparison f G = G.map (cokernel.π _) := cokernel.π_desc _ _ _ @[reassoc (attr := simp)] theorem cokernelComparison_map_desc [HasCokernel f] [HasCokernel (G.map f)] {Z : C} {h : Y ⟶ Z} (w : f ≫ h = 0) : cokernelComparison f G ≫ G.map (cokernel.desc _ h w) = cokernel.desc _ (G.map h) (by simp only [← G.map_comp, w, Functor.map_zero]) := by ext; simp [← G.map_comp] @[reassoc] theorem cokernel_map_comp_cokernelComparison {X' Y' : C} [HasCokernel f] [HasCokernel (G.map f)] (g : X' ⟶ Y') [HasCokernel g] [HasCokernel (G.map g)] (p : X ⟶ X') (q : Y ⟶ Y') (hpq : f ≫ q = p ≫ g) : cokernel.map (G.map f) (G.map g) (G.map p) (G.map q) (by rw [← G.map_comp, hpq, G.map_comp]) ≫ cokernelComparison _ G = cokernelComparison _ G ≫ G.map (cokernel.map f g p q hpq) := cokernel.map_desc _ _ (by rw [← G.map_comp, cokernel.condition, G.map_zero]) _ _ (by rw [← G.map_comp, cokernel.condition, G.map_zero]) _ _ _ _ (by simp only [← G.map_comp]; exact G.congr_map (cokernel.π_desc _ _ _)) end Comparison end CategoryTheory.Limits namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] variable [HasZeroMorphisms C] /-- `HasKernels` represents the existence of kernels for every morphism. -/ class HasKernels : Prop where has_limit : ∀ {X Y : C} (f : X ⟶ Y), HasKernel f := by infer_instance /-- `HasCokernels` represents the existence of cokernels for every morphism. -/ class HasCokernels : Prop where has_colimit : ∀ {X Y : C} (f : X ⟶ Y), HasCokernel f := by infer_instance attribute [instance 100] HasKernels.has_limit HasCokernels.has_colimit instance (priority := 100) hasKernels_of_hasEqualizers [HasEqualizers C] : HasKernels C where instance (priority := 100) hasCokernels_of_hasCoequalizers [HasCoequalizers C] : HasCokernels C where end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Multiequalizer.lean
/- Copyright (c) 2021 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.ConeCategory /-! # Multi-(co)equalizers A *multiequalizer* is an equalizer of two morphisms between two products. Since both products and equalizers are limits, such an object is again a limit. This file provides the diagram whose limit is indeed such an object. In fact, it is well-known that any limit can be obtained as a multiequalizer. The dual construction (multicoequalizers) is also provided. ## Projects Prove that a multiequalizer can be identified with an equalizer between products (and analogously for multicoequalizers). Prove that the limit of any diagram is a multiequalizer (and similarly for colimits). -/ namespace CategoryTheory.Limits open CategoryTheory universe w v u /-- The type underlying the multiequalizer diagram. -/ --@[nolint unused_arguments] inductive WalkingMulticospan {L R : Type w} (fst snd : R → L) : Type w | left : L → WalkingMulticospan fst snd | right : R → WalkingMulticospan fst snd /-- The type underlying the multiecoqualizer diagram. -/ --@[nolint unused_arguments] inductive WalkingMultispan {L R : Type w} (fst snd : L → R) : Type w | left : L → WalkingMultispan fst snd | right : R → WalkingMultispan fst snd namespace WalkingMulticospan variable {L R : Type w} {fst snd : R → L} instance [Inhabited L] : Inhabited (WalkingMulticospan fst snd) := ⟨left default⟩ /-- Morphisms for `WalkingMulticospan`. -/ inductive Hom : ∀ _ _ : WalkingMulticospan fst snd, Type w | id (A) : Hom A A | fst (b) : Hom (left (fst b)) (right b) | snd (b) : Hom (left (snd b)) (right b) /- Porting note: simpNF says the LHS of this internal identifier simplifies (which it does, using Hom.id_eq_id) -/ attribute [-simp, nolint simpNF] WalkingMulticospan.Hom.id.sizeOf_spec instance {a : WalkingMulticospan fst snd} : Inhabited (Hom a a) := ⟨Hom.id _⟩ /-- Composition of morphisms for `WalkingMulticospan`. -/ def Hom.comp : ∀ {A B C : WalkingMulticospan fst snd} (_ : Hom A B) (_ : Hom B C), Hom A C | _, _, _, Hom.id X, f => f | _, _, _, Hom.fst b, Hom.id _ => Hom.fst b | _, _, _, Hom.snd b, Hom.id _ => Hom.snd b instance : SmallCategory (WalkingMulticospan fst snd) where Hom := Hom id := Hom.id comp := Hom.comp id_comp := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl comp_id := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl assoc := by rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl @[simp] lemma Hom.id_eq_id (X : WalkingMulticospan fst snd) : Hom.id X = 𝟙 X := rfl @[simp] lemma Hom.comp_eq_comp {X Y Z : WalkingMulticospan fst snd} (f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl end WalkingMulticospan namespace WalkingMultispan variable {L R : Type v} {fst snd : L → R} instance [Inhabited L] : Inhabited (WalkingMultispan fst snd) := ⟨left default⟩ /-- Morphisms for `WalkingMultispan`. -/ inductive Hom : ∀ _ _ : WalkingMultispan fst snd, Type v | id (A) : Hom A A | fst (a) : Hom (left a) (right (fst a)) | snd (a) : Hom (left a) (right (snd a)) /- Porting note: simpNF says the LHS of this internal identifier simplifies (which it does, using Hom.id_eq_id) -/ attribute [-simp, nolint simpNF] WalkingMultispan.Hom.id.sizeOf_spec instance {a : WalkingMultispan fst snd} : Inhabited (Hom a a) := ⟨Hom.id _⟩ /-- Composition of morphisms for `WalkingMultispan`. -/ def Hom.comp : ∀ {A B C : WalkingMultispan fst snd} (_ : Hom A B) (_ : Hom B C), Hom A C | _, _, _, Hom.id X, f => f | _, _, _, Hom.fst a, Hom.id _ => Hom.fst a | _, _, _, Hom.snd a, Hom.id _ => Hom.snd a instance : SmallCategory (WalkingMultispan fst snd) where Hom := Hom id := Hom.id comp := Hom.comp id_comp := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl comp_id := by rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl assoc := by rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl @[simp] lemma Hom.id_eq_id (X : WalkingMultispan fst snd) : Hom.id X = 𝟙 X := rfl @[simp] lemma Hom.comp_eq_comp {X Y Z : WalkingMultispan fst snd} (f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl end WalkingMultispan /-- This is a structure encapsulating the data necessary to define a `Multicospan`. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] structure MulticospanIndex (C : Type u) [Category.{v} C] where (L R : Type w) (fstTo sndTo : R → L) left : L → C right : R → C fst : ∀ b, left (fstTo b) ⟶ right b snd : ∀ b, left (sndTo b) ⟶ right b /-- This is a structure encapsulating the data necessary to define a `Multispan`. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] structure MultispanIndex (C : Type u) [Category.{v} C] where (L R : Type w) (fstFrom sndFrom : L → R) left : L → C right : R → C fst : ∀ a, left a ⟶ right (fstFrom a) snd : ∀ a, left a ⟶ right (sndFrom a) namespace MulticospanIndex variable {C : Type u} [Category.{v} C] (I : MulticospanIndex.{w} C) /-- The multicospan associated to `I : MulticospanIndex`. -/ @[simps] def multicospan : WalkingMulticospan I.fstTo I.sndTo ⥤ C where obj x := match x with | WalkingMulticospan.left a => I.left a | WalkingMulticospan.right b => I.right b map {x y} f := match x, y, f with | _, _, WalkingMulticospan.Hom.id x => 𝟙 _ | _, _, WalkingMulticospan.Hom.fst b => I.fst _ | _, _, WalkingMulticospan.Hom.snd b => I.snd _ map_id := by rintro (_ | _) <;> rfl map_comp := by rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> aesop_cat variable [HasProduct I.left] [HasProduct I.right] /-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.fst`. -/ noncomputable def fstPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right := Pi.lift fun b => Pi.π I.left (I.fstTo b) ≫ I.fst b /-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.snd`. -/ noncomputable def sndPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right := Pi.lift fun b => Pi.π I.left (I.sndTo b) ≫ I.snd b @[reassoc (attr := simp)] theorem fstPiMap_π (b) : I.fstPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.fst b := by simp [fstPiMap] @[reassoc (attr := simp)] theorem sndPiMap_π (b) : I.sndPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.snd b := by simp [sndPiMap] /-- Taking the multiequalizer over the multicospan index is equivalent to taking the equalizer over the two morphisms `∏ᶜ I.left ⇉ ∏ᶜ I.right`. This is the diagram of the latter. -/ @[simps!] protected noncomputable def parallelPairDiagram := parallelPair I.fstPiMap I.sndPiMap end MulticospanIndex namespace MultispanIndex variable {C : Type u} [Category.{v} C] (I : MultispanIndex.{w} C) /-- The multispan associated to `I : MultispanIndex`. -/ def multispan : WalkingMultispan I.fstFrom I.sndFrom ⥤ C where obj x := match x with | WalkingMultispan.left a => I.left a | WalkingMultispan.right b => I.right b map {x y} f := match x, y, f with | _, _, WalkingMultispan.Hom.id x => 𝟙 _ | _, _, WalkingMultispan.Hom.fst b => I.fst _ | _, _, WalkingMultispan.Hom.snd b => I.snd _ map_id := by rintro (_ | _) <;> rfl map_comp := by rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> aesop_cat @[simp] theorem multispan_obj_left (a) : I.multispan.obj (WalkingMultispan.left a) = I.left a := rfl @[simp] theorem multispan_obj_right (b) : I.multispan.obj (WalkingMultispan.right b) = I.right b := rfl @[simp] theorem multispan_map_fst (a) : I.multispan.map (WalkingMultispan.Hom.fst a) = I.fst a := rfl @[simp] theorem multispan_map_snd (a) : I.multispan.map (WalkingMultispan.Hom.snd a) = I.snd a := rfl variable [HasCoproduct I.left] [HasCoproduct I.right] /-- The induced map `∐ I.left ⟶ ∐ I.right` via `I.fst`. -/ noncomputable def fstSigmaMap : ∐ I.left ⟶ ∐ I.right := Sigma.desc fun b => I.fst b ≫ Sigma.ι _ (I.fstFrom b) /-- The induced map `∐ I.left ⟶ ∐ I.right` via `I.snd`. -/ noncomputable def sndSigmaMap : ∐ I.left ⟶ ∐ I.right := Sigma.desc fun b => I.snd b ≫ Sigma.ι _ (I.sndFrom b) @[reassoc (attr := simp)] theorem ι_fstSigmaMap (b) : Sigma.ι I.left b ≫ I.fstSigmaMap = I.fst b ≫ Sigma.ι I.right _ := by simp [fstSigmaMap] @[reassoc (attr := simp)] theorem ι_sndSigmaMap (b) : Sigma.ι I.left b ≫ I.sndSigmaMap = I.snd b ≫ Sigma.ι I.right _ := by simp [sndSigmaMap] /-- Taking the multicoequalizer over the multispan index is equivalent to taking the coequalizer over the two morphsims `∐ I.left ⇉ ∐ I.right`. This is the diagram of the latter. -/ protected noncomputable abbrev parallelPairDiagram := parallelPair I.fstSigmaMap I.sndSigmaMap end MultispanIndex variable {C : Type u} [Category.{v} C] /-- A multifork is a cone over a multicospan. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] abbrev Multifork (I : MulticospanIndex.{w} C) := Cone I.multicospan /-- A multicofork is a cocone over a multispan. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] abbrev Multicofork (I : MultispanIndex.{w} C) := Cocone I.multispan namespace Multifork variable {I : MulticospanIndex.{w} C} (K : Multifork I) /-- The maps from the cone point of a multifork to the objects on the left. -/ def ι (a : I.L) : K.pt ⟶ I.left a := K.π.app (WalkingMulticospan.left _) @[simp] theorem app_left_eq_ι (a) : K.π.app (WalkingMulticospan.left a) = K.ι a := rfl @[simp] theorem app_right_eq_ι_comp_fst (b) : K.π.app (WalkingMulticospan.right b) = K.ι (I.fstTo b) ≫ I.fst b := by rw [← K.w (WalkingMulticospan.Hom.fst b)] rfl @[reassoc] theorem app_right_eq_ι_comp_snd (b) : K.π.app (WalkingMulticospan.right b) = K.ι (I.sndTo b) ≫ I.snd b := by rw [← K.w (WalkingMulticospan.Hom.snd b)] rfl @[reassoc (attr := simp)] theorem hom_comp_ι (K₁ K₂ : Multifork I) (f : K₁ ⟶ K₂) (j : I.L) : f.hom ≫ K₂.ι j = K₁.ι j := f.w _ /-- Construct a multifork using a collection `ι` of morphisms. -/ @[simps] def ofι (I : MulticospanIndex.{w} C) (P : C) (ι : ∀ a, P ⟶ I.left a) (w : ∀ b, ι (I.fstTo b) ≫ I.fst b = ι (I.sndTo b) ≫ I.snd b) : Multifork I where pt := P π := { app := fun x => match x with | WalkingMulticospan.left a => ι _ | WalkingMulticospan.right b => ι (I.fstTo b) ≫ I.fst b naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp apply w } @[reassoc (attr := simp)] theorem condition (b) : K.ι (I.fstTo b) ≫ I.fst b = K.ι (I.sndTo b) ≫ I.snd b := by rw [← app_right_eq_ι_comp_fst, ← app_right_eq_ι_comp_snd] /-- This definition provides a convenient way to show that a multifork is a limit. -/ @[simps] def IsLimit.mk (lift : ∀ E : Multifork I, E.pt ⟶ K.pt) (fac : ∀ (E : Multifork I) (i : I.L), lift E ≫ K.ι i = E.ι i) (uniq : ∀ (E : Multifork I) (m : E.pt ⟶ K.pt), (∀ i : I.L, m ≫ K.ι i = E.ι i) → m = lift E) : IsLimit K := { lift fac := by rintro E (a | b) · apply fac · rw [← E.w (WalkingMulticospan.Hom.fst b), ← K.w (WalkingMulticospan.Hom.fst b), ← Category.assoc] congr 1 apply fac uniq := by rintro E m hm apply uniq intro i apply hm } variable {K} lemma IsLimit.hom_ext (hK : IsLimit K) {T : C} {f g : T ⟶ K.pt} (h : ∀ a, f ≫ K.ι a = g ≫ K.ι a) : f = g := by apply hK.hom_ext rintro (_|b) · apply h · dsimp rw [app_right_eq_ι_comp_fst, reassoc_of% h] /-- Constructor for morphisms to the point of a limit multifork. -/ def IsLimit.lift (hK : IsLimit K) {T : C} (k : ∀ a, T ⟶ I.left a) (hk : ∀ b, k (I.fstTo b) ≫ I.fst b = k (I.sndTo b) ≫ I.snd b) : T ⟶ K.pt := hK.lift (Multifork.ofι _ _ k hk) @[reassoc (attr := simp)] lemma IsLimit.fac (hK : IsLimit K) {T : C} (k : ∀ a, T ⟶ I.left a) (hk : ∀ b, k (I.fstTo b) ≫ I.fst b = k (I.sndTo b) ≫ I.snd b) (a : I.L) : IsLimit.lift hK k hk ≫ K.ι a = k a := hK.fac _ _ variable (K) variable [HasProduct I.left] [HasProduct I.right] @[reassoc (attr := simp)] theorem pi_condition : Pi.lift K.ι ≫ I.fstPiMap = Pi.lift K.ι ≫ I.sndPiMap := by ext simp /-- Given a multifork, we may obtain a fork over `∏ᶜ I.left ⇉ ∏ᶜ I.right`. -/ @[simps pt] noncomputable def toPiFork (K : Multifork I) : Fork I.fstPiMap I.sndPiMap where pt := K.pt π := { app := fun x => match x with | WalkingParallelPair.zero => Pi.lift K.ι | WalkingParallelPair.one => Pi.lift K.ι ≫ I.fstPiMap naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp only [Category.id_comp, Functor.map_id, parallelPair_obj_zero, Category.comp_id, pi_condition, parallelPair_obj_one] } @[simp] theorem toPiFork_π_app_zero : K.toPiFork.ι = Pi.lift K.ι := rfl @[simp] theorem toPiFork_π_app_one : K.toPiFork.π.app WalkingParallelPair.one = Pi.lift K.ι ≫ I.fstPiMap := rfl variable (I) /-- Given a fork over `∏ᶜ I.left ⇉ ∏ᶜ I.right`, we may obtain a multifork. -/ @[simps pt] noncomputable def ofPiFork (c : Fork I.fstPiMap I.sndPiMap) : Multifork I where pt := c.pt π := { app := fun x => match x with | WalkingMulticospan.left a => c.ι ≫ Pi.π _ _ | WalkingMulticospan.right b => c.ι ≫ I.fstPiMap ≫ Pi.π _ _ naturality := by rintro (_ | _) (_ | _) (_ | _ | _) · simp · simp · dsimp; rw [c.condition_assoc]; simp · simp } @[simp] theorem ofPiFork_π_app_left (c : Fork I.fstPiMap I.sndPiMap) (a) : (ofPiFork I c).ι a = c.ι ≫ Pi.π _ _ := rfl @[simp] theorem ofPiFork_π_app_right (c : Fork I.fstPiMap I.sndPiMap) (a) : (ofPiFork I c).π.app (WalkingMulticospan.right a) = c.ι ≫ I.fstPiMap ≫ Pi.π _ _ := rfl end Multifork namespace MulticospanIndex variable (I : MulticospanIndex.{w} C) [HasProduct I.left] [HasProduct I.right] --attribute [local tidy] tactic.case_bash /-- `Multifork.toPiFork` as a functor. -/ @[simps] noncomputable def toPiForkFunctor : Multifork I ⥤ Fork I.fstPiMap I.sndPiMap where obj := Multifork.toPiFork map {K₁ K₂} f := { hom := f.hom w := by rintro (_ | _) · apply limit.hom_ext simp · apply limit.hom_ext intros j simp only [Multifork.toPiFork_π_app_one, Multifork.pi_condition, Category.assoc] dsimp [sndPiMap] simp } /-- `Multifork.ofPiFork` as a functor. -/ @[simps] noncomputable def ofPiForkFunctor : Fork I.fstPiMap I.sndPiMap ⥤ Multifork I where obj := Multifork.ofPiFork I map {K₁ K₂} f := { hom := f.hom w := by rintro (_ | _) <;> simp } /-- The category of multiforks is equivalent to the category of forks over `∏ᶜ I.left ⇉ ∏ᶜ I.right`. It then follows from `CategoryTheory.IsLimit.ofPreservesConeTerminal` (or `reflects`) that it preserves and reflects limit cones. -/ @[simps] noncomputable def multiforkEquivPiFork : Multifork I ≌ Fork I.fstPiMap I.sndPiMap where functor := toPiForkFunctor I inverse := ofPiForkFunctor I unitIso := NatIso.ofComponents fun K => Cones.ext (Iso.refl _) (by rintro (_ | _) <;> simp [← Fork.app_one_eq_ι_comp_left]) counitIso := NatIso.ofComponents fun K => Fork.ext (Iso.refl _) end MulticospanIndex namespace Multicofork variable {I : MultispanIndex.{w} C} (K : Multicofork I) /-- The maps to the cocone point of a multicofork from the objects on the right. -/ def π (b : I.R) : I.right b ⟶ K.pt := K.ι.app (WalkingMultispan.right _) @[simp] theorem π_eq_app_right (b) : K.ι.app (WalkingMultispan.right _) = K.π b := rfl @[simp] theorem fst_app_right (a) : K.ι.app (WalkingMultispan.left a) = I.fst a ≫ K.π _ := by rw [← K.w (WalkingMultispan.Hom.fst a)] rfl @[reassoc] theorem snd_app_right (a) : K.ι.app (WalkingMultispan.left a) = I.snd a ≫ K.π _ := by rw [← K.w (WalkingMultispan.Hom.snd a)] rfl @[reassoc (attr := simp)] lemma π_comp_hom (K₁ K₂ : Multicofork I) (f : K₁ ⟶ K₂) (b : I.R) : K₁.π b ≫ f.hom = K₂.π b := f.w _ /-- Construct a multicofork using a collection `π` of morphisms. -/ @[simps] def ofπ (I : MultispanIndex.{w} C) (P : C) (π : ∀ b, I.right b ⟶ P) (w : ∀ a, I.fst a ≫ π (I.fstFrom a) = I.snd a ≫ π (I.sndFrom a)) : Multicofork I where pt := P ι := { app := fun x => match x with | WalkingMultispan.left a => I.fst a ≫ π _ | WalkingMultispan.right b => π _ naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp only [Functor.map_id, MultispanIndex.multispan_obj_left, Category.id_comp, Category.comp_id, MultispanIndex.multispan_obj_right] symm apply w } @[reassoc (attr := simp)] theorem condition (a) : I.fst a ≫ K.π (I.fstFrom a) = I.snd a ≫ K.π (I.sndFrom a) := by rw [← K.snd_app_right, ← K.fst_app_right] /-- This definition provides a convenient way to show that a multicofork is a colimit. -/ @[simps] def IsColimit.mk (desc : ∀ E : Multicofork I, K.pt ⟶ E.pt) (fac : ∀ (E : Multicofork I) (i : I.R), K.π i ≫ desc E = E.π i) (uniq : ∀ (E : Multicofork I) (m : K.pt ⟶ E.pt), (∀ i : I.R, K.π i ≫ m = E.π i) → m = desc E) : IsColimit K := { desc fac := by rintro S (a | b) · rw [← K.w (WalkingMultispan.Hom.fst a), ← S.w (WalkingMultispan.Hom.fst a), Category.assoc] congr 1 apply fac · apply fac uniq := by intro S m hm apply uniq intro i apply hm } variable [HasCoproduct I.left] [HasCoproduct I.right] @[reassoc (attr := simp)] theorem sigma_condition : I.fstSigmaMap ≫ Sigma.desc K.π = I.sndSigmaMap ≫ Sigma.desc K.π := by ext simp /-- Given a multicofork, we may obtain a cofork over `∐ I.left ⇉ ∐ I.right`. -/ @[simps pt] noncomputable def toSigmaCofork (K : Multicofork I) : Cofork I.fstSigmaMap I.sndSigmaMap where pt := K.pt ι := { app := fun x => match x with | WalkingParallelPair.zero => I.fstSigmaMap ≫ Sigma.desc K.π | WalkingParallelPair.one => Sigma.desc K.π naturality := by rintro (_ | _) (_ | _) (_ | _ | _) <;> dsimp <;> simp only [Functor.map_id, parallelPair_obj_zero, parallelPair_obj_one, sigma_condition, Category.id_comp, Category.comp_id] } @[simp] theorem toSigmaCofork_π : K.toSigmaCofork.π = Sigma.desc K.π := rfl variable (I) /-- Given a cofork over `∐ I.left ⇉ ∐ I.right`, we may obtain a multicofork. -/ @[simps pt] noncomputable def ofSigmaCofork (c : Cofork I.fstSigmaMap I.sndSigmaMap) : Multicofork I where pt := c.pt ι := { app := fun x => match x with | WalkingMultispan.left a => (Sigma.ι I.left a : _) ≫ I.fstSigmaMap ≫ c.π | WalkingMultispan.right b => (Sigma.ι I.right b : _) ≫ c.π naturality := by rintro (_ | _) (_ | _) (_ | _ | _) · simp · simp · simp [c.condition] · simp } -- Porting note (#10675): dsimp cannot prove this... once ofSigmaCofork_ι_app_right' is defined @[simp] theorem ofSigmaCofork_ι_app_left (c : Cofork I.fstSigmaMap I.sndSigmaMap) (a) : (ofSigmaCofork I c).ι.app (WalkingMultispan.left a) = (Sigma.ι I.left a : _) ≫ I.fstSigmaMap ≫ c.π := rfl -- @[simp] -- Porting note: LHS simplifies to obtain the normal form below theorem ofSigmaCofork_ι_app_right (c : Cofork I.fstSigmaMap I.sndSigmaMap) (b) : (ofSigmaCofork I c).ι.app (WalkingMultispan.right b) = (Sigma.ι I.right b : _) ≫ c.π := rfl @[simp] theorem ofSigmaCofork_ι_app_right' (c : Cofork I.fstSigmaMap I.sndSigmaMap) (b) : π (ofSigmaCofork I c) b = (Sigma.ι I.right b : _) ≫ c.π := rfl end Multicofork namespace MultispanIndex variable (I : MultispanIndex.{w} C) [HasCoproduct I.left] [HasCoproduct I.right] --attribute [local tidy] tactic.case_bash /-- `Multicofork.toSigmaCofork` as a functor. -/ @[simps] noncomputable def toSigmaCoforkFunctor : Multicofork I ⥤ Cofork I.fstSigmaMap I.sndSigmaMap where obj := Multicofork.toSigmaCofork map {K₁ K₂} f := { hom := f.hom w := by rintro (_|_) all_goals { apply colimit.hom_ext rintro ⟨j⟩ simp } } /-- `Multicofork.ofSigmaCofork` as a functor. -/ @[simps] noncomputable def ofSigmaCoforkFunctor : Cofork I.fstSigmaMap I.sndSigmaMap ⥤ Multicofork I where obj := Multicofork.ofSigmaCofork I map {K₁ K₂} f := { hom := f.hom w := by --sorry --by rintro (_ | _) <;> simp rintro (_ | _) -- porting note; in mathlib3, `simp` worked. What seems to be happening is that -- the `simp` set is not confluent, and mathlib3 found -- `Multicofork.ofSigmaCofork_ι_app_left` before `Multicofork.fst_app_right`, -- but mathlib4 finds `Multicofork.fst_app_right` first. { simp [-Multicofork.fst_app_right] } -- Porting note: similarly here, the `simp` set seems to be non-confluent { simp [-Multicofork.ofSigmaCofork_pt] } } /-- The category of multicoforks is equivalent to the category of coforks over `∐ I.left ⇉ ∐ I.right`. It then follows from `CategoryTheory.IsColimit.ofPreservesCoconeInitial` (or `reflects`) that it preserves and reflects colimit cocones. -/ @[simps] noncomputable def multicoforkEquivSigmaCofork : Multicofork I ≌ Cofork I.fstSigmaMap I.sndSigmaMap where functor := toSigmaCoforkFunctor I inverse := ofSigmaCoforkFunctor I unitIso := NatIso.ofComponents fun K => Cocones.ext (Iso.refl _) (by rintro (_ | _) <;> simp) counitIso := NatIso.ofComponents fun K => Cofork.ext (Iso.refl _) (by -- Porting note: in mathlib3 this was just `ext` and I don't know why it's not here apply Limits.colimit.hom_ext rintro ⟨j⟩ dsimp simp only [Category.comp_id, colimit.ι_desc, Cofan.mk_ι_app] rfl) end MultispanIndex /-- For `I : MulticospanIndex C`, we say that it has a multiequalizer if the associated multicospan has a limit. -/ abbrev HasMultiequalizer (I : MulticospanIndex.{w} C) := HasLimit I.multicospan noncomputable section /-- The multiequalizer of `I : MulticospanIndex C`. -/ abbrev multiequalizer (I : MulticospanIndex.{w} C) [HasMultiequalizer I] : C := limit I.multicospan /-- For `I : MultispanIndex C`, we say that it has a multicoequalizer if the associated multicospan has a limit. -/ abbrev HasMulticoequalizer (I : MultispanIndex.{w} C) := HasColimit I.multispan /-- The multiecoqualizer of `I : MultispanIndex C`. -/ abbrev multicoequalizer (I : MultispanIndex.{w} C) [HasMulticoequalizer I] : C := colimit I.multispan namespace Multiequalizer variable (I : MulticospanIndex.{w} C) [HasMultiequalizer I] /-- The canonical map from the multiequalizer to the objects on the left. -/ abbrev ι (a : I.L) : multiequalizer I ⟶ I.left a := limit.π _ (WalkingMulticospan.left a) /-- The multifork associated to the multiequalizer. -/ abbrev multifork : Multifork I := limit.cone _ @[simp] theorem multifork_ι (a) : (Multiequalizer.multifork I).ι a = Multiequalizer.ι I a := rfl @[simp] theorem multifork_π_app_left (a) : (Multiequalizer.multifork I).π.app (WalkingMulticospan.left a) = Multiequalizer.ι I a := rfl @[reassoc] theorem condition (b) : Multiequalizer.ι I (I.fstTo b) ≫ I.fst b = Multiequalizer.ι I (I.sndTo b) ≫ I.snd b := Multifork.condition _ _ /-- Construct a morphism to the multiequalizer from its universal property. -/ abbrev lift (W : C) (k : ∀ a, W ⟶ I.left a) (h : ∀ b, k (I.fstTo b) ≫ I.fst b = k (I.sndTo b) ≫ I.snd b) : W ⟶ multiequalizer I := limit.lift _ (Multifork.ofι I _ k h) @[reassoc] -- Porting note (#10618): simp can prove this, removed attribute theorem lift_ι (W : C) (k : ∀ a, W ⟶ I.left a) (h : ∀ b, k (I.fstTo b) ≫ I.fst b = k (I.sndTo b) ≫ I.snd b) (a) : Multiequalizer.lift I _ k h ≫ Multiequalizer.ι I a = k _ := limit.lift_π _ _ @[ext] theorem hom_ext {W : C} (i j : W ⟶ multiequalizer I) (h : ∀ a, i ≫ Multiequalizer.ι I a = j ≫ Multiequalizer.ι I a) : i = j := Multifork.IsLimit.hom_ext (limit.isLimit _) h variable [HasProduct I.left] [HasProduct I.right] instance : HasEqualizer I.fstPiMap I.sndPiMap := ⟨⟨⟨_, IsLimit.ofPreservesConeTerminal I.multiforkEquivPiFork.functor (limit.isLimit _)⟩⟩⟩ /-- The multiequalizer is isomorphic to the equalizer of `∏ᶜ I.left ⇉ ∏ᶜ I.right`. -/ def isoEqualizer : multiequalizer I ≅ equalizer I.fstPiMap I.sndPiMap := limit.isoLimitCone ⟨_, IsLimit.ofPreservesConeTerminal I.multiforkEquivPiFork.inverse (limit.isLimit _)⟩ /-- The canonical injection `multiequalizer I ⟶ ∏ᶜ I.left`. -/ def ιPi : multiequalizer I ⟶ ∏ᶜ I.left := (isoEqualizer I).hom ≫ equalizer.ι I.fstPiMap I.sndPiMap @[reassoc (attr := simp)] theorem ιPi_π (a) : ιPi I ≫ Pi.π I.left a = ι I a := by rw [ιPi, Category.assoc, ← Iso.eq_inv_comp, isoEqualizer] simp instance : Mono (ιPi I) := mono_comp _ _ end Multiequalizer namespace Multicoequalizer variable (I : MultispanIndex.{w} C) [HasMulticoequalizer I] /-- The canonical map from the multiequalizer to the objects on the left. -/ abbrev π (b : I.R) : I.right b ⟶ multicoequalizer I := colimit.ι I.multispan (WalkingMultispan.right _) /-- The multicofork associated to the multicoequalizer. -/ abbrev multicofork : Multicofork I := colimit.cocone _ @[simp] theorem multicofork_π (b) : (Multicoequalizer.multicofork I).π b = Multicoequalizer.π I b := rfl -- @[simp] -- Porting note: LHS simplifies to obtain the normal form below theorem multicofork_ι_app_right (b) : (Multicoequalizer.multicofork I).ι.app (WalkingMultispan.right b) = Multicoequalizer.π I b := rfl @[simp] theorem multicofork_ι_app_right' (b) : colimit.ι (MultispanIndex.multispan I) (WalkingMultispan.right b) = π I b := rfl @[reassoc] theorem condition (a) : I.fst a ≫ Multicoequalizer.π I (I.fstFrom a) = I.snd a ≫ Multicoequalizer.π I (I.sndFrom a) := Multicofork.condition _ _ /-- Construct a morphism from the multicoequalizer from its universal property. -/ abbrev desc (W : C) (k : ∀ b, I.right b ⟶ W) (h : ∀ a, I.fst a ≫ k (I.fstFrom a) = I.snd a ≫ k (I.sndFrom a)) : multicoequalizer I ⟶ W := colimit.desc _ (Multicofork.ofπ I _ k h) @[reassoc] -- Porting note (#10618): simp can prove this, removed attribute theorem π_desc (W : C) (k : ∀ b, I.right b ⟶ W) (h : ∀ a, I.fst a ≫ k (I.fstFrom a) = I.snd a ≫ k (I.sndFrom a)) (b) : Multicoequalizer.π I b ≫ Multicoequalizer.desc I _ k h = k _ := colimit.ι_desc _ _ @[ext] theorem hom_ext {W : C} (i j : multicoequalizer I ⟶ W) (h : ∀ b, Multicoequalizer.π I b ≫ i = Multicoequalizer.π I b ≫ j) : i = j := colimit.hom_ext (by rintro (a | b) · simp_rw [← colimit.w I.multispan (WalkingMultispan.Hom.fst a), Category.assoc, h] · apply h) variable [HasCoproduct I.left] [HasCoproduct I.right] instance : HasCoequalizer I.fstSigmaMap I.sndSigmaMap := ⟨⟨⟨_, IsColimit.ofPreservesCoconeInitial I.multicoforkEquivSigmaCofork.functor (colimit.isColimit _)⟩⟩⟩ /-- The multicoequalizer is isomorphic to the coequalizer of `∐ I.left ⇉ ∐ I.right`. -/ def isoCoequalizer : multicoequalizer I ≅ coequalizer I.fstSigmaMap I.sndSigmaMap := colimit.isoColimitCocone ⟨_, IsColimit.ofPreservesCoconeInitial I.multicoforkEquivSigmaCofork.inverse (colimit.isColimit _)⟩ /-- The canonical projection `∐ I.right ⟶ multicoequalizer I`. -/ def sigmaπ : ∐ I.right ⟶ multicoequalizer I := coequalizer.π I.fstSigmaMap I.sndSigmaMap ≫ (isoCoequalizer I).inv @[reassoc (attr := simp)] theorem ι_sigmaπ (b) : Sigma.ι I.right b ≫ sigmaπ I = π I b := by rw [sigmaπ, ← Category.assoc, Iso.comp_inv_eq, isoCoequalizer] simp only [MultispanIndex.multicoforkEquivSigmaCofork_inverse, MultispanIndex.ofSigmaCoforkFunctor_obj, colimit.isoColimitCocone_ι_hom, Multicofork.ofSigmaCofork_pt, colimit.cocone_x, Multicofork.π_eq_app_right] rfl instance : Epi (sigmaπ I) := epi_comp _ _ end Multicoequalizer end end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Products.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.DiscreteCategory /-! # Categorical (co)products This file defines (co)products as special cases of (co)limits. A product is the categorical generalization of the object `Π i, f i` where `f : ι → C`. It is a limit cone over the diagram formed by `f`, implemented by converting `f` into a functor `Discrete ι ⥤ C`. A coproduct is the dual concept. ## Main definitions * a `Fan` is a cone over a discrete category * `Fan.mk` constructs a fan from an indexed collection of maps * a `Pi` is a `limit (Discrete.functor f)` Each of these has a dual. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. -/ noncomputable section universe w w' w₂ w₃ v v₂ u u₂ open CategoryTheory namespace CategoryTheory.Limits variable {β : Type w} {α : Type w₂} {γ : Type w₃} variable {C : Type u} [Category.{v} C] -- We don't need an analogue of `Pair` (for binary products), `ParallelPair` (for equalizers), -- or `(Co)span`, since we already have `Discrete.functor`. /-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/ abbrev Fan (f : β → C) := Cone (Discrete.functor f) /-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/ abbrev Cofan (f : β → C) := Cocone (Discrete.functor f) /-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/ @[simps! pt π_app] def Fan.mk {f : β → C} (P : C) (p : ∀ b, P ⟶ f b) : Fan f where pt := P π := Discrete.natTrans (fun X => p X.as) /-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/ @[simps! pt ι_app] def Cofan.mk {f : β → C} (P : C) (p : ∀ b, f b ⟶ P) : Cofan f where pt := P ι := Discrete.natTrans (fun X => p X.as) /-- Get the `j`th "projection" in the fan. (Note that the initial letter of `proj` matches the greek letter in `Cone.π`.) -/ def Fan.proj {f : β → C} (p : Fan f) (j : β) : p.pt ⟶ f j := p.π.app (Discrete.mk j) /-- Get the `j`th "injection" in the cofan. (Note that the initial letter of `inj` matches the greek letter in `Cocone.ι`.) -/ def Cofan.inj {f : β → C} (p : Cofan f) (j : β) : f j ⟶ p.pt := p.ι.app (Discrete.mk j) @[simp] theorem fan_mk_proj {f : β → C} (P : C) (p : ∀ b, P ⟶ f b) (j : β) : (Fan.mk P p).proj j = p j := rfl @[simp] theorem cofan_mk_inj {f : β → C} (P : C) (p : ∀ b, f b ⟶ P) (j : β) : (Cofan.mk P p).inj j = p j := rfl /-- An abbreviation for `HasLimit (Discrete.functor f)`. -/ abbrev HasProduct (f : β → C) := HasLimit (Discrete.functor f) /-- An abbreviation for `HasColimit (Discrete.functor f)`. -/ abbrev HasCoproduct (f : β → C) := HasColimit (Discrete.functor f) lemma hasCoproduct_of_equiv_of_iso (f : α → C) (g : β → C) [HasCoproduct f] (e : β ≃ α) (iso : ∀ j, g j ≅ f (e j)) : HasCoproduct g := by have : HasColimit ((Discrete.equivalence e).functor ⋙ Discrete.functor f) := hasColimit_equivalence_comp _ have α : Discrete.functor g ≅ (Discrete.equivalence e).functor ⋙ Discrete.functor f := Discrete.natIso (fun ⟨j⟩ => iso j) exact hasColimitOfIso α lemma hasProduct_of_equiv_of_iso (f : α → C) (g : β → C) [HasProduct f] (e : β ≃ α) (iso : ∀ j, g j ≅ f (e j)) : HasProduct g := by have : HasLimit ((Discrete.equivalence e).functor ⋙ Discrete.functor f) := hasLimitEquivalenceComp _ have α : Discrete.functor g ≅ (Discrete.equivalence e).functor ⋙ Discrete.functor f := Discrete.natIso (fun ⟨j⟩ => iso j) exact hasLimitOfIso α.symm /-- Make a fan `f` into a limit fan by providing `lift`, `fac`, and `uniq` -- just a convenience lemma to avoid having to go through `Discrete` -/ @[simps] def mkFanLimit {f : β → C} (t : Fan f) (lift : ∀ s : Fan f, s.pt ⟶ t.pt) (fac : ∀ (s : Fan f) (j : β), lift s ≫ t.proj j = s.proj j := by aesop_cat) (uniq : ∀ (s : Fan f) (m : s.pt ⟶ t.pt) (_ : ∀ j : β, m ≫ t.proj j = s.proj j), m = lift s := by aesop_cat) : IsLimit t := { lift } /-- Constructor for morphisms to the point of a limit fan. -/ def Fan.IsLimit.desc {F : β → C} {c : Fan F} (hc : IsLimit c) {A : C} (f : ∀ i, A ⟶ F i) : A ⟶ c.pt := hc.lift (Fan.mk A f) @[reassoc (attr := simp)] lemma Fan.IsLimit.fac {F : β → C} {c : Fan F} (hc : IsLimit c) {A : C} (f : ∀ i, A ⟶ F i) (i : β) : Fan.IsLimit.desc hc f ≫ c.proj i = f i := hc.fac (Fan.mk A f) ⟨i⟩ lemma Fan.IsLimit.hom_ext {I : Type*} {F : I → C} {c : Fan F} (hc : IsLimit c) {A : C} (f g : A ⟶ c.pt) (h : ∀ i, f ≫ c.proj i = g ≫ c.proj i) : f = g := hc.hom_ext (fun ⟨i⟩ => h i) /-- Make a cofan `f` into a colimit cofan by providing `desc`, `fac`, and `uniq` -- just a convenience lemma to avoid having to go through `Discrete` -/ @[simps] def mkCofanColimit {f : β → C} (s : Cofan f) (desc : ∀ t : Cofan f, s.pt ⟶ t.pt) (fac : ∀ (t : Cofan f) (j : β), s.inj j ≫ desc t = t.inj j := by aesop_cat) (uniq : ∀ (t : Cofan f) (m : s.pt ⟶ t.pt) (_ : ∀ j : β, s.inj j ≫ m = t.inj j), m = desc t := by aesop_cat) : IsColimit s := { desc } /-- Constructor for morphisms from the point of a colimit cofan. -/ def Cofan.IsColimit.desc {F : β → C} {c : Cofan F} (hc : IsColimit c) {A : C} (f : ∀ i, F i ⟶ A) : c.pt ⟶ A := hc.desc (Cofan.mk A f) @[reassoc (attr := simp)] lemma Cofan.IsColimit.fac {F : β → C} {c : Cofan F} (hc : IsColimit c) {A : C} (f : ∀ i, F i ⟶ A) (i : β) : c.inj i ≫ Cofan.IsColimit.desc hc f = f i := hc.fac (Cofan.mk A f) ⟨i⟩ lemma Cofan.IsColimit.hom_ext {I : Type*} {F : I → C} {c : Cofan F} (hc : IsColimit c) {A : C} (f g : c.pt ⟶ A) (h : ∀ i, c.inj i ≫ f = c.inj i ≫ g) : f = g := hc.hom_ext (fun ⟨i⟩ => h i) section variable (C) /-- An abbreviation for `HasLimitsOfShape (Discrete f)`. -/ abbrev HasProductsOfShape (β : Type v) := HasLimitsOfShape.{v} (Discrete β) /-- An abbreviation for `HasColimitsOfShape (Discrete f)`. -/ abbrev HasCoproductsOfShape (β : Type v) := HasColimitsOfShape.{v} (Discrete β) end /-- `piObj f` computes the product of a family of elements `f`. (It is defined as an abbreviation for `limit (Discrete.functor f)`, so for most facts about `piObj f`, you will just use general facts about limits.) -/ abbrev piObj (f : β → C) [HasProduct f] := limit (Discrete.functor f) /-- `sigmaObj f` computes the coproduct of a family of elements `f`. (It is defined as an abbreviation for `colimit (Discrete.functor f)`, so for most facts about `sigmaObj f`, you will just use general facts about colimits.) -/ abbrev sigmaObj (f : β → C) [HasCoproduct f] := colimit (Discrete.functor f) /-- notation for categorical products. We need `ᶜ` to avoid conflict with `Finset.prod`. -/ notation "∏ᶜ " f:60 => piObj f /-- notation for categorical coproducts -/ notation "∐ " f:60 => sigmaObj f /-- The `b`-th projection from the pi object over `f` has the form `∏ᶜ f ⟶ f b`. -/ abbrev Pi.π (f : β → C) [HasProduct f] (b : β) : ∏ᶜ f ⟶ f b := limit.π (Discrete.functor f) (Discrete.mk b) /-- The `b`-th inclusion into the sigma object over `f` has the form `f b ⟶ ∐ f`. -/ abbrev Sigma.ι (f : β → C) [HasCoproduct f] (b : β) : f b ⟶ ∐ f := colimit.ι (Discrete.functor f) (Discrete.mk b) -- porting note (#10688): added the next two lemmas to ease automation; without these lemmas, -- `limit.hom_ext` would be applied, but the goal would involve terms -- in `Discrete β` rather than `β` itself @[ext 1050] lemma Pi.hom_ext {f : β → C} [HasProduct f] {X : C} (g₁ g₂ : X ⟶ ∏ᶜ f) (h : ∀ (b : β), g₁ ≫ Pi.π f b = g₂ ≫ Pi.π f b) : g₁ = g₂ := limit.hom_ext (fun ⟨j⟩ => h j) @[ext 1050] lemma Sigma.hom_ext {f : β → C} [HasCoproduct f] {X : C} (g₁ g₂ : ∐ f ⟶ X) (h : ∀ (b : β), Sigma.ι f b ≫ g₁ = Sigma.ι f b ≫ g₂) : g₁ = g₂ := colimit.hom_ext (fun ⟨j⟩ => h j) /-- The fan constructed of the projections from the product is limiting. -/ def productIsProduct (f : β → C) [HasProduct f] : IsLimit (Fan.mk _ (Pi.π f)) := IsLimit.ofIsoLimit (limit.isLimit (Discrete.functor f)) (Cones.ext (Iso.refl _)) /-- The cofan constructed of the inclusions from the coproduct is colimiting. -/ def coproductIsCoproduct (f : β → C) [HasCoproduct f] : IsColimit (Cofan.mk _ (Sigma.ι f)) := IsColimit.ofIsoColimit (colimit.isColimit (Discrete.functor f)) (Cocones.ext (Iso.refl _)) -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `Pi.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem Pi.π_comp_eqToHom {J : Type*} (f : J → C) [HasProduct f] {j j' : J} (w : j = j') : Pi.π f j ≫ eqToHom (by simp [w]) = Pi.π f j' := by cases w simp -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `Sigma.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem Sigma.eqToHom_comp_ι {J : Type*} (f : J → C) [HasCoproduct f] {j j' : J} (w : j = j') : eqToHom (by simp [w]) ≫ Sigma.ι f j' = Sigma.ι f j := by cases w simp /-- A collection of morphisms `P ⟶ f b` induces a morphism `P ⟶ ∏ᶜ f`. -/ abbrev Pi.lift {f : β → C} [HasProduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ∏ᶜ f := limit.lift _ (Fan.mk P p) theorem Pi.lift_π {β : Type w} {f : β → C} [HasProduct f] {P : C} (p : ∀ b, P ⟶ f b) (b : β) : Pi.lift p ≫ Pi.π f b = p b := by simp only [limit.lift_π, Fan.mk_pt, Fan.mk_π_app] /-- A collection of morphisms `f b ⟶ P` induces a morphism `∐ f ⟶ P`. -/ abbrev Sigma.desc {f : β → C} [HasCoproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ∐ f ⟶ P := colimit.desc _ (Cofan.mk P p) theorem Sigma.ι_desc {β : Type w} {f : β → C} [HasCoproduct f] {P : C} (p : ∀ b, f b ⟶ P) (b : β) : Sigma.ι f b ≫ Sigma.desc p = p b := by simp only [colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] instance {f : β → C} [HasCoproduct f] : IsIso (Sigma.desc (fun a ↦ Sigma.ι f a)) := by convert IsIso.id _ ext simp /-- A version of `Cocones.ext` for `Cofan`s. -/ @[simps!] def Cofan.ext {f : β → C} {c₁ c₂ : Cofan f} (e : c₁.pt ≅ c₂.pt) (w : ∀ (b : β), c₁.inj b ≫ e.hom = c₂.inj b := by aesop_cat) : c₁ ≅ c₂ := Cocones.ext e (fun ⟨j⟩ => w j) /-- A cofan `c` on `f` such that the induced map `∐ f ⟶ c.pt` is an iso, is a coproduct. -/ def Cofan.isColimitOfIsIsoSigmaDesc {f : β → C} [HasCoproduct f] (c : Cofan f) [hc : IsIso (Sigma.desc c.inj)] : IsColimit c := IsColimit.ofIsoColimit (colimit.isColimit (Discrete.functor f)) (Cofan.ext (@asIso _ _ _ _ _ hc) (fun _ => colimit.ι_desc _ _)) lemma Cofan.isColimit_iff_isIso_sigmaDesc {f : β → C} [HasCoproduct f] (c : Cofan f) : IsIso (Sigma.desc c.inj) ↔ Nonempty (IsColimit c) := by refine ⟨fun h ↦ ⟨isColimitOfIsIsoSigmaDesc c⟩, fun ⟨hc⟩ ↦ ?_⟩ have : IsIso (((coproductIsCoproduct f).coconePointUniqueUpToIso hc).hom ≫ hc.desc c) := by simp; infer_instance convert this ext simp only [colimit.ι_desc, mk_pt, mk_ι_app, IsColimit.coconePointUniqueUpToIso, coproductIsCoproduct, colimit.cocone_x, Functor.mapIso_hom, IsColimit.uniqueUpToIso_hom, Cocones.forget_map, IsColimit.descCoconeMorphism_hom, IsColimit.ofIsoColimit_desc, Cocones.ext_inv_hom, Iso.refl_inv, colimit.isColimit_desc, Category.id_comp, IsColimit.desc_self, Category.comp_id] rfl /-- A coproduct of coproducts is a coproduct -/ def Cofan.isColimitTrans {X : α → C} (c : Cofan X) (hc : IsColimit c) {β : α → Type*} {Y : (a : α) → β a → C} (π : (a : α) → (b : β a) → Y a b ⟶ X a) (hs : ∀ a, IsColimit (Cofan.mk (X a) (π a))) : IsColimit (Cofan.mk (f := fun ⟨a,b⟩ => Y a b) c.pt (fun (⟨a, b⟩ : Σ a, _) ↦ π a b ≫ c.inj a)) := by refine mkCofanColimit _ ?_ ?_ ?_ · exact fun t ↦ hc.desc (Cofan.mk _ fun a ↦ (hs a).desc (Cofan.mk t.pt (fun b ↦ t.inj ⟨a, b⟩))) · intro t ⟨a, b⟩ simp only [mk_pt, cofan_mk_inj, Category.assoc] erw [hc.fac, (hs a).fac] rfl · intro t m h refine hc.hom_ext fun ⟨a⟩ ↦ (hs a).hom_ext fun ⟨b⟩ ↦ ?_ erw [hc.fac, (hs a).fac] simpa using h ⟨a, b⟩ /-- Construct a morphism between categorical products (indexed by the same type) from a family of morphisms between the factors. -/ abbrev Pi.map {f g : β → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b) : ∏ᶜ f ⟶ ∏ᶜ g := limMap (Discrete.natTrans fun X => p X.as) @[simp] lemma Pi.map_id {f : α → C} [HasProduct f] : Pi.map (fun a => 𝟙 (f a)) = 𝟙 (∏ᶜ f) := by ext; simp lemma Pi.map_comp_map {f g h : α → C} [HasProduct f] [HasProduct g] [HasProduct h] (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (a : α), g a ⟶ h a) : Pi.map q ≫ Pi.map q' = Pi.map (fun a => q a ≫ q' a) := by ext; simp instance Pi.map_mono {f g : β → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b) [∀ i, Mono (p i)] : Mono <| Pi.map p := @Limits.limMap_mono _ _ _ _ (Discrete.functor f) (Discrete.functor g) _ _ (Discrete.natTrans fun X => p X.as) (by dsimp; infer_instance) /-- Construct a morphism between categorical products from a family of morphisms between the factors. -/ def Pi.map' {f : α → C} {g : β → C} [HasProduct f] [HasProduct g] (p : β → α) (q : ∀ (b : β), f (p b) ⟶ g b) : ∏ᶜ f ⟶ ∏ᶜ g := Pi.lift (fun a => Pi.π _ _ ≫ q a) @[reassoc (attr := simp)] lemma Pi.map'_comp_π {f : α → C} {g : β → C} [HasProduct f] [HasProduct g] (p : β → α) (q : ∀ (b : β), f (p b) ⟶ g b) (b : β) : Pi.map' p q ≫ Pi.π g b = Pi.π f (p b) ≫ q b := limit.lift_π _ _ lemma Pi.map'_id_id {f : α → C} [HasProduct f] : Pi.map' id (fun a => 𝟙 (f a)) = 𝟙 (∏ᶜ f) := by ext; simp @[simp] lemma Pi.map'_id {f g : α → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b) : Pi.map' id p = Pi.map p := rfl lemma Pi.map'_comp_map' {f : α → C} {g : β → C} {h : γ → C} [HasProduct f] [HasProduct g] [HasProduct h] (p : β → α) (p' : γ → β) (q : ∀ (b : β), f (p b) ⟶ g b) (q' : ∀ (c : γ), g (p' c) ⟶ h c) : Pi.map' p q ≫ Pi.map' p' q' = Pi.map' (p ∘ p') (fun c => q (p' c) ≫ q' c) := by ext; simp lemma Pi.map'_comp_map {f : α → C} {g h : β → C} [HasProduct f] [HasProduct g] [HasProduct h] (p : β → α) (q : ∀ (b : β), f (p b) ⟶ g b) (q' : ∀ (b : β), g b ⟶ h b) : Pi.map' p q ≫ Pi.map q' = Pi.map' p (fun b => q b ≫ q' b) := by ext; simp lemma Pi.map_comp_map' {f g : α → C} {h : β → C} [HasProduct f] [HasProduct g] [HasProduct h] (p : β → α) (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (b : β), g (p b) ⟶ h b) : Pi.map q ≫ Pi.map' p q' = Pi.map' p (fun b => q (p b) ≫ q' b) := by ext; simp lemma Pi.map'_eq {f : α → C} {g : β → C} [HasProduct f] [HasProduct g] {p p' : β → α} {q : ∀ (b : β), f (p b) ⟶ g b} {q' : ∀ (b : β), f (p' b) ⟶ g b} (hp : p = p') (hq : ∀ (b : β), eqToHom (hp ▸ rfl) ≫ q b = q' b) : Pi.map' p q = Pi.map' p' q' := by aesop_cat /-- Construct an isomorphism between categorical products (indexed by the same type) from a family of isomorphisms between the factors. -/ abbrev Pi.mapIso {f g : β → C} [HasProductsOfShape β C] (p : ∀ b, f b ≅ g b) : ∏ᶜ f ≅ ∏ᶜ g := lim.mapIso (Discrete.natIso fun X => p X.as) section /- In this section, we provide some API for products when we are given a functor `Discrete α ⥤ C` instead of a map `α → C`. -/ variable (X : Discrete α ⥤ C) [HasProduct (fun j => X.obj (Discrete.mk j))] /-- A limit cone for `X : Discrete α ⥤ C` that is given by `∏ᶜ (fun j => X.obj (Discrete.mk j))`. -/ @[simps] def Pi.cone : Cone X where pt := ∏ᶜ (fun j => X.obj (Discrete.mk j)) π := Discrete.natTrans (fun _ => Pi.π _ _) /-- The cone `Pi.cone X` is a limit cone. -/ def productIsProduct' : IsLimit (Pi.cone X) where lift s := Pi.lift (fun j => s.π.app ⟨j⟩) fac s := by simp uniq s m hm := by dsimp ext simp only [limit.lift_π, Fan.mk_pt, Fan.mk_π_app] apply hm variable [HasLimit X] /-- The isomorphism `∏ᶜ (fun j => X.obj (Discrete.mk j)) ≅ limit X`. -/ def Pi.isoLimit : ∏ᶜ (fun j => X.obj (Discrete.mk j)) ≅ limit X := IsLimit.conePointUniqueUpToIso (productIsProduct' X) (limit.isLimit X) @[reassoc (attr := simp)] lemma Pi.isoLimit_inv_π (j : α) : (Pi.isoLimit X).inv ≫ Pi.π _ j = limit.π _ (Discrete.mk j) := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ @[reassoc (attr := simp)] lemma Pi.isoLimit_hom_π (j : α) : (Pi.isoLimit X).hom ≫ limit.π _ (Discrete.mk j) = Pi.π _ j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ end /-- Construct a morphism between categorical coproducts (indexed by the same type) from a family of morphisms between the factors. -/ abbrev Sigma.map {f g : β → C} [HasCoproduct f] [HasCoproduct g] (p : ∀ b, f b ⟶ g b) : ∐ f ⟶ ∐ g := colimMap (Discrete.natTrans fun X => p X.as) @[simp] lemma Sigma.map_id {f : α → C} [HasCoproduct f] : Sigma.map (fun a => 𝟙 (f a)) = 𝟙 (∐ f) := by ext; simp lemma Sigma.map_comp_map {f g h : α → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (a : α), g a ⟶ h a) : Sigma.map q ≫ Sigma.map q' = Sigma.map (fun a => q a ≫ q' a) := by ext; simp instance Sigma.map_epi {f g : β → C} [HasCoproduct f] [HasCoproduct g] (p : ∀ b, f b ⟶ g b) [∀ i, Epi (p i)] : Epi <| Sigma.map p := @Limits.colimMap_epi _ _ _ _ (Discrete.functor f) (Discrete.functor g) _ _ (Discrete.natTrans fun X => p X.as) (by dsimp; infer_instance) /-- Construct a morphism between categorical coproducts from a family of morphisms between the factors. -/ def Sigma.map' {f : α → C} {g : β → C} [HasCoproduct f] [HasCoproduct g] (p : α → β) (q : ∀ (a : α), f a ⟶ g (p a)) : ∐ f ⟶ ∐ g := Sigma.desc (fun a => q a ≫ Sigma.ι _ _) @[reassoc (attr := simp)] lemma Sigma.ι_comp_map' {f : α → C} {g : β → C} [HasCoproduct f] [HasCoproduct g] (p : α → β) (q : ∀ (a : α), f a ⟶ g (p a)) (a : α) : Sigma.ι f a ≫ Sigma.map' p q = q a ≫ Sigma.ι g (p a) := colimit.ι_desc _ _ lemma Sigma.map'_id_id {f : α → C} [HasCoproduct f] : Sigma.map' id (fun a => 𝟙 (f a)) = 𝟙 (∐ f) := by ext; simp @[simp] lemma Sigma.map'_id {f g : α → C} [HasCoproduct f] [HasCoproduct g] (p : ∀ b, f b ⟶ g b) : Sigma.map' id p = Sigma.map p := rfl lemma Sigma.map'_comp_map' {f : α → C} {g : β → C} {h : γ → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (p : α → β) (p' : β → γ) (q : ∀ (a : α), f a ⟶ g (p a)) (q' : ∀ (b : β), g b ⟶ h (p' b)) : Sigma.map' p q ≫ Sigma.map' p' q' = Sigma.map' (p' ∘ p) (fun a => q a ≫ q' (p a)) := by ext; simp lemma Sigma.map'_comp_map {f : α → C} {g h : β → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (p : α → β) (q : ∀ (a : α), f a ⟶ g (p a)) (q' : ∀ (b : β), g b ⟶ h b) : Sigma.map' p q ≫ Sigma.map q' = Sigma.map' p (fun a => q a ≫ q' (p a)) := by ext; simp lemma Sigma.map_comp_map' {f g : α → C} {h : β → C} [HasCoproduct f] [HasCoproduct g] [HasCoproduct h] (p : α → β) (q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (a : α), g a ⟶ h (p a)) : Sigma.map q ≫ Sigma.map' p q' = Sigma.map' p (fun a => q a ≫ q' a) := by ext; simp lemma Sigma.map'_eq {f : α → C} {g : β → C} [HasCoproduct f] [HasCoproduct g] {p p' : α → β} {q : ∀ (a : α), f a ⟶ g (p a)} {q' : ∀ (a : α), f a ⟶ g (p' a)} (hp : p = p') (hq : ∀ (a : α), q a ≫ eqToHom (hp ▸ rfl) = q' a) : Sigma.map' p q = Sigma.map' p' q' := by aesop_cat /-- Construct an isomorphism between categorical coproducts (indexed by the same type) from a family of isomorphisms between the factors. -/ abbrev Sigma.mapIso {f g : β → C} [HasCoproductsOfShape β C] (p : ∀ b, f b ≅ g b) : ∐ f ≅ ∐ g := colim.mapIso (Discrete.natIso fun X => p X.as) /-- Two products which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. -/ @[simps] def Pi.whiskerEquiv {J K : Type*} {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasProduct f] [HasProduct g] : ∏ᶜ f ≅ ∏ᶜ g where hom := Pi.map' e.symm fun k => (w (e.symm k)).inv ≫ eqToHom (by simp) inv := Pi.map' e fun j => (w j).hom /-- Two coproducts which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. -/ @[simps] def Sigma.whiskerEquiv {J K : Type*} {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasCoproduct f] [HasCoproduct g] : ∐ f ≅ ∐ g where hom := Sigma.map' e fun j => (w j).inv inv := Sigma.map' e.symm fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom #adaptation_note /-- nightly-2024-04-01 The last proof was previously by `aesop_cat`. -/ instance {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasProduct (g i)] [HasProduct fun i => ∏ᶜ g i] : HasProduct fun p : Σ i, f i => g p.1 p.2 where exists_limit := Nonempty.intro { cone := Fan.mk (∏ᶜ fun i => ∏ᶜ g i) (fun X => Pi.π (fun i => ∏ᶜ g i) X.1 ≫ Pi.π (g X.1) X.2) isLimit := mkFanLimit _ (fun s => Pi.lift fun b => Pi.lift fun c => s.proj ⟨b, c⟩) (by aesop_cat) (by intro s m w; simp only [Fan.mk_pt]; symm; ext i x; simp_all) } /-- An iterated product is a product over a sigma type. -/ @[simps] def piPiIso {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasProduct (g i)] [HasProduct fun i => ∏ᶜ g i] : (∏ᶜ fun i => ∏ᶜ g i) ≅ (∏ᶜ fun p : Σ i, f i => g p.1 p.2) where hom := Pi.lift fun ⟨i, x⟩ => Pi.π _ i ≫ Pi.π _ x inv := Pi.lift fun i => Pi.lift fun x => Pi.π _ (⟨i, x⟩ : Σ i, f i) #adaptation_note /-- nightly-2024-04-01 The last proof was previously by `aesop_cat`. -/ instance {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasCoproduct (g i)] [HasCoproduct fun i => ∐ g i] : HasCoproduct fun p : Σ i, f i => g p.1 p.2 where exists_colimit := Nonempty.intro { cocone := Cofan.mk (∐ fun i => ∐ g i) (fun X => Sigma.ι (g X.1) X.2 ≫ Sigma.ι (fun i => ∐ g i) X.1) isColimit := mkCofanColimit _ (fun s => Sigma.desc fun b => Sigma.desc fun c => s.inj ⟨b, c⟩) (by aesop_cat) (by intro s m w; simp only [Cofan.mk_pt]; symm; ext i x; simp_all) } /-- An iterated coproduct is a coproduct over a sigma type. -/ @[simps] def sigmaSigmaIso {ι : Type*} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasCoproduct (g i)] [HasCoproduct fun i => ∐ g i] : (∐ fun i => ∐ g i) ≅ (∐ fun p : Σ i, f i => g p.1 p.2) where hom := Sigma.desc fun i => Sigma.desc fun x => Sigma.ι (fun p : Σ i, f i => g p.1 p.2) ⟨i, x⟩ inv := Sigma.desc fun ⟨i, x⟩ => Sigma.ι (g i) x ≫ Sigma.ι (fun i => ∐ g i) i section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) variable (f : β → C) /-- The comparison morphism for the product of `f`. This is an iso iff `G` preserves the product of `f`, see `PreservesProduct.ofIsoComparison`. -/ def piComparison [HasProduct f] [HasProduct fun b => G.obj (f b)] : G.obj (∏ᶜ f) ⟶ ∏ᶜ fun b => G.obj (f b) := Pi.lift fun b => G.map (Pi.π f b) @[reassoc (attr := simp)] theorem piComparison_comp_π [HasProduct f] [HasProduct fun b => G.obj (f b)] (b : β) : piComparison G f ≫ Pi.π _ b = G.map (Pi.π f b) := limit.lift_π _ (Discrete.mk b) @[reassoc (attr := simp)] theorem map_lift_piComparison [HasProduct f] [HasProduct fun b => G.obj (f b)] (P : C) (g : ∀ j, P ⟶ f j) : G.map (Pi.lift g) ≫ piComparison G f = Pi.lift fun j => G.map (g j) := by ext j simp only [Discrete.functor_obj, Category.assoc, piComparison_comp_π, ← G.map_comp, limit.lift_π, Fan.mk_pt, Fan.mk_π_app] /-- The comparison morphism for the coproduct of `f`. This is an iso iff `G` preserves the coproduct of `f`, see `PreservesCoproduct.ofIsoComparison`. -/ def sigmaComparison [HasCoproduct f] [HasCoproduct fun b => G.obj (f b)] : ∐ (fun b => G.obj (f b)) ⟶ G.obj (∐ f) := Sigma.desc fun b => G.map (Sigma.ι f b) @[reassoc (attr := simp)] theorem ι_comp_sigmaComparison [HasCoproduct f] [HasCoproduct fun b => G.obj (f b)] (b : β) : Sigma.ι _ b ≫ sigmaComparison G f = G.map (Sigma.ι f b) := colimit.ι_desc _ (Discrete.mk b) @[reassoc (attr := simp)] theorem sigmaComparison_map_desc [HasCoproduct f] [HasCoproduct fun b => G.obj (f b)] (P : C) (g : ∀ j, f j ⟶ P) : sigmaComparison G f ≫ G.map (Sigma.desc g) = Sigma.desc fun j => G.map (g j) := by ext j simp only [Discrete.functor_obj, ι_comp_sigmaComparison_assoc, ← G.map_comp, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app] end Comparison variable (C) /-- An abbreviation for `Π J, HasLimitsOfShape (Discrete J) C` -/ abbrev HasProducts := ∀ J : Type w, HasLimitsOfShape (Discrete J) C /-- An abbreviation for `Π J, HasColimitsOfShape (Discrete J) C` -/ abbrev HasCoproducts := ∀ J : Type w, HasColimitsOfShape (Discrete J) C variable {C} theorem has_smallest_products_of_hasProducts [HasProducts.{w} C] : HasProducts.{0} C := fun J => hasLimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift : Discrete (ULift.{w} J) ≌ _) theorem has_smallest_coproducts_of_hasCoproducts [HasCoproducts.{w} C] : HasCoproducts.{0} C := fun J => hasColimitsOfShape_of_equivalence (Discrete.equivalence Equiv.ulift : Discrete (ULift.{w} J) ≌ _) theorem hasProducts_of_limit_fans (lf : ∀ {J : Type w} (f : J → C), Fan f) (lf_isLimit : ∀ {J : Type w} (f : J → C), IsLimit (lf f)) : HasProducts.{w} C := fun _ : Type w => { has_limit := fun F => HasLimit.mk ⟨(Cones.postcompose Discrete.natIsoFunctor.inv).obj (lf fun j => F.obj ⟨j⟩), (IsLimit.postcomposeInvEquiv _ _).symm (lf_isLimit _)⟩ } /-! (Co)products over a type with a unique term. -/ section Unique variable [Unique β] (f : β → C) /-- The limit cone for the product over an index type with exactly one term. -/ @[simps] def limitConeOfUnique : LimitCone (Discrete.functor f) where cone := { pt := f default π := Discrete.natTrans (fun ⟨j⟩ => eqToHom (by dsimp congr subsingleton)) } isLimit := { lift := fun s => s.π.app default fac := fun s j => by have h := Subsingleton.elim j default subst h simp uniq := fun s m w => by specialize w default simpa using w } instance (priority := 100) hasProduct_unique : HasProduct f := HasLimit.mk (limitConeOfUnique f) /-- A product over an index type with exactly one term is just the object over that term. -/ @[simps!] def productUniqueIso : ∏ᶜ f ≅ f default := IsLimit.conePointUniqueUpToIso (limit.isLimit _) (limitConeOfUnique f).isLimit /-- The colimit cocone for the coproduct over an index type with exactly one term. -/ @[simps] def colimitCoconeOfUnique : ColimitCocone (Discrete.functor f) where cocone := { pt := f default ι := Discrete.natTrans (fun ⟨j⟩ => eqToHom (by dsimp congr subsingleton)) } isColimit := { desc := fun s => s.ι.app default fac := fun s j => by have h := Subsingleton.elim j default subst h apply Category.id_comp uniq := fun s m w => by specialize w default erw [Category.id_comp] at w exact w } instance (priority := 100) hasCoproduct_unique : HasCoproduct f := HasColimit.mk (colimitCoconeOfUnique f) /-- A coproduct over an index type with exactly one term is just the object over that term. -/ @[simps!] def coproductUniqueIso : ∐ f ≅ f default := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (colimitCoconeOfUnique f).isColimit end Unique section Reindex variable {γ : Type w'} (ε : β ≃ γ) (f : γ → C) section variable [HasProduct f] [HasProduct (f ∘ ε)] /-- Reindex a categorical product via an equivalence of the index types. -/ def Pi.reindex : piObj (f ∘ ε) ≅ piObj f := HasLimit.isoOfEquivalence (Discrete.equivalence ε) (Discrete.natIso fun _ => Iso.refl _) @[reassoc (attr := simp)] theorem Pi.reindex_hom_π (b : β) : (Pi.reindex ε f).hom ≫ Pi.π f (ε b) = Pi.π (f ∘ ε) b := by dsimp [Pi.reindex] simp only [HasLimit.isoOfEquivalence_hom_π, Discrete.equivalence_inverse, Discrete.functor_obj, Function.comp_apply, Functor.id_obj, Discrete.equivalence_functor, Functor.comp_obj, Discrete.natIso_inv_app, Iso.refl_inv, Category.id_comp] exact limit.w (Discrete.functor (f ∘ ε)) (Discrete.eqToHom' (ε.symm_apply_apply b)) @[reassoc (attr := simp)] theorem Pi.reindex_inv_π (b : β) : (Pi.reindex ε f).inv ≫ Pi.π (f ∘ ε) b = Pi.π f (ε b) := by simp [Iso.inv_comp_eq] end section variable [HasCoproduct f] [HasCoproduct (f ∘ ε)] /-- Reindex a categorical coproduct via an equivalence of the index types. -/ def Sigma.reindex : sigmaObj (f ∘ ε) ≅ sigmaObj f := HasColimit.isoOfEquivalence (Discrete.equivalence ε) (Discrete.natIso fun _ => Iso.refl _) @[reassoc (attr := simp)] theorem Sigma.ι_reindex_hom (b : β) : Sigma.ι (f ∘ ε) b ≫ (Sigma.reindex ε f).hom = Sigma.ι f (ε b) := by dsimp [Sigma.reindex] simp only [HasColimit.isoOfEquivalence_hom_π, Functor.id_obj, Discrete.functor_obj, Function.comp_apply, Discrete.equivalence_functor, Discrete.equivalence_inverse, Functor.comp_obj, Discrete.natIso_inv_app, Iso.refl_inv, Category.id_comp] have h := colimit.w (Discrete.functor f) (Discrete.eqToHom' (ε.apply_symm_apply (ε b))) simp only [Discrete.functor_obj] at h erw [← h, eqToHom_map, eqToHom_map, eqToHom_trans_assoc] all_goals { simp } @[reassoc (attr := simp)] theorem Sigma.ι_reindex_inv (b : β) : Sigma.ι f (ε b) ≫ (Sigma.reindex ε f).inv = Sigma.ι (f ∘ ε) b := by simp [Iso.comp_inv_eq] end end Reindex end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Reflexive.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.KernelPair /-! # Reflexive coequalizers We define reflexive pairs as a pair of morphisms which have a common section. We say a category has reflexive coequalizers if it has coequalizers of all reflexive pairs. Reflexive coequalizers often enjoy nicer properties than general coequalizers, and feature heavily in some versions of the monadicity theorem. We also give some examples of reflexive pairs: for an adjunction `F ⊣ G` with counit `ε`, the pair `(FGε_B, ε_FGB)` is reflexive. If a pair `f,g` is a kernel pair for some morphism, then it is reflexive. # TODO * If `C` has binary coproducts and reflexive coequalizers, then it has all coequalizers. * If `T` is a monad on cocomplete category `C`, then `Algebra T` is cocomplete iff it has reflexive coequalizers. * If `C` is locally cartesian closed and has reflexive coequalizers, then it has images: in fact regular epi (and hence strong epi) images. -/ namespace CategoryTheory universe v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {D : Type u₂} [Category.{v₂} D] variable {A B : C} {f g : A ⟶ B} /-- The pair `f g : A ⟶ B` is reflexive if there is a morphism `B ⟶ A` which is a section for both. -/ class IsReflexivePair (f g : A ⟶ B) : Prop where common_section' : ∃ s : B ⟶ A, s ≫ f = 𝟙 B ∧ s ≫ g = 𝟙 B theorem IsReflexivePair.common_section (f g : A ⟶ B) [IsReflexivePair f g] : ∃ s : B ⟶ A, s ≫ f = 𝟙 B ∧ s ≫ g = 𝟙 B := IsReflexivePair.common_section' /-- The pair `f g : A ⟶ B` is coreflexive if there is a morphism `B ⟶ A` which is a retraction for both. -/ class IsCoreflexivePair (f g : A ⟶ B) : Prop where common_retraction' : ∃ s : B ⟶ A, f ≫ s = 𝟙 A ∧ g ≫ s = 𝟙 A theorem IsCoreflexivePair.common_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] : ∃ s : B ⟶ A, f ≫ s = 𝟙 A ∧ g ≫ s = 𝟙 A := IsCoreflexivePair.common_retraction' theorem IsReflexivePair.mk' (s : B ⟶ A) (sf : s ≫ f = 𝟙 B) (sg : s ≫ g = 𝟙 B) : IsReflexivePair f g := ⟨⟨s, sf, sg⟩⟩ theorem IsCoreflexivePair.mk' (s : B ⟶ A) (fs : f ≫ s = 𝟙 A) (gs : g ≫ s = 𝟙 A) : IsCoreflexivePair f g := ⟨⟨s, fs, gs⟩⟩ /-- Get the common section for a reflexive pair. -/ noncomputable def commonSection (f g : A ⟶ B) [IsReflexivePair f g] : B ⟶ A := (IsReflexivePair.common_section f g).choose @[reassoc (attr := simp)] theorem section_comp_left (f g : A ⟶ B) [IsReflexivePair f g] : commonSection f g ≫ f = 𝟙 B := (IsReflexivePair.common_section f g).choose_spec.1 @[reassoc (attr := simp)] theorem section_comp_right (f g : A ⟶ B) [IsReflexivePair f g] : commonSection f g ≫ g = 𝟙 B := (IsReflexivePair.common_section f g).choose_spec.2 /-- Get the common retraction for a coreflexive pair. -/ noncomputable def commonRetraction (f g : A ⟶ B) [IsCoreflexivePair f g] : B ⟶ A := (IsCoreflexivePair.common_retraction f g).choose @[reassoc (attr := simp)] theorem left_comp_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] : f ≫ commonRetraction f g = 𝟙 A := (IsCoreflexivePair.common_retraction f g).choose_spec.1 @[reassoc (attr := simp)] theorem right_comp_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] : g ≫ commonRetraction f g = 𝟙 A := (IsCoreflexivePair.common_retraction f g).choose_spec.2 /-- If `f,g` is a kernel pair for some morphism `q`, then it is reflexive. -/ theorem IsKernelPair.isReflexivePair {R : C} {f g : R ⟶ A} {q : A ⟶ B} (h : IsKernelPair q f g) : IsReflexivePair f g := IsReflexivePair.mk' _ (h.lift' _ _ rfl).2.1 (h.lift' _ _ _).2.2 -- This shouldn't be an instance as it would instantly loop. /-- If `f,g` is reflexive, then `g,f` is reflexive. -/ theorem IsReflexivePair.swap [IsReflexivePair f g] : IsReflexivePair g f := IsReflexivePair.mk' _ (section_comp_right f g) (section_comp_left f g) -- This shouldn't be an instance as it would instantly loop. /-- If `f,g` is coreflexive, then `g,f` is coreflexive. -/ theorem IsCoreflexivePair.swap [IsCoreflexivePair f g] : IsCoreflexivePair g f := IsCoreflexivePair.mk' _ (right_comp_retraction f g) (left_comp_retraction f g) variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) /-- For an adjunction `F ⊣ G` with counit `ε`, the pair `(FGε_B, ε_FGB)` is reflexive. -/ instance (B : D) : IsReflexivePair (F.map (G.map (adj.counit.app B))) (adj.counit.app (F.obj (G.obj B))) := IsReflexivePair.mk' (F.map (adj.unit.app (G.obj B))) (by rw [← F.map_comp, adj.right_triangle_components] apply F.map_id) (adj.left_triangle_components _) namespace Limits variable (C) /-- `C` has reflexive coequalizers if it has coequalizers for every reflexive pair. -/ class HasReflexiveCoequalizers : Prop where has_coeq : ∀ ⦃A B : C⦄ (f g : A ⟶ B) [IsReflexivePair f g], HasCoequalizer f g /-- `C` has coreflexive equalizers if it has equalizers for every coreflexive pair. -/ class HasCoreflexiveEqualizers : Prop where has_eq : ∀ ⦃A B : C⦄ (f g : A ⟶ B) [IsCoreflexivePair f g], HasEqualizer f g attribute [instance 1] HasReflexiveCoequalizers.has_coeq attribute [instance 1] HasCoreflexiveEqualizers.has_eq theorem hasCoequalizer_of_common_section [HasReflexiveCoequalizers C] {A B : C} {f g : A ⟶ B} (r : B ⟶ A) (rf : r ≫ f = 𝟙 _) (rg : r ≫ g = 𝟙 _) : HasCoequalizer f g := by letI := IsReflexivePair.mk' r rf rg infer_instance theorem hasEqualizer_of_common_retraction [HasCoreflexiveEqualizers C] {A B : C} {f g : A ⟶ B} (r : B ⟶ A) (fr : f ≫ r = 𝟙 _) (gr : g ≫ r = 𝟙 _) : HasEqualizer f g := by letI := IsCoreflexivePair.mk' r fr gr infer_instance /-- If `C` has coequalizers, then it has reflexive coequalizers. -/ instance (priority := 100) hasReflexiveCoequalizers_of_hasCoequalizers [HasCoequalizers C] : HasReflexiveCoequalizers C where has_coeq A B f g _ := by infer_instance /-- If `C` has equalizers, then it has coreflexive equalizers. -/ instance (priority := 100) hasCoreflexiveEqualizers_of_hasEqualizers [HasEqualizers C] : HasCoreflexiveEqualizers C where has_eq A B f g _ := by infer_instance end Limits open Limits end CategoryTheory
CategoryTheory\Limits\Shapes\RegularMono.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.Lean.Expr.Basic /-! # Definitions and basic properties of regular monomorphisms and epimorphisms. A regular monomorphism is a morphism that is the equalizer of some parallel pair. We give the constructions * `IsSplitMono → RegularMono` and * `RegularMono → Mono` as well as the dual constructions for regular epimorphisms. Additionally, we give the construction * `RegularEpi ⟶ StrongEpi`. We also define classes `RegularMonoCategory` and `RegularEpiCategory` for categories in which every monomorphism or epimorphism is regular, and deduce that these categories are `StrongMonoCategory`s resp. `StrongEpiCategory`s. -/ noncomputable section namespace CategoryTheory open CategoryTheory.Limits universe v₁ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] variable {X Y : C} /-- A regular monomorphism is a morphism which is the equalizer of some parallel pair. -/ class RegularMono (f : X ⟶ Y) where /-- An object in `C` -/ Z : C -- Porting note: violates naming but what is better? /-- A map from the codomain of `f` to `Z` -/ left : Y ⟶ Z /-- Another map from the codomain of `f` to `Z` -/ right : Y ⟶ Z /-- `f` equalizes the two maps -/ w : f ≫ left = f ≫ right := by aesop_cat /-- `f` is the equalizer of the two maps -/ isLimit : IsLimit (Fork.ofι f w) attribute [reassoc] RegularMono.w /-- Every regular monomorphism is a monomorphism. -/ instance (priority := 100) RegularMono.mono (f : X ⟶ Y) [RegularMono f] : Mono f := mono_of_isLimit_fork RegularMono.isLimit instance equalizerRegular (g h : X ⟶ Y) [HasLimit (parallelPair g h)] : RegularMono (equalizer.ι g h) where Z := Y left := g right := h w := equalizer.condition g h isLimit := Fork.IsLimit.mk _ (fun s => limit.lift _ s) (by simp) fun s m w => by apply equalizer.hom_ext simp [← w] /-- Every split monomorphism is a regular monomorphism. -/ instance (priority := 100) RegularMono.ofIsSplitMono (f : X ⟶ Y) [IsSplitMono f] : RegularMono f where Z := Y left := 𝟙 Y right := retraction f ≫ f isLimit := isSplitMonoEqualizes f /-- If `f` is a regular mono, then any map `k : W ⟶ Y` equalizing `RegularMono.left` and `RegularMono.right` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def RegularMono.lift' {W : C} (f : X ⟶ Y) [RegularMono f] (k : W ⟶ Y) (h : k ≫ (RegularMono.left : Y ⟶ @RegularMono.Z _ _ _ _ f _) = k ≫ RegularMono.right) : { l : W ⟶ X // l ≫ f = k } := Fork.IsLimit.lift' RegularMono.isLimit _ h /-- The second leg of a pullback cone is a regular monomorphism if the right component is too. See also `Pullback.sndOfMono` for the basic monomorphism version, and `regularOfIsPullbackFstOfRegular` for the flipped version. -/ def regularOfIsPullbackSndOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [hr : RegularMono h] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : RegularMono g where Z := hr.Z left := k ≫ hr.left right := k ≫ hr.right w := by repeat (rw [← Category.assoc, ← eq_whisker comm]) simp only [Category.assoc, hr.w] isLimit := by apply Fork.IsLimit.mk' _ _ intro s have l₁ : (Fork.ι s ≫ k) ≫ RegularMono.left = (Fork.ι s ≫ k) ≫ hr.right := by rw [Category.assoc, s.condition, Category.assoc] obtain ⟨l, hl⟩ := Fork.IsLimit.lift' hr.isLimit _ l₁ obtain ⟨p, _, hp₂⟩ := PullbackCone.IsLimit.lift' t _ _ hl refine ⟨p, hp₂, ?_⟩ intro m w have z : m ≫ g = p ≫ g := w.trans hp₂.symm apply t.hom_ext apply (PullbackCone.mk f g comm).equalizer_ext · erw [← cancel_mono h, Category.assoc, Category.assoc, comm] simp only [← Category.assoc, eq_whisker z] · exact z /-- The first leg of a pullback cone is a regular monomorphism if the left component is too. See also `Pullback.fstOfMono` for the basic monomorphism version, and `regularOfIsPullbackSndOfRegular` for the flipped version. -/ def regularOfIsPullbackFstOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [RegularMono k] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : RegularMono f := regularOfIsPullbackSndOfRegular comm.symm (PullbackCone.flipIsLimit t) instance (priority := 100) strongMono_of_regularMono (f : X ⟶ Y) [RegularMono f] : StrongMono f := StrongMono.mk' (by intro A B z hz u v sq have : v ≫ (RegularMono.left : Y ⟶ RegularMono.Z f) = v ≫ RegularMono.right := by apply (cancel_epi z).1 repeat (rw [← Category.assoc, ← eq_whisker sq.w]) simp only [Category.assoc, RegularMono.w] obtain ⟨t, ht⟩ := RegularMono.lift' _ _ this refine CommSq.HasLift.mk' ⟨t, (cancel_mono f).1 ?_, ht⟩ simp only [Arrow.mk_hom, Arrow.homMk'_left, Category.assoc, ht, sq.w]) /-- A regular monomorphism is an isomorphism if it is an epimorphism. -/ theorem isIso_of_regularMono_of_epi (f : X ⟶ Y) [RegularMono f] [Epi f] : IsIso f := isIso_of_epi_of_strongMono _ section variable (C) /-- A regular mono category is a category in which every monomorphism is regular. -/ class RegularMonoCategory where /-- Every monomorphism is a regular monomorphism -/ regularMonoOfMono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], RegularMono f end /-- In a category in which every monomorphism is regular, we can express every monomorphism as an equalizer. This is not an instance because it would create an instance loop. -/ def regularMonoOfMono [RegularMonoCategory C] (f : X ⟶ Y) [Mono f] : RegularMono f := RegularMonoCategory.regularMonoOfMono _ instance (priority := 100) regularMonoCategoryOfSplitMonoCategory [SplitMonoCategory C] : RegularMonoCategory C where regularMonoOfMono f _ := by haveI := isSplitMono_of_mono f infer_instance instance (priority := 100) strongMonoCategory_of_regularMonoCategory [RegularMonoCategory C] : StrongMonoCategory C where strongMono_of_mono f _ := by haveI := regularMonoOfMono f infer_instance /-- A regular epimorphism is a morphism which is the coequalizer of some parallel pair. -/ class RegularEpi (f : X ⟶ Y) where /-- An object from `C` -/ W : C -- Porting note: violates naming convention but what is better? /-- Two maps to the domain of `f` -/ (left right : W ⟶ X) /-- `f` coequalizes the two maps -/ w : left ≫ f = right ≫ f := by aesop_cat /-- `f` is the coequalizer -/ isColimit : IsColimit (Cofork.ofπ f w) attribute [reassoc] RegularEpi.w /-- Every regular epimorphism is an epimorphism. -/ instance (priority := 100) RegularEpi.epi (f : X ⟶ Y) [RegularEpi f] : Epi f := epi_of_isColimit_cofork RegularEpi.isColimit instance coequalizerRegular (g h : X ⟶ Y) [HasColimit (parallelPair g h)] : RegularEpi (coequalizer.π g h) where W := X left := g right := h w := coequalizer.condition g h isColimit := Cofork.IsColimit.mk _ (fun s => colimit.desc _ s) (by simp) fun s m w => by apply coequalizer.hom_ext simp [← w] /-- A morphism which is a coequalizer for its kernel pair is a regular epi. -/ noncomputable def regularEpiOfKernelPair {B X : C} (f : X ⟶ B) [HasPullback f f] (hc : IsColimit (Cofork.ofπ f pullback.condition)) : RegularEpi f where W := pullback f f left := pullback.fst f f right := pullback.snd f f w := pullback.condition isColimit := hc /-- Every split epimorphism is a regular epimorphism. -/ instance (priority := 100) RegularEpi.ofSplitEpi (f : X ⟶ Y) [IsSplitEpi f] : RegularEpi f where W := X left := 𝟙 X right := f ≫ section_ f isColimit := isSplitEpiCoequalizes f /-- If `f` is a regular epi, then every morphism `k : X ⟶ W` coequalizing `RegularEpi.left` and `RegularEpi.right` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def RegularEpi.desc' {W : C} (f : X ⟶ Y) [RegularEpi f] (k : X ⟶ W) (h : (RegularEpi.left : RegularEpi.W f ⟶ X) ≫ k = RegularEpi.right ≫ k) : { l : Y ⟶ W // f ≫ l = k } := Cofork.IsColimit.desc' RegularEpi.isColimit _ h /-- The second leg of a pushout cocone is a regular epimorphism if the right component is too. See also `Pushout.sndOfEpi` for the basic epimorphism version, and `regularOfIsPushoutFstOfRegular` for the flipped version. -/ def regularOfIsPushoutSndOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [gr : RegularEpi g] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : RegularEpi h where W := gr.W left := gr.left ≫ f right := gr.right ≫ f w := by rw [Category.assoc, Category.assoc, comm]; simp only [← Category.assoc, eq_whisker gr.w] isColimit := by apply Cofork.IsColimit.mk' _ _ intro s have l₁ : gr.left ≫ f ≫ s.π = gr.right ≫ f ≫ s.π := by rw [← Category.assoc, ← Category.assoc, s.condition] obtain ⟨l, hl⟩ := Cofork.IsColimit.desc' gr.isColimit (f ≫ Cofork.π s) l₁ obtain ⟨p, hp₁, _⟩ := PushoutCocone.IsColimit.desc' t _ _ hl.symm refine ⟨p, hp₁, ?_⟩ intro m w have z := w.trans hp₁.symm apply t.hom_ext apply (PushoutCocone.mk _ _ comm).coequalizer_ext · exact z · erw [← cancel_epi g, ← Category.assoc, ← eq_whisker comm] erw [← Category.assoc, ← eq_whisker comm] dsimp at z; simp only [Category.assoc, z] /-- The first leg of a pushout cocone is a regular epimorphism if the left component is too. See also `Pushout.fstOfEpi` for the basic epimorphism version, and `regularOfIsPushoutSndOfRegular` for the flipped version. -/ def regularOfIsPushoutFstOfRegular {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [RegularEpi f] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : RegularEpi k := regularOfIsPushoutSndOfRegular comm.symm (PushoutCocone.flipIsColimit t) instance (priority := 100) strongEpi_of_regularEpi (f : X ⟶ Y) [RegularEpi f] : StrongEpi f := StrongEpi.mk' (by intro A B z hz u v sq have : (RegularEpi.left : RegularEpi.W f ⟶ X) ≫ u = RegularEpi.right ≫ u := by apply (cancel_mono z).1 simp only [Category.assoc, sq.w, RegularEpi.w_assoc] obtain ⟨t, ht⟩ := RegularEpi.desc' f u this exact CommSq.HasLift.mk' ⟨t, ht, (cancel_epi f).1 (by simp only [← Category.assoc, ht, ← sq.w, Arrow.mk_hom, Arrow.homMk'_right])⟩) /-- A regular epimorphism is an isomorphism if it is a monomorphism. -/ theorem isIso_of_regularEpi_of_mono (f : X ⟶ Y) [RegularEpi f] [Mono f] : IsIso f := isIso_of_mono_of_strongEpi _ section variable (C) /-- A regular epi category is a category in which every epimorphism is regular. -/ class RegularEpiCategory where /-- Everyone epimorphism is a regular epimorphism -/ regularEpiOfEpi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], RegularEpi f end /-- In a category in which every epimorphism is regular, we can express every epimorphism as a coequalizer. This is not an instance because it would create an instance loop. -/ def regularEpiOfEpi [RegularEpiCategory C] (f : X ⟶ Y) [Epi f] : RegularEpi f := RegularEpiCategory.regularEpiOfEpi _ instance (priority := 100) regularEpiCategoryOfSplitEpiCategory [SplitEpiCategory C] : RegularEpiCategory C where regularEpiOfEpi f _ := by haveI := isSplitEpi_of_epi f infer_instance instance (priority := 100) strongEpiCategory_of_regularEpiCategory [RegularEpiCategory C] : StrongEpiCategory C where strongEpi_of_epi f _ := by haveI := regularEpiOfEpi f infer_instance end CategoryTheory
CategoryTheory\Limits\Shapes\SingleObj.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.SingleObj import Mathlib.GroupTheory.GroupAction.Basic /-! # (Co)limits of functors out of `SingleObj M` We characterise (co)limits of shape `SingleObj M`. Currently only in the category of types. ## Main results * `SingleObj.Types.limitEquivFixedPoints`: The limit of `J : SingleObj G ⥤ Type u` is the fixed points of `J.obj (SingleObj.star G)` under the induced action. * `SingleObj.Types.colimitEquivQuotient`: The colimit of `J : SingleObj G ⥤ Type u` is the quotient of `J.obj (SingleObj.star G)` by the induced action. -/ universe u v namespace CategoryTheory namespace Limits namespace SingleObj variable {M G : Type v} [Monoid M] [Group G] /-- The induced `G`-action on the target of `J : SingleObj G ⥤ Type u`. -/ instance (J : SingleObj M ⥤ Type u) : MulAction M (J.obj (SingleObj.star M)) where smul g x := J.map g x one_smul x := by show J.map (𝟙 _) x = x simp only [FunctorToTypes.map_id_apply] mul_smul g h x := by show J.map (g * h) x = (J.map h ≫ J.map g) x rw [← SingleObj.comp_as_mul] · simp only [FunctorToTypes.map_comp_apply, types_comp_apply] rfl section Limits variable (J : SingleObj M ⥤ Type u) /-- The equivalence between sections of `J : SingleObj M ⥤ Type u` and fixed points of the induced action on `J.obj (SingleObj.star M)`. -/ @[simps] def Types.sections.equivFixedPoints : J.sections ≃ MulAction.fixedPoints M (J.obj (SingleObj.star M)) where toFun s := ⟨s.val _, s.property⟩ invFun p := ⟨fun _ ↦ p.val, p.property⟩ left_inv _ := rfl right_inv _ := rfl /-- The limit of `J : SingleObj M ⥤ Type u` is equivalent to the fixed points of the induced action on `J.obj (SingleObj.star M)`. -/ @[simps!] noncomputable def Types.limitEquivFixedPoints : limit J ≃ MulAction.fixedPoints M (J.obj (SingleObj.star M)) := (Types.limitEquivSections J).trans (Types.sections.equivFixedPoints J) end Limits section Colimits variable {G : Type v} [Group G] (J : SingleObj G ⥤ Type u) /-- The relation used to construct colimits in types for `J : SingleObj G ⥤ Type u` is equivalent to the `MulAction.orbitRel` equivalence relation on `J.obj (SingleObj.star G)`. -/ lemma Types.Quot.Rel.iff_orbitRel (x y : J.obj (SingleObj.star G)) : Types.Quot.Rel J ⟨SingleObj.star G, x⟩ ⟨SingleObj.star G, y⟩ ↔ Setoid.Rel (MulAction.orbitRel G (J.obj (SingleObj.star G))) x y := by have h (g : G) : y = g • x ↔ g • x = y := ⟨symm, symm⟩ conv => rhs; rw [Setoid.comm'] show (∃ g : G, y = g • x) ↔ (∃ g : G, g • x = y) conv => lhs; simp only [h] /-- The explicit quotient construction of the colimit of `J : SingleObj G ⥤ Type u` is equivalent to the quotient of `J.obj (SingleObj.star G)` by the induced action. -/ @[simps] def Types.Quot.equivOrbitRelQuotient : Types.Quot J ≃ MulAction.orbitRel.Quotient G (J.obj (SingleObj.star G)) where toFun := Quot.lift (fun p => ⟦p.2⟧) <| fun a b h => Quotient.sound <| (Types.Quot.Rel.iff_orbitRel J a.2 b.2).mp h invFun := Quot.lift (fun x => Quot.mk _ ⟨SingleObj.star G, x⟩) <| fun a b h => Quot.sound <| (Types.Quot.Rel.iff_orbitRel J a b).mpr h left_inv := fun x => Quot.inductionOn x (fun _ ↦ rfl) right_inv := fun x => Quot.inductionOn x (fun _ ↦ rfl) /-- The colimit of `J : SingleObj G ⥤ Type u` is equivalent to the quotient of `J.obj (SingleObj.star G)` by the induced action. -/ @[simps!] noncomputable def Types.colimitEquivQuotient : colimit J ≃ MulAction.orbitRel.Quotient G (J.obj (SingleObj.star G)) := (Types.colimitEquivQuot J).trans (Types.Quot.equivOrbitRelQuotient J) end Colimits end SingleObj end Limits end CategoryTheory
CategoryTheory\Limits\Shapes\SplitCoequalizer.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers /-! # Split coequalizers We define what it means for a triple of morphisms `f g : X ⟶ Y`, `π : Y ⟶ Z` to be a split coequalizer: there is a section `s` of `π` and a section `t` of `g`, which additionally satisfy `t ≫ f = π ≫ s`. In addition, we show that every split coequalizer is a coequalizer (`CategoryTheory.IsSplitCoequalizer.isCoequalizer`) and absolute (`CategoryTheory.IsSplitCoequalizer.map`) A pair `f g : X ⟶ Y` has a split coequalizer if there is a `Z` and `π : Y ⟶ Z` making `f,g,π` a split coequalizer. A pair `f g : X ⟶ Y` has a `G`-split coequalizer if `G f, G g` has a split coequalizer. These definitions and constructions are useful in particular for the monadicity theorems. This file has been adapted to `Mathlib.CategoryTheory.Limits.Shapes.SplitEqualizer`. Please try to keep them in sync. -/ namespace CategoryTheory universe v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {X Y : C} (f g : X ⟶ Y) /-- A split coequalizer diagram consists of morphisms f π X ⇉ Y → Z g satisfying `f ≫ π = g ≫ π` together with morphisms t s X ← Y ← Z satisfying `s ≫ π = 𝟙 Z`, `t ≫ g = 𝟙 Y` and `t ≫ f = π ≫ s`. The name "coequalizer" is appropriate, since any split coequalizer is a coequalizer, see `CategoryTheory.IsSplitCoequalizer.isCoequalizer`. Split coequalizers are also absolute, since a functor preserves all the structure above. -/ structure IsSplitCoequalizer {Z : C} (π : Y ⟶ Z) where /-- A map from the coequalizer to `Y` -/ rightSection : Z ⟶ Y /-- A map in the opposite direction to `f` and `g` -/ leftSection : Y ⟶ X /-- Composition of `π` with `f` and with `g` agree -/ condition : f ≫ π = g ≫ π := by aesop_cat /-- `rightSection` splits `π` -/ rightSection_π : rightSection ≫ π = 𝟙 Z := by aesop_cat /-- `leftSection` splits `g` -/ leftSection_bottom : leftSection ≫ g = 𝟙 Y := by aesop_cat /-- `leftSection` composed with `f` is `pi` composed with `rightSection` -/ leftSection_top : leftSection ≫ f = π ≫ rightSection := by aesop_cat instance {X : C} : Inhabited (IsSplitCoequalizer (𝟙 X) (𝟙 X) (𝟙 X)) where default := { rightSection := 𝟙 X, leftSection := 𝟙 X } open IsSplitCoequalizer attribute [reassoc] condition attribute [reassoc (attr := simp)] rightSection_π leftSection_bottom leftSection_top variable {f g} /-- Split coequalizers are absolute: they are preserved by any functor. -/ @[simps] def IsSplitCoequalizer.map {Z : C} {π : Y ⟶ Z} (q : IsSplitCoequalizer f g π) (F : C ⥤ D) : IsSplitCoequalizer (F.map f) (F.map g) (F.map π) where rightSection := F.map q.rightSection leftSection := F.map q.leftSection condition := by rw [← F.map_comp, q.condition, F.map_comp] rightSection_π := by rw [← F.map_comp, q.rightSection_π, F.map_id] leftSection_bottom := by rw [← F.map_comp, q.leftSection_bottom, F.map_id] leftSection_top := by rw [← F.map_comp, q.leftSection_top, F.map_comp] section open Limits /-- A split coequalizer clearly induces a cofork. -/ @[simps! pt] def IsSplitCoequalizer.asCofork {Z : C} {h : Y ⟶ Z} (t : IsSplitCoequalizer f g h) : Cofork f g := Cofork.ofπ h t.condition @[simp] theorem IsSplitCoequalizer.asCofork_π {Z : C} {h : Y ⟶ Z} (t : IsSplitCoequalizer f g h) : t.asCofork.π = h := rfl /-- The cofork induced by a split coequalizer is a coequalizer, justifying the name. In some cases it is more convenient to show a given cofork is a coequalizer by showing it is split. -/ def IsSplitCoequalizer.isCoequalizer {Z : C} {h : Y ⟶ Z} (t : IsSplitCoequalizer f g h) : IsColimit t.asCofork := Cofork.IsColimit.mk' _ fun s => ⟨t.rightSection ≫ s.π, by dsimp rw [← t.leftSection_top_assoc, s.condition, t.leftSection_bottom_assoc], fun hm => by simp [← hm]⟩ end variable (f g) /-- The pair `f,g` is a split pair if there is an `h : Y ⟶ Z` so that `f, g, h` forms a split coequalizer in `C`. -/ class HasSplitCoequalizer : Prop where /-- There is some split coequalizer -/ splittable : ∃ (Z : C) (h : Y ⟶ Z), Nonempty (IsSplitCoequalizer f g h) /-- The pair `f,g` is a `G`-split pair if there is an `h : G Y ⟶ Z` so that `G f, G g, h` forms a split coequalizer in `D`. -/ abbrev Functor.IsSplitPair : Prop := HasSplitCoequalizer (G.map f) (G.map g) /-- Get the coequalizer object from the typeclass `IsSplitPair`. -/ noncomputable def HasSplitCoequalizer.coequalizerOfSplit [HasSplitCoequalizer f g] : C := (splittable (f := f) (g := g)).choose /-- Get the coequalizer morphism from the typeclass `IsSplitPair`. -/ noncomputable def HasSplitCoequalizer.coequalizerπ [HasSplitCoequalizer f g] : Y ⟶ HasSplitCoequalizer.coequalizerOfSplit f g := (splittable (f := f) (g := g)).choose_spec.choose /-- The coequalizer morphism `coequalizeπ` gives a split coequalizer on `f,g`. -/ noncomputable def HasSplitCoequalizer.isSplitCoequalizer [HasSplitCoequalizer f g] : IsSplitCoequalizer f g (HasSplitCoequalizer.coequalizerπ f g) := Classical.choice (splittable (f := f) (g := g)).choose_spec.choose_spec /-- If `f, g` is split, then `G f, G g` is split. -/ instance map_is_split_pair [HasSplitCoequalizer f g] : HasSplitCoequalizer (G.map f) (G.map g) where splittable := ⟨_, _, ⟨IsSplitCoequalizer.map (HasSplitCoequalizer.isSplitCoequalizer f g) _⟩⟩ namespace Limits /-- If a pair has a split coequalizer, it has a coequalizer. -/ instance (priority := 1) hasCoequalizer_of_hasSplitCoequalizer [HasSplitCoequalizer f g] : HasCoequalizer f g := HasColimit.mk ⟨_, (HasSplitCoequalizer.isSplitCoequalizer f g).isCoequalizer⟩ end Limits end CategoryTheory
CategoryTheory\Limits\Shapes\SplitEqualizer.lean
/- Copyright (c) 2024 Jack McKoen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jack McKoen -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers /-! # Split Equalizers We define what it means for a triple of morphisms `f g : X ⟶ Y`, `ι : W ⟶ X` to be a split equalizer: there is a retraction `r` of `ι` and a retraction `t` of `g`, which additionally satisfy `t ≫ f = r ≫ ι`. In addition, we show that every split equalizer is an equalizer (`CategoryTheory.IsSplitEqualizer.isEqualizer`) and absolute (`CategoryTheory.IsSplitEqualizer.map`) A pair `f g : X ⟶ Y` has a split equalizer if there is a `W` and `ι : W ⟶ X` making `f,g,ι` a split equalizer. A pair `f g : X ⟶ Y` has a `G`-split equalizer if `G f, G g` has a split equalizer. These definitions and constructions are useful in particular for the comonadicity theorems. This file was adapted from `Mathlib.CategoryTheory.Limits.Shapes.SplitCoequalizer`. Please try to keep them in sync. -/ namespace CategoryTheory universe v v₂ u u₂ variable {C : Type u} [Category.{v} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {X Y : C} (f g : X ⟶ Y) /-- A split equalizer diagram consists of morphisms ``` ι f W → X ⇉ Y g ``` satisfying `ι ≫ f = ι ≫ g` together with morphisms ``` r t W ← X ← Y ``` satisfying `ι ≫ r = 𝟙 W`, `g ≫ t = 𝟙 X` and `f ≫ t = r ≫ ι`. The name "equalizer" is appropriate, since any split equalizer is a equalizer, see `CategoryTheory.IsSplitEqualizer.isEqualizer`. Split equalizers are also absolute, since a functor preserves all the structure above. -/ structure IsSplitEqualizer {W : C} (ι : W ⟶ X) where /-- A map from `X` to the equalizer -/ leftRetraction : X ⟶ W /-- A map in the opposite direction to `f` and `g` -/ rightRetraction : Y ⟶ X /-- Composition of `ι` with `f` and with `g` agree -/ condition : ι ≫ f = ι ≫ g := by aesop_cat /-- `leftRetraction` splits `ι` -/ ι_leftRetraction : ι ≫ leftRetraction = 𝟙 W := by aesop_cat /-- `rightRetraction` splits `g` -/ bottom_rightRetraction : g ≫ rightRetraction = 𝟙 X := by aesop_cat /-- `f` composed with `rightRetraction` is `leftRetraction` composed with `ι` -/ top_rightRetraction : f ≫ rightRetraction = leftRetraction ≫ ι := by aesop_cat instance {X : C} : Inhabited (IsSplitEqualizer (𝟙 X) (𝟙 X) (𝟙 X)) where default := { leftRetraction := 𝟙 X, rightRetraction := 𝟙 X } open IsSplitEqualizer attribute [reassoc] condition attribute [reassoc (attr := simp)] ι_leftRetraction bottom_rightRetraction top_rightRetraction variable {f g} /-- Split equalizers are absolute: they are preserved by any functor. -/ @[simps] def IsSplitEqualizer.map {W : C} {ι : W ⟶ X} (q : IsSplitEqualizer f g ι) (F : C ⥤ D) : IsSplitEqualizer (F.map f) (F.map g) (F.map ι) where leftRetraction := F.map q.leftRetraction rightRetraction := F.map q.rightRetraction condition := by rw [← F.map_comp, q.condition, F.map_comp] ι_leftRetraction := by rw [← F.map_comp, q.ι_leftRetraction, F.map_id] bottom_rightRetraction := by rw [← F.map_comp, q.bottom_rightRetraction, F.map_id] top_rightRetraction := by rw [← F.map_comp, q.top_rightRetraction, F.map_comp] section open Limits /-- A split equalizer clearly induces a fork. -/ @[simps! pt] def IsSplitEqualizer.asFork {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) : Fork f g := Fork.ofι h t.condition @[simp] theorem IsSplitEqualizer.asFork_ι {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) : t.asFork.ι = h := rfl /-- The fork induced by a split equalizer is an equalizer, justifying the name. In some cases it is more convenient to show a given fork is an equalizer by showing it is split. -/ def IsSplitEqualizer.isEqualizer {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) : IsLimit t.asFork := Fork.IsLimit.mk' _ fun s => ⟨ s.ι ≫ t.leftRetraction, by simp [- top_rightRetraction, ← t.top_rightRetraction, s.condition_assoc], fun hm => by simp [← hm] ⟩ end variable (f g) /-- The pair `f,g` is a cosplit pair if there is an `h : W ⟶ X` so that `f, g, h` forms a split equalizer in `C`. -/ class HasSplitEqualizer : Prop where /-- There is some split equalizer -/ splittable : ∃ (W : C) (h : W ⟶ X), Nonempty (IsSplitEqualizer f g h) /-- The pair `f,g` is a `G`-cosplit pair if there is an `h : W ⟶ G X` so that `G f, G g, h` forms a split equalizer in `D`. -/ abbrev Functor.IsCosplitPair : Prop := HasSplitEqualizer (G.map f) (G.map g) /-- Get the equalizer object from the typeclass `IsCosplitPair`. -/ noncomputable def HasSplitEqualizer.equalizerOfSplit [HasSplitEqualizer f g] : C := (splittable (f := f) (g := g)).choose /-- Get the equalizer morphism from the typeclass `IsCosplitPair`. -/ noncomputable def HasSplitEqualizer.equalizerι [HasSplitEqualizer f g] : HasSplitEqualizer.equalizerOfSplit f g ⟶ X := (splittable (f := f) (g := g)).choose_spec.choose /-- The equalizer morphism `equalizerι` gives a split equalizer on `f,g`. -/ noncomputable def HasSplitEqualizer.isSplitEqualizer [HasSplitEqualizer f g] : IsSplitEqualizer f g (HasSplitEqualizer.equalizerι f g) := Classical.choice (splittable (f := f) (g := g)).choose_spec.choose_spec /-- If `f, g` is cosplit, then `G f, G g` is cosplit. -/ instance map_is_cosplit_pair [HasSplitEqualizer f g] : HasSplitEqualizer (G.map f) (G.map g) where splittable := ⟨_, _, ⟨IsSplitEqualizer.map (HasSplitEqualizer.isSplitEqualizer f g) _⟩⟩ namespace Limits /-- If a pair has a split equalizer, it has a equalizer. -/ instance (priority := 1) hasEqualizer_of_hasSplitEqualizer [HasSplitEqualizer f g] : HasEqualizer f g := HasLimit.mk ⟨_, (HasSplitEqualizer.isSplitEqualizer f g).isEqualizer⟩ end Limits end CategoryTheory
CategoryTheory\Limits\Shapes\StrictInitial.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # Strict initial objects This file sets up the basic theory of strict initial objects: initial objects where every morphism to it is an isomorphism. This generalises a property of the empty set in the category of sets: namely that the only function to the empty set is from itself. We say `C` has strict initial objects if every initial object is strict, ie given any morphism `f : A ⟶ I` where `I` is initial, then `f` is an isomorphism. Strictly speaking, this says that *any* initial object must be strict, rather than that strict initial objects exist, which turns out to be a more useful notion to formalise. If the binary product of `X` with a strict initial object exists, it is also initial. To show a category `C` with an initial object has strict initial objects, the most convenient way is to show any morphism to the (chosen) initial object is an isomorphism and use `hasStrictInitialObjects_of_initial_is_strict`. The dual notion (strict terminal objects) occurs much less frequently in practice so is ignored. ## TODO * Construct examples of this: `Type*`, `TopCat`, `Groupoid`, simplicial types, posets. * Construct the bottom element of the subobject lattice given strict initials. * Show cartesian closed categories have strict initials ## References * https://ncatlab.org/nlab/show/strict+initial+object -/ universe v u namespace CategoryTheory namespace Limits open Category variable (C : Type u) [Category.{v} C] section StrictInitial /-- We say `C` has strict initial objects if every initial object is strict, ie given any morphism `f : A ⟶ I` where `I` is initial, then `f` is an isomorphism. Strictly speaking, this says that *any* initial object must be strict, rather than that strict initial objects exist. -/ class HasStrictInitialObjects : Prop where out : ∀ {I A : C} (f : A ⟶ I), IsInitial I → IsIso f variable {C} section variable [HasStrictInitialObjects C] {I : C} theorem IsInitial.isIso_to (hI : IsInitial I) {A : C} (f : A ⟶ I) : IsIso f := HasStrictInitialObjects.out f hI theorem IsInitial.strict_hom_ext (hI : IsInitial I) {A : C} (f g : A ⟶ I) : f = g := by haveI := hI.isIso_to f haveI := hI.isIso_to g exact eq_of_inv_eq_inv (hI.hom_ext (inv f) (inv g)) theorem IsInitial.subsingleton_to (hI : IsInitial I) {A : C} : Subsingleton (A ⟶ I) := ⟨hI.strict_hom_ext⟩ /-- If `X ⟶ Y` with `Y` being a strict initial object, then `X` is also an initial object. -/ noncomputable def IsInitial.ofStrict {X Y : C} (f : X ⟶ Y) (hY : IsInitial Y) : IsInitial X := letI := hY.isIso_to f hY.ofIso (asIso f).symm instance (priority := 100) initial_mono_of_strict_initial_objects : InitialMonoClass C where isInitial_mono_from := fun _ hI => { right_cancellation := fun _ _ _ => hI.strict_hom_ext _ _ } /-- If `I` is initial, then `X ⨯ I` is isomorphic to it. -/ @[simps! hom] noncomputable def mulIsInitial (X : C) [HasBinaryProduct X I] (hI : IsInitial I) : X ⨯ I ≅ I := by have := hI.isIso_to (prod.snd : X ⨯ I ⟶ I) exact asIso prod.snd @[simp] theorem mulIsInitial_inv (X : C) [HasBinaryProduct X I] (hI : IsInitial I) : (mulIsInitial X hI).inv = hI.to _ := hI.hom_ext _ _ /-- If `I` is initial, then `I ⨯ X` is isomorphic to it. -/ @[simps! hom] noncomputable def isInitialMul (X : C) [HasBinaryProduct I X] (hI : IsInitial I) : I ⨯ X ≅ I := by have := hI.isIso_to (prod.fst : I ⨯ X ⟶ I) exact asIso prod.fst @[simp] theorem isInitialMul_inv (X : C) [HasBinaryProduct I X] (hI : IsInitial I) : (isInitialMul X hI).inv = hI.to _ := hI.hom_ext _ _ variable [HasInitial C] instance initial_isIso_to {A : C} (f : A ⟶ ⊥_ C) : IsIso f := initialIsInitial.isIso_to _ @[ext] theorem initial.strict_hom_ext {A : C} (f g : A ⟶ ⊥_ C) : f = g := initialIsInitial.strict_hom_ext _ _ theorem initial.subsingleton_to {A : C} : Subsingleton (A ⟶ ⊥_ C) := initialIsInitial.subsingleton_to /-- The product of `X` with an initial object in a category with strict initial objects is itself initial. This is the generalisation of the fact that `X × Empty ≃ Empty` for types (or `n * 0 = 0`). -/ @[simps! hom] noncomputable def mulInitial (X : C) [HasBinaryProduct X (⊥_ C)] : X ⨯ ⊥_ C ≅ ⊥_ C := mulIsInitial _ initialIsInitial @[simp] theorem mulInitial_inv (X : C) [HasBinaryProduct X (⊥_ C)] : (mulInitial X).inv = initial.to _ := Subsingleton.elim _ _ /-- The product of `X` with an initial object in a category with strict initial objects is itself initial. This is the generalisation of the fact that `Empty × X ≃ Empty` for types (or `0 * n = 0`). -/ @[simps! hom] noncomputable def initialMul (X : C) [HasBinaryProduct (⊥_ C) X] : (⊥_ C) ⨯ X ≅ ⊥_ C := isInitialMul _ initialIsInitial @[simp] theorem initialMul_inv (X : C) [HasBinaryProduct (⊥_ C) X] : (initialMul X).inv = initial.to _ := Subsingleton.elim _ _ end /-- If `C` has an initial object such that every morphism *to* it is an isomorphism, then `C` has strict initial objects. -/ theorem hasStrictInitialObjects_of_initial_is_strict [HasInitial C] (h : ∀ (A) (f : A ⟶ ⊥_ C), IsIso f) : HasStrictInitialObjects C := { out := fun {I A} f hI => haveI := h A (f ≫ hI.to _) ⟨⟨hI.to _ ≫ inv (f ≫ hI.to (⊥_ C)), by rw [← assoc, IsIso.hom_inv_id], hI.hom_ext _ _⟩⟩ } end StrictInitial section StrictTerminal /-- We say `C` has strict terminal objects if every terminal object is strict, ie given any morphism `f : I ⟶ A` where `I` is terminal, then `f` is an isomorphism. Strictly speaking, this says that *any* terminal object must be strict, rather than that strict terminal objects exist. -/ class HasStrictTerminalObjects : Prop where out : ∀ {I A : C} (f : I ⟶ A), IsTerminal I → IsIso f variable {C} section variable [HasStrictTerminalObjects C] {I : C} theorem IsTerminal.isIso_from (hI : IsTerminal I) {A : C} (f : I ⟶ A) : IsIso f := HasStrictTerminalObjects.out f hI theorem IsTerminal.strict_hom_ext (hI : IsTerminal I) {A : C} (f g : I ⟶ A) : f = g := by haveI := hI.isIso_from f haveI := hI.isIso_from g exact eq_of_inv_eq_inv (hI.hom_ext (inv f) (inv g)) /-- If `X ⟶ Y` with `Y` being a strict terminal object, then `X` is also an terminal object. -/ noncomputable def IsTerminal.ofStrict {X Y : C} (f : X ⟶ Y) (hY : IsTerminal X) : IsTerminal Y := letI := hY.isIso_from f hY.ofIso (asIso f) theorem IsTerminal.subsingleton_to (hI : IsTerminal I) {A : C} : Subsingleton (I ⟶ A) := ⟨hI.strict_hom_ext⟩ variable {J : Type v} [SmallCategory J] /-- If all but one object in a diagram is strict terminal, then the limit is isomorphic to the said object via `limit.π`. -/ theorem limit_π_isIso_of_is_strict_terminal (F : J ⥤ C) [HasLimit F] (i : J) (H : ∀ (j) (_ : j ≠ i), IsTerminal (F.obj j)) [Subsingleton (i ⟶ i)] : IsIso (limit.π F i) := by classical refine ⟨⟨limit.lift _ ⟨_, ⟨?_, ?_⟩⟩, ?_, ?_⟩⟩ · exact fun j => dite (j = i) (fun h => eqToHom (by cases h; rfl)) fun h => (H _ h).from _ · intro j k f split_ifs with h h_1 h_1 · cases h cases h_1 obtain rfl : f = 𝟙 _ := Subsingleton.elim _ _ simp · cases h erw [Category.comp_id] haveI : IsIso (F.map f) := (H _ h_1).isIso_from _ rw [← IsIso.comp_inv_eq] apply (H _ h_1).hom_ext · cases h_1 apply (H _ h).hom_ext · apply (H _ h).hom_ext · ext rw [assoc, limit.lift_π] dsimp only split_ifs with h · cases h rw [id_comp, eqToHom_refl] exact comp_id _ · apply (H _ h).hom_ext · rw [limit.lift_π] simp variable [HasTerminal C] instance terminal_isIso_from {A : C} (f : ⊤_ C ⟶ A) : IsIso f := terminalIsTerminal.isIso_from _ @[ext] theorem terminal.strict_hom_ext {A : C} (f g : ⊤_ C ⟶ A) : f = g := terminalIsTerminal.strict_hom_ext _ _ theorem terminal.subsingleton_to {A : C} : Subsingleton (⊤_ C ⟶ A) := terminalIsTerminal.subsingleton_to end /-- If `C` has an object such that every morphism *from* it is an isomorphism, then `C` has strict terminal objects. -/ theorem hasStrictTerminalObjects_of_terminal_is_strict (I : C) (h : ∀ (A) (f : I ⟶ A), IsIso f) : HasStrictTerminalObjects C := { out := fun {I' A} f hI' => haveI := h A (hI'.from _ ≫ f) ⟨⟨inv (hI'.from I ≫ f) ≫ hI'.from I, hI'.hom_ext _ _, by rw [assoc, IsIso.inv_hom_id]⟩⟩ } end StrictTerminal end Limits end CategoryTheory
CategoryTheory\Limits\Shapes\StrongEpi.lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Balanced import Mathlib.CategoryTheory.LiftingProperties.Basic /-! # Strong epimorphisms In this file, we define strong epimorphisms. A strong epimorphism is an epimorphism `f` which has the (unique) left lifting property with respect to monomorphisms. Similarly, a strong monomorphisms in a monomorphism which has the (unique) right lifting property with respect to epimorphisms. ## Main results Besides the definition, we show that * the composition of two strong epimorphisms is a strong epimorphism, * if `f ≫ g` is a strong epimorphism, then so is `g`, * if `f` is both a strong epimorphism and a monomorphism, then it is an isomorphism We also define classes `StrongMonoCategory` and `StrongEpiCategory` for categories in which every monomorphism or epimorphism is strong, and deduce that these categories are balanced. ## TODO Show that the dual of a strong epimorphism is a strong monomorphism, and vice versa. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] variable {P Q : C} /-- A strong epimorphism `f` is an epimorphism which has the left lifting property with respect to monomorphisms. -/ class StrongEpi (f : P ⟶ Q) : Prop where /-- The epimorphism condition on `f` -/ epi : Epi f /-- The left lifting property with respect to all monomorphism -/ llp : ∀ ⦃X Y : C⦄ (z : X ⟶ Y) [Mono z], HasLiftingProperty f z theorem StrongEpi.mk' {f : P ⟶ Q} [Epi f] (hf : ∀ (X Y : C) (z : X ⟶ Y) (_ : Mono z) (u : P ⟶ X) (v : Q ⟶ Y) (sq : CommSq u f z v), sq.HasLift) : StrongEpi f := { epi := inferInstance llp := fun {X Y} z hz => ⟨fun {u v} sq => hf X Y z hz u v sq⟩ } /-- A strong monomorphism `f` is a monomorphism which has the right lifting property with respect to epimorphisms. -/ class StrongMono (f : P ⟶ Q) : Prop where /-- The monomorphism condition on `f` -/ mono : Mono f /-- The right lifting property with respect to all epimorphisms -/ rlp : ∀ ⦃X Y : C⦄ (z : X ⟶ Y) [Epi z], HasLiftingProperty z f theorem StrongMono.mk' {f : P ⟶ Q} [Mono f] (hf : ∀ (X Y : C) (z : X ⟶ Y) (_ : Epi z) (u : X ⟶ P) (v : Y ⟶ Q) (sq : CommSq u z f v), sq.HasLift) : StrongMono f where mono := inferInstance rlp := fun {X Y} z hz => ⟨fun {u v} sq => hf X Y z hz u v sq⟩ attribute [instance 100] StrongEpi.llp attribute [instance 100] StrongMono.rlp instance (priority := 100) epi_of_strongEpi (f : P ⟶ Q) [StrongEpi f] : Epi f := StrongEpi.epi instance (priority := 100) mono_of_strongMono (f : P ⟶ Q) [StrongMono f] : Mono f := StrongMono.mono section variable {R : C} (f : P ⟶ Q) (g : Q ⟶ R) /-- The composition of two strong epimorphisms is a strong epimorphism. -/ theorem strongEpi_comp [StrongEpi f] [StrongEpi g] : StrongEpi (f ≫ g) := { epi := epi_comp _ _ llp := by intros infer_instance } /-- The composition of two strong monomorphisms is a strong monomorphism. -/ theorem strongMono_comp [StrongMono f] [StrongMono g] : StrongMono (f ≫ g) := { mono := mono_comp _ _ rlp := by intros infer_instance } /-- If `f ≫ g` is a strong epimorphism, then so is `g`. -/ theorem strongEpi_of_strongEpi [StrongEpi (f ≫ g)] : StrongEpi g := { epi := epi_of_epi f g llp := fun {X Y} z _ => by constructor intro u v sq have h₀ : (f ≫ u) ≫ z = (f ≫ g) ≫ v := by simp only [Category.assoc, sq.w] exact CommSq.HasLift.mk' ⟨(CommSq.mk h₀).lift, by simp only [← cancel_mono z, Category.assoc, CommSq.fac_right, sq.w], by simp⟩ } /-- If `f ≫ g` is a strong monomorphism, then so is `f`. -/ theorem strongMono_of_strongMono [StrongMono (f ≫ g)] : StrongMono f := { mono := mono_of_mono f g rlp := fun {X Y} z => by intros constructor intro u v sq have h₀ : u ≫ f ≫ g = z ≫ v ≫ g := by rw [← Category.assoc, eq_whisker sq.w, Category.assoc] exact CommSq.HasLift.mk' ⟨(CommSq.mk h₀).lift, by simp, by simp [← cancel_epi z, sq.w]⟩ } /-- An isomorphism is in particular a strong epimorphism. -/ instance (priority := 100) strongEpi_of_isIso [IsIso f] : StrongEpi f where epi := by infer_instance llp {X Y} z := HasLiftingProperty.of_left_iso _ _ /-- An isomorphism is in particular a strong monomorphism. -/ instance (priority := 100) strongMono_of_isIso [IsIso f] : StrongMono f where mono := by infer_instance rlp {X Y} z := HasLiftingProperty.of_right_iso _ _ theorem StrongEpi.of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) [h : StrongEpi f] : StrongEpi g := { epi := by rw [Arrow.iso_w' e] haveI := epi_comp f e.hom.right apply epi_comp llp := fun {X Y} z => by intro apply HasLiftingProperty.of_arrow_iso_left e z } theorem StrongMono.of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) [h : StrongMono f] : StrongMono g := { mono := by rw [Arrow.iso_w' e] haveI := mono_comp f e.hom.right apply mono_comp rlp := fun {X Y} z => by intro apply HasLiftingProperty.of_arrow_iso_right z e } theorem StrongEpi.iff_of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) : StrongEpi f ↔ StrongEpi g := by constructor <;> intro exacts [StrongEpi.of_arrow_iso e, StrongEpi.of_arrow_iso e.symm] theorem StrongMono.iff_of_arrow_iso {A B A' B' : C} {f : A ⟶ B} {g : A' ⟶ B'} (e : Arrow.mk f ≅ Arrow.mk g) : StrongMono f ↔ StrongMono g := by constructor <;> intro exacts [StrongMono.of_arrow_iso e, StrongMono.of_arrow_iso e.symm] end /-- A strong epimorphism that is a monomorphism is an isomorphism. -/ theorem isIso_of_mono_of_strongEpi (f : P ⟶ Q) [Mono f] [StrongEpi f] : IsIso f := ⟨⟨(CommSq.mk (show 𝟙 P ≫ f = f ≫ 𝟙 Q by simp)).lift, by aesop_cat⟩⟩ /-- A strong monomorphism that is an epimorphism is an isomorphism. -/ theorem isIso_of_epi_of_strongMono (f : P ⟶ Q) [Epi f] [StrongMono f] : IsIso f := ⟨⟨(CommSq.mk (show 𝟙 P ≫ f = f ≫ 𝟙 Q by simp)).lift, by aesop_cat⟩⟩ section variable (C) /-- A strong epi category is a category in which every epimorphism is strong. -/ class StrongEpiCategory : Prop where /-- A strong epi category is a category in which every epimorphism is strong. -/ strongEpi_of_epi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], StrongEpi f /-- A strong mono category is a category in which every monomorphism is strong. -/ class StrongMonoCategory : Prop where /-- A strong mono category is a category in which every monomorphism is strong. -/ strongMono_of_mono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], StrongMono f end theorem strongEpi_of_epi [StrongEpiCategory C] (f : P ⟶ Q) [Epi f] : StrongEpi f := StrongEpiCategory.strongEpi_of_epi _ theorem strongMono_of_mono [StrongMonoCategory C] (f : P ⟶ Q) [Mono f] : StrongMono f := StrongMonoCategory.strongMono_of_mono _ section attribute [local instance] strongEpi_of_epi instance (priority := 100) balanced_of_strongEpiCategory [StrongEpiCategory C] : Balanced C where isIso_of_mono_of_epi _ _ _ := isIso_of_mono_of_strongEpi _ end section attribute [local instance] strongMono_of_mono instance (priority := 100) balanced_of_strongMonoCategory [StrongMonoCategory C] : Balanced C where isIso_of_mono_of_epi _ _ _ := isIso_of_epi_of_strongMono _ end end CategoryTheory
CategoryTheory\Limits\Shapes\Terminal.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.PEmpty import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Category.Preorder /-! # Initial and terminal objects in a category. ## References * [Stacks: Initial and final objects](https://stacks.math.columbia.edu/tag/002B) -/ noncomputable section universe w w' v v₁ v₂ u u₁ u₂ open CategoryTheory namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] /-- Construct a cone for the empty diagram given an object. -/ @[simps] def asEmptyCone (X : C) : Cone (Functor.empty.{0} C) := { pt := X π := { app := by aesop_cat } } /-- Construct a cocone for the empty diagram given an object. -/ @[simps] def asEmptyCocone (X : C) : Cocone (Functor.empty.{0} C) := { pt := X ι := { app := by aesop_cat } } /-- `X` is terminal if the cone it induces on the empty diagram is limiting. -/ abbrev IsTerminal (X : C) := IsLimit (asEmptyCone X) /-- `X` is initial if the cocone it induces on the empty diagram is colimiting. -/ abbrev IsInitial (X : C) := IsColimit (asEmptyCocone X) /-- An object `Y` is terminal iff for every `X` there is a unique morphism `X ⟶ Y`. -/ def isTerminalEquivUnique (F : Discrete.{0} PEmpty.{1} ⥤ C) (Y : C) : IsLimit (⟨Y, by aesop_cat, by aesop_cat⟩ : Cone F) ≃ ∀ X : C, Unique (X ⟶ Y) where toFun t X := { default := t.lift ⟨X, ⟨by aesop_cat, by aesop_cat⟩⟩ uniq := fun f => t.uniq ⟨X, ⟨by aesop_cat, by aesop_cat⟩⟩ f (by aesop_cat) } invFun u := { lift := fun s => (u s.pt).default uniq := fun s _ _ => (u s.pt).2 _ } left_inv := by dsimp [Function.LeftInverse]; intro x; simp only [eq_iff_true_of_subsingleton] right_inv := by dsimp [Function.RightInverse,Function.LeftInverse] intro u; funext X; simp only /-- An object `Y` is terminal if for every `X` there is a unique morphism `X ⟶ Y` (as an instance). -/ def IsTerminal.ofUnique (Y : C) [h : ∀ X : C, Unique (X ⟶ Y)] : IsTerminal Y where lift s := (h s.pt).default fac := fun _ ⟨j⟩ => j.elim /-- An object `Y` is terminal if for every `X` there is a unique morphism `X ⟶ Y` (as explicit arguments). -/ def IsTerminal.ofUniqueHom {Y : C} (h : ∀ X : C, X ⟶ Y) (uniq : ∀ (X : C) (m : X ⟶ Y), m = h X) : IsTerminal Y := have : ∀ X : C, Unique (X ⟶ Y) := fun X ↦ ⟨⟨h X⟩, uniq X⟩ IsTerminal.ofUnique Y /-- If `α` is a preorder with top, then `⊤` is a terminal object. -/ def isTerminalTop {α : Type*} [Preorder α] [OrderTop α] : IsTerminal (⊤ : α) := IsTerminal.ofUnique _ /-- Transport a term of type `IsTerminal` across an isomorphism. -/ def IsTerminal.ofIso {Y Z : C} (hY : IsTerminal Y) (i : Y ≅ Z) : IsTerminal Z := IsLimit.ofIsoLimit hY { hom := { hom := i.hom } inv := { hom := i.inv } } /-- If `X` and `Y` are isomorphic, then `X` is terminal iff `Y` is. -/ def IsTerminal.equivOfIso {X Y : C} (e : X ≅ Y) : IsTerminal X ≃ IsTerminal Y where toFun h := IsTerminal.ofIso h e invFun h := IsTerminal.ofIso h e.symm left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- An object `X` is initial iff for every `Y` there is a unique morphism `X ⟶ Y`. -/ def isInitialEquivUnique (F : Discrete.{0} PEmpty.{1} ⥤ C) (X : C) : IsColimit (⟨X, ⟨by aesop_cat, by aesop_cat⟩⟩ : Cocone F) ≃ ∀ Y : C, Unique (X ⟶ Y) where toFun t X := { default := t.desc ⟨X, ⟨by aesop_cat, by aesop_cat⟩⟩ uniq := fun f => t.uniq ⟨X, ⟨by aesop_cat, by aesop_cat⟩⟩ f (by aesop_cat) } invFun u := { desc := fun s => (u s.pt).default uniq := fun s _ _ => (u s.pt).2 _ } left_inv := by dsimp [Function.LeftInverse]; intro; simp only [eq_iff_true_of_subsingleton] right_inv := by dsimp [Function.RightInverse,Function.LeftInverse] intro; funext; simp only /-- An object `X` is initial if for every `Y` there is a unique morphism `X ⟶ Y` (as an instance). -/ def IsInitial.ofUnique (X : C) [h : ∀ Y : C, Unique (X ⟶ Y)] : IsInitial X where desc s := (h s.pt).default fac := fun _ ⟨j⟩ => j.elim /-- An object `X` is initial if for every `Y` there is a unique morphism `X ⟶ Y` (as explicit arguments). -/ def IsInitial.ofUniqueHom {X : C} (h : ∀ Y : C, X ⟶ Y) (uniq : ∀ (Y : C) (m : X ⟶ Y), m = h Y) : IsInitial X := have : ∀ Y : C, Unique (X ⟶ Y) := fun Y ↦ ⟨⟨h Y⟩, uniq Y⟩ IsInitial.ofUnique X /-- If `α` is a preorder with bot, then `⊥` is an initial object. -/ def isInitialBot {α : Type*} [Preorder α] [OrderBot α] : IsInitial (⊥ : α) := IsInitial.ofUnique _ /-- Transport a term of type `is_initial` across an isomorphism. -/ def IsInitial.ofIso {X Y : C} (hX : IsInitial X) (i : X ≅ Y) : IsInitial Y := IsColimit.ofIsoColimit hX { hom := { hom := i.hom } inv := { hom := i.inv } } /-- If `X` and `Y` are isomorphic, then `X` is initial iff `Y` is. -/ def IsInitial.equivOfIso {X Y : C} (e : X ≅ Y) : IsInitial X ≃ IsInitial Y where toFun h := IsInitial.ofIso h e invFun h := IsInitial.ofIso h e.symm left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- Give the morphism to a terminal object from any other. -/ def IsTerminal.from {X : C} (t : IsTerminal X) (Y : C) : Y ⟶ X := t.lift (asEmptyCone Y) /-- Any two morphisms to a terminal object are equal. -/ theorem IsTerminal.hom_ext {X Y : C} (t : IsTerminal X) (f g : Y ⟶ X) : f = g := IsLimit.hom_ext t (by aesop_cat) @[simp] theorem IsTerminal.comp_from {Z : C} (t : IsTerminal Z) {X Y : C} (f : X ⟶ Y) : f ≫ t.from Y = t.from X := t.hom_ext _ _ @[simp] theorem IsTerminal.from_self {X : C} (t : IsTerminal X) : t.from X = 𝟙 X := t.hom_ext _ _ /-- Give the morphism from an initial object to any other. -/ def IsInitial.to {X : C} (t : IsInitial X) (Y : C) : X ⟶ Y := t.desc (asEmptyCocone Y) /-- Any two morphisms from an initial object are equal. -/ theorem IsInitial.hom_ext {X Y : C} (t : IsInitial X) (f g : X ⟶ Y) : f = g := IsColimit.hom_ext t (by aesop_cat) @[simp] theorem IsInitial.to_comp {X : C} (t : IsInitial X) {Y Z : C} (f : Y ⟶ Z) : t.to Y ≫ f = t.to Z := t.hom_ext _ _ @[simp] theorem IsInitial.to_self {X : C} (t : IsInitial X) : t.to X = 𝟙 X := t.hom_ext _ _ /-- Any morphism from a terminal object is split mono. -/ theorem IsTerminal.isSplitMono_from {X Y : C} (t : IsTerminal X) (f : X ⟶ Y) : IsSplitMono f := IsSplitMono.mk' ⟨t.from _, t.hom_ext _ _⟩ /-- Any morphism to an initial object is split epi. -/ theorem IsInitial.isSplitEpi_to {X Y : C} (t : IsInitial X) (f : Y ⟶ X) : IsSplitEpi f := IsSplitEpi.mk' ⟨t.to _, t.hom_ext _ _⟩ /-- Any morphism from a terminal object is mono. -/ theorem IsTerminal.mono_from {X Y : C} (t : IsTerminal X) (f : X ⟶ Y) : Mono f := by haveI := t.isSplitMono_from f; infer_instance /-- Any morphism to an initial object is epi. -/ theorem IsInitial.epi_to {X Y : C} (t : IsInitial X) (f : Y ⟶ X) : Epi f := by haveI := t.isSplitEpi_to f; infer_instance /-- If `T` and `T'` are terminal, they are isomorphic. -/ @[simps] def IsTerminal.uniqueUpToIso {T T' : C} (hT : IsTerminal T) (hT' : IsTerminal T') : T ≅ T' where hom := hT'.from _ inv := hT.from _ /-- If `I` and `I'` are initial, they are isomorphic. -/ @[simps] def IsInitial.uniqueUpToIso {I I' : C} (hI : IsInitial I) (hI' : IsInitial I') : I ≅ I' where hom := hI.to _ inv := hI'.to _ variable (C) /-- A category has a terminal object if it has a limit over the empty diagram. Use `hasTerminal_of_unique` to construct instances. -/ abbrev HasTerminal := HasLimitsOfShape (Discrete.{0} PEmpty) C /-- A category has an initial object if it has a colimit over the empty diagram. Use `hasInitial_of_unique` to construct instances. -/ abbrev HasInitial := HasColimitsOfShape (Discrete.{0} PEmpty) C section Univ variable (X : C) {F₁ : Discrete.{w} PEmpty ⥤ C} {F₂ : Discrete.{w'} PEmpty ⥤ C} /-- Being terminal is independent of the empty diagram, its universe, and the cone over it, as long as the cone points are isomorphic. -/ def isLimitChangeEmptyCone {c₁ : Cone F₁} (hl : IsLimit c₁) (c₂ : Cone F₂) (hi : c₁.pt ≅ c₂.pt) : IsLimit c₂ where lift c := hl.lift ⟨c.pt, by aesop_cat, by aesop_cat⟩ ≫ hi.hom uniq c f _ := by dsimp rw [← hl.uniq _ (f ≫ hi.inv) _] · simp only [Category.assoc, Iso.inv_hom_id, Category.comp_id] · aesop_cat /-- Replacing an empty cone in `IsLimit` by another with the same cone point is an equivalence. -/ def isLimitEmptyConeEquiv (c₁ : Cone F₁) (c₂ : Cone F₂) (h : c₁.pt ≅ c₂.pt) : IsLimit c₁ ≃ IsLimit c₂ where toFun hl := isLimitChangeEmptyCone C hl c₂ h invFun hl := isLimitChangeEmptyCone C hl c₁ h.symm left_inv := by dsimp [Function.LeftInverse]; intro; simp only [eq_iff_true_of_subsingleton] right_inv := by dsimp [Function.LeftInverse,Function.RightInverse]; intro simp only [eq_iff_true_of_subsingleton] theorem hasTerminalChangeDiagram (h : HasLimit F₁) : HasLimit F₂ := ⟨⟨⟨⟨limit F₁, by aesop_cat, by aesop_cat⟩, isLimitChangeEmptyCone C (limit.isLimit F₁) _ (eqToIso rfl)⟩⟩⟩ theorem hasTerminalChangeUniverse [h : HasLimitsOfShape (Discrete.{w} PEmpty) C] : HasLimitsOfShape (Discrete.{w'} PEmpty) C where has_limit _ := hasTerminalChangeDiagram C (h.1 (Functor.empty C)) /-- Being initial is independent of the empty diagram, its universe, and the cocone over it, as long as the cocone points are isomorphic. -/ def isColimitChangeEmptyCocone {c₁ : Cocone F₁} (hl : IsColimit c₁) (c₂ : Cocone F₂) (hi : c₁.pt ≅ c₂.pt) : IsColimit c₂ where desc c := hi.inv ≫ hl.desc ⟨c.pt, by aesop_cat, by aesop_cat⟩ uniq c f _ := by dsimp rw [← hl.uniq _ (hi.hom ≫ f) _] · simp only [Iso.inv_hom_id_assoc] · aesop_cat /-- Replacing an empty cocone in `IsColimit` by another with the same cocone point is an equivalence. -/ def isColimitEmptyCoconeEquiv (c₁ : Cocone F₁) (c₂ : Cocone F₂) (h : c₁.pt ≅ c₂.pt) : IsColimit c₁ ≃ IsColimit c₂ where toFun hl := isColimitChangeEmptyCocone C hl c₂ h invFun hl := isColimitChangeEmptyCocone C hl c₁ h.symm left_inv := by dsimp [Function.LeftInverse]; intro; simp only [eq_iff_true_of_subsingleton] right_inv := by dsimp [Function.LeftInverse,Function.RightInverse]; intro simp only [eq_iff_true_of_subsingleton] theorem hasInitialChangeDiagram (h : HasColimit F₁) : HasColimit F₂ := ⟨⟨⟨⟨colimit F₁, by aesop_cat, by aesop_cat⟩, isColimitChangeEmptyCocone C (colimit.isColimit F₁) _ (eqToIso rfl)⟩⟩⟩ theorem hasInitialChangeUniverse [h : HasColimitsOfShape (Discrete.{w} PEmpty) C] : HasColimitsOfShape (Discrete.{w'} PEmpty) C where has_colimit _ := hasInitialChangeDiagram C (h.1 (Functor.empty C)) end Univ /-- An arbitrary choice of terminal object, if one exists. You can use the notation `⊤_ C`. This object is characterized by having a unique morphism from any object. -/ abbrev terminal [HasTerminal C] : C := limit (Functor.empty.{0} C) /-- An arbitrary choice of initial object, if one exists. You can use the notation `⊥_ C`. This object is characterized by having a unique morphism to any object. -/ abbrev initial [HasInitial C] : C := colimit (Functor.empty.{0} C) /-- Notation for the terminal object in `C` -/ notation "⊤_ " C:20 => terminal C /-- Notation for the initial object in `C` -/ notation "⊥_ " C:20 => initial C section variable {C} /-- We can more explicitly show that a category has a terminal object by specifying the object, and showing there is a unique morphism to it from any other object. -/ theorem hasTerminal_of_unique (X : C) [h : ∀ Y : C, Unique (Y ⟶ X)] : HasTerminal C := { has_limit := fun F => HasLimit.mk ⟨_, (isTerminalEquivUnique F X).invFun h⟩ } theorem IsTerminal.hasTerminal {X : C} (h : IsTerminal X) : HasTerminal C := { has_limit := fun F => HasLimit.mk ⟨⟨X, by aesop_cat, by aesop_cat⟩, isLimitChangeEmptyCone _ h _ (Iso.refl _)⟩ } /-- We can more explicitly show that a category has an initial object by specifying the object, and showing there is a unique morphism from it to any other object. -/ theorem hasInitial_of_unique (X : C) [h : ∀ Y : C, Unique (X ⟶ Y)] : HasInitial C := { has_colimit := fun F => HasColimit.mk ⟨_, (isInitialEquivUnique F X).invFun h⟩ } theorem IsInitial.hasInitial {X : C} (h : IsInitial X) : HasInitial C where has_colimit F := HasColimit.mk ⟨⟨X, by aesop_cat, by aesop_cat⟩, isColimitChangeEmptyCocone _ h _ (Iso.refl _)⟩ /-- The map from an object to the terminal object. -/ abbrev terminal.from [HasTerminal C] (P : C) : P ⟶ ⊤_ C := limit.lift (Functor.empty C) (asEmptyCone P) /-- The map to an object from the initial object. -/ abbrev initial.to [HasInitial C] (P : C) : ⊥_ C ⟶ P := colimit.desc (Functor.empty C) (asEmptyCocone P) /-- A terminal object is terminal. -/ def terminalIsTerminal [HasTerminal C] : IsTerminal (⊤_ C) where lift s := terminal.from _ /-- An initial object is initial. -/ def initialIsInitial [HasInitial C] : IsInitial (⊥_ C) where desc s := initial.to _ instance uniqueToTerminal [HasTerminal C] (P : C) : Unique (P ⟶ ⊤_ C) := isTerminalEquivUnique _ (⊤_ C) terminalIsTerminal P instance uniqueFromInitial [HasInitial C] (P : C) : Unique (⊥_ C ⟶ P) := isInitialEquivUnique _ (⊥_ C) initialIsInitial P @[ext] theorem terminal.hom_ext [HasTerminal C] {P : C} (f g : P ⟶ ⊤_ C) : f = g := by ext ⟨⟨⟩⟩ @[ext] theorem initial.hom_ext [HasInitial C] {P : C} (f g : ⊥_ C ⟶ P) : f = g := by ext ⟨⟨⟩⟩ @[simp] theorem terminal.comp_from [HasTerminal C] {P Q : C} (f : P ⟶ Q) : f ≫ terminal.from Q = terminal.from P := by simp [eq_iff_true_of_subsingleton] @[simp] theorem initial.to_comp [HasInitial C] {P Q : C} (f : P ⟶ Q) : initial.to P ≫ f = initial.to Q := by simp [eq_iff_true_of_subsingleton] /-- The (unique) isomorphism between the chosen initial object and any other initial object. -/ @[simp] def initialIsoIsInitial [HasInitial C] {P : C} (t : IsInitial P) : ⊥_ C ≅ P := initialIsInitial.uniqueUpToIso t /-- The (unique) isomorphism between the chosen terminal object and any other terminal object. -/ @[simp] def terminalIsoIsTerminal [HasTerminal C] {P : C} (t : IsTerminal P) : ⊤_ C ≅ P := terminalIsTerminal.uniqueUpToIso t /-- Any morphism from a terminal object is split mono. -/ instance terminal.isSplitMono_from {Y : C} [HasTerminal C] (f : ⊤_ C ⟶ Y) : IsSplitMono f := IsTerminal.isSplitMono_from terminalIsTerminal _ /-- Any morphism to an initial object is split epi. -/ instance initial.isSplitEpi_to {Y : C} [HasInitial C] (f : Y ⟶ ⊥_ C) : IsSplitEpi f := IsInitial.isSplitEpi_to initialIsInitial _ /-- An initial object is terminal in the opposite category. -/ def terminalOpOfInitial {X : C} (t : IsInitial X) : IsTerminal (Opposite.op X) where lift s := (t.to s.pt.unop).op uniq s m _ := Quiver.Hom.unop_inj (t.hom_ext _ _) /-- An initial object in the opposite category is terminal in the original category. -/ def terminalUnopOfInitial {X : Cᵒᵖ} (t : IsInitial X) : IsTerminal X.unop where lift s := (t.to (Opposite.op s.pt)).unop uniq s m _ := Quiver.Hom.op_inj (t.hom_ext _ _) /-- A terminal object is initial in the opposite category. -/ def initialOpOfTerminal {X : C} (t : IsTerminal X) : IsInitial (Opposite.op X) where desc s := (t.from s.pt.unop).op uniq s m _ := Quiver.Hom.unop_inj (t.hom_ext _ _) /-- A terminal object in the opposite category is initial in the original category. -/ def initialUnopOfTerminal {X : Cᵒᵖ} (t : IsTerminal X) : IsInitial X.unop where desc s := (t.from (Opposite.op s.pt)).unop uniq s m _ := Quiver.Hom.op_inj (t.hom_ext _ _) instance hasInitial_op_of_hasTerminal [HasTerminal C] : HasInitial Cᵒᵖ := (initialOpOfTerminal terminalIsTerminal).hasInitial instance hasTerminal_op_of_hasInitial [HasInitial C] : HasTerminal Cᵒᵖ := (terminalOpOfInitial initialIsInitial).hasTerminal theorem hasTerminal_of_hasInitial_op [HasInitial Cᵒᵖ] : HasTerminal C := (terminalUnopOfInitial initialIsInitial).hasTerminal theorem hasInitial_of_hasTerminal_op [HasTerminal Cᵒᵖ] : HasInitial C := (initialUnopOfTerminal terminalIsTerminal).hasInitial instance {J : Type*} [Category J] {C : Type*} [Category C] [HasTerminal C] : HasLimit ((CategoryTheory.Functor.const J).obj (⊤_ C)) := HasLimit.mk { cone := { pt := ⊤_ C π := { app := fun _ => terminal.from _ } } isLimit := { lift := fun s => terminal.from _ } } /-- The limit of the constant `⊤_ C` functor is `⊤_ C`. -/ @[simps hom] def limitConstTerminal {J : Type*} [Category J] {C : Type*} [Category C] [HasTerminal C] : limit ((CategoryTheory.Functor.const J).obj (⊤_ C)) ≅ ⊤_ C where hom := terminal.from _ inv := limit.lift ((CategoryTheory.Functor.const J).obj (⊤_ C)) { pt := ⊤_ C π := { app := fun j => terminal.from _ } } @[reassoc (attr := simp)] theorem limitConstTerminal_inv_π {J : Type*} [Category J] {C : Type*} [Category C] [HasTerminal C] {j : J} : limitConstTerminal.inv ≫ limit.π ((CategoryTheory.Functor.const J).obj (⊤_ C)) j = terminal.from _ := by aesop_cat instance {J : Type*} [Category J] {C : Type*} [Category C] [HasInitial C] : HasColimit ((CategoryTheory.Functor.const J).obj (⊥_ C)) := HasColimit.mk { cocone := { pt := ⊥_ C ι := { app := fun _ => initial.to _ } } isColimit := { desc := fun s => initial.to _ } } /-- The colimit of the constant `⊥_ C` functor is `⊥_ C`. -/ @[simps inv] def colimitConstInitial {J : Type*} [Category J] {C : Type*} [Category C] [HasInitial C] : colimit ((CategoryTheory.Functor.const J).obj (⊥_ C)) ≅ ⊥_ C where hom := colimit.desc ((CategoryTheory.Functor.const J).obj (⊥_ C)) { pt := ⊥_ C ι := { app := fun j => initial.to _ } } inv := initial.to _ @[reassoc (attr := simp)] theorem ι_colimitConstInitial_hom {J : Type*} [Category J] {C : Type*} [Category C] [HasInitial C] {j : J} : colimit.ι ((CategoryTheory.Functor.const J).obj (⊥_ C)) j ≫ colimitConstInitial.hom = initial.to _ := by aesop_cat /-- A category is an `InitialMonoClass` if the canonical morphism of an initial object is a monomorphism. In practice, this is most useful when given an arbitrary morphism out of the chosen initial object, see `initial.mono_from`. Given a terminal object, this is equivalent to the assumption that the unique morphism from initial to terminal is a monomorphism, which is the second of Freyd's axioms for an AT category. TODO: This is a condition satisfied by categories with zero objects and morphisms. -/ class InitialMonoClass (C : Type u₁) [Category.{v₁} C] : Prop where /-- The map from the (any as stated) initial object to any other object is a monomorphism -/ isInitial_mono_from : ∀ {I} (X : C) (hI : IsInitial I), Mono (hI.to X) theorem IsInitial.mono_from [InitialMonoClass C] {I} {X : C} (hI : IsInitial I) (f : I ⟶ X) : Mono f := by rw [hI.hom_ext f (hI.to X)] apply InitialMonoClass.isInitial_mono_from instance (priority := 100) initial.mono_from [HasInitial C] [InitialMonoClass C] (X : C) (f : ⊥_ C ⟶ X) : Mono f := initialIsInitial.mono_from f /-- To show a category is an `InitialMonoClass` it suffices to give an initial object such that every morphism out of it is a monomorphism. -/ theorem InitialMonoClass.of_isInitial {I : C} (hI : IsInitial I) (h : ∀ X, Mono (hI.to X)) : InitialMonoClass C where isInitial_mono_from {I'} X hI' := by rw [hI'.hom_ext (hI'.to X) ((hI'.uniqueUpToIso hI).hom ≫ hI.to X)] apply mono_comp /-- To show a category is an `InitialMonoClass` it suffices to show every morphism out of the initial object is a monomorphism. -/ theorem InitialMonoClass.of_initial [HasInitial C] (h : ∀ X : C, Mono (initial.to X)) : InitialMonoClass C := InitialMonoClass.of_isInitial initialIsInitial h /-- To show a category is an `InitialMonoClass` it suffices to show the unique morphism from an initial object to a terminal object is a monomorphism. -/ theorem InitialMonoClass.of_isTerminal {I T : C} (hI : IsInitial I) (hT : IsTerminal T) (_ : Mono (hI.to T)) : InitialMonoClass C := InitialMonoClass.of_isInitial hI fun X => mono_of_mono_fac (hI.hom_ext (_ ≫ hT.from X) (hI.to T)) /-- To show a category is an `InitialMonoClass` it suffices to show the unique morphism from the initial object to a terminal object is a monomorphism. -/ theorem InitialMonoClass.of_terminal [HasInitial C] [HasTerminal C] (h : Mono (initial.to (⊤_ C))) : InitialMonoClass C := InitialMonoClass.of_isTerminal initialIsInitial terminalIsTerminal h section Comparison variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) /-- The comparison morphism from the image of a terminal object to the terminal object in the target category. This is an isomorphism iff `G` preserves terminal objects, see `CategoryTheory.Limits.PreservesTerminal.ofIsoComparison`. -/ def terminalComparison [HasTerminal C] [HasTerminal D] : G.obj (⊤_ C) ⟶ ⊤_ D := terminal.from _ -- TODO: Show this is an isomorphism if and only if `G` preserves initial objects. /-- The comparison morphism from the initial object in the target category to the image of the initial object. -/ def initialComparison [HasInitial C] [HasInitial D] : ⊥_ D ⟶ G.obj (⊥_ C) := initial.to _ end Comparison variable {J : Type u} [Category.{v} J] /-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cone for `J`. In `limitOfDiagramInitial` we show it is a limit cone. -/ @[simps] def coneOfDiagramInitial {X : J} (tX : IsInitial X) (F : J ⥤ C) : Cone F where pt := F.obj X π := { app := fun j => F.map (tX.to j) naturality := fun j j' k => by dsimp rw [← F.map_comp, Category.id_comp, tX.hom_ext (tX.to j ≫ k) (tX.to j')] } /-- From a functor `F : J ⥤ C`, given an initial object of `J`, show the cone `coneOfDiagramInitial` is a limit. -/ def limitOfDiagramInitial {X : J} (tX : IsInitial X) (F : J ⥤ C) : IsLimit (coneOfDiagramInitial tX F) where lift s := s.π.app X uniq s m w := by conv_lhs => dsimp simp_rw [← w X, coneOfDiagramInitial_π_app, tX.hom_ext (tX.to X) (𝟙 _)] simp instance hasLimit_of_domain_hasInitial [HasInitial J] {F : J ⥤ C} : HasLimit F := HasLimit.mk { cone := _, isLimit := limitOfDiagramInitial (initialIsInitial) F } -- See note [dsimp, simp] -- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has an initial object then the image of it is isomorphic to the limit of `F`. -/ abbrev limitOfInitial (F : J ⥤ C) [HasInitial J] : limit F ≅ F.obj (⊥_ J) := IsLimit.conePointUniqueUpToIso (limit.isLimit _) (limitOfDiagramInitial initialIsInitial F) /-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cone for `J`, provided that the morphisms in the diagram are isomorphisms. In `limitOfDiagramTerminal` we show it is a limit cone. -/ @[simps] def coneOfDiagramTerminal {X : J} (hX : IsTerminal X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : Cone F where pt := F.obj X π := { app := fun i => inv (F.map (hX.from _)) naturality := by intro i j f dsimp simp only [IsIso.eq_inv_comp, IsIso.comp_inv_eq, Category.id_comp, ← F.map_comp, hX.hom_ext (hX.from i) (f ≫ hX.from j)] } /-- From a functor `F : J ⥤ C`, given a terminal object of `J` and that the morphisms in the diagram are isomorphisms, show the cone `coneOfDiagramTerminal` is a limit. -/ def limitOfDiagramTerminal {X : J} (hX : IsTerminal X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsLimit (coneOfDiagramTerminal hX F) where lift S := S.π.app _ instance hasLimit_of_domain_hasTerminal [HasTerminal J] {F : J ⥤ C} [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : HasLimit F := HasLimit.mk { cone := _, isLimit := limitOfDiagramTerminal (terminalIsTerminal) F } -- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has a terminal object and all the morphisms in the diagram are isomorphisms, then the image of the terminal object is isomorphic to the limit of `F`. -/ abbrev limitOfTerminal (F : J ⥤ C) [HasTerminal J] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : limit F ≅ F.obj (⊤_ J) := IsLimit.conePointUniqueUpToIso (limit.isLimit _) (limitOfDiagramTerminal terminalIsTerminal F) /-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cocone for `J`. In `colimitOfDiagramTerminal` we show it is a colimit cocone. -/ @[simps] def coconeOfDiagramTerminal {X : J} (tX : IsTerminal X) (F : J ⥤ C) : Cocone F where pt := F.obj X ι := { app := fun j => F.map (tX.from j) naturality := fun j j' k => by dsimp rw [← F.map_comp, Category.comp_id, tX.hom_ext (k ≫ tX.from j') (tX.from j)] } /-- From a functor `F : J ⥤ C`, given a terminal object of `J`, show the cocone `coconeOfDiagramTerminal` is a colimit. -/ def colimitOfDiagramTerminal {X : J} (tX : IsTerminal X) (F : J ⥤ C) : IsColimit (coconeOfDiagramTerminal tX F) where desc s := s.ι.app X uniq s m w := by conv_rhs => dsimp -- Porting note: why do I need this much firepower? rw [← w X, coconeOfDiagramTerminal_ι_app, tX.hom_ext (tX.from X) (𝟙 _)] simp instance hasColimit_of_domain_hasTerminal [HasTerminal J] {F : J ⥤ C} : HasColimit F := HasColimit.mk { cocone := _, isColimit := colimitOfDiagramTerminal (terminalIsTerminal) F } lemma IsColimit.isIso_ι_app_of_isTerminal {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c) (X : J) (hX : IsTerminal X) : IsIso (c.ι.app X) := by change IsIso (coconePointUniqueUpToIso (colimitOfDiagramTerminal hX F) hc).hom infer_instance -- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has a terminal object then the image of it is isomorphic to the colimit of `F`. -/ abbrev colimitOfTerminal (F : J ⥤ C) [HasTerminal J] : colimit F ≅ F.obj (⊤_ J) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (colimitOfDiagramTerminal terminalIsTerminal F) /-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cocone for `J`, provided that the morphisms in the diagram are isomorphisms. In `colimitOfDiagramInitial` we show it is a colimit cocone. -/ @[simps] def coconeOfDiagramInitial {X : J} (hX : IsInitial X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : Cocone F where pt := F.obj X ι := { app := fun i => inv (F.map (hX.to _)) naturality := by intro i j f dsimp simp only [IsIso.eq_inv_comp, IsIso.comp_inv_eq, Category.comp_id, ← F.map_comp, hX.hom_ext (hX.to i ≫ f) (hX.to j)] } /-- From a functor `F : J ⥤ C`, given an initial object of `J` and that the morphisms in the diagram are isomorphisms, show the cone `coconeOfDiagramInitial` is a colimit. -/ def colimitOfDiagramInitial {X : J} (hX : IsInitial X) (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsColimit (coconeOfDiagramInitial hX F) where desc S := S.ι.app _ instance hasColimit_of_domain_hasInitial [HasInitial J] {F : J ⥤ C} [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : HasColimit F := HasColimit.mk { cocone := _, isColimit := colimitOfDiagramInitial (initialIsInitial) F } lemma IsLimit.isIso_π_app_of_isInitial {F : J ⥤ C} {c : Cone F} (hc : IsLimit c) (X : J) (hX : IsInitial X) : IsIso (c.π.app X) := by change IsIso (conePointUniqueUpToIso hc (limitOfDiagramInitial hX F)).hom infer_instance -- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`. /-- For a functor `F : J ⥤ C`, if `J` has an initial object and all the morphisms in the diagram are isomorphisms, then the image of the initial object is isomorphic to the colimit of `F`. -/ abbrev colimitOfInitial (F : J ⥤ C) [HasInitial J] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : colimit F ≅ F.obj (⊥_ J) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (colimitOfDiagramInitial initialIsInitial _) /-- If `j` is initial in the index category, then the map `limit.π F j` is an isomorphism. -/ theorem isIso_π_of_isInitial {j : J} (I : IsInitial j) (F : J ⥤ C) [HasLimit F] : IsIso (limit.π F j) := ⟨⟨limit.lift _ (coneOfDiagramInitial I F), ⟨by ext; simp, by simp⟩⟩⟩ instance isIso_π_initial [HasInitial J] (F : J ⥤ C) : IsIso (limit.π F (⊥_ J)) := isIso_π_of_isInitial initialIsInitial F theorem isIso_π_of_isTerminal {j : J} (I : IsTerminal j) (F : J ⥤ C) [HasLimit F] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (limit.π F j) := ⟨⟨limit.lift _ (coneOfDiagramTerminal I F), by ext; simp, by simp⟩⟩ instance isIso_π_terminal [HasTerminal J] (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (limit.π F (⊤_ J)) := isIso_π_of_isTerminal terminalIsTerminal F /-- If `j` is terminal in the index category, then the map `colimit.ι F j` is an isomorphism. -/ theorem isIso_ι_of_isTerminal {j : J} (I : IsTerminal j) (F : J ⥤ C) [HasColimit F] : IsIso (colimit.ι F j) := ⟨⟨colimit.desc _ (coconeOfDiagramTerminal I F), ⟨by simp, by ext; simp⟩⟩⟩ instance isIso_ι_terminal [HasTerminal J] (F : J ⥤ C) : IsIso (colimit.ι F (⊤_ J)) := isIso_ι_of_isTerminal terminalIsTerminal F theorem isIso_ι_of_isInitial {j : J} (I : IsInitial j) (F : J ⥤ C) [HasColimit F] [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (colimit.ι F j) := ⟨⟨colimit.desc _ (coconeOfDiagramInitial I F), by refine ⟨?_, by ext; simp⟩ dsimp; simp only [colimit.ι_desc, coconeOfDiagramInitial_pt, coconeOfDiagramInitial_ι_app, Functor.const_obj_obj, IsInitial.to_self, Functor.map_id] dsimp [inv]; simp only [Category.id_comp, Category.comp_id, and_self] apply @Classical.choose_spec _ (fun x => x = 𝟙 F.obj j) _ ⟩⟩ instance isIso_ι_initial [HasInitial J] (F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), IsIso (F.map f)] : IsIso (colimit.ι F (⊥_ J)) := isIso_ι_of_isInitial initialIsInitial F /-- Any morphism between terminal objects is an isomorphism. -/ lemma isIso_of_isTerminal {X Y : C} (hX : IsTerminal X) (hY : IsTerminal Y) (f : X ⟶ Y) : IsIso f := by refine ⟨⟨IsTerminal.from hX Y, ?_⟩⟩ simp only [IsTerminal.comp_from, IsTerminal.from_self, true_and] apply IsTerminal.hom_ext hY /-- Any morphism between initial objects is an isomorphism. -/ lemma isIso_of_isInitial {X Y : C} (hX : IsInitial X) (hY : IsInitial Y) (f : X ⟶ Y) : IsIso f := by refine ⟨⟨IsInitial.to hY X, ?_⟩⟩ simp only [IsInitial.to_comp, IsInitial.to_self, and_true] apply IsInitial.hom_ext hX end end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Types.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.Tactic.CategoryTheory.Elementwise import Mathlib.Data.Set.Subsingleton import Mathlib.Logic.Relation /-! # Special shapes for limits in `Type`. The general shape (co)limits defined in `CategoryTheory.Limits.Types` are intended for use through the limits API, and the actual implementation should mostly be considered "sealed". In this file, we provide definitions of the "standard" special shapes of limits in `Type`, giving the expected definitional implementation: * the terminal object is `PUnit` * the binary product of `X` and `Y` is `X × Y` * the product of a family `f : J → Type` is `Π j, f j` * the coproduct of a family `f : J → Type` is `Σ j, f j` * the binary coproduct of `X` and `Y` is the sum type `X ⊕ Y` * the equalizer of a pair of maps `(g, h)` is the subtype `{x : Y // g x = h x}` * the coequalizer of a pair of maps `(f, g)` is the quotient of `Y` by `∀ x : Y, f x ~ g x` * the pullback of `f : X ⟶ Z` and `g : Y ⟶ Z` is the subtype `{ p : X × Y // f p.1 = g p.2 }` of the product * multiequalizers We first construct terms of `IsLimit` and `LimitCone`, and then provide isomorphisms with the types generated by the `HasLimit` API. As an example, when setting up the monoidal category structure on `Type` we use the `Types.terminalLimitCone` and `Types.binaryProductLimitCone` definitions. -/ universe v u open CategoryTheory Limits namespace CategoryTheory.Limits.Types example : HasProducts.{v} (Type v) := inferInstance example [UnivLE.{v, u}] : HasProducts.{v} (Type u) := inferInstance -- This shortcut instance is required in `Mathlib.CategoryTheory.Closed.Types`, -- although I don't understand why, and wish it wasn't. instance : HasProducts.{v} (Type v) := inferInstance /-- A restatement of `Types.Limit.lift_π_apply` that uses `Pi.π` and `Pi.lift`. -/ @[simp 1001] theorem pi_lift_π_apply {β : Type v} [Small.{u} β] (f : β → Type u) {P : Type u} (s : ∀ b, P ⟶ f b) (b : β) (x : P) : (Pi.π f b : (piObj f) → f b) (@Pi.lift β _ _ f _ P s x) = s b x := congr_fun (limit.lift_π (Fan.mk P s) ⟨b⟩) x /-- A restatement of `Types.Limit.lift_π_apply` that uses `Pi.π` and `Pi.lift`, with specialized universes. -/ theorem pi_lift_π_apply' {β : Type v} (f : β → Type v) {P : Type v} (s : ∀ b, P ⟶ f b) (b : β) (x : P) : (Pi.π f b : (piObj f) → f b) (@Pi.lift β _ _ f _ P s x) = s b x := by simp /-- A restatement of `Types.Limit.map_π_apply` that uses `Pi.π` and `Pi.map`. -/ @[simp 1001] theorem pi_map_π_apply {β : Type v} [Small.{u} β] {f g : β → Type u} (α : ∀ j, f j ⟶ g j) (b : β) (x) : (Pi.π g b : ∏ᶜ g → g b) (Pi.map α x) = α b ((Pi.π f b : ∏ᶜ f → f b) x) := Limit.map_π_apply.{v, u} _ _ _ /-- A restatement of `Types.Limit.map_π_apply` that uses `Pi.π` and `Pi.map`, with specialized universes. -/ theorem pi_map_π_apply' {β : Type v} {f g : β → Type v} (α : ∀ j, f j ⟶ g j) (b : β) (x) : (Pi.π g b : ∏ᶜ g → g b) (Pi.map α x) = α b ((Pi.π f b : ∏ᶜ f → f b) x) := by simp /-- The category of types has `PUnit` as a terminal object. -/ def terminalLimitCone : Limits.LimitCone (Functor.empty (Type u)) where -- Porting note: tidy was able to fill the structure automatically cone := { pt := PUnit π := (Functor.uniqueFromEmpty _).hom } isLimit := { lift := fun _ _ => PUnit.unit fac := fun _ => by rintro ⟨⟨⟩⟩ uniq := fun _ _ _ => by funext subsingleton } /-- The terminal object in `Type u` is `PUnit`. -/ noncomputable def terminalIso : ⊤_ Type u ≅ PUnit := limit.isoLimitCone terminalLimitCone.{u, 0} /-- The terminal object in `Type u` is `PUnit`. -/ noncomputable def isTerminalPunit : IsTerminal (PUnit : Type u) := terminalIsTerminal.ofIso terminalIso -- Porting note: the following three instances have been added to ease -- the automation in a definition in `AlgebraicTopology.SimplicialSet` noncomputable instance : Inhabited (⊤_ (Type u)) := ⟨@terminal.from (Type u) _ _ (ULift (Fin 1)) (ULift.up 0)⟩ instance : Subsingleton (⊤_ (Type u)) := ⟨fun a b => congr_fun (@Subsingleton.elim (_ ⟶ ⊤_ (Type u)) _ (fun _ => a) (fun _ => b)) (ULift.up (0 : Fin 1))⟩ noncomputable instance : Unique (⊤_ (Type u)) := Unique.mk' _ /-- A type is terminal if and only if it contains exactly one element. -/ noncomputable def isTerminalEquivUnique (X : Type u) : IsTerminal X ≃ Unique X := equivOfSubsingletonOfSubsingleton (fun h => ((Iso.toEquiv (terminalIsoIsTerminal h).symm).unique)) (fun _ => IsTerminal.ofIso terminalIsTerminal (Equiv.toIso (Equiv.equivOfUnique _ _))) /-- A type is terminal if and only if it is isomorphic to `PUnit`. -/ noncomputable def isTerminalEquivIsoPUnit (X : Type u) : IsTerminal X ≃ (X ≅ PUnit) := by calc IsTerminal X ≃ Unique X := isTerminalEquivUnique _ _ ≃ (X ≃ PUnit.{u + 1}) := uniqueEquivEquivUnique _ _ _ ≃ (X ≅ PUnit) := equivEquivIso /-- The category of types has `PEmpty` as an initial object. -/ def initialColimitCocone : Limits.ColimitCocone (Functor.empty (Type u)) where -- Porting note: tidy was able to fill the structure automatically cocone := { pt := PEmpty ι := (Functor.uniqueFromEmpty _).inv } isColimit := { desc := fun _ => by rintro ⟨⟩ fac := fun _ => by rintro ⟨⟨⟩⟩ uniq := fun _ _ _ => by funext x; cases x } /-- The initial object in `Type u` is `PEmpty`. -/ noncomputable def initialIso : ⊥_ Type u ≅ PEmpty := colimit.isoColimitCocone initialColimitCocone.{u, 0} /-- The initial object in `Type u` is `PEmpty`. -/ noncomputable def isInitialPunit : IsInitial (PEmpty : Type u) := initialIsInitial.ofIso initialIso /-- An object in `Type u` is initial if and only if it is empty. -/ lemma initial_iff_empty (X : Type u) : Nonempty (IsInitial X) ↔ IsEmpty X := by constructor · intro ⟨h⟩ exact Function.isEmpty (IsInitial.to h PEmpty) · intro h exact ⟨IsInitial.ofIso Types.isInitialPunit <| Equiv.toIso <| Equiv.equivOfIsEmpty PEmpty X⟩ open CategoryTheory.Limits.WalkingPair -- We manually generate the other projection lemmas since the simp-normal form for the legs is -- otherwise not created correctly. /-- The product type `X × Y` forms a cone for the binary product of `X` and `Y`. -/ @[simps! pt] def binaryProductCone (X Y : Type u) : BinaryFan X Y := BinaryFan.mk _root_.Prod.fst _root_.Prod.snd @[simp] theorem binaryProductCone_fst (X Y : Type u) : (binaryProductCone X Y).fst = _root_.Prod.fst := rfl @[simp] theorem binaryProductCone_snd (X Y : Type u) : (binaryProductCone X Y).snd = _root_.Prod.snd := rfl /-- The product type `X × Y` is a binary product for `X` and `Y`. -/ @[simps] def binaryProductLimit (X Y : Type u) : IsLimit (binaryProductCone X Y) where lift (s : BinaryFan X Y) x := (s.fst x, s.snd x) fac _ j := Discrete.recOn j fun j => WalkingPair.casesOn j rfl rfl uniq _ _ w := funext fun x => Prod.ext (congr_fun (w ⟨left⟩) x) (congr_fun (w ⟨right⟩) x) /-- The category of types has `X × Y`, the usual cartesian product, as the binary product of `X` and `Y`. -/ @[simps] def binaryProductLimitCone (X Y : Type u) : Limits.LimitCone (pair X Y) := ⟨_, binaryProductLimit X Y⟩ /-- The categorical binary product in `Type u` is cartesian product. -/ noncomputable def binaryProductIso (X Y : Type u) : Limits.prod X Y ≅ X × Y := limit.isoLimitCone (binaryProductLimitCone X Y) @[elementwise (attr := simp)] theorem binaryProductIso_hom_comp_fst (X Y : Type u) : (binaryProductIso X Y).hom ≫ _root_.Prod.fst = Limits.prod.fst := limit.isoLimitCone_hom_π (binaryProductLimitCone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryProductIso_hom_comp_snd (X Y : Type u) : (binaryProductIso X Y).hom ≫ _root_.Prod.snd = Limits.prod.snd := limit.isoLimitCone_hom_π (binaryProductLimitCone X Y) ⟨WalkingPair.right⟩ @[elementwise (attr := simp)] theorem binaryProductIso_inv_comp_fst (X Y : Type u) : (binaryProductIso X Y).inv ≫ Limits.prod.fst = _root_.Prod.fst := limit.isoLimitCone_inv_π (binaryProductLimitCone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryProductIso_inv_comp_snd (X Y : Type u) : (binaryProductIso X Y).inv ≫ Limits.prod.snd = _root_.Prod.snd := limit.isoLimitCone_inv_π (binaryProductLimitCone X Y) ⟨WalkingPair.right⟩ -- Porting note: it was originally @[simps (config := { typeMd := reducible })] -- We add the option `type_md` to tell `@[simps]` to not treat homomorphisms `X ⟶ Y` in `Type*` as -- a function type /-- The functor which sends `X, Y` to the product type `X × Y`. -/ @[simps] def binaryProductFunctor : Type u ⥤ Type u ⥤ Type u where obj X := { obj := fun Y => X × Y map := fun { Y₁ Y₂} f => (binaryProductLimit X Y₂).lift (BinaryFan.mk _root_.Prod.fst (_root_.Prod.snd ≫ f)) } map {X₁ X₂} f := { app := fun Y => (binaryProductLimit X₂ Y).lift (BinaryFan.mk (_root_.Prod.fst ≫ f) _root_.Prod.snd) } /-- The product functor given by the instance `HasBinaryProducts (Type u)` is isomorphic to the explicit binary product functor given by the product type. -/ noncomputable def binaryProductIsoProd : binaryProductFunctor ≅ (prod.functor : Type u ⥤ _) := by refine NatIso.ofComponents (fun X => ?_) (fun _ => ?_) · refine NatIso.ofComponents (fun Y => ?_) (fun _ => ?_) · exact ((limit.isLimit _).conePointUniqueUpToIso (binaryProductLimit X Y)).symm · apply Limits.prod.hom_ext <;> simp <;> rfl · ext : 2 apply Limits.prod.hom_ext <;> simp <;> rfl /-- The sum type `X ⊕ Y` forms a cocone for the binary coproduct of `X` and `Y`. -/ @[simps!] def binaryCoproductCocone (X Y : Type u) : Cocone (pair X Y) := BinaryCofan.mk Sum.inl Sum.inr /-- The sum type `X ⊕ Y` is a binary coproduct for `X` and `Y`. -/ @[simps] def binaryCoproductColimit (X Y : Type u) : IsColimit (binaryCoproductCocone X Y) where desc := fun s : BinaryCofan X Y => Sum.elim s.inl s.inr fac _ j := Discrete.recOn j fun j => WalkingPair.casesOn j rfl rfl uniq _ _ w := funext fun x => Sum.casesOn x (congr_fun (w ⟨left⟩)) (congr_fun (w ⟨right⟩)) /-- The category of types has `X ⊕ Y`, as the binary coproduct of `X` and `Y`. -/ def binaryCoproductColimitCocone (X Y : Type u) : Limits.ColimitCocone (pair X Y) := ⟨_, binaryCoproductColimit X Y⟩ /-- The categorical binary coproduct in `Type u` is the sum `X ⊕ Y`. -/ noncomputable def binaryCoproductIso (X Y : Type u) : Limits.coprod X Y ≅ X ⊕ Y := colimit.isoColimitCocone (binaryCoproductColimitCocone X Y) --open CategoryTheory.Type @[elementwise (attr := simp)] theorem binaryCoproductIso_inl_comp_hom (X Y : Type u) : Limits.coprod.inl ≫ (binaryCoproductIso X Y).hom = Sum.inl := colimit.isoColimitCocone_ι_hom (binaryCoproductColimitCocone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inr_comp_hom (X Y : Type u) : Limits.coprod.inr ≫ (binaryCoproductIso X Y).hom = Sum.inr := colimit.isoColimitCocone_ι_hom (binaryCoproductColimitCocone X Y) ⟨WalkingPair.right⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inl_comp_inv (X Y : Type u) : ↾(Sum.inl : X ⟶ X ⊕ Y) ≫ (binaryCoproductIso X Y).inv = Limits.coprod.inl := colimit.isoColimitCocone_ι_inv (binaryCoproductColimitCocone X Y) ⟨WalkingPair.left⟩ @[elementwise (attr := simp)] theorem binaryCoproductIso_inr_comp_inv (X Y : Type u) : ↾(Sum.inr : Y ⟶ X ⊕ Y) ≫ (binaryCoproductIso X Y).inv = Limits.coprod.inr := colimit.isoColimitCocone_ι_inv (binaryCoproductColimitCocone X Y) ⟨WalkingPair.right⟩ open Function (Injective) theorem binaryCofan_isColimit_iff {X Y : Type u} (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ Injective c.inl ∧ Injective c.inr ∧ IsCompl (Set.range c.inl) (Set.range c.inr) := by classical constructor · rintro ⟨h⟩ rw [← show _ = c.inl from h.comp_coconePointUniqueUpToIso_inv (binaryCoproductColimit X Y) ⟨WalkingPair.left⟩, ← show _ = c.inr from h.comp_coconePointUniqueUpToIso_inv (binaryCoproductColimit X Y) ⟨WalkingPair.right⟩] dsimp [binaryCoproductCocone] refine ⟨(h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.injective.comp Sum.inl_injective, (h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.injective.comp Sum.inr_injective, ?_⟩ erw [Set.range_comp, ← eq_compl_iff_isCompl, Set.range_comp _ Sum.inr, ← Set.image_compl_eq (h.coconePointUniqueUpToIso (binaryCoproductColimit X Y)).symm.toEquiv.bijective] simp · rintro ⟨h₁, h₂, h₃⟩ have : ∀ x, x ∈ Set.range c.inl ∨ x ∈ Set.range c.inr := by rw [eq_compl_iff_isCompl.mpr h₃.symm] exact fun _ => or_not refine ⟨BinaryCofan.IsColimit.mk _ ?_ ?_ ?_ ?_⟩ · intro T f g x exact if h : x ∈ Set.range c.inl then f ((Equiv.ofInjective _ h₁).symm ⟨x, h⟩) else g ((Equiv.ofInjective _ h₂).symm ⟨x, (this x).resolve_left h⟩) · intro T f g funext x dsimp simp [h₁.eq_iff] · intro T f g funext x dsimp simp only [Set.mem_range, Equiv.ofInjective_symm_apply, dite_eq_right_iff, forall_exists_index] intro y e have : c.inr x ∈ Set.range c.inl ⊓ Set.range c.inr := ⟨⟨_, e⟩, ⟨_, rfl⟩⟩ rw [disjoint_iff.mp h₃.1] at this exact this.elim · rintro T _ _ m rfl rfl funext x dsimp split_ifs <;> exact congr_arg _ (Equiv.apply_ofInjective_symm _ ⟨_, _⟩).symm /-- Any monomorphism in `Type` is a coproduct injection. -/ noncomputable def isCoprodOfMono {X Y : Type u} (f : X ⟶ Y) [Mono f] : IsColimit (BinaryCofan.mk f (Subtype.val : ↑(Set.range f)ᶜ → Y)) := by apply Nonempty.some rw [binaryCofan_isColimit_iff] refine ⟨(mono_iff_injective f).mp inferInstance, Subtype.val_injective, ?_⟩ symm rw [← eq_compl_iff_isCompl] exact Subtype.range_val /-- The category of types has `Π j, f j` as the product of a type family `f : J → TypeMax.{v, u}`. -/ def productLimitCone {J : Type v} (F : J → TypeMax.{v, u}) : Limits.LimitCone (Discrete.functor F) where cone := { pt := ∀ j, F j π := Discrete.natTrans (fun ⟨j⟩ f => f j) } isLimit := { lift := fun s x j => s.π.app ⟨j⟩ x uniq := fun s m w => funext fun x => funext fun j => (congr_fun (w ⟨j⟩) x : _) } /-- The categorical product in `TypeMax.{v, u}` is the type theoretic product `Π j, F j`. -/ noncomputable def productIso {J : Type v} (F : J → TypeMax.{v, u}) : ∏ᶜ F ≅ ∀ j, F j := limit.isoLimitCone (productLimitCone.{v, u} F) -- Porting note: was `@[elementwise (attr := simp)]`, but it produces a trivial lemma -- It should produce the lemma below. @[simp] theorem productIso_hom_comp_eval {J : Type v} (F : J → TypeMax.{v, u}) (j : J) : ((productIso.{v, u} F).hom ≫ fun f => f j) = Pi.π F j := rfl @[simp] theorem productIso_hom_comp_eval_apply {J : Type v} (F : J → TypeMax.{v, u}) (j : J) (x) : ((productIso.{v, u} F).hom x) j = Pi.π F j x := rfl @[elementwise (attr := simp)] theorem productIso_inv_comp_π {J : Type v} (F : J → TypeMax.{v, u}) (j : J) : (productIso.{v, u} F).inv ≫ Pi.π F j = fun f => f j := limit.isoLimitCone_inv_π (productLimitCone.{v, u} F) ⟨j⟩ namespace Small variable {J : Type v} (F : J → Type u) [Small.{u} J] /-- A variant of `productLimitCone` using a `Small` hypothesis rather than a function to `TypeMax`. -/ noncomputable def productLimitCone : Limits.LimitCone (Discrete.functor F) where cone := { pt := Shrink (∀ j, F j) π := Discrete.natTrans (fun ⟨j⟩ f => (equivShrink (∀ j, F j)).symm f j) } isLimit := have : Small.{u} (∀ j, F j) := inferInstance { lift := fun s x => (equivShrink _) (fun j => s.π.app ⟨j⟩ x) uniq := fun s m w => funext fun x => Shrink.ext <| funext fun j => by simpa using (congr_fun (w ⟨j⟩) x : _) } /-- The categorical product in `Type u` indexed in `Type v` is the type theoretic product `Π j, F j`, after shrinking back to `Type u`. -/ noncomputable def productIso : (∏ᶜ F : Type u) ≅ Shrink.{u} (∀ j, F j) := limit.isoLimitCone (productLimitCone.{v, u} F) @[simp] theorem productIso_hom_comp_eval (j : J) : ((productIso.{v, u} F).hom ≫ fun f => (equivShrink (∀ j, F j)).symm f j) = Pi.π F j := limit.isoLimitCone_hom_π (productLimitCone.{v, u} F) ⟨j⟩ -- Porting note: -- `elementwise` seems to be broken. Applied to the previous lemma, it should produce: @[simp] theorem productIso_hom_comp_eval_apply (j : J) (x) : (equivShrink (∀ j, F j)).symm ((productIso F).hom x) j = Pi.π F j x := congr_fun (productIso_hom_comp_eval F j) x @[elementwise (attr := simp)] theorem productIso_inv_comp_π (j : J) : (productIso.{v, u} F).inv ≫ Pi.π F j = fun f => ((equivShrink (∀ j, F j)).symm f) j := limit.isoLimitCone_inv_π (productLimitCone.{v, u} F) ⟨j⟩ end Small /-- The category of types has `Σ j, f j` as the coproduct of a type family `f : J → Type`. -/ def coproductColimitCocone {J : Type v} (F : J → TypeMax.{v, u}) : Limits.ColimitCocone (Discrete.functor F) where cocone := { pt := Σj, F j ι := Discrete.natTrans (fun ⟨j⟩ x => ⟨j, x⟩)} isColimit := { desc := fun s x => s.ι.app ⟨x.1⟩ x.2 uniq := fun s m w => by funext ⟨j, x⟩ exact congr_fun (w ⟨j⟩) x } /-- The categorical coproduct in `Type u` is the type theoretic coproduct `Σ j, F j`. -/ noncomputable def coproductIso {J : Type v} (F : J → TypeMax.{v, u}) : ∐ F ≅ Σj, F j := colimit.isoColimitCocone (coproductColimitCocone F) @[elementwise (attr := simp)] theorem coproductIso_ι_comp_hom {J : Type v} (F : J → TypeMax.{v, u}) (j : J) : Sigma.ι F j ≫ (coproductIso F).hom = fun x : F j => (⟨j, x⟩ : Σj, F j) := colimit.isoColimitCocone_ι_hom (coproductColimitCocone F) ⟨j⟩ -- Porting note: was @[elementwise (attr := simp)], but it produces a trivial lemma -- removed simp attribute because it seems it never applies theorem coproductIso_mk_comp_inv {J : Type v} (F : J → TypeMax.{v, u}) (j : J) : (↾fun x : F j => (⟨j, x⟩ : Σj, F j)) ≫ (coproductIso F).inv = Sigma.ι F j := rfl section Fork variable {X Y Z : Type u} (f : X ⟶ Y) {g h : Y ⟶ Z} (w : f ≫ g = f ≫ h) /-- Show the given fork in `Type u` is an equalizer given that any element in the "difference kernel" comes from `X`. The converse of `unique_of_type_equalizer`. -/ noncomputable def typeEqualizerOfUnique (t : ∀ y : Y, g y = h y → ∃! x : X, f x = y) : IsLimit (Fork.ofι _ w) := Fork.IsLimit.mk' _ fun s => by refine ⟨fun i => ?_, ?_, ?_⟩ · apply Classical.choose (t (s.ι i) _) apply congr_fun s.condition i · funext i exact (Classical.choose_spec (t (s.ι i) (congr_fun s.condition i))).1 · intro m hm funext i exact (Classical.choose_spec (t (s.ι i) (congr_fun s.condition i))).2 _ (congr_fun hm i) /-- The converse of `type_equalizer_of_unique`. -/ theorem unique_of_type_equalizer (t : IsLimit (Fork.ofι _ w)) (y : Y) (hy : g y = h y) : ∃! x : X, f x = y := by let y' : PUnit ⟶ Y := fun _ => y have hy' : y' ≫ g = y' ≫ h := funext fun _ => hy refine ⟨(Fork.IsLimit.lift' t _ hy').1 ⟨⟩, congr_fun (Fork.IsLimit.lift' t y' _).2 ⟨⟩, ?_⟩ intro x' hx' suffices (fun _ : PUnit => x') = (Fork.IsLimit.lift' t y' hy').1 by rw [← this] apply Fork.IsLimit.hom_ext t funext ⟨⟩ apply hx'.trans (congr_fun (Fork.IsLimit.lift' t _ hy').2 ⟨⟩).symm theorem type_equalizer_iff_unique : Nonempty (IsLimit (Fork.ofι _ w)) ↔ ∀ y : Y, g y = h y → ∃! x : X, f x = y := ⟨fun i => unique_of_type_equalizer _ _ (Classical.choice i), fun k => ⟨typeEqualizerOfUnique f w k⟩⟩ /-- Show that the subtype `{x : Y // g x = h x}` is an equalizer for the pair `(g,h)`. -/ def equalizerLimit : Limits.LimitCone (parallelPair g h) where cone := Fork.ofι (Subtype.val : { x : Y // g x = h x } → Y) (funext Subtype.prop) isLimit := Fork.IsLimit.mk' _ fun s => ⟨fun i => ⟨s.ι i, by apply congr_fun s.condition i⟩, rfl, fun hm => funext fun x => Subtype.ext (congr_fun hm x)⟩ variable (g h) /-- The categorical equalizer in `Type u` is `{x : Y // g x = h x}`. -/ noncomputable def equalizerIso : equalizer g h ≅ { x : Y // g x = h x } := limit.isoLimitCone equalizerLimit -- Porting note: was @[elementwise], but it produces a trivial lemma @[simp] theorem equalizerIso_hom_comp_subtype : (equalizerIso g h).hom ≫ Subtype.val = equalizer.ι g h := by rfl @[elementwise (attr := simp)] theorem equalizerIso_inv_comp_ι : (equalizerIso g h).inv ≫ equalizer.ι g h = Subtype.val := limit.isoLimitCone_inv_π equalizerLimit WalkingParallelPair.zero end Fork section Cofork variable {X Y Z : Type u} (f g : X ⟶ Y) /-- (Implementation) The relation to be quotiented to obtain the coequalizer. -/ inductive CoequalizerRel : Y → Y → Prop | Rel (x : X) : CoequalizerRel (f x) (g x) /-- Show that the quotient by the relation generated by `f(x) ~ g(x)` is a coequalizer for the pair `(f, g)`. -/ def coequalizerColimit : Limits.ColimitCocone (parallelPair f g) where cocone := Cofork.ofπ (Quot.mk (CoequalizerRel f g)) (funext fun x => Quot.sound (CoequalizerRel.Rel x)) isColimit := Cofork.IsColimit.mk _ (fun s => Quot.lift s.π (fun a b (h : CoequalizerRel f g a b) => by cases h apply congr_fun s.condition)) (fun s => rfl) (fun s m hm => funext (fun x => Quot.inductionOn x (congr_fun hm))) /-- If `π : Y ⟶ Z` is an equalizer for `(f, g)`, and `U ⊆ Y` such that `f ⁻¹' U = g ⁻¹' U`, then `π ⁻¹' (π '' U) = U`. -/ theorem coequalizer_preimage_image_eq_of_preimage_eq (π : Y ⟶ Z) (e : f ≫ π = g ≫ π) (h : IsColimit (Cofork.ofπ π e)) (U : Set Y) (H : f ⁻¹' U = g ⁻¹' U) : π ⁻¹' (π '' U) = U := by have lem : ∀ x y, CoequalizerRel f g x y → (x ∈ U ↔ y ∈ U) := by rintro _ _ ⟨x⟩ change x ∈ f ⁻¹' U ↔ x ∈ g ⁻¹' U rw [H] -- Porting note: tidy was able to fill the structure automatically have eqv : _root_.Equivalence fun x y => x ∈ U ↔ y ∈ U := { refl := by tauto symm := by tauto trans := by tauto } ext constructor · rw [← show _ = π from h.comp_coconePointUniqueUpToIso_inv (coequalizerColimit f g).2 WalkingParallelPair.one] rintro ⟨y, hy, e'⟩ dsimp at e' replace e' := (mono_iff_injective (h.coconePointUniqueUpToIso (coequalizerColimit f g).isColimit).inv).mp inferInstance e' exact (eqv.eqvGen_iff.mp (EqvGen.mono lem (Quot.exact _ e'))).mp hy · exact fun hx => ⟨_, hx, rfl⟩ /-- The categorical coequalizer in `Type u` is the quotient by `f g ~ g x`. -/ noncomputable def coequalizerIso : coequalizer f g ≅ _root_.Quot (CoequalizerRel f g) := colimit.isoColimitCocone (coequalizerColimit f g) @[elementwise (attr := simp)] theorem coequalizerIso_π_comp_hom : coequalizer.π f g ≫ (coequalizerIso f g).hom = Quot.mk (CoequalizerRel f g) := colimit.isoColimitCocone_ι_hom (coequalizerColimit f g) WalkingParallelPair.one -- Porting note: was @[elementwise], but it produces a trivial lemma @[simp] theorem coequalizerIso_quot_comp_inv : ↾Quot.mk (CoequalizerRel f g) ≫ (coequalizerIso f g).inv = coequalizer.π f g := rfl end Cofork section Pullback -- #synth HasPullbacks.{u} (Type u) instance : HasPullbacks.{u} (Type u) := -- FIXME does not work via `inferInstance` despite `#synth HasPullbacks.{u} (Type u)` succeeding. -- https://github.com/leanprover-community/mathlib4/issues/5752 -- inferInstance hasPullbacks_of_hasWidePullbacks.{u} (Type u) instance : HasPushouts.{u} (Type u) := hasPushouts_of_hasWidePushouts.{u} (Type u) variable {X Y Z : Type u} variable (f : X ⟶ Z) (g : Y ⟶ Z) -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- The usual explicit pullback in the category of types, as a subtype of the product. The full `LimitCone` data is bundled as `pullbackLimitCone f g`. -/ abbrev PullbackObj : Type u := { p : X × Y // f p.1 = g p.2 } -- `PullbackObj f g` comes with a coercion to the product type `X × Y`. example (p : PullbackObj f g) : X × Y := p /-- The explicit pullback cone on `PullbackObj f g`. This is bundled with the `IsLimit` data as `pullbackLimitCone f g`. -/ abbrev pullbackCone : Limits.PullbackCone f g := PullbackCone.mk (fun p : PullbackObj f g => p.1.1) (fun p => p.1.2) (funext fun p => p.2) /-- The explicit pullback in the category of types, bundled up as a `LimitCone` for given `f` and `g`. -/ @[simps] def pullbackLimitCone (f : X ⟶ Z) (g : Y ⟶ Z) : Limits.LimitCone (cospan f g) where cone := pullbackCone f g isLimit := PullbackCone.isLimitAux _ (fun s x => ⟨⟨s.fst x, s.snd x⟩, congr_fun s.condition x⟩) (by aesop) (by aesop) fun s m w => funext fun x => Subtype.ext <| Prod.ext (congr_fun (w WalkingCospan.left) x) (congr_fun (w WalkingCospan.right) x) end Pullback end Types section Pullback variable {X Y S : Type v} {f : X ⟶ S} {g : Y ⟶ S} {c : PullbackCone f g} namespace PullbackCone namespace IsLimit variable (hc : IsLimit c) /-- A limit pullback cone in the category of types identifies to the explicit pullback. -/ noncomputable def equivPullbackObj : c.pt ≃ Types.PullbackObj f g := (IsLimit.conePointUniqueUpToIso hc (Types.pullbackLimitCone f g).isLimit).toEquiv @[simp] lemma equivPullbackObj_apply_fst (x : c.pt) : (equivPullbackObj hc x).1.1 = c.fst x := congr_fun (IsLimit.conePointUniqueUpToIso_hom_comp hc (Types.pullbackLimitCone f g).isLimit .left) x @[simp] lemma equivPullbackObj_apply_snd (x : c.pt) : (equivPullbackObj hc x).1.2 = c.snd x := congr_fun (IsLimit.conePointUniqueUpToIso_hom_comp hc (Types.pullbackLimitCone f g).isLimit .right) x @[simp] lemma equivPullbackObj_symm_apply_fst (x : Types.PullbackObj f g) : c.fst ((equivPullbackObj hc).symm x) = x.1.1 := by obtain ⟨x, rfl⟩ := (equivPullbackObj hc).surjective x simp @[simp] lemma equivPullbackObj_symm_apply_snd (x : Types.PullbackObj f g) : c.snd ((equivPullbackObj hc).symm x) = x.1.2 := by obtain ⟨x, rfl⟩ := (equivPullbackObj hc).surjective x simp lemma type_ext {x y : c.pt} (h₁ : c.fst x = c.fst y) (h₂ : c.snd x = c.snd y) : x = y := (equivPullbackObj hc).injective (by ext <;> assumption) end IsLimit variable (c) /-- Given `c : PullbackCone f g` in the category of types, this is the canonical map `c.pt → Types.PullbackObj f g`. -/ @[simps coe_fst coe_snd] def toPullbackObj (x : c.pt) : Types.PullbackObj f g := ⟨⟨c.fst x, c.snd x⟩, congr_fun c.condition x⟩ /-- A pullback cone `c` in the category of types is limit iff the map `c.toPullbackObj : c.pt → Types.PullbackObj f g` is a bijection. -/ noncomputable def isLimitEquivBijective : IsLimit c ≃ Function.Bijective c.toPullbackObj where toFun h := (IsLimit.equivPullbackObj h).bijective invFun h := IsLimit.ofIsoLimit (Types.pullbackLimitCone f g).isLimit (Iso.symm (PullbackCone.ext (Equiv.ofBijective _ h).toIso)) left_inv _ := Subsingleton.elim _ _ right_inv _ := rfl end PullbackCone end Pullback namespace Types section Pullback open CategoryTheory.Limits.WalkingCospan variable {W X Y Z : Type u} variable (f : X ⟶ Z) (g : Y ⟶ Z) /-- The pullback given by the instance `HasPullbacks (Type u)` is isomorphic to the explicit pullback object given by `PullbackObj`. -/ noncomputable def pullbackIsoPullback : pullback f g ≅ PullbackObj f g := (PullbackCone.IsLimit.equivPullbackObj (pullbackIsPullback f g)).toIso @[simp] theorem pullbackIsoPullback_hom_fst (p : pullback f g) : ((pullbackIsoPullback f g).hom p : X × Y).fst = (pullback.fst f g) p := PullbackCone.IsLimit.equivPullbackObj_apply_fst (pullbackIsPullback f g) p @[simp] theorem pullbackIsoPullback_hom_snd (p : pullback f g) : ((pullbackIsoPullback f g).hom p : X × Y).snd = (pullback.snd f g) p := PullbackCone.IsLimit.equivPullbackObj_apply_snd (pullbackIsPullback f g) p @[simp] theorem pullbackIsoPullback_inv_fst_apply (x : (Types.pullbackCone f g).pt) : (pullback.fst f g) ((pullbackIsoPullback f g).inv x) = (fun p => (p.1 : X × Y).fst) x := PullbackCone.IsLimit.equivPullbackObj_symm_apply_fst (pullbackIsPullback f g) x @[simp] theorem pullbackIsoPullback_inv_snd_apply (x : (Types.pullbackCone f g).pt) : (pullback.snd f g) ((pullbackIsoPullback f g).inv x) = (fun p => (p.1 : X × Y).snd) x := PullbackCone.IsLimit.equivPullbackObj_symm_apply_snd (pullbackIsPullback f g) x @[simp] theorem pullbackIsoPullback_inv_fst : (pullbackIsoPullback f g).inv ≫ pullback.fst _ _ = fun p => (p.1 : X × Y).fst := by aesop @[simp] theorem pullbackIsoPullback_inv_snd : (pullbackIsoPullback f g).inv ≫ pullback.snd _ _ = fun p => (p.1 : X × Y).snd := by aesop end Pullback section Pushout variable {S X₁ X₂ : Type u} (f : S ⟶ X₁) (g : S ⟶ X₂) /-- The pushout of two maps `f : S ⟶ X₁` and `g : S ⟶ X₂` is the quotient by the equivalence relation on `X₁ ⊕ X₂` generated by this relation. -/ inductive Pushout.Rel (f : S ⟶ X₁) (g : S ⟶ X₂) : X₁ ⊕ X₂ → X₁ ⊕ X₂ → Prop | inl_inr (s : S) : Pushout.Rel f g (Sum.inl (f s)) (Sum.inr (g s)) /-- Construction of the pushout in the category of types, as a quotient of `X₁ ⊕ X₂`. -/ def Pushout : Type u := _root_.Quot (Pushout.Rel f g) /-- In case `f : S ⟶ X₁` is a monomorphism, this relation is the equivalence relation generated by `Pushout.Rel f g`. -/ inductive Pushout.Rel' : X₁ ⊕ X₂ → X₁ ⊕ X₂ → Prop | refl (x : X₁ ⊕ X₂) : Rel' x x | inl_inl (x₀ y₀ : S) (h : g x₀ = g y₀) : Rel' (Sum.inl (f x₀)) (Sum.inl (f y₀)) | inl_inr (s : S) : Rel' (Sum.inl (f s)) (Sum.inr (g s)) | inr_inl (s : S) : Rel' (Sum.inr (g s)) (Sum.inl (f s)) /-- The quotient of `X₁ ⊕ X₂` by the relation `PushoutRel' f g`. -/ def Pushout' : Type u := _root_.Quot (Pushout.Rel' f g) namespace Pushout /-- The left inclusion in the constructed pushout `Pushout f g`. -/ @[simp] def inl : X₁ ⟶ Pushout f g := fun x => Quot.mk _ (Sum.inl x) /-- The right inclusion in the constructed pushout `Pushout f g`. -/ @[simp] def inr : X₂ ⟶ Pushout f g := fun x => Quot.mk _ (Sum.inr x) lemma condition : f ≫ inl f g = g ≫ inr f g := by ext x exact Quot.sound (Rel.inl_inr x) /-- The constructed pushout cocone in the category of types. -/ @[simps!] def cocone : PushoutCocone f g := PushoutCocone.mk _ _ (condition f g) /-- The cocone `cocone f g` is colimit. -/ def isColimitCocone : IsColimit (cocone f g) := PushoutCocone.IsColimit.mk _ (fun s => Quot.lift (fun x => match x with | Sum.inl x₁ => s.inl x₁ | Sum.inr x₂ => s.inr x₂) (by rintro _ _ ⟨t⟩ exact congr_fun s.condition t)) (fun _ => rfl) (fun _ => rfl) (fun s m h₁ h₂ => by ext ⟨x₁|x₂⟩ · exact congr_fun h₁ x₁ · exact congr_fun h₂ x₂) @[simp] lemma inl_rel'_inl_iff (x₁ y₁ : X₁) : Rel' f g (Sum.inl x₁) (Sum.inl y₁) ↔ x₁ = y₁ ∨ ∃ (x₀ y₀ : S) (_ : g x₀ = g y₀), x₁ = f x₀ ∧ y₁ = f y₀ := by constructor · rintro (_|⟨_, _, h⟩) · exact Or.inl rfl · exact Or.inr ⟨_, _, h, rfl, rfl⟩ · rintro (rfl | ⟨_,_ , h, rfl, rfl⟩) · apply Rel'.refl · exact Rel'.inl_inl _ _ h @[simp] lemma inl_rel'_inr_iff (x₁ : X₁) (x₂ : X₂) : Rel' f g (Sum.inl x₁) (Sum.inr x₂) ↔ ∃ (s : S), x₁ = f s ∧ x₂ = g s := by constructor · rintro ⟨_⟩ exact ⟨_, rfl, rfl⟩ · rintro ⟨s, rfl, rfl⟩ exact Rel'.inl_inr _ @[simp] lemma inr_rel'_inr_iff (x₂ y₂ : X₂) : Rel' f g (Sum.inr x₂) (Sum.inr y₂) ↔ x₂ = y₂ := by constructor · rintro ⟨_⟩ rfl · rintro rfl apply Rel'.refl variable {f g} lemma Rel'.symm {x y : X₁ ⊕ X₂} (h : Rel' f g x y) : Rel' f g y x := by obtain _|⟨_, _, h⟩|_|_ := h · apply Rel'.refl · exact Rel'.inl_inl _ _ h.symm · exact Rel'.inr_inl _ · exact Rel'.inl_inr _ variable (f g) lemma equivalence_rel' [Mono f] : _root_.Equivalence (Rel' f g) where refl := Rel'.refl symm h := h.symm trans := by rintro x y z (_|⟨_, _, h⟩|s|_) hyz · exact hyz · obtain z₁|z₂ := z · rw [inl_rel'_inl_iff] at hyz obtain rfl|⟨_, _, h', h'', rfl⟩ := hyz · exact Rel'.inl_inl _ _ h · obtain rfl := (mono_iff_injective f).1 inferInstance h'' exact Rel'.inl_inl _ _ (h.trans h') · rw [inl_rel'_inr_iff] at hyz obtain ⟨s, hs, rfl⟩ := hyz obtain rfl := (mono_iff_injective f).1 inferInstance hs rw [← h] apply Rel'.inl_inr · obtain z₁|z₂ := z · replace hyz := hyz.symm rw [inl_rel'_inr_iff] at hyz obtain ⟨s', rfl, hs'⟩ := hyz exact Rel'.inl_inl _ _ hs' · rw [inr_rel'_inr_iff] at hyz subst hyz apply Rel'.inl_inr · obtain z₁|z₂ := z · rw [inl_rel'_inl_iff] at hyz obtain rfl|⟨_, _, h, h', rfl⟩ := hyz · apply Rel'.inr_inl · obtain rfl := (mono_iff_injective f).1 inferInstance h' rw [h] apply Rel'.inr_inl · rw [inl_rel'_inr_iff] at hyz obtain ⟨s, hs, rfl⟩ := hyz obtain rfl := (mono_iff_injective f).1 inferInstance hs apply Rel'.refl /-- The obvious equivalence `Pushout f g ≃ Pushout' f g`. -/ def equivPushout' : Pushout f g ≃ Pushout' f g where toFun := Quot.lift (Quot.mk _) (by rintro _ _ ⟨⟩ apply Quot.sound apply Rel'.inl_inr) invFun := Quot.lift (Quot.mk _) (by rintro a b (_|⟨x₀, y₀, h⟩|_|_) · rfl · have h₀ : Rel f g _ _ := Rel.inl_inr x₀ rw [Quot.sound h₀, h] symm apply Quot.sound apply Rel.inl_inr · apply Quot.sound apply Rel.inl_inr · symm apply Quot.sound apply Rel.inl_inr) left_inv := by rintro ⟨x⟩; rfl right_inv := by rintro ⟨x⟩; rfl lemma quot_mk_eq_iff [Mono f] (a b : X₁ ⊕ X₂) : (Quot.mk _ a : Pushout f g) = Quot.mk _ b ↔ Rel' f g a b := by rw [← (equivalence_rel' f g).quot_mk_eq_iff] exact ⟨fun h => (equivPushout' f g).symm.injective h, fun h => (equivPushout' f g).injective h⟩ lemma inl_eq_inr_iff [Mono f] (x₁ : X₁) (x₂ : X₂) : (inl f g x₁ = inr f g x₂) ↔ ∃ (s : S), f s = x₁ ∧ g s = x₂ := by refine (Pushout.quot_mk_eq_iff f g (Sum.inl x₁) (Sum.inr x₂)).trans ?_ constructor · rintro ⟨⟩ exact ⟨_, rfl, rfl⟩ · rintro ⟨s, rfl, rfl⟩ apply Rel'.inl_inr end Pushout variable {f g} lemma pushoutCocone_inl_eq_inr_imp_of_iso {c c' : PushoutCocone f g} (e : c ≅ c') (x₁ : X₁) (x₂ : X₂) (h : c.inl x₁ = c.inr x₂) : c'.inl x₁ = c'.inr x₂ := by convert congr_arg e.hom.hom h · exact congr_fun (e.hom.w WalkingSpan.left).symm x₁ · exact congr_fun (e.hom.w WalkingSpan.right).symm x₂ lemma pushoutCocone_inl_eq_inr_iff_of_iso {c c' : PushoutCocone f g} (e : c ≅ c') (x₁ : X₁) (x₂ : X₂) : c.inl x₁ = c.inr x₂ ↔ c'.inl x₁ = c'.inr x₂ := by constructor · apply pushoutCocone_inl_eq_inr_imp_of_iso e · apply pushoutCocone_inl_eq_inr_imp_of_iso e.symm lemma pushoutCocone_inl_eq_inr_iff_of_isColimit {c : PushoutCocone f g} (hc : IsColimit c) (h₁ : Function.Injective f) (x₁ : X₁) (x₂ : X₂) : c.inl x₁ = c.inr x₂ ↔ ∃ (s : S), f s = x₁ ∧ g s = x₂ := by rw [pushoutCocone_inl_eq_inr_iff_of_iso (Cocones.ext (IsColimit.coconePointUniqueUpToIso hc (Pushout.isColimitCocone f g)) (by aesop_cat))] have := (mono_iff_injective f).2 h₁ apply Pushout.inl_eq_inr_iff end Pushout end Types section Multiequalizer variable (I : MulticospanIndex (Type u)) /-- Given `I : MulticospanIndex (Type u)`, this is a type which identifies to the sections of the functor `I.multicospan`. -/ @[ext] structure MulticospanIndex.sections where /-- The data of an element in `I.left i` for each `i : I.L`. -/ val (i : I.L) : I.left i property (r : I.R) : I.fst r (val _) = I.snd r (val _) /-- The bijection `I.sections ≃ I.multicospan.sections` when `I : MulticospanIndex (Type u)` is a multiequalizer diagram in the category of types. -/ @[simps] def MulticospanIndex.sectionsEquiv : I.sections ≃ I.multicospan.sections where toFun s := { val := fun i ↦ match i with | .left i => s.val i | .right j => I.fst j (s.val _) property := by rintro _ _ (_|_|r) · rfl · rfl · exact (s.property r).symm } invFun s := { val := fun i ↦ s.val (.left i) property := fun r ↦ (s.property (.fst r)).trans (s.property (.snd r)).symm } left_inv _ := rfl right_inv s := by ext (_|r) · rfl · exact s.property (.fst r) namespace Multifork variable {I} variable (c : Multifork I) /-- Given a multiequalizer diagram `I : MulticospanIndex (Type u)` in the category of types and `c` a multifork for `I`, this is the canonical map `c.pt → I.sections`. -/ @[simps] def toSections (x : c.pt) : I.sections where val i := c.ι i x property r := congr_fun (c.condition r) x lemma toSections_fac : I.sectionsEquiv.symm ∘ Types.sectionOfCone c = c.toSections := rfl /-- A multifork `c : Multifork I` in the category of types is limit iff the map `c.toSections : c.pt → I.sections` is a bijection. -/ lemma isLimit_types_iff : Nonempty (IsLimit c) ↔ Function.Bijective c.toSections := by rw [Types.isLimit_iff_bijective_sectionOfCone, ← toSections_fac, EquivLike.comp_bijective] namespace IsLimit variable {c} variable (hc : IsLimit c) /-- The bijection `I.sections ≃ c.pt` when `c : Multifork I` is a limit multifork in the category of types. -/ noncomputable def sectionsEquiv : I.sections ≃ c.pt := (Equiv.ofBijective _ (c.isLimit_types_iff.1 ⟨hc⟩)).symm @[simp] lemma sectionsEquiv_symm_apply_val (x : c.pt) (i : I.L) : ((sectionsEquiv hc).symm x).val i = c.ι i x := rfl @[simp] lemma sectionsEquiv_apply_val (s : I.sections) (i : I.L) : c.ι i (sectionsEquiv hc s) = s.val i := by obtain ⟨x, rfl⟩ := (sectionsEquiv hc).symm.surjective s simp end IsLimit end Multifork end Multiequalizer end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\WideEqualizers.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Limits.Shapes.Equalizers /-! # Wide equalizers and wide coequalizers This file defines wide (co)equalizers as special cases of (co)limits. A wide equalizer for the family of morphisms `X ⟶ Y` indexed by `J` is the categorical generalization of the subobject `{a ∈ A | ∀ j₁ j₂, f(j₁, a) = f(j₂, a)}`. Note that if `J` has fewer than two morphisms this condition is trivial, so some lemmas and definitions assume `J` is nonempty. ## Main definitions * `WalkingParallelFamily` is the indexing category used for wide (co)equalizer diagrams * `parallelFamily` is a functor from `WalkingParallelFamily` to our category `C`. * a `Trident` is a cone over a parallel family. * there is really only one interesting morphism in a trident: the arrow from the vertex of the trident to the domain of f and g. It is called `Trident.ι`. * a `wideEqualizer` is now just a `limit (parallelFamily f)` Each of these has a dual. ## Main statements * `wideEqualizer.ι_mono` states that every wideEqualizer map is a monomorphism ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1] -/ noncomputable section namespace CategoryTheory.Limits open CategoryTheory universe w v u u₂ variable {J : Type w} /-- The type of objects for the diagram indexing a wide (co)equalizer. -/ inductive WalkingParallelFamily (J : Type w) : Type w | zero : WalkingParallelFamily J | one : WalkingParallelFamily J open WalkingParallelFamily instance : DecidableEq (WalkingParallelFamily J) | zero, zero => isTrue rfl | zero, one => isFalse fun t => WalkingParallelFamily.noConfusion t | one, zero => isFalse fun t => WalkingParallelFamily.noConfusion t | one, one => isTrue rfl instance : Inhabited (WalkingParallelFamily J) := ⟨zero⟩ /-- The type family of morphisms for the diagram indexing a wide (co)equalizer. -/ inductive WalkingParallelFamily.Hom (J : Type w) : WalkingParallelFamily J → WalkingParallelFamily J → Type w | id : ∀ X : WalkingParallelFamily.{w} J, WalkingParallelFamily.Hom J X X | line : J → WalkingParallelFamily.Hom J zero one deriving DecidableEq /-- Satisfying the inhabited linter -/ instance (J : Type v) : Inhabited (WalkingParallelFamily.Hom J zero zero) where default := Hom.id _ open WalkingParallelFamily.Hom /-- Composition of morphisms in the indexing diagram for wide (co)equalizers. -/ def WalkingParallelFamily.Hom.comp : ∀ {X Y Z : WalkingParallelFamily J} (_ : WalkingParallelFamily.Hom J X Y) (_ : WalkingParallelFamily.Hom J Y Z), WalkingParallelFamily.Hom J X Z | _, _, _, id _, h => h | _, _, _, line j, id one => line j -- attribute [local tidy] tactic.case_bash Porting note: no tidy, no local instance WalkingParallelFamily.category : SmallCategory (WalkingParallelFamily J) where Hom := WalkingParallelFamily.Hom J id := WalkingParallelFamily.Hom.id comp := WalkingParallelFamily.Hom.comp assoc f g h := by cases f <;> cases g <;> cases h <;> aesop_cat comp_id f := by cases f <;> aesop_cat @[simp] theorem WalkingParallelFamily.hom_id (X : WalkingParallelFamily J) : WalkingParallelFamily.Hom.id X = 𝟙 X := rfl variable {C : Type u} [Category.{v} C] variable {X Y : C} (f : J → (X ⟶ Y)) /-- `parallelFamily f` is the diagram in `C` consisting of the given family of morphisms, each with common domain and codomain. -/ def parallelFamily : WalkingParallelFamily J ⥤ C where obj x := WalkingParallelFamily.casesOn x X Y map {x y} h := match x, y, h with | _, _, Hom.id _ => 𝟙 _ | _, _, line j => f j map_comp := by rintro _ _ _ ⟨⟩ ⟨⟩ <;> · aesop_cat @[simp] theorem parallelFamily_obj_zero : (parallelFamily f).obj zero = X := rfl @[simp] theorem parallelFamily_obj_one : (parallelFamily f).obj one = Y := rfl @[simp] theorem parallelFamily_map_left {j : J} : (parallelFamily f).map (line j) = f j := rfl /-- Every functor indexing a wide (co)equalizer is naturally isomorphic (actually, equal) to a `parallelFamily` -/ @[simps!] def diagramIsoParallelFamily (F : WalkingParallelFamily J ⥤ C) : F ≅ parallelFamily fun j => F.map (line j) := NatIso.ofComponents (fun j => eqToIso <| by cases j <;> aesop_cat) <| by rintro _ _ (_|_) <;> aesop_cat /-- `WalkingParallelPair` as a category is equivalent to a special case of `WalkingParallelFamily`. -/ @[simps!] def walkingParallelFamilyEquivWalkingParallelPair : WalkingParallelFamily.{w} (ULift Bool) ≌ WalkingParallelPair where functor := parallelFamily fun p => cond p.down WalkingParallelPairHom.left WalkingParallelPairHom.right inverse := parallelPair (line (ULift.up true)) (line (ULift.up false)) unitIso := NatIso.ofComponents (fun X => eqToIso (by cases X <;> rfl)) (by rintro _ _ (_|⟨_|_⟩) <;> aesop_cat) counitIso := NatIso.ofComponents (fun X => eqToIso (by cases X <;> rfl)) (by rintro _ _ (_|_|_) <;> aesop_cat) functor_unitIso_comp := by rintro (_|_) <;> aesop_cat /-- A trident on `f` is just a `Cone (parallelFamily f)`. -/ abbrev Trident := Cone (parallelFamily f) /-- A cotrident on `f` and `g` is just a `Cocone (parallelFamily f)`. -/ abbrev Cotrident := Cocone (parallelFamily f) variable {f} /-- A trident `t` on the parallel family `f : J → (X ⟶ Y)` consists of two morphisms `t.π.app zero : t.X ⟶ X` and `t.π.app one : t.X ⟶ Y`. Of these, only the first one is interesting, and we give it the shorter name `Trident.ι t`. -/ abbrev Trident.ι (t : Trident f) := t.π.app zero /-- A cotrident `t` on the parallel family `f : J → (X ⟶ Y)` consists of two morphisms `t.ι.app zero : X ⟶ t.X` and `t.ι.app one : Y ⟶ t.X`. Of these, only the second one is interesting, and we give it the shorter name `Cotrident.π t`. -/ abbrev Cotrident.π (t : Cotrident f) := t.ι.app one @[simp] theorem Trident.ι_eq_app_zero (t : Trident f) : t.ι = t.π.app zero := rfl @[simp] theorem Cotrident.π_eq_app_one (t : Cotrident f) : t.π = t.ι.app one := rfl @[reassoc (attr := simp)] theorem Trident.app_zero (s : Trident f) (j : J) : s.π.app zero ≫ f j = s.π.app one := by rw [← s.w (line j), parallelFamily_map_left] @[reassoc (attr := simp)] theorem Cotrident.app_one (s : Cotrident f) (j : J) : f j ≫ s.ι.app one = s.ι.app zero := by rw [← s.w (line j), parallelFamily_map_left] /-- A trident on `f : J → (X ⟶ Y)` is determined by the morphism `ι : P ⟶ X` satisfying `∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂`. -/ @[simps] def Trident.ofι [Nonempty J] {P : C} (ι : P ⟶ X) (w : ∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂) : Trident f where pt := P π := { app := fun X => WalkingParallelFamily.casesOn X ι (ι ≫ f (Classical.arbitrary J)) naturality := fun i j f => by dsimp cases' f with _ k · simp · simp [w (Classical.arbitrary J) k] } /-- A cotrident on `f : J → (X ⟶ Y)` is determined by the morphism `π : Y ⟶ P` satisfying `∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π`. -/ @[simps] def Cotrident.ofπ [Nonempty J] {P : C} (π : Y ⟶ P) (w : ∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π) : Cotrident f where pt := P ι := { app := fun X => WalkingParallelFamily.casesOn X (f (Classical.arbitrary J) ≫ π) π naturality := fun i j f => by dsimp cases' f with _ k · simp · simp [w (Classical.arbitrary J) k] } -- See note [dsimp, simp] theorem Trident.ι_ofι [Nonempty J] {P : C} (ι : P ⟶ X) (w : ∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂) : (Trident.ofι ι w).ι = ι := rfl theorem Cotrident.π_ofπ [Nonempty J] {P : C} (π : Y ⟶ P) (w : ∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π) : (Cotrident.ofπ π w).π = π := rfl @[reassoc] theorem Trident.condition (j₁ j₂ : J) (t : Trident f) : t.ι ≫ f j₁ = t.ι ≫ f j₂ := by rw [t.app_zero, t.app_zero] @[reassoc] theorem Cotrident.condition (j₁ j₂ : J) (t : Cotrident f) : f j₁ ≫ t.π = f j₂ ≫ t.π := by rw [t.app_one, t.app_one] /-- To check whether two maps are equalized by both maps of a trident, it suffices to check it for the first map -/ theorem Trident.equalizer_ext [Nonempty J] (s : Trident f) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelFamily J, k ≫ s.π.app j = l ≫ s.π.app j | zero => h | one => by rw [← s.app_zero (Classical.arbitrary J), reassoc_of% h] /-- To check whether two maps are coequalized by both maps of a cotrident, it suffices to check it for the second map -/ theorem Cotrident.coequalizer_ext [Nonempty J] (s : Cotrident f) {W : C} {k l : s.pt ⟶ W} (h : s.π ≫ k = s.π ≫ l) : ∀ j : WalkingParallelFamily J, s.ι.app j ≫ k = s.ι.app j ≫ l | zero => by rw [← s.app_one (Classical.arbitrary J), Category.assoc, Category.assoc, h] | one => h theorem Trident.IsLimit.hom_ext [Nonempty J] {s : Trident f} (hs : IsLimit s) {W : C} {k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : k = l := hs.hom_ext <| Trident.equalizer_ext _ h theorem Cotrident.IsColimit.hom_ext [Nonempty J] {s : Cotrident f} (hs : IsColimit s) {W : C} {k l : s.pt ⟶ W} (h : s.π ≫ k = s.π ≫ l) : k = l := hs.hom_ext <| Cotrident.coequalizer_ext _ h /-- If `s` is a limit trident over `f`, then a morphism `k : W ⟶ X` satisfying `∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂` induces a morphism `l : W ⟶ s.X` such that `l ≫ Trident.ι s = k`. -/ def Trident.IsLimit.lift' [Nonempty J] {s : Trident f} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : { l : W ⟶ s.pt // l ≫ Trident.ι s = k } := ⟨hs.lift <| Trident.ofι _ h, hs.fac _ _⟩ /-- If `s` is a colimit cotrident over `f`, then a morphism `k : Y ⟶ W` satisfying `∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k` induces a morphism `l : s.X ⟶ W` such that `Cotrident.π s ≫ l = k`. -/ def Cotrident.IsColimit.desc' [Nonempty J] {s : Cotrident f} (hs : IsColimit s) {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : { l : s.pt ⟶ W // Cotrident.π s ≫ l = k } := ⟨hs.desc <| Cotrident.ofπ _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a trident is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def Trident.IsLimit.mk [Nonempty J] (t : Trident f) (lift : ∀ s : Trident f, s.pt ⟶ t.pt) (fac : ∀ s : Trident f, lift s ≫ t.ι = s.ι) (uniq : ∀ (s : Trident f) (m : s.pt ⟶ t.pt) (_ : ∀ j : WalkingParallelFamily J, m ≫ t.π.app j = s.π.app j), m = lift s) : IsLimit t := { lift fac := fun s j => WalkingParallelFamily.casesOn j (fac s) (by rw [← t.w (line (Classical.arbitrary J)), reassoc_of% fac, s.w]) uniq := uniq } /-- This is another convenient method to verify that a trident is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Trident.IsLimit.mk' [Nonempty J] (t : Trident f) (create : ∀ s : Trident f, { l // l ≫ t.ι = s.ι ∧ ∀ {m}, m ≫ t.ι = s.ι → m = l }) : IsLimit t := Trident.IsLimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 (w zero) /-- This is a slightly more convenient method to verify that a cotrident is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def Cotrident.IsColimit.mk [Nonempty J] (t : Cotrident f) (desc : ∀ s : Cotrident f, t.pt ⟶ s.pt) (fac : ∀ s : Cotrident f, t.π ≫ desc s = s.π) (uniq : ∀ (s : Cotrident f) (m : t.pt ⟶ s.pt) (_ : ∀ j : WalkingParallelFamily J, t.ι.app j ≫ m = s.ι.app j), m = desc s) : IsColimit t := { desc fac := fun s j => WalkingParallelFamily.casesOn j (by rw [← t.w_assoc (line (Classical.arbitrary J)), fac, s.w]) (fac s) uniq := uniq } /-- This is another convenient method to verify that a cotrident is a colimit cocone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def Cotrident.IsColimit.mk' [Nonempty J] (t : Cotrident f) (create : ∀ s : Cotrident f, { l : t.pt ⟶ s.pt // t.π ≫ l = s.π ∧ ∀ {m}, t.π ≫ m = s.π → m = l }) : IsColimit t := Cotrident.IsColimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w => (create s).2.2 (w one) /-- Given a limit cone for the family `f : J → (X ⟶ Y)`, for any `Z`, morphisms from `Z` to its point are in bijection with morphisms `h : Z ⟶ X` such that `∀ j₁ j₂, h ≫ f j₁ = h ≫ f j₂`. Further, this bijection is natural in `Z`: see `Trident.Limits.homIso_natural`. -/ @[simps] def Trident.IsLimit.homIso [Nonempty J] {t : Trident f} (ht : IsLimit t) (Z : C) : (Z ⟶ t.pt) ≃ { h : Z ⟶ X // ∀ j₁ j₂, h ≫ f j₁ = h ≫ f j₂ } where toFun k := ⟨k ≫ t.ι, by simp⟩ invFun h := (Trident.IsLimit.lift' ht _ h.prop).1 left_inv k := Trident.IsLimit.hom_ext ht (Trident.IsLimit.lift' _ _ _).prop right_inv h := Subtype.ext (Trident.IsLimit.lift' ht _ _).prop /-- The bijection of `Trident.IsLimit.homIso` is natural in `Z`. -/ theorem Trident.IsLimit.homIso_natural [Nonempty J] {t : Trident f} (ht : IsLimit t) {Z Z' : C} (q : Z' ⟶ Z) (k : Z ⟶ t.pt) : (Trident.IsLimit.homIso ht _ (q ≫ k) : Z' ⟶ X) = q ≫ (Trident.IsLimit.homIso ht _ k : Z ⟶ X) := Category.assoc _ _ _ /-- Given a colimit cocone for the family `f : J → (X ⟶ Y)`, for any `Z`, morphisms from the cocone point to `Z` are in bijection with morphisms `h : Z ⟶ X` such that `∀ j₁ j₂, f j₁ ≫ h = f j₂ ≫ h`. Further, this bijection is natural in `Z`: see `Cotrident.IsColimit.homIso_natural`. -/ @[simps] def Cotrident.IsColimit.homIso [Nonempty J] {t : Cotrident f} (ht : IsColimit t) (Z : C) : (t.pt ⟶ Z) ≃ { h : Y ⟶ Z // ∀ j₁ j₂, f j₁ ≫ h = f j₂ ≫ h } where toFun k := ⟨t.π ≫ k, by simp⟩ invFun h := (Cotrident.IsColimit.desc' ht _ h.prop).1 left_inv k := Cotrident.IsColimit.hom_ext ht (Cotrident.IsColimit.desc' _ _ _).prop right_inv h := Subtype.ext (Cotrident.IsColimit.desc' ht _ _).prop /-- The bijection of `Cotrident.IsColimit.homIso` is natural in `Z`. -/ theorem Cotrident.IsColimit.homIso_natural [Nonempty J] {t : Cotrident f} {Z Z' : C} (q : Z ⟶ Z') (ht : IsColimit t) (k : t.pt ⟶ Z) : (Cotrident.IsColimit.homIso ht _ (k ≫ q) : Y ⟶ Z') = (Cotrident.IsColimit.homIso ht _ k : Y ⟶ Z) ≫ q := (Category.assoc _ _ _).symm /-- This is a helper construction that can be useful when verifying that a category has certain wide equalizers. Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (fun j ↦ F.map (line j))`, and a trident on `fun j ↦ F.map (line j)`, we get a cone on `F`. If you're thinking about using this, have a look at `hasWideEqualizers_of_hasLimit_parallelFamily`, which you may find to be an easier way of achieving your goal. -/ def Cone.ofTrident {F : WalkingParallelFamily J ⥤ C} (t : Trident fun j => F.map (line j)) : Cone F where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by cases X <;> aesop_cat) naturality := fun j j' g => by cases g <;> aesop_cat } /-- This is a helper construction that can be useful when verifying that a category has all coequalizers. Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (fun j ↦ F.map (line j))`, and a cotrident on `fun j ↦ F.map (line j)` we get a cocone on `F`. If you're thinking about using this, have a look at `hasWideCoequalizers_of_hasColimit_parallelFamily`, which you may find to be an easier way of achieving your goal. -/ def Cocone.ofCotrident {F : WalkingParallelFamily J ⥤ C} (t : Cotrident fun j => F.map (line j)) : Cocone F where pt := t.pt ι := { app := fun X => eqToHom (by cases X <;> aesop_cat) ≫ t.ι.app X naturality := fun j j' g => by cases g <;> dsimp <;> simp [Cotrident.app_one t] } @[simp] theorem Cone.ofTrident_π {F : WalkingParallelFamily J ⥤ C} (t : Trident fun j => F.map (line j)) (j) : (Cone.ofTrident t).π.app j = t.π.app j ≫ eqToHom (by cases j <;> aesop_cat) := rfl @[simp] theorem Cocone.ofCotrident_ι {F : WalkingParallelFamily J ⥤ C} (t : Cotrident fun j => F.map (line j)) (j) : (Cocone.ofCotrident t).ι.app j = eqToHom (by cases j <;> aesop_cat) ≫ t.ι.app j := rfl /-- Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (fun j ↦ F.map (line j))` and a cone on `F`, we get a trident on `fun j ↦ F.map (line j)`. -/ def Trident.ofCone {F : WalkingParallelFamily J ⥤ C} (t : Cone F) : Trident fun j => F.map (line j) where pt := t.pt π := { app := fun X => t.π.app X ≫ eqToHom (by cases X <;> aesop_cat) naturality := by rintro _ _ (_|_) <;> aesop_cat } /-- Given `F : WalkingParallelFamily ⥤ C`, which is really the same as `parallelFamily (F.map left) (F.map right)` and a cocone on `F`, we get a cotrident on `fun j ↦ F.map (line j)`. -/ def Cotrident.ofCocone {F : WalkingParallelFamily J ⥤ C} (t : Cocone F) : Cotrident fun j => F.map (line j) where pt := t.pt ι := { app := fun X => eqToHom (by cases X <;> aesop_cat) ≫ t.ι.app X naturality := by rintro _ _ (_|_) <;> aesop_cat } @[simp] theorem Trident.ofCone_π {F : WalkingParallelFamily J ⥤ C} (t : Cone F) (j) : (Trident.ofCone t).π.app j = t.π.app j ≫ eqToHom (by cases j <;> aesop_cat) := rfl @[simp] theorem Cotrident.ofCocone_ι {F : WalkingParallelFamily J ⥤ C} (t : Cocone F) (j) : (Cotrident.ofCocone t).ι.app j = eqToHom (by cases j <;> aesop_cat) ≫ t.ι.app j := rfl /-- Helper function for constructing morphisms between wide equalizer tridents. -/ @[simps] def Trident.mkHom [Nonempty J] {s t : Trident f} (k : s.pt ⟶ t.pt) (w : k ≫ t.ι = s.ι := by aesop_cat) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · exact w · simpa using w =≫ f (Classical.arbitrary J) /-- To construct an isomorphism between tridents, it suffices to give an isomorphism between the cone points and check that it commutes with the `ι` morphisms. -/ @[simps] def Trident.ext [Nonempty J] {s t : Trident f} (i : s.pt ≅ t.pt) (w : i.hom ≫ t.ι = s.ι := by aesop_cat) : s ≅ t where hom := Trident.mkHom i.hom w inv := Trident.mkHom i.inv (by rw [← w, Iso.inv_hom_id_assoc]) /-- Helper function for constructing morphisms between coequalizer cotridents. -/ @[simps] def Cotrident.mkHom [Nonempty J] {s t : Cotrident f} (k : s.pt ⟶ t.pt) (w : s.π ≫ k = t.π := by aesop_cat) : s ⟶ t where hom := k w := by rintro ⟨_ | _⟩ · simpa using f (Classical.arbitrary J) ≫= w · exact w /-- To construct an isomorphism between cotridents, it suffices to give an isomorphism between the cocone points and check that it commutes with the `π` morphisms. -/ def Cotrident.ext [Nonempty J] {s t : Cotrident f} (i : s.pt ≅ t.pt) (w : s.π ≫ i.hom = t.π := by aesop_cat) : s ≅ t where hom := Cotrident.mkHom i.hom w inv := Cotrident.mkHom i.inv (by rw [Iso.comp_inv_eq, w]) variable (f) section /-- `HasWideEqualizer f` represents a particular choice of limiting cone for the parallel family of morphisms `f`. -/ abbrev HasWideEqualizer := HasLimit (parallelFamily f) variable [HasWideEqualizer f] /-- If a wide equalizer of `f` exists, we can access an arbitrary choice of such by saying `wideEqualizer f`. -/ abbrev wideEqualizer : C := limit (parallelFamily f) /-- If a wide equalizer of `f` exists, we can access the inclusion `wideEqualizer f ⟶ X` by saying `wideEqualizer.ι f`. -/ abbrev wideEqualizer.ι : wideEqualizer f ⟶ X := limit.π (parallelFamily f) zero /-- A wide equalizer cone for a parallel family `f`. -/ abbrev wideEqualizer.trident : Trident f := limit.cone (parallelFamily f) @[simp] theorem wideEqualizer.trident_ι : (wideEqualizer.trident f).ι = wideEqualizer.ι f := rfl @[simp 1100] theorem wideEqualizer.trident_π_app_zero : (wideEqualizer.trident f).π.app zero = wideEqualizer.ι f := rfl @[reassoc] theorem wideEqualizer.condition (j₁ j₂ : J) : wideEqualizer.ι f ≫ f j₁ = wideEqualizer.ι f ≫ f j₂ := Trident.condition j₁ j₂ <| limit.cone <| parallelFamily f /-- The wideEqualizer built from `wideEqualizer.ι f` is limiting. -/ def wideEqualizerIsWideEqualizer [Nonempty J] : IsLimit (Trident.ofι (wideEqualizer.ι f) (wideEqualizer.condition f)) := IsLimit.ofIsoLimit (limit.isLimit _) (Trident.ext (Iso.refl _)) variable {f} /-- A morphism `k : W ⟶ X` satisfying `∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂` factors through the wide equalizer of `f` via `wideEqualizer.lift : W ⟶ wideEqualizer f`. -/ abbrev wideEqualizer.lift [Nonempty J] {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : W ⟶ wideEqualizer f := limit.lift (parallelFamily f) (Trident.ofι k h) @[reassoc (attr := simp 1100)] theorem wideEqualizer.lift_ι [Nonempty J] {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : wideEqualizer.lift k h ≫ wideEqualizer.ι f = k := limit.lift_π _ _ /-- A morphism `k : W ⟶ X` satisfying `∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂` induces a morphism `l : W ⟶ wideEqualizer f` satisfying `l ≫ wideEqualizer.ι f = k`. -/ def wideEqualizer.lift' [Nonempty J] {W : C} (k : W ⟶ X) (h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : { l : W ⟶ wideEqualizer f // l ≫ wideEqualizer.ι f = k } := ⟨wideEqualizer.lift k h, wideEqualizer.lift_ι _ _⟩ /-- Two maps into a wide equalizer are equal if they are equal when composed with the wide equalizer map. -/ @[ext] theorem wideEqualizer.hom_ext [Nonempty J] {W : C} {k l : W ⟶ wideEqualizer f} (h : k ≫ wideEqualizer.ι f = l ≫ wideEqualizer.ι f) : k = l := Trident.IsLimit.hom_ext (limit.isLimit _) h /-- A wide equalizer morphism is a monomorphism -/ instance wideEqualizer.ι_mono [Nonempty J] : Mono (wideEqualizer.ι f) where right_cancellation _ _ w := wideEqualizer.hom_ext w end section variable {f} /-- The wide equalizer morphism in any limit cone is a monomorphism. -/ theorem mono_of_isLimit_parallelFamily [Nonempty J] {c : Cone (parallelFamily f)} (i : IsLimit c) : Mono (Trident.ι c) where right_cancellation _ _ w := Trident.IsLimit.hom_ext i w end section /-- `HasWideCoequalizer f g` represents a particular choice of colimiting cocone for the parallel family of morphisms `f`. -/ abbrev HasWideCoequalizer := HasColimit (parallelFamily f) variable [HasWideCoequalizer f] /-- If a wide coequalizer of `f`, we can access an arbitrary choice of such by saying `wideCoequalizer f`. -/ abbrev wideCoequalizer : C := colimit (parallelFamily f) /-- If a wideCoequalizer of `f` exists, we can access the corresponding projection by saying `wideCoequalizer.π f`. -/ abbrev wideCoequalizer.π : Y ⟶ wideCoequalizer f := colimit.ι (parallelFamily f) one /-- An arbitrary choice of coequalizer cocone for a parallel family `f`. -/ abbrev wideCoequalizer.cotrident : Cotrident f := colimit.cocone (parallelFamily f) @[simp] theorem wideCoequalizer.cotrident_π : (wideCoequalizer.cotrident f).π = wideCoequalizer.π f := rfl @[simp 1100] theorem wideCoequalizer.cotrident_ι_app_one : (wideCoequalizer.cotrident f).ι.app one = wideCoequalizer.π f := rfl @[reassoc] theorem wideCoequalizer.condition (j₁ j₂ : J) : f j₁ ≫ wideCoequalizer.π f = f j₂ ≫ wideCoequalizer.π f := Cotrident.condition j₁ j₂ <| colimit.cocone <| parallelFamily f /-- The cotrident built from `wideCoequalizer.π f` is colimiting. -/ def wideCoequalizerIsWideCoequalizer [Nonempty J] : IsColimit (Cotrident.ofπ (wideCoequalizer.π f) (wideCoequalizer.condition f)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cotrident.ext (Iso.refl _)) variable {f} /-- Any morphism `k : Y ⟶ W` satisfying `∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k` factors through the wide coequalizer of `f` via `wideCoequalizer.desc : wideCoequalizer f ⟶ W`. -/ abbrev wideCoequalizer.desc [Nonempty J] {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : wideCoequalizer f ⟶ W := colimit.desc (parallelFamily f) (Cotrident.ofπ k h) @[reassoc (attr := simp 1100)] theorem wideCoequalizer.π_desc [Nonempty J] {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : wideCoequalizer.π f ≫ wideCoequalizer.desc k h = k := colimit.ι_desc _ _ /-- Any morphism `k : Y ⟶ W` satisfying `∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k` induces a morphism `l : wideCoequalizer f ⟶ W` satisfying `wideCoequalizer.π ≫ g = l`. -/ def wideCoequalizer.desc' [Nonempty J] {W : C} (k : Y ⟶ W) (h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : { l : wideCoequalizer f ⟶ W // wideCoequalizer.π f ≫ l = k } := ⟨wideCoequalizer.desc k h, wideCoequalizer.π_desc _ _⟩ /-- Two maps from a wide coequalizer are equal if they are equal when composed with the wide coequalizer map -/ @[ext] theorem wideCoequalizer.hom_ext [Nonempty J] {W : C} {k l : wideCoequalizer f ⟶ W} (h : wideCoequalizer.π f ≫ k = wideCoequalizer.π f ≫ l) : k = l := Cotrident.IsColimit.hom_ext (colimit.isColimit _) h /-- A wide coequalizer morphism is an epimorphism -/ instance wideCoequalizer.π_epi [Nonempty J] : Epi (wideCoequalizer.π f) where left_cancellation _ _ w := wideCoequalizer.hom_ext w end section variable {f} /-- The wide coequalizer morphism in any colimit cocone is an epimorphism. -/ theorem epi_of_isColimit_parallelFamily [Nonempty J] {c : Cocone (parallelFamily f)} (i : IsColimit c) : Epi (c.ι.app one) where left_cancellation _ _ w := Cotrident.IsColimit.hom_ext i w end variable (C) /-- `HasWideEqualizers` represents a choice of wide equalizer for every family of morphisms -/ abbrev HasWideEqualizers := ∀ J, HasLimitsOfShape (WalkingParallelFamily.{w} J) C /-- `HasWideCoequalizers` represents a choice of wide coequalizer for every family of morphisms -/ abbrev HasWideCoequalizers := ∀ J, HasColimitsOfShape (WalkingParallelFamily.{w} J) C /-- If `C` has all limits of diagrams `parallelFamily f`, then it has all wide equalizers -/ theorem hasWideEqualizers_of_hasLimit_parallelFamily [∀ {J : Type w} {X Y : C} {f : J → (X ⟶ Y)}, HasLimit (parallelFamily f)] : HasWideEqualizers.{w} C := fun _ => { has_limit := fun F => hasLimitOfIso (diagramIsoParallelFamily F).symm } /-- If `C` has all colimits of diagrams `parallelFamily f`, then it has all wide coequalizers -/ theorem hasWideCoequalizers_of_hasColimit_parallelFamily [∀ {J : Type w} {X Y : C} {f : J → (X ⟶ Y)}, HasColimit (parallelFamily f)] : HasWideCoequalizers.{w} C := fun _ => { has_colimit := fun F => hasColimitOfIso (diagramIsoParallelFamily F) } instance (priority := 10) hasEqualizers_of_hasWideEqualizers [HasWideEqualizers.{w} C] : HasEqualizers C := hasLimitsOfShape_of_equivalence.{w} walkingParallelFamilyEquivWalkingParallelPair instance (priority := 10) hasCoequalizers_of_hasWideCoequalizers [HasWideCoequalizers.{w} C] : HasCoequalizers C := hasColimitsOfShape_of_equivalence.{w} walkingParallelFamilyEquivWalkingParallelPair end CategoryTheory.Limits attribute [nolint simpNF] CategoryTheory.Limits.WalkingParallelFamily.Hom.id.sizeOf_spec
CategoryTheory\Limits\Shapes\WidePullbacks.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Thin /-! # Wide pullbacks We define the category `WidePullbackShape`, (resp. `WidePushoutShape`) which is the category obtained from a discrete category of type `J` by adjoining a terminal (resp. initial) element. Limits of this shape are wide pullbacks (pushouts). The convenience method `wideCospan` (`wideSpan`) constructs a functor from this category, hitting the given morphisms. We use `WidePullbackShape` to define ordinary pullbacks (pushouts) by using `J := WalkingPair`, which allows easy proofs of some related lemmas. Furthermore, wide pullbacks are used to show the existence of limits in the slice category. Namely, if `C` has wide pullbacks then `C/B` has limits for any object `B` in `C`. Typeclasses `HasWidePullbacks` and `HasFiniteWidePullbacks` assert the existence of wide pullbacks and finite wide pullbacks. -/ universe w w' v u open CategoryTheory CategoryTheory.Limits Opposite namespace CategoryTheory.Limits variable (J : Type w) /-- A wide pullback shape for any type `J` can be written simply as `Option J`. -/ def WidePullbackShape := Option J -- Porting note: strangely this could be synthesized instance : Inhabited (WidePullbackShape J) where default := none /-- A wide pushout shape for any type `J` can be written simply as `Option J`. -/ def WidePushoutShape := Option J instance : Inhabited (WidePushoutShape J) where default := none namespace WidePullbackShape variable {J} /-- The type of arrows for the shape indexing a wide pullback. -/ inductive Hom : WidePullbackShape J → WidePullbackShape J → Type w | id : ∀ X, Hom X X | term : ∀ j : J, Hom (some j) none deriving DecidableEq -- This is relying on an automatically generated instance name, generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 attribute [nolint unusedArguments] instDecidableEqHom instance struct : CategoryStruct (WidePullbackShape J) where Hom := Hom id j := Hom.id j comp f g := by cases f · exact g cases g apply Hom.term _ instance Hom.inhabited : Inhabited (Hom (none : WidePullbackShape J) none) := ⟨Hom.id (none : WidePullbackShape J)⟩ open Lean Elab Tactic /- Pointing note: experimenting with manual scoping of aesop tactics. Attempted to define aesop rule directing on `WidePushoutOut` and it didn't take for some reason -/ /-- An aesop tactic for bulk cases on morphisms in `WidePushoutShape` -/ def evalCasesBash : TacticM Unit := do evalTactic (← `(tactic| casesm* WidePullbackShape _, (_ : WidePullbackShape _) ⟶ (_ : WidePullbackShape _) )) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] evalCasesBash instance subsingleton_hom : Quiver.IsThin (WidePullbackShape J) := fun _ _ => by constructor intro a b casesm* WidePullbackShape _, (_ : WidePullbackShape _) ⟶ (_ : WidePullbackShape _) · rfl · rfl · rfl instance category : SmallCategory (WidePullbackShape J) := thin_category @[simp] theorem hom_id (X : WidePullbackShape J) : Hom.id X = 𝟙 X := rfl /- Porting note: we get a warning that we should change LHS to `sizeOf (𝟙 X)` but Lean cannot find the category instance on `WidePullbackShape J` in that case. Once supplied in the proof, the proposed proof of `simp [only WidePullbackShape.hom_id]` does not work -/ attribute [nolint simpNF] Hom.id.sizeOf_spec variable {C : Type u} [Category.{v} C] /-- Construct a functor out of the wide pullback shape given a J-indexed collection of arrows to a fixed object. -/ @[simps] def wideCospan (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) : WidePullbackShape J ⥤ C where obj j := Option.casesOn j B objs map f := by cases' f with _ j · apply 𝟙 _ · exact arrows j /-- Every diagram is naturally isomorphic (actually, equal) to a `wideCospan` -/ def diagramIsoWideCospan (F : WidePullbackShape J ⥤ C) : F ≅ wideCospan (F.obj none) (fun j => F.obj (some j)) fun j => F.map (Hom.term j) := NatIso.ofComponents fun j => eqToIso <| by aesop_cat /-- Construct a cone over a wide cospan. -/ @[simps] def mkCone {F : WidePullbackShape J ⥤ C} {X : C} (f : X ⟶ F.obj none) (π : ∀ j, X ⟶ F.obj (some j)) (w : ∀ j, π j ≫ F.map (Hom.term j) = f) : Cone F := { pt := X π := { app := fun j => match j with | none => f | some j => π j naturality := fun j j' f => by cases j <;> cases j' <;> cases f <;> dsimp <;> simp [w] } } /-- Wide pullback diagrams of equivalent index types are equivalent. -/ def equivalenceOfEquiv (J' : Type w') (h : J ≃ J') : WidePullbackShape J ≌ WidePullbackShape J' where functor := wideCospan none (fun j => some (h j)) fun j => Hom.term (h j) inverse := wideCospan none (fun j => some (h.invFun j)) fun j => Hom.term (h.invFun j) unitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) counitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) /-- Lifting universe and morphism levels preserves wide pullback diagrams. -/ def uliftEquivalence : ULiftHom.{w'} (ULift.{w'} (WidePullbackShape J)) ≌ WidePullbackShape (ULift J) := (ULiftHomULiftCategory.equiv.{w', w', w, w} (WidePullbackShape J)).symm.trans (equivalenceOfEquiv _ (Equiv.ulift.{w', w}.symm : J ≃ ULift.{w'} J)) end WidePullbackShape namespace WidePushoutShape variable {J} /-- The type of arrows for the shape indexing a wide pushout. -/ inductive Hom : WidePushoutShape J → WidePushoutShape J → Type w | id : ∀ X, Hom X X | init : ∀ j : J, Hom none (some j) deriving DecidableEq -- This is relying on an automatically generated instance name, generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 attribute [nolint unusedArguments] instDecidableEqHom instance struct : CategoryStruct (WidePushoutShape J) where Hom := Hom id j := Hom.id j comp f g := by cases f · exact g cases g apply Hom.init _ instance Hom.inhabited : Inhabited (Hom (none : WidePushoutShape J) none) := ⟨Hom.id (none : WidePushoutShape J)⟩ open Lean Elab Tactic -- Pointing note: experimenting with manual scoping of aesop tactics; only this worked /-- An aesop tactic for bulk cases on morphisms in `WidePushoutShape` -/ def evalCasesBash' : TacticM Unit := do evalTactic (← `(tactic| casesm* WidePushoutShape _, (_ : WidePushoutShape _) ⟶ (_ : WidePushoutShape _) )) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] evalCasesBash' instance subsingleton_hom : Quiver.IsThin (WidePushoutShape J) := fun _ _ => by constructor intro a b casesm* WidePushoutShape _, (_ : WidePushoutShape _) ⟶ (_ : WidePushoutShape _) repeat rfl instance category : SmallCategory (WidePushoutShape J) := thin_category @[simp] theorem hom_id (X : WidePushoutShape J) : Hom.id X = 𝟙 X := rfl /- Porting note: we get a warning that we should change LHS to `sizeOf (𝟙 X)` but Lean cannot find the category instance on `WidePushoutShape J` in that case. Once supplied in the proof, the proposed proof of `simp [only WidePushoutShape.hom_id]` does not work -/ attribute [nolint simpNF] Hom.id.sizeOf_spec variable {C : Type u} [Category.{v} C] /-- Construct a functor out of the wide pushout shape given a J-indexed collection of arrows from a fixed object. -/ @[simps] def wideSpan (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) : WidePushoutShape J ⥤ C where obj j := Option.casesOn j B objs map f := by cases' f with _ j · apply 𝟙 _ · exact arrows j map_comp := fun f g => by cases f · simp only [Eq.ndrec, hom_id, eq_rec_constant, Category.id_comp]; congr · cases g simp only [Eq.ndrec, hom_id, eq_rec_constant, Category.comp_id]; congr /-- Every diagram is naturally isomorphic (actually, equal) to a `wideSpan` -/ def diagramIsoWideSpan (F : WidePushoutShape J ⥤ C) : F ≅ wideSpan (F.obj none) (fun j => F.obj (some j)) fun j => F.map (Hom.init j) := NatIso.ofComponents fun j => eqToIso <| by cases j; repeat rfl /-- Construct a cocone over a wide span. -/ @[simps] def mkCocone {F : WidePushoutShape J ⥤ C} {X : C} (f : F.obj none ⟶ X) (ι : ∀ j, F.obj (some j) ⟶ X) (w : ∀ j, F.map (Hom.init j) ≫ ι j = f) : Cocone F := { pt := X ι := { app := fun j => match j with | none => f | some j => ι j naturality := fun j j' f => by cases j <;> cases j' <;> cases f <;> dsimp <;> simp [w] } } /-- Wide pushout diagrams of equivalent index types are equivalent. -/ def equivalenceOfEquiv (J' : Type w') (h : J ≃ J') : WidePushoutShape J ≌ WidePushoutShape J' where functor := wideSpan none (fun j => some (h j)) fun j => Hom.init (h j) inverse := wideSpan none (fun j => some (h.invFun j)) fun j => Hom.init (h.invFun j) unitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) counitIso := NatIso.ofComponents (fun j => by cases j <;> exact eqToIso (by simp)) /-- Lifting universe and morphism levels preserves wide pushout diagrams. -/ def uliftEquivalence : ULiftHom.{w'} (ULift.{w'} (WidePushoutShape J)) ≌ WidePushoutShape (ULift J) := (ULiftHomULiftCategory.equiv.{w', w', w, w} (WidePushoutShape J)).symm.trans (equivalenceOfEquiv _ (Equiv.ulift.{w', w}.symm : J ≃ ULift.{w'} J)) end WidePushoutShape variable (C : Type u) [Category.{v} C] /-- `HasWidePullbacks` represents a choice of wide pullback for every collection of morphisms -/ abbrev HasWidePullbacks : Prop := ∀ J : Type w, HasLimitsOfShape (WidePullbackShape J) C /-- `HasWidePushouts` represents a choice of wide pushout for every collection of morphisms -/ abbrev HasWidePushouts : Prop := ∀ J : Type w, HasColimitsOfShape (WidePushoutShape J) C variable {C J} /-- `HasWidePullback B objs arrows` means that `wideCospan B objs arrows` has a limit. -/ abbrev HasWidePullback (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) : Prop := HasLimit (WidePullbackShape.wideCospan B objs arrows) /-- `HasWidePushout B objs arrows` means that `wideSpan B objs arrows` has a colimit. -/ abbrev HasWidePushout (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) : Prop := HasColimit (WidePushoutShape.wideSpan B objs arrows) /-- A choice of wide pullback. -/ noncomputable abbrev widePullback (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) [HasWidePullback B objs arrows] : C := limit (WidePullbackShape.wideCospan B objs arrows) /-- A choice of wide pushout. -/ noncomputable abbrev widePushout (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) [HasWidePushout B objs arrows] : C := colimit (WidePushoutShape.wideSpan B objs arrows) namespace WidePullback variable {C : Type u} [Category.{v} C] {B : C} {objs : J → C} (arrows : ∀ j : J, objs j ⟶ B) variable [HasWidePullback B objs arrows] /-- The `j`-th projection from the pullback. -/ noncomputable abbrev π (j : J) : widePullback _ _ arrows ⟶ objs j := limit.π (WidePullbackShape.wideCospan _ _ _) (Option.some j) /-- The unique map to the base from the pullback. -/ noncomputable abbrev base : widePullback _ _ arrows ⟶ B := limit.π (WidePullbackShape.wideCospan _ _ _) Option.none @[reassoc (attr := simp)] theorem π_arrow (j : J) : π arrows j ≫ arrows _ = base arrows := by apply limit.w (WidePullbackShape.wideCospan _ _ _) (WidePullbackShape.Hom.term j) variable {arrows} /-- Lift a collection of morphisms to a morphism to the pullback. -/ noncomputable abbrev lift {X : C} (f : X ⟶ B) (fs : ∀ j : J, X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) : X ⟶ widePullback _ _ arrows := limit.lift (WidePullbackShape.wideCospan _ _ _) (WidePullbackShape.mkCone f fs <| w) variable (arrows) variable {X : C} (f : X ⟶ B) (fs : ∀ j : J, X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) -- Porting note (#10618): simp can prove this so removed simp attribute @[reassoc] theorem lift_π (j : J) : lift f fs w ≫ π arrows j = fs _ := by simp only [limit.lift_π, WidePullbackShape.mkCone_pt, WidePullbackShape.mkCone_π_app] -- Porting note (#10618): simp can prove this so removed simp attribute @[reassoc] theorem lift_base : lift f fs w ≫ base arrows = f := by simp only [limit.lift_π, WidePullbackShape.mkCone_pt, WidePullbackShape.mkCone_π_app] theorem eq_lift_of_comp_eq (g : X ⟶ widePullback _ _ arrows) : (∀ j : J, g ≫ π arrows j = fs j) → g ≫ base arrows = f → g = lift f fs w := by intro h1 h2 apply (limit.isLimit (WidePullbackShape.wideCospan B objs arrows)).uniq (WidePullbackShape.mkCone f fs <| w) rintro (_ | _) · apply h2 · apply h1 theorem hom_eq_lift (g : X ⟶ widePullback _ _ arrows) : g = lift (g ≫ base arrows) (fun j => g ≫ π arrows j) (by aesop_cat) := by apply eq_lift_of_comp_eq · aesop_cat · rfl -- Porting note: quite a few missing refl's in aesop_cat now @[ext 1100] theorem hom_ext (g1 g2 : X ⟶ widePullback _ _ arrows) : (∀ j : J, g1 ≫ π arrows j = g2 ≫ π arrows j) → g1 ≫ base arrows = g2 ≫ base arrows → g1 = g2 := by intro h1 h2 apply limit.hom_ext rintro (_ | _) · apply h2 · apply h1 end WidePullback namespace WidePushout variable {C : Type u} [Category.{v} C] {B : C} {objs : J → C} (arrows : ∀ j : J, B ⟶ objs j) variable [HasWidePushout B objs arrows] /-- The `j`-th inclusion to the pushout. -/ noncomputable abbrev ι (j : J) : objs j ⟶ widePushout _ _ arrows := colimit.ι (WidePushoutShape.wideSpan _ _ _) (Option.some j) /-- The unique map from the head to the pushout. -/ noncomputable abbrev head : B ⟶ widePushout B objs arrows := colimit.ι (WidePushoutShape.wideSpan _ _ _) Option.none @[reassoc (attr := simp)] theorem arrow_ι (j : J) : arrows j ≫ ι arrows j = head arrows := by apply colimit.w (WidePushoutShape.wideSpan _ _ _) (WidePushoutShape.Hom.init j) -- Porting note: this can simplify itself attribute [nolint simpNF] WidePushout.arrow_ι WidePushout.arrow_ι_assoc variable {arrows} /-- Descend a collection of morphisms to a morphism from the pushout. -/ noncomputable abbrev desc {X : C} (f : B ⟶ X) (fs : ∀ j : J, objs j ⟶ X) (w : ∀ j, arrows j ≫ fs j = f) : widePushout _ _ arrows ⟶ X := colimit.desc (WidePushoutShape.wideSpan B objs arrows) (WidePushoutShape.mkCocone f fs <| w) variable (arrows) variable {X : C} (f : B ⟶ X) (fs : ∀ j : J, objs j ⟶ X) (w : ∀ j, arrows j ≫ fs j = f) -- Porting note (#10618): simp can prove this so removed simp attribute @[reassoc] theorem ι_desc (j : J) : ι arrows j ≫ desc f fs w = fs _ := by simp only [colimit.ι_desc, WidePushoutShape.mkCocone_pt, WidePushoutShape.mkCocone_ι_app] -- Porting note (#10618): simp can prove this so removed simp attribute @[reassoc] theorem head_desc : head arrows ≫ desc f fs w = f := by simp only [colimit.ι_desc, WidePushoutShape.mkCocone_pt, WidePushoutShape.mkCocone_ι_app] theorem eq_desc_of_comp_eq (g : widePushout _ _ arrows ⟶ X) : (∀ j : J, ι arrows j ≫ g = fs j) → head arrows ≫ g = f → g = desc f fs w := by intro h1 h2 apply (colimit.isColimit (WidePushoutShape.wideSpan B objs arrows)).uniq (WidePushoutShape.mkCocone f fs <| w) rintro (_ | _) · apply h2 · apply h1 theorem hom_eq_desc (g : widePushout _ _ arrows ⟶ X) : g = desc (head arrows ≫ g) (fun j => ι arrows j ≫ g) fun j => by rw [← Category.assoc] simp := by apply eq_desc_of_comp_eq · aesop_cat · rfl -- Porting note: another missing rfl @[ext 1100] theorem hom_ext (g1 g2 : widePushout _ _ arrows ⟶ X) : (∀ j : J, ι arrows j ≫ g1 = ι arrows j ≫ g2) → head arrows ≫ g1 = head arrows ≫ g2 → g1 = g2 := by intro h1 h2 apply colimit.hom_ext rintro (_ | _) · apply h2 · apply h1 end WidePushout variable (J) /-- The action on morphisms of the obvious functor `WidePullbackShape_op : WidePullbackShape J ⥤ (WidePushoutShape J)ᵒᵖ`-/ def widePullbackShapeOpMap : ∀ X Y : WidePullbackShape J, (X ⟶ Y) → ((op X : (WidePushoutShape J)ᵒᵖ) ⟶ (op Y : (WidePushoutShape J)ᵒᵖ)) | _, _, WidePullbackShape.Hom.id X => Quiver.Hom.op (WidePushoutShape.Hom.id _) | _, _, WidePullbackShape.Hom.term _ => Quiver.Hom.op (WidePushoutShape.Hom.init _) /-- The obvious functor `WidePullbackShape J ⥤ (WidePushoutShape J)ᵒᵖ` -/ @[simps] def widePullbackShapeOp : WidePullbackShape J ⥤ (WidePushoutShape J)ᵒᵖ where obj X := op X map {X₁} {X₂} := widePullbackShapeOpMap J X₁ X₂ /-- The action on morphisms of the obvious functor `widePushoutShapeOp : WidePushoutShape J ⥤ (WidePullbackShape J)ᵒᵖ` -/ def widePushoutShapeOpMap : ∀ X Y : WidePushoutShape J, (X ⟶ Y) → ((op X : (WidePullbackShape J)ᵒᵖ) ⟶ (op Y : (WidePullbackShape J)ᵒᵖ)) | _, _, WidePushoutShape.Hom.id X => Quiver.Hom.op (WidePullbackShape.Hom.id _) | _, _, WidePushoutShape.Hom.init _ => Quiver.Hom.op (WidePullbackShape.Hom.term _) /-- The obvious functor `WidePushoutShape J ⥤ (WidePullbackShape J)ᵒᵖ` -/ @[simps] def widePushoutShapeOp : WidePushoutShape J ⥤ (WidePullbackShape J)ᵒᵖ where obj X := op X map := fun {X} {Y} => widePushoutShapeOpMap J X Y /-- The obvious functor `(WidePullbackShape J)ᵒᵖ ⥤ WidePushoutShape J`-/ @[simps!] def widePullbackShapeUnop : (WidePullbackShape J)ᵒᵖ ⥤ WidePushoutShape J := (widePullbackShapeOp J).leftOp /-- The obvious functor `(WidePushoutShape J)ᵒᵖ ⥤ WidePullbackShape J` -/ @[simps!] def widePushoutShapeUnop : (WidePushoutShape J)ᵒᵖ ⥤ WidePullbackShape J := (widePushoutShapeOp J).leftOp /-- The inverse of the unit isomorphism of the equivalence `widePushoutShapeOpEquiv : (WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J` -/ def widePushoutShapeOpUnop : widePushoutShapeUnop J ⋙ widePullbackShapeOp J ≅ 𝟭 _ := NatIso.ofComponents fun X => Iso.refl _ /-- The counit isomorphism of the equivalence `widePullbackShapeOpEquiv : (WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J` -/ def widePushoutShapeUnopOp : widePushoutShapeOp J ⋙ widePullbackShapeUnop J ≅ 𝟭 _ := NatIso.ofComponents fun X => Iso.refl _ /-- The inverse of the unit isomorphism of the equivalence `widePullbackShapeOpEquiv : (WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J` -/ def widePullbackShapeOpUnop : widePullbackShapeUnop J ⋙ widePushoutShapeOp J ≅ 𝟭 _ := NatIso.ofComponents fun X => Iso.refl _ /-- The counit isomorphism of the equivalence `widePushoutShapeOpEquiv : (WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J` -/ def widePullbackShapeUnopOp : widePullbackShapeOp J ⋙ widePushoutShapeUnop J ≅ 𝟭 _ := NatIso.ofComponents fun X => Iso.refl _ /-- The duality equivalence `(WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J` -/ @[simps] def widePushoutShapeOpEquiv : (WidePushoutShape J)ᵒᵖ ≌ WidePullbackShape J where functor := widePushoutShapeUnop J inverse := widePullbackShapeOp J unitIso := (widePushoutShapeOpUnop J).symm counitIso := widePullbackShapeUnopOp J /-- The duality equivalence `(WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J` -/ @[simps] def widePullbackShapeOpEquiv : (WidePullbackShape J)ᵒᵖ ≌ WidePushoutShape J where functor := widePullbackShapeUnop J inverse := widePushoutShapeOp J unitIso := (widePullbackShapeOpUnop J).symm counitIso := widePushoutShapeUnopOp J /-- If a category has wide pushouts on a higher universe level it also has wide pushouts on a lower universe level. -/ theorem hasWidePushouts_shrink [HasWidePushouts.{max w w'} C] : HasWidePushouts.{w} C := fun _ => hasColimitsOfShape_of_equivalence (WidePushoutShape.equivalenceOfEquiv _ Equiv.ulift.{w'}) /-- If a category has wide pullbacks on a higher universe level it also has wide pullbacks on a lower universe level. -/ theorem hasWidePullbacks_shrink [HasWidePullbacks.{max w w'} C] : HasWidePullbacks.{w} C := fun _ => hasLimitsOfShape_of_equivalence (WidePullbackShape.equivalenceOfEquiv _ Equiv.ulift.{w'}) end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\ZeroMorphisms.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Pi.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.IsomorphismClasses import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects /-! # Zero morphisms and zero objects A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra structure, not merely a property.) A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object. ## References * https://en.wikipedia.org/wiki/Zero_morphism * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v u universe v' u' open CategoryTheory open CategoryTheory.Category open scoped Classical namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] variable (D : Type u') [Category.{v'} D] /-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. -/ class HasZeroMorphisms where /-- Every morphism space has zero -/ [zero : ∀ X Y : C, Zero (X ⟶ Y)] /-- `f` composed with `0` is `0` -/ comp_zero : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := by aesop_cat /-- `0` composed with `f` is `0` -/ zero_comp : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := by aesop_cat attribute [instance] HasZeroMorphisms.zero variable {C} @[simp] theorem comp_zero [HasZeroMorphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} : f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := HasZeroMorphisms.comp_zero f Z @[simp] theorem zero_comp [HasZeroMorphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} : (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := HasZeroMorphisms.zero_comp X f instance hasZeroMorphismsPEmpty : HasZeroMorphisms (Discrete PEmpty) where zero := by aesop_cat instance hasZeroMorphismsPUnit : HasZeroMorphisms (Discrete PUnit) where zero X Y := by repeat (constructor) namespace HasZeroMorphisms /-- This lemma will be immediately superseded by `ext`, below. -/ private theorem ext_aux (I J : HasZeroMorphisms C) (w : ∀ X Y : C, (I.zero X Y).zero = (J.zero X Y).zero) : I = J := by have : I.zero = J.zero := by funext X Y specialize w X Y apply congrArg Zero.mk w cases I; cases J congr · apply proof_irrel_heq · apply proof_irrel_heq /-- If you're tempted to use this lemma "in the wild", you should probably carefully consider whether you've made a mistake in allowing two instances of `HasZeroMorphisms` to exist at all. See, particularly, the note on `zeroMorphismsOfZeroObject` below. -/ theorem ext (I J : HasZeroMorphisms C) : I = J := by apply ext_aux intro X Y have : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (I.zero X Y).zero := by apply I.zero_comp X (J.zero Y Y).zero have that : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (J.zero X Y).zero := by apply J.comp_zero (I.zero X Y).zero Y rw [← this, ← that] instance : Subsingleton (HasZeroMorphisms C) := ⟨ext⟩ end HasZeroMorphisms open Opposite HasZeroMorphisms instance hasZeroMorphismsOpposite [HasZeroMorphisms C] : HasZeroMorphisms Cᵒᵖ where zero X Y := ⟨(0 : unop Y ⟶ unop X).op⟩ comp_zero f Z := congr_arg Quiver.Hom.op (HasZeroMorphisms.zero_comp (unop Z) f.unop) zero_comp X {Y Z} (f : Y ⟶ Z) := congrArg Quiver.Hom.op (HasZeroMorphisms.comp_zero f.unop (unop X)) section variable [HasZeroMorphisms C] @[simp] lemma op_zero (X Y : C) : (0 : X ⟶ Y).op = 0 := rfl @[simp] lemma unop_zero (X Y : Cᵒᵖ) : (0 : X ⟶ Y).unop = 0 := rfl theorem zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [Mono g] (h : f ≫ g = 0) : f = 0 := by rw [← zero_comp, cancel_mono] at h exact h theorem zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [Epi f] (h : f ≫ g = 0) : g = 0 := by rw [← comp_zero, cancel_epi] at h exact h theorem eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : image.ι f = 0) : f = 0 := by rw [← image.fac f, w, HasZeroMorphisms.comp_zero] theorem nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : f ≠ 0) : image.ι f ≠ 0 := fun h => w (eq_zero_of_image_eq_zero h) end section variable [HasZeroMorphisms D] instance : HasZeroMorphisms (C ⥤ D) where zero F G := ⟨{ app := fun X => 0 }⟩ comp_zero := fun η H => by ext X; dsimp; apply comp_zero zero_comp := fun F {G H} η => by ext X; dsimp; apply zero_comp @[simp] theorem zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl end namespace IsZero variable [HasZeroMorphisms C] theorem eq_zero_of_src {X Y : C} (o : IsZero X) (f : X ⟶ Y) : f = 0 := o.eq_of_src _ _ theorem eq_zero_of_tgt {X Y : C} (o : IsZero Y) (f : X ⟶ Y) : f = 0 := o.eq_of_tgt _ _ theorem iff_id_eq_zero (X : C) : IsZero X ↔ 𝟙 X = 0 := ⟨fun h => h.eq_of_src _ _, fun h => ⟨fun Y => ⟨⟨⟨0⟩, fun f => by rw [← id_comp f, ← id_comp (0 : X ⟶ Y), h, zero_comp, zero_comp]; simp only⟩⟩, fun Y => ⟨⟨⟨0⟩, fun f => by rw [← comp_id f, ← comp_id (0 : Y ⟶ X), h, comp_zero, comp_zero]; simp only ⟩⟩⟩⟩ theorem of_mono_zero (X Y : C) [Mono (0 : X ⟶ Y)] : IsZero X := (iff_id_eq_zero X).mpr ((cancel_mono (0 : X ⟶ Y)).1 (by simp)) theorem of_epi_zero (X Y : C) [Epi (0 : X ⟶ Y)] : IsZero Y := (iff_id_eq_zero Y).mpr ((cancel_epi (0 : X ⟶ Y)).1 (by simp)) theorem of_mono_eq_zero {X Y : C} (f : X ⟶ Y) [Mono f] (h : f = 0) : IsZero X := by subst h apply of_mono_zero X Y theorem of_epi_eq_zero {X Y : C} (f : X ⟶ Y) [Epi f] (h : f = 0) : IsZero Y := by subst h apply of_epi_zero X Y theorem iff_isSplitMono_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsZero X ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.id_comp f, h, zero_comp] · intro h rw [← IsSplitMono.id f] simp only [h, zero_comp] theorem iff_isSplitEpi_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsZero Y ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.comp_id f, h, comp_zero] · intro h rw [← IsSplitEpi.id f] simp [h] theorem of_mono {X Y : C} (f : X ⟶ Y) [Mono f] (i : IsZero Y) : IsZero X := by have hf := i.eq_zero_of_tgt f subst hf exact IsZero.of_mono_zero X Y theorem of_epi {X Y : C} (f : X ⟶ Y) [Epi f] (i : IsZero X) : IsZero Y := by have hf := i.eq_zero_of_src f subst hf exact IsZero.of_epi_zero X Y end IsZero /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `HasZeroMorphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def IsZero.hasZeroMorphisms {O : C} (hO : IsZero O) : HasZeroMorphisms C where zero X Y := { zero := hO.from_ X ≫ hO.to_ Y } zero_comp X {Y Z} f := by change (hO.from_ X ≫ hO.to_ Y) ≫ f = hO.from_ X ≫ hO.to_ Z rw [Category.assoc] congr apply hO.eq_of_src comp_zero {X Y} f Z := by change f ≫ (hO.from_ Y ≫ hO.to_ Z) = hO.from_ X ≫ hO.to_ Z rw [← Category.assoc] congr apply hO.eq_of_tgt namespace HasZeroObject variable [HasZeroObject C] open ZeroObject /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `has_zero_morphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def zeroMorphismsOfZeroObject : HasZeroMorphisms C where zero X Y := { zero := (default : X ⟶ 0) ≫ default } zero_comp X {Y Z} f := by change ((default : X ⟶ 0) ≫ default) ≫ f = (default : X ⟶ 0) ≫ default rw [Category.assoc] congr simp only [eq_iff_true_of_subsingleton] comp_zero {X Y} f Z := by change f ≫ (default : Y ⟶ 0) ≫ default = (default : X ⟶ 0) ≫ default rw [← Category.assoc] congr simp only [eq_iff_true_of_subsingleton] section HasZeroMorphisms variable [HasZeroMorphisms C] @[simp] theorem zeroIsoIsInitial_hom {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).hom = 0 := by ext @[simp] theorem zeroIsoIsInitial_inv {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).inv = 0 := by ext @[simp] theorem zeroIsoIsTerminal_hom {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).hom = 0 := by ext @[simp] theorem zeroIsoIsTerminal_inv {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).inv = 0 := by ext @[simp] theorem zeroIsoInitial_hom [HasInitial C] : zeroIsoInitial.hom = (0 : 0 ⟶ ⊥_ C) := by ext @[simp] theorem zeroIsoInitial_inv [HasInitial C] : zeroIsoInitial.inv = (0 : ⊥_ C ⟶ 0) := by ext @[simp] theorem zeroIsoTerminal_hom [HasTerminal C] : zeroIsoTerminal.hom = (0 : 0 ⟶ ⊤_ C) := by ext @[simp] theorem zeroIsoTerminal_inv [HasTerminal C] : zeroIsoTerminal.inv = (0 : ⊤_ C ⟶ 0) := by ext end HasZeroMorphisms open ZeroObject instance {B : Type*} [Category B] : HasZeroObject (B ⥤ C) := (((CategoryTheory.Functor.const B).obj (0 : C)).isZero fun _ => isZero_zero _).hasZeroObject end HasZeroObject open ZeroObject variable {D} @[simp] theorem IsZero.map [HasZeroObject D] [HasZeroMorphisms D] {F : C ⥤ D} (hF : IsZero F) {X Y : C} (f : X ⟶ Y) : F.map f = 0 := (hF.obj _).eq_of_src _ _ @[simp] theorem _root_.CategoryTheory.Functor.zero_obj [HasZeroObject D] (X : C) : IsZero ((0 : C ⥤ D).obj X) := (isZero_zero _).obj _ @[simp] theorem _root_.CategoryTheory.zero_map [HasZeroObject D] [HasZeroMorphisms D] {X Y : C} (f : X ⟶ Y) : (0 : C ⥤ D).map f = 0 := (isZero_zero _).map _ section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject @[simp] theorem id_zero : 𝟙 (0 : C) = (0 : (0 : C) ⟶ 0) := by apply HasZeroObject.from_zero_ext -- This can't be a `simp` lemma because the left hand side would be a metavariable. /-- An arrow ending in the zero object is zero -/ theorem zero_of_to_zero {X : C} (f : X ⟶ 0) : f = 0 := by ext theorem zero_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : f = 0 := by have h : f = f ≫ i.hom ≫ 𝟙 0 ≫ i.inv := by simp only [Iso.hom_inv_id, id_comp, comp_id] simpa using h /-- An arrow starting at the zero object is zero -/ theorem zero_of_from_zero {X : C} (f : 0 ⟶ X) : f = 0 := by ext theorem zero_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : f = 0 := by have h : f = i.hom ≫ 𝟙 0 ≫ i.inv ≫ f := by simp only [Iso.hom_inv_id_assoc, id_comp, comp_id] simpa using h theorem zero_of_source_iso_zero' {X Y : C} (f : X ⟶ Y) (i : IsIsomorphic X 0) : f = 0 := zero_of_source_iso_zero f (Nonempty.some i) theorem zero_of_target_iso_zero' {X Y : C} (f : X ⟶ Y) (i : IsIsomorphic Y 0) : f = 0 := zero_of_target_iso_zero f (Nonempty.some i) theorem mono_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : Mono f := ⟨fun {Z} g h _ => by rw [zero_of_target_iso_zero g i, zero_of_target_iso_zero h i]⟩ theorem epi_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : Epi f := ⟨fun {Z} g h _ => by rw [zero_of_source_iso_zero g i, zero_of_source_iso_zero h i]⟩ /-- An object `X` has `𝟙 X = 0` if and only if it is isomorphic to the zero object. Because `X ≅ 0` contains data (even if a subsingleton), we express this `↔` as an `≃`. -/ def idZeroEquivIsoZero (X : C) : 𝟙 X = 0 ≃ (X ≅ 0) where toFun h := { hom := 0 inv := 0 } invFun i := zero_of_target_iso_zero (𝟙 X) i left_inv := by aesop_cat right_inv := by aesop_cat @[simp] theorem idZeroEquivIsoZero_apply_hom (X : C) (h : 𝟙 X = 0) : ((idZeroEquivIsoZero X) h).hom = 0 := rfl @[simp] theorem idZeroEquivIsoZero_apply_inv (X : C) (h : 𝟙 X = 0) : ((idZeroEquivIsoZero X) h).inv = 0 := rfl /-- If `0 : X ⟶ Y` is a monomorphism, then `X ≅ 0`. -/ @[simps] def isoZeroOfMonoZero {X Y : C} (h : Mono (0 : X ⟶ Y)) : X ≅ 0 where hom := 0 inv := 0 hom_inv_id := (cancel_mono (0 : X ⟶ Y)).mp (by simp) /-- If `0 : X ⟶ Y` is an epimorphism, then `Y ≅ 0`. -/ @[simps] def isoZeroOfEpiZero {X Y : C} (h : Epi (0 : X ⟶ Y)) : Y ≅ 0 where hom := 0 inv := 0 hom_inv_id := (cancel_epi (0 : X ⟶ Y)).mp (by simp) /-- If a monomorphism out of `X` is zero, then `X ≅ 0`. -/ def isoZeroOfMonoEqZero {X Y : C} {f : X ⟶ Y} [Mono f] (h : f = 0) : X ≅ 0 := by subst h apply isoZeroOfMonoZero ‹_› /-- If an epimorphism in to `Y` is zero, then `Y ≅ 0`. -/ def isoZeroOfEpiEqZero {X Y : C} {f : X ⟶ Y} [Epi f] (h : f = 0) : Y ≅ 0 := by subst h apply isoZeroOfEpiZero ‹_› /-- If an object `X` is isomorphic to 0, there's no need to use choice to construct an explicit isomorphism: the zero morphism suffices. -/ def isoOfIsIsomorphicZero {X : C} (P : IsIsomorphic X 0) : X ≅ 0 where hom := 0 inv := 0 hom_inv_id := by cases' P with P rw [← P.hom_inv_id, ← Category.id_comp P.inv] apply Eq.symm simp only [id_comp, Iso.hom_inv_id, comp_zero] apply (idZeroEquivIsoZero X).invFun P inv_hom_id := by simp end section IsIso variable [HasZeroMorphisms C] /-- A zero morphism `0 : X ⟶ Y` is an isomorphism if and only if the identities on both `X` and `Y` are zero. -/ @[simps] def isIsoZeroEquiv (X Y : C) : IsIso (0 : X ⟶ Y) ≃ 𝟙 X = 0 ∧ 𝟙 Y = 0 where toFun := by intro i rw [← IsIso.hom_inv_id (0 : X ⟶ Y)] rw [← IsIso.inv_hom_id (0 : X ⟶ Y)] simp only [eq_self_iff_true,comp_zero,and_self,zero_comp] invFun h := ⟨⟨(0 : Y ⟶ X), by aesop_cat⟩⟩ left_inv := by aesop_cat right_inv := by aesop_cat -- Porting note: simp solves these attribute [-simp, nolint simpNF] isIsoZeroEquiv_apply isIsoZeroEquiv_symm_apply /-- A zero morphism `0 : X ⟶ X` is an isomorphism if and only if the identity on `X` is zero. -/ def isIsoZeroSelfEquiv (X : C) : IsIso (0 : X ⟶ X) ≃ 𝟙 X = 0 := by simpa using isIsoZeroEquiv X X variable [HasZeroObject C] open ZeroObject /-- A zero morphism `0 : X ⟶ Y` is an isomorphism if and only if `X` and `Y` are isomorphic to the zero object. -/ def isIsoZeroEquivIsoZero (X Y : C) : IsIso (0 : X ⟶ Y) ≃ (X ≅ 0) × (Y ≅ 0) := by -- This is lame, because `Prod` can't cope with `Prop`, so we can't use `Equiv.prodCongr`. refine (isIsoZeroEquiv X Y).trans ?_ symm fconstructor · rintro ⟨eX, eY⟩ fconstructor · exact (idZeroEquivIsoZero X).symm eX · exact (idZeroEquivIsoZero Y).symm eY · rintro ⟨hX, hY⟩ fconstructor · exact (idZeroEquivIsoZero X) hX · exact (idZeroEquivIsoZero Y) hY · aesop_cat · aesop_cat theorem isIso_of_source_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) (j : Y ≅ 0) : IsIso f := by rw [zero_of_source_iso_zero f i] exact (isIsoZeroEquivIsoZero _ _).invFun ⟨i, j⟩ /-- A zero morphism `0 : X ⟶ X` is an isomorphism if and only if `X` is isomorphic to the zero object. -/ def isIsoZeroSelfEquivIsoZero (X : C) : IsIso (0 : X ⟶ X) ≃ (X ≅ 0) := (isIsoZeroEquivIsoZero X X).trans subsingletonProdSelfEquiv end IsIso /-- If there are zero morphisms, any initial object is a zero object. -/ theorem hasZeroObject_of_hasInitial_object [HasZeroMorphisms C] [HasInitial C] : HasZeroObject C := by refine ⟨⟨⊥_ C, fun X => ⟨⟨⟨0⟩, by aesop_cat⟩⟩, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩⟩⟩ calc f = f ≫ 𝟙 _ := (Category.comp_id _).symm _ = f ≫ 0 := by congr!; subsingleton _ = 0 := HasZeroMorphisms.comp_zero _ _ /-- If there are zero morphisms, any terminal object is a zero object. -/ theorem hasZeroObject_of_hasTerminal_object [HasZeroMorphisms C] [HasTerminal C] : HasZeroObject C := by refine ⟨⟨⊤_ C, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨0⟩, by aesop_cat⟩⟩⟩⟩ calc f = 𝟙 _ ≫ f := (Category.id_comp _).symm _ = 0 ≫ f := by congr!; subsingleton _ = 0 := zero_comp section Image variable [HasZeroMorphisms C] theorem image_ι_comp_eq_zero {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [HasImage f] [Epi (factorThruImage f)] (h : f ≫ g = 0) : image.ι f ≫ g = 0 := zero_of_epi_comp (factorThruImage f) <| by simp [h] theorem comp_factorThruImage_eq_zero {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [HasImage g] (h : f ≫ g = 0) : f ≫ factorThruImage g = 0 := zero_of_comp_mono (image.ι g) <| by simp [h] variable [HasZeroObject C] open ZeroObject /-- The zero morphism has a `MonoFactorisation` through the zero object. -/ @[simps] def monoFactorisationZero (X Y : C) : MonoFactorisation (0 : X ⟶ Y) where I := 0 m := 0 e := 0 /-- The factorisation through the zero object is an image factorisation. -/ def imageFactorisationZero (X Y : C) : ImageFactorisation (0 : X ⟶ Y) where F := monoFactorisationZero X Y isImage := { lift := fun F' => 0 } instance hasImage_zero {X Y : C} : HasImage (0 : X ⟶ Y) := HasImage.mk <| imageFactorisationZero _ _ /-- The image of a zero morphism is the zero object. -/ def imageZero {X Y : C} : image (0 : X ⟶ Y) ≅ 0 := IsImage.isoExt (Image.isImage (0 : X ⟶ Y)) (imageFactorisationZero X Y).isImage /-- The image of a morphism which is equal to zero is the zero object. -/ def imageZero' {X Y : C} {f : X ⟶ Y} (h : f = 0) [HasImage f] : image f ≅ 0 := image.eqToIso h ≪≫ imageZero @[simp] theorem image.ι_zero {X Y : C} [HasImage (0 : X ⟶ Y)] : image.ι (0 : X ⟶ Y) = 0 := by rw [← image.lift_fac (monoFactorisationZero X Y)] simp /-- If we know `f = 0`, it requires a little work to conclude `image.ι f = 0`, because `f = g` only implies `image f ≅ image g`. -/ @[simp] theorem image.ι_zero' [HasEqualizers C] {X Y : C} {f : X ⟶ Y} (h : f = 0) [HasImage f] : image.ι f = 0 := by rw [image.eq_fac h] simp end Image /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance isSplitMono_sigma_ι {β : Type u'} [HasZeroMorphisms C] (f : β → C) [HasColimit (Discrete.functor f)] (b : β) : IsSplitMono (Sigma.ι f b) := IsSplitMono.mk' { retraction := Sigma.desc <| Pi.single b (𝟙 _) } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance isSplitEpi_pi_π {β : Type u'} [HasZeroMorphisms C] (f : β → C) [HasLimit (Discrete.functor f)] (b : β) : IsSplitEpi (Pi.π f b) := IsSplitEpi.mk' { section_ := Pi.lift <| Pi.single b (𝟙 _) } /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance isSplitMono_coprod_inl [HasZeroMorphisms C] {X Y : C} [HasColimit (pair X Y)] : IsSplitMono (coprod.inl : X ⟶ X ⨿ Y) := IsSplitMono.mk' { retraction := coprod.desc (𝟙 X) 0 } /-- In the presence of zero morphisms, coprojections into a coproduct are (split) monomorphisms. -/ instance isSplitMono_coprod_inr [HasZeroMorphisms C] {X Y : C} [HasColimit (pair X Y)] : IsSplitMono (coprod.inr : Y ⟶ X ⨿ Y) := IsSplitMono.mk' { retraction := coprod.desc 0 (𝟙 Y) } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance isSplitEpi_prod_fst [HasZeroMorphisms C] {X Y : C} [HasLimit (pair X Y)] : IsSplitEpi (prod.fst : X ⨯ Y ⟶ X) := IsSplitEpi.mk' { section_ := prod.lift (𝟙 X) 0 } /-- In the presence of zero morphisms, projections into a product are (split) epimorphisms. -/ instance isSplitEpi_prod_snd [HasZeroMorphisms C] {X Y : C} [HasLimit (pair X Y)] : IsSplitEpi (prod.snd : X ⨯ Y ⟶ Y) := IsSplitEpi.mk' { section_ := prod.lift 0 (𝟙 Y) } section variable [HasZeroMorphisms C] [HasZeroObject C] {F : D ⥤ C} /-- If a functor `F` is zero, then any cone for `F` with a zero point is limit. -/ def IsLimit.ofIsZero (c : Cone F) (hF : IsZero F) (hc : IsZero c.pt) : IsLimit c where lift _ := 0 fac _ j := (F.isZero_iff.1 hF j).eq_of_tgt _ _ uniq _ _ _ := hc.eq_of_tgt _ _ /-- If a functor `F` is zero, then any cocone for `F` with a zero point is colimit. -/ def IsColimit.ofIsZero (c : Cocone F) (hF : IsZero F) (hc : IsZero c.pt) : IsColimit c where desc _ := 0 fac _ j := (F.isZero_iff.1 hF j).eq_of_src _ _ uniq _ _ _ := hc.eq_of_src _ _ lemma IsLimit.isZero_pt {c : Cone F} (hc : IsLimit c) (hF : IsZero F) : IsZero c.pt := (isZero_zero C).of_iso (IsLimit.conePointUniqueUpToIso hc (IsLimit.ofIsZero (Cone.mk 0 0) hF (isZero_zero C))) lemma IsColimit.isZero_pt {c : Cocone F} (hc : IsColimit c) (hF : IsZero F) : IsZero c.pt := (isZero_zero C).of_iso (IsColimit.coconePointUniqueUpToIso hc (IsColimit.ofIsZero (Cocone.mk 0 0) hF (isZero_zero C))) end section variable [HasZeroMorphisms C] lemma IsTerminal.isZero {X : C} (hX : IsTerminal X) : IsZero X := by rw [IsZero.iff_id_eq_zero] apply hX.hom_ext lemma IsInitial.isZero {X : C} (hX : IsInitial X) : IsZero X := by rw [IsZero.iff_id_eq_zero] apply hX.hom_ext end end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\ZeroObjects.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Johan Commelin -/ import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Zero objects A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object; see `CategoryTheory.Limits.Shapes.ZeroMorphisms`. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v u v' u' open CategoryTheory open CategoryTheory.Category variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v'} D] namespace CategoryTheory namespace Limits /-- An object `X` in a category is a *zero object* if for every object `Y` there is a unique morphism `to : X → Y` and a unique morphism `from : Y → X`. This is a characteristic predicate for `has_zero_object`. -/ structure IsZero (X : C) : Prop where /-- there are unique morphisms to the object -/ unique_to : ∀ Y, Nonempty (Unique (X ⟶ Y)) /-- there are unique morphisms from the object -/ unique_from : ∀ Y, Nonempty (Unique (Y ⟶ X)) namespace IsZero variable {X Y : C} -- Porting note: `to` is a reserved word, it was replaced by `to_` /-- If `h : IsZero X`, then `h.to_ Y` is a choice of unique morphism `X → Y`. -/ protected def to_ (h : IsZero X) (Y : C) : X ⟶ Y := @default _ <| (h.unique_to Y).some.toInhabited theorem eq_to (h : IsZero X) (f : X ⟶ Y) : f = h.to_ Y := @Unique.eq_default _ (id _) _ theorem to_eq (h : IsZero X) (f : X ⟶ Y) : h.to_ Y = f := (h.eq_to f).symm -- Porting note: `from` is a reserved word, it was replaced by `from_` /-- If `h : is_zero X`, then `h.from_ Y` is a choice of unique morphism `Y → X`. -/ protected def from_ (h : IsZero X) (Y : C) : Y ⟶ X := @default _ <| (h.unique_from Y).some.toInhabited theorem eq_from (h : IsZero X) (f : Y ⟶ X) : f = h.from_ Y := @Unique.eq_default _ (id _) _ theorem from_eq (h : IsZero X) (f : Y ⟶ X) : h.from_ Y = f := (h.eq_from f).symm theorem eq_of_src (hX : IsZero X) (f g : X ⟶ Y) : f = g := (hX.eq_to f).trans (hX.eq_to g).symm theorem eq_of_tgt (hX : IsZero X) (f g : Y ⟶ X) : f = g := (hX.eq_from f).trans (hX.eq_from g).symm /-- Any two zero objects are isomorphic. -/ def iso (hX : IsZero X) (hY : IsZero Y) : X ≅ Y where hom := hX.to_ Y inv := hX.from_ Y hom_inv_id := hX.eq_of_src _ _ inv_hom_id := hY.eq_of_src _ _ /-- A zero object is in particular initial. -/ protected def isInitial (hX : IsZero X) : IsInitial X := @IsInitial.ofUnique _ _ X fun Y => (hX.unique_to Y).some /-- A zero object is in particular terminal. -/ protected def isTerminal (hX : IsZero X) : IsTerminal X := @IsTerminal.ofUnique _ _ X fun Y => (hX.unique_from Y).some /-- The (unique) isomorphism between any initial object and the zero object. -/ def isoIsInitial (hX : IsZero X) (hY : IsInitial Y) : X ≅ Y := IsInitial.uniqueUpToIso hX.isInitial hY /-- The (unique) isomorphism between any terminal object and the zero object. -/ def isoIsTerminal (hX : IsZero X) (hY : IsTerminal Y) : X ≅ Y := IsTerminal.uniqueUpToIso hX.isTerminal hY theorem of_iso (hY : IsZero Y) (e : X ≅ Y) : IsZero X := by refine ⟨fun Z => ⟨⟨⟨e.hom ≫ hY.to_ Z⟩, fun f => ?_⟩⟩, fun Z => ⟨⟨⟨hY.from_ Z ≫ e.inv⟩, fun f => ?_⟩⟩⟩ · rw [← cancel_epi e.inv] apply hY.eq_of_src · rw [← cancel_mono e.hom] apply hY.eq_of_tgt theorem op (h : IsZero X) : IsZero (Opposite.op X) := ⟨fun Y => ⟨⟨⟨(h.from_ (Opposite.unop Y)).op⟩, fun _ => Quiver.Hom.unop_inj (h.eq_of_tgt _ _)⟩⟩, fun Y => ⟨⟨⟨(h.to_ (Opposite.unop Y)).op⟩, fun _ => Quiver.Hom.unop_inj (h.eq_of_src _ _)⟩⟩⟩ theorem unop {X : Cᵒᵖ} (h : IsZero X) : IsZero (Opposite.unop X) := ⟨fun Y => ⟨⟨⟨(h.from_ (Opposite.op Y)).unop⟩, fun _ => Quiver.Hom.op_inj (h.eq_of_tgt _ _)⟩⟩, fun Y => ⟨⟨⟨(h.to_ (Opposite.op Y)).unop⟩, fun _ => Quiver.Hom.op_inj (h.eq_of_src _ _)⟩⟩⟩ end IsZero end Limits open CategoryTheory.Limits theorem Iso.isZero_iff {X Y : C} (e : X ≅ Y) : IsZero X ↔ IsZero Y := ⟨fun h => h.of_iso e.symm, fun h => h.of_iso e⟩ theorem Functor.isZero (F : C ⥤ D) (hF : ∀ X, IsZero (F.obj X)) : IsZero F := by constructor <;> intro G <;> refine ⟨⟨⟨?_⟩, ?_⟩⟩ · refine { app := fun X => (hF _).to_ _ naturality := ?_ } intros exact (hF _).eq_of_src _ _ · intro f ext apply (hF _).eq_of_src _ _ · refine { app := fun X => (hF _).from_ _ naturality := ?_ } intros exact (hF _).eq_of_tgt _ _ · intro f ext apply (hF _).eq_of_tgt _ _ namespace Limits variable (C) /-- A category "has a zero object" if it has an object which is both initial and terminal. -/ class HasZeroObject : Prop where /-- there exists a zero object -/ zero : ∃ X : C, IsZero X instance hasZeroObject_pUnit : HasZeroObject (Discrete PUnit) where zero := ⟨⟨⟨⟩⟩, { unique_to := fun ⟨⟨⟩⟩ => ⟨{ default := 𝟙 _, uniq := by subsingleton }⟩ unique_from := fun ⟨⟨⟩⟩ => ⟨{ default := 𝟙 _, uniq := by subsingleton }⟩}⟩ section variable [HasZeroObject C] /-- Construct a `Zero C` for a category with a zero object. This can not be a global instance as it will trigger for every `Zero C` typeclass search. -/ protected def HasZeroObject.zero' : Zero C where zero := HasZeroObject.zero.choose scoped[ZeroObject] attribute [instance] CategoryTheory.Limits.HasZeroObject.zero' open ZeroObject theorem isZero_zero : IsZero (0 : C) := HasZeroObject.zero.choose_spec instance hasZeroObject_op : HasZeroObject Cᵒᵖ := ⟨⟨Opposite.op 0, IsZero.op (isZero_zero C)⟩⟩ end open ZeroObject theorem hasZeroObject_unop [HasZeroObject Cᵒᵖ] : HasZeroObject C := ⟨⟨Opposite.unop 0, IsZero.unop (isZero_zero Cᵒᵖ)⟩⟩ variable {C} theorem IsZero.hasZeroObject {X : C} (hX : IsZero X) : HasZeroObject C := ⟨⟨X, hX⟩⟩ /-- Every zero object is isomorphic to *the* zero object. -/ def IsZero.isoZero [HasZeroObject C] {X : C} (hX : IsZero X) : X ≅ 0 := hX.iso (isZero_zero C) theorem IsZero.obj [HasZeroObject D] {F : C ⥤ D} (hF : IsZero F) (X : C) : IsZero (F.obj X) := by let G : C ⥤ D := (CategoryTheory.Functor.const C).obj 0 have hG : IsZero G := Functor.isZero _ fun _ => isZero_zero _ let e : F ≅ G := hF.iso hG exact (isZero_zero _).of_iso (e.app X) namespace HasZeroObject variable [HasZeroObject C] /-- There is a unique morphism from the zero object to any object `X`. -/ protected def uniqueTo (X : C) : Unique (0 ⟶ X) := ((isZero_zero C).unique_to X).some /-- There is a unique morphism from any object `X` to the zero object. -/ protected def uniqueFrom (X : C) : Unique (X ⟶ 0) := ((isZero_zero C).unique_from X).some scoped[ZeroObject] attribute [instance] CategoryTheory.Limits.HasZeroObject.uniqueTo scoped[ZeroObject] attribute [instance] CategoryTheory.Limits.HasZeroObject.uniqueFrom @[ext] theorem to_zero_ext {X : C} (f g : X ⟶ 0) : f = g := (isZero_zero C).eq_of_tgt _ _ @[ext] theorem from_zero_ext {X : C} (f g : 0 ⟶ X) : f = g := (isZero_zero C).eq_of_src _ _ instance (X : C) : Subsingleton (X ≅ 0) := ⟨fun f g => by ext⟩ instance {X : C} (f : 0 ⟶ X) : Mono f where right_cancellation g h _ := by ext instance {X : C} (f : X ⟶ 0) : Epi f where left_cancellation g h _ := by ext instance zero_to_zero_isIso (f : (0 : C) ⟶ 0) : IsIso f := by convert show IsIso (𝟙 (0 : C)) by infer_instance subsingleton /-- A zero object is in particular initial. -/ def zeroIsInitial : IsInitial (0 : C) := (isZero_zero C).isInitial /-- A zero object is in particular terminal. -/ def zeroIsTerminal : IsTerminal (0 : C) := (isZero_zero C).isTerminal /-- A zero object is in particular initial. -/ instance (priority := 10) hasInitial : HasInitial C := hasInitial_of_unique 0 /-- A zero object is in particular terminal. -/ instance (priority := 10) hasTerminal : HasTerminal C := hasTerminal_of_unique 0 /-- The (unique) isomorphism between any initial object and the zero object. -/ def zeroIsoIsInitial {X : C} (t : IsInitial X) : 0 ≅ X := zeroIsInitial.uniqueUpToIso t /-- The (unique) isomorphism between any terminal object and the zero object. -/ def zeroIsoIsTerminal {X : C} (t : IsTerminal X) : 0 ≅ X := zeroIsTerminal.uniqueUpToIso t /-- The (unique) isomorphism between the chosen initial object and the chosen zero object. -/ def zeroIsoInitial [HasInitial C] : 0 ≅ ⊥_ C := zeroIsInitial.uniqueUpToIso initialIsInitial /-- The (unique) isomorphism between the chosen terminal object and the chosen zero object. -/ def zeroIsoTerminal [HasTerminal C] : 0 ≅ ⊤_ C := zeroIsTerminal.uniqueUpToIso terminalIsTerminal instance (priority := 100) initialMonoClass : InitialMonoClass C := InitialMonoClass.of_isInitial zeroIsInitial fun X => by infer_instance end HasZeroObject end Limits open CategoryTheory.Limits open ZeroObject theorem Functor.isZero_iff [HasZeroObject D] (F : C ⥤ D) : IsZero F ↔ ∀ X, IsZero (F.obj X) := ⟨fun hF X => hF.obj X, Functor.isZero _⟩ end CategoryTheory
CategoryTheory\Limits\Shapes\NormalMono\Basic.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Definitions and basic properties of normal monomorphisms and epimorphisms. A normal monomorphism is a morphism that is the kernel of some other morphism. We give the construction `NormalMono → RegularMono` (`CategoryTheory.NormalMono.regularMono`) as well as the dual construction for normal epimorphisms. We show equivalences reflect normal monomorphisms (`CategoryTheory.equivalenceReflectsNormalMono`), and that the pullback of a normal monomorphism is normal (`CategoryTheory.normalOfIsPullbackSndOfNormal`). We also define classes `NormalMonoCategory` and `NormalEpiCategory` for classes in which every monomorphism or epimorphism is normal, and deduce that these categories are `RegularMonoCategory`s resp. `RegularEpiCategory`s. -/ noncomputable section namespace CategoryTheory open CategoryTheory.Limits universe v₁ v₂ u₁ u₂ variable {C : Type u₁} [Category.{v₁} C] variable {X Y : C} section variable [HasZeroMorphisms C] /-- A normal monomorphism is a morphism which is the kernel of some morphism. -/ class NormalMono (f : X ⟶ Y) where Z : C -- Porting note: violates naming convention but can't think of a better one g : Y ⟶ Z w : f ≫ g = 0 isLimit : IsLimit (KernelFork.ofι f w) attribute [inherit_doc NormalMono] NormalMono.Z NormalMono.g NormalMono.w NormalMono.isLimit section /-- If `F` is an equivalence and `F.map f` is a normal mono, then `f` is a normal mono. -/ def equivalenceReflectsNormalMono {D : Type u₂} [Category.{v₁} D] [HasZeroMorphisms D] (F : C ⥤ D) [F.IsEquivalence] {X Y : C} {f : X ⟶ Y} (hf : NormalMono (F.map f)) : NormalMono f where Z := F.objPreimage hf.Z g := F.preimage (hf.g ≫ (F.objObjPreimageIso hf.Z).inv) w := F.map_injective <| by have reassoc' {W : D} (h : hf.Z ⟶ W) : F.map f ≫ hf.g ≫ h = 0 ≫ h := by rw [← Category.assoc, eq_whisker hf.w] simp [reassoc'] isLimit := @ReflectsLimit.reflects C _ D _ _ _ _ F _ _ <| IsLimit.ofConeEquiv (Cones.postcomposeEquivalence (@compNatIso C _ _ _ _ _ D _ _ F _)) <| IsLimit.ofIsoLimit (IsLimit.ofIsoLimit (IsKernel.ofCompIso _ _ (F.objObjPreimageIso hf.Z) (by simp only [Functor.map_preimage, Category.assoc, Iso.inv_hom_id, Category.comp_id]) hf.isLimit) (ofιCongr (Category.comp_id _).symm)) <| by apply Iso.symm; apply isoOfι -- Porting note: very fiddly unification here end /-- Every normal monomorphism is a regular monomorphism. -/ instance (priority := 100) NormalMono.regularMono (f : X ⟶ Y) [I : NormalMono f] : RegularMono f := { I with left := I.g right := 0 w := by simpa using I.w } /-- If `f` is a normal mono, then any map `k : W ⟶ Y` such that `k ≫ normal_mono.g = 0` induces a morphism `l : W ⟶ X` such that `l ≫ f = k`. -/ def NormalMono.lift' {W : C} (f : X ⟶ Y) [hf : NormalMono f] (k : W ⟶ Y) (h : k ≫ hf.g = 0) : { l : W ⟶ X // l ≫ f = k } := KernelFork.IsLimit.lift' NormalMono.isLimit _ h /-- The second leg of a pullback cone is a normal monomorphism if the right component is too. See also `pullback.sndOfMono` for the basic monomorphism version, and `normalOfIsPullbackFstOfNormal` for the flipped version. -/ def normalOfIsPullbackSndOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [hn : NormalMono h] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : NormalMono g where Z := hn.Z g := k ≫ hn.g w := by have reassoc' {W : C} (h' : S ⟶ W) : f ≫ h ≫ h' = g ≫ k ≫ h' := by simp only [← Category.assoc, eq_whisker comm] rw [← reassoc', hn.w, HasZeroMorphisms.comp_zero] isLimit := by letI gr := regularOfIsPullbackSndOfRegular comm t have q := (HasZeroMorphisms.comp_zero k hn.Z).symm convert gr.isLimit /-- The first leg of a pullback cone is a normal monomorphism if the left component is too. See also `pullback.fstOfMono` for the basic monomorphism version, and `normalOfIsPullbackSndOfNormal` for the flipped version. -/ def normalOfIsPullbackFstOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [NormalMono k] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk _ _ comm)) : NormalMono f := normalOfIsPullbackSndOfNormal comm.symm (PullbackCone.flipIsLimit t) section variable (C) /-- A normal mono category is a category in which every monomorphism is normal. -/ class NormalMonoCategory where normalMonoOfMono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], NormalMono f attribute [inherit_doc NormalMonoCategory] NormalMonoCategory.normalMonoOfMono end /-- In a category in which every monomorphism is normal, we can express every monomorphism as a kernel. This is not an instance because it would create an instance loop. -/ def normalMonoOfMono [NormalMonoCategory C] (f : X ⟶ Y) [Mono f] : NormalMono f := NormalMonoCategory.normalMonoOfMono _ instance (priority := 100) regularMonoCategoryOfNormalMonoCategory [NormalMonoCategory C] : RegularMonoCategory C where regularMonoOfMono f _ := by haveI := normalMonoOfMono f infer_instance end section variable [HasZeroMorphisms C] /-- A normal epimorphism is a morphism which is the cokernel of some morphism. -/ class NormalEpi (f : X ⟶ Y) where W : C g : W ⟶ X w : g ≫ f = 0 isColimit : IsColimit (CokernelCofork.ofπ f w) attribute [inherit_doc NormalEpi] NormalEpi.W NormalEpi.g NormalEpi.w NormalEpi.isColimit section /-- If `F` is an equivalence and `F.map f` is a normal epi, then `f` is a normal epi. -/ def equivalenceReflectsNormalEpi {D : Type u₂} [Category.{v₁} D] [HasZeroMorphisms D] (F : C ⥤ D) [F.IsEquivalence] {X Y : C} {f : X ⟶ Y} (hf : NormalEpi (F.map f)) : NormalEpi f where W := F.objPreimage hf.W g := F.preimage ((F.objObjPreimageIso hf.W).hom ≫ hf.g) w := F.map_injective <| by simp [hf.w] isColimit := ReflectsColimit.reflects <| IsColimit.ofCoconeEquiv (Cocones.precomposeEquivalence (compNatIso F).symm) <| IsColimit.ofIsoColimit (IsColimit.ofIsoColimit (IsCokernel.ofIsoComp _ _ (F.objObjPreimageIso hf.W).symm (by simp) hf.isColimit) (ofπCongr (Category.id_comp _).symm)) <| by apply Iso.symm; apply isoOfπ end /-- Every normal epimorphism is a regular epimorphism. -/ instance (priority := 100) NormalEpi.regularEpi (f : X ⟶ Y) [I : NormalEpi f] : RegularEpi f := { I with left := I.g right := 0 w := by simpa using I.w } /-- If `f` is a normal epi, then every morphism `k : X ⟶ W` satisfying `NormalEpi.g ≫ k = 0` induces `l : Y ⟶ W` such that `f ≫ l = k`. -/ def NormalEpi.desc' {W : C} (f : X ⟶ Y) [nef : NormalEpi f] (k : X ⟶ W) (h : nef.g ≫ k = 0) : { l : Y ⟶ W // f ≫ l = k } := CokernelCofork.IsColimit.desc' NormalEpi.isColimit _ h /-- The second leg of a pushout cocone is a normal epimorphism if the right component is too. See also `pushout.sndOfEpi` for the basic epimorphism version, and `normalOfIsPushoutFstOfNormal` for the flipped version. -/ def normalOfIsPushoutSndOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [gn : NormalEpi g] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : NormalEpi h where W := gn.W g := gn.g ≫ f w := by have reassoc' {W : C} (h' : R ⟶ W) : gn.g ≫ g ≫ h' = 0 ≫ h' := by rw [← Category.assoc, eq_whisker gn.w] rw [Category.assoc, comm, reassoc', zero_comp] isColimit := by letI hn := regularOfIsPushoutSndOfRegular comm t have q := (@zero_comp _ _ _ gn.W _ _ f).symm convert hn.isColimit /-- The first leg of a pushout cocone is a normal epimorphism if the left component is too. See also `pushout.fstOfEpi` for the basic epimorphism version, and `normalOfIsPushoutSndOfNormal` for the flipped version. -/ def normalOfIsPushoutFstOfNormal {P Q R S : C} {f : P ⟶ Q} {g : P ⟶ R} {h : Q ⟶ S} {k : R ⟶ S} [NormalEpi f] (comm : f ≫ h = g ≫ k) (t : IsColimit (PushoutCocone.mk _ _ comm)) : NormalEpi k := normalOfIsPushoutSndOfNormal comm.symm (PushoutCocone.flipIsColimit t) end open Opposite variable [HasZeroMorphisms C] /-- A normal mono becomes a normal epi in the opposite category. -/ def normalEpiOfNormalMonoUnop {X Y : Cᵒᵖ} (f : X ⟶ Y) (m : NormalMono f.unop) : NormalEpi f where W := op m.Z g := m.g.op w := congrArg Quiver.Hom.op m.w isColimit := CokernelCofork.IsColimit.ofπ _ _ (fun g' w' => (KernelFork.IsLimit.lift' m.isLimit g'.unop (congrArg Quiver.Hom.unop w')).1.op) (fun g' w' => congrArg Quiver.Hom.op (KernelFork.IsLimit.lift' m.isLimit g'.unop (congrArg Quiver.Hom.unop w')).2) (by rintro Z' g' w' m' rfl apply Quiver.Hom.unop_inj apply m.isLimit.uniq (KernelFork.ofι (m'.unop ≫ f.unop) _) m'.unop rintro (⟨⟩ | ⟨⟩) <;> simp) /-- A normal epi becomes a normal mono in the opposite category. -/ def normalMonoOfNormalEpiUnop {X Y : Cᵒᵖ} (f : X ⟶ Y) (m : NormalEpi f.unop) : NormalMono f where Z := op m.W g := m.g.op w := congrArg Quiver.Hom.op m.w isLimit := KernelFork.IsLimit.ofι _ _ (fun g' w' => (CokernelCofork.IsColimit.desc' m.isColimit g'.unop (congrArg Quiver.Hom.unop w')).1.op) (fun g' w' => congrArg Quiver.Hom.op (CokernelCofork.IsColimit.desc' m.isColimit g'.unop (congrArg Quiver.Hom.unop w')).2) (by rintro Z' g' w' m' rfl apply Quiver.Hom.unop_inj apply m.isColimit.uniq (CokernelCofork.ofπ (f.unop ≫ m'.unop) _) m'.unop rintro (⟨⟩ | ⟨⟩) <;> simp) section variable (C) /-- A normal epi category is a category in which every epimorphism is normal. -/ class NormalEpiCategory where normalEpiOfEpi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], NormalEpi f attribute [inherit_doc NormalEpiCategory] NormalEpiCategory.normalEpiOfEpi end /-- In a category in which every epimorphism is normal, we can express every epimorphism as a kernel. This is not an instance because it would create an instance loop. -/ def normalEpiOfEpi [NormalEpiCategory C] (f : X ⟶ Y) [Epi f] : NormalEpi f := NormalEpiCategory.normalEpiOfEpi _ instance (priority := 100) regularEpiCategoryOfNormalEpiCategory [NormalEpiCategory C] : RegularEpiCategory C where regularEpiOfEpi f _ := by haveI := normalEpiOfEpi f infer_instance end CategoryTheory
CategoryTheory\Limits\Shapes\NormalMono\Equalizers.lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Basic import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts /-! # Normal mono categories with finite products and kernels have all equalizers. This, and the dual result, are used in the development of abelian categories. -/ noncomputable section open CategoryTheory open CategoryTheory.Limits variable {C : Type*} [Category C] [HasZeroMorphisms C] namespace CategoryTheory.NormalMonoCategory variable [HasFiniteProducts C] [HasKernels C] [NormalMonoCategory C] /-- The pullback of two monomorphisms exists. -/ @[irreducible, nolint defLemma] -- Porting note: changed to irreducible and a def def pullback_of_mono {X Y Z : C} (a : X ⟶ Z) (b : Y ⟶ Z) [Mono a] [Mono b] : HasLimit (cospan a b) := let ⟨P, f, haf, i⟩ := normalMonoOfMono a let ⟨Q, g, hbg, i'⟩ := normalMonoOfMono b let ⟨a', ha'⟩ := KernelFork.IsLimit.lift' i (kernel.ι (prod.lift f g)) <| calc kernel.ι (prod.lift f g) ≫ f _ = kernel.ι (prod.lift f g) ≫ prod.lift f g ≫ Limits.prod.fst := by rw [prod.lift_fst] _ = (0 : kernel (prod.lift f g) ⟶ P ⨯ Q) ≫ Limits.prod.fst := by rw [kernel.condition_assoc] _ = 0 := zero_comp let ⟨b', hb'⟩ := KernelFork.IsLimit.lift' i' (kernel.ι (prod.lift f g)) <| calc kernel.ι (prod.lift f g) ≫ g _ = kernel.ι (prod.lift f g) ≫ prod.lift f g ≫ Limits.prod.snd := by rw [prod.lift_snd] _ = (0 : kernel (prod.lift f g) ⟶ P ⨯ Q) ≫ Limits.prod.snd := by rw [kernel.condition_assoc] _ = 0 := zero_comp HasLimit.mk { cone := PullbackCone.mk a' b' <| by simp? at ha' hb' says simp only [parallelPair_obj_zero, Fork.ofι_pt, Fork.ι_ofι] at ha' hb' rw [ha', hb'] isLimit := PullbackCone.IsLimit.mk _ (fun s => kernel.lift (prod.lift f g) (PullbackCone.snd s ≫ b) <| prod.hom_ext (calc ((PullbackCone.snd s ≫ b) ≫ prod.lift f g) ≫ Limits.prod.fst = PullbackCone.snd s ≫ b ≫ f := by simp only [prod.lift_fst, Category.assoc] _ = PullbackCone.fst s ≫ a ≫ f := by rw [PullbackCone.condition_assoc] _ = PullbackCone.fst s ≫ 0 := by rw [haf] _ = 0 ≫ Limits.prod.fst := by rw [comp_zero, zero_comp] ) (calc ((PullbackCone.snd s ≫ b) ≫ prod.lift f g) ≫ Limits.prod.snd = PullbackCone.snd s ≫ b ≫ g := by simp only [prod.lift_snd, Category.assoc] _ = PullbackCone.snd s ≫ 0 := by rw [hbg] _ = 0 ≫ Limits.prod.snd := by rw [comp_zero, zero_comp] )) (fun s => (cancel_mono a).1 <| by rw [KernelFork.ι_ofι] at ha' simp [ha', PullbackCone.condition s]) (fun s => (cancel_mono b).1 <| by rw [KernelFork.ι_ofι] at hb' simp [hb']) fun s m h₁ _ => (cancel_mono (kernel.ι (prod.lift f g))).1 <| calc m ≫ kernel.ι (prod.lift f g) = m ≫ a' ≫ a := by congr exact ha'.symm _ = PullbackCone.fst s ≫ a := by rw [← Category.assoc, h₁] _ = PullbackCone.snd s ≫ b := PullbackCone.condition s _ = kernel.lift (prod.lift f g) (PullbackCone.snd s ≫ b) _ ≫ kernel.ι (prod.lift f g) := by rw [kernel.lift_ι] } section attribute [local instance] pullback_of_mono /-- The pullback of `(𝟙 X, f)` and `(𝟙 X, g)` -/ private abbrev P {X Y : C} (f g : X ⟶ Y) [Mono (prod.lift (𝟙 X) f)] [Mono (prod.lift (𝟙 X) g)] : C := pullback (prod.lift (𝟙 X) f) (prod.lift (𝟙 X) g) /-- The equalizer of `f` and `g` exists. -/ -- Porting note: changed to irreducible def since irreducible_def was breaking things @[irreducible, nolint defLemma] def hasLimit_parallelPair {X Y : C} (f g : X ⟶ Y) : HasLimit (parallelPair f g) := have huv : (pullback.fst _ _ : P f g ⟶ X) = pullback.snd _ _ := calc (pullback.fst _ _ : P f g ⟶ X) = pullback.fst _ _ ≫ 𝟙 _ := Eq.symm <| Category.comp_id _ _ = pullback.fst _ _ ≫ prod.lift (𝟙 X) f ≫ Limits.prod.fst := by rw [prod.lift_fst] _ = pullback.snd _ _ ≫ prod.lift (𝟙 X) g ≫ Limits.prod.fst := by rw [pullback.condition_assoc] _ = pullback.snd _ _ := by rw [prod.lift_fst, Category.comp_id] have hvu : (pullback.fst _ _ : P f g ⟶ X) ≫ f = pullback.snd _ _ ≫ g := calc (pullback.fst _ _ : P f g ⟶ X) ≫ f = pullback.fst _ _ ≫ prod.lift (𝟙 X) f ≫ Limits.prod.snd := by rw [prod.lift_snd] _ = pullback.snd _ _ ≫ prod.lift (𝟙 X) g ≫ Limits.prod.snd := by rw [pullback.condition_assoc] _ = pullback.snd _ _ ≫ g := by rw [prod.lift_snd] have huu : (pullback.fst _ _ : P f g ⟶ X) ≫ f = pullback.fst _ _ ≫ g := by rw [hvu, ← huv] HasLimit.mk { cone := Fork.ofι (pullback.fst _ _) huu isLimit := Fork.IsLimit.mk _ (fun s => pullback.lift (Fork.ι s) (Fork.ι s) <| prod.hom_ext (by simp only [prod.lift_fst, Category.assoc]) (by simp only [prod.comp_lift, Fork.condition s])) (fun s => by simp) fun s m h => pullback.hom_ext (by simpa only [pullback.lift_fst] using h) (by simpa only [huv.symm, pullback.lift_fst] using h) } end section attribute [local instance] hasLimit_parallelPair /-- A `NormalMonoCategory` category with finite products and kernels has all equalizers. -/ instance (priority := 100) hasEqualizers : HasEqualizers C := hasEqualizers_of_hasLimit_parallelPair _ end /-- If a zero morphism is a cokernel of `f`, then `f` is an epimorphism. -/ theorem epi_of_zero_cokernel {X Y : C} (f : X ⟶ Y) (Z : C) (l : IsColimit (CokernelCofork.ofπ (0 : Y ⟶ Z) (show f ≫ 0 = 0 by simp))) : Epi f := ⟨fun u v huv => by obtain ⟨W, w, hw, hl⟩ := normalMonoOfMono (equalizer.ι u v) obtain ⟨m, hm⟩ := equalizer.lift' f huv have hwf : f ≫ w = 0 := by rw [← hm, Category.assoc, hw, comp_zero] obtain ⟨n, hn⟩ := CokernelCofork.IsColimit.desc' l _ hwf rw [Cofork.π_ofπ, zero_comp] at hn have : IsIso (equalizer.ι u v) := by apply isIso_limit_cone_parallelPair_of_eq hn.symm hl apply (cancel_epi (equalizer.ι u v)).1 exact equalizer.condition _ _⟩ section variable [HasZeroObject C] open ZeroObject /-- If `f ≫ g = 0` implies `g = 0` for all `g`, then `g` is a monomorphism. -/ theorem epi_of_zero_cancel {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Y ⟶ Z) (_ : f ≫ g = 0), g = 0) : Epi f := epi_of_zero_cokernel f 0 <| zeroCokernelOfZeroCancel f hf end end CategoryTheory.NormalMonoCategory namespace CategoryTheory.NormalEpiCategory variable [HasFiniteCoproducts C] [HasCokernels C] [NormalEpiCategory C] /-- The pushout of two epimorphisms exists. -/ @[irreducible, nolint defLemma] -- Porting note: made a def and re-added irreducible def pushout_of_epi {X Y Z : C} (a : X ⟶ Y) (b : X ⟶ Z) [Epi a] [Epi b] : HasColimit (span a b) := let ⟨P, f, hfa, i⟩ := normalEpiOfEpi a let ⟨Q, g, hgb, i'⟩ := normalEpiOfEpi b let ⟨a', ha'⟩ := CokernelCofork.IsColimit.desc' i (cokernel.π (coprod.desc f g)) <| calc f ≫ cokernel.π (coprod.desc f g) = coprod.inl ≫ coprod.desc f g ≫ cokernel.π (coprod.desc f g) := by rw [coprod.inl_desc_assoc] _ = coprod.inl ≫ (0 : P ⨿ Q ⟶ cokernel (coprod.desc f g)) := by rw [cokernel.condition] _ = 0 := HasZeroMorphisms.comp_zero _ _ let ⟨b', hb'⟩ := CokernelCofork.IsColimit.desc' i' (cokernel.π (coprod.desc f g)) <| calc g ≫ cokernel.π (coprod.desc f g) = coprod.inr ≫ coprod.desc f g ≫ cokernel.π (coprod.desc f g) := by rw [coprod.inr_desc_assoc] _ = coprod.inr ≫ (0 : P ⨿ Q ⟶ cokernel (coprod.desc f g)) := by rw [cokernel.condition] _ = 0 := HasZeroMorphisms.comp_zero _ _ HasColimit.mk { cocone := PushoutCocone.mk a' b' <| by simp only [Cofork.π_ofπ] at ha' hb' rw [ha', hb'] isColimit := PushoutCocone.IsColimit.mk _ (fun s => cokernel.desc (coprod.desc f g) (b ≫ PushoutCocone.inr s) <| coprod.hom_ext (calc coprod.inl ≫ coprod.desc f g ≫ b ≫ PushoutCocone.inr s = f ≫ b ≫ PushoutCocone.inr s := by rw [coprod.inl_desc_assoc] _ = f ≫ a ≫ PushoutCocone.inl s := by rw [PushoutCocone.condition] _ = 0 ≫ PushoutCocone.inl s := by rw [← Category.assoc, eq_whisker hfa] _ = coprod.inl ≫ 0 := by rw [comp_zero, zero_comp] ) (calc coprod.inr ≫ coprod.desc f g ≫ b ≫ PushoutCocone.inr s = g ≫ b ≫ PushoutCocone.inr s := by rw [coprod.inr_desc_assoc] _ = 0 ≫ PushoutCocone.inr s := by rw [← Category.assoc, eq_whisker hgb] _ = coprod.inr ≫ 0 := by rw [comp_zero, zero_comp] )) (fun s => (cancel_epi a).1 <| by rw [CokernelCofork.π_ofπ] at ha' have reassoced {W : C} (h : cokernel (coprod.desc f g) ⟶ W) : a ≫ a' ≫ h = cokernel.π (coprod.desc f g) ≫ h := by rw [← Category.assoc, eq_whisker ha'] simp [reassoced , PushoutCocone.condition s]) (fun s => (cancel_epi b).1 <| by rw [CokernelCofork.π_ofπ] at hb' have reassoced' {W : C} (h : cokernel (coprod.desc f g) ⟶ W) : b ≫ b' ≫ h = cokernel.π (coprod.desc f g) ≫ h := by rw [← Category.assoc, eq_whisker hb'] simp [reassoced']) fun s m h₁ _ => (cancel_epi (cokernel.π (coprod.desc f g))).1 <| calc cokernel.π (coprod.desc f g) ≫ m = (a ≫ a') ≫ m := by congr exact ha'.symm _ = a ≫ PushoutCocone.inl s := by rw [Category.assoc, h₁] _ = b ≫ PushoutCocone.inr s := PushoutCocone.condition s _ = cokernel.π (coprod.desc f g) ≫ cokernel.desc (coprod.desc f g) (b ≫ PushoutCocone.inr s) _ := by rw [cokernel.π_desc] } section attribute [local instance] pushout_of_epi /-- The pushout of `(𝟙 Y, f)` and `(𝟙 Y, g)`. -/ private abbrev Q {X Y : C} (f g : X ⟶ Y) [Epi (coprod.desc (𝟙 Y) f)] [Epi (coprod.desc (𝟙 Y) g)] : C := pushout (coprod.desc (𝟙 Y) f) (coprod.desc (𝟙 Y) g) /-- The coequalizer of `f` and `g` exists. -/ @[irreducible, nolint defLemma] -- Porting note: changed to def and restored irreducible def hasColimit_parallelPair {X Y : C} (f g : X ⟶ Y) : HasColimit (parallelPair f g) := have huv : (pushout.inl _ _ : Y ⟶ Q f g) = pushout.inr _ _ := calc (pushout.inl _ _ : Y ⟶ Q f g) = 𝟙 _ ≫ pushout.inl _ _ := Eq.symm <| Category.id_comp _ _ = (coprod.inl ≫ coprod.desc (𝟙 Y) f) ≫ pushout.inl _ _ := by rw [coprod.inl_desc] _ = (coprod.inl ≫ coprod.desc (𝟙 Y) g) ≫ pushout.inr _ _ := by simp only [Category.assoc, pushout.condition] _ = pushout.inr _ _ := by rw [coprod.inl_desc, Category.id_comp] have hvu : f ≫ (pushout.inl _ _ : Y ⟶ Q f g) = g ≫ pushout.inr _ _ := calc f ≫ (pushout.inl _ _ : Y ⟶ Q f g) = (coprod.inr ≫ coprod.desc (𝟙 Y) f) ≫ pushout.inl _ _ := by rw [coprod.inr_desc] _ = (coprod.inr ≫ coprod.desc (𝟙 Y) g) ≫ pushout.inr _ _ := by simp only [Category.assoc, pushout.condition] _ = g ≫ pushout.inr _ _ := by rw [coprod.inr_desc] have huu : f ≫ (pushout.inl _ _ : Y ⟶ Q f g) = g ≫ pushout.inl _ _ := by rw [hvu, huv] HasColimit.mk { cocone := Cofork.ofπ (pushout.inl _ _) huu isColimit := Cofork.IsColimit.mk _ (fun s => pushout.desc (Cofork.π s) (Cofork.π s) <| coprod.hom_ext (by simp only [coprod.inl_desc_assoc]) (by simp only [coprod.desc_comp, Cofork.condition s])) (fun s => by simp only [pushout.inl_desc, Cofork.π_ofπ]) fun s m h => pushout.hom_ext (by simpa only [pushout.inl_desc] using h) (by simpa only [huv.symm, pushout.inl_desc] using h) } end section attribute [local instance] hasColimit_parallelPair /-- A `NormalEpiCategory` category with finite coproducts and cokernels has all coequalizers. -/ instance (priority := 100) hasCoequalizers : HasCoequalizers C := hasCoequalizers_of_hasColimit_parallelPair _ end /-- If a zero morphism is a kernel of `f`, then `f` is a monomorphism. -/ theorem mono_of_zero_kernel {X Y : C} (f : X ⟶ Y) (Z : C) (l : IsLimit (KernelFork.ofι (0 : Z ⟶ X) (show 0 ≫ f = 0 by simp))) : Mono f := ⟨fun u v huv => by obtain ⟨W, w, hw, hl⟩ := normalEpiOfEpi (coequalizer.π u v) obtain ⟨m, hm⟩ := coequalizer.desc' f huv have reassoced {W : C} (h : coequalizer u v ⟶ W) : w ≫ coequalizer.π u v ≫ h = 0 ≫ h := by rw [← Category.assoc, eq_whisker hw] have hwf : w ≫ f = 0 := by rw [← hm, reassoced, zero_comp] obtain ⟨n, hn⟩ := KernelFork.IsLimit.lift' l _ hwf rw [Fork.ι_ofι, HasZeroMorphisms.comp_zero] at hn have : IsIso (coequalizer.π u v) := by apply isIso_colimit_cocone_parallelPair_of_eq hn.symm hl apply (cancel_mono (coequalizer.π u v)).1 exact coequalizer.condition _ _⟩ section variable [HasZeroObject C] open ZeroObject /-- If `g ≫ f = 0` implies `g = 0` for all `g`, then `f` is a monomorphism. -/ theorem mono_of_cancel_zero {X Y : C} (f : X ⟶ Y) (hf : ∀ (Z : C) (g : Z ⟶ X) (_ : g ≫ f = 0), g = 0) : Mono f := mono_of_zero_kernel f 0 <| zeroKernelOfCancelZero f hf end end CategoryTheory.NormalEpiCategory
CategoryTheory\Limits\Shapes\Pullback\Assoc.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Pasting /-! # Associativity of pullbacks This file shows that pullbacks (and pushouts) are associative up to natural isomorphism. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {W X Y Z : C} section PullbackAssoc /- The objects and morphisms are as follows: ``` Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ ``` where the two squares are pullbacks. We can then construct the pullback squares ``` W - l₂ -> Z₂ - g₄ -> X₃ | | l₁ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ ``` and ``` W' - l₂' -> Z₂ | | l₁' g₃ ∨ ∨ Z₁ X₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ ``` We will show that both `W` and `W'` are pullbacks over `g₁, g₂`, and thus we may construct a canonical isomorphism between them. -/ variable {X₁ X₂ X₃ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₁) (f₃ : X₂ ⟶ Y₂) variable (f₄ : X₃ ⟶ Y₂) [HasPullback f₁ f₂] [HasPullback f₃ f₄] local notation "Z₁" => pullback f₁ f₂ local notation "Z₂" => pullback f₃ f₄ local notation "g₁" => (pullback.fst _ _ : Z₁ ⟶ X₁) local notation "g₂" => (pullback.snd _ _ : Z₁ ⟶ X₂) local notation "g₃" => (pullback.fst _ _ : Z₂ ⟶ X₂) local notation "g₄" => (pullback.snd _ _ : Z₂ ⟶ X₃) local notation "W" => pullback (g₂ ≫ f₃) f₄ local notation "W'" => pullback f₁ (g₃ ≫ f₂) local notation "l₁" => (pullback.fst _ _ : W ⟶ Z₁) local notation "l₂" => (pullback.lift (pullback.fst _ _ ≫ g₂) (pullback.snd _ _) (Eq.trans (Category.assoc _ _ _) pullback.condition) : W ⟶ Z₂) local notation "l₁'" => (pullback.lift (pullback.fst _ _) (pullback.snd _ _ ≫ g₃) (pullback.condition.trans (Eq.symm (Category.assoc _ _ _))) : W' ⟶ Z₁) local notation "l₂'" => (pullback.snd f₁ (g₃ ≫ f₂)) /-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/ def pullbackPullbackLeftIsPullback [HasPullback (g₂ ≫ f₃) f₄] : IsLimit (PullbackCone.mk l₁ l₂ (show l₁ ≫ g₂ = l₂ ≫ g₃ from (pullback.lift_fst _ _ _).symm)) := by apply leftSquareIsPullback _ rfl (pullbackIsPullback f₃ f₄) simpa [PullbackCone.pasteHoriz] using PullbackCone.mkSelfIsLimit (pullbackIsPullback _ f₄) /-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/ def pullbackAssocIsPullback [HasPullback (g₂ ≫ f₃) f₄] : IsLimit (PullbackCone.mk (l₁ ≫ g₁) l₂ (show (l₁ ≫ g₁) ≫ f₁ = l₂ ≫ g₃ ≫ f₂ by rw [pullback.lift_fst_assoc, Category.assoc, Category.assoc, pullback.condition])) := by simpa using pasteVertIsPullback rfl (pullbackIsPullback _ _) (pullbackPullbackLeftIsPullback f₁ f₂ f₃ f₄) theorem hasPullback_assoc [HasPullback (g₂ ≫ f₃) f₄] : HasPullback f₁ (g₃ ≫ f₂) := ⟨⟨⟨_, pullbackAssocIsPullback f₁ f₂ f₃ f₄⟩⟩⟩ /-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/ def pullbackPullbackRightIsPullback [HasPullback f₁ (g₃ ≫ f₂)] : IsLimit (PullbackCone.mk l₁' l₂' (show l₁' ≫ g₂ = l₂' ≫ g₃ from pullback.lift_snd _ _ _)) := by apply topSquareIsPullback _ rfl (pullbackIsPullback f₁ f₂) simpa [PullbackCone.pasteVert] using PullbackCone.mkSelfIsLimit (pullbackIsPullback _ _) /-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[Y₂] X₃`. -/ def pullbackAssocSymmIsPullback [HasPullback f₁ (g₃ ≫ f₂)] : IsLimit (PullbackCone.mk l₁' (l₂' ≫ g₄) (show l₁' ≫ g₂ ≫ f₃ = (l₂' ≫ g₄) ≫ f₄ by rw [pullback.lift_snd_assoc, Category.assoc, Category.assoc, pullback.condition])) := by simpa [PullbackCone.pasteHoriz] using pasteHorizIsPullback rfl (pullbackIsPullback f₃ f₄) (pullbackPullbackRightIsPullback _ _ _ _) theorem hasPullback_assoc_symm [HasPullback f₁ (g₃ ≫ f₂)] : HasPullback (g₂ ≫ f₃) f₄ := ⟨⟨⟨_, pullbackAssocSymmIsPullback f₁ f₂ f₃ f₄⟩⟩⟩ /-- The canonical isomorphism `(X₁ ×[Y₁] X₂) ×[Y₂] X₃ ≅ X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/ noncomputable def pullbackAssoc [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : pullback (pullback.snd _ _ ≫ f₃ : pullback f₁ f₂ ⟶ _) f₄ ≅ pullback f₁ (pullback.fst _ _ ≫ f₂ : pullback f₃ f₄ ⟶ _) := (pullbackPullbackLeftIsPullback f₁ f₂ f₃ f₄).conePointUniqueUpToIso (pullbackPullbackRightIsPullback f₁ f₂ f₃ f₄) @[reassoc (attr := simp)] theorem pullbackAssoc_inv_fst_fst [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := by trans l₁' ≫ pullback.fst _ _ · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left · exact pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem pullbackAssoc_hom_fst [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by rw [← Iso.eq_inv_comp, pullbackAssoc_inv_fst_fst] @[reassoc (attr := simp)] theorem pullbackAssoc_hom_snd_fst [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by trans l₂ ≫ pullback.fst _ _ · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right · exact pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem pullbackAssoc_hom_snd_snd [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := by trans l₂ ≫ pullback.snd _ _ · rw [← Category.assoc] congr 1 exact IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right · exact pullback.lift_snd _ _ _ @[reassoc (attr := simp)] theorem pullbackAssoc_inv_fst_snd [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by rw [Iso.inv_comp_eq, pullbackAssoc_hom_snd_fst] @[reassoc (attr := simp)] theorem pullbackAssoc_inv_snd [HasPullback ((pullback.snd _ _ : Z₁ ⟶ X₂) ≫ f₃) f₄] [HasPullback f₁ ((pullback.fst _ _ : Z₂ ⟶ X₂) ≫ f₂)] : (pullbackAssoc f₁ f₂ f₃ f₄).inv ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by rw [Iso.inv_comp_eq, pullbackAssoc_hom_snd_snd] end PullbackAssoc section PushoutAssoc /- The objects and morphisms are as follows: ``` Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ f₂ ∨ ∨ X₁ - f₁ -> Y₁ ``` where the two squares are pushouts. We can then construct the pushout squares ``` Z₁ - g₂ -> X₂ - f₃ -> Y₂ | | g₁ l₂ ∨ ∨ X₁ - f₁ -> Y₁ - l₁ -> W and Z₂ - g₄ -> X₃ | | g₃ f₄ ∨ ∨ X₂ Y₂ | | f₂ l₂' ∨ ∨ Y₁ - l₁' -> W' ``` We will show that both `W` and `W'` are pushouts over `f₂, f₃`, and thus we may construct a canonical isomorphism between them. -/ variable {X₁ X₂ X₃ Z₁ Z₂ : C} (g₁ : Z₁ ⟶ X₁) (g₂ : Z₁ ⟶ X₂) (g₃ : Z₂ ⟶ X₂) variable (g₄ : Z₂ ⟶ X₃) [HasPushout g₁ g₂] [HasPushout g₃ g₄] local notation "Y₁" => pushout g₁ g₂ local notation "Y₂" => pushout g₃ g₄ local notation "f₁" => (pushout.inl _ _ : X₁ ⟶ Y₁) local notation "f₂" => (pushout.inr _ _ : X₂ ⟶ Y₁) local notation "f₃" => (pushout.inl _ _ : X₂ ⟶ Y₂) local notation "f₄" => (pushout.inr _ _ : X₃ ⟶ Y₂) local notation "W" => pushout g₁ (g₂ ≫ f₃) local notation "W'" => pushout (g₃ ≫ f₂) g₄ local notation "l₁" => (pushout.desc (pushout.inl _ _) (f₃ ≫ pushout.inr _ _) (pushout.condition.trans (Category.assoc _ _ _)) : Y₁ ⟶ W) local notation "l₂" => (pushout.inr _ _ : Y₂ ⟶ W) local notation "l₁'" => (pushout.inl _ _ : Y₁ ⟶ W') local notation "l₂'" => (pushout.desc (f₂ ≫ pushout.inl _ _) (pushout.inr _ _) (Eq.trans (Eq.symm (Category.assoc _ _ _)) pushout.condition) : Y₂ ⟶ W') /-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutPushoutLeftIsPushout [HasPushout (g₃ ≫ f₂) g₄] : IsColimit (PushoutCocone.mk l₁' l₂' (show f₂ ≫ l₁' = f₃ ≫ l₂' from (pushout.inl_desc _ _ _).symm)) := by apply botSquareIsPushout _ rfl (pushoutIsPushout _ g₄) simpa [PushoutCocone.pasteVert] using PushoutCocone.mkSelfIsColimit (pushoutIsPushout (g₃ ≫ f₂) g₄) /-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutAssocIsPushout [HasPushout (g₃ ≫ f₂) g₄] : IsColimit (PushoutCocone.mk (f₁ ≫ l₁') l₂' (show g₁ ≫ f₁ ≫ l₁' = (g₂ ≫ f₃) ≫ l₂' by rw [Category.assoc, pushout.inl_desc, pushout.condition_assoc])) := by simpa using pasteHorizIsPushout rfl (pushoutIsPushout g₁ g₂) (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄) theorem hasPushout_assoc [HasPushout (g₃ ≫ f₂) g₄] : HasPushout g₁ (g₂ ≫ f₃) := ⟨⟨⟨_, pushoutAssocIsPushout g₁ g₂ g₃ g₄⟩⟩⟩ /-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/ def pushoutPushoutRightIsPushout [HasPushout g₁ (g₂ ≫ f₃)] : IsColimit (PushoutCocone.mk l₁ l₂ (show f₂ ≫ l₁ = f₃ ≫ l₂ from pushout.inr_desc _ _ _)) := by apply rightSquareIsPushout _ rfl (pushoutIsPushout _ _) simpa [PushoutCocone.pasteHoriz] using PushoutCocone.mkSelfIsColimit (pushoutIsPushout _ _) /-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃`. -/ def pushoutAssocSymmIsPushout [HasPushout g₁ (g₂ ≫ f₃)] : IsColimit (PushoutCocone.mk l₁ (f₄ ≫ l₂) (show (g₃ ≫ f₂) ≫ l₁ = g₄ ≫ f₄ ≫ l₂ by rw [Category.assoc, pushout.inr_desc, pushout.condition_assoc])) := by simpa using pasteVertIsPushout rfl (pushoutIsPushout _ _) (pushoutPushoutRightIsPushout _ _ _ _) theorem hasPushout_assoc_symm [HasPushout g₁ (g₂ ≫ f₃)] : HasPushout (g₃ ≫ f₂) g₄ := ⟨⟨⟨_, pushoutAssocSymmIsPushout g₁ g₂ g₃ g₄⟩⟩⟩ -- Porting note: these are not propagating so moved into statements -- variable [HasPushout (g₃ ≫ f₂) g₄] [HasPushout g₁ (g₂ ≫ f₃)] /-- The canonical isomorphism `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃ ≅ X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/ noncomputable def pushoutAssoc [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout (g₃ ≫ pushout.inr _ _ : _ ⟶ pushout g₁ g₂) g₄ ≅ pushout g₁ (g₂ ≫ pushout.inl _ _ : _ ⟶ pushout g₃ g₄) := (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).coconePointUniqueUpToIso (pushoutPushoutRightIsPushout g₁ g₂ g₃ g₄) @[reassoc (attr := simp)] theorem inl_inl_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inl _ _ ≫ pushout.inl _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inl _ _ := by trans f₁ ≫ l₁ · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_hom _ WalkingCospan.left · exact pushout.inl_desc _ _ _ @[reassoc (attr := simp)] theorem inr_inl_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inr _ _ ≫ pushout.inl _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inl _ _ ≫ pushout.inr _ _ := by trans f₂ ≫ l₁ · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_hom _ WalkingCospan.left · exact pushout.inr_desc _ _ _ @[reassoc (attr := simp)] theorem inr_inr_pushoutAssoc_inv [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inr _ _ ≫ pushout.inr _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).inv = pushout.inr _ _ := by trans f₄ ≫ l₂' · congr 1 exact (pushoutPushoutLeftIsPushout g₁ g₂ g₃ g₄).comp_coconePointUniqueUpToIso_inv (pushoutPushoutRightIsPushout g₁ g₂ g₃ g₄) WalkingCospan.right · exact pushout.inr_desc _ _ _ @[reassoc (attr := simp)] theorem inl_pushoutAssoc_inv [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inl _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).inv = pushout.inl _ _ ≫ pushout.inl _ _ := by rw [Iso.comp_inv_eq, Category.assoc, inl_inl_pushoutAssoc_hom] @[reassoc (attr := simp)] theorem inl_inr_pushoutAssoc_inv [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inl _ _ ≫ pushout.inr _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).inv = pushout.inr _ _ ≫ pushout.inl _ _ := by rw [← Category.assoc, Iso.comp_inv_eq, Category.assoc, inr_inl_pushoutAssoc_hom] @[reassoc (attr := simp)] theorem inr_pushoutAssoc_hom [HasPushout (g₃ ≫ (pushout.inr _ _ : X₂ ⟶ Y₁)) g₄] [HasPushout g₁ (g₂ ≫ (pushout.inl _ _ : X₂ ⟶ Y₂))] : pushout.inr _ _ ≫ (pushoutAssoc g₁ g₂ g₃ g₄).hom = pushout.inr _ _ ≫ pushout.inr _ _ := by rw [← Iso.eq_comp_inv, Category.assoc, inr_inr_pushoutAssoc_inv] end PushoutAssoc end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Pullback\CommSq.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Joël Riou, Calle Sönne -/ import Mathlib.CategoryTheory.CommSq import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts import Mathlib.CategoryTheory.Limits.Constructions.ZeroObjects import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Pasting /-! # Pullback and pushout squares, and bicartesian squares We provide another API for pullbacks and pushouts. `IsPullback fst snd f g` is the proposition that ``` P --fst--> X | | snd f | | v v Y ---g---> Zfst ``` is a pullback square. (And similarly for `IsPushout`.) We provide the glue to go back and forth to the usual `IsLimit` API for pullbacks, and prove `IsPullback (pullback.fst f g) (pullback.snd f g) f g` for the usual `pullback f g` provided by the `HasLimit` API. We don't attempt to restate everything we know about pullbacks in this language, but do restate the pasting lemmas. We define bicartesian squares, and show that the pullback and pushout squares for a biproduct are bicartesian. -/ noncomputable section open CategoryTheory open CategoryTheory.Limits universe v₁ v₂ u₁ u₂ namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] attribute [simp] CommSq.mk namespace CommSq variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} /-- The (not necessarily limiting) `PullbackCone h i` implicit in the statement that we have `CommSq f g h i`. -/ def cone (s : CommSq f g h i) : PullbackCone h i := PullbackCone.mk _ _ s.w /-- The (not necessarily limiting) `PushoutCocone f g` implicit in the statement that we have `CommSq f g h i`. -/ def cocone (s : CommSq f g h i) : PushoutCocone f g := PushoutCocone.mk _ _ s.w @[simp] theorem cone_fst (s : CommSq f g h i) : s.cone.fst = f := rfl @[simp] theorem cone_snd (s : CommSq f g h i) : s.cone.snd = g := rfl @[simp] theorem cocone_inl (s : CommSq f g h i) : s.cocone.inl = h := rfl @[simp] theorem cocone_inr (s : CommSq f g h i) : s.cocone.inr = i := rfl /-- The pushout cocone in the opposite category associated to the cone of a commutative square identifies to the cocone of the flipped commutative square in the opposite category -/ def coneOp (p : CommSq f g h i) : p.cone.op ≅ p.flip.op.cocone := PushoutCocone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) /-- The pullback cone in the opposite category associated to the cocone of a commutative square identifies to the cone of the flipped commutative square in the opposite category -/ def coconeOp (p : CommSq f g h i) : p.cocone.op ≅ p.flip.op.cone := PullbackCone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) /-- The pushout cocone obtained from the pullback cone associated to a commutative square in the opposite category identifies to the cocone associated to the flipped square. -/ def coneUnop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) : p.cone.unop ≅ p.flip.unop.cocone := PushoutCocone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) /-- The pullback cone obtained from the pushout cone associated to a commutative square in the opposite category identifies to the cone associated to the flipped square. -/ def coconeUnop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) : p.cocone.unop ≅ p.flip.unop.cone := PullbackCone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) end CommSq /-- The proposition that a square ``` P --fst--> X | | snd f | | v v Y ---g---> Z ``` is a pullback square. (Also known as a fibered product or cartesian square.) -/ structure IsPullback {P X Y Z : C} (fst : P ⟶ X) (snd : P ⟶ Y) (f : X ⟶ Z) (g : Y ⟶ Z) extends CommSq fst snd f g : Prop where /-- the pullback cone is a limit -/ isLimit' : Nonempty (IsLimit (PullbackCone.mk _ _ w)) /-- The proposition that a square ``` Z ---f---> X | | g inl | | v v Y --inr--> P ``` is a pushout square. (Also known as a fiber coproduct or cocartesian square.) -/ structure IsPushout {Z X Y P : C} (f : Z ⟶ X) (g : Z ⟶ Y) (inl : X ⟶ P) (inr : Y ⟶ P) extends CommSq f g inl inr : Prop where /-- the pushout cocone is a colimit -/ isColimit' : Nonempty (IsColimit (PushoutCocone.mk _ _ w)) section /-- A *bicartesian* square is a commutative square ``` W ---f---> X | | g h | | v v Y ---i---> Z ``` that is both a pullback square and a pushout square. -/ structure BicartesianSq {W X Y Z : C} (f : W ⟶ X) (g : W ⟶ Y) (h : X ⟶ Z) (i : Y ⟶ Z) extends IsPullback f g h i, IsPushout f g h i : Prop -- Lean should make these parent projections as `lemma`, not `def`. attribute [nolint defLemma docBlame] BicartesianSq.toIsPushout end /-! We begin by providing some glue between `IsPullback` and the `IsLimit` and `HasLimit` APIs. (And similarly for `IsPushout`.) -/ namespace IsPullback variable {P X Y Z : C} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} /-- The (limiting) `PullbackCone f g` implicit in the statement that we have an `IsPullback fst snd f g`. -/ def cone (h : IsPullback fst snd f g) : PullbackCone f g := h.toCommSq.cone @[simp] theorem cone_fst (h : IsPullback fst snd f g) : h.cone.fst = fst := rfl @[simp] theorem cone_snd (h : IsPullback fst snd f g) : h.cone.snd = snd := rfl /-- The cone obtained from `IsPullback fst snd f g` is a limit cone. -/ noncomputable def isLimit (h : IsPullback fst snd f g) : IsLimit h.cone := h.isLimit'.some /-- API for PullbackCone.IsLimit.lift for `IsPullback` -/ noncomputable def lift (hP : IsPullback fst snd f g) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ P := PullbackCone.IsLimit.lift hP.isLimit h k w @[reassoc (attr := simp)] lemma lift_fst (hP : IsPullback fst snd f g) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : hP.lift h k w ≫ fst = h := PullbackCone.IsLimit.lift_fst hP.isLimit h k w @[reassoc (attr := simp)] lemma lift_snd (hP : IsPullback fst snd f g) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : hP.lift h k w ≫ snd = k := PullbackCone.IsLimit.lift_snd hP.isLimit h k w lemma hom_ext (hP : IsPullback fst snd f g) {W : C} {k l : W ⟶ P} (h₀ : k ≫ fst = l ≫ fst) (h₁ : k ≫ snd = l ≫ snd) : k = l := PullbackCone.IsLimit.hom_ext hP.isLimit h₀ h₁ /-- If `c` is a limiting pullback cone, then we have an `IsPullback c.fst c.snd f g`. -/ theorem of_isLimit {c : PullbackCone f g} (h : Limits.IsLimit c) : IsPullback c.fst c.snd f g := { w := c.condition isLimit' := ⟨IsLimit.ofIsoLimit h (Limits.PullbackCone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat))⟩ } /-- A variant of `of_isLimit` that is more useful with `apply`. -/ theorem of_isLimit' (w : CommSq fst snd f g) (h : Limits.IsLimit w.cone) : IsPullback fst snd f g := of_isLimit h /-- The pullback provided by `HasPullback f g` fits into an `IsPullback`. -/ theorem of_hasPullback (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsPullback (pullback.fst f g) (pullback.snd f g) f g := of_isLimit (limit.isLimit (cospan f g)) /-- If `c` is a limiting binary product cone, and we have a terminal object, then we have `IsPullback c.fst c.snd 0 0` (where each `0` is the unique morphism to the terminal object). -/ theorem of_is_product {c : BinaryFan X Y} (h : Limits.IsLimit c) (t : IsTerminal Z) : IsPullback c.fst c.snd (t.from _) (t.from _) := of_isLimit (isPullbackOfIsTerminalIsProduct _ _ _ _ t (IsLimit.ofIsoLimit h (Limits.Cones.ext (Iso.refl c.pt) (by rintro ⟨⟨⟩⟩ <;> · dsimp simp)))) /-- A variant of `of_is_product` that is more useful with `apply`. -/ theorem of_is_product' (h : Limits.IsLimit (BinaryFan.mk fst snd)) (t : IsTerminal Z) : IsPullback fst snd (t.from _) (t.from _) := of_is_product h t variable (X Y) theorem of_hasBinaryProduct' [HasBinaryProduct X Y] [HasTerminal C] : IsPullback Limits.prod.fst Limits.prod.snd (terminal.from X) (terminal.from Y) := of_is_product (limit.isLimit _) terminalIsTerminal open ZeroObject theorem of_hasBinaryProduct [HasBinaryProduct X Y] [HasZeroObject C] [HasZeroMorphisms C] : IsPullback Limits.prod.fst Limits.prod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert @of_is_product _ _ X Y 0 _ (limit.isLimit _) HasZeroObject.zeroIsTerminal <;> subsingleton section variable {P': C} {fst' : P' ⟶ X} {snd' : P' ⟶ Y} /-- Any object at the top left of a pullback square is isomorphic to the object at the top left of any other pullback square with the same cospan. -/ noncomputable def isoIsPullback (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : P ≅ P' := IsLimit.conePointUniqueUpToIso h.isLimit h'.isLimit @[reassoc (attr := simp)] theorem isoIsPullback_hom_fst (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback h').hom ≫ fst' = fst := IsLimit.conePointUniqueUpToIso_hom_comp h.isLimit h'.isLimit WalkingCospan.left @[reassoc (attr := simp)] theorem isoIsPullback_hom_snd (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback h').hom ≫ snd' = snd := IsLimit.conePointUniqueUpToIso_hom_comp h.isLimit h'.isLimit WalkingCospan.right @[reassoc (attr := simp)] theorem isoIsPullback_inv_fst (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback h').inv ≫ fst = fst' := by simp only [Iso.inv_comp_eq, isoIsPullback_hom_fst] @[reassoc (attr := simp)] theorem isoIsPullback_inv_snd (h : IsPullback fst snd f g) (h' : IsPullback fst' snd' f g) : (h.isoIsPullback h').inv ≫ snd = snd' := by simp only [Iso.inv_comp_eq, isoIsPullback_hom_snd] end variable {X Y} /-- Any object at the top left of a pullback square is isomorphic to the pullback provided by the `HasLimit` API. -/ noncomputable def isoPullback (h : IsPullback fst snd f g) [HasPullback f g] : P ≅ pullback f g := (limit.isoLimitCone ⟨_, h.isLimit⟩).symm @[reassoc (attr := simp)] theorem isoPullback_hom_fst (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.hom ≫ pullback.fst _ _ = fst := by dsimp [isoPullback, cone, CommSq.cone] simp @[reassoc (attr := simp)] theorem isoPullback_hom_snd (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.hom ≫ pullback.snd _ _ = snd := by dsimp [isoPullback, cone, CommSq.cone] simp @[reassoc (attr := simp)] theorem isoPullback_inv_fst (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.inv ≫ fst = pullback.fst _ _ := by simp [Iso.inv_comp_eq] @[reassoc (attr := simp)] theorem isoPullback_inv_snd (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.inv ≫ snd = pullback.snd _ _ := by simp [Iso.inv_comp_eq] theorem of_iso_pullback (h : CommSq fst snd f g) [HasPullback f g] (i : P ≅ pullback f g) (w₁ : i.hom ≫ pullback.fst _ _ = fst) (w₂ : i.hom ≫ pullback.snd _ _ = snd) : IsPullback fst snd f g := of_isLimit' h (Limits.IsLimit.ofIsoLimit (limit.isLimit _) (@PullbackCone.ext _ _ _ _ _ _ _ (PullbackCone.mk _ _ _) _ i w₁.symm w₂.symm).symm) theorem of_horiz_isIso [IsIso fst] [IsIso g] (sq : CommSq fst snd f g) : IsPullback fst snd f g := of_isLimit' sq (by refine PullbackCone.IsLimit.mk _ (fun s => s.fst ≫ inv fst) (by aesop_cat) (fun s => ?_) (by aesop_cat) simp only [← cancel_mono g, Category.assoc, ← sq.w, IsIso.inv_hom_id_assoc, s.condition]) lemma of_iso (h : IsPullback fst snd f g) {P' X' Y' Z' : C} {fst' : P' ⟶ X'} {snd' : P' ⟶ Y'} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} (e₁ : P ≅ P') (e₂ : X ≅ X') (e₃ : Y ≅ Y') (e₄ : Z ≅ Z') (commfst : fst ≫ e₂.hom = e₁.hom ≫ fst') (commsnd : snd ≫ e₃.hom = e₁.hom ≫ snd') (commf : f ≫ e₄.hom = e₂.hom ≫ f') (commg : g ≫ e₄.hom = e₃.hom ≫ g') : IsPullback fst' snd' f' g' where w := by rw [← cancel_epi e₁.hom, ← reassoc_of% commfst, ← commf, ← reassoc_of% commsnd, ← commg, h.w_assoc] isLimit' := ⟨(IsLimit.postcomposeInvEquiv (cospanExt e₂ e₃ e₄ commf.symm commg.symm) _).1 (IsLimit.ofIsoLimit h.isLimit (by refine PullbackCone.ext e₁ ?_ ?_ · change fst = e₁.hom ≫ fst' ≫ e₂.inv rw [← reassoc_of% commfst, e₂.hom_inv_id, Category.comp_id] · change snd = e₁.hom ≫ snd' ≫ e₃.inv rw [← reassoc_of% commsnd, e₃.hom_inv_id, Category.comp_id]))⟩ end IsPullback namespace IsPushout variable {Z X Y P : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} /-- The (colimiting) `PushoutCocone f g` implicit in the statement that we have an `IsPushout f g inl inr`. -/ def cocone (h : IsPushout f g inl inr) : PushoutCocone f g := h.toCommSq.cocone @[simp] theorem cocone_inl (h : IsPushout f g inl inr) : h.cocone.inl = inl := rfl @[simp] theorem cocone_inr (h : IsPushout f g inl inr) : h.cocone.inr = inr := rfl /-- The cocone obtained from `IsPushout f g inl inr` is a colimit cocone. -/ noncomputable def isColimit (h : IsPushout f g inl inr) : IsColimit h.cocone := h.isColimit'.some /-- API for PushoutCocone.IsColimit.lift for `IsPushout` -/ noncomputable def desc (hP : IsPushout f g inl inr) {W : C} (h : X ⟶ W) (k : Y ⟶ W) (w : f ≫ h = g ≫ k) : P ⟶ W := PushoutCocone.IsColimit.desc hP.isColimit h k w @[reassoc (attr := simp)] lemma inl_desc (hP : IsPushout f g inl inr) {W : C} (h : X ⟶ W) (k : Y ⟶ W) (w : f ≫ h = g ≫ k) : inl ≫ hP.desc h k w = h := PushoutCocone.IsColimit.inl_desc hP.isColimit h k w @[reassoc (attr := simp)] lemma inr_desc (hP : IsPushout f g inl inr) {W : C} (h : X ⟶ W) (k : Y ⟶ W) (w : f ≫ h = g ≫ k) : inr ≫ hP.desc h k w = k := PushoutCocone.IsColimit.inr_desc hP.isColimit h k w lemma hom_ext (hP : IsPushout f g inl inr) {W : C} {k l : P ⟶ W} (h₀ : inl ≫ k = inl ≫ l) (h₁ : inr ≫ k = inr ≫ l) : k = l := PushoutCocone.IsColimit.hom_ext hP.isColimit h₀ h₁ /-- If `c` is a colimiting pushout cocone, then we have an `IsPushout f g c.inl c.inr`. -/ theorem of_isColimit {c : PushoutCocone f g} (h : Limits.IsColimit c) : IsPushout f g c.inl c.inr := { w := c.condition isColimit' := ⟨IsColimit.ofIsoColimit h (Limits.PushoutCocone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat))⟩ } /-- A variant of `of_isColimit` that is more useful with `apply`. -/ theorem of_isColimit' (w : CommSq f g inl inr) (h : Limits.IsColimit w.cocone) : IsPushout f g inl inr := of_isColimit h /-- The pushout provided by `HasPushout f g` fits into an `IsPushout`. -/ theorem of_hasPushout (f : Z ⟶ X) (g : Z ⟶ Y) [HasPushout f g] : IsPushout f g (pushout.inl f g) (pushout.inr f g) := of_isColimit (colimit.isColimit (span f g)) /-- If `c` is a colimiting binary coproduct cocone, and we have an initial object, then we have `IsPushout 0 0 c.inl c.inr` (where each `0` is the unique morphism from the initial object). -/ theorem of_is_coproduct {c : BinaryCofan X Y} (h : Limits.IsColimit c) (t : IsInitial Z) : IsPushout (t.to _) (t.to _) c.inl c.inr := of_isColimit (isPushoutOfIsInitialIsCoproduct _ _ _ _ t (IsColimit.ofIsoColimit h (Limits.Cocones.ext (Iso.refl c.pt) (by rintro ⟨⟨⟩⟩ <;> · dsimp simp)))) /-- A variant of `of_is_coproduct` that is more useful with `apply`. -/ theorem of_is_coproduct' (h : Limits.IsColimit (BinaryCofan.mk inl inr)) (t : IsInitial Z) : IsPushout (t.to _) (t.to _) inl inr := of_is_coproduct h t variable (X Y) theorem of_hasBinaryCoproduct' [HasBinaryCoproduct X Y] [HasInitial C] : IsPushout (initial.to _) (initial.to _) (coprod.inl : X ⟶ _) (coprod.inr : Y ⟶ _) := of_is_coproduct (colimit.isColimit _) initialIsInitial open ZeroObject theorem of_hasBinaryCoproduct [HasBinaryCoproduct X Y] [HasZeroObject C] [HasZeroMorphisms C] : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) coprod.inl coprod.inr := by convert @of_is_coproduct _ _ 0 X Y _ (colimit.isColimit _) HasZeroObject.zeroIsInitial <;> subsingleton section variable {P': C} {inl' : X ⟶ P'} {inr' : Y ⟶ P'} /-- Any object at the bottom right of a pushout square is isomorphic to the object at the bottom right of any other pushout square with the same span. -/ noncomputable def isoIsPushout (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : P ≅ P' := IsColimit.coconePointUniqueUpToIso h.isColimit h'.isColimit @[reassoc (attr := simp)] theorem inl_isoIsPushout_hom (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inl ≫ (h.isoIsPushout h').hom = inl' := IsColimit.comp_coconePointUniqueUpToIso_hom h.isColimit h'.isColimit WalkingSpan.left @[reassoc (attr := simp)] theorem inr_isoIsPushout_hom (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inr ≫ (h.isoIsPushout h').hom = inr' := IsColimit.comp_coconePointUniqueUpToIso_hom h.isColimit h'.isColimit WalkingSpan.right @[reassoc (attr := simp)] theorem inl_isoIsPushout_inv (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inl' ≫ (h.isoIsPushout h').inv = inl := by simp only [Iso.comp_inv_eq, inl_isoIsPushout_hom] @[reassoc (attr := simp)] theorem inr_isoIsPushout_inv (h : IsPushout f g inl inr) (h' : IsPushout f g inl' inr') : inr' ≫ (h.isoIsPushout h').inv = inr := by simp only [Iso.comp_inv_eq, inr_isoIsPushout_hom] end variable {X Y} /-- Any object at the top left of a pullback square is isomorphic to the pullback provided by the `HasLimit` API. -/ noncomputable def isoPushout (h : IsPushout f g inl inr) [HasPushout f g] : P ≅ pushout f g := (colimit.isoColimitCocone ⟨_, h.isColimit⟩).symm @[reassoc (attr := simp)] theorem inl_isoPushout_inv (h : IsPushout f g inl inr) [HasPushout f g] : pushout.inl _ _ ≫ h.isoPushout.inv = inl := by dsimp [isoPushout, cocone, CommSq.cocone] simp @[reassoc (attr := simp)] theorem inr_isoPushout_inv (h : IsPushout f g inl inr) [HasPushout f g] : pushout.inr _ _ ≫ h.isoPushout.inv = inr := by dsimp [isoPushout, cocone, CommSq.cocone] simp @[reassoc (attr := simp)] theorem inl_isoPushout_hom (h : IsPushout f g inl inr) [HasPushout f g] : inl ≫ h.isoPushout.hom = pushout.inl _ _ := by simp [← Iso.eq_comp_inv] @[reassoc (attr := simp)] theorem inr_isoPushout_hom (h : IsPushout f g inl inr) [HasPushout f g] : inr ≫ h.isoPushout.hom = pushout.inr _ _ := by simp [← Iso.eq_comp_inv] theorem of_iso_pushout (h : CommSq f g inl inr) [HasPushout f g] (i : P ≅ pushout f g) (w₁ : inl ≫ i.hom = pushout.inl _ _) (w₂ : inr ≫ i.hom = pushout.inr _ _) : IsPushout f g inl inr := of_isColimit' h (Limits.IsColimit.ofIsoColimit (colimit.isColimit _) (PushoutCocone.ext (s := PushoutCocone.mk ..) i w₁ w₂).symm) lemma of_iso (h : IsPushout f g inl inr) {Z' X' Y' P' : C} {f' : Z' ⟶ X'} {g' : Z' ⟶ Y'} {inl' : X' ⟶ P'} {inr' : Y' ⟶ P'} (e₁ : Z ≅ Z') (e₂ : X ≅ X') (e₃ : Y ≅ Y') (e₄ : P ≅ P') (commf : f ≫ e₂.hom = e₁.hom ≫ f') (commg : g ≫ e₃.hom = e₁.hom ≫ g') (comminl : inl ≫ e₄.hom = e₂.hom ≫ inl') (comminr : inr ≫ e₄.hom = e₃.hom ≫ inr') : IsPushout f' g' inl' inr' where w := by rw [← cancel_epi e₁.hom, ← reassoc_of% commf, ← comminl, ← reassoc_of% commg, ← comminr, h.w_assoc] isColimit' := ⟨(IsColimit.precomposeHomEquiv (spanExt e₁ e₂ e₃ commf.symm commg.symm) _).1 (IsColimit.ofIsoColimit h.isColimit (PushoutCocone.ext e₄ comminl comminr))⟩ end IsPushout namespace IsPullback variable {P X Y Z : C} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} theorem flip (h : IsPullback fst snd f g) : IsPullback snd fst g f := of_isLimit (PullbackCone.flipIsLimit h.isLimit) theorem flip_iff : IsPullback fst snd f g ↔ IsPullback snd fst g f := ⟨flip, flip⟩ section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The square with `0 : 0 ⟶ 0` on the left and `𝟙 X` on the right is a pullback square. -/ @[simp] theorem zero_left (X : C) : IsPullback (0 : 0 ⟶ X) (0 : (0 : C) ⟶ 0) (𝟙 X) (0 : 0 ⟶ X) := { w := by simp isLimit' := ⟨{ lift := fun s => 0 fac := fun s => by simpa [eq_iff_true_of_subsingleton] using @PullbackCone.equalizer_ext _ _ _ _ _ _ _ s _ 0 (𝟙 _) (by simpa using (PullbackCone.condition s).symm) }⟩ } /-- The square with `0 : 0 ⟶ 0` on the top and `𝟙 X` on the bottom is a pullback square. -/ @[simp] theorem zero_top (X : C) : IsPullback (0 : (0 : C) ⟶ 0) (0 : 0 ⟶ X) (0 : 0 ⟶ X) (𝟙 X) := (zero_left X).flip /-- The square with `0 : 0 ⟶ 0` on the right and `𝟙 X` on the left is a pullback square. -/ @[simp] theorem zero_right (X : C) : IsPullback (0 : X ⟶ 0) (𝟙 X) (0 : (0 : C) ⟶ 0) (0 : X ⟶ 0) := of_iso_pullback (by simp) ((zeroProdIso X).symm ≪≫ (pullbackZeroZeroIso _ _).symm) (by simp [eq_iff_true_of_subsingleton]) (by simp) /-- The square with `0 : 0 ⟶ 0` on the bottom and `𝟙 X` on the top is a pullback square. -/ @[simp] theorem zero_bot (X : C) : IsPullback (𝟙 X) (0 : X ⟶ 0) (0 : X ⟶ 0) (0 : (0 : C) ⟶ 0) := (zero_right X).flip end -- Objects here are arranged in a 3x2 grid, and indexed by their xy coordinates. -- Morphisms are named `hᵢⱼ` for a horizontal morphism starting at `(i,j)`, -- and `vᵢⱼ` for a vertical morphism starting at `(i,j)`. /-- Paste two pullback squares "vertically" to obtain another pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem paste_vert {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ := of_isLimit (pasteHorizIsPullback rfl t.isLimit s.isLimit) /-- Paste two pullback squares "horizontally" to obtain another pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem paste_horiz {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) := (paste_vert s.flip t.flip).flip /-- Given a pullback square assembled from a commuting square on the top and a pullback square on the bottom, the top square is a pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_bot {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁) (p : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := of_isLimit (leftSquareIsPullback (PullbackCone.mk h₁₁ _ p) rfl t.isLimit s.isLimit) /-- Given a pullback square assembled from a commuting square on the left and a pullback square on the right, the left square is a pullback square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_right {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (p : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := (of_bot s.flip p.symm t.flip).flip theorem paste_vert_iff {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) (e : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ ↔ IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := ⟨fun h => h.of_bot e s, fun h => h.paste_vert s⟩ theorem paste_horiz_iff {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) (e : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) ↔ IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := ⟨fun h => h.of_right e s, fun h => h.paste_horiz s⟩ /-- Variant of `IsPullback.of_right` where `h₁₁` is induced from a morphism `h₁₃ : X₁₁ ⟶ X₁₃`, and the universal property of the right square. The objects fit in the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_right' {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {h₁₃ : X₁₁ ⟶ X₁₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₃ v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback (t.lift h₁₃ (v₁₁ ≫ h₂₁) (by rw [s.w, Category.assoc])) v₁₁ v₁₂ h₂₁ := of_right ((t.lift_fst _ _ _) ▸ s) (t.lift_snd _ _ _) t /-- Variant of `IsPullback.of_bot`, where `v₁₁` is induced from a morphism `v₃₁ : X₁₁ ⟶ X₃₁`, and the universal property of the bottom square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_bot' {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₃₁ : X₁₁ ⟶ X₃₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ v₃₁ (v₁₂ ≫ v₂₂) h₃₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ (t.lift (h₁₁ ≫ v₁₂) v₃₁ (by rw [Category.assoc, s.w])) v₁₂ h₂₁ := of_bot ((t.lift_snd _ _ _) ▸ s) (by simp only [lift_fst]) t section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject theorem of_isBilimit {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.fst b.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert IsPullback.of_is_product' h.isLimit HasZeroObject.zeroIsTerminal <;> subsingleton @[simp] theorem of_has_biproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.fst biprod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := of_isBilimit (BinaryBiproduct.isBilimit X Y) theorem inl_snd' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.inl (0 : X ⟶ 0) b.snd (0 : 0 ⟶ Y) := by refine of_right ?_ (by simp) (of_isBilimit h) simp /-- The square ``` X --inl--> X ⊞ Y | | 0 snd | | v v 0 ---0-----> Y ``` is a pullback square. -/ @[simp] theorem inl_snd (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.inl (0 : X ⟶ 0) biprod.snd (0 : 0 ⟶ Y) := inl_snd' (BinaryBiproduct.isBilimit X Y) theorem inr_fst' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.inr (0 : Y ⟶ 0) b.fst (0 : 0 ⟶ X) := by apply flip refine of_bot ?_ (by simp) (of_isBilimit h) simp /-- The square ``` Y --inr--> X ⊞ Y | | 0 fst | | v v 0 ---0-----> X ``` is a pullback square. -/ @[simp] theorem inr_fst (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.inr (0 : Y ⟶ 0) biprod.fst (0 : 0 ⟶ X) := inr_fst' (BinaryBiproduct.isBilimit X Y) theorem of_is_bilimit' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := by refine IsPullback.of_right ?_ (by simp) (IsPullback.inl_snd' h).flip simp theorem of_hasBinaryBiproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPullback (0 : 0 ⟶ X) (0 : 0 ⟶ Y) biprod.inl biprod.inr := of_is_bilimit' (BinaryBiproduct.isBilimit X Y) instance hasPullback_biprod_fst_biprod_snd [HasBinaryBiproduct X Y] : HasPullback (biprod.inl : X ⟶ _) (biprod.inr : Y ⟶ _) := HasLimit.mk ⟨_, (of_hasBinaryBiproduct X Y).isLimit⟩ /-- The pullback of `biprod.inl` and `biprod.inr` is the zero object. -/ def pullbackBiprodInlBiprodInr [HasBinaryBiproduct X Y] : pullback (biprod.inl : X ⟶ _) (biprod.inr : Y ⟶ _) ≅ 0 := limit.isoLimitCone ⟨_, (of_hasBinaryBiproduct X Y).isLimit⟩ end theorem op (h : IsPullback fst snd f g) : IsPushout g.op f.op snd.op fst.op := IsPushout.of_isColimit (IsColimit.ofIsoColimit (Limits.PullbackCone.isLimitEquivIsColimitOp h.flip.cone h.flip.isLimit) h.toCommSq.flip.coneOp) theorem unop {P X Y Z : Cᵒᵖ} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} (h : IsPullback fst snd f g) : IsPushout g.unop f.unop snd.unop fst.unop := IsPushout.of_isColimit (IsColimit.ofIsoColimit (Limits.PullbackCone.isLimitEquivIsColimitUnop h.flip.cone h.flip.isLimit) h.toCommSq.flip.coneUnop) theorem of_vert_isIso [IsIso snd] [IsIso f] (sq : CommSq fst snd f g) : IsPullback fst snd f g := IsPullback.flip (of_horiz_isIso sq.flip) lemma of_id_fst : IsPullback (𝟙 _) f f (𝟙 _) := IsPullback.of_horiz_isIso ⟨by simp⟩ lemma of_id_snd : IsPullback f (𝟙 _) (𝟙 _) f := IsPullback.of_vert_isIso ⟨by simp⟩ /-- The following diagram is a pullback ``` X --f--> Z | | id id v v X --f--> Z ``` -/ lemma id_vert (f : X ⟶ Z) : IsPullback f (𝟙 X) (𝟙 Z) f := of_vert_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ /-- The following diagram is a pullback ``` X --id--> X | | f f v v Z --id--> Z ``` -/ lemma id_horiz (f : X ⟶ Z) : IsPullback (𝟙 X) f f (𝟙 Z) := of_horiz_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ end IsPullback namespace IsPushout variable {Z X Y P : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} theorem flip (h : IsPushout f g inl inr) : IsPushout g f inr inl := of_isColimit (PushoutCocone.flipIsColimit h.isColimit) theorem flip_iff : IsPushout f g inl inr ↔ IsPushout g f inr inl := ⟨flip, flip⟩ section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The square with `0 : 0 ⟶ 0` on the right and `𝟙 X` on the left is a pushout square. -/ @[simp] theorem zero_right (X : C) : IsPushout (0 : X ⟶ 0) (𝟙 X) (0 : (0 : C) ⟶ 0) (0 : X ⟶ 0) := { w := by simp isColimit' := ⟨{ desc := fun s => 0 fac := fun s => by have c := @PushoutCocone.coequalizer_ext _ _ _ _ _ _ _ s _ 0 (𝟙 _) (by simp [eq_iff_true_of_subsingleton]) (by simpa using PushoutCocone.condition s) dsimp at c simpa using c }⟩ } /-- The square with `0 : 0 ⟶ 0` on the bottom and `𝟙 X` on the top is a pushout square. -/ @[simp] theorem zero_bot (X : C) : IsPushout (𝟙 X) (0 : X ⟶ 0) (0 : X ⟶ 0) (0 : (0 : C) ⟶ 0) := (zero_right X).flip /-- The square with `0 : 0 ⟶ 0` on the right left `𝟙 X` on the right is a pushout square. -/ @[simp] theorem zero_left (X : C) : IsPushout (0 : 0 ⟶ X) (0 : (0 : C) ⟶ 0) (𝟙 X) (0 : 0 ⟶ X) := of_iso_pushout (by simp) ((coprodZeroIso X).symm ≪≫ (pushoutZeroZeroIso _ _).symm) (by simp) (by simp [eq_iff_true_of_subsingleton]) /-- The square with `0 : 0 ⟶ 0` on the top and `𝟙 X` on the bottom is a pushout square. -/ @[simp] theorem zero_top (X : C) : IsPushout (0 : (0 : C) ⟶ 0) (0 : 0 ⟶ X) (0 : 0 ⟶ X) (𝟙 X) := (zero_left X).flip end -- Objects here are arranged in a 3x2 grid, and indexed by their xy coordinates. -- Morphisms are named `hᵢⱼ` for a horizontal morphism starting at `(i,j)`, -- and `vᵢⱼ` for a vertical morphism starting at `(i,j)`. /-- Paste two pushout squares "vertically" to obtain another pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem paste_vert {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPushout h₂₁ v₂₁ v₂₂ h₃₁) : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ := of_isColimit (pasteHorizIsPushout rfl s.isColimit t.isColimit) /-- Paste two pushout squares "horizontally" to obtain another pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem paste_horiz {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPushout h₁₂ v₁₂ v₁₃ h₂₂) : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) := (paste_vert s.flip t.flip).flip /-- Given a pushout square assembled from a pushout square on the top and a commuting square on the bottom, the bottom square is a pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_top {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁) (p : h₂₁ ≫ v₂₂ = v₂₁ ≫ h₃₁) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₂₁ v₂₁ v₂₂ h₃₁ := of_isColimit <| rightSquareIsPushout (PushoutCocone.mk _ _ p) (cocone_inr _) t.isColimit s.isColimit /-- Given a pushout square assembled from a pushout square on the left and a commuting square on the right, the right square is a pushout square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_left {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (p : h₁₂ ≫ v₁₃ = v₁₂ ≫ h₂₂) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₁₂ v₁₂ v₁₃ h₂₂ := (of_top s.flip p.symm t.flip).flip theorem paste_vert_iff {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (e : h₂₁ ≫ v₂₂ = v₂₁ ≫ h₃₁) : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ ↔ IsPushout h₂₁ v₂₁ v₂₂ h₃₁ := ⟨fun h => h.of_top e s, s.paste_vert⟩ theorem paste_horiz_iff {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (e : h₁₂ ≫ v₁₃ = v₁₂ ≫ h₂₂) : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) ↔ IsPushout h₁₂ v₁₂ v₁₃ h₂₂ := ⟨fun h => h.of_left e s, s.paste_horiz⟩ /-- Variant of `IsPushout.of_top` where `v₂₂` is induced from a morphism `v₁₃ : X₁₂ ⟶ X₃₂`, and the universal property of the top square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ | | v₁₁ v₁₂ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ | | v₂₁ v₂₂ ↓ ↓ X₃₁ - h₃₁ -> X₃₂ ``` -/ theorem of_top' {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₂ ⟶ X₃₂} {v₂₁ : X₂₁ ⟶ X₃₁} (s : IsPushout h₁₁ (v₁₁ ≫ v₂₁) v₁₃ h₃₁) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₂₁ v₂₁ (t.desc v₁₃ (v₂₁ ≫ h₃₁) (by rw [s.w, Category.assoc])) h₃₁ := of_top ((t.inl_desc _ _ _).symm ▸ s) (t.inr_desc _ _ _) t /-- Variant of `IsPushout.of_right` where `h₂₂` is induced from a morphism `h₂₃ : X₂₁ ⟶ X₂₃`, and the universal property of the left square. The objects in the statement fit into the following diagram: ``` X₁₁ - h₁₁ -> X₁₂ - h₁₂ -> X₁₃ | | | v₁₁ v₁₂ v₁₃ ↓ ↓ ↓ X₂₁ - h₂₁ -> X₂₂ - h₂₂ -> X₂₃ ``` -/ theorem of_left' {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₃ : X₂₁ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ h₂₃) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₁₂ v₁₂ v₁₃ (t.desc (h₁₂ ≫ v₁₃) h₂₃ (by rw [← Category.assoc, s.w])) := of_left ((t.inr_desc _ _ _).symm ▸ s) (by simp only [inl_desc]) t section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject theorem of_isBilimit {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := by convert IsPushout.of_is_coproduct' h.isColimit HasZeroObject.zeroIsInitial <;> subsingleton @[simp] theorem of_has_biproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) biprod.inl biprod.inr := of_isBilimit (BinaryBiproduct.isBilimit X Y) theorem inl_snd' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout b.inl (0 : X ⟶ 0) b.snd (0 : 0 ⟶ Y) := by apply flip refine of_left ?_ (by simp) (of_isBilimit h) simp /-- The square ``` X --inl--> X ⊞ Y | | 0 snd | | v v 0 ---0-----> Y ``` is a pushout square. -/ theorem inl_snd (X Y : C) [HasBinaryBiproduct X Y] : IsPushout biprod.inl (0 : X ⟶ 0) biprod.snd (0 : 0 ⟶ Y) := inl_snd' (BinaryBiproduct.isBilimit X Y) theorem inr_fst' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout b.inr (0 : Y ⟶ 0) b.fst (0 : 0 ⟶ X) := by refine of_top ?_ (by simp) (of_isBilimit h) simp /-- The square ``` Y --inr--> X ⊞ Y | | 0 fst | | v v 0 ---0-----> X ``` is a pushout square. -/ theorem inr_fst (X Y : C) [HasBinaryBiproduct X Y] : IsPushout biprod.inr (0 : Y ⟶ 0) biprod.fst (0 : 0 ⟶ X) := inr_fst' (BinaryBiproduct.isBilimit X Y) theorem of_is_bilimit' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout b.fst b.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by refine IsPushout.of_left ?_ (by simp) (IsPushout.inl_snd' h) simp theorem of_hasBinaryBiproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPushout biprod.fst biprod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := of_is_bilimit' (BinaryBiproduct.isBilimit X Y) instance hasPushout_biprod_fst_biprod_snd [HasBinaryBiproduct X Y] : HasPushout (biprod.fst : _ ⟶ X) (biprod.snd : _ ⟶ Y) := HasColimit.mk ⟨_, (of_hasBinaryBiproduct X Y).isColimit⟩ /-- The pushout of `biprod.fst` and `biprod.snd` is the zero object. -/ def pushoutBiprodFstBiprodSnd [HasBinaryBiproduct X Y] : pushout (biprod.fst : _ ⟶ X) (biprod.snd : _ ⟶ Y) ≅ 0 := colimit.isoColimitCocone ⟨_, (of_hasBinaryBiproduct X Y).isColimit⟩ end theorem op (h : IsPushout f g inl inr) : IsPullback inr.op inl.op g.op f.op := IsPullback.of_isLimit (IsLimit.ofIsoLimit (Limits.PushoutCocone.isColimitEquivIsLimitOp h.flip.cocone h.flip.isColimit) h.toCommSq.flip.coconeOp) theorem unop {Z X Y P : Cᵒᵖ} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} (h : IsPushout f g inl inr) : IsPullback inr.unop inl.unop g.unop f.unop := IsPullback.of_isLimit (IsLimit.ofIsoLimit (Limits.PushoutCocone.isColimitEquivIsLimitUnop h.flip.cocone h.flip.isColimit) h.toCommSq.flip.coconeUnop) theorem of_horiz_isIso [IsIso f] [IsIso inr] (sq : CommSq f g inl inr) : IsPushout f g inl inr := of_isColimit' sq (by refine PushoutCocone.IsColimit.mk _ (fun s => inv inr ≫ s.inr) (fun s => ?_) (by aesop_cat) (by aesop_cat) simp only [← cancel_epi f, s.condition, sq.w_assoc, IsIso.hom_inv_id_assoc]) theorem of_vert_isIso [IsIso g] [IsIso inl] (sq : CommSq f g inl inr) : IsPushout f g inl inr := (of_horiz_isIso sq.flip).flip lemma of_id_fst : IsPushout (𝟙 _) f f (𝟙 _) := IsPushout.of_horiz_isIso ⟨by simp⟩ lemma of_id_snd : IsPushout f (𝟙 _) (𝟙 _) f := IsPushout.of_vert_isIso ⟨by simp⟩ /-- The following diagram is a pullback ``` X --f--> Z | | id id v v X --f--> Z ``` -/ lemma id_vert (f : X ⟶ Z) : IsPushout f (𝟙 X) (𝟙 Z) f := of_vert_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ /-- The following diagram is a pullback ``` X --id--> X | | f f v v Z --id--> Z ``` -/ lemma id_horiz (f : X ⟶ Z) : IsPushout (𝟙 X) f f (𝟙 Z) := of_horiz_isIso ⟨by simp only [Category.id_comp, Category.comp_id]⟩ end IsPushout section Equalizer variable {X Y Z : C} {f f' : X ⟶ Y} {g g' : Y ⟶ Z} /-- If `f : X ⟶ Y`, `g g' : Y ⟶ Z` forms a pullback square, then `f` is the equalizer of `g` and `g'`. -/ noncomputable def IsPullback.isLimitFork (H : IsPullback f f g g') : IsLimit (Fork.ofι f H.w) := by fapply Fork.IsLimit.mk · exact fun s => H.isLimit.lift (PullbackCone.mk s.ι s.ι s.condition) · exact fun s => H.isLimit.fac _ WalkingCospan.left · intro s m e apply PullbackCone.IsLimit.hom_ext H.isLimit <;> refine e.trans ?_ <;> symm <;> exact H.isLimit.fac _ _ /-- If `f f' : X ⟶ Y`, `g : Y ⟶ Z` forms a pushout square, then `g` is the coequalizer of `f` and `f'`. -/ noncomputable def IsPushout.isLimitFork (H : IsPushout f f' g g) : IsColimit (Cofork.ofπ g H.w) := by fapply Cofork.IsColimit.mk · exact fun s => H.isColimit.desc (PushoutCocone.mk s.π s.π s.condition) · exact fun s => H.isColimit.fac _ WalkingSpan.left · intro s m e apply PushoutCocone.IsColimit.hom_ext H.isColimit <;> refine e.trans ?_ <;> symm <;> exact H.isColimit.fac _ _ end Equalizer namespace BicartesianSq variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} theorem of_isPullback_isPushout (p₁ : IsPullback f g h i) (p₂ : IsPushout f g h i) : BicartesianSq f g h i := BicartesianSq.mk p₁ p₂.isColimit' theorem flip (p : BicartesianSq f g h i) : BicartesianSq g f i h := of_isPullback_isPushout p.toIsPullback.flip p.toIsPushout.flip variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- ``` X ⊞ Y --fst--> X | | snd 0 | | v v Y -----0---> 0 ``` is a bicartesian square. -/ theorem of_is_biproduct₁ {b : BinaryBicone X Y} (h : b.IsBilimit) : BicartesianSq b.fst b.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := of_isPullback_isPushout (IsPullback.of_isBilimit h) (IsPushout.of_is_bilimit' h) /-- ``` 0 -----0---> X | | 0 inl | | v v Y --inr--> X ⊞ Y ``` is a bicartesian square. -/ theorem of_is_biproduct₂ {b : BinaryBicone X Y} (h : b.IsBilimit) : BicartesianSq (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := of_isPullback_isPushout (IsPullback.of_is_bilimit' h) (IsPushout.of_isBilimit h) /-- ``` X ⊞ Y --fst--> X | | snd 0 | | v v Y -----0---> 0 ``` is a bicartesian square. -/ @[simp] theorem of_has_biproduct₁ [HasBinaryBiproduct X Y] : BicartesianSq biprod.fst biprod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert of_is_biproduct₁ (BinaryBiproduct.isBilimit X Y) /-- ``` 0 -----0---> X | | 0 inl | | v v Y --inr--> X ⊞ Y ``` is a bicartesian square. -/ @[simp] theorem of_has_biproduct₂ [HasBinaryBiproduct X Y] : BicartesianSq (0 : 0 ⟶ X) (0 : 0 ⟶ Y) biprod.inl biprod.inr := by convert of_is_biproduct₂ (BinaryBiproduct.isBilimit X Y) end BicartesianSq section Functor variable {D : Type u₂} [Category.{v₂} D] variable (F : C ⥤ D) {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} theorem Functor.map_isPullback [PreservesLimit (cospan h i) F] (s : IsPullback f g h i) : IsPullback (F.map f) (F.map g) (F.map h) (F.map i) := by -- This is made slightly awkward because `C` and `D` have different universes, -- and so the relevant `WalkingCospan` diagrams live in different universes too! refine IsPullback.of_isLimit' (F.map_commSq s.toCommSq) (IsLimit.equivOfNatIsoOfIso (cospanCompIso F h i) _ _ (WalkingCospan.ext ?_ ?_ ?_) (isLimitOfPreserves F s.isLimit)) · rfl · simp · simp theorem Functor.map_isPushout [PreservesColimit (span f g) F] (s : IsPushout f g h i) : IsPushout (F.map f) (F.map g) (F.map h) (F.map i) := by refine IsPushout.of_isColimit' (F.map_commSq s.toCommSq) (IsColimit.equivOfNatIsoOfIso (spanCompIso F f g) _ _ (WalkingSpan.ext ?_ ?_ ?_) (isColimitOfPreserves F s.isColimit)) · rfl · simp · simp alias IsPullback.map := Functor.map_isPullback alias IsPushout.map := Functor.map_isPushout theorem IsPullback.of_map [ReflectsLimit (cospan h i) F] (e : f ≫ h = g ≫ i) (H : IsPullback (F.map f) (F.map g) (F.map h) (F.map i)) : IsPullback f g h i := by refine ⟨⟨e⟩, ⟨isLimitOfReflects F <| ?_⟩⟩ refine (IsLimit.equivOfNatIsoOfIso (cospanCompIso F h i) _ _ (WalkingCospan.ext ?_ ?_ ?_)).symm H.isLimit exacts [Iso.refl _, (Category.comp_id _).trans (Category.id_comp _).symm, (Category.comp_id _).trans (Category.id_comp _).symm] theorem IsPullback.of_map_of_faithful [ReflectsLimit (cospan h i) F] [F.Faithful] (H : IsPullback (F.map f) (F.map g) (F.map h) (F.map i)) : IsPullback f g h i := H.of_map F (F.map_injective <| by simpa only [F.map_comp] using H.w) theorem IsPullback.map_iff {D : Type*} [Category D] (F : C ⥤ D) [PreservesLimit (cospan h i) F] [ReflectsLimit (cospan h i) F] (e : f ≫ h = g ≫ i) : IsPullback (F.map f) (F.map g) (F.map h) (F.map i) ↔ IsPullback f g h i := ⟨fun h => h.of_map F e, fun h => h.map F⟩ theorem IsPushout.of_map [ReflectsColimit (span f g) F] (e : f ≫ h = g ≫ i) (H : IsPushout (F.map f) (F.map g) (F.map h) (F.map i)) : IsPushout f g h i := by refine ⟨⟨e⟩, ⟨isColimitOfReflects F <| ?_⟩⟩ refine (IsColimit.equivOfNatIsoOfIso (spanCompIso F f g) _ _ (WalkingSpan.ext ?_ ?_ ?_)).symm H.isColimit exacts [Iso.refl _, (Category.comp_id _).trans (Category.id_comp _), (Category.comp_id _).trans (Category.id_comp _)] theorem IsPushout.of_map_of_faithful [ReflectsColimit (span f g) F] [F.Faithful] (H : IsPushout (F.map f) (F.map g) (F.map h) (F.map i)) : IsPushout f g h i := H.of_map F (F.map_injective <| by simpa only [F.map_comp] using H.w) theorem IsPushout.map_iff {D : Type*} [Category D] (F : C ⥤ D) [PreservesColimit (span f g) F] [ReflectsColimit (span f g) F] (e : f ≫ h = g ≫ i) : IsPushout (F.map f) (F.map g) (F.map h) (F.map i) ↔ IsPushout f g h i := ⟨fun h => h.of_map F e, fun h => h.map F⟩ end Functor end CategoryTheory
CategoryTheory\Limits\Shapes\Pullback\Cospan.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # Cospan & Span We define a category `WalkingCospan` (resp. `WalkingSpan`), which is the index category for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g` and `span f g` construct functors from the walking (co)span, hitting the given morphisms. ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits -- attribute [local tidy] tactic.case_bash Porting note: no tidy, no local /-- The type of objects for the diagram indexing a pullback, defined as a special case of `WidePullbackShape`. -/ abbrev WalkingCospan : Type := WidePullbackShape WalkingPair /-- The left point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.left : WalkingCospan := some WalkingPair.left /-- The right point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.right : WalkingCospan := some WalkingPair.right /-- The central point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.one : WalkingCospan := none /-- The type of objects for the diagram indexing a pushout, defined as a special case of `WidePushoutShape`. -/ abbrev WalkingSpan : Type := WidePushoutShape WalkingPair /-- The left point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.left : WalkingSpan := some WalkingPair.left /-- The right point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.right : WalkingSpan := some WalkingPair.right /-- The central point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.zero : WalkingSpan := none namespace WalkingCospan /-- The type of arrows for the diagram indexing a pullback. -/ abbrev Hom : WalkingCospan → WalkingCospan → Type := WidePullbackShape.Hom /-- The left arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inl : left ⟶ one := WidePullbackShape.Hom.term _ /-- The right arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inr : right ⟶ one := WidePullbackShape.Hom.term _ /-- The identity arrows of the walking cospan. -/ @[match_pattern] abbrev Hom.id (X : WalkingCospan) : X ⟶ X := WidePullbackShape.Hom.id X instance (X Y : WalkingCospan) : Subsingleton (X ⟶ Y) := by constructor; intros; simp [eq_iff_true_of_subsingleton] end WalkingCospan namespace WalkingSpan /-- The type of arrows for the diagram indexing a pushout. -/ abbrev Hom : WalkingSpan → WalkingSpan → Type := WidePushoutShape.Hom /-- The left arrow of the walking span. -/ @[match_pattern] abbrev Hom.fst : zero ⟶ left := WidePushoutShape.Hom.init _ /-- The right arrow of the walking span. -/ @[match_pattern] abbrev Hom.snd : zero ⟶ right := WidePushoutShape.Hom.init _ /-- The identity arrows of the walking span. -/ @[match_pattern] abbrev Hom.id (X : WalkingSpan) : X ⟶ X := WidePushoutShape.Hom.id X instance (X Y : WalkingSpan) : Subsingleton (X ⟶ Y) := by constructor; intros a b; simp [eq_iff_true_of_subsingleton] end WalkingSpan open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] /-- To construct an isomorphism of cones over the walking cospan, it suffices to construct an isomorphism of the cone points and check it commutes with the legs to `left` and `right`. -/ def WalkingCospan.ext {F : WalkingCospan ⥤ C} {s t : Cone F} (i : s.pt ≅ t.pt) (w₁ : s.π.app WalkingCospan.left = i.hom ≫ t.π.app WalkingCospan.left) (w₂ : s.π.app WalkingCospan.right = i.hom ≫ t.π.app WalkingCospan.right) : s ≅ t := by apply Cones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.π.naturality WalkingCospan.Hom.inl dsimp at h₁ simp only [Category.id_comp] at h₁ have h₂ := t.π.naturality WalkingCospan.Hom.inl dsimp at h₂ simp only [Category.id_comp] at h₂ simp_rw [h₂, ← Category.assoc, ← w₁, ← h₁] · exact w₁ · exact w₂ /-- To construct an isomorphism of cocones over the walking span, it suffices to construct an isomorphism of the cocone points and check it commutes with the legs from `left` and `right`. -/ def WalkingSpan.ext {F : WalkingSpan ⥤ C} {s t : Cocone F} (i : s.pt ≅ t.pt) (w₁ : s.ι.app WalkingCospan.left ≫ i.hom = t.ι.app WalkingCospan.left) (w₂ : s.ι.app WalkingCospan.right ≫ i.hom = t.ι.app WalkingCospan.right) : s ≅ t := by apply Cocones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.ι.naturality WalkingSpan.Hom.fst dsimp at h₁ simp only [Category.comp_id] at h₁ have h₂ := t.ι.naturality WalkingSpan.Hom.fst dsimp at h₂ simp only [Category.comp_id] at h₂ simp_rw [← h₁, Category.assoc, w₁, h₂] · exact w₁ · exact w₂ /-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/ def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : WalkingCospan ⥤ C := WidePullbackShape.wideCospan Z (fun j => WalkingPair.casesOn j X Y) fun j => WalkingPair.casesOn j f g /-- `span f g` is the functor from the walking span hitting `f` and `g`. -/ def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : WalkingSpan ⥤ C := WidePushoutShape.wideSpan X (fun j => WalkingPair.casesOn j Y Z) fun j => WalkingPair.casesOn j f g @[simp] theorem cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.left = X := rfl @[simp] theorem span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.left = Y := rfl @[simp] theorem cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.right = Y := rfl @[simp] theorem span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.right = Z := rfl @[simp] theorem cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.one = Z := rfl @[simp] theorem span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.zero = X := rfl @[simp] theorem cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inl = f := rfl @[simp] theorem span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.fst = f := rfl @[simp] theorem cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inr = g := rfl @[simp] theorem span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.snd = g := rfl theorem cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : WalkingCospan) : (cospan f g).map (WalkingCospan.Hom.id w) = 𝟙 _ := rfl theorem span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : WalkingSpan) : (span f g).map (WalkingSpan.Hom.id w) = 𝟙 _ := rfl /-- Every diagram indexing a pullback is naturally isomorphic (actually, equal) to a `cospan` -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] def diagramIsoCospan (F : WalkingCospan ⥤ C) : F ≅ cospan (F.map inl) (F.map inr) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) /-- Every diagram indexing a pushout is naturally isomorphic (actually, equal) to a `span` -/ -- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible @[simps!] def diagramIsoSpan (F : WalkingSpan ⥤ C) : F ≅ span (F.map fst) (F.map snd) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) variable {D : Type u₂} [Category.{v₂} D] /-- A functor applied to a cospan is a cospan. -/ def cospanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : cospan f g ⋙ F ≅ cospan (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) @[simp] theorem cospanCompIso_app_left : (cospanCompIso F f g).app WalkingCospan.left = Iso.refl _ := rfl @[simp] theorem cospanCompIso_app_right : (cospanCompIso F f g).app WalkingCospan.right = Iso.refl _ := rfl @[simp] theorem cospanCompIso_app_one : (cospanCompIso F f g).app WalkingCospan.one = Iso.refl _ := rfl @[simp] theorem cospanCompIso_hom_app_left : (cospanCompIso F f g).hom.app WalkingCospan.left = 𝟙 _ := rfl @[simp] theorem cospanCompIso_hom_app_right : (cospanCompIso F f g).hom.app WalkingCospan.right = 𝟙 _ := rfl @[simp] theorem cospanCompIso_hom_app_one : (cospanCompIso F f g).hom.app WalkingCospan.one = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_left : (cospanCompIso F f g).inv.app WalkingCospan.left = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_right : (cospanCompIso F f g).inv.app WalkingCospan.right = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_one : (cospanCompIso F f g).inv.app WalkingCospan.one = 𝟙 _ := rfl end /-- A functor applied to a span is a span. -/ def spanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : span f g ⋙ F ≅ span (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp) section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) @[simp] theorem spanCompIso_app_left : (spanCompIso F f g).app WalkingSpan.left = Iso.refl _ := rfl @[simp] theorem spanCompIso_app_right : (spanCompIso F f g).app WalkingSpan.right = Iso.refl _ := rfl @[simp] theorem spanCompIso_app_zero : (spanCompIso F f g).app WalkingSpan.zero = Iso.refl _ := rfl @[simp] theorem spanCompIso_hom_app_left : (spanCompIso F f g).hom.app WalkingSpan.left = 𝟙 _ := rfl @[simp] theorem spanCompIso_hom_app_right : (spanCompIso F f g).hom.app WalkingSpan.right = 𝟙 _ := rfl @[simp] theorem spanCompIso_hom_app_zero : (spanCompIso F f g).hom.app WalkingSpan.zero = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_left : (spanCompIso F f g).inv.app WalkingSpan.left = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_right : (spanCompIso F f g).inv.app WalkingSpan.right = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_zero : (spanCompIso F f g).inv.app WalkingSpan.zero = 𝟙 _ := rfl end section variable {X Y Z X' Y' Z' : C} (iX : X ≅ X') (iY : Y ≅ Y') (iZ : Z ≅ Z') section variable {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} /-- Construct an isomorphism of cospans from components. -/ def cospanExt (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) : cospan f g ≅ cospan f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iZ, iX, iY]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp [wf, wg]) variable (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem cospanExt_app_left : (cospanExt iX iY iZ wf wg).app WalkingCospan.left = iX := by dsimp [cospanExt] @[simp] theorem cospanExt_app_right : (cospanExt iX iY iZ wf wg).app WalkingCospan.right = iY := by dsimp [cospanExt] @[simp] theorem cospanExt_app_one : (cospanExt iX iY iZ wf wg).app WalkingCospan.one = iZ := by dsimp [cospanExt] @[simp] theorem cospanExt_hom_app_left : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.left = iX.hom := by dsimp [cospanExt] @[simp] theorem cospanExt_hom_app_right : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.right = iY.hom := by dsimp [cospanExt] @[simp] theorem cospanExt_hom_app_one : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.one = iZ.hom := by dsimp [cospanExt] @[simp] theorem cospanExt_inv_app_left : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.left = iX.inv := by dsimp [cospanExt] @[simp] theorem cospanExt_inv_app_right : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.right = iY.inv := by dsimp [cospanExt] @[simp] theorem cospanExt_inv_app_one : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.one = iZ.inv := by dsimp [cospanExt] end section variable {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'} /-- Construct an isomorphism of spans from components. -/ def spanExt (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) : span f g ≅ span f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iX, iY, iZ]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp [wf, wg]) variable (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem spanExt_app_left : (spanExt iX iY iZ wf wg).app WalkingSpan.left = iY := by dsimp [spanExt] @[simp] theorem spanExt_app_right : (spanExt iX iY iZ wf wg).app WalkingSpan.right = iZ := by dsimp [spanExt] @[simp] theorem spanExt_app_one : (spanExt iX iY iZ wf wg).app WalkingSpan.zero = iX := by dsimp [spanExt] @[simp] theorem spanExt_hom_app_left : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.left = iY.hom := by dsimp [spanExt] @[simp] theorem spanExt_hom_app_right : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.right = iZ.hom := by dsimp [spanExt] @[simp] theorem spanExt_hom_app_zero : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.zero = iX.hom := by dsimp [spanExt] @[simp] theorem spanExt_inv_app_left : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.left = iY.inv := by dsimp [spanExt] @[simp] theorem spanExt_inv_app_right : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.right = iZ.inv := by dsimp [spanExt] @[simp] theorem spanExt_inv_app_zero : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.zero = iX.inv := by dsimp [spanExt] end end end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Pullback\HasPullback.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel, Bhavik Mehta, Andrew Yang, Emily Riehl, Calle Sönne -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.PullbackCone /-! # HasPullback `HasPullback f g` and `pullback f g` provides API for `HasLimit` and `limit` in the case of pullacks. # Main definitions * `HasPullback f g`: this is an abbreviation for `HasLimit (cospan f g)`, and is a typeclass used to express the fact that a given pair of morphisms has a pullback. * `HasPullbacks`: expresses the fact that `C` admits all pullbacks, it is implemented as an abbrevation for `HasLimitsOfShape WalkingCospan C` * `pullback f g`: Given a `HasPullback f g` instance, this function returns the choice of a limit object corresponding to the pullback of `f` and `g`. It fits into the following diagram: ``` pullback f g ---pullback.snd f g---> Y | | | | pullback.snd f g g | | v v X --------------f--------------> Z ``` * `HasPushout f g`: this is an abbreviation for `HasColimit (span f g)`, and is a typeclass used to express the fact that a given pair of morphisms has a pushout. * `HasPushouts`: expresses the fact that `C` admits all pushouts, it is implemented as an abbrevation for `HasColimitsOfShape WalkingSpan C` * `pushout f g`: Given a `HasPushout f g` instance, this function returns the choice of a colimit object corresponding to the pushout of `f` and `g`. It fits into the following diagram: ``` X --------------f--------------> Y | | g pushout.inr f g | | v v Z ---pushout.inl f g---> pushout f g ``` # Main results & API * The following API is available for using the universal property of `pullback f g`: `lift`, `lift_fst`, `lift_snd`, `lift'`, `hom_ext` (for uniqueness). * `pullback.map` is the induced map between pullbacks `W ×ₛ X ⟶ Y ×ₜ Z` given pointwise (compatible) maps `W ⟶ Y`, `X ⟶ Z` and `S ⟶ T`. * `pullbackComparison`: Given a functor `G`, this is the natural morphism `G.obj (pullback f g) ⟶ pullback (G.map f) (G.map g)` * `pullbackSymmetry` provides the natural isomorphism `pullback f g ≅ pullback g f` (The dual results for pushouts are also available) ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] {W X Y Z : C} /-- `HasPullback f g` represents a particular choice of limiting cone for the pair of morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`. -/ abbrev HasPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) := HasLimit (cospan f g) /-- `HasPushout f g` represents a particular choice of colimiting cocone for the pair of morphisms `f : X ⟶ Y` and `g : X ⟶ Z`. -/ abbrev HasPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) := HasColimit (span f g) /-- `pullback f g` computes the pullback of a pair of morphisms with the same target. -/ abbrev pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] := limit (cospan f g) /-- The cone associated to the pullback of `f` and `g`-/ abbrev pullback.cone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : PullbackCone f g := limit.cone (cospan f g) /-- `pushout f g` computes the pushout of a pair of morphisms with the same source. -/ abbrev pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] := colimit (span f g) /-- The cocone associated to the pullback of `f` and `g` -/ abbrev pushout.cocone {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : PushoutCocone f g := colimit.cocone (span f g) /-- The first projection of the pullback of `f` and `g`. -/ abbrev pullback.fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : pullback f g ⟶ X := limit.π (cospan f g) WalkingCospan.left /-- The second projection of the pullback of `f` and `g`. -/ abbrev pullback.snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : pullback f g ⟶ Y := limit.π (cospan f g) WalkingCospan.right /-- The first inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inl {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : Y ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.left /-- The second inclusion into the pushout of `f` and `g`. -/ abbrev pushout.inr {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : Z ⟶ pushout f g := colimit.ι (span f g) WalkingSpan.right /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `pullback.lift : W ⟶ pullback f g`. -/ abbrev pullback.lift {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ pullback f g := limit.lift _ (PullbackCone.mk h k w) /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `pushout.desc : pushout f g ⟶ W`. -/ abbrev pushout.desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout f g ⟶ W := colimit.desc _ (PushoutCocone.mk h k w) /-- The cone associated to a pullback is a limit cone. -/ abbrev pullback.isLimit {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsLimit (pullback.cone f g) := limit.isLimit (cospan f g) /-- The cocone associated to a pushout is a colimit cone. -/ abbrev pushout.isColimit {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : IsColimit (pushout.cocone f g) := colimit.isColimit (span f g) @[simp] theorem PullbackCone.fst_limit_cone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.fst (limit.cone (cospan f g)) = pullback.fst f g := rfl @[simp] theorem PullbackCone.snd_limit_cone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasLimit (cospan f g)] : PullbackCone.snd (limit.cone (cospan f g)) = pullback.snd f g := rfl -- Porting note (#10618): simp can prove this; removed simp theorem PushoutCocone.inl_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inl (colimit.cocone (span f g)) = pushout.inl _ _ := rfl -- Porting note (#10618): simp can prove this; removed simp theorem PushoutCocone.inr_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y) [HasColimit (span f g)] : PushoutCocone.inr (colimit.cocone (span f g)) = pushout.inr _ _ := rfl -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pullback.lift_fst {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.fst f g = h := limit.lift_π _ _ -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pullback.lift_snd {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.snd f g = k := limit.lift_π _ _ -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pushout.inl_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inl _ _ ≫ pushout.desc h k w = h := colimit.ι_desc _ _ -- Porting note (#10618): simp can prove this and reassoced version; removed simp @[reassoc] theorem pushout.inr_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inr _ _ ≫ pushout.desc h k w = k := colimit.ι_desc _ _ /-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism `l : W ⟶ pullback f g` such that `l ≫ pullback.fst = h` and `l ≫ pullback.snd = k`. -/ def pullback.lift' {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ pullback f g // l ≫ pullback.fst f g = h ∧ l ≫ pullback.snd f g = k } := ⟨pullback.lift h k w, pullback.lift_fst _ _ _, pullback.lift_snd _ _ _⟩ /-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism `l : pushout f g ⟶ W` such that `pushout.inl _ _ ≫ l = h` and `pushout.inr _ _ ≫ l = k`. -/ def pullback.desc' {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : pushout f g ⟶ W // pushout.inl _ _ ≫ l = h ∧ pushout.inr _ _ ≫ l = k } := ⟨pushout.desc h k w, pushout.inl_desc _ _ _, pushout.inr_desc _ _ _⟩ @[reassoc] theorem pullback.condition {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback.fst f g ≫ f = pullback.snd f g ≫ g := PullbackCone.condition _ @[reassoc] theorem pushout.condition {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : f ≫ (pushout.inl f g) = g ≫ pushout.inr _ _ := PushoutCocone.condition _ /-- Two morphisms into a pullback are equal if their compositions with the pullback morphisms are equal -/ @[ext 1100] theorem pullback.hom_ext {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] {W : C} {k l : W ⟶ pullback f g} (h₀ : k ≫ pullback.fst f g = l ≫ pullback.fst f g) (h₁ : k ≫ pullback.snd f g = l ≫ pullback.snd f g) : k = l := limit.hom_ext <| PullbackCone.equalizer_ext _ h₀ h₁ /-- The pullback cone built from the pullback projections is a pullback. -/ def pullbackIsPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsLimit (PullbackCone.mk (pullback.fst f g) (pullback.snd f g) pullback.condition) := PullbackCone.mkSelfIsLimit <| pullback.isLimit f g /-- Two morphisms out of a pushout are equal if their compositions with the pushout morphisms are equal -/ @[ext 1100] theorem pushout.hom_ext {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] {W : C} {k l : pushout f g ⟶ W} (h₀ : pushout.inl _ _ ≫ k = pushout.inl _ _ ≫ l) (h₁ : pushout.inr _ _ ≫ k = pushout.inr _ _ ≫ l) : k = l := colimit.hom_ext <| PushoutCocone.coequalizer_ext _ h₀ h₁ /-- The pushout cocone built from the pushout coprojections is a pushout. -/ def pushoutIsPushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] : IsColimit (PushoutCocone.mk (pushout.inl f g) (pushout.inr _ _) pushout.condition) := PushoutCocone.IsColimit.mk _ (fun s => pushout.desc s.inl s.inr s.condition) (by simp) (by simp) (by aesop_cat) /-- Given such a diagram, then there is a natural morphism `W ×ₛ X ⟶ Y ×ₜ Z`. ``` W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z ``` -/ abbrev pullback.map {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : pullback f₁ f₂ ⟶ pullback g₁ g₂ := pullback.lift (pullback.fst f₁ f₂ ≫ i₁) (pullback.snd f₁ f₂ ≫ i₂) (by simp only [Category.assoc, ← eq₁, ← eq₂, pullback.condition_assoc]) /-- The canonical map `X ×ₛ Y ⟶ X ×ₜ Y` given `S ⟶ T`. -/ abbrev pullback.mapDesc {X Y S T : C} (f : X ⟶ S) (g : Y ⟶ S) (i : S ⟶ T) [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] : pullback f g ⟶ pullback (f ≫ i) (g ≫ i) := pullback.map f g (f ≫ i) (g ≫ i) (𝟙 _) (𝟙 _) i (Category.id_comp _).symm (Category.id_comp _).symm @[reassoc] lemma pullback.map_comp {X Y Z X' Y' Z' X'' Y'' Z'' : C} {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} {f'' : X'' ⟶ Z''} {g'' : Y'' ⟶ Z''} (i₁ : X ⟶ X') (j₁ : X' ⟶ X'') (i₂ : Y ⟶ Y') (j₂ : Y' ⟶ Y'') (i₃ : Z ⟶ Z') (j₃ : Z' ⟶ Z'') [HasPullback f g] [HasPullback f' g'] [HasPullback f'' g''] (e₁ e₂ e₃ e₄) : pullback.map f g f' g' i₁ i₂ i₃ e₁ e₂ ≫ pullback.map f' g' f'' g'' j₁ j₂ j₃ e₃ e₄ = pullback.map f g f'' g'' (i₁ ≫ j₁) (i₂ ≫ j₂) (i₃ ≫ j₃) (by rw [reassoc_of% e₁, e₃, Category.assoc]) (by rw [reassoc_of% e₂, e₄, Category.assoc]) := by ext <;> simp @[simp] lemma pullback.map_id {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] : pullback.map f g f g (𝟙 _) (𝟙 _) (𝟙 _) (by simp) (by simp) = 𝟙 _ := by ext <;> simp /-- Given such a diagram, then there is a natural morphism `W ⨿ₛ X ⟶ Y ⨿ₜ Z`. ``` W ⟶ Y ↗ ↗ S ⟶ T ↘ ↘ X ⟶ Z ``` -/ abbrev pushout.map {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) : pushout f₁ f₂ ⟶ pushout g₁ g₂ := pushout.desc (i₁ ≫ pushout.inl _ _) (i₂ ≫ pushout.inr _ _) (by simp only [reassoc_of% eq₁, reassoc_of% eq₂, condition]) /-- The canonical map `X ⨿ₛ Y ⟶ X ⨿ₜ Y` given `S ⟶ T`. -/ abbrev pushout.mapLift {X Y S T : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] : pushout (i ≫ f) (i ≫ g) ⟶ pushout f g := pushout.map (i ≫ f) (i ≫ g) f g (𝟙 _) (𝟙 _) i (Category.comp_id _) (Category.comp_id _) @[reassoc] lemma pushout.map_comp {X Y Z X' Y' Z' X'' Y'' Z'' : C} {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'} {f'' : X'' ⟶ Y''} {g'' : X'' ⟶ Z''} (i₁ : X ⟶ X') (j₁ : X' ⟶ X'') (i₂ : Y ⟶ Y') (j₂ : Y' ⟶ Y'') (i₃ : Z ⟶ Z') (j₃ : Z' ⟶ Z'') [HasPushout f g] [HasPushout f' g'] [HasPushout f'' g''] (e₁ e₂ e₃ e₄) : pushout.map f g f' g' i₂ i₃ i₁ e₁ e₂ ≫ pushout.map f' g' f'' g'' j₂ j₃ j₁ e₃ e₄ = pushout.map f g f'' g'' (i₂ ≫ j₂) (i₃ ≫ j₃) (i₁ ≫ j₁) (by rw [reassoc_of% e₁, e₃, Category.assoc]) (by rw [reassoc_of% e₂, e₄, Category.assoc]) := by ext <;> simp @[simp] lemma pushout.map_id {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] : pushout.map f g f g (𝟙 _) (𝟙 _) (𝟙 _) (by simp) (by simp) = 𝟙 _ := by ext <;> simp instance pullback.map_isIso {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [HasPullback f₁ f₂] (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [HasPullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pullback.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · aesop_cat · aesop_cat /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pullback f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pullback.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : pullback f₁ g₁ ≅ pullback f₂ g₂ := asIso <| pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) @[simp] theorem pullback.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPullback f₁ g₁] [HasPullback f₂ g₂] : (pullback.congrHom h₁ h₂).inv = pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext <;> simp [Iso.inv_comp_eq] instance pushout.map_isIso {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [HasPushout f₁ f₂] (g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [HasPushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) [IsIso i₁] [IsIso i₂] [IsIso i₃] : IsIso (pushout.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine ⟨⟨pushout.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) ?_ ?_, ?_, ?_⟩⟩ · rw [IsIso.comp_inv_eq, Category.assoc, eq₁, IsIso.inv_hom_id_assoc] · rw [IsIso.comp_inv_eq, Category.assoc, eq₂, IsIso.inv_hom_id_assoc] · aesop_cat · aesop_cat theorem pullback.mapDesc_comp {X Y S T S' : C} (f : X ⟶ T) (g : Y ⟶ T) (i : T ⟶ S) (i' : S ⟶ S') [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)] [HasPullback (f ≫ i ≫ i') (g ≫ i ≫ i')] [HasPullback ((f ≫ i) ≫ i') ((g ≫ i) ≫ i')] : pullback.mapDesc f g (i ≫ i') = pullback.mapDesc f g i ≫ pullback.mapDesc _ _ i' ≫ (pullback.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom := by aesop_cat /-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical isomorphism `pushout f₁ g₁ ≅ pullback f₂ g₂` -/ @[simps! hom] def pushout.congrHom {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : pushout f₁ g₁ ≅ pushout f₂ g₂ := asIso <| pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) @[simp] theorem pushout.congrHom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z} (h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [HasPushout f₁ g₁] [HasPushout f₂ g₂] : (pushout.congrHom h₁ h₂).inv = pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) := by ext <;> simp [Iso.comp_inv_eq] theorem pushout.mapLift_comp {X Y S T S' : C} (f : T ⟶ X) (g : T ⟶ Y) (i : S ⟶ T) (i' : S' ⟶ S) [HasPushout f g] [HasPushout (i ≫ f) (i ≫ g)] [HasPushout (i' ≫ i ≫ f) (i' ≫ i ≫ g)] [HasPushout ((i' ≫ i) ≫ f) ((i' ≫ i) ≫ g)] : pushout.mapLift f g (i' ≫ i) = (pushout.congrHom (Category.assoc _ _ _) (Category.assoc _ _ _)).hom ≫ pushout.mapLift _ _ i' ≫ pushout.mapLift f g i := by aesop_cat section variable {D : Type u₂} [Category.{v₂} D] (G : C ⥤ D) /-- The comparison morphism for the pullback of `f,g`. This is an isomorphism iff `G` preserves the pullback of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : G.obj (pullback f g) ⟶ pullback (G.map f) (G.map g) := pullback.lift (G.map (pullback.fst f g)) (G.map (pullback.snd f g)) (by simp only [← G.map_comp, pullback.condition]) @[reassoc (attr := simp)] theorem pullbackComparison_comp_fst (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.fst _ _ = G.map (pullback.fst f g) := pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem pullbackComparison_comp_snd (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] : pullbackComparison G f g ≫ pullback.snd _ _ = G.map (pullback.snd f g):= pullback.lift_snd _ _ _ @[reassoc (attr := simp)] theorem map_lift_pullbackComparison (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasPullback (G.map f) (G.map g)] {W : C} {h : W ⟶ X} {k : W ⟶ Y} (w : h ≫ f = k ≫ g) : G.map (pullback.lift _ _ w) ≫ pullbackComparison G f g = pullback.lift (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] /-- The comparison morphism for the pushout of `f,g`. This is an isomorphism iff `G` preserves the pushout of `f,g`; see `Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean` -/ def pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout (G.map f) (G.map g) ⟶ G.obj (pushout f g) := pushout.desc (G.map (pushout.inl _ _)) (G.map (pushout.inr _ _)) (by simp only [← G.map_comp, pushout.condition]) @[reassoc (attr := simp)] theorem inl_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inl _ _ ≫ pushoutComparison G f g = G.map (pushout.inl _ _) := pushout.inl_desc _ _ _ @[reassoc (attr := simp)] theorem inr_comp_pushoutComparison (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] : pushout.inr _ _ ≫ pushoutComparison G f g = G.map (pushout.inr _ _) := pushout.inr_desc _ _ _ @[reassoc (attr := simp)] theorem pushoutComparison_map_desc (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasPushout (G.map f) (G.map g)] {W : C} {h : Y ⟶ W} {k : Z ⟶ W} (w : f ≫ h = g ≫ k) : pushoutComparison G f g ≫ G.map (pushout.desc _ _ w) = pushout.desc (G.map h) (G.map k) (by simp only [← G.map_comp, w]) := by ext <;> simp [← G.map_comp] end section PullbackSymmetry open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPullback_symmetry [HasPullback f g] : HasPullback g f := ⟨⟨⟨_, PullbackCone.flipIsLimit (pullbackIsPullback f g)⟩⟩⟩ attribute [local instance] hasPullback_symmetry /-- The isomorphism `X ×[Z] Y ≅ Y ×[Z] X`. -/ def pullbackSymmetry [HasPullback f g] : pullback f g ≅ pullback g f := IsLimit.conePointUniqueUpToIso (PullbackCone.flipIsLimit (pullbackIsPullback f g)) (limit.isLimit _) @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_fst [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.fst g f = pullback.snd f g := by simp [pullbackSymmetry] @[reassoc (attr := simp)] theorem pullbackSymmetry_hom_comp_snd [HasPullback f g] : (pullbackSymmetry f g).hom ≫ pullback.snd g f = pullback.fst f g := by simp [pullbackSymmetry] @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_fst [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.fst f g = pullback.snd g f := by simp [Iso.inv_comp_eq] @[reassoc (attr := simp)] theorem pullbackSymmetry_inv_comp_snd [HasPullback f g] : (pullbackSymmetry f g).inv ≫ pullback.snd f g = pullback.fst g f := by simp [Iso.inv_comp_eq] end PullbackSymmetry section PushoutSymmetry open WalkingCospan variable (f : X ⟶ Y) (g : X ⟶ Z) /-- Making this a global instance would make the typeclass search go in an infinite loop. -/ theorem hasPushout_symmetry [HasPushout f g] : HasPushout g f := ⟨⟨⟨_, PushoutCocone.flipIsColimit (pushoutIsPushout f g)⟩⟩⟩ attribute [local instance] hasPushout_symmetry /-- The isomorphism `Y ⨿[X] Z ≅ Z ⨿[X] Y`. -/ def pushoutSymmetry [HasPushout f g] : pushout f g ≅ pushout g f := IsColimit.coconePointUniqueUpToIso (PushoutCocone.flipIsColimit (pushoutIsPushout f g)) (colimit.isColimit _) @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inl _ _ ≫ (pushoutSymmetry f g).hom = pushout.inr _ _ := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ @[reassoc (attr := simp)] theorem inr_comp_pushoutSymmetry_hom [HasPushout f g] : pushout.inr _ _ ≫ (pushoutSymmetry f g).hom = pushout.inl _ _ := (colimit.isColimit (span f g)).comp_coconePointUniqueUpToIso_hom (PushoutCocone.flipIsColimit (pushoutIsPushout g f)) _ @[reassoc (attr := simp)] theorem inl_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inl _ _ ≫ (pushoutSymmetry f g).inv = pushout.inr _ _ := by simp [Iso.comp_inv_eq] @[reassoc (attr := simp)] theorem inr_comp_pushoutSymmetry_inv [HasPushout f g] : pushout.inr _ _ ≫ (pushoutSymmetry f g).inv = pushout.inl _ _ := by simp [Iso.comp_inv_eq] end PushoutSymmetry variable (C) /-- `HasPullbacks` represents a choice of pullback for every pair of morphisms See <https://stacks.math.columbia.edu/tag/001W> -/ abbrev HasPullbacks := HasLimitsOfShape WalkingCospan C /-- `HasPushouts` represents a choice of pushout for every pair of morphisms -/ abbrev HasPushouts := HasColimitsOfShape WalkingSpan C /-- If `C` has all limits of diagrams `cospan f g`, then it has all pullbacks -/ theorem hasPullbacks_of_hasLimit_cospan [∀ {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z}, HasLimit (cospan f g)] : HasPullbacks C := { has_limit := fun F => hasLimitOfIso (diagramIsoCospan F).symm } /-- If `C` has all colimits of diagrams `span f g`, then it has all pushouts -/ theorem hasPushouts_of_hasColimit_span [∀ {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z}, HasColimit (span f g)] : HasPushouts C := { has_colimit := fun F => hasColimitOfIso (diagramIsoSpan F) } /-- The duality equivalence `WalkingSpanᵒᵖ ≌ WalkingCospan` -/ @[simps!] def walkingSpanOpEquiv : WalkingSpanᵒᵖ ≌ WalkingCospan := widePushoutShapeOpEquiv _ /-- The duality equivalence `WalkingCospanᵒᵖ ≌ WalkingSpan` -/ @[simps!] def walkingCospanOpEquiv : WalkingCospanᵒᵖ ≌ WalkingSpan := widePullbackShapeOpEquiv _ -- see Note [lower instance priority] /-- Having wide pullback at any universe level implies having binary pullbacks. -/ instance (priority := 100) hasPullbacks_of_hasWidePullbacks (D : Type u) [Category.{v} D] [HasWidePullbacks.{w} D] : HasPullbacks.{v,u} D := hasWidePullbacks_shrink WalkingPair -- see Note [lower instance priority] /-- Having wide pushout at any universe level implies having binary pushouts. -/ instance (priority := 100) hasPushouts_of_hasWidePushouts (D : Type u) [Category.{v} D] [HasWidePushouts.{w} D] : HasPushouts.{v,u} D := hasWidePushouts_shrink WalkingPair end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Pullback\Iso.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # The pullback of an isomorphism This file provides some basic results about the pullback (and pushout) of an isomorphism. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {X Y Z : C} section PullbackLeftIso open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso f] /-- If `f : X ⟶ Z` is iso, then `X ×[Z] Y ≅ Y`. This is the explicit limit cone. -/ def pullbackConeOfLeftIso : PullbackCone f g := PullbackCone.mk (g ≫ inv f) (𝟙 _) <| by simp @[simp] theorem pullbackConeOfLeftIso_x : (pullbackConeOfLeftIso f g).pt = Y := rfl @[simp] theorem pullbackConeOfLeftIso_fst : (pullbackConeOfLeftIso f g).fst = g ≫ inv f := rfl @[simp] theorem pullbackConeOfLeftIso_snd : (pullbackConeOfLeftIso f g).snd = 𝟙 _ := rfl -- Porting note (#10618): simp can prove this; removed simp theorem pullbackConeOfLeftIso_π_app_none : (pullbackConeOfLeftIso f g).π.app none = g := by simp @[simp] theorem pullbackConeOfLeftIso_π_app_left : (pullbackConeOfLeftIso f g).π.app left = g ≫ inv f := rfl @[simp] theorem pullbackConeOfLeftIso_π_app_right : (pullbackConeOfLeftIso f g).π.app right = 𝟙 _ := rfl /-- Verify that the constructed limit cone is indeed a limit. -/ def pullbackConeOfLeftIsoIsLimit : IsLimit (pullbackConeOfLeftIso f g) := PullbackCone.isLimitAux' _ fun s => ⟨s.snd, by simp [← s.condition_assoc]⟩ theorem hasPullback_of_left_iso : HasPullback f g := ⟨⟨⟨_, pullbackConeOfLeftIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPullback_of_left_iso instance pullback_snd_iso_of_left_iso : IsIso (pullback.snd f g) := by refine ⟨⟨pullback.lift (g ≫ inv f) (𝟙 _) (by simp), ?_, by simp⟩⟩ ext · simp [← pullback.condition_assoc] · simp [pullback.condition_assoc] @[reassoc (attr := simp)] lemma pullback_inv_snd_fst_of_left_isIso : inv (pullback.snd f g) ≫ pullback.fst f g = g ≫ inv f := by rw [IsIso.inv_comp_eq, ← pullback.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PullbackLeftIso section PullbackRightIso open WalkingCospan variable (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso g] /-- If `g : Y ⟶ Z` is iso, then `X ×[Z] Y ≅ X`. This is the explicit limit cone. -/ def pullbackConeOfRightIso : PullbackCone f g := PullbackCone.mk (𝟙 _) (f ≫ inv g) <| by simp @[simp] theorem pullbackConeOfRightIso_x : (pullbackConeOfRightIso f g).pt = X := rfl @[simp] theorem pullbackConeOfRightIso_fst : (pullbackConeOfRightIso f g).fst = 𝟙 _ := rfl @[simp] theorem pullbackConeOfRightIso_snd : (pullbackConeOfRightIso f g).snd = f ≫ inv g := rfl -- Porting note (#10618): simp can prove this; removed simps theorem pullbackConeOfRightIso_π_app_none : (pullbackConeOfRightIso f g).π.app none = f := by simp @[simp] theorem pullbackConeOfRightIso_π_app_left : (pullbackConeOfRightIso f g).π.app left = 𝟙 _ := rfl @[simp] theorem pullbackConeOfRightIso_π_app_right : (pullbackConeOfRightIso f g).π.app right = f ≫ inv g := rfl /-- Verify that the constructed limit cone is indeed a limit. -/ def pullbackConeOfRightIsoIsLimit : IsLimit (pullbackConeOfRightIso f g) := PullbackCone.isLimitAux' _ fun s => ⟨s.fst, by simp [s.condition_assoc]⟩ theorem hasPullback_of_right_iso : HasPullback f g := ⟨⟨⟨_, pullbackConeOfRightIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPullback_of_right_iso instance pullback_snd_iso_of_right_iso : IsIso (pullback.fst f g) := by refine ⟨⟨pullback.lift (𝟙 _) (f ≫ inv g) (by simp), ?_, by simp⟩⟩ ext · simp · simp [pullback.condition_assoc] @[reassoc (attr := simp)] lemma pullback_inv_fst_snd_of_right_isIso : inv (pullback.fst f g) ≫ pullback.snd f g = f ≫ inv g := by rw [IsIso.inv_comp_eq, pullback.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PullbackRightIso section PushoutLeftIso open WalkingSpan variable (f : X ⟶ Y) (g : X ⟶ Z) [IsIso f] /-- If `f : X ⟶ Y` is iso, then `Y ⨿[X] Z ≅ Z`. This is the explicit colimit cocone. -/ def pushoutCoconeOfLeftIso : PushoutCocone f g := PushoutCocone.mk (inv f ≫ g) (𝟙 _) <| by simp @[simp] theorem pushoutCoconeOfLeftIso_x : (pushoutCoconeOfLeftIso f g).pt = Z := rfl @[simp] theorem pushoutCoconeOfLeftIso_inl : (pushoutCoconeOfLeftIso f g).inl = inv f ≫ g := rfl @[simp] theorem pushoutCoconeOfLeftIso_inr : (pushoutCoconeOfLeftIso f g).inr = 𝟙 _ := rfl -- Porting note (#10618): simp can prove this; removed simp theorem pushoutCoconeOfLeftIso_ι_app_none : (pushoutCoconeOfLeftIso f g).ι.app none = g := by simp @[simp] theorem pushoutCoconeOfLeftIso_ι_app_left : (pushoutCoconeOfLeftIso f g).ι.app left = inv f ≫ g := rfl @[simp] theorem pushoutCoconeOfLeftIso_ι_app_right : (pushoutCoconeOfLeftIso f g).ι.app right = 𝟙 _ := rfl /-- Verify that the constructed cocone is indeed a colimit. -/ def pushoutCoconeOfLeftIsoIsLimit : IsColimit (pushoutCoconeOfLeftIso f g) := PushoutCocone.isColimitAux' _ fun s => ⟨s.inr, by simp [← s.condition]⟩ theorem hasPushout_of_left_iso : HasPushout f g := ⟨⟨⟨_, pushoutCoconeOfLeftIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPushout_of_left_iso instance pushout_inr_iso_of_left_iso : IsIso (pushout.inr f g) := by refine ⟨⟨pushout.desc (inv f ≫ g) (𝟙 _) (by simp), by simp, ?_⟩⟩ ext · simp [← pushout.condition] · simp [pushout.condition_assoc] @[reassoc (attr := simp)] lemma pushout_inl_inv_inr_of_right_isIso : pushout.inl f g ≫ inv (pushout.inr f g) = inv f ≫ g := by rw [IsIso.eq_inv_comp, pushout.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PushoutLeftIso section PushoutRightIso open WalkingSpan variable (f : X ⟶ Y) (g : X ⟶ Z) [IsIso g] /-- If `f : X ⟶ Z` is iso, then `Y ⨿[X] Z ≅ Y`. This is the explicit colimit cocone. -/ def pushoutCoconeOfRightIso : PushoutCocone f g := PushoutCocone.mk (𝟙 _) (inv g ≫ f) <| by simp @[simp] theorem pushoutCoconeOfRightIso_x : (pushoutCoconeOfRightIso f g).pt = Y := rfl @[simp] theorem pushoutCoconeOfRightIso_inl : (pushoutCoconeOfRightIso f g).inl = 𝟙 _ := rfl @[simp] theorem pushoutCoconeOfRightIso_inr : (pushoutCoconeOfRightIso f g).inr = inv g ≫ f := rfl -- Porting note (#10618): simp can prove this; removed simp theorem pushoutCoconeOfRightIso_ι_app_none : (pushoutCoconeOfRightIso f g).ι.app none = f := by simp @[simp] theorem pushoutCoconeOfRightIso_ι_app_left : (pushoutCoconeOfRightIso f g).ι.app left = 𝟙 _ := rfl @[simp] theorem pushoutCoconeOfRightIso_ι_app_right : (pushoutCoconeOfRightIso f g).ι.app right = inv g ≫ f := rfl /-- Verify that the constructed cocone is indeed a colimit. -/ def pushoutCoconeOfRightIsoIsLimit : IsColimit (pushoutCoconeOfRightIso f g) := PushoutCocone.isColimitAux' _ fun s => ⟨s.inl, by simp [← s.condition]⟩ theorem hasPushout_of_right_iso : HasPushout f g := ⟨⟨⟨_, pushoutCoconeOfRightIsoIsLimit f g⟩⟩⟩ attribute [local instance] hasPushout_of_right_iso instance pushout_inl_iso_of_right_iso : IsIso (pushout.inl _ _ : _ ⟶ pushout f g) := by refine ⟨⟨pushout.desc (𝟙 _) (inv g ≫ f) (by simp), by simp, ?_⟩⟩ ext · simp [← pushout.condition] · simp [pushout.condition] @[reassoc (attr := simp)] lemma pushout_inr_inv_inl_of_right_isIso : pushout.inr f g ≫ inv (pushout.inl f g) = inv g ≫ f := by rw [IsIso.eq_inv_comp, ← pushout.condition_assoc, IsIso.hom_inv_id, Category.comp_id] end PushoutRightIso end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Pullback\Mono.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Iso /-! # Pullbacks and monomorphisms This file provides some results about interactions between pullbacks and monomorphisms, as well as the dual statements between pushouts and epimorphisms. ## Main results * Monomorphisms are stable under pullback. This is available using the `PullbackCone` API as `mono_fst_of_is_pullback_of_mono` and `mono_snd_of_is_pullback_of_mono`, and using the `pullback` API as `pullback.fst_of_mono` and `pullback.snd_of_mono`. * A pullback cone is a limit iff its composition with a monomorphism is a limit. This is available as `IsLimitOfCompMono` and `pullbackIsPullbackOfCompMono` respectively. * Monomorphisms admit kernel pairs, this is `has_kernel_pair_of_mono`. The dual notions for pushouts are also available. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom PullbackCone variable {C : Type u} [Category.{v} C] {W X Y Z : C} section Monomorphisms namespace PullbackCone variable {f : X ⟶ Z} {g : Y ⟶ Z} /-- Monomorphisms are stable under pullback in the first argument. -/ theorem mono_snd_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono f] : Mono t.snd := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht ?_ i⟩ rw [← cancel_mono f, Category.assoc, Category.assoc, condition] apply reassoc_of% i /-- Monomorphisms are stable under pullback in the second argument. -/ theorem mono_fst_of_is_pullback_of_mono {t : PullbackCone f g} (ht : IsLimit t) [Mono g] : Mono t.fst := by refine ⟨fun {W} h k i => IsLimit.hom_ext ht i ?_⟩ rw [← cancel_mono g, Category.assoc, Category.assoc, ← condition] apply reassoc_of% i /-- The pullback cone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a limit if `f` is a mono. The converse is shown in `mono_of_pullback_is_id`. -/ def isLimitMkIdId (f : X ⟶ Y) [Mono f] : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f) := IsLimit.mk _ (fun s => s.fst) (fun s => Category.comp_id _) (fun s => by rw [← cancel_mono f, Category.comp_id, s.condition]) fun s m m₁ _ => by simpa using m₁ /-- `f` is a mono if the pullback cone `(𝟙 X, 𝟙 X)` is a limit for the pair `(f, f)`. The converse is given in `PullbackCone.is_id_of_mono`. -/ theorem mono_of_isLimitMkIdId (f : X ⟶ Y) (t : IsLimit (mk (𝟙 X) (𝟙 X) rfl : PullbackCone f f)) : Mono f := ⟨fun {Z} g h eq => by rcases PullbackCone.IsLimit.lift' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ /-- Suppose `f` and `g` are two morphisms with a common codomain and `s` is a limit cone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through a monomorphism `h` via `x` and `y`, respectively. Then `s` is also a limit cone over the diagram formed by `x` and `y`. -/ def isLimitOfFactors (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ Z) [Mono h] (x : X ⟶ W) (y : Y ⟶ W) (hxh : x ≫ h = f) (hyh : y ≫ h = g) (s : PullbackCone f g) (hs : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ x = s.snd ≫ y from (cancel_mono h).1 <| by simp only [Category.assoc, hxh, hyh, s.condition])) := PullbackCone.isLimitAux' _ fun t => have : fst t ≫ x ≫ h = snd t ≫ y ≫ h := by -- Porting note: reassoc workaround rw [← Category.assoc, ← Category.assoc] apply congrArg (· ≫ h) t.condition ⟨hs.lift (PullbackCone.mk t.fst t.snd <| by rw [← hxh, ← hyh, this]), ⟨hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right, fun hr hr' => by apply PullbackCone.IsLimit.hom_ext hs <;> simp only [PullbackCone.mk_fst, PullbackCone.mk_snd] at hr hr' ⊢ <;> simp only [hr, hr'] <;> symm exacts [hs.fac _ WalkingCospan.left, hs.fac _ WalkingCospan.right]⟩⟩ /-- If `W` is the pullback of `f, g`, it is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/ def isLimitOfCompMono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] (s : PullbackCone f g) (H : IsLimit s) : IsLimit (PullbackCone.mk _ _ (show s.fst ≫ f ≫ i = s.snd ≫ g ≫ i by rw [← Category.assoc, ← Category.assoc, s.condition])) := by apply PullbackCone.isLimitAux' intro s rcases PullbackCone.IsLimit.lift' H s.fst s.snd ((cancel_mono i).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PullbackCone.IsLimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _) end PullbackCone end Monomorphisms /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.fst_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono g] : Mono (pullback.fst f g) := PullbackCone.mono_fst_of_is_pullback_of_mono (limit.isLimit _) /-- The pullback of a monomorphism is a monomorphism -/ instance pullback.snd_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [HasPullback f g] [Mono f] : Mono (pullback.snd f g) := PullbackCone.mono_snd_of_is_pullback_of_mono (limit.isLimit _) /-- The map `X ×[Z] Y ⟶ X × Y` is mono. -/ instance mono_pullback_to_prod {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] [HasBinaryProduct X Y] : Mono (prod.lift (pullback.fst f g) (pullback.snd f g)) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => f ≫ prod.fst) h · simpa using congrArg (fun f => f ≫ prod.snd) h⟩ /-- The pullback of `f, g` is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/ noncomputable def pullbackIsPullbackOfCompMono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] [HasPullback f g] : IsLimit (PullbackCone.mk (pullback.fst f g) (pullback.snd f g) -- Porting note: following used to be _ (show (pullback.fst f g) ≫ f ≫ i = (pullback.snd f g) ≫ g ≫ i from by simp only [← Category.assoc]; rw [cancel_mono]; apply pullback.condition)) := PullbackCone.isLimitOfCompMono f g i _ (limit.isLimit (cospan f g)) instance hasPullback_of_comp_mono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [Mono i] [HasPullback f g] : HasPullback (f ≫ i) (g ≫ i) := ⟨⟨⟨_, pullbackIsPullbackOfCompMono f g i⟩⟩⟩ section attribute [local instance] hasPullback_of_left_iso variable (f : X ⟶ Z) (i : Z ⟶ W) [Mono i] instance hasPullback_of_right_factors_mono : HasPullback i (f ≫ i) := by simpa only [Category.id_comp] using hasPullback_of_comp_mono (𝟙 Z) f i instance pullback_snd_iso_of_right_factors_mono : IsIso (pullback.snd i (f ≫ i)) := by #adaptation_note /-- nightly-testing 2024-04-01 this could not be placed directly in the `show from` without `dsimp` -/ have := limit.isoLimitCone_hom_π ⟨_, pullbackIsPullbackOfCompMono (𝟙 _) f i⟩ WalkingCospan.right dsimp only [cospan_right, id_eq, eq_mpr_eq_cast, PullbackCone.mk_pt, PullbackCone.mk_π_app, Functor.const_obj_obj, cospan_one] at this convert (congrArg IsIso (show _ ≫ pullback.snd (𝟙 Z) f = _ from this)).mp inferInstance · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm attribute [local instance] hasPullback_of_right_iso instance hasPullback_of_left_factors_mono : HasPullback (f ≫ i) i := by simpa only [Category.id_comp] using hasPullback_of_comp_mono f (𝟙 Z) i instance pullback_snd_iso_of_left_factors_mono : IsIso (pullback.fst (f ≫ i) i) := by #adaptation_note /-- nightly-testing 2024-04-01 this could not be placed directly in the `show from` without `dsimp` -/ have := limit.isoLimitCone_hom_π ⟨_, pullbackIsPullbackOfCompMono f (𝟙 _) i⟩ WalkingCospan.left dsimp only [cospan_left, id_eq, eq_mpr_eq_cast, PullbackCone.mk_pt, PullbackCone.mk_π_app, Functor.const_obj_obj, cospan_one] at this convert (congrArg IsIso (show _ ≫ pullback.fst f (𝟙 Z) = _ from this)).mp inferInstance · exact (Category.id_comp _).symm · exact (Category.id_comp _).symm end section open WalkingCospan variable (f : X ⟶ Y) instance has_kernel_pair_of_mono [Mono f] : HasPullback f f := ⟨⟨⟨_, PullbackCone.isLimitMkIdId f⟩⟩⟩ theorem fst_eq_snd_of_mono_eq [Mono f] : pullback.fst f f = pullback.snd f f := ((PullbackCone.isLimitMkIdId f).fac (getLimitCone (cospan f f)).cone left).symm.trans ((PullbackCone.isLimitMkIdId f).fac (getLimitCone (cospan f f)).cone right : _) @[simp] theorem pullbackSymmetry_hom_of_mono_eq [Mono f] : (pullbackSymmetry f f).hom = 𝟙 _ := by ext · simp [fst_eq_snd_of_mono_eq] · simp [fst_eq_snd_of_mono_eq] instance fst_iso_of_mono_eq [Mono f] : IsIso (pullback.fst f f) := by refine ⟨⟨pullback.lift (𝟙 _) (𝟙 _) (by simp), ?_, by simp⟩⟩ ext · simp · simp [fst_eq_snd_of_mono_eq] instance snd_iso_of_mono_eq [Mono f] : IsIso (pullback.snd f f) := fst_eq_snd_of_mono_eq f ▸ fst_iso_of_mono_eq f end namespace PushoutCocone variable {f : X ⟶ Y} {g : X ⟶ Z} theorem epi_inr_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi f] : Epi t.inr := ⟨fun {W} h k i => IsColimit.hom_ext ht (by simp [← cancel_epi f, t.condition_assoc, i]) i⟩ theorem epi_inl_of_is_pushout_of_epi {t : PushoutCocone f g} (ht : IsColimit t) [Epi g] : Epi t.inl := ⟨fun {W} h k i => IsColimit.hom_ext ht i (by simp [← cancel_epi g, ← t.condition_assoc, i])⟩ /-- The pushout cocone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a colimit if `f` is an epi. The converse is shown in `epi_of_isColimit_mk_id_id`. -/ def isColimitMkIdId (f : X ⟶ Y) [Epi f] : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f) := IsColimit.mk _ (fun s => s.inl) (fun s => Category.id_comp _) (fun s => by rw [← cancel_epi f, Category.id_comp, s.condition]) fun s m m₁ _ => by simpa using m₁ /-- `f` is an epi if the pushout cocone `(𝟙 X, 𝟙 X)` is a colimit for the pair `(f, f)`. The converse is given in `PushoutCocone.isColimitMkIdId`. -/ theorem epi_of_isColimitMkIdId (f : X ⟶ Y) (t : IsColimit (mk (𝟙 Y) (𝟙 Y) rfl : PushoutCocone f f)) : Epi f := ⟨fun {Z} g h eq => by rcases PushoutCocone.IsColimit.desc' t _ _ eq with ⟨_, rfl, rfl⟩ rfl⟩ /-- Suppose `f` and `g` are two morphisms with a common domain and `s` is a colimit cocone over the diagram formed by `f` and `g`. Suppose `f` and `g` both factor through an epimorphism `h` via `x` and `y`, respectively. Then `s` is also a colimit cocone over the diagram formed by `x` and `y`. -/ def isColimitOfFactors (f : X ⟶ Y) (g : X ⟶ Z) (h : X ⟶ W) [Epi h] (x : W ⟶ Y) (y : W ⟶ Z) (hhx : h ≫ x = f) (hhy : h ≫ y = g) (s : PushoutCocone f g) (hs : IsColimit s) : have reassoc₁ : h ≫ x ≫ inl s = f ≫ inl s := by -- Porting note: working around reassoc rw [← Category.assoc]; apply congrArg (· ≫ inl s) hhx have reassoc₂ : h ≫ y ≫ inr s = g ≫ inr s := by rw [← Category.assoc]; apply congrArg (· ≫ inr s) hhy IsColimit (PushoutCocone.mk _ _ (show x ≫ s.inl = y ≫ s.inr from (cancel_epi h).1 <| by rw [reassoc₁, reassoc₂, s.condition])) := PushoutCocone.isColimitAux' _ fun t => ⟨hs.desc (PushoutCocone.mk t.inl t.inr <| by rw [← hhx, ← hhy, Category.assoc, Category.assoc, t.condition]), ⟨hs.fac _ WalkingSpan.left, hs.fac _ WalkingSpan.right, fun hr hr' => by apply PushoutCocone.IsColimit.hom_ext hs · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr, hr'] symm exact hs.fac _ WalkingSpan.left · simp only [PushoutCocone.mk_inl, PushoutCocone.mk_inr] at hr hr' ⊢ simp only [hr, hr'] symm exact hs.fac _ WalkingSpan.right⟩⟩ /-- If `W` is the pushout of `f, g`, it is also the pushout of `h ≫ f, h ≫ g` for any epi `h`. -/ def isColimitOfEpiComp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] (s : PushoutCocone f g) (H : IsColimit s) : IsColimit (PushoutCocone.mk _ _ (show (h ≫ f) ≫ s.inl = (h ≫ g) ≫ s.inr by rw [Category.assoc, Category.assoc, s.condition])) := by apply PushoutCocone.isColimitAux' intro s rcases PushoutCocone.IsColimit.desc' H s.inl s.inr ((cancel_epi h).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩ refine ⟨l, h₁, h₂, ?_⟩ intro m hm₁ hm₂ exact (PushoutCocone.IsColimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _) end PushoutCocone /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inl_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi g] : Epi (pushout.inl f g) := PushoutCocone.epi_inl_of_is_pushout_of_epi (colimit.isColimit _) /-- The pushout of an epimorphism is an epimorphism -/ instance pushout.inr_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [HasPushout f g] [Epi f] : Epi (pushout.inr _ _ : Z ⟶ pushout f g) := PushoutCocone.epi_inr_of_is_pushout_of_epi (colimit.isColimit _) /-- The map `X ⨿ Y ⟶ X ⨿[Z] Y` is epi. -/ instance epi_coprod_to_pushout {C : Type*} [Category C] {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [HasPushout f g] [HasBinaryCoproduct Y Z] : Epi (coprod.desc (pushout.inl f g) (pushout.inr f g)) := ⟨fun {W} i₁ i₂ h => by ext · simpa using congrArg (fun f => coprod.inl ≫ f) h · simpa using congrArg (fun f => coprod.inr ≫ f) h⟩ /-- The pushout of `f, g` is also the pullback of `h ≫ f, h ≫ g` for any epi `h`. -/ noncomputable def pushoutIsPushoutOfEpiComp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] [HasPushout f g] : IsColimit (PushoutCocone.mk (pushout.inl f g) (pushout.inr f g) (show (h ≫ f) ≫ pushout.inl f g = (h ≫ g) ≫ pushout.inr f g from by simp only [Category.assoc]; rw [cancel_epi]; exact pushout.condition)) := PushoutCocone.isColimitOfEpiComp f g h _ (colimit.isColimit (span f g)) instance hasPushout_of_epi_comp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [Epi h] [HasPushout f g] : HasPushout (h ≫ f) (h ≫ g) := ⟨⟨⟨_, pushoutIsPushoutOfEpiComp f g h⟩⟩⟩ section attribute [local instance] hasPushout_of_left_iso variable (f : X ⟶ Z) (h : W ⟶ X) [Epi h] instance hasPushout_of_right_factors_epi : HasPushout h (h ≫ f) := by simpa only [Category.comp_id] using hasPushout_of_epi_comp (𝟙 X) f h instance pushout_inr_iso_of_right_factors_epi : IsIso (pushout.inr _ _ : _ ⟶ pushout h (h ≫ f)) := by convert (congrArg IsIso (show pushout.inr _ _ ≫ _ = _ from colimit.isoColimitCocone_ι_inv ⟨_, pushoutIsPushoutOfEpiComp (𝟙 _) f h⟩ WalkingSpan.right)).mp inferInstance · apply (Category.comp_id _).symm · apply (Category.comp_id _).symm attribute [local instance] hasPushout_of_right_iso instance hasPushout_of_left_factors_epi (f : X ⟶ Y) : HasPushout (h ≫ f) h := by simpa only [Category.comp_id] using hasPushout_of_epi_comp f (𝟙 X) h instance pushout_inl_iso_of_left_factors_epi (f : X ⟶ Y) : IsIso (pushout.inl _ _ : _ ⟶ pushout (h ≫ f) h) := by convert (congrArg IsIso (show pushout.inl _ _ ≫ _ = _ from colimit.isoColimitCocone_ι_inv ⟨_, pushoutIsPushoutOfEpiComp f (𝟙 _) h⟩ WalkingSpan.left)).mp inferInstance · exact (Category.comp_id _).symm · exact (Category.comp_id _).symm end section open WalkingSpan variable (f : X ⟶ Y) instance has_cokernel_pair_of_epi [Epi f] : HasPushout f f := ⟨⟨⟨_, PushoutCocone.isColimitMkIdId f⟩⟩⟩ theorem inl_eq_inr_of_epi_eq [Epi f] : (pushout.inl _ _ : _ ⟶ pushout f f) = pushout.inr _ _ := ((PushoutCocone.isColimitMkIdId f).fac (getColimitCocone (span f f)).cocone left).symm.trans ((PushoutCocone.isColimitMkIdId f).fac (getColimitCocone (span f f)).cocone right : _) @[simp] theorem pullback_symmetry_hom_of_epi_eq [Epi f] : (pushoutSymmetry f f).hom = 𝟙 _ := by ext <;> simp [inl_eq_inr_of_epi_eq] instance inl_iso_of_epi_eq [Epi f] : IsIso (pushout.inl _ _ : _ ⟶ pushout f f) := by refine ⟨⟨pushout.desc (𝟙 _) (𝟙 _) (by simp), by simp, ?_⟩⟩ apply pushout.hom_ext · simp · simp [inl_eq_inr_of_epi_eq] instance inr_iso_of_epi_eq [Epi f] : IsIso (pushout.inr f f) := inl_eq_inr_of_epi_eq f ▸ inl_iso_of_epi_eq f end end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Pullback\Pasting.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Calle Sönne -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback /-! # Pasting lemma This file proves the pasting lemma for pullbacks. That is, given the following diagram: ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` if the right square is a pullback, then the left square is a pullback iff the big square is a pullback. ## Main results * `pasteHorizIsPullback` shows that the big square is a pullback if both the small squares are. * `leftSquareIsPullback` shows that the left square is a pullback if the other two are. * `pullbackRightPullbackFstIso` shows, using the `pullback` API, that `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y`. * `pullbackLeftPullbackSndIso` shows, using the `pullback` API, that `(X ×[Z] Y) ×[Y] W ≅ X ×[Z] W`. -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] section PasteLemma section PastePullbackHoriz /- Let's consider the following diagram ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` where `t₁` denotes the cone corresponding to the left square, and `t₂` denotes the cone corresponding to the right square. -/ variable {X₃ Y₁ Y₂ Y₃ : C} {g₁ : Y₁ ⟶ Y₂} {g₂ : Y₂ ⟶ Y₃} {i₃ : X₃ ⟶ Y₃} (t₂ : PullbackCone g₂ i₃) variable {i₂ : t₂.pt ⟶ Y₂} (t₁ : PullbackCone g₁ i₂) (hi₂ : i₂ = t₂.fst) local notation "f₂" => t₂.snd local notation "X₁" => t₁.pt local notation "i₁" => t₁.fst local notation "f₁" => t₁.snd /-- The `PullbackCone` obtained by pasting two `PullbackCone`'s horizontally -/ abbrev PullbackCone.pasteHoriz : PullbackCone (g₁ ≫ g₂) i₃ := PullbackCone.mk i₁ (f₁ ≫ f₂) (by rw [reassoc_of% t₁.condition, Category.assoc, ← t₂.condition, ← hi₂]) variable {t₁} {t₂} /-- Given ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` Then the big square is a pullback if both the small squares are. -/ def pasteHorizIsPullback (H : IsLimit t₂) (H' : IsLimit t₁) : IsLimit (t₂.pasteHoriz t₁ hi₂) := by apply PullbackCone.isLimitAux' intro s -- Obtain the lift from lifting from both the small squares consecutively. obtain ⟨l₂, hl₂, hl₂'⟩ := PullbackCone.IsLimit.lift' H (s.fst ≫ g₁) s.snd (by rw [← s.condition, Category.assoc]) obtain ⟨l₁, hl₁, hl₁'⟩ := PullbackCone.IsLimit.lift' H' s.fst l₂ (by rw [← hl₂, hi₂]) refine ⟨l₁, hl₁, by simp [reassoc_of% hl₁', hl₂'], ?_⟩ -- Uniqueness also follows from the universal property of both the small squares. intro m hm₁ hm₂ apply PullbackCone.IsLimit.hom_ext H' (by simpa [hl₁] using hm₁) apply PullbackCone.IsLimit.hom_ext H · dsimp at hm₁ rw [Category.assoc, ← hi₂, ← t₁.condition, reassoc_of% hm₁, hl₁', hi₂, hl₂] · simpa [hl₁', hl₂'] using hm₂ variable (t₁) /-- Given ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ↓ ↓ ↓ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` Then the left square is a pullback if the right square and the big square are. -/ def leftSquareIsPullback (H : IsLimit t₂) (H' : IsLimit (t₂.pasteHoriz t₁ hi₂)) : IsLimit t₁ := by apply PullbackCone.isLimitAux' intro s -- Obtain the induced morphism from the universal property of the big square obtain ⟨l, hl, hl'⟩ := PullbackCone.IsLimit.lift' H' s.fst (s.snd ≫ f₂) (by rw [Category.assoc, ← t₂.condition, reassoc_of% s.condition, ← hi₂]) refine ⟨l, hl, ?_, ?_⟩ -- To check that `l` is compatible with the projections, we use the universal property of `t₂` · apply PullbackCone.IsLimit.hom_ext H · simp [← s.condition, ← hl, ← t₁.condition, ← hi₂] · simpa using hl' -- Uniqueness of the lift follows from the universal property of the big square · intro m hm₁ hm₂ apply PullbackCone.IsLimit.hom_ext H' · simpa [hm₁] using hl.symm · simpa [← hm₂] using hl'.symm /-- Given that the right square is a pullback, the pasted square is a pullback iff the left square is. -/ def pasteHorizIsPullbackEquiv (H : IsLimit t₂) : IsLimit (t₂.pasteHoriz t₁ hi₂) ≃ IsLimit t₁ where toFun H' := leftSquareIsPullback t₁ _ H H' invFun H' := pasteHorizIsPullback _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePullbackHoriz section PastePullbackVert /- Let's consider the following diagram ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` Let `t₁` denote the cone corresponding to the bottom square, and `t₂` denote the cone corresponding to the top square. -/ variable {X₁ X₂ X₃ Y₁ : C} {f₁ : X₂ ⟶ X₁} {f₂ : X₃ ⟶ X₂} {i₁ : Y₁ ⟶ X₁} variable (t₁ : PullbackCone i₁ f₁) {i₂ : t₁.pt ⟶ X₂} (t₂ : PullbackCone i₂ f₂) (hi₂ : i₂ = t₁.snd) local notation "Y₂" => t₁.pt local notation "g₁" => t₁.fst local notation "i₂" => t₁.snd local notation "Y₃" => t₂.pt local notation "g₂" => t₂.fst local notation "i₃" => t₂.snd /-- The `PullbackCone` obtained by pasting two `PullbackCone`'s vertically -/ abbrev PullbackCone.pasteVert : PullbackCone i₁ (f₂ ≫ f₁) := PullbackCone.mk (g₂ ≫ g₁) i₃ (by rw [← reassoc_of% t₂.condition, Category.assoc, t₁.condition, ← hi₂]) /-- Pasting two pullback cones vertically is isomorphic to the pullback cone obtained by flipping them, pasting horizontally, and then flipping the result again. -/ def PullbackCone.pasteVertFlip : (t₁.pasteVert t₂ hi₂).flip ≅ (t₁.flip.pasteHoriz t₂.flip hi₂) := PullbackCone.ext (Iso.refl _) (by simp) (by simp) variable {t₁} {t₂} /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The big square is a pullback if both the small squares are. -/ def pasteVertIsPullback (H₁ : IsLimit t₁) (H₂ : IsLimit t₂) : IsLimit (t₁.pasteVert t₂ hi₂) := by apply PullbackCone.isLimitOfFlip <| IsLimit.ofIsoLimit _ (t₁.pasteVertFlip t₂ hi₂).symm exact pasteHorizIsPullback hi₂ (PullbackCone.flipIsLimit H₁) (PullbackCone.flipIsLimit H₂) variable (t₂) /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The top square is a pullback if the bottom square and the big square are. -/ def topSquareIsPullback (H₁ : IsLimit t₁) (H₂ : IsLimit (t₁.pasteVert t₂ hi₂)) : IsLimit t₂ := PullbackCone.isLimitOfFlip (leftSquareIsPullback _ hi₂ (PullbackCone.flipIsLimit H₁) (PullbackCone.flipIsLimit H₂)) /-- Given that the bottom square is a pullback, the pasted square is a pullback iff the top square is. -/ def pasteVertIsPullbackEquiv (H : IsLimit t₁) : IsLimit (t₁.pasteVert t₂ hi₂) ≃ IsLimit t₂ where toFun H' := topSquareIsPullback t₂ _ H H' invFun H' := pasteVertIsPullback _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePullbackVert section PastePushoutHoriz /- Let's consider the following diagram ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` where `t₁` denotes the left pushout cocone, and `t₂` denotes the right pushout cocone. -/ variable {X₁ X₂ X₃ Y₁ : C} {f₁ : X₁ ⟶ X₂} {f₂ : X₂ ⟶ X₃} {i₁ : X₁ ⟶ Y₁} variable (t₁ : PushoutCocone i₁ f₁) {i₂ : X₂ ⟶ t₁.pt} (t₂ : PushoutCocone i₂ f₂) variable (hi₂ : i₂ = t₁.inr) local notation "Y₂" => t₁.pt local notation "g₁" => t₁.inl local notation "i₂" => t₁.inr local notation "Y₃" => t₂.pt local notation "g₂" => t₂.inl local notation "i₃" => t₂.inr /-- The pushout cocone obtained by pasting two pushout cocones horizontally. -/ abbrev PushoutCocone.pasteHoriz : PushoutCocone i₁ (f₁ ≫ f₂) := PushoutCocone.mk (g₁ ≫ g₂) i₃ (by rw [reassoc_of% t₁.condition, Category.assoc, ← t₂.condition, ← hi₂]) variable {t₁} {t₂} /-- Given ``` X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ ``` Then the big square is a pushout if both the small squares are. -/ def pasteHorizIsPushout (H : IsColimit t₁) (H' : IsColimit t₂) : IsColimit (t₁.pasteHoriz t₂ hi₂) := by apply PushoutCocone.isColimitAux' intro s -- Obtain the induced map from descending from both the small squares consecutively. obtain ⟨l₁, hl₁, hl₁'⟩ := PushoutCocone.IsColimit.desc' H s.inl (f₂ ≫ s.inr) (by rw [s.condition, Category.assoc]) obtain ⟨l₂, hl₂, hl₂'⟩ := PushoutCocone.IsColimit.desc' H' l₁ s.inr (by rw [← hl₁', hi₂]) refine ⟨l₂, by simp [hl₂, hl₁], hl₂', ?_⟩ -- Uniqueness also follows from the universal property of both the small squares. intro m hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H' _ (by simpa [hl₂'] using hm₂) simp only [PushoutCocone.mk_pt, PushoutCocone.mk_ι_app, Category.assoc] at hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H · rw [hm₁, ← hl₁, hl₂] · rw [← hi₂, reassoc_of% t₂.condition, reassoc_of% t₂.condition, hm₂, hl₂'] variable (t₂) /-- Given X₁ - f₁ -> X₂ - f₂ -> X₃ | | | i₁ i₂ i₃ ∨ ∨ ∨ Y₁ - g₁ -> Y₂ - g₂ -> Y₃ Then the right square is a pushout if the left square and the big square are. -/ def rightSquareIsPushout (H : IsColimit t₁) (H' : IsColimit (t₁.pasteHoriz t₂ hi₂)) : IsColimit t₂ := by apply PushoutCocone.isColimitAux' intro s -- Obtain the induced morphism from the universal property of the big square obtain ⟨l, hl, hl'⟩ := PushoutCocone.IsColimit.desc' H' (g₁ ≫ s.inl) s.inr (by rw [reassoc_of% t₁.condition, ← hi₂, s.condition, Category.assoc]) refine ⟨l, ?_, hl', ?_⟩ -- To check that `l` is compatible with the projections, we use the universal property of `t₁` · simp at hl hl' apply PushoutCocone.IsColimit.hom_ext H hl rw [← Category.assoc, ← hi₂, t₂.condition, s.condition, Category.assoc, hl'] -- Uniqueness of the lift follows from the universal property of the big square · intro m hm₁ hm₂ apply PushoutCocone.IsColimit.hom_ext H' · simpa [← hm₁] using hl.symm · simpa [← hm₂] using hl'.symm /-- Given that the left square is a pushout, the pasted square is a pushout iff the right square is. -/ def pasteHorizIsPushoutEquiv (H : IsColimit t₁) : IsColimit (t₁.pasteHoriz t₂ hi₂) ≃ IsColimit t₂ where toFun H' := rightSquareIsPushout t₂ _ H H' invFun H' := pasteHorizIsPushout _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePushoutHoriz section PastePushoutVert /- Let's consider the following diagram ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` Let `t₁` denote the cone corresponding to the bottom square, and `t₂` denote the cone corresponding to the top square. -/ variable {Y₃ Y₂ Y₁ X₃ : C} {g₂ : Y₃ ⟶ Y₂} {g₁ : Y₂ ⟶ Y₁} {i₃ : Y₃ ⟶ X₃} variable (t₁ : PushoutCocone g₂ i₃) {i₂ : Y₂ ⟶ t₁.pt} (t₂ : PushoutCocone g₁ i₂) (hi₂ : i₂ = t₁.inl) local notation "X₂" => t₁.pt local notation "f₂" => t₁.inr local notation "i₂" => t₁.inl local notation "X₁" => t₂.pt local notation "f₁" => t₂.inr local notation "i₁" => t₂.inl /-- The `PullbackCone` obtained by pasting two `PullbackCone`'s vertically -/ abbrev PushoutCocone.pasteVert : PushoutCocone (g₂ ≫ g₁) i₃ := PushoutCocone.mk i₁ (f₂ ≫ f₁) (by rw [← reassoc_of% t₁.condition, Category.assoc, t₂.condition, ← hi₂]) /-- Pasting two pushout cocones vertically is isomorphic to the pushout cocone obtained by flipping them, pasting horizontally, and then flipping the result again. -/ def PushoutCocone.pasteVertFlip : (t₁.pasteVert t₂ hi₂).flip ≅ (t₁.flip.pasteHoriz t₂.flip hi₂) := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) variable {t₁} {t₂} /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The big square is a pushout if both the small squares are. -/ def pasteVertIsPushout (H₁ : IsColimit t₁) (H₂ : IsColimit t₂) : IsColimit (t₁.pasteVert t₂ hi₂) := by apply PushoutCocone.isColimitOfFlip <| IsColimit.ofIsoColimit _ (t₁.pasteVertFlip t₂ hi₂).symm exact pasteHorizIsPushout hi₂ (PushoutCocone.flipIsColimit H₁) (PushoutCocone.flipIsColimit H₂) variable (t₂) /-- Given ``` Y₃ - i₃ -> X₃ | | g₂ f₂ ∨ ∨ Y₂ - i₂ -> X₂ | | g₁ f₁ ∨ ∨ Y₁ - i₁ -> X₁ ``` The bottom square is a pushout if the top square and the big square are. -/ def botSquareIsPushout (H₁ : IsColimit t₁) (H₂ : IsColimit (t₁.pasteVert t₂ hi₂)) : IsColimit t₂ := PushoutCocone.isColimitOfFlip (rightSquareIsPushout _ hi₂ (PushoutCocone.flipIsColimit H₁) (PushoutCocone.flipIsColimit H₂)) /-- Given that the top square is a pushout, the pasted square is a pushout iff the bottom square is. -/ def pasteVertIsPushoutEquiv (H : IsColimit t₁) : IsColimit (t₁.pasteVert t₂ hi₂) ≃ IsColimit t₂ where toFun H' := botSquareIsPushout t₂ _ H H' invFun H' := pasteVertIsPushout _ H H' left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ end PastePushoutVert end PasteLemma section /- Let's consider the following diagram of pullbacks ``` W ×[X] (X ×[Z] Y) --snd--> X ×[Z] Y --snd--> Y | | | fst fst g v v v W --------- f' ---------> X ---- f ---> Y ``` In this section we show that `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y`. -/ variable {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (f' : W ⟶ X) variable [HasPullback f g] [HasPullback f' (pullback.fst f g)] instance hasPullbackHorizPaste : HasPullback (f' ≫ f) g := HasLimit.mk { cone := (pullback.cone f g).pasteHoriz (pullback.cone f' (pullback.fst f g)) rfl isLimit := pasteHorizIsPullback rfl (pullback.isLimit f g) (pullback.isLimit f' (pullback.fst f g)) } /-- The canonical isomorphism `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y` -/ noncomputable def pullbackRightPullbackFstIso : pullback f' (pullback.fst f g) ≅ pullback (f' ≫ f) g := IsLimit.conePointUniqueUpToIso (pasteHorizIsPullback rfl (pullback.isLimit f g) (pullback.isLimit f' (pullback.fst f g))) (pullback.isLimit (f' ≫ f) g) @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_hom_fst : (pullbackRightPullbackFstIso f g f').hom ≫ pullback.fst (f' ≫ f) g = pullback.fst f' (pullback.fst f g) := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_hom_snd : (pullbackRightPullbackFstIso f g f').hom ≫ pullback.snd _ _ = pullback.snd f' (pullback.fst f g) ≫ pullback.snd f g := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_fst : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.fst f' (pullback.fst f g) = pullback.fst (f' ≫ f) g := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_snd_snd : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackRightPullbackFstIso_inv_snd_fst : (pullbackRightPullbackFstIso f g f').inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ f' := by rw [← pullback.condition] exact pullbackRightPullbackFstIso_inv_fst_assoc f g f' _ end section /- Let's consider the following diagram of pullbacks ``` (X ×[Z] Y) ×[Y] W --snd--> W | | fst g' v v (X ×[Z] Y) --- snd ---> Y | | fst g v v X -------- f --------> Z ``` In this section we show that `(X ×[Z] Y) ×[Y] W ≅ X ×[Z] W`. -/ variable {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (g' : W ⟶ Y) variable [HasPullback f g] [HasPullback (pullback.snd f g) g'] instance hasPullbackVertPaste : HasPullback f (g' ≫ g) := HasLimit.mk { cone := (pullback.cone f g).pasteVert (pullback.cone (pullback.snd f g) g') rfl isLimit := pasteVertIsPullback rfl (pullback.isLimit f g) (pullback.isLimit (pullback.snd f g) g') } /-- The canonical isomorphism `(X ×[Z] Y) ×[Y] W ≅ X ×[Z] W` -/ def pullbackLeftPullbackSndIso : pullback (pullback.snd f g) g' ≅ pullback f (g' ≫ g) := IsLimit.conePointUniqueUpToIso (pasteVertIsPullback rfl (pullback.isLimit f g) (pullback.isLimit (pullback.snd f g) g')) (pullback.isLimit f (g' ≫ g)) @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_hom_fst : (pullbackLeftPullbackSndIso f g g').hom ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_hom_snd : (pullbackLeftPullbackSndIso f g g').hom ≫ pullback.snd _ _ = pullback.snd _ _ := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_inv_fst : (pullbackLeftPullbackSndIso f g g').inv ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.left @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_inv_snd_snd : (pullbackLeftPullbackSndIso f g g').inv ≫ pullback.snd _ _ = pullback.snd _ _ := IsLimit.conePointUniqueUpToIso_inv_comp _ _ WalkingCospan.right @[reassoc (attr := simp)] theorem pullbackLeftPullbackSndIso_inv_fst_snd : (pullbackLeftPullbackSndIso f g g').inv ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ g' := by rw [pullback.condition] exact pullbackLeftPullbackSndIso_inv_snd_snd_assoc f g g' g' end section /- Let's consider the following diagram of pushouts ``` X ---- g ----> Z ----- g' -----> W | | | f inr inr v v v Y - inl -> Y ⨿[X] Z --inl--> (Y ⨿[X] Z) ⨿[Z] W ``` In this section we show that `(Y ⨿[X] Z) ⨿[Z] W ≅ Y ⨿[X] W`. -/ variable {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (g' : Z ⟶ W) variable [HasPushout f g] [HasPushout (pushout.inr f g) g'] instance : HasPushout f (g ≫ g') := HasColimit.mk { cocone := (pushout.cocone f g).pasteHoriz (pushout.cocone (pushout.inr f g) g') rfl isColimit := pasteHorizIsPushout rfl (pushout.isColimit f g) (pushout.isColimit (pushout.inr f g) g') } /-- The canonical isomorphism `(Y ⨿[X] Z) ⨿[Z] W ≅ Y ⨿[X] W` -/ noncomputable def pushoutLeftPushoutInrIso : pushout (pushout.inr f g) g' ≅ pushout f (g ≫ g') := IsColimit.coconePointUniqueUpToIso (pasteHorizIsPushout rfl (pushout.isColimit f g) (pushout.isColimit (pushout.inr f g) g')) (pushout.isColimit f (g ≫ g')) @[reassoc (attr := simp)] theorem inl_pushoutLeftPushoutInrIso_inv : (pushout.inl f (g ≫ g')) ≫ (pushoutLeftPushoutInrIso f g g').inv = (pushout.inl f g) ≫ (pushout.inl (pushout.inr f g) g') := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_pushoutLeftPushoutInrIso_hom : (pushout.inr (pushout.inr f g) g') ≫ (pushoutLeftPushoutInrIso f g g').hom = (pushout.inr f (g ≫ g')) := IsColimit.comp_coconePointUniqueUpToIso_hom (pasteHorizIsPushout _ _ _) _ WalkingSpan.right @[reassoc (attr := simp)] theorem inr_pushoutLeftPushoutInrIso_inv : (pushout.inr f (g ≫ g')) ≫ (pushoutLeftPushoutInrIso f g g').inv = (pushout.inr (pushout.inr f g) g') := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.right @[reassoc (attr := simp)] theorem inl_inl_pushoutLeftPushoutInrIso_hom : (pushout.inl f g) ≫ (pushout.inl (pushout.inr f g) g') ≫ (pushoutLeftPushoutInrIso f g g').hom = (pushout.inl f (g ≫ g')) := by rw [← Category.assoc] apply IsColimit.comp_coconePointUniqueUpToIso_hom (pasteHorizIsPushout _ _ _) _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_inl_pushoutLeftPushoutInrIso_hom : pushout.inr f g ≫ pushout.inl (pushout.inr f g) g' ≫ (pushoutLeftPushoutInrIso f g g').hom = g' ≫ pushout.inr f (g ≫ g') := by rw [← Category.assoc, ← Iso.eq_comp_inv, Category.assoc, inr_pushoutLeftPushoutInrIso_inv, pushout.condition] end section /- Let's consider the diagram of pushouts ``` X ---- g ----> Z | | f inr v v Y - inl -> Y ⨿[X] Z | | f' inr v v W - inl -> W ⨿[Y] (Y ⨿[X] Z) ``` In this section we will construct the isomorphism `W ⨿[Y] (Y ⨿[X] Z) ≅ W ⨿[X] Z`. -/ variable {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (f' : Y ⟶ W) variable [HasPushout f g] [HasPushout f' (pushout.inl f g)] instance hasPushoutVertPaste : HasPushout (f ≫ f') g := HasColimit.mk { cocone := (pushout.cocone f g).pasteVert (pushout.cocone f' (pushout.inl f g)) rfl isColimit := pasteVertIsPushout rfl (pushout.isColimit f g) (pushout.isColimit f' (pushout.inl f g)) } /-- The canonical isomorphism `W ⨿[Y] (Y ⨿[X] Z) ≅ W ⨿[X] Z` -/ noncomputable def pushoutRightPushoutInlIso : pushout f' (pushout.inl f g) ≅ pushout (f ≫ f') g := IsColimit.coconePointUniqueUpToIso (pasteVertIsPushout rfl (pushout.isColimit f g) (pushout.isColimit f' (pushout.inl f g))) (pushout.isColimit (f ≫ f') g) @[reassoc (attr := simp)] theorem inl_pushoutRightPushoutInlIso_inv : pushout.inl _ _ ≫ (pushoutRightPushoutInlIso f g f').inv = pushout.inl _ _ := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_inr_pushoutRightPushoutInlIso_hom : pushout.inr _ _ ≫ pushout.inr _ _ ≫ (pushoutRightPushoutInlIso f g f').hom = pushout.inr _ _ := by rw [← Category.assoc] apply IsColimit.comp_coconePointUniqueUpToIso_hom (pasteVertIsPushout rfl _ _) _ WalkingSpan.right @[reassoc (attr := simp)] theorem inr_pushoutRightPushoutInlIso_inv : pushout.inr _ _ ≫ (pushoutRightPushoutInlIso f g f').inv = pushout.inr _ _ ≫ pushout.inr _ _ := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ WalkingSpan.right @[reassoc (attr := simp)] theorem inl_pushoutRightPushoutInlIso_hom : pushout.inl _ _ ≫ (pushoutRightPushoutInlIso f g f').hom = pushout.inl _ _ := IsColimit.comp_coconePointUniqueUpToIso_hom (pasteVertIsPushout rfl _ _) _ WalkingSpan.left @[reassoc (attr := simp)] theorem inr_inl_pushoutRightPushoutInlIso_hom : pushout.inl _ _ ≫ pushout.inr _ _ ≫ (pushoutRightPushoutInlIso f g f').hom = f' ≫ pushout.inl _ _ := by rw [← Category.assoc, ← pushout.condition, Category.assoc, inl_pushoutRightPushoutInlIso_hom] end end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Pullback\PullbackCone.lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel, Bhavik Mehta, Andrew Yang, Emily Riehl, Calle Sönne -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Cospan /-! # PullbackCone This file provides API for interacting with cones (resp. cocones) in the case of pullbacks (resp. pushouts). # Main definitions * `PullbackCone f g`: Given morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`, a term `t : PullbackCone f g` provides the data of a cone pictured as follows ``` t.pt ---t.snd---> Y | | t.fst g | | v v X -----f------> Z ``` The type `PullbackCone f g` is implemented as an abbrevation for `Cone (cospan f g)`, so general results about cones are also available for `PullbackCone f g`. * `PushoutCone f g`: Given morphisms `f : X ⟶ Y` and `g : X ⟶ Z`, a term `t : PushoutCone f g` provides the data of a cocone pictured as follows ``` X -----f------> Y | | g t.inr | | v v Z ---t.inl---> t.pt ``` Similar to `PullbackCone`, `PushoutCone f g` is implemented as an abbreviation for `Cocone (span f g)`, so general results about cocones are also available for `PushoutCone f g`. ## API We summarize the most important parts of the API for pullback cones here. The dual notions for pushout cones is also available in this file. Various ways of constructing pullback cones: * `PullbackCone.mk` constructs a term of `PullbackCone f g` given morphisms `fst` and `snd` such that `fst ≫ f = snd ≫ g`. * `PullbackCone.flip` is the `PullbackCone` obtained by flipping `fst` and `snd`. Interaction with `IsLimit`: * `PullbackCone.isLimitAux` and `PullbackCone.isLimitAux'` provide two convenient ways to show that a given `PullbackCone` is a limit cone. * `PullbackCone.isLimit.mk` provides a convenient way to show that a `PullbackCone` constructed using `PullbackCone.mk` is a limit cone. * `PullbackCone.IsLimit.lift` and `PullbackCone.IsLimit.lift'` provides convenient ways for constructing the morphisms to the point of a limit `PullbackCone` from the universal property. * `PullbackCone.IsLimit.hom_ext` provides a convenient way to show that two morphisms to the point of a limit `PullbackCone` are equal. ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] {W X Y Z : C} /-- A pullback cone is just a cone on the cospan formed by two morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`. -/ abbrev PullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) := Cone (cospan f g) namespace PullbackCone variable {f : X ⟶ Z} {g : Y ⟶ Z} /-- The first projection of a pullback cone. -/ abbrev fst (t : PullbackCone f g) : t.pt ⟶ X := t.π.app WalkingCospan.left /-- The second projection of a pullback cone. -/ abbrev snd (t : PullbackCone f g) : t.pt ⟶ Y := t.π.app WalkingCospan.right @[simp] theorem π_app_left (c : PullbackCone f g) : c.π.app WalkingCospan.left = c.fst := rfl @[simp] theorem π_app_right (c : PullbackCone f g) : c.π.app WalkingCospan.right = c.snd := rfl @[simp] theorem condition_one (t : PullbackCone f g) : t.π.app WalkingCospan.one = t.fst ≫ f := by have w := t.π.naturality WalkingCospan.Hom.inl dsimp at w; simpa using w /-- A pullback cone on `f` and `g` is determined by morphisms `fst : W ⟶ X` and `snd : W ⟶ Y` such that `fst ≫ f = snd ≫ g`. -/ @[simps] def mk {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : PullbackCone f g where pt := W π := { app := fun j => Option.casesOn j (fst ≫ f) fun j' => WalkingPair.casesOn j' fst snd naturality := by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) j <;> cases j <;> dsimp <;> simp [eq] } @[simp] theorem mk_π_app_left {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.left = fst := rfl @[simp] theorem mk_π_app_right {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.right = snd := rfl @[simp] theorem mk_π_app_one {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).π.app WalkingCospan.one = fst ≫ f := rfl @[simp] theorem mk_fst {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).fst = fst := rfl @[simp] theorem mk_snd {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : (mk fst snd eq).snd = snd := rfl @[reassoc] theorem condition (t : PullbackCone f g) : fst t ≫ f = snd t ≫ g := (t.w inl).trans (t.w inr).symm /-- To check whether two morphisms are equalized by the maps of a pullback cone, it suffices to check it for `fst t` and `snd t` -/ theorem equalizer_ext (t : PullbackCone f g) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : ∀ j : WalkingCospan, k ≫ t.π.app j = l ≫ t.π.app j | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w inl, reassoc_of% h₀] /-- To construct an isomorphism of pullback cones, it suffices to construct an isomorphism of the cone points and check it commutes with `fst` and `snd`. -/ def ext {s t : PullbackCone f g} (i : s.pt ≅ t.pt) (w₁ : s.fst = i.hom ≫ t.fst := by aesop_cat) (w₂ : s.snd = i.hom ≫ t.snd := by aesop_cat) : s ≅ t := WalkingCospan.ext i w₁ w₂ /-- The natural isomorphism between a pullback cone and the corresponding pullback cone reconstructed using `PullbackCone.mk`. -/ @[simps!] def eta (t : PullbackCone f g) : t ≅ mk t.fst t.snd t.condition := PullbackCone.ext (Iso.refl _) /-- This is a slightly more convenient method to verify that a pullback cone is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : PullbackCone f g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ t.pt) (fac_left : ∀ s : PullbackCone f g, lift s ≫ t.fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ t.snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ t.pt) (_ : ∀ j : WalkingCospan, m ≫ t.π.app j = s.π.app j), m = lift s) : IsLimit t := { lift fac := fun s j => Option.casesOn j (by rw [← s.w inl, ← t.w inl, ← Category.assoc] congr exact fac_left s) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } /-- This is another convenient method to verify that a pullback cone is a limit cone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def isLimitAux' (t : PullbackCone f g) (create : ∀ s : PullbackCone f g, { l // l ≫ t.fst = s.fst ∧ l ≫ t.snd = s.snd ∧ ∀ {m}, m ≫ t.fst = s.fst → m ≫ t.snd = s.snd → m = l }) : Limits.IsLimit t := PullbackCone.isLimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) /-- This is a more convenient formulation to show that a `PullbackCone` constructed using `PullbackCone.mk` is a limit cone. -/ def IsLimit.mk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (eq : fst ≫ f = snd ≫ g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ W) (fac_left : ∀ s : PullbackCone f g, lift s ≫ fst = s.fst) (fac_right : ∀ s : PullbackCone f g, lift s ≫ snd = s.snd) (uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (mk fst snd eq) := isLimitAux _ lift fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) theorem IsLimit.hom_ext {t : PullbackCone f g} (ht : IsLimit t) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : k = l := ht.hom_ext <| equalizer_ext _ h₀ h₁ -- Porting note: `IsLimit.lift` and the two following simp lemmas were introduced to ease the port /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we get `l : W ⟶ t.pt`, which satisfies `l ≫ fst t = h` and `l ≫ snd t = k`, see `IsLimit.lift_fst` and `IsLimit.lift_snd`. -/ def IsLimit.lift {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ t.pt := ht.lift <| PullbackCone.mk _ _ w @[reassoc (attr := simp)] lemma IsLimit.lift_fst {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ fst t = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsLimit.lift_snd {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ snd t = k := ht.fac _ _ /-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that `h ≫ f = k ≫ g`, then we have `l : W ⟶ t.pt` satisfying `l ≫ fst t = h` and `l ≫ snd t = k`. -/ def IsLimit.lift' {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : { l : W ⟶ t.pt // l ≫ fst t = h ∧ l ≫ snd t = k } := ⟨IsLimit.lift ht h k w, by simp⟩ /-- The pullback cone reconstructed using `PullbackCone.mk` from a pullback cone that is a limit, is also a limit. -/ def mkSelfIsLimit {t : PullbackCone f g} (ht : IsLimit t) : IsLimit (mk t.fst t.snd t.condition) := IsLimit.ofIsoLimit ht (eta t) section Flip variable (t : PullbackCone f g) /-- The pullback cone obtained by flipping `fst` and `snd`. -/ def flip : PullbackCone g f := PullbackCone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_fst : t.flip.fst = t.snd := rfl @[simp] lemma flip_snd : t.flip.snd = t.fst := rfl /-- Flipping a pullback cone twice gives an isomorphic cone. -/ def flipFlipIso : t.flip.flip ≅ t := PullbackCone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pullback square is a pullback square. -/ def flipIsLimit (ht : IsLimit t) : IsLimit t.flip := IsLimit.mk _ (fun s => ht.lift s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsLimit.hom_ext ht <;> simp [h₁, h₂]) /-- A square is a pullback square if its flip is. -/ def isLimitOfFlip (ht : IsLimit t.flip) : IsLimit t := IsLimit.ofIsoLimit (flipIsLimit ht) t.flipFlipIso end Flip end PullbackCone /-- This is a helper construction that can be useful when verifying that a category has all pullbacks. Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a pullback cone on `F.map inl` and `F.map inr`, we get a cone on `F`. If you're thinking about using this, have a look at `hasPullbacks_of_hasLimit_cospan`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cone.ofPullbackCone {F : WalkingCospan ⥤ C} (t : PullbackCone (F.map inl) (F.map inr)) : Cone F where pt := t.pt π := t.π ≫ (diagramIsoCospan F).inv /-- Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`, and a cone on `F`, we get a pullback cone on `F.map inl` and `F.map inr`. -/ @[simps] def PullbackCone.ofCone {F : WalkingCospan ⥤ C} (t : Cone F) : PullbackCone (F.map inl) (F.map inr) where pt := t.pt π := t.π ≫ (diagramIsoCospan F).hom /-- A diagram `WalkingCospan ⥤ C` is isomorphic to some `PullbackCone.mk` after composing with `diagramIsoCospan`. -/ @[simps!] def PullbackCone.isoMk {F : WalkingCospan ⥤ C} (t : Cone F) : (Cones.postcompose (diagramIsoCospan.{v} _).hom).obj t ≅ PullbackCone.mk (t.π.app WalkingCospan.left) (t.π.app WalkingCospan.right) ((t.π.naturality inl).symm.trans (t.π.naturality inr : _)) := Cones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> · dsimp simp /-- A pushout cocone is just a cocone on the span formed by two morphisms `f : X ⟶ Y` and `g : X ⟶ Z`. -/ abbrev PushoutCocone (f : X ⟶ Y) (g : X ⟶ Z) := Cocone (span f g) namespace PushoutCocone variable {f : X ⟶ Y} {g : X ⟶ Z} /-- The first inclusion of a pushout cocone. -/ abbrev inl (t : PushoutCocone f g) : Y ⟶ t.pt := t.ι.app WalkingSpan.left /-- The second inclusion of a pushout cocone. -/ abbrev inr (t : PushoutCocone f g) : Z ⟶ t.pt := t.ι.app WalkingSpan.right @[simp] theorem ι_app_left (c : PushoutCocone f g) : c.ι.app WalkingSpan.left = c.inl := rfl @[simp] theorem ι_app_right (c : PushoutCocone f g) : c.ι.app WalkingSpan.right = c.inr := rfl @[simp] theorem condition_zero (t : PushoutCocone f g) : t.ι.app WalkingSpan.zero = f ≫ t.inl := by have w := t.ι.naturality WalkingSpan.Hom.fst dsimp at w; simpa using w.symm /-- A pushout cocone on `f` and `g` is determined by morphisms `inl : Y ⟶ W` and `inr : Z ⟶ W` such that `f ≫ inl = g ↠ inr`. -/ @[simps] def mk {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : PushoutCocone f g where pt := W ι := { app := fun j => Option.casesOn j (f ≫ inl) fun j' => WalkingPair.casesOn j' inl inr naturality := by rintro (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) <;> intro f <;> cases f <;> dsimp <;> aesop } @[simp] theorem mk_ι_app_left {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.left = inl := rfl @[simp] theorem mk_ι_app_right {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.right = inr := rfl @[simp] theorem mk_ι_app_zero {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).ι.app WalkingSpan.zero = f ≫ inl := rfl @[simp] theorem mk_inl {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inl = inl := rfl @[simp] theorem mk_inr {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : (mk inl inr eq).inr = inr := rfl @[reassoc] theorem condition (t : PushoutCocone f g) : f ≫ inl t = g ≫ inr t := (t.w fst).trans (t.w snd).symm /-- To check whether a morphism is coequalized by the maps of a pushout cocone, it suffices to check it for `inl t` and `inr t` -/ theorem coequalizer_ext (t : PushoutCocone f g) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : ∀ j : WalkingSpan, t.ι.app j ≫ k = t.ι.app j ≫ l | some WalkingPair.left => h₀ | some WalkingPair.right => h₁ | none => by rw [← t.w fst, Category.assoc, Category.assoc, h₀] /-- To construct an isomorphism of pushout cocones, it suffices to construct an isomorphism of the cocone points and check it commutes with `inl` and `inr`. -/ def ext {s t : PushoutCocone f g} (i : s.pt ≅ t.pt) (w₁ : s.inl ≫ i.hom = t.inl := by aesop_cat) (w₂ : s.inr ≫ i.hom = t.inr := by aesop_cat) : s ≅ t := WalkingSpan.ext i w₁ w₂ /-- The natural isomorphism between a pushout cocone and the corresponding pushout cocone reconstructed using `PushoutCocone.mk`. -/ @[simps!] def eta (t : PushoutCocone f g) : t ≅ mk t.inl t.inr t.condition := PushoutCocone.ext (Iso.refl _) /-- This is a slightly more convenient method to verify that a pushout cocone is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def isColimitAux (t : PushoutCocone f g) (desc : ∀ s : PushoutCocone f g, t.pt ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, t.inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, t.inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : t.pt ⟶ s.pt) (_ : ∀ j : WalkingSpan, t.ι.app j ≫ m = s.ι.app j), m = desc s) : IsColimit t := { desc fac := fun s j => Option.casesOn j (by simp [← s.w fst, ← t.w fst, fac_left s]) fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s) uniq := uniq } /-- This is another convenient method to verify that a pushout cocone is a colimit cocone. It only asks for a proof of facts that carry any mathematical content, and allows access to the same `s` for all parts. -/ def isColimitAux' (t : PushoutCocone f g) (create : ∀ s : PushoutCocone f g, { l // t.inl ≫ l = s.inl ∧ t.inr ≫ l = s.inr ∧ ∀ {m}, t.inl ≫ m = s.inl → t.inr ≫ m = s.inr → m = l }) : IsColimit t := isColimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1) fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right) theorem IsColimit.hom_ext {t : PushoutCocone f g} (ht : IsColimit t) {W : C} {k l : t.pt ⟶ W} (h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : k = l := ht.hom_ext <| coequalizer_ext _ h₀ h₁ -- Porting note: `IsColimit.desc` and the two following simp lemmas were introduced to ease the port /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`, see `IsColimit.inl_desc` and `IsColimit.inr_desc`-/ def IsColimit.desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : t.pt ⟶ W := ht.desc (PushoutCocone.mk _ _ w) @[reassoc (attr := simp)] lemma IsColimit.inl_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inl t ≫ IsColimit.desc ht h k w = h := ht.fac _ _ @[reassoc (attr := simp)] lemma IsColimit.inr_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : inr t ≫ IsColimit.desc ht h k w = k := ht.fac _ _ /-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that `inl t ≫ l = h` and `inr t ≫ l = k`. -/ def IsColimit.desc' {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : { l : t.pt ⟶ W // inl t ≫ l = h ∧ inr t ≫ l = k } := ⟨IsColimit.desc ht h k w, by simp⟩ /-- This is a more convenient formulation to show that a `PushoutCocone` constructed using `PushoutCocone.mk` is a colimit cocone. -/ def IsColimit.mk {W : C} {inl : Y ⟶ W} {inr : Z ⟶ W} (eq : f ≫ inl = g ≫ inr) (desc : ∀ s : PushoutCocone f g, W ⟶ s.pt) (fac_left : ∀ s : PushoutCocone f g, inl ≫ desc s = s.inl) (fac_right : ∀ s : PushoutCocone f g, inr ≫ desc s = s.inr) (uniq : ∀ (s : PushoutCocone f g) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (mk inl inr eq) := isColimitAux _ desc fac_left fac_right fun s m w => uniq s m (w WalkingCospan.left) (w WalkingCospan.right) /-- The pushout cocone reconstructed using `PushoutCocone.mk` from a pushout cocone that is a colimit, is also a colimit. -/ def mkSelfIsColimit {t : PushoutCocone f g} (ht : IsColimit t) : IsColimit (mk t.inl t.inr t.condition) := IsColimit.ofIsoColimit ht (eta t) section Flip variable (t : PushoutCocone f g) /-- The pushout cocone obtained by flipping `inl` and `inr`. -/ def flip : PushoutCocone g f := PushoutCocone.mk _ _ t.condition.symm @[simp] lemma flip_pt : t.flip.pt = t.pt := rfl @[simp] lemma flip_inl : t.flip.inl = t.inr := rfl @[simp] lemma flip_inr : t.flip.inr = t.inl := rfl /-- Flipping a pushout cocone twice gives an isomorphic cocone. -/ def flipFlipIso : t.flip.flip ≅ t := PushoutCocone.ext (Iso.refl _) (by simp) (by simp) variable {t} /-- The flip of a pushout square is a pushout square. -/ def flipIsColimit (ht : IsColimit t) : IsColimit t.flip := IsColimit.mk _ (fun s => ht.desc s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by apply IsColimit.hom_ext ht <;> simp [h₁, h₂]) /-- A square is a pushout square if its flip is. -/ def isColimitOfFlip (ht : IsColimit t.flip) : IsColimit t := IsColimit.ofIsoColimit (flipIsColimit ht) t.flipFlipIso end Flip end PushoutCocone /-- This is a helper construction that can be useful when verifying that a category has all pushout. Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a pushout cocone on `F.map fst` and `F.map snd`, we get a cocone on `F`. If you're thinking about using this, have a look at `hasPushouts_of_hasColimit_span`, which you may find to be an easier way of achieving your goal. -/ @[simps] def Cocone.ofPushoutCocone {F : WalkingSpan ⥤ C} (t : PushoutCocone (F.map fst) (F.map snd)) : Cocone F where pt := t.pt ι := (diagramIsoSpan F).hom ≫ t.ι /-- Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`, and a cocone on `F`, we get a pushout cocone on `F.map fst` and `F.map snd`. -/ @[simps] def PushoutCocone.ofCocone {F : WalkingSpan ⥤ C} (t : Cocone F) : PushoutCocone (F.map fst) (F.map snd) where pt := t.pt ι := (diagramIsoSpan F).inv ≫ t.ι /-- A diagram `WalkingSpan ⥤ C` is isomorphic to some `PushoutCocone.mk` after composing with `diagramIsoSpan`. -/ @[simps!] def PushoutCocone.isoMk {F : WalkingSpan ⥤ C} (t : Cocone F) : (Cocones.precompose (diagramIsoSpan.{v} _).inv).obj t ≅ PushoutCocone.mk (t.ι.app WalkingSpan.left) (t.ι.app WalkingSpan.right) ((t.ι.naturality fst).trans (t.ι.naturality snd).symm) := Cocones.ext (Iso.refl _) <| by rintro (_ | (_ | _)) <;> · dsimp simp end CategoryTheory.Limits
CategoryTheory\Limits\Shapes\Pullback\Square.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Square import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Commutative squares that are pushout or pullback squares In this file, we translate the `IsPushout` and `IsPullback` API for the objects of the category `Square C` of commutative squares in a category `C`. -/ universe v u namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] namespace Square variable (sq : Square C) /-- The pullback cone attached to a commutative square. -/ abbrev pullbackCone : PullbackCone sq.f₂₄ sq.f₃₄ := PullbackCone.mk sq.f₁₂ sq.f₁₃ sq.fac /-- The pushout cocone attached to a commutative square. -/ abbrev pushoutCocone : PushoutCocone sq.f₁₂ sq.f₁₃ := PushoutCocone.mk sq.f₂₄ sq.f₃₄ sq.fac /-- The condition that a commutative square is a pullback square. -/ protected def IsPullback : Prop := IsPullback sq.f₁₂ sq.f₁₃ sq.f₂₄ sq.f₃₄ /-- The condition that a commutative square is a pushout square. -/ protected def IsPushout : Prop := IsPushout sq.f₁₂ sq.f₁₃ sq.f₂₄ sq.f₃₄ lemma isPullback_iff : sq.IsPullback ↔ Nonempty (IsLimit sq.pullbackCone) := ⟨fun h ↦ ⟨h.isLimit⟩, fun h ↦ { w := sq.fac, isLimit' := h }⟩ lemma isPushout_iff : sq.IsPushout ↔ Nonempty (IsColimit sq.pushoutCocone) := ⟨fun h ↦ ⟨h.isColimit⟩, fun h ↦ { w := sq.fac, isColimit' := h }⟩ lemma IsPullback.mk (h : IsLimit sq.pullbackCone) : sq.IsPullback := sq.isPullback_iff.2 ⟨h⟩ lemma IsPushout.mk (h : IsColimit sq.pushoutCocone) : sq.IsPushout := sq.isPushout_iff.2 ⟨h⟩ variable {sq} /-- If a commutative square `sq` is a pullback square, then `sq.pullbackCone` is limit. -/ noncomputable def IsPullback.isLimit (h : sq.IsPullback) : IsLimit sq.pullbackCone := CategoryTheory.IsPullback.isLimit h /-- If a commutative square `sq` is a pushout square, then `sq.pushoutCocone` is colimit. -/ noncomputable def IsPushout.isColimit (h : sq.IsPushout) : IsColimit sq.pushoutCocone := CategoryTheory.IsPushout.isColimit h lemma IsPullback.of_iso {sq₁ sq₂ : Square C} (h : sq₁.IsPullback) (e : sq₁ ≅ sq₂) : sq₂.IsPullback := by refine CategoryTheory.IsPullback.of_iso h (evaluation₁.mapIso e) (evaluation₂.mapIso e) (evaluation₃.mapIso e) (evaluation₄.mapIso e) ?_ ?_ ?_ ?_ all_goals aesop_cat lemma IsPullback.iff_of_iso {sq₁ sq₂ : Square C} (e : sq₁ ≅ sq₂) : sq₁.IsPullback ↔ sq₂.IsPullback := ⟨fun h ↦ h.of_iso e, fun h ↦ h.of_iso e.symm⟩ lemma IsPushout.of_iso {sq₁ sq₂ : Square C} (h : sq₁.IsPushout) (e : sq₁ ≅ sq₂) : sq₂.IsPushout := by refine CategoryTheory.IsPushout.of_iso h (evaluation₁.mapIso e) (evaluation₂.mapIso e) (evaluation₃.mapIso e) (evaluation₄.mapIso e) ?_ ?_ ?_ ?_ all_goals aesop_cat lemma IsPushout.iff_of_iso {sq₁ sq₂ : Square C} (e : sq₁ ≅ sq₂) : sq₁.IsPushout ↔ sq₂.IsPushout := ⟨fun h ↦ h.of_iso e, fun h ↦ h.of_iso e.symm⟩ lemma IsPushout.op {sq : Square C} (h : sq.IsPushout) : sq.op.IsPullback := CategoryTheory.IsPushout.op h.flip lemma IsPushout.unop {sq : Square Cᵒᵖ} (h : sq.IsPushout) : sq.unop.IsPullback := CategoryTheory.IsPushout.unop h.flip lemma IsPullback.op {sq : Square C} (h : sq.IsPullback) : sq.op.IsPushout := CategoryTheory.IsPullback.op h.flip lemma IsPullback.unop {sq : Square Cᵒᵖ} (h : sq.IsPullback) : sq.unop.IsPushout := CategoryTheory.IsPullback.unop h.flip end Square end CategoryTheory
CategoryTheory\Linear\Basic.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.CategoryTheory.Preadditive.Basic /-! # Linear categories An `R`-linear category is a category in which `X ⟶ Y` is an `R`-module in such a way that composition of morphisms is `R`-linear in both variables. Note that sometimes in the literature a "linear category" is further required to be abelian. ## Implementation Corresponding to the fact that we need to have an `AddCommGroup X` structure in place to talk about a `Module R X` structure, we need `Preadditive C` as a prerequisite typeclass for `Linear R C`. This makes for longer signatures than would be ideal. ## Future work It would be nice to have a usable framework of enriched categories in which this just became a category enriched in `Module R`. -/ universe w v u open CategoryTheory.Limits open LinearMap namespace CategoryTheory /-- A category is called `R`-linear if `P ⟶ Q` is an `R`-module such that composition is `R`-linear in both variables. -/ class Linear (R : Type w) [Semiring R] (C : Type u) [Category.{v} C] [Preadditive C] where homModule : ∀ X Y : C, Module R (X ⟶ Y) := by infer_instance /-- compatibility of the scalar multiplication with the post-composition -/ smul_comp : ∀ (X Y Z : C) (r : R) (f : X ⟶ Y) (g : Y ⟶ Z), (r • f) ≫ g = r • f ≫ g := by aesop_cat /-- compatibility of the scalar multiplication with the pre-composition -/ comp_smul : ∀ (X Y Z : C) (f : X ⟶ Y) (r : R) (g : Y ⟶ Z), f ≫ (r • g) = r • f ≫ g := by aesop_cat attribute [instance] Linear.homModule attribute [simp] Linear.smul_comp Linear.comp_smul -- (the linter doesn't like `simp` on the `_assoc` lemma) end CategoryTheory open CategoryTheory namespace CategoryTheory.Linear variable {C : Type u} [Category.{v} C] [Preadditive C] instance preadditiveNatLinear : Linear ℕ C where smul_comp X Y Z r f g := by exact (Preadditive.rightComp X g).map_nsmul f r comp_smul X Y Z f r g := by exact (Preadditive.leftComp Z f).map_nsmul g r instance preadditiveIntLinear : Linear ℤ C where smul_comp X Y Z r f g := by exact (Preadditive.rightComp X g).map_zsmul f r comp_smul X Y Z f r g := by exact (Preadditive.leftComp Z f).map_zsmul g r section End variable {R : Type w} instance [Semiring R] [Linear R C] (X : C) : Module R (End X) := by dsimp [End] infer_instance instance [CommSemiring R] [Linear R C] (X : C) : Algebra R (End X) := Algebra.ofModule (fun _ _ _ => comp_smul _ _ _ _ _ _) fun _ _ _ => smul_comp _ _ _ _ _ _ end End section variable {R : Type w} [Semiring R] [Linear R C] section InducedCategory universe u' variable {D : Type u'} (F : D → C) instance inducedCategory : Linear.{w, v} R (InducedCategory C F) where homModule X Y := @Linear.homModule R _ C _ _ _ (F X) (F Y) smul_comp _ _ _ _ _ _ := smul_comp _ _ _ _ _ _ comp_smul _ _ _ _ _ _ := comp_smul _ _ _ _ _ _ end InducedCategory instance fullSubcategory (Z : C → Prop) : Linear.{w, v} R (FullSubcategory Z) where homModule X Y := @Linear.homModule R _ C _ _ _ X.obj Y.obj smul_comp _ _ _ _ _ _ := smul_comp _ _ _ _ _ _ comp_smul _ _ _ _ _ _ := comp_smul _ _ _ _ _ _ variable (R) /-- Composition by a fixed left argument as an `R`-linear map. -/ @[simps] def leftComp {X Y : C} (Z : C) (f : X ⟶ Y) : (Y ⟶ Z) →ₗ[R] X ⟶ Z where toFun g := f ≫ g map_add' := by simp map_smul' := by simp /-- Composition by a fixed right argument as an `R`-linear map. -/ @[simps] def rightComp (X : C) {Y Z : C} (g : Y ⟶ Z) : (X ⟶ Y) →ₗ[R] X ⟶ Z where toFun f := f ≫ g map_add' := by simp map_smul' := by simp instance {X Y : C} (f : X ⟶ Y) [Epi f] (r : R) [Invertible r] : Epi (r • f) := ⟨fun g g' H => by rw [smul_comp, smul_comp, ← comp_smul, ← comp_smul, cancel_epi] at H simpa [smul_smul] using congr_arg (fun f => ⅟ r • f) H⟩ instance {X Y : C} (f : X ⟶ Y) [Mono f] (r : R) [Invertible r] : Mono (r • f) := ⟨fun g g' H => by rw [comp_smul, comp_smul, ← smul_comp, ← smul_comp, cancel_mono] at H simpa [smul_smul] using congr_arg (fun f => ⅟ r • f) H⟩ /-- Given isomorphic objects `X ≅ Y, W ≅ Z` in a `k`-linear category, we have a `k`-linear isomorphism between `Hom(X, W)` and `Hom(Y, Z).` -/ def homCongr (k : Type*) {C : Type*} [Category C] [Semiring k] [Preadditive C] [Linear k C] {X Y W Z : C} (f₁ : X ≅ Y) (f₂ : W ≅ Z) : (X ⟶ W) ≃ₗ[k] Y ⟶ Z := { (rightComp k Y f₂.hom).comp (leftComp k W f₁.symm.hom) with invFun := (leftComp k W f₁.hom).comp (rightComp k Y f₂.symm.hom) left_inv := fun x => by simp only [Iso.symm_hom, LinearMap.toFun_eq_coe, LinearMap.coe_comp, Function.comp_apply, leftComp_apply, rightComp_apply, Category.assoc, Iso.hom_inv_id, Category.comp_id, Iso.hom_inv_id_assoc] right_inv := fun x => by simp only [Iso.symm_hom, LinearMap.coe_comp, Function.comp_apply, rightComp_apply, leftComp_apply, LinearMap.toFun_eq_coe, Iso.inv_hom_id_assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id] } theorem homCongr_apply (k : Type*) {C : Type*} [Category C] [Semiring k] [Preadditive C] [Linear k C] {X Y W Z : C} (f₁ : X ≅ Y) (f₂ : W ≅ Z) (f : X ⟶ W) : homCongr k f₁ f₂ f = (f₁.inv ≫ f) ≫ f₂.hom := rfl theorem homCongr_symm_apply (k : Type*) {C : Type*} [Category C] [Semiring k] [Preadditive C] [Linear k C] {X Y W Z : C} (f₁ : X ≅ Y) (f₂ : W ≅ Z) (f : Y ⟶ Z) : (homCongr k f₁ f₂).symm f = f₁.hom ≫ f ≫ f₂.inv := rfl variable {R} @[simp] lemma units_smul_comp {X Y Z : C} (r : Rˣ) (f : X ⟶ Y) (g : Y ⟶ Z) : (r • f) ≫ g = r • f ≫ g := by apply Linear.smul_comp @[simp] lemma comp_units_smul {X Y Z : C} (f : X ⟶ Y) (r : Rˣ) (g : Y ⟶ Z) : f ≫ (r • g) = r • f ≫ g := by apply Linear.comp_smul end section variable {S : Type w} [CommSemiring S] [Linear S C] /-- Composition as a bilinear map. -/ @[simps] def comp (X Y Z : C) : (X ⟶ Y) →ₗ[S] (Y ⟶ Z) →ₗ[S] X ⟶ Z where toFun f := leftComp S Z f map_add' := by intros ext simp map_smul' := by intros ext simp end end CategoryTheory.Linear
CategoryTheory\Linear\FunctorCategory.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Preadditive.FunctorCategory import Mathlib.CategoryTheory.Linear.Basic /-! # Linear structure on functor categories If `C` and `D` are categories and `D` is `R`-linear, then `C ⥤ D` is also `R`-linear. -/ namespace CategoryTheory open CategoryTheory.Limits Linear variable {R : Type*} [Semiring R] variable {C D : Type*} [Category C] [Category D] [Preadditive D] [Linear R D] instance functorCategoryLinear : Linear R (C ⥤ D) where homModule F G := { smul := fun r α => { app := fun X => r • α.app X naturality := by intros rw [comp_smul, smul_comp, α.naturality] } one_smul := by intros ext apply one_smul zero_smul := by intros ext apply zero_smul smul_zero := by intros ext apply smul_zero add_smul := by intros ext apply add_smul smul_add := by intros ext apply smul_add mul_smul := by intros ext apply mul_smul } smul_comp := by intros ext apply smul_comp comp_smul := by intros ext apply comp_smul namespace NatTrans variable {F G : C ⥤ D} /-- Application of a natural transformation at a fixed object, as group homomorphism -/ @[simps] def appLinearMap (X : C) : (F ⟶ G) →ₗ[R] F.obj X ⟶ G.obj X where toFun α := α.app X map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem app_smul (X : C) (r : R) (α : F ⟶ G) : (r • α).app X = r • α.app X := rfl end NatTrans end CategoryTheory
CategoryTheory\Linear\LinearFunctor.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Linear.Basic import Mathlib.Algebra.Module.LinearMap.Rat /-! # Linear Functors An additive functor between two `R`-linear categories is called *linear* if the induced map on hom types is a morphism of `R`-modules. # Implementation details `Functor.Linear` is a `Prop`-valued class, defined by saying that for every two objects `X` and `Y`, the map `F.map : (X ⟶ Y) → (F.obj X ⟶ F.obj Y)` is a morphism of `R`-modules. -/ namespace CategoryTheory variable (R : Type*) [Semiring R] /-- An additive functor `F` is `R`-linear provided `F.map` is an `R`-module morphism. -/ class Functor.Linear {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D] [Linear R C] [Linear R D] (F : C ⥤ D) [F.Additive] : Prop where /-- the functor induces a linear map on morphisms -/ map_smul : ∀ {X Y : C} (f : X ⟶ Y) (r : R), F.map (r • f) = r • F.map f := by aesop_cat section Linear namespace Functor section variable {R} variable {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D] [CategoryTheory.Linear R C] [CategoryTheory.Linear R D] (F : C ⥤ D) [Additive F] [Linear R F] @[simp] theorem map_smul {X Y : C} (r : R) (f : X ⟶ Y) : F.map (r • f) = r • F.map f := Functor.Linear.map_smul _ _ @[simp] theorem map_units_smul {X Y : C} (r : Rˣ) (f : X ⟶ Y) : F.map (r • f) = r • F.map f := by apply map_smul instance : Linear R (𝟭 C) where instance {E : Type*} [Category E] [Preadditive E] [CategoryTheory.Linear R E] (G : D ⥤ E) [Additive G] [Linear R G] : Linear R (F ⋙ G) where variable (R) /-- `F.mapLinearMap` is an `R`-linear map whose underlying function is `F.map`. -/ @[simps] def mapLinearMap {X Y : C} : (X ⟶ Y) →ₗ[R] F.obj X ⟶ F.obj Y := { F.mapAddHom with map_smul' := fun r f => F.map_smul r f } theorem coe_mapLinearMap {X Y : C} : ⇑(F.mapLinearMap R : (X ⟶ Y) →ₗ[R] _) = F.map := rfl end section InducedCategory variable {C : Type*} {D : Type*} [Category D] [Preadditive D] [CategoryTheory.Linear R D] (F : C → D) instance inducedFunctorLinear : Functor.Linear R (inducedFunctor F) where end InducedCategory instance fullSubcategoryInclusionLinear {C : Type*} [Category C] [Preadditive C] [CategoryTheory.Linear R C] (Z : C → Prop) : (fullSubcategoryInclusion Z).Linear R where section variable {R} {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D] (F : C ⥤ D) [Additive F] instance natLinear : F.Linear ℕ where map_smul := F.mapAddHom.map_nsmul instance intLinear : F.Linear ℤ where map_smul f r := F.mapAddHom.map_zsmul f r variable [CategoryTheory.Linear ℚ C] [CategoryTheory.Linear ℚ D] instance ratLinear : F.Linear ℚ where map_smul f r := F.mapAddHom.toRatLinearMap.map_smul r f end end Functor namespace Equivalence variable {C D : Type*} [Category C] [Category D] [Preadditive C] [Linear R C] [Preadditive D] [Linear R D] instance inverseLinear (e : C ≌ D) [e.functor.Additive] [e.functor.Linear R] : e.inverse.Linear R where map_smul r f := by apply e.functor.map_injective simp end Equivalence end Linear end CategoryTheory
CategoryTheory\Linear\Yoneda.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Category.ModuleCat.Basic import Mathlib.CategoryTheory.Linear.Basic import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic /-! # The Yoneda embedding for `R`-linear categories The Yoneda embedding for `R`-linear categories `C`, sends an object `X : C` to the `ModuleCat R`-valued presheaf on `C`, with value on `Y : Cᵒᵖ` given by `ModuleCat.of R (unop Y ⟶ X)`. TODO: `linearYoneda R C` is `R`-linear. TODO: In fact, `linearYoneda` itself is additive and `R`-linear. -/ universe w v u open Opposite namespace CategoryTheory variable (R : Type w) [Ring R] {C : Type u} [Category.{v} C] [Preadditive C] [Linear R C] variable (C) -- Porting note: inserted specific `ModuleCat.ofHom` in the definition of `linearYoneda` -- and similarly in `linearCoyoneda`, otherwise many simp lemmas are not triggered automatically. -- Eventually, doing so allows more proofs to be automatic! /-- The Yoneda embedding for `R`-linear categories `C`, sending an object `X : C` to the `ModuleCat R`-valued presheaf on `C`, with value on `Y : Cᵒᵖ` given by `ModuleCat.of R (unop Y ⟶ X)`. -/ @[simps] def linearYoneda : C ⥤ Cᵒᵖ ⥤ ModuleCat R where obj X := { obj := fun Y => ModuleCat.of R (unop Y ⟶ X) map := fun f => ModuleCat.ofHom (Linear.leftComp R _ f.unop) } map {X₁ X₂} f := { app := fun Y => @ModuleCat.ofHom R _ (Y.unop ⟶ X₁) (Y.unop ⟶ X₂) _ _ _ _ (Linear.rightComp R _ f) } /-- The Yoneda embedding for `R`-linear categories `C`, sending an object `Y : Cᵒᵖ` to the `ModuleCat R`-valued copresheaf on `C`, with value on `X : C` given by `ModuleCat.of R (unop Y ⟶ X)`. -/ @[simps] def linearCoyoneda : Cᵒᵖ ⥤ C ⥤ ModuleCat R where obj Y := { obj := fun X => ModuleCat.of R (unop Y ⟶ X) map := fun f => ModuleCat.ofHom (Linear.rightComp R _ f) } map {Y₁ Y₂} f := { app := fun X => @ModuleCat.ofHom R _ (unop Y₁ ⟶ X) (unop Y₂ ⟶ X) _ _ _ _ (Linear.leftComp _ _ f.unop) } instance linearYoneda_obj_additive (X : C) : ((linearYoneda R C).obj X).Additive where instance linearCoyoneda_obj_additive (Y : Cᵒᵖ) : ((linearCoyoneda R C).obj Y).Additive where @[simp] theorem whiskering_linearYoneda : linearYoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R)) = yoneda := rfl @[simp] theorem whiskering_linearYoneda₂ : linearYoneda R C ⋙ (whiskeringRight _ _ _).obj (forget₂ (ModuleCat.{v} R) AddCommGrp.{v}) = preadditiveYoneda := rfl @[simp] theorem whiskering_linearCoyoneda : linearCoyoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R)) = coyoneda := rfl @[simp] theorem whiskering_linearCoyoneda₂ : linearCoyoneda R C ⋙ (whiskeringRight _ _ _).obj (forget₂ (ModuleCat.{v} R) AddCommGrp.{v}) = preadditiveCoyoneda := rfl instance full_linearYoneda : (linearYoneda R C).Full := let _ : Functor.Full (linearYoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) := Yoneda.yoneda_full Functor.Full.of_comp_faithful (linearYoneda R C) ((whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) instance full_linearCoyoneda : (linearCoyoneda R C).Full := let _ : Functor.Full (linearCoyoneda R C ⋙ (whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) := Coyoneda.coyoneda_full Functor.Full.of_comp_faithful (linearCoyoneda R C) ((whiskeringRight _ _ _).obj (forget (ModuleCat.{v} R))) instance faithful_linearYoneda : (linearYoneda R C).Faithful := Functor.Faithful.of_comp_eq (whiskering_linearYoneda R C) instance faithful_linearCoyoneda : (linearCoyoneda R C).Faithful := Functor.Faithful.of_comp_eq (whiskering_linearCoyoneda R C) end CategoryTheory
CategoryTheory\Localization\Adjunction.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.CatCommSq import Mathlib.CategoryTheory.Localization.Predicate import Mathlib.CategoryTheory.Adjunction.FullyFaithful /-! # Localization of adjunctions In this file, we show that if we have an adjunction `adj : G ⊣ F` such that both functors `G : C₁ ⥤ C₂` and `F : C₂ ⥤ C₁` induce functors `G' : D₁ ⥤ D₂` and `F' : D₂ ⥤ D₁` on localized categories, i.e. that we have localization functors `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` with respect to morphism properties `W₁` and `W₂` respectively, and 2-commutative diagrams `[CatCommSq G L₁ L₂ G']` and `[CatCommSq F L₂ L₁ F']`, then we have an induced adjunction `Adjunction.localization L₁ W₁ L₂ W₂ G' F' : G' ⊣ F'`. -/ namespace CategoryTheory open Localization Category namespace Adjunction variable {C₁ C₂ D₁ D₂ : Type*} [Category C₁] [Category C₂] [Category D₁] [Category D₂] {G : C₁ ⥤ C₂} {F : C₂ ⥤ C₁} (adj : G ⊣ F) section variable (L₁ : C₁ ⥤ D₁) (W₁ : MorphismProperty C₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) (W₂ : MorphismProperty C₂) [L₂.IsLocalization W₂] (G' : D₁ ⥤ D₂) (F' : D₂ ⥤ D₁) [CatCommSq G L₁ L₂ G'] [CatCommSq F L₂ L₁ F'] namespace Localization /-- Auxiliary definition of the unit morphism for the adjunction `Adjunction.localization` -/ noncomputable def ε : 𝟭 D₁ ⟶ G' ⋙ F' := by letI : Lifting L₁ W₁ ((G ⋙ F) ⋙ L₁) (G' ⋙ F') := Lifting.mk (CatCommSq.hComp G F L₁ L₂ L₁ G' F').iso'.symm exact Localization.liftNatTrans L₁ W₁ L₁ ((G ⋙ F) ⋙ L₁) (𝟭 D₁) (G' ⋙ F') (whiskerRight adj.unit L₁) lemma ε_app (X₁ : C₁) : (ε adj L₁ W₁ L₂ G' F').app (L₁.obj X₁) = L₁.map (adj.unit.app X₁) ≫ (CatCommSq.iso F L₂ L₁ F').hom.app (G.obj X₁) ≫ F'.map ((CatCommSq.iso G L₁ L₂ G').hom.app X₁) := by letI : Lifting L₁ W₁ ((G ⋙ F) ⋙ L₁) (G' ⋙ F') := Lifting.mk (CatCommSq.hComp G F L₁ L₂ L₁ G' F').iso'.symm simp only [ε, liftNatTrans_app, Lifting.iso, Iso.symm, Functor.id_obj, Functor.comp_obj, Lifting.id_iso', Functor.rightUnitor_hom_app, whiskerRight_app, CatCommSq.hComp_iso'_hom_app, id_comp] /-- Auxiliary definition of the counit morphism for the adjunction `Adjunction.localization` -/ noncomputable def η : F' ⋙ G' ⟶ 𝟭 D₂ := by letI : Lifting L₂ W₂ ((F ⋙ G) ⋙ L₂) (F' ⋙ G') := Lifting.mk (CatCommSq.hComp F G L₂ L₁ L₂ F' G').iso'.symm exact liftNatTrans L₂ W₂ ((F ⋙ G) ⋙ L₂) L₂ (F' ⋙ G') (𝟭 D₂) (whiskerRight adj.counit L₂) lemma η_app (X₂ : C₂) : (η adj L₁ L₂ W₂ G' F').app (L₂.obj X₂) = G'.map ((CatCommSq.iso F L₂ L₁ F').inv.app X₂) ≫ (CatCommSq.iso G L₁ L₂ G').inv.app (F.obj X₂) ≫ L₂.map (adj.counit.app X₂) := by letI : Lifting L₂ W₂ ((F ⋙ G) ⋙ L₂) (F' ⋙ G') := Lifting.mk (CatCommSq.hComp F G L₂ L₁ L₂ F' G').iso'.symm simp only [η, liftNatTrans_app, Lifting.iso, Iso.symm, CatCommSq.hComp_iso'_inv_app, whiskerRight_app, Lifting.id_iso', Functor.rightUnitor_inv_app, comp_id, assoc] end Localization /-- If `adj : G ⊣ F` is an adjunction between two categories `C₁` and `C₂` that are equipped with localization functors `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` with respect to `W₁ : MorphismProperty C₁` and `W₂ : MorphismProperty C₂`, and that the functors `F : C₂ ⥤ C₁` and `G : C₁ ⥤ C₂` induce functors `F' : D₂ ⥤ D₁` and `G' : D₁ ⥤ D₂` on the localized categories, then the adjunction `adj` induces an adjunction `G' ⊣ F'`. -/ noncomputable def localization : G' ⊣ F' := Adjunction.mkOfUnitCounit { unit := Localization.ε adj L₁ W₁ L₂ G' F' counit := Localization.η adj L₁ L₂ W₂ G' F' left_triangle := by apply natTrans_ext L₁ W₁ intro X₁ have eq := congr_app adj.left_triangle X₁ dsimp at eq rw [NatTrans.comp_app, NatTrans.comp_app, whiskerRight_app, Localization.ε_app, Functor.associator_hom_app, id_comp, whiskerLeft_app, G'.map_comp, G'.map_comp, assoc, assoc] erw [(Localization.η adj L₁ L₂ W₂ G' F').naturality, Localization.η_app, assoc, assoc, ← G'.map_comp_assoc, ← G'.map_comp_assoc, assoc, Iso.hom_inv_id_app, comp_id, (CatCommSq.iso G L₁ L₂ G').inv.naturality_assoc, ← L₂.map_comp_assoc, eq, L₂.map_id, id_comp, Iso.inv_hom_id_app] rfl right_triangle := by apply natTrans_ext L₂ W₂ intro X₂ have eq := congr_app adj.right_triangle X₂ dsimp at eq rw [NatTrans.comp_app, NatTrans.comp_app, whiskerLeft_app, whiskerRight_app, Localization.η_app, Functor.associator_inv_app, id_comp, F'.map_comp, F'.map_comp] erw [← (Localization.ε _ _ _ _ _ _).naturality_assoc, Localization.ε_app, assoc, assoc, ← F'.map_comp_assoc, Iso.hom_inv_id_app, F'.map_id, id_comp, ← NatTrans.naturality, ← L₁.map_comp_assoc, eq, L₁.map_id, id_comp, Iso.inv_hom_id_app] rfl } @[simp] lemma localization_unit_app (X₁ : C₁) : (adj.localization L₁ W₁ L₂ W₂ G' F').unit.app (L₁.obj X₁) = L₁.map (adj.unit.app X₁) ≫ (CatCommSq.iso F L₂ L₁ F').hom.app (G.obj X₁) ≫ F'.map ((CatCommSq.iso G L₁ L₂ G').hom.app X₁) := by apply Localization.ε_app @[simp] lemma localization_counit_app (X₂ : C₂) : (adj.localization L₁ W₁ L₂ W₂ G' F').counit.app (L₂.obj X₂) = G'.map ((CatCommSq.iso F L₂ L₁ F').inv.app X₂) ≫ (CatCommSq.iso G L₁ L₂ G').inv.app (F.obj X₂) ≫ L₂.map (adj.counit.app X₂) := by apply Localization.η_app end lemma isLocalization [F.Full] [F.Faithful] : G.IsLocalization ((MorphismProperty.isomorphisms C₂).inverseImage G) := by let W := ((MorphismProperty.isomorphisms C₂).inverseImage G) have hG : W.IsInvertedBy G := fun _ _ _ hf => hf have : ∀ (X : C₁), IsIso ((whiskerRight adj.unit W.Q).app X) := fun X => Localization.inverts W.Q W _ (by change IsIso _ infer_instance) have : IsIso (whiskerRight adj.unit W.Q) := NatIso.isIso_of_isIso_app _ let e : W.Localization ≌ C₂ := Equivalence.mk (Localization.lift G hG W.Q) (F ⋙ W.Q) (liftNatIso W.Q W W.Q (G ⋙ F ⋙ W.Q) _ _ (W.Q.leftUnitor.symm ≪≫ asIso (whiskerRight adj.unit W.Q))) (Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Localization.fac G hG W.Q) ≪≫ asIso adj.counit) apply Functor.IsLocalization.of_equivalence_target W.Q W G e (Localization.fac G hG W.Q) end Adjunction end CategoryTheory
CategoryTheory\Localization\Bousfield.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.ClosedUnderIsomorphisms import Mathlib.CategoryTheory.MorphismProperty.Composition import Mathlib.CategoryTheory.Localization.Adjunction /-! # Bousfield localization Given a predicate `P : C → Prop` on the objects of a category `C`, we define `Localization.LeftBousfield.W P : MorphismProperty C` as the class of morphisms `f : X ⟶ Y` such that for any `Z : C` such that `P Z`, the precomposition with `f` induces a bijection `(Y ⟶ Z) ≃ (X ⟶ Z)`. (This construction is part of left Bousfield localization in the context of model categories.) When `G ⊣ F` is an adjunction with `F : C ⥤ D` fully faithful, then `G : D ⥤ C` is a localization functor for the class `W (· ∈ Set.range F.obj)`, which then identifies to the inverse image by `G` of the class of isomorphisms in `C`. ## References * https://ncatlab.org/nlab/show/left+Bousfield+localization+of+model+categories -/ namespace CategoryTheory open Category namespace Localization variable {C D : Type*} [Category C] [Category D] namespace LeftBousfield section variable (P : C → Prop) /-- Given a predicate `P : C → Prop`, this is the class of morphisms `f : X ⟶ Y` such that for all `Z : C` such that `P Z`, the precomposition with `f` induces a bijection `(Y ⟶ Z) ≃ (X ⟶ Z)`. -/ def W : MorphismProperty C := fun _ _ f => ∀ Z, P Z → Function.Bijective (fun (g : _ ⟶ Z) => f ≫ g) variable {P} in /-- The bijection `(Y ⟶ Z) ≃ (X ⟶ Z)` induced by `f : X ⟶ Y` when `LeftBousfield.W P f` and `P Z`. -/ @[simps! apply] noncomputable def W.homEquiv {X Y : C} {f : X ⟶ Y} (hf : W P f) (Z : C) (hZ : P Z) : (Y ⟶ Z) ≃ (X ⟶ Z) := Equiv.ofBijective _ (hf Z hZ) lemma W_isoClosure : W (isoClosure P) = W P := by ext X Y f constructor · intro hf Z hZ exact hf _ (le_isoClosure _ _ hZ) · rintro hf Z ⟨Z', hZ', ⟨e⟩⟩ constructor · intro g₁ g₂ eq rw [← cancel_mono e.hom] apply (hf _ hZ').1 simp only [reassoc_of% eq] · intro g obtain ⟨a, h⟩ := (hf _ hZ').2 (g ≫ e.hom) exact ⟨a ≫ e.inv, by simp only [reassoc_of% h, e.hom_inv_id, comp_id]⟩ instance : (W P).IsMultiplicative where id_mem X Z _ := by simp [id_comp] exact Function.bijective_id comp_mem f g hf hg Z hZ := by simpa using Function.Bijective.comp (hf Z hZ) (hg Z hZ) instance : (W P).HasTwoOutOfThreeProperty where of_postcomp f g hg hfg Z hZ := by rw [← Function.Bijective.of_comp_iff _ (hg Z hZ)] simpa using hfg Z hZ of_precomp f g hf hfg Z hZ := by rw [← Function.Bijective.of_comp_iff' (hf Z hZ)] simpa using hfg Z hZ lemma W_of_isIso {X Y : C} (f : X ⟶ Y) [IsIso f] : W P f := fun Z _ => by constructor · intro g₁ g₂ _ simpa only [← cancel_epi f] · intro g exact ⟨inv f ≫ g, by simp⟩ lemma W_iff_isIso {X Y : C} (f : X ⟶ Y) (hX : P X) (hY : P Y) : W P f ↔ IsIso f := by constructor · intro hf obtain ⟨g, hg⟩ := (hf _ hX).2 (𝟙 X) exact ⟨g, hg, (hf _ hY).1 (by simp only [reassoc_of% hg, comp_id])⟩ · apply W_of_isIso end section variable {F : C ⥤ D} {G : D ⥤ C} (adj : G ⊣ F) [F.Full] [F.Faithful] lemma W_adj_unit_app (X : D) : W (· ∈ Set.range F.obj) (adj.unit.app X) := by rintro _ ⟨Y, rfl⟩ convert ((Functor.FullyFaithful.ofFullyFaithful F).homEquiv.symm.trans (adj.homEquiv X Y)).bijective using 1 aesop lemma W_iff_isIso_map {X Y : D} (f : X ⟶ Y) : W (· ∈ Set.range F.obj) f ↔ IsIso (G.map f) := by rw [← MorphismProperty.postcomp_iff _ _ _ (W_adj_unit_app adj Y)] erw [adj.unit.naturality f] rw [MorphismProperty.precomp_iff _ _ _ (W_adj_unit_app adj X), W_iff_isIso _ _ ⟨_, rfl⟩ ⟨_, rfl⟩] constructor · intro h dsimp at h exact isIso_of_fully_faithful F (G.map f) · intro rw [Functor.comp_map] infer_instance lemma W_eq_inverseImage_isomorphisms : W (· ∈ Set.range F.obj) = (MorphismProperty.isomorphisms _).inverseImage G := by ext P₁ P₂ f rw [W_iff_isIso_map adj] rfl lemma isLocalization : G.IsLocalization (W (· ∈ Set.range F.obj)) := by rw [W_eq_inverseImage_isomorphisms adj] exact adj.isLocalization end end LeftBousfield end Localization end CategoryTheory
CategoryTheory\Localization\CalculusOfFractions.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Opposite /-! # Calculus of fractions Following the definitions by [Gabriel and Zisman][gabriel-zisman-1967], given a morphism property `W : MorphismProperty C` on a category `C`, we introduce the class `W.HasLeftCalculusOfFractions`. The main result `Localization.exists_leftFraction` is that if `L : C ⥤ D` is a localization functor for `W`, then for any morphism `L.obj X ⟶ L.obj Y` in `D`, there exists an auxiliary object `Y' : C` and morphisms `g : X ⟶ Y'` and `s : Y ⟶ Y'`, with `W s`, such that the given morphism is a sort of fraction `g / s`, or more precisely of the form `L.map g ≫ (Localization.isoOfHom L W s hs).inv`. We also show that the functor `L.mapArrow : Arrow C ⥤ Arrow D` is essentially surjective. Similar results are obtained when `W` has a right calculus of fractions. ## References * [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967] -/ namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] open Category namespace MorphismProperty /-- A left fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the datum of an object `Y' : C` and maps `f : X ⟶ Y'` and `s : Y ⟶ Y'` such that `W s`. -/ structure LeftFraction (W : MorphismProperty C) (X Y : C) where /-- the auxiliary object of a left fraction -/ {Y' : C} /-- the numerator of a left fraction -/ f : X ⟶ Y' /-- the denominator of a left fraction -/ s : Y ⟶ Y' /-- the condition that the denominator belongs to the given morphism property -/ hs : W s namespace LeftFraction variable (W : MorphismProperty C) {X Y : C} /-- The left fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/ @[simps] def ofHom (f : X ⟶ Y) [W.ContainsIdentities] : W.LeftFraction X Y := mk f (𝟙 Y) (W.id_mem Y) variable {W} /-- The left fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/ @[simps] def ofInv (s : Y ⟶ X) (hs : W s) : W.LeftFraction X Y := mk (𝟙 X) s hs /-- If `φ : W.LeftFraction X Y` and `L` is a functor which inverts `W`, this is the induced morphism `L.obj X ⟶ L.obj Y` -/ noncomputable def map (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.obj X ⟶ L.obj Y := have := hL _ φ.hs L.map φ.f ≫ inv (L.map φ.s) @[reassoc (attr := simp)] lemma map_comp_map_s (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : φ.map L hL ≫ L.map φ.s = L.map φ.f := by letI := hL _ φ.hs simp [map] variable (W) lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] : (ofHom W f).map L hL = L.map f := by simp [map] @[reassoc (attr := simp)] lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) : (ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by letI := hL _ hs simp [map] @[reassoc (attr := simp)] lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by letI := hL _ hs simp [map] variable {W} lemma cases (α : W.LeftFraction X Y) : ∃ (Y' : C) (f : X ⟶ Y') (s : Y ⟶ Y') (hs : W s), α = LeftFraction.mk f s hs := ⟨_, _, _, _, rfl⟩ end LeftFraction /-- A right fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the datum of an object `X' : C` and maps `s : X' ⟶ X` and `f : X' ⟶ Y` such that `W s`. -/ structure RightFraction (W : MorphismProperty C) (X Y : C) where /-- the auxiliary object of a right fraction -/ {X' : C} /-- the denominator of a right fraction -/ s : X' ⟶ X /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- the numerator of a right fraction -/ f : X' ⟶ Y namespace RightFraction variable (W : MorphismProperty C) variable {X Y : C} /-- The right fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/ @[simps] def ofHom (f : X ⟶ Y) [W.ContainsIdentities] : W.RightFraction X Y := mk (𝟙 X) (W.id_mem X) f variable {W} /-- The right fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/ @[simps] def ofInv (s : Y ⟶ X) (hs : W s) : W.RightFraction X Y := mk s hs (𝟙 Y) /-- If `φ : W.RightFraction X Y` and `L` is a functor which inverts `W`, this is the induced morphism `L.obj X ⟶ L.obj Y` -/ noncomputable def map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.obj X ⟶ L.obj Y := have := hL _ φ.hs inv (L.map φ.s) ≫ L.map φ.f @[reassoc (attr := simp)] lemma map_s_comp_map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.map φ.s ≫ φ.map L hL = L.map φ.f := by letI := hL _ φ.hs simp [map] variable (W) @[simp] lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] : (ofHom W f).map L hL = L.map f := by simp [map] @[reassoc (attr := simp)] lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) : (ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by letI := hL _ hs simp [map] @[reassoc (attr := simp)] lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by letI := hL _ hs simp [map] variable {W} lemma cases (α : W.RightFraction X Y) : ∃ (X' : C) (s : X' ⟶ X) (hs : W s) (f : X' ⟶ Y) , α = RightFraction.mk s hs f := ⟨_, _, _, _, rfl⟩ end RightFraction variable (W : MorphismProperty C) /-- A multiplicative morphism property `W` has left calculus of fractions if any right fraction can be turned into a left fraction and that two morphisms that can be equalized by precomposition with a morphism in `W` can also be equalized by postcomposition with a morphism in `W`. -/ class HasLeftCalculusOfFractions extends W.IsMultiplicative : Prop where exists_leftFraction ⦃X Y : C⦄ (φ : W.RightFraction X Y) : ∃ (ψ : W.LeftFraction X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f ext : ∀ ⦃X' X Y : C⦄ (f₁ f₂ : X ⟶ Y) (s : X' ⟶ X) (_ : W s) (_ : s ≫ f₁ = s ≫ f₂), ∃ (Y' : C) (t : Y ⟶ Y') (_ : W t), f₁ ≫ t = f₂ ≫ t /-- A multiplicative morphism property `W` has right calculus of fractions if any left fraction can be turned into a right fraction and that two morphisms that can be equalized by postcomposition with a morphism in `W` can also be equalized by precomposition with a morphism in `W`. -/ class HasRightCalculusOfFractions extends W.IsMultiplicative : Prop where exists_rightFraction ⦃X Y : C⦄ (φ : W.LeftFraction X Y) : ∃ (ψ : W.RightFraction X Y), ψ.s ≫ φ.f = ψ.f ≫ φ.s ext : ∀ ⦃X Y Y' : C⦄ (f₁ f₂ : X ⟶ Y) (s : Y ⟶ Y') (_ : W s) (_ : f₁ ≫ s = f₂ ≫ s), ∃ (X' : C) (t : X' ⟶ X) (_ : W t), t ≫ f₁ = t ≫ f₂ variable {W} lemma RightFraction.exists_leftFraction [W.HasLeftCalculusOfFractions] {X Y : C} (φ : W.RightFraction X Y) : ∃ (ψ : W.LeftFraction X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f := HasLeftCalculusOfFractions.exists_leftFraction φ /-- A choice of a left fraction deduced from a right fraction for a morphism property `W` when `W` has left calculus of fractions. -/ noncomputable def RightFraction.leftFraction [W.HasLeftCalculusOfFractions] {X Y : C} (φ : W.RightFraction X Y) : W.LeftFraction X Y := φ.exists_leftFraction.choose @[reassoc] lemma RightFraction.leftFraction_fac [W.HasLeftCalculusOfFractions] {X Y : C} (φ : W.RightFraction X Y) : φ.f ≫ φ.leftFraction.s = φ.s ≫ φ.leftFraction.f := φ.exists_leftFraction.choose_spec lemma LeftFraction.exists_rightFraction [W.HasRightCalculusOfFractions] {X Y : C} (φ : W.LeftFraction X Y) : ∃ (ψ : W.RightFraction X Y), ψ.s ≫ φ.f = ψ.f ≫ φ.s := HasRightCalculusOfFractions.exists_rightFraction φ /-- A choice of a right fraction deduced from a left fraction for a morphism property `W` when `W` has right calculus of fractions. -/ noncomputable def LeftFraction.rightFraction [W.HasRightCalculusOfFractions] {X Y : C} (φ : W.LeftFraction X Y) : W.RightFraction X Y := φ.exists_rightFraction.choose @[reassoc] lemma LeftFraction.rightFraction_fac [W.HasRightCalculusOfFractions] {X Y : C} (φ : W.LeftFraction X Y) : φ.rightFraction.s ≫ φ.f = φ.rightFraction.f ≫ φ.s := φ.exists_rightFraction.choose_spec /-- The equivalence relation on left fractions for a morphism property `W`. -/ def LeftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y) : Prop := ∃ (Z : C) (t₁ : z₁.Y' ⟶ Z) (t₂ : z₂.Y' ⟶ Z) (_ : z₁.s ≫ t₁ = z₂.s ≫ t₂) (_ : z₁.f ≫ t₁ = z₂.f ≫ t₂), W (z₁.s ≫ t₁) namespace LeftFractionRel lemma refl {X Y : C} (z : W.LeftFraction X Y) : LeftFractionRel z z := ⟨z.Y', 𝟙 _, 𝟙 _, rfl, rfl, by simpa only [Category.comp_id] using z.hs⟩ lemma symm {X Y : C} {z₁ z₂ : W.LeftFraction X Y} (h : LeftFractionRel z₁ z₂) : LeftFractionRel z₂ z₁ := by obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h exact ⟨Z, t₂, t₁, hst.symm, hft.symm, by simpa only [← hst] using ht⟩ lemma trans {X Y : C} {z₁ z₂ z₃ : W.LeftFraction X Y} [HasLeftCalculusOfFractions W] (h₁₂ : LeftFractionRel z₁ z₂) (h₂₃ : LeftFractionRel z₂ z₃) : LeftFractionRel z₁ z₃ := by obtain ⟨Z₄, t₁, t₂, hst, hft, ht⟩ := h₁₂ obtain ⟨Z₅, u₂, u₃, hsu, hfu, hu⟩ := h₂₃ obtain ⟨⟨v₄, v₅, hv₅⟩, fac⟩ := HasLeftCalculusOfFractions.exists_leftFraction (RightFraction.mk (z₁.s ≫ t₁) ht (z₃.s ≫ u₃)) simp only [Category.assoc] at fac have eq : z₂.s ≫ u₂ ≫ v₅ = z₂.s ≫ t₂ ≫ v₄ := by simpa only [← reassoc_of% hsu, reassoc_of% hst] using fac obtain ⟨Z₇, w, hw, fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ z₂.hs eq simp only [Category.assoc] at fac' refine ⟨Z₇, t₁ ≫ v₄ ≫ w, u₃ ≫ v₅ ≫ w, ?_, ?_, ?_⟩ · rw [reassoc_of% fac] · rw [reassoc_of% hft, ← fac', reassoc_of% hfu] · rw [← reassoc_of% fac, ← reassoc_of% hsu, ← Category.assoc] exact W.comp_mem _ _ hu (W.comp_mem _ _ hv₅ hw) end LeftFractionRel section variable (W) lemma equivalenceLeftFractionRel [W.HasLeftCalculusOfFractions] (X Y : C) : @_root_.Equivalence (W.LeftFraction X Y) LeftFractionRel where refl := LeftFractionRel.refl symm := LeftFractionRel.symm trans := LeftFractionRel.trans variable {W} namespace LeftFraction open HasLeftCalculusOfFractions /-- Auxiliary definition for the composition of left fractions. -/ @[simp] def comp₀ [W.HasLeftCalculusOfFractions] {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) (z₃ : W.LeftFraction z₁.Y' z₂.Y') : W.LeftFraction X Z := mk (z₁.f ≫ z₃.f) (z₂.s ≫ z₃.s) (W.comp_mem _ _ z₂.hs z₃.hs) /-- The equivalence class of `z₁.comp₀ z₂ z₃` does not depend on the choice of `z₃` provided they satisfy the compatibility `z₂.f ≫ z₃.s = z₁.s ≫ z₃.f`. -/ lemma comp₀_rel [W.HasLeftCalculusOfFractions] {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) (z₃ z₃' : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) (h₃' : z₂.f ≫ z₃'.s = z₁.s ≫ z₃'.f) : LeftFractionRel (z₁.comp₀ z₂ z₃) (z₁.comp₀ z₂ z₃') := by obtain ⟨z₄, fac⟩ := exists_leftFraction (RightFraction.mk z₃.s z₃.hs z₃'.s) dsimp at fac have eq : z₁.s ≫ z₃.f ≫ z₄.f = z₁.s ≫ z₃'.f ≫ z₄.s := by rw [← reassoc_of% h₃, ← reassoc_of% h₃', fac] obtain ⟨Y, t, ht, fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ z₁.hs eq simp only [assoc] at fac' refine ⟨Y, z₄.f ≫ t, z₄.s ≫ t, ?_, ?_, ?_⟩ · simp only [comp₀, assoc, reassoc_of% fac] · simp only [comp₀, assoc, fac'] · simp only [comp₀, assoc, ← reassoc_of% fac] exact W.comp_mem _ _ z₂.hs (W.comp_mem _ _ z₃'.hs (W.comp_mem _ _ z₄.hs ht)) variable (W) /-- The morphisms in the constructed localized category for a morphism property `W` that has left calculus of fractions are equivalence classes of left fractions. -/ def Localization.Hom (X Y : C) := Quot (LeftFractionRel : W.LeftFraction X Y → W.LeftFraction X Y → Prop) variable {W} /-- The morphism in the constructed localized category that is induced by a left fraction. -/ def Localization.Hom.mk {X Y : C} (z : W.LeftFraction X Y) : Localization.Hom W X Y := Quot.mk _ z lemma Localization.Hom.mk_surjective {X Y : C} (f : Localization.Hom W X Y) : ∃ (z : W.LeftFraction X Y), f = mk z := by obtain ⟨z⟩ := f exact ⟨z, rfl⟩ variable [W.HasLeftCalculusOfFractions] /-- Auxiliary definition towards the definition of the composition of morphisms in the constructed localized category for a morphism property that has left calculus of fractions. -/ noncomputable def comp {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) : Localization.Hom W X Z := Localization.Hom.mk (z₁.comp₀ z₂ (RightFraction.mk z₁.s z₁.hs z₂.f).leftFraction) lemma comp_eq {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) (z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) : z₁.comp z₂ = Localization.Hom.mk (z₁.comp₀ z₂ z₃) := Quot.sound (LeftFraction.comp₀_rel _ _ _ _ (RightFraction.leftFraction_fac (RightFraction.mk z₁.s z₁.hs z₂.f)) h₃) namespace Localization /-- Composition of morphisms in the constructed localized category for a morphism property that has left calculus of fractions. -/ noncomputable def Hom.comp {X Y Z : C} (z₁ : Hom W X Y) (z₂ : Hom W Y Z) : Hom W X Z := by refine Quot.lift₂ (fun a b => a.comp b) ?_ ?_ z₁ z₂ · rintro a b₁ b₂ ⟨U, t₁, t₂, hst, hft, ht⟩ obtain ⟨z₁, fac₁⟩ := exists_leftFraction (RightFraction.mk a.s a.hs b₁.f) obtain ⟨z₂, fac₂⟩ := exists_leftFraction (RightFraction.mk a.s a.hs b₂.f) obtain ⟨w₁, fac₁'⟩ := exists_leftFraction (RightFraction.mk z₁.s z₁.hs t₁) obtain ⟨w₂, fac₂'⟩ := exists_leftFraction (RightFraction.mk z₂.s z₂.hs t₂) obtain ⟨u, fac₃⟩ := exists_leftFraction (RightFraction.mk w₁.s w₁.hs w₂.s) dsimp at fac₁ fac₂ fac₁' fac₂' fac₃ ⊢ have eq : a.s ≫ z₁.f ≫ w₁.f ≫ u.f = a.s ≫ z₂.f ≫ w₂.f ≫ u.s := by rw [← reassoc_of% fac₁, ← reassoc_of% fac₂, ← reassoc_of% fac₁', ← reassoc_of% fac₂', reassoc_of% hft, fac₃] obtain ⟨Z, p, hp, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a.hs eq simp only [assoc] at fac₄ rw [comp_eq _ _ z₁ fac₁, comp_eq _ _ z₂ fac₂] apply Quot.sound refine ⟨Z, w₁.f ≫ u.f ≫ p, w₂.f ≫ u.s ≫ p, ?_, ?_, ?_⟩ · dsimp simp only [assoc, ← reassoc_of% fac₁', ← reassoc_of% fac₂', reassoc_of% hst, reassoc_of% fac₃] · dsimp simp only [assoc, fac₄] · dsimp simp only [assoc] rw [← reassoc_of% fac₁', ← reassoc_of% fac₃, ← assoc] exact W.comp_mem _ _ ht (W.comp_mem _ _ w₂.hs (W.comp_mem _ _ u.hs hp)) · rintro a₁ a₂ b ⟨U, t₁, t₂, hst, hft, ht⟩ obtain ⟨z₁, fac₁⟩ := exists_leftFraction (RightFraction.mk a₁.s a₁.hs b.f) obtain ⟨z₂, fac₂⟩ := exists_leftFraction (RightFraction.mk a₂.s a₂.hs b.f) obtain ⟨w₁, fac₁'⟩ := exists_leftFraction (RightFraction.mk (a₁.s ≫ t₁) ht (b.f ≫ z₁.s)) obtain ⟨w₂, fac₂'⟩ := exists_leftFraction (RightFraction.mk (a₂.s ≫ t₂) (show W _ by rw [← hst]; exact ht) (b.f ≫ z₂.s)) let p₁ : W.LeftFraction X Z := LeftFraction.mk (a₁.f ≫ t₁ ≫ w₁.f) (b.s ≫ z₁.s ≫ w₁.s) (W.comp_mem _ _ b.hs (W.comp_mem _ _ z₁.hs w₁.hs)) let p₂ : W.LeftFraction X Z := LeftFraction.mk (a₂.f ≫ t₂ ≫ w₂.f) (b.s ≫ z₂.s ≫ w₂.s) (W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs w₂.hs)) dsimp at fac₁ fac₂ fac₁' fac₂' ⊢ simp only [assoc] at fac₁' fac₂' rw [comp_eq _ _ z₁ fac₁, comp_eq _ _ z₂ fac₂] apply Quot.sound refine LeftFractionRel.trans ?_ ((?_ : LeftFractionRel p₁ p₂).trans ?_) · have eq : a₁.s ≫ z₁.f ≫ w₁.s = a₁.s ≫ t₁ ≫ w₁.f := by rw [← fac₁', reassoc_of% fac₁] obtain ⟨Z, u, hu, fac₃⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₁.hs eq simp only [assoc] at fac₃ refine ⟨Z, w₁.s ≫ u, u, ?_, ?_, ?_⟩ · dsimp simp only [assoc] · dsimp simp only [assoc, fac₃] · dsimp simp only [assoc] exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₁.hs (W.comp_mem _ _ w₁.hs hu)) · obtain ⟨q, fac₃⟩ := exists_leftFraction (RightFraction.mk (z₁.s ≫ w₁.s) (W.comp_mem _ _ z₁.hs w₁.hs) (z₂.s ≫ w₂.s)) dsimp at fac₃ simp only [assoc] at fac₃ have eq : a₁.s ≫ t₁ ≫ w₁.f ≫ q.f = a₁.s ≫ t₁ ≫ w₂.f ≫ q.s := by rw [← reassoc_of% fac₁', ← fac₃, reassoc_of% hst, reassoc_of% fac₂'] obtain ⟨Z, u, hu, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₁.hs eq simp only [assoc] at fac₄ refine ⟨Z, q.f ≫ u, q.s ≫ u, ?_, ?_, ?_⟩ · simp only [assoc, reassoc_of% fac₃] · rw [assoc, assoc, assoc, assoc, fac₄, reassoc_of% hft] · simp only [assoc, ← reassoc_of% fac₃] exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs (W.comp_mem _ _ w₂.hs (W.comp_mem _ _ q.hs hu))) · have eq : a₂.s ≫ z₂.f ≫ w₂.s = a₂.s ≫ t₂ ≫ w₂.f := by rw [← fac₂', reassoc_of% fac₂] obtain ⟨Z, u, hu, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₂.hs eq simp only [assoc] at fac₄ refine ⟨Z, u, w₂.s ≫ u, ?_, ?_, ?_⟩ · dsimp simp only [assoc] · dsimp simp only [assoc, fac₄] · dsimp simp only [assoc] exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs (W.comp_mem _ _ w₂.hs hu)) lemma Hom.comp_eq {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) : Hom.comp (mk z₁) (mk z₂) = z₁.comp z₂ := rfl end Localization /-- The constructed localized category for a morphism property that has left calculus of fractions. -/ @[nolint unusedArguments] def Localization (_ : MorphismProperty C) := C namespace Localization noncomputable instance : Category (Localization W) where Hom X Y := Localization.Hom W X Y id X := Localization.Hom.mk (ofHom W (𝟙 _)) comp f g := f.comp g comp_id := by rintro (X Y : C) f obtain ⟨z, rfl⟩ := Hom.mk_surjective f change (Hom.mk z).comp (Hom.mk (ofHom W (𝟙 Y))) = Hom.mk z rw [Hom.comp_eq, comp_eq z (ofHom W (𝟙 Y)) (ofInv z.s z.hs) (by simp)] dsimp [comp₀] simp only [comp_id, id_comp] id_comp := by rintro (X Y : C) f obtain ⟨z, rfl⟩ := Hom.mk_surjective f change (Hom.mk (ofHom W (𝟙 X))).comp (Hom.mk z) = Hom.mk z rw [Hom.comp_eq, comp_eq (ofHom W (𝟙 X)) z (ofHom W z.f) (by simp)] dsimp simp only [comp₀, id_comp, comp_id] assoc := by rintro (X₁ X₂ X₃ X₄ : C) f₁ f₂ f₃ obtain ⟨z₁, rfl⟩ := Hom.mk_surjective f₁ obtain ⟨z₂, rfl⟩ := Hom.mk_surjective f₂ obtain ⟨z₃, rfl⟩ := Hom.mk_surjective f₃ change ((Hom.mk z₁).comp (Hom.mk z₂)).comp (Hom.mk z₃) = (Hom.mk z₁).comp ((Hom.mk z₂).comp (Hom.mk z₃)) rw [Hom.comp_eq z₁ z₂, Hom.comp_eq z₂ z₃] obtain ⟨z₁₂, fac₁₂⟩ := exists_leftFraction (RightFraction.mk z₁.s z₁.hs z₂.f) obtain ⟨z₂₃, fac₂₃⟩ := exists_leftFraction (RightFraction.mk z₂.s z₂.hs z₃.f) obtain ⟨z', fac⟩ := exists_leftFraction (RightFraction.mk z₁₂.s z₁₂.hs z₂₃.f) dsimp at fac₁₂ fac₂₃ fac rw [comp_eq z₁ z₂ z₁₂ fac₁₂, comp_eq z₂ z₃ z₂₃ fac₂₃, comp₀, comp₀, Hom.comp_eq, Hom.comp_eq, comp_eq _ z₃ (mk z'.f (z₂₃.s ≫ z'.s) (W.comp_mem _ _ z₂₃.hs z'.hs)) (by dsimp; rw [assoc, reassoc_of% fac₂₃, fac]), comp_eq z₁ _ (mk (z₁₂.f ≫ z'.f) z'.s z'.hs) (by dsimp; rw [assoc, ← reassoc_of% fac₁₂, fac])] simp variable (W) /-- The localization functor to the constructed localized category for a morphism property that has left calculus of fractions. -/ @[simps obj] def Q : C ⥤ Localization W where obj X := X map f := Hom.mk (ofHom W f) map_id _ := rfl map_comp {X Y Z} f g := by change _ = Hom.comp _ _ rw [Hom.comp_eq, comp_eq (ofHom W f) (ofHom W g) (ofHom W g) (by simp)] simp only [ofHom, comp₀, comp_id] variable {W} /-- The morphism on `Localization W` that is induced by a left fraction. -/ abbrev homMk {X Y : C} (f : W.LeftFraction X Y) : (Q W).obj X ⟶ (Q W).obj Y := Hom.mk f lemma homMk_eq_hom_mk {X Y : C} (f : W.LeftFraction X Y) : homMk f = Hom.mk f := rfl variable (W) lemma Q_map {X Y : C} (f : X ⟶ Y) : (Q W).map f = homMk (ofHom W f) := rfl variable {W} lemma homMk_comp_homMk {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) (z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) : homMk z₁ ≫ homMk z₂ = homMk (z₁.comp₀ z₂ z₃) := by change Hom.comp _ _ = _ erw [Hom.comp_eq, comp_eq z₁ z₂ z₃ h₃] lemma homMk_eq_of_leftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y) (h : LeftFractionRel z₁ z₂) : homMk z₁ = homMk z₂ := Quot.sound h lemma homMk_eq_iff_leftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y) : homMk z₁ = homMk z₂ ↔ LeftFractionRel z₁ z₂ := @Equivalence.quot_mk_eq_iff _ _ (equivalenceLeftFractionRel W X Y) _ _ /-- The morphism in `Localization W` that is the formal inverse of a morphism which belongs to `W`. -/ def Qinv {X Y : C} (s : X ⟶ Y) (hs : W s) : (Q W).obj Y ⟶ (Q W).obj X := homMk (ofInv s hs) lemma Q_map_comp_Qinv {X Y Y' : C} (f : X ⟶ Y') (s : Y ⟶ Y') (hs : W s) : (Q W).map f ≫ Qinv s hs = homMk (mk f s hs) := by dsimp only [Q_map, Qinv] rw [homMk_comp_homMk (ofHom W f) (ofInv s hs) (ofHom W (𝟙 _)) (by simp)] simp /-- The isomorphism in `Localization W` that is induced by a morphism in `W`. -/ @[simps] def Qiso {X Y : C} (s : X ⟶ Y) (hs : W s) : (Q W).obj X ≅ (Q W).obj Y where hom := (Q W).map s inv := Qinv s hs hom_inv_id := by rw [Q_map_comp_Qinv] apply homMk_eq_of_leftFractionRel exact ⟨_, 𝟙 Y, s, by simp, by simp, by simpa using hs⟩ inv_hom_id := by dsimp only [Qinv, Q_map] rw [homMk_comp_homMk (ofInv s hs) (ofHom W s) (ofHom W (𝟙 Y)) (by simp)] apply homMk_eq_of_leftFractionRel exact ⟨_, 𝟙 Y, 𝟙 Y, by simp, by simp, by simpa using W.id_mem Y⟩ @[reassoc (attr := simp)] lemma Qiso_hom_inv_id {X Y : C} (s : X ⟶ Y) (hs : W s) : (Q W).map s ≫ Qinv s hs = 𝟙 _ := (Qiso s hs).hom_inv_id @[reassoc (attr := simp)] lemma Qiso_inv_hom_id {X Y : C} (s : X ⟶ Y) (hs : W s) : Qinv s hs ≫ (Q W).map s = 𝟙 _ := (Qiso s hs).inv_hom_id instance {X Y : C} (s : X ⟶ Y) (hs : W s) : IsIso (Qinv s hs) := (inferInstance : IsIso (Qiso s hs).inv) section variable {E : Type*} [Category E] /-- The image by a functor which inverts `W` of an equivalence class of left fractions. -/ noncomputable def Hom.map {X Y : C} (f : Hom W X Y) (F : C ⥤ E) (hF : W.IsInvertedBy F) : F.obj X ⟶ F.obj Y := Quot.lift (fun f => f.map F hF) (by intro a₁ a₂ ⟨Z, t₁, t₂, hst, hft, h⟩ dsimp have := hF _ h rw [← cancel_mono (F.map (a₁.s ≫ t₁)), F.map_comp, map_comp_map_s_assoc, ← F.map_comp, ← F.map_comp, hst, hft, F.map_comp, F.map_comp, map_comp_map_s_assoc]) f @[simp] lemma Hom.map_mk {W} {X Y : C} (f : LeftFraction W X Y) (F : C ⥤ E) (hF : W.IsInvertedBy F) : Hom.map (Hom.mk f) F hF = f.map F hF := rfl namespace StrictUniversalPropertyFixedTarget variable (W) lemma inverts : W.IsInvertedBy (Q W) := fun _ _ s hs => (inferInstance : IsIso (Qiso s hs).hom) variable {W} /-- The functor `Localization W ⥤ E` that is induced by a functor `C ⥤ E` which inverts `W`, when `W` has a left calculus of fractions. -/ noncomputable def lift (F : C ⥤ E) (hF : W.IsInvertedBy F) : Localization W ⥤ E where obj X := F.obj X map {X Y : C} f := f.map F hF map_id := by intro (X : C) dsimp change (Hom.mk (ofHom W (𝟙 X))).map F hF = _ rw [Hom.map_mk, map_ofHom, F.map_id] map_comp := by rintro (X Y Z : C) f g obtain ⟨f, rfl⟩ := Hom.mk_surjective f obtain ⟨g, rfl⟩ := Hom.mk_surjective g dsimp obtain ⟨z, fac⟩ := HasLeftCalculusOfFractions.exists_leftFraction (RightFraction.mk f.s f.hs g.f) rw [homMk_comp_homMk f g z fac, Hom.map_mk] dsimp at fac ⊢ have := hF _ g.hs have := hF _ z.hs rw [← cancel_mono (F.map g.s), assoc, map_comp_map_s, ← cancel_mono (F.map z.s), assoc, assoc, ← F.map_comp, ← F.map_comp, map_comp_map_s, fac] dsimp rw [F.map_comp, F.map_comp, map_comp_map_s_assoc] lemma fac (F : C ⥤ E) (hF : W.IsInvertedBy F) : Q W ⋙ lift F hF = F := Functor.ext (fun X => rfl) (fun X Y f => by dsimp [lift] rw [Q_map, Hom.map_mk, id_comp, comp_id, map_ofHom]) lemma uniq (F₁ F₂ : Localization W ⥤ E) (h : Q W ⋙ F₁ = Q W ⋙ F₂) : F₁ = F₂ := Functor.ext (fun X => Functor.congr_obj h X) (by rintro (X Y : C) f obtain ⟨f, rfl⟩ := Hom.mk_surjective f rw [show Hom.mk f = homMk (mk f.f f.s f.hs) by rfl, ← Q_map_comp_Qinv f.f f.s f.hs, F₁.map_comp, F₂.map_comp, assoc] erw [Functor.congr_hom h f.f] rw [assoc, assoc] congr 2 have := inverts W _ f.hs rw [← cancel_epi (F₂.map ((Q W).map f.s)), ← F₂.map_comp_assoc, Qiso_hom_inv_id, Functor.map_id, id_comp] erw [Functor.congr_hom h.symm f.s] dsimp rw [assoc, assoc, eqToHom_trans_assoc, eqToHom_refl, id_comp, ← F₁.map_comp, Qiso_hom_inv_id] dsimp rw [F₁.map_id, comp_id]) end StrictUniversalPropertyFixedTarget variable (W) open StrictUniversalPropertyFixedTarget in /-- The universal property of the localization for the constructed localized category when there is a left calculus of fractions. -/ noncomputable def strictUniversalPropertyFixedTarget (E : Type*) [Category E] : Localization.StrictUniversalPropertyFixedTarget (Q W) W E where inverts := inverts W lift := lift fac := fac uniq := uniq instance : (Q W).IsLocalization W := Functor.IsLocalization.mk' _ _ (strictUniversalPropertyFixedTarget W _) (strictUniversalPropertyFixedTarget W _) end lemma homMk_eq {X Y : C} (f : LeftFraction W X Y) : homMk f = f.map (Q W) (Localization.inverts _ W) := by have := Localization.inverts (Q W) W f.s f.hs rw [← Q_map_comp_Qinv f.f f.s f.hs, ← cancel_mono ((Q W).map f.s), assoc, Qiso_inv_hom_id, comp_id, map_comp_map_s] lemma map_eq_iff {X Y : C} (f g : LeftFraction W X Y) : f.map (LeftFraction.Localization.Q W) (Localization.inverts _ _) = g.map (LeftFraction.Localization.Q W) (Localization.inverts _ _) ↔ LeftFractionRel f g := by simp only [← Hom.map_mk _ (Q W)] constructor · intro h rw [← homMk_eq_iff_leftFractionRel, homMk_eq, homMk_eq] exact h · intro h congr 1 exact Quot.sound h end Localization section lemma map_eq {W} {X Y : C} (φ : W.LeftFraction X Y) (L : C ⥤ D) [L.IsLocalization W] : φ.map L (Localization.inverts L W) = L.map φ.f ≫ (Localization.isoOfHom L W φ.s φ.hs).inv := rfl lemma map_compatibility {W} {X Y : C} (φ : W.LeftFraction X Y) {E : Type*} [Category E] (L₁ : C ⥤ D) (L₂ : C ⥤ E) [L₁.IsLocalization W] [L₂.IsLocalization W] : (Localization.uniq L₁ L₂ W).functor.map (φ.map L₁ (Localization.inverts L₁ W)) = (Localization.compUniqFunctor L₁ L₂ W).hom.app X ≫ φ.map L₂ (Localization.inverts L₂ W) ≫ (Localization.compUniqFunctor L₁ L₂ W).inv.app Y := by let e := Localization.compUniqFunctor L₁ L₂ W have := Localization.inverts L₂ W φ.s φ.hs rw [← cancel_mono (e.hom.app Y), assoc, assoc, e.inv_hom_id_app, comp_id, ← cancel_mono (L₂.map φ.s), assoc, assoc, map_comp_map_s, ← e.hom.naturality] simpa [← Functor.map_comp_assoc, map_comp_map_s] using e.hom.naturality φ.f lemma map_eq_of_map_eq {W} {X Y : C} (φ₁ φ₂ : W.LeftFraction X Y) {E : Type*} [Category E] (L₁ : C ⥤ D) (L₂ : C ⥤ E) [L₁.IsLocalization W] [L₂.IsLocalization W] (h : φ₁.map L₁ (Localization.inverts L₁ W) = φ₂.map L₁ (Localization.inverts L₁ W)) : φ₁.map L₂ (Localization.inverts L₂ W) = φ₂.map L₂ (Localization.inverts L₂ W) := by apply (Localization.uniq L₂ L₁ W).functor.map_injective rw [map_compatibility φ₁ L₂ L₁, map_compatibility φ₂ L₂ L₁, h] lemma map_comp_map_eq_map {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) (z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) (L : C ⥤ D) [L.IsLocalization W] : z₁.map L (Localization.inverts L W) ≫ z₂.map L (Localization.inverts L W) = (z₁.comp₀ z₂ z₃).map L (Localization.inverts L W) := by have := Localization.inverts L W _ z₂.hs have := Localization.inverts L W _ z₃.hs have : IsIso (L.map (z₂.s ≫ z₃.s)) := by rw [L.map_comp] infer_instance dsimp [LeftFraction.comp₀] rw [← cancel_mono (L.map (z₂.s ≫ z₃.s)), map_comp_map_s, L.map_comp, assoc, map_comp_map_s_assoc, ← L.map_comp, h₃, L.map_comp, map_comp_map_s_assoc, L.map_comp] end end LeftFraction end end MorphismProperty variable (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] section variable [W.HasLeftCalculusOfFractions] lemma Localization.exists_leftFraction {X Y : C} (f : L.obj X ⟶ L.obj Y) : ∃ (φ : W.LeftFraction X Y), f = φ.map L (Localization.inverts L W) := by let E := Localization.uniq (MorphismProperty.LeftFraction.Localization.Q W) L W let e : _ ⋙ E.functor ≅ L := Localization.compUniqFunctor _ _ _ obtain ⟨f', rfl⟩ : ∃ (f' : E.functor.obj X ⟶ E.functor.obj Y), f = e.inv.app _ ≫ f' ≫ e.hom.app _ := ⟨e.hom.app _ ≫ f ≫ e.inv.app _, by simp⟩ obtain ⟨g, rfl⟩ := E.functor.map_surjective f' obtain ⟨g, rfl⟩ := MorphismProperty.LeftFraction.Localization.Hom.mk_surjective g refine ⟨g, ?_⟩ rw [← MorphismProperty.LeftFraction.Localization.homMk_eq_hom_mk, MorphismProperty.LeftFraction.Localization.homMk_eq g, g.map_compatibility (MorphismProperty.LeftFraction.Localization.Q W) L, assoc, assoc, Iso.inv_hom_id_app, comp_id, Iso.inv_hom_id_app_assoc] lemma MorphismProperty.LeftFraction.map_eq_iff {X Y : C} (φ ψ : W.LeftFraction X Y) : φ.map L (Localization.inverts _ _) = ψ.map L (Localization.inverts _ _) ↔ LeftFractionRel φ ψ := by constructor · intro h rw [← MorphismProperty.LeftFraction.Localization.map_eq_iff] apply map_eq_of_map_eq _ _ _ _ h · intro h simp only [← Localization.Hom.map_mk _ L (Localization.inverts _ _)] congr 1 exact Quot.sound h lemma MorphismProperty.map_eq_iff_postcomp {X Y : C} (f₁ f₂ : X ⟶ Y) : L.map f₁ = L.map f₂ ↔ ∃ (Z : C) (s : Y ⟶ Z) (_ : W s), f₁ ≫ s = f₂ ≫ s := by constructor · intro h rw [← LeftFraction.map_ofHom W _ L (Localization.inverts _ _), ← LeftFraction.map_ofHom W _ L (Localization.inverts _ _), LeftFraction.map_eq_iff] at h obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h dsimp at t₁ t₂ hst hft ht simp only [id_comp] at hst exact ⟨Z, t₁, by simpa using ht, by rw [hft, hst]⟩ · rintro ⟨Z, s, hs, fac⟩ simp only [← cancel_mono (Localization.isoOfHom L W s hs).hom, Localization.isoOfHom_hom, ← L.map_comp, fac] lemma Localization.essSurj_mapArrow : L.mapArrow.EssSurj where mem_essImage f := by have := Localization.essSurj L W obtain ⟨X, ⟨eX⟩⟩ : ∃ (X : C), Nonempty (L.obj X ≅ f.left) := ⟨_, ⟨L.objObjPreimageIso f.left⟩⟩ obtain ⟨Y, ⟨eY⟩⟩ : ∃ (Y : C), Nonempty (L.obj Y ≅ f.right) := ⟨_, ⟨L.objObjPreimageIso f.right⟩⟩ obtain ⟨φ, hφ⟩ := Localization.exists_leftFraction L W (eX.hom ≫ f.hom ≫ eY.inv) refine ⟨Arrow.mk φ.f, ⟨Iso.symm ?_⟩⟩ refine Arrow.isoMk eX.symm (eY.symm ≪≫ Localization.isoOfHom L W φ.s φ.hs) ?_ dsimp simp only [← cancel_epi eX.hom, Iso.hom_inv_id_assoc, reassoc_of% hφ, MorphismProperty.LeftFraction.map_comp_map_s] end namespace MorphismProperty variable {W} /-- The right fraction in the opposite category corresponding to a left fraction. -/ @[simps] def LeftFraction.op {X Y : C} (φ : W.LeftFraction X Y) : W.op.RightFraction (Opposite.op Y) (Opposite.op X) where X' := Opposite.op φ.Y' s := φ.s.op hs := φ.hs f := φ.f.op /-- The left fraction in the opposite category corresponding to a right fraction. -/ @[simps] def RightFraction.op {X Y : C} (φ : W.RightFraction X Y) : W.op.LeftFraction (Opposite.op Y) (Opposite.op X) where Y' := Opposite.op φ.X' s := φ.s.op hs := φ.hs f := φ.f.op /-- The right fraction corresponding to a left fraction in the opposite category. -/ @[simps] def LeftFraction.unop {W : MorphismProperty Cᵒᵖ} {X Y : Cᵒᵖ} (φ : W.LeftFraction X Y) : W.unop.RightFraction (Opposite.unop Y) (Opposite.unop X) where X' := Opposite.unop φ.Y' s := φ.s.unop hs := φ.hs f := φ.f.unop /-- The left fraction corresponding to a right fraction in the opposite category. -/ @[simps] def RightFraction.unop {W : MorphismProperty Cᵒᵖ} {X Y : Cᵒᵖ} (φ : W.RightFraction X Y) : W.unop.LeftFraction (Opposite.unop Y) (Opposite.unop X) where Y' := Opposite.unop φ.X' s := φ.s.unop hs := φ.hs f := φ.f.unop lemma RightFraction.op_map {X Y : C} (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : (φ.map L hL).op = φ.op.map L.op hL.op := by dsimp [map, LeftFraction.map] rw [op_inv] lemma LeftFraction.op_map {X Y : C} (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : (φ.map L hL).op = φ.op.map L.op hL.op := by dsimp [map, RightFraction.map] rw [op_inv] instance [h : W.HasLeftCalculusOfFractions] : W.op.HasRightCalculusOfFractions where exists_rightFraction X Y φ := by obtain ⟨ψ, eq⟩ := h.exists_leftFraction φ.unop exact ⟨ψ.op, Quiver.Hom.unop_inj eq⟩ ext X Y Y' f₁ f₂ s hs eq := by obtain ⟨X', t, ht, fac⟩ := h.ext f₁.unop f₂.unop s.unop hs (Quiver.Hom.op_inj eq) exact ⟨Opposite.op X', t.op, ht, Quiver.Hom.unop_inj fac⟩ instance [h : W.HasRightCalculusOfFractions] : W.op.HasLeftCalculusOfFractions where exists_leftFraction X Y φ := by obtain ⟨ψ, eq⟩ := h.exists_rightFraction φ.unop exact ⟨ψ.op, Quiver.Hom.unop_inj eq⟩ ext X' X Y f₁ f₂ s hs eq := by obtain ⟨Y', t, ht, fac⟩ := h.ext f₁.unop f₂.unop s.unop hs (Quiver.Hom.op_inj eq) exact ⟨Opposite.op Y', t.op, ht, Quiver.Hom.unop_inj fac⟩ instance (W : MorphismProperty Cᵒᵖ) [h : W.HasLeftCalculusOfFractions] : W.unop.HasRightCalculusOfFractions where exists_rightFraction X Y φ := by obtain ⟨ψ, eq⟩ := h.exists_leftFraction φ.op exact ⟨ψ.unop, Quiver.Hom.op_inj eq⟩ ext X Y Y' f₁ f₂ s hs eq := by obtain ⟨X', t, ht, fac⟩ := h.ext f₁.op f₂.op s.op hs (Quiver.Hom.unop_inj eq) exact ⟨Opposite.unop X', t.unop, ht, Quiver.Hom.op_inj fac⟩ instance (W : MorphismProperty Cᵒᵖ) [h : W.HasRightCalculusOfFractions] : W.unop.HasLeftCalculusOfFractions where exists_leftFraction X Y φ := by obtain ⟨ψ, eq⟩ := h.exists_rightFraction φ.op exact ⟨ψ.unop, Quiver.Hom.op_inj eq⟩ ext X' X Y f₁ f₂ s hs eq := by obtain ⟨Y', t, ht, fac⟩ := h.ext f₁.op f₂.op s.op hs (Quiver.Hom.unop_inj eq) exact ⟨Opposite.unop Y', t.unop, ht, Quiver.Hom.op_inj fac⟩ /-- The equivalence relation on right fractions for a morphism property `W`. -/ def RightFractionRel {X Y : C} (z₁ z₂ : W.RightFraction X Y) : Prop := ∃ (Z : C) (t₁ : Z ⟶ z₁.X') (t₂ : Z ⟶ z₂.X') (_ : t₁ ≫ z₁.s = t₂ ≫ z₂.s) (_ : t₁ ≫ z₁.f = t₂ ≫ z₂.f), W (t₁ ≫ z₁.s) lemma RightFractionRel.op {X Y : C} {z₁ z₂ : W.RightFraction X Y} (h : RightFractionRel z₁ z₂) : LeftFractionRel z₁.op z₂.op := by obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h exact ⟨Opposite.op Z, t₁.op, t₂.op, Quiver.Hom.unop_inj hs, Quiver.Hom.unop_inj hf, ht⟩ lemma RightFractionRel.unop {W : MorphismProperty Cᵒᵖ} {X Y : Cᵒᵖ} {z₁ z₂ : W.RightFraction X Y} (h : RightFractionRel z₁ z₂) : LeftFractionRel z₁.unop z₂.unop := by obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h exact ⟨Opposite.unop Z, t₁.unop, t₂.unop, Quiver.Hom.op_inj hs, Quiver.Hom.op_inj hf, ht⟩ lemma LeftFractionRel.op {X Y : C} {z₁ z₂ : W.LeftFraction X Y} (h : LeftFractionRel z₁ z₂) : RightFractionRel z₁.op z₂.op := by obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h exact ⟨Opposite.op Z, t₁.op, t₂.op, Quiver.Hom.unop_inj hs, Quiver.Hom.unop_inj hf, ht⟩ lemma LeftFractionRel.unop {W : MorphismProperty Cᵒᵖ} {X Y : Cᵒᵖ} {z₁ z₂ : W.LeftFraction X Y} (h : LeftFractionRel z₁ z₂) : RightFractionRel z₁.unop z₂.unop := by obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h exact ⟨Opposite.unop Z, t₁.unop, t₂.unop, Quiver.Hom.op_inj hs, Quiver.Hom.op_inj hf, ht⟩ lemma leftFractionRel_op_iff {X Y : C} (z₁ z₂ : W.RightFraction X Y) : LeftFractionRel z₁.op z₂.op ↔ RightFractionRel z₁ z₂ := ⟨fun h => h.unop, fun h => h.op⟩ lemma rightFractionRel_op_iff {X Y : C} (z₁ z₂ : W.LeftFraction X Y) : RightFractionRel z₁.op z₂.op ↔ LeftFractionRel z₁ z₂ := ⟨fun h => h.unop, fun h => h.op⟩ namespace RightFractionRel lemma refl {X Y : C} (z : W.RightFraction X Y) : RightFractionRel z z := (LeftFractionRel.refl z.op).unop lemma symm {X Y : C} {z₁ z₂ : W.RightFraction X Y} (h : RightFractionRel z₁ z₂) : RightFractionRel z₂ z₁ := h.op.symm.unop lemma trans {X Y : C} {z₁ z₂ z₃ : W.RightFraction X Y} [HasRightCalculusOfFractions W] (h₁₂ : RightFractionRel z₁ z₂) (h₂₃ : RightFractionRel z₂ z₃) : RightFractionRel z₁ z₃ := (h₁₂.op.trans h₂₃.op).unop end RightFractionRel lemma equivalenceRightFractionRel (X Y : C) [HasRightCalculusOfFractions W] : @_root_.Equivalence (W.RightFraction X Y) RightFractionRel where refl := RightFractionRel.refl symm := RightFractionRel.symm trans := RightFractionRel.trans end MorphismProperty section variable [W.HasRightCalculusOfFractions] lemma Localization.exists_rightFraction {X Y : C} (f : L.obj X ⟶ L.obj Y) : ∃ (φ : W.RightFraction X Y), f = φ.map L (Localization.inverts L W) := by obtain ⟨φ, eq⟩ := Localization.exists_leftFraction L.op W.op f.op refine ⟨φ.unop, Quiver.Hom.op_inj ?_⟩ rw [eq, MorphismProperty.RightFraction.op_map] rfl lemma MorphismProperty.RightFraction.map_eq_iff {X Y : C} (φ ψ : W.RightFraction X Y) : φ.map L (Localization.inverts _ _) = ψ.map L (Localization.inverts _ _) ↔ RightFractionRel φ ψ := by rw [← leftFractionRel_op_iff, ← LeftFraction.map_eq_iff L.op W.op φ.op ψ.op, ← φ.op_map L (Localization.inverts _ _), ← ψ.op_map L (Localization.inverts _ _)] constructor · apply Quiver.Hom.unop_inj · apply Quiver.Hom.op_inj lemma MorphismProperty.map_eq_iff_precomp {Y Z : C} (f₁ f₂ : Y ⟶ Z) : L.map f₁ = L.map f₂ ↔ ∃ (X : C) (s : X ⟶ Y) (_ : W s), s ≫ f₁ = s ≫ f₂ := by constructor · intro h rw [← RightFraction.map_ofHom W _ L (Localization.inverts _ _), ← RightFraction.map_ofHom W _ L (Localization.inverts _ _), RightFraction.map_eq_iff] at h obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h dsimp at t₁ t₂ hst hft ht simp only [comp_id] at hst exact ⟨Z, t₁, by simpa using ht, by rw [hft, hst]⟩ · rintro ⟨Z, s, hs, fac⟩ simp only [← cancel_epi (Localization.isoOfHom L W s hs).hom, Localization.isoOfHom_hom, ← L.map_comp, fac] lemma Localization.essSurj_mapArrow_of_hasRightCalculusOfFractions : L.mapArrow.EssSurj where mem_essImage f := by have := Localization.essSurj_mapArrow L.op W.op obtain ⟨g, ⟨e⟩⟩ : ∃ (g : _), Nonempty (L.op.mapArrow.obj g ≅ Arrow.mk f.hom.op) := ⟨_, ⟨Functor.objObjPreimageIso _ _⟩⟩ exact ⟨Arrow.mk g.hom.unop, ⟨Arrow.isoMk (Arrow.rightFunc.mapIso e.symm).unop (Arrow.leftFunc.mapIso e.symm).unop (Quiver.Hom.op_inj e.inv.w.symm)⟩⟩ end end CategoryTheory
CategoryTheory\Localization\Composition.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.LocalizerMorphism /-! # Composition of localization functors Given two composable functors `L₁ : C₁ ⥤ C₂` and `L₂ : C₂ ⥤ C₃`, it is shown in this file that under some suitable conditions on `W₁ : MorphismProperty C₁` `W₂ : MorphismProperty C₂` and `W₃ : MorphismProperty C₁`, then if `L₁ : C₁ ⥤ C₂` is a localization functor for `W₁`, then the composition `L₁ ⋙ L₂ : C₁ ⥤ C₃` is a localization functor for `W₃` if and only if `L₂ : C₂ ⥤ C₃` is a localization functor for `W₂`. The two implications are the lemmas `Functor.IsLocalization.comp` and `Functor.IsLocalization.of_comp`. -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace CategoryTheory variable {C₁ : Type u₁} {C₂ : Type u₂} {C₃ : Type u₃} {E : Type u₄} [Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} C₃] [Category.{v₄} E] {L₁ : C₁ ⥤ C₂} {L₂ : C₂ ⥤ C₃} {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} namespace Localization /-- Under some conditions on the `MorphismProperty`, functors satisfying the strict universal property of the localization are stable under composition -/ def StrictUniversalPropertyFixedTarget.comp (h₁ : StrictUniversalPropertyFixedTarget L₁ W₁ E) (h₂ : StrictUniversalPropertyFixedTarget L₂ W₂ E) (W₃ : MorphismProperty C₁) (hW₃ : W₃.IsInvertedBy (L₁ ⋙ L₂)) (hW₁₃ : W₁ ≤ W₃) (hW₂₃ : W₂ ≤ W₃.map L₁) : StrictUniversalPropertyFixedTarget (L₁ ⋙ L₂) W₃ E where inverts := hW₃ lift F hF := h₂.lift (h₁.lift F (MorphismProperty.IsInvertedBy.of_le _ _ F hF hW₁₃)) (by refine MorphismProperty.IsInvertedBy.of_le _ _ _ ?_ hW₂₃ simpa only [MorphismProperty.IsInvertedBy.map_iff, h₁.fac F] using hF) fac F hF := by rw [Functor.assoc, h₂.fac, h₁.fac] uniq F₁ F₂ h := h₂.uniq _ _ (h₁.uniq _ _ (by simpa only [Functor.assoc] using h)) end Localization open Localization namespace Functor namespace IsLocalization variable (L₁ W₁ L₂ W₂) lemma comp [L₁.IsLocalization W₁] [L₂.IsLocalization W₂] (W₃ : MorphismProperty C₁) (hW₃ : W₃.IsInvertedBy (L₁ ⋙ L₂)) (hW₁₃ : W₁ ≤ W₃) (hW₂₃ : W₂ ≤ W₃.map L₁) : (L₁ ⋙ L₂).IsLocalization W₃ := by -- The proof proceeds by reducing to the case of the constructed -- localized categories, which satisfy the strict universal property -- of the localization. In order to do this, we introduce -- an equivalence of categories `E₂ : C₂ ≅ W₁.Localization`. Via -- this equivalence, we introduce `W₂' : MorphismProperty W₁.Localization` -- which corresponds to `W₂` via the equivalence `E₂`. -- Then, we have a localizer morphism `Φ : LocalizerMorphism W₂ W₂'` which -- is a localized equivalence (because `E₂` is an equivalence). let E₂ := Localization.uniq L₁ W₁.Q W₁ let W₂' := W₂.map E₂.functor let Φ : LocalizerMorphism W₂ W₂' := { functor := E₂.functor map := by have eq := W₂.isoClosure.inverseImage_map_eq_of_isEquivalence E₂.functor rw [MorphismProperty.map_isoClosure] at eq rw [eq] apply W₂.le_isoClosure } have := LocalizerMorphism.IsLocalizedEquivalence.of_equivalence Φ (by rfl) -- The fact that `Φ` is a localized equivalence allows to consider -- the induced equivalence of categories `E₃ : C₃ ≅ W₂'.Localization`, and -- the isomorphism `iso : (W₁.Q ⋙ W₂'.Q) ⋙ E₃.inverse ≅ L₁ ⋙ L₂` let E₃ := (Φ.localizedFunctor L₂ W₂'.Q).asEquivalence let iso : (W₁.Q ⋙ W₂'.Q) ⋙ E₃.inverse ≅ L₁ ⋙ L₂ := by calc _ ≅ L₁ ⋙ E₂.functor ⋙ W₂'.Q ⋙ E₃.inverse := Functor.associator _ _ _ ≪≫ isoWhiskerRight (compUniqFunctor L₁ W₁.Q W₁).symm _ ≪≫ Functor.associator _ _ _ _ ≅ L₁ ⋙ L₂ ⋙ E₃.functor ⋙ E₃.inverse := isoWhiskerLeft _ ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (Φ.catCommSq L₂ W₂'.Q).iso E₃.inverse ≪≫ Functor.associator _ _ _) _ ≅ L₁ ⋙ L₂ := isoWhiskerLeft _ (isoWhiskerLeft _ E₃.unitIso.symm ≪≫ L₂.rightUnitor) -- In order to show `(W₁.Q ⋙ W₂'.Q).IsLocalization W₃`, we need -- to check the assumptions of `StrictUniversalPropertyFixedTarget.comp` have hW₃' : W₃.IsInvertedBy (W₁.Q ⋙ W₂'.Q) := by simpa only [← MorphismProperty.IsInvertedBy.iff_comp _ _ E₃.inverse, MorphismProperty.IsInvertedBy.iff_of_iso W₃ iso] using hW₃ have hW₂₃' : W₂' ≤ W₃.map W₁.Q := (MorphismProperty.monotone_map E₂.functor hW₂₃).trans (by simpa only [W₃.map_map] using le_of_eq (W₃.map_eq_of_iso (compUniqFunctor L₁ W₁.Q W₁))) have : (W₁.Q ⋙ W₂'.Q).IsLocalization W₃ := by refine IsLocalization.mk' _ _ ?_ ?_ all_goals exact (StrictUniversalPropertyFixedTarget.comp (strictUniversalPropertyFixedTargetQ W₁ _) (strictUniversalPropertyFixedTargetQ W₂' _) W₃ hW₃' hW₁₃ hW₂₃') -- Finally, the previous result can be transported via the equivalence `E₃` exact IsLocalization.of_equivalence_target _ W₃ _ E₃.symm iso lemma of_comp (W₃ : MorphismProperty C₁) [L₁.IsLocalization W₁] [(L₁ ⋙ L₂).IsLocalization W₃] (hW₁₃ : W₁ ≤ W₃) (hW₂₃ : W₂ = W₃.map L₁) : L₂.IsLocalization W₂ := by have : (L₁ ⋙ W₂.Q).IsLocalization W₃ := comp L₁ W₂.Q W₁ W₂ W₃ (fun X Y f hf => Localization.inverts W₂.Q W₂ _ (by simpa only [hW₂₃] using W₃.map_mem_map _ _ hf)) hW₁₃ (by rw [hW₂₃]) exact IsLocalization.of_equivalence_target W₂.Q W₂ L₂ (Localization.uniq (L₁ ⋙ W₂.Q) (L₁ ⋙ L₂) W₃) (liftNatIso L₁ W₁ _ _ _ _ ((Functor.associator _ _ _).symm ≪≫ Localization.compUniqFunctor (L₁ ⋙ W₂.Q) (L₁ ⋙ L₂) W₃)) end IsLocalization end Functor end CategoryTheory
CategoryTheory\Localization\Construction.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.MorphismProperty.Composition import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy import Mathlib.CategoryTheory.Category.Quiv /-! # Construction of the localized category This file constructs the localized category, obtained by formally inverting a class of maps `W : MorphismProperty C` in a category `C`. We first construct a quiver `LocQuiver W` whose objects are the same as those of `C` and whose maps are the maps in `C` and placeholders for the formal inverses of the maps in `W`. The localized category `W.Localization` is obtained by taking the quotient of the path category of `LocQuiver W` by the congruence generated by four types of relations. The obvious functor `Q W : C ⥤ W.Localization` satisfies the universal property of the localization. Indeed, if `G : C ⥤ D` sends morphisms in `W` to isomorphisms in `D` (i.e. we have `hG : W.IsInvertedBy G`), then there exists a unique functor `G' : W.Localization ⥤ D` such that `Q W ≫ G' = G`. This `G'` is `lift G hG`. The expected property of `lift G hG` if expressed by the lemma `fac` and the uniqueness is expressed by `uniq`. ## References * [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967] -/ noncomputable section open CategoryTheory.Category namespace CategoryTheory -- category universes first for convenience universe uC' uD' uC uD variable {C : Type uC} [Category.{uC'} C] (W : MorphismProperty C) {D : Type uD} [Category.{uD'} D] namespace Localization namespace Construction -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- If `W : MorphismProperty C`, `LocQuiver W` is a quiver with the same objects as `C`, and whose morphisms are those in `C` and placeholders for formal inverses of the morphisms in `W`. -/ structure LocQuiver (W : MorphismProperty C) where /-- underlying object -/ obj : C instance : Quiver (LocQuiver W) where Hom A B := (A.obj ⟶ B.obj) ⊕ { f : B.obj ⟶ A.obj // W f } /-- The object in the path category of `LocQuiver W` attached to an object in the category `C` -/ def ιPaths (X : C) : Paths (LocQuiver W) := ⟨X⟩ /-- The morphism in the path category associated to a morphism in the original category. -/ @[simp] def ψ₁ {X Y : C} (f : X ⟶ Y) : ιPaths W X ⟶ ιPaths W Y := Paths.of.map (Sum.inl f) /-- The morphism in the path category corresponding to a formal inverse. -/ @[simp] def ψ₂ {X Y : C} (w : X ⟶ Y) (hw : W w) : ιPaths W Y ⟶ ιPaths W X := Paths.of.map (Sum.inr ⟨w, hw⟩) /-- The relations by which we take the quotient in order to get the localized category. -/ inductive relations : HomRel (Paths (LocQuiver W)) | id (X : C) : relations (ψ₁ W (𝟙 X)) (𝟙 _) | comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : relations (ψ₁ W (f ≫ g)) (ψ₁ W f ≫ ψ₁ W g) | Winv₁ {X Y : C} (w : X ⟶ Y) (hw : W w) : relations (ψ₁ W w ≫ ψ₂ W w hw) (𝟙 _) | Winv₂ {X Y : C} (w : X ⟶ Y) (hw : W w) : relations (ψ₂ W w hw ≫ ψ₁ W w) (𝟙 _) end Construction end Localization namespace MorphismProperty open Localization.Construction -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- The localized category obtained by formally inverting the morphisms in `W : MorphismProperty C` -/ def Localization := CategoryTheory.Quotient (Localization.Construction.relations W) instance : Category (Localization W) := by dsimp only [Localization] infer_instance /-- The obvious functor `C ⥤ W.Localization` -/ def Q : C ⥤ W.Localization where obj X := (Quotient.functor _).obj (Paths.of.obj ⟨X⟩) map f := (Quotient.functor _).map (ψ₁ W f) map_id X := Quotient.sound _ (relations.id X) map_comp f g := Quotient.sound _ (relations.comp f g) end MorphismProperty namespace Localization namespace Construction variable {W} /-- The isomorphism in `W.Localization` associated to a morphism `w` in W -/ def wIso {X Y : C} (w : X ⟶ Y) (hw : W w) : Iso (W.Q.obj X) (W.Q.obj Y) where hom := W.Q.map w inv := (Quotient.functor _).map (by dsimp; exact Paths.of.map (Sum.inr ⟨w, hw⟩)) hom_inv_id := Quotient.sound _ (relations.Winv₁ w hw) inv_hom_id := Quotient.sound _ (relations.Winv₂ w hw) /-- The formal inverse in `W.Localization` of a morphism `w` in `W`. -/ abbrev wInv {X Y : C} (w : X ⟶ Y) (hw : W w) := (wIso w hw).inv variable (W) theorem _root_.CategoryTheory.MorphismProperty.Q_inverts : W.IsInvertedBy W.Q := fun _ _ w hw => (Localization.Construction.wIso w hw).isIso_hom variable {W} variable (G : C ⥤ D) (hG : W.IsInvertedBy G) /-- The lifting of a functor to the path category of `LocQuiver W` -/ @[simps!] def liftToPathCategory : Paths (LocQuiver W) ⥤ D := Quiv.lift { obj := fun X => G.obj X.obj map := by intros X Y rintro (f | ⟨g, hg⟩) · exact G.map f · haveI := hG g hg exact inv (G.map g) } /-- The lifting of a functor `C ⥤ D` inverting `W` as a functor `W.Localization ⥤ D` -/ @[simps!] def lift : W.Localization ⥤ D := Quotient.lift (relations W) (liftToPathCategory G hG) (by rintro ⟨X⟩ ⟨Y⟩ f₁ f₂ r -- Porting note: rest of proof was `rcases r with ⟨⟩; tidy` rcases r with (_|_|⟨f,hf⟩|⟨f,hf⟩) · aesop_cat · aesop_cat all_goals dsimp haveI := hG f hf simp rfl) @[simp] theorem fac : W.Q ⋙ lift G hG = G := Functor.ext (fun X => rfl) (by intro X Y f simp only [Functor.comp_map, eqToHom_refl, comp_id, id_comp] dsimp [MorphismProperty.Q, Quot.liftOn, Quotient.functor] rw [composePath_toPath]) theorem uniq (G₁ G₂ : W.Localization ⥤ D) (h : W.Q ⋙ G₁ = W.Q ⋙ G₂) : G₁ = G₂ := by suffices h' : Quotient.functor _ ⋙ G₁ = Quotient.functor _ ⋙ G₂ by refine Functor.ext ?_ ?_ · rintro ⟨⟨X⟩⟩ apply Functor.congr_obj h · rintro ⟨⟨X⟩⟩ ⟨⟨Y⟩⟩ ⟨f⟩ apply Functor.congr_hom h' refine Paths.ext_functor ?_ ?_ · ext X cases X apply Functor.congr_obj h · rintro ⟨X⟩ ⟨Y⟩ (f | ⟨w, hw⟩) · simpa only using Functor.congr_hom h f · have hw : W.Q.map w = (wIso w hw).hom := rfl have hw' := Functor.congr_hom h w simp only [Functor.comp_map, hw] at hw' refine Functor.congr_inv_of_congr_hom _ _ _ ?_ ?_ hw' all_goals apply Functor.congr_obj h variable (W) /-- The canonical bijection between objects in a category and its localization with respect to a morphism_property `W` -/ @[simps] def objEquiv : C ≃ W.Localization where toFun := W.Q.obj invFun X := X.as.obj left_inv X := rfl right_inv := by rintro ⟨⟨X⟩⟩ rfl variable {W} /-- A `MorphismProperty` in `W.Localization` is satisfied by all morphisms in the localized category if it contains the image of the morphisms in the original category, the inverses of the morphisms in `W` and if it is stable under composition -/ theorem morphismProperty_is_top (P : MorphismProperty W.Localization) [P.IsStableUnderComposition] (hP₁ : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P (W.Q.map f)) (hP₂ : ∀ ⦃X Y : C⦄ (w : X ⟶ Y) (hw : W w), P (wInv w hw)) : P = ⊤ := by funext X Y f ext constructor · intro apply MorphismProperty.top_apply · intro let G : _ ⥤ W.Localization := Quotient.functor _ haveI : G.Full := Quotient.full_functor _ suffices ∀ (X₁ X₂ : Paths (LocQuiver W)) (f : X₁ ⟶ X₂), P (G.map f) by rcases X with ⟨⟨X⟩⟩ rcases Y with ⟨⟨Y⟩⟩ simpa only [Functor.map_preimage] using this _ _ (G.preimage f) intros X₁ X₂ p induction' p with X₂ X₃ p g hp · simpa only [Functor.map_id] using hP₁ (𝟙 X₁.obj) · let p' : X₁ ⟶X₂ := p rw [show p'.cons g = p' ≫ Quiver.Hom.toPath g by rfl, G.map_comp] refine P.comp_mem _ _ hp ?_ rcases g with (g | ⟨g, hg⟩) · apply hP₁ · apply hP₂ /-- A `MorphismProperty` in `W.Localization` is satisfied by all morphisms in the localized category if it contains the image of the morphisms in the original category, if is stable under composition and if the property is stable by passing to inverses. -/ theorem morphismProperty_is_top' (P : MorphismProperty W.Localization) [P.IsStableUnderComposition] (hP₁ : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P (W.Q.map f)) (hP₂ : ∀ ⦃X Y : W.Localization⦄ (e : X ≅ Y) (_ : P e.hom), P e.inv) : P = ⊤ := morphismProperty_is_top P hP₁ (fun _ _ w _ => hP₂ _ (hP₁ w)) namespace NatTransExtension variable {F₁ F₂ : W.Localization ⥤ D} (τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂) /-- If `F₁` and `F₂` are functors `W.Localization ⥤ D` and if we have `τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂`, we shall define a natural transformation `F₁ ⟶ F₂`. This is the `app` field of this natural transformation. -/ def app (X : W.Localization) : F₁.obj X ⟶ F₂.obj X := eqToHom (congr_arg F₁.obj ((objEquiv W).right_inv X).symm) ≫ τ.app ((objEquiv W).invFun X) ≫ eqToHom (congr_arg F₂.obj ((objEquiv W).right_inv X)) @[simp] theorem app_eq (X : C) : (app τ) (W.Q.obj X) = τ.app X := by simp only [app, eqToHom_refl, comp_id, id_comp] rfl end NatTransExtension /-- If `F₁` and `F₂` are functors `W.Localization ⥤ D`, a natural transformation `F₁ ⟶ F₂` can be obtained from a natural transformation `W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂`. -/ @[simps] def natTransExtension {F₁ F₂ : W.Localization ⥤ D} (τ : W.Q ⋙ F₁ ⟶ W.Q ⋙ F₂) : F₁ ⟶ F₂ where app := NatTransExtension.app τ naturality := by suffices MorphismProperty.naturalityProperty (NatTransExtension.app τ) = ⊤ by intro X Y f simpa only [← this] using MorphismProperty.top_apply f refine morphismProperty_is_top' (MorphismProperty.naturalityProperty (NatTransExtension.app τ)) ?_ (MorphismProperty.naturalityProperty.stableUnderInverse _) intros X Y f dsimp simpa only [NatTransExtension.app_eq] using τ.naturality f @[simp] theorem natTransExtension_hcomp {F G : W.Localization ⥤ D} (τ : W.Q ⋙ F ⟶ W.Q ⋙ G) : 𝟙 W.Q ◫ natTransExtension τ = τ := by aesop_cat theorem natTrans_hcomp_injective {F G : W.Localization ⥤ D} {τ₁ τ₂ : F ⟶ G} (h : 𝟙 W.Q ◫ τ₁ = 𝟙 W.Q ◫ τ₂) : τ₁ = τ₂ := by ext X have eq := (objEquiv W).right_inv X simp only [objEquiv] at eq rw [← eq, ← NatTrans.id_hcomp_app, ← NatTrans.id_hcomp_app, h] variable (W D) namespace WhiskeringLeftEquivalence /-- The functor `(W.Localization ⥤ D) ⥤ (W.FunctorsInverting D)` induced by the composition with `W.Q : C ⥤ W.Localization`. -/ @[simps!] def functor : (W.Localization ⥤ D) ⥤ W.FunctorsInverting D := FullSubcategory.lift _ ((whiskeringLeft _ _ D).obj W.Q) fun _ => MorphismProperty.IsInvertedBy.of_comp W W.Q W.Q_inverts _ /-- The function `(W.FunctorsInverting D) ⥤ (W.Localization ⥤ D)` induced by `Construction.lift`. -/ @[simps!] def inverse : W.FunctorsInverting D ⥤ W.Localization ⥤ D where obj G := lift G.obj G.property map τ := natTransExtension (eqToHom (by rw [fac]) ≫ τ ≫ eqToHom (by rw [fac])) map_id G := natTrans_hcomp_injective (by rw [natTransExtension_hcomp] ext X simp only [NatTrans.comp_app, eqToHom_app, eqToHom_refl, comp_id, id_comp, NatTrans.hcomp_id_app, NatTrans.id_app, Functor.map_id] rfl) map_comp τ₁ τ₂ := natTrans_hcomp_injective (by ext X simp only [natTransExtension_hcomp, NatTrans.comp_app, eqToHom_app, eqToHom_refl, id_comp, comp_id, NatTrans.hcomp_app, NatTrans.id_app, Functor.map_id, natTransExtension_app, NatTransExtension.app_eq] rfl) /-- The unit isomorphism of the equivalence of categories `whiskeringLeftEquivalence W D`. -/ @[simps!] def unitIso : 𝟭 (W.Localization ⥤ D) ≅ functor W D ⋙ inverse W D := eqToIso (by refine Functor.ext (fun G => ?_) fun G₁ G₂ τ => ?_ · apply uniq dsimp [Functor] erw [fac] rfl · apply natTrans_hcomp_injective ext X simp) /-- The counit isomorphism of the equivalence of categories `WhiskeringLeftEquivalence W D`. -/ @[simps!] def counitIso : inverse W D ⋙ functor W D ≅ 𝟭 (W.FunctorsInverting D) := eqToIso (by refine Functor.ext ?_ ?_ · rintro ⟨G, hG⟩ ext exact fac G hG · rintro ⟨G₁, hG₁⟩ ⟨G₂, hG₂⟩ f ext apply NatTransExtension.app_eq) end WhiskeringLeftEquivalence /-- The equivalence of categories `(W.localization ⥤ D) ≌ (W.FunctorsInverting D)` induced by the composition with `W.Q : C ⥤ W.localization`. -/ def whiskeringLeftEquivalence : W.Localization ⥤ D ≌ W.FunctorsInverting D where functor := WhiskeringLeftEquivalence.functor W D inverse := WhiskeringLeftEquivalence.inverse W D unitIso := WhiskeringLeftEquivalence.unitIso W D counitIso := WhiskeringLeftEquivalence.counitIso W D functor_unitIso_comp F := by ext simp only [WhiskeringLeftEquivalence.unitIso_hom, eqToHom_app, eqToHom_refl, WhiskeringLeftEquivalence.counitIso_hom, eqToHom_map, eqToHom_trans] rfl end Construction end Localization end CategoryTheory
CategoryTheory\Localization\Equivalence.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Predicate import Mathlib.CategoryTheory.CatCommSq /-! # Localization functors are preserved through equivalences In `Localization/Predicate.lean`, the lemma `Localization.of_equivalence_target` already showed that the predicate of localized categories is unchanged when we replace the target category (i.e. the candidate localized category) by an equivalent category. In this file, we show the same for the source category (`Localization.of_equivalence_source`). More generally, `Localization.of_equivalences` shows that we may replace both the source and target categories by equivalent categories. This is obtained using `Localization.isEquivalence` which provide a sufficient condition in order to show that a functor between localized categories is an equivalence. -/ namespace CategoryTheory open Category Localization variable {C₁ C₂ D D₁ D₂ : Type*} [Category C₁] [Category C₂] [Category D] [Category D₁] [Category D₂] namespace Localization variable (L₁ : C₁ ⥤ D₁) (W₁ : MorphismProperty C₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) (W₂ : MorphismProperty C₂) [L₂.IsLocalization W₂] (G : C₁ ⥤ D₂) (G' : D₁ ⥤ D₂) [Lifting L₁ W₁ G G'] (F : C₂ ⥤ D₁) (F' : D₂ ⥤ D₁) [Lifting L₂ W₂ F F'] (α : G ⋙ F' ≅ L₁) (β : F ⋙ G' ≅ L₂) /-- Basic constructor of an equivalence between localized categories -/ noncomputable def equivalence : D₁ ≌ D₂ := Equivalence.mk G' F' (liftNatIso L₁ W₁ L₁ (G ⋙ F') (𝟭 D₁) (G' ⋙ F') α.symm) (liftNatIso L₂ W₂ (F ⋙ G') L₂ (F' ⋙ G') (𝟭 D₂) β) @[simp] lemma equivalence_counitIso_app (X : C₂) : (equivalence L₁ W₁ L₂ W₂ G G' F F' α β).counitIso.app (L₂.obj X) = (Lifting.iso L₂ W₂ (F ⋙ G') (F' ⋙ G')).app X ≪≫ β.app X := by ext dsimp [equivalence, Equivalence.mk] rw [liftNatTrans_app] dsimp [Lifting.iso] rw [comp_id] /-- Basic constructor of an equivalence between localized categories -/ lemma isEquivalence : G'.IsEquivalence := (equivalence L₁ W₁ L₂ W₂ G G' F F' α β).isEquivalence_functor end Localization namespace Functor namespace IsLocalization /-- If `L₁ : C₁ ⥤ D` is a localization functor for `W₁ : MorphismProperty C₁`, then it is also the case of a functor `L₂ : C₂ ⥤ D` for a suitable `W₂ : MorphismProperty C₂` when we have an equivalence of category `E : C₁ ≌ C₂` and an isomorphism `E.functor ⋙ L₂ ≅ L₁`. -/ lemma of_equivalence_source (L₁ : C₁ ⥤ D) (W₁ : MorphismProperty C₁) (L₂ : C₂ ⥤ D) (W₂ : MorphismProperty C₂) (E : C₁ ≌ C₂) (hW₁ : W₁ ≤ W₂.isoClosure.inverseImage E.functor) (hW₂ : W₂.IsInvertedBy L₂) [L₁.IsLocalization W₁] (iso : E.functor ⋙ L₂ ≅ L₁) : L₂.IsLocalization W₂ := by have h : W₁.IsInvertedBy (E.functor ⋙ W₂.Q) := fun _ _ f hf => by obtain ⟨_, _, f', hf', ⟨e⟩⟩ := hW₁ f hf exact ((MorphismProperty.isomorphisms _).arrow_mk_iso_iff (W₂.Q.mapArrow.mapIso e)).1 (Localization.inverts W₂.Q W₂ _ hf') exact { inverts := hW₂ isEquivalence := Localization.isEquivalence W₂.Q W₂ L₁ W₁ L₂ (Construction.lift L₂ hW₂) (E.functor ⋙ W₂.Q) (Localization.lift (E.functor ⋙ W₂.Q) h L₁) (by calc L₂ ⋙ lift (E.functor ⋙ W₂.Q) h L₁ ≅ _ := (leftUnitor _).symm _ ≅ _ := isoWhiskerRight E.counitIso.symm _ _ ≅ E.inverse ⋙ E.functor ⋙ L₂ ⋙ lift (E.functor ⋙ W₂.Q) h L₁ := Functor.associator _ _ _ _ ≅ E.inverse ⋙ L₁ ⋙ lift (E.functor ⋙ W₂.Q) h L₁ := isoWhiskerLeft E.inverse ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight iso _) _ ≅ E.inverse ⋙ E.functor ⋙ W₂.Q := isoWhiskerLeft _ (Localization.fac (E.functor ⋙ W₂.Q) h L₁) _ ≅ (E.inverse ⋙ E.functor) ⋙ W₂.Q := (Functor.associator _ _ _).symm _ ≅ 𝟭 C₂ ⋙ W₂.Q := isoWhiskerRight E.counitIso _ _ ≅ W₂.Q := leftUnitor _) (Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Lifting.iso W₂.Q W₂ _ _) ≪≫ iso) } /-- If `L₁ : C₁ ⥤ D₁` is a localization functor for `W₁ : MorphismProperty C₁`, then if we transport this functor `L₁` via equivalences `C₁ ≌ C₂` and `D₁ ≌ D₂` to get a functor `L₂ : C₂ ⥤ D₂`, then `L₂` is also a localization functor for a suitable `W₂ : MorphismProperty C₂`. -/ lemma of_equivalences (L₁ : C₁ ⥤ D₁) (W₁ : MorphismProperty C₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) (W₂ : MorphismProperty C₂) (E : C₁ ≌ C₂) (E' : D₁ ≌ D₂) [CatCommSq E.functor L₁ L₂ E'.functor] (hW₁ : W₁ ≤ W₂.isoClosure.inverseImage E.functor) (hW₂ : W₂.IsInvertedBy L₂) : L₂.IsLocalization W₂ := by haveI : (E.functor ⋙ L₂).IsLocalization W₁ := of_equivalence_target L₁ W₁ _ E' ((CatCommSq.iso _ _ _ _).symm) exact of_equivalence_source (E.functor ⋙ L₂) W₁ L₂ W₂ E hW₁ hW₂ (Iso.refl _) end IsLocalization end Functor end CategoryTheory
CategoryTheory\Localization\FiniteProducts.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.ConeCategory import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Localization.Adjunction import Mathlib.CategoryTheory.Localization.HasLocalization import Mathlib.CategoryTheory.Localization.Pi import Mathlib.CategoryTheory.MorphismProperty.Limits /-! The localized category has finite products In this file, it is shown that if `L : C ⥤ D` is a localization functor for `W : MorphismProperty C` and that `W` is stable under finite products, then `D` has finite products, and `L` preserves finite products. -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Limits namespace Localization variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (L : C ⥤ D) {W : MorphismProperty C} [L.IsLocalization W] [W.ContainsIdentities] namespace HasProductsOfShapeAux variable {J : Type} [Finite J] [HasProductsOfShape J C] (hW : W.IsStableUnderProductsOfShape J) lemma inverts : (W.functorCategory (Discrete J)).IsInvertedBy (lim ⋙ L) := fun _ _ f hf => Localization.inverts L W _ (hW.lim_map f hf) /-- The (candidate) limit functor for the localized category. It is induced by `lim ⋙ L : (Discrete J ⥤ C) ⥤ D`. -/ noncomputable abbrev limitFunctor : (Discrete J ⥤ D) ⥤ D := Localization.lift _ (inverts L hW) ((whiskeringRight (Discrete J) C D).obj L) /-- The functor `limitFunctor L hW` is induced by `lim ⋙ L`. -/ noncomputable def compLimitFunctorIso : ((whiskeringRight (Discrete J) C D).obj L) ⋙ limitFunctor L hW ≅ lim ⋙ L := by apply Localization.fac instance : CatCommSq (Functor.const (Discrete J)) L ((whiskeringRight (Discrete J) C D).obj L) (Functor.const (Discrete J)) where iso' := (Functor.compConstIso _ _).symm noncomputable instance : CatCommSq lim ((whiskeringRight (Discrete J) C D).obj L) L (limitFunctor L hW) where iso' := (compLimitFunctorIso L hW).symm /-- The adjunction between the constant functor `D ⥤ (Discrete J ⥤ D)` and `limitFunctor L hW`. -/ noncomputable def adj : Functor.const _ ⊣ limitFunctor L hW := constLimAdj.localization L W ((whiskeringRight (Discrete J) C D).obj L) (W.functorCategory (Discrete J)) (Functor.const _) (limitFunctor L hW) lemma adj_counit_app (F : Discrete J ⥤ C) : (adj L hW).counit.app (F ⋙ L) = (Functor.const (Discrete J)).map ((compLimitFunctorIso L hW).hom.app F) ≫ (Functor.compConstIso (Discrete J) L).hom.app (lim.obj F) ≫ whiskerRight (constLimAdj.counit.app F) L := by apply constLimAdj.localization_counit_app /-- Auxiliary definition for `Localization.preservesProductsOfShape`. -/ noncomputable def isLimitMapCone (F : Discrete J ⥤ C) : IsLimit (L.mapCone (limit.cone F)) := IsLimit.ofIsoLimit (isLimitConeOfAdj (adj L hW) (F ⋙ L)) (Cones.ext ((compLimitFunctorIso L hW).app F) (by simp [adj_counit_app, constLimAdj])) end HasProductsOfShapeAux variable (W) lemma hasProductsOfShape (J : Type) [Finite J] [HasProductsOfShape J C] (hW : W.IsStableUnderProductsOfShape J) : HasProductsOfShape J D := hasLimitsOfShape_iff_isLeftAdjoint_const.2 (HasProductsOfShapeAux.adj L hW).isLeftAdjoint /-- When `C` has finite products indexed by `J`, `W : MorphismProperty C` contains identities and is stable by products indexed by `J`, then any localization functor for `W` preserves finite products indexed by `J`. -/ noncomputable def preservesProductsOfShape (J : Type) [Finite J] [HasProductsOfShape J C] (hW : W.IsStableUnderProductsOfShape J) : PreservesLimitsOfShape (Discrete J) L where preservesLimit {F} := preservesLimitOfPreservesLimitCone (limit.isLimit F) (HasProductsOfShapeAux.isLimitMapCone L hW F) variable [HasFiniteProducts C] [W.IsStableUnderFiniteProducts] lemma hasFiniteProducts : HasFiniteProducts D := ⟨fun _ => hasProductsOfShape L W _ (W.isStableUnderProductsOfShape_of_isStableUnderFiniteProducts _)⟩ /-- When `C` has finite products and `W : MorphismProperty C` contains identities and is stable by finite products, then any localization functor for `W` preserves finite products. -/ noncomputable def preservesFiniteProducts : PreservesFiniteProducts L where preserves J _ := preservesProductsOfShape L W J (W.isStableUnderProductsOfShape_of_isStableUnderFiniteProducts _) instance : HasFiniteProducts (W.Localization) := hasFiniteProducts W.Q W noncomputable instance : PreservesFiniteProducts W.Q := preservesFiniteProducts W.Q W instance [W.HasLocalization] : HasFiniteProducts (W.Localization') := hasFiniteProducts W.Q' W noncomputable instance [W.HasLocalization] : PreservesFiniteProducts W.Q' := preservesFiniteProducts W.Q' W end Localization end CategoryTheory
CategoryTheory\Localization\HasLocalization.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Predicate /-! Morphism properties equipped with a localized category If `C : Type u` is a category (with `[Category.{v} C]`), and `W : MorphismProperty C`, then the constructed localized category `W.Localization` is in `Type u` (the objects are essentially the same as that of `C`), but the morphisms are in `Type (max u v)`. In particular situations, it may happen that there is a localized category for `W` whose morphisms are in a lower universe like `v`: it shall be so for the homotopy categories of model categories (TODO), and it should also be so for the derived categories of Grothendieck abelian categories (TODO: but this shall be very technical). Then, in order to allow the user to provide a localized category with specific universe parameters when it exists, we introduce a typeclass `MorphismProperty.HasLocalization.{w} W` which contains the data of a localized category `D` for `W` with `D : Type u` and `[Category.{w} D]`. Then, all definitions which involve "the" localized category for `W` should contain a `[MorphismProperty.HasLocalization.{w} W]` assumption for a suitable `w`. The functor `W.Q' : C ⥤ W.Localization'` shall be the localization functor for this fixed choice of the localized category. If the statement of a theorem does not involve the localized category, but the proof does, it is no longer necessary to use a `HasLocalization` assumption, but one may use `HasLocalization.standard` in the proof instead. -/ universe w v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] variable (W : MorphismProperty C) namespace MorphismProperty /-- The data of a localized category with a given universe for the morphisms. -/ class HasLocalization where /-- the objects of the localized category. -/ {D : Type u} /-- the category structure. -/ [hD : Category.{w} D] /-- the localization functor. -/ L : C ⥤ D [hL : L.IsLocalization W] variable [HasLocalization.{w} W] /-- The localized category for `W : MorphismProperty C` that is fixed by the `[HasLocalization W]` instance. -/ def Localization' := HasLocalization.D W instance : Category W.Localization' := HasLocalization.hD /-- The localization functor `C ⥤ W.Localization'` that is fixed by the `[HasLocalization W]` instance. -/ def Q' : C ⥤ W.Localization' := HasLocalization.L instance : W.Q'.IsLocalization W := HasLocalization.hL /-- The constructed localized category. -/ def HasLocalization.standard : HasLocalization.{max u v} W where L := W.Q end MorphismProperty end CategoryTheory
CategoryTheory\Localization\HomEquiv.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.LocalizerMorphism import Mathlib.CategoryTheory.HomCongr /-! # Bijections between morphisms in two localized categories Given two localization functors `L₁ : C ⥤ D₁` and `L₂ : C ⥤ D₂` for the same class of morphisms `W : MorphismProperty C`, we define a bijection `Localization.homEquiv W L₁ L₂ : (L₁.obj X ⟶ L₁.obj Y) ≃ (L₂.obj X ⟶ L₂.obj Y)` between the types of morphisms in the two localized categories. More generally, given a localizer morphism `Φ : LocalizerMorphism W₁ W₂`, we define a map `Φ.homMap L₁ L₂ : (L₁.obj X ⟶ L₁.obj Y) ⟶ (L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y))`. The definition `Localization.homEquiv` is obtained by applying the construction to the identity localizer morphism. -/ namespace CategoryTheory open Category variable {C C₁ C₂ C₃ D₁ D₂ D₃ : Type*} [Category C] [Category C₁] [Category C₂] [Category C₃] [Category D₁] [Category D₂] [Category D₃] namespace LocalizerMorphism variable {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} {W₃ : MorphismProperty C₃} (Φ : LocalizerMorphism W₁ W₂) (Ψ : LocalizerMorphism W₂ W₃) (L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂] (L₃ : C₃ ⥤ D₃) [L₃.IsLocalization W₃] {X Y Z : C₁} /-- If `Φ : LocalizerMorphism W₁ W₂` is a morphism of localizers, `L₁` and `L₂` are localization functors for `W₁` and `W₂`, then this is the induced map `(L₁.obj X ⟶ L₁.obj Y) ⟶ (L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y))` for all objects `X` and `Y`. -/ noncomputable def homMap (f : L₁.obj X ⟶ L₁.obj Y) : L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y) := Iso.homCongr ((CatCommSq.iso _ _ _ _).symm.app _) ((CatCommSq.iso _ _ _ _).symm.app _) ((Φ.localizedFunctor L₁ L₂).map f) @[simp] lemma homMap_map (f : X ⟶ Y) : Φ.homMap L₁ L₂ (L₁.map f) = L₂.map (Φ.functor.map f) := by dsimp [homMap] erw [← NatTrans.naturality_assoc] simp variable (X) in @[simp] lemma homMap_id : Φ.homMap L₁ L₂ (𝟙 (L₁.obj X)) = 𝟙 (L₂.obj (Φ.functor.obj X)) := by simpa using Φ.homMap_map L₁ L₂ (𝟙 X) @[reassoc] lemma homMap_comp (f : L₁.obj X ⟶ L₁.obj Y) (g : L₁.obj Y ⟶ L₁.obj Z) : Φ.homMap L₁ L₂ (f ≫ g) = Φ.homMap L₁ L₂ f ≫ Φ.homMap L₁ L₂ g := by simp [homMap] @[reassoc] lemma homMap_apply (G : D₁ ⥤ D₂) (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G) (f : L₁.obj X ⟶ L₁.obj Y) : Φ.homMap L₁ L₂ f = e.hom.app X ≫ G.map f ≫ e.inv.app Y := by let G' := Φ.localizedFunctor L₁ L₂ let e' := CatCommSq.iso Φ.functor L₁ L₂ G' change e'.hom.app X ≫ G'.map f ≫ e'.inv.app Y = _ letI : Localization.Lifting L₁ W₁ (Φ.functor ⋙ L₂) G := ⟨e.symm⟩ let α : G' ≅ G := Localization.liftNatIso L₁ W₁ (L₁ ⋙ G') (Φ.functor ⋙ L₂) _ _ e'.symm have : e = e' ≪≫ isoWhiskerLeft _ α := by ext X dsimp [α] rw [Localization.liftNatTrans_app] erw [id_comp] rw [Iso.hom_inv_id_app_assoc] rfl simp [this] @[simp] lemma id_homMap (f : L₁.obj X ⟶ L₁.obj Y) : (id W₁).homMap L₁ L₁ f = f := by simpa using (id W₁).homMap_apply L₁ L₁ (𝟭 D₁) (Iso.refl _) f @[simp] lemma homMap_homMap (f : L₁.obj X ⟶ L₁.obj Y) : Ψ.homMap L₂ L₃ (Φ.homMap L₁ L₂ f) = (Φ.comp Ψ).homMap L₁ L₃ f := by let G := Φ.localizedFunctor L₁ L₂ let G' := Ψ.localizedFunctor L₂ L₃ let e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G := CatCommSq.iso _ _ _ _ let e' : Ψ.functor ⋙ L₃ ≅ L₂ ⋙ G' := CatCommSq.iso _ _ _ _ rw [Φ.homMap_apply L₁ L₂ G e, Ψ.homMap_apply L₂ L₃ G' e', (Φ.comp Ψ).homMap_apply L₁ L₃ (G ⋙ G') (Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e' ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight e _ ≪≫ Functor.associator _ _ _)] dsimp simp only [Functor.map_comp, assoc, comp_id, id_comp] end LocalizerMorphism namespace Localization variable (W : MorphismProperty C) (L₁ : C ⥤ D₁) [L₁.IsLocalization W] (L₂ : C ⥤ D₂) [L₂.IsLocalization W] (L₃ : C ⥤ D₃) [L₃.IsLocalization W] {X Y Z : C} /-- Bijection between types of morphisms in two localized categories for the same class of morphisms `W`. -/ @[simps (config := .lemmasOnly) apply] noncomputable def homEquiv : (L₁.obj X ⟶ L₁.obj Y) ≃ (L₂.obj X ⟶ L₂.obj Y) where toFun := (LocalizerMorphism.id W).homMap L₁ L₂ invFun := (LocalizerMorphism.id W).homMap L₂ L₁ left_inv f := by rw [LocalizerMorphism.homMap_homMap] apply LocalizerMorphism.id_homMap right_inv g := by rw [LocalizerMorphism.homMap_homMap] apply LocalizerMorphism.id_homMap @[simp] lemma homEquiv_symm_apply (g : L₂.obj X ⟶ L₂.obj Y) : (homEquiv W L₁ L₂).symm g = homEquiv W L₂ L₁ g := rfl lemma homEquiv_eq (G : D₁ ⥤ D₂) (e : L₁ ⋙ G ≅ L₂) (f : L₁.obj X ⟶ L₁.obj Y) : homEquiv W L₁ L₂ f = e.inv.app X ≫ G.map f ≫ e.hom.app Y := by rw [homEquiv_apply, LocalizerMorphism.homMap_apply (LocalizerMorphism.id W) L₁ L₂ G e.symm, Iso.symm_hom, Iso.symm_inv] @[simp] lemma homEquiv_refl (f : L₁.obj X ⟶ L₁.obj Y) : homEquiv W L₁ L₁ f = f := by apply LocalizerMorphism.id_homMap lemma homEquiv_trans (f : L₁.obj X ⟶ L₁.obj Y) : homEquiv W L₂ L₃ (homEquiv W L₁ L₂ f) = homEquiv W L₁ L₃ f := by dsimp only [homEquiv_apply] apply LocalizerMorphism.homMap_homMap lemma homEquiv_comp (f : L₁.obj X ⟶ L₁.obj Y) (g : L₁.obj Y ⟶ L₁.obj Z) : homEquiv W L₁ L₂ (f ≫ g) = homEquiv W L₁ L₂ f ≫ homEquiv W L₁ L₂ g := by apply LocalizerMorphism.homMap_comp @[simp] lemma homEquiv_map (f : X ⟶ Y) : homEquiv W L₁ L₂ (L₁.map f) = L₂.map f := by simp [homEquiv_apply] variable (X) in @[simp] lemma homEquiv_id : homEquiv W L₁ L₂ (𝟙 (L₁.obj X)) = 𝟙 (L₂.obj X) := by simp [homEquiv_apply] lemma homEquiv_isoOfHom_inv (f : Y ⟶ X) (hf : W f) : homEquiv W L₁ L₂ (isoOfHom L₁ W f hf).inv = (isoOfHom L₂ W f hf).inv := by rw [← cancel_mono (isoOfHom L₂ W f hf).hom, Iso.inv_hom_id, isoOfHom_hom, ← homEquiv_map W L₁ L₂ f, ← homEquiv_comp, isoOfHom_inv_hom_id, homEquiv_id] end Localization end CategoryTheory
CategoryTheory\Localization\LocalizerMorphism.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Equivalence /-! # Morphisms of localizers A morphism of localizers consists of a functor `F : C₁ ⥤ C₂` between two categories equipped with morphism properties `W₁` and `W₂` such that `F` sends morphisms in `W₁` to morphisms in `W₂`. If `Φ : LocalizerMorphism W₁ W₂`, and that `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` are localization functors for `W₁` and `W₂`, the induced functor `D₁ ⥤ D₂` is denoted `Φ.localizedFunctor L₁ L₂`; we introduce the condition `Φ.IsLocalizedEquivalence` which expresses that this functor is an equivalence of categories. This condition is independent of the choice of the localized categories. ## References * [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008] -/ universe v₁ v₂ v₃ v₄ v₄' v₅ v₅' v₆ u₁ u₂ u₃ u₄ u₄' u₅ u₅' u₆ namespace CategoryTheory open Localization variable {C₁ : Type u₁} {C₂ : Type u₂} {C₃ : Type u₃} {D₁ : Type u₄} {D₂ : Type u₅} {D₃ : Type u₆} [Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} C₃] [Category.{v₄} D₁] [Category.{v₅} D₂] [Category.{v₆} D₃] (W₁ : MorphismProperty C₁) (W₂ : MorphismProperty C₂) (W₃ : MorphismProperty C₃) /-- If `W₁ : MorphismProperty C₁` and `W₂ : MorphismProperty C₂`, a `LocalizerMorphism W₁ W₂` is the datum of a functor `C₁ ⥤ C₂` which sends morphisms in `W₁` to morphisms in `W₂` -/ structure LocalizerMorphism where /-- a functor between the two categories -/ functor : C₁ ⥤ C₂ /-- the functor is compatible with the `MorphismProperty` -/ map : W₁ ≤ W₂.inverseImage functor namespace LocalizerMorphism /-- The identity functor as a morphism of localizers. -/ @[simps] def id : LocalizerMorphism W₁ W₁ where functor := 𝟭 C₁ map _ _ _ hf := hf variable {W₁ W₂ W₃} /-- The composition of two localizers morphisms. -/ @[simps] def comp (Φ : LocalizerMorphism W₁ W₂) (Ψ : LocalizerMorphism W₂ W₃) : LocalizerMorphism W₁ W₃ where functor := Φ.functor ⋙ Ψ.functor map _ _ _ hf := Ψ.map _ (Φ.map _ hf) variable (Φ : LocalizerMorphism W₁ W₂) /-- The opposite localizer morphism `LocalizerMorphism W₁.op W₂.op` deduced from `Φ : LocalizerMorphism W₁ W₂`. -/ @[simps] def op : LocalizerMorphism W₁.op W₂.op where functor := Φ.functor.op map _ _ _ hf := Φ.map _ hf variable (L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂] lemma inverts : W₁.IsInvertedBy (Φ.functor ⋙ L₂) := fun _ _ _ hf => Localization.inverts L₂ W₂ _ (Φ.map _ hf) /-- When `Φ : LocalizerMorphism W₁ W₂` and that `L₁` and `L₂` are localization functors for `W₁` and `W₂`, then `Φ.localizedFunctor L₁ L₂` is the induced functor on the localized categories. --/ noncomputable def localizedFunctor : D₁ ⥤ D₂ := lift (Φ.functor ⋙ L₂) (Φ.inverts _) L₁ noncomputable instance liftingLocalizedFunctor : Lifting L₁ W₁ (Φ.functor ⋙ L₂) (Φ.localizedFunctor L₁ L₂) := by dsimp [localizedFunctor] infer_instance /-- The 2-commutative square expressing that `Φ.localizedFunctor L₁ L₂` lifts the functor `Φ.functor` -/ noncomputable instance catCommSq : CatCommSq Φ.functor L₁ L₂ (Φ.localizedFunctor L₁ L₂) := CatCommSq.mk (Lifting.iso _ W₁ _ _).symm variable (G : D₁ ⥤ D₂) section variable [CatCommSq Φ.functor L₁ L₂ G] {D₁' : Type u₄'} {D₂' : Type u₅'} [Category.{v₄'} D₁'] [Category.{v₅'} D₂'] (L₁' : C₁ ⥤ D₁') (L₂' : C₂ ⥤ D₂') [L₁'.IsLocalization W₁] [L₂'.IsLocalization W₂] (G' : D₁' ⥤ D₂') [CatCommSq Φ.functor L₁' L₂' G'] /-- If a localizer morphism induces an equivalence on some choice of localized categories, it will be so for any choice of localized categoriees. -/ lemma isEquivalence_imp [G.IsEquivalence] : G'.IsEquivalence := let E₁ := Localization.uniq L₁ L₁' W₁ let E₂ := Localization.uniq L₂ L₂' W₂ let e : L₁ ⋙ G ⋙ E₂.functor ≅ L₁ ⋙ E₁.functor ⋙ G' := calc L₁ ⋙ G ⋙ E₂.functor ≅ Φ.functor ⋙ L₂ ⋙ E₂.functor := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (CatCommSq.iso Φ.functor L₁ L₂ G).symm E₂.functor ≪≫ Functor.associator _ _ _ _ ≅ Φ.functor ⋙ L₂' := isoWhiskerLeft Φ.functor (compUniqFunctor L₂ L₂' W₂) _ ≅ L₁' ⋙ G' := CatCommSq.iso Φ.functor L₁' L₂' G' _ ≅ L₁ ⋙ E₁.functor ⋙ G' := isoWhiskerRight (compUniqFunctor L₁ L₁' W₁).symm G' ≪≫ Functor.associator _ _ _ have := Functor.isEquivalence_of_iso (liftNatIso L₁ W₁ _ _ (G ⋙ E₂.functor) (E₁.functor ⋙ G') e) Functor.isEquivalence_of_comp_left E₁.functor G' lemma isEquivalence_iff : G.IsEquivalence ↔ G'.IsEquivalence := ⟨fun _ => Φ.isEquivalence_imp L₁ L₂ G L₁' L₂' G', fun _ => Φ.isEquivalence_imp L₁' L₂' G' L₁ L₂ G⟩ end /-- Condition that a `LocalizerMorphism` induces an equivalence on the localized categories -/ class IsLocalizedEquivalence : Prop := /-- the induced functor on the constructed localized categories is an equivalence -/ isEquivalence : (Φ.localizedFunctor W₁.Q W₂.Q).IsEquivalence lemma IsLocalizedEquivalence.mk' [CatCommSq Φ.functor L₁ L₂ G] [G.IsEquivalence] : Φ.IsLocalizedEquivalence where isEquivalence := by rw [Φ.isEquivalence_iff W₁.Q W₂.Q (Φ.localizedFunctor W₁.Q W₂.Q) L₁ L₂ G] exact inferInstance /-- If a `LocalizerMorphism` is a localized equivalence, then any compatible functor between the localized categories is an equivalence. -/ lemma isEquivalence [h : Φ.IsLocalizedEquivalence] [CatCommSq Φ.functor L₁ L₂ G] : G.IsEquivalence := (by rw [Φ.isEquivalence_iff L₁ L₂ G W₁.Q W₂.Q (Φ.localizedFunctor W₁.Q W₂.Q)] exact h.isEquivalence) /-- If a `LocalizerMorphism` is a localized equivalence, then the induced functor on the localized categories is an equivalence -/ instance localizedFunctor_isEquivalence [Φ.IsLocalizedEquivalence] : (Φ.localizedFunctor L₁ L₂).IsEquivalence := Φ.isEquivalence L₁ L₂ _ /-- When `Φ : LocalizerMorphism W₁ W₂`, if the composition `Φ.functor ⋙ L₂` is a localization functor for `W₁`, then `Φ` is a localized equivalence. -/ lemma IsLocalizedEquivalence.of_isLocalization_of_isLocalization [(Φ.functor ⋙ L₂).IsLocalization W₁] : IsLocalizedEquivalence Φ := by have : CatCommSq Φ.functor (Φ.functor ⋙ L₂) L₂ (𝟭 D₂) := CatCommSq.mk (Functor.rightUnitor _).symm exact IsLocalizedEquivalence.mk' Φ (Φ.functor ⋙ L₂) L₂ (𝟭 D₂) /-- When the underlying functor `Φ.functor` of `Φ : LocalizerMorphism W₁ W₂` is an equivalence of categories and that `W₁` and `W₂` essentially correspond to each other via this equivalence, then `Φ` is a localized equivalence. -/ lemma IsLocalizedEquivalence.of_equivalence [Φ.functor.IsEquivalence] (h : W₂ ≤ W₁.map Φ.functor) : IsLocalizedEquivalence Φ := by haveI : Functor.IsLocalization (Φ.functor ⋙ MorphismProperty.Q W₂) W₁ := by refine Functor.IsLocalization.of_equivalence_source W₂.Q W₂ (Φ.functor ⋙ W₂.Q) W₁ (Functor.asEquivalence Φ.functor).symm ?_ (Φ.inverts W₂.Q) ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight ((Equivalence.unitIso _).symm) _ ≪≫ Functor.leftUnitor _) erw [W₁.isoClosure.inverseImage_equivalence_functor_eq_map_inverse] rw [MorphismProperty.map_isoClosure] exact h exact IsLocalizedEquivalence.of_isLocalization_of_isLocalization Φ W₂.Q instance IsLocalizedEquivalence.isLocalization [Φ.IsLocalizedEquivalence] : (Φ.functor ⋙ L₂).IsLocalization W₁ := Functor.IsLocalization.of_iso _ ((Φ.catCommSq W₁.Q L₂).iso).symm /-- The localizer morphism from `W₁.arrow` to `W₂.arrow` that is induced by `Φ : LocalizerMorphism W₁ W₂`. -/ @[simps] def arrow : LocalizerMorphism W₁.arrow W₂.arrow where functor := Φ.functor.mapArrow map _ _ _ hf := ⟨Φ.map _ hf.1, Φ.map _ hf.2⟩ end LocalizerMorphism end CategoryTheory
CategoryTheory\Localization\Opposite.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Predicate /-! # Localization of the opposite category If a functor `L : C ⥤ D` is a localization functor for `W : MorphismProperty C`, it is shown in this file that `L.op : Cᵒᵖ ⥤ Dᵒᵖ` is also a localization functor. -/ noncomputable section open CategoryTheory CategoryTheory.Category namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] {L : C ⥤ D} {W : MorphismProperty C} namespace Localization /-- If `L : C ⥤ D` satisfies the universal property of the localisation for `W : MorphismProperty C`, then `L.op` also does. -/ def StrictUniversalPropertyFixedTarget.op {E : Type*} [Category E] (h : StrictUniversalPropertyFixedTarget L W Eᵒᵖ) : StrictUniversalPropertyFixedTarget L.op W.op E where inverts := h.inverts.op lift F hF := (h.lift F.rightOp hF.rightOp).leftOp fac F hF := by convert congr_arg Functor.leftOp (h.fac F.rightOp hF.rightOp) uniq F₁ F₂ eq := by suffices F₁.rightOp = F₂.rightOp by rw [← F₁.rightOp_leftOp_eq, ← F₂.rightOp_leftOp_eq, this] have eq' := congr_arg Functor.rightOp eq exact h.uniq _ _ eq' instance isLocalization_op : W.Q.op.IsLocalization W.op := Functor.IsLocalization.mk' W.Q.op W.op (strictUniversalPropertyFixedTargetQ W _).op (strictUniversalPropertyFixedTargetQ W _).op end Localization variable (L W) variable [L.IsLocalization W] namespace Functor instance IsLocalization.op : L.op.IsLocalization W.op := IsLocalization.of_equivalence_target W.Q.op W.op L.op (Localization.equivalenceFromModel L W).op (NatIso.op (Localization.qCompEquivalenceFromModelFunctorIso L W).symm) end Functor namespace Localization lemma isoOfHom_unop {X Y : Cᵒᵖ} (w : X ⟶ Y) (hw : W.op w) : (isoOfHom L.op W.op w hw).unop = (isoOfHom L W w.unop hw) := by ext; rfl lemma isoOfHom_op_inv {X Y : Cᵒᵖ} (w : X ⟶ Y) (hw : W.op w) : (isoOfHom L.op W.op w hw).inv = (isoOfHom L W w.unop hw).inv.op := congr_arg Quiver.Hom.op (congr_arg Iso.inv (isoOfHom_unop L W w hw)) end Localization end CategoryTheory
CategoryTheory\Localization\Pi.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Prod import Mathlib.CategoryTheory.Localization.Equivalence import Mathlib.Data.Fintype.Option /-! # Localization of product categories In this file, it is shown that if for all `j : J` (with `J` finite), functors `L j : C j ⥤ D j` are localization functors with respect to a class of morphisms `W j : MorphismProperty (C j)`, then the product functor `Functor.pi L : (∀ j, C j) ⥤ ∀ j, D j` is a localization functor for the product class of morphisms `MorphismProperty.pi W`. The proof proceeds by induction on the cardinal of `J` using the main result of the file `Mathlib.CategoryTheory.Localization.Prod`. -/ universe w v₁ v₂ u₁ u₂ namespace CategoryTheory.Functor.IsLocalization instance pi {J : Type w} [Finite J] {C : J → Type u₁} {D : J → Type u₂} [∀ j, Category.{v₁} (C j)] [∀ j, Category.{v₂} (D j)] (L : ∀ j, C j ⥤ D j) (W : ∀ j, MorphismProperty (C j)) [∀ j, (W j).ContainsIdentities] [∀ j, (L j).IsLocalization (W j)] : (Functor.pi L).IsLocalization (MorphismProperty.pi W) := by revert J apply Finite.induction_empty_option · intro J₁ J₂ e hJ₁ C₂ D₂ _ _ L₂ W₂ _ _ let L₁ := fun j => (L₂ (e j)) let E := Pi.equivalenceOfEquiv C₂ e let E' := Pi.equivalenceOfEquiv D₂ e haveI : CatCommSq E.functor (Functor.pi L₁) (Functor.pi L₂) E'.functor := (CatCommSq.hInvEquiv E (Functor.pi L₁) (Functor.pi L₂) E').symm ⟨Iso.refl _⟩ refine IsLocalization.of_equivalences (Functor.pi L₁) (MorphismProperty.pi (fun j => (W₂ (e j)))) (Functor.pi L₂) (MorphismProperty.pi W₂) E E' ?_ (MorphismProperty.IsInvertedBy.pi _ _ (fun _ => Localization.inverts _ _)) intro _ _ f hf refine ⟨_, _, E.functor.map f, fun i => ?_, ⟨Iso.refl _⟩⟩ have H : ∀ {j j' : J₂} (h : j = j') {X Y : C₂ j} (g : X ⟶ Y) (_ : W₂ j g), W₂ j' ((Pi.eqToEquivalence C₂ h).functor.map g) := by rintro j _ rfl _ _ g hg exact hg exact H (e.apply_symm_apply i) _ (hf (e.symm i)) · intro C D _ _ L W _ _ haveI : ∀ j, IsEquivalence (L j) := by rintro ⟨⟩ refine IsLocalization.of_isEquivalence _ _ (fun _ _ _ _ => ?_) rw [MorphismProperty.isomorphisms.iff, isIso_pi_iff] rintro ⟨⟩ · intro J _ hJ C D _ _ L W _ _ let L₁ := (L none).prod (Functor.pi (fun j => L (some j))) haveI : CatCommSq (Pi.optionEquivalence C).symm.functor L₁ (Functor.pi L) (Pi.optionEquivalence D).symm.functor := ⟨NatIso.pi' (by rintro (_|i) <;> apply Iso.refl)⟩ refine IsLocalization.of_equivalences L₁ ((W none).prod (MorphismProperty.pi (fun j => W (some j)))) (Functor.pi L) _ (Pi.optionEquivalence C).symm (Pi.optionEquivalence D).symm ?_ ?_ · intro ⟨X₁, X₂⟩ ⟨Y₁, Y₂⟩ f ⟨hf₁, hf₂⟩ refine ⟨_, _, (Pi.optionEquivalence C).inverse.map f, ?_, ⟨Iso.refl _⟩⟩ rintro (_|i) · exact hf₁ · apply hf₂ · apply MorphismProperty.IsInvertedBy.pi rintro (_|i) <;> apply Localization.inverts /-- If `L : C ⥤ D` is a localization functor for `W : MorphismProperty C`, then the induced functor `(Discrete J ⥤ C) ⥤ (Discrete J ⥤ D)` is also a localization for `W.functorCategory (Discrete J)` if `W` contains identities. -/ instance {J : Type} [Finite J] {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (L : C ⥤ D) (W : MorphismProperty C) [W.ContainsIdentities] [L.IsLocalization W] : ((whiskeringRight (Discrete J) C D).obj L).IsLocalization (W.functorCategory (Discrete J)) := by let E := piEquivalenceFunctorDiscrete J C let E' := piEquivalenceFunctorDiscrete J D let L₂ := (whiskeringRight (Discrete J) C D).obj L let L₁ := Functor.pi (fun (_ : J) => L) have : CatCommSq E.functor L₁ L₂ E'.functor := ⟨(Functor.rightUnitor _).symm ≪≫ isoWhiskerLeft _ E'.counitIso.symm ≪≫ Functor.associator _ _ _≪≫ isoWhiskerLeft _ ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (by exact Iso.refl _) _) ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight E.unitIso.symm L₁) _ ≪≫ isoWhiskerRight L₁.leftUnitor _⟩ refine Functor.IsLocalization.of_equivalences L₁ (MorphismProperty.pi (fun _ => W)) L₂ _ E E' ?_ ?_ · intro X Y f hf exact MorphismProperty.le_isoClosure _ _ (fun ⟨j⟩ => hf j) · intro X Y f hf have : ∀ (j : Discrete J), IsIso ((L₂.map f).app j) := fun j => Localization.inverts L W _ (hf j) apply NatIso.isIso_of_isIso_app end CategoryTheory.Functor.IsLocalization
CategoryTheory\Localization\Predicate.lean
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Construction /-! # Predicate for localized categories In this file, a predicate `L.IsLocalization W` is introduced for a functor `L : C ⥤ D` and `W : MorphismProperty C`: it expresses that `L` identifies `D` with the localized category of `C` with respect to `W` (up to equivalence). We introduce a universal property `StrictUniversalPropertyFixedTarget L W E` which states that `L` inverts the morphisms in `W` and that all functors `C ⥤ E` inverting `W` uniquely factors as a composition of `L ⋙ G` with `G : D ⥤ E`. Such universal properties are inputs for the constructor `IsLocalization.mk'` for `L.IsLocalization W`. When `L : C ⥤ D` is a localization functor for `W : MorphismProperty` (i.e. when `[L.IsLocalization W]` holds), for any category `E`, there is an equivalence `FunctorEquivalence L W E : (D ⥤ E) ≌ (W.FunctorsInverting E)` that is induced by the composition with the functor `L`. When two functors `F : C ⥤ E` and `F' : D ⥤ E` correspond via this equivalence, we shall say that `F'` lifts `F`, and the associated isomorphism `L ⋙ F' ≅ F` is the datum that is part of the class `Lifting L W F F'`. The functions `liftNatTrans` and `liftNatIso` can be used to lift natural transformations and natural isomorphisms between functors. -/ noncomputable section namespace CategoryTheory open Category variable {C D : Type*} [Category C] [Category D] (L : C ⥤ D) (W : MorphismProperty C) (E : Type*) [Category E] namespace Functor /-- The predicate expressing that, up to equivalence, a functor `L : C ⥤ D` identifies the category `D` with the localized category of `C` with respect to `W : MorphismProperty C`. -/ class IsLocalization : Prop where /-- the functor inverts the given `MorphismProperty` -/ inverts : W.IsInvertedBy L /-- the induced functor from the constructed localized category is an equivalence -/ isEquivalence : IsEquivalence (Localization.Construction.lift L inverts) instance q_isLocalization : W.Q.IsLocalization W where inverts := W.Q_inverts isEquivalence := by suffices Localization.Construction.lift W.Q W.Q_inverts = 𝟭 _ by rw [this] infer_instance apply Localization.Construction.uniq simp only [Localization.Construction.fac] rfl end Functor namespace Localization /-- This universal property states that a functor `L : C ⥤ D` inverts morphisms in `W` and the all functors `D ⥤ E` (for a fixed category `E`) uniquely factors through `L`. -/ structure StrictUniversalPropertyFixedTarget where /-- the functor `L` inverts `W` -/ inverts : W.IsInvertedBy L /-- any functor `C ⥤ E` which inverts `W` can be lifted as a functor `D ⥤ E` -/ lift : ∀ (F : C ⥤ E) (_ : W.IsInvertedBy F), D ⥤ E /-- there is a factorisation involving the lifted functor -/ fac : ∀ (F : C ⥤ E) (hF : W.IsInvertedBy F), L ⋙ lift F hF = F /-- uniqueness of the lifted functor -/ uniq : ∀ (F₁ F₂ : D ⥤ E) (_ : L ⋙ F₁ = L ⋙ F₂), F₁ = F₂ /-- The localized category `W.Localization` that was constructed satisfies the universal property of the localization. -/ @[simps] def strictUniversalPropertyFixedTargetQ : StrictUniversalPropertyFixedTarget W.Q W E where inverts := W.Q_inverts lift := Construction.lift fac := Construction.fac uniq := Construction.uniq instance : Inhabited (StrictUniversalPropertyFixedTarget W.Q W E) := ⟨strictUniversalPropertyFixedTargetQ _ _⟩ /-- When `W` consists of isomorphisms, the identity satisfies the universal property of the localization. -/ @[simps] def strictUniversalPropertyFixedTargetId (hW : W ≤ MorphismProperty.isomorphisms C) : StrictUniversalPropertyFixedTarget (𝟭 C) W E where inverts X Y f hf := hW f hf lift F _ := F fac F hF := by cases F rfl uniq F₁ F₂ eq := by cases F₁ cases F₂ exact eq end Localization namespace Functor theorem IsLocalization.mk' (h₁ : Localization.StrictUniversalPropertyFixedTarget L W D) (h₂ : Localization.StrictUniversalPropertyFixedTarget L W W.Localization) : IsLocalization L W := { inverts := h₁.inverts isEquivalence := IsEquivalence.mk' (h₂.lift W.Q W.Q_inverts) (eqToIso (Localization.Construction.uniq _ _ (by simp only [← Functor.assoc, Localization.Construction.fac, h₂.fac, Functor.comp_id]))) (eqToIso (h₁.uniq _ _ (by simp only [← Functor.assoc, h₂.fac, Localization.Construction.fac, Functor.comp_id]))) } theorem IsLocalization.for_id (hW : W ≤ MorphismProperty.isomorphisms C) : (𝟭 C).IsLocalization W := IsLocalization.mk' _ _ (Localization.strictUniversalPropertyFixedTargetId W _ hW) (Localization.strictUniversalPropertyFixedTargetId W _ hW) end Functor namespace Localization variable [L.IsLocalization W] theorem inverts : W.IsInvertedBy L := (inferInstance : L.IsLocalization W).inverts /-- The isomorphism `L.obj X ≅ L.obj Y` that is deduced from a morphism `f : X ⟶ Y` which belongs to `W`, when `L.IsLocalization W`. -/ @[simps! hom] def isoOfHom {X Y : C} (f : X ⟶ Y) (hf : W f) : L.obj X ≅ L.obj Y := haveI : IsIso (L.map f) := inverts L W f hf asIso (L.map f) @[reassoc (attr := simp)] lemma isoOfHom_hom_inv_id {X Y : C} (f : X ⟶ Y) (hf : W f) : L.map f ≫ (isoOfHom L W f hf).inv = 𝟙 _ := (isoOfHom L W f hf).hom_inv_id @[reassoc (attr := simp)] lemma isoOfHom_inv_hom_id {X Y : C} (f : X ⟶ Y) (hf : W f) : (isoOfHom L W f hf).inv ≫ L.map f = 𝟙 _ := (isoOfHom L W f hf).inv_hom_id @[simp] lemma isoOfHom_id_inv (X : C) (hX : W (𝟙 X)) : (isoOfHom L W (𝟙 X) hX).inv = 𝟙 _ := by rw [← cancel_mono (isoOfHom L W (𝟙 X) hX).hom, Iso.inv_hom_id, id_comp, isoOfHom_hom, Functor.map_id] variable {W} lemma Construction.wIso_eq_isoOfHom {X Y : C} (f : X ⟶ Y) (hf : W f) : Construction.wIso f hf = isoOfHom W.Q W f hf := by ext; rfl lemma Construction.wInv_eq_isoOfHom_inv {X Y : C} (f : X ⟶ Y) (hf : W f) : Construction.wInv f hf = (isoOfHom W.Q W f hf).inv := congr_arg Iso.inv (wIso_eq_isoOfHom f hf) instance : (Localization.Construction.lift L (inverts L W)).IsEquivalence := (inferInstance : L.IsLocalization W).isEquivalence variable (W) /-- A chosen equivalence of categories `W.Localization ≅ D` for a functor `L : C ⥤ D` which satisfies `L.IsLocalization W`. This shall be used in order to deduce properties of `L` from properties of `W.Q`. -/ def equivalenceFromModel : W.Localization ≌ D := (Localization.Construction.lift L (inverts L W)).asEquivalence /-- Via the equivalence of categories `equivalence_from_model L W : W.localization ≌ D`, one may identify the functors `W.Q` and `L`. -/ def qCompEquivalenceFromModelFunctorIso : W.Q ⋙ (equivalenceFromModel L W).functor ≅ L := eqToIso (Construction.fac _ _) /-- Via the equivalence of categories `equivalence_from_model L W : W.localization ≌ D`, one may identify the functors `L` and `W.Q`. -/ def compEquivalenceFromModelInverseIso : L ⋙ (equivalenceFromModel L W).inverse ≅ W.Q := calc L ⋙ (equivalenceFromModel L W).inverse ≅ _ := isoWhiskerRight (qCompEquivalenceFromModelFunctorIso L W).symm _ _ ≅ W.Q ⋙ (equivalenceFromModel L W).functor ⋙ (equivalenceFromModel L W).inverse := (Functor.associator _ _ _) _ ≅ W.Q ⋙ 𝟭 _ := isoWhiskerLeft _ (equivalenceFromModel L W).unitIso.symm _ ≅ W.Q := Functor.rightUnitor _ theorem essSurj (W) [L.IsLocalization W] : L.EssSurj := ⟨fun X => ⟨(Construction.objEquiv W).invFun ((equivalenceFromModel L W).inverse.obj X), Nonempty.intro ((qCompEquivalenceFromModelFunctorIso L W).symm.app _ ≪≫ (equivalenceFromModel L W).counitIso.app X)⟩⟩ /-- The functor `(D ⥤ E) ⥤ W.functors_inverting E` induced by the composition with a localization functor `L : C ⥤ D` with respect to `W : morphism_property C`. -/ def whiskeringLeftFunctor : (D ⥤ E) ⥤ W.FunctorsInverting E := FullSubcategory.lift _ ((whiskeringLeft _ _ E).obj L) (MorphismProperty.IsInvertedBy.of_comp W L (inverts L W)) instance : (whiskeringLeftFunctor L W E).IsEquivalence := by let iso : (whiskeringLeft (MorphismProperty.Localization W) D E).obj (equivalenceFromModel L W).functor ⋙ (Construction.whiskeringLeftEquivalence W E).functor ≅ whiskeringLeftFunctor L W E := NatIso.ofComponents (fun F => eqToIso (by ext change (W.Q ⋙ Localization.Construction.lift L (inverts L W)) ⋙ F = L ⋙ F rw [Construction.fac])) (fun τ => by ext dsimp [Construction.whiskeringLeftEquivalence, equivalenceFromModel, whiskerLeft] erw [NatTrans.comp_app, NatTrans.comp_app, eqToHom_app, eqToHom_app, eqToHom_refl, eqToHom_refl, comp_id, id_comp] · rfl all_goals change (W.Q ⋙ Localization.Construction.lift L (inverts L W)) ⋙ _ = L ⋙ _ rw [Construction.fac]) exact Functor.isEquivalence_of_iso iso /-- The equivalence of categories `(D ⥤ E) ≌ (W.FunctorsInverting E)` induced by the composition with a localization functor `L : C ⥤ D` with respect to `W : MorphismProperty C`. -/ def functorEquivalence : D ⥤ E ≌ W.FunctorsInverting E := (whiskeringLeftFunctor L W E).asEquivalence /-- The functor `(D ⥤ E) ⥤ (C ⥤ E)` given by the composition with a localization functor `L : C ⥤ D` with respect to `W : MorphismProperty C`. -/ @[nolint unusedArguments] def whiskeringLeftFunctor' [L.IsLocalization W] (E : Type*) [Category E] : (D ⥤ E) ⥤ C ⥤ E := (whiskeringLeft C D E).obj L theorem whiskeringLeftFunctor'_eq : whiskeringLeftFunctor' L W E = Localization.whiskeringLeftFunctor L W E ⋙ inducedFunctor _ := rfl variable {E} in @[simp] theorem whiskeringLeftFunctor'_obj (F : D ⥤ E) : (whiskeringLeftFunctor' L W E).obj F = L ⋙ F := rfl instance : (whiskeringLeftFunctor' L W E).Full := by rw [whiskeringLeftFunctor'_eq] apply @Functor.Full.comp _ _ _ _ _ _ _ _ ?_ ?_ · infer_instance apply InducedCategory.full -- why is it not found automatically ??? instance : (whiskeringLeftFunctor' L W E).Faithful := by rw [whiskeringLeftFunctor'_eq] apply @Functor.Faithful.comp _ _ _ _ _ _ _ _ ?_ ?_ · infer_instance apply InducedCategory.faithful -- why is it not found automatically ??? lemma full_whiskeringLeft (L : C ⥤ D) (W) [L.IsLocalization W] (E : Type*) [Category E] : ((whiskeringLeft C D E).obj L).Full := inferInstanceAs (whiskeringLeftFunctor' L W E).Full lemma faithful_whiskeringLeft (L : C ⥤ D) (W) [L.IsLocalization W] (E : Type*) [Category E] : ((whiskeringLeft C D E).obj L).Faithful := inferInstanceAs (whiskeringLeftFunctor' L W E).Faithful variable {E} theorem natTrans_ext (L : C ⥤ D) (W) [L.IsLocalization W] {F₁ F₂ : D ⥤ E} (τ τ' : F₁ ⟶ F₂) (h : ∀ X : C, τ.app (L.obj X) = τ'.app (L.obj X)) : τ = τ' := by haveI := essSurj L W ext Y rw [← cancel_epi (F₁.map (L.objObjPreimageIso Y).hom), τ.naturality, τ'.naturality, h] -- Porting note: the field `iso` was renamed `Lifting.iso'` and it was redefined as -- `Lifting.iso` with explicit parameters /-- When `L : C ⥤ D` is a localization functor for `W : MorphismProperty C` and `F : C ⥤ E` is a functor, we shall say that `F' : D ⥤ E` lifts `F` if the obvious diagram is commutative up to an isomorphism. -/ class Lifting (W : MorphismProperty C) (F : C ⥤ E) (F' : D ⥤ E) where /-- the isomorphism relating the localization functor and the two other given functors -/ iso' : L ⋙ F' ≅ F /-- The distinguished isomorphism `L ⋙ F' ≅ F` given by `[Lifting L W F F']`. -/ def Lifting.iso (F : C ⥤ E) (F' : D ⥤ E) [Lifting L W F F'] : L ⋙ F' ≅ F := Lifting.iso' W variable {W} /-- Given a localization functor `L : C ⥤ D` for `W : MorphismProperty C` and a functor `F : C ⥤ E` which inverts `W`, this is a choice of functor `D ⥤ E` which lifts `F`. -/ def lift (F : C ⥤ E) (hF : W.IsInvertedBy F) (L : C ⥤ D) [L.IsLocalization W] : D ⥤ E := (functorEquivalence L W E).inverse.obj ⟨F, hF⟩ instance liftingLift (F : C ⥤ E) (hF : W.IsInvertedBy F) (L : C ⥤ D) [L.IsLocalization W] : Lifting L W F (lift F hF L) := ⟨(inducedFunctor _).mapIso ((functorEquivalence L W E).counitIso.app ⟨F, hF⟩)⟩ -- Porting note: removed the unnecessary @[simps] attribute /-- The canonical isomorphism `L ⋙ lift F hF L ≅ F` for any functor `F : C ⥤ E` which inverts `W`, when `L : C ⥤ D` is a localization functor for `W`. -/ def fac (F : C ⥤ E) (hF : W.IsInvertedBy F) (L : C ⥤ D) [L.IsLocalization W] : L ⋙ lift F hF L ≅ F := Lifting.iso L W F _ instance liftingConstructionLift (F : C ⥤ D) (hF : W.IsInvertedBy F) : Lifting W.Q W F (Construction.lift F hF) := ⟨eqToIso (Construction.fac F hF)⟩ variable (W) /-- Given a localization functor `L : C ⥤ D` for `W : MorphismProperty C`, if `(F₁' F₂' : D ⥤ E)` are functors which lifts functors `(F₁ F₂ : C ⥤ E)`, a natural transformation `τ : F₁ ⟶ F₂` uniquely lifts to a natural transformation `F₁' ⟶ F₂'`. -/ def liftNatTrans (F₁ F₂ : C ⥤ E) (F₁' F₂' : D ⥤ E) [Lifting L W F₁ F₁'] [Lifting L W F₂ F₂'] (τ : F₁ ⟶ F₂) : F₁' ⟶ F₂' := (whiskeringLeftFunctor' L W E).preimage ((Lifting.iso L W F₁ F₁').hom ≫ τ ≫ (Lifting.iso L W F₂ F₂').inv) @[simp] theorem liftNatTrans_app (F₁ F₂ : C ⥤ E) (F₁' F₂' : D ⥤ E) [Lifting L W F₁ F₁'] [Lifting L W F₂ F₂'] (τ : F₁ ⟶ F₂) (X : C) : (liftNatTrans L W F₁ F₂ F₁' F₂' τ).app (L.obj X) = (Lifting.iso L W F₁ F₁').hom.app X ≫ τ.app X ≫ (Lifting.iso L W F₂ F₂').inv.app X := congr_app (Functor.map_preimage (whiskeringLeftFunctor' L W E) _) X @[reassoc (attr := simp)] theorem comp_liftNatTrans (F₁ F₂ F₃ : C ⥤ E) (F₁' F₂' F₃' : D ⥤ E) [h₁ : Lifting L W F₁ F₁'] [h₂ : Lifting L W F₂ F₂'] [h₃ : Lifting L W F₃ F₃'] (τ : F₁ ⟶ F₂) (τ' : F₂ ⟶ F₃) : liftNatTrans L W F₁ F₂ F₁' F₂' τ ≫ liftNatTrans L W F₂ F₃ F₂' F₃' τ' = liftNatTrans L W F₁ F₃ F₁' F₃' (τ ≫ τ') := natTrans_ext L W _ _ fun X => by simp only [NatTrans.comp_app, liftNatTrans_app, assoc, Iso.inv_hom_id_app_assoc] @[simp] theorem liftNatTrans_id (F : C ⥤ E) (F' : D ⥤ E) [h : Lifting L W F F'] : liftNatTrans L W F F F' F' (𝟙 F) = 𝟙 F' := natTrans_ext L W _ _ fun X => by simp only [liftNatTrans_app, NatTrans.id_app, id_comp, Iso.hom_inv_id_app] rfl /-- Given a localization functor `L : C ⥤ D` for `W : MorphismProperty C`, if `(F₁' F₂' : D ⥤ E)` are functors which lifts functors `(F₁ F₂ : C ⥤ E)`, a natural isomorphism `τ : F₁ ⟶ F₂` lifts to a natural isomorphism `F₁' ⟶ F₂'`. -/ @[simps] def liftNatIso (F₁ F₂ : C ⥤ E) (F₁' F₂' : D ⥤ E) [h₁ : Lifting L W F₁ F₁'] [h₂ : Lifting L W F₂ F₂'] (e : F₁ ≅ F₂) : F₁' ≅ F₂' where hom := liftNatTrans L W F₁ F₂ F₁' F₂' e.hom inv := liftNatTrans L W F₂ F₁ F₂' F₁' e.inv namespace Lifting @[simps] instance compRight {E' : Type*} [Category E'] (F : C ⥤ E) (F' : D ⥤ E) [Lifting L W F F'] (G : E ⥤ E') : Lifting L W (F ⋙ G) (F' ⋙ G) := ⟨isoWhiskerRight (iso L W F F') G⟩ @[simps] instance id : Lifting L W L (𝟭 D) := ⟨Functor.rightUnitor L⟩ @[simps] instance compLeft (F : D ⥤ E) : Localization.Lifting L W (L ⋙ F) F := ⟨Iso.refl _⟩ @[simp] lemma compLeft_iso (W) (F : D ⥤ E) : Localization.Lifting.iso L W (L ⋙ F) F = Iso.refl _ := rfl /-- Given a localization functor `L : C ⥤ D` for `W : MorphismProperty C`, if `F₁' : D ⥤ E` lifts a functor `F₁ : C ⥤ D`, then a functor `F₂'` which is isomorphic to `F₁'` also lifts a functor `F₂` that is isomorphic to `F₁`. -/ @[simps] def ofIsos {F₁ F₂ : C ⥤ E} {F₁' F₂' : D ⥤ E} (e : F₁ ≅ F₂) (e' : F₁' ≅ F₂') [Lifting L W F₁ F₁'] : Lifting L W F₂ F₂' := ⟨isoWhiskerLeft L e'.symm ≪≫ iso L W F₁ F₁' ≪≫ e⟩ end Lifting end Localization namespace Functor namespace IsLocalization open Localization theorem of_iso {L₁ L₂ : C ⥤ D} (e : L₁ ≅ L₂) [L₁.IsLocalization W] : L₂.IsLocalization W := by have h := Localization.inverts L₁ W rw [MorphismProperty.IsInvertedBy.iff_of_iso W e] at h let F₁ := Localization.Construction.lift L₁ (Localization.inverts L₁ W) let F₂ := Localization.Construction.lift L₂ h exact { inverts := h isEquivalence := Functor.isEquivalence_of_iso (liftNatIso W.Q W L₁ L₂ F₁ F₂ e) } /-- If `L : C ⥤ D` is a localization for `W : MorphismProperty C`, then it is also the case of a functor obtained by post-composing `L` with an equivalence of categories. -/ theorem of_equivalence_target {E : Type*} [Category E] (L' : C ⥤ E) (eq : D ≌ E) [L.IsLocalization W] (e : L ⋙ eq.functor ≅ L') : L'.IsLocalization W := by have h : W.IsInvertedBy L' := by rw [← MorphismProperty.IsInvertedBy.iff_of_iso W e] exact MorphismProperty.IsInvertedBy.of_comp W L (Localization.inverts L W) eq.functor let F₁ := Localization.Construction.lift L (Localization.inverts L W) let F₂ := Localization.Construction.lift L' h let e' : F₁ ⋙ eq.functor ≅ F₂ := liftNatIso W.Q W (L ⋙ eq.functor) L' _ _ e exact { inverts := h isEquivalence := Functor.isEquivalence_of_iso e' } instance (F : D ⥤ E) [F.IsEquivalence] [L.IsLocalization W] : (L ⋙ F).IsLocalization W := of_equivalence_target L W _ F.asEquivalence (Iso.refl _) lemma of_isEquivalence (L : C ⥤ D) (W : MorphismProperty C) (hW : W ≤ MorphismProperty.isomorphisms C) [IsEquivalence L] : L.IsLocalization W := by haveI : (𝟭 C).IsLocalization W := for_id W hW exact of_equivalence_target (𝟭 C) W L L.asEquivalence L.leftUnitor end IsLocalization end Functor namespace Localization variable {D₁ D₂ : Type _} [Category D₁] [Category D₂] (L₁ : C ⥤ D₁) (L₂ : C ⥤ D₂) (W' : MorphismProperty C) [L₁.IsLocalization W'] [L₂.IsLocalization W'] /-- If `L₁ : C ⥤ D₁` and `L₂ : C ⥤ D₂` are two localization functors for the same `MorphismProperty C`, this is an equivalence of categories `D₁ ≌ D₂`. -/ def uniq : D₁ ≌ D₂ := (equivalenceFromModel L₁ W').symm.trans (equivalenceFromModel L₂ W') lemma uniq_symm : (uniq L₁ L₂ W').symm = uniq L₂ L₁ W' := rfl /-- The functor of equivalence of localized categories given by `Localization.uniq` is compatible with the localization functors. -/ def compUniqFunctor : L₁ ⋙ (uniq L₁ L₂ W').functor ≅ L₂ := calc L₁ ⋙ (uniq L₁ L₂ W').functor ≅ (L₁ ⋙ (equivalenceFromModel L₁ W').inverse) ⋙ (equivalenceFromModel L₂ W').functor := (Functor.associator _ _ _).symm _ ≅ W'.Q ⋙ (equivalenceFromModel L₂ W').functor := isoWhiskerRight (compEquivalenceFromModelInverseIso L₁ W') _ _ ≅ L₂ := qCompEquivalenceFromModelFunctorIso L₂ W' /-- The inverse functor of equivalence of localized categories given by `Localization.uniq` is compatible with the localization functors. -/ def compUniqInverse : L₂ ⋙ (uniq L₁ L₂ W').inverse ≅ L₁ := compUniqFunctor L₂ L₁ W' instance : Lifting L₁ W' L₂ (uniq L₁ L₂ W').functor := ⟨compUniqFunctor L₁ L₂ W'⟩ instance : Lifting L₂ W' L₁ (uniq L₁ L₂ W').inverse := ⟨compUniqInverse L₁ L₂ W'⟩ /-- If `L₁ : C ⥤ D₁` and `L₂ : C ⥤ D₂` are two localization functors for the same `MorphismProperty C`, any functor `F : D₁ ⥤ D₂` equipped with an isomorphism `L₁ ⋙ F ≅ L₂` is isomorphic to the functor of the equivalence given by `uniq`. -/ def isoUniqFunctor (F : D₁ ⥤ D₂) (e : L₁ ⋙ F ≅ L₂) : F ≅ (uniq L₁ L₂ W').functor := letI : Lifting L₁ W' L₂ F := ⟨e⟩ liftNatIso L₁ W' L₂ L₂ F (uniq L₁ L₂ W').functor (Iso.refl L₂) end Localization section variable {X Y : C} (f g : X ⟶ Y) /-- The property that two morphisms become equal in the localized category. -/ def AreEqualizedByLocalization : Prop := W.Q.map f = W.Q.map g lemma areEqualizedByLocalization_iff [L.IsLocalization W] : AreEqualizedByLocalization W f g ↔ L.map f = L.map g := by dsimp [AreEqualizedByLocalization] constructor · intro h let e := Localization.compUniqFunctor W.Q L W rw [← NatIso.naturality_1 e f, ← NatIso.naturality_1 e g] dsimp rw [h] · intro h let e := Localization.compUniqFunctor L W.Q W rw [← NatIso.naturality_1 e f, ← NatIso.naturality_1 e g] dsimp rw [h] namespace AreEqualizedByLocalization lemma mk (L : C ⥤ D) [L.IsLocalization W] (h : L.map f = L.map g) : AreEqualizedByLocalization W f g := (areEqualizedByLocalization_iff L W f g).2 h variable {W f g} lemma map_eq (h : AreEqualizedByLocalization W f g) (L : C ⥤ D) [L.IsLocalization W] : L.map f = L.map g := (areEqualizedByLocalization_iff L W f g).1 h end AreEqualizedByLocalization end end CategoryTheory
CategoryTheory\Localization\Prod.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Localization.Predicate import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Localization of product categories In this file, it is shown that if functors `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` are localization functors for morphisms properties `W₁` and `W₂`, then the product functor `C₁ × C₂ ⥤ D₁ × D₂` is a localization functor for `W₁.prod W₂ : MorphismProperty (C₁ × C₂)`, at least if both `W₁` and `W₂` contain identities. This main result is the instance `Functor.IsLocalization.prod`. The proof proceeds by showing first `Localization.Construction.prodIsLocalization`, which asserts that this holds for the localization functors `W₁.Q` and `W₂.Q` to the constructed localized categories: this is done by showing that the product functor `W₁.Q.prod W₂.Q : C₁ × C₂ ⥤ W₁.Localization × W₂.Localization` satisfies the strict universal property of the localization for `W₁.prod W₂`. The general case follows by transporting this result through equivalences of categories. -/ universe v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅ namespace CategoryTheory variable {C₁ : Type u₁} {C₂ : Type u₂} {D₁ : Type u₃} {D₂ : Type u₄} [Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} D₁] [Category.{v₄} D₂] (L₁ : C₁ ⥤ D₁) {W₁ : MorphismProperty C₁} (L₂ : C₂ ⥤ D₂) {W₂ : MorphismProperty C₂} namespace Localization namespace StrictUniversalPropertyFixedTarget variable {E : Type u₅} [Category.{v₅} E] (F : C₁ × C₂ ⥤ E) lemma prod_uniq (F₁ F₂ : (W₁.Localization × W₂.Localization ⥤ E)) (h : (W₁.Q.prod W₂.Q) ⋙ F₁ = (W₁.Q.prod W₂.Q) ⋙ F₂) : F₁ = F₂ := by apply Functor.curry_obj_injective apply Construction.uniq apply Functor.flip_injective apply Construction.uniq apply Functor.flip_injective apply Functor.uncurry_obj_injective simpa only [Functor.uncurry_obj_curry_obj_flip_flip] using h /-- Auxiliary definition for `prodLift`. -/ noncomputable def prodLift₁ [W₂.ContainsIdentities] (hF : (W₁.prod W₂).IsInvertedBy F) : W₁.Localization ⥤ C₂ ⥤ E := Construction.lift (curry.obj F) (fun _ _ f₁ hf₁ => by haveI : ∀ (X₂ : C₂), IsIso (((curry.obj F).map f₁).app X₂) := fun X₂ => hF _ ⟨hf₁, MorphismProperty.id_mem _ _⟩ apply NatIso.isIso_of_isIso_app) variable (hF : (W₁.prod W₂).IsInvertedBy F) lemma prod_fac₁ [W₂.ContainsIdentities] : W₁.Q ⋙ prodLift₁ F hF = curry.obj F := Construction.fac _ _ variable [W₁.ContainsIdentities] [W₂.ContainsIdentities] /-- The lifting of a functor `F : C₁ × C₂ ⥤ E` inverting `W₁.prod W₂` to a functor `W₁.Localization × W₂.Localization ⥤ E` -/ noncomputable def prodLift : W₁.Localization × W₂.Localization ⥤ E := by refine uncurry.obj (Construction.lift (prodLift₁ F hF).flip ?_).flip intro _ _ f₂ hf₂ haveI : ∀ (X₁ : W₁.Localization), IsIso (((Functor.flip (prodLift₁ F hF)).map f₂).app X₁) := fun X₁ => by obtain ⟨X₁, rfl⟩ := (Construction.objEquiv W₁).surjective X₁ exact ((MorphismProperty.isomorphisms E).arrow_mk_iso_iff (((Functor.mapArrowFunctor _ _).mapIso (eqToIso (Functor.congr_obj (prod_fac₁ F hF) X₁))).app (Arrow.mk f₂))).2 (hF _ ⟨MorphismProperty.id_mem _ _, hf₂⟩) apply NatIso.isIso_of_isIso_app lemma prod_fac₂ : W₂.Q ⋙ (curry.obj (prodLift F hF)).flip = (prodLift₁ F hF).flip := by simp only [prodLift, Functor.curry_obj_uncurry_obj, Functor.flip_flip] apply Construction.fac lemma prod_fac : (W₁.Q.prod W₂.Q) ⋙ prodLift F hF = F := by rw [← Functor.uncurry_obj_curry_obj_flip_flip', prod_fac₂, Functor.flip_flip, prod_fac₁, Functor.uncurry_obj_curry_obj] variable (W₁ W₂) /-- The product of two (constructed) localized categories satisfies the universal property of the localized category of the product. -/ noncomputable def prod : StrictUniversalPropertyFixedTarget (W₁.Q.prod W₂.Q) (W₁.prod W₂) E where inverts := (Localization.inverts W₁.Q W₁).prod (Localization.inverts W₂.Q W₂) lift := fun F hF => prodLift F hF fac := fun F hF => prod_fac F hF uniq := prod_uniq end StrictUniversalPropertyFixedTarget variable (W₁ W₂) variable [W₁.ContainsIdentities] [W₂.ContainsIdentities] lemma Construction.prodIsLocalization : (W₁.Q.prod W₂.Q).IsLocalization (W₁.prod W₂) := Functor.IsLocalization.mk' _ _ (StrictUniversalPropertyFixedTarget.prod W₁ W₂) (StrictUniversalPropertyFixedTarget.prod W₁ W₂) end Localization open Localization namespace Functor namespace IsLocalization variable (W₁ W₂) variable [W₁.ContainsIdentities] [W₂.ContainsIdentities] /-- If `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` are localization functors for `W₁ : MorphismProperty C₁` and `W₂ : MorphismProperty C₂` respectively, and if both `W₁` and `W₂` contain identites, then the product functor `L₁.prod L₂ : C₁ × C₂ ⥤ D₁ × D₂` is a localization functor for `W₁.prod W₂`. -/ instance prod [L₁.IsLocalization W₁] [L₂.IsLocalization W₂] : (L₁.prod L₂).IsLocalization (W₁.prod W₂) := by haveI := Construction.prodIsLocalization W₁ W₂ exact of_equivalence_target (W₁.Q.prod W₂.Q) (W₁.prod W₂) (L₁.prod L₂) ((uniq W₁.Q L₁ W₁).prod (uniq W₂.Q L₂ W₂)) (NatIso.prod (compUniqFunctor W₁.Q L₁ W₁) (compUniqFunctor W₂.Q L₂ W₂)) end IsLocalization end Functor end CategoryTheory
CategoryTheory\Localization\Resolution.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.LocalizerMorphism /-! # Resolutions for a morphism of localizers Given a morphism of localizers `Φ : LocalizerMorphism W₁ W₂` (i.e. `W₁` and `W₂` are morphism properties on categories `C₁` and `C₂`, and we have a functor `Φ.functor : C₁ ⥤ C₂` which sends morphisms in `W₁` to morphisms in `W₂`), we introduce the notion of right resolutions of objects in `C₂`: if `X₂ : C₂`. A right resolution consists of an object `X₁ : C₁` and a morphism `w : X₂ ⟶ Φ.functor.obj X₁` that is in `W₂`. Then, the typeclass `Φ.HasRightResolutions` holds when any `X₂ : C₂` has a right resolution. The type of right resolutions `Φ.RightResolution X₂` is endowed with a category structure when the morphism property `W₁` is multiplicative. Similiar definitions are done from left resolutions. ## Future works * formalize right derivability structures as localizer morphisms admitting right resolutions and forming a Guitart exact square, as it is defined in [the paper by Kahn and Maltsiniotis][KahnMaltsiniotis2008] (TODO @joelriou) * show that if `C` is an abelian category with enough injectives, there is a derivability structure associated to the inclusion of the full subcategory of complexes of injective objects into the bounded below homotopy category of `C` (TODO @joelriou) * formalize dual results ## References * [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008] -/ universe v₁ v₂ v₂' u₁ u₂ u₂' namespace CategoryTheory open Category Localization variable {C₁ C₂ D₂ H : Type*} [Category C₁] [Category C₂] [Category D₂] [Category H] {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} namespace LocalizerMorphism variable (Φ : LocalizerMorphism W₁ W₂) /-- The category of right resolutions of an object in the target category of a localizer morphism. -/ structure RightResolution (X₂ : C₂) where /-- an object in the source category -/ {X₁ : C₁} /-- a morphism to an object of the form `Φ.functor.obj X₁` -/ w : X₂ ⟶ Φ.functor.obj X₁ hw : W₂ w /-- The category of left resolutions of an object in the target category of a localizer morphism. -/ structure LeftResolution (X₂ : C₂) where /-- an object in the source category -/ {X₁ : C₁} /-- a morphism from an object of the form `Φ.functor.obj X₁` -/ w : Φ.functor.obj X₁ ⟶ X₂ hw : W₂ w variable {Φ X₂} in lemma RightResolution.mk_surjective (R : Φ.RightResolution X₂) : ∃ (X₁ : C₁) (w : X₂ ⟶ Φ.functor.obj X₁) (hw : W₂ w), R = RightResolution.mk w hw := ⟨_, R.w, R.hw, rfl⟩ variable {Φ X₂} in lemma LeftResolution.mk_surjective (L : Φ.LeftResolution X₂) : ∃ (X₁ : C₁) (w : Φ.functor.obj X₁ ⟶ X₂) (hw : W₂ w), L = LeftResolution.mk w hw := ⟨_, L.w, L.hw, rfl⟩ /-- A localizer morphism has right resolutions when any object has a right resolution. -/ abbrev HasRightResolutions := ∀ (X₂ : C₂), Nonempty (Φ.RightResolution X₂) /-- A localizer morphism has right resolutions when any object has a right resolution. -/ abbrev HasLeftResolutions := ∀ (X₂ : C₂), Nonempty (Φ.LeftResolution X₂) namespace RightResolution variable {Φ} {X₂ : C₂} /-- The type of morphisms in the category `Φ.RightResolution X₂` (when `W₁` is multiplicative). -/ @[ext] structure Hom (R R' : Φ.RightResolution X₂) where /-- a morphism in the source category -/ f : R.X₁ ⟶ R'.X₁ hf : W₁ f comm : R.w ≫ Φ.functor.map f = R'.w := by aesop_cat attribute [reassoc (attr := simp)] Hom.comm /-- The identity of a object in `Φ.RightResolution X₂`. -/ @[simps] def Hom.id [W₁.ContainsIdentities] (R : Φ.RightResolution X₂) : Hom R R where f := 𝟙 _ hf := W₁.id_mem _ variable [W₁.IsMultiplicative] /-- The composition of morphisms in `Φ.RightResolution X₂`. -/ @[simps] def Hom.comp {R R' R'' : Φ.RightResolution X₂} (φ : Hom R R') (ψ : Hom R' R'') : Hom R R'' where f := φ.f ≫ ψ.f hf := W₁.comp_mem _ _ φ.hf ψ.hf instance : Category (Φ.RightResolution X₂) where Hom := Hom id := Hom.id comp := Hom.comp @[simp] lemma id_f (R : Φ.RightResolution X₂) : Hom.f (𝟙 R) = 𝟙 R.X₁ := rfl @[simp, reassoc] lemma comp_f {R R' R'' : Φ.RightResolution X₂} (φ : R ⟶ R') (ψ : R' ⟶ R'') : (φ ≫ ψ).f = φ.f ≫ ψ.f := rfl @[ext] lemma hom_ext {R R' : Φ.RightResolution X₂} {φ₁ φ₂ : R ⟶ R'} (h : φ₁.f = φ₂.f) : φ₁ = φ₂ := Hom.ext h end RightResolution namespace LeftResolution variable {Φ} {X₂ : C₂} /-- The type of morphisms in the category `Φ.LeftResolution X₂` (when `W₁` is multiplicative). -/ @[ext] structure Hom (L L' : Φ.LeftResolution X₂) where /-- a morphism in the source category -/ f : L.X₁ ⟶ L'.X₁ hf : W₁ f comm : Φ.functor.map f ≫ L'.w = L.w := by aesop_cat attribute [reassoc (attr := simp)] Hom.comm /-- The identity of a object in `Φ.LeftResolution X₂`. -/ @[simps] def Hom.id [W₁.ContainsIdentities] (L : Φ.LeftResolution X₂) : Hom L L where f := 𝟙 _ hf := W₁.id_mem _ variable [W₁.IsMultiplicative] /-- The composition of morphisms in `Φ.LeftResolution X₂`. -/ @[simps] def Hom.comp {L L' L'' : Φ.LeftResolution X₂} (φ : Hom L L') (ψ : Hom L' L'') : Hom L L'' where f := φ.f ≫ ψ.f hf := W₁.comp_mem _ _ φ.hf ψ.hf instance : Category (Φ.LeftResolution X₂) where Hom := Hom id := Hom.id comp := Hom.comp @[simp] lemma id_f (L : Φ.LeftResolution X₂) : Hom.f (𝟙 L) = 𝟙 L.X₁ := rfl @[simp, reassoc] lemma comp_f {L L' L'' : Φ.LeftResolution X₂} (φ : L ⟶ L') (ψ : L' ⟶ L'') : (φ ≫ ψ).f = φ.f ≫ ψ.f := rfl @[ext] lemma hom_ext {L L' : Φ.LeftResolution X₂} {φ₁ φ₂ : L ⟶ L'} (h : φ₁.f = φ₂.f) : φ₁ = φ₂ := Hom.ext h end LeftResolution variable {Φ} /-- The canonical map `Φ.LeftResolution X₂ → Φ.op.RightResolution (Opposite.op X₂)`. -/ @[simps] def LeftResolution.op {X₂ : C₂} (L : Φ.LeftResolution X₂) : Φ.op.RightResolution (Opposite.op X₂) where X₁ := Opposite.op L.X₁ w := L.w.op hw := L.hw /-- The canonical map `Φ.op.LeftResolution X₂ → Φ.RightResolution X₂`. -/ @[simps] def LeftResolution.unop {X₂ : C₂ᵒᵖ} (L : Φ.op.LeftResolution X₂) : Φ.RightResolution X₂.unop where X₁ := Opposite.unop L.X₁ w := L.w.unop hw := L.hw /-- The canonical map `Φ.RightResolution X₂ → Φ.op.LeftResolution (Opposite.op X₂)`. -/ @[simps] def RightResolution.op {X₂ : C₂} (L : Φ.RightResolution X₂) : Φ.op.LeftResolution (Opposite.op X₂) where X₁ := Opposite.op L.X₁ w := L.w.op hw := L.hw /-- The canonical map `Φ.op.RightResolution X₂ → Φ.LeftResolution X₂`. -/ @[simps] def RightResolution.unop {X₂ : C₂ᵒᵖ} (L : Φ.op.RightResolution X₂) : Φ.LeftResolution X₂.unop where X₁ := Opposite.unop L.X₁ w := L.w.unop hw := L.hw variable (Φ) lemma nonempty_leftResolution_iff_op (X₂ : C₂) : Nonempty (Φ.LeftResolution X₂) ↔ Nonempty (Φ.op.RightResolution (Opposite.op X₂)) := Equiv.nonempty_congr { toFun := fun L => L.op invFun := fun R => R.unop left_inv := fun _ => rfl right_inv := fun _ => rfl } lemma nonempty_rightResolution_iff_op (X₂ : C₂) : Nonempty (Φ.RightResolution X₂) ↔ Nonempty (Φ.op.LeftResolution (Opposite.op X₂)) := Equiv.nonempty_congr { toFun := fun R => R.op invFun := fun L => L.unop left_inv := fun _ => rfl right_inv := fun _ => rfl } lemma hasLeftResolutions_iff_op : Φ.HasLeftResolutions ↔ Φ.op.HasRightResolutions := ⟨fun _ X₂ => ⟨(Classical.arbitrary (Φ.LeftResolution X₂.unop)).op⟩, fun _ X₂ => ⟨(Classical.arbitrary (Φ.op.RightResolution (Opposite.op X₂))).unop⟩⟩ lemma hasRightResolutions_iff_op : Φ.HasRightResolutions ↔ Φ.op.HasLeftResolutions := ⟨fun _ X₂ => ⟨(Classical.arbitrary (Φ.RightResolution X₂.unop)).op⟩, fun _ X₂ => ⟨(Classical.arbitrary (Φ.op.LeftResolution (Opposite.op X₂))).unop⟩⟩ /-- The functor `(Φ.LeftResolution X₂)ᵒᵖ ⥤ Φ.op.RightResolution (Opposite.op X₂)`. -/ @[simps] def LeftResolution.opFunctor (X₂ : C₂) [W₁.IsMultiplicative] : (Φ.LeftResolution X₂)ᵒᵖ ⥤ Φ.op.RightResolution (Opposite.op X₂) where obj L := L.unop.op map φ := { f := φ.unop.f.op hf := φ.unop.hf comm := Quiver.Hom.unop_inj φ.unop.comm } /-- The functor `(Φ.op.RightResolution X₂)ᵒᵖ ⥤ Φ.LeftResolution X₂.unop`. -/ @[simps] def RightResolution.unopFunctor (X₂ : C₂ᵒᵖ) [W₁.IsMultiplicative] : (Φ.op.RightResolution X₂)ᵒᵖ ⥤ Φ.LeftResolution X₂.unop where obj R := R.unop.unop map φ := { f := φ.unop.f.unop hf := φ.unop.hf comm := Quiver.Hom.op_inj φ.unop.comm } /-- The equivalence of categories `(Φ.LeftResolution X₂)ᵒᵖ ≌ Φ.op.RightResolution (Opposite.op X₂)`. -/ @[simps] def LeftResolution.opEquivalence (X₂ : C₂) [W₁.IsMultiplicative] : (Φ.LeftResolution X₂)ᵒᵖ ≌ Φ.op.RightResolution (Opposite.op X₂) where functor := LeftResolution.opFunctor Φ X₂ inverse := (RightResolution.unopFunctor Φ (Opposite.op X₂)).rightOp unitIso := Iso.refl _ counitIso := Iso.refl _ section variable (L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂] lemma essSurj_of_hasRightResolutions [Φ.HasRightResolutions] : (Φ.functor ⋙ L₂).EssSurj where mem_essImage X₂ := by have := Localization.essSurj L₂ W₂ have R : Φ.RightResolution (L₂.objPreimage X₂) := Classical.arbitrary _ exact ⟨R.X₁, ⟨(Localization.isoOfHom L₂ W₂ _ R.hw).symm ≪≫ L₂.objObjPreimageIso X₂⟩⟩ lemma isIso_iff_of_hasRightResolutions [Φ.HasRightResolutions] {F G : D₂ ⥤ H} (α : F ⟶ G) : IsIso α ↔ ∀ (X₁ : C₁), IsIso (α.app (L₂.obj (Φ.functor.obj X₁))) := by constructor · intros infer_instance · intro hα have : ∀ (X₂ : D₂), IsIso (α.app X₂) := fun X₂ => by have := Φ.essSurj_of_hasRightResolutions L₂ rw [← NatTrans.isIso_app_iff_of_iso α ((Φ.functor ⋙ L₂).objObjPreimageIso X₂)] apply hα exact NatIso.isIso_of_isIso_app α lemma essSurj_of_hasLeftResolutions [Φ.HasLeftResolutions] : (Φ.functor ⋙ L₂).EssSurj where mem_essImage X₂ := by have := Localization.essSurj L₂ W₂ have L : Φ.LeftResolution (L₂.objPreimage X₂) := Classical.arbitrary _ exact ⟨L.X₁, ⟨Localization.isoOfHom L₂ W₂ _ L.hw ≪≫ L₂.objObjPreimageIso X₂⟩⟩ lemma isIso_iff_of_hasLeftResolutions [Φ.HasLeftResolutions] {F G : D₂ ⥤ H} (α : F ⟶ G) : IsIso α ↔ ∀ (X₁ : C₁), IsIso (α.app (L₂.obj (Φ.functor.obj X₁))) := by constructor · intros infer_instance · intro hα have : ∀ (X₂ : D₂), IsIso (α.app X₂) := fun X₂ => by have := Φ.essSurj_of_hasLeftResolutions L₂ rw [← NatTrans.isIso_app_iff_of_iso α ((Φ.functor ⋙ L₂).objObjPreimageIso X₂)] apply hα exact NatIso.isIso_of_isIso_app α end end LocalizerMorphism end CategoryTheory
CategoryTheory\Localization\SmallHom.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.HomEquiv import Mathlib.Logic.Small.Defs /-! # Shrinking morphisms in localized categories Given a class of morphisms `W : MorphismProperty C`, and two objects `X` and `Y`, we introduce a type-class `HasSmallLocalizedHom.{w} W X Y` which expresses that in the localized category with respect to `W`, the type of morphisms from `X` to `Y` is `w`-small for a certain universe `w`. Under this assumption, we define `SmallHom.{w} W X Y : Type w` as the shrunk type. For any localization functor `L : C ⥤ D` for `W`, we provide a bijection `SmallHom.equiv.{w} W L : SmallHom.{w} W X Y ≃ (L.obj X ⟶ L.obj Y)` that is compatible with the composition of morphisms. -/ universe w w' v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅ namespace CategoryTheory open Category namespace Localization variable {C : Type u₁} [Category.{v₁} C] (W : MorphismProperty C) {D : Type u₂} [Category.{v₂} D] {D' : Type u₃} [Category.{v₃} D'] section variable (L : C ⥤ D) [L.IsLocalization W] (X Y Z : C) /-- This property holds if the type of morphisms between `X` and `Y` in the localized category with respect to `W : MorphismProperty C` is small. -/ class HasSmallLocalizedHom : Prop where small : Small.{w} (W.Q.obj X ⟶ W.Q.obj Y) attribute [instance] HasSmallLocalizedHom.small variable {X Y Z} lemma hasSmallLocalizedHom_iff : HasSmallLocalizedHom.{w} W X Y ↔ Small.{w} (L.obj X ⟶ L.obj Y) := by constructor · intro h have := h.small exact small_map (homEquiv W W.Q L).symm · intro h exact ⟨small_map (homEquiv W W.Q L)⟩ lemma hasSmallLocalizedHom_of_isLocalization : HasSmallLocalizedHom.{v₂} W X Y := by rw [hasSmallLocalizedHom_iff W L] infer_instance variable (X Y) in lemma small_of_hasSmallLocalizedHom [HasSmallLocalizedHom.{w} W X Y] : Small.{w} (L.obj X ⟶ L.obj Y) := by rwa [← hasSmallLocalizedHom_iff W] lemma hasSmallLocalizedHom_iff_of_isos {X' Y' : C} (e : X ≅ X') (e' : Y ≅ Y') : HasSmallLocalizedHom.{w} W X Y ↔ HasSmallLocalizedHom.{w} W X' Y' := by simp only [hasSmallLocalizedHom_iff W W.Q] exact small_congr (Iso.homCongr (W.Q.mapIso e) (W.Q.mapIso e')) end /-- The type of morphisms from `X` to `Y` in the localized category with respect to `W : MorphismProperty C` that is shrunk to `Type w` when `HasSmallLocalizedHom.{w} W X Y` holds. -/ def SmallHom (X Y : C) [HasSmallLocalizedHom.{w} W X Y] : Type w := Shrink.{w} (W.Q.obj X ⟶ W.Q.obj Y) namespace SmallHom /-- The canonical bijection `SmallHom.{w} W X Y ≃ (L.obj X ⟶ L.obj Y)` when `L` is a localization functor for `W : MorphismProperty C` and that `HasSmallLocalizedHom.{w} W X Y` holds. -/ noncomputable def equiv (L : C ⥤ D) [L.IsLocalization W] {X Y : C} [HasSmallLocalizedHom.{w} W X Y] : SmallHom.{w} W X Y ≃ (L.obj X ⟶ L.obj Y) := letI := small_of_hasSmallLocalizedHom.{w} W W.Q X Y (equivShrink _).symm.trans (homEquiv W W.Q L) lemma equiv_equiv_symm (L : C ⥤ D) [L.IsLocalization W] (L' : C ⥤ D') [L'.IsLocalization W] (G : D ⥤ D') (e : L ⋙ G ≅ L') {X Y : C} [HasSmallLocalizedHom.{w} W X Y] (f : L.obj X ⟶ L.obj Y) : equiv W L' ((equiv W L).symm f) = e.inv.app X ≫ G.map f ≫ e.hom.app Y := by dsimp [equiv] rw [Equiv.symm_apply_apply, homEquiv_trans] apply homEquiv_eq /-- The element in `SmallHom W X Y` induced by `f : X ⟶ Y`. -/ noncomputable def mk {X Y : C} [HasSmallLocalizedHom.{w} W X Y] (f : X ⟶ Y) : SmallHom.{w} W X Y := (equiv.{w} W W.Q).symm (W.Q.map f) @[simp] lemma equiv_mk (L : C ⥤ D) [L.IsLocalization W] {X Y : C} [HasSmallLocalizedHom.{w} W X Y] (f : X ⟶ Y) : equiv.{w} W L (mk W f) = L.map f := by simp [equiv, mk] variable {W} /-- The formal inverse in `SmallHom W X Y` of a morphism `f : Y ⟶ X` such that `W f`. -/ noncomputable def mkInv {X Y : C} (f : Y ⟶ X) (hf : W f) [HasSmallLocalizedHom.{w} W X Y] : SmallHom.{w} W X Y := (equiv.{w} W W.Q).symm (Localization.isoOfHom W.Q W f hf).inv @[simp] lemma equiv_mkInv (L : C ⥤ D) [L.IsLocalization W] {X Y : C} (f : Y ⟶ X) (hf : W f) [HasSmallLocalizedHom.{w} W X Y] : equiv.{w} W L (mkInv f hf) = (Localization.isoOfHom L W f hf).inv := by simp only [equiv, mkInv, Equiv.symm_trans_apply, Equiv.symm_symm, homEquiv_symm_apply, Equiv.trans_apply, Equiv.symm_apply_apply, homEquiv_isoOfHom_inv] /-- The composition on `SmallHom W`. -/ noncomputable def comp {X Y Z : C} [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y Z] [HasSmallLocalizedHom.{w} W X Z] (α : SmallHom.{w} W X Y) (β : SmallHom.{w} W Y Z) : SmallHom.{w} W X Z := (equiv W W.Q).symm (equiv W W.Q α ≫ equiv W W.Q β) lemma equiv_comp (L : C ⥤ D) [L.IsLocalization W] {X Y Z : C} [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y Z] [HasSmallLocalizedHom.{w} W X Z] (α : SmallHom.{w} W X Y) (β : SmallHom.{w} W Y Z) : equiv W L (α.comp β) = equiv W L α ≫ equiv W L β := by letI := small_of_hasSmallLocalizedHom.{w} W W.Q X Y letI := small_of_hasSmallLocalizedHom.{w} W W.Q Y Z obtain ⟨α, rfl⟩ := (equivShrink _).surjective α obtain ⟨β, rfl⟩ := (equivShrink _).surjective β dsimp [equiv, comp] rw [Equiv.symm_apply_apply] erw [(equivShrink _).symm_apply_apply, (equivShrink _).symm_apply_apply] simp only [homEquiv_refl, homEquiv_comp] variable {X Y Z T : C} lemma mk_comp_mk [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y Z] [HasSmallLocalizedHom.{w} W X Z] (f : X ⟶ Y) (g : Y ⟶ Z) : (mk W f).comp (mk W g) = mk W (f ≫ g) := (equiv W W.Q).injective (by simp [equiv_comp]) @[simp] lemma comp_mk_id [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y Y] (α : SmallHom.{w} W X Y) : α.comp (mk W (𝟙 Y)) = α := (equiv W W.Q).injective (by simp [equiv_comp]) @[simp] lemma mk_id_comp [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W X X] (α : SmallHom.{w} W X Y) : (mk W (𝟙 X)).comp α = α := (equiv W W.Q).injective (by simp [equiv_comp]) @[simp] lemma comp_assoc [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W X Z] [HasSmallLocalizedHom.{w} W X T] [HasSmallLocalizedHom.{w} W Y Z] [HasSmallLocalizedHom.{w} W Y T] [HasSmallLocalizedHom.{w} W Z T] (α : SmallHom.{w} W X Y) (β : SmallHom.{w} W Y Z) (γ : SmallHom.{w} W Z T) : (α.comp β).comp γ = α.comp (β.comp γ) := by apply (equiv W W.Q).injective simp only [equiv_comp, assoc] @[simp] lemma mk_comp_mkInv [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y X] [HasSmallLocalizedHom.{w} W Y Y] (f : Y ⟶ X) (hf : W f) : (mk W f).comp (mkInv f hf) = mk W (𝟙 Y) := (equiv W W.Q).injective (by simp [equiv_comp]) @[simp] lemma mkInv_comp_mk [HasSmallLocalizedHom.{w} W X X] [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y X] (f : Y ⟶ X) (hf : W f) : (mkInv f hf).comp (mk W f) = mk W (𝟙 X) := (equiv W W.Q).injective (by simp [equiv_comp]) end SmallHom end Localization namespace LocalizerMorphism open Localization variable {C₁ : Type u₁} [Category.{v₁} C₁] {W₁ : MorphismProperty C₁} {C₂ : Type u₂} [Category.{v₂} C₂] {W₂ : MorphismProperty C₂} {D₁ : Type u₃} [Category.{v₃} D₁] {D₂ : Type u₄} [Category.{v₄} D₂] (Φ : LocalizerMorphism W₁ W₂) (L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂] variable {W} section variable {X Y Z : C₁} variable [HasSmallLocalizedHom.{w} W₁ X Y] [HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Y)] /-- The action of a localizer morphism on `SmallHom`. -/ noncomputable def smallHomMap (f : SmallHom.{w} W₁ X Y) : SmallHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Y) := (SmallHom.equiv W₂ W₂.Q).symm (Iso.homCongr ((CatCommSq.iso Φ.functor W₁.Q W₂.Q _).symm.app _) ((CatCommSq.iso Φ.functor W₁.Q W₂.Q _).symm.app _) ((Φ.localizedFunctor W₁.Q W₂.Q).map ((SmallHom.equiv W₁ W₁.Q) f))) lemma equiv_smallHomMap (G : D₁ ⥤ D₂) (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G) (f : SmallHom.{w} W₁ X Y) : (SmallHom.equiv W₂ L₂) (Φ.smallHomMap f) = e.hom.app X ≫ G.map (SmallHom.equiv W₁ L₁ f) ≫ e.inv.app Y := by obtain ⟨g, rfl⟩ := (SmallHom.equiv W₁ W₁.Q).symm.surjective f simp only [smallHomMap, Equiv.apply_symm_apply] let G' := Φ.localizedFunctor W₁.Q W₂.Q let β := CatCommSq.iso Φ.functor W₁.Q W₂.Q G' let E₁ := (uniq W₁.Q L₁ W₁).functor let α₁ : W₁.Q ⋙ E₁ ≅ L₁ := compUniqFunctor W₁.Q L₁ W₁ let E₂ := (uniq W₂.Q L₂ W₂).functor let α₂ : W₂.Q ⋙ E₂ ≅ L₂ := compUniqFunctor W₂.Q L₂ W₂ rw [SmallHom.equiv_equiv_symm W₁ W₁.Q L₁ E₁ α₁, SmallHom.equiv_equiv_symm W₂ W₂.Q L₂ E₂ α₂] change α₂.inv.app _ ≫ E₂.map (β.hom.app X ≫ G'.map g ≫ β.inv.app Y) ≫ _ = _ let γ : G' ⋙ E₂ ≅ E₁ ⋙ G := liftNatIso W₁.Q W₁ (W₁.Q ⋙ G' ⋙ E₂) (W₁.Q ⋙ E₁ ⋙ G) _ _ ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight β.symm E₂ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ α₂ ≪≫ e ≪≫ isoWhiskerRight α₁.symm G ≪≫ Functor.associator _ _ _) have hγ : ∀ (X : C₁), γ.hom.app (W₁.Q.obj X) = E₂.map (β.inv.app X) ≫ α₂.hom.app (Φ.functor.obj X) ≫ e.hom.app X ≫ G.map (α₁.inv.app X) := fun X ↦ by dsimp [γ] rw [liftNatTrans_app] dsimp rw [id_comp, id_comp, comp_id] erw [id_comp, comp_id] simp only [Functor.map_comp, assoc] erw [← NatIso.naturality_1 γ] simp only [Functor.comp_map, ← cancel_epi (e.inv.app X), ← cancel_epi (G.map (α₁.hom.app X)), ← cancel_epi (γ.hom.app (W₁.Q.obj X)), assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, id_comp, Iso.hom_inv_id_app_assoc] simp only [hγ, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, id_comp, Iso.hom_inv_id_app_assoc, Iso.inv_hom_id_app_assoc, Iso.hom_inv_id_app, Functor.comp_obj, comp_id] end variable {X Y Z : C₁} variable [HasSmallLocalizedHom.{w} W₁ X Y] [HasSmallLocalizedHom.{w} W₁ Y Z] [HasSmallLocalizedHom.{w} W₁ X Z] [HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Y)] [HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj Y) (Φ.functor.obj Z)] [HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Z)] lemma smallHomMap_comp (f : SmallHom.{w} W₁ X Y) (g : SmallHom.{w} W₁ Y Z) : Φ.smallHomMap (f.comp g) = (Φ.smallHomMap f).comp (Φ.smallHomMap g) := by apply (SmallHom.equiv W₂ W₂.Q).injective simp [Φ.equiv_smallHomMap W₁.Q W₂.Q (Φ.localizedFunctor W₁.Q W₂.Q) (CatCommSq.iso _ _ _ _), SmallHom.equiv_comp] end LocalizerMorphism end CategoryTheory
CategoryTheory\Localization\SmallShiftedHom.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.SmallHom import Mathlib.CategoryTheory.Shift.ShiftedHom import Mathlib.CategoryTheory.Shift.Localization /-! # Shrinking morphisms in localized categories equipped with shifts If `C` is a category equipped with a shift by an additive monoid `M`, and `W : MorphismProperty C` is compatible with the shift, we define a type-class `HasSmallLocalizedShiftedHom.{w} W X Y` which says that all the types of morphisms from `X⟦a⟧` to `Y⟦b⟧` in the localized category are `w`-small for a certain universe. Then, we define types `SmallShiftedHom.{w} W X Y m : Type w` for all `m : M`, and endow these with a composition which transports the composition on the types `ShiftedHom (L.obj X) (L.obj Y) m` when `L : C ⥤ D` is any localization functor for `W`. -/ universe w w' v₁ v₂ u₁ u₂ namespace CategoryTheory open Category variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (W : MorphismProperty C) {M : Type w'} [AddMonoid M] [HasShift C M] [HasShift D M] [W.IsCompatibleWithShift M] namespace Localization section variable (X Y : C) variable (M) in /-- Given objects `X` and `Y` in a category `C`, this is the property that all the types of morphisms from `X⟦a⟧` to `Y⟦b⟧` are `w`-small in the localized category with respect to a class of morphisms `W`. -/ abbrev HasSmallLocalizedShiftedHom : Prop := ∀ (a b : M), HasSmallLocalizedHom.{w} W (X⟦a⟧) (Y⟦b⟧) variable (M) in lemma hasSmallLocalizedShiftedHom_iff (L : C ⥤ D) [L.IsLocalization W] [L.CommShift M] (X Y : C) : HasSmallLocalizedShiftedHom.{w} W M X Y ↔ ∀ (a b : M), Small.{w} ((L.obj X)⟦a⟧ ⟶ (L.obj Y)⟦b⟧) := by dsimp [HasSmallLocalizedShiftedHom] have eq := fun (a b : M) ↦ small_congr.{w} (Iso.homCongr ((L.commShiftIso a).app X) ((L.commShiftIso b).app Y)) dsimp at eq simp only [hasSmallLocalizedHom_iff _ L, eq] variable [HasSmallLocalizedShiftedHom.{w} W M X Y] variable (M) in lemma hasSmallLocalizedHom_of_hasSmallLocalizedShiftedHom₀ : HasSmallLocalizedHom.{w} W X Y := (hasSmallLocalizedHom_iff_of_isos W ((shiftFunctorZero C M).app X) ((shiftFunctorZero C M).app Y)).1 inferInstance instance (m : M) : HasSmallLocalizedHom.{w} W X (Y⟦m⟧) := (hasSmallLocalizedHom_iff_of_isos W ((shiftFunctorZero C M).app X) (Iso.refl (Y⟦m⟧))).1 inferInstance instance (m : M) : HasSmallLocalizedHom.{w} W (X⟦m⟧) Y := (hasSmallLocalizedHom_iff_of_isos W (Iso.refl (X⟦m⟧)) ((shiftFunctorZero C M).app Y)).1 inferInstance instance (m m' n : M) : HasSmallLocalizedHom.{w} W (X⟦m⟧⟦m'⟧) (Y⟦n⟧) := (hasSmallLocalizedHom_iff_of_isos W ((shiftFunctorAdd C m m').app X) (Iso.refl (Y⟦n⟧))).1 inferInstance instance (m n n' : M) : HasSmallLocalizedHom.{w} W (X⟦m⟧) (Y⟦n⟧⟦n'⟧) := (hasSmallLocalizedHom_iff_of_isos W (Iso.refl (X⟦m⟧)) ((shiftFunctorAdd C n n').app Y)).1 inferInstance end namespace SmallHom variable {W} variable (L : C ⥤ D) [L.IsLocalization W] [L.CommShift M] {X Y : C} [HasSmallLocalizedHom.{w} W X Y] (f : SmallHom.{w} W X Y) (a : M) [HasSmallLocalizedHom.{w} W (X⟦a⟧) (Y⟦a⟧)] /-- Given `f : SmallHom W X Y` and `a : M`, this is the element in `SmallHom W (X⟦a⟧) (Y⟦a⟧)` obtained by shifting by `a`. -/ noncomputable def shift : SmallHom.{w} W (X⟦a⟧) (Y⟦a⟧) := (W.shiftLocalizerMorphism a).smallHomMap f lemma equiv_shift : equiv W L (f.shift a) = (L.commShiftIso a).hom.app X ≫ (equiv W L f)⟦a⟧' ≫ (L.commShiftIso a).inv.app Y := (W.shiftLocalizerMorphism a).equiv_smallHomMap _ _ _ (L.commShiftIso a) f end SmallHom /-- The type of morphisms from `X` to `Y⟦m⟧` in the localized category with respect to `W : MorphismProperty C` that is shrunk to `Type w` when `HasSmallLocalizedShiftedHom.{w} W X Y` holds. -/ def SmallShiftedHom (X Y : C) [HasSmallLocalizedShiftedHom.{w} W M X Y] (m : M) : Type w := SmallHom W X (Y⟦m⟧) namespace SmallShiftedHom section variable {W} variable {X Y Z : C} /-- Given `f : SmallShiftedHom.{w} W X Y a`, this is the element in `SmallHom.{w} W (X⟦n⟧) (Y⟦a'⟧)` that is obtained by shifting by `n` when `a + n = a'`. -/ noncomputable def shift {a : M} [HasSmallLocalizedShiftedHom.{w} W M X Y] [HasSmallLocalizedShiftedHom.{w} W M Y Y] (f : SmallShiftedHom.{w} W X Y a) (n a' : M) (h : a + n = a') : SmallHom.{w} W (X⟦n⟧) (Y⟦a'⟧) := (SmallHom.shift f n).comp (SmallHom.mk W ((shiftFunctorAdd' C a n a' h).inv.app Y)) /-- The composition on `SmallShiftedHom W`. -/ noncomputable def comp {a b c : M} [HasSmallLocalizedShiftedHom.{w} W M X Y] [HasSmallLocalizedShiftedHom.{w} W M Y Z] [HasSmallLocalizedShiftedHom.{w} W M X Z] [HasSmallLocalizedShiftedHom.{w} W M Z Z] (f : SmallShiftedHom.{w} W X Y a) (g : SmallShiftedHom.{w} W Y Z b) (h : b + a = c) : SmallShiftedHom.{w} W X Z c := SmallHom.comp f (g.shift a c h) variable (W) in /-- The canonical map `(X ⟶ Y) → SmallShiftedHom.{w} W X Y m₀` when `m₀ = 0` and `[HasSmallLocalizedShiftedHom.{w} W M X Y]` holds. -/ noncomputable def mk₀ [HasSmallLocalizedShiftedHom.{w} W M X Y] (m₀ : M) (hm₀ : m₀ = 0) (f : X ⟶ Y) : SmallShiftedHom.{w} W X Y m₀ := SmallHom.mk W (f ≫ (shiftFunctorZero' C m₀ hm₀).inv.app Y) end section variable (L : C ⥤ D) [L.IsLocalization W] [HasShift D M] [L.CommShift M] {X Y Z T : C} /-- The bijection `SmallShiftedHom.{w} W X Y m ≃ ShiftedHom (L.obj X) (L.obj Y) m` for all `m : M`, and `X` and `Y` in `C` when `L : C ⥤ D` is a localization functor for `W : MorphismProperty C` such that the category `D` is equipped with a shift by `M` and `L` commutes with the shifts. -/ noncomputable def equiv [HasSmallLocalizedShiftedHom.{w} W M X Y] {m : M} : SmallShiftedHom.{w} W X Y m ≃ ShiftedHom (L.obj X) (L.obj Y) m := (SmallHom.equiv W L).trans ((L.commShiftIso m).app Y).homToEquiv lemma equiv_shift' {a : M} [HasSmallLocalizedShiftedHom.{w} W M X Y] [HasSmallLocalizedShiftedHom.{w} W M Y Y] (f : SmallShiftedHom.{w} W X Y a) (n a' : M) (h : a + n = a') : SmallHom.equiv W L (f.shift n a' h) = (L.commShiftIso n).hom.app X ≫ (SmallHom.equiv W L f)⟦n⟧' ≫ ((L.commShiftIso a).hom.app Y)⟦n⟧' ≫ (shiftFunctorAdd' D a n a' h).inv.app (L.obj Y) ≫ (L.commShiftIso a').inv.app Y := by simp only [shift, SmallHom.equiv_comp, SmallHom.equiv_shift, SmallHom.equiv_mk, assoc, L.commShiftIso_add' h, Functor.CommShift.isoAdd'_inv_app, Iso.inv_hom_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.comp_obj, comp_id] lemma equiv_shift {a : M} [HasSmallLocalizedShiftedHom.{w} W M X Y] [HasSmallLocalizedShiftedHom.{w} W M Y Y] (f : SmallShiftedHom.{w} W X Y a) (n a' : M) (h : a + n = a') : equiv W L (f.shift n a' h) = (L.commShiftIso n).hom.app X ≫ (equiv W L f)⟦n⟧' ≫ (shiftFunctorAdd' D a n a' h).inv.app (L.obj Y) := by dsimp [equiv] erw [Iso.homToEquiv_apply, Iso.homToEquiv_apply, equiv_shift'] simp only [Functor.comp_obj, Iso.app_hom, assoc, Iso.inv_hom_id_app, comp_id, Functor.map_comp] rfl lemma equiv_comp [HasSmallLocalizedShiftedHom.{w} W M X Y] [HasSmallLocalizedShiftedHom.{w} W M Y Z] [HasSmallLocalizedShiftedHom.{w} W M X Z] [HasSmallLocalizedShiftedHom.{w} W M Z Z] {a b c : M} (f : SmallShiftedHom.{w} W X Y a) (g : SmallShiftedHom.{w} W Y Z b) (h : b + a = c) : equiv W L (f.comp g h) = (equiv W L f).comp (equiv W L g) h := by dsimp [comp, equiv, ShiftedHom.comp] erw [Iso.homToEquiv_apply, Iso.homToEquiv_apply, Iso.homToEquiv_apply, SmallHom.equiv_comp] simp only [equiv_shift', Functor.comp_obj, Iso.app_hom, assoc, Iso.inv_hom_id_app, comp_id, Functor.map_comp] rfl @[simp] lemma equiv_mk₀ [HasSmallLocalizedShiftedHom.{w} W M X Y] (m₀ : M) (hm₀ : m₀ = 0) (f : X ⟶ Y) : equiv W L (SmallShiftedHom.mk₀ W m₀ hm₀ f) = ShiftedHom.mk₀ m₀ hm₀ (L.map f) := by subst hm₀ dsimp [equiv, mk₀] erw [SmallHom.equiv_mk, Iso.homToEquiv_apply, Functor.map_comp] dsimp [equiv, mk₀, ShiftedHom.mk₀, shiftFunctorZero'] simp only [comp_id, L.commShiftIso_zero, Functor.CommShift.isoZero_hom_app, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.id_obj, Functor.map_id, id_comp] end lemma comp_assoc {X Y Z T : C} {a₁ a₂ a₃ a₁₂ a₂₃ a : M} [HasSmallLocalizedShiftedHom.{w} W M X Y] [HasSmallLocalizedShiftedHom.{w} W M X Z] [HasSmallLocalizedShiftedHom.{w} W M X T] [HasSmallLocalizedShiftedHom.{w} W M Y Z] [HasSmallLocalizedShiftedHom.{w} W M Y T] [HasSmallLocalizedShiftedHom.{w} W M Z T] [HasSmallLocalizedShiftedHom.{w} W M Z Z] [HasSmallLocalizedShiftedHom.{w} W M T T] (α : SmallShiftedHom.{w} W X Y a₁) (β : SmallShiftedHom.{w} W Y Z a₂) (γ : SmallShiftedHom.{w} W Z T a₃) (h₁₂ : a₂ + a₁ = a₁₂) (h₂₃ : a₃ + a₂ = a₂₃) (h : a₃ + a₂ + a₁ = a) : (α.comp β h₁₂).comp γ (show a₃ + a₁₂ = a by rw [← h₁₂, ← add_assoc, h]) = α.comp (β.comp γ h₂₃) (by rw [← h₂₃, h]) := by apply (equiv W W.Q).injective simp only [equiv_comp, ShiftedHom.comp_assoc _ _ _ h₁₂ h₂₃ h] end SmallShiftedHom end Localization end CategoryTheory
CategoryTheory\Localization\StructuredArrow.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.HomEquiv import Mathlib.CategoryTheory.Localization.Opposite import Mathlib.CategoryTheory.Comma.StructuredArrow /-! # Induction principles for structured and costructured arrows Assume that `L : C ⥤ D` is a localization functor for `W : MorphismProperty C`. Given `X : C` and a predicate `P` on `StructuredArrow (L.obj X) L`, we obtain the lemma `Localization.induction_structuredArrow` which shows that `P` holds for all structured arrows if `P` holds for the identity map `𝟙 (L.obj X)`, if `P` is stable by post-composition with `L.map f` for any `f` and if `P` is stable by post-composition with the inverse of `L.map w` when `W w`. We obtain a similar lemma `Localization.induction_costructuredArrow` for costructured arrows. -/ namespace CategoryTheory open Opposite variable {C D D' : Type*} [Category C] [Category D] [Category D'] namespace Localization section variable (W : MorphismProperty C) (L : C ⥤ D) (L' : C ⥤ D') [L.IsLocalization W] [L'.IsLocalization W] {X : C} /-- The bijection `StructuredArrow (L.obj X) L ≃ StructuredArrow (L'.obj X) L'` when `L` and `L'` are two localization functors for the same class of morphisms. -/ @[simps] noncomputable def structuredArrowEquiv : StructuredArrow (L.obj X) L ≃ StructuredArrow (L'.obj X) L' where toFun f := StructuredArrow.mk (homEquiv W L L' f.hom) invFun f := StructuredArrow.mk (homEquiv W L' L f.hom) left_inv f := by obtain ⟨Y, f, rfl⟩ := f.mk_surjective dsimp rw [← homEquiv_symm_apply, Equiv.symm_apply_apply] right_inv f := by obtain ⟨Y, f, rfl⟩ := f.mk_surjective dsimp rw [← homEquiv_symm_apply, Equiv.symm_apply_apply] end section variable (W : MorphismProperty C) {X : C} (P : StructuredArrow (W.Q.obj X) W.Q → Prop) open Construction in private lemma induction_structuredArrow' (hP₀ : P (StructuredArrow.mk (𝟙 (W.Q.obj X)))) (hP₁ : ∀ ⦃Y₁ Y₂ : C⦄ (f : Y₁ ⟶ Y₂) (φ : W.Q.obj X ⟶ W.Q.obj Y₁), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ W.Q.map f))) (hP₂ : ∀ ⦃Y₁ Y₂ : C⦄ (w : Y₁ ⟶ Y₂) (hw : W w) (φ : W.Q.obj X ⟶ W.Q.obj Y₂), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ (isoOfHom W.Q W w hw).inv))) (g : StructuredArrow (W.Q.obj X) W.Q) : P g := by let X₀ : Paths (LocQuiver W) := ⟨X⟩ suffices ∀ ⦃Y₀ : Paths (LocQuiver W)⦄ (f : X₀ ⟶ Y₀), P (StructuredArrow.mk ((Quotient.functor (relations W)).map f)) by obtain ⟨Y, g, rfl⟩ := g.mk_surjective obtain ⟨g, rfl⟩ := (Quotient.functor (relations W)).map_surjective g exact this g intro Y₀ f induction f with | nil => exact hP₀ | cons f g hf => obtain (g|⟨w, hw⟩) := g · exact hP₁ g _ hf · simpa only [← Construction.wInv_eq_isoOfHom_inv w hw] using hP₂ w hw _ hf end section variable (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] {X : C} (P : StructuredArrow (L.obj X) L → Prop) @[elab_as_elim] lemma induction_structuredArrow (hP₀ : P (StructuredArrow.mk (𝟙 (L.obj X)))) (hP₁ : ∀ ⦃Y₁ Y₂ : C⦄ (f : Y₁ ⟶ Y₂) (φ : L.obj X ⟶ L.obj Y₁), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ L.map f))) (hP₂ : ∀ ⦃Y₁ Y₂ : C⦄ (w : Y₁ ⟶ Y₂) (hw : W w) (φ : L.obj X ⟶ L.obj Y₂), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ (isoOfHom L W w hw).inv))) (g : StructuredArrow (L.obj X) L) : P g := by let P' : StructuredArrow (W.Q.obj X) W.Q → Prop := fun g ↦ P (structuredArrowEquiv W W.Q L g) rw [← (structuredArrowEquiv W W.Q L).apply_symm_apply g] apply induction_structuredArrow' W P' · convert hP₀ simp · intros Y₁ Y₂ f φ hφ convert hP₁ f (homEquiv W W.Q L φ) hφ simp [homEquiv_comp] · intros Y₁ Y₂ w hw φ hφ convert hP₂ w hw (homEquiv W W.Q L φ) hφ simp [homEquiv_comp, homEquiv_isoOfHom_inv] end section variable (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] {Y : C} (P : CostructuredArrow L (L.obj Y) → Prop) @[elab_as_elim] lemma induction_costructuredArrow (hP₀ : P (CostructuredArrow.mk (𝟙 (L.obj Y)))) (hP₁ : ∀ ⦃X₁ X₂ : C⦄ (f : X₁ ⟶ X₂) (φ : L.obj X₂ ⟶ L.obj Y), P (CostructuredArrow.mk φ) → P (CostructuredArrow.mk (L.map f ≫ φ))) (hP₂ : ∀ ⦃X₁ X₂ : C⦄ (w : X₁ ⟶ X₂) (hw : W w) (φ : L.obj X₁ ⟶ L.obj Y), P (CostructuredArrow.mk φ) → P (CostructuredArrow.mk ((isoOfHom L W w hw).inv ≫ φ))) (g : CostructuredArrow L (L.obj Y)) : P g := by let g' := StructuredArrow.mk (T := L.op) (Y := op g.left) g.hom.op show P (CostructuredArrow.mk g'.hom.unop) induction g' using induction_structuredArrow L.op W.op with | hP₀ => exact hP₀ | hP₁ f φ hφ => exact hP₁ f.unop φ.unop hφ | hP₂ w hw φ hφ => simpa [isoOfHom_op_inv L W w hw] using hP₂ w.unop hw φ.unop hφ end end Localization end CategoryTheory
CategoryTheory\Localization\Triangulated.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.CalculusOfFractions.ComposableArrows import Mathlib.CategoryTheory.Localization.CalculusOfFractions.Preadditive import Mathlib.CategoryTheory.Triangulated.Functor import Mathlib.CategoryTheory.Shift.Localization /-! # Localization of triangulated categories If `L : C ⥤ D` is a localization functor for a class of morphisms `W` that is compatible with the triangulation on the category `C` and admits a left calculus of fractions, it is shown in this file that `D` can be equipped with a pretriangulated category structure, and that it is triangulated. ## References * [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996] -/ namespace CategoryTheory open Category Limits Pretriangulated Localization variable {C D : Type*} [Category C] [Category D] (L : C ⥤ D) [HasShift C ℤ] [Preadditive C] [HasZeroObject C] [∀ (n : ℤ), (shiftFunctor C n).Additive] [Pretriangulated C] [HasShift D ℤ] [L.CommShift ℤ] namespace MorphismProperty /-- Given `W` is a class of morphisms in a pretriangulated category `C`, this is the condition that `W` is compatible with the triangulation on `C`. -/ class IsCompatibleWithTriangulation (W : MorphismProperty C) extends W.IsCompatibleWithShift ℤ : Prop where compatible_with_triangulation (T₁ T₂ : Triangle C) (_ : T₁ ∈ distTriang C) (_ : T₂ ∈ distTriang C) (a : T₁.obj₁ ⟶ T₂.obj₁) (b : T₁.obj₂ ⟶ T₂.obj₂) (_ : W a) (_ : W b) (_ : T₁.mor₁ ≫ b = a ≫ T₂.mor₁) : ∃ (c : T₁.obj₃ ⟶ T₂.obj₃) (_ : W c), (T₁.mor₂ ≫ c = b ≫ T₂.mor₂) ∧ (T₁.mor₃ ≫ a⟦1⟧' = c ≫ T₂.mor₃) export IsCompatibleWithTriangulation (compatible_with_triangulation) end MorphismProperty namespace Functor /-- Given a functor `C ⥤ D` from a pretriangulated category, this is the set of triangles in `D` that are in the essential image of distinguished triangles of `C`. -/ def essImageDistTriang : Set (Triangle D) := fun T => ∃ (T' : Triangle C) (_ : T ≅ L.mapTriangle.obj T'), T' ∈ distTriang C lemma essImageDistTriang_mem_of_iso {T₁ T₂ : Triangle D} (e : T₂ ≅ T₁) (h : T₁ ∈ L.essImageDistTriang) : T₂ ∈ L.essImageDistTriang := by obtain ⟨T', e', hT'⟩ := h exact ⟨T', e ≪≫ e', hT'⟩ lemma contractible_mem_essImageDistTriang [EssSurj L] [HasZeroObject D] [HasZeroMorphisms D] [L.PreservesZeroMorphisms] (X : D) : contractibleTriangle X ∈ L.essImageDistTriang := by refine ⟨contractibleTriangle (L.objPreimage X), ?_, contractible_distinguished _⟩ exact ((contractibleTriangleFunctor D).mapIso (L.objObjPreimageIso X)).symm ≪≫ Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) L.mapZeroObject.symm (by simp) (by simp) (by simp) lemma rotate_essImageDistTriang [Preadditive D] [L.Additive] [∀ (n : ℤ), (shiftFunctor D n).Additive] (T : Triangle D) : T ∈ L.essImageDistTriang ↔ T.rotate ∈ L.essImageDistTriang := by constructor · rintro ⟨T', e', hT'⟩ exact ⟨T'.rotate, (rotate D).mapIso e' ≪≫ L.mapTriangleRotateIso.app T', rot_of_distTriang T' hT'⟩ · rintro ⟨T', e', hT'⟩ exact ⟨T'.invRotate, (triangleRotation D).unitIso.app T ≪≫ (invRotate D).mapIso e' ≪≫ L.mapTriangleInvRotateIso.app T', inv_rot_of_distTriang T' hT'⟩ lemma complete_distinguished_essImageDistTriang_morphism (H : ∀ (T₁' T₂' : Triangle C) (_ : T₁' ∈ distTriang C) (_ : T₂' ∈ distTriang C) (a : L.obj (T₁'.obj₁) ⟶ L.obj (T₂'.obj₁)) (b : L.obj (T₁'.obj₂) ⟶ L.obj (T₂'.obj₂)) (_ : L.map T₁'.mor₁ ≫ b = a ≫ L.map T₂'.mor₁), ∃ (φ : L.mapTriangle.obj T₁' ⟶ L.mapTriangle.obj T₂'), φ.hom₁ = a ∧ φ.hom₂ = b) (T₁ T₂ : Triangle D) (hT₁ : T₁ ∈ Functor.essImageDistTriang L) (hT₂ : T₂ ∈ L.essImageDistTriang) (a : T₁.obj₁ ⟶ T₂.obj₁) (b : T₁.obj₂ ⟶ T₂.obj₂) (fac : T₁.mor₁ ≫ b = a ≫ T₂.mor₁) : ∃ c, T₁.mor₂ ≫ c = b ≫ T₂.mor₂ ∧ T₁.mor₃ ≫ a⟦1⟧' = c ≫ T₂.mor₃ := by obtain ⟨T₁', e₁, hT₁'⟩ := hT₁ obtain ⟨T₂', e₂, hT₂'⟩ := hT₂ have comm₁ := e₁.inv.comm₁ have comm₁' := e₂.hom.comm₁ have comm₂ := e₁.hom.comm₂ have comm₂' := e₂.hom.comm₂ have comm₃ := e₁.inv.comm₃ have comm₃' := e₂.hom.comm₃ dsimp at comm₁ comm₁' comm₂ comm₂' comm₃ comm₃' simp only [assoc] at comm₃ obtain ⟨φ, hφ₁, hφ₂⟩ := H T₁' T₂' hT₁' hT₂' (e₁.inv.hom₁ ≫ a ≫ e₂.hom.hom₁) (e₁.inv.hom₂ ≫ b ≫ e₂.hom.hom₂) (by simp only [assoc, ← comm₁', ← reassoc_of% fac, ← reassoc_of% comm₁]) have h₂ := φ.comm₂ have h₃ := φ.comm₃ dsimp at h₂ h₃ simp only [assoc] at h₃ refine ⟨e₁.hom.hom₃ ≫ φ.hom₃ ≫ e₂.inv.hom₃, ?_, ?_⟩ · rw [reassoc_of% comm₂, reassoc_of% h₂, hφ₂, assoc, assoc, Iso.hom_inv_id_triangle_hom₂_assoc, ← reassoc_of% comm₂', Iso.hom_inv_id_triangle_hom₃, comp_id] · rw [assoc, assoc, ← cancel_epi e₁.inv.hom₃, ← reassoc_of% comm₃, Iso.inv_hom_id_triangle_hom₃_assoc, ← cancel_mono (e₂.hom.hom₁⟦(1 : ℤ)⟧'), assoc, assoc, assoc, assoc, assoc, ← Functor.map_comp, ← Functor.map_comp, ← hφ₁, h₃, comm₃', Iso.inv_hom_id_triangle_hom₃_assoc] end Functor namespace Triangulated namespace Localization variable (W : MorphismProperty C) [L.IsLocalization W] [W.HasLeftCalculusOfFractions] lemma distinguished_cocone_triangle {X Y : D} (f : X ⟶ Y) : ∃ (Z : D) (g : Y ⟶ Z) (h : Z ⟶ X⟦(1 : ℤ)⟧), Triangle.mk f g h ∈ L.essImageDistTriang := by have := essSurj_mapArrow L W obtain ⟨φ, ⟨e⟩⟩ : ∃ (φ : Arrow C), Nonempty (L.mapArrow.obj φ ≅ Arrow.mk f) := ⟨_, ⟨Functor.objObjPreimageIso _ _⟩⟩ obtain ⟨Z, g, h, H⟩ := Pretriangulated.distinguished_cocone_triangle φ.hom refine ⟨L.obj Z, e.inv.right ≫ L.map g, L.map h ≫ (L.commShiftIso (1 : ℤ)).hom.app _ ≫ e.hom.left⟦(1 : ℤ)⟧', _, ?_, H⟩ refine Triangle.isoMk _ _ (Arrow.leftFunc.mapIso e.symm) (Arrow.rightFunc.mapIso e.symm) (Iso.refl _) e.inv.w.symm (by simp) ?_ dsimp simp only [assoc, id_comp, ← Functor.map_comp, ← Arrow.comp_left, e.hom_inv_id, Arrow.id_left, Functor.mapArrow_obj_left, Functor.map_id, comp_id] section variable [W.IsCompatibleWithTriangulation] lemma complete_distinguished_triangle_morphism (T₁ T₂ : Triangle D) (hT₁ : T₁ ∈ L.essImageDistTriang) (hT₂ : T₂ ∈ L.essImageDistTriang) (a : T₁.obj₁ ⟶ T₂.obj₁) (b : T₁.obj₂ ⟶ T₂.obj₂) (fac : T₁.mor₁ ≫ b = a ≫ T₂.mor₁) : ∃ c, T₁.mor₂ ≫ c = b ≫ T₂.mor₂ ∧ T₁.mor₃ ≫ a⟦1⟧' = c ≫ T₂.mor₃ := by refine L.complete_distinguished_essImageDistTriang_morphism ?_ T₁ T₂ hT₁ hT₂ a b fac clear a b fac hT₁ hT₂ T₁ T₂ intro T₁ T₂ hT₁ hT₂ a b fac obtain ⟨α, hα⟩ := exists_leftFraction L W a obtain ⟨β, hβ⟩ := (MorphismProperty.RightFraction.mk α.s α.hs T₂.mor₁).exists_leftFraction obtain ⟨γ, hγ⟩ := exists_leftFraction L W (b ≫ L.map β.s) have := inverts L W β.s β.hs have := inverts L W γ.s γ.hs dsimp at hβ obtain ⟨Z₂, σ, hσ, fac⟩ := (MorphismProperty.map_eq_iff_postcomp L W (α.f ≫ β.f ≫ γ.s) (T₁.mor₁ ≫ γ.f)).1 (by rw [← cancel_mono (L.map β.s), assoc, assoc, hγ, ← cancel_mono (L.map γ.s), assoc, assoc, assoc, hα, MorphismProperty.LeftFraction.map_comp_map_s, ← Functor.map_comp] at fac rw [fac, ← Functor.map_comp_assoc, hβ, Functor.map_comp, Functor.map_comp, Functor.map_comp, assoc, MorphismProperty.LeftFraction.map_comp_map_s_assoc]) simp only [assoc] at fac obtain ⟨Y₃, g, h, hT₃⟩ := Pretriangulated.distinguished_cocone_triangle (β.f ≫ γ.s ≫ σ) let T₃ := Triangle.mk (β.f ≫ γ.s ≫ σ) g h change T₃ ∈ distTriang C at hT₃ have hβγσ : W (β.s ≫ γ.s ≫ σ) := W.comp_mem _ _ β.hs (W.comp_mem _ _ γ.hs hσ) obtain ⟨ψ₃, hψ₃, hψ₁, hψ₂⟩ := MorphismProperty.compatible_with_triangulation T₂ T₃ hT₂ hT₃ α.s (β.s ≫ γ.s ≫ σ) α.hs hβγσ (by dsimp [T₃]; rw [reassoc_of% hβ]) let ψ : T₂ ⟶ T₃ := Triangle.homMk _ _ α.s (β.s ≫ γ.s ≫ σ) ψ₃ (by dsimp [T₃]; rw [reassoc_of% hβ]) hψ₁ hψ₂ have : IsIso (L.mapTriangle.map ψ) := Triangle.isIso_of_isIsos _ (inverts L W α.s α.hs) (inverts L W _ hβγσ) (inverts L W ψ₃ hψ₃) refine ⟨L.mapTriangle.map (completeDistinguishedTriangleMorphism T₁ T₃ hT₁ hT₃ α.f (γ.f ≫ σ) fac.symm) ≫ inv (L.mapTriangle.map ψ), ?_, ?_⟩ · rw [← cancel_mono (L.mapTriangle.map ψ).hom₁, ← comp_hom₁, assoc, IsIso.inv_hom_id, comp_id] dsimp [ψ] rw [hα, MorphismProperty.LeftFraction.map_comp_map_s] · rw [← cancel_mono (L.mapTriangle.map ψ).hom₂, ← comp_hom₂, assoc, IsIso.inv_hom_id, comp_id] dsimp [ψ] simp only [Functor.map_comp, reassoc_of% hγ, MorphismProperty.LeftFraction.map_comp_map_s_assoc] variable [HasZeroObject D] [Preadditive D] [∀ (n : ℤ), (shiftFunctor D n).Additive] [L.Additive] /-- The pretriangulated structure on the localized category. -/ def pretriangulated : Pretriangulated D where distinguishedTriangles := L.essImageDistTriang isomorphic_distinguished _ hT₁ _ e := L.essImageDistTriang_mem_of_iso e hT₁ contractible_distinguished := have := essSurj L W; L.contractible_mem_essImageDistTriang distinguished_cocone_triangle f := distinguished_cocone_triangle L W f rotate_distinguished_triangle := L.rotate_essImageDistTriang complete_distinguished_triangle_morphism := complete_distinguished_triangle_morphism L W instance isTriangulated_functor : letI : Pretriangulated D := pretriangulated L W; L.IsTriangulated := letI : Pretriangulated D := pretriangulated L W ⟨fun T hT => ⟨T, Iso.refl _, hT⟩⟩ end variable [HasZeroObject D] [Preadditive D] [∀ (n : ℤ), (shiftFunctor D n).Additive] lemma isTriangulated [Pretriangulated D] [L.IsTriangulated] [IsTriangulated C] : IsTriangulated D := by have := essSurj_mapComposableArrows L W 2 exact isTriangulated_of_essSurj_mapComposableArrows_two L variable [W.IsCompatibleWithTriangulation] instance (n : ℤ) : (shiftFunctor (W.Localization) n).Additive := by rw [Localization.functor_additive_iff W.Q W] exact Functor.additive_of_iso (W.Q.commShiftIso n) instance : Pretriangulated W.Localization := pretriangulated W.Q W instance [IsTriangulated C] : IsTriangulated W.Localization := isTriangulated W.Q W section variable [W.HasLocalization] instance (n : ℤ) : (shiftFunctor (W.Localization') n).Additive := by rw [Localization.functor_additive_iff W.Q' W] exact Functor.additive_of_iso (W.Q'.commShiftIso n) instance : Pretriangulated W.Localization' := pretriangulated W.Q' W instance [IsTriangulated C] : IsTriangulated W.Localization' := isTriangulated W.Q' W end end Localization end Triangulated namespace Functor variable [HasZeroObject D] [Preadditive D] [∀ (n : ℤ), (shiftFunctor D n).Additive] [Pretriangulated D] [L.mapArrow.EssSurj] [L.IsTriangulated] lemma distTriang_iff (T : Triangle D) : (T ∈ distTriang D) ↔ T ∈ L.essImageDistTriang := by constructor · intro hT let f := L.mapArrow.objPreimage T.mor₁ obtain ⟨Z, g : f.right ⟶ Z, h : Z ⟶ f.left⟦(1 : ℤ)⟧, mem⟩ := Pretriangulated.distinguished_cocone_triangle f.hom exact ⟨_, (exists_iso_of_arrow_iso T _ hT (L.map_distinguished _ mem) (L.mapArrow.objObjPreimageIso T.mor₁).symm).choose, mem⟩ · rintro ⟨T₀, e, hT₀⟩ exact isomorphic_distinguished _ (L.map_distinguished _ hT₀) _ e end Functor end CategoryTheory
CategoryTheory\Localization\CalculusOfFractions\ComposableArrows.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Andrew Yang -/ import Mathlib.CategoryTheory.ComposableArrows import Mathlib.CategoryTheory.Localization.CalculusOfFractions /-! # Essential surjectivity of the functor induced on composable arrows Assuming that `L : C ⥤ D` is a localization functor for a class of morphisms `W` that has a calculus of left *or* right fractions, we show in this file that the functor `L.mapComposableArrows n : ComposableArrows C n ⥤ ComposableArrows D n` is essentially surjective for any `n : ℕ`. -/ namespace CategoryTheory namespace Localization variable {C D : Type*} [Category C] [Category D] (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] open ComposableArrows lemma essSurj_mapComposableArrows_of_hasRightCalculusOfFractions [W.HasRightCalculusOfFractions] (n : ℕ) : (L.mapComposableArrows n).EssSurj where mem_essImage Y := by have := essSurj L W induction n with | zero => obtain ⟨Y, rfl⟩ := mk₀_surjective Y exact ⟨mk₀ _, ⟨isoMk₀ (L.objObjPreimageIso Y)⟩⟩ | succ n hn => obtain ⟨Y, Z, f, rfl⟩ := ComposableArrows.precomp_surjective Y obtain ⟨Y', ⟨e⟩⟩ := hn Y obtain ⟨f', hf'⟩ := exists_rightFraction L W ((L.objObjPreimageIso Z).hom ≫ f ≫ (e.app 0).inv) refine ⟨Y'.precomp f'.f, ⟨isoMkSucc (isoOfHom L W _ f'.hs ≪≫ L.objObjPreimageIso Z) e ?_⟩⟩ dsimp at hf' ⊢ simp [← cancel_mono (e.inv.app 0), hf'] lemma essSurj_mapComposableArrows [W.HasLeftCalculusOfFractions] (n : ℕ) : (L.mapComposableArrows n).EssSurj := by have := essSurj_mapComposableArrows_of_hasRightCalculusOfFractions L.op W.op n have := Functor.essSurj_of_iso (L.mapComposableArrowsOpIso n).symm exact Functor.essSurj_of_comp_fully_faithful _ (opEquivalence D n).functor.rightOp end Localization end CategoryTheory
CategoryTheory\Localization\CalculusOfFractions\Fractions.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.CalculusOfFractions /-! # Lemmas on fractions Let `W : MorphismProperty C`, and objects `X` and `Y` in `C`. In this file, we introduce structures like `W.LeftFraction₂ X Y` which consists of two left fractions with the "same denominator" which shall be important in the construction of the preadditive structure on the localized category when `C` is preadditive and `W` has a left calculus of fractions. When `W` has a left calculus of fractions, we generalize the lemmas `RightFraction.exists_leftFraction` as `RightFraction₂.exists_leftFraction₂`, `Localization.exists_leftFraction` as `Localization.exists_leftFraction₂` and `Localization.exists_leftFraction₃`, and `LeftFraction.map_eq_iff` as `LeftFraction₂.map_eq_iff`. ## Implementation note The lemmas in this file are phrased with data that is bundled into structures like `LeftFraction₂` or `LeftFraction₃`. It could have been possible to phrase them with "unbundled data". However, this would require introducing 4 or 5 variables instead of one. It is also very convenient to use dot notation. Many definitions have been made reducible so as to ease rewrites when this API is used. -/ namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] namespace MorphismProperty /-- This structure contains the data of two left fractions for `W : MorphismProperty C` that have the same "denominator". -/ structure LeftFraction₂ (X Y : C) where /-- the auxiliary object of left fractions -/ {Y' : C} /-- the numerator of the first left fraction -/ f : X ⟶ Y' /-- the numerator of the second left fraction -/ f' : X ⟶ Y' /-- the denominator of the left fractions -/ s : Y ⟶ Y' /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- This structure contains the data of three left fractions for `W : MorphismProperty C` that have the same "denominator". -/ structure LeftFraction₃ (X Y : C) where /-- the auxiliary object of left fractions -/ {Y' : C} /-- the numerator of the first left fraction -/ f : X ⟶ Y' /-- the numerator of the second left fraction -/ f' : X ⟶ Y' /-- the numerator of the third left fraction -/ f'' : X ⟶ Y' /-- the denominator of the left fractions -/ s : Y ⟶ Y' /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- This structure contains the data of two right fractions for `W : MorphismProperty C` that have the same "denominator". -/ structure RightFraction₂ (X Y : C) where /-- the auxiliary object of right fractions -/ {X' : C} /-- the denominator of the right fractions -/ s : X' ⟶ X /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- the numerator of the first right fraction -/ f : X' ⟶ Y /-- the numerator of the second right fraction -/ f' : X' ⟶ Y variable {W} /-- The equivalence relation on tuples of left fractions with the same denominator for a morphism property `W`. The fact it is an equivalence relation is not formalized, but it would follow easily from `LeftFraction₂.map_eq_iff`. -/ def LeftFraction₂Rel {X Y : C} (z₁ z₂ : W.LeftFraction₂ X Y) : Prop := ∃ (Z : C) (t₁ : z₁.Y' ⟶ Z) (t₂ : z₂.Y' ⟶ Z) (_ : z₁.s ≫ t₁ = z₂.s ≫ t₂) (_ : z₁.f ≫ t₁ = z₂.f ≫ t₂) (_ : z₁.f' ≫ t₁ = z₂.f' ≫ t₂), W (z₁.s ≫ t₁) namespace LeftFraction₂ variable {X Y : C} (φ : W.LeftFraction₂ X Y) /-- The first left fraction. -/ abbrev fst : W.LeftFraction X Y where Y' := φ.Y' f := φ.f s := φ.s hs := φ.hs /-- The second left fraction. -/ abbrev snd : W.LeftFraction X Y where Y' := φ.Y' f := φ.f' s := φ.s hs := φ.hs /-- The exchange of the two fractions. -/ abbrev symm : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f' f' := φ.f s := φ.s hs := φ.hs end LeftFraction₂ namespace LeftFraction₃ variable {X Y : C} (φ : W.LeftFraction₃ X Y) /-- The first left fraction. -/ abbrev fst : W.LeftFraction X Y where Y' := φ.Y' f := φ.f s := φ.s hs := φ.hs /-- The second left fraction. -/ abbrev snd : W.LeftFraction X Y where Y' := φ.Y' f := φ.f' s := φ.s hs := φ.hs /-- The third left fraction. -/ abbrev thd : W.LeftFraction X Y where Y' := φ.Y' f := φ.f'' s := φ.s hs := φ.hs /-- Forgets the first fraction. -/ abbrev forgetFst : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f' f' := φ.f'' s := φ.s hs := φ.hs /-- Forgets the second fraction. -/ abbrev forgetSnd : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f f' := φ.f'' s := φ.s hs := φ.hs /-- Forgets the third fraction. -/ abbrev forgetThd : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f f' := φ.f' s := φ.s hs := φ.hs end LeftFraction₃ namespace LeftFraction₂Rel variable {X Y : C} {z₁ z₂ : W.LeftFraction₂ X Y} lemma fst (h : LeftFraction₂Rel z₁ z₂) : LeftFractionRel z₁.fst z₂.fst := by obtain ⟨Z, t₁, t₂, hst, hft, _, ht⟩ := h exact ⟨Z, t₁, t₂, hst, hft, ht⟩ lemma snd (h : LeftFraction₂Rel z₁ z₂) : LeftFractionRel z₁.snd z₂.snd := by obtain ⟨Z, t₁, t₂, hst, _, hft', ht⟩ := h exact ⟨Z, t₁, t₂, hst, hft', ht⟩ end LeftFraction₂Rel namespace LeftFraction₂ variable (W) variable [W.HasLeftCalculusOfFractions] lemma map_eq_iff {X Y : C} (φ ψ : W.LeftFraction₂ X Y) : (φ.fst.map L (Localization.inverts _ _) = ψ.fst.map L (Localization.inverts _ _) ∧ φ.snd.map L (Localization.inverts _ _) = ψ.snd.map L (Localization.inverts _ _)) ↔ LeftFraction₂Rel φ ψ := by simp only [LeftFraction.map_eq_iff L W] constructor · intro ⟨h, h'⟩ obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h obtain ⟨Z', t₁', t₂', hst', hft', ht'⟩ := h' dsimp at t₁ t₂ t₁' t₂' hst hft hst' hft' ht ht' have ⟨α, hα⟩ := (RightFraction.mk _ ht (φ.s ≫ t₁')).exists_leftFraction simp only [Category.assoc] at hα obtain ⟨Z'', u, hu, fac⟩ := HasLeftCalculusOfFractions.ext _ _ _ φ.hs hα have hα' : ψ.s ≫ t₂ ≫ α.f ≫ u = ψ.s ≫ t₂' ≫ α.s ≫ u := by rw [← reassoc_of% hst, ← reassoc_of% hα, ← reassoc_of% hst'] obtain ⟨Z''', u', hu', fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ ψ.hs hα' simp only [Category.assoc] at fac fac' refine ⟨Z''', t₁' ≫ α.s ≫ u ≫ u', t₂' ≫ α.s ≫ u ≫ u', ?_, ?_, ?_, ?_⟩ · rw [reassoc_of% hst'] · rw [reassoc_of% fac, reassoc_of% hft, fac'] · rw [reassoc_of% hft'] · rw [← Category.assoc] exact W.comp_mem _ _ ht' (W.comp_mem _ _ α.hs (W.comp_mem _ _ hu hu')) · intro h exact ⟨h.fst, h.snd⟩ end LeftFraction₂ namespace RightFraction₂ variable {X Y : C} variable (φ : W.RightFraction₂ X Y) /-- The first right fraction. -/ abbrev fst : W.RightFraction X Y where X' := φ.X' f := φ.f s := φ.s hs := φ.hs /-- The second right fraction. -/ abbrev snd : W.RightFraction X Y where X' := φ.X' f := φ.f' s := φ.s hs := φ.hs lemma exists_leftFraction₂ [W.HasLeftCalculusOfFractions] : ∃ (ψ : W.LeftFraction₂ X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f ∧ φ.f' ≫ ψ.s = φ.s ≫ ψ.f' := by obtain ⟨ψ₁, hψ₁⟩ := φ.fst.exists_leftFraction obtain ⟨ψ₂, hψ₂⟩ := φ.snd.exists_leftFraction obtain ⟨α, hα⟩ := (RightFraction.mk _ ψ₁.hs ψ₂.s).exists_leftFraction dsimp at hψ₁ hψ₂ hα refine ⟨LeftFraction₂.mk (ψ₁.f ≫ α.f) (ψ₂.f ≫ α.s) (ψ₂.s ≫ α.s) (W.comp_mem _ _ ψ₂.hs α.hs), ?_, ?_⟩ · dsimp rw [hα, reassoc_of% hψ₁] · rw [reassoc_of% hψ₂] end RightFraction₂ end MorphismProperty namespace Localization variable [W.HasLeftCalculusOfFractions] open MorphismProperty lemma exists_leftFraction₂ {X Y : C} (f f' : L.obj X ⟶ L.obj Y) : ∃ (φ : W.LeftFraction₂ X Y), f = φ.fst.map L (inverts L W) ∧ f' = φ.snd.map L (inverts L W) := by have ⟨φ, hφ⟩ := exists_leftFraction L W f have ⟨φ', hφ'⟩ := exists_leftFraction L W f' obtain ⟨α, hα⟩ := (RightFraction.mk _ φ.hs φ'.s).exists_leftFraction let ψ : W.LeftFraction₂ X Y := { Y' := α.Y' f := φ.f ≫ α.f f' := φ'.f ≫ α.s s := φ'.s ≫ α.s hs := W.comp_mem _ _ φ'.hs α.hs } have := inverts L W _ φ'.hs have := inverts L W _ α.hs have : IsIso (L.map (φ'.s ≫ α.s)) := by rw [L.map_comp] infer_instance refine ⟨ψ, ?_, ?_⟩ · rw [← cancel_mono (L.map (φ'.s ≫ α.s)), LeftFraction.map_comp_map_s, hα, L.map_comp, hφ, LeftFraction.map_comp_map_s_assoc, L.map_comp] · rw [← cancel_mono (L.map (φ'.s ≫ α.s)), hφ'] nth_rw 1 [L.map_comp] rw [LeftFraction.map_comp_map_s_assoc, LeftFraction.map_comp_map_s, L.map_comp] lemma exists_leftFraction₃ {X Y : C} (f f' f'' : L.obj X ⟶ L.obj Y) : ∃ (φ : W.LeftFraction₃ X Y), f = φ.fst.map L (inverts L W) ∧ f' = φ.snd.map L (inverts L W) ∧ f'' = φ.thd.map L (inverts L W) := by obtain ⟨α, hα, hα'⟩ := exists_leftFraction₂ L W f f' have ⟨β, hβ⟩ := exists_leftFraction L W f'' obtain ⟨γ, hγ⟩ := (RightFraction.mk _ α.hs β.s).exists_leftFraction dsimp at hγ let ψ : W.LeftFraction₃ X Y := { Y' := γ.Y' f := α.f ≫ γ.f f' := α.f' ≫ γ.f f'' := β.f ≫ γ.s s := β.s ≫ γ.s hs := W.comp_mem _ _ β.hs γ.hs } have := inverts L W _ β.hs have := inverts L W _ γ.hs have : IsIso (L.map (β.s ≫ γ.s)) := by rw [L.map_comp] infer_instance refine ⟨ψ, ?_, ?_, ?_⟩ · rw [← cancel_mono (L.map (β.s ≫ γ.s)), LeftFraction.map_comp_map_s, hα, hγ, L.map_comp, LeftFraction.map_comp_map_s_assoc, L.map_comp] · rw [← cancel_mono (L.map (β.s ≫ γ.s)), LeftFraction.map_comp_map_s, hα', hγ, L.map_comp, LeftFraction.map_comp_map_s_assoc, L.map_comp] · rw [← cancel_mono (L.map (β.s ≫ γ.s)), hβ] nth_rw 1 [L.map_comp] rw [LeftFraction.map_comp_map_s_assoc, LeftFraction.map_comp_map_s, L.map_comp] end Localization end CategoryTheory
CategoryTheory\Localization\CalculusOfFractions\Preadditive.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.CalculusOfFractions.Fractions import Mathlib.CategoryTheory.Localization.HasLocalization import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.Logic.Equiv.TransferInstance /-! # The preadditive category structure on the localized category In this file, it is shown that if `W : MorphismProperty C` has a left calculus of fractions, and `C` is preadditive, then the localized category is preadditive, and the localization functor is additive. Let `L : C ⥤ D` be a localization functor for `W`. We first construct an abelian group structure on `L.obj X ⟶ L.obj Y` for `X` and `Y` in `C`. The addition is defined using representatives of two morphisms in `L` as left fractions with the same denominator thanks to the lemmas in `CategoryTheory.Localization.CalculusOfFractions.Fractions`. As `L` is essentially surjective, we finally transport these abelian group structures to `X' ⟶ Y'` for all `X'` and `Y'` in `D`. Preadditive category instances are defined on the categories `W.Localization` (and `W.Localization'`) under the assumption the `W` has a left calculus of fractions. (It would be easy to deduce from the results in this file that if `W` has a right calculus of fractions, then the localized category can also be equipped with a preadditive structure, but only one of these two constructions can be made an instance!) -/ namespace CategoryTheory open MorphismProperty Preadditive Limits Category variable {C D : Type*} [Category C] [Category D] [Preadditive C] (L : C ⥤ D) {W : MorphismProperty C} [L.IsLocalization W] [W.HasLeftCalculusOfFractions] namespace MorphismProperty /-- The opposite of a left fraction. -/ abbrev LeftFraction.neg {X Y : C} (φ : W.LeftFraction X Y) : W.LeftFraction X Y where Y' := φ.Y' f := -φ.f s := φ.s hs := φ.hs namespace LeftFraction₂ variable {X Y : C} (φ : W.LeftFraction₂ X Y) /-- The sum of two left fractions with the same denominator. -/ abbrev add : W.LeftFraction X Y where Y' := φ.Y' f := φ.f + φ.f' s := φ.s hs := φ.hs @[simp] lemma symm_add : φ.symm.add = φ.add := by dsimp [add, symm] congr 1 apply add_comm @[simp] lemma map_add (F : C ⥤ D) (hF : W.IsInvertedBy F) [Preadditive D] [F.Additive] : φ.add.map F hF = φ.fst.map F hF + φ.snd.map F hF := by have := hF φ.s φ.hs rw [← cancel_mono (F.map φ.s), add_comp, LeftFraction.map_comp_map_s, LeftFraction.map_comp_map_s, LeftFraction.map_comp_map_s, F.map_add] end LeftFraction₂ end MorphismProperty variable (W) namespace Localization namespace Preadditive section ImplementationDetails /-! The definitions in this section (like `neg'` and `add'`) should never be used directly. These are auxiliary definitions in order to construct the preadditive structure `Localization.preadditive` (which is made irreducible). The user should only rely on the fact that the localization functor is additive, as this completely determines the preadditive structure on the localized category when there is a calculus of left fractions. -/ variable {X Y Z : C} variable {L} /-- The opposite of a map `L.obj X ⟶ L.obj Y` when `L : C ⥤ D` is a localization functor, `C` is preadditive and there is a left calculus of fractions. -/ noncomputable def neg' (f : L.obj X ⟶ L.obj Y) : L.obj X ⟶ L.obj Y := (exists_leftFraction L W f).choose.neg.map L (inverts L W) lemma neg'_eq (f : L.obj X ⟶ L.obj Y) (φ : W.LeftFraction X Y) (hφ : f = φ.map L (inverts L W)) : neg' W f = φ.neg.map L (inverts L W) := by obtain ⟨φ₀, rfl, hφ₀⟩ : ∃ (φ₀ : W.LeftFraction X Y) (_ : f = φ₀.map L (inverts L W)), neg' W f = φ₀.neg.map L (inverts L W) := ⟨_, (exists_leftFraction L W f).choose_spec, rfl⟩ rw [MorphismProperty.LeftFraction.map_eq_iff] at hφ obtain ⟨Y', t₁, t₂, hst, hft, ht⟩ := hφ have := inverts L W _ ht rw [← cancel_mono (L.map (φ₀.s ≫ t₁))] nth_rw 1 [L.map_comp] rw [hφ₀, hst, LeftFraction.map_comp_map_s_assoc, L.map_comp, LeftFraction.map_comp_map_s_assoc, ← L.map_comp, ← L.map_comp, neg_comp, neg_comp, hft] /-- The addition of two maps `L.obj X ⟶ L.obj Y` when `L : C ⥤ D` is a localization functor, `C` is preadditive and there is a left calculus of fractions. -/ noncomputable def add' (f₁ f₂ : L.obj X ⟶ L.obj Y) : L.obj X ⟶ L.obj Y := (exists_leftFraction₂ L W f₁ f₂).choose.add.map L (inverts L W) lemma add'_eq (f₁ f₂ : L.obj X ⟶ L.obj Y) (φ : W.LeftFraction₂ X Y) (hφ₁ : f₁ = φ.fst.map L (inverts L W)) (hφ₂ : f₂ = φ.snd.map L (inverts L W)) : add' W f₁ f₂ = φ.add.map L (inverts L W) := by obtain ⟨φ₀, rfl, rfl, hφ₀⟩ : ∃ (φ₀ : W.LeftFraction₂ X Y) (_ : f₁ = φ₀.fst.map L (inverts L W)) (_ : f₂ = φ₀.snd.map L (inverts L W)), add' W f₁ f₂ = φ₀.add.map L (inverts L W) := ⟨(exists_leftFraction₂ L W f₁ f₂).choose, (exists_leftFraction₂ L W f₁ f₂).choose_spec.1, (exists_leftFraction₂ L W f₁ f₂).choose_spec.2, rfl⟩ obtain ⟨Z, t₁, t₂, hst, hft, hft', ht⟩ := (LeftFraction₂.map_eq_iff L W φ₀ φ).1 ⟨hφ₁, hφ₂⟩ have := inverts L W _ ht rw [hφ₀, ← cancel_mono (L.map (φ₀.s ≫ t₁))] nth_rw 2 [hst] rw [L.map_comp, L.map_comp, LeftFraction.map_comp_map_s_assoc, LeftFraction.map_comp_map_s_assoc, ← L.map_comp, ← L.map_comp, add_comp, add_comp, hft, hft'] lemma add'_comm (f₁ f₂ : L.obj X ⟶ L.obj Y) : add' W f₁ f₂ = add' W f₂ f₁ := by obtain ⟨α, h₁, h₂⟩ := exists_leftFraction₂ L W f₁ f₂ rw [add'_eq W f₁ f₂ α h₁ h₂, add'_eq W f₂ f₁ α.symm h₂ h₁, α.symm_add] lemma add'_zero (f : L.obj X ⟶ L.obj Y) : add' W f (L.map 0) = f := by obtain ⟨α, hα⟩ := exists_leftFraction L W f rw [add'_eq W f (L.map 0) (LeftFraction₂.mk α.f 0 α.s α.hs) hα, hα]; swap · have := inverts L W _ α.hs rw [← cancel_mono (L.map α.s), ← L.map_comp, Limits.zero_comp, LeftFraction.map_comp_map_s] dsimp [LeftFraction₂.add] rw [add_zero] lemma zero_add' (f : L.obj X ⟶ L.obj Y) : add' W (L.map 0) f = f := by rw [add'_comm, add'_zero] lemma add'_left_neg' (f : L.obj X ⟶ L.obj Y) : add' W (neg' W f) f = L.map 0 := by obtain ⟨α, rfl⟩ := exists_leftFraction L W f have := inverts L W _ α.hs rw [add'_eq W _ _ (LeftFraction₂.mk (-α.f) α.f α.s α.hs) (neg'_eq W _ _ rfl) rfl] simp only [← cancel_mono (L.map α.s), LeftFraction.map_comp_map_s, ← L.map_comp, Limits.zero_comp, add_left_neg] lemma add'_assoc (f₁ f₂ f₃ : L.obj X ⟶ L.obj Y) : add' W (add' W f₁ f₂) f₃ = add' W f₁ (add' W f₂ f₃) := by obtain ⟨α, h₁, h₂, h₃⟩ := exists_leftFraction₃ L W f₁ f₂ f₃ rw [add'_eq W f₁ f₂ α.forgetThd h₁ h₂, add'_eq W f₂ f₃ α.forgetFst h₂ h₃, add'_eq W _ _ (LeftFraction₂.mk (α.f + α.f') α.f'' α.s α.hs) rfl h₃, add'_eq W _ _ (LeftFraction₂.mk α.f (α.f' + α.f'') α.s α.hs) h₁ rfl] dsimp [LeftFraction₂.add] rw [add_assoc] @[reassoc (attr := simp)] lemma add'_comp (f₁ f₂ : L.obj X ⟶ L.obj Y) (g : L.obj Y ⟶ L.obj Z) : add' W f₁ f₂ ≫ g = add' W (f₁ ≫ g) (f₂ ≫ g) := by obtain ⟨α, h₁, h₂⟩ := exists_leftFraction₂ L W f₁ f₂ obtain ⟨β, hβ⟩ := exists_leftFraction L W g obtain ⟨γ, hγ⟩ := (RightFraction.mk _ α.hs β.f).exists_leftFraction dsimp at hγ rw [add'_eq W f₁ f₂ α h₁ h₂, add'_eq W (f₁ ≫ g) (f₂ ≫ g) (LeftFraction₂.mk (α.f ≫ γ.f) (α.f' ≫ γ.f) (β.s ≫ γ.s) (W.comp_mem _ _ β.hs γ.hs))]; rotate_left · rw [h₁, hβ] exact LeftFraction.map_comp_map_eq_map _ _ _ hγ _ · rw [h₂, hβ] exact LeftFraction.map_comp_map_eq_map _ _ _ hγ _ rw [hβ, LeftFraction.map_comp_map_eq_map _ _ γ hγ] dsimp [LeftFraction₂.add] rw [add_comp] @[reassoc (attr := simp)] lemma comp_add' (f : L.obj X ⟶ L.obj Y) (g₁ g₂ : L.obj Y ⟶ L.obj Z) : f ≫ add' W g₁ g₂ = add' W (f ≫ g₁) (f ≫ g₂) := by obtain ⟨α, hα⟩ := exists_leftFraction L W f obtain ⟨β, hβ₁, hβ₂⟩ := exists_leftFraction₂ L W g₁ g₂ obtain ⟨γ, hγ₁, hγ₂⟩ := (RightFraction₂.mk _ α.hs β.f β.f').exists_leftFraction₂ dsimp at hγ₁ hγ₂ rw [add'_eq W g₁ g₂ β hβ₁ hβ₂, add'_eq W (f ≫ g₁) (f ≫ g₂) (LeftFraction₂.mk (α.f ≫ γ.f) (α.f ≫ γ.f') (β.s ≫ γ.s) (W.comp_mem _ _ β.hs γ.hs)) (by simpa only [hα, hβ₁] using LeftFraction.map_comp_map_eq_map α β.fst γ.fst hγ₁ L) (by simpa only [hα, hβ₂] using LeftFraction.map_comp_map_eq_map α β.snd γ.snd hγ₂ L), hα, LeftFraction.map_comp_map_eq_map α β.add γ.add (by simp only [add_comp, hγ₁, hγ₂, comp_add])] dsimp [LeftFraction₂.add] rw [comp_add] @[simp] lemma add'_map (f₁ f₂ : X ⟶ Y) : add' W (L.map f₁) (L.map f₂) = L.map (f₁ + f₂) := (add'_eq W (L.map f₁) (L.map f₂) (LeftFraction₂.mk f₁ f₂ (𝟙 _) (W.id_mem _)) (LeftFraction.map_ofHom _ _ _ _).symm (LeftFraction.map_ofHom _ _ _ _).symm).trans (LeftFraction.map_ofHom _ _ _ _) variable (L X Y) /-- The abelian group structure on `L.obj X ⟶ L.obj Y` when `L : C ⥤ D` is a localization functor, `C` is preadditive and there is a left calculus of fractions. -/ noncomputable def addCommGroup' : AddCommGroup (L.obj X ⟶ L.obj Y) := by letI : Zero (L.obj X ⟶ L.obj Y) := ⟨L.map 0⟩ letI : Add (L.obj X ⟶ L.obj Y) := ⟨add' W⟩ letI : Neg (L.obj X ⟶ L.obj Y) := ⟨neg' W⟩ exact { add_assoc := add'_assoc _ add_zero := add'_zero _ add_comm := add'_comm _ zero_add := zero_add' _ add_left_neg := add'_left_neg' _ nsmul := nsmulRec zsmul := zsmulRec } variable {X Y} variable {L} variable {X' Y' Z' : D} (eX : L.obj X ≅ X') (eY : L.obj Y ≅ Y') (eZ : L.obj Z ≅ Z') /-- The bijection `(X' ⟶ Y') ≃ (L.obj X ⟶ L.obj Y)` induced by isomorphisms `eX : L.obj X ≅ X'` and `eY : L.obj Y ≅ Y'`. -/ @[simps] def homEquiv : (X' ⟶ Y') ≃ (L.obj X ⟶ L.obj Y) where toFun f := eX.hom ≫ f ≫ eY.inv invFun g := eX.inv ≫ g ≫ eY.hom left_inv _ := by simp right_inv _ := by simp /-- The addition of morphisms in `D`, when `L : C ⥤ D` is a localization functor, `C` is preadditive and there is a left calculus of fractions. -/ noncomputable def add (f₁ f₂ : X' ⟶ Y') : X' ⟶ Y' := (homEquiv eX eY).symm (add' W (homEquiv eX eY f₁) (homEquiv eX eY f₂)) @[reassoc] lemma add_comp (f₁ f₂ : X' ⟶ Y') (g : Y' ⟶ Z') : add W eX eY f₁ f₂ ≫ g = add W eX eZ (f₁ ≫ g) (f₂ ≫ g) := by obtain ⟨f₁, rfl⟩ := (homEquiv eX eY).symm.surjective f₁ obtain ⟨f₂, rfl⟩ := (homEquiv eX eY).symm.surjective f₂ obtain ⟨g, rfl⟩ := (homEquiv eY eZ).symm.surjective g simp [add] @[reassoc] lemma comp_add (f : X' ⟶ Y') (g₁ g₂ : Y' ⟶ Z') : f ≫ add W eY eZ g₁ g₂ = add W eX eZ (f ≫ g₁) (f ≫ g₂) := by obtain ⟨f, rfl⟩ := (homEquiv eX eY).symm.surjective f obtain ⟨g₁, rfl⟩ := (homEquiv eY eZ).symm.surjective g₁ obtain ⟨g₂, rfl⟩ := (homEquiv eY eZ).symm.surjective g₂ simp [add] lemma add_eq_add {X'' Y'' : C} (eX' : L.obj X'' ≅ X') (eY' : L.obj Y'' ≅ Y') (f₁ f₂ : X' ⟶ Y') : add W eX eY f₁ f₂ = add W eX' eY' f₁ f₂ := by have h₁ := comp_add W eX' eX eY (𝟙 _) f₁ f₂ have h₂ := add_comp W eX' eY eY' f₁ f₂ (𝟙 _) simp only [id_comp] at h₁ simp only [comp_id] at h₂ rw [h₁, h₂] variable (L X' Y') in /-- The abelian group structure on morphisms in `D`, when `L : C ⥤ D` is a localization functor, `C` is preadditive and there is a left calculus of fractions. -/ noncomputable def addCommGroup : AddCommGroup (X' ⟶ Y') := by have := Localization.essSurj L W letI := addCommGroup' L W (L.objPreimage X') (L.objPreimage Y') exact Equiv.addCommGroup (homEquiv (L.objObjPreimageIso X') (L.objObjPreimageIso Y')) lemma add_eq (f₁ f₂ : X' ⟶ Y') : letI := addCommGroup L W X' Y' f₁ + f₂ = add W eX eY f₁ f₂ := by apply add_eq_add variable (L) lemma map_add (f₁ f₂ : X ⟶ Y) : letI := addCommGroup L W (L.obj X) (L.obj Y) L.map (f₁ + f₂) = L.map f₁ + L.map f₂ := by rw [add_eq W (Iso.refl _) (Iso.refl _) (L.map f₁) (L.map f₂)] simp [add] end ImplementationDetails end Preadditive /-- The preadditive structure on `D`, when `L : C ⥤ D` is a localization functor, `C` is preadditive and there is a left calculus of fractions. -/ noncomputable def preadditive : Preadditive D where homGroup := Preadditive.addCommGroup L W add_comp _ _ _ _ _ _ := by apply Preadditive.add_comp comp_add _ _ _ _ _ _ := by apply Preadditive.comp_add lemma functor_additive : letI := preadditive L W L.Additive := letI := preadditive L W ⟨by apply Preadditive.map_add⟩ attribute [irreducible] preadditive lemma functor_additive_iff {E : Type*} [Category E] [Preadditive E] [Preadditive D] [L.Additive] (G : D ⥤ E) : G.Additive ↔ (L ⋙ G).Additive := by constructor · intro infer_instance · intro h suffices ∀ ⦃X Y : C⦄ (f g : L.obj X ⟶ L.obj Y), G.map (f + g) = G.map f + G.map g by refine ⟨fun {X Y f g} => ?_⟩ have hL := essSurj L W have eq := this ((L.objObjPreimageIso X).hom ≫ f ≫ (L.objObjPreimageIso Y).inv) ((L.objObjPreimageIso X).hom ≫ g ≫ (L.objObjPreimageIso Y).inv) rw [Functor.map_comp, Functor.map_comp, Functor.map_comp, Functor.map_comp, ← comp_add, ← comp_add, ← add_comp, ← add_comp, Functor.map_comp, Functor.map_comp] at eq rw [← cancel_mono (G.map (L.objObjPreimageIso Y).inv), ← cancel_epi (G.map (L.objObjPreimageIso X).hom), eq] intros X Y f g obtain ⟨φ, rfl, rfl⟩ := exists_leftFraction₂ L W f g have := Localization.inverts L W φ.s φ.hs rw [← φ.map_add L (inverts L W), ← cancel_mono (G.map (L.map φ.s)), ← G.map_comp, add_comp, ← G.map_comp, ← G.map_comp, LeftFraction.map_comp_map_s, LeftFraction.map_comp_map_s, LeftFraction.map_comp_map_s, ← Functor.comp_map, Functor.map_add, Functor.comp_map, Functor.comp_map] noncomputable instance : Preadditive W.Localization := preadditive W.Q W instance : W.Q.Additive := functor_additive W.Q W instance [HasZeroObject C] : HasZeroObject W.Localization := W.Q.hasZeroObject_of_additive variable [W.HasLocalization] noncomputable instance : Preadditive W.Localization' := preadditive W.Q' W instance : W.Q'.Additive := functor_additive W.Q' W instance [HasZeroObject C] : HasZeroObject W.Localization' := W.Q'.hasZeroObject_of_additive end Localization end CategoryTheory
CategoryTheory\Localization\DerivabilityStructure\Basic.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Resolution import Mathlib.CategoryTheory.GuitartExact.VerticalComposition /-! # Derivability structures Let `Φ : LocalizerMorphism W₁ W₂` be a localizer morphism, i.e. `W₁ : MorphismProperty C₁`, `W₂ : MorphismProperty C₂`, and `Φ.functor : C₁ ⥤ C₂` is a functors which maps `W₁` to `W₂`. Following the definition introduced by Bruno Kahn and Georges Maltsiniotis in [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008], we say that `Φ` is a right derivability structure if `Φ` has right resolutions and the following 2-square is Guitart exact, where `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` are localization functors for `W₁` and `W₂`, and `F : D₁ ⥤ D₂` is the induced functor on the localized categories: ``` Φ.functor C₁ ⥤ C₂ | | L₁| | L₂ v v D₁ ⥤ D₂ F ``` ## Implementation details In the field `guitartExact'` of the structure `LocalizerMorphism.IsRightDerivabilityStructure`, The condition that the square is Guitart exact is stated for the localization functors of the constructed categories (`W₁.Q` and `W₂.Q`). The lemma `LocalizerMorphism.isRightDerivabilityStructure_iff` show that it does not depend of the choice of the localization functors. ## TODO * Construct derived functors using derivability structures * Define the notion of left derivability structures * Construct the injective derivability structure in order to derive functor from the bounded below homotopy category in an abelian category with enough injectives * Construct the projective derivability structure in order to derive functor from the bounded above homotopy category in an abelian category with enough projectives * Construct the flat derivability structure on the bounded above homotopy category of categories of modules (and categories of sheaves of modules) * Define the product derivability structure and formalize derived functors of functors in several variables ## References * [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008] -/ universe v₁ v₂ u₁ u₂ namespace CategoryTheory open Category Localization variable {C₁ : Type u₁} {C₂ : Type u₂} [Category.{v₁} C₁] [Category.{v₂} C₂] {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} namespace LocalizerMorphism variable (Φ : LocalizerMorphism W₁ W₂) /-- A localizer morphism `Φ : LocalizerMorphism W₁ W₂` is a right derivability structure if it has right resolutions and the 2-square where the left and right functors are localizations functors for `W₁` and `W₂` are Guitart exact. -/ class IsRightDerivabilityStructure : Prop where hasRightResolutions : Φ.HasRightResolutions := by infer_instance guitartExact' : TwoSquare.GuitartExact ((Φ.catCommSq W₁.Q W₂.Q).iso).hom attribute [instance] IsRightDerivabilityStructure.hasRightResolutions IsRightDerivabilityStructure.guitartExact' variable {D₁ D₂ : Type*} [Category D₁] [Category D₂] (L₁ : C₁ ⥤ D₁) (L₂ : C₂ ⥤ D₂) [L₁.IsLocalization W₁] [L₂.IsLocalization W₂] (F : D₁ ⥤ D₂) lemma isRightDerivabilityStructure_iff [Φ.HasRightResolutions] (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ F) : Φ.IsRightDerivabilityStructure ↔ TwoSquare.GuitartExact e.hom := by have : Φ.IsRightDerivabilityStructure ↔ TwoSquare.GuitartExact ((Φ.catCommSq W₁.Q W₂.Q).iso).hom := ⟨fun h => h.guitartExact', fun h => ⟨inferInstance, h⟩⟩ rw [this] let e' := (Φ.catCommSq W₁.Q W₂.Q).iso let E₁ := Localization.uniq W₁.Q L₁ W₁ let E₂ := Localization.uniq W₂.Q L₂ W₂ let e₁ : W₁.Q ⋙ E₁.functor ≅ L₁ := compUniqFunctor W₁.Q L₁ W₁ let e₂ : W₂.Q ⋙ E₂.functor ≅ L₂ := compUniqFunctor W₂.Q L₂ W₂ let e'' : (Φ.functor ⋙ W₂.Q) ⋙ E₂.functor ≅ (W₁.Q ⋙ E₁.functor) ⋙ F := Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e₂ ≪≫ e ≪≫ isoWhiskerRight e₁.symm F let e''' : Φ.localizedFunctor W₁.Q W₂.Q ⋙ E₂.functor ≅ E₁.functor ⋙ F := liftNatIso W₁.Q W₁ _ _ _ _ e'' have : TwoSquare.vComp' e'.hom e'''.hom e₁ e₂ = e.hom := by ext X₁ rw [TwoSquare.vComp'_app, liftNatIso_hom, liftNatTrans_app] simp only [Functor.comp_obj, Iso.trans_hom, isoWhiskerLeft_hom, isoWhiskerRight_hom, Iso.symm_hom, NatTrans.comp_app, Functor.associator_hom_app, whiskerLeft_app, whiskerRight_app, id_comp, assoc, e''] dsimp [Lifting.iso] rw [F.map_id, id_comp, ← F.map_comp, Iso.inv_hom_id_app, F.map_id, comp_id, ← Functor.map_comp_assoc] erw [show (CatCommSq.iso Φ.functor W₁.Q W₂.Q (localizedFunctor Φ W₁.Q W₂.Q)).hom = (Lifting.iso W₁.Q W₁ _ _).inv by rfl, Iso.inv_hom_id_app] simp rw [← TwoSquare.GuitartExact.vComp'_iff_of_equivalences e'.hom E₁ E₂ e''' e₁ e₂, this] lemma guitartExact_of_isRightDerivabilityStructure' [h : Φ.IsRightDerivabilityStructure] (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ F) : TwoSquare.GuitartExact e.hom := by simpa only [Φ.isRightDerivabilityStructure_iff L₁ L₂ F e] using h lemma guitartExact_of_isRightDerivabilityStructure [Φ.IsRightDerivabilityStructure] : TwoSquare.GuitartExact ((Φ.catCommSq L₁ L₂).iso).hom := guitartExact_of_isRightDerivabilityStructure' _ _ _ _ _ instance [W₁.ContainsIdentities] : (LocalizerMorphism.id W₁).HasRightResolutions := fun X₂ => ⟨RightResolution.mk (𝟙 X₂) (W₁.id_mem X₂)⟩ instance [W₁.ContainsIdentities] : (LocalizerMorphism.id W₁).IsRightDerivabilityStructure := by rw [(LocalizerMorphism.id W₁).isRightDerivabilityStructure_iff W₁.Q W₁.Q (𝟭 W₁.Localization) (Iso.refl _)] dsimp exact TwoSquare.guitartExact_id W₁.Q end LocalizerMorphism end CategoryTheory
CategoryTheory\Localization\DerivabilityStructure\Constructor.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.DerivabilityStructure.Basic /-! # Constructor for derivability structures In this file, we provide a constructor for right derivability structures. Assume that `W₁` and `W₂` are classes of morphisms in categories `C₁` and `C₂`, and that we have a localizer morphism `Φ : LocalizerMorphism W₁ W₂` that is a localized equivalence, i.e. `Φ.functor` induces an equivalence of categories between the localized categories. Assume moreover that `W₁` is multiplicative and `W₂` contains identities. Then, `Φ` is a right derivability structure (`LocalizerMorphism.IsRightDerivabilityStructure.mk'`) if it satisfies the two following conditions: * for any `X₂ : C₂`, the category `Φ.RightResolution X₂` of resolutions of `X₂` is connected * any arrow in `C₂` admits a resolution (i.e. `Φ.arrow.HasRightResolutions` holds, where `Φ.arrow` is the induced localizer morphism on categories of arrows in `C₁` and `C₂`) This statement is essentially Lemme 6.5 in [the paper by Kahn and Maltsiniotis][KahnMaltsiniotis2008]. ## References * [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008] -/ namespace CategoryTheory open Category Localization variable {C₁ C₂ : Type*} [Category C₁] [Category C₂] {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} namespace LocalizerMorphism namespace IsRightDerivabilityStructure section variable (Φ : LocalizerMorphism W₁ W₂) [W₁.IsMultiplicative] [∀ X₂, IsConnected (Φ.RightResolution X₂)] [Φ.arrow.HasRightResolutions] [W₂.ContainsIdentities] namespace Constructor variable {D : Type*} [Category D] (L : C₂ ⥤ D) [L.IsLocalization W₂] {X₂ : C₂} {X₃ : D} (y : L.obj X₂ ⟶ X₃) /-- Given `Φ : LocalizerMorphism W₁ W₂`, `L : C₂ ⥤ D` a localization functor for `W₂` and a morphism `y : L.obj X₂ ⟶ X₃`, this is the functor which sends `R : Φ.RightResolution d` to `(isoOfHom L W₂ R.w R.hw).inv ≫ y` in the category `w.CostructuredArrowDownwards y` where `w` is `TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _) (Functor.rightUnitor _).inv`. -/ @[simps] noncomputable def fromRightResolution : Φ.RightResolution X₂ ⥤ (TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _) (Functor.rightUnitor _).inv).CostructuredArrowDownwards y where obj R := CostructuredArrow.mk (Y := StructuredArrow.mk R.w) (StructuredArrow.homMk ((isoOfHom L W₂ R.w R.hw).inv ≫ y)) map {R R'} φ := CostructuredArrow.homMk (StructuredArrow.homMk φ.f) (by ext dsimp rw [← assoc, ← cancel_epi (isoOfHom L W₂ R.w R.hw).hom, isoOfHom_hom, isoOfHom_hom_inv_id_assoc, assoc, ← L.map_comp_assoc, φ.comm, isoOfHom_hom_inv_id_assoc]) lemma isConnected : IsConnected ((TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _) (Functor.rightUnitor _).inv).CostructuredArrowDownwards y) := by let w := (TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _) (Functor.rightUnitor _).inv) have : Nonempty (w.CostructuredArrowDownwards y) := ⟨(fromRightResolution Φ L y).obj (Classical.arbitrary _)⟩ suffices ∀ (X : w.CostructuredArrowDownwards y), ∃ Y, Zigzag X ((fromRightResolution Φ L y).obj Y) by refine zigzag_isConnected (fun X X' => ?_) obtain ⟨Y, hX⟩ := this X obtain ⟨Y', hX'⟩ := this X' exact hX.trans ((zigzag_obj_of_zigzag _ (isPreconnected_zigzag Y Y')).trans hX'.symm) intro X obtain ⟨c, g, x, fac, rfl⟩ := TwoSquare.CostructuredArrowDownwards.mk_surjective X dsimp [w] at x fac rw [id_comp] at fac let ρ : Φ.arrow.RightResolution (Arrow.mk g) := Classical.arbitrary _ refine ⟨RightResolution.mk ρ.w.left ρ.hw.1, ?_⟩ have := zigzag_obj_of_zigzag (fromRightResolution Φ L x ⋙ w.costructuredArrowDownwardsPrecomp x y g fac) (isPreconnected_zigzag (RightResolution.mk (𝟙 _) (W₂.id_mem _)) (RightResolution.mk ρ.w.right ρ.hw.2)) refine Zigzag.trans ?_ (Zigzag.trans this ?_) · exact Zigzag.of_hom (eqToHom (by aesop)) · apply Zigzag.of_inv refine CostructuredArrow.homMk (StructuredArrow.homMk ρ.X₁.hom (by simp)) ?_ ext dsimp rw [← cancel_epi (isoOfHom L W₂ ρ.w.left ρ.hw.1).hom, isoOfHom_hom, isoOfHom_hom_inv_id_assoc, ← L.map_comp_assoc, Arrow.w_mk_right, Arrow.mk_hom, L.map_comp, assoc, isoOfHom_hom_inv_id_assoc, fac] end Constructor /-- If a localizer morphism `Φ` is a localized equivalence, then it is a right derivability structure if the categories of right resolutions are connected and the categories of right resolutions of arrows are nonempty. -/ lemma mk' [Φ.IsLocalizedEquivalence] : Φ.IsRightDerivabilityStructure := by rw [Φ.isRightDerivabilityStructure_iff (Φ.functor ⋙ W₂.Q) W₂.Q (𝟭 _) (Functor.rightUnitor _).symm, TwoSquare.guitartExact_iff_isConnected_downwards] intro X₂ X₃ g apply Constructor.isConnected end end IsRightDerivabilityStructure end LocalizerMorphism end CategoryTheory
CategoryTheory\Monad\Adjunction.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.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 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`. -/ -- Porting note: Specifying simps projections manually to match mathlib3 behavior. @[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`. -/ -- Porting note: Specifying simps projections manually to match mathlib3 behavior. @[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 X => 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 X => 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 X => 𝟙 _ } inv := { app := fun X => 𝟙 _ } 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 X => 𝟙 _ } inv := { app := fun X => 𝟙 _ } 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 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 right 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 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] erw [X.unit] simp⟩⟩⟩ 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 aesop_cat⟩ 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] erw [X.counit] simp, 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 [Adjunction.counit_naturality, Functor.comp_obj, Functor.id_obj, Adjunction.left_triangle_components_assoc, assoc] erw [X.counit] simp lemma comparison_full [R.Full] {L : C ⥤ D} (adj : R ⊣ L) : (Comonad.comparison adj).Full where map_surjective f := ⟨R.preimage f.f, by aesop_cat⟩ 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 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 adj := coreflectorAdjunction R eqv := { full := Coreflective.comparison_full _ } end CategoryTheory
CategoryTheory\Monad\Algebra.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.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 aesop_cat /-- The associativity axiom associated to an algebra. -/ assoc : T.μ.app A ≫ a = (T : C ⥤ C).map a ≫ a := by aesop_cat 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 aesop_cat -- Porting note: no need to restate axioms in lean4. --restate_axiom hom.h 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 _ _ _ -- Porting note (#11041): Adding this `ext` lemma to help automation below. @[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 aesop_cat) : 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 dsimp simp [← Y.assoc, ← T.μ.naturality_assoc] } left_inv := fun f => by ext dsimp 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 rw [IsIso.eq_comp_inv f.f, Category.assoc, ← f.h] simp }, by aesop_cat⟩⟩ instance forget_reflects_iso : T.forget.ReflectsIsomorphisms where -- Porting note: Is this the right approach to introduce instances? reflects {_ _} f := fun [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 dsimp simp [A.unit] assoc := by dsimp simp [A.assoc] } map f := { f := f.f } /-- The identity monad morphism induces the identity functor from the category of algebras to itself. -/ -- Porting note: `semireducible -> default` @[simps (config := { 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 (config := { 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 (config := { 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`. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] 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 aesop_cat /-- The coassociativity axiom associated to a coalgebra. -/ coassoc : a ≫ G.δ.app A = a ≫ G.map a := by aesop_cat -- Porting note: no need to restate axioms in lean4. --restate_axiom coalgebra.counit' --restate_axiom coalgebra.coassoc' attribute [reassoc] Coalgebra.counit Coalgebra.coassoc namespace Coalgebra variable {G : Comonad C} /-- A morphism of Eilenberg-Moore coalgebras for the comonad `G`. -/ -- Porting note(#5171): linter not ported yet --@[ext, nolint has_nonempty_instance] @[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 aesop_cat -- Porting note: no need to restate axioms in lean4. --restate_axiom hom.h 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 _ _ _ -- Porting note (#11041): Adding `ext` lemma to help automation below. @[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 aesop_cat) : 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 dsimp 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 aesop_cat⟩⟩ instance forget_reflects_iso : G.forget.ReflectsIsomorphisms where -- Porting note: Is this the right approach to introduce instances? reflects {_ _} f := fun [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
CategoryTheory\Monad\Basic.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta, Adam Topaz -/ import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.Functor.FullyFaithful import Mathlib.CategoryTheory.Functor.ReflectsIso /-! # 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 [CategoryTheory 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 aesop_cat left_unit : ∀ X : C, η.app (toFunctor.obj X) ≫ μ.app _ = 𝟙 _ := by aesop_cat right_unit : ∀ X : C, toFunctor.map (η.app X) ≫ μ.app _ = 𝟙 _ := by aesop_cat /-- 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 aesop_cat left_counit : ∀ X : C, δ.app X ≫ ε.app (toFunctor.obj X) = 𝟙 _ := by aesop_cat right_counit : ∀ X : C, δ.app X ≫ toFunctor.map (ε.app X) = 𝟙 _ := by aesop_cat 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⟩ -- Porting note: these lemmas are syntactic tautologies --@[simp] --theorem monad_toFunctor_eq_coe : T.toFunctor = T := -- rfl -- --@[simp] --theorem comonad_toFunctor_eq_coe : G.toFunctor = G := -- rfl initialize_simps_projections CategoryTheory.Monad (toFunctor → coe) initialize_simps_projections CategoryTheory.Comonad (toFunctor → coe) -- Porting note: 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 aesop_cat app_μ : ∀ X, T₁.μ.app X ≫ app X = (T₁.map (app X) ≫ app _) ≫ T₂.μ.app X := by aesop_cat 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 aesop_cat app_δ : ∀ X, app X ≫ N.δ.app X = M.δ.app X ≫ app _ ≫ N.map (app X) := by aesop_cat 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 -- Porting note (#10688): added to ease automation @[ext] lemma MonadHom.ext' {T₁ T₂ : Monad C} (f g : T₁ ⟶ T₂) (h : f.app = g.app) : f = g := MonadHom.ext h -- Porting note (#10688): added to ease automation @[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] } } -- `aesop_cat` 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] } } -- `aesop_cat` 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 aesop_cat) (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 aesop_cat) : 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 aesop_cat) (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 aesop_cat) : 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. -/ /- Porting note: removed `@[simps (config := { rhsMd := semireducible })]` and replaced with `@[simps]` in the two declarations below-/ @[simps!] 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!] 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 [id_obj, 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 [id_obj, 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 end CategoryTheory
CategoryTheory\Monad\Coequalizer.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.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`. 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
CategoryTheory\Monad\Equalizer.lean
/- Copyright (c) 2024 Jack McKoen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jack McKoen -/ 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`. 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] erw [← T.ε.naturality, reassoc_of% h₁, Comonad.left_counit] -- TODO: missing simp lemmas 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
CategoryTheory\Monad\EquivMon.lean
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ 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 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 /-- 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) one := M.η mul := M.μ mul_assoc := by ext; simp [M.assoc] variable (C) /-- Passing from `Monad C` to `Mon_ (C ⥤ C)` is functorial. -/ @[simps] def monadToMon : Monad C ⥤ Mon_ (C ⥤ C) where obj := toMon map f := { hom := f.toNatTrans } variable {C} /-- 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.one μ := M.mul left_unit := fun X => by -- Porting note: now using `erw` erw [← whiskerLeft_app, ← NatTrans.comp_app, M.mul_one] rfl right_unit := fun X => by -- Porting note: now using `erw` erw [← whiskerRight_app, ← NatTrans.comp_app, M.one_mul] rfl assoc := fun X => by rw [← whiskerLeft_app, ← whiskerRight_app, ← NatTrans.comp_app] -- Porting note: had to add this step: erw [M.mul_assoc] simp -- 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_η := by intro X erw [← NatTrans.comp_app, f.one_hom] simp only [Functor.id_obj, ofMon_obj, ofMon_η] app_μ := by intro Z erw [← NatTrans.comp_app, f.mul_hom] dsimp simp only [Category.assoc, NatTrans.naturality, ofMon_obj, ofMon] } /-- 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
CategoryTheory\Monad\Kleisli.lean
/- Copyright (c) 2020 Wojciech Nawrocki. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wojciech Nawrocki, Bhavik Mehta -/ 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 [CategoryTheory 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 {X} {Y} {Z} f g := f ≫ (T : C ⥤ C).map g ≫ T.μ.app Z id_comp {X} {Y} f := by dsimp -- Porting note: unfold comp rw [← T.η.naturality_assoc f, T.left_unit] apply Category.comp_id assoc f g h := by simp only [Functor.map_comp, Category.assoc, Monad.assoc] erw [T.μ.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 -- Porting note: hack for missing unfold_projs tactic change _ = (f ≫ (Monad.η T).app Y) ≫ T.map (g ≫ (Monad.η T).app Z) ≫ T.μ.app Z 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 X := T.right_unit _ map_comp {X} {Y} {Z} f g := by -- Porting note: hack for missing unfold_projs tactic change T.map (f ≫ T.map g ≫ T.μ.app Z) ≫ T.μ.app Z = _ simp only [Functor.map_comp, Category.assoc] erw [← 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 -- Porting note: used to be unfold_projs; dsimp change f ≫ g = (f ≫ T.η.app Y) ≫ T.map g ≫ T.μ.app Z rw [Category.assoc, ← T.η.naturality_assoc g, Functor.id_map] dsimp simp [Monad.left_unit] } /-- The composition of the adjunction gives the original functor. -/ def toKleisliCompFromKleisliIsoSelf : toKleisli T ⋙ fromKleisli T ≅ T := NatIso.ofComponents fun X => 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 {X} {Y} {Z} f g := U.δ.app X ≫ (U : C ⥤ C).map f ≫ g id_comp f := by dsimp; rw [U.right_counit_assoc] assoc {X} {Y} {Z} {W} f g h := by -- Porting note: working around lack of unfold_projs change U.δ.app X ≫ U.map (U.δ.app X ≫ U.map f ≫ g) ≫ h = U.δ.app X ≫ U.map f ≫ (U.δ.app Y ≫ U.map g ≫ h) -- Porting note: something was broken here and was easier just to redo from scratch simp only [Functor.map_comp, ← Category.assoc, eq_whisker] simp only [Category.assoc, U.δ.naturality, Functor.comp_map, U.coassoc_assoc] 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 -- Porting note: working around lack of unfold_projs change U.ε.app X ≫ f ≫ g = U.δ.app X ≫ U.map (U.ε.app X ≫ f) ≫ U.ε.app Y ≫ g simp [← U.ε.naturality g] /-- 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 X := U.right_counit _ map_comp {X} {Y} {_} f g := by -- Porting note: working around lack of unfold_projs change U.δ.app X ≫ U.map (U.δ.app X ≫ U.map f ≫ g) = (U.δ.app X ≫ U.map f) ≫ (U.δ.app Y ≫ U.map g) 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 -- Porting note: working around lack of unfold_projs change f ≫ g = U.δ.app X ≫ U.map f ≫ U.ε.app Y ≫ g erw [← Category.assoc (U.map f), U.ε.naturality]; dsimp simp only [← Category.assoc, Comonad.left_counit, Category.id_comp] } /-- The composition of the adjunction gives the original functor. -/ def toCokleisliCompFromCokleisliIsoSelf : toCokleisli U ⋙ fromCokleisli U ≅ U := NatIso.ofComponents fun X => Iso.refl _ end Adjunction end Cokleisli end CategoryTheory
CategoryTheory\Monad\Limits.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta, Jack McKoen -/ import Mathlib.CategoryTheory.Monad.Adjunction import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # 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 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] dsimp; simp -- See library note [dsimp, 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 dsimp erw [c.w f] simp } /-- (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. -/ 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] 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)] dsimp; simp -- See library note [dsimp, 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] 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] 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 dsimp erw [comp_id, c.w] } } 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 _) := @hasLimitOfIso _ _ _ _ (F ⋙ R) _ _ (isoWhiskerLeft F (Monad.comparisonForget (monadicAdjunction R)).symm) 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 preservesColimitOfIsoDiagram _ 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 preservesColimitOfIsoDiagram _ (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.leftAdjointPreservesColimits (monadicAdjunction R)).1 letI : PreservesColimitsOfShape J (monadicLeftAdjoint R ⋙ R) := by apply CategoryTheory.Limits.compPreservesColimitsOfShape _ _ ⟨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).leftAdjointPreservesColimits.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. -/ noncomputable def leftAdjointPreservesTerminalOfReflective (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 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.preservesLimitOfCreatesLimitAndHasLimit F R apply (A.preserves (limit.isLimit F)).conePointUniqueUpToIso h apply preservesLimitOfIsoDiagram _ (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 dsimp erw [c.w f] simp } /-- (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. -/ 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] 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] 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] 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 dsimp erw [id_comp, c.w] } } 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 _) := @hasColimitOfIso _ _ _ _ (F ⋙ R) _ _ (isoWhiskerLeft F (Comonad.comparisonForget (comonadicAdjunction R)).symm) 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 preservesLimitOfIsoDiagram _ 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 preservesLimitOfIsoDiagram _ (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.rightAdjointPreservesLimits (comonadicAdjunction R)).1 letI : PreservesLimitsOfShape J (comonadicRightAdjoint R ⋙ R) := by apply CategoryTheory.Limits.compPreservesLimitsOfShape _ _ ⟨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).rightAdjointPreservesLimits.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. -/ noncomputable def rightAdjointPreservesInitialOfCoreflective (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 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.preservesColimitOfCreatesColimitAndHasColimit F R apply (A.preserves (colimit.isColimit F)).coconePointUniqueUpToIso h apply preservesColimitOfIsoDiagram _ (Functor.emptyExt (F ⋙ R) _) end end CategoryTheory
CategoryTheory\Monad\Monadicity.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.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 right 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` ## Tags Beck, monadicity, descent ## TODO Dualise to show comonadicity theorems. -/ 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⟩ left_inv := fun g => by ext; rfl right_inv := fun f => by ext; rfl } /-- 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 -- Porting note: the goal was previously closed by the following, which succeeds until -- `Category.assoc`. -- dsimp [comparisonLeftAdjointHomEquiv] -- rw [← adj.homEquiv_naturality_right, Category.assoc] simp [Cofork.IsColimit.homIso] /-- 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 change _ = G.map _ ≫ _ 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)) -- Porting note: Lean 3 didn't seem to need this 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 end MonadicityInternal open CategoryTheory Adjunction Monad 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 · apply @preservesColimitOfIsoDiagram _ _ _ _ _ _ _ _ _ (diagramIsoParallelPair.{v₁} _).symm ?_ dsimp infer_instance · apply @preservesColimitOfIsoDiagram _ _ _ _ _ _ _ _ _ (diagramIsoParallelPair.{v₁} _).symm ?_ dsimp infer_instance section BeckMonadicity -- Porting note: added these to replace parametric instances lean4#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] 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 lean4#2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g], PreservesColimit (parallelPair f g) 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 lean4#2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g], ReflectsColimit (parallelPair f g) 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 `C` has them. -/ def monadicOfHasPreservesReflectsGSplitCoequalizers [HasCoequalizerOfIsSplitPair G] [PreservesColimitOfIsSplitPair G] [ReflectsColimitOfIsSplitPair G] : MonadicRightAdjoint G where 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 lean4#2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsSplitPair f g], CreatesColimit (parallelPair f g) G] : class CreatesColimitOfIsSplitPair (G : D ⥤ C) where 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 right adjoint and creates coequalizers of `G`-split pairs, then it is monadic. This is the converse of `createsGSplitOfMonadic`. -/ def monadicOfCreatesGSplitCoequalizers [CreatesColimitOfIsSplitPair G] : MonadicRightAdjoint G := by let I {A B} (f g : A ⟶ B) [G.IsSplitPair f g] : HasColimit (parallelPair f g ⋙ G) := by apply @hasColimitOfIso _ _ _ _ _ _ ?_ (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 reflectsColimitOfReflectsIsomorphisms⟩ apply monadicOfHasPreservesReflectsGSplitCoequalizers adj end BeckMonadicity section ReflexiveMonadicity variable [HasReflexiveCoequalizers D] [G.ReflectsIsomorphisms] -- Porting note: added these to replace parametric instances lean4#2311 -- [∀ ⦃A B⦄ (f g : A ⟶ B) [G.IsReflexivePair f g], PreservesColimit (parallelPair f g) 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 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 reflectsColimitOfReflectsIsomorphisms exact (comparisonAdjunction adj).toEquivalence.isEquivalence_inverse end ReflexiveMonadicity end end Monad end CategoryTheory
CategoryTheory\Monad\Products.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over 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 Y => Limits.prod.snd } δ := { app := fun Y => 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] dsimp 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 _) (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 Y => coprod.inr } μ := { app := fun Y => 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] dsimp 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
CategoryTheory\Monad\Types.lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Bhavik Mehta -/ import Mathlib.CategoryTheory.Monad.Basic import Mathlib.CategoryTheory.Monad.Kleisli import Mathlib.CategoryTheory.Category.KleisliCat import Mathlib.CategoryTheory.Types import Mathlib.Control.Basic -- Porting note: Needed for `joinM_map_map`, etc. /-! # 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] -- Porting note: Used `apply ...` instead of the direct term -- in a few proofs below to avoid introducing typeclass instances inline. /-- 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 α β (f : α → β) => funext fun a => by apply joinM_map_map⟩ assoc α := funext fun a => by apply joinM_map_joinM left_unit α := funext fun a => by apply joinM_pure right_unit α := funext fun a => by apply 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 X => rfl map_comp := fun f g => by --unfold_projs funext t -- Porting note: missing tactic `unfold_projs`, using `change` instead. change _ = joinM (g <$> (f t)) simp only [joinM, seq_bind_eq, Function.id_comp] rfl } inverse := { obj := fun X => X map := fun f => f map_id := fun X => 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 dsimp -- Porting note: missing tactic `unfold_projs`, using `change` instead. change joinM (g <$> (f t)) = _ simp only [joinM, seq_bind_eq, Function.id_comp] 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
CategoryTheory\Monoidal\Bimod.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Oleksandr Manzyuk -/ import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.Monoidal.Mon_ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers /-! # The category of bimodule objects over a pair of monoid objects. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory open CategoryTheory.MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] section open CategoryTheory.Limits variable [HasCoequalizers C] section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] theorem id_tensor_π_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Z ⊗ Y ⟶ W) (wh : (Z ◁ f) ≫ h = (Z ◁ g) ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorLeft Z) f g h wh theorem id_tensor_π_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : Z ⊗ X ⟶ X') (q : Z ⊗ Y ⟶ Y') (wf : (Z ◁ f) ≫ q = p ≫ f') (wg : (Z ◁ g) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ colimMap (parallelPairHom (Z ◁ f) (Z ◁ g) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorLeft Z) f g f' g' p q wf wg h wh end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem π_tensor_id_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Y ⊗ Z ⟶ W) (wh : (f ▷ Z) ≫ h = (g ▷ Z) ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorRight Z) f g h wh theorem π_tensor_id_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⊗ Z ⟶ X') (q : Y ⊗ Z ⟶ Y') (wf : (f ▷ Z) ≫ q = p ≫ f') (wg : (g ▷ Z) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ colimMap (parallelPairHom (f ▷ Z) (g ▷ Z) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorRight Z) f g f' g' p q wf wg h wh end end /-- A bimodule object for a pair of monoid objects, all internal to some monoidal category. -/ structure Bimod (A B : Mon_ C) where X : C actLeft : A.X ⊗ X ⟶ X one_actLeft : (A.one ▷ X) ≫ actLeft = (λ_ X).hom := by aesop_cat left_assoc : (A.mul ▷ X) ≫ actLeft = (α_ A.X A.X X).hom ≫ (A.X ◁ actLeft) ≫ actLeft := by aesop_cat actRight : X ⊗ B.X ⟶ X actRight_one : (X ◁ B.one) ≫ actRight = (ρ_ X).hom := by aesop_cat right_assoc : (X ◁ B.mul) ≫ actRight = (α_ X B.X B.X).inv ≫ (actRight ▷ B.X) ≫ actRight := by aesop_cat middle_assoc : (actLeft ▷ B.X) ≫ actRight = (α_ A.X X B.X).hom ≫ (A.X ◁ actRight) ≫ actLeft := by aesop_cat attribute [reassoc (attr := simp)] Bimod.one_actLeft Bimod.actRight_one Bimod.left_assoc Bimod.right_assoc Bimod.middle_assoc namespace Bimod variable {A B : Mon_ C} (M : Bimod A B) /-- A morphism of bimodule objects. -/ @[ext] structure Hom (M N : Bimod A B) where hom : M.X ⟶ N.X left_act_hom : M.actLeft ≫ hom = (A.X ◁ hom) ≫ N.actLeft := by aesop_cat right_act_hom : M.actRight ≫ hom = (hom ▷ B.X) ≫ N.actRight := by aesop_cat attribute [reassoc (attr := simp)] Hom.left_act_hom Hom.right_act_hom /-- The identity morphism on a bimodule object. -/ @[simps] def id' (M : Bimod A B) : Hom M M where hom := 𝟙 M.X instance homInhabited (M : Bimod A B) : Inhabited (Hom M M) := ⟨id' M⟩ /-- Composition of bimodule object morphisms. -/ @[simps] def comp {M N O : Bimod A B} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom instance : Category (Bimod A B) where Hom M N := Hom M N id := id' comp f g := comp f g -- Porting note: added because `Hom.ext` is not triggered automatically @[ext] lemma hom_ext {M N : Bimod A B} (f g : M ⟶ N) (h : f.hom = g.hom) : f = g := Hom.ext h @[simp] theorem id_hom' (M : Bimod A B) : (𝟙 M : Hom M M).hom = 𝟙 M.X := rfl @[simp] theorem comp_hom' {M N K : Bimod A B} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : Hom M K).hom = f.hom ≫ g.hom := rfl /-- Construct an isomorphism of bimodules by giving an isomorphism between the underlying objects and checking compatibility with left and right actions only in the forward direction. -/ @[simps] def isoOfIso {X Y : Mon_ C} {P Q : Bimod X Y} (f : P.X ≅ Q.X) (f_left_act_hom : P.actLeft ≫ f.hom = (X.X ◁ f.hom) ≫ Q.actLeft) (f_right_act_hom : P.actRight ≫ f.hom = (f.hom ▷ Y.X) ≫ Q.actRight) : P ≅ Q where hom := { hom := f.hom } inv := { hom := f.inv left_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_left_act_hom, ← Category.assoc, ← MonoidalCategory.whiskerLeft_comp, Iso.inv_hom_id, MonoidalCategory.whiskerLeft_id, Category.id_comp] right_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_right_act_hom, ← Category.assoc, ← comp_whiskerRight, Iso.inv_hom_id, MonoidalCategory.id_whiskerRight, Category.id_comp] } hom_inv_id := by ext; dsimp; rw [Iso.hom_inv_id] inv_hom_id := by ext; dsimp; rw [Iso.inv_hom_id] variable (A) /-- A monoid object as a bimodule over itself. -/ @[simps] def regular : Bimod A A where X := A.X actLeft := A.mul actRight := A.mul instance : Inhabited (Bimod A A) := ⟨regular A⟩ /-- The forgetful functor from bimodule objects to the ambient category. -/ def forget : Bimod A B ⥤ C where obj A := A.X map f := f.hom open CategoryTheory.Limits variable [HasCoequalizers C] namespace TensorBimod variable {R S T : Mon_ C} (P : Bimod R S) (Q : Bimod S T) /-- The underlying object of the tensor product of two bimodules. -/ noncomputable def X : C := coequalizer (P.actRight ▷ Q.X) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actLeft)) section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] /-- Left action for the tensor product of two bimodules. -/ noncomputable def actLeft : R.X ⊗ X P Q ⟶ X P Q := (PreservesCoequalizer.iso (tensorLeft R.X) _ _).inv ≫ colimMap (parallelPairHom _ _ _ _ ((α_ _ _ _).inv ≫ ((α_ _ _ _).inv ▷ _) ≫ (P.actLeft ▷ S.X ▷ Q.X)) ((α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X)) (by dsimp simp only [Category.assoc] slice_lhs 1 2 => rw [associator_inv_naturality_middle] slice_rhs 3 4 => rw [← comp_whiskerRight, middle_assoc, comp_whiskerRight] coherence) (by dsimp slice_lhs 1 1 => rw [MonoidalCategory.whiskerLeft_comp] slice_lhs 2 3 => rw [associator_inv_naturality_right] slice_lhs 3 4 => rw [whisker_exchange] coherence)) theorem whiskerLeft_π_actLeft : (R.X ◁ coequalizer.π _ _) ≫ actLeft P Q = (α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X) ≫ coequalizer.π _ _ := by erw [map_π_preserves_coequalizer_inv_colimMap (tensorLeft _)] simp only [Category.assoc] theorem one_act_left' : (R.one ▷ _) ≫ actLeft P Q = (λ_ _).hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace `rw` by `erw` slice_lhs 1 2 => erw [whisker_exchange] slice_lhs 2 3 => rw [whiskerLeft_π_actLeft] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, one_actLeft] slice_rhs 1 2 => rw [leftUnitor_naturality] coherence theorem left_assoc' : (R.mul ▷ _) ≫ actLeft P Q = (α_ R.X R.X _).hom ≫ (R.X ◁ actLeft P Q) ≫ actLeft P Q := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [X] slice_lhs 1 2 => rw [whisker_exchange] slice_lhs 2 3 => rw [whiskerLeft_π_actLeft] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, left_assoc, comp_whiskerRight, comp_whiskerRight] slice_rhs 1 2 => rw [associator_naturality_right] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 5 => rw [whiskerLeft_π_actLeft] slice_rhs 3 4 => rw [associator_inv_naturality_middle] coherence end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] /-- Right action for the tensor product of two bimodules. -/ noncomputable def actRight : X P Q ⊗ T.X ⟶ X P Q := (PreservesCoequalizer.iso (tensorRight T.X) _ _).inv ≫ colimMap (parallelPairHom _ _ _ _ ((α_ _ _ _).hom ≫ (α_ _ _ _).hom ≫ (P.X ◁ S.X ◁ Q.actRight) ≫ (α_ _ _ _).inv) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actRight)) (by dsimp slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] simp) (by dsimp simp only [comp_whiskerRight, whisker_assoc, Category.assoc, Iso.inv_hom_id_assoc] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, middle_assoc, MonoidalCategory.whiskerLeft_comp] simp)) theorem π_tensor_id_actRight : (coequalizer.π _ _ ▷ T.X) ≫ actRight P Q = (α_ _ _ _).hom ≫ (P.X ◁ Q.actRight) ≫ coequalizer.π _ _ := by erw [map_π_preserves_coequalizer_inv_colimMap (tensorRight _)] simp only [Category.assoc] theorem actRight_one' : (_ ◁ T.one) ≫ actRight P Q = (ρ_ _).hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace `rw` by `erw` slice_lhs 1 2 =>erw [← whisker_exchange] slice_lhs 2 3 => rw [π_tensor_id_actRight] slice_lhs 1 2 => rw [associator_naturality_right] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, actRight_one] simp theorem right_assoc' : (_ ◁ T.mul) ≫ actRight P Q = (α_ _ T.X T.X).inv ≫ (actRight P Q ▷ T.X) ≫ actRight P Q := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace some `rw` by `erw` slice_lhs 1 2 => rw [← whisker_exchange] slice_lhs 2 3 => rw [π_tensor_id_actRight] slice_lhs 1 2 => rw [associator_naturality_right] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, right_assoc, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 1 2 => rw [associator_inv_naturality_left] slice_rhs 2 3 => rw [← comp_whiskerRight, π_tensor_id_actRight, comp_whiskerRight, comp_whiskerRight] slice_rhs 4 5 => rw [π_tensor_id_actRight] simp end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem middle_assoc' : (actLeft P Q ▷ T.X) ≫ actRight P Q = (α_ R.X _ T.X).hom ≫ (R.X ◁ actRight P Q) ≫ actLeft P Q := by refine (cancel_epi ((tensorLeft _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] slice_lhs 1 2 => rw [← comp_whiskerRight, whiskerLeft_π_actLeft, comp_whiskerRight, comp_whiskerRight] slice_lhs 3 4 => rw [π_tensor_id_actRight] slice_lhs 2 3 => rw [associator_naturality_left] -- Porting note: had to replace `rw` by `erw` slice_rhs 1 2 => rw [associator_naturality_middle] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, π_tensor_id_actRight, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 5 => rw [whiskerLeft_π_actLeft] slice_rhs 3 4 => rw [associator_inv_naturality_right] slice_rhs 4 5 => rw [whisker_exchange] simp end end TensorBimod section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] /-- Tensor product of two bimodule objects as a bimodule object. -/ @[simps] noncomputable def tensorBimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : Bimod X Z where X := TensorBimod.X M N actLeft := TensorBimod.actLeft M N actRight := TensorBimod.actRight M N one_actLeft := TensorBimod.one_act_left' M N actRight_one := TensorBimod.actRight_one' M N left_assoc := TensorBimod.left_assoc' M N right_assoc := TensorBimod.right_assoc' M N middle_assoc := TensorBimod.middle_assoc' M N /-- Left whiskering for morphisms of bimodule objects. -/ @[simps] noncomputable def whiskerLeft {X Y Z : Mon_ C} (M : Bimod X Y) {N₁ N₂ : Bimod Y Z} (f : N₁ ⟶ N₂) : M.tensorBimod N₁ ⟶ M.tensorBimod N₂ where hom := colimMap (parallelPairHom _ _ _ _ (_ ◁ f.hom) (_ ◁ f.hom) (by rw [whisker_exchange]) (by simp only [Category.assoc, tensor_whiskerLeft, Iso.inv_hom_id_assoc, Iso.cancel_iso_hom_left] slice_lhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.left_act_hom] simp)) left_act_hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one, MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_rhs 1 2 => rw [associator_inv_naturality_right] slice_rhs 2 3 => rw [whisker_exchange] simp right_act_hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.right_act_hom] slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight] slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight] simp /-- Right whiskering for morphisms of bimodule objects. -/ @[simps] noncomputable def whiskerRight {X Y Z : Mon_ C} {M₁ M₂ : Bimod X Y} (f : M₁ ⟶ M₂) (N : Bimod Y Z) : M₁.tensorBimod N ⟶ M₂.tensorBimod N where hom := colimMap (parallelPairHom _ _ _ _ (f.hom ▷ _ ▷ _) (f.hom ▷ _) (by rw [← comp_whiskerRight, Hom.right_act_hom, comp_whiskerRight]) (by slice_lhs 2 3 => rw [whisker_exchange] simp)) left_act_hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [← comp_whiskerRight, Hom.left_act_hom] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one, MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_rhs 1 2 => rw [associator_inv_naturality_middle] simp right_act_hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [whisker_exchange] slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight] slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight] simp end namespace AssociatorBimod variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] variable {R S T U : Mon_ C} (P : Bimod R S) (Q : Bimod S T) (L : Bimod T U) /-- An auxiliary morphism for the definition of the underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def homAux : (P.tensorBimod Q).X ⊗ L.X ⟶ (P.tensorBimod (Q.tensorBimod L)).X := (PreservesCoequalizer.iso (tensorRight L.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).hom ≫ (P.X ◁ coequalizer.π _ _) ≫ coequalizer.π _ _) (by dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 4 => rw [coequalizer.condition] slice_lhs 2 3 => rw [associator_naturality_right] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp] simp) /-- The underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def hom : ((P.tensorBimod Q).tensorBimod L).X ⟶ (P.tensorBimod (Q.tensorBimod L)).X := coequalizer.desc (homAux P Q L) (by dsimp [homAux] refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [TensorBimod.X] slice_lhs 1 2 => rw [← comp_whiskerRight, TensorBimod.π_tensor_id_actRight, comp_whiskerRight, comp_whiskerRight] slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 2 3 => rw [associator_naturality_middle] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.condition, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 1 2 => rw [associator_naturality_left] slice_rhs 2 3 => rw [← whisker_exchange] slice_rhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] simp) theorem hom_left_act_hom' : ((P.tensorBimod Q).tensorBimod L).actLeft ≫ hom P Q L = (R.X ◁ hom P Q L) ≫ (P.tensorBimod (Q.tensorBimod L)).actLeft := by dsimp; dsimp [hom, homAux] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ rw [tensorLeft_map] slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc, MonoidalCategory.whiskerLeft_comp] refine (cancel_epi ((tensorRight _ ⋙ tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_inv_naturality_middle] slice_lhs 2 3 => rw [← comp_whiskerRight, TensorBimod.whiskerLeft_π_actLeft, comp_whiskerRight, comp_whiskerRight] slice_lhs 4 6 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [associator_naturality_left] slice_rhs 1 3 => rw [← MonoidalCategory.whiskerLeft_comp, ← MonoidalCategory.whiskerLeft_comp, π_tensor_id_preserves_coequalizer_inv_desc, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 3 4 => erw [TensorBimod.whiskerLeft_π_actLeft P (Q.tensorBimod L)] slice_rhs 2 3 => erw [associator_inv_naturality_right] slice_rhs 3 4 => erw [whisker_exchange] coherence theorem hom_right_act_hom' : ((P.tensorBimod Q).tensorBimod L).actRight ≫ hom P Q L = (hom P Q L ▷ U.X) ≫ (P.tensorBimod (Q.tensorBimod L)).actRight := by dsimp; dsimp [hom, homAux] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc, comp_whiskerRight] refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 2 3 => rw [associator_naturality_right] slice_rhs 1 3 => rw [← comp_whiskerRight, ← comp_whiskerRight, π_tensor_id_preserves_coequalizer_inv_desc, comp_whiskerRight, comp_whiskerRight] slice_rhs 3 4 => erw [TensorBimod.π_tensor_id_actRight P (Q.tensorBimod L)] slice_rhs 2 3 => erw [associator_naturality_middle] dsimp slice_rhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.π_tensor_id_actRight, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] coherence /-- An auxiliary morphism for the definition of the underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def invAux : P.X ⊗ (Q.tensorBimod L).X ⟶ ((P.tensorBimod Q).tensorBimod L).X := (PreservesCoequalizer.iso (tensorLeft P.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).inv ≫ (coequalizer.π _ _ ▷ L.X) ≫ coequalizer.π _ _) (by dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_inv_naturality_middle] rw [← Iso.inv_hom_id_assoc (α_ _ _ _) (P.X ◁ Q.actRight), comp_whiskerRight] slice_lhs 3 4 => rw [← comp_whiskerRight, Category.assoc, ← TensorBimod.π_tensor_id_actRight, comp_whiskerRight] slice_lhs 4 5 => rw [coequalizer.condition] slice_lhs 3 4 => rw [associator_naturality_left] slice_rhs 1 2 => rw [MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [associator_inv_naturality_right] slice_rhs 3 4 => rw [whisker_exchange] coherence) /-- The underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def inv : (P.tensorBimod (Q.tensorBimod L)).X ⟶ ((P.tensorBimod Q).tensorBimod L).X := coequalizer.desc (invAux P Q L) (by dsimp [invAux] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [TensorBimod.X] slice_lhs 1 2 => rw [whisker_exchange] slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, coequalizer.condition, comp_whiskerRight, comp_whiskerRight] slice_rhs 1 2 => rw [associator_naturality_right] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 6 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_rhs 3 4 => rw [associator_inv_naturality_middle] coherence) theorem hom_inv_id : hom P Q L ≫ inv P Q L = 𝟙 _ := by dsimp [hom, homAux, inv, invAux] apply coequalizer.hom_ext slice_lhs 1 2 => rw [coequalizer.π_desc] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_lhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 1 3 => rw [Iso.hom_inv_id_assoc] dsimp only [TensorBimod.X] slice_rhs 2 3 => rw [Category.comp_id] rfl theorem inv_hom_id : inv P Q L ≫ hom P Q L = 𝟙 _ := by dsimp [hom, homAux, inv, invAux] apply coequalizer.hom_ext slice_lhs 1 2 => rw [coequalizer.π_desc] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ rw [tensorLeft_map] slice_lhs 1 3 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_lhs 2 4 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 1 3 => rw [Iso.inv_hom_id_assoc] dsimp only [TensorBimod.X] slice_rhs 2 3 => rw [Category.comp_id] rfl end AssociatorBimod namespace LeftUnitorBimod variable {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the left unitor isomorphism. -/ noncomputable def hom : TensorBimod.X (regular R) P ⟶ P.X := coequalizer.desc P.actLeft (by dsimp; rw [Category.assoc, left_assoc]) /-- The underlying morphism of the inverse component of the left unitor isomorphism. -/ noncomputable def inv : P.X ⟶ TensorBimod.X (regular R) P := (λ_ P.X).inv ≫ (R.one ▷ _) ≫ coequalizer.π _ _ theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by dsimp only [hom, inv, TensorBimod.X] ext; dsimp slice_lhs 1 2 => rw [coequalizer.π_desc] slice_lhs 1 2 => rw [leftUnitor_inv_naturality] slice_lhs 2 3 => rw [whisker_exchange] slice_lhs 3 3 => rw [← Iso.inv_hom_id_assoc (α_ R.X R.X P.X) (R.X ◁ P.actLeft)] slice_lhs 4 6 => rw [← Category.assoc, ← coequalizer.condition] slice_lhs 2 3 => rw [associator_inv_naturality_left] slice_lhs 3 4 => rw [← comp_whiskerRight, Mon_.one_mul] slice_rhs 1 2 => rw [Category.comp_id] coherence theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by dsimp [hom, inv] slice_lhs 3 4 => rw [coequalizer.π_desc] rw [one_actLeft, Iso.inv_hom_id] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem hom_left_act_hom' : ((regular R).tensorBimod P).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by dsimp; dsimp [hom, TensorBimod.actLeft, regular] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc] slice_lhs 2 3 => rw [left_assoc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc] rw [Iso.inv_hom_id_assoc] theorem hom_right_act_hom' : ((regular R).tensorBimod P).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by dsimp; dsimp [hom, TensorBimod.actRight, regular] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc] slice_rhs 1 2 => rw [middle_assoc] simp only [Category.assoc] end LeftUnitorBimod namespace RightUnitorBimod variable {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the right unitor isomorphism. -/ noncomputable def hom : TensorBimod.X P (regular S) ⟶ P.X := coequalizer.desc P.actRight (by dsimp; rw [Category.assoc, right_assoc, Iso.hom_inv_id_assoc]) /-- The underlying morphism of the inverse component of the right unitor isomorphism. -/ noncomputable def inv : P.X ⟶ TensorBimod.X P (regular S) := (ρ_ P.X).inv ≫ (_ ◁ S.one) ≫ coequalizer.π _ _ theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by dsimp only [hom, inv, TensorBimod.X] ext; dsimp slice_lhs 1 2 => rw [coequalizer.π_desc] slice_lhs 1 2 => rw [rightUnitor_inv_naturality] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 4 => rw [coequalizer.condition] slice_lhs 2 3 => rw [associator_naturality_right] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, Mon_.mul_one] slice_rhs 1 2 => rw [Category.comp_id] coherence theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by dsimp [hom, inv] slice_lhs 3 4 => rw [coequalizer.π_desc] rw [actRight_one, Iso.inv_hom_id] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem hom_left_act_hom' : (P.tensorBimod (regular S)).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by dsimp; dsimp [hom, TensorBimod.actLeft, regular] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc] slice_lhs 2 3 => rw [middle_assoc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc] rw [Iso.inv_hom_id_assoc] theorem hom_right_act_hom' : (P.tensorBimod (regular S)).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by dsimp; dsimp [hom, TensorBimod.actRight, regular] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc] slice_lhs 2 3 => rw [right_assoc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc] rw [Iso.hom_inv_id_assoc] end RightUnitorBimod variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] /-- The associator as a bimodule isomorphism. -/ noncomputable def associatorBimod {W X Y Z : Mon_ C} (L : Bimod W X) (M : Bimod X Y) (N : Bimod Y Z) : (L.tensorBimod M).tensorBimod N ≅ L.tensorBimod (M.tensorBimod N) := isoOfIso { hom := AssociatorBimod.hom L M N inv := AssociatorBimod.inv L M N hom_inv_id := AssociatorBimod.hom_inv_id L M N inv_hom_id := AssociatorBimod.inv_hom_id L M N } (AssociatorBimod.hom_left_act_hom' L M N) (AssociatorBimod.hom_right_act_hom' L M N) /-- The left unitor as a bimodule isomorphism. -/ noncomputable def leftUnitorBimod {X Y : Mon_ C} (M : Bimod X Y) : (regular X).tensorBimod M ≅ M := isoOfIso { hom := LeftUnitorBimod.hom M inv := LeftUnitorBimod.inv M hom_inv_id := LeftUnitorBimod.hom_inv_id M inv_hom_id := LeftUnitorBimod.inv_hom_id M } (LeftUnitorBimod.hom_left_act_hom' M) (LeftUnitorBimod.hom_right_act_hom' M) /-- The right unitor as a bimodule isomorphism. -/ noncomputable def rightUnitorBimod {X Y : Mon_ C} (M : Bimod X Y) : M.tensorBimod (regular Y) ≅ M := isoOfIso { hom := RightUnitorBimod.hom M inv := RightUnitorBimod.inv M hom_inv_id := RightUnitorBimod.hom_inv_id M inv_hom_id := RightUnitorBimod.inv_hom_id M } (RightUnitorBimod.hom_left_act_hom' M) (RightUnitorBimod.hom_right_act_hom' M) theorem whiskerLeft_id_bimod {X Y Z : Mon_ C} {M : Bimod X Y} {N : Bimod Y Z} : whiskerLeft M (𝟙 N) = 𝟙 (M.tensorBimod N) := by ext apply Limits.coequalizer.hom_ext dsimp only [tensorBimod_X, whiskerLeft_hom, id_hom'] simp only [MonoidalCategory.whiskerLeft_id, ι_colimMap, parallelPair_obj_one, parallelPairHom_app_one, Category.id_comp] erw [Category.comp_id] theorem id_whiskerRight_bimod {X Y Z : Mon_ C} {M : Bimod X Y} {N : Bimod Y Z} : whiskerRight (𝟙 M) N = 𝟙 (M.tensorBimod N) := by ext apply Limits.coequalizer.hom_ext dsimp only [tensorBimod_X, whiskerRight_hom, id_hom'] simp only [MonoidalCategory.id_whiskerRight, ι_colimMap, parallelPair_obj_one, parallelPairHom_app_one, Category.id_comp] erw [Category.comp_id] theorem whiskerLeft_comp_bimod {X Y Z : Mon_ C} (M : Bimod X Y) {N P Q : Bimod Y Z} (f : N ⟶ P) (g : P ⟶ Q) : whiskerLeft M (f ≫ g) = whiskerLeft M f ≫ whiskerLeft M g := by ext apply Limits.coequalizer.hom_ext simp theorem id_whiskerLeft_bimod {X Y : Mon_ C} {M N : Bimod X Y} (f : M ⟶ N) : whiskerLeft (regular X) f = (leftUnitorBimod M).hom ≫ f ≫ (leftUnitorBimod N).inv := by dsimp [tensorHom, regular, leftUnitorBimod] ext apply coequalizer.hom_ext dsimp slice_lhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] dsimp [LeftUnitorBimod.hom] slice_rhs 1 2 => rw [coequalizer.π_desc] dsimp [LeftUnitorBimod.inv] slice_rhs 1 2 => rw [Hom.left_act_hom] slice_rhs 2 3 => rw [leftUnitor_inv_naturality] slice_rhs 3 4 => rw [whisker_exchange] slice_rhs 4 4 => rw [← Iso.inv_hom_id_assoc (α_ X.X X.X N.X) (X.X ◁ N.actLeft)] slice_rhs 5 7 => rw [← Category.assoc, ← coequalizer.condition] slice_rhs 3 4 => rw [associator_inv_naturality_left] slice_rhs 4 5 => rw [← comp_whiskerRight, Mon_.one_mul] have : (λ_ (X.X ⊗ N.X)).inv ≫ (α_ (𝟙_ C) X.X N.X).inv ≫ ((λ_ X.X).hom ▷ N.X) = 𝟙 _ := by coherence slice_rhs 2 4 => rw [this] slice_rhs 1 2 => rw [Category.comp_id] theorem comp_whiskerLeft_bimod {W X Y Z : Mon_ C} (M : Bimod W X) (N : Bimod X Y) {P P' : Bimod Y Z} (f : P ⟶ P') : whiskerLeft (M.tensorBimod N) f = (associatorBimod M N P).hom ≫ whiskerLeft M (whiskerLeft N f) ≫ (associatorBimod M N P').inv := by dsimp [tensorHom, tensorBimod, associatorBimod] ext apply coequalizer.hom_ext dsimp slice_lhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] dsimp [TensorBimod.X, AssociatorBimod.hom] slice_rhs 1 2 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.homAux, AssociatorBimod.inv] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_rhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_rhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one] slice_rhs 3 4 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.invAux] slice_rhs 2 2 => rw [MonoidalCategory.whiskerLeft_comp] slice_rhs 3 5 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_rhs 2 3 => rw [associator_inv_naturality_right] slice_rhs 1 3 => rw [Iso.hom_inv_id_assoc] slice_lhs 1 2 => rw [← whisker_exchange] rfl theorem comp_whiskerRight_bimod {X Y Z : Mon_ C} {M N P : Bimod X Y} (f : M ⟶ N) (g : N ⟶ P) (Q : Bimod Y Z) : whiskerRight (f ≫ g) Q = whiskerRight f Q ≫ whiskerRight g Q := by ext apply Limits.coequalizer.hom_ext simp theorem whiskerRight_id_bimod {X Y : Mon_ C} {M N : Bimod X Y} (f : M ⟶ N) : whiskerRight f (regular Y) = (rightUnitorBimod M).hom ≫ f ≫ (rightUnitorBimod N).inv := by dsimp [tensorHom, regular, rightUnitorBimod] ext apply coequalizer.hom_ext dsimp slice_lhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] dsimp [RightUnitorBimod.hom] slice_rhs 1 2 => rw [coequalizer.π_desc] dsimp [RightUnitorBimod.inv] slice_rhs 1 2 => rw [Hom.right_act_hom] slice_rhs 2 3 => rw [rightUnitor_inv_naturality] slice_rhs 3 4 => rw [← whisker_exchange] slice_rhs 4 5 => rw [coequalizer.condition] slice_rhs 3 4 => rw [associator_naturality_right] slice_rhs 4 5 => rw [← MonoidalCategory.whiskerLeft_comp, Mon_.mul_one] simp theorem whiskerRight_comp_bimod {W X Y Z : Mon_ C} {M M' : Bimod W X} (f : M ⟶ M') (N : Bimod X Y) (P : Bimod Y Z) : whiskerRight f (N.tensorBimod P) = (associatorBimod M N P).inv ≫ whiskerRight (whiskerRight f N) P ≫ (associatorBimod M' N P).hom := by dsimp [tensorHom, tensorBimod, associatorBimod] ext apply coequalizer.hom_ext dsimp slice_lhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] dsimp [TensorBimod.X, AssociatorBimod.inv] slice_rhs 1 2 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.invAux, AssociatorBimod.hom] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ rw [tensorLeft_map] slice_rhs 1 3 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_rhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_rhs 2 3 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one] slice_rhs 3 4 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.homAux] slice_rhs 2 2 => rw [comp_whiskerRight] slice_rhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_rhs 2 3 => rw [associator_naturality_left] slice_rhs 1 3 => rw [Iso.inv_hom_id_assoc] slice_lhs 1 2 => rw [whisker_exchange] rfl theorem whisker_assoc_bimod {W X Y Z : Mon_ C} (M : Bimod W X) {N N' : Bimod X Y} (f : N ⟶ N') (P : Bimod Y Z) : whiskerRight (whiskerLeft M f) P = (associatorBimod M N P).hom ≫ whiskerLeft M (whiskerRight f P) ≫ (associatorBimod M N' P).inv := by dsimp [tensorHom, tensorBimod, associatorBimod] ext apply coequalizer.hom_ext dsimp slice_lhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] dsimp [AssociatorBimod.hom] slice_rhs 1 2 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.homAux] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_lhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one] slice_rhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_rhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one] dsimp [AssociatorBimod.inv] slice_rhs 3 4 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.invAux] slice_rhs 2 2 => rw [MonoidalCategory.whiskerLeft_comp] slice_rhs 3 5 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_rhs 2 3 => rw [associator_inv_naturality_middle] slice_rhs 1 3 => rw [Iso.hom_inv_id_assoc] slice_lhs 1 1 => rw [comp_whiskerRight] theorem whisker_exchange_bimod {X Y Z : Mon_ C} {M N : Bimod X Y} {P Q : Bimod Y Z} (f : M ⟶ N) (g : P ⟶ Q) : whiskerLeft M g ≫ whiskerRight f Q = whiskerRight f P ≫ whiskerLeft N g := by ext apply coequalizer.hom_ext dsimp slice_lhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 1 2 => rw [whisker_exchange] slice_rhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] slice_rhs 2 3 => rw [ι_colimMap, parallelPairHom_app_one] simp only [Category.assoc] theorem pentagon_bimod {V W X Y Z : Mon_ C} (M : Bimod V W) (N : Bimod W X) (P : Bimod X Y) (Q : Bimod Y Z) : whiskerRight (associatorBimod M N P).hom Q ≫ (associatorBimod M (N.tensorBimod P) Q).hom ≫ whiskerLeft M (associatorBimod N P Q).hom = (associatorBimod (M.tensorBimod N) P Q).hom ≫ (associatorBimod M N (P.tensorBimod Q)).hom := by dsimp [associatorBimod] ext apply coequalizer.hom_ext dsimp dsimp only [AssociatorBimod.hom] slice_lhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [coequalizer.π_desc] slice_rhs 1 2 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.homAux] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc] slice_rhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_rhs 3 4 => rw [coequalizer.π_desc] refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [← comp_whiskerRight, π_tensor_id_preserves_coequalizer_inv_desc, comp_whiskerRight, comp_whiskerRight] slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] dsimp only [TensorBimod.X] slice_lhs 2 3 => rw [associator_naturality_middle] slice_lhs 5 6 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 4 5 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, π_tensor_id_preserves_coequalizer_inv_desc, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 1 2 => rw [associator_naturality_left] slice_rhs 2 3 => rw [← whisker_exchange] slice_rhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_rhs 2 3 => rw [associator_naturality_right] coherence theorem triangle_bimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : (associatorBimod M (regular Y) N).hom ≫ whiskerLeft M (leftUnitorBimod N).hom = whiskerRight (rightUnitorBimod M).hom N := by dsimp [associatorBimod, leftUnitorBimod, rightUnitorBimod] ext apply coequalizer.hom_ext dsimp dsimp [AssociatorBimod.hom] slice_lhs 1 2 => rw [coequalizer.π_desc] dsimp [AssociatorBimod.homAux] slice_rhs 1 2 => rw [ι_colimMap, parallelPairHom_app_one] dsimp [RightUnitorBimod.hom] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [regular] slice_lhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] dsimp [LeftUnitorBimod.hom] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc] slice_rhs 1 2 => rw [coequalizer.condition] simp only [Category.assoc] /-- The bicategory of algebras (monoids) and bimodules, all internal to some monoidal category. -/ noncomputable def monBicategory : Bicategory (Mon_ C) where Hom X Y := Bimod X Y homCategory X Y := (inferInstance : Category (Bimod X Y)) id X := regular X comp M N := tensorBimod M N whiskerLeft L _ _ f := whiskerLeft L f whiskerRight f N := whiskerRight f N associator := associatorBimod leftUnitor := leftUnitorBimod rightUnitor := rightUnitorBimod whiskerLeft_id _ _ := whiskerLeft_id_bimod whiskerLeft_comp M _ _ _ f g := whiskerLeft_comp_bimod M f g id_whiskerLeft := id_whiskerLeft_bimod comp_whiskerLeft M N _ _ f := comp_whiskerLeft_bimod M N f id_whiskerRight _ _ := id_whiskerRight_bimod comp_whiskerRight f g Q := comp_whiskerRight_bimod f g Q whiskerRight_id := whiskerRight_id_bimod whiskerRight_comp := whiskerRight_comp_bimod whisker_assoc M _ _ f P := whisker_assoc_bimod M f P whisker_exchange := whisker_exchange_bimod pentagon := pentagon_bimod triangle := triangle_bimod end Bimod
CategoryTheory\Monoidal\Bimon_.lean
/- Copyright (c) 2024 Lean FRO LLC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Monoidal.Comon_ /-! # The category of bimonoids in a braided monoidal category. We define bimonoids in a braided monoidal category `C` as comonoid objects in the category of monoid objects in `C`. We verify that this is equivalent to the monoid objects in the category of comonoid objects. ## TODO * Define Hopf monoids, which in a cartesian monoidal category are exactly group objects, and use this to define group schemes. * Construct the category of modules, and show that it is monoidal with a monoidal forgetful functor to `C`. * Some form of Tannaka reconstruction: given a monoidal functor `F : C ⥤ D` into a braided category `D`, the internal endomorphisms of `F` form a bimonoid in presheaves on `D`, in good circumstances this is representable by a bimonoid in `D`, and then `C` is monoidally equivalent to the modules over that bimonoid. -/ noncomputable section universe v₁ v₂ u₁ u₂ u open CategoryTheory MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] [BraidedCategory C] /-- A bimonoid object in a braided category `C` is a comonoid object in the (monoidal) category of monoid objects in `C`. -/ def Bimon_ := Comon_ (Mon_ C) namespace Bimon_ instance : Category (Bimon_ C) := inferInstanceAs (Category (Comon_ (Mon_ C))) @[ext] lemma ext {X Y : Bimon_ C} {f g : X ⟶ Y} (w : f.hom.hom = g.hom.hom) : f = g := Comon_.Hom.ext (Mon_.Hom.ext w) @[simp] theorem id_hom' (M : Bimon_ C) : Comon_.Hom.hom (𝟙 M) = 𝟙 M.X := rfl @[simp] theorem comp_hom' {M N K : Bimon_ C} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g).hom = f.hom ≫ g.hom := rfl /-- The forgetful functor from bimonoid objects to monoid objects. -/ abbrev toMon_ : Bimon_ C ⥤ Mon_ C := Comon_.forget (Mon_ C) /-- The forgetful functor from bimonoid objects to the underlying category. -/ def forget : Bimon_ C ⥤ C := toMon_ C ⋙ Mon_.forget C @[simp] theorem toMon_forget : toMon_ C ⋙ Mon_.forget C = forget C := rfl /-- The forgetful functor from bimonoid objects to comonoid objects. -/ @[simps!] def toComon_ : Bimon_ C ⥤ Comon_ C := (Mon_.forgetMonoidal C).toOplaxMonoidalFunctor.mapComon @[simp] theorem toComon_forget : toComon_ C ⋙ Comon_.forget C = forget C := rfl set_option maxHeartbeats 400000 in /-- The object level part of the forward direction of `Comon_ (Mon_ C) ≌ Mon_ (Comon_ C)` -/ def toMon_Comon_obj (M : Bimon_ C) : Mon_ (Comon_ C) where X := (toComon_ C).obj M one := { hom := M.X.one } mul := { hom := M.X.mul, hom_comul := by dsimp; simp [tensor_μ] } attribute [simps] toMon_Comon_obj -- We add this after the fact to avoid a timeout. /-- The forward direction of `Comon_ (Mon_ C) ≌ Mon_ (Comon_ C)` -/ @[simps] def toMon_Comon_ : Bimon_ C ⥤ Mon_ (Comon_ C) where obj := toMon_Comon_obj C map f := { hom := (toComon_ C).map f } /-- The object level part of the backward direction of `Comon_ (Mon_ C) ≌ Mon_ (Comon_ C)` -/ @[simps] def ofMon_Comon_obj (M : Mon_ (Comon_ C)) : Bimon_ C where X := (Comon_.forgetMonoidal C).toLaxMonoidalFunctor.mapMon.obj M counit := { hom := M.X.counit } comul := { hom := M.X.comul, mul_hom := by dsimp; simp [tensor_μ] } /-- The backward direction of `Comon_ (Mon_ C) ≌ Mon_ (Comon_ C)` -/ @[simps] def ofMon_Comon_ : Mon_ (Comon_ C) ⥤ Bimon_ C where obj := ofMon_Comon_obj C map f := { hom := (Comon_.forgetMonoidal C).toLaxMonoidalFunctor.mapMon.map f } /-- The equivalence `Comon_ (Mon_ C) ≌ Mon_ (Comon_ C)` -/ def equivMon_Comon_ : Bimon_ C ≌ Mon_ (Comon_ C) where functor := toMon_Comon_ C inverse := ofMon_Comon_ C unitIso := NatIso.ofComponents (fun _ => Comon_.mkIso (Mon_.mkIso (Iso.refl _))) counitIso := NatIso.ofComponents (fun _ => Mon_.mkIso (Comon_.mkIso (Iso.refl _))) end Bimon_
CategoryTheory\Monoidal\Category.lean
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C → C → C` * `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`, * `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for 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 morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`, where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`. Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C → C → C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ /-- right whiskering for morphisms -/ whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) := whiskerRight f X₂ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `𝟙_ C` -/ tensorUnit : C /-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) /-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/ leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X /-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/ rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/ scoped notation "𝟙_ " C:max => (MonoidalCategoryStruct.tensorUnit : C) open Lean PrettyPrinter.Delaborator SubExpr in /-- Used to ensure that `𝟙_` notation is used, as the ascription makes this not automatic. -/ @[delab app.CategoryTheory.MonoidalCategoryStruct.tensorUnit] def delabTensorUnit : Delab := whenPPOption getPPNotation <| withOverApp 3 do let e ← getExpr guard <| e.isAppOfArity ``MonoidalCategoryStruct.tensorUnit 3 let C ← withNaryArg 0 delab `(𝟙_ $C) /-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ scoped notation "α_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/ scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. See <https://stacks.math.columbia.edu/tag/0FFK>. -/ -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat /-- Composition of tensor products is tensor product of compositions: `(f₁ ⊗ g₁) ∘ (f₂ ⊗ g₂) = (f₁ ∘ f₂) ⊗ (g₁ ⊗ g₂)` -/ tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by aesop_cat whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by aesop_cat id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/ associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y` -/ leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y` -/ rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W` -/ pentagon : ∀ W X Y Z : C, (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y` -/ triangle : ∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by aesop_cat attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : f ⊗ 𝟙 Y = f ▷ Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) : 𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) : (f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) : f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ := whisker_exchange f g ▸ tensorHom_def f g @[reassoc] lemma whiskerLeft_whiskerLeft_associator_inv (X Y : C) {Z₁ Z₂ : C} (f : Z₁ ⟶ Z₂) : X ◁ Y ◁ f ≫ (α_ _ _ _).inv = (α_ _ _ _).inv ≫ _ ◁ f := by simp end MonoidalCategory open scoped MonoidalCategory open MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] namespace MonoidalCategory @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) : whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where hom := f.hom ▷ Z inv := f.inv ▷ Z instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : inv (f ▷ Z) = inv f ▷ Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) : whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl end MonoidalCategory /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {C : Type u} {X Y X' Y' : C} [Category.{v} C] [MonoidalCategory.{v} C] (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where hom := f.hom ⊗ g.hom inv := f.inv ⊗ g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ infixr:70 " ⊗ " => tensorIso namespace MonoidalCategory section variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) := (asIso f ⊗ asIso g).isIso_hom @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : inv (f ⊗ g) = inv f ⊗ inv g := by simp [tensorHom_def ,whisker_exchange] variable {U V W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C) : (if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc] theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp @[reassoc] theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp @[reassoc] theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp @[reassoc] theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp @[reassoc] theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by simp @[reassoc] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') : f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) : f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv : (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom = W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv := by rw [← cancel_epi (W ◁ (α_ X Y Z).inv), ← cancel_mono (α_ (W ⊗ X) Y Z).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv : (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom = (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv : W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv = (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z := by simp [← cancel_epi (W ◁ (α_ X Y Z).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom : (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv = (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom : (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv = (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z := by rw [← cancel_epi (α_ W X (Y ⊗ Z)).inv, ← cancel_mono ((α_ W X Y).inv ▷ Z)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom : (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv = (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom : (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom = (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom := by simp [← cancel_epi ((α_ W X Y).hom ▷ Z)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv : (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z = W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (X Y : C) : (α_ X (𝟙_ C) Y).inv ≫ ((ρ_ X).hom ▷ Y) = X ◁ (λ_ Y).hom := by rw [← triangle, Iso.inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (X Y : C) : (ρ_ X).inv ▷ Y ≫ (α_ X (𝟙_ C) Y).hom = X ◁ (λ_ Y).inv := by simp [← cancel_mono (X ◁ (λ_ Y).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (X Y : C) : (X ◁ (λ_ Y).inv) ≫ (α_ X (𝟙_ C) Y).inv = (ρ_ X).inv ▷ Y := by simp [← cancel_mono ((ρ_ X).hom ▷ Y)] /-- We state it as a simp lemma, which is regarded as an involved version of `id_whiskerRight X Y : 𝟙 X ▷ Y = 𝟙 (X ⊗ Y)`. -/ @[reassoc, simp] theorem leftUnitor_whiskerRight (X Y : C) : (λ_ X).hom ▷ Y = (α_ (𝟙_ C) X Y).hom ≫ (λ_ (X ⊗ Y)).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 (X Y : C) : (λ_ X).inv ▷ Y = (λ_ (X ⊗ Y)).inv ≫ (α_ (𝟙_ C) X Y).inv := eq_of_inv_eq_inv (by simp) @[reassoc, simp] theorem whiskerLeft_rightUnitor (X Y : C) : X ◁ (ρ_ Y).hom = (α_ X Y (𝟙_ C)).inv ≫ (ρ_ (X ⊗ Y)).hom := by rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ← cancel_epi (X ◁ (α_ _ _ _).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 (X Y : C) : X ◁ (ρ_ Y).inv = (ρ_ (X ⊗ Y)).inv ≫ (α_ X Y (𝟙_ C)).hom := eq_of_inv_eq_inv (by simp) @[reassoc] theorem leftUnitor_tensor (X Y : C) : (λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ (λ_ X).hom ▷ Y := by simp @[reassoc] theorem leftUnitor_tensor_inv (X Y : C) : (λ_ (X ⊗ Y)).inv = (λ_ X).inv ▷ Y ≫ (α_ (𝟙_ C) X Y).hom := by simp @[reassoc] theorem rightUnitor_tensor (X Y : C) : (ρ_ (X ⊗ Y)).hom = (α_ X Y (𝟙_ C)).hom ≫ X ◁ (ρ_ Y).hom := by simp @[reassoc] theorem rightUnitor_tensor_inv (X Y : C) : (ρ_ (X ⊗ Y)).inv = X ◁ (ρ_ Y).inv ≫ (α_ X Y (𝟙_ C)).inv := by simp end @[reassoc] theorem associator_inv_naturality {X Y Z X' Y' Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) := by simp [tensorHom_def] @[reassoc, simp] theorem associator_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g) ⊗ h = (α_ X Y Z).hom ≫ (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv := by rw [associator_inv_naturality, hom_inv_id_assoc] @[reassoc] theorem associator_inv_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : f ⊗ g ⊗ h = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) ≫ (α_ X' Y' Z').hom := by rw [associator_naturality, inv_hom_id_assoc] -- TODO these next two lemmas aren't so fundamental, and perhaps could be removed -- (replacing their usages by their proofs). @[reassoc] theorem id_tensor_associator_naturality {X Y Z Z' : C} (h : Z ⟶ Z') : (𝟙 (X ⊗ Y) ⊗ h) ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ (𝟙 X ⊗ 𝟙 Y ⊗ h) := by rw [← tensor_id, associator_naturality] @[reassoc] theorem id_tensor_associator_inv_naturality {X Y Z X' : C} (f : X ⟶ X') : (f ⊗ 𝟙 (Y ⊗ Z)) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ ((f ⊗ 𝟙 Y) ⊗ 𝟙 Z) := by rw [← tensor_id, associator_inv_naturality] @[reassoc (attr := simp)] theorem hom_inv_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (f.hom ⊗ g) ≫ (f.inv ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by rw [← tensor_comp, f.hom_inv_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem inv_hom_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (f.inv ⊗ g) ≫ (f.hom ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by rw [← tensor_comp, f.inv_hom_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem tensor_hom_inv_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f.hom) ≫ (h ⊗ f.inv) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by rw [← tensor_comp, f.hom_inv_id]; simp [tensorHom_id] @[reassoc (attr := simp)] theorem tensor_inv_hom_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f.inv) ≫ (h ⊗ f.hom) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by rw [← tensor_comp, f.inv_hom_id]; simp [tensorHom_id] @[reassoc (attr := simp)] theorem hom_inv_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (f ⊗ g) ≫ (inv f ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by rw [← tensor_comp, IsIso.hom_inv_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem inv_hom_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (inv f ⊗ g) ≫ (f ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by rw [← tensor_comp, IsIso.inv_hom_id]; simp [id_tensorHom] @[reassoc (attr := simp)] theorem tensor_hom_inv_id' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f) ≫ (h ⊗ inv f) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by rw [← tensor_comp, IsIso.hom_inv_id]; simp [tensorHom_id] @[reassoc (attr := simp)] theorem tensor_inv_hom_id' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ inv f) ≫ (h ⊗ f) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by rw [← tensor_comp, IsIso.inv_hom_id]; simp [tensorHom_id] /-- A constructor for monoidal categories that requires `tensorHom` instead of `whiskerLeft` and `whiskerRight`. -/ abbrev ofTensorHom [MonoidalCategoryStruct C] (tensor_id : ∀ X₁ X₂ : C, tensorHom (𝟙 X₁) (𝟙 X₂) = 𝟙 (tensorObj X₁ X₂) := by aesop_cat) (id_tensorHom : ∀ (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂), tensorHom (𝟙 X) f = whiskerLeft X f := by aesop_cat) (tensorHom_id : ∀ {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C), tensorHom f (𝟙 Y) = whiskerRight f Y := by aesop_cat) (tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), tensorHom (f₁ ≫ g₁) (f₂ ≫ g₂) = tensorHom f₁ f₂ ≫ tensorHom g₁ g₂ := by aesop_cat) (associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : 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 aesop_cat) (leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), tensorHom (𝟙 tensorUnit) f ≫ (leftUnitor Y).hom = (leftUnitor X).hom ≫ f := by aesop_cat) (rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), tensorHom f (𝟙 tensorUnit) ≫ (rightUnitor Y).hom = (rightUnitor X).hom ≫ f := by aesop_cat) (pentagon : ∀ W X Y Z : 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 aesop_cat) (triangle : ∀ X Y : C, (associator X tensorUnit Y).hom ≫ tensorHom (𝟙 X) (leftUnitor Y).hom = tensorHom (rightUnitor X).hom (𝟙 Y) := by aesop_cat) : MonoidalCategory C where tensorHom_def := by intros; simp [← id_tensorHom, ← tensorHom_id, ← tensor_comp] whiskerLeft_id := by intros; simp [← id_tensorHom, ← tensor_id] id_whiskerRight := by intros; simp [← tensorHom_id, tensor_id] pentagon := by intros; simp [← id_tensorHom, ← tensorHom_id, pentagon] triangle := by intros; simp [← id_tensorHom, ← tensorHom_id, triangle] @[reassoc] theorem comp_tensor_id (f : W ⟶ X) (g : X ⟶ Y) : f ≫ g ⊗ 𝟙 Z = (f ⊗ 𝟙 Z) ≫ (g ⊗ 𝟙 Z) := by simp @[reassoc] theorem id_tensor_comp (f : W ⟶ X) (g : X ⟶ Y) : 𝟙 Z ⊗ f ≫ g = (𝟙 Z ⊗ f) ≫ (𝟙 Z ⊗ g) := by simp @[reassoc] theorem id_tensor_comp_tensor_id (f : W ⟶ X) (g : Y ⟶ Z) : (𝟙 Y ⊗ f) ≫ (g ⊗ 𝟙 X) = g ⊗ f := by rw [← tensor_comp] simp @[reassoc] theorem tensor_id_comp_id_tensor (f : W ⟶ X) (g : Y ⟶ Z) : (g ⊗ 𝟙 W) ≫ (𝟙 Z ⊗ f) = g ⊗ f := by rw [← tensor_comp] simp theorem tensor_left_iff {X Y : C} (f g : X ⟶ Y) : 𝟙 (𝟙_ C) ⊗ f = 𝟙 (𝟙_ C) ⊗ g ↔ f = g := by simp theorem tensor_right_iff {X Y : C} (f g : X ⟶ Y) : f ⊗ 𝟙 (𝟙_ C) = g ⊗ 𝟙 (𝟙_ C) ↔ f = g := by simp end section variable (C) attribute [local simp] whisker_exchange /-- The tensor product expressed as a functor. -/ @[simps] def tensor : C × C ⥤ C where obj X := X.1 ⊗ X.2 map {X Y : C × C} (f : X ⟶ Y) := f.1 ⊗ f.2 /-- The left-associated triple tensor product as a functor. -/ def leftAssocTensor : C × C × C ⥤ C where obj X := (X.1 ⊗ X.2.1) ⊗ X.2.2 map {X Y : C × C × C} (f : X ⟶ Y) := (f.1 ⊗ f.2.1) ⊗ f.2.2 @[simp] theorem leftAssocTensor_obj (X) : (leftAssocTensor C).obj X = (X.1 ⊗ X.2.1) ⊗ X.2.2 := rfl @[simp] theorem leftAssocTensor_map {X Y} (f : X ⟶ Y) : (leftAssocTensor C).map f = (f.1 ⊗ f.2.1) ⊗ f.2.2 := rfl /-- The right-associated triple tensor product as a functor. -/ def rightAssocTensor : C × C × C ⥤ C where obj X := X.1 ⊗ X.2.1 ⊗ X.2.2 map {X Y : C × C × C} (f : X ⟶ Y) := f.1 ⊗ f.2.1 ⊗ f.2.2 @[simp] theorem rightAssocTensor_obj (X) : (rightAssocTensor C).obj X = X.1 ⊗ X.2.1 ⊗ X.2.2 := rfl @[simp] theorem rightAssocTensor_map {X Y} (f : X ⟶ Y) : (rightAssocTensor C).map f = f.1 ⊗ f.2.1 ⊗ f.2.2 := rfl /-- The tensor product bifunctor `C ⥤ C ⥤ C` of a monoidal category. -/ @[simps] def curriedTensor : C ⥤ C ⥤ C where obj X := { obj := fun Y => X ⊗ Y map := fun g => X ◁ g } map f := { app := fun Y => f ▷ Y } variable {C} /-- Tensoring on the left with a fixed object, as a functor. -/ @[simps!] def tensorLeft (X : C) : C ⥤ C := (curriedTensor C).obj X /-- Tensoring on the right with a fixed object, as a functor. -/ @[simps!] def tensorRight (X : C) : C ⥤ C := (curriedTensor C).flip.obj X variable (C) /-- The functor `fun X ↦ 𝟙_ C ⊗ X`. -/ abbrev tensorUnitLeft : C ⥤ C := tensorLeft (𝟙_ C) /-- The functor `fun X ↦ X ⊗ 𝟙_ C`. -/ abbrev tensorUnitRight : C ⥤ C := tensorRight (𝟙_ C) -- We can express the associator and the unitors, given componentwise above, -- as natural isomorphisms. -- Porting Note: Had to add a `simps!` because Lean was complaining this wasn't a constructor app. /-- The associator as a natural isomorphism. -/ @[simps!] def associatorNatIso : leftAssocTensor C ≅ rightAssocTensor C := NatIso.ofComponents (fun _ => MonoidalCategory.associator _ _ _) -- Porting Note: same as above /-- The left unitor as a natural isomorphism. -/ @[simps!] def leftUnitorNatIso : tensorUnitLeft C ≅ 𝟭 C := NatIso.ofComponents MonoidalCategory.leftUnitor -- Porting Note: same as above /-- The right unitor as a natural isomorphism. -/ @[simps!] def rightUnitorNatIso : tensorUnitRight C ≅ 𝟭 C := NatIso.ofComponents MonoidalCategory.rightUnitor /-- The associator as a natural isomorphism between trifunctors `C ⥤ C ⥤ C ⥤ C`. -/ @[simps!] def curriedAssociatorNatIso : bifunctorComp₁₂ (curriedTensor C) (curriedTensor C) ≅ bifunctorComp₂₃ (curriedTensor C) (curriedTensor C) := NatIso.ofComponents (fun X₁ => NatIso.ofComponents (fun X₂ => NatIso.ofComponents (fun X₃ => α_ X₁ X₂ X₃))) section variable {C} /-- Tensoring on the left with `X ⊗ Y` is naturally isomorphic to tensoring on the left with `Y`, and then again with `X`. -/ def tensorLeftTensor (X Y : C) : tensorLeft (X ⊗ Y) ≅ tensorLeft Y ⋙ tensorLeft X := NatIso.ofComponents (associator _ _) fun {Z} {Z'} f => by simp @[simp] theorem tensorLeftTensor_hom_app (X Y Z : C) : (tensorLeftTensor X Y).hom.app Z = (associator X Y Z).hom := rfl @[simp] theorem tensorLeftTensor_inv_app (X Y Z : C) : (tensorLeftTensor X Y).inv.app Z = (associator X Y Z).inv := by simp [tensorLeftTensor] variable (C) /-- Tensoring on the left, as a functor from `C` into endofunctors of `C`. TODO: show this is an op-monoidal functor. -/ abbrev tensoringLeft : C ⥤ C ⥤ C := curriedTensor C instance : (tensoringLeft C).Faithful where map_injective {X} {Y} f g h := by injections h replace h := congr_fun h (𝟙_ C) simpa using h /-- Tensoring on the right, as a functor from `C` into endofunctors of `C`. We later show this is a monoidal functor. -/ abbrev tensoringRight : C ⥤ C ⥤ C := (curriedTensor C).flip instance : (tensoringRight C).Faithful where map_injective {X} {Y} f g h := by injections h replace h := congr_fun h (𝟙_ C) simpa using h variable {C} /-- Tensoring on the right with `X ⊗ Y` is naturally isomorphic to tensoring on the right with `X`, and then again with `Y`. -/ def tensorRightTensor (X Y : C) : tensorRight (X ⊗ Y) ≅ tensorRight X ⋙ tensorRight Y := NatIso.ofComponents (fun Z => (associator Z X Y).symm) fun {Z} {Z'} f => by simp @[simp] theorem tensorRightTensor_hom_app (X Y Z : C) : (tensorRightTensor X Y).hom.app Z = (associator Z X Y).inv := rfl @[simp] theorem tensorRightTensor_inv_app (X Y Z : C) : (tensorRightTensor X Y).inv.app Z = (associator Z X Y).hom := by simp [tensorRightTensor] end end section universe v₁ v₂ u₁ u₂ variable (C₁ : Type u₁) [Category.{v₁} C₁] [MonoidalCategory.{v₁} C₁] variable (C₂ : Type u₂) [Category.{v₂} C₂] [MonoidalCategory.{v₂} C₂] attribute [local simp] associator_naturality leftUnitor_naturality rightUnitor_naturality pentagon @[simps! tensorObj tensorHom tensorUnit whiskerLeft whiskerRight associator] instance prodMonoidal : MonoidalCategory (C₁ × C₂) where tensorObj X Y := (X.1 ⊗ Y.1, X.2 ⊗ Y.2) tensorHom f g := (f.1 ⊗ g.1, f.2 ⊗ g.2) whiskerLeft X _ _ f := (whiskerLeft X.1 f.1, whiskerLeft X.2 f.2) whiskerRight f X := (whiskerRight f.1 X.1, whiskerRight f.2 X.2) tensorHom_def := by simp [tensorHom_def] tensorUnit := (𝟙_ C₁, 𝟙_ C₂) associator X Y Z := (α_ X.1 Y.1 Z.1).prod (α_ X.2 Y.2 Z.2) leftUnitor := fun ⟨X₁, X₂⟩ => (λ_ X₁).prod (λ_ X₂) rightUnitor := fun ⟨X₁, X₂⟩ => (ρ_ X₁).prod (ρ_ X₂) @[simp] theorem prodMonoidal_leftUnitor_hom_fst (X : C₁ × C₂) : ((λ_ X).hom : 𝟙_ _ ⊗ X ⟶ X).1 = (λ_ X.1).hom := by cases X rfl @[simp] theorem prodMonoidal_leftUnitor_hom_snd (X : C₁ × C₂) : ((λ_ X).hom : 𝟙_ _ ⊗ X ⟶ X).2 = (λ_ X.2).hom := by cases X rfl @[simp] theorem prodMonoidal_leftUnitor_inv_fst (X : C₁ × C₂) : ((λ_ X).inv : X ⟶ 𝟙_ _ ⊗ X).1 = (λ_ X.1).inv := by cases X rfl @[simp] theorem prodMonoidal_leftUnitor_inv_snd (X : C₁ × C₂) : ((λ_ X).inv : X ⟶ 𝟙_ _ ⊗ X).2 = (λ_ X.2).inv := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_hom_fst (X : C₁ × C₂) : ((ρ_ X).hom : X ⊗ 𝟙_ _ ⟶ X).1 = (ρ_ X.1).hom := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_hom_snd (X : C₁ × C₂) : ((ρ_ X).hom : X ⊗ 𝟙_ _ ⟶ X).2 = (ρ_ X.2).hom := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_inv_fst (X : C₁ × C₂) : ((ρ_ X).inv : X ⟶ X ⊗ 𝟙_ _).1 = (ρ_ X.1).inv := by cases X rfl @[simp] theorem prodMonoidal_rightUnitor_inv_snd (X : C₁ × C₂) : ((ρ_ X).inv : X ⟶ X ⊗ 𝟙_ _).2 = (ρ_ X.2).inv := by cases X rfl end end MonoidalCategory end CategoryTheory
CategoryTheory\Monoidal\Center.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Functor.ReflectsIso /-! # Half braidings and the Drinfeld center of a monoidal category We define `Center C` to be pairs `⟨X, b⟩`, where `X : C` and `b` is a half-braiding on `X`. We show that `Center C` is braided monoidal, and provide the monoidal functor `Center.forget` from `Center C` back to `C`. ## Implementation notes Verifying the various axioms directly requires tedious rewriting. Using the `slice` tactic may make the proofs marginally more readable. More exciting, however, would be to make possible one of the following options: 1. Integration with homotopy.io / globular to give "picture proofs". 2. The monoidal coherence theorem, so we can ignore associators (after which most of these proofs are trivial). 3. Automating these proofs using `rewrite_search` or some relative. In this file, we take the second approach using the monoidal composition `⊗≫` and the `coherence` tactic. -/ open CategoryTheory open CategoryTheory.MonoidalCategory universe v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] /-- A half-braiding on `X : C` is a family of isomorphisms `X ⊗ U ≅ U ⊗ X`, monoidally natural in `U : C`. Thinking of `C` as a 2-category with a single `0`-morphism, these are the same as natural transformations (in the pseudo- sense) of the identity 2-functor on `C`, which send the unique `0`-morphism to `X`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. structure HalfBraiding (X : C) where β : ∀ U, X ⊗ U ≅ U ⊗ X monoidal : ∀ U U', (β (U ⊗ U')).hom = (α_ _ _ _).inv ≫ ((β U).hom ▷ U') ≫ (α_ _ _ _).hom ≫ (U ◁ (β U').hom) ≫ (α_ _ _ _).inv := by aesop_cat naturality : ∀ {U U'} (f : U ⟶ U'), (X ◁ f) ≫ (β U').hom = (β U).hom ≫ (f ▷ X) := by aesop_cat attribute [reassoc, simp] HalfBraiding.monoidal -- the reassoc lemma is redundant as a simp lemma attribute [simp, reassoc] HalfBraiding.naturality variable (C) /-- The Drinfeld center of a monoidal category `C` has as objects pairs `⟨X, b⟩`, where `X : C` and `b` is a half-braiding on `X`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. def Center := Σ X : C, HalfBraiding X namespace Center variable {C} /-- A morphism in the Drinfeld center of `C`. -/ -- Porting note(#5171): linter not ported yet @[ext] -- @[nolint has_nonempty_instance] structure Hom (X Y : Center C) where f : X.1 ⟶ Y.1 comm : ∀ U, (f ▷ U) ≫ (Y.2.β U).hom = (X.2.β U).hom ≫ (U ◁ f) := by aesop_cat attribute [reassoc (attr := simp)] Hom.comm instance : Quiver (Center C) where Hom := Hom @[ext] theorem ext {X Y : Center C} (f g : X ⟶ Y) (w : f.f = g.f) : f = g := by cases f; cases g; congr instance : Category (Center C) where id X := { f := 𝟙 X.1 } comp f g := { f := f.f ≫ g.f } @[simp] theorem id_f (X : Center C) : Hom.f (𝟙 X) = 𝟙 X.1 := rfl @[simp] theorem comp_f {X Y Z : Center C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).f = f.f ≫ g.f := rfl /-- Construct an isomorphism in the Drinfeld center from a morphism whose underlying morphism is an isomorphism. -/ @[simps] def isoMk {X Y : Center C} (f : X ⟶ Y) [IsIso f.f] : X ≅ Y where hom := f inv := ⟨inv f.f, fun U => by simp [← cancel_epi (f.f ▷ U), ← comp_whiskerRight_assoc, ← MonoidalCategory.whiskerLeft_comp] ⟩ instance isIso_of_f_isIso {X Y : Center C} (f : X ⟶ Y) [IsIso f.f] : IsIso f := by change IsIso (isoMk f).hom infer_instance /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ @[simps] def tensorObj (X Y : Center C) : Center C := ⟨X.1 ⊗ Y.1, { β := fun U => α_ _ _ _ ≪≫ (whiskerLeftIso X.1 (Y.2.β U)) ≪≫ (α_ _ _ _).symm ≪≫ (whiskerRightIso (X.2.β U) Y.1) ≪≫ α_ _ _ _ monoidal := fun U U' => by dsimp only [Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] simp only [HalfBraiding.monoidal] -- We'd like to commute `X.1 ◁ U ◁ (HalfBraiding.β Y.2 U').hom` -- and `((HalfBraiding.β X.2 U).hom ▷ U' ▷ Y.1)` past each other. -- We do this with the help of the monoidal composition `⊗≫` and the `coherence` tactic. calc _ = 𝟙 _ ⊗≫ X.1 ◁ (HalfBraiding.β Y.2 U).hom ▷ U' ⊗≫ (_ ◁ (HalfBraiding.β Y.2 U').hom ≫ (HalfBraiding.β X.2 U).hom ▷ _) ⊗≫ U ◁ (HalfBraiding.β X.2 U').hom ▷ Y.1 ⊗≫ 𝟙 _ := by coherence _ = _ := by rw [whisker_exchange]; coherence naturality := fun {U U'} f => by dsimp only [Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ (X.1 ◁ (Y.1 ◁ f ≫ (HalfBraiding.β Y.2 U').hom)) ⊗≫ (HalfBraiding.β X.2 U').hom ▷ Y.1 ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X.1 ◁ (HalfBraiding.β Y.2 U).hom ⊗≫ (X.1 ◁ f ≫ (HalfBraiding.β X.2 U').hom) ▷ Y.1 ⊗≫ 𝟙 _ := by rw [HalfBraiding.naturality]; coherence _ = _ := by rw [HalfBraiding.naturality]; coherence }⟩ @[reassoc] theorem whiskerLeft_comm (X : Center C) {Y₁ Y₂ : Center C} (f : Y₁ ⟶ Y₂) (U : C) : (X.1 ◁ f.f) ▷ U ≫ ((tensorObj X Y₂).2.β U).hom = ((tensorObj X Y₁).2.β U).hom ≫ U ◁ X.1 ◁ f.f := by dsimp only [tensorObj_fst, tensorObj_snd_β, Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ X.fst ◁ (f.f ▷ U ≫ (HalfBraiding.β Y₂.snd U).hom) ⊗≫ (HalfBraiding.β X.snd U).hom ▷ Y₂.fst ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X.fst ◁ (HalfBraiding.β Y₁.snd U).hom ⊗≫ ((X.fst ⊗ U) ◁ f.f ≫ (HalfBraiding.β X.snd U).hom ▷ Y₂.fst) ⊗≫ 𝟙 _ := by rw [f.comm]; coherence _ = _ := by rw [whisker_exchange]; coherence /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def whiskerLeft (X : Center C) {Y₁ Y₂ : Center C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ where f := X.1 ◁ f.f comm U := whiskerLeft_comm X f U @[reassoc] theorem whiskerRight_comm {X₁ X₂ : Center C} (f : X₁ ⟶ X₂) (Y : Center C) (U : C) : f.f ▷ Y.1 ▷ U ≫ ((tensorObj X₂ Y).2.β U).hom = ((tensorObj X₁ Y).2.β U).hom ≫ U ◁ f.f ▷ Y.1 := by dsimp only [tensorObj_fst, tensorObj_snd_β, Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ (f.f ▷ (Y.fst ⊗ U) ≫ X₂.fst ◁ (HalfBraiding.β Y.snd U).hom) ⊗≫ (HalfBraiding.β X₂.snd U).hom ▷ Y.fst ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X₁.fst ◁ (HalfBraiding.β Y.snd U).hom ⊗≫ (f.f ▷ U ≫ (HalfBraiding.β X₂.snd U).hom) ▷ Y.fst ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; coherence _ = _ := by rw [f.comm]; coherence /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def whiskerRight {X₁ X₂ : Center C} (f : X₁ ⟶ X₂) (Y : Center C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y where f := f.f ▷ Y.1 comm U := whiskerRight_comm f Y U /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ @[simps] def tensorHom {X₁ Y₁ X₂ Y₂ : Center C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂ where f := f.f ⊗ g.f comm U := by rw [tensorHom_def, comp_whiskerRight_assoc, whiskerLeft_comm, whiskerRight_comm_assoc, MonoidalCategory.whiskerLeft_comp] section /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ @[simps] def tensorUnit : Center C := ⟨𝟙_ C, { β := fun U => λ_ U ≪≫ (ρ_ U).symm }⟩ /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def associator (X Y Z : Center C) : tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) := isoMk ⟨(α_ X.1 Y.1 Z.1).hom, fun U => by simp⟩ /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def leftUnitor (X : Center C) : tensorObj tensorUnit X ≅ X := isoMk ⟨(λ_ X.1).hom, fun U => by simp⟩ /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def rightUnitor (X : Center C) : tensorObj X tensorUnit ≅ X := isoMk ⟨(ρ_ X.1).hom, fun U => by simp⟩ end section attribute [local simp] associator_naturality leftUnitor_naturality rightUnitor_naturality pentagon attribute [local simp] Center.associator Center.leftUnitor Center.rightUnitor attribute [local simp] Center.whiskerLeft Center.whiskerRight Center.tensorHom instance : MonoidalCategory (Center C) where tensorObj X Y := tensorObj X Y tensorHom f g := tensorHom f g tensorHom_def := by intros; ext; simp [tensorHom_def] whiskerLeft X _ _ f := whiskerLeft X f whiskerRight f Y := whiskerRight f Y tensorUnit := tensorUnit associator := associator leftUnitor := leftUnitor rightUnitor := rightUnitor @[simp] theorem tensor_fst (X Y : Center C) : (X ⊗ Y).1 = X.1 ⊗ Y.1 := rfl @[simp] theorem tensor_β (X Y : Center C) (U : C) : (X ⊗ Y).2.β U = α_ _ _ _ ≪≫ (whiskerLeftIso X.1 (Y.2.β U)) ≪≫ (α_ _ _ _).symm ≪≫ (whiskerRightIso (X.2.β U) Y.1) ≪≫ α_ _ _ _ := rfl @[simp] theorem whiskerLeft_f (X : Center C) {Y₁ Y₂ : Center C} (f : Y₁ ⟶ Y₂) : (X ◁ f).f = X.1 ◁ f.f := rfl @[simp] theorem whiskerRight_f {X₁ X₂ : Center C} (f : X₁ ⟶ X₂) (Y : Center C) : (f ▷ Y).f = f.f ▷ Y.1 := rfl @[simp] theorem tensor_f {X₁ Y₁ X₂ Y₂ : Center C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (f ⊗ g).f = f.f ⊗ g.f := rfl @[simp] theorem tensorUnit_β (U : C) : (𝟙_ (Center C)).2.β U = λ_ U ≪≫ (ρ_ U).symm := rfl @[simp] theorem associator_hom_f (X Y Z : Center C) : Hom.f (α_ X Y Z).hom = (α_ X.1 Y.1 Z.1).hom := rfl @[simp] theorem associator_inv_f (X Y Z : Center C) : Hom.f (α_ X Y Z).inv = (α_ X.1 Y.1 Z.1).inv := by apply Iso.inv_ext' -- Porting note: Originally `ext` rw [← associator_hom_f, ← comp_f, Iso.hom_inv_id]; rfl @[simp] theorem leftUnitor_hom_f (X : Center C) : Hom.f (λ_ X).hom = (λ_ X.1).hom := rfl @[simp] theorem leftUnitor_inv_f (X : Center C) : Hom.f (λ_ X).inv = (λ_ X.1).inv := by apply Iso.inv_ext' -- Porting note: Originally `ext` rw [← leftUnitor_hom_f, ← comp_f, Iso.hom_inv_id]; rfl @[simp] theorem rightUnitor_hom_f (X : Center C) : Hom.f (ρ_ X).hom = (ρ_ X.1).hom := rfl @[simp] theorem rightUnitor_inv_f (X : Center C) : Hom.f (ρ_ X).inv = (ρ_ X.1).inv := by apply Iso.inv_ext' -- Porting note: Originally `ext` rw [← rightUnitor_hom_f, ← comp_f, Iso.hom_inv_id]; rfl end section variable (C) /-- The forgetful monoidal functor from the Drinfeld center to the original category. -/ @[simps] def forget : MonoidalFunctor (Center C) C where obj X := X.1 map f := f.f ε := 𝟙 (𝟙_ C) μ X Y := 𝟙 (X.1 ⊗ Y.1) instance : (forget C).ReflectsIsomorphisms where reflects f i := by dsimp at i; change IsIso (isoMk f).hom; infer_instance end /-- Auxiliary definition for the `BraidedCategory` instance on `Center C`. -/ @[simps!] def braiding (X Y : Center C) : X ⊗ Y ≅ Y ⊗ X := isoMk ⟨(X.2.β Y.1).hom, fun U => by dsimp simp only [Category.assoc] rw [← IsIso.inv_comp_eq, IsIso.Iso.inv_hom, ← HalfBraiding.monoidal_assoc, ← HalfBraiding.naturality_assoc, HalfBraiding.monoidal] simp⟩ instance braidedCategoryCenter : BraidedCategory (Center C) where braiding := braiding -- `aesop_cat` handles the hexagon axioms section variable [BraidedCategory C] open BraidedCategory /-- Auxiliary construction for `ofBraided`. -/ @[simps] def ofBraidedObj (X : C) : Center C := ⟨X, { β := fun Y => β_ X Y}⟩ variable (C) /-- The functor lifting a braided category to its center, using the braiding as the half-braiding. -/ @[simps] def ofBraided : MonoidalFunctor C (Center C) where obj := ofBraidedObj map f := { f comm := fun U => braiding_naturality_left f U } ε := { f := 𝟙 _ } μ X Y := { f := 𝟙 _ } end end Center end CategoryTheory
CategoryTheory\Monoidal\CoherenceLemmas.lean
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.Tactic.CategoryTheory.Coherence /-! # Lemmas which are consequences of monoidal coherence These lemmas are all proved `by coherence`. ## Future work Investigate whether these lemmas are really needed, or if they can be replaced by use of the `coherence` tactic. -/ open CategoryTheory Category Iso namespace CategoryTheory.MonoidalCategory variable {C : Type*} [Category C] [MonoidalCategory C] -- See Proposition 2.2.4 of <http://www-math.mit.edu/~etingof/egnobookfinal.pdf> @[reassoc] theorem leftUnitor_tensor'' (X Y : C) : (α_ (𝟙_ C) X Y).hom ≫ (λ_ (X ⊗ Y)).hom = (λ_ X).hom ⊗ 𝟙 Y := by coherence @[reassoc] theorem leftUnitor_tensor' (X Y : C) : (λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ ((λ_ X).hom ⊗ 𝟙 Y) := by coherence @[reassoc] theorem leftUnitor_tensor_inv' (X Y : C) : (λ_ (X ⊗ Y)).inv = ((λ_ X).inv ⊗ 𝟙 Y) ≫ (α_ (𝟙_ C) X Y).hom := by coherence @[reassoc] theorem id_tensor_rightUnitor_inv (X Y : C) : 𝟙 X ⊗ (ρ_ Y).inv = (ρ_ _).inv ≫ (α_ _ _ _).hom := by coherence @[reassoc] theorem leftUnitor_inv_tensor_id (X Y : C) : (λ_ X).inv ⊗ 𝟙 Y = (λ_ _).inv ≫ (α_ _ _ _).inv := by coherence @[reassoc] theorem pentagon_inv_inv_hom (W X Y Z : C) : (α_ W (X ⊗ Y) Z).inv ≫ ((α_ W X Y).inv ⊗ 𝟙 Z) ≫ (α_ (W ⊗ X) Y Z).hom = (𝟙 W ⊗ (α_ X Y Z).hom) ≫ (α_ W X (Y ⊗ Z)).inv := by coherence theorem unitors_equal : (λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom := by coherence theorem unitors_inv_equal : (λ_ (𝟙_ C)).inv = (ρ_ (𝟙_ C)).inv := by coherence @[reassoc] theorem pentagon_hom_inv {W X Y Z : C} : (α_ W X (Y ⊗ Z)).hom ≫ (𝟙 W ⊗ (α_ X Y Z).inv) = (α_ (W ⊗ X) Y Z).inv ≫ ((α_ W X Y).hom ⊗ 𝟙 Z) ≫ (α_ W (X ⊗ Y) Z).hom := by coherence @[reassoc] theorem pentagon_inv_hom (W X Y Z : C) : (α_ (W ⊗ X) Y Z).inv ≫ ((α_ W X Y).hom ⊗ 𝟙 Z) = (α_ W X (Y ⊗ Z)).hom ≫ (𝟙 W ⊗ (α_ X Y Z).inv) ≫ (α_ W (X ⊗ Y) Z).inv := by coherence end CategoryTheory.MonoidalCategory
CategoryTheory\Monoidal\CommMon_.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.Mon_ /-! # The category of commutative monoids in a braided monoidal category. -/ universe v₁ v₂ u₁ u₂ u open CategoryTheory MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] [BraidedCategory.{v₁} C] /-- A commutative monoid object internal to a monoidal category. -/ structure CommMon_ extends Mon_ C where mul_comm : (β_ _ _).hom ≫ mul = mul := by aesop_cat attribute [reassoc (attr := simp)] CommMon_.mul_comm namespace CommMon_ /-- The trivial commutative monoid object. We later show this is initial in `CommMon_ C`. -/ @[simps!] def trivial : CommMon_ C := { Mon_.trivial C with mul_comm := by dsimp; rw [braiding_leftUnitor, unitors_equal] } instance : Inhabited (CommMon_ C) := ⟨trivial C⟩ variable {C} variable {M : CommMon_ C} instance : Category (CommMon_ C) := InducedCategory.category CommMon_.toMon_ @[simp] theorem id_hom (A : CommMon_ C) : Mon_.Hom.hom (𝟙 A) = 𝟙 A.X := rfl @[simp] theorem comp_hom {R S T : CommMon_ C} (f : R ⟶ S) (g : S ⟶ T) : Mon_.Hom.hom (f ≫ g) = f.hom ≫ g.hom := rfl -- Porting note (#5229): added because `Mon_.Hom.ext` is not triggered automatically -- for morphisms in `CommMon_ C` @[ext] lemma hom_ext {A B : CommMon_ C} (f g : A ⟶ B) (h : f.hom = g.hom) : f = g := Mon_.Hom.ext h -- Porting note (#10688): the following two lemmas `id'` and `comp'` -- have been added to ease automation; @[simp] lemma id' (A : CommMon_ C) : (𝟙 A : A.toMon_ ⟶ A.toMon_) = 𝟙 (A.toMon_) := rfl @[simp] lemma comp' {A₁ A₂ A₃ : CommMon_ C} (f : A₁ ⟶ A₂) (g : A₂ ⟶ A₃) : ((f ≫ g : A₁ ⟶ A₃) : A₁.toMon_ ⟶ A₃.toMon_) = @CategoryStruct.comp (Mon_ C) _ _ _ _ f g := rfl section variable (C) /-- The forgetful functor from commutative monoid objects to monoid objects. -/ def forget₂Mon_ : CommMon_ C ⥤ Mon_ C := inducedFunctor CommMon_.toMon_ -- Porting note: no delta derive handler, see https://github.com/leanprover-community/mathlib4/issues/5020 instance : (forget₂Mon_ C).Full := InducedCategory.full _ instance : (forget₂Mon_ C).Faithful := InducedCategory.faithful _ @[simp] theorem forget₂_Mon_obj_one (A : CommMon_ C) : ((forget₂Mon_ C).obj A).one = A.one := rfl @[simp] theorem forget₂_Mon_obj_mul (A : CommMon_ C) : ((forget₂Mon_ C).obj A).mul = A.mul := rfl @[simp] theorem forget₂_Mon_map_hom {A B : CommMon_ C} (f : A ⟶ B) : ((forget₂Mon_ C).map f).hom = f.hom := rfl end instance uniqueHomFromTrivial (A : CommMon_ C) : Unique (trivial C ⟶ A) := Mon_.uniqueHomFromTrivial A.toMon_ open CategoryTheory.Limits instance : HasInitial (CommMon_ C) := hasInitial_of_unique (trivial C) end CommMon_ namespace CategoryTheory.LaxBraidedFunctor variable {C} {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] [BraidedCategory.{v₂} D] /-- A lax braided functor takes commutative monoid objects to commutative monoid objects. That is, a lax braided functor `F : C ⥤ D` induces a functor `CommMon_ C ⥤ CommMon_ D`. -/ @[simps!] def mapCommMon (F : LaxBraidedFunctor C D) : CommMon_ C ⥤ CommMon_ D where obj A := { F.toLaxMonoidalFunctor.mapMon.obj A.toMon_ with mul_comm := by dsimp have := F.braided slice_lhs 1 2 => rw [← this] slice_lhs 2 3 => rw [← CategoryTheory.Functor.map_comp, A.mul_comm] } map f := F.toLaxMonoidalFunctor.mapMon.map f variable (C) (D) -- Porting note (#10688): added @[simps] to ease automation /-- `mapCommMon` is functorial in the lax braided functor. -/ @[simps] def mapCommMonFunctor : LaxBraidedFunctor C D ⥤ CommMon_ C ⥤ CommMon_ D where obj := mapCommMon map α := { app := fun A => { hom := α.app A.X } naturality := by intros; ext; simp } end CategoryTheory.LaxBraidedFunctor namespace CommMon_ open CategoryTheory.LaxBraidedFunctor namespace EquivLaxBraidedFunctorPUnit /-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/ @[simps] def laxBraidedToCommMon : LaxBraidedFunctor (Discrete PUnit.{u + 1}) C ⥤ CommMon_ C where obj F := (F.mapCommMon : CommMon_ _ ⥤ CommMon_ C).obj (trivial (Discrete PUnit.{u+1})) map α := ((mapCommMonFunctor (Discrete PUnit.{u+1}) C).map α).app _ /-- Implementation of `CommMon_.equivLaxBraidedFunctorPunit`. -/ @[simps] def commMonToLaxBraided : CommMon_ C ⥤ LaxBraidedFunctor (Discrete PUnit.{u + 1}) C where obj A := { obj := fun _ => A.X map := fun _ => 𝟙 _ ε := A.one μ := fun _ _ => A.mul map_id := fun _ => rfl map_comp := fun _ _ => (Category.id_comp (𝟙 A.X)).symm } map f := { app := fun _ => f.hom naturality := fun _ _ _ => by dsimp; rw [Category.id_comp, Category.comp_id] unit := Mon_.Hom.one_hom f tensor := fun _ _ => Mon_.Hom.mul_hom f } /-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/ @[simps!] def unitIso : 𝟭 (LaxBraidedFunctor (Discrete PUnit.{u + 1}) C) ≅ laxBraidedToCommMon C ⋙ commMonToLaxBraided C := NatIso.ofComponents (fun F => LaxBraidedFunctor.mkIso (MonoidalNatIso.ofComponents (fun _ => F.toLaxMonoidalFunctor.toFunctor.mapIso (eqToIso (by ext))) (by rintro ⟨⟩ ⟨⟩ f; aesop_cat) (by aesop_cat) (by aesop_cat))) /-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/ @[simps!] def counitIso : commMonToLaxBraided C ⋙ laxBraidedToCommMon C ≅ 𝟭 (CommMon_ C) := NatIso.ofComponents (fun F => { hom := { hom := 𝟙 _ } inv := { hom := 𝟙 _ } }) end EquivLaxBraidedFunctorPUnit open EquivLaxBraidedFunctorPUnit /-- Commutative monoid objects in `C` are "just" braided lax monoidal functors from the trivial braided monoidal category to `C`. -/ @[simps] def equivLaxBraidedFunctorPUnit : LaxBraidedFunctor (Discrete PUnit.{u + 1}) C ≌ CommMon_ C where functor := laxBraidedToCommMon C inverse := commMonToLaxBraided C unitIso := unitIso C counitIso := counitIso C end CommMon_
CategoryTheory\Monoidal\Comon_.lean
/- Copyright (c) 2024 Lean FRO LLC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Monoidal.Mon_ import Mathlib.CategoryTheory.Monoidal.Braided.Opposite import Mathlib.CategoryTheory.Monoidal.Transport import Mathlib.CategoryTheory.Monoidal.CoherenceLemmas import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # The category of comonoids in a monoidal category. We define comonoids in a monoidal category `C`, and show that they are equivalently monoid objects in the opposite category. We construct the monoidal structure on `Comon_ C`, when `C` is braided. An oplax monoidal functor takes comonoid objects to comonoid objects. That is, a oplax monoidal functor `F : C ⥤ D` induces a functor `Comon_ C ⥤ Comon_ D`. ## TODO * Comonoid objects in `C` are "just" oplax monoidal functors from the trivial monoidal category to `C`. -/ universe v₁ v₂ u₁ u₂ u open CategoryTheory MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- A comonoid object internal to a monoidal category. When the monoidal category is preadditive, this is also sometimes called a "coalgebra object". -/ structure Comon_ where /-- The underlying object of a comonoid object. -/ X : C /-- The counit of a comonoid object. -/ counit : X ⟶ 𝟙_ C /-- The comultiplication morphism of a comonoid object. -/ comul : X ⟶ X ⊗ X counit_comul : comul ≫ (counit ▷ X) = (λ_ X).inv := by aesop_cat comul_counit : comul ≫ (X ◁ counit) = (ρ_ X).inv := by aesop_cat comul_assoc : comul ≫ (X ◁ comul) = comul ≫ (comul ▷ X) ≫ (α_ X X X).hom := by aesop_cat attribute [reassoc (attr := simp)] Comon_.counit_comul Comon_.comul_counit attribute [reassoc (attr := simp)] Comon_.comul_assoc namespace Comon_ /-- The trivial comonoid object. We later show this is terminal in `Comon_ C`. -/ @[simps] def trivial : Comon_ C where X := 𝟙_ C counit := 𝟙 _ comul := (λ_ _).inv comul_assoc := by coherence counit_comul := by coherence comul_counit := by coherence instance : Inhabited (Comon_ C) := ⟨trivial C⟩ variable {C} variable {M : Comon_ C} @[reassoc (attr := simp)] theorem counit_comul_hom {Z : C} (f : M.X ⟶ Z) : M.comul ≫ (M.counit ⊗ f) = f ≫ (λ_ Z).inv := by rw [leftUnitor_inv_naturality, tensorHom_def, counit_comul_assoc] @[reassoc (attr := simp)] theorem comul_counit_hom {Z : C} (f : M.X ⟶ Z) : M.comul ≫ (f ⊗ M.counit) = f ≫ (ρ_ Z).inv := by rw [rightUnitor_inv_naturality, tensorHom_def', comul_counit_assoc] @[reassoc] theorem comul_assoc_flip : M.comul ≫ (M.comul ▷ M.X) = M.comul ≫ (M.X ◁ M.comul) ≫ (α_ M.X M.X M.X).inv := by simp [← comul_assoc] /-- A morphism of comonoid objects. -/ @[ext] structure Hom (M N : Comon_ C) where /-- The underlying morphism of a morphism of comonoid objects. -/ hom : M.X ⟶ N.X hom_counit : hom ≫ N.counit = M.counit := by aesop_cat hom_comul : hom ≫ N.comul = M.comul ≫ (hom ⊗ hom) := by aesop_cat attribute [reassoc (attr := simp)] Hom.hom_counit Hom.hom_comul /-- The identity morphism on a comonoid object. -/ @[simps] def id (M : Comon_ C) : Hom M M where hom := 𝟙 M.X instance homInhabited (M : Comon_ C) : Inhabited (Hom M M) := ⟨id M⟩ /-- Composition of morphisms of monoid objects. -/ @[simps] def comp {M N O : Comon_ C} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom instance : Category (Comon_ C) where Hom M N := Hom M N id := id comp f g := comp f g @[ext] lemma ext {X Y : Comon_ C} {f g : X ⟶ Y} (w : f.hom = g.hom) : f = g := Hom.ext w @[simp] theorem id_hom' (M : Comon_ C) : (𝟙 M : Hom M M).hom = 𝟙 M.X := rfl @[simp] theorem comp_hom' {M N K : Comon_ C} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g).hom = f.hom ≫ g.hom := rfl section variable (C) /-- The forgetful functor from comonoid objects to the ambient category. -/ @[simps] def forget : Comon_ C ⥤ C where obj A := A.X map f := f.hom end instance forget_faithful : (@forget C _ _).Faithful where instance {A B : Comon_ C} (f : A ⟶ B) [e : IsIso ((forget C).map f)] : IsIso f.hom := e /-- The forgetful functor from comonoid objects to the ambient category reflects isomorphisms. -/ instance : (forget C).ReflectsIsomorphisms where reflects f e := ⟨⟨{ hom := inv f.hom }, by aesop_cat⟩⟩ /-- Construct an isomorphism of comonoids by giving an isomorphism between the underlying objects and checking compatibility with counit and comultiplication only in the forward direction. -/ @[simps] def mkIso {M N : Comon_ C} (f : M.X ≅ N.X) (f_counit : f.hom ≫ N.counit = M.counit := by aesop_cat) (f_comul : f.hom ≫ N.comul = M.comul ≫ (f.hom ⊗ f.hom) := by aesop_cat) : M ≅ N where hom := { hom := f.hom hom_counit := f_counit hom_comul := f_comul } inv := { hom := f.inv hom_counit := by rw [← f_counit]; simp hom_comul := by rw [← cancel_epi f.hom] slice_rhs 1 2 => rw [f_comul] simp } instance uniqueHomToTrivial (A : Comon_ C) : Unique (A ⟶ trivial C) where default := { hom := A.counit hom_counit := by dsimp; simp hom_comul := by dsimp; simp [A.comul_counit, unitors_inv_equal] } uniq f := by ext; simp rw [← Category.comp_id f.hom] erw [f.hom_counit] open CategoryTheory.Limits instance : HasTerminal (Comon_ C) := hasTerminal_of_unique (trivial C) open Opposite variable (C) /-- Turn a comonoid object into a monoid object in the opposite category. -/ @[simps] def Comon_ToMon_OpOp_obj' (A : Comon_ C) : Mon_ (Cᵒᵖ) where X := op A.X one := A.counit.op mul := A.comul.op one_mul := by rw [← op_whiskerRight, ← op_comp, counit_comul] rfl mul_one := by rw [← op_whiskerLeft, ← op_comp, comul_counit] rfl mul_assoc := by rw [← op_inv_associator, ← op_whiskerRight, ← op_comp, ← op_whiskerLeft, ← op_comp, comul_assoc_flip, op_comp, op_comp_assoc] rfl /-- The contravariant functor turning comonoid objects into monoid objects in the opposite category. -/ @[simps] def Comon_ToMon_OpOp : Comon_ C ⥤ (Mon_ (Cᵒᵖ))ᵒᵖ where obj A := op (Comon_ToMon_OpOp_obj' C A) map := fun f => op <| { hom := f.hom.op one_hom := by apply Quiver.Hom.unop_inj; simp mul_hom := by apply Quiver.Hom.unop_inj; simp [op_tensorHom] } /-- Turn a monoid object in the opposite category into a comonoid object. -/ @[simps] def Mon_OpOpToComon_obj' (A : (Mon_ (Cᵒᵖ))) : Comon_ C where X := unop A.X counit := A.one.unop comul := A.mul.unop counit_comul := by rw [← unop_whiskerRight, ← unop_comp, Mon_.one_mul]; rfl comul_counit := by rw [← unop_whiskerLeft, ← unop_comp, Mon_.mul_one]; rfl comul_assoc := by rw [← unop_whiskerRight, ← unop_whiskerLeft, ← unop_comp_assoc, ← unop_comp, Mon_.mul_assoc_flip] rfl /-- The contravariant functor turning monoid objects in the opposite category into comonoid objects. -/ @[simps] def Mon_OpOpToComon_ : (Mon_ (Cᵒᵖ))ᵒᵖ ⥤ Comon_ C where obj A := Mon_OpOpToComon_obj' C (unop A) map := fun f => { hom := f.unop.hom.unop hom_counit := by apply Quiver.Hom.op_inj; simp hom_comul := by apply Quiver.Hom.op_inj; simp [op_tensorHom] } /-- Comonoid objects are contravariantly equivalent to monoid objects in the opposite category. -/ @[simps] def Comon_EquivMon_OpOp : Comon_ C ≌ (Mon_ (Cᵒᵖ))ᵒᵖ := { functor := Comon_ToMon_OpOp C inverse := Mon_OpOpToComon_ C unitIso := NatIso.ofComponents (fun _ => Iso.refl _) counitIso := NatIso.ofComponents (fun _ => Iso.refl _) } /-- Comonoid objects in a braided category form a monoidal category. This definition is via transporting back and forth to monoids in the opposite category, -/ instance [BraidedCategory C] : MonoidalCategory (Comon_ C) := Monoidal.transport (Comon_EquivMon_OpOp C).symm variable [BraidedCategory C] theorem tensorObj_X (A B : Comon_ C) : (A ⊗ B).X = A.X ⊗ B.X := rfl theorem tensorObj_counit (A B : Comon_ C) : (A ⊗ B).counit = (A.counit ⊗ B.counit) ≫ (λ_ _).hom := rfl /-- Preliminary statement of the comultiplication for a tensor product of comonoids. This version is the definitional equality provided by transport, and not quite as good as the version provided in `tensorObj_comul` below. -/ theorem tensorObj_comul' (A B : Comon_ C) : (A ⊗ B).comul = (A.comul ⊗ B.comul) ≫ (tensor_μ Cᵒᵖ (op A.X, op B.X) (op A.X, op B.X)).unop := by rfl /-- The comultiplication on the tensor product of two comonoids is the tensor product of the comultiplications followed by the tensor strength (to shuffle the factors back into order). -/ theorem tensorObj_comul (A B : Comon_ C) : (A ⊗ B).comul = (A.comul ⊗ B.comul) ≫ tensor_μ C (A.X, A.X) (B.X, B.X) := by rw [tensorObj_comul'] congr simp only [tensor_μ, unop_tensorObj, unop_op] apply Quiver.Hom.unop_inj dsimp [op_tensorObj, op_associator] rw [Category.assoc, Category.assoc, Category.assoc] /-- The forgetful functor from `Comon_ C` to `C` is monoidal when `C` is braided monoidal. -/ def forgetMonoidal : MonoidalFunctor (Comon_ C) C := { forget C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } @[simp] theorem forgetMonoidal_toFunctor : (forgetMonoidal C).toFunctor = forget C := rfl @[simp] theorem forgetMonoidal_ε : (forgetMonoidal C).ε = 𝟙 (𝟙_ C) := rfl @[simp] theorem forgetMonoidal_μ (X Y : Comon_ C) : (forgetMonoidal C).μ X Y = 𝟙 (X.X ⊗ Y.X) := rfl end Comon_ namespace CategoryTheory.OplaxMonoidalFunctor variable {C} {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] /-- A oplax monoidal functor takes comonoid objects to comonoid objects. That is, a oplax monoidal functor `F : C ⥤ D` induces a functor `Comon_ C ⥤ Comon_ D`. -/ @[simps] def mapComon (F : OplaxMonoidalFunctor C D) : Comon_ C ⥤ Comon_ D where obj A := { X := F.obj A.X counit := F.map A.counit ≫ F.η comul := F.map A.comul ≫ F.δ _ _ counit_comul := by simp_rw [comp_whiskerRight, Category.assoc, F.δ_natural_left_assoc, F.left_unitality, ← F.map_comp_assoc, A.counit_comul] comul_counit := by simp_rw [MonoidalCategory.whiskerLeft_comp, Category.assoc, F.δ_natural_right_assoc, F.right_unitality, ← F.map_comp_assoc, A.comul_counit] comul_assoc := by simp_rw [comp_whiskerRight, Category.assoc, F.δ_natural_left_assoc, MonoidalCategory.whiskerLeft_comp, F.δ_natural_right_assoc, ← F.map_comp_assoc, A.comul_assoc, F.map_comp, Category.assoc, F.associativity] } map f := { hom := F.map f.hom hom_counit := by dsimp; rw [← F.map_comp_assoc, f.hom_counit] hom_comul := by dsimp rw [Category.assoc, F.δ_natural, ← F.map_comp_assoc, ← F.map_comp_assoc, f.hom_comul] } map_id A := by ext; simp map_comp f g := by ext; simp -- TODO We haven't yet set up the category structure on `OplaxMonoidalFunctor C D` -- and so can't state `mapComonFunctor : OplaxMonoidalFunctor C D ⥤ Comon_ C ⥤ Comon_ D`. end CategoryTheory.OplaxMonoidalFunctor
CategoryTheory\Monoidal\Conv.lean
/- Copyright (c) 2024 Lean FRO LLC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Monoidal.Comon_ /-! # The convolution monoid. When `M : Comon_ C` and `N : Mon_ C`, the morphisms `M.X ⟶ N.X` form a monoid (in Type). -/ universe v₁ u₁ namespace CategoryTheory open MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] /-- The morphisms in `C` between the underlying objects of a pair of bimonoids in `C` naturally has a (set-theoretic) monoid structure. -/ def Conv (M : Comon_ C) (N : Mon_ C) : Type v₁ := M.X ⟶ N.X namespace Conv variable {M : Comon_ C} {N : Mon_ C} instance : One (Conv M N) where one := M.counit ≫ N.one theorem one_eq : (1 : Conv M N) = M.counit ≫ N.one := rfl instance : Mul (Conv M N) where mul := fun f g => M.comul ≫ f ▷ M.X ≫ N.X ◁ g ≫ N.mul theorem mul_eq (f g : Conv M N) : f * g = M.comul ≫ f ▷ M.X ≫ N.X ◁ g ≫ N.mul := rfl instance : Monoid (Conv M N) where one_mul f := by simp [one_eq, mul_eq, ← whisker_exchange_assoc] mul_one f := by simp [one_eq, mul_eq, ← whisker_exchange_assoc] mul_assoc f g h := by simp only [mul_eq] simp only [comp_whiskerRight, whisker_assoc, Category.assoc, MonoidalCategory.whiskerLeft_comp] slice_lhs 7 8 => rw [← whisker_exchange] slice_rhs 2 3 => rw [← whisker_exchange] slice_rhs 1 2 => rw [M.comul_assoc] slice_rhs 3 4 => rw [← associator_naturality_left] slice_lhs 6 7 => rw [← associator_inv_naturality_right] slice_lhs 8 9 => rw [N.mul_assoc] simp end Conv end CategoryTheory
CategoryTheory\Monoidal\Discrete.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Hom.Defs import Mathlib.CategoryTheory.DiscreteCategory import Mathlib.CategoryTheory.Monoidal.NaturalTransformation /-! # Monoids as discrete monoidal categories The discrete category on a monoid is a monoidal category. Multiplicative morphisms induced monoidal functors. -/ universe u u' open CategoryTheory Discrete MonoidalCategory variable (M : Type u) [Monoid M] namespace CategoryTheory @[to_additive (attr := simps tensorObj_as leftUnitor rightUnitor associator) Discrete.addMonoidal] instance Discrete.monoidal : MonoidalCategory (Discrete M) where tensorUnit := Discrete.mk 1 tensorObj X Y := Discrete.mk (X.as * Y.as) whiskerLeft X _ _ f := eqToHom (by dsimp; rw [eq_of_hom f]) whiskerRight f X := eqToHom (by dsimp; rw [eq_of_hom f]) tensorHom f g := eqToHom (by dsimp; rw [eq_of_hom f, eq_of_hom g]) leftUnitor X := Discrete.eqToIso (one_mul X.as) rightUnitor X := Discrete.eqToIso (mul_one X.as) associator X Y Z := Discrete.eqToIso (mul_assoc _ _ _) @[to_additive (attr := simp) Discrete.addMonoidal_tensorUnit_as] lemma Discrete.monoidal_tensorUnit_as : (𝟙_ (Discrete M)).as = 1 := rfl variable {M} {N : Type u'} [Monoid N] /-- A multiplicative morphism between monoids gives a monoidal functor between the corresponding discrete monoidal categories. -/ @[to_additive (attr := simps) Discrete.addMonoidalFunctor] def Discrete.monoidalFunctor (F : M →* N) : MonoidalFunctor (Discrete M) (Discrete N) where obj X := Discrete.mk (F X.as) map f := Discrete.eqToHom (DFunLike.congr_arg F (eq_of_hom f)) ε := Discrete.eqToHom F.map_one.symm μ X Y := Discrete.eqToHom (F.map_mul X.as Y.as).symm /-- An additive morphism between add_monoids gives a monoidal functor between the corresponding discrete monoidal categories. -/ add_decl_doc Discrete.addMonoidalFunctor variable {K : Type u} [Monoid K] /-- The monoidal natural isomorphism corresponding to composing two multiplicative morphisms. -/ @[to_additive Discrete.addMonoidalFunctorComp "The monoidal natural isomorphism corresponding to\ncomposing two additive morphisms."] def Discrete.monoidalFunctorComp (F : M →* N) (G : N →* K) : Discrete.monoidalFunctor F ⊗⋙ Discrete.monoidalFunctor G ≅ Discrete.monoidalFunctor (G.comp F) where hom := { app := fun X => 𝟙 _ } inv := { app := fun X => 𝟙 _ } end CategoryTheory
CategoryTheory\Monoidal\End.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Andrew Yang -/ import Mathlib.CategoryTheory.Monoidal.Functor /-! # Endofunctors as a monoidal category. We give the monoidal category structure on `C ⥤ C`, and show that when `C` itself is monoidal, it embeds via a monoidal functor into `C ⥤ C`. ## TODO Can we use this to show coherence results, e.g. a cheap proof that `λ_ (𝟙_ C) = ρ_ (𝟙_ C)`? I suspect this is harder than is usually made out. -/ universe v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] /-- The category of endofunctors of any category is a monoidal category, with tensor product given by composition of functors (and horizontal composition of natural transformations). -/ def endofunctorMonoidalCategory : MonoidalCategory (C ⥤ C) where tensorObj F G := F ⋙ G whiskerLeft X _ _ F := whiskerLeft X F whiskerRight F X := whiskerRight F X tensorHom α β := α ◫ β tensorUnit := 𝟭 C associator F G H := Functor.associator F G H leftUnitor F := Functor.leftUnitor F rightUnitor F := Functor.rightUnitor F open CategoryTheory.MonoidalCategory attribute [local instance] endofunctorMonoidalCategory @[simp] theorem endofunctorMonoidalCategory_tensorUnit_obj (X : C) : (𝟙_ (C ⥤ C)).obj X = X := rfl @[simp] theorem endofunctorMonoidalCategory_tensorUnit_map {X Y : C} (f : X ⟶ Y) : (𝟙_ (C ⥤ C)).map f = f := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_obj (F G : C ⥤ C) (X : C) : (F ⊗ G).obj X = G.obj (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_map (F G : C ⥤ C) {X Y : C} (f : X ⟶ Y) : (F ⊗ G).map f = G.map (F.map f) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorMap_app {F G H K : C ⥤ C} {α : F ⟶ G} {β : H ⟶ K} (X : C) : (α ⊗ β).app X = β.app (F.obj X) ≫ K.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerLeft_app {F H K : C ⥤ C} {β : H ⟶ K} (X : C) : (F ◁ β).app X = β.app (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerRight_app {F G H : C ⥤ C} {α : F ⟶ G} (X : C) : (α ▷ H).app X = H.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_associator_hom_app (F G H : C ⥤ C) (X : C) : (α_ F G H).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_associator_inv_app (F G H : C ⥤ C) (X : C) : (α_ F G H).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_hom_app (F : C ⥤ C) (X : C) : (λ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_inv_app (F : C ⥤ C) (X : C) : (λ_ F).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_hom_app (F : C ⥤ C) (X : C) : (ρ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_inv_app (F : C ⥤ C) (X : C) : (ρ_ F).inv.app X = 𝟙 _ := rfl /-- Tensoring on the right gives a monoidal functor from `C` into endofunctors of `C`. -/ @[simps!] def tensoringRightMonoidal [MonoidalCategory.{v} C] : MonoidalFunctor C (C ⥤ C) := { tensoringRight C with ε := (rightUnitorNatIso C).inv μ := fun X Y => (isoWhiskerRight (curriedAssociatorNatIso C) ((evaluation C (C ⥤ C)).obj X ⋙ (evaluation C C).obj Y)).hom } variable {C} variable {M : Type*} [Category M] [MonoidalCategory M] (F : MonoidalFunctor M (C ⥤ C)) @[reassoc (attr := simp)] theorem μ_hom_inv_app (i j : M) (X : C) : (F.μ i j).app X ≫ (F.μIso i j).inv.app X = 𝟙 _ := (F.μIso i j).hom_inv_id_app X @[reassoc (attr := simp)] theorem μ_inv_hom_app (i j : M) (X : C) : (F.μIso i j).inv.app X ≫ (F.μ i j).app X = 𝟙 _ := (F.μIso i j).inv_hom_id_app X @[reassoc (attr := simp)] theorem ε_hom_inv_app (X : C) : F.ε.app X ≫ F.εIso.inv.app X = 𝟙 _ := F.εIso.hom_inv_id_app X @[reassoc (attr := simp)] theorem ε_inv_hom_app (X : C) : F.εIso.inv.app X ≫ F.ε.app X = 𝟙 _ := F.εIso.inv_hom_id_app X @[reassoc (attr := simp)] theorem ε_naturality {X Y : C} (f : X ⟶ Y) : F.ε.app X ≫ (F.obj (𝟙_ M)).map f = f ≫ F.ε.app Y := (F.ε.naturality f).symm @[reassoc (attr := simp)] theorem ε_inv_naturality {X Y : C} (f : X ⟶ Y) : (MonoidalFunctor.εIso F).inv.app X ≫ (𝟙_ (C ⥤ C)).map f = F.εIso.inv.app X ≫ f := by aesop_cat @[reassoc (attr := simp)] theorem μ_naturality {m n : M} {X Y : C} (f : X ⟶ Y) : (F.obj n).map ((F.obj m).map f) ≫ (F.μ m n).app Y = (F.μ m n).app X ≫ (F.obj _).map f := (F.toLaxMonoidalFunctor.μ m n).naturality f -- This is a simp lemma in the reverse direction via `NatTrans.naturality`. @[reassoc] theorem μ_inv_naturality {m n : M} {X Y : C} (f : X ⟶ Y) : (F.μIso m n).inv.app X ≫ (F.obj n).map ((F.obj m).map f) = (F.obj _).map f ≫ (F.μIso m n).inv.app Y := ((F.μIso m n).inv.naturality f).symm -- This is not a simp lemma since it could be proved by the lemmas later. @[reassoc] theorem μ_naturality₂ {m n m' n' : M} (f : m ⟶ m') (g : n ⟶ n') (X : C) : (F.map g).app ((F.obj m).obj X) ≫ (F.obj n').map ((F.map f).app X) ≫ (F.μ m' n').app X = (F.μ m n).app X ≫ (F.map (f ⊗ g)).app X := by have := congr_app (F.toLaxMonoidalFunctor.μ_natural f g) X dsimp at this simpa using this @[reassoc (attr := simp)] theorem μ_naturalityₗ {m n m' : M} (f : m ⟶ m') (X : C) : (F.obj n).map ((F.map f).app X) ≫ (F.μ m' n).app X = (F.μ m n).app X ≫ (F.map (f ▷ n)).app X := by rw [← tensorHom_id, ← μ_naturality₂ F f (𝟙 n) X] simp @[reassoc (attr := simp)] theorem μ_naturalityᵣ {m n n' : M} (g : n ⟶ n') (X : C) : (F.map g).app ((F.obj m).obj X) ≫ (F.μ m n').app X = (F.μ m n).app X ≫ (F.map (m ◁ g)).app X := by rw [← id_tensorHom, ← μ_naturality₂ F (𝟙 m) g X] simp @[reassoc (attr := simp)] theorem μ_inv_naturalityₗ {m n m' : M} (f : m ⟶ m') (X : C) : (F.μIso m n).inv.app X ≫ (F.obj n).map ((F.map f).app X) = (F.map (f ▷ n)).app X ≫ (F.μIso m' n).inv.app X := by rw [← IsIso.comp_inv_eq, Category.assoc, ← IsIso.eq_inv_comp] simp @[reassoc (attr := simp)] theorem μ_inv_naturalityᵣ {m n n' : M} (g : n ⟶ n') (X : C) : (F.μIso m n).inv.app X ≫ (F.map g).app ((F.obj m).obj X) = (F.map (m ◁ g)).app X ≫ (F.μIso m n').inv.app X := by rw [← IsIso.comp_inv_eq, Category.assoc, ← IsIso.eq_inv_comp] simp @[reassoc] theorem left_unitality_app (n : M) (X : C) : (F.obj n).map (F.ε.app X) ≫ (F.μ (𝟙_ M) n).app X ≫ (F.map (λ_ n).hom).app X = 𝟙 _ := by have := congr_app (F.toLaxMonoidalFunctor.left_unitality n) X dsimp at this simpa using this.symm -- Porting note: linter claims `simp can prove it`, but cnot @[reassoc (attr := simp, nolint simpNF)] theorem obj_ε_app (n : M) (X : C) : (F.obj n).map (F.ε.app X) = (F.map (λ_ n).inv).app X ≫ (F.μIso (𝟙_ M) n).inv.app X := by refine Eq.trans ?_ (Category.id_comp _) rw [← Category.assoc, ← IsIso.comp_inv_eq, ← IsIso.comp_inv_eq, Category.assoc] convert left_unitality_app F n X · simp · simp -- Porting note: linter claims `simp can prove it`, but cnot @[reassoc (attr := simp, nolint simpNF)] theorem obj_ε_inv_app (n : M) (X : C) : (F.obj n).map (F.εIso.inv.app X) = (F.μ (𝟙_ M) n).app X ≫ (F.map (λ_ n).hom).app X := by rw [← cancel_mono ((F.obj n).map (F.ε.app X)), ← Functor.map_comp] simp @[reassoc] theorem right_unitality_app (n : M) (X : C) : F.ε.app ((F.obj n).obj X) ≫ (F.μ n (𝟙_ M)).app X ≫ (F.map (ρ_ n).hom).app X = 𝟙 _ := by have := congr_app (F.toLaxMonoidalFunctor.right_unitality n) X dsimp at this simpa using this.symm @[simp] theorem ε_app_obj (n : M) (X : C) : F.ε.app ((F.obj n).obj X) = (F.map (ρ_ n).inv).app X ≫ (F.μIso n (𝟙_ M)).inv.app X := by refine Eq.trans ?_ (Category.id_comp _) rw [← Category.assoc, ← IsIso.comp_inv_eq, ← IsIso.comp_inv_eq, Category.assoc] convert right_unitality_app F n X using 1 simp @[simp] theorem ε_inv_app_obj (n : M) (X : C) : F.εIso.inv.app ((F.obj n).obj X) = (F.μ n (𝟙_ M)).app X ≫ (F.map (ρ_ n).hom).app X := by rw [← cancel_mono (F.ε.app ((F.obj n).obj X)), ε_inv_hom_app] simp @[reassoc] theorem associativity_app (m₁ m₂ m₃ : M) (X : C) : (F.obj m₃).map ((F.μ m₁ m₂).app X) ≫ (F.μ (m₁ ⊗ m₂) m₃).app X ≫ (F.map (α_ m₁ m₂ m₃).hom).app X = (F.μ m₂ m₃).app ((F.obj m₁).obj X) ≫ (F.μ m₁ (m₂ ⊗ m₃)).app X := by have := congr_app (F.toLaxMonoidalFunctor.associativity m₁ m₂ m₃) X dsimp at this simpa using this -- Porting note: linter claims `simp can prove it`, but cnot @[reassoc (attr := simp, nolint simpNF)] theorem obj_μ_app (m₁ m₂ m₃ : M) (X : C) : (F.obj m₃).map ((F.μ m₁ m₂).app X) = (F.μ m₂ m₃).app ((F.obj m₁).obj X) ≫ (F.μ m₁ (m₂ ⊗ m₃)).app X ≫ (F.map (α_ m₁ m₂ m₃).inv).app X ≫ (F.μIso (m₁ ⊗ m₂) m₃).inv.app X := by rw [← associativity_app_assoc] simp -- Porting note: linter claims `simp can prove it`, but cnot @[reassoc (attr := simp, nolint simpNF)] theorem obj_μ_inv_app (m₁ m₂ m₃ : M) (X : C) : (F.obj m₃).map ((F.μIso m₁ m₂).inv.app X) = (F.μ (m₁ ⊗ m₂) m₃).app X ≫ (F.map (α_ m₁ m₂ m₃).hom).app X ≫ (F.μIso m₁ (m₂ ⊗ m₃)).inv.app X ≫ (F.μIso m₂ m₃).inv.app ((F.obj m₁).obj X) := by rw [← IsIso.inv_eq_inv] convert obj_μ_app F m₁ m₂ m₃ X using 1 · refine IsIso.inv_eq_of_hom_inv_id ?_ rw [← Functor.map_comp] simp · simp only [MonoidalFunctor.μIso_hom, Category.assoc, NatIso.inv_inv_app, IsIso.inv_comp] congr · refine IsIso.inv_eq_of_hom_inv_id ?_ simp · refine IsIso.inv_eq_of_hom_inv_id ?_ simp @[reassoc (attr := simp)] theorem obj_zero_map_μ_app {m : M} {X Y : C} (f : X ⟶ (F.obj m).obj Y) : (F.obj (𝟙_ M)).map f ≫ (F.μ m (𝟙_ M)).app _ = F.εIso.inv.app _ ≫ f ≫ (F.map (ρ_ m).inv).app _ := by rw [← IsIso.inv_comp_eq, ← IsIso.comp_inv_eq] simp @[simp] theorem obj_μ_zero_app (m₁ m₂ : M) (X : C) : (F.μ (𝟙_ M) m₂).app ((F.obj m₁).obj X) ≫ (F.μ m₁ (𝟙_ M ⊗ m₂)).app X ≫ (F.map (α_ m₁ (𝟙_ M) m₂).inv).app X ≫ (F.μIso (m₁ ⊗ 𝟙_ M) m₂).inv.app X = (F.μ (𝟙_ M) m₂).app ((F.obj m₁).obj X) ≫ (F.map (λ_ m₂).hom).app ((F.obj m₁).obj X) ≫ (F.obj m₂).map ((F.map (ρ_ m₁).inv).app X) := by rw [← obj_ε_inv_app_assoc, ← Functor.map_comp] simp /-- If `m ⊗ n ≅ 𝟙_M`, then `F.obj m` is a left inverse of `F.obj n`. -/ @[simps!] noncomputable def unitOfTensorIsoUnit (m n : M) (h : m ⊗ n ≅ 𝟙_ M) : F.obj m ⋙ F.obj n ≅ 𝟭 C := F.μIso m n ≪≫ F.toFunctor.mapIso h ≪≫ F.εIso.symm /-- If `m ⊗ n ≅ 𝟙_M` and `n ⊗ m ≅ 𝟙_M` (subject to some commuting constraints), then `F.obj m` and `F.obj n` forms a self-equivalence of `C`. -/ @[simps] noncomputable def equivOfTensorIsoUnit (m n : M) (h₁ : m ⊗ n ≅ 𝟙_ M) (h₂ : n ⊗ m ≅ 𝟙_ M) (H : h₁.hom ▷ m ≫ (λ_ m).hom = (α_ m n m).hom ≫ m ◁ h₂.hom ≫ (ρ_ m).hom) : C ≌ C where functor := F.obj m inverse := F.obj n unitIso := (unitOfTensorIsoUnit F m n h₁).symm counitIso := unitOfTensorIsoUnit F n m h₂ functor_unitIso_comp := by intro X dsimp simp only [μ_naturalityᵣ_assoc, μ_naturalityₗ_assoc, ε_inv_app_obj, Category.assoc, obj_μ_inv_app, Functor.map_comp, μ_inv_hom_app_assoc, obj_ε_app, unitOfTensorIsoUnit_inv_app] simp [← NatTrans.comp_app, ← F.toFunctor.map_comp, ← H, -Functor.map_comp] end CategoryTheory
CategoryTheory\Monoidal\Functor.lean
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Monoidal.Category import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Products.Basic /-! # (Lax) monoidal functors A lax monoidal functor `F` between monoidal categories `C` and `D` is a functor between the underlying categories equipped with morphisms * `ε : 𝟙_ D ⟶ F.obj (𝟙_ C)` (called the unit morphism) * `μ X Y : (F.obj X) ⊗ (F.obj Y) ⟶ F.obj (X ⊗ Y)` (called the tensorator, or strength). satisfying various axioms. A monoidal functor is a lax monoidal functor for which `ε` and `μ` are isomorphisms. We show that the composition of (lax) monoidal functors gives a (lax) monoidal functor. See also `CategoryTheory.Monoidal.Functorial` for a typeclass decorating an object-level function with the additional data of a monoidal functor. This is useful when stating that a pre-existing functor is monoidal. See `CategoryTheory.Monoidal.NaturalTransformation` for monoidal natural transformations. We show in `CategoryTheory.Monoidal.Mon_` that lax monoidal functors take monoid objects to monoid objects. ## References See <https://stacks.math.columbia.edu/tag/0FFL>. -/ open CategoryTheory universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory.Category open CategoryTheory.Functor namespace CategoryTheory section open MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] (D : Type u₂) [Category.{v₂} D] [MonoidalCategory.{v₂} D] -- The direction of `left_unitality` and `right_unitality` as simp lemmas may look strange: -- remember the rule of thumb that component indices of natural transformations -- "weigh more" than structural maps. -- (However by this argument `associativity` is currently stated backwards!) /-- A lax monoidal functor is a functor `F : C ⥤ D` between monoidal categories, equipped with morphisms `ε : 𝟙 _D ⟶ F.obj (𝟙_ C)` and `μ X Y : F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)`, satisfying the appropriate coherences. -/ structure LaxMonoidalFunctor extends C ⥤ D where /-- unit morphism -/ ε : 𝟙_ D ⟶ obj (𝟙_ C) /-- tensorator -/ μ : ∀ X Y : C, obj X ⊗ obj Y ⟶ obj (X ⊗ Y) μ_natural_left : ∀ {X Y : C} (f : X ⟶ Y) (X' : C), map f ▷ obj X' ≫ μ Y X' = μ X X' ≫ map (f ▷ X') := by aesop_cat μ_natural_right : ∀ {X Y : C} (X' : C) (f : X ⟶ Y) , obj X' ◁ map f ≫ μ X' Y = μ X' X ≫ map (X' ◁ f) := by aesop_cat /-- associativity of the tensorator -/ associativity : ∀ X Y Z : C, μ X Y ▷ obj Z ≫ μ (X ⊗ Y) Z ≫ map (α_ X Y Z).hom = (α_ (obj X) (obj Y) (obj Z)).hom ≫ obj X ◁ μ Y Z ≫ μ X (Y ⊗ Z) := by aesop_cat -- unitality left_unitality : ∀ X : C, (λ_ (obj X)).hom = ε ▷ obj X ≫ μ (𝟙_ C) X ≫ map (λ_ X).hom := by aesop_cat right_unitality : ∀ X : C, (ρ_ (obj X)).hom = obj X ◁ ε ≫ μ X (𝟙_ C) ≫ map (ρ_ X).hom := by aesop_cat -- Porting note (#11215): TODO: remove this configuration and use the default configuration. -- We keep this to be consistent with Lean 3. -- See also `initialize_simps_projections MonoidalFunctor` below. -- This may require waiting on https://github.com/leanprover-community/mathlib4/pull/2936 initialize_simps_projections LaxMonoidalFunctor (+toFunctor, -obj, -map) attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_left attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_right attribute [simp] LaxMonoidalFunctor.left_unitality attribute [simp] LaxMonoidalFunctor.right_unitality attribute [reassoc (attr := simp)] LaxMonoidalFunctor.associativity -- When `rewrite_search` lands, add @[search] attributes to -- LaxMonoidalFunctor.μ_natural LaxMonoidalFunctor.left_unitality -- LaxMonoidalFunctor.right_unitality LaxMonoidalFunctor.associativity section variable {C D} @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.μ_natural (F : LaxMonoidalFunctor C D) {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (F.map f ⊗ F.map g) ≫ F.μ Y Y' = F.μ X X' ≫ F.map (f ⊗ g) := by simp [tensorHom_def] /-- A constructor for lax monoidal functors whose axioms are described by `tensorHom` instead of `whiskerLeft` and `whiskerRight`. -/ @[simps] def LaxMonoidalFunctor.ofTensorHom (F : C ⥤ D) /- unit morphism -/ (ε : 𝟙_ D ⟶ F.obj (𝟙_ C)) /- tensorator -/ (μ : ∀ X Y : C, F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)) (μ_natural : ∀ {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y'), (F.map f ⊗ F.map g) ≫ μ Y Y' = μ X X' ≫ F.map (f ⊗ g) := by aesop_cat) /- associativity of the tensorator -/ (associativity : ∀ X Y Z : C, (μ X Y ⊗ 𝟙 (F.obj Z)) ≫ μ (X ⊗ Y) Z ≫ F.map (α_ X Y Z).hom = (α_ (F.obj X) (F.obj Y) (F.obj Z)).hom ≫ (𝟙 (F.obj X) ⊗ μ Y Z) ≫ μ X (Y ⊗ Z) := by aesop_cat) /- unitality -/ (left_unitality : ∀ X : C, (λ_ (F.obj X)).hom = (ε ⊗ 𝟙 (F.obj X)) ≫ μ (𝟙_ C) X ≫ F.map (λ_ X).hom := by aesop_cat) (right_unitality : ∀ X : C, (ρ_ (F.obj X)).hom = (𝟙 (F.obj X) ⊗ ε) ≫ μ X (𝟙_ C) ≫ F.map (ρ_ X).hom := by aesop_cat) : LaxMonoidalFunctor C D where obj := F.obj map := F.map map_id := F.map_id map_comp := F.map_comp ε := ε μ := μ μ_natural_left := fun f X' => by simp_rw [← tensorHom_id, ← F.map_id, μ_natural] μ_natural_right := fun X' f => by simp_rw [← id_tensorHom, ← F.map_id, μ_natural] associativity := fun X Y Z => by simp_rw [← tensorHom_id, ← id_tensorHom, associativity] left_unitality := fun X => by simp_rw [← tensorHom_id, left_unitality] right_unitality := fun X => by simp_rw [← id_tensorHom, right_unitality] @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.left_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) : (λ_ (F.obj X)).inv ≫ F.ε ▷ F.obj X ≫ F.μ (𝟙_ C) X = F.map (λ_ X).inv := by rw [Iso.inv_comp_eq, F.left_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.right_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) : (ρ_ (F.obj X)).inv ≫ F.obj X ◁ F.ε ≫ F.μ X (𝟙_ C) = F.map (ρ_ X).inv := by rw [Iso.inv_comp_eq, F.right_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.associativity_inv (F : LaxMonoidalFunctor C D) (X Y Z : C) : F.obj X ◁ F.μ Y Z ≫ F.μ X (Y ⊗ Z) ≫ F.map (α_ X Y Z).inv = (α_ (F.obj X) (F.obj Y) (F.obj Z)).inv ≫ F.μ X Y ▷ F.obj Z ≫ F.μ (X ⊗ Y) Z := by rw [Iso.eq_inv_comp, ← F.associativity_assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] end /-- A oplax monoidal functor is a functor `F : C ⥤ D` between monoidal categories, equipped with morphisms `η : F.obj (𝟙_ C) ⟶ 𝟙 _D` and `δ X Y : F.obj (X ⊗ Y) ⟶ F.obj X ⊗ F.obj Y`, satisfying the appropriate coherences. -/ structure OplaxMonoidalFunctor extends C ⥤ D where /-- counit morphism -/ η : obj (𝟙_ C) ⟶ 𝟙_ D /-- cotensorator -/ δ : ∀ X Y : C, obj (X ⊗ Y) ⟶ obj X ⊗ obj Y δ_natural_left : ∀ {X Y : C} (f : X ⟶ Y) (X' : C), δ X X' ≫ map f ▷ obj X' = map (f ▷ X') ≫ δ Y X' := by aesop_cat δ_natural_right : ∀ {X Y : C} (X' : C) (f : X ⟶ Y) , δ X' X ≫ obj X' ◁ map f = map (X' ◁ f) ≫ δ X' Y := by aesop_cat /-- associativity of the tensorator -/ associativity : ∀ X Y Z : C, δ (X ⊗ Y) Z ≫ δ X Y ▷ obj Z ≫ (α_ (obj X) (obj Y) (obj Z)).hom = map (α_ X Y Z).hom ≫ δ X (Y ⊗ Z) ≫ obj X ◁ δ Y Z := by aesop_cat -- unitality left_unitality : ∀ X : C, (λ_ (obj X)).inv = map (λ_ X).inv ≫ δ (𝟙_ C) X ≫ η ▷ obj X := by aesop_cat right_unitality : ∀ X : C, (ρ_ (obj X)).inv = map (ρ_ X).inv ≫ δ X (𝟙_ C) ≫ obj X ◁ η := by aesop_cat initialize_simps_projections OplaxMonoidalFunctor (+toFunctor, -obj, -map) attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.δ_natural_left attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.δ_natural_right attribute [simp] OplaxMonoidalFunctor.left_unitality attribute [simp] OplaxMonoidalFunctor.right_unitality attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.associativity section variable {C D} @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.δ_natural (F : OplaxMonoidalFunctor C D) {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : F.δ X X' ≫ (F.map f ⊗ F.map g) = F.map (f ⊗ g) ≫ F.δ Y Y' := by simp [tensorHom_def] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.left_unitality_hom (F : OplaxMonoidalFunctor C D) (X : C) : F.δ (𝟙_ C) X ≫ F.η ▷ F.obj X ≫ (λ_ (F.obj X)).hom = F.map (λ_ X).hom := by rw [← Category.assoc, ← Iso.eq_comp_inv, F.left_unitality, ← Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, id_comp] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.right_unitality_hom (F : OplaxMonoidalFunctor C D) (X : C) : F.δ X (𝟙_ C) ≫ F.obj X ◁ F.η ≫ (ρ_ (F.obj X)).hom = F.map (ρ_ X).hom := by rw [← Category.assoc, ← Iso.eq_comp_inv, F.right_unitality, ← Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, id_comp] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.associativity_inv (F : OplaxMonoidalFunctor C D) (X Y Z : C) : F.δ X (Y ⊗ Z) ≫ F.obj X ◁ F.δ Y Z ≫ (α_ (F.obj X) (F.obj Y) (F.obj Z)).inv = F.map (α_ X Y Z).inv ≫ F.δ (X ⊗ Y) Z ≫ F.δ X Y ▷ F.obj Z := by rw [← Category.assoc, Iso.comp_inv_eq, Category.assoc, Category.assoc, F.associativity, ← Category.assoc, ← F.toFunctor.map_comp, Iso.inv_hom_id, F.toFunctor.map_id, id_comp] end /-- A monoidal functor is a lax monoidal functor for which the tensorator and unitor are isomorphisms. See <https://stacks.math.columbia.edu/tag/0FFL>. -/ structure MonoidalFunctor extends LaxMonoidalFunctor.{v₁, v₂} C D where ε_isIso : IsIso ε := by infer_instance μ_isIso : ∀ X Y : C, IsIso (μ X Y) := by infer_instance -- See porting note on `initialize_simps_projections LaxMonoidalFunctor` initialize_simps_projections MonoidalFunctor (+toLaxMonoidalFunctor, -obj, -map, -ε, -μ) attribute [instance] MonoidalFunctor.ε_isIso MonoidalFunctor.μ_isIso variable {C D} /-- The unit morphism of a (strong) monoidal functor as an isomorphism. -/ noncomputable def MonoidalFunctor.εIso (F : MonoidalFunctor.{v₁, v₂} C D) : 𝟙_ D ≅ F.obj (𝟙_ C) := asIso F.ε /-- The tensorator of a (strong) monoidal functor as an isomorphism. -/ noncomputable def MonoidalFunctor.μIso (F : MonoidalFunctor.{v₁, v₂} C D) (X Y : C) : F.obj X ⊗ F.obj Y ≅ F.obj (X ⊗ Y) := asIso (F.μ X Y) /-- The underlying oplax monoidal functor of a (strong) monoidal functor. -/ @[simps] noncomputable def MonoidalFunctor.toOplaxMonoidalFunctor (F : MonoidalFunctor C D) : OplaxMonoidalFunctor C D := { F with η := inv F.ε, δ := fun X Y => inv (F.μ X Y), δ_natural_left := by aesop_cat δ_natural_right := by aesop_cat associativity := by intros X Y Z dsimp rw [IsIso.inv_comp_eq, ← inv_whiskerRight, IsIso.inv_comp_eq] slice_rhs 1 3 => rw [F.associativity] simp left_unitality := by intros X dsimp apply Iso.inv_ext rw [F.left_unitality] slice_lhs 3 4 => rw [← F.map_comp, Iso.hom_inv_id, F.map_id] simp [inv_whiskerRight] right_unitality := by intros X dsimp apply Iso.inv_ext rw [F.right_unitality] slice_lhs 3 4 => rw [← F.map_comp, Iso.hom_inv_id, F.map_id] simp } end open MonoidalCategory namespace LaxMonoidalFunctor variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity lax monoidal functor. -/ @[simps] def id : LaxMonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } instance : Inhabited (LaxMonoidalFunctor C C) := ⟨id C⟩ end LaxMonoidalFunctor namespace OplaxMonoidalFunctor variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity lax monoidal functor. -/ @[simps] def id : OplaxMonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with η := 𝟙 _ δ := fun X Y => 𝟙 _ } instance : Inhabited (OplaxMonoidalFunctor C C) := ⟨id C⟩ end OplaxMonoidalFunctor namespace MonoidalFunctor section variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] variable (F : MonoidalFunctor.{v₁, v₂} C D) @[reassoc] theorem map_tensor {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : F.map (f ⊗ g) = inv (F.μ X X') ≫ (F.map f ⊗ F.map g) ≫ F.μ Y Y' := by simp @[reassoc] theorem map_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) : F.map (X ◁ f) = inv (F.μ X Y) ≫ F.obj X ◁ F.map f ≫ F.μ X Z := by simp @[reassoc] theorem map_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) : F.map (f ▷ Z) = inv (F.μ X Z) ≫ F.map f ▷ F.obj Z ≫ F.μ Y Z := by simp @[reassoc] theorem map_leftUnitor (X : C) : F.map (λ_ X).hom = inv (F.μ (𝟙_ C) X) ≫ inv F.ε ▷ F.obj X ≫ (λ_ (F.obj X)).hom := by simp only [LaxMonoidalFunctor.left_unitality] slice_rhs 2 3 => rw [← comp_whiskerRight] simp simp @[reassoc] theorem map_rightUnitor (X : C) : F.map (ρ_ X).hom = inv (F.μ X (𝟙_ C)) ≫ F.obj X ◁ inv F.ε ≫ (ρ_ (F.obj X)).hom := by simp only [LaxMonoidalFunctor.right_unitality] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp] simp simp /-- The tensorator as a natural isomorphism. -/ noncomputable def μNatIso : Functor.prod F.toFunctor F.toFunctor ⋙ tensor D ≅ tensor C ⋙ F.toFunctor := NatIso.ofComponents (by intros apply F.μIso) (by intros apply F.toLaxMonoidalFunctor.μ_natural) @[simp] theorem μIso_hom (X Y : C) : (F.μIso X Y).hom = F.μ X Y := rfl @[reassoc (attr := simp)] theorem μ_inv_hom_id (X Y : C) : (F.μIso X Y).inv ≫ F.μ X Y = 𝟙 _ := (F.μIso X Y).inv_hom_id @[simp] theorem μ_hom_inv_id (X Y : C) : F.μ X Y ≫ (F.μIso X Y).inv = 𝟙 _ := (F.μIso X Y).hom_inv_id @[simp] theorem εIso_hom : F.εIso.hom = F.ε := rfl @[reassoc (attr := simp)] theorem ε_inv_hom_id : F.εIso.inv ≫ F.ε = 𝟙 _ := F.εIso.inv_hom_id @[simp] theorem ε_hom_inv_id : F.ε ≫ F.εIso.inv = 𝟙 _ := F.εIso.hom_inv_id /-- Monoidal functors commute with left tensoring up to isomorphism -/ @[simps!] noncomputable def commTensorLeft (X : C) : F.toFunctor ⋙ tensorLeft (F.toFunctor.obj X) ≅ tensorLeft X ⋙ F.toFunctor := NatIso.ofComponents (fun Y => F.μIso X Y) fun f => F.μ_natural_right X f /-- Monoidal functors commute with right tensoring up to isomorphism -/ @[simps!] noncomputable def commTensorRight (X : C) : F.toFunctor ⋙ tensorRight (F.toFunctor.obj X) ≅ tensorRight X ⋙ F.toFunctor := NatIso.ofComponents (fun Y => F.μIso Y X) fun f => F.μ_natural_left f X end section variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity monoidal functor. -/ @[simps] def id : MonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } instance : Inhabited (MonoidalFunctor C C) := ⟨id C⟩ end end MonoidalFunctor variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] [MonoidalCategory.{v₃} E] namespace LaxMonoidalFunctor variable (F : LaxMonoidalFunctor.{v₁, v₂} C D) (G : LaxMonoidalFunctor.{v₂, v₃} D E) /-- The composition of two lax monoidal functors is again lax monoidal. -/ @[simps] def comp : LaxMonoidalFunctor.{v₁, v₃} C E := { F.toFunctor ⋙ G.toFunctor with ε := G.ε ≫ G.map F.ε μ := fun X Y => G.μ (F.obj X) (F.obj Y) ≫ G.map (F.μ X Y) μ_natural_left := by intro X Y f X' simp_rw [comp_obj, F.comp_map, μ_natural_left_assoc, assoc, ← G.map_comp, μ_natural_left] μ_natural_right := by intro X Y f X' simp_rw [comp_obj, F.comp_map, μ_natural_right_assoc, assoc, ← G.map_comp, μ_natural_right] associativity := fun X Y Z => by dsimp simp_rw [comp_whiskerRight, assoc, μ_natural_left_assoc, MonoidalCategory.whiskerLeft_comp, assoc, μ_natural_right_assoc] slice_rhs 1 3 => rw [← G.associativity] simp_rw [Category.assoc, ← G.toFunctor.map_comp, F.associativity] } @[inherit_doc] infixr:80 " ⊗⋙ " => comp end LaxMonoidalFunctor namespace OplaxMonoidalFunctor variable (F : OplaxMonoidalFunctor.{v₁, v₂} C D) (G : OplaxMonoidalFunctor.{v₂, v₃} D E) /-- The composition of two oplax monoidal functors is again oplax monoidal. -/ @[simps] def comp : OplaxMonoidalFunctor.{v₁, v₃} C E := { F.toFunctor ⋙ G.toFunctor with η := G.map F.η ≫ G.η δ := fun X Y => G.map (F.δ X Y) ≫ G.δ (F.obj X) (F.obj Y) δ_natural_left := by intro X Y f X' simp_rw [comp_obj, Functor.comp_map, ← G.map_comp_assoc, ← F.δ_natural_left, assoc, G.δ_natural_left, ← G.map_comp_assoc] δ_natural_right := by intro X Y f X' simp_rw [comp_obj, Functor.comp_map, ← G.map_comp_assoc, ← F.δ_natural_right, assoc, G.δ_natural_right, ← G.map_comp_assoc] associativity := fun X Y Z => by dsimp simp_rw [comp_whiskerRight, assoc, δ_natural_left_assoc, MonoidalCategory.whiskerLeft_comp, δ_natural_right_assoc] slice_rhs 1 3 => simp only [← G.toFunctor.map_comp] rw [← F.associativity] rw [G.associativity] simp only [G.map_comp, Category.assoc] } @[inherit_doc] infixr:80 " ⊗⋙ " => comp end OplaxMonoidalFunctor namespace LaxMonoidalFunctor universe v₀ u₀ variable {B : Type u₀} [Category.{v₀} B] [MonoidalCategory.{v₀} B] variable (F : LaxMonoidalFunctor.{v₀, v₁} B C) (G : LaxMonoidalFunctor.{v₂, v₃} D E) attribute [local simp] μ_natural associativity left_unitality right_unitality /-- The cartesian product of two lax monoidal functors is lax monoidal. -/ @[simps] def prod : LaxMonoidalFunctor (B × D) (C × E) := { F.toFunctor.prod G.toFunctor with ε := (ε F, ε G) μ := fun X Y => (μ F X.1 Y.1, μ G X.2 Y.2) } end LaxMonoidalFunctor namespace MonoidalFunctor variable (C) /-- The diagonal functor as a monoidal functor. -/ @[simps] def diag : MonoidalFunctor C (C × C) := { Functor.diag C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } end MonoidalFunctor namespace LaxMonoidalFunctor variable (F : LaxMonoidalFunctor.{v₁, v₂} C D) (G : LaxMonoidalFunctor.{v₁, v₃} C E) /-- The cartesian product of two lax monoidal functors starting from the same monoidal category `C` is lax monoidal. -/ def prod' : LaxMonoidalFunctor C (D × E) := (MonoidalFunctor.diag C).toLaxMonoidalFunctor ⊗⋙ F.prod G @[simp] theorem prod'_toFunctor : (F.prod' G).toFunctor = F.toFunctor.prod' G.toFunctor := rfl @[simp] theorem prod'_ε : (F.prod' G).ε = (F.ε, G.ε) := by dsimp [prod'] simp @[simp] theorem prod'_μ (X Y : C) : (F.prod' G).μ X Y = (F.μ X Y, G.μ X Y) := by dsimp [prod'] simp end LaxMonoidalFunctor namespace MonoidalFunctor variable (F : MonoidalFunctor.{v₁, v₂} C D) (G : MonoidalFunctor.{v₂, v₃} D E) /-- The composition of two monoidal functors is again monoidal. -/ @[simps] def comp : MonoidalFunctor.{v₁, v₃} C E := { F.toLaxMonoidalFunctor.comp G.toLaxMonoidalFunctor with ε_isIso := by dsimp infer_instance μ_isIso := by dsimp infer_instance } @[inherit_doc] infixr:80 " ⊗⋙ " =>-- We overload notation; potentially dangerous, but it seems to work. comp end MonoidalFunctor namespace MonoidalFunctor universe v₀ u₀ variable {B : Type u₀} [Category.{v₀} B] [MonoidalCategory.{v₀} B] variable (F : MonoidalFunctor.{v₀, v₁} B C) (G : MonoidalFunctor.{v₂, v₃} D E) /-- The cartesian product of two monoidal functors is monoidal. -/ @[simps] def prod : MonoidalFunctor (B × D) (C × E) := { F.toLaxMonoidalFunctor.prod G.toLaxMonoidalFunctor with ε_isIso := (isIso_prod_iff C E).mpr ⟨ε_isIso F, ε_isIso G⟩ μ_isIso := fun X Y => (isIso_prod_iff C E).mpr ⟨μ_isIso F X.1 Y.1, μ_isIso G X.2 Y.2⟩ } end MonoidalFunctor namespace MonoidalFunctor variable (F : MonoidalFunctor.{v₁, v₂} C D) (G : MonoidalFunctor.{v₁, v₃} C E) /-- The cartesian product of two monoidal functors starting from the same monoidal category `C` is monoidal. -/ def prod' : MonoidalFunctor C (D × E) := diag C ⊗⋙ F.prod G @[simp] theorem prod'_toLaxMonoidalFunctor : (F.prod' G).toLaxMonoidalFunctor = F.toLaxMonoidalFunctor.prod' G.toLaxMonoidalFunctor := rfl end MonoidalFunctor section -- TODO: The definitions below would be slightly better phrased if, in addition to -- `MonoidalFunctor` (which extends `Functor`), we had a data valued type class -- `Functor.Monoidal` (resp. `Functor.LaxMonoidal`) so that the definitions below -- could be phrased in terms of `F : C ⥤ D`, `G : D ⥤ D`, `h : F ⊣ G` and `[F.Monoidal]`. -- Then, in the case of an equivalence (see `monoidalInverse`), we could just take as -- input an equivalence of categories `e : C ≌ D` and the data `[e.functor.Monoidal]`. variable (F : MonoidalFunctor C D) {G : D ⥤ C} (h : F.toFunctor ⊣ G) /-- If we have a right adjoint functor `G` to a monoidal functor `F`, then `G` has a lax monoidal structure as well. -/ @[simp] noncomputable def monoidalAdjoint : LaxMonoidalFunctor D C where toFunctor := G ε := h.homEquiv _ _ (inv F.ε) μ := fun X Y => h.homEquiv _ _ (inv (F.μ (G.obj X) (G.obj Y)) ≫ (h.counit.app X ⊗ h.counit.app Y)) μ_natural_left {X Y} f X' := by rw [← h.homEquiv_naturality_left, ← h.homEquiv_naturality_right, Equiv.apply_eq_iff_eq, assoc, IsIso.eq_inv_comp, ← F.toLaxMonoidalFunctor.μ_natural_left_assoc, IsIso.hom_inv_id_assoc, tensorHom_def, ← comp_whiskerRight_assoc, Adjunction.counit_naturality, comp_whiskerRight_assoc, ← whisker_exchange, ← tensorHom_def_assoc] μ_natural_right {X Y} X' f := by rw [← h.homEquiv_naturality_left, ← h.homEquiv_naturality_right, Equiv.apply_eq_iff_eq, assoc, IsIso.eq_inv_comp, ← F.toLaxMonoidalFunctor.μ_natural_right_assoc, IsIso.hom_inv_id_assoc, tensorHom_def', ← MonoidalCategory.whiskerLeft_comp_assoc, Adjunction.counit_naturality, whisker_exchange, MonoidalCategory.whiskerLeft_comp, ← tensorHom_def_assoc] associativity X Y Z := by dsimp only rw [← h.homEquiv_naturality_right, ← h.homEquiv_naturality_left, ← h.homEquiv_naturality_left, ← h.homEquiv_naturality_left, Equiv.apply_eq_iff_eq, ← cancel_epi (F.μ (G.obj X ⊗ G.obj Y) (G.obj Z)), ← cancel_epi (F.μ (G.obj X) (G.obj Y) ▷ (F.obj (G.obj Z)))] simp only [assoc] calc _ = (α_ _ _ _).hom ≫ (h.counit.app X ⊗ h.counit.app Y ⊗ h.counit.app Z) := by rw [← F.μ_natural_left_assoc, IsIso.hom_inv_id_assoc, h.homEquiv_unit, tensorHom_def_assoc (h.counit.app (X ⊗ Y)) (h.counit.app Z)] dsimp only [comp_obj, id_obj] simp_rw [← MonoidalCategory.comp_whiskerRight_assoc] rw [F.map_comp_assoc, h.counit_naturality, h.left_triangle_components_assoc, IsIso.hom_inv_id_assoc, ← tensorHom_def_assoc, associator_naturality] _ = _ := by rw [F.associativity_assoc, ← F.μ_natural_right_assoc, IsIso.hom_inv_id_assoc, h.homEquiv_unit, tensorHom_def (h.counit.app X) (h.counit.app (Y ⊗ Z))] dsimp only [id_obj, comp_obj] rw [whisker_exchange_assoc, ← MonoidalCategory.whiskerLeft_comp, F.map_comp_assoc, h.counit_naturality, h.left_triangle_components_assoc, whisker_exchange_assoc, ← MonoidalCategory.whiskerLeft_comp, ← tensorHom_def, IsIso.hom_inv_id_assoc] left_unitality X := by rw [← h.homEquiv_naturality_right, ← h.homEquiv_naturality_left, ← Equiv.symm_apply_eq, h.homEquiv_counit, F.map_leftUnitor_assoc, h.homEquiv_unit, F.map_whiskerRight_assoc, assoc, IsIso.hom_inv_id_assoc, tensorHom_def_assoc, ← MonoidalCategory.comp_whiskerRight_assoc, F.map_comp_assoc, h.counit_naturality, h.left_triangle_components_assoc] simp right_unitality X := by rw [← h.homEquiv_naturality_right, ← h.homEquiv_naturality_left, ← Equiv.symm_apply_eq, h.homEquiv_counit, F.map_rightUnitor_assoc, h.homEquiv_unit, F.map_whiskerLeft_assoc, assoc, IsIso.hom_inv_id_assoc, tensorHom_def'_assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, F.map_comp_assoc, h.counit_naturality, h.left_triangle_components_assoc] simp instance [F.IsEquivalence] : IsIso (monoidalAdjoint F h).ε := by dsimp rw [Adjunction.homEquiv_unit] infer_instance instance (X Y : D) [F.IsEquivalence] : IsIso ((monoidalAdjoint F h).μ X Y) := by dsimp rw [Adjunction.homEquiv_unit] infer_instance /-- If a monoidal functor `F` is an equivalence of categories then its inverse is also monoidal. -/ @[simps] noncomputable def monoidalInverse [F.IsEquivalence] : MonoidalFunctor D C where toLaxMonoidalFunctor := monoidalAdjoint F h end end CategoryTheory
CategoryTheory\Monoidal\FunctorCategory.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Functor.Category import Mathlib.CategoryTheory.Functor.Const /-! # Monoidal structure on `C ⥤ D` when `D` is monoidal. When `C` is any category, and `D` is a monoidal category, there is a natural "pointwise" monoidal structure on `C ⥤ D`. The initial intended application is tensor product of presheaves. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory open CategoryTheory.MonoidalCategory namespace CategoryTheory.Monoidal variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] namespace FunctorCategory variable (F G F' G' : C ⥤ D) /-- (An auxiliary definition for `functorCategoryMonoidal`.) Tensor product of functors `C ⥤ D`, when `D` is monoidal. -/ @[simps] def tensorObj : C ⥤ D where obj X := F.obj X ⊗ G.obj X map f := F.map f ⊗ G.map f variable {F G F' G'} variable (α : F ⟶ G) (β : F' ⟶ G') /-- (An auxiliary definition for `functorCategoryMonoidal`.) Tensor product of natural transformations into `D`, when `D` is monoidal. -/ @[simps] def tensorHom : tensorObj F F' ⟶ tensorObj G G' where app X := α.app X ⊗ β.app X naturality X Y f := by dsimp; rw [← tensor_comp, α.naturality, β.naturality, tensor_comp] /-- (An auxiliary definition for `functorCategoryMonoidal`.) -/ @[simps] def whiskerLeft (F) (β : F' ⟶ G') : tensorObj F F' ⟶ tensorObj F G' where app X := F.obj X ◁ β.app X naturality X Y f := by simp only [← id_tensorHom] apply (tensorHom (𝟙 F) β).naturality /-- (An auxiliary definition for `functorCategoryMonoidal`.) -/ @[simps] def whiskerRight (F') : tensorObj F F' ⟶ tensorObj G F' where app X := α.app X ▷ F'.obj X naturality X Y f := by simp only [← tensorHom_id] apply (tensorHom α (𝟙 F')).naturality end FunctorCategory open CategoryTheory.Monoidal.FunctorCategory /-- When `C` is any category, and `D` is a monoidal category, the functor category `C ⥤ D` has a natural pointwise monoidal structure, where `(F ⊗ G).obj X = F.obj X ⊗ G.obj X`. -/ instance functorCategoryMonoidalStruct : MonoidalCategoryStruct (C ⥤ D) where tensorObj F G := tensorObj F G tensorHom α β := tensorHom α β whiskerLeft F _ _ α := FunctorCategory.whiskerLeft F α whiskerRight α F := FunctorCategory.whiskerRight α F tensorUnit := (CategoryTheory.Functor.const C).obj (𝟙_ D) leftUnitor F := NatIso.ofComponents fun X => λ_ (F.obj X) rightUnitor F := NatIso.ofComponents fun X => ρ_ (F.obj X) associator F G H := NatIso.ofComponents fun X => α_ (F.obj X) (G.obj X) (H.obj X) @[simp] theorem tensorUnit_obj {X} : (𝟙_ (C ⥤ D)).obj X = 𝟙_ D := rfl @[simp] theorem tensorUnit_map {X Y} {f : X ⟶ Y} : (𝟙_ (C ⥤ D)).map f = 𝟙 (𝟙_ D) := rfl @[simp] theorem tensorObj_obj {F G : C ⥤ D} {X} : (F ⊗ G).obj X = F.obj X ⊗ G.obj X := rfl @[simp] theorem tensorObj_map {F G : C ⥤ D} {X Y} {f : X ⟶ Y} : (F ⊗ G).map f = F.map f ⊗ G.map f := rfl @[simp] theorem tensorHom_app {F G F' G' : C ⥤ D} {α : F ⟶ G} {β : F' ⟶ G'} {X} : (α ⊗ β).app X = α.app X ⊗ β.app X := rfl @[simp] theorem whiskerLeft_app {F F' G' : C ⥤ D} {β : F' ⟶ G'} {X} : (F ◁ β).app X = F.obj X ◁ β.app X := rfl @[simp] theorem whiskerRight_app {F G F' : C ⥤ D} {α : F ⟶ G} {X} : (α ▷ F').app X = α.app X ▷ F'.obj X := rfl @[simp] theorem leftUnitor_hom_app {F : C ⥤ D} {X} : ((λ_ F).hom : 𝟙_ _ ⊗ F ⟶ F).app X = (λ_ (F.obj X)).hom := rfl @[simp] theorem leftUnitor_inv_app {F : C ⥤ D} {X} : ((λ_ F).inv : F ⟶ 𝟙_ _ ⊗ F).app X = (λ_ (F.obj X)).inv := rfl @[simp] theorem rightUnitor_hom_app {F : C ⥤ D} {X} : ((ρ_ F).hom : F ⊗ 𝟙_ _ ⟶ F).app X = (ρ_ (F.obj X)).hom := rfl @[simp] theorem rightUnitor_inv_app {F : C ⥤ D} {X} : ((ρ_ F).inv : F ⟶ F ⊗ 𝟙_ _).app X = (ρ_ (F.obj X)).inv := rfl @[simp] theorem associator_hom_app {F G H : C ⥤ D} {X} : ((α_ F G H).hom : (F ⊗ G) ⊗ H ⟶ F ⊗ G ⊗ H).app X = (α_ (F.obj X) (G.obj X) (H.obj X)).hom := rfl @[simp] theorem associator_inv_app {F G H : C ⥤ D} {X} : ((α_ F G H).inv : F ⊗ G ⊗ H ⟶ (F ⊗ G) ⊗ H).app X = (α_ (F.obj X) (G.obj X) (H.obj X)).inv := rfl /-- When `C` is any category, and `D` is a monoidal category, the functor category `C ⥤ D` has a natural pointwise monoidal structure, where `(F ⊗ G).obj X = F.obj X ⊗ G.obj X`. -/ instance functorCategoryMonoidal : MonoidalCategory (C ⥤ D) where tensorHom_def := by intros; ext; simp [tensorHom_def] pentagon F G H K := by ext X; dsimp; rw [pentagon] section BraidedCategory open CategoryTheory.BraidedCategory variable [BraidedCategory.{v₂} D] /-- When `C` is any category, and `D` is a braided monoidal category, the natural pointwise monoidal structure on the functor category `C ⥤ D` is also braided. -/ instance functorCategoryBraided : BraidedCategory (C ⥤ D) where braiding F G := NatIso.ofComponents fun X => β_ _ _ hexagon_forward F G H := by ext X; apply hexagon_forward hexagon_reverse F G H := by ext X; apply hexagon_reverse example : BraidedCategory (C ⥤ D) := CategoryTheory.Monoidal.functorCategoryBraided end BraidedCategory section SymmetricCategory open CategoryTheory.SymmetricCategory variable [SymmetricCategory.{v₂} D] /-- When `C` is any category, and `D` is a symmetric monoidal category, the natural pointwise monoidal structure on the functor category `C ⥤ D` is also symmetric. -/ instance functorCategorySymmetric : SymmetricCategory (C ⥤ D) where symmetry F G := by ext X; apply symmetry end SymmetricCategory end CategoryTheory.Monoidal
CategoryTheory\Monoidal\Functorial.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Functor import Mathlib.CategoryTheory.Functor.Functorial /-! # Unbundled lax monoidal functors ## Design considerations The essential problem I've encountered that requires unbundled functors is having an existing (non-monoidal) functor `F : C ⥤ D` between monoidal categories, and wanting to assert that it has an extension to a lax monoidal functor. The two options seem to be 1. Construct a separate `F' : LaxMonoidalFunctor C D`, and assert `F'.toFunctor ≅ F`. 2. Introduce unbundled functors and unbundled lax monoidal functors, and construct `LaxMonoidal F.obj`, then construct `F' := LaxMonoidalFunctor.of F.obj`. Both have costs, but as for option 2. the cost is in library design, while in option 1. the cost is users having to carry around additional isomorphisms forever, I wanted to introduce unbundled functors. TODO: later, we may want to do this for strong monoidal functors as well, but the immediate application, for enriched categories, only requires this notion. -/ open CategoryTheory universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory.Category open CategoryTheory.Functor namespace CategoryTheory open MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] -- Perhaps in the future we'll redefine `LaxMonoidalFunctor` in terms of this, -- but that isn't the immediate plan. /-- An unbundled description of lax monoidal functors. -/ class LaxMonoidal (F : C → D) [Functorial.{v₁, v₂} F] where /-- unit morphism -/ ε : 𝟙_ D ⟶ F (𝟙_ C) /-- tensorator -/ μ : ∀ X Y : C, F X ⊗ F Y ⟶ F (X ⊗ Y) μ_natural_left : ∀ {X Y : C} (f : X ⟶ Y) (X' : C), map F f ▷ F X' ≫ μ Y X' = μ X X' ≫ map F (f ▷ X') := by aesop_cat μ_natural_right : ∀ {X Y : C} (X' : C) (f : X ⟶ Y) , F X' ◁ map F f ≫ μ X' Y = μ X' X ≫ map F (X' ◁ f) := by aesop_cat /-- associativity of the tensorator -/ associativity : ∀ X Y Z : C, μ X Y ▷ F Z ≫ μ (X ⊗ Y) Z ≫ map F (α_ X Y Z).hom = (α_ (F X) (F Y) (F Z)).hom ≫ F X ◁ μ Y Z ≫ μ X (Y ⊗ Z) := by aesop_cat /-- left unitality -/ left_unitality : ∀ X : C, (λ_ (F X)).hom = ε ▷ F X ≫ μ (𝟙_ C) X ≫ map F (λ_ X).hom := by aesop_cat /-- right unitality -/ right_unitality : ∀ X : C, (ρ_ (F X)).hom = F X ◁ ε ≫ μ X (𝟙_ C) ≫ map F (ρ_ X).hom := by aesop_cat /-- An unbundled description of lax monoidal functors. -/ abbrev LaxMonoidal.ofTensorHom (F : C → D) [Functorial.{v₁, v₂} F] /- unit morphism -/ (ε : 𝟙_ D ⟶ F (𝟙_ C)) /- tensorator -/ (μ : ∀ X Y : C, F X ⊗ F Y ⟶ F (X ⊗ Y)) /- naturality -/ (μ_natural : ∀ {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y'), (map F f ⊗ map F g) ≫ μ Y Y' = μ X X' ≫ map F (f ⊗ g) := by aesop_cat) /- associativity of the tensorator -/ (associativity : ∀ X Y Z : C, (μ X Y ⊗ 𝟙 (F Z)) ≫ μ (X ⊗ Y) Z ≫ map F (α_ X Y Z).hom = (α_ (F X) (F Y) (F Z)).hom ≫ (𝟙 (F X) ⊗ μ Y Z) ≫ μ X (Y ⊗ Z) := by aesop_cat) /- left unitality -/ (left_unitality : ∀ X : C, (λ_ (F X)).hom = (ε ⊗ 𝟙 (F X)) ≫ μ (𝟙_ C) X ≫ map F (λ_ X).hom := by aesop_cat) /- right unitality -/ (right_unitality : ∀ X : C, (ρ_ (F X)).hom = (𝟙 (F X) ⊗ ε) ≫ μ X (𝟙_ C) ≫ map F (ρ_ X).hom := by aesop_cat) : LaxMonoidal.{v₁, v₂} F where ε := ε μ := μ μ_natural_left f X := by simpa using μ_natural f (𝟙 X) μ_natural_right X f := by simpa using μ_natural (𝟙 X) f associativity X Y Z := by simpa using associativity X Y Z left_unitality X := by simpa using left_unitality X right_unitality X := by simpa using right_unitality X attribute [simp, nolint simpNF] LaxMonoidal.μ_natural_left LaxMonoidal.μ_natural_right -- The unitality axioms cannot be used as simp lemmas because they require -- higher-order matching to figure out the `F` and `X` from `F X`. attribute [simp] LaxMonoidal.associativity namespace LaxMonoidalFunctor /-- Construct a bundled `LaxMonoidalFunctor` from the object level function and `Functorial` and `LaxMonoidal` typeclasses. -/ @[simps] def of (F : C → D) [I₁ : Functorial.{v₁, v₂} F] [I₂ : LaxMonoidal.{v₁, v₂} F] : LaxMonoidalFunctor.{v₁, v₂} C D := { I₁, I₂ with obj := F } end LaxMonoidalFunctor instance (F : LaxMonoidalFunctor.{v₁, v₂} C D) : LaxMonoidal.{v₁, v₂} F.obj := { F with } section instance laxMonoidalId : LaxMonoidal.{v₁, v₁} (id : C → C) where ε := 𝟙 _ μ X Y := 𝟙 _ end -- TODO instances for composition, as required -- TODO `StrongMonoidal`, as well as `LaxMonoidal` end CategoryTheory
CategoryTheory\Monoidal\Limits.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Functorial 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 functorial association `F ↦ limit F` is lax monoidal, i.e. there are morphisms * `limLax.ε : (𝟙_ C) → limit (𝟙_ (J ⥤ C))` * `limLax.μ : 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. -/ open CategoryTheory open CategoryTheory.MonoidalCategory namespace CategoryTheory.Limits universe v u w noncomputable section variable {J : Type w} [SmallCategory J] variable {C : Type u} [Category.{v} C] [HasLimitsOfShape J C] instance limitFunctorial : Functorial fun F : J ⥤ C => limit F where map' := Limits.lim.map @[simp] theorem limitFunctorial_map {F G : J ⥤ C} (α : F ⟶ G) : map (fun F : J ⥤ C => limit F) α = Limits.lim.map α := rfl variable [MonoidalCategory.{v} C] @[simps] instance limitLaxMonoidal : LaxMonoidal fun F : J ⥤ C => limit F := .ofTensorHom (ε := limit.lift _ { pt := _ π := { app := fun j => 𝟙 _ } }) (μ := 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, ← tensor_comp, limit.w] } }) (μ_natural := fun f g => by ext; dsimp simp only [limit.lift_π, Cones.postcompose_obj_π, Monoidal.tensorHom_app, limit.lift_map, NatTrans.comp_app, Category.assoc, ← tensor_comp, limMap_π]) (associativity := fun X Y Z => by ext j; dsimp simp only [limit.lift_π, Cones.postcompose_obj_π, Monoidal.associator_hom_app, limit.lift_map, NatTrans.comp_app, Category.assoc] slice_lhs 2 2 => rw [← tensor_id_comp_id_tensor] slice_lhs 1 2 => rw [← comp_tensor_id, limit.lift_π] dsimp slice_lhs 1 2 => rw [tensor_id_comp_id_tensor] conv_lhs => rw [associator_naturality] conv_rhs => rw [← id_tensor_comp_tensor_id (limit.π (Y ⊗ Z) j)] slice_rhs 2 3 => rw [← id_tensor_comp, limit.lift_π] dsimp dsimp; rw [id_tensor_comp_tensor_id]) (left_unitality := fun X => by ext j; dsimp simp only [limit.lift_map, Category.assoc, limit.lift_π, Cones.postcompose_obj_pt, Cones.postcompose_obj_π, NatTrans.comp_app, Functor.const_obj_obj, Monoidal.tensorObj_obj, Monoidal.tensorUnit_obj, Monoidal.leftUnitor_hom_app] conv_rhs => rw [← tensor_id_comp_id_tensor (limit.π X j)] slice_rhs 1 2 => rw [← comp_tensor_id] erw [limit.lift_π] dsimp slice_rhs 2 3 => rw [id_tensorHom, leftUnitor_naturality] simp) (right_unitality := fun X => by ext j; dsimp simp only [limit.lift_map, Category.assoc, limit.lift_π, Cones.postcompose_obj_pt, Cones.postcompose_obj_π, NatTrans.comp_app, Functor.const_obj_obj, Monoidal.tensorObj_obj, Monoidal.tensorUnit_obj, Monoidal.rightUnitor_hom_app] conv_rhs => rw [← id_tensor_comp_tensor_id _ (limit.π X j)] slice_rhs 1 2 => rw [← id_tensor_comp] erw [limit.lift_π] dsimp slice_rhs 2 3 => rw [tensorHom_id, rightUnitor_naturality] simp) /-- The limit functor `F ↦ limit F` bundled as a lax monoidal functor. -/ def limLax : LaxMonoidalFunctor (J ⥤ C) C := LaxMonoidalFunctor.of fun F : J ⥤ C => limit F @[simp] theorem limLax_obj (F : J ⥤ C) : limLax.obj F = limit F := rfl theorem limLax_obj' (F : J ⥤ C) : limLax.obj F = lim.obj F := rfl @[simp] theorem limLax_map {F G : J ⥤ C} (α : F ⟶ G) : limLax.map α = lim.map α := rfl @[simp] theorem limLax_ε : (@limLax J _ C _ _ _).ε = limit.lift _ { pt := _ π := { app := fun j => 𝟙 _ } } := rfl @[simp] theorem limLax_μ (F G : J ⥤ C) : (@limLax J _ C _ _ _).μ 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, ← tensor_comp, limit.w] } } := rfl end end CategoryTheory.Limits
CategoryTheory\Monoidal\Linear.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.CategoryTheory.Monoidal.Preadditive /-! # Linear monoidal categories A monoidal category is `MonoidalLinear R` if it is monoidal preadditive and tensor product of morphisms is `R`-linear in both factors. -/ namespace CategoryTheory open CategoryTheory.Limits open CategoryTheory.MonoidalCategory variable (R : Type*) [Semiring R] variable (C : Type*) [Category C] [Preadditive C] [Linear R C] variable [MonoidalCategory C] -- Porting note: added `MonoidalPreadditive` as argument `` /-- A category is `MonoidalLinear R` if tensoring is `R`-linear in both factors. -/ class MonoidalLinear [MonoidalPreadditive C] : Prop where whiskerLeft_smul : ∀ (X : C) {Y Z : C} (r : R) (f : Y ⟶ Z) , X ◁ (r • f) = r • (X ◁ f) := by aesop_cat smul_whiskerRight : ∀ (r : R) {Y Z : C} (f : Y ⟶ Z) (X : C), (r • f) ▷ X = r • (f ▷ X) := by aesop_cat attribute [simp] MonoidalLinear.whiskerLeft_smul MonoidalLinear.smul_whiskerRight variable {C} variable [MonoidalPreadditive C] [MonoidalLinear R C] instance tensorLeft_linear (X : C) : (tensorLeft X).Linear R where instance tensorRight_linear (X : C) : (tensorRight X).Linear R where instance tensoringLeft_linear (X : C) : ((tensoringLeft C).obj X).Linear R where instance tensoringRight_linear (X : C) : ((tensoringRight C).obj X).Linear R where /-- A faithful linear monoidal functor to a linear monoidal category ensures that the domain is linear monoidal. -/ theorem monoidalLinearOfFaithful {D : Type*} [Category D] [Preadditive D] [Linear R D] [MonoidalCategory D] [MonoidalPreadditive D] (F : MonoidalFunctor D C) [F.Faithful] [F.toFunctor.Additive] [F.toFunctor.Linear R] : MonoidalLinear R D := { whiskerLeft_smul := by intros X Y Z r f apply F.toFunctor.map_injective rw [F.map_whiskerLeft] simp smul_whiskerRight := by intros r X Y f Z apply F.toFunctor.map_injective rw [F.map_whiskerRight] simp } end CategoryTheory
CategoryTheory\Monoidal\Mod_.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Mon_ /-! # The category of module objects over a monoid object. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] variable {C} /-- A module object for a monoid object, all internal to some monoidal category. -/ structure Mod_ (A : Mon_ C) where X : C act : A.X ⊗ X ⟶ X one_act : (A.one ▷ X) ≫ act = (λ_ X).hom := by aesop_cat assoc : (A.mul ▷ X) ≫ act = (α_ A.X A.X X).hom ≫ (A.X ◁ act) ≫ act := by aesop_cat attribute [reassoc (attr := simp)] Mod_.one_act Mod_.assoc namespace Mod_ variable {A : Mon_ C} (M : Mod_ A) theorem assoc_flip : (A.X ◁ M.act) ≫ M.act = (α_ A.X A.X M.X).inv ≫ (A.mul ▷ M.X) ≫ M.act := by simp /-- A morphism of module objects. -/ @[ext] structure Hom (M N : Mod_ A) where hom : M.X ⟶ N.X act_hom : M.act ≫ hom = (A.X ◁ hom) ≫ N.act := by aesop_cat attribute [reassoc (attr := simp)] Hom.act_hom /-- The identity morphism on a module object. -/ @[simps] def id (M : Mod_ A) : Hom M M where hom := 𝟙 M.X instance homInhabited (M : Mod_ A) : Inhabited (Hom M M) := ⟨id M⟩ /-- Composition of module object morphisms. -/ @[simps] def comp {M N O : Mod_ A} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom instance : Category (Mod_ A) where Hom M N := Hom M N id := id comp f g := comp f g -- Porting note (#5229): added because `Hom.ext` is not triggered automatically @[ext] lemma hom_ext {M N : Mod_ A} (f₁ f₂ : M ⟶ N) (h : f₁.hom = f₂.hom) : f₁ = f₂ := Hom.ext h @[simp] theorem id_hom' (M : Mod_ A) : (𝟙 M : M ⟶ M).hom = 𝟙 M.X := by rfl @[simp] theorem comp_hom' {M N K : Mod_ A} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g).hom = f.hom ≫ g.hom := rfl variable (A) /-- A monoid object as a module over itself. -/ @[simps] def regular : Mod_ A where X := A.X act := A.mul instance : Inhabited (Mod_ A) := ⟨regular A⟩ /-- The forgetful functor from module objects to the ambient category. -/ def forget : Mod_ A ⥤ C where obj A := A.X map f := f.hom open CategoryTheory.MonoidalCategory /-- A morphism of monoid objects induces a "restriction" or "comap" functor between the categories of module objects. -/ @[simps] def comap {A B : Mon_ C} (f : A ⟶ B) : Mod_ B ⥤ Mod_ A where obj M := { X := M.X act := (f.hom ▷ M.X) ≫ M.act one_act := by slice_lhs 1 2 => rw [← comp_whiskerRight] rw [f.one_hom, one_act] assoc := by -- oh, for homotopy.io in a widget! slice_rhs 2 3 => rw [whisker_exchange] simp only [whiskerRight_tensor, MonoidalCategory.whiskerLeft_comp, Category.assoc, Iso.hom_inv_id_assoc] slice_rhs 4 5 => rw [Mod_.assoc_flip] slice_rhs 3 4 => rw [associator_inv_naturality_middle] slice_rhs 2 4 => rw [Iso.hom_inv_id_assoc] slice_rhs 1 2 => rw [← MonoidalCategory.comp_whiskerRight, ← whisker_exchange] slice_rhs 1 2 => rw [← MonoidalCategory.comp_whiskerRight, ← tensorHom_def', ← f.mul_hom] rw [comp_whiskerRight, Category.assoc] } map g := { hom := g.hom act_hom := by dsimp slice_rhs 1 2 => rw [whisker_exchange] slice_rhs 2 3 => rw [← g.act_hom] rw [Category.assoc] } -- Lots more could be said about `comap`, e.g. how it interacts with -- identities, compositions, and equalities of monoid object morphisms. end Mod_
CategoryTheory\Monoidal\Mon_.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.Discrete import Mathlib.CategoryTheory.Monoidal.CoherenceLemmas import Mathlib.CategoryTheory.Limits.Shapes.Terminal import Mathlib.Algebra.PUnitInstances.Algebra /-! # The category of monoids in a monoidal category. We define monoids in a monoidal category `C` and show that the category of monoids is equivalent to the category of lax monoidal functors from the unit monoidal category to `C`. We also show that if `C` is braided, then the category of monoids is naturally monoidal. -/ universe v₁ v₂ u₁ u₂ u open CategoryTheory MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- A monoid object internal to a monoidal category. When the monoidal category is preadditive, this is also sometimes called an "algebra object". -/ structure Mon_ where X : C one : 𝟙_ C ⟶ X mul : X ⊗ X ⟶ X one_mul : (one ▷ X) ≫ mul = (λ_ X).hom := by aesop_cat mul_one : (X ◁ one) ≫ mul = (ρ_ X).hom := by aesop_cat -- Obviously there is some flexibility stating this axiom. -- This one has left- and right-hand sides matching the statement of `Monoid.mul_assoc`, -- and chooses to place the associator on the right-hand side. -- The heuristic is that unitors and associators "don't have much weight". mul_assoc : (mul ▷ X) ≫ mul = (α_ X X X).hom ≫ (X ◁ mul) ≫ mul := by aesop_cat attribute [reassoc] Mon_.one_mul Mon_.mul_one attribute [simp] Mon_.one_mul Mon_.mul_one -- We prove a more general `@[simp]` lemma below. attribute [reassoc (attr := simp)] Mon_.mul_assoc namespace Mon_ /-- The trivial monoid object. We later show this is initial in `Mon_ C`. -/ @[simps] def trivial : Mon_ C where X := 𝟙_ C one := 𝟙 _ mul := (λ_ _).hom mul_assoc := by coherence mul_one := by coherence instance : Inhabited (Mon_ C) := ⟨trivial C⟩ variable {C} variable {M : Mon_ C} @[simp] theorem one_mul_hom {Z : C} (f : Z ⟶ M.X) : (M.one ⊗ f) ≫ M.mul = (λ_ Z).hom ≫ f := by rw [tensorHom_def'_assoc, M.one_mul, leftUnitor_naturality] @[simp] theorem mul_one_hom {Z : C} (f : Z ⟶ M.X) : (f ⊗ M.one) ≫ M.mul = (ρ_ Z).hom ≫ f := by rw [tensorHom_def_assoc, M.mul_one, rightUnitor_naturality] theorem mul_assoc_flip : (M.X ◁ M.mul) ≫ M.mul = (α_ M.X M.X M.X).inv ≫ (M.mul ▷ M.X) ≫ M.mul := by simp /-- A morphism of monoid objects. -/ @[ext] structure Hom (M N : Mon_ C) where hom : M.X ⟶ N.X one_hom : M.one ≫ hom = N.one := by aesop_cat mul_hom : M.mul ≫ hom = (hom ⊗ hom) ≫ N.mul := by aesop_cat attribute [reassoc (attr := simp)] Hom.one_hom Hom.mul_hom /-- The identity morphism on a monoid object. -/ @[simps] def id (M : Mon_ C) : Hom M M where hom := 𝟙 M.X instance homInhabited (M : Mon_ C) : Inhabited (Hom M M) := ⟨id M⟩ /-- Composition of morphisms of monoid objects. -/ @[simps] def comp {M N O : Mon_ C} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom instance : Category (Mon_ C) where Hom M N := Hom M N id := id comp f g := comp f g -- Porting note: added, as `Hom.ext` does not apply to a morphism. @[ext] lemma ext {X Y : Mon_ C} {f g : X ⟶ Y} (w : f.hom = g.hom) : f = g := Hom.ext w @[simp] theorem id_hom' (M : Mon_ C) : (𝟙 M : Hom M M).hom = 𝟙 M.X := rfl @[simp] theorem comp_hom' {M N K : Mon_ C} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : Hom M K).hom = f.hom ≫ g.hom := rfl section variable (C) /-- The forgetful functor from monoid objects to the ambient category. -/ @[simps] def forget : Mon_ C ⥤ C where obj A := A.X map f := f.hom end instance forget_faithful : (forget C).Faithful where instance {A B : Mon_ C} (f : A ⟶ B) [e : IsIso ((forget C).map f)] : IsIso f.hom := e /-- The forgetful functor from monoid objects to the ambient category reflects isomorphisms. -/ instance : (forget C).ReflectsIsomorphisms where reflects f e := ⟨⟨{ hom := inv f.hom }, by aesop_cat⟩⟩ /-- Construct an isomorphism of monoids by giving an isomorphism between the underlying objects and checking compatibility with unit and multiplication only in the forward direction. -/ @[simps] def mkIso {M N : Mon_ C} (f : M.X ≅ N.X) (one_f : M.one ≫ f.hom = N.one := by aesop_cat) (mul_f : M.mul ≫ f.hom = (f.hom ⊗ f.hom) ≫ N.mul := by aesop_cat) : M ≅ N where hom := { hom := f.hom } inv := { hom := f.inv one_hom := by rw [← one_f]; simp mul_hom := by rw [← cancel_mono f.hom] slice_rhs 2 3 => rw [mul_f] simp } instance uniqueHomFromTrivial (A : Mon_ C) : Unique (trivial C ⟶ A) where default := { hom := A.one mul_hom := by dsimp; simp [A.one_mul, unitors_equal] } uniq f := by ext simp only [trivial_X] rw [← Category.id_comp f.hom] erw [f.one_hom] open CategoryTheory.Limits instance : HasInitial (Mon_ C) := hasInitial_of_unique (trivial C) end Mon_ namespace CategoryTheory.LaxMonoidalFunctor variable {C} {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] -- TODO: mapMod F A : Mod A ⥤ Mod (F.mapMon A) /-- A lax monoidal functor takes monoid objects to monoid objects. That is, a lax monoidal functor `F : C ⥤ D` induces a functor `Mon_ C ⥤ Mon_ D`. -/ @[simps] def mapMon (F : LaxMonoidalFunctor C D) : Mon_ C ⥤ Mon_ D where obj A := { X := F.obj A.X one := F.ε ≫ F.map A.one mul := F.μ _ _ ≫ F.map A.mul one_mul := by simp_rw [comp_whiskerRight, Category.assoc, μ_natural_left_assoc, left_unitality] slice_lhs 3 4 => rw [← F.toFunctor.map_comp, A.one_mul] mul_one := by simp_rw [MonoidalCategory.whiskerLeft_comp, Category.assoc, μ_natural_right_assoc, right_unitality] slice_lhs 3 4 => rw [← F.toFunctor.map_comp, A.mul_one] mul_assoc := by simp_rw [comp_whiskerRight, Category.assoc, μ_natural_left_assoc, MonoidalCategory.whiskerLeft_comp, Category.assoc, μ_natural_right_assoc] slice_lhs 3 4 => rw [← F.toFunctor.map_comp, A.mul_assoc] simp } map f := { hom := F.map f.hom one_hom := by dsimp; rw [Category.assoc, ← F.toFunctor.map_comp, f.one_hom] mul_hom := by dsimp rw [Category.assoc, F.μ_natural_assoc, ← F.toFunctor.map_comp, ← F.toFunctor.map_comp, f.mul_hom] } variable (C D) /-- `mapMon` is functorial in the lax monoidal functor. -/ @[simps] -- Porting note: added this, not sure how it worked previously without. def mapMonFunctor : LaxMonoidalFunctor C D ⥤ Mon_ C ⥤ Mon_ D where obj := mapMon map α := { app := fun A => { hom := α.app A.X } } end CategoryTheory.LaxMonoidalFunctor namespace Mon_ open CategoryTheory.LaxMonoidalFunctor namespace EquivLaxMonoidalFunctorPUnit /-- Implementation of `Mon_.equivLaxMonoidalFunctorPUnit`. -/ @[simps] def laxMonoidalToMon : LaxMonoidalFunctor (Discrete PUnit.{u + 1}) C ⥤ Mon_ C where obj F := (F.mapMon : Mon_ _ ⥤ Mon_ C).obj (trivial (Discrete PUnit)) map α := ((mapMonFunctor (Discrete PUnit) C).map α).app _ /-- Implementation of `Mon_.equivLaxMonoidalFunctorPUnit`. -/ @[simps] def monToLaxMonoidal : Mon_ C ⥤ LaxMonoidalFunctor (Discrete PUnit.{u + 1}) C where obj A := { obj := fun _ => A.X map := fun _ => 𝟙 _ ε := A.one μ := fun _ _ => A.mul } map f := { app := fun _ => f.hom } attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases attribute [local simp] eqToIso_map /-- Implementation of `Mon_.equivLaxMonoidalFunctorPUnit`. -/ @[simps!] def unitIso : 𝟭 (LaxMonoidalFunctor (Discrete PUnit.{u + 1}) C) ≅ laxMonoidalToMon C ⋙ monToLaxMonoidal C := NatIso.ofComponents (fun F => MonoidalNatIso.ofComponents (fun _ => F.toFunctor.mapIso (eqToIso (by ext)))) /-- Implementation of `Mon_.equivLaxMonoidalFunctorPUnit`. -/ @[simps!] def counitIso : monToLaxMonoidal C ⋙ laxMonoidalToMon C ≅ 𝟭 (Mon_ C) := NatIso.ofComponents (fun F => { hom := { hom := 𝟙 _ }, inv := { hom := 𝟙 _ } }) end EquivLaxMonoidalFunctorPUnit open EquivLaxMonoidalFunctorPUnit attribute [local simp] eqToIso_map /-- Monoid objects in `C` are "just" lax monoidal functors from the trivial monoidal category to `C`. -/ @[simps] def equivLaxMonoidalFunctorPUnit : LaxMonoidalFunctor (Discrete PUnit.{u + 1}) C ≌ Mon_ C where functor := laxMonoidalToMon C inverse := monToLaxMonoidal C unitIso := unitIso C counitIso := counitIso C end Mon_ namespace Mon_ /-! In this section, we prove that the category of monoids in a braided monoidal category is monoidal. Given two monoids `M` and `N` in a braided monoidal category `C`, the multiplication on the tensor product `M.X ⊗ N.X` is defined in the obvious way: it is the tensor product of the multiplications on `M` and `N`, except that the tensor factors in the source come in the wrong order, which we fix by pre-composing with a permutation isomorphism constructed from the braiding. (There is a subtlety here: in fact there are two ways to do these, using either the positive or negative crossing.) A more conceptual way of understanding this definition is the following: The braiding on `C` gives rise to a monoidal structure on the tensor product functor from `C × C` to `C`. A pair of monoids in `C` gives rise to a monoid in `C × C`, which the tensor product functor by being monoidal takes to a monoid in `C`. The permutation isomorphism appearing in the definition of the multiplication on the tensor product of two monoids is an instance of a more general family of isomorphisms which together form a strength that equips the tensor product functor with a monoidal structure, and the monoid axioms for the tensor product follow from the monoid axioms for the tensor factors plus the properties of the strength (i.e., monoidal functor axioms). The strength `tensor_μ` of the tensor product functor has been defined in `Mathlib.CategoryTheory.Monoidal.Braided`. Its properties, stated as independent lemmas in that module, are used extensively in the proofs below. Notice that we could have followed the above plan not only conceptually but also as a possible implementation and could have constructed the tensor product of monoids via `mapMon`, but we chose to give a more explicit definition directly in terms of `tensor_μ`. To complete the definition of the monoidal category structure on the category of monoids, we need to provide definitions of associator and unitors. The obvious candidates are the associator and unitors from `C`, but we need to prove that they are monoid morphisms, i.e., compatible with unit and multiplication. These properties translate to the monoidality of the associator and unitors (with respect to the monoidal structures on the functors they relate), which have also been proved in `Mathlib.CategoryTheory.Monoidal.Braided`. -/ variable {C} -- The proofs that associators and unitors preserve monoid units don't require braiding. theorem one_associator {M N P : Mon_ C} : ((λ_ (𝟙_ C)).inv ≫ ((λ_ (𝟙_ C)).inv ≫ (M.one ⊗ N.one) ⊗ P.one)) ≫ (α_ M.X N.X P.X).hom = (λ_ (𝟙_ C)).inv ≫ (M.one ⊗ (λ_ (𝟙_ C)).inv ≫ (N.one ⊗ P.one)) := by simp only [Category.assoc, Iso.cancel_iso_inv_left] slice_lhs 1 3 => rw [← Category.id_comp P.one, tensor_comp] slice_lhs 2 3 => rw [associator_naturality] slice_rhs 1 2 => rw [← Category.id_comp M.one, tensor_comp] slice_lhs 1 2 => rw [tensorHom_id, ← leftUnitor_tensor_inv] rw [← cancel_epi (λ_ (𝟙_ C)).inv] slice_lhs 1 2 => rw [leftUnitor_inv_naturality] simp theorem one_leftUnitor {M : Mon_ C} : ((λ_ (𝟙_ C)).inv ≫ (𝟙 (𝟙_ C) ⊗ M.one)) ≫ (λ_ M.X).hom = M.one := by simp theorem one_rightUnitor {M : Mon_ C} : ((λ_ (𝟙_ C)).inv ≫ (M.one ⊗ 𝟙 (𝟙_ C))) ≫ (ρ_ M.X).hom = M.one := by simp [← unitors_equal] section BraidedCategory variable [BraidedCategory C] theorem Mon_tensor_one_mul (M N : Mon_ C) : (((λ_ (𝟙_ C)).inv ≫ (M.one ⊗ N.one)) ▷ (M.X ⊗ N.X)) ≫ tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul) = (λ_ (M.X ⊗ N.X)).hom := by simp only [comp_whiskerRight_assoc] slice_lhs 2 3 => rw [tensor_μ_natural_left] slice_lhs 3 4 => rw [← tensor_comp, one_mul M, one_mul N] symm exact tensor_left_unitality C M.X N.X theorem Mon_tensor_mul_one (M N : Mon_ C) : (M.X ⊗ N.X) ◁ ((λ_ (𝟙_ C)).inv ≫ (M.one ⊗ N.one)) ≫ tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul) = (ρ_ (M.X ⊗ N.X)).hom := by simp only [MonoidalCategory.whiskerLeft_comp_assoc] slice_lhs 2 3 => rw [tensor_μ_natural_right] slice_lhs 3 4 => rw [← tensor_comp, mul_one M, mul_one N] symm exact tensor_right_unitality C M.X N.X theorem Mon_tensor_mul_assoc (M N : Mon_ C) : ((tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul)) ▷ (M.X ⊗ N.X)) ≫ tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul) = (α_ (M.X ⊗ N.X) (M.X ⊗ N.X) (M.X ⊗ N.X)).hom ≫ ((M.X ⊗ N.X) ◁ (tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul))) ≫ tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul) := by simp only [comp_whiskerRight_assoc, MonoidalCategory.whiskerLeft_comp_assoc] slice_lhs 2 3 => rw [tensor_μ_natural_left] slice_lhs 3 4 => rw [← tensor_comp, mul_assoc M, mul_assoc N, tensor_comp, tensor_comp] slice_lhs 1 3 => rw [tensor_associativity] slice_lhs 3 4 => rw [← tensor_μ_natural_right] simp theorem mul_associator {M N P : Mon_ C} : (tensor_μ C (M.X ⊗ N.X, P.X) (M.X ⊗ N.X, P.X) ≫ (tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul) ⊗ P.mul)) ≫ (α_ M.X N.X P.X).hom = ((α_ M.X N.X P.X).hom ⊗ (α_ M.X N.X P.X).hom) ≫ tensor_μ C (M.X, N.X ⊗ P.X) (M.X, N.X ⊗ P.X) ≫ (M.mul ⊗ tensor_μ C (N.X, P.X) (N.X, P.X) ≫ (N.mul ⊗ P.mul)) := by simp only [tensor_obj, prodMonoidal_tensorObj, Category.assoc] slice_lhs 2 3 => rw [← Category.id_comp P.mul, tensor_comp] slice_lhs 3 4 => rw [associator_naturality] slice_rhs 3 4 => rw [← Category.id_comp M.mul, tensor_comp] simp only [tensorHom_id, id_tensorHom] slice_lhs 1 3 => rw [associator_monoidal] simp only [Category.assoc] theorem mul_leftUnitor {M : Mon_ C} : (tensor_μ C (𝟙_ C, M.X) (𝟙_ C, M.X) ≫ ((λ_ (𝟙_ C)).hom ⊗ M.mul)) ≫ (λ_ M.X).hom = ((λ_ M.X).hom ⊗ (λ_ M.X).hom) ≫ M.mul := by rw [← Category.comp_id (λ_ (𝟙_ C)).hom, ← Category.id_comp M.mul, tensor_comp] simp only [tensorHom_id, id_tensorHom] slice_lhs 3 4 => rw [leftUnitor_naturality] slice_lhs 1 3 => rw [← leftUnitor_monoidal] simp only [Category.assoc, Category.id_comp] theorem mul_rightUnitor {M : Mon_ C} : (tensor_μ C (M.X, 𝟙_ C) (M.X, 𝟙_ C) ≫ (M.mul ⊗ (λ_ (𝟙_ C)).hom)) ≫ (ρ_ M.X).hom = ((ρ_ M.X).hom ⊗ (ρ_ M.X).hom) ≫ M.mul := by rw [← Category.id_comp M.mul, ← Category.comp_id (λ_ (𝟙_ C)).hom, tensor_comp] simp only [tensorHom_id, id_tensorHom] slice_lhs 3 4 => rw [rightUnitor_naturality] slice_lhs 1 3 => rw [← rightUnitor_monoidal] simp only [Category.assoc, Category.id_comp] @[simps tensorObj_X tensorHom_hom] instance monMonoidalStruct : MonoidalCategoryStruct (Mon_ C) := let tensorObj (M N : Mon_ C) : Mon_ C := { X := M.X ⊗ N.X one := (λ_ (𝟙_ C)).inv ≫ (M.one ⊗ N.one) mul := tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul) one_mul := Mon_tensor_one_mul M N mul_one := Mon_tensor_mul_one M N mul_assoc := Mon_tensor_mul_assoc M N } let tensorHom {X₁ Y₁ X₂ Y₂ : Mon_ C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : tensorObj _ _ ⟶ tensorObj _ _ := { hom := f.hom ⊗ g.hom one_hom := by dsimp slice_lhs 2 3 => rw [← tensor_comp, Hom.one_hom f, Hom.one_hom g] mul_hom := by dsimp slice_rhs 1 2 => rw [tensor_μ_natural] slice_lhs 2 3 => rw [← tensor_comp, Hom.mul_hom f, Hom.mul_hom g, tensor_comp] simp only [Category.assoc] } { tensorObj := tensorObj tensorHom := tensorHom whiskerRight := fun f Y => tensorHom f (𝟙 Y) whiskerLeft := fun X _ _ g => tensorHom (𝟙 X) g tensorUnit := trivial C associator := fun M N P ↦ mkIso (α_ M.X N.X P.X) one_associator mul_associator leftUnitor := fun M ↦ mkIso (λ_ M.X) one_leftUnitor mul_leftUnitor rightUnitor := fun M ↦ mkIso (ρ_ M.X) one_rightUnitor mul_rightUnitor } @[simp] theorem tensorUnit_X : (𝟙_ (Mon_ C)).X = 𝟙_ C := rfl @[simp] theorem tensorUnit_one : (𝟙_ (Mon_ C)).one = 𝟙 (𝟙_ C) := rfl @[simp] theorem tensorUnit_mul : (𝟙_ (Mon_ C)).mul = (λ_ (𝟙_ C)).hom := rfl @[simp] theorem tensorObj_one (X Y : Mon_ C) : (X ⊗ Y).one = (λ_ (𝟙_ C)).inv ≫ (X.one ⊗ Y.one) := rfl @[simp] theorem tensorObj_mul (X Y : Mon_ C) : (X ⊗ Y).mul = tensor_μ C (X.X, Y.X) (X.X, Y.X) ≫ (X.mul ⊗ Y.mul) := rfl @[simp] theorem whiskerLeft_hom {X Y : Mon_ C} (f : X ⟶ Y) (Z : Mon_ C) : (f ▷ Z).hom = f.hom ▷ Z.X := by rw [← tensorHom_id]; rfl @[simp] theorem whiskerRight_hom (X : Mon_ C) {Y Z : Mon_ C} (f : Y ⟶ Z) : (X ◁ f).hom = X.X ◁ f.hom := by rw [← id_tensorHom]; rfl @[simp] theorem leftUnitor_hom_hom (X : Mon_ C) : (λ_ X).hom.hom = (λ_ X.X).hom := rfl @[simp] theorem leftUnitor_inv_hom (X : Mon_ C) : (λ_ X).inv.hom = (λ_ X.X).inv := rfl @[simp] theorem rightUnitor_hom_hom (X : Mon_ C) : (ρ_ X).hom.hom = (ρ_ X.X).hom := rfl @[simp] theorem rightUnitor_inv_hom (X : Mon_ C) : (ρ_ X).inv.hom = (ρ_ X.X).inv := rfl @[simp] theorem associator_hom_hom (X Y Z : Mon_ C) : (α_ X Y Z).hom.hom = (α_ X.X Y.X Z.X).hom := rfl @[simp] theorem associator_inv_hom (X Y Z : Mon_ C) : (α_ X Y Z).inv.hom = (α_ X.X Y.X Z.X).inv := rfl @[simp] theorem tensor_one (M N : Mon_ C) : (M ⊗ N).one = (λ_ (𝟙_ C)).inv ≫ (M.one ⊗ N.one) := rfl @[simp] theorem tensor_mul (M N : Mon_ C) : (M ⊗ N).mul = tensor_μ C (M.X, N.X) (M.X, N.X) ≫ (M.mul ⊗ N.mul) := rfl instance monMonoidal : MonoidalCategory (Mon_ C) where tensorHom_def := by intros; ext; simp [tensorHom_def] variable (C) /-- The forgetful functor from `Mon_ C` to `C` is monoidal when `C` is braided monoidal. -/ def forgetMonoidal : MonoidalFunctor (Mon_ C) C := { forget C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } @[simp] theorem forgetMonoidal_toFunctor : (forgetMonoidal C).toFunctor = forget C := rfl @[simp] theorem forgetMonoidal_ε : (forgetMonoidal C).ε = 𝟙 (𝟙_ C) := rfl @[simp] theorem forgetMonoidal_μ (X Y : Mon_ C) : (forgetMonoidal C).μ X Y = 𝟙 (X.X ⊗ Y.X) := rfl variable {C} theorem one_braiding {X Y : Mon_ C} : (X ⊗ Y).one ≫ (β_ X.X Y.X).hom = (Y ⊗ X).one := by simp only [monMonoidalStruct_tensorObj_X, tensor_one, Category.assoc, BraidedCategory.braiding_naturality, braiding_tensorUnit_right, Iso.cancel_iso_inv_left] coherence end BraidedCategory /-! We next show that if `C` is symmetric, then `Mon_ C` is braided, and indeed symmetric. Note that `Mon_ C` is *not* braided in general when `C` is only braided. The more interesting construction is the 2-category of monoids in `C`, bimodules between the monoids, and intertwiners between the bimodules. When `C` is braided, that is a monoidal 2-category. -/ section SymmetricCategory variable [SymmetricCategory C] theorem mul_braiding {X Y : Mon_ C} : (X ⊗ Y).mul ≫ (β_ X.X Y.X).hom = ((β_ X.X Y.X).hom ⊗ (β_ X.X Y.X).hom) ≫ (Y ⊗ X).mul := by simp only [monMonoidalStruct_tensorObj_X, tensor_mul, tensor_μ, Category.assoc, BraidedCategory.braiding_naturality, BraidedCategory.braiding_tensor_right, BraidedCategory.braiding_tensor_left, comp_whiskerRight, whisker_assoc, MonoidalCategory.whiskerLeft_comp, pentagon_assoc, pentagon_inv_hom_hom_hom_inv_assoc, Iso.inv_hom_id_assoc, whiskerLeft_hom_inv_assoc] slice_lhs 3 4 => -- We use symmetry here: rw [← MonoidalCategory.whiskerLeft_comp, ← comp_whiskerRight, SymmetricCategory.symmetry] simp only [id_whiskerRight, MonoidalCategory.whiskerLeft_id, Category.id_comp, Category.assoc, pentagon_inv_assoc, Iso.hom_inv_id_assoc] slice_lhs 1 2 => rw [← associator_inv_naturality_left] slice_lhs 2 3 => rw [Iso.inv_hom_id] rw [Category.id_comp] slice_lhs 2 3 => rw [← associator_naturality_right] slice_lhs 1 2 => rw [← tensorHom_def] simp only [Category.assoc] instance : SymmetricCategory (Mon_ C) where braiding := fun X Y => mkIso (β_ X.X Y.X) one_braiding mul_braiding symmetry := fun X Y => by ext simp [← SymmetricCategory.braiding_swap_eq_inv_braiding] end SymmetricCategory end Mon_ /-! Projects: * Check that `Mon_ MonCat ≌ CommMonCat`, via the Eckmann-Hilton argument. (You'll have to hook up the cartesian monoidal structure on `MonCat` first, available in mathlib3#3463) * More generally, check that `Mon_ (Mon_ C) ≌ CommMon_ C` when `C` is braided. * Check that `Mon_ TopCat ≌ [bundled topological monoids]`. * Check that `Mon_ AddCommGrp ≌ RingCat`. (We've already got `Mon_ (ModuleCat R) ≌ AlgebraCat R`, in `Mathlib.CategoryTheory.Monoidal.Internal.Module`.) * Can you transport this monoidal structure to `RingCat` or `AlgebraCat R`? How does it compare to the "native" one? * Show that when `F` is a lax braided functor `C ⥤ D`, the functor `map_Mon F : Mon_ C ⥤ Mon_ D` is lax monoidal. -/
CategoryTheory\Monoidal\NaturalTransformation.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Monoidal.Functor import Mathlib.CategoryTheory.FullSubcategory /-! # Monoidal natural transformations Natural transformations between (lax) monoidal functors must satisfy an additional compatibility relation with the tensorators: `F.μ X Y ≫ app (X ⊗ Y) = (app X ⊗ app Y) ≫ G.μ X Y`. (Lax) monoidal functors between a fixed pair of monoidal categories themselves form a category. -/ open CategoryTheory universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory.Category open CategoryTheory.Functor namespace CategoryTheory open MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] /-- A monoidal natural transformation is a natural transformation between (lax) monoidal functors additionally satisfying: `F.μ X Y ≫ app (X ⊗ Y) = (app X ⊗ app Y) ≫ G.μ X Y` -/ @[ext] structure MonoidalNatTrans (F G : LaxMonoidalFunctor C D) extends NatTrans F.toFunctor G.toFunctor where /-- The unit condition for a monoidal natural transformation. -/ unit : F.ε ≫ app (𝟙_ C) = G.ε := by aesop_cat /-- The tensor condition for a monoidal natural transformation. -/ tensor : ∀ X Y, F.μ _ _ ≫ app (X ⊗ Y) = (app X ⊗ app Y) ≫ G.μ _ _ := by aesop_cat -- Porting note: `reassoc (attr := simp)` seems to add a `simp` -- attribute to the original lemma as well. attribute [reassoc (attr := simp)] MonoidalNatTrans.tensor attribute [reassoc (attr := simp)] MonoidalNatTrans.unit initialize_simps_projections MonoidalNatTrans (+toNatTrans, -app) namespace MonoidalNatTrans /-- The identity monoidal natural transformation. -/ @[simps!] def id (F : LaxMonoidalFunctor C D) : MonoidalNatTrans F F := { 𝟙 F.toFunctor with } instance (F : LaxMonoidalFunctor C D) : Inhabited (MonoidalNatTrans F F) := ⟨id F⟩ /-- Vertical composition of monoidal natural transformations. -/ @[simps!] def vcomp {F G H : LaxMonoidalFunctor C D} (α : MonoidalNatTrans F G) (β : MonoidalNatTrans G H) : MonoidalNatTrans F H := { NatTrans.vcomp α.toNatTrans β.toNatTrans with } instance categoryLaxMonoidalFunctor : Category (LaxMonoidalFunctor C D) where Hom := MonoidalNatTrans id := id comp α β := vcomp α β @[simp] theorem comp_toNatTrans_lax {F G H : LaxMonoidalFunctor C D} {α : F ⟶ G} {β : G ⟶ H} : (α ≫ β).toNatTrans = @CategoryStruct.comp (C ⥤ D) _ _ _ _ α.toNatTrans β.toNatTrans := rfl instance categoryMonoidalFunctor : Category (MonoidalFunctor C D) := InducedCategory.category MonoidalFunctor.toLaxMonoidalFunctor -- Porting note: added, as `MonoidalNatTrans.ext` does not apply to morphisms. @[ext] lemma ext' {F G : LaxMonoidalFunctor C D} {α β : F ⟶ G} (w : ∀ X : C, α.app X = β.app X) : α = β := MonoidalNatTrans.ext (funext w) @[simp] theorem comp_toNatTrans {F G H : MonoidalFunctor C D} {α : F ⟶ G} {β : G ⟶ H} : (α ≫ β).toNatTrans = @CategoryStruct.comp (C ⥤ D) _ _ _ _ α.toNatTrans β.toNatTrans := rfl variable {E : Type u₃} [Category.{v₃} E] [MonoidalCategory.{v₃} E] /-- Horizontal composition of monoidal natural transformations. -/ @[simps] def hcomp {F G : LaxMonoidalFunctor C D} {H K : LaxMonoidalFunctor D E} (α : MonoidalNatTrans F G) (β : MonoidalNatTrans H K) : MonoidalNatTrans (F ⊗⋙ H) (G ⊗⋙ K) := { NatTrans.hcomp α.toNatTrans β.toNatTrans with unit := by dsimp; simp conv_lhs => rw [← K.toFunctor.map_comp, α.unit] tensor := fun X Y => by dsimp; simp conv_lhs => rw [← K.toFunctor.map_comp, α.tensor, K.toFunctor.map_comp] } section attribute [local simp] NatTrans.naturality MonoidalNatTrans.unit MonoidalNatTrans.tensor /-- The cartesian product of two monoidal natural transformations is monoidal. -/ @[simps] def prod {F G : LaxMonoidalFunctor C D} {H K : LaxMonoidalFunctor C E} (α : MonoidalNatTrans F G) (β : MonoidalNatTrans H K) : MonoidalNatTrans (F.prod' H) (G.prod' K) where app X := (α.app X, β.app X) end end MonoidalNatTrans namespace MonoidalNatIso variable {F G : LaxMonoidalFunctor C D} /-- Construct a monoidal natural isomorphism from object level isomorphisms, and the monoidal naturality in the forward direction. -/ def ofComponents (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality' : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f := by aesop_cat) (unit' : F.ε ≫ (app (𝟙_ C)).hom = G.ε := by aesop_cat) (tensor' : ∀ X Y, F.μ X Y ≫ (app (X ⊗ Y)).hom = ((app X).hom ⊗ (app Y).hom) ≫ G.μ X Y := by aesop_cat) : F ≅ G where hom := { app := fun X => (app X).hom } inv := { (NatIso.ofComponents app @naturality').inv with app := fun X => (app X).inv unit := by dsimp rw [← unit', assoc, Iso.hom_inv_id, comp_id] tensor := fun X Y => by dsimp rw [Iso.comp_inv_eq, assoc, tensor', ← tensor_comp_assoc, Iso.inv_hom_id, Iso.inv_hom_id, tensor_id, id_comp] } @[simp] theorem ofComponents.hom_app (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (unit) (tensor) (X) : (ofComponents app naturality unit tensor).hom.app X = (app X).hom := rfl @[simp] theorem ofComponents.inv_app (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (unit) (tensor) (X) : (ofComponents app naturality unit tensor).inv.app X = (app X).inv := by simp [ofComponents] instance isIso_of_isIso_app (α : F ⟶ G) [∀ X : C, IsIso (α.app X)] : IsIso α := (ofComponents (fun X => asIso (α.app X)) (fun f => α.toNatTrans.naturality f) α.unit α.tensor).isIso_hom end MonoidalNatIso variable (F : MonoidalFunctor C D) {G : D ⥤ C} (h : F.toFunctor ⊣ G) /-- The unit of a adjunction can be upgraded to a monoidal natural transformation. -/ def monoidalUnit : LaxMonoidalFunctor.id C ⟶ F.toLaxMonoidalFunctor ⊗⋙ (monoidalAdjoint F h) where toNatTrans := h.unit tensor X Y := by dsimp simp only [id_comp, comp_id, assoc, Adjunction.homEquiv_unit, ← h.unit_naturality_assoc, ← Functor.map_comp, F.map_tensor, IsIso.hom_inv_id_assoc, ← tensor_comp_assoc, Adjunction.left_triangle_components, tensorHom_id, id_whiskerRight, IsIso.inv_hom_id, map_id] /-- The unit of a adjunction can be upgraded to a monoidal natural transformation. -/ @[simps] def monoidalCounit : (monoidalAdjoint F h) ⊗⋙ F.toLaxMonoidalFunctor ⟶ LaxMonoidalFunctor.id D where toNatTrans := h.counit tensor X Y := by have eq := h.counit_naturality (F.μ (G.obj X) (G.obj Y)) =≫ inv (F.μ _ _) simp only [assoc, IsIso.hom_inv_id, comp_id] at eq dsimp simp only [Adjunction.homEquiv_unit, comp_id, assoc, map_comp, map_inv, h.counit_naturality, ← eq, h.left_triangle_components_assoc, IsIso.inv_hom_id_assoc, IsIso.hom_inv_id_assoc] unit := by have eq := h.counit.naturality F.ε dsimp at eq ⊢ rw [Adjunction.homEquiv_unit, map_inv, map_comp, assoc, assoc, map_inv, ← cancel_mono F.ε, assoc, assoc, assoc, ← eq, IsIso.inv_hom_id_assoc, Adjunction.left_triangle_components, comp_id, id_comp] instance [F.IsEquivalence] : IsIso (monoidalUnit F h) := by dsimp [monoidalUnit] infer_instance instance [F.IsEquivalence] : IsIso (monoidalCounit F h) := by dsimp [monoidalCounit] infer_instance end CategoryTheory
CategoryTheory\Monoidal\OfHasFiniteProducts.lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Simon Hudon -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal /-! # The natural monoidal structure on any category with finite (co)products. A category with a monoidal structure provided in this way is sometimes called a (co)cartesian category, although this is also sometimes used to mean a finitely complete category. (See <https://ncatlab.org/nlab/show/cartesian+category>.) As this works with either products or coproducts, and sometimes we want to think of a different monoidal structure entirely, we don't set up either construct as an instance. ## Implementation We had previously chosen to rely on `HasTerminal` and `HasBinaryProducts` instead of `HasBinaryProducts`, because we were later relying on the definitional form of the tensor product. Now that `has_limit` has been refactored to be a `Prop`, this issue is irrelevant and we could simplify the construction here. See `CategoryTheory.monoidalOfChosenFiniteProducts` for a variant of this construction which allows specifying a particular choice of terminal object and binary products. -/ universe v u noncomputable section namespace CategoryTheory variable (C : Type u) [Category.{v} C] {X Y : C} open CategoryTheory.Limits section /-- A category with a terminal object and binary products has a natural monoidal structure. -/ def monoidalOfHasFiniteProducts [HasTerminal C] [HasBinaryProducts C] : MonoidalCategory C := letI : MonoidalCategoryStruct C := { tensorObj := fun X Y ↦ X ⨯ Y whiskerLeft := fun X _ _ g ↦ Limits.prod.map (𝟙 _) g whiskerRight := fun {_ _} f Y ↦ Limits.prod.map f (𝟙 _) tensorHom := fun f g ↦ Limits.prod.map f g tensorUnit := ⊤_ C associator := prod.associator leftUnitor := fun P ↦ prod.leftUnitor P rightUnitor := fun P ↦ prod.rightUnitor P } .ofTensorHom (pentagon := prod.pentagon) (triangle := prod.triangle) (associator_naturality := @prod.associator_naturality _ _ _) end namespace monoidalOfHasFiniteProducts variable [HasTerminal C] [HasBinaryProducts C] attribute [local instance] monoidalOfHasFiniteProducts open scoped MonoidalCategory @[ext] theorem unit_ext {X : C} (f g : X ⟶ 𝟙_ C) : f = g := terminal.hom_ext f g @[ext] theorem tensor_ext {X Y Z : C} (f g : X ⟶ Y ⊗ Z) (w₁ : f ≫ prod.fst = g ≫ prod.fst) (w₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g := prod.hom_ext w₁ w₂ @[simp] theorem tensorUnit : 𝟙_ C = ⊤_ C := rfl @[simp] theorem tensorObj (X Y : C) : X ⊗ Y = (X ⨯ Y) := rfl @[simp] theorem tensorHom {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : f ⊗ g = Limits.prod.map f g := rfl @[simp] theorem whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) : X ◁ f = Limits.prod.map (𝟙 X) f := rfl @[simp] theorem whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) : f ▷ Z = Limits.prod.map f (𝟙 Z) := rfl @[simp] theorem leftUnitor_hom (X : C) : (λ_ X).hom = Limits.prod.snd := rfl @[simp] theorem leftUnitor_inv (X : C) : (λ_ X).inv = prod.lift (terminal.from X) (𝟙 _) := rfl @[simp] theorem rightUnitor_hom (X : C) : (ρ_ X).hom = Limits.prod.fst := rfl @[simp] theorem rightUnitor_inv (X : C) : (ρ_ X).inv = prod.lift (𝟙 _) (terminal.from X) := rfl -- We don't mark this as a simp lemma, even though in many particular -- categories the right hand side will simplify significantly further. -- For now, we'll plan to create specialised simp lemmas in each particular category. theorem associator_hom (X Y Z : C) : (α_ X Y Z).hom = prod.lift (Limits.prod.fst ≫ Limits.prod.fst) (prod.lift (Limits.prod.fst ≫ Limits.prod.snd) Limits.prod.snd) := rfl theorem associator_inv (X Y Z : C) : (α_ X Y Z).inv = prod.lift (prod.lift prod.fst (prod.snd ≫ prod.fst)) (prod.snd ≫ prod.snd) := rfl @[reassoc] theorem associator_hom_fst (X Y Z : C) : (α_ X Y Z).hom ≫ prod.fst = prod.fst ≫ prod.fst := by simp [associator_hom] @[reassoc] theorem associator_hom_snd_fst (X Y Z : C) : (α_ X Y Z).hom ≫ prod.snd ≫ prod.fst = prod.fst ≫ prod.snd := by simp [associator_hom] @[reassoc] theorem associator_hom_snd_snd (X Y Z : C) : (α_ X Y Z).hom ≫ prod.snd ≫ prod.snd = prod.snd := by simp [associator_hom] @[reassoc] theorem associator_inv_fst_fst (X Y Z : C) : (α_ X Y Z).inv ≫ prod.fst ≫ prod.fst = prod.fst := by simp [associator_inv] @[reassoc] theorem associator_inv_fst_snd (X Y Z : C) : (α_ X Y Z).inv ≫ prod.fst ≫ prod.snd = prod.snd ≫ prod.fst := by simp [associator_inv] @[reassoc] theorem associator_inv_snd (X Y Z : C) : (α_ X Y Z).inv ≫ prod.snd = prod.snd ≫ prod.snd := by simp [associator_inv] end monoidalOfHasFiniteProducts section attribute [local instance] monoidalOfHasFiniteProducts open MonoidalCategory /-- The monoidal structure coming from finite products is symmetric. -/ @[simps] def symmetricOfHasFiniteProducts [HasTerminal C] [HasBinaryProducts C] : SymmetricCategory C where braiding X Y := Limits.prod.braiding X Y braiding_naturality_left f X := by simp braiding_naturality_right X _ _ f := by simp hexagon_forward X Y Z := by dsimp [monoidalOfHasFiniteProducts.associator_hom]; simp hexagon_reverse X Y Z := by dsimp [monoidalOfHasFiniteProducts.associator_inv]; simp symmetry X Y := by dsimp; simp end section /-- A category with an initial object and binary coproducts has a natural monoidal structure. -/ def monoidalOfHasFiniteCoproducts [HasInitial C] [HasBinaryCoproducts C] : MonoidalCategory C := letI : MonoidalCategoryStruct C := { tensorObj := fun X Y ↦ X ⨿ Y whiskerLeft := fun X _ _ g ↦ Limits.coprod.map (𝟙 _) g whiskerRight := fun {_ _} f Y ↦ Limits.coprod.map f (𝟙 _) tensorHom := fun f g ↦ Limits.coprod.map f g tensorUnit := ⊥_ C associator := coprod.associator leftUnitor := fun P ↦ coprod.leftUnitor P rightUnitor := fun P ↦ coprod.rightUnitor P } .ofTensorHom (pentagon := coprod.pentagon) (triangle := coprod.triangle) (associator_naturality := @coprod.associator_naturality _ _ _) end namespace monoidalOfHasFiniteCoproducts variable [HasInitial C] [HasBinaryCoproducts C] attribute [local instance] monoidalOfHasFiniteCoproducts open scoped MonoidalCategory @[simp] theorem tensorObj (X Y : C) : X ⊗ Y = (X ⨿ Y) := rfl @[simp] theorem tensorHom {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : f ⊗ g = Limits.coprod.map f g := rfl @[simp] theorem whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) : X ◁ f = Limits.coprod.map (𝟙 X) f := rfl @[simp] theorem whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) : f ▷ Z = Limits.coprod.map f (𝟙 Z) := rfl @[simp] theorem leftUnitor_hom (X : C) : (λ_ X).hom = coprod.desc (initial.to X) (𝟙 _) := rfl @[simp] theorem rightUnitor_hom (X : C) : (ρ_ X).hom = coprod.desc (𝟙 _) (initial.to X) := rfl @[simp] theorem leftUnitor_inv (X : C) : (λ_ X).inv = Limits.coprod.inr := rfl @[simp] theorem rightUnitor_inv (X : C) : (ρ_ X).inv = Limits.coprod.inl := rfl -- We don't mark this as a simp lemma, even though in many particular -- categories the right hand side will simplify significantly further. -- For now, we'll plan to create specialised simp lemmas in each particular category. theorem associator_hom (X Y Z : C) : (α_ X Y Z).hom = coprod.desc (coprod.desc coprod.inl (coprod.inl ≫ coprod.inr)) (coprod.inr ≫ coprod.inr) := rfl theorem associator_inv (X Y Z : C) : (α_ X Y Z).inv = coprod.desc (coprod.inl ≫ coprod.inl) (coprod.desc (coprod.inr ≫ coprod.inl) coprod.inr) := rfl end monoidalOfHasFiniteCoproducts section attribute [local instance] monoidalOfHasFiniteCoproducts open MonoidalCategory /-- The monoidal structure coming from finite coproducts is symmetric. -/ @[simps] def symmetricOfHasFiniteCoproducts [HasInitial C] [HasBinaryCoproducts C] : SymmetricCategory C where braiding := Limits.coprod.braiding braiding_naturality_left f g := by simp braiding_naturality_right f g := by simp hexagon_forward X Y Z := by dsimp [monoidalOfHasFiniteCoproducts.associator_hom]; simp hexagon_reverse X Y Z := by dsimp [monoidalOfHasFiniteCoproducts.associator_inv]; simp symmetry X Y := by dsimp; simp end section attribute [local instance] monoidalOfHasFiniteProducts variable {C} variable {D : Type*} [Category D] (F : C ⥤ D) [HasTerminal C] [HasBinaryProducts C] [HasTerminal D] [HasBinaryProducts D] [PreservesLimit (Functor.empty.{0} C) F] [PreservesLimitsOfShape (Discrete WalkingPair) F] /-- Promote a finite products preserving functor to a monoidal functor between categories equipped with the monoidal category structure given by finite products. -/ @[simps] def Functor.toMonoidalFunctorOfHasFiniteProducts : MonoidalFunctor C D where toFunctor := F ε := (asIso (terminalComparison F)).inv μ X Y := (asIso (prodComparison F X Y)).inv μ_natural_left {X Y} f X' := by simpa using (prodComparison_inv_natural F f (𝟙 X')).symm μ_natural_right {X Y} X' g := by simpa using (prodComparison_inv_natural F (𝟙 X') g).symm associativity X Y Z := by dsimp only [monoidalOfHasFiniteProducts.associator_hom] rw [← cancel_epi (prod.map (prodComparison F X Y) (𝟙 (F.obj Z)))] dsimp simp only [prod.map_map_assoc, IsIso.hom_inv_id, Category.comp_id, prod.map_id_id, Category.id_comp, prod.lift_map_assoc, IsIso.inv_comp_eq] rw [← cancel_mono (prodComparison F X (Y ⨯ Z))] simp only [Category.assoc, IsIso.inv_hom_id, Category.comp_id, prod.comp_lift, prod.map_fst_assoc, prodComparison_fst, prodComparison_fst_assoc] ext · simp [-Functor.map_comp, ← F.map_comp] · rw [← cancel_mono (prodComparison F Y Z)] ext all_goals simp [-Functor.map_comp, ← F.map_comp] left_unitality Y := by rw [← cancel_epi (prod.map (terminalComparison F) (𝟙 (F.obj Y)))] dsimp simp only [prod.map_map_assoc, IsIso.hom_inv_id, Category.comp_id, prod.map_id_id, Category.id_comp, IsIso.eq_inv_comp] erw [prod.map_snd, Category.comp_id, prodComparison_snd] right_unitality X := by rw [← cancel_epi (prod.map (𝟙 (F.obj X)) (terminalComparison F))] dsimp simp only [prod.map_map_assoc, Category.comp_id, IsIso.hom_inv_id, prod.map_id_id, Category.id_comp, IsIso.eq_inv_comp] erw [prod.map_fst, Category.comp_id, prodComparison_fst] instance [F.IsEquivalence] : F.toMonoidalFunctorOfHasFiniteProducts.IsEquivalence := by assumption end end CategoryTheory
CategoryTheory\Monoidal\Opposite.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Tactic.CategoryTheory.Coherence /-! # Monoidal opposites We write `Cᵐᵒᵖ` for the monoidal opposite of a monoidal category `C`. -/ universe v₁ v₂ u₁ u₂ variable {C : Type u₁} namespace CategoryTheory open CategoryTheory.MonoidalCategory /-- The type of objects of the opposite (or "reverse") monoidal category. Use the notation `Cᴹᵒᵖ`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. structure MonoidalOpposite (C : Type u₁) where /-- The object of `MonoidalOpposite C` that represents `x : C`. -/ mop :: /-- The object of `C` represented by `x : MonoidalOpposite C`. -/ unmop : C namespace MonoidalOpposite @[inherit_doc] notation:max C "ᴹᵒᵖ" => MonoidalOpposite C theorem mop_injective : Function.Injective (mop : C → Cᴹᵒᵖ) := @mop.inj C theorem unmop_injective : Function.Injective (unmop : Cᴹᵒᵖ → C) := fun _ _ h => congrArg mop h theorem mop_inj_iff (x y : C) : mop x = mop y ↔ x = y := mop_injective.eq_iff @[simp] theorem unmop_inj_iff (x y : Cᴹᵒᵖ) : unmop x = unmop y ↔ x = y := unmop_injective.eq_iff @[simp] theorem mop_unmop (X : Cᴹᵒᵖ) : mop (unmop X) = X := rfl -- can't be simp bc after putting the lhs in whnf it's `X = X` theorem unmop_mop (X : C) : unmop (mop X) = X := rfl instance monoidalOppositeCategory [Category.{v₁} C] : Category Cᴹᵒᵖ where Hom X Y := (unmop X ⟶ unmop Y)ᴹᵒᵖ id X := mop (𝟙 (unmop X)) comp f g := mop (unmop f ≫ unmop g) end MonoidalOpposite end CategoryTheory open CategoryTheory open CategoryTheory.MonoidalOpposite variable [Category.{v₁} C] /-- The monoidal opposite of a morphism `f : X ⟶ Y` is just `f`, thought of as `mop X ⟶ mop Y`. -/ def Quiver.Hom.mop {X Y : C} (f : X ⟶ Y) : mop X ⟶ mop Y := MonoidalOpposite.mop f /-- We can think of a morphism `f : mop X ⟶ mop Y` as a morphism `X ⟶ Y`. -/ def Quiver.Hom.unmop {X Y : Cᴹᵒᵖ} (f : X ⟶ Y) : unmop X ⟶ unmop Y := MonoidalOpposite.unmop f namespace Quiver.Hom open MonoidalOpposite renaming mop → mop', unmop → unmop' theorem mop_inj {X Y : C} : Function.Injective (Quiver.Hom.mop : (X ⟶ Y) → (mop' X ⟶ mop' Y)) := fun _ _ H => congr_arg Quiver.Hom.unmop H theorem unmop_inj {X Y : Cᴹᵒᵖ} : Function.Injective (Quiver.Hom.unmop : (X ⟶ Y) → (unmop' X ⟶ unmop' Y)) := fun _ _ H => congr_arg Quiver.Hom.mop H @[simp] theorem unmop_mop {X Y : C} {f : X ⟶ Y} : f.mop.unmop = f := rfl @[simp] theorem mop_unmop {X Y : Cᴹᵒᵖ} {f : X ⟶ Y} : f.unmop.mop = f := rfl end Quiver.Hom namespace CategoryTheory @[simp] theorem mop_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).mop = f.mop ≫ g.mop := rfl @[simp] theorem mop_id {X : C} : (𝟙 X).mop = 𝟙 (mop X) := rfl @[simp] theorem unmop_comp {X Y Z : Cᴹᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).unmop = f.unmop ≫ g.unmop := rfl @[simp] theorem unmop_id {X : Cᴹᵒᵖ} : (𝟙 X).unmop = 𝟙 (unmop X) := rfl @[simp] theorem unmop_id_mop {X : C} : (𝟙 (mop X)).unmop = 𝟙 X := rfl @[simp] theorem mop_id_unmop {X : Cᴹᵒᵖ} : (𝟙 (unmop X)).mop = 𝟙 X := rfl variable (C) /-- The identity functor on `C`, viewed as a functor from `C` to its monoidal opposite. -/ @[simps obj map] -- need to specify `obj, map` or else we generate `mopFunctor_obj_unmop` def mopFunctor : C ⥤ Cᴹᵒᵖ := Functor.mk ⟨mop, .mop⟩ /-- The identity functor on `C`, viewed as a functor from the monoidal opposite of `C` to `C`. -/ @[simps obj map] -- not necessary but the symmetry with `mopFunctor` looks nicer def unmopFunctor : Cᴹᵒᵖ ⥤ C := Functor.mk ⟨unmop, .unmop⟩ variable {C} namespace Iso /-- An isomorphism in `C` gives an isomorphism in `Cᴹᵒᵖ`. -/ abbrev mop {X Y : C} (f : X ≅ Y) : mop X ≅ mop Y := (mopFunctor C).mapIso f /-- An isomorphism in `Cᴹᵒᵖ` gives an isomorphism in `C`. -/ abbrev unmop {X Y : Cᴹᵒᵖ} (f : X ≅ Y) : unmop X ≅ unmop Y := (unmopFunctor C).mapIso f end Iso namespace IsIso instance {X Y : C} (f : X ⟶ Y) [IsIso f] : IsIso f.mop := (mopFunctor C).map_isIso f instance {X Y : Cᴹᵒᵖ} (f : X ⟶ Y) [IsIso f] : IsIso f.unmop := (unmopFunctor C).map_isIso f end IsIso variable [MonoidalCategory.{v₁} C] open Opposite MonoidalCategory instance monoidalCategoryOp : MonoidalCategory Cᵒᵖ where tensorObj X Y := op (unop X ⊗ unop Y) whiskerLeft X _ _ f := (X.unop ◁ f.unop).op whiskerRight f X := (f.unop ▷ X.unop).op tensorHom f g := (f.unop ⊗ g.unop).op tensorHom_def f g := Quiver.Hom.unop_inj (tensorHom_def' _ _) tensorUnit := op (𝟙_ C) associator X Y Z := (α_ (unop X) (unop Y) (unop Z)).symm.op leftUnitor X := (λ_ (unop X)).symm.op rightUnitor X := (ρ_ (unop X)).symm.op associator_naturality f g h := Quiver.Hom.unop_inj <| by simp leftUnitor_naturality f := Quiver.Hom.unop_inj <| by simp rightUnitor_naturality f := Quiver.Hom.unop_inj <| by simp triangle X Y := Quiver.Hom.unop_inj <| by dsimp; coherence pentagon W X Y Z := Quiver.Hom.unop_inj <| by dsimp; coherence section OppositeLemmas @[simp] lemma op_tensorObj (X Y : C) : op (X ⊗ Y) = op X ⊗ op Y := rfl @[simp] lemma unop_tensorObj (X Y : Cᵒᵖ) : unop (X ⊗ Y) = unop X ⊗ unop Y := rfl @[simp] lemma op_tensorUnit : op (𝟙_ C) = 𝟙_ Cᵒᵖ := rfl @[simp] lemma unop_tensorUnit : unop (𝟙_ Cᵒᵖ) = 𝟙_ C := rfl @[simp] lemma op_tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (f ⊗ g).op = f.op ⊗ g.op := rfl @[simp] lemma unop_tensorHom {X₁ Y₁ X₂ Y₂ : Cᵒᵖ} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (f ⊗ g).unop = f.unop ⊗ g.unop := rfl @[simp] lemma op_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) : (X ◁ f).op = op X ◁ f.op := rfl @[simp] lemma unop_whiskerLeft (X : Cᵒᵖ) {Y Z : Cᵒᵖ} (f : Y ⟶ Z) : (X ◁ f).unop = unop X ◁ f.unop := rfl @[simp] lemma op_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) : (f ▷ Z).op = f.op ▷ op Z := rfl @[simp] lemma unop_whiskerRight {X Y : Cᵒᵖ} (f : X ⟶ Y) (Z : Cᵒᵖ) : (f ▷ Z).unop = f.unop ▷ unop Z := rfl @[simp] lemma op_associator (X Y Z : C) : (α_ X Y Z).op = (α_ (op X) (op Y) (op Z)).symm := rfl @[simp] lemma unop_associator (X Y Z : Cᵒᵖ) : (α_ X Y Z).unop = (α_ (unop X) (unop Y) (unop Z)).symm := rfl @[simp] lemma op_hom_associator (X Y Z : C) : (α_ X Y Z).hom.op = (α_ (op X) (op Y) (op Z)).inv := rfl @[simp] lemma unop_hom_associator (X Y Z : Cᵒᵖ) : (α_ X Y Z).hom.unop = (α_ (unop X) (unop Y) (unop Z)).inv := rfl @[simp] lemma op_inv_associator (X Y Z : C) : (α_ X Y Z).inv.op = (α_ (op X) (op Y) (op Z)).hom := rfl @[simp] lemma unop_inv_associator (X Y Z : Cᵒᵖ) : (α_ X Y Z).inv.unop = (α_ (unop X) (unop Y) (unop Z)).hom := rfl @[simp] lemma op_leftUnitor (X : C) : (λ_ X).op = (λ_ (op X)).symm := rfl @[simp] lemma unop_leftUnitor (X : Cᵒᵖ) : (λ_ X).unop = (λ_ (unop X)).symm := rfl @[simp] lemma op_hom_leftUnitor (X : C) : (λ_ X).hom.op = (λ_ (op X)).inv := rfl @[simp] lemma unop_hom_leftUnitor (X : Cᵒᵖ) : (λ_ X).hom.unop = (λ_ (unop X)).inv := rfl @[simp] lemma op_inv_leftUnitor (X : C) : (λ_ X).inv.op = (λ_ (op X)).hom := rfl @[simp] lemma unop_inv_leftUnitor (X : Cᵒᵖ) : (λ_ X).inv.unop = (λ_ (unop X)).hom := rfl @[simp] lemma op_rightUnitor (X : C) : (ρ_ X).op = (ρ_ (op X)).symm := rfl @[simp] lemma unop_rightUnitor (X : Cᵒᵖ) : (ρ_ X).unop = (ρ_ (unop X)).symm := rfl @[simp] lemma op_hom_rightUnitor (X : C) : (ρ_ X).hom.op = (ρ_ (op X)).inv := rfl @[simp] lemma unop_hom_rightUnitor (X : Cᵒᵖ) : (ρ_ X).hom.unop = (ρ_ (unop X)).inv := rfl @[simp] lemma op_inv_rightUnitor (X : C) : (ρ_ X).inv.op = (ρ_ (op X)).hom := rfl @[simp] lemma unop_inv_rightUnitor (X : Cᵒᵖ) : (ρ_ X).inv.unop = (ρ_ (unop X)).hom := rfl end OppositeLemmas theorem op_tensor_op {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : f.op ⊗ g.op = (f ⊗ g).op := rfl theorem unop_tensor_unop {W X Y Z : Cᵒᵖ} (f : W ⟶ X) (g : Y ⟶ Z) : f.unop ⊗ g.unop = (f ⊗ g).unop := rfl instance monoidalCategoryMop : MonoidalCategory Cᴹᵒᵖ where tensorObj X Y := mop (unmop Y ⊗ unmop X) whiskerLeft X _ _ f := (f.unmop ▷ X.unmop).mop whiskerRight f X := (X.unmop ◁ f.unmop).mop tensorHom f g := (g.unmop ⊗ f.unmop).mop tensorHom_def f g := Quiver.Hom.unmop_inj (tensorHom_def' _ _) tensorUnit := mop (𝟙_ C) associator X Y Z := (α_ (unmop Z) (unmop Y) (unmop X)).symm.mop leftUnitor X := (ρ_ (unmop X)).mop rightUnitor X := (λ_ (unmop X)).mop associator_naturality f g h := Quiver.Hom.unmop_inj <| by simp leftUnitor_naturality f := Quiver.Hom.unmop_inj <| by simp rightUnitor_naturality f := Quiver.Hom.unmop_inj <| by simp -- Porting note: Changed `by coherence` to `by simp` below triangle X Y := Quiver.Hom.unmop_inj <| by simp pentagon W X Y Z := Quiver.Hom.unmop_inj <| by dsimp; coherence -- it would be nice if we could autogenerate all of these somehow section MonoidalOppositeLemmas @[simp] lemma mop_tensorObj (X Y : C) : mop (X ⊗ Y) = mop Y ⊗ mop X := rfl @[simp] lemma unmop_tensorObj (X Y : Cᴹᵒᵖ) : unmop (X ⊗ Y) = unmop Y ⊗ unmop X := rfl @[simp] lemma mop_tensorUnit : mop (𝟙_ C) = 𝟙_ Cᴹᵒᵖ := rfl @[simp] lemma unmop_tensorUnit : unmop (𝟙_ Cᴹᵒᵖ) = 𝟙_ C := rfl @[simp] lemma mop_tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (f ⊗ g).mop = g.mop ⊗ f.mop := rfl @[simp] lemma unmop_tensorHom {X₁ Y₁ X₂ Y₂ : Cᴹᵒᵖ} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (f ⊗ g).unmop = g.unmop ⊗ f.unmop := rfl @[simp] lemma mop_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) : (X ◁ f).mop = f.mop ▷ mop X := rfl @[simp] lemma unmop_whiskerLeft (X : Cᴹᵒᵖ) {Y Z : Cᴹᵒᵖ} (f : Y ⟶ Z) : (X ◁ f).unmop = f.unmop ▷ unmop X := rfl @[simp] lemma mop_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) : (f ▷ Z).mop = mop Z ◁ f.mop := rfl @[simp] lemma unmop_whiskerRight {X Y : Cᴹᵒᵖ} (f : X ⟶ Y) (Z : Cᴹᵒᵖ) : (f ▷ Z).unmop = unmop Z ◁ f.unmop := rfl @[simp] lemma mop_associator (X Y Z : C) : (α_ X Y Z).mop = (α_ (mop Z) (mop Y) (mop X)).symm := rfl @[simp] lemma unmop_associator (X Y Z : Cᴹᵒᵖ) : (α_ X Y Z).unmop = (α_ (unmop Z) (unmop Y) (unmop X)).symm := rfl @[simp] lemma mop_hom_associator (X Y Z : C) : (α_ X Y Z).hom.mop = (α_ (mop Z) (mop Y) (mop X)).inv := rfl @[simp] lemma unmop_hom_associator (X Y Z : Cᴹᵒᵖ) : (α_ X Y Z).hom.unmop = (α_ (unmop Z) (unmop Y) (unmop X)).inv := rfl @[simp] lemma mop_inv_associator (X Y Z : C) : (α_ X Y Z).inv.mop = (α_ (mop Z) (mop Y) (mop X)).hom := rfl @[simp] lemma unmop_inv_associator (X Y Z : Cᴹᵒᵖ) : (α_ X Y Z).inv.unmop = (α_ (unmop Z) (unmop Y) (unmop X)).hom := rfl @[simp] lemma mop_leftUnitor (X : C) : (λ_ X).mop = (ρ_ (mop X)) := rfl @[simp] lemma unmop_leftUnitor (X : Cᴹᵒᵖ) : (λ_ X).unmop = ρ_ (unmop X) := rfl @[simp] lemma mop_hom_leftUnitor (X : C) : (λ_ X).hom.mop = (ρ_ (mop X)).hom := rfl @[simp] lemma unmop_hom_leftUnitor (X : Cᴹᵒᵖ) : (λ_ X).hom.unmop = (ρ_ (unmop X)).hom := rfl @[simp] lemma mop_inv_leftUnitor (X : C) : (λ_ X).inv.mop = (ρ_ (mop X)).inv := rfl @[simp] lemma unmop_inv_leftUnitor (X : Cᴹᵒᵖ) : (λ_ X).inv.unmop = (ρ_ (unmop X)).inv := rfl @[simp] lemma mop_rightUnitor (X : C) : (ρ_ X).mop = (λ_ (mop X)) := rfl @[simp] lemma unmop_rightUnitor (X : Cᴹᵒᵖ) : (ρ_ X).unmop = λ_ (unmop X) := rfl @[simp] lemma mop_hom_rightUnitor (X : C) : (ρ_ X).hom.mop = (λ_ (mop X)).hom := rfl @[simp] lemma unmop_hom_rightUnitor (X : Cᴹᵒᵖ) : (ρ_ X).hom.unmop = (λ_ (unmop X)).hom := rfl @[simp] lemma mop_inv_rightUnitor (X : C) : (ρ_ X).inv.mop = (λ_ (mop X)).inv := rfl @[simp] lemma unmop_inv_rightUnitor (X : Cᴹᵒᵖ) : (ρ_ X).inv.unmop = (λ_ (unmop X)).inv := rfl end MonoidalOppositeLemmas variable (C) /-- The (identity) equivalence between `C` and its monoidal opposite. -/ @[simps] def MonoidalOpposite.mopEquiv : C ≌ Cᴹᵒᵖ where functor := mopFunctor C inverse := unmopFunctor C unitIso := Iso.refl _ counitIso := Iso.refl _ /-- The (identity) equivalence between `Cᴹᵒᵖ` and `C`. -/ @[simps!] def MonoidalOpposite.unmopEquiv : Cᴹᵒᵖ ≌ C := (mopEquiv C).symm -- todo: upgrade to monoidal equivalence /-- The equivalence between `C` and its monoidal opposite's monoidal opposite. -/ @[simps!] def MonoidalOpposite.mopMopEquivalence : Cᴹᵒᵖᴹᵒᵖ ≌ C := .trans (MonoidalOpposite.unmopEquiv Cᴹᵒᵖ) (MonoidalOpposite.unmopEquiv C) /-- The identification `mop X ⊗ mop Y = mop (Y ⊗ X)` as a natural isomorphism. -/ @[simps!] def MonoidalOpposite.tensorIso : tensor Cᴹᵒᵖ ≅ (unmopFunctor C).prod (unmopFunctor C) ⋙ Prod.swap C C ⋙ tensor C ⋙ mopFunctor C := Iso.refl _ variable {C} /-- The identification `X ⊗ - = mop (- ⊗ unmop X)` as a natural isomorphism. -/ @[simps!] def MonoidalOpposite.tensorLeftIso (X : Cᴹᵒᵖ) : tensorLeft X ≅ unmopFunctor C ⋙ tensorRight (unmop X) ⋙ mopFunctor C := Iso.refl _ /-- The identification `mop X ⊗ - = mop (- ⊗ X)` as a natural isomorphism. -/ @[simps!] def MonoidalOpposite.tensorLeftMopIso (X : C) : tensorLeft (mop X) ≅ unmopFunctor C ⋙ tensorRight X ⋙ mopFunctor C := Iso.refl _ /-- The identification `unmop X ⊗ - = unmop (mop - ⊗ X)` as a natural isomorphism. -/ @[simps!] def MonoidalOpposite.tensorLeftUnmopIso (X : Cᴹᵒᵖ) : tensorLeft (unmop X) ≅ mopFunctor C ⋙ tensorRight X ⋙ unmopFunctor C := Iso.refl _ /-- The identification `- ⊗ X = mop (unmop X ⊗ -)` as a natural isomorphism. -/ @[simps!] def MonoidalOpposite.tensorRightIso (X : Cᴹᵒᵖ) : tensorRight X ≅ unmopFunctor C ⋙ tensorLeft (unmop X) ⋙ mopFunctor C := Iso.refl _ /-- The identification `- ⊗ mop X = mop (- ⊗ unmop X)` as a natural isomorphism. -/ @[simps!] def MonoidalOpposite.tensorRightMopIso (X : C) : tensorRight (mop X) ≅ unmopFunctor C ⋙ tensorLeft X ⋙ mopFunctor C := Iso.refl _ /-- The identification `- ⊗ unmop X = unmop (X ⊗ mop -)` as a natural isomorphism. -/ @[simps!] def MonoidalOpposite.tensorRightUnmopIso (X : Cᴹᵒᵖ) : tensorRight (unmop X) ≅ mopFunctor C ⋙ tensorLeft X ⋙ unmopFunctor C := Iso.refl _ end CategoryTheory
CategoryTheory\Monoidal\Preadditive.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Monoidal.Functor /-! # Preadditive monoidal categories A monoidal category is `MonoidalPreadditive` if it is preadditive and tensor product of morphisms is linear in both factors. -/ noncomputable section open scoped Classical namespace CategoryTheory open CategoryTheory.Limits open CategoryTheory.MonoidalCategory variable (C : Type*) [Category C] [Preadditive C] [MonoidalCategory C] /-- A category is `MonoidalPreadditive` if tensoring is additive in both factors. Note we don't `extend Preadditive C` here, as `Abelian C` already extends it, and we'll need to have both typeclasses sometimes. -/ class MonoidalPreadditive : Prop where whiskerLeft_zero : ∀ {X Y Z : C}, X ◁ (0 : Y ⟶ Z) = 0 := by aesop_cat zero_whiskerRight : ∀ {X Y Z : C}, (0 : Y ⟶ Z) ▷ X = 0 := by aesop_cat whiskerLeft_add : ∀ {X Y Z : C} (f g : Y ⟶ Z), X ◁ (f + g) = X ◁ f + X ◁ g := by aesop_cat add_whiskerRight : ∀ {X Y Z : C} (f g : Y ⟶ Z), (f + g) ▷ X = f ▷ X + g ▷ X := by aesop_cat attribute [simp] MonoidalPreadditive.whiskerLeft_zero MonoidalPreadditive.zero_whiskerRight attribute [simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight variable {C} variable [MonoidalPreadditive C] namespace MonoidalPreadditive -- The priority setting will not be needed when we replace `𝟙 X ⊗ f` by `X ◁ f`. @[simp (low)] theorem tensor_zero {W X Y Z : C} (f : W ⟶ X) : f ⊗ (0 : Y ⟶ Z) = 0 := by simp [tensorHom_def] -- The priority setting will not be needed when we replace `f ⊗ 𝟙 X` by `f ▷ X`. @[simp (low)] theorem zero_tensor {W X Y Z : C} (f : Y ⟶ Z) : (0 : W ⟶ X) ⊗ f = 0 := by simp [tensorHom_def] theorem tensor_add {W X Y Z : C} (f : W ⟶ X) (g h : Y ⟶ Z) : f ⊗ (g + h) = f ⊗ g + f ⊗ h := by simp [tensorHom_def] theorem add_tensor {W X Y Z : C} (f g : W ⟶ X) (h : Y ⟶ Z) : (f + g) ⊗ h = f ⊗ h + g ⊗ h := by simp [tensorHom_def] end MonoidalPreadditive instance tensorLeft_additive (X : C) : (tensorLeft X).Additive where instance tensorRight_additive (X : C) : (tensorRight X).Additive where instance tensoringLeft_additive (X : C) : ((tensoringLeft C).obj X).Additive where instance tensoringRight_additive (X : C) : ((tensoringRight C).obj X).Additive where /-- A faithful additive monoidal functor to a monoidal preadditive category ensures that the domain is monoidal preadditive. -/ theorem monoidalPreadditive_of_faithful {D} [Category D] [Preadditive D] [MonoidalCategory D] (F : MonoidalFunctor D C) [F.Faithful] [F.Additive] : MonoidalPreadditive D := { whiskerLeft_zero := by intros apply F.toFunctor.map_injective simp [F.map_whiskerLeft] zero_whiskerRight := by intros apply F.toFunctor.map_injective simp [F.map_whiskerRight] whiskerLeft_add := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerLeft, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.whiskerLeft_add] add_whiskerRight := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerRight, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.add_whiskerRight] } theorem whiskerLeft_sum (P : C) {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) : P ◁ ∑ j ∈ s, g j = ∑ j ∈ s, P ◁ g j := map_sum ((tensoringLeft C).obj P).mapAddHom g s theorem sum_whiskerRight {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) (P : C) : (∑ j ∈ s, g j) ▷ P = ∑ j ∈ s, g j ▷ P := map_sum ((tensoringRight C).obj P).mapAddHom g s theorem tensor_sum {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (f ⊗ ∑ j ∈ s, g j) = ∑ j ∈ s, f ⊗ g j := by simp only [tensorHom_def, whiskerLeft_sum, Preadditive.comp_sum] theorem sum_tensor {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (∑ j ∈ s, g j) ⊗ f = ∑ j ∈ s, g j ⊗ f := by simp only [tensorHom_def, sum_whiskerRight, Preadditive.sum_comp] -- In a closed monoidal category, this would hold because -- `tensorLeft X` is a left adjoint and hence preserves all colimits. -- In any case it is true in any preadditive category. instance (X : C) : PreservesFiniteBiproducts (tensorLeft X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← id_tensorHom] simp only [← tensor_comp, Category.comp_id, ← tensor_sum, ← tensor_id, IsBilimit.total i]) } } instance (X : C) : PreservesFiniteBiproducts (tensorRight X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← tensorHom_id] simp only [← tensor_comp, Category.comp_id, ← sum_tensor, ← tensor_id, IsBilimit.total i]) } } variable [HasFiniteBiproducts C] /-- The isomorphism showing how tensor product on the left distributes over direct sums. -/ def leftDistributor {J : Type} [Fintype J] (X : C) (f : J → C) : X ⊗ ⨁ f ≅ ⨁ fun j => X ⊗ f j := (tensorLeft X).mapBiproduct f theorem leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) : (leftDistributor X f).hom = ∑ j : J, (X ◁ biproduct.π f j) ≫ biproduct.ι (fun j => X ⊗ f j) j := by ext dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone] erw [biproduct.lift_π] simp only [Preadditive.sum_comp, Category.assoc, biproduct.ι_π, comp_dite, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, ite_true, eqToHom_refl, Category.comp_id] theorem leftDistributor_inv {J : Type} [Fintype J] (X : C) (f : J → C) : (leftDistributor X f).inv = ∑ j : J, biproduct.π _ j ≫ (X ◁ biproduct.ι f j) := by ext dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone] simp only [Preadditive.comp_sum, biproduct.ι_π_assoc, dite_comp, zero_comp, Finset.sum_dite_eq, Finset.mem_univ, ite_true, eqToHom_refl, Category.id_comp, biproduct.ι_desc] @[reassoc (attr := simp)] theorem leftDistributor_hom_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (leftDistributor X f).hom ≫ biproduct.π _ j = X ◁ biproduct.π _ j := by simp [leftDistributor_hom, Preadditive.sum_comp, biproduct.ι_π, comp_dite] @[reassoc (attr := simp)] theorem biproduct_ι_comp_leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (X ◁ biproduct.ι _ j) ≫ (leftDistributor X f).hom = biproduct.ι (fun j => X ⊗ f j) j := by simp [leftDistributor_hom, Preadditive.comp_sum, ← MonoidalCategory.whiskerLeft_comp_assoc, biproduct.ι_π, whiskerLeft_dite, dite_comp] @[reassoc (attr := simp)] theorem leftDistributor_inv_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (leftDistributor X f).inv ≫ (X ◁ biproduct.π _ j) = biproduct.π _ j := by simp [leftDistributor_inv, Preadditive.sum_comp, ← MonoidalCategory.whiskerLeft_comp, biproduct.ι_π, whiskerLeft_dite, comp_dite] @[reassoc (attr := simp)] theorem biproduct_ι_comp_leftDistributor_inv {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : biproduct.ι _ j ≫ (leftDistributor X f).inv = X ◁ biproduct.ι _ j := by simp [leftDistributor_inv, Preadditive.comp_sum, ← id_tensor_comp, biproduct.ι_π_assoc, dite_comp] theorem leftDistributor_assoc {J : Type} [Fintype J] (X Y : C) (f : J → C) : (asIso (𝟙 X) ⊗ leftDistributor Y f) ≪≫ leftDistributor X _ = (α_ X Y (⨁ f)).symm ≪≫ leftDistributor (X ⊗ Y) f ≪≫ biproduct.mapIso fun j => α_ X Y _ := by ext simp only [Category.comp_id, Category.assoc, eqToHom_refl, Iso.trans_hom, Iso.symm_hom, asIso_hom, comp_zero, comp_dite, Preadditive.sum_comp, Preadditive.comp_sum, tensor_sum, id_tensor_comp, tensorIso_hom, leftDistributor_hom, biproduct.mapIso_hom, biproduct.ι_map, biproduct.ι_π, Finset.sum_dite_irrel, Finset.sum_dite_eq', Finset.sum_const_zero] simp_rw [← id_tensorHom] simp only [← id_tensor_comp, biproduct.ι_π] simp only [id_tensor_comp, tensor_dite, comp_dite] simp /-- The isomorphism showing how tensor product on the right distributes over direct sums. -/ def rightDistributor {J : Type} [Fintype J] (f : J → C) (X : C) : (⨁ f) ⊗ X ≅ ⨁ fun j => f j ⊗ X := (tensorRight X).mapBiproduct f theorem rightDistributor_hom {J : Type} [Fintype J] (f : J → C) (X : C) : (rightDistributor f X).hom = ∑ j : J, (biproduct.π f j ▷ X) ≫ biproduct.ι (fun j => f j ⊗ X) j := by ext dsimp [rightDistributor, Functor.mapBiproduct, Functor.mapBicone] erw [biproduct.lift_π] simp only [Preadditive.sum_comp, Category.assoc, biproduct.ι_π, comp_dite, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, ite_true] theorem rightDistributor_inv {J : Type} [Fintype J] (f : J → C) (X : C) : (rightDistributor f X).inv = ∑ j : J, biproduct.π _ j ≫ (biproduct.ι f j ▷ X) := by ext dsimp [rightDistributor, Functor.mapBiproduct, Functor.mapBicone] simp only [biproduct.ι_desc, Preadditive.comp_sum, ne_eq, biproduct.ι_π_assoc, dite_comp, zero_comp, Finset.sum_dite_eq, Finset.mem_univ, eqToHom_refl, Category.id_comp, ite_true] @[reassoc (attr := simp)] theorem rightDistributor_hom_comp_biproduct_π {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) : (rightDistributor f X).hom ≫ biproduct.π _ j = biproduct.π _ j ▷ X := by simp [rightDistributor_hom, Preadditive.sum_comp, biproduct.ι_π, comp_dite] @[reassoc (attr := simp)] theorem biproduct_ι_comp_rightDistributor_hom {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) : (biproduct.ι _ j ▷ X) ≫ (rightDistributor f X).hom = biproduct.ι (fun j => f j ⊗ X) j := by simp [rightDistributor_hom, Preadditive.comp_sum, ← comp_whiskerRight_assoc, biproduct.ι_π, dite_whiskerRight, dite_comp] @[reassoc (attr := simp)] theorem rightDistributor_inv_comp_biproduct_π {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) : (rightDistributor f X).inv ≫ (biproduct.π _ j ▷ X) = biproduct.π _ j := by simp [rightDistributor_inv, Preadditive.sum_comp, ← MonoidalCategory.comp_whiskerRight, biproduct.ι_π, dite_whiskerRight, comp_dite] @[reassoc (attr := simp)] theorem biproduct_ι_comp_rightDistributor_inv {J : Type} [Fintype J] (f : J → C) (X : C) (j : J) : biproduct.ι _ j ≫ (rightDistributor f X).inv = biproduct.ι _ j ▷ X := by simp [rightDistributor_inv, Preadditive.comp_sum, ← id_tensor_comp, biproduct.ι_π_assoc, dite_comp] theorem rightDistributor_assoc {J : Type} [Fintype J] (f : J → C) (X Y : C) : (rightDistributor f X ⊗ asIso (𝟙 Y)) ≪≫ rightDistributor _ Y = α_ (⨁ f) X Y ≪≫ rightDistributor f (X ⊗ Y) ≪≫ biproduct.mapIso fun j => (α_ _ X Y).symm := by ext simp only [Category.comp_id, Category.assoc, eqToHom_refl, Iso.symm_hom, Iso.trans_hom, asIso_hom, comp_zero, comp_dite, Preadditive.sum_comp, Preadditive.comp_sum, sum_tensor, comp_tensor_id, tensorIso_hom, rightDistributor_hom, biproduct.mapIso_hom, biproduct.ι_map, biproduct.ι_π, Finset.sum_dite_irrel, Finset.sum_dite_eq', Finset.sum_const_zero, Finset.mem_univ, if_true] simp_rw [← tensorHom_id] simp only [← comp_tensor_id, biproduct.ι_π, dite_tensor, comp_dite] simp theorem leftDistributor_rightDistributor_assoc {J : Type _} [Fintype J] (X : C) (f : J → C) (Y : C) : (leftDistributor X f ⊗ asIso (𝟙 Y)) ≪≫ rightDistributor _ Y = α_ X (⨁ f) Y ≪≫ (asIso (𝟙 X) ⊗ rightDistributor _ Y) ≪≫ leftDistributor X _ ≪≫ biproduct.mapIso fun j => (α_ _ _ _).symm := by ext simp only [Category.comp_id, Category.assoc, eqToHom_refl, Iso.symm_hom, Iso.trans_hom, asIso_hom, comp_zero, comp_dite, Preadditive.sum_comp, Preadditive.comp_sum, sum_tensor, tensor_sum, comp_tensor_id, tensorIso_hom, leftDistributor_hom, rightDistributor_hom, biproduct.mapIso_hom, biproduct.ι_map, biproduct.ι_π, Finset.sum_dite_irrel, Finset.sum_dite_eq', Finset.sum_const_zero, Finset.mem_univ, if_true] simp_rw [← tensorHom_id, ← id_tensorHom] simp only [← comp_tensor_id, ← id_tensor_comp_assoc, Category.assoc, biproduct.ι_π, comp_dite, dite_comp, tensor_dite, dite_tensor] simp @[ext] theorem leftDistributor_ext_left {J : Type} [Fintype J] {X Y : C} {f : J → C} {g h : X ⊗ ⨁ f ⟶ Y} (w : ∀ j, (X ◁ biproduct.ι f j) ≫ g = (X ◁ biproduct.ι f j) ≫ h) : g = h := by apply (cancel_epi (leftDistributor X f).inv).mp ext simp? [leftDistributor_inv, Preadditive.comp_sum_assoc, biproduct.ι_π_assoc, dite_comp] says simp only [leftDistributor_inv, Preadditive.comp_sum_assoc, biproduct.ι_π_assoc, dite_comp, zero_comp, Finset.sum_dite_eq, Finset.mem_univ, ↓reduceIte, eqToHom_refl, Category.id_comp] apply w @[ext] theorem leftDistributor_ext_right {J : Type} [Fintype J] {X Y : C} {f : J → C} {g h : X ⟶ Y ⊗ ⨁ f} (w : ∀ j, g ≫ (Y ◁ biproduct.π f j) = h ≫ (Y ◁ biproduct.π f j)) : g = h := by apply (cancel_mono (leftDistributor Y f).hom).mp ext simp? [leftDistributor_hom, Preadditive.sum_comp, Preadditive.comp_sum_assoc, biproduct.ι_π, comp_dite] says simp only [leftDistributor_hom, Category.assoc, Preadditive.sum_comp, biproduct.ι_π, comp_dite, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, ↓reduceIte, eqToHom_refl, Category.comp_id] apply w -- One might wonder how many iterated tensor products we need simp lemmas for. -- The answer is two: this lemma is needed to verify the pentagon identity. @[ext] theorem leftDistributor_ext₂_left {J : Type} [Fintype J] {X Y Z : C} {f : J → C} {g h : X ⊗ (Y ⊗ ⨁ f) ⟶ Z} (w : ∀ j, (X ◁ (Y ◁ biproduct.ι f j)) ≫ g = (X ◁ (Y ◁ biproduct.ι f j)) ≫ h) : g = h := by apply (cancel_epi (α_ _ _ _).hom).mp ext simp [w] @[ext] theorem leftDistributor_ext₂_right {J : Type} [Fintype J] {X Y Z : C} {f : J → C} {g h : X ⟶ Y ⊗ (Z ⊗ ⨁ f)} (w : ∀ j, g ≫ (Y ◁ (Z ◁ biproduct.π f j)) = h ≫ (Y ◁ (Z ◁ biproduct.π f j))) : g = h := by apply (cancel_mono (α_ _ _ _).inv).mp ext simp [w] @[ext] theorem rightDistributor_ext_left {J : Type} [Fintype J] {f : J → C} {X Y : C} {g h : (⨁ f) ⊗ X ⟶ Y} (w : ∀ j, (biproduct.ι f j ▷ X) ≫ g = (biproduct.ι f j ▷ X) ≫ h) : g = h := by apply (cancel_epi (rightDistributor f X).inv).mp ext simp? [rightDistributor_inv, Preadditive.comp_sum_assoc, biproduct.ι_π_assoc, dite_comp] says simp only [rightDistributor_inv, Preadditive.comp_sum_assoc, biproduct.ι_π_assoc, dite_comp, zero_comp, Finset.sum_dite_eq, Finset.mem_univ, ↓reduceIte, eqToHom_refl, Category.id_comp] apply w @[ext] theorem rightDistributor_ext_right {J : Type} [Fintype J] {f : J → C} {X Y : C} {g h : X ⟶ (⨁ f) ⊗ Y} (w : ∀ j, g ≫ (biproduct.π f j ▷ Y) = h ≫ (biproduct.π f j ▷ Y)) : g = h := by apply (cancel_mono (rightDistributor f Y).hom).mp ext simp? [rightDistributor_hom, Preadditive.sum_comp, Preadditive.comp_sum_assoc, biproduct.ι_π, comp_dite] says simp only [rightDistributor_hom, Category.assoc, Preadditive.sum_comp, biproduct.ι_π, comp_dite, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, ↓reduceIte, eqToHom_refl, Category.comp_id] apply w @[ext] theorem rightDistributor_ext₂_left {J : Type} [Fintype J] {f : J → C} {X Y Z : C} {g h : ((⨁ f) ⊗ X) ⊗ Y ⟶ Z} (w : ∀ j, ((biproduct.ι f j ▷ X) ▷ Y) ≫ g = ((biproduct.ι f j ▷ X) ▷ Y) ≫ h) : g = h := by apply (cancel_epi (α_ _ _ _).inv).mp ext simp [w] @[ext] theorem rightDistributor_ext₂_right {J : Type} [Fintype J] {f : J → C} {X Y Z : C} {g h : X ⟶ ((⨁ f) ⊗ Y) ⊗ Z} (w : ∀ j, g ≫ ((biproduct.π f j ▷ Y) ▷ Z) = h ≫ ((biproduct.π f j ▷ Y) ▷ Z)) : g = h := by apply (cancel_mono (α_ _ _ _).hom).mp ext simp [w] end CategoryTheory
CategoryTheory\Monoidal\Skeleton.lean
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.Transport import Mathlib.CategoryTheory.Skeletal /-! # The monoid on the skeleton of a monoidal category The skeleton of a monoidal category is a monoid. ## Main results * `Skeleton.instMonoid`, for monoidal categories. * `Skeleton.instCommMonoid`, for braided monoidal categories. -/ namespace CategoryTheory open MonoidalCategory universe v u variable {C : Type u} [Category.{v} C] [MonoidalCategory C] /-- If `C` is monoidal and skeletal, it is a monoid. See note [reducible non-instances]. -/ abbrev monoidOfSkeletalMonoidal (hC : Skeletal C) : Monoid C where mul X Y := (X ⊗ Y : C) one := (𝟙_ C : C) one_mul X := hC ⟨λ_ X⟩ mul_one X := hC ⟨ρ_ X⟩ mul_assoc X Y Z := hC ⟨α_ X Y Z⟩ /-- If `C` is braided and skeletal, it is a commutative monoid. -/ def commMonoidOfSkeletalBraided [BraidedCategory C] (hC : Skeletal C) : CommMonoid C := { monoidOfSkeletalMonoidal hC with mul_comm := fun X Y => hC ⟨β_ X Y⟩ } namespace Skeleton /-- The skeleton of a monoidal category has a monoidal structure itself, induced by the equivalence. -/ noncomputable instance instMonoidalCategory : MonoidalCategory (Skeleton C) := Monoidal.transport (skeletonEquivalence C).symm /-- The skeleton of a monoidal category can be viewed as a monoid, where the multiplication is given by the tensor product, and satisfies the monoid axioms since it is a skeleton. -/ noncomputable instance instMonoid : Monoid (Skeleton C) := monoidOfSkeletalMonoidal (skeleton_isSkeleton _).skel /-- The skeleton of a braided monoidal category has a braided monoidal structure itself, induced by the equivalence. -/ noncomputable instance instBraidedCategory [BraidedCategory C] : BraidedCategory (Skeleton C) := letI := Monoidal.instIsEquivalence_fromTransported (skeletonEquivalence C).symm braidedCategoryOfFullyFaithful (Monoidal.fromTransported (skeletonEquivalence C).symm) /-- The skeleton of a braided monoidal category can be viewed as a commutative monoid, where the multiplication is given by the tensor product, and satisfies the monoid axioms since it is a skeleton. -/ noncomputable instance instCommMonoid [BraidedCategory C] : CommMonoid (Skeleton C) := commMonoidOfSkeletalBraided (skeleton_isSkeleton _).skel end Skeleton end CategoryTheory