\subsection{Functors}\label{subsec:functors}

\begin{definition}\label{def:functor}\mcite[def. 1.2.1 \\ def. 1.2.10]{Leinster2016Basic}
  Fix some \hyperref[def:category]{categories} \( \cat{C} \) and \( \cat{D} \). A \term{functor} \( F: \cat{C} \to \cat{D} \) is a \hyperref[eq:def:category_of_small_quivers/homomorphism]{quiver homomorphism} between the underlying quivers that is compatible with composition and identities.

  Explicitly, a functor is a family of functions
  \begin{equation}\label{eq:def:functor_as_family_of_function}
    \begin{aligned}
      F_{\obj}:       &\obj(\cat{C}) \to \obj(\cat{D}) \\
      F_{\hom(A, B)}: &\cat{C}(A, B) \to \cat{D}(F_{\obj}(A), F_{\obj}(B)),
    \end{aligned}
  \end{equation}
  where \( F_{\hom(A, B)} \) is a distinct function for every pair of objects \( A \) and \( B \).

  In practice, we usually define the functor as the set
  \begin{equation}\label{eq:def:functor_as_single_function}
    F \coloneqq F_{\obj} \cup \bigcup\set{ F_{\hom(A, B)} \given A, B \in \obj(\cat{C}) }
  \end{equation}

  Since the domains of all constituent functions are disjoint, \( F \) is again a total single-valued function. This allows us to justify the notation \( F(A) \) for objects and \( F(f) \) for morphisms.

  \begin{thmenum}[resume=def:functor]
    \thmitem{def:functor/domain_and_codomain} We say that the category \( \cat{C} \) is the \term{domain} and \( \cat{D} \) --- the \term{codomain} of the functor \( F \). These are technically not the domain and codomain of \( F \) when regarded as a function, however it is consistent with \fullref{def:category_of_small_categories}.

    \thmitem{def:functor/endofunctor} Similarly to \fullref{def:multi_valued_function/endofunction} for functions, if the domain \( \cat{C} \) and codomain \( \cat{D} \) of a functor coincide, we say that it is an \term{endofunctor}.
  \end{thmenum}

  The definition of a functor additionally requires the following compatibility conditions to hold:
  \begin{thmenum}[series=def:functor]
    \thmitem[def:functor/CF1]{CF1} Functors must preserve identities, meaning that for any object \( A \in \cat{C} \) the following equality must hold:
    \begin{equation}\label{eq:def:functor/CF1}\tag{\logic{CF1}}
      F(\id_A) = \id_{F(A)}.
    \end{equation}

    \thmitem[def:functor/CF2]{CF2} Functors must preserve composition, meaning that for any pair of morphism \( f: A \to B \) and \( g: B \to C \) in \( \cat{C} \),
    \begin{equation}\label{eq:def:functor/CF2}\tag{\logic{CF2}}
      F(g \bincirc f) = F(g) \bincirc F(f).
    \end{equation}
  \end{thmenum}
\end{definition}
\begin{defproof}
  The definition \eqref{eq:def:functor_as_family_of_function} ensures that the quiver homomorphism conditions \eqref{eq:def:category_of_small_quivers/homomorphism/head} and \eqref{eq:def:category_of_small_quivers/homomorphism/tail} hold.

  Indeed, for any morphism \( f: A \to B \) in \( \cat{C} \) we have
  \begin{equation*}
    F(\dom(f)) = F(A) = \dom(F(f)),
  \end{equation*}
  which implies \eqref{eq:def:category_of_small_quivers/homomorphism/head}. We also have
  \begin{equation*}
    F(\co\dom(f)) = F(B) = \co\dom(F(f)),
  \end{equation*}
  which implies \eqref{eq:def:category_of_small_quivers/homomorphism/tail}.
\end{defproof}

\begin{remark}\label{rem:functor_size}
  It is possible that \( \cat{C} \) is \( \mscrU \)-small in the sense of \fullref{def:category_size}, but the \hyperref[def:functor]{functor} \( F \), as the set \eqref{eq:def:functor_as_single_function}, is not \( \mscrU \)-small in the sense of \fullref{def:large_and_small_sets}. Without using universes, we cannot prove the existence of any functor from the category of smalls sets to itself, for example.
\end{remark}

\begin{example}\label{ex:unary_functors_in_set}
  In \fullref{def:basic_set_operations}, we defined some operations on the category \hyperref[def:category_of_small_sets]{\( \cat{Set} \)} of small sets.

  \begin{thmenum}
    \thmitem{ex:unary_functors_in_set/power} The \hyperref[def:basic_set_operations/power_set]{power set} \( \pow: \cat{Set} \to \cat{Set} \) is a canonical example of an \hyperref[def:functor/endofunctor]{endofunctor}. Explicitly:
    \begin{equation*}
      \begin{aligned}
        &\pow: \cat{Set} \to \cat{Set}, \\
        &\pow(A) \coloneqq \set{ S \given S \subseteq A }, \\
        &\pow(f: A \to B) \coloneqq (S \mapsto f[S]). \\
      \end{aligned}
    \end{equation*}

    We must verify that it is indeed a functor. \ref{def:functor/CF2} is satisfied because
    \begin{equation*}
      \pow(g) \bincirc \pow(f) = (S \mapsto g[f[S]]) = \pow(g \bincirc f).
    \end{equation*}

    The condition \ref{def:functor/CF2} is also obviously satisfied.

    The nuance here is that we send every function \( f: A \to B \) to its \hyperref[def:multi_valued_function/set_value]{set value} \( f[S] \) of some subset \( S \) of \( A \).

    \thmitem{ex:unary_functors_in_set/union} The \hyperref[def:basic_set_operations/union]{union} \( \bigcup \) and \hyperref[def:basic_set_operations/intersection]{intersection} \( \bigcap \) may seem to be good examples of endofunctors in \( \cat{Set} \). Unfortunately, there is no natural way to extend a morphism (function) \( f: A \to B \) to a morphism from \( \bigcup A \) to \( \bigcup B \) or \( \bigcap A \) to \( \bigcap B \).
  \end{thmenum}
\end{example}

\begin{definition}\label{def:subcategory}\mcite[def. 1.2.18]{Leinster2016Basic}
  We call the category \( \cat{D} \) a \term{subcategory} of \( \cat{C} \) if the following hold:
  \begin{itemize}
    \item The underlying quiver \( U(\cat{D}) \) is a \hyperref[def:quiver/submodel]{subquiver} of \( U(\cat{C}) \). That is, every object in \( \cat{D} \) is an object in \( \cat{C} \) and every morphism in \( \cat{D} \) is a morphism in \( \cat{C} \).
    \item Composition and identity in \( \cat{D} \) are \hyperref[def:multi_valued_function/restriction]{restrictions} of composition and identity in \( \cat{C} \).
  \end{itemize}

  \begin{thmenum}
    \thmitem{def:subcategory/inclusion} For every subcategory there exists an \term{inclusion functor} \( \Iota: \cat{D} \to \cat{C} \), which sends every object and morphism of \( \cat{D} \) to itself in \( \cat{C} \).

    \thmitem{def:subcategory/full} We say that \( \cat{D} \) is a \term{full subcategory} if the underlying quiver \( U(\cat{C}) \) is a \hyperref[def:quiver/submodel]{full subquiver}. That is, in case \( \cat{D}(A, B) = \cat{C}(A, B) \) for every pair of objects \( A \) and \( B \) of \( \cat{D} \).

    By \fullref{thm:def:functor_invertibility/properties/full_subcategory}, this is equivalent to the inclusion functor being \hyperref[def:functor_invertibility/full]{full}.

    \thmitem{def:subcategory/induced} Every \hyperref[rem:family_of_sets]{family} \( \mscrD \) of objects in \( \cat{C} \) induces a full subcategory \( \cat{D} \) of \( \cat{C} \), whose objects are those of \( \mscrD \) and whose morphisms are restricted to those whose domain and codomain are both in \( \mscrD \).
  \end{thmenum}
\end{definition}

\begin{remark}\label{rem:contravariant_functor}\mcite[def. 1.2.10]{Leinster2016Basic}
  We can invert the order of composition in \ref{def:functor/CF2} in the definition of a functor given in \fullref{def:functor}.
  \begin{thmenum}
    \thmitem[rem:contravariant_functor/CF2]{CF2\Textprime} We can replace \ref{def:functor/CF2} with
    \begin{equation}\label{eq:rem:contravariant_functor/CF2}\tag{\logic{CF2\Textprime}}
      F(g \bincirc f) = F(f) \bincirc F(g).
    \end{equation}
  \end{thmenum}

  This also requires some other straightforward modifications to the definition of a functor.

  A functor that satisfies \ref{rem:contravariant_functor/CF2} rather than \ref{def:functor/CF2} is called \term{contravariant}. In this context, a functor satisfying \ref{def:functor/CF2} is called \term{covariant}.

  Fortunately, a contravariant functor from \( \cat{C}^{\opcat} \) to \( \cat{D} \) is identical to a covariant functor from \( \cat{C} \) to \( \cat{D} \). Therefore, there is no formal difference between the two concepts.

  The usage of the terms are entirely dictated by context. Unless necessary, we will avoid speaking about contravariant functors to avoid confusion. Some examples where this terminology may be useful are \fullref{def:dual_functor}, \fullref{def:hom_functor/unary} and \fullref{ex:dual_space_contravariant_functor}.
\end{remark}

\begin{example}\label{ex:dual_space_contravariant_functor}
  We can try to na\"ively define a functor that assigns to a \hyperref[def:vector_space]{vector space} its \hyperref[def:dual_vector_space]{algebraic dual}:
  \begin{equation*}
    \begin{aligned}
      &F: \cat{Vect_\BbbK} \to \cat{Vect_\BbbK}, \\
      &F(V) \coloneqq V^*, \\
      &F(f: V \to W) \coloneqq (\varphi: W \to \BbbK \mapsto \varphi \bincirc f).
    \end{aligned}
  \end{equation*}

  Unfortunately, \( F(f) \) is supposed to be a morphism from \( V^* \) to \( W^* \), but is actually a morphism from \( W^* \) to \( V^* \). This makes \( F \) a \hyperref[rem:contravariant_functor]{contravariant functor} or, equivalently, a functor from \( \cat{Vect_\BbbK}^{\opcat} \) to \( \cat{Vect_\BbbK} \).
\end{example}

\begin{definition}\label{def:discrete_category}
  A \term{discrete category} is a category with no morphisms except for the identities. Clearly to any set there corresponds exactly one discrete category and vice versa.
\end{definition}

\begin{example}\label{ex:discrete_category_adjunction}
  Denote by
  \begin{equation*}
    U: \cat{Cat} \to \cat{Set}
  \end{equation*}
  the forgetful functor that for any small category \( \cat{C} \) gives us its set of objects \( \obj(\cat{C}) \). There is also a functor
  \begin{equation*}
    D: \cat{Set} \to \cat{Cat}
  \end{equation*}
  that for any small set \( A \) gives us the \hyperref[def:discrete_category]{discrete category} whose set of objects is \( A \).

  This is actually an \hyperref[def:category_adjunction]{adjunction} --- see \fullref{ex:def:category_adjunction/set_cat}.
\end{example}

\begin{proposition}\label{thm:def:functor/properties}
  \hyperref[def:functor]{Functors} have the following basic properties:
  \begin{thmenum}
    \thmitem{thm:def:functor/properties/half_inverses} Functors preserve inverses. For every functor \( F: \cat{C} \to \cat{D} \) and every morphism \( f: A \to B \) in \( \cat{C} \) with a right inverse \( g: B \to A \), \( F(f) \) is a right inverse of \( F(g) \). Similarly, if \( g \) is a left inverse of \( f \), then \( F(g) \) is a left inverse of \( F(f) \).

    \thmitem{thm:def:functor/properties/inverses} For every functor \( F: \cat{C} \to \cat{D} \) and every isomorphism \( f: A \to B \) in \( \cat{C} \),
    \begin{equation}\label{eq:thm:def:functor/properties/inverses}
      [F(f)]^{-1} = F(f^{-1}).
    \end{equation}

    \thmitem{thm:def:functor/properties/isomorphisms} Functors preserve \hyperref[def:morphism_invertibility/isomorphism]{isomorphisms}. That is, for every functor \( F: \cat{C} \to \cat{D} \), if \( f: A \to B \) is an isomorphism in \( \cat{C} \), \( F(f) \) is an isomorphism in \( \cat{D} \).

    Consequently, for every pair of objects \( A \) and \( B \) in \( \cat{C} \), from \( A \cong B \) it follows that \( F(A) \cong F(B) \).

    The converse sometimes also holds --- see \fullref{thm:def:functor_invertibility/properties/fully_faithful_reflects_isomorphisms}.
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:def:functor/properties/half_inverses} Let \( f: A \to B \) be a right inverse of \( g: B \to A \) in \( \cat{C} \). Then
  \begin{equation*}
    F(g) \bincirc F(f)
    \reloset {\eqref{eq:def:functor/CF2}} =
    F(g \bincirc f)
    =
    F(\id_A)
    \reloset {\eqref{eq:def:functor/CF1}} =
    \id_{F(A)}.
  \end{equation*}

  Thus, \( F(f) \) is a right inverse of \( F(g) \). Since \( g \) is a left inverse of \( f \), automatically \( F(g) \) is a left inverse of \( F(f) \).

  \SubProofOf{thm:def:functor/properties/inverses} If \( f^{-1} \) is a left inverse of \( f \), by \fullref{thm:def:functor/properties/half_inverses} we have that \( F(f^{-1}) \) is a left inverse of \( F(f) \). But \( F(f^{-1}) \) is also a right inverse, and again by \fullref{thm:def:functor/properties/half_inverses} \( F(g) \) is a right inverse of \( F(f^{-1}) \).

  Therefore, \( F(f^{-1}) \) is a two-sided inverse of \( F(f) \). By \fullref{thm:def:morphism_invertibility/properties/at_most_one_inverse}, it is the only two-sided inverse, hence
  \begin{equation*}
    [F(f)]^{-1} = F(f^{-1}).
  \end{equation*}

  \SubProofOf{thm:def:functor/properties/isomorphisms} Follows from \fullref{thm:def:functor/properties/inverses}.
