module Cat.Displayed.Instances.Simple {o β} (B : Precategory o β) (has-prods : β X Y β Product B X Y) where open Cat.Reasoning B open Binary-products B has-prods
Simple fibrationsπ
One reason to be interested in fibrations is that they provide an excellent setting to study logical and type-theoretical phenomena. When constructing models of type theories, the general pattern is to construct a category of contexts and substitutions, and then to study types and terms as structures over this category. The language of displayed categories allows us to capture this situation quite succinctly by considering these extra pieces of equipment as being fibred over our category of contexts.
Focusing in, the language of simple fibrations provides us with enough structure to study simply-typed languages that have enough structure to represent contexts internally (i.e.: product types).
To start, we fix some base category with binary products. Intuitvely, this will be some sort of category of contexts, and context extension endows this category with products. We interpret a type in a context to be an object
Maps between types in contexts are then given by a map between contexts, and a map which is meant to denote a derivation of from
To encode this as a displayed category, we define the space of objects over some to be simply an object of This may seem odd, but recall that we are modeling a type theory with enough structure to consider contexts as types: if this is not the situation (IE: STLC without products), then we need to consider a more refined notion.
For the maps, we already have the map as the base morphism, so the displayed portion of the map will be the map between derivations. The identity morphism ignores the context, and derives by using the we already had, and is thus represented by the second projection
Composition of morphisms is somewhat more involved, but can be derived by playing type-tetris, as itβs all a matter of golfing the types and contexts into the correct place. The category laws are then a matter of bashing through a bunch of nested pairings and projections, and can be entirely automated.
Simple : Displayed B o β Simple .Displayed.Ob[_] Ξ = Ob Simple .Displayed.Hom[_] {Ξ} {Ξ} u X Y = Hom (Ξ ββ X) Y Simple .Displayed.Hom[_]-set _ _ _ = Hom-set (_ ββ _) _ Simple .Displayed.id' = Οβ Simple .Displayed._β'_ {f = u} {g = v} f g = f β β¨ v β Οβ , g β© Simple .Displayed.idr' f = f β β¨ (id β Οβ) , Οβ β© β‘β¨ products! B has-prods β©β‘ f β Simple .Displayed.idl' {f = u} f = Οβ β β¨ u β Οβ , f β© β‘β¨ products! B has-prods β©β‘ f β Simple .Displayed.assoc' {f = u} {g = v} {h = w} f g h = f β β¨ (v β w) β Οβ , g β β¨ w β Οβ , h β© β© β‘β¨ products! B has-prods β©β‘ (f β β¨ v β Οβ , g β©) β β¨ w β Οβ , h β© β
Cartesian morphismsπ
A morphism in the simple fibration is cartesian if and only if the morphism is invertible. This means that the cartesian morphisms are the isomorphisms of types, as we are interpreting morphisms in the simple fibration as derivations.
We begin with the reverse direction, as it is slightly simpler to show.
β¨β©-invertibleβcartesian : β {Ξ Ξ x y} {f : Hom Ξ Ξ} {f' : Hom (Ξ ββ x) y} β is-invertible β¨ Οβ , f' β© β is-cartesian Simple f f' β¨β©-invertibleβcartesian {Ξ} {Ξ} {x} {y} {f} {f'} β¨β©-inv = cart where module β¨β©-inv = is-invertible β¨β©-inv open is-cartesian
Let and be a pair of morphisms; we need to construct some that factorizes through
We begin by constructing the map which we can then pre-compose with the inverse to to obtain a map Finally, we can compose these two maps with the second projection, yielding the required map.
cart : is-cartesian Simple f f' cart .universal m h' = Οβ β β¨β©-inv.inv β β¨ m β Οβ , h' β©
Showing that this map uniquely factorises boils down to pushing around products and using that fact that the inverse to is, in fact, an inverse.
cart .commutes m h' = f' β β¨ m β Οβ , Οβ β β¨β©-inv.inv β β¨ m β Οβ , h' β© β© β‘Λβ¨ apβ _β_ refl (β¨β©-unique (pulll (Οβ-inv β¨β©-inv) β Οβββ¨β©) refl) β©β‘Λ f' β β¨β©-inv.inv β β¨ m β Οβ , h' β© β‘β¨ pulll (Οβ-inv β¨β©-inv) β©β‘ Οβ β β¨ m β Οβ , h' β© β‘β¨ Οβββ¨β© β©β‘ h' β cart .unique {m = m} {h' = h'} m' p = m' β‘Λβ¨ Οβββ¨β© β©β‘Λ Οβ β β¨ m β Οβ , m' β© β‘β¨ apβ _β_ refl (introl β¨β©-inv.invr) β©β‘ Οβ β (β¨β©-inv.inv β β¨ Οβ , f' β©) β β¨ m β Οβ , m' β© β‘β¨ products! B has-prods β©β‘ Οβ β β¨β©-inv.inv β β¨ m β Οβ , β f' β β¨ m β Οβ , m' β© β β© β‘β¨ ap! p β©β‘ Οβ β β¨β©-inv.inv β β¨ m β Οβ , h' β© β
On to the forward direction! Let and form a cartesian map in the simple fibration. We can construct an inverse to by factorizing the map as in the following diagram:
cartesianββ¨β©-invertible : β {Ξ Ξ x y} {f : Hom Ξ Ξ} {f' : Hom (Ξ ββ x) y} β is-cartesian Simple f f' β is-invertible β¨ Οβ , f' β© cartesianββ¨β©-invertible {Ξ} {Ξ} {x} {y} {f} {f'} cart = make-invertible β¨ Οβ , universal id Οβ β© left-inv right-inv where open is-cartesian cart
Showing that this map is a left inverse can be seen by a short computation.
left-inv : β¨ Οβ , f' β© β β¨ Οβ , universal id Οβ β© β‘ id left-inv = β¨ Οβ , f' β© β β¨ Οβ , universal id Οβ β© β‘β¨ products! B has-prods β©β‘ β¨ Οβ , β f' β β¨ id β Οβ , universal id Οβ β© β β© β‘β¨ ap! (commutes id Οβ) β©β‘ β¨ Οβ , Οβ β© β‘β¨ β¨β©-Ξ· β©β‘ id β
Showing that the constructed map is a right inverse is somewhat more involved. The key lemma is that is equal to To see this, consider the following diagram
Note that factorizes so it must be equal to the universal factorisation of as is cartesian. Furthermore, also factorizes which lets us see that
universal-Οβ-unique : f' β β¨ id β Οβ , universal id Οβ β β¨ Οβ , f' β© β© β‘ f' universal-Οβ-unique = f' β β¨ id β Οβ , universal id Οβ β β¨ Οβ , f' β© β© β‘β¨ products! B has-prods β©β‘ f' β β¨ id β Οβ , universal id Οβ β© β β¨ Οβ , f' β© β‘β¨ pulll (commutes id Οβ) β©β‘ Οβ β β¨ Οβ , f' β© β‘β¨ Οβββ¨β© β©β‘ f' β universal-Οββf' : universal id Οβ β β¨ Οβ , f' β© β‘ Οβ universal-Οββf' = universal id Οβ β β¨ Οβ , f' β© β‘β¨ unique _ universal-Οβ-unique β©β‘ universal id f' β‘Λβ¨ unique _ (elimr (apβ β¨_,_β© (idl _) refl β β¨β©-Ξ·)) β©β‘Λ Οβ β
We can then apply this lemma to see that forms a right inverse.
right-inv : β¨ Οβ , universal id Οβ β© β β¨ Οβ , f' β© β‘ id right-inv = β¨ Οβ , universal id Οβ β© β β¨ Οβ , f' β© β‘β¨ products! B has-prods β©β‘ β¨ Οβ , universal id Οβ β β¨ Οβ , f' β© β© β‘β¨ apβ β¨_,_β© refl universal-Οββf' β©β‘ β¨ Οβ , Οβ β© β‘β¨ β¨β©-Ξ· β©β‘ id β
Fibration structureπ
As suggested by itβs name, the simple fibration is a fibration. given a map in the base, and a upstairs, we can construct a lift by selecting as the corner of the lift, and then using the second projection as the lift itself. Intuitively, this encodes a substitution of contexts: because we are working with a simple type theory, the substitutions donβt need to touch the types, as there are no possible dependencies!
Simple-fibration : Cartesian-fibration Simple Simple-fibration .has-lift f Y .x' = Y Simple-fibration .has-lift f Y .lifting = Οβ Simple-fibration .has-lift f Y .cartesian .universal _ h = h Simple-fibration .has-lift f Y .cartesian .commutes g h = Οβββ¨β© Simple-fibration .has-lift f Y .cartesian .unique {m = g} {h' = h} h' p = h' β‘Λβ¨ Οβββ¨β© β©β‘Λ Οβ β β¨ g β Οβ , h' β© β‘β¨ p β©β‘ h β
Comprehension structureπ
The simple fibration admits a fibred functor into the codomain fibration that maps an object over to the projection
SimpleβSlices : Vertical-functor Simple (Slices B) SimpleβSlices = func where open Vertical-functor open /-Obj open Slice-hom func : Vertical-functor _ _ func .Fβ' {x} x' = cut {domain = x ββ x'} Οβ func .Fβ' {f = f} f' = slice-hom β¨ f β Οβ , f' β© (sym Οβββ¨β©) func .F-id' = Slice-path B $ β¨ id β Οβ , Οβ β© β‘β¨ apβ β¨_,_β© (idl _) refl β β¨β©-Ξ· β©β‘ id β func .F-β' {f = f} {g = g} {f' = f'} {g' = g'} = Slice-path B $ β¨ (f β g) β Οβ , f' β β¨ g β Οβ , g' β© β© β‘β¨ products! B has-prods β©β‘ β¨ f β Οβ , f' β© β β¨ g β Οβ , g' β© β
Furthermore, this functor is fibred. The general sketch is that cartesian morphisms in the codomain fibration are given by pullbacks, and cartesian maps in the simple fibration are given by inverses to and we can use this inverse to construct the universal map for the pullback.
SimpleβSlices-fibred : is-vertical-fibred SimpleβSlices SimpleβSlices-fibred {f = f} f' cart = pullbackβcartesian B pb where open is-pullback β¨β©-inv : is-invertible β¨ Οβ , f' β© β¨β©-inv = cartesianββ¨β©-invertible cart module β¨β©-inv = is-invertible β¨β©-inv pb : is-pullback B Οβ f β¨ f β Οβ , f' β© Οβ pb .square = sym Οβββ¨β© pb .universal {P'} {pβ'} {pβ'} p = β¨β©-inv.inv β β¨ pβ' , Οβ β pβ' β©
Showing that this map is universal involves a series of somewhat tedious calculations, so we omit them.
pb .pββuniversal {P} {pβ'} {pβ'} {p} = Οβ β β¨β©-inv.inv β β¨ pβ' , Οβ β pβ' β© β‘β¨ pulll (Οβ-inv β¨β©-inv) β©β‘ Οβ β β¨ pβ' , Οβ β pβ' β© β‘β¨ Οβββ¨β© β©β‘ pβ' β pb .pββuniversal {P} {pβ'} {pβ'} {p} = β¨ f β Οβ , f' β© β β¨β©-inv.inv β β¨ pβ' , Οβ β pβ' β© β‘β¨ pulll (β¨β©β _) β©β‘ β¨ (f β Οβ) β β¨β©-inv.inv , f' β β¨β©-inv.inv β© β β¨ pβ' , Οβ β pβ' β© β‘β¨ apβ _β_ (apβ β¨_,_β© (pullr (Οβ-inv β¨β©-inv)) (Οβ-inv β¨β©-inv)) refl β©β‘ β¨ f β Οβ , Οβ β© β β¨ pβ' , Οβ β pβ' β© β‘β¨ products! B has-prods β©β‘ β¨ f β pβ' , Οβ β pβ' β© β‘β¨ apβ β¨_,_β© p refl β©β‘ β¨ Οβ β pβ' , Οβ β pβ' β© β‘β¨ products! B has-prods β©β‘ pβ' β pb .unique {P} {pβ'} {pβ'} {p} {h'} q r = h' β‘β¨ insertl β¨β©-inv.invr β©β‘ β¨β©-inv.inv β β¨ Οβ , f' β© β h' β‘β¨ apβ _β_ refl (β¨β©β h') β©β‘ β¨β©-inv.inv β β¨ β Οβ β h' β , f' β h' β© β‘β¨ ap! q β©β‘ β¨β©-inv.inv β β¨ pβ' , β f' β h' β β© β‘β¨ ap! (pushl (sym Οβββ¨β©)) β©β‘ β¨β©-inv.inv β β¨ pβ' , Οβ β β β¨ f β Οβ , f' β© β h' β β© β‘β¨ ap! r β©β‘ β¨β©-inv.inv β β¨ pβ' , Οβ β pβ' β© β
This yields a comprehension structure on the simple fibration, which encodes the structure of a non-dependent type theory.
Simple-comprehension : Comprehension Simple Simple-comprehension .Vertical-fibred-functor.vert = SimpleβSlices Simple-comprehension .Vertical-fibred-functor.F-cartesian = SimpleβSlices-fibred