\subsection{Category equivalences}\label{subsec:category_equivalences}

\begin{remark}\label{rem:category_similarity}
  We have the following notions for expressing that two categories \( \cat{C} \) and \( \cat{D} \) are similar:

  \begin{thmenum}
    \thmitem{rem:category_similarity/equality} Obviously, if \( \cat{C} \) and \( \cat{D} \) are equal, they are similar.

    \thmitem{rem:category_similarity/isomorphism} A slightly less obvious notion is \term{isomorphism of categories}. This is an isomorphism, in the sense of \fullref{def:morphism_invertibility/isomorphism}, in the category \hyperref[def:category_of_small_categories]{\( \ucat{Cat} \)} of small categories for a suitable \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \). That is, \( \cat{C} \) and \( \cat{D} \) are isomorphic if there exists an invertible functor between them.

    We rarely distinguish between objects and arrows of isomorphic categories, even if we do not have strict equality in the sense of the \hyperref[def:zfc/extensionality]{axiom of extensionality} in \hyperref[def:zfc]{\logic{ZFC}}.

    Examples of isomorphic categories include \fullref{thm:order_category_isomorphism} and \fullref{ex:isomorphism_of_quiver_categories}.

    \thmitem{rem:category_similarity/equivalence} A weaker but very useful notion is \term{category equivalence} defined in \fullref{def:category_equivalence}.
  \end{thmenum}
\end{remark}

\begin{example}\label{ex:set_discr_cat_isomorphism}
  There is an isomorphism between the category \( \ucat{Set} \) of small sets and \( \ucat{DiscrCat} \) of all small \hyperref[def:discrete_category]{discrete categories}.

  Consider the pair of functors
  \begin{equation*}
    U: \ucat{DiscrCat} \to \ucat{Set},
  \end{equation*}
  which for any small category \( \cat{C} \) gives us its set of objects \( \obj(\cat{C}) \) and
  \begin{equation*}
    D: \ucat{Set} \to \ucat{DiscrCat},
  \end{equation*}
  which for any small set \( A \) gives us the \hyperref[def:discrete_category]{discrete category} whose set of objects is \( A \).

  These were discussed in \fullref{ex:discrete_category_adjunction}, although with \( \cat{Cat} \) rather than \( \ucat{DiscrCat} \).

  It is obvious that for any small category \( \cat{C} \), the functor \( D \bincirc U \) is bijective on objects. We need to verify that it is bijective on morphisms, however, in order to prove that \( D \bincirc U \) is the identity functor on \( \ucat{DiscrCat} \).

  But any functor \( F: \cat{C} \to \cat{D} \) is completely determined by how \( F \) acts on the objects of \( \cat{C} \). Indeed, the only morphisms in \( \cat{C} \) are the identity morphisms and, by \ref{def:functor/CF1}, every object \( X \) in \( \cat{C} \) determines how the identity \( \id_X \in \cat{C}(X) \) is mapped by \( F \).

  Therefore, \( D \) is a left inverse of \( U \). It is also a right inverse --- for any function \( f: A \to B \) between small sets,
  \begin{equation*}
    [U \bincirc D](f) = D(f)\restr_{A} = f.
  \end{equation*}

  Therefore, the forgetful functor \( U \) is invertible, and its inverse is \( D \).
\end{example}

\begin{definition}\label{def:category_equivalence}\mcite[def. 1.3.15]{Leinster2016Basic}
  An \term{equivalence} between the \hyperref[def:category]{categories} \( \cat{C} \) and \( \cat{D} \) is a quadruple
  \begin{equation}\label{eq:def:category_equivalence/signature}
    \begin{aligned}
                F &: \cat{C} \to \cat{D}, \\
                G &: \cat{D} \to \cat{C}, \\
             \eta &: \id_{\cat{C}} \Rightarrow G \bincirc F, \\
      \varepsilon &: F \bincirc G \Rightarrow \id_{\cat{D}},
    \end{aligned}
  \end{equation}
  where \( \eta \) and \( \varepsilon \) are \hyperref[thm:natural_isomorphism]{natural isomorphisms}.

  We call \( \eta \) the \term{unit} of the equivalence and \( \varepsilon \) the \term{counit}.

  If \( (F, G, \eta, \varepsilon) \) is an equivalence, we say that \( \cat{C} \) and \( \cat{D} \) are equivalent categories. This is justified because equivalence of categories is an equivalence relation --- see \fullref{thm:category_equivalence_is_equivalence_relation}.

  Note that an equivalence is not necessarily an \hyperref[def:category_adjunction]{adjunction}, they simply have a common setup. This is discussed in \fullref{thm:adjoint_equivalence}.
\end{definition}

\begin{proposition}\label{thm:category_equivalence_is_equivalence_relation}
  For every \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \), \hyperref[def:category_equivalence]{category equivalence} is an \hyperref[def:equivalence_relation]{equivalence relation} on the set \( \obj(\ucat{Cat}) \)
\end{proposition}
\begin{proof}
  \SubProofOf[def:binary_relation/reflexive]{reflexivity} Clearly \( (\id_{\cat{C}}, \id_{\cat{C}}, \id_{\id_{\cat{C}}}, \id_{\id_{\cat{C}}}]) \) is a self-equivalence for the category \( \cat{C} \).

  \SubProofOf[def:binary_relation/symmetric]{symmetry} If \( (F, G, \eta, \varepsilon) \) is an \hyperref[def:category_equivalence]{equivalence} between the categories \( \cat{C} \) and \( \cat{D} \), then \( (G, F, \varepsilon^{-1}, \eta^{-1}) \) is an equivalence between \( \cat{D} \) and \( \cat{C} \).

  \SubProofOf[def:binary_relation/transitive]{transitivity} By \fullref{thm:def:morphism_invertibility/invertible_composition}, the composition of invertible natural isomorphisms is again a natural isomorphism, hence equivalence in \( \obj(\ucat{Cat}) \) is a transitive relation.
\end{proof}

\begin{proposition}\label{thm:discrete_category_equivalence}
  Let \( \cat{C} \) and \( \cat{D} \) be \hyperref[def:discrete_category]{discrete categories}. Then \( \cat{C} \) and \( \cat{D} \) are \hyperref[def:category_equivalence]{equivalent} if and only if the underlying sets \( \obj(\cat{C}) \) and \( \obj(\cat{D}) \) are \hyperref[def:equinumerosity]{equinumerous}.
\end{proposition}
\begin{proof}
  \SufficiencySubProof Suppose that \( (F, G, \eta, \varepsilon) \) be a category equivalence.

  The unit natural transformation \( \eta: \id_{\cat{C}} \Rightarrow G \bincirc F \) consists of a morphism
  \begin{equation*}
    \eta_A: A \to [G \bincirc F](A)
  \end{equation*}
  for every object \( A \) of \( \cat{C} \). Since the only morphisms in \( \cat{C} \) are the identities, it follows that \( \eta_A = \id_A \) and hence \( [G \bincirc F](A) = A \). In particular, this implies that \( \eta \) is the \hyperref[eq:def:functor_category/identity]{identity natural transformation} on \( \id_{\cat{C}} \) and that the restriction \( G\restr_{\obj(D)} \) is a left inverse of \( F\restr_{\obj(\cat{C})} \).

  Similarly, for the counit \( \varepsilon: F \bincirc G \Rightarrow \id_{\cat{D}} \), for every object \( X \) in \( \cat{D} \) we have \( \varepsilon_X = \id_X \) and hence \( [F \bincirc G](X) = X \). Thus, \( \eta \) is the identity natural transformation on \( \id_{\cat{D}} \) and \( G\restr_{\obj(D)} \) is a right inverse of \( F\restr_{\obj(\cat{C})} \).

  Therefore, the sets \( \obj(\cat{C}) \) and \( \obj(D) \) are equinumerous.

  \NecessitySubProof Suppose that \( F: \obj(\cat{C}) \to \obj(D) \) is a bijective function. Then it is an isomorphism in the category \( \ucat{Cat} \) for an appropriate universe \( \mscrU \), hence it induces an equivalence between \( \cat{C} \) and \( \cat{D} \).
\end{proof}

\begin{proposition}\label{thm:opposite_of_category_equivalence}
  The \hyperref[def:opposite_category]{opposite} of \hyperref[def:category_equivalence]{equivalent categories} are equivalent.

  More precisely, if \( (F, G, \eta, \varepsilon) \) is an \hyperref[def:category_equivalence]{equivalence} between the categories \( \cat{C} \) and \( \cat{D} \), then
  \begin{equation*}
    \begin{aligned}
                G^{\opcat} &: \cat{D}^{\opcat} \to \cat{C}^{\opcat}, \\
                F^{\opcat} &: \cat{C}^{\opcat} \to \cat{D}^{\opcat}, \\
      \varepsilon^{\opcat} &: \id_{\cat{D}} \Rightarrow [F \bincirc G]^{\opcat}, \\
             \eta^{\opcat} &: \underbrace{[G \bincirc F]^{\opcat}}_{G^{\opcat} \bincirc F^{\opcat}} \Rightarrow \id_{\cat{C}^{\opcat}},
    \end{aligned}
  \end{equation*}
  is an equivalence between \( \cat{C}^{\opcat} \) and \( \cat{D}^{\opcat} \).

  This is part of the duality principles listed in \fullref{thm:categorical_principle_of_duality}.
\end{proposition}
\begin{proof}
  Trivial.
\end{proof}

\begin{proposition}\label{thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor}
  In any \hyperref[def:category_equivalence]{category equivalence} \( (F, G, \eta, \varepsilon) \), the functor \( F \) is \hyperref[def:functor_invertibility/fully_faithful]{fully faithful} and \hyperref[def:functor_invertibility/surjective_on_objects]{essentially surjective on objects}.

  The converse of this statement is \fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}.
\end{proposition}
\begin{proof}
  \SubProofOf[def:functor_invertibility/surjective_on_objects]{essential surjectivity} For any object \( X \) in \( \cat{D} \), \( A \coloneqq G(X) \) is an object in \( \cat{C} \).

  By definition of category equivalence, the morphism
  \begin{equation*}
    \varepsilon_X: \underbrace{[F \bincirc G](X)}_{F(A)} \to X
  \end{equation*}
  is an isomorphism.

  Therefore, for every object \( X \) in \( \cat{D} \), there exists some object \( A \) in \( \cat{C} \) such that \( F(A) \cong X \). Thus, \( F \) is essentially surjective.

  \SubProofOf[def:functor_invertibility/faithful]{faithfulness} Fix some objects \( A \) and \( B \) in \( \cat{C} \). Let \( f_1: A \to B \) and \( f_2: A \to B \) be morphisms such that \( F(f_1) = F(f_2) \).

  From the naturality of \( \eta \) it follows that the following diagram commutes:
  \begin{equation}\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/faithfullness}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}
    \end{aligned}
  \end{equation}

  Therefore, \( \eta_B \bincirc f_1 = \eta_B \bincirc f_2 \) and, since \( \eta_B \) is left-cancellative, \( f_1 = f_2 \).

  \SubProofOf[def:functor_invertibility/full]{fullness} Fix some objects \( A \) and \( B \) in \( \cat{C} \). Let \( g: F(A) \to F(B) \) be an arbitrary morphism.

  We can define a morphism \( f: A \to B \) via the composition
  \begin{equation}\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/fullness/def}
    \begin{aligned}
      \includegraphics[page=2]{output/thm__equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}
    \end{aligned}
  \end{equation}

  By naturality of \( \eta \), the following diagram commutes:
  \begin{equation}\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/fullness/eta_nat}
    \begin{aligned}
      \includegraphics[page=3]{output/thm__equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}
    \end{aligned}
  \end{equation}

  Therefore,
  \begin{equation*}
     G(g) = [G \bincirc F](f).
  \end{equation*}

  We have already shown that \( F \) is faithful and, by \fullref{thm:category_equivalence_is_equivalence_relation}, \( G \) is also faithful. Since \( g \) and \( F(f) \) are parallel, it follows that they are equal.

  Therefore, \( F \) is full.