\end{proof}

\begin{definition}\label{def:category_of_small_categories}
  Suppose that we are given a \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \), which is safe to assume to be the smallest suitable one as explained in \fullref{def:large_and_small_sets}.

  We denote the \hyperref[def:category]{category} of \( \mscrU \)-small \hyperref[def:category]{categories} by \( \ucat{Cat} \) or, if the universe is clear from the context, simply by \( \cat{Cat} \). See \fullref{def:category_size} for a further discussion of universes and categories.

  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj(\cat{Cat}) \) is the set of all \( \mscrU \)-small categories.

    \item The \hyperref[def:category/morphisms]{set of morphisms} \( \cat{Cat}(A, B) \) from \( A \) to \( B \) is the set of all \hyperref[def:functor]{functors} from \( A \) to \( B \).

    \item The \hyperref[def:category/composition]{composition of morphisms} is the \hyperref[def:multi_valued_function/composition]{function composition} of the functors regarded as the functions \eqref{eq:def:functor_as_single_function}. That is, the composition of \( F: \cat{C} \to \cat{D} \) and \( G: \cat{D} \to \cat{E} \) is the functor
    \begin{equation}\label{eq:def:category_of_small_categories/composition}
      \begin{aligned}
        &[G \bincirc F]: \cat{C} \to \cat{E}, \\
        &[G \bincirc F](A) \coloneqq G(F(A)), \\
        &[G \bincirc F](f) \coloneqq G(F(f)).
      \end{aligned}
    \end{equation}

    \item The \hyperref[def:category/identity]{identity morphism} on the category \( \cat{C} \) is the \term{identity functor}
    \begin{equation}\label{eq:def:category_of_small_categories/identity}
      \begin{aligned}
        &\id_{\cat{C}}: \cat{C} \to \cat{C}, \\
        &\id_{\cat{C}}(A) \coloneqq A, \\
        &\id_{\cat{C}}(f) \coloneqq f.
      \end{aligned}
    \end{equation}
  \end{itemize}
\end{definition}
\begin{defproof}
  To see that \( \ucat{Cat} \) is indeed a category, we verify the conditions \ref{def:category/C1} and \ref{def:category/C2}.

  \SubProofOf{def:category/C1} For every two \( \mscrU \)-small categories \( \cat{C} \) and \( \cat{D} \) and every functor \( F: \cat{C} \to \cat{D} \), for every object \( A \in \cat{C} \) we have
  \begin{equation*}
    [\id_{\cat{D}} \bincirc F](A)
    =
    \id_{\cat{D}}(F(A))
    =
    F(A)
    =
    F(\id_{\cat{C}}(A))
    =
    [F \bincirc \id_{\cat{C}}](A)
  \end{equation*}
  and analogously for morphisms.

  Therefore, \( \id_{\cat{C}} \) and \( \id_{\cat{D}} \) satisfy \eqref{eq:def:category/C1}.

  \SubProofOf{def:category/C2} Associativity of functor composition is inherited from the associativity of function composition.
\end{defproof}

\begin{definition}\label{def:universal_categories}
  For any \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \), the \hyperref[def:category_of_small_categories]{category of \( \mscrU \)-small categories} \( \ucat{Cat} \) has an initial and a terminal object.

  Similarly to how we use the \hyperref[def:ordinal]{ordinals} \( 0 \) and \( 1 \) to denote the initial and terminal object in the category of sets (see \fullref{ex:def:universal_objects/set}), we denote the initial category by \( \cat{0} \) and the final category by \( \cat{1} \). Note that the final category is only unique up to an isomorphism. They are identical, however, for all universes \( \mscrU \).

  These categories are precisely the \hyperref[def:discrete_category]{discrete categories} induced by the ordinals \( 0 \) and \( 1 \) as described in \fullref{thm:order_category_isomorphism}.
\end{definition}

\begin{definition}\label{def:dual_functor}\mcite{nLab:opposite_category}
  The \term{opposite} or \term{dual} functor of \( F: \cat{C} \to \cat{D} \) is the functor
  \begin{equation*}
    \begin{aligned}
      &F^{\opcat}: \cat{C}^{\opcat} \to \cat{D}^{\opcat} \\
      &F^{\opcat}(A) \coloneqq A \\
      &F^{\opcat}(f^{\opcat}: B \to A) \coloneqq [F(f: A \to B)]^{\opcat}.
    \end{aligned}
  \end{equation*}

  For the composition of functors, we then have
  \begin{equation}\label{eq:def:dual_functor/composition}
    [G \bincirc F]^{\opcat} = G^{\opcat} \bincirc F^{\opcat}.
  \end{equation}

  This is somewhat in contrast to the general practice of inverting morphisms when taking duals. Thus, we define, for any \hyperref[def:grothendieck_universe]{Grothendieck universe} \( \mscrU \), the \term{oppositization functor}
  \begin{equation*}
    (\anon*)^{\opcat}: \ucat{Cat}^{\opcat} \to \ucat{Cat}.
  \end{equation*}

  As an \hyperref[def:multi_valued_function/endofunction]{endofunction} on \( \obj(\ucat{Cat}) \), the oppositization functor is clearly an \hyperref[def:set_with_involution]{involution}.

  Dual functors also arise naturally in \fullref{thm:dual_functor_category}.
\end{definition}

\begin{definition}\label{def:functor_image}
  The \term{image} of a functor \( F: \cat{C} \to \cat{D} \) is the \hyperref[def:quiver]{quiver} whose vertex set is
  \begin{equation*}
    V \coloneqq \set{ F(A) \given A \in \cat{C} }
  \end{equation*}
  and whose arc set is
  \begin{equation*}
    A \coloneqq \set{ F(f) \given A, B \in \cat{C} \T{and} f \in \cat{C}(A, B) }.
  \end{equation*}

  This quiver has no categorical structure --- it is merely a directed multigraph. As shown in \fullref{ex:functor_image_not_a_category}, imposing a categorical structure na\"ively may fail.
\end{definition}

\begin{example}\label{ex:functor_image_not_a_category}\mcite{MathSE:image_of_functor_is_not_a_category}
  \begin{figure}
    \hfill
    \includegraphics[page=1]{output/ex__functor_image_not_a_category.pdf}
    \hfill
    \hfill
    \caption{A functor whose image is not a category.}\label{fig:ex:functor_image_not_a_category}
  \end{figure}

  Consider the functor \( F: \cat{C} \to \cat{D} \) from \cref{fig:ex:functor_image_not_a_category}.

  \begin{itemize}
    \item The solid arrows are the morphisms in \( \cat{C} \) and their images in \( F(\cat{C}) \).
    \item The dashed arrows denote the action of the functor \( F \).
    \item The dotted arrow exists in \( \cat{D} \) as the composition of the other two arrows, however it is missing in the image \( F(\cat{C}) \). Thus, composition is not fully defined in \( F(\cat{C}) \), and \( F(\cat{C}) \) fails to be a category.
  \end{itemize}
\end{example}

\begin{definition}\label{def:categorical_diagram}
  Fix a category \( \cat{I} \), called an \term{index category}. A \term{diagram} in \( \cat{C} \) of shape \( \cat{I} \) is simply a functor \( D: \cat{I} \to \cat{C} \), whose domain is \( \cat{I} \). We sometimes identify a diagram functor with its image \( D(\cat{I}) \).

  It is often convenient to draw graphically the \hyperref[def:quiver_geometric_realization]{geometric realizations} of the \hyperref[def:quiver]{quiver} \( D(\cat{I}) \). An established convention is to allow multiple vertices representing the same object, which can be achieved formally by actually adjoining new vertices to the quiver and labeling them as in \fullref{def:weighted_set}. Other established conventions for drawing diagrams include not drawing identity morphisms and adding various visual aids. In this regard, categorical diagrams correspond to the everyday sense of the word \enquote{diagram}.

  We say that the diagram \( D \) over \( \cat{C} \) \term{commutes} if, whenever \( p = (f_1, \ldots, f_n) \) and \( q = (g_1, \ldots, g_m) \) are two \hyperref[def:quiver_path/directed]{directed paths} in \( D(\cat{I}) \) with identical endpoints and either \( n > 1 \) or \( m > 1 \), then
  \begin{equation*}
    f_n \bincirc f_{n-1} \bincirc \cdots \bincirc f_2 \bincirc f_1
    =
    g_m \bincirc g_{m-1} \bincirc \cdots \bincirc g_2 \bincirc g_1.
  \end{equation*}

  We do not really care about how the objects and morphisms in \( \cat{I} \) are labeled, hence we often use placeholder dots like in \eqref{eq:ex:quivers_as_functors/index/dots}.

  The requirement that the one of the paths is nontrivial, however, is crucial in \fullref{def:equalizers}.
\end{definition}

\begin{remark}\label{rem:inverting_isomorphisms_may_preserve_commutativity}
  Inverting isomorphisms in a \hyperref[def:categorical_diagram]{commutative diagram} may or may not preserve commutativity.

  If \( p = (f_1, \ldots, f_n) \) and \( q = (g_1, \ldots, g_m) \) are two paths in a commutative diagram, and if \( f_1 \) is invertible, then obviously
  \begin{equation*}
    f_n \bincirc \cdots \bincirc f_1 = g_m \bincirc \cdots \bincirc g_1
  \end{equation*}
  if and only if
  \begin{equation*}
    f_n \bincirc \cdots \bincirc f_2 = g_m \bincirc \cdots \bincirc g_1 \bincirc f_1
  \end{equation*}
  and similarly if \( f_n \) is invertible.

  On the other hand, consider \hyperref[def:ordinal]{ordinals} in \( \cat{Set} \). Denote by \( \iota \) the inclusion maps and by \( f: \omega^2 \to \omega \) the bijective map from \fullref{thm:omega_equinumerous_with_omega_squared}. Then the following diagram commutes:
  \begin{equation}\label{eq:rem:inverting_isomorphisms_may_preserve_commutativity/ordinals_commuting}
    \begin{aligned}
      \includegraphics[page=1]{output/rem__inverting_isomorphisms_may_preserve_commutativity.pdf}
    \end{aligned}
  \end{equation}
  but the following does not:
  \begin{equation}\label{eq:rem:inverting_isomorphisms_may_preserve_commutativity/ordinals_not_commuting}
    \begin{aligned}
      \includegraphics[page=2]{output/rem__inverting_isomorphisms_may_preserve_commutativity.pdf}
    \end{aligned}
  \end{equation}
\end{remark}

