\documentclass{article}
\input{packages}
\input{def}

\lecture{2-Categories}

\begin{document}
\maketitle

\begin{definition}[2-Category]
A $\cat{Cat}$-enriched category.
\end{definition}

\begin{remark}
The objects of a 2-category are called objects or 0-cells.
Given two objects $\ob{C}_1$ and $\ob{C}_2$, the objects of the category $\cat{M}(\ob{C}_1,\ob{C}_2)$ are called the morphisms or 1-cells of the 2-category.
Given two objects $\ob{C}_1$ and $\ob{C}_2$, the morphisms of the category $\cat{M}(\ob{C}_1,\ob{C}_2)$ from $\mo{f}_1$ to $\mo{f}_2$ are called the faces or 2-cells of the 2-category.
They are often depicted as in the following, with $\alpha$ being a 2-cell:
\begin{center}
\begin{tikzpicture}
\node(c1) at (-1,0) {$\ob{C}_1$};
\node(c2) at (1,0) {$\ob{C}_2$};
\draw[->] (c1) to[bend right=45] node(f1){} node[below]{$\mo{f}_1$} (c2);
\draw[->] (c1) to[bend left=45] node(f2){} node[above]{$\mo{f}_2$} (c2);
\draw[double,double equal sign distance,baseline,-implies] (f1) -- node[right]{$\alpha$} (f2);
\end{tikzpicture}
\end{center}
Composition of 2-cells within the category $\cat{M}(\ob{C}_1,\ob{C}_2)$ is called vertical composition.
The process of taking 2-cells in $\cat{M}(\ob{C}_1,\ob{C}_2)$ and 2-cells in $\cat{M}(\ob{C}_2,\ob{C}_3)$ to 2-cells in $\cat{M}(\ob{C}_1,\ob{C}_3)$ given by enrichment is called horizontal composition.
The fact that this process is a bifunctor guarantees that all the ways to compose the 2-cells in the following diagram produce the same result:
\begin{center}
\begin{tikzpicture}
\node(c1) at (-2,0) {$\ob{C}_1$};
\node(c2) at (0,0) {$\ob{C}_2$};
\node(c3) at (2,0) {$\ob{C}_3$};
\draw[->] (c1) to[bend right=60] node(f1){} node[below]{$\mo{f}_1$} (c2);
\draw[->] (c1) -- node(f2){} node[above,very near start]{$\mo{f}_2$} (c2);
\draw[->] (c1) to[bend left=60] node(f3){} node[above]{$\mo{f}_3$} (c2);
\draw[->] (c2) to[bend right=60] node(g1){} node[below]{$\mo{g}_1$} (c3);
\draw[->] (c2) -- node(g2){} node[above,very near start]{$\mo{g}_2$} (c3);
\draw[->] (c2) to[bend left=60] node(g3){} node[above]{$\mo{g}_3$} (c3);
\draw[double,double equal sign distance,-implies] (f1) -- node[right]{$\alpha_1$} (f2);
\draw[double,double equal sign distance,-implies] (f2) -- node[right]{$\alpha_2$} (f3);
\draw[double,double equal sign distance,-implies] (g1) -- node[right]{$\beta_1$} (g2);
\draw[double,double equal sign distance,-implies] (g2) -- node[right]{$\beta_2$} (g3);
\end{tikzpicture}
\end{center}
\end{remark}

\begin{example}
$\cat{Cat}$ and $\cat{CAT}$ can be made into 2-categories by using natural transformations as the 2-cells.
\end{example}

\begin{example}
$\cat{Multicat}$ and $\cat{MULTICAT}$ can be made into 2-categories by using natural transformations as 2-cells.
A natural transformation~$\alpha : F \nto G : \cat{C} \mto \cat{D}$ assigns a unary $\cat{D}$-morphism $[F(\ob{C})] \xmto{\alpha_\ob{C}} [G(\ob{C})]$ to each object~$\ob{C} : \cat{C}$ in such a way that, for each morphism $\mo{m} : [\ob{C}_1, \dots, \ob{C}_n] \!\mto \ob{C}$ of $\cat{C}$, the $\cat{D}$-morphism $[\alpha_{\ob{C}_1}, \dots, \alpha_{\ob{C}_n}] \cocomp G(\mo{m})$ equals $[F(\mo{m})] \cocomp \alpha_\ob{C}$.
\end{example}