\end{proof}

\begin{remark}\label{rem:adjoint_equivalence_induces_fully_faithful_and_essentially_surjective_functor}
  In the fullness proof of \fullref{thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor}, we can use another argument if \( (F, G, \eta, \varepsilon) \) is an \hyperref[def:adjoint_equivalence]{adjoint equivalence}.

  If the triangle diagram \eqref{eq:def:category_adjunction/d_triangle} commutes, the dashed lines in the following diagram also commute:
  \begin{equation}\label{eq:thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor/fullness/triangles}
    \begin{aligned}
      \includegraphics[page=1]{output/rem__adjoint_equivalence_induces_fully_faithful_and_essentially_surjective_functor.pdf}
    \end{aligned}
  \end{equation}
\end{remark}

\begin{theorem}[Fully faithful and essentially surjective functor induces equivalence]\label{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}
  Every \hyperref[def:functor_invertibility/fully_faithful]{fully faithful} and \hyperref[def:functor_invertibility/surjective_on_objects]{essentially surjective on objects} functor induces a \hyperref[def:category_equivalence]{category equivalence}.

  More precisely, given a functor \( F: \cat{C} \to \cat{D} \) that is fully faithful and essentially surjective on objects, there exists a functor \( G: \cat{D} \to \cat{C} \) and \hyperref[def:natural_transformation]{natural transformations}
  \begin{align*}
    \eta        &: \id_{\cat{C}} \Rightarrow G \bincirc F, \\
    \varepsilon &: F \bincirc G \Rightarrow \id_{\cat{D}},
  \end{align*}
  such that the quadruple \( (F, G, \eta, \varepsilon) \) is a \hyperref[def:category_equivalence]{category equivalence}.

  In \hyperref[def:zfc]{\logic{ZF}}, this theorem is equivalent to the \hyperref[def:zfc/choice]{axiom of choice} --- see \fullref{thm:axiom_of_choice_equivalences/fully_faithful_essentially_surjective}.

  We prove the converse of this statement separately in \fullref{thm:equivalence_induces_fully_faithful_and_essentially_surjective_functor}.
\end{theorem}
\begin{proof}
  \ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence]{functors induce equivalences} Suppose that the axiom of choice holds and let \( F \) be a fully faithful functor that is surjective on objects.

  From essential surjectivity of \( F \), it follows that for every object \( X \) in \( \cat{D} \), the preimage of \( X \) under \( F \) is nonempty. The preimage of \( X \) is the set \( \mscrA_X \) of objects in \( \cat{C} \) such that \( A \in \mscrA_X \) if and only if \( F(A) \cong X \). We use the axiom of choice on the family \( \set{ \mscrA_X }_{X \in \cat{D}} \) to select a single preimage for every \( X \), which we denote by \( G(X) \).

  Again using the axiom of choice, we pick an isomorphism \( \varepsilon_X: F(G(X)) \to X \) for every \( X \).

  We have defined a function \( G \) from \( \obj(\cat{D}) \) to \( \obj(\cat{C}) \). In order to \( G \) to become a functor, we must extend it to morphisms. Let \( X \) and \( Y \) be objects in \( \cat{D} \) and \( g: X \to Y \) be any morphism.

  Consider the morphism
  \begin{equation*}
    \varepsilon_Z^{-1} \bincirc f \bincirc \varepsilon_X: [F \bincirc G](X) \to [F \bincirc G](Y).
  \end{equation*}

  Since \( F \) is fully faithful, there exists a unique morphism \( g \) in \( \cat{D}(G(X), G(Y)) \) such that the following diagram commutes:
  \begin{equation}\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/inverse_morphism_definition}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}
    \end{aligned}
  \end{equation}

  We define \( G(g) \coloneqq g \).

  In order to prove that \( G \) is a functor, we need to show that \ref{def:functor/CF1} and \ref{def:functor/CF2} hold.

  For \ref{def:functor/CF1}, note that the following diagram commutes for any object \( X \) in \( \cat{D} \):
  \begin{equation}\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/identity}
    \begin{aligned}
      \includegraphics[page=2]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}
    \end{aligned}
  \end{equation}

  Note that \eqref{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/inverse_morphism_definition} also commutes if we replace \( [F \bincirc G](\id_X) \) with \( F(\id_{G(X)}) \). Since \( F \) is fully faithful, this morphism is unique and it follows that
  \begin{equation*}
    [F \bincirc G](\id_X) = F(\id_{G(X)}).
  \end{equation*}

  For \ref{def:functor/CF2}, analogously, given morphisms \( g: X \to Y \) and \( f: Y \to Z \), the following diagram commutes:
  \begin{equation}\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/composition}
    \begin{aligned}
      \includegraphics[page=3]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}
    \end{aligned}
  \end{equation}

  We have implicitly used \fullref{rem:inverting_isomorphisms_may_preserve_commutativity} above.

  By the same uniqueness argument used for \ref{def:functor/CF1}, we conclude that
  \begin{equation*}
    G(f \bincirc q) = G(f) \bincirc G(g).
  \end{equation*}

  We have shown that \( G \) is a functor. Furthermore, \( \varepsilon \) is a natural transformation since, for any morphism \( g: X \to Y \) in \( \cat{D} \), the following diagram commutes:
  \begin{equation}\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon}
    \begin{aligned}
      \includegraphics[page=4]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}
    \end{aligned}
  \end{equation}

  To show that \( F \) induces an equivalence, it now only remains to define a unit natural transformation \( \eta: \id_{\cat{C}} \to G \bincirc F \). For every object \( A \) in \( \cat{C} \) we have an isomorphism
  \begin{equation*}
    \varepsilon_{F(A)}^{-1}: F(A) \to [F \bincirc G \bincirc F](A).
  \end{equation*}

  Using \( G(\varepsilon_{F(A)}^{-1}) \) will get us nowhere. Fortunately, \( F \) is fully faithful, so there is a bijective function
  \begin{equation*}
    \varphi: \cat{D}(F(A), [F \bincirc G \bincirc F](A)) \to \cat{C}(A, [F \bincirc G](A)).
  \end{equation*}

  Hence, we can define
  \begin{equation*}
    \begin{aligned}
      &\eta: \id_{\cat{C}} \Rightarrow F \bincirc G \\
      &\eta_A \coloneqq \varphi(\varepsilon_{F(A)}^{-1})
    \end{aligned}
  \end{equation*}
  so that \( F(\eta_A) = \varepsilon_{F(A)}^{-1} \). By \fullref{thm:def:functor_invertibility/fully_faithful_reflects_invertible}, since \( \varepsilon_{F(A)} \) is an isomorphism, \( \eta_A \) is also an isomorphism.

  By naturality of \( F(\eta_A) \), the following diagram commutes:
  \begin{equation}\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon_image_nat}
    \begin{aligned}
      \includegraphics[page=5]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}
    \end{aligned}
  \end{equation}

  Hence, by \fullref{thm:commutative_diagrams_preserved_and_reflected}, the following diagram also commutes:
  \begin{equation}\label{eq:thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence/varepsilon_source_nat}
    \begin{aligned}
      \includegraphics[page=6]{output/thm__fully_faithful_and_essentially_surjective_functor_induces_equivalence.pdf}
    \end{aligned}
  \end{equation}

  Therefore, the quadruple \( (F, G, \eta, \varepsilon) \) is an equivalence of categories.

  \ImplicationSubProof[thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence]{functors induce equivalences}[def:zfc/choice]{the axiom of choice} Let \( \mscrA \) be a family of nonempty sets. Let \( \cat{D} \) be the \hyperref[def:discrete_category]{discrete category} induced by \( \mscrA \).

  Define the category \( \cat{C} \) as follows:
  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj(\cat{C}) \) is the \hyperref[def:disjoint_union]{disjoint union} \( \coprod_{A \in \mscrA} A \).

    \item The \hyperref[def:category/morphisms]{set of morphisms} \( \cat{C}((A, x), (B, y)) \) has a single morphism if \( A = B \) and no morphisms otherwise. This single morphism can be encoded as the triple \( (A, x, y) \).

    \item The \hyperref[def:category/composition]{composition of the morphisms} \( (A, x, y) \) and \( (A, y, z) \) is the morphism \( (A, x, z) \).

    \item The \hyperref[def:category/identity]{identity morphism} on the object \( (A, x) \in \cat{C} \) is \( (A, x, x) \).
  \end{itemize}

  Define the functor
  \begin{equation*}
    \begin{aligned}
      &F: \cat{C} \to \cat{D} \\
      &F(A, x) \coloneqq A \\
      &F(A, x, y) \coloneqq \id_A
    \end{aligned}
  \end{equation*}
  that maps each point \( x \in A \in \mscrA \) into the set \( A \) it belongs to. We have taken the disjoint union of \( \mscrA \) since otherwise there may not be a canonical choice of set \( A \) for \( F \) to send \( x \) to. Thus, the functor is surjective on objects (not essentially surjective but actually surjective).

  Note that \( \cat{D}(F(A, x), F(B, y)) \) has a single morphism if \( A = B \) and is empty otherwise. From this it follows that \( F \) is fully faithful.

  Therefore, \( F \) induces a \hyperref[def:category_equivalence]{category equivalence} \( (F, G, \eta, \varepsilon) \). The functor \( G \) chooses an object \( (A, x) \) of \( \cat{C} \) for each object \( A \) of \( \cat{D} \). This induces a \hyperref[def:choice_function]{choice function} on \( \mscrA \).

  We have shown that the axiom of choice holds.
\end{proof}

\begin{definition}\label{def:groupoid}
  A \term{groupoid} is a category whose only morphisms are \hyperref[def:morphism_invertibility/isomorphism]{isomorphisms}.
\end{definition}

\begin{definition}\label{def:monoid_delooping}\mcite[def. 1.1.7]{Perrone2019}
  Let \( (M, \cdot, e) \) be a \hyperref[def:monoid]{monoid}. The \term{delooping} \( \cat{B}_M \) of \( M \) is the following category:
  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj(\cat{B}_M) \) is the singleton set \( \set{ \Anon } \), where \( \Anon \) is any set not in the set of all morphisms \( M \).

    \item The only \hyperref[def:category/morphisms]{set of morphisms} \( \cat{B}_M(\Anon) \) is the underlying set \( M \) of the monoid.

    \item The \hyperref[def:category/composition]{composition of the morphisms} \( x \) and \( y \) is the multiplication:
    \begin{equation*}
      y \bincirc x \coloneqq y \cdot x.
    \end{equation*}

    Note how we write composition in the same order as multiplication. This may seem to contradict the general convention, however it is consistent with groups being regarded as sets of invertible transformations.

    \item The \hyperref[def:category/identity]{identity morphism} is \( e \).
  \end{itemize}
\end{definition}

\begin{proposition}\label{thm:delooping_of_group}
  The \hyperref[def:monoid_delooping]{delooping} of a \hyperref[def:group]{group} \( G \) is a \hyperref[def:groupoid]{groupoid}.

  There is a restricted form of a converse --- see \fullref{thm:connected_delooping}.
\end{proposition}
\begin{proof}
  Trivial.
\end{proof}

