\chapter{Reflexive coequalizers}\label{chap:rcoeq}

The material of this chapter is joint work with Bas Spitters, which we started in the academic year 2012-2013 while I was a research assistant at the Radboud University of Nijmegen.

We begin this chapter with a proof of the type theoretic Yoneda lemma, \cref{lem:yoneda}. The Yoneda lemma is used to show in \cref{thm:emb_disc} that the discrete functor $\Delta:\UU\to\mathsf{rGph}$ from small types into the type of small reflexive graphs, is an embedding. In \cref{thm:discrete_rgraph} we show that a reflexive graph $\mathcal{A}$ is discrete if and only if it satisfies any one (and hence all) of the unique extension properties
\begin{equation*}
\begin{tikzcd}
\mathcal{I} \arrow[r] \arrow[d] & \mathcal{A} & \unit \arrow[d,swap,"0"] \arrow[r] & \mathcal{A} & \unit \arrow[d,swap,"1"] \arrow[r] & \mathcal{A}, \\
\unit \arrow[ur,densely dotted] & & \mathcal{I} \arrow[ur,densely dotted] & & \mathcal{I} \arrow[ur,densely dotted]
\end{tikzcd}
\end{equation*}
where $\mathcal{I}$ is the walking edge.

The (homotopy) reflexive coequalizer satisfies the universal property of the left adjoint of $\Delta:\UU\to\mathsf{rGph}$. We show in \cref{thm:rcoeq_is_pushout} that the reflexive coequalizer of a reflexive graph $\mathcal{A}$ is just a pushout
\begin{equation*}
\begin{tikzcd}
\sm{x,y:\pts{A}}\edg{A}(x,y) \arrow[r,"\pi_2"] \arrow[d,swap,"\pi_1"] & \pts{A} \arrow[d] \\
\pts{A} \arrow[r] & \mathsf{rcoeq}(\mathcal{A}).
\end{tikzcd}
\end{equation*}
In particular it follows that if a universe is closed under pushouts (which is our running assumption), then it is also closed under reflexive coequalizers. More practically, this characterization of reflexive coequalizers as pushouts allows us to compute in \cref{eg:rcoeq} many reflexive coequalizers in terms of previously defined operations.

Our next purpose is to study the morphisms $f:\mathcal{B}\to\mathcal{A}$ of reflexive graphs that are \emph{fibrations} in the sense that they satisfy the right orthogonality conditions
\begin{equation*}
\begin{tikzcd}
\mathcal{I} \arrow[r] \arrow[d] & \mathcal{B} \arrow[d,"f"] & \unit \arrow[d,swap,"0"] \arrow[r] & \mathcal{B} \arrow[d,"f"] & \unit \arrow[d,swap,"1"] \arrow[r] & \mathcal{B} \arrow[d,"f"] \\
\unit \arrow[ur,densely dotted] \arrow[r] & \mathcal{A} & \mathcal{I} \arrow[ur,densely dotted] \arrow[r] & \mathcal{A} & \mathcal{I} \arrow[ur,densely dotted] \arrow[r] & \mathcal{A}.
\end{tikzcd}
\end{equation*}

We show in \cref{prp:fib_cart} that the class of fibrations is precisely the class of \emph{cartesian} morphisms of reflexive graphs, i.e.~the morphisms $f:\mathcal{B}\to\mathcal{A}$ for which the naturality squares
\begin{equation*}
\begin{tikzcd}
\pts{B} \arrow[d] & \sm{i,j:\pts{B}}\edg{B}(i,j) \arrow[d] \arrow[r] \arrow[l] & \pts{B} \arrow[d] & \pts{B} \arrow[r] \arrow[d] & \sm{i,j:\pts{B}}\edg{B}(i,j) \arrow[d] \\
\pts{A} & \sm{i,j:\pts{A}}\edg{A}(i,j) \arrow[l] \arrow[r] & \pts{A} & \pts{A} \arrow[r] & \sm{i,j:\pts{A}}\edg{A}(i,j)
\end{tikzcd}
\end{equation*}
are pullback squares. It follows that $f:\mathcal{B}\to\mathcal{A}$ is a fibration whenever it appears as a pullback
\begin{equation*}
\begin{tikzcd}
\mathcal{B} \arrow[d,swap,"f"] \arrow[r] & \Delta Y \arrow[d] \\
\mathcal{A} \arrow[r] & \Delta X
\end{tikzcd}
\end{equation*}
of some map between discrete reflexive graphs. Pulling back along $h:\mathcal{A}\to\Delta X$ for a fixed type $X$ therefore provides an operation
\begin{equation*}
h^\ast : \Big(\sm{Y:\UU}(Y\to X)\Big)\to \Big(\sm{\mathcal{B}:\mathsf{rGph}}\mathsf{fib}(\mathcal{B},\mathcal{A})\Big).
\end{equation*}
One way of stating the descent property for reflexive coequalizers, is that this map is an equivalence whenever $f:\mathcal{A}\to\Delta X$ is a reflexive coequalizer. As a consequence of the descent property we obtain in \cref{thm:rcoeq_cartesian} that for any fibration $f:\mathcal{B}\to\mathcal{A}$ of reflexive graphs, a commuting square of the form
\begin{equation*}
\begin{tikzcd}
\mathcal{B} \arrow[d,->>,swap,"f"] \arrow[r] & \Delta Y \arrow[d] \\
\mathcal{A} \arrow[r] & \Delta X
\end{tikzcd}
\end{equation*}
is a pullback square of reflexive graphs if and only if the square
\begin{equation*}
\begin{tikzcd}
\mathsf{rcoeq}(\mathcal{B}) \arrow[d,swap,"\mathsf{rcoeq}(f)"] \arrow[r] & Y \arrow[d] \\
\mathsf{rcoeq}(\mathcal{A}) \arrow[r] & X
\end{tikzcd}
\end{equation*}
is a pullback square. A minor note about the forward direction is that the hypothesis that $f$ is a fibration is implied by the assumption that the square is a pullback square, so this assumption is unrestrictively superfluous. However, this assumption is necessary for the converse direction.