\begin{example}
$\cat{Rel}$ can be made into a 2-category by having a unique 2-cell $\unlabeledtwocell{X}{Y}{R_1}{R_2}$ when $\forall x : X, y : Y.\; x \mathrel{R_1} y \imply x \mathrel{R_2} y$.
\end{example}

\begin{example}
$\cat{Prost}$ can be made into a 2-category by having a unique 2-cell $\unlabeledtwocell[1.35]{\langle X, \leq \rangle}{\langle Y, \leq \rangle}{\mo{f}_1}{\mo{f}_2}$ when $\forall x : X.\; f_1(x) \leq f_2(x)$.
\end{example}

\begin{notation}
The identity 2-cell of a morphism~$\mo{f}$ is often denoted by abuse of notation with~$\mo{f}$.
The identity morphism of an object~$\ob{C}$ is often denoted by abuse of notation with~$\ob{C}$.
Note that this means $\ob{C}$ can also denote the identity 2-cell of its identity morphism.
\end{notation}

\begin{notation}
Below, the left diagram indicates $\mathtt{flatten}$ is a natural transformation from $\List \cocomp \List$ to $\List$.
The right two diagrams both indicate that $[\bullet]$ (i.e.~$\mathtt{singleton}$) is a natural transformation from $\cat{Set}$ to $\List$.
The unarrowed line in the middle diagram should be viewed as simply stretching a 0-cell.
A diagram can similarly have a path of 1-cells as the codomain of a 2-cell.
\begin{center}
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (-2,0) {$\cat{Set}$};
\node(c2) at (0,-1) {$\cat{Set}$};
\node(c3) at (2,0) {$\cat{Set}$};
\draw[->] (c1) to[bend right=15] node[below left]{$\List$} (c2);
\draw[->] (c2) to[bend right=15] node[below right]{$\List$} (c3);
\draw[->] (c1) to[bend left=30] node[above]{$\List$} node(f2){} (c3);
\draw[double,double equal sign distance,-implies] (c2) -- node[right]{$\mathtt{flatten}$} (f2);
\end{tikzpicture}
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (-2,0) {$\cat{Set}$};
\node(c3) at (2,0) {$\cat{Set}$};
\draw (c1) to[bend right=30] node(c2){} (c3);
\draw[->] (c1) to[bend left=30] node[above]{$\List$} node(f2){} (c3);
\draw[double,double equal sign distance,-implies] (c2) -- node[right]{$[\bullet]$} (f2);
\end{tikzpicture}
\begin{tikzpicture}[baseline=(singleton.base)]
\node(c1) at (0,-1) {$\cat{Set}$};
\clip (-1,-1) rectangle (1,1);
\draw[->] (c1.north west) .. controls (-2,1) and (2,1) .. node[above]{$\List$} node(f2){} (c1.north east);
\draw[double,double equal sign distance,-implies] (c1) -- node(singleton)[right]{$[\bullet]$} (f2);
\end{tikzpicture}
\end{center}
\end{notation}

\begin{notation}
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (-2,0) {$\ob{C}_1$};
\node(c2) at (0,0) {$\ob{C}_2$};
\node(c3) at (2,0) {$\ob{C}_3$};
\draw[->] (c1) to[bend right=60] node(f1){} node[below]{$\mo{f}_1$} (c2);
\draw[->] (c1) to[bend left=60] node(f2){} node[above]{$\mo{f}_2$} (c2);
\draw[->] (c2) to node(g1){} node[above]{$\mo{g}$} (c3);
\draw[double,double equal sign distance,-implies] (f1) -- node[right]{$\alpha$} (f2);
\end{tikzpicture}
denotes the horizontal composition
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (-2,0) {$\ob{C}_1$};
\node(c2) at (0,0) {$\ob{C}_2$};
\node(c3) at (2,0) {$\ob{C}_3$};
\draw[->] (c1) to[bend right=60] node(f1){} node[below]{$\mo{f}_1$} (c2);
\draw[->] (c1) to[bend left=60] node(f2){} node[above]{$\mo{f}_2$} (c2);
\draw[->] (c2) to[bend right=60] node(g1){} node[below]{$\mo{g}$} (c3);
\draw[->] (c2) to[bend left=60] node(g2){} node[above]{$\mo{g}$} (c3);
\draw[double,double equal sign distance,-implies] (f1) -- node[right]{$\alpha$} (f2);
\draw[double,double equal sign distance,-implies] (g1) -- node[right]{$\id_\mo{g}$} (g2);
\end{tikzpicture}
.
\end{notation}

