\subsection{Categorical limits}\label{subsec:categorical_limits}

\begin{definition}\label{def:comma_category}\mcite[def. 2.3.1]{Leinster2016Basic}
  Comma categories allow us to define morphisms between morphisms, which becomes useful in, for example, the concise definition of a limit in \fullref{def:category_of_cones/limit}.

  \begin{thmenum}
    \thmitem{def:comma_category/variable} We first prove the most general construction. Let \( F: \cat{A} \to \cat{C} \) and \( G: \cat{B} \to \cat{C} \) be any two functors with a common codomain. We define their \term{comma category} \( (F \downarrow G) \) as follows:

    \begin{itemize}
      \item The \hyperref[def:category/objects]{set of objects} \( \obj(F \downarrow G) \) is the set of triples \( (A, s, B) \), where \( A \in \cat{A} \), \( B \in \cat{B} \) and \( s: F(A) \to G(B) \).

      \item The \hyperref[def:category/morphisms]{set of morphisms} \( [F \downarrow G]((A, s, B), (A', s', B')) \) is the set of pairs
      \begin{equation*}
        (f: A \to A', g: B \to B'),
      \end{equation*}
      such that the following diagram commutes:
      \begin{equation}\label{eq:def:comma_category/variable}
        \begin{aligned}
          \includegraphics[page=1]{output/def__comma_category.pdf}
        \end{aligned}
      \end{equation}

      \item The \hyperref[def:category/composition]{composition of morphisms} is their pairwise composition, analogically to \hyperref[def:product_category]{product categories}.

      \item The \hyperref[def:category/identity]{identity morphism} on the object \( (A, s, B) \) is the identity pair \( (\id_A, \id_B) \).
    \end{itemize}

    \thmitem{def:comma_category/fixed} It is often the case where either \( F \) or \( G \) are constant. If, instead of \( G \), we are given an object \( X \) in \( \cat{C} \), we use the constant functor \( \Delta_X^{\cat{1}}: \cat{1} \to \cat{C} \) with domain the \hyperref[def:universal_categories]{terminal category} \( \cat{1} \), in order to use the comma category \( (F \downarrow \Delta_X^{\cat{1}}) \).

    We can thus simplify \fullref{def:comma_category/variable} as follows:

    \begin{minipage}[t]{0.43\textwidth}
      \begin{equation*}
        (F \downarrow X) \coloneqq (F \downarrow \Delta_X^{\cat{1}}).
      \end{equation*}

      \begin{itemize}
        \item The \hyperref[def:category/objects]{set of objects} \( \obj(F \downarrow X) \) is
        \begin{equation*}
          \set{ (A, s) \given s: F(A) \to X }
        \end{equation*}

        \item The \hyperref[def:category/morphisms]{hom-set}
        \begin{equation*}
          [F \downarrow X]\parens[\Big]{ (A, s), (A', s') }
        \end{equation*}
        is the set of \( f: A \to A' \), such that
        \begin{equation}\label{eq:def:comma_category/fixed/right}
          \begin{aligned}
            \includegraphics[page=2]{output/def__comma_category.pdf}
          \end{aligned}
        \end{equation}
      \end{itemize}
    \end{minipage}
    \begin{minipage}[t]{0.43\textwidth}
      \begin{equation*}
        (X \downarrow G) \coloneqq (\Delta_X^{\cat{1}} \downarrow G)
      \end{equation*}

      \begin{itemize}
        \item The \hyperref[def:category/objects]{set of objects} \( \obj(X \downarrow G) \) is
        \begin{equation*}
          \set{ (s, B) \given s: X \to F(B) }
        \end{equation*}

        \item The \hyperref[def:category/morphisms]{hom-set}
        \begin{equation*}
          [X \downarrow G]\parens[\Big]{ (s, B), (s', B') }
        \end{equation*}
        is the set of \( g: B \to B' \), such that
        \begin{equation}\label{eq:def:comma_category/fixed/left}
          \begin{aligned}
            \includegraphics[page=3]{output/def__comma_category.pdf}
          \end{aligned}
        \end{equation}
      \end{itemize}
    \end{minipage}
  \end{thmenum}
\end{definition}

\begin{definition}\label{def:factors_through}\mcite[133]{Knapp2016BasicAlgebra}
  Consider a morphism \( f: A \to B \). We say that \( f \) \term{factors through} the object \( X \) if there exist morphisms \( g: A \to X \) and \( h: X \to B \) such that the following diagram commutes:
  \begin{equation}\label{eq:def:factors_through}
    \begin{aligned}
      \includegraphics[page=1]{output/def__factors_through.pdf}
    \end{aligned}
  \end{equation}

  If, given \( g \), \( h \) is unique or vice versa, we say that \( f \) \term{uniquely factors through} \( X \). In some cases, for example in \fullref{def:zero_morphisms/morphism}, \( f \) there exists unique \( g \) and \( h \) and neither of them must be given beforehand.
\end{definition}

\begin{definition}\label{def:category_of_cones}
  Let \( D: \cat{I} \to \cat{C} \) be a \hyperref[def:categorical_diagram]{diagram}.

  \begin{thmenum}
    \thmitem{def:category_of_cones/category} We define \term{category of cones} to \( D \) as the \hyperref[def:comma_category/fixed]{constant-functor comma category}
    \begin{equation*}
      \cat{Cone}(D) \coloneqq \underbrace{ (\Delta^{\cat{I}} \downarrow D) }_{(\Delta^{\cat{I}} \downarrow \Delta^{\cat{1}}_{D})},
    \end{equation*}
    where \( \Delta^{\cat{I}}: \cat{C} \to [\cat{I}, \cat{C}] \) is the \( \cat{I} \)-shaped \hyperref[def:diagonal_functor]{diagonal functor} on \( \cat{C} \).

    \thmitem{def:category_of_cones/cone} A \( D \)-\term{cone} is simply a member of \( \cat{Cone}(D) \).

    Explicitly, a cone with \term{vertex} \( A \in \cat{C} \) is a pair \( (\Delta^{\cat{I}}_A, \alpha) \), where \( \Delta^{\cat{I}}_A \) is the constant functor at \( A \) and \( \alpha \) is a natural transformation from \( \Delta^{\cat{I}}_A \) to \( D \).

    Even more explicitly, a cone is a family of morphisms
    \begin{equation}\label{eq:def:category_of_cones/cone}
      \seq{ \alpha_k: A \to D(k) }_{k \in \cat{I}}.
    \end{equation}
    satisfying a simplified naturality condition (compared to \eqref{eq:def:natural_transformation/diagram}). For every morphism \( u: k \to m \) in \( \cat{I} \), the following diagram must commute:
    \begin{equation}\label{eq:def:category_of_cones/cone_nat}
      \begin{aligned}
        \includegraphics[page=1]{output/def__category_of_cones.pdf}
      \end{aligned}
    \end{equation}

    Note that this diagram is very different from \eqref{eq:def:comma_category/fixed/right}, they merely look similar.

    \thmitem{def:category_of_cones/limit} A \term{limit cone} of the diagram \( D \) is a \hyperref[def:universal_objects/terminal]{terminal object} of the cone category \( \cat{Cone}(D) \).

    Explicitly, \( (L, \lambda) \) is limit cone if, for every cone \( (A, \alpha) \), there exists a unique \hyperref[eq:def:comma_category/fixed/right]{cone morphism} \( l_A: (A, \alpha) \to (L, \lambda) \).

    Even more explicitly, \( (L, \lambda) \) is a limit cone if it satisfies the following \hyperref[rem:limit_universal_mapping_property]{universal mapping property}:
    \begin{displayquote}
      For every cone \( (A, \alpha) \), there exists a unique morphism \( l_A: A \to L \) such that following diagram commutes for every index morphism \( u: k \to m \):
      \begin{equation}\label{eq:def:category_of_cones/limit}
        \begin{aligned}
          \includegraphics[page=2]{output/def__category_of_cones.pdf}
        \end{aligned}
      \end{equation}
    \end{displayquote}

    Thus, \( \alpha_k \) \hyperref[def:factors_through]{uniquely factors through} \( L \) for every \( k \in \cat{I} \). Furthermore, \( l_A \) is compatible with morphisms in \( \cat{I} \) and does not depend on \( k \).

    From \fullref{thm:def:universal_objects/terminal} and \fullref{thm:universal_objects_as_adjunctions/terminal} it follows that a limit, if it exists, is unique up to a unique isomorphism.

    Without further context, we usually refer to \( L \) as the limit vertex and \( (L, \lambda) \) as the limit cone. By \enquote{the limit}, we usually mean the vertex \( L \).

    \thmitem{def:category_of_cones/cocone} \hyperref[thm:categorical_principle_of_duality]{Dually}, a \( D \)-\term{cocone} with vertex \( A \) is a family of morphisms
    \begin{equation}\label{eq:def:category_of_cones/cocone}
      \seq{ \alpha_k: D(k) \to A }_{k \in \cat{I}}.
    \end{equation}
    satisfying the naturality condition that for every morphism \( u: k \to m \) in \( \cat{I} \), the following diagram must commute:
    \begin{equation}\label{eq:def:category_of_cones/cocone_nat}
      \begin{aligned}
        \includegraphics[page=3]{output/def__category_of_cones.pdf}
      \end{aligned}
    \end{equation}

    \thmitem{def:category_of_cones/colimit} A \term{colimit cocone} of the diagram \( D \) is an \hyperref[def:universal_objects/initial]{initial object} of the cocone category \( (D \downarrow \Delta) \).

    There are two major differences compared to limits: a colimit cocone is an initial object, not a terminal object, and its underlying comma category is \( (D \downarrow \Delta) \), not \( (\Delta^{\cat{I}} \downarrow D) \).

    The analogous diagram to \eqref{eq:def:category_of_cones/limit} is exactly its \hyperref[thm:categorical_principle_of_duality]{opposite}:
    \begin{equation}\label{eq:def:category_of_cones/colimit}
      \begin{aligned}
        \includegraphics[page=4]{output/def__category_of_cones.pdf}
      \end{aligned}
    \end{equation}

    In particular, \( \alpha_k \) \hyperref[def:factors_through]{uniquely factors through} \( L \) for every \( k \in \cat{I} \).

    Without further context, we usually refer to \( L \) as the colimit vertex and \( (L, \lambda) \) as the colimit cocone. By \enquote{the colimit}, we usually mean the vertex \( L \).
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:categorical_limit_duality}
  For every \hyperref[def:category_of_cones/cone]{cone} \( (A, \alpha) \) of the \hyperref[def:categorical_diagram]{diagram} \( D \) in \( \cat{C} \), \( (A, \alpha^{\opcat}) \) is a \hyperref[def:category_of_cones/cone]{cocone} of \( D^{\opcat} \) in the \hyperref[def:opposite_category]{opposite category} \( \cat{C}^{\opcat} \).

  Even more, for every \hyperref[def:category_of_cones/limit]{limit} \( (L, \lambda) \) of \( D \) in \( \cat{C} \), \( (L, \lambda^{\opcat}) \) is a \hyperref[def:category_of_cones/colimit]{colimit} of \( D^{\opcat} \) in \( \cat{C}^{\opcat} \).

  This is part of the duality principles listed in \fullref{thm:categorical_principle_of_duality}.
\end{proposition}
\begin{proof}
  Note that the defining diagrams \eqref{eq:def:category_of_cones/cone}, \eqref{eq:def:category_of_cones/cone_nat} and \eqref{eq:def:category_of_cones/limit} are dual to \eqref{eq:def:category_of_cones/cocone}, \eqref{eq:def:category_of_cones/cocone_nat} and \eqref{eq:def:category_of_cones/colimit}.
\end{proof}

\begin{lemma}\label{thm:categorical_limit_uniqueness_lemma}
  Any two limits (resp. colimits) of a diagram are isomorphic.

  We prove a stronger result in \fullref{thm:categorical_limit_uniqueness}.
\end{lemma}
\begin{proof}
  Let \( (L', \lambda') \) and \( (L^\dprime, \lambda^\dprime) \) be two limit cones over the diagram \( D: \cat{I} \to \cat{C} \). The definition \eqref{eq:def:category_of_cones/limit} of a limit implies that
  \begin{equation}\label{eq:thm:categorical_limit_uniqueness}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__categorical_limit_uniqueness.pdf}
    \end{aligned}
  \end{equation}
  commutes.

  Therefore, the limits \( L' \) and \( L^\dprime \) are isomorphic.

  Now let \( (L', \lambda') \) and \( (L^\dprime, \lambda^\dprime) \) be colimit cocones. By \fullref{thm:categorical_limit_duality}, \( (L', \lambda'^{\opcat}) \) and \( (L^\dprime, {\lambda^\dprime}^{\opcat}) \) are limits in the opposite category and are thus isomorphic. By \fullref{thm:morphism_invertibility_duality}, the colimits are isomorphic.
\end{proof}

\begin{proposition}\label{thm:categorical_limit_is_adjoint}
  Suppose that, for a given category \( \cat{C} \), the limits over all \( \cat{I} \)-shaped diagrams exist. Denote by \( \lim(D) \) the vertex of the limiting cone of the diagram \( D \).

  Given a natural transformation \( \alpha: D \to E \) between diagrams, the diagram \eqref{eq:thm:categorical_limit_is_adjoint/c_triangle} defining a limit uniquely determines a morphism \( \lim(D) \) to \( \lim(E) \). Denote this morphism by \( \lim(\alpha) \).

  We have defined a functor
  \begin{equation*}
    \lim: [\cat{I}, \cat{C}] \to \cat{C}.
  \end{equation*}

  This functor is \hyperref[def:category_adjunction]{right adjoint} to the diagonal functor
  \begin{equation*}
    \Delta: \cat{C} \to [\cat{I}, \cat{C}]
  \end{equation*}

  \hyperref[thm:categorical_principle_of_duality]{Dually}, the colimit functor
  \begin{equation*}
    \co\lim: [\cat{I}, \cat{C}] \to \cat{C}
  \end{equation*}
  is left adjoint to \( \Delta \).
\end{proposition}
\begin{proof}
  It is sufficient to prove this for limits since the statement for colimits follows from the duality principles \fullref{thm:category_adjunction_duality} and \fullref{thm:categorical_limit_duality}. The unit \( \eta: \id_{\cat{C}} \to [{\lim} \bincirc \Delta] \) of the adjunction
  \begin{equation*}
    \Delta \dashv \lim
  \end{equation*}
  is the unique morphism from an object \( A \) of \( \cat{C} \) to the limit of its constant diagram \( \Delta_A: \cat{I} \to \cat{C} \) such that \eqref{eq:def:category_of_cones/limit} commutes. The counit is more complicated because its components are themselves natural transformations:
  \begin{equation*}
    \begin{aligned}
      \varepsilon:       &[\Delta \bincirc \lim] \Rightarrow \id_{[\cat{I}, \cat{C}]} \\
      \varepsilon_D:     &\Delta(\lim D) \Rightarrow D \\
      \varepsilon_{D,k}: &\lim(D) \to D(k),
    \end{aligned}
  \end{equation*}
  where \( \varepsilon_{D,k} \) are the projections of the limit.

  For any diagram \( D: \cat{I} \to \cat{C} \), the following triangle commutes:
  \begin{equation}\label{eq:thm:categorical_limit_is_adjoint/ic_triangle}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__categorical_limit_is_adjoint.pdf}
    \end{aligned}
  \end{equation}

  Indeed,
  \begin{equation*}
    \eta_{\lim(D)}: \lim(D) \to \smash{ \overbrace{\lim(\Delta_{\lim(D)})}^{[{\lim} \bincirc \Delta \bincirc {\lim}](D)} }
  \end{equation*}
  is the unique morphism such that \eqref{eq:def:category_of_cones/limit} commutes, and (somewhat) similarly for
  \begin{equation*}
    \lim(\varepsilon_D): [{\lim} \bincirc \Delta \bincirc {\lim}](D) \to \lim(D).
  \end{equation*}

  It follows that both \( \lim(D) \) and \( [{\lim} \bincirc \Delta \bincirc {\lim}](D) \) are limits over the same diagram. By \fullref{thm:categorical_limit_is_adjoint}, they are isomorphic, and hence \eqref{eq:thm:categorical_limit_is_adjoint/ic_triangle} commutes.

  Also, for any object \( A \) in \( \cat{C} \), the following triangle also commutes:
  \begin{equation}\label{eq:thm:categorical_limit_is_adjoint/c_triangle}
    \begin{aligned}
      \includegraphics[page=2]{output/thm__categorical_limit_is_adjoint.pdf}
    \end{aligned}
  \end{equation}

  Indeed,
  \begin{equation*}
    \Delta(\eta_A) = \seq{ \eta_A: A \to \lim(\Delta_A) }_{k \in \cat{I}}
  \end{equation*}
  is the constant family consisting of \( \eta_A \) and
  \begin{equation*}
    \varepsilon_{\Delta(A)} = \seq{ \lambda_k^{\Delta_A}: \lim(\Delta_A) \to \underbrace{\Delta_A(k)}_{A} }_{k \in \cat{I}}.
  \end{equation*}
  is a constant family of the single projection of the limit to \( A \). From the commutativity of \eqref{eq:def:category_of_cones/limit} it follows that \eqref{eq:thm:categorical_limit_is_adjoint/c_triangle} also commutes.
\end{proof}

\begin{corollary}\label{thm:categorical_limit_uniqueness}
  A limit (resp. colimit) of a diagram, if it exists, is unique up to a unique isomorphism.

  This statement strengthens \fullref{thm:categorical_limit_uniqueness_lemma}.
\end{corollary}
\begin{proof}
  Follows from \fullref{thm:functor_adjoint_uniqueness} and \fullref{thm:categorical_limit_is_adjoint}.
\end{proof}

\begin{remark}\label{rem:limit_universal_mapping_property}
  The limit diagram \eqref{eq:def:category_of_cones/limit} may seem unrelated to the universal mapping properties discussed in \fullref{rem:universal_mapping_property}, however it is actually a special case.

  Suppose that, for a given category \( \cat{C} \), the limits over all \( \cat{I} \)-shaped diagrams exist and fix a diagram \( D: \cat{I} \to \cat{C} \). Consider the functors
  \begin{align*}
    \lim:   &[\cat{I}, \cat{C}] \to \cat{C} \\
    \Delta: &\cat{C} \to [\cat{I}, \cat{C}]
  \end{align*}
  discussed in \fullref{thm:categorical_limit_is_adjoint}. We have established that \( \Delta \dashv \lim \).

  For every diagram \( D: \cat{I} \to \cat{C} \), there exist unique up to a unique isomorphism object \( \lim(D) \) in \( \cat{C} \) and canonical projection map \( \lambda: [\Delta \bincirc {\lim}(D)] \to D \) satisfying the following universal mapping property:
  \begin{displayquote}
    For every object \( A \) in \( \cat{C} \) and every natural transformation \( \alpha: \Delta(A) \Rightarrow D \), there exists a unique morphism \( l: A \to \lim(D) \) such that the following diagram commutes:
    \begin{equation}\label{eq:rem:limit_universal_mapping_property/ic_triangle}
      \begin{aligned}
        \includegraphics[page=1]{output/rem__limit_universal_mapping_property.pdf}
      \end{aligned}
    \end{equation}
  \end{displayquote}

  For a fixed index object \( k \in \cat{I} \), this becomes:
  \begin{equation}\label{eq:rem:limit_universal_mapping_property/c_triangle_basic}
    \begin{aligned}
      \includegraphics[page=2]{output/rem__limit_universal_mapping_property.pdf}
    \end{aligned}
  \end{equation}

  The defining diagram \eqref{eq:def:category_of_cones/limit} of a limit simply encodes the cone naturality condition \eqref{eq:def:category_of_cones/cone_nat} into \eqref{eq:rem:limit_universal_mapping_property/c_triangle_basic}.

  Except for being simpler to check, limits defined via universal mapping properties have the advantage (compared to adjoint functors) that limits can exist for some diagrams and not for others.

  The construction for colimits is dual.
\end{remark}

\begin{proposition}\label{thm:limits_of_empty_diagram}
  The \hyperref[def:category_of_cones/limit]{limits} of an empty diagram over \( \cat{C} \) are the \hyperref[def:universal_objects/terminal]{terminal objects} and the \hyperref[def:category_of_cones/colimit]{colimits} are the \hyperref[def:universal_objects/initial]{initial object}.

  Compare this result with \fullref{thm:limits_of_identity_functor}.
\end{proposition}
\begin{proof}
  A cone of the empty diagram is simply an object of \( \cat{C} \). A limit cone is then an object \( L \) such that every other object \( A \) has a unique morphism \( l_A: A \to L \). This is precisely the definition of a terminal object.

  The statement for colimits follows by \hyperref[thm:categorical_principle_of_duality]{duality}.
\end{proof}

\begin{proposition}\label{thm:limits_of_identity_functor}
  Fix an arbitrary category \( \cat{C} \).

  \begin{thmenum}
    \thmitem{thm:limits_of_identity_functor/initial_object_ks_limit} If \( I \) is an \hyperref[def:universal_objects/initial]{initial object} of \( \cat{C} \), \( (I, \xi) \) is a limit cone of the \hyperref[eq:def:category_of_small_categories/identity]{identity functor} \( \id_{\cat{C}} \), where
    \begin{equation*}
      \xi \coloneqq \seq{ \xi_A: I \to A }_{A \in \cat{C}}
    \end{equation*}
    is the family of unique morphisms with domain \( I \).

    \thmitem{thm:limits_of_identity_functor/limit_ks_knitial_object} Conversely, if \( (L, \lambda) \) is a limit cone of the identity, then \( L \) is an initial object.
  \end{thmenum}

  \hyperref[thm:categorical_principle_of_duality]{Dually}, by \fullref{thm:universal_object_duality} and \fullref{thm:categorical_limit_duality}, the cocones (and colimits) of the identity functor are the terminal objects.

  Compare this result with \fullref{thm:limits_of_empty_diagram}.
\end{proposition}
\begin{proof}
  \SubProofOf{thm:limits_of_identity_functor/initial_object_ks_limit} For an initial object \( I \) with morphisms \( \xi \), and for any morphism \( f: B \to C \), from the uniqueness of the arrows in \( \xi \) it follows that \( \xi_C = f \bincirc \xi_B \). Thus, the following naturality diagram commutes:
  \begin{equation}\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/nat}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__limits_of_identity_functor.pdf}
    \end{aligned}
  \end{equation}

  Therefore, \( (I, \xi) \) is a cone.

  Now let \( (A, \alpha) \) be another cone. The naturality of \( \alpha \) implies that the following diagram commutes for every object \( B \):
  \begin{equation}\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/half_limit}
    \begin{aligned}
      \includegraphics[page=2]{output/thm__limits_of_identity_functor.pdf}
    \end{aligned}
  \end{equation}

  In particular, since \( \xi_I = \id_I \), for every morphism \( g: A \to I \) we have
  \begin{equation}\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/cone_morphism_uniqueness}
    \begin{aligned}
      \includegraphics[page=3]{output/thm__limits_of_identity_functor.pdf}
    \end{aligned}
  \end{equation}
  which shows that \( \alpha_I = g \) and thus \( \alpha_I \) is the unique morphism from \( A \) to \( I \).

  Therefore, for any morphism \( f: B \to C \), the following diagram commutes:
  \begin{equation}\label{eq:def:thm:limits_of_identity_functor/initial_object_ks_limit/limit}
    \begin{aligned}
      \includegraphics[page=4]{output/thm__limits_of_identity_functor.pdf}
    \end{aligned}
  \end{equation}

  This is precisely the defining diagram for a limit cone. Therefore, \( (I, \xi) \) is a limit cone.

  \SubProofOf{thm:limits_of_identity_functor/limit_ks_knitial_object} Let \( (L, \lambda) \) be a limit cone of the identity. The component \( \lambda_B \) of the natural transformation \( \lambda \) is a morphism from \( L \) to \( B \). In order for \( L \) to be an initial object, these morphisms must be unique.

  Since \( (L, \lambda) \) is a limit cone, for any cone \( (A, \alpha) \) and any morphism \( f: B \to C \), there exists a unique morphism \( l_A: A \to L \) such that the following diagram commutes:
  \begin{equation}\label{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/limit}
    \begin{aligned}
      \includegraphics[page=5]{output/thm__limits_of_identity_functor.pdf}
    \end{aligned}
  \end{equation}

  In particular, there exists a unique map \( l_L: L \to L \) for the cone \( (L, \lambda) \) such that the following diagram commutes:
  \begin{equation}\label{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/endomorphism_uniqueness}
    \begin{aligned}
      \includegraphics[page=6]{output/thm__limits_of_identity_functor.pdf}
    \end{aligned}
  \end{equation}

  Since \eqref{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/endomorphism_uniqueness} commutes with \( \id_L \) instead of \( l_L \), by uniqueness it follows that \( l_L = \id_L \). Since, by the naturality of \( \lambda \), \( \lambda_L \) also satisfies this condition, \( \lambda_L = \id_L \).

  From the naturality of \( \lambda \), for any map \( f: L \to C \) it follows that the following diagram commutes:
  \begin{equation}\label{eq:def:thm:limits_of_identity_functor/limit_ks_knitial_object/morphism_uniqueness}
    \begin{aligned}
      \includegraphics[page=7]{output/thm__limits_of_identity_functor.pdf}
    \end{aligned}
  \end{equation}

  Therefore, \( f = \lambda_B \). Since \( f \) was an arbitrary morphism with domain \( L \), we conclude that \( L \) has a unique morphism to every object in \( \cat{C} \). Hence, \( L \) is an initial object.
