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

\lecture{Functors}

\begin{document}
\maketitle

\begin{definition}[(Biased) ($\cat{Set}$-enriched) (Covariant) Functor from $\langle O_\cat{C}, M_\cat{C}, \cocomp_\cat, \noprf, \id_\cat{C}, \noprf \rangle$ to $\langle O_\cat{D}, M_\cat{D}, \cocomp_\cat{D}, \noprf, \id_\cat{D}, \noprf \rangle$]
A tuple $\langle F_O, F_M, \prf{d}, \prf{i} \rangle$ where the components have the following types:
\begin{description}
\item[Function on Objects $F_O$:] $O_\cat{C} \to O_\cat{D}$
\item[Function on Morphisms $F_M$:] $\forall \ob{C}_1, \ob{C}_2 : O_\cat{C}.\; M_\cat{C}(\ob{C}_1, \ob{C}_2) \to M_\cat{D}(F_O(\ob{C}_1), F_O(\ob{C}_2))$ (objects implicit)
\item[Distributivity $\prf{d}$:] $\forall \ob{C}_1, \ob{C}_2, \ob{C}_3 : O_\cat{C}.\; \forall \mo{m}_1 : M_\cat{C}(\ob{C}_1, \ob{C}_2), \mo{m}_2 : M_\cat{C}(\ob{C}_2, \ob{C}_3).\; F_M(\mo{m}_1) \cocomp_\cat{D} F_M(\mo{m}_2) = F_M(\mo{m}_1 \cocomp_\cat{C} \mo{m}_2)$
\item[Identity $\prf{i}$:] $\forall \ob{C} : O_\cat{C}.\; \id_\cat{D} = F_M(\id_\cat{D})$
\end{description}
\end{definition}

\begin{notation}
We represent both $F_O$ and~$F_M$ with just~$F$.
\end{notation}

\begin{notation}
When multiple categories (such as $\cat{C}$ and $\cat{D}$) are present, we represent all their morphism types (e.g.~$M_\cat{C}$ and~$M_\cat{D}$) with just~$M$ or with the infix operator~$\mto$.
\end{notation}

\begin{notation}
When multiple categories (such as $\cat{C}$ and $\cat{D}$) are present, we represent all their composition operators (e.g.~$\cocomp_\cat{C}$ and~$\cocomp_\cat{D}$) with just~$\cocomp$.
\end{notation}

\begin{notation}
When multiple categories (such as $\cat{C}$ and $\cat{D}$) are present, we represent all their identity operators (e.g.~$\id_\cat{C}$ and~$\id_\cat{D}$) with just~$\id$.
\end{notation}

\begin{notation}
We use $\ob{C} : \cat{C}$ to denote $\ob{C} : O_\cat{C}$.
\end{notation}

\begin{remark}
With these notations, the above definitions can be rephrased as:
A functor from $\cat{C}$ to $\cat{D}$ is a tuple $\langle F, F, \prf{d}, \prf{i} \rangle$ where the components have the following types:
\begin{description}
\item[Function on Objects $F$:] $O_\cat{C} \to O_\cat{D}$
\item[Function on Morphisms $F$:] $\forall \ob{C}_1, \ob{C}_2 : \cat{C}.\; \ob{C}_1 \mto \ob{C}_2 \to F(\ob{C}_1) \mto F(\ob{C}_2)$ (objects implicit)
\item[Distributivity $\prf{d}$:] $\forall \ob{C}_1, \ob{C}_2, \ob{C}_3 : \cat{C}.\; \forall \ob{C}_1 \xmto{\mo{m}_1} \ob{C}_2, \ob{C}_2 \xmto{\mo{m}_2} \ob{C}_3.\; F(\mo{m}_1) \cocomp F(\mo{m}_2) = F(\mo{m}_1 \cocomp \mo{m}_2)$
\item[Identity $\prf{i}$:] $\forall \ob{C} : \cat{C}.\; \id = F(\id)$
\end{description}
\end{remark}