\begin{definition}\label{def:functor_invertibility}
  In connection with \fullref{def:morphism_invertibility} and \fullref{def:function_invertibility}, we introduce the following terminology:
  \begin{thmenum}
    \thmitem{def:functor_invertibility/injective_on_objects} The \hyperref[def:functor]{functor} \( F: \cat{C} \to \cat{D} \) is \term{injective on objects} if the \hyperref[def:multi_valued_function/restriction]{restriction}
    \begin{equation*}
      F\restr_{\obj(C)}: \obj(C) \to \obj(D)
    \end{equation*}
    is \hyperref[def:function_invertibility/injective]{injective}.

    That is, for every pair of objects \( A \) and \( B \) in \( \cat{C} \), from \( F(A) = F(B) \) it follows that \( A = B \).

    If, instead, from \( F(A) \cong F(B) \) it follows that \( A \cong B \), we say that \( F \) if \term{essentially injective on objects}.

    \thmitem{def:functor_invertibility/injective_on_morphisms} The \hyperref[def:functor]{functor} \( F: \cat{C} \to \cat{D} \) is \term{injective on morphisms} if its restriction to the set
    \begin{equation*}
      \bigcup\set{ \cat{C}(A, B) \given A, B \in \obj(\cat{C}) }
    \end{equation*}
    of all morphisms is injective.

    That is, for every pair of morphisms \( f \) and \( g \) in \( \cat{C} \), from \( F(f) = F(g) \) it follows that \( f = g \). Note that if the morphisms are not parallel, we assume that they are not equal.

    \thmitem{def:functor_invertibility/faithful}\mcite[def. 1.2.16]{Leinster2016Basic} The functor \( F: \cat{C} \to \cat{D} \) is \term{faithful} if it is \hyperref[def:function_invertibility/injective]{injective} on \( \hom \)-sets, i.e. for all pairs of objects \( A \) and \( B \) in \( \cat{C} \), the restriction of \( F \) to \( \cat{C}(A, B) \) is an injective function.

    That is, for every pair of objects \( A \) and \( B \) in \( \cat{C} \) and every pair of morphisms \( f \) and \( g \) in \( \cat{C}(A, B) \), from \( F(f) = F(g) \) it follows that \( f = g \).

    See \fullref{thm:def:functor_invertibility/properties/injective} for how faithful functors relate to functors injective on objects or on morphisms.

    \thmitem{def:functor_invertibility/surjective_on_objects}\mcite[def. 1.3.17]{Leinster2016Basic} The functor \( F: \cat{C} \to \cat{D} \) is \term{surjective on objects} if the restriction
    \begin{equation*}
      F\restr_{\obj(C)}: \obj(C) \to \obj(D)
    \end{equation*}
    is \hyperref[def:function_invertibility/surjective]{surjective}.

    That is, for every object \( B \) in \( \cat{D} \), there exists at least one object \( A \) in \( \cat{C} \) such that \( F(A) = B \).

    If, instead, there exists at least one object \( A \in \cat{C} \) such that \( F(A) \cong B \), we say that \( F \) is \term{essentially surjective on objects}.

    \thmitem{def:functor_invertibility/surjective_on_morphisms} Similarly, \( F: \cat{C} \to \cat{D} \) is \term{surjective on morphisms} if its restriction to the set of all morphisms is surjective.

    That is, for every morphism \( g \) in \( \cat{D} \), there exists at least one morphism \( f \) in \( \cat{C} \) such that \( F(f) = g \).

    \thmitem{def:functor_invertibility/full}\mcite[def. 1.2.16]{Leinster2016Basic} The functor \( F: \cat{C} \to \cat{D} \) is \term{full} if it is surjective on \( \hom \)-sets, i.e. for all pairs of objects \( A \) and \( B \) in \( \cat{C} \), the restriction of \( F \) to \( \cat{C}(A, B) \) is a surjective function.

    That is, for every pair of objects \( A \) and \( B \) in \( \cat{C} \) and every morphism \( g: F(A) \to F(B) \) in \( \cat{D} \), there exists at least one morphism in \( f: A \to B \) in \( \cat{C} \) such that \( F(f) = g \).

    \thmitem{def:functor_invertibility/fully_faithful} Finally, \( F: \cat{C} \to \cat{D} \) is \term{fully faithful} if it is both full and faithful.
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:def:functor_invertibility/properties}
  \hyperref[def:functor]{Functors} have the following basic properties regarding their \hyperref[def:functor_invertibility]{invertibility}:

  \begin{thmenum}
    \thmitem{thm:def:functor_invertibility/properties/injective} A functor is \hyperref[def:functor_invertibility/injective_on_morphisms]{injective on morphisms} if and only if it is both \hyperref[def:functor_invertibility/injective_on_objects]{injective on objects} and \hyperref[def:functor_invertibility/faithful]{faithful}.

    \thmitem{thm:def:functor_invertibility/properties/surjective} A functor is \hyperref[def:functor_invertibility/surjective_on_morphisms]{surjective on morphisms} if and only if it is both \hyperref[def:functor_invertibility/surjective_on_objects]{surjective on objects} and \hyperref[def:functor_invertibility/full]{full}.

    \thmitem{thm:def:functor_invertibility/properties/full_subcategory} A \hyperref[def:subcategory]{subcategory} \( \cat{D} \) of \( \cat{C} \) is full in the sense of \fullref{def:subcategory} if and only if the \hyperref[def:subcategory]{inclusion functor} \( \Iota: \cat{D} \to \cat{C} \) is full in the sense of \fullref{def:functor_invertibility/full}.

    \thmitem{thm:def:functor_invertibility/properties/faithful_reflects_composition} \hyperref[def:functor_invertibility/faithful]{Faithful} functors reflect composition. That is, for every functor \( F: \cat{C} \to \cat{D} \), if the following diagram commutes:
    \begin{equation}\label{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/image}
      \begin{aligned}
        \includegraphics[page=1]{output/thm__def__functor_invertibility__properties.pdf}
      \end{aligned}
    \end{equation}
    then the following diagram are identities:
    \begin{equation}\label{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/source}
      \begin{aligned}
        \includegraphics[page=2]{output/thm__def__functor_invertibility__properties.pdf}
      \end{aligned}
    \end{equation}

    \thmitem{thm:def:functor_invertibility/properties/faithful_reflects_cancellative} A \hyperref[def:functor_invertibility/faithful]{faithful} functor reflects monomorphisms and epimorphisms. For every functor \( F: \cat{C} \to \cat{D} \) and morphism \( f: A \to B \) in \( \cat{C} \), if \( F(f) \) is a monomorphism (resp. epimorphism), so is \( f \).

    \thmitem{thm:def:functor_invertibility/properties/fully_faithful_reflects_identities} A \hyperref[def:functor_invertibility/fully_faithful]{fully faithful} functor reflects identities. For every functor \( F: \cat{C} \to \cat{D} \) and endomorphism \( f: A \to A \) in \( \cat{C} \), if \( F(f) = \id_{F(A)} \), then \( f = \id_A \).

    \thmitem{thm:def:functor_invertibility/properties/fully_faithful_reflects_isomorphisms} A \hyperref[def:functor_invertibility/fully_faithful]{fully faithful} functor reflects split monomorphisms and split epimorphisms, and hence also isomorphisms.

    That is, for every functor \( F: \cat{C} \to \cat{D} \) and morphism \( f: A \to B \) in \( \cat{C} \), if \( F(f) \) is a split monomorphism (resp. split epimorphism or isomorphism), so is \( f \).

    \thmitem{thm:def:functor_invertibility/properties/isomorphism} A functor between \( \mscrU \)-small categories that is both injective and surjective on morphisms is itself an isomorphism in \( \ucat{Cat} \).
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:def:functor_invertibility/properties/injective}
  \SufficiencySubProof* Let \( F: \cat{C} \to \cat{D} \) be injective on morphisms. It is trivially faithful since faithfulness is a more restrictive condition.

  To see that \( F \) is injective on objects, let \( A, B \in \cat{C} \) and suppose that \( F(A) = F(B) \). Then \( \id_{F(A)} = \id_{F(B)} \) and
  \begin{equation*}
    F(\id_A)
    \reloset {\eqref{eq:def:functor/CF2}} =
    \id_{F(A)}
    =
    \id_{F(B)}
    \reloset {\eqref{eq:def:functor/CF2}} =
    F(\id_B).
  \end{equation*}

  Since \( F \) is injective on morphisms, it follows that \( \id_A = \id_B \), hence \( A = B \). Thus, \( F \) is injective on objects.

  \NecessitySubProof* Let \( F: \cat{C} \to \cat{D} \) be faithful and injective on objects. Let \( f: A \to B \) and \( g: C \to D \) be morphisms in \( \cat{C} \) such that \( F(f) = F(g) \).

  Then both \( F(f) \) and \( F(g) \) have the same domain \( F(A) = F(C) \) and codomain \( F(B) = F(D) \). Hence, since \( F \) is injective on objects, we have \( A = C \) and \( B = D \).

  Thus, \( f \) and \( g \) are both morphisms from \( A \) to \( B \). Since \( F \) is also faithful, from \( F(f) = F(g) \) it follows that \( f = g \).

  Therefore, \( F \) is injective on morphisms.

  \SubProofOf{thm:def:functor_invertibility/properties/surjective}
  \SufficiencySubProof* Let \( F: \cat{C} \to \cat{D} \) be surjective on morphisms. It is trivially full since fullness is a more restrictive condition.

  To see that \( F \) is surjective on objects, let \( C \in \cat{D} \). Then there exists some morphism \( f: A \to B \) in \( \cat{C} \) such that \( F(f) = \id_Z \). We thus necessarily have \( F(A) = C \) and \( F(B) = C \).

  \NecessitySubProof* Let \( F: \cat{C} \to \cat{D} \) be full and injective on objects. Let \( g: C \to D \) be a morphism in \( \cat{D} \).

  Since \( F \) is surjective on objects, there exists preimages \( A \) of \( C \) and \( B \) of \( D \) under \( F \). Thus, \( g \in \cat{D}(F(A), F(B)) \).

  Since \( F \) is also full, there exists some morphism \( f: A \to B \) such that \( F(f) = g \).

  Therefore, \( F \) is surjective on morphisms.

  \SubProofOf{thm:def:functor_invertibility/properties/full_subcategory} Trivial.

  \SubProofOf{thm:def:functor_invertibility/properties/faithful_reflects_composition} Suppose that \eqref{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/image} commutes. Then, since \( F \) is faithful and thus injective on the morphism set \( \cat{C}(A, C) \), the equality \( F(g \bincirc f) = F(g) \bincirc F(f) = F(h) \) implies that \( g \bincirc f = h \). Hence, \eqref{eq:thm:def:functor_invertibility/properties/faithful_reflects_composition/source} also commutes.

  \SubProofOf{thm:def:functor_invertibility/properties/faithful_reflects_cancellative} Let \( F(g) \) be a monomorphism and let \( f_1, f_2: A \to B \) be parallel morphisms such that
  \begin{equation*}
    g \bincirc f_1 = g \bincirc f_2.
  \end{equation*}

  Then, since \( F(g) \) is a monomorphism, we have that \( F(f_1) = F(f_2) \). Since \( F \) is faithful, the restriction \( F\restr_{C(A, B)} \) is injective, and \( f_1 = f_2 \).

  The proof when \( F(g) \) is an epimorphism is analogous.

  \SubProofOf{thm:def:functor_invertibility/properties/fully_faithful_reflects_identities} If \( F: \cat{C} \to \cat{D} \) is fully faithful, for every object \( A \) in \( \cat{C} \), the identity morphism \( \id_{F(A)} \) has a unique preimage under \( F \). By \ref{def:functor/CF1}, this preimage can only be \( \id_A \).

  \SubProofOf{thm:def:functor_invertibility/properties/fully_faithful_reflects_isomorphisms} Let \( q \) be a left inverse of \( F(f) \). Since \( F \) is fully faithful, there exists a unique morphism \( g: B \to A \) such that \( F(g) = q \).

  Since
  \begin{equation*}
    F(g) \bincirc F(f) = \id_{F(A)},
  \end{equation*}
  by \fullref{thm:def:functor_invertibility/properties/fully_faithful_reflects_identities} we have
  \begin{equation*}
    g \bincirc f = \id_A.
  \end{equation*}

  Therefore, \( g \) is a left inverse of \( F(f) \).

  The proof for right inverses follows from \fullref{thm:def:morphism_invertibility/properties/inverse_interchanges}.

  From \fullref{thm:def:morphism_invertibility/properties/left_and_right} it follows that if \( F(f) \) is an isomorphism, so is \( f \).

  \SubProofOf{thm:def:functor_invertibility/properties/isomorphism} If \( F \) is both injective and surjective on morphisms, it is also injective and surjective on objects and hence, as a function, is bijective. Therefore, it is both left and right invertible as a consequence of \fullref{thm:function_invertibility_categorical/fully_invertible}.
\end{proof}

\begin{example}\label{ex:def:functor_invertibility}
  \hfill
  \begin{thmenum}
    \thmitem{ex:def:functor_invertibility/power} The power set functor described in \fullref{ex:unary_functors_in_set} is clearly \hyperref[def:functor_invertibility/injective_on_morphisms]{injective on morphisms}, hence by \fullref{thm:def:functor_invertibility/properties/injective}, it is also \hyperref[def:functor_invertibility/injective_on_objects]{injective on objects} and \hyperref[def:functor_invertibility/faithful]{faithful}.

    It is not full, nor surjective on objects.

    \thmitem{ex:def:functor_invertibility/cat_to_set} The forgetful functor \( D: \ucat{Cat} \to \ucat{Set} \) discussed in \fullref{def:discrete_category} is \hyperref[def:functor_invertibility/surjective_on_morphisms]{surjective on morphisms}, hence by \fullref{thm:def:functor_invertibility/properties/surjective}, it is also \hyperref[def:functor_invertibility/surjective_on_objects]{surjective on objects} and \hyperref[def:functor_invertibility/full]{full}.

    It is not faithful, nor injective on objects.
  \end{thmenum}
\end{example}

\begin{proposition}\label{thm:commutative_diagrams_preserved_and_reflected}
  Functors preserve commutative diagrams and faithful functors also reflect commutative diagrams.

  More precisely, let \( \cat{C} \) be an arbitrary category, let \( D \) be a diagram in \( \cat{C} \), and let \( p = (f_1, \ldots, f_n) \) and \( q = (g_1, \ldots, g_m) \) be two \hyperref[def:quiver_path/directed]{directed paths} with the same endpoints in \( D \).

  For any functor \( F: \cat{C} \to \cat{D} \), if
  \begin{equation}\label{eq:thm:commutative_diagrams_preserved_and_reflected/source}
    f_n \bincirc \cdots \bincirc \bincirc f_1 = g_m \bincirc \cdots \bincirc \bincirc g_1,
  \end{equation}
  then
  \begin{equation}\label{eq:thm:commutative_diagrams_preserved_and_reflected/image}
    F(f_n) \bincirc \cdots \bincirc \bincirc F(f_1) = F(g_m) \bincirc \cdots \bincirc \bincirc F(g_1),
  \end{equation}

  Conversely, if \( F \) is faithful, then \eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} implies \eqref{eq:thm:commutative_diagrams_preserved_and_reflected/source}.
\end{proposition}
\begin{proof}
  Functors preserve composition by \ref{eq:def:functor/CF2}, hence \eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} follows from \eqref{eq:thm:commutative_diagrams_preserved_and_reflected/source} directly.

  Now suppose that \eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} holds for a faithful functor \( F \). \ref{eq:def:functor/CF2} allows us to reduce \eqref{eq:thm:commutative_diagrams_preserved_and_reflected/image} to
  \begin{equation*}
    F(f_n \bincirc \cdots \bincirc \bincirc f_1) = F(g_m \bincirc \cdots \bincirc \bincirc g_1).
  \end{equation*}

  Then, by injectivity of \( F \) on the morphism set \( \cat{C}(\dom(f_1), \co\dom(f_1)) \), \eqref{eq:thm:commutative_diagrams_preserved_and_reflected/source} holds.
\end{proof}