\end{proof}

\begin{example}\label{ex:limits_of_partially_ordered_set}
  We will show that limits and colimits correspond to suprema and infima of partially ordered sets.

  Let \( (P, \leq) \) be a \hyperref[def:partially_ordered_set]{partially ordered set} and \( \cat{P} \) be its corresponding \hyperref[def:thin_category]{thin} \hyperref[def:skeletal_category]{skeletal} category. The correspondence is discussed in \fullref{thm:order_category_isomorphism/preordered}.

  The image of a diagram \( D: \cat{I} \to \cat{P} \) is a pair \( (A, R) \), where \( A \) is the set of objects \( D(\obj(\cat{I})) \) in the image \( D(\cat{I}) \) and \( R \) is a subrelation of \( \leq \). This relation is reflexive, however it may not even be a preorder as shown in \fullref{ex:functor_image_not_a_category}.

  Conversely, every subset \( A \subseteq P \) with a corresponding category \( \cat{A} \) is given by the diagram \( \Iota_A \), where the \hyperref[def:subcategory]{inclusion functor} \( \Iota_A: \cat{A} \to \cat{P} \).

  A cone of a diagram \( D: \cat{I} \to \cat{P} \) is a \hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{lower bound} of the set \( D(\obj(\cat{I})) \). The relation induced by \( D \) does not matter here.

  Indeed, the cone \( (x, R) \) in \( \cat{P} \) consists of morphisms with domain \( x \). That is, \( R \) is a subrelation of \( \leq \) whose first component is \( x \). Clearly then \( x \) is a lower bound of the set \( D(\obj(\cat{I})) \).

  For the limiting cone \( (y, S) \), it holds that \( x \leq y \) for every other cone \( (x, R) \). Both \( R \) and \( S \) are subrelations of \( \leq \) with the same second components. Thus, \( y \) is the greatest lower bound of \( D(\obj(\cat{I})) \).

  \hyperref[thm:categorical_principle_of_duality]{Dually}, cocones are upper bounds and colimits are suprema.

  As mentioned, the relation induced by the diagram \( D \) does not actually matter. Therefore, we may choose, without loss of generality, \( D \) to be a \hyperref[def:discrete_category]{discrete category}. It then follows that infima and suprema correspond to \hyperref[def:discrete_category_limits]{products} and \hyperref[def:discrete_category_limits]{coproduct}, however what we have shown here is more general.