The situation here is that we have an adjunction $F\dashv G$ (in the present case $\mathsf{rcoeq}\dashv \Delta$) satisfying the `descent condition' that if $f$ is a fibration, i.e. the naturality square of the unit $\eta:\idfunc\Rightarrow GF$ at $f$ is a pullback square, then any square of the form
\begin{equation*}
\begin{tikzcd}
A \arrow[d,swap,"f"] \arrow[r] & GX \arrow[d,"Gg"] \\
B \arrow[r] & GY
\end{tikzcd}
\end{equation*}
is a pullback square if and only if the square
\begin{equation*}
\begin{tikzcd}
FA \arrow[r] \arrow[d,swap,"Ff"] & X \arrow[d,"g"] \\
FB \arrow[r] & Y
\end{tikzcd}
\end{equation*}
is a pullback square. We will investigate this situation further in \cref{sec:modal_descent}, where we study the descent condition for general modalities.

In the final section of this chapter we apply the previous results to colimits of diagrams indexed by a (reflexive) graph. Most useful to us are the results on sequential colimits, which we will rely on in later chapters. Here we apply our results on diagrams over (reflexive) graphs to obtain results on sequential colimits. In \cite{DoornRijkeSojakova} these results are obtained directly, and moreover they are formalized.

\section{The Yoneda lemma}
The universal property of identity types is sometimes called the type theoretic Yoneda lemma: families of maps out of the identity type are uniquely determined by their action on the reflexivity identification.

\begin{lem}\label{lem:yoneda}
Let $B$ be a type family over $A$, and let $a:A$. Then the map
\begin{equation*}
\mathsf{ev\usc{}refl}:\Big(\prd{x:A} (a=x)\to B(x)\Big)\to B(a)
\end{equation*}
given by $\lam{f} f(a,\refl{a})$ is an equivalence.
\end{lem}

\begin{proof}
The inverse of $\mathsf{ev\usc{}refl}$ is $\ind{a=}:B(a)\to \prd{x:A}(a=x)\to B(x)$. We have the homotopy $\lam{b}\refl{b}:\mathsf{ev\usc{}refl}\circ\ind{a=}\htpy \idfunc[B(a)]$ by the computation rule for identity types, so it is indeed the case that $\ind{a=}$ is a section of $\mathsf{ev\usc{}refl}$.

To see that $\ind{a=}\circ \mathsf{ev\usc{}refl}\htpy\idfunc$, let $f:\prd{x:A}(a=x)\to B(x)$. To show that $\ind{a=}(f(a,\refl{a}))=f$ we use function extensionality (twice), so it suffices to show that
\begin{equation*}
\prd{x:A}{p:a=x} \varphi(f(a,\refl{a}),x,p)=f(x,p).
\end{equation*}
This follows by path induction on $p$, since $\ind{a=}(f(a,\refl{a}),a,\refl{a})\jdeq f(a,\refl{a})$.
\end{proof}

\begin{cor}\label{cor:yoneda}
Let $B$ be a type family over $A$, and let $a:A$. Then there is an equivalence
\begin{equation*}
\eqv{\Big(\idtypevar{A}(a)=B\Big)}{\Big(B(a)\times\iscontr\Big(\sm{x:A}B(x)\Big)\Big)}.
\end{equation*}
Furthermore, for $b:B(a)$ there is an equivalence
\begin{equation*}
\eqv{\Big((\idtypevar{A}(a),\refl{a})=(B,b)\Big)}{\iscontr\Big(\sm{x:A}B(x)\Big)}.
\end{equation*}
\end{cor}

\begin{proof}
First we show that there is an equivalence
\begin{equation*}
\eqv{\Big(\prd{x:A} (a=x)\eqvsym B(x)\Big)}{B(a)\times\iscontr\Big(\sm{x:A}B(x)\Big)}.
\end{equation*}
To see this, note that the type of fiberwise equivalences $\prd{x:A} (a=x)\eqvsym B(x)$ is equivalent to the type
\begin{equation*}
\sm{f:\prd{x:A}(a=x)\to B(x)}\prd{x:A}\isequiv(f)
\end{equation*}
By \cref{thm:id_fundamental}, the type $\prd{x:A}\isequiv(f)$ is equivalent to the contractibility of the total space of $B$. Now the claim follows from \cref{lem:yoneda}. The claims in the statement are now easy consequences.
\end{proof}

\begin{defn}\label{defn:rrel}
A (small) \define{reflexive relation} $\mathcal{R}$ on $A$ is a pair $(R,\rho)$ consisting of a binary type-valued relation $R:A\to (A\to \UU)$ equipped with a proof of reflexivity
\begin{equation*}
\rho : \prd{x:A}R(x,x).
\end{equation*}
We will write $\mathsf{rRel}(A)$ for the type of all small reflexive relations on $A$, i.e.
\begin{equation*}
\mathsf{rRel}(A) \defeq \sm{R:A\to (A\to \UU)}\prd{x:A}R(x,x).
\end{equation*}
\end{defn}

\begin{cor}\label{cor:yoneda_rel}
Let $\mathcal{R}\jdeq (R,\rho)$ be a reflexive relation on $A$.
Then there is an equivalence
\begin{equation*}
\eqv{\Big((\idtypevar,\refl{})=(R,\rho)\Big)}{\prd{a:A}\iscontr\Big(\sm{x:A}R(a,x)\Big)}.
\end{equation*}
\end{cor}

The following theorem, which was proven independently by Escardó \cite{Escardo2016} around the same time, shows that the canonical map
\begin{equation*}
(x=y)\to (\idtypevar{A}(x)=\idtypevar{A}(y))
\end{equation*}
is an equivalence, for any $x,y:A$. This will be particularly relevant to us once we study $\infty$-equivalence relations.

\begin{prp}
For any type $A:\UU$, the map
\begin{equation*}
\idtypevar{A}:A\to (A\to\UU)
\end{equation*}
is an embedding.\index{identity type!is an embedding|textit}
\end{prp}

\begin{proof}
Let $a:A$. Then we calculate the fiber of $\idtypevar{A}$ at a type family $B:A\to \UU$ as follows:
\begin{align*}
\fib{\idtypevar{A}}{B} & \jdeq \sm{a:A}\idtypevar{A}(a)=B \\
& \eqvsym \sm{a:A} \Big(B(a)\times\iscontr\Big(\sm{x:A}B(x)\Big)\Big) \tag{by \cref{cor:yoneda}}\\
& \eqvsym \Big(\sm{a:A}B(a)\Big)\times \iscontr\Big(\sm{x:A}B(x)\Big) \\
& \eqvsym \iscontr\Big(\sm{x:A}B(x)\Big).
\end{align*}
The last equivalence follows since $X\times \iscontr(X)\eqvsym \iscontr(X)$ for every type $X$. We conclude that the fibers of $\idtypevar{A}$ are propositions, so $\idtypevar{A}$ is an embedding by \cref{thm:prop_emb}.
\end{proof}

\section{Discrete reflexive graphs}

\begin{defn}\label{defn:graphs_ctx}
A \define{non-reflexive graph} $\mathcal{A}$ in $\UU$ is a pair $\pairr{\pts{A},\edg{A}}$ consisting of
\begin{align*}
\pts{A} & : \UU \\
\edg{A} & : \pts{A}\to\pts{A}\to\UU.
\end{align*}
We write $\mathsf{Gph}$ for the type of all graphs in $\UU$. When $\mathcal{A}$ is a graph, we say that $\pts{A}$ is its type of \define{vertices}, and that $\edg{A}$ is its family of \define{edges}.

A \define{reflexive graph} $\mathcal{A}$ in $\UU$ consists of a graph $(\pts{A},\edg{A})$ equipped with a \define{reflexivity} term
\begin{align*}
\rfx{\mathcal{A}} & : \prd{i:\pts{A}}\edg{A}(i,i).
\end{align*}
We write
\begin{equation*}
\mathsf{rGph}\defeq \sm{V:\UU}{E:V\to (V\to\UU)}\prd{v:V}E(v,v)
\end{equation*}
for the type of reflexive graphs in $\UU$.
\end{defn}

\begin{eg}
\begin{enumerate}
\item A \define{reflexive pair} consists of types $V$ and $E$, and maps $s$, $t$, and $r$ between $V$ and $E$ as indicated in the diagram
\begin{equation*}
\begin{tikzcd}[column sep=large]
E \arrow[r,yshift=1.5ex,"s"] \arrow[r,yshift=-1.5ex,swap,"t"] & V, \arrow[l,"r" description]
\end{tikzcd}
\end{equation*}
equipped with homotopies $H_{sr}:s\circ r\htpy \idfunc[V]$ and $H_{tr}:t\circ r\htpy \idfunc[V]$.
Given a reflexive pair as above, we obtain a reflexive graph $\mathcal{A}$ by taking
\begin{align*}
\pts{A} & \defeq V \\
\edg{A}(v,w) & \defeq \sm{e:E} (s(e)=v)\times (t(e)=w) \\
\rfx{\mathcal{A}}(v) & \defeq \pairr{r(v),H_{sr}(v),H_{tr}(v)}.
\end{align*}
By a routine construction it can be shown that the type of small reflexive pairs is equivalent to the type of small reflexive graphs.
\item \label{eg:disc_codisc} Given a type $X$, the \define{discrete graph} $\Delta(X)$ on $X$ is the reflexive graph consisting of
\begin{align*}
\pts{\Delta(X)} & \defeq X \\
\edg{\Delta(X)} & \defeq \idtypevar{X} \\
\rfx{\Delta(X)} & \defeq \refl{}.
\end{align*}
\item Given a map $f:A\to X$, the \define{pre-kernel} $k(f)$ of $f$ is the reflexive relation on $A$ given by $x,y\mapsto f(x)=f(y)$.
\item The \define{indiscrete graph} $\nabla(X)$ on $X$ is the reflexive graph consisting of
\begin{align*}
\pts{\nabla(X)} & \defeq X \\
\edg{\nabla(X)} & \defeq \lam{x}{y}\unit \\
\rfx{\nabla(X)} & \defeq \ttt.
\end{align*}
The reflexive pair corresponding to $\nabla(X)$ is (equivalent to) the reflexive pair
\begin{equation*}
\begin{tikzcd}
X\times X \arrow[r,yshift=1ex,"\pi_1"] \arrow[r,yshift=-1ex,"\pi_2"] & X. \arrow[l,"\delta" description]
\end{tikzcd}
\end{equation*}
In particular, we have the \define{unit} graph $\unit\defeq\nabla(\unit)$, which happens to also be $\Delta(\unit)$.
\item The \define{walking edge} $\mathcal{I}$ is an example of a reflexive graph. One way of defining it is by taking
\begin{align*}
\pts{\mathcal{I}} & \defeq \bool \\
\edg{\mathcal{I}}(x,y) & \defeq \tau(x)\to \tau(y) \\
\rfx{\mathcal{I}}(x) & \defeq \idfunc[\tau(x)]
\end{align*}
where $\tau:\bool\to\UU$ is the \define{tautological family} on the type $\bool$ of booleans, given by $\tau(\bfalse)\defeq\emptyt$ and $\tau(\btrue)\defeq\unit$. We write $a$ for the (unique) edge from $\bfalse$ to $\btrue$. It may be helpful to think of the walking edge $\mathcal{I}$ as an interval, hence the choice of notation.
\end{enumerate}
\end{eg}

\begin{defn}
A \define{morphism} of graphs $f$ from $\mathcal{A}$ to $\mathcal{B}$ is a pair
\begin{align*}
\pts{f} & : \pts{A} \to \pts{B} \\
\edg{f} & : \prd{i,j:\pts{A}} \edg{A}(i,j)\to \edg{B}(\pts{f}(i),\pts{f}(j)).
\end{align*}
We write $\mathsf{Gph}(\mathcal{A},\mathcal{B})$ for the type of graph morphisms from $\mathcal{A}$ to $\mathcal{B}$.

A \define{morphism} of reflexive graphs $f$ from $\mathcal{A}$ to $\mathcal{B}$ is a morphism of graphs equipped with a term
\begin{align*}
\rfx{f} & : \prd{i:\pts{A}} \edg{f}(\rfx{\mathcal{A}}(i))= \rfx{\mathcal{B}}(\pts{f}(i))
\end{align*}
witnessing that reflexivity is preserved. We write $\mathsf{rGph}(\mathcal{A},\mathcal{B})$ for the type of reflexive graph morphisms from $\mathcal{A}$ to $\mathcal{B}$.
\end{defn}

For any reflexive graph there is an identity morphism, and for any composable pair of morphisms there is a composite. Furthermore, these operations are associative, and satisfy the unit laws, both up to homotopy. It should be noted, however, that composition of reflexive graph morphisms is not expected to be associative on the nose, since the reflexivity is only preserved up to higher identification.

\begin{eg}\label{eg:rgraph_morphism}
\begin{enumerate}
\item Given a function $f:X\to Y$ we obtain a morphism $\Delta f:\mathsf{rGph}(\Delta X,\Delta Y)$ given by
\begin{align*}
\pts{\Delta f} & \defeq f \\
\edg{\Delta f} & \defeq \apfunc{f} \\
\rfx{\Delta f} & \defeq \refl{\refl{f(x)}}
\end{align*}
The action of $\Delta$ on morphisms preserves identity morphisms and compositions, and moreover it preserves the unit laws and associativity.
\item The graph $\nabla(\unit)$ is the terminal reflexive graph in the sense that for any graph $\mathcal{A}$, the type $\mathsf{rGph}(\mathcal{A},\unit)$ is contractible.
\item For any reflexive graph $\mathcal{A}$, the map
\begin{equation*}
\mathsf{ev\usc{}pt}:\mathsf{rGph}(\unit,\mathcal{A})\to\pts{A}
\end{equation*}
given by $f\mapsto \pts{f}(\ttt)$, is an equivalence. The analogous statement is false for non-reflexive graphs.
\item The universal property of the walking edge $\mathcal{I}$ is that every edge $e$ in a graph $\mathcal{A}$, the type of reflexive graph morphisms that map the edge $a$ of $\mathcal{I}$ to $e$ is contractible. In other words, the map
\begin{equation*}
\mathsf{ev\usc{}edge} : \mathsf{rGph}(\mathcal{I},\mathcal{A})\to \sm{i,j:\pts{A}}\edg{A}(i,j)
\end{equation*}
given by $f\mapsto (\pts{f}(0),\pts{f}(1),\edg{f}(a))$ is an equivalence.
\item For the walking edge $\mathcal{I}$ there are reflexive graph morphisms
\begin{equation*}
\begin{tikzcd}
\mathcal{I} \arrow[r] & \unit \arrow[l,yshift=1ex,swap,"1"] \arrow[l,yshift=-1ex,"0"]
\end{tikzcd}
\end{equation*}
This is a \emph{cograph} object of reflexive graphs, since the morphism $\mathcal{I}\to\unit$ is a common \emph{retraction} of the end-point inclusions $0,1:\unit\to \mathcal{I}$, whereas in a reflexive pair (a graph object) the morphism $r$ is a common \emph{section} of the source and target maps.
\item \label{eg:freerfx} Since we do not have the technology available to establish that graphs and reflexive graphs form $\infty$-categories, a comparison between the two structures is limited to what we can say directly using the basic categorical operations such as composition. However, this is just enough to establish the universal property of an adjunction.

Given a non-reflexive graph $\mathcal{A}\jdeq\pairr{\pts{A},\edg{A}}$, we can obtain a reflexive graph $F\mathcal{A}$ by freely adjoining reflexivity:
\begin{align*}
\pts{F\mathcal{A}} & \defeq \pts{A} \\
\edg{F\mathcal{A}}(i,j) & \defeq \edg{A}(i,j)+(i=j) \\
\rfx{F\mathcal{A}}(i) & \defeq \inr(\refl{i}).
\end{align*}
On the other hand, there is the projection $U:\mathsf{rGph}\to\mathsf{Gph}$ which forgets the reflexivity structure, and for each graph $\mathcal{A}$ there is a graph morphism $\eta:\mathcal{A}\to UF\mathcal{A}$. Both $F$ and $U$ are functorial in the sense that they act on morphisms, and preserve units and composition in the obvious way, and $\eta$ is natural in $\mathcal{A}$.

The universal property of the construction $F$ of freely adjoining reflexivity, is that the map
\begin{equation*}
U(\blank)\circ \eta : \mathsf{rGph}(F\mathcal{A},\mathcal{B})\to \mathsf{Gph}(\mathcal{A},U\mathcal{B})
\end{equation*}
is an equivalence. Indeed, this is the universal property that establishes $F$ as a left adjoint to $U$, even though we cannot manifest $F$ and $U$ as functors.

The construction $F$ of freely adjoining reflexivity is not surjective on morphisms. For example, there are no morphisms from $\unit$ to the graph $\mathcal{A}$ with a contractible type of vertices but no edges. However $F\mathcal{A}$ is the terminal reflexive graph.
\end{enumerate}
\end{eg}

\begin{prp}\label{thm:emb_disc}
The operation $\Delta:\UU\to\mathsf{rGph}$ is an embedding in the following sense:
\begin{enumerate}
\item As a function, $\Delta:\UU\to\mathsf{rGph}$ is an embedding.
\item For every two types $X$ and $Y$, the action on morphisms
\begin{equation*}
\Delta : (X\to Y)\to \mathsf{rGph}(\Delta X,\Delta Y)
\end{equation*}
is an equivalence.
\end{enumerate}
\end{prp}

\begin{proof}
Let $\mathcal{A}$ be a reflexive graph. Then the fiber of $\Delta:\UU\to\mathsf{rGph}$ is calculated as follows:
\begin{align*}
\fib{\Delta}{\mathcal{A}} & \defeq \sm{X:\UU} \Delta X = \mathcal{A} \\
& \eqvsym (\idtypevar{\pts{A}},\refl{})=(\edg{A},\rfx{A}) \\
& \eqvsym \prd{x:\pts{A}}\iscontr\Big(\sm{y:\pts{A}}\edg{A}(x,y)\Big),\tag{by \cref{cor:yoneda_rel}}
\end{align*}
which is a proposition.

The map $(X\to Y)\to \mathsf{rGph}(\Delta X,\Delta Y)$ is an equivalence, since the type
\begin{equation*}
\sm{\varphi:\prd{x,y:X}(x=y)\to (f(x)=f(y))}\varphi(\refl{x})=\refl{f(x)}
\end{equation*}
is equivalent to the fiber of the map
\begin{equation*}
\mathsf{ev\usc{}refl} : \Big(\prd{x,y:X}(x=y)\to (f(x)=f(y))\Big)\to \Big(f(x)=f(x)\Big),
\end{equation*}
which is contractible by \cref{lem:yoneda}.
\end{proof}

\begin{thm}\label{thm:discrete_rgraph}
Let $\mathcal{A}$ be a reflexive graph. The following are equivalent:
\begin{enumerate}
\item The canonical map
\begin{equation*}
\prd{i,j:\pts{A}} (i=j)\to \edg{A}(i,j)
\end{equation*}
given by $\refl{i}\mapsto \rfx{\mathcal{A}}(i)$ is a fiberwise equivalence. In particular, $\mathcal{A}$ is in the image of $\Delta:\UU\to\mathsf{rGph}$.
\item The graph $\mathcal{A}$ is \define{$\mathcal{I}$-null} in the sense that the map
\begin{equation*}
\mathsf{rGph}(\unit,\mathcal{A}) \to \mathsf{rGph}(\mathcal{I},\mathcal{A})
\end{equation*}
given by pre-composition by the unique morphism $\mathsf{rGph}(\mathcal{I},\unit)$, is an equivalence.
\item The map
\begin{equation*}
\mathsf{rGph}(\mathcal{I},\mathcal{A})\to \mathsf{rGph}(\unit,\mathcal{A})
\end{equation*}
given by pre-composing with the end-point inclusion $0:\mathsf{rGph}(\unit,\mathcal{I})$, is an equivalence.
\item The map
\begin{equation*}
\mathsf{rGph}(\mathcal{I},\mathcal{A})\to \mathsf{rGph}(\unit,\mathcal{A})
\end{equation*}
given by pre-composing with the end-point inclusion $1:\mathsf{rGph}(\unit,\mathcal{I})$, is an equivalence.
\end{enumerate}
If any of these conditions hold, we say that $\mathcal{A}$ is \define{discrete}.
\end{thm}

\begin{proof}
The outline of our argument is as follows:
\begin{equation*}
\begin{tikzcd}[row sep=tiny]
& & (iii) \arrow[dr,Rightarrow] \\
(i) \arrow[r,Rightarrow] & (ii) \arrow[ur,Rightarrow] \arrow[dr,Rightarrow] & & (i). \\
& & (iv) \arrow[ur,Rightarrow]
\end{tikzcd}
\end{equation*}
Suppose (i) holds. We have a commuting square
\begin{equation*}
\begin{tikzcd}
\mathsf{rGph}(\unit,\mathcal{A}) \arrow[d,swap,"\mathsf{ev\usc{}pt}"] \arrow[r] & \mathsf{rGph}(\mathcal{I},\mathcal{A}) \arrow[d,"\mathsf{ev\usc{}edge}"] \\
\pts{A} \arrow[r] & \sm{i,j:\pts{A}}\edg{A}(i,j)
\end{tikzcd}
\end{equation*}
where both vertical maps are equivalences, and the bottom map is an equivalence by assumption. Therefore the top map is an equivalence. This proves that (i) implies (ii).

Since the reflexive graph morphism $\mathsf{rGph}(\mathcal{I},\unit)$ is a common retraction of both end-point inclusions, it follows that the pre-composition map
\begin{equation*}
\mathsf{rGph}(\unit,\mathcal{A}) \to \mathsf{rGph}(\mathcal{I},\mathcal{A})
\end{equation*}
is a common section of both pre-composition maps
\begin{equation*}
0^\ast,1^\ast:\mathsf{rGph}(\mathcal{I},\mathcal{A})\to \mathsf{rGph}(\unit,\mathcal{A})
\end{equation*}
However, assuming (ii) it follows that both $0^\ast$ and $1^\ast$ are equivalences, so (ii) implies both (iii) and (iv).

Now suppose that (iii) holds; we will show that (i) follows. We have the commuting square
\begin{equation*}
\begin{tikzcd}
\mathsf{rGph}(\mathcal{I},\mathcal{A}) \arrow[d,swap,"\mathsf{ev\usc{}edge}"] \arrow[r,"0^\ast"] & \mathsf{rGph}(\unit,\mathcal{A}) \arrow[d,"\mathsf{ev\usc{}pt}"] \\
\sm{i,j:\pts{A}}\edg{A}(i,j) \arrow[r,swap,"\pi_1"] & \pts{A}
\end{tikzcd}
\end{equation*}
in which both vertical maps are equivalences. Therefore the fibers of $\pi_1$ are equivalent to the fibers of $0^\ast$. Note that the fibers of $\pi_1$ are of the form
\begin{equation*}
\sm{j:\pts{A}}\edg{A}(i,j),
\end{equation*}
so it follows from (iii) that these are contractible. Then (i) follows by the fundamental theorem of identity types, \cref{thm:id_fundamental}.

The argument that (i) follows from (iv) is similar, using $\pi_2$ and $1^\ast$ instead of $\pi_1$ and $0^\ast$ in the square.
\end{proof}

\section{Reflexive coequalizers}

\begin{defn}
Consider a reflexive graph $\mathcal{A}$ and a type $X$ equipped with a morphism $f:\mathsf{rGph}(\mathcal{A},\Delta(X))$. We say that $f$ is a \define{reflexive coequalizer of $\mathcal{A}$} if the map
\begin{equation*}
\Delta(\blank) \circ f: (X\to Y)\to \mathsf{rGph}(\mathcal{A},\Delta(Y))
\end{equation*}
is an equivalence.
\end{defn}

Our goal in this section is to show that reflexive coequalizers can be constructed as pushouts. We will use the following lemma, which was discovered jointly with Simon Boulier.

\begin{lem}\label{lem:coh_red}
Consider a type $A$ with a type family $B$, and $a:A$. Furthermore, suppose that
\begin{equation*}
\alpha:\prd{x:A}B(x)\to (a=x).
\end{equation*}
Then the \define{coherence reduction} map
\begin{equation*}
\mathsf{coh\usc{}red} : \Big(\sm{y:B(a)}\alpha(y)=\refl{a}\Big)\to\Big(\sm{x:A}B(x)\Big)
\end{equation*}
given by $(y,q)\mapsto (a,y)$ is an equivalence.
\end{lem}

\begin{rmk}
A quick way to see that there is an equivalence
\begin{equation*}
\sm{x:A}B(x) \eqvsym \sm{b:B(a)} \alpha_{a}(b)=\refl{a}.
\end{equation*}
is to use the contractibility of the total space of identity types twice:
\begin{align*}
\sm{x:A}B(x) & \eqvsym \sm{x:A}{y:B(x)}{p:a=x}\alpha(y)=p \\
& \eqvsym \sm{y:B(a)}\alpha(y)=\refl{a}.\qedhere
\end{align*}
However, it is not clear at once that the underlying map of this composite of equivalences is indeed the map $\mathsf{coh\usc{}red}$ defined in \cref{lem:coh_red}.
\end{rmk}

\begin{proof}[Proof of \cref{lem:coh_red}]
We show that the fibers are contractible:
\begin{align*}
\fib{\mathsf{coh\usc{}red}}{(x,y)} & \eqvsym \sm{y':B(a)}{q:\alpha(y')=\refl{a}} (a,y')=(x,y) \\
& \eqvsym \sm{y':B(a)}{q:\alpha(y')=\refl{a}}{p:a=x} \mathsf{tr}_B(p,y')=y \\
& \eqvsym \sm{y':B(a)}{q:\alpha(y')=\refl{a}}{p:a=x} y'=\mathsf{tr}_B(p^{-1},y) \\
& \eqvsym \sm{p:a=x}\alpha(\mathsf{tr}_B(p^{-1},y))=\refl{a} \\
& \eqvsym \sm{p:a=x}p=\alpha(y).\qedhere
\end{align*}
\end{proof}

\begin{cor}
Consider a type $A$ with a relation $R:A\to A\to\UU$ such that
\begin{equation*}
\alpha: \prd{x,y:A}R(x,y)\to (x=y).
\end{equation*}
Then the map
\begin{equation*}
\mathsf{coh\usc{}red}:\Big(\sm{x:A}{r:R(x,x)}\alpha(r)=\refl{x}\Big)\to \Big(\sm{x,y:A}R(x,y)\Big).
\end{equation*}
given by $(x,r,c)\mapsto (x,x,r)$ is an equivalence.\qed
\end{cor}

\begin{defn}
For any reflexive graph $\mathcal{A}$ we define the span $\tilde{\mathcal{A}}$ of $\mathcal{A}$ to consist of
\begin{equation*}
\begin{tikzcd}
\tilde{A}_0 & \tilde{A}_1 \arrow[l,swap,"\pi_1"] \arrow[r,"\pi_2"] & \tilde{A}_0
\end{tikzcd}
\end{equation*}
where $\tilde{A}_0\defeq A_0$ and $\tilde{A}_1\defeq\sm{x,y:A_0}A_1(x,y)$.
\end{defn}

\begin{lem}\label{lem:rcoeq_into_disc}
For any reflexive graph $\mathcal{A}$, and any type $X$, the map
\begin{equation*}
f\mapsto (f_0,f_0,\lam{(x,y,e)}\edg{f}(e)) : \mathsf{rGph}(\mathcal{A},\Delta X) \to \mathsf{cocone}_{\tilde{\mathcal{A}}}(X),
\end{equation*}
is an equivalence, where $\tilde{\mathcal{A}}$ is the span $(\tilde{A}_1,\pi_1,\pi_2)$ from $A_0$ to $A_0$.
\end{lem}

\begin{proof}
First observe that $\mathsf{rGph}(\mathcal{A},\Delta X)$ is equivalent to the type
\begin{equation*}
\sm{\pts{f}:\pts{A}\to X}{\edg{f}:\prd{x,y:\pts{A}}\edg{A}(x,y)\to f(x)=f(y)}\mathsf{eq\usc{}htpy}(\lam{x}\edg{f}(\rfx{\mathcal{A}}(x)))=\refl{\pts{f}}.
\end{equation*}
We write $\mathsf{rGph}'(\mathcal{A},\Delta X)$ for the latter type. Furthermore, we observe that the type $\mathsf{cocone}_{\tilde{\mathcal{A}}}(X)$ is equivalent to the type
\begin{equation*}
\mathsf{cocone}'_{\tilde{A}}(X) \defeq \sm{f,g:\pts{A}\to X}\prd{x,y:\pts{A}}\edg{A}(x,y)\to f(x)=f(y).
\end{equation*}
Now we note that we have a commuting square
\begin{equation*}
\begin{tikzcd}[column sep=large]
\mathsf{rGph}(\mathcal{A},\Delta X) \arrow[d] \arrow[r,"\varphi"] & \mathsf{cocone}_{\tilde{\mathcal{A}}}(X) \arrow[d] \\
\mathsf{rGph}'(\mathcal{A},\Delta X) \arrow[r,swap,"\mathsf{coh\usc{}red}"] & \mathsf{cocone}'_{\tilde{\mathcal{A}}}(X).
\end{tikzcd}
\end{equation*}
where the map $\varphi$ is the map in the statement, and the coherence reduction map uses the homotopy
\begin{equation*}
(f,g,H)\mapsto \mathsf{eq\usc{}htpy}(\lam{x}H(\rfx{A}(x))).
\end{equation*}
Both vertical maps and the coherence reduction map are equivalences, so it follows that the asserted map is an equivalence.
\end{proof}

\begin{prp}\label{thm:rcoeq_is_pushout}
Let $\mathcal{A}$ be a reflexive graph, and let $X$ be a type equipped with $f:\mathsf{rGph}(\mathcal{A},\Delta X)$. Then the following are equivalent:
\begin{enumerate}
\item $X$ is a reflexive coequalizer of $\mathcal{A}$.
\item The square
\begin{equation*}
\begin{tikzcd}
\sm{x,y:\pts{A}}\edg{A}(x,y) \arrow[r,"\pi_2"] \arrow[d,swap,"\pi_1"] & \pts{A} \arrow[d,"\pts{f}"] \\
\pts{A} \arrow[r,swap,"\pts{f}"] & X
\end{tikzcd}
\end{equation*}
which commutes by $\lam{(i,j,e)}\edg{f}(e)$, is a pushout square.
\end{enumerate}
In particular, there is a reflexive coequalizer for every reflexive graph $\mathcal{A}$, for which we write
\begin{equation*}
\mathsf{constr}:\mathsf{rGph}(\mathcal{A},\Delta(\mathsf{rcoeq}(\mathcal{A}))).
\end{equation*}
\end{prp}

\begin{proof}
The triangle
\begin{equation*}
\begin{tikzcd}
& Y^X \arrow[dl,swap,"{\Delta(\blank)\circ f}"] \arrow[dr,"\mathsf{cocone\usc{}map}"] \\
\mathsf{rGph}(\mathcal{A},\Delta Y) \arrow[rr,"\eqvsym"] & & \mathsf{cocone}(Y)
\end{tikzcd}
\end{equation*}
commutes, for any type $Y$. In this triangle, the bottom map is the map defined in \cref{lem:rcoeq_into_disc}, which is an equivalence, so the claim follows by the 3-for-2 property of equivalences.
\end{proof}

\begin{eg}\label{eg:rcoeq} {}~
\begin{enumerate}
\item The reflexive graph quotient of the discrete graph $\Delta(X)$ of a type $X$ is just $X$ itself. It also follows that $\mathsf{constr} : \mathsf{rGph}(\mathcal{A},\Delta(\mathsf{rcoeq}(\mathcal{A})))$ is an equivalence of reflexive graphs if and only if $\mathcal{A}$ is a discrete graph.
\item The reflexive graph quotient of the indiscrete graph $\nabla(X)$ on a type $X$ is the join square $\join{X}{X}$.
\item Let $\mathcal{A}$ be a non-reflexive graph, and let $F(\mathcal{A})$ be the reflexive graph obtained by freely adding a proof of reflexivity, as in \autoref{eg:freerfx} of \autoref{eg:rgraph_morphism}. Then the non-reflexive graph quotient of $\mathcal{A}$ is the reflexive graph quotient of $F(\mathcal{A})$.
\item Let $f:A\to B$ be a map. Then the reflexive coequalizer of the reflexive graph $(A,k(f))$ is the fiberwise join $\join[X]{A}{A}$, which was introduced in \cref{defn:fib_join}.
\item Let $X$ be a type with base point $x_0:X$. Define the reflexive graph $SX$ by
\begin{align*}
\pts{SX} & \defeq \unit \\
\edg{SX} & \defeq \lam{\nameless}{\nameless}X \\
\rfx{SX} & \defeq \lam{\nameless}x_0.
\end{align*}
The reflexive graph quotient of $SX$ is the suspension of $X$.
\item The reflexive coequalizer of the walking edge $\mathcal{I}$ is the interval, which is contractible.
\end{enumerate}
\end{eg}

\section{Descent for reflexive coequalizers}\label{sec:descent_rcoeq}

Recall from \cite{AnelBiedermanFinsterJoyal} that morphism $f:X\to Y$ is right orthogonal to a map $i:A\to B$ if and only if the square
\begin{equation*}
\begin{tikzcd}
X^B \arrow[r,"\blank\circ i"] \arrow[d,swap,"f\circ \blank"] & X^A \arrow[d,"f\circ \blank"] \\
Y^B \arrow[r,swap,"\blank\circ i"] & Y^A
\end{tikzcd}
\end{equation*}
is a pullback square. We use this way of stating the orthogonality condition in our definition of fibrations of reflexive graphs: a morphism $f:\mathsf{rGph}(\mathcal{X},\mathcal{Y})$ of reflexive graphs is said to be right orthogonal to a morphism $i:\mathsf{rGph}(\mathcal{A},\mathcal{B})$ if the square
\begin{equation*}
\begin{tikzcd}
\mathsf{rGph}(\mathcal{X},\mathcal{B}) \arrow[r,"\blank\circ i"] \arrow[d,swap,"f\circ\blank"] & \mathsf{rGph}(\mathcal{X},\mathcal{A}) \arrow[d,"f\circ\blank"] \\
\mathsf{rGph}(\mathcal{Y},\mathcal{B}) \arrow[r,swap,"\blank\circ i"] & \mathsf{rGph}(\mathcal{Y},\mathcal{A})
\end{tikzcd}
\end{equation*}
is a pullback square.%
\footnote{One may note that the category of reflexive graphs is also locally cartesian closed (has $\Pi$-types), so that we could also state the orthogonality condition internally. Although this is straightforward, it is extra work and we will not need it in this thesis.}

\begin{defn}\label{defn:graph_fibration}
A morphism $f:\mathsf{rGph}(\mathcal{A},\mathcal{B})$ is said to be a \define{left fibration} of reflexive graphs if it is right orthogonal to the morphism $0:\mathsf{rGph}(\unit,\mathcal{I})$. Similarly, we say that $f$ is a \define{right fibration} of reflexive graphs if it is right orthogonal to the morphism $1:\mathsf{rGph}(\unit,\mathcal{I})$, and we say that $f$ is a \define{fibration} if it is both a left and a right fibration.
\end{defn}

\begin{lem}\label{lem:leftfib_Inull}
Suppose $f:\mathsf{rGph}(\mathcal{B},\mathcal{A})$ is a left or a right fibration. Then $f$ is right orthogonal to the terminal projection $t:\mathsf{rGph}(\mathcal{I},\unit)$.
\end{lem}

\begin{proof}
We prove the assertion assuming that $f$ is a left fibration, the case of a right fibration being similar. Consider the diagram
\begin{equation*}
\begin{tikzcd}
\mathsf{rGph}(\unit,\mathcal{A}) \arrow[d] \arrow[r] & \mathsf{rGph}(\mathcal{I},\mathcal{A}) \arrow[r] \arrow[d] & \mathsf{rGph}(\unit,\mathcal{A}) \arrow[d] \\
\mathsf{rGph}(\unit,\mathcal{B}) \arrow[r] & \mathsf{rGph}(\mathcal{I},\mathcal{B}) \arrow[r] & \mathsf{rGph}(\unit,\mathcal{B})
\end{tikzcd}
\end{equation*}
The square on the right is a pullback. Since the composite $\unit \to \mathcal{I}\to \unit$ is the identity morphism of reflexive graphs, the outer rectangle is also a pullback. Therefore the square on the left is a pullback.
\end{proof}

\begin{defn}
A morphism $f:\mathsf{rGph}(\mathcal{A},\mathcal{B})$ of reflexive graphs is said to be \define{left cartesian} if the naturality square
\begin{equation*}
\begin{tikzcd}
\sm{i,j:\pts{A}}\edg{A}(i,j) \arrow[d] \arrow[r,"\pi_1"] & \pts{A} \arrow[d] \\
\sm{i,j:\pts{B}}\edg{B}(i,j) \arrow[r,swap,"\pi_1"] & \pts{B}
\end{tikzcd}
\end{equation*}
is a pullback square. Similarly we say that $f$ is \define{right cartesian} if the naturality square
\begin{equation*}
\begin{tikzcd}
\sm{i,j:\pts{A}}\edg{A}(i,j) \arrow[d] \arrow[r,"\pi_2"] & \pts{A} \arrow[d] \\
\sm{i,j:\pts{B}}\edg{B}(i,j) \arrow[r,swap,"\pi_2"] & \pts{B}
\end{tikzcd}
\end{equation*}
is a pullback square, and we say that $f$ is \define{cartesian} if it is both left and right cartesian.
\end{defn}

\begin{eg}
A common way to obtain a cartesian morphism of reflexive graphs is via equifibered families.
An \define{equifibered family} $\mathcal{E}$ over $\mathcal{A}$ consists of
\begin{align*}
\pts{E} & : \pts{A}\to\UU \\
\edg{E} & : \prd{i,j:\pts{A}} \edg{A}(i,j)\to (\eqv{\pts{E}(i)}{\pts{E}(j)}) \\
\rfx{E} & : \prd{i:\pts{A}} \edg{E}(\rfx{\mathcal{A}}(i))\htpy \idfunc[\pts{E}(i)]
\end{align*}
Given an equifibered family $\mathcal{E}$, we form the reflexive graph $\msm{\mathcal{A}}{\mathcal{E}}$ by
\begin{align*}
\pts{\msm{\mathcal{A}}{\mathcal{E}}} & \defeq \sm{x:\pts{A}}\pts{E}(x) \\
\edg{\msm{\mathcal{A}}{\mathcal{E}}}((x,u),(y,v)) & \defeq \sm{e:\edg{A}(x,y)} \edg{E}(e,u) = v \\
\rfx{\msm{\mathcal{A}}{\mathcal{E}}}(x,u) & \defeq (\rfx{\mathcal{A}}(x),\rfx{\mathcal{E}}(x,u)).
\end{align*}
There is an obvious projection morphism $\proj 1 : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{E}},\mathcal{A})$, which is cartesian, because the squares in the diagram
\begin{equation*}
\begin{tikzcd}
\pts{\msm{\mathcal{A}}{\mathcal{E}}} \arrow[d,"\proj 1"] & \sm{s,t:\msm{\mathcal{A}}{\mathcal{E}}}\edg{\msm{\mathcal{A}}{\mathcal{E}}} \arrow[l] \arrow[r] \arrow[d,swap,"\proj 1"] & \pts{\msm{\mathcal{A}}{\mathcal{E}}} \arrow[d] \\
\pts{\mathcal{A}} & \sm{x,y:\pts{A}}\edg{A}(x,y) \arrow[l] \arrow[r] & \pts{\mathcal{A}}
\end{tikzcd}
\end{equation*}
are pullback squares by \cref{thm:pb_fibequiv}.
\end{eg}

\begin{lem}
Consider $f:\mathsf{rGph}(\mathcal{B},\mathcal{A})$ and $g:\mathsf{rGph}(\mathcal{C},\mathcal{B})$, and suppose that $f$ is (left/right) cartesian. Then $g$ is (left/right) cartesian if and only if $f\circ g$ is (left/right) cartesian, respectively.
\end{lem}

\begin{proof}
Immediate by \cref{thm:pb_pasting}.
\end{proof}

\begin{prp}\label{prp:fib_cart}
Let $f:\mathsf{rGph}(\mathcal{B},\mathcal{A})$ be a morphism of reflexive graphs. The following are equivalent:
\begin{enumerate}
\item $f$ is a (left/right) fibration.
\item $f$ is (left/right) cartesian.
\end{enumerate}
\end{prp}

\begin{proof}
We only show that $f$ is a left fibration if and only if $f$ is left cartesian, the right case being similar.

For any morphism $f:\mathsf{rGph}(\mathcal{B},\mathcal{A})$ we have the commuting cube
\begin{equation*}
\begin{tikzcd}
& \mathsf{rGph}(\mathcal{I},\mathcal{B}) \arrow[dl] \arrow[d] \arrow[dr] \\
\mathsf{rGph}(\unit,\mathcal{B}) \arrow[d] & \sm{i,j:\pts{B}}\edg{B}(i,j) \arrow[dl] \arrow[dr] & \mathsf{rGph}(\mathcal{I},\mathcal{A}) \arrow[dl,crossing over] \arrow[d] \\
\pts{B} \arrow[dr] & \mathsf{rGph}(\unit,\mathcal{A}) \arrow[d] \arrow[from=ul,crossing over] & \sm{i,j:\pts{A}}\edg{A}(i,j) \arrow[dl] \\
\phantom{\sm{i,j:\pts{A}}\edg{A}(i,j)} & \pts{A}
\end{tikzcd}
\end{equation*}
in which all vertical maps are equivalences. Therefore the top square is a pullback if and only if the bottom square is a pullback, which proves that (ii) holds if and only if (iii) holds.
\end{proof}

\begin{cor}
Suppose that $f:\mathsf{rGph}(\mathcal{B},\mathcal{A})$ is left or right cartesian. Then the square
\begin{equation*}
\begin{tikzcd}
\pts{B} \arrow[r] \arrow[d] & \sm{i,j:\pts{B}}\edg{B}(i,j) \arrow[d] \\
\pts{A} \arrow[r] & \sm{i,j:\pts{A}}\edg{A}(i,j)
\end{tikzcd}
\end{equation*}
is a pullback square.
\end{cor}

\begin{prp}
Consider a commuting square
\begin{equation*}
\begin{tikzcd}
\mathcal{C} \arrow[r] \arrow[d] & \mathcal{B} \arrow[d] \\
\mathcal{A} \arrow[r] & \mathcal{X}
\end{tikzcd}
\end{equation*}
of reflexive graphs. The following are equivalent:
\begin{enumerate}
\item The square is a pullback square.
\item The squares
\begin{equation*}
\begin{tikzcd}
\tilde{C}_0 \arrow[r] \arrow[d] & \tilde{B}_0 \arrow[d] & \tilde{C}_1 \arrow[r] \arrow[d] & \tilde{B}_1 \arrow[d] \\
\tilde{A}_0 \arrow[r] & \tilde{X}_0 & \tilde{A}_1 \arrow[r] & \tilde{X}_1
\end{tikzcd}
\end{equation*}
are pullback squares.
\end{enumerate}
\end{prp}

\begin{proof}
Straightforward.
\end{proof}

The following proposition is true more generally:

\begin{prp}\label{thm:fibration_pullback}
Consider a pullback square
\begin{equation*}
\begin{tikzcd}
\mathcal{B}' \arrow[r] \arrow[d,swap,"{f'}"] & \mathcal{B} \arrow[d,"f"] \\
\mathcal{A}' \arrow[r] & \mathcal{A}
\end{tikzcd}
\end{equation*}
of reflexive graphs, and let $h:\mathsf{rGph}(\mathcal{Y},\mathcal{X})$ be a morphism of reflexive graphs. If $f$ is right orthogonal to $h$, then so is $f'$. In particular, if $f$ is a (left/right) fibration, then so is $f'$.
\end{prp}

\begin{proof}
Consider the commuting cube
\begin{equation*}
\begin{tikzcd}
& \mathsf{rGph}(\mathcal{Y},\mathcal{B}') \arrow[dl] \arrow[d] \arrow[dr] \\
\mathsf{rGph}(\mathcal{Y},\mathcal{A}') \arrow[d] & \mathsf{rGph}(\mathcal{X},\mathcal{B}') \arrow[dl] \arrow[dr] & \mathsf{rGph}(\mathcal{Y},\mathcal{B}) \arrow[dl,crossing over] \arrow[d] \\
\mathsf{rGph}(\mathcal{X},\mathcal{A}') \arrow[dr] & \mathsf{rGph}(\mathcal{Y},\mathcal{A}) \arrow[from=ul,crossing over] \arrow[d] & \mathsf{rGph}(\mathcal{X},\mathcal{B}) \arrow[dl] \\
& \mathsf{rGph}(\mathcal{X},\mathcal{A}). & \phantom{\mathsf{rGph}(\mathcal{X},\mathcal{A}')}
\end{tikzcd}
\end{equation*}
Note $\mathsf{rGph}(\mathcal{X},\blank)$ preserves pullbacks for any reflexive graph $\mathcal{X}$. Therefore it follows that the top and bottom squares are pullback squares. Moreover, the square on the front right is a pullback square by the assumption that $f$ is right orthogonal to $h:\mathsf{rGph}(\mathcal{Y},\mathcal{X})$. Now it follows by the pasting property of pullbacks that the square on the back left is a pullback square. In other words, $f'$ is right orthogonal to $h$.
\end{proof}

\begin{prp}\label{prp:fibration_discrete}
For any map $f:X\to Y$, the morphism $\Delta f : \Delta X \to \Delta Y$ is a fibration.
\end{prp}

\begin{proof}
The commuting square
\begin{equation*}
\begin{tikzcd}
\mathsf{rGph}(\mathcal{I},\Delta X) \arrow[d] \arrow[r,"0^\ast/1^\ast"] & \mathsf{rGph}(\unit,\Delta X) \arrow[d] \\
\mathsf{rGph}(\mathcal{I},\Delta Y) \arrow[r,swap,"0^\ast/1^\ast"] & \mathsf{rGph}(\unit,\Delta Y)
\end{tikzcd}
\end{equation*}
is a pullback square, since both horizontal maps are equivalences.
\end{proof}

\begin{comment}
\begin{cor}\label{cor:fibration_pullback}
Any pullback of a morphism between discrete reflexive graphs is a fibration.
\end{cor}

We will see in \cref{thm:etale_fibration} that a morphism of reflexive graphs is a fibration if and only if the square
\begin{equation*}
\begin{tikzcd}
\mathcal{A} \arrow[d,swap,"f"] \arrow[r] & \Delta(\rcoeq(\mathcal{A})) \arrow[d,"\Delta(\rcoeq(f))"] \\
\mathcal{B} \arrow[r] & \Delta(\rcoeq(\mathcal{B}))
\end{tikzcd}
\end{equation*}
is a pullback square.

\begin{lem}
Consider any square (commuting or not)
\begin{equation*}
\begin{tikzcd}
\mathcal{B} \arrow[d,swap,"f"] \arrow[r,"k"] & \Delta Y \arrow[d,"\Delta g"] \\
\mathcal{A} \arrow[r,swap,"h"] & \Delta X.
\end{tikzcd}
\end{equation*}
of morphisms of reflexive graphs.
Then the type of identifications witnessing that the square commutes is equivalent to the type of triples $(H,H',K)$ consisting of two homotopies $H,H': h_0 \circ f_0\htpy g\circ k_0$ and a homotopy $K$ witnessing that the cube
\begin{equation*}
\begin{tikzcd}
& \tilde{B}_1 \arrow[dl] \arrow[d] \arrow[dr] \\
\tilde{B}_0 \arrow[d] & \tilde{A}_1 \arrow[dl] \arrow[dr] & \tilde{B}_0 \arrow[dl,crossing over] \arrow[d] \\
\tilde{A}_0 \arrow[dr] & Y \arrow[from=ul,crossing over] \arrow[d] & \tilde{A}_0 \arrow[dl] \\
& X
\end{tikzcd}
\end{equation*}
commutes. In this cube we assign $H$ and $H'$ to the front left and right squares, respectively.\marginnote{To prove}
\end{lem}

\begin{proof}
The type of identifications witnessing that the square commutes is equivalent to the type of triples $(H,K,L)$ consisting of
\begin{align*}
H : h_0\circ f_0\htpy g\circ k_0 \\
K :
\end{align*}
\end{proof}
\end{comment}

\begin{comment}
\begin{thm}\label{thm:descent_rcoeq}
Consider a reflexive graph morphism $h:\mathsf{rGph}(\mathcal{A},\Delta X)$. If $h$ is a reflexive coequalizer, then the map
\begin{equation*}
h^\ast : \Big(\sm{Y:\UU}Y\to X\Big)\to \Big(\sm{\mathcal{B}:\mathsf{rGph}}\mathsf{fib\usc{}rGph}(\mathcal{B},\mathcal{A})\Big)
\end{equation*}
is an equivalence. \marginnote{To prove}
\end{thm}

\begin{cor}\label{cor:descent_rcoeq}
For an cartesian morphism $f:\mathsf{rGph}(\mathcal{B},\mathcal{A})$ of reflexive graphs, the type of maps $g:X\to \mathsf{rcoeq}(\mathcal{A})$ equipped with a morphism $h:\mathsf{rGph}(\mathcal{B},\Delta X)$ and an identification witnessing that the square
\begin{equation*}
\begin{tikzcd}
\mathcal{B} \arrow[d,swap,"f"] \arrow[r,"h"] & \Delta X \arrow[d,"\Delta g"] \\
\mathcal{A} \arrow[r,swap,"\mathsf{constr}"] & \Delta(\mathsf{rcoeq}(\mathcal{A}))
\end{tikzcd}
\end{equation*}
of reflexive graph morphisms commutes, is contractible.
\end{cor}
\end{comment}

\begin{thm}\label{thm:rcoeq_cartesian}
Consider a commuting square
\begin{equation}\label{eq:rcoeq_descent}
\begin{tikzcd}
\mathcal{B} \arrow[r] \arrow[d,swap,"f"] & \Delta Y \arrow[d] \\
\mathcal{A} \arrow[r] & \Delta X
\end{tikzcd}
\end{equation}
of reflexive graphs, where $f:\mathcal{B}\to\mathcal{A}$ is a fibration of reflexive graphs. Then the following are equivalent:
\begin{enumerate}
\item The square is a pullback square of reflexive graphs.
\item The square
\begin{equation*}
\begin{tikzcd}
\mathsf{rcoeq}(\mathcal{B}) \arrow[r] \arrow[d,swap,"\mathsf{rcoeq}(f)"] & Y \arrow[d] \\
\mathsf{rcoeq}(\mathcal{A}) \arrow[r] & X
\end{tikzcd}
\end{equation*}
of types is a pullback square.
\end{enumerate}
\end{thm}

\begin{proof}
The commuting square \cref{eq:rcoeq_descent} induces a commuting cube
\begin{equation*}
\begin{tikzcd}
& \tilde{B}_1 \arrow[dl] \arrow[dr] \arrow[d] \\
\tilde{B}_0 \arrow[d] & \tilde{A}_1 \arrow[dl] \arrow[dr] & \tilde{B}_0 \arrow[d] \arrow[dl,crossing over] \\
\tilde{A}_0 \arrow[dr] & Y \arrow[from=ul,crossing over] \arrow[d] & \tilde{A}_0 \arrow[dl] \\
& X
\end{tikzcd}
\end{equation*}
in which the two vertical squares in the back are pullback squares. Moreover, the square in \cref{eq:rcoeq_descent} is a pullback square if and only if the front two squares in the cube are pullback squares. The front two squares are pullback squares if and only if the square
\begin{equation*}
\begin{tikzcd}
\tilde{B}_0 \sqcup^{\tilde{B}_1} \tilde{B}_0 \arrow[r] \arrow[d] & Y \arrow[d] \\
\tilde{A}_0 \sqcup^{\tilde{A}_1} \tilde{A}_0 \arrow[r] & Y
\end{tikzcd}
\end{equation*}
is a pullback square. Since the pushouts on the left are reflexive coequalizers, the claim follows.
\end{proof}

\begin{comment}
\subsection{Equifibered families over reflexive graphs}

In preparation for the full descent theorem we will show in \cref{prp:equifib_fam_equiv} that for any reflexive graph $\mathcal{A}$, the type of (small) type families over the reflexive coequalizer $\mathsf{rcoeq}(\mathcal{A})$ is equivalent to the type of \emph{equifibered families} over $\mathcal{A}$, and in \cref{prp:rcoeq_flattening} we will prove the flattening `lemma' for reflexive coequalizer.