\begin{definition}\label{def:natural_transformation}\mcite[def. 1.3.1]{Leinster2016Basic}
  Let \( F \) and \( G \) be parallel \hyperref[def:functor]{functors} from the category \( \cat{C} \) to \( \cat{D} \).

  A \term{natural transformation} \( \alpha \) from \( F \) to \( G \) is an \hyperref[def:cartesian_product/indexed_family]{indexed family} of
  \begin{equation}\label{eq:def:natural_transformation/family}
    \seq{ \alpha_A: F(A) \to G(A) }_{A \in \cat{C}}
  \end{equation}
  of morphisms in \( \cat{D} \) such that, for every morphism \( f: A \to B \) in \( \cat{C} \), the following \hyperref[def:categorical_diagram]{diagram commutes}:
  \begin{equation}\label{eq:def:natural_transformation/diagram}
    \begin{aligned}
      \includegraphics[page=1]{output/def__natural_transformation.pdf}
    \end{aligned}
  \end{equation}

  The morphisms \( \alpha_A \) are called the components of \( \alpha \). We denote natural transformations by \( \alpha: F \Rightarrow G \) and, when used in diagrams, by
  \begin{equation}\label{eq:def:natural_transformation/notation}
    \begin{aligned}
      \includegraphics[page=2]{output/def__natural_transformation.pdf}
    \end{aligned}
  \end{equation}
\end{definition}

\begin{example}\label{ex:quivers_as_functors}\mcite[exmpl. 1.3.46]{Perrone2019}
  In \fullref{def:quiver}, we have defined a quiver as a set \( V \) of vertices, a set \( A \) of arcs and two functions --- the head \( h: A \to V \)and tail \( t: A \to V \) of an arc.

  Now consider the following \hyperref[def:categorical_diagram]{index category} \( \cat{I}: \)
  \begin{equation}\label{eq:ex:quivers_as_functors/index/dots}
    \begin{aligned}
      \includegraphics[page=1]{output/ex__quivers_as_functors.pdf}
    \end{aligned}
  \end{equation}

  For the sake of readability, we will give the following explicit labels in this category:
  \begin{equation}\label{eq:ex:quivers_as_functors/index/annotated}
    \begin{aligned}
      \includegraphics[page=2]{output/ex__quivers_as_functors.pdf}
    \end{aligned}
  \end{equation}

  A quiver can then be defined as a functor \( Q: \cat{I} \to \ucat{Set} \) to the category \hyperref[def:category_of_small_sets]{\( \ucat{Set} \)} of \( \mscrU \)-small sets (for a \hyperref[def:category_size]{fixed Grothendieck universe} \( \mscrU \)).

  A \hyperref[def:natural_transformation]{natural transformation} from the quiver \( Q: \cat{I} \to \ucat{Set} \) to \( R: \cat{I} \to \ucat{Set} \) is then a pair of functions \( f_V: Q(V) \to R(V) \) and \( f_A: Q(A) \to R(A) \) such that the following \hyperref[def:categorical_diagram]{diagrams commute}:
  \begin{equation}\label{eq:ex:quivers_as_functors/index/diagram}
    \begin{aligned}
      \includegraphics[page=3]{output/ex__quivers_as_functors.pdf}
      \quad\quad\quad\quad
      \includegraphics[page=4]{output/ex__quivers_as_functors.pdf}
    \end{aligned}
  \end{equation}

  See \fullref{ex:isomorphism_of_quiver_categories} for how these functors related to quivers as defined in \fullref{def:quiver}.
\end{example}

\begin{remark}\label{rem:natural_transformations_into_set}
  Let \( \cat{C} \) be an arbitrary \( \mscrU \)-small category. A \hyperref[def:natural_transformation]{natural transformation} \( \alpha \) from \( F: \cat{C} \to \ucat{Set} \) to \( G: \cat{C} \to \ucat{Set} \) is then a family of functions
  \begin{equation*}
    \seq{ \alpha_A: F(A) \to G(A) }_{A \in \cat{C}}.
  \end{equation*}

  Suppose that for every two objects \( A \) and \( B \) in \( \cat{C} \), the functions \( \alpha_A \) and \( \alpha_B \) agree on \( F(A) \cap F(B) \). This is automatically satisfied in \( F(A) \) and \( F(B) \) are disjoint whenever \( A \neq B \).

  We can then take the set-theoretic union of \( \alpha \) to obtain the function
  \begin{equation*}
    \bigcup_{A \in \cat{C}} \alpha_A: \bigcup\set{ F(A) \given A \in \cat{C} } \to \bigcup\set{ G(A) \given A \in \cat{C} }.
  \end{equation*}

  Both the domain and codomain are sets as a consequence of \ref{def:grothendieck_universe/union}, therefore the function is well-defined in the universe \( \mscrU \). Denote it on \( \Alpha \) for brevity.

  An advantage of this is that we can define a natural transformation to be a function on a general enough set and then prove that its restrictions satisfy \eqref{eq:def:natural_transformation/diagram}.

  For example, consider the power set functor \( \pow: \ucat{Set} \to \ucat{Set} \) discussed in \fullref{ex:unary_functors_in_set}. The \hyperref[def:multi_valued_function/identity]{identity function} \( \id_\mscrU \) is then a natural transformation from the identity functor \( \id_{\ucat{Set}} \) to \( \pow \).

  Another natural transformation between the same functors is the singleton set operation \( \Sigma \) on sets defined as \( A \mapsto \set{ A } \). Note that, in this context, \( \Sigma \) operates not on the sets \( \id_{\ucat{Set}}(A) \) and \( \pow(A) \), but on their members. The diagram \eqref{eq:def:natural_transformation/diagram} becomes
  \begin{equation}\label{eq:rem:natural_transformations_into_set}
    \begin{aligned}
      \includegraphics[page=1]{output/rem__natural_transformations_into_set.pdf}
    \end{aligned}
  \end{equation}

  This diagram commutes because, for every function \( f: A \to B \) and every \( x \in A \), we have
  \begin{equation*}
    f[\set{ x }] = \set{ f(x) }.
  \end{equation*}
\end{remark}

\begin{definition}\label{def:functor_category}
  Let \( \cat{C} \) and \( \cat{D} \) be arbitrary \hyperref[def:category]{categories}. The \term{functor category} \( [\cat{C}, \cat{D}] \), also denoted as \( \cat{D}^{\cat{C}} \), is defined as follows:

  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} \( \obj([\cat{C}, \cat{D}]) \) is the set of all functors from \( \cat{C} \) to \( \cat{D} \).

    \item The \hyperref[def:category/morphisms]{set of morphisms} \( [\cat{C}, \cat{D}](F, G) \) from \( F \) to \( G \) is the set of all \hyperref[def:natural_transformation]{natural transformations} from \( F \) to \( G \).

    \item The \hyperref[def:category/composition]{composition of the morphisms} \( \alpha: F \Rightarrow G \) and \( \beta: G \Rightarrow H \) is the natural transformation \( \beta \bincirc \alpha: F \Rightarrow H \) defined in terms of componentwise morphism composition, i.e.
    \begin{equation}\label{eq:def:functor_category/composition}
      (\beta \bincirc \alpha)_A \coloneqq \beta_A \bincirc \alpha_A.
    \end{equation}

    \item The \hyperref[def:category/identity]{identity morphism} on the functor \( F: \cat{C} \to \cat{D} \) is the \term{identity natural transformation} \( \id_F: F \Rightarrow F \) with components
    \begin{equation}\label{eq:def:functor_category/identity}
      (\id_F)_A \coloneqq \underbrace{\id_{F(A)}}_{F(\id_A)}
    \end{equation}
  \end{itemize}
\end{definition}
\begin{defproof}
  Just to verify that the composition \( \beta \bincirc \alpha \) defined in \eqref{eq:def:functor_category/composition} is indeed a natural transformation from \( F \) to \( H \), note that the following diagram trivially commutes:
  \begin{equation}\label{def:functor_category/composition}
    \begin{aligned}
      \includegraphics[page=1]{output/def__functor_category.pdf}
    \end{aligned}
  \end{equation}

  Now, to see that \( [\cat{C}, \cat{D}] \) is indeed a category, we verify the conditions \ref{def:category/C1} and \ref{def:category/C2}, which are in turn inherited from the same conditions on the categories \( \cat{C} \) and \( \cat{D} \).

  \SubProofOf{def:category/C1} For every two functors \( F, G: \cat{C} \to \cat{D} \) and natural transformation \( \alpha: F \Rightarrow G \), for every object \( A \in \cat{C} \) we have
  \begin{equation*}
    \id_{G(A)} \bincirc \alpha_A
    \reloset{\eqref{def:category/C1}} =
    \alpha_A
    \reloset{\eqref{def:category/C1}} =
    \alpha_A \bincirc \id_{F(A)}
  \end{equation*}

  Therefore,
  \begin{equation*}
    \id_G \bincirc \alpha = \alpha = \alpha \bincirc \id_F
  \end{equation*}
  and, after generalizing, we obtain that \eqref{eq:def:category/C1} holds in \( [\cat{C}, \cat{D}] \).

  \SubProofOf{def:category/C2} For any quadruple \( F \), \( G \), \( H \) and \( T \) of functors from \( \cat{C} \) to \( \cat{D} \) and every combination of natural transformations \( \alpha: F \Rightarrow G \), \( \beta: G \Rightarrow H \) and \( \gamma: H \Rightarrow T \), for every object \( A \in \cat{C} \) we have
  \begin{equation*}
    (\gamma_A \bincirc \beta_A) \bincirc \alpha_A
    \reloset{\eqref{def:category/C2}} =
    \gamma_A \bincirc (\beta_A \bincirc \alpha_A).
  \end{equation*}

  Therefore, after generalizing, we obtain that \eqref{eq:def:category/C2} holds in \( [\cat{C}, \cat{D}] \).
\end{defproof}

\begin{remark}\label{rem:functor_category_size}
  If \( \cat{C} \) and \( \cat{D} \) are \( \mscrU \)-large categories in the sense of \fullref{def:category_size}, we cannot construct the \hyperref[def:functor_category]{functor category} \( [\cat{C}, \cat{D}] \). This is the main motivation for the \hyperref[def:axiom_of_universes]{axiom of universes}, which is discussed in \fullref{def:large_and_small_sets} and, in relation to category theory, in \fullref{def:category_size}.
\end{remark}

\begin{example}\label{ex:isomorphism_of_quiver_categories}
  In \fullref{ex:quivers_as_functors}, we defined \hyperref[def:quiver]{quivers} as functors from a certain index category \( \cat{I} \) to \( \ucat{Set} \) (for a \hyperref[def:category_size]{fixed Grothendieck universe} \( \mscrU \)).

  There is then an obvious correspondence between quivers as objects of \hyperref[def:category_of_small_quivers]{\( \ucat{Quiv} \)}, defined in \fullref{def:quiver}, and quivers as objects in the \hyperref[def:functor_category]{functor category} \( [\cat{I}, \ucat{Set}] \), defined in \fullref{ex:quivers_as_functors}. Indeed, given any functor \( Q: \cat{I} \to \ucat{Set} \), the quadruple
  \begin{equation*}
    \parens[\Big]{ Q(V), Q(A), Q(h), Q(t) }
  \end{equation*}
  is a quiver in the sense of \fullref{def:quiver}.

  No object in \( \ucat{Quiv} \) is formally equal to any object in \( [\cat{I}, \ucat{Set}] \) in the sense of \hyperref[def:zfc]{\logic{ZFC}}. They are, however, equivalent, as shown above, and this can be formalized by stating that the two categories are isomorphic, in the sense of \fullref{def:morphism_invertibility/isomorphism}, as objects of the category \( \ucat[\mscrV]{Cat} \), where \( \mscrV \) is a Grothendieck universe that strictly contains \( \mscrU \). We have already defined this isomorphism explicitly.

  This is an example of \term{isomorphism of categories}. In practice, if two categories are not so obviously identical, we are usually better served by \term{equivalences of categories} defined in \fullref{def:category_equivalence}.
\end{example}

\begin{definition}\label{def:dual_natural_transformation}\mcite{nLab:opposite_category}
  The \term{opposite} or \term{dual} natural transformation of \( \alpha: F \Rightarrow G \), where \( F \) and \( G \) are functors from \( \cat{C} \) to \( \cat{D} \), is the natural transformation \( \alpha^{\opcat}: G^{\opcat} \Rightarrow F^{\opcat} \), in which we take the opposite of each component in \( \alpha \).

  Dual natural transformation arise naturally in \fullref{thm:dual_functor_category}.
\end{definition}
\begin{defproof}
  The naturality diagram \eqref{eq:def:natural_transformation/diagram} commutes for \( \alpha^{\opcat} \) because all morphisms are simply reversed.
\end{defproof}

\begin{proposition}\label{thm:dual_functor_category}
  For the \hyperref[def:dual_category]{dual} of the \hyperref[def:functor_category]{functor category} \( [\cat{C}, \cat{D}] \) we have
  \begin{equation*}
    [\cat{C}, \cat{D}]^{\opcat} = [\cat{C}^{\opcat}, \cat{D}^{\opcat}].
  \end{equation*}

  This is part of the duality principles listed in \fullref{thm:categorical_principle_of_duality}.
\end{proposition}
\begin{proof}
  In \fullref{def:dual_functor}, we have defined the opposite functor \( F^{\opcat}: \cat{C}^{\opcat} \to \cat{D}^{\opcat} \) of \( F: \cat{C} \to \cat{D} \) in a way that allows us to regard it as an object of \( [\cat{C}^{\opcat}, \cat{D}^{\opcat}] \).

  In \fullref{def:dual_natural_transformation}, we have defined the opposite natural transformation \( \alpha^{\opcat}: G^{\opcat} \to F^{\opcat} \) of \( \alpha: F \Rightarrow G \) in a way that allows us to regard it as a morphism of \( [\cat{C}^{\opcat}, \cat{D}^{\opcat}] \).

  Furthermore, \( \alpha^{\opcat}: G^{\opcat} \to F^{\opcat} \) reverses the direction of its morphisms, and hence it is the dual to \( \alpha \) in the category \( [\cat{C}, \cat{D}]^{\opcat} \).