\end{example}

\begin{definition}\label{def:direct_and_inverse_limits}
  We will define limits and colimits of diagrams over infinite \hyperref[def:partially_ordered_set_chain_and_antichain]{chains} of integers. These notions predate limits and colimits, which explains why their names may seem inconsistent with other limits and colimits.

  \begin{thmenum}
    \thmitem{def:direct_and_inverse_limits/direct}\mcite[exmpl. 5.2.15]{Leinster2016Basic} Consider the category \hyperref[thm:order_category_isomorphism]{induced} by the positive integers
    \begin{equation}\label{eq:def:direct_and_inverse_limits/direct}
      \begin{aligned}
        \includegraphics[page=1]{output/def__direct_and_inverse_limits.pdf}
      \end{aligned}
    \end{equation}

    A \hyperref[def:category_of_cones/colimit]{colimit} over a diagram of this shape is called a \term{direct limit}. In this context, the diagram itself is sometimes called a \term{direct system}.

    \thmitem{def:direct_and_inverse_limits/inverse}\mcite[exmpl. 5.1.21(d)]{Leinster2016Basic} Now consider the opposite category
    \begin{equation}\label{eq:def:direct_and_inverse_limits/inverse}
      \begin{aligned}
        \includegraphics[page=2]{output/def__direct_and_inverse_limits.pdf}
      \end{aligned}
    \end{equation}

    Somewhat confusingly, a \hyperref[def:category_of_cones/limit]{limit} of a diagram of this shape is called an \term{inverse limit}. In this context, the diagram itself is sometimes called an \term{inverse system}.
  \end{thmenum}
\end{definition}

\begin{example}\label{ex:def:direct_and_inverse_limits}
  We will list several examples of \hyperref[def:direct_and_inverse_limits/direct]{direct} and \hyperref[def:direct_and_inverse_limits/inverse]{inverse} limits.

  \begin{thmenum}
    \thmitem{ex:def:direct_and_inverse_limits/vector_space_direct} Consider the chain of \hyperref[def:module_of_tuples]{tuple vector spaces}
    \begin{equation}\label{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/ex__def__direct_and_inverse_limits.pdf}
      \end{aligned}
    \end{equation}
    where \( \iota_n^m: \BbbK^n \to \BbbK^m \) is simply the canonical inclusion map.

    Let \( \BbbK_0^\infty \) be the vector space of all sequences in \( \BbbK \) with only finitely many nonzero elements. For each positive integer \( n \), denote by \( \iota_n^\infty: \BbbK^n \to \BbbK_0^\infty \) the canonical inclusion.

    Then \( (\BbbK_0^\infty, \iota) \) is a \hyperref[def:category_of_cones/cocone]{cocone} of \eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}. We will show that it is a colimit cocone, i.e. that \( \BbbK_0^\infty \) is a \hyperref[def:direct_and_inverse_limits]{direct limit} of \eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}.

    Let \( (A, \alpha) \) be another cocone. We want to define a linear map \( l_A: \BbbK_0^\infty \to A \) so that the following diagram commutes:
    \begin{equation}\label{eq:ex:def:direct_and_inverse_limits/vector_space_direct/limit}
      \begin{aligned}
        \includegraphics[page=2]{output/ex__def__direct_and_inverse_limits.pdf}
      \end{aligned}
    \end{equation}

    For every vector \( x \in \BbbK^m \), we must have
    \begin{equation*}
      \alpha_n(x) = l_A(\iota_n^\infty(x)).
    \end{equation*}

    This implies the obvious definition where, given a vector \( x \in \BbbK_0^\infty \) whose greatest nonzero element has index \( m \), we define
    \begin{equation*}
      l_A(x) \coloneqq \alpha_m(x).
    \end{equation*}

    This map is well-defined because the compatibility with inclusion maps guarantees that \( \alpha_{m+1}(x) = \iota_{m+1}(\alpha^{m+1}_m(x)) \), i.e. the result obtained by using \( \alpha_m \) and \( \alpha_{m+1} \) is the same.

    Therefore, \( (\BbbK_0^\infty, \iota) \) is a direct limit of the diagram \eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}.

    \thmitem{ex:def:direct_and_inverse_limits/vector_space_inverse} \hyperref[thm:categorical_principle_of_duality]{Dually}, consider the chain
    \begin{equation}\label{eq:ex:def:direct_and_inverse_limits/vector_space_inverse/diagram}
      \begin{aligned}
        \includegraphics[page=3]{output/ex__def__direct_and_inverse_limits.pdf}
      \end{aligned}
    \end{equation}
    where
    \begin{equation*}
      \begin{aligned}
        &\pi_n^m: \BbbK^m \to \BbbK^n \\
        &\pi_n^m(x_1, \ldots, x_n, x_{k+1}, \ldots, x_m) \coloneqq (x_1, \ldots, x_n).
      \end{aligned}
    \end{equation*}

    Let \( \BbbK^\infty \) be the vector space of all sequences in \( \BbbK \) and, for each positive integer \( n \), define \( \pi_n^\infty \) as a truncation in the obvious way.

    Then \( (\BbbK^\infty, \pi^\infty) \) is a \hyperref[def:category_of_cones/cone]{cone} of \eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}. We will show that it is a limit cone, i.e. that \( \BbbK^\infty \) is a \hyperref[def:direct_and_inverse_limits]{direct limit} of \eqref{eq:ex:def:direct_and_inverse_limits/vector_space_direct/diagram}.

    Let \( (A, \alpha) \) be another cone. We want to define \( l_A: A \to \BbbK^\infty \) so that the following diagram commutes:
    \begin{equation}\label{eq:ex:def:direct_and_inverse_limits/vector_space_inverse/limit}
      \begin{aligned}
        \includegraphics[page=4]{output/ex__def__direct_and_inverse_limits.pdf}
      \end{aligned}
    \end{equation}

    For every \( a \in A \), we must have
    \begin{equation*}
      \alpha_n(a) = \pi_n^\infty(l_A(a)),
    \end{equation*}
    which implies the obvious definition where the \( n \)-th coordinate of the vector \( l_A(a) \) is
    \begin{equation*}
      [l_A(a)]_n \coloneqq [\alpha_n(a)]_n.
    \end{equation*}

    That is, \( l_A(a) \) is a sequence whose \( n \)-th coordinate is the \( n \)-th coordinate \( \alpha_n(a) \). This is well-defined because, for \( m > n \), we have
    \begin{equation*}
      \pi_m^n \bincirc \alpha_m = \alpha_n.
    \end{equation*}

    \thmitem{ex:def:direct_and_inverse_limits/generalized_intersection} In \hyperref[def:concrete_category]{concrete categories}, \hyperref[def:direct_and_inverse_limits/inverse]{inverse limits} are generalizations of \hyperref[thm:zfc_existence_theorems/arbitrary_intersection]{set intersections}.

    As an example, consider the chain of sets
    \begin{equation}\label{eq:ex:inverse_limit_as_intersection/diagram}
      \begin{aligned}
        \includegraphics[page=5]{output/ex__def__direct_and_inverse_limits.pdf}
      \end{aligned}
    \end{equation}
    where \( A_{k+1} \subseteq A_k \) for every positive integer \( k \) and \( \iota_k^m: A_m \to A_k \) is simply the canonical inclusion map.

    Then the intersection \( \bigcap_{k=1}^\infty A_k \) along with its inclusion maps is a limit of \eqref{eq:ex:inverse_limit_as_intersection/diagram}. This is a consequence of the discussion in \fullref{ex:limits_of_partially_ordered_set}.

    We can replace the inclusion maps \( \iota_k^m \) with other injective functions, or even non-injective functions. In this case, we would obtain a \enquote{generalized intersection}.
  \end{thmenum}
\end{example}