\begin{definition}\label{def:connected_category}\mcite[exer. 1.5.20]{Perrone2019}
  A \hyperref[def:category]{category} is \term{connected} if there exists a morphism between any two objects. That is, for a connected category \( \cat{C} \), given two objects \( X \) and \( Y \), either \( \cat{C}(X, Y) \) or \( \cat{C}(Y, X) \) is nonempty.

  Connected categories are used in \fullref{thm:connected_delooping} and \fullref{thm:order_category_isomorphism/totally_ordered}.
\end{definition}

\begin{proposition}\label{thm:connected_delooping}
  For every \hyperref[def:connected_category]{connected} \hyperref[def:groupoid]{groupoid} \( \cat{G} \) there exists a \hyperref[def:group]{group} \( G \) such that \( \cat{G} \) is \hyperref[def:category_equivalence]{equivalent} to the \hyperref[def:monoid_delooping]{delooping} \( \cat{B}_G \). Furthermore, if \( \cat{G} \) has only one object, then this equivalence is an \hyperref[rem:category_similarity/isomorphism]{isomorphism}.

  See \fullref{thm:delooping_of_group} for a much simpler converse.
\end{proposition}
\begin{proof}
  Define the group \( G \) as follows:
  \begin{itemize}
    \item Let the underlying set of \( G \) be the set of all morphisms of \( \cat{G} \).
    \item Define \( x \cdot y = z \) to hold whenever the following diagram commutes:
    \begin{equation}\label{eq:thm:connected_delooping/mult}
      \begin{aligned}
        \includegraphics[page=1]{output/thm__connected_delooping.pdf}
      \end{aligned}
    \end{equation}
    \item Pick the identity of \( G \) out of the identity morphisms in \( G \).
    \item Let the inverse of \( x \) be the inverse morphism \( x^{-1} \).
  \end{itemize}

  Finally, define the functor \( F: \cat{G} \to \cat{B}_G \), which sends every object to \( \anon \) and every morphism to itself.

  By definition, for every morphism \( x: \anon \to \anon \) in the delooping, there exists a unique \( f: X \to Y \) in \( \cat{G} \) such that \( F(f) = x \). Hence, \( f \) is surjective on morphisms, and by \fullref{thm:def:functor_invertibility/surjective}, full and surjective on objects.

  Furthermore, for any objects \( X \) and \( Y \) in \( \cat{G} \), we have
  \begin{equation*}
    \cat{G}(X, Y) \subseteq \cat{B}_G(F(X), F(Y)).
  \end{equation*}

  Hence, \( G \) is faithful. Therefore, by \fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}, the groupoid \( \cat{G} \) is equivalent to the delooping \( \cat{B}_G \).

  Furthermore, if \( \cat{G} \) has only one object, it is also injective on objects and, by \fullref{thm:def:functor_invertibility/injective}, injective on morphisms. In this case, we have an isomorphism due to \fullref{thm:def:functor_invertibility/isomorphism}.
\end{proof}

\begin{definition}\label{def:skeletal_category}\mcite[91]{MacLane1994}
  The category \( \cat{S} \) is called \term{skeletal} if the only isomorphisms in \( \cat{S} \) are the identity morphisms.

  If \( \cat{S} \) is a subcategory of \( \cat{C} \) and if they are \hyperref[def:category_equivalence]{equivalent}, we say that \( \cat{S} \) is a \term{skeleton} of \( \cat{C} \).
\end{definition}

\begin{example}\label{ex:skeleton_of_set}
  Fix a Grothendieck universe \( \mscrU \), the \hyperref[def:cardinal_number]{cardinal numbers} in \( \mscrU \) are a \hyperref[def:skeletal_category]{skeletal subcategory} of \( \ucat{Set} \).
\end{example}

\begin{theorem}[Category skeleton existence]\label{thm:category_skeleton_existence}
  Every \hyperref[def:category]{category} has a \hyperref[def:skeletal_category]{skeleton}.

  In \hyperref[def:zfc]{\logic{ZF}}, this theorem is equivalent to the \hyperref[def:zfc/choice]{axiom of choice} --- see \fullref{thm:axiom_of_choice_equivalences/skeletons}.
\end{theorem}
\begin{proof}
  \ImplicationSubProof[def:zfc/choice]{the axiom of choice}[thm:category_skeleton_existence]{skeleton existence} Suppose that the axiom of choice holds and let \( F \) be a fully faithful functor that is surjective on objects.

  Fix a category \( \cat{C} \). We will build a subcategory \( \cat{S} \) of \( \cat{C} \) whose inclusion functor \( \Iota: \cat{S} \to \cat{C} \) is essentially surjective and fully faithful. By \fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}, this is sufficient for \( \cat{S} \) and \( \cat{C} \) to be equivalent.

  In order for \( \Iota \) to be a full functor, \( \cat{S} \) must be a full subcategory. Therefore, when building \( \cat{S} \), we can only remove objects and must preserve the morphism sets for the remaining objects.

  Denote by \( \obj(\cat{C}) / \cong \) the quotient of \( \cat{C} \) by the isomorphism relation. Using the axiom of choice, we can obtain a \hyperref[def:choice_function]{choice function} \( c: (\obj(\cat{C}) / \cong) \to \obj(\cat{C}) \).

  Define \( \cat{S} \) as the subcategory induced by the image \( c[\obj(\cat{C}) / \cong] \).

  Now consider the \hyperref[def:subcategory]{inclusion functor} \( \Iota: \cat{S} \to \cat{C} \). For every pair \( X \) and \( Y \) of objects in \( \cat{S} \), clearly
  \begin{equation*}
    \cat{S}(X, Y) = \cat{C}(\Iota(X), \Iota(Y)).
  \end{equation*}

  Hence, \( \Iota \) is fully faithful.

  Now let \( X \) and \( Y \) be objects of \( \cat{C} \). Since the objects of \( \cat{S} \) were chosen from isomorphism classes of \( \cat{C} \), there exist objects \( X' \) and \( Y' \) in \( \cat{S} \) that are isomorphic to \( X \) and \( Y \), correspondingly. Hence, \( \Iota \) is essentially surjective.

  Therefore, \( F \) satisfies \fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}, from which is follows that \( \cat{C} \) and \( \cat{S} \) are equivalent.

  \ImplicationSubProof[thm:category_skeleton_existence]{skeleton existence}[def:zfc/choice]{the axiom of choice} Suppose that every category has a skeleton.

  Let \( \mscrA \) be a family of nonempty sets. Construct a category \( \cat{C} \)from the \hyperref[def:disjoint_union]{disjoint union} \( \coprod_{A \in \mscrA} A \), where a morphism exists only between members of the same set. This construction is performed in detail in the proof of \fullref{thm:fully_faithful_and_essentially_surjective_functor_induces_equivalence}.

  Then \( \cat{C} \) has a skeleton \( \cat{S} \). All morphisms in \( \cat{C} \) are isomorphisms, hence the set \( \obj(\cat{S}) \) contains exactly one representative for each set in the family \( \mscrA \).

  More precisely, define the set
  \begin{equation*}
    S \coloneqq \set{ x \given (A, x) \in \obj(\cat{S}) }.
  \end{equation*}

  Then \( S \) satisfies \fullref{thm:axiom_of_choice_equivalences/choice_sets}.

  Since the family \( \mscrA \) is arbitrary, we conclude that the axiom of choice holds.
\end{proof}

\begin{remark}\label{rem:skeletons_and_thin_categories}
  Rather than defining representatives of equivalence classes, as in \fullref{thm:category_skeleton_existence}, we can define morphisms between the equivalence classes themselves, as in \fullref{thm:preorder_to_partial_order}.

  This does not require the \hyperref[def:zfc/choice]{axiom of choice}, but is rarely applicable, unfortunately. One case where it is applicable is in \hyperref[def:thin_category]{thin categories} --- see \fullref{thm:order_category_isomorphism}.
\end{remark}

\begin{definition}\label{def:thin_category}\mcite{nLab:thin_category}
  A \hyperref[def:category]{category} is \term{thin} if any two parallel morphisms are equal.

  This is equivalent to saying that the function for every two objects \( A \) and \( B \) in \( \cat{P} \), whenever the set \( \cat{P}(A, B) \) is at most a singleton.

  As shown in \fullref{ex:preorder_nonuniqueness} and discussed in \fullref{thm:order_category_isomorphism}, a thin category may not be \hyperref[def:skeletal_category]{skeletal}.

  Thin categories are often conflated with preordered sets due to \fullref{thm:order_category_isomorphism/preordered}.
\end{definition}

\begin{theorem}[Ordered sets as categories]\label{thm:order_category_isomorphism}
  Regarding ordered sets, we have the following \hyperref[rem:category_similarity/isomorphism]{category isomorphisms}:
  \begin{thmenum}
    \thmitem{thm:order_category_isomorphism/preordered} The categories \hyperref[def:preordered_set/category]{\( \cat{PreOrd} \)} and \( \cat{Thin} \), where
    \begin{itemize}
      \item \( \cat{PreOrd} \) is the category of small \hyperref[def:preordered_set]{preordered sets} and (nonstrict) \hyperref[def:preordered_set/homomorphism]{monotone maps}.

      \item \( \cat{Thin} \) is the subcategory of \hyperref[def:category_of_small_categories]{\( \cat{Cat} \)} \hyperref[def:subcategory]{induced} by \hyperref[def:thin_category]{thin categories}, i.e. the category of small thin categories.
    \end{itemize}

    \thmitem{thm:order_category_isomorphism/partially_ordered} The categories \hyperref[def:partially_ordered_set/category]{\( \cat{Pos} \)} and \( \cat{SkelThin} \), where
    \begin{itemize}
      \item \( \cat{Pos} \) is the subcategory of \( \cat{PreOrd} \) induced by (nonstrict) \hyperref[def:partially_ordered_set]{partially ordered sets}.

      \item \( \cat{SkelThin} \) is the subcategory of \( \cat{Thin} \) induced by \hyperref[def:skeletal_category]{skeletal categories}, i.e. the category of small thin skeletal categories.
    \end{itemize}

    \thmitem{thm:order_category_isomorphism/totally_ordered} The categories \hyperref[def:totally_ordered_set]{\( \cat{Tos} \)} and \( \cat{ConnSkelThin} \), where
    \begin{itemize}
      \item \( \cat{Tos} \) is the subcategory of \( \cat{Pos} \) induced by (nonstrict) \hyperref[def:totally_ordered_set]{totally ordered sets}.

      \item \( \cat{ConnSkelThin} \) is the subcategory of \( \cat{SkelThin} \) induced by \hyperref[def:connected_category]{connected categories}, i.e. the category of small thin skeletal connected categories.
    \end{itemize}
  \end{thmenum}
