source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/Local.lean | import Mathlib.CategoryTheory.ObjectProperty.ClosedUnderIsomorphisms
import Mathlib.CategoryTheory.MorphismProperty.Basic
/-!
# Objects that are local with respect to a property of morphisms
Given `W : MorphismProperty C`, we define `W.isLocal : ObjectProperty C`
which is the property of objects `Z` such that for any `f : X ⟶ Y` satisfying `W`,
the precomposition with `f` gives a bijection `(Y ⟶ Z) ≃ (X ⟶ Z)`.
(In the file `CategoryTheory.Localization.Bousfield`, it is shown that this is
part of a Galois connection, with "dual" construction
`Localization.LeftBousfield.W : ObjectProperty C → MorphismProperty C`.)
-/
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
namespace MorphismProperty
variable (W : MorphismProperty C)
/-- Given `W : MorphismProperty C`, this is the property of `W`-local objects, i.e.
the objects `Z` such that for any `f : X ⟶ Y` such that `W f` holds, the precomposition
with `f` gives a bijection `(Y ⟶ Z) ≃ (X ⟶ Z)`.
(See the file `CategoryTheory.Localization.Bousfield` for the "dual" construction
`Localization.LeftBousfield.W : ObjectProperty C → MorphismProperty C`.) -/
def isLocal : ObjectProperty C :=
fun Z ↦ ∀ ⦃X Y : C⦄ (f : X ⟶ Y),
W f → Function.Bijective (fun (g : _ ⟶ Z) ↦ f ≫ g)
lemma isLocal_iff (Z : C) :
W.isLocal Z ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y),
W f → Function.Bijective (fun (g : _ ⟶ Z) ↦ f ≫ g) := Iff.rfl
instance : W.isLocal.IsClosedUnderIsomorphisms where
of_iso {Z Z'} e hZ X Y f hf := by
rw [← Function.Bijective.of_comp_iff _ (Iso.homToEquiv e).bijective]
convert (Iso.homToEquiv e).bijective.comp (hZ f hf) using 1
aesop
end MorphismProperty
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/Ind.lean | import Mathlib.CategoryTheory.Presentable.ColimitPresentation
/-!
# Ind and pro-properties
Given an object property `P`, we define an object property `ind P` that is satisfied for
`X` if `X` is a filtered colimit of `Xᵢ` and `Xᵢ` satisfies `P`.
## Main definitions
- `CategoryTheory.ObjectProperty.ind`: `X` satisfies `ind P` if `X` is a filtered colimit of `Xᵢ`
for `Xᵢ` in `P`.
## Main results
- `CategoryTheory.ObjectProperty.ind_ind`: If `P` implies finitely presentable, then
`P.ind.ind = P.ind`.
## TODOs:
- Dualise to obtain `CategoryTheory.ObjectProperty.pro`.
-/
universe w v u
namespace CategoryTheory.ObjectProperty
open Limits Opposite
variable {C : Type u} [Category.{v} C] {P : ObjectProperty C}
/-- `X` satisfies `ind P` if `X` is a filtered colimit of `Xᵢ` for `Xᵢ` in `P`. -/
def ind (P : ObjectProperty C) : ObjectProperty C :=
fun X ↦ ∃ (J : Type w) (_ : SmallCategory J) (_ : IsFiltered J)
(pres : ColimitPresentation J X), ∀ i, P (pres.diag.obj i)
variable (P) in
lemma le_ind : P ≤ ind.{w} P := by
intro X hX
exact ⟨PUnit, inferInstance, inferInstance, .self X, by simpa⟩
instance : P.ind.IsClosedUnderIsomorphisms where
of_iso {X Y} e := fun ⟨J, _, _, pres, h⟩ ↦ ⟨J, ‹_›, ‹_›, pres.ofIso e, h⟩
/-- `ind` is idempotent if `P` implies finitely presentable. -/
lemma ind_ind (h : P ≤ isFinitelyPresentable.{w} C) [LocallySmall.{w} C] :
ind.{w} (ind.{w} P) = ind.{w} P := by
refine le_antisymm (fun X h ↦ ?_) (le_ind P.ind)
choose J Jc Jf pres K Kc Kf pres' hp using h
have (j : J) (i : K j) : IsFinitelyPresentable ((pres' j).diag.obj i) := h _ (hp _ _)
have := IsFiltered.of_equivalence (ShrinkHoms.equivalence (ColimitPresentation.Total pres'))
exact ⟨_, inferInstance, inferInstance,
(pres.bind pres').reindex (ShrinkHoms.equivalence _).inverse, fun k ↦ by simp [hp]⟩
end CategoryTheory.ObjectProperty |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/ContainsZero.lean | import Mathlib.CategoryTheory.ObjectProperty.ClosedUnderIsomorphisms
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero
/-!
# Properties of objects which hold for a zero object
Given a category `C` and `P : ObjectProperty C`, we define a type class `P.ContainsZero`
expressing that there exists a zero object for which `P` holds. (We do not require
that `P` holds for all zero objects, as in some applications (e.g. triangulated categories),
`P` may not necessarily be closed under isomorphisms.)
-/
universe v v' u u'
namespace CategoryTheory
open Limits ZeroObject
variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
namespace ObjectProperty
variable (P : ObjectProperty C)
/-- Given `P : ObjectProperty C`, we say that `P.ContainsZero` if there exists
a zero object for which `P` holds. When `P` is closed under isomorphisms,
this holds for any zero object. -/
class ContainsZero : Prop where
exists_zero : ∃ (Z : C), IsZero Z ∧ P Z
lemma exists_prop_of_containsZero [P.ContainsZero] :
∃ (Z : C), IsZero Z ∧ P Z :=
ContainsZero.exists_zero
lemma prop_of_isZero [P.ContainsZero] [P.IsClosedUnderIsomorphisms]
{Z : C} (hZ : IsZero Z) :
P Z := by
obtain ⟨Z₀, hZ₀, h₀⟩ := P.exists_prop_of_containsZero
exact P.prop_of_iso (hZ₀.iso hZ) h₀
lemma prop_zero [P.ContainsZero] [P.IsClosedUnderIsomorphisms] [HasZeroObject C] :
P 0 :=
P.prop_of_isZero (isZero_zero C)
instance [HasZeroObject C] : (⊤ : ObjectProperty C).ContainsZero where
exists_zero := ⟨0, isZero_zero C, by simp⟩
instance [HasZeroObject C] : ContainsZero (IsZero (C := C)) where
exists_zero := ⟨0, isZero_zero C, isZero_zero C⟩
instance [P.ContainsZero] [HasZeroMorphisms C] [HasZeroMorphisms D]
(F : C ⥤ D) [F.PreservesZeroMorphisms] : (P.map F).ContainsZero where
exists_zero := by
obtain ⟨Z, h₁, h₂⟩ := P.exists_prop_of_containsZero
exact ⟨F.obj Z, F.map_isZero h₁, P.prop_map_obj F h₂⟩
instance [P.ContainsZero] [P.IsClosedUnderIsomorphisms]
[HasZeroMorphisms C] [HasZeroMorphisms D]
(F : D ⥤ C) [F.PreservesZeroMorphisms] [HasZeroObject D] :
(P.inverseImage F).ContainsZero where
exists_zero :=
⟨0, isZero_zero D, P.prop_of_isZero (F.map_isZero (isZero_zero D))⟩
instance [P.ContainsZero] : P.isoClosure.ContainsZero where
exists_zero := by
obtain ⟨Z, hZ, hP⟩ := P.exists_prop_of_containsZero
exact ⟨Z, hZ, P.le_isoClosure _ hP⟩
end ObjectProperty
/-- Given a functor `F : C ⥤ D`, this is the property of objects of `C`
satisfies by those `X : C` such that `IsZero (F.obj X)`. -/
abbrev Functor.kernel (F : C ⥤ D) : ObjectProperty C :=
ObjectProperty.inverseImage IsZero F
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/Small.lean | import Mathlib.CategoryTheory.ObjectProperty.CompleteLattice
import Mathlib.CategoryTheory.ObjectProperty.FullSubcategory
import Mathlib.CategoryTheory.ObjectProperty.Opposite
import Mathlib.Logic.Small.Basic
/-!
# Smallness of a property of objects
In this file, given `P : ObjectProperty C`, we define
`ObjectProperty.Small.{w} P` as an abbreviation for `Small.{w} (Subtype P)`.
-/
universe w v u
namespace CategoryTheory.ObjectProperty
open Opposite
variable {C : Type u} [Category.{v} C]
/-- A property of objects is small relative to a universe `w`
if the corresponding subtype is. -/
@[pp_with_univ]
protected abbrev Small (P : ObjectProperty C) : Prop := _root_.Small.{w} (Subtype P)
instance (P : ObjectProperty C) [ObjectProperty.Small.{w} P] :
Small.{w} P.FullSubcategory :=
small_of_surjective (f := fun (x : Subtype P) ↦ ⟨x.1, x.2⟩) (fun x ↦ ⟨⟨x.1, x.2⟩, rfl⟩)
lemma Small.of_le {P Q : ObjectProperty C} [ObjectProperty.Small.{w} Q] (h : P ≤ Q) :
ObjectProperty.Small.{w} P :=
small_of_injective (Subtype.map_injective h Function.injective_id)
instance (P : ObjectProperty C) [ObjectProperty.Small.{w} P] :
ObjectProperty.Small.{w} P.op :=
small_of_injective P.subtypeOpEquiv.injective
instance (P : ObjectProperty Cᵒᵖ) [ObjectProperty.Small.{w} P] :
ObjectProperty.Small.{w} P.unop := by
simpa only [← small_congr P.unop.subtypeOpEquiv]
instance {ι : Type*} (X : ι → C) [Small.{w} ι] :
ObjectProperty.Small.{w} (ofObj X) :=
small_of_surjective (f := fun i ↦ ⟨X i, by simp⟩) (by rintro ⟨_, ⟨i⟩⟩; simp)
instance (X Y : C) : ObjectProperty.Small.{w} (.pair X Y) := by
dsimp [pair]
infer_instance
instance {P Q : ObjectProperty C} [ObjectProperty.Small.{w} Q] :
ObjectProperty.Small.{w} (P ⊓ Q) :=
Small.of_le inf_le_right
instance {P Q : ObjectProperty C} [ObjectProperty.Small.{w} P] :
ObjectProperty.Small.{w} (P ⊓ Q) :=
Small.of_le inf_le_left
instance {P Q : ObjectProperty C} [ObjectProperty.Small.{w} P] [ObjectProperty.Small.{w} Q] :
ObjectProperty.Small.{w} (P ⊔ Q) :=
small_of_surjective (f := fun (x : Subtype P ⊕ Subtype Q) ↦ match x with
| .inl x => ⟨x.1, Or.inl x.2⟩
| .inr x => ⟨x.1, Or.inr x.2⟩)
(by rintro ⟨x, hx | hx⟩ <;> aesop)
instance {α : Type*} (P : α → ObjectProperty C)
[∀ a, ObjectProperty.Small.{w} (P a)] [Small.{w} α] :
ObjectProperty.Small.{w} (⨆ a, P a) :=
small_of_surjective (f := fun (x : Σ a, Subtype (P a)) ↦ ⟨x.2.1, by aesop⟩)
(fun ⟨x, hx⟩ ↦ by aesop)
@[simp]
lemma small_op_iff (P : ObjectProperty C) :
ObjectProperty.Small.{w} P.op ↔ ObjectProperty.Small.{w} P :=
small_congr
{ toFun x := ⟨x.1.unop, x.2⟩
invFun x := ⟨op x.1, x.2⟩}
@[simp]
lemma small_unop_iff (P : ObjectProperty Cᵒᵖ) :
ObjectProperty.Small.{w} P.unop ↔ ObjectProperty.Small.{w} P := by
rw [← small_op_iff, op_unop]
instance (P : ObjectProperty C) [ObjectProperty.Small.{w} P] :
ObjectProperty.Small.{w} P.op := by
simpa
instance (P : ObjectProperty Cᵒᵖ) [ObjectProperty.Small.{w} P] :
ObjectProperty.Small.{w} P.unop := by
simpa
/-- A property of objects is essentially small relative to a universe `w`
if it is contained in the closure by isomorphisms of a small property. -/
@[pp_with_univ]
protected class EssentiallySmall (P : ObjectProperty C) : Prop where
exists_small_le' (P) : ∃ (Q : ObjectProperty C) (_ : ObjectProperty.Small.{w} Q),
P ≤ Q.isoClosure
lemma EssentiallySmall.exists_small_le (P : ObjectProperty C)
[ObjectProperty.EssentiallySmall.{w} P] :
∃ (Q : ObjectProperty C) (_ : ObjectProperty.Small.{w} Q), Q ≤ P ∧ P ≤ Q.isoClosure := by
obtain ⟨Q, _, hQ⟩ := exists_small_le' P
let P' := Q ⊓ P.isoClosure
have h (X' : Subtype P') : ∃ (X : Subtype P), Nonempty (X'.1 ≅ X.1) :=
⟨⟨X'.2.2.choose, X'.2.2.choose_spec.choose⟩, X'.2.2.choose_spec.choose_spec⟩
choose φ hφ using h
refine ⟨fun X ↦ X ∈ Set.range (Subtype.val ∘ φ), ?_, ?_, ?_⟩
· exact small_of_surjective (f := fun X ↦ ⟨(φ X).1, by tauto⟩)
(by rintro ⟨_, Z, rfl⟩; exact ⟨Z, rfl⟩)
· intro X hX
simp only [Set.mem_range, Function.comp_apply, Subtype.exists] at hX
obtain ⟨Y, hY, rfl⟩ := hX
exact (φ ⟨Y, hY⟩).2
· intro X hX
obtain ⟨Y, hY, ⟨e⟩⟩ := hQ _ hX
let Z : Subtype P' := ⟨Y, hY, ⟨X, hX, ⟨e.symm⟩⟩⟩
exact ⟨_, ⟨Z, rfl⟩, ⟨e ≪≫ (hφ Z).some⟩⟩
instance (P : ObjectProperty C) [ObjectProperty.Small.{w} P] :
ObjectProperty.EssentiallySmall.{w} P where
exists_small_le' := ⟨P, inferInstance, le_isoClosure P⟩
instance (P : ObjectProperty C) [ObjectProperty.EssentiallySmall.{w} P] :
ObjectProperty.EssentiallySmall.{w} P.isoClosure where
exists_small_le' := by
obtain ⟨Q, _, _, _⟩ := EssentiallySmall.exists_small_le.{w} P
exact ⟨Q, inferInstance, by rwa [isoClosure_le_iff]⟩
lemma EssentiallySmall.exists_small (P : ObjectProperty C) [P.IsClosedUnderIsomorphisms]
[ObjectProperty.EssentiallySmall.{w} P] :
∃ (P₀ : ObjectProperty C) (_ : ObjectProperty.Small.{w} P₀), P = P₀.isoClosure := by
obtain ⟨Q, _, hQ₁, hQ₂⟩ := exists_small_le P
exact ⟨Q, inferInstance, le_antisymm hQ₂ (by rwa [isoClosure_le_iff])⟩
lemma EssentiallySmall.of_le {P Q : ObjectProperty C}
[ObjectProperty.EssentiallySmall.{w} Q] (h : P ≤ Q) :
ObjectProperty.EssentiallySmall.{w} P where
exists_small_le' := by
obtain ⟨R, _, hR⟩ := EssentiallySmall.exists_small_le' Q
exact ⟨R, inferInstance, h.trans hR⟩
instance {P Q : ObjectProperty C}
[ObjectProperty.EssentiallySmall.{w} P] [ObjectProperty.EssentiallySmall.{w} Q] :
ObjectProperty.EssentiallySmall.{w} (P ⊔ Q) := by
obtain ⟨P', _, hP'⟩ := EssentiallySmall.exists_small_le' P
obtain ⟨Q', _, hQ'⟩ := EssentiallySmall.exists_small_le' Q
refine ⟨P' ⊔ Q', inferInstance, ?_⟩
simp only [sup_le_iff]
constructor
· exact hP'.trans (monotone_isoClosure le_sup_left)
· exact hQ'.trans (monotone_isoClosure le_sup_right)
instance {α : Type*} (P : α → ObjectProperty C)
[∀ a, ObjectProperty.EssentiallySmall.{w} (P a)] [Small.{w} α] :
ObjectProperty.EssentiallySmall.{w} (⨆ a, P a) where
exists_small_le' := by
have h (a : α) := EssentiallySmall.exists_small_le' (P a)
choose Q _ hQ using h
refine ⟨⨆ a, Q a, inferInstance, ?_⟩
simp only [iSup_le_iff]
intro a
exact (hQ a).trans (monotone_isoClosure (le_iSup Q a))
@[simp]
lemma essentiallySmall_op_iff (P : ObjectProperty C) :
ObjectProperty.EssentiallySmall.{w} P.op ↔
ObjectProperty.EssentiallySmall.{w} P := by
refine ⟨fun _ ↦ ?_, fun _ ↦ ?_⟩
· obtain ⟨Q, h₁, _, h₂⟩ := EssentiallySmall.exists_small_le P.op
exact ⟨Q.unop, inferInstance, by rwa [← unop_isoClosure, ← op_monotone_iff, op_unop]⟩
· obtain ⟨Q, h₁, _, h₂⟩ := EssentiallySmall.exists_small_le P
exact ⟨Q.op, inferInstance, by rwa [← op_isoClosure, op_monotone_iff]⟩
@[simp]
lemma essentiallySmall_unop_iff (P : ObjectProperty Cᵒᵖ) :
ObjectProperty.EssentiallySmall.{w} P.unop ↔
ObjectProperty.EssentiallySmall.{w} P := by
rw [← essentiallySmall_op_iff, op_unop]
instance (P : ObjectProperty C) [ObjectProperty.EssentiallySmall.{w} P] :
ObjectProperty.EssentiallySmall.{w} P.op := by
simpa
instance (P : ObjectProperty Cᵒᵖ) [ObjectProperty.EssentiallySmall.{w} P] :
ObjectProperty.EssentiallySmall.{w} P.unop := by
simpa
end CategoryTheory.ObjectProperty |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/ClosedUnderIsomorphisms.lean | import Mathlib.CategoryTheory.Iso
import Mathlib.CategoryTheory.ObjectProperty.Basic
import Mathlib.Order.Basic
/-! # Properties of objects which are closed under isomorphisms
Given a category `C` and `P : ObjectProperty C` (i.e. `P : C → Prop`),
this file introduces the type class `P.IsClosedUnderIsomorphisms`.
-/
universe v v' u u'
namespace CategoryTheory
variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
(P Q : ObjectProperty C)
namespace ObjectProperty
/-- A predicate `C → Prop` on the objects of a category is closed under isomorphisms
if whenever `P X`, then all the objects `Y` that are isomorphic to `X` also satisfy `P Y`. -/
class IsClosedUnderIsomorphisms : Prop where
of_iso {X Y : C} (_ : X ≅ Y) (_ : P X) : P Y
lemma prop_of_iso [IsClosedUnderIsomorphisms P] {X Y : C} (e : X ≅ Y) (hX : P X) : P Y :=
IsClosedUnderIsomorphisms.of_iso e hX
lemma prop_iff_of_iso [IsClosedUnderIsomorphisms P] {X Y : C} (e : X ≅ Y) : P X ↔ P Y :=
⟨prop_of_iso P e, prop_of_iso P e.symm⟩
lemma prop_of_isIso [IsClosedUnderIsomorphisms P] {X Y : C} (f : X ⟶ Y) [IsIso f] (hX : P X) :
P Y :=
prop_of_iso P (asIso f) hX
lemma prop_iff_of_isIso [IsClosedUnderIsomorphisms P] {X Y : C} (f : X ⟶ Y) [IsIso f] : P X ↔ P Y :=
prop_iff_of_iso P (asIso f)
/-- The closure by isomorphisms of a predicate on objects in a category. -/
def isoClosure : ObjectProperty C := fun X => ∃ (Y : C) (_ : P Y), Nonempty (X ≅ Y)
lemma prop_isoClosure_iff (X : C) :
isoClosure P X ↔ ∃ (Y : C) (_ : P Y), Nonempty (X ≅ Y) := by rfl
variable {P} in
lemma prop_isoClosure {X Y : C} (h : P X) (e : X ⟶ Y) [IsIso e] : isoClosure P Y :=
⟨X, h, ⟨(asIso e).symm⟩⟩
lemma le_isoClosure : P ≤ isoClosure P :=
fun X hX => ⟨X, hX, ⟨Iso.refl X⟩⟩
variable {P Q} in
lemma monotone_isoClosure (h : P ≤ Q) : isoClosure P ≤ isoClosure Q := by
rintro X ⟨X', hX', ⟨e⟩⟩
exact ⟨X', h _ hX', ⟨e⟩⟩
lemma isoClosure_eq_self [IsClosedUnderIsomorphisms P] : isoClosure P = P := by
apply le_antisymm
· intro X ⟨Y, hY, ⟨e⟩⟩
exact prop_of_iso P e.symm hY
· exact le_isoClosure P
lemma isoClosure_le_iff [IsClosedUnderIsomorphisms Q] : isoClosure P ≤ Q ↔ P ≤ Q :=
⟨(le_isoClosure P).trans,
fun h => (monotone_isoClosure h).trans (by rw [isoClosure_eq_self])⟩
instance : IsClosedUnderIsomorphisms (isoClosure P) where
of_iso := by
rintro X Y e ⟨Z, hZ, ⟨f⟩⟩
exact ⟨Z, hZ, ⟨e.symm.trans f⟩⟩
lemma isClosedUnderIsomorphisms_iff_isoClosure_eq_self :
IsClosedUnderIsomorphisms P ↔ isoClosure P = P :=
⟨fun _ ↦ isoClosure_eq_self _, fun h ↦ by rw [← h]; infer_instance⟩
instance (F : C ⥤ D) : IsClosedUnderIsomorphisms (P.map F) where
of_iso := by
rintro _ _ e ⟨X, hX, ⟨e'⟩⟩
exact ⟨X, hX, ⟨e' ≪≫ e⟩⟩
instance (F : D ⥤ C) [P.IsClosedUnderIsomorphisms] :
IsClosedUnderIsomorphisms (P.inverseImage F) where
of_iso e hX := P.prop_of_iso (F.mapIso e) hX
end ObjectProperty
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/CompleteLattice.lean | import Mathlib.CategoryTheory.ObjectProperty.ClosedUnderIsomorphisms
import Mathlib.Order.CompleteLattice.Basic
/-!
# ObjectProperty is a complete lattice
-/
universe v u
namespace CategoryTheory.ObjectProperty
variable {C : Type u} [Category.{v} C]
example : CompleteLattice (ObjectProperty C) := inferInstance
section
variable (P Q : ObjectProperty C) (X : C)
@[simp high] lemma prop_inf_iff : (P ⊓ Q) X ↔ P X ∧ Q X := Iff.rfl
@[simp high] lemma prop_sup_iff : (P ⊔ Q) X ↔ P X ∨ Q X := Iff.rfl
lemma isoClosure_sup : (P ⊔ Q).isoClosure = P.isoClosure ⊔ Q.isoClosure := by
ext X
simp only [prop_sup_iff]
constructor
· rintro ⟨Y, hY, ⟨e⟩⟩
simp only [prop_sup_iff] at hY
obtain hY | hY := hY
· exact Or.inl ⟨Y, hY, ⟨e⟩⟩
· exact Or.inr ⟨Y, hY, ⟨e⟩⟩
· rintro (hY | hY)
· exact monotone_isoClosure le_sup_left _ hY
· exact monotone_isoClosure le_sup_right _ hY
instance [P.IsClosedUnderIsomorphisms] [Q.IsClosedUnderIsomorphisms] :
(P ⊔ Q).IsClosedUnderIsomorphisms := by
simp only [isClosedUnderIsomorphisms_iff_isoClosure_eq_self, isoClosure_sup, isoClosure_eq_self]
end
section
variable {α : Sort*} (P : α → ObjectProperty C) (X : C)
@[simp high] lemma prop_iSup_iff :
(⨆ (a : α), P a) X ↔ ∃ (a : α), P a X := by simp
lemma isoClosure_iSup :
((⨆ (a : α), P a)).isoClosure = ⨆ (a : α), (P a).isoClosure := by
refine le_antisymm ?_ ?_
· rintro X ⟨Y, hY, ⟨e⟩⟩
simp only [prop_iSup_iff] at hY ⊢
obtain ⟨a, hY⟩ := hY
exact ⟨a, _, hY, ⟨e⟩⟩
· simp only [iSup_le_iff]
intro a
rw [isoClosure_le_iff]
exact (le_iSup P a).trans (le_isoClosure _)
instance [∀ a, (P a).IsClosedUnderIsomorphisms] :
((⨆ (a : α), P a)).IsClosedUnderIsomorphisms := by
simp only [isClosedUnderIsomorphisms_iff_isoClosure_eq_self,
isoClosure_iSup, isoClosure_eq_self]
end
end CategoryTheory.ObjectProperty |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/Shift.lean | import Mathlib.CategoryTheory.ObjectProperty.ClosedUnderIsomorphisms
import Mathlib.CategoryTheory.Shift.Basic
/-!
# Properties of objects on categories equipped with shift
Given a predicate `P : ObjectProperty C` on objects of a category equipped with a shift
by `A`, we define shifted properties of objects `P.shift a` for all `a : A`.
We also introduce a typeclass `P.IsStableUnderShift A` to say that `P X`
implies `P (X⟦a⟧)` for all `a : A`.
-/
open CategoryTheory Category
namespace CategoryTheory
variable {C : Type*} [Category C] (P : ObjectProperty C)
{A : Type*} [AddMonoid A] [HasShift C A]
namespace ObjectProperty
/-- Given a predicate `P : C → Prop` on objects of a category equipped with a shift by `A`,
this is the predicate which is satisfied by `X` if `P (X⟦a⟧)`. -/
def shift (a : A) : ObjectProperty C := fun X => P (X⟦a⟧)
lemma prop_shift_iff (a : A) (X : C) : P.shift a X ↔ P (X⟦a⟧) := Iff.rfl
instance (a : A) [P.IsClosedUnderIsomorphisms] :
(P.shift a).IsClosedUnderIsomorphisms where
of_iso e hX := P.prop_of_iso ((shiftFunctor C a).mapIso e) hX
variable (A)
@[simp]
lemma shift_zero [P.IsClosedUnderIsomorphisms] : P.shift (0 : A) = P := by
ext X
exact P.prop_iff_of_iso ((shiftFunctorZero C A).app X)
variable {A}
lemma shift_shift (a b c : A) (h : a + b = c) [P.IsClosedUnderIsomorphisms] :
(P.shift b).shift a = P.shift c := by
ext X
exact P.prop_iff_of_iso ((shiftFunctorAdd' C a b c h).symm.app X)
/-- `P : ObjectProperty C` is stable under the shift by `a : A` if
`P X` implies `P X⟦a⟧`. -/
class IsStableUnderShiftBy (a : A) : Prop where
le_shift : P ≤ P.shift a
lemma le_shift (a : A) [P.IsStableUnderShiftBy a] :
P ≤ P.shift a := IsStableUnderShiftBy.le_shift
instance (a : A) [P.IsStableUnderShiftBy a] :
P.isoClosure.IsStableUnderShiftBy a where
le_shift := by
rintro X ⟨Y, hY, ⟨e⟩⟩
exact ⟨Y⟦a⟧, P.le_shift a _ hY, ⟨(shiftFunctor C a).mapIso e⟩⟩
variable (A) in
/-- `P : ObjectProperty C` is stable under the shift by `A` if
`P X` implies `P X⟦a⟧` for any `a : A`. -/
class IsStableUnderShift where
isStableUnderShiftBy (a : A) : P.IsStableUnderShiftBy a := by infer_instance
attribute [instance] IsStableUnderShift.isStableUnderShiftBy
instance [P.IsStableUnderShift A] :
P.isoClosure.IsStableUnderShift A where
lemma prop_shift_iff_of_isStableUnderShift {G : Type*} [AddGroup G] [HasShift C G]
[P.IsStableUnderShift G] [P.IsClosedUnderIsomorphisms] (X : C) (g : G) :
P (X⟦g⟧) ↔ P X := by
refine ⟨fun hX ↦ ?_, P.le_shift g _⟩
rw [← P.shift_zero G, ← P.shift_shift g (-g) 0 (by simp)]
exact P.le_shift (-g) _ hX
end ObjectProperty
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/LimitsClosure.lean | import Mathlib.CategoryTheory.ObjectProperty.LimitsOfShape
import Mathlib.CategoryTheory.ObjectProperty.CompleteLattice
import Mathlib.Order.TransfiniteIteration
import Mathlib.SetTheory.Cardinal.HasCardinalLT
/-!
# Closure of a property of objects under limits of certain shapes
In this file, given a property `P` of objects in a category `C` and
family of categories `J : α → Type _`, we introduce the closure
`P.limitsClosure J` of `P` under limits of shapes `J a` for all `a : α`,
and under certain smallness assumptions, we show that its essentially small.
-/
universe w w' t v' u' v u
namespace CategoryTheory.ObjectProperty
open Limits
variable {C : Type u} [Category.{v} C] (P : ObjectProperty C)
{α : Type t} (J : α → Type u') [∀ a, Category.{v'} (J a)]
/-- The closure of a property of objects of a category under limits of
shape `J a` for a family of categories `J`. -/
inductive limitsClosure : ObjectProperty C
| of_mem (X : C) (hX : P X) : limitsClosure X
| of_isoClosure {X Y : C} (e : X ≅ Y) (hX : limitsClosure X) : limitsClosure Y
| of_limitPresentation {X : C} {a : α} (pres : LimitPresentation (J a) X)
(h : ∀ j, limitsClosure (pres.diag.obj j)) : limitsClosure X
@[simp]
lemma le_limitsClosure : P ≤ P.limitsClosure J :=
fun X hX ↦ .of_mem X hX
instance : (P.limitsClosure J).IsClosedUnderIsomorphisms where
of_iso e hX := .of_isoClosure e hX
instance (a : α) : (P.limitsClosure J).IsClosedUnderLimitsOfShape (J a) where
limitsOfShape_le := by
rintro X ⟨hX⟩
exact .of_limitPresentation hX.toLimitPresentation hX.prop_diag_obj
variable {P J} in
lemma limitsClosure_le {Q : ObjectProperty C} [Q.IsClosedUnderIsomorphisms]
[∀ (a : α), Q.IsClosedUnderLimitsOfShape (J a)] (h : P ≤ Q) :
P.limitsClosure J ≤ Q := by
intro X hX
induction hX with
| of_mem X hX => exact h _ hX
| of_isoClosure e hX hX' => exact Q.prop_of_iso e hX'
| of_limitPresentation pres h h' => exact Q.prop_of_isLimit pres.isLimit h'
variable {P} in
lemma limitsClosure_monotone {Q : ObjectProperty C} (h : P ≤ Q) :
P.limitsClosure J ≤ Q.limitsClosure J :=
limitsClosure_le (h.trans (Q.le_limitsClosure J))
lemma limitsClosure_isoClosure :
P.isoClosure.limitsClosure J = P.limitsClosure J := by
refine le_antisymm (limitsClosure_le ?_)
(limitsClosure_monotone _ P.le_isoClosure)
rw [isoClosure_le_iff]
exact le_limitsClosure P J
/-- Given `P : ObjectProperty C` and a family of categories `J : α → Type _`,
this property objects contains `P` and all objects that are equal to `lim F`
for some functor `F : J a ⥤ C` such that `F.obj j` satisfies `P` for any `j`. -/
def strictLimitsClosureStep : ObjectProperty C :=
P ⊔ (⨆ (a : α), P.strictLimitsOfShape (J a))
@[simp]
lemma le_strictLimitsClosureStep : P ≤ P.strictLimitsClosureStep J := le_sup_left
variable {P} in
lemma strictLimitsClosureStep_monotone {Q : ObjectProperty C} (h : P ≤ Q) :
P.strictLimitsClosureStep J ≤ Q.strictLimitsClosureStep J := by
dsimp [strictLimitsClosureStep]
simp only [sup_le_iff, iSup_le_iff]
exact ⟨h.trans le_sup_left, fun a ↦ (strictLimitsOfShape_monotone (J a) h).trans
(le_trans (by rfl) ((le_iSup _ a).trans le_sup_right))⟩
section
variable {β : Type w'} [LinearOrder β] [OrderBot β] [SuccOrder β] [WellFoundedLT β]
/-- Given `P : ObjectProperty C`, a family of categories `J a`, this
is the transfinite iteration of `Q ↦ Q.strictLimitsClosureStep J`. -/
abbrev strictLimitsClosureIter (b : β) : ObjectProperty C :=
transfiniteIterate (φ := fun Q ↦ Q.strictLimitsClosureStep J) b P
lemma le_strictLimitsClosureIter (b : β) :
P ≤ P.strictLimitsClosureIter J b :=
le_of_eq_of_le (transfiniteIterate_bot _ _).symm
(monotone_transfiniteIterate _ _ (fun _ ↦ le_strictLimitsClosureStep _ _) bot_le)
lemma strictLimitsClosureIter_le_limitsClosure (b : β) :
P.strictLimitsClosureIter J b ≤ P.limitsClosure J := by
induction b using SuccOrder.limitRecOn with
| isMin b hb =>
obtain rfl := hb.eq_bot
simp
| succ b hb hb' =>
rw [strictLimitsClosureIter, transfiniteIterate_succ _ _ _ hb,
strictLimitsClosureStep, sup_le_iff, iSup_le_iff]
exact ⟨hb', fun a ↦ ((strictLimitsOfShape_le_limitsOfShape _ _).trans
(limitsOfShape_monotone _ hb')).trans (limitsOfShape_le _ _)⟩
| isSuccLimit b hb hb' =>
simp only [transfiniteIterate_limit _ _ _ hb,
iSup_le_iff, Subtype.forall, Set.mem_Iio]
intro c hc
exact hb' _ hc
instance [ObjectProperty.Small.{w} P] [LocallySmall.{w} C] [Small.{w} α]
[∀ a, Small.{w} (J a)] [∀ a, LocallySmall.{w} (J a)] (b : β)
[hb₀ : Small.{w} (Set.Iio b)] :
ObjectProperty.Small.{w} (P.strictLimitsClosureIter J b) := by
have H {b c : β} (hbc : b ≤ c) [Small.{w} (Set.Iio c)] : Small.{w} (Set.Iio b) :=
small_of_injective (f := fun x ↦ (⟨x.1, lt_of_lt_of_le x.2 hbc⟩ : Set.Iio c))
(fun _ _ _ ↦ by aesop)
induction b using SuccOrder.limitRecOn generalizing hb₀ with
| isMin b hb =>
obtain rfl := hb.eq_bot
simp only [transfiniteIterate_bot]
infer_instance
| succ b hb hb' =>
have := H (Order.le_succ b)
rw [strictLimitsClosureIter, transfiniteIterate_succ _ _ _ hb,
strictLimitsClosureStep]
infer_instance
| isSuccLimit b hb hb' =>
simp only [transfiniteIterate_limit _ _ _ hb]
have (c : Set.Iio b) : ObjectProperty.Small.{w}
(transfiniteIterate (fun Q ↦ Q.strictLimitsClosureStep J) c.1 P) := by
have := H c.2.le
exact hb' c.1 c.2
infer_instance
end
section
variable (κ : Cardinal.{w}) [Fact κ.IsRegular] (h : ∀ (a : α), HasCardinalLT (J a) κ)
include h
lemma strictLimitsClosureStep_strictLimitsClosureIter_eq_self :
(P.strictLimitsClosureIter J κ.ord).strictLimitsClosureStep J =
(P.strictLimitsClosureIter J κ.ord) := by
have hκ : κ.IsRegular := Fact.out
have (a : α) := (h a).small
refine le_antisymm (fun X hX ↦ ?_) (le_strictLimitsClosureStep _ _)
simp only [strictLimitsClosureStep, prop_sup_iff, prop_iSup_iff] at hX
obtain (hX | ⟨a, F, hF⟩) := hX
· exact hX
· simp only [strictLimitsClosureIter, transfiniteIterate_limit _ _ _
(Cardinal.isSuccLimit_ord hκ.aleph0_le), prop_iSup_iff,
Subtype.exists, Set.mem_Iio, exists_prop] at hF
choose o ho ho' using hF
obtain ⟨m, hm, hm'⟩ : ∃ (m : Ordinal.{w}) (hm : m < κ.ord), ∀ (j : J a), o j ≤ m := by
refine ⟨⨆ j, o ((equivShrink.{w} (J a)).symm j),
Ordinal.iSup_lt_ord ?_ (fun _ ↦ ho _), fun j ↦ ?_⟩
· rw [hκ.cof_eq, ← hasCardinalLT_iff_cardinal_mk_lt _ κ,
← hasCardinalLT_iff_of_equiv (equivShrink.{w} (J a))]
exact h a
· obtain ⟨j, rfl⟩ := (equivShrink.{w} (J a)).symm.surjective j
exact le_ciSup (Ordinal.bddAbove_range _) _
refine monotone_transfiniteIterate _ _
(fun (Q : ObjectProperty C) ↦ Q.le_strictLimitsClosureStep J) (Order.succ_le_iff.2 hm) _ ?_
dsimp
rw [transfiniteIterate_succ _ _ _ (by simp)]
simp only [strictLimitsClosureStep, prop_sup_iff, prop_iSup_iff]
exact Or.inr ⟨a, ⟨_, fun j ↦ monotone_transfiniteIterate _ _
(fun (Q : ObjectProperty C) ↦ Q.le_strictLimitsClosureStep J) (hm' j) _ (ho' j)⟩⟩
lemma isoClosure_strictLimitsClosureIter_eq_limitsClosure :
(P.strictLimitsClosureIter J κ.ord).isoClosure = P.limitsClosure J := by
refine le_antisymm ?_ ?_
· rw [isoClosure_le_iff]
exact P.strictLimitsClosureIter_le_limitsClosure J κ.ord
· have (a : α) :
(P.strictLimitsClosureIter J κ.ord).isoClosure.IsClosedUnderLimitsOfShape (J a) := ⟨by
conv_rhs => rw [← P.strictLimitsClosureStep_strictLimitsClosureIter_eq_self J κ h]
rw [limitsOfShape_isoClosure, ← isoClosure_strictLimitsOfShape,
strictLimitsClosureStep]
exact monotone_isoClosure ((le_trans (by rfl) (le_iSup _ a)).trans le_sup_right)⟩
refine limitsClosure_le
((P.le_strictLimitsClosureIter J κ.ord).trans (le_isoClosure _))
lemma isEssentiallySmall_limitsClosure
[ObjectProperty.EssentiallySmall.{w} P] [LocallySmall.{w} C] [Small.{w} α]
[∀ a, Small.{w} (J a)] [∀ a, LocallySmall.{w} (J a)] :
ObjectProperty.EssentiallySmall.{w} (P.limitsClosure J) := by
obtain ⟨Q, hQ, hQ₁, hQ₂⟩ := EssentiallySmall.exists_small_le.{w} P
have : ObjectProperty.EssentiallySmall.{w} (Q.isoClosure.limitsClosure J) := by
rw [limitsClosure_isoClosure,
← Q.isoClosure_strictLimitsClosureIter_eq_limitsClosure J κ h]
infer_instance
exact .of_le (limitsClosure_monotone J hQ₂)
end
instance [ObjectProperty.EssentiallySmall.{w} P] [LocallySmall.{w} C] [Small.{w} α]
[∀ a, Small.{w} (J a)] [∀ a, LocallySmall.{w} (J a)] :
ObjectProperty.EssentiallySmall.{w} (P.limitsClosure J) := by
obtain ⟨κ, h₁, h₂⟩ := HasCardinalLT.exists_regular_cardinal_forall J
have : Fact κ.IsRegular := ⟨h₁⟩
exact isEssentiallySmall_limitsClosure P J κ h₂
end CategoryTheory.ObjectProperty |
.lake/packages/mathlib/Mathlib/CategoryTheory/ObjectProperty/ColimitsOfShape.lean | import Mathlib.CategoryTheory.ObjectProperty.Small
import Mathlib.CategoryTheory.ObjectProperty.LimitsOfShape
import Mathlib.CategoryTheory.Limits.Presentation
/-!
# Objects that are colimits of objects satisfying a certain property
Given a property of objects `P : ObjectProperty C` and a category `J`,
we introduce two properties of objects `P.strictColimitsOfShape J`
and `P.colimitsOfShape J`. The former contains exactly the objects
of the form `colimit F` for any functor `F : J ⥤ C` that has
a colimit and such that `F.obj j` satisfies `P` for any `j`, while
the latter contains all the objects that are isomorphic to
these "chosen" objects `colimit F`.
Under certain circumstances, the type of objects satisfying
`P.strictColimitsOfShape J` is small: the main reason this variant is
introduced is to deduce that the full subcategory of `P.colimitsOfShape J`
is essentially small.
By requiring `P.colimitsOfShape J ≤ P`, we introduce a typeclass
`P.IsClosedUnderColimitsOfShape J`.
We also show that `colimitsOfShape` in a category `C` is related
to `limitsOfShape` in the opposite category `Cᵒᵖ` and vice versa.
## TODO
* refactor `ObjectProperty.ind` by saying that it is the supremum
of `P.colimitsOfShape J` for a filtered category `J`
(generalize also to `κ`-filtered categories?)
* formalize the closure of `P` under finite colimits (which require
iterating over `ℕ`), and more generally the closure under colimits
indexed by a category whose type of arrows has a cardinality
that is bounded by a certain regular cardinal (@joelriou)
-/
universe w v'' v' u'' u' v u
namespace CategoryTheory.ObjectProperty
open Limits
variable {C : Type*} [Category C] (P : ObjectProperty C)
(J : Type u') [Category.{v'} J]
{J' : Type u''} [Category.{v''} J']
/-- The property of objects that are *equal* to `colimit F` for some
functor `F : J ⥤ C` where all `F.obj j` satisfy `P`. -/
inductive strictColimitsOfShape : ObjectProperty C
| colimit (F : J ⥤ C) [HasColimit F] (hF : ∀ j, P (F.obj j)) :
strictColimitsOfShape (colimit F)
variable {P} in
lemma strictColimitsOfShape_monotone {Q : ObjectProperty C} (h : P ≤ Q) :
P.strictColimitsOfShape J ≤ Q.strictColimitsOfShape J := by
rintro _ ⟨F, hF⟩
exact ⟨F, fun j ↦ h _ (hF j)⟩
/-- A structure expressing that `X : C` is the colimit of a functor
`diag : J ⥤ C` such that `P (diag.obj j)` holds for all `j`. -/
structure ColimitOfShape (X : C) extends ColimitPresentation J X where
prop_diag_obj (j : J) : P (diag.obj j)
namespace ColimitOfShape
variable {P J}
/-- If `F : J ⥤ C` is a functor that has a colimit and is such that for all `j`,
`F.obj j` satisfies a property `P`, then this structure expresses that `colimit F`
is indeed a colimit of objects satisfying `P`. -/
@[simps toColimitPresentation]
noncomputable def colimit (F : J ⥤ C) [HasColimit F] (hF : ∀ j, P (F.obj j)) :
P.ColimitOfShape J (colimit F) where
toColimitPresentation := .colimit F
prop_diag_obj := hF
/-- If `X` is a colimit indexed by `J` of objects satisfying a property `P`, then
any object that is isomorphic to `X` also is. -/
@[simps toColimitPresentation]
def ofIso {X : C} (h : P.ColimitOfShape J X) {Y : C} (e : X ≅ Y) :
P.ColimitOfShape J Y where
toColimitPresentation := .ofIso h.toColimitPresentation e
prop_diag_obj := h.prop_diag_obj
/-- If `X` is a colimit indexed by `J` of objects satisfying a property `P`,
it is also a colimit indexed by `J` of objects satisfying `Q` if `P ≤ Q`. -/
@[simps toColimitPresentation]
def ofLE {X : C} (h : P.ColimitOfShape J X) {Q : ObjectProperty C} (hPQ : P ≤ Q) :
Q.ColimitOfShape J X where
toColimitPresentation := h.toColimitPresentation
prop_diag_obj j := hPQ _ (h.prop_diag_obj j)
/-- Change the index category for `ObjectProperty.ColimitOfShape`. -/
@[simps toColimitPresentation]
noncomputable def reindex {X : C} (h : P.ColimitOfShape J X) (G : J' ⥤ J) [G.Final] :
P.ColimitOfShape J' X where
toColimitPresentation := h.toColimitPresentation.reindex G
prop_diag_obj _ := h.prop_diag_obj _
end ColimitOfShape
/-- The property of objects that are the point of a colimit cocone for a
functor `F : J ⥤ C` where all objects `F.obj j` satisfy `P`. -/
def colimitsOfShape : ObjectProperty C :=
fun X ↦ Nonempty (P.ColimitOfShape J X)
variable {P J} in
lemma ColimitOfShape.colimitsOfShape {X : C} (h : P.ColimitOfShape J X) :
P.colimitsOfShape J X :=
⟨h⟩
lemma strictColimitsOfShape_le_colimitsOfShape :
P.strictColimitsOfShape J ≤ P.colimitsOfShape J := by
rintro X ⟨F, hF⟩
exact ⟨.colimit F hF⟩
instance : (P.colimitsOfShape J).IsClosedUnderIsomorphisms where
of_iso := by rintro _ _ e ⟨h⟩; exact ⟨h.ofIso e⟩
@[simp]
lemma isoClosure_strictColimitsOfShape :
(P.strictColimitsOfShape J).isoClosure = P.colimitsOfShape J := by
refine le_antisymm ?_ ?_
· rw [isoClosure_le_iff]
apply strictColimitsOfShape_le_colimitsOfShape
· intro X ⟨h⟩
have := h.hasColimit
exact ⟨colimit h.diag, strictColimitsOfShape.colimit h.diag h.prop_diag_obj,
⟨h.isColimit.coconePointUniqueUpToIso (colimit.isColimit _)⟩⟩
variable {P} in
lemma colimitsOfShape_monotone {Q : ObjectProperty C} (hPQ : P ≤ Q) :
P.colimitsOfShape J ≤ Q.colimitsOfShape J := by
intro X ⟨h⟩
exact ⟨h.ofLE hPQ⟩
@[simp]
lemma colimitsOfShape_isoClosure :
P.isoClosure.colimitsOfShape J = P.colimitsOfShape J := by
refine le_antisymm ?_ (colimitsOfShape_monotone _ (P.le_isoClosure))
intro X ⟨h⟩
choose obj h₁ h₂ using h.prop_diag_obj
exact
⟨{ toColimitPresentation := h.changeDiag (h.diag.isoCopyObj obj (fun j ↦ (h₂ j).some)).symm
prop_diag_obj := h₁ }⟩
instance [ObjectProperty.Small.{w} P] [LocallySmall.{w} C] [Small.{w} J] [LocallySmall.{w} J] :
ObjectProperty.Small.{w} (P.strictColimitsOfShape J) := by
refine small_of_surjective
(f := fun (F : { F : J ⥤ P.FullSubcategory // HasColimit (F ⋙ P.ι) }) ↦
(⟨_, letI := F.2; ⟨F.1 ⋙ P.ι, fun j ↦ (F.1.obj j).2⟩⟩)) ?_
rintro ⟨_, ⟨F, hF⟩⟩
exact ⟨⟨P.lift F hF, by assumption⟩, rfl⟩
/-- A property of objects satisfies `P.IsClosedUnderColimitsOfShape J` if it
is stable by colimits of shape `J`. -/
@[mk_iff]
class IsClosedUnderColimitsOfShape (P : ObjectProperty C) (J : Type u') [Category.{v'} J] where
colimitsOfShape_le (P J) : P.colimitsOfShape J ≤ P
variable {P J} in
lemma IsClosedUnderColimitsOfShape.mk' [P.IsClosedUnderIsomorphisms]
(h : P.strictColimitsOfShape J ≤ P) :
P.IsClosedUnderColimitsOfShape J where
colimitsOfShape_le := by
conv_rhs => rw [← P.isoClosure_eq_self]
rw [← isoClosure_strictColimitsOfShape]
exact monotone_isoClosure h
export IsClosedUnderColimitsOfShape (colimitsOfShape_le)
section
variable {J} [P.IsClosedUnderColimitsOfShape J]
variable {P} in
lemma ColimitOfShape.prop {X : C} (h : P.ColimitOfShape J X) : P X :=
P.colimitsOfShape_le J _ ⟨h⟩
lemma prop_of_isColimit {F : J ⥤ C} {c : Cocone F} (hc : IsColimit c)
(hF : ∀ (j : J), P (F.obj j)) : P c.pt :=
P.colimitsOfShape_le J _ ⟨{ diag := _, ι := _, isColimit := hc, prop_diag_obj := hF }⟩
lemma prop_colimit (F : J ⥤ C) [HasColimit F] (hF : ∀ (j : J), P (F.obj j)) :
P (colimit F) :=
P.prop_of_isColimit (colimit.isColimit F) hF
end
variable {J} in
lemma colimitsOfShape_le_of_final (G : J ⥤ J') [G.Final] :
P.colimitsOfShape J' ≤ P.colimitsOfShape J :=
fun _h ⟨h⟩ ↦ ⟨h.reindex G⟩
variable {J} in
lemma colimitsOfShape_congr (e : J ≌ J') :
P.colimitsOfShape J = P.colimitsOfShape J' :=
le_antisymm (P.colimitsOfShape_le_of_final e.inverse)
(P.colimitsOfShape_le_of_final e.functor)
variable {J} in
lemma isClosedUnderColimitsOfShape_iff_of_equivalence (e : J ≌ J') :
P.IsClosedUnderColimitsOfShape J ↔
P.IsClosedUnderColimitsOfShape J' := by
simp [isClosedUnderColimitsOfShape_iff, P.colimitsOfShape_congr e]
variable {P J} in
lemma IsClosedUnderColimitsOfShape.of_equivalence (e : J ≌ J')
[P.IsClosedUnderColimitsOfShape J] :
P.IsClosedUnderColimitsOfShape J' := by
rwa [← P.isClosedUnderColimitsOfShape_iff_of_equivalence e]
lemma colimitsOfShape_eq_unop_limitsOfShape :
P.colimitsOfShape J = (P.op.limitsOfShape Jᵒᵖ).unop := by
ext X
refine ⟨fun ⟨h⟩ => ⟨?_⟩, fun ⟨h⟩ => ⟨?_⟩⟩
· exact
{ diag := h.diag.op
π := NatTrans.op h.ι
isLimit := isLimitOfUnop h.isColimit
prop_diag_obj _ := h.prop_diag_obj _ }
· exact
{ diag := h.diag.unop
ι := NatTrans.unop h.π
isColimit := isColimitOfOp h.isLimit
prop_diag_obj _ := h.prop_diag_obj _ }
lemma limitsOfShape_eq_unop_colimitsOfShape :
P.limitsOfShape J = (P.op.colimitsOfShape Jᵒᵖ).unop := by
ext X
refine ⟨fun ⟨h⟩ => ⟨?_⟩, fun ⟨h⟩ => ⟨?_⟩⟩
· exact
{ diag := h.diag.op
ι := NatTrans.op h.π
isColimit := isColimitOfUnop h.isLimit
prop_diag_obj _ := h.prop_diag_obj _ }
· exact
{ diag := h.diag.unop
π := NatTrans.unop h.ι
isLimit := isLimitOfOp h.isColimit
prop_diag_obj _ := h.prop_diag_obj _ }
lemma limitsOfShape_op :
P.op.limitsOfShape J = (P.colimitsOfShape Jᵒᵖ).op := by
rw [colimitsOfShape_eq_unop_limitsOfShape, op_unop,
P.op.limitsOfShape_congr (opOpEquivalence J)]
lemma colimitsOfShape_op :
P.op.colimitsOfShape J = (P.limitsOfShape Jᵒᵖ).op := by
rw [limitsOfShape_eq_unop_colimitsOfShape, op_unop,
P.op.colimitsOfShape_congr (opOpEquivalence J)]
lemma isClosedUnderColimitsOfShape_iff_op :
P.IsClosedUnderColimitsOfShape J ↔
P.op.IsClosedUnderLimitsOfShape Jᵒᵖ := by
rw [isClosedUnderColimitsOfShape_iff, isClosedUnderLimitsOfShape_iff,
colimitsOfShape_eq_unop_limitsOfShape, ← op_monotone_iff, op_unop]
lemma isClosedUnderLimitsOfShape_iff_op :
P.IsClosedUnderLimitsOfShape J ↔
P.op.IsClosedUnderColimitsOfShape Jᵒᵖ := by
rw [isClosedUnderColimitsOfShape_iff, isClosedUnderLimitsOfShape_iff,
limitsOfShape_eq_unop_colimitsOfShape, ← op_monotone_iff, op_unop]
lemma isClosedUnderColimitsOfShape_op_iff_op :
P.IsClosedUnderColimitsOfShape Jᵒᵖ ↔
P.op.IsClosedUnderLimitsOfShape J := by
rw [isClosedUnderColimitsOfShape_iff, isClosedUnderLimitsOfShape_iff,
limitsOfShape_op, op_monotone_iff]
lemma isClosedUnderLimitsOfShape_op_iff_op :
P.IsClosedUnderLimitsOfShape Jᵒᵖ ↔
P.op.IsClosedUnderColimitsOfShape J := by
rw [isClosedUnderColimitsOfShape_iff, isClosedUnderLimitsOfShape_iff,
colimitsOfShape_op, op_monotone_iff]
instance [P.IsClosedUnderColimitsOfShape J] :
P.op.IsClosedUnderLimitsOfShape Jᵒᵖ := by
rwa [← isClosedUnderColimitsOfShape_iff_op]
instance [P.IsClosedUnderLimitsOfShape J] :
P.op.IsClosedUnderColimitsOfShape Jᵒᵖ := by
rwa [← isClosedUnderLimitsOfShape_iff_op]
instance [P.IsClosedUnderColimitsOfShape Jᵒᵖ] :
P.op.IsClosedUnderLimitsOfShape J := by
rwa [← isClosedUnderColimitsOfShape_op_iff_op]
instance [P.IsClosedUnderLimitsOfShape Jᵒᵖ] :
P.op.IsClosedUnderColimitsOfShape J := by
rwa [← isClosedUnderLimitsOfShape_op_iff_op]
section
variable (Q : ObjectProperty Cᵒᵖ)
lemma isClosedUnderColimitsOfShape_iff_unop :
Q.IsClosedUnderColimitsOfShape J ↔
Q.unop.IsClosedUnderLimitsOfShape Jᵒᵖ :=
(Q.unop.isClosedUnderLimitsOfShape_op_iff_op J).symm
lemma isClosedUnderLimitsOfShape_iff_unop :
Q.IsClosedUnderLimitsOfShape J ↔
Q.unop.IsClosedUnderColimitsOfShape Jᵒᵖ :=
(Q.unop.isClosedUnderColimitsOfShape_op_iff_op J).symm
lemma isClosedUnderColimitsOfShape_op_iff_unop :
Q.IsClosedUnderColimitsOfShape Jᵒᵖ ↔
Q.unop.IsClosedUnderLimitsOfShape J :=
(Q.unop.isClosedUnderLimitsOfShape_iff_op J).symm
lemma isClosedUnderLimitsOfShape_op_iff_unop :
Q.IsClosedUnderLimitsOfShape Jᵒᵖ ↔
Q.unop.IsClosedUnderColimitsOfShape J :=
(Q.unop.isClosedUnderColimitsOfShape_iff_op J).symm
instance [Q.IsClosedUnderColimitsOfShape J] :
Q.unop.IsClosedUnderLimitsOfShape Jᵒᵖ := by
rwa [← isClosedUnderColimitsOfShape_iff_unop]
instance [Q.IsClosedUnderLimitsOfShape J] :
Q.unop.IsClosedUnderColimitsOfShape Jᵒᵖ := by
rwa [← isClosedUnderLimitsOfShape_iff_unop]
instance [Q.IsClosedUnderColimitsOfShape Jᵒᵖ] :
Q.unop.IsClosedUnderLimitsOfShape J := by
rwa [← isClosedUnderColimitsOfShape_op_iff_unop]
instance [Q.IsClosedUnderLimitsOfShape Jᵒᵖ] :
Q.unop.IsClosedUnderColimitsOfShape J := by
rwa [← isClosedUnderLimitsOfShape_op_iff_unop]
end
end ObjectProperty
namespace Limits
@[deprecated (since := "2025-09-22")] alias ClosedUnderColimitsOfShape :=
ObjectProperty.IsClosedUnderColimitsOfShape
@[deprecated (since := "2025-09-22")] alias closedUnderColimitsOfShape_of_colimit :=
ObjectProperty.IsClosedUnderColimitsOfShape.mk'
@[deprecated (since := "2025-09-22")] alias ClosedUnderColimitsOfShape.colimit :=
ObjectProperty.prop_colimit
end CategoryTheory.Limits |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Biproducts.lean | import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise
import Mathlib.Algebra.Group.Ext
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Biproducts
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.Tactic.Abel
/-!
# Basic facts about biproducts in preadditive categories.
In (or between) preadditive categories,
* Any biproduct satisfies the equality
`total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`,
or, in the binary case, `total : fst ≫ inl + snd ≫ inr = 𝟙 X`.
* Any (binary) `product` or (binary) `coproduct` is a (binary) `biproduct`.
* In any category (with zero morphisms), if `biprod.map f g` is an isomorphism,
then both `f` and `g` are isomorphisms.
* If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂`
so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`),
via Gaussian elimination.
* As a corollary of the previous two facts,
if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
we can construct an isomorphism `X₂ ≅ Y₂`.
* If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`,
or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero.
* If `f : ⨁ S ⟶ ⨁ T` is an isomorphism,
then every column (corresponding to a nonzero summand in the domain)
has some nonzero matrix entry.
* A functor preserves a biproduct if and only if it preserves
the corresponding product if and only if it preserves the corresponding coproduct.
There are connections between this material and the special case of the category whose morphisms are
matrices over a ring, in particular the Schur complement (see
`Mathlib/LinearAlgebra/Matrix/SchurComplement.lean`). In particular, the declarations
`CategoryTheory.Biprod.isoElim`, `CategoryTheory.Biprod.gaussian`
and `Matrix.invertibleOfFromBlocks₁₁Invertible` are all closely related.
-/
open CategoryTheory
open CategoryTheory.Preadditive
open CategoryTheory.Limits
open CategoryTheory.Functor
open CategoryTheory.Preadditive
universe v v' u u'
noncomputable section
namespace CategoryTheory
variable {C : Type u} [Category.{v} C] [Preadditive C]
namespace Limits
section Fintype
variable {J : Type*} [Fintype J]
/-- In a preadditive category, we can construct a biproduct for `f : J → C` from
any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`.
(That is, such a bicone is a limit cone and a colimit cocone.)
-/
def isBilimitOfTotal {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) :
b.IsBilimit where
isLimit :=
{ lift := fun s => ∑ j : J, s.π.app ⟨j⟩ ≫ b.ι j
uniq := fun s m h => by
rw [← Category.comp_id m]
dsimp
rw [← total, comp_sum]
apply Finset.sum_congr rfl
intro j _
have reassoced : m ≫ Bicone.π b j ≫ Bicone.ι b j = s.π.app ⟨j⟩ ≫ Bicone.ι b j := by
simpa using eq_whisker (h ⟨j⟩) _
rw [reassoced]
fac := fun s j => by
classical
cases j
simp only [sum_comp, Category.assoc, Bicone.toCone_π_app, b.ι_π, comp_dite]
simp }
isColimit :=
{ desc := fun s => ∑ j : J, b.π j ≫ s.ι.app ⟨j⟩
uniq := fun s m h => by
rw [← Category.id_comp m]
dsimp
rw [← total, sum_comp]
apply Finset.sum_congr rfl
intro j _
simpa using b.π j ≫= h ⟨j⟩
fac := fun s j => by
classical
cases j
simp only [comp_sum, ← Category.assoc, Bicone.toCocone_ι_app, b.ι_π, dite_comp]
simp }
theorem IsBilimit.total {f : J → C} {b : Bicone f} (i : b.IsBilimit) :
∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt :=
i.isLimit.hom_ext fun j => by
classical
cases j
simp [sum_comp, b.ι_π, comp_dite]
/-- In a preadditive category, we can construct a biproduct for `f : J → C` from
any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`.
(That is, such a bicone is a limit cone and a colimit cocone.)
-/
theorem hasBiproduct_of_total {f : J → C} (b : Bicone f)
(total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : HasBiproduct f :=
HasBiproduct.mk
{ bicone := b
isBilimit := isBilimitOfTotal b total }
/-- In a preadditive category, any finite bicone which is a limit cone is in fact a bilimit
bicone. -/
def isBilimitOfIsLimit {f : J → C} (t : Bicone f) (ht : IsLimit t.toCone) : t.IsBilimit :=
isBilimitOfTotal _ <|
ht.hom_ext fun j => by
classical
cases j
simp [sum_comp, t.ι_π, comp_dite]
/-- We can turn any limit cone over a pair into a bilimit bicone. -/
def biconeIsBilimitOfLimitConeOfIsLimit {f : J → C} {t : Cone (Discrete.functor f)}
(ht : IsLimit t) : (Bicone.ofLimitCone ht).IsBilimit :=
isBilimitOfIsLimit _ <| IsLimit.ofIsoLimit ht <| Cones.ext (Iso.refl _) (by simp)
/-- In a preadditive category, any finite bicone which is a colimit cocone is in fact a bilimit
bicone. -/
def isBilimitOfIsColimit {f : J → C} (t : Bicone f) (ht : IsColimit t.toCocone) : t.IsBilimit :=
isBilimitOfTotal _ <|
ht.hom_ext fun j => by
classical
cases j
simp_rw [Bicone.toCocone_ι_app, comp_sum, ← Category.assoc, t.ι_π, dite_comp]
simp
/-- We can turn any limit cone over a pair into a bilimit bicone. -/
def biconeIsBilimitOfColimitCoconeOfIsColimit {f : J → C} {t : Cocone (Discrete.functor f)}
(ht : IsColimit t) : (Bicone.ofColimitCocone ht).IsBilimit :=
isBilimitOfIsColimit _ <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) <| by
simp
end Fintype
section Finite
variable {J : Type*} [Finite J]
/-- In a preadditive category, if the product over `f : J → C` exists,
then the biproduct over `f` exists. -/
theorem HasBiproduct.of_hasProduct (f : J → C) [HasProduct f] : HasBiproduct f := by
cases nonempty_fintype J
exact HasBiproduct.mk
{ bicone := _
isBilimit := biconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) }
/-- In a preadditive category, if the coproduct over `f : J → C` exists,
then the biproduct over `f` exists. -/
theorem HasBiproduct.of_hasCoproduct (f : J → C) [HasCoproduct f] : HasBiproduct f := by
cases nonempty_fintype J
exact HasBiproduct.mk
{ bicone := _
isBilimit := biconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) }
end Finite
/-- A preadditive category with finite products has finite biproducts. -/
theorem HasFiniteBiproducts.of_hasFiniteProducts [HasFiniteProducts C] : HasFiniteBiproducts C :=
⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasProduct _ }⟩
/-- A preadditive category with finite coproducts has finite biproducts. -/
theorem HasFiniteBiproducts.of_hasFiniteCoproducts [HasFiniteCoproducts C] :
HasFiniteBiproducts C :=
⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasCoproduct _ }⟩
section HasBiproduct
variable {J : Type} [Fintype J] {f : J → C} [HasBiproduct f]
/-- In any preadditive category, any biproduct satisfies
`∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`
-/
@[simp]
theorem biproduct.total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f) :=
IsBilimit.total (biproduct.isBilimit _)
theorem biproduct.lift_eq {T : C} {g : ∀ j, T ⟶ f j} :
biproduct.lift g = ∑ j, g j ≫ biproduct.ι f j := by
classical
ext j
simp only [sum_comp, biproduct.ι_π, comp_dite, biproduct.lift_π, Category.assoc, comp_zero,
Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, if_true]
theorem biproduct.desc_eq {T : C} {g : ∀ j, f j ⟶ T} :
biproduct.desc g = ∑ j, biproduct.π f j ≫ g j := by
classical
ext j
simp [comp_sum, biproduct.ι_π_assoc, dite_comp]
@[reassoc]
theorem biproduct.lift_desc {T U : C} {g : ∀ j, T ⟶ f j} {h : ∀ j, f j ⟶ U} :
biproduct.lift g ≫ biproduct.desc h = ∑ j : J, g j ≫ h j := by
classical
simp [biproduct.lift_eq, biproduct.desc_eq, comp_sum, sum_comp, biproduct.ι_π_assoc, comp_dite,
dite_comp]
theorem biproduct.map_eq [HasFiniteBiproducts C] {f g : J → C} {h : ∀ j, f j ⟶ g j} :
biproduct.map h = ∑ j : J, biproduct.π f j ≫ h j ≫ biproduct.ι g j := by
classical
ext
simp [biproduct.ι_π, biproduct.ι_π_assoc, sum_comp, comp_dite, dite_comp]
@[reassoc]
theorem biproduct.lift_matrix {K : Type} [Finite K] [HasFiniteBiproducts C] {f : J → C} {g : K → C}
{P} (x : ∀ j, P ⟶ f j) (m : ∀ j k, f j ⟶ g k) :
biproduct.lift x ≫ biproduct.matrix m = biproduct.lift fun k => ∑ j, x j ≫ m j k := by
ext
simp [biproduct.lift_desc]
end HasBiproduct
section HasFiniteBiproducts
variable {J K : Type} [Finite J] {f : J → C} [HasFiniteBiproducts C]
@[reassoc]
theorem biproduct.matrix_desc [Fintype K] {f : J → C} {g : K → C}
(m : ∀ j k, f j ⟶ g k) {P} (x : ∀ k, g k ⟶ P) :
biproduct.matrix m ≫ biproduct.desc x = biproduct.desc fun j => ∑ k, m j k ≫ x k := by
ext
simp [lift_desc]
variable [Finite K]
@[reassoc]
theorem biproduct.matrix_map {f : J → C} {g : K → C} {h : K → C} (m : ∀ j k, f j ⟶ g k)
(n : ∀ k, g k ⟶ h k) :
biproduct.matrix m ≫ biproduct.map n = biproduct.matrix fun j k => m j k ≫ n k := by
ext
simp
@[reassoc]
theorem biproduct.map_matrix {f : J → C} {g : J → C} {h : K → C} (m : ∀ k, f k ⟶ g k)
(n : ∀ j k, g j ⟶ h k) :
biproduct.map m ≫ biproduct.matrix n = biproduct.matrix fun j k => m j ≫ n j k := by
ext
simp
end HasFiniteBiproducts
/-- Reindex a categorical biproduct via an equivalence of the index types. -/
@[simps]
def biproduct.reindex {β γ : Type} [Finite β] (ε : β ≃ γ)
(f : γ → C) [HasBiproduct f] [HasBiproduct (f ∘ ε)] : ⨁ f ∘ ε ≅ ⨁ f where
hom := biproduct.desc fun b => biproduct.ι f (ε b)
inv := biproduct.lift fun b => biproduct.π f (ε b)
hom_inv_id := by
ext b b'
by_cases h : b' = b
· subst h; simp
· have : ε b' ≠ ε b := by simp [h]
simp [biproduct.ι_π_ne _ h, biproduct.ι_π_ne _ this]
inv_hom_id := by
classical
cases nonempty_fintype β
ext g g'
by_cases h : g' = g <;>
simp [Preadditive.sum_comp, biproduct.lift_desc,
biproduct.ι_π, comp_dite, Equiv.apply_eq_iff_eq_symm_apply,
h]
/-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from
any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`.
(That is, such a bicone is a limit cone and a colimit cocone.)
-/
def isBinaryBilimitOfTotal {X Y : C} (b : BinaryBicone X Y)
(total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : b.IsBilimit where
isLimit :=
{ lift := fun s =>
(BinaryFan.fst s ≫ b.inl : s.pt ⟶ b.pt) + (BinaryFan.snd s ≫ b.inr : s.pt ⟶ b.pt)
uniq := fun s m h => by
have hₗ := h ⟨.left⟩
have hᵣ := h ⟨.right⟩
dsimp at hₗ hᵣ
simpa [← hₗ, ← hᵣ] using m ≫= total.symm
fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp }
isColimit :=
{ desc := fun s =>
(b.fst ≫ BinaryCofan.inl s : b.pt ⟶ s.pt) + (b.snd ≫ BinaryCofan.inr s : b.pt ⟶ s.pt)
uniq := fun s m h => by
have hₗ := h ⟨.left⟩
have hᵣ := h ⟨.right⟩
dsimp at hₗ hᵣ
simpa [← hₗ, ← hᵣ] using total.symm =≫ m
fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp }
theorem IsBilimit.binary_total {X Y : C} {b : BinaryBicone X Y} (i : b.IsBilimit) :
b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt :=
i.isLimit.hom_ext fun j => by rcases j with ⟨⟨⟩⟩ <;> simp
/-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from
any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`.
(That is, such a bicone is a limit cone and a colimit cocone.)
-/
theorem hasBinaryBiproduct_of_total {X Y : C} (b : BinaryBicone X Y)
(total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : HasBinaryBiproduct X Y :=
HasBinaryBiproduct.mk
{ bicone := b
isBilimit := isBinaryBilimitOfTotal b total }
/-- We can turn any limit cone over a pair into a bicone. -/
@[simps]
def BinaryBicone.ofLimitCone {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) :
BinaryBicone X Y where
pt := t.pt
fst := t.π.app ⟨WalkingPair.left⟩
snd := t.π.app ⟨WalkingPair.right⟩
inl := ht.lift (BinaryFan.mk (𝟙 X) 0)
inr := ht.lift (BinaryFan.mk 0 (𝟙 Y))
theorem inl_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) :
t.inl = ht.lift (BinaryFan.mk (𝟙 X) 0) := by
apply ht.uniq (BinaryFan.mk (𝟙 X) 0); rintro ⟨⟨⟩⟩ <;> simp
theorem inr_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) :
t.inr = ht.lift (BinaryFan.mk 0 (𝟙 Y)) := by
apply ht.uniq (BinaryFan.mk 0 (𝟙 Y)); rintro ⟨⟨⟩⟩ <;> simp
/-- In a preadditive category, any binary bicone which is a limit cone is in fact a bilimit
bicone. -/
def isBinaryBilimitOfIsLimit {X Y : C} (t : BinaryBicone X Y) (ht : IsLimit t.toCone) :
t.IsBilimit :=
isBinaryBilimitOfTotal _ (by refine BinaryFan.IsLimit.hom_ext ht ?_ ?_ <;> simp)
/-- We can turn any limit cone over a pair into a bilimit bicone. -/
def binaryBiconeIsBilimitOfLimitConeOfIsLimit {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) :
(BinaryBicone.ofLimitCone ht).IsBilimit :=
isBinaryBilimitOfTotal _ <| BinaryFan.IsLimit.hom_ext ht (by simp) (by simp)
/-- In a preadditive category, if the product of `X` and `Y` exists, then the
binary biproduct of `X` and `Y` exists. -/
theorem HasBinaryBiproduct.of_hasBinaryProduct (X Y : C) [HasBinaryProduct X Y] :
HasBinaryBiproduct X Y :=
HasBinaryBiproduct.mk
{ bicone := _
isBilimit := binaryBiconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) }
/-- In a preadditive category, if all binary products exist, then all binary biproducts exist. -/
theorem HasBinaryBiproducts.of_hasBinaryProducts [HasBinaryProducts C] : HasBinaryBiproducts C :=
{ has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryProduct X Y }
/-- We can turn any colimit cocone over a pair into a bicone. -/
@[simps]
def BinaryBicone.ofColimitCocone {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) :
BinaryBicone X Y where
pt := t.pt
fst := ht.desc (BinaryCofan.mk (𝟙 X) 0)
snd := ht.desc (BinaryCofan.mk 0 (𝟙 Y))
inl := t.ι.app ⟨WalkingPair.left⟩
inr := t.ι.app ⟨WalkingPair.right⟩
theorem fst_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) :
t.fst = ht.desc (BinaryCofan.mk (𝟙 X) 0) := by
apply ht.uniq (BinaryCofan.mk (𝟙 X) 0)
rintro ⟨⟨⟩⟩ <;> simp
theorem snd_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) :
t.snd = ht.desc (BinaryCofan.mk 0 (𝟙 Y)) := by
apply ht.uniq (BinaryCofan.mk 0 (𝟙 Y))
rintro ⟨⟨⟩⟩ <;> simp
/-- In a preadditive category, any binary bicone which is a colimit cocone is in fact a
bilimit bicone. -/
def isBinaryBilimitOfIsColimit {X Y : C} (t : BinaryBicone X Y) (ht : IsColimit t.toCocone) :
t.IsBilimit :=
isBinaryBilimitOfTotal _ <| by
refine BinaryCofan.IsColimit.hom_ext ht ?_ ?_ <;> simp
/-- We can turn any colimit cocone over a pair into a bilimit bicone. -/
def binaryBiconeIsBilimitOfColimitCoconeOfIsColimit {X Y : C} {t : Cocone (pair X Y)}
(ht : IsColimit t) : (BinaryBicone.ofColimitCocone ht).IsBilimit :=
isBinaryBilimitOfIsColimit (BinaryBicone.ofColimitCocone ht) <|
IsColimit.ofIsoColimit ht <|
Cocones.ext (Iso.refl _) fun j => by
rcases j with ⟨⟨⟩⟩ <;> simp
/-- In a preadditive category, if the coproduct of `X` and `Y` exists, then the
binary biproduct of `X` and `Y` exists. -/
theorem HasBinaryBiproduct.of_hasBinaryCoproduct (X Y : C) [HasBinaryCoproduct X Y] :
HasBinaryBiproduct X Y :=
HasBinaryBiproduct.mk
{ bicone := _
isBilimit := binaryBiconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) }
/-- In a preadditive category, if all binary coproducts exist, then all binary biproducts exist. -/
theorem HasBinaryBiproducts.of_hasBinaryCoproducts [HasBinaryCoproducts C] :
HasBinaryBiproducts C :=
{ has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryCoproduct X Y }
section
variable {X Y : C} [HasBinaryBiproduct X Y]
/-- In any preadditive category, any binary biproduct satisfies
`biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y)`.
-/
@[simp]
theorem biprod.total : biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y) := by
ext <;> simp
theorem biprod.lift_eq {T : C} {f : T ⟶ X} {g : T ⟶ Y} :
biprod.lift f g = f ≫ biprod.inl + g ≫ biprod.inr := by ext <;> simp [add_comp]
theorem biprod.desc_eq {T : C} {f : X ⟶ T} {g : Y ⟶ T} :
biprod.desc f g = biprod.fst ≫ f + biprod.snd ≫ g := by ext <;> simp
@[reassoc (attr := simp)]
theorem biprod.lift_desc {T U : C} {f : T ⟶ X} {g : T ⟶ Y} {h : X ⟶ U} {i : Y ⟶ U} :
biprod.lift f g ≫ biprod.desc h i = f ≫ h + g ≫ i := by simp [biprod.lift_eq, biprod.desc_eq]
theorem biprod.map_eq [HasBinaryBiproducts C] {W X Y Z : C} {f : W ⟶ Y} {g : X ⟶ Z} :
biprod.map f g = biprod.fst ≫ f ≫ biprod.inl + biprod.snd ≫ g ≫ biprod.inr := by
ext <;> simp
section
variable {Z : C}
lemma biprod.decomp_hom_to (f : Z ⟶ X ⊞ Y) :
∃ f₁ f₂, f = f₁ ≫ biprod.inl + f₂ ≫ biprod.inr :=
⟨f ≫ biprod.fst, f ≫ biprod.snd, by aesop⟩
lemma biprod.ext_to_iff {f g : Z ⟶ X ⊞ Y} :
f = g ↔ f ≫ biprod.fst = g ≫ biprod.fst ∧ f ≫ biprod.snd = g ≫ biprod.snd := by
aesop
lemma biprod.decomp_hom_from (f : X ⊞ Y ⟶ Z) :
∃ f₁ f₂, f = biprod.fst ≫ f₁ + biprod.snd ≫ f₂ :=
⟨biprod.inl ≫ f, biprod.inr ≫ f, by aesop⟩
lemma biprod.ext_from_iff {f g : X ⊞ Y ⟶ Z} :
f = g ↔ biprod.inl ≫ f = biprod.inl ≫ g ∧ biprod.inr ≫ f = biprod.inr ≫ g := by
aesop
end
/-- Every split mono `f` with a cokernel induces a binary bicone with `f` as its `inl` and
the cokernel map as its `snd`.
We will show in `is_bilimit_binary_bicone_of_split_mono_of_cokernel` that this binary bicone is in
fact already a biproduct. -/
@[simps]
def binaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f] {c : CokernelCofork f}
(i : IsColimit c) : BinaryBicone X c.pt where
pt := Y
fst := retraction f
snd := c.π
inl := f
inr :=
let c' : CokernelCofork (𝟙 Y - (𝟙 Y - retraction f ≫ f)) :=
CokernelCofork.ofπ (Cofork.π c) (by simp)
let i' : IsColimit c' := isCokernelEpiComp i (retraction f) (by simp)
let i'' := isColimitCoforkOfCokernelCofork i'
(splitEpiOfIdempotentOfIsColimitCofork C (by simp) i'').section_
inl_fst := by simp
inl_snd := by simp
inr_fst := by
dsimp only
rw [splitEpiOfIdempotentOfIsColimitCofork_section_,
isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc]
dsimp only [cokernelCoforkOfCofork_ofπ]
letI := epi_of_isColimit_cofork i
apply zero_of_epi_comp c.π
simp only [sub_comp, comp_sub, Category.comp_id, Category.assoc, IsSplitMono.id, sub_self,
Cofork.IsColimit.π_desc_assoc, CokernelCofork.π_ofπ, IsSplitMono.id_assoc]
apply sub_eq_zero_of_eq
apply Category.id_comp
inr_snd := by apply SplitEpi.id
/-- The bicone constructed in `binaryBiconeOfSplitMonoOfCokernel` is a bilimit.
This is a version of the splitting lemma that holds in all preadditive categories. -/
def isBilimitBinaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f]
{c : CokernelCofork f} (i : IsColimit c) : (binaryBiconeOfIsSplitMonoOfCokernel i).IsBilimit :=
isBinaryBilimitOfTotal _
(by
simp only [binaryBiconeOfIsSplitMonoOfCokernel_fst,
binaryBiconeOfIsSplitMonoOfCokernel_inr,
binaryBiconeOfIsSplitMonoOfCokernel_snd,
splitEpiOfIdempotentOfIsColimitCofork_section_]
dsimp only [binaryBiconeOfIsSplitMonoOfCokernel_pt]
rw [isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc]
simp only [binaryBiconeOfIsSplitMonoOfCokernel_inl, Cofork.IsColimit.π_desc,
cokernelCoforkOfCofork_π, Cofork.π_ofπ, add_sub_cancel])
/-- If `b` is a binary bicone such that `b.inl` is a kernel of `b.snd`, then `b` is a bilimit
bicone. -/
def BinaryBicone.isBilimitOfKernelInl {X Y : C} (b : BinaryBicone X Y)
(hb : IsLimit b.sndKernelFork) : b.IsBilimit :=
isBinaryBilimitOfIsLimit _ <|
BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp)
(fun f g => by simp) fun {T} f g m h₁ h₂ => by
dsimp at m
have h₁' : ((m : T ⟶ b.pt) - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by
simpa using sub_eq_zero.2 h₁
have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂
obtain ⟨q : T ⟶ X, hq : q ≫ b.inl = m - (f ≫ b.inl + g ≫ b.inr)⟩ :=
KernelFork.IsLimit.lift' hb _ h₂'
rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inl_fst, ← Category.assoc, hq, h₁',
zero_comp]
/-- If `b` is a binary bicone such that `b.inr` is a kernel of `b.fst`, then `b` is a bilimit
bicone. -/
def BinaryBicone.isBilimitOfKernelInr {X Y : C} (b : BinaryBicone X Y)
(hb : IsLimit b.fstKernelFork) : b.IsBilimit :=
isBinaryBilimitOfIsLimit _ <|
BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp)
(fun f g => by simp) fun {T} f g m h₁ h₂ => by
dsimp at m
have h₁' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by simpa using sub_eq_zero.2 h₁
have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂
obtain ⟨q : T ⟶ Y, hq : q ≫ b.inr = m - (f ≫ b.inl + g ≫ b.inr)⟩ :=
KernelFork.IsLimit.lift' hb _ h₁'
rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inr_snd, ← Category.assoc, hq, h₂',
zero_comp]
/-- If `b` is a binary bicone such that `b.fst` is a cokernel of `b.inr`, then `b` is a bilimit
bicone. -/
def BinaryBicone.isBilimitOfCokernelFst {X Y : C} (b : BinaryBicone X Y)
(hb : IsColimit b.inrCokernelCofork) : b.IsBilimit :=
isBinaryBilimitOfIsColimit _ <|
BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp)
(fun f g => by simp) fun {T} f g m h₁ h₂ => by
dsimp at m
have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁
have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂
obtain ⟨q : X ⟶ T, hq : b.fst ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ :=
CokernelCofork.IsColimit.desc' hb _ h₂'
rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inl_fst, Category.assoc, hq, h₁',
comp_zero]
/-- If `b` is a binary bicone such that `b.snd` is a cokernel of `b.inl`, then `b` is a bilimit
bicone. -/
def BinaryBicone.isBilimitOfCokernelSnd {X Y : C} (b : BinaryBicone X Y)
(hb : IsColimit b.inlCokernelCofork) : b.IsBilimit :=
isBinaryBilimitOfIsColimit _ <|
BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp)
(fun f g => by simp) fun {T} f g m h₁ h₂ => by
dsimp at m
have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁
have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂
obtain ⟨q : Y ⟶ T, hq : b.snd ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ :=
CokernelCofork.IsColimit.desc' hb _ h₁'
rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inr_snd, Category.assoc, hq, h₂',
comp_zero]
/-- Every split epi `f` with a kernel induces a binary bicone with `f` as its `snd` and
the kernel map as its `inl`.
We will show in `binary_bicone_of_is_split_mono_of_cokernel` that this binary bicone is in fact
already a biproduct. -/
@[simps]
def binaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f] {c : KernelFork f}
(i : IsLimit c) : BinaryBicone c.pt Y :=
{ pt := X
fst :=
let c' : KernelFork (𝟙 X - (𝟙 X - f ≫ section_ f)) := KernelFork.ofι (Fork.ι c) (by simp)
let i' : IsLimit c' := isKernelCompMono i (section_ f) (by simp)
let i'' := isLimitForkOfKernelFork i'
(splitMonoOfIdempotentOfIsLimitFork C (by simp) i'').retraction
snd := f
inl := c.ι
inr := section_ f
inl_fst := by apply SplitMono.id
inl_snd := by simp
inr_fst := by
dsimp only
rw [splitMonoOfIdempotentOfIsLimitFork_retraction, isLimitForkOfKernelFork_lift,
isKernelCompMono_lift]
dsimp only [kernelForkOfFork_ι]
letI := mono_of_isLimit_fork i
apply zero_of_comp_mono c.ι
simp only [comp_sub, Category.comp_id, Category.assoc, sub_self, Fork.IsLimit.lift_ι,
Fork.ι_ofι, IsSplitEpi.id_assoc]
inr_snd := by simp }
/-- The bicone constructed in `binaryBiconeOfIsSplitEpiOfKernel` is a bilimit.
This is a version of the splitting lemma that holds in all preadditive categories. -/
def isBilimitBinaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f]
{c : KernelFork f} (i : IsLimit c) : (binaryBiconeOfIsSplitEpiOfKernel i).IsBilimit :=
BinaryBicone.isBilimitOfKernelInl _ <| i.ofIsoLimit <| Fork.ext (Iso.refl _) (by simp)
end
section
variable {X Y : C} (f g : X ⟶ Y)
/-- The existence of binary biproducts implies that there is at most one preadditive structure. -/
theorem biprod.add_eq_lift_id_desc [HasBinaryBiproduct X X] :
f + g = biprod.lift (𝟙 X) (𝟙 X) ≫ biprod.desc f g := by simp
/-- The existence of binary biproducts implies that there is at most one preadditive structure. -/
theorem biprod.add_eq_lift_desc_id [HasBinaryBiproduct Y Y] :
f + g = biprod.lift f g ≫ biprod.desc (𝟙 Y) (𝟙 Y) := by simp
end
end Limits
open CategoryTheory.Limits
section
attribute [local ext] Preadditive
/-- The existence of binary biproducts implies that there is at most one preadditive structure. -/
instance subsingleton_preadditive_of_hasBinaryBiproducts {C : Type u} [Category.{v} C]
[HasZeroMorphisms C] [HasBinaryBiproducts C] : Subsingleton (Preadditive C) where
allEq := fun a b => by
apply Preadditive.ext; funext X Y; apply AddCommGroup.ext; funext f g
have h₁ := @biprod.add_eq_lift_id_desc _ _ a _ _ f g
(by convert (inferInstance : HasBinaryBiproduct X X); subsingleton)
have h₂ := @biprod.add_eq_lift_id_desc _ _ b _ _ f g
(by convert (inferInstance : HasBinaryBiproduct X X); subsingleton)
refine h₁.trans (Eq.trans ?_ h₂.symm)
congr! 2 <;> subsingleton
end
section
variable [HasBinaryBiproducts.{v} C]
variable {X₁ X₂ Y₁ Y₂ : C}
variable (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂)
/-- The "matrix" morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` with specified components.
-/
def Biprod.ofComponents : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂ :=
biprod.fst ≫ f₁₁ ≫ biprod.inl + biprod.fst ≫ f₁₂ ≫ biprod.inr + biprod.snd ≫ f₂₁ ≫ biprod.inl +
biprod.snd ≫ f₂₂ ≫ biprod.inr
@[simp]
theorem Biprod.inl_ofComponents :
biprod.inl ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₁₁ ≫ biprod.inl + f₁₂ ≫ biprod.inr := by
simp [Biprod.ofComponents]
@[simp]
theorem Biprod.inr_ofComponents :
biprod.inr ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₂₁ ≫ biprod.inl + f₂₂ ≫ biprod.inr := by
simp [Biprod.ofComponents]
@[simp]
theorem Biprod.ofComponents_fst :
Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.fst = biprod.fst ≫ f₁₁ + biprod.snd ≫ f₂₁ := by
simp [Biprod.ofComponents]
@[simp]
theorem Biprod.ofComponents_snd :
Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.snd = biprod.fst ≫ f₁₂ + biprod.snd ≫ f₂₂ := by
simp [Biprod.ofComponents]
@[simp]
theorem Biprod.ofComponents_eq (f : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂) :
Biprod.ofComponents (biprod.inl ≫ f ≫ biprod.fst) (biprod.inl ≫ f ≫ biprod.snd)
(biprod.inr ≫ f ≫ biprod.fst) (biprod.inr ≫ f ≫ biprod.snd) =
f := by
ext <;>
simp only [Category.comp_id, biprod.inr_fst, biprod.inr_snd, biprod.inl_snd, add_zero, zero_add,
Biprod.inl_ofComponents, Biprod.inr_ofComponents, Category.assoc,
comp_zero, biprod.inl_fst, Preadditive.add_comp]
@[simp]
theorem Biprod.ofComponents_comp {X₁ X₂ Y₁ Y₂ Z₁ Z₂ : C} (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂)
(f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂) (g₁₁ : Y₁ ⟶ Z₁) (g₁₂ : Y₁ ⟶ Z₂) (g₂₁ : Y₂ ⟶ Z₁)
(g₂₂ : Y₂ ⟶ Z₂) :
Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ Biprod.ofComponents g₁₁ g₁₂ g₂₁ g₂₂ =
Biprod.ofComponents (f₁₁ ≫ g₁₁ + f₁₂ ≫ g₂₁) (f₁₁ ≫ g₁₂ + f₁₂ ≫ g₂₂) (f₂₁ ≫ g₁₁ + f₂₂ ≫ g₂₁)
(f₂₁ ≫ g₁₂ + f₂₂ ≫ g₂₂) := by
dsimp [Biprod.ofComponents]
ext <;>
simp only [add_comp, comp_add, add_zero, zero_add, biprod.inl_fst,
biprod.inl_snd, biprod.inr_fst, biprod.inr_snd, biprod.inl_fst_assoc, biprod.inl_snd_assoc,
biprod.inr_fst_assoc, biprod.inr_snd_assoc, comp_zero, zero_comp, Category.assoc]
/-- The unipotent upper triangular matrix
```
(1 r)
(0 1)
```
as an isomorphism.
-/
@[simps]
def Biprod.unipotentUpper {X₁ X₂ : C} (r : X₁ ⟶ X₂) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ where
hom := Biprod.ofComponents (𝟙 _) r 0 (𝟙 _)
inv := Biprod.ofComponents (𝟙 _) (-r) 0 (𝟙 _)
/-- The unipotent lower triangular matrix
```
(1 0)
(r 1)
```
as an isomorphism.
-/
@[simps]
def Biprod.unipotentLower {X₁ X₂ : C} (r : X₂ ⟶ X₁) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ where
hom := Biprod.ofComponents (𝟙 _) 0 r (𝟙 _)
inv := Biprod.ofComponents (𝟙 _) 0 (-r) (𝟙 _)
/-- If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂`
so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`),
via Gaussian elimination.
(This is the version of `Biprod.gaussian` written in terms of components.)
-/
def Biprod.gaussian' [IsIso f₁₁] :
Σ' (L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂) (R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂) (g₂₂ : X₂ ⟶ Y₂),
L.hom ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ R.hom = biprod.map f₁₁ g₂₂ :=
⟨Biprod.unipotentLower (-f₂₁ ≫ inv f₁₁), Biprod.unipotentUpper (-inv f₁₁ ≫ f₁₂),
f₂₂ - f₂₁ ≫ inv f₁₁ ≫ f₁₂, by ext <;> simp; abel⟩
/-- If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂`
so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`),
via Gaussian elimination.
-/
def Biprod.gaussian (f : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂) [IsIso (biprod.inl ≫ f ≫ biprod.fst)] :
Σ' (L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂) (R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂) (g₂₂ : X₂ ⟶ Y₂),
L.hom ≫ f ≫ R.hom = biprod.map (biprod.inl ≫ f ≫ biprod.fst) g₂₂ := by
let this :=
Biprod.gaussian' (biprod.inl ≫ f ≫ biprod.fst) (biprod.inl ≫ f ≫ biprod.snd)
(biprod.inr ≫ f ≫ biprod.fst) (biprod.inr ≫ f ≫ biprod.snd)
rwa [Biprod.ofComponents_eq] at this
/-- If `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` via a two-by-two matrix whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct an isomorphism `X₂ ≅ Y₂`, via Gaussian elimination.
-/
def Biprod.isoElim' [IsIso f₁₁] [IsIso (Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂)] : X₂ ≅ Y₂ := by
obtain ⟨L, R, g, w⟩ := Biprod.gaussian' f₁₁ f₁₂ f₂₁ f₂₂
letI : IsIso (biprod.map f₁₁ g) := by
rw [← w]
infer_instance
letI : IsIso g := isIso_right_of_isIso_biprod_map f₁₁ g
exact asIso g
/-- If `f` is an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct an isomorphism `X₂ ≅ Y₂`, via Gaussian elimination.
-/
def Biprod.isoElim (f : X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂) [IsIso (biprod.inl ≫ f.hom ≫ biprod.fst)] : X₂ ≅ Y₂ :=
letI :
IsIso
(Biprod.ofComponents (biprod.inl ≫ f.hom ≫ biprod.fst) (biprod.inl ≫ f.hom ≫ biprod.snd)
(biprod.inr ≫ f.hom ≫ biprod.fst) (biprod.inr ≫ f.hom ≫ biprod.snd)) := by
simp only [Biprod.ofComponents_eq]
infer_instance
Biprod.isoElim' (biprod.inl ≫ f.hom ≫ biprod.fst) (biprod.inl ≫ f.hom ≫ biprod.snd)
(biprod.inr ≫ f.hom ≫ biprod.fst) (biprod.inr ≫ f.hom ≫ biprod.snd)
theorem Biprod.column_nonzero_of_iso {W X Y Z : C} (f : W ⊞ X ⟶ Y ⊞ Z) [IsIso f] :
𝟙 W = 0 ∨ biprod.inl ≫ f ≫ biprod.fst ≠ 0 ∨ biprod.inl ≫ f ≫ biprod.snd ≠ 0 := by
by_contra! h
rcases h with ⟨nz, a₁, a₂⟩
set x := biprod.inl ≫ f ≫ inv f ≫ biprod.fst
have h₁ : x = 𝟙 W := by simp [x]
have h₀ : x = 0 := by
dsimp [x]
rw [← Category.id_comp (inv f), Category.assoc, ← biprod.total]
conv_lhs =>
slice 2 3
rw [comp_add]
simp only [Category.assoc]
rw [comp_add_assoc, add_comp]
conv_lhs =>
congr
next => skip
slice 1 3
rw [a₂]
simp only [zero_comp, add_zero]
conv_lhs =>
slice 1 3
rw [a₁]
simp only [zero_comp]
exact nz (h₁.symm.trans h₀)
end
theorem Biproduct.column_nonzero_of_iso' {σ τ : Type} [Finite τ] {S : σ → C} [HasBiproduct S]
{T : τ → C} [HasBiproduct T] (s : σ) (f : ⨁ S ⟶ ⨁ T) [IsIso f] :
(∀ t : τ, biproduct.ι S s ≫ f ≫ biproduct.π T t = 0) → 𝟙 (S s) = 0 := by
cases nonempty_fintype τ
intro z
have reassoced {t : τ} {W : C} (h : _ ⟶ W) :
biproduct.ι S s ≫ f ≫ biproduct.π T t ≫ h = 0 ≫ h := by grind
set x := biproduct.ι S s ≫ f ≫ inv f ≫ biproduct.π S s
have h₁ : x = 𝟙 (S s) := by simp [x]
have h₀ : x = 0 := by
dsimp [x]
rw [← Category.id_comp (inv f), Category.assoc, ← biproduct.total]
simp only [comp_sum_assoc]
grind [CategoryTheory.Limits.zero_comp, Finset.sum_const_zero]
exact h₁.symm.trans h₀
/-- If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, and `s` is a non-trivial summand of the source,
then there is some `t` in the target so that the `s, t` matrix entry of `f` is nonzero.
-/
def Biproduct.columnNonzeroOfIso {σ τ : Type} [Fintype τ] {S : σ → C} [HasBiproduct S] {T : τ → C}
[HasBiproduct T] (s : σ) (nz : 𝟙 (S s) ≠ 0) (f : ⨁ S ⟶ ⨁ T) [IsIso f] :
Trunc (Σ' t : τ, biproduct.ι S s ≫ f ≫ biproduct.π T t ≠ 0) := by
classical
apply truncSigmaOfExists
have t := Biproduct.column_nonzero_of_iso'.{v} s f
by_contra h
simp only [not_exists_not] at h
exact nz (t h)
section Preadditive
variable {D : Type u'} [Category.{v'} D] [Preadditive.{v'} D]
variable (F : C ⥤ D) [PreservesZeroMorphisms F]
namespace Limits
section Finite
variable {J : Type*} [Finite J]
/-- A functor between preadditive categories that preserves (zero morphisms and) finite biproducts
preserves finite products. -/
lemma preservesProduct_of_preservesBiproduct {f : J → C} [PreservesBiproduct f F] :
PreservesLimit (Discrete.functor f) F where
preserves hc :=
let ⟨_⟩ := nonempty_fintype J
⟨IsLimit.ofIsoLimit
((IsLimit.postcomposeInvEquiv (Discrete.compNatIsoDiscrete _ _) _).symm
(isBilimitOfPreserves F (biconeIsBilimitOfLimitConeOfIsLimit hc)).isLimit) <|
Cones.ext (Iso.refl _) (by rintro ⟨⟩; simp)⟩
section
attribute [local instance] preservesProduct_of_preservesBiproduct
/-- A functor between preadditive categories that preserves (zero morphisms and) finite biproducts
preserves finite products. -/
lemma preservesProductsOfShape_of_preservesBiproductsOfShape [PreservesBiproductsOfShape J F] :
PreservesLimitsOfShape (Discrete J) F where
preservesLimit {_} := preservesLimit_of_iso_diagram _ Discrete.natIsoFunctor.symm
end
/-- A functor between preadditive categories that preserves (zero morphisms and) finite products
preserves finite biproducts. -/
lemma preservesBiproduct_of_preservesProduct {f : J → C} [PreservesLimit (Discrete.functor f) F] :
PreservesBiproduct f F where
preserves {b} hb :=
let ⟨_⟩ := nonempty_fintype J
⟨isBilimitOfIsLimit _ <|
IsLimit.ofIsoLimit
((IsLimit.postcomposeHomEquiv (Discrete.compNatIsoDiscrete _ _) (F.mapCone b.toCone)).symm
(isLimitOfPreserves F hb.isLimit)) <|
Cones.ext (Iso.refl _) (by rintro ⟨⟩; simp)⟩
/-- If the (product-like) biproduct comparison for `F` and `f` is a monomorphism, then `F`
preserves the biproduct of `f`. For the converse, see `mapBiproduct`. -/
lemma preservesBiproduct_of_mono_biproductComparison {f : J → C} [HasBiproduct f]
[HasBiproduct (F.obj ∘ f)] [Mono (biproductComparison F f)] : PreservesBiproduct f F := by
haveI : HasProduct fun b => F.obj (f b) := by
change HasProduct (F.obj ∘ f)
infer_instance
have that : piComparison F f =
(F.mapIso (biproduct.isoProduct f)).inv ≫
biproductComparison F f ≫ (biproduct.isoProduct _).hom := by
ext j
convert piComparison_comp_π F f j; simp [← Function.comp_def, ← Functor.map_comp]
haveI : IsIso (biproductComparison F f) := isIso_of_mono_of_isSplitEpi _
haveI : IsIso (piComparison F f) := by
rw [that]
infer_instance
haveI := PreservesProduct.of_iso_comparison F f
apply preservesBiproduct_of_preservesProduct
/-- If the (coproduct-like) biproduct comparison for `F` and `f` is an epimorphism, then `F`
preserves the biproduct of `F` and `f`. For the converse, see `mapBiproduct`. -/
lemma preservesBiproduct_of_epi_biproductComparison' {f : J → C} [HasBiproduct f]
[HasBiproduct (F.obj ∘ f)] [Epi (biproductComparison' F f)] : PreservesBiproduct f F := by
haveI : Epi (splitEpiBiproductComparison F f).section_ := by simpa
haveI : IsIso (biproductComparison F f) :=
IsIso.of_epi_section' (splitEpiBiproductComparison F f)
apply preservesBiproduct_of_mono_biproductComparison
/-- A functor between preadditive categories that preserves (zero morphisms and) finite products
preserves finite biproducts. -/
lemma preservesBiproductsOfShape_of_preservesProductsOfShape
[PreservesLimitsOfShape (Discrete J) F] :
PreservesBiproductsOfShape J F where
preserves {_} := preservesBiproduct_of_preservesProduct F
/-- A functor between preadditive categories that preserves (zero morphisms and) finite biproducts
preserves finite coproducts. -/
lemma preservesCoproduct_of_preservesBiproduct {f : J → C} [PreservesBiproduct f F] :
PreservesColimit (Discrete.functor f) F where
preserves {c} hc :=
let ⟨_⟩ := nonempty_fintype J
⟨IsColimit.ofIsoColimit
((IsColimit.precomposeHomEquiv (Discrete.compNatIsoDiscrete _ _) _).symm
(isBilimitOfPreserves F (biconeIsBilimitOfColimitCoconeOfIsColimit hc)).isColimit) <|
Cocones.ext (Iso.refl _) (by rintro ⟨⟩; simp)⟩
section
attribute [local instance] preservesCoproduct_of_preservesBiproduct
/-- A functor between preadditive categories that preserves (zero morphisms and) finite biproducts
preserves finite coproducts. -/
lemma preservesCoproductsOfShape_of_preservesBiproductsOfShape [PreservesBiproductsOfShape J F] :
PreservesColimitsOfShape (Discrete J) F where
preservesColimit {_} := preservesColimit_of_iso_diagram _ Discrete.natIsoFunctor.symm
end
/-- A functor between preadditive categories that preserves (zero morphisms and) finite coproducts
preserves finite biproducts. -/
lemma preservesBiproduct_of_preservesCoproduct {f : J → C}
[PreservesColimit (Discrete.functor f) F] :
PreservesBiproduct f F where
preserves {b} hb :=
let ⟨_⟩ := nonempty_fintype J
⟨isBilimitOfIsColimit _ <|
IsColimit.ofIsoColimit
((IsColimit.precomposeInvEquiv (Discrete.compNatIsoDiscrete _ _)
(F.mapCocone b.toCocone)).symm
(isColimitOfPreserves F hb.isColimit)) <|
Cocones.ext (Iso.refl _) (by rintro ⟨⟩; simp)⟩
/-- A functor between preadditive categories that preserves (zero morphisms and) finite coproducts
preserves finite biproducts. -/
lemma preservesBiproductsOfShape_of_preservesCoproductsOfShape
[PreservesColimitsOfShape (Discrete J) F] : PreservesBiproductsOfShape J F where
preserves {_} := preservesBiproduct_of_preservesCoproduct F
end Finite
/-- A functor between preadditive categories that preserves (zero morphisms and) binary biproducts
preserves binary products. -/
lemma preservesBinaryProduct_of_preservesBinaryBiproduct {X Y : C}
[PreservesBinaryBiproduct X Y F] :
PreservesLimit (pair X Y) F where
preserves {c} hc := ⟨IsLimit.ofIsoLimit
((IsLimit.postcomposeInvEquiv (diagramIsoPair _) _).symm
(isBinaryBilimitOfPreserves F (binaryBiconeIsBilimitOfLimitConeOfIsLimit hc)).isLimit) <|
Cones.ext (by dsimp; rfl) fun j => by
rcases j with ⟨⟨⟩⟩ <;> simp⟩
section
attribute [local instance] preservesBinaryProduct_of_preservesBinaryBiproduct
/-- A functor between preadditive categories that preserves (zero morphisms and) binary biproducts
preserves binary products. -/
lemma preservesBinaryProducts_of_preservesBinaryBiproducts [PreservesBinaryBiproducts F] :
PreservesLimitsOfShape (Discrete WalkingPair) F where
preservesLimit {_} := preservesLimit_of_iso_diagram _ (diagramIsoPair _).symm
end
/-- A functor between preadditive categories that preserves (zero morphisms and) binary products
preserves binary biproducts. -/
lemma preservesBinaryBiproduct_of_preservesBinaryProduct {X Y : C} [PreservesLimit (pair X Y) F] :
PreservesBinaryBiproduct X Y F where
preserves {b} hb := ⟨isBinaryBilimitOfIsLimit _ <| IsLimit.ofIsoLimit
((IsLimit.postcomposeHomEquiv (diagramIsoPair _) (F.mapCone b.toCone)).symm
(isLimitOfPreserves F hb.isLimit)) <|
Cones.ext (by dsimp; rfl) fun j => by
rcases j with ⟨⟨⟩⟩ <;> simp⟩
/-- If the (product-like) biproduct comparison for `F`, `X` and `Y` is a monomorphism, then
`F` preserves the biproduct of `X` and `Y`. For the converse, see `map_biprod`. -/
lemma preservesBinaryBiproduct_of_mono_biprodComparison {X Y : C} [HasBinaryBiproduct X Y]
[HasBinaryBiproduct (F.obj X) (F.obj Y)] [Mono (biprodComparison F X Y)] :
PreservesBinaryBiproduct X Y F := by
have that :
prodComparison F X Y =
(F.mapIso (biprod.isoProd X Y)).inv ≫ biprodComparison F X Y ≫ (biprod.isoProd _ _).hom := by
ext <;> simp [← Functor.map_comp]
haveI : IsIso (biprodComparison F X Y) := isIso_of_mono_of_isSplitEpi _
haveI : IsIso (prodComparison F X Y) := by
rw [that]
infer_instance
haveI := PreservesLimitPair.of_iso_prod_comparison F X Y
apply preservesBinaryBiproduct_of_preservesBinaryProduct
/-- If the (coproduct-like) biproduct comparison for `F`, `X` and `Y` is an epimorphism, then
`F` preserves the biproduct of `X` and `Y`. For the converse, see `mapBiprod`. -/
lemma preservesBinaryBiproduct_of_epi_biprodComparison' {X Y : C} [HasBinaryBiproduct X Y]
[HasBinaryBiproduct (F.obj X) (F.obj Y)] [Epi (biprodComparison' F X Y)] :
PreservesBinaryBiproduct X Y F := by
haveI : Epi (splitEpiBiprodComparison F X Y).section_ := by simpa
haveI : IsIso (biprodComparison F X Y) :=
IsIso.of_epi_section' (splitEpiBiprodComparison F X Y)
apply preservesBinaryBiproduct_of_mono_biprodComparison
/-- A functor between preadditive categories that preserves (zero morphisms and) binary products
preserves binary biproducts. -/
lemma preservesBinaryBiproducts_of_preservesBinaryProducts
[PreservesLimitsOfShape (Discrete WalkingPair) F] : PreservesBinaryBiproducts F where
preserves {_} {_} := preservesBinaryBiproduct_of_preservesBinaryProduct F
/-- A functor between preadditive categories that preserves (zero morphisms and) binary biproducts
preserves binary coproducts. -/
lemma preservesBinaryCoproduct_of_preservesBinaryBiproduct {X Y : C}
[PreservesBinaryBiproduct X Y F] :
PreservesColimit (pair X Y) F where
preserves {c} hc :=
⟨IsColimit.ofIsoColimit
((IsColimit.precomposeHomEquiv (diagramIsoPair _) _).symm
(isBinaryBilimitOfPreserves F
(binaryBiconeIsBilimitOfColimitCoconeOfIsColimit hc)).isColimit) <|
Cocones.ext (by dsimp; rfl) fun j => by
rcases j with ⟨⟨⟩⟩ <;> simp⟩
section
attribute [local instance] preservesBinaryCoproduct_of_preservesBinaryBiproduct
/-- A functor between preadditive categories that preserves (zero morphisms and) binary biproducts
preserves binary coproducts. -/
lemma preservesBinaryCoproducts_of_preservesBinaryBiproducts [PreservesBinaryBiproducts F] :
PreservesColimitsOfShape (Discrete WalkingPair) F where
preservesColimit {_} := preservesColimit_of_iso_diagram _ (diagramIsoPair _).symm
end
/-- A functor between preadditive categories that preserves (zero morphisms and) binary coproducts
preserves binary biproducts. -/
lemma preservesBinaryBiproduct_of_preservesBinaryCoproduct {X Y : C}
[PreservesColimit (pair X Y) F] :
PreservesBinaryBiproduct X Y F where
preserves {b} hb :=
⟨isBinaryBilimitOfIsColimit _ <|
IsColimit.ofIsoColimit
((IsColimit.precomposeInvEquiv (diagramIsoPair _) (F.mapCocone b.toCocone)).symm
(isColimitOfPreserves F hb.isColimit)) <|
Cocones.ext (Iso.refl _) fun j => by
rcases j with ⟨⟨⟩⟩ <;> simp⟩
/-- A functor between preadditive categories that preserves (zero morphisms and) binary coproducts
preserves binary biproducts. -/
lemma preservesBinaryBiproducts_of_preservesBinaryCoproducts
[PreservesColimitsOfShape (Discrete WalkingPair) F] : PreservesBinaryBiproducts F where
preserves {_} {_} := preservesBinaryBiproduct_of_preservesBinaryCoproduct F
end Limits
end Preadditive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/AdditiveFunctor.lean | import Mathlib.CategoryTheory.Limits.ExactFunctor
import Mathlib.CategoryTheory.Limits.Preserves.Finite
import Mathlib.CategoryTheory.Preadditive.Biproducts
import Mathlib.CategoryTheory.Preadditive.FunctorCategory
/-!
# Additive Functors
A functor between two preadditive categories is called *additive*
provided that the induced map on hom types is a morphism of abelian
groups.
An additive functor between preadditive categories creates and preserves biproducts.
Conversely, if `F : C ⥤ D` is a functor between preadditive categories, where `C` has binary
biproducts, and if `F` preserves binary biproducts, then `F` is additive.
We also define the category of bundled additive functors.
## Implementation details
`Functor.Additive` 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 abelian groups.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
/-- A functor `F` is additive provided `F.map` is an additive homomorphism. -/
@[stacks 00ZY]
class Functor.Additive {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D]
(F : C ⥤ D) : Prop where
/-- the addition of two morphisms is mapped to the sum of their images -/
map_add : ∀ {X Y : C} {f g : X ⟶ Y}, F.map (f + g) = F.map f + F.map g := by cat_disch
section Preadditive
namespace Functor
section
variable {C D E : Type*} [Category C] [Category D] [Category E]
[Preadditive C] [Preadditive D] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
@[simp]
theorem map_add {X Y : C} {f g : X ⟶ Y} : F.map (f + g) = F.map f + F.map g :=
Functor.Additive.map_add
/-- `F.mapAddHom` is an additive homomorphism whose underlying function is `F.map`. -/
@[simps!]
def mapAddHom {X Y : C} : (X ⟶ Y) →+ (F.obj X ⟶ F.obj Y) :=
AddMonoidHom.mk' (fun f => F.map f) fun _ _ => F.map_add
theorem coe_mapAddHom {X Y : C} : ⇑(F.mapAddHom : (X ⟶ Y) →+ _) = F.map :=
rfl
instance (priority := 100) preservesZeroMorphisms_of_additive : PreservesZeroMorphisms F where
map_zero _ _ := F.mapAddHom.map_zero
instance : Additive (𝟭 C) where
instance {E : Type*} [Category E] [Preadditive E] (G : D ⥤ E) [Functor.Additive G] :
Additive (F ⋙ G) where
instance {J : Type*} [Category J] (j : J) : ((evaluation J C).obj j).Additive where
@[simp]
theorem map_neg {X Y : C} {f : X ⟶ Y} : F.map (-f) = -F.map f :=
(F.mapAddHom : (X ⟶ Y) →+ (F.obj X ⟶ F.obj Y)).map_neg _
@[simp]
theorem map_sub {X Y : C} {f g : X ⟶ Y} : F.map (f - g) = F.map f - F.map g :=
(F.mapAddHom : (X ⟶ Y) →+ (F.obj X ⟶ F.obj Y)).map_sub _ _
theorem map_nsmul {X Y : C} {f : X ⟶ Y} {n : ℕ} : F.map (n • f) = n • F.map f :=
(F.mapAddHom : (X ⟶ Y) →+ (F.obj X ⟶ F.obj Y)).map_nsmul _ _
-- You can alternatively just use `Functor.map_smul` here, with an explicit `(r : ℤ)` argument.
theorem map_zsmul {X Y : C} {f : X ⟶ Y} {r : ℤ} : F.map (r • f) = r • F.map f :=
(F.mapAddHom : (X ⟶ Y) →+ (F.obj X ⟶ F.obj Y)).map_zsmul _ _
@[simp]
nonrec theorem map_sum {X Y : C} {α : Type*} (f : α → (X ⟶ Y)) (s : Finset α) :
F.map (∑ a ∈ s, f a) = ∑ a ∈ s, F.map (f a) :=
map_sum F.mapAddHom f s
variable {F}
lemma additive_of_iso {G : C ⥤ D} (e : F ≅ G) : G.Additive := by
constructor
intro X Y f g
simp only [← NatIso.naturality_1 e (f + g), map_add, Preadditive.add_comp,
NatTrans.naturality, Preadditive.comp_add, Iso.inv_hom_id_app_assoc]
variable (F)
lemma additive_of_full_essSurj_comp [Full F] [EssSurj F] (G : D ⥤ E)
[(F ⋙ G).Additive] : G.Additive where
map_add {X Y f g} := by
obtain ⟨f', hf'⟩ := F.map_surjective ((F.objObjPreimageIso X).hom ≫ f ≫
(F.objObjPreimageIso Y).inv)
obtain ⟨g', hg'⟩ := F.map_surjective ((F.objObjPreimageIso X).hom ≫ g ≫
(F.objObjPreimageIso Y).inv)
simp only [← cancel_mono (G.map (F.objObjPreimageIso Y).inv),
← cancel_epi (G.map (F.objObjPreimageIso X).hom),
Preadditive.add_comp, Preadditive.comp_add, ← Functor.map_comp]
erw [← hf', ← hg', ← (F ⋙ G).map_add]
dsimp
rw [F.map_add]
lemma additive_of_comp_faithful
(F : C ⥤ D) (G : D ⥤ E) [G.Additive] [(F ⋙ G).Additive] [Faithful G] :
F.Additive where
map_add {_ _ f₁ f₂} := G.map_injective (by
rw [← Functor.comp_map, G.map_add, (F ⋙ G).map_add, Functor.comp_map, Functor.comp_map])
open ZeroObject Limits in
include F in
lemma hasZeroObject_of_additive [HasZeroObject C] :
HasZeroObject D where
zero := ⟨F.obj 0, by rw [IsZero.iff_id_eq_zero, ← F.map_id, id_zero, F.map_zero]⟩
end
section InducedCategory
variable {C : Type*} {D : Type*} [Category D] [Preadditive D] (F : C → D)
instance inducedFunctor_additive : Functor.Additive (inducedFunctor F) where
end InducedCategory
instance fullSubcategoryInclusion_additive {C : Type*} [Category C] [Preadditive C]
(Z : ObjectProperty C) : Z.ι.Additive where
section
-- To talk about preservation of biproducts we need to specify universes explicitly.
noncomputable section
variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] [Preadditive C]
[Preadditive D] (F : C ⥤ D)
open CategoryTheory.Limits
open CategoryTheory.Preadditive
instance (priority := 100) preservesFiniteBiproductsOfAdditive [Additive F] :
PreservesFiniteBiproducts F where
preserves := fun {J} _ =>
let ⟨_⟩ := nonempty_fintype J
{ preserves :=
{ preserves := fun hb =>
⟨isBilimitOfTotal _ (by
simp_rw [F.mapBicone_π, F.mapBicone_ι, ← F.map_comp]
erw [← F.map_sum, ← F.map_id, IsBilimit.total hb])⟩ } }
instance (priority := 100) preservesFiniteCoproductsOfAdditive [Additive F] :
PreservesFiniteCoproducts F where
preserves _ := preservesCoproductsOfShape_of_preservesBiproductsOfShape F
instance (priority := 100) preservesFiniteProductsOfAdditive [Additive F] :
PreservesFiniteProducts F where
preserves _ := preservesProductsOfShape_of_preservesBiproductsOfShape F
theorem additive_of_preservesBinaryBiproducts [HasBinaryBiproducts C] [PreservesZeroMorphisms F]
[PreservesBinaryBiproducts F] : Additive F where
map_add {X Y f g} := by
rw [biprod.add_eq_lift_id_desc, F.map_comp, ← biprod.lift_mapBiprod,
← biprod.mapBiprod_hom_desc, Category.assoc, Iso.inv_hom_id_assoc, F.map_id,
biprod.add_eq_lift_id_desc]
lemma additive_of_preserves_binary_products
[HasBinaryProducts C] [PreservesLimitsOfShape (Discrete WalkingPair) F]
[F.PreservesZeroMorphisms] : F.Additive := by
have : HasBinaryBiproducts C := HasBinaryBiproducts.of_hasBinaryProducts
have := preservesBinaryBiproducts_of_preservesBinaryProducts F
exact Functor.additive_of_preservesBinaryBiproducts F
end
end
end Functor
namespace Equivalence
variable {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D]
instance inverse_additive (e : C ≌ D) [e.functor.Additive] : e.inverse.Additive where
map_add {f g} := e.functor.map_injective (by simp)
end Equivalence
section
variable (C D : Type*) [Category C] [Category D] [Preadditive C] [Preadditive D]
/-- Bundled additive functors. -/
def AdditiveFunctor :=
ObjectProperty.FullSubcategory fun F : C ⥤ D => F.Additive
instance : Category (AdditiveFunctor C D) :=
ObjectProperty.FullSubcategory.category _
/-- the category of additive functors is denoted `C ⥤+ D` -/
infixr:26 " ⥤+ " => AdditiveFunctor
instance : Preadditive (C ⥤+ D) :=
Preadditive.inducedCategory _
/-- An additive functor is in particular a functor. -/
def AdditiveFunctor.forget : (C ⥤+ D) ⥤ C ⥤ D :=
ObjectProperty.ι _
instance : (AdditiveFunctor.forget C D).Full :=
ObjectProperty.full_ι _
instance : (AdditiveFunctor.forget C D).Faithful :=
ObjectProperty.faithful_ι _
variable {C D}
/-- Turn an additive functor into an object of the category `AdditiveFunctor C D`. -/
def AdditiveFunctor.of (F : C ⥤ D) [F.Additive] : C ⥤+ D :=
⟨F, inferInstance⟩
@[simp]
theorem AdditiveFunctor.of_fst (F : C ⥤ D) [F.Additive] : (AdditiveFunctor.of F).1 = F :=
rfl
@[simp]
theorem AdditiveFunctor.forget_obj (F : C ⥤+ D) : (AdditiveFunctor.forget C D).obj F = F.1 :=
rfl
theorem AdditiveFunctor.forget_obj_of (F : C ⥤ D) [F.Additive] :
(AdditiveFunctor.forget C D).obj (AdditiveFunctor.of F) = F :=
rfl
@[simp]
theorem AdditiveFunctor.forget_map (F G : C ⥤+ D) (α : F ⟶ G) :
(AdditiveFunctor.forget C D).map α = α :=
rfl
instance : Functor.Additive (AdditiveFunctor.forget C D) where map_add := rfl
instance (F : C ⥤+ D) : Functor.Additive F.1 :=
F.2
end
section Exact
open CategoryTheory.Limits
variable (C : Type u₁) (D : Type u₂) [Category.{v₁} C] [Category.{v₂} D] [Preadditive C]
variable [Preadditive D] [HasZeroObject C] [HasZeroObject D] [HasBinaryBiproducts C]
section
attribute [local instance] preservesBinaryBiproducts_of_preservesBinaryProducts
attribute [local instance] preservesBinaryBiproducts_of_preservesBinaryCoproducts
/-- Turn a left exact functor into an additive functor. -/
def AdditiveFunctor.ofLeftExact : (C ⥤ₗ D) ⥤ C ⥤+ D :=
ObjectProperty.ιOfLE fun F ⟨_⟩ =>
Functor.additive_of_preservesBinaryBiproducts F
instance : (AdditiveFunctor.ofLeftExact C D).Full := ObjectProperty.full_ιOfLE _
instance : (AdditiveFunctor.ofLeftExact C D).Faithful := ObjectProperty.faithful_ιOfLE _
/-- Turn a right exact functor into an additive functor. -/
def AdditiveFunctor.ofRightExact : (C ⥤ᵣ D) ⥤ C ⥤+ D :=
ObjectProperty.ιOfLE fun F ⟨_⟩ =>
Functor.additive_of_preservesBinaryBiproducts F
instance : (AdditiveFunctor.ofRightExact C D).Full := ObjectProperty.full_ιOfLE _
instance : (AdditiveFunctor.ofRightExact C D).Faithful := ObjectProperty.faithful_ιOfLE _
/-- Turn an exact functor into an additive functor. -/
def AdditiveFunctor.ofExact : (C ⥤ₑ D) ⥤ C ⥤+ D :=
ObjectProperty.ιOfLE fun F ⟨⟨_⟩, _⟩ =>
Functor.additive_of_preservesBinaryBiproducts F
instance : (AdditiveFunctor.ofExact C D).Full := ObjectProperty.full_ιOfLE _
instance : (AdditiveFunctor.ofExact C D).Faithful := ObjectProperty.faithful_ιOfLE _
end
variable {C D}
@[simp]
theorem AdditiveFunctor.ofLeftExact_obj_fst (F : C ⥤ₗ D) :
((AdditiveFunctor.ofLeftExact C D).obj F).obj = F.obj :=
rfl
@[simp]
theorem AdditiveFunctor.ofRightExact_obj_fst (F : C ⥤ᵣ D) :
((AdditiveFunctor.ofRightExact C D).obj F).obj = F.obj :=
rfl
@[simp]
theorem AdditiveFunctor.ofExact_obj_fst (F : C ⥤ₑ D) :
((AdditiveFunctor.ofExact C D).obj F).obj = F.obj :=
rfl
@[simp]
theorem AdditiveFunctor.ofLeftExact_map {F G : C ⥤ₗ D} (α : F ⟶ G) :
(AdditiveFunctor.ofLeftExact C D).map α = α :=
rfl
@[simp]
theorem AdditiveFunctor.ofRightExact_map {F G : C ⥤ᵣ D} (α : F ⟶ G) :
(AdditiveFunctor.ofRightExact C D).map α = α :=
rfl
@[simp]
theorem AdditiveFunctor.ofExact_map {F G : C ⥤ₑ D} (α : F ⟶ G) :
(AdditiveFunctor.ofExact C D).map α = α :=
rfl
end Exact
end Preadditive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/OfBiproducts.lean | import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts
import Mathlib.GroupTheory.EckmannHilton
import Mathlib.Tactic.CategoryTheory.Reassoc
/-!
# Constructing a semiadditive structure from binary biproducts
We show that any category with zero morphisms and binary biproducts is enriched over the category
of commutative monoids.
-/
noncomputable section
universe v u
open CategoryTheory
open CategoryTheory.Limits
namespace CategoryTheory.SemiadditiveOfBinaryBiproducts
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasBinaryBiproducts C]
section
variable (X Y : C)
/-- `f +ₗ g` is the composite `X ⟶ Y ⊞ Y ⟶ Y`, where the first map is `(f, g)` and the second map
is `(𝟙 𝟙)`. -/
@[simp]
def leftAdd (f g : X ⟶ Y) : X ⟶ Y :=
biprod.lift f g ≫ biprod.desc (𝟙 Y) (𝟙 Y)
/-- `f +ᵣ g` is the composite `X ⟶ X ⊞ X ⟶ Y`, where the first map is `(𝟙, 𝟙)` and the second map
is `(f g)`. -/
@[simp]
def rightAdd (f g : X ⟶ Y) : X ⟶ Y :=
biprod.lift (𝟙 X) (𝟙 X) ≫ biprod.desc f g
local infixr:65 " +ₗ " => leftAdd X Y
local infixr:65 " +ᵣ " => rightAdd X Y
theorem isUnital_leftAdd : EckmannHilton.IsUnital (· +ₗ ·) 0 := by
have hr : ∀ f : X ⟶ Y, biprod.lift (0 : X ⟶ Y) f = f ≫ biprod.inr := by
intro f
ext
· simp
· simp [Category.assoc]
have hl : ∀ f : X ⟶ Y, biprod.lift f (0 : X ⟶ Y) = f ≫ biprod.inl := by
intro f
ext
· simp
· simp [biprod.lift_snd, Category.assoc, comp_zero]
exact {
left_id := fun f => by simp [hr f, leftAdd, Category.assoc, Category.comp_id, biprod.inr_desc],
right_id := fun f => by simp [hl f, leftAdd, Category.assoc, Category.comp_id, biprod.inl_desc]
}
theorem isUnital_rightAdd : EckmannHilton.IsUnital (· +ᵣ ·) 0 := by
have h₂ : ∀ f : X ⟶ Y, biprod.desc (0 : X ⟶ Y) f = biprod.snd ≫ f := by
intro f
ext
· simp
· simp only [biprod.inr_desc, BinaryBicone.inr_snd_assoc]
have h₁ : ∀ f : X ⟶ Y, biprod.desc f (0 : X ⟶ Y) = biprod.fst ≫ f := by
intro f
ext
· simp
· simp only [biprod.inr_desc, BinaryBicone.inr_fst_assoc, zero_comp]
exact {
left_id := fun f => by simp [h₂ f, rightAdd, biprod.lift_snd_assoc, Category.id_comp],
right_id := fun f => by simp [h₁ f, rightAdd, biprod.lift_fst_assoc, Category.id_comp]
}
theorem distrib (f g h k : X ⟶ Y) : (f +ᵣ g) +ₗ h +ᵣ k = (f +ₗ h) +ᵣ g +ₗ k := by
let diag : X ⊞ X ⟶ Y ⊞ Y := biprod.lift (biprod.desc f g) (biprod.desc h k)
have hd₁ : biprod.inl ≫ diag = biprod.lift f h := by ext <;> simp [diag]
have hd₂ : biprod.inr ≫ diag = biprod.lift g k := by ext <;> simp [diag]
have h₁ : biprod.lift (f +ᵣ g) (h +ᵣ k) = biprod.lift (𝟙 X) (𝟙 X) ≫ diag := by
ext <;> cat_disch
have h₂ : diag ≫ biprod.desc (𝟙 Y) (𝟙 Y) = biprod.desc (f +ₗ h) (g +ₗ k) := by
ext <;> simp [reassoc_of% hd₁, reassoc_of% hd₂]
rw [leftAdd, h₁, Category.assoc, h₂, rightAdd]
/-- In a category with binary biproducts, the morphisms form a commutative monoid. -/
def addCommMonoidHomOfHasBinaryBiproducts : AddCommMonoid (X ⟶ Y) where
add := (· +ᵣ ·)
add_assoc :=
(EckmannHilton.mul_assoc (isUnital_leftAdd X Y) (isUnital_rightAdd X Y) (distrib X Y)).assoc
zero_add := (isUnital_rightAdd X Y).left_id
add_zero := (isUnital_rightAdd X Y).right_id
add_comm :=
(EckmannHilton.mul_comm (isUnital_leftAdd X Y) (isUnital_rightAdd X Y) (distrib X Y)).comm
nsmul := letI : Add (X ⟶ Y) := ⟨(· +ᵣ ·)⟩; nsmulRec
end
section
variable {X Y Z : C}
attribute [local instance] addCommMonoidHomOfHasBinaryBiproducts
theorem add_eq_right_addition (f g : X ⟶ Y) : f + g = biprod.lift (𝟙 X) (𝟙 X) ≫ biprod.desc f g :=
rfl
theorem add_eq_left_addition (f g : X ⟶ Y) : f + g = biprod.lift f g ≫ biprod.desc (𝟙 Y) (𝟙 Y) :=
congr_fun₂ (EckmannHilton.mul (isUnital_leftAdd X Y) (isUnital_rightAdd X Y) (distrib X Y)).symm f
g
theorem add_comp (f g : X ⟶ Y) (h : Y ⟶ Z) : (f + g) ≫ h = f ≫ h + g ≫ h := by
simp only [add_eq_right_addition, Category.assoc]
congr
ext <;> simp
theorem comp_add (f : X ⟶ Y) (g h : Y ⟶ Z) : f ≫ (g + h) = f ≫ g + f ≫ h := by
simp only [add_eq_left_addition, ← Category.assoc]
congr
ext <;> simp
end
end CategoryTheory.SemiadditiveOfBinaryBiproducts |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Opposite.lean | import Mathlib.Algebra.Group.TransferInstance
import Mathlib.Algebra.Module.Equiv.Defs
import Mathlib.Algebra.Module.Opposite
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# If `C` is preadditive, `Cᵒᵖ` has a natural preadditive structure.
-/
open Opposite
namespace CategoryTheory
variable (C : Type*) [Category C] [Preadditive C]
instance : Preadditive Cᵒᵖ where
homGroup X Y := Equiv.addCommGroup (opEquiv X Y)
add_comp _ _ _ f f' g := Quiver.Hom.unop_inj (Preadditive.comp_add _ _ _ g.unop f.unop f'.unop)
comp_add _ _ _ f g g' := Quiver.Hom.unop_inj (Preadditive.add_comp _ _ _ g.unop g'.unop f.unop)
instance moduleEndLeft {X Y : C} : Module (End X)ᵐᵒᵖ (X ⟶ Y) where
smul_add _ _ _ := Preadditive.comp_add _ _ _ _ _ _
smul_zero _ := Limits.comp_zero
add_smul _ _ _ := Preadditive.add_comp _ _ _ _ _ _
zero_smul _ := Limits.zero_comp
@[simp]
theorem unop_add {X Y : Cᵒᵖ} (f g : X ⟶ Y) : (f + g).unop = f.unop + g.unop :=
rfl
@[simp]
theorem unop_zsmul {X Y : Cᵒᵖ} (k : ℤ) (f : X ⟶ Y) : (k • f).unop = k • f.unop :=
rfl
@[simp]
theorem unop_neg {X Y : Cᵒᵖ} (f : X ⟶ Y) : (-f).unop = -f.unop :=
rfl
@[simp]
theorem op_add {X Y : C} (f g : X ⟶ Y) : (f + g).op = f.op + g.op :=
rfl
@[simp]
theorem op_zsmul {X Y : C} (k : ℤ) (f : X ⟶ Y) : (k • f).op = k • f.op :=
rfl
@[simp]
theorem op_neg {X Y : C} (f : X ⟶ Y) : (-f).op = -f.op :=
rfl
variable {C}
/-- `unop` induces morphisms of monoids on hom groups of a preadditive category -/
@[simps!]
def unopHom (X Y : Cᵒᵖ) : (X ⟶ Y) →+ (Opposite.unop Y ⟶ Opposite.unop X) :=
AddMonoidHom.mk' (fun f => f.unop) fun f g => unop_add _ f g
@[simp]
theorem unop_sum (X Y : Cᵒᵖ) {ι : Type*} (s : Finset ι) (f : ι → (X ⟶ Y)) :
(s.sum f).unop = s.sum fun i => (f i).unop :=
map_sum (unopHom X Y) _ _
/-- `op` induces morphisms of monoids on hom groups of a preadditive category -/
@[simps!]
def opHom (X Y : C) : (X ⟶ Y) →+ (Opposite.op Y ⟶ Opposite.op X) :=
AddMonoidHom.mk' (fun f => f.op) fun f g => op_add _ f g
@[simp]
theorem op_sum (X Y : C) {ι : Type*} (s : Finset ι) (f : ι → (X ⟶ Y)) :
(s.sum f).op = s.sum fun i => (f i).op :=
map_sum (opHom X Y) _ _
/-- `G ⟶ G` and `(End G)ᵐᵒᵖ` are isomorphic as `(End G)ᵐᵒᵖ`-modules. -/
@[simps]
def Preadditive.homSelfLinearEquivEndMulOpposite (G : C) : (G ⟶ G) ≃ₗ[(End G)ᵐᵒᵖ] (End G)ᵐᵒᵖ where
toFun f := ⟨f⟩
map_add' := by cat_disch
map_smul' := by cat_disch
invFun := fun ⟨f⟩ => f
left_inv := by cat_disch
right_inv := by cat_disch
variable {D : Type*} [Category D] [Preadditive D]
instance Functor.op_additive (F : C ⥤ D) [F.Additive] : F.op.Additive where
instance Functor.rightOp_additive (F : Cᵒᵖ ⥤ D) [F.Additive] : F.rightOp.Additive where
instance Functor.leftOp_additive (F : C ⥤ Dᵒᵖ) [F.Additive] : F.leftOp.Additive where
instance Functor.unop_additive (F : Cᵒᵖ ⥤ Dᵒᵖ) [F.Additive] : F.unop.Additive where
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/LeftExact.lean | import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# Left exactness of functors between preadditive categories
We show that a functor is left exact in the sense that it preserves finite limits, if it
preserves kernels. The dual result holds for right exact functors and cokernels.
## Main results
* We first derive preservation of binary product in the lemma
`preservesBinaryProductsOfPreservesKernels`,
* then show the preservation of equalizers in `preservesEqualizerOfPreservesKernels`,
* and then derive the preservation of all finite limits with the usual construction.
-/
universe v₁ v₂ u₁ u₂
noncomputable section
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Preadditive
namespace CategoryTheory
namespace Functor
variable {C : Type u₁} [Category.{v₁} C] [Preadditive C] {D : Type u₂} [Category.{v₂} D]
[Preadditive D] (F : C ⥤ D) [PreservesZeroMorphisms F]
section FiniteLimits
/-- A functor between preadditive categories which preserves kernels preserves that an
arbitrary binary fan is a limit.
-/
def isLimitMapConeBinaryFanOfPreservesKernels {X Y Z : C} (π₁ : Z ⟶ X) (π₂ : Z ⟶ Y)
[PreservesLimit (parallelPair π₂ 0) F] (i : IsLimit (BinaryFan.mk π₁ π₂)) :
IsLimit (F.mapCone (BinaryFan.mk π₁ π₂)) := by
let bc := BinaryBicone.ofLimitCone i
let presf : PreservesLimit (parallelPair bc.snd 0) F := by simpa
let hf : IsLimit bc.sndKernelFork := BinaryBicone.isLimitSndKernelFork i
exact (isLimitMapConeBinaryFanEquiv F π₁ π₂).invFun
(BinaryBicone.isBilimitOfKernelInl (F.mapBinaryBicone bc)
(isLimitMapConeForkEquiv' F bc.inl_snd (isLimitOfPreserves F hf))).isLimit
/-- A kernel-preserving functor between preadditive categories preserves any pair being a limit. -/
lemma preservesBinaryProduct_of_preservesKernels
[∀ {X Y} (f : X ⟶ Y), PreservesLimit (parallelPair f 0) F] {X Y : C} :
PreservesLimit (pair X Y) F where
preserves {c} hc :=
⟨IsLimit.ofIsoLimit
(isLimitMapConeBinaryFanOfPreservesKernels F _ _ (IsLimit.ofIsoLimit hc (isoBinaryFanMk c)))
((Cones.functoriality _ F).mapIso (isoBinaryFanMk c).symm)⟩
attribute [local instance] preservesBinaryProduct_of_preservesKernels
/-- A kernel-preserving functor between preadditive categories preserves binary products. -/
lemma preservesBinaryProducts_of_preservesKernels
[∀ {X Y} (f : X ⟶ Y), PreservesLimit (parallelPair f 0) F] :
PreservesLimitsOfShape (Discrete WalkingPair) F where
preservesLimit := preservesLimit_of_iso_diagram F (diagramIsoPair _).symm
attribute [local instance] preservesBinaryProducts_of_preservesKernels
variable [HasBinaryBiproducts C]
/-- A functor between preadditive categories preserves the equalizer of two
morphisms if it preserves all kernels. -/
lemma preservesEqualizer_of_preservesKernels
[∀ {X Y} (f : X ⟶ Y), PreservesLimit (parallelPair f 0) F]
{X Y : C} (f g : X ⟶ Y) : PreservesLimit (parallelPair f g) F := by
letI := preservesBinaryBiproducts_of_preservesBinaryProducts F
haveI := additive_of_preservesBinaryBiproducts F
constructor; intro c i
let c' := isLimitKernelForkOfFork (i.ofIsoLimit (Fork.isoForkOfι c))
dsimp only [kernelForkOfFork_ofι] at c'
let iFc := isLimitForkMapOfIsLimit' F _ c'
constructor
apply IsLimit.ofIsoLimit _ ((Cones.functoriality _ F).mapIso (Fork.isoForkOfι c).symm)
apply (isLimitMapConeForkEquiv F (Fork.condition c)).invFun
let p : parallelPair (F.map (f - g)) 0 ≅ parallelPair (F.map f - F.map g) 0 :=
parallelPair.eqOfHomEq F.map_sub rfl
exact
IsLimit.ofIsoLimit
(isLimitForkOfKernelFork ((IsLimit.postcomposeHomEquiv p _).symm iFc))
(Fork.ext (Iso.refl _) (by simp [p]))
/-- A functor between preadditive categories preserves all equalizers if it preserves all kernels.
-/
lemma preservesEqualizers_of_preservesKernels
[∀ {X Y} (f : X ⟶ Y), PreservesLimit (parallelPair f 0) F] :
PreservesLimitsOfShape WalkingParallelPair F where
preservesLimit {K} := by
letI := preservesEqualizer_of_preservesKernels F (K.map WalkingParallelPairHom.left)
(K.map WalkingParallelPairHom.right)
apply preservesLimit_of_iso_diagram F (diagramIsoParallelPair K).symm
/-- A functor between preadditive categories which preserves kernels preserves all finite limits.
-/
lemma preservesFiniteLimits_of_preservesKernels [HasFiniteProducts C] [HasEqualizers C]
[HasZeroObject C] [HasZeroObject D] [∀ {X Y} (f : X ⟶ Y), PreservesLimit (parallelPair f 0) F] :
PreservesFiniteLimits F :=
have := preservesEqualizers_of_preservesKernels F
have := preservesTerminalObject_of_preservesZeroMorphisms F
have := preservesLimitsOfShape_pempty_of_preservesTerminal F
have : PreservesFiniteProducts F :=.of_preserves_binary_and_terminal F
preservesFiniteLimits_of_preservesEqualizers_and_finiteProducts F
end FiniteLimits
section FiniteColimits
/-- A functor between preadditive categories which preserves cokernels preserves finite coproducts.
-/
def isColimitMapCoconeBinaryCofanOfPreservesCokernels {X Y Z : C} (ι₁ : X ⟶ Z) (ι₂ : Y ⟶ Z)
[PreservesColimit (parallelPair ι₂ 0) F] (i : IsColimit (BinaryCofan.mk ι₁ ι₂)) :
IsColimit (F.mapCocone (BinaryCofan.mk ι₁ ι₂)) := by
let bc := BinaryBicone.ofColimitCocone i
let presf : PreservesColimit (parallelPair bc.inr 0) F := by simpa
let hf : IsColimit bc.inrCokernelCofork := BinaryBicone.isColimitInrCokernelCofork i
exact
(isColimitMapCoconeBinaryCofanEquiv F ι₁ ι₂).invFun
(BinaryBicone.isBilimitOfCokernelFst (F.mapBinaryBicone bc)
(isColimitMapCoconeCoforkEquiv' F bc.inr_fst (isColimitOfPreserves F hf))).isColimit
/-- A cokernel-preserving functor between preadditive categories preserves any pair being
a colimit. -/
lemma preservesCoproduct_of_preservesCokernels
[∀ {X Y} (f : X ⟶ Y), PreservesColimit (parallelPair f 0) F] {X Y : C} :
PreservesColimit (pair X Y) F where
preserves {c} hc :=
⟨IsColimit.ofIsoColimit
(isColimitMapCoconeBinaryCofanOfPreservesCokernels F _ _
(IsColimit.ofIsoColimit hc (isoBinaryCofanMk c)))
((Cocones.functoriality _ F).mapIso (isoBinaryCofanMk c).symm)⟩
attribute [local instance] preservesCoproduct_of_preservesCokernels
/-- A cokernel-preserving functor between preadditive categories preserves binary coproducts. -/
lemma preservesBinaryCoproducts_of_preservesCokernels
[∀ {X Y} (f : X ⟶ Y), PreservesColimit (parallelPair f 0) F] :
PreservesColimitsOfShape (Discrete WalkingPair) F where
preservesColimit := preservesColimit_of_iso_diagram F (diagramIsoPair _).symm
attribute [local instance] preservesBinaryCoproducts_of_preservesCokernels
variable [HasBinaryBiproducts C]
/-- A functor between preadditive categories preserves the coequalizer of two
morphisms if it preserves all cokernels. -/
lemma preservesCoequalizer_of_preservesCokernels
[∀ {X Y} (f : X ⟶ Y), PreservesColimit (parallelPair f 0) F] {X Y : C} (f g : X ⟶ Y) :
PreservesColimit (parallelPair f g) F := by
letI := preservesBinaryBiproducts_of_preservesBinaryCoproducts F
haveI := additive_of_preservesBinaryBiproducts F
constructor
intro c i
let c' := isColimitCokernelCoforkOfCofork (i.ofIsoColimit (Cofork.isoCoforkOfπ c))
dsimp only [cokernelCoforkOfCofork_ofπ] at c'
let iFc := isColimitCoforkMapOfIsColimit' F _ c'
constructor
apply
IsColimit.ofIsoColimit _ ((Cocones.functoriality _ F).mapIso (Cofork.isoCoforkOfπ c).symm)
apply (isColimitMapCoconeCoforkEquiv F (Cofork.condition c)).invFun
let p : parallelPair (F.map (f - g)) 0 ≅ parallelPair (F.map f - F.map g) 0 :=
parallelPair.ext (Iso.refl _) (Iso.refl _) (by simp) (by simp)
exact
IsColimit.ofIsoColimit
(isColimitCoforkOfCokernelCofork ((IsColimit.precomposeHomEquiv p.symm _).symm iFc))
(Cofork.ext (Iso.refl _) (by simp [p]))
/-- A functor between preadditive categories preserves all coequalizers if it preserves all kernels.
-/
lemma preservesCoequalizers_of_preservesCokernels
[∀ {X Y} (f : X ⟶ Y), PreservesColimit (parallelPair f 0) F] :
PreservesColimitsOfShape WalkingParallelPair F where
preservesColimit {K} := by
letI := preservesCoequalizer_of_preservesCokernels F (K.map Limits.WalkingParallelPairHom.left)
(K.map Limits.WalkingParallelPairHom.right)
apply preservesColimit_of_iso_diagram F (diagramIsoParallelPair K).symm
/-- A functor between preadditive categories which preserves kernels preserves all finite limits.
-/
lemma preservesFiniteColimits_of_preservesCokernels [HasFiniteCoproducts C] [HasCoequalizers C]
[HasZeroObject C] [HasZeroObject D]
[∀ {X Y} (f : X ⟶ Y), PreservesColimit (parallelPair f 0) F] : PreservesFiniteColimits F := by
letI := preservesCoequalizers_of_preservesCokernels F
letI := preservesInitialObject_of_preservesZeroMorphisms F
letI := preservesColimitsOfShape_pempty_of_preservesInitial F
letI : PreservesFiniteCoproducts F :=
⟨fun _ ↦ preservesFiniteCoproductsOfPreservesBinaryAndInitial F _⟩
exact preservesFiniteColimits_of_preservesCoequalizers_and_finiteCoproducts F
end FiniteColimits
end Functor
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Indization.lean | import Mathlib.CategoryTheory.Limits.Indization.Category
import Mathlib.CategoryTheory.Preadditive.Transfer
import Mathlib.CategoryTheory.Preadditive.Opposite
import Mathlib.Algebra.Category.Grp.LeftExactFunctor
/-!
# The category of ind-objects is preadditive
-/
universe v u
open CategoryTheory Limits
namespace CategoryTheory
variable {C : Type u} [SmallCategory C] [Preadditive C] [HasFiniteColimits C]
attribute [local instance] HasFiniteBiproducts.of_hasFiniteCoproducts in
noncomputable instance : Preadditive (Ind C) :=
.ofFullyFaithful (((Ind.leftExactFunctorEquivalence C).trans
(AddCommGrpCat.leftExactFunctorForgetEquivalence _).symm).fullyFaithfulFunctor.comp
(ObjectProperty.fullyFaithfulι _))
instance : HasFiniteBiproducts (Ind C) :=
HasFiniteBiproducts.of_hasFiniteCoproducts
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/CommGrp_.lean | import Mathlib.CategoryTheory.Monoidal.CommGrp_
import Mathlib.CategoryTheory.Preadditive.Biproducts
/-!
# Commutative group objects in additive categories.
We construct an inverse of the forgetful functor `CommGrp C ⥤ C` if `C` is an additive category.
This looks slightly strange because the additive structure of `C` maps to the multiplicative
structure of the commutative group objects.
-/
universe v u
namespace CategoryTheory.Preadditive
open CategoryTheory Limits MonoidalCategory CartesianMonoidalCategory
variable {C : Type u} [Category.{v} C] [Preadditive C] [CartesianMonoidalCategory C]
@[simps]
instance (X : C) : GrpObj X where
one := 0
mul := fst _ _ + snd _ _
inv := -𝟙 X
one_mul := by simp [← leftUnitor_hom]
mul_one := by simp [← rightUnitor_hom]
mul_assoc := by simp [add_assoc]
variable [BraidedCategory C]
instance (X : C) : IsCommMonObj X where
mul_comm := by simp [add_comm]
variable (C) in
/-- The canonical functor from an additive category into its commutative group objects. This is
always an equivalence, see `commGrpEquivalence`. -/
@[simps]
def toCommGrp : C ⥤ CommGrp C where
obj X := ⟨X⟩
map {X Y} f := .mk' f
-- PROJECT: develop `ChosenFiniteCoproducts`, and construct `ChosenFiniteCoproducts` from
-- `CartesianMonoidalCategory` in preadditive categories, to give this lemma a proper home.
omit [BraidedCategory C] in
private theorem monoidal_hom_ext {X Y Z : C} {f g : X ⊗ Y ⟶ Z}
(h₁ : lift (𝟙 X) 0 ≫ f = lift (𝟙 X) 0 ≫ g) (h₂ : lift 0 (𝟙 Y) ≫ f = lift 0 (𝟙 Y) ≫ g) :
f = g :=
BinaryCofan.IsColimit.hom_ext
(binaryBiconeIsBilimitOfLimitConeOfIsLimit (tensorProductIsBinaryProduct X Y)).isColimit h₁ h₂
/-- Auxiliary definition for `commGrpEquivalence`. -/
@[simps!]
def commGrpEquivalenceAux : CommGrp.forget C ⋙ toCommGrp C ≅
𝟭 (CommGrp C) := by
refine NatIso.ofComponents (fun _ => CommGrp.mkIso (Iso.refl _) ?_ ?_) ?_
· exact ((IsZero.iff_id_eq_zero _).2 (Subsingleton.elim _ _)).eq_of_src _ _
· simp only [Functor.comp_obj, CommGrp.forget_obj, toCommGrp_obj_X, Functor.id_obj,
toCommGrp_obj_grp, mul_def, Iso.refl_hom, Category.comp_id, tensorHom_id, id_whiskerRight,
Category.id_comp]
apply monoidal_hom_ext
· simp only [comp_add, lift_fst, lift_snd, add_zero]
convert (MonObj.lift_comp_one_right _ 0).symm
· simp
· infer_instance
· simp only [comp_add, lift_fst, lift_snd, zero_add]
convert (MonObj.lift_comp_one_left 0 _).symm
· simp
· infer_instance
· cat_disch
/-- An additive category is equivalent to its category of commutative group objects. -/
@[simps!]
def commGrpEquivalence : C ≌ CommGrp C where
functor := toCommGrp C
inverse := CommGrp.forget C
unitIso := Iso.refl _
counitIso := commGrpEquivalenceAux
end CategoryTheory.Preadditive |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Basic.lean | import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Group.Action.Units
import Mathlib.Algebra.Module.End
import Mathlib.CategoryTheory.Endomorphism
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
import Mathlib.Algebra.BigOperators.Group.Finset.Defs
/-!
# Preadditive categories
A preadditive category is a category in which `X ⟶ Y` is an abelian group in such a way that
composition of morphisms is linear in both variables.
This file contains a definition of preadditive category that directly encodes the definition given
above. The definition could also be phrased as follows: A preadditive category is a category
enriched over the category of Abelian groups. Once the general framework to state this in Lean is
available, the contents of this file should become obsolete.
## Main results
* Definition of preadditive categories and basic properties
* In a preadditive category, `f : Q ⟶ R` is mono if and only if `g ≫ f = 0 → g = 0` for all
composable `g`.
* A preadditive category with kernels has equalizers.
## Implementation notes
The simp normal form for negation and composition is to push negations as far as possible to
the outside. For example, `f ≫ (-g)` and `(-f) ≫ g` both become `-(f ≫ g)`, and `(-f) ≫ (-g)`
is simplified to `f ≫ g`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
## Tags
additive, preadditive, Hom group, Ab-category, Ab-enriched
-/
universe v u
open CategoryTheory.Limits
namespace CategoryTheory
variable (C : Type u) [Category.{v} C]
/-- A category is called preadditive if `P ⟶ Q` is an abelian group such that composition is
linear in both variables. -/
@[stacks 00ZY]
class Preadditive where
homGroup : ∀ P Q : C, AddCommGroup (P ⟶ Q) := by infer_instance
add_comp : ∀ (P Q R : C) (f f' : P ⟶ Q) (g : Q ⟶ R), (f + f') ≫ g = f ≫ g + f' ≫ g := by
cat_disch
comp_add : ∀ (P Q R : C) (f : P ⟶ Q) (g g' : Q ⟶ R), f ≫ (g + g') = f ≫ g + f ≫ g' := by
cat_disch
attribute [inherit_doc Preadditive] Preadditive.homGroup Preadditive.add_comp Preadditive.comp_add
attribute [instance] Preadditive.homGroup
-- simp can already prove reassoc version
attribute [reassoc, simp] Preadditive.add_comp
attribute [reassoc] Preadditive.comp_add
attribute [simp] Preadditive.comp_add
end CategoryTheory
open CategoryTheory
namespace CategoryTheory
namespace Preadditive
section Preadditive
open AddMonoidHom
variable {C : Type u} [Category.{v} C] [Preadditive C]
section InducedCategory
universe u'
variable {D : Type u'} (F : D → C)
instance inducedCategory : Preadditive.{v} (InducedCategory C F) where
homGroup P Q := @Preadditive.homGroup C _ _ (F P) (F Q)
add_comp _ _ _ _ _ _ := add_comp _ _ _ _ _ _
comp_add _ _ _ _ _ _ := comp_add _ _ _ _ _ _
end InducedCategory
instance fullSubcategory (Z : ObjectProperty C) : Preadditive Z.FullSubcategory where
homGroup P Q := @Preadditive.homGroup C _ _ P.obj Q.obj
add_comp _ _ _ _ _ _ := add_comp _ _ _ _ _ _
comp_add _ _ _ _ _ _ := comp_add _ _ _ _ _ _
instance (X : C) : AddCommGroup (End X) := by
dsimp [End]
infer_instance
/-- Composition by a fixed left argument as a group homomorphism -/
def leftComp {P Q : C} (R : C) (f : P ⟶ Q) : (Q ⟶ R) →+ (P ⟶ R) :=
mk' (fun g => f ≫ g) fun g g' => by simp
/-- Composition by a fixed right argument as a group homomorphism -/
def rightComp (P : C) {Q R : C} (g : Q ⟶ R) : (P ⟶ Q) →+ (P ⟶ R) :=
mk' (fun f => f ≫ g) fun f f' => by simp
variable {P Q R : C} (f f' : P ⟶ Q) (g g' : Q ⟶ R)
/-- Composition as a bilinear group homomorphism -/
def compHom : (P ⟶ Q) →+ (Q ⟶ R) →+ (P ⟶ R) :=
AddMonoidHom.mk' (fun f => leftComp _ f) fun f₁ f₂ =>
AddMonoidHom.ext fun g => (rightComp _ g).map_add f₁ f₂
-- simp can prove the reassoc version
@[reassoc, simp]
theorem sub_comp : (f - f') ≫ g = f ≫ g - f' ≫ g :=
map_sub (rightComp P g) f f'
-- simp can prove the reassoc version
@[reassoc, simp]
theorem comp_sub : f ≫ (g - g') = f ≫ g - f ≫ g' :=
map_sub (leftComp R f) g g'
-- simp can prove the reassoc version
@[reassoc, simp]
theorem neg_comp : (-f) ≫ g = -f ≫ g :=
map_neg (rightComp P g) f
-- simp can prove the reassoc version
@[reassoc, simp]
theorem comp_neg : f ≫ (-g) = -f ≫ g :=
map_neg (leftComp R f) g
@[reassoc]
theorem neg_comp_neg : (-f) ≫ (-g) = f ≫ g := by simp
theorem nsmul_comp (n : ℕ) : (n • f) ≫ g = n • f ≫ g :=
map_nsmul (rightComp P g) n f
theorem comp_nsmul (n : ℕ) : f ≫ (n • g) = n • f ≫ g :=
map_nsmul (leftComp R f) n g
theorem zsmul_comp (n : ℤ) : (n • f) ≫ g = n • f ≫ g :=
map_zsmul (rightComp P g) n f
theorem comp_zsmul (n : ℤ) : f ≫ (n • g) = n • f ≫ g :=
map_zsmul (leftComp R f) n g
@[reassoc]
theorem comp_sum {P Q R : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (Q ⟶ R)) :
(f ≫ ∑ j ∈ s, g j) = ∑ j ∈ s, f ≫ g j :=
map_sum (leftComp R f) _ _
@[reassoc]
theorem sum_comp {P Q R : C} {J : Type*} (s : Finset J) (f : J → (P ⟶ Q)) (g : Q ⟶ R) :
(∑ j ∈ s, f j) ≫ g = ∑ j ∈ s, f j ≫ g :=
map_sum (rightComp P g) _ _
@[reassoc]
theorem sum_comp' {P Q R S : C} {J : Type*} (s : Finset J) (f : J → (P ⟶ Q)) (g : J → (Q ⟶ R))
(h : R ⟶ S) : (∑ j ∈ s, f j ≫ g j) ≫ h = ∑ j ∈ s, f j ≫ g j ≫ h := by
simp only [← Category.assoc]
apply sum_comp
instance {P Q : C} {f : P ⟶ Q} [Epi f] : Epi (-f) :=
⟨fun g g' H => by rwa [neg_comp, neg_comp, ← comp_neg, ← comp_neg, cancel_epi, neg_inj] at H⟩
instance {P Q : C} {f : P ⟶ Q} [Mono f] : Mono (-f) :=
⟨fun g g' H => by rwa [comp_neg, comp_neg, ← neg_comp, ← neg_comp, cancel_mono, neg_inj] at H⟩
instance (priority := 100) preadditiveHasZeroMorphisms : HasZeroMorphisms C where
zero := inferInstance
comp_zero f R := show leftComp R f 0 = 0 from map_zero _
zero_comp P _ _ f := show rightComp P f 0 = 0 from map_zero _
/-- This instance is split off from the `Ring (End X)` instance to speed up instance search. -/
instance {X : C} : Semiring (End X) :=
{ End.monoid with
zero_mul := fun f => by dsimp [mul]; exact HasZeroMorphisms.comp_zero f _
mul_zero := fun f => by dsimp [mul]; exact HasZeroMorphisms.zero_comp _ f
left_distrib := fun f g h => Preadditive.add_comp X X X g h f
right_distrib := fun f g h => Preadditive.comp_add X X X h f g }
instance {X : C} : Ring (End X) :=
{ (inferInstance : Semiring (End X)),
(inferInstance : AddCommGroup (End X)) with
neg_add_cancel := neg_add_cancel }
instance moduleEndRight {X Y : C} : Module (End Y) (X ⟶ Y) where
smul_add _ _ _ := add_comp _ _ _ _ _ _
smul_zero _ := zero_comp
add_smul _ _ _ := comp_add _ _ _ _ _ _
zero_smul _ := comp_zero
theorem mono_of_cancel_zero {Q R : C} (f : Q ⟶ R) (h : ∀ {P : C} (g : P ⟶ Q), g ≫ f = 0 → g = 0) :
Mono f where
right_cancellation := fun {Z} g₁ g₂ hg =>
sub_eq_zero.1 <| h _ <| (map_sub (rightComp Z f) g₁ g₂).trans <| sub_eq_zero.2 hg
theorem mono_iff_cancel_zero {Q R : C} (f : Q ⟶ R) :
Mono f ↔ ∀ (P : C) (g : P ⟶ Q), g ≫ f = 0 → g = 0 :=
⟨fun _ _ _ => zero_of_comp_mono _, mono_of_cancel_zero f⟩
theorem mono_of_kernel_zero {X Y : C} {f : X ⟶ Y} [HasLimit (parallelPair f 0)]
(w : kernel.ι f = 0) : Mono f :=
mono_of_cancel_zero f fun g h => by rw [← kernel.lift_ι f g h, w, Limits.comp_zero]
lemma mono_of_isZero_kernel' {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hc : IsLimit c)
(h : IsZero c.pt) : Mono f := mono_of_cancel_zero _ (fun g hg => by
obtain ⟨a, ha⟩ := KernelFork.IsLimit.lift' hc _ hg
rw [← ha, h.eq_of_tgt a 0, Limits.zero_comp])
lemma mono_iff_isZero_kernel' {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hc : IsLimit c) :
Mono f ↔ IsZero c.pt :=
⟨fun _ ↦ KernelFork.IsLimit.isZero_of_mono hc, mono_of_isZero_kernel' c hc⟩
lemma mono_of_isZero_kernel {X Y : C} (f : X ⟶ Y) [HasKernel f] (h : IsZero (kernel f)) :
Mono f :=
mono_of_isZero_kernel' _ (kernelIsKernel _) h
lemma mono_iff_isZero_kernel {X Y : C} (f : X ⟶ Y) [HasKernel f] :
Mono f ↔ IsZero (kernel f) :=
mono_iff_isZero_kernel' _ (limit.isLimit _)
theorem epi_of_cancel_zero {P Q : C} (f : P ⟶ Q) (h : ∀ {R : C} (g : Q ⟶ R), f ≫ g = 0 → g = 0) :
Epi f :=
⟨fun {Z} g g' hg =>
sub_eq_zero.1 <| h _ <| (map_sub (leftComp Z f) g g').trans <| sub_eq_zero.2 hg⟩
theorem epi_iff_cancel_zero {P Q : C} (f : P ⟶ Q) :
Epi f ↔ ∀ (R : C) (g : Q ⟶ R), f ≫ g = 0 → g = 0 :=
⟨fun _ _ _ => zero_of_epi_comp _, epi_of_cancel_zero f⟩
theorem epi_of_cokernel_zero {X Y : C} {f : X ⟶ Y} [HasColimit (parallelPair f 0)]
(w : cokernel.π f = 0) : Epi f :=
epi_of_cancel_zero f fun g h => by rw [← cokernel.π_desc f g h, w, Limits.zero_comp]
lemma epi_of_isZero_cokernel' {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (hc : IsColimit c)
(h : IsZero c.pt) : Epi f := epi_of_cancel_zero _ (fun g hg => by
obtain ⟨a, ha⟩ := CokernelCofork.IsColimit.desc' hc _ hg
rw [← ha, h.eq_of_src a 0, Limits.comp_zero])
lemma epi_iff_isZero_cokernel' {X Y : C} {f : X ⟶ Y} (c : CokernelCofork f) (hc : IsColimit c) :
Epi f ↔ IsZero c.pt :=
⟨fun _ ↦ CokernelCofork.IsColimit.isZero_of_epi hc, epi_of_isZero_cokernel' c hc⟩
lemma epi_of_isZero_cokernel {X Y : C} (f : X ⟶ Y) [HasCokernel f] (h : IsZero (cokernel f)) :
Epi f :=
epi_of_isZero_cokernel' _ (cokernelIsCokernel _) h
lemma epi_iff_isZero_cokernel {X Y : C} (f : X ⟶ Y) [HasCokernel f] :
Epi f ↔ IsZero (cokernel f) :=
epi_iff_isZero_cokernel' _ (colimit.isColimit _)
namespace IsIso
@[simp]
theorem comp_left_eq_zero [IsIso f] : f ≫ g = 0 ↔ g = 0 := by
rw [← IsIso.eq_inv_comp, Limits.comp_zero]
@[simp]
theorem comp_right_eq_zero [IsIso g] : f ≫ g = 0 ↔ f = 0 := by
rw [← IsIso.eq_comp_inv, Limits.zero_comp]
end IsIso
open ZeroObject
variable [HasZeroObject C]
theorem mono_of_kernel_iso_zero {X Y : C} {f : X ⟶ Y} [HasLimit (parallelPair f 0)]
(w : kernel f ≅ 0) : Mono f :=
mono_of_kernel_zero (zero_of_source_iso_zero _ w)
theorem epi_of_cokernel_iso_zero {X Y : C} {f : X ⟶ Y} [HasColimit (parallelPair f 0)]
(w : cokernel f ≅ 0) : Epi f :=
epi_of_cokernel_zero (zero_of_target_iso_zero _ w)
end Preadditive
section Equalizers
variable {C : Type u} [Category.{v} C] [Preadditive C]
section
variable {X Y : C} {f : X ⟶ Y} {g : X ⟶ Y}
/-- Map a kernel cone on the difference of two morphisms to the equalizer fork. -/
@[simps! pt]
def forkOfKernelFork (c : KernelFork (f - g)) : Fork f g :=
Fork.ofι c.ι <| by rw [← sub_eq_zero, ← comp_sub, c.condition]
@[simp]
theorem forkOfKernelFork_ι (c : KernelFork (f - g)) : (forkOfKernelFork c).ι = c.ι :=
rfl
/-- Map any equalizer fork to a cone on the difference of the two morphisms. -/
def kernelForkOfFork (c : Fork f g) : KernelFork (f - g) :=
Fork.ofι c.ι <| by rw [comp_sub, comp_zero, sub_eq_zero, c.condition]
@[simp]
theorem kernelForkOfFork_ι (c : Fork f g) : (kernelForkOfFork c).ι = c.ι :=
rfl
@[simp]
theorem kernelForkOfFork_ofι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) :
kernelForkOfFork (Fork.ofι ι w) = KernelFork.ofι ι (by simp [w]) :=
rfl
/-- A kernel of `f - g` is an equalizer of `f` and `g`. -/
def isLimitForkOfKernelFork {c : KernelFork (f - g)} (i : IsLimit c) :
IsLimit (forkOfKernelFork c) :=
Fork.IsLimit.mk' _ fun s =>
⟨i.lift (kernelForkOfFork s), i.fac _ _, fun h => by apply Fork.IsLimit.hom_ext i; cat_disch⟩
@[simp]
theorem isLimitForkOfKernelFork_lift {c : KernelFork (f - g)} (i : IsLimit c) (s : Fork f g) :
(isLimitForkOfKernelFork i).lift s = i.lift (kernelForkOfFork s) :=
rfl
/-- An equalizer of `f` and `g` is a kernel of `f - g`. -/
def isLimitKernelForkOfFork {c : Fork f g} (i : IsLimit c) : IsLimit (kernelForkOfFork c) :=
Fork.IsLimit.mk' _ fun s =>
⟨i.lift (forkOfKernelFork s), i.fac _ _, fun h => by apply Fork.IsLimit.hom_ext i; cat_disch⟩
variable (f g)
/-- A preadditive category has an equalizer for `f` and `g` if it has a kernel for `f - g`. -/
theorem hasEqualizer_of_hasKernel [HasKernel (f - g)] : HasEqualizer f g :=
HasLimit.mk
{ cone := forkOfKernelFork _
isLimit := isLimitForkOfKernelFork (equalizerIsEqualizer (f - g) 0) }
/-- A preadditive category has a kernel for `f - g` if it has an equalizer for `f` and `g`. -/
theorem hasKernel_of_hasEqualizer [HasEqualizer f g] : HasKernel (f - g) :=
HasLimit.mk
{ cone := kernelForkOfFork (equalizer.fork f g)
isLimit := isLimitKernelForkOfFork (limit.isLimit (parallelPair f g)) }
variable {f g}
/-- Map a cokernel cocone on the difference of two morphisms to the coequalizer cofork. -/
@[simps! pt]
def coforkOfCokernelCofork (c : CokernelCofork (f - g)) : Cofork f g :=
Cofork.ofπ c.π <| by rw [← sub_eq_zero, ← sub_comp, c.condition]
@[simp]
theorem coforkOfCokernelCofork_π (c : CokernelCofork (f - g)) :
(coforkOfCokernelCofork c).π = c.π :=
rfl
/-- Map any coequalizer cofork to a cocone on the difference of the two morphisms. -/
def cokernelCoforkOfCofork (c : Cofork f g) : CokernelCofork (f - g) :=
Cofork.ofπ c.π <| by rw [sub_comp, zero_comp, sub_eq_zero, c.condition]
@[simp]
theorem cokernelCoforkOfCofork_π (c : Cofork f g) : (cokernelCoforkOfCofork c).π = c.π :=
rfl
@[simp]
theorem cokernelCoforkOfCofork_ofπ {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) :
cokernelCoforkOfCofork (Cofork.ofπ π w) = CokernelCofork.ofπ π (by simp [w]) :=
rfl
/-- A cokernel of `f - g` is a coequalizer of `f` and `g`. -/
def isColimitCoforkOfCokernelCofork {c : CokernelCofork (f - g)} (i : IsColimit c) :
IsColimit (coforkOfCokernelCofork c) :=
Cofork.IsColimit.mk' _ fun s =>
⟨i.desc (cokernelCoforkOfCofork s), i.fac _ _, fun h => by
apply Cofork.IsColimit.hom_ext i; cat_disch⟩
@[simp]
theorem isColimitCoforkOfCokernelCofork_desc {c : CokernelCofork (f - g)} (i : IsColimit c)
(s : Cofork f g) :
(isColimitCoforkOfCokernelCofork i).desc s = i.desc (cokernelCoforkOfCofork s) :=
rfl
/-- A coequalizer of `f` and `g` is a cokernel of `f - g`. -/
def isColimitCokernelCoforkOfCofork {c : Cofork f g} (i : IsColimit c) :
IsColimit (cokernelCoforkOfCofork c) :=
Cofork.IsColimit.mk' _ fun s =>
⟨i.desc (coforkOfCokernelCofork s), i.fac _ _, fun h => by
apply Cofork.IsColimit.hom_ext i; cat_disch⟩
variable (f g)
/-- A preadditive category has a coequalizer for `f` and `g` if it has a cokernel for `f - g`. -/
theorem hasCoequalizer_of_hasCokernel [HasCokernel (f - g)] : HasCoequalizer f g :=
HasColimit.mk
{ cocone := coforkOfCokernelCofork _
isColimit := isColimitCoforkOfCokernelCofork (coequalizerIsCoequalizer (f - g) 0) }
/-- A preadditive category has a cokernel for `f - g` if it has a coequalizer for `f` and `g`. -/
theorem hasCokernel_of_hasCoequalizer [HasCoequalizer f g] : HasCokernel (f - g) :=
HasColimit.mk
{ cocone := cokernelCoforkOfCofork (coequalizer.cofork f g)
isColimit := isColimitCokernelCoforkOfCofork (colimit.isColimit (parallelPair f g)) }
end
/-- If a preadditive category has all kernels, then it also has all equalizers. -/
theorem hasEqualizers_of_hasKernels [HasKernels C] : HasEqualizers C :=
@hasEqualizers_of_hasLimit_parallelPair _ _ fun {_} {_} f g => hasEqualizer_of_hasKernel f g
/-- If a preadditive category has all cokernels, then it also has all coequalizers. -/
theorem hasCoequalizers_of_hasCokernels [HasCokernels C] : HasCoequalizers C :=
@hasCoequalizers_of_hasColimit_parallelPair _ _ fun {_} {_} f g =>
hasCoequalizer_of_hasCokernel f g
end Equalizers
section
variable {C : Type*} [Category C] [Preadditive C] {X Y : C}
instance : SMul (Units ℤ) (X ≅ Y) where
smul a e :=
{ hom := (a : ℤ) • e.hom
inv := ((a⁻¹ : Units ℤ) : ℤ) • e.inv
hom_inv_id := by
simp only [comp_zsmul, zsmul_comp, smul_smul, Units.inv_mul, one_smul, e.hom_inv_id]
inv_hom_id := by
simp only [comp_zsmul, zsmul_comp, smul_smul, Units.mul_inv, one_smul, e.inv_hom_id] }
@[simp]
lemma smul_iso_hom (a : Units ℤ) (e : X ≅ Y) : (a • e).hom = a • e.hom := rfl
@[simp]
lemma smul_iso_inv (a : Units ℤ) (e : X ≅ Y) : (a • e).inv = a⁻¹ • e.inv := rfl
instance : Neg (X ≅ Y) where
neg e :=
{ hom := -e.hom
inv := -e.inv }
@[simp]
lemma neg_iso_hom (e : X ≅ Y) : (-e).hom = -e.hom := rfl
@[simp]
lemma neg_iso_inv (e : X ≅ Y) : (-e).inv = -e.inv := rfl
end
end Preadditive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Schur.lean | import Mathlib.Algebra.Group.Ext
import Mathlib.CategoryTheory.Simple
import Mathlib.CategoryTheory.Linear.Basic
import Mathlib.CategoryTheory.Endomorphism
import Mathlib.FieldTheory.IsAlgClosed.Spectrum
/-!
# Schur's lemma
We first prove the part of Schur's Lemma that holds in any preadditive category with kernels,
that any nonzero morphism between simple objects
is an isomorphism.
Second, we prove Schur's lemma for `𝕜`-linear categories with finite-dimensional hom spaces,
over an algebraically closed field `𝕜`:
the hom space `X ⟶ Y` between simple objects `X` and `Y` is at most one dimensional,
and is 1-dimensional iff `X` and `Y` are isomorphic.
-/
namespace CategoryTheory
open CategoryTheory.Limits
variable {C : Type*} [Category C]
variable [Preadditive C]
-- See also `epi_of_nonzero_to_simple`, which does not require `Preadditive C`.
theorem mono_of_nonzero_from_simple [HasKernels C] {X Y : C} [Simple X] {f : X ⟶ Y} (w : f ≠ 0) :
Mono f :=
Preadditive.mono_of_kernel_zero (kernel_zero_of_nonzero_from_simple w)
/-- The part of **Schur's lemma** that holds in any preadditive category with kernels:
that a nonzero morphism between simple objects is an isomorphism.
-/
theorem isIso_of_hom_simple
[HasKernels C] {X Y : C} [Simple X] [Simple Y] {f : X ⟶ Y} (w : f ≠ 0) : IsIso f :=
haveI := mono_of_nonzero_from_simple w
isIso_of_mono_of_nonzero w
/-- As a corollary of Schur's lemma for preadditive categories,
any morphism between simple objects is (exclusively) either an isomorphism or zero.
-/
theorem isIso_iff_nonzero [HasKernels C] {X Y : C} [Simple X] [Simple Y] (f : X ⟶ Y) :
IsIso f ↔ f ≠ 0 :=
⟨fun I => by
intro h
apply id_nonzero X
simp only [← IsIso.hom_inv_id f, h, zero_comp],
fun w => isIso_of_hom_simple w⟩
open scoped Classical in
/-- In any preadditive category with kernels,
the endomorphisms of a simple object form a division ring. -/
noncomputable instance [HasKernels C] {X : C} [Simple X] : DivisionRing (End X) where
inv f := if h : f = 0 then 0 else haveI := isIso_of_hom_simple h; inv f
exists_pair_ne := ⟨𝟙 X, 0, id_nonzero _⟩
inv_zero := dif_pos rfl
mul_inv_cancel f hf := by
dsimp
rw [dif_neg hf]
haveI := isIso_of_hom_simple hf
exact IsIso.inv_hom_id f
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
qsmul := _
qsmul_def := fun _ _ => rfl
open Module
section
variable (𝕜 : Type*) [DivisionRing 𝕜]
/-- Part of **Schur's lemma** for `𝕜`-linear categories:
the hom space between two non-isomorphic simple objects is 0-dimensional.
-/
theorem finrank_hom_simple_simple_eq_zero_of_not_iso [HasKernels C] [Linear 𝕜 C] {X Y : C}
[Simple X] [Simple Y] (h : (X ≅ Y) → False) : finrank 𝕜 (X ⟶ Y) = 0 :=
haveI :=
subsingleton_of_forall_eq (0 : X ⟶ Y) fun f => by
have p := not_congr (isIso_iff_nonzero f)
simp only [Classical.not_not, Ne] at p
exact p.mp fun _ => h (asIso f)
finrank_zero_of_subsingleton
end
variable (𝕜 : Type*) [Field 𝕜]
variable [IsAlgClosed 𝕜] [Linear 𝕜 C]
-- We prove this with the explicit `isIso_iff_nonzero` assumption,
-- rather than just `[Simple X]`, as this form is useful for
-- Müger's formulation of semisimplicity.
/-- An auxiliary lemma for Schur's lemma.
If `X ⟶ X` is finite dimensional, and every nonzero endomorphism is invertible,
then `X ⟶ X` is 1-dimensional.
-/
theorem finrank_endomorphism_eq_one {X : C} (isIso_iff_nonzero : ∀ f : X ⟶ X, IsIso f ↔ f ≠ 0)
[I : FiniteDimensional 𝕜 (X ⟶ X)] : finrank 𝕜 (X ⟶ X) = 1 := by
have id_nonzero := (isIso_iff_nonzero (𝟙 X)).mp (by infer_instance)
refine finrank_eq_one (𝟙 X) id_nonzero ?_
intro f
have : Nontrivial (End X) := nontrivial_of_ne _ _ id_nonzero
have : FiniteDimensional 𝕜 (End X) := I
obtain ⟨c, nu⟩ := spectrum.nonempty_of_isAlgClosed_of_finiteDimensional 𝕜 (End.of f)
use c
rw [spectrum.mem_iff, IsUnit.sub_iff, isUnit_iff_isIso, isIso_iff_nonzero, Ne,
Classical.not_not, sub_eq_zero, Algebra.algebraMap_eq_smul_one] at nu
exact nu.symm
variable [HasKernels C]
/-- **Schur's lemma** for endomorphisms in `𝕜`-linear categories.
-/
theorem finrank_endomorphism_simple_eq_one (X : C) [Simple X] [FiniteDimensional 𝕜 (X ⟶ X)] :
finrank 𝕜 (X ⟶ X) = 1 :=
finrank_endomorphism_eq_one 𝕜 isIso_iff_nonzero
theorem endomorphism_simple_eq_smul_id {X : C} [Simple X] [FiniteDimensional 𝕜 (X ⟶ X)]
(f : X ⟶ X) : ∃ c : 𝕜, c • 𝟙 X = f :=
(finrank_eq_one_iff_of_nonzero' (𝟙 X) (id_nonzero X)).mp (finrank_endomorphism_simple_eq_one 𝕜 X)
f
/-- Endomorphisms of a simple object form a field if they are finite dimensional.
This can't be an instance as `𝕜` would be undetermined.
-/
noncomputable def fieldEndOfFiniteDimensional (X : C) [Simple X] [I : FiniteDimensional 𝕜 (X ⟶ X)] :
Field (End X) := by
classical exact
{ (inferInstance : DivisionRing (End X)) with
mul_comm := fun f g => by
obtain ⟨c, rfl⟩ := endomorphism_simple_eq_smul_id 𝕜 f
obtain ⟨d, rfl⟩ := endomorphism_simple_eq_smul_id 𝕜 g
simp [← mul_smul, mul_comm c d] }
-- There is a symmetric argument that uses `[FiniteDimensional 𝕜 (Y ⟶ Y)]` instead,
-- but we don't bother proving that here.
/-- **Schur's lemma** for `𝕜`-linear categories:
if hom spaces are finite dimensional, then the hom space between simples is at most 1-dimensional.
See `finrank_hom_simple_simple_eq_one_iff` and `finrank_hom_simple_simple_eq_zero_iff` below
for the refinements when we know whether or not the simples are isomorphic.
-/
theorem finrank_hom_simple_simple_le_one (X Y : C) [FiniteDimensional 𝕜 (X ⟶ X)] [Simple X]
[Simple Y] : finrank 𝕜 (X ⟶ Y) ≤ 1 := by
obtain (h|h) := subsingleton_or_nontrivial (X ⟶ Y)
· rw [finrank_zero_of_subsingleton]
exact zero_le_one
· obtain ⟨f, nz⟩ := (nontrivial_iff_exists_ne 0).mp h
haveI fi := (isIso_iff_nonzero f).mpr nz
refine finrank_le_one f ?_
intro g
obtain ⟨c, w⟩ := endomorphism_simple_eq_smul_id 𝕜 (g ≫ inv f)
exact ⟨c, by simpa using w =≫ f⟩
theorem finrank_hom_simple_simple_eq_one_iff (X Y : C) [FiniteDimensional 𝕜 (X ⟶ X)]
[FiniteDimensional 𝕜 (X ⟶ Y)] [Simple X] [Simple Y] :
finrank 𝕜 (X ⟶ Y) = 1 ↔ Nonempty (X ≅ Y) := by
fconstructor
· intro h
rw [finrank_eq_one_iff'] at h
obtain ⟨f, nz, -⟩ := h
rw [← isIso_iff_nonzero] at nz
exact ⟨asIso f⟩
· rintro ⟨f⟩
have le_one := finrank_hom_simple_simple_le_one 𝕜 X Y
have zero_lt : 0 < finrank 𝕜 (X ⟶ Y) :=
finrank_pos_iff_exists_ne_zero.mpr ⟨f.hom, (isIso_iff_nonzero f.hom).mp inferInstance⟩
cutsat
theorem finrank_hom_simple_simple_eq_zero_iff (X Y : C) [FiniteDimensional 𝕜 (X ⟶ X)]
[FiniteDimensional 𝕜 (X ⟶ Y)] [Simple X] [Simple Y] :
finrank 𝕜 (X ⟶ Y) = 0 ↔ IsEmpty (X ≅ Y) := by
rw [← not_nonempty_iff, ← not_congr (finrank_hom_simple_simple_eq_one_iff 𝕜 X Y)]
have := finrank_hom_simple_simple_le_one 𝕜 X Y
cutsat
open scoped Classical in
theorem finrank_hom_simple_simple (X Y : C) [∀ X Y : C, FiniteDimensional 𝕜 (X ⟶ Y)] [Simple X]
[Simple Y] : finrank 𝕜 (X ⟶ Y) = if Nonempty (X ≅ Y) then 1 else 0 := by
split_ifs with h
· exact (finrank_hom_simple_simple_eq_one_iff 𝕜 X Y).2 h
· exact (finrank_hom_simple_simple_eq_zero_iff 𝕜 X Y).2 (not_nonempty_iff.mp h)
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/LiftToFinset.lean | import Mathlib.CategoryTheory.Limits.Constructions.Filtered
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Additional results about the `liftToFinset` construction
If `f` is a family of objects of `C`, then there is a canonical cocone whose cocone point is the
coproduct of `f` and whose legs are given by the inclusions of the finite subcoproducts. If `C`
is preadditive, then we can describe the legs of this cocone as finite sums of projections followed
by inclusions.
-/
universe w v u
namespace CategoryTheory.Limits
variable {C : Type u} [Category.{v} C] [Preadditive C]
namespace CoproductsFromFiniteFiltered
variable [HasFiniteCoproducts C]
theorem finiteSubcoproductsCocone_ι_app_eq_sum {α : Type w} [DecidableEq α] (f : α → C)
[HasCoproduct f] (S : Finset (Discrete α)) :
(finiteSubcoproductsCocone f).ι.app S = ∑ a ∈ S.attach, Sigma.π _ a ≫ Sigma.ι _ a.1.as := by
dsimp only [liftToFinsetObj_obj, Discrete.functor_obj_eq_as, finiteSubcoproductsCocone_pt,
Functor.const_obj_obj, finiteSubcoproductsCocone_ι_app]
ext v
simp only [colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app, Preadditive.comp_sum]
rw [Finset.sum_eq_single v]
· simp
· intro b hb hb₁
rw [Sigma.ι_π_of_ne_assoc _ (Ne.symm hb₁), zero_comp]
· simp
end CoproductsFromFiniteFiltered
namespace ProductsFromFiniteCofiltered
variable [HasFiniteProducts C]
theorem finiteSubproductsCocone_π_app_eq_sum {α : Type w} [DecidableEq α] (f : α → C) [HasProduct f]
(S : (Finset (Discrete α))ᵒᵖ) :
(finiteSubproductsCone f).π.app S =
∑ a ∈ S.unop.attach, Pi.π f a.1.as ≫ Pi.ι (fun a => f a.1.as) a := by
dsimp only [finiteSubproductsCone_pt, Functor.const_obj_obj, liftToFinsetObj_obj,
Discrete.functor_obj_eq_as, finiteSubproductsCone_π_app]
ext v
simp only [limit.lift_π, Fan.mk_pt, Fan.mk_π_app, Preadditive.sum_comp, Category.assoc]
rw [Finset.sum_eq_single v]
· simp
· intro b hb hb₁
rw [Pi.ι_π_of_ne _ hb₁, comp_zero]
· simp
end ProductsFromFiniteCofiltered
end CategoryTheory.Limits |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/SingleObj.lean | import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.SingleObj
/-!
# `SingleObj α` is preadditive when `α` is a ring.
-/
namespace CategoryTheory
variable {α : Type*} [Ring α]
instance : Preadditive (SingleObj α) where
add_comp _ _ _ f f' g := mul_add g f f'
comp_add _ _ _ f g g' := add_mul g g' f
-- TODO define `PreAddCat` (with additive functors as morphisms), and `Ring ⥤ PreAddCat`.
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/EndoFunctor.lean | import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Endofunctor.Algebra
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# Preadditive structure on algebras over a monad
If `C` is a preadditive category and `F` is an additive endofunctor on `C` then `Algebra F` is
also preadditive. Dually, the category `Coalgebra F` is also preadditive.
-/
universe v₁ u₁
-- morphism levels before object levels. See note [category_theory universes].
namespace CategoryTheory
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C] (F : C ⥤ C) [Functor.Additive (F : C ⥤ C)]
open CategoryTheory.Limits Preadditive
/-- The category of algebras over an additive endofunctor on a preadditive category is preadditive.
-/
@[simps]
instance Endofunctor.algebraPreadditive : Preadditive (Endofunctor.Algebra F) where
homGroup A₁ A₂ :=
{ add := fun α β =>
{ f := α.f + β.f
h := by simp only [Functor.map_add, add_comp, Endofunctor.Algebra.Hom.h, comp_add] }
zero :=
{ f := 0
h := by simp only [Functor.map_zero, zero_comp, comp_zero] }
nsmul := fun n α =>
{ f := n • α.f
h := by rw [comp_nsmul, Functor.map_nsmul, nsmul_comp, Endofunctor.Algebra.Hom.h] }
neg := fun α =>
{ f := -α.f
h := by simp only [Functor.map_neg, neg_comp, Endofunctor.Algebra.Hom.h, comp_neg] }
sub := fun α β =>
{ f := α.f - β.f
h := by simp only [Functor.map_sub, sub_comp, Endofunctor.Algebra.Hom.h, comp_sub] }
zsmul := fun r α =>
{ f := r • α.f
h := by rw [comp_zsmul, Functor.map_zsmul, zsmul_comp, Endofunctor.Algebra.Hom.h] }
add_assoc := by
intros
apply Algebra.Hom.ext
apply add_assoc
zero_add := by
intros
apply Algebra.Hom.ext
apply zero_add
add_zero := by
intros
apply Algebra.Hom.ext
apply add_zero
nsmul_zero := by
intros
apply Algebra.Hom.ext
apply zero_smul
nsmul_succ := by
intros
apply Algebra.Hom.ext
apply succ_nsmul
sub_eq_add_neg := by
intros
apply Algebra.Hom.ext
apply sub_eq_add_neg
zsmul_zero' := by
intros
apply Algebra.Hom.ext
apply zero_smul
zsmul_succ' := by
intros
apply Algebra.Hom.ext
simp only [natCast_zsmul, succ_nsmul]
rfl
zsmul_neg' := by
intros
apply Algebra.Hom.ext
simp only [negSucc_zsmul, ← Nat.cast_smul_eq_nsmul ℤ]
neg_add_cancel := by
intros
apply Algebra.Hom.ext
apply neg_add_cancel
add_comm := by
intros
apply Algebra.Hom.ext
apply add_comm }
add_comp := by
intros
apply Algebra.Hom.ext
apply add_comp
comp_add := by
intros
apply Algebra.Hom.ext
apply comp_add
instance Algebra.forget_additive : (Endofunctor.Algebra.forget F).Additive where
@[simps]
instance Endofunctor.coalgebraPreadditive : Preadditive (Endofunctor.Coalgebra F) where
homGroup A₁ A₂ :=
{ add := fun α β =>
{ f := α.f + β.f
h := by simp only [Functor.map_add, comp_add, Endofunctor.Coalgebra.Hom.h, add_comp] }
zero :=
{ f := 0
h := by simp only [Functor.map_zero, zero_comp, comp_zero] }
nsmul := fun n α =>
{ f := n • α.f
h := by rw [Functor.map_nsmul, comp_nsmul, Endofunctor.Coalgebra.Hom.h, nsmul_comp] }
neg := fun α =>
{ f := -α.f
h := by simp only [Functor.map_neg, comp_neg, Endofunctor.Coalgebra.Hom.h, neg_comp] }
sub := fun α β =>
{ f := α.f - β.f
h := by simp only [Functor.map_sub, comp_sub, Endofunctor.Coalgebra.Hom.h, sub_comp] }
zsmul := fun r α =>
{ f := r • α.f
h := by rw [Functor.map_zsmul, comp_zsmul, Endofunctor.Coalgebra.Hom.h, zsmul_comp] }
add_assoc := by
intros
apply Coalgebra.Hom.ext
apply add_assoc
zero_add := by
intros
apply Coalgebra.Hom.ext
apply zero_add
add_zero := by
intros
apply Coalgebra.Hom.ext
apply add_zero
nsmul_zero := by
intros
apply Coalgebra.Hom.ext
apply zero_smul
nsmul_succ := by
intros
apply Coalgebra.Hom.ext
apply succ_nsmul
sub_eq_add_neg := by
intros
apply Coalgebra.Hom.ext
apply sub_eq_add_neg
zsmul_zero' := by
intros
apply Coalgebra.Hom.ext
apply zero_smul
zsmul_succ' := by
intros
apply Coalgebra.Hom.ext
simp only [natCast_zsmul, succ_nsmul]
rfl
zsmul_neg' := by
intros
apply Coalgebra.Hom.ext
simp only [negSucc_zsmul, ← Nat.cast_smul_eq_nsmul ℤ]
neg_add_cancel := by
intros
apply Coalgebra.Hom.ext
apply neg_add_cancel
add_comm := by
intros
apply Coalgebra.Hom.ext
apply add_comm }
add_comp := by
intros
apply Coalgebra.Hom.ext
apply add_comp
comp_add := by
intros
apply Coalgebra.Hom.ext
apply comp_add
instance Coalgebra.forget_additive : (Endofunctor.Coalgebra.forget F).Additive where
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Transfer.lean | import Mathlib.Algebra.Group.TransferInstance
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# Pulling back a preadditive structure along a fully faithful functor
A preadditive structure on a category `D` transfers to a preadditive structure on `C` for a given
fully faithful functor `F : C ⥤ D`.
-/
namespace CategoryTheory
open Limits
universe v₁ v₂ u₁ u₂
variable {C : Type u₁} [Category.{v₁} C]
variable {D : Type u₂} [Category.{v₂} D] [Preadditive D]
variable {F : C ⥤ D} (hF : F.FullyFaithful)
namespace Preadditive
/-- If `D` is a preadditive category, any fully faithful functor `F : C ⥤ D` induces a preadditive
structure on `C`. -/
def ofFullyFaithful : Preadditive C where
homGroup P Q := hF.homEquiv.addCommGroup
add_comp P Q R f f' g := hF.map_injective (by simp [Equiv.add_def])
comp_add P Q R f g g' := hF.map_injective (by simp [Equiv.add_def])
end Preadditive
open Preadditive
namespace Functor.FullyFaithful
/-- The preadditive structure on `C` induced by a fully faithful functor `F : C ⥤ D` makes `F` an
additive functor. -/
lemma additive_ofFullyFaithful :
letI : Preadditive C := Preadditive.ofFullyFaithful hF
F.Additive :=
letI : Preadditive C := Preadditive.ofFullyFaithful hF
{ map_add := by simp [Equiv.add_def] }
end Functor.FullyFaithful
namespace Equivalence
/-- The preadditive structure on `C` induced by an equivalence `e : C ≌ D` makes `e.inverse` an
additive functor. -/
lemma additive_inverse_of_FullyFaithful (e : C ≌ D) :
letI : Preadditive C := ofFullyFaithful e.fullyFaithfulFunctor
e.inverse.Additive :=
letI : Preadditive C := ofFullyFaithful e.fullyFaithfulFunctor
letI : e.functor.Additive := e.fullyFaithfulFunctor.additive_ofFullyFaithful
e.inverse_additive
end Equivalence
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/HomOrthogonal.lean | import Mathlib.CategoryTheory.Linear.Basic
import Mathlib.CategoryTheory.Preadditive.Biproducts
import Mathlib.LinearAlgebra.Matrix.InvariantBasisNumber
import Mathlib.Data.Set.Subsingleton
/-!
# Hom orthogonal families.
A family of objects in a category with zero morphisms is "hom orthogonal" if the only
morphism between distinct objects is the zero morphism.
We show that in any category with zero morphisms and finite biproducts,
a morphism between biproducts drawn from a hom orthogonal family `s : ι → C`
can be decomposed into a block diagonal matrix with entries in the endomorphism rings of the `s i`.
When the category is preadditive, this decomposition is an additive equivalence,
and intertwines composition and matrix multiplication.
When the category is `R`-linear, the decomposition is an `R`-linear equivalence.
If every object in the hom orthogonal family has an endomorphism ring with invariant basis number
(e.g. if each object in the family is simple, so its endomorphism ring is a division ring,
or otherwise if each endomorphism ring is commutative),
then decompositions of an object as a biproduct of the family have uniquely defined multiplicities.
We state this as:
```
theorem HomOrthogonal.equiv_of_iso (o : HomOrthogonal s) {f : α → ι} {g : β → ι}
(i : (⨁ fun a => s (f a)) ≅ ⨁ fun b => s (g b)) : ∃ e : α ≃ β, ∀ a, g (e a) = f a
```
This is preliminary to defining semisimple categories.
-/
open Matrix CategoryTheory.Limits
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
/-- A family of objects is "hom orthogonal" if
there is at most one morphism between distinct objects.
(In a category with zero morphisms, that must be the zero morphism.) -/
def HomOrthogonal {ι : Type*} (s : ι → C) : Prop :=
Pairwise fun i j => Subsingleton (s i ⟶ s j)
namespace HomOrthogonal
variable {ι : Type*} {s : ι → C}
theorem eq_zero [HasZeroMorphisms C] (o : HomOrthogonal s) {i j : ι} (w : i ≠ j) (f : s i ⟶ s j) :
f = 0 :=
(o w).elim _ _
section
variable [HasZeroMorphisms C] [HasFiniteBiproducts C]
open scoped Classical in
/-- Morphisms between two direct sums over a hom orthogonal family `s : ι → C`
are equivalent to block diagonal matrices,
with blocks indexed by `ι`,
and matrix entries in `i`-th block living in the endomorphisms of `s i`. -/
@[simps]
noncomputable def matrixDecomposition (o : HomOrthogonal s) {α β : Type} [Finite α] [Finite β]
{f : α → ι} {g : β → ι} :
((⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b)) ≃
∀ i : ι, Matrix (g ⁻¹' {i}) (f ⁻¹' {i}) (End (s i)) where
toFun z i j k :=
eqToHom
(by
rcases k with ⟨k, ⟨⟩⟩
simp) ≫
biproduct.components z k j ≫
eqToHom
(by
rcases j with ⟨j, ⟨⟩⟩
simp)
invFun z :=
biproduct.matrix fun j k =>
if h : f j = g k then z (f j) ⟨k, by simp [h]⟩ ⟨j, by simp⟩ ≫ eqToHom (by simp [h]) else 0
left_inv z := by
ext j k
simp only [biproduct.matrix_π, biproduct.ι_desc]
split_ifs with h
· simp
rfl
· symm
apply o.eq_zero h
right_inv z := by
ext i ⟨j, w⟩ ⟨k, ⟨⟩⟩
simp only [eqToHom_refl, biproduct.matrix_components, Category.id_comp]
split_ifs with h
· simp
· exfalso
exact h w.symm
end
section
variable [Preadditive C] [HasFiniteBiproducts C]
/-- `HomOrthogonal.matrixDecomposition` as an additive equivalence. -/
@[simps!]
noncomputable def matrixDecompositionAddEquiv (o : HomOrthogonal s) {α β : Type} [Finite α]
[Finite β] {f : α → ι} {g : β → ι} :
((⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b)) ≃+
∀ i : ι, Matrix (g ⁻¹' {i}) (f ⁻¹' {i}) (End (s i)) :=
{ o.matrixDecomposition with
map_add' := fun w z => by
ext
dsimp [biproduct.components]
simp }
open scoped Classical in
@[simp]
theorem matrixDecomposition_id (o : HomOrthogonal s) {α : Type} [Finite α] {f : α → ι} (i : ι) :
o.matrixDecomposition (𝟙 (⨁ fun a => s (f a))) i = 1 := by
ext ⟨b, ⟨⟩⟩ ⟨a, j_property⟩
simp only [Set.mem_preimage, Set.mem_singleton_iff] at j_property
simp only [Category.comp_id, Category.id_comp, End.one_def, eqToHom_refl,
Matrix.one_apply, HomOrthogonal.matrixDecomposition_apply, biproduct.components]
split_ifs with h
· cases h
simp
· simp only [Subtype.mk.injEq] at h
convert comp_zero
simpa using biproduct.ι_π_ne _ (Ne.symm h)
open scoped Classical in
theorem matrixDecomposition_comp (o : HomOrthogonal s) {α β γ : Type} [Finite α] [Fintype β]
[Finite γ] {f : α → ι} {g : β → ι} {h : γ → ι} (z : (⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b))
(w : (⨁ fun b => s (g b)) ⟶ ⨁ fun c => s (h c)) (i : ι) :
o.matrixDecomposition (z ≫ w) i = o.matrixDecomposition w i * o.matrixDecomposition z i := by
ext ⟨c, ⟨⟩⟩ ⟨a, j_property⟩
simp only [Set.mem_preimage, Set.mem_singleton_iff] at j_property
simp only [Matrix.mul_apply, Limits.biproduct.components,
HomOrthogonal.matrixDecomposition_apply, Category.comp_id, Category.id_comp, Category.assoc,
End.mul_def, eqToHom_refl, eqToHom_trans_assoc]
conv_lhs => rw [← Category.id_comp w, ← biproduct.total]
simp only [Preadditive.sum_comp, Preadditive.comp_sum]
apply Finset.sum_congr_set
· simp
· intro b nm
simp only [Set.mem_preimage, Set.mem_singleton_iff] at nm
simp only [Category.assoc]
convert comp_zero
convert comp_zero
convert comp_zero
convert comp_zero
simp only [o.eq_zero nm]
section
variable {R : Type*} [Semiring R] [Linear R C]
/-- `HomOrthogonal.MatrixDecomposition` as an `R`-linear equivalence. -/
@[simps]
noncomputable def matrixDecompositionLinearEquiv (o : HomOrthogonal s) {α β : Type} [Finite α]
[Finite β] {f : α → ι} {g : β → ι} :
((⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b)) ≃ₗ[R]
∀ i : ι, Matrix (g ⁻¹' {i}) (f ⁻¹' {i}) (End (s i)) :=
{ o.matrixDecompositionAddEquiv with
map_smul' := fun w z => by
ext
dsimp [biproduct.components]
simp }
end
/-!
The hypothesis that `End (s i)` has invariant basis number is automatically satisfied
if `s i` is simple (as then `End (s i)` is a division ring).
-/
variable [∀ i, InvariantBasisNumber (End (s i))]
/-- Given a hom orthogonal family `s : ι → C`
for which each `End (s i)` is a ring with invariant basis number (e.g. if each `s i` is simple),
if two direct sums over `s` are isomorphic, then they have the same multiplicities.
-/
theorem equiv_of_iso (o : HomOrthogonal s) {α β : Type} [Finite α] [Finite β] {f : α → ι}
{g : β → ι} (i : (⨁ fun a => s (f a)) ≅ ⨁ fun b => s (g b)) :
∃ e : α ≃ β, ∀ a, g (e a) = f a := by
classical
refine ⟨Equiv.ofPreimageEquiv ?_, fun a => Equiv.ofPreimageEquiv_map _ _⟩
intro c
apply Nonempty.some
apply Cardinal.eq.1
cases nonempty_fintype α; cases nonempty_fintype β
simp only [Cardinal.mk_fintype, Nat.cast_inj]
exact
Matrix.square_of_invertible (o.matrixDecomposition i.inv c) (o.matrixDecomposition i.hom c)
(by
rw [← o.matrixDecomposition_comp]
simp)
(by
rw [← o.matrixDecomposition_comp]
simp)
end
end HomOrthogonal
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/FunctorCategory.lean | import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Preadditive structure on functor categories
If `C` and `D` are categories and `D` is preadditive,
then `C ⥤ D` is also preadditive.
-/
namespace CategoryTheory
open CategoryTheory.Limits Preadditive
variable {C D : Type*} [Category C] [Category D] [Preadditive D]
instance {F G : C ⥤ D} : Zero (F ⟶ G) where
zero := { app := fun _ => 0 }
instance {F G : C ⥤ D} : Add (F ⟶ G) where
add α β := { app := fun X => α.app X + β.app X }
instance {F G : C ⥤ D} : Neg (F ⟶ G) where
neg α := { app := fun X => -α.app X }
instance functorCategoryPreadditive : Preadditive (C ⥤ D) where
homGroup F G :=
{ nsmul := nsmulRec
zsmul := zsmulRec
sub := fun α β => { app := fun X => α.app X - β.app X }
add_assoc := by
intros
ext
apply add_assoc
zero_add := by
intros
ext
apply zero_add
add_zero := by
intros
ext
apply add_zero
add_comm := by
intros
ext
apply add_comm
sub_eq_add_neg := by
intros
ext
apply sub_eq_add_neg
neg_add_cancel := by
intros
ext
apply neg_add_cancel }
add_comp := by
intros
ext
apply add_comp
comp_add := by
intros
ext
apply comp_add
namespace NatTrans
variable {F G : C ⥤ D}
/-- Application of a natural transformation at a fixed object,
as group homomorphism -/
@[simps]
def appHom (X : C) : (F ⟶ G) →+ (F.obj X ⟶ G.obj X) where
toFun α := α.app X
map_zero' := rfl
map_add' _ _ := rfl
@[simp]
theorem app_zero (X : C) : (0 : F ⟶ G).app X = 0 :=
rfl
@[simp]
theorem app_add (X : C) (α β : F ⟶ G) : (α + β).app X = α.app X + β.app X :=
rfl
@[simp]
theorem app_sub (X : C) (α β : F ⟶ G) : (α - β).app X = α.app X - β.app X :=
rfl
@[simp]
theorem app_neg (X : C) (α : F ⟶ G) : (-α).app X = -α.app X :=
rfl
@[simp]
theorem app_nsmul (X : C) (α : F ⟶ G) (n : ℕ) : (n • α).app X = n • α.app X :=
(appHom X).map_nsmul α n
@[simp]
theorem app_zsmul (X : C) (α : F ⟶ G) (n : ℤ) : (n • α).app X = n • α.app X :=
(appHom X : (F ⟶ G) →+ (F.obj X ⟶ G.obj X)).map_zsmul α n
@[simp]
theorem app_units_zsmul (X : C) (α : F ⟶ G) (n : ℤˣ) : (n • α).app X = n • α.app X := by
apply app_zsmul
@[simp]
theorem app_sum {ι : Type*} (s : Finset ι) (X : C) (α : ι → (F ⟶ G)) :
(∑ i ∈ s, α i).app X = ∑ i ∈ s, (α i).app X := by
simp only [← appHom_apply, map_sum]
end NatTrans
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Mat.lean | import Mathlib.Algebra.BigOperators.Group.Finset.Pi
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.Opposites
import Mathlib.Algebra.Ring.Opposite
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Mul
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
/-- The index type `ι` -/
ι : Type
[fintype : Fintype ι]
/-- The map from `ι` to objects in `C` -/
X : ι → C
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
namespace Hom
open scoped Classical in
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by
classical
simp +unfoldPartialApp [dite_comp]
comp_id f := by
classical
simp +unfoldPartialApp [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
open scoped Classical in
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
open scoped Classical in
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) :=
inferInstanceAs <| AddCommGroup (DMatrix M.ι N.ι _)
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
open scoped Classical in
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine if h : x.1 = j then ?_ else 0
refine if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then ?_ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine if h : y.1 = j then ?_ else 0
refine if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then ?_ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans]
erw [Finset.sum_sigma]
dsimp
simp only [if_true, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp,
Sigma.mk.inj_iff, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
classical
ext
cases M; cases N
simp [comp_dite, dite_comp]
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
classical
ext
cases M; cases N
simp [comp_dite, dite_comp]
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `PUnit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
namespace Embedding
instance : (embedding C).Faithful where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : (embedding C).Full where map_surjective f := ⟨f PUnit.unit PUnit.unit, rfl⟩
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
open scoped Classical in
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j _ => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i _ k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
rw [Fintype.univ_ofSubsingleton, Finset.sum_singleton, dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
intro i
apply biproduct.hom_ext'
intro j
simp only [Category.id_comp, Category.assoc, biproduct.lift_π, biproduct.ι_desc_assoc,
biproduct.ι_π]
ext ⟨⟩ ⟨⟩
simp only [embedding, comp_apply, comp_dite, dite_comp, comp_zero, zero_comp,
Finset.sum_dite_eq', Finset.mem_univ, ite_true, eqToHom_refl, Category.comp_id]
split_ifs with h
· subst h
simp
· rfl
variable {D : Type u₁} [Category.{v₁} D] [Preadditive D]
/-- This instance can be found using `Functor.hasBiproduct_of_preserves'`, but it is faster
to keep it here. -/
instance (F : Mat_ C ⥤ D) [Functor.Additive F] (M : Mat_ C) :
HasBiproduct (fun i => F.obj ((embedding C).obj (M.X i))) :=
F.hasBiproduct_of_preserves _
/-- Every `M` is a direct sum of objects from `C`, and `F` preserves biproducts. -/
def additiveObjIsoBiproduct (F : Mat_ C ⥤ D) [Functor.Additive F] (M : Mat_ C) :
F.obj M ≅ ⨁ fun i => F.obj ((embedding C).obj (M.X i)) :=
F.mapIso (isoBiproductEmbedding M) ≪≫ F.mapBiproduct _
@[reassoc (attr := simp)]
lemma additiveObjIsoBiproduct_hom_π (F : Mat_ C ⥤ D) [Functor.Additive F] (M : Mat_ C) (i : M.ι) :
(additiveObjIsoBiproduct F M).hom ≫ biproduct.π _ i =
F.map (M.isoBiproductEmbedding.hom ≫ biproduct.π _ i) := by
dsimp [additiveObjIsoBiproduct]
rw [biproduct.lift_π, Category.assoc]
erw [biproduct.lift_π, ← F.map_comp]
simp
@[reassoc (attr := simp)]
lemma ι_additiveObjIsoBiproduct_inv (F : Mat_ C ⥤ D) [Functor.Additive F] (M : Mat_ C) (i : M.ι) :
biproduct.ι _ i ≫ (additiveObjIsoBiproduct F M).inv =
F.map (biproduct.ι _ i ≫ M.isoBiproductEmbedding.inv) := by
dsimp [additiveObjIsoBiproduct, Functor.mapBiproduct, Functor.mapBicone]
simp only [biproduct.ι_desc, biproduct.ι_desc_assoc, ← F.map_comp]
variable [HasFiniteBiproducts D]
@[reassoc]
theorem additiveObjIsoBiproduct_naturality (F : Mat_ C ⥤ D) [Functor.Additive F] {M N : Mat_ C}
(f : M ⟶ N) :
F.map f ≫ (additiveObjIsoBiproduct F N).hom =
(additiveObjIsoBiproduct F M).hom ≫
biproduct.matrix fun i j => F.map ((embedding C).map (f i j)) := by
classical
ext i : 1
simp only [Category.assoc, additiveObjIsoBiproduct_hom_π, isoBiproductEmbedding_hom,
embedding_obj_ι, embedding_obj_X, biproduct.lift_π, biproduct.matrix_π,
← cancel_epi (additiveObjIsoBiproduct F M).inv, Iso.inv_hom_id_assoc]
ext j : 1
simp only [ι_additiveObjIsoBiproduct_inv_assoc, isoBiproductEmbedding_inv,
biproduct.ι_desc, ← F.map_comp]
congr 1
funext ⟨⟩ ⟨⟩
simp [comp_apply, dite_comp, comp_dite]
@[reassoc]
theorem additiveObjIsoBiproduct_naturality' (F : Mat_ C ⥤ D) [Functor.Additive F] {M N : Mat_ C}
(f : M ⟶ N) :
(additiveObjIsoBiproduct F M).inv ≫ F.map f =
biproduct.matrix (fun i j => F.map ((embedding C).map (f i j)) :) ≫
(additiveObjIsoBiproduct F N).inv := by
rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, additiveObjIsoBiproduct_naturality]
attribute [local simp] biproduct.lift_desc
/-- Any additive functor `C ⥤ D` to a category `D` with finite biproducts extends to
a functor `Mat_ C ⥤ D`. -/
@[simps]
def lift (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ D where
obj X := ⨁ fun i => F.obj (X.X i)
map f := biproduct.matrix fun i j => F.map (f i j)
map_id X := by
ext i j
by_cases h : j = i
· subst h; simp
· simp [h]
instance lift_additive (F : C ⥤ D) [Functor.Additive F] : Functor.Additive (lift F) where
/-- An additive functor `C ⥤ D` factors through its lift to `Mat_ C ⥤ D`. -/
@[simps!]
def embeddingLiftIso (F : C ⥤ D) [Functor.Additive F] : embedding C ⋙ lift F ≅ F :=
NatIso.ofComponents
(fun X =>
{ hom := biproduct.desc fun _ => 𝟙 (F.obj X)
inv := biproduct.lift fun _ => 𝟙 (F.obj X) })
/-- `Mat_.lift F` is the unique additive functor `L : Mat_ C ⥤ D` such that `F ≅ embedding C ⋙ L`.
-/
def liftUnique (F : C ⥤ D) [Functor.Additive F] (L : Mat_ C ⥤ D) [Functor.Additive L]
(α : embedding C ⋙ L ≅ F) : L ≅ lift F :=
NatIso.ofComponents
(fun M =>
additiveObjIsoBiproduct L M ≪≫
(biproduct.mapIso fun i => α.app (M.X i)) ≪≫
(biproduct.mapIso fun i => (embeddingLiftIso F).symm.app (M.X i)) ≪≫
(additiveObjIsoBiproduct (lift F) M).symm)
fun f => by
dsimp only [Iso.trans_hom, Iso.symm_hom, biproduct.mapIso_hom]
simp only [additiveObjIsoBiproduct_naturality_assoc]
simp only [biproduct.matrix_map_assoc, Category.assoc]
simp only [additiveObjIsoBiproduct_naturality']
simp only [biproduct.map_matrix_assoc]
congr 3
ext j k
apply biproduct.hom_ext
rintro ⟨⟩
dsimp
simpa using α.hom.naturality (f j k)
-- TODO is there some uniqueness statement for the natural isomorphism in `liftUnique`?
/-- Two additive functors `Mat_ C ⥤ D` are naturally isomorphic if
their precompositions with `embedding C` are naturally isomorphic as functors `C ⥤ D`. -/
def ext {F G : Mat_ C ⥤ D} [Functor.Additive F] [Functor.Additive G]
(α : embedding C ⋙ F ≅ embedding C ⋙ G) : F ≅ G :=
liftUnique (embedding C ⋙ G) _ α ≪≫ (liftUnique _ _ (Iso.refl _)).symm
/-- Natural isomorphism needed in the construction of `equivalenceSelfOfHasFiniteBiproducts`.
-/
def equivalenceSelfOfHasFiniteBiproductsAux [HasFiniteBiproducts C] :
embedding C ⋙ 𝟭 (Mat_ C) ≅ embedding C ⋙ lift (𝟭 C) ⋙ embedding C :=
Functor.rightUnitor _ ≪≫
(Functor.leftUnitor _).symm ≪≫
Functor.isoWhiskerRight (embeddingLiftIso _).symm _ ≪≫ Functor.associator _ _ _
/--
A preadditive category that already has finite biproducts is equivalent to its additive envelope.
Note that we only prove this for a large category;
otherwise there are universe issues that I haven't attempted to sort out.
-/
def equivalenceSelfOfHasFiniteBiproducts (C : Type (u₁ + 1)) [LargeCategory C] [Preadditive C]
[HasFiniteBiproducts C] : Mat_ C ≌ C :=
Equivalence.mk
(-- I suspect this is already an adjoint equivalence, but it seems painful to verify.
lift
(𝟭 C))
(embedding C) (ext equivalenceSelfOfHasFiniteBiproductsAux) (embeddingLiftIso (𝟭 C))
@[simp]
theorem equivalenceSelfOfHasFiniteBiproducts_functor {C : Type (u₁ + 1)} [LargeCategory C]
[Preadditive C] [HasFiniteBiproducts C] :
(equivalenceSelfOfHasFiniteBiproducts C).functor = lift (𝟭 C) :=
rfl
@[simp]
theorem equivalenceSelfOfHasFiniteBiproducts_inverse {C : Type (u₁ + 1)} [LargeCategory C]
[Preadditive C] [HasFiniteBiproducts C] :
(equivalenceSelfOfHasFiniteBiproducts C).inverse = embedding C :=
rfl
end Mat_
universe u
/-- A type synonym for `Fintype`, which we will equip with a category structure
where the morphisms are matrices with components in `R`. -/
@[nolint unusedArguments]
def Mat (_ : Type u) :=
FintypeCat.{u}
instance (R : Type u) : Inhabited (Mat R) := by
dsimp [Mat]
infer_instance
instance (R : Type u) : CoeSort (Mat R) (Type u) :=
FintypeCat.instCoeSort
open Matrix
open scoped Classical in
instance (R : Type u) [Semiring R] : Category (Mat R) where
Hom X Y := Matrix X Y R
id X := (1 : Matrix X X R)
comp {X Y Z} f g := (show Matrix X Y R from f) * (show Matrix Y Z R from g)
assoc := by intros; simp [Matrix.mul_assoc]
namespace Mat
section
variable {R : Type u} [Semiring R]
@[ext]
theorem hom_ext {X Y : Mat R} (f g : X ⟶ Y) (h : ∀ i j, f i j = g i j) : f = g :=
Matrix.ext_iff.mp h
variable (R)
open scoped Classical in
theorem id_def (M : Mat R) : 𝟙 M = fun i j => if i = j then 1 else 0 :=
rfl
open scoped Classical in
theorem id_apply (M : Mat R) (i j : M) : (𝟙 M : Matrix M M R) i j = if i = j then 1 else 0 :=
rfl
@[simp]
theorem id_apply_self (M : Mat R) (i : M) : (𝟙 M : Matrix M M R) i i = 1 := by simp [id_apply]
@[simp]
theorem id_apply_of_ne (M : Mat R) (i j : M) (h : i ≠ j) : (𝟙 M : Matrix M M R) i j = 0 := by
simp [id_apply, h]
theorem comp_def {M N K : Mat R} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N, f i j * g j k :=
rfl
@[simp]
theorem comp_apply {M N K : Mat R} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N, f i j * g j k :=
rfl
instance (M N : Mat R) : Inhabited (M ⟶ N) :=
⟨fun (_ : M) (_ : N) => (0 : R)⟩
end
variable (R : Type) [Ring R]
open Opposite
/-- Auxiliary definition for `CategoryTheory.Mat.equivalenceSingleObj`. -/
@[simps]
def equivalenceSingleObjInverse : Mat_ (SingleObj Rᵐᵒᵖ) ⥤ Mat R where
obj X := FintypeCat.of X.ι
map f i j := MulOpposite.unop (f i j)
map_id X := by
ext
simp only [Mat_.id_def, id_def]
split_ifs <;> rfl
map_comp f g := by
-- Porting note: this proof was automatic in mathlib3
ext
simp only [Mat_.comp_apply, comp_apply]
apply Finset.unop_sum
instance : (equivalenceSingleObjInverse R).Faithful where
map_injective w := by
ext
apply_fun MulOpposite.unop using MulOpposite.unop_injective
exact congr_fun (congr_fun w _) _
instance : (equivalenceSingleObjInverse R).Full where
map_surjective f := ⟨fun i j => MulOpposite.op (f i j), rfl⟩
instance : (equivalenceSingleObjInverse R).EssSurj where
mem_essImage X :=
⟨{ ι := X
X := fun _ => PUnit.unit }, ⟨eqToIso (by cases X; congr)⟩⟩
instance : (equivalenceSingleObjInverse R).IsEquivalence where
/-- The categorical equivalence between the category of matrices over a ring,
and the category of matrices over that ring considered as a single-object category. -/
def equivalenceSingleObj : Mat R ≌ Mat_ (SingleObj Rᵐᵒᵖ) :=
(equivalenceSingleObjInverse R).asEquivalence.symm
instance (X Y : Mat R) : AddCommGroup (X ⟶ Y) := by
change AddCommGroup (Matrix X Y R)
infer_instance
variable {R}
@[simp]
theorem add_apply {M N : Mat R} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
attribute [local simp] add_mul mul_add Finset.sum_add_distrib
instance : Preadditive (Mat R) where
-- TODO show `Mat R` has biproducts, and that `biprod.map` "is" forming a block diagonal matrix.
end Mat
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/EilenbergMoore.lean | import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Monad.Algebra
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# Preadditive structure on algebras over a monad
If `C` is a preadditive category and `T` is an additive monad on `C` then `Algebra T` is also
preadditive. Dually, if `U` is an additive comonad on `C` then `Coalgebra U` is preadditive as well.
-/
universe v₁ u₁
namespace CategoryTheory
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C] (T : Monad C)
[Functor.Additive (T : C ⥤ C)]
open CategoryTheory.Limits Preadditive
/-- The category of algebras over an additive monad on a preadditive category is preadditive. -/
@[simps]
instance Monad.algebraPreadditive : Preadditive (Monad.Algebra T) where
homGroup F G :=
{ add := fun α β =>
{ f := α.f + β.f
h := by simp only [Functor.map_add, add_comp, Monad.Algebra.Hom.h, comp_add] }
zero :=
{ f := 0
h := by simp only [Functor.map_zero, zero_comp, comp_zero] }
nsmul := fun n α =>
{ f := n • α.f
h := by rw [Functor.map_nsmul, nsmul_comp, Monad.Algebra.Hom.h, comp_nsmul] }
neg := fun α =>
{ f := -α.f
h := by simp only [Functor.map_neg, neg_comp, Monad.Algebra.Hom.h, comp_neg] }
sub := fun α β =>
{ f := α.f - β.f
h := by simp only [Functor.map_sub, sub_comp, Monad.Algebra.Hom.h, comp_sub] }
zsmul := fun r α =>
{ f := r • α.f
h := by rw [Functor.map_zsmul, zsmul_comp, Monad.Algebra.Hom.h, comp_zsmul] }
add_assoc := by
intros
ext
apply add_assoc
zero_add := by
intros
ext
apply zero_add
add_zero := by
intros
ext
apply add_zero
nsmul_zero := by
intros
ext
apply zero_smul
nsmul_succ := by
intros
ext
apply succ_nsmul
sub_eq_add_neg := by
intros
ext
apply sub_eq_add_neg
zsmul_zero' := by
intros
ext
apply zero_smul
zsmul_succ' := by
intros
ext
simp only [natCast_zsmul, succ_nsmul]
rfl
zsmul_neg' := by
intros
ext
simp only [negSucc_zsmul, ← Nat.cast_smul_eq_nsmul ℤ]
neg_add_cancel := by
intros
ext
apply neg_add_cancel
add_comm := by
intros
ext
apply add_comm }
add_comp := by
intros
ext
apply add_comp
comp_add := by
intros
ext
apply comp_add
instance Monad.forget_additive : (Monad.forget T).Additive where
variable (U : Comonad C) [Functor.Additive (U : C ⥤ C)]
/-- The category of coalgebras over an additive comonad on a preadditive category is preadditive. -/
@[simps]
instance Comonad.coalgebraPreadditive : Preadditive (Comonad.Coalgebra U) where
homGroup F G :=
{ add := fun α β =>
{ f := α.f + β.f
h := by simp only [Functor.map_add, comp_add, Comonad.Coalgebra.Hom.h, add_comp] }
zero :=
{ f := 0
h := by simp only [Functor.map_zero, comp_zero, zero_comp] }
nsmul := fun n α =>
{ f := n • α.f
h := by rw [Functor.map_nsmul, comp_nsmul, Comonad.Coalgebra.Hom.h, nsmul_comp] }
neg := fun α =>
{ f := -α.f
h := by simp only [Functor.map_neg, comp_neg, Comonad.Coalgebra.Hom.h, neg_comp] }
sub := fun α β =>
{ f := α.f - β.f
h := by simp only [Functor.map_sub, comp_sub, Comonad.Coalgebra.Hom.h, sub_comp] }
zsmul := fun r α =>
{ f := r • α.f
h := by rw [Functor.map_zsmul, comp_zsmul, Comonad.Coalgebra.Hom.h, zsmul_comp] }
add_assoc := by
intros
ext
apply add_assoc
zero_add := by
intros
ext
apply zero_add
add_zero := by
intros
ext
apply add_zero
nsmul_zero := by
intros
ext
apply zero_smul
nsmul_succ := by
intros
ext
apply succ_nsmul
sub_eq_add_neg := by
intros
ext
apply sub_eq_add_neg
zsmul_zero' := by
intros
ext
apply zero_smul
zsmul_succ' := by
intros
ext
simp only [natCast_zsmul, succ_nsmul]
rfl
zsmul_neg' := by
intros
ext
simp only [negSucc_zsmul, ← Nat.cast_smul_eq_nsmul ℤ]
neg_add_cancel := by
intros
ext
apply neg_add_cancel
add_comm := by
intros
ext
apply add_comm }
add_comp := by
intros
ext
apply add_comp
comp_add := by
intros
ext
apply comp_add
instance Comonad.forget_additive : (Comonad.forget U).Additive where
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Projective/Internal.lean | import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.CategoryTheory.ObjectProperty.Retract
/-!
# Internal projectivity
This file defines internal projectivity of objects `P` in a category `C` as a class
`InternallyProjective P`. This means that the functor taking internal homs out of `P`
preserves epimorphisms. It also proves that a retract of an internally projective object
is internally projective (see `InternallyProjective.ofRetract`).
This property is important in the setting of light condensed abelian groups, when establishing
the solid theory (see the lecture series on analytic stacks:
https://www.youtube.com/playlist?list=PLx5f8IelFRgGmu6gmL-Kf_Rl_6Mm7juZO).
-/
noncomputable section
universe u
open CategoryTheory MonoidalCategory MonoidalClosed Limits Functor
namespace CategoryTheory
variable {C : Type*} [Category C] [MonoidalCategory C] [MonoidalClosed C]
/--
An object `P : C` is *internally projective* if the functor `P ⟶[C] -` taking internal homs
out of `P` preserves epimorphisms.
-/
def isInternallyProjective : ObjectProperty C := fun P ↦ (ihom P).PreservesEpimorphisms
/--
An object `P : C` is *internally projective* if the functor `P ⟶[C] -` taking internal homs
out of `P` preserves epimorphisms.
-/
abbrev InternallyProjective (P : C) := isInternallyProjective.Is P
instance InternallyProjective.preserves_epi (P : C) [InternallyProjective P] :
(ihom P).PreservesEpimorphisms :=
isInternallyProjective.prop_of_is P
instance : (isInternallyProjective (C := C)).IsStableUnderRetracts where
of_retract {Y X} r h :=
have : InternallyProjective X := ⟨h⟩
have : Retract (ihom Y) (ihom X) := r.op.map internalHom
preservesEpimorphisms.ofRetract this
namespace InternallyProjective
lemma ofRetract {X Y : C} (r : Retract Y X) [InternallyProjective X] : InternallyProjective Y :=
⟨isInternallyProjective.prop_of_retract r (isInternallyProjective.prop_of_is _)⟩
end CategoryTheory.InternallyProjective |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Projective/Preserves.lean | import Mathlib.CategoryTheory.Preadditive.Projective.Basic
/-!
# Preservation of projective objects
We define a typeclass `Functor.PreservesProjectiveObjects`.
We restate the existing result that if `F ⊣ G` is an adjunction and `G` preserves monomorphisms,
then `F` preserves projective objects. We show that the converse is true if the domain of `F` has
enough projectives.
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{E : Type u₃} [Category.{v₃} E]
/-- A functor preserves projective objects if it maps projective objects to projective objects. -/
class Functor.PreservesProjectiveObjects (F : C ⥤ D) : Prop where
projective_obj {X : C} : Projective X → Projective (F.obj X)
/-- See `Functor.projective_obj_of_projective` for a variant taking `Projective X` as an explicit
argument. -/
instance Functor.projective_obj (F : C ⥤ D) [F.PreservesProjectiveObjects] (X : C) [Projective X] :
Projective (F.obj X) :=
Functor.PreservesProjectiveObjects.projective_obj inferInstance
/-- See `Functor.projective_obj` for a variant taking `Projective X` as a typeclass argument. -/
theorem Functor.projective_obj_of_projective (F : C ⥤ D) [F.PreservesProjectiveObjects] {X : C}
(h : Projective X) : Projective (F.obj X) :=
Functor.PreservesProjectiveObjects.projective_obj h
instance Functor.preservesProjectiveObjects_comp (F : C ⥤ D) (G : D ⥤ E)
[F.PreservesProjectiveObjects] [G.PreservesProjectiveObjects] :
(F ⋙ G).PreservesProjectiveObjects where
projective_obj := G.projective_obj_of_projective ∘ F.projective_obj_of_projective
theorem Functor.preservesProjectiveObjects_of_adjunction_of_preservesEpimorphisms
{F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) [G.PreservesEpimorphisms] :
F.PreservesProjectiveObjects where
projective_obj h := adj.map_projective _ h
instance (priority := low) Functor.preservesProjectiveObjects_of_isEquivalence {F : C ⥤ D}
[IsEquivalence F] : F.PreservesProjectiveObjects :=
preservesProjectiveObjects_of_adjunction_of_preservesEpimorphisms F.asEquivalence.toAdjunction
theorem Functor.preservesEpimorphisms_of_adjunction_of_preservesProjectiveObjects
[EnoughProjectives C] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) [F.PreservesProjectiveObjects] :
G.PreservesEpimorphisms where
preserves {X Y} f _ := by
suffices ∃ h, h ≫ G.map f = Projective.π (G.obj Y) from epi_of_epi_fac this.choose_spec
refine ⟨adj.unit.app (Projective.over (G.obj Y)) ≫
G.map (Projective.factorThru (F.map (Projective.π _) ≫ adj.counit.app Y) f), ?_⟩
rw [Category.assoc, ← Functor.map_comp]
simp
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Projective/LiftingProperties.lean | import Mathlib.CategoryTheory.Preadditive.Projective.Basic
import Mathlib.CategoryTheory.MorphismProperty.LiftingProperty
/-!
# Characterization of projective objects in terms of lifting properties
An object `P` is projective iff the morphism `0 ⟶ P` has the
left lifting property with respect to epimorphisms,
`projective_iff_llp_epimorphisms_zero`.
-/
universe v u
namespace CategoryTheory
open Limits ZeroObject
variable {C : Type u} [Category.{v} C]
namespace Projective
lemma hasLiftingProperty_of_isZero
{Z P X Y : C} (i : Z ⟶ P) (p : X ⟶ Y) [Epi p] [Projective P] (hZ : IsZero Z) :
HasLiftingProperty i p where
sq_hasLift {f g} sq := ⟨⟨{
l := Projective.factorThru g p
fac_left := hZ.eq_of_src _ _ }⟩⟩
instance {X Y P : C} (p : X ⟶ Y) [Epi p] [Projective P] [HasZeroObject C] (i : 0 ⟶ P) :
HasLiftingProperty (i : 0 ⟶ P) p :=
Projective.hasLiftingProperty_of_isZero i p (isZero_zero C)
end Projective
lemma projective_iff_llp_epimorphisms_of_isZero
[HasZeroMorphisms C] {P Z : C} (i : Z ⟶ P) (hZ : IsZero Z) :
Projective P ↔ (MorphismProperty.epimorphisms C).llp i := by
obtain rfl := hZ.eq_of_src i 0
constructor
· intro _ X Y p (_ : Epi p)
exact Projective.hasLiftingProperty_of_isZero 0 p hZ
· intro h
constructor
intro X Y f p hp
have := h _ hp
have sq : CommSq 0 (0 : Z ⟶ P) p f := ⟨by simp⟩
exact ⟨sq.lift, by simp⟩
lemma projective_iff_llp_epimorphisms_zero
[HasZeroMorphisms C] [HasZeroObject C] (P : C) :
Projective P ↔ (MorphismProperty.epimorphisms C).llp (0 : 0 ⟶ P) :=
projective_iff_llp_epimorphisms_of_isZero _ (isZero_zero C)
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Projective/Basic.lean | import Mathlib.CategoryTheory.Adjunction.FullyFaithful
import Mathlib.CategoryTheory.Adjunction.Limits
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono
import Mathlib.CategoryTheory.Limits.Preserves.Finite
import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts
/-!
# Projective objects and categories with enough projectives
An object `P` is called *projective* if every morphism out of `P` factors through every epimorphism.
A category `C` *has enough projectives* if every object admits an epimorphism from some
projective object.
`CategoryTheory.Projective.over X` picks an arbitrary such projective object, and
`CategoryTheory.Projective.π X : CategoryTheory.Projective.over X ⟶ X` is the corresponding
epimorphism.
Given a morphism `f : X ⟶ Y`, `CategoryTheory.Projective.left f` is a projective object over
`CategoryTheory.Limits.kernel f`, and `Projective.d f : Projective.left f ⟶ X` is the morphism
`π (kernel f) ≫ kernel.ι f`.
-/
noncomputable section
open CategoryTheory Limits Opposite
universe v u v' u'
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
/--
An object `P` is called *projective* if every morphism out of `P` factors through every epimorphism.
-/
class Projective (P : C) : Prop where
factors : ∀ {E X : C} (f : P ⟶ X) (e : E ⟶ X) [Epi e], ∃ f', f' ≫ e = f
variable (C) in
/-- The `ObjectProperty C` corresponding to the notion of projective objects in `C`. -/
abbrev isProjective : ObjectProperty C := Projective
lemma Limits.IsZero.projective {X : C} (h : IsZero X) : Projective X where
factors _ _ _ := ⟨h.to_ _, h.eq_of_src _ _⟩
section
/-- A projective presentation of an object `X` consists of an epimorphism `f : P ⟶ X`
from some projective object `P`.
-/
structure ProjectivePresentation (X : C) where
/-- The projective object `p` of this presentation -/
p : C
[projective : Projective p]
/-- The epimorphism from `p` of this presentation -/
f : p ⟶ X
[epi : Epi f]
attribute [instance] ProjectivePresentation.projective ProjectivePresentation.epi
variable (C)
/-- A category "has enough projectives" if for every object `X` there is a projective object `P` and
an epimorphism `P ↠ X`. -/
class EnoughProjectives : Prop where
presentation : ∀ X : C, Nonempty (ProjectivePresentation X)
end
namespace Projective
/--
An arbitrarily chosen factorisation of a morphism out of a projective object through an epimorphism.
-/
def factorThru {P X E : C} [Projective P] (f : P ⟶ X) (e : E ⟶ X) [Epi e] : P ⟶ E :=
(Projective.factors f e).choose
@[reassoc (attr := simp)]
theorem factorThru_comp {P X E : C} [Projective P] (f : P ⟶ X) (e : E ⟶ X) [Epi e] :
factorThru f e ≫ e = f :=
(Projective.factors f e).choose_spec
section
open ZeroObject
instance zero_projective [HasZeroObject C] : Projective (0 : C) :=
(isZero_zero C).projective
end
theorem of_iso {P Q : C} (i : P ≅ Q) (_ : Projective P) : Projective Q where
factors f e _ :=
let ⟨f', hf'⟩ := Projective.factors (i.hom ≫ f) e
⟨i.inv ≫ f', by simp [hf']⟩
theorem iso_iff {P Q : C} (i : P ≅ Q) : Projective P ↔ Projective Q :=
⟨of_iso i, of_iso i.symm⟩
/-- The axiom of choice says that every type is a projective object in `Type`. -/
instance (X : Type u) : Projective X where
factors f e _ :=
have he : Function.Surjective e := surjective_of_epi e
⟨fun x => (he (f x)).choose, funext fun x ↦ (he (f x)).choose_spec⟩
instance Type.enoughProjectives : EnoughProjectives (Type u) where
presentation X := ⟨⟨X, 𝟙 X⟩⟩
instance {P Q : C} [HasBinaryCoproduct P Q] [Projective P] [Projective Q] : Projective (P ⨿ Q) where
factors f e epi := ⟨coprod.desc (factorThru (coprod.inl ≫ f) e) (factorThru (coprod.inr ≫ f) e),
by cat_disch⟩
instance {β : Type v} (g : β → C) [HasCoproduct g] [∀ b, Projective (g b)] : Projective (∐ g) where
factors f e epi := ⟨Sigma.desc fun b => factorThru (Sigma.ι g b ≫ f) e, by cat_disch⟩
instance {P Q : C} [HasZeroMorphisms C] [HasBinaryBiproduct P Q] [Projective P] [Projective Q] :
Projective (P ⊞ Q) where
factors f e epi := ⟨biprod.desc (factorThru (biprod.inl ≫ f) e) (factorThru (biprod.inr ≫ f) e),
by cat_disch⟩
instance {β : Type v} (g : β → C) [HasZeroMorphisms C] [HasBiproduct g] [∀ b, Projective (g b)] :
Projective (⨁ g) where
factors f e epi := ⟨biproduct.desc fun b => factorThru (biproduct.ι g b ≫ f) e, by cat_disch⟩
theorem projective_iff_preservesEpimorphisms_coyoneda_obj (P : C) :
Projective P ↔ (coyoneda.obj (op P)).PreservesEpimorphisms :=
⟨fun hP =>
⟨fun f _ =>
(epi_iff_surjective _).2 fun g =>
have : Projective (unop (op P)) := hP
⟨factorThru g f, factorThru_comp _ _⟩⟩,
fun _ =>
⟨fun f e _ =>
(epi_iff_surjective _).1 (inferInstance : Epi ((coyoneda.obj (op P)).map e)) f⟩⟩
section EnoughProjectives
variable [EnoughProjectives C]
/-- `Projective.over X` provides an arbitrarily chosen projective object equipped with
an epimorphism `Projective.π : Projective.over X ⟶ X`.
-/
def over (X : C) : C :=
(EnoughProjectives.presentation X).some.p
instance projective_over (X : C) : Projective (over X) :=
(EnoughProjectives.presentation X).some.projective
/-- The epimorphism `projective.π : projective.over X ⟶ X`
from the arbitrarily chosen projective object over `X`.
-/
def π (X : C) : over X ⟶ X :=
(EnoughProjectives.presentation X).some.f
instance π_epi (X : C) : Epi (π X) :=
(EnoughProjectives.presentation X).some.epi
section
variable [HasZeroMorphisms C] {X Y : C} (f : X ⟶ Y) [HasKernel f]
/-- When `C` has enough projectives, the object `Projective.syzygies f` is
an arbitrarily chosen projective object over `kernel f`.
-/
def syzygies : C := over (kernel f)
instance : Projective (syzygies f) := inferInstanceAs (Projective (over _))
/-- When `C` has enough projectives,
`Projective.d f : Projective.syzygies f ⟶ X` is the composition
`π (kernel f) ≫ kernel.ι f`.
(When `C` is abelian, we have `exact (projective.d f) f`.)
-/
abbrev d : syzygies f ⟶ X :=
π (kernel f) ≫ kernel.ι f
end
end EnoughProjectives
end Projective
namespace Adjunction
variable {D : Type u'} [Category.{v'} D] {F : C ⥤ D} {G : D ⥤ C}
theorem map_projective (adj : F ⊣ G) [G.PreservesEpimorphisms] (P : C) (hP : Projective P) :
Projective (F.obj P) where
factors f g _ := by
rcases hP.factors (adj.unit.app P ≫ G.map f) (G.map g) with ⟨f', hf'⟩
use F.map f' ≫ adj.counit.app _
rw [Category.assoc, ← Adjunction.counit_naturality, ← Category.assoc, ← F.map_comp, hf']
simp
theorem projective_of_map_projective (adj : F ⊣ G) [F.Full] [F.Faithful] (P : C)
(hP : Projective (F.obj P)) : Projective P where
factors f g _ := by
haveI := Adjunction.leftAdjoint_preservesColimits.{0, 0} adj
rcases (@hP).1 (F.map f) (F.map g) with ⟨f', hf'⟩
use adj.unit.app _ ≫ G.map f' ≫ (inv <| adj.unit.app _)
exact F.map_injective (by simpa)
/-- Given an adjunction `F ⊣ G` such that `G` preserves epis, `F` maps a projective presentation of
`X` to a projective presentation of `F(X)`. -/
def mapProjectivePresentation (adj : F ⊣ G) [G.PreservesEpimorphisms] (X : C)
(Y : ProjectivePresentation X) : ProjectivePresentation (F.obj X) where
p := F.obj Y.p
projective := adj.map_projective _ Y.projective
f := F.map Y.f
epi := have := Adjunction.leftAdjoint_preservesColimits.{0, 0} adj; inferInstance
end Adjunction
namespace Functor
variable {D : Type*} [Category D] (F : C ⥤ D)
theorem projective_of_map_projective [F.Full] [F.Faithful]
[F.PreservesEpimorphisms] {P : C} (hP : Projective (F.obj P)) : Projective P where
factors g f _ := by
obtain ⟨h, fac⟩ := hP.factors (F.map g) (F.map f)
exact ⟨F.preimage h, F.map_injective (by simp [fac])⟩
end Functor
namespace Equivalence
variable {D : Type u'} [Category.{v'} D] (F : C ≌ D)
theorem map_projective_iff (P : C) : Projective (F.functor.obj P) ↔ Projective P :=
⟨F.toAdjunction.projective_of_map_projective P, F.toAdjunction.map_projective P⟩
/-- Given an equivalence of categories `F`, a projective presentation of `F(X)` induces a
projective presentation of `X.` -/
def projectivePresentationOfMapProjectivePresentation (X : C)
(Y : ProjectivePresentation (F.functor.obj X)) : ProjectivePresentation X where
p := F.inverse.obj Y.p
projective := Adjunction.map_projective F.symm.toAdjunction Y.p Y.projective
f := F.inverse.map Y.f ≫ F.unitInv.app _
epi := epi_comp _ _
theorem enoughProjectives_iff (F : C ≌ D) : EnoughProjectives C ↔ EnoughProjectives D := by
constructor
all_goals intro H; constructor; intro X; constructor
· exact F.symm.projectivePresentationOfMapProjectivePresentation _
(Nonempty.some (H.presentation (F.inverse.obj X)))
· exact F.projectivePresentationOfMapProjectivePresentation X
(Nonempty.some (H.presentation (F.functor.obj X)))
end Equivalence
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Projective/Resolution.lean | import Mathlib.Algebra.Homology.QuasiIso
import Mathlib.Algebra.Homology.SingleHomology
import Mathlib.CategoryTheory.Preadditive.Projective.Preserves
/-!
# Projective resolutions
A projective resolution `P : ProjectiveResolution Z` of an object `Z : C` consists of
an `ℕ`-indexed chain complex `P.complex` of projective objects,
along with a quasi-isomorphism `P.π` from `C` to the chain complex consisting just
of `Z` in degree zero.
-/
universe v u v' u'
namespace CategoryTheory
open Category Limits ChainComplex HomologicalComplex
variable {C : Type u} [Category.{v} C]
open Projective
variable [HasZeroObject C] [HasZeroMorphisms C]
/--
A `ProjectiveResolution Z` consists of a bundled `ℕ`-indexed chain complex of projective objects,
along with a quasi-isomorphism to the complex consisting of just `Z` supported in degree `0`.
-/
structure ProjectiveResolution (Z : C) where
/-- the chain complex involved in the resolution -/
complex : ChainComplex C ℕ
/-- the chain complex must be degreewise projective -/
projective : ∀ n, Projective (complex.X n) := by infer_instance
/-- the chain complex must have homology -/
[hasHomology : ∀ i, complex.HasHomology i]
/-- the morphism to the single chain complex with `Z` in degree `0` -/
π : complex ⟶ (ChainComplex.single₀ C).obj Z
/-- the morphism to the single chain complex with `Z` in degree `0` is a quasi-isomorphism -/
quasiIso : QuasiIso π := by infer_instance
open ProjectiveResolution in
attribute [instance] projective hasHomology ProjectiveResolution.quasiIso
/-- An object admits a projective resolution.
-/
class HasProjectiveResolution (Z : C) : Prop where
out : Nonempty (ProjectiveResolution Z)
variable (C)
/-- You will rarely use this typeclass directly: it is implied by the combination
`[EnoughProjectives C]` and `[Abelian C]`.
By itself it's enough to set up the basic theory of derived functors.
-/
class HasProjectiveResolutions : Prop where
out : ∀ Z : C, HasProjectiveResolution Z
attribute [instance 100] HasProjectiveResolutions.out
namespace ProjectiveResolution
variable {C}
variable {Z : C} (P : ProjectiveResolution Z)
lemma complex_exactAt_succ (n : ℕ) :
P.complex.ExactAt (n + 1) := by
rw [← quasiIsoAt_iff_exactAt' P.π (n + 1) (exactAt_succ_single_obj _ _)]
infer_instance
lemma exact_succ (n : ℕ) :
(ShortComplex.mk _ _ (P.complex.d_comp_d (n + 2) (n + 1) n)).Exact :=
((HomologicalComplex.exactAt_iff' _ (n + 2) (n + 1) n) (by simp only [prev]; rfl)
(by simp)).1 (P.complex_exactAt_succ n)
@[simp]
theorem π_f_succ (n : ℕ) : P.π.f (n + 1) = 0 :=
(isZero_single_obj_X _ _ _ _ (by simp)).eq_of_tgt _ _
@[reassoc (attr := simp)]
theorem complex_d_comp_π_f_zero :
P.complex.d 1 0 ≫ P.π.f 0 = 0 := by
rw [← P.π.comm 1 0, single_obj_d, comp_zero]
theorem complex_d_succ_comp (n : ℕ) :
P.complex.d n (n + 1) ≫ P.complex.d (n + 1) (n + 2) = 0 := by
simp
/-- The (limit) cokernel cofork given by the composition
`P.complex.X 1 ⟶ P.complex.X 0 ⟶ Z` when `P : ProjectiveResolution Z`. -/
@[simp]
noncomputable def cokernelCofork : CokernelCofork (P.complex.d 1 0) :=
CokernelCofork.ofπ _ P.complex_d_comp_π_f_zero
/-- `Z` is the cokernel of `P.complex.X 1 ⟶ P.complex.X 0` when `P : ProjectiveResolution Z`. -/
noncomputable def isColimitCokernelCofork : IsColimit (P.cokernelCofork) := by
refine IsColimit.ofIsoColimit (P.complex.opcyclesIsCokernel 1 0 (by simp)) ?_
refine Cofork.ext (P.complex.isoHomologyι₀.symm ≪≫ isoOfQuasiIsoAt P.π 0 ≪≫
singleObjHomologySelfIso _ _ _) ?_
rw [← cancel_mono (singleObjHomologySelfIso (ComplexShape.down ℕ) 0 _).inv,
← cancel_mono (isoHomologyι₀ _).hom]
dsimp
simp only [isoHomologyι₀_inv_naturality_assoc, p_opcyclesMap_assoc, single₀_obj_zero, assoc,
Iso.hom_inv_id, comp_id, isoHomologyι_inv_hom_id, singleObjHomologySelfIso_inv_homologyι,
singleObjOpcyclesSelfIso_hom, single₀ObjXSelf, Iso.refl_inv, id_comp]
instance (n : ℕ) : Epi (P.π.f n) := by
cases n
· exact epi_of_isColimit_cofork P.isColimitCokernelCofork
· rw [π_f_succ]; infer_instance
variable (Z)
/-- A projective object admits a trivial projective resolution: itself in degree 0. -/
@[simps]
noncomputable def self [Projective Z] : ProjectiveResolution Z where
complex := (ChainComplex.single₀ C).obj Z
π := 𝟙 ((ChainComplex.single₀ C).obj Z)
projective n := by
cases n
· simpa
· apply IsZero.projective
apply HomologicalComplex.isZero_single_obj_X
simp
end ProjectiveResolution
namespace Functor
open Limits
variable {C : Type u} [Category C] [HasZeroObject C] [Preadditive C]
{D : Type u'} [Category.{v'} D] [HasZeroObject D] [Preadditive D] [CategoryWithHomology D]
/-- An additive functor `F` which preserves homology and sends projective objects to projective
objects sends a projective resolution of `Z` to a projective resolution of `F.obj Z`. -/
@[simps complex π]
noncomputable def mapProjectiveResolution (F : C ⥤ D) [F.Additive]
[F.PreservesProjectiveObjects] [F.PreservesHomology] {Z : C} (P : ProjectiveResolution Z) :
ProjectiveResolution (F.obj Z) where
complex := (F.mapHomologicalComplex _).obj P.complex
projective n := PreservesProjectiveObjects.projective_obj (P.projective n)
π := (F.mapHomologicalComplex _).map P.π ≫
(HomologicalComplex.singleMapHomologicalComplex _ _ _).hom.app _
quasiIso := inferInstance
end CategoryTheory.Functor |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Injective/Preserves.lean | import Mathlib.CategoryTheory.Preadditive.Injective.Basic
/-!
# Preservation of injective objects
We define a typeclass `Functor.PreservesInjectiveObjects`.
We restate the existing result that if `F ⊣ G` is an adjunction and `F` preserves monomorphisms,
then `G` preserves injective objects. We show that the converse is true if the codomain of `F` has
enough injectives.
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{E : Type u₃} [Category.{v₃} E]
/-- A functor preserves injective objects if it maps injective objects to injective objects. -/
class Functor.PreservesInjectiveObjects (F : C ⥤ D) : Prop where
injective_obj {X : C} : Injective X → Injective (F.obj X)
/-- See `Functor.injective_obj_of_injective` for a variant taking `Injective X` as an explicit
argument. -/
instance Functor.injective_obj (F : C ⥤ D) [F.PreservesInjectiveObjects] (X : C) [Injective X] :
Injective (F.obj X) :=
Functor.PreservesInjectiveObjects.injective_obj inferInstance
/-- See `Functor.injective_obj` for a variant taking `Injective X` as a typeclass argument. -/
theorem Functor.injective_obj_of_injective (F : C ⥤ D) [F.PreservesInjectiveObjects] {X : C}
(h : Injective X) : Injective (F.obj X) :=
Functor.PreservesInjectiveObjects.injective_obj h
instance Functor.preservesInjectiveObjects_comp (F : C ⥤ D) (G : D ⥤ E)
[F.PreservesInjectiveObjects] [G.PreservesInjectiveObjects] :
(F ⋙ G).PreservesInjectiveObjects where
injective_obj := G.injective_obj_of_injective ∘ F.injective_obj_of_injective
theorem Functor.preservesInjectiveObjects_of_adjunction_of_preservesMonomorphisms
{F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) [F.PreservesMonomorphisms] :
G.PreservesInjectiveObjects where
injective_obj h := adj.map_injective _ h
instance (priority := low) Functor.preservesInjectiveObjects_of_isEquivalence {F : C ⥤ D}
[IsEquivalence F] : F.PreservesInjectiveObjects :=
preservesInjectiveObjects_of_adjunction_of_preservesMonomorphisms
F.asEquivalence.symm.toAdjunction
theorem Functor.preservesMonomorphisms_of_adjunction_of_preservesInjectiveObjects
[EnoughInjectives D] {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) [G.PreservesInjectiveObjects] :
F.PreservesMonomorphisms where
preserves {X Y} f _ := by
suffices ∃ h, F.map f ≫ h = Injective.ι (F.obj X) from mono_of_mono_fac this.choose_spec
exact ⟨F.map (Injective.factorThru (adj.unit.app X ≫ G.map (Injective.ι _)) f) ≫
adj.counit.app (Injective.under (F.obj X)), by simp [← Functor.map_comp_assoc]⟩
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Injective/LiftingProperties.lean | import Mathlib.CategoryTheory.Preadditive.Injective.Basic
import Mathlib.CategoryTheory.MorphismProperty.LiftingProperty
/-!
# Characterization of injective objects in terms of lifting properties
An object `I` is injective iff the morphism `I ⟶ 0` has the
right lifting property with respect to monomorphisms,
`injective_iff_rlp_monomorphisms_zero`.
-/
universe v u
namespace CategoryTheory
open Limits ZeroObject
variable {C : Type u} [Category.{v} C]
namespace Injective
lemma hasLiftingProperty_of_isZero
{A B I Z : C} (i : A ⟶ B) [Mono i] [Injective I] (p : I ⟶ Z) (hZ : IsZero Z) :
HasLiftingProperty i p where
sq_hasLift {f g} sq := ⟨⟨{
l := Injective.factorThru f i
fac_right := hZ.eq_of_tgt _ _ }⟩⟩
instance {A B I : C} (i : A ⟶ B) [Mono i] [Injective I] [HasZeroObject C] (p : I ⟶ 0) :
HasLiftingProperty i (p : I ⟶ 0) :=
Injective.hasLiftingProperty_of_isZero i p (isZero_zero C)
end Injective
lemma injective_iff_rlp_monomorphisms_of_isZero
[HasZeroMorphisms C] {I Z : C} (p : I ⟶ Z) (hZ : IsZero Z) :
Injective I ↔ (MorphismProperty.monomorphisms C).rlp p := by
obtain rfl := hZ.eq_of_tgt p 0
constructor
· intro _ A B i (_ : Mono i)
exact Injective.hasLiftingProperty_of_isZero i 0 hZ
· intro h
constructor
intro A B f i hi
have := h _ hi
have sq : CommSq f i (0 : I ⟶ Z) 0 := ⟨by simp⟩
exact ⟨sq.lift, by simp⟩
lemma injective_iff_rlp_monomorphisms_zero
[HasZeroMorphisms C] [HasZeroObject C] (I : C) :
Injective I ↔ (MorphismProperty.monomorphisms C).rlp (0 : I ⟶ 0) :=
injective_iff_rlp_monomorphisms_of_isZero _ (isZero_zero C)
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Injective/Basic.lean | import Mathlib.CategoryTheory.Preadditive.Projective.Basic
/-!
# Injective objects and categories with enough injectives
An object `J` is injective iff every morphism into `J` can be obtained by extending a monomorphism.
-/
noncomputable section
open CategoryTheory Limits Opposite
universe v v₁ v₂ u₁ u₂
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C]
/--
An object `J` is injective iff every morphism into `J` can be obtained by extending a monomorphism.
-/
class Injective (J : C) : Prop where
factors : ∀ {X Y : C} (g : X ⟶ J) (f : X ⟶ Y) [Mono f], ∃ h : Y ⟶ J, f ≫ h = g
attribute [inherit_doc Injective] Injective.factors
variable (C) in
/-- The `ObjectProperty C` corresponding to the notion of injective objects in `C`. -/
abbrev isInjective : ObjectProperty C := Injective
lemma Limits.IsZero.injective {X : C} (h : IsZero X) : Injective X where
factors _ _ _ := ⟨h.from_ _, h.eq_of_tgt _ _⟩
section
/-- An injective presentation of an object `X` consists of a monomorphism `f : X ⟶ J`
to some injective object `J`.
-/
structure InjectivePresentation (X : C) where
J : C
injective : Injective J := by infer_instance
f : X ⟶ J
mono : Mono f := by infer_instance
open InjectivePresentation in
attribute [inherit_doc InjectivePresentation] J injective f mono
attribute [instance] InjectivePresentation.injective InjectivePresentation.mono
variable (C)
/-- A category "has enough injectives" if every object has an injective presentation,
i.e. if for every object `X` there is an injective object `J` and a monomorphism `X ↪ J`. -/
class EnoughInjectives : Prop where
presentation : ∀ X : C, Nonempty (InjectivePresentation X)
attribute [inherit_doc EnoughInjectives] EnoughInjectives.presentation
end
namespace Injective
/--
Let `J` be injective and `g` a morphism into `J`, then `g` can be factored through any monomorphism.
-/
def factorThru {J X Y : C} [Injective J] (g : X ⟶ J) (f : X ⟶ Y) [Mono f] : Y ⟶ J :=
(Injective.factors g f).choose
@[reassoc (attr := simp)]
theorem comp_factorThru {J X Y : C} [Injective J] (g : X ⟶ J) (f : X ⟶ Y) [Mono f] :
f ≫ factorThru g f = g :=
(Injective.factors g f).choose_spec
section
open ZeroObject
instance zero_injective [HasZeroObject C] : Injective (0 : C) :=
(isZero_zero C).injective
end
theorem of_iso {P Q : C} (i : P ≅ Q) (hP : Injective P) : Injective Q :=
{
factors := fun g f mono => by
obtain ⟨h, h_eq⟩ := @Injective.factors C _ P _ _ _ (g ≫ i.inv) f mono
refine ⟨h ≫ i.hom, ?_⟩
rw [← Category.assoc, h_eq, Category.assoc, Iso.inv_hom_id, Category.comp_id] }
theorem iso_iff {P Q : C} (i : P ≅ Q) : Injective P ↔ Injective Q :=
⟨of_iso i, of_iso i.symm⟩
/-- The axiom of choice says that every nonempty type is an injective object in `Type`. -/
instance (X : Type u₁) [Nonempty X] : Injective X where
factors g f mono :=
⟨fun z => by
classical
exact
if h : z ∈ Set.range f then g (Classical.choose h) else Nonempty.some inferInstance, by
ext y
classical
change dite (f y ∈ Set.range f) (fun h => g (Classical.choose h)) _ = _
split_ifs <;> rename_i h
· rw [mono_iff_injective] at mono
rw [mono (Classical.choose_spec h)]
· exact False.elim (h ⟨y, rfl⟩)⟩
instance Type.enoughInjectives : EnoughInjectives (Type u₁) where
presentation X :=
Nonempty.intro
{ J := WithBot X
injective := inferInstance
f := WithBot.some
mono := by
rw [mono_iff_injective]
exact WithBot.coe_injective }
instance {P Q : C} [HasBinaryProduct P Q] [Injective P] [Injective Q] : Injective (P ⨯ Q) where
factors g f mono := by
use Limits.prod.lift (factorThru (g ≫ Limits.prod.fst) f) (factorThru (g ≫ Limits.prod.snd) f)
simp only [prod.comp_lift, comp_factorThru]
ext
· simp only [prod.lift_fst]
· simp only [prod.lift_snd]
instance {β : Type v} (c : β → C) [HasProduct c] [∀ b, Injective (c b)] : Injective (∏ᶜ c) where
factors g f mono := by
refine ⟨Pi.lift fun b => factorThru (g ≫ Pi.π c _) f, ?_⟩
ext b
simp only [Category.assoc, limit.lift_π, Fan.mk_π_app, comp_factorThru]
instance {P Q : C} [HasZeroMorphisms C] [HasBinaryBiproduct P Q] [Injective P] [Injective Q] :
Injective (P ⊞ Q) where
factors g f mono := by
refine ⟨biprod.lift (factorThru (g ≫ biprod.fst) f) (factorThru (g ≫ biprod.snd) f), ?_⟩
ext
· simp only [Category.assoc, biprod.lift_fst, comp_factorThru]
· simp only [Category.assoc, biprod.lift_snd, comp_factorThru]
instance {β : Type v} (c : β → C) [HasZeroMorphisms C] [HasBiproduct c] [∀ b, Injective (c b)] :
Injective (⨁ c) where
factors g f mono := by
refine ⟨biproduct.lift fun b => factorThru (g ≫ biproduct.π _ _) f, ?_⟩
ext
simp only [Category.assoc, biproduct.lift_π, comp_factorThru]
instance {P : Cᵒᵖ} [Projective P] : Injective no_index (unop P) where
factors g f mono :=
⟨(@Projective.factorThru Cᵒᵖ _ P _ _ _ g.op f.op _).unop, Quiver.Hom.op_inj (by simp)⟩
instance {J : Cᵒᵖ} [Injective J] : Projective no_index (unop J) where
factors f e he :=
⟨(@factorThru Cᵒᵖ _ J _ _ _ f.op e.op _).unop, Quiver.Hom.op_inj (by simp)⟩
instance {J : C} [Injective J] : Projective (op J) where
factors f e epi :=
⟨(@factorThru C _ J _ _ _ f.unop e.unop _).op, Quiver.Hom.unop_inj (by simp)⟩
instance {P : C} [Projective P] : Injective (op P) where
factors g f mono :=
⟨(@Projective.factorThru C _ P _ _ _ g.unop f.unop _).op, Quiver.Hom.unop_inj (by simp)⟩
theorem injective_iff_projective_op {J : C} : Injective J ↔ Projective (op J) :=
⟨fun _ => inferInstance, fun _ => show Injective (unop (op J)) from inferInstance⟩
theorem projective_iff_injective_op {P : C} : Projective P ↔ Injective (op P) :=
⟨fun _ => inferInstance, fun _ => show Projective (unop (op P)) from inferInstance⟩
theorem injective_iff_preservesEpimorphisms_yoneda_obj (J : C) :
Injective J ↔ (yoneda.obj J).PreservesEpimorphisms := by
rw [injective_iff_projective_op, Projective.projective_iff_preservesEpimorphisms_coyoneda_obj]
exact Functor.preservesEpimorphisms.iso_iff (Coyoneda.objOpOp _)
section Adjunction
open CategoryTheory.Functor
variable {D : Type u₂} [Category.{v₂} D]
variable {L : C ⥤ D} {R : D ⥤ C} [PreservesMonomorphisms L]
theorem injective_of_adjoint (adj : L ⊣ R) (J : D) [Injective J] : Injective <| R.obj J :=
⟨fun {A} {_} g f im =>
⟨adj.homEquiv _ _ (factorThru ((adj.homEquiv A J).symm g) (L.map f)),
(adj.homEquiv _ _).symm.injective
(by simp [Adjunction.homEquiv_unit, Adjunction.homEquiv_counit])⟩⟩
end Adjunction
section EnoughInjectives
variable [EnoughInjectives C]
/-- `Injective.under X` provides an arbitrarily chosen injective object equipped with
a monomorphism `Injective.ι : X ⟶ Injective.under X`.
-/
def under (X : C) : C :=
(EnoughInjectives.presentation X).some.J
instance injective_under (X : C) : Injective (under X) :=
(EnoughInjectives.presentation X).some.injective
/-- The monomorphism `Injective.ι : X ⟶ Injective.under X`
from the arbitrarily chosen injective object under `X`.
-/
def ι (X : C) : X ⟶ under X :=
(EnoughInjectives.presentation X).some.f
instance ι_mono (X : C) : Mono (ι X) :=
(EnoughInjectives.presentation X).some.mono
section
variable [HasZeroMorphisms C] {X Y : C} (f : X ⟶ Y) [HasCokernel f]
/-- When `C` has enough injectives, the object `Injective.syzygies f` is
an arbitrarily chosen injective object under `cokernel f`.
-/
def syzygies : C :=
under (cokernel f)
deriving Injective
/-- When `C` has enough injective,
`Injective.d f : Y ⟶ syzygies f` is the composition
`cokernel.π f ≫ ι (cokernel f)`.
(When `C` is abelian, we have `exact f (injective.d f)`.)
-/
abbrev d : Y ⟶ syzygies f :=
cokernel.π f ≫ ι (cokernel f)
end
end EnoughInjectives
instance [EnoughInjectives C] : EnoughProjectives Cᵒᵖ :=
⟨fun X => ⟨{ p := _, f := (Injective.ι (unop X)).op}⟩⟩
instance [EnoughProjectives C] : EnoughInjectives Cᵒᵖ :=
⟨fun X => ⟨⟨_, inferInstance, (Projective.π (unop X)).op, inferInstance⟩⟩⟩
theorem enoughProjectives_of_enoughInjectives_op [EnoughInjectives Cᵒᵖ] : EnoughProjectives C :=
⟨fun X => ⟨{ p := _, f := (Injective.ι (op X)).unop} ⟩⟩
theorem enoughInjectives_of_enoughProjectives_op [EnoughProjectives Cᵒᵖ] : EnoughInjectives C :=
⟨fun X => ⟨⟨_, inferInstance, (Projective.π (op X)).unop, inferInstance⟩⟩⟩
end Injective
namespace Adjunction
variable {D : Type*} [Category D] {F : C ⥤ D} {G : D ⥤ C}
theorem map_injective (adj : F ⊣ G) [F.PreservesMonomorphisms] (I : D) (hI : Injective I) :
Injective (G.obj I) :=
⟨fun {X} {Y} f g => by
intro
rcases hI.factors (F.map f ≫ adj.counit.app _) (F.map g) with ⟨w,h⟩
use adj.unit.app Y ≫ G.map w
rw [← unit_naturality_assoc, ← G.map_comp, h]
simp⟩
theorem injective_of_map_injective (adj : F ⊣ G) [G.Full] [G.Faithful] (I : D)
(hI : Injective (G.obj I)) : Injective I :=
⟨fun {X} {Y} f g => by
intro
haveI : PreservesLimitsOfSize.{0, 0} G := adj.rightAdjoint_preservesLimits
rcases hI.factors (G.map f) (G.map g) with ⟨w,h⟩
use inv (adj.counit.app _) ≫ F.map w ≫ adj.counit.app _
exact G.map_injective (by simpa)⟩
/-- Given an adjunction `F ⊣ G` such that `F` preserves monos, `G` maps an injective presentation
of `X` to an injective presentation of `G(X)`. -/
def mapInjectivePresentation (adj : F ⊣ G) [F.PreservesMonomorphisms] (X : D)
(I : InjectivePresentation X) : InjectivePresentation (G.obj X) where
J := G.obj I.J
injective := adj.map_injective _ I.injective
f := G.map I.f
mono := by
haveI : PreservesLimitsOfSize.{0, 0} G := adj.rightAdjoint_preservesLimits; infer_instance
/-- Given an adjunction `F ⊣ G` such that `F` preserves monomorphisms and is faithful,
then any injective presentation of `F(X)` can be pulled back to an injective presentation of `X`.
This is similar to `mapInjectivePresentation`. -/
def injectivePresentationOfMap (adj : F ⊣ G)
[F.PreservesMonomorphisms] [F.ReflectsMonomorphisms] (X : C)
(I : InjectivePresentation <| F.obj X) :
InjectivePresentation X where
J := G.obj I.J
injective := Injective.injective_of_adjoint adj _
f := adj.homEquiv _ _ I.f
end Adjunction
namespace Functor
variable {D : Type*} [Category D] (F : C ⥤ D)
theorem injective_of_map_injective [F.Full] [F.Faithful]
[F.PreservesMonomorphisms] {I : C} (hI : Injective (F.obj I)) : Injective I where
factors g f _ := by
obtain ⟨h, fac⟩ := hI.factors (F.map g) (F.map f)
exact ⟨F.preimage h, F.map_injective (by simp [fac])⟩
end Functor
/--
[Lemma 3.8](https://ncatlab.org/nlab/show/injective+object#preservation_of_injective_objects)
-/
lemma EnoughInjectives.of_adjunction {C : Type u₁} {D : Type u₂}
[Category.{v₁} C] [Category.{v₂} D]
{L : C ⥤ D} {R : D ⥤ C} (adj : L ⊣ R) [L.PreservesMonomorphisms] [L.ReflectsMonomorphisms]
[EnoughInjectives D] : EnoughInjectives C where
presentation _ :=
⟨adj.injectivePresentationOfMap _ (EnoughInjectives.presentation _).some⟩
/-- An equivalence of categories transfers enough injectives. -/
lemma EnoughInjectives.of_equivalence {C : Type u₁} {D : Type u₂}
[Category.{v₁} C] [Category.{v₂} D]
(e : C ⥤ D) [e.IsEquivalence] [EnoughInjectives D] : EnoughInjectives C :=
EnoughInjectives.of_adjunction (adj := e.asEquivalence.toAdjunction)
namespace Equivalence
variable {D : Type*} [Category D] (F : C ≌ D)
theorem map_injective_iff (P : C) : Injective (F.functor.obj P) ↔ Injective P :=
⟨F.symm.toAdjunction.injective_of_map_injective P, F.symm.toAdjunction.map_injective P⟩
/-- Given an equivalence of categories `F`, an injective presentation of `F(X)` induces an
injective presentation of `X.` -/
def injectivePresentationOfMapInjectivePresentation (X : C)
(I : InjectivePresentation (F.functor.obj X)) : InjectivePresentation X :=
F.toAdjunction.injectivePresentationOfMap _ I
theorem enoughInjectives_iff (F : C ≌ D) : EnoughInjectives C ↔ EnoughInjectives D :=
⟨fun h => h.of_adjunction F.symm.toAdjunction, fun h => h.of_adjunction F.toAdjunction⟩
end Equivalence
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Injective/Resolution.lean | import Mathlib.Algebra.Homology.QuasiIso
import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex
import Mathlib.Algebra.Homology.SingleHomology
import Mathlib.CategoryTheory.Preadditive.Injective.Basic
/-!
# Injective resolutions
An injective resolution `I : InjectiveResolution Z` of an object `Z : C` consists of
an `ℕ`-indexed cochain complex `I.cocomplex` of injective objects,
along with a quasi-isomorphism `I.ι` from the cochain complex consisting just of `Z`
in degree zero to `I.cocomplex`.
```
Z ----> 0 ----> ... ----> 0 ----> ...
| | |
| | |
v v v
I⁰ ---> I¹ ---> ... ----> Iⁿ ---> ...
```
-/
noncomputable section
universe v u
namespace CategoryTheory
open Limits HomologicalComplex CochainComplex
variable {C : Type u} [Category.{v} C] [HasZeroObject C] [HasZeroMorphisms C]
/--
An `InjectiveResolution Z` consists of a bundled `ℕ`-indexed cochain complex of injective objects,
along with a quasi-isomorphism from the complex consisting of just `Z` supported in degree `0`.
-/
structure InjectiveResolution (Z : C) where
/-- the cochain complex involved in the resolution -/
cocomplex : CochainComplex C ℕ
/-- the cochain complex must be degreewise injective -/
injective : ∀ n, Injective (cocomplex.X n) := by infer_instance
/-- the cochain complex must have homology -/
[hasHomology : ∀ i, cocomplex.HasHomology i]
/-- the morphism from the single cochain complex with `Z` in degree `0` -/
ι : (single₀ C).obj Z ⟶ cocomplex
/-- the morphism from the single cochain complex with `Z` in degree `0` is a quasi-isomorphism -/
quasiIso : QuasiIso ι := by infer_instance
open InjectiveResolution in
attribute [instance] injective hasHomology InjectiveResolution.quasiIso
/-- An object admits an injective resolution. -/
class HasInjectiveResolution (Z : C) : Prop where
out : Nonempty (InjectiveResolution Z)
attribute [inherit_doc HasInjectiveResolution] HasInjectiveResolution.out
section
variable (C)
/-- You will rarely use this typeclass directly: it is implied by the combination
`[EnoughInjectives C]` and `[Abelian C]`. -/
class HasInjectiveResolutions : Prop where
out : ∀ Z : C, HasInjectiveResolution Z
attribute [instance 100] HasInjectiveResolutions.out
end
namespace InjectiveResolution
variable {Z : C} (I : InjectiveResolution Z)
lemma cocomplex_exactAt_succ (n : ℕ) :
I.cocomplex.ExactAt (n + 1) := by
rw [← quasiIsoAt_iff_exactAt I.ι (n + 1) (exactAt_succ_single_obj _ _)]
infer_instance
lemma exact_succ (n : ℕ) :
(ShortComplex.mk _ _ (I.cocomplex.d_comp_d n (n + 1) (n + 2))).Exact :=
(HomologicalComplex.exactAt_iff' _ n (n + 1) (n + 2) (by simp)
(by simp only [CochainComplex.next]; rfl)).1 (I.cocomplex_exactAt_succ n)
@[simp]
theorem ι_f_succ (n : ℕ) : I.ι.f (n + 1) = 0 :=
(isZero_single_obj_X _ _ _ _ (by simp)).eq_of_src _ _
@[reassoc]
theorem ι_f_zero_comp_complex_d :
I.ι.f 0 ≫ I.cocomplex.d 0 1 = 0 := by
simp
theorem complex_d_comp (n : ℕ) :
I.cocomplex.d n (n + 1) ≫ I.cocomplex.d (n + 1) (n + 2) = 0 := by
simp
/-- The (limit) kernel fork given by the composition
`Z ⟶ I.cocomplex.X 0 ⟶ I.cocomplex.X 1` when `I : InjectiveResolution Z`. -/
@[simp]
def kernelFork : KernelFork (I.cocomplex.d 0 1) :=
KernelFork.ofι _ I.ι_f_zero_comp_complex_d
/-- `Z` is the kernel of `I.cocomplex.X 0 ⟶ I.cocomplex.X 1` when `I : InjectiveResolution Z`. -/
def isLimitKernelFork : IsLimit (I.kernelFork) := by
refine IsLimit.ofIsoLimit (I.cocomplex.cyclesIsKernel 0 1 (by simp)) (Iso.symm ?_)
refine Fork.ext ((singleObjHomologySelfIso _ _ _).symm ≪≫
isoOfQuasiIsoAt I.ι 0 ≪≫ I.cocomplex.isoHomologyπ₀.symm) ?_
rw [← cancel_epi (singleObjHomologySelfIso (ComplexShape.up ℕ) _ _).hom,
← cancel_epi (isoHomologyπ₀ _).hom,
← cancel_epi (singleObjCyclesSelfIso (ComplexShape.up ℕ) _ _).inv]
simp
instance (n : ℕ) : Mono (I.ι.f n) := by
cases n
· exact mono_of_isLimit_fork I.isLimitKernelFork
· rw [ι_f_succ]; infer_instance
variable (Z)
/-- An injective object admits a trivial injective resolution: itself in degree 0. -/
@[simps]
def self [Injective Z] : InjectiveResolution Z where
cocomplex := (CochainComplex.single₀ C).obj Z
ι := 𝟙 ((CochainComplex.single₀ C).obj Z)
injective n := by
cases n
· simpa
· apply IsZero.injective
apply HomologicalComplex.isZero_single_obj_X
simp
end InjectiveResolution
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Yoneda/Basic.lean | import Mathlib.CategoryTheory.Preadditive.Opposite
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Algebra.Category.Grp.Yoneda
/-!
# The Yoneda embedding for preadditive categories
The Yoneda embedding for preadditive categories sends an object `Y` to the presheaf sending an
object `X` to the group of morphisms `X ⟶ Y`. At each point, we get an additional `End Y`-module
structure.
We also show that this presheaf is additive and that it is compatible with the normal Yoneda
embedding in the expected way and deduce that the preadditive Yoneda embedding is fully faithful.
## TODO
* The Yoneda embedding is additive itself
-/
universe v u u₁
open CategoryTheory.Preadditive Opposite CategoryTheory.Limits CategoryTheory.Functor
noncomputable section
namespace CategoryTheory
variable {C : Type u} [Category.{v} C] [Preadditive C]
/-- The Yoneda embedding for preadditive categories sends an object `Y` to the presheaf sending an
object `X` to the `End Y`-module of morphisms `X ⟶ Y`.
-/
@[simps]
def preadditiveYonedaObj (Y : C) : Cᵒᵖ ⥤ ModuleCat.{v} (End Y) where
obj X := ModuleCat.of _ (X.unop ⟶ Y)
map f := ModuleCat.ofHom
{ toFun := fun g => f.unop ≫ g
map_add' := fun _ _ => comp_add _ _ _ _ _ _
map_smul' := fun _ _ => Eq.symm <| Category.assoc _ _ _ }
/-- The Yoneda embedding for preadditive categories sends an object `Y` to the presheaf sending an
object `X` to the group of morphisms `X ⟶ Y`. At each point, we get an additional `End Y`-module
structure, see `preadditiveYonedaObj`.
-/
@[simps obj]
def preadditiveYoneda : C ⥤ Cᵒᵖ ⥤ AddCommGrpCat.{v} where
obj Y := preadditiveYonedaObj Y ⋙ forget₂ _ _
map f :=
{ app := fun _ => AddCommGrpCat.ofHom
{ toFun := fun g => g ≫ f
map_zero' := Limits.zero_comp
map_add' := fun _ _ => add_comp _ _ _ _ _ _ }
naturality := fun _ _ _ => AddCommGrpCat.ext fun _ => Category.assoc _ _ _ }
/-- The Yoneda embedding for preadditive categories sends an object `X` to the copresheaf sending an
object `Y` to the `End X`-module of morphisms `X ⟶ Y`.
-/
@[simps]
def preadditiveCoyonedaObj (X : C) : C ⥤ ModuleCat.{v} (End X)ᵐᵒᵖ where
obj Y := ModuleCat.of _ (X ⟶ Y)
map f := ModuleCat.ofHom
{ toFun := fun g => g ≫ f
map_add' := fun _ _ => add_comp _ _ _ _ _ _
map_smul' := fun _ _ => Category.assoc _ _ _ }
/-- The Yoneda embedding for preadditive categories sends an object `X` to the copresheaf sending an
object `Y` to the group of morphisms `X ⟶ Y`. At each point, we get an additional `End X`-module
structure, see `preadditiveCoyonedaObj`.
-/
@[simps obj]
def preadditiveCoyoneda : Cᵒᵖ ⥤ C ⥤ AddCommGrpCat.{v} where
obj X := preadditiveCoyonedaObj (unop X) ⋙ forget₂ _ _
map f :=
{ app := fun _ => AddCommGrpCat.ofHom
{ toFun := fun g => f.unop ≫ g
map_zero' := Limits.comp_zero
map_add' := fun _ _ => comp_add _ _ _ _ _ _ }
naturality := fun _ _ _ =>
AddCommGrpCat.ext fun _ => Eq.symm <| Category.assoc _ _ _ }
instance additive_yonedaObj (X : C) : Functor.Additive (preadditiveYonedaObj X) where
instance additive_yonedaObj' (X : C) : Functor.Additive (preadditiveYoneda.obj X) where
instance additive_coyonedaObj (X : C) : Functor.Additive (preadditiveCoyonedaObj X) where
instance additive_coyonedaObj' (X : Cᵒᵖ) : Functor.Additive (preadditiveCoyoneda.obj X) where
/-- Composing the preadditive yoneda embedding with the forgetful functor yields the regular
Yoneda embedding.
-/
@[simp]
theorem whiskering_preadditiveYoneda :
preadditiveYoneda ⋙
(whiskeringRight Cᵒᵖ AddCommGrpCat (Type v)).obj (forget AddCommGrpCat) =
yoneda :=
rfl
/-- Composing the preadditive yoneda embedding with the forgetful functor yields the regular
Yoneda embedding.
-/
@[simp]
theorem whiskering_preadditiveCoyoneda :
preadditiveCoyoneda ⋙
(whiskeringRight C AddCommGrpCat (Type v)).obj (forget AddCommGrpCat) =
coyoneda :=
rfl
instance full_preadditiveYoneda : (preadditiveYoneda : C ⥤ Cᵒᵖ ⥤ AddCommGrpCat).Full :=
let _ : Functor.Full (preadditiveYoneda ⋙
(whiskeringRight Cᵒᵖ AddCommGrpCat (Type v)).obj (forget AddCommGrpCat)) :=
Yoneda.yoneda_full
Functor.Full.of_comp_faithful preadditiveYoneda
((whiskeringRight Cᵒᵖ AddCommGrpCat (Type v)).obj (forget AddCommGrpCat))
instance full_preadditiveCoyoneda : (preadditiveCoyoneda : Cᵒᵖ ⥤ C ⥤ AddCommGrpCat).Full :=
let _ : Functor.Full (preadditiveCoyoneda ⋙
(whiskeringRight C AddCommGrpCat (Type v)).obj (forget AddCommGrpCat)) :=
Coyoneda.coyoneda_full
Functor.Full.of_comp_faithful preadditiveCoyoneda
((whiskeringRight C AddCommGrpCat (Type v)).obj (forget AddCommGrpCat))
instance faithful_preadditiveYoneda : (preadditiveYoneda : C ⥤ Cᵒᵖ ⥤ AddCommGrpCat).Faithful :=
Functor.Faithful.of_comp_eq whiskering_preadditiveYoneda
instance faithful_preadditiveCoyoneda :
(preadditiveCoyoneda : Cᵒᵖ ⥤ C ⥤ AddCommGrpCat).Faithful :=
Functor.Faithful.of_comp_eq whiskering_preadditiveCoyoneda
section
variable {D : Type u₁} [Category.{v} D] [Preadditive D] (F : C ⥤ D) [F.Additive]
/-- The natural transformation `preadditiveYoneda.obj X ⟶ F.op ⋙ preadditiveYoneda.obj (F.obj X)`
when `F : C ⥤ D` is an additive functor between preadditive categories and `X : C`. -/
@[simps]
def preadditiveYonedaMap (X : C) :
preadditiveYoneda.obj X ⟶ F.op ⋙ preadditiveYoneda.obj (F.obj X) where
app Y := AddCommGrpCat.ofHom F.mapAddHom
end
/-- The preadditive coyoneda functor for the category `AddCommGrpCat` agrees with
`AddCommGrpCat.coyoneda`. -/
def _root_.AddCommGrpCat.preadditiveCoyonedaIso : preadditiveCoyoneda ≅ AddCommGrpCat.coyoneda :=
NatIso.ofComponents fun X ↦ NatIso.ofComponents fun Y ↦ AddCommGrpCat.homAddEquiv.toAddCommGrpIso
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Yoneda/Injective.lean | import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic
import Mathlib.CategoryTheory.Preadditive.Injective.Basic
import Mathlib.Algebra.Category.Grp.EpiMono
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
An object is injective iff the preadditive yoneda functor on it preserves epimorphisms.
-/
universe v u
open Opposite
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
section Preadditive
variable [Preadditive C]
namespace Injective
theorem injective_iff_preservesEpimorphisms_preadditiveYoneda_obj (J : C) :
Injective J ↔ (preadditiveYoneda.obj J).PreservesEpimorphisms := by
rw [injective_iff_preservesEpimorphisms_yoneda_obj]
refine
⟨fun h : (preadditiveYoneda.obj J ⋙ (forget AddCommGrpCat)).PreservesEpimorphisms => ?_, ?_⟩
· exact
Functor.preservesEpimorphisms_of_preserves_of_reflects (preadditiveYoneda.obj J) (forget _)
· intro
exact (inferInstance : (preadditiveYoneda.obj J ⋙ forget _).PreservesEpimorphisms)
theorem injective_iff_preservesEpimorphisms_preadditive_yoneda_obj' (J : C) :
Injective J ↔ (preadditiveYonedaObj J).PreservesEpimorphisms := by
rw [injective_iff_preservesEpimorphisms_yoneda_obj]
refine ⟨fun h : (preadditiveYonedaObj J ⋙ (forget <| ModuleCat (End J))).PreservesEpimorphisms =>
?_, ?_⟩
· exact
Functor.preservesEpimorphisms_of_preserves_of_reflects (preadditiveYonedaObj J) (forget _)
· intro
exact (inferInstance : (preadditiveYonedaObj J ⋙ forget _).PreservesEpimorphisms)
end Injective
end Preadditive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Yoneda/Projective.lean | import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic
import Mathlib.CategoryTheory.Preadditive.Projective.Basic
import Mathlib.Algebra.Category.Grp.EpiMono
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
An object is projective iff the preadditive coyoneda functor on it preserves epimorphisms.
-/
universe v u
open Opposite
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
section Preadditive
variable [Preadditive C]
namespace Projective
theorem projective_iff_preservesEpimorphisms_preadditiveCoyoneda_obj (P : C) :
Projective P ↔ (preadditiveCoyoneda.obj (op P)).PreservesEpimorphisms := by
rw [projective_iff_preservesEpimorphisms_coyoneda_obj]
refine ⟨fun h : (preadditiveCoyoneda.obj (op P) ⋙
forget AddCommGrpCat).PreservesEpimorphisms => ?_, ?_⟩
· exact Functor.preservesEpimorphisms_of_preserves_of_reflects (preadditiveCoyoneda.obj (op P))
(forget _)
· intro
exact (inferInstance : (preadditiveCoyoneda.obj (op P) ⋙ forget _).PreservesEpimorphisms)
theorem projective_iff_preservesEpimorphisms_preadditiveCoyonedaObj (P : C) :
Projective P ↔ (preadditiveCoyonedaObj P).PreservesEpimorphisms := by
rw [projective_iff_preservesEpimorphisms_coyoneda_obj]
refine ⟨fun h : (preadditiveCoyonedaObj P ⋙ forget _).PreservesEpimorphisms => ?_, ?_⟩
· exact Functor.preservesEpimorphisms_of_preserves_of_reflects (preadditiveCoyonedaObj P)
(forget _)
· intro
exact (inferInstance : (preadditiveCoyonedaObj P ⋙ forget _).PreservesEpimorphisms)
end Projective
end Preadditive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Preadditive/Yoneda/Limits.lean | import Mathlib.CategoryTheory.Preadditive.Yoneda.Basic
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.CategoryTheory.Limits.Yoneda
/-!
# The Yoneda embedding for preadditive categories preserves limits
The Yoneda embedding for preadditive categories preserves limits.
## Implementation notes
This is in a separate file to avoid having to import the development of the abelian structure on
`ModuleCat` in the main file about the preadditive Yoneda embedding.
-/
universe v u
open CategoryTheory.Preadditive Opposite CategoryTheory.Limits
noncomputable section
namespace CategoryTheory
variable {C : Type u} [Category.{v} C] [Preadditive C]
instance preservesLimits_preadditiveYonedaObj (X : C) : PreservesLimits (preadditiveYonedaObj X) :=
have : PreservesLimits (preadditiveYonedaObj X ⋙ forget _) :=
(inferInstance : PreservesLimits (yoneda.obj X))
preservesLimits_of_reflects_of_preserves _ (forget _)
instance preservesLimits_preadditiveCoyonedaObj (X : C) :
PreservesLimits (preadditiveCoyonedaObj X) :=
have : PreservesLimits (preadditiveCoyonedaObj X ⋙ forget _) :=
(inferInstance : PreservesLimits (coyoneda.obj (op X)))
preservesLimits_of_reflects_of_preserves _ (forget _)
instance preservesLimits_preadditiveYoneda_obj (X : C) :
PreservesLimits (preadditiveYoneda.obj X) :=
show PreservesLimits (preadditiveYonedaObj X ⋙ forget₂ _ _) from inferInstance
instance preservesLimits_preadditiveCoyoneda_obj (X : Cᵒᵖ) :
PreservesLimits (preadditiveCoyoneda.obj X) :=
show PreservesLimits (preadditiveCoyonedaObj (unop X) ⋙ forget₂ _ _) from inferInstance
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/Finite.lean | import Mathlib.CategoryTheory.Limits.Filtered
import Mathlib.CategoryTheory.Limits.Preserves.Filtered
import Mathlib.CategoryTheory.Limits.Types.Filtered
import Mathlib.CategoryTheory.MorphismProperty.Basic
import Mathlib.CategoryTheory.Presentable.Basic
/-!
# Finitely Presentable Objects
We define finitely presentable objects as a synonym for `ℵ₀`-presentable objects,
and link this definition with the preservation of filtered colimits.
-/
universe w v' v u' u
namespace CategoryTheory
open Limits Opposite Cardinal
variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
attribute [local instance] fact_isRegular_aleph0
/-- A functor `F : C ⥤ D` is finitely accessible if it is `ℵ₀`-accessible.
Equivalently, it preserves all filtered colimits.
See `CategoryTheory.Functor.IsFinitelyAccessible_iff_preservesFilteredColimits`. -/
abbrev Functor.IsFinitelyAccessible (F : C ⥤ D) : Prop := IsCardinalAccessible.{w} F ℵ₀
lemma Functor.IsFinitelyAccessible_iff_preservesFilteredColimitsOfSize {F : C ⥤ D} :
IsFinitelyAccessible.{w} F ↔ PreservesFilteredColimitsOfSize.{w, w} F := by
refine ⟨fun ⟨H⟩ ↦ ⟨?_⟩, fun ⟨H⟩ ↦ ⟨?_⟩⟩ <;>
simp only [isCardinalFiltered_aleph0_iff] at * <;>
exact H
lemma Functor.isFinitelyAccessible_iff_preservesFilteredColimits {F : C ⥤ D} :
IsFinitelyAccessible.{v'} F ↔ PreservesFilteredColimits F :=
IsFinitelyAccessible_iff_preservesFilteredColimitsOfSize
/-- An object `X` is finitely presentable if `Hom(X, -)` preserves all filtered colimits. -/
abbrev IsFinitelyPresentable (X : C) : Prop :=
IsCardinalPresentable.{w} X ℵ₀
variable (C) in
/-- `IsFinitelyPresentable` as an `ObjectProperty` on `C`. This is sometimes called "compact". -/
def ObjectProperty.isFinitelyPresentable : ObjectProperty C := fun X ↦ IsFinitelyPresentable.{w} X
variable (C) in
/-- A morphism `f : X ⟶ Y` is finitely presentable if it is so as an object of `Under X`. -/
def MorphismProperty.isFinitelyPresentable : MorphismProperty C :=
fun _ _ f ↦ ObjectProperty.isFinitelyPresentable.{w} _ (CategoryTheory.Under.mk f)
lemma isFinitelyPresentable_iff_preservesFilteredColimitsOfSize {X : C} :
IsFinitelyPresentable.{w} X ↔ PreservesFilteredColimitsOfSize.{w, w} (coyoneda.obj (op X)) :=
Functor.IsFinitelyAccessible_iff_preservesFilteredColimitsOfSize
lemma isFinitelyPresentable_iff_preservesFilteredColimits {X : C} :
IsFinitelyPresentable.{v} X ↔ PreservesFilteredColimits (coyoneda.obj (op X)) :=
Functor.IsFinitelyAccessible_iff_preservesFilteredColimitsOfSize
instance (X : C) [IsFinitelyPresentable.{w} X] :
PreservesFilteredColimitsOfSize.{w, w} (coyoneda.obj (op X)) := by
rw [← isFinitelyPresentable_iff_preservesFilteredColimitsOfSize]
infer_instance
lemma IsFinitelyPresentable.exists_hom_of_isColimit {J : Type w} [SmallCategory J] [IsFiltered J]
{D : J ⥤ C} {c : Cocone D} (hc : IsColimit c) {X : C} [IsFinitelyPresentable.{w} X]
(f : X ⟶ c.pt) :
∃ (j : J) (p : X ⟶ D.obj j), p ≫ c.ι.app j = f :=
Types.jointly_surjective_of_isColimit (isColimitOfPreserves (coyoneda.obj (op X)) hc) f
lemma IsFinitelyPresentable.exists_eq_of_isColimit {J : Type w} [SmallCategory J] [IsFiltered J]
{D : J ⥤ C} {c : Cocone D} (hc : IsColimit c) {X : C} [IsFinitelyPresentable.{w} X]
{i j : J} (f : X ⟶ D.obj i) (g : X ⟶ D.obj j) (h : f ≫ c.ι.app i = g ≫ c.ι.app j) :
∃ (k : J) (u : i ⟶ k) (v : j ⟶ k), f ≫ D.map u = g ≫ D.map v :=
(Types.FilteredColimit.isColimit_eq_iff _ (isColimitOfPreserves (coyoneda.obj (op X)) hc)).mp h
lemma IsFinitelyPresentable.exists_hom_of_isColimit_under
{J : Type w} [SmallCategory J] [IsFiltered J] {D : J ⥤ C} {c : Cocone D} (hc : IsColimit c)
{X A : C} (p : X ⟶ A) (s : (Functor.const J).obj X ⟶ D)
[IsFinitelyPresentable.{w} (Under.mk p)]
(f : A ⟶ c.pt) (h : ∀ (j : J), s.app j ≫ c.ι.app j = p ≫ f) :
∃ (j : J) (q : A ⟶ D.obj j), p ≫ q = s.app j ∧ q ≫ c.ι.app j = f := by
have : Nonempty J := IsFiltered.nonempty
let hc' := Under.isColimitLiftCocone D s c (p ≫ f) h hc
obtain ⟨j, q, hq⟩ := exists_hom_of_isColimit (X := Under.mk p) hc' (Under.homMk f rfl)
use j, q.right, Under.w q, congr($(hq).right)
lemma HasCardinalFilteredColimits_iff_hasFilteredColimitsOfSize :
HasCardinalFilteredColimits.{w} C ℵ₀ ↔ HasFilteredColimitsOfSize.{w, w} C := by
refine ⟨fun ⟨H⟩ ↦ ⟨?_⟩, fun ⟨H⟩ ↦ ⟨?_⟩⟩ <;>
simp only [isCardinalFiltered_aleph0_iff] at * <;>
exact H
lemma HasCardinalFilteredColimits_iff_hasFilteredColimits :
HasCardinalFilteredColimits.{v} C ℵ₀ ↔ HasFilteredColimits C :=
HasCardinalFilteredColimits_iff_hasFilteredColimitsOfSize
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/LocallyPresentable.lean | import Mathlib.CategoryTheory.Presentable.CardinalFilteredPresentation
/-!
# Locally presentable and accessible categories
In this file, we define the notion of locally presentable and accessible
categories. We first define these notions for a category `C` relative to a
fixed regular cardinal `κ` (typeclasses `IsCardinalLocallyPresentable C κ`
and `IsCardinalAccessibleCategory C κ`). The existence of such a regular
cardinal `κ` is asserted in the typeclasses `IsLocallyPresentable` and
`IsAccessibleCategory`. We show that in a locally presentable or
accessible category, any object is presentable.
## References
* [Adámek, J. and Rosický, J., *Locally presentable and accessible categories*][Adamek_Rosicky_1994]
-/
universe w v u
namespace CategoryTheory
open Limits
section
variable (C : Type u) [Category.{v} C] (κ : Cardinal.{w}) [Fact κ.IsRegular]
/-- Given a regular cardinal `κ`, a category `C` is `κ`-locally presentable
if it is cocomplete and admits a (small) family `G : ι → C` of `κ`-presentable
objects such that any object identifies as a `κ`-filtered colimit of these objects. -/
class IsCardinalLocallyPresentable : Prop
extends HasCardinalFilteredGenerators C κ, HasColimitsOfSize.{w, w} C where
/-- Given a regular cardinal `κ`, a category `C` is `κ`-accessible
if it has `κ`-filtered colimits and admits a (small) family `G : ι → C` of `κ`-presentable
objects such that any object identifies as a `κ`-filtered colimit of these objects. -/
class IsCardinalAccessibleCategory : Prop
extends HasCardinalFilteredGenerators C κ, HasCardinalFilteredColimits.{w} C κ where
instance [IsCardinalLocallyPresentable C κ] : IsCardinalAccessibleCategory C κ where
end
section
/-- A category `C` is locally presentable if it is `κ`-locally presentable
for some regular cardinal `κ`. -/
@[pp_with_univ]
class IsLocallyPresentable (C : Type u) [hC : Category.{v} C] : Prop where
exists_cardinal (C) [hC] : ∃ (κ : Cardinal.{w}) (_ : Fact κ.IsRegular),
IsCardinalLocallyPresentable C κ
/-- A category `C` is accessible if it is `κ`-accessible
for some regular cardinal `κ`. -/
@[pp_with_univ]
class IsAccessibleCategory (C : Type u) [hC : Category.{v} C] : Prop where
exists_cardinal (C) [hC] : ∃ (κ : Cardinal.{w}) (_ : Fact κ.IsRegular),
IsCardinalAccessibleCategory C κ
variable (C : Type u) [hC : Category.{v} C]
instance [IsLocallyPresentable.{w} C] : IsAccessibleCategory.{w} C where
exists_cardinal := by
obtain ⟨κ, hκ, h'⟩ := IsLocallyPresentable.exists_cardinal C
exact ⟨κ, hκ, inferInstance⟩
instance [IsAccessibleCategory.{w} C] (X : C) : IsPresentable.{w} X := by
obtain ⟨κ, _, _⟩ := IsAccessibleCategory.exists_cardinal C
obtain ⟨ι, G, h⟩ := HasCardinalFilteredGenerators.exists_generators C κ
apply h.presentable
end
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/ColimitPresentation.lean | import Mathlib.CategoryTheory.Limits.Presentation
import Mathlib.CategoryTheory.Presentable.Finite
/-!
# Presentation of a colimit of objects equipped with a presentation
## Main definition:
- `CategoryTheory.Limits.ColimitPresentation.bind`: Given a colimit presentation of `X` and
colimit presentations of the components, this is the colimit presentation over the sigma type.
-/
universe s t w v u
namespace CategoryTheory.Limits.ColimitPresentation
variable {C : Type u} [Category.{v} C]
variable {J : Type*} {I : J → Type*} [Category J] [∀ j, Category (I j)]
{D : J ⥤ C} {P : ∀ j, ColimitPresentation (I j) (D.obj j)}
set_option linter.unusedVariables false in
/-- The type underlying the category used in the construction of the composition
of colimit presentations. This is simply `Σ j, I j` but with a different category structure. -/
@[nolint unusedArguments]
def Total (P : ∀ j, ColimitPresentation (I j) (D.obj j)) : Type _ :=
Σ j, I j
variable (P) in
/-- Constructor for `Total` to guide type checking. -/
abbrev Total.mk (i : J) (k : I i) : Total P := ⟨i, k⟩
/-- Morphisms in the `Total` category. -/
@[ext]
structure Total.Hom (k l : Total P) where
/-- The underlying morphism in the first component. -/
base : k.1 ⟶ l.1
/-- A morphism in `C`. -/
hom : (P k.1).diag.obj k.2 ⟶ (P l.1).diag.obj l.2
w : (P k.1).ι.app k.2 ≫ D.map base = hom ≫ (P l.1).ι.app l.2 := by cat_disch
attribute [reassoc] Total.Hom.w
/-- Composition of morphisms in the `Total` category. -/
@[simps]
def Total.Hom.comp {k l m : Total P} (f : k.Hom l) (g : l.Hom m) : k.Hom m where
base := f.base ≫ g.base
hom := f.hom ≫ g.hom
w := by
simp only [Functor.const_obj_obj, Functor.map_comp, Category.assoc]
rw [f.w_assoc, g.w]
@[simps! id_base id_hom comp_base comp_hom]
instance : Category (Total P) where
Hom := Total.Hom
id _ := { base := 𝟙 _, hom := 𝟙 _ }
comp := Total.Hom.comp
instance [LocallySmall.{w} C] [LocallySmall.{w} J] : LocallySmall.{w} (Total P) where
hom_small k l :=
let f (x : k ⟶ l) : (k.1 ⟶ l.1) × ((P k.1).diag.obj k.2 ⟶ (P l.1).diag.obj l.2) :=
(x.base, x.hom)
small_of_injective (f := f) (by grind [Function.Injective, Total.Hom.ext])
section Small
variable {J : Type w} {I : J → Type w} [SmallCategory J] [∀ j, SmallCategory (I j)]
{D : J ⥤ C} {P : ∀ j, ColimitPresentation (I j) (D.obj j)}
lemma Total.exists_hom_of_hom {j j' : J} (i : I j) (u : j ⟶ j')
[IsFiltered (I j')] [IsFinitelyPresentable.{w} ((P j).diag.obj i)] :
∃ (i' : I j') (f : Total.mk P j i ⟶ Total.mk P j' i'), f.base = u := by
obtain ⟨i', q, hq⟩ := IsFinitelyPresentable.exists_hom_of_isColimit (P j').isColimit
((P j).ι.app i ≫ D.map u)
use i', { base := u, hom := q, w := by simp [← hq] }
instance [IsFiltered J] [∀ j, IsFiltered (I j)] : Nonempty (Total P) := by
obtain ⟨j⟩ : Nonempty J := IsFiltered.nonempty
obtain ⟨i⟩ : Nonempty (I j) := IsFiltered.nonempty
exact ⟨⟨j, i⟩⟩
instance [IsFiltered J] [∀ j, IsFiltered (I j)]
[∀ j i, IsFinitelyPresentable.{w} ((P j).diag.obj i)] :
IsFiltered (Total P) where
cocone_objs k l := by
let a := IsFiltered.max k.1 l.1
obtain ⟨a', f, hf⟩ := Total.exists_hom_of_hom (P := P) k.2 (IsFiltered.leftToMax k.1 l.1)
obtain ⟨b', g, hg⟩ := Total.exists_hom_of_hom (P := P) l.2 (IsFiltered.rightToMax k.1 l.1)
refine ⟨⟨a, IsFiltered.max a' b'⟩, ?_, ?_, trivial⟩
· exact f ≫ { base := 𝟙 _, hom := (P _).diag.map (IsFiltered.leftToMax _ _) }
· exact g ≫ { base := 𝟙 _, hom := (P _).diag.map (IsFiltered.rightToMax _ _) }
cocone_maps {k l} f g := by
let a := IsFiltered.coeq f.base g.base
obtain ⟨a', u, hu⟩ := Total.exists_hom_of_hom (P := P) l.2 (IsFiltered.coeqHom f.base g.base)
have : (f.hom ≫ u.hom) ≫ (P _).ι.app _ = (g.hom ≫ u.hom) ≫ (P _).ι.app _ := by
simp only [Category.assoc, Functor.const_obj_obj, ← u.w, ← f.w_assoc, ← g.w_assoc]
rw [← Functor.map_comp, hu, IsFiltered.coeq_condition f.base g.base]
simp
obtain ⟨j, p, q, hpq⟩ := IsFinitelyPresentable.exists_eq_of_isColimit (P _).isColimit _ _ this
dsimp at p q
refine ⟨⟨a, IsFiltered.coeq p q⟩,
u ≫ { base := 𝟙 _, hom := (P _).diag.map (p ≫ IsFiltered.coeqHom p q) }, ?_⟩
apply Total.Hom.ext
· simp [hu, IsFiltered.coeq_condition f.base g.base]
· rw [Category.assoc] at hpq
simp only [Functor.map_comp, comp_hom, reassoc_of% hpq]
simp [← Functor.map_comp, ← IsFiltered.coeq_condition]
/-- If `P` is a colimit presentation over `J` of `X` and for every `j` we are given a colimit
presentation `Qⱼ` over `I j` of the `P.diag.obj j`, this is the refined colimit presentation of `X`
over `Total Q`. -/
@[simps]
def bind {X : C} (P : ColimitPresentation J X) (Q : ∀ j, ColimitPresentation (I j) (P.diag.obj j))
[∀ j, IsFiltered (I j)] [∀ j i, IsFinitelyPresentable.{w} ((Q j).diag.obj i)] :
ColimitPresentation (Total Q) X where
diag.obj k := (Q k.1).diag.obj k.2
diag.map {k l} f := f.hom
ι.app k := (Q k.1).ι.app k.2 ≫ P.ι.app k.1
ι.naturality {k l} u := by simp [← u.w_assoc]
isColimit.desc c := P.isColimit.desc
{ pt := c.pt
ι.app j := (Q j).isColimit.desc
{ pt := c.pt
ι.app i := c.ι.app ⟨j, i⟩
ι.naturality {i i'} u := by
let v : Total.mk Q j i ⟶ .mk _ j i' := { base := 𝟙 _, hom := (Q _).diag.map u }
simpa using c.ι.naturality v }
ι.naturality {j j'} u := by
refine (Q j).isColimit.hom_ext fun i ↦ ?_
simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.comp_id,
(Q j).isColimit.fac]
obtain ⟨i', hom, rfl⟩ := Total.exists_hom_of_hom (P := Q) i u
rw [reassoc_of% hom.w, (Q j').isColimit.fac]
simpa using c.ι.naturality hom }
isColimit.fac := fun c ⟨j, i⟩ ↦ by simp [P.isColimit.fac, (Q j).isColimit.fac]
isColimit.uniq c m hm := by
refine P.isColimit.hom_ext fun j ↦ ?_
simp only [Functor.const_obj_obj, P.isColimit.fac]
refine (Q j).isColimit.hom_ext fun i ↦ ?_
simpa [(Q j).isColimit.fac] using hm (.mk _ j i)
end Small
end CategoryTheory.Limits.ColimitPresentation |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/Basic.lean | import Mathlib.CategoryTheory.Adjunction.Limits
import Mathlib.CategoryTheory.Limits.Preserves.Ulift
import Mathlib.CategoryTheory.Presentable.IsCardinalFiltered
import Mathlib.SetTheory.Cardinal.HasCardinalLT
/-! # Presentable objects
A functor `F : C ⥤ D` is `κ`-accessible (`Functor.IsCardinalAccessible`)
if it commutes with colimits of shape `J` where `J` is any `κ`-filtered category
(that is essentially small relative to the universe `w` such that `κ : Cardinal.{w}`.).
We also introduce another typeclass `Functor.IsAccessible` saying that there exists
a regular cardinal `κ` such that `Functor.IsCardinalAccessible`.
An object `X` of a category is `κ`-presentable (`IsCardinalPresentable`)
if the functor `Hom(X, _)` (i.e. `coyoneda.obj (op X)`) is `κ`-accessible.
Similar as for accessible functors, we define a type class `IsAccessible`.
## References
* [Adámek, J. and Rosický, J., *Locally presentable and accessible categories*][Adamek_Rosicky_1994]
-/
universe w w' v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
open Limits Opposite
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
namespace Functor
section
variable (F G : C ⥤ D) (e : F ≅ G) (κ : Cardinal.{w}) [Fact κ.IsRegular]
/-- A functor `F : C ⥤ D` is `κ`-accessible (with `κ` a regular cardinal)
if it preserves colimits of shape `J` where `J` is any `κ`-filtered category.
In the mathematical literature, some assumptions are often made on the
categories `C` or `D` (e.g. the existence of `κ`-filtered colimits,
see `HasCardinalFilteredColimits` below), but here we do not
make such assumptions. -/
class IsCardinalAccessible : Prop where
preservesColimitOfShape (J : Type w) [SmallCategory J] [IsCardinalFiltered J κ] :
PreservesColimitsOfShape J F
lemma preservesColimitsOfShape_of_isCardinalAccessible [F.IsCardinalAccessible κ]
(J : Type w) [SmallCategory J] [IsCardinalFiltered J κ] :
PreservesColimitsOfShape J F :=
IsCardinalAccessible.preservesColimitOfShape κ _
lemma preservesColimitsOfShape_of_isCardinalAccessible_of_essentiallySmall
[F.IsCardinalAccessible κ]
(J : Type u₃) [Category.{v₃} J] [EssentiallySmall.{w} J] [IsCardinalFiltered J κ] :
PreservesColimitsOfShape J F := by
have := IsCardinalFiltered.of_equivalence κ (equivSmallModel.{w} J)
have := F.preservesColimitsOfShape_of_isCardinalAccessible κ (SmallModel.{w} J)
exact preservesColimitsOfShape_of_equiv (equivSmallModel.{w} J).symm F
variable {κ} in
lemma isCardinalAccessible_of_le
[F.IsCardinalAccessible κ] {κ' : Cardinal.{w}} [Fact κ'.IsRegular] (h : κ ≤ κ') :
F.IsCardinalAccessible κ' where
preservesColimitOfShape {J _ _} := by
have := IsCardinalFiltered.of_le J h
exact F.preservesColimitsOfShape_of_isCardinalAccessible κ J
include e in
variable {F G} in
lemma isCardinalAccessible_of_natIso [F.IsCardinalAccessible κ] : G.IsCardinalAccessible κ where
preservesColimitOfShape J _ hκ := by
have := F.preservesColimitsOfShape_of_isCardinalAccessible κ J
exact preservesColimitsOfShape_of_natIso e
end
section
variable (F : C ⥤ D)
/-- A functor is accessible relative to a universe `w` if
it is `κ`-accessible for some regular `κ : Cardinal.{w}`. -/
@[pp_with_univ]
class IsAccessible : Prop where
exists_cardinal : ∃ (κ : Cardinal.{w}) (_ : Fact κ.IsRegular), IsCardinalAccessible F κ
lemma isAccessible_of_isCardinalAccessible (κ : Cardinal.{w}) [Fact κ.IsRegular]
[IsCardinalAccessible F κ] : IsAccessible.{w} F where
exists_cardinal := ⟨κ, inferInstance, inferInstance⟩
end
end Functor
section
variable (X : C) (Y : C) (e : X ≅ Y) (κ : Cardinal.{w}) [Fact κ.IsRegular]
/-- An object `X` in a category is `κ`-presentable (for `κ` a regular cardinal)
when the functor `Hom(X, _)` preserves colimits indexed by
`κ`-filtered categories. -/
abbrev IsCardinalPresentable : Prop := (coyoneda.obj (op X)).IsCardinalAccessible κ
lemma preservesColimitsOfShape_of_isCardinalPresentable [IsCardinalPresentable X κ]
(J : Type w) [SmallCategory.{w} J] [IsCardinalFiltered J κ] :
PreservesColimitsOfShape J (coyoneda.obj (op X)) :=
(coyoneda.obj (op X)).preservesColimitsOfShape_of_isCardinalAccessible κ J
lemma preservesColimitsOfShape_of_isCardinalPresentable_of_essentiallySmall
[IsCardinalPresentable X κ]
(J : Type u₃) [Category.{v₃} J] [EssentiallySmall.{w} J] [IsCardinalFiltered J κ] :
PreservesColimitsOfShape J (coyoneda.obj (op X)) :=
(coyoneda.obj (op X)).preservesColimitsOfShape_of_isCardinalAccessible_of_essentiallySmall κ J
variable {κ} in
lemma isCardinalPresentable_of_le [IsCardinalPresentable X κ]
{κ' : Cardinal.{w}} [Fact κ'.IsRegular] (h : κ ≤ κ') :
IsCardinalPresentable X κ' :=
(coyoneda.obj (op X)).isCardinalAccessible_of_le h
include e in
variable {X Y} in
lemma isCardinalPresentable_of_iso [IsCardinalPresentable X κ] : IsCardinalPresentable Y κ :=
Functor.isCardinalAccessible_of_natIso (coyoneda.mapIso e.symm.op) κ
lemma isCardinalPresentable_of_equivalence
{C' : Type u₃} [Category.{v₃} C'] [IsCardinalPresentable X κ] (e : C ≌ C') :
IsCardinalPresentable (e.functor.obj X) κ := by
refine ⟨fun J _ _ ↦ ⟨fun {Y} ↦ ?_⟩⟩
have := preservesColimitsOfShape_of_isCardinalPresentable X κ J
suffices PreservesColimit Y (coyoneda.obj (op (e.functor.obj X)) ⋙ uliftFunctor.{v₁}) from
⟨fun {c} hc ↦ ⟨isColimitOfReflects uliftFunctor.{v₁}
(isColimitOfPreserves (coyoneda.obj (op (e.functor.obj X)) ⋙ uliftFunctor.{v₁}) hc)⟩⟩
have iso : coyoneda.obj (op (e.functor.obj X)) ⋙ uliftFunctor.{v₁} ≅
e.inverse ⋙ coyoneda.obj (op X) ⋙ uliftFunctor.{v₃} :=
NatIso.ofComponents (fun Z ↦
(Equiv.ulift.trans ((e.toAdjunction.homEquiv X Z).trans Equiv.ulift.symm)).toIso) (by
intro _ _ f
ext ⟨g⟩
apply Equiv.ulift.injective
simp [Adjunction.homEquiv_unit])
exact preservesColimit_of_natIso Y iso.symm
instance isCardinalPresentable_of_isEquivalence
{C' : Type u₃} [Category.{v₃} C'] [IsCardinalPresentable X κ] (F : C ⥤ C')
[F.IsEquivalence] :
IsCardinalPresentable (F.obj X) κ :=
isCardinalPresentable_of_equivalence X κ F.asEquivalence
@[simp]
lemma isCardinalPresentable_iff_of_isEquivalence
{C' : Type u₃} [Category.{v₃} C'] (F : C ⥤ C')
[F.IsEquivalence] :
IsCardinalPresentable (F.obj X) κ ↔ IsCardinalPresentable X κ := by
constructor
· intro
exact isCardinalPresentable_of_iso
(show F.inv.obj (F.obj X) ≅ X from F.asEquivalence.unitIso.symm.app X :) κ
· intro
infer_instance
end
section
variable (X : C)
/-- An object of a category is presentable relative to a universe `w`
if it is `κ`-presentable for some regular `κ : Cardinal.{w}`. -/
@[pp_with_univ]
abbrev IsPresentable (X : C) : Prop :=
Functor.IsAccessible.{w} (coyoneda.obj (op X))
lemma isPresentable_of_isCardinalPresentable (κ : Cardinal.{w}) [Fact κ.IsRegular]
[IsCardinalPresentable X κ] : IsPresentable.{w} X where
exists_cardinal := ⟨κ, inferInstance, inferInstance⟩
end
section
variable (C) (κ : Cardinal.{w}) [Fact κ.IsRegular]
/-- A category has `κ`-filtered colimits if it has colimits of shape `J`
for any `κ`-filtered category `J`. -/
class HasCardinalFilteredColimits : Prop where
hasColimitsOfShape (J : Type w) [SmallCategory J] [IsCardinalFiltered J κ] :
HasColimitsOfShape J C := by intros; infer_instance
instance [HasColimitsOfSize.{w, w} C] : HasCardinalFilteredColimits.{w} C κ where
end
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/CardinalFilteredPresentation.lean | import Mathlib.CategoryTheory.Presentable.Limits
import Mathlib.CategoryTheory.Generator.StrongGenerator
/-!
# Presentable generators
Let `C` be a category, `G : ι → C` a family of objects and `κ` a regular cardinal
(with `ι` and `κ` both in the same universe `w`). In this file, we
introduce a property `h : AreCardinalFilteredGenerators G κ`:
this property says that the objects `G i` are all `κ`-presentable and that
any object in `C` identifies as a `κ`-filtered colimit of these objects.
We show in the lemma `AreCardinalFilteredGenerators.presentable` that it
follows that any object `X` is presentable (relatively to a possibly
larger regular cardinal `κ'`). The lemma `AreCardinalFilteredGenerators.isStrongGenerator`
shows that the objects `G i` form a strong generator of the category `C`.
Finally, we define a typeclass `HasCardinalFilteredGenerators C κ` saying
that `C` is locally `w`-small and that there exists a family `G : ι → C`
indexed by `ι : Type w` such that `AreCardinalFilteredGenerators G κ` holds.
This is used in the definition of locally presentable and accessible
categories in the file `CategoryTheory.Presentable.LocallyPresentable`.
## References
* [Adámek, J. and Rosický, J., *Locally presentable and accessible categories*][Adamek_Rosicky_1994]
-/
universe w v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
namespace Limits.ColimitPresentation
lemma isCardinalPresentable {X : C} {J : Type w} [SmallCategory J]
(p : ColimitPresentation J X) (κ : Cardinal.{w}) [Fact κ.IsRegular]
(h : ∀ (j : J), IsCardinalPresentable (p.diag.obj j) κ) [LocallySmall.{w} C]
(κ' : Cardinal.{w}) [Fact κ'.IsRegular] (h : κ ≤ κ')
(hJ : HasCardinalLT (Arrow J) κ') :
IsCardinalPresentable X κ' :=
have (k : J) : IsCardinalPresentable (p.diag.obj k) κ' := isCardinalPresentable_of_le _ h
isCardinalPresentable_of_isColimit _ p.isColimit κ' hJ
end Limits.ColimitPresentation
open Limits
section
variable {ι : Type w} (G : ι → C) (κ : Cardinal.{w}) [Fact κ.IsRegular]
/-- Given a regular cardinal `κ`, this is the property that a family
of objects `G : ι → C` consists of `κ`-presentable objects and that any
object in `C` identifies to a `κ`-filtered colimit of these objects. -/
structure AreCardinalFilteredGenerators : Prop where
isCardinalPresentable (i : ι) : IsCardinalPresentable (G i) κ
exists_colimitPresentation (X : C) :
∃ (J : Type w) (_ : SmallCategory J) (_ : IsCardinalFiltered J κ)
(p : ColimitPresentation J X),
∀ (j : J), ∃ (i : ι), Nonempty (p.diag.obj j ≅ G i)
namespace AreCardinalFilteredGenerators
variable {G κ} (h : AreCardinalFilteredGenerators G κ) (X : C)
/-- When `G : ι → C` is a family of objects such that `AreCardinalFilteredGenerators G κ`
holds, and `X : C`, this is the index category of a presentation of `X`
as a `κ`-filtered colimit of objects in the family `G`. -/
def J : Type w := (h.exists_colimitPresentation X).choose
noncomputable instance : SmallCategory (h.J X) :=
(h.exists_colimitPresentation X).choose_spec.choose
noncomputable instance : IsCardinalFiltered (h.J X) κ :=
(h.exists_colimitPresentation X).choose_spec.choose_spec.choose
/-- A choice of a presentation of an object `X` in a category `C`
as a `κ`-filtered colimit of objects in the family `G : ι → C`
when `h : AreCardinalFilteredGenerators G κ`. -/
noncomputable def colimitPresentation : ColimitPresentation (h.J X) X :=
(h.exists_colimitPresentation X).choose_spec.choose_spec.choose_spec.choose
lemma exists_colimitPresentation_diag_obj_iso (j : h.J X) :
∃ (i : ι), Nonempty ((h.colimitPresentation X).diag.obj j ≅ G i) :=
(h.exists_colimitPresentation X).choose_spec.choose_spec.choose_spec.choose_spec j
instance (j : h.J X) :
IsCardinalPresentable.{w} ((h.colimitPresentation X).diag.obj j) κ := by
obtain ⟨i, ⟨e⟩⟩ := h.exists_colimitPresentation_diag_obj_iso X j
have := h.isCardinalPresentable
exact isCardinalPresentable_of_iso e.symm κ
include h in
lemma isPresentable (i : ι) : IsPresentable.{w} (G i) :=
have := h.isCardinalPresentable
isPresentable_of_isCardinalPresentable _ κ
instance (j : h.J X) : IsPresentable.{w} ((h.colimitPresentation X).diag.obj j) :=
isPresentable_of_isCardinalPresentable _ κ
include h in
lemma presentable [LocallySmall.{w} C] (X : C) : IsPresentable.{w} X := by
obtain ⟨κ', _, le, hκ'⟩ : ∃ (κ' : Cardinal.{w}) (_ : Fact κ'.IsRegular) (_ : κ ≤ κ'),
HasCardinalLT (Arrow (h.J X)) κ' := by
obtain ⟨κ', h₁, h₂⟩ := HasCardinalLT.exists_regular_cardinal_forall.{w}
(Sum.elim (fun (_ : Unit) ↦ Arrow (h.J X)) (fun (_ : Unit) ↦ κ.ord.toType))
exact ⟨κ', ⟨h₁⟩,
le_of_lt (by simpa [hasCardinalLT_iff_cardinal_mk_lt] using h₂ (Sum.inr ⟨⟩)),
h₂ (Sum.inl ⟨⟩)⟩
have := (h.colimitPresentation X).isCardinalPresentable κ (by infer_instance) κ' le hκ'
exact isPresentable_of_isCardinalPresentable _ κ'
-- TODO: Move `AreCardinalFilteredGenerators` to the `ObjectProperty` namespace
include h in
lemma isStrongGenerator :
ObjectProperty.IsStrongGenerator (.ofObj G) :=
.mk_of_exists_colimitsOfShape (fun X ↦ ⟨h.J X, inferInstance, by
rw [← ObjectProperty.colimitsOfShape_isoClosure]
refine ⟨h.colimitPresentation X, fun j ↦ ?_⟩
obtain ⟨i, e⟩ := h.exists_colimitPresentation_diag_obj_iso X j
exact ⟨_, .mk i, e⟩⟩)
end AreCardinalFilteredGenerators
end
/-- The property that a category `C` and a regular cardinal `κ`
satisfy `AreCardinalFilteredGenerators G κ` for a suitable family
of objects `G : ι → C`. -/
class HasCardinalFilteredGenerators (C : Type u) [hC : Category.{v} C]
(κ : Cardinal.{w}) [hκ : Fact κ.IsRegular] : Prop extends LocallySmall.{w} C where
exists_generators (C κ) [hC] [hκ] : ∃ (ι : Type w) (G : ι → C),
AreCardinalFilteredGenerators G κ
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/IsCardinalFiltered.lean | import Mathlib.CategoryTheory.Filtered.Basic
import Mathlib.CategoryTheory.Limits.Shapes.WideEqualizers
import Mathlib.CategoryTheory.Comma.CardinalArrow
import Mathlib.SetTheory.Cardinal.Cofinality
import Mathlib.SetTheory.Cardinal.HasCardinalLT
import Mathlib.SetTheory.Cardinal.Arithmetic
/-! # κ-filtered category
If `κ` is a regular cardinal, we introduce the notion of `κ`-filtered
category `J`: it means that any functor `A ⥤ J` from a small category such
that `Arrow A` is of cardinality `< κ` admits a cocone.
This generalizes the notion of filtered category.
Indeed, we obtain the equivalence `IsCardinalFiltered J ℵ₀ ↔ IsFiltered J`.
The API is mostly parallel to that of filtered categories.
A preordered type `J` is a `κ`-filtered category (i.e. `κ`-directed set)
if any subset of `J` of cardinality `< κ` has an upper bound.
## References
* [Adámek, J. and Rosický, J., *Locally presentable and accessible categories*][Adamek_Rosicky_1994]
-/
universe w v' v u' u
namespace CategoryTheory
open Limits Opposite
/-- A category `J` is `κ`-filtered (for a regular cardinal `κ`) if
any functor `F : A ⥤ J` from a category `A` such that `HasCardinalLT (Arrow A) κ`
admits a cocone. See `isCardinalFiltered_iff` for a more
concrete characterization of `κ`-filtered categories. -/
class IsCardinalFiltered (J : Type u) [Category.{v} J]
(κ : Cardinal.{w}) [Fact κ.IsRegular] : Prop where
nonempty_cocone {A : Type w} [SmallCategory A] (F : A ⥤ J)
(hA : HasCardinalLT (Arrow A) κ) : Nonempty (Cocone F)
lemma hasCardinalLT_arrow_walkingParallelFamily {T : Type u}
{κ : Cardinal.{w}} (hT : HasCardinalLT T κ) (hκ : Cardinal.aleph0 ≤ κ) :
HasCardinalLT (Arrow (WalkingParallelFamily T)) κ := by
simpa only [hasCardinalLT_iff_of_equiv (WalkingParallelFamily.arrowEquiv T),
hasCardinalLT_option_iff _ _ hκ] using hT
namespace IsCardinalFiltered
variable {J : Type u} [Category.{v} J] {κ : Cardinal.{w}} [hκ : Fact κ.IsRegular]
[IsCardinalFiltered J κ]
/-- A choice of cocone for a functor `F : A ⥤ J` such that `HasCardinalLT (Arrow A) κ`
when `J` is a `κ`-filtered category, and `Arrow A` has cardinality `< κ`. -/
noncomputable def cocone {A : Type v'} [Category.{u'} A]
(F : A ⥤ J) (hA : HasCardinalLT (Arrow A) κ) :
Cocone F := by
have := hA.small
have := small_of_small_arrow.{w} A
have := locallySmall_of_small_arrow.{w} A
let e := (Shrink.equivalence.{w} A).trans (ShrinkHoms.equivalence.{w} (Shrink.{w} A))
exact (Cocones.equivalenceOfReindexing e.symm (Iso.refl _)).inverse.obj
(nonempty_cocone (κ := κ) (e.inverse ⋙ F) (by simpa)).some
variable (J) in
lemma of_le {κ' : Cardinal.{w}} [Fact κ'.IsRegular] (h : κ' ≤ κ) :
IsCardinalFiltered J κ' where
nonempty_cocone F hA := ⟨cocone F (hA.of_le h)⟩
variable (κ) in
lemma of_equivalence {J' : Type u'} [Category.{v'} J'] (e : J ≌ J') :
IsCardinalFiltered J' κ where
nonempty_cocone F hA := ⟨e.inverse.mapCoconeInv (cocone (F ⋙ e.inverse) hA)⟩
section max
variable {K : Type u'} (S : K → J) (hS : HasCardinalLT K κ)
/-- If `S : K → J` is a family of objects of cardinality `< κ` in a `κ`-filtered category,
this is a choice of objects in `J` which is the target of a map from any of
the objects `S k`. -/
noncomputable def max : J :=
(cocone (Discrete.functor S) (by simpa using hS)).pt
/-- If `S : K → J` is a family of objects of cardinality `< κ` in a `κ`-filtered category,
this is a choice of map `S k ⟶ max S hS` for any `k : K`. -/
noncomputable def toMax (k : K) :
S k ⟶ max S hS :=
(cocone (Discrete.functor S) (by simpa using hS)).ι.app ⟨k⟩
end max
section coeq
variable {K : Type v'} {j j' : J} (f : K → (j ⟶ j')) (hK : HasCardinalLT K κ)
/-- Given a family of maps `f : K → (j ⟶ j')` in a `κ`-filtered category `J`,
with `HasCardinalLT K κ`, this is an object of `J` where these morphisms
shall be equalized. -/
noncomputable def coeq : J :=
(cocone (parallelFamily f)
(hasCardinalLT_arrow_walkingParallelFamily hK hκ.out.aleph0_le)).pt
/-- Given a family of maps `f : K → (j ⟶ j')` in a `κ`-filtered category `J`,
with `HasCardinalLT K κ`, and `k : K`, this is a choice of morphism `j' ⟶ coeq f hK`. -/
noncomputable def coeqHom : j' ⟶ coeq f hK :=
(cocone (parallelFamily f)
(hasCardinalLT_arrow_walkingParallelFamily hK hκ.out.aleph0_le)).ι.app .one
/-- Given a family of maps `f : K → (j ⟶ j')` in a `κ`-filtered category `J`,
with `HasCardinalLT K κ`, this is a morphism `j ⟶ coeq f hK` which is equal
to all compositions `f k ≫ coeqHom f hK` for `k : K`. -/
noncomputable def toCoeq : j ⟶ coeq f hK :=
(cocone (parallelFamily f)
(hasCardinalLT_arrow_walkingParallelFamily hK hκ.out.aleph0_le)).ι.app .zero
@[reassoc]
lemma coeq_condition (k : K) : f k ≫ coeqHom f hK = toCoeq f hK :=
(cocone (parallelFamily f)
(hasCardinalLT_arrow_walkingParallelFamily hK hκ.out.aleph0_le)).w
(.line k)
end coeq
/-- Variant of `IsFiltered.span` for `κ`-filtered categories. -/
lemma wideSpan {ι : Type v'} {j : J} {k : ι → J}
(f : ∀ i, j ⟶ k i) (hι : HasCardinalLT ι κ) :
∃ (m : J) (a : ∀ i, k i ⟶ m) (b : j ⟶ m), ∀ i, f i ≫ a i = b := by
let φ (i : ι) := f i ≫ toMax k hι i
exact ⟨coeq φ hι, fun i ↦ toMax k hι i ≫ coeqHom φ hι,
toCoeq φ hι, by simpa [φ] using coeq_condition φ hι⟩
end IsCardinalFiltered
open IsCardinalFiltered in
lemma isFiltered_of_isCardinalFiltered (J : Type u) [Category.{v} J]
(κ : Cardinal.{w}) [hκ : Fact κ.IsRegular] [IsCardinalFiltered J κ] :
IsFiltered J := by
rw [IsFiltered.iff_cocone_nonempty.{w}]
intro A _ _ F
have hA : HasCardinalLT (Arrow A) κ := by
refine HasCardinalLT.of_le ?_ hκ.out.aleph0_le
simp only [hasCardinalLT_aleph0_iff]
infer_instance
exact ⟨cocone F hA⟩
@[deprecated (since := "2025-10-07")] alias isFiltered_of_isCardinalDirected :=
isFiltered_of_isCardinalFiltered
attribute [local instance] Cardinal.fact_isRegular_aleph0
lemma isCardinalFiltered_aleph0_iff (J : Type u) [Category.{v} J] :
IsCardinalFiltered J Cardinal.aleph0.{w} ↔ IsFiltered J := by
constructor
· intro
exact isFiltered_of_isCardinalFiltered J Cardinal.aleph0
· intro
constructor
intro A _ F hA
rw [hasCardinalLT_aleph0_iff] at hA
have := ((Arrow.finite_iff A).1 hA).some
exact ⟨IsFiltered.cocone F⟩
lemma isCardinalFiltered_preorder (J : Type w) [Preorder J]
(κ : Cardinal.{w}) [Fact κ.IsRegular]
(h : ∀ ⦃K : Type w⦄ (s : K → J) (_ : Cardinal.mk K < κ),
∃ (j : J), ∀ (k : K), s k ≤ j) :
IsCardinalFiltered J κ where
nonempty_cocone {A _ F hA} := by
obtain ⟨j, hj⟩ := h F.obj (by simpa only [hasCardinalLT_iff_cardinal_mk_lt] using
hasCardinalLT_of_hasCardinalLT_arrow hA)
exact ⟨Cocone.mk j
{ app a := homOfLE (hj a)
naturality _ _ _ := rfl }⟩
instance (κ : Cardinal.{w}) [hκ : Fact κ.IsRegular] :
IsCardinalFiltered κ.ord.toType κ :=
isCardinalFiltered_preorder _ _ (fun ι f hs ↦ by
have h : Function.Surjective (fun i ↦ (⟨f i, i, rfl⟩ : Set.range f)) := fun _ ↦ by aesop
obtain ⟨j, hj⟩ := Ordinal.lt_cof_type
(α := κ.ord.toType) (r := (· < ·)) (S := Set.range f)
(lt_of_le_of_lt (Cardinal.mk_le_of_surjective h)
(lt_of_lt_of_le hs (by simp [hκ.out.cof_eq])))
exact ⟨j, fun i ↦ (hj (f i) (by simp)).le⟩)
open IsCardinalFiltered
instance isCardinalFiltered_under
(J : Type u) [Category.{v} J] (κ : Cardinal.{w}) [Fact κ.IsRegular]
[IsCardinalFiltered J κ] (j₀ : J) : IsCardinalFiltered (Under j₀) κ where
nonempty_cocone {A _} F hA := ⟨by
have := isFiltered_of_isCardinalFiltered J κ
let c := cocone (F ⋙ Under.forget j₀) hA
let x (a : A) : j₀ ⟶ IsFiltered.max j₀ c.pt := (F.obj a).hom ≫ c.ι.app a ≫
IsFiltered.rightToMax j₀ c.pt
have hκ' : HasCardinalLT A κ := hasCardinalLT_of_hasCardinalLT_arrow hA
exact
{ pt := Under.mk (toCoeq x hκ')
ι :=
{ app a := Under.homMk (c.ι.app a ≫ IsFiltered.rightToMax j₀ c.pt ≫ coeqHom x hκ')
(by simpa [x] using coeq_condition x hκ' a)
naturality a b f := by
ext
have := c.w f
dsimp at this ⊢
simp only [reassoc_of% this, Category.comp_id] } }⟩
instance isCardinalFiltered_prod (J₁ : Type u) (J₂ : Type u')
[Category.{v} J₁] [Category.{v'} J₂] (κ : Cardinal.{w}) [Fact κ.IsRegular]
[IsCardinalFiltered J₁ κ] [IsCardinalFiltered J₂ κ] :
IsCardinalFiltered (J₁ × J₂) κ where
nonempty_cocone F hC := ⟨by
let c₁ := cocone (F ⋙ Prod.fst _ _) hC
let c₂ := cocone (F ⋙ Prod.snd _ _) hC
exact
{ pt := (c₁.pt, c₂.pt)
ι.app i := (c₁.ι.app i, c₂.ι.app i)
ι.naturality {i j} f := by
ext
· simpa using c₁.w f
· simpa using c₂.w f }⟩
instance isCardinalFiltered_pi {ι : Type u'} (J : ι → Type u) [∀ i, Category.{v} (J i)]
(κ : Cardinal.{w}) [Fact κ.IsRegular] [∀ i, IsCardinalFiltered (J i) κ] :
IsCardinalFiltered (∀ i, J i) κ where
nonempty_cocone F hC := ⟨by
let c (i : ι) := cocone (F ⋙ Pi.eval J i) hC
exact
{ pt i := (c i).pt
ι.app X i := (c i).ι.app X
ι.naturality {X Y} f := by
ext i
simpa using (c i).ι.naturality f }⟩
section
variable {J : Type u} [Category.{v} J] {κ : Cardinal.{w}} [Fact κ.IsRegular]
(h₁ : (∀ ⦃ι : Type w⦄ (j : ι → J) (_ : HasCardinalLT ι κ),
∃ (k : J), ∀ (i : ι), Nonempty (j i ⟶ k)))
(h₂ : ∀ ⦃ι : Type w⦄ ⦃j k : J⦄ (f : ι → (j ⟶ k)) (_ : HasCardinalLT ι κ),
∃ (l : J) (a : k ⟶ l) (b : j ⟶ l), ∀ (i : ι), f i ≫ a = b)
include h₁ h₂ in
omit [Fact κ.IsRegular] in
lemma isCardinalFiltered_iff_aux₁ {ι : Type w} {j : J} {k : ι → J}
(f : ∀ i, j ⟶ k i) (hι : HasCardinalLT ι κ) :
∃ (m : J) (a : ∀ i, k i ⟶ m) (b : j ⟶ m), ∀ i, f i ≫ a i = b := by
obtain ⟨l, hl⟩ := h₁ k hι
let a (i : ι) := (hl i).some
obtain ⟨m, b, c, hm⟩ := h₂ (fun i ↦ f i ≫ a i) hι
exact ⟨m, fun i ↦ a i ≫ b, c, by grind⟩
include h₁ h₂ in
lemma isCardinalFiltered_iff_aux₂ {ι : Type w} {j : ι → J} {k : J}
(f₁ f₂ : ∀ i, j i ⟶ k) (hι : HasCardinalLT ι κ) :
∃ (l : J) (a : k ⟶ l), ∀ i, f₁ i ≫ a = f₂ i ≫ a := by
have (i : ι) : ∃ (l : J) (p : k ⟶ l), f₁ i ≫ p = f₂ i ≫ p := by
obtain ⟨l, a, b, hl⟩ := h₂ (Sum.elim (fun (_ : PUnit.{w + 1}) ↦ f₁ i)
(fun (_ : PUnit.{w + 1}) ↦ f₂ i))
(hasCardinalLT_of_finite _ _ (Cardinal.IsRegular.aleph0_le Fact.out))
exact ⟨l, a, (hl (Sum.inl .unit)).trans (hl (Sum.inr .unit)).symm⟩
choose l p hp using this
obtain ⟨l, a, b, h⟩ := isCardinalFiltered_iff_aux₁ h₁ h₂ p hι
exact ⟨l, b, fun i ↦ by grind⟩
variable (J κ) in
/-- A category is `κ`-filtered iff
1) any family of objects of cardinality `< κ` admits a map towards a common object, and
2) any family of morphisms `j ⟶ k` of cardinality `< κ` (between *fixed* objects
`j` and `k`) can be coequalized by a suitable morphism `k ⟶ l`. -/
lemma isCardinalFiltered_iff :
IsCardinalFiltered J κ ↔
(∀ ⦃ι : Type w⦄ (j : ι → J) (_ : HasCardinalLT ι κ),
∃ (k : J), ∀ (i : ι), Nonempty (j i ⟶ k)) ∧
∀ ⦃ι : Type w⦄ ⦃j k : J⦄ (f : ι → (j ⟶ k)) (_ : HasCardinalLT ι κ),
∃ (l : J) (a : k ⟶ l) (b : j ⟶ l), ∀ (i : ι), f i ≫ a = b := by
refine ⟨fun _ ↦ ⟨fun ι j hι ↦ ⟨_, fun i ↦ ⟨toMax j hι i⟩⟩,
fun ι j k f hι ↦ ⟨_, _, _, coeq_condition f hι⟩⟩,
fun ⟨h₁, h₂⟩ ↦ ⟨fun {A _} F hA ↦ ?_⟩⟩
obtain ⟨j, hj⟩ := h₁ F.obj (hasCardinalLT_of_hasCardinalLT_arrow hA)
let a (i : A) : F.obj i ⟶ j := (hj i).some
obtain ⟨l, b, hb⟩ := isCardinalFiltered_iff_aux₂ h₁ h₂
(fun (f : Arrow A) ↦ F.map f.hom ≫ a f.right)
(fun (f : Arrow A) ↦ a f.left) hA
exact ⟨{
pt := l
ι.app i := a i ≫ b
ι.naturality _ _ f := by simpa using hb (Arrow.mk f) }⟩
end
lemma IsCardinalFiltered.multicoequalizer
{J : Type u} [Category.{v} J] {κ : Cardinal.{w}} [Fact κ.IsRegular]
[IsCardinalFiltered J κ] {ι : Type v'} {j : ι → J} {k : J}
(f₁ f₂ : ∀ i, j i ⟶ k) (hι : HasCardinalLT ι κ) :
∃ (l : J) (a : k ⟶ l), ∀ i, f₁ i ≫ a = f₂ i ≫ a := by
have := isFiltered_of_isCardinalFiltered J κ
obtain ⟨l, a, b, h⟩ := IsCardinalFiltered.wideSpan
(fun i ↦ IsFiltered.coeqHom (f₁ i) (f₂ i)) hι
exact ⟨l, b, fun i ↦ by rw [← h i, IsFiltered.coeq_condition_assoc]⟩
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/OrthogonalReflection.lean | import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer
import Mathlib.CategoryTheory.Localization.Bousfield
import Mathlib.CategoryTheory.SmallObject.Iteration.Basic
/-!
# The Orthogonal-reflection construction
Given `W : MorphismProperty C` (which should be small) and assuming the existence
of certain colimits in `C`, we construct a morphism `toSucc W Z : Z ⟶ succ W Z` for
any `Z : C`. This morphism belongs to `LeftBousfield.W W.isLocal` and
is an isomorphism iff `Z` belongs to `W.isLocal` (see the lemma `isIso_toSucc_iff`).
The morphism `toSucc W Z : Z ⟶ succ W Z` is defined as a composition
of two morphisms that are roughly described as follows:
* `toStep W Z : Z ⟶ step W Z`: for any morphism `f : X ⟶ Y` satisfying `W`
and any morphism `X ⟶ Z`, we "attach" a morphism `Y ⟶ step W Z` (using
coproducts and a pushout in essentially the same way as it is done in
the file `CategoryTheory.SmallObject.Construction` for the small object
argument);
* `fromStep W Z : step W Z ⟶ succ W Z`: this morphism coequalizes all pairs
of morphisms `g₁ g₂ : Y ⟶ step W Z` such that there is a `f : X ⟶ Y`
satisfying `W` such that `f ≫ g₁ = f ≫ g₂`.
The morphism `toSucc W Z : Z ⟶ succ W Z` is a variant of the (wrong) definition
p. 32 in the book by Adámek and Rosický. In this book, a slightly different object
as `succ W Z` is defined directly as a colimit of an intricate diagram, but
contrary to what is stated on p. 33, it does not satisfy `isIso_toSucc_iff`.
The author of this file was unable to not understand the attempt of the authors
to fix this mistake in the errata to this book. This led to the definition
in two steps outlined above.
These morphisms `toSucc W Z : Z ⟶ succ W Z` for all `Z : C` allow to
define `succStruct W Z₀ : SuccStruct C` for any `Z₀ : C`. We will apply
a transfinite induction to this construction in order to obtain a left adjoint
to the inclusion of the full subcategory of `W`-local objects under
suitable assumptions (TODO).
## References
* [Adámek, J. and Rosický, J., *Locally presentable and accessible categories*][Adamek_Rosicky_1994]
-/
universe w v u
namespace CategoryTheory
open Limits Localization
variable {C : Type u} [Category.{v} C] (W : MorphismProperty C)
namespace OrthogonalReflection
variable (Z : C)
/-- Given `W : MorphismProperty C` and `Z : C`, this is the index type
parametrising the data of a morphism `f : X ⟶ Y` satisfying `W`
and a morphism `X ⟶ Z`. -/
def D₁ : Type _ := Σ (f : W.toSet), f.1.left ⟶ Z
variable {W Z} in
/-- If `d : D₁ W Z` corresponds to the data of `f : X ⟶ Y` satisfying `W` and
of a morphism `X ⟶ Z`, this is the object `X`. -/
def D₁.obj₁ (d : D₁ W Z) : C := d.1.1.left
variable {W Z} in
/-- If `d : D₁ W Z` corresponds to the data of `f : X ⟶ Y` satisfying `W` and
of a morphism `X ⟶ Z`, this is the object `Y`. -/
def D₁.obj₂ (d : D₁ W Z) : C := d.1.1.right
variable [HasCoproduct (D₁.obj₁ (W := W) (Z := Z))]
/-- Considering all diagrams consisting of a morphism `f : X ⟶ Y` satisfying `W`
and of a morphism `d : X ⟶ Z`, this is the morphism from the coproduct of
all these `X` objects to `Z` given by these morphisms `d`. -/
noncomputable abbrev D₁.l : ∐ (obj₁ (W := W) (Z := Z)) ⟶ Z :=
Sigma.desc (fun d ↦ d.2)
variable {W Z} in
/-- The inclusion of a summand in `∐ obj₁`. -/
noncomputable abbrev D₁.ιLeft {X Y : C} (f : X ⟶ Y) (hf : W f) (g : X ⟶ Z) :
X ⟶ ∐ obj₁ (W := W) (Z := Z) :=
Sigma.ι (obj₁ (W := W) (Z := Z)) ⟨⟨Arrow.mk f, hf⟩, g⟩
variable {W Z} in
@[reassoc]
lemma D₁.ιLeft_comp_l {X Y : C} (f : X ⟶ Y) (hf : W f) (g : X ⟶ Z) :
D₁.ιLeft f hf g ≫ D₁.l W Z = g :=
Sigma.ι_desc _ _
section
variable [HasCoproduct (D₁.obj₂ (W := W) (Z := Z))]
/-- The coproduct of all the morphisms `f` indexed by all diagrams
consisting of a morphism `f : X ⟶ Y` satisfying `W` and of a morphism `d : X ⟶ Z`. -/
noncomputable abbrev D₁.t : ∐ (obj₁ (W := W) (Z := Z)) ⟶ ∐ (obj₂ (W := W) (Z := Z)) :=
Limits.Sigma.map (fun d ↦ d.1.1.hom)
variable {W Z} in
/-- The inclusion of a summand in `∐ obj₂`. -/
noncomputable abbrev D₁.ιRight {X Y : C} (f : X ⟶ Y) (hf : W f) (g : X ⟶ Z) :
Y ⟶ ∐ (obj₂ (W := W) (Z := Z)) :=
Sigma.ι (obj₂ (W := W) (Z := Z)) ⟨⟨Arrow.mk f, hf⟩, g⟩
variable {W Z} in
@[reassoc]
lemma D₁.ι_comp_t (d : D₁ W Z) :
Sigma.ι _ d ≫ D₁.t W Z = d.1.1.hom ≫ Sigma.ι obj₂ d := by
apply ι_colimMap
variable {W Z} in
@[reassoc]
lemma D₁.ιLeft_comp_t {X Y : C} (f : X ⟶ Y) (hf : W f) (g : X ⟶ Z) :
D₁.ιLeft f hf g ≫ D₁.t W Z = f ≫ D₁.ιRight f hf g := by
apply ι_colimMap
variable [HasPushouts C]
/-- The intermediate object in the definition of the morphism `toSucc W Z : Z ⟶ succ W Z`.
It is the pushout of the following square:
```lean
∐ D₁.obj₁ ⟶ ∐ D₁.obj₂
| |
v v
Z ⟶ step W Z
```
where the coproduct is taken over all the diagram consisting of a morphism `f : X ⟶ Y`
satisfying `W` and a morphism `X ⟶ Z`. The top map is the coproduct of all of these `f`.
-/
noncomputable abbrev step := pushout (D₁.t W Z) (D₁.l W Z)
/-- The canonical map from `Z` to the pushout of `D₁.t W Z` and `D₁.l W Z`. -/
noncomputable abbrev toStep : Z ⟶ step W Z := pushout.inr _ _
/-- The index type parametrising the data of two morphisms `g₁ g₂ : Y ⟶ step W Z`, and
a map `f : X ⟶ Y` satisfying `W` such that `f ≫ g₁ = f ≫ g₂`. -/
def D₂ : Type _ :=
Σ (f : W.toSet),
{ pq : (f.1.right ⟶ step W Z) × (f.1.right ⟶ step W Z) // f.1.hom ≫ pq.1 = f.1.hom ≫ pq.2 }
/-- The shape of the multicoequalizer of all pairs of morphisms `g₁ g₂ : Y ⟶ step W Z` with
a `f : X ⟶ Y` satisfying `W` such that `f ≫ g₁ = f ≫ g₂`. -/
@[simps]
def D₂.multispanShape : MultispanShape where
L := D₂ W Z
R := Unit
fst _ := .unit
snd _ := .unit
/-- The diagram of the multicoequalizer of all pair of morphisms `g₁ g₂ : Y ⟶ step W Z` with
a `f : X ⟶ Y` satisfying `W` such that `f ≫ g₁ = f ≫ g₂`. -/
@[simps]
noncomputable def D₂.multispanIndex : MultispanIndex (multispanShape W Z) C where
left d := d.1.1.right
right _ := step W Z
fst d := d.2.1.1
snd d := d.2.1.2
variable [HasMulticoequalizer (D₂.multispanIndex W Z)]
/-- The object `succ W Z` is the multicoequalizer of all pairs of morphisms
`g₁ g₂ : Y ⟶ step W Z` with a `f : X ⟶ Y` satisfying `W` such that `f ≫ g₁ = f ≫ g₂`. -/
noncomputable abbrev succ := multicoequalizer (D₂.multispanIndex W Z)
/-- The projection from `Z` to the multicoequalizer of all morphisms `g₁ g₂ : Y ⟶ step W Z` with
a `f : X ⟶ Y` satisfying `W` such that `f ≫ g₁ = f ≫ g₂`. -/
noncomputable abbrev fromStep : step W Z ⟶ succ W Z :=
Multicoequalizer.π (D₂.multispanIndex W Z) .unit
variable {W Z} in
@[reassoc]
lemma D₂.condition {X Y : C} (f : X ⟶ Y) (hf : W f)
{g₁ g₂ : Y ⟶ step W Z} (h : f ≫ g₁ = f ≫ g₂) :
g₁ ≫ fromStep W Z = g₂ ≫ fromStep W Z :=
Multicoequalizer.condition (D₂.multispanIndex W Z)
⟨⟨Arrow.mk f, hf⟩, ⟨g₁, g₂⟩, h⟩
/-- The morphism `Z ⟶ succ W Z`. -/
noncomputable abbrev toSucc : Z ⟶ succ W Z := toStep W Z ≫ fromStep W Z
variable {W Z} in
lemma toSucc_injectivity {X Y : C} (f : X ⟶ Y) (hf : W f)
(g₁ g₂ : Y ⟶ Z) (hg : f ≫ g₁ = f ≫ g₂) :
g₁ ≫ toSucc W Z = g₂ ≫ toSucc W Z := by
simpa using D₂.condition f hf (g₁ := g₁ ≫ toStep W Z) (g₂ := g₂ ≫ toStep W Z)
(by simp [reassoc_of% hg])
variable {W Z} in
lemma toSucc_surjectivity {X Y : C} (f : X ⟶ Y) (hf : W f) (g : X ⟶ Z) :
∃ (g' : Y ⟶ succ W Z), f ≫ g' = g ≫ toSucc W Z :=
⟨D₁.ιRight f hf g ≫ pushout.inl _ _ ≫ fromStep W Z, by
simp [← D₁.ιLeft_comp_t_assoc, pushout.condition_assoc]⟩
lemma leftBousfieldW_isLocal_toSucc :
LeftBousfield.W W.isLocal (toSucc W Z) := by
refine fun T hT ↦ ⟨fun φ₁ φ₂ h ↦ ?_, fun g ↦ ?_⟩
· ext ⟨⟩
simp only [Category.assoc] at h
dsimp
ext d
· apply (hT d.1.1.hom d.1.2).1
simp only [← D₁.ι_comp_t_assoc, pushout.condition_assoc, h]
· exact h
· choose f hf using fun (d : D₁ W Z) ↦ (hT d.1.1.hom d.1.2).2 (d.2 ≫ g)
exact ⟨Multicoequalizer.desc _ _ (fun ⟨⟩ ↦ pushout.desc (Sigma.desc f) g)
(fun d ↦ (hT d.1.1.hom d.1.2).1 (by simp [reassoc_of% d.2.2])), by simp⟩
lemma isIso_toSucc_iff :
IsIso (toSucc W Z) ↔ W.isLocal Z := by
refine ⟨fun _ X Y f hf ↦ ?_, fun hZ ↦ ?_⟩
· refine ⟨fun g₁ g₂ h ↦ ?_, fun g ↦ ?_⟩
· simpa [← cancel_mono (toSucc W Z)] using
D₂.condition f hf (g₁ := g₁ ≫ toStep W Z) (g₂ := g₂ ≫ toStep W Z)
(by simp [reassoc_of% h])
· have hZ := IsIso.hom_inv_id (toSucc W Z)
simp only [Category.assoc] at hZ
exact ⟨D₁.ιRight f hf g ≫ pushout.inl _ _ ≫ fromStep W Z ≫ inv (toSucc W Z),
by simp [← D₁.ιLeft_comp_t_assoc, pushout.condition_assoc, hZ]⟩
· obtain ⟨f, hf⟩ := (leftBousfieldW_isLocal_toSucc W Z _ hZ).2 (𝟙 _)
dsimp at hf
refine ⟨f, hf, ?_⟩
ext ⟨⟩
dsimp
ext d
· simp only [Category.assoc] at hf
simp only [Category.comp_id, ← Category.assoc]
refine D₂.condition _ d.1.2 ?_
rw [Category.assoc, Category.assoc, Category.assoc,
← D₁.ι_comp_t_assoc, pushout.condition_assoc, reassoc_of% hf,
← D₁.ι_comp_t_assoc, pushout.condition]
· simp [reassoc_of% hf]
end
open SmallObject
variable [HasPushouts C]
[∀ Z, HasCoproduct (D₁.obj₁ (W := W) (Z := Z))]
[∀ Z, HasCoproduct (D₁.obj₂ (W := W) (Z := Z))]
[∀ Z, HasMulticoequalizer (D₂.multispanIndex W Z)]
/-- The successor structure of the orthogonal-reflection construction. -/
noncomputable def succStruct (Z₀ : C) : SuccStruct C where
X₀ := Z₀
succ Z := succ W Z
toSucc Z := toSucc W Z
end OrthogonalReflection
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Presentable/Limits.lean | import Mathlib.CategoryTheory.Limits.Types.Filtered
import Mathlib.CategoryTheory.Limits.Yoneda
import Mathlib.CategoryTheory.Presentable.Basic
/-!
# Colimits of presentable objects
In this file, we show that `κ`-accessible functors (to the category of types)
are stable under limits indexed by a category `K` such that
`HasCardinalLT (Arrow K) κ`.
In particular, `κ`-presentable objects are stable by colimits indexed
by a category `K` such that `HasCardinalLT (Arrow K) κ`.
-/
universe w w' v' v u' u
namespace CategoryTheory
open Opposite Limits
variable {C : Type u} [Category.{v} C]
namespace Functor
namespace Accessible
namespace Limits
section
variable {K : Type u'} [Category.{v'} K] {F : K ⥤ C ⥤ Type w'}
(c : Cone F) (hc : ∀ (Y : C), IsLimit (((evaluation _ _).obj Y).mapCone c))
(κ : Cardinal.{w}) [Fact κ.IsRegular]
(hK : HasCardinalLT (Arrow K) κ)
{J : Type w} [SmallCategory J] [IsCardinalFiltered J κ]
{X : J ⥤ C} (cX : Cocone X)
(hF : ∀ (k : K), IsColimit ((F.obj k).mapCocone cX))
namespace isColimitMapCocone
include hc hF hK
lemma surjective (x : c.pt.obj cX.pt) :
∃ (j : J) (x' : c.pt.obj (X.obj j)), x = (c.pt.mapCocone cX).ι.app j x' := by
have := isFiltered_of_isCardinalFiltered J κ
obtain ⟨y, hy⟩ := (Types.isLimitEquivSections (hc cX.pt)).symm.surjective x
obtain ⟨j₀, z, hz⟩ : ∃ (j₀ : J) (z : (k : K) → (F.obj k).obj (X.obj j₀)),
∀ (k : K), y.1 k = (F.obj k).map (cX.ι.app j₀) (z k) := by
have H (k : K) := Types.jointly_surjective_of_isColimit (hF k) (y.1 k)
let j (k : K) : J := (H k).choose
let z (k : K) : (F.obj k).obj (X.obj (j k)) := (H k).choose_spec.choose
have hz (k : K) : (F.obj k).map (cX.ι.app (j k)) (z k) = y.1 k :=
(H k).choose_spec.choose_spec
exact ⟨IsCardinalFiltered.max j (hasCardinalLT_of_hasCardinalLT_arrow hK),
fun k ↦ (F.obj k).map (X.map (IsCardinalFiltered.toMax j _ k)) (z k),
fun k ↦ by rw [← hz, ← FunctorToTypes.map_comp_apply, cX.w]⟩
obtain ⟨j₁, α, hα⟩ : ∃ (j₁ : J) (α : j₀ ⟶ j₁), ∀ ⦃k k' : K⦄ (φ : k ⟶ k'),
(F.obj k').map (X.map α) ((F.map φ).app _ (z k)) =
(F.obj k').map (X.map α) (z k') := by
have H {k k' : K} (φ : k ⟶ k') :=
(Types.FilteredColimit.isColimit_eq_iff' (ht := hF k')
(x := (F.map φ).app _ (z k)) (y := z k')).1 (by
dsimp
simpa only [← FunctorToTypes.naturality, ← hz] using y.2 φ)
let j {k k' : K} (φ : k ⟶ k') : J := (H φ).choose
let g {k k' : K} (φ : k ⟶ k') : j₀ ⟶ j φ := (H φ).choose_spec.choose
have hg {k k' : K} (φ : k ⟶ k') :
(F.obj k').map (X.map (g φ)) ((F.map φ).app _ (z k)) =
(F.obj k').map (X.map (g φ)) (z k') := (H φ).choose_spec.choose_spec
obtain ⟨j₁, α, β, hα⟩ : ∃ (j₁ : J) (α : j₀ ⟶ j₁)
(β : ∀ ⦃k k' : K⦄ (φ : k ⟶ k'), j φ ⟶ j₁),
∀ ⦃k k' : K⦄ (φ : k ⟶ k'), α = g φ ≫ β φ := by
let j'' (f : Arrow K) : J := j f.hom
let ψ (f : Arrow K) : j₀ ⟶ IsCardinalFiltered.max j'' hK :=
g f.hom ≫ IsCardinalFiltered.toMax j'' hK f
refine ⟨IsCardinalFiltered.coeq ψ hK, IsCardinalFiltered.toCoeq ψ hK,
fun k k' φ ↦ IsCardinalFiltered.toMax j'' hK φ ≫ IsCardinalFiltered.coeqHom ψ hK,
fun k k' φ ↦ ?_⟩
simpa [ψ] using (IsCardinalFiltered.coeq_condition ψ hK (Arrow.mk φ)).symm
exact ⟨j₁, α, fun k k' φ ↦ by simp [hα φ, hg]⟩
let s : (F ⋙ (evaluation C (Type w')).obj (X.obj j₁)).sections :=
{ val k := (F.obj k).map (X.map α) (z k)
property {k k'} φ := by
dsimp
rw [FunctorToTypes.naturality, ← hα φ] }
refine ⟨j₁, (Types.isLimitEquivSections (hc (X.obj j₁))).symm s, ?_⟩
apply (Types.isLimitEquivSections (hc cX.pt)).injective
rw [← hy, Equiv.apply_symm_apply]
ext k
have h₁ := Types.isLimitEquivSections_apply (hc cX.pt) k
(c.pt.map (cX.ι.app j₁) ((Types.isLimitEquivSections (hc (X.obj j₁))).symm s))
have h₂ := Types.isLimitEquivSections_symm_apply (hc (X.obj j₁)) s k
dsimp at h₁ h₂ ⊢
rw [h₁, hz, FunctorToTypes.naturality, h₂, ← FunctorToTypes.map_comp_apply, cX.w]
lemma injective (j : J) (x₁ x₂ : c.pt.obj (X.obj j))
(h : c.pt.map (cX.ι.app j) x₁ = c.pt.map (cX.ι.app j) x₂) :
∃ (j' : J) (α : j ⟶ j'),
c.pt.map (X.map α) x₁ = c.pt.map (X.map α) x₂ := by
have := isFiltered_of_isCardinalFiltered J κ
let y₁ := Types.isLimitEquivSections (hc (X.obj j)) x₁
let y₂ := Types.isLimitEquivSections (hc (X.obj j)) x₂
have hy₁ : (Types.isLimitEquivSections (hc (X.obj j))).symm y₁ = x₁ := by simp [y₁]
have hy₂ : (Types.isLimitEquivSections (hc (X.obj j))).symm y₂ = x₂ := by simp [y₂]
have H (k : K) := (Types.FilteredColimit.isColimit_eq_iff' (ht := hF k)
(x := y₁.1 k) (y := y₂.1 k)).1 (by
simp only [y₁, y₂, Types.isLimitEquivSections_apply]
dsimp
simp only [← FunctorToTypes.naturality, h])
let j₁ (k : K) : J := (H k).choose
let f (k : K) : j ⟶ j₁ k := (H k).choose_spec.choose
have hf (k : K) : (F.obj k).map (X.map (f k)) (y₁.1 k) =
(F.obj k).map (X.map (f k)) (y₂.1 k) :=
(H k).choose_spec.choose_spec
have hK' := hasCardinalLT_of_hasCardinalLT_arrow hK
let ψ (k : K) : j ⟶ IsCardinalFiltered.max j₁ hK' :=
f k ≫ IsCardinalFiltered.toMax j₁ hK' k
refine ⟨IsCardinalFiltered.coeq ψ hK', IsCardinalFiltered.toCoeq ψ hK', ?_⟩
apply (Types.isLimitEquivSections (hc _)).injective
ext k
simp only [Types.isLimitEquivSections_apply, ← hy₁, ← hy₂]
have h₁ := Types.isLimitEquivSections_symm_apply (hc (X.obj j)) y₁ k
have h₂ := Types.isLimitEquivSections_symm_apply (hc (X.obj j)) y₂ k
dsimp at h₁ h₂ ⊢
simp only [FunctorToTypes.naturality, h₁, h₂,
← IsCardinalFiltered.coeq_condition ψ hK' k,
map_comp, FunctorToTypes.map_comp_apply, ψ, hf]
end isColimitMapCocone
/-- Auxiliary definition for `isCardinalAccessible_of_isLimit`. -/
noncomputable def isColimitMapCocone : IsColimit (c.pt.mapCocone cX) := by
have := isFiltered_of_isCardinalFiltered J κ
apply Types.FilteredColimit.isColimitOf'
· exact isColimitMapCocone.surjective c hc κ hK cX hF
· exact isColimitMapCocone.injective c hc κ hK cX hF
end
end Limits
end Accessible
lemma isCardinalAccessible_of_isLimit {K : Type u'} [Category.{v'} K] {F : K ⥤ C ⥤ Type w'}
(c : Cone F) (hc : IsLimit c) (κ : Cardinal.{w}) [Fact κ.IsRegular]
[HasLimitsOfShape K (Type w')] (hK : HasCardinalLT (Arrow K) κ)
[∀ k, (F.obj k).IsCardinalAccessible κ] :
c.pt.IsCardinalAccessible κ where
preservesColimitOfShape {J _ _} := ⟨fun {X} ↦ ⟨fun {cX} hcX ↦ by
have := fun k ↦ preservesColimitsOfShape_of_isCardinalAccessible (F.obj k) κ J
exact ⟨Accessible.Limits.isColimitMapCocone c
(fun Y ↦ isLimitOfPreserves ((evaluation C (Type w')).obj Y) hc) κ hK cX
(fun k ↦ isColimitOfPreserves (F.obj k) hcX)⟩⟩⟩
end Functor
/-- In case `C` is locally `w`-small, use `isCardinalPresentable_of_isColimit`. -/
lemma isCardinalPresentable_of_isColimit'
{K : Type u'} [Category.{v'} K] {Y : K ⥤ C}
(c : Cocone Y) (hc : IsColimit c) (κ : Cardinal.{w}) [Fact κ.IsRegular]
[HasLimitsOfShape Kᵒᵖ (Type v)] (hK : HasCardinalLT (Arrow K) κ)
[∀ k, IsCardinalPresentable (Y.obj k) κ] :
IsCardinalPresentable c.pt κ := by
have (k : Kᵒᵖ) : ((Y.op ⋙ coyoneda).obj k).IsCardinalAccessible κ := by
dsimp; infer_instance
exact Functor.isCardinalAccessible_of_isLimit
(coyoneda.mapCone c.op) (isLimitOfPreserves _ hc.op) κ (by simpa)
lemma isCardinalPresentable_of_isColimit [LocallySmall.{w} C]
{K : Type u'} [Category.{v'} K] [HasLimitsOfShape Kᵒᵖ (Type w)] {Y : K ⥤ C}
(c : Cocone Y) (hc : IsColimit c) (κ : Cardinal.{w}) [Fact κ.IsRegular]
(hK : HasCardinalLT (Arrow K) κ)
[∀ k, IsCardinalPresentable (Y.obj k) κ] :
IsCardinalPresentable c.pt κ := by
let e := ShrinkHoms.equivalence.{w} C
have (k : K) : IsCardinalPresentable ((Y ⋙ e.functor).obj k) κ := by
dsimp; infer_instance
rw [← isCardinalPresentable_iff_of_isEquivalence c.pt κ e.functor]
exact isCardinalPresentable_of_isColimit' _
(isColimitOfPreserves e.functor hc) κ hK
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Types/Basic.lean | import Mathlib.CategoryTheory.EpiMono
import Mathlib.Data.Set.CoeSort
import Mathlib.Tactic.PPWithUniv
import Mathlib.Tactic.ToAdditive
/-!
# The category `Type`.
In this section we set up the theory so that Lean's types and functions between them
can be viewed as a `LargeCategory` in our framework.
Lean cannot transparently view a function as a morphism in this category, and needs a hint in
order to be able to type check. We provide the abbreviation `asHom f` to guide type checking,
as well as a corresponding notation `↾ f`. (Entered as `\upr `.)
We provide various simplification lemmas for functors and natural transformations valued in `Type`.
We define `uliftFunctor`, from `Type u` to `Type (max u v)`, and show that it is fully faithful
(but not, of course, essentially surjective).
We prove some basic facts about the category `Type`:
* epimorphisms are surjections and monomorphisms are injections,
* `Iso` is both `Iso` and `Equiv` to `Equiv` (at least within a fixed universe),
* every type level `IsLawfulFunctor` gives a categorical functor `Type ⥤ Type`
(the corresponding fact about monads is in `Mathlib/CategoryTheory/Monad/Types.lean`).
-/
namespace CategoryTheory
-- morphism levels before object levels. See note [category theory universes].
universe v v' w u u'
/- The `@[to_additive]` attribute is just a hint that expressions involving this instance can
still be additivized. -/
@[to_additive self]
instance types : LargeCategory (Type u) where
Hom a b := a → b
id _ := id
comp f g := g ∘ f
theorem types_hom {α β : Type u} : (α ⟶ β) = (α → β) :=
rfl
@[ext] theorem types_ext {α β : Type u} (f g : α ⟶ β) (h : ∀ a : α, f a = g a) : f = g := by
funext x
exact h x
theorem types_id (X : Type u) : 𝟙 X = id :=
rfl
theorem types_comp {X Y Z : Type u} (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ g = g ∘ f :=
rfl
@[simp]
theorem types_id_apply (X : Type u) (x : X) : (𝟙 X : X → X) x = x :=
rfl
@[simp]
theorem types_comp_apply {X Y Z : Type u} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) :=
rfl
@[simp]
theorem hom_inv_id_apply {X Y : Type u} (f : X ≅ Y) (x : X) : f.inv (f.hom x) = x :=
congr_fun f.hom_inv_id x
@[simp]
theorem inv_hom_id_apply {X Y : Type u} (f : X ≅ Y) (y : Y) : f.hom (f.inv y) = y :=
congr_fun f.inv_hom_id y
-- Unfortunately without this wrapper we can't use `CategoryTheory` idioms, such as `IsIso f`.
/-- `asHom f` helps Lean type check a function as a morphism in the category `Type`. -/
abbrev asHom {α β : Type u} (f : α → β) : α ⟶ β :=
f
@[inherit_doc]
scoped notation "↾" f:200 => CategoryTheory.asHom f
section
-- We verify the expected type checking behaviour of `asHom`
variable (α β γ : Type u) (f : α → β) (g : β → γ)
example : α → γ :=
↾f ≫ ↾g
example [IsIso (↾f)] : Mono (↾f) := by infer_instance
example [IsIso (↾f)] : ↾f ≫ inv (↾f) = 𝟙 α := by simp
end
namespace Functor
variable {J : Type u} [Category.{v} J]
/-- The sections of a functor `F : J ⥤ Type` are
the choices of a point `u j : F.obj j` for each `j`,
such that `F.map f (u j) = u j'` for every morphism `f : j ⟶ j'`.
We later use these to define limits in `Type` and in many concrete categories.
-/
def sections (F : J ⥤ Type w) : Set (∀ j, F.obj j) :=
{ u | ∀ {j j'} (f : j ⟶ j'), F.map f (u j) = u j' }
@[simp]
lemma sections_property {F : J ⥤ Type w} (s : (F.sections : Type _))
{j j' : J} (f : j ⟶ j') : F.map f (s.val j) = s.val j' :=
s.property f
lemma sections_ext_iff {F : J ⥤ Type w} {x y : F.sections} : x = y ↔ ∀ j, x.val j = y.val j :=
Subtype.ext_iff.trans funext_iff
variable (J)
/-- The functor which sends a functor to types to its sections. -/
@[simps]
def sectionsFunctor : (J ⥤ Type w) ⥤ Type max u w where
obj F := F.sections
map {F G} φ x := ⟨fun j => φ.app j (x.1 j), fun {j j'} f =>
(congr_fun (φ.naturality f) (x.1 j)).symm.trans (by simp [x.2 f])⟩
end Functor
namespace FunctorToTypes
variable {C : Type u} [Category.{v} C] (F G H : C ⥤ Type w) {X Y Z : C}
variable (σ : F ⟶ G) (τ : G ⟶ H)
@[simp]
theorem map_comp_apply (f : X ⟶ Y) (g : Y ⟶ Z) (a : F.obj X) :
(F.map (f ≫ g)) a = (F.map g) ((F.map f) a) := by simp
@[simp]
theorem map_id_apply (a : F.obj X) : (F.map (𝟙 X)) a = a := by simp
theorem naturality (f : X ⟶ Y) (x : F.obj X) : σ.app Y ((F.map f) x) = (G.map f) (σ.app X x) :=
congr_fun (σ.naturality f) x
@[simp]
theorem comp (x : F.obj X) : (σ ≫ τ).app X x = τ.app X (σ.app X x) :=
rfl
@[simp]
theorem eqToHom_map_comp_apply (p : X = Y) (q : Y = Z) (x : F.obj X) :
F.map (eqToHom q) (F.map (eqToHom p) x) = F.map (eqToHom <| p.trans q) x := by
cat_disch
variable {D : Type u'} [𝒟 : Category.{u'} D] (I J : D ⥤ C) (ρ : I ⟶ J) {W : D}
@[simp]
theorem hcomp (x : (I ⋙ F).obj W) : (ρ ◫ σ).app W x = (G.map (ρ.app W)) (σ.app (I.obj W) x) :=
rfl
@[simp]
theorem map_inv_map_hom_apply (f : X ≅ Y) (x : F.obj X) : F.map f.inv (F.map f.hom x) = x :=
congr_fun (F.mapIso f).hom_inv_id x
@[simp]
theorem map_hom_map_inv_apply (f : X ≅ Y) (y : F.obj Y) : F.map f.hom (F.map f.inv y) = y :=
congr_fun (F.mapIso f).inv_hom_id y
@[simp]
theorem hom_inv_id_app_apply (α : F ≅ G) (X) (x) : α.inv.app X (α.hom.app X x) = x :=
congr_fun (α.hom_inv_id_app X) x
@[simp]
theorem inv_hom_id_app_apply (α : F ≅ G) (X) (x) : α.hom.app X (α.inv.app X x) = x :=
congr_fun (α.inv_hom_id_app X) x
lemma naturality_symm {F G : C ⥤ Type*} (e : ∀ j, F.obj j ≃ G.obj j)
(naturality : ∀ {j j'} (f : j ⟶ j'), e j' ∘ F.map f = G.map f ∘ e j) {j j' : C}
(f : j ⟶ j') :
(e j').symm ∘ G.map f = F.map f ∘ (e j).symm := by
ext x
obtain ⟨y, rfl⟩ := (e j).surjective x
apply (e j').injective
dsimp
simp only [Equiv.apply_symm_apply, Equiv.symm_apply_apply]
exact (congr_fun (naturality f) y).symm
end FunctorToTypes
/-- The isomorphism between a `Type` which has been `ULift`ed to the same universe,
and the original type.
-/
def uliftTrivial (V : Type u) : ULift.{u} V ≅ V where
hom a := a.1
inv a := .up a
/-- The functor embedding `Type u` into `Type (max u v)`.
Write this as `uliftFunctor.{5, 2}` to get `Type 2 ⥤ Type 5`.
-/
@[pp_with_univ]
def uliftFunctor : Type u ⥤ Type max u v where
obj X := ULift.{v} X
map {X} {_} f := fun x : ULift.{v} X => ULift.up (f x.down)
@[simp]
theorem uliftFunctor_obj {X : Type u} : uliftFunctor.obj.{v} X = ULift.{v} X :=
rfl
@[simp]
theorem uliftFunctor_map {X Y : Type u} (f : X ⟶ Y) (x : ULift.{v} X) :
uliftFunctor.map f x = ULift.up (f x.down) :=
rfl
/-- `uliftFunctor : Type u ⥤ Type max u v` is fully faithful. -/
def fullyFaithfulULiftFunctor : (uliftFunctor.{v, u}).FullyFaithful where
preimage f := fun x ↦ (f (ULift.up x)).down
instance uliftFunctor_full : (uliftFunctor.{v, u}).Full :=
fullyFaithfulULiftFunctor.full
instance uliftFunctor_faithful : uliftFunctor.{v, u}.Faithful :=
fullyFaithfulULiftFunctor.faithful
/-- The functor embedding `Type u` into `Type u` via `ULift` is isomorphic to the identity functor.
-/
def uliftFunctorTrivial : uliftFunctor.{u, u} ≅ 𝟭 _ :=
NatIso.ofComponents uliftTrivial
-- TODO We should connect this to a general story about concrete categories
-- whose forgetful functor is representable.
/-- Any term `x` of a type `X` corresponds to a morphism `PUnit ⟶ X`. -/
def homOfElement {X : Type u} (x : X) : PUnit ⟶ X := fun _ => x
theorem homOfElement_eq_iff {X : Type u} (x y : X) : homOfElement x = homOfElement y ↔ x = y :=
⟨fun H => congr_fun H PUnit.unit, by simp_all⟩
/-- A morphism in `Type` is a monomorphism if and only if it is injective. -/
@[stacks 003C]
theorem mono_iff_injective {X Y : Type u} (f : X ⟶ Y) : Mono f ↔ Function.Injective f := by
constructor
· intro H x x' h
rw [← homOfElement_eq_iff] at h ⊢
exact (cancel_mono f).mp h
· exact fun H => ⟨fun g g' h => H.comp_left h⟩
theorem injective_of_mono {X Y : Type u} (f : X ⟶ Y) [hf : Mono f] : Function.Injective f :=
(mono_iff_injective f).1 hf
/-- A morphism in `Type` is an epimorphism if and only if it is surjective. -/
@[stacks 003C]
theorem epi_iff_surjective {X Y : Type u} (f : X ⟶ Y) : Epi f ↔ Function.Surjective f := by
constructor
· rintro ⟨H⟩
refine Function.surjective_of_right_cancellable_Prop fun g₁ g₂ hg => ?_
rw [← Equiv.ulift.symm.injective.comp_left.eq_iff]
apply H
change ULift.up ∘ g₁ ∘ f = ULift.up ∘ g₂ ∘ f
rw [hg]
· exact fun H => ⟨fun g g' h => H.injective_comp_right h⟩
theorem surjective_of_epi {X Y : Type u} (f : X ⟶ Y) [hf : Epi f] : Function.Surjective f :=
(epi_iff_surjective f).1 hf
section
/-- `ofTypeFunctor m` converts from Lean's `Type`-based `Category` to `CategoryTheory`. This
allows us to use these functors in category theory. -/
def ofTypeFunctor (m : Type u → Type v) [_root_.Functor m] [LawfulFunctor m] : Type u ⥤ Type v where
obj := m
map f := _root_.Functor.map f
map_id := fun α => by funext X; apply id_map
variable (m : Type u → Type v) [_root_.Functor m] [LawfulFunctor m]
@[simp]
theorem ofTypeFunctor_obj : (ofTypeFunctor m).obj = m :=
rfl
@[simp]
theorem ofTypeFunctor_map {α β} (f : α → β) :
(ofTypeFunctor m).map f = (_root_.Functor.map f : m α → m β) :=
rfl
end
end CategoryTheory
-- Isomorphisms in Type and equivalences.
namespace Equiv
universe u
variable {X Y : Type u}
/-- Any equivalence between types in the same universe gives
a categorical isomorphism between those types.
-/
def toIso (e : X ≃ Y) : X ≅ Y where
hom := e.toFun
inv := e.invFun
hom_inv_id := funext e.left_inv
inv_hom_id := funext e.right_inv
@[simp]
theorem toIso_hom {e : X ≃ Y} : e.toIso.hom = e :=
rfl
@[simp]
theorem toIso_inv {e : X ≃ Y} : e.toIso.inv = e.symm :=
rfl
end Equiv
universe u
namespace CategoryTheory.Iso
open CategoryTheory
variable {X Y : Type u}
/-- Any isomorphism between types gives an equivalence. -/
def toEquiv (i : X ≅ Y) : X ≃ Y where
toFun := i.hom
invFun := i.inv
left_inv x := congr_fun i.hom_inv_id x
right_inv y := congr_fun i.inv_hom_id y
@[simp]
theorem toEquiv_fun (i : X ≅ Y) : (i.toEquiv : X → Y) = i.hom :=
rfl
@[simp]
theorem toEquiv_symm_fun (i : X ≅ Y) : (i.toEquiv.symm : Y → X) = i.inv :=
rfl
@[simp]
theorem toEquiv_id (X : Type u) : (Iso.refl X).toEquiv = Equiv.refl X :=
rfl
@[simp]
theorem toEquiv_comp {X Y Z : Type u} (f : X ≅ Y) (g : Y ≅ Z) :
(f ≪≫ g).toEquiv = f.toEquiv.trans g.toEquiv :=
rfl
end CategoryTheory.Iso
namespace CategoryTheory
/-- A morphism in `Type u` is an isomorphism if and only if it is bijective. -/
theorem isIso_iff_bijective {X Y : Type u} (f : X ⟶ Y) : IsIso f ↔ Function.Bijective f :=
Iff.intro (fun _ => (asIso f : X ≅ Y).toEquiv.bijective) fun b =>
(Equiv.ofBijective f b).toIso.isIso_hom
instance : SplitEpiCategory (Type u) where
isSplitEpi_of_epi f hf :=
IsSplitEpi.mk' <|
{ section_ := Function.surjInv <| (epi_iff_surjective f).1 hf
id := funext <| Function.rightInverse_surjInv <| (epi_iff_surjective f).1 hf }
theorem isSplitEpi_iff_surjective {X Y : Type u} (f : X ⟶ Y) :
IsSplitEpi f ↔ Function.Surjective f :=
Iff.intro (fun _ => surjective_of_epi _)
fun hf => (by simp only [(epi_iff_surjective f).mpr hf, isSplitEpi_of_epi])
end CategoryTheory
-- We prove `equivIsoIso` and then use that to sneakily construct `equivEquivIso`.
-- (In this order the proofs are handled by `cat_disch`.)
/-- Equivalences (between types in the same universe) are the same as (isomorphic to) isomorphisms
of types. -/
@[simps]
def equivIsoIso {X Y : Type u} : X ≃ Y ≅ X ≅ Y where
hom e := e.toIso
inv i := i.toEquiv
/-- Equivalences (between types in the same universe) are the same as (equivalent to) isomorphisms
of types. -/
def equivEquivIso {X Y : Type u} : X ≃ Y ≃ (X ≅ Y) :=
equivIsoIso.toEquiv
@[simp]
theorem equivEquivIso_hom {X Y : Type u} (e : X ≃ Y) : equivEquivIso e = e.toIso :=
rfl
@[simp]
theorem equivEquivIso_inv {X Y : Type u} (e : X ≅ Y) : equivEquivIso.symm e = e.toEquiv :=
rfl |
.lake/packages/mathlib/Mathlib/CategoryTheory/Types/Set.lean | import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.Types.Basic
import Mathlib.Data.Set.Basic
/-!
# The functor from `Set X` to types
Given `X : Type u`, we define the functor `Set.functorToTypes : Set X ⥤ Type u`
which sends `A : Set X` to its underlying type.
-/
universe u
open CategoryTheory
namespace Set
/-- Given `X : Type u`, this the functor `Set X ⥤ Type u` which sends `A`
to its underlying type. -/
@[simps obj map]
def functorToTypes {X : Type u} : Set X ⥤ Type u where
obj S := S
map {S T} f := fun ⟨x, hx⟩ ↦ ⟨x, leOfHom f hx⟩
end Set |
.lake/packages/mathlib/Mathlib/CategoryTheory/Types/Monomorphisms.lean | import Mathlib.CategoryTheory.Limits.Connected
import Mathlib.CategoryTheory.Limits.Types.Filtered
import Mathlib.CategoryTheory.Limits.Types.Pushouts
import Mathlib.CategoryTheory.MorphismProperty.Limits
/-!
# Stability properties of monomorphisms in `Type`
In this file, we show that in the category `Type u`, monomorphisms
are stable under cobase change, filtered colimits.
After importing `Mathlib/CategoryTheory/MorphismProperty/TransfiniteComposition.lean`,
the fact that monomorphisms are stable under transfinite composition
will also be inferred automatically.
(The stability by retracts holds in any category: it is shown
in the file `Mathlib/CategoryTheory/MorphismProperty/Retract.lean`.)
-/
universe v' u' u
namespace CategoryTheory.Types
open MorphismProperty Limits
instance : (monomorphisms (Type u)).IsStableUnderCobaseChange where
of_isPushout {X₁ X₂ X₃ X₄ t l r b} sq ht := by
simp only [monomorphisms.iff] at ht ⊢
exact Limits.Types.pushoutCocone_inr_mono_of_isColimit sq.flip.isColimit
instance : MorphismProperty.IsStableUnderFilteredColimits.{v', u'} (monomorphisms (Type u)) where
isStableUnderColimitsOfShape J _ _ := ⟨fun F₁ F₂ c₁ c₂ hc₁ hc₂ f hf φ hφ ↦ by
simp only [functorCategory, monomorphisms.iff, mono_iff_injective] at hf ⊢
replace hφ (j : J) := congr_fun (hφ j)
dsimp at hφ
intro x₁ y₁ h
obtain ⟨j, x₁, y₁, rfl, rfl⟩ : ∃ (j : J) (x₁' y₁' : F₁.obj j),
x₁ = c₁.ι.app j x₁' ∧ y₁ = c₁.ι.app j y₁' := by
obtain ⟨j, x₁, rfl⟩ := Types.jointly_surjective_of_isColimit hc₁ x₁
obtain ⟨l, y₁, rfl⟩ := Types.jointly_surjective_of_isColimit hc₁ y₁
exact ⟨_, _, _, congr_fun (c₁.w (IsFiltered.leftToMax j l)).symm _,
congr_fun (c₁.w (IsFiltered.rightToMax j l)).symm _⟩
rw [hφ, hφ] at h
obtain ⟨k, α, hk⟩ := (Types.FilteredColimit.isColimit_eq_iff' hc₂ _ _).1 h
simp only [← FunctorToTypes.naturality] at hk
rw [← c₁.w α, types_comp_apply, types_comp_apply, hf _ hk]⟩
end CategoryTheory.Types |
.lake/packages/mathlib/Mathlib/CategoryTheory/Products/Bifunctor.lean | import Mathlib.CategoryTheory.Products.Basic
/-!
# Lemmas about functors out of product categories.
-/
open CategoryTheory
namespace CategoryTheory.Bifunctor
universe v₁ v₂ v₃ u₁ u₂ u₃
variable {C : Type u₁} {D : Type u₂} {E : Type u₃}
variable [Category.{v₁} C] [Category.{v₂} D] [Category.{v₃} E]
open scoped Prod
@[simp]
theorem map_id (F : C × D ⥤ E) (X : C) (Y : D) :
F.map ((𝟙 X) ×ₘ (𝟙 Y)) = 𝟙 (F.obj (X, Y)) :=
F.map_id (X, Y)
@[simp]
theorem map_id_comp (F : C × D ⥤ E) (W : C) {X Y Z : D} (f : X ⟶ Y) (g : Y ⟶ Z) :
F.map (𝟙 W ×ₘ (f ≫ g)) = F.map (𝟙 W ×ₘ f) ≫ F.map (𝟙 W ×ₘ g) := by
rw [← Functor.map_comp, prod_comp, Category.comp_id]
@[simp]
theorem map_comp_id (F : C × D ⥤ E) (X Y Z : C) (W : D) (f : X ⟶ Y) (g : Y ⟶ Z) :
F.map ((f ≫ g) ×ₘ 𝟙 W) = F.map (f ×ₘ 𝟙 W) ≫ F.map (g ×ₘ 𝟙 W) := by
rw [← Functor.map_comp, prod_comp, Category.comp_id]
@[simp]
theorem diagonal (F : C × D ⥤ E) (X X' : C) (f : X ⟶ X') (Y Y' : D) (g : Y ⟶ Y') :
F.map (𝟙 X ×ₘ g) ≫ F.map (f ×ₘ 𝟙 Y') = F.map (f ×ₘ g) := by
rw [← Functor.map_comp, prod_comp, Category.id_comp, Category.comp_id]
@[simp]
theorem diagonal' (F : C × D ⥤ E) (X X' : C) (f : X ⟶ X') (Y Y' : D) (g : Y ⟶ Y') :
F.map (f ×ₘ 𝟙 Y) ≫ F.map (𝟙 X' ×ₘ g) = F.map (f ×ₘ g) := by
rw [← Functor.map_comp, prod_comp, Category.id_comp, Category.comp_id]
end CategoryTheory.Bifunctor |
.lake/packages/mathlib/Mathlib/CategoryTheory/Products/Basic.lean | import Mathlib.CategoryTheory.Functor.Const
import Mathlib.CategoryTheory.Opposites
import Mathlib.Data.Prod.Basic
/-!
# Cartesian products of categories
We define the category instance on `C × D` when `C` and `D` are categories.
We define:
* `sectL C Z` : the functor `C ⥤ C × D` given by `X ↦ ⟨X, Z⟩`
* `sectR Z D` : the functor `D ⥤ C × D` given by `Y ↦ ⟨Z, Y⟩`
* `fst` : the functor `⟨X, Y⟩ ↦ X`
* `snd` : the functor `⟨X, Y⟩ ↦ Y`
* `swap` : the functor `C × D ⥤ D × C` given by `⟨X, Y⟩ ↦ ⟨Y, X⟩`
(and the fact this is an equivalence)
We further define `evaluation : C ⥤ (C ⥤ D) ⥤ D` and `evaluationUncurried : C × (C ⥤ D) ⥤ D`,
and products of functors and natural transformations, written `F.prod G` and `α.prod β`.
-/
namespace CategoryTheory
open Functor
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
section
variable (C : Type u₁) [CategoryStruct.{v₁} C] (D : Type u₂) [CategoryStruct.{v₂} D]
/-- `CategoryStruct.prod C D` gives the Cartesian product of two `CategoryStruct`'s. -/
@[simps (notRecursive := [])] -- notRecursive to generate simp lemmas like `id_fst` and `comp_snd`
instance prod : CategoryStruct.{max v₁ v₂} (C × D) where
Hom X Y := (X.1 ⟶ Y.1) × (X.2 ⟶ Y.2)
id X := ⟨𝟙 X.1, 𝟙 X.2⟩
comp f g := (f.1 ≫ g.1, f.2 ≫ g.2)
@[ext]
lemma prod.hom_ext {X Y : C × D} {f g : X ⟶ Y} (h₁ : f.1 = g.1) (h₂ : f.2 = g.2) : f = g := by
dsimp
ext <;> assumption
/-- Two rfl lemmas that cannot be generated by `@[simps]`. -/
@[simp]
theorem prod_id (X : C) (Y : D) : 𝟙 (X, Y) = (𝟙 X, 𝟙 Y) :=
rfl
@[simp]
theorem prod_comp {P Q R : C} {S T U : D} (f : (P, S) ⟶ (Q, T)) (g : (Q, T) ⟶ (R, U)) :
f ≫ g = (f.1 ≫ g.1, f.2 ≫ g.2) :=
rfl
namespace Prod
variable {C D} in
/-- Construct a morphism in a product category by giving its constituent components.
This constructor should be preferred over `Prod.mk`, because lean infers better the
source and target of the resulting morphism. -/
abbrev mkHom {X₁ X₂ : C} {Y₁ Y₂ : D} (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) : (X₁, Y₁) ⟶ (X₂, Y₂) :=
⟨f, g⟩
@[inherit_doc Prod.mkHom]
scoped infixr:70 " ×ₘ " => Prod.mkHom
end Prod
end
section
variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D]
/-- `prod C D` gives the Cartesian product of two categories. -/
@[stacks 001K]
instance prod' : Category.{max v₁ v₂} (C × D) where
theorem isIso_prod_iff {P Q : C} {S T : D} {f : (P, S) ⟶ (Q, T)} :
IsIso f ↔ IsIso f.1 ∧ IsIso f.2 := by
constructor
· rintro ⟨g, hfg, hgf⟩
simp? at hfg hgf says simp only [prod_Hom, prod_comp, prod_id, Prod.mk.injEq] at hfg hgf
rcases hfg with ⟨hfg₁, hfg₂⟩
rcases hgf with ⟨hgf₁, hgf₂⟩
exact ⟨⟨⟨g.1, hfg₁, hgf₁⟩⟩, ⟨⟨g.2, hfg₂, hgf₂⟩⟩⟩
· rintro ⟨⟨g₁, hfg₁, hgf₁⟩, ⟨g₂, hfg₂, hgf₂⟩⟩
dsimp at hfg₁ hgf₁ hfg₂ hgf₂
refine ⟨⟨(g₁, g₂), ?_, ?_⟩⟩
repeat { simp; constructor; assumption; assumption }
section
variable {C D}
/-- The isomorphism between `(X.1, X.2)` and `X`. -/
@[simps]
def prod.etaIso (X : C × D) : (X.1, X.2) ≅ X where
hom := (𝟙 _, 𝟙 _)
inv := (𝟙 _, 𝟙 _)
/-- Construct an isomorphism in `C × D` out of two isomorphisms in `C` and `D`. -/
@[simps]
def Iso.prod {P Q : C} {S T : D} (f : P ≅ Q) (g : S ≅ T) : (P, S) ≅ (Q, T) where
hom := (f.hom, g.hom)
inv := (f.inv, g.inv)
end
end
section
variable (C : Type u₁) [Category.{v₁} C] (D : Type u₁) [Category.{v₁} D]
/-- `Category.uniformProd C D` is an additional instance specialised so both factors have the same
universe levels. This helps typeclass resolution.
-/
instance uniformProd : Category (C × D) :=
CategoryTheory.prod' C D
end
-- Next we define the natural functors into and out of product categories. For now this doesn't
-- address the universal properties.
namespace Prod
/-- `sectL C Z` is the functor `C ⥤ C × D` given by `X ↦ (X, Z)`. -/
@[simps]
def sectL (C : Type u₁) [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (Z : D) : C ⥤ C × D where
obj X := (X, Z)
map f := (f, 𝟙 Z)
/-- `sectR Z D` is the functor `D ⥤ C × D` given by `Y ↦ (Z, Y)` . -/
@[simps]
def sectR {C : Type u₁} [Category.{v₁} C] (Z : C) (D : Type u₂) [Category.{v₂} D] : D ⥤ C × D where
obj X := (Z, X)
map f := (𝟙 Z, f)
variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D]
/-- `fst` is the functor `(X, Y) ↦ X`. -/
@[simps]
def fst : C × D ⥤ C where
obj X := X.1
map f := f.1
/-- `snd` is the functor `(X, Y) ↦ Y`. -/
@[simps]
def snd : C × D ⥤ D where
obj X := X.2
map f := f.2
/-- The functor swapping the factors of a Cartesian product of categories, `C × D ⥤ D × C`. -/
@[simps]
def swap : C × D ⥤ D × C where
obj X := (X.2, X.1)
map f := (f.2, f.1)
/-- Swapping the factors of a Cartesian product of categories twice is naturally isomorphic
to the identity functor.
-/
@[simps]
def symmetry : swap C D ⋙ swap D C ≅ 𝟭 (C × D) where
hom := { app := fun X => 𝟙 X }
inv := { app := fun X => 𝟙 X }
/-- The equivalence, given by swapping factors, between `C × D` and `D × C`.
-/
@[simps]
def braiding : C × D ≌ D × C where
functor := swap C D
inverse := swap D C
unitIso := Iso.refl _
counitIso := Iso.refl _
instance swapIsEquivalence : (swap C D).IsEquivalence :=
(by infer_instance : (braiding C D).functor.IsEquivalence)
variable {C D}
/-- Any morphism in a product factors as a morphism whose left component is an identity
followed by a morphism whose right component is an identity. -/
@[reassoc]
lemma fac {x y : C × D} (f : x ⟶ y) : f = (𝟙 x.1 ×ₘ f.2) ≫ (f.1 ×ₘ (𝟙 y.2)) := by simp
/-- Any morphism in a product factors as a morphism whose right component is an identity
followed by a morphism whose left component is an identity. -/
@[reassoc]
lemma fac' {x y : C × D} (f : x ⟶ y) : f = (f.1 ×ₘ 𝟙 x.2) ≫ ((𝟙 y.1) ×ₘ f.2) := by simp
end Prod
section
variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D]
/-- The "evaluation at `X`" functor, such that
`(evaluation.obj X).obj F = F.obj X`,
which is functorial in both `X` and `F`.
-/
@[simps]
def evaluation : C ⥤ (C ⥤ D) ⥤ D where
obj X :=
{ obj := fun F => F.obj X
map := fun α => α.app X }
map {_} {_} f :=
{ app := fun F => F.map f }
/-- The "evaluation of `F` at `X`" functor,
as a functor `C × (C ⥤ D) ⥤ D`.
-/
@[simps]
def evaluationUncurried : C × (C ⥤ D) ⥤ D where
obj p := p.2.obj p.1
map := fun {x} {y} f => x.2.map f.1 ≫ f.2.app y.1
variable {C}
/-- The constant functor followed by the evaluation functor is just the identity. -/
@[simps!]
def Functor.constCompEvaluationObj (X : C) : Functor.const C ⋙ (evaluation C D).obj X ≅ 𝟭 D :=
NatIso.ofComponents fun _ => Iso.refl _
end
variable {A : Type u₁} [Category.{v₁} A] {B : Type u₂} [Category.{v₂} B] {C : Type u₃}
[Category.{v₃} C] {D : Type u₄} [Category.{v₄} D]
namespace Functor
/-- The Cartesian product of two functors. -/
@[simps]
def prod (F : A ⥤ B) (G : C ⥤ D) : A × C ⥤ B × D where
obj X := (F.obj X.1, G.obj X.2)
map f := (F.map f.1, G.map f.2)
/- Because of limitations in Lean 3's handling of notations, we do not setup a notation `F × G`.
You can use `F.prod G` as a "poor man's infix", or just write `functor.prod F G`. -/
/-- Similar to `prod`, but both functors start from the same category `A` -/
@[simps]
def prod' (F : A ⥤ B) (G : A ⥤ C) : A ⥤ B × C where
obj a := (F.obj a, G.obj a)
map f := (F.map f, G.map f)
/-- The product `F.prod' G` followed by projection on the first component is isomorphic to `F` -/
@[simps!]
def prod'CompFst (F : A ⥤ B) (G : A ⥤ C) : F.prod' G ⋙ CategoryTheory.Prod.fst B C ≅ F :=
NatIso.ofComponents fun _ => Iso.refl _
/-- The product `F.prod' G` followed by projection on the second component is isomorphic to `G` -/
@[simps!]
def prod'CompSnd (F : A ⥤ B) (G : A ⥤ C) : F.prod' G ⋙ CategoryTheory.Prod.snd B C ≅ G :=
NatIso.ofComponents fun _ => Iso.refl _
section
variable (C)
/-- The diagonal functor. -/
@[simps! obj map]
def diag : C ⥤ C × C :=
(𝟭 C).prod' (𝟭 C)
end
end Functor
namespace NatTrans
/-- The Cartesian product of two natural transformations. -/
@[simps! app_fst app_snd]
def prod {F G : A ⥤ B} {H I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) : F.prod H ⟶ G.prod I where
app X := (α.app X.1, β.app X.2)
/- Again, it is inadvisable in Lean 3 to setup a notation `α × β`;
use instead `α.prod β` or `NatTrans.prod α β`. -/
/-- The Cartesian product of two natural transformations where both functors have the
same source. -/
@[simps! app_fst app_snd]
def prod' {F G : A ⥤ B} {H K : A ⥤ C} (α : F ⟶ G) (β : H ⟶ K) : F.prod' H ⟶ G.prod' K where
app X := (α.app X, β.app X)
end NatTrans
/-- The Cartesian product functor between functor categories -/
@[simps]
def prodFunctor : (A ⥤ B) × (C ⥤ D) ⥤ A × C ⥤ B × D where
obj FG := FG.1.prod FG.2
map nm := NatTrans.prod nm.1 nm.2
namespace NatIso
/-- The Cartesian product of two natural isomorphisms. -/
@[simps]
def prod {F F' : A ⥤ B} {G G' : C ⥤ D} (e₁ : F ≅ F') (e₂ : G ≅ G') :
F.prod G ≅ F'.prod G' where
hom := NatTrans.prod e₁.hom e₂.hom
inv := NatTrans.prod e₁.inv e₂.inv
end NatIso
namespace Equivalence
/-- The Cartesian product of two equivalences of categories. -/
@[simps]
def prod (E₁ : A ≌ B) (E₂ : C ≌ D) : A × C ≌ B × D where
functor := E₁.functor.prod E₂.functor
inverse := E₁.inverse.prod E₂.inverse
unitIso := NatIso.prod E₁.unitIso E₂.unitIso
counitIso := NatIso.prod E₁.counitIso E₂.counitIso
end Equivalence
/-- `F.flip` composed with evaluation is the same as evaluating `F`. -/
@[simps!]
def flipCompEvaluation (F : A ⥤ B ⥤ C) (a) : F.flip ⋙ (evaluation _ _).obj a ≅ F.obj a :=
NatIso.ofComponents fun b => Iso.refl _
theorem flip_comp_evaluation (F : A ⥤ B ⥤ C) (a) : F.flip ⋙ (evaluation _ _).obj a = F.obj a :=
rfl
/-- `F` composed with evaluation is the same as evaluating `F.flip`. -/
@[simps!]
def compEvaluation (F : A ⥤ B ⥤ C) (b) : F ⋙ (evaluation _ _).obj b ≅ F.flip.obj b :=
NatIso.ofComponents fun a => Iso.refl _
theorem comp_evaluation (F : A ⥤ B ⥤ C) (b) : F ⋙ (evaluation _ _).obj b = F.flip.obj b :=
rfl
/-- Whiskering by `F` and then evaluating at `a` is the same as evaluating at `F.obj a`. -/
@[simps!]
def whiskeringLeftCompEvaluation (F : A ⥤ B) (a : A) :
(whiskeringLeft A B C).obj F ⋙ (evaluation A C).obj a ≅ (evaluation B C).obj (F.obj a) :=
Iso.refl _
/-- Whiskering by `F` and then evaluating at `a` is the same as evaluating at `F.obj a`. -/
@[simp]
theorem whiskeringLeft_comp_evaluation (F : A ⥤ B) (a : A) :
(whiskeringLeft A B C).obj F ⋙ (evaluation A C).obj a = (evaluation B C).obj (F.obj a) :=
rfl
/-- Whiskering by `F` and then evaluating at `a` is the same as evaluating at `F` and then
applying `F`. -/
@[simps!]
def whiskeringRightCompEvaluation (F : B ⥤ C) (a : A) :
(whiskeringRight A B C).obj F ⋙ (evaluation _ _).obj a ≅ (evaluation _ _).obj a ⋙ F :=
Iso.refl _
/-- Whiskering by `F` and then evaluating at `a` is the same as evaluating at `F` and then
applying `F`. -/
@[simp]
theorem whiskeringRight_comp_evaluation (F : B ⥤ C) (a : A) :
(whiskeringRight A B C).obj F ⋙ (evaluation _ _).obj a = (evaluation _ _).obj a ⋙ F :=
rfl
variable (A B C)
/-- The forward direction for `functorProdFunctorEquiv` -/
@[simps]
def prodFunctorToFunctorProd : (A ⥤ B) × (A ⥤ C) ⥤ A ⥤ B × C where
obj F := F.1.prod' F.2
map {F G} f := NatTrans.prod' f.1 f.2
/-- The backward direction for `functorProdFunctorEquiv` -/
@[simps]
def functorProdToProdFunctor : (A ⥤ B × C) ⥤ (A ⥤ B) × (A ⥤ C) where
obj F := ⟨F ⋙ CategoryTheory.Prod.fst B C, F ⋙ CategoryTheory.Prod.snd B C⟩
map α := ⟨whiskerRight α _, whiskerRight α _⟩
/-- The unit isomorphism for `functorProdFunctorEquiv` -/
@[simps!]
def functorProdFunctorEquivUnitIso :
𝟭 _ ≅ prodFunctorToFunctorProd A B C ⋙ functorProdToProdFunctor A B C :=
NatIso.ofComponents fun F =>
Functor.prod'CompFst F.fst F.snd |>.prod (Functor.prod'CompSnd F.fst F.snd) |>.trans
(prod.etaIso F) |>.symm
/-- The counit isomorphism for `functorProdFunctorEquiv` -/
@[simps!]
def functorProdFunctorEquivCounitIso :
functorProdToProdFunctor A B C ⋙ prodFunctorToFunctorProd A B C ≅ 𝟭 _ :=
NatIso.ofComponents fun F => NatIso.ofComponents fun X => prod.etaIso (F.obj X)
/-- The equivalence of categories between `(A ⥤ B) × (A ⥤ C)` and `A ⥤ (B × C)` -/
@[simps]
def functorProdFunctorEquiv : (A ⥤ B) × (A ⥤ C) ≌ A ⥤ B × C :=
{ functor := prodFunctorToFunctorProd A B C,
inverse := functorProdToProdFunctor A B C,
unitIso := functorProdFunctorEquivUnitIso A B C,
counitIso := functorProdFunctorEquivCounitIso A B C, }
section Opposite
open Opposite
/-- The equivalence between the opposite of a product and the product of the opposites. -/
@[simps!]
def prodOpEquiv : (C × D)ᵒᵖ ≌ Cᵒᵖ × Dᵒᵖ where
functor :=
{ obj := fun X ↦ ⟨op X.unop.1, op X.unop.2⟩,
map := fun f ↦ ⟨f.unop.1.op, f.unop.2.op⟩ }
inverse :=
{ obj := fun ⟨X,Y⟩ ↦ op ⟨X.unop, Y.unop⟩,
map := fun ⟨f,g⟩ ↦ op ⟨f.unop, g.unop⟩ }
unitIso := Iso.refl _
counitIso := Iso.refl _
end Opposite
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Products/Associator.lean | import Mathlib.CategoryTheory.Products.Basic
/-!
The associator functor `((C × D) × E) ⥤ (C × (D × E))` and its inverse form an equivalence.
-/
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
open CategoryTheory
namespace CategoryTheory.prod
variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D] (E : Type u₃)
[Category.{v₃} E]
/-- The associator functor `(C × D) × E ⥤ C × (D × E)`.
-/
@[simps]
def associator : (C × D) × E ⥤ C × D × E where
obj X := (X.1.1, (X.1.2, X.2))
map := @fun _ _ f => (f.1.1, (f.1.2, f.2))
/-- The inverse associator functor `C × (D × E) ⥤ (C × D) × E `.
-/
@[simps]
def inverseAssociator : C × D × E ⥤ (C × D) × E where
obj X := ((X.1, X.2.1), X.2.2)
map := @fun _ _ f => ((f.1, f.2.1), f.2.2)
/-- The equivalence of categories expressing associativity of products of categories.
-/
@[simps]
def associativity : (C × D) × E ≌ C × D × E where
functor := associator C D E
inverse := inverseAssociator C D E
unitIso := Iso.refl _
counitIso := Iso.refl _
instance associatorIsEquivalence : (associator C D E).IsEquivalence :=
(by infer_instance : (associativity C D E).functor.IsEquivalence)
instance inverseAssociatorIsEquivalence : (inverseAssociator C D E).IsEquivalence :=
(by infer_instance : (associativity C D E).inverse.IsEquivalence)
-- TODO pentagon natural transformation? ...satisfying?
variable (A : Type u₄) [Category.{v₄} A]
/-- The associator isomorphism is compatible with `prodFunctorToFunctorProd`. -/
@[simps!]
def prodFunctorToFunctorProdAssociator :
(associativity _ _ _).functor ⋙ ((𝟭 _).prod (prodFunctorToFunctorProd A D E) ⋙
(prodFunctorToFunctorProd A C (D × E))) ≅
(prodFunctorToFunctorProd A C D).prod (𝟭 _) ⋙ (prodFunctorToFunctorProd A (C × D) E) ⋙
(associativity C D E).congrRight.functor :=
Iso.refl _
/-- The associator isomorphism is compatible with `functorProdToProdFunctor`. -/
@[simps!]
def functorProdToProdFunctorAssociator :
(associativity _ _ _).congrRight.functor ⋙ functorProdToProdFunctor A C (D × E) ⋙
(𝟭 _).prod (functorProdToProdFunctor A D E) ≅
functorProdToProdFunctor A (C × D) E ⋙ (functorProdToProdFunctor A C D).prod (𝟭 _) ⋙
(associativity _ _ _).functor :=
Iso.refl _
end CategoryTheory.prod |
.lake/packages/mathlib/Mathlib/CategoryTheory/Products/Unitor.lean | import Mathlib.CategoryTheory.Products.Basic
import Mathlib.CategoryTheory.Discrete.Basic
/-!
# The left/right unitor equivalences `1 × C ≌ C` and `C × 1 ≌ C`.
-/
universe w v u
open CategoryTheory
namespace CategoryTheory.prod
variable (C : Type u) [Category.{v} C]
/-- The left unitor functor `1 × C ⥤ C` -/
@[simps]
def leftUnitor : Discrete (PUnit : Type w) × C ⥤ C where
obj X := X.2
map f := f.2
/-- The right unitor functor `C × 1 ⥤ C` -/
@[simps]
def rightUnitor : C × Discrete (PUnit : Type w) ⥤ C where
obj X := X.1
map f := f.1
/-- The left inverse unitor `C ⥤ 1 × C` -/
@[simps]
def leftInverseUnitor : C ⥤ Discrete (PUnit : Type w) × C where
obj X := ⟨⟨PUnit.unit⟩, X⟩
map f := ⟨𝟙 _, f⟩
/-- The right inverse unitor `C ⥤ C × 1` -/
@[simps]
def rightInverseUnitor : C ⥤ C × Discrete (PUnit : Type w) where
obj X := ⟨X, ⟨PUnit.unit⟩⟩
map f := ⟨f, 𝟙 _⟩
/-- The equivalence of categories expressing left unity of products of categories. -/
@[simps]
def leftUnitorEquivalence : Discrete (PUnit : Type w) × C ≌ C where
functor := leftUnitor C
inverse := leftInverseUnitor C
unitIso := Iso.refl _
counitIso := Iso.refl _
/-- The equivalence of categories expressing right unity of products of categories. -/
@[simps]
def rightUnitorEquivalence : C × Discrete (PUnit : Type w) ≌ C where
functor := rightUnitor C
inverse := rightInverseUnitor C
unitIso := Iso.refl _
counitIso := Iso.refl _
instance leftUnitor_isEquivalence : (leftUnitor C).IsEquivalence :=
(leftUnitorEquivalence C).isEquivalence_functor
instance rightUnitor_isEquivalence : (rightUnitor C).IsEquivalence :=
(rightUnitorEquivalence C).isEquivalence_functor
end CategoryTheory.prod |
.lake/packages/mathlib/Mathlib/CategoryTheory/ComposableArrows/Basic.lean | import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.Comma.Arrow
import Mathlib.CategoryTheory.EpiMono
import Mathlib.Data.Fintype.Basic
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.SuppressCompilation
/-!
# Composable arrows
If `C` is a category, the type of `n`-simplices in the nerve of `C` identifies
to the type of functors `Fin (n + 1) ⥤ C`, which can be thought as families of `n` composable
arrows in `C`. In this file, we introduce and study this category `ComposableArrows C n`
of `n` composable arrows in `C`.
If `F : ComposableArrows C n`, we define `F.left` as the leftmost object, `F.right` as the
rightmost object, and `F.hom : F.left ⟶ F.right` is the canonical map.
The most significant definition in this file is the constructor
`F.precomp f : ComposableArrows C (n + 1)` for `F : ComposableArrows C n` and `f : X ⟶ F.left`:
"it shifts `F` towards the right and inserts `f` on the left". This `precomp` has
good definitional properties.
In the namespace `CategoryTheory.ComposableArrows`, we provide constructors
like `mk₁ f`, `mk₂ f g`, `mk₃ f g h` for `ComposableArrows C n` for small `n`.
TODO (@joelriou):
* construct some elements in `ComposableArrows m (Fin (n + 1))` for small `n`
the precomposition with which shall induce functors
`ComposableArrows C n ⥤ ComposableArrows C m` which correspond to simplicial operations
(specifically faces) with good definitional properties (this might be necessary for
up to `n = 7` in order to formalize spectral sequences following Verdier)
-/
/-!
New `simprocs` that run even in `dsimp` have caused breakages in this file.
(e.g. `dsimp` can now simplify `2 + 3` to `5`)
For now, we just turn off the offending simprocs in this file.
*However*, hopefully it is possible to refactor the material here so that no disabling of
simprocs is needed.
See issue https://github.com/leanprover-community/mathlib4/issues/27382.
-/
attribute [-simp] Fin.reduceFinMk
namespace CategoryTheory
open Category
variable (C : Type*) [Category C]
/-- `ComposableArrows C n` is the type of functors `Fin (n + 1) ⥤ C`. -/
abbrev ComposableArrows (n : ℕ) := Fin (n + 1) ⥤ C
namespace ComposableArrows
variable {C} {n m : ℕ}
variable (F G : ComposableArrows C n)
/-- A wrapper for `omega` which prefaces it with some quick and useful attempts -/
macro "valid" : tactic =>
`(tactic| first | assumption | apply zero_le | apply le_rfl | transitivity <;> assumption | omega)
/-- The `i`th object (with `i : ℕ` such that `i ≤ n`) of `F : ComposableArrows C n`. -/
@[simp]
abbrev obj' (i : ℕ) (hi : i ≤ n := by valid) : C := F.obj ⟨i, by cutsat⟩
/-- The map `F.obj' i ⟶ F.obj' j` when `F : ComposableArrows C n`, and `i` and `j`
are natural numbers such that `i ≤ j ≤ n`. -/
@[simp]
abbrev map' (i j : ℕ) (hij : i ≤ j := by valid) (hjn : j ≤ n := by valid) :
F.obj ⟨i, by cutsat⟩ ⟶ F.obj ⟨j, by cutsat⟩ :=
F.map (homOfLE (by simp only [Fin.mk_le_mk]; valid))
lemma map'_self (i : ℕ) (hi : i ≤ n := by valid) : F.map' i i = 𝟙 _ := F.map_id _
lemma map'_comp (i j k : ℕ) (hij : i ≤ j := by valid)
(hjk : j ≤ k := by valid) (hk : k ≤ n := by valid) :
F.map' i k = F.map' i j ≫ F.map' j k :=
F.map_comp _ _
/-- The leftmost object of `F : ComposableArrows C n`. -/
abbrev left := obj' F 0
/-- The rightmost object of `F : ComposableArrows C n`. -/
abbrev right := obj' F n
/-- The canonical map `F.left ⟶ F.right` for `F : ComposableArrows C n`. -/
abbrev hom : F.left ⟶ F.right := map' F 0 n
variable {F G}
/-- The map `F.obj' i ⟶ G.obj' i` induced on `i`th objects by a morphism `F ⟶ G`
in `ComposableArrows C n` when `i` is a natural number such that `i ≤ n`. -/
@[simp]
abbrev app' (φ : F ⟶ G) (i : ℕ) (hi : i ≤ n := by valid) :
F.obj' i ⟶ G.obj' i := φ.app _
@[reassoc]
lemma naturality' (φ : F ⟶ G) (i j : ℕ) (hij : i ≤ j := by valid)
(hj : j ≤ n := by valid) :
F.map' i j ≫ app' φ j = app' φ i ≫ G.map' i j :=
φ.naturality _
/-- Constructor for `ComposableArrows C 0`. -/
@[simps!]
def mk₀ (X : C) : ComposableArrows C 0 := (Functor.const (Fin 1)).obj X
namespace Mk₁
variable (X₀ X₁ : C)
/-- The map which sends `0 : Fin 2` to `X₀` and `1` to `X₁`. -/
@[simp]
def obj : Fin 2 → C
| ⟨0, _⟩ => X₀
| ⟨1, _⟩ => X₁
variable {X₀ X₁}
variable (f : X₀ ⟶ X₁)
/-- The obvious map `obj X₀ X₁ i ⟶ obj X₀ X₁ j` whenever `i j : Fin 2` satisfy `i ≤ j`. -/
@[simp]
def map : ∀ (i j : Fin 2) (_ : i ≤ j), obj X₀ X₁ i ⟶ obj X₀ X₁ j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 _
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨1, _⟩, ⟨1, _⟩, _ => 𝟙 _
lemma map_id (i : Fin 2) : map f i i (by simp) = 𝟙 _ :=
match i with
| 0 => rfl
| 1 => rfl
lemma map_comp {i j k : Fin 2} (hij : i ≤ j) (hjk : j ≤ k) :
map f i k (hij.trans hjk) = map f i j hij ≫ map f j k hjk := by
obtain rfl | rfl : i = j ∨ j = k := by cutsat
· rw [map_id, id_comp]
· rw [map_id, comp_id]
end Mk₁
/-- Constructor for `ComposableArrows C 1`. -/
@[simps]
def mk₁ {X₀ X₁ : C} (f : X₀ ⟶ X₁) : ComposableArrows C 1 where
obj := Mk₁.obj X₀ X₁
map g := Mk₁.map f _ _ (leOfHom g)
map_id := Mk₁.map_id f
map_comp g g' := Mk₁.map_comp f (leOfHom g) (leOfHom g')
/-- Constructor for morphisms `F ⟶ G` in `ComposableArrows C n` which takes as inputs
a family of morphisms `F.obj i ⟶ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def homMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ⟶ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) ≫ app _ = app _ ≫ G.map' i (i + 1)) :
F ⟶ G where
app := app
naturality := by
suffices ∀ (k i j : ℕ) (hj : i + k = j) (hj' : j ≤ n),
F.map' i j ≫ app _ = app _ ≫ G.map' i j by
rintro ⟨i, hi⟩ ⟨j, hj⟩ hij
have hij' := leOfHom hij
simp only [Fin.mk_le_mk] at hij'
obtain ⟨k, hk⟩ := Nat.le.dest hij'
exact this k i j hk (by valid)
intro k
induction k with intro i j hj hj'
| zero =>
simp only [add_zero] at hj
obtain rfl := hj
rw [F.map'_self i, G.map'_self i, id_comp, comp_id]
| succ k hk =>
rw [← add_assoc] at hj
subst hj
rw [F.map'_comp i (i + k) (i + k + 1), G.map'_comp i (i + k) (i + k + 1), assoc,
w (i + k) (by valid), reassoc_of% (hk i (i + k) rfl (by valid))]
/-- Constructor for isomorphisms `F ≅ G` in `ComposableArrows C n` which takes as inputs
a family of isomorphisms `F.obj i ≅ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def isoMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ≅ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n),
F.map' i (i + 1) ≫ (app _).hom = (app _).hom ≫ G.map' i (i + 1)) :
F ≅ G where
hom := homMk (fun i => (app i).hom) w
inv := homMk (fun i => (app i).inv) (fun i hi => by
dsimp only
rw [← cancel_epi ((app _).hom), ← reassoc_of% (w i hi), Iso.hom_inv_id, comp_id,
Iso.hom_inv_id_assoc])
lemma ext {F G : ComposableArrows C n} (h : ∀ i, F.obj i = G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) =
eqToHom (h _) ≫ G.map' i (i + 1) ≫ eqToHom (h _).symm) : F = G :=
Functor.ext_of_iso
(isoMk (fun i => eqToIso (h i)) (fun i hi => by simp [w i hi])) h
/-- Constructor for morphisms in `ComposableArrows C 0`. -/
@[simps!]
def homMk₀ {F G : ComposableArrows C 0} (f : F.obj' 0 ⟶ G.obj' 0) : F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => f) (fun i hi => by simp at hi)
@[ext]
lemma hom_ext₀ {F G : ComposableArrows C 0} {φ φ' : F ⟶ G}
(h : app' φ 0 = app' φ' 0) :
φ = φ' := by
ext i
fin_cases i
exact h
/-- Constructor for isomorphisms in `ComposableArrows C 0`. -/
@[simps!]
def isoMk₀ {F G : ComposableArrows C 0} (e : F.obj' 0 ≅ G.obj' 0) : F ≅ G where
hom := homMk₀ e.hom
inv := homMk₀ e.inv
lemma ext₀ {F G : ComposableArrows C 0} (h : F.obj' 0 = G.obj 0) : F = G :=
ext (fun i => match i with
| ⟨0, _⟩ => h) (fun i hi => by simp at hi)
lemma mk₀_surjective (F : ComposableArrows C 0) : ∃ (X : C), F = mk₀ X :=
⟨F.obj' 0, ext₀ rfl⟩
/-- Constructor for morphisms in `ComposableArrows C 1`. -/
@[simps!]
def homMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ⟶ G.obj' 0) (right : F.obj' 1 ⟶ G.obj' 1)
(w : F.map' 0 1 ≫ right = left ≫ G.map' 0 1 := by cat_disch) :
F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => left
| ⟨1, _⟩ => right) (by
intro i hi
obtain rfl : i = 0 := by simpa using hi
exact w)
@[ext]
lemma hom_ext₁ {F G : ComposableArrows C 1} {φ φ' : F ⟶ G}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) :
φ = φ' := by
ext i
match i with
| 0 => exact h₀
| 1 => exact h₁
/-- Constructor for isomorphisms in `ComposableArrows C 1`. -/
@[simps!]
def isoMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ≅ G.obj' 0) (right : F.obj' 1 ≅ G.obj' 1)
(w : F.map' 0 1 ≫ right.hom = left.hom ≫ G.map' 0 1 := by cat_disch) :
F ≅ G where
hom := homMk₁ left.hom right.hom w
inv := homMk₁ left.inv right.inv (by
rw [← cancel_mono right.hom, assoc, assoc, w, right.inv_hom_id, left.inv_hom_id_assoc]
apply comp_id)
lemma map'_eq_hom₁ (F : ComposableArrows C 1) : F.map' 0 1 = F.hom := rfl
lemma ext₁ {F G : ComposableArrows C 1}
(left : F.left = G.left) (right : F.right = G.right)
(w : F.hom = eqToHom left ≫ G.hom ≫ eqToHom right.symm) : F = G :=
Functor.ext_of_iso (isoMk₁ (eqToIso left) (eqToIso right) (by simp [map'_eq_hom₁, w]))
(fun i => by fin_cases i <;> assumption)
(fun i => by fin_cases i <;> rfl)
lemma mk₁_surjective (X : ComposableArrows C 1) : ∃ (X₀ X₁ : C) (f : X₀ ⟶ X₁), X = mk₁ f :=
⟨_, _, X.map' 0 1, ext₁ rfl rfl (by simp)⟩
/-- The bijection between `ComposableArrows C 1` and `Arrow C`. -/
@[simps]
def arrowEquiv : ComposableArrows C 1 ≃ Arrow C where
toFun F := Arrow.mk F.hom
invFun f := mk₁ f.hom
left_inv F := ComposableArrows.ext₁ rfl rfl (by simp)
right_inv _ := rfl
variable (F)
namespace Precomp
variable (X : C)
/-- The map `Fin (n + 1 + 1) → C` which "shifts" `F.obj'` to the right and inserts `X` in
the zeroth position. -/
def obj : Fin (n + 1 + 1) → C
| ⟨0, _⟩ => X
| ⟨i + 1, hi⟩ => F.obj' i
@[simp]
lemma obj_zero : obj F X 0 = X := rfl
@[simp]
lemma obj_one : obj F X 1 = F.obj' 0 := rfl
@[simp]
lemma obj_succ (i : ℕ) (hi : i + 1 < n + 1 + 1) : obj F X ⟨i + 1, hi⟩ = F.obj' i := rfl
variable {X} (f : X ⟶ F.left)
/-- Auxiliary definition for the action on maps of the functor `F.precomp f`.
It sends `0 ≤ 1` to `f` and `i + 1 ≤ j + 1` to `F.map' i j`. -/
def map : ∀ (i j : Fin (n + 1 + 1)) (_ : i ≤ j), obj F X i ⟶ obj F X j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 X
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨0, _⟩, ⟨j + 2, hj⟩, _ => f ≫ F.map' 0 (j + 1)
| ⟨i + 1, hi⟩, ⟨j + 1, hj⟩, hij => F.map' i j (by simpa using hij)
@[simp]
lemma map_zero_zero : map F f 0 0 (by simp) = 𝟙 X := rfl
@[simp]
lemma map_one_one : map F f 1 1 (by simp) = F.map (𝟙 _) := rfl
@[simp]
lemma map_zero_one : map F f 0 1 (by simp) = f := rfl
@[simp]
lemma map_zero_one' : map F f 0 ⟨0 + 1, by simp⟩ (by simp) = f := rfl
@[simp]
lemma map_zero_succ_succ (j : ℕ) (hj : j + 2 < n + 1 + 1) :
map F f 0 ⟨j + 2, hj⟩ (by simp) = f ≫ F.map' 0 (j+1) := rfl
@[simp]
lemma map_succ_succ (i j : ℕ) (hi : i + 1 < n + 1 + 1) (hj : j + 1 < n + 1 + 1)
(hij : i + 1 ≤ j + 1) :
map F f ⟨i + 1, hi⟩ ⟨j + 1, hj⟩ hij = F.map' i j := rfl
@[simp]
lemma map_one_succ (j : ℕ) (hj : j + 1 < n + 1 + 1) :
map F f 1 ⟨j + 1, hj⟩ (by simp [Fin.le_def]) = F.map' 0 j := rfl
lemma map_id (i : Fin (n + 1 + 1)) : map F f i i (by simp) = 𝟙 _ := by
obtain ⟨_ | _, hi⟩ := i <;> simp
lemma map_comp {i j k : Fin (n + 1 + 1)} (hij : i ≤ j) (hjk : j ≤ k) :
map F f i k (hij.trans hjk) = map F f i j hij ≫ map F f j k hjk := by
obtain ⟨i, hi⟩ := i
obtain ⟨j, hj⟩ := j
obtain ⟨k, hk⟩ := k
cases i
· obtain _ | _ | j := j
· dsimp
rw [id_comp]
· obtain _ | _ | k := k
· simp at hjk
· simp
· rfl
· obtain _ | _ | k := k
· simp [Fin.ext_iff] at hjk
· simp [Fin.le_def] at hjk
· dsimp
rw [assoc, ← F.map_comp, homOfLE_comp]
· obtain _ | j := j
· simp [Fin.ext_iff] at hij
· obtain _ | k := k
· simp [Fin.ext_iff] at hjk
· dsimp
rw [← F.map_comp, homOfLE_comp]
end Precomp
/-- "Precomposition" of `F : ComposableArrows C n` by a morphism `f : X ⟶ F.left`. -/
@[simps]
def precomp {X : C} (f : X ⟶ F.left) : ComposableArrows C (n + 1) where
obj := Precomp.obj F X
map g := Precomp.map F f _ _ (leOfHom g)
map_id := Precomp.map_id F f
map_comp g g' := Precomp.map_comp F f (leOfHom g) (leOfHom g')
/-- Constructor for `ComposableArrows C 2`. -/
@[simp]
def mk₂ {X₀ X₁ X₂ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) : ComposableArrows C 2 :=
(mk₁ g).precomp f
/-- Constructor for `ComposableArrows C 3`. -/
@[simp]
def mk₃ {X₀ X₁ X₂ X₃ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) : ComposableArrows C 3 :=
(mk₂ g h).precomp f
/-- Constructor for `ComposableArrows C 4`. -/
@[simp]
def mk₄ {X₀ X₁ X₂ X₃ X₄ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) (i : X₃ ⟶ X₄) :
ComposableArrows C 4 :=
(mk₃ g h i).precomp f
/-- Constructor for `ComposableArrows C 5`. -/
@[simp]
def mk₅ {X₀ X₁ X₂ X₃ X₄ X₅ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃)
(i : X₃ ⟶ X₄) (j : X₄ ⟶ X₅) :
ComposableArrows C 5 :=
(mk₄ g h i j).precomp f
section
variable {X₀ X₁ X₂ X₃ X₄ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) (i : X₃ ⟶ X₄)
/-! These examples are meant to test the good definitional properties of `precomp`,
and that `dsimp` can see through. -/
example : map' (mk₂ f g) 0 1 = f := by dsimp
example : map' (mk₂ f g) 1 2 = g := by dsimp
example : map' (mk₂ f g) 0 2 = f ≫ g := by dsimp
example : (mk₂ f g).hom = f ≫ g := by dsimp
example : map' (mk₂ f g) 0 0 = 𝟙 _ := by dsimp
example : map' (mk₂ f g) 1 1 = 𝟙 _ := by dsimp
example : map' (mk₂ f g) 2 2 = 𝟙 _ := by dsimp
example : map' (mk₃ f g h) 0 1 = f := by dsimp
example : map' (mk₃ f g h) 1 2 = g := by dsimp
example : map' (mk₃ f g h) 2 3 = h := by dsimp
example : map' (mk₃ f g h) 0 3 = f ≫ g ≫ h := by dsimp
example : (mk₃ f g h).hom = f ≫ g ≫ h := by dsimp
example : map' (mk₃ f g h) 0 2 = f ≫ g := by dsimp
example : map' (mk₃ f g h) 1 3 = g ≫ h := by dsimp
end
/-- The map `ComposableArrows C m → ComposableArrows C n` obtained by precomposition with
a functor `Fin (n + 1) ⥤ Fin (m + 1)`. -/
@[simps!]
def whiskerLeft (F : ComposableArrows C m) (Φ : Fin (n + 1) ⥤ Fin (m + 1)) :
ComposableArrows C n := Φ ⋙ F
/-- The functor `ComposableArrows C m ⥤ ComposableArrows C n` obtained by precomposition with
a functor `Fin (n + 1) ⥤ Fin (m + 1)`. -/
@[simps!]
def whiskerLeftFunctor (Φ : Fin (n + 1) ⥤ Fin (m + 1)) :
ComposableArrows C m ⥤ ComposableArrows C n where
obj F := F.whiskerLeft Φ
map f := Functor.whiskerLeft Φ f
/-- The functor `Fin n ⥤ Fin (n + 1)` which sends `i` to `i.succ`. -/
@[simps]
def _root_.Fin.succFunctor (n : ℕ) : Fin n ⥤ Fin (n + 1) where
obj i := i.succ
map {_ _} hij := homOfLE (Fin.succ_le_succ_iff.2 (leOfHom hij))
/-- The functor `ComposableArrows C (n + 1) ⥤ ComposableArrows C n` which forgets
the first arrow. -/
@[simps!]
def δ₀Functor : ComposableArrows C (n + 1) ⥤ ComposableArrows C n :=
whiskerLeftFunctor (Fin.succFunctor (n + 1))
/-- The `ComposableArrows C n` obtained by forgetting the first arrow. -/
abbrev δ₀ (F : ComposableArrows C (n + 1)) := δ₀Functor.obj F
@[simp]
lemma precomp_δ₀ {X : C} (f : X ⟶ F.left) : (F.precomp f).δ₀ = F := rfl
/-- The functor `Fin n ⥤ Fin (n + 1)` which sends `i` to `i.castSucc`. -/
@[simps]
def _root_.Fin.castSuccFunctor (n : ℕ) : Fin n ⥤ Fin (n + 1) where
obj i := i.castSucc
map hij := hij
/-- The functor `ComposableArrows C (n + 1) ⥤ ComposableArrows C n` which forgets
the last arrow. -/
@[simps!]
def δlastFunctor : ComposableArrows C (n + 1) ⥤ ComposableArrows C n :=
whiskerLeftFunctor (Fin.castSuccFunctor (n + 1))
/-- The `ComposableArrows C n` obtained by forgetting the first arrow. -/
abbrev δlast (F : ComposableArrows C (n + 1)) := δlastFunctor.obj F
section
variable {F G : ComposableArrows C (n + 1)}
/-- Inductive construction of morphisms in `ComposableArrows C (n + 1)`: in order to construct
a morphism `F ⟶ G`, it suffices to provide `α : F.obj' 0 ⟶ G.obj' 0` and `β : F.δ₀ ⟶ G.δ₀`
such that `F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1`. -/
def homMkSucc (α : F.obj' 0 ⟶ G.obj' 0) (β : F.δ₀ ⟶ G.δ₀)
(w : F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1) : F ⟶ G :=
homMk
(fun i => match i with
| ⟨0, _⟩ => α
| ⟨i + 1, hi⟩ => app' β i)
(fun i hi => by
obtain _ | i := i
· exact w
· exact naturality' β i (i + 1))
variable (α : F.obj' 0 ⟶ G.obj' 0) (β : F.δ₀ ⟶ G.δ₀)
(w : F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1)
@[simp]
lemma homMkSucc_app_zero : (homMkSucc α β w).app 0 = α := rfl
@[simp]
lemma homMkSucc_app_succ (i : ℕ) (hi : i + 1 < n + 1 + 1) :
(homMkSucc α β w).app ⟨i + 1, hi⟩ = app' β i := rfl
end
lemma hom_ext_succ {F G : ComposableArrows C (n + 1)} {f g : F ⟶ G}
(h₀ : app' f 0 = app' g 0) (h₁ : δ₀Functor.map f = δ₀Functor.map g) : f = g := by
ext ⟨i, hi⟩
obtain _ | i := i
· exact h₀
· exact congr_app h₁ ⟨i, by valid⟩
/-- Inductive construction of isomorphisms in `ComposableArrows C (n + 1)`: in order to
construct an isomorphism `F ≅ G`, it suffices to provide `α : F.obj' 0 ≅ G.obj' 0` and
`β : F.δ₀ ≅ G.δ₀` such that `F.map' 0 1 ≫ app' β.hom 0 = α.hom ≫ G.map' 0 1`. -/
@[simps]
def isoMkSucc {F G : ComposableArrows C (n + 1)} (α : F.obj' 0 ≅ G.obj' 0)
(β : F.δ₀ ≅ G.δ₀) (w : F.map' 0 1 ≫ app' β.hom 0 = α.hom ≫ G.map' 0 1) : F ≅ G where
hom := homMkSucc α.hom β.hom w
inv := homMkSucc α.inv β.inv (by
rw [← cancel_epi α.hom, ← reassoc_of% w, α.hom_inv_id_assoc, β.hom_inv_id_app]
dsimp
rw [comp_id])
hom_inv_id := by
apply hom_ext_succ
· simp
· ext ⟨i, hi⟩
simp
inv_hom_id := by
apply hom_ext_succ
· simp
· ext ⟨i, hi⟩
simp
lemma ext_succ {F G : ComposableArrows C (n + 1)} (h₀ : F.obj' 0 = G.obj' 0)
(h : F.δ₀ = G.δ₀) (w : F.map' 0 1 = eqToHom h₀ ≫ G.map' 0 1 ≫
eqToHom (Functor.congr_obj h.symm 0)) : F = G := by
have : ∀ i, F.obj i = G.obj i := by
intro ⟨i, hi⟩
rcases i with - | i
· exact h₀
· exact Functor.congr_obj h ⟨i, by valid⟩
exact Functor.ext_of_iso (isoMkSucc (eqToIso h₀) (eqToIso h) (by
rw [w]
dsimp [app']
rw [eqToHom_app, assoc, assoc, eqToHom_trans, eqToHom_refl, comp_id])) this
(by rintro ⟨_ | _, hi⟩ <;> simp)
lemma precomp_surjective (F : ComposableArrows C (n + 1)) :
∃ (F₀ : ComposableArrows C n) (X₀ : C) (f₀ : X₀ ⟶ F₀.left), F = F₀.precomp f₀ :=
⟨F.δ₀, _, F.map' 0 1, ext_succ rfl (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 2}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
/-- Constructor for morphisms in `ComposableArrows C 2`. -/
def homMk₂ : f ⟶ g := homMkSucc app₀ (homMk₁ app₁ app₂ w₁) w₀
@[simp]
lemma homMk₂_app_zero : (homMk₂ app₀ app₁ app₂ w₀ w₁).app 0 = app₀ := rfl
@[simp]
lemma homMk₂_app_one : (homMk₂ app₀ app₁ app₂ w₀ w₁).app 1 = app₁ := rfl
@[simp]
lemma homMk₂_app_two : (homMk₂ app₀ app₁ app₂ w₀ w₁).app ⟨2, by valid⟩ = app₂ := rfl
end
@[ext]
lemma hom_ext₂ {f g : ComposableArrows C 2} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₁ h₁ h₂)
/-- Constructor for isomorphisms in `ComposableArrows C 2`. -/
@[simps]
def isoMk₂ {f g : ComposableArrows C 2}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2) : f ≅ g where
hom := homMk₂ app₀.hom app₁.hom app₂.hom w₀ w₁
inv := homMk₂ app₀.inv app₁.inv app₂.inv
(by rw [← cancel_epi app₀.hom, ← reassoc_of% w₀, app₁.hom_inv_id,
comp_id, app₀.hom_inv_id_assoc])
(by rw [← cancel_epi app₁.hom, ← reassoc_of% w₁, app₂.hom_inv_id,
comp_id, app₁.hom_inv_id_assoc])
lemma ext₂ {f g : ComposableArrows C 2}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm) : f = g :=
ext_succ h₀ (ext₁ h₁ h₂ w₁) w₀
lemma mk₂_surjective (X : ComposableArrows C 2) :
∃ (X₀ X₁ X₂ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂), X = mk₂ f₀ f₁ :=
⟨_, _, _, X.map' 0 1, X.map' 1 2, ext₂ rfl rfl rfl (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 3}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
/-- Constructor for morphisms in `ComposableArrows C 3`. -/
def homMk₃ : f ⟶ g := homMkSucc app₀ (homMk₂ app₁ app₂ app₃ w₁ w₂) w₀
@[simp]
lemma homMk₃_app_zero : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app 0 = app₀ := rfl
@[simp]
lemma homMk₃_app_one : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app 1 = app₁ := rfl
@[simp]
lemma homMk₃_app_two : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app ⟨2, by valid⟩ = app₂ :=
rfl
@[simp]
lemma homMk₃_app_three : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app ⟨3, by valid⟩ = app₃ :=
rfl
end
@[ext]
lemma hom_ext₃ {f g : ComposableArrows C 3} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₂ h₁ h₂ h₃)
/-- Constructor for isomorphisms in `ComposableArrows C 3`. -/
@[simps]
def isoMk₃ {f g : ComposableArrows C 3}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3) : f ≅ g where
hom := homMk₃ app₀.hom app₁.hom app₂.hom app₃.hom w₀ w₁ w₂
inv := homMk₃ app₀.inv app₁.inv app₂.inv app₃.inv
(by rw [← cancel_epi app₀.hom, ← reassoc_of% w₀, app₁.hom_inv_id,
comp_id, app₀.hom_inv_id_assoc])
(by rw [← cancel_epi app₁.hom, ← reassoc_of% w₁, app₂.hom_inv_id,
comp_id, app₁.hom_inv_id_assoc])
(by rw [← cancel_epi app₂.hom, ← reassoc_of% w₂, app₃.hom_inv_id,
comp_id, app₂.hom_inv_id_assoc])
lemma ext₃ {f g : ComposableArrows C 3}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm) : f = g :=
ext_succ h₀ (ext₂ h₁ h₂ h₃ w₁ w₂) w₀
lemma mk₃_surjective (X : ComposableArrows C 3) :
∃ (X₀ X₁ X₂ X₃ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃), X = mk₃ f₀ f₁ f₂ :=
⟨_, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3,
ext₃ rfl rfl rfl rfl (by simp) (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 4}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3) (app₄ : f.obj' 4 ⟶ g.obj' 4)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄ = app₃ ≫ g.map' 3 4)
/-- Constructor for morphisms in `ComposableArrows C 4`. -/
def homMk₄ : f ⟶ g := homMkSucc app₀ (homMk₃ app₁ app₂ app₃ app₄ w₁ w₂ w₃) w₀
@[simp]
lemma homMk₄_app_zero : (homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app 0 = app₀ := rfl
@[simp]
lemma homMk₄_app_one : (homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app 1 = app₁ := rfl
@[simp]
lemma homMk₄_app_two :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨2, by valid⟩ = app₂ := rfl
@[simp]
lemma homMk₄_app_three :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨3, by valid⟩ = app₃ := rfl
@[simp]
lemma homMk₄_app_four :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨4, by valid⟩ = app₄ := rfl
end
@[ext]
lemma hom_ext₄ {f g : ComposableArrows C 4} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) (h₄ : app' φ 4 = app' φ' 4) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₃ h₁ h₂ h₃ h₄)
lemma map'_inv_eq_inv_map' {n m : ℕ} (h : n + 1 ≤ m) {f g : ComposableArrows C m}
(app : f.obj' n ≅ g.obj' n) (app' : f.obj' (n + 1) ≅ g.obj' (n + 1))
(w : f.map' n (n + 1) ≫ app'.hom = app.hom ≫ g.map' n (n + 1)) :
map' g n (n + 1) ≫ app'.inv = app.inv ≫ map' f n (n + 1) := by
rw [← cancel_epi app.hom, ← reassoc_of% w, app'.hom_inv_id, comp_id, app.hom_inv_id_assoc]
/-- Constructor for isomorphisms in `ComposableArrows C 4`. -/
@[simps]
def isoMk₄ {f g : ComposableArrows C 4}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3) (app₄ : f.obj' 4 ≅ g.obj' 4)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄.hom = app₃.hom ≫ g.map' 3 4) :
f ≅ g where
hom := homMk₄ app₀.hom app₁.hom app₂.hom app₃.hom app₄.hom w₀ w₁ w₂ w₃
inv := homMk₄ app₀.inv app₁.inv app₂.inv app₃.inv app₄.inv
(by rw [map'_inv_eq_inv_map' (by valid) app₀ app₁ w₀])
(by rw [map'_inv_eq_inv_map' (by valid) app₁ app₂ w₁])
(by rw [map'_inv_eq_inv_map' (by valid) app₂ app₃ w₂])
(by rw [map'_inv_eq_inv_map' (by valid) app₃ app₄ w₃])
lemma ext₄ {f g : ComposableArrows C 4}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3) (h₄ : f.obj' 4 = g.obj' 4)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm)
(w₃ : f.map' 3 4 = eqToHom h₃ ≫ g.map' 3 4 ≫ eqToHom h₄.symm) :
f = g :=
ext_succ h₀ (ext₃ h₁ h₂ h₃ h₄ w₁ w₂ w₃) w₀
lemma mk₄_surjective (X : ComposableArrows C 4) :
∃ (X₀ X₁ X₂ X₃ X₄ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃) (f₃ : X₃ ⟶ X₄),
X = mk₄ f₀ f₁ f₂ f₃ :=
⟨_, _, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3, X.map' 3 4,
ext₄ rfl rfl rfl rfl rfl (by simp) (by simp) (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 5}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3) (app₄ : f.obj' 4 ⟶ g.obj' 4) (app₅ : f.obj' 5 ⟶ g.obj' 5)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄ = app₃ ≫ g.map' 3 4)
(w₄ : f.map' 4 5 ≫ app₅ = app₄ ≫ g.map' 4 5)
/-- Constructor for morphisms in `ComposableArrows C 5`. -/
def homMk₅ : f ⟶ g := homMkSucc app₀ (homMk₄ app₁ app₂ app₃ app₄ app₅ w₁ w₂ w₃ w₄) w₀
@[simp]
lemma homMk₅_app_zero : (homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app 0 = app₀ := rfl
@[simp]
lemma homMk₅_app_one : (homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app 1 = app₁ := rfl
@[simp]
lemma homMk₅_app_two :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨2, by valid⟩ = app₂ := rfl
@[simp]
lemma homMk₅_app_three :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨3, by valid⟩ = app₃ := rfl
@[simp]
lemma homMk₅_app_four :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨4, by valid⟩ = app₄ := rfl
@[simp]
lemma homMk₅_app_five :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨5, by valid⟩ = app₅ := rfl
end
@[ext]
lemma hom_ext₅ {f g : ComposableArrows C 5} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) (h₄ : app' φ 4 = app' φ' 4) (h₅ : app' φ 5 = app' φ' 5) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₄ h₁ h₂ h₃ h₄ h₅)
/-- Constructor for isomorphisms in `ComposableArrows C 5`. -/
@[simps]
def isoMk₅ {f g : ComposableArrows C 5}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3) (app₄ : f.obj' 4 ≅ g.obj' 4) (app₅ : f.obj' 5 ≅ g.obj' 5)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄.hom = app₃.hom ≫ g.map' 3 4)
(w₄ : f.map' 4 5 ≫ app₅.hom = app₄.hom ≫ g.map' 4 5) :
f ≅ g where
hom := homMk₅ app₀.hom app₁.hom app₂.hom app₃.hom app₄.hom app₅.hom w₀ w₁ w₂ w₃ w₄
inv := homMk₅ app₀.inv app₁.inv app₂.inv app₃.inv app₄.inv app₅.inv
(by rw [map'_inv_eq_inv_map' (by valid) app₀ app₁ w₀])
(by rw [map'_inv_eq_inv_map' (by valid) app₁ app₂ w₁])
(by rw [map'_inv_eq_inv_map' (by valid) app₂ app₃ w₂])
(by rw [map'_inv_eq_inv_map' (by valid) app₃ app₄ w₃])
(by rw [map'_inv_eq_inv_map' (by valid) app₄ app₅ w₄])
lemma ext₅ {f g : ComposableArrows C 5}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3) (h₄ : f.obj' 4 = g.obj' 4) (h₅ : f.obj' 5 = g.obj' 5)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm)
(w₃ : f.map' 3 4 = eqToHom h₃ ≫ g.map' 3 4 ≫ eqToHom h₄.symm)
(w₄ : f.map' 4 5 = eqToHom h₄ ≫ g.map' 4 5 ≫ eqToHom h₅.symm) :
f = g :=
ext_succ h₀ (ext₄ h₁ h₂ h₃ h₄ h₅ w₁ w₂ w₃ w₄) w₀
lemma mk₅_surjective (X : ComposableArrows C 5) :
∃ (X₀ X₁ X₂ X₃ X₄ X₅ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃)
(f₃ : X₃ ⟶ X₄) (f₄ : X₄ ⟶ X₅), X = mk₅ f₀ f₁ f₂ f₃ f₄ :=
⟨_, _, _, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3, X.map' 3 4, X.map' 4 5,
ext₅ rfl rfl rfl rfl rfl rfl (by simp) (by simp) (by simp) (by simp) (by simp)⟩
/-- The `i`th arrow of `F : ComposableArrows C n`. -/
def arrow (i : ℕ) (hi : i < n := by valid) :
ComposableArrows C 1 := mk₁ (F.map' i (i + 1))
section mkOfObjOfMapSucc
variable (obj : Fin (n + 1) → C) (mapSucc : ∀ (i : Fin n), obj i.castSucc ⟶ obj i.succ)
lemma mkOfObjOfMapSucc_exists : ∃ (F : ComposableArrows C n) (e : ∀ i, F.obj i ≅ obj i),
∀ (i : ℕ) (hi : i < n), mapSucc ⟨i, hi⟩ =
(e ⟨i, _⟩).inv ≫ F.map' i (i + 1) ≫ (e ⟨i + 1, _⟩).hom := by
induction n with
| zero => exact ⟨mk₀ (obj 0), fun 0 => Iso.refl _, fun i hi => by simp at hi⟩
| succ n hn =>
obtain ⟨F, e, h⟩ := hn (fun i => obj i.succ) (fun i => mapSucc i.succ)
refine ⟨F.precomp (mapSucc 0 ≫ (e 0).inv), fun i => match i with
| 0 => Iso.refl _
| ⟨i + 1, hi⟩ => e _, fun i hi => ?_⟩
obtain _ | i := i
· simp
· exact h i (by valid)
/-- Given `obj : Fin (n + 1) → C` and `mapSucc i : obj i.castSucc ⟶ obj i.succ`
for all `i : Fin n`, this is `F : ComposableArrows C n` such that `F.obj i` is
definitionally equal to `obj i` and such that `F.map' i (i + 1) = mapSucc ⟨i, hi⟩`. -/
noncomputable def mkOfObjOfMapSucc : ComposableArrows C n :=
(mkOfObjOfMapSucc_exists obj mapSucc).choose.copyObj obj
(mkOfObjOfMapSucc_exists obj mapSucc).choose_spec.choose
@[simp]
lemma mkOfObjOfMapSucc_obj (i : Fin (n + 1)) :
(mkOfObjOfMapSucc obj mapSucc).obj i = obj i := rfl
lemma mkOfObjOfMapSucc_map_succ (i : ℕ) (hi : i < n := by valid) :
(mkOfObjOfMapSucc obj mapSucc).map' i (i + 1) = mapSucc ⟨i, hi⟩ :=
((mkOfObjOfMapSucc_exists obj mapSucc).choose_spec.choose_spec i hi).symm
lemma mkOfObjOfMapSucc_arrow (i : ℕ) (hi : i < n := by valid) :
(mkOfObjOfMapSucc obj mapSucc).arrow i = mk₁ (mapSucc ⟨i, hi⟩) :=
ext₁ rfl rfl (by simpa using mkOfObjOfMapSucc_map_succ obj mapSucc i hi)
end mkOfObjOfMapSucc
suppress_compilation in
variable (C n) in
/-- The equivalence `(ComposableArrows C n)ᵒᵖ ≌ ComposableArrows Cᵒᵖ n` obtained
by reversing the arrows. -/
@[simps!]
def opEquivalence : (ComposableArrows C n)ᵒᵖ ≌ ComposableArrows Cᵒᵖ n :=
((orderDualEquivalence (Fin (n + 1))).symm.trans
Fin.revOrderIso.equivalence).symm.congrLeft.op.trans
(Functor.leftOpRightOpEquiv (Fin (n + 1)) C)
end ComposableArrows
section
open ComposableArrows
variable {C} {D : Type*} [Category D] (G : C ⥤ D) (n : ℕ)
/-- The functor `ComposableArrows C n ⥤ ComposableArrows D n` obtained by postcomposition
with a functor `C ⥤ D`. -/
@[simps!]
def Functor.mapComposableArrows :
ComposableArrows C n ⥤ ComposableArrows D n :=
(whiskeringRight _ _ _).obj G
suppress_compilation in
/-- The functor `ComposableArrows C n ⥤ ComposableArrows D n` induced by `G : C ⥤ D`
commutes with `opEquivalence`. -/
def Functor.mapComposableArrowsOpIso :
G.mapComposableArrows n ⋙ (opEquivalence D n).functor.rightOp ≅
(opEquivalence C n).functor.rightOp ⋙ (G.op.mapComposableArrows n).op :=
Iso.refl _
end
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/LocallyCartesianClosed/ChosenPullbacksAlong.lean | import Mathlib.CategoryTheory.Comma.Over.Pullback
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic
import Mathlib.CategoryTheory.Adjunction.Unique
/-!
# Chosen pullbacks along a morphism
## Main declarations
- `ChosenPullbacksAlong` : For a morphism `f : Y ⟶ X` in `C`, the type class
`ChosenPullbacksAlong f` provides the data of a pullback functor `Over X ⥤ Over Y`
as a right adjoint to `Over.map f`.
## Main results
- We prove that `ChosenPullbacksAlong` has good closure properties: isos have chosen pullbacks,
and composition of morphisms with chosen pullbacks have chosen pullbacks.
- We prove that chosen pullbacks yields usual pullbacks: `ChosenPullbacksAlong.isPullback`
proves that for morphisms `f` and `g` with the same codomain, the object
`ChosenPullbacksAlong.pullbackObj f g` together with morphisms
`ChosenPullbacksAlong.fst f g` and `ChosenPullbacksAlong.snd f g` form a pullback square
over `f` and `g`.
- We prove that in cartesian monoidal categories, morphisms to the terminal tensor unit and
the product projections have chosen pullbacks.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
open Category Limits CartesianMonoidalCategory MonoidalCategory Over
variable {C : Type u₁} [Category.{v₁} C]
/-- A functorial choice of pullbacks along a morphism `f : Y ⟶ X` in `C` given by a functor
`Over X ⥤ Over Y` which is a right adjoint to the functor `Over.map f`. -/
class ChosenPullbacksAlong {Y X : C} (f : Y ⟶ X) where
/-- The pullback functor along `f`. -/
pullback : Over X ⥤ Over Y
/-- The adjunction between `Over.map f` and `pullback f`. -/
mapPullbackAdj (f) : Over.map f ⊣ pullback
variable (C) in
/-- A category has chosen pullbacks if every morphism has a chosen pullback. -/
abbrev ChosenPullbacks := Π {X Y : C} (f : Y ⟶ X), ChosenPullbacksAlong f
namespace ChosenPullbacksAlong
/-- Relating the existing noncomputable `HasPullbacksAlong` typeclass to `ChosenPullbacksAlong`. -/
@[simps]
noncomputable def ofHasPullbacksAlong {Y X : C} (f : Y ⟶ X) [HasPullbacksAlong f] :
ChosenPullbacksAlong f where
pullback := Over.pullback f
mapPullbackAdj := Over.mapPullbackAdj f
/-- The identity morphism has a functorial choice of pullbacks. -/
@[simps]
def id (X : C) : ChosenPullbacksAlong (𝟙 X) where
pullback := 𝟭 _
mapPullbackAdj := (Adjunction.id).ofNatIsoLeft (Over.mapId _).symm
attribute [local instance] ChosenPullbacksAlong.id in
/-- The chosen pullback functor of the identity morphism is naturally isomorphic to the
identity functor. -/
def pullbackId (X : C) : pullback (𝟙 X) ≅ 𝟭 (Over X) := Iso.refl _
/-- Every isomorphism has a functorial choice of pullbacks. -/
@[simps]
def iso {Y X : C} (f : Y ≅ X) : ChosenPullbacksAlong f.hom where
pullback.obj Z := Over.mk (Z.hom ≫ f.inv)
pullback.map {Y Z} g := Over.homMk (g.left)
mapPullbackAdj.unit.app T := Over.homMk (𝟙 T.left)
mapPullbackAdj.counit.app U := Over.homMk (𝟙 _)
/-- The inverse of an isomorphism has a functorial choice of pullbacks. -/
@[simps!]
def isoInv {Y X : C} (f : Y ≅ X) : ChosenPullbacksAlong f.inv := iso f.symm
/-- The composition of morphisms with chosen pullbacks has a chosen pullback. -/
@[simps]
def comp {Z Y X : C} (f : Y ⟶ X) (g : Z ⟶ Y)
[ChosenPullbacksAlong f] [ChosenPullbacksAlong g] : ChosenPullbacksAlong (g ≫ f) where
pullback := pullback f ⋙ pullback g
mapPullbackAdj := ((mapPullbackAdj g).comp (mapPullbackAdj f)).ofNatIsoLeft
(Over.mapComp g f).symm
attribute [local instance] ChosenPullbacksAlong.comp in
/-- The chosen pullback functor of a composition of morphisms is naturally isomorphic to
the composition of the chosen pullback functors. -/
def pullbackComp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z)
[ChosenPullbacksAlong f] [ChosenPullbacksAlong g] :
pullback (f ≫ g) ≅ pullback g ⋙ pullback f :=
Iso.refl _
/-- In cartesian monoidal categories, any morphism to the terminal tensor unit has a functorial
choice of pullbacks. -/
@[simps]
def cartesianMonoidalCategoryToUnit [CartesianMonoidalCategory C] {X : C} (f : X ⟶ 𝟙_ C) :
ChosenPullbacksAlong f where
pullback.obj Y := Over.mk (snd Y.left X)
pullback.map {Y Z} g := Over.homMk (g.left ▷ X)
mapPullbackAdj.unit.app T := Over.homMk (lift (𝟙 _) (T.hom))
mapPullbackAdj.counit.app U := Over.homMk (fst _ _)
/-- In cartesian monoidal categories, the first product projections `fst` have a functorial choice
of pullbacks. -/
@[simps]
def cartesianMonoidalCategoryFst [CartesianMonoidalCategory C] (X Y : C) :
ChosenPullbacksAlong (fst X Y : X ⊗ Y ⟶ X) where
pullback.obj Z := Over.mk (Z.hom ▷ Y)
pullback.map g := Over.homMk (g.left ▷ Y)
mapPullbackAdj.unit.app T := Over.homMk (lift (𝟙 _) (T.hom ≫ snd _ _))
mapPullbackAdj.counit.app U := Over.homMk (fst _ _)
/-- In cartesian monoidal categories, the second product projections `snd` have a functorial choice
of pullbacks. -/
@[simps]
def cartesianMonoidalCategorySnd [CartesianMonoidalCategory C] (X Y : C) :
ChosenPullbacksAlong (snd X Y : X ⊗ Y ⟶ Y) where
pullback.obj Z := Over.mk (X ◁ Z.hom)
pullback.map g := Over.homMk (X ◁ g.left)
mapPullbackAdj.unit.app T := Over.homMk (lift (T.hom ≫ fst _ _) (𝟙 _))
mapPullbackAdj.counit.app U := Over.homMk (snd _ _)
section PullbackFromChosenPullbacksAlongs
variable {Y Z X : C} (f : Y ⟶ X) (g : Z ⟶ X) [ChosenPullbacksAlong g]
/-- The underlying object of the chosen pullback along `g` of `f`. -/
abbrev pullbackObj : C := ((pullback g).obj (Over.mk f)).left
/-- A morphism in `Over X` from the chosen pullback along `g` of `f` to `Over.mk f`. -/
abbrev fst' : (Over.map g).obj ((pullback g).obj (Over.mk f)) ⟶ Over.mk f :=
(mapPullbackAdj g).counit.app <| Over.mk f
/-- The first projection from the chosen pullback along `g` of `f` to the domain of `f`. -/
abbrev fst : pullbackObj f g ⟶ Y := fst' f g |>.left
theorem fst'_left : (fst' f g).left = fst f g := rfl
/-- The second projection from the chosen pullback along `g` of `f` to the domain of `g`. -/
abbrev snd : pullbackObj f g ⟶ Z := (pullback g).obj (Over.mk f) |>.hom
/-- A morphism in `Over X` from the chosen pullback along `g` of `f` to `Over.mk g`. -/
abbrev snd' : (Over.map g).obj ((pullback g).obj (Over.mk f)) ⟶ (Over.mk g) :=
Over.homMk (snd f g)
theorem snd'_left : (snd' f g).left = snd f g := rfl
variable {f g}
@[reassoc]
theorem condition : fst f g ≫ f = snd f g ≫ g :=
Over.w (fst' f g)
variable (f g) in
@[ext]
theorem hom_ext {W : C} {φ₁ φ₂ : W ⟶ pullbackObj f g} (h₁ : φ₁ ≫ fst _ _ = φ₂ ≫ fst _ _)
(h₂ : φ₁ ≫ snd _ _ = φ₂ ≫ snd _ _) :
φ₁ = φ₂ := by
let adj := mapPullbackAdj g
let U : Over Z := Over.mk (φ₁ ≫ snd f g)
let φ₁' : U ⟶ (pullback g).obj (Over.mk f) := Over.homMk φ₁
let φ₂' : U ⟶ (pullback g).obj (Over.mk f) := Over.homMk φ₂ (by simpa using h₂.symm)
have : φ₁' = φ₂' := by
apply (adj.homEquiv U _).symm.injective
apply (Over.forget X).map_injective
simpa using h₁
exact congr_arg CommaMorphism.left this
section Lift
variable {W : C} (a : W ⟶ Y) (b : W ⟶ Z) (h : a ≫ f = b ≫ g := by cat_disch)
/-- Given morphisms `a : W ⟶ Y` and `b : W ⟶ Z` satisfying `a ≫ f = b ≫ g`,
constructs the unique morphism `W ⟶ pullbackObj f g` which lifts `a` and `b`. -/
def lift : W ⟶ pullbackObj f g :=
(((mapPullbackAdj g).homEquiv (Over.mk b) (Over.mk f)) (Over.homMk a)).left
@[reassoc (attr := simp)]
theorem lift_fst : lift a b h ≫ fst f g = a := by
let adj := mapPullbackAdj g
let a' : (Over.map g).obj (Over.mk b) ⟶ Over.mk f := Over.homMk a h
have : (Over.map g).map (adj.homEquiv (.mk b) (.mk f) (Over.homMk a)) ≫ fst' f g = a' := by
simp only [← Adjunction.homEquiv_counit, Equiv.symm_apply_apply, adj, a']
exact congr_arg CommaMorphism.left this
@[reassoc (attr := simp)]
theorem lift_snd : lift a b h ≫ snd f g = b := by
simp [lift]
end Lift
section PullbackMap
variable (f g)
/-- The functoriality of `pullbackObj f g` in both arguments: Given a map from the pullback cospans
of `f' : Y' ⟶ X'` and `g' : Z' ⟶ X'` to the pullback cospan of `f : Y ⟶ X` and `g : Z ⟶ X`
as in the diagram below
```
Y' ⟶ Y
↘ ↘
X' ⟶ X
↗ ↗
Z' ⟶ Z
```
if the morphisms `g'` and `g` both have chosen pullbacks, then we get an induced morphism
`pullbackMap f g f' g' comm₁ comm₂` from the chosen pullback of
`f' : Y' ⟶ X'` along `g'` to the chosen pullback of `f : Y ⟶ X` along `g`.
Here `comm₁` and `comm₂` are the commutativity conditions of the squares in the diagram above.
-/
def pullbackMap {Y' Z' X' : C} (f' : Y' ⟶ X') (g' : Z' ⟶ X') [ChosenPullbacksAlong g']
(γ₁ : Y' ⟶ Y) (γ₂ : Z' ⟶ Z) (γ₃ : X' ⟶ X)
(comm₁ : f' ≫ γ₃ = γ₁ ≫ f := by cat_disch) (comm₂ : g' ≫ γ₃ = γ₂ ≫ g := by cat_disch) :
pullbackObj f' g' ⟶ pullbackObj f g :=
lift (fst f' g' ≫ γ₁) (snd f' g' ≫ γ₂)
(by rw [assoc, ← comm₁, ← assoc, condition, assoc, comm₂, assoc])
variable {f g}
@[reassoc (attr := simp)]
theorem pullbackMap_fst {Y' Z' X' : C} {f' : Y' ⟶ X'} {g' : Z' ⟶ X'} [ChosenPullbacksAlong g']
{γ₁ : Y' ⟶ Y} {γ₂ : Z' ⟶ Z} {γ₃ : X' ⟶ X} (comm₁ comm₂ := by cat_disch) :
pullbackMap f g f' g' γ₁ γ₂ γ₃ comm₁ comm₂ ≫ fst f g = fst f' g' ≫ γ₁ := by
simp only [pullbackMap, lift_fst]
@[reassoc (attr := simp)]
theorem pullbackMap_snd {Y' Z' X' : C} {f' : Y' ⟶ X'} {g' : Z' ⟶ X'} [ChosenPullbacksAlong g']
{γ₁ : Y' ⟶ Y} {γ₂ : Z' ⟶ Z} {γ₃ : X' ⟶ X} (comm₁ comm₂ := by cat_disch) :
pullbackMap f g f' g' γ₁ γ₂ γ₃ comm₁ comm₂ ≫ snd f g = snd f' g' ≫ γ₂ := by
simp only [pullbackMap, lift_snd]
@[simp]
theorem pullbackMap_id : pullbackMap f g f g (𝟙 Y) (𝟙 Z) (𝟙 X) = 𝟙 _ := by
cat_disch
@[reassoc (attr := simp)]
theorem pullbackMap_comp {Y' Z' X' Y'' Z'' X'' : C}
{f' : Y' ⟶ X'} {g' : Z' ⟶ X'} {f'' : Y'' ⟶ X''} {g'' : Z'' ⟶ X''}
[ChosenPullbacksAlong g'] [ChosenPullbacksAlong g'']
{γ₁ : Y' ⟶ Y} {γ₂ : Z' ⟶ Z} {γ₃ : X' ⟶ X}
{δ₁ : Y'' ⟶ Y'} {δ₂ : Z'' ⟶ Z'} {δ₃ : X'' ⟶ X'}
(comm₁ comm₂ comm₁' comm₂' := by cat_disch) :
pullbackMap f' g' f'' g'' δ₁ δ₂ δ₃ comm₁' comm₂' ≫
pullbackMap f g f' g' γ₁ γ₂ γ₃ comm₁ comm₂ =
pullbackMap f g f'' g'' (δ₁ ≫ γ₁) (δ₂ ≫ γ₂) (δ₃ ≫ γ₃)
(by rw [reassoc_of% comm₁', comm₁, assoc]) (by rw [reassoc_of% comm₂', comm₂, assoc]) := by
cat_disch
end PullbackMap
variable (f g)
theorem isPullback : IsPullback (fst f g) (snd f g) f g where
w := condition
isLimit' :=
⟨PullbackCone.IsLimit.mk _ (fun s ↦ lift s.fst s.snd s.condition)
(by simp) (by simp) (by cat_disch)⟩
attribute [local simp] condition in
/-- If `g` has a chosen pullback, then `Over.ChosenPullbacksAlong.fst f g` has a chosen pullback. -/
def chosenPullbacksAlongFst : ChosenPullbacksAlong (fst f g) where
pullback.obj W := Over.mk (pullbackMap _ _ _ _ W.hom (𝟙 _) (𝟙 _))
pullback.map {W' W} k := Over.homMk (lift (fst _ g ≫ k.left) (snd _ g)) _
mapPullbackAdj.unit.app Q := Over.homMk (lift (𝟙 _) (Q.hom ≫ snd _ _))
mapPullbackAdj.counit.app W := Over.homMk (fst _ g)
instance hasPullbackAlong : HasPullbacksAlong g := fun f => (isPullback f g).hasPullback
instance hasPullbacks [ChosenPullbacks C] : HasPullbacks C :=
hasPullbacks_of_hasLimit_cospan _
/-- The computable `ChosenPullbacksAlong.pullback g` is naturally isomorphic to the noncomputable
`Over.pullback g`. -/
noncomputable def pullbackIsoOverPullback : ChosenPullbacksAlong.pullback g ≅ Over.pullback g :=
(ChosenPullbacksAlong.mapPullbackAdj g).rightAdjointUniq (Over.mapPullbackAdj g)
@[reassoc (attr := simp)]
theorem pullbackIsoOverPullback_hom_app_comp_fst (T : Over X) :
((pullbackIsoOverPullback g).hom.app T).left ≫ pullback.fst _ _ = fst _ _ := by
simpa using (Over.forget _).congr_map
((ChosenPullbacksAlong.mapPullbackAdj g).rightAdjointUniq_hom_app_counit
(Over.mapPullbackAdj g) T)
@[reassoc (attr := simp)]
theorem pullbackIsoOverPullback_hom_app_comp_snd (T : Over X) :
((pullbackIsoOverPullback g).hom.app T).left ≫ pullback.snd _ _ = snd _ _ :=
Over.w ((pullbackIsoOverPullback g).hom.app T)
@[reassoc (attr := simp)]
theorem pullbackIsoOverPullback_inv_app_comp_fst (T : Over X) :
((pullbackIsoOverPullback g).inv.app T).left ≫ fst _ _ = pullback.fst _ _ := by
simp [← pullbackIsoOverPullback_hom_app_comp_fst, ← Over.comp_left_assoc]
@[reassoc (attr := simp)]
theorem pullbackIsoOverPullback_inv_app_comp_snd (T : Over X) :
((pullbackIsoOverPullback g).inv.app T).left ≫ snd _ _ = pullback.snd _ _ :=
Over.w ((pullbackIsoOverPullback g).inv.app T)
end PullbackFromChosenPullbacksAlongs
end ChosenPullbacksAlong
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Join/Sum.lean | import Mathlib.CategoryTheory.Join.Basic
import Mathlib.CategoryTheory.Sums.Basic
/-!
# Embedding of `C ⊕ D` into `C ⋆ D`
This file constructs a canonical functor `Join.fromSum` from `C ⊕ D` to `C ⋆ D` and gives
its characterization in terms of the canonical inclusions.
We also provide `Faithful` and `EssSurj` instances on this functor.
-/
namespace CategoryTheory.Join
variable (C D : Type*) [Category C] [Category D]
/-- The canonical functor from the sum to the join.
It sends `inl c` to `left c` and `inr d` to `right d`. -/
@[simps! obj] -- Maps get characterized w.r.t. the inclusions below
def fromSum : C ⊕ D ⥤ C ⋆ D := (inclLeft C D).sum' <| inclRight C D
variable {C} in
@[simp]
lemma fromSum_map_inl {c c' : C} (f : c ⟶ c') :
(fromSum C D).map ((Sum.inl_ C D).map f) = (inclLeft C D).map f :=
rfl
variable {D} in
@[simp]
lemma fromSum_map_inr {d d' : D} (f : d ⟶ d') :
(fromSum C D).map ((Sum.inr_ C D).map f) = (inclRight C D).map f :=
rfl
/-- Characterization of `fromSum` with respect to the left inclusion. -/
@[simps! hom_app inv_app]
def inlCompFromSum : Sum.inl_ C D ⋙ fromSum C D ≅ inclLeft C D := Functor.inlCompSum' _ _
/-- Characterization of `fromSum` with respect to the right inclusion. -/
@[simps! hom_app inv_app]
def inrCompFromSum : Sum.inr_ C D ⋙ fromSum C D ≅ inclRight C D := Functor.inrCompSum' _ _
instance : (fromSum C D).EssSurj where
mem_essImage
| left c => Functor.obj_mem_essImage _ (Sum.inl c)
| right d => Functor.obj_mem_essImage _ (Sum.inr d)
instance : (fromSum C D).Faithful where
map_injective {x y} h h' heq := by
cases h <;> cases h'
all_goals
simp only [fromSum_obj, Sum.inl__obj, fromSum_map_inl, Sum.inr__obj, fromSum_map_inr] at heq
simp [Functor.map_injective _ heq]
end CategoryTheory.Join |
.lake/packages/mathlib/Mathlib/CategoryTheory/Join/Pseudofunctor.lean | import Mathlib.CategoryTheory.Join.Basic
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor
/-!
# Pseudofunctoriality of categorical joins
In this file, we promote the join construction to two pseudofunctors
`Join.pseudofunctorLeft` and `Join.pseudofunctorRight`, expressing its pseudofunctoriality in
each variable.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory.Join
open Bicategory Functor
-- The proof gets too slow if we put it in a single `pseudofunctor` constructor,
-- so we break down the component proofs for the pseudofunctors over several lemmas.
section
variable {A B C D : Type*} [Category A] [Category B] [Category C] [Category D]
variable (A) in
/-- The structural isomorphism for composition of `pseudofunctorRight`. -/
def mapCompRight (F : B ⥤ C) (G : C ⥤ D) :
mapPair (𝟭 A) (F ⋙ G) ≅ mapPair (𝟭 A) F ⋙ mapPair (𝟭 A) G :=
mapIsoWhiskerRight (Functor.leftUnitor _).symm _ ≪≫ mapPairComp (𝟭 A) F (𝟭 A) G
variable (D) in
/-- The structural isomorphism for composition of `pseudofunctorLeft`. -/
def mapCompLeft (F : A ⥤ B) (G : B ⥤ C) :
mapPair (F ⋙ G) (𝟭 D) ≅ mapPair F (𝟭 D) ⋙ mapPair G (𝟭 D) :=
mapIsoWhiskerLeft _ (Functor.leftUnitor _).symm ≪≫ mapPairComp F (𝟭 D) G (𝟭 D)
variable (A) in
@[reassoc]
lemma mapWhiskerLeft_whiskerLeft (F : B ⥤ C) {G H : C ⥤ D} (η : G ⟶ H) :
mapWhiskerLeft _ (whiskerLeft F η) =
(mapCompRight A F G).hom ≫ whiskerLeft (mapPair (𝟭 A) F) (mapWhiskerLeft _ η) ≫
(mapCompRight A F H).inv := by
apply natTrans_ext <;> ext <;> simp [mapCompRight]
variable (D) in
@[reassoc]
lemma mapWhiskerRight_whiskerLeft (F : A ⥤ B) {G H : B ⥤ C} (η : G ⟶ H) :
mapWhiskerRight (whiskerLeft F η) (𝟭 D) =
(mapCompLeft D F G).hom ≫ whiskerLeft (mapPair F (𝟭 D)) (mapWhiskerRight η _) ≫
(mapCompLeft D F H).inv := by
apply natTrans_ext <;> ext <;> simp [mapCompLeft]
variable (A) in
@[reassoc]
lemma mapWhiskerLeft_whiskerRight {F G : B ⥤ C} (η : F ⟶ G) (H : C ⥤ D) :
mapWhiskerLeft _ (whiskerRight η H) =
(mapCompRight A F H).hom ≫ whiskerRight (mapWhiskerLeft _ η) (mapPair (𝟭 A) H) ≫
(mapCompRight A G H).inv := by
apply natTrans_ext <;> ext <;> simp [mapCompRight]
variable (D) in
@[reassoc]
lemma mapWhiskerRight_whiskerRight {F G : A ⥤ B} (η : F ⟶ G) (H : B ⥤ C) :
mapWhiskerRight (whiskerRight η H) _ =
(mapCompLeft D F H).hom ≫ whiskerRight (mapWhiskerRight η _) (mapPair H (𝟭 D)) ≫
(mapCompLeft D G H).inv := by
apply natTrans_ext <;> ext <;> simp [mapCompLeft]
variable {E : Type*} [Category E]
variable (A) in
@[reassoc]
lemma mapWhiskerLeft_associator_hom (F : B ⥤ C) (G : C ⥤ D) (H : D ⥤ E) :
mapWhiskerLeft _ (F.associator G H).hom =
(mapCompRight A (F ⋙ G) H).hom ≫ whiskerRight (mapCompRight A F G).hom (mapPair (𝟭 A) H) ≫
((mapPair (𝟭 A) F).associator (mapPair (𝟭 A) G) (mapPair (𝟭 A) H)).hom ≫
whiskerLeft (mapPair (𝟭 A) F) (mapCompRight A G H).inv ≫ (mapCompRight A F (G ⋙ H)).inv := by
apply natTrans_ext <;> ext <;> simp [mapCompRight]
variable (E) in
lemma mapWhiskerRight_associator_hom (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) :
mapWhiskerRight (F.associator G H).hom _ =
(mapCompLeft E (F ⋙ G) H).hom ≫ whiskerRight (mapCompLeft E F G).hom (mapPair H (𝟭 E)) ≫
((mapPair F (𝟭 E)).associator (mapPair G (𝟭 E)) (mapPair H (𝟭 E))).hom ≫
whiskerLeft (mapPair F (𝟭 E)) (mapCompLeft E G H).inv ≫ (mapCompLeft E F (G ⋙ H)).inv := by
apply natTrans_ext <;> ext <;> simp [mapCompLeft]
variable (A) in
lemma mapWhiskerLeft_leftUnitor_hom (F : B ⥤ C) :
mapWhiskerLeft _ F.leftUnitor.hom =
(mapCompRight A (𝟭 _) F).hom ≫ whiskerRight mapPairId.hom (mapPair _ F) ≫
(mapPair _ F).leftUnitor.hom := by
apply natTrans_ext <;> ext <;> simp [mapCompRight]
variable (C) in
lemma mapWhiskerRight_leftUnitor_hom (F : A ⥤ B) :
mapWhiskerRight F.leftUnitor.hom (𝟭 C) =
(mapCompLeft C (𝟭 A) F).hom ≫ whiskerRight mapPairId.hom (mapPair F (𝟭 C)) ≫
(mapPair F (𝟭 C)).leftUnitor.hom := by
apply natTrans_ext <;> ext <;> simp [mapCompLeft]
variable (A) in
lemma mapWhiskerLeft_rightUnitor_hom (F : B ⥤ C) :
mapWhiskerLeft _ F.rightUnitor.hom =
(mapCompRight A F (𝟭 C)).hom ≫ whiskerLeft (mapPair _ F) mapPairId.hom ≫
(mapPair (𝟭 A) _).rightUnitor.hom := by
apply natTrans_ext <;> ext <;> simp [mapCompRight]
variable (C) in
lemma mapWhiskerRight_rightUnitor_hom (F : A ⥤ B) :
mapWhiskerRight F.rightUnitor.hom _ =
(mapCompLeft C F (𝟭 B)).hom ≫ whiskerLeft (mapPair F _) mapPairId.hom ≫
(mapPair _ (𝟭 C)).rightUnitor.hom := by
apply natTrans_ext <;> ext <;> simp [mapCompLeft]
end
/-- The pseudofunctor sending `D` to `C ⋆ D`. -/
@[simps!]
def pseudofunctorRight (C : Type u₁) [Category.{v₁} C] :
Pseudofunctor Cat.{v₂, u₂} Cat.{max v₁ v₂, max u₁ u₂} where
obj D := Cat.of (C ⋆ D)
map F := mapPair (𝟭 C) F
map₂ := mapWhiskerLeft _
map₂_id {x y} f := by apply mapWhiskerLeft_id
map₂_comp η θ := by apply mapWhiskerLeft_comp
mapId D := mapPairId
mapComp := mapCompRight C
map₂_whisker_left := mapWhiskerLeft_whiskerLeft C
map₂_whisker_right := mapWhiskerLeft_whiskerRight C
map₂_associator := mapWhiskerLeft_associator_hom C
map₂_left_unitor := mapWhiskerLeft_leftUnitor_hom C
map₂_right_unitor := mapWhiskerLeft_rightUnitor_hom C
/-- The pseudofunctor sending `C` to `C ⋆ D`. -/
@[simps!]
def pseudofunctorLeft (D : Type u₂) [Category.{v₂} D] :
Pseudofunctor Cat.{v₁, u₁} Cat.{max v₁ v₂, max u₁ u₂} where
obj C := Cat.of (C ⋆ D)
map F := mapPair F (𝟭 D)
map₂ := (mapWhiskerRight · _)
map₂_id {x y} f := by apply mapWhiskerRight_id
map₂_comp η θ := by apply mapWhiskerRight_comp
mapId D := mapPairId
mapComp := mapCompLeft D
map₂_whisker_left := mapWhiskerRight_whiskerLeft D
map₂_whisker_right := mapWhiskerRight_whiskerRight D
map₂_associator := mapWhiskerRight_associator_hom D
map₂_left_unitor := mapWhiskerRight_leftUnitor_hom D
map₂_right_unitor := mapWhiskerRight_rightUnitor_hom D
end CategoryTheory.Join |
.lake/packages/mathlib/Mathlib/CategoryTheory/Join/Final.lean | import Mathlib.CategoryTheory.Join.Basic
import Mathlib.CategoryTheory.Limits.Final
import Mathlib.CategoryTheory.Limits.IsConnected
/-!
# (Co)Finality of the inclusions in joins of categories
This file records the fact that `inclLeft C D : C ⥤ C ⋆ D` is initial if `C` is connected.
Dually, `inclRight : C ⥤ C ⋆ D` is final if `D` is connected.
-/
namespace CategoryTheory.Join
variable (C D : Type*) [Category C] [Category D]
/-- The category of `Join.inclLeft C D`-costructured arrows with target `right d` is equivalent to
`C`. -/
def costructuredArrowEquiv (d : D) : CostructuredArrow (inclLeft C D) (right d) ≌ C where
functor := CostructuredArrow.proj (inclLeft C D) (right d)
inverse :=
{ obj c := .mk (edge c d)
map f := CostructuredArrow.homMk f }
unitIso := NatIso.ofComponents (fun _ ↦ CostructuredArrow.isoMk (Iso.refl _))
counitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _)
/-- The category of `Join.inclRight C D`-structured arrows with source `left c` is equivalent to
`D`. -/
def structuredArrowEquiv (c : C) : StructuredArrow (left c) (inclRight C D) ≌ D where
functor := StructuredArrow.proj (left c) (inclRight C D)
inverse :=
{ obj d := .mk (edge c d)
map f := StructuredArrow.homMk f }
unitIso := NatIso.ofComponents (fun _ ↦ StructuredArrow.isoMk (Iso.refl _))
counitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _)
instance [IsConnected C] : (inclLeft C D).Initial where
out x := match x with
|.left _ => isConnected_of_isTerminal _ CostructuredArrow.mkIdTerminal
|.right d => isConnected_of_equivalent (costructuredArrowEquiv C D d).symm
instance [IsConnected D] : (inclRight C D).Final where
out x := match x with
|.left c => isConnected_of_equivalent (structuredArrowEquiv C D c).symm
|.right _ => isConnected_of_isInitial _ (StructuredArrow.mkIdInitial (T := inclRight C D))
end CategoryTheory.Join |
.lake/packages/mathlib/Mathlib/CategoryTheory/Join/Basic.lean | import Mathlib.CategoryTheory.Functor.Category
import Mathlib.CategoryTheory.Products.Basic
/-!
# Joins of categories
Given categories `C, D`, this file constructs a category `C ⋆ D`. Its objects are either
objects of `C` or objects of `D`, morphisms between objects of `C` are morphisms in `C`,
morphisms between objects of `D` are morphisms in `D`, and finally, given `c : C` and `d : D`,
there is a unique morphism `c ⟶ d` in `C ⋆ D`.
## Main constructions
* `Join.edge c d`: the unique map from `c` to `d`.
* `Join.inclLeft : C ⥤ C ⋆ D`, the left inclusion. Its action on morphisms is the main entry point
to construct maps in `C ⋆ D` between objects coming from `C`.
* `Join.inclRight : D ⥤ C ⋆ D`, the right inclusion. Its action on morphisms is the main entry point
to construct maps in `C ⋆ D` between objects coming from `D`.
* `Join.mkFunctor`, A constructor for functors out of a join of categories.
* `Join.mkNatTrans`, A constructor for natural transformations between functors out of a join
of categories.
* `Join.mkNatIso`, A constructor for natural isomorphisms between functors out of a join
of categories.
## References
* [Kerodon: section 1.4.3.2](https://kerodon.net/tag/0160)
-/
universe v₁ v₂ v₃ v₄ v₅ v₆ u₁ u₂ u₃ u₄ u₅ u₆
namespace CategoryTheory
open Functor
/-- Elements of `Join C D` are either elements of `C` or elements of `D`. -/
-- Impl. : We are not defining it as a type alias for `C ⊕ D` so that we can have
-- aesop to call cases on `Join C D`
inductive Join (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D] : Type (max u₁ u₂)
| left : C → Join C D
| right : D → Join C D
attribute [aesop safe cases (rule_sets := [CategoryTheory])] Join
namespace Join
@[inherit_doc] scoped infixr:30 " ⋆ " => Join
variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D]
section CategoryStructure
variable {C D}
/-- Morphisms in `C ⋆ D` are those of `C` and `D`, plus a unique
morphism `(left c ⟶ right d)` for every `c : C` and `d : D`. -/
def Hom : C ⋆ D → C ⋆ D → Type (max v₁ v₂)
| .left x, .left y => ULift (x ⟶ y)
| .right x, .right y => ULift (x ⟶ y)
| .left _, .right _ => PUnit
| .right _, .left _ => PEmpty
/-- Identity morphisms in `C ⋆ D` are inherited from those in `C` and `D`. -/
def id : ∀ X : C ⋆ D, Hom X X
| .left x => ULift.up (𝟙 x)
| .right x => ULift.up (𝟙 x)
/-- Composition in `C ⋆ D` is inherited from the compositions in `C` and `D`. -/
def comp : ∀ {x y z : C ⋆ D}, Hom x y → Hom y z → Hom x z
| .left _x, .left _y, .left _z, f, g => ULift.up (ULift.down f ≫ ULift.down g)
| .left _x, .left _y, .right _z, _, _ => PUnit.unit
| .left _x, .right _y, .right _z, _, _ => PUnit.unit
| .right _x, .right _y, .right _z, f, g => ULift.up (ULift.down f ≫ ULift.down g)
instance : Category.{max v₁ v₂} (C ⋆ D) where
Hom X Y := Hom X Y
id _ := id _
comp := comp
assoc {a b c d} f g h := by
cases a <;>
cases b <;>
cases c <;>
cases d <;>
simp only [Hom, comp, Category.assoc] <;>
tauto
id_comp {x y} f := by
cases x <;> cases y <;> simp only [Hom, id, comp, Category.id_comp] <;> tauto
comp_id {x y} f := by
cases x <;> cases y <;> simp only [Hom, id, comp, Category.comp_id] <;> tauto
@[aesop safe destruct (rule_sets := [CategoryTheory])]
lemma false_of_right_to_left {X : D} {Y : C} (f : right X ⟶ left Y) : False := (f : PEmpty).elim
instance {X : C} {Y : D} : Unique (left X ⟶ right Y) := inferInstanceAs (Unique PUnit)
/-- Join.edge c d is the unique morphism from c to d. -/
def edge (c : C) (d : D) : left c ⟶ right d := default
end CategoryStructure
section Inclusions
/-- The canonical inclusion from C to `C ⋆ D`.
Terms of the form `(inclLeft C D).map f` should be treated as primitive when working with joins
and one should avoid trying to reduce them. For this reason, there is no `inclLeft_map` simp
lemma. -/
@[simps! obj]
def inclLeft : C ⥤ C ⋆ D where
obj := left
map := ULift.up
/-- The canonical inclusion from D to `C ⋆ D`.
Terms of the form `(inclRight C D).map f` should be treated as primitive when working with joins
and one should avoid trying to reduce them. For this reason, there is no `inclRight_map` simp
lemma. -/
@[simps! obj]
def inclRight : D ⥤ C ⋆ D where
obj := right
map := ULift.up
variable {C D}
/-- An induction principle for morphisms in a join of categories: a morphism is either of the form
`(inclLeft _ _).map _`, `(inclRight _ _).map _`, or is `edge _ _`. -/
@[elab_as_elim, cases_eliminator, induction_eliminator]
def homInduction {P : {x y : C ⋆ D} → (x ⟶ y) → Sort*}
(left : ∀ x y : C, (f : x ⟶ y) → P ((inclLeft C D).map f))
(right : ∀ x y : D, (f : x ⟶ y) → P ((inclRight C D).map f))
(edge : ∀ (c : C) (d : D), P (edge c d))
{x y : C ⋆ D} (f : x ⟶ y) : P f :=
match x, y, f with
| .left x, .left y, .up f => left x y f
| .right x, .right y, .up f => right x y f
| .left x, .right y, _ => edge x y
@[simp]
lemma homInduction_left {P : {x y : C ⋆ D} → (x ⟶ y) → Sort*}
(left : ∀ x y : C, (f : x ⟶ y) → P ((inclLeft C D).map f))
(right : ∀ x y : D, (f : x ⟶ y) → P ((inclRight C D).map f))
(edge : ∀ (c : C) (d : D), P (edge c d))
{x y : C} (f : x ⟶ y) : homInduction left right edge ((inclLeft C D).map f) = left x y f :=
rfl
@[simp]
lemma homInduction_right {P : {x y : C ⋆ D} → (x ⟶ y) → Sort*}
(left : ∀ x y : C, (f : x ⟶ y) → P ((inclLeft C D).map f))
(right : ∀ x y : D, (f : x ⟶ y) → P ((inclRight C D).map f))
(edge : ∀ (c : C) (d : D), P (edge c d))
{x y : D} (f : x ⟶ y) : homInduction left right edge ((inclRight C D).map f) = right x y f :=
rfl
@[simp]
lemma homInduction_edge {P : {x y : C ⋆ D} → (x ⟶ y) → Sort*}
(left : ∀ x y : C, (f : x ⟶ y) → P ((inclLeft C D).map f))
(right : ∀ x y : D, (f : x ⟶ y) → P ((inclRight C D).map f))
(edge : ∀ (c : C) (d : D), P (edge c d))
{c : C} {d : D} : homInduction left right edge (Join.edge c d) = edge c d :=
rfl
variable (C D)
/-- The left inclusion is fully faithful. -/
def inclLeftFullyFaithful : (inclLeft C D).FullyFaithful where
preimage f := f.down
/-- The right inclusion is fully faithful. -/
def inclRightFullyFaithful : (inclRight C D).FullyFaithful where
preimage f := f.down
instance inclLeftFull : (inclLeft C D).Full := inclLeftFullyFaithful C D |>.full
instance inclRightFull : (inclRight C D).Full := inclRightFullyFaithful C D |>.full
instance inclLeftFaithful : (inclLeft C D).Faithful := inclLeftFullyFaithful C D |>.faithful
instance inclRightFaithful : (inclRight C D).Faithful := inclRightFullyFaithful C D |>.faithful
variable {C} in
/-- A situational lemma to help putting identities in the form `(inclLeft _ _).map _` when using
`homInduction`. -/
lemma id_left (c : C) : 𝟙 (left c) = (inclLeft C D).map (𝟙 c) := rfl
variable {D} in
/-- A situational lemma to help putting identities in the form `(inclRight _ _).map _` when using
`homInduction`. -/
lemma id_right (d : D) : 𝟙 (right d) = (inclRight C D).map (𝟙 d) := rfl
/-- The "canonical" natural transformation from `(Prod.fst C D) ⋙ inclLeft C D` to
`(Prod.snd C D) ⋙ inclRight C D`. This is bundling together all the edge morphisms
into the data of a natural transformation. -/
@[simps!]
def edgeTransform :
Prod.fst C D ⋙ inclLeft C D ⟶ Prod.snd C D ⋙ inclRight C D where
app := fun (c, d) ↦ edge c d
end Inclusions
section Functoriality
variable {C D} {E : Type u₃} [Category.{v₃} E] {E' : Type u₄} [Category.{v₄} E']
/-- A pair of functors `F : C ⥤ E, G : D ⥤ E` as well as a natural transformation
`α : (Prod.fst C D) ⋙ F ⟶ (Prod.snd C D) ⋙ G` defines a functor out of `C ⋆ D`.
This is the main entry point to define functors out of a join of categories. -/
def mkFunctor (F : C ⥤ E) (G : D ⥤ E) (α : Prod.fst C D ⋙ F ⟶ Prod.snd C D ⋙ G) :
C ⋆ D ⥤ E where
obj X :=
match X with
| .left x => F.obj x
| .right x => G.obj x
map f :=
homInduction
(left := fun _ _ f ↦ F.map f)
(right := fun _ _ g ↦ G.map g)
(edge := fun c d ↦ α.app (c,d))
f
map_id x := by
cases x
· dsimp only [id_left, homInduction_left]
simp
· dsimp only [id_right, homInduction_right]
simp
map_comp {x y z} f g := by
cases f <;> cases g
· simp [← Functor.map_comp]
· case left.edge f d => simpa using (α.naturality <| (Prod.sectL _ d).map f).symm
· simp [← Functor.map_comp]
· case edge.right c _ _ f => simpa using α.naturality <| (Prod.sectR c _).map f
section
variable (F : C ⥤ E) (G : D ⥤ E) (α : Prod.fst C D ⋙ F ⟶ Prod.snd C D ⋙ G)
-- As these equalities of objects are definitional, they should be fine.
@[simp]
lemma mkFunctor_obj_left (c : C) : (mkFunctor F G α).obj (left c) = F.obj c := rfl
@[simp]
lemma mkFunctor_obj_right (d : D) : (mkFunctor F G α).obj (right d) = G.obj d := rfl
@[simp]
lemma mkFunctor_map_inclLeft {c c' : C} (f : c ⟶ c') :
(mkFunctor F G α).map ((inclLeft C D).map f) = F.map f :=
rfl
/-- Precomposing `mkFunctor F G α` with the left inclusion gives back `F`. -/
@[simps!]
def mkFunctorLeft : inclLeft C D ⋙ mkFunctor F G α ≅ F := Iso.refl _
/-- Precomposing `mkFunctor F G α` with the right inclusion gives back `G`. -/
@[simps!]
def mkFunctorRight : inclRight C D ⋙ mkFunctor F G α ≅ G := Iso.refl _
@[simp]
lemma mkFunctor_map_inclRight {d d' : D} (f : d ⟶ d') :
(mkFunctor F G α).map ((inclRight C D).map f) = G.map f :=
rfl
/-- Whiskering `mkFunctor F G α` with the universal transformation gives back `α`. -/
@[simp]
lemma mkFunctor_edgeTransform :
whiskerRight (edgeTransform C D) (mkFunctor F G α) = α := by
ext x
simp [mkFunctor]
@[simp]
lemma mkFunctor_map_edge (c : C) (d : D) :
(mkFunctor F G α).map (edge c d) = α.app (c, d) :=
rfl
end
/-- Construct a natural transformation between functors out of a join from
the data of natural transformations between each side that are compatible with the
action on edge maps. -/
def mkNatTrans {F : C ⋆ D ⥤ E} {F' : C ⋆ D ⥤ E}
(αₗ : inclLeft C D ⋙ F ⟶ inclLeft C D ⋙ F') (αᵣ : inclRight C D ⋙ F ⟶ inclRight C D ⋙ F')
(h : whiskerRight (edgeTransform C D) F ≫ whiskerLeft (Prod.snd C D) αᵣ =
whiskerLeft (Prod.fst C D) αₗ ≫ whiskerRight (edgeTransform C D) F' :=
by cat_disch) :
F ⟶ F' where
app x := match x with
| left x => αₗ.app x
| right x => αᵣ.app x
naturality {x y} f := by
cases f with
| @left x y f => simpa using αₗ.naturality f
| @right x y f => simpa using αᵣ.naturality f
| @edge c d => exact funext_iff.mp (NatTrans.ext_iff.mp h) (c, d)
section
variable {F : C ⋆ D ⥤ E} {F' : C ⋆ D ⥤ E}
(αₗ : inclLeft C D ⋙ F ⟶ inclLeft C D ⋙ F') (αᵣ : inclRight C D ⋙ F ⟶ inclRight C D ⋙ F')
(h : whiskerRight (edgeTransform C D) F ≫ whiskerLeft (Prod.snd C D) αᵣ =
whiskerLeft (Prod.fst C D) αₗ ≫ whiskerRight (edgeTransform C D) F' :=
by cat_disch)
@[simp]
lemma mkNatTrans_app_left (c : C) : (mkNatTrans αₗ αᵣ h).app (left c) = αₗ.app c := rfl
@[simp]
lemma mkNatTrans_app_right (d : D) : (mkNatTrans αₗ αᵣ h).app (right d) = αᵣ.app d := rfl
@[simp]
lemma whiskerLeft_inclLeft_mkNatTrans : whiskerLeft (inclLeft C D) (mkNatTrans αₗ αᵣ h) = αₗ := rfl
@[simp]
lemma whiskerLeft_inclRight_mkNatTrans :
whiskerLeft (inclRight C D) (mkNatTrans αₗ αᵣ h) = αᵣ := rfl
end
/-- Two natural transformations between functors out of a join are equal if they are so
after whiskering with the inclusions. -/
lemma natTrans_ext {F F' : C ⋆ D ⥤ E} {α β : F ⟶ F'}
(h₁ : whiskerLeft (inclLeft C D) α = whiskerLeft (inclLeft C D) β)
(h₂ : whiskerLeft (inclRight C D) α = whiskerLeft (inclRight C D) β) :
α = β := by
ext t
cases t with
| left t => exact congrArg (fun x ↦ x.app t) h₁
| right t => exact congrArg (fun x ↦ x.app t) h₂
lemma eq_mkNatTrans {F F' : C ⋆ D ⥤ E} (α : F ⟶ F') :
mkNatTrans (whiskerLeft (inclLeft C D) α) (whiskerLeft (inclRight C D) α) = α := by
apply natTrans_ext <;> simp
section
/-- `mkNatTrans` respects vertical composition. -/
lemma mkNatTransComp
{F F' F'' : C ⋆ D ⥤ E}
(αₗ : inclLeft C D ⋙ F ⟶ inclLeft C D ⋙ F')
(αᵣ : inclRight C D ⋙ F ⟶ inclRight C D ⋙ F')
(βₗ : inclLeft C D ⋙ F' ⟶ inclLeft C D ⋙ F'')
(βᵣ : inclRight C D ⋙ F' ⟶ inclRight C D ⋙ F'')
(h : whiskerRight (edgeTransform C D) F ≫ whiskerLeft (Prod.snd C D) αᵣ =
whiskerLeft (Prod.fst C D) αₗ ≫ whiskerRight (edgeTransform C D) F' :=
by cat_disch)
(h' : whiskerRight (edgeTransform C D) F' ≫ whiskerLeft (Prod.snd C D) βᵣ =
whiskerLeft (Prod.fst C D) βₗ ≫ whiskerRight (edgeTransform C D) F'' := by cat_disch) :
mkNatTrans (αₗ ≫ βₗ) (αᵣ ≫ βᵣ) (by simp [← h', reassoc_of% h]) =
mkNatTrans αₗ αᵣ h ≫ mkNatTrans βₗ βᵣ h' := by
apply natTrans_ext <;> cat_disch
end
/-- Two functors out of a join of categories are naturally isomorphic if their
compositions with the inclusions are isomorphic and the whiskering with the canonical
transformation is respected through these isomorphisms. -/
@[simps]
def mkNatIso {F : C ⋆ D ⥤ E} {G : C ⋆ D ⥤ E}
(eₗ : inclLeft C D ⋙ F ≅ inclLeft C D ⋙ G)
(eᵣ : inclRight C D ⋙ F ≅ inclRight C D ⋙ G)
(h : whiskerRight (edgeTransform C D) F ≫ (isoWhiskerLeft (Prod.snd C D) eᵣ).hom =
(isoWhiskerLeft (Prod.fst C D) eₗ).hom ≫ whiskerRight (edgeTransform C D) G := by cat_disch) :
F ≅ G where
hom := mkNatTrans eₗ.hom eᵣ.hom (by simpa using h)
inv := mkNatTrans eₗ.inv eᵣ.inv (by rw [Eq.comm, ← isoWhiskerLeft_inv, ← isoWhiskerLeft_inv,
Iso.inv_comp_eq, ← Category.assoc, Eq.comm, Iso.comp_inv_eq, h])
/-- A pair of functors ((C ⥤ E), (D ⥤ E')) induces a functor `C ⋆ D ⥤ E ⋆ E'`. -/
def mapPair (Fₗ : C ⥤ E) (Fᵣ : D ⥤ E') : C ⋆ D ⥤ E ⋆ E' :=
mkFunctor (Fₗ ⋙ inclLeft _ _) (Fᵣ ⋙ inclRight _ _) { app := fun _ ↦ edge _ _ }
section mapPair
variable (Fₗ : C ⥤ E) (Fᵣ : D ⥤ E')
@[simp]
lemma mapPair_obj_left (c : C) : (mapPair Fₗ Fᵣ).obj (left c) = left (Fₗ.obj c) := rfl
@[simp]
lemma mapPair_obj_right (d : D) : (mapPair Fₗ Fᵣ).obj (right d) = right (Fᵣ.obj d) := rfl
@[simp]
lemma mapPair_map_inclLeft {c c' : C} (f : c ⟶ c') :
(mapPair Fₗ Fᵣ).map ((inclLeft C D).map f) = (inclLeft E E').map (Fₗ.map f) := rfl
@[simp]
lemma mapPair_map_inclRight {d d' : D} (f : d ⟶ d') :
(mapPair Fₗ Fᵣ).map ((inclRight C D).map f) = (inclRight E E').map (Fᵣ.map f) := rfl
/-- Characterizing `mapPair` on left morphisms. -/
@[simps! hom_app inv_app]
def mapPairLeft : inclLeft _ _ ⋙ mapPair Fₗ Fᵣ ≅ Fₗ ⋙ inclLeft _ _ := mkFunctorLeft _ _ _
/-- Characterizing `mapPair` on right morphisms. -/
@[simps! hom_app inv_app]
def mapPairRight : inclRight _ _ ⋙ mapPair Fₗ Fᵣ ≅ Fᵣ ⋙ inclRight _ _ := mkFunctorRight _ _ _
end mapPair
/-- Any functor out of a join is naturally isomorphic to a functor of the form `mkFunctor F G α`. -/
@[simps!]
def isoMkFunctor (F : C ⋆ D ⥤ E) :
F ≅ mkFunctor (inclLeft C D ⋙ F) (inclRight C D ⋙ F) (whiskerRight (edgeTransform C D) F) :=
mkNatIso (mkFunctorLeft _ _ _).symm (mkFunctorRight _ _ _).symm
/-- `mapPair` respects identities -/
@[simps!]
def mapPairId : mapPair (𝟭 C) (𝟭 D) ≅ 𝟭 (C ⋆ D) :=
mkNatIso
(mapPairLeft _ _ ≪≫ Functor.leftUnitor _ ≪≫ (Functor.rightUnitor _).symm)
(mapPairRight _ _ ≪≫ Functor.leftUnitor _ ≪≫ (Functor.rightUnitor _).symm)
variable {J : Type u₅} [Category.{v₅} J]
{K : Type u₆} [Category.{v₆} K]
-- @[simps!] times out here
/-- `mapPair` respects composition -/
def mapPairComp (Fₗ : C ⥤ E) (Fᵣ : D ⥤ E') (Gₗ : E ⥤ J) (Gᵣ : E' ⥤ K) :
mapPair (Fₗ ⋙ Gₗ) (Fᵣ ⋙ Gᵣ) ≅ mapPair Fₗ Fᵣ ⋙ mapPair Gₗ Gᵣ :=
mkNatIso
(mapPairLeft (Fₗ ⋙ Gₗ) (Fᵣ ⋙ Gᵣ) ≪≫
Functor.associator Fₗ Gₗ (inclLeft J K) ≪≫
(isoWhiskerLeft Fₗ (mapPairLeft Gₗ Gᵣ).symm) ≪≫
(Functor.associator Fₗ (inclLeft E E') (mapPair Gₗ Gᵣ)).symm ≪≫
isoWhiskerRight (mapPairLeft Fₗ Fᵣ).symm (mapPair Gₗ Gᵣ))
(mapPairRight (Fₗ ⋙ Gₗ) (Fᵣ ⋙ Gᵣ) ≪≫
Functor.associator Fᵣ Gᵣ (inclRight J K) ≪≫
(isoWhiskerLeft Fᵣ (mapPairRight Gₗ Gᵣ).symm) ≪≫
(Functor.associator Fᵣ (inclRight E E') (mapPair Gₗ Gᵣ)).symm ≪≫
isoWhiskerRight (mapPairRight Fₗ Fᵣ).symm (mapPair Gₗ Gᵣ))
section mapPairComp
variable (Fₗ : C ⥤ E) (Fᵣ : D ⥤ E') (Gₗ : E ⥤ J) (Gᵣ : E' ⥤ K)
@[simp]
lemma mapPairComp_hom_app_left (c : C) :
(mapPairComp Fₗ Fᵣ Gₗ Gᵣ).hom.app (left c) = 𝟙 (left (Gₗ.obj (Fₗ.obj c))) := by
dsimp [mapPairComp]
simp
@[simp]
lemma mapPairComp_hom_app_right (d : D) :
(mapPairComp Fₗ Fᵣ Gₗ Gᵣ).hom.app (right d) = 𝟙 (right (Gᵣ.obj (Fᵣ.obj d))) := by
dsimp [mapPairComp]
simp
@[simp]
lemma mapPairComp_inv_app_left (c : C) :
(mapPairComp Fₗ Fᵣ Gₗ Gᵣ).inv.app (left c) = 𝟙 (left (Gₗ.obj (Fₗ.obj c))) := by
dsimp [mapPairComp]
simp
@[simp]
lemma mapPairComp_inv_app_right (d : D) :
(mapPairComp Fₗ Fᵣ Gₗ Gᵣ).inv.app (right d) = 𝟙 (right (Gᵣ.obj (Fᵣ.obj d))) := by
dsimp [mapPairComp]
simp
end mapPairComp
end Functoriality
section NaturalTransforms
variable {E : Type u₃} [Category.{v₃} E]
{E' : Type u₄} [Category.{v₄} E']
variable {C D}
/-- A natural transformation `Fₗ ⟶ Gₗ` induces a natural transformation
`mapPair Fₗ H ⟶ mapPair Gₗ H` for every `H : D ⥤ E'`. -/
@[simps!]
def mapWhiskerRight {Fₗ : C ⥤ E} {Gₗ : C ⥤ E} (α : Fₗ ⟶ Gₗ) (H : D ⥤ E') :
mapPair Fₗ H ⟶ mapPair Gₗ H :=
mkNatTrans
((mapPairLeft Fₗ H).hom ≫ whiskerRight α (inclLeft E E') ≫ (mapPairLeft Gₗ H).inv)
((mapPairRight Fₗ H).hom ≫ whiskerRight (𝟙 H) (inclRight E E') ≫ (mapPairRight Gₗ H).inv)
@[simp]
lemma mapWhiskerRight_comp {Fₗ : C ⥤ E} {Gₗ : C ⥤ E} {Hₗ : C ⥤ E}
(α : Fₗ ⟶ Gₗ) (β : Gₗ ⟶ Hₗ) (H : D ⥤ E') :
mapWhiskerRight (α ≫ β) H = mapWhiskerRight α H ≫ mapWhiskerRight β H := by
cat_disch
@[simp]
lemma mapWhiskerRight_id (Fₗ : C ⥤ E) (H : D ⥤ E') :
mapWhiskerRight (𝟙 Fₗ) H = 𝟙 _ := by
cat_disch
/-- A natural transformation `Fᵣ ⟶ Gᵣ` induces a natural transformation
`mapPair H Fᵣ ⟶ mapPair H Gᵣ` for every `H : C ⥤ E`. -/
@[simps!]
def mapWhiskerLeft (H : C ⥤ E) {Fᵣ : D ⥤ E'} {Gᵣ : D ⥤ E'} (α : Fᵣ ⟶ Gᵣ) :
mapPair H Fᵣ ⟶ mapPair H Gᵣ :=
mkNatTrans
((mapPairLeft H Fᵣ).hom ≫ whiskerRight (𝟙 H) (inclLeft E E') ≫ (mapPairLeft H Gᵣ).inv)
((mapPairRight H Fᵣ).hom ≫ whiskerRight α (inclRight E E') ≫ (mapPairRight H Gᵣ).inv)
@[simp]
lemma mapWhiskerLeft_comp {Fᵣ : D ⥤ E'} {Gᵣ : D ⥤ E'} {Hᵣ : D ⥤ E'}
(H : C ⥤ E) (α : Fᵣ ⟶ Gᵣ) (β : Gᵣ ⟶ Hᵣ) :
mapWhiskerLeft H (α ≫ β) = mapWhiskerLeft H α ≫ mapWhiskerLeft H β := by
cat_disch
@[simp]
lemma mapWhiskerLeft_id (H : C ⥤ E) (Fᵣ : D ⥤ E') :
mapWhiskerLeft H (𝟙 Fᵣ) = 𝟙 _ := by
cat_disch
/-- One can exchange `mapWhiskerLeft` and `mapWhiskerRight`. -/
lemma mapWhisker_exchange (Fₗ : C ⥤ E) (Gₗ : C ⥤ E) (Fᵣ : D ⥤ E') (Gᵣ : D ⥤ E')
(αₗ : Fₗ ⟶ Gₗ) (αᵣ : Fᵣ ⟶ Gᵣ) :
mapWhiskerLeft Fₗ αᵣ ≫ mapWhiskerRight αₗ Gᵣ =
mapWhiskerRight αₗ Fᵣ ≫ mapWhiskerLeft Gₗ αᵣ := by
ext
cat_disch
/-- A natural isomorphism `Fᵣ ≅ Gᵣ` induces a natural isomorphism
`mapPair H Fᵣ ≅ mapPair H Gᵣ` for every `H : C ⥤ E`. -/
@[simps!]
def mapIsoWhiskerLeft (H : C ⥤ E) {Fᵣ : D ⥤ E'} {Gᵣ : D ⥤ E'} (α : Fᵣ ≅ Gᵣ) :
mapPair H Fᵣ ≅ mapPair H Gᵣ :=
mkNatIso
(mapPairLeft H Fᵣ ≪≫ isoWhiskerRight (Iso.refl H) (inclLeft _ _) ≪≫ (mapPairLeft H Gᵣ).symm)
(mapPairRight H Fᵣ ≪≫ isoWhiskerRight α (inclRight E E') ≪≫ (mapPairRight H Gᵣ).symm)
/-- A natural isomorphism `Fᵣ ≅ Gᵣ` induces a natural isomorphism
`mapPair Fₗ H ≅ mapPair Gₗ H` for every `H : C ⥤ E`. -/
@[simps!]
def mapIsoWhiskerRight {Fₗ : C ⥤ E} {Gₗ : C ⥤ E} (α : Fₗ ≅ Gₗ) (H : D ⥤ E') :
mapPair Fₗ H ≅ mapPair Gₗ H :=
mkNatIso
(mapPairLeft Fₗ H ≪≫ isoWhiskerRight α (inclLeft E E') ≪≫ (mapPairLeft Gₗ H).symm)
(mapPairRight Fₗ H ≪≫ isoWhiskerRight (Iso.refl H) (inclRight E E') ≪≫ (mapPairRight Gₗ H).symm)
lemma mapIsoWhiskerRight_hom {Fₗ : C ⥤ E} {Gₗ : C ⥤ E} (α : Fₗ ≅ Gₗ) (H : D ⥤ E') :
(mapIsoWhiskerRight α H).hom = mapWhiskerRight α.hom H := rfl
lemma mapIsoWhiskerRight_inv {Fₗ : C ⥤ E} {Gₗ : C ⥤ E} (α : Fₗ ≅ Gₗ) (H : D ⥤ E') :
(mapIsoWhiskerRight α H).inv = mapWhiskerRight α.inv H := by
ext x
cases x <;> simp [mapIsoWhiskerRight]
lemma mapIsoWhiskerLeft_hom (H : C ⥤ E) {Fᵣ : D ⥤ E'} {Gᵣ : D ⥤ E'} (α : Fᵣ ≅ Gᵣ) :
(mapIsoWhiskerLeft H α).hom = mapWhiskerLeft H α.hom := rfl
lemma mapIsoWhiskerLeft_inv (H : C ⥤ E) {Fᵣ : D ⥤ E'} {Gᵣ : D ⥤ E'} (α : Fᵣ ≅ Gᵣ) :
(mapIsoWhiskerLeft H α).inv = mapWhiskerLeft H α.inv := by
ext x
cases x <;> simp [mapIsoWhiskerLeft]
end NaturalTransforms
section mapPairEquiv
variable {C' : Type u₃} [Category.{v₃} C']
{D' : Type u₄} [Category.{v₄} D']
variable {C D}
/-- Equivalent categories have equivalent joins. -/
@[simps]
def mapPairEquiv (e : C ≌ C') (e' : D ≌ D') : C ⋆ D ≌ C' ⋆ D' where
functor := mapPair e.functor e'.functor
inverse := mapPair e.inverse e'.inverse
unitIso :=
mapPairId.symm ≪≫
mapIsoWhiskerRight e.unitIso _ ≪≫
mapIsoWhiskerLeft _ e'.unitIso ≪≫
mapPairComp _ _ _ _
counitIso :=
(mapPairComp _ _ _ _).symm ≪≫
mapIsoWhiskerRight e.counitIso _ ≪≫
mapIsoWhiskerLeft _ e'.counitIso ≪≫
mapPairId
functor_unitIso_comp x := by
cases x <;>
simp [← (inclLeft C' D').map_comp, ← (inclRight C' D').map_comp]
instance isEquivalenceMapPair {F : C ⥤ C'} {F' : D ⥤ D'} [F.IsEquivalence] [F'.IsEquivalence] :
(mapPair F F').IsEquivalence :=
inferInstanceAs (mapPairEquiv F.asEquivalence F'.asEquivalence).functor.IsEquivalence
end mapPairEquiv
end Join
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Join/Opposites.lean | import Mathlib.CategoryTheory.Join.Basic
import Mathlib.CategoryTheory.Opposites
/-!
# Opposites of joins of categories
This file constructs the canonical equivalence of categories `(C ⋆ D)ᵒᵖ ≌ Dᵒᵖ ⋆ Cᵒᵖ`.
This equivalence is characterized in both directions.
-/
namespace CategoryTheory.Join
open Opposite Functor
universe v₁ v₂ u₁ u₂
variable (C : Type u₁) (D : Type u₂) [Category.{v₁} C] [Category.{v₂} D]
/-- The equivalence `(C ⋆ D)ᵒᵖ ≌ Dᵒᵖ ⋆ Cᵒᵖ` induced by `Join.opEquivFunctor` and
`Join.opEquivInverse`. -/
def opEquiv : (C ⋆ D)ᵒᵖ ≌ Dᵒᵖ ⋆ Cᵒᵖ where
functor := Functor.leftOp <|
Join.mkFunctor (inclRight _ _).rightOp (inclLeft _ _).rightOp {app _ := (edge _ _).op}
inverse := Join.mkFunctor (inclRight _ _).op (inclLeft _ _).op {app _ := (edge _ _).op}
unitIso := NatIso.ofComponents
(fun
| op (left _) => Iso.refl _
| op (right _) => Iso.refl _ )
(@fun
| op (left _), op (left _), _ => by cat_disch
| op (right _), op (left _), _ => by cat_disch
| op (right _), op (right _), _ => by cat_disch)
counitIso := NatIso.ofComponents
(fun
| left _ => Iso.refl _
| right _ => Iso.refl _)
functor_unitIso_comp
| op (left _) => by cat_disch
| op (right _) => by cat_disch
variable {C} in
@[simp]
lemma opEquiv_functor_obj_op_left (c : C) :
(opEquiv C D).functor.obj (op <| left c) = right (op c) :=
rfl
variable {D} in
@[simp]
lemma opEquiv_functor_obj_op_right (d : D) :
(opEquiv C D).functor.obj (op <| right d) = left (op d) :=
rfl
variable {C} in
@[simp]
lemma opEquiv_functor_map_op_inclLeft {c c' : C} (f : c ⟶ c') :
(opEquiv C D).functor.map (op <| (inclLeft C D).map f) = (inclRight _ _).map (op f) :=
rfl
variable {D} in
@[simp]
lemma opEquiv_functor_map_op_inclRight {d d' : D} (f : d ⟶ d') :
(opEquiv C D).functor.map (op <| (inclRight C D).map f) = (inclLeft _ _).map (op f) :=
rfl
variable {C D} in
lemma opEquiv_functor_map_op_edge (c : C) (d : D) :
(opEquiv C D).functor.map (op <| edge c d) = edge (op d) (op c) :=
rfl
/-- Characterize (up to a rightOp) the action of the left inclusion on `Join.opEquivFunctor`. -/
@[simps!]
def InclLeftCompRightOpOpEquivFunctor :
inclLeft C D ⋙ (opEquiv C D).functor.rightOp ≅ (inclRight _ _).rightOp :=
isoWhiskerLeft _ (leftOpRightOpIso _) ≪≫ mkFunctorLeft _ _ _
/-- Characterize (up to a rightOp) the action of the right inclusion on `Join.opEquivFunctor`. -/
@[simps!]
def InclRightCompRightOpOpEquivFunctor :
inclRight C D ⋙ (opEquiv C D).functor.rightOp ≅ (inclLeft _ _).rightOp :=
isoWhiskerLeft _ (leftOpRightOpIso _) ≪≫ mkFunctorRight _ _ _
variable {D} in
@[simp]
lemma opEquiv_inverse_obj_left_op (d : D) :
(opEquiv C D).inverse.obj (left <| op d) = op (right d) :=
rfl
variable {C} in
@[simp]
lemma opEquiv_inverse_obj_right_op (c : C) :
(opEquiv C D).inverse.obj (right <| op c) = op (left c) :=
rfl
variable {D} in
@[simp]
lemma opEquiv_inverse_map_inclLeft_op {d d' : D} (f : d ⟶ d') :
(opEquiv C D).inverse.map ((inclLeft Dᵒᵖ Cᵒᵖ).map f.op) = op ((inclRight _ _).map f) :=
rfl
variable {D} in
@[simp]
lemma opEquiv_inverse_map_inclRight_op {c c' : C} (f : c ⟶ c') :
(opEquiv C D).inverse.map ((inclRight Dᵒᵖ Cᵒᵖ).map f.op) = op ((inclLeft _ _).map f) :=
rfl
variable {C D} in
@[simp]
lemma opEquiv_inverse_map_edge_op (c : C) (d : D) :
(opEquiv C D).inverse.map (edge (op d) (op c)) = op (edge c d) :=
rfl
/-- Characterize `Join.opEquivInverse` with respect to the left inclusion -/
def inclLeftCompOpEquivInverse :
Join.inclLeft Dᵒᵖ Cᵒᵖ ⋙ (opEquiv C D).inverse ≅ (inclRight _ _).op :=
Join.mkFunctorLeft _ _ _
/-- Characterize `Join.opEquivInverse` with respect to the right inclusion -/
def inclRightCompOpEquivInverse :
Join.inclRight Dᵒᵖ Cᵒᵖ ⋙ (opEquiv C D).inverse ≅ (inclLeft _ _).op :=
Join.mkFunctorRight _ _ _
variable {D} in
@[simp]
lemma inclLeftCompOpEquivInverse_hom_app_op (d : D) :
(inclLeftCompOpEquivInverse C D).hom.app (op d) = 𝟙 (op <| right d) :=
rfl
variable {C} in
@[simp]
lemma inclRightCompOpEquivInverse_hom_app_op (c : C) :
(inclRightCompOpEquivInverse C D).hom.app (op c) = 𝟙 (op <| left c) :=
rfl
variable {D} in
@[simp]
lemma inclLeftCompOpEquivInverse_inv_app_op (d : D) :
(inclLeftCompOpEquivInverse C D).inv.app (op d) = 𝟙 (op <| right d) :=
rfl
variable {C} in
@[simp]
lemma inclRightCompOpEquivInverse_inv_app_op (c : C) :
(inclRightCompOpEquivInverse C D).inv.app (op c) = 𝟙 (op <| left c) :=
rfl
end CategoryTheory.Join |
.lake/packages/mathlib/Mathlib/CategoryTheory/CopyDiscardCategory/Deterministic.lean | import Mathlib.CategoryTheory.CopyDiscardCategory.Basic
/-!
# Deterministic Morphisms in Copy-Discard Categories
Morphisms that preserve the copy operation perfectly.
A morphism `f : X → Y` is deterministic if copying then applying `f` to both copies equals applying
`f` then copying: `f ≫ Δ[Y] = Δ[X] ≫ (f ⊗ f)`.
In probabilistic settings, these are morphisms without randomness. In cartesian categories, all
morphisms are deterministic.
## Main definitions
* `Deterministic` - Type class for morphisms that preserve copying
## Main results
* Identity morphisms are deterministic
* Composition of deterministic morphisms is deterministic
## Tags
deterministic, copy-discard category, comonoid morphism
-/
universe v u
namespace CategoryTheory
open MonoidalCategory ComonObj
variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] [CopyDiscardCategory.{v} C]
/-- A morphism is deterministic if it preserves the comonoid structure.
In probabilistic contexts, these are morphisms without randomness. -/
abbrev Deterministic {X Y : C} (f : X ⟶ Y) := IsComonHom f
namespace Deterministic
variable {X Y Z : C}
/-- Deterministic morphisms commute with copying. -/
lemma copy_natural (f : X ⟶ Y) [Deterministic f] : f ≫ Δ[Y] = Δ[X] ≫ (f ⊗ₘ f) :=
IsComonHom.hom_comul f
/-- Deterministic morphisms commute with discarding. -/
lemma discard_natural (f : X ⟶ Y) [Deterministic f] : f ≫ ε[Y] = ε[X] :=
IsComonHom.hom_counit f
end Deterministic
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/CopyDiscardCategory/Basic.lean | import Mathlib.CategoryTheory.Monoidal.Comon_
/-!
# Copy-Discard Categories
Symmetric monoidal categories where every object has a commutative
comonoid structure compatible with tensor products.
## Main definitions
* `CopyDiscardCategory` - Category with coherent copy and delete
## Notations
* `Δ[X]` - Copy morphism for X (from `ComonObj`)
* `ε[X]` - Delete morphism for X (from `ComonObj`)
## Implementation notes
We use `ComonObj` instances to provide the comonoid structure.
The key axioms ensure tensor products respect the comonoid structure.
## References
* [Cho and Jacobs, *Disintegration and Bayesian inversion via string diagrams*][cho_jacobs_2019]
* [Fritz, *A synthetic approach to Markov kernels, conditional independence
and theorems on sufficient statistics*][fritz2020]
## Tags
copy-discard, comonoid, symmetric monoidal
-/
universe v u
namespace CategoryTheory
open MonoidalCategory ComonObj
variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C]
/-- Category where objects have compatible copy and discard operations. -/
class CopyDiscardCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C]
extends SymmetricCategory C where
/-- Every object has commutative comonoid structure. -/
[comonObj : (X : C) → ComonObj X]
/-- Every object's comonoid structure is commutative. -/
[isCommComonObj : (X : C) → IsCommComonObj X]
/-- Tensor products of copies equal copies of tensor products. -/
copy_tensor (X Y : C) : Δ[X ⊗ Y] = (Δ[X] ⊗ₘ Δ[Y]) ≫ tensorμ X X Y Y := by cat_disch
/-- Discard distributes over tensor. -/
discard_tensor (X Y : C) : ε[X ⊗ Y] = (ε[X] ⊗ₘ ε[Y]) ≫ (λ_ (𝟙_ C)).hom := by cat_disch
/-- Copy on the unit object. -/
copy_unit : Δ[𝟙_ C] = (λ_ (𝟙_ C)).inv := by cat_disch
/-- Discard on the unit object. -/
discard_unit : ε[𝟙_ C] = 𝟙 (𝟙_ C) := by cat_disch
attribute [instance] CopyDiscardCategory.comonObj CopyDiscardCategory.isCommComonObj
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/CopyDiscardCategory/Cartesian.lean | import Mathlib.CategoryTheory.CopyDiscardCategory.Basic
import Mathlib.CategoryTheory.CopyDiscardCategory.Deterministic
import Mathlib.CategoryTheory.Monoidal.Cartesian.Comon_
import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic
/-!
# Cartesian Categories as Copy-Discard Categories
Every cartesian monoidal category is a copy-discard category where:
- Copy is the diagonal map
- Discard is the unique map to terminal
## Main results
* `CopyDiscardCategory` instance for cartesian monoidal categories
* All morphisms in cartesian categories are deterministic
## Tags
cartesian, copy-discard, comonoid, symmetric monoidal
-/
universe v u
namespace CategoryTheory
open MonoidalCategory CartesianMonoidalCategory ComonObj
variable {C : Type u} [Category.{v} C] [CartesianMonoidalCategory.{v} C]
namespace CartesianCopyDiscard
/-- Provide `ComonObj` instances using the canonical cartesian comonoid structure. -/
abbrev instComonObjOfCartesian (X : C) : ComonObj X :=
((cartesianComon C).obj X).comon
attribute [local instance] instComonObjOfCartesian
variable [BraidedCategory C]
/-- Every object in a cartesian category has commutative comonoid structure. -/
instance instIsCommComonObjOfCartesian (X : C) : IsCommComonObj X where
/-- Cartesian categories have copy-discard structure. -/
abbrev ofCartesianMonoidalCategory : CopyDiscardCategory C where
attribute [local instance] ofCartesianMonoidalCategory
/-- In cartesian categories, every morphism is deterministic (preserves the comonoid structure). -/
instance instDeterministic {X Y : C} (f : X ⟶ Y) : Deterministic f where
end CartesianCopyDiscard
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Grpd.lean | import Mathlib.CategoryTheory.SingleObj
import Mathlib.CategoryTheory.Limits.Shapes.Products
/-!
# Category of groupoids
This file contains the definition of the category `Grpd` of all groupoids.
In this category objects are groupoids and morphisms are functors
between these groupoids.
We also provide two “forgetting” functors: `objects : Grpd ⥤ Type`
and `forgetToCat : Grpd ⥤ Cat`.
## Implementation notes
Though `Grpd` is not a concrete category, we use `Bundled` to define
its carrier type.
-/
assert_not_exists MonoidWithZero
universe v u
namespace CategoryTheory
-- intended to be used with explicit universe parameters
/-- Category of groupoids -/
@[nolint checkUnivs]
def Grpd :=
Bundled Groupoid.{v, u}
namespace Grpd
instance : Inhabited Grpd :=
⟨Bundled.of (SingleObj PUnit)⟩
instance str' (C : Grpd.{v, u}) : Groupoid.{v, u} C.α :=
C.str
instance : CoeSort Grpd Type* :=
Bundled.coeSort
/-- Construct a bundled `Grpd` from the underlying type and the typeclass `Groupoid`. -/
def of (C : Type u) [Groupoid.{v} C] : Grpd.{v, u} :=
Bundled.of C
@[simp]
theorem coe_of (C : Type u) [Groupoid C] : (of C : Type u) = C :=
rfl
/-- Category structure on `Grpd` -/
instance category : LargeCategory.{max v u} Grpd.{v, u} where
Hom C D := C ⥤ D
id C := 𝟭 C
comp F G := F ⋙ G
id_comp _ := rfl
comp_id _ := rfl
assoc := by intros; rfl
/-- Functor that gets the set of objects of a groupoid. It is not
called `forget`, because it is not a faithful functor. -/
def objects : Grpd.{v, u} ⥤ Type u where
obj := Bundled.α
map F := F.obj
/-- Forgetting functor to `Cat` -/
def forgetToCat : Grpd.{v, u} ⥤ Cat.{v, u} where
obj C := Cat.of C
map := id
instance (X : Grpd) : Groupoid (Grpd.forgetToCat.obj X) := inferInstanceAs (Groupoid X)
instance forgetToCat_full : forgetToCat.Full where map_surjective f := ⟨f, rfl⟩
instance forgetToCat_faithful : forgetToCat.Faithful where
/-- Convert arrows in the category of groupoids to functors,
which sometimes helps in applying simp lemmas -/
theorem comp_eq_comp {C D E : Grpd.{v, u}} (f : C ⟶ D) (g : D ⟶ E) : f ≫ g = f ⋙ g :=
rfl
/-- Converts identity in the category of groupoids to the functor identity -/
theorem id_eq_id {C : Grpd.{v, u}} : 𝟙 C = 𝟭 C :=
rfl
@[deprecated (since := "2025-09-04")] alias hom_to_functor := comp_eq_comp
@[deprecated "Deprecated in favor of using `CategoryTheory.Grpd.id_eq_id`" (since := "2025-09-04")]
theorem id_to_functor {C : Grpd.{v, u}} : 𝟭 C = 𝟙 C :=
rfl
section Products
/-- Construct the product over an indexed family of groupoids, as a fan. -/
def piLimitFan ⦃J : Type u⦄ (F : J → Grpd.{u, u}) : Limits.Fan F :=
Limits.Fan.mk (@of (∀ j : J, F j) _) fun j => CategoryTheory.Pi.eval _ j
/-- The product fan over an indexed family of groupoids, is a limit cone. -/
def piLimitFanIsLimit ⦃J : Type u⦄ (F : J → Grpd.{u, u}) : Limits.IsLimit (piLimitFan F) :=
Limits.mkFanLimit (piLimitFan F) (fun s => Functor.pi' fun j => s.proj j)
(by
intros
dsimp only [piLimitFan]
simp [comp_eq_comp])
(by
intro s m w
apply Functor.pi_ext
intro j; specialize w j
simpa)
instance has_pi : Limits.HasProducts.{u} Grpd.{u, u} :=
Limits.hasProducts_of_limit_fans (by apply piLimitFan) (by apply piLimitFanIsLimit)
/-- The product of a family of groupoids is isomorphic
to the product object in the category of Groupoids -/
noncomputable def piIsoPi (J : Type u) (f : J → Grpd.{u, u}) : @of (∀ j, f j) _ ≅ ∏ᶜ f :=
Limits.IsLimit.conePointUniqueUpToIso (piLimitFanIsLimit f)
(Limits.limit.isLimit (Discrete.functor f))
@[simp]
theorem piIsoPi_hom_π (J : Type u) (f : J → Grpd.{u, u}) (j : J) :
(piIsoPi J f).hom ≫ Limits.Pi.π f j = CategoryTheory.Pi.eval _ j := by
simp [piIsoPi]
rfl
end Products
end Grpd
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/GaloisConnection.lean | import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.Order.GaloisConnection.Defs
/-!
# Galois connections between preorders are adjunctions.
* `GaloisConnection.adjunction` is the adjunction associated to a Galois connection.
-/
universe u v
section
variable {X : Type u} {Y : Type v} [Preorder X] [Preorder Y]
/-- A Galois connection between preorders induces an adjunction between the associated categories.
-/
def GaloisConnection.adjunction {l : X → Y} {u : Y → X} (gc : GaloisConnection l u) :
gc.monotone_l.functor ⊣ gc.monotone_u.functor :=
CategoryTheory.Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f => CategoryTheory.homOfLE (gc.le_u f.le)
invFun := fun f => CategoryTheory.homOfLE (gc.l_le f.le)
left_inv := by cat_disch
right_inv := by cat_disch } }
end
namespace CategoryTheory
variable {X : Type u} {Y : Type v} [Preorder X] [Preorder Y]
/-- An adjunction between preorder categories induces a Galois connection.
-/
theorem Adjunction.gc {L : X ⥤ Y} {R : Y ⥤ X} (adj : L ⊣ R) : GaloisConnection L.obj R.obj :=
fun x y =>
⟨fun h => ((adj.homEquiv x y).toFun h.hom).le, fun h => ((adj.homEquiv x y).invFun h.hom).le⟩
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/ReflQuiv.lean | import Mathlib.Combinatorics.Quiver.ReflQuiver
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Category.Quiv
/-!
# The category of refl quivers
The category `ReflQuiv` of (bundled) reflexive quivers, and the free/forgetful adjunction between
`Cat` and `ReflQuiv`.
-/
namespace CategoryTheory
universe v u v₁ v₂ u₁ u₂
/-- Category of refl quivers. -/
@[nolint checkUnivs]
def ReflQuiv :=
Bundled ReflQuiver.{v + 1, u}
namespace ReflQuiv
instance : CoeSort ReflQuiv (Type u) where coe := Bundled.α
instance (C : ReflQuiv.{v, u}) : ReflQuiver.{v + 1, u} C := C.str
/-- The underlying quiver of a reflexive quiver -/
def toQuiv (C : ReflQuiv.{v, u}) : Quiv.{v, u} := Quiv.of C.α
/-- Construct a bundled `ReflQuiv` from the underlying type and the typeclass. -/
def of (C : Type u) [ReflQuiver.{v + 1} C] : ReflQuiv.{v, u} := Bundled.of C
instance : Inhabited ReflQuiv := ⟨ReflQuiv.of (Discrete default)⟩
@[simp] theorem of_val (C : Type u) [ReflQuiver C] : (ReflQuiv.of C) = C := rfl
/-- Category structure on `ReflQuiv` -/
instance category : LargeCategory.{max v u} ReflQuiv.{v, u} where
Hom C D := ReflPrefunctor C D
id C := ReflPrefunctor.id C
comp F G := ReflPrefunctor.comp F G
theorem id_eq_id (X : ReflQuiv) : 𝟙 X = 𝟭rq X := rfl
theorem comp_eq_comp {X Y Z : ReflQuiv} (F : X ⟶ Y) (G : Y ⟶ Z) : F ≫ G = F ⋙rq G := rfl
/-- The forgetful functor from categories to quivers. -/
@[simps]
def forget : Cat.{v, u} ⥤ ReflQuiv.{v, u} where
obj C := ReflQuiv.of C
map F := F.toReflPrefunctor
theorem forget_faithful {C D : Cat.{v, u}} (F G : C ⥤ D)
(hyp : forget.map F = forget.map G) : F = G := by
cases F; cases G; cases hyp; rfl
instance forget.Faithful : Functor.Faithful (forget) where
map_injective := fun hyp ↦ forget_faithful _ _ hyp
/-- The forgetful functor from categories to quivers. -/
@[simps]
def forgetToQuiv : ReflQuiv.{v, u} ⥤ Quiv.{v, u} where
obj V := Quiv.of V
map F := F.toPrefunctor
theorem forgetToQuiv_faithful {V W : ReflQuiv} (F G : V ⥤rq W)
(hyp : forgetToQuiv.map F = forgetToQuiv.map G) : F = G := by
cases F; cases G; cases hyp; rfl
instance forgetToQuiv.Faithful : Functor.Faithful forgetToQuiv where
map_injective := fun hyp ↦ forgetToQuiv_faithful _ _ hyp
theorem forget_forgetToQuiv : forget ⋙ forgetToQuiv = Quiv.forget := rfl
/-- An isomorphism of quivers lifts to an isomorphism of reflexive quivers given a suitable
compatibility with the identities. -/
def isoOfQuivIso {V W : Type u} [ReflQuiver V] [ReflQuiver W]
(e : Quiv.of V ≅ Quiv.of W)
(h_id : ∀ (X : V), e.hom.map (𝟙rq X) = ReflQuiver.id (obj := W) (e.hom.obj X)) :
ReflQuiv.of V ≅ ReflQuiv.of W where
hom := ReflPrefunctor.mk e.hom h_id
inv := ReflPrefunctor.mk e.inv
(fun Y => (Quiv.homEquivOfIso e).injective (by simp [Quiv.hom_map_inv_map_of_iso, h_id]))
hom_inv_id := by
apply forgetToQuiv.map_injective
exact e.hom_inv_id
inv_hom_id := by
apply forgetToQuiv.map_injective
exact e.inv_hom_id
/-- Compatible equivalences of types and hom-types induce an isomorphism of reflexive quivers. -/
def isoOfEquiv {V W : Type u} [ReflQuiver V] [ReflQuiver W] (e : V ≃ W)
(he : ∀ (X Y : V), (X ⟶ Y) ≃ (e X ⟶ e Y))
(h_id : ∀ (X : V), he _ _ (𝟙rq X) = ReflQuiver.id (obj := W) (e X)) :
ReflQuiv.of V ≅ ReflQuiv.of W := isoOfQuivIso (Quiv.isoOfEquiv e he) h_id
end ReflQuiv
namespace ReflPrefunctor
/-- A refl prefunctor can be promoted to a functor if it respects composition. -/
def toFunctor {C D : Cat} (F : (ReflQuiv.of C) ⟶ (ReflQuiv.of D))
(hyp : ∀ {X Y Z : ↑C} (f : X ⟶ Y) (g : Y ⟶ Z),
F.map (CategoryStruct.comp (obj := C) f g) =
CategoryStruct.comp (obj := D) (F.map f) (F.map g)) : C ⥤ D where
obj := F.obj
map := F.map
map_id := F.map_id
map_comp := hyp
end ReflPrefunctor
namespace Cat
/-- The hom relation that identifies the specified reflexivity arrows with the nil paths -/
inductive FreeReflRel {V} [ReflQuiver V] : (X Y : Paths V) → (f g : X ⟶ Y) → Prop
| mk {X : V} : FreeReflRel X X (Quiver.Hom.toPath (𝟙rq X)) .nil
/-- A reflexive quiver generates a free category, defined as a quotient of the free category
on its underlying quiver (called the "path category") by the hom relation that uses the specified
reflexivity arrows as the identity arrows. -/
def FreeRefl (V) [ReflQuiver V] := Quotient (C := Paths V) (FreeReflRel (V := V))
instance (V) [ReflQuiver V] : Category (FreeRefl V) :=
inferInstanceAs (Category (Quotient _))
/-- The quotient functor associated to a quotient category defines a natural map from the free
category on the underlying quiver of a refl quiver to the free category on the reflexive quiver. -/
def FreeRefl.quotientFunctor (V) [ReflQuiver V] : Paths V ⥤ FreeRefl V :=
Quotient.functor (C := Paths V) (FreeReflRel (V := V))
/-- This is a specialization of `Quotient.lift_unique'` rather than `Quotient.lift_unique`, hence
the prime in the name. -/
theorem FreeRefl.lift_unique' {V} [ReflQuiver V] {D} [Category D] (F₁ F₂ : FreeRefl V ⥤ D)
(h : quotientFunctor V ⋙ F₁ = quotientFunctor V ⋙ F₂) :
F₁ = F₂ :=
Quotient.lift_unique' (C := Cat.free.obj (Quiv.of V)) (FreeReflRel (V := V)) _ _ h
@[simp]
lemma FreeRefl.quotientFunctor_map_id (V) [ReflQuiver V] (X : V) :
(FreeRefl.quotientFunctor V).map (𝟙rq X).toPath = 𝟙 _ :=
Quotient.sound _ .mk
instance (V : Type*) [ReflQuiver V] [Unique V] : Unique (FreeRefl V) :=
letI : Unique (Paths V) := inferInstanceAs (Unique V)
inferInstanceAs (Unique (Quotient _))
instance (V : Type*) [ReflQuiver V] [Unique V]
[∀ (x y : V), Unique (x ⟶ y)] (x y : FreeRefl V) :
Unique (x ⟶ y) where
default := (FreeRefl.quotientFunctor V).map ((Paths.of V).map default)
uniq f := by
letI : Unique (Paths V) := inferInstanceAs (Unique V)
induction f using Quotient.induction with | @h x y f =>
rw [← FreeRefl.quotientFunctor]
symm
induction f using Paths.induction with
| id =>
apply Quotient.sound
obtain rfl : x = y := by subsingleton
rw [show (Paths.of V).map default = (𝟙rq _).toPath by congr; subsingleton]
exact .mk
| @comp x y z f g hrec =>
obtain rfl : x = z := by subsingleton
obtain rfl : x = y := by subsingleton
obtain rfl : g = 𝟙rq _ := by subsingleton
simp only [Paths.of_obj, ↓hrec, Paths.of_map, Functor.map_comp,
FreeRefl.quotientFunctor_map_id, Category.comp_id]
/-- A refl prefunctor `V ⥤rq W` induces a functor `FreeRefl V ⥤ FreeRefl W` defined using
`freeMap` and the quotient functor. -/
@[simps!]
def freeReflMap {V W : Type*} [ReflQuiver.{v₁ + 1} V] [ReflQuiver.{v₂ + 1} W] (F : V ⥤rq W) :
FreeRefl V ⥤ FreeRefl W :=
Quotient.lift _ (freeMap F.toPrefunctor ⋙ FreeRefl.quotientFunctor W) (by
rintro _ _ _ _ ⟨hfg⟩
apply Quotient.sound
simp [ReflPrefunctor.map_id]
constructor)
theorem freeReflMap_naturality
{V W : Type*} [ReflQuiver.{v₁ + 1} V] [ReflQuiver.{v₂ + 1} W] (F : V ⥤rq W) :
FreeRefl.quotientFunctor V ⋙ freeReflMap F =
freeMap F.toPrefunctor ⋙ FreeRefl.quotientFunctor W :=
Quotient.lift_spec _ _ _
/-- The functor sending a reflexive quiver to the free category it generates, a quotient of
its path category -/
@[simps!]
def freeRefl : ReflQuiv.{v, u} ⥤ Cat.{max u v, u} where
obj V := Cat.of (FreeRefl V)
map F := freeReflMap F
map_id X := by
refine (Quotient.lift_unique _ _ _ _ ((Functor.comp_id _).trans <|
(Functor.id_comp _).symm.trans ?_)).symm
congr 1
exact (free.map_id X.toQuiv).symm
map_comp {X Y Z} f g := by
apply (Quotient.lift_unique _ _ _ _ _).symm
change FreeRefl.quotientFunctor _ ⋙ _ = _
rw [Cat.comp_eq_comp, ← Functor.assoc, freeReflMap_naturality, Functor.assoc,
freeReflMap_naturality, ← Functor.assoc]
have : freeMap (f ≫ g).toPrefunctor =
freeMap f.toPrefunctor ⋙ freeMap g.toPrefunctor := by rw [← freeMap_comp]; rfl
rw [this]
/-- We will make use of the natural quotient map from the free category on the underlying
quiver of a refl quiver to the free category on the reflexive quiver. -/
def freeReflNatTrans : ReflQuiv.forgetToQuiv ⋙ Cat.free ⟶ freeRefl where
app V := FreeRefl.quotientFunctor V
naturality _ _ f := freeReflMap_naturality f
end Cat
namespace ReflQuiv
open Category Functor
/-- The unit components are defined as the composite of the corresponding unit component for the
adjunction between categories and quivers with the map underlying the quotient functor. -/
@[simps! toPrefunctor obj map]
def adj.unit.app (V : Type u) [ReflQuiver V] :
V ⥤rq forget.obj (Cat.freeRefl.obj (ReflQuiv.of V)) where
toPrefunctor := Paths.of V ⋙q (Cat.FreeRefl.quotientFunctor V).toPrefunctor
map_id := fun _ => Quotient.sound _ ⟨⟩
/-- This is used in the proof of both triangle equalities. -/
theorem adj.unit.map_app_eq (V : ReflQuiv.{max u v, u}) :
forgetToQuiv.map (adj.unit.app V) = Quiv.adj.unit.app (V.toQuiv) ≫
Quiv.forget.map (Y := Cat.of _) (Cat.FreeRefl.quotientFunctor V) := rfl
/-- The counit components are defined using the universal property of the quotient
from the corresponding counit component for the adjunction between categories and quivers. -/
@[simps!]
def adj.counit.app (C : Type u) [Category.{max u v} C] :
Cat.freeRefl.obj (ReflQuiv.of C) ⥤ C :=
Quotient.lift Cat.FreeReflRel (pathComposition C) (by
intro x y f g rel
cases rel
unfold pathComposition
simp only [composePath_toPath]
rfl)
/-- The counit of `ReflQuiv.adj` is closely related to the counit of `Quiv.adj`. -/
@[simp]
theorem adj.counit.comp_app_eq (C : Type u) [Category C] :
Cat.FreeRefl.quotientFunctor C ⋙ adj.counit.app C = pathComposition (Cat.of C) :=
rfl
/--
The adjunction between forming the free category on a reflexive quiver, and forgetting a category
to a reflexive quiver.
-/
nonrec def adj : Cat.freeRefl.{max u v, u} ⊣ ReflQuiv.forget :=
Adjunction.mkOfUnitCounit {
unit := {
app _ := adj.unit.app _
naturality _ _ _ := rfl
}
counit := {
app _ := adj.counit.app _
naturality _ _ F := Quotient.lift_unique' _ _ _ (Quiv.adj.counit.naturality F)
}
left_triangle := by
ext V
apply Cat.FreeRefl.lift_unique'
dsimp
conv => rhs; rw [Cat.id_eq_id]; apply Functor.comp_id
simp only [id_comp]
rw [Cat.comp_eq_comp, ← Functor.assoc]
change (Cat.FreeRefl.quotientFunctor _ ⋙ Cat.freeReflMap _) ⋙ _ = _
rw [Cat.freeReflMap_naturality, Functor.assoc]
dsimp only [Cat.freeRefl, Cat.free_obj, Cat.of_α, of_val, forget_obj,
adj.unit.app_toPrefunctor]
rw [adj.counit.comp_app_eq]
dsimp only [Cat.of_α]
rw [Cat.freeMap_comp, Functor.assoc, Quiv.pathComposition_naturality]
rw [← Functor.assoc]
have := Quiv.freeMap_pathsOf_pathComposition
simp only at this
rw [this]
exact Functor.id_comp _
right_triangle := by
ext C
dsimp
exact forgetToQuiv_faithful _ _ (Quiv.adj.right_triangle_components C)
}
end ReflQuiv
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Factorisation.lean | import Mathlib.CategoryTheory.Category.Basic
import Mathlib.CategoryTheory.Comma.Arrow
import Mathlib.CategoryTheory.Limits.Shapes.Terminal
/-!
# The Factorisation Category of a Category
`Factorisation f` is the category containing as objects all factorisations of a morphism `f`.
We show that `Factorisation f` always has an initial and a terminal object.
TODO: Show that `Factorisation f` is isomorphic to a comma category in two ways.
TODO: Make `MonoFactorisation f` a special case of a `Factorisation f`.
-/
namespace CategoryTheory
universe v u
variable {C : Type u} [Category.{v} C]
/-- Factorisations of a morphism `f` as a structure, containing, one object, two morphisms,
and the condition that their composition equals `f`. -/
structure Factorisation {X Y : C} (f : X ⟶ Y) where
/-- The midpoint of the factorisation. -/
mid : C
/-- The morphism into the factorisation midpoint. -/
ι : X ⟶ mid
/-- The morphism out of the factorisation midpoint. -/
π : mid ⟶ Y
/-- The factorisation condition. -/
ι_π : ι ≫ π = f := by cat_disch
attribute [simp] Factorisation.ι_π
namespace Factorisation
variable {X Y : C} {f : X ⟶ Y}
/-- Morphisms of `Factorisation f` consist of morphism between their midpoints and the obvious
commutativity conditions. -/
@[ext]
protected structure Hom (d e : Factorisation f) : Type (max u v) where
/-- The morphism between the midpoints of the factorizations. -/
h : d.mid ⟶ e.mid
/-- The left commuting triangle of the factorization morphism. -/
ι_h : d.ι ≫ h = e.ι := by cat_disch
/-- The right commuting triangle of the factorization morphism. -/
h_π : h ≫ e.π = d.π := by cat_disch
attribute [simp] Factorisation.Hom.ι_h Factorisation.Hom.h_π
/-- The identity morphism of `Factorisation f`. -/
@[simps]
protected def Hom.id (d : Factorisation f) : Factorisation.Hom d d where
h := 𝟙 _
/-- Composition of morphisms in `Factorisation f`. -/
@[simps]
protected def Hom.comp {d₁ d₂ d₃ : Factorisation f}
(f : Factorisation.Hom d₁ d₂) (g : Factorisation.Hom d₂ d₃) : Factorisation.Hom d₁ d₃ where
h := f.h ≫ g.h
ι_h := by rw [← Category.assoc, f.ι_h, g.ι_h]
h_π := by rw [Category.assoc, g.h_π, f.h_π]
instance : Category.{max u v} (Factorisation f) where
Hom d e := Factorisation.Hom d e
id d := Factorisation.Hom.id d
comp f g := Factorisation.Hom.comp f g
variable (d : Factorisation f)
/-- The initial object in `Factorisation f`, with the domain of `f` as its midpoint. -/
@[simps]
protected def initial : Factorisation f where
mid := X
ι := 𝟙 _
π := f
/-- The unique morphism out of `Factorisation.initial f`. -/
@[simps]
protected def initialHom (d : Factorisation f) :
Factorisation.Hom (Factorisation.initial : Factorisation f) d where
h := d.ι
instance : Unique ((Factorisation.initial : Factorisation f) ⟶ d) where
default := Factorisation.initialHom d
uniq f := by apply Factorisation.Hom.ext; simp [← f.ι_h]
/-- The terminal object in `Factorisation f`, with the codomain of `f` as its midpoint. -/
@[simps]
protected def terminal : Factorisation f where
mid := Y
ι := f
π := 𝟙 _
/-- The unique morphism into `Factorisation.terminal f`. -/
@[simps]
protected def terminalHom (d : Factorisation f) :
Factorisation.Hom d (Factorisation.terminal : Factorisation f) where
h := d.π
instance : Unique (d ⟶ (Factorisation.terminal : Factorisation f)) where
default := Factorisation.terminalHom d
uniq f := by apply Factorisation.Hom.ext; simp [← f.h_π]
open Limits
/-- The initial factorisation is an initial object -/
def IsInitial_initial : IsInitial (Factorisation.initial : Factorisation f) := IsInitial.ofUnique _
instance : HasInitial (Factorisation f) := Limits.hasInitial_of_unique Factorisation.initial
/-- The terminal factorisation is a terminal object -/
def IsTerminal_terminal : IsTerminal (Factorisation.terminal : Factorisation f) :=
IsTerminal.ofUnique _
instance : HasTerminal (Factorisation f) := Limits.hasTerminal_of_unique Factorisation.terminal
/-- The forgetful functor from `Factorisation f` to the underlying category `C`. -/
@[simps]
def forget : Factorisation f ⥤ C where
obj := Factorisation.mid
map f := f.h
end Factorisation
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Pairwise.lean | import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.Limits.IsLimit
import Mathlib.Order.CompleteLattice.Basic
/-!
# The category of "pairwise intersections".
Given `ι : Type v`, we build the diagram category `Pairwise ι`
with objects `single i` and `pair i j`, for `i j : ι`,
whose only non-identity morphisms are
`left : pair i j ⟶ single i` and `right : pair i j ⟶ single j`.
We use this later in describing (one formulation of) the sheaf condition.
Given any function `U : ι → α`, where `α` is some complete lattice (e.g. `(Opens X)ᵒᵖ`),
we produce a functor `Pairwise ι ⥤ α` in the obvious way,
and show that `iSup U` provides a colimit cocone over this functor.
-/
noncomputable section
universe v u
open CategoryTheory
open CategoryTheory.Limits
namespace CategoryTheory
/-- An inductive type representing either a single term of a type `ι`, or a pair of terms.
We use this as the objects of a category to describe the sheaf condition.
-/
inductive Pairwise (ι : Type v)
| single : ι → Pairwise ι
| pair : ι → ι → Pairwise ι
variable {ι : Type v}
namespace Pairwise
instance pairwiseInhabited [Inhabited ι] : Inhabited (Pairwise ι) :=
⟨single default⟩
/-- Morphisms in the category `Pairwise ι`. The only non-identity morphisms are
`left i j : single i ⟶ pair i j` and `right i j : single j ⟶ pair i j`.
-/
inductive Hom : Pairwise ι → Pairwise ι → Type v
| id_single : ∀ i, Hom (single i) (single i)
| id_pair : ∀ i j, Hom (pair i j) (pair i j)
| left : ∀ i j, Hom (pair i j) (single i)
| right : ∀ i j, Hom (pair i j) (single j)
open Hom
instance homInhabited [Inhabited ι] : Inhabited (Hom (single (default : ι)) (single default)) :=
⟨id_single default⟩
/-- The identity morphism in `Pairwise ι`.
-/
def id : ∀ o : Pairwise ι, Hom o o
| single i => id_single i
| pair i j => id_pair i j
/-- Composition of morphisms in `Pairwise ι`. -/
def comp : ∀ {o₁ o₂ o₃ : Pairwise ι} (_ : Hom o₁ o₂) (_ : Hom o₂ o₃), Hom o₁ o₃
| _, _, _, id_single _, g => g
| _, _, _, id_pair _ _, g => g
| _, _, _, left i j, id_single _ => left i j
| _, _, _, right i j, id_single _ => right i j
instance : CategoryStruct (Pairwise ι) where
Hom := Hom
id := id
comp := @comp _
section
open Lean Elab Tactic in
/-- A helper tactic for `cat_disch` and `Pairwise`. -/
def pairwiseCases : TacticM Unit := do
evalTactic (← `(tactic| casesm* (_ : Pairwise _) ⟶ (_ : Pairwise _)))
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] pairwiseCases in
instance : Category (Pairwise ι) where
end
variable {α : Type u} (U : ι → α)
section
variable [SemilatticeInf α]
/-- Auxiliary definition for `diagram`. -/
@[simp]
def diagramObj : Pairwise ι → α
| single i => U i
| pair i j => U i ⊓ U j
/-- Auxiliary definition for `diagram`. -/
@[simp]
def diagramMap : ∀ {o₁ o₂ : Pairwise ι} (_ : o₁ ⟶ o₂), diagramObj U o₁ ⟶ diagramObj U o₂
| _, _, id_single _ => 𝟙 _
| _, _, id_pair _ _ => 𝟙 _
| _, _, left _ _ => homOfLE inf_le_left
| _, _, right _ _ => homOfLE inf_le_right
/-- Given a function `U : ι → α` for `[SemilatticeInf α]`, we obtain a functor `Pairwise ι ⥤ α`,
sending `single i` to `U i` and `pair i j` to `U i ⊓ U j`,
and the morphisms to the obvious inequalities.
-/
@[simps]
def diagram : Pairwise ι ⥤ α where
obj := diagramObj U
map := diagramMap U
end
section
-- `CompleteLattice` is not really needed, as we only ever use `inf`,
-- but the appropriate structure has not been defined.
variable [CompleteLattice α]
/-- Auxiliary definition for `cocone`. -/
def coconeιApp : ∀ o : Pairwise ι, diagramObj U o ⟶ iSup U
| single i => homOfLE (le_iSup U i)
| pair i _ => homOfLE inf_le_left ≫ homOfLE (le_iSup U i)
/-- Given a function `U : ι → α` for `[CompleteLattice α]`,
`iSup U` provides a cocone over `diagram U`.
-/
@[simps]
def cocone : Cocone (diagram U) where
pt := iSup U
ι := { app := coconeιApp U }
/-- Given a function `U : ι → α` for `[CompleteLattice α]`,
`iInf U` provides a limit cone over `diagram U`.
-/
def coconeIsColimit : IsColimit (cocone U) where
desc s := homOfLE
(by
apply CompleteSemilatticeSup.sSup_le
rintro _ ⟨j, rfl⟩
exact (s.ι.app (single j)).le)
end
end Pairwise
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Bipointed.lean | import Mathlib.CategoryTheory.Category.Pointed
/-!
# The category of bipointed types
This defines `Bipointed`, the category of bipointed types.
## TODO
Monoidal structure
-/
open CategoryTheory
universe u
/-- The category of bipointed types. -/
structure Bipointed : Type (u + 1) where
/-- The underlying type of a bipointed type. -/
protected X : Type u
/-- The two points of a bipointed type, bundled together as a pair. -/
toProd : X × X
namespace Bipointed
instance : CoeSort Bipointed Type* := ⟨Bipointed.X⟩
/-- Turns a bipointing into a bipointed type. -/
abbrev of {X : Type*} (to_prod : X × X) : Bipointed :=
⟨X, to_prod⟩
theorem coe_of {X : Type*} (to_prod : X × X) : ↥(of to_prod) = X :=
rfl
alias _root_.Prod.Bipointed := of
instance : Inhabited Bipointed :=
⟨of ((), ())⟩
/-- Morphisms in `Bipointed`. -/
@[ext]
protected structure Hom (X Y : Bipointed.{u}) : Type u where
/-- The underlying function of a morphism of bipointed types. -/
toFun : X → Y
map_fst : toFun X.toProd.1 = Y.toProd.1
map_snd : toFun X.toProd.2 = Y.toProd.2
namespace Hom
/-- The identity morphism of `X : Bipointed`. -/
@[simps]
nonrec def id (X : Bipointed) : Bipointed.Hom X X :=
⟨id, rfl, rfl⟩
instance (X : Bipointed) : Inhabited (Bipointed.Hom X X) :=
⟨id X⟩
/-- Composition of morphisms of `Bipointed`. -/
@[simps]
def comp {X Y Z : Bipointed.{u}} (f : Bipointed.Hom X Y) (g : Bipointed.Hom Y Z) :
Bipointed.Hom X Z :=
⟨g.toFun ∘ f.toFun, by rw [Function.comp_apply, f.map_fst, g.map_fst], by
rw [Function.comp_apply, f.map_snd, g.map_snd]⟩
end Hom
instance largeCategory : LargeCategory Bipointed where
Hom := Bipointed.Hom
id := Hom.id
comp := @Hom.comp
/-- The subtype of functions corresponding to the morphisms in `Bipointed`. -/
abbrev HomSubtype (X Y : Bipointed) :=
{ f : X → Y // f X.toProd.1 = Y.toProd.1 ∧ f X.toProd.2 = Y.toProd.2 }
instance (X Y : Bipointed) : FunLike (HomSubtype X Y) X Y where
coe f := f
coe_injective' _ _ := Subtype.ext
instance hasForget : ConcreteCategory Bipointed HomSubtype where
hom f := ⟨f.1, ⟨f.2, f.3⟩⟩
ofHom f := ⟨f.1, f.2.1, f.2.2⟩
/-- Swaps the pointed elements of a bipointed type. `Prod.swap` as a functor. -/
@[simps]
def swap : Bipointed ⥤ Bipointed where
obj X := ⟨X, X.toProd.swap⟩
map f := ⟨f.toFun, f.map_snd, f.map_fst⟩
/-- The equivalence between `Bipointed` and itself induced by `Prod.swap` both ways. -/
@[simps!]
def swapEquiv : Bipointed ≌ Bipointed where
functor := swap
inverse := swap
unitIso := Iso.refl _
counitIso := Iso.refl _
@[simp]
theorem swapEquiv_symm : swapEquiv.symm = swapEquiv :=
rfl
end Bipointed
/-- The forgetful functor from `Bipointed` to `Pointed` which forgets about the second point. -/
def bipointedToPointedFst : Bipointed ⥤ Pointed where
obj X := ⟨X, X.toProd.1⟩
map f := ⟨f.toFun, f.map_fst⟩
/-- The forgetful functor from `Bipointed` to `Pointed` which forgets about the first point. -/
def bipointedToPointedSnd : Bipointed ⥤ Pointed where
obj X := ⟨X, X.toProd.2⟩
map f := ⟨f.toFun, f.map_snd⟩
@[simp]
theorem bipointedToPointedFst_comp_forget :
bipointedToPointedFst ⋙ forget Pointed = forget Bipointed :=
rfl
@[simp]
theorem bipointedToPointedSnd_comp_forget :
bipointedToPointedSnd ⋙ forget Pointed = forget Bipointed :=
rfl
@[simp]
theorem swap_comp_bipointedToPointedFst :
Bipointed.swap ⋙ bipointedToPointedFst = bipointedToPointedSnd :=
rfl
@[simp]
theorem swap_comp_bipointedToPointedSnd :
Bipointed.swap ⋙ bipointedToPointedSnd = bipointedToPointedFst :=
rfl
/-- The functor from `Pointed` to `Bipointed` which bipoints the point. -/
def pointedToBipointed : Pointed.{u} ⥤ Bipointed where
obj X := ⟨X, X.point, X.point⟩
map f := ⟨f.toFun, f.map_point, f.map_point⟩
/-- The functor from `Pointed` to `Bipointed` which adds a second point. -/
def pointedToBipointedFst : Pointed.{u} ⥤ Bipointed where
obj X := ⟨Option X, X.point, none⟩
map f := ⟨Option.map f.toFun, congr_arg _ f.map_point, rfl⟩
map_id _ := Bipointed.Hom.ext Option.map_id
map_comp f g := Bipointed.Hom.ext (Option.map_comp_map f.1 g.1).symm
/-- The functor from `Pointed` to `Bipointed` which adds a first point. -/
def pointedToBipointedSnd : Pointed.{u} ⥤ Bipointed where
obj X := ⟨Option X, none, X.point⟩
map f := ⟨Option.map f.toFun, rfl, congr_arg _ f.map_point⟩
map_id _ := Bipointed.Hom.ext Option.map_id
map_comp f g := Bipointed.Hom.ext (Option.map_comp_map f.1 g.1).symm
@[simp]
theorem pointedToBipointedFst_comp_swap :
pointedToBipointedFst ⋙ Bipointed.swap = pointedToBipointedSnd :=
rfl
@[simp]
theorem pointedToBipointedSnd_comp_swap :
pointedToBipointedSnd ⋙ Bipointed.swap = pointedToBipointedFst :=
rfl
/-- `BipointedToPointed_fst` is inverse to `PointedToBipointed`. -/
@[simps!]
def pointedToBipointedCompBipointedToPointedFst :
pointedToBipointed ⋙ bipointedToPointedFst ≅ 𝟭 _ :=
NatIso.ofComponents fun X =>
{ hom := ⟨id, rfl⟩
inv := ⟨id, rfl⟩ }
/-- `BipointedToPointed_snd` is inverse to `PointedToBipointed`. -/
@[simps!]
def pointedToBipointedCompBipointedToPointedSnd :
pointedToBipointed ⋙ bipointedToPointedSnd ≅ 𝟭 _ :=
NatIso.ofComponents fun X =>
{ hom := ⟨id, rfl⟩
inv := ⟨id, rfl⟩ }
/-- The free/forgetful adjunction between `PointedToBipointed_fst` and `BipointedToPointed_fst`.
-/
def pointedToBipointedFstBipointedToPointedFstAdjunction :
pointedToBipointedFst ⊣ bipointedToPointedFst :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f => ⟨f.toFun ∘ Option.some, f.map_fst⟩
invFun := fun f => ⟨fun o => o.elim Y.toProd.2 f.toFun, f.map_point, rfl⟩
left_inv := fun f => by
apply Bipointed.Hom.ext
funext x
cases x
· exact f.map_snd.symm
· rfl }
homEquiv_naturality_left_symm := fun f g => by
apply Bipointed.Hom.ext
funext x
cases x <;> rfl }
/-- The free/forgetful adjunction between `PointedToBipointed_snd` and `BipointedToPointed_snd`.
-/
def pointedToBipointedSndBipointedToPointedSndAdjunction :
pointedToBipointedSnd ⊣ bipointedToPointedSnd :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f => ⟨f.toFun ∘ Option.some, f.map_snd⟩
invFun := fun f => ⟨fun o => o.elim Y.toProd.1 f.toFun, rfl, f.map_point⟩
left_inv := fun f => by
apply Bipointed.Hom.ext
funext x
cases x
· exact f.map_fst.symm
· rfl }
homEquiv_naturality_left_symm := fun f g => by
apply Bipointed.Hom.ext
funext x
cases x <;> rfl } |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Init.lean | import Mathlib.Init
import Aesop
/-!
# Category Theory Rule Set
This module defines the `CategoryTheory` Aesop rule set which is used by the
`aesop_cat` tactic. Aesop rule sets only become visible once the file in which
they're declared is imported, so we must put this declaration into its own file.
-/
declare_aesop_rule_sets [CategoryTheory]
/-- Option to control whether the category theory library should use `grind` or `aesop`
in the `cat_disch` tactic, which is widely used as an autoparameter. -/
register_option mathlib.tactic.category.grind : Bool := {
defValue := false
descr := "The category theory library should use `grind` instead of `aesop`."
}
/-- Log a message whenever the category theory discharger uses `grind`. -/
register_option mathlib.tactic.category.log_grind : Bool := {
defValue := false
descr := "Log a message whenever the category theory discharger uses `grind`."
}
/-- Log a message whenever the category theory discharger uses `aesop`. -/
register_option mathlib.tactic.category.log_aesop : Bool := {
defValue := false
descr := "Log a message whenever the category theory discharger uses `aesop`."
} |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/TwoP.lean | import Mathlib.CategoryTheory.Category.Bipointed
import Mathlib.Data.TwoPointing
/-!
# The category of two-pointed types
This defines `TwoP`, the category of two-pointed types.
## References
* [nLab, *coalgebra of the real interval*]
(https://ncatlab.org/nlab/show/coalgebra+of+the+real+interval)
-/
open CategoryTheory Option
universe u
variable {α β : Type*}
/-- The category of two-pointed types. -/
structure TwoP : Type (u + 1) where
/-- The underlying type of a two-pointed type. -/
protected X : Type u
/-- The two points of a bipointed type, bundled together as a pair of distinct elements. -/
toTwoPointing : TwoPointing X
namespace TwoP
instance : CoeSort TwoP Type* :=
⟨TwoP.X⟩
/-- Turns a two-pointing into a two-pointed type. -/
abbrev of {X : Type*} (toTwoPointing : TwoPointing X) : TwoP :=
⟨X, toTwoPointing⟩
theorem coe_of {X : Type*} (toTwoPointing : TwoPointing X) : ↥(of toTwoPointing) = X :=
rfl
alias _root_.TwoPointing.TwoP := of
instance : Inhabited TwoP :=
⟨of TwoPointing.bool⟩
/-- Turns a two-pointed type into a bipointed type, by forgetting that the pointed elements are
distinct. -/
noncomputable def toBipointed (X : TwoP) : Bipointed :=
X.toTwoPointing.toProd.Bipointed
@[simp]
theorem coe_toBipointed (X : TwoP) : ↥X.toBipointed = ↥X :=
rfl
noncomputable instance largeCategory : LargeCategory TwoP :=
InducedCategory.category toBipointed
noncomputable instance concreteCategory : ConcreteCategory TwoP
(fun X Y => Bipointed.HomSubtype X.toBipointed Y.toBipointed) :=
InducedCategory.concreteCategory toBipointed
noncomputable instance hasForgetToBipointed : HasForget₂ TwoP Bipointed :=
InducedCategory.hasForget₂ toBipointed
/-- Swaps the pointed elements of a two-pointed type. `TwoPointing.swap` as a functor. -/
@[simps]
noncomputable def swap : TwoP ⥤ TwoP where
obj X := ⟨X, X.toTwoPointing.swap⟩
map f := ⟨f.toFun, f.map_snd, f.map_fst⟩
/-- The equivalence between `TwoP` and itself induced by `Prod.swap` both ways. -/
@[simps!]
noncomputable def swapEquiv : TwoP ≌ TwoP where
functor := swap
inverse := swap
unitIso := Iso.refl _
counitIso := Iso.refl _
@[simp]
theorem swapEquiv_symm : swapEquiv.symm = swapEquiv :=
rfl
end TwoP
@[simp]
theorem TwoP_swap_comp_forget_to_Bipointed :
TwoP.swap ⋙ forget₂ TwoP Bipointed = forget₂ TwoP Bipointed ⋙ Bipointed.swap :=
rfl
/-- The functor from `Pointed` to `TwoP` which adds a second point. -/
@[simps]
noncomputable def pointedToTwoPFst : Pointed.{u} ⥤ TwoP where
obj X := ⟨Option X, ⟨X.point, none⟩, some_ne_none _⟩
map f := ⟨Option.map f.toFun, congr_arg _ f.map_point, rfl⟩
map_id _ := Bipointed.Hom.ext Option.map_id
map_comp f g := Bipointed.Hom.ext (Option.map_comp_map f.1 g.1).symm
/-- The functor from `Pointed` to `TwoP` which adds a first point. -/
@[simps]
noncomputable def pointedToTwoPSnd : Pointed.{u} ⥤ TwoP where
obj X := ⟨Option X, ⟨none, X.point⟩, (some_ne_none _).symm⟩
map f := ⟨Option.map f.toFun, rfl, congr_arg _ f.map_point⟩
map_id _ := Bipointed.Hom.ext Option.map_id
map_comp f g := Bipointed.Hom.ext (Option.map_comp_map f.1 g.1).symm
@[simp]
theorem pointedToTwoPFst_comp_swap : pointedToTwoPFst ⋙ TwoP.swap = pointedToTwoPSnd :=
rfl
@[simp]
theorem pointedToTwoPSnd_comp_swap : pointedToTwoPSnd ⋙ TwoP.swap = pointedToTwoPFst :=
rfl
@[simp]
theorem pointedToTwoPFst_comp_forget_to_bipointed :
pointedToTwoPFst ⋙ forget₂ TwoP Bipointed = pointedToBipointedFst :=
rfl
@[simp]
theorem pointedToTwoPSnd_comp_forget_to_bipointed :
pointedToTwoPSnd ⋙ forget₂ TwoP Bipointed = pointedToBipointedSnd :=
rfl
/-- Adding a second point is left adjoint to forgetting the second point. -/
noncomputable def pointedToTwoPFstForgetCompBipointedToPointedFstAdjunction :
pointedToTwoPFst ⊣ forget₂ TwoP Bipointed ⋙ bipointedToPointedFst :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f => ⟨f.toFun ∘ Option.some, f.map_fst⟩
invFun := fun f => ⟨fun o => o.elim Y.toTwoPointing.toProd.2 f.toFun, f.map_point, rfl⟩
left_inv := fun f => by
apply Bipointed.Hom.ext
funext x
cases x
· exact f.map_snd.symm
· rfl }
homEquiv_naturality_left_symm := fun f g => by
apply Bipointed.Hom.ext
funext x
cases x <;> rfl }
/-- Adding a first point is left adjoint to forgetting the first point. -/
noncomputable def pointedToTwoPSndForgetCompBipointedToPointedSndAdjunction :
pointedToTwoPSnd ⊣ forget₂ TwoP Bipointed ⋙ bipointedToPointedSnd :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f => ⟨f.toFun ∘ Option.some, f.map_snd⟩
invFun := fun f => ⟨fun o => o.elim Y.toTwoPointing.toProd.1 f.toFun, rfl, f.map_point⟩
left_inv := fun f => by
apply Bipointed.Hom.ext
funext x
cases x
· exact f.map_fst.symm
· rfl }
homEquiv_naturality_left_symm := fun f g => by
apply Bipointed.Hom.ext
funext x
cases x <;> rfl } |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/RelCat.lean | import Mathlib.CategoryTheory.EssentialImage
import Mathlib.CategoryTheory.Iso
import Mathlib.CategoryTheory.Opposites
import Mathlib.CategoryTheory.Types.Basic
import Mathlib.Data.Rel
/-!
# Basics on the category of relations
We define the category of types `CategoryTheory.RelCat` with binary relations as morphisms.
Associating each function with the relation defined by its graph yields a faithful and
essentially surjective functor `graphFunctor` that also characterizes all isomorphisms
(see `rel_iso_iff`).
By flipping the arguments to a relation, we construct an equivalence `opEquivalence` between
`RelCat` and its opposite.
-/
open SetRel
namespace CategoryTheory
universe u
/-- A type synonym for `Type u`, which carries the category instance for which
morphisms are binary relations. -/
def RelCat :=
Type u
namespace RelCat
variable {X Y Z : RelCat.{u}}
instance inhabited : Inhabited RelCat := by unfold RelCat; infer_instance
/-- The morphisms in the relation category are relations. -/
structure Hom (X Y : RelCat.{u}) : Type u where
/-- Build a morphism `X ⟶ Y` for `X Y : RelCat` from a relation between `X` and `Y`. -/
ofRel ::
/-- The underlying relation between `X` and `Y` of a morphism `X ⟶ Y` for `X Y : RelCat`. -/
rel : SetRel X Y
initialize_simps_projections Hom (as_prefix rel)
/-- The category of types with binary relations as morphisms. -/
instance instLargeCategory : LargeCategory RelCat where
Hom := Hom
id _ := .ofRel .id
comp f g := .ofRel <| f.rel ○ g.rel
namespace Hom
@[ext] lemma ext (f g : X ⟶ Y) (h : f.rel = g.rel) : f = g := by cases f; cases g; congr
@[simp] protected lemma rel_id (X : RelCat.{u}) : rel (𝟙 X) = .id := rfl
@[simp] protected lemma rel_comp (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).rel = f.rel.comp g.rel := rfl
theorem rel_id_apply₂ (x y : X) : x ~[rel (𝟙 X)] y ↔ x = y := .rfl
theorem rel_comp_apply₂ (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) (z : Z) :
x ~[(f ≫ g).rel] z ↔ ∃ y, x ~[f.rel] y ∧ y ~[g.rel] z := .rfl
end Hom
/-- The essentially surjective faithful embedding
from the category of types and functions into the category of types and relations. -/
@[simps obj map_rel]
def graphFunctor : Type u ⥤ RelCat.{u} where
obj X := X
map f := .ofRel f.graph
@[deprecated rel_graphFunctor_map (since := "2025-06-08")]
theorem graphFunctor_map {X Y : Type u} (f : X ⟶ Y) (x : X) (y : Y) :
x ~[(graphFunctor.map f).rel] y ↔ f x = y := .rfl
instance graphFunctor_faithful : graphFunctor.Faithful where
map_injective h := Function.graph_injective congr(($h).rel)
instance graphFunctor_essSurj : graphFunctor.EssSurj :=
graphFunctor.essSurj_of_surj Function.surjective_id
/-- A relation is an isomorphism in `RelCat` iff it is the image of an isomorphism in
`Type u`. -/
theorem rel_iso_iff {X Y : RelCat} (r : X ⟶ Y) :
IsIso (C := RelCat) r ↔ ∃ f : Iso (C := Type u) X Y, graphFunctor.map f.hom = r := by
constructor
· intro h
have h1 := congr_fun₂ congr((· ~[($h.hom_inv_id).rel] ·))
have h2 := congr_fun₂ congr((· ~[($h.inv_hom_id).rel] ·))
simp only [RelCat.Hom.rel_comp_apply₂, RelCat.Hom.rel_id_apply₂, eq_iff_iff] at h1 h2
obtain ⟨f, hf⟩ := Classical.axiomOfChoice (fun a => (h1 a a).mpr rfl)
obtain ⟨g, hg⟩ := Classical.axiomOfChoice (fun a => (h2 a a).mpr rfl)
suffices hif : IsIso (C := Type u) f by
use asIso f
ext ⟨x, y⟩
exact ⟨by aesop, fun hxy ↦ (h2 (f x) y).1 ⟨x, (hf x).2, hxy⟩⟩
use g
constructor
· ext x
apply (h1 _ _).mp
use f x, (hg _).2, (hf _).2
· ext y
apply (h2 _ _).mp
use g y, (hf (g y)).2, (hg y).2
· rintro ⟨f, rfl⟩
apply graphFunctor.map_isIso
section Opposite
open Opposite
/-- The argument-swap isomorphism from `RelCat` to its opposite. -/
def opFunctor : RelCat ⥤ RelCatᵒᵖ where
obj X := op X
map {_ _} r := .op <| .ofRel r.rel.inv
/-- The other direction of `opFunctor`. -/
def unopFunctor : RelCatᵒᵖ ⥤ RelCat where
obj X := unop X
map {_ _} r := .ofRel r.unop.rel.inv
@[simp] theorem opFunctor_comp_unopFunctor_eq :
Functor.comp opFunctor unopFunctor = Functor.id _ := rfl
@[simp] theorem unopFunctor_comp_opFunctor_eq :
Functor.comp unopFunctor opFunctor = Functor.id _ := rfl
/-- `RelCat` is self-dual: The map that swaps the argument order of a
relation induces an equivalence between `RelCat` and its opposite. -/
@[simps]
def opEquivalence : RelCat ≌ RelCatᵒᵖ where
functor := opFunctor
inverse := unopFunctor
unitIso := Iso.refl _
counitIso := Iso.refl _
instance : opFunctor.IsEquivalence := by
change opEquivalence.functor.IsEquivalence
infer_instance
instance : unopFunctor.IsEquivalence := by
change opEquivalence.inverse.IsEquivalence
infer_instance
end Opposite
end RelCat
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/KleisliCat.lean | import Mathlib.CategoryTheory.Category.Basic
/-!
# The Kleisli construction on the Type category
Define the Kleisli category for (control) monads.
`CategoryTheory/Monad/Kleisli` defines the general version for a monad on `C`, and demonstrates
the equivalence between the two.
## TODO
Generalise this to work with CategoryTheory.Monad
-/
universe u v
namespace CategoryTheory
-- This file is about Lean 3 declaration "Kleisli".
/-- The Kleisli category on the (type-)monad `m`. Note that the monad is not assumed to be lawful
yet. -/
@[nolint unusedArguments]
def KleisliCat (_ : Type u → Type v) :=
Type u
/-- Construct an object of the Kleisli category from a type. -/
def KleisliCat.mk (m) (α : Type u) : KleisliCat m :=
α
instance KleisliCat.categoryStruct {m} [Monad.{u, v} m] :
CategoryStruct (KleisliCat m) where
Hom α β := α → m β
id _ x := pure x
comp f g := f >=> g
@[ext]
theorem KleisliCat.ext {m} [Monad.{u, v} m] (α β : KleisliCat m)
(f g : α ⟶ β) (h : ∀ x, f x = g x) : f = g := funext h
instance KleisliCat.category {m} [Monad.{u, v} m] [LawfulMonad m] : Category (KleisliCat m) := by
refine { id_comp := ?_, comp_id := ?_, assoc := ?_ } <;> intros <;>
ext <;>
simp +unfoldPartialApp [CategoryStruct.id, CategoryStruct.comp, (· >=> ·)]
@[simp]
theorem KleisliCat.id_def {m} [Monad m] (α : KleisliCat m) : 𝟙 α = @pure m _ α :=
rfl
theorem KleisliCat.comp_def {m} [Monad m] (α β γ : KleisliCat m) (xs : α ⟶ β) (ys : β ⟶ γ) (a : α) :
(xs ≫ ys) a = xs a >>= ys :=
rfl
instance : Inhabited (KleisliCat id) :=
⟨PUnit⟩
instance {α : Type u} [Inhabited α] : Inhabited (KleisliCat.mk id α) :=
⟨show α from default⟩
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Basic.lean | import Mathlib.CategoryTheory.Category.Init
import Mathlib.Combinatorics.Quiver.Basic
import Mathlib.Tactic.PPWithUniv
import Mathlib.Tactic.Common
import Mathlib.Tactic.StacksAttribute
import Mathlib.Tactic.TryThis
/-!
# Categories
Defines a category, as a type class parametrised by the type of objects.
## Notation
Introduces notations in the `CategoryTheory` scope
* `X ⟶ Y` for the morphism spaces (type as `\hom`),
* `𝟙 X` for the identity morphism on `X` (type as `\b1`),
* `f ≫ g` for composition in the 'arrows' convention (type as `\gg`).
Users may like to add `g ⊚ f` for composition in the standard convention, using
```lean
local notation:80 g " ⊚ " f:80 => CategoryTheory.CategoryStruct.comp f g -- type as \oo
```
-/
library_note2 «category theory universes»
/--
The typeclass `Category C` describes morphisms associated to objects of type `C : Type u`.
The universe levels of the objects and morphisms are independent, and will often need to be
specified explicitly, as `Category.{v} C`.
Typically any concrete example will either be a `SmallCategory`, where `v = u`,
which can be introduced as
```
universe u
variable {C : Type u} [SmallCategory C]
```
or a `LargeCategory`, where `u = v+1`, which can be introduced as
```
universe u
variable {C : Type (u+1)} [LargeCategory C]
```
In order for the library to handle these cases uniformly,
we generally work with the unconstrained `Category.{v u}`,
for which objects live in `Type u` and morphisms live in `Type v`.
Because the universe parameter `u` for the objects can be inferred from `C`
when we write `Category C`, while the universe parameter `v` for the morphisms
cannot be automatically inferred, through the category theory library
we introduce universe parameters with morphism levels listed first,
as in
```
universe v u
```
or
```
universe v₁ v₂ u₁ u₂
```
when multiple independent universes are needed.
This has the effect that we can simply write `Category.{v} C`
(that is, only specifying a single parameter) while `u` will be inferred.
Often, however, it's not even necessary to include the `.{v}`.
(Although it was in earlier versions of Lean.)
If it is omitted a "free" universe will be used.
-/
universe v u
namespace CategoryTheory
/-- A preliminary structure on the way to defining a category,
containing the data, but none of the axioms. -/
@[pp_with_univ]
class CategoryStruct (obj : Type u) : Type max u (v + 1) extends Quiver.{v + 1} obj where
/-- The identity morphism on an object. -/
id : ∀ X : obj, Hom X X
/-- Composition of morphisms in a category, written `f ≫ g`. -/
comp : ∀ {X Y Z : obj}, (X ⟶ Y) → (Y ⟶ Z) → (X ⟶ Z)
initialize_simps_projections CategoryStruct (-toQuiver_Hom)
/-- Notation for the identity morphism in a category. -/
scoped notation "𝟙" => CategoryStruct.id -- type as \b1
/-- Notation for composition of morphisms in a category. -/
scoped infixr:80 " ≫ " => CategoryStruct.comp -- type as \gg
/-- Close the main goal with `sorry` if its type contains `sorry`, and fail otherwise. -/
syntax (name := sorryIfSorry) "sorry_if_sorry" : tactic
open Lean Meta Elab.Tactic in
@[tactic sorryIfSorry, inherit_doc sorryIfSorry] def evalSorryIfSorry : Tactic := fun _ => do
let goalType ← getMainTarget
if goalType.hasSorry then
closeMainGoal `sorry_if_sorry (← mkSorry goalType true)
else
throwError "The goal does not contain `sorry`"
/--
`rfl_cat` is a macro for `intros; rfl` which is attempted in `aesop_cat` before
doing the more expensive `aesop` tactic.
This gives a speedup because `simp` (called by `aesop`) can be very slow.
https://github.com/leanprover-community/mathlib4/pull/25475 contains measurements from June 2025.
Implementation notes:
* `refine id ?_`:
In some cases it is important that the type of the proof matches the expected type exactly.
e.g. if the goal is `2 = 1 + 1`, the `rfl` tactic will give a proof of type `2 = 2`.
Starting a proof with `refine id ?_` is a trick to make sure that the proof has exactly
the expected type, in this case `2 = 1 + 1`. See also
https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/changing.20a.20proof.20can.20break.20a.20later.20proof
* `apply_rfl`:
`rfl` is a macro that attempts both `eq_refl` and `apply_rfl`. Since `apply_rfl`
subsumes `eq_refl`, we can use `apply_rfl` instead. This fails twice as fast as `rfl`.
-/
macro (name := rfl_cat) "rfl_cat" : tactic => do `(tactic| (refine id ?_; intros; apply_rfl))
/--
A thin wrapper for `aesop` which adds the `CategoryTheory` rule set and
allows `aesop` to look through semireducible definitions when calling `intros`.
This tactic fails when it is unable to solve the goal, making it suitable for
use in auto-params.
-/
macro (name := aesop_cat) "aesop_cat" c:Aesop.tactic_clause* : tactic =>
`(tactic|
first | sorry_if_sorry | rfl_cat |
aesop $c* (config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))
/--
We also use `aesop_cat?` to pass along a `Try this` suggestion when using `aesop_cat`
-/
macro (name := aesop_cat?) "aesop_cat?" c:Aesop.tactic_clause* : tactic =>
`(tactic|
first | sorry_if_sorry | try_this rfl_cat |
aesop? $c* (config := { introsTransparency? := some .default, terminal := true })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))
/--
A variant of `aesop_cat` which does not fail when it is unable to solve the
goal. Use this only for exploration! Nonterminal `aesop` is even worse than
nonterminal `simp`.
-/
macro (name := aesop_cat_nonterminal) "aesop_cat_nonterminal" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop $c* (config := { introsTransparency? := some .default, warnOnNonterminal := false })
(rule_sets := [$(Lean.mkIdent `CategoryTheory):ident]))
attribute [aesop safe (rule_sets := [CategoryTheory])] Subsingleton.elim
open Lean Elab Tactic in
/-- A tactic for discharging easy category theory goals, widely used as an autoparameter.
Currently this defaults to the `aesop_cat` wrapper around `aesop`, but by setting
the option `mathlib.tactic.category.grind` to `true`, it will use the `grind` tactic instead.
-/
def categoryTheoryDischarger : TacticM Unit := do
if ← getBoolOption `mathlib.tactic.category.grind then
if ← getBoolOption `mathlib.tactic.category.log_grind then
logInfo "Category theory discharger using `grind`."
evalTacticSeq (← `(tacticSeq|
intros; (try dsimp only) <;> ((try ext); grind (gen := 20) (ematch := 20))))
else
if ← getBoolOption `mathlib.tactic.category.log_aesop then
logInfo "Category theory discharger using `aesop`."
evalTactic (← `(tactic| aesop_cat))
@[inherit_doc categoryTheoryDischarger]
elab (name := cat_disch) "cat_disch" : tactic =>
categoryTheoryDischarger
set_option mathlib.tactic.category.grind true
/-- The typeclass `Category C` describes morphisms associated to objects of type `C`.
The universe levels of the objects and morphisms are unconstrained, and will often need to be
specified explicitly, as `Category.{v} C`. (See also `LargeCategory` and `SmallCategory`.) -/
@[pp_with_univ, stacks 0014]
class Category (obj : Type u) : Type max u (v + 1) extends CategoryStruct.{v} obj where
/-- Identity morphisms are left identities for composition. -/
id_comp : ∀ {X Y : obj} (f : X ⟶ Y), 𝟙 X ≫ f = f := by cat_disch
/-- Identity morphisms are right identities for composition. -/
comp_id : ∀ {X Y : obj} (f : X ⟶ Y), f ≫ 𝟙 Y = f := by cat_disch
/-- Composition in a category is associative. -/
assoc : ∀ {W X Y Z : obj} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z), (f ≫ g) ≫ h = f ≫ g ≫ h := by
cat_disch
attribute [simp] Category.id_comp Category.comp_id Category.assoc
attribute [trans] CategoryStruct.comp
attribute [grind =] Category.id_comp Category.comp_id
attribute [grind _=_] Category.assoc
example {C} [Category C] {X Y : C} (f : X ⟶ Y) : 𝟙 X ≫ f = f := by simp
example {C} [Category C] {X Y : C} (f : X ⟶ Y) : f ≫ 𝟙 Y = f := by simp
/-- A `LargeCategory` has objects in one universe level higher than the universe level of
the morphisms. It is useful for examples such as the category of types, or the category
of groups, etc.
-/
abbrev LargeCategory (C : Type (u + 1)) : Type (u + 1) := Category.{u} C
/-- A `SmallCategory` has objects and morphisms in the same universe level.
-/
abbrev SmallCategory (C : Type u) : Type (u + 1) := Category.{u} C
section
variable {C : Type u} [Category.{v} C] {X Y Z : C}
initialize_simps_projections Category (-Hom)
/-- postcompose an equation between morphisms by another morphism -/
theorem eq_whisker {f g : X ⟶ Y} (w : f = g) (h : Y ⟶ Z) : f ≫ h = g ≫ h := by rw [w]
/-- precompose an equation between morphisms by another morphism -/
theorem whisker_eq (f : X ⟶ Y) {g h : Y ⟶ Z} (w : g = h) : f ≫ g = f ≫ h := by rw [w]
/--
Notation for whiskering an equation by a morphism (on the right).
If `f g : X ⟶ Y` and `w : f = g` and `h : Y ⟶ Z`, then `w =≫ h : f ≫ h = g ≫ h`.
-/
scoped infixr:80 " =≫ " => eq_whisker
/--
Notation for whiskering an equation by a morphism (on the left).
If `g h : Y ⟶ Z` and `w : g = h` and `f : X ⟶ Y`, then `f ≫= w : f ≫ g = f ≫ h`.
-/
scoped infixr:80 " ≫= " => whisker_eq
theorem eq_of_comp_left_eq {f g : X ⟶ Y} (w : ∀ {Z : C} (h : Y ⟶ Z), f ≫ h = g ≫ h) :
f = g := by
convert w (𝟙 Y) <;> simp
theorem eq_of_comp_right_eq {f g : Y ⟶ Z} (w : ∀ {X : C} (h : X ⟶ Y), h ≫ f = h ≫ g) :
f = g := by
convert w (𝟙 Y) <;> simp
theorem eq_of_comp_left_eq' (f g : X ⟶ Y)
(w : (fun {Z} (h : Y ⟶ Z) => f ≫ h) = fun {Z} (h : Y ⟶ Z) => g ≫ h) : f = g :=
eq_of_comp_left_eq @fun Z h => by convert congr_fun (congr_fun w Z) h
theorem eq_of_comp_right_eq' (f g : Y ⟶ Z)
(w : (fun {X} (h : X ⟶ Y) => h ≫ f) = fun {X} (h : X ⟶ Y) => h ≫ g) : f = g :=
eq_of_comp_right_eq @fun X h => by convert congr_fun (congr_fun w X) h
theorem id_of_comp_left_id (f : X ⟶ X) (w : ∀ {Y : C} (g : X ⟶ Y), f ≫ g = g) : f = 𝟙 X := by
convert w (𝟙 X)
simp
theorem id_of_comp_right_id (f : X ⟶ X) (w : ∀ {Y : C} (g : Y ⟶ X), g ≫ f = g) : f = 𝟙 X := by
convert w (𝟙 X)
simp
theorem comp_ite {P : Prop} [Decidable P] {X Y Z : C} (f : X ⟶ Y) (g g' : Y ⟶ Z) :
(f ≫ if P then g else g') = if P then f ≫ g else f ≫ g' := by aesop
theorem ite_comp {P : Prop} [Decidable P] {X Y Z : C} (f f' : X ⟶ Y) (g : Y ⟶ Z) :
(if P then f else f') ≫ g = if P then f ≫ g else f' ≫ g := by aesop
theorem comp_dite {P : Prop} [Decidable P]
{X Y Z : C} (f : X ⟶ Y) (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 aesop
theorem dite_comp {P : Prop} [Decidable P]
{X Y Z : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (g : Y ⟶ Z) :
(if h : P then f h else f' h) ≫ g = if h : P then f h ≫ g else f' h ≫ g := by aesop
/-- A morphism `f` is an epimorphism if it can be cancelled when precomposed:
`f ≫ g = f ≫ h` implies `g = h`. -/
@[stacks 003B]
class Epi (f : X ⟶ Y) : Prop where
/-- A morphism `f` is an epimorphism if it can be cancelled when precomposed. -/
left_cancellation : ∀ {Z : C} (g h : Y ⟶ Z), f ≫ g = f ≫ h → g = h
/-- A morphism `f` is a monomorphism if it can be cancelled when postcomposed:
`g ≫ f = h ≫ f` implies `g = h`. -/
@[stacks 003B]
class Mono (f : X ⟶ Y) : Prop where
/-- A morphism `f` is a monomorphism if it can be cancelled when postcomposed. -/
right_cancellation : ∀ {Z : C} (g h : Z ⟶ X), g ≫ f = h ≫ f → g = h
instance (X : C) : Epi (𝟙 X) :=
⟨fun g h w => by aesop⟩
instance (X : C) : Mono (𝟙 X) :=
⟨fun g h w => by aesop⟩
theorem cancel_epi (f : X ⟶ Y) [Epi f] {g h : Y ⟶ Z} : f ≫ g = f ≫ h ↔ g = h :=
⟨fun p => Epi.left_cancellation g h p, congr_arg _⟩
theorem cancel_epi_assoc_iff (f : X ⟶ Y) [Epi f] {g h : Y ⟶ Z} {W : C} {k l : Z ⟶ W} :
(f ≫ g) ≫ k = (f ≫ h) ≫ l ↔ g ≫ k = h ≫ l :=
⟨fun p => (cancel_epi f).1 <| by simpa using p, fun p => by simp only [Category.assoc, p]⟩
theorem cancel_mono (f : X ⟶ Y) [Mono f] {g h : Z ⟶ X} : g ≫ f = h ≫ f ↔ g = h :=
-- Porting note: in Lean 3 we could just write `congr_arg _` here.
⟨fun p => Mono.right_cancellation g h p, congr_arg (fun k => k ≫ f)⟩
theorem cancel_mono_assoc_iff (f : X ⟶ Y) [Mono f] {g h : Z ⟶ X} {W : C} {k l : W ⟶ Z} :
k ≫ (g ≫ f) = l ≫ (h ≫ f) ↔ k ≫ g = l ≫ h :=
⟨fun p => (cancel_mono f).1 <| by simpa using p, fun p => by simp only [← Category.assoc, p]⟩
theorem cancel_epi_id (f : X ⟶ Y) [Epi f] {h : Y ⟶ Y} : f ≫ h = f ↔ h = 𝟙 Y := by
convert cancel_epi f
simp
theorem cancel_mono_id (f : X ⟶ Y) [Mono f] {g : X ⟶ X} : g ≫ f = f ↔ g = 𝟙 X := by
convert cancel_mono f
simp
/-- The composition of epimorphisms is again an epimorphism. This version takes `Epi f` and `Epi g`
as typeclass arguments. For a version taking them as explicit arguments, see `epi_comp'`. -/
instance epi_comp {X Y Z : C} (f : X ⟶ Y) [Epi f] (g : Y ⟶ Z) [Epi g] : Epi (f ≫ g) :=
⟨fun _ _ w => (cancel_epi g).1 <| (cancel_epi_assoc_iff f).1 w⟩
/-- The composition of epimorphisms is again an epimorphism. This version takes `Epi f` and `Epi g`
as explicit arguments. For a version taking them as typeclass arguments, see `epi_comp`. -/
theorem epi_comp' {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} (hf : Epi f) (hg : Epi g) : Epi (f ≫ g) :=
inferInstance
/-- The composition of monomorphisms is again a monomorphism. This version takes `Mono f` and
`Mono g` as typeclass arguments. For a version taking them as explicit arguments, see `mono_comp'`.
-/
instance mono_comp {X Y Z : C} (f : X ⟶ Y) [Mono f] (g : Y ⟶ Z) [Mono g] : Mono (f ≫ g) :=
⟨fun _ _ w => (cancel_mono f).1 <| (cancel_mono_assoc_iff g).1 w⟩
/-- The composition of monomorphisms is again a monomorphism. This version takes `Mono f` and
`Mono g` as explicit arguments. For a version taking them as typeclass arguments, see `mono_comp`.
-/
theorem mono_comp' {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} (hf : Mono f) (hg : Mono g) :
Mono (f ≫ g) :=
inferInstance
theorem mono_of_mono {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [Mono (f ≫ g)] : Mono f :=
⟨fun _ _ w => (cancel_mono (f ≫ g)).1 <| by simp only [← Category.assoc, w]⟩
theorem mono_of_mono_fac {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [Mono h]
(w : f ≫ g = h) : Mono f := by
subst h; exact mono_of_mono f g
theorem epi_of_epi {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [Epi (f ≫ g)] : Epi g :=
⟨fun _ _ w => (cancel_epi (f ≫ g)).1 <| by simp only [Category.assoc, w]⟩
theorem epi_of_epi_fac {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [Epi h]
(w : f ≫ g = h) : Epi g := by
subst h; exact epi_of_epi f g
/-- `f : X ⟶ Y` is a monomorphism iff for all `Z`, composition of morphisms `Z ⟶ X` with `f`
is injective. -/
lemma mono_iff_forall_injective {X Y : C} (f : X ⟶ Y) :
Mono f ↔ ∀ Z, (fun g : Z ⟶ X ↦ g ≫ f).Injective :=
⟨fun _ _ _ _ hg ↦ (cancel_mono f).1 hg, fun h ↦ ⟨fun _ _ hg ↦ h _ hg⟩⟩
/-- `f : X ⟶ Y` is an epimorphism iff for all `Z`, composition of morphisms `Y ⟶ Z` with `f`
is injective. -/
lemma epi_iff_forall_injective {X Y : C} (f : X ⟶ Y) :
Epi f ↔ ∀ Z, (fun g : Y ⟶ Z ↦ f ≫ g).Injective :=
⟨fun _ _ _ _ hg ↦ (cancel_epi f).1 hg, fun h ↦ ⟨fun _ _ hg ↦ h _ hg⟩⟩
section
variable [Quiver.IsThin C] (f : X ⟶ Y)
instance : Mono f where
right_cancellation _ _ _ := Subsingleton.elim _ _
instance : Epi f where
left_cancellation _ _ _ := Subsingleton.elim _ _
end
end
section
variable (C : Type u)
variable [Category.{v} C]
universe u'
/-- The category structure on `ULift C` that is induced from the category
structure on `C`. This is not made a global instance because of a diamond
when `C` is a preordered type. -/
def uliftCategory : Category.{v} (ULift.{u'} C) where
Hom X Y := X.down ⟶ Y.down
id X := 𝟙 X.down
comp f g := f ≫ g
attribute [local instance] uliftCategory in
-- We verify that this previous instance can lift small categories to large categories.
example (D : Type u) [SmallCategory D] : LargeCategory (ULift.{u + 1} D) := by infer_instance
end
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/ULift.lean | import Mathlib.CategoryTheory.Category.Basic
import Mathlib.CategoryTheory.Equivalence
import Mathlib.CategoryTheory.EqToHom
import Mathlib.Data.ULift
/-!
# Basic API for ULift
This file contains a very basic API for working with the categorical
instance on `ULift C` where `C` is a type with a category instance.
1. `CategoryTheory.ULift.upFunctor` is the functorial version of the usual `ULift.up`.
2. `CategoryTheory.ULift.downFunctor` is the functorial version of the usual `ULift.down`.
3. `CategoryTheory.ULift.equivalence` is the categorical equivalence between
`C` and `ULift C`.
## ULiftHom
Given a type `C : Type u`, `ULiftHom.{w} C` is just an alias for `C`.
If we have `category.{v} C`, then `ULiftHom.{w} C` is endowed with a category instance
whose morphisms are obtained by applying `ULift.{w}` to the morphisms from `C`.
This is a category equivalent to `C`. The forward direction of the equivalence is `ULiftHom.up`,
the backward direction is `ULiftHom.down` and the equivalence is `ULiftHom.equiv`.
## AsSmall
This file also contains a construction which takes a type `C : Type u` with a
category instance `Category.{v} C` and makes a small category
`AsSmall.{w} C : Type (max w v u)` equivalent to `C`.
The forward direction of the equivalence, `C ⥤ AsSmall C`, is denoted `AsSmall.up`
and the backward direction is `AsSmall.down`. The equivalence itself is `AsSmall.equiv`.
-/
universe w₁ v₁ v₂ u₁ u₂
namespace CategoryTheory
attribute [local instance] uliftCategory
variable {C : Type u₁} [Category.{v₁} C]
/-- The functorial version of `ULift.up`. -/
@[simps]
def ULift.upFunctor : C ⥤ ULift.{u₂} C where
obj := ULift.up
map f := f
/-- The functorial version of `ULift.down`. -/
@[simps]
def ULift.downFunctor : ULift.{u₂} C ⥤ C where
obj := ULift.down
map f := f
/-- The categorical equivalence between `C` and `ULift C`. -/
@[simps]
def ULift.equivalence : C ≌ ULift.{u₂} C where
functor := ULift.upFunctor
inverse := ULift.downFunctor
unitIso :=
{ hom := 𝟙 _
inv := 𝟙 _ }
counitIso :=
{ hom := { app := fun _ => 𝟙 _ }
inv := { app := fun _ => 𝟙 _ } }
section ULiftHom
/-- `ULiftHom.{w} C` is an alias for `C`, which is endowed with a category instance
whose morphisms are obtained by applying `ULift.{w}` to the morphisms from `C`.
-/
def ULiftHom.{w, u} (C : Type u) : Type u :=
let _ := ULift.{w} C
C
instance {C} [Inhabited C] : Inhabited (ULiftHom C) :=
⟨(default : C)⟩
/-- The obvious function `ULiftHom C → C`. -/
def ULiftHom.objDown {C} (A : ULiftHom C) : C :=
A
/-- The obvious function `C → ULiftHom C`. -/
def ULiftHom.objUp {C} (A : C) : ULiftHom C :=
A
/-- The type-level equivalence between `C` and `ULiftHom C`. -/
def ULiftHom.objEquiv {C} : C ≃ ULiftHom C where
toFun := ULiftHom.objUp
invFun := ULiftHom.objDown
@[simp]
theorem objDown_objUp {C} (A : C) : (ULiftHom.objUp A).objDown = A :=
rfl
@[simp]
theorem objUp_objDown {C} (A : ULiftHom C) : ULiftHom.objUp A.objDown = A :=
rfl
instance ULiftHom.category : Category.{max v₂ v₁} (ULiftHom.{v₂} C) where
Hom A B := ULift.{v₂} <| A.objDown ⟶ B.objDown
id _ := ⟨𝟙 _⟩
comp f g := ⟨f.down ≫ g.down⟩
/-- One half of the equivalence between `C` and `ULiftHom C`. -/
@[simps]
def ULiftHom.up : C ⥤ ULiftHom C where
obj := ULiftHom.objUp
map f := ⟨f⟩
/-- One half of the equivalence between `C` and `ULiftHom C`. -/
@[simps]
def ULiftHom.down : ULiftHom C ⥤ C where
obj := ULiftHom.objDown
map f := f.down
/-- The equivalence between `C` and `ULiftHom C`. -/
def ULiftHom.equiv : C ≌ ULiftHom C where
functor := ULiftHom.up
inverse := ULiftHom.down
unitIso := NatIso.ofComponents fun _ => eqToIso rfl
counitIso := NatIso.ofComponents fun _ => eqToIso rfl
end ULiftHom
/-- `AsSmall C` is a small category equivalent to `C`.
More specifically, if `C : Type u` is endowed with `Category.{v} C`, then
`AsSmall.{w} C : Type (max w v u)` is endowed with an instance of a small category.
The objects and morphisms of `AsSmall C` are defined by applying `ULift` to the
objects and morphisms of `C`.
Note: We require a category instance for this definition in order to have direct
access to the universe level `v`.
-/
@[nolint unusedArguments]
def AsSmall.{w, v, u} (D : Type u) [Category.{v} D] := ULift.{max w v} D
instance : SmallCategory (AsSmall.{w₁} C) where
Hom X Y := ULift.{max w₁ u₁} <| X.down ⟶ Y.down
id _ := ⟨𝟙 _⟩
comp f g := ⟨f.down ≫ g.down⟩
/-- One half of the equivalence between `C` and `AsSmall C`. -/
@[simps]
def AsSmall.up : C ⥤ AsSmall C where
obj X := ⟨X⟩
map f := ⟨f⟩
/-- One half of the equivalence between `C` and `AsSmall C`. -/
@[simps]
def AsSmall.down : AsSmall C ⥤ C where
obj X := ULift.down X
map f := f.down
@[reassoc]
theorem down_comp {X Y Z : AsSmall C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).down = f.down ≫ g.down :=
rfl
@[simp]
theorem eqToHom_down {X Y : AsSmall C} (h : X = Y) :
(eqToHom h).down = eqToHom (congrArg ULift.down h) := by
subst h
rfl
/-- The equivalence between `C` and `AsSmall C`. -/
@[simps]
def AsSmall.equiv : C ≌ AsSmall C where
functor := AsSmall.up
inverse := AsSmall.down
unitIso := NatIso.ofComponents fun _ => eqToIso rfl
counitIso := NatIso.ofComponents fun _ => eqToIso <| ULift.ext _ _ rfl
instance [Inhabited C] : Inhabited (AsSmall C) :=
⟨⟨default⟩⟩
/-- The type-level equivalence between `C` and `ULiftHom (ULift C)`. -/
def ULiftHomULiftCategory.objEquiv.{v', u', u} {C : Type u} :
C ≃ ULiftHom.{v'} (ULift.{u'} C) :=
Equiv.ulift.symm.trans ULiftHom.objEquiv
/-- The equivalence between `C` and `ULiftHom (ULift C)`. -/
def ULiftHomULiftCategory.equiv.{v', u', v, u} (C : Type u) [Category.{v} C] :
C ≌ ULiftHom.{v'} (ULift.{u'} C) :=
ULift.equivalence.trans ULiftHom.equiv
/-- A type-level equivalence `(C ⥤ D) ≃ (C ⥤ (ULiftHom.{v'} (ULift.{u'} D)))`. Note that this is
not ensured by a categorical equivalence, and so needs special treatment. -/
def ULiftHomULiftCategory.equivCongrLeft.{v', u'}
{C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] :
(C ⥤ D) ≃ (C ⥤ (ULiftHom.{v'} (ULift.{u'} D))) where
toFun F := F ⋙ ULift.upFunctor ⋙ ULiftHom.up
invFun F := F ⋙ ULiftHom.down ⋙ ULift.downFunctor
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/PartialFun.lean | import Mathlib.CategoryTheory.Category.Pointed
import Mathlib.Data.PFun
/-!
# The category of types with partial functions
This defines `PartialFun`, the category of types equipped with partial functions.
This category is classically equivalent to the category of pointed types. The reason it doesn't hold
constructively stems from the difference between `Part` and `Option`. Both can model partial
functions, but the latter forces a decidable domain.
Precisely, `PartialFunToPointed` turns a partial function `α →. β` into a function
`Option α → Option β` by sending to `none` the undefined values (and `none` to `none`). But being
defined is (generally) undecidable while being sent to `none` is decidable. So it can't be
constructive.
## References
* [nLab, *The category of sets and partial functions*]
(https://ncatlab.org/nlab/show/partial+function)
-/
open CategoryTheory Option
universe u
/-- The category of types equipped with partial functions. -/
def PartialFun : Type _ :=
Type*
namespace PartialFun
instance : CoeSort PartialFun Type* :=
⟨id⟩
/-- Turns a type into a `PartialFun`. -/
def of : Type* → PartialFun :=
id
instance : Inhabited PartialFun :=
⟨Type*⟩
instance largeCategory : LargeCategory.{u} PartialFun where
Hom := PFun
id := PFun.id
comp f g := g.comp f
id_comp := @PFun.comp_id
comp_id := @PFun.id_comp
assoc _ _ _ := (PFun.comp_assoc _ _ _).symm
/-- Constructs a partial function isomorphism between types from an equivalence between them. -/
@[simps]
def Iso.mk {α β : PartialFun.{u}} (e : α ≃ β) : α ≅ β where
hom x := e x
inv x := e.symm x
hom_inv_id := (PFun.coe_comp _ _).symm.trans (by
simp only [Equiv.symm_comp_self, PFun.coe_id]
rfl)
inv_hom_id := (PFun.coe_comp _ _).symm.trans (by
simp only [Equiv.self_comp_symm, PFun.coe_id]
rfl)
end PartialFun
/-- The forgetful functor from `Type` to `PartialFun` which forgets that the maps are total. -/
def typeToPartialFun : Type u ⥤ PartialFun where
obj := id
map := @PFun.lift
map_comp _ _ := PFun.coe_comp _ _
instance : typeToPartialFun.Faithful where
map_injective {_ _} := PFun.lift_injective
-- b ∈ PFun.toSubtype (fun x ↦ x ≠ X.point) Subtype.val a ↔ b ∈ Part.some a
/-- The functor which deletes the point of a pointed type. In return, this makes the maps partial.
This is the computable part of the equivalence `PartialFunEquivPointed`. -/
@[simps obj map]
def pointedToPartialFun : Pointed.{u} ⥤ PartialFun where
obj X := { x : X // x ≠ X.point }
map f := PFun.toSubtype _ f.toFun ∘ Subtype.val
map_id _ :=
PFun.ext fun _ b =>
PFun.mem_toSubtype_iff (b := b).trans (Subtype.coe_inj.trans Part.mem_some_iff.symm)
map_comp {X Y Z} f g := by
refine PFun.ext fun ⟨a, ha⟩ ⟨c, hc⟩ =>
(PFun.mem_toSubtype_iff.trans ?_).trans Part.mem_bind_iff.symm
suffices c = g.toFun (f.toFun a) → ¬Y.point = f.toFun a ∧ ¬Z.point = g.toFun (f.toFun a) by
aesop
rintro rfl
refine ⟨fun h => hc.symm <| g.map_point ▸ congr_arg g.toFun h, hc.symm⟩
/-- The functor which maps undefined values to a new point. This makes the maps total and creates
pointed types. This is the noncomputable part of the equivalence `PartialFunEquivPointed`. It can't
be computable because `= Option.none` is decidable while the domain of a general `Part` isn't. -/
@[simps obj map]
noncomputable def partialFunToPointed : PartialFun ⥤ Pointed := by
classical
exact
{ obj := fun X => ⟨Option X, none⟩
map := fun f => ⟨Option.elim' none fun a => (f a).toOption, rfl⟩
map_id := fun X => Pointed.Hom.ext <| funext fun o => Option.recOn o rfl fun a => (by
dsimp [CategoryStruct.id]
convert Part.some_toOption a)
map_comp := fun f g => Pointed.Hom.ext <| funext fun o => Option.recOn o rfl fun a => by
dsimp [CategoryStruct.comp]
rw [Part.bind_toOption g (f a), Option.elim'_eq_elim] }
/-- The equivalence induced by `PartialFunToPointed` and `PointedToPartialFun`.
`Part.equivOption` made functorial. -/
@[simps!]
noncomputable def partialFunEquivPointed : PartialFun.{u} ≌ Pointed where
functor := partialFunToPointed
inverse := pointedToPartialFun
unitIso := NatIso.ofComponents (fun X => PartialFun.Iso.mk
{ toFun := fun a => ⟨some a, some_ne_none a⟩
invFun := fun a => Option.get _ (Option.ne_none_iff_isSome.1 a.2)
left_inv := fun _ => Option.get_some _ _
right_inv := fun a => by simp only [some_get, Subtype.coe_eta] })
fun f =>
PFun.ext fun a b => by
dsimp [PartialFun.Iso.mk, CategoryStruct.comp, pointedToPartialFun]
rw [Part.bind_some]
refine (Part.mem_bind_iff.trans ?_).trans PFun.mem_toSubtype_iff.symm
obtain ⟨b | b, hb⟩ := b
· exact (hb rfl).elim
· simp only [partialFunToPointed_obj, ne_eq, Part.mem_some_iff, Subtype.mk.injEq,
some.injEq, exists_eq_right', elim'_some]
classical
refine Part.mem_toOption.symm.trans ?_
exact eq_comm
counitIso :=
NatIso.ofComponents
(fun X ↦ Pointed.Iso.mk (by classical exact Equiv.optionSubtypeNe X.point) (by rfl))
fun {X Y} f ↦ Pointed.Hom.ext <| funext fun a ↦ by
obtain _ | ⟨a, ha⟩ := a
· exact f.map_point.symm
simp_all [Option.casesOn'_eq_elim, Part.elim_toOption]
functor_unitIso_comp X := by
ext (_ | x)
· rfl
· simp
rfl
/-- Forgetting that maps are total and making them total again by adding a point is the same as just
adding a point. -/
@[simps!]
noncomputable def typeToPartialFunIsoPartialFunToPointed :
typeToPartialFun ⋙ partialFunToPointed ≅ typeToPointed :=
NatIso.ofComponents
(fun _ =>
{ hom := ⟨id, rfl⟩
inv := ⟨id, rfl⟩
hom_inv_id := rfl
inv_hom_id := rfl })
fun f =>
Pointed.Hom.ext <|
funext fun a => Option.recOn a rfl fun a => by
convert Part.some_toOption _
simpa using (Part.get_eq_iff_mem (by trivial)).mp rfl |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Pointed.lean | import Mathlib.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.Adjunction.Basic
/-!
# The category of pointed types
This defines `Pointed`, the category of pointed types.
## TODO
* Monoidal structure
* Upgrade `typeToPointed` to an equivalence
-/
open CategoryTheory
universe u
/-- The category of pointed types. -/
structure Pointed : Type (u + 1) where
/-- the underlying type -/
protected X : Type u
/-- the distinguished element -/
point : X
namespace Pointed
instance : CoeSort Pointed Type* :=
⟨Pointed.X⟩
/-- Turns a point into a pointed type. -/
abbrev of {X : Type*} (point : X) : Pointed :=
⟨X, point⟩
theorem coe_of {X : Type*} (point : X) : ↥(of point) = X :=
rfl
alias _root_.Prod.Pointed := of
instance : Inhabited Pointed :=
⟨of ((), ())⟩
/-- Morphisms in `Pointed`. -/
@[ext]
protected structure Hom (X Y : Pointed.{u}) : Type u where
/-- the underlying map -/
toFun : X → Y
/-- compatibility with the distinguished points -/
map_point : toFun X.point = Y.point
namespace Hom
/-- The identity morphism of `X : Pointed`. -/
@[simps]
def id (X : Pointed) : Pointed.Hom X X :=
⟨_root_.id, rfl⟩
instance (X : Pointed) : Inhabited (Pointed.Hom X X) :=
⟨id X⟩
/-- Composition of morphisms of `Pointed`. -/
@[simps]
def comp {X Y Z : Pointed.{u}} (f : Pointed.Hom X Y) (g : Pointed.Hom Y Z) : Pointed.Hom X Z :=
⟨g.toFun ∘ f.toFun, by rw [Function.comp_apply, f.map_point, g.map_point]⟩
end Hom
instance largeCategory : LargeCategory Pointed where
Hom := Pointed.Hom
id := Hom.id
comp := @Hom.comp
@[simp] lemma Hom.id_toFun' (X : Pointed.{u}) : (𝟙 X : X ⟶ X).toFun = _root_.id := rfl
@[simp] lemma Hom.comp_toFun' {X Y Z : Pointed.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).toFun = g.toFun ∘ f.toFun := rfl
instance (X Y : Pointed) : FunLike { f : X → Y // f X.point = Y.point } X Y where
coe f := f
coe_injective' _ _ := Subtype.ext
instance hasForget : ConcreteCategory Pointed fun X Y => { f : X → Y // f X.point = Y.point } where
hom f := ⟨f.1, f.2⟩
ofHom f := ⟨f.1, f.2⟩
/-- Constructs an isomorphism between pointed types from an equivalence that preserves the point
between them. -/
@[simps]
def Iso.mk {α β : Pointed} (e : α ≃ β) (he : e α.point = β.point) : α ≅ β where
hom := ⟨e, he⟩
inv := ⟨e.symm, e.symm_apply_eq.2 he.symm⟩
hom_inv_id := Pointed.Hom.ext e.symm_comp_self
inv_hom_id := Pointed.Hom.ext e.self_comp_symm
end Pointed
/-- `Option` as a functor from types to pointed types. This is the free functor. -/
@[simps]
def typeToPointed : Type u ⥤ Pointed.{u} where
obj X := ⟨Option X, none⟩
map f := ⟨Option.map f, rfl⟩
map_id _ := Pointed.Hom.ext Option.map_id
map_comp _ _ := Pointed.Hom.ext (Option.map_comp_map _ _).symm
/-- `typeToPointed` is the free functor. -/
def typeToPointedForgetAdjunction : typeToPointed ⊣ forget Pointed :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f => f.toFun ∘ Option.some
invFun := fun f => ⟨fun o => o.elim Y.point f, rfl⟩
left_inv := fun f => by
apply Pointed.Hom.ext
funext x
cases x
· exact f.map_point.symm
· rfl }
homEquiv_naturality_left_symm := fun f g => by
apply Pointed.Hom.ext
funext x
cases x <;> rfl } |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat.lean | import Mathlib.CategoryTheory.Bicategory.Strict.Basic
import Mathlib.CategoryTheory.ConcreteCategory.Bundled
import Mathlib.CategoryTheory.Discrete.Basic
import Mathlib.CategoryTheory.Types.Basic
/-!
# Category of categories
This file contains the definition of the category `Cat` of all categories.
In this category objects are categories and
morphisms are functors between these categories.
## Implementation notes
Though `Cat` is not a concrete category, we use `bundled` to define
its carrier type.
-/
universe v u
namespace CategoryTheory
open Bicategory Functor
-- intended to be used with explicit universe parameters
/-- Category of categories. -/
@[nolint checkUnivs]
def Cat :=
Bundled Category.{v, u}
namespace Cat
instance : Inhabited Cat :=
⟨⟨Type u, CategoryTheory.types⟩⟩
-- TODO: maybe this coercion should be defined to be `objects.obj`?
instance : CoeSort Cat (Type u) :=
⟨Bundled.α⟩
instance str (C : Cat.{v, u}) : Category.{v, u} C :=
Bundled.str C
/-- Construct a bundled `Cat` from the underlying type and the typeclass. -/
def of (C : Type u) [Category.{v} C] : Cat.{v, u} :=
Bundled.of C
/-- Bicategory structure on `Cat` -/
instance bicategory : Bicategory.{max v u, max v u} Cat.{v, u} where
Hom C D := C ⥤ D
id C := 𝟭 C
comp F G := F ⋙ G
homCategory := fun _ _ => Functor.category
whiskerLeft {_} {_} {_} F _ _ η := whiskerLeft F η
whiskerRight {_} {_} {_} _ _ η H := whiskerRight η H
associator {_} {_} {_} _ := Functor.associator
leftUnitor {_} _ := Functor.leftUnitor
rightUnitor {_} _ := Functor.rightUnitor
pentagon := fun {_} {_} {_} {_} {_}=> Functor.pentagon
triangle {_} {_} {_} := Functor.triangle
/-- `Cat` is a strict bicategory. -/
instance bicategory.strict : Bicategory.Strict Cat.{v, u} where
id_comp {C} {D} F := by cases F; rfl
comp_id {C} {D} F := by cases F; rfl
assoc := by intros; rfl
/-- Category structure on `Cat` -/
instance category : LargeCategory.{max v u} Cat.{v, u} :=
StrictBicategory.category Cat.{v, u}
@[ext]
theorem ext {C D : Cat} {F G : C ⟶ D} {α β : F ⟶ G} (w : α.app = β.app) : α = β :=
NatTrans.ext w
@[simp]
theorem id_obj {C : Cat} (X : C) : (𝟙 C : C ⥤ C).obj X = X :=
rfl
@[simp]
theorem id_map {C : Cat} {X Y : C} (f : X ⟶ Y) : (𝟙 C : C ⥤ C).map f = f :=
rfl
@[simp]
theorem comp_obj {C D E : Cat} (F : C ⟶ D) (G : D ⟶ E) (X : C) : (F ≫ G).obj X = G.obj (F.obj X) :=
rfl
@[simp]
theorem comp_map {C D E : Cat} (F : C ⟶ D) (G : D ⟶ E) {X Y : C} (f : X ⟶ Y) :
(F ≫ G).map f = G.map (F.map f) :=
rfl
@[simp]
theorem id_app {C D : Cat} (F : C ⟶ D) (X : C) : (𝟙 F : F ⟶ F).app X = 𝟙 (F.obj X) := rfl
@[simp]
theorem comp_app {C D : Cat} {F G H : C ⟶ D} (α : F ⟶ G) (β : G ⟶ H) (X : C) :
(α ≫ β).app X = α.app X ≫ β.app X := rfl
@[simp]
theorem eqToHom_app {C D : Cat} (F G : C ⟶ D) (h : F = G) (X : C) :
(eqToHom h).app X = eqToHom (Functor.congr_obj h X) :=
CategoryTheory.eqToHom_app h X
@[simp]
lemma whiskerLeft_app {C D E : Cat} (F : C ⟶ D) {G H : D ⟶ E} (η : G ⟶ H) (X : C) :
(F ◁ η).app X = η.app (F.obj X) :=
rfl
@[simp]
lemma whiskerRight_app {C D E : Cat} {F G : C ⟶ D} (H : D ⟶ E) (η : F ⟶ G) (X : C) :
(η ▷ H).app X = H.map (η.app X) :=
rfl
lemma leftUnitor_hom_app {B C : Cat} (F : B ⟶ C) (X : B) : (λ_ F).hom.app X = eqToHom (by simp) :=
rfl
lemma leftUnitor_inv_app {B C : Cat} (F : B ⟶ C) (X : B) : (λ_ F).inv.app X = eqToHom (by simp) :=
rfl
lemma rightUnitor_hom_app {B C : Cat} (F : B ⟶ C) (X : B) : (ρ_ F).hom.app X = eqToHom (by simp) :=
rfl
lemma rightUnitor_inv_app {B C : Cat} (F : B ⟶ C) (X : B) : (ρ_ F).inv.app X = eqToHom (by simp) :=
rfl
lemma associator_hom_app {B C D E : Cat} (F : B ⟶ C) (G : C ⟶ D) (H : D ⟶ E) (X : B) :
(α_ F G H).hom.app X = eqToHom (by simp) :=
rfl
lemma associator_inv_app {B C D E : Cat} (F : B ⟶ C) (G : C ⟶ D) (H : D ⟶ E) (X : B) :
(α_ F G H).inv.app X = eqToHom (by simp) :=
rfl
/-- The identity in the category of categories equals the identity functor. -/
theorem id_eq_id (X : Cat) : 𝟙 X = 𝟭 X := rfl
/-- Composition in the category of categories equals functor composition. -/
theorem comp_eq_comp {X Y Z : Cat} (F : X ⟶ Y) (G : Y ⟶ Z) : F ≫ G = F ⋙ G := rfl
@[simp] theorem of_α (C) [Category C] : (of C).α = C := rfl
@[simp] theorem coe_of (C : Cat.{v, u}) : Cat.of C = C := rfl
end Cat
namespace Functor
/-- Functors between categories of the same size define arrows in `Cat`. -/
def toCatHom {C D : Type u} [Category.{v} C] [Category.{v} D] (F : C ⥤ D) :
Cat.of C ⟶ Cat.of D := F
/-- Arrows in `Cat` define functors. -/
def ofCatHom {C D : Type} [Category C] [Category D] (F : Cat.of C ⟶ Cat.of D) : C ⥤ D := F
@[simp] theorem to_ofCatHom {C D : Type} [Category C] [Category D] (F : Cat.of C ⟶ Cat.of D) :
(ofCatHom F).toCatHom = F := rfl
@[simp] theorem of_toCatHom {C D : Type} [Category C] [Category D] (F : C ⥤ D) :
ofCatHom (F.toCatHom) = F := rfl
end Functor
namespace Cat
/-- Functor that gets the set of objects of a category. It is not
called `forget`, because it is not a faithful functor. -/
def objects : Cat.{v, u} ⥤ Type u where
obj C := C
map F := F.obj
/-- See through the defeq `objects.obj X = X`. -/
instance (X : Cat.{v, u}) : Category (objects.obj X) := inferInstanceAs <| Category X
section
attribute [local simp] eqToHom_map
/-- Any isomorphism in `Cat` induces an equivalence of the underlying categories. -/
def equivOfIso {C D : Cat} (γ : C ≅ D) : C ≌ D where
functor := γ.hom
inverse := γ.inv
unitIso := eqToIso <| Eq.symm γ.hom_inv_id
counitIso := eqToIso γ.inv_hom_id
/-- Under certain hypotheses, an equivalence of categories actually
defines an isomorphism in `Cat`. -/
@[simps]
def isoOfEquiv {C D : Cat.{v, u}} (e : C ≌ D)
(h₁ : ∀ (X : C), e.inverse.obj (e.functor.obj X) = X)
(h₂ : ∀ (Y : D), e.functor.obj (e.inverse.obj Y) = Y)
(h₃ : ∀ (X : C), e.unitIso.hom.app X = eqToHom (h₁ X).symm := by cat_disch)
(h₄ : ∀ (Y : D), e.counitIso.hom.app Y = eqToHom (h₂ Y) := by cat_disch) :
C ≅ D where
hom := e.functor
inv := e.inverse
hom_inv_id := (Functor.ext_of_iso e.unitIso (fun X ↦ (h₁ X).symm) h₃).symm
inv_hom_id := (Functor.ext_of_iso e.counitIso h₂ h₄)
end
end Cat
/-- Embedding `Type` into `Cat` as discrete categories.
This ought to be modelled as a 2-functor!
-/
@[simps]
def typeToCat : Type u ⥤ Cat where
obj X := Cat.of (Discrete X)
map := fun f => Discrete.functor (Discrete.mk ∘ f)
map_id X := by
apply Functor.ext
· intro X Y f
cases f
simp only [eqToHom_refl, Cat.id_map, Category.comp_id, Category.id_comp]
apply ULift.ext
cat_disch
· simp
map_comp f g := by apply Functor.ext; cat_disch
instance : Functor.Faithful typeToCat.{u} where
map_injective {_X} {_Y} _f _g h :=
funext fun x => congr_arg Discrete.as (Functor.congr_obj h ⟨x⟩)
instance : Functor.Full typeToCat.{u} where
map_surjective F := ⟨Discrete.as ∘ F.obj ∘ Discrete.mk, by
apply Functor.ext
· intro x y f
dsimp
apply ULift.ext
cat_disch
· rintro ⟨x⟩
apply Discrete.ext
rfl⟩
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Quiv.lean | import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.PathCategory.MorphismProperty
/-!
# The category of quivers
The category of (bundled) quivers, and the free/forgetful adjunction between `Cat` and `Quiv`.
-/
universe v u v₁ v₂ v₃ u₁ u₂ u₃ w
namespace CategoryTheory
-- intended to be used with explicit universe parameters
/-- Category of quivers. -/
@[nolint checkUnivs]
def Quiv :=
Bundled Quiver.{v + 1, u}
namespace Quiv
instance : CoeSort Quiv (Type u) where coe := Bundled.α
instance str' (C : Quiv.{v, u}) : Quiver.{v + 1, u} C :=
C.str
/-- Construct a bundled `Quiv` from the underlying type and the typeclass. -/
def of (C : Type u) [Quiver.{v + 1} C] : Quiv.{v, u} :=
Bundled.of C
instance : Inhabited Quiv :=
⟨Quiv.of (Quiver.Empty PEmpty)⟩
/-- Category structure on `Quiv` -/
instance category : LargeCategory.{max v u} Quiv.{v, u} where
Hom C D := Prefunctor C D
id C := Prefunctor.id C
comp F G := Prefunctor.comp F G
/-- The forgetful functor from categories to quivers. -/
@[simps]
def forget : Cat.{v, u} ⥤ Quiv.{v, u} where
obj C := Quiv.of C
map F := F.toPrefunctor
/-- The identity in the category of quivers equals the identity prefunctor. -/
theorem id_eq_id (X : Quiv) : 𝟙 X = 𝟭q X := rfl
/-- Composition in the category of quivers equals prefunctor composition. -/
theorem comp_eq_comp {X Y Z : Quiv} (F : X ⟶ Y) (G : Y ⟶ Z) : F ≫ G = F ⋙q G := rfl
end Quiv
namespace Prefunctor
/-- Prefunctors between quivers define arrows in `Quiv`. -/
def toQuivHom {C D : Type u} [Quiver.{v + 1} C] [Quiver.{v + 1} D] (F : C ⥤q D) :
Quiv.of C ⟶ Quiv.of D := F
/-- Arrows in `Quiv` define prefunctors. -/
def ofQuivHom {C D : Quiv} (F : C ⟶ D) : C ⥤q D := F
@[simp] theorem to_ofQuivHom {C D : Quiv} (F : C ⟶ D) : toQuivHom (ofQuivHom F) = F := rfl
@[simp] theorem of_toQuivHom {C D : Type} [Quiver C] [Quiver D] (F : C ⥤q D) :
ofQuivHom (toQuivHom F) = F := rfl
end Prefunctor
namespace Cat
/-- A prefunctor `V ⥤q W` induces a functor between the path categories defined by `F.mapPath`. -/
@[simps]
def freeMap {V W : Type*} [Quiver V] [Quiver W] (F : V ⥤q W) : Paths V ⥤ Paths W where
obj := F.obj
map := F.mapPath
map_comp f g := F.mapPath_comp f g
/-- The functor `free : Quiv ⥤ Cat` preserves identities up to natural isomorphism and in fact up
to equality. -/
@[simps!]
def freeMapIdIso (V : Type*) [Quiver V] : freeMap (𝟭q V) ≅ 𝟭 _ :=
NatIso.ofComponents (fun _ ↦ Iso.refl _)
theorem freeMap_id (V : Type*) [Quiver V] :
freeMap (𝟭q V) = 𝟭 _ :=
Functor.ext_of_iso (freeMapIdIso V) (fun _ ↦ rfl)
/-- The functor `free : Quiv ⥤ Cat` preserves composition up to natural isomorphism and in fact up
to equality. -/
@[simps!]
def freeMapCompIso {V₁ : Type u₁} {V₂ : Type u₂} {V₃ : Type u₃}
[Quiver.{v₁ + 1} V₁] [Quiver.{v₂ + 1} V₂] [Quiver.{v₃ + 1} V₃] (F : V₁ ⥤q V₂) (G : V₂ ⥤q V₃) :
freeMap (F ⋙q G) ≅ freeMap F ⋙ freeMap G :=
NatIso.ofComponents (fun _ ↦ Iso.refl _) (fun f ↦ by
dsimp
simp only [Category.comp_id, Category.id_comp, Prefunctor.mapPath_comp_apply])
theorem freeMap_comp {V₁ : Type u₁} {V₂ : Type u₂} {V₃ : Type u₃}
[Quiver.{v₁ + 1} V₁] [Quiver.{v₂ + 1} V₂] [Quiver.{v₃ + 1} V₃]
(F : V₁ ⥤q V₂) (G : V₂ ⥤q V₃) :
freeMap (F ⋙q G) = freeMap F ⋙ freeMap G :=
Functor.ext_of_iso (freeMapCompIso F G) (fun _ ↦ rfl)
/-- The functor sending each quiver to its path category. -/
@[simps]
def free : Quiv.{v, u} ⥤ Cat.{max u v, u} where
obj V := Cat.of (Paths V)
map F := Functor.toCatHom (freeMap (Prefunctor.ofQuivHom F))
map_id _ := freeMap_id _
map_comp _ _ := freeMap_comp _ _
end Cat
namespace Quiv
section
variable {V W : Quiv} (e : V ≅ W)
/-- An isomorphism of quivers defines an equivalence on carrier types. -/
@[simps]
def equivOfIso : V ≃ W where
toFun := e.hom.obj
invFun := e.inv.obj
left_inv := Prefunctor.congr_obj e.hom_inv_id
right_inv := Prefunctor.congr_obj e.inv_hom_id
@[simp]
lemma inv_obj_hom_obj_of_iso (X : V) : e.inv.obj (e.hom.obj X) = X := (equivOfIso e).left_inv X
@[simp]
lemma hom_obj_inv_obj_of_iso (Y : W) : e.hom.obj (e.inv.obj Y) = Y := (equivOfIso e).right_inv Y
lemma hom_map_inv_map_of_iso {V W : Quiv} (e : V ≅ W) {X Y : W} (f : X ⟶ Y) :
e.hom.map (e.inv.map f) = Quiver.homOfEq f (by simp) (by simp) := by
rw [← Prefunctor.comp_map]
exact (Prefunctor.congr_hom e.inv_hom_id.symm f).symm
lemma inv_map_hom_map_of_iso {V W : Quiv} (e : V ≅ W) {X Y : V} (f : X ⟶ Y) :
e.inv.map (e.hom.map f) = Quiver.homOfEq f (by simp) (by simp) :=
hom_map_inv_map_of_iso e.symm f
/-- An isomorphism of quivers defines an equivalence on hom types. -/
@[simps]
def homEquivOfIso {V W : Quiv} (e : V ≅ W) {X Y : V} :
(X ⟶ Y) ≃ (e.hom.obj X ⟶ e.hom.obj Y) where
toFun f := e.hom.map f
invFun g := Quiver.homOfEq (e.inv.map g) (by simp) (by simp)
left_inv f := by simp [inv_map_hom_map_of_iso]
right_inv g := by simp [hom_map_inv_map_of_iso]
end
section
variable {V W : Type u} [Quiver V] [Quiver W]
(e : V ≃ W) (he : ∀ X Y : V, (X ⟶ Y) ≃ (e X ⟶ e Y))
include he in
@[simp]
lemma homOfEq_map_homOfEq {X Y : V} (f : X ⟶ Y) {X' Y' : V} (hX : X = X') (hY : Y = Y')
{X'' Y'' : W} (hX' : e X' = X'') (hY' : e Y' = Y'') :
Quiver.homOfEq (he _ _ (Quiver.homOfEq f hX hY)) hX' hY' =
Quiver.homOfEq (he _ _ f) (by rw [hX, hX']) (by rw [hY, hY']) := by
subst hX hY hX' hY'
rfl
/-- Compatible equivalences of types and hom-types induce an isomorphism of quivers. -/
def isoOfEquiv : Quiv.of V ≅ Quiv.of W where
hom := Prefunctor.mk e (he _ _)
inv :=
{ obj := e.symm
map {X Y} f := (he _ _).symm (Quiver.homOfEq f (by simp) (by simp)) }
hom_inv_id := Prefunctor.ext' e.left_inv (fun X Y f ↦ by
dsimp [Quiv.id_eq_id, Quiv.comp_eq_comp]
apply (he _ _).injective
apply Quiver.homOfEq_injective (X' := e X) (Y' := e Y) (by simp) (by simp)
simp)
inv_hom_id := Prefunctor.ext' e.right_inv (by simp [Quiv.id_eq_id, Quiv.comp_eq_comp])
end
/-- Any prefunctor into a category lifts to a functor from the path category. -/
@[simps]
def lift {V : Type u} [Quiver.{v + 1} V] {C : Type u₁} [Category.{v₁} C]
(F : Prefunctor V C) : Paths V ⥤ C where
obj X := F.obj X
map f := composePath (F.mapPath f)
/-- Naturality of `pathComposition`. -/
def pathCompositionNaturality {C : Type u} {D : Type u₁}
[Category.{v} C] [Category.{v₁} D] (F : C ⥤ D) :
Cat.freeMap (F.toPrefunctor) ⋙ pathComposition D ≅ pathComposition C ⋙ F :=
Paths.liftNatIso (fun _ ↦ Iso.refl _) (by simp)
/-- Naturality of `pathComposition`, which defines a natural transformation
`Quiv.forget ⋙ Cat.free ⟶ 𝟭 _`. -/
theorem pathComposition_naturality {C : Type u} {D : Type u₁}
[Category.{v} C] [Category.{v₁} D]
(F : C ⥤ D) : Cat.freeMap (F.toPrefunctor) ⋙ pathComposition D = pathComposition C ⋙ F :=
Paths.ext_functor rfl (by simp)
/-- Naturality of `Paths.of`, which defines a natural transformation
` 𝟭 _⟶ Cat.free ⋙ Quiv.forget`. -/
lemma pathsOf_freeMap_toPrefunctor
{V : Type u} {W : Type u₁} [Quiver.{v + 1} V] [Quiver.{v₁ + 1} W] (F : V ⥤q W) :
Paths.of V ⋙q (Cat.freeMap F).toPrefunctor = F ⋙q Paths.of W := rfl
/-- The left triangle identity of `Cat.free ⊣ Quiv.forget` as a natural isomorphism -/
def freeMapPathsOfCompPathCompositionIso (V : Type u) [Quiver.{v + 1} V] :
Cat.freeMap (Paths.of V) ⋙ pathComposition (Paths V) ≅ 𝟭 (Paths V) :=
Paths.liftNatIso (fun v ↦ Iso.refl _) (by simp)
lemma freeMap_pathsOf_pathComposition (V : Type u) [Quiver.{v + 1} V] :
Cat.freeMap (Paths.of (V := V)) ⋙ pathComposition (Paths V) = 𝟭 (Paths V) :=
Paths.ext_functor rfl (by simp)
/-- An unbundled version of the right triangle equality. -/
lemma pathsOf_pathComposition_toPrefunctor (C : Type u) [Category.{v} C] :
Paths.of C ⋙q (pathComposition C).toPrefunctor = 𝟭q C := by
dsimp only [Prefunctor.comp]
congr
funext X Y f
exact Category.id_comp _
/--
The adjunction between forming the free category on a quiver, and forgetting a category to a quiver.
-/
def adj : Cat.free ⊣ Quiv.forget :=
Adjunction.mkOfUnitCounit {
unit := { app _ := Paths.of _}
counit := {
app C := pathComposition C
naturality _ _ F := pathComposition_naturality F
}
left_triangle := by
ext V
exact freeMap_pathsOf_pathComposition V
right_triangle := by
ext C
exact pathsOf_pathComposition_toPrefunctor C
}
/-- The universal property of the path category of a quiver. -/
def pathsEquiv {V : Type u} {C : Type u₁} [Quiver.{v + 1} V] [Category.{v₁} C] :
(Paths V ⥤ C) ≃ V ⥤q C where
toFun F := (Paths.of V).comp F.toPrefunctor
invFun G := Cat.freeMap G ⋙ pathComposition C
left_inv F := by
dsimp
rw [Cat.freeMap_comp, Functor.assoc, pathComposition_naturality, ← Functor.assoc,
freeMap_pathsOf_pathComposition, Functor.id_comp]
right_inv G := by
dsimp
rw [← Functor.toPrefunctor_comp, ← Prefunctor.comp_assoc,
pathsOf_freeMap_toPrefunctor, Prefunctor.comp_assoc,
pathsOf_pathComposition_toPrefunctor, Prefunctor.comp_id]
@[simp]
lemma adj_homEquiv {V C : Type u} [Quiver.{max u v + 1} V] [Category.{max u v} C] :
adj.homEquiv (Quiv.of V) (Cat.of C) = pathsEquiv (V := V) (C := C) := rfl
end Quiv
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Preorder.lean | import Mathlib.CategoryTheory.Equivalence
import Mathlib.CategoryTheory.EqToHom
import Mathlib.Order.Hom.Basic
import Mathlib.Data.ULift
/-!
# Preorders as categories
We install a category instance on any preorder. This is not to be confused with the category _of_
preorders, defined in `Order.Category.Preorder`.
We show that monotone functions between preorders correspond to functors of the associated
categories.
## Main definitions
* `homOfLE` and `leOfHom` provide translations between inequalities in the preorder, and
morphisms in the associated category.
* `Monotone.functor` is the functor associated to a monotone function.
-/
universe u v
namespace Preorder
open CategoryTheory
-- see Note [lower instance priority]
/--
The category structure coming from a preorder. There is a morphism `X ⟶ Y` if and only if `X ≤ Y`.
Because we don't allow morphisms to live in `Prop`,
we have to define `X ⟶ Y` as `ULift (PLift (X ≤ Y))`.
See `CategoryTheory.homOfLE` and `CategoryTheory.leOfHom`. -/
@[stacks 00D3]
instance (priority := 100) smallCategory (α : Type u) [Preorder α] : SmallCategory α where
Hom U V := ULift (PLift (U ≤ V))
id X := ⟨⟨le_refl X⟩⟩
comp f g := ⟨⟨le_trans _ _ _ f.down.down g.down.down⟩⟩
instance subsingleton_hom {α : Type u} [Preorder α] (U V : α) : Subsingleton (U ⟶ V) :=
⟨fun _ _ => ULift.ext _ _ (Subsingleton.elim _ _ )⟩
end Preorder
namespace CategoryTheory
open Opposite
variable {X : Type u} [Preorder X]
/-- Express an inequality as a morphism in the corresponding preorder category. -/
def homOfLE {x y : X} (h : x ≤ y) : x ⟶ y :=
ULift.up (PLift.up h)
@[inherit_doc homOfLE]
abbrev _root_.LE.le.hom := @homOfLE
@[simp]
theorem homOfLE_refl {x : X} (h : x ≤ x) : h.hom = 𝟙 x :=
rfl
@[simp]
theorem homOfLE_comp {x y z : X} (h : x ≤ y) (k : y ≤ z) :
homOfLE h ≫ homOfLE k = homOfLE (h.trans k) :=
rfl
/-- Extract the underlying inequality from a morphism in a preorder category. -/
theorem leOfHom {x y : X} (h : x ⟶ y) : x ≤ y :=
h.down.down
@[nolint defLemma, inherit_doc leOfHom]
abbrev _root_.Quiver.Hom.le := @leOfHom
@[simp]
theorem homOfLE_leOfHom {x y : X} (h : x ⟶ y) : h.le.hom = h :=
rfl
lemma homOfLE_isIso_of_eq {x y : X} (h : x ≤ y) (heq : x = y) :
IsIso (homOfLE h) :=
⟨homOfLE (le_of_eq heq.symm), by simp⟩
@[simp, reassoc]
lemma homOfLE_comp_eqToHom {a b c : X} (hab : a ≤ b) (hbc : b = c) :
homOfLE hab ≫ eqToHom hbc = homOfLE (hab.trans (le_of_eq hbc)) :=
rfl
@[simp, reassoc]
lemma eqToHom_comp_homOfLE {a b c : X} (hab : a = b) (hbc : b ≤ c) :
eqToHom hab ≫ homOfLE hbc = homOfLE ((le_of_eq hab).trans hbc) :=
rfl
@[simp, reassoc]
lemma homOfLE_op_comp_eqToHom {a b c : X} (hab : b ≤ a) (hbc : op b = op c) :
(homOfLE hab).op ≫ eqToHom hbc = (homOfLE ((le_of_eq (op_injective hbc.symm)).trans hab)).op :=
rfl
@[simp, reassoc]
lemma eqToHom_comp_homOfLE_op {a b c : X} (hab : op a = op b) (hbc : c ≤ b) :
eqToHom hab ≫ (homOfLE hbc).op = (homOfLE (hbc.trans (le_of_eq (op_injective hab.symm)))).op :=
rfl
/-- Construct a morphism in the opposite of a preorder category from an inequality. -/
def opHomOfLE {x y : Xᵒᵖ} (h : unop x ≤ unop y) : y ⟶ x :=
(homOfLE h).op
theorem le_of_op_hom {x y : Xᵒᵖ} (h : x ⟶ y) : unop y ≤ unop x :=
h.unop.le
instance uniqueToTop [OrderTop X] {x : X} : Unique (x ⟶ ⊤) where
default := homOfLE le_top
uniq := fun a => by rfl
instance uniqueFromBot [OrderBot X] {x : X} : Unique (⊥ ⟶ x) where
default := homOfLE bot_le
uniq := fun a => by rfl
variable (X) in
/-- The equivalence of categories from the order dual of a preordered type `X`
to the opposite category of the preorder `X`. -/
@[simps]
def orderDualEquivalence : Xᵒᵈ ≌ Xᵒᵖ where
functor :=
{ obj := fun x => op (OrderDual.ofDual x)
map := fun f => (homOfLE (leOfHom f)).op }
inverse :=
{ obj := fun x => OrderDual.toDual x.unop
map := fun f => (homOfLE (leOfHom f.unop)) }
unitIso := Iso.refl _
counitIso := Iso.refl _
end CategoryTheory
section
open CategoryTheory
variable {X : Type u} {Y : Type v} [Preorder X] [Preorder Y]
/-- A monotone function between preorders induces a functor between the associated categories. -/
def Monotone.functor {f : X → Y} (h : Monotone f) : X ⥤ Y where
obj := f
map g := CategoryTheory.homOfLE (h g.le)
@[simp]
theorem Monotone.functor_obj {f : X → Y} (h : Monotone f) : h.functor.obj = f :=
rfl
-- Faithfulness is automatic because preorder categories are thin
instance (f : X ↪o Y) : f.monotone.functor.Full where
map_surjective h := ⟨homOfLE (f.map_rel_iff.1 h.le), rfl⟩
/-- The equivalence of categories `X ≌ Y` induced by `e : X ≃o Y`. -/
@[simps]
def OrderIso.equivalence (e : X ≃o Y) : X ≌ Y where
functor := e.monotone.functor
inverse := e.symm.monotone.functor
unitIso := NatIso.ofComponents (fun _ ↦ eqToIso (by simp))
counitIso := NatIso.ofComponents (fun _ ↦ eqToIso (by simp))
end
section Preorder
variable {X : Type u} {Y : Type v} [Preorder X] [Preorder Y]
namespace CategoryTheory.Functor
/-- A functor between preorder categories is monotone. -/
@[mono]
theorem monotone (f : X ⥤ Y) : Monotone f.obj := fun _ _ hxy => (f.map hxy.hom).le
/-- A functor `X ⥤ Y` between preorder categories as an `OrderHom`. -/
@[simps!]
def toOrderHom (F : X ⥤ Y) : X →o Y where
toFun := F.obj
monotone' := F.monotone
end CategoryTheory.Functor
namespace OrderHom
open CategoryTheory
/-- An `OrderHom` as a functor `X ⥤ Y` between preorder categories. -/
abbrev toFunctor (f : X →o Y) : X ⥤ Y := f.monotone.functor
/-- The equivalence between `X →o Y` and the type of functors `X ⥤ Y` between preorder categories
`X` and `Y`. -/
@[simps]
def equivFunctor : (X →o Y) ≃ (X ⥤ Y) where
toFun := toFunctor
invFun F := F.toOrderHom
/-- The categorical equivalence between the category of monotone functions `X →o Y` and the category
of functors `X ⥤ Y`, where `X` and `Y` are preorder categories. -/
@[simps! functor_obj_obj inverse_obj unitIso_hom_app unitIso_inv_app counitIso_inv_app_app
counitIso_hom_app_app]
def equivalenceFunctor : (X →o Y) ≌ (X ⥤ Y) where
functor :=
{ obj f := f.toFunctor
map f := { app x := homOfLE <| leOfHom f x } }
inverse :=
{ obj F := F.toOrderHom
map f := homOfLE fun x ↦ leOfHom <| f.app x }
unitIso := Iso.refl _
counitIso := Iso.refl _
end OrderHom
end Preorder
section PartialOrder
namespace CategoryTheory
variable {X : Type u} {Y : Type v} [PartialOrder X] [PartialOrder Y]
theorem Iso.to_eq {x y : X} (f : x ≅ y) : x = y :=
le_antisymm f.hom.le f.inv.le
/-- A categorical equivalence between partial orders is just an order isomorphism. -/
def Equivalence.toOrderIso (e : X ≌ Y) : X ≃o Y where
toFun := e.functor.obj
invFun := e.inverse.obj
left_inv a := (e.unitIso.app a).to_eq.symm
right_inv b := (e.counitIso.app b).to_eq
map_rel_iff' {a a'} :=
⟨fun h =>
((Equivalence.unit e).app a ≫ e.inverse.map h.hom ≫ (Equivalence.unitInv e).app a').le,
fun h : a ≤ a' => (e.functor.map h.hom).le⟩
-- `@[simps]` on `Equivalence.toOrderIso` produces lemmas that fail the `simpNF` linter,
-- so we provide them by hand:
@[simp]
theorem Equivalence.toOrderIso_apply (e : X ≌ Y) (x : X) : e.toOrderIso x = e.functor.obj x :=
rfl
@[simp]
theorem Equivalence.toOrderIso_symm_apply (e : X ≌ Y) (y : Y) :
e.toOrderIso.symm y = e.inverse.obj y :=
rfl
end CategoryTheory
end PartialOrder
open CategoryTheory
lemma PartialOrder.isIso_iff_eq {X : Type u} [PartialOrder X]
{a b : X} (f : a ⟶ b) : IsIso f ↔ a = b := by
constructor
· intro _
exact (asIso f).to_eq
· rintro rfl
rw [Subsingleton.elim f (𝟙 _)]
infer_instance |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat/Colimit.lean | import Mathlib.AlgebraicTopology.SimplicialSet.NerveAdjunction
import Mathlib.CategoryTheory.Monad.Limits
/-!
# The category of small categories has all small colimits.
In this file, the existence of colimits in `Cat` is deduced from the existence of colimits in the
category of simplicial sets. Indeed, `Cat` identifies to a reflective subcategory of the category
of simplicial sets (see `AlgebraicTopology.SimplicialSet.NerveAdjunction`), so that colimits in
`Cat` can be computed by passing to nerves, taking the colimit in `SSet` and finally applying the
homotopy category functor `SSet ⥤ Cat`.
-/
noncomputable section
universe v
open CategoryTheory.Limits
namespace CategoryTheory
namespace Cat
/-- The category of small categories has all small colimits as a reflective subcategory of the
category of simplicial sets, which has all small colimits. -/
instance : HasColimits Cat.{v, v} :=
hasColimits_of_reflective nerveFunctor
end Cat
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat/Limit.lean | import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Limits.Types.Limits
import Mathlib.CategoryTheory.Limits.Preserves.Basic
/-!
# The category of small categories has all small limits.
An object in the limit consists of a family of objects,
which are carried to one another by the functors in the diagram.
A morphism between two such objects is a family of morphisms between the corresponding objects,
which are carried to one another by the action on morphisms of the functors in the diagram.
## Future work
Can the indexing category live in a lower universe?
-/
noncomputable section
universe v u
open CategoryTheory.Limits
namespace CategoryTheory
variable {J : Type v} [SmallCategory J]
namespace Cat
namespace HasLimits
instance categoryObjects {F : J ⥤ Cat.{u, u}} {j} :
SmallCategory ((F ⋙ Cat.objects.{u, u}).obj j) :=
(F.obj j).str
/-- Auxiliary definition:
the diagram whose limit gives the morphism space between two objects of the limit category. -/
@[simps]
def homDiagram {F : J ⥤ Cat.{v, v}} (X Y : limit (F ⋙ Cat.objects.{v, v})) : J ⥤ Type v where
obj j := limit.π (F ⋙ Cat.objects) j X ⟶ limit.π (F ⋙ Cat.objects) j Y
map f g := by
refine eqToHom ?_ ≫ (F.map f).map g ≫ eqToHom ?_
· exact (congr_fun (limit.w (F ⋙ Cat.objects) f) X).symm
· exact congr_fun (limit.w (F ⋙ Cat.objects) f) Y
map_id X := by
funext f
letI : Category (objects.obj (F.obj X)) := (inferInstance : Category (F.obj X))
simp [Functor.congr_hom (F.map_id X) f]
map_comp {_ _ Z} f g := by
funext h
letI : Category (objects.obj (F.obj Z)) := (inferInstance : Category (F.obj Z))
simp [Functor.congr_hom (F.map_comp f g) h, eqToHom_map]
@[simps]
instance (F : J ⥤ Cat.{v, v}) : Category (limit (F ⋙ Cat.objects)) where
Hom X Y := limit (homDiagram X Y)
id X := Types.Limit.mk.{v, v} (homDiagram X X) (fun _ => 𝟙 _) fun j j' f => by simp
comp {X Y Z} f g :=
Types.Limit.mk.{v, v} (homDiagram X Z)
(fun j => limit.π (homDiagram X Y) j f ≫ limit.π (homDiagram Y Z) j g) fun j j' h => by
simp [← congr_fun (limit.w (homDiagram X Y) h) f,
← congr_fun (limit.w (homDiagram Y Z) h) g]
id_comp _ := by
apply Types.limit_ext.{v, v}
simp
comp_id _ := by
apply Types.limit_ext.{v, v}
simp
/-- Auxiliary definition: the limit category. -/
@[simps]
def limitConeX (F : J ⥤ Cat.{v, v}) : Cat.{v, v} where α := limit (F ⋙ Cat.objects)
/-- Auxiliary definition: the cone over the limit category. -/
@[simps]
def limitCone (F : J ⥤ Cat.{v, v}) : Cone F where
pt := limitConeX F
π :=
{ app := fun j =>
{ obj := limit.π (F ⋙ Cat.objects) j
map := fun f => limit.π (homDiagram _ _) j f }
naturality := fun _ _ f =>
CategoryTheory.Functor.ext (fun X => (congr_fun (limit.w (F ⋙ Cat.objects) f) X).symm)
fun X Y h => (congr_fun (limit.w (homDiagram X Y) f) h).symm }
/-- Auxiliary definition: the universal morphism to the proposed limit cone. -/
@[simps]
def limitConeLift (F : J ⥤ Cat.{v, v}) (s : Cone F) : s.pt ⟶ limitConeX F where
obj :=
limit.lift (F ⋙ Cat.objects)
{ pt := s.pt
π :=
{ app := fun j => (s.π.app j).obj
naturality := fun _ _ f => objects.congr_map (s.π.naturality f) } }
map f := by
fapply Types.Limit.mk.{v, v}
· intro j
refine eqToHom ?_ ≫ (s.π.app j).map f ≫ eqToHom ?_ <;> simp
· intro j j' h
dsimp
simp only [Category.assoc, Functor.map_comp, eqToHom_map, eqToHom_trans,
eqToHom_trans_assoc, ← Functor.comp_map]
have := (s.π.naturality h).symm
dsimp at this
rw [Category.id_comp] at this
erw [Functor.congr_hom this f]
simp
@[simp]
theorem limit_π_homDiagram_eqToHom {F : J ⥤ Cat.{v, v}} (X Y : limit (F ⋙ Cat.objects.{v, v}))
(j : J) (h : X = Y) :
limit.π (homDiagram X Y) j (eqToHom h) =
eqToHom (congr_arg (limit.π (F ⋙ Cat.objects.{v, v}) j) h) := by
subst h
simp
/-- Auxiliary definition: the proposed cone is a limit cone. -/
def limitConeIsLimit (F : J ⥤ Cat.{v, v}) : IsLimit (limitCone F) where
lift := limitConeLift F
fac s j := CategoryTheory.Functor.ext (by simp) fun X Y f => by
dsimp [limitConeLift]
exact Types.Limit.π_mk.{v, v} _ _ _ _
uniq s m w := by
symm
refine CategoryTheory.Functor.ext ?_ ?_
· intro X
apply Types.limit_ext.{v, v}
intro j
simp [← w j]
· intro X Y f
simp [fun j => Functor.congr_hom (w j).symm f]
end HasLimits
/-- The category of small categories has all small limits. -/
instance : HasLimits Cat.{v, v} where
has_limits_of_shape _ :=
{ has_limit := fun F => ⟨⟨⟨HasLimits.limitCone F, HasLimits.limitConeIsLimit F⟩⟩⟩ }
instance : PreservesLimits Cat.objects.{v, v} where
preservesLimitsOfShape :=
{ preservesLimit := fun {F} =>
preservesLimit_of_preserves_limit_cone (HasLimits.limitConeIsLimit F)
(Limits.IsLimit.ofIsoLimit (limit.isLimit (F ⋙ Cat.objects))
(Cones.ext (by rfl) (by cat_disch))) }
end Cat
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat/AsSmall.lean | import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Category.ULift
/-!
# Functorially embedding `Cat` into the category of small categories
There is a canonical functor `asSmallFunctor` between the category of categories of any size and
any larger category of small categories.
## Future Work
Show that `asSmallFunctor` is faithful.
-/
universe w v u
namespace CategoryTheory
namespace Cat
/-- Assigning to each category `C` the small category `AsSmall C` induces a functor `Cat ⥤ Cat`. -/
@[simps]
def asSmallFunctor : Cat.{v, u} ⥤ Cat.{max w v u, max w v u} where
obj C := .of <| AsSmall C
map F := AsSmall.down ⋙ F ⋙ AsSmall.up
end Cat
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat/Terminal.lean | import Mathlib.CategoryTheory.Limits.Shapes.Terminal
/-!
# Terminal categories
We prove that a category is terminal if its underlying type has a `Unique` structure and the
category has an `IsDiscrete` instance.
We then use this to provide various examples of terminal categories.
TODO: Show the converse: that terminal categories have a unique object and are discrete.
TODO: Provide an analogous characterization of terminal categories as codiscrete categories
with a unique object.
-/
universe v u v' u'
open CategoryTheory Limits Functor
namespace CategoryTheory.Cat
/-- A discrete category with a unique object is terminal. -/
def isTerminalOfUniqueOfIsDiscrete {T : Type u} [Category.{v} T] [Unique T] [IsDiscrete T] :
IsTerminal (Cat.of T) :=
IsTerminal.ofUniqueHom (fun X ↦ (const X).obj (default : T))
(fun _ _ ↦ Functor.ext (by simp [eq_iff_true_of_subsingleton]))
instance : HasTerminal Cat.{v, u} := by
have : IsDiscrete (ShrinkHoms.{u} PUnit.{u + 1}) := {
subsingleton _ _ := { allEq _ _ := eq_of_comp_right_eq (congrFun rfl) }
eq_of_hom _ := rfl
}
exact IsTerminal.hasTerminal (X := Cat.of (ShrinkHoms PUnit)) isTerminalOfUniqueOfIsDiscrete
/-- Any `T : Cat.{u, u}` with a unique object and discrete homs is isomorphic to `⊤_ Cat.{u, u}.` -/
noncomputable def terminalIsoOfUniqueOfIsDiscrete
{T : Type u} [Category.{v} T] [Unique T] [IsDiscrete T] : ⊤_ Cat.{v, u} ≅ Cat.of T :=
terminalIsoIsTerminal isTerminalOfUniqueOfIsDiscrete
/-- The discrete category on `PUnit` is terminal. -/
def isTerminalDiscretePUnit : IsTerminal (Cat.of (Discrete PUnit)) :=
isTerminalOfUniqueOfIsDiscrete
/-- Any terminal object `T : Cat.{u, u}` is isomorphic to `Cat.of (Discrete PUnit)`. -/
def isoDiscretePUnitOfIsTerminal {T : Type u} [Category.{u} T] (hT : IsTerminal (Cat.of T)) :
Cat.of T ≅ Cat.of (Discrete PUnit) :=
IsTerminal.uniqueUpToIso hT isTerminalDiscretePUnit
end CategoryTheory.Cat |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat/Op.lean | import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Opposites
/-!
# The dualizing functor on `Cat`
We define a (strict) functor `opFunctor` and an equivalence assigning opposite categories to
categories. We then show that this functor is strictly involutive and that it induces an
equivalence on `Cat`.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
namespace Cat
/-- The endofunctor `Cat ⥤ Cat` assigning to each category its opposite category. -/
@[simps]
def opFunctor : Cat.{v₁, u₁} ⥤ Cat.{v₁, u₁} where
obj C := .of Cᵒᵖ
map := Functor.op
/-- The natural isomorphism between the double application of `Cat.opFunctor` and the
identity functor on `Cat`. -/
@[simps!]
def opFunctorInvolutive : opFunctor.{v₁, u₁} ⋙ opFunctor.{v₁, u₁} ≅ 𝟭 _ :=
NatIso.ofComponents (fun C => .mk (unopUnop C) (opOp C))
/-- The equivalence `Cat ≌ Cat` associating each category with its opposite category. -/
@[simps]
def opEquivalence : Cat.{v₁, u₁} ≌ Cat.{v₁, u₁} where
functor := opFunctor
inverse := opFunctor
unitIso := NatIso.ofComponents (fun _ => Iso.mk (opOp _) (unopUnop _))
counitIso := NatIso.ofComponents (fun _ => Iso.mk (unopUnop _) (opOp _))
end Cat
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat/CartesianClosed.lean | import Mathlib.CategoryTheory.Closed.Cartesian
import Mathlib.CategoryTheory.Functor.Currying
import Mathlib.CategoryTheory.Monoidal.Cartesian.Cat
/-!
# Cartesian closed structure on `Cat`
The category of small categories is Cartesian closed, with the exponential at a category `C`
defined by the functor category mapping out of `C`.
Adjoint transposition is defined by currying and uncurrying.
TODO: It would be useful to investigate and formalize further compatibilities along the
lines of `Cat.ihom_obj` and `Cat.ihom_map`, relating currying of functors with currying in
monoidal closed categories and precomposition with left whiskering. These may not be
definitional equalities but may have to be phrased using `eqToIso`.
-/
universe v u v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace CategoryTheory
open Functor Cat
namespace Cat
variable (C : Type u) [Category.{v} C]
/-- A category `C` induces a functor from `Cat` to itself defined
by forming the category of functors out of `C`. -/
@[simps]
def exp : Cat ⥤ Cat where
obj D := Cat.of (C ⥤ D)
map F := (whiskeringRight _ _ _).obj F
end Cat
section
variable {B : Type u₁} [Category.{v₁} B] {C : Type u₂} [Category.{v₂} C] {D : Type u₃}
[Category.{v₃} D] {E : Type u₄} [Category.{v₄} E]
/-- The isomorphism of categories of bifunctors given by currying. -/
@[simps!]
def curryingIso : Cat.of (C ⥤ D ⥤ E) ≅ Cat.of (C × D ⥤ E) :=
isoOfEquiv currying Functor.curry_obj_uncurry_obj Functor.uncurry_obj_curry_obj
/-- The isomorphism of categories of bifunctors given by flipping the arguments. -/
@[simps!]
def flippingIso : Cat.of (C ⥤ D ⥤ E) ≅ Cat.of (D ⥤ C ⥤ E) :=
isoOfEquiv flipping Functor.flip_flip Functor.flip_flip
end
namespace Cat
section
variable (C : Type u) [Category.{u} C]
instance closed : Closed (Cat.of C) where
rightAdj := exp C
adj := Adjunction.mkOfHomEquiv
{ homEquiv _ _ := curryingFlipEquiv.symm
homEquiv_naturality_left_symm := comp_flip_uncurry_eq
homEquiv_naturality_right := curry_obj_comp_flip }
instance cartesianClosed : CartesianClosed Cat.{u, u} where
closed C := closed C
@[simp]
lemma ihom_obj (D : Type u) [Category.{u} D] :
(ihom (Cat.of C)).obj (Cat.of D) = Cat.of (C ⥤ D) := rfl
@[simp]
lemma ihom_map {D E : Type u} [Category.{u} D] [Category.{u} E] (F : D ⥤ E) :
(ihom (Cat.of C)).map F.toCatHom = (whiskeringRight _ _ _).obj F := rfl
end
end Cat
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Category/Cat/Adjunction.lean | import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.ConnectedComponents
/-!
# Adjunctions related to Cat, the category of categories
The embedding `typeToCat: Type ⥤ Cat`, mapping a type to the corresponding discrete category, is
left adjoint to the functor `Cat.objects`, which maps a category to its set of objects.
Another functor `connectedComponents : Cat ⥤ Type` maps a category to the set of its connected
components and functors to functions between those sets.
## Notes
All this could be made with 2-functors
-/
universe v u
namespace CategoryTheory.Cat
variable (X : Type u) (C : Cat)
private def typeToCatObjectsAdjHomEquiv : (typeToCat.obj X ⟶ C) ≃ (X ⟶ Cat.objects.obj C) where
toFun f x := f.obj ⟨x⟩
invFun := Discrete.functor
left_inv F := Functor.ext (fun _ ↦ rfl) (fun ⟨_⟩ ⟨_⟩ f => by
obtain rfl := Discrete.eq_of_hom f
simp)
private def typeToCatObjectsAdjCounitApp : (Cat.objects ⋙ typeToCat).obj C ⥤ C where
obj := Discrete.as
map := eqToHom ∘ Discrete.eq_of_hom
/-- `typeToCat : Type ⥤ Cat` is left adjoint to `Cat.objects : Cat ⥤ Type` -/
def typeToCatObjectsAdj : typeToCat ⊣ Cat.objects :=
Adjunction.mk' {
homEquiv := typeToCatObjectsAdjHomEquiv
unit := { app:= fun _ ↦ Discrete.mk }
counit := {
app := typeToCatObjectsAdjCounitApp
naturality := fun _ _ _ ↦ Functor.hext (fun _ ↦ rfl)
(by intro ⟨_⟩ ⟨_⟩ f
obtain rfl := Discrete.eq_of_hom f
cat_disch ) } }
/-- The connected components functor -/
def connectedComponents : Cat.{v, u} ⥤ Type u where
obj C := ConnectedComponents C
map F := Functor.mapConnectedComponents F
map_id _ := funext fun x ↦ (Quotient.exists_rep x).elim (fun _ h ↦ by subst h; rfl)
map_comp _ _ := funext fun x ↦ (Quotient.exists_rep x).elim (fun _ h => by subst h; rfl)
/-- `typeToCat : Type ⥤ Cat` is right adjoint to `connectedComponents : Cat ⥤ Type` -/
def connectedComponentsTypeToCatAdj : connectedComponents ⊣ typeToCat :=
Adjunction.mk' {
homEquiv := fun C X ↦ ConnectedComponents.typeToCatHomEquiv C X
unit :=
{ app:= fun C ↦ ConnectedComponents.functorToDiscrete _ (𝟙 (connectedComponents.obj C)) }
counit := {
app := fun X => ConnectedComponents.liftFunctor _ (𝟙 typeToCat.obj X)
naturality := fun _ _ _ =>
funext (fun xcc => by
obtain ⟨x,h⟩ := Quotient.exists_rep xcc
cat_disch) }
homEquiv_counit := fun {C X G} => by
funext cc
obtain ⟨_, _⟩ := Quotient.exists_rep cc
cat_disch }
end CategoryTheory.Cat |
.lake/packages/mathlib/Mathlib/CategoryTheory/Groupoid/FreeGroupoidOfCategory.lean | import Mathlib.CategoryTheory.Groupoid.FreeGroupoid
import Mathlib.CategoryTheory.Category.Grpd
import Mathlib.CategoryTheory.Adjunction.Reflective
import Mathlib.CategoryTheory.Localization.Predicate
/-!
# Free groupoid on a category
This file defines the free groupoid on a category, the lifting of a functor to its unique
extension as a functor from the free groupoid, and proves uniqueness of this extension.
## Main results
Given a type `C` and a category instance on `C`:
- `CategoryTheory.FreeGroupoid C`: the underlying type of the free groupoid on `C`.
- `CategoryTheory.FreeGroupoid.instGroupoid`: the `Groupoid` instance on `FreeGroupoid C`.
- `CategoryTheory.FreeGroupoid.lift`: the lifting of a functor `C ⥤ G` where `G` is a
groupoid, to a functor `CategoryTheory.FreeGroupoid C ⥤ G`.
- `CategoryTheory.FreeGroupoid.lift_spec` and
`CategoryTheory.FreeGroupoid.lift_unique`:
the proofs that, respectively, `CategoryTheory.FreeGroupoid.lift` indeed is a lifting
and is the unique one.
- `CategoryTheory.Grpd.free`: the free functor from `Grpd` to `Cat`
- `CategoryTheory.Grpd.freeForgetAdjunction`: that `free` is left adjoint to
`Grpd.forgetToCat`.
## Implementation notes
The free groupoid on a category `C` is first defined by taking the free groupoid `G`
on the underlying *quiver* of `C`. Then the free groupoid on the *category* `C` is defined as
the quotient of `G` by the relation that makes the inclusion prefunctor `C ⥤q G` a functor.
-/
noncomputable section
namespace CategoryTheory
universe v u v₁ u₁ v₂ u₂
variable (C : Type u) [Category.{v} C]
open Quiver in
/-- The relation on the free groupoid on the underlying *quiver* of C that
promotes the prefunctor `C ⥤q FreeGroupoid C` into a functor
`C ⥤ Quotient (FreeGroupoid.homRel C)`. -/
inductive FreeGroupoid.homRel : HomRel (Quiver.FreeGroupoid C) where
| map_id (X : C) : homRel ((FreeGroupoid.of C).map (𝟙 X)) (𝟙 ((FreeGroupoid.of C).obj X))
| map_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : homRel ((FreeGroupoid.of C).map (f ≫ g))
((FreeGroupoid.of C).map f ≫ (FreeGroupoid.of C).map g)
/-- The underlying type of the free groupoid on a category,
defined by quotienting the free groupoid on the underlying quiver of `C`
by the relation that promotes the prefunctor `C ⥤q FreeGroupoid C` into a functor
`C ⥤ Quotient (FreeGroupoid.homRel C)`. -/
def FreeGroupoid := Quotient (FreeGroupoid.homRel C)
instance [Nonempty C] : Nonempty (FreeGroupoid C) :=
⟨Quotient.mk (Quotient.mk ((Paths.of _).obj (Classical.arbitrary C)))⟩
instance : Groupoid (FreeGroupoid C) :=
Quotient.groupoid (FreeGroupoid.homRel C)
namespace FreeGroupoid
/-- The localization functor from the category `C` to the groupoid `FreeGroupoid C` -/
def of : C ⥤ FreeGroupoid C where
__ := Quiver.FreeGroupoid.of C ⋙q (Quotient.functor (FreeGroupoid.homRel C)).toPrefunctor
map_id X := Quotient.sound _ (FreeGroupoid.homRel.map_id X)
map_comp f g := Quotient.sound _ (FreeGroupoid.homRel.map_comp f g)
variable {C}
/-- Construct an object in the free groupoid on `C` by providing an object in `C`. -/
abbrev mk (X : C) : FreeGroupoid C := (of C).obj X
/-- Construct a morphism in the free groupoid on `C` by providing a morphism in `C`. -/
abbrev homMk {X Y : C} (f : X ⟶ Y) : mk X ⟶ mk Y := (of C).map f
lemma eq_mk (X : FreeGroupoid C) : X = .mk (X.as.as) := rfl
lemma of_obj_bijective : Function.Bijective (of C).obj where
left _ _ h := by cases h; rfl
right X := ⟨X.as.as, rfl⟩
section UniversalProperty
variable {G : Type u₁} [Groupoid.{v₁} G]
/-- The lift of a functor from `C` to a groupoid to a functor from
`FreeGroupoid C` to the groupoid -/
def lift (φ : C ⥤ G) : FreeGroupoid C ⥤ G :=
Quotient.lift (FreeGroupoid.homRel C) (Quiver.FreeGroupoid.lift φ.toPrefunctor)
(fun _ _ f g r ↦ by
have {X Y : C} (f : X ⟶ Y) :=
Prefunctor.congr_hom (Quiver.FreeGroupoid.lift_spec φ.toPrefunctor) f
induction r <;> cat_disch)
theorem lift_spec (φ : C ⥤ G) : of C ⋙ lift φ = φ :=
Functor.toPrefunctor_injective (by
change Quiver.FreeGroupoid.of C ⋙q
(Quotient.functor (FreeGroupoid.homRel C)).toPrefunctor ⋙q
(lift φ).toPrefunctor = φ.toPrefunctor
simp [lift, Quotient.lift_spec, Quiver.FreeGroupoid.lift_spec])
@[simp]
lemma lift_obj_mk {E : Type u₂} [Groupoid.{v₂} E] (φ : C ⥤ E) (X : C) :
(lift φ).obj (mk X) = φ.obj X := rfl
@[simp]
lemma lift_map_homMk {E : Type u₂} [Groupoid.{v₂} E] (φ : C ⥤ E) {X Y : C} (f : X ⟶ Y) :
(lift φ).map (homMk f) = φ.map f := by
simpa using Functor.congr_hom (lift_spec φ) f
theorem lift_unique (φ : C ⥤ G) (Φ : FreeGroupoid C ⥤ G) (hΦ : of C ⋙ Φ = φ) :
Φ = lift φ := by
apply Quotient.lift_unique
apply Quiver.FreeGroupoid.lift_unique
exact congr_arg Functor.toPrefunctor hΦ
theorem lift_id_comp_of : lift (𝟭 G) ⋙ of G = 𝟭 _ := by
rw [lift_unique (of G) (lift (𝟭 G) ⋙ of G) (by rw [← Functor.assoc, lift_spec, Functor.id_comp])]
symm; apply lift_unique
rw [Functor.comp_id]
theorem lift_comp {H : Type u₂} [Groupoid.{v₂} H] (φ : C ⥤ G) (ψ : G ⥤ H) :
lift (φ ⋙ ψ) = lift φ ⋙ ψ := by
symm
apply lift_unique
rw [← Functor.assoc, lift_spec]
/-- The universal property of the free groupoid. -/
def strictUniversalPropertyFixedTarget :
Localization.StrictUniversalPropertyFixedTarget (of C) ⊤ G where
inverts _ := inferInstance
lift F _ := lift F
fac _ _ := lift_spec ..
uniq F G h := by rw [lift_unique (of C ⋙ G) F h, ← lift_unique (of C ⋙ G) G rfl]
attribute [local instance] Localization.groupoid
instance : (of C).IsLocalization ⊤ :=
.mk' _ _ strictUniversalPropertyFixedTarget strictUniversalPropertyFixedTarget
/-- In order to define a natural isomorphism `F ≅ G` with `F G : FreeGroupoid ⥤ D`,
it suffices to do so after precomposing with `FreeGroupoid.of C`. -/
def liftNatIso (F₁ F₂ : FreeGroupoid C ⥤ G) (τ : of C ⋙ F₁ ≅ of C ⋙ F₂) : F₁ ≅ F₂ :=
Localization.liftNatIso (of C) ⊤ (of C ⋙ F₁) (of C ⋙ F₂) _ _ τ
@[simp]
lemma liftNatIso_hom_app (F₁ F₂ : FreeGroupoid C ⥤ G) (τ : of C ⋙ F₁ ≅ of C ⋙ F₂) (X) :
(liftNatIso F₁ F₂ τ).hom.app (mk X) = τ.hom.app X := by
simp [liftNatIso]
@[simp]
lemma liftNatIso_inv_app (F₁ F₂ : FreeGroupoid C ⥤ G) (τ : of C ⋙ F₁ ≅ of C ⋙ F₂) (X) :
(liftNatIso F₁ F₂ τ).inv.app (mk X) = τ.inv.app X := by
simp [liftNatIso]
end UniversalProperty
section Functoriality
variable {D : Type u₁} [Category.{v₁} D] {E : Type u₂} [Category.{v₂} E]
/-- The functor between free groupoids induced by a functor between categories. -/
def map (φ : C ⥤ D) : FreeGroupoid C ⥤ FreeGroupoid D :=
lift (φ ⋙ of D)
lemma of_comp_map (F : C ⥤ D) : of C ⋙ map F = F ⋙ of D := rfl
/-- The operation `of` is natural. -/
def ofCompMapIso (F : C ⥤ D) : of C ⋙ map F ≅ F ⋙ of D := Iso.refl _
variable (C) in
/-- The functor induced by the identity is the identity. -/
def mapId : map (𝟭 C) ≅ 𝟭 (FreeGroupoid C) :=
liftNatIso _ _ (Iso.refl _)
@[simp]
lemma mapId_hom_app (X) : (mapId C).hom.app X = 𝟙 X :=
liftNatIso_hom_app ..
@[simp]
lemma mapId_inv_app (X) : (mapId C).inv.app X = 𝟙 X :=
liftNatIso_inv_app ..
variable (C) in
theorem map_id : map (𝟭 C) = 𝟭 (FreeGroupoid C) := by
symm; apply lift_unique; rfl
/-- The functor induced by a composition is the composition of the functors they induce. -/
def mapComp (φ : C ⥤ D) (φ' : D ⥤ E) : map (φ ⋙ φ') ≅ map φ ⋙ map φ':=
liftNatIso _ _ (Iso.refl _)
@[simp]
lemma mapComp_hom_app (φ : C ⥤ D) (φ' : D ⥤ E) (X) : (mapComp φ φ').hom.app X = 𝟙 _ :=
liftNatIso_hom_app ..
@[simp]
lemma mapComp_inv_app (φ : C ⥤ D) (φ' : D ⥤ E) (X) : (mapComp φ φ').inv.app X = 𝟙 _ :=
liftNatIso_inv_app ..
theorem map_comp (φ : C ⥤ D) (φ' : D ⥤ E) : map (φ ⋙ φ') = map φ ⋙ map φ' := by
symm; apply lift_unique; rfl
@[simp]
lemma map_obj_mk (φ : C ⥤ D) (X : C) : (map φ).obj (mk X) = mk (φ.obj X) := rfl
@[simp]
lemma map_map_homMk (φ : C ⥤ D) {X Y : C} (f : X ⟶ Y) :
(map φ).map (homMk f) = homMk (φ.map f) := rfl
variable {E : Type u₂} [Groupoid.{v₂} E]
lemma map_comp_lift (F : C ⥤ D) (G : D ⥤ E) : map F ⋙ lift G = lift (F ⋙ G) := by
apply lift_unique
rw [← Functor.assoc, of_comp_map, Functor.assoc, lift_spec G]
/-- The operation `lift` is natural. -/
def mapCompLift (F : C ⥤ D) (G : D ⥤ E) : map F ⋙ lift G ≅ lift (F ⋙ G) :=
liftNatIso _ _ (Iso.refl _)
@[simp]
lemma mapCompLift_hom_app (F : C ⥤ D) (G : D ⥤ E) (X) : (mapCompLift F G).hom.app X = 𝟙 _ :=
liftNatIso_hom_app ..
@[simp]
lemma mapCompLift_inv_app (F : C ⥤ D) (G : D ⥤ E) (X) : (mapCompLift F G).inv.app X = 𝟙 _ :=
liftNatIso_inv_app ..
end Functoriality
/-- Functors out of the free groupoid biject with functors out of the original category. -/
@[simps]
def functorEquiv {D : Type*} [Groupoid D] : (FreeGroupoid C ⥤ D) ≃ (C ⥤ D) where
toFun G := of C ⋙ G
invFun F := lift F
right_inv := lift_spec
left_inv _ := (lift_unique _ _ rfl).symm
end FreeGroupoid
namespace Grpd
open FreeGroupoid
/-- The free groupoid construction on a category as a functor. -/
def free : Cat.{u, u} ⥤ Grpd.{u, u} where
obj C := Grpd.of <| FreeGroupoid C
map {C D} F := map F
map_id C := by simp [Grpd.id_eq_id, map_id, Cat.id_eq_id]
map_comp F G := by simp [Grpd.comp_eq_comp, map_comp, Cat.comp_eq_comp]
@[simp]
lemma free_obj (C : Cat.{u, u}) : free.obj C = FreeGroupoid C :=
rfl
@[simp]
lemma free_map {C D : Cat.{u, u}} (F : C ⟶ D) : free.map F = map F :=
rfl
/-- The free-forgetful adjunction between `Grpd` and `Cat`. -/
def freeForgetAdjunction : free ⊣ Grpd.forgetToCat :=
Adjunction.mkOfHomEquiv
{ homEquiv _ _ := FreeGroupoid.functorEquiv
homEquiv_naturality_left_symm _ _ := (FreeGroupoid.map_comp_lift _ _).symm
homEquiv_naturality_right _ _ := rfl }
variable {C : Type u} [Category.{u} C] {D : Type u} [Groupoid.{u} D]
@[simp]
lemma freeForgetAdjunction_homEquiv_apply (F : FreeGroupoid C ⥤ D) :
freeForgetAdjunction.homEquiv (Cat.of C) (Grpd.of D) F = FreeGroupoid.of C ⋙ F :=
rfl
@[simp]
lemma freeForgetAdjunction_homEquiv_symm_apply (F : C ⥤ D) :
(freeForgetAdjunction.homEquiv (Cat.of C) (Grpd.of D)).symm F = map F ⋙ lift (𝟭 D) :=
rfl
@[simp]
lemma freeForgetAdjunction_unit_app :
freeForgetAdjunction.unit.app (Cat.of C) = FreeGroupoid.of C :=
rfl
@[simp]
lemma freeForgetAdjunction_counit_app :
freeForgetAdjunction.counit.app (Grpd.of D) = lift (𝟭 D) :=
rfl
instance : Reflective Grpd.forgetToCat where
L := free
adj := freeForgetAdjunction
end Grpd
end CategoryTheory
end |
.lake/packages/mathlib/Mathlib/CategoryTheory/Groupoid/Discrete.lean | import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Discrete.Basic
/-!
# Discrete categories are groupoids
-/
namespace CategoryTheory
variable {C : Type*}
instance : Groupoid (Discrete C) := { inv := fun h ↦ ⟨⟨h.1.1.symm⟩⟩ }
instance [Category C] [IsDiscrete C] : IsGroupoid C where
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Groupoid/VertexGroup.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.PathCategory.Basic
import Mathlib.Combinatorics.Quiver.Path
/-!
# Vertex group
This file defines the vertex group (*aka* isotropy group) of a groupoid at a vertex.
## Implementation notes
* The instance is defined "manually", instead of relying on `CategoryTheory.Aut.group` or
using `CategoryTheory.inv`.
* The multiplication order therefore matches the categorical one: `x * y = x ≫ y`.
* The inverse is directly defined in terms of the groupoidal inverse: `x ⁻¹ = Groupoid.inv x`.
## Tags
isotropy, vertex group, groupoid
-/
namespace CategoryTheory
namespace Groupoid
universe u v
variable {C : Type u} [Groupoid C]
/-- The vertex group at `c`. -/
@[simps mul one inv]
instance vertexGroup (c : C) : Group (c ⟶ c) where
mul := fun x y : c ⟶ c => x ≫ y
mul_assoc := Category.assoc
one := 𝟙 c
one_mul := Category.id_comp
mul_one := Category.comp_id
inv := Groupoid.inv
inv_mul_cancel := inv_comp
/-- The inverse in the group is equal to the inverse given by `CategoryTheory.inv`. -/
theorem vertexGroup.inv_eq_inv (c : C) (γ : c ⟶ c) : γ⁻¹ = CategoryTheory.inv γ :=
Groupoid.inv_eq_inv γ
/-- An arrow in the groupoid defines, by conjugation, an isomorphism of groups between
its endpoints.
-/
@[simps]
def vertexGroupIsomOfMap {c d : C} (f : c ⟶ d) : (c ⟶ c) ≃* (d ⟶ d) where
toFun γ := inv f ≫ γ ≫ f
invFun δ := f ≫ δ ≫ inv f
left_inv γ := by
simp_rw [Category.assoc, comp_inv, Category.comp_id, ← Category.assoc, comp_inv,
Category.id_comp]
right_inv δ := by
simp_rw [Category.assoc, inv_comp, ← Category.assoc, inv_comp, Category.id_comp,
Category.comp_id]
map_mul' γ₁ γ₂ := by
simp only [vertexGroup_mul, inv_eq_inv, Category.assoc, IsIso.hom_inv_id_assoc]
/-- A path in the groupoid defines an isomorphism between its endpoints.
-/
def vertexGroupIsomOfPath {c d : C} (p : Quiver.Path c d) : (c ⟶ c) ≃* (d ⟶ d) :=
vertexGroupIsomOfMap (composePath p)
/-- A functor defines a morphism of vertex group. -/
@[simps]
def CategoryTheory.Functor.mapVertexGroup {D : Type v} [Groupoid D] (φ : C ⥤ D) (c : C) :
(c ⟶ c) →* (φ.obj c ⟶ φ.obj c) where
toFun := φ.map
map_one' := φ.map_id c
map_mul' := φ.map_comp
end Groupoid
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Groupoid/Subgroupoid.lean | import Mathlib.Algebra.Group.Subgroup.Defs
import Mathlib.CategoryTheory.Groupoid.VertexGroup
import Mathlib.CategoryTheory.Groupoid.Basic
import Mathlib.CategoryTheory.Groupoid
import Mathlib.Data.Set.Lattice
/-!
# Subgroupoid
This file defines subgroupoids as `structure`s containing the subsets of arrows and their
stability under composition and inversion.
Also defined are:
* containment of subgroupoids is a complete lattice;
* images and preimages of subgroupoids under a functor;
* the notion of normality of subgroupoids and its stability under intersection and preimage;
* compatibility of the above with `CategoryTheory.Groupoid.vertexGroup`.
## Main definitions
Given a type `C` with associated `groupoid C` instance.
* `CategoryTheory.Subgroupoid C` is the type of subgroupoids of `C`
* `CategoryTheory.Subgroupoid.IsNormal` is the property that the subgroupoid is stable under
conjugation by arbitrary arrows, _and_ that all identity arrows are contained in the subgroupoid.
* `CategoryTheory.Subgroupoid.comap` is the "preimage" map of subgroupoids along a functor.
* `CategoryTheory.Subgroupoid.map` is the "image" map of subgroupoids along a functor _injective on
objects_.
* `CategoryTheory.Subgroupoid.vertexSubgroup` is the subgroup of the *vertex group* at a given
vertex `v`, assuming `v` is contained in the `CategoryTheory.Subgroupoid` (meaning, by definition,
that the arrow `𝟙 v` is contained in the subgroupoid).
## Implementation details
The structure of this file is copied from/inspired by `Mathlib/GroupTheory/Subgroup/Basic.lean`
and `Mathlib/Combinatorics/SimpleGraph/Subgraph.lean`.
## TODO
* Equivalent inductive characterization of generated (normal) subgroupoids.
* Characterization of normal subgroupoids as kernels.
* Prove that `CategoryTheory.Subgroupoid.full` and `CategoryTheory.Subgroupoid.disconnect` preserve
intersections (and `CategoryTheory.Subgroupoid.disconnect` also unions)
## Tags
category theory, groupoid, subgroupoid
-/
namespace CategoryTheory
open Set Groupoid
universe u v
variable {C : Type u} [Groupoid C]
/-- A sugroupoid of `C` consists of a choice of arrows for each pair of vertices, closed
under composition and inverses.
-/
@[ext]
structure Subgroupoid (C : Type u) [Groupoid C] where
/-- The arrow choice for each pair of vertices -/
arrows : ∀ c d : C, Set (c ⟶ d)
protected inv : ∀ {c d} {p : c ⟶ d}, p ∈ arrows c d → Groupoid.inv p ∈ arrows d c
protected mul : ∀ {c d e} {p}, p ∈ arrows c d → ∀ {q}, q ∈ arrows d e → p ≫ q ∈ arrows c e
namespace Subgroupoid
variable (S : Subgroupoid C)
theorem inv_mem_iff {c d : C} (f : c ⟶ d) :
Groupoid.inv f ∈ S.arrows d c ↔ f ∈ S.arrows c d := by
constructor
· intro h
simpa only [inv_eq_inv, IsIso.inv_inv] using S.inv h
· apply S.inv
theorem mul_mem_cancel_left {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hf : f ∈ S.arrows c d) :
f ≫ g ∈ S.arrows c e ↔ g ∈ S.arrows d e := by
constructor
· rintro h
suffices Groupoid.inv f ≫ f ≫ g ∈ S.arrows d e by
simpa only [inv_eq_inv, IsIso.inv_hom_id_assoc] using this
apply S.mul (S.inv hf) h
· apply S.mul hf
theorem mul_mem_cancel_right {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hg : g ∈ S.arrows d e) :
f ≫ g ∈ S.arrows c e ↔ f ∈ S.arrows c d := by
constructor
· rintro h
suffices (f ≫ g) ≫ Groupoid.inv g ∈ S.arrows c d by
simpa only [inv_eq_inv, IsIso.hom_inv_id, Category.comp_id, Category.assoc] using this
apply S.mul h (S.inv hg)
· exact fun hf => S.mul hf hg
/-- The vertices of `C` on which `S` has non-trivial isotropy -/
def objs : Set C :=
{c : C | (S.arrows c c).Nonempty}
theorem mem_objs_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : c ∈ S.objs :=
⟨f ≫ Groupoid.inv f, S.mul h (S.inv h)⟩
theorem mem_objs_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : d ∈ S.objs :=
⟨Groupoid.inv f ≫ f, S.mul (S.inv h) h⟩
theorem id_mem_of_nonempty_isotropy (c : C) : c ∈ objs S → 𝟙 c ∈ S.arrows c c := by
rintro ⟨γ, hγ⟩
convert S.mul hγ (S.inv hγ)
simp only [inv_eq_inv, IsIso.hom_inv_id]
theorem id_mem_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 c ∈ S.arrows c c :=
id_mem_of_nonempty_isotropy S c (mem_objs_of_src S h)
theorem id_mem_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 d ∈ S.arrows d d :=
id_mem_of_nonempty_isotropy S d (mem_objs_of_tgt S h)
/-- A subgroupoid seen as a quiver on vertex set `C` -/
def asWideQuiver : Quiver C :=
⟨fun c d => Subtype <| S.arrows c d⟩
/-- The coercion of a subgroupoid as a groupoid -/
@[simps comp_coe, simps -isSimp inv_coe]
instance coe : Groupoid S.objs where
Hom a b := S.arrows a.val b.val
id a := ⟨𝟙 a.val, id_mem_of_nonempty_isotropy S a.val a.prop⟩
comp p q := ⟨p.val ≫ q.val, S.mul p.prop q.prop⟩
inv p := ⟨Groupoid.inv p.val, S.inv p.prop⟩
@[simp]
theorem coe_inv_coe' {c d : S.objs} (p : c ⟶ d) :
(CategoryTheory.inv p).val = CategoryTheory.inv p.val := by
simp only [← inv_eq_inv, coe_inv_coe]
/-- The embedding of the coerced subgroupoid to its parent -/
def hom : S.objs ⥤ C where
obj c := c.val
map f := f.val
map_id _ := rfl
map_comp _ _ := rfl
theorem hom.inj_on_objects : Function.Injective (hom S).obj := by
rintro ⟨c, hc⟩ ⟨d, hd⟩ hcd
simp only [Subtype.mk_eq_mk]; exact hcd
theorem hom.faithful : ∀ c d, Function.Injective fun f : c ⟶ d => (hom S).map f := by
rintro ⟨c, hc⟩ ⟨d, hd⟩ ⟨f, hf⟩ ⟨g, hg⟩ hfg; exact Subtype.eq hfg
/-- The subgroup of the vertex group at `c` given by the subgroupoid -/
def vertexSubgroup {c : C} (hc : c ∈ S.objs) : Subgroup (c ⟶ c) where
carrier := S.arrows c c
mul_mem' hf hg := S.mul hf hg
one_mem' := id_mem_of_nonempty_isotropy _ _ hc
inv_mem' hf := S.inv hf
/-- The set of all arrows of a subgroupoid, as a set in `Σ c d : C, c ⟶ d`. -/
@[coe] def toSet (S : Subgroupoid C) : Set (Σ c d : C, c ⟶ d) :=
{F | F.2.2 ∈ S.arrows F.1 F.2.1}
instance : SetLike (Subgroupoid C) (Σ c d : C, c ⟶ d) where
coe := toSet
coe_injective' := fun ⟨S, _, _⟩ ⟨T, _, _⟩ h => by ext c d f; apply Set.ext_iff.1 h ⟨c, d, f⟩
theorem mem_iff (S : Subgroupoid C) (F : Σ c d, c ⟶ d) : F ∈ S ↔ F.2.2 ∈ S.arrows F.1 F.2.1 :=
Iff.rfl
theorem le_iff (S T : Subgroupoid C) : S ≤ T ↔ ∀ {c d}, S.arrows c d ⊆ T.arrows c d := by
rw [SetLike.le_def, Sigma.forall]; exact forall_congr' fun c => Sigma.forall
instance : Top (Subgroupoid C) :=
⟨{ arrows := fun _ _ => Set.univ
mul := by intros; trivial
inv := by intros; trivial }⟩
theorem mem_top {c d : C} (f : c ⟶ d) : f ∈ (⊤ : Subgroupoid C).arrows c d :=
trivial
theorem mem_top_objs (c : C) : c ∈ (⊤ : Subgroupoid C).objs := by
dsimp [Top.top, objs]
simp only [univ_nonempty]
instance : Bot (Subgroupoid C) :=
⟨{ arrows := fun _ _ => ∅
mul := False.elim
inv := False.elim }⟩
instance : Inhabited (Subgroupoid C) :=
⟨⊤⟩
instance : Min (Subgroupoid C) :=
⟨fun S T =>
{ arrows := fun c d => S.arrows c d ∩ T.arrows c d
inv := fun hp ↦ ⟨S.inv hp.1, T.inv hp.2⟩
mul := fun hp _ hq ↦ ⟨S.mul hp.1 hq.1, T.mul hp.2 hq.2⟩ }⟩
instance : InfSet (Subgroupoid C) :=
⟨fun s =>
{ arrows := fun c d => ⋂ S ∈ s, Subgroupoid.arrows S c d
inv := fun hp ↦ by rw [mem_iInter₂] at hp ⊢; exact fun S hS => S.inv (hp S hS)
mul := fun hp _ hq ↦ by
rw [mem_iInter₂] at hp hq ⊢
exact fun S hS => S.mul (hp S hS) (hq S hS) }⟩
theorem mem_sInf_arrows {s : Set (Subgroupoid C)} {c d : C} {p : c ⟶ d} :
p ∈ (sInf s).arrows c d ↔ ∀ S ∈ s, p ∈ S.arrows c d :=
mem_iInter₂
theorem mem_sInf {s : Set (Subgroupoid C)} {p : Σ c d : C, c ⟶ d} :
p ∈ sInf s ↔ ∀ S ∈ s, p ∈ S :=
mem_sInf_arrows
instance : CompleteLattice (Subgroupoid C) :=
{ completeLatticeOfInf (Subgroupoid C) (by
refine fun s => ⟨fun S Ss F => ?_, fun T Tl F fT => ?_⟩ <;> simp only [mem_sInf]
exacts [fun hp => hp S Ss, fun S Ss => Tl Ss fT]) with
bot := ⊥
bot_le := fun _ => empty_subset _
top := ⊤
le_top := fun _ => subset_univ _
inf := (· ⊓ ·)
le_inf := fun _ _ _ RS RT _ pR => ⟨RS pR, RT pR⟩
inf_le_left := fun _ _ _ => And.left
inf_le_right := fun _ _ _ => And.right }
theorem le_objs {S T : Subgroupoid C} (h : S ≤ T) : S.objs ⊆ T.objs := fun s ⟨γ, hγ⟩ =>
⟨γ, @h ⟨s, s, γ⟩ hγ⟩
/-- The functor associated to the embedding of subgroupoids -/
def inclusion {S T : Subgroupoid C} (h : S ≤ T) : S.objs ⥤ T.objs where
obj s := ⟨s.val, le_objs h s.prop⟩
map f := ⟨f.val, @h ⟨_, _, f.val⟩ f.prop⟩
map_id _ := rfl
map_comp _ _ := rfl
theorem inclusion_inj_on_objects {S T : Subgroupoid C} (h : S ≤ T) :
Function.Injective (inclusion h).obj := fun ⟨s, hs⟩ ⟨t, ht⟩ => by
simpa only [inclusion, Subtype.mk_eq_mk] using id
theorem inclusion_faithful {S T : Subgroupoid C} (h : S ≤ T) (s t : S.objs) :
Function.Injective fun f : s ⟶ t => (inclusion h).map f := fun ⟨f, hf⟩ ⟨g, hg⟩ => by
-- Porting note: was `...; simpa only [Subtype.mk_eq_mk] using id`
dsimp only [inclusion]; rw [Subtype.mk_eq_mk, Subtype.mk_eq_mk]; exact id
theorem inclusion_refl {S : Subgroupoid C} : inclusion (le_refl S) = 𝟭 S.objs :=
Functor.hext (fun _ => rfl) fun _ _ _ => HEq.refl _
theorem inclusion_trans {R S T : Subgroupoid C} (k : R ≤ S) (h : S ≤ T) :
inclusion (k.trans h) = inclusion k ⋙ inclusion h :=
rfl
theorem inclusion_comp_embedding {S T : Subgroupoid C} (h : S ≤ T) : inclusion h ⋙ T.hom = S.hom :=
rfl
/-- The family of arrows of the discrete groupoid -/
inductive Discrete.Arrows : ∀ c d : C, (c ⟶ d) → Prop
| id (c : C) : Discrete.Arrows c c (𝟙 c)
/-- The only arrows of the discrete groupoid are the identity arrows. -/
def discrete : Subgroupoid C where
arrows c d := {p | Discrete.Arrows c d p}
inv := by rintro _ _ _ ⟨⟩; simp only [inv_eq_inv, IsIso.inv_id]; constructor
mul := by rintro _ _ _ _ ⟨⟩ _ ⟨⟩; rw [Category.comp_id]; constructor
theorem mem_discrete_iff {c d : C} (f : c ⟶ d) :
f ∈ discrete.arrows c d ↔ ∃ h : c = d, f = eqToHom h :=
⟨by rintro ⟨⟩; exact ⟨rfl, rfl⟩, by rintro ⟨rfl, rfl⟩; constructor⟩
/-- A subgroupoid is wide if its carrier set is all of `C`. -/
structure IsWide : Prop where
wide : ∀ c, 𝟙 c ∈ S.arrows c c
theorem isWide_iff_objs_eq_univ : S.IsWide ↔ S.objs = Set.univ := by
constructor
· rintro h
ext x; constructor <;> simp only [mem_univ, imp_true_iff, forall_true_left]
apply mem_objs_of_src S (h.wide x)
· rintro h
refine ⟨fun c => ?_⟩
obtain ⟨γ, γS⟩ := (le_of_eq h.symm : ⊤ ⊆ S.objs) (Set.mem_univ c)
exact id_mem_of_src S γS
theorem IsWide.id_mem {S : Subgroupoid C} (Sw : S.IsWide) (c : C) : 𝟙 c ∈ S.arrows c c :=
Sw.wide c
theorem IsWide.eqToHom_mem {S : Subgroupoid C} (Sw : S.IsWide) {c d : C} (h : c = d) :
eqToHom h ∈ S.arrows c d := by cases h; simp only [eqToHom_refl]; apply Sw.id_mem c
/-- A subgroupoid is normal if it is wide and satisfies the expected stability under conjugacy. -/
structure IsNormal : Prop extends IsWide S where
conj : ∀ {c d} (p : c ⟶ d) {γ : c ⟶ c}, γ ∈ S.arrows c c → Groupoid.inv p ≫ γ ≫ p ∈ S.arrows d d
theorem IsNormal.conj' {S : Subgroupoid C} (Sn : IsNormal S) :
∀ {c d} (p : d ⟶ c) {γ : c ⟶ c}, γ ∈ S.arrows c c → p ≫ γ ≫ Groupoid.inv p ∈ S.arrows d d :=
fun p γ hs => by convert Sn.conj (Groupoid.inv p) hs; simp
theorem IsNormal.conjugation_bij (Sn : IsNormal S) {c d} (p : c ⟶ d) :
Set.BijOn (fun γ : c ⟶ c => Groupoid.inv p ≫ γ ≫ p) (S.arrows c c) (S.arrows d d) := by
refine ⟨fun γ γS => Sn.conj p γS, fun γ₁ _ γ₂ _ h => ?_, fun δ δS =>
⟨p ≫ δ ≫ Groupoid.inv p, Sn.conj' p δS, ?_⟩⟩
· simpa only [inv_eq_inv, Category.assoc, IsIso.hom_inv_id, Category.comp_id,
IsIso.hom_inv_id_assoc] using p ≫= h =≫ inv p
· simp only [inv_eq_inv, Category.assoc, IsIso.inv_hom_id, Category.comp_id,
IsIso.inv_hom_id_assoc]
theorem top_isNormal : IsNormal (⊤ : Subgroupoid C) :=
{ wide := fun _ => trivial
conj := fun _ _ _ => trivial }
theorem sInf_isNormal (s : Set <| Subgroupoid C) (sn : ∀ S ∈ s, IsNormal S) : IsNormal (sInf s) :=
{ wide := by simp_rw [sInf, mem_iInter₂]; exact fun c S Ss => (sn S Ss).wide c
conj := by simp_rw [sInf, mem_iInter₂]; exact fun p γ hγ S Ss => (sn S Ss).conj p (hγ S Ss) }
theorem discrete_isNormal : (@discrete C _).IsNormal :=
{ wide := fun c => by constructor
conj := fun f γ hγ => by
cases hγ
simp only [inv_eq_inv, Category.id_comp, IsIso.inv_hom_id]; constructor }
theorem IsNormal.vertexSubgroup (Sn : IsNormal S) (c : C) (cS : c ∈ S.objs) :
(S.vertexSubgroup cS).Normal where
conj_mem x hx y := by rw [mul_assoc]; exact Sn.conj' y hx
section GeneratedSubgroupoid
-- TODO: proof that generated is just "words in X" and generatedNormal is similarly
variable (X : ∀ c d : C, Set (c ⟶ d))
/-- The subgroupoid generated by the set of arrows `X` -/
def generated : Subgroupoid C :=
sInf {S : Subgroupoid C | ∀ c d, X c d ⊆ S.arrows c d}
theorem subset_generated (c d : C) : X c d ⊆ (generated X).arrows c d := by
dsimp only [generated, sInf]
simp only [subset_iInter₂_iff]
exact fun S hS f fS => hS _ _ fS
/-- The normal sugroupoid generated by the set of arrows `X` -/
def generatedNormal : Subgroupoid C :=
sInf {S : Subgroupoid C | (∀ c d, X c d ⊆ S.arrows c d) ∧ S.IsNormal}
theorem generated_le_generatedNormal : generated X ≤ generatedNormal X := by
apply @sInf_le_sInf (Subgroupoid C) _
exact fun S ⟨h, _⟩ => h
theorem generatedNormal_isNormal : (generatedNormal X).IsNormal :=
sInf_isNormal _ fun _ h => h.right
theorem IsNormal.generatedNormal_le {S : Subgroupoid C} (Sn : S.IsNormal) :
generatedNormal X ≤ S ↔ ∀ c d, X c d ⊆ S.arrows c d := by
constructor
· rintro h c d
have h' := generated_le_generatedNormal X
rw [le_iff] at h h'
exact ((subset_generated X c d).trans (@h' c d)).trans (@h c d)
· rintro h
apply @sInf_le (Subgroupoid C) _
exact ⟨h, Sn⟩
end GeneratedSubgroupoid
section Hom
variable {D : Type*} [Groupoid D] (φ : C ⥤ D)
/-- A functor between groupoid defines a map of subgroupoids in the reverse direction
by taking preimages.
-/
def comap (S : Subgroupoid D) : Subgroupoid C where
arrows c d := {f : c ⟶ d | φ.map f ∈ S.arrows (φ.obj c) (φ.obj d)}
inv hp := by rw [mem_setOf, inv_eq_inv, φ.map_inv, ← inv_eq_inv]; exact S.inv hp
mul := by
intros
simp only [mem_setOf, Functor.map_comp]
apply S.mul <;> assumption
theorem comap_mono (S T : Subgroupoid D) : S ≤ T → comap φ S ≤ comap φ T := fun ST _ =>
@ST ⟨_, _, _⟩
theorem isNormal_comap {S : Subgroupoid D} (Sn : IsNormal S) : IsNormal (comap φ S) where
wide c := by rw [comap, mem_setOf, Functor.map_id]; apply Sn.wide
conj f γ hγ := by
simp_rw [inv_eq_inv f, comap, mem_setOf, Functor.map_comp, Functor.map_inv, ← inv_eq_inv]
exact Sn.conj _ hγ
@[simp]
theorem comap_comp {E : Type*} [Groupoid E] (ψ : D ⥤ E) : comap (φ ⋙ ψ) = comap φ ∘ comap ψ :=
rfl
/-- The kernel of a functor between subgroupoid is the preimage. -/
def ker : Subgroupoid C :=
comap φ discrete
theorem mem_ker_iff {c d : C} (f : c ⟶ d) :
f ∈ (ker φ).arrows c d ↔ ∃ h : φ.obj c = φ.obj d, φ.map f = eqToHom h :=
mem_discrete_iff (φ.map f)
theorem ker_isNormal : (ker φ).IsNormal :=
isNormal_comap φ discrete_isNormal
@[simp]
theorem ker_comp {E : Type*} [Groupoid E] (ψ : D ⥤ E) : ker (φ ⋙ ψ) = comap φ (ker ψ) :=
rfl
/-- The family of arrows of the image of a subgroupoid under a functor injective on objects -/
inductive Map.Arrows (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : ∀ c d : D, (c ⟶ d) → Prop
| im {c d : C} (f : c ⟶ d) (hf : f ∈ S.arrows c d) : Map.Arrows hφ S (φ.obj c) (φ.obj d) (φ.map f)
theorem Map.arrows_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) :
Map.Arrows φ hφ S c d f ↔
∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b),
f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by
constructor
· rintro ⟨g, hg⟩; exact ⟨_, _, g, rfl, rfl, hg, eq_conj_eqToHom _⟩
· rintro ⟨a, b, g, rfl, rfl, hg, rfl⟩; rw [← eq_conj_eqToHom]; constructor; exact hg
/-- The "forward" image of a subgroupoid under a functor injective on objects -/
def map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : Subgroupoid D where
arrows c d := {x | Map.Arrows φ hφ S c d x}
inv := by
rintro _ _ _ ⟨⟩
rw [inv_eq_inv, ← Functor.map_inv, ← inv_eq_inv]
constructor; apply S.inv; assumption
mul := by
rintro _ _ _ _ ⟨f, hf⟩ q hq
obtain ⟨c₃, c₄, g, he, rfl, hg, gq⟩ := (Map.arrows_iff φ hφ S q).mp hq
cases hφ he; rw [gq, ← eq_conj_eqToHom, ← φ.map_comp]
constructor; exact S.mul hf hg
theorem mem_map_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) :
f ∈ (map φ hφ S).arrows c d ↔
∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b),
f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb :=
Map.arrows_iff φ hφ S f
theorem galoisConnection_map_comap (hφ : Function.Injective φ.obj) :
GaloisConnection (map φ hφ) (comap φ) := by
rintro S T; simp_rw [le_iff]; constructor
· exact fun h c d f fS => h (Map.Arrows.im f fS)
· rintro h _ _ g ⟨a, gφS⟩
exact h gφS
theorem map_mono (hφ : Function.Injective φ.obj) (S T : Subgroupoid C) :
S ≤ T → map φ hφ S ≤ map φ hφ T := fun h => (galoisConnection_map_comap φ hφ).monotone_l h
theorem le_comap_map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) :
S ≤ comap φ (map φ hφ S) :=
(galoisConnection_map_comap φ hφ).le_u_l S
theorem map_comap_le (hφ : Function.Injective φ.obj) (T : Subgroupoid D) :
map φ hφ (comap φ T) ≤ T :=
(galoisConnection_map_comap φ hφ).l_u_le T
theorem map_le_iff_le_comap (hφ : Function.Injective φ.obj) (S : Subgroupoid C)
(T : Subgroupoid D) : map φ hφ S ≤ T ↔ S ≤ comap φ T :=
(galoisConnection_map_comap φ hφ).le_iff_le
theorem mem_map_objs_iff (hφ : Function.Injective φ.obj) (d : D) :
d ∈ (map φ hφ S).objs ↔ ∃ c ∈ S.objs, φ.obj c = d := by
dsimp [objs, map]
constructor
· rintro ⟨f, hf⟩
change Map.Arrows φ hφ S d d f at hf; rw [Map.arrows_iff] at hf
obtain ⟨c, d, g, ec, ed, eg, gS, eg⟩ := hf
exact ⟨c, ⟨mem_objs_of_src S eg, ec⟩⟩
· rintro ⟨c, ⟨γ, γS⟩, rfl⟩
exact ⟨φ.map γ, ⟨γ, γS⟩⟩
@[simp]
theorem map_objs_eq (hφ : Function.Injective φ.obj) : (map φ hφ S).objs = φ.obj '' S.objs := by
ext x; convert mem_map_objs_iff S φ hφ x
/-- The image of a functor injective on objects -/
def im (hφ : Function.Injective φ.obj) :=
map φ hφ ⊤
theorem mem_im_iff (hφ : Function.Injective φ.obj) {c d : D} (f : c ⟶ d) :
f ∈ (im φ hφ).arrows c d ↔
∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d),
f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by
convert Map.arrows_iff φ hφ ⊤ f; simp only [Top.top, mem_univ, exists_true_left]
theorem mem_im_objs_iff (hφ : Function.Injective φ.obj) (d : D) :
d ∈ (im φ hφ).objs ↔ ∃ c : C, φ.obj c = d := by
simp only [im, mem_map_objs_iff, mem_top_objs, true_and]
theorem obj_surjective_of_im_eq_top (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊤) :
Function.Surjective φ.obj := by
rintro d
rw [← mem_im_objs_iff _ hφ, hφ']
apply mem_top_objs
theorem isNormal_map (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊤) (Sn : S.IsNormal) :
(map φ hφ S).IsNormal :=
{ wide := fun d => by
obtain ⟨c, rfl⟩ := obj_surjective_of_im_eq_top φ hφ hφ' d
change Map.Arrows φ hφ S _ _ (𝟙 _); rw [← Functor.map_id]
constructor; exact Sn.wide c
conj := fun {d d'} g δ hδ => by
rw [mem_map_iff] at hδ
obtain ⟨c, c', γ, cd, cd', γS, hγ⟩ := hδ; subst_vars; cases hφ cd'
have : d' ∈ (im φ hφ).objs := by rw [hφ']; apply mem_top_objs
rw [mem_im_objs_iff] at this
obtain ⟨c', rfl⟩ := this
have : g ∈ (im φ hφ).arrows (φ.obj c) (φ.obj c') := by rw [hφ']; trivial
rw [mem_im_iff] at this
obtain ⟨b, b', f, hb, hb', _, hf⟩ := this; cases hφ hb; cases hφ hb'
change Map.Arrows φ hφ S (φ.obj c') (φ.obj c') _
simp only [eqToHom_refl, Category.comp_id, Category.id_comp, inv_eq_inv]
suffices Map.Arrows φ hφ S (φ.obj c') (φ.obj c') (φ.map <| Groupoid.inv f ≫ γ ≫ f) by
simp only [inv_eq_inv, Functor.map_comp, Functor.map_inv] at this; exact this
constructor; apply Sn.conj f γS }
end Hom
section Thin
/-- A subgroupoid is thin (`CategoryTheory.Subgroupoid.IsThin`) if it has at most one arrow between
any two vertices. -/
abbrev IsThin :=
Quiver.IsThin S.objs
nonrec theorem isThin_iff : S.IsThin ↔ ∀ c : S.objs, Subsingleton (S.arrows c c) := isThin_iff _
end Thin
section Disconnected
/-- A subgroupoid `IsTotallyDisconnected` if it has only isotropy arrows. -/
nonrec abbrev IsTotallyDisconnected :=
IsTotallyDisconnected S.objs
theorem isTotallyDisconnected_iff :
S.IsTotallyDisconnected ↔ ∀ c d, (S.arrows c d).Nonempty → c = d := by
constructor
· rintro h c d ⟨f, fS⟩
exact congr_arg Subtype.val <| h ⟨c, mem_objs_of_src S fS⟩ ⟨d, mem_objs_of_tgt S fS⟩ ⟨f, fS⟩
· rintro h ⟨c, hc⟩ ⟨d, hd⟩ ⟨f, fS⟩
simp only [Subtype.mk_eq_mk]
exact h c d ⟨f, fS⟩
/-- The isotropy subgroupoid of `S` -/
def disconnect : Subgroupoid C where
arrows c d := {f | c = d ∧ f ∈ S.arrows c d}
inv := by rintro _ _ _ ⟨rfl, h⟩; exact ⟨rfl, S.inv h⟩
mul := by rintro _ _ _ _ ⟨rfl, h⟩ _ ⟨rfl, h'⟩; exact ⟨rfl, S.mul h h'⟩
theorem disconnect_le : S.disconnect ≤ S := by rw [le_iff]; rintro _ _ _ ⟨⟩; assumption
theorem disconnect_normal (Sn : S.IsNormal) : S.disconnect.IsNormal :=
{ wide := fun c => ⟨rfl, Sn.wide c⟩
conj := fun _ _ ⟨_, h'⟩ => ⟨rfl, Sn.conj _ h'⟩ }
@[simp]
theorem mem_disconnect_objs_iff {c : C} : c ∈ S.disconnect.objs ↔ c ∈ S.objs :=
⟨fun ⟨γ, _, γS⟩ => ⟨γ, γS⟩, fun ⟨γ, γS⟩ => ⟨γ, rfl, γS⟩⟩
theorem disconnect_objs : S.disconnect.objs = S.objs := Set.ext fun _ ↦ mem_disconnect_objs_iff _
theorem disconnect_isTotallyDisconnected : S.disconnect.IsTotallyDisconnected := by
rw [isTotallyDisconnected_iff]; exact fun c d ⟨_, h, _⟩ => h
end Disconnected
section Full
variable (D : Set C)
/-- The full subgroupoid on a set `D : Set C` -/
def full : Subgroupoid C where
arrows c d := {_f | c ∈ D ∧ d ∈ D}
inv := by rintro _ _ _ ⟨⟩; constructor <;> assumption
mul := by rintro _ _ _ _ ⟨⟩ _ ⟨⟩; constructor <;> assumption
theorem full_objs : (full D).objs = D :=
Set.ext fun _ => ⟨fun ⟨_, h, _⟩ => h, fun h => ⟨𝟙 _, h, h⟩⟩
@[simp]
theorem mem_full_iff {c d : C} {f : c ⟶ d} : f ∈ (full D).arrows c d ↔ c ∈ D ∧ d ∈ D :=
Iff.rfl
@[simp]
theorem mem_full_objs_iff {c : C} : c ∈ (full D).objs ↔ c ∈ D := by rw [full_objs]
@[simp]
theorem full_empty : full ∅ = (⊥ : Subgroupoid C) := by
ext
simp only [Bot.bot, mem_full_iff, mem_empty_iff_false, and_self_iff]
@[simp]
theorem full_univ : full Set.univ = (⊤ : Subgroupoid C) := by
ext
simp only [mem_full_iff, mem_univ, and_self, mem_top]
theorem full_mono {D E : Set C} (h : D ≤ E) : full D ≤ full E := by
rw [le_iff]
rintro c d f
simp only [mem_full_iff]
exact fun ⟨hc, hd⟩ => ⟨h hc, h hd⟩
theorem full_arrow_eq_iff {c d : (full D).objs} {f g : c ⟶ d} :
f = g ↔ f.1 = g.1 :=
Subtype.ext_iff
end Full
end Subgroupoid
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Groupoid/Basic.lean | import Mathlib.CategoryTheory.Groupoid
import Mathlib.Combinatorics.Quiver.Basic
/-!
This file defines a few basic properties of groupoids.
-/
namespace CategoryTheory
namespace Groupoid
variable (C : Type*) [Groupoid C]
section Thin
theorem isThin_iff : Quiver.IsThin C ↔ ∀ c : C, Subsingleton (c ⟶ c) := by
refine ⟨fun h c => h c c, fun h c d => Subsingleton.intro fun f g => ?_⟩
haveI := h d
calc
f = f ≫ inv g ≫ g := by simp only [inv_eq_inv, IsIso.inv_hom_id, Category.comp_id]
_ = f ≫ inv f ≫ g := by congr 1
simp only [inv_eq_inv, IsIso.inv_hom_id, eq_iff_true_of_subsingleton]
_ = g := by simp only [inv_eq_inv, IsIso.hom_inv_id_assoc]
end Thin
section Disconnected
/-- A subgroupoid is totally disconnected if it only has loops. -/
def IsTotallyDisconnected :=
∀ c d : C, (c ⟶ d) → c = d
end Disconnected
end Groupoid
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Groupoid/FreeGroupoid.lean | import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.PathCategory.Basic
/-!
# Free groupoid on a quiver
This file defines the free groupoid on a quiver, the lifting of a prefunctor to its unique
extension as a functor from the free groupoid, and proves uniqueness of this extension.
## Main results
Given the type `V` and a quiver instance on `V`:
- `Quiver.FreeGroupoid V`: a type synonym for `V`.
- `Quiver.FreeGroupoid.instGroupoid`: the `Groupoid` instance on `Quiver.FreeGroupoid V`.
- `lift`: the lifting of a prefunctor from `V` to `V'` where `V'` is a groupoid, to a functor.
`Quiver.FreeGroupoid V ⥤ V'`.
- `lift_spec` and `lift_unique`: the proofs that, respectively, `lift` indeed is a lifting
and is the unique one.
## Implementation notes
The free groupoid is first defined by symmetrifying the quiver, taking the induced path category
and finally quotienting by the reducibility relation.
-/
open Set Function
namespace Quiver
open CategoryTheory
universe u v u' v' u'' v''
variable {V : Type u} [Quiver.{v + 1} V]
/-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/
abbrev Hom.toPosPath {X Y : V} (f : X ⟶ Y) :
(CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom X Y :=
f.toPos.toPath
/-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/
abbrev Hom.toNegPath {X Y : V} (f : X ⟶ Y) :
(CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom Y X :=
f.toNeg.toPath
/-- The "reduction" relation -/
inductive FreeGroupoid.redStep : HomRel (Paths (Quiver.Symmetrify V))
| step (X Z : Quiver.Symmetrify V) (f : X ⟶ Z) :
redStep (𝟙 ((Paths.of (Quiver.Symmetrify V)).obj X)) (f.toPath ≫ (Quiver.reverse f).toPath)
/-- The underlying vertices of the free groupoid -/
protected def FreeGroupoid (V) [Q : Quiver V] :=
CategoryTheory.Quotient (@FreeGroupoid.redStep V Q)
namespace FreeGroupoid
open Quiver
instance {V} [Quiver V] [Nonempty V] : Nonempty (Quiver.FreeGroupoid V) := by
inhabit V; exact ⟨⟨@default V _⟩⟩
theorem congr_reverse {X Y : Paths <| Quiver.Symmetrify V} (p q : X ⟶ Y) :
Quotient.CompClosure redStep p q → Quotient.CompClosure redStep p.reverse q.reverse := by
rintro ⟨XW, pp, qq, WY, _, Z, f⟩
have : Quotient.CompClosure redStep (WY.reverse ≫ 𝟙 _ ≫ XW.reverse)
(WY.reverse ≫ (f.toPath ≫ (Quiver.reverse f).toPath) ≫ XW.reverse) := by
constructor
constructor
simpa only [CategoryStruct.comp, CategoryStruct.id, Quiver.Path.reverse, Quiver.Path.nil_comp,
Quiver.Path.reverse_comp, Quiver.reverse_reverse, Quiver.Path.reverse_toPath,
Quiver.Path.comp_assoc] using this
open Relation in
theorem congr_comp_reverse {X Y : Paths <| Quiver.Symmetrify V} (p : X ⟶ Y) :
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (p ≫ p.reverse) =
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (𝟙 X) := by
apply Quot.eqvGen_sound
induction p with
| nil => apply EqvGen.refl
| cons q f ih =>
simp only [Quiver.Path.reverse]
fapply EqvGen.trans
-- Porting note: dot notation for `Quiver.Path.*` and `Quiver.Hom.*` not working
· exact q ≫ Quiver.Path.reverse q
· apply EqvGen.symm
apply EqvGen.rel
have : Quotient.CompClosure redStep (q ≫ 𝟙 _ ≫ Quiver.Path.reverse q)
(q ≫ (Quiver.Hom.toPath f ≫ Quiver.Hom.toPath (Quiver.reverse f)) ≫
Quiver.Path.reverse q) := by
apply Quotient.CompClosure.intro
apply redStep.step
simp only [Category.assoc, Category.id_comp] at this ⊢
-- Porting note: `simp` cannot see how `Quiver.Path.comp_assoc` is relevant, so change to
-- category notation
change Quotient.CompClosure redStep (q ≫ Quiver.Path.reverse q)
(Quiver.Path.cons q f ≫ (Quiver.Hom.toPath (Quiver.reverse f)) ≫ (Quiver.Path.reverse q))
simp only [← Category.assoc] at this ⊢
exact this
· exact ih
theorem congr_reverse_comp {X Y : Paths <| Quiver.Symmetrify V} (p : X ⟶ Y) :
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (p.reverse ≫ p) =
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (𝟙 Y) := by
nth_rw 2 [← Quiver.Path.reverse_reverse p]
apply congr_comp_reverse
instance : Category (Quiver.FreeGroupoid V) :=
Quotient.category redStep
/-- The inverse of an arrow in the free groupoid -/
def quotInv {X Y : Quiver.FreeGroupoid V} (f : X ⟶ Y) : Y ⟶ X :=
Quot.liftOn f (fun pp => Quot.mk _ <| pp.reverse) fun pp qq con =>
Quot.sound <| congr_reverse pp qq con
instance instGroupoid : Groupoid (Quiver.FreeGroupoid V) where
inv := quotInv
inv_comp p := Quot.inductionOn p fun pp => congr_reverse_comp pp
comp_inv p := Quot.inductionOn p fun pp => congr_comp_reverse pp
/-- The inclusion of the quiver on `V` to the underlying quiver on `FreeGroupoid V` -/
def of (V) [Quiver V] : V ⥤q Quiver.FreeGroupoid V where
obj X := ⟨X⟩
map f := Quot.mk _ f.toPosPath
theorem of_eq :
of V = (Quiver.Symmetrify.of ⋙q (Paths.of (Quiver.Symmetrify V))).comp
(Quotient.functor <| @redStep V _).toPrefunctor := rfl
section UniversalProperty
variable {V' : Type u'} [Groupoid V']
/-- The lift of a prefunctor to a groupoid, to a functor from `FreeGroupoid V` -/
def lift (φ : V ⥤q V') : Quiver.FreeGroupoid V ⥤ V' :=
CategoryTheory.Quotient.lift _ (Paths.lift <| Quiver.Symmetrify.lift φ) <| by
rintro _ _ _ _ ⟨X, Y, f⟩
-- Porting note: `simp` does not work, so manually `rewrite`
erw [Paths.lift_nil, Paths.lift_cons, Quiver.Path.comp_nil, Paths.lift_toPath,
Quiver.Symmetrify.lift_reverse]
symm
apply Groupoid.comp_inv
theorem lift_spec (φ : V ⥤q V') : of V ⋙q (lift φ).toPrefunctor = φ := by
rw [of_eq, Prefunctor.comp_assoc, Prefunctor.comp_assoc, Functor.toPrefunctor_comp]
dsimp [lift]
rw [Quotient.lift_spec, Paths.lift_spec, Quiver.Symmetrify.lift_spec]
theorem lift_unique (φ : V ⥤q V') (Φ : Quiver.FreeGroupoid V ⥤ V')
(hΦ : of V ⋙q Φ.toPrefunctor = φ) : Φ = lift φ := by
apply Quotient.lift_unique
apply Paths.lift_unique
fapply @Quiver.Symmetrify.lift_unique _ _ _ _ _ _ _ _ _
· rw [← Functor.toPrefunctor_comp]
exact hΦ
· rintro X Y f
simp only [← Functor.toPrefunctor_comp, Prefunctor.comp_map, Paths.of_map]
change Φ.map (Groupoid.inv ((Quotient.functor redStep).toPrefunctor.map f.toPath)) =
Groupoid.inv (Φ.map ((Quotient.functor redStep).toPrefunctor.map f.toPath))
have := Functor.map_inv Φ ((Quotient.functor redStep).toPrefunctor.map f.toPath)
convert this <;> simp only [Groupoid.inv_eq_inv]
end UniversalProperty
end FreeGroupoid
section Functoriality
open FreeGroupoid
variable {V' : Type u'} [Quiver.{v' + 1} V'] {V'' : Type u''} [Quiver.{v'' + 1} V'']
/-- The functor of free groupoid induced by a prefunctor of quivers -/
def freeGroupoidFunctor (φ : V ⥤q V') : Quiver.FreeGroupoid V ⥤ Quiver.FreeGroupoid V' :=
lift (φ ⋙q of V')
theorem freeGroupoidFunctor_id :
freeGroupoidFunctor (Prefunctor.id V) = Functor.id (Quiver.FreeGroupoid V) := by
dsimp only [freeGroupoidFunctor]; symm
apply lift_unique; rfl
theorem freeGroupoidFunctor_comp (φ : V ⥤q V') (φ' : V' ⥤q V'') :
freeGroupoidFunctor (φ ⋙q φ') = freeGroupoidFunctor φ ⋙ freeGroupoidFunctor φ' := by
dsimp only [freeGroupoidFunctor]; symm
apply lift_unique; rfl
end Functoriality
end Quiver |
.lake/packages/mathlib/Mathlib/CategoryTheory/Distributive/Monoidal.lean | import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts
import Mathlib.CategoryTheory.Limits.Preserves.FunctorCategory
import Mathlib.CategoryTheory.Monoidal.Braided.Basic
import Mathlib.CategoryTheory.Monoidal.End
import Mathlib.CategoryTheory.Monoidal.Preadditive
/-!
# Distributive monoidal categories
## Main definitions
A monoidal category `C` with binary coproducts is left distributive if the left tensor product
preserves binary coproducts. This means that, for all objects `X`, `Y`, and `Z` in `C`,
the cogap map `(X ⊗ Y) ⨿ (X ⊗ Z) ⟶ X ⊗ (Y ⨿ Z)` can be promoted to an isomorphism. We refer to
this isomorphism as the left distributivity isomorphism.
A monoidal category `C` with binary coproducts is right distributive if the right tensor product
preserves binary coproducts. This means that, for all objects `X`, `Y`, and `Z` in `C`,
the cogap map `(Y ⊗ X) ⨿ (Z ⊗ X) ⟶ (Y ⨿ Z) ⊗ X` can be promoted to an isomorphism. We refer to
this isomorphism as the right distributivity isomorphism.
A distributive monoidal category is a monoidal category that is both left and right distributive.
## Main results
- A symmetric monoidal category is left distributive if and only if it is right distributive.
- A closed monoidal category is left distributive.
- For a category `C` the category of endofunctors `C ⥤ C` is left distributive (but almost
never right distributive). The left distributivity is tantamount to the fact that the coproduct
in the functor categories is computed pointwise.
- We show that any preadditive monoidal category with coproducts is distributive. This includes the
examples of abelian groups, R-modules, and vector bundles.
## TODO
Show that a distributive monoidal category whose unit is weakly terminal is finitary distributive.
Show that the category of pointed types with the monoidal structure given by the smash product of
pointed types and the coproduct given by the wedge sum is distributive.
## References
* [Hans-Joachim Baues, Mamuka Jibladze, Andy Tonks, Cohomology of
monoids in monoidal categories, in: Operads: Proceedings of Renaissance
Conferences, Contemporary Mathematics 202, AMS (1997) 137-166][MR1268290]
-/
universe v v₂ u u₂
noncomputable section
namespace CategoryTheory
open Category MonoidalCategory Limits Iso
/-- A monoidal category with binary coproducts is left distributive
if the left tensor product functor preserves binary coproducts. -/
class IsMonoidalLeftDistrib (C : Type u) [Category.{v} C]
[MonoidalCategory C] [HasBinaryCoproducts C] : Prop where
preservesBinaryCoproducts_tensorLeft (X : C) :
PreservesColimitsOfShape (Discrete WalkingPair) (tensorLeft X) := by infer_instance
/-- A monoidal category with binary coproducts is right distributive
if the right tensor product functor preserves binary coproducts. -/
class IsMonoidalRightDistrib (C : Type u) [Category.{v} C]
[MonoidalCategory C] [HasBinaryCoproducts C] : Prop where
preservesBinaryCoproducts_tensorRight (X : C) :
PreservesColimitsOfShape (Discrete WalkingPair) (tensorRight X) := by infer_instance
/-- A monoidal category with binary coproducts is distributive
if it is both left and right distributive. -/
class IsMonoidalDistrib (C : Type u) [Category.{v} C]
[MonoidalCategory C] [HasBinaryCoproducts C] extends
IsMonoidalLeftDistrib C, IsMonoidalRightDistrib C
variable {C} [Category.{v} C] [MonoidalCategory C] [HasBinaryCoproducts C]
section IsMonoidalLeftDistrib
attribute [instance] IsMonoidalLeftDistrib.preservesBinaryCoproducts_tensorLeft
/-- The canonical left distributivity isomorphism -/
def leftDistrib [IsMonoidalLeftDistrib C] (X Y Z : C) :
(X ⊗ Y) ⨿ (X ⊗ Z) ≅ X ⊗ (Y ⨿ Z) :=
PreservesColimitPair.iso (tensorLeft X) Y Z
end IsMonoidalLeftDistrib
namespace Distributive
/-- Notation for the forward direction morphism of the canonical left distributivity isomorphism -/
scoped notation "∂L" => leftDistrib
end Distributive
open Distributive
lemma IsMonoidalLeftDistrib.of_isIso_coprodComparisonTensorLeft
[i : ∀ {X Y Z : C}, IsIso (coprodComparison (tensorLeft X) Y Z)] : IsMonoidalLeftDistrib C where
preservesBinaryCoproducts_tensorLeft X :=
preservesBinaryCoproducts_of_isIso_coprodComparison (tensorLeft X)
/-- The forward direction of the left distributivity isomorphism is the cogap morphism
`coprod.desc (_ ◁ coprod.inl) (_ ◁ coprod.inr) : (X ⊗ Y) ⨿ (X ⊗ Z) ⟶ X ⊗ (Y ⨿ Z)`. -/
lemma leftDistrib_hom [IsMonoidalLeftDistrib C] {X Y Z : C} :
(∂L X Y Z).hom = coprod.desc (_ ◁ coprod.inl) (_ ◁ coprod.inr) := by rfl
@[reassoc (attr := simp)]
lemma coprod_inl_leftDistrib_hom [IsMonoidalLeftDistrib C] {X Y Z : C} :
coprod.inl ≫ (∂L X Y Z).hom = X ◁ coprod.inl := by
rw [leftDistrib_hom, coprod.inl_desc]
@[reassoc (attr := simp)]
lemma coprod_inr_leftDistrib_hom [IsMonoidalLeftDistrib C] {X Y Z : C} :
coprod.inr ≫ (∂L X Y Z).hom = X ◁ coprod.inr := by
rw [leftDistrib_hom, coprod.inr_desc]
/-- The composite of `(X ◁ coprod.inl) : X ⊗ Y ⟶ X ⊗ (Y ⨿ Z)` and
`(∂L X Y Z).inv : X ⊗ (Y ⨿ Z) ⟶ (X ⊗ Y) ⨿ (X ⊗ Z)`
is equal to the left coprojection `coprod.inl : X ⊗ Y ⟶ (X ⊗ Y) ⨿ (X ⊗ Z)`. -/
@[reassoc (attr := simp)]
lemma whiskerLeft_coprod_inl_leftDistrib_inv [IsMonoidalLeftDistrib C] {X Y Z : C} :
(X ◁ coprod.inl) ≫ (∂L X Y Z).inv = coprod.inl := by
apply (cancel_iso_hom_right _ _ (∂L X Y Z)).mp
rw [assoc, Iso.inv_hom_id, comp_id, coprod_inl_leftDistrib_hom]
/-- The composite of `(X ◁ coprod.inr) : X ⊗ Z ⟶ X ⊗ (Y ⨿ Z)` and
`(∂L X Y Z).inv : X ⊗ (Y ⨿ Z) ⟶ (X ⊗ Y) ⨿ (X ⊗ Z)`
is equal to the right coprojection `coprod.inr : X ⊗ Z ⟶ (X ⊗ Y) ⨿ (X ⊗ Z)`. -/
@[reassoc (attr := simp)]
lemma whiskerLeft_coprod_inr_leftDistrib_inv [IsMonoidalLeftDistrib C] {X Y Z : C} :
(X ◁ coprod.inr) ≫ (∂L X Y Z).inv = coprod.inr := by
apply (cancel_iso_hom_right _ _ (∂L X Y Z)).mp
rw [assoc, Iso.inv_hom_id, comp_id, coprod_inr_leftDistrib_hom]
section IsMonoidalRightDistrib
attribute [instance] IsMonoidalRightDistrib.preservesBinaryCoproducts_tensorRight
/-- The canonical right distributivity isomorphism -/
def rightDistrib [IsMonoidalRightDistrib C] (X Y Z : C) : (Y ⊗ X) ⨿ (Z ⊗ X) ≅ (Y ⨿ Z) ⊗ X :=
PreservesColimitPair.iso (tensorRight X) Y Z
end IsMonoidalRightDistrib
namespace Distributive
/-- Notation for the forward direction morphism of the canonical right distributivity isomorphism -/
notation "∂R" => rightDistrib
end Distributive
lemma IsMonoidalRightDistrib.of_isIso_coprodComparisonTensorRight
[i : ∀ {X Y Z : C}, IsIso (coprodComparison (tensorRight X) Y Z)] :
IsMonoidalRightDistrib C where
preservesBinaryCoproducts_tensorRight _ :=
⟨preservesBinaryCoproducts_of_isIso_coprodComparison _ |>.preservesColimit⟩
/-- The forward direction of the right distributivity isomorphism is equal to the cogap morphism
`coprod.desc (coprod.inl ▷ _) (coprod.inr ▷ _) : (Y ⊗ X) ⨿ (Z ⊗ X) ⟶ (Y ⨿ Z) ⊗ X`. -/
lemma rightDistrib_hom [IsMonoidalRightDistrib C] {X Y Z : C} :
(∂R X Y Z).hom = coprod.desc (coprod.inl ▷ _) (coprod.inr ▷ _) := by rfl
@[reassoc (attr := simp)]
lemma coprod_inl_rightDistrib_hom [IsMonoidalRightDistrib C] {X Y Z : C} :
coprod.inl ≫ (∂R X Y Z).hom = coprod.inl ▷ X := by
rw [rightDistrib_hom, coprod.inl_desc]
@[reassoc (attr := simp)]
lemma coprod_inr_rightDistrib_hom [IsMonoidalRightDistrib C] {X Y Z : C} :
coprod.inr ≫ (∂R X Y Z).hom = coprod.inr ▷ X := by
rw [rightDistrib_hom, coprod.inr_desc]
/-- The composite of `(coprod.inl ▷ X) : Y ⊗ X ⟶ (Y ⨿ Z) ⊗ X` and
`(∂R X Y Z).inv : (Y ⨿ Z) ⊗ X ⟶ (Y ⊗ X) ⨿ (Z ⊗ X)` is equal to the left coprojection
`coprod.inl : Y ⊗ X ⟶ (Y ⊗ X) ⨿ (Z ⊗ X)`. -/
@[reassoc (attr := simp)]
lemma whiskerRight_coprod_inl_rightDistrib_inv [IsMonoidalRightDistrib C] {X Y Z : C} :
(coprod.inl ▷ X) ≫ (∂R X Y Z).inv = coprod.inl := by
apply (cancel_iso_hom_right _ _ (∂R X Y Z)).mp
rw [assoc, Iso.inv_hom_id, comp_id, coprod_inl_rightDistrib_hom]
/-- The composite of `(coprod.inr ▷ X) : Z ⊗ X ⟶ (Y ⨿ Z) ⊗ X` and
`(∂R X Y Z).inv : (Y ⨿ Z) ⊗ X ⟶ (Y ⊗ X) ⨿ (Z ⊗ X)` is equal to the right coprojection
`coprod.inr : Z ⊗ X ⟶ (Y ⊗ X) ⨿ (Z ⊗ X)`. -/
@[reassoc (attr := simp)]
lemma whiskerRight_coprod_inr_rightDistrib_inv [IsMonoidalRightDistrib C] {X Y Z : C} :
(coprod.inr ▷ X) ≫ (∂R X Y Z).inv = coprod.inr := by
apply (cancel_iso_hom_right _ _ (∂R X Y Z)).mp
rw [assoc, Iso.inv_hom_id, comp_id, coprod_inr_rightDistrib_hom]
/-- In a symmetric monoidal category, the left distributivity is equal to
the right distributivity up to braiding isomorphisms. -/
@[simp]
lemma coprodComparison_tensorLeft_braiding_hom [BraidedCategory C] {X Y Z : C} :
(coprodComparison (tensorLeft X) Y Z) ≫ (β_ X (Y ⨿ Z)).hom =
(coprod.map (β_ X Y).hom (β_ X Z).hom) ≫ (coprodComparison (tensorRight X) Y Z) := by
simp [coprodComparison]
/-- In a symmetric monoidal category, the right distributivity is equal to
the left distributivity up to braiding isomorphisms. -/
@[simp]
lemma coprodComparison_tensorRight_braiding_hom [SymmetricCategory C] {X Y Z : C} :
(coprodComparison (tensorRight X) Y Z) ≫ (β_ (Y ⨿ Z) X).hom =
(coprod.map (β_ Y X).hom (β_ Z X).hom) ≫ (coprodComparison (tensorLeft X) Y Z) := by
simp [coprodComparison]
/-- A left distributive symmetric monoidal category is distributive. -/
lemma SymmetricCategory.isMonoidalDistrib_of_isMonoidalLeftDistrib
[SymmetricCategory C] [IsMonoidalLeftDistrib C] : IsMonoidalDistrib C where
preservesBinaryCoproducts_tensorRight X :=
preservesColimitsOfShape_of_natIso (BraidedCategory.tensorLeftIsoTensorRight X)
/-- The right distributivity isomorphism of the a left distributive symmetric monoidal category
is given by `(β_ (Y ⨿ Z) X).hom ≫ (∂L X Y Z).inv ≫ (coprod.map (β_ X Y).hom (β_ X Z).hom)`. -/
@[simp]
lemma SymmetricCategory.rightDistrib_of_leftDistrib
[SymmetricCategory C] [IsMonoidalDistrib C] {X Y Z : C} :
∂R X Y Z = (coprod.mapIso (β_ Y X) (β_ Z X)) ≪≫ (∂L X Y Z) ≪≫ (β_ X (Y ⨿ Z)) := by
ext <;> simp [leftDistrib_hom, rightDistrib_hom]
/-- A closed monoidal category is left distributive. -/
instance MonoidalClosed.isMonoidalLeftDistrib [MonoidalClosed C] :
IsMonoidalLeftDistrib C where
preservesBinaryCoproducts_tensorLeft X := by
infer_instance
instance isMonoidalDistrib.of_symmetric_monoidal_closed [SymmetricCategory C] [MonoidalClosed C] :
IsMonoidalDistrib C := by
apply SymmetricCategory.isMonoidalDistrib_of_isMonoidalLeftDistrib
/-- The inverse of distributivity isomorphism from the closed monoidal structure -/
lemma MonoidalClosed.leftDistrib_inv [MonoidalClosed C] {X Y Z : C} :
(leftDistrib X Y Z).inv =
uncurry (coprod.desc (curry coprod.inl) (curry coprod.inr)) := by
rw [← curry_eq_iff]
ext <;> simp [← curry_natural_left]
section Endofunctors
attribute [local instance] endofunctorMonoidalCategory
/-- The monoidal structure on the category of endofunctors is left distributive. -/
instance isMonoidalLeftDistrib.of_endofunctors : IsMonoidalLeftDistrib (C ⥤ C) where
preservesBinaryCoproducts_tensorLeft F :=
inferInstanceAs (PreservesColimitsOfShape _ ((Functor.whiskeringLeft C C C).obj F))
end Endofunctors
section MonoidalPreadditive
attribute [local instance] preservesBinaryBiproducts_of_preservesBiproducts
preservesBinaryCoproducts_of_preservesBinaryBiproducts
/-- A preadditive monoidal category with binary biproducts is distributive. -/
instance IsMonoidalDistrib.of_MonoidalPreadditive_with_binary_coproducts [Preadditive C]
[MonoidalPreadditive C] :
IsMonoidalDistrib C where
end MonoidalPreadditive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Distributive/Cartesian.lean | import Mathlib.CategoryTheory.Distributive.Monoidal
import Mathlib.CategoryTheory.Limits.MonoCoprod
import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic
/-!
# Distributive categories
## Main definitions
A category `C` with finite products and binary coproducts is called distributive if the
canonical distributivity morphism `(X ⨯ Y) ⨿ (X ⨯ Z) ⟶ X ⨯ (Y ⨿ Z)` is an isomorphism
for all objects `X`, `Y`, and `Z` in `C`.
## Implementation Details
A Cartesian distributive category is defined as a Cartesian monoidal category which is
monoidal distributive.
## Main results
- The coproduct coprojections are monic in a Cartesian distributive category.
## TODO
- Every Cartesian distributive category is finitary distributive, meaning that
the left tensor product functor `X ⊗ -` preserves all finite coproducts.
- Show that any extensive distributive category can be embedded into a topos.
## References
- [J.R.B.Cockett, Introduction to distributive categories, 1993][cockett1993]
- [Carboni et al, Introduction to extensive and distributive categories][CARBONI1993145]
-/
universe v v₂ u u₂
noncomputable section
namespace CategoryTheory
open Category Limits MonoidalCategory Distributive CartesianMonoidalCategory
variable (C : Type u) [Category.{v} C] [CartesianMonoidalCategory C] [HasBinaryCoproducts C]
/-- A category `C` with finite products is Cartesian distributive if is monoidal distributive
with respect to the Cartesian monoidal structure. -/
abbrev IsCartesianDistributive :=
IsMonoidalDistrib C
namespace IsCartesianDistributive
/-- To show a category is Cartesian distributive it is enough to show it is left distributive.
The right distributivity is inferred from symmetry of the Cartesian monoidal structure. -/
lemma of_isMonoidalLeftDistrib [IsMonoidalLeftDistrib C] : IsCartesianDistributive C :=
letI : BraidedCategory C := Nonempty.some inferInstance
SymmetricCategory.isMonoidalDistrib_of_isMonoidalLeftDistrib
/-- The coproduct coprojections are monic in a Cartesian distributive category. -/
instance monoCoprod [IsCartesianDistributive C] : MonoCoprod C :=
MonoCoprod.mk' fun A B =>
⟨_, coprodIsCoprod A B, ⟨fun {Z} f g he ↦ by
let ι := coprod.inl (X := A) (Y := B)
have : Mono (Z ◁ ι) := SplitMono.mono
{ retraction := (∂L Z A B).inv ≫ coprod.desc (𝟙 _) (fst Z B ≫ lift (𝟙 Z) f) }
have : lift (𝟙 Z) f = lift (𝟙 Z) g := by rw [← cancel_mono (Z ◁ ι)]; aesop
simpa only [lift_snd] using this =≫ snd _ _⟩⟩
end IsCartesianDistributive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/GuitartExact/Opposite.lean | import Mathlib.CategoryTheory.GuitartExact.VerticalComposition
/-!
# The opposite of a Guitart exact square
A `2`-square is Guitart exact iff the opposite (transposed) `2`-square
is Guitart exact.
-/
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace CategoryTheory
open Category
variable {C₁ : Type u₁} {C₂ : Type u₂} {C₃ : Type u₃} {C₄ : Type u₄}
[Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} C₃] [Category.{v₄} C₄]
{T : C₁ ⥤ C₂} {L : C₁ ⥤ C₃} {R : C₂ ⥤ C₄} {B : C₃ ⥤ C₄}
namespace TwoSquare
variable (w : TwoSquare T L R B)
section
variable {X₃ : C₃ᵒᵖ} {X₂ : C₂ᵒᵖ} (g : B.op.obj X₃ ⟶ R.op.obj X₂)
namespace structuredArrowRightwardsOpEquivalence
/-- Auxiliary definition for `structuredArrowRightwardsOpEquivalence`. -/
@[simps!]
def functor :
(w.op.StructuredArrowRightwards g)ᵒᵖ ⥤
w.CostructuredArrowDownwards g.unop where
obj f := CostructuredArrowDownwards.mk _ _ f.unop.right.left.unop
f.unop.right.hom.unop f.unop.hom.left.unop
(Quiver.Hom.op_inj (by simpa using CostructuredArrow.w f.unop.hom))
map {f f'} φ :=
CostructuredArrow.homMk
(StructuredArrow.homMk (φ.unop.right.left.unop)
(Quiver.Hom.op_inj (CostructuredArrow.w φ.unop.right))) (by
ext
exact Quiver.Hom.op_inj
((CostructuredArrow.proj _ _).congr_map (StructuredArrow.w φ.unop)))
/-- Auxiliary definition for `structuredArrowRightwardsOpEquivalence`. -/
def inverse :
w.CostructuredArrowDownwards g.unop ⥤
(w.op.StructuredArrowRightwards g)ᵒᵖ where
obj f := Opposite.op
(StructuredArrowRightwards.mk _ _ (Opposite.op f.left.right)
f.hom.right.op f.left.hom.op (Quiver.Hom.unop_inj (StructuredArrow.w f.hom)))
map {f f'} φ :=
(StructuredArrow.homMk
(CostructuredArrow.homMk (φ.left.right.op)
(Quiver.Hom.unop_inj (by exact StructuredArrow.w φ.left)))
(by
ext
exact Quiver.Hom.unop_inj
((StructuredArrow.proj _ _).congr_map (CostructuredArrow.w φ)))).op
end structuredArrowRightwardsOpEquivalence
/-- If `w : TwoSquare T L R B`, and `g : B.op.obj X₃ ⟶ R.op.obj X₂`, this is
the obvious equivalence of categories between
`(w.op.StructuredArrowRightwards g)ᵒᵖ` and `w.CostructuredArrowDownwards g.unop`. -/
@[simps]
def structuredArrowRightwardsOpEquivalence :
(w.op.StructuredArrowRightwards g)ᵒᵖ ≌
w.CostructuredArrowDownwards g.unop where
functor := structuredArrowRightwardsOpEquivalence.functor w g
inverse := structuredArrowRightwardsOpEquivalence.inverse w g
unitIso := Iso.refl _
counitIso := Iso.refl _
end
instance [w.GuitartExact] : w.op.GuitartExact := by
rw [guitartExact_iff_isConnected_rightwards]
intro X₃ X₂ g
rw [← isConnected_op_iff_isConnected,
isConnected_iff_of_equivalence (w.structuredArrowRightwardsOpEquivalence g)]
infer_instance
lemma guitartExact_op_iff : w.op.GuitartExact ↔ w.GuitartExact := by
constructor
· intro
let w₁ : TwoSquare T (opOp C₁) (opOp C₂) T.op.op := 𝟙 _
let w₂ : TwoSquare B.op.op (unopUnop C₃) (unopUnop C₄) B := 𝟙 _
have : w = (w₁ ≫ᵥ w.op.op) ≫ᵥ w₂ := by cat_disch
rw [this]
infer_instance
· intro
infer_instance
instance guitartExact_id' (F : C₁ ⥤ C₂) :
GuitartExact (TwoSquare.mk F (𝟭 C₁) (𝟭 C₂) F (𝟙 F)) := by
rw [← guitartExact_op_iff]
apply guitartExact_id
end TwoSquare
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/GuitartExact/KanExtension.lean | import Mathlib.CategoryTheory.GuitartExact.Basic
import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction
/-!
# Guitart exact squares and Kan extensions
Given a Guitart exact square `w : T ⋙ R ⟶ L ⋙ B`,
```
T
C₁ ⥤ C₂
L | | R
v v
C₃ ⥤ C₄
B
```
we show that an extension `F' : C₄ ⥤ D` of `F : C₂ ⥤ D` along `R`
is a pointwise left Kan extension at `B.obj X₃` iff
the composition `T ⋙ F'` is a pointwise left Kan extension at `X₃`
of `B ⋙ F'`.
When suitable (pointwise) left Kan extensions exist, we also show that
the natural transformation of functors `(C₂ ⥤ D) ⥤ C₃ ⥤ D`
`(whiskeringLeft C₁ C₂ D).obj T ⋙ L.lan ⟶ R.lan ⋙ (whiskeringLeft C₃ C₄ D).obj B`
induced by a Guitart exact square `w` is an isomorphism.
## References
* https://ncatlab.org/nlab/show/exact+square
-/
universe v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅
namespace CategoryTheory
open Limits
variable {C₁ : Type u₁} {C₂ : Type u₂} {C₃ : Type u₃} {C₄ : Type u₄} {D : Type u₅}
[Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} C₃] [Category.{v₄} C₄]
[Category.{v₅} D]
namespace Functor.LeftExtension
variable {T : C₁ ⥤ C₂} {L : C₁ ⥤ C₃} {R : C₂ ⥤ C₄} {B : C₃ ⥤ C₄}
{F : C₂ ⥤ D} (E : R.LeftExtension F)
/-- Given a square `w : TwoSquare T L R B` (consisting of a natural transformation
`T ⋙ R ⟶ L ⋙ B`), this is the obvious map `R.LeftExtension F → L.LeftExtension (T ⋙ F)`
obtained by the precomposition with `B` and the postcomposition with `w`. -/
abbrev compTwoSquare (w : TwoSquare T L R B) : L.LeftExtension (T ⋙ F) :=
LeftExtension.mk (B ⋙ E.right)
(whiskerLeft _ E.hom ≫ (associator _ _ _).inv ≫
whiskerRight w.natTrans _ ≫ (associator _ _ _).hom)
/-- If `w : TwoSquare T L R B` is a Guitart exact square, and `E` is a left extension
of `F` along `R`, then `E` is a pointwise left Kan extension of `F` along `R` at
`B.obj X₃` iff `E.compTwoSquare w` is a pointwise left Kan extension
of `T ⋙ F` along `L` at `X₃`. -/
noncomputable def isPointwiseLeftKanExtensionAtCompTwoSquareEquiv
(w : TwoSquare T L R B) (X₃ : C₃) [Final (w.costructuredArrowRightwards X₃)] :
(E.compTwoSquare w).IsPointwiseLeftKanExtensionAt X₃ ≃
E.IsPointwiseLeftKanExtensionAt (B.obj X₃) := by
refine Equiv.trans ?_ (Final.isColimitWhiskerEquiv (w.costructuredArrowRightwards X₃) _)
exact IsColimit.equivIsoColimit (Cocones.ext (Iso.refl _))
lemma nonempty_isPointwiseLeftKanExtensionAt_compTwoSquare_iff
(w : TwoSquare T L R B) (X₃ : C₃) [Final (w.costructuredArrowRightwards X₃)] :
Nonempty ((E.compTwoSquare w).IsPointwiseLeftKanExtensionAt X₃) ↔
Nonempty (E.IsPointwiseLeftKanExtensionAt (B.obj X₃)) :=
(E.isPointwiseLeftKanExtensionAtCompTwoSquareEquiv w _).nonempty_congr
variable {E} in
/-- If `w : TwoSquare T L R B` is a Guitart exact square, and `E` is a pointwise
left Kan extension of `F` along `R`, then `E.compTwoSquare w` is a pointwise left
Kan extension of `T ⋙ F` along `L`. -/
noncomputable def IsPointwiseLeftKanExtension.compTwoSquare
(h : E.IsPointwiseLeftKanExtension) (w : TwoSquare T L R B) [w.GuitartExact] :
(E.compTwoSquare w).IsPointwiseLeftKanExtension :=
fun X₃ ↦ (E.isPointwiseLeftKanExtensionAtCompTwoSquareEquiv w X₃).symm (h _)
/-- If `w : TwoSquare T L R B` is a Guitart exact square, with `B` essentially surjective,
and `E` is a left extension of `F` along `R`, then `E` is a pointwise
left Kan extension of `F` along `R` provided `E.compTwoSquare w` is a pointwise left
Kan extension of `T ⋙ F` along `L`. -/
noncomputable def isPointwiseLeftKanExtensionOfCompTwoSquare
(w : TwoSquare T L R B) [w.GuitartExact] [B.EssSurj]
(h : (E.compTwoSquare w).IsPointwiseLeftKanExtension) :
E.IsPointwiseLeftKanExtension :=
fun X₄ ↦ E.isPointwiseLeftKanExtensionAtOfIso'
(E.isPointwiseLeftKanExtensionAtCompTwoSquareEquiv w _ (h (B.objPreimage X₄)))
(B.objObjPreimageIso X₄)
/-- If `w : TwoSquare T L R B` is a Guitart exact square, with `B` essentially surjective,
and `E` is a left extension of `F` along `R`, then `E` is a pointwise left Kan extension
of `F` along `R` iff `E.compTwoSquare w` is a pointwise left Kan extension
of `T ⋙ F` along `L`. -/
noncomputable def isPointwiseLeftKanExtensionEquivOfGuitartExact
(w : TwoSquare T L R B) [w.GuitartExact] [B.EssSurj] :
(E.compTwoSquare w).IsPointwiseLeftKanExtension ≃
E.IsPointwiseLeftKanExtension where
toFun h := E.isPointwiseLeftKanExtensionOfCompTwoSquare w h
invFun h := h.compTwoSquare w
left_inv _ := by subsingleton
right_inv _ := by subsingleton
end Functor.LeftExtension
namespace TwoSquare
variable {T : C₁ ⥤ C₂} {L : C₁ ⥤ C₃} {R : C₂ ⥤ C₄} {B : C₃ ⥤ C₄}
(w : TwoSquare T L R B)
include w
lemma hasPointwiseLeftKanExtensionAt_iff
(F : C₂ ⥤ D) (X₃ : C₃) [(w.costructuredArrowRightwards X₃).Final] :
L.HasPointwiseLeftKanExtensionAt (T ⋙ F) X₃ ↔
R.HasPointwiseLeftKanExtensionAt F (B.obj X₃) := by
dsimp [Functor.HasPointwiseLeftKanExtensionAt]
rw [← Functor.Final.hasColimit_comp_iff (w.costructuredArrowRightwards X₃)]
rfl
lemma hasPointwiseLeftKanExtension_iff [w.GuitartExact] [B.EssSurj] (F : C₂ ⥤ D) :
L.HasPointwiseLeftKanExtension (T ⋙ F) ↔
R.HasPointwiseLeftKanExtension F := by
dsimp [Functor.HasPointwiseLeftKanExtension]
simp only [hasPointwiseLeftKanExtensionAt_iff w]
refine ⟨fun h X₄ ↦ ?_, fun h _ ↦ h _⟩
rw [← Functor.hasPointwiseLeftKanExtensionAt_iff_of_iso _ _ (B.objObjPreimageIso X₄)]
apply h
lemma hasPointwiseLeftKanExtension [w.GuitartExact]
(F : C₂ ⥤ D) [R.HasPointwiseLeftKanExtension F] :
L.HasPointwiseLeftKanExtension (T ⋙ F) :=
((R.pointwiseLeftKanExtensionIsPointwiseLeftKanExtension
F).compTwoSquare w).hasPointwiseLeftKanExtension
lemma hasLeftKanExtension [w.GuitartExact]
(F : C₂ ⥤ D) [R.HasPointwiseLeftKanExtension F] :
L.HasLeftKanExtension (T ⋙ F) := by
have := w.hasPointwiseLeftKanExtension F
infer_instance
section
open Functor
section
variable [∀ (F : C₁ ⥤ D), L.HasLeftKanExtension F] [∀ (F : C₂ ⥤ D), R.HasLeftKanExtension F]
/-- The base change natural transformation for left Kan extensions associated to
a 2-square. -/
@[simps -isSimp]
noncomputable def lanBaseChange :
(whiskeringLeft C₁ C₂ D).obj T ⋙ L.lan ⟶ R.lan ⋙ (whiskeringLeft C₃ C₄ D).obj B where
app F :=
((L.lanAdjunction D).homEquiv _ _).symm
((LeftExtension.mk _ (R.lanUnit.app F)).compTwoSquare w).hom
naturality {F₁ F₂} τ := by
dsimp
refine (Adjunction.homEquiv_naturality_left_symm ..).symm.trans
(Eq.trans ?_ (Adjunction.homEquiv_naturality_right_symm ..))
congr 1
ext X
have := R.lanUnit.naturality_app (T.obj X) τ
simp [reassoc_of% this]
lemma isIso_lanBaseChange_app_iff (F : C₂ ⥤ D) :
IsIso (w.lanBaseChange.app F) ↔
IsLeftKanExtension _ ((LeftExtension.mk _ (R.lanUnit.app F)).compTwoSquare w).hom := by
rw [lanBaseChange_app, isIso_lanAdjunction_homEquiv_symm_iff]
simp
instance isIso_lanBaseChange_app (F : C₂ ⥤ D)
[R.HasPointwiseLeftKanExtension F] [w.GuitartExact] :
IsIso (w.lanBaseChange.app F) := by
rw [isIso_lanBaseChange_app_iff]
let hF := isPointwiseLeftKanExtensionOfIsLeftKanExtension (F := F) _ (R.lanUnit.app F)
exact (hF.compTwoSquare w).isLeftKanExtension
end
instance [∀ (F : C₁ ⥤ D), L.HasLeftKanExtension F]
[∀ (F : C₂ ⥤ D), R.HasPointwiseLeftKanExtension F] [w.GuitartExact] :
IsIso (w.lanBaseChange (D := D)) := by
rw [NatTrans.isIso_iff_isIso_app]
infer_instance
end
end TwoSquare
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/GuitartExact/VerticalComposition.lean | import Mathlib.CategoryTheory.CatCommSq
import Mathlib.CategoryTheory.GuitartExact.Basic
/-!
# Vertical composition of Guitart exact squares
In this file, we show that the vertical composition of Guitart exact squares
is Guitart exact.
-/
namespace CategoryTheory
open Category
variable {C₁ C₂ C₃ D₁ D₂ D₃ : Type*} [Category C₁] [Category C₂] [Category C₃]
[Category D₁] [Category D₂] [Category D₃]
namespace TwoSquare
section WhiskerVertical
variable {T : C₁ ⥤ D₁} {L : C₁ ⥤ C₂} {R : D₁ ⥤ D₂} {B : C₂ ⥤ D₂} (w : TwoSquare T L R B)
{L' : C₁ ⥤ C₂} {R' : D₁ ⥤ D₂}
/-- Given `w : TwoSquare T L R B`, one may obtain a 2-square `TwoSquare T L' R' B` if we
provide natural transformations `α : L ⟶ L'` and `β : R' ⟶ R`. -/
@[simps!]
def whiskerVertical (α : L ⟶ L') (β : R' ⟶ R) :
TwoSquare T L' R' B :=
(w.whiskerLeft α).whiskerRight β
namespace GuitartExact
/-- A 2-square stays Guitart exact if we replace the left and right functors
by isomorphic functors. See also `whiskerVertical_iff`. -/
lemma whiskerVertical [w.GuitartExact] (α : L ≅ L') (β : R ≅ R') :
(w.whiskerVertical α.hom β.inv).GuitartExact := by
rw [guitartExact_iff_initial]
intro X₂
let e : structuredArrowDownwards (w.whiskerVertical α.hom β.inv) X₂ ≅
w.structuredArrowDownwards X₂ ⋙ (StructuredArrow.mapIso (β.app X₂) ).functor :=
NatIso.ofComponents (fun f => StructuredArrow.isoMk (α.symm.app f.right) (by
dsimp
simp only [NatTrans.naturality_assoc, assoc, ← B.map_comp,
Iso.hom_inv_id_app, B.map_id, comp_id]))
rw [Functor.initial_natIso_iff e]
infer_instance
/-- A 2-square is Guitart exact iff it is so after replacing the left and right functors by
isomorphic functors. -/
@[simp]
lemma whiskerVertical_iff (α : L ≅ L') (β : R ≅ R') :
(w.whiskerVertical α.hom β.inv).GuitartExact ↔ w.GuitartExact := by
constructor
· intro h
have : w = (w.whiskerVertical α.hom β.inv).whiskerVertical α.inv β.hom := by
ext X₁
simp only [Functor.comp_obj, whiskerVertical_app, assoc, Iso.hom_inv_id_app_assoc,
← B.map_comp, Iso.hom_inv_id_app, B.map_id, comp_id]
rw [this]
exact whiskerVertical (w.whiskerVertical α.hom β.inv) α.symm β.symm
· intro h
exact whiskerVertical w α β
instance [w.GuitartExact] (α : L ⟶ L') (β : R' ⟶ R)
[IsIso α] [IsIso β] : (w.whiskerVertical α β).GuitartExact :=
whiskerVertical w (asIso α) (asIso β).symm
end GuitartExact
end WhiskerVertical
section VerticalComposition
variable {H₁ : C₁ ⥤ D₁} {L₁ : C₁ ⥤ C₂} {R₁ : D₁ ⥤ D₂} {H₂ : C₂ ⥤ D₂}
(w : TwoSquare H₁ L₁ R₁ H₂)
{L₂ : C₂ ⥤ C₃} {R₂ : D₂ ⥤ D₃} {H₃ : C₃ ⥤ D₃}
(w' : TwoSquare H₂ L₂ R₂ H₃)
/-- The canonical isomorphism between
`w.structuredArrowDownwards Y₁ ⋙ w'.structuredArrowDownwards (R₁.obj Y₁)` and
`(w ≫ᵥ w').structuredArrowDownwards Y₁.` -/
def structuredArrowDownwardsComp (Y₁ : D₁) :
w.structuredArrowDownwards Y₁ ⋙ w'.structuredArrowDownwards (R₁.obj Y₁) ≅
(w ≫ᵥ w').structuredArrowDownwards Y₁ :=
NatIso.ofComponents (fun _ => StructuredArrow.isoMk (Iso.refl _))
/-- The vertical composition of 2-squares. (Variant where we allow the replacement of
the vertical compositions by isomorphic functors.) -/
@[simps!]
def vComp' {L₁₂ : C₁ ⥤ C₃} {R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ L₂ ≅ L₁₂)
(eR : R₁ ⋙ R₂ ≅ R₁₂) : TwoSquare H₁ L₁₂ R₁₂ H₃ :=
(w ≫ᵥ w').whiskerVertical eL.hom eR.inv
namespace GuitartExact
instance vComp [hw : w.GuitartExact] [hw' : w'.GuitartExact] :
(w ≫ᵥ w').GuitartExact := by
simp only [TwoSquare.guitartExact_iff_initial]
intro Y₁
rw [← Functor.initial_natIso_iff (structuredArrowDownwardsComp w w' Y₁)]
infer_instance
instance vComp' [GuitartExact w] [GuitartExact w'] {L₁₂ : C₁ ⥤ C₃}
{R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ L₂ ≅ L₁₂)
(eR : R₁ ⋙ R₂ ≅ R₁₂) : (w.vComp' w' eL eR).GuitartExact := by
dsimp only [TwoSquare.vComp']
infer_instance
lemma vComp_iff_of_equivalences (eL : C₂ ≌ C₃) (eR : D₂ ≌ D₃)
(w' : H₂ ⋙ eR.functor ≅ eL.functor ⋙ H₃) :
(w ≫ᵥ w'.hom).GuitartExact ↔ w.GuitartExact := by
constructor
· intro hww'
letI : CatCommSq H₂ eL.functor eR.functor H₃ := ⟨w'⟩
have hw' : CatCommSq.iso H₂ eL.functor eR.functor H₃ = w' := rfl
letI : CatCommSq H₃ eL.inverse eR.inverse H₂ := CatCommSq.vInvEquiv _ _ _ _ inferInstance
let w'' := CatCommSq.iso H₃ eL.inverse eR.inverse H₂
let α : (L₁ ⋙ eL.functor) ⋙ eL.inverse ≅ L₁ :=
Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft L₁ eL.unitIso.symm ≪≫ L₁.rightUnitor
let β : (R₁ ⋙ eR.functor) ⋙ eR.inverse ≅ R₁ :=
Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft R₁ eR.unitIso.symm ≪≫ R₁.rightUnitor
have : w = (w ≫ᵥ w'.hom).vComp' w''.hom α β := by
ext X₁
simp? [w'', α, β] says
simp only [Functor.comp_obj, vComp'_app, Iso.trans_inv, Functor.isoWhiskerLeft_inv,
Iso.symm_inv, assoc, NatTrans.comp_app, Functor.id_obj, Functor.rightUnitor_inv_app,
Functor.whiskerLeft_app, Functor.associator_inv_app, comp_id, id_comp, vComp_app,
Functor.map_comp, Equivalence.inv_fun_map, CatCommSq.vInv_iso_hom_app, Iso.trans_hom,
Functor.isoWhiskerLeft_hom, Iso.symm_hom, Functor.associator_hom_app,
Functor.rightUnitor_hom_app, Iso.hom_inv_id_app_assoc, w'', α, β]
simp only [hw', ← eR.inverse.map_comp_assoc]
rw [Equivalence.counitInv_app_functor, ← Functor.comp_map, ← NatTrans.naturality_assoc]
simp [← H₂.map_comp]
rw [this]
infer_instance
· intro
exact vComp w w'.hom
lemma vComp'_iff_of_equivalences (E : C₂ ≌ C₃) (E' : D₂ ≌ D₃)
(w' : H₂ ⋙ E'.functor ≅ E.functor ⋙ H₃) {L₁₂ : C₁ ⥤ C₃}
{R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ E.functor ≅ L₁₂)
(eR : R₁ ⋙ E'.functor ≅ R₁₂) :
(w.vComp' w'.hom eL eR).GuitartExact ↔ w.GuitartExact := by
rw [← vComp_iff_of_equivalences w E E' w', TwoSquare.vComp', whiskerVertical_iff]
end GuitartExact
end VerticalComposition
end TwoSquare
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/GuitartExact/Over.lean | import Mathlib.CategoryTheory.GuitartExact.Basic
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts
/-!
# Guitart exact squares involving `Over` categories
Let `F : C ⥤ D` be a functor and `X : C`. One may consider the
commutative square of categories where vertical functors are `Over.forget`:
```
Over.post F
Over X ⥤ Over (F.obj X)
| |
v v
C ⥤ D
F
```
We show that this square is Guitart exact if for all `Y : C`, the binary product `X ⨯ Y`
exists and `F` commutes with it.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
open Limits
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
(F : C ⥤ D) (X : C)
/-- Given `F : C ⥤ D` and `X : C`, this is the `2`-square
```
Over.post F
Over X ⥤ Over (F.obj X)
| |
v v
C ⥤ D
F
```
with `Over.forget` as vertical functors. -/
abbrev TwoSquare.overPost :
TwoSquare (Over.post F) (Over.forget X) (Over.forget (F.obj X)) F :=
TwoSquare.mk _ _ _ _ (𝟙 _)
instance [∀ (Y : C), HasBinaryProduct X Y] [∀ (Y : C), PreservesLimit (pair X Y) F] :
(TwoSquare.overPost F X).GuitartExact where
isConnected_rightwards {W Z} g := by
let P : (TwoSquare.overPost F X).StructuredArrowRightwards g :=
TwoSquare.StructuredArrowRightwards.mk _ _ (Over.mk (Y := X ⨯ Z) prod.fst)
(Over.homMk (prod.lift (show W.left ⟶ F.obj X from W.hom) g ≫ inv (prodComparison F X Z))
(by simp [inv_prodComparison_map_fst])) prod.snd
(by simp [inv_prodComparison_map_snd])
have := Nonempty.intro P
let φ (Q) : Q ⟶ P := StructuredArrow.homMk (CostructuredArrow.homMk
(Over.homMk (prod.lift Q.right.left.hom Q.right.hom))) (by
ext
dsimp
rw [← cancel_mono (prodComparison F X _)]
ext
· simpa [← Functor.map_comp, P] using Over.w Q.hom.left
· simpa [← Functor.map_comp, P] using CostructuredArrow.w Q.hom)
exact zigzag_isConnected (fun Q₁ Q₂ ↦ (Zigzag.of_hom (φ Q₁)).trans (Zigzag.of_inv (φ Q₂)))
end CategoryTheory |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.