\subsection{Groups}\label{subsec:groups}

\begin{definition}\label{def:monoid_inverse}
  Let \( M \) be a \hyperref[def:monoid]{monoid}. We say that \( y \) is the \term{left inverse} (resp. \term{right inverse}) of \( x \) if \( yx = e \) (resp. \( xy = e \)).

  If \( y \) is simultaneously a left and right inverse of \( x \), we call a \term{two-sided inverse} or simply an \term{inverse} of \( x \) and denote it by \( x^{-1} \). It is unique by \fullref{thm:monoid_inverse_unique}. This notation is consistent with monoid exponentiation defined in \fullref{def:monoid/exponentiation}.

  We call \( x \) \term{invertible} if it has a two-sided inverse.
\end{definition}

\begin{proposition}\label{thm:monoid_inverse_unique}
  For every element \( x \) of any monoid, the (two-sided) \hyperref[def:monoid_inverse]{inverse} \( x^{-1} \) of \( x \), if it exists, is unique.
\end{proposition}
\begin{proof}
  If \( y \) and \( z \) are both inverses of \( x \), then
  \begin{equation*}
    y = ey = zxy = ze = z.
  \end{equation*}
\end{proof}

\begin{definition}\label{def:zero_morphisms}
  Let \( \cat{C} \) be a \hyperref[def:universal_objects/zero]{pointed category} with a fixed \hyperref[def:universal_objects/zero]{zero object} \( Z \).

  \begin{thmenum}
    \thmitem{def:zero_morphisms/morphism}\mcite{nLab:zero_morphism} For every pair of objects \( A \) and \( B \) in \( \cat{C} \), there exists unique morphism, called the \term{zero morphism}, that \hyperref[def:factors_through]{uniquely factors through} \( Z \):
    \begin{equation}\label{eq:def:zero_morphisms/morphism}
      \begin{aligned}
        \includegraphics[page=1]{output/def__zero_morphisms.pdf}
      \end{aligned}
    \end{equation}

    We denote this zero morphism by \( 0_{A,B} \).

    \thmitem{def:zero_morphisms/kernel} The \term{kernel} cone of a morphism \( f: A \to B \) is the \hyperref[eq:def:equalizers/equalizer]{equalizer} cone of \( f \) and \( 0_{A,B} \).

    By \fullref{thm:equalizer_invertibility}, a kernel morphism is necessarily a monomorphism. A monomorphism is \term{normal} if it is a kernel.

    \thmitem{def:zero_morphisms/cokernel} \hyperref[thm:categorical_principle_of_duality]{Dually}, the \term{cokernel} cocone of a morphism \( f: A \to B \) is the \hyperref[eq:def:equalizers/coequalizer]{coequalizer} cocone of \( f \) and \( 0_{A,B} \).

    By \fullref{thm:equalizer_invertibility}, a cokernel morphism is necessarily an epimorphism. An epimorphism is \term{normal} if it is a kernel.
  \end{thmenum}
\end{definition}

\begin{definition}\label{def:group}
  A \term{group} is a \hyperref[def:monoid]{monoid} in which every element has an \hyperref[def:monoid_inverse]{inverse}. Groups are the most well-studied and most well-behaved magmas. Many useful properties like \hyperref[thm:def:group/cancellative]{cancellation} rely on associativity, so we do not consider non-associative groups.

  Groups have the following metamathematical properties:
  \begin{thmenum}
    \thmitem{def:group/theory} We can construct a \hyperref[def:first_order_theory]{first-order theory} for groups by adding a unary \hyperref[def:first_order_language/func]{functional symbol} \( (\anon)^{-1} \) to the language and the axiom
    \begin{equation}\label{eq:def:group/theory/inverse_axiom}
      \qforall \xi (\xi \cdot \xi^{-1} = e \wedge \xi^{-1} \cdot \xi = e)
    \end{equation}
    to the \hyperref[def:monoid/theory]{theory of monoids}.

    \thmitem{def:group/function_parity} A \hyperref[def:function]{function} \( \varphi: G \to H \) between two groups is called \term{even} if, for every \( x \in G \), we have
    \begin{equation}\label{eq:def:group/function_parity/even}
      \varphi(x^{-1}) = \varphi(x)
    \end{equation}
    and \term{odd} if
    \begin{equation}\label{eq:def:group/function_parity/odd}
      \varphi(x^{-1}) = \varphi(x)^{-1}.
    \end{equation}

    \thmitem{def:group/homomorphism} A \hyperref[def:first_order_homomorphism]{first-order homomorphism} between the groups \( G \) and \( H \) is an odd \hyperref[def:monoid/homomorphism]{monoid homomorphism}.

    As shown in \fullref{thm:group_homomorphism_single_condition}, however, the conditions \eqref{eq:def:pointed_set/homomorphism} and \eqref{eq:def:group/function_parity/odd} are redundant.

    \thmitem{def:group/submodel} The set \( A \subseteq G \) is a \hyperref[thm:substructure_is_model]{submodel} of \( G \) if it is a \hyperref[def:monoid/submodel]{submonoid} and if \( x \in A \) implies \( x^{-1} \in A \). We say that \( A \) is a \term{subgroup} of \( G \).

    As a consequence of \fullref{thm:positive_formulas_preserved_under_homomorphism}, the image of a group homomorphism is a subgroup of its range.

    For an arbitrary subset \( A \) of \( G \), we denote the \hyperref[def:first_order_generated_substructure]{generated submodel} by \( \braket{ A } \). In addition to the elements of \( A \), \( \braket{ A } \) contains their products and inverses, the products of their products and inverses, etc...

    The \hyperref[def:free_group]{free group} builds a group out of a plain set; furthermore, as a consequence of \fullref{thm:group_presentation}, every group is a \hyperref[def:group/quotient]{quotient} of a free group. Compare this to \hyperref[def:free_semimodule]{free semimodules} and \hyperref[def:polynomial_algebra]{polynomial semirings}.

    \thmitem{def:group/trivial} The \hyperref[thm:substructures_form_complete_lattice/bottom]{trivial} group is the \hyperref[def:pointed_set/trivial]{trivial pointed set} \( \set{ e } \).

    \thmitem{def:group/exponentiation} We extend \hyperref[def:monoid/exponentiation]{monoid exponentiation} to all integers by setting
    \begin{equation*}
      x^{-n} \coloneqq (x^n)^{-1}.
    \end{equation*}

    This operation behaves well as shown in \fullref{thm:def:group/negative_power}.

    \thmitem{def:group/category} The \hyperref[def:category_of_small_first_order_models]{category of \( \mscrU \)-small models} of groups \( \ucat{Grp} \) is \hyperref[def:concrete_category]{concrete} over \hyperref[def:monoid]{\( \ucat{Mon} \)}.

    By \fullref{thm:def:group/involution}, \( \ucat{Grp} \) is also a concrete category over \( \ucat{Inv} \).

    The unique up to an isomorphism zero object in this category is the trivial group \( \set{ e } \). The \hyperref[def:zero_morphisms/morphism]{zero morphism} from \( G \) to \( H \) is
    \begin{equation*}
      \begin{aligned}
        &0_{G,H}: G \to H \\
        &0_{G,H}(x) \coloneqq e_H.
      \end{aligned}
    \end{equation*}

    We will define the \hyperref[def:free_group]{free group} functor in \fullref{subsec:free_groups}. Then from \fullref{thm:first_order_categorical_invertibility} it will follow that monomorphisms are precisely the injective homomorphisms, and that the \hyperref[def:subobject_and_quotient]{categorical subobjects} correspond to subgroups.

    Unlike in the category \hyperref[def:monoid/category]{\( \cat{Mon} \)} of monoids, in \( \cat{Grp} \) every epimorphism is surjective. We will prove this in \fullref{thm:group_epimorphisms_are_surjective}. Along with \fullref{thm:group_epimorphisms_are_normal}, this shows that the \hyperref[def:subobject_and_quotient]{categorical quotient objects} correspond to \hyperref[def:group/quotient]{quotient groups}, which we will define shortly.

    To avoid circularity, in this section, we will avoid using that monomorphisms are injective and epimorphism are surjective.

    \thmitem{def:group/kernel} The \term{kernel} of a group homomorphism \( \varphi: G \to H \) is the subgroup
    \begin{equation*}
      \ker \varphi \coloneqq \varphi^{-1}(e_H) = \set{ x \in G \given \varphi(x) = e_H }.
    \end{equation*}

    This coincides with the notion of a categorical kernel defined in \fullref{def:zero_morphisms/kernel}. Similarly to \fullref{ex:equalizers_in_set/equalizer}, \( \ker \varphi \) is the equalizer of \( \varphi \) and the zero morphism \( 0_{G,H} \).

    This equivalence holds much more generally, even for \hyperref[def:pointed_set]{pointed sets}, however speaking of kernels is only established when we have an appropriate notion of cokernels. As we will see in \fullref{def:group/quotient}, cokernels are very well-behaved for groups, but not in general. Some related problems are highlighted in \cite[ch. 8]{Golan2010}. \Fullref{thm:def:group/kernel_cokernel_compatibility} expresses the compatibility between group kernels and cokernels.

    \thmitem{def:group/quotient} Consider the group homomorphism \( \varphi: G \to H \). We will find its \hyperref[def:zero_morphisms/cokernel]{cokernel}. This will highlight several very fundamental facts about groups, especially quotient groups. In practice, quotients are conveniently characterized by \fullref{thm:quotient_group_universal_property}.

    Similarly to \fullref{ex:equalizers_in_set/coequalizer}, the cokernel is an \hyperref[thm:equivalence_partition]{equivalence partition} of \( H \). The partitioning relation is different, however. An equivalence relation that is compatible with the operations of an algebraic structure is called a \term{congruence}. For the group \( H \), the equivalence relation \( \cong \) is a congruence if:
    \begin{itemize}
      \item It is compatible with the group operation: \( x \cong x' \) and \( y \cong y' \) imply \( x y \cong x' y' \).
      \item It is compatible with identities: \( e_H \cong x \) implies \( y \cong xy \) for all \( y \in H \). This easily follows from the first condition.
      \item It is compatible with inverses: \( x \cong x' \) implies \( x^{-1} \cong x'^{-1} \). This also follows from the first condition: \( x^{-1} \cong x^{-1} \) implies \( e \cong x^{-1} x' \), and thus \( x'^{-1} \cong x^{-1} \).
    \end{itemize}

    We need congruences since we are working with groups and group homomorphisms rather than sets and functions. We define \( \cong \) to be the smallest congruence relation containing
    \begin{equation*}
      \set{ (s(g), e_H) \given g \in G }.
    \end{equation*}

    Denote the partition \( H / {\cong} \) by \( Q \). Define a group operation on \( Q \) as \( [x] \cdot [y] = [xy] \).
    \begin{itemize}
      \item This operation is well-defined since group congruences are compatible with the group operation. We are thus free to denote it via juxtaposition.
      \item The coset \( [e_H] \) is the identity of \( Q \) since congruences are compatible with identities.
      \item The coset \( [x]^{-1} \) is the inverse of \( [x] \) since congruences are compatible with inverses.
    \end{itemize}

    Therefore, \( Q \) is a group and \( \pi(x) \coloneqq [x] \) is a group homomorphism. The pair \( (Q, \pi) \) is thus a categorical cokernel of \( \varphi \) by the same argument as in \fullref{ex:equalizers_in_set/coequalizer}.

    Denote the identity \( [e_H] \) by \( N \). It is a subgroup of \( H \):
    \begin{itemize}
      \item It contains the identity \( e_H \).
      \item It is closed under the group operation. Indeed, if \( [x] = [y] = N \), then
      \begin{equation*}
        [xy] = [x][y] = NN = N.
      \end{equation*}

      \item It is closed under the group inverse. Indeed, \( [x^{-1} x] = N \) for every \( x \in H \). If \( [x] = N \), then \( [x^{-1}] N = N \), and hence \( [x^{-1}] = N \).

      \item It possesses one additional important property. If \( [x] = N \), then not only \( x \in N \), but also \( y^{-1} x y \in N \) for every \( y \in H \). This holds because
      \begin{equation*}
        [y^{-1} x y]
        =
        [y^{-1}] [x] [y]
        =
        [y^{-1}] [y]
        =
        [y]^{-1} [y]
        =
        N.
      \end{equation*}
    \end{itemize}

    This last property distinguishes \( N \) from the \hyperref[def:multi_valued_function/image]{image} of \( \varphi \). A subgroup satisfying this property is called a \term{normal subgroup}. See \fullref{thm:normal_subgroup} for equivalent conditions. If the image \( \img \varphi \) is a normal subgroup of \( H \), \( \varphi \) is a normal epimorphism in the sense of \fullref{def:zero_morphisms/cokernel}.

    Obviously \( \img \varphi \subseteq N \). Since \( Q \) is a colimit, \( N \) must be the smallest normal subgroup containing \( \img \varphi \).

    It is more intriguing that \( [x] = xN \) for every \( x \in H \). This can be shown as follows:
    \begin{itemize}
      \item Suppose first that \( y \in xN \), i.e. \( y = xn \) for some \( n \in N \). Then
      \begin{equation*}
        y \in [y] = [xn] = [x] N = [x].
      \end{equation*}

      Generalizing on \( y \), we obtain that \( xN \subseteq [x] \).

      \item Conversely, let \( y \in [x] \). Obviously \( x = y (y^{-1} x) \). Then
      \begin{equation*}
        [x^{-1} y] = [x^{-1}] [y] = [x]^{-1} [y] = [x]^{-1} [x] = N.
      \end{equation*}

      Hence, \( x^{-1} y \in N \) and \( y \in xN \). Generalizing on \( y \), we obtain that \( [x] \subseteq xN \).
    \end{itemize}

    Therefore, all cosets in the quotient group \( Q = H / {\cong} \) are translations of the identity \( N \). In particular, in the notation of \hyperref[def:magma/powet_set]{power set operations}, it follows that
    \begin{equation*}
      xyN = xN yN.
    \end{equation*}

    Finally, given a normal subgroup \( N \) of an arbitrary group \( G \), we can define the \term{quotient group} \( G / N \) as the cokernel of the inclusion \( \iota: N \to G \). That is, \( G / N \) consists of the cosets \( xN \) for \( x \in G \) with the group operation \( xN yN = xyN \).

    \thmitem{def:group/simple} If the only proper \hyperref[thm:normal_subgroup_equivalences]{normal subgroup} of \( G \) is the \hyperref[def:group/trivial]{trivial subgroup} \( \set{ e_G } \), we say that \( G \) is a \term{simple group}.

    The trivial group itself is not simple, because it has no proper subgroups.
  \end{thmenum}