\begin{definition}\label{def:discrete_category_limits}
  Fix an arbitrary category \( \cat{C} \). A \term{product} in \( \cat{C} \) is a \hyperref[def:category_of_cones/limit]{limit} over a diagram \( D: \cat{I} \to \cat{C} \), whose domain \( \cat{I} \) is a \hyperref[def:discrete_category]{discrete category}. \hyperref[thm:categorical_principle_of_duality]{Dually}, a \term{coproduct} or \term{sum} in \( \cat{C} \) is a colimit of \( D \).

  It will be convenient for us to speak about the product of an \hyperref[def:cartesian_product/indexed_family]{indexed family} \( \seq{ X_k }_{k \in \mscrK} \) of objects in \( \cat{C} \).

  \begin{minipage}[t]{0.47\textwidth}
    A cone with vertex \( A \) consists of morphisms with signatures
    \begin{equation*}
      \alpha = \seq{ \alpha_k: A \to X_k }.
    \end{equation*}
  \end{minipage}
  \hfill
  \begin{minipage}[t]{0.47\textwidth}
    A cocone with vertex \( A \) consists of morphisms with signatures
    \begin{equation*}
      \alpha = \seq{ \alpha_k: X_k \to A }.
    \end{equation*}
  \end{minipage}

  \begin{minipage}[t]{0.47\textwidth}
    A product \hyperref[def:category_of_cones/cone]{cone} \( (\prod_{k \in \mscrK} X_k, \pi) \) satisfies the following \hyperref[rem:limit_universal_mapping_property]{universal mapping property}:
    \begin{displayquote}
      For every cone \( (A, \alpha) \), there exists a unique morphism
      \begin{equation*}
        l_A: A \to \prod_{k \in \mscrK} X_k,
      \end{equation*}
      such that the following diagram commutes:
    \end{displayquote}
    \begin{equation}\label{eq:def:discrete_category_limits/product}
      \begin{aligned}
        \includegraphics[page=1]{output/def__discrete_category_limits.pdf}
      \end{aligned}
    \end{equation}
  \end{minipage}
  \hfill
  \begin{minipage}[t]{0.47\textwidth}
    A coproduct \hyperref[def:category_of_cones/cocone]{cocone} \( (\coprod_{k \in \mscrK} X_k, \iota) \) satisfies the following \hyperref[rem:limit_universal_mapping_property]{universal mapping property}:
    \begin{displayquote}
      For every cone \( (A, \alpha) \), there exists a unique morphism
      \begin{equation*}
        l_A: A \to \coprod_{k \in \mscrK} X_k,
      \end{equation*}
      such that the following diagram commutes:
    \end{displayquote}
    \begin{equation}\label{eq:def:discrete_category_limits/coproduct}
      \begin{aligned}
        \includegraphics[page=3]{output/def__discrete_category_limits.pdf}
      \end{aligned}
    \end{equation}
  \end{minipage}

  \begin{minipage}[t]{0.47\textwidth}
    We call the morphism \( \pi_k \) the \term{canonical projection} of the product onto \( X_k \), even though it may not be a surjective function.
  \end{minipage}
  \hfill
  \begin{minipage}[t]{0.47\textwidth}
    We call the morphism \( \iota_k \) the \term{canonical inclusion} of \( X_k \) into the coproduct, even though it may not be an injective function.
  \end{minipage}
  \medskip

  From \fullref{thm:limits_of_empty_diagram} it follows that the product (resp. coproduct) of an empty family is a terminal (resp. initial) object of \( \cat{C} \).

  As in the case of general limits, we call \( \prod_{k \in \mscrK} X_k \) \hi{the} product of the family \( X \).

  In the case of only two objects, their product is given by the following diagram:
  \begin{equation}\label{eq:def:discrete_category_limits/product/binary}
    \begin{aligned}
      \includegraphics[page=2]{output/def__discrete_category_limits.pdf}
    \end{aligned}
  \end{equation}
  and their coproduct by
  \begin{equation}\label{eq:def:discrete_category_limits/coproduct/binary}
    \begin{aligned}
      \includegraphics[page=4]{output/def__discrete_category_limits.pdf}
    \end{aligned}
  \end{equation}
\end{definition}

\begin{proposition}\label{thm:discrete_category_limits_in_set}
  The \hyperref[def:discrete_category_limits]{product} in the category \hyperref[def:category_of_small_sets]{\( \ucat{Set} \)} of \( \mscrU \)-small sets of a family \( \mscrA = \seq{ A_k }_{k \in \mscrK} \) is their \hyperref[def:cartesian_product/product]{Cartesian product} \( \prod_{k \in \mscrK} A_k \) and the \hyperref[def:discrete_category_limits]{coproduct} is their \hyperref[def:disjoint_union]{disjoint union} \( \coprod_{k \in \mscrK} A_k \).
\end{proposition}
\begin{proof}
  \SubProof{Proof for products} Consider the Cartesian product
  \begin{equation*}
    L \coloneqq \prod_{k \in \mscrK} A_k = \set*{ f: A \to \bigcup_{k \in \mscrK} A_k \given* \qforall {k \in \mscrK} k \in A_k }.
  \end{equation*}

  Since \( \mscrU \) is a model of \logic{ZFC} (with or without the axiom of infinity), hence the product is an object of \( \ucat{Set} \). Define the projection morphisms
  \begin{equation*}
    \pi_k(f) \coloneqq f(k).
  \end{equation*}

  Then \( (L, \pi) \) is a cone for (some diagram forming) \( \mscrA \). Let \( (B, \beta) \) also be a cone and consider the following diagram:
  \begin{equation}\label{eq:thm:discrete_category_limits_in_set/limit}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__discrete_category_limits_in_set.pdf}
    \end{aligned}
  \end{equation}

  We want to define a function \( l_B: B \to L \) such that
  \begin{equation*}
    \underbrace{ \pi_k(l_B(b)) }_{[l_B(b)](k)} = \beta_k(b)
  \end{equation*}
  for every \( b \in B \) and \( k \in \mscrK \). This is uniquely determined by \( b \) and \( k \), hence
  \begin{equation*}
    l_B(b) \coloneqq \seq{ \beta_k(b) }_{k \in \mscrK}.
  \end{equation*}

  The cone \( (B, \beta) \) was chosen randomly, and we showed that there exists a unique morphism \( l_B: B \to L \) such that \eqref{eq:thm:discrete_category_limits_in_set/limit} commutes. Therefore, \( (L, \pi) \) is a categorical product of the family \( \mscrA \).

  \SubProof{Proof for coproducts} Now consider the disjoint union
  \begin{equation*}
    L \coloneqq \coprod_{k \in \mscrK} A_k = \set{ (k, a) \given k \in \mscrK \T{and} a \in A_k }
  \end{equation*}
  and the inclusions
  \begin{equation*}
    \iota_k\parens[\Big]{ (k, a) } = a.
  \end{equation*}

  We must show that, for any other cocone \( (B, \beta) \), the following diagram commutes:
  \begin{equation}\label{eq:thm:discrete_category_limits_in_set/colimit}
    \begin{aligned}
      \includegraphics[page=2]{output/thm__discrete_category_limits_in_set.pdf}
    \end{aligned}
  \end{equation}

  Analogously to products, the condition
  \begin{equation*}
    \underbrace{ l_B(\iota_k(a)) }_{l_B(k, a)} = \beta_k(a)
  \end{equation*}
  for every \( b \in B \) and \( k \in \mscrK \) uniquely identifies the function
  \begin{equation*}
    l_B(k, a) \coloneqq \beta_k(a).
  \end{equation*}
\end{proof}

\begin{definition}\label{def:equalizers}\mcite[def. 5.1.11]{Leinster2016Basic}
  Consider the index category
  \begin{equation}\label{eq:def:equalizers/index}
    \begin{aligned}
      \includegraphics[page=1]{output/def__equalizers.pdf}
    \end{aligned}
  \end{equation}

  A diagram indexed by \eqref{eq:def:equalizers/index} is sometimes called a \term{fork}. A \hyperref[def:category_of_cones/limit]{limit} of a fork is called an \term{equalizer} and a \hyperref[def:category_of_cones/colimit]{colimit} --- a \term{coequalizer}.

  Note that in \fullref{def:categorical_diagram} we defined commutativity only when at least one path is nontrivial. That is, \eqref{eq:def:equalizers/index} cannot commute by definition since all of its paths have length either \( 0 \) or \( 1 \).

  We will describe equalizers in more detail. Fix a fork in \( \cat{C} \) which we will denote by
  \begin{equation}\label{eq:def:equalizers/raw_diagram}
    \begin{aligned}
      \includegraphics[page=2]{output/def__equalizers.pdf}
    \end{aligned}
  \end{equation}

  \begin{minipage}[t]{0.47\textwidth}
    A \hyperref[def:category_of_cones/cone]{cone} with vertex \( A \) over this diagram has a single morphism \( f: A \to X \) such that the following diagram commutes:
    \begin{equation}\label{eq:def:equalizers/cone}
      \begin{aligned}
        \includegraphics[page=3]{output/def__equalizers.pdf}
      \end{aligned}
    \end{equation}

    This is equivalent to requiring
    \begin{equation*}
      s \bincirc f = t \bincirc f.
    \end{equation*}

    An equalizer limit cone \( (L, \iota) \) satisfies the following \hyperref[rem:limit_universal_mapping_property]{universal mapping property}:
    \begin{displayquote}
      For every cone \( (A, f) \), \( f \) \hyperref[def:factors_through]{uniquely factors through} \( L \). That is, there exists a unique morphism
      \begin{equation*}
         l_A: A \to L
      \end{equation*}
      such that the following diagram commutes:
    \end{displayquote}
    \begin{equation}\label{eq:def:equalizers/equalizer}
      \begin{aligned}
        \includegraphics[page=4]{output/def__equalizers.pdf}
      \end{aligned}
    \end{equation}
  \end{minipage}
  \hfill
  \begin{minipage}[t]{0.47\textwidth}
    A \hyperref[def:category_of_cones/cocone]{cocone} with vertex \( A \) over this diagram has a single morphism \( f: Y \to A \) such that the following diagram commutes:
    \begin{equation}\label{eq:def:equalizers/cocone}
      \begin{aligned}
        \includegraphics[page=5]{output/def__equalizers.pdf}
      \end{aligned}
    \end{equation}

    This is equivalent to requiring
    \begin{equation*}
      f \bincirc s = f \bincirc t.
    \end{equation*}

    A coequalizer cocone \( (L, \pi) \) satisfies the following \hyperref[rem:limit_universal_mapping_property]{universal mapping property}:
    \begin{displayquote}
      For every cocone \( (A, f) \), \( f \) \hyperref[def:factors_through]{uniquely factors through} \( L \). That is, there exists a unique morphism
      \begin{equation*}
        l_A: L \to A
      \end{equation*}
      such that the following diagram commutes:
    \end{displayquote}
    \begin{equation}\label{eq:def:equalizers/coequalizer}
      \begin{aligned}
        \includegraphics[page=6]{output/def__equalizers.pdf}
      \end{aligned}
    \end{equation}
  \end{minipage}

  The requirement that \eqref{eq:def:equalizers/equalizer} commutes does not mean that \( p = q \). As discussed in \fullref{def:categorical_diagram}, for commutative diagrams, we only consider a pair of paths if at least one of them is nontrivial. We made this requirement in order to allow parallel morphisms.

  Note how we interchanged the notation for the projections and inclusions compared to \fullref{def:discrete_category_limits} --- \( (L, \iota) \) is a \hi{limit} of a fork, while \( (L, \pi) \) is a \hi{colimit}. The reason for this is that equalizers are usually canonical inclusions, while coequalizers are projections.
\end{definition}

\begin{proposition}\label{thm:equalizer_invertibility}
  If \( (L, \iota) \) is an \hyperref[def:equalizers]{equalizer} in the category \( \cat{C} \), then \( \iota \) is a \hyperref[def:morphism_invertibility/left_cancellative]{monomorphism}.

  \hyperref[thm:categorical_principle_of_duality]{Dually}, if \( (L, \pi) \) is a \hyperref[def:equalizers]{coequalizer}, then \( \pi \) is an \hyperref[def:morphism_invertibility/right_cancellative]{epimorphism}.