\begin{notation}
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (-2,0) {$\ob{C}_1$};
\node(c2) at (0,0) {$\ob{C}_2$};
\node(c3) at (2,0) {$\ob{C}_3$};
\draw[->] (c1) to node(f1){} node[above]{$\mo{f}$} (c2);
\draw[->] (c2) to[bend right=60] node(g1){} node[below]{$\mo{g}_1$} (c3);
\draw[->] (c2) to[bend left=60] node(g2){} node[above]{$\mo{g}_2$} (c3);
\draw[double,double equal sign distance,-implies] (g1) -- node[right]{$\beta$} (g2);
\end{tikzpicture}
denotes the horizontal composition
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (-2,0) {$\ob{C}_1$};
\node(c2) at (0,0) {$\ob{C}_2$};
\node(c3) at (2,0) {$\ob{C}_3$};
\draw[->] (c1) to[bend right=60] node(f1){} node[below]{$\mo{f}$} (c2);
\draw[->] (c1) to[bend left=60] node(f2){} node[above]{$\mo{f}$} (c2);
\draw[->] (c2) to[bend right=60] node(g1){} node[below]{$\mo{g}_1$} (c3);
\draw[->] (c2) to[bend left=60] node(g2){} node[above]{$\mo{g}_2$} (c3);
\draw[double,double equal sign distance,-implies] (f1) -- node[right]{$\id_\mo{f}$} (f2);
\draw[double,double equal sign distance,-implies] (g1) -- node[right]{$\beta$} (g2);
\end{tikzpicture}
.
\end{notation}

\begin{remark}
Due to bifunctoriality of horizontal composition, these notations do not introduce any ambiguity.
\end{remark}

\begin{definition}[Dual of a Planar Graph]
In a planar graph, edges not only connect vertices but also separate faces.
Consequently, one can build a planar graph that is called the dual of a planar graph: it has a vertex for each face of the original graph, there is an edge goes from one vertex to another if the original has an edge separating the corresponding faces with the source to the right of the edge, and it has a face for each vertex of the original graph whose border is the edges corresponding to the edges connected to the corresponding vertex.
\end{definition}