\begin{example}
\begin{description}
\setlength{\itemsep}{0pt}
\item[$\cat{Prost}$ to $\cat{Set}$:] $\langle \lambda \tau.\; \tau, \lambda \langle \tau_1, \tau_2 \rangle.\; \lambda \langle f, \noprf \rangle.\; f, \noprf, \noprf \rangle$
\item[$\cat{Mat}$ to $\cat{Set}$:] $\langle \lambda n.\; \R^n, \lambda \langle n_1, n_2 \rangle.\; \lambda M.\; \lambda \vec{x}.\; M \cdot \vec{x}, \noprf, \noprf \rangle$
\item[$\mathbb{\Delta}$ to $\cat{Prost}$:] $\langle \lambda n.\; \langle \mathbb{n}, \leq, \noprf, \noprf \rangle, \lambda \langle n_1, n_2 \rangle.\; \lambda \sigma.\; \langle \sigma, \noprf \rangle, \noprf, \noprf \rangle$
\item[$\cat{\omega}$ to $\mathbb{\Delta}$:] $\langle \lambda n.\; n, \lambda \langle n_1, n_2 \rangle.\; \lambda \prf{lte}.\; \lambda n.\; n\textrm{~as~}\mathbb{n}_2\textrm{~using~}\prf{lte}, \noprf, \noprf \rangle$
\item[$\cat{Set}$ to $\cat{Rel}$:] $\langle \lambda \tau.\; \tau, \lambda \langle \tau_1, \tau_2 \rangle.\; \lambda f.\; \lambda \langle t_1, t_2 \rangle.\; f(t_1) = t_2, \noprf, \noprf \rangle$
\item[$\cat{Rel}$ to $\cat{Set}$:] $\langle \Set, \lambda \langle \tau_1, \tau_2 \rangle.\; \lambda \phi.\; \lambda T_1.\; \{ t_2 : \tau_2 \mid \exists t_1 : \tau_1.\; t_1 \in T_1 \wedge \phi(t_1, t_2) \}, \noprf, \noprf \rangle$
%\item[$\List : \cat{Set} \mto \cat{Set}$:] $\langle \List, \lambda \langle \tau_1, \tau_2 \rangle.\; \lambda f.\; \mathtt{map}(f), \noprf, \noprf \rangle$
\item[$\cat{Mon}_b$ to $\cat{Alg}(2, 0)$:] $\langle \lambda \langle M, *, \noprf, e, \noprf \rangle.\; \langle M, *, e \rangle, \lambda \langle \alg{M}_1, \alg{M}_2 \rangle.\; \lambda \langle f, \noprf, \noprf \rangle.\; \langle f, \noprf \rangle, \noprf, \noprf \rangle$
\item[$\cat{Mon}_u$ to $\cat{Alg}(\langle \N, \lambda n.\; \mathbb{n} \rangle)$:] $\langle \lambda \langle M, \prod, \noprf \rangle.\; \langle M, \lambda n.\; \lambda (m_i)_{i \in \mathbb{n}}.\; \prod[m_1, \dots, m_n], \noprf \rangle, \lambda \langle \alg{M}_1, \alg{M}_2 \rangle.\; \lambda \langle f, \noprf \rangle.\; \langle f, \noprf \rangle, \noprf, \noprf \rangle$
\item[$\cat{Prost}$ to $\cat{Rel}(2)$:] $\langle \lambda \langle \tau, R, \noprf \rangle.\; \langle \tau, R \rangle,\; \lambda \mo{f}.\; \mo{f}, \noprf, \noprf \rangle$
\end{description}
\end{example}

\begin{exercise}
Prove that there are functors from~$\cat{Set}$ to~$\cat{Set}$ mapping a set~$S$ to~$\List S$, to~$\Multiset S$, to~$\Finset S$, and to~$\Set S$.
\end{exercise}

\begin{exercise}
Prove that the set of functors from~$\cat{1}$ to~$\cat{C}$ is isomorphic to $O_C$.
\end{exercise}

\begin{exercise}
Prove that the set of functors from~$\cat{2}$ to~$\cat{C}$ is isomorphic to $\sum_{\ob{C}_1, \ob{C}_2 : \cat{C}} \ob{C}_1 \mto \ob{C}_2$.
\end{exercise}

\begin{exercise}
Prove that there is a category~$\cat{CAT}$ (of a higher universe) of categories whose objects are categories and whose morphisms are functors, such that there exists a functor from $\cat{CAT}$ to $\cat{SET}$ (i.e.~$\cat{Set}$ for a higher universe) mapping categories to their set of objects and functors to their functions on objects.
\end{exercise}

\begin{definition}[$\cat{Cat}$]
The category of ``small'' categories (categories where $O$ is an element of $\Type$ rather than $\TYPE{1}$) and functors between them.
\end{definition}

\clearpage

\begin{definition}[(Biased) ($\cat{Set}$-enriched) Contravariant Functor from $\langle O_\cat{C}, M_\cat{C}, \cocomp_\cat, \noprf, \id_\cat{C}, \noprf \rangle$ to $\langle O_\cat{D}, M_\cat{D}, \cocomp_\cat{D}, \noprf, \id_\cat{D}, \noprf \rangle$]
A tuple $\langle F_O, F_M, \prf{d}, \prf{i} \rangle$ where the components have the following types:
\begin{description}
\item[Function on Objects $F$:] $O_\cat{C} \to O_\cat{D}$
\item[Function on Morphisms $F$:] $\forall \ob{C}_1, \ob{C}_2 : \cat{C}.\; \ob{C}_1 \mto \ob{C}_2 \to F(\ob{C}_2) \mto F(\ob{C}_1)$ (objects implicit)
\item[Distributivity $\prf{d}$:] $\forall \ob{C}_1, \ob{C}_2, \ob{C}_3 : \cat{C}.\; \forall \ob{C}_1 \xmto{\mo{m}_1} \ob{C}_2, \ob{C}_2 \xmto{\mo{m}_2} \ob{C}_3.\; F(\mo{m}_2) \cocomp F(\mo{m}_1) = F(\mo{m}_1 \cocomp \mo{m}_2)$
\item[Identity $\prf{i}$:] $\forall \ob{C} : \cat{C}.\; \id = F(\id)$
\end{description}
\end{definition}

\begin{exercise}
Prove that there is a contravariant functor from~$\cat{Set}$ to~$\cat{Set}$ mapping a set~$S$ to~$\Set S$.
\end{exercise}

\begin{exercise}
Prove that there is a contravariant functor from~$\cat{Rel}$ to~$\cat{Rel}$ whose object is component is the identity function.
\end{exercise}

\begin{exercise}
Prove that there is a contravariant functor from~$\cat{Sig}$ to~$\cat{CAT}$ mapping $\Omega : \cat{Sig}$ to $\cat{Alg}(\Omega) : \cat{CAT}$.
\end{exercise}

\begin{exercise}
Prove that there is a contravariant functor from~$\cat{Sig}$ to~$\cat{CAT}$ mapping $\Phi : \cat{Sig}$ to $\cat{Rel}(\Phi) : \cat{CAT}$.
\end{exercise}

\end{document}
