2.4 Homotopies and Equivalences
So far, we have seen how the identity type $x{=}_{A}y$ can be regarded as a type of identifications, paths, or equivalences between two elements $x$ and $y$ of a type $A$. Now we investigate the appropriate notions of “identification” or “sameness” between functions and between types. In §2.9 (http://planetmath.org/29pitypesandthefunctionextensionalityaxiom),§2.10 (http://planetmath.org/210universesandtheunivalenceaxiom), we will see that homotopy type theory allows us to identify these with instances of the identity type, but before we can do that we need to understand them in their own right.
Traditionally, we regard two functions as the same if they take equal values on all inputs. Under the propositionsastypes interpretation^{}, this suggests that two functions $f$ and $g$ (perhaps dependently typed) should be the same if the type ${\prod}_{(x:A)}(f(x)=g(x))$ is inhabited. Under the homotopical interpretation, this dependent function type consists of continuous^{} paths or functorial equivalences, and thus may be regarded as the type of homotopies^{} or of natural isomorphisms.We will adopt the topological terminology for this.
Definition 2.4.1.
Let $f\mathrm{,}g\mathrm{:}{\mathrm{\prod}}_{\mathrm{(}x\mathrm{:}A\mathrm{)}}P\mathit{}\mathrm{(}x\mathrm{)}$ be two sections^{} of a type family $P\mathrm{:}A\mathrm{\to}\mathrm{U}$. A homotopy from $f$ to $g$ is a dependent function of type
$$(f\sim g):\equiv \prod _{x:A}(f(x)=g(x)).$$ 
Note that a homotopy is not the same as an identification $(f=g)$. However, in §2.9 (http://planetmath.org/29pitypesandthefunctionextensionalityaxiom) we will introduce an axiom making homotopies and identifications “equivalent^{}”.
The following proofs are left to the reader.
Lemma 2.4.2.
Homotopy is an equivalence relation on each function type $A\mathrm{\to}B$. That is, we have elements of the types
$$\prod _{f:A\to B}(f\sim f)$$  
$$\prod _{f,g:A\to B}(f\sim g)\to (g\sim f)$$  
$$\prod _{f,g,h:A\to B}(f\sim g)\to (g\sim h)\to (f\sim h).$$ 
Just as functions in type theory^{} are automatically “functors^{}”, homotopies are automatically “natural transformations”, in the following sense. Recall that for $f:A\to B$ and $p:x{=}_{A}y$, we may write $f\left(p\right)$ to mean ${\mathrm{\U0001d5ba\U0001d5c9}}_{f}(p)$.
Lemma 2.4.3.
Suppose $H\mathrm{:}f\mathrm{\sim}g$ is a homotopy between functions $f\mathrm{,}g\mathrm{:}A\mathrm{\to}B$ and let $p\mathrm{:}x{\mathrm{=}}_{A}y$. Then we have
$$H(x)\text{centerdot}g\left(p\right)=f\left(p\right)\text{centerdot}H(y).$$ 
We may also draw this as a commutative diagram^{}:
Proof.
By induction^{}, we may assume $p$ is ${\mathrm{\U0001d5cb\U0001d5be\U0001d5bf\U0001d5c5}}_{x}$. Since ${\mathrm{\U0001d5ba\U0001d5c9}}_{f}$ and ${\mathrm{\U0001d5ba\U0001d5c9}}_{g}$ compute on reflexivity^{}, in this case what we must show is
$$H(x)\text{centerdot}{\mathrm{\U0001d5cb\U0001d5be\U0001d5bf\U0001d5c5}}_{g(x)}={\mathrm{\U0001d5cb\U0001d5be\U0001d5bf\U0001d5c5}}_{f(x)}\text{centerdot}H(x).$$ 
But this follows since both sides are equal to $H(x)$. ∎
Corollary 2.4.4.
Let $H\mathrm{:}f\mathrm{\sim}{\mathrm{id}}_{A}$ be a homotopy, with $f\mathrm{:}A\mathrm{\to}A$. Then for any $x\mathrm{:}A$ we have
$$H(f(x))=f\left(H(x)\right).$$ 
Here $f(x)$ denotes the ordinary application of $f$ to $x$, while $f\left(H(x)\right)$ denotes ${\mathrm{\U0001d5ba\U0001d5c9}}_{f}(H(x))$.
Proof.
By naturality of $H$, the following diagram of paths commutes:
That is, $f\left(Hx\right)\text{centerdot}Hx=H(fx)\text{centerdot}Hx$. We can now whisker by ${(Hx)}^{1}$ to cancel $Hx$, obtaining
$$f\left(Hx\right)=f\left(Hx\right)\text{centerdot}Hx\text{centerdot}{(Hx)}^{1}=H(fx)\text{centerdot}Hx\text{centerdot}{(Hx)}^{1}=H(fx)$$ 
as desired (with some associativity paths suppressed). ∎
Of course, like the functoriality of functions (Lemma 2.2.2 (http://planetmath.org/22functionsarefunctors#Thmprelem2)), the equality in Lemma 2.4.3 (http://planetmath.org/24homotopiesandequivalences#Thmprelem2) is a path which satisfies its own coherence laws, and so on.
Moving on to types, from a traditional perspective one may say that a function $f:A\to B$ is an isomorphism^{} if there is a function $g:B\to A$ such that both composites $f\circ g$ and $g\circ f$ are pointwise equal to the identity^{}, i.e. such that $f\circ g\sim {\mathrm{\U0001d5c2\U0001d5bd}}_{B}$ and $g\circ f\sim {\mathrm{\U0001d5c2\U0001d5bd}}_{A}$. A homotopical perspective suggests that this should be called a homotopy equivalence^{}, and from a categorical one, it should be called an equivalence of (higher) groupoids^{}. However, when doing proofrelevant mathematics, the corresponding type
$$\sum _{g:B\to A}((f\circ g\sim {\mathrm{\U0001d5c2\U0001d5bd}}_{B})\times (g\circ f\sim {\mathrm{\U0001d5c2\U0001d5bd}}_{A}))$$  (2.4.5) 
is poorly behaved. For instance, for a single function $f:A\to B$ there may be multiple unequal inhabitants of (2.4.5). (This is closely related to the observation in higher category theory that often one needs to consider adjoint^{} equivalences rather than plain equivalences.) For this reason, we give (2.4.5) the following historically accurate, but slightly derogatorysounding name instead.
Definition 2.4.6.
For a function $f\mathrm{:}A\mathrm{\to}B$, a quasiinverse^{} of $f$ is a triple $\mathrm{(}g\mathrm{,}\alpha \mathrm{,}\beta \mathrm{)}$ consisting of a function $g\mathrm{:}B\mathrm{\to}A$ and homotopies $\alpha \mathrm{:}f\mathrm{\circ}g\mathrm{\sim}{\mathrm{id}}_{B}$ and $\beta \mathrm{:}g\mathrm{\circ}f\mathrm{\sim}{\mathrm{id}}_{A}$.
Thus, (2.4.5) is the type of quasiinverses of $f$; we may denote it by $\mathrm{\U0001d5ca\U0001d5c2\U0001d5c7\U0001d5cf}(f)$.
Example 2.4.7.
The identity function ${\mathrm{id}}_{A}\mathrm{:}A\mathrm{\to}A$ has a quasiinverse given by ${\mathrm{id}}_{A}$ itself, together with homotopies defined by $\alpha \mathrm{(}y\mathrm{)}\mathrm{:}\mathrm{\equiv}{\mathrm{refl}}_{y}$ and $\beta \mathrm{(}x\mathrm{)}\mathrm{:}\mathrm{\equiv}{\mathrm{refl}}_{x}$.
Example 2.4.8.
For any $p\mathrm{:}x{\mathrm{=}}_{A}y$ and $z\mathrm{:}A$, the functions
$(p\text{centerdot}\mathit{\text{\u2013}})$  $:(y{=}_{A}z)\to (x{=}_{A}z)\mathit{\hspace{1em}\hspace{1em}}\text{\mathit{a}\mathit{n}\mathit{d}}$  
$(\mathit{\text{\u2013}}\text{centerdot}p)$  $:(z{=}_{A}x)\to (z{=}_{A}y)$ 
have quasiinverses given by $\mathrm{(}{p}^{\mathrm{}\mathrm{1}}\mathit{}\text{centerdot}\mathit{}\mathit{\text{\u2013}}\mathrm{)}$ and $\mathrm{(}\mathit{\text{\u2013}}\mathit{}\text{centerdot}\mathit{}{p}^{\mathrm{}\mathrm{1}}\mathrm{)}$, respectively; see http://planetmath.org/node/87637Exercise 2.6.
Example 2.4.9.
For any $p\mathrm{:}x{\mathrm{=}}_{A}y$ and $P\mathrm{:}A\mathrm{\to}\mathrm{U}$, the function
$${\mathrm{\U0001d5cd\U0001d5cb\U0001d5ba\U0001d5c7\U0001d5cc\U0001d5c9\U0001d5c8\U0001d5cb\U0001d5cd}}^{P}(p,\mathit{\text{\u2013}}):P(x)\to P(y)$$ 
has a quasiinverse given by ${\mathrm{transport}}^{P}\mathit{}\mathrm{(}{p}^{\mathrm{}\mathrm{1}}\mathrm{,}\mathit{\text{\u2013}}\mathrm{)}$; this follows from Lemma 2.3.9 (http://planetmath.org/23typefamiliesarefibrations#Thmprelem6).
In general, we will only use the word isomorphism (and similar words such as bijection) in the special case when the types $A$ and $B$ “behave like sets” (see §3.1 (http://planetmath.org/31setsandntypes)). In this case, the type (2.4.5) is unproblematic. We will reserve the word equivalence for an improved notion $\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f)$ with the following properties:

1.
For each $f:A\to B$ there is a function $\mathrm{\U0001d5ca\U0001d5c2\U0001d5c7\U0001d5cf}(f)\to \mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f)$.

2.
Similarly, for each $f$ we have $\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f)\to \mathrm{\U0001d5ca\U0001d5c2\U0001d5c7\U0001d5cf}(f)$; thus the two are logically equivalent (see §1.11 (http://planetmath.org/111propositionsastypes)).

3.
For any two inhabitants ${e}_{1},{e}_{2}:\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f)$ we have ${e}_{1}={e}_{2}$.
In http://planetmath.org/node/87577Chapter 4 we will see that there are many different definitions of $\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f)$ which satisfy these three properties, but that all of them are equivalent. For now, to convince the reader that such things exist, we mention only the easiest such definition:
$$\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f):\equiv \left(\sum _{g:B\to A}(f\circ g\sim {\mathrm{\U0001d5c2\U0001d5bd}}_{B})\right)\times \left(\sum _{h:B\to A}(h\circ f\sim {\mathrm{\U0001d5c2\U0001d5bd}}_{A})\right).$$  (2.4.10) 
We can show 1 and 2 for this definition now. A function $\mathrm{\U0001d5ca\U0001d5c2\U0001d5c7\U0001d5cf}(f)\to \mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f)$ is easy to define by taking $(g,\alpha ,\beta )$ to $(g,\alpha ,g,\beta )$. In the other direction, given $(g,\alpha ,h,\beta )$, let $\gamma $ be the composite homotopy
$$g\stackrel{\mathit{\beta}}{\sim}h\circ f\circ g\stackrel{\mathit{\alpha}}{\sim}h$$ 
and let ${\beta}^{\prime}:g\circ f\sim {\mathrm{\U0001d5c2\U0001d5bd}}_{A}$ be obtained from $\gamma $ and $\beta $. Then $(g,\alpha ,{\beta}^{\prime}):\mathrm{\U0001d5ca\U0001d5c2\U0001d5c7\U0001d5cf}(f)$.
Property 3 for this definition is not too hard to prove either, but it requires identifying the identity types of cartesian products^{} and dependent pair types, which we will discuss in §2.6 (http://planetmath.org/26cartesianproducttypes),§2.7 (http://planetmath.org/27sigmatypes). Thus, we postpone it as well; see §4.3 (http://planetmath.org/43biinvertiblemaps). At this point, the main thing to take away is that there is a wellbehaved type which we can pronounce as “$f$ is an equivalence”, and that we can prove $f$ to be an equivalence by exhibiting a quasiinverse to it. In practice, this is the most common way to prove that a function is an equivalence.
In accord with the proofrelevant philosophy, an equivalence from $A$ to $B$ is defined to be a function $f:A\to B$ together with an inhabitant of $\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f)$, i.e. a proof that it is an equivalence. We write $(A\simeq B)$ for the type of equivalences from $A$ to $B$, i.e. the type
$$(A\simeq B):\equiv \sum _{f:A\to B}\mathrm{\U0001d5c2\U0001d5cc\U0001d5be\U0001d5ca\U0001d5ce\U0001d5c2\U0001d5cf}(f).$$  (2.4.11) 
Property 3 above will ensure that if two equivalences are equal as functions (that is, the underlying elements of $A\to B$ are equal), then they are also equal as equivalences (see §2.7 (http://planetmath.org/27sigmatypes)). Thus, we often abuse notation by denoting an equivalence by the same letter as its underlying function.
We conclude by observing:
Lemma 2.4.12.
Type equivalence is an equivalence relation on $\mathrm{U}$. More specifically:

1.
For any $A$, the identity function ${\mathrm{\U0001d5c2\U0001d5bd}}_{A}$ is an equivalence; hence $A\simeq A$.

2.
For any $f:A\simeq B$, we have an equivalence ${f}^{1}:B\simeq A$.

3.
For any $f:A\simeq B$ and $g:B\simeq C$, we have $g\circ f:A\simeq C$.
Proof.
The identity function is clearly its own quasiinverse; hence it is an equivalence.
If $f:A\to B$ is an equivalence, then it has a quasiinverse, say ${f}^{1}:B\to A$. Then $f$ is also a quasiinverse of ${f}^{1}$, so ${f}^{1}$ is an equivalence $B\to A$.
Finally, given $f:A\simeq B$ and $g:B\simeq C$ with quasiinverses ${f}^{1}$ and ${g}^{1}$, say, then for any $a:A$ we have ${f}^{1}{g}^{1}gfa={f}^{1}fa=a$, and for any $c:C$ we have $gf{f}^{1}{g}^{1}c=g{g}^{1}c=c$. Thus ${f}^{1}\circ {g}^{1}$ is a quasiinverse to $g\circ f$, hence the latter is an equivalence. ∎
Title  2.4 Homotopies and Equivalences 

\metatable 