module Cat.CartesianClosed.Locally where

# Locally cartesian closed categoriesπ

A finitely
complete category
$C$
is said to be **locally Cartesian closed** when each of its
slice categories
is Cartesian
closed. Note that requiring finite limits in
$C$
does exclude some examples, since
$C$
might have each of its slices Cartesian closed, but lack a terminal
object.^{1} With the extra condition, a locally
Cartesian closed category is Cartesian closed.

record Locally-cartesian-closed {o β} (C : Precategory o β) : Type (o β β) where field has-is-lex : Finitely-complete C slices-cc : β A β Cartesian-closed (Slice C A) (Slice-products (Finitely-complete.pullbacks has-is-lex)) Slice-terminal-object

module _ {o β} (C : Precategory o β) (fp : Finitely-complete C) where open Locally-cartesian-closed open Finitely-complete fp open Cat.Reasoning C open Pullback module _ {A : Ob} where private module Fc = Cat.Reasoning Cat[ Slice C A , Slice C A ] Γ/ = Binary-products.Γ-functor (Slice C A) (Slice-products pullbacks) open make-natural-iso

The idea of exponentials in a slice is pretty complicated^{2}, so fortunately, there is an
alternative characterisation of local cartesian closure, which is
informed by
$Cβs$
*internal type theory*.

Recall that, when thinking about dependent type theory in a category
$C,$
we have the following dictionary: The objects of
$C$
correspond to the *contexts*
$Ξ,Ξ,β¦,$
and the morphisms
$ΞβΞ$
are the *substitutions* between those contexts. The objects in
$C/Ξ$
are the *types in context
$Ξ$*.
From this point of view, the pullback functors
implement *substitution* in a dependent type, mapping a type
$Ξβ’A$
to
$Ξβ’Ο_{β}A,$
along the substitution
$Ο:ΞβΞ.$

To make this a bit clearer, letβs focus on the simplest case, where
$Ο$
is the projection of a variable
$Ο_{1}:Ξ.AβΞ.$
Instantiating the discussion above, we discover that base change along
$Ο_{1}$
will map types
$Ξβ’B$
to their *weakenings*
$Ξ,x:Aβ’Ο_{1}B.$

Under this correspondence, what do *dependent function types*
correspond to? Letβs roll up our sleeves and write out some gosh-darn
$Ξs$
and turnstiles. Itβs not much, but itβs honest work. We have the
introduction and elimination rules

which, by abstracting away the substitution of the argument^{3}, expresses that there is an
isomorphism between derivations
$Ξβ’f:Ξ_{(x:A)}B(x)$
and
$Ξ,x:Aβ’f(x):B(x).$
If we squint, this says precisely that
$Ξ$
is a right adjoint to
the action of base change along
$Ο_{1}:Ξ.AβA!$

This is our second characterisation of locally Cartesian closed categories. Generalising away from weakenings, we should have a correspondence between $Hom(f_{β}A,B)$ and $Hom(A,Ξ_{f}B),$ for an arbitrary substitution $f:ΞβΞ.$ Back to categorical language, that is a right adjoint to the base change functor, fitting into an adjoint triple

$Ξ£_{f}β£f_{β}β£Ξ_{f}.$## From dependent productsπ

But how does this correlate to the characterisation in terms of Cartesian closed slices? Other than the intuition about βfunction types (in context) between dependent typesβ, we can do some honest category theory. First, observe that, for $f:XβA,$ the product functor $βΓf:C/AβC/A$ is isomorphically given by

$C/Af_{β}βC/XΞ£_{f}βC/A,$since products in a slice are implemented by pullbacks in $C;$ We can chase a $g:YβA$ along the above diagram to see that it first gets sent to $f_{β}g$ as in the diagram

by the pullback functor, then to $fβ(f_{β}g):XΓ_{A}YβA$ by the dependent sum. But this is exactly the object $gΓf$ in $C/A,$ so that $βΓf$ and $Ξ£_{f}f_{β}$ are indeed naturally isomorphic.

Slice-product-functor : β {X} β make-natural-iso (Ξ£f (X .map) Fβ Base-change pullbacks (X .map)) (Bifunctor.Left Γ/ X) Slice-product-functor .eta x .map = id Slice-product-functor .eta x .commutes = idr _ β pullbacks _ _ .square Slice-product-functor .inv x .map = id Slice-product-functor .inv x .commutes = idr _ β sym (pullbacks _ _ .square) Slice-product-functor .etaβinv x = ext $ idl _ Slice-product-functor .invβeta x = ext $ idl _ Slice-product-functor .natural x y f = ext $ id-comm β ap (id β_) (pullbacks _ _ .unique (pullbacks _ _ .pββuniversal) (pullbacks _ _ .pββuniversal β idl _))