\end{proposition}
\begin{proof}
  Fix an equalizer cone \( (L, \iota) \) of the fork \eqref{eq:def:equalizers/raw_diagram}. Fix any object \( A \) in \( \cat{C} \) and any two parallel morphisms \( a_1, a_2: A \to X \) such that
  \begin{equation*}
    \iota \bincirc a_1 = \iota \bincirc a_2.
  \end{equation*}

  Then
  \begin{equation*}
    g \bincirc \iota \bincirc a_1 = h \bincirc \iota \bincirc a_2,
  \end{equation*}
  and thus \( \iota \bincirc a_1 = \iota \bincirc a_2 \) is the morphism of a cone. Hence, both \( (A, \iota \bincirc a_1) \) and \( (A, \iota \bincirc a_2) \) are cones and thus \( a_1 \) and \( a_2 \) are the unique maps such that the following diagram commutes:
  \begin{equation}\label{eq:thm:equalizer_invertibility/monomorphism}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__equalizer_invertibility.pdf}
    \end{aligned}
  \end{equation}

  Therefore, \( a_1 = a_2 \) and, since \( a_1 \) and \( a_2 \) were arbitrary, it follows that \( \iota \) is a monomorphism.

  Dually, if \( (L, \pi) \) is a coequalizer colimit cocone in \( \cat{C} \), then by \fullref{thm:categorical_limit_duality}, \( (L, \pi^{\opcat}) \) is an equalizer in \( \cat{C}^{\opcat} \). Hence, \( \pi^{\opcat} \) is a monomorphism, and by \fullref{thm:morphism_invertibility_duality}, \( \pi \) is an epimorphism.
\end{proof}

\begin{example}\label{ex:equalizers_in_set}
  \hfill
  \begin{thmenum}
    \thmitem{ex:equalizers_in_set/equalizer} For a pair of functions \( s, t: X \to Y \) in \( \cat{Set} \), define the set
    \begin{equation*}
      E = \set{ x \in X \given s(x) = t(x) }.
    \end{equation*}

    With the inclusion map \( \iota: E \to X \), this is an \hyperref[def:equalizers]{equalizer} cone for \( s \) and \( t \).

    We will now prove that it is a limit cone. The pair \( (E, \iota) \) is obviously a cone. For any other cone \( (A, f) \), we must find a map \( l_A: A \to E \) such that the following equalizer diagram commutes:
    \begin{equation}\label{eq:ex:equalizers_in_set/equalizer}
      \begin{aligned}
        \includegraphics[page=1]{output/ex__equalizers_in_set.pdf}
      \end{aligned}
    \end{equation}

    In order for \( (A, f) \) to be a cone, the image \( f[A] \) must be a subset of \( E \). In order for \eqref{eq:ex:equalizers_in_set/equalizer} to commute, it only makes sense to take \( l_A \) to be \( f \) with its codomain restricted to \( E \).

    It follows that \( (E, \iota) \) is a limit cone.

    \thmitem{ex:equalizers_in_set/coequalizer} The coequalizer of \( s, t: X \to Y \) is more nuanced. Suppose that \( (L, \pi) \) is a colimit cocone and \( (A, f) \) is any cocone for the coequalizer diagram
    \begin{equation}\label{eq:ex:equalizers_in_set/coequalizer}
      \begin{aligned}
        \includegraphics[page=2]{output/ex__equalizers_in_set.pdf}
      \end{aligned}
    \end{equation}

    In order for \( (A, f) \) to be a cocone, for every \( x \in X \), we must have \( f(s(x)) = f(t(x)) \). Thus, \( A \) must be a partition of \( Y \) in a way such that \( s(x) \) and \( t(x) \) belong to the same coset if and only if \( f(s(x)) = f(t(x)) \). Outside the images of \( s \) and \( t \), \( f \) is free to take any value.

    Let \( {\sim} \) be the smallest equivalence relation on \( Y \) such that \( s(x) \sim t(x) \) for every \( x \in X \). Explicitly, this is the \hyperref[thm:equivalence_closure]{equivalence closure} of the relation
    \begin{equation*}
      \set{ (s(x), t(x)) \given x \in X }.
    \end{equation*}

    Consider the partition \( Y / {\sim} \) with the projection map
    \begin{equation*}
      \begin{aligned}
        &\pi: Y \to Y / {\sim} \\
        &\pi(y) \coloneqq [y]
      \end{aligned}
    \end{equation*}

    This is a cocone. Furthermore, it is a colimit cocone because, for any other cocone \( (A, f) \), we can define \( l_A([y]) \coloneqq f(y) \) so that \eqref{eq:ex:equalizers_in_set/coequalizer} commutes.

    Coequalizers mostly make sense in the context of \hyperref[def:group/quotient]{quotient groups}, where partitions are especially well-behaved and admit a much simpler description. See \fullref{def:group/quotient}.
  \end{thmenum}
\end{example}


\section{Subset of Supported Operations}

\setlongtables
\begin{longtable}{| p{4.8in} |}
%\hline
\endhead
%\hline
\endfoot
%
%
\hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Negate( PLA_Obj A )
\end{verbatim}
\end{minipage}
\purpose{$ A \becomes - A $.}
\parameter{\tt A}{descriptor of data to be updated}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Obj_set_diagonal( PLA_Obj sigma, PLA_Obj A )
\end{verbatim}
\end{minipage}
\purpose{
Set the diagonal of $ A $ to $ \sigma I $.
All other values in $ A $ are unaffected.
}
\parameter{\tt sigma, A}{descriptor for $ \sigma $ and $ A $}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Shift_diagonal( PLA_Obj sigma, PLA_Obj A )
\end{verbatim}
\end{minipage}
\purpose{
$ A \becomes A + \sigma I $.
}
\parameter{\tt sigma, A}{descriptor for $ \sigma $ and $ A $}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Symmetrize( PLA_Uplo uplo, PLA_Conj conj, PLA_Obj A )
\end{verbatim}
\end{minipage}
\purpose{
$ A \becomes \mbox{symm}(A) $ or
$ A \becomes \mbox{herm}(A) $,
where {\tt uplo} indicates whether
$ A $ is originally stored only in the upper or
lower triangular part of {\tt A}.
}
\parameter{\tt uplo}{
indicates where $ A$ is stored.
}
\parameter{\tt conj}{
indicates whether to create a symmetric or hermitian matrix.
}
\parameter{\tt A}{
descriptor for matrix $ A $.
}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Triangularize( PLA_Uplo uplo, PLA_Diag diag, PLA_Obj A )
\end{verbatim}
\end{minipage}
\purpose{
$ A \becomes \mbox{lower}(A) $ or
$ A \becomes \mbox{upper}(A) $.
}
\parameter{\tt uplo}{
indicates whether whether $ A$ should be upper of
lower triangular.
}
\parameter{\tt diag}{
indicates whether set diagonal to zero or one.
}
\parameter{\tt A}{
descriptor for matrix $ A $.
}
% \\ \hline \hline
% \begin{minipage}{4.8in}
% \footnotesize
% \begin{verbatim}
% PLA_LU( PLA_Obj A, PLA_Obj ipiv )
% \end{verbatim}
% \end{minipage}
% \purpose{Compute the
% LU factorization with partial pivoting of
% matrix $ A $, overwriting $ A $ with factors
% $ L $ and $ U $.  The pivot matrix $ P $ is
% stored as a vector of indices, in {\tt ipiv}.
% }
% \parameter{\tt A}{descriptor for $ A $}
% \parameter{\tt ipiv}{descriptor for vector in which $ P $ is
% stored}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Nrm1( PLA_Obj A, PLA_Obj alpha )
\end{verbatim}
\end{minipage}
\purpose{$ \alpha \becomes \| A \|_1 $.
}
\parameter{\tt A, alpha}{descriptor for $ A $ and $ \alpha $}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Nrm_inf( PLA_Obj A, PLA_Obj alpha )
\end{verbatim}
\end{minipage}
\purpose{
$ \alpha \becomes \| A \|_\infty $.
}
\parameter{\tt A, alpha}{descriptor for $ A $ and $ \alpha $}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Scal_x( PLA_Uplo uplo, PLA_Obj alpha, PLA_Obj A )
\end{verbatim}
\end{minipage}
\purpose{
$ A \becomes \alpha A $
where {\tt uplo} indicates whether $ A $ is stored in the upper
or lower triangular part of {\tt A}.
}
\parameter{\tt alpha, A}{descriptor for $ \alpha $ and $ A $}
\\ \hline \hline
\begin{minipage}{4.8in}
\footnotesize
\begin{verbatim}
PLA_Swap_x( PLA_Trans trans, PLA_Obj A, PLA_Obj B )
\end{verbatim}
\end{minipage}
\purpose{
$ A, B \becomes \op_{trans}(A), \op_{trans}(B) $.
}
\parameter{\tt trans}{indicates whether to transpose and/or conjugate the data}
\parameter{\tt A, B}{descriptors for $ A $ and $ B $}
\\ \hline
\end{longtable}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}

\title{\LaTeX{} Maths examples}
\author{Becky Nisbet}
\date{January 2021}

\begin{document}

\maketitle

\section{Symbols}
Infinity: $\infty$\\
Double bold maths (like real numbers): $\mathbb{R}, \mathbb{C}, \mathbb{N}$ \\ %needs package amssymb
Set notation: $\in, \notin, \ni, \subset, \subseteq, \supset, \supseteq, \cup, \cap \varnothing$\\
Logic symbols: $\forall, \exists, \rightarrow, \Rightarrow, \equiv \iff, \leftrightarrow, \neg, \sim$

\section{Calculus}
Derivatives:\\
$\frac{dy}{dx} =x^2+3\\
\frac{d}{dx}y=x^2+3\\
\frac{\partial y}{\partial x}=xy+1\\
\frac{\partial}{\partial x}[xy]=y$\\
Integrals:\\
$\int x = \frac{x^2}{2}+c\\
\int_0^2 x = 2$

\section{Vectors and linear algebra}
A matrix;\\
$M = \left( %this has to go before the begin array if you want the brackets
\begin{array}{cc}

    1 & 0 \\
    0 & 1
\end{array}
\right)$\\
A vector;\\
$\vec{v}=\left(
\begin{array}{c}
    a \\
    b
\end{array}
\right)$ \\%note how similar this is to constructing tables!
Determinants;\\
$\det{A} =
\left|
\begin{array}{cc}
    a & b \\
    c & d
\end{array}
\right|$

\end{document}


Optimization problems can appear in almost all situations on life, but there are special important cases where those problems appears, specially on the industry, since if we can achieve an optimal solution, we will improve the efficiency of the industrial process and then get lower production cost with the same (or better) efficiency. This improvement of the costs have an effect on the competitiveness of the companies and on the final quality of their products, including that this is an important money-saving factor.

   The challenging part is when this kind of problems become really big, since then they have a attached really high computational complexity and cost, therefore we need some methods to face them.

   To do so, we have two approaches, the always-optimal methods that obtain the optimal solution but taking into account every possible combination of the problems' solutions, as for instance Integer Linear Programming does. By the other hand we have those methods that concerns about fair execution times and are looking for a trade-off between acceptable execution times and the quality of the solution.

   In this work we propose two approaches in order to solve the scheduling of nurses in a hospital taking into account several constraints. The first one is using Integer Linear Programming and the second one by using metaheuristics. In the metaheuristics part we are focusing specifically in the Greedy Randomized Adaptative Procedure (GRASP) and the Biased-Random Key Genetic Algorithm (BRKGA).

   Firstly we compare the efficiency in terms of solving time and wellness of ILP and metaheuristics over medium-sized problems.

   Lastly, since large problems are intractable for ILP due to combinatorial explosion reasons, we compare the metaheuristics among them to compare such kind of problems.

   \subsection{Problem Statement}

   A public hospital needs to design the working schedule of their nurses. As a first approximation, we are asked to help in designing the schedule of a single day. We know, for each hour h, that at least demandh nurses should be working at the hospital. We have available a set of nNurses nurses and we need to determine at which hours each nurse should be working. However, there are some limitations that should be taken into account:

   \begin{itemize}
   \item Each nurse should work at least minHours hours.
   \item Each nurse should work at most maxHours hours.
   \item Each nurse should work at most maxConsec consecutive hours.
   \item No nurse can stay at the hospital for more than maxPresence hours (e.g. if maxPresence is 7, it is OK that a nurse works at 2am and also at 8am, but it not possible that he/she works at 2am and also at 9am).
   \item No nurse can rest for more than one consecutive hour (e.g. working at 8am, resting at 9am and 10am, and working again at 11am is not allowed, since there are two consecutive resting hours).
   \end{itemize}

