756 A second route: \(a=a\) as a path— HoTT/Cubical Derived

This section does not continue the chain of Section 755. It starts again from \(a=a\) and takes another road: the two places of \(a=a\) are pulled apart into the two ends of an interval. On this road function extensionality, equality of equivalent statements, univalence, the circle, quotients and “some” are all computed. The assumption (A) is not made here.

756.1 The interval: two places, and what lies between

The statement \(a=a\) has two places. Name them \(0\) and \(1\), and let a variable \(i\) run between them: this is the interval \(\mathbb I\). On names of places the gates of Section 755.5 act,

\[ i\wedge j,\qquad i\vee j,\qquad \neg i=1-i , \]
with the laws of AND, OR and NOT that do not mention a particular value: both are associative, commutative and idempotent, each distributes over the other, \(0\) and \(1\) are their units and their zeros, \(\neg \neg i=i\), and \(\neg (i\wedge j)=\neg i\vee \neg j\). Two laws of \(2\) are not imposed:
\[ i\wedge \neg i=0\qquad \text {and}\qquad i\vee \neg i=1 . \]
They hold at the two ends and nowhere else. The interval is \(2\) without “no contradiction” and “excluded middle”: between the two places there are points.

756.2 Paths

A proof of \(a=b\) in \(A\) is a path: a map \(p:\mathbb I\to A\) with \(p(0)=a\) and \(p(1)=b\), written \(\langle i\rangle \,p(i)\). The following are read off, with no rule beyond the gates.

\begin{align} \mathrm {refl}_a&=\langle i\rangle \,a &&\text {the constant path: } a=a, \tag{26499}\\ p^{-1}&=\langle i\rangle \,p(\neg i) &&b=a, \tag{26500}\\ f(p)&=\langle i\rangle \,f(p(i)) &&f(a)=f(b), \tag{26501}\\ \mathrm {funext}(h)&=\langle i\rangle \,\lambda x.\,h(x)(i) &&f=g \ \text { from } h:\forall x\,(f(x)=g(x)). \tag{26502}\end{align}

The last line is function extensionality: the place \(i\) and the place \(x\) are exchanged, and nothing else is done.

(J), first half: everything equal to \(a\) is one point. For \(p:a=b\),

\[ \langle i\rangle \,\bigl (p(i),\ \langle j\rangle \,p(i\wedge j)\bigr ) \ :\ (a,\mathrm {refl}_a)=(b,p)\quad \text {in }\Sigma _x(a=x), \]
since at \(i=0\) the inner path is \(\langle j\rangle \,p(0)=\mathrm {refl}_a\) and at \(i=1\) it is \(\langle j\rangle \,p(j)=p\). The gate \(\wedge \) is what contracts the pair to the diagonal.

756.3 Closing a box: composition

Let \(\varphi \) be a condition on places built from \(i=0\), \(i=1\), \(\wedge \) and \(\vee \) (a union of faces). An open box in \(A\) is a bottom \(a_0:A\) and sides \(u\), a path defined where \(\varphi \) holds, agreeing with \(a_0\) at the start. Its lid is

\[ \mathrm {comp}^{i}\,A\,[\varphi \mapsto u]\,a_0 , \]
which agrees with \(u(1)\) where \(\varphi \) holds. Composition is not assumed for kinds in general; it is computed from the way each kind is formed.

kind its lid
\(2\), \(\mathbb N\) the bottom itself, constructor by constructor
\(A\times B\), \(\Sigma _xB(x)\) the lid of the first place, then of the second over its filling
\(A\to B\), \(\Pi _xB(x)\) at each argument, carried back along the family: \(\lambda x.\ \text {lid at } x\)
\(a=_Ab\) the lid in \(A\) of the box with the two extra sides \(a\) and \(b\)
\(\mathrm {Glue}\) Section 756.6
\(\mathcal U\) by \(\mathrm {Glue}\), Section 756.7

What composition gives. With no sides it is carrying along a path of kinds, and with two sides it is joining:

\begin{align} \mathrm {transp}^{i}\,A\ a&=\mathrm {comp}^{i}\,A\,[\,]\,a &&A(0)\to A(1), \tag{26503}\\ p\cdot q&=\langle i\rangle \ \mathrm {comp}^{j}\,A\, [\,i=0\mapsto a,\ \ i=1\mapsto q(j)\,]\ p(i) &&a=c . \tag{26504}\end{align}