\end{theorem}
\begin{proof}
  \SubProofOf{thm:order_category_isomorphism/preordered}
  \SubProof*{Proof that preorders induce thin categories} Let \( (P, \leq) \) be a small preordered set. Let \( \cat{P} \) be the \hyperref[def:quiver_free_category]{free category} obtained by regarding \( (P, \leq) \) as a \hyperref[def:quiver]{quiver}. Explicitly, the category \( \cat{P} \) is built as follows:
  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj(\cat{P}) \) is simply \( P \).

    \item The \hyperref[def:category/morphisms]{set of morphisms} \( \cat{P}(x, y) \) consists of the tuple \( (x, y) \) if \( x \leq y \) and is empty otherwise.

    \item The \hyperref[def:category/composition]{composition of the morphisms} \( (x, y) \) and \( (y, z) \) is simply \( (x, y) \). This is well-defined because of the \hyperref[def:binary_relation/transitive]{transitivity} of \( \leq \).

    \item The \hyperref[def:category/identity]{identity morphism} on the object \( x \in \cat{C} \) is \( (x, x) \). This is well-defined because of the \hyperref[def:binary_relation/reflexive]{reflexivity} of \( \leq \).
  \end{itemize}

  The category is clearly thin because \( \leq \) is a binary relation and ordered tuples with the same elements are equal.

  Now let \( f: P \to Q \) be a nonstrict monotone map. It induces the functor
  \begin{equation*}
    \begin{aligned}
      &F: \cat{P} \to \cat{Q} \\
      &F(x) \coloneqq f(x) \\
      &F(x, y) \coloneqq (f(x), f(y)).
    \end{aligned}
  \end{equation*}

  \ref{def:functor/CF1} is immediate and \ref{def:functor/CF2} follows from \eqref{eq:def:preordered_set/homomorphism}, hence \( F \) is indeed a functor.

  \SubProof*{Proof that thin categories induce preorders} Let \( \cat{P} \) be a small category. Define the binary relation
  \begin{equation*}
    X \leq Y \T{if and only if} \cat{P}(X, Y) \neq \varnothing.
  \end{equation*}

  This is a binary relation over the set \( P \coloneqq \obj(\cat{P}) \). It is reflexive because of the existence of identity morphisms in \( \cat{P} \) and transitive because of the requirement that the composition of compatible morphisms exists.

  Therefore, \( (P, \leq) \) is a preordered set.

  Given a functor \( F: \cat{P} \to \cat{Q} \), the restriction \( F\restr_{\obj(\cat{P})} \) is a monotone map from \( (P, \leq_P) \) to \( (Q, \leq_Q) \).

  Indeed, if \( X \leq Y \) for \( X, Y \in P \), then \( \cat{P}(X, Y) \neq \varnothing \). Hence, \( \cat{P}(F(X), F(Y)) \neq \varnothing \) and \( F(X) \leq F(Y) \).

  \SubProof*{Proof of isomorphism} We have implicitly defined a functor from \( \cat{PreOrd} \) to \( \cat{Thin} \) and vice versa. Isomorphism of \( \cat{PreOrd} \) and \( \cat{Thin} \) requires that these functors are mutually inverse.

  We need to prove that the induced preordered set for the induced thin category of a preordered set is the same as the original. In the other direction, we need to prove that the induced thin category for the induced preordered set of a thin category is the same as the original.

  Both of these proofs are trivial but nevertheless the fact that we need to perform such a check is important.

  \SubProofOf{thm:order_category_isomorphism/partially_ordered} We have already shown in \fullref{thm:order_category_isomorphism/preordered} the isomorphism between \( \cat{PreOrd} \) and \( \cat{Thin} \).

  For a thin category, there is an isomorphism between \( x \) and \( y \) if and only if there is both a morphism from \( x \) to \( y \) and one from \( y \) to \( x \). This isomorphism may not be unique as a consequence of \fullref{ex:preorder_nonuniqueness}. Uniqueness requires \( x = y \) to hold in this case, which is in turn equivalent to partial order \hyperref[def:binary_relation/antisymmetric]{antisymmetry}.

  \SubProofOf{thm:order_category_isomorphism/totally_ordered} We have already shown in \fullref{thm:order_category_isomorphism/partially_ordered} the isomorphism between \( \cat{Pos} \) and \( \cat{SkelThin} \).

  \hyperref[def:connected_category]{Connectedness} of a category \( \cat{P} \) is then equivalent to \hyperref[def:binary_relation/total]{totality} of \( (P, \leq) \).
\end{proof}

\begin{proposition}\label{thm:order_category_isomorphism_properties}
  Let \( (P, \leq) \) be a \hyperref[def:partially_ordered_set]{partially ordered set} and let \( \cat{P} \) be its corresponding category induced by \fullref{thm:order_category_isomorphism}.

  \begin{thmenum}
    \thmitem{thm:order_category_isomorphism_properties/opposite} The \hyperref[def:opposite_category]{opposite category} \( \cat{P}^{\opcat} \) corresponds to the \hyperref[def:partially_ordered_set/opposite]{opposite partially ordered set} \( (P, \geq) \).

    \thmitem{thm:order_category_isomorphism_properties/universal} If \( \cat{P} \) has an \hyperref[def:universal_objects/initial]{initial object}, since it is a skeletal category, this initial object is unique.

    An object \( I \) is an initial object if and only if it is the \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{bottom} of \( P \).

    \hyperref[thm:categorical_principle_of_duality]{Dually}, \( T \) is a \hyperref[def:universal_objects/terminal]{terminal object} if and only if it is the \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top} of \( P \).
  \end{thmenum}
\end{proposition}
\begin{proof}
  Trivial.
\end{proof}


\section{Properties of determinants}

\begin{outcome}
  \begin{enumerate}
  \item Use the determinant of a square matrix to decide whether the
    matrix is invertible.
  \item From the determinants of two matrices, calculate the
    determinant of their product.
  \item From the determinant of a matrix, calculate the determinant of
    its inverse.
  \item From the determinant of a matrix, calculate the determinant of
    its transpose.
  \item Calculate the determinant of $kA$, if the determinant of $A$
    is known.
  \item Without calculation, find the determinant of a matrix
    containing a row or column of zeros, or a matrix containing a row
    (or column) that is a scalar multiple of another row (or column).
  \item Use algebraic properties to reason about determinants.
  \end{enumerate}
\end{outcome}

One reason that the determinant is such an important quantity is that
it permits us to tell whether a square matrix is invertible.

\begin{theorem}{Determinants and invertible matrices}{determinant-invertible}
  Let $A$ be an $n\times n$-matrix. Then $A$ is invertible%
  \index{determinant!and invertibility}%
  \index{matrix!determinant!and invertibility}%
  \index{invertible matrix!and determinant}%
  \index{matrix!invertible!and determinant} if and
  only if $\det(A) \neq 0$.
\end{theorem}

\begin{proof}
  We know that every matrix $A$ can be converted to {\ef} by
  elementary row operations. We also know from
  Theorem~\ref{thm:determinant-row-operations} that no elementary row
  operation changes whether the determinant is zero or not.  Let $R$
  be an {\ef} of $A$. Because $R$ is an {\ef}, it is also an upper
  triangular matrix. Case 1: $A$ is invertible. In that case, the rank
  of $R$ is $n$, and every diagonal entry of $R$ is a pivot entry
  (therefore non-zero). It follows that $\det(R)\neq 0$, which implies
  $\det(A)\neq 0$. Case 2: $A$ is not invertible. In that case, the
  triangular matrix $R$ contains a row of zeros. It follows that
  $\det(R)=0$, and therefore $\det(A)=0$.
\end{proof}

\begin{example}{Determinants and invertible matrices}{determinant-invertible}
  Determine which of the following matrices are invertible by
  computing their determinants.
  \begin{equation*}
    A = \begin{mymatrix}{rr}
      3 & 6 \\
      2 & 4 \\
    \end{mymatrix},\quad
    B = \begin{mymatrix}{rr}
      2 & 3 \\
      5 & 1 \\
    \end{mymatrix},\quad
    C = \begin{mymatrix}{rrr}
      1 & 2 & -5 \\
      2 & 0 & 2  \\
      3 & 1 & 0  \\
    \end{mymatrix}.
  \end{equation*}
\end{example}

\begin{solution}
  We have $\det(A) = 3\cdot 4 - 2\cdot 6 = 0$ and $\det(B) = 2\cdot
  1-5\cdot 3 = -13$. Therefore, $B$ is invertible and $A$ is not
  invertible. A quick way to compute the determinant of $C$ is to
  expand it along the third row. We have
  \begin{equation*}
    \det(C)
    = 3\begin{absmatrix}{rr}
      2 & -5 \\
      0 & 2 \\
    \end{absmatrix}
    - 1\begin{absmatrix}{rr}
      1 & -5 \\
      2 & 2 \\
    \end{absmatrix}
    = 3\cdot 4 - 1\cdot 12 = 0.
  \end{equation*}
  Therefore, $C$ is not invertible.
\end{solution}

As an application of Theorem~\ref{thm:determinant-invertible}, we note
that the determinant of an $n\times n$-matrix can be used to predict
whether a homogeneous system of equations has non-trivial solutions.

\begin{corollary}{Determinants and homogeneous systems}{determinant-homogeneous}
  Let $A$ be an $n\times n$-matrix. Then the homogeneous system
  $A\vect{v}=\vect{0}$ has non-trivial solutions if and only if $\det(A)=0$.
\end{corollary}

\begin{proof}
  We know from Theorem~\ref{thm:rank-homogeneous-solutions} that the
  homogeneous system has a non-trivial solution if and only if
  $\rank(A)<n$. This is the case if and only if $A$ is not invertible,
  i.e., if and only if $\det(A)=0$.
\end{proof}

Another reason the determinant is important is that it compatible with
matrix product.

\begin{theorem}{Determinant of a product}{determinant-of-product}
  Let $A$ and $B$ be $n\times n$-matrices. Then%
  \index{determinant!of product}%
  \index{matrix!determinant!of product}%
  \index{matrix!multiplication!determinant of product}%
  \index{multiplication!of matrices!determinant of product}%
  \begin{equation*}
    \det(AB) =\det(A)\det(B)
  \end{equation*}
\end{theorem}

\begin{proof}
  We first prove this in case $A=E$ is an elementary matrix. Remember
  from Section~\ref{sec:elementary-matrices} that elementary matrices
  correspond to elementary row operations.
  \begin{enumerate}
  \item If $E$ is an elementary matrix for swapping two rows, then
    $\det(E)=-1$. Also, by Theorem~\ref{thm:determinant-row-operations}(1),
    $\det(EB)=-\det(B)$. Therefore $\det(EB)=\det(E)\det(B)$.
  \item If $E$ is an elementary matrix for multiplying a row by a
    non-zero scalar $k$, then $\det(E)=k$. Also, by
    Theorem~\ref{thm:determinant-row-operations}(2),
    $\det(EB)=k\det(B)$. Therefore $\det(EB)=\det(E)\det(B)$.
  \item If $E$ is an elementary matrix for adding a multiple of one
    row to another, then $\det(E)=1$. Also, by
    Theorem~\ref{thm:determinant-row-operations}(3),
    $\det(EB)=\det(B)$. Therefore $\det(EB)=\det(E)\det(B)$.
  \end{enumerate}
  Now consider the case where $A$ is an arbitrary matrix. Case 1: $A$
  is invertible. Then by Theorem~\ref{thm:prod-elementary}, we can
  write $A$ as a product of elementary matrices $A=E_1E_2\cdots E_k$.
  By repeatedly using the formula $\det(EB)=\det(E)\det(B)$ that we
  proved above, we have
  \begin{equation*}
    \det(AB) = \det(E_1E_2\cdots E_kB) = \det(E_1)\det(E_2)\cdots\det(E_k)\det(B)
    = \det(A)\det(B).
  \end{equation*}
  Case 2: $A$ is not invertible. Then $AB$ is also not invertible
  (because if $C$ were an inverse of $AB$, we would have $ABC=I$, and
  therefore, $BC$ would be an inverse of $A$). Therefore, by
  Theorem~\ref{thm:determinant-invertible}, we have $\det(A)=0$ and
  $\det(AB)=0$. It follows that $\det(AB)=\det(A)\det(B)$.
\end{proof}

