open import Cat.Displayed.Cartesian
open import Cat.Displayed.Functor
open import Cat.Displayed.Total
open import Cat.Displayed.Base
open import Cat.Prelude

import Cat.Displayed.Reasoning as DR

module Cat.Displayed.Composition where


# Composition of displayed categoriesπ

A displayed category over is equivalent to the data of a functor into the forward direction of this equivalence is witnessed by the total category of along with the canonical projection functor from the total category into This suggests that we ought to be able to compose displayed categories. That is, if is displayed over and is displayed over then we can construct a new category displayed over that contains the data of both and

To actually construct the composite, we bundle up the data of and into pairs, so an object in over consists of a pair objects of over and over and Morphisms are defined similarly, as do equations.

_Dβ_ : β {o β o' β' o'' β''}
β {β¬ : Precategory o β}
β (β° : Displayed β¬ o' β') β (β± : Displayed (β« β°) o'' β'')
β Displayed β¬ (o' β o'') (β' β β'')
_Dβ_ {β¬ = β¬} β° β± = disp where
module β° = Displayed β°
module β± = Displayed β±

disp : Displayed β¬ _ _
Displayed.Ob[ disp ] X =
Ξ£[ X' β β°.Ob[ X ] ] β±.Ob[ X , X' ]
Displayed.Hom[ disp ] f X Y =
Ξ£[ f' β β°.Hom[ f ] (X .fst) (Y .fst) ] β±.Hom[ total-hom f f' ] (X .snd) (Y .snd)
Displayed.Hom[ disp ]-set f x y =
Ξ£-is-hlevel 2 (β°.Hom[ f ]-set (x .fst) (y .fst)) Ξ» f' β
β±.Hom[ total-hom f f' ]-set (x .snd) (y .snd)
disp .Displayed.id' =
β°.id' , β±.id'
disp .Displayed._β'_ f' g' =
(f' .fst β°.β' g' .fst) , (f' .snd β±.β' g' .snd)
disp .Displayed.idr' f' =
β°.idr' (f' .fst) ,β β±.idr' (f' .snd)
disp .Displayed.idl' f' =
β°.idl' (f' .fst) ,β β±.idl' (f' .snd)
disp .Displayed.assoc' f' g' h' =
(β°.assoc' (f' .fst) (g' .fst) (h' .fst)) ,β (β±.assoc' (f' .snd) (g' .snd) (h' .snd))


We also obtain a displayed functor from to that projects out the data of from the composite.

Οα΅ : β {o β o' β' o'' β''}
β {β¬ : Precategory o β}
β {β° : Displayed β¬ o' β'} {β± : Displayed (β« β°) o'' β''}
β Displayed-functor (β° Dβ β±) β° Id
Οα΅ .Displayed-functor.Fβ' = fst
Οα΅ .Displayed-functor.Fβ' = fst
Οα΅ .Displayed-functor.F-id' = refl
Οα΅ .Displayed-functor.F-β' = refl


## Composition of fibrationsπ

As one may expect, the composition of fibrations is itself a fibration.

module _
{o β o' β' o'' β''}
{β¬ : Precategory o β}
{β° : Displayed β¬ o' β'} {β± : Displayed (β« β°) o'' β''}
where

private
open Precategory β¬
module β° = Displayed β°
module β± = Displayed β±
module β±R = DR β±


The idea of the proof is that we can take lifts of lifts, and in fact, this is exactly how we construct the liftings.

  fibration-β : Cartesian-fibration β° β Cartesian-fibration β±
β Cartesian-fibration (β° Dβ β±)
fibration-β β°-fib β±-fib = β°ββ±-fib where
open Cartesian-fibration
open Cartesian-lift

β°ββ±-fib : Cartesian-fibration (β° Dβ β±)
β°ββ±-fib .has-lift f (y' , y'') = cart-lift where

β°-lift = β°-fib .has-lift f y'
β±-lift = β±-fib .has-lift (total-hom f (β°-lift .lifting)) y''

cart-lift : Cartesian-lift (β° Dβ β±) f (y' , y'')
cart-lift .x' = β°-lift .x' , β±-lift .x'
cart-lift .lifting = β°-lift .lifting , β±-lift .lifting


However, showing that the constructed lift is cartesian is somewhat more subtle. The issue is that when we go to construct the universal map, we are handed an displayed over and also an displayed over which is not a composite definitionally. However, it is propositionally a composite, as is witnessed by β°-lift .commutes, so we can use the generalized propositional functions of β±-lift to construct the universal map, and show that it is indeed universal.

      cart-lift .cartesian .is-cartesian.universal m (h' , h'') =
β°-lift .universal m h' ,
universal' β±-lift (total-hom-path β° refl (β°-lift .commutes m h')) h''
cart-lift .cartesian .is-cartesian.commutes m h' =
β°-lift .commutes m (h' .fst) ,β
commutesp β±-lift _ (h' .snd)
cart-lift .cartesian .is-cartesian.unique m' p =
β°-lift .unique (m' .fst) (ap fst p) ,β
uniquep β±-lift _ _
(total-hom-path β° refl (β°-lift .commutes _ _))
(m' .snd)
(ap snd p)