module Cat.Displayed.Comprehension {o â o' â'} {B : Precategory o â} (E : Displayed B o' â') where
open Cat.Reasoning B open Cat.Displayed.Reasoning E open Displayed E open Functor open _=>_ open Total-hom open /-Obj open Slice-hom
Comprehension categoriesð
Fibrations provide an excellent categorical framework for studying logic and type theory, as they give us the tools required to describe objects in a context, and substitutions between them. However, this framework is missing a key ingredient: we have no way to describe context extension!
Before giving a definition, it is worth pondering what context extension does. Consider some context and type context extension yields a new context extended with a fresh variable of type along with a substitution that forgets this fresh variable.
We also have a notion of substitution extension: Given any substitution types and and term there exists some substitution such that the following square commutes.
Furthermore, when the term is simply a variable from this square is a pullback square!
Now that weâve got a general idea of how context extension ought to behave, we can begin to categorify. Our first step is to replace the category of contexts with an arbitrary category and the types with some fibration We can then encode context extension via a functor from to the codomain fibration. This is a somewhat opaque definition, so itâs worth unfolding somewhat. Note that the action of such a functor on objects takes some object over in to a pair of an object we will suggestively name in along with a map Thus, the action on objects yields both the extended context and the projection substitution. If we inspect the action on morphisms of we see that it takes some map over to a map in such that the following square commutes:
Note that this is the exact same square as above!
Furthermore, this functor ought to be fibred; this captures the situation where extending a substitution with a variable yields a pullback square.
We call such a fibred functor a comprehension structure on 1.
Comprehension : Type _ Comprehension = Vertical-fibred-functor E (Slices B)
Now, letâs make all that earlier intuition formal. Let be a fibration, and be a comprehension structure on We begin by defining context extensions, along with their associated projections.
module Comprehension (fib : Cartesian-fibration E) (P : Comprehension) where opaque open Vertical-fibred-functor P open Cartesian-fibration fib _⚟_ : â Î â Ob[ Î ] â Ob Π⚟ x = Fâ' x .domain infixl 5 _⚟_ _[_] : â {Î Î} â Ob[ Î ] â Hom Î Î â Ob[ Î ] x [ Ï ] = base-change E fib Ï .Fâ x Ïᶠ: â {Î x} â Hom (Π⚟ x) Î Ïᶠ{x = x} = Fâ' x .map
As is a fibration, we can reindex along the projection to obtain a notion of weakening.
weaken : â {Î} â (x : Ob[ Î ]) â Ob[ Î ] â Ob[ Π⚟ x ] weaken x y = y [ Ïᶠ]
Furthermore, if
is an object over
then we have a map over 쇦
between from the weakened form
of
to
Ïá¶' : â {Î} {x y : Ob[ Î ]} â Hom[ Ïᶠ] (weaken x y) y Ïá¶' = has-lift.lifting Ïᶠ_ Ïá¶'-cartesian : â {Î x y} â is-cartesian E Ïᶠ(Ïá¶' {Î} {x} {y}) Ïá¶'-cartesian = has-lift.cartesian Ïᶠ_
Next, we define extension of substitutions, and show that they commute with projections.
_⚟ˢ_ : â {Î Î x y} (Ï : Hom Î Î) â Hom[ Ï ] x y â Hom (Π⚟ x) (Π⚟ y) Ï âšŸË¢ f = Fâ' f .to infixl 8 _⚟ˢ_ sub-proj : â {Î Î x y} {Ï : Hom Î Î} â (f : Hom[ Ï ] x y) â Ïᶠâ (Ï âšŸË¢ f) â¡ Ï â Ïᶠsub-proj f = sym $ Fâ' f .commute
Crucially, when is cartesian, then the above square is a pullback.
sub-pullback : â {Î Î x y} {Ï : Hom Î Î} {f : Hom[ Ï ] x y} â is-cartesian E Ï f â is-pullback B Ïá¶ Ï (Ï âšŸË¢ f) Ïᶠsub-pullback {f = f} cart = cartesianâpullback B (F-cartesian f cart) module sub-pullback {Î Î x y} {Ï : Hom Î Î} {f : Hom[ Ï ] x y} (cart : is-cartesian E Ï f) = is-pullback (sub-pullback cart)
We also obtain a map over between the weakenings of and which also commutes with projections.
_⚟ˢ'_ : â {Î Î x y} (Ï : Hom Î Î) â (f : Hom[ Ï ] x y) â Hom[ Ï âšŸË¢ f ] (weaken x x) (weaken y y) Ï âšŸË¢' f = has-lift.universal' Ïᶠ_ (sub-proj f) (f â' Ïá¶') infixl 5 _⚟ˢ'_ sub-proj' : â {Î Î x y} {Ï : Hom Î Î} â (f : Hom[ Ï ] x y) â Ïá¶' â' (Ï âšŸË¢' f) â¡[ sub-proj f ] f â' Ïá¶' sub-proj' f = has-lift.commutesp Ïᶠ_ (sub-proj _) (f â' Ïá¶')
If we extend the identity substitution with the identity morphism, we obtain the identity morphism.
sub-id : â {Î x} â id {Î} ⚟ˢ id' {Î} {x} â¡ id sub-id = ap to F-id' sub-id' : â {Î x} â (id ⚟ˢ' id') â¡[ sub-id {Î} {x} ] id' sub-id' = symP $ has-lift.uniquep Ïᶠ_ _ (symP sub-id) (sub-proj id') id' $ idr' _ â[] symP (idl' _)
Furthermore, extending a substitution with a pair of composites is the same as composing the two extensions.
sub-â : â {ΠΠΚ x y z} â {Ï : Hom ΠΚ} {ÎŽ : Hom Î Î} {f : Hom[ Ï ] y z} {g : Hom[ ÎŽ ] x y} â (Ï â ÎŽ) ⚟ˢ (f â' g) â¡ (Ï âšŸË¢ f) â (ÎŽ ⚟ˢ g) sub-â {Ï = Ï} {ÎŽ = ÎŽ} {f = f} {g = g} = ap to F-â' sub-â' : â {ΠΠΚ x y z} â {Ï : Hom ΠΚ} {ÎŽ : Hom Î Î} {f : Hom[ Ï ] y z} {g : Hom[ ÎŽ ] x y} â ((Ï â ÎŽ) ⚟ˢ' (f â' g)) â¡[ sub-â ] (Ï âšŸË¢' f) â' (ÎŽ ⚟ˢ' g) sub-â' = symP $ has-lift.uniquep Ïᶠ_ _ (symP sub-â) (sub-proj _) _ $ pulll[] _ (sub-proj' _) â[] extendr[] _ (sub-proj' _)
We can also define the substitution that duplicates the variable via the following pullback square.
Ύᶠ: â {Î x} â Hom (Π⚟ x) (Π⚟ x ⚟ weaken x x) Ύᶠ= sub-pullback.universal (has-lift.cartesian Ïᶠ_) {pâ' = id} {pâ' = id} refl
This lets us easily show that applying projection after duplication is the identity.
proj-dup : â {Î x} â Ïᶠâ Ύᶠ{Î} {x} â¡ id proj-dup = sub-pullback.pââuniversal (has-lift.cartesian Ïᶠ_) extend-proj-dup : â {Î x} â (Ïᶠ⚟ˢ Ïá¶') â Ύᶠ{Î} {x} â¡ id extend-proj-dup = sub-pullback.pââuniversal (has-lift.cartesian Ïᶠ_)
We also obtain a substitution upstairs from the weakening of to the iterated weakening of
ÎŽá¶' : â {Î} {x : Ob[ Î ]} â Hom[ Ύᶠ] (weaken x x) (weaken (weaken x x) (weaken x x)) ÎŽá¶' = has-lift.universal' Ïᶠ(weaken _ _) proj-dup id'
We also obtain similar lemmas detailing how duplication upstairs interacts with projection.
proj-dup' : â {Î x} â Ïá¶' â' ÎŽá¶' {Î} {x} â¡[ proj-dup ] id' proj-dup' = has-lift.commutesp Ïᶠ_ proj-dup _ extend-proj-dup' : â {Î x} â (Ïᶠ⚟ˢ' Ïá¶') â' ÎŽá¶' {Î} {x} â¡[ extend-proj-dup ] id' extend-proj-dup' = has-lift.uniquepâ Ïᶠ_ _ _ _ _ _ (pulll[] _ (sub-proj' _) â[] cancelr[] _ proj-dup') (idr' _)
From this, we can conclude that ÎŽá¶'
is cartesian. The
factorisation of
is given by
This is universal, as ÎŽá¶'
is given by the universal
factorisation of
ÎŽá¶'-cartesian : â {Î x} â is-cartesian E (Ύᶠ{Î} {x}) ÎŽá¶' ÎŽá¶'-cartesian {Î = Î} {x = x} = cart where open is-cartesian cart : is-cartesian E (Ύᶠ{Î} {x}) ÎŽá¶' cart .universal m h' = hom[ cancell proj-dup ] (Ïá¶' â' h') cart .commutes m h' = cast[] $ unwrapr _ â[] has-lift.uniquepâ Ïᶠ_ _ (apâ _â_ refl (cancell proj-dup)) refl _ _ (cancell[] _ proj-dup') refl cart .unique m' p = has-lift.uniquepâ Ïᶠ_ refl refl _ _ _ refl (unwrapr _ â[] apâ _â'_ refl (apâ _â'_ refl (sym p)) â[] λ i â Ïá¶' â' cancell[] _ proj-dup' {f' = m'} i)
We can also characterize how duplication interacts with extension.
dup-extend : â {Î Î x y} {Ï : Hom Î Î} {f : Hom[ Ï ] x y} â Ύᶠâ (Ï âšŸË¢ f) â¡ (Ï âšŸË¢ f ⚟ˢ (Ï âšŸË¢' f)) â Ύᶠdup-extend {Ï = Ï} {f = f} = sub-pullback.uniqueâ (has-lift.cartesian Ïᶠ_) {p = refl} (cancell proj-dup ) (cancell extend-proj-dup) (pulll (sub-proj _) â cancelr proj-dup) (pulll (sym sub-â â apâ _⚟ˢ_ (sub-proj _) (sub-proj' _) â sub-â) â cancelr extend-proj-dup) dup-extend' : â {Î Î x y} {Ï : Hom Î Î} {f : Hom[ Ï ] x y} â ÎŽá¶' â' (Ï âšŸË¢' f) â¡[ dup-extend ] (Ï âšŸË¢ f ⚟ˢ' (Ï âšŸË¢' f)) â' ÎŽá¶' dup-extend' {Ï = Ï} {f = f} = has-lift.uniquepâ Ïᶠ_ _ _ _ _ _ (cancell[] _ proj-dup') (pulll[] _ (sub-proj' (Ï âšŸË¢' f)) â[] cancelr[] _ proj-dup')
extend-dup² : â {Î x} â (Ύᶠ{Î} {x} ⚟ˢ ÎŽá¶') â Ύᶠ⡠Ύᶠâ Ύᶠextend-dup² = sub-pullback.uniqueâ (has-lift.cartesian Ïᶠ_) {p = refl} (pulll (sub-proj _) â cancelr proj-dup) (cancell (sym sub-â â apâ _⚟ˢ_ proj-dup proj-dup' â sub-id)) (cancell proj-dup) (cancell extend-proj-dup) extend-dup²' : â {Î x} â (Ύᶠ{Î} {x} ⚟ˢ' ÎŽá¶') â' ÎŽá¶' â¡[ extend-dup² ] ÎŽá¶' â' ÎŽá¶' extend-dup²' = has-lift.uniquepâ Ïᶠ_ _ _ _ _ _ (pulll[] _ (sub-proj' ÎŽá¶') â[] cancelr[] _ proj-dup') (cancell[] _ proj-dup')
Note that we can extend the operation of context extension to a functor from the total category of to that takes every pair to
Extend : Functor (â« E) B Extend .Fâ (Î , x) = Π⚟ x Extend .Fâ (total-hom Ï f) = Ï âšŸË¢ f Extend .F-id = ap to F-id' Extend .F-â f g = ap to F-â'
There is also a natural transformation from this functor into the projection out of the total category of where each component of is a projection
proj : Extend => ÏᶠE proj .η (Î , x) = Ïᶠproj .is-natural (Î , x) (Î , y) (total-hom Ï f) = sub-proj f
Comprehension structures as comonadsð
Comprehension structures on fibrations induce comonads on the total category of These comonads are particularly nice: all of the counits are cartesian morphisms, and every square of the following form is a pullback square, provided that is cartesian.
We call such comonads comprehension comonads.
record Comprehension-comonad : Type (o â â â o' â â') where no-eta-equality field comonad : Comonad (â« E) open Comonad comonad public field counit-cartesian : â {Î x} â is-cartesian E (counit.ε (Î , x) .hom) (counit.ε (Î , x) .preserves) cartesian-pullback : (â {Î Î x y} {Ï : Hom Î Î} {f : Hom[ Ï ] x y} â is-cartesian E Ï f â is-pullback (â« E) (counit.ε (Î , x)) (total-hom Ï f) (Wâ (total-hom Ï f)) (counit.ε (Î , y)))
As promised, comprehension structures on yield comprehension comonads.
Comprehensionâcomonad : Cartesian-fibration E â Comprehension â Comprehension-comonad Comprehensionâcomonad fib P = comp-comonad where open Comprehension fib P open Comonad
We begin by constructing the endofunctor which maps a pair to the extension along with the weakening of
comonad : Comonad (â« E) comonad .W .Fâ (Î , x) = Π⚟ x , weaken x x comonad .W .Fâ (total-hom Ï f) = total-hom (Ï âšŸË¢ f) (Ï âšŸË¢' f) comonad .W .F-id = total-hom-path E sub-id sub-id' comonad .W .F-â (total-hom Ï f) (total-hom ÎŽ g) = total-hom-path E sub-â sub-â'
The counit is given by the projection substitution, and comultiplication is given by duplication.
comonad .counit .η (Î , x) = total-hom ÏᶠÏá¶' comonad .counit .is-natural (Î , x) (Î , g) (total-hom Ï f) = total-hom-path E (sub-proj f) (sub-proj' f) comonad .comult .η (Î , x) = total-hom ΎᶠΎá¶' comonad .comult .is-natural (Î , x) (Î , g) (total-hom Ï f) = total-hom-path E dup-extend dup-extend' comonad .left-ident = total-hom-path E extend-proj-dup extend-proj-dup' comonad .right-ident = total-hom-path E proj-dup proj-dup' comonad .comult-assoc = total-hom-path E extend-dup² extend-dup²'
To see that this comonad is a comprehension comonad, note that the projection substitution is cartesian. Furthermore, we can construct a pullback square in the total category of from one in the base, provided that two opposing sides are cartesian, which the projection morphism most certainly is!
comp-comonad : Comprehension-comonad comp-comonad .Comprehension-comonad.comonad = comonad comp-comonad .Comprehension-comonad.counit-cartesian = Ïá¶'-cartesian comp-comonad .Comprehension-comonad.cartesian-pullback cart = cartesian+pullbackâtotal-pullback E Ïá¶'-cartesian Ïá¶'-cartesian (sub-pullback cart) (cast[] (symP (sub-proj' _)))
We also show that comprehension comonads yield comprehension structures.
Comonadâcomprehension : Cartesian-fibration E â Comprehension-comonad â Comprehension
We begin by constructing a vertical functor that maps an lying over to the base component of the counit
Comonadâcomprehension fib comp-comonad = comprehend where open Comprehension-comonad comp-comonad open Vertical-functor open is-pullback vert : Vertical-functor E (Slices B) vert .Fâ' {Î} x = cut (counit.ε (Î , x) .hom) vert .Fâ' {f = Ï} f = slice-hom (Wâ (total-hom Ï f) .hom) (sym (ap hom (counit.is-natural _ _ _))) vert .F-id' = Slice-path B (ap hom W-id) vert .F-â' = Slice-path B (ap hom (W-â _ _))
To see that this functor is fibred, recall that pullbacks in the codomain fibration are given by pullbacks. Furthermore, if we have a pullback square in the total category of where two opposing sides are cartesian, then we have a corresponding pullback square in As the comonad is a comprehension comonad, counit is cartesian, which finishes off the proof.
fibred : is-vertical-fibred vert fibred {f = Ï} f cart = pullbackâcartesian B $ cartesian+total-pullbackâpullback E fib counit-cartesian counit-cartesian (cartesian-pullback cart) comprehend : Comprehension comprehend .Vertical-fibred-functor.vert = vert comprehend .Vertical-fibred-functor.F-cartesian = fibred
Other sources call such fibrations comprehension categories, but this is a bit of a misnomer, as they are structures on fibrations!â©ïž