\end{proof}

\begin{definition}\label{def:diagonal_functor}\mcite[143]{Leinster2016Basic}
  Given an \term{index category} \( \cat{I} \) and an arbitrary category \( \cat{C} \), for any object \( A \) in \( \cat{C} \), we can define the \term{constant functor}
  \begin{equation*}
    \begin{aligned}
      &\Delta_A^{\cat{I}}: \cat{I} \to \cat{C}, \\
      &\Delta_A^{\cat{I}}(X) \coloneqq X, \\
      &\Delta_A^{\cat{I}}(g: X \to Y) \coloneqq \id_A.
    \end{aligned}
  \end{equation*}

  Given two objects \( A \) and \( B \) in \( \cat{C} \), a natural transformation \( \alpha: \Delta_A^{\cat{I}} \Rightarrow \Delta_B^{\cat{I}} \) is an \hyperref[def:cartesian_product/indexed_family]{indexed family} that gives the same morphism for every object of the index category \( \cat{I} \).

  Indeed, the diagram \eqref{eq:def:natural_transformation/diagram} in this case becomes
  \begin{equation}\label{eq:def:diagonal_functor/nat}
    \begin{aligned}
      \includegraphics[page=1]{output/def__diagonal_functor.pdf}
    \end{aligned}
  \end{equation}

  This diagram implies that \( \alpha_A = \alpha_B \) for any two objects \( A \) and \( B \) in \( \cat{I} \). Therefore, all components of \( \alpha \) are equal to some morphism in \( \cat{C}(A, B) \).

  We can now define the \( \cat{I} \)-shaped \term{diagonal functor} on \( \cat{C} \)
  \begin{equation*}
    \begin{aligned}
      &\Delta^{\cat{I}}: \cat{C} \to [\cat{I}, \cat{C}], \\
      &\Delta^{\cat{I}}(A) \coloneqq \Delta_A^{\cat{I}}, \\
      &\Delta^{\cat{I}}(f: A \to B) \coloneqq \seq{ f: A \to B }_{k \in \cat{I}}.
    \end{aligned}
  \end{equation*}

  It is called a diagonal functor because, if \( \cat{I} \) is a discrete category of two objects, then \( \Delta_{\cat{I}} \) gives the diagonal of the \hyperref[def:product_category]{product category} \( \cat{C}^2 \) by providing, for each object \( A \) of \( \cat{C} \), the ordered pair \( (A, A) \) (and similarly for morphisms).
\end{definition}

\begin{proposition}\label{thm:natural_isomorphism}\mcite{math3ma:natural_transformations}
  Let \( F \) and \( G \) be parallel \hyperref[def:functor]{functors} from the category \( \cat{C} \) to \( \cat{D} \). The family \eqref{eq:def:natural_transformation/family} is an isomorphism in the corresponding \hyperref[def:functor_category]{functor category} \( [\cat{C}, \cat{D}] \) if and only if all of its components are isomorphisms and, for any morphism \( f: A \to B \) in \( \cat{C} \), the following diagram commutes:
  \begin{equation}\label{eq:thm:natural_isomorphism/diagram}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__natural_isomorphism.pdf}
    \end{aligned}
  \end{equation}

  We say that \( \alpha \) is a \term{natural isomorphism}.
\end{proposition}
\begin{proof}
  If all components of \( \alpha \) are isomorphisms, the condition
  \begin{equation*}
    \alpha_B \bincirc F(f) = G(f) \bincirc \alpha_A
  \end{equation*}
  is equivalent to
  \begin{equation*}
    F(f) = \alpha_B^{-1} \bincirc G(f) \bincirc \alpha_A.
  \end{equation*}

  We must now show that, if \( \alpha \) is an isomorphism in \( [\cat{C}, \cat{D}] \), all of its components are isomorphisms.

  If \( \alpha: F \Rightarrow G \) is an isomorphism in \( [\cat{C}, \cat{D}] \). Then there exists some natural transformation \( \beta: G \Rightarrow F \) such that
  \begin{equation*}
    \beta \bincirc \alpha = \id_F \quad\T{and}\quad \alpha \bincirc \beta = \id_G.
  \end{equation*}

  For every object \( A \) in \( \cat{C} \), the morphism \( \alpha_A: F(A) \to G(A) \) composed with \( \beta_A: G(A) \to F(A) \) is
  \begin{equation*}
    \beta_A \bincirc \alpha_A = \id_{F(A)}.
  \end{equation*}

  Therefore, \( \alpha_A \) is left-invertible. Analogously,
  \begin{equation*}
    \alpha_A \bincirc \beta_A = \id_{F(A)}
  \end{equation*}
  and hence \( \alpha_A \) is right-invertible.

  Therefore, for every object \( A \) in \( \cat{C} \), the morphism \( \alpha_A \) is fully invertible, i.e. an isomorphism.
\end{proof}

\begin{definition}\label{def:product_category}\mcite[const. 1.1.11]{Leinster2016Basic}
  We define the \term{product category} \( \cat{C} \times \cat{D} \) of \( \cat{C} \) and \( \cat{D} \) as follows:

  \begin{itemize}
    \item The \hyperref[def:category/objects]{set of objects} is the \hyperref[def:cartesian_product]{Cartesian product}
    \begin{equation}\label{eq:def:product_category/objects}
      \obj(\cat{C} \times \cat{D}) \coloneqq \obj(\cat{C}) \times \obj(\cat{D}).
    \end{equation}

    \item The \hyperref[def:category/morphisms]{set of morphisms} from the pair of objects \( (A, X) \) to \( (B, Y) \) is the product
    \begin{equation}\label{eq:def:product_category/morphisms}
      (\cat{C} \times \cat{D})\parens[\Big]{ (A, X), (B, Y) } \coloneqq \cat{C}(A, B) \times \cat{D}(X, Y).
    \end{equation}

    \item The \hyperref[def:category/composition]{composition of the morphisms}
    \begin{align*}
      (f, r)&: (A, X) \to (B, Y) \\
      (g, s)&: (B, Y) \to (C, Z)
    \end{align*}
    is the pairwise composition
    \begin{equation}\label{eq:def:product_category/composition}
      (g, s) \bincirc (f, r) \coloneqq \underbrace{(g \bincirc f, s \bincirc r)}_{(A, X) \to (C, Z)}.
    \end{equation}

    \item The \hyperref[def:category/identity]{identity morphism} of the pair \( (A, X) \) is simply the pair of identity morphisms \( (\id_A, \id_X) \).
  \end{itemize}
\end{definition}

\begin{definition}\label{def:hom_functor}
  Let \( \cat{C} \) be a \hyperref[def:category_size]{locally \( \mscrU \)-small} category. We can regard the morphism sets \( \cat{C}(A, B) \) as a functor parameterized by objects of \( \cat{C} \).

  \begin{thmenum}
    \thmitem{def:hom_functor/binary} For any pair of morphisms \( f: B \to A \) and \( g: X \to Y \) in \( \cat{C} \), define the operator
    \begin{equation}\label{eq:def:hom_functor/t}
      \begin{aligned}
        &T_{f,g}: \cat{C}(A, X) \to \cat{C}(B, Y) \\
        &T_{f,g}(s) \mapsto g \bincirc s \bincirc f.
      \end{aligned}
    \end{equation}

    The action of \( T_{f,g} \) can be expressed graphically as
    \begin{equation}\label{eq:def:hom_functor/t_diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/def__hom_functor.pdf}
      \end{aligned}
    \end{equation}

    We can now define the following \term{binary hom-functor}:
    \begin{equation}\label{eq:def:hom_functor/binary}
      \begin{aligned}
        &\cat{C}(\anon*, \anon*): \cat{C}^{\opcat} \times \cat{C} \to \ucat{Set} \\
        &\cat{C}(A, X) \coloneqq \set{ s: A \to X } \\
        &\cat{C}(f, g) \coloneqq T_{f,g}
      \end{aligned}
    \end{equation}

    \thmitem{def:hom_functor/unary} Fixing the first argument \( A \) in \eqref{eq:def:hom_functor/binary}, we instead obtain a covariant unary hom-functor:
    \begin{equation}\label{eq:def:hom_functor/unary/covariant}
      \cat{C}(A, \anon*): \cat{C} \to \ucat{Set}
    \end{equation}

    Analogously, fixing the second argument \( X \), we obtain a \hyperref[def:hom_functor/unary]{contravariant} unary hom-functor:
    \begin{equation}\label{eq:def:hom_functor/unary/contravariant}
      \cat{C}(\anon*, X): \cat{C}^{\opcat} \to \ucat{Set}
    \end{equation}
  \end{thmenum}
\end{definition}
\begin{defproof}
  It is sufficient to verify that \eqref{eq:def:hom_functor/binary} defines a functor. \ref{def:functor/CF2} can be seen to hold by inspecting the diagram:
  \begin{equation}\label{eq:def:hom_functor/inv_composition}
    \begin{aligned}
      \includegraphics[page=2]{output/def__hom_functor.pdf}
    \end{aligned}
  \end{equation}

  The other functor condition \ref{def:functor/CF1} is straightforward to prove.
\end{defproof}

\begin{proposition}\label{thm:currying_is_natural_isomorphism}
  \hyperref[def:function/currying]{Function currying} is a natural isomorphism between the functors
  \begin{align*}
    &\cat{Set}(A \times B, C)
    &\cat{Set}(A, \cat{Set}(B, C))
  \end{align*}

  More concretely, consider the following functors, which are loosely based in \fullref{def:hom_functor}:
  \begin{equation*}
    \begin{aligned}
      &V: \cat{Set}^3 \to \cat{Set} \\
      &V(A, B, C) \coloneqq \cat{Set}(A \times B, C) \\
      \Big[& V(f: X \to A, g: Y \to B, h: C \to Z) \Big](s: A \times B \to C) \coloneqq \smash{ \overbrace{ (x, y) \mapsto h\parens[\Bigg]{ s\parens[\Big]{ \underbrace{ f(x), g(y) }_{A \times B} } } }^{X \times Y \to Z} } \\
    \end{aligned}
  \end{equation*}
  and
  \begin{equation*}
    \begin{aligned}
      &W: \cat{Set}^3 \to \cat{Set} \\
      &W(A, B, C) \coloneqq \cat{Set}(A, \cat{Set}(B, C)) \\
      \Big[& W(f: X \to A, g: Y \to B, h: C \to Z) \Big](t: A \to \cat{Set}(B, C)) \coloneqq \smash{ \underbrace{ x \mapsto \overbrace{y \mapsto h\parens[\Bigg]{ \overbrace{t(f(x))}^{B \to C}\parens[\Big]{ g(y) } } }^{Y \to Z} }_{X \to \cat{Set}(Y, Z)} } \\
    \end{aligned}
  \end{equation*}

  Then the family of functions
  \begin{equation*}
    \begin{aligned}
      &\alpha: V \Rightarrow W \\
      &\alpha_{A,B,C}(s: A \times B \to C) \coloneqq a \mapsto b \mapsto s(a, b)
    \end{aligned}
  \end{equation*}
  is a \hyperref[thm:natural_isomorphism]{natural isomorphism}.
\end{proposition}
\begin{proof}
  The function \( \varphi \) is clearly invertible. Fix a triple of functions \( f: X \to A \), \( g: Y \to B \) and \( h: C \to Z \). For every \( s: A \times B \to C \) we have
  \begin{align*}
    [W(f, g, h)](\alpha_{A,B,C}(s))
    &=
    x \mapsto y \mapsto \parens[\Big]{ h\parens[\Big]{ [a \mapsto b \mapsto s(a, b)](f(x))(g(y)) } }
    = \\ &=
    x \mapsto y \mapsto h\parens[\Big]{ s(f(x), g(y)) }
    = \\ &=
    \alpha_{X,Y,Z}(V(f, g, h)),
  \end{align*}
  which proves that the following diagram commutes:
  \begin{equation}\label{eq:thm:currying_is_natural_isomorphism/diagram}
    \begin{aligned}
      \includegraphics[page=1]{output/thm__currying_is_natural_isomorphism.pdf}
    \end{aligned}
  \end{equation}
\end{proof}


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

%%% \documentclass{article}
%%% \usepackage{graphicx}
%%% \usepackage{color}

%%% \sloppy
%%% \definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}

%%% \begin{document}

\subsection*{Allan Overlapping Deviation}

\begin{par}
Example for algorithm OADEV.
\end{par} \vspace{1em}
\begin{par}
OADEV is an algorithm to compute the overlapping Allan deviation for a set of time-domain frequency data.
\end{par} \vspace{1em}
\begin{par}
See also W. J. Riley, "The Calculation of Time Domain Frequency Stability". Implementation: M. A. Hopcroft, \verb"mhopeng@gmail.com", Matlab Central.'
\end{par} \vspace{1em}

\subsubsection*{Contents}

\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item Generate sample data
   \item Call algorithm
   \item Display results
\end{itemize}

\subsubsection*{Generate sample data}

\begin{par}
A random numbers with normal probability distribution function will be generated into input data \lstinline{DI.y.v}. Next a drift will be added.
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
DI = [];
DI.y.v = 1.5 + 3.*randn(1, 1e3);
DI.y.v = DI.y.v + [1:1:1e3]./100;
\end{lstlisting}
\begin{par}
Lets suppose a sampling frequency is 1 Hz. The algorithm will generate all possible tau values automatically.
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
DI.fs.v = 1;
\end{lstlisting}

\subsubsection*{Call algorithm}

\begin{par}
Use QWTB to apply algorithm \lstinline{OADEV} to data \lstinline{DI}.
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
DO = qwtb('OADEV', DI);
\end{lstlisting}

        \begin{lstlisting}[style=output]