(J), second half. For \(C(x,p)\) and \(d:C(a,\mathrm {refl}_a)\),

\[ \mathrm J\,d\,p=\mathrm {transp}^{i}\ C\bigl (p(i),\ \langle j\rangle \,p(i\wedge j)\bigr )\ d \ :\ C(b,p), \]
carrying \(d\) along the contraction of Section 756.2. So (J) is computed, and with it everything of Section 69.3.

756.4 Levels: one point, at most one point, sets

\begin{align} \mathrm {isContr}(A)&=\Sigma _{a}\,\Pi _{x}\,(a=x) &&\text {exactly one point}, \tag{26505}\\ \mathrm {isProp}(A)&=\Pi _{x,y}\,(x=y) &&\text {at most one point}, \tag{26506}\\ \mathrm {isSet}(A)&=\Pi _{x,y}\,\mathrm {isProp}(x=y) &&\text {at most one proof of each equality}. \tag{26507}\end{align}

A map \(f:A\to B\) is an equivalence when each fibre has exactly one point:

\[ \mathrm {isEquiv}(f)=\Pi _{b}\ \mathrm {isContr}\bigl (\Sigma _{a}\,(f(a)=b)\bigr ), \qquad A\simeq B=\Sigma _f\,\mathrm {isEquiv}(f). \]
This is “kernel \(\Delta \) and onto”, said with paths.

756.5 Gluing is computed: a pullback

Gluing is not a new former. Let \(\varphi \) be a face, and write \(X^{\varphi }\) for the points of \(X\) given only where \(\varphi \) holds: the maps from the part \(\varphi \) of the places into \(X\). Restricting to \(\varphi \) is a map \(A\to A^{\varphi }\), and \(e\) gives \(e^{\varphi }:T^{\varphi }\to A^{\varphi }\). Then

\[ \mathrm {Glue}\,[\varphi \mapsto (T,e)]\,A =\{(a,t)\in A\times T^{\varphi }:\ a|_{\varphi }=e^{\varphi }(t)\}, \]
the part of the pairs on which the two maps into \(A^{\varphi }\) agree. This is the inverse image of the diagonal of \(A^{\varphi }\), as a kernel is (Section 69.3): gluing is made from pairs, maps out of a part, and \(\Delta \).

Where \(\varphi \) holds it is \(T\). There \(X^{\varphi }=X\), and the pairs \((a,t)\) with \(a=e(t)\) are given by \(t\) alone: the kind is isomorphic to \(T\) by \((a,t)\mapsto t\).

From isomorphic to equal. For the lid of \(\mathcal U\) the glued kind must be \(T\) itself where \(\varphi \) holds. A kind may be given by cases on a face: \(T\) where \(\varphi \) holds and the pullback elsewhere, joined along the isomorphism above. This step is used, not computed; it is the one place where sameness of kinds is asked to be more than isomorphism.

Forgetting. \(\mathrm {unglue}(a,t)=a\) is the first place of the pair. Its fibre over \(a\) is the fibre of \(e\) where \(\varphi \) holds, and one point elsewhere; so it is an equivalence.

756.6 Gluing a kind onto another

Let \(A\) be a kind, \(\varphi \) a condition on places, and where \(\varphi \) holds let \(T\) be a kind with an equivalence \(e:T\simeq A\). Then

\[ \mathrm {Glue}\,[\varphi \mapsto (T,e)]\,A \]
is the kind of pairs: a point \(a\) of \(A\) and, where \(\varphi \) holds, a point \(t\) of \(T\) with \(e(t)=a\). It is made from \(\Sigma \), from maps defined on part of the places, and from equality on faces. Two facts are immediate:
\begin{align} &\text {where $\varphi $ holds,}\quad \mathrm {Glue}\,[\varphi \mapsto (T,e)]\,A=T, \tag{26508}\\ &\mathrm {unglue}:\mathrm {Glue}\,[\varphi \mapsto (T,e)]\,A\to A,\qquad (a,t)\mapsto a . \tag{26509}\end{align}

Three tools. For a line of kinds \(A\), a box \([\psi \mapsto u]\,a_0\) and a map \(f:T\to A\):