\begin{defn}

\end{defn}

\begin{defn}
We define an operation
\begin{equation*}
\mathsf{equifib\usc{}fam} : (\mathsf{rcoeq}(\mathcal{A})\to\UU)\to \mathsf{equifib}(\mathcal{A})
\end{equation*}
for each reflexive graph $\mathcal{A}$, by
\begin{align*}
\pts{\mathsf{equifib\usc{}fam}(P)} & \defeq P \circ \pts{\mathsf{constr}} \\
\edg{\mathsf{equifib\usc{}fam}(P)}(e) & \defeq \mathsf{tr}_P(\edg{\mathsf{constr}}(e)) \\
\rfx{\mathsf{equifib\usc{}fam}(P)}(i) & \defeq \mathsf{htpy\usc{}eq}(\ap{\mathsf{tr}_P}{\rfx{\mathsf{constr}}(i)}).
\end{align*}
\end{defn}

\begin{prp}\label{prp:equifib_fam_equiv}
The operation
\begin{equation*}
\mathsf{equifib\usc{}fam} : (\mathsf{rcoeq}(\mathcal{A})\to\UU)\to \mathsf{equifib}(\mathcal{A})
\end{equation*}
is an equivalence for each reflexive graph $\mathcal{A}$.
\end{prp}

\begin{proof}
Note that there is a commuting square
\begin{equation*}
\begin{tikzcd}
\big(\mathsf{rcoeq}(\mathcal{A})\to\UU\big) \arrow[r] \arrow[d,swap,"\mathsf{cocone\usc{}map}(\mathsf{constr}(\mathcal{A}))","\eqvsym"'] & \mathsf{equifib}(\mathcal{A}) \arrow[from=d,swap,"\eqvsym"] \\
\mathsf{rGph}(\mathcal{A},\Delta \UU) \arrow[r,swap,"i\circ\blank"] & \mathsf{rGph}(\mathcal{A},\UU^{\eqvsym}),
\end{tikzcd}
\end{equation*}
where $\UU^{\eqvsym}$ is the reflexive graph consisting of
\begin{align*}
{\UU^{\eqvsym}_0} & \defeq \UU \\
{\UU^{\eqvsym}_1}(X,Y) & \defeq (\eqv{X}{Y}) \\
\rfx{(\UU^{\eqvsym})}(X) & \defeq \idfunc[X].
\end{align*}
Since $\UU^{\eqvsym}$ is a discrete graph by the univalence axiom, it follows that the canonical morphism $i:\mathsf{rGph}(\Delta\UU,\UU^{\eqvsym})$ is an equivalence of graphs. Furthermore, the only difference between the type of equifibered families over $\mathcal{A}$ and the type of morphisms $\mathsf{rGph}(\mathcal{A},\UU^{\eqvsym})$ is that in an equifibered family reflexivity is required to be preserved up to homotopy, whereas in a morphism reflexivity is required to be preserved up to identification. Therefore the canonical map $\mathsf{rGph}(\mathcal{A},\UU^{\eqvsym})\to\mathsf{equifib}(\mathcal{A})$ is an equivalence by function extensionality. Thus we see that $\mathsf{equifib\usc{}fam}(\mathcal{A})$ is a composite of equivalences, so the claim follows.
\end{proof}

\begin{rmk}
Using the walking edge $\mathcal{I}$ it can be shown that if the operation $\mathsf{equifib\usc{}fam}(\mathcal{I})$ is an equivalence, then the univalence axiom holds \cite{RijkeSpittersBarcelona}. Thus: `an interval satisfying descent implies univalence'.
\end{rmk}

\begin{cor}
Let $\mathcal{E}$ be an equifibered family over $\mathcal{A}$. The type of small families $E$ over $\mathsf{rcoeq}(\mathcal{A})$ equipped with
\begin{enumerate}
\item a family of equivalences
\begin{align*}
\varphi_0 & : \prd{x:\pts{A}} E_0(x) \eqvsym E(\mathsf{constr}_0(x)),
\end{align*}
\item for each edge $e:\edg{A}(x,y)$ a commuting square
\begin{equation*}
\begin{tikzcd}
E_0(x) \arrow[d,swap,"E_1(e)"] \arrow[r,"\varphi_0(x)"] & E(\mathsf{constr}_0(x)) \arrow[d,"\mathsf{tr}_{E}(\mathsf{constr}_1(e))"] \\
E_0(y) \arrow[r,swap,"\varphi_0(y)"] & E(\mathsf{constr}_0(y)),
\end{tikzcd}
\end{equation*}
\item for each $x:A_0$ a homotopy witnessing that the triangle
\begin{equation*}
\begin{tikzcd}[column sep=tiny]
\varphi_0(x)\circ E_1(\rfx{\mathcal{A}}(x)) \arrow[rr,"\varphi_1(\rfx{\mathcal{A}}(x))"] \arrow[dr,swap,"\varphi_0(x)\cdot \rfx{\mathcal{E}}(x)"] & & \mathsf{tr}_{E}(\mathsf{constr}_1(\rfx{\mathcal{A}}(x)))\circ \varphi_0(x) \arrow[dl,"\mathsf{htpy\usc{}eq}(\ap{\mathsf{tr}_{E}}{\rfx{\mathsf{constr}}(x)})\cdot\varphi_0(x)"] \\
& \varphi_0(x),
\end{tikzcd}
\end{equation*}
\end{enumerate}
is contractible.
\end{cor}

\begin{proof}
The described type is equivalent to the fiber of $\mathsf{equifib\usc{}fam}$.
\end{proof}

\begin{defn}
Let $\mathcal{E}$ be an equifibered family over $\mathcal{A}$.
We define $\rcoeq(\mathcal{E}):\rcoeq (\mathcal{A})\to\UU$ to be the type family
$\mathsf{equifib\usc{}fam}^{-1}(\mathcal{E})$.
\end{defn}

By \cref{cor:descent_rcoeq} there is a commuting square
\begin{equation*}
\begin{tikzcd}[column sep=huge]
\msm{\mathcal{A}}{\mathcal{E}} \arrow[d,swap,"\proj 1"] \arrow[r,"\mathsf{tot\usc{}constr}"] & \Delta\big(\sm{x:\mathsf{rcoeq}(\mathcal{A})}\mathsf{rcoeq}(\mathcal{E},x)\big) \arrow[d,"\Delta(\proj 1)"] \\
\mathcal{A} \arrow[r,swap,"\mathsf{constr}"] & \Delta(\mathsf{rcoeq}(\mathcal{A}))
\end{tikzcd}
\end{equation*}
of reflexive graph morphisms.

\begin{prp}\label{prp:rcoeq_flattening}
For any equifibered family over $\mathcal{A}$, the reflexive graph morphism
\begin{equation*}
\mathsf{tot\usc{}constr}:\mathsf{rGph}\Big(\msm{\mathcal{A}}{\mathcal{E}},\Delta\big(\sm{x:\mathsf{rcoeq}(\mathcal{A})}\mathsf{rcoeq}(\mathcal{E},x)\big)\Big)
\end{equation*}
is a reflexive coequalizer.
\end{prp}

\subsection{The descent theorem for reflexive graphs}

\begin{defn}\label{defn:graphs_fam}
A \define{family $\mathcal{B}$ of graphs over $\mathcal{A}$} is a triple $\pairr{\pts{B},\edg{B},\rfx{B}}$ consisting of
\begin{align*}
\pts{B} & : \pts{A}\to\UU \\
\edg{B} & : \prd*{i,j:\pts{A}}{q:\edg{A}(i,j)} \pts{B}(i)\to\pts{B}(j)\to\UU \\
\rfx{\mathcal{B}} & : \prd{i:\pts{A}}{x:\pts{B}(i)} \edg{B}(\rfx{\mathcal{A}}(i),x,x).
\end{align*}
We will write $\mathsf{fam}(\mathcal{A})$ for the type of families of (small) graphs over $\mathcal{A}$.
\end{defn}

\begin{defn}\label{graph:ext}
Suppose that $\mathcal{B}$ is a family of reflexive graphs over $\mathcal{A}$. Then we define the \define{total graph} of $\mathcal{B}$ to be the reflexive graph $\msm{\mathcal{A}}{\mathcal{B}}$ given by
\begin{align*}
\pts{\msm{\mathcal{A}}{\mathcal{B}}} & \defeq \sm{i:\pts{A}}\pts{B}(i)\\
\edg{\msm{\mathcal{A}}{\mathcal{B}}}(\pairr{i,x},\pairr{j,y}) & \defeq \sm{q:\edg{A}(i,j)}\edg{B}(q,x,y)\\
\rfx{\msm{\mathcal{A}}{\mathcal{B}}}(\pairr{i,x}) & \defeq \pairr{\rfx{\mathcal{A}}(i),\rfx{\mathcal{B}}(x)}.
\end{align*}
Furthermore, we define the reflexive graph morphism $\proj 1:\mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{B}},\mathcal{A})$ by
\begin{align*}
\pts{(\proj 1)} & \defeq \proj 1 \\
\edg{(\proj 1)}((i,x),(j,y)) & \defeq \proj 1 \\
\rfx{(\proj 1)}((i,x)) & \defeq \refl{\rfx{\mathcal{A}}(i)}.
\end{align*}
\end{defn}

\begin{prp}
For any small reflexive graph $\mathcal{A}$, the type $\mathsf{fam}_\UU(\mathcal{A})$ is equivalent to the type
\begin{equation*}
\sm{\mathcal{B}:\mathsf{rGph}}\mathsf{rGph}(\mathcal{B},\mathcal{A}).
\end{equation*}
\end{prp}

\begin{eg}
We define the universe $\mathcal{G}$ of reflexive graphs to be the reflexive graph consisting of
\begin{align*}
\pts{\mathcal{G}} & \defeq \mathsf{rGph} \\
\edg{\mathcal{G}}(\mathcal{A},\mathcal{B}) & \defeq \pts{A}\to\pts{B}\to\UU \\
\rfx{\mathcal{G}}(\mathcal{A}) & \defeq \edg{A},
\end{align*}
and we define the \define{universal family of reflexive graphs} $\tilde{\mathcal{G}}$ over $\mathcal{G}$ to consist of
\begin{align*}
\pts{\tilde{\mathcal{G}}}(\mathcal{A}) & \defeq \pts{A} \\
\edg{\tilde{\mathcal{G}}}(S) & \defeq S \\
\rfx{\tilde{\mathcal{G}}}(\mathcal{A}) & \defeq \rfx{\mathcal{A}}.
\end{align*}
This family of graphs is universal in the sense that for any reflexive graphs $\mathcal{A}$, the pre-composition map $\alpha\mapsto \tilde{\mathcal{G}}\cdot\alpha$ of type
\begin{equation*}
\begin{tikzcd}
\mathsf{rGph}({\mathcal{A}},{\mathcal{G}})\to\tffam{\mathcal{A}}
\end{tikzcd}
\end{equation*}
is an equivalence.

To see this, note that a morphism $\chi:\mathcal{A}\to\mathcal{G}$ is a triple $\pairr{\mathcal{G},R,\rho}$ consisting of
\begin{align*}
\mathcal{G} & : \pts{A}\to\mathsf{rGraph} \\
R & : \prd*{i,j:\pts{A}}{q:\edg{A}(i,j)} \pts{\mathcal{G}(i)}\to\pts{\mathcal{G}(j)}\to\UU \\
\rho & : \prd{i:\pts{A}} \edg{\mathcal{G}(i)}=R(\rfx{\mathcal{A}}(i)).
\end{align*}
The type of such triples $\pairr{\mathcal{G},R,\rho}$ is equivalent to the type of pentuples $\pairr{\pts{G},\edg{G},\rfx{G},R,\rho}$ consisting of
\begin{align*}
\pts{G} & : \pts{A}\to\UU \\
\edg{G} & : \prd*{i:\pts{A}} \pts{G}(i)\to\pts{G}(i)\to\UU \\
\rfx{G} & : \prd{i:\pts{A}}{g:\pts{G}(i)} \edg{G}(g,g) \\
R & : \prd*{i,j:\pts{A}}{q:\edg{A}(i,j)} \pts{G}(i)\to\pts{G}(j)\to\UU \\
\rho & : \prd{i:\pts{A}} \edg{G}(i)=R(\rfx{\mathcal{A}}(i)).
\end{align*}
Note that the type of $R$ does not depend on $\edg{G}$ or $\rfx{G}$, and that the type of $\rho$ does not depend on $\rfx{G}$. Thus, we can use the contractibility of the type of pairs $\pairr{\edg{G},\rho}$ to conclude that the type of pentuples $\pairr{\pts{G},\edg{G},\rfx{G},R,\rho}$ as described above is equivalent to the type of triples $\pairr{\pts{G},R,\rfx{G}}$ consisting of
\begin{align*}
\pts{G} & : \pts{A}\to\UU \\
R & : \prd*{i,j:\pts{A}}{q:\edg{A}(i,j)} \pts{G}(i)\to\pts{G}(j)\to\UU \\
\rfx{G} & : \prd*{i:\pts{A}}{g:\pts{G}(i)} R(\rfx{A}(i),g,g).
\end{align*}
Note that this is precisely the type of families of reflexive graphs over $\mathcal{A}$. Explicitly, the equivalence we have constructed is given by
\begin{equation*}
\pairr{\mathcal{G},R,\rho}\mapsto \pairr{(\lam{i}\pts{\mathcal{G}(i)}),R,(\lam{i}{g}\trans{\rho(i)}{\rfx{\mathcal{G}(i)}(g)})}.
\end{equation*}
By inspection one sees that this map is the map
\begin{equation*}
\pairr{\mathcal{G},R,\rho}\mapsto \tilde{U}\cdot\pairr{\mathcal{G},R,\rho}
\end{equation*}
of which the theorem asserts that it is an equivalence.
\end{eg}

\begin{rmk}
There also is a universal family of non-reflexive graphs, which is considerably simpler. However, the universe of non-reflexive graphs is \emph{not} obtained by simply forgetting the reflexivity of $\mathcal{G}$. Instead, the universe $\mathcal{S}$ of non-reflexive graphs is given by
\begin{align*}
\pts{\mathcal{S}} & \defeq \UU \\
\edg{\mathcal{S}}(A, B) & \defeq A \to B \to\UU,
\end{align*}
and its universal family $\tilde{\mathcal{S}}$ over $\mathcal{S}$ is given by
\begin{align*}
\pts{\tilde{\mathcal{S}}}(A) & \defeq A \\
\edg{\tilde{\mathcal{S}}}(R) & \defeq R.
\end{align*}
Then it can be shown that the canonical map
\begin{equation*}
\begin{tikzcd}
\mathsf{Gph}({\mathcal{A}},{\mathcal{S}})\to\tffam{\mathcal{A}}
\end{tikzcd}
\end{equation*}
is an equivalence, where $\tffam{\mathcal{A}}$ is the type of small families of non-reflexive graphs.
\end{rmk}

\begin{defn}\label{defn:functional}
Let $R:A\to (B\to \UU)$ be a binary relation from $A$ to $B$.
\begin{enumerate}
\item $R$ is said to be \define{functional} if there is a term of type
\begin{equation*}
\isfunction (R) \defeq \prd{x:A}\iscontr \big(\sm{y:B}R(x,y)\big).
\end{equation*}
\item The \define{opposite} $R^{op}:B\to (A\to \UU)$ of a relation $R:A\to (B\to \UU)$ is defined by $R^{op}(b,a)\defeq R(a,b)$.
\item $R$ is said to be a \define{correspondence} if both $R$ and $R^{op}$ are functional. We will write $\mathsf{is\usc{}corr}(R)$ for the property that $R$ is a correspondence.
\end{enumerate}
\end{defn}

\begin{lem}[Exercise 4.2 in \cite{hottbook}]\label{lem:fun_rel}
Let $A$ and $B$ be types.
\begin{enumerate}
\item The map $f\mapsto \lam{x}{y}(f(x)=y)$ with the canonical proof that the relation associated to $f$ is functional is an equivalence
\begin{equation*}
(A\to B) \eqvsym {\sm{R:A\to B\to \UU}\isfunction (R)}.
\end{equation*}
\item The map $e\mapsto \lam{x}{y}(e(x)=y)$ with the canonical proof that the relation associated to $e$ is a correspondence is an equivalence
\end{enumerate}
\begin{equation*}
(\eqv{A}{B}) \eqvsym {\sm{R:A\to B\to\UU}\mathsf{is\usc{}corr}(R)}.\qedhere
\end{equation*}
\end{lem}

\begin{defn}
Let $\mathcal{B}$ be a family of reflexive graphs over $\mathcal{A}$.
\begin{enumerate}
\item We say that $\mathcal{B}$ is \define{diagrammatic} if each relation
\begin{equation*}
\edg{B}(e):\pts{B}(i)\to \pts{B}(j)\to\UU
\end{equation*}
is functional. We write $\mathsf{is\usc{}diagr}(\mathcal{B})$ for the proposition that $\mathcal{B}$ is diagrammatic.
\item We say that $\mathcal{B}$ is \define{equifibered} if each relation
\begin{equation*}
\edg{B}(e):\pts{B}(i)\to \pts{B}(j)\to\UU
\end{equation*}
is a correspondence. We write $\mathsf{is\usc{}eqf}(\mathcal{B})$ for the proposition that $\mathcal{B}$ is equifibered.
\end{enumerate}
\end{defn}

\begin{lem}
The type of diagrammatic families over $\mathcal{A}$ is equivalent to the type of diagrams over $\mathcal{A}$.
\end{lem}

\begin{lem}
The type of families $\mathcal{B}$ over $\mathcal{A}$ satisfying $\mathsf{is\usc{}eqf}(\mathcal{B})$ is equivalent to the type of equifibered families over $\mathcal{A}$.
\end{lem}

\begin{thm}
Let $\mathcal{B}$ be a family of reflexive graphs over $\mathcal{A}$. The following are equivalent:
\begin{enumerate}
\item $\mathcal{B}$ is diagrammatic.
\item The morphism $\proj 1 : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{B}},\mathcal{A})$ is a left fibration.
\item The morphism $\proj 1 : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{B}},\mathcal{A})$ is left cartesian.
\end{enumerate}
\end{thm}

\begin{thm}\label{thm:fib_cart}
Let $\mathcal{B}$ be a family of reflexive graphs over $\mathcal{A}$. The following are equivalent:
\begin{enumerate}
\item $A$ is equifibered.
\item The morphism $\proj 1 : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{B}},\mathcal{A})$ is a fibration.
\item The morphism $\proj 1 : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{B}},\mathcal{A})$ is cartesian.
\end{enumerate}
\end{thm}
\end{comment}

\begin{comment}
\section{\texorpdfstring{$2$}{2}-simplicial types}

We have observed in \cref{eg:rcoeq} that for any $f:A\to X$ we have a reflexive coequalizer diagram
\begin{equation*}
\begin{tikzcd}
\Big(\sm{x,y:A}f(x)=f(y)\Big) \arrow[r,yshift=1ex] \arrow[r,yshift=-1ex] & A \arrow[l] \arrow[r] & \join[X]{A}{A},
\end{tikzcd}
\end{equation*}
and for any coherent H-space $X$ we have a reflexive coequalizer diagram
\begin{equation*}
\begin{tikzcd}
X \arrow[r,yshift=1ex] \arrow[r,yshift=-1ex] & \unit \arrow[l] \arrow[r] & \susp X.
\end{tikzcd}
\end{equation*}
However, both the pre-kernel of a map and a coherent H-space come equipped with a multiplicative structure that satisfies unit laws. What spaces do we get when take not only the reflexive coequalizer, but also take into account the multiplicative structure and unit laws when forming the colimit?

This question can by answered by studying `$2$-truncated simplicial types', by which we understand triples $(A_0,A_1,A_2)$ consisting of
\begin{align*}
A_0 & : \UU \\
A_1 & : A_0 \to A_0 \to \UU\\
A_2 & : \prd{x,y,z:A_0} A_1(x,y) \to A_1(x,z)\to A_1(y,z) \to \UU,
\end{align*}
representing the types of $0$-, $1$-, and $2$-cells, equipped with a `unital' or `simplicial' structure consisting of a unit (the reflexivity term of $A_1$), a right and left unit law and a coherence between them. In this section I give a brief sketch of some developments in this direction. Further details will appear in \cite{Rijke_simplicial}.

\begin{defn}
A small \define{$2$-simplicial type}\marginnote{I'm not entirely sold on the terminology of $2$-simplicial type. Open to suggestions} $\mathcal{A}$ consists of:
\begin{enumerate}
\item A \define{$2$-semi-simplicial structure} $(A_0,A_1,A_2)$ consisting of
\begin{align*}
A_0 & : \UU \\
A_1 & : A_0 \to A_0 \to \UU \\
A_2 & : \prd{x_0,x_1,x_2:A_0} A_1(x_0,x_1)\to A_1(x_0,x_2)\to A_1(x_1,x_2)\to\UU.
\end{align*}
Terms of $A_0$ are also called \define{vertices} or \define{$0$-cells}. Terms of type $A_1(x,y)$ are also called \define{edges} or \define{$1$-cells}. Terms of type $A_2(p,r,q)$ are also called \define{$2$-cells}.
\item A \define{$2$-simplicial structure} or \define{unital structure}
\begin{equation*}
(\rfx{\mathcal{A}},\mathsf{right\usc{}unit}_{\mathcal{A}},\mathsf{left\usc{}unit}_{\mathcal{A}},\mathsf{coh\usc{}unit}_{\mathcal{A}})
\end{equation*}
consisting of
\begin{align*}
\rfx{\mathcal{A}} & : \prd{x:\pts{A}} \edg{A}(x,x) \\
\mathsf{right\usc{}unit}_{\mathcal{A}} & : \prd{x_0,x_1:A_0}{f:A_1(x_0,x_1)} A_2(f,f,\rfx{\mathcal{A}}(x_1)) \\
\mathsf{left\usc{}unit}_{\mathcal{A}} & : \prd{x_1,x_2:A_0}{g:A_1(x_1,x_2)} A_2(\rfx{\mathcal{A}}(x_1),g,g) \\
\mathsf{coh\usc{}unit}_{\mathcal{A}} & : \prd{x:A_0} \mathsf{left\usc{}unit}(\rfx{\mathcal{A}}(x))=\mathsf{right\usc{}unit}(\rfx{\mathcal{A}}(x)).
\end{align*}
Given a 2-semi-simplicial structure $\mathcal{A}$, we write $\mathsf{simp}(\mathcal{A})$ for the type of quadruples in the $2$-simplicial structure of $\mathcal{A}$.
\end{enumerate}
\end{defn}

\begin{eg}
Let $X$ be a type. The \define{discrete} $2$-simplicial type $\Delta X$ consists of
\begin{samepage}
\begin{align*}
\pts{\Delta X} & \defeq X \\
\edg{\Delta X}(x,y) & \defeq x=y \\
\Delta X_2(p,r,q) & \defeq \ct{p}{q}=r,
\end{align*}
\end{samepage}%
using that the identity type is reflexive and that composition satisfies the coherent unit laws.
\end{eg}

\begin{eg}
Let $X$ be a type. The \define{indiscrete} $2$-simplicial type $\nabla X$ consists of
\begin{samepage}
\begin{align*}
\pts{\Delta X} & \defeq X \\
\edg{\Delta X}(x,y) & \defeq \unit \\
\Delta X_2(p,r,q) & \defeq \unit. \\
\end{align*}
\end{samepage}%
Since the types of $1$-cells and $2$-cells are always contractible, the indiscrete $2$-simplicial type $\nabla X$ possesses the unital structure in a unique way.
\end{eg}

\begin{eg}
Let $f:A\to X$ be a map. The \define{$2$-pre-kernel} $k^2(f)$ consists of
\begin{samepage}
\begin{align*}
\pts{k^2(f)} & \defeq A \\
\edg{k^2(f)}(x,y) & \defeq f(x)=f(y) \\
k^2(f)_2(p,r,q) & \defeq \ct{p}{q}=r. \\
\end{align*}
\end{samepage}%
The unital structure of $k^2(f)$ comes from the unital structure of the identity type of $B$.
\end{eg}

\begin{eg}
Let $X$ be a coherent H-space, as specified in \cref{defn:coh_hspace}. Then we have the $2$-simplicial type $S^2X$ consisting of
\begin{samepage}
\begin{align*}
\pts{S^2X} & \defeq \unit \\
\edg{S^2X}(s,t) & \defeq X \\
S^2X_2(x,z,y) & \defeq \mu(x,y)=z \\
\end{align*}
\end{samepage}%
Since $X$ has a unit and the multiplication satisfies the coherent unit laws, we obtain the unital structure of $S^2 X$ in a canonical way.
\end{eg}

\begin{table}
\centering
\caption{\label{table:stype_eg}The specification of the $2$-simplicial types $\Delta X$, $\nabla X$, $k^2(f)$, and $S^2 X$.}
\begin{tabular}{lllll}
\toprule
$\mathcal{A}$ & $\Delta X$ & $\nabla X$ & $k^2(f)$ & $S^2X$ \\
\midrule
$\pts{A}$ & $X$ & $X$ & $A$ & $\unit$  \\
$\edg{A}(x,y)$ &  $x=y$ & $\unit$ & $f(x)=f(y)$ & $X$ \\
$\rfx{\mathcal{A}}$(x) & $\refl{x}$ & $\ttt$ & $\refl{f(x)}$ & $1$  \\
$A_2(p,r,q)$ & $\ct{p}{q}=r$ & $\unit$ & $\ct{p}{q}=r$ & $\mu(p,q)=r$ \\
$\mathsf{right\usc{}unit}_{\mathcal{A}}(p)$ & $\mathsf{right\usc{}unit}(p)$ & $\ttt$ & $\mathsf{right\usc{}unit}(p)$ & $\mathsf{right\usc{}unit}_{\mu}(p)$ \\
$\mathsf{left\usc{}unit}_{\mathcal{A}}(p)$ & $\mathsf{left\usc{}unit}(p)$ & $\ttt$ & $\mathsf{left\usc{}unit}(p)$ & $\mathsf{left\usc{}unit}_{\mu}(p)$ \\
$\mathsf{coh\usc{}unit}_{\mathcal{A}}(p)$ & $\mathsf{coh\usc{}unit}(p)$ & $\refl{\ttt}$ & $\mathsf{coh\usc{}unit}(p)$ & $\mathsf{coh\usc{}unit}_{\mu}(p)$ \\
\bottomrule
\end{tabular}
\end{table}

In \cref{prp:2disc_emb} we show that the operation $\Delta:\UU\to \mathsf{sType}_2$, taking types to discrete $2$-simplicial types, is an embedding. Moreover, its action on morphisms
\begin{equation*}
(X\to Y) \to \mathsf{sType}_2(\Delta X,\Delta Y)
\end{equation*}
is an equivalence. As in the case of reflexive graphs, discrete $2$-simplicial types play a pivotal role in this chapter. We analyze the discrete $2$-simplicial types further by showing that they are right orthogonal to the morphisms between the walking $0$-, $1$-, and $2$-cells, also known as the standard $0$-, $1$-, and $2$-simplices. The standard simplices organize themselves in a cosimplicial object
\begin{equation*}
\begin{tikzcd}
\Delta[2] \arrow[r,yshift=1ex] \arrow[r,yshift=-1ex] & \Delta[1] \arrow[l,yshift=2ex] \arrow[l] \arrow[l,yshift=-2ex] \arrow[r] & \Delta[0] \arrow[l,yshift=1ex] \arrow[l,yshift=-1ex]
\end{tikzcd}
\end{equation*}
and a fibration is a morphism that is right orthogonal with respect to all morphisms in the above cosimplicial diagram. This condition is equivalent to being right orthogonal to the horn inclusions.

Analogous to \cref{thm:rcoeq_is_pushout}, we show that the typal realization of a $2$-simplicial type $\mathcal{A}$ is simply the homotopy colimit of the diagram
\begin{equation*}
\begin{tikzcd}
& \tilde{A}_2 \arrow[dl] \arrow[d] \arrow[dr] \\
\tilde{A}_1 \arrow[d] & \tilde{A}_1 \arrow[dl] \arrow[dr] & \tilde{A}_1 \arrow[dl,crossing over] \arrow[d] \\
\tilde{A}_0 & \tilde{A}_0 \arrow[from=ul,crossing over] & \tilde{A}_0,
\end{tikzcd}
\end{equation*}
where $\tilde{A}_i$ is the total space of all $i$-cells.
This presentation of the typal realization allows us to compute typal realizations as iterated pushouts.

We will show in \cref{cor:2-pre-kernel} that the typal realization of the $2$-pre-kernel of a map $f:A\to X$ is the triple fiberwise join $\join[X]{A}{\join[X]{A}{A}}$, and we will show in \cref{cor:geom_hspace} that the typal realization of a coherent H-space is the cofiber of the Hopf fibration
\begin{equation*}
\begin{tikzcd}
\join{X}{X} \arrow[r,"\eta_X"] \arrow[d] & \susp X \arrow[d] \\
\unit \arrow[r] & \mathsf{cof}_{\eta_X}.
\end{tikzcd}
\end{equation*}
Of course, in this result we use the coherence of a coherent H-space.

We will also be able to use the material of this chapter to show that the join and smash product are associative operations.
\end{comment}

\section{Colimits of diagrams over graphs}

\begin{defn}
Let $\mathcal{A}$ be a reflexive graph. A diagram $\mathcal{D}$ over $\mathcal{A}$ is a triple $(\pts{D},\edg{D},\rfx{\mathcal{D}})$ consisting of
\begin{align*}
\pts{D} & : \pts{A}\to \UU \\
\edg{D} & : \prd{i,j:\pts{A}} \edg{A}(i,j)\to (\pts{D}(i)\to \pts{D}(j)) \\
\rfx{\mathcal{D}} & : \prd{i:\pts{A}} \edg{D}(\rfx{\mathcal{A}}(i))\htpy \idfunc[\pts{D}(i)].
\end{align*}
\end{defn}

\begin{defn}
Let $\mathcal{D}$ be a diagram over $\mathcal{A}$. We form the \define{total graph} $\msm{\mathcal{A}}{\mathcal{D}}$ of $\mathcal{D}$ by
\begin{align*}
\pts{\msm{\mathcal{A}}{\mathcal{D}}} & \defeq \sm{i:\pts{A}}\pts{D}(i) \\
\edg{\msm{\mathcal{A}}{\mathcal{D}}}((i,x),(j,y)) & \defeq \sm{e:\edg{A}(i,j)} \edg{D}(e,x)=y \\
\rfx{\msm{\mathcal{A}}{\mathcal{D}}}((i,x)) & \defeq (\rfx{\mathcal{A}}(i),\rfx{\mathcal{D}}(i,x)).
\end{align*}
There is an obvious projection $\proj 1 : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{D}},\mathcal{A})$.
\end{defn}