\end{definition}

\begin{example}\label{ex:power_set_is_not_a_group}
  The \hyperref[def:magma/power_set]{power set magma} \( \pow(G) \) of a group \( G \) is a monoid, but it is not a group unless \( G \) is trivial.
\end{example}

\begin{proposition}\label{thm:def:group}
  Every \hyperref[def:group]{group} \( G \) has the following basic properties:
  \begin{thmenum}
    \thmitem{thm:def:group/cancellative} The (binary) group operation is \hyperref[def:magma/cancellative]{cancellative}.
    \thmitem{thm:def:group/identity_inverse} The identity \( e \) is its own inverse.
    \thmitem{thm:def:group/inverse_composition} \( (xy)^{-1} = y^{-1} x^{-1} \).
    \thmitem{thm:def:group/involution} \( x = (x^{-1})^{-1} \)
    \thmitem{thm:def:group/negative_power} For any positive integer \( n \), \( (x^n)^{-1} = (x^{-1})^n \)
    \thmitem{thm:def:group/inverse_isomorphism} The map \( x \mapsto x^{-1} \) is a group isomorphism.
    \thmitem{thm:def:group/zero_kernel} The \hyperref[def:group/kernel]{kernel} of a group homomorphism \( \varphi: G \to H \) is trivial if and only if \( \varphi \) is an \hyperref[def:first_order_homomorphism_invertibility/embedding]{embedding} (injective homomorphism).

    \thmitem{thm:def:group/kernel_cokernel_compatibility} For a \hyperref[def:group/quotient]{quotient group} \( G / N \) with canonical projection \( \pi(x) \coloneqq xN \), the \hyperref[def:group/kernel]{kernel} of \( \pi \) is \( N \).

    \thmitem{thm:def:group/kernel_is_normal_subgroup} The kernel of a group homomorphism is a \hyperref[thm:normal_subgroup_equivalences]{normal subgroup}.
  \end{thmenum}
\end{proposition}
\begin{proof}
  \SubProofOf{thm:def:group/cancellative} If \( x = y \), obviously \( xz = yz \) and \( zx = zy \). Now if \( xz = yz \), we have
  \begin{equation*}
    x = x(zz^{-1}) = (xz)z^{-1} = (yz)z^{-1} = y(zz^{-1}) = y.
  \end{equation*}

  The case \( zx = zy \) is analogous.

  \SubProofOf{thm:def:group/identity_inverse} \( ee = e \).
  \SubProofOf{thm:def:group/inverse_composition}
  \begin{equation*}
    (xy) (y^{-1} x^{-1})
    =
    x (y y^{-1}) x^{-1}
    =
    e
    =
    y^{-1} (x^{-1} x) y
    =
    (y^{-1} x^{-1}) (xy).
  \end{equation*}

  \SubProofOf{thm:def:group/involution}
  \begin{equation*}
    (x^{-1})^{-1}
    =
    x x^{-1} (x^{-1})^{-1}
    =
    x.
  \end{equation*}

  \SubProofOf{thm:def:group/negative_power} Using \fullref{thm:def:group/involution},
  \begin{equation*}
    x^{-n}
    =
    (x^n)^{-1}
    =
    x^{-1} \cdots x^{-1}
    =
    (x^{-1})^n.
  \end{equation*}

  \SubProofOf{thm:def:group/inverse_isomorphism} Trivial.

  \SubProofOf{thm:def:group/zero_kernel}
  \SufficiencySubProof* Suppose that \( \ker \varphi = \set{ e_H } \) and \( \varphi(x) = \varphi(y) \). Then
  \begin{equation*}
    e_H = \varphi(x) \varphi(y)^{-1} = \varphi(x y^{-1}).
  \end{equation*}

  Thus, \( x y^{-1} \in \ker \varphi \), and hence \( x = y \).

  Therefore, \( \varphi \) is injective.

  \NecessitySubProof* Suppose that \( \varphi \) is injective. Since \( \varphi(e_G) = e_H \), \( \varphi(x) = e_H \) implies that \( x = e_G \).

  \SubProofOf{thm:def:group/kernel_cokernel_compatibility} Trivial.

  \SubProofOf{thm:def:group/kernel_is_normal_subgroup} For a homomorphism \( \varphi: G \to H \), if \( x \in \ker \varphi \), then
  \begin{equation*}
    \varphi(y^{-1} x y) = \varphi(y)^{-1} \varphi(x) \varphi(y) = \varphi(y)^{-1} \varphi(y) = e_H,
  \end{equation*}
  and thus \( y^{-1} x y \in \ker \varphi \).
\end{proof}

\begin{proposition}\label{thm:group_homomorphism_single_condition}
  A function between groups is a \hyperref[def:group/homomorphism]{group homomorphism} if and only if it satisfies \eqref{eq:def:magma/homomorphism}.
\end{proposition}
\begin{proof}
  \SufficiencySubProof \eqref{eq:def:magma/homomorphism} is required to hold by definition.

  \NecessitySubProof Let the function \( \varphi: G \to H \) satisfy \eqref{eq:def:magma/homomorphism}. Then it preserves identities, i.e. is a \hyperref[def:pointed_set/homomorphism]{pointed set homomorphism}. Indeed, we have
  \begin{equation*}
    e_H \varphi(e_G) = \varphi(e_G) = \varphi(e_G e_G) = \varphi(e_G) \varphi(e_G).
  \end{equation*}

  By \fullref{thm:def:group/cancellative}, \( \varphi \) is cancellative, and hence \( e_H = \varphi(e_G) \).

  Inverses are preserved (i.e. \eqref{eq:def:group/function_parity/odd} holds) because
  \begin{equation*}
    \varphi(x^{-1})
    =
    \varphi(x^{-1}) e_H
    =
    \varphi(x^{-1}) \varphi(x) \varphi(x)^{-1}
    =
    \varphi(x^{-1} x) \varphi(x)^{-1}
    =
    e_H \varphi(x)^{-1}
    =
    \varphi(x)^{-1}.
  \end{equation*}

  Therefore, \( \varphi \) is indeed a group homomorphism.
\end{proof}

\begin{lemma}\label{thm:group_operation_induces_bijections}
  For each element \( x \) of a group \( G \), consider the function \( \varphi_x \coloneqq x \id_G \), i.e.
  \begin{equation*}
    \begin{aligned}
      &\varphi_x: G \to G \\
      &\varphi_x(y) \coloneqq x \cdot y.
    \end{aligned}
  \end{equation*}

  This is a bijective function (but not necessarily a group isomorphism).