\begin{example}{The determinant of a product}{determinant-of-product}
  Compare $\det(AB)$ and $\det(A)\det(B)$, where
  \begin{equation*}
    A=\begin{mymatrix}{rr}
      1 & 2 \\
      -3 & 2
    \end{mymatrix}
    \quad\mbox{and}\quad
    B=\begin{mymatrix}{rr}
      3 & 2 \\
      4 & 1
    \end{mymatrix}.
  \end{equation*}
\end{example}

\begin{solution}
  We first compute $AB$:
  \begin{equation*}
    AB=\begin{mymatrix}{rr}
      1 & 2 \\
      -3 & 2
    \end{mymatrix} \begin{mymatrix}{rr}
      3 & 2 \\
      4 & 1
    \end{mymatrix} = \begin{mymatrix}{rr}
      11 & 4 \\
      -1 & -4
    \end{mymatrix}.
  \end{equation*}
  The three determinants are
  \begin{equation*}
    \det(AB) = \begin{absmatrix}{rr}
      11 & 4 \\
      -1 & -4
    \end{absmatrix} = -40,
    \quad
    \det(A) = \begin{absmatrix}{rr}
      1 & 2 \\
      -3 & 2
    \end{absmatrix} = 8,
    \quad\mbox{and}\quad
    \det(B) = \begin{absmatrix}{rr}
      3 & 2 \\
      4 & 1
    \end{absmatrix} = -5.
  \end{equation*}
  Therefore $\det(A)\det(B) = 8\cdot(-5) = -40 = \det(AB)$.
\end{solution}

The following proposition summarizes some properties of determinants we
have discussed so far, as well as additional properties.

\begin{proposition}{Properties of determinants}{properties-of-determinants}
  Let $A,B$ be $n\times n$-matrices. Then:%
  \index{determinant!properties of}%
  \index{properties of determinants}%
  \index{matrix!determinant!properties}%
  \index{matrix!properties of determinants}
  \begin{enumerate}
  \item $\det(AB)=\det(A)\det(B)$.
  \item $\det(I) = 1$.
  \item $A$ is invertible if and only if $\det(A)\neq 0$. Moreover, if
    this is the case, then
    \begin{equation*}
      \det(A^{-1}) = \frac{1}{\det(A)}.
    \end{equation*}
  \item $\det(kA)=k^n\det(A)$.
  \item $\det(A^T) = \det(A)$.
  \end{enumerate}
\end{proposition}

\begin{proof}
  Property 1 is a restatement of
  Theorem~\ref{thm:determinant-of-product}. Property 2 follows from
  Theorem~\ref{thm:determinant-of-triangular-matrix}, because the
  identity matrix is an upper triangular matrix. Property 3: The first
  part is Theorem~\ref{thm:determinant-invertible}. For the second
  part, assume $A$ is invertible. Then by properties 1 and 2,
  $\det(A)\det(A^{-1}) = \det(AA^{-1}) = \det(I) = 1$. The claim
  follows by dividing both sides of the equation by
  $\det(A)$. Property 4 follows from
  Theorem~\ref{thm:determinant-row-operations}(2), because $kA$ is
  obtained from $A$ by multiplying all $n$ rows by $k$. Each time we
  multiple one row by $k$, the determinant is multiplied by
  $k$. Property 5 follows because expanding $\det(A)$ along columns
  amounts to the same thing as expanding $\det(A^T)$ along rows.
\end{proof}

We end this section with a few useful ways of spotting matrices of
determinant 0.

\begin{theorem}{Special matrices with zero determinant}{special-determinant-zero}
  Let $A$ be an $n\times n$-matrix.
  \begin{enumerate}
  \item If $A$ has a row consisting only of zeros, or a column
    consisting only of zeros, then $\det(A)=0$.
  \item If $A$ has a row that is a scalar multiple of another row, or
    a column that is a scalar multiple of another column, then
    $\det(A)=0$.
  \end{enumerate}
\end{theorem}

\begin{proof}
  The first property follows by cofactor expansion: simply expand the
  determinant along the row or column that consists only of zeros.
  For the second property, assume that $A$ has a row that is a scalar
  multiple of another row. We can then perform an elementary row
  operation to create a row of zeros. By
  Theorem~\ref{thm:determinant-row-operations}(3), the determinant is
  unchanged, so that $\det(A)=0$. In the case that $A$ has a column
  that is a scalar multiple of another column, we apply the same
  reasoning to $A^T$ and use the fact that $\det(A)=\det(A^T)$.
\end{proof}


\section{Cycle}

%%%%%%%%%%%%%%%
\begin{frame}{Cycle detection}
  \begin{table}[ht]
    \centering
    \caption{Cycle detection \pno{3.4.21}}
    \begin{tabular}{c||c|c}
     \hline
     		& Digraph 			& Undirected graph  \\ \hline \hline
		DFS 	& back edge \textcolor{red}{$\iff$} cycle
			& back edge $\iff$ cycle
			\\ \hline
		BFS	& \begin{tabular}[c]{@{}l@{}}back edge $\Rightarrow$ cycle\\ cycle \textcolor{red}{$\nRightarrow$} back edge \end{tabular}
			& cross edge $\iff$ cycle
			\\ \hline
    \end{tabular}
  \end{table}
\end{frame}
%%%%%%%%%%%%%%%
\begin{frame}{Cycle detection}
  \begin{block}{Solution.}
    \begin{columns}[t]
      \column{0.50\textwidth}
	DFS on digraph: $\text{cycle} \Rightarrow \text{back edge}$
	\begin{figure}
	  \centering
	  \includegraphics[width=0.50\textwidth]{figures/dfs-digraph-cycle-detection-without-back.pdf}
	\end{figure}
      \column{0.50\textwidth}
	BFS on digraph: $\text{cycle} \nRightarrow \text{back edge}$
	\begin{figure}
	  \centering
	  \includegraphics[width=0.30\textwidth]{figures/bfs-digraph-cycle-without-back.png}
	\end{figure}
      \end{columns}
  \end{block}

  \begin{alertblock}{Remark.}
    \begin{itemize}
      \item cycle in undirected graphs (shortly)
      \item cycle in digraphs $\Rightarrow$ DAG, SCC
    \end{itemize}
  \end{alertblock}
\end{frame}
%%%%%%%%%%%%%%%
\begin{frame}{Edge deletion}
  \begin{exampleblock}{Edge deletion \pno{3.4.12}}
    \begin{itemize}
      \item Input: connected, undirected graph $G$
      \item Problem: $\exists? e \in E: G \setminus e$ is connected?
      \item $O(|V|)$
    \end{itemize}
  \end{exampleblock}

  \begin{block}{Solution.}
    cycle $\iff \exists e$:
    \begin{proof}
      \begin{itemize}
	\item $\Leftarrow$: by contradiction. connected + acyclic $\Rightarrow$ tree
      \end{itemize}
    \end{proof}

    tree: $|E| = |V| - 1$ $\Rightarrow$ check $|E| \ge |V|$
  \end{block}
\end{frame}
%%%%%%%%%%%%%%%
\begin{frame}{Orientation of undirected graph}
  \begin{exampleblock}{Orientation of undirected graph \pno{3.4.13}}
    Undirected (connected) graph $G$, edge oriented s.t. $\forall v, \text{in}[v] \ge 1$.
  \end{exampleblock}

  \begin{block}{Solution.}
    orientation $\iff$ $\exists$ cycle; DFS
  \end{block}
\end{frame}
%%%%%%%%%%%%%%%
\begin{frame}{Bipartite graph}
  \begin{exampleblock}{Bipartite graph \pno{3.4.26; 3.4.32}}
    To test bipartiteness of an undirected graph.
  \end{exampleblock}

  \begin{block}{Solution.}
    \begin{columns}
      \column{0.40\textwidth}
        BFS + Coloring:
	\begin{itemize}
	  \item pick any $s$, c[s] = 0
	  \item $u \gets \text{Dequeue}(Q)$
	  \item $\forall (u,v)$:
	    \begin{itemize}
	      \item tree edge
	      \item cross edge: \textcolor{red}{check}
	    \end{itemize}
	\end{itemize}
      \column{0.60\textwidth}
	\begin{proof}
	  Check cross edge $(u,v)$:
	  \begin{itemize}
	    \item ($\exists$) $d[v] = d[u]$ $\Rightarrow$ the same layer $\Rightarrow$ odd cycle (\pno{3.4.17}; \textcolor{red}{EX}) $\Rightarrow$ non-bipartite
	    \item ($\forall$) $d[v] = d[u] + 1$ $\Rightarrow$ different layers $\Rightarrow$ different colors
	  \end{itemize}
	\end{proof}
    \end{columns}
  \end{block}
\end{frame}
%%%%%%%%%%%%%%%


\section{Computational Methods and Software}
\label{sec:method}

\subsection{Equations (discretization and finite elements)}

We use the 3-D incompressible Navier-Stokes to model a
low-speed fluid flow with heat convection and diffusion and buoyancy.

\begin{align*}
    \bv{R}\left(\left[
    \begin{array}{l}
        \bv{u} \\
        p \\
        T
    \end{array}
    \right]\right) \equiv&
    \left[
    \begin{array}{l}
        \frac{\partial (\rho \bv{u})}{\partial t} + \rho \bv{u} \cdot
    \nabla \bv{u} + \nabla p - \mu \nabla^2 \bv{u} +
    \rho \beta_T (T - T_0) \bv{g} \\
    \nabla \cdot \bv{u} \\
    \frac{\partial (\rho c_p T)}{\partial t} + \rho c_p \bv{u} \cdot
    \nabla T - k \nabla^2 T
    \end{array}
    \right] = 0
\end{align*}

The Navier-Stokes equations are derived from conservation of mass,
momentum and energy, and are a highly reliable model for low-speed flows
of the sort encountered here. The boussinesq approximation for the
buoyancy is less generally applicable, but still accurate for a
wide variety of flows in nature, such as atmospheric fronts, oceanic
circulation, etc. The Boussinesq buoyancy approximation relies upon the
difference in density in the fluid being negligible except for gravitational
forces which are large enough to make the specific weight appreciably different
between the two fluids.

\subsection{Modeling the vanes}

Talk about penalty method here
% Be sure to pull out your old penalty method write up here.
% Will want to use an abridged version, and expand that in the full doc

\subsection{Software}

GRINS blurb (dont forget paper)

\subsection{Simulation geometry}

check out val doc here
dont forget to add wall spacing function to document

probably need to create a table of runs, perhaps that goes in results


\subsection{Statistical Analysis} \label{sec:tth_stat_analysis}
The measured parameters of interest (POIs), namely $\mu_{\ttH}$, are extracted by constructing a likelihood function which depends on these POIs and finding their values which maximize the likelihood function.
The likelihood function expresses the probability of the observed data, given the prediction taken from the signal and background model.
More precisely,
\begin{equation}
    \mathcal L (\text{data} ~|~ \mu_{\ttH}, \vec{\theta}) = \mathcal L \bigg(\text{data} ~\Big|~ \Big[ S(\mu_{\ttH}, \vec{\theta}) + B(\vec{\theta}) \Big] \times C(\vec{\theta}) \bigg),
\end{equation}
where $\vec{\theta}$ is the vector of nuisance parameters (i.e. those described in Sec.~\ref{sec:tth_systematic_uncertainties}) which are typically modeled as log-normal distributions (Eqn.~\ref{eqn:tth_log_normal}).

The fit is performed simultaneously in all signal regions; in other words, the likelihood function is a product of the likelihood functions for each signal region:
\begin{equation}
    \mathcal L (\text{data} ~|~ \mu_{\ttH}, \vec{\theta})
    =
    \prod_{i=1}^{N_{\text{SR}}} \mathcal L_i \bigg(\text{data}_i ~\Big|~ \Big[ S_i(\mu_{\ttH}, \vec{\theta}) + B_i(\vec{\theta}) \Big] \times C(\vec{\theta}) \bigg),