\begin{lem}
For any diagram $\mathcal{D}$ over $\mathcal{A}$, the projection $\proj 1 : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{D}},\mathcal{A})$ is a left fibration.
\end{lem}

\begin{proof}
It suffices to show that
\begin{equation*}
\begin{tikzcd}
\sm{(i,x),(j,y):\pts{\msm{\mathcal{A}}{\mathcal{D}}}} \edg{\msm{\mathcal{A}}{\mathcal{D}}}((i,x),(j,y)) \arrow[r,"\pi_1"] \arrow[d] & \msm{\mathcal{A}}{\mathcal{D}} \arrow[d] \\
\sm{i,j:\pts{A}}\edg{A}(i,j) \arrow[r,swap,"\pi_1"] & \pts{A}
\end{tikzcd}
\end{equation*}
is a pullback square. Note that this square is equivalent to the square
\begin{equation*}
\begin{tikzcd}[column sep=6em]
\sm{i,j:\pts{A}}{e:\edg{A}(i,j)}\pts{D}(i) \arrow[r,"{\lam{(i,j,e,x)}(i,x)}"] \arrow[d] & \sm{i:\pts{A}}\pts{D}(i) \arrow[d] \\
\sm{i,j:\pts{A}}\edg{A}(i,j) \arrow[r,swap,"\pi_1"] & \pts{A},
\end{tikzcd}
\end{equation*}
which is clearly a pullback square.
\end{proof}

