\section{Extensions of the Euler-Lagrange Equations}
\subsection{Euler-Lagrange with Constraints}
Our objective is to extremize the functional
$$F[y]=\int_\alpha^\beta f(x,y,y^\prime)\,\mathrm dx$$
subject to the constraint $G[y]=0$ for a functional $G$ in the form
$$G[y]=\int_\alpha^\beta g(x,y,y^\prime)\,\mathrm dx$$
We can tackle this by using an analog of Lagrange multiplier.
Consider the new functional
$$\Phi[y;\lambda]=F[y]-\lambda G[y]=\int_\alpha^\beta (f-\lambda g)(x,y,y^\prime)\,\mathrm dx$$
from the study of Lagrange multiplier earlier in the $\mathbb R^n$ case, we are inspired to extremise $\Phi$ instead.
The Euler-Lagrange equation form $\Phi$ is then
$$\frac{\mathrm d}{\mathrm dx}\frac{\partial}{\partial y^\prime}(f-\lambda g)=\frac{\partial}{\partial y}(f-\lambda g)$$
\begin{example}[Dido's Problem (aka the Isoperimetric Problem)]
    We want to ask what simple closed plane curve with fixed length $L$ maximises its area.
    We can assume WLOG that the curve is convex and put it on the coordinate plane.
    Then by convexity it is bounded by the lines $x=\alpha,x=\beta$ for some $\alpha,\beta$.
    Also, for each $x\in(\alpha,\beta)$ there are exactly two values $y=y_1,y_2$, $y_1<y_2$ such that $(x,y)$ is on the curve.
    The area element is then $\mathrm dA=(y_2-y_1)\,\mathrm dx$.
    So the functional we want to maximise is
    $$A[y]=\int_\alpha^\beta y_2-y_1\,\mathrm dx=\oint_Cy\,\mathrm dx$$
    subject to the contraint that
    $$L[y]=\oint_C\,\mathrm dl=\oint_C\sqrt{1+(y^\prime)^2}\,\mathrm dx$$
    is constantly $L$.
    To use Lagrange multiplier, we set $h=y-\lambda\sqrt{1+(y^\prime)^2}$, then as $h$ does not explicitly depend on $x$, we can use the first integral
    $$K=\text{const.}=h-y^\prime\frac{\partial h}{\partial y^\prime}=y-\frac{\lambda}{\sqrt{1+(y^\prime)^2}}\implies (y^\prime)^2=\frac{\lambda^2}{(y-K)^2}-1$$
    Hence,
    $$\int\frac{y-K}{\sqrt{\lambda^2-(y-K)^2}}\,\mathrm dy=x-x_0\implies (y-y_0)^2+(x-x_0)^2=\lambda^2$$
    where $x_0,y_0$ are constants.
    This is the equation of a circle, and by the constraint, $\lambda=L/2\pi$.
\end{example}
\begin{example}[The Sturm-Liouville Problem]\label{sturm-liouville}
    Let $\rho=\rho(x)>0$ for $x\in [\alpha,\beta]$.
    Consider the following functional:
    $$F[y]=\int_\alpha^\beta\rho(x)(y^\prime)^2+\sigma(x)y^2\,\mathrm dx$$
    which we want to maximise subject to the condition that
    $$G[y]=\int_\alpha^\beta y^2\,\mathrm dx=1$$
    One will see it again and again in the settings of quantum mechanics.
    So our goal is to extremise
    $$\Phi[y;\lambda]=F[y]-\lambda(G[y]-1)$$
    So
    $$h=\rho(y^\prime)^2+\sigma y^2-\lambda\left( y^2-\frac{1}{\beta-\alpha} \right)$$
    The Euler-Lagrange equation is then
    $$-\frac{\mathrm d}{\mathrm dx}(\rho y^\prime)+\sigma y=\lambda y$$
    We write $\mathcal L(y)$ to denote the differential operator on the right hand side.
    $\mathcal L$ is called the Sturm-Liouville operator.
    Viewing it like this, the ODE is now the eigenvalue problem of the operator $\mathcal L$.
\end{example}
\begin{remark}
    If $\rho=1$, then $\sigma$ can be taken as the potential which makes the equation the (one-dimensional) time-independent Schr\"odinger equation.
\end{remark}
If $\sigma>0$ everywhere, then $F[y]>0$ everywhere.
\begin{claim}
    We claim that he (positive) mimimum of $F[y]$ is the lowest eigenvalue of $\mathcal L$.
\end{claim}
\begin{proof}
    We multiply the Sturm-Liouville equation by $y$ on both sides and integrate from $\alpha$ to $\beta$, which gives $F[y]=\lambda G[y]$.
\end{proof}
\subsection{Several Dependent Variables}
Suppose $\underline{y}(x)=(y_1(x),\ldots,y_n(x))$.
We want to consider the functional
$$F[\underline{y}]=\int_\alpha^\beta f(x,y_1,\ldots,y_n,y_1^\prime,\ldots,y_n^\prime)\,\mathrm dx$$
Suppose a perturbation $y_i=y_i+\epsilon \eta_i$ is incurred for $i=1,\ldots,n$, $\epsilon>0$ small and $\eta_i(\alpha)=\eta_i(\beta)=0$.
Then
$$F[\underline{y}+\epsilon\underline{\eta}]-F[\underline{y}]=\epsilon\int_\alpha^\beta\sum_{i=1}^n\eta_i\left( \frac{\mathrm d}{\mathrm dx}\frac{\partial f}{\partial y_i^\prime}-\frac{\partial f}{\partial y_i} \right)\,\mathrm dx+O(\epsilon^2)$$
By Lemma \ref{fund_lemma}, we have
$$\frac{\mathrm d}{\mathrm dx}\frac{\partial f}{\partial y_i^\prime}=\frac{\partial f}{\partial y_i}$$
for $i=1,\ldots,n$.
This is simply just $n$ Euler-Lagrange equations, which are $n$ second-order ODEs.
Of course, we also want to reduce this system of second order ODEs to first integrals whenever possible.\\
If $\partial f/\partial y_j=0$ for some $j$, then
$$\frac{\partial f}{\partial y_j^\prime}=\text{const.}$$
If the number of such $j$'s is big enough, we can simplify this a big deal.\\
If $\partial f/\partial x=0$, then we have
$$f-\sum_{i=1}^ny_i^\prime\frac{\partial f}{\partial y_i^\prime}=\text{const.}$$
which might help in some cases.
\begin{example}[Geodesics on Surfaces]
    Consider a surface $\Sigma\subset\mathbb R^3$ given by $g(x,y,z)=0$.
    Pick two points $A,B$ from $\Sigma$.
    Our aim is to minimize the length of shortest path on $\Sigma$ which connects $A,B$.
    If such a length exists, then any path with this length is called a geodesics.
    Let $t\in[0,1]$ be a parameter on the curve and parameterise a curve between $A,B$ by $\underline{x}(0)=A,\underline{x}(1)=B$.
    For the curve to lie on the surface, we have the constraint $g(\underline{x}(t))=0$ for any $t$.\\
    So by the idea of Lagrange multiplier, we want to minimise the functional
    $$\Phi[\underline{x},\lambda]=\int_0^1\left( \sqrt{\dot{x}^2+\dot{y}^2+\dot{z}^2} -\lambda(t) g(x,y,z)\right)\,\mathrm dt$$
    Note that the Lagrange multiplier is now a function $\lambda=\lambda(t)$, as our constraint has to be valid for all $t$.
    Write the integrand in $\Phi$ by $h(x,y,z,\lambda,\dot{x},\dot{y},\dot{z})$.
    The Euler-Lagrange equation wrt $\lambda$ is then
    $$\frac{\mathrm d}{\mathrm dt}\frac{\partial h}{\partial \dot{\lambda}}-\frac{\partial h}{\partial\lambda}=0\implies g(x,y,z)=-\frac{\partial h}{\partial\lambda}=0$$
    For the rest of the Euler-Lagrange equations, write $(x,y,z)=x_i\underline{e_i}$, then it becomes
    $$\frac{\mathrm d}{\mathrm dt}\left( \frac{\dot{x}_i}{\sqrt{\dot{x}^2+\dot{y}^2+\dot{z}^2}} \right)+\lambda\frac{\partial g}{\partial x_i}=0$$
    which, for specified $g$, should solve to get us a geodesics.
\end{example}
\subsection{Several Independent Variables}
In general, the parameter of the functional is a function $\mathbb R^n\to\mathbb R^m$.
If $n>1$, then the Euler-Lagrange equations, as one may expect, become PDEs.
Suppose $n=3$, then the functional can have the form
$$F[\phi]=\int_Df(x,y,z,\phi,\phi_x,\phi_y,\phi_z)\,\mathrm dx\,\mathrm dy\,\mathrm dz$$
where $D\subset\mathbb R^3$.
Assume $\phi$ is at an extremum of $F$, then the perturbation we are considering would become
$$\phi(x,y,z)\mapsto \phi(x,y,z)+\epsilon \eta(x,y,z), \epsilon\in\mathbb R,\eta|_{\partial D}=0$$
So if we write
$$\underline{v}=\left( \frac{\partial f}{\partial \phi_x},\frac{\partial f}{\partial \phi_y},\frac{\partial f}{\partial\phi_z} \right)$$
then,
\begin{align*}
    F[\phi+\epsilon\eta]-F[\phi]&=\epsilon\int_D\left( \eta\frac{\partial f}{\partial\phi}+\eta_x\frac{\partial f}{\partial \phi_x}+\eta_y\frac{\partial f}{\partial \phi_y}+\eta_z\frac{\partial f}{\partial \phi_z} \right)\,\mathrm dx\,\mathrm dy\,\mathrm dz+O(\epsilon^2)\\
    &=\epsilon\int_D\left( \eta\frac{\partial f}{\partial\phi}+\nabla\cdot( \eta\underline{v})-\eta\nabla\cdot\underline{v} \right)\,\mathrm dx\,\mathrm dy\,\mathrm dz+O(\epsilon^2)
\end{align*}
By the Divergence Theorem, we have
$$\int_D\nabla\cdot(\eta\underline{v})\,\mathrm dx\,\mathrm dy\,\mathrm dz=\int_{\partial D}\eta\underline{v}\cdot\mathrm d\underline{S}=0$$
By the boundary assumption on $\eta$, therefore
$$\frac{F[\phi+\epsilon\eta]-F[\phi]}{\epsilon}=\int_D\eta\left( \frac{\partial f}{\partial\phi}-\nabla\cdot\underline{v} \right)\,\mathrm dx\,\mathrm dy\,\mathrm dz$$
We obviously have the analogy of Lemma \ref{fund_lemma} here, hence for $\delta F=0$, we obtain
$$\frac{\partial f}{\partial\phi}-\nabla\cdot\underline{v}=0$$
which, by expanding $\underline{v}$, is
$$\frac{\partial f}{\partial\phi}-\frac{\partial}{\partial x_i}\frac{\partial f}{\partial \phi_{x_i}}=0$$
where the summation is implied by convention.
This can be generalized from $3$ to $n$ in an obvious way.
\begin{example}
    We want to extremise the functional of potential energy
    $$F[\phi]=\iint_{D\subset\mathbb R^2}\frac{1}{2}(\phi_x^2+\phi_y^2)\,\mathrm dx\,\mathrm dy$$
    Where $\phi:\mathbb R^2\to\mathbb R$.
    So the Euler-Lagrange equation becomes
    $$\phi_{xx}+\phi_{yy}=0$$
    which is the Laplace equation.
\end{example}
\begin{example}[Minimal Surfaces]
    We want to minimise the area of a surface $\Sigma\subset\mathbb R^3$ subject to boundary conditions (e.g. specified $\partial\Sigma$).
    This can allow us to find the shape of a soap film.
    Suppose we can write $\Sigma$ as the graph of $z=f(x,y)$ for some function $\phi$.
    \footnote{This can always be done locally given that $\Sigma$ is nice enough due to Implicit Function Theorem.}
    The line element is $\mathrm ds^2=\mathrm dx^2+\mathrm dy^2+\mathrm dz^2$ and we have $\mathrm dz=\phi_x\,\mathrm dx+\phi_y\,\mathrm dy$, so
    $$\mathrm ds^2=(1+\phi_x^2)\,\mathrm dx^2+(1+\phi_y^2)\mathrm dy^2+2\phi_x\phi_y\,\mathrm dx\,\mathrm dy$$
    This is called the first fundamental form (or the Riemannian metric) in geometrical settings.
    We can write, in summation notation, $\mathrm ds^2=g_{ij}(x,y)\,\mathrm dx^i\,\mathrm dx^j$ with
    $$g=\begin{pmatrix}
            1+\phi_x^2&\phi_x\phi_y\\
            \phi_x\phi_y&1+\phi_y^2
    \end{pmatrix}$$
    As one can verify, $\det g\ge 0$ and $\sqrt{\det g}$, so
    $$A[\phi]=\iint_D\sqrt{1+\phi_x^2+\phi_y^2}\,\mathrm dx\,\mathrm dy$$
    Write $h$ to denote the integrand, then we have
    $$\frac{\partial h}{\partial\phi_x}=\frac{\phi_x}{\sqrt{1+\phi_x^2+\phi_y^2}},\frac{\partial h}{\partial\phi_y}=\frac{\phi_y}{\sqrt{1+\phi_x^2+\phi_y^2}}$$
    So, upon some simplification, the Euler-Lagrange equation transforms to
    $$(1+\phi_y^2)\phi_{xx}+(1+\phi_x^2)\phi_{yy}-2\phi_x\phi_y\phi_{xy}=0$$
    which is known as the minimal surface equation.\\
    A particular case of it is when the surface is a surface of revolution, i.e. $z=z(r),r=\sqrt{x^2+y^2}$.
    We want to solve it subject to the surface's boundary being two equal circles whose centres are on the $z$-axis and are parallel to the $x-y$ plane.
    This initial condition can give us the shape of soap film between two circular loops.\\
    In this case, the PDE transforms to
    $$rz^{\prime\prime}+z^\prime+(z^\prime)^3$$
    by a lot of calculations.
    Write $w=z^\prime$, then
    $$\frac{1}{2}r\frac{\mathrm dw^2}{\mathrm dr}+w^2+w^4$$
    which we can integrate to find
    $$r=r_0\cosh\left( \frac{z-z_0}{r_0} \right)$$
    which is called the catenoid.
    This result was first proved by Euler in 1744.
    Note that being a catenoid is a necessary condition for a minimal surface in this form to exist.\\
    Suppose the centres of the circles are located at $L\underline{e_z}$ and $-L\underline{e_z}$ and both circles have radius $R$.
    Then $r(L)=r(-L)$, hence if $L\neq 0$ then $-L-z_0=-L+z_0$, thus $z_0=0$.
    Therefore $R=r_0\cosh(L/r_0)$.
    But $r_0$ is then the radius of the circle as the intersection between the surface and the $x-y$ plane.
    WLOG set $L=1$ (as we can scale the whole thing), then by a simple plot we obtain that $R\ge c$ globally for some $c>0$.
    By estimation the minimum occurs at $r_0\approx 0.833$ and $c\approx 1.5$.
    Also, for $R>c$, we see that there are two possible values of $r_0$, which corresponds to two minimal surfaces.
    After our latter discussion on second variations, we find that the thinner one of which is unstable and the thicker one is stable.
\end{example}
The case where $R$ is less than the threshold exhibits an example where there is no solution.
\subsection{Higher Derivatives}
We want to generalise the theory to a wider range of functionals, specifically in the form
$$F[y]=\int_\alpha^\beta f(x,y,y^\prime,\ldots,y^{(n)})\,\mathrm dx$$
Assume such an $y$ that extremises $F$ exists, then consider the perturbation $y\mapsto y+\epsilon\eta$ where $\eta,\eta^\prime,\ldots,\eta^{(n-1)}$ all vanishes at $\alpha,\beta$, then by the higher-dimensional Taylor expansion,
$$F[y+\epsilon\eta]-F[y]=\epsilon\int_\alpha^\beta\left( \frac{\partial f}{\partial y}\eta+\cdots +\frac{\partial f}{\partial y^{(n)}}\eta^{(n)} \right)\,\mathrm dx+O(\epsilon^2)$$
By integration by part,
$$\int_\alpha^\beta\frac{\partial f}{\partial y^{(i)}}\eta^{(i)}\,\mathrm dx=\int_\alpha^\beta\eta(-1)^i\frac{\mathrm d^i}{\mathrm dx^i}\frac{\partial f}{\partial y^{(i)}}\,\mathrm dx$$
Due to our boundary conditions on $\eta$.
Hence
$$\frac{F[y+\epsilon\eta]-F[y]}{\epsilon}=\int_\alpha^\beta \eta\left(\frac{\partial f}{\partial y}+\sum_{i=1}^n(-1)^i\frac{\mathrm d^i}{\mathrm dx^i}\frac{\partial f}{\partial y^{(i)}}\right)\,\mathrm dx+O(\epsilon)$$
Hence by Lemma \ref{fund_lemma}, we obtain the Euler-Lagrange equation in the following form:
$$\frac{\partial f}{\partial y}+\sum_{i=1}^n(-1)^i\frac{\mathrm d^i}{\mathrm dx^i}\frac{\partial f}{\partial y^{(i)}}=0$$
\begin{example}[First Integral]
    If $n=2$ and $f$ does not explicitly depend on $y$, the equation becomes
    $$\frac{\mathrm d}{\mathrm dx}\left( \frac{\partial f}{\partial y^\prime}-\frac{\mathrm d}{\mathrm dx}\frac{\partial f}{\partial y^{\prime\prime}} \right)=0\implies \frac{\partial f}{\partial y^\prime}-\frac{\mathrm d}{\mathrm dx}\frac{\partial f}{\partial y^{\prime\prime}}=\text{const.}$$
\end{example}
\begin{example}
    If we want to extremise
    $$F[y]=\int_0^1(y^{\prime\prime})^2\,\mathrm dx$$
    with $y(0)=y(1)=y^\prime(0)=0$ and $y^\prime(1)=1$.
    Then the first integral above reduces to
    $$\frac{\mathrm d}{\mathrm dx}(2y^{\prime\prime})=\text{const.}\implies y^{(3)}=\text{const.}$$
    which solves to $y=x^3-x^2$ for the specified boundary conditions.
\end{example}
Note that the $y_0$ in the previous example is actually an absolute minimum of the functional $F$.
To argue this, observe that for an arbitrary $C^2$ function $\eta$ with $\eta,\eta^\prime$ both vanish at $0,1$ but $\eta$ is not identically zero.
Then
\begin{align*}
    F[y_0+\eta]-F[y_0]&=\int_0^1(\eta^{\prime\prime})^2\,\mathrm dx+2\int_0^1 y_0^{\prime\prime}\eta^{\prime\prime}\,\mathrm dx\\
    &>4\int_0^1(3x-1)\eta^{\prime\prime}\\
    &=0
\end{align*}
through integration by part.
Hence $y$ is the global minimum in our chosen space $C^2[0,1]$.
This trick does not always work, but sometimes it does, like the one we just did.


\section{K-D Trees and Nearest Neighbors}

\paragraph{Consistency heuristic} Whenever you want to guess a
property of something, given nothing else to go on but a set of
reference cases, find the most similar case, as measured by known
properties, for which the property is known. Guess that the
unknown property is the same as that known property.

\paragraph{Decision tree} A decision tree is a representation,
that is a semantic tree in which:
\begin{itemize}
  \item Each node is connected to a set of possible answers
  \item Each nonleaf noed is connected to a test that splits its
    set of possible answers into subsets corresponding to
    different test results
  \item Each branch carries a particular test result's subset to
    another node
\end{itemize}

\paragraph{k-d tree} A k-d tree is a representation,
that is a decision tree in which:
\begin{itemize}
  \item The set of possible answers consists of points, one of
    which may be the nearest neighbor to a given point
  \item Each test specifies a coordinate, a threshold, and a
    neutral zone around the threshold containing no points
  \item Each test divides a set of points into two sets, according
    to on which sid of the threshold each point lies
\end{itemize}

How to divide the cases into sets:
\begin{itemize}
  \item If there is only one case, stop
  \item If this is the first division of cases, pick the vertical
    axis for comparison; otherwise, pick the axis that is
    different from the axis at the next higher level
  \item Considering only the axis of comparison, find the average
    position of the two middle objects. Call this average position
    the threshold, and construct a decision-tree test that
    compares unknowns in the axis of comparison againsts the
    threshold. Also note the position of the two middle obkects in
    the axis of comparison. Call these positions the upper and
    lower boundaries
  \item Divide up all the obects into two subsets, accorting to on
    which side of the average position they lies
  \item Divide up thw objects in each subset, forming a subtree
    for each, using this procedure
\end{itemize}

To find the nearest neighbor using the K-D procedure:
\begin{itemize}
  \item Determine whether there is only one element in the set
    under consideration
  \begin{itemize}
    \item If there is only one, report it
    \item Otherwise, compare the unknown, in the axis of
      comparison, against the current node's threshold. The result
      determines the likely set
    \item Find the nearest neighbor in the likely set using this
      procedure
    \item Determine whether the distance to the nearest neighbor
      in the likely set is less than or equal to the distance to
      the other set's boundary in the axis of comparison:
      \begin{itemize}
        \item If it is, then report the nearest neighbor in the
          likely set
        \item If it is not, check the unlikely set using this
          procedure; return the nearer of the nearest neighbors in
          the likely set and in the unlikely set
      \end{itemize}
  \end{itemize}
\end{itemize}


\subsection{Critical Points}
\noindent
Critical points are those that have the possibility of being a minimum or maximum.
They are an extension of critical points in single-variable calculus when the derivative is 0.\\

\noindent
\begin{definition}
	$(x_0, y_0)$ is a critical point of $f$ if $f_x$ and $f_y$ at $(x_0, y_0)$ both are 0 or DNE.
\end{definition}

\noindent
For example, consider the function $f(x,y) = x^2/2 - y^2/2 - xy - 2x - 2y$.
\begin{align*}
	f_x &= x - y - 2	\text{ and is } 0 \text{ when } y = x-2 \\
	f_y &= -y - x - 2 \text{ and is } 0 \text{ when } y = -x-2 \\
	x - 2 &= -x -2 \text{ when } x = 0.
\end{align*}
When $x = 0$, $ y =-2$, so $(0, -2)$ is a critical point of $f$.

\input{./differentialMultivariableCalculus/2ndDerivativeTestHessianMatrix}


\chapter{Cycles in the Collatz Tree}

\section{A remark about cycles}
\label{sec:cycles}
In graph theory, a path of length $n\geq 1$ that starts and ends at the same vertex is called a circuit. A circuit, in which no vertex is repeated with the sole exception that the initial vertex is the terminal vertex, is called a cycle. A cycle of length $n$ is referred to as an $n$-cycle. For these definitions, we rely on \cite[p.~599]{Ref_Rosen}, \cite[p.~35]{Ref_Benjamin_Chartrand_Zhang} and \cite[p.~445]{Ref_Chartrand_Zhang}. Furthermore, we call a cycle originating from the root a trivial cycle.

\begin{remark}
	In order for the cycles to become graphically visible, we now require that in a graph $H$ two vertices $v_1$ and $v_2$ are one and the same if the label of both nodes are identical: $l_{V(H)}(v_1)=l_{V(H)}(v_2)\rightarrow v_1=v_2$. As a consequence, there is no guarantee that the graph precisely refers to the algebraic structure of a free monoid anymore. A free monoid requires that each of its elements can be written in one and only one way.
\end{remark}

When different nodes collapse on one, the graph is no longer necessarily a tree. Let us point to the monoid S*, which we introduced in section \ref{sec:groups_graphs}. Take for example four of its elements, the empty string $e$, the strings $qqr$, $qqrqqr$, and $qqrqqrqqr$. These elements lie as well within the subset $U\subset T\subset S^*$, and they are represented by nodes of the tree $H_U$ that all have the same label $1=ev_{S^*}(qqr,1)=ev_{S^*}(qqrqqr,1)=ev_{S^*}(qqrqqrqqr,1)$. These nodes are one and the same, the root of $H_U$. Visually, then in $H_U$ a directed edge goes from the vertex labeled with $4$ back to the root node. Analogically, in $H_C$ a loop connects the root to itself, since due to the path contraction even labeled nodes do not exist in $H_C$. The  aforementioned example reflects the trivial cycle of the Collatz sequence.

\par\medskip
Figure~\ref{fig:5} depicts a section of $H_{C,5}$, which includes the $3$-cycle $43,17,27$. Because of the two non-trivial cycles $43,17,27$ and $83,33,13$, in $H_{C,5}$ there does not exist a path between the root and the vertex $43$ and between the root and the vertex $83$. Hence, $H_{C,5}$ is said to be a disconnected graph. Generally, a graph is called a disconnected graph if it is impossible to walk (along its edges) from any vertex to any other \cite[pp.~46-47]{Ref_Benjamin_Chartrand_Zhang}.

\begin{figure}
	\includegraphics[width=1.00\textwidth]{figures/h_c5a.png}
	\caption{Section of $H_{C,5}$ including the $3$-cycle $43,17,27$}
	\label{fig:5}
\end{figure}

\par\medskip
The following considerations focus on non-trivial cycles, and therefore on cycles that do not originate from the root, but cause the graph to be a disconnected graph. Utilizing the example of the graph $H_{C,5}$ we are able to deduct from the cycle $43,17,27$ the simple and self-evident equality $\textit{left-child}^3(43)=43$:
\begin{equation*}
\begin{array}{l}
\textit{left-child}(43)=\frac{1}{5}*\left(43*2^1-1\right)=17
\\[\medskipamount]
\textit{left-child}(17)=\frac{1}{5}*\left(17*2^3-1\right)=27
\\[\medskipamount]
\textit{left-child}(27)=\frac{1}{5}*\left(27*2^3-1\right)=43
\end{array}
\end{equation*}

Obviously, the authors note, it would be interesting to find out what circumstances enable a graph to have non-trivial cycles, whether it be the $5x+1$ variant of $H_C$, the $7x+1$ variant of $H_C$ or any variant of $H_C$; let us say the $kx+1$ variant of $H_C$ with $k\geq 1$.

\section{Which variants of \mbox{$H_C$} have non-trivial cycles?}
\label{sec:non_trivial_cycles}
Let us refer to a $kx+1$ variant of $H_C$ as $H_{C,k}$. By having introduced and proven theorem~\ref{theo:1} we already started an assertion about the reachability of successive nodes in $H_C$. This reachability relationship can be generalized for any graph $H_{C,k}$ as follows:
\begin{equation}
\label{eq:generalized_reachability}
v_{n+1}=k^nv_1\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)2^{-\alpha_i}
\end{equation}