\begin{notation}
One can also denote a 2-cell composition using diagrams dual to what we have presented above:
\begin{center}
\begin{tabular}{@{}c|@{}c@{}|@{}c@{}|@{}c@{}}
\rotatebox[origin=c]{90}{Cell Diagram}
&
\begin{tikzpicture}[baseline=0]
\node(c1) at (0,1) {$\cat{Set}$};
\node(c2) at (1,-1) {$\cat{Set}$};
\node(c3) at (3,-1) {$\cat{Set}$};
\node(c4) at (4,1) {$\cat{Set}$};
\draw[->] (c1) -- node[below left]{$\List$} (c2);
\draw[->] (c2) -- node[below]{$\List$} (c3);
\draw[->] (c3) -- node[below right]{$\List$} (c4);
\draw[->] (c1) -- node(f12){} (c3);
\draw[->] (c1) -- node(f123){} (c4);
\draw[double,double equal sign distance,-implies] (c2) -- node[below right]{\tiny$\mathtt{flatten}$} (f12);
\draw[double,double equal sign distance,-implies] (c3) -- node[right]{\tiny$\mathtt{flatten}$} (f123);
\end{tikzpicture}
&
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (0,0) {$\cat{Set}$};
\node(c2) at (4,0) {$\cat{Set}$};
\draw[->] (c1) .. controls (1.5,-1.5) and (2.5,-1.5) .. node(f1){} node[below]{$\List$} (c2);
\draw[->] (c2) .. controls (1.75,-1.5) and (1.75,1.5) .. node(f2){} node[left]{$\List$} (c2);
\draw[->] (c1) .. controls (1.5,1.5) and (2.5,1.5) .. node(f12){} node[above]{$\List$} (c2);
\draw[double,double equal sign distance,-implies] (c2) -- node[above]{$[\bullet]$} (f2);
\draw[double,double equal sign distance,-implies] ($(f1.west) !.5! (c2.south)$) .. controls +(-1.5,-.5) and ($(f12.south west) + (-.5,-1)$) .. node[left]{\tiny$\mathtt{flatten}$} (f12.south west);
\end{tikzpicture}
and
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (0,0) {$\cat{Set}$};
\node(c2) at (1.5,-1) {$\cat{Set}$};
\node(c3) at (3,0) {$\cat{Set}$};
\draw[->] (c1) -- node[below left]{$\List$} (c2);
\draw (c2) to[bend right=30] node(id){} (c3);
\draw[->] (c2) to[bend left=30] node(f2){} node[above left]{$\List$} (c3);
\draw[->] (c1) to[bend left=30] node(f12){} node[above]{$\List$} (c3);
\draw[double,double equal sign distance,-implies] (id) -- node[very near start,above]{$\quad[\bullet]$} (f2);
\draw[double,double equal sign distance,-implies] (c2) -- node[left]{\tiny$\mathtt{flatten}$} (f12);
\end{tikzpicture}
&
\begin{tikzpicture}[baseline=(c1.base)]
\node(c1) at (0,0) {$\cat{Set}$};
\node(c2) at (1.5,0) {$\cat{Set}$};
\draw[->] (c1) to[bend right=30] node[below]{$\List$} node(f1){} (c2);
\draw[->] (c1) to[bend left=30] node[above]{$\List$} node(f2){} (c2);
\draw[double,double equal sign distance] (f1) -- (f2);
\end{tikzpicture}
\\
&
can be denoted with
&
can both be denoted with
&
with
\\
\rotatebox[origin=c]{90}{String Diagram}
&
\begin{tikzpicture}[baseline=1.5cm]
\node(f1) at (0,0) {$\List$};
\node(f2) at (2,0) {$\List$};
\node(f3) at (4,0) {$\List$};
\node(n1)[circle,draw] at (1,1) {\tiny$\mathtt{flatten}$};
\node(n2)[circle,draw] at (2,2) {\tiny$\mathtt{flatten}$};
\node(f123) at (2,3) {$\List$};
\draw[->] (f1) -- (n1);
\draw[->] (f2) -- (n1);
\draw[->] (f3) -- (n2);
\draw[->] (n1) -- node(f12)[above left]{$\List$} (n2);
\draw[->] (n2) -- (f123);
\node at (.5,2.5) {$\cat{Set}$};
\node at (1,.25) {$\cat{Set}$};
\node at (2.25,.75) {$\cat{Set}$};
\node at (3.5,2) {$\cat{Set}$};
\end{tikzpicture}
&
\begin{tikzpicture}[baseline=1.5cm]
\node(f1) at (0,0) {$\List$};
\node(n1)[circle,draw] at (1,1) {$[\bullet]$};
\node(n2)[circle,draw] at (0,2) {\tiny$\mathtt{flatten}$};
\node(f12) at (0,3) {$\List$};
\draw[->] (f1) -- ++(0,.5) .. controls +(0,.5) and ($(n2.south west) + (-.5,-.5)$) .. (n2.south west);
\draw[->] (n1) -- node[above right]{$\List$} (n2);
\draw[->] (n2) -- (f12);
\node at (-1,1) {$\cat{Set}$};
\node at (1.5,2.25) {$\cat{Set}$};
\end{tikzpicture}
&
\begin{tikzpicture}[baseline=1.5cm]
\node(f1) at (0,0) {$\List$};
\node(f2) at (0,3) {$\List$};
\draw[->] (f1) -- (f2);
\node at (-.5,1.5) {$\cat{Set}$};
\node at (.5,1.5) {$\cat{Set}$};
\end{tikzpicture}
\\
\rotatebox[center=c]{90}{Program}
&
$\lambda \vec{\vec{\vec{x}}}.\; \texttt{flatten}(\texttt{map}_\texttt{flatten}(\vec{\vec{\vec{x}}}))$
&
$\lambda \vec{x}.\; \texttt{flatten}([\vec{x}])$
&
$\lambda \vec{x}.\; \vec{x}$
\\
\multicolumn{4}{@{}p{\textwidth}@{}}{\textit{Remark.} \begin{tabular}{c}Note that all of the above string diagrams could be flipped horizontally to get a new diagram. \\ The following are the programs corresponding to those flipped diagrams.\end{tabular}}
\\
\rotatebox[center=c]{90}{Flipped}
\rotatebox[center=c]{90}{Program}
&
$\lambda \vec{\vec{\vec{x}}}.\; \texttt{flatten}(\texttt{flatten}(\vec{\vec{\vec{x}}}))$
&
$\lambda \vec{x}.\; \texttt{flatten}(\texttt{map}_{[\bullet]}(\vec{x}))$
&
$\lambda \vec{x}.\; \vec{x}$
\end{tabular}
\end{center}
\end{notation}

\begin{notation}
In string diagrams, often the face labels will be elided.
\end{notation}

\begin{notation}
In string diagrams, often the edge arrows will be elided. Generally, the direction is upward.
\end{notation}

\end{document}