\begin{align} \shortintertext {the inside of the box:} \mathrm {fill}^{i}\,A\,[\psi \mapsto u]\,a_0 &=\langle j\rangle \ \mathrm {comp}^{k}\,A(j\wedge k)\notag \\ &\qquad [\,\psi \mapsto u(j\wedge k),\ \ j=0\mapsto a_0\,]\ a_0, \tag{26510}\\ \shortintertext {$f$ keeps lids, up to a path:} \mathrm {pres}^{i}\,f\,[\psi \mapsto u]\,t_0 &=\langle j\rangle \ \mathrm {comp}^{i}\,A\notag \\ &\qquad [\,\psi \mapsto f(u),\ \ j=1\mapsto f(v)\,]\ f(t_0),\notag \\ &\qquad v=\mathrm {fill}^{i}\,T\,[\psi \mapsto u]\,t_0, \tag{26511}\\ \shortintertext {a point of a one-point kind $F$, given on $\chi $:} \mathrm {ext}\,(c,h)\,[\chi \mapsto p] &=\mathrm {comp}^{i}\,F\,[\,\chi \mapsto h(p)(i)\,]\ c. \tag{26512}\end{align}

The second is a path from \(\mathrm {comp}^{i}A[\psi \mapsto f(u)]f(t_0)\) to \(f(\mathrm {comp}^{i}T[\psi \mapsto u]t_0)\). In the third, \((c,h)\) is the proof that \(F\) has exactly one point: a centre \(c\) and a path \(h(x):c=x\) for each \(x\). Here the fibre of \(e\) over \(a\) is read as \(\Sigma _t\,(a=e(t))\).

The lid of \(\mathrm {Glue}\). Let \(G=\mathrm {Glue}\,[\varphi \mapsto (T,e)]\,A\) along \(i\), with a box \([\psi \mapsto b]\,b_0\) in \(G\). Write \(a=\mathrm {unglue}(b)\), \(a_0=\mathrm {unglue}(b_0)\), and let \(\delta \) be the part of \(\varphi \) that holds for every \(i\). Then, in six steps:

\begin{align} \shortintertext {close the box in $A$:} a_1'&=\mathrm {comp}^{i}\,A\,[\psi \mapsto a]\,a_0, \tag{26513}\\ \shortintertext {on $\delta $, where $G$ is $T$: close it in $T$:} t_1'&=\mathrm {comp}^{i}\,T\,[\psi \mapsto b]\,b_0, \tag{26514}\\ \shortintertext {on $\delta $: the two lids agree up to $\omega $:} \omega &=\mathrm {pres}^{i}\,e\,[\psi \mapsto b]\,b_0\ :\ a_1'=e(t_1'), \tag{26515}\\ \shortintertext {on $\varphi (1)$: one point of the fibre:} (t_1,\alpha )&=\mathrm {ext}\,\bigl (\text {the fibre of $e(1)$ over $a_1'$}\bigr )\notag \\ &\qquad [\,\delta \mapsto (t_1',\omega ),\ \ \psi \mapsto (b(1),\langle j\rangle a_1')\,], \tag{26516}\\ \shortintertext {correct the lid in $A$ along $\alpha $:} a_1&=\mathrm {comp}^{j}\,A(1)\notag \\ &\qquad [\,\varphi (1)\mapsto \alpha (j),\ \ \psi \mapsto a(1)\,]\ a_1', \tag{26517}\\ \shortintertext {the lid in $G$:} b_1&=\bigl (a_1,\ t_1\bigr ). \tag{26518}\end{align}

It is a point of \(G(1)\). On \(\varphi (1)\), \(a_1=\alpha (1)=e(t_1)\), since \(\alpha :a_1'=e(t_1)\).

It agrees with the sides. On \(\psi \): \(t_1=b(1)\) and \(\alpha \) is constant, so \(a_1=a(1)\) and \(b_1=b(1)\).

Where \(\varphi \) holds throughout it is the lid of \(T\). There \(\delta \) is everything, so \(t_1=t_1'=\mathrm {comp}^{i}\,T\,[\psi \mapsto b]\,b_0\).

\(\mathrm {unglue}\) is an equivalence. Over \(a\), the fibre of \(\mathrm {unglue}\) is, where \(\varphi \) holds, the fibre of \(e\), which has exactly one point; \(\mathrm {ext}\) extends it to all places.

The lid of \(\mathcal U\). For a box of kinds \([\psi \mapsto E]\,A_0\),

\[ \mathrm {comp}^{i}\,\mathcal U\,[\psi \mapsto E]\,A_0 =\mathrm {Glue}\,[\,\psi \mapsto (E(1),\ \text {carrying back along }E)\,]\ A_0 . \]

756.7 Univalence

Let \(\mathcal U\) be the kind of the kinds of a level, closed under the formers above (the whole of a level, C26).

From an equivalence, a path. For \(e:A\simeq B\),

\[ \mathrm {ua}(e)=\langle i\rangle \ \mathrm {Glue}\, [\,i=0\mapsto (A,e),\ \ i=1\mapsto (B,\mathrm {id}_B)\,]\ B\ :\ A=_{\mathcal U}B , \]
since at \(i=0\) the glued kind is \(A\) and at \(i=1\) it is \(B\).

It computes. Carrying along \(\mathrm {ua}(e)\) is \(e\):

\[ \mathrm {transp}^{i}\,\mathrm {ua}(e)(i)\ a=e(a), \]
up to a path made of constant lids in \(B\).

Everything equivalent to \(A\) is one point. For \((T,e)\) with \(e:T\simeq A\),

\[ \langle i\rangle \ \bigl (\mathrm {Glue}\,[\,i=0\mapsto (T,e),\ i=1\mapsto (A,\mathrm {id})\,]\,A,\ \ \mathrm {unglue}\bigr ) \ :\ (T,e)=(A,\mathrm {id})\quad \text {in }\Sigma _{T}\,(T\simeq A). \]
So \(\Sigma _T(T\simeq A)\) has exactly one point. By Section 756.2, \(\Sigma _T(T=A)\) also has exactly one point. A map between two families over \(\mathcal U\) whose totals each have exactly one point is an equivalence on each fibre; applied to \(\mathrm {idtoeqv}:(T=A)\to (T\simeq A)\), defined by (J):
\[ (A=_{\mathcal U}B)\ \simeq \ (A\simeq B). \]
This is univalence. It is computed from the interval, the gates on it, and gluing.

756.8 Kinds given by points and paths are least kinds

The circle, “some” and quotients are not new formers either. Each is the least kind closed under some points, some paths, and lids: the same construction as \(\langle e\rangle \) in Section 755.7, with paths among the generators.

How it is there. Take all terms built from the point generators, the path generators applied to places, and one formal lid for each open box. Identify two terms by the kernel that makes the faces agree: a path generator at an end is its end point, and a lid on a side is that side. The quotient is the kind. That the terms are together one kind is (C26), as for \(\mathbb N\); the rest is a kernel.

What it is for. Being least, it has exactly one arrow out for each choice of the same data in another kind.

kind

generated by

an arrow out of it is

\(S^{1}\)

a point, a path \(\mathrm {base}=\mathrm {base}\)

a point \(x\) and a proof of \(x=x\)

\(\|A\|\)

a point for each \(a\), a path between any two points

an arrow \(A\to P\), for \(P\) with at most one point

\(A/R\)

a point for each \(a\), a path for each \(R(a,b)\)

an arrow \(A\to X\) keeping \(R\), for \(X\) a set

So the circle is the free \(a=a\): the kind with one point and one proof that it is itself, beyond \(\mathrm {refl}\). “Some” is again the left adjoint of Section 755.2, and the quotient is again the quotient by a kernel. Gluing is made on the side of the right adjoints, from pairs and a pullback; these kinds are made on the side of the left adjoints, from generators and a kernel.

756.9 What follows

Equivalent statements are equal. If \(P,Q\) have at most one point and \(P\leftrightarrow Q\), each fibre of \(P\to Q\) has exactly one point; so \(P\simeq Q\), and \(\mathrm {ua}\) gives \(P=Q\).

\(\mathbb F_2\) is the equalities of \(2\). The arrows \(2\to 2\) are \(\mathrm {id},\sigma ,c_0,c_1\); the equivalences are \(\mathrm {id}\) and \(\sigma \). By univalence

\[ (2=_{\mathcal U}2)=\{\mathrm {refl},\ \mathrm {ua}(\sigma )\},\qquad \mathrm {ua}(\sigma )\cdot \mathrm {ua}(\sigma )=\mathrm {ua}(\sigma \circ \sigma )=\mathrm {refl}: \qquad 1+1=0 . \]
On this road \(\mathbb F_2\) is literally \(a=a\) at \(a:=2\). Carrying \(0\) along \(\mathrm {ua}(\sigma )\) gives \(1\) and along \(\mathrm {refl}\) gives \(0\), so \(\mathrm {ua}(\sigma )\neq \mathrm {refl}\): \(\mathcal U\) is not a set.

The circle and \(\mathbb Z\). Let \(S^{1}\) have a point \(\mathrm {base}\) and a path \(\mathrm {loop}:\mathrm {base}=\mathrm {base}\); its lids are formal, one for each open box. Put

\[ \mathrm {code}(\mathrm {base})=\mathbb Z,\qquad \mathrm {code}(\mathrm {loop}(i))=\mathrm {ua}(S)(i),\qquad w(p)=\mathrm {transp}^{i}\,\mathrm {code}(p(i))\ 0 . \]
Then, since carrying along \(\mathrm {ua}(S)\) is \(S\),
\[ w(\mathrm {loop})=S(0)=1,\qquad w(\mathrm {loop}\cdot \mathrm {loop})=2,\qquad w(\mathrm {loop}^{-1})=-1, \]
and \(w:(\mathrm {base}=\mathrm {base})\simeq \mathbb Z\). The numbers are the ways in which a point of the circle is itself; the sum is the joining of paths, and the systems of Section 755.7 are equalities \(a=a\) in suitable kinds.

“Some” and quotients. \(\|A\|\) has a point \(|a|\) for each \(a:A\) and a path between any two of its points; then \(\exists x\,P(x)=\|\Sigma _xP(x)\|\). \(A/R\) has a point \([a]\) for each \(a\), a path \([a]=[b]\) for each proof of \(R(a,b)\), and at most one proof of each equality.

756.10 What is computed on this road

principle how
identity, \(\mathrm {refl}\), (J) paths; the gate \(\wedge \); carrying
equal values give equal arrows exchange of two places
equivalent statements are equal univalence for kinds with at most one point
univalence gluing
the circle, \(\mathbb Z\) as its loops \(\mathrm {ua}(S)\) and carrying
“some”, quotients kinds given by points and paths
excluded middle, choice not on this road
\[ \begin {aligned} a=a\ &\to \ \mathbb I\ (0,1,\wedge ,\vee ,\neg )\ \to \ \text {paths}\ \to \ \text {lids}\ \to \ \text {(J)}\\ &\to \ \mathrm {Glue}\ \to \ \mathrm {ua}\ \to \ (A=B)\simeq (A\simeq B)\\ &\to \ \mathbb F_2=(2=2),\ \ \mathbb Z=(\mathrm {base}=\mathrm {base}) \end {aligned} \]

The two roads meet on sets. There the gates, \(\mathbb F_2\), \(B\), the systems and the hierarchy are the same. They part at \(\mathcal U\): on the first road (A) makes every equality have one proof; on this road the interval has points between its ends, (A) is not made, and \(2=2\) has two proofs.

Remark 756.1 (Why this section is not checked in Lean). Lean is not a cubical system. In Lean an equality has exactly one proof, so inside Lean the equalities of \(2\) with itself are \(\mathrm {refl}\) alone, and univalence is false there. Hence gluing, \(\mathrm {ua}\) and the circle cannot be checked in Lean. The file PathRoute.lean checks only what does not depend on this; the section itself is checked in Cubical Agda (Section 756.11). It also checks that forgetting the glued part is an equivalence, and the three lines of the table of Section 756.8.

756.11 Cubical Agda — Verified

PIC

Figure 939: The file PathRoute.agda checked by Cubical Agda (Agda 2.8.0.2) with the cubical library, under –safe: exit code \(0\), no errors and no warnings.

The file checks: the path operations and function extensionality read off the interval; (J) computed by carrying along the contraction; \(\mathrm {ua}\) built from gluing, and that carrying along \(\mathrm {ua}(e)\) is \(e\); univalence; that equivalent statements are equal; that \(\mathrm {ua}(\sigma )\cdot \mathrm {ua}(\sigma )=\mathrm {refl}\) and \(\mathrm {ua}(\sigma )\neq \mathrm {refl}\), so that the kind of kinds is not a set; that the loops of the circle are \(\mathbb Z\), with \(w(\mathrm {loop})=1\), \(w(\mathrm {loop}\cdot \mathrm {loop})=2\) and \(w(\mathrm {loop}^{-1})=-1\) by computation; and the constructors of “some” and of quotients. Univalence and the equivalence for the circle are taken from the library. The lid of \(\mathrm {Glue}\) is built into the system; the six steps of Section 756.6 are written by hand.

Listing 395: PathRoute.agda: the second route, checked with –safe.

PathRoute.agda

{-# OPTIONS --cubical --safe --guardedness #-}

{-
  PathRoute.agda
  The second route: a = a as a path.  Checked in Cubical Agda with the
  cubical library.  `--safe`: no postulates.

  Sections 1-3 use only the interval and the built-in lid (hcomp, transp).
  Section 4 builds `ua` from the built-in Glue.  Sections 5-7 use the
  library for univalence, the Booleans, the circle and the integers.
-}

module PathRoute where

open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
  hiding (refl ; sym ; cong ; funExt ; _∙_ ; J ; JRefl)
  renaming (transport to tr)
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
  hiding (ua ; uaβ)
import Cubical.Foundations.Prelude as P
import Cubical.Foundations.Univalence as U
open import Cubical.Data.Bool
open import Cubical.Data.Int
open import Cubical.Data.Sigma
open import Cubical.Data.Empty as ⊥
open import Cubical.Relation.Nullary
open import Cubical.HITs.S1
open import Cubical.HITs.PropositionalTruncation
open import Cubical.HITs.SetQuotients

private
  variable
    ℓ ℓ' : Level
    A B : Type ℓ

------------------------------------------------------------------------
-- 1. Paths: read off the interval and its gates
------------------------------------------------------------------------

refl : {a : A} → a ≡ a
refl {a = a} = λ i → a

sym : {a b : A} → a ≡ b → b ≡ a
sym p = λ i → p (~ i)

cong : (f : A → B) {a b : A} → a ≡ b → f a ≡ f b
cong f p = λ i → f (p i)

-- function extensionality: exchange two places
funExt : {f g : A → B} → ((x : A) → f x ≡ g x) → f ≡ g
funExt h = λ i x → h x i

-- ¬ ¬ i = i, on the nose
symInvol : {a b : A} (p : a ≡ b) → sym (sym p) ≡ p
symInvol p = refl

-- everything equal to a is one point: the gate ∧
contract : {a b : A} (p : a ≡ b)
         → Path (Σ[ x ∈ A ] (a ≡ x)) (a , refl) (b , p)
contract p = λ i → (p i , λ j → p (i ∧ j))

------------------------------------------------------------------------
-- 2. Lids: joining and carrying
------------------------------------------------------------------------

_∙_ : {a b c : A} → a ≡ b → b ≡ c → a ≡ c
_∙_ {a = a} p q = λ i → hcomp (λ j → λ { (i = i0) → a ; (i = i1) → q j }) (p i)

infixr 30 _∙_

-- (J), computed by carrying along the contraction
J : {a : A} (C : (x : A) → a ≡ x → Type ℓ') (d : C a refl)
    {b : A} (p : a ≡ b) → C b p
J C d p = tr (λ i → C (p i) (λ j → p (i ∧ j))) d

JRefl : {a : A} (C : (x : A) → a ≡ x → Type ℓ') (d : C a refl)
      → J C d refl ≡ d
JRefl C d = transportRefl d

------------------------------------------------------------------------
-- 3. Levels
------------------------------------------------------------------------

singlContr : (a : A) → isContr (Σ[ x ∈ A ] (a ≡ x))
singlContr a = (a , refl) , λ s → contract (s .snd)

------------------------------------------------------------------------
-- 4. Gluing, and a path from an equivalence
------------------------------------------------------------------------

ua : {A B : Type ℓ} → A ≃ B → A ≡ B
ua {A = A} {B = B} e i =
  Glue B (λ { (i = i0) → (A , e) ; (i = i1) → (B , idEquiv B) })

-- carrying along ua e is e
uaβ : {A B : Type ℓ} (e : A ≃ B) (a : A) → tr (ua e) a ≡ equivFun e a
uaβ e a = transportRefl (equivFun e a)

-- it is the library's ua
ua-is-ua : {A B : Type ℓ} (e : A ≃ B) → ua e ≡ U.ua e
ua-is-ua e = refl

------------------------------------------------------------------------
-- 5. Univalence
------------------------------------------------------------------------

-- everything equivalent to A is one point
equivContr : (A : Type ℓ) → isContr (Σ[ T ∈ Type ℓ ] (T ≃ A))
equivContr A = EquivContr A

-- univalence
univalence′ : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalence′ = univalence

-- equivalent statements are equal
propExt : {P Q : Type ℓ} → isProp P → isProp Q → (P → Q) → (Q → P) → P ≡ Q
propExt = hPropExt

------------------------------------------------------------------------
-- 6. F₂ is the equalities of 2
------------------------------------------------------------------------

σ : Bool ≃ Bool
σ = notEquiv

-- carrying along ua σ swaps
swap-false : tr (ua σ) false ≡ true
swap-false = uaβ σ false

-- σ ∘ σ = id as equivalences
σσ : compEquiv σ σ ≡ idEquiv Bool
σσ = equivEq (P.funExt notnot)

-- 1 + 1 = 0
one-plus-one : ua σ P.∙ ua σ ≡ P.refl
one-plus-one = P.sym (uaCompEquiv σ σ) P.∙ P.cong U.ua σσ P.∙ uaIdEquiv

-- ua σ is not refl
σ≢refl : ¬ (ua σ ≡ P.refl)
σ≢refl q =
  true≢false
    (P.sym swap-false P.∙ P.cong (λ p → tr p false) q P.∙ transportRefl false)

-- the kind of kinds is not a set
¬isSetType : ¬ isSet (Type ℓ-zero)
¬isSetType h = σ≢refl (h Bool Bool (ua σ) P.refl)

------------------------------------------------------------------------
-- 7. The circle and ℤ
------------------------------------------------------------------------

-- the loops of the circle are the integers
loops : ΩS¹ ≡ ℤ
loops = ΩS¹≡ℤ

w-loop : winding loop ≡ pos 1
w-loop = P.refl

w-loop-loop : winding (loop P.∙ loop) ≡ pos 2
w-loop-loop = P.refl

w-loop-inv : winding (P.sym loop) ≡ negsuc 0
w-loop-inv = P.refl

w-three : winding (loop P.∙ loop P.∙ loop) ≡ pos 3
w-three = P.refl

------------------------------------------------------------------------
-- 8. "Some" and quotients
------------------------------------------------------------------------

some-isProp : isProp ∥ A ∥₁
some-isProp = squash₁

quot-isSet : {R : A → A → Type ℓ'} → isSet (A / R)
quot-isSet = squash/

quot-eq : {R : A → A → Type ℓ'} (a b : A) → R a b → Path (A / R) [ a ] [ b ]
quot-eq a b r = eq/ a b r

------------------------------------------------------------------------
-- 9. Gluing and kinds given by points and paths: what they are for
------------------------------------------------------------------------

-- forgetting the glued part is an equivalence
unglue-equiv : (A : Type ℓ) (φ : I)
               (f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] (T ≃ A)))
             → Glue A f ≃ A
unglue-equiv A φ f = unglueEquiv A φ f

-- the circle is the least kind with a point and a proof of a = a:
-- an arrow out of it is exactly such a pair
circle-out : {X : Type ℓ} → Iso (S¹ → X) (Σ[ x ∈ X ] (x ≡ x))
circle-out {X = X} = iso to from (λ _ → P.refl) back
  where
  to : (S¹ → X) → Σ[ x ∈ X ] (x ≡ x)
  to f = f base , λ i → f (loop i)
  from : Σ[ x ∈ X ] (x ≡ x) → S¹ → X
  from (x , p) base = x
  from (x , p) (loop i) = p i
  back : (f : S¹ → X) → from (to f) ≡ f
  back f = P.funExt λ { base → P.refl ; (loop i) → P.refl }

-- "some" is the left adjoint: an arrow out of it into a statement is an
-- arrow out of the kind
some-rec : {P : Type ℓ'} → isProp P → (A → P) → ∥ A ∥₁ → P
some-rec h g ∣ a ∣₁ = g a
some-rec h g (squash₁ x y i) = h (some-rec h g x) (some-rec h g y) i

some-out : {P : Type ℓ'} → isProp P → Iso (∥ A ∥₁ → P) (A → P)
some-out h =
  iso (λ f a → f ∣ a ∣₁) (some-rec h) (λ _ → P.refl)
      (λ f → P.funExt λ x → h _ _)

-- a quotient is the left adjoint: an arrow out of it into a set is an
-- arrow out of the kind that respects the relation
quot-out : {R : A → A → Type ℓ'} {X : Type ℓ} → isSet X
         → Iso (A / R → X) (Σ[ f ∈ (A → X) ] ((a b : A) → R a b → f a ≡ f b))
quot-out h = setQuotUniversalIso h