This generalization leads to the condition for an existence of an $n$-cycle in any $kx+1$ variant of $H_C$, which looks analogous to the condition given by equation~\ref{eq:func_cycle} that specifies $H_C$ has a cycle:
\begin{equation}
\label{eq:generalized_cycle}
2^\alpha=\prod_{i=1}^{n}\left(k+\frac{1}{v_i}\right)
\end{equation}

The natural number $\alpha$ is the sum of edges that have been contracted between the vertices $v_i$ forming the cycle, in other words $\alpha$ is the number of divisions by $2$ within the sequence. The natural number $n$ is the cycle length and $k$ obviously specifies the variant of $H_C$. Since between each vertex at least one edge has been contracted (at least one division by $2$ took place), we know that our exponent alpha is greater than or equal to the sequence length:
\begin{equation}
\label{eq:n_alpha}
\alpha\ge n
\end{equation}

\par\medskip
Using incremental search, one can calculate cycles through trial and error. Table~\ref{table:known_cycles} lists all empirically discovered cycles having a length up to $100$ that appear in $kx+1$ variants of $H_C$ for $k\in[1,1000]$. Within each of these variants, the cycles have been searched at potential starting nodes $v_1$ with a label between $1$ and $1000$. Note that the cycles in table~\ref{table:known_cycles} are written in reverse order, i.e. in the order which corresponds to the Collatz sequence. To obtain the cycles in terms of graph theory referring to the graph $H_C$, read them from right to left.

