\documentclass{article}

\usepackage{fullpage}
\usepackage{amsmath,amssymb}

\setlength{\parindent}{0pt}

\begin{document}

\section*{The Birthday Problem}

\textsc{Q: What is the probability that, in a group of $n$ people, at least 2 have the same birthday?}\\[1em]
Let us represent the days of the year by the integers 1, 2, \ldots, 365. Then we choose our sample space $\textsl{S}$ to be \{all possible combinations of $n$ birthdays\}. That is, we include all possible combinations of $n$ days, with repetition (up to $n$ repetitions of the same day, where all $n$ birthdays fall on the same day).\\[1ex]
For example, if $n=3$, we include:
\begin{itemize}
\item all the single days of the year (eg. (1, 1, 1), (2, 2, 2), (3, 3, 3), \ldots), in the case that all 3 birthdays fall on the same day,
\item all combinations of 2 different days of the year (eg. (1, 1, 2), (1, 1, 3), (1, 1, 4), \ldots), in the case that 2 of the birthdays fall on the same day, and
\item all combinations of 3 different days of the year (eg. (1, 2, 3), (1, 2, 4), (1, 2, 5), \ldots), in the case that all 3 birthdays fall on different days
\end{itemize}
Suppose that all birthdays are equally likely. Then, by the classical definition of probability,
\begin{equation*}
\boxed{
P(\{\text{at least 2 people share a birthday}\})=\dfrac{|\{\text{at least 2\ldots}\}|}{|\textsl{S}|}
}
\end{equation*}
We know from counting principles that
\begin{align*}
|\textsl{S}|& =\text{\# of ways to select the first birthday $\times$ \# of ways to select the second birthday}\\
& \quad\times\ldots\times\text{\# of ways to select the $n$th birthday}\\
& =365\times 365\times\ldots\times 365\\
& =365^n
\end{align*}
and that
\begin{align*}
|\{\text{at least 2\ldots}\}|& =\text{\# of arrangements of $n$ birthdays where 2 people share a birthday}\\
& \quad+\text{\# of arrangements of $n$ birthdays where 3 people share a birthday}\\
& \quad+\ldots+\text{\# of arrangements of $n$ birthdays where $n$ people share a birthday}
\end{align*}
So
\begin{equation*}
\boxed{
P(\{\text{at least 2 people share a birthday}\})=\dfrac{|\{\text{2 people share a birthday}\}|+\ldots+|\{\text{$n$ people share a birthday}\}|}{365^n}
}
\end{equation*}
Then we consider that
\begin{align*}
\text{\# of arrangements of $n$ birthdays}& \\
\text{where $r$ people share a birthday}& =\text{\# of ways to select the first unshared birthday}\\
& \quad\times\text{\# of ways to select the second unshared birthday}\\
& \quad\times\ldots\times\text{\# of ways to select the $(n-r)$th unshared birthday}\\
& \quad\times \text{\# of ways to select the shared birthday}\\
& \quad\times \text{\# of ways to arrange $n-r$ different birthdays and $r$ same birthdays}\\
& =365\times 364\times\ldots\times(365-(n-r-1))\times(365-(n-r))\times \dfrac{n!}{r!1!\ldots 1!}
\end{align*}
For example, if $n=3$,
\begin{align*}
\text{\# of arr. where 2 people share a birthday}& =\text{\# of ways to select the unshared birthday}\\
& \quad\times \text{\# of ways to select the shared birthday}\\
& \quad\times\text{\# of ways to arrange 1 unique birthday and 2 same birthdays}\\
& =365\times 364\times \frac{3!}{2!1!}\\
& =398\,580
\end{align*}
and then
\begin{align*}
P(\{\text{at least 2 people share a birthday}\})&=\dfrac{|\{\text{2 people share a birthday}\}|+|\{\text{3 people share a birthday}\}|}{365^3}\\
& =\dfrac{398\,580+365}{365^3}\\
& =\dfrac{398\,945}{365^3}
\end{align*}
%\textsc{In general,}
%\begin{align*}
%|\{\text{at least 2\ldots}\}|& =(365\times 364\times\ldots\times(365-(n-2-1))\times(365-(n-2)))\times \dfrac{n!}{2!1!\ldots 1!}\\
%& \quad+(365\times 364\times\ldots\times(365-(n-3-1))\times(365-(n-3)))\times\dfrac{n!}{3!1!\ldots 1!}\\
%& \quad+\ldots+365\\
%& =\sum\limits_{i=2}^n \left(\dfrac{n!}{i!}\prod\limits_{j=i}^{n}(365-(n-j))\right)
%\end{align*}
%and so
%\begin{equation*}
%\boxed{
%P(\{\text{at least 2 people share a birthday}\})=\dfrac{\sum\limits_{i=2}^n \left(\dfrac{n!}{i!}\prod\limits_{j=i}^{n}(365-(n-j))\right)}{365^n}
%}
%\end{equation*}
\textsc{However}, this seems very laborious to compute, particularly if $n$ is large.\\
We can instead use the complement rule to determine that
\begin{equation*}
\boxed{\begin{split}
P(\{\text{at least 2 people share a birthday}\})& =1-P(\{\overline{\text{at least 2 people share a birthday}}\})\\
& =1-P(\{\text{no shared birthdays}\})\\
& =1-\dfrac{\text{\# of ways to select $n$ unshared birthdays}}{365^n}\\
& =1-\dfrac{365\times 364\times\ldots\times(365-n+1)}{365^n}
\end{split}}
\end{equation*}
For example, if $n=3$,
\begin{align*}
P(\{\text{at least 2 people share a birthday}\})
& =1-\dfrac{\text{\# of ways to select 3 unshared birthdays}}{365^n}\\
& =1-\dfrac{365\times 364\times 363}{365^3}\\
& =1-\dfrac{48\,228\,180}{365^3}\\
& =\dfrac{398\,945}{365^3}
\end{align*}
\textsc{Notice} that, if $n>365$, the above calculation produces
\begin{align*}
P(\{\text{at least 2\ldots}\})& =1-\dfrac{365\times(365-1)\times\ldots\times(365-364)\times(365-365)\times\ldots\times(365-n+1)}{365^n}\\
& =1-\dfrac{365\times\ldots\times 0\times\ldots\times(365-n+1)}{365^n}\\
& =1-\dfrac{0}{365^n}\\
& =1-0=1
\end{align*}
Why does this make sense?\\[1ex]
By the pigeonhole principle, if we have $n$ objects to place in fewer than $n$ pigeonholes, at least 1 pigeonhole will contain multiple objects. In this case, if there are more than 365 birthdays to distribute over 365 days, at least 2 birthdays will fall on the same day. Thus, the probability of at least 2 people sharing a birthday is 1, or absolutely certain.\\[1ex]
\textsc{Note} that this counting method counts \textit{ordered} $n$-tuples: for example, where $n=3$, we consider (1, 1, 2) and (1, 2, 1) to be different combinations of birthdays.\\
If we were to instead consider unordered $n$-tuples, we could not use the classical definition of probability, since not all outcomes would be equally likely. For example, where $n=3$, the unordered combination (1, 1, 2) is more likely than the unordered combination (1, 2, 3), since there are more ways in which the former can occur.

\end{document}


\section{Adjoints of bounded operators}
\label{sec:adjoints-bounded-operators}

\para
Throughout this section, $\hilbertH$ stands for a Hilbert space over the
field $\fldK$ of real or complex numbers.
Let $A \in \blinOps (\hilbertH)$ that is let
$A:\hilbertH \rightarrow \hilbertH$ be linear and bounded. Then the map
\[
 b_A : \hilbertH \times \hilbertH \to \fldK, \: (v,w) \mapsto \inprod{v, Aw}
\]
is sesquilinear and bounded with norm
\[
\norm{b_A} = \sup \big\{ \left| b_A(v,w)\right| \bigmid
   v,w\in \hilbertH \:\&\: \norm{w}=\norm{v}=1 \big\} =
                \norm{A} \ .
\]
By \Cref{thm:correspondence-bounded-sesquilinear-forms-bounded-operators}
to the Riesz representation theorem there exists a unique element
$A^* \in \blinOps(\hilbertH)$ such that
\[
 b_A (v,w) = \inprod{A^* v, w} \quad
 \text{for all } v,w \in \hilbertH \ .
\]
This operator satisfies $\norm{A^*}= \norm{b_A} = \norm{A}$.
\begin{definition}
The unique operator $A^*\in \blinOps (\hilbertH)$ associated to some
$A\in \blinOps(\hilbertH)$ such that
\[
 \inprod{v,Aw} = \inprod{A^* v, w} \quad
 \text{for all } v,w \in \hilbertH
\]
is called the \emph{adjoint} of $A$.
\end{definition}

\begin{proposition}
If $A \in \blinOps (\hilbertH)$, then so is its adjoint $A^* \in \blinOps (\hilbertH)$.
\end{proposition}

\begin{proof}
First we show that $A^*$ is linear. Given $v, w, w' \in H$, we compute
\begin{align*}
\inprod{v, A^*(w + w')} &= \mu_{A, w+w'}(v) = \inprod{Av, w + w'} = \inprod{Av, w} + \inprod{Av, w'}\\
&= \mu_{A, w}(v) + \mu_{A, w'}(v) = \inprod{v, A^*w} + \inprod{v, A^*w'} = \inprod{v, A^*w + A^*w'}
\end{align*}
Since this is true for all $v \in H$, this implies that $A^*(w+w') = A^*w'$.  Furthermore, given $\lambda \in \fldK$, we have
\begin{align*}
\inprod{v, A^*(\lambda w)} &= \mu_{A, \lambda w}(v) = \inprod{Av, \lambda w} = \widebar \lambda \inprod{Av, w}\\
&= \widebar \lambda \mu_{A, w}(v) = \widebar \lambda \inprod{v, A^* w} = \inprod{v, \lambda A^*w}.
\end{align*}
Again, since this is true for all $v \in H$, we know $A^*(\lambda w) = \lambda A^*w$. This proves that $A^*$ is linear.

It remains to show that $A^*$ is bounded. We know
\[
\norm{A^*} = \sup_{\norm{v} = \norm{w} = 1} \abs{\inprod{v, A^* w}} = \sup_{\norm{v} = \norm{w} = 1} \abs{\inprod{w, Av}} = \norm{A} < \infty,
\]
which is what we wanted to show. Note that $\norm{A^*} = \norm{A}$.
\end{proof}

We leave it as an exercise to show that
\[
\norm{A} = \sup_{\norm{v} = \norm{w} = 1} \abs{\inprod{v, Aw}}
\]
for all $A \in \linOps (\hilbertH)$, as was used in the above proof.

\begin{definition}
An operator $A \in \linOps (\hilbertH)$ is called \emph{self-adjoint} if $A = A^*$, \emph{unitary} if $A^* = A^{-1}$, and \emph{normal} if $[A, A^*] = AA^* - A^*A = 0$.
\end{definition}

We note that self-adjoint and unitary operators are always normal, but normal operators do not have to be self-adjoint or unitary. In the remainder of these notes, we gather several results on self-adjoint and normal operators.

\begin{lemma}
An operator $A \in \linOps (\hilbertH)$ is self-adjoint if and only if $\inprod{Av, v} \in \R$ for all $v \in H$.
\end{lemma}

\begin{proof}
$\Rightarrow$) If $A$ is self-adjoint, then
\[
\inprod{Av, v} = \mu_{A,v}(v) = \inprod{v, A^*v} = \inprod{v, Av} = \overline{\inprod{Av,v}},
\]
which implies that $\inprod{Av,v} \in \R$.

$\Leftarrow$) Suppose that $\inprod{Av, v} \in \R$ for all $v \in H$. We know
\begin{align*}
\inprod{A(v+w), v+w} = \inprod{Av, v} + \inprod{Av, w} + \inprod{Aw, v} + \inprod{Aw, w}. \tag{$*$}
\end{align*}
By assumption, $\inprod{A(v+w), v+w}$, $\inprod{Av, v}$, and $\inprod{Aw, w}$ are all real. This implies that $\inprod{Av, w} + \inprod{Aw, v}$ is real as well, so
\[
\Im \inprod{Av, w} = -\Im \inprod{Aw, v}= \Im \inprod{v, Aw}.
\]
Since this holds for all $w \in H$, it holds for $iw$ as well. Thus,
\[
\Re \inprod{Av, w} = \Im \inprod{Av, -iw} = \Im \inprod{v, A(-iw)} = \Im i\inprod{v, Aw} = \Re \inprod{v, Aw}.
\]
Combining the above two lines yields $\inprod{Av, w} = \inprod{v, Aw}$ for all $v, w \in H$. Since the adjoint satisfies $\inprod{Av, w} = \inprod{v, A^*w}$, this implies that $A = A^*$.
\end{proof}

\begin{proposition}
If $A \in \linOps (\hilbertH)$ and $\inprod{Av, v} = 0$ for all $v \in H$, then $A = 0$.
\end{proposition}

\begin{proof}
Since $\inprod{Av, v} = 0$ for all $v \in H$, equation ($*$) from Lemma 4 reduces to
\[
\inprod{Av, w} = -\inprod{Aw, v} = -\inprod{w, Av} = -\overline{\inprod{Av, w}} \quad \text{for all } v, w \in H \ ,
\]
i.e.\ $\inprod{Av,w}$ has no real part for all $v, w \in H$. But then fixing $v$ and setting $w = Av$ implies $\norm{Av}^2 = 0$ for all $v \in H$, so $A = 0$.
\end{proof}

\begin{proposition}
If $A \in \linOps (\hilbertH)$ is self-adjoint, then
\[
\norm{A} = \sup_{\norm{v} = 1} \abs{\inprod{Av, v}}.
\]
\end{proposition}

\begin{proof}
We know
\[
\norm{A} = \sup_{\norm{v} = \norm{w} = 1} \abs{\inprod{Av, w}},
\]
so we clearly have
\[
\sup_{\norm{v} = 1} \abs{\inprod{Av, v}} \leq \norm{A}.
\]
%I'M NOT SURE HOW TO PROVE THE OTHER DIRECTION.
\end{proof}

\begin{proposition}
If $A \in \linOps (\hilbertH)$, then $A^*A$ is self-adjoint and $\norm{A^*A} = \norm{A}^2$.
\end{proposition}

\begin{proof}
For arbitrary $v \in H$, we have
\[
\inprod{A^*Av, v} = \inprod{Av, Av} = \norm{Av}^2 \in \R,
\]
so $A^*A$ is self-adjoint by Lemma 4. By Proposition 6,
\[
\norm{A^*A} = \sup_{\norm{v} = 1} \abs{\inprod{A^*Av, v}}  = \sup_{\norm{v} = 1} \norm{Av}^2 = \norm{A}^2.
\]
\end{proof}

\begin{proposition}
If $A \in \linOps (\hilbertH)$, then there exist $B,C \in \linOps (\hilbertH)$ self-adjoint such that $A = B+iC$. Furthermore, $A$ is normal if and only if $[B,C] = 0$.
\end{proposition}

\begin{proof}
We define
\[
B = \frac{1}{2}(A + A^*) \quad \text{ and } \quad C = \frac{i}{2}(A^* - A).
\]
Clearly $A = B + iC$. Note also that $A^* = B - iC$. Furthermore, for all $v \in H$
\begin{align*}
\inprod{Bv, v} = \frac{1}{2} \inprod{Av, v} + \frac{1}{2}\inprod{A^*v, v} = \frac{1}{2}\inprod{Av, v} + \frac{1}{2}\overline{\inprod{Av, v}} \in \R
\end{align*}
and
\begin{align*}
\inprod{Cv, v} = \frac{i}{2}\inprod{A^*v, v} - \frac{i}{2}\inprod{Av, v} = \frac{i}{2}\overline{\inprod{Av, v}} - \frac{i}{2}\inprod{Av, v} \in \R
\end{align*}
This implies that $B$ and $C$ are self-adjoint by Lemma 4.

Finally, we compute
\begin{align*}
[A, A^*] = [B + iC, B-iC] = -i[B, C] + i[C,B] = -2i[B,C],
\end{align*}
Clearly $A$ is normal if and only if $[B,C] = 0$.
\end{proof}

\begin{proposition}
If $A$ is normal, then $\norm{Av} = \norm{A^*v}$ for all $v \in H$.
\end{proposition}

\begin{proof}
Using the fact that $A^*A = AA^*$, we compute
\begin{align*}
\norm{Av}^2 = \inprod{Av, Av} = \inprod{v, A^*Av} = \inprod{v, AA^*v} = \inprod{A^*v, A^*v} = \norm{A^*v}^2.
\end{align*}
Taking a square root yields the desired result.
\end{proof}


\chapter{Binary Collatz Tree}
\label{ch:binary_tree}

\section{Some essentials on binary trees}
A binary tree is a rooted tree, where each node has at most two immediate successors. Those nodes, from which no edge goes out downward, are called leaves, the others are called internal nodes. In a full binary tree, all internal nodes have exactly two children \cite[p.~102]{Ref_Higham_2015}. Full binary trees have an odd number $2n+1$ of nodes. Of these $n+1$ are leaves and $n$ are inner nodes \cite[p.~134]{Ref_Kersting_Wakolbinger_2008}. Each node in a binary tree has a left subtree and a right subtree, which is why a binary tree is inherently recursive, since the left and right subtrees of the root are themselves binary trees \cite[p.~246-247]{Ref_Mazur_2010}. As it often pops up in combinatorial problems, the famous $n$-th Catalan number, named after the Belgian mathematician Eugène Catalan, comes in connection with binary trees into play. For $n\ge1$ it specifies the number of binary trees on $n$ vertices \cite[p.~247]{Ref_Mazur_2010}:
\[
B_n=\sum_{i=0}^{n-1}B_iB_{n-1-i}=\sum_{i=1}^{n}B_{i-1}B_{n-i}=\frac{1}{n+1}\binom{2n}{n}
\]

There is an interesting property that trees exhibit regarding abstract algebra. Let's have a look at the algebraic structure of magmas. Consider an element $x$ of a magma $(M,*)$ which is an iterated product of other elements in $M$. Such an element can be described by a planar (no edges cross each other) rooted binary tree whose $n$ leaves are labelled by these other elements $x_1,\ldots,x_n\in M$ \cite[p.~96]{Ref_Kalka_2016}.

Binary trees make well-suited data structures for storing information. With about $2^m$ data points (nodes), a search of a binary tree takes only about $m$ steps, compared to about $2^{m-1}$ steps which are required to search a simple list \cite[p.~84]{Ref_Benjamin_2009}.

\section{Transforming the Collatz tree into a binary tree}
Jan Kleinnijenhuis and Alissa M. Kleinnijenhuis \cite{Ref_Kleinnijenhuis_2020a} introduced a binary tree $T_{\ge0}$ by transforming the original Collatz tree $H_U$ into the Syracuse tree $H_{C,3}$, which in turn is transformed into the binary tree $T_{\ge0}$ as described next. The edges are changed according to the following procedure: whenever a parent node $w$ has edges to its child nodes $v_0,v_1,\ldots,v_n$, on the tree $H_{C,3}$, we draw an edge from $w$ to $v_0$, and edges from $v_i$ to $v_{i+1}$ for each $i=1,\ldots,n-1$, in the binary new tree. Note that the nodes $v_1,v_2,\ldots,v_n$ are sorted in increasing order of label $v_0<v_1<\ldots<v_n$, which is already given by \ref{eq:n_fold_right_sibling_k}. Figure~\ref{fig:bt3} and \ref{fig:bt3_rot} display that tree -- once in our standard layout and once reversed (from bottom to top).

\begin{figure}[H]
	\includegraphics[width=1.00\textwidth]{figures/bt_3_t0.png}
	\caption{The Collatz Tree transformed to the binary tree $T_{\ge0}$}
	\label{fig:bt3}
\end{figure}

\vspace{-2em}
\begin{figure}[H]
	\includegraphics[width=1.00\textwidth]{figures/bt_3_t0_rot.png}
	\caption{The binary tree $T_{\ge0}$ with \textit{bottom-to-top} layout orientation}
	\label{fig:bt3_rot}
\end{figure}

\begin{remark}
	To clarify the terminology, it should be mentioned that Jan and Alissa M. Kleinnijenhuis in their manuscripts \cite{Ref_Kleinnijenhuis_2020a}, \cite{Ref_Kleinnijenhuis_2020b} denote the original Collatz tree $T_C$ while we call it $H_U$. They denote the Syracuse Tree $T_T$ which in our nomenclature is referred to as $H_{C,3}$.
\end{remark}

Nodes that are highlighted orange in figures~\ref{fig:bt3},~\ref{fig:bt3_rot} are called \textit{prunable} and they are exactly those nodes resulting as output of the \textit{Rightward} function. For navigating within this binary tree, Jan Kleinnijenhuis and Alissa M. Kleinnijenhuis \cite{Ref_Kleinnijenhuis_2020a} defined an \textit{Upward} function $U(n)$ and a \textit{Rightward} function $R(n)$ as follows:

\begin{equation}
\label{eq:bintree_3_rightward_upward}
\setlength{\arraycolsep}{1.6em}
\begin{array}{cc}
U(n)=\begin{cases}
        4n+1	&	n\equiv 1\pmod 6\\
        16n+5	&	n\equiv 5\pmod 6
    \end{cases} &
R(n)=\begin{cases}
    \nicefrac{(2^2n-1)}{3}	&	n\in[1]_{18}\cup[13]_{18}\\
    \nicefrac{(2^3n-1)}{3}	&	n\in[5]_{18}\\
    \nicefrac{(2^4n-1)}{3}	&	n\in[7]_{18}\\
    \nicefrac{(2^1n-1)}{3}	&	n\in[11]_{18}\cup[17]_{18}
\end{cases}
\end{array}
\end{equation}

The domain and codomain of both functions consist of the two residue classes $[1]_6,[5]_6$, which form the multiplicative (cyclic) group $\mathbb{Z}^\ast_6=\{1,5\}=\left<5\right>$. Consequently, the domain and codomain exclude all integers divisible by $2$ and $3$, which is due to the fact that this binary tree (just like our tree $H_{C,3}$) does not contain even numbers and additionally all leaves -- namely those nodes labeled with an integer divisible by three -- were deleted. The function $U(n)$ is very similar to the function~\ref{eq:next_sibling_k3} and to the more general function~\ref{eq:n_fold_right_sibling_k} (when setting $n=1,k=3$) which both calculate the right-sibling of a given vertex. This is clear, since siblings (parallel) in $H_{C,3}$ are successors (serial) in the binary tree $T_{\ge0}$. In the end, for a node $v_0$ having a leaf as right-sibling in $H_{C,3}$, the function $U(v_0)$ is defined as $v_1=4v_0+1$ executed twice $v_1=4(4v_0+1)+1=16v_0+5$, because we must skip this leaf. Recall that all leafs in $H_{C,3}$ are excluded from the binary tree without exception. For any $n\in[5]_6$ it applies that $U(n)\equiv16n+5\equiv\boldsymbol{1}\bmod(6)$ since $6\mid16n+5-\boldsymbol{1}$ resulting in $6\mid16(5+k\cdot6)+5-\boldsymbol{1}$, see \ref{eq:congruence}, and analogously for any $n\in[1]_6$ it applies that $U(n)\equiv4n+1\equiv\boldsymbol{5}\bmod(6)$ since $6\mid4n+1-\boldsymbol{5}$ resulting in $6\mid4(1+k\cdot6)+1-\boldsymbol{5}$. Therefore executing the Upward function twice in a row leads unconditionally to $U^2(n)=16(4n+1)+5=4(16n+5)+1=64n+21$.

\begin{remark}
	While we displayed trees from top to down, it is sometimes usual to draw trees in a bottom-to-top fashion as Kleinnijenhuis \cite{Ref_Kleinnijenhuis_2020b} do. The Rightward function corresponds to what we call left-child and the Upward function relates to the right-child which is commonly used in the context of binary trees \cite[p. 246]{Ref_Mazur_2010}.
\end{remark}

Jan and Alissa M. Kleinnijenhuis \cite{Ref_Kleinnijenhuis_2020a} defined the set $N(T_C)=N(H_U)$ that contains the labels of all nodes, to which a path from the root in $H_U$ exists, in other words, this set contains all integers $n$ for which the orbit of $n$ under the (uncompressed) Collatz function~\ref{eq:func_collatz} converges to $1$. Furthermore they introduced $S_{\ge0}$ as the node set containing integers that are neither divisible by $2$ nor by $3$. The set $S_{-1}$ comprises on the contrary all numbers, which are divisible by $2$ or $3$. In order to comprehend the structure of these sets $S$, let us take a look at the following list showing which tree includes which node set, see also the ancillary files of \cite{Ref_Kleinnijenhuis_2020a}, \cite{Ref_Kleinnijenhuis_2020b}:

\[\arraycolsep=0.6em\def\arraystretch{1.4}
\begin{array}{llll}
\text{Original Collatz tree} & N(T_C)=N(H_U)&=&\mathbb{N^+} \hspace{0.6em}\text{if the Collatz conjecture holds}\\
\text{Syracuse tree} & N(T_T)=N(H_{C,3})&=&N(T_C)\setminus2\mathbb{N}\\
\text{Binary tree}\hspace{0.6em}T_{\ge0}& N(T_{\ge0})=S_{\ge0}&=&N(T_C)\setminus S_{-1}\hspace{2.1em}=S_{0}\cup S_{1}\cup S_{2}\ldots\\
\text{Binary tree}\hspace{0.6em}T_{\ge1}& N(T_{\ge1})=S_{\ge1}&=&N(T_C)\setminus \bigcup_{i=-1}^{0}S_i=S_{1}\cup S_{2}\cup S_{3}\ldots\\
\text{Binary tree}\hspace{0.6em}T_{\ge j} & N(T_{\ge j})=S_{\ge j}&=&N(T_C)\setminus \bigcup_{i=-1}^{j-1}S_i=\bigcup_{i=j}^{\infty}S_i
\end{array}
\]

\par\medskip
Let us describe these sets using multiplicative groups. The set $S_{\ge0}=\mathbb{Z}^\ast_6$ can be understood as the multiplicative group modulo $6$ and the set $S_{-1}=\mathbb{Z}/6\mathbb{Z}\setminus\mathbb{Z}^\ast_6=\{0,2,3,4\}$ as the set of all non-invertible elements (non-units) of $\mathbb{Z}/6\mathbb{Z}$.

The set $S_0$ consists of all nodes resulting as output of $R(n)$ within the binary tree $T_{\ge0}$. These are the orange highlighted nodes displayed by figures~\ref{fig:bt3},~\ref{fig:bt3_rot}. In other words, $S_0$ is the codomain of the function $R(n)$ operating on nodes within $T_{\ge0}$. The binary tree $T_{\ge0}$ can be transformed to a (pruned) binary tree $T_{\ge1}$. For this, the prunable nodes will be deleted and their neighbors reconnected. The upward neighbor of a pruned node will then be identified as pruning candidate for a later transformation of the resulting tree $T_{\ge1}$ to a more pruned tree $T_{\ge2}$.

The set $S_1$ contains all nodes that are (as per the description above) identified as pruning candidates for the next transformation of $T_{\ge1}$ to $T_{\ge2}$. After having transformed $T_{\ge1}$ to $T_{\ge2}$, the more pruned binary tree $T_{\ge2}$ contains nodes that are identified as pruning candidates for another upcoming transformation of $T_{\ge2}$ to $T_{\ge3}$ -- these nodes are elements of the set $S_2$. This pruning algorithm is repeatedly applied in the same pattern. And in this way we obtain the sets $S_1,S_2,S_3,\ldots$ and so forth. Generally, we can write these sets in the form $S_j=\{n\in N(T_{j-1})\mid U^{-j}(n)\in S_0\}$. Kleinnijenhuis found out that the codomain $\mathbb{N}^U$ of the Upward function contains $5$ residue classes modulo $96$, namely $\{5, 29, 53, 77, 85\}=\mathbb{N}^U$ and the codomain $\mathbb{N}^R$ of the Rightward function comprises $27$ residue classes modulo $96$, namely $\{1, 7, 11, 13, 17, 19, 23, 25, 31, 35, 37, 41, 43, 47, 49, 55, 59, 61, 65, 67, 71, 73, 79, 83, 89, 91, 95\}=\mathbb{N}^R$. The union of both sets $\mathbb{N}^U\cup\mathbb{N}^R$ forms the non-cyclic multiplicative group $\mathbb{Z}^\ast_{96}$, whose generating set is $\{5, 17, 31\}$ (see \cite{Ref_Lang_2017}, \cite{Ref_OESIS_A033949}). All elements of the Upward function's codomain have the same remainder $5$ when divided by $8$.

For each subset $X$ of a group $G$, the intersection over all subgroups (of $G$) that contain this subset $X$ is \cite[p.~34]{Ref_Karpfinger_Meyberg_2017}:
\[
\left<X\right>=\bigcap_{X\subseteq U\le G}U
\]

Firstly it applies $\left<X\right>\le G$ meaning that this intersection is again a subgroup of $G$. It is generated by the \textit{generating set} $X$ and it is the smallest subgroup of $G$ containing every element of $X$ \cite[p.~35]{Ref_Karpfinger_Meyberg_2017}. Secondly, $\left<X\right>\subseteq U$ for each subgroup $U$ (of $G$) containing $X$.  Thirdly, when there is only a single element $x$ in $X$, then $\left<X\right>$ is usually written as $\left<x\right>$ and in this case, $\left<x\right>$ is the cyclic subgroup of $G$ -- such situations we have already seen in section~\ref{sec:left_child_right_sibling_3}. Let us refer back to $\mathbb{Z}^\ast_{96}$. In this example, $\left<\{5,17,31\}\right>$ is the subgroup generated by $\{5,17,31\}$ and therefore every element of $\mathbb{Z}^\ast_{96}$ is of the form $5^l17^m31^n$ where $l\in\{0,1,\ldots,7\}$ because the element $5$ has order $8$, and similarly $m,n\in\{0,1\}$ since both elements $17$ and $31$ have order $2$. Non-cyclic groups can be cyclic decomposed, which is detailed by Gallian and Rusin \cite{Ref_Gallian_Rusin_1980} and Cheng \cite{Ref_Cheng_1989} using the concept of the external direct product \cite[p.~79]{Ref_Karpfinger_Meyberg_2017}, \cite[p.~156]{Ref_Gallian} and the internal direct product \cite[p.~80]{Ref_Karpfinger_Meyberg_2017}, \cite[p.~183]{Ref_Gallian}. A comprehensive table of cyclic decompositions of multiplicative non-cyclic groups of integers modulo $n$ up to $n=130$ is provided by Wolfdieter Lang \cite{Ref_Lang_2017}.

% http://mathonline.wikidot.com/the-internal-direct-product-of-two-groups

Let us take a closer look at the (cyclic) multiplicative group $\mathbb{Z}^\ast_{18}=\{1,5,7,11,13,17\}=\left<5\right>$ which has an order $ord(\mathbb{Z}^\ast_{18})=6$. Having the generator $5$ coprime to the modulus $18$, we obtain the congruence $5^{\phi(18)}\equiv1\pmod{18}$ in accordance with Euler's theorem \ref{eq:eulers_theorem}. This allows us to infer from $5^6\equiv5^{6(n+1)}\equiv5^j5^{6n+6-j}\equiv1\pmod{18}$ the congruences given by \ref{eq:homomorphism_congruences} (on the left).

If a natural number divides another, $m\mid n$, as in our case $3\mid18$, then for two integers $a,b$ the following implication holds, see \cite[p.~21]{Ref_Mueller-Stach_2011}:

\begin{equation}
	\label{eq:reduce_modulus}
	a\equiv b\pmod n\rightarrow a\equiv b\pmod m
\end{equation}

This means in our case $w\cdot5^{6n+6}\equiv 1\pmod{18}\rightarrow w\cdot5^{6n+6}\equiv 1\pmod 3$.
In fact, Euler's theorem (\ref{eq:eulers_theorem}) gives us two congruences $5^{\phi(18)}\equiv1\pmod{18}$ and $2^{\phi(3)}\equiv1\pmod{3}$. The latter is obvious, because $\mathbb{Z}_3^\ast=\left<2\right>$. Since $\phi(18)=6$ and $\phi(3)=2$, every power of five with an exponent divisible by $6$ and every power of two with an exponent divisible by 2 belong to the residue classes $[1]_{18}$ and $[1]_3$.

Because of $[1]_{18}=[5^0]_{18},\ldots,[13]_{18}=[5^4]_{18}$ and finally $[11]_{18}=[5^5]_{18}$ we obtain the congruences on the left side in \ref{eq:homomorphism_congruences}. The exponents are indicated by the $j$. For example, it follows from $w\in[13]_{18}$ that $[w\cdot5^{6n+2}]_{18}=[w]_{18}\cdot[5^{6n+2}]_{18}=[13]_{18}\cdot[5^{6n+2}]_{18}=[5^4]_{18}\cdot[5^{6n+2}]_{18}=[5^{6n+6}]_{18}=[1]_{18}$, because $6n+6$ is divisible by $6$ (Euler's theorem).

From the equality of the residue classes modulo $18$ and modulo $3$ (according to equation~\ref{eq:reduce_modulus}) it follows for $w\in[13]_{18}$ from $[w]_{18}\cdot[5^{6n+2}]_{18}=[13]_{18} \cdot[5^{6n+2}]_{18}=[1]_{18}$ the following equation:

\begin{equation}
\label{eq:mod_18_3}
[1]_3=[w]_3\cdot[5^{6n+2}]_3=[13]_3\cdot[5^{6n+2}]_3
\end{equation}

Just replacing $18$ with $3$, that is the homomorphism given by the map $f:\mathbb{Z}^\ast_n\rightarrow \mathbb{Z}^\ast_m$ with $f(r\bmod n)=r\bmod m$ as long as $\gcd(r\bmod n,n)=1$ leads to $\gcd(r\bmod m,m)=1$. By Euclid, we know that in the case $r$ is coprime to $n$ then it is also coprime to every factor $m$ of $n$. That is why a homomorphism exist to the congruences shown in \ref{eq:homomorphism_congruences} (on the right).

Using the fact that $[5^{6n}]_{18}=[5^0]_{18}=[1]_{18}$ and thus $[5^{6n+k}]_{18}=[5^k]_{18}=[5]_{18}^k=[5]_3^k$, we obtain from equation~\ref{eq:mod_18_3}:

\[
[1]_3=[13]_3\cdot[5]_3^2=[13]_3\cdot[2]_3^2
\]

Therefore $[13]_{18}\cdot4=[13]_3\cdot4\equiv1\pmod{3}$. The third and the last row in \ref{eq:homomorphism_congruences} are obtained in the same way. The powers of two that appear in the other rows result from the fact that we can always add or remove even powers of two because $[2^2]_3=[1]_3$.

Based on equation~\ref{eq:congruence_reduction} we can state that $a\equiv b\pmod m$ implies $(a+m)\equiv b\pmod m$. Let us set $a=w\cdot2^{2n+2}$ and $b=1$ and $m=3$, then we obtain $(w\cdot2^{2n+2}+3)\equiv1\pmod3$ and using a factor $i\in\mathbb{N}$ we obtain the more general congruence $(w\cdot2^{2n+2}+3i)\equiv1\pmod3$. As a consequence the congruences in \ref{eq:homomorphism_congruences} are true, while $w\cdot5^{6n+6}=w\cdot2^{2n+2}+3\cdot i$ or rather while $3\mid(5^{6n+6}-2^{2n+2})$. These conditions continue $3\mid(5^{6n+5}-2^{2n+3})$ and $3\mid(5^{6n+4}-2^{2n+4})$ and so forth.

\begin{equation}
\label{eq:homomorphism_congruences}
\begin{array}{llllll}
	j=0, & w\in [1]_{18} & \hspace{1em} w\cdot5^{6n+6}&\equiv1\pmod{18}&\hspace{4em}w\cdot2^{2n+2} &\equiv1\pmod{3}\\
	j=1, & w\in [5]_{18} & \hspace{1em} w\cdot5^{6n+5}&\equiv1\pmod{18}&\hspace{4em}w\cdot2^{2n+3} &\equiv1\pmod{3}\\
	j=2, & w\in [7]_{18} & \hspace{1em} w\cdot5^{6n+4}&\equiv1\pmod{18}&\hspace{4em}w\cdot2^{2n+4} &\equiv1\pmod{3}\\
	j=3, & w\in [17]_{18} & \hspace{1em} w\cdot5^{6n+3}&\equiv1\pmod{18}&\hspace{4em}w\cdot2^{2n+1} &\equiv1\pmod{3}\\
	j=4, & w\in [13]_{18} & \hspace{1em} w\cdot5^{6n+2}&\equiv1\pmod{18}&\hspace{4em}w\cdot2^{2n+2} &\equiv1\pmod{3}\\
	j=5, & w\in [11]_{18} & \hspace{1em} w\cdot5^{6n+1}&\equiv1\pmod{18}&\hspace{4em}w\cdot2^{2n+1} &\equiv1\pmod{3}
\end{array}
\end{equation}

The inverse upward function, which can be understood as a downward function $U^{-1}(n)=D(n)$ is defined as follows:

\[
D(n)=U^{-1}(n)=\begin{cases}
	\nicefrac{n-1}{4}	&	n\equiv 5\pmod{24}\\
	\nicefrac{n-5}{16}	&	n\equiv 85\pmod{96}
\end{cases}
\]

The modular conditions are deduced as follows: We have $D(n)=\nicefrac{n-1}{4}$ if $\nicefrac{n-1}{4}\equiv1\pmod6$ and $D(n)=\nicefrac{n-5}{16}$ if $\nicefrac{n-5}{16}\equiv5\pmod6$. For $a,b\in\mathbb{Z}$ and $n,m\in\mathbb{N}$ we can apply the following modular arithmetic rule \cite[p.~21]{Ref_Mueller-Stach_2011}:

\begin{equation}
a\equiv b\pmod n \leftrightarrow m\cdot a\equiv m\cdot b\pmod{m\cdot n}
\end{equation}

This leads to $D(n)=n-1$ if $n-1\equiv4\pmod{24}$ and $D(n)=n-5$ if $n-5\equiv80\pmod{96}$.

Now we make the use of another modular arithmetic rule, which for two given congruences $a\equiv b\pmod n$ and $c\equiv d\pmod n$ states that \cite[p.~19]{Ref_Mueller-Stach_2011}:

\begin{equation}
	a+c\equiv b+d\pmod n\hspace{2em} \text{and}\hspace{2em}a\cdot c\equiv b\cdot d\pmod n
\end{equation}

This finally leads to $D(n)=n-1$ if $n\equiv5\pmod{24}$ and $D(n)=n-5$ if $n\equiv85\pmod{96}$.

The rightward function that operates on the tree of pruning level $1$, thus the tree $T_{\ge1}$, is can be expressed as the right-to-left composition $R_{\ge1}(n)=U\circ R\circ U^{-1}(n)=U\circ R\circ D(n)$ and it is defined as follows:

\[
R_{\ge1}(n)=\begin{cases}
	\nicefrac{(8D(n)-1)}{3}	&	2D(n)\equiv4\bmod{18}\wedge D(n)\in[11]_{18}\cup[17]_{18}\\
	\nicefrac{(16D(n)-1)}{3}	&	4D(n)\equiv4\bmod{18}\wedge D(n)\in[11]_{18}\cup[13]_{18}\\
	\nicefrac{(32D(n)-1)}{3}	&	2D(n)\equiv16\bmod{18}\wedge D(n)\in[11]_{18}\cup[17]_{18}\vee D(n)\in[5]_{18}\\
	\nicefrac{(64D(n)-1)}{3}	&	4D(n)\equiv16\bmod{18}\wedge D(n)\in[1]_{18}\cup[13]_{18}\vee D(n)\in[7]_{18}\end{cases}
\]

\[
R_{\ge2}(n)=\begin{cases}
	\nicefrac{(32D^2(n)-1)}{3}	&	2D^2(n)\in[4]_{18}\wedge D^2(n)\in[11]_{18}\vee8D^2(n)\in[4]_{18}\wedge D^2(n)\in[17]_{18}\\
	\nicefrac{(64D^2(n)-1)}{3}	&	D^2(n)\in[1]_{18}\cup[13]_{18}\wedge4D^2(n),16D^2(n)\in[4]_{18}\\
	\nicefrac{(128D^2(n)-1)}{3}	& \parbox[t]{.7\textwidth}{$	D^2(n)\in[11]_{18}\cup[17]_{18}\wedge(2D^2(n)\in[4]_{18}\wedge8D^2(n)\in[16]_{18}\vee2D^2(n)\in[16]_{18}\wedge32D^2(n)\in[4]_{18})$}\\
	\nicefrac{(256D^2(n)-1)}{3}	&	D^2(n)\in[1]_{18}\vee D^2(n)\in[7]_{18}\cup[13]_{18}\wedge64D^2(n)\in[4]_{18}\\
	\nicefrac{(512D^2(n)-1)}{3}	&	32D^2(n)\in[16]_{18}\wedge(2D^2(n)\in[16]_{18}\wedge D^2(n)\in[11]_{18}\cup[17]_{18}\vee D^2(n)\in[5]_{18})\\
	\nicefrac{(1024D^2(n)-1)}{3}	&	64D^2(n)\in[16]_{18}\wedge(D^2(n)\in[7]_{18}\vee4D^2(n)\in[16]_{18}\wedge D^2(n)\in[1]_{18}\cup[13]_{18})\end{cases}
\]

\newpage
Figure~\ref{fig:tree_transformations} shows the complete chain of tree transformations, beginning from the original Collatz tree, over the Syracuse tree to the binary tree and pruned ones.

% trim=left bottom right top
\begin{figure}[H]
	\includegraphics[trim=1.1cm 10cm 2.6cm 0.2cm,
	width=1.00\textwidth,page=1]{figures/tree_transformations.pdf}
	\caption{Transformation chain, beginning from the original Collatz tree up to pruned binary trees}
	\label{fig:tree_transformations}
\end{figure}


\chapter{The Hamiltonian Method}
\section{Basics}
\begin{definition}
If the determinant of the matrix
\begin{align}
a_{ik} = \frac{\partial^2 L(q_m,\dot{q}_m)}{\partial \dot{q}_i \partial \dot{q}_k}
\end{align}
vanishes, the Lagrangian is called degenerate. Otherwise, $L$ is nondegenerate or regular.
\end{definition}
When the Lagrangian is degenerate, some of the velocities $\dot{q}_i$ can disappear when we try to find $p_i(q_i,\dot{q}_i)$. We are left with an equation depending on the coordinates and momenta, called a constraint.
\begin{definition}[Primary constraint]
Equations of the form
\begin{align}
\phi_m(q_i,p_i) = 0,
\end{align}
where $m = 1, ..., M$ is the number of constraints, are called primary constraints when they follow from the definition of the generalized momentum.
\end{definition}
Let's illustrate what these constraints mean. One can visualize the state of a mechanical system with $n$ degrees of freedom as a point $(q_i,p_i)$ in a $2n$-dimensional phase space ($n$ coordinates and $n$ momenta). The coordinates of this point (the state) depend on time and evolve according to the Hamiltonian equations of motion.
\begin{figure}[H]
\begin{center}
\includegraphics[scale=1.28]{img/constraint.pdf}
\end{center}
\caption{Two intersecting constraint surfaces. The system is only allowed to be in states in which both constraints are fulfilled.}
\label{fig:1}
\end{figure}
In general, the trajectory of this point can fill the whole phase space. When we have constraints, the system is only allowed to be in states in which the constraints are fulfilled. In phase space, they build hypersurfaces on which the point is allowed to move. If every constraint can be fulfilled, the point will move on the intersections of all constraints, like visualized in Fig. \ref{fig:1}. But how to include this into the mathematical formalism? \\
To see, how the constraints enter into the Hamiltonian equations of motion
\begin{align}
\dot{q}_i &= \frac{\partial H}{\partial p_i} \label{eq:1} \\
\dot{p}_i &= - \frac{\partial H}{\partial q_i} \label{eq:2}
\end{align}
and change the dynamics, it will be very useful to write them with Poisson brackets.
\begin{definition}[Poisson bracket]
\begin{align}
\left \{ f(q_i, p_i),g(q_i, p_i) \right \} \equiv \sum_{i=1}^n \left( \frac{\partial f}{\partial q_i} \frac{\partial g}{\partial p_i} - \frac{\partial g}{\partial q_i} \frac{\partial f}{\partial p_i} \right).
\end{align}
\end{definition}
Some properties of the Poisson bracket are:
\begin{enumerate}
\item \(
\begin{aligned}[t]
\left \{ f,g \right \} = - \left \{ g,f \right \}
\end{aligned} \) \ - \ anticommutative
\item \(
\begin{aligned}[t]
\left \{ \alpha f_1 + \beta f_2,g \right \} = \alpha \left \{ f_1,g \right \} + \beta \left \{ f_2,g \right \}
\end{aligned} \) \ - \ bilinear
\item \(
\begin{aligned}[t]
\left \{  f_1 f_2,g \right \} = f_1 \left \{ f_2,g \right \} + f_2 \left \{ f_1,g \right \}
\end{aligned} \) \ - \ "derivative"
\item \(
\begin{aligned}[t]
\left \{ \left \{ f,g \right \},h \right \} + \left \{ \left \{ g,h \right \},f \right \} + \left \{ \left \{ h,f \right \},g \right \} = 0
\end{aligned} \) \ - \ Jacobi identity
\end{enumerate}
These rules hold for any three functions $f,g,h$ of phase space and time (observables).
\begin{theorem}\label{theorem}
The time evolution for any observable $g(q_i,p_i)$ is
\begin{equation}\label{eq:3}
\dot{g} = \frac{dg}{dt} = \left \{ g,H \right \}.
\end{equation}
It is equivalent to the Hamiltonian equations of motion.
\end{theorem}
\begin{proof}
"$\Rightarrow$" By definition of the total derivative we have
\begin{align}
\frac{dg}{dt} = \sum_{i=1}^n \left( \frac{\partial g}{\partial q_i} \dot{q}_i + \frac{\partial g}{\partial p_i} \dot{p}_i \right) = \sum_{i=1}^n \left( \frac{\partial g}{\partial q_i} \frac{\partial H}{\partial p_i} - \frac{\partial g}{\partial p_i} \frac{\partial H}{\partial q_i} \right) = \left \{ g,H \right \},
\end{align}
where we used the Hamiltonian equations of motion \eqref{eq:1} and \eqref{eq:2}. \\
"$\Leftarrow$" Choose $g = q_k$ and get
\begin{align}
\dot{q}_k = \left \{ q_k,H \right \} = \frac{\partial H}{\partial p_k}.
\end{align}
Analog, with $g = p_k$ we get
\begin{align}
\dot{p}_k = \left \{ p_k,H \right \} = - \frac{\partial H}{\partial q_k}.
\end{align}
\end{proof}
From now on, we will use equation \eqref{eq:3} when we talk about equation of motion. This notation has the big advantage that it can be generalized directly under quantization:
\begin{align}
\left \{ f,g \right \} \  \longrightarrow \ \frac{1}{i \hbar} \ [\hat{f},\hat{g}].
\end{align}
So when we quantize our system and $\hat{g}(\hat{q}_i,\hat{p}_i)$ is an operator, the equation of motion take the form
\begin{align}
\frac{d}{dt}\hat{g} = \frac{i}{\hbar} \ [\hat{H} , \hat{g}],
\end{align}
which is equivalent to the Heisenberg and Schrödinger equation.

\section{From the Lagrangian to the Hamiltonian}
Suppose we have a Lagrangian $L = L(q_i,\dot{q}_i)$. The first step to get the Hamiltonian
\begin{align}
q_i \longrightarrow p_i \equiv \frac{\partial L(q_i,\dot{q}_i)}{\partial \dot{q}_i} = p_i(q_i,\dot{q}_i)
\end{align}
is always possible because one can still differentiate, even when $L$ is degenerate.
For the next step, to express the Hamiltonian only through $q_i$ and $p_i$, it can happen that some velocities $\dot{q}_k$ vanish when we try to calculate the generalized momenta. In this case, it is not possible to express $\dot{q}_k$ through the conjugated momentum $p_k$ and we are left with a primary constraint. So we have not set them by hand, they arised from the definition of the generalized momentum. But there is a nice theorem:
\begin{theorem}
Even if we cannot invert the definition of the generalized momentum and express some velocities through their momenta,
\begin{align}
H(q_i,\dot{q}_i) = \sum_{i=1}^{n} \dot{q}_i p_i(q_i,\dot{q}_i) - L(q_i,\dot{q}_i),
\end{align}
is still a function of the coordinates and momenta, all velocities can be eliminated.
\end{theorem}
\begin{proof}
The variation of this function is
\begin{align}
\delta H(q_i,\dot{q}_i) &= \sum_{k=1}^{n} \left( \frac{\partial H}{\partial q_k} \delta q_k + \frac{\partial H}{\partial \dot{q}_k} \delta \dot{q}_k \right) \notag \\
&= \sum_{k=1}^{n} \left( \sum_{i=1}^n \dot{q}_i \frac{\partial p_i}{\partial q_k} - \frac{\partial L}{\partial q_k} \right) \delta q_k + \sum_{k=1}^n \left( p_k + \sum_{i=1}^n \dot{q}_i \frac{\partial p_i}{\partial \dot{q}_k} - \frac{\partial L}{\partial \dot{q}_k} \right) \delta \dot{q}_k \notag \\
&= \sum_{i=1}^{n} \dot{q}_i \left( \sum_{k=1}^n \frac{\partial p_i}{\partial q_k} \delta q_k + \sum_{k=1}^n \frac{\partial p_i}{\partial \dot{q}_k} \delta \dot{q}_k \right) - \sum_{k=1}^n \frac{\partial L}{\partial q_k} \delta q_k \notag \\
&= \sum_{i=1}^n \dot{q}_i \delta p_i - \sum_{i=1}^n \frac{\partial L}{\partial q_i} \delta q_i.
\end{align}
Since we can rewrite the variation in terms of $\delta q_i$ and $\delta p_i$, the Hamiltonian can be expressed as a function of the coordinates and momenta only.
\end{proof}
Comparing the terms in the last line with the variation of $H$ with respect to $\delta q_i$ and $\delta p_i$ and using the Euler-Lagrange-equation, one can find the Hamilton equations of motion. \\
But it is not so easy after all. Remember that we still can have primary constraints $\phi_m$ with vanashing variation:
\begin{align}
\delta \phi_m = 0 = \sum_{i=1}^n \left( \frac{\partial \phi_m}{\partial q_i} \delta q_i + \frac{\partial \phi_m}{\partial p_i} \delta p_i \right).
\end{align}
So we could add this variation to the variation of the Hamiltonian without changing it. This is very useful because normally, $M$ constraints would result in $2n - M$ independent equations of motion but most times, it is easier just to add $M$ independent arbitrary coefficients/functions than reducing the number of equations. So we return the lost degrees of freedom by multiplying our constraints with arbitrary functions $u_m$ and adding them to our variation.
Continuing this idea, since the variation of the constraints is zero, we can add
\begin{align}
0 = \sum_{m=1}^M u_m \delta \phi_m = \sum_{m=1}^M u_m \sum_{i=1}^n \left( \frac{\partial \phi_m}{\partial q_i} \delta q_i + \frac{\partial \phi_m}{\partial p_i} \delta p_i \right)
\end{align}
to
\begin{align}
\sum_{i=1}^n \left( \frac{\partial H}{\partial p_i} - \dot{q}_i \right) \delta p_i + \sum_{i=1}^n \left( \frac{\partial H}{\partial q_i} + \dot{p}_i \right) \delta q_i = 0,
\end{align}
where we used the Hamilton equations of motion, and get
\begin{align}
\frac{\partial H}{\partial p_i} + \sum_{m=1}^M u_m \frac{\partial \phi_m}{\partial p_i} &= \dot{q}_i \\
\frac{\partial H}{\partial q_i} + \sum_{m=1}^M u_m \frac{\partial \phi_m}{\partial q_i} &= - \dot{p}_i,
\end{align}
which are $2n$ equations with $M$ independent extra-functions.
It looks like these extra-functions were added to the Hamiltonian, so the following definition is reasonable:
\begin{definition}[Total Hamiltonian]
\begin{align}
H_T(q_i,p_i) \equiv H(q_i,p_i) + \sum_{m=1}^M u_m(q_i,p_i) \phi_m(q_i,p_i).
\end{align}
\end{definition}
Now we want to adapt our results to the formulations of the equations of motion with Poisson brackets. We claim that
\begin{align}
\dot{g} = \left \{ g,H_T \right \} &= \left \{ g,H \right \} + \sum_{m=1}^M u_m  \left \{ g,\phi_m \right \} + \sum_{m=1}^M \left \{ g,u_m \right \} \phi_m \notag \\
&\approx \left \{ g,H \right \} + \sum_{m=1}^M u_m  \left \{ g,\phi_m \right \},
\end{align}
where we have used that all constraints are zero on the constraint surface in the last step. The proof is analog to the proof of Theorem~\ref{theorem}. \\

At this point, we should say something about the usage of constraints and \textit{weak equalities}. First of all, we are not allowed to use the constraints inside a Poisson bracket. We have to calculate the Poisson bracket first and then apply the constraint when it is outside the bracket. If two quantities $f,g$ differ only by a linear combination of constraints, we call them weakly equal (denoted by $f \approx g$). We will use this notation sometimes to distinguish them from usual or strong equations.

\begin{example}
Consider the Lagrangian
\begin{align}
L = L(q,\dot{q}) = q \dot{q} - \frac{q^2}{2}.
\end{align}
From the definition of the generalized momentum follows a primary constraint:
\begin{align}
p = \frac{\partial L}{\partial \dot{q}} = q \ \ \ \Longrightarrow \ \ \ \phi_1 = p - q = 0.
\end{align}
Because of this constraint, the Hamiltonian is not unique:
\begin{align}
H = \dot{q} p - L = \frac{q^2}{2} = \frac{p^2}{2} = \frac{q p}{2}.
\end{align}
This arbitrariness is included in the total Hamiltonian:
\begin{align}
H_T = \frac{q^2}{2} - u_1(q,p) (p-q).
\end{align}
Depending on the choice of $u_1(q,p)$, we can switch from one form to another.
\end{example}

Realizing the appearance of unknown functions in the Hamiltonian and the equations of motion, one might develop bad thoughts about determinism and the predictability of the future.
It turns out that everything keeps predictable and the unknown functions aren't a big problem after all. We will see later that they correspond to mathematical degrees of freedom, so called gauge transformations. \\

For now, let us focus on the consistency of our theory. When we choose the initial conditions, we have to assure ourself that they fulfill the constraints. After time, the equations of motion could lead to a point in phase space which is not on the constraint surface. How to ensure that the system doesn't leave the constraint surface?
Since we want that the primary constraints are fulfilled at every moment, we require
\begin{align}\label{eq:4}
0 \overset{!}{=} \dot{\phi}_k = \left \{ \phi_k,H \right \} + \sum_{m=1}^M u_m  \left \{ \phi_k,\phi_m \right \},
\end{align}
for $k=1,...,M$. This can lead to four cases. First, it could lead directly to an inconsistency saying that the Lagrangian describes no proper system. Second, it could be satisfied identically and we can be sure that everything will be fine. Third, it can lead to an equation that determines the unknown functions and reduces the degrees of gauge freedom. Fourth, it can lead to other constraints, called \textit{secondary constraints}:
\begin{align}\label{eq:5}
0 = \dot{\phi}_1 = \left \{ \phi_1,H \right \} + \sum_{m=1}^M u_m  \left \{ \phi_1,\phi_m \right \} = \left \{ \phi_1,H \right \} = \chi(q,p).
\end{align}
They differ from the primary constraints in the fact that the primary constraints are merely a consequence of the definition of the generalized momenta, while for the secondary constraints, one has to make use of the Lagrangian equations of motion as well. \\
If we have a secondary constraint, then we get another consistency condition because we can work out again $\dot{\chi}$ according to the equation of motion and require that $\dot{\chi} = 0$. This equation has to be treated on the same footing as \eqref{eq:4}. One must again see to which case it leads. If it leads to another secondary constraint, we have to push the process one stage further and check the consistency condition again. \\
We carry on like that until we have exhausted all the consistency conditions, and the final result will be that we are left with a number of secondary constraints together with a number of conditions on the functions $u_m$. The process \footnote{It should be mentioned that it is a controversial topic whether every new constraint should be added to the total Hamiltonian with an undetermined function after each step or not. It only makes a difference when we generate second-class constraints during our procedure. For the most cases, Dirac's procedure (without adding the secondary constraints to the Hamiltonian) works out and leads to the right physics. If one has second-class constraints, one should pay attention and ponder what to do. There are even examples where adding secondary constraints to the Hamiltonian leads to wrong results. That's why we will stick to Dirac and describe his method.} is described in detail by Dirac in his lectures on quantum mechanics \cite{1}. \\

Let's take a closer look on the secondary constraints now. Since they are treated for many purposes like primary constraints, we will denote them like
\begin{align}
\phi_{M+1}(q_i,p_i), ... , \phi_J(q_i,p_i)
\end{align}
and require now
\begin{align}\label{eq:6}
\dot{\phi}_j = \left \{ \phi_j,H \right \} + \sum_{m=1}^M u_m  \left \{ \phi_j,\phi_m \right \} = 0,
\end{align}
for $j=1,...,M,M+1,...,J$. These are a number of non-homogeneous linear equations for the unknown functions $u_m$. Let us investigate the solvability of this system. Suppose that we are at the beginning of our procedure and have no secondary constraints yet. Then we can introduce the matrix $\hat{a}$ with components
\begin{align}
a_{jm} = \left \{ \phi_j,\phi_m \right \}, \ \ j,m = 1, \dots, M.
\end{align}
With equation \eqref{eq:6} it follows that
\begin{align}
\sum_{m=1}^M a_{jm} u_m = b_j = - \left \{ \phi_j,H \right \},
\end{align}
which expresses the linear equation system in matrix form. Since the rank of this matrix can be between 0 and $M$:
\begin{align}
0 \leq \text{rank} (\hat{a}) \leq M,
\end{align}
there are two options for solutions of this system.

\pagebreak

\begin{enumerate}
\item If the rank of the $M \times M$ matrix is maximal, then one has a minimal system of $M$ equations with $M$ variables.
There exists a unique solution
\begin{align}
u_m = U_m(q_i,p_i).
\end{align}
\item If the rank of the $M \times M$ matrix is $\leq M-1$, then there exist eigenvectors
\begin{align}\label{eq:7}
u_m = U_m(q_i,p_i) + \sum_{a=1}^A v_a(q_i,p_i) V_m^{(a)}(q_i,p_i),
\end{align}
where $A = M - \text{rank} (\hat{a})$ with arbitrary coefficients $v_a$ and any solution $V_m^{(a)}(q_i,p_i)$ of the homogeneous equations. They satisfy
\begin{align}
\sum_{m=1}^M a_{jm} U_m = b_j \ \ \ \text{and} \ \ \ \sum_{m=1}^M a_{jm} V_m^{(a)} = 0.
\end{align}
The solution is not unique.
\end{enumerate}

Inserting \eqref{eq:7} in the total Hamiltonian, we get
\begin{align}\label{eq:8}
H_T(q_i,p_i) &= H + \sum_{m=1}^M U_m \phi_m + \sum_{a=1}^A v_a \left( \sum_{m=1}^M V_m^{(a)} \phi_m \right) \notag \\
&= H' + \sum_{a=1}^A v_a \tilde{\phi}_a.
\end{align}
Depending on how much the rank of the matrix $\hat{a}$ is smaller than $M$, we are left with $A = M - \text{rank} (\hat{a})$ constraints. So after the procedure, we can find some unknown functions $u_m$ and reduce their degree of freedom in some cases. The general rules are:
\begin{enumerate}
\item If the $u$'s vanish $\longrightarrow$ introduce secondary constraints
\item If not $\longrightarrow$ find conditions on the $u$'s and reduce their degree of freedom.
\end{enumerate}

For the following analysis, we introduce a useful terminology:
\begin{definition}[First-class quantity]
A quantity $R(q_i,p_i)$ is first-class, if it has zero Poisson brackets with all the $\phi$'s:
\begin{align}
\left \{ R,\phi_j \right \} = \sum_{j' = 1}^J r_{j j'} \phi_{j'} \approx 0,
\end{align}
where $j = 1, ... , J$. Otherwise, $R$ is second-class.
\end{definition}
It is important to find all constraints first and then talk about what is first-class and second-class. The following theorem shows a nice property of first-class quantities.

\pagebreak

\begin{theorem}
The Poisson bracket of two first-class quantities is also first-class.
\end{theorem}
\begin{proof}
Let $R,S$ be first-class. Then we have
\begin{align}
\left \{ R,\phi_j \right \} &= \sum_{j' = 1}^J r_{j j'} \phi_{j'} \approx 0 \\
\left \{ S,\phi_j \right \} &= \sum_{j' = 1}^J s_{j j'} \phi_{j'} \approx 0.
\end{align}
Using the Jacobi identity and the Einstein summation convention, we have
\begin{align}
\left \{ \left \{ R,S \right \},\phi_j \right \} &= \left \{ \left \{ R,\phi_j \right \},S \right \} - \left \{ \left \{ S,\phi_j \right \},R \right \} \notag \\
&= \left \{ r_{j j'} \phi_{j'},S \right \} - \left \{ s_{j j'} \phi_{j'},R \right \} \notag \\
&= r_{j j'} \left \{ \phi_{j'},S \right \} + \left \{ r_{j j'},S \right \} \phi_{j'} - s_{j j'} \left \{ \phi_{j'},R \right \} - \left \{ s_{j j'},R \right \} \phi_{j'} \notag \\
&\approx 0.
\end{align}
\end{proof}

It turns out that our Hamiltonian in equation \eqref{eq:8} is first-class. To see this, check that every term is first-class:
\begin{itemize}
\item \(
\begin{aligned}[t]
\left \{ H',\phi_j \right \} &= \left \{ H + \sum_{m=1}^M U_m \phi_m ,\phi_j \right \} \approx  \left \{ H ,\phi_j \right \} + \sum_{m=1}^M U_m \left \{ \phi_m ,\phi_j \right \} \notag \\
&= b_j - \sum_{m=1}^M a_{jm} U_m = b_j - b_j = 0.
\end{aligned} \)
\item \(
\begin{aligned}[t]
\left \{ v_a \tilde{\phi}_a,\phi_j \right \} \approx v_a \left \{\tilde{\phi}_a,\phi_j \right \} = v_a \sum_{m=1}^M V_m^{(a)} \left \{ \phi_m ,\phi_j \right \} = - v_a \sum_{m=1}^M a_{jm} V_m^{(a)} = 0.
\end{aligned} \)
\end{itemize}

\section{Examples}

Now, we present two typical exersices. Consider the Lagrangian
\begin{align}
L = \frac{1}{2} \left[ \left( \frac{d}{dt} - y \right) x \right]^2 = \frac{1}{2} \left(\dot{x} - xy \right)^2.
\end{align}
First, calculate the conjugate momentum:
\begin{align}
p_x &= \frac{\partial L}{\partial \dot{x}} = \dot{x} - xy \\
p_y &= \frac{\partial L}{\partial \dot{y}} = 0.
\end{align}
From here, we get our first constraint: $\phi_1 = p_y = 0$. \\

The Hamiltonian is given by
\begin{align}
H &= \dot{x} p_x + \dot{y} p_y - \frac{1}{2} \left(\dot{x} - xy \right)^2 \notag \\
&= (p_x + xy)p_x - \frac{1}{2} p_x^2 \notag \\
&= \frac{1}{2} p_x^2 + xy p_x.
\end{align}
But it is not unique. The full Hamiltonian is
\begin{align}
H_T = H + u(x,p_x,y,p_y) \phi_1.
\end{align}
In the following, we will write $u = u(x,p_x,y,p_y)$ but keep in mind that it depends on all these variables. We get the equation of motion by
\begin{align}
\dot{g} = \left \{ g,H \right \} + u \left \{ g,\phi_1 \right \}.
\end{align}
We notice that
\begin{align}
0 = \dot{\phi}_1 = \left \{ \phi_1,H \right \} + u \left \{ \phi_1,\phi_1 \right \} = \left \{ p_y,\frac{1}{2} p_x^2 + xy p_x \right \} = \left \{ p_y,y \right \} x p_x = - x p_x.
\end{align}
Which leads to a secondary constraint:
\begin{align}
\left.
\begin{array}{llll}
      \text{Either:} & x = 0 & \Rightarrow &  p_x = 0 \\
      \text{Or:} & p_x = 0
\end{array}
\right \} \Longrightarrow \phi_2 = p_x = 0.
\end{align}
Let's check whether it satisfies the condition that we required for a constraint:
\begin{align}
0 \overset{?}{=} \dot{\phi}_2 = \left \{ \phi_2,H \right \} + u \left \{ \phi_2,\phi_1 \right \} = \left \{ p_x,\frac{1}{2} p_x^2 + xy p_x \right \} = \left \{ p_x,x \right \} y p_x = - y p_x \approx 0.
\end{align}
So it is consistent and we get no more constraints. We can also check that $\phi_1, \phi_2$ and $H$ are first-class. We show it only for $H$:
\begin{align}
\left \{ H,\phi_1 \right \} &= \left \{ \frac{1}{2} p_x^2 + xyp_x, p_x \right \} = y p_x \approx 0 \\
\left \{ H,\phi_2 \right \} &= \left \{ \frac{1}{2} p_x^2 + xyp_x, p_y \right \} = x p_x \approx 0.
\end{align}

Another example which is quite similar to string theory, is the following.
\begin{align}
L = q_1 q_2 (\dot{q}_1 + \dot{q}_2).
\end{align}
Following the procedure, we get two primary constraints:
\begin{align}
p_1 &= \frac{\partial L}{\partial \dot{q}_1} = q_1 q_2 \ \ \ \Longrightarrow \ \ \ \phi_1 = p_1 - q_1 q_2 = 0. \\
p_2 &= \frac{\partial L}{\partial \dot{q}_2} = q_1 q_2 \ \ \ \Longrightarrow \ \ \ \phi_2 = p_2 - q_1 q_2 = 0.
\end{align}
The Hamiltonian is
\begin{align}
H = \dot{q}_1 p_1 + \dot{q}_2 p_2 - q_1 q_2 (\dot{q}_1 + \dot{q}_2) = 0.
\end{align}
At this point, it is useful to notice the following theorem. \\

\begin{theorem}
\label{Theorem}
If the Lagrangian $L$ is homogeneous of degree $1$ in the velocities
\begin{align}
L(q_i,\lambda \dot{q}_i) = \lambda L(q_i,\dot{q}_i), \label{eq:9}
\end{align}
then $H(q_i,p_i) = 0$.
\end{theorem}
\begin{proof}
The proof of this theorem is analog to the proof of Euler's homogeneous function theorem.
Differentiating both sides of equation \eqref{eq:9} with respect to $\lambda$ yields
\begin{align}
L(q_i,\dot{q}_i) = \frac{\partial L(q_i,\lambda \dot{q}_i)}{\partial \lambda} = \sum_k \dot{q}_k \frac{\partial L(q_i,\lambda \dot{q}_i)}{\partial (\lambda \dot{q}_k)} .
\end{align}
By setting $\lambda = 1$, we obtain
\begin{align}
\sum_k \dot{q}_k \frac{\partial L(q_i,\dot{q}_i)}{\partial \dot{q}_k} - L(q_i,\dot{q}_i) = H(q_i,p_i) = 0.
\end{align}
\end{proof}

So we didn't even have to calculate the Hamiltonian because our Lagrangian is homogeneous of degree $1$. \\

The total Hamiltonian is
\begin{align}
H_T = 0 + u_1 \phi_1 + u_2 \phi_2
\end{align}
and the equation of motion is
\begin{align}
\dot{g} = u_1 \left \{ g, \phi_1 \right \} + u_2 \left \{ g, \phi_2 \right \}.
\end{align}

With the identity $\{ q_i, p_k \} = \delta_{ik}$, we get $\{ \phi_1 , \phi_2 \} = q_2 - q_1$ and obtain a new (secondary) constraints out of the requirement that
\begin{align}
0 \overset{!}{=} \dot{\phi}_1 &= u_1 \left \{ \phi_1, \phi_1 \right \} + u_2 \left \{ \phi_1, \phi_2 \right \} = u_2 (q_2 - q_1) \\
0 \overset{!}{=} \dot{\phi}_2 &= u_1 \left \{ \phi_2, \phi_1 \right \} + u_2 \left \{ \phi_2, \phi_2 \right \} = u_1 (q_1 - q_2).
\end{align}
\textit{First case $\phi_3 = q_1 - q_2 = 0$.} \\
We have to check that this constraint fulfills our requirement too:
\begin{align}
0 \overset{!}{=} \dot{\phi}_3 &= u_1 \left \{ \phi_3, \phi_1 \right \} + u_2 \left \{ \phi_3, \phi_2 \right \} = u_1 - u_2.
\end{align}
This is just an additional condition on the functions $u_1$ and $u_2$, saying that $u_1 = u_2 = v$. \\

The total Hamiltonian is therefore
\begin{equation}
H_T = v ( \phi_1 + \phi_2 ).
\end{equation}
Now, we want to see whether the Hamiltonian is first-class or second-class. But have we found already all constraints? There is a theorem saying that there is always an even number of second-class constraints, if one cannot combine all secondary constraints to get a new primary constraint. We will proof it later but for now, in our case, we only have one secondary constraint, so we have to find more constraints by combining the old ones:
\begin{align}
\tilde{\phi}_1 &= \phi_1 + \phi_2 = 0 \\
\tilde{\phi}_2 &= \phi_1 - \phi_2 = 0.
\end{align}
And now check which of them are first-class or second-class:
\begin{itemize}
\item \(
\begin{aligned}[t]
\left \{ \tilde{\phi}_1,\tilde{\phi}_2 \right \} = \left \{ p_1 + p_2 - 2 q_1 q_2, p_1 - p_2 \right \} = 2 (q_1 - q_2) = 0.
\end{aligned} \)
\item \(
\begin{aligned}[t]
\left \{ \tilde{\phi}_1,\phi_3 \right \} = \left \{ p_1 + p_2 - 2 q_1 q_2, q_1 - q_2 \right \} = -1 + 1 = 0.
\end{aligned} \)
\item \(
\begin{aligned}[t]
\left \{ \tilde{\phi}_2,\phi_3 \right \} = \left \{ p_1 - p_2, q_1 - q_2 \right \} = -2.
\end{aligned} \)
\end{itemize}
So $\tilde{\phi}_1$, and therefore our Hamiltonian, is first-class and $\tilde{\phi}_2,\phi_3$ are second-class like we expected. We notice:
\begin{definition}
True secondary constraints are secondary constraints which one cannot combine to first-class quantities.
\end{definition}

\textit{Second case $q_1 \neq q_2 \Longrightarrow u_1 = u_2 = 0$.} \\
And the total Hamiltonian is zero.

\section{Gauge Transformations}
In this section, we will see the meaning of the arbitrary coefficients in the total Hamiltonian \eqref{eq:8}.
With the equation of motion, one can express little changes in the function $g$:
\begin{align}\label{eq:10}
\frac{\Delta g}{\Delta t} = \dot{g} = \left \{ g,H' \right \} + \sum_{a=1}^A v_a \left \{ g,\tilde{\phi}_a \right \}.
\end{align}
Since the $v_a$ are arbitrary, there are many possible results for $\Delta g$. The situation is illustrated in Fig.~\ref{fig:2}.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=1.4]{img/gauge1.pdf}
\end{center}
\caption{Evolution of the observable $g$ in phase space.}
\label{fig:2}
\end{figure}

The time evolution of the observable $g$ for small intervals $\Delta t$ can be estimated as
\begin{align}
g(t + \Delta t) = g_0 + \Delta g,
\end{align}
where $\Delta g$ is given by equation \eqref{eq:10}:
\begin{align}
\Delta g = \left \{ g,H' \right \} \Delta t + \sum_{a=1}^A \left( v_a \Delta t \right) \left \{ g,\tilde{\phi}_a \right \}.
\end{align}

Let's choose two different $v_a^{(1)}$ and $v_a^{(2)}$ with which we land eather on $g_1$ or $g_2$, the corresponding change $\Delta g_i$ can be written as:
\begin{align}
\Delta g_1 &= \left \{ g,H' \right \} \Delta t + \sum_{a=1}^A \left( v_a^{(1)} \Delta t \right) \left \{ g,\tilde{\phi}_a \right \} \\
\Delta g_2 &= \left \{ g,H' \right \} \Delta t + \sum_{a=1}^A \left( v_a^{(2)} \Delta t \right) \left \{ g,\tilde{\phi}_a \right \}.
\end{align}

Different functions $v_a^{(i)}$ lead to different results $\Delta g_i$. This means that $g(t + \Delta t)$ is not well defined and depends on the functions $v_a^{(i)}$. The key to the solution of this problem is to say that all \textit{mathematical states} $g_i$ correspond to the same \textit{physical state} $g(t + \Delta t)$. Like in electrodynamics, where $\vec{A} \longrightarrow \vec{A}' = \vec{A} + \nabla f$ leaves the magnetic field unchanged. \\

The transformation which leads from $g_1$ to $g_2$ is called a \textit{gauge transformation}:
\begin{align}
g_1 \longrightarrow g_2 =  g_1 + \delta g.
\end{align}

Let us calculate the explicit form of $\delta g$:
\begin{align}
\delta g = \Delta g_2 - \Delta g_1 = \sum_{a=1}^A \left( v_a^{(2)} - v_a^{(1)} \right) \Delta t \left \{ g,\tilde{\phi}_a \right \} \equiv \sum_{a=1}^A \varepsilon_a \left \{ g,\tilde{\phi}_a \right \},
\end{align}
where $\varepsilon_a$ is a small, arbitrary parameter since $\Delta t$ is small.
\label{sec:gauge_transformations}
We see that this \textit{infinitesimal} change can be expressed as the Poisson bracket of $g$ with the primary constraints. We therefore say that primary constraints are generators of \textit{infinitesimal} gauge transforations. \\
More exactly, the first-class primary constraints are generators of gauge transformation since we started with a first-class total Hamiltonian. Later, we will learn more about the role of first-class quantities for gauge transformations. \\

Before continuing, we would like to illustrate gauge transformations with the following example.
Consider the Lagrangian
\begin{align}
L = \frac{1}{2} (x \dot{x} + y \dot{y})^2.
\end{align}
The definition of the generalized momentum
\begin{align}
p_x &= \frac{\partial L}{\partial \dot{x}} =  x (x \dot{x} + y \dot{y}) \\
p_y &= \frac{\partial L}{\partial \dot{y}} = y (x \dot{x} + y \dot{y})
\end{align}
leads to the primary constraint
\begin{align}
\phi_1 = p_x y - p_y x = 0.
\end{align}
So again, the Hamiltonian is not unique:
\begin{align}
H &= \dot{x} p_x + \dot{y} p_y - \frac{1}{2} (x \dot{x} + y \dot{y})^2 \notag \\
&= x \dot{x} (x \dot{x} + y \dot{y}) + y \dot{y} (x \dot{x} + y \dot{y}) - \frac{1}{2} (x \dot{x} + y \dot{y})^2 \notag \\
&= (x \dot{x} + y \dot{y})^2 - \frac{1}{2} (x \dot{x} + y \dot{y})^2 \notag \\
&= \frac{1}{2} (x \dot{x} + y \dot{y})^2  \notag \\
&= \frac{p_x^2}{2 x^2} = \frac{p_y^2}{2 y^2} = \frac{p_x p_y}{2 x y}.
\end{align}
We therefore build the total Hamiltonian
\begin{align}
H_T = \frac{p_x^2}{2 x^2} + u_1 (p_x y - p_y x),
\end{align}
where the arbitrariness lies completely in the function $u_1$ now. By choosing $u_1$, one can change between the different variants. The equation of motion is given by
\begin{align}
\dot{g} = \left \{ g,H \right \} + u_1 \left \{ g,\phi_1 \right \}.
\end{align}
Let's check whether the consistency condition holds:
\begin{align}
0 = \dot{\phi}_1 &= \left \{ \phi_1,H \right \} + u_1 \left \{ \phi_1,\phi_1 \right \} = \left \{ p_x y - p_y x,\frac{p_x^2}{2 x^2} \right \} \notag \\
&= \frac{p_x^2 y}{2} \left \{ p_x,\frac{1}{x^2} \right \} - \frac{p_y}{2 x^2} \left \{ x,p_x^2 \right \} \notag \\
&= \frac{p_x^2 y}{2} \left(-(-2) \frac{1}{x^3}\right) - \frac{p_y}{2 x^2} 2 p_x \notag \\
&= \frac{p_x (p_x y - p_y x)}{x^3} \notag \\
&= \frac{p_x \phi_1}{x^3} \approx 0. \ \ \ \surd
\end{align}
So $u_1$ remains arbitrary and we have no secondary constraints. It follows that $\phi_1 = \phi$ is first-class (which is always the case when we only have one constraint) and act as a generator of gauge transformations:
\begin{align}
\Delta g = \varepsilon \left \{ g,\phi \right \}.
\end{align}
Let us insert $\phi$ and see which transformations don't change the physical state of the observables:
\begin{itemize}
\item $\Delta x = \varepsilon \left \{ x,\phi \right \} = \varepsilon \left \{ x,p_x y - p_y x \right \}= \varepsilon y$
\item $\Delta y = \varepsilon \left \{ y,\phi \right \} = - \varepsilon x$
\item $\Delta p_x = \varepsilon \left \{ p_x,\phi \right \} = \varepsilon p_y$
\item $\Delta p_y = \varepsilon \left \{ p_y,\phi \right \} = - \varepsilon p_x$.
\end{itemize}
These transformations do look like the infinitesimal version of rotations in $2$ dimensional space. So let us work out the connection. We will show it for the space part and the momentum is completely analogous.
The equations
\begin{align}
x' &= x + \varepsilon y \\
y' &= y - \varepsilon x
\end{align}
can be written in matrix form like
\begin{align}
\bar{r} \ ' = \bar{r} + \varepsilon \hat{\omega} \bar{r},
\end{align}
where
\begin{align}
\bar{r} =
\begin{pmatrix}
    x \\
    y
\end{pmatrix} \ \ \ \text{and} \ \ \
\hat{\omega} =
\begin{pmatrix}
    0 & 1 \\
    -1 & 0
\end{pmatrix}.
\end{align}
It follows that
\begin{align}
\Delta \bar{r} = \varepsilon \hat{\omega} \bar{r}.
\end{align}
Redefine the small parameter $\varepsilon \longrightarrow \Delta \alpha$ and solve the differential equation:
\begin{align}
\frac{\Delta \bar{r}}{\Delta \alpha} = \hat{\omega} \bar{r} \ \ \Longrightarrow \ \ \bar{r}(\alpha) = \exp(\hat{\omega} \alpha) \bar{r}(0).
\end{align}
To get a better feeling for what this means, we expand the solution into the Taylor series and note that
\begin{align}
\hat{\omega} =
\begin{pmatrix}
    0 & 1 \\
    -1 & 0
\end{pmatrix}, \ \
\hat{\omega}^2 = - I, \ \
\hat{\omega}^3 = - \hat{\omega}, \ \
\hat{\omega}^4 = I, \ \
\hat{\omega}^5 = \hat{\omega}, \ \dots .
\end{align}
So
\begin{align}
\bar{r}(\alpha) &= \left( I + \alpha \hat{\omega} + \frac{\alpha^2 \hat{\omega}^2}{2} + \frac{\alpha^3 \hat{\omega}^3}{3 !} + \frac{\alpha^4 \hat{\omega}^4}{4 !} + \dots  \right) \bar{r}(0) \notag \\
&= \Bigg [  \Big ( \underbrace{1 - \frac{\alpha^2}{2} + \frac{\alpha^4}{4 !} - \dots}_{\Large = \ \cos \alpha} \Big ) I + \Big ( \underbrace{\alpha - \frac{\alpha^3}{3 !} + \frac{\alpha^5}{5 !} - \dots}_{\Large = \ \sin \alpha} \Big ) \hat{\omega} \Bigg ] \bar{r}(0) .
\end{align}
\begin{align}
\Longrightarrow \
\begin{pmatrix}
    x' \\
    y'
\end{pmatrix} =
\begin{pmatrix}
    \cos \alpha & \sin \alpha \\
    - \sin \alpha & \cos \alpha
\end{pmatrix}
\begin{pmatrix}
    x \\
    y
\end{pmatrix}.
\end{align}
So our suggestion was right, the gauge transformations are really rotations.
We can illustrate this as follows:
\begin{figure}[H]
\begin{center}
\includegraphics[scale=1.4]{img/rotation.pdf}
\end{center}
\caption{Rotations as gauge transformations.}
\label{fig:3}
\end{figure}
So the quantity
\begin{align}
R = x^2 + y^2
\end{align}
will not change under these gauge transformations. To see this, notice that
\begin{align}
\delta R = \varepsilon \left \{ x^2 + y^2 , \phi \right \} = \varepsilon \left \{ x^2 + y^2 , p_x y - p_y x \right \} = \varepsilon (2xy - 2yx) = 0.
\end{align}

With a bit of imagination, one could see this faster. The Lagrangian depends only on the radius $R$, not the angle:
\begin{align}
L = \frac{1}{2} (x \dot{x} + y \dot{y})^2 = \frac{1}{8} \left( \frac{d}{dt} (x^2 + y^2) \right)^2 = \frac{1}{8} \left( \frac{d R^2}{dt} \right)^2 = \frac{1}{8} (2 R \dot{R})^2 = \frac{1}{2} R^2 \dot{R}^2.
\end{align}

\label{sec:finite_gauge_transformations}
How to get from infinitesimal transformations to finite transformations in general? \\

We claim that
\begin{align}
g(\alpha) = \sum_{n=0}^{\infty} \frac{\alpha^n}{n !} \underbrace{\Large \{ \dots \left \{ \left \{ g_0 , \phi \right \} , \phi \right \} \dots \ , \phi \Large \}}_{n \ \text{times}}
\end{align}
is the general solution.
\begin{proof}
\begin{align}
\frac{d g}{d \alpha} &= \sum_{n=1}^{\infty} \frac{\alpha^{n-1}}{(n-1) !} \underbrace{\Large \{ \dots \left \{ \left \{ g_0 , \phi \right \} , \phi \right \} \dots \ , \phi \Large \}}_{n \ \text{times}} \notag \\
&= \sum_{\bar{n}=0}^{\infty} \frac{\alpha^{\bar{n}}}{\bar{n} !} \underbrace{\Large \{ \dots \left \{ \left \{ g_0 , \phi \right \} , \phi \right \} \dots \ , \phi \Large \}}_{\bar{n} + 1 \ \text{times}} \notag \\
&= \left \{ g , \phi \right \}.
\end{align}
\end{proof}
So, one gets the full transformation out of the constraint $\phi$ by
\begin{align}\label{eq:11}
g(\alpha) = g_0 + \alpha \left\{ g_0 , \phi \right \} + \frac{\alpha^2}{2} \left \{ \left \{ g_0 , \phi \right \} , \phi \right \} + \dots \ .
\end{align}
With this method we can again derive the same result of the last example:
\begin{itemize}
\item $\left\{ x , \phi \right \} = y$
\item $\left \{ \left\{ x , \phi \right \} , \phi \right \} = \left\{ y , \phi \right \} = - x$
\item $\left \{ \left \{ \left\{ x , \phi \right \} , \phi \right \} , \phi \right \} = \left\{ -x , \phi \right \} = - y$
\item $\left \{ \left \{ \left \{ \left\{ x , \phi \right \} , \phi \right \}, \phi \right \}, \phi \right \} = \left\{ -y , \phi \right \} = x$.
\end{itemize}
So we see that
\begin{align}
x(\alpha) &= \sum_{n=0}^{\infty} \frac{\alpha^n}{n !} \Large \{ \dots \left \{ \left \{ x , \phi \right \} , \phi \right \} \dots \ , \phi \Large \} \notag \\
&= \left( x + \frac{\alpha^2}{2} (-x) + \frac{\alpha^4}{4 !} (x) + \dots \right) + \left( \alpha y + \frac{\alpha^3}{3 !} (-y) + \frac{\alpha^5}{5 !} (y) + \dots \right) \notag \\
&= x \cos \alpha + y \sin \alpha.
\end{align}

\pagebreak

\textbf{General Case} \\

We already know that first-class primary constraints generate gauge transformations, but what about secondary constraints? Will they also be first-class and generate gauge transformations?
Dirac could not show this in general but for all physical situations.

\begin{proof}
Let $\phi_1$ and $\phi_2$ be two constraints.
\begin{figure}[H]
\begin{center}
\includegraphics[scale=1.2]{img/gauge2.pdf}
\end{center}
\caption{Different constraints generate different transformations.}
\label{fig:4}
\end{figure}
First, we want to show that transformations between $g_{12}$ and $g_{21}$ are generated by $\left\{ \phi_1 , \phi_2 \right \}$.
We use equation \eqref{eq:11} to the second order to get
\begin{itemize}
\item $g_1 = g_0 + \alpha \left\{ g_0 , \phi_1 \right \} + \frac{\alpha^2}{2} \left \{ \left \{ g_0 , \phi_1 \right \} , \phi_1 \right \} $
\item $g_{12} = g_1 + \beta \left\{ g_1 , \phi_2 \right \} + \frac{\beta^2}{2} \left \{ \left \{ g_1 , \phi_2 \right \} , \phi_2 \right \}  $
\item $g_2 = g_0 + \beta \left\{ g_0 , \phi_2 \right \} + \frac{\beta^2}{2} \left \{ \left \{ g_0 , \phi_2 \right \} , \phi_2 \right \} $
\item $g_{21} = g_2 + \alpha \left\{ g_2 , \phi_1 \right \} + \frac{\alpha^2}{2} \left \{ \left \{ g_2 , \phi_1 \right \} , \phi_1 \right \} .$
\end{itemize}
So
\begin{align}
\Delta g = g_{12} - g_{21} = \dots  = \alpha \beta \left \{ g_0 , \left \{ \phi_1 , \phi_2 \right \} \right \}.
\end{align}
When secondary constraints are first-class then this works out and $\left \{ \phi_1 , \phi_2 \right \}$ is a generator.

\pagebreak

Now, we want to show that $\left\{ H , \phi_a \right \}$ is also a generator of gauge transformations.

\begin{figure}[H]
\begin{center}
\includegraphics[scale=1.1]{img/gauge3.pdf}
\end{center}
\caption{Physical and mathematical changes of the quantity $g_0$.}
\label{fig:5}
\end{figure}
Consider again
\begin{align}
\frac{\Delta g}{\Delta t} = \left\{ g , H' \right \} + \sum_{a=1}^A v_a \left\{ g , \phi_a \right \}.
\end{align}
We can analyse which part is responsible for which action:
\begin{align}
g' = g(t + \Delta t) = g_0 + \underbrace{\left\{ g_0 , H' \right \} \Delta t}_{\begin{subarray}{l}\text{corresponds to a}\\ \text{physical change}\\
    \text{from layer \ $t \ \rightarrow \ t + \Delta t$.}\end{subarray}}
+ \underbrace{\sum_{a=1}^A \varepsilon_a \left\{ g_0 , \phi_a \right \}}_{\begin{subarray}{2}\text{corresponds to a shift}\\
    \text{within a layer of constant time,}\\
    \text{not physical change.}\end{subarray}}.
\end{align}
Performing a gauge transformation on $g'$ yields:
\begin{align}
g'' = g' + \varepsilon_a \left\{ g' , \phi_a \right \} = g_0 + \left\{ g_0 , H' \right \} \Delta t + 2 \varepsilon_a \left\{ g_0 , \phi_a \right \} + \varepsilon_a \left\{ \left\{ g_0 , H' \right \} \Delta t, \phi_a \right\}.
\end{align}
Now, perform a gauge transformation first
\begin{align}
g_0' = g_0 + \varepsilon_a \left\{ g_0 , \phi_a \right \}
\end{align}
and then calculate the physical change
\begin{align}
g_0'' &= g_0' + \left\{ g_0' , H' \right \} \Delta t + \varepsilon_a \left\{ g_0' , \phi_a \right \} \notag \\
&= g_0 + \left\{ g_0 , H' \right \} \Delta t + 2 \varepsilon_a \left\{ g_0 , \phi_a \right \} + \varepsilon_a \left\{ \left\{ g_0 , \phi_a \right \} , H' \right \} \Delta t.
\end{align}
The difference is
\begin{align}
\Delta g = g'' - g_0'' &= \varepsilon_a  \left\{ \left\{ g_0 , H' \right \} , \phi_a \right \} \Delta t - \varepsilon_a  \left\{ \left\{ g_0 , \phi_a \right \} , H' \right \} \Delta t \notag \\
&= \varepsilon_a \left\{ g_0 ,  \left\{  H' , \phi_a \right \} \right \} \Delta t ,
\end{align}
which shows that $\left\{  H' , \phi_a \right \}$ is a generator. Both $H'$ and $\phi_a$ are first-class.
\end{proof}

Now that we showed that all first-class quantities generate some kind of gauge transformations, it is reasonable to introduce the following definitions:
\begin{definition}[Total Hamiltonian]
\begin{align}
H_T = H + \sum {\begin{subarray}{l}\text{primary constraints}\\ \text{(first-class)}\end{subarray}}.
\end{align}
\end{definition}

\begin{definition}[Generalized Hamiltonian]
\begin{align}
H_E = H_T + \sum {\begin{subarray}{l}\text{secondary constraints}\\ \text{(first-class)}\end{subarray}}.
\end{align}
\end{definition}

The following example shows a case where all constraints are first-class:
\begin{example}
\begin{align}
L = \frac{1}{2} (\dot{x} - xy)^2
\end{align}
From the definition of the generalized momentum we get the primary constraint
\begin{align}
\phi_1 = p_y = 0
\end{align}
and a secondary constraint from the consistency condition:
\begin{align}
0 = \dot{\phi}_1 \ \ \ \Longrightarrow \ \ \ \phi_2 = p_x = 0.
\end{align}
There are no more constraints. Since both constraints are first-class, we can write the generalized Hamiltonian
\begin{align}
H_E &= \frac{p_x^2}{2} + xy p_x + v p_y + V p_x \notag \\
&= v p_y + \tilde{V} p_x.
\end{align}
The first constraint $\phi_1 = p_y = 0$ lead to gauge transformations of the form
\begin{align}
\delta y = \varepsilon_1 \left \{ y, p_y \right \} = \varepsilon_1 \\
y \ \longrightarrow \ y' = y + \varepsilon_1
\end{align}
and the second constraint $\phi_2 = p_x = 0$ analogous
\begin{align}
\delta x = \varepsilon_2 \left \{ x, p_x \right \} = \varepsilon_2 \\
x \ \longrightarrow \ x' = x + \varepsilon_2.
\end{align}
\end{example}

\pagebreak

\section{Quantization}

In this section we want to discuss which problems can occur when we try to quantize a Hamiltonian system with constraints.
We will focus on the canonical quantization where we replace every physical observable with an operator and change the Poisson bracket into the commutator:

\begin{align}
q_i \ \longrightarrow \ \hat{q}_i \ \ \ , \ \ \ p_i \ \longrightarrow \ \hat{p}_i.
\end{align}
\begin{align}
\left \{ q_i , p_k \right \} = \delta_{ik} \ \ \longrightarrow \ \ \frac{1}{i \hbar} \left[ \hat{q}_i ,\hat{p}_k \right] = \delta_{ik}.
\end{align}
\begin{align}
\forall g \rightarrow \hat{g} : \ \ \frac{d}{dt} \hat{g} = \frac{1}{i \hbar} \left[ \hat{g} ,\hat{H} \right]  \ \ \Longrightarrow \ \ \hat{H} \psi(q_1, \dots, q_n) = E \psi(q_1, \dots, q_n).
\end{align}

What happens with the constraints?

They are also replaced by operators and if we act on a wavefunction $\psi$, they will vanish since they vanish on the constraint surface. For first-class constraints this leads to the vanishing of the commutator on the constraint surface:
\begin{align}
\left.
\begin{array}{l}
\hat{\phi}_b \hat{\phi}_a \psi(q_1, \dots, q_n) = 0 \\
\hat{\phi}_a \hat{\phi}_b \psi(q_1, \dots, q_n) = 0
\end{array} \ \right \} \ \
\Longrightarrow \ \ \left[ \hat{\phi}_a ,\hat{\phi}_b \right] \psi = 0.
\end{align}
So for first-class constraints, we can make the transition
\begin{align}
\left \{ \phi_a ,\phi_b \right \} = 0 \ \ \longrightarrow \ \ \left[ \hat{\phi}_a ,\hat{\phi}_b \right] = 0
\end{align}
without problems.
But if we have second-class constraints, for instance
\begin{align}
\left.
\begin{array}{l}
\chi_1 = q_1 = 0 \\
\chi_2 = p_1 = 0
\end{array} \ \right \} \ \
\Longrightarrow \ \ \left \{ \chi_1 ,\chi_2 \right \} = 1,
\end{align}
it won't work that way and will lead to contradictions:
\begin{align}
\left.
\begin{array}{l}
\hat{p}_1 \hat{q}_1 \psi(q_1, \dots, q_n) = 0 \\
\hat{q}_1 \hat{p}_1 \psi(q_1, \dots, q_n) = 0
\end{array} \ \right \} \ \
\Longrightarrow \ \ \underbrace{\left[ \hat{q}_1 ,\hat{p}_1 \right]}_{= i \hbar} \psi = 0 \ \ \Longrightarrow \ \ \psi = 0.
\end{align}

We can do calculations with the commutator of first-class constraints but not of second-class constraints.
\begin{align}
H_E = H' + \underbrace{\sum_{a=1}^A v_a \  \tilde{\phi}_a}_{\begin{subarray}{l}\text{primary constraints}\\ \text{(first-class)}\end{subarray}} + \underbrace{\sum v_b \ \tilde{\tilde{\phi}}_b}_{\begin{subarray}{l}\text{secondary constraints}\\ \text{(first-class)}\end{subarray}}.
\end{align}
First-class constraints are generators of gauge transforations and don't change the physical state.
The commutator shows that they are problems with second-class constraints. Let us see how to quantize a Hamiltonian system with second-class constraints.

\pagebreak

First, we will show that there is always an even number of true second-class constraints (which one cannot combine to first-class constraints). This is good, since every two second-class constraints will lead to a reduction of one degree of freedom.
Mathematically, we will replace the Poisson bracket with the Dirac bracket (which is a generalized Poisson bracket) to fix the problem of second-class constraints.

\label{sec:number_secondary_constraints}
\begin{theorem}
Let $\chi_1, \chi_2, \dots, \chi_S$ be true second-class constraints. Then $S$ is even.
\end{theorem}
%komischer abstand hier ...
\begin{proof}
Introduce the  matrix
\begin{align}
\hat{a}_{ik} = \left \{ \chi_i , \chi_k \right \}, \ \ \ 1 \leq i,k \leq S,
\end{align}
which is obviously antisymmetric because of the antisymmetry of the Poisson bracket. Since the determinant of an odd dimensional antisymmetric matrix is automatically zero, we have to show that $\det (\hat{a}) \neq 0$ which would imply that $S$ is even. \\
Suppose $S$ is odd and $\det (\hat{a}) = 0$. Then $\text{rank}(\hat{a}) = T < S$. \\
Find a minor of $\hat{a}$ which has $\text{rank} = T$ and $\det \neq 0$ and build the \\ $(T+1) \times (T+1)$ - matrix
\begin{align}
\hat{b} =
\left(
\arraycolsep=1.4pt\def\arraystretch{1.4}
\begin{array}{c|cccc}
\chi_1 & \left\{ \chi_1,\chi_{k_1} \right\} & \left\{ \chi_1,\chi_{k_2} \right\} & \cdots & \left\{ \chi_1,\chi_{k_T} \right\} \\
\chi_2 & \left\{ \chi_2,\chi_{k_1} \right\} & \left\{ \chi_2,\chi_{k_2} \right\} & \cdots & \left\{ \chi_2,\chi_{k_T} \right\} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
\chi_T & \left\{ \chi_T,\chi_{k_1} \right\} & \left\{ \chi_T,\chi_{k_2} \right\} & \cdots & \left\{ \chi_T,\chi_{k_T} \right\} \\ \cline{1-5}
\chi_{T+1} & \left\{ \chi_{T+1},\chi_{k_1} \right\} & \left\{ \chi_{T+1},\chi_{k_2} \right\} & \cdots & \left\{ \chi_{T+1},\chi_{k_T} \right\}
\end{array} \right),
\end{align}
where $\chi_{T+1}$ is an arbitrary constraint which is left. We claim that $\det (\hat{b})$ is first-class. This would lead to a contradiction since we can't reach a first-class quantity with true second-class constraints.
Let's show this: \\
\begin{align}
\left\{ \det (\hat{b}),\phi_j \right\} &=
\det \left(
\arraycolsep=1.4pt\def\arraystretch{1.4}
\begin{array}{c|cccc}
\left\{ \chi_1,\phi_j \right\} & \left\{ \chi_1,\chi_{k_1} \right\} & \left\{ \chi_1,\chi_{k_2} \right\} & \cdots & \left\{ \chi_1,\chi_{k_T} \right\} \\
\left\{ \chi_2,\phi_j \right\} & \left\{ \chi_2,\chi_{k_1} \right\} & \left\{ \chi_2,\chi_{k_2} \right\} & \cdots & \left\{ \chi_2,\chi_{k_T} \right\} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
\left\{ \chi_T,\phi_j \right\} & \left\{ \chi_T,\chi_{k_1} \right\} & \left\{ \chi_T,\chi_{k_2} \right\} & \cdots & \left\{ \chi_T,\chi_{k_T} \right\} \\
\left\{ \chi_{T+1},\phi_j \right\} & \left\{ \chi_{T+1},\chi_{k_1} \right\} & \left\{ \chi_{T+1},\chi_{k_2} \right\} & \cdots & \left\{ \chi_{T+1},\chi_{k_T} \right\}
\end{array} \right) \notag \\[14pt]
&+
\det \left(
\arraycolsep=1.4pt\def\arraystretch{1.4}
\begin{array}{c|c|ccc}
\chi_1 & \left\{ \left\{ \chi_1,\chi_{k_1} \right\},\phi_j \right\} & \left\{ \chi_1,\chi_{k_2} \right\} & \cdots & \left\{ \chi_1,\chi_{k_T} \right\} \\
\chi_2 & \left\{ \left\{ \chi_2,\chi_{k_1} \right\},\phi_j \right\} & \left\{ \chi_2,\chi_{k_2} \right\} & \cdots & \left\{ \chi_2,\chi_{k_T} \right\} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
\chi_T & \left\{ \left\{ \chi_T,\chi_{k_1} \right\},\phi_j \right\} & \left\{ \chi_T,\chi_{k_2} \right\} & \cdots & \left\{ \chi_T,\chi_{k_T} \right\} \\
\chi_{T+1} & \left\{ \left\{ \chi_{T+1},\chi_{k_1} \right\},\phi_j \right\} & \left\{ \chi_{T+1},\chi_{k_2} \right\} & \cdots & \left\{ \chi_{T+1},\chi_{k_T} \right\}
\end{array} \right) \notag \\[14pt]
&+ \dots \ .
\end{align}
Only the first term is really interesting because we can Laplace expand every other term with respect to the first column and use the fact that $\chi_1, \chi_2, \dots, \chi_{T+1}$ vanish on the constraint surface. \\

Now, there can be several cases:
\begin{itemize}
\item If $\phi_j$ is first-class, then the Poisson brackets $\left\{ \chi_i,\phi_j \right\}$ will vanish and we are done.
\item If $\phi_j$ is second-class, then it is one of $\chi_1, \dots, \chi_S$ and there are two options:
\begin{enumerate}
\item $\phi_j \in \{ \chi_{k_1}, \dots, \chi_{k_T} \}$, then there will be two equal columns $\Rightarrow \det =0$.
\item $\phi_j \in \{ \chi_{k_{T+1}}, \dots, \chi_{k_S} \}$, then the matrix will be a $(T+1) \times (T+1)$ - minor of the matrix $\hat{a}$ but we fixed $\text{rank} (\hat{a}) = T$, so again $\det = 0$.
\end{enumerate}
\end{itemize}
We showed that $\left\{ \det (\hat{b}),\phi_j \right\} = 0, \ \forall \phi_j$. \\
$\Longrightarrow  \det (\hat{b})$ is a first-class quantity.
\end{proof}

For being able to quantize a Hamiltonian system with second-class constraints, Dirac invented the Dirac bracket:
\label{sec:dirac_bracket}

\begin{definition}[Generalized Dirac bracket]
\begin{align}
\left\{ f,g \right\}_D = \left\{ f,g \right\} - \sum_{i,j = 1}^S \left\{ f,\chi_i \right\} (\hat{a}^{-1})_{ij} \left\{ \chi_j,g \right\}.
\end{align}
\end{definition}

The Dirac bracket has all the properties of the Poisson bracket $+$ fixes the problems:
\begin{enumerate}
\item \(
\begin{aligned}[t]
\left \{ f,g \right \}_D = - \left \{ g,f \right \}_D
\end{aligned} \) \ - \ anticommutative
\item \(
\begin{aligned}[t]
\left \{ \alpha f_1 + \beta f_2,g \right \}_D = \alpha \left \{ f_1,g \right \}_D + \beta \left \{ f_2,g \right \}_D
\end{aligned} \) \ - \ bilinear
\item \(
\begin{aligned}[t]
\left \{  f_1 f_2,g \right \}_D = f_1 \left \{ f_2,g \right \}_D + f_2 \left \{ f_1,g \right \}_D
\end{aligned} \) \ - \ "derivative"
\item \(
\begin{aligned}[t]
\left \{ \left \{ f,g \right \}_D,h \right \}_D + \left \{ \left \{ g,h \right \}_D,f \right \}_D + \left \{ \left \{ h,f \right \}_D,g \right \}_D = 0
\end{aligned} \) \ - \ Jacobi identity
\end{enumerate}

Moreover the equation of motion doesn't change:
\begin{align}
\dot{g} = \left \{ g,H_T \right \}_D = \left \{ g,H_T \right \}
\end{align}
because $H_T$ is a first-class quantity.
The advantage is that every quantity is first-class with the Dirac bracket because the second-class constraints turn to first-class constraints:
\begin{align}
\left \{ g, \chi_j \right \}_D &= \left\{ g,\chi_j \right\} - \sum_{i,k = 1}^S \left\{ g,\chi_i \right\} (\hat{a}^{-1})_{ij} \left\{ \chi_k,\chi_j \right\} \notag \\
&= \left\{ g,\chi_j \right\} - \sum_{i,k = 1}^S \left\{ g,\chi_i \right\} \delta_{ij} \notag \\
&= 0.
\end{align}
In the last section, we said that we have to find all constraints before classifying them. But with the proofed theorem in mind, we don't have to do it anymore since every constraint will be first-class.

\pagebreak

The following example shows how every two (initially) second-class constraints reduce the degree of freedom by one.

\begin{example}
Consider two second-class constraints:
\begin{align}
\chi_1 &= q_1 = 0 \\
\chi_2 &= p_1 = 0
\end{align}
Then the Dirac bracket is just
\begin{align}
\left \{ f,g \right \}_D &= \left \{ f,g \right \} - \sum_{i,j = 1}^2 \left\{ f,\chi_i \right\} (\hat{a}^{-1})_{ij} \left\{ \chi_j,g \right\} \notag \\
&= \left \{ f,g \right \} - \left\{ f,\chi_1 \right\} (\hat{a}^{-1})_{12} \left\{ \chi_2,g \right\} - \left\{ f,\chi_2 \right\} (\hat{a}^{-1})_{21} \left\{ \chi_1,g \right\} \notag \\
&= \sum_{i=1}^n \left( \frac{\partial f}{\partial q_i} \frac{\partial g}{\partial p_i} - \frac{\partial g}{\partial q_i} \frac{\partial f}{\partial p_i} \right) - \left( - \frac{\partial f}{\partial p_1} \right) (-1) \left( - \frac{\partial g}{\partial q_1} \right) - \left( \frac{\partial f}{\partial q_1} \right) (+1) \left( \frac{\partial g}{\partial p_1} \right) \notag \\
&= \sum_{i=2}^n \left( \frac{\partial f}{\partial q_i} \frac{\partial g}{\partial p_i} - \frac{\partial g}{\partial q_i} \frac{\partial f}{\partial p_i} \right).
\end{align}
\end{example}

Since there is always an even number of true second-class constraints, the Dirac bracket will always reduce to the normal Poisson bracket with fewer degrees of freedom.


\section{Lecture 1 - Reduction to SAT}

\begin{frame}
  \frametitle{Solving SMT \formulae by reduction to SAT}

  \scriptsize

  Approaches to solve SMT \formulae are based on the observation
  that SMT can be {\bf reduced} to SAT, i.e., the purely Boolean
  Satisfiability Problem
  \vfill
  Consider for instance the \Lia formula
  $$
  \varphi\ \equiv\ (x - y \leq 0)\ \wedge\ (y - z \leq 0)\ \wedge\ ((z - x \leq -1)\ \vee\ (z - x \leq -2))
  $$
  We may use a Boolean variable $a$ to mean ``$x - y \leq 0$'' evaluates to $\top$
  in the model. Similarly we could use $b, c, d$ for the other \tatoms, obtaining
  $$
  \psi\ \equiv\ a \wedge b \wedge (c \vee d)
  $$
  \vfill
  \pause
  However we are not done with the encoding ! In fact altough $\mu^\Boo \equiv \{ a, b, c \}$
  is a (Boolean) model for $\psi$, the correspondent set of \tatoms $\{ x - y \leq 0, y - z \leq 0, z - x \leq -1 \}$
  is not consistent in \Lia: we cannot extend $\mu^\Boo$ to a model $\mu$ that satisfies $\varphi$.
  \pause
  \vfill
  This information can be added to the encoding in the following form
  $$ \neg( a \wedge b \wedge c )$$
  \pause
  \vfill
  Similarly we may derive {\bf all} the remaining incompatibilities
  $$ \neg( a \wedge b \wedge d )\quad\quad \neg( \neg a \wedge \neg b \wedge \neg c )\quad\quad \neg( \neg a \wedge \neg b \wedge \neg d )$$

\end{frame}

\begin{frame}
  \frametitle{Solving SMT \formulae by reduction to SAT}

  \scriptsize

  Initial \Lia formula
  $$
  \varphi \equiv (x - y \leq 0) \wedge (y - z \leq 0) \wedge ((z - x \leq -1) \vee (z - x \leq -2))
  $$
  Putting all the conditions together we get the Boolean formula
  $$
  \psi \equiv\ a \wedge b \wedge (c \vee d)\ \wedge\ \neg( a \wedge b \wedge c )\ \wedge\ \neg( a \wedge b \wedge d )\ \wedge\
  \neg( \neg a \wedge \neg b \wedge \neg c )\ \wedge\ \neg( \neg a \wedge \neg b \wedge \neg d )
  $$ \pause
  \vfill
  Starting from $\varphi$ we have
  \begin{enumerate}[$(i)$]
    \item encoded the structure of $\varphi$
    \item {\bf exhaustively} encoded all incompatible relations between \tatoms
  \end{enumerate}
  \vfill
  \begin{theorem}[Exercise 4 - correctness of the encoding]
    $\varphi$ is \T-satisfiable $\Leftrightarrow$ $\psi$ is satisfiable,
    where $\psi$ is obtained from $\varphi$ with the steps $(i)$-$(ii)$
  \end{theorem}

\end{frame}

\begin{frame}
  \frametitle{Exercise 4 - Proof}

  ($a_i$ is the Boolean variable corresponding to a \tatom $P_i$)
  \vfill

  ($\Rightarrow$)
  \medskip \\
  If $\varphi$ is \T-satisfiable, then it means that a model $\mu$ exists.
  A model $\mu^\Boo$ for $\psi$ can be defined with $\mu^\Boo(a_i) = \mu(P_i)$.
  \vfill\pause

  ($\Leftarrow$)
  \medskip \\
  Suppose that $\psi$ is satisfiable but $\varphi$ is not. If so, then
  there is a model $\mu^\Boo$ (e.g., $\{ \neg a_1, a_3 \}$) such that
  its encoding (e.g., $(\neg P_1 \wedge P_3)$) represents an incompatible relation
  of \tatoms. But if it is an incompatible relation, than its negation was
  added to $\psi$ (e.g, $\neg ( a_1 \wedge a_3 )$), and it should not be satisfied
  by $\mu^\Boo$. Contradiction.

\end{frame}

\begin{frame}
  \frametitle{Exercize 2}

  \scriptsize

  Given the unsatisfiable formula
  $$
  \psi \equiv\ a \wedge b \wedge (c \vee d)\ \wedge\ \neg( a \wedge b \wedge c )\ \wedge\ \neg( a \wedge b \wedge d )\ \wedge\
  \neg( \neg a \wedge \neg b \wedge \neg c )\ \wedge\ \neg( \neg a \wedge \neg b \wedge \neg d )
  $$
  show that $\neg( \neg a \wedge \neg b \wedge \neg c )$ and $\neg( \neg a \wedge \neg b \wedge \neg d )$ are redundant.
  \vfill\pause
  The last two clauses are redundant if
  $$a \wedge b \wedge (c \vee d)\ \wedge\ \neg( a \wedge b \wedge c )\ \wedge\ \neg( a \wedge b \wedge d )$$
  is already unsatisfiable on its own. \pause In every model $a$ and $b$ must be assigned to $\top$. This simplifies
  the formula to
  $$(c \vee d)\ \wedge\ \neg( c )\ \wedge\ \neg( d )$$\pause
  Now in every model $c$ and $d$ must be assigned to $\bot$. This simplifies the formula to
  $$\bot$$

\end{frame}


\subsection{Chapter 2}

\begin{p}
%{\bf 2} {\em
Show that the two definitions of continuity are equivalent:
 \begin{itemize}
\item Topological definition: $f$ is continuous if for any open $U\subset Y$, $f^{-1}(U)\subset X$ is also open
 \item $\epsilon-\delta$ definition: $f$ is continuous when for all $x$ and $\epsilon>0$, there exists a $\delta>0$ such that $||x-x'||<\delta$ implies $||f(x)-f(x')||<\epsilon$.
\end{itemize}
\end{p}
{
 \begin{itemize}
\item[$\Rightarrow$] Pick $f(x)\in Y$ and $\epsilon>0$. Set $U=\{y:||y-f(x)||<\epsilon\}$, which is an open set . Thus $f^{-1}(U)$ is also an open set. This means that for all $x\in f^{-1}(U)$ all points sufficiently close to $x$ are also in $f^{-1}(U)$ or, put differently, for all $x$ there exists $\delta>0$ such that $N_\delta(x)=\{x':||x-x'||<\delta\}\subset f^{-1}(U)$. Thus, $f(x')\in U$ for all $x'\in N_\delta(x)$, which means there exists a $\delta>0$ such that $||x-x'||<\delta$ implies $||f(x)-f(x')||<\epsilon$

 \item[$\Leftarrow$] Pick any open $U$. Now we must show that $f^{-1}(U)$ is open. For any $f(x)\in U$ there exists $\delta>0$ such that $||x-x'||<\delta$ means $||f(x)-f(x')||<\epsilon$, so we can pick $\epsilon$ small enough to ensure that $\{f(x'):||f(x)-f(x')||<\epsilon\}\subset U$. Hence, for any point $x\in f^{-1}(U)$, points sufficiently close are also in $f^{-1}(U)$: $f^{-1}(U)$ is open.
\end{itemize}
}

\begin{p}
Show that $S^n\subset \R^{n+1}$ with its induced topology is a manifold.
\end{p}
We need to check that the transition functions are smooth. This can be ensured by
mapping each of the subsets of the sphere back into $\R^{n+1}$ and
applying the transition function there (it's the identity function there).

\begin{p}
Show that if $M$ is a manifold and $U$ is an open subset of $M$, then $U$ with its
induced topology is a manifold.
\end{p}
{
The only thing one really needs to check is the smoothness of the transition functions
$\varphi_\alpha \circ \varphi_\beta^{-1}$. But this property is directly inherited from $M$,
since subsets of the form $U \cap S$ where $S$ is open in $M$ are themselves open
subsets of $M$.
}

\begin{p}
Given topological spaces $X$ and $Y$, we give $X\times Y$ the product topology in which a set is open if and only if it is a union of sets of the form $U\times V$,where $U$ is open in $X$ and $V$ is open in $Y$. Show that if $M$ is an $m$-dimensional manifold and $N$ is an $n$-dimensional manifold, $M \times  N$ is an $(m + n)$-dimensional manifold.
\end{p}
{...}
\begin{p}
Given topological spaces $X$ and $Y$, we give $X\times Y$ the disjoint union topology in which a set is open if and only if it is the union of an open subset of $X$ and an open subset of $Y$. Show that if $M$ and $N$ are $n$-dimensional manifolds the disjoint union $M \cup N$ is an $n$-dimensional manifold.
\end{p}
{...}


\subgroup{4}{Rob Ruigrok}

\paragraph{Description}
This chapter will cover the derivation of the dynamics of a heavy chain with uniform density $\rho$, length $L$ and a point mass on the end with mass $m$. The top of the chain will be suspended on a rolling trolley, where the lateral speed can be controlled. First, we will derive the dynamics, and later go into more detail on the "flatness" of the system and several control inputs.

\paragraph{Model}

An overview of the system is provided in figure \ref{fig:heavychainoverview}. Let $x$ be coordinate along the length of the chain, where the chain is attached to the trolley at $x=L$. The lateral displacement of the chain is denoted by $y(x,t)$. The problem can be made more complex by adding a point mass $m$ to the end of the chain.

\begin{figure}[h]
\label{fig:heavychainoverview}
\centering
\includegraphics[width = 4cm]{Overview.png}
\end{figure}

The derivation of the dynamics goes largely the same as the derivation of the vibrating spring. Here, however, the tension in the chain will be depending on $x$, and there will now be different boundary conditions linked to the trolley at the top and the attached mass at the bottom. Figure \ref{fig:heavychaindx} illustrates the forces acting on a finite chain element of length $dx$, which is the basis in the derivation of the PDE.\newline

\begin{figure}[h]
\label{fig:heavychaindx}
\centering
\includegraphics[width = 5cm]{SmallElement.png}
\end{figure}

We start with defining the tension in the chain as a function of $x$:

\begin{equation}
\label{eq:chaintension}
T = (m + x\rho)g
\end{equation}

To analyze the dynamics, we are interested of the lateral component of this tension. When examining an infinitesimal chain element of length $\Delta x$, we are interested in the net lateral force. Instead of defining the force on both sides of element $\Delta x$, we here determining the difference by using a first order Taylor approximation, together with a small angle approximation:

\begin{equation}
\label{eq:chainapprox}
sin(\theta)T \approx tan(\theta)T = \frac{\partial y}{\partial x}T
\end{equation}

\begin{equation}
\label{eq:chainforce}
\Delta F \approx F_x \Delta x = \big[\frac{\partial y}{\partial x}T\big]_x \Delta x
\end{equation}

The lateral motion of an infinitesimal chain element can now be described with Newtons second law of motion, $F = ma$, for which the net force is defined in equation \ref{eq:chainforce}. The mass of the chain element is $\rho \Delta x$, and the acceleration is $\frac{\partial^2 y}{\partial t^2}$

\begin{equation}
\begin{aligned}
    F &= ma \\
    \big[\frac{\partial y}{\partial x}T\big]_x \Delta x &= \rho \Delta x \frac{\partial^2 y}{\partial t^2} \\
    \big[\frac{\partial y}{\partial x} (m + x\rho)g \big]_x &= \rho \frac{\partial^2 y}{\partial t^2}
\end{aligned}
\end{equation}

When there is no mass suspended to end of the chain, the dynamics can be further written out:

\begin{eqnarray}
\label{eq:chainPDE}
    \big[\frac{\partial y}{\partial x} x \rho g \big]_x &=& \rho \frac{\partial^2 y}{\partial t^2} \\
    g \big[\frac{\partial y}{\partial x} x \big]_x &=& \frac{\partial^2 y}{\partial t^2} \\
    g \big[x \frac{\partial^2 y}{\partial x^2} + \frac{\partial y}{\partial x} \big] &=& \frac{\partial^2 y}{\partial t^2}
\end{eqnarray}
with boundary condition: $y(L,t) = u(t) $.

\paragraph{Solving the PDE}
\bigskip
\emph{\textbf{TODO: move part of it to control section
}}\bigskip

It is difficult to directly find a solution for the partial differential equation in equation~5\ref{eq:chainPDE}). For this particular problem, we assume that we know that we can rewrite to a Bessel function. Bessel functions are mainly used to describe wave propagation, and have the following format, where $\alpha$ denotes the order of the Bessel function:

\begin{equation}
\label{eq:Bessels}
x^2\frac{d^2 y}{dx^2} + x\frac{dy}{dx} + (x^2 - \alpha^2)y = 0
\end{equation}

In order to make the formulation in equation \ref{eq:chainPDE} fit this a zero-order Bessel function, we have to do certain changes of variables and convert the problem to the Laplace domain. In the Laplace domain, we can find solutions for our type of Bessel function, after which we need to transform it back to the time domain and reverse the variable changes. \newline

\paragraph{Step 1: substitution}

First step, do a substitution with $p = 2\sqrt{\frac{x}{g}}$. This will change the dependency from y(x,t) to y(p,t). Use the chain rule and find fill out the new values:

\begin{equation}
\label{eq:ChainRule}
\begin{aligned}
\frac{\partial p}{\partial x} &= \frac{1}{g}\bigg(\frac{x}{g}\bigg)^{-\frac{1}{2}} = \frac{1}{g\sqrt{\frac{x}{g}}} = \frac{2}{gp}\\
\frac{\partial y}{\partial x} &=  \frac{\partial y}{\partial p} \frac{\partial p}{\partial x} + \frac{\partial y}{\partial t} \cancelto{0}{\frac{\partial t}{\partial x}} = \frac{\partial y}{\partial p} \frac{2}{gp}
\end{aligned}
\end{equation}

When we fill everything out in the left part of equation \ref{eq:chainPDE}, we get the following expression:

\begin{equation}
\label{eq:chaincombination1}
\begin{aligned}
g \frac{\partial}{\partial x}\big[\frac{\partial y}{\partial x} x \big] &= g \frac{\partial}{\partial x}\big[\frac{\partial y}{\partial p} \frac{2}{gp} \frac{1}{4}gp^2 \big] = g \frac{\partial}{\partial x}\big[\frac{\partial y}{\partial p} \frac{p}{2} \big] \\
&= g \frac{\partial}{\partial p}\big[\frac{\partial y}{\partial p} \frac{p}{2} \big]\frac{\partial p}{\partial x} = g \big[\frac{\partial^2 y}{\partial p^2} \frac{p}{2} + \frac{1}{2} \frac{\partial y}{\partial p}\big] \frac{2}{gp} \\
&= \frac{\partial^2 y}{\partial p^2} + \frac{1}{p} \frac{\partial y}{\partial p}
\end{aligned}
\end{equation}

So the total equation can be written as:
\begin{eqnarray}
\label{eq:chaincombination2}
 g \big[\frac{\partial y}{\partial x} x \big]_x - \frac{\partial^2 y}{\partial t^2} &=& 0 \\
  \frac{\partial^2 y}{\partial p^2} + \frac{1}{p} \frac{\partial y}{\partial p} - \frac{\partial^2 y}{\partial t^2} &=& 0 \\
 p \frac{\partial^2 y}{\partial p^2} +
  \frac{\partial y}{\partial p} - p \frac{\partial^2 y}{\partial t^2} &=& 0
\end{eqnarray}

\paragraph{Step 2: transform to Laplace domain}

When converting the from the time domain, we use the following notation:
\begin{center}
$y(x,t) \xrightarrow{\mathcal{L}} Y(x,s)$
\end{center}
Further, to get the Laplace transform in the desired format, we require that the systems is initially \textit{at rest}, which means that $y(x,0)=0$ and $\dot{y}(x,0)=0$.

\begin{equation}
\label{eq:heavychainlaplace}
\begin{aligned}
 p \frac{\partial^2 y(x,t)}{\partial p^2} +
  \frac{\partial (x,t)}{\partial p} - p \frac{\partial^2 y(x,t)}{\partial t^2} = 0 \\
  \xrightarrow{\mathcal{L}}
 p \frac{\partial^2 Y(x,s)}{\partial p^2} +
  \frac{\partial Y(x,s)}{\partial p} - p s^2 Y(x,s) = 0
\end{aligned}
\end{equation}

NEW CHANGE OF VARIABLES (did it myself on paper, still need to isert)\newline
Bessel function!