\end{lemma}
\begin{proof}
  \SubProofOf[def:function_invertibility/injective]{injectivity} If \( y, y' \in G \) and \( \varphi_x(y) = \varphi_x(y') \), we have
  \begin{equation*}
    xy = \varphi_x(y) = \varphi_x(y') = xy'.
  \end{equation*}

  By \fullref{thm:def:group/cancellative}, \( y = y' \). Therefore, \( \varphi_x \) is injective.

  \SubProofOf[def:function_invertibility/surjective]{surjectivity} If \( z \in G \), then \( z = x(x^{-1} z) \). Therefore, \( z = \varphi_x(x^{-1} z) \), and thus every member of \( G \) has a preimage. Thus, \( \varphi_x \) is surjective.
\end{proof}

\begin{proposition}\label{thm:invertible_submonoid_is_group}
  The set of all \hyperref[def:monoid_inverse]{invertible} elements of a \hyperref[def:monoid]{monoid} is a \hyperref[def:group]{group}.
\end{proposition}
\begin{proof}
  Fix a monoid \( M \).

  \begin{itemize}
    \item \( e_M \) is invertible.
    \item If \( x \) and \( y \) are invertible, then \( xy \) is invertible with inverse \( y^{-1} x^{-1} \).
    \item If \( x \) is invertible with inverse \( x^{-1} \), then \( x^{-1} \) is invertible with inverse \( x \).
  \end{itemize}

  Therefore, the set of invertible elements is a submonoid and is closed under inverses.
\end{proof}

\begin{definition}\label{def:subgroup_cosets}
  Let \( H \subseteq G \) be a subgroup of \( G \). Even if \( H \) is not normal, we can define the \term{left} and \term{right cosets}
  \begin{equation*}
    x H \coloneqq \set{ xh \given h \in H }
    \quad\quad
    H x \coloneqq \set{ hx \given h \in H }.
  \end{equation*}

  The \term{index} \( [G : H] \) of \( H \) in \( G \) is \hyperref[def:cardinal]{cardinality} of the family of all left cosets.

  The discussion in \fullref{def:group/quotient} can be generalized to show that  \( \set{ xH \given x \in G } \) is a \hyperref[def:set_partition]{partition} of \( G \) into \hyperref[def:equinumerosity]{equinumerous} sets. If \( H \) is not normal, this partition is not induced by a congruence, and we cannot form a quotient group using a non-normal subgroup. Nonetheless, left and right cosets still turn out useful.
\end{definition}

\begin{proposition}\label{thm:group_coset_bijection}
  The family of all \hyperref[def:subgroup_cosets]{left cosets} of a subgroup is \hyperref[def:equinumerosity]{equinumerous} to the family of all right cosets.
\end{proposition}
\begin{proof}
  Fix a subgroup \( H \) of \( G \), and consider the function \( xH \mapsto Hx \) taking left cosets to right cosets.

  It is well-defined because, if \( x H = x' H \), then there exists \( h \), such that \( x = x' h \), and thus
  \begin{equation*}
    H x' = H h^{-1} x = H x.
  \end{equation*}

  It is injective by the same converse argument, and it is surjective by definition. Therefore, it is bijective.
\end{proof}

\begin{proposition}\label{thm:normal_subgroup_equivalences}
  For a subgroup \( N \) of \( G \), the following conditions are equivalent:
  \begin{thmenum}
    \thmitem{thm:normal_subgroup_equivalences/congruence} For every element \( x \) of \( G \), we have the set equality
    \begin{equation}\label{eq:thm:normal_subgroup_equivalences/congruence}
      x^{-1} N x = N.
    \end{equation}

    This is the definition of a normal subgroup obtained in \fullref{def:group/quotient}.

    \thmitem{thm:normal_subgroup_equivalences/cosets} The partitions induced by the \hyperref[def:subgroup_cosets]{left and rights cosets} of \( N \) coincide.

    \thmitem{thm:normal_subgroup_equivalences/kernel} \( N \) is the \hyperref[thm:group_kernels]{kernel} of some group homomorphism.
  \end{thmenum}

  In particular, kernels are always normal subgroups.
\end{proposition}
\begin{proof}
  This is the group-theoretic analog to \fullref{thm:equivalence_partition}.

  \ImplicationSubProof{thm:normal_subgroup_equivalences/congruence}{thm:normal_subgroup_equivalences/cosets} For any \( x \in G \)
  \begin{equation*}
    N x = (x N x^{-1})x = x N(x^{-1}x) = x N,
  \end{equation*}
  thus every left coset is a right coset and vice versa.

  \ImplicationSubProof{thm:normal_subgroup_equivalences/cosets}{thm:normal_subgroup_equivalences/kernel} We can take the \hyperref[def:group/quotient]{canonical projection} \( \pi(x) \coloneqq x N \) as the homomorphism. By \fullref{thm:def:group/kernel_cokernel_compatibility}, \( \ker \pi = N \).

  \ImplicationSubProof{thm:normal_subgroup_equivalences/kernel}{thm:normal_subgroup_equivalences/congruence} Let \( \varphi: G \to H \) be a group homomorphism and fix any \( x \in G \). Denote \( N \coloneqq \ker(f) \). By \fullref{thm:def:group/kernel_is_normal_subgroup}, it is a normal subgroup in the sense of \fullref{def:group/quotient}, i.e. it satisfies \eqref{eq:thm:normal_subgroup_equivalences/congruence}.
\end{proof}

\begin{theorem}[Quotient group universal property]\label{thm:quotient_group_universal_property}\mcite[thm. II.7.12]{Aluffi2009}
  For every \hyperref[def:group]{group} \( G \) and \hyperref[thm:normal_subgroup_equivalences]{normal subgroup} \( N \), the \hyperref[def:group/quotient]{quotient group} \( G / N \) has the following \hyperref[rem:universal_mapping_property]{universal mapping property}:
  \begin{displayquote}
    Every group homomorphism \( \varphi: G \to H \) satisfying \( N \subseteq \ker \varphi \) \hyperref[def:factors_through]{uniquely factors through} \( G / N \). That is, there exists a unique homomorphism \( \widetilde{\varphi}: G / N \to H \), such that the following diagram commutes:
    \begin{equation}\label{eq:thm:quotient_group_universal_property/diagram}
      \begin{aligned}
        \includegraphics[page=1]{output/thm__quotient_group_universal_property.pdf}
      \end{aligned}
    \end{equation}

    In the case where \( N = \ker \varphi \), \( \widetilde{\varphi} \) is an \hyperref[def:first_order_homomorphism_invertibility/embedding]{embedding}.
  \end{displayquote}

  This extends to \fullref{thm:quotient_module_universal_property} and \fullref{thm:quotient_algebra_universal_property}.
\end{theorem}
\begin{proof}
  We want
  \begin{equation*}
    \widetilde{\varphi}(\pi(x)) = \widetilde{\varphi}(xN) = \varphi(x).
  \end{equation*}

  This suggests the definition
  \begin{equation*}
    \widetilde{\varphi}(xN) \coloneqq \varphi(x).
  \end{equation*}

  The homomorphism \( \widetilde{\varphi} \) is well-defined because, if \( x N = x' N \), since \( N \subseteq \ker \varphi \), we have
  \begin{equation*}
    \varphi(x)
    =
    \varphi(x) e_N
    =
    \varphi(x) \varphi(N)
    =
    \varphi(x N)
    =
    \varphi(x' N)
    =
    \cdots
    =
    \varphi(y).
  \end{equation*}

  If \( N = \ker \varphi \), the kernel of \( \widetilde{\varphi} \) is trivial. By \fullref{thm:def:group/zero_kernel}, it is an injective function.
\end{proof}

\begin{corollary}\label{thm:quotient_group_by_kernel}
  Every \hyperref[def:group/homomorphism]{group homomorphism} \( \varphi: G \to H \) induces an isomorphism
  \begin{equation*}
    G / \ker \varphi \cong \img \varphi.
  \end{equation*}
\end{corollary}
\begin{proof}
  Directly follows from \fullref{thm:quotient_group_universal_property} by restricting the range of \( \widetilde{\varphi} \) to its image.
\end{proof}

\begin{corollary}\label{thm:group_epimorphisms_are_normal}
  Every surjective group homomorphism is a \hyperref[def:zero_morphisms/cokernel]{normal epimorphism}.
\end{corollary}
\begin{proof}
  Fix a group homomorphism \( \varphi: G \to H \). By \fullref{thm:quotient_group_by_kernel}, \( G / \ker \varphi \cong \img \varphi = H \). Thus, \( H \) is a \hyperref[def:zero_morphisms/cokernel]{cokernel} of the canonical inclusion \( \iota: \ker \varphi \to G \).
\end{proof}

\begin{theorem}[Quotient subgroup lattice theorem]\label{thm:quotient_subgroup_lattice_theorem}\mcite[prop. II.8.9]{Aluffi2009}
  Given a \hyperref[thm:normal_subgroup_equivalences]{normal subgroup} \( N \) of \( G \), the function \( H \mapsto H / N \) is a \hyperref[def:semilattice/homomorphism]{lattice homomorphism} between the \hyperref[thm:substructures_form_complete_lattice]{lattice of subgroups} of \( G \) containing \( N \) and the lattice of subgroups of the \hyperref[def:group/quotient]{quotient} \( G / N \).

  \begin{figure}[h]
    \centering
    \includegraphics[page=1]{output/thm__lattice_theorem_for_groups.pdf}
    \caption{The lattice of subgroups of \( G \) and the lattice of subgroups of \( G / N \).}
    \label{fig:thm:quotient_subgroup_lattice_theorem}
  \end{figure}

  This extends to \fullref{thm:quotient_submodule_lattice_theorem} and \fullref{thm:quotient_ideal_lattice_theorem}.
\end{theorem}
\begin{proof}
  \SubProofOf[def:function_invertibility/injective/equality]{injectivity} Let \( H_1 / N = H_2 / N \). Both \( H_1 / N \) and \( H_2 / N \) consist of the same cosets, hence
  \begin{equation*}
    H_1 = \bigcup (H_1 / N) = \bigcup (H_2 / N) = H_2.
  \end{equation*}

  Therefore, the map \( H \mapsto H / N \) is injective.

  \SubProofOf[def:function_invertibility/surjective/existence]{surjectivity} Fix a subgroup \( M \) of \( G / N \) and define
  \begin{equation*}
    H \coloneqq \set{ x \in G \given xN \in M }.
  \end{equation*}

  Then clearly \( H / N = M \). Therefore, the map \( H \mapsto H / N \) is surjective.

  \SubProofOf[def:semilattice/homomorphism]{lattice compatibility} The join \( \braket{ K \cup H } \) of two subgroups of \( G \) containing \( N \) must satisfy the equality
  \begin{equation}\label{eq:thm:quotient_subgroup_lattice_theorem/join}
    \underbrace{ \braket{ K \cup H } / N }_{\set{ xN \given x \in \braket{ K \cup H } }}
    =
    \underbrace{ \braket{ (K / N) \cup (H / N) } }_{\braket{ \set{ xN \given x \in K \cup H } }}.
  \end{equation}

  Verifying this amounts to noting that \( \braket{ K \cup H } \) is obtained by adding the products and inverses of any elements of \( G \) not in \( K \cup H \). Since the projection map \( \pi: G \to G / N \) is a homomorphism, the coset \( xy N \) of the product of \( x, y \in \braket{ K \cup H } \) is the product \( (xN) (yN) \) of the cosets \( xN \) and \( yN \), and analogously for inverses. Hence, adding an element \( x \in G \) to \( K \cup H \) and then taking all cosets is the same as adding the coset \( xH \) to \( (K / N) \cup (H / N) \).

  Therefore, \eqref{eq:thm:quotient_subgroup_lattice_theorem/join} holds, and thus \( H \mapsto H / N \) preserves joins in the lattice of subgroups.

  The other verifications are simpler. For meets, we have
  \begin{equation*}
    (K \cap H) / N
    =
    \set{ xN \given x \in K \cap H }
    =
    \set{ xN \given x \in K } \cap \set{ xN \cap x \in H }
    =
    (K / N) \cap (H / N).
  \end{equation*}

  Finally, it remains to show that \( H \mapsto H / N \) preserves the \hyperref[def:partially_ordered_set_extremal_points/top_and_bottom]{top and bottom elements}. This is trivial since \( G / N \) contains all possible cosets of \( N \) and is hence the top in the lattice of subgroups of \( G / N \), and \( N / N \) is the trivial group and hence the bottom.

  Therefore, \( H \mapsto H / N \) is a lattice isomorphism.
\end{proof}

\begin{theorem}[Lagrange's theorem for groups]\label{thm:lagranges_theorem_for_groups}
  Let \( H \) be a subgroup of \( G \). We have the following equality
  \begin{equation}\label{eq:thm:lagranges_theorem_for_groups/index}
    \card(G) = \card(H) \cdot [G : H].
  \end{equation}

  If \( H \) is a \hyperref[thm:normal_subgroup_equivalences]{normal subgroup}, then \( [G : H] = \card(G / H) \) and
  \begin{equation}\label{eq:thm:lagranges_theorem_for_groups/card}
    \card(G) = \card(H) \cdot \card(G / H).
  \end{equation}

  This demonstrates that there exists a bijective function between the \hyperref[def:monoid_direct_product]{direct product} \( H \times G / H \) and \( H \), however this may not be a group homomorphism --- see \fullref{ex:lagranges_theorem_for_groups/direct_product_zn}.
\end{theorem}
\begin{proof}
  By \fullref{def:subgroup_cosets}, every coset of \( G \) with respect to \( H \) is equinumerous with \( H \), and there is a total of \( [G : H] \) cosets. Therefore, \eqref{eq:thm:lagranges_theorem_for_groups/index} holds.
\end{proof}

\begin{example}\label{ex:subgroups_of_integers}
  Consider the group \( \BbbZ \) of integers with respect to addition.

  Let \( 2\BbbZ \) be the subgroup of all even integers. Then both \( \BbbZ \) and \( 2\BbbZ \) are countably infinite, but their quotient group \( \BbbZ / 2\BbbZ \) has two elements --- the set \( 2\BbbZ \) of all even integers and the set \( 2\BbbZ + 1 \) of all odd integers. Generalizations of this quotient group are discussed in \fullref{thm:group_of_integers_modulo}. \Fullref{thm:lagranges_theorem_for_groups} holds, but it gives no insight due to the absorbing properties of transfinite cardinal arithmetic described in \fullref{thm:simplified_cardinal_arithmetic}.

  Now consider the groups \( 4\BbbZ \subseteq 2\BbbZ \subseteq \BbbZ \). As a consequence of \fullref{thm:lagranges_theorem_for_groups}, \( 3\BbbZ \) is not a subgroup of \( 2\BbbZ \), and so we consider powers of \( 2 \).

  Since \( 2\BbbZ \) is a subgroup of \( \BbbZ \), the quotient \( 2\BbbZ / 4\BbbZ \) must a subgroup of \( \BbbZ / 4\BbbZ \) as a consequence of \fullref{thm:quotient_subgroup_lattice_theorem}. We may not know the structure of the quotient groups (although we do, see \fullref{thm:group_of_integers_modulo}), but we know how \( 4\BbbZ \), \( 2\BbbZ \) and \( \BbbZ \) relate to each other, and we are able to determine how the quotient groups relate to each other.
\end{example}


\documentclass{article}
\usepackage{tocloft}
\include{common_symbols_and_format}
\renewcommand{\cfttoctitlefont}{\Large\bfseries}
\begin{document}
\logo
\rulename{Exponential Trading Rule - Two factor}

\tblofcontents

\ruledescription{These representations have the position dependent on an exponentially weighted average of the prior values of research and price. The look back length, $\lookbacklength$, determines how far back the rule looks. The decay rates, $\decaycoefficientone$ and $\decaycoefficienttwo$, and amplitudes, $\amplitudecoefficientone$ and $\amplitudecoefficienttwo$, coefficients determine the contribution from each exponential. The expression is normalised to be dimensionless by division by the weighting factors and current price.}

\ruleparameters
{Window size}{10}{This is the number of time steps over which exponential contributions are sourced.}{$\lookbacklength$}
{$1^{st}$ Exponential decay rate for price}{0.0}{This is the $1^{st}$ decay factor that reduces older contributions from the price series.}{$\decaycoefficientone^{\price}$}
{$1^{st}$ Exponential decay rate for research}{0.0}{This is the $1^{st}$ decay factor that reduces older contributions from the research series.}{$\decaycoefficientone^{\research}$}
{Amplitude of price $1^{st}$ contribution}{-0.1}{This factor scales the $1^{st}$ contribution from past values of price.}{$\amplitudecoefficientone^{\price}$}
{Amplitude of research $1^{st}$ contribution}{0.1}{This factor scales the $1^{st}$ contribution from past values of research.}{$\amplitudecoefficientone^{\research}$}
{$2^{nd}$ Exponential decay rate for price}{0.0}{This is the $2^{nd}$ decay factor that reduces older contributions from the price series.}{$\decaycoefficienttwo^{\price}$}
{$2^{nd}$ Exponential decay rate for research}{0.0}{This is the $2^{nd}$ decay factor that reduces older contributions from the research series.}{$\decaycoefficienttwo^{\research}$}
{Amplitude of $2^{nd}$ price contribution}{-0.1}{This factor scales the $2^{nd}$ contribution from past values of price.}{$\amplitudecoefficienttwo^{\price}$}
{Amplitude of $2^{nd}$ research contribution}{0.1}{This factor scales the $2^{nd}$ contribution from past values of research.}{$\amplitudecoefficienttwo^{\research}$}
\stoptable

\section{Equation}

\begin{equation}
\contribution^{\price}(\dummyiterator,\dummyiteratortwo) = \sum_{\dummyiteratorthree = 1}^{\dummyiteratortwo} e^{- \frac{ \dummyiterator}{e^{-\decaycoefficient_\dummyiteratorthree^\price}}}
\end{equation}
\begin{equation}
\contribution^{\research}(\dummyiterator,\dummyiteratortwo) = \sum_{\dummyiteratorthree = 1}^{\dummyiteratortwo} e^{- \frac{ \dummyiterator}{e^{-\decaycoefficient_\dummyiteratorthree^\research}}}
\end{equation}
\begin{equation}
{\bigcontribution}_{\dummyiteratortwo \price} = \amplitudecoefficient_{\dummyiteratortwo}^{\price} \frac{\sum_{\dummyiterator=0}^{\lookbacklength} \price_{\currenttime - \dummyiterator} \contribution^{\price}(\dummyiterator, \dummyiteratortwo)}{\sum_{\dummyiterator = 0}^{\lookbacklength} \contribution^{\price}(\dummyiterator, \dummyiteratortwo)} \\
\end{equation}
\begin{equation}
\bigcontribution_{\dummyiteratortwo  \research} = \amplitudecoefficient_{\dummyiteratortwo}^{\research} \frac{\sum_{\dummyiterator=0}^{\lookbacklength} \research_{\currenttime - \dummyiterator} \contribution^{\research}(\dummyiterator, \dummyiteratortwo)}{\sum_{\dummyiterator = 0}^{\lookbacklength} \contribution^{\research}(\dummyiterator, \dummyiteratortwo)} \\
\end{equation}
\begin{equation}
\position_{\currenttime} = ({\bigcontributionone}_{\price} + {\bigcontributionone}_{\research} + {\bigcontributiontwo}_{\price} + {\bigcontributiontwo}_{\research})/{\price}_{\currenttime} \\
\end{equation}
\hspace{200mm}

\noindent where $\price_\currenttime$ is the price at time $\currenttime$, $\research$ is the value of the research series, $\amplitudecoefficientone$ and $\amplitudecoefficienttwo$ are the amplitude coefficients, $\decaycoefficientone$ and $\decaycoefficienttwo$ are the decay rate coefficients and $\position$ is the resultant fractional portfolio investment.\\
Intuitively, the $\contribution$ are the exponential weightings for each historical value in the look back period, with $\bigcontribution$ the normalised sum of all the contributions, scaled by the amplitude coefficient. The total contributions are then scaled by the current price to give a dimensionless fraction of the portfolio to invest.
\hspace{200mm}
\hspace{200mm}

\keyterms
\furtherlinks
\end{document}


\documentclass{article}

\usepackage{palatino}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[utf8]{inputenc}
\usepackage[colorlinks=true]{hyperref}

% macros
\newcommand{\LL}{\mathcal{L}}
\newcommand{\half}{\frac{1}{2}}
\newcommand{\norm}[1]{\left|\left|#1\right|\right|}
\newcommand{\dd}{d}
\newcommand{\ddd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\block}[1]{\left(#1\right)}
\newcommand{\mat}[1]{ \begin{pmatrix} #1 \end{pmatrix} }
\newcommand{\inv}[1]{#1^{-1}}
\newcommand{\argmin}[1]{\underset{#1}{\textrm{argmin}}}

\newcommand{\p}[1]{#1^{+}}
\newcommand{\m}[1]{#1^{-}}
\newcommand{\s}[1]{#1^{*}}
\newcommand{\xp}{\p{x}}
\newcommand{\xm}{\m{x}}
\newcommand{\vp}{\p{v}}
\newcommand{\vm}{\m{v}}
\newcommand{\vs}{\s{v}}
\newcommand{\fp}{\p{f}}
\newcommand{\fm}{\m{f}}
\newcommand{\fs}{\s{f}}
\newcommand{\Dx}{\Delta x}
\newcommand{\Dv}{\Delta v}
\newcommand{\lambdap}{\p{\lambda}}
\newcommand{\phip}{\p{\phi}}
\newcommand{\JpT}{J^{+^T}}
\newcommand{\Cp}{\p{C}}

\begin{document}
\title{Newton Solver Reference}
\author{Fran\c{c}ois Faure and Matthieu Nesme}
\date{\today}
\maketitle
%
\begin{abstract}
  Detailing the non-linear time-stepping scheme implemented in the CompliantNLImplicitSolver component.
\end{abstract}
%

\section{Notations}

\begin{itemize}
\item $x$: positions
\item $v$: velocities
\item $f(x,v,t)$: forces for given positions and velocities at time $t$
\item $h$: time step
\item $\m{(.)}$, $\p{(.)}$: a state at, respectively, the beginning and the end of the time step
\item $\Dx=\xp-\xm$: variation of position during the time step
\item $\Dv=\vp-\vm$: variation of velocity during the time step
\item $\alpha$, $\beta$: blending parameters such as $\fs=\alpha\fp+(1-\alpha)\fm$ and $\vs=\beta\vp+(1-\beta)\vm$. Corresponding Data are called implicitVelocity and implicitPosition.
\item $M$: mass
\end{itemize}

\section{Euler Integration}

\[
   \left \{
   \begin{array}{r c l}
      \Dx  & = & h\vs \\
      M\Dv & = & h\fs \\
   \end{array}
   \right .
\]

from explicit $\alpha=\beta=0$ to implicit $\alpha=\beta=1$.

\section{Non-linear Solver}

The method computes the next velocity $\vp$, such that $e \equiv M\Dv-h\fs$ is satisfied.
(Note that other time discretizations are implemented to rather compute the new acceleration or $\Dv$, similar development can be done being careful of the time step scaling.)\\

Based on the Newton's method, an approximate solution is iteratively improved by solving a linear equation system based on the Jacobian of the residual of the equation to satisfy.
A first guess is computed with the regular, linearized system (cf the linear time-stepping scheme in the Compliant plugin doc). \\

Stating that \[ e \equiv M(\vp-\vm)-h(\alpha\fp+(1-\alpha)\fm)\] we obtain the jacobian \[ \ddd{e}{\vp}=M-h\alpha\ddd{\fp}{\vp}\]

A first order approximation of the Taylor serie of $\fp=f(\xp,\vp,t+h)$ gives

\[
   \begin{array}{r c l}
      \fp  & = & f(\xm,\vm,t)+\ddd{f}{x}\Dx+\ddd{f}{v}\Dv \\
           & = & \fm+K\Dx+B\Dv \\
           & = & \fm+K(h(\beta\vp+(1-\beta)\vm))+B(\vp-\vm)
   \end{array}
\]

with $K=\ddd{f}{x}$ the stiffness matrix and $B=\ddd{f}{v}$ the damping matrix. \\

So \[ \ddd{\fp}{\vp}=h\beta K+B\] and \[\ddd{e}{\vp}=M-h\alpha B-h^2\alpha\beta K\]

\section{Constraints}

Bilateral, holonomic constraint $\phi(x)=0$, combined with the ODE leads to $Jv=0$ with $J=\ddd{\phi}{x}$, the constraint forces are $-J^T\lambdap$ with $\lambda$ the Lagrange multipliers.

The error becomes \[ e \equiv M(\vp-\vm)-h(\alpha(\fp-\JpT\lambdap)+(1-\alpha)\fm)\]

For compliant constraints $C\lambda=-\phi$ \[ e \equiv M(\vp-\vm)-h(\alpha(\fp-\JpT\lambdap)+(1-\alpha)\fm)-\Cp h\lambdap+\frac{\phip}{h}\]
\\

Unilateral constraints $\phi(x)>=0$ are handled the same way, expect they participate to the error only when they are violated (i.e. when then generate a force $\lambda$).

\section{Newton Step Length}

Two different strategies are implemented:
\begin{itemize}
\item naïve sub-step approach: a predefinied portion (Data 0$<$newtonStepLength$<$1) of the correction is applied successively while the error is decreasing.
\item Backtracking algorithm (Data newtonStepLength=1): try to find the maximum amount of correction to apply that decreased "sufficiently" the error. The line search described in \textit{Numerical Recipies} (chapter Globally Convergent Methods for Nonlinear Systems of Equations) is employed.
\end{itemize}

\end{document}


\newpage
\chapter{Stagnation flow flames}
\section{Introduction}
The stagnation flame model in Camflow is a transient model capable of predicting the species profiles, velocity profile, and the temperature profile.  When the temperature profile is obtained from experiment, the model can be used to simulate only the species profiles and velocity profile by providing the experimentally observed temperature profile. In this case only the species transport equations,  momentum and continuity equations are solved. An initial guess of intermediate species needs to be provided. If the temperature profile is not known, the model can predict the temperature profile by solving the energy equation. In this case in addition to the intermediate species composition, an initial guess for the temperature profile also needs to be provided.

\section{Fundamentals}
The equation of continuity in cylindrical coordinate by considering only axial and radial coordinate can be written as
\begin{equation}
 \frac{\partial \rho}{\partial t} + \frac{1}{r}\frac{\partial}{\partial r}(\rho rv) + \frac{\partial}{\partial z}(\rho u) = 0;
\end{equation}
The radial and axial momentum follows as
\begin{equation}
 \rho \bigg(
 \frac{\partial v}{\partial t} +
 v\frac{\partial v}{\partial r}+
 u\frac{\partial v}{\partial x} \bigg) = -\frac{\partial p}{\partial r} +
\mu \bigg[\frac{\partial}{\partial r}\bigg(\frac{1}{r}\frac{\partial}{\partial r}(rv)\bigg) + \frac{\partial^2v}{\partial x^2}\bigg],
\end{equation}

\begin{equation}
 \rho \bigg(
 \frac{\partial u}{\partial t} +
 v\frac{\partial u}{\partial r}+
 u\frac{\partial u}{\partial x} \bigg) = -\frac{\partial p}{\partial r} +
\mu \bigg[\frac{1}{r} \frac{\partial}{\partial r}\bigg(r\frac{\partial u}{\partial r}\bigg) + \frac{\partial^2u}{\partial x^2}\bigg],
\end{equation}
Assuming similarity near the center line, the axial velocity, radial velocity, temperature and species mass fraction turns out to be functions of time and axial coordinate. Defining v/r =V(x), and by applying boundary layer theory in the axial direction the continuity and momentum simplified to

\begin{equation}
\frac{\partial \rho}{\partial t} + \frac{\partial (\rho u)}{\partial x} + 2\rho V = 0
\end{equation}
\begin{equation}
 \rho \frac{\partial V}{\partial t} + \rho u \frac{\partial V}{\partial x} + \rho V^2 = -\Lambda + \frac{\partial }{\partial x}\bigg(\mu \frac{\partial V}{\partial x} \bigg),
\end{equation}
and
\begin{equation}
 \frac{\partial p}{\partial x} = 0.
\end{equation}
The eigen value $\Lambda$ of the system has to be solved with other dependent variables
\begin{equation}
 \frac{1}{r}\frac{\partial p}{\partial r} = \Lambda
\end{equation}
The energy equation is written as
\begin{equation}
 \rho c_p \frac{\partial T}{\partial t}+ \rho u c_p \frac{\partial T}{\partial z} - \frac{\partial }{\partial z}\bigg(\lambda \frac{\partial T}{\partial z} \bigg) + \frac{\partial}{\partial z} \sum_k j_k h_{k}  + \sum_k h_k\dot{\omega}_k = 0
\end{equation}
and the species transport equation
\begin{equation}
 \rho \frac{\partial Y_k}{\partial t}+ \rho u \frac{\partial Y_k}{\partial z} + \frac{\partial j_k}{\partial z} = \dot{\omega}_k W_k, \quad k=1\ldots K_g
\end{equation}
with $j_k$ defined as
\begin{equation}
 j_k = -\rho D_{km} \frac{dY_k}{dz},
\end{equation}
The boundary conditions for the above system of equations are
\begin{eqnarray}
 x = 0: \quad u=u_f(t), \quad V = V_f(t) \quad T=T_f(t), \quad Y_k = Y_{kf} \nonumber \\
x=L: \quad u=0, \quad V=0, \quad T=T_{wall}, \quad \frac{dY_k}{dx}=0
\end{eqnarray}
In the above equations, $\rho$ is the density in kg/m$^3$, $u$ is the axial velocity in m/s, $v$ is the radial velocity in m/s,  $Y_k$ is the mass fraction of the k\'th chemical species, $j_k$ the mass flux of the k\'the species in kg/$m^2-s$, $\dot{\omega}_k$ the molar production rate of the k\'the species in mol/m$^3$-s, D$_{km}$ the diffusion coefficient of the k\'the species in the mixture, $h_k$ the specific enthalpy in J/kg, and the $t$ the time in $s$.

\section{Input file}
An example of ``camflow.xml'' input file is shown below
{\scriptsize{

\begin{verbatim}
<?xml version="1.0" encoding="ISO-8859-1"?>
<camflow>
   <reactor model="stagflow">
    <diameter unit="m">0.015</diameter>
    <length unit="cm">2</length>
  </reactor>
  <op_condition>
     <temperature>userdefined</temperature>
     <twall unit="K">300.0</twall>
     <pressure unit="bar">1.0</pressure>
     <strain>100</strain>
  </op_condition>
  <inlet>
     <fuel>
       <velocity unit="m/s">2.0</velocity>
       <temperature unit="K">300.0</temperature>
       <molefrac>
        <species name="H2">0.5</species>
        <species name="O2">*</species>
       </molefrac>
    </fuel>
  </inlet>
  <solver mode="coupled" solver="cvode" residual="on">
     <maxTime>10000</maxTime>
     <iterations>1</iterations>
     <tols>
        <species>
           <aTol>1.e-10</aTol>
           <rTol>1.e-08</rTol>
        </species>
        <temperature>
           <aTol>1.e-03</aTol>
           <rTol>1.e-03</rTol>
        </temperature>
        <flow>
           <aTol>1.e-03</aTol>
           <rTol>1.e-03</rTol>
        </flow>
     </tols>
  </solver>
  <initialize>
    <mCenter unit="cm">1</mCenter>
    <mWidth unit="cm">0.5</mWidth>
    <massfrac>
      <intrmdt name="H">0.1</intrmdt>
      <intrmdt name="OH">0.12</intrmdt>
      <intrmdt name="HO2">0.001</intrmdt>
      <intrmdt name="H2O">0.01</intrmdt>
    </massfrac>
    <Tprofile unit_L="cm" unit_T="K">
      <position x="0.00">300.</position>
      <position x="0.10">350.0</position>
      <position x="0.20">400.0</position>
      <position x="0.30">500.0</position>
      <position x="0.40">600.0</position>
      <position x="0.90">1100.0.</position>
      <position x="1.00">1200.0</position>
      <position x="1.10">1100.0.</position>
      <position x="1.20">1000.0</position>
      <position x="1.30">900.0</position>
      <position x="1.40">800.0</position>
      <position x="1.50">700.0</position>
      <position x="1.60">600.0</position>
      <position x="1.70">500.0</position>
      <position x="1.80">400.0</position>
      <position x="1.90">350.0</position>
      <position x="2.00">300.0</position>
    </Tprofile>
 </initialize>
 <report outfile="final" species="mole">
 </report>
 <grid>grid.inp</grid>
</camflow>

\end{verbatim}}
}

The input file follows xml standard. A detailed description about the various elements in the input file is specified below.

\begin{itemize}
 \item \textbf{rector} : The reactor element specifies which model is to be simulated and for a stagnation flow flame camflow expects ``stagflow'' as the model attribute value. The reactor element also holds child element length for specifying the nozzle-wall separation, and is given with the unit attribute. The unit of the value specified can be in ``cm'', ``m'', or in ``in''ches. Appropriate attribute must be specified. However,, the grid file (described later) has higher precedence over the value specified here.

\item \textbf{op\_conditions} : The element op\_conditions describes the operating conditions for the flame. This includes the specification of the pressure and the condition applied to the solution of energy equation. The flame pressure may be specified in the units of ``Pa'', ``atm'', or ``bar''. The temperature element can take the values of ``isothermal'', ``adiabatic'', or ``userdefined''. In the case of isothermal calculation, the energy equation is not solved and the flame is assumed to be at the same temperature as the incoming fuel. The user may also perform the integration for a pre-calculated or measured temperature profile. In this case the temperature child element must be assigned with the value ``userdefined'' and the user defined temperature profile can be specified (explained later). For adiabatic calculations, provide the temperature element with the value ``adiabatic'', and in this case the energy equation will be solved to predict the temperature profile. Further the temperature of the wall surface also needs to be specified using the element ``twall'' with appropriate unit for temperature.\\

In addition to the temperature and pressure, the strain rate needs to be specified since camflow does not solve for the pressure gradient eigen value. Instead it is calculated from the strain rate according to
\begin{equation}
 \Lambda = -\rho_o a^2
\end{equation}

\item \textbf{inlet} : All properties pertaining to the fuel inlet must be specified under the element ``fuel''. ``fuel'' element must specify the velocity at the inlet using the ``velocity'' element, temperature using the ``temperature'' element and the species composition using ``molefrac'' or ``massfrac'' element.The unit for velocity may be in m/s or in cm/s and temperature can be in C or in K. The appropriate units must be specified as attribute values. The chemical species present in the fuel can be specified using the species elements, with the species name as attribute and corresponding mole/mass fraction as attribute. The last species composition may be specified using ``*'', and this case the ``*'' will stand for 1-sum of composition of other species.

\item \textbf{solver}: The solver element holds the solver control specifications. The attributes ``mode'' can be specified as ``coupled'' or ``segregated'' for counter flow flames. The solver name is essentially provided to switch from one solver to another. However, the present version of Camflow uses only CVode as the numerical integrator, and therefore accepts only ``cvode'' as the solver name. When the solver mode is specified as coupled, the governing equations are solved simultaneously, and for ``segregated'' mode, the governing equations are solved sequentially for a number of times that is specified by the element iterations. By default the value of iterations element is one. At the end of the number of iterations, the solution mode will automatically switch to coupled. The user is encouraged to use coupled mode for counter-flow calculations.\\

Additionally the integration time may be optionally specified by the element maxTime. By default the value of maxTime is 100000 s. However, the final integration time is the maxTime or the time required to reach steady state whichever is lower. This means the solver will stop integration, if steady state is reached before the specified integrations time.\\

The element ``tols'' hold the various tolarences that can be applied to the species, energy, and continuity equations. For species a relative tolarence of at least 10$^{-6}$ should be used. The user may need to adjust the tolarence values for the species in case of solution difficulties.

\item \textbf{initialize} The initialize element can be used to specify various initial conditions.
A guess value for the intermediate species composition may be used to initialize the flow filed. When specifying the intermediate compostions, the mixing center and mixing width needs to be specified. When these compositions are specified a guassien profile will be generated for the intermediate species with peaks at the mixing centers and the having the spread specified by mixing width. The mixing center is specified by the element ``mCenter`` and the mixing width is specified by ''mWidth``. Both these elements are provided with ''unit`` attribute, and appropriate unit of length must be specified. Unlike the specification of fuel inlet species composition, the sum of intermediate or product species composition need not to sum up to one. However, the user must ensure that the sum does not exceeds one.\\

The temperature profile can be specified by using the ``Tprofile'' element with two attributes namely ``unit\_L'' for length unit and ``unit\_T'' for temperature unit. The length unit can be in ``cm'' or in ``m'', where as the temperature unit can be either in ``K'' or in ``C''. The actual temperature as a function of reactor position is specified with the child elements position with the attribute ``x'', which stands for the position with the reactor. If the length unit is specified as ``cm'' then ``x'' is the position from the reactor inlet in ``cm'', and the value for the position element is the temperature at position ``x''.

\item \textbf{report}: The desired output for the species composition must be specified in this element using the species attribute. ``mole'' or ``mass'' may be used as the attribute values, and correspondingly the output will be produced either in mole fraction or mass fractions.

\item \textbf{grid}: The premix flame model requires a descretised geometry. The geometry may be specified using anyfile that contains a nodes of the descretised geometry. The content of the grid file is assumed to be in ``m'' units. An example is shown below\\
{\scriptsize{\begin{verbatim}
0.0
0.0002
0.0003
0.0004
0.0005
0.0006
0.0007
0.0009
0.001
0.0015
0.002
0.003
0.004
0.005
0.006
0.007
0.008
0.009
0.01
0.02
\end{verbatim}
}}

The content of the grid file has precedence over the length of the flame specified in the reactor element. This means that the length of the flame after reading the grid file will be set to the final point specified in the grid file.
\end{itemize}

\section{Executing the binary}
The stagnation flame model of Camflow expects four input files namely, ``camflow.xml'', ``therm.dat'',  ``chem.inp'', and ``tran.dat''. All the files must be present in the working directory. Upon succesful execution the output file ``profile.dat'' containing the final integration time (s), axial position (m), residence time (1/s), density (kg/m$^3$), velocity (m/s), massflow rate (kg/m$^2$s), temperature (K), and the species compositions in mass or mole fractions.

%===============================================================================================
%
%
%
%===============================================================================================


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                             Conclusion                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}
\label{cha:conclusion}
\markboth{Conclusion}{Conclusion}

In this Ph.D. thesis, we contributed to the formulation and the resolution of the posture generation problem for robotics.
%Which is a subproblem of many robotics applications such as planning, trajectory generation and control.
%Such problems aim at finding a robot configuration that satisfies some high-level requests while ensuring its viability, in the sense that, in this configuration, the robot is stable, avoid collisions and respects its intrinsic limitations.
Posture generation is the problem of finding a robot configuration to fulfill high-level task goals under viability or user-specified constraints (e.g. find a posture that is statically stable, avoids non-desired contacts and respects the robot's intrinsic limitations).
This problem is traditionally formulated and solved as an optimization problem by minimizing a specific cost function under a set of constraints.

We described the formulation of the basic building blocks of the posture generation problems and proposed some extensions, such as a 'smooth' formulation of non-inclusive contact constraints between two polygons; which allows finding optimal contact configurations in complex situations where two surfaces in contact cannot be included in each other.
This formulation proved very helpful for planning complex scenarios such as making the HRP-2 robot climb a ladder, it allowed to automatically find some contact configurations that would otherwise take a long time to find manually by trial and errors.
%even when generate viable configurations of contact that would otherwise not be considered by usual formulations; it relies on the idea of adding to the problem a set of variables that represent an ellipse included in both polygons.

Robotics problems often contain variables that belong to non-Euclidean manifolds, they are traditionally handled by modifying the mathematical definition of the problem and adding extra variables and constraints to it.
We present a generic way to handle such variables in our formulation, without modifying the mathematical problem, and most importantly, we propose an adaptation of existing optimization techniques to solve constrained nonlinear optimization problems defined on non-Euclidean manifolds.
We then detail our implementation of such an algorithm, based on an SQP approach, which, to our knowledge, is the first implementation of a nonlinear solver on manifolds that can handle constraints.
This, not only allows us to formulate mathematical problems more elegantly and ensure the validity of our variables at every step of the optimization process, but also enables us to have a better understanding of our solver, and flexibility in tuning it for robotics problems.
In turn, this allows us to investigate new ways of solving posture generation problems.

The search space of a posture generation problem is the Cartesian product of several (sub)manifolds in which different quantities/variables are defined (e.g.translations, rotations, joint angles, contact forces, etc.).
%We design a new the posture generation frameword that takes advantage of the structure of the search space.
%We present a new formulation of the posture generation problem that takes into account the inherent structure of its configuration space as a cartesian product of submanifolds representing different quantities(translations, rotations, joint angles, contact forces, etc.).
%Each submanifold of the search space is considered as a separate entity, and variables on it can be considered separately from each other.
%We take advantage of that structure to propose a posture generation framework where the variables, submanifolds, and function's derivations are managed automatically, and geometric expressions can be written intuitively, which simplifies the work of the developer of new functions.
We take advantage of that structure to propose a posture generation framework where the variables and submanifolds are managed automatically, and geometric expressions can be written intuitively and are differentiated automatically.
This framework helps reducing the work the developer of new functions has to do, as functions of geometric expressions can be quickly prototyped and their derivatives are computed automatically, and the variable management allows to simply write the function on its input space without worrying about the location of said input space within the global search space.
Our framework allows to easily and elegantly write custom constraints on selected sets of variables defined on the submanifolds of the search space.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
We exploit the capabilities of our framework to generate viable robot's configurations with contacts on non-flat surfaces by parametrizing the location of the contact point with additional variables.
That approach allowed us to compute manipulation and locomotion postures involving solids defined only by their meshes and where the choice of the contact location was left entirely to the solver.
That way, we computed some postures of an HRP-4 robot holding the leg of an HRP-2 robot in its grippers, and others, for example, where HRP-4 is climbing on a stack of cubes and the contacts locations are chosen automatically.
This was made possible by proposing a generic way to parametrize the surface of a solid represented by a mesh, based on the Catmull-Clark subdivision algorithm, and using it to compute configurations where the optimal location of contact on a complex object is chosen by the solver.

We took a great care to eliminate many of the cumbersome aspects of writing a posture generation problem, and in the end, the genericity of our framework allows the definition and use of a wide range of functions applied to any variables of the problem (joint angles, forces, torques or any additional variables).
Such function can then be used to define and solve custom posture generation problems with our solver, and compute viable postures that satisfy any user-defined tasks.

We evaluate the performances of our solver on problems relying heavily on the manifold formulation and show that it is superior to the classic approach in terms of convergence speed and time spent per iteration.
%We then present some evaluations of our solver and posture generator: we solved a cube stacking problem that relies heavily on the manifold formulation to showcase that, the manifold formulation performs better than the traditional one in that problem and in particular, the time spent per iteration is, as expected, shorter.
%We studied the influence of the distance between the initial guess and the problem's solution on the success rate of the posture generation problem.
%This showed that when starting close to the solution, convergence is almost always reached whereas when starting remotely, it is more difficult to find the solution, and more work on the solver could help increase this success rate.
%Such study allowed us to compare results for different solver options.
%We showed that in terms of hessian update method, the self-scaling BFGS update on individual Hessians gives us the best results.
We then present an approach to evaluate and compare the performances of different resolution methods for solving several types of posture generation problems, which could help develop strategies to tune our solver, based on the problem at hand.

We developed our solver in order to solve posture generation problems, but we show that its capabilities can be leveraged to solve other kinds of problems such as the identification of inertial parameters, where the manifold formulation guarantees that the optimization iterates are always physically valid.
For this problem, our solver and formulation proved more efficient than the traditional formulation solved with an off-the-shelf solver.
Finally, we presented our preliminary work in using posture generation in multi-contact planning in real sensory acquired environment.

%Overall, we present an efficient and user-friendly framework for posture generation along with a nonlinear solver on manifold that can be used to compute viable robotic postures satisfying some tasks.
%The framework is designed such that creating custom functions and constraints to the problem is simple.

%Although our solver fairs correctly, compared to other solvers on some problems (Schittkowsky, Inertial identification), we believe that some improvements could still be made to it.
%This study showed that our solver is able to solve posture generation problems in times comparable to the state of the art, but we are fully aware that those computation times could be improved.
Although we manage to get some satisfying results out of our posture generator, the solver still requires some tuning of its options, and of the initial guess, to ensure good convergence rates.
We are fully aware that even though the computation times that we observe are of the same order of magnitude as the ones found in the literature, improvements could and should be made in the future to make our posture generator more robust and faster, by not only improving the solver's implementation, but also specializing it for robotic posture generation problems.
%We believe that improvements could be made to make our solver more reliable and to specialize it for the resolution of posture generation problems.
In particular, we believe that the restoration phase, especially the treatment of the Hessian updates, can be improved.
We can also try using other QP solvers than LSSOL.
A sparse solver, for example, may be more suited to take advantage of the structure of our problem.
Most importantly, future works need to develop the solver to make it specialized for posture generation problems, either by finding optimal solver options or by modifying the optimization algorithm.
In future research, having an open solver and being able to modify it will be a crucial element of our ability to find and use the most suited algorithm to solve posture generation and other problems encountered in robotics more efficiently.
%An initial study of the problem to solve, followed by an automatic tuning of the solver seems like a promising idea to improve the posture generator's performances.
One could, for example, choose an initial guess from a database of robot postures and some solver options automatically, based on an initial study of the structure of the problem.
It would also be possible to take into account the very specific structure of a robot in the resolution algorithm.

%Having an open and functionnal solver is a crutial tool in
%Our open solver, which can be modified to suit the needs [xxx of what], can be crutial tool to achieve this goal.
%This is made possible by the fact that we now have an open solver that we can modify to suit our needs.
%It could be done through defining families of typical problems and finding an optimal set of solver options to solve them.
%That could be done through finding an optimal set of solver options to solve a family of problems.
%For example we could allow it to treat a variable number of constraints along the iterations, that way, some constraints could be dynamically added or ignored during the resolution.
%This could be useful to reduce the amount of computation per iterations, for example by ignoring some collision constraints when they are far from the iterate.

It would be interesting to use our posture generator in a higher-level software, like a multi-contact stance planner, to automatically generate sequences of viable configuration to use to guide the motion of the robot.
Ideally, we would like to integrate the posture generation with our multi-contact control framework to allow on-the-fly replanning of postures when the initial plan becomes not feasible because of issues, such as drift of the robot motion from the original plan.

%We present a formulation of the posture generation problem that takes into account the fact that some variables such as the 3D rotations live in non-Euclidean manifolds while making the writing of problems and of specific constraints more versatile.

%In order to solve nonlinear optimization problems on manifolds, we developped our own solver, which not only allows us to formulate mathematical problems more elegantly and ensure the validity of our variables at every step of the optimization process, but also enables us to have a better understanding and mastering in the way to tune our solver for robotic problems, and allows us to try new ways of solving those problems.

%We proposed several new types of constraint formulation that make the spectrum of discoverable viable postures larger.
%We presented a formulation of non-inclusive flat contacts that allows to generate contacts between two surfaces while monitoring the size of their intersections.
%Leveraging our problem formulation and its ability to manage manifolds allowed us to generate contacts with


%==============================================================================
\chapter{$\rbr{1+1}$-dimensional Dilaton Gravity}
\label{sec:1+1ddlt}
%==============================================================================

Since quantum field theories in $\rbr{3+1}$-dimensional Einstein gravitation
are difficult to solve, one may turn to alternative solvable gravity models to
get some hints for the physics in reality. The $\rbr{1+1}$-dimensional dilaton
gravity, or the Callan--Giddings--Harvey--Strominger (CGHS) model, is such a
candidate, which is used in the thesis and has been extensively studied in the
literature, see for instance \cite{Callan1992,Demers1996,Ashtekar2011}. In this
chapter a very brief review of the model is provided, mainly based on
\cite{Demers1996}.

The action for the model, with $N$ massless scalar fields minimally coupled,
reads
\begin{equation}
S \coloneqq \int \dd^2 x \sqrt{-\ol{g}}\cbr{\frac{\ee^{-2\ol{\phi}}}{\nG}
\sbr{\ol{R}+4\rbr{\nabla \ol{\phi}}^2 + 4\lambda^2}
-\frac{1}{2}\sum_{i=1}^N\rbr{\nabla f_i}^2},
\label{eq:action-CGHS-dilaton}
\end{equation}
where $f_i$'s are the neutral scalar matter fields, $\ol{\phi}$ is the dilaton
field, $\nG$ the dimensionless Newton constant, and $\lambda > 0$ the
cosmological constant. The dilaton field is essential in two dimensions, because
there is only one independent component in the Riemann curvature tensor, hence a
pure $\rbr{1+1}$-dimensional Einstein theory shall be trivial. Transforming
with $\phi = \ee^{-2\ol{\phi}}$ and $g_{\alpha\beta} = \ee^{-2\ol{\phi}}
\ol{g}_{\alpha\beta}$ eliminates the kinetic term for the dilaton, yielding
\begin{equation}
S = \int \dd x\,\dd t\sqrt{-g}\cbr{\frac{1}{\nG}\sbr{R\phi + 4\lambda^2}
-\frac{1}{2}\rbr{\nabla f}^2},
\label{eq:action-CGHS-dilaton-eli}
\end{equation}
where only one matter field is considered for simplicity, and an
ADM-like\footnote{Arnowitt--Deser--Misner, see \cite{Arnowitt2008}.}
parametrisation of the metric
\begin{equation}
\dd s^2 = \ee^{2\rho}\sbr{-\sigma^2\,\dd t^2 + \rbr{\dd x + \xi\,\dd t}^2}
\label{eq:ADM-para}
\end{equation}
is assumed, in which $\rbr{\sigma, \xi}$ are the lapse and shift functions.
The action in \cref{eq:action-CGHS-dilaton-eli} has a classical solution
describing a collapsing null-matter shell, which resembles the solution of
a spherically collapsing body in the $\rbr{3+1}$-dimensional Einstein case.
The corresponding conformal diagram is plotted in \cref{fig:dil-col-bod}.

To apply the canonical quantisation scheme, the action in
\cref{eq:action-CGHS-dilaton-eli} is to be recast in the Hamiltonian formalism.
However, the Legendre transformation of the field momenta proves to be
singular. This means that the momenta, as functions of the positions and
velocities, cannot be inverted to express the corresponding velocities as
functions of momenta and positions, so that the standard algorithm to obtain
the Hamiltonian
\begin{equation}
H \coloneqq \sbr{\frpa{L}{\dot{X}_i}\dot{X}_i - L}_{\dot{X}
= \rfun{\dot{X}}{P,X}}
\end{equation}
does not apply, where $\rbr{X, \dot{X}, P}$ are the positions, velocities and
momenta, respectively.

The systems, of which the Legendre transformation is singular, are called
\emph{constrained systems}. Other examples include a relativistic point
particle in the covariant form, Yang--Mills theories and string theories. For
such systems, the usual quantisation scheme and the Schrödinger equation do
not apply directly. Instead, one has to identify the constraints in the system
and apply Dirac's quantisation rules \cite{dirac1964lectures,Gitman1990}. The
result is that the quantum wave functional describing the CGHS model is
\emph{constrained} by
\begin{align}
0 = \mscrH_\parallel\sfun{\Psi}{\rho,\phi,f} &\coloneqq
\rbr{\frde{\rho}{x}\frdva{}{\rho} - \frde{}{x}\frdva{}{\rho}
+\frde{\phi}{x}\frdva{}{\phi} + \frde{f}{x}\frdva{}{f}}\sfun{\Psi}{\rho,\phi,f},
\label{eq:hpara}\\
0 = \mscrH_\perp\sfun{\Psi}{\rho,\phi,f} &\coloneqq
\rbr{\frac{\nG}{2}\frdva{^2}{\rho\,\dva\phi} - \frac{1}{2}\frdva{^2}{f^2}
+\frac{1}{2\nG}V_G + V_M}\sfun{\Psi}{\rho,\phi,f},
\label{eq:hperp}
\end{align}
where
\begin{equation}
V_G \coloneqq 4\rbr{\frde{^2\phi}{x^2} - \frde{\phi}{x}\frde{\rho}{x} -
2\lambda^2 \ee^{2\rho}},\qquad
V_M \coloneqq\frac{1}{2}\rbr{\frde{f}{x}}^2.
\end{equation}
\Cref{eq:hpara,eq:hperp} are the \emph{Wheeler--DeWitt equations} for the CGHS
model, which play the role of the usual Schrödinger equation for the whole
system.

In the next step, a semi-classical approximation (see also \cite[sec.\
5.4]{Kiefer2012}) of the Born--Oppenheimer type is applied to $\Psi$ by
expanding the exponent as
\begin{equation}
\sfun{\Psi}{\rho,\phi,f} = \ee^{\ii\rbr{\nG^{-1}S_0 + S_1 + \nG S_2 + \ldots}}.
\end{equation}
Inserting this expression into \cref{eq:hpara,eq:hperp}, one finds that at
order $\nG^{0}$, variables can be separated by setting
\begin{equation}
\ee^{\ii S_1} \coloneqq \sfun{D^{-1}}{\rho,\phi}\sfun{\chi}{\rho,\phi,f}.
\end{equation}
Inserting the leading and next-to-leading order terms into
\cref{eq:hpara,eq:hperp} yields
\begin{equation}
\ii \rbr{\frpa{\rho}{t}\frdva{\chi}{\rho} + \frpa{\phi}{t}\frdva{\chi}{\phi}} =
\frac{1}{2}\cbr{-\frdva{^2}{f^2}+\rbr{\frpa{f}{x}}^2} \chi,
\end{equation}
integrating of which gives the functional Schrödinger equation for the matter
field \eqref{eq:functional-Sch-chi}.

% Order $\nG^{-1}$: Hamilton--Jacobi for pure gravity

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../mythesis"
%%% End:


%---------------------------Shape-----------------------------
\section{Edge Ratio\label{s:hex-edge-ratio}}

The edge ratio quality metric is the ratio of the longest to
shortest edge of a hexahedron:
\[
q = \frac{L_{\max}}{L_{\min}}.
\]

\hexmetrictable{edge ratio}%
{$1$}%                                        Dimension
{--}%                                         Acceptable range
{$[1,DBL\_MAX]$}%                             Normal range
{$[1,DBL\_MAX]$}%                             Full range
{$1$}%                                        Cube
{--}%                                         Citation
{v\_hex\_edge\_ratio}%                        Verdict function name


Following the work of \cite{Brosse18tULA}, we aim to quantify the accuracy of these methods by finding the first and second moments of known distributions. Then, comparing the error between the generated value and the true value will give a first indication on the accuracy of the scheme. Beginning with the original code associated with \cite{Brosse18tULA}\footnote{Available at \url{https://github.com/nbrosse/TULA}}, we initially optimised the code then aimed to reproduce the results they found.

\subsection{Testing Potentials}
For the purposes of testing, four qualitatively different potentials have been made available within our program. These are: Gaussian, Double Well, Rosenbrock function and Ginzburg-Landau model. We note that these, save for Gaussian, are non-convex.

Any of the above potentials may also be scaled by \textit{temperature} $T$. That is, having chosen a potential function $U$ and a temperature $T$, the true distribution to be sampled from will be
\[\pi(x) = e^{-\frac{U(x)}{T}}.\]
This is common in the molecular dynamics literature and is also useful in MCMC to find modes of distributions more quickly, a technique known as tempering.

Figure \ref{fig:tamedStep} shows how taming prevents divergence even at higher step sizes, where the untamed algorithms would diverge. Figure \ref{fig:doubleWell_moment} compares first and second moments of the double well distribution in 100 dimensions after running the methods for \(10^5\) iterations and with a stepsize of \(h=0.1\). Note that \texttt{ULA} and \texttt{HOLA} diverge and produce no useful samples. Theoretically, the first moment of this distribution is 0, and the second moment is around 0.104 in 100 dimensions. It can be seen that at this larger step size, the taming is causing an overestimation of the second moment for \texttt{tULA,tLM} and \texttt{tHOLA}. Adjusting the taming to a coordinatewise function is reducing the issue. This a similar phenomena to that seen in Section \ref{sec:stiff}. Figure \ref{fig:timedRun} takes a different approach. Rather than running each algorithm for a fixed number of iterations, we instead let each scheme run for 10 seconds. It can be seen that \texttt{tHOLA} has a much higher range of error when stepsize is low. This is because each iterate takes much longer than the other methods, resulting in an order of magnitude fewer samples being produced in 10 seconds. This is due to the algorithm involving the multiplication of large matrices, a costly computation. When the stepsize is increased the Metroplised algorithms seem to perform worst. It is unclear why this should be the case. Once again \texttt{ULA} and \texttt{LM} diverge.

\begin{figure}
\centering
  \begin{minipage}[b]{0.32\textwidth}
  \centering
    \includegraphics[width=\textwidth]{Figures/tula_fm.png}
  \end{minipage} %
  \begin{minipage}[b]{0.32\textwidth}
  \centering
    \includegraphics[width=\textwidth]{Figures/tulac_fm.png}
  \end{minipage} %
  \begin{minipage}[b]{0.32\textwidth}
  \centering
    \includegraphics[width=\textwidth]{Figures/tmala_fm.png}
  \end{minipage}
   \caption{Comparison of \texttt{tULA}, \texttt{tULAc} and \texttt{tMALA} for the first moment evolving as a function of step size.}
   \label{fig:tamedStep}
\end{figure}

\begin{figure}
\centering
  \begin{minipage}[b]{0.85\textwidth}
  \centering
    \includegraphics[width=\textwidth]{Figures/doublewell_0_1_10_5samp_100dFirstMoment.png}
  \end{minipage}\\ %
  \begin{minipage}[b]{0.85\textwidth}
  \centering
    \includegraphics[width=\textwidth]{Figures/secondmoment_double_well_100d_10_5samp.png}
  \end{minipage} %
  \caption{Comparison of first (top) and second (bottom) moments of the double well distribution in 100 dimensions after running the methods for \(10^5\) iterations and with a stepsize of \(h=0.1\). Note that \texttt{ULA} and \texttt{HOLA} diverge and produce no useful samples.  The true first moment is 0, and second moment $\approx 0.1$}
  \label{fig:doubleWell_moment}
  \end{figure}

  \begin{figure}
\centering
  \begin{minipage}[b]{0.47\textwidth}
  \centering
    \includegraphics[width=\textwidth]{Figures/10sBoxPlot1moment100dim001step.png}
  \end{minipage} %
  \begin{minipage}[b]{0.47\textwidth}
  \centering
    \includegraphics[width=\textwidth]{Figures/10sBoxPlot1moment100dim01step.png}
  \end{minipage} %
  \caption{Comparison of methods when given 10 seconds to run at \(h=0.01\) (left) and \(h=0.1\) (right). Note that \texttt{ULA} and \texttt{LM} both diverge when the stepsize is too high.}
  \label{fig:timedRun}
  \end{figure}


\section{Omitted Proofs}

\subsection{Permutation Network}\label{sec:perm-proof}

We now formally prove that the oblivious permutation network protocol in \figureref{fig:switching-net}	and repeated in \figureref{fig:perm-net-repeat} is secure with respect to the  \f{permute} functionality of  \figureref{fig:perm-ideal-2}.

\begin{figure}
	\framebox{\begin{minipage}{0.95\linewidth}\small
			Parameters: $3$ parties denoted as \programmer, \sender and \receiver. Elements are strings in $\Sigma:=\{0,1\}^\sigma$. An input, output vector size of $n, m$.
			\smallskip

			\input{prot-fig-perm}
	\end{minipage}}
	\caption{The Oblivious Permutation Network protocol $\proto{permute}$ repeated. }
	\label{fig:perm-net-repeat}
\end{figure}

\begin{figure}\small
	\framebox{\begin{minipage}{0.95\linewidth}
			Parameters: $3$ parties denoted as the \programmer, \sender and \receiver. Elements are strings in $\Sigma:=\{0,1\}^\sigma$. An input vector size of $n$ and output size of $m$.

			{\bf [Permute]} Upon the command $(\textsc{Permute}, \pi, \shareTwo{A}_0)$ from the \programmer and $(\textsc{Permute}, \shareTwo{A}_1)$ from the \sender:
			\begin{enumerate}
				\item Interpret $\pi: [m]\rightarrow [n]$ as an injective function and $A\in \Sigma^n$.
				\item Compute $A'\in \Sigma^m$ s.t. $\forall i\in [m], A_{\pi(i)} = A'_i$.
				\item Generate $\shareTwo{A'}$ and send $\shareTwo{A'}_0$ to \programmer and $\shareTwo{A'}_1$ to \receiver.
			\end{enumerate}
	\end{minipage}}
	\caption{The Oblivious Permutation Network ideal functionality \f{permute}.}
	\label{fig:perm-ideal-2}
\end{figure}

\begin{theorem}\label{thm:permute}
	Protocol $\proto{permute}$ of \figureref{fig:perm-net-repeat} securely realized the ideal functionality \f{permute} of \figureref{fig:perm-ideal-2} given at most one party is corrupted in the semi-honest model.
\end{theorem}
\begin{proof}
	Correctness follows directly from $\pi_1\circ \pi_0 = \pi$ and that the masks cancel out.
	With respect to simulation, consider the following three cases:
	\begin{enumerate}
		\item \emph{Corrupt \programmer}: The view of \programmer contains no messages and therefore is trivial to simulation.
		\item \emph{Corrupt \sender}:  The view of \programmer contains $\pi_1, S$ which are sent by \programmer. The simulator can uniformly sample $\pi_1:[m]\rightarrow[n]$ from all such injective functions and uniformly sample $S\gets\Sigma^n$. Clearly $S$ has the same distribution.

		With respect to $\pi_1$, observe if $\pi_1$ if first fixed uniformly at random then there are exactly $(n-m)!$ ways to choose $\pi_0$. Moreover, for each choice of $\pi_1$ there is a disjoint set of possible $\pi_0$ values. Therefore, \programmer sampling $\pi_0$ uniformly at random results in the distribution of $\pi_1$ also being uniform.

		%consider the following hybrid: \programmer first uniformly sample $\pi_1:[m]\rightarrow[n]$ and then defines $\pi_0:[n]\rightarrow[n]$ appropriately. For each choice of $\pi_1$, there are always exactly ${n\choose m}$ options for $\pi_0$. What is more, these options are unique to this choice of $\pi_1$.
		\item \emph{Corrupt \receiver}: The view of \receiver contains $B:= ( A_{\pi_0(1)} \oplus S_1, ..., A_{\pi_0(n)} \oplus S_n)$  and $\pi_1, T\in \Sigma^m$. $\pi_1,T$ are sampled uniformly and therefore trivial to simulation. similarly, each $B_i=A_{\pi_0(i)}\oplus S_i$ where $S_i$ is uniformly distributed in their view. Therefore $B_i$ is similarly distributed.
	\end{enumerate}
\end{proof}

\subsection{Duplication Network}\label{sec:dup-proof}

We now formally prove that the oblivious duplication network protocol in \figureref{fig:switching-net}	and repeated in \figureref{fig:perm-net-repeat} is secure with respect to the  \f{dup} functionality of  \figureref{fig:dup-ideal-2}.

\begin{figure}
	\framebox{\begin{minipage}{0.95\linewidth}\small
			Parameters: $3$ parties denoted as \programmer, \sender and \receiver. Elements are strings in $\Sigma:=\{0,1\}^\sigma$. An input, output vector size of $n$.
			\smallskip

			\input{prot-fig-dup}
	\end{minipage}}
	\caption{The Oblivious Duplication Network protocol \proto{duplicate} repeated. }
	\label{fig:dup-net-repeat}
\end{figure}

\begin{figure}\small
	\framebox{\begin{minipage}{0.95\linewidth}
			Parameters: $3$ parties denoted as the \programmer, \sender and \receiver. Elements are strings in $\Sigma:=\{0,1\}^\sigma$. An input vector size of $n$ and output size of $n$.

			{\bf [Duplicate]} Upon the command $(\textsc{Duplicate}, \pi, \shareTwo{A}_0)$ from the \programmer and $(\textsc{Duplicate}, \shareTwo{A}_1)$ from the \sender:
			\begin{enumerate}
				\item Interpret $\pi: [n]\rightarrow [n]$ as a function s.t. $\pi(1)=1, \pi(i)\in \{i,\pi(i-1)\}$ for $i\in[2,n]$ and $A\in \Sigma^n$.
				\item Compute $A'\in \Sigma^m$ s.t. $\forall i\in [n], A_{\pi(i)} = A'_i$.
				\item Generate $\shareTwo{A'}$ and send $\shareTwo{A'}_0$ to \programmer and $\shareTwo{A'}_1$ to \receiver.
			\end{enumerate}
	\end{minipage}}
	\caption{The Oblivious Duplication Network ideal functionality \f{duplicate}.}
	\label{fig:dup-ideal-2}
\end{figure}

\begin{theorem}\label{thm:dup}
	Protocol $\proto{duplicate}$ of \figureref{fig:dup-net-repeat} securely realized the ideal functionality \f{duplicate} of \figureref{fig:dup-ideal-2} given at most one party is corrupted in the semi-honest model.
\end{theorem}
\begin{proof}
	Correctness follows an inductive argument. It is easy to verify $B_1=\shareTwo{A_1}_1$ and that this is correct since $\pi(1)=1$ by definition. Inductively let us assume that ${B_{i-1}}=\shareTwo{A_{\pi(i-1)}}_1$ and we will show that ${B_i}=\shareTwo{A_{\pi(i)}}_1$.
	Observe that for $i\in[2,n]$
	\begin{align*}
	\shareTwo{B_i}_0&=M^{b_i}_i\qquad\qquad\qquad\qquad\qquad\qquad\qquad\ \ \  \oplus W^{\rho_i}_i\oplus b_i\shareTwo{B_{i-1}}_0 \\
 		    &=\overline{b_i}\shareTwo{A_i}_0\oplus b_i\shareTwo{B_{i-1}}_1 \oplus \shareTwo{B_{i}}_1\oplus W^{b_i\oplus\phi_i}_i\oplus W^{\rho_i}_i\oplus b_i\shareTwo{B_{i-1}}_0  \\
		    &=\overline{b_i}\shareTwo{A_i}_0 \oplus b_i B_{i-1}\oplus \shareTwo{B_i}_1
	\end{align*}
	And therefore $B=\pi(\shareTwo{A}_1)$ and

	\begin{align*}
		A'=&\shareTwo{B}_1\oplus R \oplus \pi(\shareTwo{A}_0) \oplus \shareTwo{B}_1\oplus R\\
		=& B \oplus \pi(\shareTwo{A}_0)\\
		=& \pi(\shareTwo{A}_1) \oplus \pi(\shareTwo{A}_0)\\
		=& \pi(A)\\
	\end{align*}

	With respect to simulation, consider the following three cases:
	\begin{enumerate}
		\item \emph{Corrupt \programmer}: The transcript of \programmer contains $M^0, M^1\in \Sigma^n,\shareTwo{B_1}_0\in \Sigma, \phi\in \{0,1\}^n$ from \sender and $W^{b_i\oplus\phi_i}_i$ from \receiver. First observe that $\shareTwo{B_1}_0, \phi$ are sampled uniformly and therefore can be simulated as the same.

		 Next recall that
	\begin{align*}
	M^{b_i}_i=&...\oplus\shareTwo{B_i}_1\\
	M^{\overline{b_i}}_i=&...\oplus W^{\overline{b_i\oplus\phi_i}}_i
	\end{align*}
	where $\shareTwo{B_i}_1,  W^{\overline{b_i\oplus\phi_i}}_i\in \Sigma$ are sampled uniformly can not in the view of \programmer.  Therefore $M^0_i,M^1_i$ are distributed uniformly.

		\item \emph{Corrupt \sender}:  The transcript of \sender contains nothing and therefore is trivial to simulate. Note that the distribution of the output shares in independent of \sender's random tape (view) due to $\programmer,\receiver$ re-randomizing the shares with $R\gets\Sigma^n$.

		\item \emph{Corrupt \receiver}:  The transcript of \receiver contains $\shareTwo{B_1}_1, W^0,W^1$ from \sender and $\rho$ from \programmer. $W^0,W^1$ are sampled uniformly and therefore can be simulated as the same. $\shareTwo{B_1}_1=A_1\oplus \shareTwo{B_1}_0$ where $\shareTwo{B_1}_0$ is sampled uniformly and not in the view. Therefore $\shareTwo{B_1}_1$ is distributed uniformly. The same applies to $\rho$ since $\phi$ is uniform and not in the view.
	\end{enumerate}
\end{proof}

\subsection{Switching Network}\label{sec:switch-proof}

We now formally prove that the oblivious switching network protocol in \figureref{fig:switching-net} and repeated in \figureref{fig:switch-net-repeat} is secure with respect to the  \f{switch} functionality of  \figureref{fig:switch-ideal-2}. In the proof we will replace calls to the Permutaiton and Duplication protocols of \proto{Switch} with their ideal functionalities (\figureref{fig:perm-ideal-2}, \ref{fig:dup-ideal-2}).

\begin{figure}
	\framebox{\begin{minipage}{0.95\linewidth}\small
			Parameters: $3$ parties denoted as \programmer, \sender and \receiver. Elements are strings in $\Sigma:=\{0,1\}^\sigma$. An input, output vector size of $n, m$.
			\smallskip

			\input{prot-fig-switch}
	\end{minipage}}
	\caption{The Oblivious Switching Network protocol \proto{switch} repeated. }
	\label{fig:switch-net-repeat}
\end{figure}

\begin{figure}\small
	\framebox{\begin{minipage}{0.95\linewidth}
			\input{ideal-fig-switch}
	\end{minipage}}
	\caption{The Oblivious Switching Network ideal functionality \f{switch} repeated.}
	\label{fig:switch-ideal-2}
\end{figure}

\begin{theorem}\label{thm:switch}
	Protocol $\proto{Switch}$ of \figureref{fig:switch-net-repeat} securely realized the ideal functionality \f{switch} of \figureref{fig:switch-ideal-2} given at most one party is corrupted in the semi-honest  model.
\end{theorem}
\begin{proof}
	Correctness follows from the first oblivious permutation call rearranges the input vector such that each output item which appears $k$ times is followed by $k-1$ items which do not appear in the output. The duplication network then copies each of these output items into the next $k-1$ position. The final permutation places these items in the final order.

	With respect to simulation, the transcript of each party contains their transcripts of three subprotocols: Permute, Shared-Duplicate and Shared-Permute. By \theoremref{thm:permute} the Permute subprotocol transcript can be simulated. Similarly, \theoremref{thm:permute},\ref{thm:dup} also imply that the other two transcripts can be simulated. Therefore this implies that the overall protocol can be simulated given that no other communication is performed.

\end{proof}
%
%
%\subsection{Shared Network}\label{sec:shared-proof}
%
%
%
%\begin{figure}
%	\framebox{\begin{minipage}{0.95\linewidth}\small
%			Parameters: $3$ parties denoted as \programmer, \sender and \receiver. Elements are strings in $\Sigma:=\{0,1\}^\sigma$. An input, output vector size of $n, m$.
%			\smallskip
%
%			\input{prot-fig-shared}
%	\end{minipage}}
%	\caption{The Oblivious Shared Switching Network protocol \proto{shared} repeated. }
%	\label{fig:shared-net-repeat}
%\end{figure}
%
%\begin{figure}\small
%	\framebox{\begin{minipage}{0.95\linewidth}
%
%			Parameters: $3$ parties denoted as the \programmer, \sender and \receiver. Elements are strings in $\Sigma:=\{0,1\}^\sigma$. An input vector size of $n$ and output size of $m$.
%
%			{\bf [Shared]} Upon the command $(\textsc{Shared}, cmd, \pi, \shareTwo{A}_0)$ from the \programmer and $(\textsc{Shared},cmd, \shareTwo{A}_1)$ from the \sender:
%			\begin{enumerate}
%				\item Interpret $\pi: [m]\rightarrow [n]$ and $A=\shareTwo{A}_0\oplus \shareTwo{A}_1\in \Sigma^n$.
%				\item If $cmd=\textsc{Permute}$, require $\pi$ to be injective.
%				\item If $cmd=\textsc{Duplicate}$, require $n=m,\pi(1)=1, \pi(i)\in \{i, \pi(i-1)\}, \forall i\in[2,n]$.
%				\item Require $cmd\in \{\textsc{Permute},\textsc{Duplicate},\textsc{Switch}\}$.
%
%				\item Compute $A'\in \Sigma^m$ s.t. $\forall i\in [m], A_{\pi(i)} = A'_i$.
%				\item Generate $\shareTwo{A'}$ and send $\shareTwo{A'}_0$ to \programmer and $\shareTwo{A'}_1$ to \receiver.
%
%			\end{enumerate}
%
%	\end{minipage}}
%	\caption{The Oblivious Shared Switching Network ideal functionality \f{shared}.}
%	\label{fig:shared-ideal-2}
%\end{figure}
%
%
%
%\begin{theorem}\label{thm:shared}
%	Protocol $\proto{shared}$ of \figureref{fig:shared-net-repeat} securely realized the ideal functionality \f{shared} of \figureref{fig:shared-ideal-2} given at most one party is corrupted in the semi-honest  model.
%\end{theorem}
%\begin{proof}
%	Correctness follows from the correctness of the underlying subprotocol and that the \programmer can locally apply the mapping function to their own share. Simulation of this protocol is exactly that of the underlying subprotocol along with updating the output as specified.
%\end{proof}
%

\subsection{Join Protocol}\label{sec:join-proof}

\begin{theorem}\label{thm:join}
	Protocol $\proto{join}$ of \figureref{fig:full_proto} securely realized the ideal functionality \f{join} of \figureref{fig:full_ideal} given at most one party is corrupted in the semi-honest \f{Permute},\f{Switch},\f{encode}-hybrid model with statistical security parameters $\lambda$.
\end{theorem}
\begin{proof}
	First we demonstrate the correctness of the protocol. Recall that the set of non-\null join keys $\{(X_{J_1}||...||X_{J_l})[i] \mid i\in [n]\}$ are all distinct. The same holds true for the $Y$ table. As such, $P_0$ receives $n$ uniformly random values from \f{encode}. As discussed in \ref{sec:encode}, given that these encodings are of length at least $\lambda + 2 \log_2(n)$ bits, then with probability $1-2^{-\lambda}$ all the encodings are distinct.

	Recall that $P_1$ then constructs a cuckoo hash table using the encodings $\mathbb{E}_y$. Given that cuckoo hash table is parameterized as described in  \cite{DRRT18}, this succeeds with overwhelming probability, i.e. $1-2^{-\lambda}$.

	The correctness of the rest of the protocol is straight forward. The shared table $\share{Y}$ are permuted to form a shared cuckoo hash table $\share{T}$. Based on the encodings  $\mathbb{E}_x$, the shares in the table $T$ are mapped to the corresponding row of $X$. It is easy to verify that if $Y$ has a matching row then it will have been mapped. Finally, \f{mpc} is used to compute the circuit which constructs the output table.

	With respect to simulation, consider the following cases:
	\begin{enumerate}
		\item \emph{Corrupt $P_0$}: The transcript of $P_0$ contains the encodings $\mathbb{E}_x$, the output $\shareTwo{\widehat{Y}^l}_0$ from \f{Switch}, and the output of $\f{mpc}$. Given that the inputs to \f{encode} are either set to \null or all distinct values, the output $\mathbb{E}_x$ is uniformly distributed and therefore can be sample as such by the simulator. Similarly, the output of $\f{Switch},\f{mpc}$ are both uniform.

		\item \emph{Corrupt $P_1$}:  The transcript of $P_1$ contains the encodings $\mathbb{E}_y$, the output $\shareTwo{\widehat{T}}_1$ from \f{Permute}, the output $\shareTwo{\widehat{Y}^l}_1$ from \f{Switch}, and the output of $\f{mpc}$. All of these are distributed uniformly. The simulation of this transcript follows the same as that of $P_0$.

		\item \emph{Corrupt $P_2$}: The transcript of $P_2$ contains the output $\shareTwo{\widehat{T}}_0$ from \f{Permute}, the output $\shareTwo{\widehat{Y}^l}_0$ from \f{Switch}, and the output of $\f{mpc}$. All of these are distributed uniformly. The simulation of this transcript follows the same as that of $P_0$.
	\end{enumerate}

\end{proof}