\begin{table}[H]
	\centering
	\begin{tabular}{|L{2cm}|R{4cm}|R{2cm}|C{2cm}|}
		\hline
		\thead{\boldsymbol{$k$}} &
		\thead{\textbf{cycle}} &
		\thead{\boldsymbol{$\alpha$}} &
		\thead{\textbf{non-trivial}} \\
		\hline
		1 &
		1 &
		1 &
		\\
		\hline
		3 &
		1 &
		2 &
		\\
		\hline
		5 &
		1,3 &
		5 &
		\\
		\hline
		5 &
		13,33,83 &
		7 &
		\checkmark \\
		\hline
		5 &
		27,17,43 &
		7 &
		\checkmark \\
		\hline
		7 &
		1 &
		3 &
		\\
		\hline
		15 &
		1 &
		4 &
		\\
		\hline
		31 &
		1 &
		5 &
		\\
		\hline
		63 &
		1 &
		6 &
		\\
		\hline
		127 &
		1 &
		7 &
		\\
		\hline
		181 &
		27,611 &
		15 &
		\checkmark \\
		\hline
		181 &
		35,99 &
		15 &
		\checkmark \\
		\hline
		255 &
		1 &
		8 &
		\\
		\hline
		511 &
		1 &
		9 &
		\\
		\hline
	\end{tabular}
	\caption{Known $n$-cycles in $kx+1$ variants of $H_C$ for $k\leq1000$, $n\leq 100$}
	\label{table:known_cycles}
\end{table}
Based on the results shown in table~\ref{table:known_cycles} we state the following theorem~\ref{theo:2} that renders more precisely the prerequisite for cycles that may occur in variants of $H_C$.

\par\medskip
\begin{theorem}
	\label{theo:2}
	An $n$-cycle can only exist in a graph $H_{C,k}$, that means in a $kx+1$ variant of $H_C$, if the following equation holds:
	\begin{equation*}
	2^{\bar\alpha}=2^{\lfloor n\log_2k\rfloor+1}=\prod_{i=1}^{n}\left(k+\frac{1}{v_i}\right)
	\end{equation*}
\end{theorem}

\par\medskip
The key of theorem~\ref{theo:2} consists in the claim that, in order for an $n$-cycle to occur, the exponent $\alpha$ has to be $\bar\alpha=\lfloor n\log_2k\rfloor+1$. We approach a proof by expressing formally that $\bar\alpha$ is not allowed to be smaller and it is not allowed to be greater than $\lfloor n\log_2k\rfloor+1$, in other words we indicate a lower and an upper limit for $\bar\alpha$ as follows:

\begin{samepage}
	\begin{flalign}
	\label{eq:inequality_min}
	&\bar\alpha>\lfloor n\log_2k\rfloor\\
	\label{eq:inequality_max}
	&\bar\alpha<\lfloor n\log_2k\rfloor+2
	\end{flalign}
\end{samepage}

The validity of the first part (\ref{eq:inequality_min}), which specifies $\lfloor n\log_2k\rfloor+1$ as the lower limit for $\bar\alpha$, can be demonstrated in a fairly simple way: Our starting point is equation~\ref{eq:generalized_reachability}, which describes the relationship of successive vertices in $H_{C,k}$. Having a cycle, requires us to consider the first and the last vertex being one and the same $v_{n+1}=v_1$. Setting a smaller exponent $\bar\alpha=\lfloor n\log_2k\rfloor$ into equation~\ref{eq:generalized_reachability} results in the inequality $v_{n+1}>v_1$, which is in any case a true statement:
\begin{equation*}
\begin{array}{l}
k^nv_12^{-\lfloor n\log_2k\rfloor}\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)>v_1
\\[\medskipamount]
k^n\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)>2^{\lfloor\ n\log_2k\rfloor}
\\[\medskipamount]
\log_2\left(k^n\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)\right)>\lfloor n\log_2k\rfloor
\\[\medskipamount]
n\log_2k+\log_2\left(\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)\right)>\lfloor n\log_2k\rfloor
\end{array}
\end{equation*}

The validity of the second part (\ref{eq:inequality_max}) is not so trivial to prove. Analogous to the above-shown proof of the cylce-alpha's lower limit, we again refer to equation~\ref{eq:generalized_reachability} as our starting point and we need to show that $v_{n+1}$ is smaller than $v_1$ if $\alpha=\lfloor\ nlog_2k\rfloor+2$:
\begin{equation*}
\begin{array}{l}
k^nv_12^{-\left(\lfloor n\log_2k\rfloor+2\right)}\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)<v_1
\\[\medskipamount]
k^n\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)<2^{\left(\lfloor n\log_2k\rfloor+2\right)}
\end{array}
\end{equation*}
This leads to the following general condition for the validity of the cycle-alpha's upper limit:
\begin{equation}
\label{eq:condition_max}
n\log_2k-\lfloor n\log_2k\rfloor<2-\log_2\left(\prod_{i=1}^{n}\left(1+\frac{1}{kv_{i}}\right)\right)
\end{equation}