QWTB: no uncertainty calculation
\end{lstlisting} \color{black}

\subsubsection*{Display results}

\begin{par}
Log log figure is the best to see allan deviation results:
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
figure; hold on
loglog(DO.tau.v, DO.oadev.v, '-b')
loglog(DO.tau.v, DO.oadev.v + DO.oadev.u, '-k')
loglog(DO.tau.v, DO.oadev.v - DO.oadev.u, '-k')
xlabel('\tau (sec)');
ylabel('\sigma_y(\tau)');
title(['period = ' num2str(DI.fs.v)]);
grid('on'); hold off
\end{lstlisting}

\begin{center}
\includegraphics[width=0.7\textwidth]{algs_examples_published/OADEV_alg_example_01.pdf}
\end{center}

%%% \end{document}


\documentclass[11pt]{article}

\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{pseudocode}
\usepackage{url}
\usepackage{float}
\usepackage{subcaption}
\usepackage[backref, colorlinks=true, citecolor=red, urlcolor=blue, pdfauthor={Jyh-Ming Lien}]{hyperref}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
  \framebox{
    \vbox{
      \hbox to 5.78in { {\bf } \hfill #2 }
      \vspace{4mm}
      \hbox to 5.78in { {\Large \hfill #5  \hfill} }
      \vspace{2mm}
      \hbox to 5.78in { {\em #3 \hfill #4} }
    }
  }
  \end{center}
  \vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{#4}{#1}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{assumption}[theorem]{Assumption}

% 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.
\topmargin 0pt
\advance \topmargin by -\headheight
\advance \topmargin by -\headsep
\textheight 8.9in
\oddsidemargin 0pt
\evensidemargin \oddsidemargin
\marginparwidth 0.5in
\textwidth 6.5in

\parindent 0in
\parskip 1.5ex
%\renewcommand{\baselinestretch}{1.25}

\begin{document}

\lecture{Project 2: Hedcut}{Fall 2019}{William Austin}{CS 633 Computational Geometry}

\section{Summary of the hedcut method}

The hedcut method that is implemented in this project is closely related to the idea of stippling, which uses a combination of dots to represent an image. Originally, this style of drawing was used in newspapers because they are typically black-and-white, can be easily printed on a page, and retained the important details of the image throughout this process. However, these works are also produced manually by a skilled artist and take several hours to complete. Therefore, this project explores how this style of art can be generated in an automated way, based off of an input image.

The provided functionality uses the concepts described in the paper ``Weighted Voronoi Stippling'', which is based on the concept of centroidal Voronoi diagrams. In order for a Voronoi diagram to be centroidal, the generating points must also be the centroid, which can be interpreted as the center of mass. For images, we can calculate the intensity at each pixel: ((R + G + B) / 3), and interpret it as a density function. Then, for each Voronoi cell, we can compute the centroid, based on the ``weight'' and location of each pixel in the cell.

The implementation is an iterative algorithm that starts off with random samples from the image. Then, we repeatedly:
\begin{enumerate}
	\item Compute the Voronoi diagram for the given point locations, and
	\item For each cell, find the centroid, and use it as the generating point for the next iteration.
\end{enumerate}

We must introduce some stopping criteria so that the algorithm eventually halts. In our case, we can specify an upper limit to the number of iterations performed or the distance the centroid moves in a step (total or average.)

\section{Improvement of hedcuter method}

I've made several improvements to the provided functionality, listed below. In each section, I will give some examples, and intuition for the new features. A quick summary of the changes is given here, in the expanded options list for the hedcuter application:

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.3]{HeducterCommandOptions}
	\caption{Hedcuter Application Command Options}
\end{figure}

\subsection{Creating Voronoi Diagrams using OpenGL}

The first large improvement to the application was to use OpenGL to compute the Voronoi diagrams at each step in the algorithm. The idea is to construct a scene with a cone centered on the X-Y plane at each generating point. By fixing the camera to look at the all of the cones in the direction of the Z-axis, using a 2-D projection, the resulting scene is the Voronoi diagram.

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{VoronoiDiagram}
	\caption{Voronoi Diagram, as computed by OpenGL}
	\label{fig:voronoiDiagram}
\end{figure}

One of the problems that arises during the implementation of this feature is trying to map the regions in the rendered diagram back to the point that generated them. We do this by converting the index of the generating point $[0 \dots n - 1]$ into the RGB color-space by transforming the index into a point in the range $[0 \dots 256^3]$, and then representing it as $256^2 \cdot R + 256 \cdot G + B$. This tells Open GL what colors to use for the cones, and then we do the reverse transform to map the Voronoi regions of a certain color back to the correct generating point.

Some other challenges that arise include:
\begin{itemize}
	\item Model space in OpenGL is represented in X-Y coordinates, so (0, 0) is in the bottom-left of the screen, whereas OpenCV uses row-column format, with the pixel at (0, 0) in the upper-left of the screen. Therefore, when converting between the representations, we must flip the image, and reverse the coordinate order.
	\item OpenGL initialization requires another library to control the window system, such as GLUT. Offline rendering does not seem to be especially well supported.
	\item Internally, the OpenCV library uses a BGR representation for colors instead of the more traditional RGB. Therefore, we need to take care to convert correctly and make sure that the code is accessing the correct channel for the data structure.
\end{itemize}

Most of my code for this feature is in the \verb|vorgpu.hpp| and \verb|vorgpu.cpp| files. A few changes to other files were required to integrated the command line option and call the correct functionality. This is in the \verb|wcvt.cpp| file, in the \verb|compute_weighted_cvt()| function. The functionality is enabled by specifying the \verb|-useOpenGL| flag, with no options.

I was able to get good stippling results using the OpenGL option. The example below shows the original input on the left, and the generated hedcut with 4000 disks.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.48\linewidth}
	 	\includegraphics[width=\linewidth]{Snorlax}
	 	\caption{Original Image, Snorlax}
	 	\label{fig:snorlax}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Snorlax-OpenGL-4000}
		\caption{Hedcut Image using OpenGL with 4000 Disks, Snorlax}
		\label{fig:snorlaxOpenGL}
	\end{subfigure}
	\caption{OpenGL Example with Snorlax}
	\label{fig:snorlaxExample}
\end{figure}

Despite the complete implementation and reasonable output, I did not notice a large speedup when using the OpenGL functionality instead of the built-in method. In most cases, the total time taken is comparable. For example, the output below shows that OpenGL based method was slightly slower for 750 disks.

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{OpenGL-Performance}
	\caption{Relative OpenGL Performance}
	\label{fig:OpenGLPerformance}
\end{figure}

\subsection{Colored Disks, Grayscale Disks, and Background Color}

For the next feature to be added into the Hedcuter code, I added a few different ways to specify color in the output image. This includes:

\begin{itemize}
	\item Use the \verb|-diskColor R G B| option to specify a constant disk color. The default is black.
	\item Use the \verb|-bgColor R G B| option to specify a background color for the output. The default is no background (transparent).
	\item Use the \verb|-useGrayscaleColor| flag to create an image with disks based on the average grayscale intensity for each Voronoi cell to be represented.
	\item Use the \verb|-useAvgDiskColor| flag to create an image with disks based on the average color for each Voronoi cell to be represented.
\end{itemize}

Some sample results are shown below.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Mount-Rushmore}
		\caption{Original Image, Mount Rushmore}
		\label{fig:mountRushmore}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Mount-Rushmore-Red-15000}
		\caption{Red Hedcut Image with 15000 Disks}
		\label{fig:mountRusmoreRed}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Mount-Rushmore-Blue-15000}
		\caption{Blue Hedcut Image with 15000 Disks}
		\label{fig:mountRusmoreBlue}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Mount-Rushmore-Inverted-15000}
		\caption{Inverted Hedcut Image with 15000 Disks}
		\label{fig:mountRusmoreInverted}
	\end{subfigure}
	\caption{Color Example with Mount Rushmore}
	\label{fig:mountRushmoreEx}
\end{figure}

A more dynamic coloring approach can be seen by using the grayscale color and average color options. This is accomplished by simply averaging all of the cell colors together to choose an approximation of the input color when we create the disks for the hedcut.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.52\linewidth}
		\includegraphics[width=\linewidth]{Jordan-Pond}
		\caption{Original Image, Jordan Pond}
		\label{fig:jordanPond}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Jordan-Pond-Grayscale-10000}
		\caption{Jordan Pond, Grayscale, 10000 Disks}
		\label{fig:jordanPondGray}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Jordan-Pond-Color-10000}
		\caption{Jordan Pond, Colored, 10000 Disks}
		\label{fig:jordanPondColor}
	\end{subfigure}
	\caption{Colore Example with Jordan Pond}
	\label{fig:jordanPondExample}
\end{figure}

\subsection{Disk Sizing based on Cell Area and Intensity, with Regularization}

I have also implemented dynamic disk sizing to produced different visual effects in the final hedcut image. The first way of doing this is to scale the size of each disk by the size of the containing Voronoi cell. This is done by specifying \verb|-areaScaling scaleFactor|. In the example with Roger Federer, you can see that the disks on the handle of the racket and his grip are much larger than the rest of the disks in the second example, but much smaller in second example because we specified a negative value to invert the relationship.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.52\linewidth}
		\includegraphics[width=\linewidth]{Roger-Federer}
		\caption{Original Image, Roger Federer}
		\label{fig:rf}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Roger-Federer-AreaScale-12000}
		\caption{Roger Federer, Area scaled, 12000 Disks}
		\label{fig:rf2}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Roger-Federer-ReverseAreaScaling-12000}
		\caption{Roger Federer, Reverse area scaled, 12000 Disks}
		\label{fig:rf3}
	\end{subfigure}
	\caption{Area Scaling Example with Roger Federer}
	\label{fig:rf4}
\end{figure}

We can perform the same scaling operation, but use the average intensity of the cell as the input, instead of the cell area. This is shown below when we specify the \verb|-areaScaling scaleFactor| option. As expected, in the first image, the darker areas produce larger disks, and the lighter areas produce smaller disks. The relationship is reversed for the second example when we pass a negative argument.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.52\linewidth}
		\includegraphics[width=\linewidth]{Emilee-And-Lola}
		\caption{Original Image, Girl and Dog}
		\label{fig:gff}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Emilee-And-Lola-IntensityScaled2-10000}
		\caption{Intensity scaled, 10000 Disks}
		\label{fig:rff2}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Emilee-And-Lola-IntensityScaled-10000}
		\caption{Reverse Intensity scaled, 10000 Disks}
		\label{fig:rff3}
	\end{subfigure}
	\caption{Intensity Scaling Example with Girl and Dog}
	\label{fig:rff4}
\end{figure}

We can also apply a regularization process to artificially introduce some variation into the stippling. For example, in the area scaling example, most of the cells are about the same size with a few outliers. In the regularization process, we push the distribution of disk sizes to be more uniform, based on a regularization factor from 0 to 1. The images below show an image of train with negative area scaling and regularization values of 0, 0.3 and 0.8. This effect is enabled by using the \verb|-regularize factor| command.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Train-Canada}
		\caption{Original Image, Train}
		\label{fig:train}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Train-Canada-8000-1}
		\caption{Reverse area scaling, R = 0}
		\label{fig:train1}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Train-Canada-8000-2}
		\caption{Reverse area scaling, R = 0.3}
		\label{fig:train2}
	\end{subfigure}
		\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Train-Canada-8000-3}
		\caption{Reverse area scaling, R = 0.8}
		\label{fig:train3}
	\end{subfigure}
	\caption{Regularization Example with Train}
	\label{fig:mountRusddhmoreEx}
\end{figure}

\subsection{More Dynamic Initial Sampling}

We have also  implemented a tweak to allow greater control over the sampling process. This is enabled with the \verb|-samplingWeight weight| command option. The effect of this is that we are more selective when keeping or throwing away points during the initial sampling. A larger value means that lighter pixels are less likely to get chosen and darker pixels are more likely to be included. In the example below, we see the results for a sampling weight of 0 (uniform distribution), and a sampling weight of 3. Note that we have implemented this as a linear cutoff and large values may lead to an infinite loop because not enough points are eligible for inclusion, so care must be taken.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.52\linewidth}
		\includegraphics[width=\linewidth]{Chessboard}
		\caption{Original Image, Chessboard}
		\label{fig:gfff}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Chessboard-Points-1}
		\caption{Uniform sample points, 6000 Disks}
		\label{fig:rfff2}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Chessboard-6000-1}
		\caption{Stippled Chessboard 1, 600 Disks}
		\label{fig:rfff3}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Chessboard-Points-2}
		\caption{Weighted sample points, 6000 Disks}
		\label{fig:rffdf2}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Chessboard-6000-2}
		\caption{Stippled Chessboard 2, 600 Disks}
		\label{fig:rfffd3}
	\end{subfigure}
	\caption{Initial Sampling Example with Chessboard}
	\label{fig:rfff4}
\end{figure}

\subsection{Edge Detection}

The last feature that we have included in the application is the ability to incorporate information about edges in the input image into the stipple pattern. This enabled by using the \verb|-detectEdges alpha| option. If this is specified, we use OpenCV to detect edges in the input image, using the Sobel operator. Then, we create a linear combination of this output with the grayscale input image, to be used when computing the cell centroids at each step. This helps drag cell centers toward edges in the input image, creating a more well-defined output hedcut, as shown below.