\end{equation}
where $N_{\text{SR}} = 8$ is the total number of signal regions and $\text{data}_i, S_I,$ and $B_i$ are the observed data, signal model, and background model in the $i$-th signal region, respectively.

Moreover, the likelihood function is discretized into bins of 0.25 GeV in the [100, 180] GeV region. The likelihood function in a particular signal region is then
\begin{equation}
    \mathcal L_i \bigg(\text{data}_i ~\Big|~ \Big[ S_i(\mu_{\ttH}, \vec{\theta}) + B_i(\vec{\theta}) \Big] \times C(\vec{\theta}) \bigg)
    =
    \prod_{j=1}^{N_\text{bins}} \text{Poisson}\Big( n_{i,j} ~\Big|~ \lambda_{i,j} \Big) \times C(\vec{\theta}),
\end{equation}
with $N_\text{bins} = 320$ the total number of bins per signal region, $n_{i,j}$ the number of observed data events in the $j$-th bin of the $i$-th signal region, and $\lambda_{i,j}$ the expected number of events in that bin
\begin{equation}
    \lambda_{i,j} = S_{i,j}(\mu_{\ttH}, \vec{\theta}) + B_{i,j}(\vec{\theta}),
\end{equation}
and Poisson indicates the standard Poisson distribution
\begin{equation}
    \text{Poisson}(n|\lambda)
    =
    \frac{\lambda^n e^{-\lambda}}{n!}.
\end{equation}
The bin size of 0.25 GeV is chosen with the characteristic diphoton mass resolution of 1.5-2 GeV in mind -- the bin size is sufficiently smaller than the resolution that the information lost by binning the data is negligible.

In practice, -2 times the natural logarithm of the likelihood function is nicer to work with from a numerical optimization point of view, and it is this quantity, referred to as the ``log-likelihood'', that is actually minimized in the fit:
\begin{equation}
    2\text{NLL} = -2 \ln(\mathcal L).
\end{equation}
In general, the fitted value $\hat{\mu}$ of a POI $\mu$ is called the maximum likelihood estimate (MLE) of $\mu$.

The log-likelihood also has desirable qualities for purposes of assessing the uncertainty on fitted POIs.
In particular, we may be interested in how much more likely a particular value of a POI $\mu$ is than its MLE $\hat{\mu}$, i.e. the uncertainty on the fitted value.
To this end, it is helpful to study the quantity
\begin{equation} \label{eqn:tth_likelihood_ratio}
    \lambda(\mu) = \frac{L(\mu, \hat{\vec{\theta}})}{L(\hat{\mu}, \hat{\hat{\vec{\theta}}})}
\end{equation}
where $\hat{\vec{\theta}}$ and $\hat{\hat{\vec{\theta}}}$ are the ML values of $\vec{\theta}$ for $\mu$ and $\hat{\mu}$, respectively.
The quantity $\lambda(\mu)$ is called the ``profile likelihood ratio'', and -2 times the logarithm of this quantity is called the ``log-likelihood ratio''.
A convenient property of the log-likelihood ratio is the fact that in the case of a single POI, it approximately follows a $\chi^2$ distribution with one degree of freedom~\cite{Cowan:2010js}.
For this reason, taking the square root of $\lambda(\mu)$ gives the Gaussian significance $Z$ associated with $\mu$~\cite{Cowan:2010js}, where
\begin{equation}
    Z \equiv \Phi^{-1} (1 - p),
\end{equation}
with $\Phi$ the Gaussian quantile function and $p$ the $p$-value.
The frequentist interpretation of $p$ is the following: in the limit of an infinite number of repeated, indepedent experiments in which the true value of the POI is $\hat{\mu}$, a value more extreme than $\mu$ would be obtained in $p$ percent of these.
The Gaussian significance $Z$ can be interpreted in the following way: a Gaussian-distributed variable found $Z$ standard deviations away from its mean value has an associated p-value of $p$.

Within this framework, we express the uncertainty on $\hat{\mu}$ in terms of the values of $\mu$ corresponding to a 68\% (1 standard deviation) CL\footnote{The choice of a 68\% CL as the default for expressing uncertainties is somewhat arbitrary, and could easily be chosen as some other value.}, namely the values of $\mu$ which give $\lambda(\mu) = 1$.
Another value of $\mu$ of particular interest is $\mu = 0$, corresponding to the case of the background-only hypothesis.
The associated significance $Z = \sqrt{\lambda(0)}$ is said to be the significance with which the signal has been observed, with $Z=5$ taken as the threshold for claiming discovery.

\subsection{Cross Section, Signal Strength, \& Significance}
The observed diphoton mass distributions in the eight signal regions are nicely summarized in a couple plots in Fig.~\ref{fig:tth_obs_sr_weighted}, which shows the weighted and unweighted sums of the distributions from each signal region.
In the case of the weighted sum, the distribution from each signal region is weighted by the factor $S / (S + B)$, giving higher weight to regions with higher purity.
$S$ and $B$ are the signal and background yields, defined as the total number of \Hgg events and the total number of non-resonant background events, respectively.
\begin{figure} [htbp!]
    \centering
    \begin{tabular} {c c}
        \includegraphics[width=0.48\linewidth]{figures/tth/examplecombcat_weighted.pdf} &
        \includegraphics[width=0.48\linewidth]{figures/tth/examplecombcat_unweighted.pdf}
    \end{tabular}
    \caption{Weighted (left) and unweighted (right) sum of observed diphoton mass distributions for all of the signal regions. Events from each signal region are weighted by the respective $S / (S +B)$ of that category in the case of the weighted sum. Taken from ~\cite{tth_observation}.}
    \label{fig:tth_obs_sr_weighted}
\end{figure}

The diphoton mass distributions for each of the eight signal regions are shown individually in Appendix~\ref{app:sr_mgg}.

The observed MLE of $\mu_{\ttH}$ is obtained from minimization of 2NLL of the likelihood function defined in Sec.~\ref{sec:tth_stat_analysis} and is found to be 1.38.
The 68\% CL for $\hat{\mu}_{\ttH}$ is obtained from constructing the log-likelihood ratio defined in Eqn.~\ref{eqn:tth_likelihood_ratio} as a function of $\mu_{\ttH}$ and is found to be $1.38^{+0.36}_{-0.29}$.
The log-likelihood ratio is shown in Fig.~\ref{fig:tth_llr}.

\begin{figure} [htbp!]
    \centering
    \includegraphics[width=0.95\linewidth]{figures/tth/MuScanProfileMH.pdf}
    \caption{Log-likelihood ratio for $\mu_{\ttH}$. The expected distribution, assuming the SM signal strength $\mu_{\ttH} = 1$, is shown in the green dotted line. The observed distribution is shown with full uncertainties (only statistical uncertainty) in the blue (red) lines. Taken from~\cite{tth_observation}.}
    \label{fig:tth_llr}
\end{figure}

The observed cross-section times branching fraction of the \ttH (\Hgg) process is found to be $\sigma_{\ttH} \mathcal B(\text{H} \to \gamma \gamma) = 1.56^{+0.34}_{-0.32}$ fb, while the SM prediction is $\sigma_{\ttH} \mathcal B(\text{H} \to \gamma \gamma) = 1.13^{+0.08}_{-0.11}$ fb.

In addition to the MLE of $\mu_{\ttH}$ and its uncertainty, we are interested in the significance of the observation: the difference between the log-likelihood ratio evaluated at the MLE of $\mu_{\ttH} = \hat{\mu}_{\ttH}$ and $\mu_{\ttH} = 0$, the case of the background-only hypothesis.
The observed significance, relative to the background-only hypothesis, is 6.6 standard deviations, while the expected significance is 4.7 standard deviations.
With a discovery threshold of 5 standard deviations, we are able to claim observation of the \ttH (\Hgg) process.
The observed and expected results for the cross section, signal strength, and significance are shown in Table~\ref{tab:tth_results}.
\begin{table} [htbp!]
    \centering
    \caption{Expected and observed values of the cross section times branching fraction ($\sigma_{\ttH} \mathcal B(\text{H} \to \gamma \gamma)$), signal strength ($\mu_{\ttH}$), and significance.}
    \begin{tabular}{r c c} \hline \hline
        Quantity & Expected Value & Observed Value \\ \hline
        $\sigma_{\ttH} \mathcal B(\text{H} \to \gamma \gamma)$ & $1.13$ fb & $1.56^{+0.34}_{-0.32}$ fb \\
        $\mu_{\ttH}$ & $1.00$ & $1.38^{+0.36}_{-0.29}$ \\
        Significance & $4.7\sigma$ & $6.6\sigma$ \\ \hline \hline
    \end{tabular}
    %\caption{Expected and observed values of the cross section times branching fraction ($\sigma_{\ttH} \mathcal B(\text{H} \to \gamma \gamma)$), signal strength ($\mu_{\ttH}$), and significance.}
    \label{tab:tth_results}
\end{table}

\subsection{CP Measurement}
In addition to measuring the cross section and signal strength of the \ttH (\Hgg) process, the CP structure of the tree-level top quark Yukawa (Htt) coupling can also be tested.
The SM predicts that the Htt coupling is purely CP-even; any non-zero CP-odd component of the coupling would be an indication of new physics.

A parametrization of the CP structure of the Htt amplitude can be given in terms of CP-even and CP-odd components~\cite{Gritsan:2016hjl}:\begin{equation}
    A(\text{Htt}) = - \frac{m_t}{v} \bar{\psi}_t \Big (\kappa_t + i \tilde{\kappa}_t \gamma_5 \Big) \psi_t,
\end{equation}
where $\kappa_t$ and $\tilde{\kappa}_t$ represent the CP-even and CP-odd couplings, respectively, and $v$ represents the SM Higgs field VEV.
As the SM predicts a purely CP-even Htt coupling, this implies the SM prediction of $\kappa_t = 1$ and $\tilde{\kappa}_t = 0$.
The fractional CP-odd component is defined as
\begin{equation}
    f^{\text{Htt}}_{\text{CP}} = \frac{|\tilde{\kappa}_t|^2}{|\kappa_t|^2 + |\tilde{\kappa}_t|^2}~\text{sign}(\tilde{\kappa}_t/\kappa_t),
\end{equation}
and this is the physical observable constrained by the \ttH (\Hgg) analysis~\cite{tth_observation}.

The CP measurement is performed by starting with signal categories defined by the BDT-bkg algorithm detailed in Sec.~\ref{sec:tth_mvas}.
Next, BDTs, referred to as the $\mathcal D_{0-}$ discriminants, are trained to distinguish between CP-even and CP-odd scenarios for the Htt coupling.
This is achieved by first simulating \ttH samples with anomalous couplings, including samples of pure CP-even (SM-like), pure CP-odd, and a mixture of the two.
These samples are generated at leading order with the \textsc{JHUGen} 7.0.2 software package and reweighted with the MELA matrix element library~\cite{Gritsan:2016hjl,Gao:2010qx,Bolognesi:2012mm,Anderson:2013afp}.
The $\mathcal D_{0-}$ BDTs are trained on the kinematic features described in Sec.~\ref{sec:tth_hlf}, with a separate BDT for the hadronic and the leptonic channels, just as for the BDT-bkg algorithm.
In both the hadronic and leptonic channels, two signal categories are formed with requirements on the output of BDT-bkg, with the boundaries shown in Fig.~\ref{fig:tth_bdt-bkg}.
Each of these signal categories is further divided into three signal regions, chosen to maximize the expected sensitivity to $f^{\text{Htt}}_{\text{CP}}$, giving 12 total signal categories for the CP measurement.

