open import Cat.Displayed.Cartesian.Discrete
open import Cat.Instances.Shape.Terminal
open import Cat.Displayed.Bifibration
open import Cat.Displayed.Cocartesian
open import Cat.Displayed.Cartesian
open import Cat.Functor.Equivalence
open import Cat.Displayed.Fibre
open import Cat.Displayed.Total
open import Cat.Displayed.Base
open import Cat.Prelude

module Cat.Displayed.Instances.Identity
{o β} (B : Precategory o β)
where

open Precategory B
open Displayed
open Functor
open Total-hom


## The Identity Bifibrationπ

Let $\mathcal{B}$ be a precategory. We can define a displayed category $\mathrm{Id}(\mathcal{B})$ over $B$ whose total category is isomorphic to $B$, called the identity bifibration.

IdD : Displayed B lzero lzero
IdD .Ob[_] _ = β€
IdD .Hom[_] _ _ _ = β€
IdD .Hom[_]-set _ _ _ = hlevel!
IdD .idβ² = tt
IdD ._ββ²_ _ _ = tt
IdD .idrβ² _ = refl
IdD .idlβ² _ = refl
IdD .assocβ² _ _ _ = refl


This fibration is obviously a discrete fibration; in fact, itβs about as discrete as you can get!

IdD-discrete-fibration : Discrete-fibration IdD
IdD-discrete-fibration .Discrete-fibration.fibre-set = hlevel!
IdD-discrete-fibration .Discrete-fibration.lifts _ _ = hlevel!


Every morphism in the identity fibration is trivially cartesian and cocartesian.

idd-is-cartesian
: β {x y} {f : Hom x y}
β is-cartesian IdD f tt
idd-is-cartesian .is-cartesian.universal _ _ = tt
idd-is-cartesian .is-cartesian.commutes _ _ = refl
idd-is-cartesian .is-cartesian.unique _ _ = refl

idd-is-cocartesian
: β {x y} {f : Hom x y}
β is-cocartesian IdD f (tt)
idd-is-cocartesian .is-cocartesian.universal _ _ = tt
idd-is-cocartesian .is-cocartesian.commutes _ _ = refl
idd-is-cocartesian .is-cocartesian.unique _ _ = refl


This implies that itβs trivially a bifibration. We omit the proofs, because they are totally uninteresting.

IdD-fibration : Cartesian-fibration IdD
IdD-opfibration : Cocartesian-fibration IdD
IdD-bifibration : is-bifibration IdD

IdD-fibration .Cartesian-fibration.has-lift f yβ² .Cartesian-lift.xβ² = tt
IdD-fibration .Cartesian-fibration.has-lift f yβ² .Cartesian-lift.lifting = tt
IdD-fibration .Cartesian-fibration.has-lift f yβ² .Cartesian-lift.cartesian =
idd-is-cartesian

IdD-opfibration .Cocartesian-fibration.has-lift f xβ² .Cocartesian-lift.yβ² = tt
IdD-opfibration .Cocartesian-fibration.has-lift f xβ² .Cocartesian-lift.lifting = tt
IdD-opfibration .Cocartesian-fibration.has-lift f xβ² .Cocartesian-lift.cocartesian =
idd-is-cocartesian

IdD-bifibration .is-bifibration.fibration = IdD-fibration
IdD-bifibration .is-bifibration.opfibration = IdD-opfibration


## Fibre Categoriesπ

The fibre categories of the identity bifibration are isomorphic to the terminal category.

IdDFib : β x β Functor β€Cat (Fibre IdD x)
IdDFib x .Fβ _ = tt
IdDFib x .Fβ _ = tt
IdDFib x .F-id = refl
IdDFib x .F-β _ _ = refl

IdD-is-iso : β x β is-precat-iso (IdDFib x)
IdD-is-iso x .is-precat-iso.has-is-ff = id-equiv
IdD-is-iso x .is-precat-iso.has-is-iso = id-equiv


## Total Categoryπ

The total category of the identity bifibration is isomorphic to $\mathcal{B}$ itself.

IdDTotal : Functor B (β« IdD)
IdDTotal .Fβ x = x , tt
IdDTotal .Fβ f = total-hom f (tt)
IdDTotal .F-id = total-hom-path _ refl refl
IdDTotal .F-β _ _ = total-hom-path _ refl refl

IdDTotal-is-iso : is-precat-iso IdDTotal
IdDTotal-is-iso .is-precat-iso.has-is-ff =
is-isoβis-equiv (iso hom (Ξ» _ β total-hom-path _ refl refl) (Ξ» _ β refl))
IdDTotal-is-iso .is-precat-iso.has-is-iso =
is-isoβis-equiv (iso fst (Ξ» _ β refl) (Ξ» _ β refl))