\begin{figure}[H]
	\centering
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Portrait}
		\caption{Original Image, Portrait}
		\label{fig:trafin}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Portrait-Sobel}
		\caption{Portrait after Sobel Operator (k=3)}
		\label{fig:trxain1}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Portrait-7000-1}
		\caption{Portrait Stippling Default}
		\label{fig:traixn2}
	\end{subfigure}
	\begin{subfigure}[b]{.48\linewidth}
		\includegraphics[width=\linewidth]{Portrait-7000-2}
		\caption{Portrait Stippling with Edge Detection}
		\label{fig:traxin3}
	\end{subfigure}
	\caption{Edge Detection Example with Portrait}
	\label{fig:mountRusdxdhmoreEx}
\end{figure}

\section{Conclusion}

This project was a good example of how computer vision and computation geometry algorithms can be applied to interesting real world problems. All of the code that I implemented is completed, and the submitted application runs without any errors. However, there are several things that could be improved or expanded upon. Some examples are:

\begin{itemize}
	\item When using the OpenGL Voronoi diagram option, cells seem to converge somewhat more slowly than using the original method. All of my code is a drop-in replacement for the \verb|vor()| method, so I was a bit confused by this because the \verb|move_sites()| code is exactly the same, regardless of whether the option is on or not.
	\item There are several cases in the code where I have commented out print statements, or dead code. Throughout the course of this project, I spent considerable time experimenting with different ways of doing things and did not have time to clean up everything.
	\item An idea for improvement is to support alpha channels for the disk and background coloring functionality.
	\item Another improvement would be to have support for color scaling, so that stipples could be different shades of the same color (variable intensity). This would look like a grayscale image, but with a different hue.
	\item There are also performance improvements that could be made. For example, I did not implement Fortune's algorithm. In addition, my focus for this project was to enhance the visual aspects of the produced hedcut images, so it is likely that portions of my code could be implemented more cleanly and efficiently.
\end{itemize}

\bibliographystyle{plain}
\bibliography{report}

\end{document}