As for the cross section and signal strength measurements, $f^{\text{Htt}}_{\text{CP}}$ is constrained with a simultaneous fit to the diphoton invariant mass spectrum in all 12 signal categories.
Fig.~\ref{fig:tth_cp} shows the results of this fit, which are consistent with the SM prediction of $f^{\text{Htt}}_{\text{CP}} = 0$.
\begin{figure} [htbp!]
    \centering
    \includegraphics[width=\linewidth]{figures/tth/Figure_003.png}
    \caption{Distribution of events, weighted by S/(S+B), selected for the CP measurement of the Htt coupling. Events from both BDT-bkg categories in both the hadronic and leptonic channels are shown in each $\mathcal D_{0-}$ bin. The background contribution is subtracted from each bin. The likelihood scan for $f^{\text{Htt}}_{\text{CP}}$ is displayed in the inner panel. Taken from~\cite{tth_observation}.}
    \label{fig:tth_cp}
\end{figure}
The observed (expected) constraint on the CP structure of the Htt coupling is $f^{\text{Htt}}_{\text{CP}} = 0.00 \pm 0.33 (0.00 \pm 0.49)$ at 68\% CL.
The observed (expected) significance with which the pure CP-odd model is excluded is $3.2\sigma (2.6\sigma)$.
An additional systematic uncertainty is introduced for the CP measurement to account for potential differences in kinematic distributions obtained through the \textsc{JHUGen} generator and the \textsc{MadGraph} generator used to model the SM processes, though the uncertainty in the measurement is still dominated by the statistical uncertainty.

Thus, the measurement of the CP structure of the Htt coupling is found to be consistent with the SM value of $f^{\text{Htt}}_{\text{CP}} = 0$.


\section{Dynamic Programming}

DP are effective for medium size problems (million of states).

\subsection{Policy Evaluation (Prediction)}

If $P$ and $\pi$ are known, Bellman equation (\ref{bellman:v}) could be converted to iterative solution. All $V$ are randomly initialized and updated using \cindex{iterative policy evaluation}:

