Martin Escardo, 23rd May 2025.

Homotopy pullbacks and some basic properties to begin with.

This is loosely based on

[1] Jeremy Avigad, Chris Kapulkin, Peter LeFanu Lumsdaine.
    Homotopy limits in type theory, 2015 (first version 2013).
    https://arxiv.org/abs/1304.0680

\begin{code}

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

module UF.Pullback where

open import MLTT.Spartan
open import UF.Embeddings
open import UF.Equiv
open import UF.Subsingletons

\end{code}

We assume a cospan

                 Y
                 |
                 | g
                 |
                 v
      X -------> C
           f

\begin{code}

module pullback
        {๐“ค ๐“ฅ ๐“ฆ : Universe}
        {X : ๐“ค ฬ‡ } {Y : ๐“ฅ ฬ‡ } {Z : ๐“ฆ ฬ‡ }
        (f : X โ†’ Z) (g : Y โ†’ Z)
       where

\end{code}

And we consider commutative squares of the form

           q
      A -------> X
      |          |
    p |          | g
      |          |
      v          v
      Y -------> Z
            f

completing the cospan.

\begin{code}

 commutative-square : {A : ๐“ฃ ฬ‡ } โ†’ (A โ†’ X) ร— (A โ†’ Y) โ†’ ๐“ฆ โŠ” ๐“ฃ ฬ‡
 commutative-square (p , q) = f โˆ˜ p โˆผ g โˆ˜ q

\end{code}

A cone over the cospan is the totality of these data.

\begin{code}

 cone : ๐“ฃ ฬ‡ โ†’ ๐“ค โŠ” ๐“ฅ โŠ” ๐“ฆ โŠ” ๐“ฃ ฬ‡
 cone A = ฮฃ pq ๊ž‰ ((A โ†’ X) ร— (A โ†’ Y)) , commutative-square pq

\end{code}

It is convenient to collect all cones in a universe into a single
type.

\begin{code}

 Cone : (๐“ฃ : Universe) โ†’ ๐“ค โŠ” ๐“ฅ โŠ” ๐“ฆ โŠ” (๐“ฃ โบ) ฬ‡
 Cone ๐“ฃ = ฮฃ A ๊ž‰ ๐“ฃ ฬ‡ , cone A

 source : Cone ๐“ฃ โ†’ ๐“ฃ ฬ‡
 source (P , c) = P

 cone-of : (๐“’ : Cone ๐“ฃ) โ†’ cone (source ๐“’)
 cone-of (P , c) = c

\end{code}

If we have a cone

            q
      P -------> Y
      |          |
    p |          | g
      |          |
      v          v
      X -------> Z
            f

and a map u : A โ†’ P, we get a cone

          q โˆ˜ u
      A -------> Y
      |          |
p โˆ˜ u |          | g
      |          |
      v          v
      X -------> Z
            f