The goal of this project is to determine at which hours each nurse should be working in order to minimize the number of nurses required and satisfy all the aforementioned constraints.

\subsection{Document Structure}

The structure of this document is the following: The problem definition is done in chapter 2. Here it is explained the problem that is faced, which constraints is needed to take into account and what we want to optimize. At chapter 3 is explained the ILP model that has been developed, i.e. the decision variables and also the constraints with a mathematical nomenclature. After this chapter, at chapter 4 is explained how it has been used the heuristics approach in order to face with the problem, two meta-heuristics has been used: GRASP3 and BRKGA4 . After perform several executions for those approaches, a comparison in terms of time and quality of the result is done at chapter 5. Finally conclusions of the project are explained at chapter 6.

\pagebreak


\section{Algebraic view of systems of equations}

\begin{outcome}
  \begin{enumerate}
  \item Recognize the difference between a linear equation and a
    non-linear equation.
  \item Determine whether a tuple of real numbers is a solution for a
    system of linear equations.
  \item Understand what it means for a system of linear equations to
    be consistent or inconsistent.
  \end{enumerate}
\end{outcome}

We have taken an in-depth look at graphical representations of systems
of equations, as well as how to find possible solutions
graphically. Our attention now turns to working with systems
algebraically.

\begin{definition}{Linear equation}{linear-equation}
  A \textbf{linear equation}%
  \index{linear equation} is an equation of the form
  \begin{equation*}
    a_1x_1 + a_2x_2 + \ldots + a_nx_n = b.
  \end{equation*}
  Here, $a_1,\ldots,a_n$ are real numbers called the
  \textbf{coefficients}%
  \index{coefficient} of the equation, $b$ is a real number called the
  \textbf{constant term}%
  \index{constant term} of the equation, and $x_1,\ldots,x_n$ are
  \textbf{variables}%
  \index{variable}.
\end{definition}

Real numbers, such as the coefficients $a_1,\ldots,a_n$, the constant
term $b$, or the values of the variables $x_1,\ldots,x_n$, will also
be called \textbf{scalars}%
\index{scalar}. For now, the word ``scalar'' is just a synonym for
``real number''. Later, in Section~\ref{sec:fields}, we will discover
other kinds of scalars.

\begin{example}{Linear vs. non-linear equation}{linear-vs-non-linear}
  Which of the following equations are linear?
  \begin{equation*}
    \begin{array}{c}
      2x+3y=5 \\
      2x^2+3y=5 \\
      2\sqrt{x} + 3y = 5 \\
      (\sqrt{2}) x + 3y = 5^2
    \end{array}
  \end{equation*}
\end{example}

\begin{solution}
  The equation $2x+3y=5$ is linear. The equation $2x^2+3y=5$ is not
  linear, because it contains the square of a variable instead of a
  variable.  The equation $2\sqrt{x} + 3y = 5$ is also not linear,
  because the square root is applied to one of the variables. On the
  other hand, the equation $(\sqrt{2}) x + 3y = 5^2$ is linear,
  because $\sqrt{2}$ and $5^2$ are real numbers, and can
  therefore be used as coefficients and constant terms.
\end{solution}

We also permit minor notational variants of linear equations. The
equation $2x-3y=5$ is linear although
Definition~\ref{def:linear-equation} does not mention subtraction,
because it can be regarded as just another notation for
$2x+(-3)y = 5$. Similarly, the equation $2x=5+3y$ can be regarded as
linear, because it can be easily rewritten as $2x-3y=5$ by bringing
all the variables (and their coefficients) to the left-hand side.
When we need to emphasize that some linear equation is literally of
the form $a_1x_1 + a_2x_2 + \ldots + a_nx_n = b$, we say that the
equation is in \textbf{standard form}%
\index{linear equation!standard form}%
\index{standard form!of a linear equation}. Thus, the standard form of
the equation $2x=5+3y$ is $2x+(-3)y=5$.

A \textbf{solution}%
\index{linear equation!solution} to a linear equation is an assignment
of real numbers to the variables, making the equation true. More
precisely, if $r_1,\ldots,r_n$ are real numbers, the assignment
$x_1=r_1$, \ldots, $x_n=r_n$ is a solution to the equation in
Definition~\ref{def:linear-equation} if the real number
$a_1r_1 + a_2r_2 + \ldots + a_nr_n$ is equal to the real number
$b$. To save space, we often write solutions in \textbf{tuple
  notation}%
\index{tuple}\footnote{The terminology ``tuple'' arose as follows. A
  collection of two items is called a ``pair'', a collection of three
  items is called a ``triple'', followed by ``quadruple'',
  ``quintuple'', ``sextuple'', and so on. You have to know Latin to
  know what the next ones are called. To avoid these Latin terms,
  mathematicians started saying $4$-tuple, $5$-tuple, $6$-tuple and so
  on, and more generally, $n$-tuple for an ordered collection of $n$
  items. When $n$ doesn't matter or is clear from the context, we
  often just say ``tuple''.}  as
$(x_1,\ldots,x_n) = (r_1,\ldots,r_n)$. When there is no doubt about
the order of the variables, we also often simply write the solution as
$(r_1,\ldots,r_n)$.

\begin{example}{Solutions of a linear equation}{linear-equation-solutions}
  Consider the linear equation $2x+3y-4z=5$. Which of the following
  are solutions? (a) $(x,y,z)=(1,1,0)$, (b) $(x,y,z)=(0,3,1)$, (c)
  $(x,y,z)=(1,1,1)$.
\end{example}

\begin{solution}
  The assignment $(x,y,z) = (1,1,0)$ is a solution because
  $2(1)+3(1)-4(0) = 5$. The assignment $(x,y,z) = (0,3,1)$ is also a
  solution, because $2(0) + 3(3) - 4(1) = 5$. On the other hand,
  $(x,y,z) = (1,1,1)$ is not a solution, because
  $2(1) + 3(1)-4(1) = 1 \neq 5$.
\end{solution}

A system of linear equations is just several linear equations taken
together.

\begin{definition}{System of linear equations}{system-of-linear-equations}
  A \textbf{system of linear equations}%
  \index{system of linear equations} is a list of equations
  \begin{equation*}
    \begin{array}{c@{~}c@{~}c}
      a_{11}x_1+a_{12}x_2+\ldots+a_{1n}x_n&=&b_1 \\
      a_{21}x_1+a_{22}x_2+\ldots+a_{2n}x_n&=&b_2 \\
      \vdots \\
      a_{m1}x_1+a_{m2}x_2+\ldots+a_{mn}x_n&=&b_m,
    \end{array}
  \end{equation*}
  where $a_{ij}$ and $b_i$ are scalars (i.e., real numbers). The above
  is a system of $m$ equations in the $n$ variables,
  $x_1,x_2\ldots,x_n$.  As before, the numbers $a_{ij}$ are called the
  \textbf{coefficients}%
  \index{coefficient} and the numbers $b_i$ are called the
  \textbf{constant terms}%
  \index{constant term} of the system of equations.
\end{definition}

The relative size of $m$ and $n$ is not important here. We may have
more variables than equations, more equations than variables, or an
equal number of equations and variables.

A \textbf{solution}%
\index{system of linear equations!solution} to a system of linear
equations is an assignment of real numbers to the variables that is a
solution to {\em all} of the equations in the system.

\begin{example}{Solutions of a system of linear equations}{linear-system-solutions}
  Consider the system of linear equations
  \begin{equation*}
    \begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}
      2x&+&3y&-&4z &=& 5 \\
      -2x&+&y&+&2z &=& -1.
    \end{array}
  \end{equation*}
  Which of the following are solutions of the system? (a)
  $(x,y,z)=(1,1,0)$, (b) $(x,y,z)=(6,3,4)$, (c) $(x,y,z)=(0,3,1)$.
\end{example}

\begin{solution}
  The assignment $(x,y,z)=(1,1,0)$ is a solution of this system of
  equations, because it is a solution to the first equation and the
  second equation. Also, $(x,y,z)=(6,3,4)$ is another solution of this
  system of equations (check this!).  On the other hand,
  $(x,y,z)=(0,3,1)$ is not a solution of the system, because although
  it is a solution to the first equation, it is not a solution to the
  second equation.
\end{solution}

Recall from Section~\ref{sec:systems-geometric} that a system of
equations either has a unique solution, infinitely many solutions, or
no solution. It is very important to us whether a system of equations
has solutions or not. For this reason, we introduce the following
terminology:

\begin{definition}{Consistent and inconsistent systems}{consistent-and-inconsistent}
  A system of linear equations is called \textbf{consistent}%
  \index{consistent system}%
  \index{system of linear equations!consistent} if there exists at
  least one solution. It is called \textbf{inconsistent}%
  \index{inconsistent system}%
  \index{system of linear equations!inconsistent} if there is no
  solution.
\end{definition}

If we think of each equation as a condition that must be satisfied by
the variables, consistent means that there is some choice of values
for the variables which can satisfy \textbf{all} of the
conditions. Inconsistent means that there is no such choice of values
for the variables. In the following sections, you will learn a method
for determining whether a system of equations is consistent or not,
and in case it is consistent, to find all of its solutions.


\chapter{Integrating differential forms}
We now show how to integrate differential forms over cells,
and state Stokes' theorem in this context.
In this chapter, all vector spaces are finite-dimensional and real.

\section{Motivation: line integrals}
Given a function $g : [a,b] \to \RR$,
we know by the fundamental theorem of calculus that
\[
	\int_{[a,b]} g(t) \; dt = f(b) - f(a)
\]
where $f$ is a function such that $g = df/dt$.
%(You might recognize this more readily
%as the more customary $\int_a^b g(t) \; dt$.)
Equivalently, for $f : [a,b] \to \RR$,
\[ \int_{[a,b]} g \; dt = \int_{[a,b]} df = f(b) - f(a) \]
where $df$ is the exterior derivative we defined earlier.

Cool, so we can integrate over $[a,b]$.
Now suppose more generally, we have $U$ an open subset of our real vector space $V$
and a $1$-form $\alpha : U \to V^\vee$.
We consider a \vocab{parametrized curve}, which is a smooth function $c : [a,b] \to U$.
Picture:
\begin{center}
	\begin{asy}
		size(8.5cm);
		pair A = (-13,0);
		pair B = (-9,0);
		draw(A--B, grey);
		dot(A, grey); dot(B, grey);
		label("$[a,b]$", A--B, dir(90), grey);
		dot("$t$", 0.3*A+0.7*B, dir(-90), grey);

		draw( (-8,0) -- (-6,0) , EndArrow);
		label("$c$", (-7,0), dir(90));

		bigblob("$U$");
		pair a = (-2,-2);
		pair b = (3,0);
		pair p = (0,1);
		pair q = (2,0);
		label("$c$", q, dir(45), red);
		draw(a..p..q..b, red);
		dot("$p = c(t)$", p, dir(90), blue);
		draw(p--(p+1.5*dir(-10)), blue, EndArrow);

		draw( (0,-4)--(0,-8), EndArrow );
		label("$\alpha$", (0,-6), dir(0));
		label("$\alpha_p(v) \in \mathbb R$", (0,-9), heavygreen);

		draw( (-10,-1)--(-1,-8), EndArrow);
		label("$c^\ast \alpha$", (-5.5,-4.5), dir(225));
	\end{asy}
\end{center}

We want to define an $\int_c \alpha$ such that:
\begin{moral}
	The integral $\int_c \alpha$ should add up all the $\alpha$ along the curve $c$.
\end{moral}
Our differential form $\alpha$ first takes in a point $p$ to get $\alpha_p \in V^\vee$.
Then, it eats a tangent vector $v \in V$ to the curve $c$ to finally give a real number $\alpha_p(v) \in \RR$.
We would like to ``add all these numbers up'',
using only the notion of an integral over $[a,b]$.