A product $\prod(1+a_n)$ with positive terms $a_n$ is convergent if the series $\sum a_n$ converges, see Knopp \cite[p.~220]{Ref_Knopp}. A similar statement provides Murphy \cite{Ref_Murphy}, who write the factors in the form $c_n=1+a_n$ and explains that if $\prod c_n$ is convergent then $c_n\rightarrow1$ and therefore if $\prod (1+a_n)$ is convergent then $a_n\rightarrow0$. Thus, to verify whether the product in condition~\ref{eq:condition_max} is converging towards a limiting value, it is sufficient to examine the following sum:
\begin{equation*}
\sum_{i=1}^{n}\frac{1}{kv_{i}}
\end{equation*}

The sum of reciprocal vertices depending only from $v_1$ is given in appendix~\ref{appx:sum_reciprocal_vertices}.

\section{Cycles and the product in the condition for alpha's upper limit}
Let us start with the following product equality, which will give us insights into the relationship between cycles and the product in the condition for alpha's upper limit. The variables $V_1,\ldots,V_m$ and $W_1,\ldots,W_n$ are all odd positive integers:
\begin{equation}
\label{eq:product_equality}
(V_1+1)\cdots(V_m+1)\cdot W_1\cdots W_n=V_1\cdots V_m\cdot(W_1+1)\cdots(W_n+1)
\end{equation}

Every natural odd number $V$ can be expressed in the form of $V=v\cdot2^{\alpha}-1$ whereby $v$ is an positive odd integer and $\alpha>0$ is any natural number. This allows us to perform the following substitution (we use $\alpha_V$ for denoting the divisions by two between nodes $v_i$ and $\alpha_W$ for divisions by two between nodes $w_i$):

\begin{equation}
\label{eq:product_equality_substitution}
\begin{array}{lll}
V_1&=v_22^{\alpha_{V,1}}-1&=kv_1\\
V_2&=v_32^{\alpha_{V,2}}-1&=kv_2\\
\vdots&\vdots&\vdots\\
V_{m-1}&=v_m2^{\alpha_{V,m-1}}-1&=kv_{m-1}\\
V_m&=v_12^{\alpha_{V,m}}-1&=kv_m
\end{array}\qquad
\begin{array}{lll}
W_1&=w_22^{\alpha_{W,1}}-1&=kw_1\\
W_2&=w_32^{\alpha_{W,2}}-1&=kw_2\\
\vdots&\vdots&\vdots\\
W_{n-1}&=w_n2^{\alpha_{W,n-1}}-1&=kw_{n-1}\\
W_n&=w_12^{\alpha_{W,n}}-1&=kw_n
\end{array}
\end{equation}

The substitution rotating from $v_2=(kv_1+1)\cdot2^{-\alpha_{V,1}}$ to $v_m=(kv_{m-1}+1)\cdot2^{-\alpha_{V,m-1}}$ and finally back to $v_1=(kv_m+1)\cdot2^{-\alpha_{V,m}}$ describes a cycle. The result of these substitutions into equation~\ref{eq:product_equality} is the following equality:
\begin{flalign*}
v_22^{\alpha_{V,1}}\cdots v_m2^{\alpha_{V,m-1}}v_12^{\alpha_{V,m}}\cdot W_1\cdots W_n&=V_1\cdots V_m\cdot w_22^{\alpha_{W,1}}\cdots w_n2^{\alpha_{W,n-1}}w_12^{\alpha_{W,n}}\\
v_22^{\alpha_{V,1}}\cdots v_m2^{\alpha_{V,m-1}}v_12^{\alpha_{V,m}}\cdot kw_1\cdots kw_n&=kv_1\cdots kv_m\cdot w_22^{\alpha_{W,1}}\cdots w_n2^{\alpha_{W,n-1}}w_12^{\alpha_{W,n}}
\end{flalign*}

The trivial case where $n=m$ and the sum of exponents are equal $\sum_{i=1}^{m}\alpha_{V,i}=\sum_{i=1}^{n}\alpha_{W,i}$ simplifies the product equality as follows:
\begin{flalign*}
(V_1+1)\cdots(V_n+1)\cdot W_1\cdots W_n&=V_1\cdots V_n\cdot(W_1+1)\cdots(W_n+1)\\
v_1\cdots v_n\cdot\cancel{2^{\alpha_{V,1}+\ldots+\alpha_{V,n}}}\cdot W_1\cdots W_n&=V_1\cdots V_m\cdot w_1\cdots w_n\cdot\cancel{2^{\alpha_{W,1}+\ldots+\alpha_{W,n}}}
\end{flalign*}
This equality becomes immediatly true if $V_1\cdots V_n=W_1\cdots W_n$ which is the less spectacular case. The more interesting case arises from setting $V_i=kv_i$ and $W_i=kw_i$ as given by substitution~\ref{eq:product_equality_substitution} wich turns the product equality into an always true statement as well:
\begin{flalign*}
v_1\cdots v_n\cdot W_1\cdots W_n&=V_1\cdots V_m\cdot w_1\cdots w_n\\
v_1\cdots v_n\cdot k^n\cdot w_1\cdots w_n&=k^n\cdot v_1\cdots v_n\cdot w_1\cdots w_n
\end{flalign*}

\begin{example}
The following exemplarly product equality fullfills equation~\ref{eq:product_equality}, whereby $V_1=65$, $V_2=165$, $V_3=415$ and $W_1=135$, $W_2=85$, $W_3=215$:
\[
(65+1)(165+1)(415+1)\cdot135\cdot85\cdot215=65\cdot165\cdot415\cdot(135+1)(85+1)(215+1)
\]
We perform the following substitutions:
\[
\arraycolsep=0.2em\begin{array}{ll}
V_1=65&=v_22^{\alpha_{V,1}}-1=33\cdot2^1-1=5v_1\\
V_2=165&=v_32^{\alpha_{V,2}}-1=83\cdot2^1-1=5v_2\\
V_3=415&=v_12^{\alpha_{V,3}}-1=13\cdot2^5-1=5v_3
\end{array}\hspace{1em}
\begin{array}{ll}
W_1=135&=w_22^{\alpha_{W,1}}-1=17\cdot2^3-1=5w_1\\
W_2=85&=w_32^{\alpha_{W,2}}-1=43\cdot2^1-1=5w_2\\
W_3=215&=w_12^{\alpha_{W,3}}-1=27\cdot2^3-1=5w_3
\end{array}
\]
The result of these substitutions is:
\[
33\cdot\cancel{2^1}\cdot83\cdot\cancel{2^1}\cdot13\cdot\cancel{2^5}\cdot135\cdot85\cdot215=65\cdot165\cdot415\cdot17\cdot\cancel{2^3}\cdot43\cdot\cancel{2^1}\cdot27\cdot\cancel{2^3}
\]
Since the sum of exponents $\alpha_{V,i}$ and $\alpha_{W,i}$ are equal, we can cancel out all powers of two and obtain:
\[
v_2v_3v_1W_1W_2W_3=33\cdot83\cdot13\cdot135\cdot85\cdot215=65\cdot165\cdot415\cdot17\cdot43\cdot27=V_1V_2V_3w_2w_3w_1
\]
This product equality becomes true $v_2v_3v_1\cdot k^3\cdot w_1w_2w_3=k^3\cdot v_1v_2v_3\cdot w_2w_3w_1$ when we set $V_i=kv_i$ and $W_i=kw_i$ (for $i=1,2,3$) which inevitably leads to the two corresponding cycles for $k=5$ that are already presented by table~\ref{table:known_cycles}.
\end{example}

\section{Existence of a solitary cycle for $k=1$}
As per theorem~\ref{theo:2}, for $k=1$, the only possible alpha for a cycle is $1$:
\[
\bar\alpha=\lfloor n\log_21\rfloor+1=1
\]
In accordance with the condition $\alpha\ge n$ stated by \ref{eq:n_alpha} it is clear that between two successive vertices at least one edge has been contracted or respectively one division by two took place. This is the reason why, if theorem~\ref{theo:2} is true, a cycle can only occur for $n=1$. Based on equation~\ref{eq:generalized_cycle} we can show that this is the case for the trivial cycle, starting at the root $v_1=1$:
\[
2^{\bar\alpha}=2^{\lfloor 1\log_21\rfloor+1}=2^1=\left(1+\frac{1}{v_1}\right)=\left(1+\frac{1}{1}\right)
\]
Since no other value of $v_1$ results in a natural number, no other cycle for $n=1$ is possible. In order to prove theorem~\ref{theo:2} for $k=1$, we now have to show that condition~\ref{eq:condition_max} is true.

\section{Verifying cycle-alpha's upper limit for the $1x+1$ variant of $H_C$}
\label{sec:alphas_upper_limit_k_1}
We prove that theorem~\ref{theo:2} is true for $k=1$ using the so-called Engel expansion, which we will explore more closely in appendix~\ref{sec:worstcase_k3}. Setting $b=2$ and $k=1$ into equation~\ref{eq:generalized_asc_continued_fraction} leads to the formula that calculates the node $v_{n+1}$ for a sequence, in which we divide by $2$ only once per iteration:
\begin{equation}
\label{eq:appx_1}
v_{n+1}=\frac{v_1+2^n-1}{2^n}
\end{equation}

\begin{example}
	Let us consider the sequence $v1=17$, $v_2=9$, $v_3=5$, $v_4=3$. Setting $v_1=17$ and $n=3$ results in:
	\[
	v_{3+1}=v_4=\frac{17+2^3-1}{2^3}=3
	\]
\end{example}

Equation~\ref{eq:appx_1} represents the (hypothetical) case in which a sequence progresses to the highest possible successive node for a specific starting node $v_1$. Actually, the sequence decreases in any case except $v_1=1$ and $n=1$. We can show that setting $v_1=1$ and $n=1$ results in the trivial cycle:
\[
v_1=1=v_2=\frac{1+2^1-1}{2^1}
\]

The equation above, complies to (and verifies) theorem~\ref{theo:2}, since $1=n=\alpha=\bar\alpha$:
\[
\bar\alpha=\lfloor n\log_21\rfloor+1=1
\]

The condition~\ref{eq:n_alpha}, namely the inequality $\alpha\ge n$, can be used to prove that no other $\alpha$ than $\bar\alpha$ leads to a cycle. To show this, we set $v_{n+1}=v_1$:
\[
v_1=\frac{v_1+2^n-1}{2^n}=\frac{v_1}{2^n}-\frac{1}{2^n}+1=\frac{v_1-1}{2^n}+1
\]

The above term is only true for $v_1=1$ and $n=\alpha=\bar\alpha=1$. Any higher value for $v_1$, $n$ or $\alpha$ leads to a result less than $v_1$. Therefore, a cycle is not possible for $\alpha\ne 1$ and theorem~\ref{theo:2} is true for $k=1$. A cycle can only occur for the case $v_1=1$ and $\alpha=\bar\alpha=n=1$. For any other case the following condition applies:
\[
v_1>\frac{v_1-1}{2^n}+1
\]

Knowing that theorem~\ref{theo:2} is true, we can revisit condition~\ref{eq:condition_max} determining the upper limit of $\bar\alpha$. We set $k=1$ into this condition and obtain:
\begin{equation}
n\log_21-\lfloor n\log_21\rfloor<2-\log_2\left(\prod_{i=1}^{n}\left(1+\frac{1}{1v_{i}}\right)\right)
\end{equation}

The above-given inequality gets simplified to a condition which is true and proves that the product in condition~\ref{eq:condition_max} is always less than four:
\[
4>\prod_{i=1}^{n}\left(1+\frac{1}{v_{i}}\right)
\]

%\par\medskip\noindent
%\textbf{Case 1 (\boldsymbol{$v_1=1$})}

%As per the inequality \ref{eq:n_alpha}, which states that $\alpha\ge n$ and thus $2\ge n$, we know that in this case of $k=1$ a cycle can have a maximum length of $2$. This is obviously correct.

%By setting $n=1$ in equation~\ref{eq:generalized_reachability}, we describe the relationship between two successive nodes in $H_{C,k}$ and we obtain:\\
%\begin{equation*}
%	v_2=\frac{kv_1+1}{2^a}
%\end{equation*}

%Let $v_1$ and $v_2$ be the same vertex defining a $1$-cycle (a loop). The equality $v_1=v_2$ requires the exponent $a$ to be bigger than $\lfloor\log_2k\rfloor*n$ (see equation~\ref{eq:inequality}). Otherwise $v_2$ will be bigger than $v_1$:\\

% Carmichael numbers, Mersenne Primes, Primes, mod 8

\section{Verifying cycle-alpha's upper limit for $H_{C,k>1}$}
%Let us now validate alpha's upper limit for all $kx+1$ variants of $H_C$ for $k=3$. For this we need to show that the condition~\ref{eq:condition_max} is true for $k>1$. To improve readability, we denote the factor $(1+\frac{1}{3v_i})$ with $\beta_i$:

In order to prove the upper limit of $\bar\alpha$ for $k=3$, we have to show that condition~\ref{eq:condition_max} is true. For better readability we denote the factor $(1+\frac{1}{3v_i})$ with $\beta_i$:
\begin{equation*}
	n\log_23-\lfloor n\log_23\rfloor<2-\log_2\prod_{i=1}^{n}\beta_i
\end{equation*}

Having a look at the above term makes clear that to prove the inequality, we have to show that the following condition is true:

\begin{equation}
\label{eq:condition_beta_lt_2}
	\prod_{i=1}^{n}\beta_i<2
\end{equation}

We formulate a proof for condition~\ref{eq:condition_beta_lt_2} based on theorem~\ref{theo:1}:

\begin{equation}
\label{eq:based_theo_1}
v_{n+1}=3^nv_1\prod_{i=1}^{n}\beta_i\prod_{i=1}^{n}2^{-\alpha_i}
\end{equation}

The variable $\beta_{n+1}$ can be calculated with the following equation:

\begin{equation}
\label{eq:beta_n_plus_1}
\beta_{n+1}=1+\frac{1}{3v_{n+1}}
\end{equation}

\begin{example}
	Setting $v_2=5$ and $n=1$ leads to:
	\[
	\beta_{1+1}=1+\frac{1}{3v_{1+1}}=1+\frac{1}{3\cdot5}=1.0\overline{6}
	\]
\end{example}

When we replace $v_{n+1}$ in equation~\ref{eq:beta_n_plus_1} with theorem~\ref{theo:1}, we obtain the following formula:

\begin{equation}
\label{eq:beta_n_plus_1_theo_1}
\beta_{n+1}=1+\frac{1}{3\cdot3^nv_1\prod_{i=1}^{n}\beta_i\prod_{i=1}^{n}2^{-\alpha_i}}=1+\frac{\prod_{i=1}^{n}2^{\alpha_i}}{3^{n+1}v_1\prod_{i=1}^{n}\beta_i}
\end{equation}

\begin{example}
Let us consider $v_1=13$ and $n=1$. In this case $\beta_{n+1}$ equals $1.0\overline{6}$:
\[
\beta_{1+1}=1+\frac{\prod_{i=1}^{1}2^{\alpha_i}}{3^{1+1}v_1\prod_{i=1}^{1}\beta_i}
\]
\[
\beta_{1+1}=1+\frac{2^3}{3^2\cdot13\cdot1.0256}=1+\frac{1}{3\cdot5}=1.0\overline{6}
\]
\end{example}

We now assume that the product $\prod_{i=1}^{n+1}\beta_i$ reaches the value $2$ in the next iteration, which would violate the inequality~\ref{eq:condition_beta_lt_2}:

\begin{equation}
\label{eq:assume_beta_eq_2}
2=\prod_{i=1}^{n+1}\beta_i=\beta_{n+1}\cdot\prod_{i=1}^{n}\beta_i
\end{equation}

Replacing $\beta_{n+1}$ in assumption~\ref{eq:assume_beta_eq_2} with equation~\ref{eq:beta_n_plus_1_theo_1} leads to:

\begin{equation}
\label{eq:prod_power_of_two}
\large\def\arraystretch{2.0}\begin{array}{l}
2=\left(1+\frac{\prod_{i=1}^{n}2^{\alpha_i}}{3^{n+1}v_1\prod_{i=1}^{n}\beta_i}\right)\cdot\prod_{i=1}^{n}\beta_i\\
2=\prod_{i=1}^{n}\beta_i+\frac{\prod_{i=1}^{n}2^{\alpha_i}}{3^{n+1}v_1}\\
2-\prod_{i=1}^{n}\beta_i=\frac{\prod_{i=1}^{n}2^{\alpha_i}}{3^{n+1}v_1}\\
3^{n+1}v_1\cdot\left(2-\prod_{i=1}^{n}\beta_i\right) =\prod_{i=1}^{n}2^{\alpha_i}\\
\prod_{i=1}^{n}2^{\alpha_i}=3^{n+1}v_1\left(2-\prod_{i=1}^{n}\beta_i\right)
\end{array}
\end{equation}

We finally insert equation~\ref{eq:prod_power_of_two} into equation~\ref{eq:based_theo_1} and we increment the vertex's index by one:
\begin{flalign*}
v_{n+2}&=3^{n+1}v_1\prod_{i=1}^{n+1}\beta_i\prod_{i=1}^{n+1}2^{-\alpha_i}\\
v_{n+2}&=3^{n+1}v_1\prod_{i=1}^{n+1}\beta_i\left(\prod_{i=1}^{n}2^{-\alpha_i}\right)2^{-\alpha_{n+1}}\\
v_{n+2}&=\frac{3^{n+1}v_1\prod_{i=1}^{n+1}\beta_i}{\left(\prod_{i=1}^{n}2^{\alpha_i}\right)2^{\alpha_{n+1}}}=\frac{3^{n+1}\cdot v_1\cdot2}{3^{n+1}v_1\left(2-\prod_{i=1}^{n}\beta_i\right)\cdot2^{\alpha_{n+1}}}\\
v_{n+2}&=\frac{2}{\left(2-\prod_{i=1}^{n}\beta_i\right)\cdot2^{\alpha_{n+1}}}
\end{flalign*}

Knowing that $1<\prod_{i=1}^{n}\beta_i<2$ and $2^{\alpha_{i+1}}\ge2$ leads to the following true statement:

\begin{equation}
\label{eq:inequality_v_n_plus_2}
v_{n+2}<1
\end{equation}

\par\bigskip
The statement~\ref{eq:inequality_v_n_plus_2} shows that $\prod_{i=1}^{n+1}\beta_i\ge2$ is impossible, since it would result in a final node $v_{n+2}<1$. We therefore have proven theorem~\ref{theo:2} for $k=3$ by contradiction. Having a look at the proof makes clear that it is not only valid for $k=3$ but for all $k>1$. It is also applicable for $k=1$, except for the case $v_1=1$. Here  $\beta_1$ equals $2$ immediately in the first iteration. This is the reason why we had to rely on another proof for $k=1$.


% !TEX root = math_subfile.tex

\chapter{Maths}

\section{Equations}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut,placerat ac, adipiscing vitae, felis.
\begin{equation}
    \sum_{k=1}^\infty \frac{1}{k^2} = \frac{\pi^2}{6}.
\end{equation}
Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpisegestas. Mauris ut leo.
\begin{align*}
    f(x) &= x(x-1)^2 \\
    &= x(x^2-2x+1) \\
    &= x^3-2x^2+x.
\end{align*}

\section{Theorems}

\begin{theorem}
    This is an important theorem.
\end{theorem}
\begin{proof}
    The proof is left as an exercise.
\end{proof}
You can also define a restatable theorem. Useful for restating the theorem when the proofs are in the appendices.
\begin{restatable}[Goldbach's conjecture]{theorem}{goldbach}
    \label{thm:goldbach}
    Every even integer greater than 2 can be expressed as the sum of two primes.
\end{restatable}
And then, we recall \cref{thm:goldbach}.
\goldbach*


\subsection{Determination of the band integral intensity}
\label{band_intensities}

One of the important spectroscopic information is the integral intensity of
particular Raman bands from the spectrum.
The band's shape is usually modeled by Gaussian or Lorentzian curves or as
their combination.
The combination of the Lorentzian $\func{L}$ and Gaussian $\func{G}$ curve can
be expressed as
\begin{equation}
	\func{S}(\wn; I_\text{m}, \mu, \sigma) =
		c_\text{L} \cdot \func{L}(\wn; I_\text{m}, \mu, \sigma)
		+ (1 - c_\text{L}) \cdot \func{G}(\wn; I_\text{m}, \mu, \sigma),
	\label{\eqnlabel{band_intensities:single_shape}}
\end{equation}
where $c_\text{L}$ is the Lorentzian curve fraction coefficient, $I_m$ is the
height, $\mu$ is the band position, $\sigma$ is the Gaussian root mean square
width, and $\wn$ is the wavenumber.
The Gaussian function is taken in the form of
\begin{equation*}
	\func{G}(\wn; I_\text{m}, \mu, \sigma) =
		I_\text{m} e^{-\frac{(\wn - \mu)^2}{2\sigma^2}}.
\end{equation*}

It is beneficial to select the parameters of the Lorentzian curve to match the
parameters of the Gaussian curve.
This matching is straightforward for the height $I_\text{m}$ and position
$\mu$ parameters but less evident for the width $\sigma$ parameter.
To give the proper meaning to the Lorentzian curve fraction coefficient
$c_\text{L}$, we decided to make the full width at half maximum (FWHM) between
the Gaussian and Lorentzian curve equal for the same $\sigma$.
Therefore we needed to calculate the FWHM of the Gaussian curve.
Let us assume, without loss of generality,
$I_\text{m} = 1$
and
$\mu = 0$,
and only the positive solution of the quadratic equation
\begin{align}
	\frac{1}{2} &= \func{G}(\wn; 1, 0, \sigma)
		= e^{-\frac{\wn^2}{2\sigma^2}}, \nonumber \\
	\func{ln}2  &= \frac{\wn^2}{2\sigma^2}, \nonumber \\
	\wn         &= \sigma\sqrt{2\ln2},
		\label{\eqnlabel{band_intensities:HWHM}}\\
	\func{FWHD}_\text{G}(\sigma)
	            &= 2\wn = 2\sigma\sqrt{2\ln2}. \nonumber
\end{align}

The matching width parameter of the Lorentzian curve can be calculated as
\begin{align*}
	\frac{1}{2} &= \frac{1}{1 + p\wn^2}, \\
	1 + p\wn^2  &= 2, \\
	\wn         &= \frac{1}{\sqrt{p}}.
\end{align*}
Then with the result from \eqnref{band_intensities:HWHM}, we get
\begin{align*}
	\sigma\sqrt{2\ln2}
	            &= \frac{1}{\sqrt{p}}, \\
  p           &= \frac{1}{2\sigma^2\ln2}.
\end{align*}
With this result, the final form of the Lorentzian curve is
\begin{equation*}
	\func{L}(\wn; I_\text{m}, \mu, \sigma) =
		\frac{I_m}{1 + \frac{(\wn - \mu)^2}{2\sigma^2\ln2}}.
\end{equation*}
This definition of the Lorentzian curve means that with the Lorentzian curve
fraction coefficient $c_\text{L} = 0.5$, the contributions to the FWHM of the
Lorentzian and the Gaussian curve to the combined band shape are equal.

The integral intensity of the band can be calculated as the sum of the
contributions of both bands.
It obviously does not depend on the position of the band $\mu$, so we can,
without loss of generality, set it to zero during further calculations
\begin{equation}
\func{I}(I_\text{m}, \sigma) =
	c_\text{L} \func{I}_\text{L}(I_\text{m}, \sigma)
	+ (1 - c_\text{L}) \func{I}_\text{G}(I_\text{m}, \sigma),
\end{equation}
where
\begin{align*}
	\func{I}_\text{G}(I_\text{m}; \sigma)
		&= I_\text{m}\int_{-\infty}^{\infty}
			{e^{-\frac{\wn^2}{2\sigma^2}}\text{d}\wn}
		= \begin{vmatrix}
			\wn = \sigma\sqrt{2}x \\
			\text{d}\wn = \sigma\sqrt{2}\text{d}x
		\end{vmatrix}
		= I_\text{m}\sigma\sqrt{2}\int_{-\infty}^{\infty}{e^{-x^2}\text{d}x} \\
		&= I_\text{m}\sigma\sqrt{2\text{\g{p}}}
\end{align*}
and
\begin{align*}
	\func{I}_\text{L}(I_\text{m}, \sigma)
		&= \int_{-\infty}^{\infty}
			{\frac{I_\text{m}}{1 + \frac{\wn^2}{2\sigma^2\ln2}}\text{d}\wn}
		= \begin{vmatrix}
			\wn = \sigma\sqrt{2ln2}x \\
			\text{d}\wn = \sigma\sqrt{2\ln2}\text{d}x
		\end{vmatrix}
		= I_\text{m}\sigma\sqrt{2\ln2}\int_{-\infty}^{\infty}
			{\frac{1}{1 + x^2}\text{d}x} \\
		&= I_\text{m}\sigma\text{\g{p}}\sqrt{2\ln2}.
\end{align*}

Raman bands in a typical Raman spectrum of complex samples are overlapped.
We solved this problem by modeling the band as a combination of more
band-shape functions from
\eqnref{band_intensities:single_shape}
\begin{equation}
	\func{S}(\wn; I_{\text{m},1..n}, \mu_{1..n}, \sigma_{1..n}) =
		\sum_{i = 1}^n = 	\func{S}_i(\wn; I_{\text{m},i}, \mu_i, \sigma_i),
	\label{\eqnlabel{band_intensities:shape}}
\end{equation}
where $n$ is the number of the overlapping bands.

This band shape was fitted to the measured spectra. The slightly enhanced
Marquardt-Levenberg method
(see \cref{minimization})
was used for the nonlinear regression, and analytical derivatives was used for
gradient computation.
\\


\chapter{Permutations}
\label{chapter:permutations}
Recall that a permutation is a bijection from $\range{n}$ to $\range{n}$. We
already discussed several properties of them. In this chapter we will discuss
some combinatorial properties of them. We denote by $\permutations{n}$ the set
of all permutations of $\range{n}$.\footnote{%
  Letter $S$ is used since in the group theory this set is called
  the symmetric group.
}
\nomenclature[S]{$\permutations{n}$}{denotes the set of all permutations of $\range{n}$}

The main operation over permutations is composition, for two permutations $p$
and $q$ we denote their composition $p \circ q$ by $pq$.\footnote{%
  Some authors denote $q \circ p$ by $pq$.
}
Note that this operation is not commutative; i.e. $p \circ q$ is not
necessarily equal to $q \circ p$.

Every permutation $p$ can be uniquely determined by the values $p(1)$, \dots,
$p(n)$, thus sometimes we denote the permutation $f$ by a sequence
$p(1) p(2) \dots p(n)$ (we call it \emph{one-line notation}).
For example, the permutation $3 1 2$ is equal to the function $p : \range{3} \to
\range{3}$
such that
\[
  p(x) =
  \begin{cases}
    3 & \text{if } x = 1 \\
    1 & \text{if } x = 2 \\
    2 & \text{if } x = 3
  \end{cases}.
\]

\section{Cycles}
Consider the permutation $p$ equal to $2 3 1 5 4$ and draw a diagram with
$5$ points where we draw an arrow from $i$ to $j$ iff $p(i) = j$.
\begin{center}
  \begin{tikzpicture}[thick]%
    \node[circle, draw, minimum width=4pt]
      (p1) at (0, 0) {1};
    \node[circle, draw, minimum width=4pt]
      (p2) at (-1, 1.4) {2};
    \node[circle, draw, minimum width=4pt]
      (p3) at (1, 1.4) {3};
    \node[circle, draw, minimum width=4pt]
      (p4) at (4, 0) {4};
    \node[circle, draw, minimum width=4pt]
      (p5) at (4, 1.4) {5};
    \draw[->] (p1) -- (p2);
    \draw[->] (p2) -- (p3);
    \draw[->] (p3) -- (p1);

    \draw[->] (p4) to[out=45, in=-45] (p5);
    \draw[->] (p5) to[out=-135, in=135] (p4);
  \end{tikzpicture}
\end{center}
It is easy to see that there are two ``cycles'' in the diagram. In this section
we prove that this is not a coincidence and we also study some properties of
permutations with respect to the structure of these cycles.

\begin{definition}
  Let $p$ be a permutation of $\range{n}$, $x \in \range{n}$, and $i$ be the smallest
  integer such that
  $p^i(x) = \underbrace{p(p(\dots p(}_{i \text{ times}} x) \dots )) = x$.
  The we say that the entries $x$, $p(x)$, \dots, $p^{i - 1}(x)$ form an
  $i$-cycle in $p$.

  We denote a permutation $q : \range{n} \to \range{n}$ consisting of one cycle
  $a_1$, \dots, $a_k$ by $(a_1, \dots, a_k)$; i.e.
  \[
    q(x) =
    \begin{cases}
      a_2 & \text{if } x = a_1 \\
      a_3 & \text{if } x = a_2 \\
      \dots \\
      a_1 & \text{if } x = a_k \\
      x & \text{otherwise}
    \end{cases}.
  \]
\end{definition}

\begin{theorem}
\label{theorem:permuations-into-cycles}
  All permutations can be decomposed into the disjoint unions of their cycles.
\end{theorem}
\begin{exercise}
  Prove Theorem~\ref{theorem:permuations-into-cycles}.
\end{exercise}
For example, the discussed permutation $2 3 1 5 4$ can be decomposed into
$(1, 2, 3) (4, 5)$.

If an permutation $p : \range{n} \to \range{n}$ has $c_i$ cycles of length $i \in \range{n}$, then
we say that $(c_1, c_2, \dots, c_n)$ is the \emph{cycle type} of $p$.
The simplest question we may ask is ``how many permutations of a certain cyclic
type exist?'', the following theorem gives an answer for this question.
\begin{theorem}
  Let $c_1$, \dots, $c_n$ be some positive integers such that
  $\sum_{i = 1}^n i c_i = n$. Then there are
  $\frac{n!}{c_1! c_2! \dots c_n! 1^{c_1} 2^{c_2} \dots n^{c_n}}$
  permutation of the cyclic type $(c_1, \dots, c_n)$.
\end{theorem}

Note that this result allows us to answer the following problem. King Arthur has
$n$ Knights of the Round Table; Arthur wonders: how many ways to seat in the
round table? In other words he is asking how many permutations of the cyclic
type $(0, 0, \dots, 0, 1)$. Hence, the answer for Arthur's question is $n!$
(note that we also need to give a seat to the king).

\section{Stirling Numbers of The First Kind}
In the previous chapter we defined Stirling numbers of the second kind; in this
section we define their first kind counterpart.

\begin{definition}
  Let $n > k$ be some integers. We denote the number of permutations of
  $\range{n}$ with $k$ cycles by $c(n, k)$. The number $s(n, k) = (-1)^{n - k}
  c(n, k)$ is called a \emph{Stirling number of the first kind}.
\end{definition}
The multiplier $(-1)^{n - k}$ seems a bit strange, but we will explain it
in Theorem~\ref{theorem:connection-between-stirling-numbers}.

Like the numbers $S(n, k)$, the numbers $c(n, k)$ satisfy a simple recurrent
formula.
\begin{theorem}
\label{theorem:stirling-numbers-first-kind-reccurent-relation}
  Let $n \ge k$ be positive integers. Then
  \[
    c(n, k) = c(n - 1, k - 1) + (n - 1) c(n - 1, k).
  \]
\end{theorem}

\begin{exercise}
  Prove Theorem~\ref{theorem:stirling-numbers-first-kind-reccurent-relation}.
\end{exercise}

\begin{theorem}
\label{theorem:connection-between-stirling-numbers}
  For any real $x$ and positive integer $n$,
  \[
    \numberOfPermutations[n]{x} = \sum_{k = 0}^n s(n, k) x^k.
  \]
\end{theorem}
Now one may see why the multiplier $(-1)^{n - k}$ was necessary by comparing
this equality with the equality from
Theorem~\ref{theorem:stirling-numbers-and-polynomials} stating that
\[
  x^n = \sum_{k = 0}^n S(n, k) \numberOfPermutations[k]{x}.
\]
In other words, Stirling numbers of the second kind are ``inverse'' to the
Stirling numbers of the first kind.

We can interpret this result in terms of linear algebra. Consider the vector
space $\mathbb{P}_n$ of real polynomials of degree at most $n$. It is well
known that $1$, $x$, \dots, $x^n$ is the basis of this space; additionally,
it is easy to see that $1$, $\numberOfPermutations[1]{x}$, \dots,
$\numberOfPermutations[n]{x}$ is also a basis. Then
the matrices $M^{(S)}$ and $M^{(s)}$ such that
$M^{(S)}_{i, j} = S(i, j)$ and $M^{(s)}_{i, j} = s(i, j)$ are
change of basis matrices between these two bases.

\section{Permutations with Restricted Cycle Structure}
One of the problem of the representation of a permutation as a collection of
cycles is that it is not unique; e.g. $(1, 2, 3) (4, 5)$ and $(5, 4) (1, 2, 3)$
represent the same permutation. To avoid this we introduce a \emph{canonical
cycle form}, That is, each cycle will be written with its largest element first,
and the cycles will be written in increasing order of their first elements. Thus
the permutation's $2 3 1 5 4$ canonical cycle form is $(3, 1, 2) (5, 4)$.

Using this notation and the next lemma we can discover several nice properties
of permutations.
\begin{lemma}
\label{lemma:permuations-transfomration}
  Let $p : \range{n} \to \range{n}$ be a permutation written in canonical cycle notation.
  Let $\fpm(p)$ be the permutation obtained from $p$ by omitting the
  parentheses and reading the entries as a permutation in the one-line notation.
  Then $\fpm$ is a bijection from $\permutations{n}$ to $\permutations{n}$.
\end{lemma}
For example, $\fpm(2 3 1 5 4) = 31254$ and
$\fpm^{-1}(2 3 1 5 4) = (2) (3, 1) (5, 4) = 32154$.

Using this transformation we may prove the following result, which is very
technical without this transformation.
\begin{theorem}
  Let $n$ be a positive integer and $x_1, \dots, x_k \in \range{n}$ be $k$ different
  numbers. There are $n! / k$ permutations of $\range{n}$ such that $x_1$, \dots,
  $x_k$ are in the same cycle.
\end{theorem}
\begin{proof}
  Without loss of generality, $x_1 = n$.

  Let $q = q_1 q_2 \dots q_n$ be a permutation of $n$, and let $\fpm(p) = q$,
  where $\fpm$ is the bijection from
  Lemma~\ref{lemma:permuations-transfomration}.
  Note that the last cycle of $p$ starts with $x_1 = n$, and the entries in that
  cycle of $q$ are precisely the entries on the right of $n$ in $q$. Therefore,
  $p$ contains $x_1$, \dots, $x_k$ in the same cycle if and only if $x_2$,
  \dots, $x_k$ are on the right of $n$ in $q$. It is easy to see that
  there are $\binom{n}{k} (k - 1)! (n - k)! = \frac{n!}{k}$ such permutations
  $q$.
\end{proof}

Another nice result states that for any $i \in \range{n}$, the probability that
$i$ is in a cycle of length $k$ does not depend on $k$ and is equal to $1 / n$.
\begin{theorem}
  Let $i \in \range{n}$. Then for all $k \in \range{n}$, there are exactly $(n - 1)!$
  permutations of $\range{n}$ in which the cycle containing $i$ is of length $k$.
\end{theorem}
\begin{proof}
  Again, it is sufficient to prove the statement for $i = n$. Let
  $q = q_1 q_2 \dots q_n$ be a permutation of $n$, let $\fpm(p) = q$, where
  $\fpm$ is the bijection from Lemma~\ref{lemma:permuations-transfomration},
  and let  $q_j = n$. Then the cycle $C$ containing $n$ in $p$ is of length
  $n - j + 1$ as $n$ itself starts the last cycle. So if we want $C$ to have
  length $k$, we must have $j = n + 1 - k$. However, there are clearly
  $(n - 1)!$ permutations of length $n$ that contain $n$ in a given position,
  and the proof follows.
\end{proof}

\section{Superpermutations}
In this section we consider the following problem. In the TV series ``The
Melancholy of Haruhi Suzumiya'' there are $14$ episodes. The episodes feature
time travel and are chronologically challenging for the viewer. Moreover,
they were originally aired in a nonlinear order. When the series went to DVD,
the episodes were rearranged. Thus, it is something of an obsession for fans to
rewatch the series over and over again, going through in many different
chronologies. So the question is as follows: if you want to watch all the
episodes of the anime in every possible order, what is the shortest sequence of
episodes you need to watch?

Let us first formulate a more formal question.
\begin{definition}
  A sequence $w_1, \dots, w_\ell \in \range{n}$ is called an $n$-superpermutation iff
  for any $p \in \permutations{n}$ there is $0 \le i \le \ell - n$ such that
  $w_{i + 1} = p(1)$, $w_{i + 2} = p(2)$, \dots, and $w_{i + n} = p(n)$.
\end{definition}
In other words, the question we wish to study can be formulated in the
following way: what is the minimal length of a $14$-superpermutation?

As usual, we would like to study a more complicated question, what is the
minimal length of an $n$-superpermutation. The answer for this question is
unknown; however, there are relatively tight known upper and lower bounds. The
known upper bound was proven by Greg Egan in 2008.
\begin{theorem}
  For all $n \ge 4$, there is an $n$-superpermutation of length at most
  \[
    n! + (n - 1)! + (n - 2)! + (n - 3)! + n - 3.
  \]
\end{theorem}

However, the problem became especially famous because the best known lower bound
was proven by an anonymous author on 4chan. The anonymous proved the following
theorem.
\marginurl{%
  The Verge: \\\noindent
  An anonymous 4chan post could help solve a 25-year-old math mystery
}{bit.ly/2Gj8kpT}
\begin{theorem}
  Every $n$-superpermutation has length at least
  \[
    n! + (n - 1)! + (n - 2)! + n - 3.
  \]
\end{theorem}
\begin{proof}
  First we need to define the notion of length between two permutations
  $p, q \in \permutations{n}$. We say that the distance between $p$ and $q$ is equal to
  $\mathcal{D} = k$
  iff there is a word $u$ of length $k$ such that the last $n$ letters of the
  concatenation of  $w = p(1) p(2) \dots p(n)$ and $u$ encodes the permutation
  $q$ but any the last $n$ symbols of the concatenation of $w$ and any proper
  prefix of $u$ is not a permutation; otherwise, we say that the distance is
  equal to $+\infty$.

  Note that $n + \mathcal{D}(p_1, \dots, p_\ell) =
  \sum_{i = 1}^{\ell - 1} \mathcal{D}(p_i, p_{i + 1}) \le m$, where
  \begin{gather*}
    w_1, w_2, \dots, w_m \in \range{n} \\
    \text{and} \\
    \set{i_1 < i_2 < \dots < i_\ell} =
    \set[{
      w_{i + 1} = p(1), \dots, w_{i + n} = p(n)
    }]{
      i \in \range{m - n}
    }.
  \end{gather*}
  In other words, to find the minimal $n$-superpermutation, we need to find
  a sequence of permutations $p_1, \dots, p_\ell$ containing all the permutations
  and with the minimal $\mathcal{D}$.

  Instead of proving the statement right away, we prove four lower bounds, each
  stronger but more complicated than the previous one.

  \begin{itemize}
    \item ($n! + n - 1$) We prove that
      \begin{equation}
        \label{equation:inequality-1}
        \mathcal{D}(p_1, \dots, p_k) \ge
        C_0(p_1, \dots, p_k) - 1,
      \end{equation}
      where $C_0(p_1, \dots, p_k)$ is equal to
      the number of permutations occurring in $p_1, \dots, p_k$.

      It is easy to see that $C_0(p_1) = 1$ and $\mathcal{D}(p_1) = 0$ so
      $\mathcal{D}(p_1) = 0 \ge 1 - 1 = C_0(p_1) - 1$. We may also
      note that for any $p_{k + 1} \in \permutations{n}$,
      $C_0(p_1, \dots, p_{k + 1}) \le C_0(p_1, \dots, p_k) + 1$ and
      $\mathcal{D}(p_k, p_{k + 1}) \ge 1$. Therefore
      \begin{multline*}
        \mathcal{D}(p_1, \dots, p_{k + 1}) \ge
        \mathcal{D}(p_1, \dots, p_k) + 1 \ge \\
        C_0(p_1, \dots, p_k) + 1 - 1 \ge
        C_0(p_1, \dots, p_{k + 1}) - 1.
      \end{multline*}

      Combining (\ref{equation:inequality-1}) with the fact that if all the
      permutations occur in the sequence $p_1, \dots, p_\ell$, then
      $C_0(p_1, \dots, p_\ell) = n!$,
      we prove that any $n$-superpermutation has length at least $n! - 1 + n$.
    \item ($n! + (n - 1)! + (n - 2)$)
      To prove this lower bound we need to introduce the notion of a $1$-cycle
      class. A $1$-cycle class of permutations of $\range{n}$ is a
      subset $\set{p_1, \dots, p_n} \subseteq \permutations{n}$ such that $p_{k + 1}(n) =
      p_k(1)$, and $p_{k + 1}(i) = p_k(i + 1)$ for $i \in \range{n - 1}$. For
      example,
      \[
        \set{12345, 23451, 34512, 45123, 51234}
      \]
      is a $1$-cycle class.

      Let us now prove that
      \begin{equation}
        \label{equation:inequality-2}
        \mathcal{D}(p_1, \dots, p_k) \ge
        C_0(p_1, \dots, p_k) + C_1(p_1, \dots, p_k) - 1,
      \end{equation}
      where $C_1(p_1, \dots, p_k)$ is equal to the number of complete $1$-cycle
      classes in $p_1$, \dots, $p_{k - 1}$ (a $1$-cycle class
      $\set{q_1, \dots, q_n}$ is complete in $p_1$, \dots, $p_t$ iff
      $\set{q_1, \dots, q_n} \subseteq \set{p_1, \dots, p_t}$).

      It is easy to see that $C_0(p_1) = 1$, $C_1(p_1) = 0$ and
      $\mathcal{D}(p_1) = 0$ so
      $\mathcal{D}(p_1) = 0 \ge 1 + 0 - 1 = C_0(p_1) + C_1(p_1) - 1$.

      It is easy to see that for any $p_{k + 1} \in \permutations{n}$,
      \begin{gather*}
        C_0(p_1, \dots, p_{k + 1}) \le C_0(p_1, \dots, p_k) + 1  \\
        C_1(p_1, \dots, p_{k + 1}) \le C_1(p_1, \dots, p_k) + 1.
      \end{gather*}
      Hence, if $\mathcal{D}(p_k, p_{k + 1}) \ge 2$, then
      (\ref{equation:inequality-2}) is true.

      If $\mathcal{D}(p_k, p_{k + 1}) = 1$, we claim that only one of $C_0$ and
      $C_1$ increased. Note that $p_k$ and $p_{k + 1}$ are in the same $1$-
      cycle class. Therefore
      \begin{enumerate}
        \item either this cycle is not complete yet and
          \[
            C_1(p_1, \dots, p_{k + 1}) = C_1(p_1, \dots, p_k),
          \]
        \item or we finished the cycle and
          \[
            C_0(p_1, \dots, p_{k + 1}) = C_0(p_1, \dots, p_k).
          \]
      \end{enumerate}
      As a result, (\ref{equation:inequality-2}) is true.

      Combining (\ref{equation:inequality-2}) with the
      fact that if all the
      permutations occur in the sequence $p_1, \dots, p_\ell$, then
      $C_0(p_1, \dots, p_\ell) = n!$ and $C_1(p_1, \dots, p_\ell) \ge
      (n - 1)! - 1$,
      we prove that any $n$-superpermutation has length at least
      $n! + (n - 1)! - 1 - 1 + n$.
    \item ($n! + (n - 1)! + (n - 2)! + (n - 3)$)
      To prove the final lower bound we need to define $2$-cycles. The $2$-cycle
      generated by $p$ is the sequence $p_1, \dots, p_{n(n - 1)}$ such that
      $p_1 = p$, $\mathcal{D}(p_{in + j}, p_{in + j + 1}) = 1$ for $i \ge 0$
      and $n \ge j \ge 1$, and $\mathcal{D}(p_{in}, p_{in + 1}) = 2$ for
      $i \ge 1$ (note that the cycle is unique). For example,
      $12345$, $23451$, $34512$, $45123$, $51234$, $23415$, $34152$, $41523$,
      $15234$, $52341$, $34125$, $41253$, $12534$, $25341$, $53412$, $41235$,
      $12354$, $23541$, $35412$, $54123$ is a $2$-cycle generated by $12345$,
      it is also generated by $23415$, $34125$, and $41235$. More generally, we
      have the following result. If a $2$-cycle is generated by $p$, then it is
      generated by all $n - 1$ permutations obtained by fixing the
      last entry of $p$ and cyclically permuting the other entries; i.e., by
      $p$ and the permutations
      \begin{align*}
        &p(2) \dots p(n - 1) p(1)p(n), \\
        &p(3) \dots p(n - 1) p(1) p(2) p(n), \\
        &\dots, \\
        &p(n - 1) p(1) \dots p(n - 2) p(n).
      \end{align*}
      We say that a sequence $p_1$, \dots, $p_k$ enters the $2$-cycle generated
      by $p$ if $p_{i + 1} = p$ and $\mathcal{D}(p_i, p_{i + 1}) \ge 2$.
      Because each $2$-cycle contains only $n (n - 1)$ permutations, any
      sequence containing all the permutations must enter at least $(n - 2)!$
      different $2$-cycles.

      Let us now prove that
      \begin{multline}
        \label{equation:inequality-3}
        \mathcal{D}(p_1, \dots, p_k) \ge \\
        C_0(p_1, \dots, p_k) + C_1(p_1, \dots, p_k) + C_2(p_1, \dots, p_k) - 2,
      \end{multline}
      where $C_2(p_1, \dots, p_k)$ is equal to the number of entered $2$-cycles.

      It is easy to see that $C_0(p_1) = 1$, $C_1(p_1) = 0$, $C_2(p_1) = 1$, and
      $\mathcal{D}(p_1) = 0$ so
      $\mathcal{D}(p_1) = 0 \ge 1 + 0 + 1 - 2 =
      C_0(p_1) + C_1(p_1) + C_2(p_1)- 2$.

      It is easy to see that for any $p_{k + 1} \in \permutations{n}$,
      \begin{gather*}
        C_0(p_1, \dots, p_{k + 1}) \le C_0(p_1, \dots, p_k) + 1  \\
        C_1(p_1, \dots, p_{k + 1}) \le C_1(p_1, \dots, p_k) + 1 \\
        C_2(p_1, \dots, p_{k + 1}) \le C_2(p_1, \dots, p_k) + 1.
      \end{gather*}
      Hence, if $\mathcal{D}(p_k, p_{k + 1}) \ge 3$, then
      (\ref{equation:inequality-3}) is true.

      If $k = 1$, then we are still
      inside the last $2$-cycle and inside the last $1$-cycle class, therefore
      like in the previous case (\ref{equation:inequality-3}) is true.

      If $k = 2$, then we claim that if the value of $C_1$ increases, then
      the value of $C_2$ cannot change. Suppose that the value of $C_1$
      increases. This means that the permutation $p_k$ complete the $1$-cycle
      class and we have not visited it before. Since we
      completed the $1$-cycle class, we visited the permutation
      $q = p_k(2) p_k(3) \dots p_k(n) p_k(1)$ by $2$-step.
      It is also possible to note that $q$ and
      $p_{k + 1}$ generate the same cyclic class and it
      implies that $C_2(p_1, \dots, p_{k + 1}) = C_2(p_1, \dots, p_k)$.
      As a result, (\ref{equation:inequality-3}) is true.

      Combining (\ref{equation:inequality-2}) with the
      fact that if all the
      permutations occur in the sequence $p_1, \dots, p_\ell$, then
      $C_0(p_1, \dots, p_\ell) = n!$, $C_1(p_1, \dots, p_\ell) \ge
      (n - 1)! - 1$, and $C_2(p_1, \dots, p_\ell) \ge (n - 2)!$,
      we prove that any $n$-superpermutation has length at least
      $n! + (n - 1)! - 1 + (n - 2)! - 2 + n$.
  \end{itemize}
\end{proof}

Using this inequality we may conclude that real fans of
``The Melancholy of Haruhi Suzumiya'' need to watch at least $93884313611$
episodes which takes around $3572462$ years.

\begin{chapterendexercises}
  \exercise[recommended] Recall that the number of inverses in a permutation
    $p \in \permutations{n}$ is the number of pairs $i, j$ such that $i < j$ and
    $p(i) > p(j)$. Let $I(n, k)$ denotes the number of permutations with $k$
    inversions. Prove that $I(n, k) = I(n, \binom{n}{2} - k)$.
  \exercise Let $n$, $b_1$, \dots, and $b_k$ be positive integers such that
    $b_1 + \dots + b_k \le n$. Show that $b_1! b_2! \dots b_n! \le n!$.
  \exercise[recommended] Find an explicit formula for $c(n, n - 2)$.
    \begin{solution}
      The solution of this problem is similar to the solution of the problem for
      $S(n, n - 2)$.

      Note that there are two types of permutations with $n - 2$ cycles.
      \begin{enumerate}
        \item The first type consists of permutations with one cycle of length
          $3$ and $n - 3$ cycles of length $1$. Note that there are $\binom{n}{3}$
          ways to choose elements of the cycle of length $3$ and there are $2$
          ways to form a cycle from these elements. Hence, there are $2 \cdot
          \binom{n}{3}$ permutations of this type.
        \item The second type consists of permutations with two cycles of length $2$
          and $n - 4$ cycles of length $1$. Note that there are $\binom{n}{2}$
          ways to select elements of the first cycle and $\binom{n - 2}{2}$ ways
          to select the second cycle. Hence, there are $\frac{\binom{n}{2} \cdot
          \binom{n - 2}{2}}{2}$ permutations of this type (we divide by $2$ since
          we may reorder the cycles).
      \end{enumerate}

      As a result, the final answer is $2 \cdot \binom{n}{3} + \frac{\binom{n}{2}
      \cdot \binom{n - 2}{2}}{2}$.
    \end{solution}
  \exercise Prove that for any fixed $k$, the function $c(n, n - k)$ is a
    polynomial function of $n$. Find the degree of that polynomial.
  \exercise Find a reccurent relation for the number of permutations $\pi \in
    \permutations{n}$ such that $\pi^3(x) = x$ for all $x \in \range{n}$.
  \exercise Let $p$ be a permutation of $\range{n}$. We associate a permutation matrix
    $M^{(p)}$ to $p$ as follows. Let $M^{(p)}_{i, j} = 1$ if $p(i) = j$, and let
    $M^{(p)}_{i, j} = 0$ otherwise. Prove that $|\det M^{(p)}| = 1$.
  \exercise Prove that if $p$ and $q$ are two permutations, then
    $M^{(p)} M^{(q)} = M^{(pq)}$.
  \exercise Let $p$ be a permutation of the cyclic type $(c_1, \dots, c_n)$.
    Show that $p^\ell = 1 2 3 \dots n$, where
    \[
      \ell = \prod_{i ~:~ c_i \neq 0} i.
    \]
    \begin{solution}
      First we prove the following statement, if $p \in \permutations{n}$ is a cycle of
      length $\ell$, then $p^\ell = 12 \dots n$. Indeed, assume $p = (i_0,
      \dots, i_{\ell - 1})$;note that $p(i_j) = i_{(j + 1) \mod \ell}$,
      therefore, $p^\ell(i_j) = i_{(j + \ell) \mod \ell} = i_j$. It is also
      clear that if $p$ is a cycle of length $\ell$, then $p^{d\ell} =
      12 \dots n$ for any $d \in \N$.

      Another part of the argument is the following let $p$ and $q$ be two
      disjoint cycles, then $pq = qp$ (this can be easily derived from the
      definition of the composition).

      As a result, if a permutation $p = q_1 q_2 \dots q_k$, where $q_i$s are
      disjoint cycles, then $p^\ell = q^\ell_1 q^\ell_2 \dots q^\ell_k$. Hence,
      if $\ell = \prod_{i ~:~ c_i \neq 0} i$, $p^\ell = 1 2 \dots n$.
    \end{solution}
  \exercise Show that any permutation can be obtained as a product of some
    transpositions; i.e., cycles of length $2$.
    \begin{solution}
      It is easy to see that it is enough to prove the statement for the cycles.
      Consider a permuatation $(i_1, \dots, i_k)$. It is clear that $(i_1, i_2)
      (i_2, i_3)$ is equal to $(i_1, i_2, i_3)$ and moreover $(i_1, i_2) (i_2,
      i_3) \dots (i_{k - 1}, i_k)$ is equal to $(i_1, \dots, i_k)$. Therefore we
      proved the statement.
    \end{solution}
  \exercise Show that any permuation from $\permutations{n}$ can be expressed as
    a product of $(1, 2)$, \dots, $(n - 1, n)$ (each permuation can be used
    multiple times).
  \exercise Show that for any $n \in \N$, there are two permuations $p, q \in
    \permutations{n}$ such that any permuation from $\permutations{n}$ can be expressed as
    their product (each permuation can be used multiple times).
    \begin{solution}
      First, let us note that any permuation can be obtained as a product of the
      permuations $(1, 2)$, \dots, $(n - 1, n)$. It is enough to prove that any
      permutation $(i ,j)$ ($i < j$) can be obtained from them. Note that
      $(i + 1, j) \dots (j - 2, j)(j - 1, j)(i, i + 1) \dots (j - 1, j) =
        (i, j)$.

      So to prove the statement we need to came up with two permutations such
      that we can obtain $(i, i + 1)$ as their product for any $i \in [n - 1]$.
      Consider $(1, 2)$ and $(1, 2, \dots, n)$. Note that $(1, 2, \dots, n)^n =
      1 2 \dots n$. Hence, $(1, 2, \dots, n)^{n - 1} = (1, 2, \dots, n)^{-1}$.
      It is also easy to see that
      $(i, i + 1) = (1, 2, \dots, n)^{-i} (1, 2) (1, 2, \dots, n)^i$.
    \end{solution}
  \exercise[recommended] Prove that permutations $p$ and $p^{-1}$ are of the
    same cycle type for any permutation $p$.
  \exercise[recommended] A permutation $p$ is called a nontrivial involution if
    $p^2 = 1 2 \dots n$, but $p \neq 1 2 \dots n$. Prove that if $n > 1$, the
    number of nontrivial involutions in $\permutations{n}$ is odd.
    \begin{solution}
      Let $p \in \permutations{n}$ and $p^2 \neq \identity{\range{n}}$; it is easy to see
      that $(p^{-1})^2 \neq \identity{\range{n}}$. Therefore it is possible to
      split all the permutations from the set
      $\set[p^2 \neq \identity{\range{n}}]{p \in \permutations{n}}$ into pairs $p$ and
      $p^{-1}$. Hence, the size of the set
      $\set[p^2 \neq \identity{\range{n}}]{p \in \permutations{n}}$ is even; we
      may also note that the size of $\permutations{n}$ is also even. As a
      result, the size of $\set[p^2 = I]{p \in \permutations{n}}$ is even as well, but it
      implies that $\set[{p^2 = I \text{ and } p \neq I}]{p \in
      \permutations{n}}$ is odd.
    \end{solution}
  \exercise There are $n$ seats in a bus; $n - 1$ people are assigned seats in
    this bus. However, a dog came to the bus and took one of the seats uniformly
    at random. So each next passenger either takes his or her seat if it is
    available, or a uniformly random available seat otherwise. What is the
    probability that the last passenger seats on the assigned seat?
\end{chapterendexercises}