\begin{code}

 cone-map : {P : ๐“ฃ' ฬ‡ } (A : ๐“ฃ ฬ‡ ) โ†’ cone P โ†’ (A โ†’ P) โ†’ cone A
 cone-map X ((p , q) , e) u = (p โˆ˜ u , q โˆ˜ u) , e โˆ˜ u

\end{code}

We say that a cone

            q
      P -------> Y
      |          |
    p |          | g
      |          |
      v          v
      X -------> Z
            f

is a (homotopy) pullback if the cone map is an equivalence for every A.

\begin{code}

 is-pullback : Cone ๐“ฃ โ†’ ๐“คฯ‰
 is-pullback (P , c) = {๐“ฃ' : Universe} (A : ๐“ฃ' ฬ‡ ) โ†’ is-equiv (cone-map A c)

\end{code}

We record the equivalence explicitly.

\begin{code}

 module _ (๐“’@(P , c@((pโ‚ , pโ‚‚) , s)) : Cone ๐“ฃ)
          (i : is-pullback ๐“’)
        where

  pullback-equivalence : (A : ๐“ฃ' ฬ‡ ) โ†’ (A โ†’ P) โ‰ƒ cone A
  pullback-equivalence A = cone-map A c , i A

\end{code}

And we can formulate the universal property of pullbacks in terms of
(homotopy) unique existence.

\begin{code}

  module _ (๐““@(A , d@((hโ‚ , hโ‚‚) , t)) : Cone ๐“ฃ') where

   universal-property
    : โˆƒ! u ๊ž‰ (A โ†’ P) , ((pโ‚ โˆ˜ u , pโ‚‚ โˆ˜ u) , s โˆ˜ u) ๏ผ ((hโ‚ , hโ‚‚) , t)
   universal-property
    = equivs-are-vv-equivs (cone-map A c) (i A) d

\end{code}

It is convenient to name the uniquely existing u as the "mediating
map", and record the equations it satisfies.

\begin{code}

   mediating-map : (A โ†’ P)
   mediating-map = prโ‚ (center universal-property)

   _ : mediating-map ๏ผ โŒœ pullback-equivalence A โŒโปยน d
   _ = refl

   mediating-map-eqโ‚ : pโ‚ โˆ˜ mediating-map ๏ผ hโ‚
   mediating-map-eqโ‚ = ap (prโ‚ โˆ˜ prโ‚) (prโ‚‚ (center universal-property))

   mediating-map-eqโ‚‚ : pโ‚‚ โˆ˜ mediating-map ๏ผ hโ‚‚
   mediating-map-eqโ‚‚ = ap (prโ‚‚ โˆ˜ prโ‚) (prโ‚‚ (center universal-property))

\end{code}

We now show that pullbacks exist, and call them simply pullbacks,
although perhaps we should call them standard pullbacks, or chosen
pullbacks.

The construction is illustrated in the following diagram.

                                   pbโ‚‚
 ฮฃ (x , y) ๊ž‰ X ร— Y , f x ๏ผ g y  -------> Y
           |                              |
      pbโ‚  |                              | g
           |                              |
           v                              v
           X ---------------------------> Z
                                   f
\begin{code}

 pullback : ๐“ค โŠ” ๐“ฅ โŠ” ๐“ฆ ฬ‡
 pullback = ฮฃ (x , y) ๊ž‰ X ร— Y , f x ๏ผ g y

 private
  P = pullback

 pbโ‚ : P โ†’ X
 pbโ‚ ((x , y) , s) = x

 pbโ‚‚ : P โ†’ Y
 pbโ‚‚ ((x , y) , s) = y

 pullback-square : commutative-square (pbโ‚ , pbโ‚‚)
 pullback-square ((x , y) , s) = s

 pullback-cone : cone P
 pullback-cone = ((pbโ‚ , pbโ‚‚) , pullback-square)

 Pullback-Cone : Cone (๐“ค โŠ” ๐“ฅ โŠ” ๐“ฆ)
 Pullback-Cone = P , pullback-cone

 pullback-cone-map : (A : ๐“ฃ' ฬ‡ ) โ†’ (A โ†’ P) โ†’ cone A
 pullback-cone-map A = cone-map A pullback-cone

 pullback-mediating-map : {A : ๐“ฃ ฬ‡ } โ†’ cone A โ†’ (A โ†’ P)
 pullback-mediating-map ((p , q) , s) a = (p a , q a) , s a

 pullback-Cone-is-pullback : is-pullback Pullback-Cone
 pullback-Cone-is-pullback A =
  qinvs-are-equivs
   (pullback-cone-map A)
   (pullback-mediating-map , (ฮป u โ†’ refl) , (ฮป c โ†’ refl))

 _ : (A : ๐“ฃ' ฬ‡ ) (c : cone A)
   โ†’ pullback-mediating-map c
   ๏ผ mediating-map Pullback-Cone pullback-Cone-is-pullback (A , c)
 _ = ฮป A c โ†’ refl

\end{code}

Pullbacks of embeddings are embeddings.

\begin{code}

 pbโ‚‚-is-embedding : is-embedding f โ†’ is-embedding pbโ‚‚
 pbโ‚‚-is-embedding f-is-embedding y = I
   where
    I : is-prop (fiber pbโ‚‚ y)
    I (((xโ‚ , y) , eโ‚) , refl) (((xโ‚‚ , y) , eโ‚‚) , refl) = III II
     where
      II : (xโ‚ , eโ‚) ๏ผ (xโ‚‚ , eโ‚‚)
      II = f-is-embedding (g y) (xโ‚ , eโ‚) (xโ‚‚ , eโ‚‚)

      III : {(xโ‚ , eโ‚) (xโ‚‚ , eโ‚‚) : fiber f (g y)}
          โ†’ (xโ‚ , eโ‚) ๏ผ (xโ‚‚ , eโ‚‚)
          โ†’ (((xโ‚ , y) , eโ‚) , refl) ๏ผ[ fiber pbโ‚‚ y ] (((xโ‚‚ , y) , eโ‚‚) , refl)
      III refl = refl

\end{code}

We have a pullback

           fiber f c ----> ๐Ÿ™
              |            |
  fiber-point |            | c
              |            |
              v            v
              X ---------> Z
                     f

\begin{code}

module _ {๐“ค ๐“ฅ ๐“ฆ : Universe}
         {X : ๐“ค ฬ‡ }
         {Z : ๐“ฆ ฬ‡ }
         (f : X โ†’ Z)
         (z : Z)
       where

 open pullback f (ฮป (_ : ๐Ÿ™ {๐“ฅ}) โ†’ z)

 fiber-is-pullback
  : is-pullback (fiber f z , (fiber-point , unique-to-๐Ÿ™) , fiber-identification)
 fiber-is-pullback A
  = qinvs-are-equivs ฯ• (ฮณ , (ฮป u โ†’ refl) , (ฮป c โ†’ refl))
  where
   ฯ• : (A โ†’ fiber f z) โ†’ cone A
   ฯ• = cone-map A ((fiber-point , unique-to-๐Ÿ™) , fiber-identification)

   ฮณ : cone A โ†’ (A โ†’ fiber f z)
   ฮณ ((p , q) , s) a = p a , s a

\end{code}

TODO. Implement other results from [1].