\chapter{补充内容}
\section{$L^{p}$ Spaces for $0<p<1$}
下面内容来自Matt Rosenzweig:
\subsection{Complete Quasi-Normed Space}
\begin{lemma}
If $p \in(0,1)$ and $a, b \geq 0$, then
\[
    (a+b)^{p} \leq a^{p}+b^{p}
\]
with equality if and only if either a or $b$ is zero.
\end{lemma}
\begin{proof}
    Define a function $f(t):=(1+t)^{p}-1-t^{p}$ for $t \geq 0 .$ Then $f^{\prime}(t)=p(1+t)^{p-1}-p t^{p-1}<0$ for all $t \in(0, \infty)$. Since $f(0)=0$, it follows that $f(t)<0$ on $\left(0, \infty\right.$. If $a, b \neq 0$, then substituting $t=\frac{a}{b}$
    \[
        \left(1+\frac{a}{b}\right)^{p}-1-\left(\frac{a}{b}\right)^{p}<0 \Longleftrightarrow\left(\frac{a+b}{b}\right)^{p}-1-\left(\frac{a}{b}\right)^{p}<0 \Longleftrightarrow(a+b)^{p}-\left(a^{p}+b^{p}\right)<0
    \]
    The equality criterion is obvious from the fact that $f$ is strictly decreasing on $(0, \infty)$.
    Recall that a pair $(X,\|\cdot\|)$, consiting of a (real or complex) vector space $X$ and a function $\|\cdot\|: X \rightarrow \mathbb{R}^{\geq 0}$ satisfying $\|\lambda x\|=|\lambda|\|x\|$, is a quasinormed space, if there exists $K \geq 1$ such that
    \[
        \|x+y\| \leq K(\|x\|+\|y\|) \quad \forall x, y \in X \qedhere
    \]
\end{proof}

\begin{proposition}
    For $0<p<\infty,\left(L^{p}(X, \mu),\|\cdot\|_{L^{p}}\right)$ is a complete quasinormed space.
\end{proposition}
\begin{proof}
    We can define a distance function on $L^{p}(X, \mu)$ by
    \[
        d(f, g):=\|f-g\|_{L^{p}}^{p}=\int_{X}|f-g|^{p} d \mu
    \]
    The only metric axiom which isn't obvious is the triangle inequality. Applying the preceding lemma, for all $f, g, h \in L^{p}(X, \mu)$
    \[
        d(f, g)+d(g, h)=\int_{X}\left(|f-g|^{p}+|g-h|^{p}\right) d \mu \geq \int_{X}(|f-g|+|g-h|)^{p} d \mu \geq \int_{X}|f-h|^{p} d \mu=d(f, h)
    \]
    Since $\left\|f_{n}-f_{m}\right\|_{L^{p}} \rightarrow 0, n, m \rightarrow \infty \Longleftrightarrow d\left(f_{n}, f_{m}\right) \rightarrow 0, n, m \rightarrow \infty$ by the continuity of the maps $x \mapsto x^{p}$ and $x \mapsto x^{\frac{1}{p}}$, to show that $d$ is a complete metric, it suffices to show that given a sequence $\left(f_{n}\right)_{n=1}^{\infty}$
    \[
        \left\|f_{n}-f_{m}\right\|_{L^{p}}^{p} \rightarrow 0, n, m \rightarrow \infty \Rightarrow \exists f \in L^{p},\left\|f_{n}-f\right\|_{L^{p}}^{p} \rightarrow 0, n \rightarrow \infty
    \]
    Let $\left(f_{n}\right)_{n=1}^{\infty}$ be such a sequence. Then we can construct a subsequence $\left(f_{n_{k}}\right)_{k \in \mathbb{N}}$ such that $\left\|f_{n_{k}}-f_{n_{k+1}}\right\|_{L^{p}}^{p} \leq \frac{1}{2^{k}}$. Define
    \[
        f=f_{n_{1}}+\sum_{k=1}^{\infty}\left(f_{n_{k+1}}-f_{n_{k}}\right)
    \]
    Since
    \[
        \left\|\sum_{k=1}^{N}\left(f_{n_{k+1}}-f_{n_{k}}\right)\right\|_{L^{p}}^{p} \leq \sum_{k=1}^{N}\left\|f_{n_{k+1}}-f_{n_{k}}\right\|_{L^{p}}^{p} \leq \sum_{k=1}^{N} \frac{1}{2^{k}} \leq 1 \forall N \in \mathbb{N}
    \]
    it follows from the monotone convergence theorem, $\left|f_{n_{1}}\right|+\sum_{k=1}^{\infty}\left|f_{n_{k+1}}-f_{n_{k}}\right| \in L^{p}(X, \mu) .$ Hence, by the Lebesgue dominated convergence theorem, $f \in L^{p}(X, \mu)$.
    \[
    f_{1}+\sum_{k=1}^{N}\left(f_{n_{k+1}}-f_{n_{k}}\right)=f_{n_{N+1}} \Rightarrow \lim _{k \rightarrow \infty} f_{n_{k}}=f
    \]
    Hence, $\left(f_{n}\right)_{n=1}^{\infty}$ is Cauchy with a convergent subsequence and therefore $\left\|f_{n}-f\right\|_{L^{p}}^{p} \rightarrow 0$, as $n \rightarrow \infty$
\end{proof}
\subsection{Inequalities}
\begin{proposition}[Reverse Hölder's]
    Let $q \in(0,1) .$ For $r<0$ and $g>0 \mu-a . e .$, define $\|g\|_{L^{r}}:=\left\|g^{-1}\right\|_{L^{|r|}}^{-1}$. Then for $f \geq 0$ and $g>0 \mu-$ a.e., we have that
    \[
        \|f g\|_{L^{1}} \geq\|f\|_{L^{q}}\|g\|_{L^{q^{\prime}}}
    \]
    where $\frac{1}{q}+\frac{1}{q^{\prime}}=1$
\end{proposition}
\begin{proof}
    If $f g \notin L^{1}(X, \mu)$ (i.e. $\|f g\|_{L^{1}}=\infty$ ) or $g^{-1} \notin L^{q^{\prime}}(X, \mu)$, then the inequality is trivial. So assume otherwise. Since $q \in(0,1)$ and $1=\frac{1}{q}+\frac{1}{q^{\prime}}$, we have that $q^{\prime}<0$ and
    \[
        \frac{1}{q}=\frac{1}{1}+\frac{1}{\left|q^{\prime}\right|}
    \]
    By Hölder's inequality applied to $f g$ and $g^{-1} \in L^{\left|q^{\prime}\right|}$,
    \[
        \|f\|_{L^{q}}=\left\|f g g^{-1}\right\|_{L^{q}} \leq\|f g\|_{L^{1}}\left\|g^{-1}\right\|_{L^{\prime q^{\prime}} \mid} \Rightarrow\|f\|_{L^{q}}\|g\|_{L^{q^{\prime}}}=\|f\|_{L^{q}}\left\|g^{-1}\right\|_{L^{\left|q^{\prime}\right|}} \leq\|f g\|_{L^{1}}\qedhere
    \]
\end{proof}

\begin{proposition}[Reverse Minkowski's]
    Let $f_{1}, \cdots, f_{N} \in L^{p}(X, \mu)$, where $0<p<1$ Then
    \[
        \sum_{j=1}^{N}\left\|f_{j}\right\|_{L^{p}} \leq\left\|\sum_{j=1}^{N}\left|f_{j}\right|\right\|_{L^{p}}
    \]
\end{proposition}
\begin{proof}
    By induction it suffices to consider the case $N=2 .$ If $\left\|\left|f_{1}\right|+\left|f_{2}\right|\right\|_{L^{p}}=\infty$, then the stated inequality is trivially true, so assume otherwise. Furthermore, if either $f_{1}$ or $f_{2}$ are zero $\mu-. a . e$, then the inequality is also trivial, so assume otherwise. By the reverse Hölder's inequality,
    \[
        \begin{aligned}
        \left\|\left|f_{1}\right|+\left|f_{2}\right|\right\|_{L^{p}}^{p}=\int_{X}\left\|f_{1}|+| f_{2}\right\|^{p} d x &=\int_{X}\left|f_{1}\right|\left\|f_{1}|+| f_{2}\right\|^{p-1} d x+\int_{X}\left|f_{2}\right|\left\|f_{1}|+| f_{2}\right\|^{p-1} d x \\
        & \geq\left\|f_{1}\right\|_{L^{p}}\left\|\left(\left|f_{1}\right|+\left|f_{2}\right|\right)^{p-1}\right\|_{L^{\frac{p}{p-1}}}+\left\|f_{2}\right\|_{L^{p}}\left\|\left(\left|f_{1}\right|+\left|f_{2}\right|\right)^{p-1}\right\|_{L^{\frac{p}{p-1}}} \\
        &=\left(\left\|f_{1}\right\|_{L^{p}}+\left\|f_{2}\right\|_{L^{p}}\right)\left\|\left|f_{1}\right|+\left|f_{2}\right|\right\|_{L^{p}}^{p-1}
        \end{aligned}
    \]
    Dividing both sides by $\left\|f_{1}+f_{2}\right\|_{L^{p}}^{p-1}$ yields the stated inequality.
\end{proof}
The preceding proposition shows that $\left(L^{p}(X, \mu),\|\cdot\|_{L^{p}}\right)$ is not a normed space when $0<p<\infty$.

\begin{lemma}
    Suppose $1 \leq \theta<\infty$. Then for $a_{1}, \cdots, a_{N} \in \mathbb{R}^{\geq 0}$,
    \[
        \left(\sum_{j=1}^{N} a_{j}\right)^{\theta} \leq N^{\theta-1} \sum_{j=1}^{N} a_{j}^{\theta}
    \]
\end{lemma}
\begin{proof}
    Since $\theta \geq 1$, the function $f(x)=x^{\theta}$ is convex. Hence,
    \[
        \left(\sum_{j=1}^{N} a_{j}\right)^{\theta}=f\left(\frac{\sum_{j=1}^{N} N a_{j}}{N}\right) \leq \frac{1}{N} \sum_{j=1}^{N} f\left(N a_{j}\right)=N^{\theta-1} \sum_{j=1}^{N} a_{j}^{\theta} \qedhere
    \]
\end{proof}

\begin{proposition}
    For $0<p<1$,
    \[
        \left\|\sum_{j=1}^{N} f_{j}\right\|_{L^{p}} \leq N^{\frac{1-p}{p}} \sum_{j=1}^{N}\left\|f_{j}\right\|_{L^{p}}
    \]
    Furthermore, $N^{\frac{1-p}{p}}$ is the best possible constant.
\end{proposition}
\begin{proof}
    If $\left\|f_{j}\right\|_{L^{p}}=\infty$ for some $j$, then the inequality trivially holds, so assume otherwise. Since $\frac{1}{p}>1$, by the preceding lemma,
    \[
        \left\|\sum_{j=1}^{N} f_{j}\right\|_{L^{p}}=\left(\int_{X}\left|\sum_{j=1}^{N} f_{j}\right|^{p} d x\right)^{\frac{1}{p}} \leq\left(\sum_{j=1}^{N} \int_{X}\left|f_{j}\right|^{p} d x\right)^{\frac{1}{p}} \leq N^{\frac{1}{p}-1} \sum_{j=1}^{N}\left(\int_{X}\left|f_{j}\right|^{p} d x\right)^{\frac{1}{p}}=N^{\frac{1-p}{p}} \sum_{j=1}^{N}\left\|f_{j}\right\|_{L^{p}}
    \]
    To see that $N^{\frac{1-p}{p}}$ is the best possible constant, let $E$ be a measurable set such that $\mu(E)=\alpha<\infty$, and set $E_{j}:=E$ and $f_{j}:=\mathbf{1}_{E}$ for $1 \leq j \leq N$. Then
    \[
        \left\|\sum_{j=1}^{N} f_{j}\right\|_{L^{p}}=\left(\sum_{j=1}^{N} \mu\left(E_{j}\right)\right)^{\frac{1}{p}}=(N \alpha)^{\frac{1}{p}}=N^{\frac{1-p}{p}}\left(N \alpha^{\frac{1}{p}}\right)=N^{\frac{1-p}{p}} \sum_{j=1}^{N} \mu\left(E_{j}\right)^{\frac{1}{p}}=N^{\frac{1-p}{p}} \sum_{j=1}^{N}\left\|f_{j}\right\|_{L^{p}}
    \]
\end{proof}
\subsection{Day's theorem}
\begin{lemma}
    Let $(X, \mathcal{A}, \mu)$ be a measure space with the property that given any $f \in L^{p}(X, \mu)$ for $p \in(0,1)$, the functional
    \[
        \mathcal{A} \rightarrow \mathbb{R}, E \mapsto \int_{E}|f|^{p} d \mu
    \]
    assumes all values between 0 and $\|f\|_{L^{p}}^{p}$. Then $L^{p}(X, \mu)$, with $0<p<1$, contains no convex open sets, other than $\emptyset$ and $L^{p}(X, \mu)$
\end{lemma}

\begin{proof}
    Let $\Omega$ be a nonempty convex open neighborhood of the origin in $L^{p}(X)$ and $f \in L^{p}(X)$ be arbitrary. Since $\Omega$ is open, there exists a ball $B_{\delta}$ about the origin contained in $\Omega .$ Choose $n \in \mathbb{Z}^{\geq 1}$ such that $\frac{\|f\|_{L^{p}}^{p}}{n^{1-p}} \leq \delta$ (i.e. $\left.n f \in B_{n \delta}\right)$. Note that we can choose such a $n$ precisely because $p \in(0,1)$. Using the intermediate value hypothesis for the measure space, there exists a measurable set $E_{1}$ such that
    \[
        \int_{E_{1}}|f|^{p} d \mu=\frac{1}{n} \int_{X}|f|^{p} d \mu=\frac{\|f\|_{L^{p}}^{p}}{n}
    \]
    Repeating the argument for $f_{1}=f \mathbf{1}_{E_{1}^{c}}$ and apply induction, we obtain a partition $\left\{E_{1}, \cdots, E_{n}\right\}$ of $X$ into disjoint measurable subsets such that $\int_{E_{j}}|f|^{p}=\frac{\|f\|_{L^{p}}^{p}}{n} \forall j=1, \cdots, n .$ Define $h_{j}:=n f \mathbf{1}_{E_{j}} .$ Then by our choice of $n$,
    \[
        \int_{X}\left|h_{j}\right|^{p} d \mu=\int_{E_{j}} n^{p}|f|^{p} d \mu=\frac{1}{n^{1-p}} \int_{X}|f|^{p} d \mu \leq \delta
    \]
    Hence, $h_{j} \in B_{\delta} \subset \Omega \forall j=1, \cdots, n$. By convexity,
    \[
        f=\frac{h_{1}+\cdots+h_{n}}{n} \in \Omega
    \]
    Since $f \in L^{p}(X, \mu)$ was arbitrary, we obtain that $\Omega=L^{p}(X, \mu)$
\end{proof}
\begin{corollary}
    With $(X, \mathcal{A}, \mu)$ as above, the natural topology for $L^{p}(X, \mu)$, with $0<p<1$, is not locally convex.
\end{corollary}

The following result, originally proven by M.M. Day, shows that the Hahn-Banach theorem fails for $L^{p}(X, \mu)$, when $0<p<1$. Specifically, the Hahn-Banach theorem may fail when we only assume the underlying space is quasi-normed.

\begin{theorem}[M.M. Day]
    Let $p \in(0,1)$ and let $T: L^{p}(X, \mu) \rightarrow Y$ be a continuous linear mapping of $L^{p}(X, \mu)$ into a locally convex $T_{0}$ space $Y$ (i.e. singletons are closed). Then $T$ is the zero map. In particular, $L^{p}(X, \mu)^{*}=\{0\}$
\end{theorem}

\begin{proof}
    Let $T$ be such a map, and let $\mathcal{B}$ be a convex local base for $Y$ at the origin. Let $W \in \mathcal{B}$. Then $T^{-1}(W)$ is a nonempty open convex subset of $L^{p}(X, \mu)$, hence by the preceding lemma, $T^{-1}(W)=L^{p}(X, \mu)$. Hence, $T\left(L^{p}(X, \mu)\right) \subset W$ for all $W \in \mathcal{B} .$ I claim that $\bigcap_{W \in \mathcal{B}} W=\{0\} .$ Assume the contrary, and let $x \neq 0$ be in the intersection. Since singletons are closed in $Y, Y \backslash\{x\}$ is an open neighborhood of $0 .$ Hence, $\bigcap_{W \in \mathcal{B}} W \subset(Y \backslash\{x\})$, which is a contradiction. We conclude that $T\left(L^{p}(X, \mu)\right)=\{0\} \Longleftrightarrow T=0$.
\end{proof}
\subsection{Non-Normability}
One might ask if $L^{p}(X, \mu), 0<p<1$, is normable for an arbitrary measure space $(X, \mathcal{A}, \mu)$. The following example shows that it is not, even for a nice measure space.

\begin{proposition}
    Let $\left(f_{n}\right)_{n=1}^{\infty}$ be a sequence in $L^{p}([0,1], \mathcal{L}, \lambda)$, where $\mathcal{L}$ is the Lebesgue $\sigma$-algebra and $\lambda$ is the Lebesgue measure on $[0,1] .$ Then there does not exist a norm $\|\cdot\|$ on $L^{p}([0,1])$ such that for any sequence $\left(f_{n}\right)_{n \in \mathbb{N}} \subset L^{p}([0,1]), f_{n} \rightarrow 0$ in $L^{p} \Rightarrow\left\|f_{n}\right\| \rightarrow 0, n \rightarrow \infty$
\end{proposition}

\begin{proof}
    Suppose such a norm $\|\cdot\|$ exists. I claim that there exists a positive constant $C<\infty$ such that $\|f\| \leq$ $C\|f\|_{L^{p}} \forall f \in L^{p}([0,1]) .$ Indeed, the map $L^{p}([0,1]) \rightarrow \mathbb{R}, f \mapsto\|f\|$ is evidently continuous. Hence, there exists $\delta>0$ such that $\|f\|_{L^{p}}<\delta \Rightarrow\|f\| \leq 1$. Then $\forall f \in L^{p}([0,1]), \frac{\alpha \delta f}{\|f\|_{L^{p}}} \in B_{\delta}$, where $0<|\alpha|<1 .$ Hence,
    \[
        \left\|\frac{\alpha \delta f}{\|f\|_{L^{p}}}\right\| \leq 1 \Rightarrow\|f\| \leq \frac{1}{\alpha \delta}\|f\|_{L^{p}}
    \]
    Letting $\alpha \rightarrow 1$, we see that the inequality holds for $C=\frac{1}{\delta} .$ Choose $C=\inf \left\{K:\|f\| \leq K\|f\|_{L^{p}} \forall f \in L^{p}([0,1])\right\}$ (Note that we do not exclude the possibility that $C=0$ ). By the intermediate value theorem, there exists $c \in(0,1)$ such that
    \[
        \int_{0}^{c}|f|^{p} d \lambda=\int_{c}^{1}|f|^{p} d \lambda=\frac{1}{2} \int_{0}^{1}|f|^{p} d \lambda
    \]
    Set $g=f \chi_{[0, c]}$ and $h=f \chi_{(c, 1]} .$ Then $f=g+h$ and $\|g\|_{L^{p}}=\|h\|_{L^{p}}=2^{-\frac{1}{p}}\|f\|_{L^{p}} .$ By the triangle inequality,
    \[
        \|f\| \leq\|g\|+\|h\| \leq C\left(\|g\|_{L^{p}}+\|h\|_{L^{p}}\right)=\frac{C}{2^{\frac{1}{p}-1}}\|f\|_{L^{p}}
    \]
    Since $p \in(0,1), \frac{C}{2^{\frac{1}{p}-1}} \leq C \Rightarrow C=0 \Rightarrow\|f\|=0 ,\forall f \in L^{p}(X, \mu)$, which contradicts that $\|\cdot\|$ is a norm.
\end{proof}

\begin{remark}
    In fact, the non-normability of $L^{p}([0,1])$, when $0<p<1$, follows from M.M. Day's thoerem. If $L^{p}([0,1])$ were normable, then the Hahn-Banach theorem would hold, contradicting that $L^{p}([0,1])^{*}=\{0\}$. So we have the more general assertion that given any measure space $(X, \mathcal{A}, \mu)$ which satisfies the hypotheses of Day's theorem, $L^{p}(X, \mu)$ is non-normable.
\end{remark}


\documentclass{article}
\usepackage{amsthm}
\usepackage{amssymb}

\newcommand{\ket}[1]{\ensuremath{\left\vert #1 \right \rangle}}
\newcommand{\weight}[1]{\ensuremath{\mathrm{w}\left(#1\right)}}

\begin{document}

\section*{Change in mutation operator}

Let $\Sigma=\{0,1\}$. Consider an $n$ length string $\mathbf{x} \in
\Sigma^n$. A flip in positions $\mathbf{a} \in \Sigma^n$ is defined
using the operator

\[
U_{\mathbf{a}} \ket{\mathbf{x}} = \ket{\mathbf{x} + \mathbf{a}}
\]

In the quantum setting there is a possibility of applying the phase
flip as well which is defined using the operator $V_\mathbf{b}$ as

\[
V_\mathbf{b} \ket{\mathbf{x}} =
(-1)^{\mathbf{b}^{\mathrm{T}}\mathbf{x}} \ket{\mathbf{x}}.
\]

In general for $\mathbf{a}$ and $\mathbf{b}$ in $\Sigma^n$, let
$W_{\mathbf{a},\mathbf{b}}$ denote the operator
$U_\mathbf{a}V_\mathbf{b}$, then candidate solutions $\ket{x}$ can be
mutated by applying any of the operators $W_{\mathbf{a},\mathbf{b}}$.

The parameter of interest here is the joint weight defined as

\[
\weight{\mathbf{a},\mathbf{b}} = \# \{ i | (a_i,b_i) \neq (0,0) \}.
\]

Local search and EA on an average make only one mutation per
step. This can be modeled by making transformation
$W_{\mathbf{a},\mathbf{b}}$ where the average joint weight
$\weight{\mathbf{a},\mathbf{b}}$.

\end{document}


\documentclass[a4paper,10pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[fleqn]{amsmath}

\begin{document}
Just a short explanation how the calculations for the graver sharpening jig works.
Normally, there are three 5 parameters that define the form of the base plate:

\begin{tabular}{ll}
 $\alpha$ & Angle of the cutting face \\
 $\beta$ & Angle of the v-shape \\
 $\theta$ & Angle of the heel \\
 $d$ & Elevation of the sharpening stone over the plane the jig is running on \\
 $s$ & Stick out, the length the graver is protruding from the front face of the jig
\end{tabular}

\vspace{2em}
In order to print a jig with a given width $b$, three main dimensions are calculated:
\vspace{1em}

\begin{minipage}{0.45\textwidth}
 \begin{tikzpicture}[scale=2]
\draw[thick] (0,0) -- (0,2)-- (2,2) -- (2,0) -- (1,-1) -- (0,0);
\draw [fill] (1,1) circle [radius=0.1];

\draw[teal, dashed] (0,1.8) -- (2,1.8);
\node[teal] at (0.3,1.7) {b};

\draw[teal, dashed] (1,2) -- (1,1);
\node[teal] at (1.2,1.5) {h1};

\draw[teal, dashed] (1,1) -- (1,-1);
\node[teal] at (1.2,0) {h2};

\draw[teal] (2.2,1) -- (2.4,1);
\draw[teal] (2.2,0) -- (2.4,0);
\draw[teal, dashed] (2.3,1) -- (2.3,0);
\node[teal] at (2.44,0.5) {h3};
\end{tikzpicture}
\end{minipage}
\begin{minipage}{0.45\textwidth}
 \begin{tabular}{lp{5cm}}
  $h1$ & Distance between the axis of the graver and the edge of the jig (for face sharpening) \\
  $h2$ & Distance between the axis of the graver and the tip of the jig (for the heels) \\
  $h3$ & Height from graver axis to the lower corners (for the heels) \\
 \end{tabular}
\end{minipage}

With some base geometry the dimensions can be found to be:
$$
    h_1 = \frac{s \cdot \sin \alpha  + d}{\cos \alpha}
$$
$$
    h_2 = \frac{s \cdot \sin \theta  + d}{\cos \theta \cdot \sin \frac{\beta}{2}}
$$
$$
    h_3 = h_2 - \frac{b}{2 \tan \frac{\beta}{2}}
$$

\section*{Example (distances in mm, angles in °):}
\begin{minipage}{0.65\textwidth}
given: \\
$b=50, d=20, s=30$ \\ $\alpha=45, \beta=105, \theta=8 $
$$
    h_1 = \frac{30 \cdot \sin 45  + 20}{\cos 45} \approx \frac{41.2}{0.71} \approx 49.5
$$
$$
    h_2 = \frac{30 \cdot \sin 8  + 20}{\cos 8 \cdot \sin 52.5} \approx \frac{24.2}{0.8} \approx 30.8
$$
$$
    h_3 = 30.8 - \frac{25}{\tan 52.5} \approx 11.6
$$

\end{minipage}
\begin{minipage}{0.25\textwidth}
\begin{tikzpicture}[scale=0.05]
\draw[thick] (0,0) -- (0,49.5) -- (50,49.5) -- (50,0) -- (50,-11.6) -- (25,-30.8) -- (0,-11.6) -- (0,0) ;
\draw [fill] (25,0) circle [radius=1.15];
\end{tikzpicture}
\end{minipage}

\end{document}