\documentclass[a4paper]{article}

\def\npart{III}

\def\ntitle{Category Theory}
\def\nlecturer{P.\ T.\ Johnstone}

\def\nterm{Michaelmas}
\def\nyear{2018}

\input{header}

%\usepackage{tipa} % \textcorner
\usepackage{xcolor}

% add annotation to middle of a commutative square in tikzcd
% https://tex.stackexchange.com/questions/119543/how-can-i-get-symbols-to-appear-in-the-middle-of-commutative-diagrams-using-tikz
\tikzset{commutative diagrams/.cd,
mysymbol/.style={start anchor=center,end anchor=center,draw=none}
}
\newcommand\MySymb[2][?]{%
  \arrow[mysymbol]{#2}[description]{#1}}

\renewcommand{\c}[1]{\mathbf{#1}}
\DeclareMathOperator{\ob}{ob}
\DeclareMathOperator{\mor}{mor}
\DeclareMathOperator{\dom}{dom}
\DeclareMathOperator{\cod}{cod}

\newcommand{\Set}{{\c{Set}}}
\newcommand{\Top}{{\c{Top}}}
\newcommand{\Rel}{{\c{Rel}}}
\newcommand{\Cone}{{\c{Cone}}}
\newcommand{\Sh}{{\c{Sh}}}
\newcommand{\sh}{{\c{sh}}}
\newcommand{\Sub}{{\c{Sub}}}

\newcommand{\mono}{\rightarrowtail}
\newcommand{\epi}{\twoheadrightarrow}

\newcommand{\adjoint}{\dashv}

\newcommand{\T}{{\mathbb{T}}} % monad
\newcommand{\blue}[1]{\textcolor{blue}{#1}}

\DeclareMathOperator{\ev}{ev} % evaluation

\begin{document}

\input{titlepage}

\tableofcontents

\section{Definitions and examples}

\begin{definition}[category]\index{category}
  A \emph{category} \(\c C\) consists of
  \begin{enumerate}
  \item a collection \(\ob \c C\) of \emph{objects} \(A, B, C, \dots\),
  \item a collection \(\mor \c C\) of \emph{morphisms} \(f, g, h, \dots\),
  \item two operations \(\dom\) and \(\cod\) assigning to each \(f \in \mor \c C\) a pair of objects, its \emph{domain} and \emph{codomain}. We write \(A \xrightarrow{f} B\) to mean \(f\) is a morphism and \(\dom f = A, \cod f = B\),
  \item an operation assigning to each \(A \in \ob \c C\) a morhpism \(A \xrightarrow{1_A} A\),
  \item a partial binary operation \((f, g) \mapsto fg\) on morphisms, such that \(fg\) is defined if and only if \(\dom f = \cod g\) and let \(\dom fg = \dom g, \cod fg = \cod f\) if \(fg\) is defined
  \end{enumerate}
  satisfying
  \begin{enumerate}
  \item \(f 1_A = f = 1_B f\) for any \(A \xrightarrow{f} B\),
  \item \((fg) h = f(gh)\) whenever \(fg\) and \(gh\) are defined.
  \end{enumerate}
\end{definition}

\begin{remark}\leavevmode
  \begin{enumerate}
  \item This definition is independent of any model of set theory. If we're given a particuar model of set theory, we call \(\c C\) \emph{small}\index{category!small} if \(\ob \c C\) and \(\mor \c C\) are sets.
  \item Some texts say \(fg\) means \(f\) followed by \(g\) (we are not).
  \item Note that a morphism \(f\) is an identity if and only if \(fg = g\) and \(hf = h\) whenever the compositions are defined so we could formulate the definitions entirely in terms of morphisms.
  \end{enumerate}
\end{remark}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item The category \(\Set\) has all sets as objects and all functions between sets as morphisms (strictly, morphisms \(A \to B\) are pairs \((f, B)\) where \(f\) is a set theoretic function).
  \item The category \(\c{Gp}\) where objects are groups, morphisms are group homomorphisms. Similarly \(\c{Ring}\) is the category of rings and \(\c{Mod}_R\) is the category of \(R\)-modules.
  \item The category \(\Top\) has all topological spaces as objects and continuous functions as morphisms. Similarly \(\c{Unif}\) the category of uniform spaces with uniformly continuous functions and \(\c{Mf}\) the category of manifolds with smooth maps.
  \item The cateogry \(\c{Htpy}\) has same objects as \(\Top\) but morphisms are homotopy classes of continuous functions.

    More generally, given \(\c C\) we call an equivalence relation \(\simeq\) on \(\mor \c C\) a \emph{congruence}\index{congruence} if \(f \simeq g\) implies \(\dom f = \dom g, \cod f = \cod g\) and \(fh \simeq gh\) and vice versa.
    Then we have a set \(\c C / \simeq\) with the same objects as \(\c C\) but congruence classes as morphisms.
  \item Given \(\c C\), the \emph{opposite category}\index{category!opposite} \(\c C^{\text{op}}\) has the same objects and morphisms as \(\c C\), but domain and codomain interchanged and \(fg\) in \(\c C^{\text{op}}\) is \(gf\) in \(\c C\).

    This leads to \emph{duality principle}: if \(P\) is a valid statement about categories so is \(P^*\) attained by reversing all the arrows.
  \item A small category with one object is a \emph{monoid}\index{monoid}, i.e.\ a semigroup with \(1\). In particular, a group is a small category with one object, in which every morphism is an isomorphism (i.e.\ for all \(f\) there exists \(g\) such that \(fg\) and \(gf\) are identities).
  \item A \emph{groupoid} is a category in which every morphism is an isomorphism. For example, for a topological space \(X\), the \emph{fundamental groupoid} \(\pi(X)\) has all points of \(X\) as objects and morphisms \(x \to y\) as homotopy classes rel \({0, 1}\) of paths \(\gamma: [0, 1] \to X\) with \(\gamma(1) = y\).
  \item A \emph{discrete}\index{category!discrete} category is one whose only morphisms are identities. A \emph{preorder} is a category \(\c C\) in which for any pair \((A, B)\) there exists at most one morphism \(A \to B\). A small preorder is a set equipped with a binary relation which is reflexive and transitive. In particular a partially ordered set is a partially ordered set is a small preorder in which the only isomorphisms are identities.
  \item The category \(\Rel\) has the same objects as \(\Set\) but morphisms \(A \to B\) are arbitrary relations. Given \(R \subseteq A \times B, S \subseteq B \times C\), we define
    \[
      S \compose R = \{(a, c) \in A \times C: \exists b \in B \text{ s.t. } (a, b) \in R, (b, c) \in S\}.
    \]
    The identity \(1_A: A \to A\) is \(\{(a, a): a \in A\}\). Similarly, the category \(\c{Part}\) of sets and partial functions (i.e.\ relations such that for all \((a, b), (a, b') \in R\), \(b = b'\)) can be defined.
  \item Let \(K\) be a field. The category \(\c{Mat}_K\) has natural numbers as objects and morphisms \(n \to p\) are \((p \times n)\) matrices with entries from \(K\). Composition is matrix multiplication.
  \end{enumerate}
\end{eg}

\begin{definition}[functor]\index{functor}
  Let \(\c C, \c D\) be categories. A \emph{functor} \(F: \c C \to \c D\) consists of
  \begin{enumerate}
  \item a mapping \(A \mapsto F(A)\) from \(\ob \c C\) to \(\ob \c D\),
  \item a mapping \(f \mapsto F(f)\) from \(\mor \c C\) to \(\mor \c D\) such that
    \begin{align*}
      \dom(F(f)) &= F(\dom f), \cod (Ff) = F \cod(f) \\
      1_{F(A)} &= F(1_A), (F(f))(F(g)) = F(fg)
    \end{align*}
    wherever \(fg\) is defined.
  \end{enumerate}
\end{definition}

\begin{eg}
  We write \(\c{Cat}\) for the category whose objects are all small categories and whose morphisms are functors between them.
\end{eg}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item We have \emph{forgetful functors}\index{functor!forgetful} \(U: \c{Gp} \to \Set, \c{Ring} \to \Set, \Top \to \Set \dots\) and \(\c{Ring} \to \c{AbGp}\) (forget multiplication), \(\c{Ring} \to \c{Mon}\) (forget addition).
  \item Given \(A\), the free group \(F(A)\) has the property given any group \(G\), any \(A \xrightarrow{f} U G\), there is a unique homomorphism \(FA \xrightarrow{\tilde f} G\) extending \(f\).

    \(F\) is a functor \(\Set \to \c{Gp}\): given any \(A \xrightarrow{f} B\), we define \(F(f)\) to be the unique homomorphism extending \(A \xrightarrow{f} B \embed U FB\). Functoriality follows from uniqueness: given \(B \xrightarrow{g} C\), \(F(gf)\) and \((Fg)(Ff)\) are both homomorphisms extending
    \[
      A \xrightarrow{f} B \xrightarrow{g} C \embed U F C.
    \]
  \item Given a set \(A\), we write \(PA\) for the set of all subsets of \(A\). We can make \(P\) into a functor \(\Set \to \Set\): given \(A \xrightarrow{f} B\), we define
    \[
      Pf(A') = \{f(a): a \in A'\}
    \]
    for \(A' \subseteq A\).

    But we also have a functor \(P^*: \Set \to \Set^{\text{op}}\) defined by
    \[
      P^*f(B') = \{a \in A: f(a) \in B'\}
    \]
    for \(B' \subseteq B\).
  \item By a \emph{contravariant functor}\index{functor!contravariant} \(\c C \to \c D\) we mean a functor \(\c C \to \c D^{\text{op}}\) (or \(\c C^{\text{op}} \to \c D\). (A \emph{covariant functor} is one that doesn't reverse arrows)

    Let \(K\) be a field. We have a functor \(\cdot^*: \c{Mod}_K \to \c{Mod}^{\text{op}}_K\) defined by
    \[
      V^* = \{\text{linear maps } V \to K\}
    \]
    and if \(V \xrightarrow{f} W\), \(f^*(\theta) = \theta f\).
  \item We have a functor \(\cdot^\text{op}: \c{Cat} \to \c{Cat}\) which is the identity on morphisms. (note that this is \emph{covariant})
  \item A functor between monoids is a monoid homomorphism.
  \item A functor between posets is an order-preserving map.
  \item Let \(G\) be a group. A functor \(F: G \to \Set\) consists of a ast \(A = F*\) together with an action of \(G\) on \(A\), i.e.\ permutation representation of \(G\). Similarly a functor \(G \to \c{Mod}_K\) is a \(K\)-linear representation of \(G\).
  \item The construction of the fundamental gropu \(\pi_1(X, x)\) of a space \(X\) with basepoint \(x\) is a functor
    \[
      \Top_* \to \c{Gp}
    \]
    where \(\Top_*\) is the category of spaces with a chosen basepoint.

    Similarly, the fundamental groupoid is a functor
    \[
      \Top \to \c{Gpd}
    \]
    where \(\c{Gpd}\) is the category of groupoids and functors between them.
  \end{enumerate}
\end{eg}

\begin{definition}[natural transformation]\index{natural transformation}
  Let \(\c C, \c D\) be categories and \(F, G: \c C \to \c D\) be two functors. A \emph{natural transformation} \(\alpha: F \to G\) consists of an assignment \(A \mapsto \alpha_A\) from \(\ob \c C\) to \(\mor \c D\) such that \(\dom \alpha_A = FA, \cod \alpha_A = GA\) for all \(A\), and for all \(A \xrightarrow{f} B\) in \(\c C\), the square
  \[
    \begin{tikzcd}
      FA \ar[r, "Ff"] \ar[d, "\alpha_A"] & FB \ar[d, "\alpha_B"] \\
      GA \ar[r, "Gf"] & GB
    \end{tikzcd}
  \]
  commutes, i.e.\ \(\alpha_B(Ff) = (Gf)\alpha_A\).
\end{definition}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item Given categories \(\c C, \c D\), we write \([\c C, \c D]\) for the category whose objects are functors \(\c C \to \c D\) and whose morphisms are natural transformations.
  \item Let \(K\) be a field and \(V\) a vector space over \(K\). There is a linear map \(\alpha_V: V \to V^{**}\) given by
    \[
      \alpha_V(v)(\theta) = \theta(v)
    \]
    for \(\theta \in V^*\). This is the \(V\)-component of a natural transformation
    \[
      1_{\c{Mod}_K} \to \cdot^{**}: \c{Mod}_K \to \c{Mod}_K.
    \]
  \item For any set \(A\), we have a mapping \(\sigma_A: A \to PA\) sending \(a\) to \(\{a\}\). If \(f: A \to B\) then \(Pf(\{a\}) = \{f(a)\}\). So \(\sigma\) is a natural transformation \(1_\Set \to P\).
  \item Let \(F: \Set \to \c{Gp}\) be the free group functor and \(U: \c{Gp} \to \Set\) the forgetful functor. The inclusions \(A \to UFA\) is a natural transformation \(1_\Set \to UF\).
  \item Let \(G, H\) be groups and \(f, g: G \to H\) be two homomorphisms. Then a natural tranformation \(\alpha: f \to g\) corresponds to an element \(h = \alpha_*\) such that \(h f(x) = g(x) h\) for all \(x \in G\), or equivalently \(f(x) = h^{-1} g(x) h\), i.e.\ \(f\) and \(g\) are conjugate group homomorphisms.
  \item Let \(A\) and \(B\) be two \(G\)-sets, regarded as functors \(G \to \Set\). A natural transformation \(A \to B\) is a function \(f\) satisfying \(f(g . a) = g. f(a)\) for all \(a \in A\), i.e.\ a \(G\)-equivariant map.
  \end{enumerate}
\end{eg}

When we say ``natural isomorphism'', it is ambiguous and can formally mean two different things: one could mean there is a natural transformation going the other way which when composed produces identity, or each component is an isomorphism. It turns out they coincide:

\begin{lemma}
  Let \(F, G: \c C \to \c D\) be two functors and \(\alpha: F \to G\) a natural transformation. Then \(\alpha\) is an isomorphism in \([\c C, \c D]\) if and only if each \(\alpha_A\) is an isomorphism in \(\c D\).
\end{lemma}

\begin{proof}
  Only if is trivial. For if, suppose each \(\alpha_A\) has an inverse \(\beta_A\). We need to prove the \(\beta\)'s satisfy the naturality condition: give \(f: A \to B\) in \(\c C\), we need to show that
  \[
    \begin{tikzcd}
      GA \ar[r, "Gf"] \ar[d, "\beta_A"] & GB \ar[d, "\beta_B"] \\
      FA \ar[r, "Ff"] & FB
    \end{tikzcd}
  \]
  commutes. But
  \[
    (Ff) \beta_A = \beta_B \alpha_B(Ff) \beta_A
    = \beta_B (GF) \alpha_A \beta_A
    =\beta_B (Gf)
  \]
  by naturality of \(\alpha\).
\end{proof}

In study of algebraic theories (for example), we are interested in isomorphisms of objects and investigate the properties of objects ``up to isomorphism''. However, in category theory a weaker notion of isomorphism is often more useful:

\begin{definition}[equivalence]\index{equivalence}
  Let \(\c C\) and \(\c D\) be categories. By an \emph{equivalence} between \(\c C\) and \(\c D\) we mean a pair of functors \(F : \c C \to \c D, G: \c D \to \c C\) together with natural isomorphisms \(\alpha: 1_{\c C} \to GF, \beta: FG \to 1_{\c D}\). We write \(\c C \simeq \c D\) if \(\c C\) and \(\c D\) are equivalent.

  We say a property \(P\) of categories is a \emph{category propery} if whenever \(\c C\) has \(P\) and \(\c C \simeq \c D\) then \(\c D\) has \(P\).
\end{definition}

For example, being a groupoid or a preorder are categorical properies, but being a group or a partial order are not.

\begin{eg}\leavevmode
  \begin{enumerate}
  \item The category \(\c{Part}\) is equivalent to the category \(\Set_*\) of pointed sets (and basepoint preserving functions). We define
    \begin{align*}
      F: \Set_* &\to \c{Part} \\
      (A, a) &\mapsto A \setminus \{a\} \\
    \end{align*}
    and if \(f: (A, a) \to (B, b)\) then \(Ff(x) = f(x)\) if \(f(x) \neq b\) and undefined otherwise, and
    \begin{align*}
      G: \c{Part} &\to \Set_* \\
      A &\mapsto A^+ = (A \cup \{A\}, A)
    \end{align*}
    and if \(f: A \to B\) is a partial function , we define
    \[
      x \mapsto
      \begin{cases}
        f(x) & \text{if } x \in A \text{ and } f(x) \text{ defined} \\
        B & \text{otherwise}
      \end{cases}
    \]
    Then \(FG\) is the identity on \(\c{Part}\) but \(GF\) is not. However there is an isomorphism
    \[
      (A, a) \to ((A \setminus \{a\})^+, A \setminus \{a\})
    \]
   sending \(a\) to \(A \setminus \{a\}\) and everything else to itself. This is natural.

   Note that there can be no isomorphism \(\Set_* \to \c{Part}\) since \(\c{Part}\) has a \(1\)-element isomorphism class \(\{\emptyset\}\) and \(\Set_*\) doesn't.
 \item The category \(\c{fdMod}_K\) of finite-dimensional vector spaces over \(K\) is equivalent to \(\c{fdMod}_K^{\text{op}}\):  the functors in both directions are \(\cdot^*\) and both isomorphisms are the natural transformations given by double dual.
 \item \(\c{fdMod}_K\) is also equivalent to \(\c{Mat}_K\): we write \(F: \c{Mat}_K \to \c{fdMod}_K\) by \(F(n) = K^n\), and \(F(A)\) is the map represented by \(A\) with respect to the standard basis. To define functor \(G\) the other way, choose a basis for each finite-dimensional vector space and define
   \begin{align*}
     G(V) &= \dim V \\
     G(V \xrightarrow{f} W) &= \text{ matrix representing \(f\) w.r.t.\ chosen bases}
   \end{align*}
   \(GF\) is the identity, provided we choose the standard bases for the space \(K^n\). \(FG \neq 1\) but the chosen bases give isomorphisms \(FG(V) = K^{\dim V} \to V\) for each \(V\), which form a natural isomorphism.
  \end{enumerate}
\end{eg}

Example 3 illustrates a general principle: when constructing a pair of functors between equivalent categories, ususally one is ``canonical'' and the other requires some choice, and a clever choice results in a particularly simple form for one way of composition. The next theorem abstracts away the ``choice'' and tells us when a functor is part of an equivalence purely by its properties.

The criterion is stated in term of ``bijectivity'' of functors, informally. It is generally a bad idea to look at sur/injectivity of functors on objects. Instead the correct way is to look at their behaviour on morphisms.

\begin{definition}[faithful, full, essentially surjective]\index{functor!faithful}\index{functor!full}\index{functor!essentially surjective}
  Let \(\c C \xrightarrow{F} \c D\) be a functor.
  \begin{enumerate}
  \item \(F\) is \emph{faithful} if given \(f, f' \in \mor \c C\) with \(\dom f = \dom f', \cod f = \cod f'\) and \(Ff = Ff'\) then \(f = f'\).
  \item \(F\) is \emph{full} if given \(FA \xrightarrow{g} FB\) in \(\c D\) then there exists \(A \xrightarrow{f} B\) in \(\c C\) with \(Ff = g\).
  \item \(F\) is \emph{essentially surjective} if for every \(B \in \ob \c D\) there exists \(A \in \ob \c C\) and an isomorphism \(FA \to B\) in \(\c D\).
  \end{enumerate}
\end{definition}

\begin{definition}
  A subcategory \(\c C' \subseteq \c C\) is \emph{full} if the inclusion \(\c C' \to \c C\) is a full functor.
\end{definition}

\begin{eg}
  \(\c{Gp}\) is a full subcategory of \(\c{Mon}\) but \(\c{Mon}\) is not a full subcategory of the category \(\c{SGp}\) of semigroups.
\end{eg}

\begin{lemma}
  Assuming the axiom of choice. A functor \(F: \c C \to \c D\) is part of an equivalence \(\c C \simeq \c D\) if and only if it's full, faithful and essentially surjective.
\end{lemma}

\begin{proof}
  Suppose given \(G, \alpha, \beta\) as in the definition of equivalence of categories. Then for each \(B \in \ob \c D\), \(\beta_B\) is an isomorphism \(FGB \to B\) so \(F\) is essentially surjective.

  Given \(A \xrightarrow{f} B\) in \(\c C\), we can recover \(f\) from \(Ff\) as the via conjugation by \(\alpha\):
  \[
    \begin{tikzcd}
      GFA \ar[r, "GFf"] & GFB \\
      A \ar[u, "\alpha_A"] \ar[r, "f"] & B \ar[u, "\alpha_B"]
    \end{tikzcd}
  \]
  Hence if \(A \xrightarrow{f'} B\) satisfies \(Ff = Ff'\) then \(f = f'\).

  Similarly there is a natural preimage given a morphism in \(\c D\). Given \(FA \xrightarrow{g} FB\), define \(f\) to be the composite
  \[
    \begin{tikzcd}
      GFA \ar[r, "Gg"] & GFB \\
      A \ar[u, "\alpha_A"] \ar[r, dashed] & B \ar[u, "\alpha_B"]
    \end{tikzcd}
  \]
  Then \(GFf = \alpha_B f \alpha_A^{-1} = Gg\). As \(G\) is faithful for the same reasons as \(F\), \(Ff = g\).

  Conversely, for each \(B \in \ob \c D\), choose \(GB \in \ob \c C\) and an isomorphism \(\beta_B: FGB \to B\) in \(\c D\). Given \(B \xrightarrow{g} B'\), define \(Gg: GB \to GB'\) to be the unique morphism whose image under \(F\) is the composition
  \[
    \begin{tikzcd}
      B \ar[r, "f"] & B' \\
      FGB \ar[u, "\beta_B"] \ar[r, dashed] & FGA \ar[u, "\beta_{B'}"]
    \end{tikzcd}
  \]
  Faithfulness implies functoriality: given \(B' \xrightarrow{g'} B''\), \((Gg') (Gg)\) and \(G(g'g)\) have the same image under \(F\) so they are equal.

  By construction, \(\beta\) is a natural transformation \(FG \to 1_{\c D}\).

  Given \(A \in \ob \c C\), define \(\alpha_A: A \to GFA\) to be the unique morphism whose image under \(F\) is
  \[
    FA \xrightarrow{\beta_{FA}^{-1}} FGFA.
  \]
  \(\alpha_A\) is an isomorphism since \(\beta_{FA}\) also has a unique preimage under \(F\). Finally \(\alpha\) is a natural transformation, since any naturality square for \(\alpha\) is mapped by \(F\) to a commutative square (corresponding to naturality square for \(\beta\)) and \(F\) is faithful.
\end{proof}

Note that axiom of choice is only used in the if part. The lemma is useful as it saves us from making explicit choices when showing an equivalence by exhibiting inverses. However note that the choice is always required.

\begin{definition}[skeleton]\index{skeleton}\index{category!skeletal}
  By a \emph{skeleton} of a category \(\c C\) we mean a full subcategory \(\c C_0\) containing one object from each isomorphism class. We say \(\c C\) is \emph{skeletal} if it's a skeleton of itself.
\end{definition}

\begin{eg}
  \(\c{Mat}_K\) is skeletal and the image of \(F: \c{Mat}_K \to \c{fdMod}_K\) is a skeleton of \(\c{fdMod}_K\) (essentially because \(F\) is full and faithful).
\end{eg}

\begin{remark}
  Almost any assertion about skeletons is equivalent to the axiom of choice. See example sheet 1 Q2. This is one reason why we should not restrict out attention to skeletal categories.
\end{remark}

\begin{definition}[monomorphism, epimorphism]\index{monomorphism}\index{epimorphism}
  Let \(A \xrightarrow{f} B\) be a morphism in \(\c C\).
  \begin{enumerate}
  \item We say \(f\) is a \emph{monomorphism} or \emph{monic} if given any pair \(g, h: C \to A\), \(fg = fh\) implies \(g = h\).
  \item We say \(f\) is a \emph{epimorphism} or \emph{epic} if it is a monomorphism in \(\c C^{\text{op}}\), i.e.\ given any pair \(g, h: B \to C\), \(gf = hf\) implies \(g = h\).
  \end{enumerate}

  We denote monomorphisms by \(f: A \mono B\) and epimorphisms by \(f: A \epi B\).
\end{definition}

Any isomorphism is monic and epic. More generally if \(f\) has a left inverse then it's monic. We call such monomorphisms \emph{split}\index{monomorphism!split}.

\begin{definition}[balanced]\index{category!balanced}
  We say \(\c C\) is a \emph{balanced} category if any morphism which is both monic and epic is an isomorphism.
\end{definition}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item In \(\Set\), monomorphism is precisely an injection (one direction is easy and for the other direction take \(C = 1 = \{*\}\)) and epimorphism is precisely a surjection (use morphisms \(B \to 2 = \{0, 1\}\)). Thus \(\Set\) is balanced.
  \item In \(\c{Gp}\), monomorphism is precisely an injection (use homomorphism from the free group with one generator, i.e.\ \(\Z \to A\)) and epimorphism is precisely a surjection (use free product with amalgamation). Thus \(\c{Gp}\) is balanced.
  \item In \(\c{Rng}\), monomorphism is precisely an injection (similarly to free group) but the inclusion \(\Z \to \Q\) is an epimorphism, since if \(f, g: \Q \to R\) agree on all integers they agree everywhere. So \(\c{Rng}\) is not balanced.
  \item In \(\Top\), monomorphism is precisely an injection and epimorphism is precisely a precisely surjection (same argument as \(\Set\)) but \(\Top\) is not balanced since a continuous bijection need not to have a continuous inverse.
  \end{enumerate}
\end{eg}

\section{The Yoneda lemma}

It may seem weird to devote an entire chapter to a lemma. However, although the Yoneda lemma is indeed a lemma, with a simple statement and straightforward proof, it is much more than a normal lemma and underlies the entire category theory.

Here is a little story about Yoneda lemma. It is named after Nobuo Yoneda, who is better known as a computer scientist than a mathematician. The result is likely not due to him and he wasn't the first person to write it down. In fact, he never actually wrote down the lemma, as opposed to some books claiming the lemma was first to be found in one of Yoneda's papers. The story, according to Saunders Mac Lane, is that after a conference he met Yoneda on a train platform. While exchanging conversations Yoneda told him the result, which Mac Lane was not aware of at that moment but immediately recognised its importance. Mac Lane later attributed the lemma to Yoneda and because of his standing in category theory, the name retains. Perhaps this is the first and only result in mathematics to be enunciated on a train platform!

\begin{definition}[locally small category]\index{category!locally small}
  We say a category \(\c C\) is \emph{locally small} if, for any two objects \(A, B\), the morphisms \(A \to B\) in \(\c C\) form a set \(\c C(A, B)\).
\end{definition}

If we fix \(A\) and let \(B\) vary, the assignment \(B \mapsto \c C(A, B)\) becomes a functor \(\c C(A, -): \c C \to \Set\): given \(B \xrightarrow{f} C\), \(\c C(A, f)\) is the mapping \(g \mapsto fg\). Similarly, \(A \mapsto \c C(A, B)\) defines a functor \(\c C(-, B): \c C^{\text{op}} \to \Set\).

\begin{lemma}[Yoneda lemma]\index{Yoneda lemma}
  \label{lem:Yoneda}
  Let \(\c C\) be a locally small category, \(A \in \ob \c C\) and \(F: \c C \to \Set\) is a functor. Then natural transformations \(\c C(A, -) \to F\) are in bijection with elements of \(FA\).

  Moreover, this bijection is natural in both \(A\) and \(F\).
\end{lemma}

\begin{proof}
  We prove the first part now. The second part follows very easily once we have gained some intuitions so we'll come back to it later. Given \(\alpha: \c C(A, -) \to F\), we define
  \[
    \Phi(\alpha) = \alpha_A(1_A) \in FA.
  \]
  Conversely, given \(x \in FA\), we define \(\Psi(x): \c C(A, -) \to F\) by
  \[
    \Psi(x)_B (A \xrightarrow{f} B) = Ff(x) \in FB
  \]
  which is natural: given \(g: B \to C\), we have
  \begin{align*}
    \Psi(x)_C \c C(A, g)(f) &= \Psi(x)_C (gf) = F(gf) (x) \\
    (Fg) \Psi(x)_B (f) &= (Fg) (Ff)(x) = F(gf) (x)
  \end{align*}
  \[
    \begin{tikzcd}
      \c C(A, B) \ar[rrr, "{\c C(A, g)}"] \ar[ddd, "\Psi(x)_B"] &&& \c C(A, C) \ar[ddd, "\Psi(x)_C"] \\
      & f \ar[r, mapsto] \ar[d, mapsto] & gf \ar[d, mapsto] \\
      & Ff(x) \ar[r, mapsto] & F(gf)(x) \\
      FB \ar[rrr, "Fg"] &&& FC
    \end{tikzcd}
  \]
  by functoriality of \(F\). Now left to show they are inverses to each other.
  \begin{align*}
    \Phi\Psi(x) &= \Psi(x)_A(1_A) = F(1_A) (x) = x \\
    \Psi\Phi(\alpha)_B(f) &= \Psi (\alpha_A(1_A))_B (f) = Ff (\alpha_A(1_A)) = \alpha_B \c C(A, f) (1_A) = \alpha_B(f)
  \end{align*}
  so \(\Psi \Phi(\alpha) = \alpha\).
\end{proof}

\begin{corollary}[Yoneda embedding]\index{Yoneda embedding}
  The assignment \(A \mapsto \c C(A, -)\) defines a full faithful functor \(\c C^{\text{op}} \to [\c C, \Set]\).
\end{corollary}

\begin{proof}
  Put \(F = \c C(B, -)\) in the above proof, we get a bijection between \(\c C(B, A)\) and morphisms \(\c C(A, -) \to \c C(B, -)\) in \([\c C, \Set]\). We need to verify that this is functorial. But it sends \(f: B \to A\) to the natural transformation \(g \mapsto gf\). So functoriality follows from associativity.
\end{proof}

We call this functor (or the functor \(\c C \to [\c C^{\text{op}}, \Set]\) sending \(A\) to \(\c C(-, A)\)) the \emph{Yoneda embedding} of \(\c C\) and typically denote it by \(Y\). At first glance, \([\c C, \Set]\) seems like a much more complicated entity and is much more unwieldy. However, it stands out as being more concrete and thus easier to deal with. It is in analogy with group representation: instead of an abstract group, we consider its action on a set, which is more explicit and concrete. We'll come back to this point in a minute.

Now return to the second part of the lemma. Suppose for the moment that \(\c C\) is small, so that \([\c C, \Set]\) is locally small. Then we have two functors \(\c C \times [\c C, \Set] \to \Set\): one sends \((A, F)\) to \(FA\), and the other is the composite
\[
  \c C \times [\c C, \Set]
  \xrightarrow{Y \times 1} [\c C, \Set]^{\text{op}} \times [\c C, \Set]
  \xrightarrow{[\c C, \Set] (-, -)} \Set
\]
where the last map maps a pair of functors to the set of natural transformations between them, and the naturality in the statement of Yoneda lemma says that these are naturally isomorphic. We can translate this into an elementary statement, making sense even when \(\c C\) isn't small: given \(A \xrightarrow{f} B\) and \(F \xrightarrow{\alpha} G\), there are two ways of producing an element of \(GB\) from the natural transformation. For example, given \(\beta: \c C(A, -) \to F\), the two ways give the same result, namely
\[
  \alpha_B(Ff) \beta_A (1_A) = (Gf)\alpha_A \beta_A (1_A)
\]
which is equal to \(\alpha_B\beta_B(f)\).
\[
  \begin{tikzcd}
    {[\c C, \Set](\c C(A, -), F)} \ar[rrr] \ar[ddd] \ar[dr, "\Phi_{A, F}"] &&& {[\c C, \Set](\c C(B, -), F)} \ar[ddd] \ar[dl, "\Phi_{B, F}"] \\
    & FA \ar[r, "Ff"] \ar[d, "\alpha_A"] & FB \ar[d, "\alpha_B"] \\
    & GB \ar[r, "Gf"] & GB \\
    {[\c C, \Set](\c C(A, -), G)} \ar[rrr] \ar[ur, "\Phi_{A, G}"] &&& {[\c C, \Set](\c C(B, -), G)} \ar[ul, "\Phi_{B, G}"] \\
  \end{tikzcd}
\]

\begin{definition}[representable functor, representation]\index{functor!representable}\index{universal element}
  We say a functor \(F: \c C \to \Set\) is \emph{representable} if it's isomorphic to \(\c C(A, -)\) for some \(A\).

  By a \emph{representation} of \(F\), we mean a pair \((A, x)\) where \(x \in FA\) is such that \(\Psi(x)\) is an isomorphism. We also call \(x\) a \emph{universal element} of \(F\).
\end{definition}

\begin{corollary}
  If \((A, x)\) and \((B, y)\) are both representations of \(F\), then there is a unique isomorphism \(f: A \to B\) such that \((Ff)(x) = y\).
\end{corollary}

\begin{proof}
  Consider the composite
  \[
    \c C(B, -) \xrightarrow{\Psi(y)} F \xrightarrow{\Psi(x)^{-1}} \c C(A, -),
  \]
  By Yoneda embedding, this is of the form \(Y(f)\) for a unique isomorphism \(f: A \to B\) and the diagram
  \[
    \begin{tikzcd}
      \c C(B, -) \ar[rr, "Y(f)"] \ar[dr, "\Psi(y)"'] & & \c C(A, -) \ar[dl, "\Psi(x)"] \\
      & F
    \end{tikzcd}
  \]
  commutes if and only if \((Ff) (x) = y\).
\end{proof}

\begin{eg}\leavevmode
  \label{eg:representable functor}
  \begin{enumerate}
  \item The forgetful functor \(\c{Gp} \to \Set\) is representable by \((\Z, 1)\). Similarly the forgetful functor \(\c{Rng} \to \Set\) is representable by \((\Z[x], x)\). The forgetful functor \(\Top \to \Set\) is representable by \((\{*\}, *)\).
  \item The functor \(P^*: \Set^{\text{op}} \to \Set\) is representable by \((\{0, 1\}, \{1\})\). This is the bijection between subsets and characteristic functions.
  \item Let \(G\) be a group. The unique (up to isomorphism) representable functor \(G(*, -): G \to \Set\) is the \emph{Cayley representation} of \(G\), i.e.\ the set \(UG\) with \(G\) acting by left multiplication.
  \item Let \(A\) and \(B\) be two objects of a locally small category \(\c C\). Then we have a functor \(\c C^{\text{op}} \to \Set\) sending \(C\) to \(\c C(C, A) \times \c C(C, B)\) (note that it is a purely categorical product and require only cartesian product of the morphism sets). A representation of this, if it exists, is called a (categorical) \emph{product}\index{product} of \(A\) and \(B\), and denoted
    \[
      \begin{tikzcd}
        & A \times B \ar[dl, "\pi_1"'] \ar[dr, "\pi_2"] \\
        A & & B
      \end{tikzcd}
    \]
    This pair has the property that, for any pair \((C \xrightarrow{f} A, C \xrightarrow{g} B)\), there is a unique \(C \xrightarrow{h} A \times B\) with \(\pi_1 h = f\) and \(\pi_2 h = g\).
    \[
      \begin{tikzcd}
        & A \times B \ar[dl, "\pi_1"'] \ar[dr, "\pi_2"] \\
        A & C \ar[l, "f"] \ar[r, "g"] \ar[u, "h", dashed] & B
      \end{tikzcd}
    \]

    Products exist in many categories of interest: in \(\Set, \c{Gp}, \c{Rng}, \Top, \dots\) they are ``just'' cartesian products. In posets they are binary meets.

    Dually, we have the notion of \emph{coproduct}\index{coproduct}
    \[
      \begin{tikzcd}
        & A + B \\
        A \ar[ur, "\nu_1"] & & B \ar[ul, "\nu_2"']
      \end{tikzcd}
    \]
    These also exist in many categories of interest.
  \item Let \(f, g: A \to B\) be morphisms in a locally small category \(\c C\). We have a functor \(F: \c C^{\text{op}} \to \Set\) defined by
    \[
      F(C) = \{h \in \c C(C, A): fh = gh\},
    \]
    which is a subfunctor of \(\c C(-, A)\). A representation of \(F\), if it exists, is called an \emph{equaliser}\index{equaliser} of \((f, g)\). It consists of an object \(E\) and a morphism \(E \xrightarrow{e} A\) such that \(fe = ge\) and every \(h\) with \(fh = gh\) factors uniquely through \(e\). In \(\Set\), we take \(E = \{x \in A: f(x) = g(x)\}\) and \(e\) to be inclusion. Similar constructions work in \(\c{Gp}, \c{Rng}, \Top, \dots\)
    \[
      \begin{tikzcd}
        E \ar[r, "e"] & A \ar[r, "f", shift left] \ar[r, "g"', shift right] & B \\
        C \ar[u, dashed] \ar[ur, "h"]
      \end{tikzcd}
    \]

    Dually we have the notion of \emph{coequaliser}\index{coequaliser}.
  \end{enumerate}
\end{eg}

\begin{remark}
  If \(e\) occurs as an equaliser then it is a monomorphism, since any \(h\) factors through it in at most one way. We say a monomorphism is \emph{regular}\index{monomorphism!regular} if it occurs as an equaliser.

  Split monomorphisms are regular (see example sheet 1 Q6 (i)). Note that a regular mono that is also epic implies isomorphism: if the equaliser \(e\) of \((f, g)\) is epic then \(f = g\) so \(e \cong 1_{\cod e}\).
\end{remark}

\begin{definition}[separating/detecting family, seperator, detector]\index{separating family}\index{detecting family}\index{separator}\index{detector}
  Let \(\c C\) be a category, \(\mathcal G\) a class of objects of \(\c C\).
  \begin{enumerate}
  \item  We say \(\mathcal G\) is a \emph{separating family} for \(\c C\) if, given \(f, g: A \to B\) such that \(fh = gh\) for all \(G \xrightarrow{h} A\) with \(G \in \mathcal G\) then \(f = g\). (i.e.\ the functor \(\c C(G, -)\) where \(G \in \mathcal G\) are collectively faithful)
  \item We say \(\mathcal G\) is a \emph{detecting family}  for \(\c C\) if, given \(A \xrightarrow{f} B\) such that every \(G \xrightarrow{h} B\) with \(G \in \mathcal G\) factors uniquely through \(f\), then \(f\) is an isomorphism.
  \end{enumerate}

  If \(\mathcal G = \{G\}\) then we call \(G\) a \emph{separator} or \emph{detector}.
\end{definition}

\begin{lemma}\leavevmode
  \begin{enumerate}
  \item If \(\c C\) is a balanced category then any separating family is detecting.
  \item If \(\c C\) has equalisers (i.e.\ every pair has an equaliser) then any detecting family is separating.
  \end{enumerate}
\end{lemma}

\begin{proof}\leavevmode
  \begin{enumerate}
  \item Suppose \(\mathcal G\) is separating and \(A \xrightarrow{f} B\) satisfies condition in definition 2.
    If \(g, h: B \to C\) satisfy \(gf = hf\), then \(gx = hx\) for every \(G \xrightarrow{x} B\), so \(g = h\), i.e.\ \(f\) is epic.

    Similarly if \(k, \ell: D \to A\) satisfy \(fk = f\ell\) then \(ky = \ell y\) for any \(G \xrightarrow{y} D\), since both are factorisations of \(fky\) through \(f\). So \(k = \ell\), i.e.\ \(f\) is monic.
  \item Suppose \(\mathcal G\) is detecting and \(f, g: A \to B\) satisfy definition 1. Then the equaliser \(E \xrightarrow{e} A\) of \((f, g)\) is isomorphism so \(f = g\).
  \end{enumerate}
\end{proof}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item In \([\c C, \Set]\) the family \(\{\c C(A, -): A \in \ob \c C\}\) is both separating and detecting. This is just a restatement of Yoneda lemma.
  \item In \(\Set\), \(1 = \{*\}\) is both a separator and a detector since it represents the identity functor \(\Set \to \Set\). Similarly \(\Z\) is both in \(\c{Gp}\) since it represents the forgetful functor \(\c{Gp} \to \Set\).

    Dually, \(2 = \{0, 1\}\) is a coseparator and a codetector in \(\Set\) since it represents \(P^*: \Set^{\text{op}} \to \Set\).
  \item In \(\Top\), \(1 = \{*\}\) is a separator since it represents the forgetful functor \(\Top \to \Set\), but not a detector. In fact \(\Top\) has no detecting \emph{set} of objects: for any infinite cardinality \(\kappa\), let \(X\) be a discrete space of cardinality \(\kappa\), and \(Y\) the same set with ``co-\(\kappa\)'' topology, i.e.\ \(F \subseteq Y\) closed if and only if \(F = Y\) or \(F\) has cardinality smaller \(\kappa\). The identity map \(X \to Y\) is continuous but not a homomorphism. So if \(\{G_i: i \in I\}\) is any set of spaces, taking \(\kappa\) larger than cardinality of \(G_i\) for all \(i\) yields an exmaple to show that the set is not detecting.
  \item Let \(\c C\) be the category of pointed conntected CW-complexes and homotopy classes of (basepoint-preserving) continuous maps. J.\ H.\ C.\ Whitehead proved that if \(X \xrightarrow{f} Y\) in this category induces isomorphisms \(\pi_n(X) \to \pi_n(Y)\) for all \(n\) then it is an isomorphism in \(\c C\). This says that \(\{S^n: n \geq 1\}\) is a detecting set for \(\c C\). But P.\ J.\ Freyd showed there is no faithful functor \(\c C \to \Set\), so no separating \emph{set}: if \(\{G_i: i \in I\}\) were separating then
    \[
      X \mapsto \coprod_{i \in I} \c C(G_i, X)
    \]
    would be faithful.
  \end{enumerate}
\end{eg}

Note that any functor of the form \(\c C(A, -)\) preserves monos, but they don't preserve epis. We give a name to those special functors.

\begin{definition}[projective, injective]\index{projective}\index{injective}
  We say an object \(P\) is \emph{projective} if given
  \[
    \begin{tikzcd}
      & P \ar[d, "f"] \ar[dl, "g"', dashed] \\
      A \ar[r, "e", twoheadrightarrow] & B
    \end{tikzcd}
  \]
  there exists \(P \xrightarrow{g} A\) with \(eg = f\). If \(\c C\) is locally small, this says \(\c C(P, -)\) preserves epimorphisms.

  Dually an \emph{injective} object of \(\c C\) is a projective object of \(\c C^{\text{op}}\).

  Given a class \(\mathcal E\) of epimorphisms, we say \(P\) is \emph{\(\mathcal E\)-projective} if it satisfies the condition for all \(e \in \mathcal E\).
\end{definition}

\begin{lemma}
  \label{lem:representable functors are projectives}
  Representable functors are (pointwise) projectives in \([\c C, \Set]\).
\end{lemma}

\begin{proof}
  Suppose given
  \[
    \begin{tikzcd}
      & \c C(A, -) \ar[d, "\beta"] \ar[dl, "\gamma"', dashed]\\
      F \ar[r, "\alpha"] & G
    \end{tikzcd}
  \]
  where \(\alpha\) is pointwise surjective. By Yoneda, \(\beta\) corresponds to some \(y \in GA\) and we can find \(x \in FA\) with \(\alpha_A(x) = y\). Now if \(\gamma: \c C(A, -) \to F\) corresponds to \(x\), then naturality of the Yoneda bijection yields \(\alpha\gamma = \beta\).
\end{proof}

\section{Adjunctions}

\begin{definition}[adjunction]\index{adjunction}
  Let \(\c C\) and \(\c D\) be two categories and \(F: \c C \to \c D, G: \c D \to \c C\) be two functors. By an \emph{adjunction} between \(F\) and \(G\) we mean a bijection between morphisms \(\hat f: FA \to B\) in \(\c D\) and \(f: A \to GB\) in \(\c C\), which is natural in \(A\) and \(B\), i.e.\ given \(A' \xrightarrow{g} A\) and \(B \xrightarrow{h} B'\), \(h \hat f(Fg) = \widehat{(Gh) fg}: FA' \to B'\)
  \[
    \begin{tikzcd}
      FA \ar[r, "\hat f"] & B \ar[d, "h"] \\
      FA' \ar[u, "Fg"] \ar[r, dashed] & B'
    \end{tikzcd}
    \qquad
    \begin{tikzcd}
      A \ar[r, "f"] & GB \ar[d, "Gh"] \\
      A' \ar[u, "g"] \ar[r, dashed] & GB'
    \end{tikzcd}
  \]
  We say \(F\) is \emph{left adjoint} to \(G\) and write \(F \adjoint G\).
\end{definition}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item The functor \(F: \Set \to \c{Gp}\) is left adjoint to the forgetful functor \(U: \c{Gp} \to \Set\) since any function \(f: A \to UB\) extends uniquely to a group homomorphism \(\hat f: FA \to B\) and any homomorphism induces a set function. Naturality in \(B\) is easy and naturality in \(A\) follows from the definition of \(F\) as a functor. Similar for \(\c{Rng}, \c{Mod}_K, \dots\)
  \item The forgetful functor \(U: \Top \to \Set\) has a left adjoint \(D\) which equips any set with the discrete topology and a right adjoint \(I\) which equips any set with the indiscrete topology so \(D \adjoint U \adjoint I\).
  \item The functor \(\ob: \c{Cat} \to \Set\) (recall that \(\c{Cat}\) is the category of small categories) has a left adjoint \(D\) sending \(A\) to the discrete category with \(\ob(DA) = A\) and only identity morphisms, and a right adjoint \(I\) sending \(A\) to the category with \(\ob(IA) = A\) and one morphism \(x \to y\) for each \((x, y) \in A \times A\). In this case \(D\) in turn has a left adjoint \(\pi_0\) sending a small category \(\c C\) to its set of \emph{connected components}, i.e.\ the quotient of \(\ob \c C\) by the smallest equivalence relation identifying \(\dom f\) with \(\cod f\) for all \(f \in \mor \c C\). So \(\pi_0 \adjoint D \adjoint \ob \adjoint I\).
  \item Let \(M\) be the monoid \(\{1, e\}\) with \(e^2 = e\). An object of \([M, \Set]\) is a pair \((A, e)\) where \(e: A \to A\) satisfying \(e^2 = e\). We have a functor \(G: [M, \Set] \to \Set\) sending \((A, e)\) to
    \[
      \{x \in A: e(x) = x\} = \{e(x): x \in A\}
    \]
    and a functor \(F: \Set \to [M, \Set]\) sending \(A\) to \((A, 1_A)\). Claim that
    \[
      F \adjoint G \adjoint F.
    \]
    Given \(f: (A, 1_A) \to (B, e)\), it must take values in \(G(B, e)\) and any \(g: (B, e) \to (A, 1_A)\) is determined by its values on the image of \(e\). In some way this is due to the two ways in which the fixed point of \(e\) can be written.
  \item Let \(\c 1\) be the discrete category with one object \(*\). For any \(\c C\), there is a unique functor \(\c C \to \c 1\). A left adjoint for this picks out an \emph{initial object}\index{initial object} of \(\c C\), i.e.\ an object \(I\) such that there exists a unique \(I \to A\) for each \(A \in \ob C\). Dually a right adjoint for \(\c C \to \c 1\) corresponds to a \emph{terminal object}\index{terminal object} of \(\c C\).
  \item Let \(A \xrightarrow{f} B\) be a morphism in \(\Set\). We can regard \(PA\) and \(PB\) as posets, and we have functors \(Pf: PA \to PB\) and \(P^*f: PB \to PA\). Claim \(Pf \adjoint P^*f\): we have \(Pf(A') \subseteq B'\) if and only if \(f(x) \in B'\) for all \(x \in A'\), if and only if \(A' \subseteq P^*f(B')\).
  \item Galois connection: suppose givens sets \(A\) and \(B\) and a relation \(R \subseteq A \times B\). We define mappings \(\cdot^\ell, \cdot^r\) between \(PA\) and \(PB\)  by
    \begin{align*}
      S^r &= \{y \in B: \forall x \in S, (x, y) \in R\}, S \subseteq A \\
      T^\ell &= \{x \in A: \forall y \in T, (x, y) \in R\}, T \subseteq B
    \end{align*}
    These mappings are order-reversing, i.e.\ contravariant functors, and \(T\subseteq S^r\) if and only if \(S \times T \subseteq R\), so by symmetry if and only if \(S \subseteq T^\ell\). We say \(\cdot^r\) and \(\cdot^\ell\) are \emph{adjoint on the right}\index{adjoints on the right}.
  \item The functor \(P^*: \Set^{\text{op}} \to \Set\) is self-adjoint on the right since a function \(A \to PB\) corresponds bijectively to subsets of \(A \times B\), and hence by symmetry to functions \(B \to PA\). % IID Logic and set
  \end{enumerate}
\end{eg}

\begin{theorem}
  \label{thm:unit-counit characterisation of adjunction}
  Let \(G: \c D \to \c C\) be a functor. Then specifying a left adjoint functor for \(G\) is equivalent to specifying an initial object of \((A \downarrow G)\) for each \(A \in \ob \c C\) where \((A \downarrow G)\)\index{arrow category} has objects pairs \((B, f)\) with \(A \xrightarrow{f} GB\) and morphisms \((B, f) \to (B', f')\) are morphisms \(B \xrightarrow{g} B'\) such that the following diagram commutes
  \[
    \begin{tikzcd}
      A \ar[r, "f"] \ar[dr, "f'"'] & GB \ar[d, "Gg"] \\
      & GB'
    \end{tikzcd}
  \]
\end{theorem}

\begin{proof}
  Suppose given \(F \adjoint G\). Consider the morphism \(\eta_A: A \to GFA\) corresponding to \(FA \xrightarrow{1} FA\). Then \((FA, \eta_A)\) is an object of \((A \downarrow G)\). Moreover, given \(g: FA \to B\) and \(f: A \to GB\), the diagram
  \[
    \begin{tikzcd}
      A \ar[r, "\eta_A"] \ar[dr, "f"'] & GFA \ar[d, "Gg"] \\
      & GB
    \end{tikzcd}
  \]
  commutes if and only if
  \[
    \begin{tikzcd}
      FA \ar[r, "1_A"] \ar[dr, "\hat f"'] & FA \ar[d, "g"] \\
      & B
    \end{tikzcd}
  \]
  commutes by naturality condition in adjunction, i.e.\ \(g = \hat f\). So \((FA, \eta_A)\) is initial to \((A \downarrow G)\).

  Conversely, suppose given an initial object \((FA, \eta_A)\) for each \((A \downarrow G)\). Given \(f: A \to A'\), we define \(Ff: FA \to FA'\) to be the unique morphism making
  \[
    \begin{tikzcd}
      A \ar[r, "\eta_A"] \ar[d, "f"] & GFA \ar[d, "GFf"] \\
      A' \ar[r, "\eta_{A'}"] & GFA'
    \end{tikzcd}
  \]
  commutes. Functoriality follows from uniqueness: given \(f': A' \to A''\), both \(F(f'f)\) and \((Ff')(Ff)\) are both morphisms \((FA, \eta_A) \to (FA'', \eta_{A''}f'f)\) in \((A \downarrow G)\). To show \(F \adjoint G\): given \(A \xrightarrow{f} GB\), we define \(\hat f: FA \to B\) to be the unique morphism \((FA, \eta_A) \to (B, f)\) in \((A \downarrow G)\). This is a bijection with inverse
  \[
    (FA \xrightarrow{g} B) \mapsto (A \xrightarrow{\eta_A} GFA \xrightarrow{Gg} GB).
  \]
  The latter mapping is natural in \(B\) since \(G\) is a functor, and in \(A\) since by construction \(\eta\) is a natural transformation \(1_{\c C} \to GF\).
\end{proof}

\begin{corollary}
  If \(F\) and \(F'\) are both left adjoint to \(G: \c D \to \c C\) then they are naturally isomorphic.
\end{corollary}

\begin{proof}
  It basically follows from the fact that initial object in any category, if exists, is unique up to isomorphism. For any \(A\), \((FA, \eta_A)\) and \((F'A, \eta'_A)\) are both initial in \((A \downarrow G)\) so there is a unique isomorphism
  \[
    \alpha_A: (FA, \eta_A) \to (F'A, \eta'_A).
  \]
  In any naturality square for \(\alpha\), the two ways round are both morphisms in \((A \downarrow G)\) whose domain is initial, so they're equal.
\end{proof}

\begin{lemma}
  \label{lem:composition of adjoints}
  Given
  \[
    \begin{tikzcd}
      \c C \ar[r, "F", shift left] & \c D \ar[l, "G", shift left] \ar[r, "H", shift left] & \c E \ar[l, "K", shift left]
    \end{tikzcd}
  \]
  with \(F \adjoint G\) and \(H \adjoint K\), we have
  \[
    HF \adjoint GK.
  \]
\end{lemma}

\begin{proof}
  We have bijections between morphisms \(A \to GKC\), morphisms \(FA \to KC\) and morphisms \(HFA \to C\), which are both natural in \(A\) and \(C\).
\end{proof}

\begin{corollary}
  \label{cor:commutative square of adjoints}
  Given a commutative square
  \[
    \begin{tikzcd}
      \c C \ar[r] \ar[d] & \c D \ar[d] \\
      \c E \ar[r] &\c F
    \end{tikzcd}
  \]
  of categories and functors, if the functors all have left adjoints, then the diagram of left adjoints commutes up to natural isomorphsms.
\end{corollary}

\begin{proof}
  By \Cref{lem:composition of adjoints}, both ways round the diagram of left adjoints are left adjoint to the composite \(\c C \to \c F\), so by \Cref{thm:unit-counit characterisation of adjunction} they are isomorphic.
\end{proof}

Actually, we didn't use the full strength of \Cref{lem:composition of adjoints}: if we require merely instead that the original commutative diagram is only up to natural isomorphism, then we'll get the same conclusion. In practice, however, the weaker version stated above will usually suffice.

\begin{definition}[unit, counit]\index{unit}\index{counit}
  Given an adjunction \(F \adjoint G\), the natural transformation \(\eta: 1_{\c C} \to GF\) emerging in the proof of \Cref{thm:unit-counit characterisation of adjunction} is called the \emph{unit} of the adjunction.

  Dually we have a natural transformation \(\varepsilon: FG \to 1_{\c D}\) such that \(\varepsilon_B: FGB \to B\) corresponds to \(GB \xrightarrow{1_{GB}} GB\), is called the \emph{counit}.
\end{definition}

\begin{theorem}
  Given \(F: \c C \to \c D, G: \c D \to \c C\), specifying an adjunction \(F \adjoint G\) is equivalent to specifying two natural transformations
  \begin{align*}
    \eta: 1_{\c C} &\to GF \\
    \varepsilon: FG &\to 1_{\c D}
  \end{align*}
  satisfying the commutative diagrams
  \[
    \begin{tikzcd}
      F \ar[r, "F\eta"] \ar[dr, "1_F"'] & FGF \ar[d, "\varepsilon_F"] \\
      & F
    \end{tikzcd}
    \qquad
    \begin{tikzcd}
      G \ar[r, "\eta_G"] \ar[dr, "1_G"'] & GFG \ar[d, "G\varepsilon"] \\
      & G
    \end{tikzcd}
  \]
  which are called the \emph{triangular identities}.\index{triangular identities}
\end{theorem}

\begin{proof}
  First suppose given \(F \adjoint G\). Define \(\eta\) and \(\varepsilon\) as in \Cref{thm:unit-counit characterisation of adjunction} and its dual. Now consider the composite
  \[
    FA \xrightarrow{F\eta_A} FGFA \xrightarrow{\varepsilon_{FA}} FA.
  \]
  Under the adjunction this corresponds to
  \[
    A \xrightarrow{\eta_A} GFA \xrightarrow{1_{GFA}} GFA
  \]
  but this also corresponds to \(1_{FA}\) so \(\varepsilon_{FA} F\eta_A = 1_{FA}\). The other identity is dual.

  Conversely, suppose \(\eta\) and \(\varepsilon\) satisfying the trianglular identities. Given \(A \xrightarrow{f} GB\), let \(\Phi(f)\) be the composite
  \[
    FA \xrightarrow{Ff} FGB \xrightarrow{\varepsilon_B} B
  \]
  and given \(FA \xrightarrow{g} B\), let \(\Psi(g)\) be
  \[
    A \xrightarrow{\eta_A} GFA \xrightarrow{Gg} GB.
  \]
  Then both \(\Phi\) and \(\Psi\) are both natural. Need to show that \(\Phi\Psi\) and \(\Psi\Phi\) are identity mappings. But
  \begin{align*}
    &\Psi\Phi(A \xrightarrow{f} GB) \\
    =& A \xrightarrow{\eta_A} GFA \xrightarrow{GFf} GFGB \xrightarrow{G \varepsilon_B} GB \\
    =& A \xrightarrow{f} GB \xrightarrow{\eta_{GB}} GFGB \xrightarrow{G\varepsilon_B} GB \\
    =& A \xrightarrow{f} GB
  \end{align*}
  where the second equality is naturality of \(\eta\) and the third equality is triangular equation. Dually \(\Phi\Psi(g) = g\).
\end{proof}

Sometimes this is taken to be the definition of adjunction.

Obviously two inverse functors form an adjunction. We have seen before a weaker notion of inverse, namely a pair of functors forming an equivalence of categories. The question is, do they always from an adjunction? The answer is yes, but sometimes we can't see it since we've chosen the wrong isomorphism.

\begin{lemma}
  Given functors \(F: \c C \to \c D, G: \c D \to \c C\) and natural isomorphisms
  \begin{align*}
    \alpha: 1_{\c C} &\to GF \\
    \beta: FG &\to 1_{\c D}
  \end{align*}
  there are isomorphism
  \begin{align*}
    \alpha': 1_{\c C} &\to GF \\
    \beta': FG &\to 1_{\c D}
  \end{align*}
  which satisfy the triangular identities so \(F \adjoint G\) and \(G \adjoint F\).
\end{lemma}

This is often summarised as ``every equivalence is an adjoint equivalence''.

\begin{proof}
  We fix \(\alpha' = \alpha\) and modify \(\beta\). We have to change the domain and codomain of \(\beta\) by conjugation.

  Let \(\beta'\) be the composite
  \[
    FG \xrightarrow{(FG\beta)^{-1}} FGFG \xrightarrow{(F\alpha_G)^{-1}} FG \xrightarrow{\beta} 1_{\c D}.
  \]
  Note that \(FG\beta = \beta_{FG}\) since
  \[
    \begin{tikzcd}
      FGFG \ar[r, "FG\beta"] \ar[d, "\beta_{FG}"] & FG \ar[d, "\beta"] \\
      FG \ar[r, "\beta"] & 1_{\c D}
    \end{tikzcd}
  \]
  commmutes by naturality of \(\beta\) and \(\beta\) is monic.

  Now \((\beta'_F)(F\alpha')\) is the composite
   \begin{align*}
     &F \xrightarrow{F\alpha} FGF \xrightarrow{(\beta_{FGF})^{-1}} FGFGF \xrightarrow{(F\alpha_{GF})^{-1}} FGF \xrightarrow{\beta_F} F \\
     =& F \xrightarrow{(\beta_F)^{-1}} FGF \xrightarrow{FGF\alpha} FGFGF \xrightarrow{(F\alpha_{GF})^{-1}} FGF \xrightarrow{\beta_F} F \\
     =& F \xrightarrow{(\beta_F)^{-1}} FGF \xrightarrow{\beta_F} F \\
     =& 1_F
   \end{align*}
  since \(GF \alpha = \alpha_{GF}\). Similarly \((G\beta')(\alpha'_G)\) is
  \begin{align*}
    &G \xrightarrow{\alpha_G} GFG \xrightarrow{(GFG\beta)^{-1}} GFGFG \xrightarrow{(GF\alpha_G)^{-1}} GFG \xrightarrow{G\beta} G \\
    =& G \xrightarrow{(G\beta)^{-1}} GFG \xrightarrow{\alpha_{GFG}} GFGFG \xrightarrow{(GF\alpha_G)^{-1}} GFG \xrightarrow{G\beta} G \\
    =& G \xrightarrow{(G\beta)^{-1}} GFG \xrightarrow{G\beta} G \\
    =& 1_G
  \end{align*}
\end{proof}

\begin{lemma}
  Suppose \(G: \c D \to \c C\) has a left adjoint \(F\) with counit \(\varepsilon: FG \to 1_{\c D}\), then
  \begin{enumerate}
  \item \(G\) is faithful if and only if \(\varepsilon\) is pointwise epic,
  \item \(G\) is full and faithful is and only if \(\varepsilon\) is an isomorphism.
  \end{enumerate}
\end{lemma}

\begin{proof}\leavevmode
  \begin{enumerate}
  \item Given \(B \xrightarrow{g} B'\), \(Gg\) corresponds under the adjunction to the composite
    \[
      FGB \xrightarrow{\varepsilon_B} B \xrightarrow{g} B'.
    \]
    Hence the mapping \(g \mapsto Gg\) is injective on morphisms with domain \(B\) (and specified codomain) if and only if \(g \mapsto g\varepsilon_B\) is injective, if and only if \(\varepsilon_B\) is epic.
  \item Similarly, \(G\) is full and faithful if and only if \(g \mapsto g\varepsilon_B\) is bijective. If \(\alpha: B \to FGB\) is such that \(\alpha\varepsilon_B = 1_{FGB}\), i.e.\ \(\alpha\) is left inverse of \(\varepsilon_B\), then
    \[
      \varepsilon_B\alpha \varepsilon_B = \varepsilon_B,
    \]
    whence \(\varepsilon_B\alpha = 1_B\). So \(\varepsilon_B\) is an isomophism. Thus \(\varepsilon\) is an isomorphism.
  \end{enumerate}
\end{proof}

\begin{definition}[reflection, reflective subcategory]\index{reflection}\index{reflective subcategory}
  By a \emph{reflection} we mean an adjunction in which the right adjoint is full and faithful (equivalently the counit is an isomorphism).

  We say a full subcategory \(\c C' \subseteq \c C\) is \emph{reflective} if the inclusion \(\c C' \to \c C\) has a left adjoint.
\end{definition}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item The category \(\c{AbGp}\) of abelian groups is reflective in \(\c{Gp}\): the left adjoint sends a group \(G\) to its \emph{abelianization} \(G/G'\), where \(G'\) is the subgroup generated by all commutators \([x, y] = xyx^{-1}y^{-1}\) for \(x, y \in G\). (The unit of the adjunction is the quotient map \(G \to G/G'\))

    This is where the name ``reflecting subcategory'' comes from: mirror is 2D so reflection in a mirror cannot create a copy of a 3D object. However, it keeps every 2D detail fully and faithfully. Similarly abelianization does not tell you everything about \(G\) but as much as an abelian group can. c.f.\ universal property.
  \item Given an abelian group, let \(A_T\) denote the torsion subgroup, i.e.\ the subgroup of elements of finite orders. The assigment \(A \mapsto A/A_T\) gives a left adjoint to the inclusion \(\c{tfAbGp} \to \c{AbGp}\), where \(\c{tfAbGp}\) is the full subcategory of torsion-free abelian groups.

    On the other hand \(A \mapsto A_T\) is the right adjoint to the inclusion \(\c{tAbGp} \to \c{AbGp}\) from torsion abelian groups to abelain groups, so this subcategory is coreflective. There are many many examples in algebra involving (co)reflective subcategories, and the constructions all give rise to important universal properries.
  \item Let \(\c{KHaus} \subseteq \Top\) be the full subcategory of compact Hausdorff spaces. The inclusion \(\c{KHaus} \to \Top\) has a left adjoint \(\beta\), the \emph{Stone-Čech compactification}\index{Stone-Čech compactification}. It is a reflective subcategory. We'll revisit this example later in the course.
  \item Let \(X\) be a topological space. We say \(A\subseteq X\) is \emph{sequentially closed} if \(x_n \to x_\infty\) and \(x_n \in A\) for all \(n\) implies \(x_\infty \in A\). Note that closed implies sequentially closed but not vice versa. We say \(X\) is \emph{sequential} if all sequentially closed sets are closed, e.g.\ a metric space. Given a non-sequential space \(X\), let \(X_s\) be the same set with topology given by the sequentially open sets (complements of sequentially closed sets) in \(X\). Certainly the identity \(X_s \to X\) is continuous, and defines the counit of an adjunction between the inclusion \(\c{Seq} \to \Top\) and its right adjoint \(X \mapsto X_s\).
  \item If \(X\) is a topological space, the poset \(CX\) of closed subsets of \(X\) is reflective in \(PX\) with reflector given by closure and the poset \(OX\) of open subsets is coreflective with coreflector given by interior.
  \end{enumerate}
\end{eg}

\section{Limits}

\begin{definition}[diagram, cone, limit]\index{diagram}\index{cone}\index{diagram}\leavevmode
  \begin{enumerate}
  \item Let \(\c J\) be a category (almost always small, often finite). By a \emph{diagram of shape \(\c J\)} in \(\c C\) we mean a functor \(D: \c J \to \c C\). The objects \(D(j)\) for \(j \in \ob \c J\) are called \emph{vertices} of the diagram and the morphisms \(D(\alpha)\) \(\alpha \in \mor \c J\) are called \emph{edges} of \(D\).
 \item Given \(D: \c J \to \c C\), a \emph{cone} over \(D\) consists of an object \(A\) of \(\c C\), called the \emph{apex} of the cone, together with morphisms \(A \xrightarrow{\lambda_j} D(j)\) for each \(j \in \ob \c J\), called the \emph{legs} of the cone, such that
    \[
      \begin{tikzcd}
        & A \ar[dl, "\lambda_j"'] \ar[dr, "\lambda_{j'}"] \\
        D(j) \ar[rr, "D(\alpha)"] && D(j')
      \end{tikzcd}
    \]
    commutes for all \(j \xrightarrow{\alpha} j'\) in \(\mor \c J\).

    Given cones \((A, (\lambda_j)_{j \in \ob \c J})\) and \((B, (\mu_j)_{j \in \ob \c J})\), a \emph{morphism} of cones between them is a morphism \(A \xrightarrow{f} B\) such that
    \[
      \begin{tikzcd}
        A \ar[dr, "\lambda_j"'] \ar[rr, "f"] && B \ar[dl, "\mu_j"] \\
        & D(j)
      \end{tikzcd}
    \]
    commutes for all \(j\).

    We write \(\Cone(D)\) for the category of all cones over \(D\).
  \item A \emph{limit} for \(D\) is a terminal object of \(\Cone(D)\), if this exists.

    Dually we have the notion of cone \emph{under} a diagram (sometime called \emph{cocone}) and of \emph{colimit} (i.e.\ initial cone under \(D\)).
  \end{enumerate}
\end{definition}

For example, if \(\c J\) is the category
\[
  \begin{tikzcd}
    \cdot \ar[r] \ar[d] \ar[dr] & \cdot \ar[d] \\
    \cdot \ar[r] & \cdot
  \end{tikzcd}
\]
with 4 objects and 5 non-identity morphisms, a diagram of shape \(\c J\) is a commutative square
\[
  \begin{tikzcd}
    A \ar[r, "f"] \ar[d, "g"] & B \ar[d, "h"] \\
    C \ar[r, "k"] & D
  \end{tikzcd}
\]

On the other hand, to express a not-necessarily-commutative square, we use the shape
\[
  \begin{tikzcd}
    \cdot \ar[r] \ar[d] \ar[dr, shift left] \ar[dr, shift right] & \cdot \ar[d] \\
    \cdot \ar[r] & \cdot
  \end{tikzcd}
\]

An alternative way to understand limits is that, if \(\c C\) is locally small and \(\c J\) is small, we have a functor \(\c C^{\text{op}} \to \Set\) sending \(A\) to the set of cones with apex \(A\). A limit for \(D\) is a representation of this functor.

A thrid way to visualise cones: if \(\Delta A\) denotes the constant diagram of shape \(\c J\) with all vertices \(A\) and all edges \(1_A\), then a cone over \(D\) with apex \(A\) is the same thing as a natural transformation \(\Delta A \to D\). \(\Delta\) is a functor \(\c C \to [\c J, \c C]\) and \(\Cone(D)\) is the arrow category \((\Delta \downarrow D)\). So to say that every diagram of shape \(\c J\) in \(\c C\) has a limit is equivalent to saying that \(\Delta\) has a right adjoint. (We say \(\c C\) \emph{has limits} of shape \(\c J\))

Dually \(\c C\) has colimits of shape \(\c J\) if and only if \(\Delta: \c C \to [\c J, \c C]\) has a left adjoint.

\begin{eg}\leavevmode
  \begin{enumerate}
  \item Suppose \(J = \emptyset\). There is a unique diagram of shape \(\c J\) in \(\c C\); a cone over it is just an object, and a morphism of cones is a morphism of \(\c C\). So a limit for the empty diagram is a terminal object of \(\c C\). We defined limits in terms of terminal object but now the terminal object is also a special limit. Dually a colimit for it is an initial object.
  \item Let \(\c J\) be the category
    \[
      \begin{tikzcd}
        \cdot & \cdot
      \end{tikzcd}
    \]
    A diagram of shape \(\c J\) is a pair of objects \(A, B\); a cone over it is a span
    \[
      \begin{tikzcd}
        & C \ar[dl] \ar[dr] \\
        A & & B
      \end{tikzcd}
    \]
    and a limit for it is a \emph{product}\index{product}
    \[
      \begin{tikzcd}
        & A \times B \ar[dl, "\pi_1"'] \ar[dr, "\pi_2"] \\
        A & & B
      \end{tikzcd}
    \]
    as defined in example~4 on page~\pageref{eg:representable functor}. Dually a colimit for it is a \emph{coproduct}\index{coproduct}.

    More generally, if \(\c J\) is a small discrete category, a diagram of shape \(\c J\) is an indexed family \((A_j: j \in \c J)\), and a limit for it is a product \((\prod_{j \in \c J} A_j \xrightarrow{\pi_j} A_j: j \in \c J)\). Dually, \((A_j \xrightarrow{\nu_j} \sum_{j \in \c J} A_j: j\in \c J)\), sometimes also written as \(\coprod_{j \in \c J} A_j\).
  \item Let \(\c J\) be the category
    \[
      \begin{tikzcd}
        \cdot \ar[r, shift left] \ar[r, shift right] & \cdot
      \end{tikzcd}
    \]
    A diagram of shape \(\c J\) is a parallel pair
    \[
      \begin{tikzcd}
        A \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & B
      \end{tikzcd}
    \]
    a cone over it is
    \[
      \begin{tikzcd}
        & C \ar[dl, "h"'] \ar[dr, "k"] \\
        A & & B
      \end{tikzcd}
    \]
    satisfying \(fh = k = gh\), or equivalently a morphism \(h: C \to A\) satisfying \(fh = gh\). A (co)limit for the diagram is a \emph{(co)equaliser}\index{equaliser}\index{coequaliser} as defined in example~5 on page~\pageref{eg:representable functor}.
  \item Let \(\c J\) be the category
    \[
      \begin{tikzcd}
        & \cdot \ar[d] \\
        \cdot \ar[r] & \cdot
      \end{tikzcd}
    \]
    A diagram of shape \(\c J\) is a cospan
    \[
      \begin{tikzcd}
        & A \ar[d, "f"] \\
        B \ar[r, "g"] & C
      \end{tikzcd}
    \]
    a cone over it is
    \[
      \begin{tikzcd}
        D \ar[r, "p"] \ar[d, "q"] \ar[dr, "r"] & A \\
        B & C
      \end{tikzcd}
    \]
    satisfying \(fp = r = gq\), or equivalently a span \((p, q)\) completing the diagram to a commutative square. A limit for the diagram is called a \emph{pullback}\index{pullback} of \((f, g)\). In \(\Set\), the apex of the pullback is the ``fibre product''
    \[
      A \times_C B = \{(x, y): A \times B: f(x) = g(y)\}.
    \]
    Dually, colimits of shape \(\c J^{\text{op}}\) are \emph{pushouts}\index{pushout}. Given
    \[
      \begin{tikzcd}
        A \ar[r, "f"] \ar[d, "g"] & B \\
        C
      \end{tikzcd}
    \]
    we ``push \(g\) along \(f\)'' to get the RHS of the colimt square.
  \item Let \(\c J\) be the poset of natural numbers. A diagram of shape \(\c J\) is a \emph{directed system}
    \[
      A_0 \xrightarrow{f_0} A_1 \xrightarrow{f_1} A_2 \xrightarrow{f_2} A_3 \xrightarrow{f_3} \dots
    \]
    A colimit for this is called a \emph{direct limit}\index{direct limit}: it consists of \(A_\infty\) equipped with morphisms \(A_n \xrightarrow{g_n} A_\infty\) satisfying \(g_n = g_{n + 1} f_n\) for all \(n\) and universal among such. Dually we have \emph{inverse system} and \emph{inverse limit}\index{inverse limit}.
  \end{enumerate}
\end{eg}

\begin{theorem}\leavevmode
  \label{thm:existence of limits}
  \begin{enumerate}
  \item Suppose \(\c C\) has equalisers and all finite (respectively small) products. Then \(\c C\) has all finite (respectively small) limits.
  \item Suppose \(\c C\) has pullbacks and a terminal object, then \(\c C\) has all finite limts.
  \end{enumerate}
\end{theorem}

\begin{proof}\leavevmode
  \begin{enumerate}
  \item Suppose given \(D: \c J \to \c C\). Form the industrial strength products
    \[
      P = \prod_{j \in \ob \c J} D(j), Q = \prod_{\alpha \in \mor \c J} D(\cod \alpha).
    \]
    We have morphisms \(f, g: P \to Q\) defined by
    \[
      \pi_\alpha f = \pi_{\cod \alpha}, \pi_\alpha g = D(\alpha) \pi_{\dom \alpha}
    \]
    for all \(\alpha\). Let \(e: E \to P\) be an equaliser of \((f, g)\). The composites
    \[
      \lambda_j = \pi_j e: E \to D(j)
    \]
    form a cone over \(D\): given \(\alpha: j \to j'\) in \(\c J\),
    \[
      D(\alpha) \lambda_j = D(\alpha) \pi_j e = \pi_\alpha ge = \pi_\alpha fe = \pi_{j'} e = \lambda_{j'}.
    \]
    Given any cone \((A, (\mu_j: j \in \ob \c J))\) over \(D\), there is a unique \(\mu: A \to P\) with \(\pi_j \mu = \mu_j\) for each \(j\) and
    \[
      \pi_\alpha f \mu = \mu_{\cod \alpha} = D(\alpha) \mu_{\dom \alpha} = \pi_\alpha g \mu
    \]
    for all \(\alpha\), and hence \(f\mu = g\mu\), so exists unique \(\nu: A \to E\) with \(e\nu = \mu\). So \((E, (\lambda_j: j \in \ob \c J))\) is a limit cone.
  \item It is enough to construct finite products and equalisers. But if \(1\) is the terminal object, then a pullback for
    \[
      \begin{tikzcd}
        & A \ar[d] \\
        B \ar[r] & 1
      \end{tikzcd}
    \]
    has the universal property of a product \(A \times B\) and we can form \(\prod_{i = 1}^n A_i\) inductively as
    \[
      A_1 \times (A_2 \times (A_3 \times \cdots (A_{n - 1} \times A_n)) \cdots).
    \]
    Now to form the equalisers of \(f, g: A \to B\), consider the cospan
    \[
      \begin{tikzcd}
        & A \ar[d, "{(1_A, f)}"] \\
        A \ar[r, "{(1_A, g)}"] & A \times B
      \end{tikzcd}
    \]
    A cone over this consists of
    \[
      \begin{tikzcd}
      P \ar[r, "h"] \ar[,d, "k"] & A \\
      A
      \end{tikzcd}
    \]
    satisfying \((1_A, f) h = (1_A, g) k\) or equivalently \(1_A h = 1_Ak\) and \(fh = gk\), or equivalently a morphism \(h: P \to A\) satisfying \(fh = gh\). So a pullback for \((1_A, f)\) and \((1_A, g)\) is an equaliser of \((f, g)\).
  \end{enumerate}
\end{proof}

\begin{definition}[complete, cocomplete]\index{category!complete}\index{category!cocomplete}
  We say a category \(\c C\) is \emph{complete} if it has all small limits. Dually, \(\c C\) is \emph{cocomplete} if has all small colimts.
\end{definition}

For example, \(\Set\) is both complete and cocomplete: products are cartesian products and coproducts are disjoint unions. Similarly \(\c{Gp}, \c{AbGp}, \c{Rng}, \c{Mod}_K\) are all complete and cocomplete.\footnote{Note that the products have underlying set the cartesian products of those of each component, but coproducts tend to be different. We'll discuss this later.} \(\Top\) is also complete and cocomplete, with both product and coproduct given by the underlying set.

\begin{definition}[preserve limit, reflect limit, create limit]\index{preserve limit}\index{preserve limit}\index{create limit}
  Let \(F: \c C \to \c D\) be a functor.
  \begin{enumerate}
  \item We say \(F\) \emph{preserves limits} of shape \(\c J\) if, given \(D: \c J \to \c C\) and a limit cone \((L, (\lambda_j: j \in \ob \c J))\) in \(\c C\), \((FL, (F\lambda_j: j \in \ob \c J))\) is a limit for \(FD\).
  \item We say \(F\) \emph{reflects limits} of shape \(\c J\) if, given \(D: \c J \to \c C\) and a cone \((L, (\lambda_j: j \in \ob \c J))\) such that \((FL, (F\lambda_j: j \in \ob \c J))\) is a limit for \(FD\) then \((L, (\lambda_j: j \in \ob \c J))\) for \(D\).
  \item We say \(F\) \emph{creates limts} of shape \(\c J\) if, given \(D: \c J \to \c C\) and a limit \((M, (\mu_j: j \in \ob \c J))\) for \(FD\), there exists a cone \((L, (\lambda_j: j \in \ob \c J))\) over \(D\) whose image under \(F\) is isomorphic to the limit cone, and any such cone is a limit for \(D\).
  \end{enumerate}
\end{definition}

\begin{remark}\leavevmode
  \begin{enumerate}
  \item If \(\c C\) has limits of shape \(\c J\) and \(F: \c C \to \c D\) preserves them and reflects isomorphisms then \(F\) reflects limits of shape \(\c J\).
  \item \(F\) reflects limits of shape \(1\) if and only if \(F\) reflects isomorphism.
  \item If \(\c D\) has limits of shape \(\c J\) and \(F: \c C \to \c D\) creates them, then \(F\) both preserves and reflects them.
  \item In any of the statement of \Cref{thm:existence of limits}, we may replace both instances of ``\(\c C\) has'' by either ``\(\c C\) has and \(F: \c C \to \c D\) preserves'' or ``\(\c D\) has and \(F: \c C \to \c D\) creates''.
  \end{enumerate}
\end{remark}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item \(U: \c{Gp} \to \Set\) creates all small limits: given a family \((G_i: i \in I)\) of groups, there is a unique group structure on \(\prod_{i \in I} UG_i\) making the projections homomorphisms, and this makes it a product in \(\c{Gp}\). Similarly for equalisers.

    But \(U\) doesn't preserve coproducts: \(U(G * H) \ncong UG \amalg UH\).
  \item \(U: \Top \to \Set\) preserves all small limits and colimits but doesn't reflect them: if \(L\) is a limit for \(D: \c J \to \Top\) and \(L\) is not discrete, there is another cone with apex \(L_d\), which is the same underlying space as \(L\) with discrete topology, mapped to the same limit in \(\Set\).
  \item The inclusion functor \(I: \c{AbGp} \to \c{Gp}\) reflects coproducts, but doesn't preserve them. The direct sum \(A \oplus B\) (coproduct in \(\c{AbGp}\)) is not normally isomorphic to the free product \(A * B\), which is not abelian unless either \(A\) or \(B\) is trivial, but if \(A \cong \{e\}\) then \(A \times B \cong A \oplus B \cong B\).
  \end{enumerate}
\end{eg}

The following lemma tells us how to construct limit in functor categories:

\begin{lemma}
  If \(\c D\) has limits of shape \(\c J\) then so does the functor category \([\c C, \c D]\) for any \(\c C\), and the forgetful functor \([\c C, \c D] \to \c D^{\ob \c C}\) creates them.
\end{lemma}

\begin{proof}
  Suppose given a diagram of shape \(\c J\) in \([\c C, \c D]\). Think of it as a functor \(D: \c J \times \c C \to \c D\). For each \(A \in \ob \c C\), let \((LA, (\lambda_{j, A}: j \in \ob \c J))\) be a limit cone for the diagram \(D(-, A): \c J \to \c D\).

  Given \(A \xrightarrow{f} B\) in \(\c C\), the composition
  \[
    LA \xrightarrow{\lambda_{j, A}} D(j, A) \xrightarrow{D(j, f)} D(j, B)
  \]
  form a cone over \(\c D(-, B)\), since the square
  \[
    \begin{tikzcd}
      D(j, A) \ar[r, "{D(j, f)}"] \ar[d, "{D(\alpha, A)}"] & D(j, B) \ar[d, "{D(\alpha, B)}"] \\
      D(j', A) \ar[r, "{D(j', f)}"] & D(j', B)
    \end{tikzcd}
  \]
  commutes. So there is a unique \(Lf: LA \to LB\) making
  \[
    \begin{tikzcd}
      LA \ar[r, "{\lambda_{j, A}}"] \ar[d, "Lf"] & {D(j, A)} \ar[d, "{D(j, f)}"] \\
      LB \ar[r, "{\lambda_{j, B}}"] & D(j, B)
    \end{tikzcd}
  \]
  commute for all \(j\). Uniqueness follows from functoriality: given \(g: B \to C\), \(L(gf)\) and \(L(g)L(f)\) are factorisations of the same cone through the limit \(LC\). And this is the unique functor structure on \(A \mapsto LA\) making the \(\lambda_{j, -}\) into natural transformations.

  The cone \((L, (\lambda_{j, -}: j \in \ob \c J))\) is a limit: suppose given another cone \((M, (\mu_{j, -}: j \in \ob \c J))\), then for each \(A\), \((MA, (\mu_{j, A}: j \in \ob \c J))\) is a cone over \(\c D(-, A)\), so induces a unique \(\alpha_A: MA \to LA\). Naturality of \(\alpha\) follows from uniqueness of factorisation through a limit. So \((M, (\mu_J))\) factors uniquely through \((L, (\lambda_j))\). (This is creation is the strict sense, i.e.\ equality instead of isomorphism)
\end{proof}

\begin{remark}
  In any category, a morphism \(A \xrightarrow{f} B\) is monic if and only if
  \[
    \begin{tikzcd}
      A \ar[r, "1_A"] \ar[d, "1_A"] & A \ar[d, "f"] \\
      A \ar[r, "f"] & B
    \end{tikzcd}
  \]
  is a pullback. Hence any functor which preserves pullbacks preserves monomorphisms. In particular if \(\c D\) has pullbacks momomorphisms in \([\c C, \c D]\) are just pointwise monos. See example sheet 1 for a counterexample for the neccessity of the pullback condition. Now we can delete the word ``pointwise'' in the statement of \Cref{lem:representable functors are projectives}.
\end{remark}

\begin{theorem}[right adjoint preserves limits]\index{right adjoint preserves limits}
  Suppose \(G: \c D \to \c C\) has a left adjoint. Then \(G\) preserves all limits which exist in \(\c D\).
\end{theorem}

\begin{proof}[Proof 1 with additional assumption]
  Suppose \(\c C\) and \(\c D\) both have limits of shape \(\c J\). We have a commutative diagram
  \[
    \begin{tikzcd}
      \c C \ar[r, "F"] \ar[d, "\Delta"] & \c D \ar[d, "\Delta"] \\
      {[\c J, \c C]} \ar[r, "{[\c J, F]}"] & {[\c J, \c D]}
    \end{tikzcd}
  \]
  where \(\Delta\) sends an object to its constant diagram and \([\c J, F]\) is composition with \(F\). All functors in it have right adjoints (in particular, \([\c J, F] \adjoint [\c J, G]\)). So by \Cref{cor:commutative square of adjoints} the diagram of right adjoints
  \[
    \begin{tikzcd}
      \c D \ar[r, "G"] & \c C \\
      {[\c J, \c D]} \ar[u, "\lim_{\c J}"] \ar[r, "{[\c J, G]}"] & {[\c J, \c C]} \ar[u, "\lim_{\c J}"]
    \end{tikzcd}
  \]
  commutes up to isomorphism, i.e.\ \(G\) preserves limits of shape \(\c J\).
\end{proof}

\begin{proof}[Proof 2]
  Suppose given \(D: \c J \to \c D\) and a limit cone \((L, (\lambda_j: L \to D(j): j \in \ob \c J))\). Given a cone \((A, (\alpha_j: A \to GD(j):j \in \ob \c J))\) over \(GD\), the morphisms \(FA \xrightarrow{\hat \alpha_j} D(j)\) form a cone over \(D\), so they induce a unique \(FA \xrightarrow{\hat \beta} L\) such that \(\lambda_j \hat \beta = \hat \alpha_j\) for all \(j\). Then \(A \xrightarrow{\beta} GL\) is the unique morphism satisfying \((G\lambda_j)\beta = \alpha_j\) for all \(j\). So \((GL, (G\lambda_j: j \in \ob \c J))\) is a limit cone in \(\c C\).
\end{proof}

The last major theorem in this chapter is adjoint functor theorem. It says that morally the converse of the above theorem is also true, i.e.\ a functor preserving all limits ought to have a left adjoint. It may only fail so if some limits do not exist. The ``primeval'' adjoint functor theorem is exactly this: if \(\c D\) has and \(G: \c D \to \c C\) preserves \emph{all} limits, then \(G\) has a left adjoint. However, this is too strong a condition as the categories having all limits can be shown to be preorders. Thus there are two more versions cut down on the all limits requirement and use some set theory to replace part of it.

\begin{lemma}
  Suppose \(\c D\) has and \(G: \c D \to \c C\) preserves limits of shape \(\c J\). Then for any \(A \in \ob \c C\) the arrow category \((A \downarrow G)\) has limits of shape \(\c J\), and the forgetful functor \(U: (A \downarrow G) \to \c D\) creates them.
\end{lemma}

\begin{proof}
  Suppose given \(D: \c J \to (A \downarrow G)\). Write \(D(j)\) as \((UD(j), f_j)\). Let \((L, (\lambda_j: L \to UD(j))_{j \in \ob \c J})\) be a limit for \(UD\). Then \((GL, (\lambda_j)_{j \in \ob \c J})\) is a limit for \(GUD\). Since the edges of \(UD\) are morphisms in \((A \downarrow G)\), the \(f_j\) form a cone over \(GUD\) so there is a unique \(h: A \to GL\) such that \((G\lambda_j)h = f_j\) for all \(j\), i.e.\ there's a unique \(h\) such that the \(\lambda_j\)'s are all morphisms in \((L, h) \to (UD(j), f_j)\) in \((A \downarrow G)\). We need to show that \(((L, h), (\lambda_j)_{j \in \ob \c J})\) is a limit cone in \((A \downarrow G)\). If \((C, (\mu_j)_{j \in \ob \c J})\) is any cone over \(\c D\) then \((C, (\mu_j)_{j \in \ob \c J})\) is a cone over \(UD\) so ther is a unique \(\ell: C \to L\) with \(\lambda_j \ell = \mu_j\) for all \(j\). We need to show \((G\ell) k = h\). But
  \[
    (G\lambda_j) (G\ell) k = (G \mu_j)k = f_j = (G\lambda_j)h
  \]
  for all \(j\) so \((G\ell) k = h\) by uniqueness of factorisations through limits.
\end{proof}

Recall that we have seen a limit for the empty diagram is a terminal object. We can also consider dually the diagram of ``maximal size'', namely that of a category over itself, to realise inital object as a limit. Think for example posets, in which limit for an empty diagram is maximimum while limit for the

\begin{lemma}
  A category \(\c C\) has an initial object if and only if \(1_{\c C}: \c C \to \c C\), regarded as a diagram of shape \(\c C\) in \(\c C\), has a limit.
\end{lemma}

Note that this is an exception to \(\c J\) being small.

% joke about one-to-one real world map

\begin{proof}
  First suppose \(\c C\) has an initial object \(I\). Then the unique morphisms \((I \to A: A \in \ob \c C)\) form a cone over \(1_{\c C}\) and given any cone \((\lambda_A: C \to A: A \in \ob \c C)\), for any \(A\) the triangle
  \[
    \begin{tikzcd}
      C \ar[r, "\lambda_I"] \ar[dr, "\lambda_A"'] & I \ar[d] \\
      & A
    \end{tikzcd}
  \]
  commutes so \(\lambda_I\) is the unique factorisation of \((\lambda_A: A \in \ob \c C)\) through \((I \to A: A \in \ob \c C)\).

  Conversely, suppose \((I, (\lambda_A: I \to A)_{A \in \ob \c C})\) is a limit. Then for any \(f: I \to A\) the diagram
  \[
    \begin{tikzcd}
      I \ar[r, "\lambda_I"] \ar[dr, "\lambda_A"'] & I \ar[d, "f"] \\
      & A
    \end{tikzcd}
  \]
  commutes. \(I\) is weakly initial as we don't know if it is unique, i.e.\ if \(\lambda_I = 1_I\). In particular, putting \(f = \lambda_A\), we see that \(\lambda_I\) is a factorisation of the limit cone through itself so \(\lambda_I = 1_I\). Hence every \(f: I \to A\) satisfies \(f = \lambda_A\).
\end{proof}

The primeval adjoint functor theorem follows immediately from the previous two lemmas and 3.3. However, it only applies to functors between preorders. See example sheet 2 Q6.

\begin{theorem}[general adjoint functor theorem]\index{adjoint functor theorem!general}
  Suppose \(\c D\) is locally small and complete. Then \(G: \c D \to \c C\) has a left adjoint if and only if \(G\) preserves all small limits and satisfies the \emph{solution set condition}, which says that for each \(A \in \ob \c C\), there exists a set of morphisms \(\{f_i: A \to GB_i: i \in I\}\) such that every \(h: A \to GC\) factors as
  \[
    A \xrightarrow{f_i} GB_i \xrightarrow{Gg} GC
  \]
  for some \(i\) and some \(g: B_i \to C\).
\end{theorem}

\begin{proof}
  If \(F \adjoint G\) then \(G\) preserves limits. To obtain the solution set, note that \(\{\eta_A: A \to GFA\}\) is a singleton solution set by 3.3 since it is initial.

  Conversely, by 4.10 \((A \downarrow G)\) is complete and it inherits local smallness from \(\c D\). We need to show that if \(\mathcal A\) is complete and locally small and has a weakly initial set of objects \(\{B_i: i \in I\}\) then \(\mathcal A\) has an initial object. First form \(P = \prod_{i \in I} B_i\); then \(P\) is weakly initial. Now form the limit of
  \[
    \begin{tikzcd}
      P \ar[r, shift left, "\vdots"'] \ar[r, shift right] & P
    \end{tikzcd}
  \]
  where edges are all the endomorphisms of \(P\). Denote it \(i: I \to P\). \(I\) is also weakly initial in \(\mathcal A\). Suppose given \(f, g: I \to C\). Form the equaliser \(e: E \to I\) of \((f, g)\). Then there exists \(h: P \to E\) since \(P\) is weakly initial. \(ieh: P \to P\) and \(1_P\) are edegs of the diagram so \(i = iehi\). But \(i\) is monic so \(ehi = 1_I\) so \(e\) is split epic so \(f = g\). Thus \(I\) is initial.
\end{proof}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item This example comes from Mac Lane. He asked the question that, if we are not given the free group functor, how can we to construct the left adjoint of forgetful functor? Consider the forgetful functor \(U: \c{Gp} \to \Set\). By 4.6a \(U\) creates all small limits so \(\c{Gp}\) has them and \(U\) preserves them. \(\c{Gp}\) is locally smal, given a set \(A\), any \(f: A \to UG\) factors as
    \[
      A \to UG' \to UG
    \]
    where \(G'\) is the subgroup generated by \(\{f(x): x \in A\}\) and \(\operatorname{card} G' \leq \max\{\aleph_0, \operatorname{card} A\}\). Let \(B\) be a set of this cardinality. Consider all subsets \(B' \subseteq B\), all group structures on \(B'\) and all mappings \(A \to B'\). These give us a solution set at \(A\). % grudge against Mac Lane. Similar as http://wwwf.imperial.ac.uk/~buzzard/maths/research/notes/the_adjoint_functor_theorem.pdf
  \item Consider the category \(\c{CLat}\) of complete lattices (posets with arbitrary meets and joints). Again the forgetful functor \(U: \c{CLat} \to \Set\) creates all small limits. But A.\ W.\ Hales showed in 1964 that for any cardinal \(\kappa\) there exists complete lattices of cardinality \(\geq \kappa\) generated by three elements. So the solution set condition fails at \(A = \{x, y, z\}\) as we cannot bound the cartinality of the solution set, and \(U\) doesn't have a left adjoint.
  \end{enumerate}
\end{eg}

The general adjoint functor theorem is general in the sense that it applies to all categories, although it imposes solution set condition, which is a rather strong condition on the functor. Special adjoint functor theorem aims to get rid of the condition on the functor.

\begin{definition}[subobject, quotient object]\index{subobject}\index{quotient object}
  By a \emph{subobject} of an object \(A\) of \(\c C\) we mean a monomorphism \(A' \mono A\). The subobjects of \(A\) are preordered by \(A'' \leq A'\) if there is a factorisation
  \[
    \begin{tikzcd}
      A'' \ar[r] \ar[dr, tail] & A' \ar[d, tail] \\
      & A
    \end{tikzcd}
  \]
  Dually we have \emph{quotient objects}.
\end{definition}

\begin{definition}[well-powered]\index{category!well-powered}
  We say \(\c C\) is \emph{well-powered} if each \(A \in \ob \c C\) has a set of subobjects \(\{A_i \mono A: i \in I\}\) such that every subobject of \(A\) is isomorphic to some \(A_i\).

  Dually if \(\c C^{\text{op}}\) is well-powered, we say \(\c C\) is \emph{well-copowered}. (\emph{not} cowell-powered, as it implies badly powered. It also sounds like something being powered by Simon Cowell, which is not quite what we study in this course)
\end{definition}

For example in \(\Set\) we can take inclusions \(\{A' \embed A: A ' \in PA\}\). This is also where the name ``well-powered'' comes from as in the \(\Set\) case it simply means power set exists.

Before stating and proving the special functor theorem we point out a simple yet powerful observation about pullback square.

\begin{lemma}
  Given a pullback square
  \[
    \begin{tikzcd}
      P \ar[r, "h"] \ar[d, "k"] & A \ar[d, "f", tail] \\
      B \ar[r, "g"] & C
    \end{tikzcd}
  \]
  with \(f\) monic. Then \(k\) is monic.
\end{lemma}

\begin{proof}
  Suppose \(x, y: D \to P\) satisfy \(kx = ky\). Then
  \[
    fhx = gkx = gky = fhy.
  \]
  By \(f\) is monic so \(hx = hy\). So \(x, y\) are factorisations of the same cone through the limit cone \((h, k)\).
\end{proof}

\begin{theorem}[special adjoint functor theorem]\index{adjoint functor theorem!special}
  Suppose \(\c C\) and \(\c D\) are both locally small, and that \(\c D\) is complete and well-powered and has a coseparating set. Then a functor \(G: \c D \to \c C\) has a left adjoint if and only if it preserves all small limits.
\end{theorem}

\begin{proof}
  The only if is given by right adjoint preserves limits. For the other direction, for any \(A \in \ob \c C\), \((A \downarrow G)\) is locally complete by 4.10, locally small, and well-powered since the subobjects of \((B, f)\) in \((A \downarrow G)\) are just those subobjects \(B' \mono B\) in \(\c D\) for which \(f\) factors through \(GB' \mono GB\). Also if \(\{S_i: i \in I\}\) is a coseparating set for \(\c D\) then the set
  \[
    \{(S_i, f): i \in I, f \in \c C(A, GS_i)\}
  \]
  is coseparating in \((A \downarrow G)\): given \(g, h: (B, f) \to (B', f')\) in \((A \downarrow G)\) with \(g \neq h\), there exists \(k: B' \to S_i\) for some \(i\) with \(kg \neq kh\), and then \(k\) is also a morphism \((B', f') \to (S_i, (Gk) f')\) in \((A \downarrow G)\).

  So we need to show that if \(\mathcal A\) is complete, locally small and well-powered and has a coseparating set \(\{S_i: i \in I\}\) then \(\mathcal A\) has an initial object. Form the product \(P = \prod_i \in S_i\). We have the industrial stength product and now we need the industrial strength pullback. Consider the diagram
  \[
    \begin{tikzcd}[row sep=tiny, column sep=tiny]
      & & P_j \ar[dddr, tail] & P_i \ar[ddd, tail] \\
      & \ar[ddrr, tail] \\
      & \vdots \\
      P' \ar[rrr, tail] & & & P
    \end{tikzcd}
  \]
  whose edges are representative set of subobjects of \(P\) and form its limit
  \[
    \begin{tikzcd}[row sep=tiny, column sep=tiny]
      I \ar[rrr] \ar[rrrd] \ar[ddd] & & & P_i \\
      & & & P_j \\
      & & \dots \\
      P'
    \end{tikzcd}
  \]
  By the argument in the previous lemma, the legs of the cones are all monic; in particular \(I \mono P\) is monic, and it's a least subobject of \(P\). Hence \(I\) has no proper subobjects. So given \(f, g: I \to A\) their equaliser is an isomorphism and hence \(f = g\).

  We get uniqueness for free but need to work harder to show existence. Now let \(A\) be any object of \(\mathcal A\). Form the product \(Q = \prod_{i \in I, f \in \mathcal A (A, S_i)} S_i\). There is an obvious \(h: A \to Q\) defined by \(\pi_{i, F} h = f\); and \(h\) is monic, since the \(S_i\)'s are a coseparating set. We also have a morphism \(k: P \to Q\) defined by \(\pi_{i, f} k = \pi_i\). Now form the pullback
   \[
     \begin{tikzcd}
       B \ar[r] \ar[d, tail] & A \ar[d, "h", tail] \\
       P \ar[r, "k"] & Q
     \end{tikzcd}
   \]
  by lemma \(P\) is monic so \(B\) is a subobject of \(P\). Hence there exists
  \[
    \begin{tikzcd}
      I \ar[r] \ar[dr] & B \ar[d] \\
      & P
    \end{tikzcd}
  \]
  and hence a morphism \(I \to B \to A\).
\end{proof}

This result is due to Freyd, who first published it in a book as an exercise to the readers (!).

\begin{eg}
  Consider the inclusion \(I: \c{KHaus} \to \Top\), where \(\c{KHaus}\) is the full subcategory of compact Hausdorff spaces. \(\c{KHaus}\) has and \(I\) preserves small products (by Tychonoff's theorem) and equalisers (since equalisers of pairs \(f, g: X \to Y\) with \(Y\) Hausdorff are closed subspaces). Both cateogories are locally small and \(\c{KHaus}\) is well-powered (subobjects of \(X\) are isomorphic to closed subspaces). The closed interval \([0, 1]\) is a coseparateor in \(\c{KHaus}\) by Urysohn's lemma. So by special adjoint functor theorem \(I\) has a left adjoint \(\beta\), the Stone-Čech compactification\index{Stone-Čech compactification}.
\end{eg}

\begin{remark}\leavevmode
  \begin{enumerate}
  \item % I've never asked Freyed but this is probabily how he gets the inspiration for AFT. not from Marshall Stone's proof

  Čech's construction of \(\beta\) is as follow: given \(X\), form
  \[
    P = \prod_{f: X \to [0, 1]} [0, 1]
  \]
  and define \(h: X \to P\) by \(\pi_f h = f\). Define \(\beta X\) to be the closure of the image of \(h\)

  % coseparator in \((X \downarrow [0, 1])\), smallest subobject being precisely the closure.

  Čech's proof that this works is essentially the same as SAFT.
\item We could have used GAFT to construct \(\beta\) by a cardinality argument: we get a solution set at \(X\) by considering all continuous \(f: X \to Y\) with \(Y\) compact Hausdorff and \(f(X)\) dense in \(Y\) and such \(Y\) have cardinality \(\leq 2^{2^{\operatorname{card} X}}\).
  \end{enumerate}
\end{remark}

\section{Monad}

The idea of a monad is what is left in an adjunction when you cannot see one of the categories. Suppose given \(f: \c C \to \c D, g: \c D \to \c C\) with \(F \adjoint G\). How much of this structure can we describe without mentioning \(\c D\)? We have
\begin{enumerate}
\item the functor \(T = GF: \c C \to \c C\),
\item the unit \(\eta: 1_{\c C} \to T = GF\),
\item and ``shadow'' of counit as a natural transformation \(\mu = G\varepsilon_F: TT = GFGF \to GF = T\)
\end{enumerate}
satisfying the commutative diagrams 1, 2
\[
  \begin{tikzcd}
    T \ar[r, "T\eta"] \ar[dr, "1_T"'] & TT \ar[d, "\mu"] & T \ar[l, "\eta_T"'] \ar[dl, "1_T"] \\
    & T
  \end{tikzcd}
\]
by the triangle inequalities, and 3
\[
  \begin{tikzcd}
    TTT \ar[r, "T\mu"] \ar[d, "\mu_T"] & TT \ar[d, "\mu"] \\
    TT \ar[r, "\mu"] & T
  \end{tikzcd}
\]
by naturality of \(\varepsilon\).

\begin{definition}[monad]\index{monad}\index{unit}\index{multiplication}
  A \emph{monad} \(\T = (T, \eta, \mu)\) on a category \(\c C\) consists of a functor \(T: \c C \to \c C\) and natural transofrmations \(\eta: 1_{\c C} \to T, \mu: TT \to T\) satisfying commutative diagrams 1 - 3.

  \(\eta\) and \(\mu\) are called the \emph{unit} and \emph{multiplication} of \(\T\).
\end{definition}

The name ``monad'' was used because of the similarity of axioms of monad with those of monoid. Before that, although being well-known to mathematicians, monad didn't really have an identifier. It goes by the name ``standard construction'', then ``triple'', thereby the letter \(\T\). But both are confessions of failure to come up with a meaningful name! Someone invented the name ``monad'' and Mac Lane popularised it.

\begin{eg}\leavevmode
  \begin{enumerate}
  \item Any adjunction \(F \adjoint G\) induces a monad \((GF, \eta, G\varepsilon_F)\) on \(\c C\) and a \emph{comonad}\index{comonad} \((FG, \varepsilon, F\eta_G)\) on \(\c D\).
  \item Let \(M\) be a monoid. The functor \((M \times - ): \Set \to \Set\) has a monad structure with unit given by \(\eta_A(a) = (a_M, a)\) and multiplication \(\mu_A(m, m', a) = (mm', a)\). The monad identities follow from the monoid ones.
  \item Let \(\c C\) be any category with finite products and \(A \in \ob \c C\). The functor \((A \times -): \c C \to \c C\) has a comonad structure with counit \(\varepsilon_B: A \times B \to B\) given by \(\pi_2\) and comultiplication \(\delta_B: A \times B \to A \times A \times B\) given by \((\pi_1, \pi_1, \pi_2)\).
  \end{enumerate}
\end{eg}

Does every monad comes from an adjunction? The answer is yes and is given independently in 1965 by Eilenberg, Moore and Kleisli. We will cover both.

In example 2 above we have the cateogry \([M, \Set]\). Its forgetful functor to \(\Set\) has a left adjoint, sending \(A\) to \(M \times A\) with \(M\) acting by multiplication on the left factor. This adjunction gives rise to the monad.

\begin{definition}[Eilenberg-Moore algebra]\index{algebra}
  Let \(\T\) be a monad on \(\c C\). A \emph{\(\T\)-algebra} is a pair \((A, \alpha)\) with \(A \in \ob \c C\) and \(\alpha: TA \to A\) satisfying commutative diagrams 4, 5
  \[
    \begin{tikzcd}
      A \ar[r, "\eta_A"] \ar[dr, "1_A"'] & TA \ar[d, "\alpha"] \\
      & A
    \end{tikzcd}
    \qquad
    \begin{tikzcd}
      TTA \ar[r, "T\alpha"] \ar[d, "\mu_A"] & TA \ar[d, "\alpha"] \\
      TA \ar[r, "\alpha"] & A
    \end{tikzcd}
  \]

  A \emph{homomorphism} \(f: (A, \alpha) \to (B, \beta)\) is a morphism \(f: A \to B\) such that diagram 6
  \[
    \begin{tikzcd}
      TA \ar[r, "Tf"] \ar[d, "\alpha"] & TB \ar[d, "\beta"] \\
      A \ar[r, "f"] & B
    \end{tikzcd}
  \]
  commutes.

  The category of \(\T\)-algebras is denoted \(\c C^\T\).
\end{definition}

\begin{lemma}
  The forgetful functor \(G^\T: \c C^\T \to \c C\) has a left-adjoint \(F^\T\) and the adjunction induces \(\T\).
\end{lemma}

\begin{proof}
  We define a ``free'' \(\T\)-algebra functor, mimicking that in monoid case. Define \(F^\T A = (TA, \mu_A)\) (an algebra by 2, 3) and \(F^\T(A \xrightarrow{f} B) = Tf\) (a homomorphism by naturality of \(\mu\)). Clearly \(G^\T F^\T = T\), the unit of the adjunction is \(\eta\). We define the counit \(\varepsilon_{(A, \alpha)} = \alpha: (TA, \mu_A) \to (A, \alpha)\) (a homomorphism by 5) and is natural by 6. The triangle identities
  \begin{align*}
    \varepsilon_{FA} (F\eta_A) &= 1_{FA} \\
    G\varepsilon_{(A, \alpha)} \eta_A &= 1_A
  \end{align*}
  are given by 1 and 4. Finally, the monad induced by \(F^\T \adjoint G^\T\) has functor \(T\) and unit \(\eta\), and
  \[
    G^\T \varepsilon_{F^\T A} = \mu_A
  \]
  by definition of \(F^\T A\).
\end{proof}

Kleisli took a ``minimalist'' approach: if \(F: \c C \to \c D, G: \c D \to \c C\) induces \(\T\) then so does \(F: \c C \to \c D', G 1_{\c D'}: \c D' \to \c C\) where \(\c D'\) is the full subcategory of \(\c D\) on objects \(FA\). So in trying to construct \(\c D\), we may assume \(F\) is surjective (or indeed bijective) on objects. But then morphisms \(FA \to FB\) correspond bijectively to morphisms \(A \to GFB = TB\) in \(\c C\). This leads us half way through as we sitll have to specify how to compose morphisms (in general domains and codomains don't match up).

\begin{definition}[Kleisli category]\index{Kleisli category}
  Given a monad \(\T\) on \(\c C\), the \emph{Kleisli category} \(\c C_\T\) has \(\ob \c C_\T = \ob \c C\) and morphisms
  \begin{tikzcd}
    A \ar[r, blue] & B
  \end{tikzcd}
  (we use blue arrow to signify morphism in \(\c C_\T\)) are \(A \to TB\) in \(\c C\). The composite
  \begin{tikzcd}
    A \ar[r, blue, "f"] & B \ar[r, blue, "g"] & C
  \end{tikzcd}
  is
  \[
    \begin{tikzcd}
      A \ar[r, "f"] & TB \ar[r, "Tg"] & TTC \ar[r, "\mu_C"] & C
    \end{tikzcd}
  \]
  and the identity
  \begin{tikzcd}
    A \ar[r, blue] & A
  \end{tikzcd}
  is \(A \xrightarrow{\eta_A} TA\).
\end{definition}

To verify associativity, suppose given
\begin{tikzcd}
  A \ar[r, blue, "f"] & B \ar[r, blue, "g"] & C \ar[r, blue, "h"] & D
\end{tikzcd}
then
\[
  \begin{tikzcd}
    A \ar[r, "f"] & TB \ar[r, "T_g"] & TTC \ar[r, "TTh"] \ar[d, "\mu_C"] & TTTD \ar[r, "T\mu D"] \ar[d, "\mu_{TD}"] & TTD \ar[d, "\mu_D"] \\
    & & TC \ar[r, "Th"] & TTD \ar[r, "\mu_D"] & TD
  \end{tikzcd}
\]
commutes: the upper way monad is \((hg) f\) and the lower is \(h(gf)\). (used diagram 3 in rightmost square)

The unit laws similarly follow from
\[
  \begin{tikzcd}
    A \ar[r, "f"] & TB \ar[r, "T\eta_B"] \ar[dr, "1_{TB}"'] & TTB \ar[d, "\mu_B"] \\
    & & TB
  \end{tikzcd}
  \qquad
  \begin{tikzcd}
    A \ar[r, "f"] \ar[d, "\eta_A"] & TB \ar[dr, "1_{TB}"] \ar[d, "1_{TB}"] \\
    TA \ar[r, "Tf"] & TTB \ar[r, "\mu_B"] & TB
  \end{tikzcd}
\]
(used diagram 1 and 2 respecitively in the triangles)

\begin{lemma}
  There exists an adjunction \(F_\T: \c C \to \c C_\T, G_\T: \c C_T \to \c C\) inducing the monad \(\T\).
\end{lemma}

\begin{proof}
  We define \(F_\T A = A, F_\T(A \xrightarrow{f} B) = A \xrightarrow{f} B \xrightarrow{\eta_B} TB\). \(F_\T\) preserves identities by definition. For composites, consider \(A \xrightarrow{f} B \xrightarrow{g} C\), we get
  \[
    \begin{tikzcd}
      A \ar[r, "f"] & B \ar[r, "\eta_B"] \ar[d, "g"] & TB \ar[d, "Tg"] \\
      & C \ar[r, "\eta_C"] & TC \ar[r, "T\eta_C"] \ar[dr, "1_{TC}"'] & TTC \ar[d, "\mu_C"] \\
      & & & TC
    \end{tikzcd}
  \]
  (used diagram 1 in the triangle)

  We define
  \begin{align*}
    G_\T A &= TA \\
    G_\T(A \blue{\xrightarrow{f}} B) &= TA \xrightarrow{Tf} TTB \xrightarrow{\mu_B} TB
  \end{align*}
  \(G_\T\) preserves identities by diagram 1. For composite, consider
  \begin{tikzcd}
    A \ar[r, blue, "f"] & B \ar[r, blue, "g"] & C
  \end{tikzcd}
  , we get
  \[
    \begin{tikzcd}
      TA \ar[r, "Tf"] & TTB \ar[r, "TTg"] \ar[d, "\mu_B"] & TTTC \ar[r, "T\mu_C"] \ar[d, "\mu_{TC}"] & TTC \ar[d, "\mu_C"] \\
      & TB \ar[r, "Tg"] & TTC \ar[r, "\mu_C"] & TC
    \end{tikzcd}
  \]
  (used diagram 3 is last square)

  Have
  \begin{align*}
    G_\T F_\T A &= TA \\
    G_\T T_\T f &= \mu_B (T\eta_B) Tf = TF
  \end{align*}
  so we take \(\eta: 1_{\c C} \to T\) as the unit of \(F_\T \adjoint G_\T\). The counit
  \begin{tikzcd}
    TA \ar[r, "\varepsilon_A"] & A
  \end{tikzcd}
  is \(1_{TA}\). To verify naturality consider the square
  \[
    \begin{tikzcd}
      TA \ar[r, blue, "F_\T G_\T f"] \ar[d, blue, "\varepsilon_A"] & TB \ar[d, blue, "\varepsilon_B"] \\
      A \ar[r, blue, "f"] & B
    \end{tikzcd}
  \]
  This expands to
  \[
    \begin{tikzcd}
      TA \ar[r, "Tf"] & TTB \ar[r, "\mu_B"] & TB \ar[r, "\eta_{TB}"] \ar[dr, "1_{TB}"'] & TTB \ar[d, "\mu_B"] \\
      & & & TB
    \end{tikzcd}
  \]
  (used diagram 2 in triangle) so \(\varepsilon\) is natural.

  Finally, \(G_\T(TA \blue{\xrightarrow{\varepsilon_A}} A) = \mu_A\) so
   \[
     G_\T(\blue{\varepsilon_A}) \eta_{G_\T A} = \mu_A \eta_{TA} = 1_{TA}
   \]
   and \(\blue{(\varepsilon_{F_\T A}) (F_\T \eta_A)}\) is
   \[
     \begin{tikzcd}
       A \ar[r, "\eta_A"] & TA \ar[r, "\eta_{TA}"] \ar[dr, "1_{TA}"'] & TTA \ar[d, "\mu_A"] \\
       & & TA
     \end{tikzcd}
   \]
    (used diagram 1 in triangle) which is \(\blue{(1_{F_\T A})}\). Also \(G_\T(\blue{\varepsilon_{F_\T A}}) = \mu_A\) so \(F_\T \adjoint G_\T\) induces \(\T\).
\end{proof}

\begin{theorem}
  Given a monad \(\T\) on \(\c C\), let \(\c{Adj} (\T)\) be the category whose objects are the adjunctions \(F: \c C \to \c D, G: \c D \to \c D\) inducing \(\T\), and whose morphisms
  \[
    \begin{tikzcd}
      (\c C \ar[r, shift left, "F"] & \c D) \ar[l, shift left, "G"] \ar[r] & (\c C \ar[r, shift left, "F'"] & \c D') \ar[l, shift left, "G'"]
    \end{tikzcd}
  \]
  are functors \(H: \c D \to \c D'\) satisfying \(HF = F'\) and \(G'H = G\). Then the Kleisli adjunction is an initial object of \(\c{Adj} (\T)\) and Eilenberg-Moore adjunction is terminal.
\end{theorem}

\begin{proof}
  Let \(F G\) be an object of \(\c{Adj} (\T)\). We define the \emph{Eilenberg-Moore comparison functor}\index{Eilenberg-Moore comparison functor} \(K: \c D \to \c C^\T\) by \(KB = (GB, G\varepsilon_B)\) where \(\varepsilon\) is the counit of \(F \adjoint G\). Note this is an algebra by one of the triangular identities for \(F \adjoint G\) and naturality of \(\varepsilon\), and \(K(B \xrightarrow{g} B') = Gg\), a homomorphism by naturality of \(\varepsilon\).

  Clearly \(G^\T K = G\) and
  \begin{align*}
    KFA &= (GFA, G\varepsilon_{FA}) = (TA, \mu_A) = F^\T A \\
    KF(A \xrightarrow{f} A') &= Tf = F^\T f
  \end{align*}
  so \(K\) is a morphism of \(\c{Adj} (\T)\).

  Suppose \(K': \c D \to \c C^\T\) is another such, then since \(G^\T K' = G\) we know \(K'B = (GB, \beta_B)\) where \(\beta\) is a natural transformation \(GFG \to G\). Also since \(K' F = F^\T\), we have
  \[
    \beta_{FA} = \mu_A = G\varepsilon_{FA}.
  \]
  Now given any \(B \in \ob \c D\), consider the diagram.

  Also since \(K'F = F^\T\) we have \(\beta_{FA} = \mu_A = G \varepsilon_{FA}\).

  Now given any \(B \in \ob \c D\), consider the diagram
  \[
    \begin{tikzcd}
      GFGFGB \ar[r, "GFG\varepsilon_B"] \ar[d, shift right, "G\varepsilon_{FGB}"', "="] \ar[d, shift left, "\beta_{FGB}"] & GFGB \ar[d, shift right, "G\varepsilon_B"'] \ar[d, shift left, "\beta_B"] \\
      GFGB \ar[r, "G\varepsilon_B"] & GB
    \end{tikzcd}
  \]
  Both squares commute so \(G\varepsilon_B\) and \(\beta_B\) have the same composite with \(GFG\varepsilon_B\). But this is split epic with splitting \(GF\eta_{GB}\) so \(\beta = G\varepsilon\). Hence \(K' = K\).

  We now define the Kleisli comparison functor \(L: \c C _\T \to \c D\) by \(LA = FA\),
  \[
    L(A \blue{\xrightarrow{f}} B) = FA \xrightarrow{Ff} FGFB \xrightarrow{\varepsilon_{FB}} FB.
  \]
  \(L\) preserves identities by one of the triangular identities for \(F \adjoint G\). Given \(A \blue{\xrightarrow{f}} B \blue{\xrightarrow{g}} C\), we have
  \[
    \begin{tikzcd}
      FA \ar[r, "Ff"] & FGFB \ar[r, "FGFg"] \ar[d, "\varepsilon_{FB}"] & FGFGFC \ar[r, "FG\varepsilon_{FC}"] \ar[d, "\varepsilon_{FGFC}"] & FGFC \ar[d, "\varepsilon_{FC}"] \\
      & FB \ar[r, "Fg"] & FGFC \ar[r, "\varepsilon_{FC}"] & FC
    \end{tikzcd}
  \]
  Also
  \begin{align*}
    GLA &= TA = G_\T A \\
    GL(A \blue{\xrightarrow{f}} B) &= (G \varepsilon_{FB}) (FGf) = \mu_B(Tf) = G_\T f \\
    GF_\T A &= FA \\
    LF_\T(A \xrightarrow{f} B) &= (\varepsilon_{FB}) (F\eta_B) (Ff) = Ff
  \end{align*}
  For future reference, note that \(L\) is full and faithful: its effect on morphisms (with blue domains and codmains) is that of transposition across \(F \adjoint G\).

  Finally for uniqueness, suppose \(L': \c C_\T \to \c D\) is a morphism of \(\c{Adj}(\T)\). We must have \(L'A = FA\) and \(L'\) maps the counit \(TA \blue{\to} A\) to the counit \(FGFA \xrightarrow{\varepsilon_{FA}} FA\). For any \(A \blue{\xrightarrow{f}} B\), we have
  \begin{align*}
    \blue{f = 1_{TA}(F_\T f)}
  \end{align*}
  so \(L'(\blue{f}) = \varepsilon_{FA} (Ff) = Lf\).
\end{proof}

If \(\c C\) has coproducts then so does \(\c C_\T\) since \(F_\T\) preserves them. But in general it has few other limits or colimits. In contrast, we have

\begin{theorem}\leavevmode
  \begin{enumerate}
  \item The forgetful functor \(G: \c C^\T \to \c C\) creates all limits which exists in \(\c C\).
  \item If \(\c C\) has colimits of shape \(\c J\) then \(G: \c C^\T \to \c C\) creates them if and only if \(T\) preserves them.
  \end{enumerate}
\end{theorem}

\begin{proof}\leavevmode
  \begin{enumerate}
  \item Suppose given \(D: \c J \to \c C^\T\). Write \(D(j) = (GD(j), \delta_j)\) and suppose \((L, (\mu_j: L \to GD(j): j \in \ob \c J))\) is a limit cone for \(GD\). Then the composites
    \[
      TL \xrightarrow{T\mu_j} TGD(j) \xrightarrow{\delta_j} GD(j)
    \]
    form a cone over \(GD\) since the edges of \(GD\) are homomorphisms, so they induce a unique \(\lambda: TL \to L\) such that \(\mu_j \lambda = \delta_j(T_\mu)\) for all \(j\). The fact that \(\lambda\) is a \(\T\)-algebra structure on \(L\) follows from the fact that the \(\delta_j\) are algebra structure and uniqueness of factorisations through limits. So \(((L, \lambda), (\mu_j: j \in \ob \c J))\) is the unique lifting of the limit cone over \(GD\) to a cone over \(D\), and it's a limit, since given a conve over \(D\) with apex \((A, \alpha)\), we get a unique factorisation \(A \xrightarrow{f} L\) in \(\c C\), and \(F\) is an algebra homomorphism by uniqueness of factorisation through \(L\).
  %\item For \(\implies\) direction, \(F: \c C \to \c C^\T\) preserves colimits since it is a left adjoint, so \(T = GF\) preserves colimits of shape \(\c J\).
    %TODO: uncomment the previous line

    For \(\impliedby\) direction, suppose given \(D: \c J \to \c C^\T\) as in 1, and a colimit cone \((GD(j) \xrightarrow{\mu_j} L: j \in \ob \c J)\) in \(\c C\), then \((TGD(j) \xrightarrow{T\mu_j} TL: j \in \ob \c C)\) is also a colimit cone, so the composite
    \[
      TGD(j) \xrightarrow{f_j} GD(j) \xrightarrow{\mu_j} L
    \]
    induces a unique \(\lambda: TL \to L\). The rest of the argument is like 1.
  \end{enumerate}
\end{proof}

\begin{definition}[monadicity]\index{monadicity}
  Given an adjunctin \(F \adjoint G\), we say the adjunction (or the functor \(G\)) is \emph{monadic} if the comparison functor \(K: \c D \to \c C^\T\) is part of an equivalence of categories.
\end{definition}

Note that since the Kleisi comparison \(\c C_\T \to \c D\) is full and faithful, it's part of an equivalence if and only if it (equivalently, \(F\)) is essentially surjective on objects.

\begin{remark}
  Given any adjunction \(F \adjoint G\), for each object \(B\) of \(\c D\) we have a diagram
  \[
    \begin{tikzcd}
      FGFGB \ar[r, shift left, "FG\varepsilon_B"] \ar[r, shift right, "\varepsilon_{FGB}"'] & FGB \ar[r, "\varepsilon_B"] & B
    \end{tikzcd}
  \]
  with equal composites. The ``primeval'' monadicity theorem asserts that \(\c C^\T\) is characterised in \(\c{Adj}(\T)\) by the fact that these diagrams are all coequalisers.
\end{remark}

\begin{definition}[reflexivity, split coequaliser]\index{reflexivity}\index{coequaliser!split}\leavevmode
  \begin{enumerate}
  \item We say a parallel pair \(f, g: A \to B\) is \emph{reflexive} if their exists \(B \xrightarrow{r} A\) such that \(fr = gr = 1_B\).

    We say \(\c C\) has reflexive coequalisers if it has coequalisers of all reflexive pairs. Equivalently, colimits of shape
    \[
      \begin{tikzcd}
        \cdot \ar[loop, out=90, in=150, looseness=6] \ar[loop, out=210, in=270, looseness=5] \ar[r, shift left] \ar[r, shift right] & \cdot \ar[l]
      \end{tikzcd}
    \]
  \item By a \emph{split coequaliser diagram} we mean a diagram
    \[
      \begin{tikzcd}
        A \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & B \ar[l, bend left=50, "t"] \ar[r, "h"] & C \ar[l, bend left=50, "s"]
      \end{tikzcd}
    \]
    satisfying \(hf = hg, hs = 1_C, gt = 1_B\) and \(ft = sh\).

    These equalisers imply that \(h\) is a coequaliser of \((f, g)\), if \(B \xrightarrow{x} D\) satisfies \(xf = xg\) then
    \[
      x = xgt = xfg = xsh
    \]
    so \(x\) factors through \(h\) and the factorisation is unique since its split monic.

    Note that split coequalisers are preserved by \emph{all} functors.
  \item Given a functor \(G: \c D \to \c C\), a parallel pair
    \begin{tikzcd}
      A \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & B
    \end{tikzcd}
    is called \emph{\(G\)-split} if there exists a split coequaliser diagram
    \[
      \begin{tikzcd}
        GA \ar[r, shift left, "Gf"] \ar[r, shift right, "Gg"'] & GB \ar[l, bend left=50, "t"] \ar[r, "h"] & C \ar[l, bend left=50, "s"]
      \end{tikzcd}
    \]
    in \(\c C\).

     Note that
     \begin{tikzcd}
       FGFGB \ar[r, shift left, "FG\varepsilon_B"] \ar[r, shift right, "\varepsilon_{FGB}"'] & FGB
     \end{tikzcd}
    is \(G\)-split, since
    \[
      \begin{tikzcd}
        GFGFGB \ar[r, shift left, "GFG\varepsilon_B"] \ar[r, shift right, "G\varepsilon_{FGB}"'] & GFGB \ar[l, bend left=50, "\eta_{GFGB}"] \ar[r, "G\varepsilon_B"] & C \ar[l, bend left=50, "\eta_{GB}"]
      \end{tikzcd}
    \]
  \end{enumerate}
\end{definition}

Note that the aforementioned pair
\[
  \begin{tikzcd}
    FGFGB \ar[r, shift left, "FG\varepsilon_B"] \ar[r, shift right, "\varepsilon_{FGB}"'] & FGB
  \end{tikzcd}
\]
is reflexive with \(r = F\eta_{GB'}\).

\begin{lemma}
  \label{lem:left adjoint and coequaliser}
  Suppose given an adjunction
  \begin{tikzcd}
    \c C \ar[r, shift left, "F"] & \c D \ar[l, shift left, "G"]
  \end{tikzcd}
  where \(F \adjoint G\), inducing a monad \(\T\) on \(\c C\). Then \(K: \c D \to \c C^\T\) has a left adjoint provided, for every \(\T\)-algebra \((A, \alpha)\), the pair
  \begin{tikzcd}
    FGFA \ar[r, shift left, "F_\alpha"] \ar[r, shift right, "\varepsilon_{FA}"'] & FA
  \end{tikzcd}
  has a coequaliser in \(\c D\).
\end{lemma}

\begin{proof}
  We define \(L: \c C^\T \to \c D\) by taking \(FA \to L(A, \alpha)\) to be a coequaliser for \((F\alpha, \varepsilon_{FA})\). Note that this is a functor \(\c C^\T \to \c D\). Recall that \(K\) is defined by \(KB = (GB, G\varepsilon_B)\). For any \(B\), morphisms \(LA \to B\) correspond bijectively to morphisms \(FA \xrightarrow{f} B\) satisfying \(f(F\alpha) = f(\varepsilon_{FA})\). These correspond to morphisms \(A \xrightarrow{\check f} GB\) satisfying
  \[
    \check f \alpha = Gf = G(\varepsilon_B(F \check f)) = (G\varepsilon_B)(T \check f)
  \]
  i.e.\ to algebra homomorphisms \((A, \alpha) \to KB\). And these bijections are natural in \((A, \alpha)\) and in \(B\).
\end{proof}

\begin{theorem}[precise monadicity theorem]\index{monadicity theorem}
  \label{thm:precise monadicity theorem}
  \(G: \c D \to \c C\) is monadic if and only if \(G\) has a left adjoint and creates coequalisers of \(G\)-split pairs.
\end{theorem}

\begin{theorem}[refined/reflexive monadicity theorem]\index{monadicity theorem}
  \label{thm:refined monadicity theorem}
  Suppose \(\c D\) has and \(G: \c D \to \c C\) preserves reflexive coequalisers, and that \(G\) reflects isomorphisms and has a left adjoint. Then \(G\) is monadic.
\end{theorem}

\begin{proof}
  \Cref{thm:precise monadicity theorem} \(\implies\): sufficient to show that \(G^\T: \c C^\T \to \c C\) creates coequalisers of \(G^\T\)-split pairs. But this follows from the argument of 5.4 (2), %(note: lecture sasy 5.8 (ii), check later).
  since if \(f, g: (A, \alpha) \to (B, \beta)\) is a \(G^\T\)-split pairs, the coequalisers of
  \begin{tikzcd}
    A \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & B
  \end{tikzcd}
  is preserved by \(T\) and \(TT\).

  \Cref{thm:precise monadicity theorem} \(\impliedby\) and \Cref{thm:refined monadicity theorem}: Let \(\T\) denote the monad induced by \(F \adjoint G\). For any \(\T\)-algebra \((A, \alpha)\), the pair
  \begin{tikzcd}
    FGFA \ar[r, shift left, "F\alpha"] \ar[r, shift right, "\varepsilon_{FA}"'] & A
  \end{tikzcd}
  is both reflexive and \(G\)-split, so has a coequaliser in \(\c D\) and hence by \Cref{lem:left adjoint and coequaliser}, \(K: \c D \to \c C^\T\) has a left adjoint \(L\). Then unit of \(L \adjoint K\) at an algebra \((A, \alpha)\), the coequaliser defining \(L(A, \alpha)\) is mapped by \(K\) to the diagram
  \[
    \begin{tikzcd}
      F^\T TA \ar[r, shift left, "F^\T\alpha"] \ar[r, shift right, "\mu_A"'] & F^\T A \ar[r] \ar[dr, "\alpha"] & KL(A, \alpha) \\
      & & (A, \alpha) \ar[u, dashed, "\iota_{(A, \alpha)}"'] % check this cell
    \end{tikzcd}
  \]
  and \(\iota_{(A, \alpha)}\) is the factorisation of this through the \(G^\T\)-split coequaliser \(\alpha\). But either set of hypothesis implies that \(G\) preserves the coequaliser defining \(L(A, \alpha)\), so \(\iota_{(A, \alpha)}\) is an isomorphism. For the counit \(\xi: LKB \to B\), we have a coequaliser
  \[
    \begin{tikzcd}
      FGFGB \ar[r, shift left, "FG\varepsilon_B"] \ar[r, shift right, "\varepsilon_{FGB}"'] & FGB \ar[r] \ar[dr, "\varepsilon_B"] & LKB \ar[d, dashed, "\xi_B"] \\
      & & B
    \end{tikzcd}
  \]
  Again, either set of hypothesis implies that \(\varepsilon_B\) is a coequaliser of \((FG\varepsilon_B, \varepsilon_{FGB})\) so \(\xi_B\) is an isomorphism.
\end{proof}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item The forgetful functors \(\c{Gp} \to \Set, \c{Rng} \to \Set, \c{Mod}_R \to \Set \dots\) all satisfy the hypothesis of refined monadicity theorem, for the relexive coequalisers, use example sheet 4 Q3 which shows that if
    \[
      \begin{tikzcd}
        A \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & B \ar[r, "h"] & C
      \end{tikzcd}
    \]
    is a reflexive coequaliser diagram in \(\Set\) then so is
    \[
      \begin{tikzcd}
        A^n \ar[r, shift left, "f^n"] \ar[r, shift right, "g^n"'] & B^n \ar[r, "h^n"] & C^n.
      \end{tikzcd}
    \]
  \item Any reflection is monadic: this follows from example sheet 3 Q3, but can also be proved using precise monadicity theorem. Let \(\c D\) be a relfecitve (full) subcategory of \(\c C\), and suppose a pair \(f, g: A \to B\) in \(\c D\) fits into a split coequaliser diagram
    \[
      \begin{tikzcd}
        A \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & B \ar[l, blue, bend left=50, "t"] \ar[r, blue, "h"] & C \ar[l, blue, bend left=50, "s"]
      \end{tikzcd}
    \]
    in \(\c C\). Then \(t\) and \(ft = sh\) belongs to \(\c D\) since \(\c D\) is full and hence \(s\) is in \(\c D\) since it's an equaliser of \((1_B, sh)\) and \(\c D\) is closed under limits in \(\c C\). Hence also \(h \in \mor \c D\).
  \item Consider the composite adjunction
    \[
      \begin{tikzcd}
        \Set \ar[r, shift left, "F"] & \c{AbGp} \ar[l, shift left, "U"] \ar[r, shift left, "L"] & \c{tfAbGp} \ar[l, shift left, "I"]
      \end{tikzcd}
    \]
    These two factors are monadic by the above two examples respectively, but the composite isn't, since the monad it induces on \(\Set\) is isomorphic to that induced by \(F \adjoint U\).
  \item Consider the forgetful functor \(U: \Top \to \Set\). This is faithful and has both left and right adjoint (so preserves all coequalisers), but the monad induced on \(\Set\) is \((1, 1, 1)\) and the category of algebras is \(\Set\).
  \item One may get the impression that monadicty is something only shared by algebraic construction but not topological constructions. Consider the composite adjunction
    \[
      \begin{tikzcd}
        \Set \ar[r, shift left, "D"] & \Top \ar[l, shift left, "U"] \ar[r, shift left, "\beta"] & \c{KHaus} \ar[l, shift left, "I"]
      \end{tikzcd}
    \]
    We shall show that this satisfies the hypothesis of precise monadicity theorem. Let
    \[
      \begin{tikzcd}
        X \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & Y \ar[l, bend left=50, blue, "t"] \ar[r, blue, "h"] & Z \ar[l, bend left=50, blue, "s"]
      \end{tikzcd}
    \]
    be a split coequaliser in \(\Set\) where \(X\) and \(Y\) have compact Hausdorff topologies and \(f, g\) are continuous. Note that the quotient topology on \(Z \cong Y/R\) is compact, so it's the only possible candidate for a compact Hausdorff topology making \(h\) continuous.

    We use the lemma from general topology: if \(Y\) is compact Hausdorff, then a quotient \(Y/R\) is Hausdorff if and only if \(R \subseteq Y \times Y\) is closed. We note
    \begin{align*}
      R
      &= \{(y, y'): h(y) = h(y')\} \\
      &= \{(y, y'): sh(y) = sh(y')\} \\
      &= \{(y, y'): ft(y) = ft(y')\}
    \end{align*}
    so if we define \(S = \{(x, x'): f(x) = f(x')\} \subseteq X \times X\) then \(R \subseteq (g \times g)(S)\), but this reverse inclusion also holds. But
    \[
      \begin{tikzcd}
        S \ar[r] & X \times X \ar[r, shift left, "f\pi_1"] \ar[r, shift right, "f\pi_2"'] & Y
      \end{tikzcd}
    \]
    is an equaliser, \(Y\) is Hausdorff, so \(S\) is closed on \(X \times X\) and hence compact. So \(R = (g \times g)(S)\) is compact and hence closed in \(Y \times Y\).

    Morally, a category that is monadic over \(\Set\) can be thought as an algebraic object, in the sense that it is defined by algebraic equations. This applies to \(\c{KHaus}\) by including ``infinitary equations''.
  \end{enumerate}
\end{eg}

\begin{definition}[monadic tower]\index{monadic tower}
  Let
  \begin{tikzcd}
    \c C \ar[r, shift left, "F"] & \c D \ar[l, shift left, "G"]
  \end{tikzcd}
  be an adjunction and suppose \(\c D\) has reflexive coequalisers. The \emph{monadic tower} of \(F \adjoint G\) is the diagram
  \[
    \begin{tikzcd}[row sep=huge]
      & \vdots \ar[d, shift left] \ar[dl, shift left] \\
      \c D \ar[ur, shift left] \ar[r, shift left, "K'"] \ar[dr, shift left, "K"] \ar[ddr, shift left, "G"] & (\c C^\T)^{\mathbb S} \ar[l, shift left, "L"] \ar[d, shift left] \ar[u, shift left] \\
      & \c C^\T \ar[ul, shift left, "L"] \ar[u, shift left] \ar[d, shift left] \\
      & \c C \ar[uul, shift left, "F"] \ar[u, shift left]
    \end{tikzcd}
  \]
  where \(\T\) is the monad induced by \(F \adjoint G\), \(K\) is as in 5.7, \(L\) as in 5.11 (comparison?) \(\mathbb S\) is the moand induced by \(L \adjoint K\) and so on.

  We say \(F \adjoint G\) has \emph{monadic length} \(n\) if we reach an equlvalence after \(n\) steps.
\end{definition}

Monadic length 0: already equivalence. Monadic length 1: monad

For example, the adjunction of 5.14c has monadic length \(1\). The adjunction of 5.14d has monadic length \(\infty\).

We will need one more result for topos theory, which we state without proof. (lifting of left adjoint in categorical algebra)

\begin{theorem}
  Suppose given an adjunction
  \begin{tikzcd}
    \c C \ar[r, shift left, "L"] & \c D \ar[l, shift left, "R"]
  \end{tikzcd}
  and monads \(\T, \mathbb S\) on \(\c C, \c D\) respectively, and a functor \(\overline R: \c D^{\mathbb S} \to \c C^\T\) such that
  \[
    \begin{tikzcd}
      \c D^{\mathbb S} \ar[r, "\overline R"] \ar[d, "G^{\mathbb S}"] & \c C^\T \ar[d, "G^\T"] \\
      \c D \ar[r, "R"] & \c C
    \end{tikzcd}
  \]
  commutes up to isomorphism. Suppose also \(\c D^{\mathbb S}\) has reflexive coequalisers. Then \(\overline R\) has a left adjoint \(\overline L\).
\end{theorem}

\begin{proof}
  Note that if \(\overline L\) exists we must have \(\overline L F^\T \cong F^{\mathbb S} L\) by 3.6. So we'd expect \(\overline L(A, \alpha)\) to be a coequaliser of two morphisms
  \begin{tikzcd}
    F^{\mathbb S} LTA \ar[r, shift left, "F^{\mathbb S}L\alpha"] \ar[r, shift right, "?"'] & F^{\mathbb S}LA.
  \end{tikzcd}
  To construct the second morphism, note first that we assume wlog \(G^\T \overline R = RG^{\mathbb G}\), by transporting \(\T\)-algebra structurs along the isomorphism \(G^\T R(B, \beta) \to RB\).

  We obtain \(\phi: TR \to RS\) by starting from
  \[
    R \xrightarrow{R\iota} RS = RG^{\mathbb S} F^{\mathbb S} = G^\T \overline R F^{\mathbb S},
  \]
  conjugate by \(F\) to get
  \[
    F^\T R \to \overline R F^{\mathbb S},
  \]
  and finally (?)
  \[
    TR = G^\T F^\T R \xrightarrow{\phi} G^\T \overline R F^{\mathbb S} = RG^{\mathbb S} F^{\mathbb S} = RS.
  \]
  Convert it into \(\varphi: LT \to SL\) by
  \[
    LT \xrightarrow{LT\gamma} LTRL \xrightarrow{L\theta_L} LRSL \xrightarrow{\delta_{SL}} SL
  \]
  where \(\gamma\) and \(\delta\) are the unit and counit of \(L \adjoint R\). Transposing across \(F^{\mathbb S} \adjoint G^{\mathbb S}\), we get \(\overline \varphi: F^{\mathbb S} LT \xrightarrow{F^{\mathbb S}} L\). The pair \((F^{\mathbb S} L\alpha, \overline \varphi_A)\) is relexive, with common splitting \(F^{\mathbb S}L\eta\). (\(\overline \varphi\) is the question mark in the diagram)

  It can be verified (albeit extremely tedious) that the coequaliser of this pair has the unviersal property we require for \(\overline L(A, \alpha)\).
\end{proof}

\section{Cartesian closed categories}

\begin{definition}[exponentiable object, cartesian closed category]\index{exponentiable object}\index{category!cartesian closed}
  Let \(\c C\) be a category with finite products. We say \(A \in \ob \c C\) is \emph{exponentiable} if the functor \((-) \times A: \c C \to \c C\) has a right adjoint \((-)^A\).

  If every object of \(\c C\) is exponentiable, we say \(\c C\) is \emph{cartesian closed}.
\end{definition}

Intuitively, exponential object ``lifts'' morphisms to an object, instead of a set. ``internalisation''

\begin{eg}\leavevmode
  \begin{enumerate}
  \item \(\Set\) is cartesian closed, with \(B^A = \Set(A, B)\). A function \(f: C \times A \to B\) corresponds to \(\overline f: C \to B^A\).
  \item \(\c{Cat}\) is cartesian closed with \(\c D^{\c C} = [\c C, \c D]\). In fact we have implicitly used this idea when discussing limits in functor categories.
  \item In \(\Top\), if an exponential \(Y^X\) exists, its points must be the continuous maps \(X \to Y\). The \emph{compact-open} topology on \(\c{Top}(X, Y)\) has the universal property of an exponential if and only if \(X\) is locally compact.

    Note that finite products of exponential objects are exponentiable: since
    \[
      (-) \times (A \times B) \cong (- \times A) \times B,
    \]
    we have \((-)^{A \times B} \cong ((-)^B)^A\). However, even if \(X\) and \(Y\) are locally compact, \(Y^X\) needn't be. So the exponentiable objects don't form a cartesian closed full subcategory.
  \item A cartesian closed poset is called a \emph{Heyting semilattice}\index{Heyting semilattice}: it's a poset with finite meet \(\wedge\) and a binary operation \(\implies\) satisfying
    \[
      a \leq (b \implies c) \text{ if and only if } a \wedge b \leq c.
    \]
    For example, a complete poset is a Heyting semilattice if and only if it satisfies the infinite distributive law
    \[
      a \wedge \bigvee_{i \in I} \{b_i\} = \bigvee_{i \in I} \{a \wedge b_i\}.
    \]
    For any topological space, the lattice \(\mathcal O(X)\) of open sets satisfies this condition, since \(\wedge\) and \(\vee\) conincide with \(\cap\) an \(\cup\). (However it does not satisfy the dual condition: arbitrary intersection needs to take interior).
  \end{enumerate}
\end{eg}

Recall from example sheet 2 that, if \(B \in \ob C\), we define the \emph{slice category}\index{slice category} \(\c C /B\) to have objects which are morphisms \(A \to B\) in \(\c C\) and morphisms are commutative triangles
\[
  \begin{tikzcd}
    A \ar[r] \ar[dr] & A' \ar[d] \\
    & B
  \end{tikzcd}
\]
The forgetful functor \(\c C/B \to \c C\) will be denoted \(\Sigma_B\). If \(\c C\) has finite products, \(\Sigma_B\) has a right adjoint \(B^*\) which sends \(A\) to
\[
  A \times B \xrightarrow{\pi_2} B
\]
since morphisms
\[
  \begin{tikzcd}
    C \ar[r, "{(f, g)}"] \ar[dr, "g"] & A \times B \ar[d, "\pi_2"] \\
    & B
  \end{tikzcd}
\]
% diagonal. Dually left adjoint is diagonal???
correspond to morphisms \(f: \Sigma_Bg = C \to A\).

\begin{lemma}
  If \(\c C\) has all finite limits then an object \(B\) is exponentiable if and only if \(B^*: \c C \to \c C/B\) has a right adjoint \(\Pi_B\).
\end{lemma}

\begin{proof}\leavevmode
  \begin{enumerate}
  \item \(\impliedby\): The composite \(\Sigma_B B^*\) is equal to \((-) \times B\) so we take \((-)^B\) to be \(\Sigma_B B^*\).
  \item \(\implies\): If \(B\) is exponentiable, for any \(f: A \to B\) we define \(\Pi_B9f)\) to be the pullback
    \[
      \begin{tikzcd}
        \Pi_B(f) \ar[r] \ar[d] & A^B \ar[d, "F^B"] \\
        1 \ar[r, "\overline \pi_2"] & B^B
      \end{tikzcd}
    \]
    where \(\overline \pi_2\) is the transpose of the projection (?). Then morphisms \(C \to \Pi_B(f)\) corresponding to morphisms \(C \to A^B\) making
    \[
      \begin{tikzcd}
        C \ar[r] \ar[d] & A^B \ar[d, "f^B"] \\
        1 \ar[r, "\overline \pi_2"] & B^B
      \end{tikzcd}
    \]
    commute, i.e.\ to morhpisms \(C \times B \to A\) making
    \[
      \begin{tikzcd}
        C \times B \ar[r] \ar[dr, "\pi_2"'] & A \ar[d, "f"] \\
        & B
      \end{tikzcd}
    \]
    commute.
  \end{enumerate}
\end{proof}

\begin{lemma}
  Suppose \(\c C\) has finite limits. If \(A\) is exponentiable in \(\c C\) then \(B^*A\) is exponentiable in \(\c C/B\) for any \(B\). Moreover \(B^*\) preserves exponentials.
\end{lemma}

\begin{proof}
  Given an object
  \begin{tikzcd}
    C \ar[d, "f"] \\
    B
  \end{tikzcd}
  , form the pullback
  \[
    \begin{tikzcd}
      P \ar[r] \ar[d, "f^{B^*A}"] & C^A \ar[d, "f^A"] \\
      B \ar[r, "\overline \pi_1"] & B^A
    \end{tikzcd}
  \]
  Then for any
  \begin{tikzcd}
    D \ar[d, "g"] \\
    B
  \end{tikzcd}
  , morphisms \(g \to f^{B^*A}\) in \(\c C/B\) correspond to morphisms \(D \xrightarrow{\overline h} C^A\) making
  \[
    \begin{tikzcd}
      D \ar[r, "\overline h"] \ar[d, "g"] & C^A \ar[d, "f^A"] \\
      B \ar[r, "\overline \pi_1"] & B^A
    \end{tikzcd}
  \]
  commute, and hence to morphisms \(D \times A \xrightarrow{h} C\) making
  \[
    \begin{tikzcd}
      D \times A \ar[r, "h"] \ar[dr, "g\pi_1"] & C \ar[d, "f"] \\
      & B
    \end{tikzcd}
  \]
  commmute. But
  \[
    \begin{tikzcd}
      D \times A \ar[r, "g \times 1_A"] \ar[d, "\pi_1"] & B \times A \ar[d, "\pi_1"] \\
      D \ar[r, "g"] & B
    \end{tikzcd}
  \]
  is a pullback in \(\c C\), i.e.\ a product in \(\c C/B\).

  For the second assertion, note that if \(C \xrightarrow{f} B\) is of the form \(B \times E \xrightarrow{\pi_1} B\) then the pullback defining \(f^{B^*A}\) becomes
  \[
    \begin{tikzcd}
      B \times E^A \ar[r, "\overline \pi_1 \times 1_{E^A}"] \ar[d, "\pi_1"] & B^A \times E^A \ar[d, "\pi_1"] \\
      B \ar[r, "\overline \pi_1"] & B^A
    \end{tikzcd}
  \]
  so \(f^{B^*A} \cong B^*(E^A)\).
\end{proof}

\begin{remark}
  \(\c C/B\) is isomorphic to the category of coalgebra for the monad structure on \((-) \times B\) (5.2c). So the first part of the lemma could be proved using lift of adjoint (last theorem of chapter 5).
\end{remark}

\begin{definition}[locally cartesian closed]\index{category!locally cartesian closed}
  We say \(\c C\) is \emph{locally cartesian closed} if it has all finite limits and each \(\c C/B\) is cartesian closed.
\end{definition}

Note that this includes the fact that \(\c C \cong \c C/1\) is cartesian closed. So the usuage is to the contrary of normal usage of ``locally'' as it imposes a stricter condition.

\begin{eg}\leavevmode
  \begin{enumerate}
  \item \(\Set\) is locally cartesian closed since \(\Set/B \simeq \Set^B\) for any \(B\).
  \item For any small category \(\c C\), \([\c C, \Set]\) is cartesian closed: by Yoneda
    \[
      G^F(A) \cong [\c C, \Set](\c C(A, -), G^F) \cong [\c C, \Set](\c C(A, -) \times F, G)
    \]
    so we take RHS as a definition of \(G^F(A)\) and define \(G^F\) on morphisms \(A \xrightarrow{f} B\) by composition with \(\c C(f, -) \times 1_F\). Note that the class of funtors \(H\) for which we have
    \[
      [\c C, \Set](H, G^F) \cong [\c C, \Set](H \times F, G)
    \]
    is closed under colimits. But every functor \(\c C \to \Set\) is a colimit of representables.

    In fact \([\c C, \Set]\) is locally cartesian closed since all its slice categories \([\c C, \Set]/F\) are of the same form. See example sheet 4 Q6.
  \item Any Heyting semilattice \(H\) is locally cartesian closed since \(H/b \cong \downarrow(b)\), the poset of elements \(\leq b\), and \(b^* = (-) \wedge b\) is surjective.
  \item \(\c{Cat}\) is \emph{not} locally cartesian closed, since not all strong epis are regular. c.f.\ example sheet 3 Q6.
  \end{enumerate}
\end{eg}

Note that given
\begin{tikzcd}
  A \ar[d, "f"] \\
  B
\end{tikzcd}
in \(\c C/B\), the iterated slice \((\c C/B)/f\) is isomorphic to \(\c C/A\), and this identifies \(f^*: \c C/B \to (\c C/B)/f\) with the operation of pulling back morphisms along \(f\). So by 6.3 \(\c C\) is locally cartesian closed if and only if it has finite limits and \(f^*: \c C/B \to \c C/A\) has a right adjoint \(\Pi_f\) for every \(A \xrightarrow{f} B\) in \(\c C\). This can be taken as the definition of locally cartesian closed category.

\begin{theorem}
  Suppose \(\c C\) is locally cartesian closed and has reflexive coequalisers. Then every morphism \(A \xrightarrow{f} B\) factors as
  \[
    A \stackrel{q}{\epi} I \stackrel{m}{\mono} B
  \]
  where \(q\) is regular epic and \(m\) is monic.
\end{theorem}

\begin{proof}
  First form the pullback
  \[
    \begin{tikzcd}
      R \ar[r, "a"] \ar[d, "b"] & A \ar[d, "f"] \\
      A \ar[r, "f"] & B
    \end{tikzcd}
  \]
  and then form the coequaliser
  \[
    \begin{tikzcd}
      R \ar[r, shift left, "a"] \ar[r, shift right, "b"'] & A \ar[r, "q"] & I.
    \end{tikzcd}
  \]
  Since \(fa = fb\), \(f\) factors as
  \[
    \begin{tikzcd}
      A \ar[r, "q"] & I \ar[r, "m"] & B.
    \end{tikzcd}
  \]
  Suppose given
  \begin{tikzcd}
    D \ar[r, shift left, "g"] \ar[r, shift right, "h"'] & I
  \end{tikzcd}
  with \(mg = mh\), form the pullback
  \[
    \begin{tikzcd}
      E \ar[r, "n"] \ar[d, "{(k, \ell)}"] & D \ar[d, "{(g, h)}"] \\
      A \times A \ar[r, "q \times q"] & I \times I
    \end{tikzcd}
  \]
  Since \(q \times q\) factors as \((q \times 1_I)(1_A \times q)\) and both factors are pullbacks of \(q\), it is an epimorphism and so is \(n\). Now
  \[
    fk = mqk = mgn = mhn = mg\ell = f\ell
  \]
  so there exists \(E \xrightarrow{p} R\) with \(ap = k, bp = \ell\).

  Now
  \[
    qk = qap = qbp = q\ell,
  \]
  i.e.\ \(gn = hn\). But \(n\) is epic so \(g = h\). Hence \(m\) is monic.
\end{proof}

Note that this implies any strong epi \(A \xrightarrow{f} B\) is regular since the monic part of its image factorisation is an isomorphism. In particular, regular epimorphisms are stable under composition.

\begin{definition}
  If \(\c C\) and \(\c D\) are cartesian closed categories and \(F: \c C \to \c D\) preserves products then for each pair of objects \((A, B)\) of \(\c C\), we get a natural morphism \(\theta: F(B^A) \to FB^{FA}\), namely the transpose of
  \[
    F(B^A) \times FA \cong F(B^A \times A) \xrightarrow{F(\ev)} FB
  \]
  where \(\ev\) is the counit of \(((-) \times A \adjoint (-)^A)\).

  We say \(F\) is a \emph{cartesian closed functor} if \(\theta\) is an isomorphism for every pair \((A, B)\). Note that the second part of 6.4 syas that if \(\c C\) is locally cartesian closed then \(f^*: \c C/B \to \c C/A\) is a continuous cartesian functor for any \(A \xrightarrow{f} B\).
\end{definition}

\begin{theorem}
  Let \(\c C\) and \(\c D\) be cartesian closed categories and \(F: \c C \to \c D\) a functor having a left adjoint \(L\). Then \(F\) is cartesian closed if and only if the canonical morphism \(\varphi_{A, B}\)
  \[
    \begin{tikzcd}
      L(B \times FA) \ar[r, "{(L\pi_1, L\pi_2)}"] & LB \times LFA \ar[r, "1_{LA} \times \varepsilon_B"] & LB \times A
    \end{tikzcd}
  \]
  is an isomorphism for all \(A \in \ob \c C, B \in \ob \c D\). This condition is called \emph{Frobenius reciprocity}\index{Frobenius reciprocity}.
\end{theorem}

% check this below paragraph
Note that if \(\c C\) is locally cartesian closed then \(f^*: \c C/B \to \c C/A\) has a left adjoint \(\Sigma_f\) given by composition with \(f\), and it's easy to verify that
\[
  \Sigma_f(g \times f^*h) \cong \Sigma_f g \times h.
\]

\begin{proof}\leavevmode
  \begin{itemize}
  \item \(\implies\): Given an inverse for \(\theta: F(C^A) \to FA^{FA}\), we define \(\varphi_{A, B}^{-1}\) to be the composite
    \[
      \begin{tikzcd}
        LB \times B \ar[r, "L\lambda \times 1"] & L((B \times FA)^{FA}) \times A \ar[r, "L(\eta^{FA}) \times 1"] & L(FL(B \times FA)^{FA}) \times B \ar[d, "L\theta^{-1} \times 1"] \\
        L(B \times FA) & L(B \times FA)^A \times A \ar[l, "\operatorname{ev}"] & LF(L(B \times FA)^A) \times A \ar[l, "\varepsilon \times 1"]
      \end{tikzcd}
    \]
    The verification is a tedious exercise.
  \item \(\impliedby\): Given an inverse for \(\varphi\), we define \(\theta^{-1}\) to be
    \[
      \begin{tikzcd}
        F((L(FC^{FA} \times A))^A) \ar[d, "F(\varphi^{-1 A})"] & FL(FC^{FA}) \ar[l, "F\lambda"] & FC^{FA} \ar[l, "\eta"] \\
        F((L(FC^{FA} \times FA))^A) \ar[r, "F((L(\operatorname{ev}))^A)"] & F((LFC)^A) \ar[r, "F(\varepsilon^A)"] & F(C^A).
      \end{tikzcd}
    \]
  \end{itemize}
\end{proof}

\begin{corollary}
  Suppose \(\c C\) and \(\c D\) are cartesian closed, and \(F: \c C \to \c D\) has a left adjoint \(L\) which preserves finite products. Then \(F\) is cartesian closed if and only if \(F\) is full and faithful.
\end{corollary}

\begin{proof}\leavevmode
  \begin{itemize}
  \item \(\implies\): \(L\) preserves \(1\) so if we substitute \(B\) in the definition of \(\varphi\) above, we get \(LFA \xrightarrow{\varepsilon_A} A\). But \(\varepsilon\) is an isomorphism if and only if \(F\) is full and faithful.
  \item \(\impliedby\): If \(L\) preserves binary products and \(\varepsilon\) is an isomorphism. Then both factors in the definition of \(\varphi\) are isomorphisms.
  \end{itemize}
\end{proof}

\begin{definition}[exponential ideal]\index{exponential ideal}
  Let \(\c C\) be a cartesian closed category. By an \emph{exponential ideal} of \(\c C\) we mean a class of objects (or a full subcategory) \(\mathcal E\) such that \(B \in \mathcal E\) implies \(B^A \in \mathcal E\) for all \(A \in \ob \c C\).
\end{definition}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item We say \(A\) is \emph{subterminal}\index{subterminal} if \(A \to 1\) is monic. In any cartesian closed category \(\c C\), the class \(\operatorname{Sub}_{\c C}(1)\) is an exponential ideal since \(A\) is subterminal if and only if there exists at most 1 morphisms \(B \to A\) for any \(B\), if and only if at most 1 morphism \(C \times B \to A\) for any \(B\) and \(C\), so by adjunction if and only if at most 1 morphism \(C \to A^B\), if and only if \(A^B\) is subterminal.

    More generally, if \(\c C\) is locally cartesian closed then \(\operatorname{Sub}_{\c C}(A)\) is an exponential ideal in \(\c C/A\) for any \(A\).  if \(\c C\) also satisfies the hypotheses of 6.7 then \(\operatorname{Sub}_{\c C}(A)\) is reflexive in \(\c C/A\).
  \item Let \(X\) be a topological space. By a \emph{presheaf}\index{presheaf} of \(X\) we mean a functor \(F: \mathcal O(X)^{\text{op}} \to \Set\) where \(\mathcal O(X)\) is the partial order of open subsets of \(X\). So \(F\) has sets \(F(U)\) for each open \(U\) and restriction maps \(F(U) \to F(V): x \mapsto x|_V\) whenever \(V \subseteq U\).

    We say \(F\) is a \emph{sheaf}\index{sheaf} if whenever \(U = \bigcup_{i \in I} U_i\) and we're given \(x_i \in F(U_i)\) for each \(i\), such that
    \[
      x_i|_{U_i \cap U_j} = x_j|_{U_i \cap U_j}
    \]
    for all \((i, j)\), then exists a unique \(x \in F(U)\) such that \(x|_{U_i} = x_i\) for all \(i\).

    We write \(\Sh(X) \subseteq [\mathcal O(X)^{\text{op}}, \Set]\) for the full subcategory of sheaves. We'll show \(\Sh(X)\) is an exponential ideal: given presheaves \(F, G\), \(G^F(U)\) is the set of natural transofrmations \(F \times \mathcal O(X) (-, U) \to G\) or equivalently, the set of natural transformations \(F|_U \to G|_U\) where \(F|_U: \mathcal O(X)^{\text{op}} \to \Set\) is the presheaf obtained by restricting \(F\) to open sets in \(U\). Now suppose \(G\) is a sheaf. Suppose \(U = \bigcup_{i \in I} U_i\) and suppose given \(\alpha_i: F|_{U_i} \to G|_{U_i}\) for each \(i\) such that
    \[
      \alpha_i|_{U_i \cap U_j} = \alpha_j|_{U_i \cap U_j}
    \]
    for all \(i, j\). Given \(x \in F(V)\) where \(V \subseteq U\), write \(V_i = V \cap U_i\), then \(V = \bigcup_{i \in I} V_i\). The elements \(x|_{V_i}\), \(i \in I\), satisfying the compatibility condition and hence so do the elements \((\alpha_i)_{V_i} (x|_{V_i}) \in G(V_i)\) . So there's a unique \(y \in G(V)\) such that
    \[
      y|_{V_i} = (\alpha_i)_{V_i} (x|_{V_i})
    \]
    for all \(i\) and we define this to be \(\alpha_V(x)\). This defines natural transformations \(\alpha: F|_U \to G|_U\) and it's the unique transformation whose restriction to \(U_i\) is \(\alpha_i\) for each \(i\).

    Note that since \(\Sh(X)\) is closed under finite products (and in fact all limits) in \([\mathcal O(X)^{\text{op}}, \Set]\), it is itself cartesian closed.
  \end{enumerate}
\end{eg}

\begin{lemma}
  Suppose \(\c C\) is cartesian closed and \(\c D \subseteq \c C\) is a (full) reflective subcategory, with reflector \(L: \c C \to \c D\). Then \(\c D\) is an exponential ideal if and only if \(L\) preserves binary products.
\end{lemma}

\begin{proof}\leavevmode
  \begin{itemize}
  \item \(\implies\): Suppose \(A, B \in \ob \c C, C \in \ob \c D\). Then we have bijections
    \begin{align*}
      A \times B &\to C \\
      A &\to C^B \\
      LA &\to C^B \\
      LA \times B &\to C \\
      B &\to C^{LA} \\
      LB &\to C^{LA} \\
      LA \times LA &\to C
    \end{align*}
    so \(LA \times LB\) has the universal property of \(L(A \times B)\).
  \item \(\impliedby\): Suppose \(B \in \ob \c D, A, C \in \ob \c C\). We have bijections
    \begin{align*}
      C &\to B^A \\
      C \times A &\to B \\
      LC \times LA \cong L(C \times A) &\to B \\
      L(LC \times A) &\to B \\
      LC \times A &\to B \\
      LC &\to B^A
    \end{align*}
    so every \(C \to B^A\) factors throu \(C \to LC\), hence \(B^A \in \ob \c D\).
  \end{itemize}
\end{proof}

\section{Toposes}

Topos has it orgin in the French school of algebraic geometry. In 1963, when studing cohomologies in gemoetry, Grothendieck studied toposes as categories of ``generalised sheaves''. As sheaves can be seen as representation of spaces and properties of the space can be detected from sheaves, toposes become generalised spaces. Thus the name topos: something more fundamental than topology.

J.\ Giraud gave a characterisation of such categories by (set-theoretic) categorical properties. F.\ W.\ Lawvere and M. Tierney (1969 - 1970) investigated the elementary categorical properties of these categories and come up with the elementary definition. In fact a Grothendieck topos is exactly a Lawvere-Tierney topos which is (co)complete and locally small, and has a separating set of objects (which is what Grothendieck should, but didn't, come up with, by the way).

\begin{definition}[subobject classifier, topos, logical functor]\index{subobject classifier}\index{topos}\index{logical functor}\leavevmode
  \begin{enumerate}
  \item Let \(\c{\mathcal E}\) be a category with finite limits. A \emph{subobject classifier} for \(\mathcal E\) is a monomorphism \(\top: \Omega' \mono \Omega\) such that for every mono \(m: A' \mono A\) in \(\mathcal E\), there is a unique \(\chi_m: A \to \Omega\) for which there is a pullback square
    \[
      \begin{tikzcd}
        A' \ar[r] \ar[d, "m", tail] & \Omega' \ar[d, "\top", tail] \\
        A \ar[r, "\chi_m"] & \Omega
      \end{tikzcd}
    \]
    Note that, for any \(A\), there is a unique \(A \to \Omega\) which factors through \(\top: \Omega' \mono \Omega\), so the domain of \(\top\) is actually a terminal object.

    If \(\mathcal E\) is well-powered, we have a functor \(\operatorname{Sub}_{\c{\mathcal E}}: \c{\mathcal E} \to \Set\) sending \(A\) to the set of (isomorphism classes) of subobjects of \(A\) and acting on morphisms by pullback, and an subobject classifier is a representation of this functor.
  \item A \emph{topos} is a category which has finite limits, is cartesian closed and has a subobject classifier.
  \item If \(\c{\mathcal E}\) and \(\c{\mathcal F}\) are toposes, a \emph{logical functor} \(F: \c{\mathcal E} \to \c{\mathcal F}\) is one which preserves finite limits, exponentiables and the subobject classifier.
  \end{enumerate}
\end{definition}

\begin{eg}\leavevmode
  \begin{enumerate}
  \item \(\Set\) is a topos, with \(\Omega = \{0, 1\}\) and \(\top = 1: 1 \mapsto \{0, 1\}\). Have
    \[
      \chi(a) =
      \begin{cases}
        1 & a \in A \\
        0 & a \notin A
      \end{cases}
    \]
    So also is the category \(\Set_f\) of finite set, or the category \(\Set_\kappa\) of sets of cardinality \(< \kappa\), where \(\kappa\) is an infinite cardinal such that if \(\lambda < \kappa\) then \(2^\lambda < \kappa\). %? does this exists in, say, standard set axioms?
  \item For any small category \(\c C\), \([\c C^{\text{op}}, \Set]\) is a topos: we've seen that it's cartesian, and \(\Omega\) is determined by Yoneda:
    \[
      \Omega(A) \cong [\c C^{\text{op}}, \Set](\c C(-, A), \Omega) \cong \{\text{subfunctors of } \c C(-, A)\}.
    \]
    So we define \(\Omega(A)\) to be the set of \emph{sieves}\index{sieve} on \(A\), i.e.\ sets \(R\) of morphisms with codomain \(A\) such that if \(f \in R\) then \(fg \in R\) for any \(g\).

    Given \(f: B \to A\) and a sieve \(R\) on \(A\), we define \(f^*R\) to be the set of \(g\) with codomain \(B\) such that \(fg \in R\). This makes \(\Omega\) into a functor \(\c C^{\text{op}} \to \Set\): \(\top: 1 \to \Omega\) is defined by
    \[
      \top_A(*) = \{\text{all morphisms with codomain } A\}.
    \]
    Given a subfunctor \(m: F' \mono F\), we define \(\chi_m: F \to \Omega\) by
    \[
      (\chi_m)_A(x) = \{f: B \to A: Ff(x) \in F'(B)\}.
    \]
    This is the unique natural transformation making
    \[
      \begin{tikzcd}
        F' \ar[r] \ar[d, "m", tail] & 1 \ar[d, "\top", tail] \\
        F \ar[r, "\chi_m"] & \Omega
      \end{tikzcd}
    \]
    a pullback.
  \item For any space \(X\), \(\Sh(X)\) is a topos. It's cartesian closed. For the subobject classifier we take
    \[
      \Omega(U) = \{V \in \mathcal O(X): V \subseteq U\}
    \]
    and \(\Omega(U' \to U)\) is the map \(V \mapsto V \subseteq U'\). \(\Omega\) is a sheaf since if we have \(U = \bigcup_{i \in I} U_i\) and \(U_i \subseteq U_i\) such that \(V_i \cap U_j = V_j \cap U_i\) for each \(i, j\) then \(V = \bigcup_{i \in I} V_i\) is the unique open subset of \(U\) with \(V \cap U_i = V_i\) for each \(i\).

    If \(m: F' \mono F\) is a subsheaf then for any \(x \in F(U)\) the sieve
    \[
      \{V \subseteq U: x|_V \in F'(V)\}
    \]
    has a greatest element since \(F'\) is a sheaf. So we define \(\chi_m: F \to \Omega\) to send \(x\) to this object.
  \item Let \(\c C\) be a group \(G\). The topos structure on \([G, \Set]\) is particularly simple: \(B^A\) is the set of all \(G\)-equivariant maps \(f: A \times G \to B\) but such an \(f\) is determined by its values at elements of the form \((a, 1)\) since \(f(a, g) = g . f(g^{-1} . a, 1)\), and this restriction can be any mapping \(A \times \{1\} \to B\). So we can take \(B^A\) to be the set of functions \(A \to B\) with \(G\) acting by
    \[
      (g . f) (a) = g(f(g^{-1} . a))
    \]
    and \(\Omega = \{0, 1\}\) with trivial \(G\)-action. So the forgetful functor \([G, \Set] \to \Set\) is logical, as is the functor which equips a set \(A\) with trivial \(G\)-action.

    Moreover, even if \(G\) is infinite, \([G, \Set]\) is a topos and this inclusion \([G, \Set_f] \to [G, \Set]\) is logical. Similarly if \(\mathcal G\) is a large group (i.e.\ the underlying space may not be a set), then \([\mathcal G, \Set]\) is a topos.
  \item Let \(\c C\) be a category such that every \(\c C/A\) is equivalent to a finite category. Then \([\c C^{\text{op}}, \Set_f]\) is a topos. Similarly if \(\c C\) is large but all \(\c C/A\) are small, then \([\c C^{\text{op}}, \Set]\) is a topos. In partciular \([\c{On}, \Set]\) is a topos, but it's not locally small.
  \end{enumerate}
\end{eg}

\begin{lemma}
  Suppose \(\mathcal E\) has finite limits and a subobject classifier. Then every monomorphism in \(\mathcal E\) is regular. In particular \(\mathcal E\) is balanced.
\end{lemma}

\begin{proof}
  The universal monomorphism \(\top: 1 \mono \Omega\) is split and hence regular. But any pullback of a regular mono is regular: if \(f\) is an equaliser of \((g, h)\) then \(K^*(f)\) is an equaliser of \((gk, hk)\). The second assertion follows since a regular mono that is also epic is an isomorphism.
\end{proof}

Given an object \(A\) in a topos \(\mathcal E\), we write \(PA\) for the exponential \(\Omega^A\). and \(\ni_A \mono PA \times A\) for the subobject corresponding to \(\ev: PA \times A \to \Omega\). This has the property that, for any \(B\) and any \(m: R \mono B \times A\), there is a unique \(\ulcorner m \urcorner: B \to PA\) such that
\[
  \begin{tikzcd}
    R \ar[r] \ar[d, "m", tail] & \ni_A \ar[d, tail] \\
    B \times A \ar[r, "\ulcorner m \urcorner \times 1_\Delta"] & PA \times A
  \end{tikzcd}
\]
is a pullback.

\begin{definition}[power-object]\index{power-object}\index{topos}\index{logical functor}
  By a \emph{power-object} for \(A\) in a category \(\mathcal E\) with finite limits, we mean an object \(PA\) equipped with \(\ni_A \to PA \times A\) satisfying th above.

  We say \(\mathcal E\) is a \emph{weak topos} if every \(A \in \ob \mathcal E\) has a power-object.

  Similarly we say \(F: \mathcal E \to \mathcal F\) is \emph{weakly logical} if \(F(\ni_A) \mono F(PA) \times FA\) is a power-object for \(FA\) for every \(A \in \ob \mathcal E\).
\end{definition}

A power-object for the termimal object is the same as a subobject classifier.

This is an ad hoc defintion and we will soon show that \(\mathcal E\) is cartesian closed and therefore we can safely drop the adjective ``weak''. Consequently this may be taken as the definition of topos.

\begin{lemma}
  \(P\) is a functor \(\mathcal E^{\text{op}} \to \mathcal E\) . Moreover it is self-adjoint on the right.
\end{lemma}

Compare this with the contravariant power set functor on \(\Set\), which is a special case.

\begin{proof}
  Given \(f: A \to B\), we define \(Pf: PB \to PA\) to correspond to the pullback
  \[
    \begin{tikzcd}
      E_f \ar[r] \ar[d, tail] & \ni_B \ar[d, tail] \\
      PB \times A \ar[r, "1 \times f"] & PB \times B
    \end{tikzcd}
  \]
  For any \(\ulcorner m \urcorner: c \to PB\), it's easy to see that \((Pf) \ulcorner m \urcorner\) corresponds to \((1_C \times f)^* (m)\), hence \(f \mapsto Pf\) is functorial. For any \(A\) and \(B\), we have a bijection between subobjects of \(A \times B\) and of \(B \times A\) given by composition with \((\pi_2, \pi_1): A \times B \to B \times A\). This yields a (natural) bijection between morphisms \(A \to PB\) and \(B \to PA\).
\end{proof}

We write \(\{\}_A: A \to PA\) (pronounced ``singleton'')\index{singleton} for the morphism corresponding to \((1_a, 1_a): A \mono A \times A\).

\begin{lemma}
  Given \(f: A \to B\), \(\{\}_Bf\) corresponds to \((1_A, f): A \mono A \times B\) and \((Pf) \{\}_B\) corresponds to \((f, 1_A): A \mono B \times A\).
\end{lemma}

\begin{proof}
  The square
  \[
    \begin{tikzcd}
      A \ar[r, "f"] \ar[d, "{(1, f)}", tail] & B \ar[d, "{(1, 1)}", tail] \\
      A \times B \ar[r, "f \times 1"] & B \times B
    \end{tikzcd}
  \]
  is a pullback. Similarly for the second assertion.
\end{proof}

\begin{corollary}\leavevmode
  \begin{enumerate}
  \item \(\{\}_A: A \to A\) is monic.
  \item \(P\) is faithful.
  \end{enumerate}
\end{corollary}

\begin{proof}\leavevmode
  \begin{enumerate}
  \item If \(\{\}f = \{\}g\) then \((1_A, f)\) and \((1_A, g)\) are isomorphic as subobjects of \(A \times B\), which forces \(f = g\).
  \item Similarly if \(Pf = Pg\) then \((Pf)\{\} = (Pg)\{\}\) so we again deduce \(f = g\).
  \end{enumerate}
\end{proof}

Given a mono \(f: A \mono B\) is \(\mathcal E\), we define \(\exists f: PA \to PA\) to correspond to the composite
\[
  \begin{tikzcd}
    \ni_A \ar[r, tail] & PA \times A \ar[r, "1 \times f", tail] & PA \times B.
  \end{tikzcd}
\]
Then for any \(\ulcorner m \urcorner: C \to PA\), \((\exists f) \ulcorner m \urcorner\) correponds to
\[
  \begin{tikzcd}
    R \ar[r, "m", tail] & C \times A \ar[r, "1 \times f", tail] & C \times B
  \end{tikzcd}
\]
so \(f \mapsto \exists f\) is a functor \(\c{Mono}(\mathcal E) \to \mathcal E\).

\begin{lemma}[Beck-Chevalley condition]\index{Beck-Chevalley condition}
  Suppose
  \[
    \begin{tikzcd}
      D \ar[r, "h"] \ar[d, "k", tail] & A \ar[d, "f", tail] \\
      B \ar[r, "g"] & C
    \end{tikzcd}
  \]
  is a pullback with \(f\) monic. Then the diagram
  \[
    \begin{tikzcd}
      PA \ar[r, "\exists f"] \ar[d, "Ph"] & PC \ar[d, "Pg"] \\
      PD \ar[r, "\exists k"] & PB
    \end{tikzcd}
  \]
  commutes.
\end{lemma}

\begin{proof}
  Consider the diagram
  \[
    \begin{tikzcd}
      E_n \ar[r] \ar[d, tail] & \ni_A \ar[d, tail] \\
      PA \times D \ar[r, "1 \times h"] \ar[d, "1 \times k"] & PA \times A \ar[d, "1 \times f"] \\
      PA \times B \ar[r, "1 \times g"] & PA \times C
    \end{tikzcd}
  \]
  The lower square is a pullback so the upper square is a pull back. This is equivalent to the composite is a pullback.
\end{proof}

\begin{theorem}[Paré]\index{Paré theorem}
  The functor \(P: \mathcal E^{\text{op}} \to \mathcal E\) is monadic.
\end{theorem}

\begin{proof}
  It has a left adjoint \(P: \mathcal E \to \mathcal E^{\text{op}}\) by 7.5 (the ``self-adjoint on the right'' lemma). It's faithful by 7.7 (ii) and hence reflects isomorphisms by 7.3. \(\mathcal E^{\text{op}}\) has coequalisers since \(\mathcal E\) has equalisers. Suppose
  \[
    \begin{tikzcd}
      A \ar[r, shift left, "f"] \ar[r, shift right, "g"'] & B \ar[l, "r"']
    \end{tikzcd}
  \]
  is a coreflexive pair in \(\mathcal E\), then \(f\) and \(g\) are (split) monic and the equaliser \(e: E \to A\) makes
  \[
    \begin{tikzcd}
      E \ar[r, "e"] \ar[d, "e", tail] & A \ar[d, "g", tail] \\
      A \ar[r, "f"] & B
    \end{tikzcd}
  \]
  a pullback square. Since any cone over
  \[
    \begin{tikzcd}
      & A \ar[d, "g"] \\
      A \ar[r, "f"] & B
    \end{tikzcd}
  \]
  has both legs equal so by Beck-Chevalley condition we have \((Pf)(\exists g) = (\exists e)(Pe)\). But we also have \((Pg) (\exists g) = 1_{FA}\) since
  \[
    \begin{tikzcd}
      A \ar[r, "1"] \ar[d, "1"] & A \ar[d, "g"] \\
      A \ar[r, "g"] & B
    \end{tikzcd}
  \]
  is a pullback, and similarly \((PE)(\exists e) = 1_{PE}\). So
  \[
    \begin{tikzcd}
      PB \ar[r, shift left, "Pf"] \ar[r, shift right, "Pg"'] & PA \ar[l, bend left=50, "\exists g"] \ar[r, "Pe"] & PE \ar[l, bend left=50, "\exists e"]
    \end{tikzcd}
  \]
  is a split coequaliser and in particular a coequaliser. Hence by 5.13 \(P\) is monadic.
\end{proof}

\begin{corollary}\leavevmode
  \begin{enumerate}
  \item A weak topos has finite colimits. Moreover if it has any infinite limits then it has the corresponding colimits. In particular if it is complete then it is cocomplete.
  \item If a weakly logical functor has a left adjoint then it has a right adjoint.
  \end{enumerate}
\end{corollary}

\begin{proof}\leavevmode
  \begin{enumerate}
  \item \(P\) creates all limits which exist, by 5.e.
  \item By definition if \(F\) is weakly logical then
    \[
      \begin{tikzcd}
        \mathcal E^{\text{op}} \ar[r, "F"] \ar[d, "P"] & \exists^{\text{op}} \ar[d, "P"] \\
        \mathcal E \ar[r, "F"] & \exists
      \end{tikzcd}
    \]
    commutes up to isomorphism. So this follows from 5.16.
  \end{enumerate}
\end{proof}

\begin{lemma}
  Let \(\mathcal E\) be a category with finite limits and suppose \(A \in \ob \mathcal E\) has a power-object \(PA\). Then, for any \(B\), \(B^*(PA)\) is a power-object for \(B^*A\) in \(\mathcal E/B\).
\end{lemma}

\begin{proof}
  Given
  \begin{tikzcd}
    C \ar[d, "g"] \\
    B
  \end{tikzcd}
  we have a pullback square
  \[
    \begin{tikzcd}
      C \times A \ar[r, "g \times 1"] \ar[d, "\pi_1"] & B \times A \ar[d, "\pi_1"] \\
      C \ar[r, "g"] & B
    \end{tikzcd}
  \]
  so \(\Sigma_B(g \times B^*A) \cong C \times A\). Hence
  \[
    \Sub_{\mathcal E/B} (g \times B^*A) \cong \Sub_{\mathcal E} (C \times A),
  \]
  but if \(h: C \to PA\) corresponds to
  \begin{tikzcd}
    R \ar[d, tail] \\
    C \times A
  \end{tikzcd}
  then the upper square of the diagram
   \[
     \begin{tikzcd}
       R \ar[rr] \ar[d, tail] & & B \times \ni_A \ar[d, tail] \\
       C \times A \ar[rr, "{(g, h) \times 1_A}"] \ar[dr, "g\pi_1"'] & & B \times PA \times A \ar[dl, "\pi_1"] \\
         & B
       \end{tikzcd}
     \]
    is a pullback. So
    \begin{tikzcd}
      B \times PA \ar[d, "\pi_1"] \\
      B
    \end{tikzcd}
    equipped with \(B^*(\ni_A) \mono B^*(PA \times A)\) is a power object for \(B^*A\).
\end{proof}

\begin{theorem}
  Suppose \(\mathcal E\) is a weak topos. Then for any \(B \in \ob \mathcal E\), \(\mathcal E/B\) is a weak topos and \(B^*: \mathcal E \to \mathcal E/B\) is weakly logical.
\end{theorem}

\begin{proof}
  The second assertion follows from the previous lemma. For the first, we need to construct a power object for an arbitrary
  \begin{tikzcd}
    A \ar[d, "f"] \\
    B
  \end{tikzcd}
  in \(\mathcal E/B\). Then the pullback
  \[
    \begin{tikzcd}
      \Sigma_B(g \times f) \ar[r] \ar[d] & A \ar[d, "f"] \\
      C \ar[r, "g"] & B
    \end{tikzcd}
  \]
  is a subobject of \(C \times A\), namely the equaliser of
  \[
    \begin{tikzcd}
      C \times A \ar[r, shift left, "f\pi_1"] \ar[r, shift right, "g\pi_2"'] & B
    \end{tikzcd}
  \]

  Define \(\wedge: PA \times PA \to PA\) to correspond to the intersection of \(\pi_{13}^*(\ni_A \mono PA \times A)\) and \(\pi_{23}^*(\ni_A \mono PA \times A)\) and dfine \(P_1A \mono PA \times PA\) to be the equaliser of
  \begin{tikzcd}
    PA \times PA \ar[r, shift left, "\wedge"] \ar[r, shift right, "\pi_1"'] & PA.
  \end{tikzcd}
  Then, for any \(C\),
  \begin{tikzcd}
    C \ar[r, "{(\ulcorner m \urcorner, \ulcorner n \urcorner)}"] & PA \times PA
  \end{tikzcd}
  factors through \(P_1A\) if and only if \(m \leq n\) in \(\Sub_{\mathcal E} (C \times A)\). Now form the pullback
  \[
    \begin{tikzcd}
      Q \ar[rr] \ar[d, tail, "{(h, k)}"] & & P_1A \ar[d, tail] \\
      PA \times B \ar[r, "1 \times \{\}"] & PA \times PB \ar[r, "1 \times Pf"] & PA \times PA
    \end{tikzcd}
  \]
  Given any
  \begin{tikzcd}
    C \ar[d, "g"] \\
    B
  \end{tikzcd}
  morphisms \(g \xrightarrow{\ell} k\) in \(\mathcal E /B\) correspond to morphisms \(C \xrightarrow{h \ell} PA\) such that the subobject named by \(h\ell\) is contained in that named by \((Pf)(\{\})g\). But the latter is indeed \(\Sigma_B(g \times f) \mono C \times A\) so \(k\) is a power object for \(f\) in \(\mathcal E/B\).
\end{proof}

\begin{corollary}
  A weak topos is locally cartesian closed. In particular, it is a topos.
\end{corollary}

\begin{proof}
  For any \(f: A \to B\) in \(\mathcal E\), we can define \((\mathcal E/B)/f)\) with \(\mathcal E/A\) and \(f^*: \mathcal E/B \to \mathcal E/A\) with pullback along \(f\). Hence all such functors are weakly logical.

  But \(f^*\) has a left adjoint \(\Sigma_f\) so by 7.7 (2) (in lecture 7.10 (ii)) it has a right adjoint \(\Pi_f\). Hence by 6.3 \(\mathcal E/B\) is cartesian closed for any \(B\).
\end{proof}

\begin{remark}
  It can be shown that a weakly logical functor is cartesian closed, and hence logical.
\end{remark}

\begin{corollary}\leavevmode
  \begin{enumerate}
  \item Any epimorphism in a topos is regular.
  \item Any \(f: A \to B\) in a topos factors uniquely up to isomorphism as
    \[
      \begin{tikzcd}
        A \ar[r, "q", twoheadrightarrow] & I \ar[r, tail, "m"] & B
      \end{tikzcd}
    \]
  \end{enumerate}
\end{corollary}

\begin{proof}
  \(\mathcal E\) is locally cartesian closed by the above corollary and has coequalisers by 7.10(i) so by 6.7 every \(f\) factors uniquely as regular epi plus mono. If \(f\) itself is epic then the monic part of the factorisation is isomorphism by 7.3, so \(f\) is regular epic.
\end{proof}

\subsection{Sheaves and local operators*}

Recall that \(\Sh(X) \subseteq [\mathcal O(X)^{\text{op}}, \Set]\) is a full subcategory closed under limits. In fact it's reflective and the reflector \(L: [\mathcal O(X)^{\text{op}}, \Set] \to \Sh(X)\) preserves finite limits. This suggests considering reflective subcategories \(\mathcal D \subseteq \mathcal E\) for which the reflector preserves finite limits (equivalently, pullbacks).

\begin{lemma}
  \label{lem:closure operator}
  Given such a reflective subcategory and a monomorphism \(A' \mono A\) in \(\mathcal E\), define \(c(A') \mono A\) by the pullback diagram
  \[
    \begin{tikzcd}
      c(A') \ar[r] \ar[d, tail] & LA' \ar[d, tail] \\
      A \ar[r, "\eta_A"] & LA
    \end{tikzcd}
  \]
  Then \(A' \mapsto c(A')\) is a closure\index{closure} operation on \(\Sub_{\mathcal E}(A)\) and commutes with pullback along a fixed morphism of \(\mathcal E\).
\end{lemma}

By ``closure'' we mean an order-preserving inflationary idempotent operator.

\begin{proof}
  Since
  \[
    \begin{tikzcd}
      A \ar[r, "\eta_{A'}"] \ar[d, tail] & LA' \ar[d, tail] \\
      A \ar[r, "eta_A"] & LA
    \end{tikzcd}
  \]
  and \(A' \leq A''\) in \(\Sub(A)\) implies \(LA' \leq LA''\) in \(\Sub(LA)\) and hence \(c(A') \leq c(A'')\).

  Since \(L\eta\) is an isomorphism,
  \[
    \begin{tikzcd}
      LA' \ar[r, "L\eta_{A'}"] \ar[d, tail] & LLA' \ar[d, tail] \\
      LA \ar[r, "L\eta_A"] & LLA
    \end{tikzcd}
  \]
  is a pullback, and since \(L\) preserves pullbacks we deduce \(Lc(A') \cong LA'\) in \(\Sub(LA)\). Hence \(c(c(A')) \cong c(A')\).

  For stability under pullback, suppose
  \[
    \begin{tikzcd}
      A' \ar[r] \ar[d, tail] & B' \ar[d, tail] \\
      A \ar[r, "f"] & B
    \end{tikzcd}
  \]
  is a pullback. Then in the cube
  \[
    \begin{tikzcd}
      c(A') \ar[rr] \ar[dr] \ar[dd] & & LA' \ar[dr] \ar[dd] \\
      & c(B') \ar[rr, crossing over] & & LB' \ar[dd] \\
      A \ar[rr, "\eta_A", near end] \ar[dr, "f"] && LA \ar[dr, "Lf"] \\
      & B \ar[rr, "\eta_B"] \ar[from=uu, crossing over] && LB
    \end{tikzcd}
  \]

  the front, back and right faces are pullbacks, whence the left face is too.
\end{proof}

\begin{definition}[local operator]\index{local operator}
  Let \(\mathcal E\) be a topos. By a \emph{local operator} in \(\mathcal E\) we mean a morphism \(j: \Omega \to \Omega\) satisfying the commutative diagrams
  \[
    \begin{tikzcd}
    \end{tikzcd}
  \]
  \[
    \begin{tikzcd}
      1 \ar[r, "\top"] \ar[dr, "\top"'] & \Omega \ar[d, "j"] & \Omega \ar[l, "j"'] \ar[dl, "j"] \\
      & \Omega
    \end{tikzcd}
    \qquad
    \begin{tikzcd}
      \Omega_1 \ar[r] \ar[d, tail] & \Omega_1 \ar[d, tail] \\
      \Omega \times \Omega \ar[r, "j \times j"] & \Omega \times \Omega
    \end{tikzcd}
  \]
  where \(\Omega_1\) is the order relation on \(\Omega\) define in 7.12.

  Given a closure operator on subobjects in the above lemma, define \(J \mono \Omega\) to be the closure of \(\top: 1 \mono \Omega\) and \(j: \Omega \to \Omega\) to be the classifying map of \(J \mono \Omega\). Then, for any \(A' \mono A\) with classifying map \(\chi_m: A \to \Omega\), the composite \(j \chi_m\) classifies \(c(A') \mono A\).
\end{definition}

Given a pullback-stable cloure operation \(c\) on subobjects, we say \(A' \mono A\) is \emph{dense}\index{dense} if \(c(A') \mono A\) is isomorphism, and \emph{closed}\index{closed} if \(A' \mono c(A')\) is isomorphism.

\begin{lemma}
  \label{lem:factorisation through dense and closed}
  Suppose given a commutative square
  \[
    \begin{tikzcd}
      B' \ar[r, "f'"] \ar[d, "n", tail] & A' \ar[d, "m", tail] \\
      B \ar[r, "f"] & A
    \end{tikzcd}
  \]
  with \(n\) dense and \(m\) closed. Then there is a unique \(g: B \to A'\) with \(mg = f\) (and \(gn = f'\)).
\end{lemma}

\begin{proof}
  We have \(n \leq f^*(m)\) in \(\Sub(B)\) so
  \[
    1_B \cong c(n) \leq f^*(c(m)) \cong f^*(m)
  \]
  so we define \(g\) as
  \[
    \begin{tikzcd}
      B \ar[r, "\cong"] & f^*(A') \ar[r] & A'
    \end{tikzcd}
  \]
\end{proof}

Note that \(c(A')\) may be characterised as the unique (up to isomorphism) subobject \(A''\) such that \(A' \mono A''\) is dense and \(A'' \mono A\) is closed.

\begin{lemma}
  Suppose \(c\) is induced as in \Cref{lem:closure operator} by a reflector \(L: \mathcal E \to \mathcal D\) preserving finite limits. Then an object \(A\) of \(\mathcal E\) belongs to \(\mathcal D\) (up to isomorphism) if and only if, given any diagram
  \[
    \begin{tikzcd}
      B' \ar[r, "f'"] \ar[d, "m", tail] & A \\
      B
    \end{tikzcd}
  \]
  with \(m\) dense, there exists a unique \(f: B \to A\) with \(fm = f'\).
\end{lemma}

\begin{proof}
  Note first that \(m\) is dense if and only if \(Lm\) is an isomorphism: \(\impliedby\) follows from the definition. \(\implies\) follows since, by the proof of \Cref{lem:closure operator}, we know \(L(B')\) and \(L(c(B'))\) are isomorphic in \(\Sub(B)\).

  Given this, if \(A\) is in \(\mathcal D\) then the given diagram extends uniquely to
  \[
    \begin{tikzcd}
      B' \ar[r, "\eta_{B'}"] \ar[d, tail] & LB' \ar[d, "\cong"] \ar[r] & A \\
      B \ar[r, "\eta_B"] & LB \ar[ur]
    \end{tikzcd}
  \]
  Conversely, suppose \(A\) satisfies the condition. Let
  \begin{tikzcd}
    R \ar[r, shift left, "a"] \ar[r, shift right, "b"'] & A
  \end{tikzcd}
  be the kernel-pair of \(\eta_A: A \to LA\) and \(d: A \mono R\) the factorisation of \((1_A, 1_A)\) through \((a, b)\). Since \(L\eta_A\) is isomorphism and \(L\) preservse pullbacks, \(Ld\) is isomorphism so \(d\) is dense. This forces \(a = b\) so \(\eta_A\) is monic. And \(\eta_A\) is dense so we get a unique \(r: LA \to A\) with \(r\eta_A = 1_A\). Now \(\eta_A r \eta_A = \eta_A\) and since \(LA\) satisfies the condition we have \(\eta_A r = 1_{LA}\).
\end{proof}

We say \(A\) is a \emph{sheaf} (for \(c\), or for \(j\)) it it satisfies the condition in the previous lemma. Given a local operator \(j\) on \(\mathcal E\), we write \(\sh_j(\mathcal E)\) for the full subcategory of \(j\)-sheaves in \(\mathcal E\).

Our aim is to show \(\sh_j(\mathcal E)\) is a topos.

\begin{lemma}
  \(\sh_j(\mathcal E)\) is closed under limits in \(\mathcal E\) and an exponential ideal.
\end{lemma}

\begin{proof}
  The first assertion follows since the definition involves only morphisms with codomain \(A\). For the second, note that if \(m: B' \mono B\) is dense the so is \( \times 1_C: B' \times C \mono B \times C\) for any \(C\) (since it's \(\pi_1^*(m)\)) and so if \(A\) is a sheaf then any morphism \(B' \to A^C\) extends uniquely to a morphism \(B \to A^C\).
\end{proof}

\begin{lemma}
  If \(A\) is a sheaf then a subobject \(m: A' \mono A\) in \(\mathcal E\) is a sheaf if and only if it is closed.
\end{lemma}

\begin{proof}\leavevmode
  \begin{itemize}
  \item \(\impliedby\): Immediate from \Cref{lem:factorisation through dense and closed}.
  \item \(\implies\): Consider
    \[
      \begin{tikzcd}
        A' \ar[r, "p", tail] & c(A') \ar[r, "q", tail] & A
      \end{tikzcd}
    \]
    \(p\) is dense so if \(A\) is a sheaf we get a unique \(r: c(A') \to A'\) with \(rp = 1_{A'}\). But \(c(A')\) is a sheaf so \(prp = p\) and thus \(pr = 1_{c(A')}\).
  \end{itemize}
\end{proof}

We define \(\Omega_j \mono \Omega\) to be the equaliser of
\begin{tikzcd}
  \Omega \ar[r, shift left, "j"] \ar[r, shift right, "1_\Omega"'] & \Omega.
\end{tikzcd}
Then for any \(A\), morphisms \(A \to \Omega_j\) corresponding to closed subobjects of \(A\).

\begin{lemma}
  \(\Omega_j\) is a \(j\)-sheaf.
\end{lemma}

\begin{proof}
  We want to show that if \(m: B \mono A\) is a dense mono the pullback along \(m\) yields a bijection from closed subobjects of \(A\) to closed subobjects of \(B\). If \(n: A' \mono A\) is closed then the pullback
  \[
    \begin{tikzcd}
      B' \ar[r, "m'", tail] \ar[d, "n'", tail] & A' \ar[d, "n", tail] \\
      B \ar[r, "m", tail] & A
    \end{tikzcd}
  \]
  \(m'\) is dense so \(A' \mono A\) is the closure of \(B' \mono B \mono A\). It remains to show that if \(B' \mono B\) is closed, it is iso up to the pullback of its closure in \(A\). But (writing \(A' \mono A\) for the closure) we have a factorisation \(B' \to f^*A'\) which is dense since \(B' \to A'\) is dense, and closed since \(B' \to B\) is closed.
\end{proof}

\begin{theorem}
  For any local operator \(j\) on \(\mathcal E\), \(\sh_j(\mathcal E)\) is a topos. Moreover it's reflective in \(\mathcal E\) and the reflector preserves finite limits.
\end{theorem}

\begin{proof}
  \(\sh_j(\mathcal E)\) is cartesian closed and has a subobject classifier \(\Omega_j\) by the lemma. To construct the reflect, consider the composite
  \[
    \begin{tikzcd}
      A \ar[r, "\{\}", tail] & \Omega^A \ar[r, "j^A", tail] & \Omega_j^A
    \end{tikzcd}
  \]
  this corresponds to the closure \((a, b): \cl A \mono A \times A\) of the diagonal subobject \((1_A, 1_A): A \mono A \times A\). I claim (with proof omitted) that
  \begin{tikzcd}
    \cl A \ar[r, shift left, "a"] \ar[r, shift right, "b"'] & A
  \end{tikzcd}
  is the kernel-pair of \(f\). Hence any morphism \(g: A \to B\) where \(B\) is a sheaf satisfies \(ga = gb\). So if we form the image
  \[
    \begin{tikzcd}
      A \ar[r, "q", twoheadrightarrow] & I \ar[r, "m", tail] & \Omega_j^A
    \end{tikzcd}
  \]
  of \(f\) any such \(g\) factors uniquely through \(q\).

  Now \(\Omega_j^A\) is a sheaf by the lemmas so if we form the closure \(LA \mono \Omega_j^A\) of \(m\), we get a morphism \(A \to LA\) through which any morphism from \(A\) to a sheaf factors uniquely. Hence \(L\) becomes a functor \(\mathcal E \to \sh_j(\mathcal E)\), left adjoint to the inclusion.

  By 6.13, we know \(L\) preserves finite products. In fact it preserves equalisers as well (can be checked but omitted here).
\end{proof}

Finally, we state the relation between topos and the topos Grothendieck was interested in (i.e.\ sheaves):

\begin{theorem}
  For a category \(\mathcal E\), TFAE:
  \begin{enumerate}
  \item \(\mathcal E\) is a topos, complete and locally small and has a separating set of objects.
  \item there exists a small category \(\c C\) and a local operators on \([\c C^{\text{op}}, \Set]\) such that
    \[
      \mathcal E \simeq \sh_j([\c C^{\text{op}}, \Set]).
    \]
  \end{enumerate}
\end{theorem}

\begin{proof}[Sketch of proof]\leavevmode
  \begin{enumerate}
  \item \(1 \implies 2\): since \(\sh_j([\c C^{\text{op}}, \Set])\) has given properties.
  \item \(1 \impliedby 2\): take \(\c C\) to be the full subcategory of \(\mathcal E\) on the separating set and consider
    \[
      \begin{tikzcd}
        \mathcal E \ar[r, "Y"] & {[\mathcal E^{\text{op}}, \Set]} \ar[r] & {[\c C^{\text{op}}, \Set]}.
      \end{tikzcd}
    \]
  \end{enumerate}
\end{proof}

\printindex
\end{document}