Martin Escardo, 20 Jun 2025.

Copied from a 16th August 2023 file in this repository on injectivity
of mathematical structures, because it deserves a better and more
general home.

We formulate and prove what we call here the "Fundamental Lemma of
transport along equivalences".

\begin{code}

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

module UF.FundamentalLemmaOfTransportAlongEquivalences where

open import MLTT.Spartan
open import UF.Equiv
open import UF.Univalence

\end{code}

In the presence of univalence, we can transport along equivalences in
the following sense.

\begin{code}

transport-along-โ‰ƒ : is-univalent ๐“ค
                  โ†’ (S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ )
                    {X Y : ๐“ค ฬ‡ }
                  โ†’ X โ‰ƒ Y โ†’ S X โ†’ S Y
transport-along-โ‰ƒ ua S {X} {Y} ๐•— = transport S (eqtoid ua X Y ๐•—)

\end{code}

That is, this construction converts the equivalence to an
identification, using univalence, and then uses standard transport.

Because the function transport-along-โ‰ƒ uses univalence as a
hypothesis, it is difficult to reason with, and also to compute with.

However, if we can guess *any* functions

   T      : {X Y : ๐“ค ฬ‡ } โ†’ X โ‰ƒ Y โ†’ S X โ†’ S Y,
   T-refl : {X : ๐“ค ฬ‡ } โ†’ T (โ‰ƒ-refl X) โˆผ id,

which we are very often able to do in practice, then it becomes
trivial to reason with, and also to compute with, thanks to the
following fundamental lemma of transport along equivalences.

This says that, for any equivalence

  ๐•— : X โ‰ƒ Y,

we have that

  T ๐•— โˆผ transport-along-โ‰ƒ ua S ๐•—,

so that we can work with T rather than with the more awkward
map transport-along-โ‰ƒ.

What is perhaps surprising is that no conditions on T and T-refl are
needed. Any T and T-refl with the given types work, without the need
of any further condition.

The proof is by equivalence induction (called JEq), with T-refl giving
the induction step.

\begin{code}

transport-along-โ‰ƒ-fundamental-lemma
 : {๐“ค ๐“ฅ : Universe}
   (S : ๐“ค ฬ‡ โ†’ ๐“ฅ ฬ‡ )
   (T : {X Y : ๐“ค ฬ‡ } โ†’ X โ‰ƒ Y โ†’ S X โ†’ S Y)
   (T-refl : {X : ๐“ค ฬ‡ } โ†’ T (โ‰ƒ-refl X) โˆผ id)
   {X Y : ๐“ค ฬ‡ }
   (๐•— : X โ‰ƒ Y)
   (ua : is-univalent ๐“ค)
 โ†’ T ๐•— โˆผ transport-along-โ‰ƒ ua S ๐•—
transport-along-โ‰ƒ-fundamental-lemma {๐“ค} {๐“ฅ} S T T-refl {X} {Y} ๐•— ua s
 = JEq ua X A I Y ๐•—
 where
  A : (Y : ๐“ค ฬ‡ ) (๐•— : X โ‰ƒ Y) โ†’ ๐“ฅ ฬ‡
  A Y ๐•— = T ๐•— s ๏ผ transport-along-โ‰ƒ ua S ๐•— s

  I : A X (โ‰ƒ-refl X)
  I = T (โ‰ƒ-refl X) s                            ๏ผโŸจ T-refl s โŸฉ
      s                                         ๏ผโŸจ refl โŸฉ
      transport S refl s                        ๏ผโŸจ II โŸฉ
      transport S (eqtoid ua X X (โ‰ƒ-refl X)) s  ๏ผโŸจ refl โŸฉ
      transport-along-โ‰ƒ ua S (โ‰ƒ-refl X) s       โˆŽ
    where
     II = (ap (ฮป - โ†’ transport S - s) (eqtoid-refl ua X))โปยน

\end{code}

I am not sure this lemma has been formulated and proved before, but I
won't be surprised if it has. It does follow from what Egbert Rijke
calls "The Fundamental Theorem of identity types", although here we
are giving a direct proof by equivalence induction.

In any case, we have found it to be really useful in practice.