\begin{exercise}
	Try to guess what the definition of the integral should be.
	(By type-checking, there's only one reasonable answer.)
\end{exercise}

So, the definition we give is
\[ \int_c \alpha \defeq
	\int_{[a,b]} \alpha_{c(t)} \left( c'(t) \right) \; dt.  \]
Here, $c'(t)$ is shorthand for $(Dc)_{c(t)}(1)$.
It represents the \emph{tangent vector} to the curve $c$ at the point $p=c(t)$,
at time $t$.
(Here we are taking advantage of the fact that $[a,b]$ is one-dimensional.)

Now that definition was a pain to write, so we will define a differential
$1$-form $c^\ast \alpha$ on $[a,b]$ to swallow that entire thing:
specifically, in this case we define $c^\ast\alpha$ to be
\[ \left( c^\ast \alpha \right)_t (\eps) = \alpha_{c(t)} \cdot (Dc)_{t} (\eps) \]
(here $\eps$ is some displacement in time).
Thus, we can more succinctly write
\[ \int_c \alpha \defeq \int_{[a,b]} c^\ast \alpha. \]
This is a special case of a \emph{pullback}:
roughly, if $\phi : U \to U'$ (where $U \subseteq V$, $U' \subseteq V'$),
we can change any differential $k$-form $\alpha$ on $U'$
to a $k$-form on $U$.
In particular, if $U = [a,b]$,\footnote{OK,
	so $[a,b]$ isn't actually open, sorry.
	I ought to write $(a-\eps, b+\eps)$, or something.}
we can resort to our old definition of an integral.
Let's now do this in full generality.

\section{Pullbacks}
Let $V$ and $V'$ be finite dimensional real vector spaces (possibly different dimensions)
and suppose $U$ and $U'$ are open subsets of each;
next, consider a $k$-form $\alpha$ on $U'$.

Given a map $\phi : U \to U'$ we now want to define a pullback in
much the same way as before.
Picture:
\begin{center}
	\begin{asy}
		size(13cm);
		bigblob("$U$");
		pair p = (-1,0);
		dot("$p$", p, dir(90), red);
		pair p1 = p + 1.4*dir(150);
		pair p2 = p + 1.7*dir(-50);
		draw(p--p1, red, EndArrow);
		draw(p--p2, red, EndArrow);

		add(scale(0.8)*shift(14*dir(180))*CC());
		bigblob("$U'$");
		pair q = (-0.5,0.5);
		dot("$q = \phi(p)$", q, dir(90), blue);
		pair q1 = q + 1.8*dir(-100);
		pair q2 = q + 2.3*dir(-10);
		draw(q--q1, blue, EndArrow);
		draw(q--q2, blue, EndArrow);

		draw((-9,0)--(-3,0), EndArrow);
		label("$\phi$", (-6,0), dir(90));

		draw( (0,-4)--(0,-8), EndArrow );
		label("$\alpha$", (0,-6), dir(0));
		label("$\alpha_q(\dots) \in \mathbb R$", (0,-9), heavygreen);

		draw( (-11,-3)--(-1,-8), EndArrow);
		label("$\phi^\ast \alpha$", (-6,-6), dir(225));
	\end{asy}
\end{center}

Well, there's a total of about one thing we can do.
Specifically: $\alpha$ accepts a point in $U'$ and $k$ tangent vectors in $V'$,
and returns a real number.
We want $\phi^\ast \alpha$ to accept a point in $p \in U$
and $k$ tangent vectors $v_1, \dots, v_k$ in $V$,
and feed the corresponding information to $\alpha$.

Clearly we give the point $q = \phi(p)$.
As for the tangent vectors, since we are interested in volume, we take the
derivative of $\phi$ at $p$, $(D\phi)_p$, which will scale each of our vectors $v_i$
into some vector in the target $V'$.
To cut a long story short:
\begin{definition}
	Given $\phi : U \to U'$ and $\alpha$ a $k$-form, we define the \vocab{pullback}
	\[
		(\phi^\ast \alpha)_p(v_1, \dots, v_k)
		\defeq \alpha_{\phi(p)}
		\left( (D\phi)_p(v_1), \dots, (D\phi)_p(v_k) \right).
	\]
\end{definition}

There is a more concrete way to define the pullback using bases.
Suppose $w_1, \dots, w_n$ is a basis of $V'$
and $e_1, \dots, e_m$ is a basis of $V$.
Thus, by the projection principle (\Cref{thm:project_principle})
the map $\phi : V \to V'$ can be thought of as
\[ \phi(v) = \phi_1(v) w_1 +  \dots \phi_n(v) w_n \]
where each $\phi_i$ takes in a $v \in V$ and returns a real number.
We know also that $\alpha$ can be written concretely as
\[ \alpha = \sum_{J \subseteq \{1, \dots, n\}} f_J w_J. \]
Then, we define
\[
	\phi^\ast\alpha
	= \sum_{I \subseteq \{1, \dots, m\}}
	(f_I \circ \phi) (D\phi_{i_1} \wedge \dots \wedge D\phi_{i_k}).
\]
A diligent reader can check these definitions are equivalent.
\begin{example}
	[Computation of a pullback]
	Let $V = \RR^2$ with basis $\ee_1$ and $\ee_2$,
	and suppose $\phi : V \to V'$ is given by sending
	\[ \phi(a\ee_1 + b\ee_2) = (a^2+b^2)w_1 + \log(a^2+1) w_2 + b^3 w_3 \]
	where $w_1$, $w_2$, $w_3$ is a basis for $V'$.
	Consider the form $\alpha_q = f(q) w_1 \wedge w_3$, where $f : V' \to \RR$.
	Then
	\[ (\phi^\ast\alpha)_p = f(\phi(p)) \cdot (2a \ee_1^\vee + 2b\ee_2^\vee) \wedge (3b^2 \ee_2^\vee)
		= f(\phi(p)) \cdot 6ab^2 \cdot \ee_1^\vee \wedge \ee_2^\vee. \]
\end{example}

It turns out that the pullback basically behaves nicely as possible, e.g.\
\begin{itemize}
	\ii $\phi^\ast(c\alpha + \beta) = c\phi^\ast \alpha + \phi^\ast\beta$ (linearity)
	\ii $\phi^\ast(\alpha\wedge\beta)
	= (\phi^\ast \alpha)\wedge(\phi^\ast \beta)$
	\ii $\phi_1^\ast(\phi_2^\ast(\alpha))
	= (\phi_2 \circ \phi_1)^\ast(\alpha)$ (naturality)
\end{itemize}
but I won't take the time to check these here
(one can verify them all by expanding with a basis).

\section{Cells}
\prototype{A disk in $\RR^2$ can be thought of as the cell
	$[0,R]\times[0,2\pi] \to \RR^2$ by
	$(r,\theta) \mapsto (r\cos\theta)\ee_1 + (r\sin\theta)\ee_2$.}
Now that we have the notion of a pullback,
we can define the notion of an integral for more general spaces.
Specifically, to generalize the notion of integrals we had before:
\begin{definition}
	A \vocab{$k$-cell} is a smooth function $c : [a_1, b_1] \times [a_2,b_2] \times \dots [a_k, b_k] \to V$.
\end{definition}
\begin{example}
	[Examples of cells]
	Let $V = \RR^2$ for convenience.
	\begin{enumerate}[(a)]
		\ii A $0$-cell consists of a single point.
		\ii As we saw, a $1$-cell is an arbitrary curve.
		\ii A $2$-cell corresponds to a $2$-dimensional surface.
		For example, the map $c : [0,R] \times [0,2\pi] \to V$ by
		\[ c : (r,\theta) \mapsto (r\cos\theta, r\sin\theta) \]
		can be thought of as a disk of radius $R$.
	\end{enumerate}
\end{example}
Then, to define an integral
\[ \int_c \alpha \]
for a differential $k$-form $\alpha$ and a $k$-cell $c : [0,1]^k \to V$,
we simply take the pullback
\[ \int_{[0,1]^k} c^\ast \alpha \]
Since $c^\ast \alpha$ is a $k$-form on the $k$-dimensional unit box,
it can be written as $f(x_1, \dots, x_n) \; dx_1 \wedge \dots \wedge dx_n$,
so the above integral can be written as
\[ \int_0^1 \dots \int_0^1 f(x_1, \dots, x_n) \; dx_1 \wedge \dots \wedge dx_n \]

\begin{example}[Area of a circle]
	Consider $V = \RR^2$ and let $c : (r,\theta) \mapsto (r\cos\theta)\ee_1 + (r\sin\theta)\ee_2$
	on $[0,R] \times [0,2\pi]$ as before.
	Take the $2$-form $\alpha$ which gives $\alpha_p = \ee_1^\vee \wedge \ee_2^\vee$ at every point $p$.
	Then
	\begin{align*}
		c^\ast\alpha &=
		\left( \cos\theta dr - r\sin\theta d\theta \right)
		\wedge
		\left( \sin\theta dr + r\cos\theta d\theta \right) \\
		&= r(\cos^2\theta+\sin^2\theta) (dr \wedge d\theta) \\
		&= r \; dr \wedge d\theta
	\end{align*}
	Thus,
	\[ \int_c \alpha
		= \int_0^R \int_0^{2\pi} r \; dr \wedge d\theta
		= \pi R^2 \]
	which is the area of a circle.
\end{example}

Here's some geometric intuition for what's happening.
Given a $k$-cell in $V$, a differential $k$-form $\alpha$ accepts a point $p$ and some tangent vectors $v_1$, \dots, $v_k$
and spits out a number $\alpha_p(v_1, \dots, v_k)$,
which as before we view as a signed hypervolume.
Then the integral \emph{adds up all these infinitesimals across the entire cell}.
In particular, if $V = \RR^k$ and we take the form $\alpha : p \mapsto \ee_1^\vee \wedge \dots \wedge \ee_k^\vee$,
then what these $\alpha$'s give is the $k$th hypervolume of the cell.
For this reason, this $\alpha$ is called the \vocab{volume form} on $\RR^k$.

You'll notice I'm starting to play loose with the term ``cell'':
while the cell $c : [0,R] \times [0,2\pi] \to \RR^2$ is supposed to be a function
I have been telling you to think of it as a unit disk (i.e.\ in terms of its image).
In the same vein, a curve $[0,1] \to V$ should be thought of as a curve in space,
rather than a function on time.

This error turns out to be benign.
Let $\alpha$ be a $k$-form on $U$ and $c : [a_1, b_1] \times \dots \times [a_k, b_k] \to U$ a $k$-cell.
Suppose $\phi : [a_1', b_1'] \times \dots [a_k', b_k'] \to [a_1, b_1] \times \dots \times [a_k, b_k]$;
it is a \vocab{reparametrization} if $\phi$ is bijective and $(D\phi)_p$ is always invertible
(think ``change of variables'');
thus
\[ c \circ \phi : [a_1', b_1'] \times \dots \times [a_k',b_k'] \to U \]
is a $k$-cell as well.
Then it is said to \vocab{preserve orientation} if $\det(D\phi)_p > 0$ for all $p$
and \vocab{reverse orientation} if $\det(D\phi)_p < 0$ for all $p$.
\begin{exercise}
	Why is it that exactly one of these cases must occur?
\end{exercise}

\begin{theorem}
	[Changing variables doesn't affect integrals]
	Let $c$ be a $k$-cell, $\alpha$ a $k$-form, and $\phi$ a reparametrization.
	Then
	\[ \int_{c \circ \phi} \alpha
		=
		\begin{cases}
			\int_c \alpha & \phi \text{ preserves orientation} \\
			- \int_c \alpha & \phi \text{ reverses orientation}.
		\end{cases}
	\]
\end{theorem}
\begin{proof}
	Use naturality of the pullback to reduce it to the corresponding
	theorem in normal calculus.
\end{proof}

So for example, if we had parametrized the unit circle as $[0,1] \times [0,1] \to \RR^2$
by $(r,t) \mapsto R\cos(2\pi t) \ee_1 + R\sin(2\pi t) \ee_2$, we would have arrived at the same result.
So we really can think of a $k$-cell just in terms of the points it specifies.

\section{Boundaries}
\prototype{The boundary of $[a,b]$ is $\{b\}-\{a\}$. The boundary of a square goes around its edge counterclockwise.}
First, I introduce a technical term that lets us consider multiple cells at once.
\begin{definition}
	A \vocab{$k$-chain} $U$ is a formal
	linear combination of $k$-cells over $U$,
	i.e.\ a sum of the form
	\[ c = a_1 c_1 + \dots + a_m c_m \]
	where each $a_i \in \RR$ and $c_i$ is a $k$-cell.
	We define $\int_c \alpha = \sum_i a_i \int c_i$.
\end{definition}
In particular, a $0$-chain consists of several points, each with a given weight.

Now, how do we define the boundary?
For a $1$-cell $[a,b] \to U$, as I hinted earlier we want the answer to be the $0$-chain $\{c(b)\}-\{c(a)\}$.
Here's how we do it in general.
\begin{definition}
	Suppose $c : [0,1]^k \to U$ is a $k$-cell.
	Then the \vocab{boundary} of $c$, denoted $\partial c : [0,1]^{k-1} \to U$,
	is the $(k-1)$-chain defined as follows.
	For each $i = 1,\dots,k$ define
	\begin{align*}
		c_i^{\text{start}}(t_1, \dots, t_{k-1}) &
		= (t_1, \dots, t_{i-1}, 0, t_i, \dots, t_k) \\
		c_i^{\text{stop}}(t_1, \dots, t_{k-1}) &
		= (t_1, \dots, t_{i-1}, 1, t_i, \dots, t_k).
	\end{align*}
	Then
	\[ \partial c \defeq
	\sum_{i=1}^k (-1)^{i+1} \left( c_i^{\text{stop}} - c_i^{\text{start}}  \right). \]
	Finally, the boundary of a chain is the sum of the boundaries of each cell (with the appropriate weights).
	That is, $\partial(\sum a_ic_i) = \sum a_i \partial c_i$.
\end{definition}
\begin{ques}
	Satisfy yourself that one can extend this definition to
	a $k$-cell $c$ defined on $c : [a_1, b_1] \times \dots \times [a_k, b_k] \to V$
	(rather than from $[0,1]^k \to V$).
\end{ques}

\begin{example}
	[Examples of boundaries]
	Consider the $2$-cell $c : [0,1]^2 \to \RR^2$ shown below.
	\begin{center}
		\begin{asy}
			size(7cm);
			pen e1 = heavyred;
			pen e2 = orange;
			pen e3 = olive;
			pen e4 = heavymagenta;
			draw((0,0)--(2,0), e1, EndArrow);
			draw((2,0)--(2,2), e2, EndArrow);
			draw((2,2)--(0,2), e3, EndArrow);
			draw((0,2)--(0,0), e4, EndArrow);
			label(scale(0.8)*"$[0,1]^2$", (1,1));
			draw( (3,1)--(6,1), EndArrow);
			label("$c$", (4.5,1), dir(90));
			pair p1 = (7,-1);
			pair p2 = (12,-2);
			pair p3 = (11,3);
			pair p4 = (8,2);
			fill(p1--p2--p3--p4--cycle, palecyan);
			draw(p1--p2, e1, EndArrow, Margins);
			draw(p2--p3, e2, EndArrow, Margins);
			draw(p3--p4, e3, EndArrow, Margins);
			draw(p4--p1, e4, EndArrow, Margins);
			dot("$p_1$", p1, dir(225), blue+4);
			dot("$p_2$", p2, dir(315), blue+4);
			dot("$p_3$", p3, dir( 45), blue+4);
			dot("$p_4$", p4, dir(135), blue+4);
			label("$c$", (p1+p2+p3+p4)/4);
		\end{asy}
	\end{center}
	Here $p_1$, $p_2$, $p_3$, $p_4$ are the images of $(0,0)$, $(0,1)$, $(1,0)$, $(1,1)$, respectively.
	Then we can think of $\partial c$ as
	\[ \partial c = [p_1,p_2] + [p_2,p_3] + [p_3,p_4] + [p_4,p_1] \]
where each ``interval'' represents the $1$-cell shown by the reddish arrows on the right.
	We can take the boundary of this as well, and obtain an empty chain as
	\[ \partial(\partial c) = \sum_{i=1}^4 \partial([p_i, p_{i+1}]) = \sum_{i=1}^4 \{p_{i+1}\}-\{p_i\} = 0. \]
\end{example}

\begin{example}
	[Boundary of a unit disk]
	Consider the unit disk given by
	\[ c : [0,1] \times [0,2\pi] \to \RR^2 \quad\text{by}\quad
	(r,\theta) \mapsto s\cos(2\pi t)\ee_1 + s\sin(2\pi t)\ee_2. \]
	The four parts of the boundary are shown in the picture below:
	\begin{center}
		\begin{asy}
			size(7cm);
			pen e1 = heavyred;
			pen e2 = orange;
			pen e3 = olive;
			pen e4 = heavymagenta;
			draw((0,0)--(2,0), e1, EndArrow);
			draw((2,0)--(2,2), e2, EndArrow);
			draw((2,2)--(0,2), e3, EndArrow);
			draw((0,2)--(0,0), e4, EndArrow);
			label("$r$", (2,0), dir(-45));
			label("$\theta$", (0,2), dir(135));

			label(scale(0.8)*"$[0,1]^2$", (1,1));
			draw( (3,1)--(6,1), EndArrow);
			label("$c$", (4.5,1), dir(90));

			pair O = (9,1);
			pair P = O + 2*dir(0);
			fill(CP(O,P), palecyan);
			real eps = 0.3;
			draw(shift(0,eps) * (O--P), e1, EndArrow, Margins);
			draw(shift(0,-eps) * (P--O), e3, EndArrow, Margins);
			draw(CP(O,P), e2, EndArrow, Margins);
			dot(O, e4+4);
		\end{asy}
	\end{center}
	Note that two of the arrows more or less cancel each other out when they are integrated.
	Moreover, we interestingly have a \emph{degenerate} $1$-cell at the center of the circle;
	it is a constant function $[0,1] \to \RR^2$ which always gives the origin.
\end{example}

Obligatory theorem, analogous to $d^2=0$ and left as a problem.
\begin{theorem}[The boundary of the boundary is empty]
	$\partial^2 = 0$, in the sense that for any $k$-chain $c$ we have $\partial^2(c) = 0$.
\end{theorem}

\section{Stokes' theorem}
\prototype{$\int_{[a,b]} dg = g(b) - g(a)$.}

We now have all the ingredients to state Stokes' theorem for cells.
\begin{theorem}
	[Stokes' theorem for cells]
	Take $U \subseteq V$ as usual, let $c : [0,1]^k \to U$ be a $k$-cell
	and let $\alpha : U \to \Lambda^{k-1}(V^\vee)$ be a $k-1$-form.
	Then
	\[ \int_c d\alpha = \int_{\partial c} \alpha. \]
	In particular, if $d\alpha = 0$ then the left-hand side vanishes.
\end{theorem}
For example, if $c$ is the interval $[a,b]$ then $\partial c = \{b\} - \{a\}$,
and thus we obtain the fundamental theorem of calculus.

\section\problemhead
\begin{dproblem}[Green's theorem]
	Let $f,g : \RR^2 \to \RR$ be smooth functions.
	Prove that
	\[ \int_c \left( \fpartial gx - \fpartial fy \right) \; dx \wedge dy
	= \int_{\partial c} (f \; dx + g \; dy). \]
	\begin{hint}
		Direct application of Stokes' theorem to $\alpha = f \; dx + g \; dy$.
	\end{hint}
\end{dproblem}

\begin{problem}
	Show that $\partial^2 = 0$.
	\label{prob:partial_zero}
	\begin{hint}
		This is just an exercises in sigma notation.
	\end{hint}
\end{problem}

\begin{problem}[Pullback and $d$ commute]
	Let $U$ and $U'$ be open sets of vector spaces $V$ and $V'$
	and let $\phi : U \to U'$ be a smooth map between them.
	Prove that for any differential form $\alpha$ on $U'$ we have
	\[ \phi^\ast(d\alpha) = d(\phi^\ast\alpha). \]
	\begin{hint}
		This is a straightforward (but annoying) computation.
	\end{hint}
\end{problem}

\begin{problem}[Arc length isn't a form]
	Show that there does \emph{not} exist a $1$-form $\alpha$ on $\RR^2$ such that
	for a curve $c : [0,1] \to \RR^2$,
	the integral $\int_c \alpha$ gives the arc length of $c$.
	\begin{hint}
		We would want $\alpha_p(v) = \norm{v}$.
	\end{hint}
\end{problem}

\begin{problem}
	An \vocab{exact} $k$-form $\alpha$ is one satisfying $\alpha = d\beta$ for some $\beta$.
	Prove that
	\[ \int_{C_1} \alpha = \int_{C_2} \alpha \]
	where $C_1$ and $C_2$ are any concentric circles in the plane
	and $\alpha$ is some exact $1$-form.
	\begin{hint}
		Show that $d^2=0$ implies $\int_{\partial c} \alpha = 0$ for exact $\alpha$.
		Draw an annulus.
	\end{hint}
\end{problem}


\RequirePackage{luatex85}
\documentclass[addpoints]{exam}
\usepackage{multicol, amsmath}
\everymath{\displaystyle}
\begin{document}
\begin{questions}
\section{Elementary algebra. Equations.}
\question Solve $2=-\frac32+b$. \qquad\qquad
\begin{oneparchoices}
	\correctchoice $\frac83$
	\choice $\frac43$
	\choice 3
	\end{oneparchoices}

\section{Elementary algebra. Functions.}
\question Let $f(x) = x^2$. Find $f(5)$.
\begin{oneparchoices}
	\correctchoice 25
	\choice $f(25)$
	\end{oneparchoices}

\section{Algebra. Functions. Composition.}
\question Let $f(x) = -2+\sqrt{x+3}$ and let $g(x) = \frac1x$. Find the composition $(f\circ g)(x)$.
\begin{multicols}3
\begin{choices}
	\choice $\frac1{-2+\sqrt{x+3}}$
	\choice $-2+\sqrt{x+3}$
	\choice $-2+\frac1{\sqrt{x+3}}$
	\choice $-2+\frac1{\sqrt x+3}$
	\correctchoice $-2+\sqrt{\frac1x+3}$
	\end{choices}
	\end{multicols}

\section{Algebra. Functions. Domain.}
\question Find the domain of $-2+\sqrt{3+1/x}$.
\begin{multicols}3
\begin{choices}
	\choice $(-\infty,0)\cup(0,\infty)$ %6/30
	\choice $(-\infty,\infty)$ %5/30
	\choice $[0,\infty)$ %5/30
	\choice $(1,\infty)$ %3/30
	\choice $(-\infty,0)\cup(0,1)$ %3/30
	\correctchoice $(-\infty,-\tfrac13]\cup(0,\infty)$ %2/30
	\end{choices}
	\end{multicols}
\question Find the domain of $\frac1{-2+\sqrt{3+x}}$.
\begin{multicols}3
\begin{choices}
	\correctchoice $[-3,1)\cup(1,\infty)$
	\choice $(-\infty,0)\cup(0,\infty)$
	\choice $(-\infty,\infty)$
	\choice $(-\infty,1)\cup(1,\infty)$
	\choice $(-\infty,-3)\cup(-3,\infty)$
	\end{choices}
	\end{multicols}

\section{Algebra. Trig. Right triangle apps.}
\question The angle of elevation is $26^\circ$. Which diagram is correctly labelled.

\section{Calculus I. Limits. Algebraic.}
\question Find $\lim_{x\to 25} \frac{\sqrt x-5}{x-25}$. \qquad\qquad
\begin{oneparchoices}
	\correctchoice $\frac1{10}$
	\choice $\frac1{50}$ % +reasoning/level; +student stats
	\choice $\frac1{60}$
	\choice $\frac15$
	\choice 0
	\choice DNE
	\choice 0.10001
	\end{oneparchoices}
\question Find $\lim_{h\to0} \frac0h$. \qquad\qquad
\begin{oneparchoices}
	\correctchoice 0
	\choice 1
	\choice $\infty$
	\choice DNE
	\end{oneparchoices}

\section{Calculus Lab}
\question Write $x^{1/(1-x)}$ using computer notation.
\begin{oneparchoices}
	\correctchoice $x\wedge(1/(1-x))$
	\choice $(x\wedge 1)/(1-x))$
	\choice $x\wedge 1/(1-x)$
	\end{oneparchoices}

\end{questions}
\end{document}