\begin{rmk}
It can be shown that the total graph operation is an equivalence from diagrams over $\mathcal{A}$ to left fibrations over $\mathcal{A}$.
\end{rmk}

\begin{defn}
Let $D$ be a diagram over $\mathcal{A}$, and let $X$ be a type. A $D$-cocone on $X$ is a morphism $f:\mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{D}},\Delta X)$ of reflexive graphs. A $D$-cocone $f$ on $X$ is colimiting if the map
\begin{equation*}
\Delta(\blank)\circ f : (X\to Y)\to \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{D}},\Delta Y)
\end{equation*}
is an equivalence for every type $Y$.
\end{defn}

\begin{rmk}
By \cref{thm:rcoeq_is_pushout} it follows that every diagram $D$ over any reflexive graph $\mathcal{A}$ has a colimit.
\end{rmk}

\begin{defn}
Let $\mathcal{D}$ and $\mathcal{D}'$ be diagrams over $\mathcal{A}$. A \define{natural transformation} $\tau : \mathcal{D}'\to \mathcal{D}$ of diagrams consists of
\begin{align*}
\pts{\tau} & : \prd{i:\pts{A}}\pts{D'}(i)\to\pts{D}(i) \\
\edg{\tau} & : \prd*{i,j:\pts{A}}{e:\edg{A}(i,j)}\prd{x:\pts{D}(i)}\pts{\tau}(\edg{D'}(e,x))=\edg{D}(e,\pts{\tau}(x)) \\
\rfx{\tau} & : \prd{i:\pts{A}}{x:\pts{D}(i)} \dpath{}{}{\edg{\tau}(\rfx{A}(i),x)}{\refl{\pts{\tau}(x)}}
\end{align*}
A natural transformation $\tau:\mathcal{D}'\to \mathcal{D}$ of diagrams over $\mathcal{A}$ is said to be \define{cartesian} if the commutative squares
\begin{equation*}
\begin{tikzcd}[column sep=large]
\pts{D'}(i) \arrow[r,"{\edg{D'}(e)}"] \arrow[d,swap,"\pts{\tau}(i)"] & \pts{D'}(j) \arrow[d,"\pts{\tau}(j)"] \\
\pts{D}(i) \arrow[r,swap,"{\edg{D}(e)}"] & \pts{D}(i)
\end{tikzcd}
\end{equation*}
are all pullback squares.
%We will write $D'\mathbin{\to_\times}D$ for the type of cartesian natural transformations from $D'$ to $D$.
\end{defn}

We will use the following general fact about pullbacks.

\begin{prp}\label{lem:pb_total}
Let $I$ be a type, and consider for each $i:I$ a commuting square
\begin{equation*}
\begin{tikzcd}
C_i \arrow[r,"q_i"] \arrow[d,swap,"p_i"] & B_i \arrow[d,"g_i"] \\
A_i \arrow[r,swap,"f_i"] & X_i.
\end{tikzcd}
\end{equation*}
with $H_i:f_i\circ p_i\htpy g_i\circ q_i$. Then the following are equivalent:
\begin{enumerate}
\item For each $i:I$, the square is a pullback square.
\item The induced square on total spaces
\begin{equation*}
\begin{tikzcd}
\sm{i:I}C_i \arrow[r,"\total{q}"] \arrow[d,swap,"\total{p}"] & \sm{i:I}B_i \arrow[d,"\total{g}"] \\
\sm{i:I}A_i \arrow[r,swap,"\total{f}"] & \sm{i:I}X_i.
\end{tikzcd}
\end{equation*}
which commutes via the homotopy $\total{H}:\total{f}\circ\total{p}\htpy\total{g}\circ\total{q}$, is a pullback square.
\end{enumerate}
\end{prp}

\begin{proof}
The gap map of the square in assertion (ii) factors as follows:
\begin{equation*}
\begin{tikzcd}[column sep=small]
\phantom{\Big(\sm{i:I}A_i\Big)\times_{\big(\sm{i:I}X_i\big)} \Big(\sm{i:I}B_i\Big)} & \sm{i:I}C_i \arrow[dl,swap,"\total{\mathsf{gap}(p_i,q_i,H_i)}"] \arrow[dr,"{\mathsf{gap}(\total{p},\total{q},\total{H})}"] \\
\sm{i:I}A_i\times_{X_i}B_i \arrow[rr,swap,"{\lam{(i,a,b,p)}((i,a),(i,b),(\refl{i},p))}"] & & \Big(\sm{i:I}A_i\Big)\times_{\big(\sm{i:I}X_i\big)} \Big(\sm{i:I}B_i\Big)
\end{tikzcd}
\end{equation*}
and the bottom map is an equivalence. Therefore it follows by the 3-for-2 property and an application of \cref{thm:fib_equiv} that $\mathsf{gap}(p_i,q_i,H_i)$ is an equivalence for each $i:I$, if and only if $\mathsf{gap}(\total{p},\total{q},\total{H})$ is an equivalence.
\end{proof}

\begin{prp}\label{prp:nattrans_cartesian}
Let $\tau:\mathsf{nat}(\mathcal{E},\mathcal{D})$ be a natural transformation of diagrams over $\mathcal{A}$. Then $\tau$ is cartesian if and only if the induced morphism of reflexive graphs
\begin{equation*}
\total{\tau} : \mathsf{rGph}(\msm{\mathcal{A}}{\mathcal{E}},\msm{\mathcal{A}}{\mathcal{D}})
\end{equation*}
is cartesian.
\end{prp}

\begin{proof}
Straightforward consequence of \cref{lem:pb_total}.
\end{proof}

\begin{cor}
Let $\tau:\mathsf{cart}(\mathcal{E},\mathcal{D})$ be a cartesian morphisms of diagrams over $\mathcal{A}$, and consider a commuting square of reflexive graphs of the following form
\begin{equation*}
\begin{tikzcd}
\msm{\mathcal{A}}{\mathcal{E}} \arrow[d,swap,"\mathsf{tot}(\tau)"] \arrow[r] & \Delta Y \arrow[d] \\
\msm{\mathcal{A}}{\mathcal{D}} \arrow[r] & \Delta X.
\end{tikzcd}
\end{equation*}
Then the following are equivalent:
\begin{enumerate}
\item The square is a pullback square.
\item The square
\begin{equation*}
\begin{tikzcd}
\mathsf{colim}(\mathcal{E}) \arrow[r] \arrow[d,swap,"\mathsf{colim}(\tau)"] & Y \arrow[d] \\
\mathsf{colim}(\mathcal{D}) \arrow[r] & X
\end{tikzcd}
\end{equation*}
is a pullback square.
\end{enumerate}
\end{cor}

\section{Sequential colimits}

Type sequences are diagrams of the following form.
\begin{equation*}
\begin{tikzcd}
A_0 \arrow[r,"f_0"] & A_1 \arrow[r,"f_1"] & A_2 \arrow[r,"f_2"] & \cdots.
\end{tikzcd}
\end{equation*}
Their formal specification is as follows.

\begin{defn}
An \define{(increasing) type sequence} $\mathcal{A}$ consists of
\begin{align*}
A & : \N\to\UU \\
f & : \prd{n:\N} A_n\to A_{n+1}.
\end{align*}
\end{defn}

Sequential colimits are characterized by their universal property.

\begin{defn}
\begin{enumerate}
\item A \define{(sequential) cocone} on a type sequence $\mathcal{A}$ with vertex $X$ consists of
\begin{align*}
h & : \prd{n:\N} A_n\to X \\
H & : \prd{n:\N} f_n\htpy f_{n+1}\circ H_n.
\end{align*}
We write $\mathsf{cocone}(X)$ for the type of cones with vertex $X$.
\item Given a cone $(h,H)$ with vertex $X$ on a type sequence $\mathcal{A}$ we define the map
\begin{equation*}
\mathsf{cocone\usc{}map}(h,H) : (X\to Y)\to \mathsf{cocone}(X)
\end{equation*}
given by $f\mapsto (f\circ h,\lam{n}{x}\mathsf{ap}_f(H_n(x)))$.
\item We say that a cone $(h,H)$ with vertex $X$ is \define{colimiting} if the map $\mathsf{cocone\usc{}map}(h,H)$ is an equivalence for any type $Y$.
\end{enumerate}
\end{defn}

In order to study sequential colimits, we first note that type sequences appear as diagrams over the graph $(\N,\prec)$ with type of vertices $\N$, and with
\begin{equation*}
(n\prec m) \defeq (n+1=m).
\end{equation*}
Note that this is a non-reflexive graph. A reflexive graph is obtained by the adjunction explained in \cref{eg:freerfx} of \cref{eg:rgraph_morphism}, which transforms the relation $\prec$ into the reflexive relation $\preceq$ given by
\begin{equation*}
(n\preceq m) \defeq (n+1=m)+ (n=m).
\end{equation*}
A diagram $\mathcal{A}$ on $(\N,\prec)$ consists of
\begin{equation*}
\pts{A} : \prd{n:\N} A_n \\
\edg{A} : \prd{n,m:\N}{e:n+1=m} A_n\to A_m.
\end{equation*}
Note that the type of $\edg{A}$ is equivalent to the type $\prd{n:\N}A_n\to A_{n+1}$, so we see indeed that type sequences are equivalently described as diagrams over $(\N,\prec)$. Similarly, a sequential cocone on $\mathcal{A}$ with vertex $X$ is equivalently described as a cocone on the diagram $\mathcal{A}$ with vertex $X$. Thus, we also have the following:

\begin{lem}\label{thm:sequential_up}
Consider a cocone $(h,H)$ with vertex $B$ for a type sequence $\mathcal{A}$. The following are equivalent:
\begin{enumerate}
\item The cocone $(h,H)$ is colimiting.
\item The cocone $(h,H)$ is inductive in the sense that for every type family $P:B\to \UU$, the map
\begin{align*}
\Big(\prd{b:B}P(b)\Big)\to {}& \sm{h:\prd{n:\N}{x:A_n}P(h_n(x))}\\
& \qquad \prd{n:\N}{x:A_n} \mathsf{tr}_P(H_n(x),h_n(x))={h_{n+1}(f_n(x))}
\end{align*}
given by
\begin{equation*}
s\mapsto (\lam{n}s\circ h_n,\lam{n}{x} \mathsf{apd}_{s}(H_n(x)))
\end{equation*}
has a section.
\item The map in (ii) is an equivalence.\qedhere
\end{enumerate}
\end{lem}

\begin{defn}
The type of \define{descent data} on a type sequence $\mathcal{A}\jdeq (A,f)$ is defined to be
\begin{equation*}
\mathsf{Desc}(\mathcal{A}) \defeq \sm{B:\prd{n:\N}A_n\to\UU}\prd{n:\N}{x:A_n}\eqv{B_n(x)}{B_{n+1}(f_n(x))}.
\end{equation*}
Equivalently, if $\mathcal{A}$ is seen as a diagram over $(\N,\prec)$,
\end{defn}

\begin{defn}
We define a map
\begin{equation*}
\mathsf{desc\usc{}fam} : (A_\infty\to\UU)\to\mathsf{Desc}(\mathcal{A})
\end{equation*}
by $B\mapsto (\lam{n}{x}B(\mathsf{seq\usc{}in}(n,x)),\lam{n}{x}\mathsf{tr}_B(\mathsf{seq\usc{}glue}(n,x)))$.
\end{defn}

\begin{thm}
The map
\begin{equation*}
\mathsf{desc\usc{}fam} : (A_\infty\to\UU)\to\mathsf{Desc}(\mathcal{A})
\end{equation*}
is an equivalence.
\end{thm}

\begin{defn}
A \define{cartesian transformation} of type sequences from $\mathcal{A}$ to $\mathcal{B}$ is a pair $(h,H)$ consisting of
\begin{align*}
h & : \prd{n:\N} A_n\to B_n \\
H & : \prd{n:\N} g_n\circ h_n \htpy h_{n+1}\circ f_n,
\end{align*}
such that each of the squares in the diagram
\begin{equation*}
\begin{tikzcd}
A_0 \arrow[d,swap,"h_0"] \arrow[r,"f_0"] & A_1 \arrow[d,swap,"h_1"] \arrow[r,"f_1"] & A_2 \arrow[d,swap,"h_2"] \arrow[r,"f_2"] & \cdots \\
B_0 \arrow[r,swap,"g_0"] & B_1 \arrow[r,swap,"g_1"] & B_2 \arrow[r,swap,"g_2"] & \cdots
\end{tikzcd}
\end{equation*}
is a pullback square. We define
\begin{align*}
\mathsf{cart}(\mathcal{A},\mathcal{B}) & \defeq\sm{h:\prd{n:\N}A_n\to B_n} \\
& \qquad\qquad \sm{H:\prd{n:\N}g_n\circ h_n\htpy h_{n+1}\circ f_n}\prd{n:\N}\mathsf{is\usc{}pullback}(h_n,f_n,H_n),
\end{align*}
and we write
\begin{equation*}
\mathsf{Cart}(\mathcal{B}) \defeq \sm{\mathcal{A}:\mathsf{Seq}}\mathsf{cart}(\mathcal{A},\mathcal{B}).
\end{equation*}
\end{defn}

\begin{defn}
We define a map
\begin{equation*}
\mathsf{cart\usc{}map}(\mathcal{B}) : \Big(\sm{X':\UU}X'\to X\Big)\to\mathsf{Cart}(\mathcal{B}).
\end{equation*}
which associates to any morphism $h:X'\to X$ a cartesian transformation of type sequences into $\mathcal{B}$.
\end{defn}

\begin{thm}
The operation $\mathsf{cart\usc{}map}(\mathcal{B})$ is an equivalence.
\end{thm}

The flattening lemma for sequential colimits essentially states that sequential colimits commute with $\Sigma$.

\begin{lem}
Consider
\begin{align*}
B & : \prd{n:\N}A_n\to\UU \\
g & : \prd{n:\N}{x:A_n}\eqv{B_n(x)}{B_{n+1}(f_n(x))}.
\end{align*}
and suppose $P:A_\infty\to\UU$ is the unique family equipped with
\begin{align*}
e & : \prd{n:\N}\eqv{B_n(x)}{P(\mathsf{seq\usc{}in}(n,x))}
\end{align*}
and homotopies $H_n(x)$ witnessing that the square
\begin{equation*}
\begin{tikzcd}[column sep=7em]
B_n(x) \arrow[r,"g_n(x)"] \arrow[d,swap,"e_n(x)"] & B_{n+1}(f_n(x)) \arrow[d,"e_{n+1}(f_n(x))"] \\
P(\mathsf{seq\usc{}in}(n,x)) \arrow[r,swap,"{\mathsf{tr}_P(\mathsf{seq\usc{}glue}(n,x))}"] & P(\mathsf{seq\usc{}in}(n+1,f_n(x)))
\end{tikzcd}
\end{equation*}
commutes. Then $\sm{t:A_\infty}P(t)$ satisfies the universal property of the sequential colimit of the type sequence
\begin{equation*}
\begin{tikzcd}
\sm{x:A_0}B_0(x) \arrow[r,"{\total[f_0]{g_0}}"] & \sm{x:A_1}B_1(x) \arrow[r,"{\total[f_1]{g_1}}"] & \sm{x:A_2}B_2(x) \arrow[r,"{\total[f_2]{g_2}}"] & \cdots.
\end{tikzcd}
\end{equation*}
\end{lem}

In the following theorem we rephrase the flattening lemma in using cartesian transformations of type sequences.

\begin{thm}
Consider a commuting diagram of the form
\begin{equation*}
\begin{tikzcd}[column sep=small,row sep=small]
A_0 \arrow[rr] \arrow[dd] & & A_1 \arrow[rr] \arrow[dr] \arrow[dd] &[-.9em] &[-.9em] A_2 \arrow[dl] \arrow[dd] & & \cdots \\
& & & X \arrow[from=ulll,crossing over] \arrow[from=urrr,crossing over] \arrow[from=ur,to=urrr] \\
B_0 \arrow[rr] \arrow[drrr] & & B_1 \arrow[rr] \arrow[dr] & & B_2 \arrow[rr] \arrow[dl] & & \cdots \arrow[dlll] \\
& & & Y \arrow[from=uu,crossing over]
\end{tikzcd}
\end{equation*}
If each of the vertical squares is a pullback square, and $Y$ is the sequential colimit of the type sequence $B_n$, then $X$ is the sequential colimit of the type sequence $A_n$.
\end{thm}

\begin{cor}
Consider a commuting diagram of the form
\begin{equation*}
\begin{tikzcd}[column sep=small,row sep=small]
A_0 \arrow[rr] \arrow[dd] & & A_1 \arrow[rr] \arrow[dr] \arrow[dd] &[-.9em] &[-.9em] A_2 \arrow[dl] \arrow[dd] & & \cdots \\
& & & X \arrow[from=ulll,crossing over] \arrow[from=urrr,crossing over] \arrow[from=ur,to=urrr] \\
B_0 \arrow[rr] \arrow[drrr] & & B_1 \arrow[rr] \arrow[dr] & & B_2 \arrow[rr] \arrow[dl] & & \cdots \arrow[dlll] \\
& & & Y \arrow[from=uu,crossing over]
\end{tikzcd}
\end{equation*}
If each of the vertical squares is a pullback square, then the square
\begin{equation*}
\begin{tikzcd}
A_\infty \arrow[r] \arrow[d] & X \arrow[d] \\
B_\infty \arrow[r] & Y
\end{tikzcd}
\end{equation*}
is a pullback square.
\end{cor}


\documentclass[10pt]{article}

\usepackage{hyperref}
\usepackage{fullpage, graphicx, color, transparent, colortbl}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{textcomp}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}[section]

\def\compactify{\itemsep=0pt \topsep=0pt \partopsep=0pt \parsep=0pt}
\let\latexusecounter=\usecounter
\newenvironment{CompactItemize}
  {\def\usecounter{\compactify\latexusecounter}
   \begin{itemize}}
  {\end{itemize}\let\usecounter=\latexusecounter}
\newenvironment{CompactEnumerate}
  {\def\usecounter{\compactify\latexusecounter}
   \begin{enumerate}}
  {\end{enumerate}\let\usecounter=\latexusecounter}

\title{HashPipe Analysis}

\begin{document}
\maketitle

\section{Setup}

We can think of two conceptual models to analyze heavy-hitter detection
algorithms: the aggregate model and the cash-register model. In the aggregate
model, all packets of a flow arrive in one shot, while in the cash-register
model, the packets of different flows can interleave. In both models, flows can
arrive in any arbitrary order.

The switch has $d$ stages, where the algorithm can probe $l$ locations in
parallel at each stage. We desire to find the top $k$ heavy hitters using $m$
memory overall, such that $m \geq k$ and $m \in O(k)$. Denote the set of the top
$r$ items in the stream
by $S_r$. We wish to determine the set $S_k$ at the end of processing all items.

\section{Aggregate model with $d=1$ and $l=1$}

\begin{theorem}
  With probability $> 1/2$, an item $j \in S_{k/2}$ is in the data structure
  after all items have been processed.
\end{theorem}
\begin{proof}
  Consider an item $j \in S_{k/2}$ that hashes to location $i$. Regardless of
  the order of the items, the probability $p$ that none of the heavier items
  hashed to the same location $i$ is $(1 - 1/m)^r$, where $r$ is the number of
  items heavier than $j$. Since $r \leq k/2$, $p \geq (1 - 1/m)^{k/2}$. If $m$ is
  set to $k$, then $p \geq (1 - 1/k)^{k/2} \geq (1/e)^{1/2} > 1/2$.
\end{proof}

This bound can be strengthened either by increasing the amount of available
memory per stage, e.g., by making $m \in O(k)$ instead of strictly $k$, or
increasing the number of probes per stage $l$. We look at the latter (less
obvious) case next.

\section{Aggregate model with $d=1$ and $l>1$}

The algorithm here is to look at $l$ locations in the table for each incoming
flow. We evict the item with the minimum count among the $l$ items and the
incoming item. Let the count associated with item $j$ be $val_j$. When item $i$
is inserted, let $n_i$ denote the number of items in the data structure whose
count is higher than $val_j$.

The main challenge with the $l > 1$ case is that the order of item arrivals
seems to matter in a nonobvious way: if more heavier items are in the data
structure before item $j$ is inserted, $j$ may not be inserted. But if $j$ is
inserted, it is more likely to stay in the data structure since there are fewer
heavier items that may evict it in future.

\begin{theorem}
  \label{thm:staying-after-entering}
  Given that item $j \in S_{k/2}$ enters the data structure, the chance that it
  stays in the data structure after processing all items is $\geq e^{-1/2^l}$.
\end{theorem}
\begin{proof}
  Suppose item $j$ is already in the data structure. For each item $i$ inserted
  afterward, the probability that $i$ evicts $j$ is given by $(1/m) \cdot
  (n_i/m)^{l-1}$, corresponding to $i$ hashing to the location of $j$, and also
  independently hashing $l-1$ times to one of the $n_i$ locations with value
  $\geq val_j$. Suppose there are $r$ items in the overall data stream with
  value $\geq val_j$. Then the probability $p$ that item $j$ stays in the data
  structure after being inserted is $(1 - (1/m) \cdot (n_i/m)^{l-1})^r \geq (1 -
  (1/m) \cdot (n_i/m)^{l-1})^{k/2}$, since $r \leq k/2$.  We also have $m \geq
  k$ and $n_i \leq k/2$. Then $p \geq (1 - (1/m) \cdot 1/2^{l-1})^{k/2} \geq
  e^{-1/2^l}$.
\end{proof}

\begin{theorem}
  \label{thm:entering-the-ds}
  The probability that an item $j \in S_{k/2}$ is inserted into the data
  structure is $\geq (1 - 1/2^l)$.
\end{theorem}
\begin{proof}
Let $n_j$ denote the number of items with counts greater than $val_j$ at the
time of inserting $j$. Then the only event when $j$ cannot get into the data
structure is when all of its $l$ probed locations have counts higher than
$val_j$. This happens with probability $(n_j/m)^l \leq 1/2^l$ since $n_j < k/2$
and $m \geq k$. Hence, $j$ enters the data structure with probability $\geq 1 -
1/2^l$.
\end{proof}

\begin{theorem}
  \label{thm:aggregate-d1}
  With probability $\geq (1 - 1/2^l) \cdot e^{-1/2^l}$, an item $j \in S_{k/2}$ is
  in the data structure after all items have been processed.
\end{theorem}
\begin{proof}
An item $j$ is in the data structure after processing all items if (i) it enters
the data structure on arrival, and (ii) stays without being evicted after. By
Bayes rule, this probability is $P(\mathrm{enters}) \cdot
P(\mathrm{not\ evicted\ after\ entry})$, and we can complete the proof using
theorems \ref{thm:staying-after-entering} and \ref{thm:entering-the-ds}.
\end{proof}

\section{Aggregate model with true minimum over $d > 1$ stages ($l=1$)}

The algorithm here is to look at $l=1$ location in each stage upon inserting an
item, and evict the minimum-valued item among the $d+1$ items. The memory $m$ is
partitioned uniformly across the $d$ stages.

\begin{theorem}
  With probability $\geq d \cdot e^{-d/2}$, an item $j \in S_{k/2}$ is in the
  data structure after all items have been processed.
\end{theorem}

\begin{proof}
Let $A_i$ denote an indicator variable for the event that item $j \in S_{k/2}$
is in table $i$ after processing all items. Then item $j$ is in the data
structure if it is in any one of the $0, \ldots, d$ stages. Suppose $A$ is an
indicator variable for the event that item $j$ is in one of the $d$ stages after
processing all items. Since the algorithm ensures that an item is present in at
most one stage, we have $A = A_1 + \cdots + A_d$.

Any one stage has memory $k/d$. Consider a stage $i$ {\em in isolation}, i.e.,
assuming it is the only table available to process the incoming items. The
probability that item $j \in S_{k/2}$ is in table $i$ after all items have been
processed is $\geq (1 - (1/m) \cdot (n_i/m)^{l-1})^{k/2} \geq (1 -
1/(k/d))^{k/2} \geq e^{-d/2}$ since $l=1$ and the available memory is
$k/d$.\footnote{From the most general expressions of theorems
  \ref{thm:staying-after-entering} and \ref{thm:entering-the-ds}, this
  probability should also be multiplied by $1 - (n_i/m)^l \geq 1 - (d/2)^l$,
  which may be a negative number. This makes the result look weird; we should
  check this.}

Since the $A_i$'s and $A$ are indicator variables, their expectation is equal to
the probability of the indicated event. Hence, $E[A_i]$ ({\em in isolation from
  other stages}) is $\geq e^{-d/2}$. {\em Suppose we can use this value as the
  expectation of $A_i$ more generally, despite the presence of other
  stages}.\footnote{This claim must be proved.} Then, by linearity of
expectation, we have $E[A] = E[A_1] + \cdots + E[A_d] \geq d \cdot
e^{-d/2}$. This is the probability of the indicated event, i.e., item $j \in
S_{k/2}$ is in one of the $d$ stages after all items are processed.

\end{proof}

\end{document}


\documentclass[a4paper,12pt]{article}

% Font
\usepackage[T1]{fontenc}
\usepackage{gentium}

% Math packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{bm}

% Define symbol shortcuts
\newcommand{\cc}{\mathcal{C}}
\newcommand{\dd}{\mathcal{D}}
\newcommand{\hh}{\mathcal{H}}
\newcommand{\xx}{{\bm x}}
\newcommand{\yy}{{\bm y}}
\newcommand{\ww}{{\bm w}}

% Math environment
\newtheorem*{thm}{Theorem}

% Better list management:
% - vertical spacing in lists
% - items in lists start with dash not bullet point.
\usepackage{enumitem}
\setlist{label=\textemdash,
  itemsep=0pt, topsep=3pt, partopsep=0pt}

% Include graphics
\usepackage{graphicx}
\usepackage{subcaption}

% Page format
\usepackage[top=2cm,left=2cm,right=2cm,bottom=2cm]{geometry}

\begin{document}
%%% HEADER
\raisebox{0.6in}[0in]{\makebox[\textwidth][r]{\it Unproofed version }}
\vspace{-0.7in}

\begin{center}
\bf\large MA2823: Foundations of Machine Learning \\
Chapter 10: Artificial Neural Networks
\end{center}

\noindent
Lecturer: Chlo\'e-Agathe Azencott
\hfill
Scribe: Meryll Dindin, Horace Guy

\noindent
\rule{\textwidth}{1pt}

\medskip

%%% NOTES START HERE

\section{Introduction to human brain :}

\indent
The motivation of neural networks comes from the humain brain. Our brain is made out of neurons, communicating through axones ($10^{10}$ neurons and $10^4$ connections). We recognize the advantages of parallel processing, distributed computation and memory, but it is also all about a robust system to noise and failures. To classify pictures thanks to a neural network will work the same way as our brain does, to identify features and be able to recognize the same time of pictures afterwards.

\section{Perceptron}

\indent
The model of perceptron has been introduced in 1958 thanks to Rosenblatt. The model presents layers : a labeled input, weighted connections and an output. It is a {\bfseries parametric model}, since we know, before running the model, the shape of the model. Here it is a linear combination of the defined weights for each connection.

\vspace{0.1in}

\centerline{The model function looks like : $f(\xx) = \sum_{j=1}^p w_j x_j + w_0 = \ww^T \cdot \xx$ }

\vspace{0.1in}

\indent
Concerning the shape of the decision boundary, it is a {\bfseries hyperplane}, as it is the case for {\itshape linear regression}. If we now want to output the probability of belonging to the positive class, we apply a {\bfseries logistic function}. An example of it is the {\itshape sigmoid function} defined below :

\[\sigma(u) = \frac{1}{1+exp(-u)}\]

\begin{figure}[!ht]
\centerline{\includegraphics[width=0.5\textwidth]{./figures/sigmoid_fun.png}}
\end{figure}

\indent
To conclude with a short summary :
\begin{itemize}
	\item Regression : \[f(\xx) = \ww \cdot \xx + w_0\]
	\item Classification : \[ f(\xx) = s( \ww ^T\xx) = s (w_0 + \sum_{j=1}^p w_j x_j ) \]
knowing $s(o(\xx)) = \mathbb{I}_{o(\xx) > 0}$
\end{itemize}

\begin{figure}[!ht]
\centerline{\includegraphics[width=0.5\textwidth]{./figures/multicl_1lay_per.png}}
\end{figure}
\centerline{\footnotesize{Multi-Class One Layer Perceptron}}

\vspace{0.1in}

\indent
For multiclass classification, the model is similar except for the specificity that we will rather use K output units. For each class, we reason as a binary decision (does it belong to the class or not). To get probabilities, you may use the {\bfseries softmax} function, which is similar to the maximum, except that it is differentiable. If the output for one class is sufficiently larger than for the others, its softmax output will be close to 1.

\vspace{0.1in}

\[  f_k(\xx) =  \frac{\exp(o_k)}{\sum_{l=1}^K \exp(o_l)} \text{ with } o_k = \ww ^{kT} \cdot \xx \]

Then we choose the class $C_k$ if $f_k(\xx) = \max_{l \in [1,K]} f_l(\xx) $
\section{Training a perceptron}

\indent
You generally have two possibilities : {\bfseries online learning}, which roam every instances one by one, and the {\bfseries batch learning}, that consider all the data-set in a whole. It is a flexible model, that may adapt to a changing problem over time. As a consequence comes the {\bfseries generic update rule} which means that everytime we have a new training instance, each weight get updated, taking into account the previously established weights $w_j \leftarrow w_j + \Delta w_j $. The update term can be computed as follow, knowing the error function $Error(f(\xx^i),y^i)$ and setting (arbitrary) the \emph{learning rate} $\eta$ :

\[ \Delta w_j = - \eta \frac{\partial Error(f(\xx^i), y^i)}{\partial w_j} \]

We will see that in each of the following cases, which present different error functions, this expression simplifies to the same form :

\[ \Delta w_j = \eta (y^i - f(\xx^i) ) x_j^i \]

\vspace{0.1in}

\paragraph*{Regression}
Having $Error(f(\xx^i),y^i) = \frac{1}{2} (y^i - f(\xx^i))^2 = \frac{1}{2} (y^i - \ww ^T \xx^i)^2$, that leads to the above-stated formula.

\paragraph*{Classification}
We introduce the sigmoid output $\sigma (u) = \frac{1}{1 + \exp(-u)}$ which derives as $\sigma'(u) = u'\sigma (u) (1 - \sigma(u))$ ; $f$ expresses then as $f(\xx^i) = \sigma (\ww^T\xx^i) $.
We then use the cross-entropy error, which has the same purpose than the error function established for the regression case

\[ Error(f(\xx^i), y^i) = -y^i \log f(\xx^i) - (1-y^i) \log (1-f(\xx^i)) \]

\paragraph*{K classes}
With the definition of the softmax outputs stated in section 2, we can compute the Cross-entropy error :
\[ Error(f(\xx^i), y^i) = - \sum_{k=1}^K y_k^i \log f_k(\xx^i) \]

\indent
We observe that the generic rule for regression is exactly the same than for the classification model. To make it simple : the update rule is equal to the learning rate times the difference between the desired output and the actual output times the input. It comes to mind that if the desired output is equal to the actual output, there will be no change. But if they're not, the predictions will get less accurate.

\indent
Still, it has limitations. It can learn the logical AND but not the logical XOR (because data cannot be separated by a hyperplane). This is considered as a very limitated model.

\begin{figure}[!ht]
\centerline{\includegraphics[width=0.4\textwidth]{./figures/perceptron_AND.png}}
\end{figure}
\centerline{\footnotesize{Learning of the logical operator AND, with a single layer perceptron.}}
\vspace{0.1in}

\indent
To quote Minsky and Papert in 1969 : {\itshape"The perceptron has shown itself worthy of study despite (and even because of!) its severe limitations. It has many features to attract attention: its linearity; its intriguing learning theorem; its clear paradigmatic simplicity as a kind of parallel computation. There is no reason to suppose that any of these virtues carry over to the many-layered version. Nevertheless, we consider it to be an important research problem to elucidate (or reject) our intuitive judgement that the extension to multilayer systems is sterile."}

\section{Multilayer Perceptrons}

\indent
Every node of the hidden layer is the output of a sigmoid perceptron. Then the output of the entire model is a linear combination of the different sigmoid perceptrons, which makes it non-linear in x ! We then came from a linear model and ended up with a non-linear model. As a consequence, the logical XOR can be learned !

{\bfseries Universal Approximation :} Any continuous function on a compact subset of $\mathbb{R}^n$ can be approximated to any arbitrary degree of precision by a feed-forward multi-layer perceptron with a single hidden layer containing a finite number of neurons.

\newpage

\begin{figure}[!ht]
\centerline{\includegraphics[width=0.7\textwidth]{./figures/XOR_learn.png}}
\end{figure}
\centerline{\footnotesize{Learning of the logical operator XOR.}}

\vspace{0.1in}

\subsection{Backpropagation}

\indent
This is one of the most powerful tool in deep-learning. The question of who invented it is still being discussed.

\vspace{0.1in}

\indent
Backpropagation, an abbreviation for "backward propagation of errors", is a common method of training artificial neural networks used in conjunction with an optimization method such as gradient descent. It calculates the gradient of a loss function with respect to all the weights in the network, so that the gradient is fed to the optimization method which in turn uses it to update the weights, in an attempt to minimize the loss function.

\vspace{0.1in}

{\itshape Source : https://en.wikipedia.org/wiki/Backpropagation}

\vspace{0.1in}

\indent
This method may be used for binary model or multiclass perceptron. The mathematics hidden behind this process may be summed up in the following lines :

\[ z_h = \frac{1}{1+e^{- \ww_h^T \cdot \xx}}\]
\[ f(\xx) = v^T \cdot \xx = v_0 + \sum_{h=1}^H \frac{v_h}{1+e^{- \ww_h^T \cdot \xx}} \]
\[ \frac{\partial E}{\partial w_{h_j}} = \frac{\partial E}{\partial f(\xx)} \cdot \frac{\partial f(\xx)}{\partial z_h} \cdot \frac{\partial z_h}{\partial  w_{h_j}} \]

\vspace{0.1in}

\indent
Concerning the generic update rule, we obtain, thanks to the previously exposed formulas the next updated weights :

\begin{itemize}
\item {\bfseries Regression :}
\[ \Delta w_{jh} = -\eta \frac{\partial E^i}{\partial w_{jh}} = -\eta (y^i - f(\xx^i)) v_h z_h^i (1 - z_h^i) x_j^i \]
\item {\bfseries Classification :}
\[ \Delta w_{jh} = - \eta \frac{\partial E^i}{\partial w_{jh}} = \eta \sum_{i=1}^n (y^i - f(\xx^i)) v_h z_h^i (1 - z_h^i) x_j^i \]
\item {\bfseries K Classes :}
\[ \Delta w_{jh} = - \eta \frac{\partial E^i}{\partial w_{jh}} = \eta \sum_{i=1}^n \left( \sum_{k=1}^K (y_k^i - f_k(\xx^i)) v_{kh} \right) z_h^i (1 - z_h^i) x_j^i \]
\end{itemize}

\subsection{Deep-Learning}

\indent
Deep-learning can then be introduced thanks to hidden multilayers perceptrons. The more the hidden layers, the more complex and 'deep' is the learning.

\section{Neural Network Magic}

\indent
The architecture is the following : Start with one hidden layer, stop adding layers when you're overfitting, never use more weights than training samples ! Concerning the {\bfseries weight sharing}, different units may have connections to different inputs but may be sharing the same weights. Another flexibility remain in modifying the {\bfseries network size}, in a destructive or constructive way, as much as {\bfseries overtraining} is.

\begin{figure}[!ht]
\centerline{\includegraphics[width=0.7\textwidth]{./figures/growing_netw.png}}
\end{figure}
\centerline{\footnotesize{Growing network until satisfactory error rate is reached.}}

\vspace{0.1in}

\indent
There exist a lot of optimization algorithms : {\bfseries Batch Learning} where the weights are updated after a complete pass over the training set, {\bfseries Mini-Batch Learning} where the weights are updates after a pass over a set of training points of fixed size, Quasi-Newton Methods (Levenberg-Marquardt), Conjugate Gradient Descent, ... But still, {\bfseries neural newtorks are hard to train}, and they imply a lot of methods to be implemented, such as {\itshape preconditionning} that standardizes inputs and targets, initializes weights carefully to avoid saturation (implied by large weigths) and uses local learning rates

\subsection{For fun :}

Playing with a neural network :
\vspace{0.1in}
\centerline{http://playground.tensorflow.org/}
\vspace{0.1in}

\end{document}


% !TeX spellcheck = en_US
\section{Conclusion}\label{sec:conclusion}
We discussed some mappings between the constraint satisfaction problem (CSP) and the Boolean satisfiability problem (SAT). Some theoretical background has been introduced and based on general comparing criterion the encodings have been analyzed and compared against each other. It has been shown that the choice of an encoding has a large impact on the efficiency and solvability of the generated problem. Encoding CSP into simpler SAT problem has led to efficient instances of the original problem that can be solved quickly. This claim was supported with theoretical arguments and proofs specially in the case of some tractable CSP classes encoded using the order encoding. Based on similar encoding techniques various new SAT-based constraint solves have been developed. On the other hand, a variety of SAT to CSP encodings have been introduced. Although no SAT to CSP encoding has proven itself to be superior, a clearer picture of the relation between CSP and SAT has emerged and further studies can build upon these results.