If we then have a functor $Ξ_{f}$ fitting into an adjoint triple $Ξ£_{f}β£f_{β}β£Ξ_{f},$ we can compose that to obtain $Ξ£_{f}f_{β}β£Ξ_{f}f_{β},$ and, by the natural isomorphism we just constructed, $βΓfβ£Ξ_{f}f_{β}.$ Since a right adjoint to Cartesian product is exactly the definition of an exponential object, such an adjoint triple serves to conclude that each slice of $C$ is Cartesian closed.

dependent-productβlcc : (Ξ f : β {a b} (f : Hom a b) β Functor (Slice C a) (Slice C b)) β (f*β£Ξ f : β {a b} (f : Hom a b) β Base-change pullbacks f β£ Ξ f f) β Locally-cartesian-closed C dependent-productβlcc Ξ f adj = record { has-is-lex = fp ; slices-cc = slice-cc } where slice-cc : (A : Ob) β Cartesian-closed (Slice C A) _ _ slice-cc A = product-adjointβcartesian-closed (Slice C A) _ _ (Ξ» f β Ξ f (f .map) Fβ Base-change pullbacks (f .map)) Ξ» A β adjoint-natural-isol (to-natural-iso Slice-product-functor) (LFβ£GR (adj _) (Ξ£fβ£f* _ _))

module _ {o β} (C : Precategory o β) (lcc : Locally-cartesian-closed C) where open Locally-cartesian-closed lcc open Finitely-complete has-is-lex open Cat.Reasoning C open Pullback private module _ A where open Cartesian-closed (slices-cc A) public prod/ : β {a} β has-products (Slice C a) prod/ = Slice-products pullbacks pullback/ : β {b} β has-pullbacks (Slice C b) pullback/ = Slice-pullbacks pullbacks

## Recovering the adjunctionπ

Now suppose that each slice of $C$ is Cartesian closed. How do we construct the dependent product $Ξ_{f}:C/AβC/B?$ Happily, this is another case where we just have to assemble preΓ«xisting parts, like weβre putting together a theorem from IKEA.

We already know that, since
$f:AβB$
is an exponentiable
object in
$C/B,$
there is a *product along
$f$
functor*, mapping from the double slice
$(C/B)/fβC/B,$
which is a right adjoint to the constant families
functor
$C/Bβ(C/B)/f.$
And since (by the yoga of iterated
slices)
$(C/B)/f$
is identical to
$C/A,$
this becomes a functor
$Ξ_{f}:C/AβC/B,$
of the right type.

lccβdependent-product : β {a b} (f : Hom a b) β Functor (Slice C a) (Slice C b) lccβdependent-product {a} {b} f = exponentiableβproduct _ _ _ _ (has-exp b (cut f)) pullback/ Fβ Slice-twice f

It remains to verify that itβs actually an adjoint to pullback along
$f.$
We know that itβs a right adjoint to the constant families functor
$Ξ_{f}$
*on
$C/B$*,
and that constant families are given by
$Ο_{2}:gΓfβf.$
Since the Cartesian product in a slice is given by pullback, the base
change functor turns out naturally isomorphic to
$f_{β},$
when regarded as a functor
$C/BβC/A$
through the equivalence
$(C/B)/fβC/A.$

lccβpullbackβ£dependent-product : β {a b} (f : Hom a b) β Base-change pullbacks f β£ lccβdependent-product f lccβpullbackβ£dependent-product {b = b} f = adjoint-natural-isol (to-natural-iso remβ) (LFβ£GR remβ (Twiceβ£Slice f)) where remβ : constant-family prod/ β£ exponentiableβproduct (Slice C _) _ _ _ _ _ remβ = exponentiableβconstant-familyβ£product _ _ _ _ _ _ remβ : make-natural-iso (Twice-slice f Fβ constant-family prod/) (Base-change pullbacks f) remβ .eta x .map = id remβ .eta x .commutes = idr _ remβ .inv x .map = id remβ .inv x .commutes = idr _ remβ .etaβinv x = ext (idr _) remβ .invβeta x = ext (idr _) remβ .natural x y f = ext $ idr _ Β·Β· ap (pullbacks _ _ .universal) prop! Β·Β· sym (idl _)

An example is the category of locales and local homeomorphisms, $LH.$ Each slice $LH/X$ is Cartesian closed β theyβre even topoi β but $LH$ has no terminal object.β©οΈ

Indeed, even for the category $Sets,$ showing local Cartesian closure is not at all straightforward: the local exponential $f_{g}$ over $B$ is the set $β_{b:B}f_{β1}(b)βg_{β1}(b),$ though this computation is best understood in terms of slices of sets.β©οΈ

To expand on the idea of this more

*categorical*application, if we have $Ξβ’f:Ξ_{x:A}B(x),$ we first βopenβ it to uncover $Ξ,x:Aβ’f(x):B(x);$ if we then have an argument $Ξβ’a:A,$ then we can use substitution to obtain $Ξβ’f(x)[a/x]:B(a).$β©οΈ