Anna Williams 14 February 2026

\begin{code}

{-# OPTIONS --safe --without-K #-}

open import MLTT.Spartan
open import UF.Base
open import UF.Equiv hiding (_โ‰…_)
open import UF.EquivalenceExamples
open import UF.Sets-Properties
open import UF.DependentEquality
open import Notation.UnderlyingType
open import Categories.Wild
open import Categories.Pre
open import Categories.Univalent
open import Categories.Notation.Univalent hiding (โŒœ_โŒ)
open import Categories.Displayed.Pre
open import Categories.Displayed.Univalent
open import Categories.Displayed.Notation.Pre
open import Categories.Displayed.Notation.Univalent

module Categories.Displayed.Total where

\end{code}

We can now define a total precategory. This is the category that pairs up the
objects of a 'base' precategory with the corresponding objects index by that
object in the displayed precategory. That is, the objects are of the form
ฮฃ x : obj P , obj[ x ]. We similarly define the homomorphisms and other fields.

\begin{code}

module _ {๐“ค ๐“ฅ ๐“ฆ ๐“ฃ : Universe} where

 TotalPrecategory : {P : Precategory ๐“ค ๐“ฅ}
                    (D : DisplayedPrecategory ๐“ฆ ๐“ฃ P)
                  โ†’ Precategory (๐“ค โŠ” ๐“ฆ) (๐“ฅ โŠ” ๐“ฃ)
 TotalPrecategory {P} D = (total-wild-category
                                           , total-is-precategory)
  where
   open PrecategoryNotation P
   open DisplayedPrecategoryNotation D

   total-wild-category : WildCategory (๐“ค โŠ” ๐“ฆ) (๐“ฅ โŠ” ๐“ฃ)
   total-wild-category = wildcategory
                        (ฮฃ p ๊ž‰ obj P , obj[ p ] D)
                        (ฮป (a , x) (b , y) โ†’ ฮฃ f ๊ž‰ hom a b , hom[ f ] x y)
                        (๐’Š๐’… , D-๐’Š๐’…)
                        (ฮป (g , ๐•˜) (f , ๐•—) โ†’ g โ—ฆ f , ๐•˜ โ—‹ ๐•—)
                        (ฮป (f , ๐•—) โ†’ to-ฮฃ-๏ผ (๐’Š๐’…-is-left-neutral f
                                             , transport-from-dependent-Id
                                                (D-๐’Š๐’…-is-left-neutral ๐•—)))
                        (ฮป (f , ๐•—) โ†’ to-ฮฃ-๏ผ (๐’Š๐’…-is-right-neutral f
                                             , transport-from-dependent-Id
                                                (D-๐’Š๐’…-is-right-neutral ๐•—)))
                        (ฮป f g h โ†’ to-ฮฃ-๏ผ (assoc _ _ _
                                        , transport-from-dependent-Id D-assoc))

   total-is-precategory : is-precategory total-wild-category
   total-is-precategory _ _ = ฮฃ-is-set (hom-is-set P) (ฮป _ โ†’ hom[-]-is-set)

\end{code}

We now show that if we have a category and a displayed category, the total
category formed of these is a category.

\begin{code}

 module _ {P : Precategory ๐“ค ๐“ฅ} (D : DisplayedPrecategory ๐“ฆ ๐“ฃ P) where
  open PrecategoryNotation P
  open PrecategoryNotation (TotalPrecategory D)
  open DisplayedPrecategoryNotation D
  
  total-iso-join :  {a b : obj P} {x : obj[ a ] D} {y : obj[ b ] D}
                 โ†’ (ฮฃ f ๊ž‰ a โ‰… b , x โ‰…[ f ] y) โ‰ƒ ((a , x) โ‰… (b , y))
  total-iso-join {a} {b} {x} {y} = qinveq F (Fโปยน , has-section , is-section)
   where
    F : (ฮฃ f ๊ž‰ a โ‰… b , x โ‰…[ f ] y) โ†’ ((a , x) โ‰… (b , y))
    F ((f , fโปยน , p , q)
     , (๐•— , ๐•—โปยน , ๐•ก , ๐•ข)) = (f , ๐•—)
                         , (fโปยน , ๐•—โปยน)
                         , to-ฮฃ-๏ผ (p , transport-from-dependent-Id ๐•ก)
                         , to-ฮฃ-๏ผ (q , transport-from-dependent-Id ๐•ข)

    Fโปยน : ((a , x) โ‰… (b , y)) โ†’ (ฮฃ f ๊ž‰ a โ‰… b , x โ‰…[ f ] y)
    Fโปยน ((f , ๐•—) , (fโปยน , ๐•—โปยน) , p , q) = (f , fโปยน , ap prโ‚ p , ap prโ‚ q)
                                       , (๐•— , ๐•—โปยน , snd-eq-left , snd-eq-right)
     where
      snd-eq-left : ๐•—โปยน โ—‹ ๐•— ๏ผโŸฆ (ฮป - โ†’ hom[ - ] _ _) , ap prโ‚ p โŸง D-๐’Š๐’…
      snd-eq-left = dependent-Id-from-transport (prโ‚‚ (from-ฮฃ-๏ผ p))

      snd-eq-right : ๐•— โ—‹ ๐•—โปยน ๏ผโŸฆ (ฮป - โ†’ hom[ - ] _ _) , ap prโ‚ q โŸง D-๐’Š๐’…
      snd-eq-right = dependent-Id-from-transport (prโ‚‚ (from-ฮฃ-๏ผ q))

    has-section : Fโปยน โˆ˜ F โˆผ id
    has-section e@(iso@(f , fโปยน , p , q)
     , d-iso@(๐•— , ๐•—โปยน , ๐•ก , ๐•ข)) = to-ฮฃ-๏ผ (f-eq , disp-eq)
     where
      f-eq = to-โ‰…-๏ผ refl

      lem : {a b : obj P}
            {x : obj[ a ] D}
            {y : obj[ b ] D}
            {f f' : a โ‰… b}
            (e : f ๏ผ f')
            (๐•— : x โ‰…[ f ] y)
          โ†’ prโ‚ (transport (ฮป - โ†’ x โ‰…[ - ] y) e ๐•—)
          ๏ผ transport _ (ap prโ‚ e) (prโ‚ ๐•—)
      lem refl _ = refl

      ๐•—' = (prโ‚‚ ((Fโปยน โˆ˜ F) e))

      eq : prโ‚ (transport (ฮป - โ†’ x โ‰…[ - ] y) f-eq ๐•—') ๏ผ ๐•—
      eq = prโ‚ (transport (ฮป - โ†’ x โ‰…[ - ] y) f-eq ๐•—')            ๏ผโŸจ I โŸฉ
           transport (ฮป - โ†’ hom[ - ] x y) (ap prโ‚ f-eq) (prโ‚ ๐•—') ๏ผโŸจ II โŸฉ
           ๐•— โˆŽ
       where
        I = lem f-eq _
        II = apโ‚‚ (transport (ฮป - โ†’ hom[ - ] x y))
                 (hom-is-set P (ap prโ‚ f-eq) refl)
                 refl

      disp-eq : transport (ฮป - โ†’ x โ‰…[ - ] y) f-eq (prโ‚‚ ((Fโปยน โˆ˜ F) e)) ๏ผ d-iso
      disp-eq = to-โ‰…[-]-๏ผ eq

    is-section : F โˆ˜ Fโปยน โˆผ id
    is-section ((f , ๐•—) , (fโปยน , ๐•—โปยน) , p , q) = to-โ‰…-๏ผ refl


 TotalCategory : {C : Category ๐“ค ๐“ฅ}
                 (D : DisplayedCategory ๐“ฆ ๐“ฃ โŸจ C โŸฉ)
               โ†’ Category (๐“ค โŠ” ๐“ฆ) (๐“ฅ โŠ” ๐“ฃ)
 TotalCategory {C} D = (TotalPrecategory โŸจ D โŸฉ) , is-cat
  where
   open CategoryNotation C
   open DisplayedCategoryNotation D
   open PrecategoryNotation (TotalPrecategory โŸจ D โŸฉ)

   is-cat : is-category (TotalPrecategory โŸจ D โŸฉ)
   is-cat (a , x) (b , y) = equiv-closed-under-โˆผ โŒœ univalence โŒ
                                                 (id-to-iso (a , x) (b , y))
                                                 โŒœ univalence โŒ-is-equiv
                                                 pointwise-equality
    where
     univalence : ((a , x) ๏ผ (b , y)) โ‰ƒ ((a , x) โ‰… (b , y))
     univalence = ((a , x) ๏ผ (b , y))                      โ‰ƒโŸจ i โŸฉ
                  ((ฮฃ e ๊ž‰ a ๏ผ b , transport _ e x ๏ผ y))   โ‰ƒโŸจ ii โŸฉ
                  (ฮฃ e ๊ž‰ a ๏ผ b , x โ‰…[ id-to-iso a b e ] y) โ‰ƒโŸจ iii โŸฉ
                  (ฮฃ f ๊ž‰ a โ‰… b , x โ‰…[ f ] y)                โ‰ƒโŸจ iv โŸฉ
                  total-isomorphism                         โ– 
      where
       total-isomorphism : ๐“ฅ โŠ” ๐“ฃ ฬ‡
       total-isomorphism = ((a , x) โ‰… (b , y))

       transport-equiv-iso : (e : a ๏ผ b)
                           โ†’ (transport (ฮป - โ†’ obj[ - ] D) e x ๏ผ y)
                           โ‰ƒ x โ‰…[ id-to-iso a b e ] y
       transport-equiv-iso refl = (D-id-to-iso โŸจ D โŸฉ refl x y)
                                , D-id-to-iso-is-equiv D refl x y

       i = ฮฃ-๏ผ-โ‰ƒ
       ii = ฮฃ-cong transport-equiv-iso
       iii = ฮฃ-change-of-variable (ฮป - โ†’ (x โ‰…[ - ] y))
                                  (id-to-iso a b)
                                  (id-to-iso-is-equiv C a b)
       iv = total-iso-join โŸจ D โŸฉ

     pointwise-equality : id-to-iso (a , x) (b , y)
                         โˆผ โŒœ univalence โŒ
     pointwise-equality refl = refl

\end{code}