{- | Left Kan extensions.
-
- Given `f : A ->⁺ B` and `P : A ->⁺ \Cat`, {LeftKanExt} is the free left fibration ({InfCat.Fibration.FreeLeft}) on
- `f ∘ π : \Sigma⁺ (a : A) (P a) ->⁺ B`, that is, the right part of the factorization of `f ∘ π` with respect to the
- factorization system generated by `dleft : 1 ->⁺ DI`. Unlike {InfCat.Fibration.KanExtension}, this needs no fibrewise
- localization. It is a left fibration ({leftKanExt-leftFib}) with unit {leftKanExt-unit}, and its universal property is
- that of the free left fibration ({freeLeft-isLeft}). When `P` is a left fibration, its fiber over `b` is the colimit
- of `P` over the comma category `f ↓ b`.
-
- For functors to types, {LeftKanExtType} is left adjoint to restriction along `f` ({leftKanAdjunction},
- {leftKanExtType-unit}, {leftKanExtType-univ}) and covariant in `P`; its values are the fibers of {LeftKanExt}
- ({leftKanExtType-equiv}). It sends universal elements to universal elements ({leftKanExtType-univElem}),
- so it preserves representable functors: the comparison map {LeftKanExtType-repr} is an isomorphism ({LeftKanExtType-repr-iso}).
- It is compatible with composition: the comparison map {LeftKanExtType-comp} is an isomorphism ({LeftKanExtType-comp-iso}),
- and the two comparison maps are compatible ({LeftKanExtType-comp-repr}).
-
- Construction ({leftKanRightAdjoint}). For small data (`A B : \Cat u`, `P : A ->⁺ \Type u`) the fibers of
- {LeftKanExt} are small ({leftKanRightAdjoint.ext-small}), so straightening ({Resize+}, see {InfCat.Fibration.Straightening})
- gives a family {leftKanRightAdjoint.Small} with values in `\Type u`. Sections of left fibrations over its total category
- are sections over the total category of `P` ({leftKanRightAdjoint.univ}), which makes it a pointwise left adjoint.
- Since {Resize+} and the factorization are not functorial in `P`, {LeftKanExtType} is defined as the left adjoint
- of the restriction functor, which is functorial.
-}
\import Equiv
\import Function.Meta
\import InfCat.Basics
\import InfCat.Fibration.Categorical
\import InfCat.Fibration.Univalence.DirectedUnivalence
\import InfCat.Fibration.Covariant.FreeLeft
\import InfCat.Fibration.Covariant.LeftFib
\import InfCat.Fibration.Univalence.Straightening
\import InfCat.Functor.Adjunction
\import InfCat.Functor.Conservative
\import InfCat.Functor.Equiv
\import InfCat.OFS.CatOFS
\import InfCat.Paths
\import InfCat.Rezk
\import InfCat.Yoneda.CovariantYoneda
\import Logic
\import Paths
\import Paths.Meta
-- | The left Kan extension along {f} of functors to `\Type u`.
\func LeftKanExtType.{u} {A B : \Cat u} (f : A ->⁺ B) (P :⁺ A ->⁺ \Type u) (b :⁺ B) : \Type u
=> (leftKanRightAdjoint f).ladj P b
-- | Left Kan extension along {f} is left adjoint to restriction along {f}.
\func leftKanAdjunction.{u} {A B : \Cat u} (f : A ->⁺ B) : QAdjunction (A ->⁺ \Type u) (B ->⁺ \Type u)
=> (leftKanRightAdjoint f).toAdjunction
-- | The unit of {LeftKanExtType}.
\func leftKanExtType-unit.{u} {A B : \Cat u} (f : A ->⁺ B) (P :⁺ A ->⁺ \Type u) : P ~> (\lam a => LeftKanExtType f P (f a))
=> (leftKanRightAdjoint f).heta P
-- | The universal property of {LeftKanExtType}: natural transformations out of it are natural transformations out of {P}.
\lemma leftKanExtType-univ.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) (Q : B ->⁺ \Type u)
: IsEquiv {LeftKanExtType f P ~> Q} {P ~> (\lam a => Q (f a))}
(\lam g => comp (leftKanExtType-unit f P) (dmap (\lam G a =>⁺ G (f a)) g))
=> (leftKanRightAdjoint f).heta-univ P Q
-- | The universal arrow given by {LeftKanExtType}.
\func leftKanExtType-univArrow.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u)
: UnivArrow {A ->⁺ \Type u} {B ->⁺ \Type u} (\lam G a =>⁺ G (f a)) P \cowith
| L0x => LeftKanExtType f P
| eta0x => leftKanExtType-unit f P
| eta0x-univ {Q} => leftKanExtType-univ f P Q
\lemma leftKanExtType-leftFib.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) : IsLeftFib (LeftKanExtType f P)
=> leftFib-pullback (LeftKanExtType f P) universe-leftFib
-- | If {p} is a universal element of {P} at {a}, then its image under the unit is a universal element of the left Kan extension at `f a`.
\lemma leftKanExtType-univElem.{u} {A B : \Cat u} (f : A ->⁺ B) {P : A ->⁺ \Type u} {a : A} {p : P a} (U : IsUnivElem P a p)
: IsUnivElem (LeftKanExtType f P) (f a) (~>_-> (dmap (\lam H => H a) (leftKanExtType-unit f P)) p)
=> \lam Q => transport IsEquiv
(ext \lam g => pmap (~>_-> __ p) (dmap_comp (\lam (H : A ->⁺ \Type u) => H a) {_} {_} {_} {leftKanExtType-unit f P} {dmap (\lam G a' =>⁺ G (f a')) g})
*> ~>_->_comp _ _)
(IsEquiv.trans (leftKanExtType-univ f P Q) (U (\lam a' => Q (f a'))))
{- | The comparison map from the left Kan extension of the representable functor of {x} to the representable functor of `f x`,
- adjoint to the action of {f} on arrows out of {x}.
-}
\sfunc LeftKanExtType-repr.{u} {A B : \Cat u} (f : A ->⁺ B) (x : A) : LeftKanExtType f (ReprFunctor x) ~> ReprFunctor (f x)
=> (leftKanAdjunction f).heta_heps-rl (IsEquiv.ret (yonedaCov x \lam a => ReprFunctor (f x) (f a)) (Straight.toStraight idd))
-- | {LeftKanExtType-repr} sends the unit at an arrow {b} out of {x} to its image under {f}.
\sfunc LeftKanExtType-repr-unit.{u} {A B : \Cat u} {f : A ->⁺ B} {x y : A} (b : x ~> y)
: ~>_-> (dmap (__ (f y)) (LeftKanExtType-repr f x)) (~>_-> (dmap (__ y) (leftKanExtType-unit f (ReprFunctor x))) (Straight.toStraight b))
= Straight.toStraight (dmap f b)
=> inv (~>_->_comp-fam (leftKanExtType-unit f (ReprFunctor x)) (dmap (\lam Q a =>⁺ Q (f a)) (LeftKanExtType-repr f x)) y (Straight.toStraight b))
*> pmap (\lam m => ~>_-> (dpath \lam i => comp (leftKanExtType-unit f (ReprFunctor x)) (dmap (\lam Q a =>⁺ Q (f a)) m) i y) (Straight.toStraight b))
(\peval LeftKanExtType-repr f x)
*> pmap (\lam (s : ReprFunctor x ~> (\lam a => ReprFunctor (f x) (f a))) => ~>_-> (dmap (__ y) s) (Straight.toStraight b))
(leftKanAdjunction f).heta_heps-rlr
*> inv yonedaCov-component
*> pmap (~>_-> (dmap (\lam a => ReprFunctor (f x) (f a)) b)) (IsEquiv.f_ret (yonedaCov x \lam a => ReprFunctor (f x) (f a)))
*> ReprFunctor-transport-idd (dmap f b)
-- | Left Kan extension preserves representable functors.
\lemma LeftKanExtType-repr-iso.{u} {A B : \Cat u} {f : A ->⁺ B} {x : A} : IsIso (LeftKanExtType-repr f x)
=> (univElem-iso-char (leftKanExtType-univElem f (yonedaCov x)) (yonedaCov (f x))
(~>_->_idd *> inv (LeftKanExtType-repr-unit idd))).2 idd-iso
-- | {LeftKanExtType-repr} is natural in {x}.
\sfunc LeftKanExtType-repr-natural.{u} {A B : \Cat u} {f : A ->⁺ B} {x y : A} (b : x ~> y)
: comp (dmap (\lam P => LeftKanExtType f P) (IsEquiv.ret yonedaEmbCov b)) (LeftKanExtType-repr f x)
= comp (LeftKanExtType-repr f y) (IsEquiv.ret yonedaEmbCov (dmap f b))
=> \let | m => IsEquiv.ret yonedaEmbCov b
| m' => IsEquiv.ret yonedaEmbCov (dmap f b)
| uy => ~>_-> (dmap (__ y) (leftKanExtType-unit f (ReprFunctor y))) (Straight.toStraight idd)
\in IsEquiv.isInj (leftKanExtType-univElem f (yonedaCov y) (ReprFunctor (f x))) $
~>_->_comp-fam _ _ (f y) uy
*> pmap (~>_-> (dmap (__ (f y)) (LeftKanExtType-repr f x)))
(~>_->-natural (\lam P a => ~>_-> (dmap (__ y) (leftKanExtType-unit f P)) a) m
*> pmap (~>_-> (dmap (__ y) (leftKanExtType-unit f (ReprFunctor x))))
(inv (ReprFunctor.equiv.ret_f _) *> pmap Straight.toStraight (IsEquiv.f_ret yonedaEmbCov)))
*> LeftKanExtType-repr-unit {A} {B} {f} b
*> pmap Straight.toStraight (inv (IsEquiv.f_ret yonedaEmbCov)) *> ReprFunctor.equiv.ret_f _
*> pmap (~>_-> (dmap (__ (f y)) m')) (inv (LeftKanExtType-repr-unit idd))
*> inv (~>_->_comp-fam _ _ (f y) uy)
-- | The comparison map for left Kan extension along a composite, adjoint to the composite of the units.
\sfunc LeftKanExtType-comp.{u} {A B C : \Cat u} (f : A ->⁺ B) (g : B ->⁺ C) (P :⁺ A ->⁺ \Type u)
: LeftKanExtType (\lam a => g (f a)) P ~> LeftKanExtType g (LeftKanExtType f P)
=> (leftKanAdjunction (\lam a => g (f a))).heta_heps-rl $
comp (leftKanExtType-unit f P) $ dmap (\lam G a =>⁺ G (f a)) (leftKanExtType-unit g (LeftKanExtType f P))
-- | {LeftKanExtType-comp} sends the unit along the composite to the composite of the units.
\sfunc LeftKanExtType-comp-unit.{u} {A B C : \Cat u} {f : A ->⁺ B} {g : B ->⁺ C} {P : A ->⁺ \Type u} {a : A} (p : P a)
: ~>_-> (dmap (__ (g (f a))) (LeftKanExtType-comp f g P)) (~>_-> (dmap (__ a) (leftKanExtType-unit (\lam a => g (f a)) P)) p)
= ~>_-> (dmap (__ (f a)) (leftKanExtType-unit g (LeftKanExtType f P))) (~>_-> (dmap (__ a) (leftKanExtType-unit f P)) p)
=> inv (~>_->_comp-fam (leftKanExtType-unit (\lam a => g (f a)) P) (dmap (\lam Q a =>⁺ Q (g (f a))) (LeftKanExtType-comp f g P)) a p)
*> pmap (\lam m => ~>_-> (dmap (__ a) (comp (leftKanExtType-unit (\lam a => g (f a)) P) (dmap (\lam Q a =>⁺ Q (g (f a))) m))) p)
(\peval LeftKanExtType-comp f g P)
*> pmap (\lam s => ~>_-> (dmap (__ a) s) p) ((leftKanAdjunction (\lam a => g (f a))).heta_heps-rlr {_} {_} {comp (leftKanExtType-unit f P) _})
*> ~>_->_comp-fam (leftKanExtType-unit f P) (dmap (\lam Q a =>⁺ Q (f a)) (leftKanExtType-unit g (LeftKanExtType f P))) a p
-- | Left Kan extension along a composite is the composite of left Kan extensions.
\lemma LeftKanExtType-comp-iso.{u} {A B C : \Cat u} {f : A ->⁺ B} {g : B ->⁺ C} {P : A ->⁺ \Type u} : IsIso (LeftKanExtType-comp f g P)
=> precomp-equiv=>iso \lam Q => IsEquiv.leftFactor (leftKanExtType-univ (\lam a => g (f a)) P Q) $ transport IsEquiv
(ext \lam k => pmap (comp _) (dmap_comp (\lam (G : B ->⁺ \Type u) a =>⁺ G (f a))) *> comp-assoc
*> pmap (comp __ _) (inv (pmap (\lam m => comp (leftKanExtType-unit (\lam a => g (f a)) P) (dmap (\lam (G : C ->⁺ \Type u) a =>⁺ G (g (f a))) m))
(\peval LeftKanExtType-comp f g P)
*> (leftKanAdjunction \lam a => g (f a)).heta_heps-rlr))
*> inv comp-assoc *> pmap (comp _) (inv (dmap_comp \lam (G : C ->⁺ \Type u) a =>⁺ G (g (f a)))))
(IsEquiv.trans (leftKanExtType-univ g (LeftKanExtType f P) Q) (leftKanExtType-univ f P \lam b => Q (g b)))
-- | Left Kan extension along the identity is the identity: the unit is universal among arrows out of {P}.
\sfunc LeftKanExtType-id.{u} {A : \Cat u} {P :⁺ A ->⁺ \Type u} : LeftKanExtType (\lam a => a) P = P
=> inv $ path \lam i => natIso-path (leftKanExtType-unit \lam a => a) (\lam P => precomp-equiv=>iso (leftKanExtType-univ (\lam a => a) P)) i P
-- | {LeftKanExtType-comp} is compatible with {LeftKanExtType-repr}.
\sfunc LeftKanExtType-comp-repr.{u} {A B C : \Cat u} {f : A ->⁺ B} {g : B ->⁺ C} {x : A}
: comp (LeftKanExtType-comp f g (ReprFunctor x))
(comp (dmap (\lam P => LeftKanExtType g P) (LeftKanExtType-repr f x)) (LeftKanExtType-repr g (f x)))
= LeftKanExtType-repr (\lam a => g (f a)) x
=> \let | gf (a :⁺ A) => g (f a)
| u0 => ~>_-> (dmap (__ x) (leftKanExtType-unit gf (ReprFunctor x))) (Straight.toStraight idd)
| uf => ~>_-> (dmap (__ x) (leftKanExtType-unit f (ReprFunctor x))) (Straight.toStraight idd)
\in IsEquiv.isInj (leftKanExtType-univElem gf {ReprFunctor x} {x} {Straight.toStraight idd} (yonedaCov x) (ReprFunctor (g (f x)))) $
~>_->_comp-fam _ _ (g (f x)) u0
*> pmap (~>_-> (dmap (__ (g (f x))) (comp (dmap (\lam P => LeftKanExtType g P) (LeftKanExtType-repr f x)) (LeftKanExtType-repr g (f x)))))
(LeftKanExtType-comp-unit (Straight.toStraight idd))
*> ~>_->_comp-fam _ _ (g (f x)) _
*> pmap (~>_-> (dmap (__ (g (f x))) (LeftKanExtType-repr g (f x))))
(~>_->-natural (\lam P a => ~>_-> (dmap (__ (f x)) (leftKanExtType-unit g P)) a) (LeftKanExtType-repr f x)
*> pmap (~>_-> (dmap (__ (f x)) (leftKanExtType-unit g (ReprFunctor (f x))))) (LeftKanExtType-repr-unit idd))
*> LeftKanExtType-repr-unit idd
*> inv (LeftKanExtType-repr-unit idd)
-- | {Small} is pointwise left adjoint to restriction along {f}.
\func leftKanRightAdjoint.{u} {A B : \Cat u} (f : A ->⁺ B) : RightAdjoint {A ->⁺ \Type u} {B ->⁺ \Type u} (\lam Q a => Q (f a)) \cowith
| lob P => Small f P
| eta0 P => depUnivalence.ret (\lam t => unit f P t.1 t.2)
| eta0-adjoint {P} {Q} => IsEquiv.leftFactor (inP depUnivalence) $ transport IsEquiv
(path \lam i g => comp-unit f P Q g i)
(IsEquiv.trans (inP depUnivalence) (univ f P (leftFib-pullback Q universe-leftFib)))
\where {
-- | The left Kan extension of {P} along {f}.
\func Large {A B : \Cat} (f : A ->⁺ B) (P : A ->⁺ \Cat) (b :⁺ B) : \Cat
=> FreeLeft {\Sigma⁺ (a : A) (P a)} (\lam t => f t.1) b
\lemma Large-leftFib {A B : \Cat} (f : A ->⁺ B) (P : A ->⁺ \Cat) : IsLeftFib (Large f P)
=> freeLeft-leftFib _
-- | The comparison map from {P} to the pullback of {Large} along {f}.
\func Large-unit {A B : \Cat} (f : A ->⁺ B) (P : A ->⁺ \Cat) (a :⁺ A) (x :⁺ P a) : Large f P (f a)
=> freeLeft-unit (\lam t => f t.1) ((a, x) : \Sigma⁺ (a : A) (P a))
-- | The fibers of {Large} of a small family along a functor between small categories are small.
\lemma ext-small.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) (b : B) : IsSmall.{u} (Large f P b)
=> IsSmall.fromGroupoid (leftFib-grpd (Large-leftFib f P) b) \new QEquiv {
| A => \Sigma (d : FreeLeftTot (\lam t => f t.1)) (freeLeftProj d = b)
| B => Large f P b
| f x => (x.1, x.2)
| ret y => (y.1, y.2)
| ret_f _ => idp
| f_sec _ => idp
}
-- | {Large} straightened to a family with values in `\Type u`.
\func Small.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) (b :⁺ B) : \Type u
=> Straight (Large-leftFib f P) (ext-small f P) b
-- | The comparison map from {P} to the pullback of {Small} along {f}.
\func unit.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) (a :⁺ A) (x :⁺ P a) : Small f P (f a)
=> Straight.toStraight (Large-unit f P a x)
-- | The total category of {Small} is equivalent to that of the free left fibration.
\func total.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u)
: HQEquiv {FreeLeftTot {\Sigma⁺ (a : A) (P a)} (\lam t => f t.1)} {\Sigma⁺ (b : B) (Small f P b)} \cowith
| f d => (freeLeftProj d, Straight.toStraight (d, idp))
| finv s => (Straight.fromStraight s.2).1
| finv_f => idpe
| f_finv s => \let x =>⁺ Straight.fromStraight s.2
\in path (\lam i => (x.2 i, Straight.toStraight (x.1, path \lam j => x.2 @ I.squeeze i j)))
*> path (\lam i => (s.1, Straight.toStraight_fromStraight s.2 i))
-- | The unit of {Small} on total categories is left orthogonal to every left fibration over {B}.
\lemma isLeft.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) {E : \Cat} {h : E ->⁺ B} (hl : IsLeftFib (Fibers h))
: IsOrthogonal {\Sigma⁺ (a : A) (P a)} {\Sigma⁺ (b : B) (Small f P b)} (\lam t => (f t.1, unit f P t.1 t.2)) h
=> IsOrthogonal_o-left (freeLeft-isLeft hl) (IsOrthogonal_IsHEquiv-left (inP (total f P)))
-- | Sections over the total category of {Small} of a left fibration {Q} over {B} are maps from {P} to its pullback along {f}.
\lemma univ.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) {Q : B ->⁺ \Cat} (Ql : IsLeftFib Q)
: IsEquiv {\Pi (s :⁺ \Sigma⁺ (b : B) (Small f P b)) -> Q s.1} {\Pi (t :⁺ \Sigma⁺ (a : A) (P a)) -> Q (f t.1)}
(\lam g t => g (f t.1, unit f P t.1 t.2))
=> IsOrthogonal-family-sections (isLeft f P (leftFib-total Ql)) __.1
-- | Under {depUnivalence}, postcomposing the unit of {Small} with a restricted arrow is restriction of sections.
\sfunc comp-unit.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) (Q : B ->⁺ \Type u) (g : Small f P ~> Q)
: (\lam (t :⁺ \Sigma⁺ (a : A) (P a)) => depUnivalence g (f t.1, unit f P t.1 t.2))
= depUnivalence (comp (depUnivalence.ret \lam t => unit f P t.1 t.2) (dmap (\lam G a =>⁺ G (f a)) g))
=> \let | eta => depUnivalence.ret (\lam t => unit f P t.1 t.2)
| rg => dmap (\lam G a =>⁺ G (f a)) g
\in ext \lam t => inv (~>_->_comp (dmap (\lam H => H t.1) eta) (dmap (\lam H => H t.1) rg))
*> pmap+ (~>_-> __ t.2) (inv (dmap_comp (\lam (H : A ->⁺ \Type u) => H t.1) {_} {_} {_} {eta} {rg}))
-- | The comparison map from {LeftKanExtType} to {Small}, adjoint to the unit of {Small}.
\func ladj-map.{u} {A B : \Cat u} (f : A ->⁺ B) (P : A ->⁺ \Type u) : LeftKanExtType f P ~> Small f P
=> (leftKanAdjunction f).heta_heps-rl (depUnivalence.ret \lam t => unit f P t.1 t.2)
-- | {LeftKanExtType} agrees with {Small}.
\lemma ladj-iso.{u} {A B : \Cat u} {f : A ->⁺ B} {P : A ->⁺ \Type u} : IsIso (ladj-map f P)
=> precomp-equiv=>iso \lam Q => IsEquiv.leftFactor (leftKanExtType-univ f P Q) $ transport IsEquiv
(ext \lam k => pmap (comp __ _) (inv ((leftKanAdjunction f).heta_heps-rlr {_} {_} {depUnivalence.ret \lam t => unit f P t.1 t.2}))
*> inv comp-assoc *> pmap (comp _) (inv (dmap_comp \lam (G : B ->⁺ \Type u) a =>⁺ G (f a))))
((leftKanRightAdjoint f).eta0-adjoint {P} {Q})
}