\begin{equation}
	V_{k+1} (s) = \sum_a \pi (a | s) \left ( \sum_{s',r} p(s',r | s,a) \Big ( r + \gamma V_{k}(s') \Big ) \right )
\end{equation}

Here $V_{t+1}(s)$ means the value of $V(s)$ in $(t+1)$ round.

There are two ways to update $V_{t+1}(s)$:
\begin{itemize}
	\item copy $V_{t+1}(s)$ to a new array and update original array when sweeping is done
	\item \cindex{in-place} update: update $V(s)$ on the fly. updated value may be used immediately so it is faster than two array solution.
\end{itemize}

The problem is that iterative algorithm \cindex{sweep} through all state space, which might not be practical.

See Algorithm (\ref{algo:itepole}) for detail.

\begin{algorithm}
	\caption{Iterative policy evaluation, estimate $V_\pi$}\label{algo:itepole}

	\begin{algorithmic}[1]
		\Procedure{}{$\pi, p, \theta$}
			\State $\forall s \in S, V(s) \gets random$
			\State $V(terminal) \gets 0$
			\Repeat
				\State $\Delta \gets 0$
				\For{$s \in S$}
					\State $v \gets V(s)$
					\State \Comment{in-place update}
					\State $V(s) \gets \sum\limits_a \pi (a | s) \left ( \sum\limits_{s',r} p(s',r | s,a) \big(r + \gamma V(s') \big ) \right )$
					\State $\Delta \gets \max{}(v, |v - V(s)|)$
				\EndFor
			\Until{$\Delta < \theta$}
		\EndProcedure
	\end{algorithmic}

\end{algorithm}

\subsection{Policy Improvement}

The reason for calculating value function is to help find a better policy. A new greedy policy $\pi^{\prime}$ could be calculated using:

\begin{equation}
	\begin{aligned}
		\pi^{\prime}(s) &= \underset{a \in \mathcal{A}(s)}{\text{argmax}} \ q_{\pi}(s,a)\\
		&=\underset{a \in \mathcal{A}(s)}{\text{argmax}}\ \sum_{s',r} p(s',r|s,a)\Big ( r+\gamma V(s') \Big )
	\end{aligned}
\end{equation}

A series of policy evaluation and improvement will converge to optimal result, and its conversion is very fast.

The drawback is that every iteration may trigger evaluation, which involves multiple sweep through all state space.

See Algorithm (\ref{algo:polite}) for detail.

\begin{algorithm}
	\caption{Policy Iteration, estimate $V_*$ and $\pi_*$}\label{algo:polite}

	\begin{algorithmic}[1]
		\State $\forall s \in \mathcal{S}, V(s) \gets random$
		\State $V(terminal) \gets 0$
		\State $\pi(s) \gets \text{random}(\mathcal{A}(s))$

		\Statex

		\Procedure{PolicyEvaluation}{$\varepsilon$}
			\Repeat
				\State $\Delta \gets 0$
				\For{$s \in \mathcal{S}$}
					\State $v \gets V(s)$
					\State $V(s) \gets \sum\limits_{s',r} p(s',r|s,\pi(s))\big (r+\gamma V(s') \big )$ \Comment{$\pi(s)$ : use optimal policy}
					\State $\Delta \gets \max (\Delta, |v - V(s)|)$
				\EndFor
			\Until{$\Delta < \varepsilon$}
		\EndProcedure

		\Statex

		\Procedure{PolicyImprovement}{}
			\State $\text{stable} \gets \text{TRUE}$
			\For{$s \in \mathcal{S}$}
				\State $old \gets \pi(s)$
				\State $\pi(s) \gets \underset{a \in \mathcal{A}(s)}{\text{argmax}}\ \sum\limits_{s',r}P(s',r|s,a) \big (r+\gamma V(s') \big )$
				\If{$old \neq \pi(s)$}
					\State $\text{stable} \gets \text{FALSE}$
				\EndIf
			\EndFor
			\If{$\text{stable}$}
				\Return $(V_*,\pi_*)$
			\Else
				\State \Call{PolicyEvaluation}{$\varepsilon$} \Comment{update $V$ if optimal policy has changed}
			\EndIf
		\EndProcedure
	\end{algorithmic}
\end{algorithm}

\subsection{Value Iteration}

In policy iteration, multiple sweep can be reduce to one by taking the best action, and calculate optimal policy using (\ref{optimal:policy}):

\begin{equation}
	\begin{aligned}
		V_{k+1}^{old} (s) &= \sum_{s',r} p(s',r|s,\pi(s))\big (r+\gamma V_k(s') \big ) \\
		V_{k+1}^{new} (s) &= \underset{a}{\max} \sum_{s',r} p(s',r|s,a) \big (r+\gamma V_k(s') \big )
	\end{aligned}
\end{equation}

See Algorithm (\ref{algo:valite}) for detail.

\begin{algorithm}
	\caption{Value Iteration, estimate $\pi_*$}\label{algo:valite}

	\begin{algorithmic}[1]
		\State $\forall s \in S, V(s) \gets random$
		\State $V(terminal) \gets 0$

		\Statex

		\Repeat
			\State $\Delta \gets 0$
			\For{$s \in S$}
				\State $v \gets V(s)$
				\State \Comment policy evaluation and improvement
				\State $V(s) \gets \underset{a}{\max}\ \sum\limits_{s',r} p(s',r|s,a) \big ( r+\gamma V(s') \big )$
				\State $\Delta \gets \max (\Delta, |v - V(s)|)$
			\EndFor
		\Until{$\Delta < \theta$}

		\State \Return $\pi_*(s)= \underset{a}{\text{argmax}} \ \sum\limits_{s',r} p(s',r|s,a) \big (r+\gamma V(s') \big )$
	\end{algorithmic}
\end{algorithm}

\subsection{Generalized Policy Iteration}

\cindex{Generalized Policy Iteration} (GPI) is a series of evaluation and improvement process. Almost all reinforcement learning methods are GPI.

\subsection{Performance}

DP is exponentially faster than direct \cindex{policy space search}.

DP is better than \cindex{linear programming methods} for large problem, but worse for small problem.

The \cindex{curse of dimension} is not the problem of algorithm but the problem itself.

The time complexity for $v$ is $O(mn^2)$ and for $q$ is $O(m^2 n^2)$, where $m$ is the number of action and $n$ is the number of state. So DP is effective for medium size problems (million of states).

\subsection{Extension to Sweeping}

\subsubsection{Prioritized Sweeping}

backup the state with the maximum \cindex{Bellman error}:
\begin{equation}
	\left| \max_{ a \in \mathcal{A}} \left( \mathcal{R}
	+ \gamma \sum_{s' \in S} \mathcal{P}_{ss'}^a v(s') \right) - v(s) \right|
\end{equation}

\subsubsection{Realtime Dynamic Programming}

Choose the state that are relevant to agent.


\startcomponent ma-cb-en-mathcharacters

\product ma-cb-en

\chapter[overviews]{Commands in math mode}

\index{symbols in math mode}

\section{Greek characters}

\starttabulate[|l|l|l|l|l|l|l|l|l|]
\NC           \NC $\alpha$      \NC \type{\alpha}
\NC           \NC $\iota$       \NC \type{\iota}
\NC           \NC $\varrho$     \NC \type{\varrho}    \NC\NR
\NC           \NC $\beta$       \NC \type{\beta}
\NC           \NC $\kappa$      \NC \type{\kappa}
\NC $\Sigma$  \NC $\sigma$      \NC \type{\sigma}     \NC\NR
\NC $\Gamma$  \NC $\gamma$      \NC \type{\gamma}
\NC $\Lambda$ \NC $\lambda$     \NC \type{\lambda}
\NC           \NC $\varsigma$   \NC \type{\varsigma}  \NC\NR
\NC $\Delta$  \NC $\delta$      \NC \type{\delta}
\NC           \NC $\mu$         \NC \type{\mu}
\NC           \NC $\tau$        \NC \type{\tau}       \NC\NR
\NC           \NC $\epsilon$    \NC \type{\epsilon}
\NC           \NC $\nu$         \NC \type{\nu}
\NC           \NC $\upsilon$    \NC \type{\upsilon}   \NC\NR
\NC           \NC $\varepsilon$ \NC \type{\varepsilon}
\NC $\Xi$     \NC $\xi$         \NC \type{\xi}
\NC $\Phi$    \NC $\phi$        \NC \type{\phi}       \NC\NR
\NC           \NC $\zeta$       \NC \type{\zeta}
\NC           \NC $o$           \NC \type{o}
\NC           \NC $\varphi$     \NC \type{\varphi}    \NC\NR
\NC           \NC $\eta$        \NC \type{\eta}
\NC $\Pi$     \NC $\pi$         \NC \type{\pi}
\NC           \NC $\chi$        \NC \type{\chi}       \NC\NR
\NC $\Theta$  \NC $\theta$      \NC \type{\theta}
\NC           \NC $\varpi$      \NC \type{\varpi}
\NC $\Psi$    \NC $\psi$        \NC \type{\psi}       \NC\NR
\NC           \NC $\vartheta$   \NC \type{\vartheta}
\NC           \NC $\rho$        \NC \type{\rho}
\NC $\Omega$  \NC $\omega$      \NC \type{\omega}     \NC\NR
\stoptabulate

\section{Special symbols}

\starttabulate[|l|l|l|l|l|l|]
\NC $\aleph$       \NC \type{\aleph}
\NC $\prime$       \NC \type{\prime}
\NC $\forall$      \NC \type{\forall}
\NC\NR
\NC $\hbar$        \NC \type{\hbar}
\NC $\emptyset$    \NC \type{\emptyset}
\NC $\exists$      \NC \type{\exists}
\NC\NR
\NC $\imath$       \NC \type{\imath}
\NC $\nabla$       \NC \type{\nabla}
\NC $\neg$         \NC \type{\neg}
\NC\NR
\NC $\jmath$       \NC \type{\jmath}
\NC $\surd$        \NC \type{\surd}
\NC $\flat$        \NC \type{\flat}
\NC\NR
\NC $\ell$         \NC \type{\ell}
\NC $\top$         \NC \type{\top}
\NC $\natural$     \NC \type{\natural}
\NC\NR
\NC $\wp$          \NC \type{\wp}
\NC $\bot$         \NC \type{\bot}
\NC $\sharp$       \NC \type{\sharp}
\NC\NR
\NC $\Re$          \NC \type{\Re}
\NC $\Vert$        \NC \type{\Vert}
\NC $\clubsuit$    \NC \type{\clubsuit}
\NC\NR
\NC $\Im$          \NC \type{\Im}
\NC $\angle$       \NC \type{\angle}
\NC $\diamondsuit$ \NC \type{\diamondsuit}
\NC\NR
\NC $\partial$     \NC \type{\partial}
\NC $\triangle$    \NC \type{\triangle}
\NC $\heartsuit$   \NC \type{\heartsuit}
\NC\NR
\NC $\infty$       \NC \type{\infty}
\NC $\backslash$   \NC \type{\backslash}
\NC $\spadesuit$   \NC \type{\spadesuit}
\NC\NR
\stoptabulate

\section{Operators in addition to $+$, $-$ and $*$}

\starttabulate[|l|l|l|l|l|l|]
\NC $\pm$              \NC \type{\pm}
\NC $\cap$             \NC \type{\cap}
\NC $\vee$             \NC \type{\vee}
\NC\NR
\NC $\mp$              \NC \type{\mp}
\NC $\cup$             \NC \type{\cup}
\NC $\wedge$           \NC \type{\wedge}
\NC\NR
\NC $\setminus$        \NC \type{\setminus}
\NC $\uplus$           \NC \type{\uplus}
\NC $\oplus$           \NC \type{\oplus}
\NC\NR
\NC $\cdot$            \NC \type{\cdot}
\NC $\sqcap$           \NC \type{\sqcap}
\NC $\ominus$          \NC \type{\ominus}
\NC\NR
\NC $\times$           \NC \type{\times}
\NC $\sqcup$           \NC \type{\sqcup}
\NC $\otimes$          \NC \type{\otimes}
\NC\NR
\NC $\ast$             \NC \type{\ast}
\NC $\triangleleft$    \NC \type{\triangleleft}
\NC $\oslash$          \NC \type{\oslash}
\NC\NR
\NC $\star$            \NC \type{\star}
\NC $\triangleright$   \NC \type{\triangleright}
\NC $\odot$            \NC \type{\odot}
\NC\NR
\NC $\diamond$         \NC \type{\diamond}
\NC $\wr$              \NC \type{\wr}
\NC $\dagger$          \NC \type{\dagger}
\NC\NR
\NC $\circ$            \NC \type{\circ}
\NC $\bigcirc$         \NC \type{\bigcirc}
\NC $\ddagger$         \NC \type{\ddagger}
\NC\NR
\NC $\bullet$          \NC \type{\bullet}
\NC $\bigtriangleup$   \NC \type{\bigtriangleup}
\NC $\amalg$           \NC \type{\amalg}
\NC\NR
\NC $\div$             \NC \type{\div}
\NC $\bigtriangledown$ \NC \type{\bigtriangledown}
\NC ~                  \NC ~
\NC\NR
\stoptabulate

\section{Operators}

\starttabulate[|l|l|l|l|l|l|]
\NC $\sum$       \NC \type{\sum}
\NC $\prod$      \NC \type{\prod}
\NC $\coprod$    \NC \type{\coprod}
\NC\NR
\NC $\int$       \NC \type{\int}
\NC $\oint$      \NC \type{\oint}
\NC $\bigcap$    \NC \type{\bigcap}
\NC\NR
\NC $\bigcup$    \NC \type{\bigcup}
\NC $\bigsqcup$  \NC \type{\bigsqcup}
\NC $\bigvee$    \NC \type{\bigvee}
\NC\NR
\NC $\bigwedge$  \NC \type{\bigwedge}
\NC $\bigodot$   \NC \type{\bigodot}
\NC $\bigotimes$ \NC \type{\bigotimes}
\NC\NR
\NC $\bigoplus$  \NC \type{\bigoplus}
\NC $\biguplus$  \NC \type{\biguplus}
\NC              \NC
\NC\NR
\stoptabulate

\section{Relation in addition to $>$, $<$ and $=$}

\starttabulate[|l|l|l|l|l|l|]
\NC $\leq$        \NC \type{\leq}
\NC $\geq$        \NC \type{\geq}
\NC $\equiv$      \NC \type{\equiv}
\NC\NR
\NC $\prec$       \NC \type{\prec}
\NC $\succ$       \NC \type{\succ}
\NC $\sim$        \NC \type{\sim}
\NC\NR
\NC $\preceq$     \NC \type{\preceq}
\NC $\succeq$     \NC \type{\succeq}
\NC $\simeq$      \NC \type{\simeq}
\NC\NR
\NC $\ll$         \NC \type{\ll}
\NC $\gg$         \NC \type{\gg}
\NC $\asymp$      \NC \type{\asymp}
\NC\NR
\NC $\subset$     \NC \type{\subset}
\NC $\supset$     \NC \type{\supset}
\NC $\approx$     \NC \type{\approx}
\NC\NR
\NC $\subseteq$   \NC \type{\subseteq}
\NC $\supseteq$   \NC \type{\supseteq}
\NC $\cong$       \NC \type{\cong}
\NC\NR
\NC $\sqsubseteq$ \NC \type{\sqsubseteq}
\NC $\sqsupseteq$ \NC \type{\sqsupseteq}
\NC $\bowtie$     \NC \type{\bowtie}
\NC\NR
\NC $\in$         \NC \type{\in}
\NC $\ni$         \NC \type{\ni}
\NC $\propto$     \NC \type{\propto}
\NC\NR
\NC $\vdash$      \NC \type{\vdash}
\NC $\dashv$      \NC \type{\dashv}
\NC $\models$     \NC \type{\models}
\NC\NR
\NC $\smile$      \NC \type{\smile}
\NC $\mid$        \NC \type{\mid}
\NC $\doteq$      \NC \type{\doteq}
\NC\NR
\NC $\frown$      \NC \type{\frown}
\NC $\parallel$   \NC \type{\parallel}
\NC $\perp$       \NC \type{\perp}
\NC\NR
\stoptabulate

\section{Negated relations}

\starttabulate[|l|l|l|l|l|l|]
\NC $\not<$           \NC \type{\not}\type{<}
\NC $\not>$           \NC \type{\not}\type{>}
\NC $\not=$           \NC \type{\not}\type{=}
\NC\NR
\NC $\not\leq$        \NC \type{\not}\type{\leq}
\NC $\not\geq$        \NC \type{\not}\type{\geq}
\NC $\not\equiv$      \NC \type{\not}\type{\equiv}
\NC\NR
\NC $\not\prec$        \NC \type{\not}\type{\prec}
\NC $\not\succ$        \NC \type{\not}\type{\succ}
\NC $\not\sim$         \NC \type{\not}\type{\sim}
\NC\NR
\NC $\not\preceq$      \NC \type{\not}\type{\preceq}
\NC $\not\succeq$      \NC \type{\not}\type{\succeq}
\NC $\not\simeq$       \NC \type{\not}\type{\simeq}
\NC\NR
\NC $\not\subset$      \NC \type{\not}\type{\subset}
\NC $\not\supset$      \NC \type{\not}\type{\supset}
\NC $\not\approx$      \NC \type{\not}\type{\approx}
\NC\NR
\NC $\not\subseteq$    \NC \type{\not}\type{\subseteq}
\NC $\not\supseteq$    \NC \type{\not}\type{\supseteq}
\NC $\not\cong$        \NC \type{\not}\type{\cong}
\NC\NR
\NC $\not\sqsubseteq$  \NC \type{\not}\type{\sqsubseteq}
\NC $\not\sqsupseteq$  \NC \type{\not}\type{\sqsupseteq}
\NC $\not\asymp$       \NC \type{\not}\type{\asymp}
\NC\NR
\stoptabulate

\section{Some arrows}

\starttabulate[|l|l|l|l|l|l|]
\NC $\leftarrow$          \NC \type{\leftarrow}
\NC $\longleftarrow$      \NC \type{\longleftarrow}
\NC $\uparrow$            \NC \type{\uparrow}
\NC\NR
\NC $\Leftarrow$          \NC \type{\Leftarrow}
\NC $\Longleftarrow$      \NC \type{\Longleftarrow}
\NC $\Uparrow$            \NC \type{\Uparrow}
\NC\NR
\NC $\rightarrow$         \NC \type{\rightarrow}
\NC $\longrightarrow$     \NC \type{\Rightarrow}
\NC $\downarrow$          \NC \type{\downarrow}
\NC\NR
\NC $\Rightarrow$         \NC \type{\Rightarrow}
\NC $\Longrightarrow$     \NC \type{\Longrightarrow}
\NC $\Downarrow$          \NC \type{\Downarrow}
\NC\NR
\NC $\leftrightarrow$     \NC \type{\leftrightarrow}
\NC $\longleftrightarrow$ \NC \type{\longleftrightarrow}
\NC $\updownarrow$        \NC \type{\updownarrow}
\NC\NR
\NC $\Leftrightarrow$     \NC \type{\Leftrightarrow}
\NC $\Longleftrightarrow$ \NC \type{\Longleftrightarrow}
\NC $\Updownarrow$        \NC \type{\Updownarrow}
\NC\NR
\NC $\mapsto$             \NC \type{\mapsto}
\NC $\longmapsto$         \NC \type{\longmapsto}
\NC $\nearrow$            \NC \type{\nearrow}
\NC\NR
\NC $\searrow$            \NC \type{\searrow}
\NC $\swarrow$            \NC \type{\swarrow}
\NC $\nwarrow$            \NC \type{\nwarrow}
\NC\NR
\NC $\hookleftarrow$      \NC \type{\hookleftarrow}
\NC $\hookrightarrow$     \NC \type{\hookrightarrow}
\NC ~ \NC ~
\NC\NR
\stoptabulate

\section{Alternative commands}

\starttabulate[|l|l|l|l|l|l|l|l|l|l|]
\NC $\ne$   \NC \type{\ne}
\NC $\{$    \NC {\tttf\leftargument}
\NC $\land$ \NC \type{\land}
\NC $\to$   \NC \type{\to}
\NC $\vert$ \NC \type{\vert}
\NC\NR
\NC $\le$   \NC \type{\le}
\NC $\}$    \NC {\tttf\rightargument}
\NC $\lor$  \NC \type{\lor}
\NC $\gets$ \NC \type{\gets}
\NC $\Vert$ \NC \type{\Vert}
\NC\NR
\NC $\ge$   \NC \type{\ge}
\NC $\owns$ \NC \type{\owns}
\NC $\lnot$ \NC \type{\lnot}
\NC \NC
\NC \NC
\NC\NR
\stoptabulate

\stopcomponent