\chapter{Appendix}

% \section{To the proof of the theorem of Peano}

% \begin{definition}
%   A function sequence $f^n$ is called \textbf{equicontinuous}, if it holds:
%   \begin{gather*}
%   \forall \,\epsilon > 0
%   \;\exists \, \delta > 0
%   \;\forall \, n \in \mathbb{N}
%   \;\forall |y-x| < \delta
%   \quad:\quad |f^n(y)-f^n(x)| < \epsilon
%   \end{gather*}
% \end{definition}

% \begin{theorem}[Arzela-Ascoli]\label{theorem:arzelaascoli}
%   Let be $f^h$ a equicontinuous, uniformly bounded sequence
%   of functions. Then it exists a subsequence $f^{h_i}$ which converges to a
% 	uniformly continuous function $f$.
% \end{theorem}

% \begin{todo}
% \begin{proof}
%   Nachzulesen in ...? %%%%%%%%%%%%%%%%
% \end{proof}
% \end{todo}

% \begin{proof}[Proof of the theorem of Peano]
%   I) Choose a sequence $h \to 0$ and compute approximations $u^h(t)$ with
% 		Euler's method.

%     The method is well-defined,
% 		if $(t_n,u_n^h) \in D \ \ \ \forall n$ with $|t_n-t_0| \le T$

%     $|u_1^h - u_0| = |h f(t_0,u_0)| \le h M$

%     $|u_n^h - u_0| = | \sum\limits_{k=0}^{n-1} h f(t_k,u_k^h) |
% 		\le M \underbrace{h n}_{= T} \le M T \le \beta$

%   \noindent II) To show: $u^h(t)$ is uniformly bounded and
% 		equicontinuous.

%     a) Since $u^h(t) \in D \Rightarrow |u^h(t)-u_0| \le \beta$

%     b) For $\tau,t \in [t_{n-1},t_n]$ holds $|u^h(\tau)-u^h(t)| \le M |\tau-t|$

%     \noindent $\Rightarrow$ The functions $u^h$ are equicontinuous and
% 		Lipschitz continuous with L-constant $M$.

%     \noindent $\underset{Theorem~\ref{Theorem:arzelaascoli} }{\Rightarrow}$ It exists
% 		a sequence $u_i^h$ with $u_i^h \to u$ and $u$ is equicontinuous.

%   \noindent III) The limit function $u$ solves Volterra's integral equation

%     $u(t) = u_0 + \int\limits_{t_0}^t f(s,u(s))\ \mathrm{d}s$.

%     \noindent To that: (The subsequence index will be omitted in the following)

%     $u^h(t) = u_0 + \sum\limits_{j=0}^k h f(t_j,u_j^h) + (t-t_k) f(t_k,u_k^h)$,

%     \noindent where $t_k$ is the highest point of Euler's method with $t_k < t$.

%     $\begin{array}{lcl}
%       u^h(t) = u_0 + \int\limits_{t_0}^t \Phi^h(s) \ \mathrm{d}s
%         & \text{ with } & \Phi^h(t) = f(t_j,u_j^h) \text{ for } t \in [t_j,t_{j+1}]\\
%       \Big\downarrow h \to 0 & \ & \Big\downarrow h \to 0 \\
%       u(t) = u_0 + \int\limits_{t_0}^t \Phi(s) \ \mathrm{d}s
%         & \text{ with } & \Phi(t) = f(t,u(t))\\
%     \end{array}$

%     \noindent Remains to show: $\Phi^h \to \Phi$ uniformly

% 		This follows from the uniformly continuity of $f$ in $\overline{D}$ and
% 		the equicontinuity of $u^h \to u$.
% \end{proof}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Comments on uniqueness of an IVP}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	For a first order differential equation Lipschitz continuity is only a
	sufficient and not, as one might think, a necessary condition for
	uniqueness of a first order differential equation. The following theorem
	and proof show that it is indeed possible to have uniqueness of solution
	without assuming Lipschitz continuity on the function.

\begin{Theorem*}{nonnecessity}{Non-necessity of L-continuity}
	Let $f$ be a continous function satisfying $f(x) > 0$ for all
	$x \in \R$. Then, the solution to the IVP
	\begin{subequations} \label{eq:myivp}
		\begin{align}
		  u'(t)&=f\bigl(t,u(t)\bigr) \\
		  u(t_0)&=u_0
		\end{align}
	\end{subequations}
	is globally unique for all $(t_0, u_0) \in \R^2$.
\end{Theorem*}

\begin{proof}
	Assume two solutions $\varphi, \, \psi \colon I \to \R$ on an open
	intervall $I$ with $t_0 \in I$. Then, there holds
\begin{xalignat}{3}
      && 1 = \frac{\varphi(t) '}{f(\varphi(t))} = \frac{\psi(t) '}{f(\psi(t))}
	  && \text{for all } t \in I. \label{eq:myivp2}
\end{xalignat}
	Define the function $F \colon \R \to \R$ through
\begin{gather*}
		F(x) = \int_{u_0} ^x \frac{\ds}{f(s)}.
\end{gather*}
	$F$ is continously differentiable since
\begin{gather*}
		\partial_x F(x)
		= \partial_x \left( \int_{u_0} ^x \frac{\ds}{f(s)} \right)
		= \frac{1}{f(x)}.
\end{gather*}
	Obviously, $F$ is also stricly increasing, hence injective on
	$\R$: Take $x, \, y \in \R$ and assume without loss of generality
	 that $x < y$. Then we have $F(x) < F(y)$ and thus $F(x) \neq F(y)$.
	 Thus, $F$ is an injection.

	Also, for all $t \in I$ there holds
\begin{gather*}
		F(\varphi(t))
		= \int_{u_0} ^t \frac{\varphi'(s)}{f(\varphi(s))} \ds
		\overset{\ref{eq:myivp2}}{=} \int_{u_0} ^t \frac{\psi'(s)}{f(\psi(s))} \ds
		= F(\psi(t)).
\end{gather*}
	Thus, since $F$ is injective, we have $\varphi(t) = \psi(t)$ for all
	$t \in I$. In conclusion, the IVP \ref{eq:myivp} has a unique solution.
\end{proof}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Properties of matrices}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{The matrix exponential}
\label{sec:matrix-exponentials}

\begin{definition}
  The matrix exponential $e^A$ of a matrix $A\in \R^{d\times d}$ is defined
  by its power series
  \begin{gather}
    \label{eq:appendix:1}
    e^A = \sum_{k=0}^\infty \frac{A^k}{k!}.
  \end{gather}
\end{definition}

\begin{lemma}
  \label{lemma:appendix:exp-0}
  The power series~\eqref{eq:appendix:1} converges for each matrix $A$. It is
  therefore valid to write
  \begin{gather}
    \label{eq:appendix:1.5}
    e^A = \lim_{m \to \infty} \sum_{k=0}^m \frac{A^k}{k!}
		= \sum_{k=0}^\infty \frac{A^k}{k!}.
  \end{gather}
\end{lemma}

\begin{proof}
  Chose $\| \cdot \|$ a submultiplicative matrix norm on $\R^d$. We want to
  show that the sequence of partial sums $(S_n)_{n \in \mathbb N_0}$ with $S_n$
  given as $\lim_{m \to \infty} \sum_{k=n} ^m \frac{A^k}{k!}$ converges to
  $S := e^A = \lim_{m \to \infty} \sum_{k=0} ^m \frac{A^k}{k!}$. Consider
  therefore
  \begin{gather}
    \|S - S_n\| = \left\| \lim_{m \to \infty} \sum_{k=n+1}^m \frac{A^k}{k!} \right\|
		= \lim_{m \to \infty} \left\| \sum_{k=n+1}^m \frac{A^k}{k!} \right\|.
  \end{gather}
  Using the triangle-inequality and the fact that $\| \cdot \|$ is submultiplicative
  yields
  \begin{gather}
  	\lim_{m \to \infty} \sum_{k=n+1}^m \left\| \frac{A^k}{k!} \right\|
		\le \lim_{m \to \infty} \sum_{k=n+1}^m \frac{1}{k!} \|A \|^k.
  \end{gather}
  Considering the limit $n \to \infty$ concludes the proof.
\end{proof}

\begin{lemma}[Properties of the matrix exponential function]
  \label{Lemma:appendix:exp-1}
	The following relations hold true:
  \begin{xalignat}2
    \label{eq:appendix:2}
    e^0 &= \identity \\
    \label{eq:appendix:3}
    e^{\alpha A} e^{\beta A} &= e^{(\alpha+\beta) A}, &\forall
    	A\in\R^{d\times d}\; \forall \alpha,\beta\in \R,\\
    \label{eq:appendix:4}
    e^A e^{-A} &= \identity &\forall A\in\R^{d\times d},\\
    \label{eq:appendix:5}
    e^{S^{-1}AS} &= S^{-1} A S^{-1} &\forall A \in\R^{d\times d} \text{ intervertible},\\
    \label{eq:appendix:6}
    e^{\diag(\lambda_1, \dots, \lambda_d)} &= \diag(e^{\lambda_1}, \dots, e^{\lambda_d})
		&\forall \lambda_i \in\R, \, i = 1, \dots, d.
  \end{xalignat}
  Moreover, $e^A$ is invertible for arbitrary quadratic matrices $A$ with $(e^A)^{-1} = e^{-A}$.
\end{lemma}

\begin{proof}
	The equality \ref{eq:appendix:2} follows directly from the definition.

    For \ref{eq:appendix:3} consider the function $\phi(\alpha)$ given by
    \begin{gather*}
	\phi(\alpha) = e^{\alpha A}e^{\beta A} - e^{(\alpha + \beta) A}.
	\end{gather*}
    For the derivative $\phi '$ there holds
    \begin{gather*}
	\phi'(\alpha) = A\big(e^{\alpha A}e^{\beta A}
		- e^{(\alpha + \beta) A} \big) = A \phi(\alpha).
	\end{gather*}
    For the obtained differential equation we obtain the initial value at
	$\alpha = 0$ by
    \begin{gather*}
	\phi(0) = \identity e^{\beta A} - e^{\beta A} = 0.
	\end{gather*}
    The solution is to this IVP then given by $\phi(\alpha) = e^{\alpha A}
		\phi(0) = 0$. Hence there holds
    \begin{gather*}
	\phi(\alpha) = \begin{cases}
	 e^{\alpha A}e^{\beta A} - e^{(\alpha + \beta) A} \\
     0
	\end{cases}
	\end{gather*}
    and we obtain $e^{\alpha A}e^{\beta A} = e^{(\alpha + \beta) A}$
		as desired.

    Equation \ref{eq:appendix:4} is a special case of \ref{eq:appendix:3}
	with parameters $\alpha=1$ and $\beta = -1$. Using \ref{eq:appendix:2}
	yields the result.

    For \ref{eq:appendix:5} note that $\R^{d \times d}$ forms a ring and is
	associative as such. Then for $k \in \mathbb N_0$ we have
    \begin{align*}
	(S^{-1} AS)^k &= (S^{-1} AS) (S^{-1} AS) \cdots (S^{-1} AS)(S^{-1} AS) \\
		&= S^{-1} A (SS^{-1}) A (S \cdots S^{-1}) A (SS^{-1}) AS = S^{-1} A^k S& \\
			\intertext{and thus by convergence}
	e^{S^{-1}AS} &= \sum_{k=0}^\infty \frac{1}{k!} (S^{-1}AS)^k \\
		&= \sum_{k=0}^\infty\frac{1}{k!} S^{-1} A^k S \\
		&= \enskip S^{-1} \cdot \left( \sum_{k=0}^\infty \frac{1}{k!} A^k \right)
			\cdot S  \enskip =  \enskip S^{-1} e^A S.&
	\end{align*}

    Lastly, let $D = \diag(\lambda_1, \dots, \lambda_d) \in \R^{d \times d}$
	where $\lambda_i \in \R$, $i= 1, \dots, d$. Then, $D^k = \diag(\lambda_1^k,
	\dots, \lambda_n^k)$ for any $k \in \mathbb N_0$. Then we have
	\begin{align}
	e^D =& \sum_{k=0}^\infty \frac{1}{k!} \diag(\lambda_1^k, \dots, \lambda_n^k) \\
	=& \sum_{k=0}^\infty \diag \left(\frac{1}{k!}\lambda_1^k, \dots,
		\frac{1}{k!}\lambda_n^k \right) \\
	=& \diag \left(\sum_{k=0}^\infty \frac{1}{k!} \lambda_1^k, \dots, \sum _{k=0} ^m
		\frac{1}{k!}\lambda_n^k \right) \\
	=& \diag \left(\sum_{k=0}^\infty \frac{1}{k!} \lambda_1^k, \dots, \lim_{m \to \infty}
		\sum _{k=0} ^m \frac{1}{k!}\lambda_n^k 	\right) \\
	=& \diag(e^{\lambda_1^k}, \dots, e^{\lambda_n^k})
	\end{align}
	Here we have used the absolute convergence of the series and that these matrices are
	elements of the ring $R^{d \times d}$.
	\end{proof}

\begin{example}
	We will perform an exemplary calculation of a matrix exponential. Consider
	\begin{gather*}
		A = \begin{pmatrix} 0 & 1 \\ k^2 & 0 \end{pmatrix}.
	\end{gather*}
	As the matrix exponential of a diagonal matrix is simply a diagonal matrix
	with the exponential of the entries.

	To diagonalize $A$ note that the eigenvalues $\lambda_1, \, \lambda_2$ of
	$A$ are $\lambda_1 = k$ and $\lambda_2 = -k$. By $D$ we denote the diagnoal
	matrix with the eigenvalues of $A$ as diagonal elements. The correspondig
	eigenvectors $v_1, \, v_2$ are $v_1 = \big( 1, k \big)^T$ and
	$v_2 = \big(1, -k \big)$. The matrix $S = (v_1 | v_2) \in \R^{2\times 2}$
	satisfies
	\begin{gather*}
		A = S^{-1} D S.
	\end{gather*}
	The inverse of $S$ is given as
	\begin{gather*}
		S^{-1} = \frac 12
			\begin{pmatrix}
				1 & \nicefrac 1k \\
				1 & - \nicefrac 1k
			\end{pmatrix}
	\end{gather*}
	and with the above lemma we can now calculate
	\begin{gather*}
	e^A = S e^D S^{-1} = \frac 12
			\begin{pmatrix}
				e^k + e^{-k} & \nicefrac 1k (e^k - e^{-k}) \\
				k (e^k - e^{-k}) & e^k + e^{-k}
			\end{pmatrix}
			=
			\begin{pmatrix}
				\cosh(k) & \nicefrac 1k \sinh(k) \\
				k \sinh(k) & \cosh(k)
			\end{pmatrix}
	\end{gather*}
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The Banach fixed-point theorem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{Theorem*}{banach}{Banach fixed-point theorem}
	Let $\Omega \subset \R$ be a closed set and $f \colon \Omega \to \Omega$
	a contraction, i.e. there holds $|f(x) - f(y)| \le \gamma |x-y|$ for a
	$\gamma \in (0,1)$.

	Then there exists a unique $x^* \in \Omega$ such that $f(x^*) =x^*$.
\end{Theorem*}

\begin{proof}
	Let $x_0 \in \Omega$ and define $f(x_k) = x_{k+1}$. First, we prove
	existence unsing the cauchy-criterion. Let $k, n \in \mathbb N_0$ and consider
	\begin{gather*}
	|x_k - x_{k+m} | = |f(x_{k-1}) - f(x_{k+m-1})| \le \gamma |x_{k-1} - x_{k+m-1})|.
	\end{gather*}

	Iteratively, we get
	\begin{gather*}
	|x_k - x_{k+m} | \le \gamma^k |x_0 - x_m|.
	\end{gather*}

	We now write $x_0 - x_m = x_0 - x_1 + x_1 - x_2 + \dots + x_{m-1} - x_m$.
	The triangle-inequality yields the estimate
	\begin{gather*}
	\gamma^k |x_0 - x_m| \le \gamma^k |x_0 - x_1| + |x_1 - x_2| + \dots + |x_{m-1} - x_m|  \\
	\le \gamma^k |x_0 - x_1| (1 + \gamma + \gamma ^2 + \dots + \gamma^m) \\
	\le \frac{\gamma^k}{1-\gamma} |x_0 - x_1|.
	\end{gather*}
	As $k$ gets larger the estimate goes to zero.

	Concerning uniqueness, let $x^*$ and $y^*$ be fixpoints.
	\begin{gather*}
	|x^* - y^*| = |f(x*) - f(y^*) | \le \gamma |x^* - y^*|
	\end{gather*}
	Since $\gamma \in (0,1)$ we immediately obtain $|x^* - y^*| = 0$. Using
	that $|a| = 0$ if and only if $a=0$ yields $y^* = x^*$. This concludes the proof.
\end{proof}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The implicit and explicit Euler-method}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	The explicit resp. implicit Euler is given by the one-step method
	\begin{align*}
	&& y_1 = y_0 + h f(y_0) && \text{resp.} && y_1 = y_0 + h f(y_1) &&
	\end{align*}
	Clearly, the explicit Euler is a rather easy calculation since all
	one needs are $f$, $h$ and $y_0$. The implicit Euler is more
	difficult to compute since for calculating $y_1$ we need the value
	of $f$ at $y_1$. The goal of this section is to visualize and give
	an intuition for the two algorithms.

	Consider the following visualizations.
	\begin{center}
	\begin{minipage}[t]{0.45\textwidth}
	\begin{tikzpicture}[domain=0:4]
	\draw[->] (0,0) -- (4.5,0) node[anchor=north] {$t$};
	\draw[->] (0,0) -- (0,4) node[anchor=east] {$y$};
	\draw[dashed] (2,4) -- (2,-0.22) node[anchor=north] {$t_1$};
	\draw plot [smooth] coordinates {
			(0,1) (0.5,1.19125) (1,1.41907)
			(1.5,1.69046) (2,2.01375)
			(2.5, 2.39888) (3, 2.85765)
			(3.5, 3.40417) (4, 4.0552)
					} node[left] {$u$};
	\draw[-{>[scale=2.0]}] (0,1) -- (4, 2.4) node[right] {$u'(t_0)$};
	\end{tikzpicture}

	For the explicit Euler we take $u_0$ and $u'_0$. $y_1$, our approximated
	solution for $u_1$, is chosen as the intersection point of $t_1$ and
	$g(t) = y_0 + t \cdot u'(t_0)$.
	\end{minipage}
	\begin{minipage}[t]{0.1\textwidth}
	\phantom{Käse}
	\end{minipage}
	\begin{minipage}[t]{0.45\textwidth}
	\begin{tikzpicture}[domain=0:4]
	\draw[->] (0,0) -- (4.5,0) node[anchor=north] {$t$};
	\draw[->] (0,0) -- (0,4) node[anchor=east] {$y$};
	\draw[dashed] (2,4) -- (2,-0.22) node[anchor=north] {$t_1$};
	\draw plot [smooth] coordinates {
			(0,1) (0.5,1.19125) (1,1.41907)
			(1.5,1.69046) (2,2.01375)
			(2.5, 2.39888) (3, 2.85765)
			(3.5, 3.40417) (4, 4.0552)
					} node[left] {$u$};
	\draw[{<[scale=3.0]}-] (0,1) -- (4, 3.81925) node[right] {$u'(t_1)$};
	\end{tikzpicture}

	For implicit Euler we go backwards. On the $t_1$-axis we are looking
	for an the affine function $g$ that fulfills $g(0) = u_0$ and $g'(t_1) = f(t_1)$.
	Then we set $y_1 = g(t_1)$.
	\end{minipage}
      \end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Derivation of a BDF-scheme}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	The BDF formulas use the approximations of the solution in the previous points
	$t_k -sh, \dots, t_k-h$ and the unkown value $y_k$ at $t_k$ which is to determine.
	With the Lagrange polynomial given by $L_i (t) = \prod_{j=1, j \not=i} ^n \tfrac{t- t_i}{t_j-t_i}$
	we let $y(t) = \sum_{j=1} ^s y_{k-j} L_{k-j}(t)$. Then, we will assume that $y$
	solves the IVP in the point $t_k$ and obtain a linear system from which we
	derive the desired value $y_k$.\\

	We now aim to derive the scheme for BDF(2). Let the points $t_k -2h,t_k -h$ and $t_k$ be given.

	\begin{center}
	\begin{tikzpicture}[scale=2, domain=-0.5:2.5]
	\draw[->] (-.25,0) -- (2.25,0) node[pos=1.025] {$t$};
	\draw[fill=black] (0,0) circle [radius=0.04] node[below] {$t_k - 2h$};
	\draw[fill=black] (1,0) circle [radius=0.04] node[below] {$t_k - h$};
	\draw[fill=black] (2,0) circle [radius=0.04] node[below] {$t_k$};
	\end{tikzpicture}
	\end{center}

	For the Lagrange polynomials in the points $t_k$, $t_k -h$ resp. $t_k -2h$ we have
	\begin{gather*}
		L_0 (t) = \tfrac{t-(t_k-h)(t-t_k)}{2h^2}, \,
		L_1 (t) = \tfrac{(t-t_k)(t-t_kj-2h)}{h^2} \, \text{resp.} \,
		L_2 (t) =  \tfrac{(t-t_k+2h)(t-t_k+h)}{2h^2}.
	\end{gather*}

	As announced, we assume that the interpolation polynomial fulfilles the IVP in
	the point $t_k$, i.e. there holds $f_k := f(t_k, y(t_k)) = y'(t_k) = \sum_{j=1} ^s
		y_{k-j} L_{k-j} ' (t)$. The product rule and evaluation at $t=t_k$ yields

	\begin{gather*}
		L_0 '(t) = \tfrac{2t-2t_k+h}{2h^2} = \tfrac{1}{2h}, \,
		L_1 '(t) = -\tfrac{2t -2t_k + 2h}{h^2} = -\tfrac{2}{h}  \, \text{and} \,
		L_2 '(t) = \tfrac{2t-2t_k + 3h}{2h^2} = \tfrac{3}{2h}.
	\end{gather*}

	Then, we obtain
	\begin{gather*}
		f_k = \tfrac{1}{2h} y_{k-2} - \tfrac{2}{h}y_{k-1} + \tfrac{3}{2h} y_k.
	\end{gather*}
	Multiplication with $\tfrac{2}{3h}$ yields the scheme
	\begin{gather*}
		y_k - \tfrac{4}{3} y_{k-1} + 3y_{k-2} = \tfrac{2}{3h} f_k.
	\end{gather*}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "notes"
%%% End:


\documentclass[10pt, handout]{beamer}
\setbeamertemplate{navigation symbols}{}
\usefonttheme{serif}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{color}
\usepackage{setspace}
\usepackage{hyperref}

\newcommand{\xx}{{\bf{x}}}

\begin{document}
\title{Machine Learning I Lecture VII:\\ Logistic Regression}
\author{Jakob H Macke\\ Max Planck Institute for Biological Cybernetics\\ Bernstein Center for Computational Neuroscience}
\date{\today}

\frame{\titlepage}

%\frame{\frametitle{Today: Back to basics of probability theory}}

\frame{\frametitle{Plan for today}\tableofcontents}

\section{Logistic Regression}

\frame{\frametitle{For the linear classification model, we assumed the class-conditional distributions to be Gaussian}
\begin{itemize}
\item We assumed $x| (t=1) \sim \mathcal{N}(\mu_+, \Sigma_+)$ and $x| (t=-1) \sim \mathcal{N}(\mu_-, \Sigma_-)$, and two class-probabilities $P(t=1)$ and $P(t=-1)$.
\item \pause This is called an \alert{generative model}, as we have written down a full joint model over the data.
\item \pause We saw that violations of the model assumption can lead to `bad' decision boundaries.
\end{itemize}
\begin{center}
\includegraphics[width=.35\textwidth]{Figure44a.pdf}
\includegraphics[width=.35\textwidth]{Figure44b.pdf}

\tiny Figures from Bishop PRML, 44a and b
\end{center}
}

\frame{\frametitle{For regression, we assumed Gaussian outputs, but did not need assumptions about the distribution of inputs.}
\begin{itemize}
\item For linear regression, we conditioned on $x$, and assumed a Gaussian distribution over $t$: $t|x \sim \mathcal{N}(y(x), \gamma^2)$
\item \pause We maximized the conditional log-likelihood $L(\omega)=\sum_n \log p(t_n|x_n, \omega)$, i.e we assumed that the $x$ were given.
\item \pause Therefore, this approach to linear regression works for \alert{any} distribution over $x$.
\item $x$ is typically high-dimensional, so it is difficult to make appropriate distributional assumptions for it.
\end{itemize}
\begin{center}
\includegraphics[width=.4\textwidth]{Figure128.pdf}

\tiny Figure Bishop PRLM 128
\end{center}
}

\frame{\frametitle{We can define a discriminative model for classification by modelling the conditional class probabilities.}
\begin{itemize}
\item From the homework-exercise, we know that $P(t=1 | z(x))=\sigma(z(x))$ where $\sigma(z)=1/(1+\exp(-z))$ and $z(x)=
\omega^\top x+\omega_o$.
\item Notation is simpler if we use $0$ and $1$ as class labels, so we define $s_n=1$ as the label for the positive class, and $s_n=0$ als label for the negative class.
\item In other words, $s |x \sim \mbox{Bernoulli}(\sigma(y(x))$.
\item Also, we set $y_n=\sigma(z(x))$.
\item \pause The parameters of $z(x)=\omega^\top x+ \omega_o$ can be learned by maximizing the conditional log-likelihood $L(\omega)=\sum_n \log p(t_n|x_n, \omega)$ [on board]
\item \pause This is an \alert{discriminative} approach to classification, as we only model the labels, and not the inputs.
\item
\pause Decision rule and function shape of $p(t|x)$ will be the same for the generative (`Linear Discriminant Analysis') and the discriminative model, but the parameters were obtained differently.
\end{itemize}
}

\section{Maximum likelihood estimation of Logistic Regression}

\frame{\frametitle{Maximum likelihood estimation of Logistic Regression}
\begin{center}
\includegraphics[width=.35\textwidth]{Figure44a.pdf}
\includegraphics[width=.35\textwidth]{Figure44b.pdf}

\tiny Bishop PRML Figure 44 a and b
\end{center}
\begin{itemize}
\item This algorithm is called \alert{logistic regression}, and is a \emph{much} better algorithm than the algorithms we discussed last week.
\item Need to optimize log-likelihood numerically.
\item \pause People typically minimize the negative log-likelihood $\mathcal{L}$ rather than maximize the log-likelihood...
\item \pause To numerically minimize the negative log-likelihood, we need its gradient (and maybe its hessian) [on board]
\end{itemize}
}

\frame{\frametitle{The cost-function for logistic regression is convex.}
\begin{center}
\includegraphics[width=.48\textwidth]{Convex.pdf}
\includegraphics[width=.48\textwidth]{NotConvex.pdf}
\end{center}
\begin{itemize}
\item \pause Fact: The negative log-likelihood is \emph{convex} -- this makes life much more easier.
\item \pause There are no local minima to get stuck in, and there is good optimization techniques for convex problems.
\end{itemize}
}

\frame{\frametitle{\emph{Gradient descent} is a simple method for numerically minimizing a function.}
\begin{itemize}
\item The gradient $\nabla \mathcal{L}$ of a function points into the direction of steepest descent.
\item \pause Gradient descent: 'run down the gradient' $\omega_{new}=\omega_{old}-\alpha \nabla \mathcal{L}_\omega$, with learning rate $\alpha$.
\item \pause Slightly more sophisticated version: numerically optimize $\alpha$ for each step by doing a \emph{line search}.
\item \pause Convergence can be very slow if cost-function has `valleys'.
\end{itemize}
\includegraphics[width=.7\textwidth]{BoydGradientDescent}

\tiny Figure from Stephen Boyd, Convex Optimization
}

\frame{\frametitle{\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}
\includegraphics[width=.8\textwidth]{Newton0}
}

\frame{\frametitle{\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}
\includegraphics[width=.8\textwidth]{Newton1}
}

\frame{\frametitle{\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}
\includegraphics[width=.8\textwidth]{Newton2}
}

\frame{\frametitle{\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}
\includegraphics[width=.8\textwidth]{Newton3}
}

\frame{\frametitle{\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}
\includegraphics[width=.8\textwidth]{Newton4}
}
\frame{\frametitle{\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}
\includegraphics[width=.8\textwidth]{Newton5}
}
\frame{\frametitle{\emph{Iterative Least Squares:} Approximate by parabola, minimze, iterate.}
\includegraphics[width=.8\textwidth]{Newton6}
}

\frame{\frametitle{\emph{Iterative Least Squares} is a more efficient method for minimizing the cost-function}
\begin{itemize}
\item Newton-Raphson: $\omega_{new}=\omega_{old}-\alpha (\nabla \nabla \mathcal{L})^{-1}\nabla L_\omega$
\item Pre-multiplying the gradient by the inverse-hessian speeds up convergence `along valleys' (analogy with LDA)
 \item Motivation: For quadratic functions $F(x)=a+b^\top x+ x^\top B x$, Newton-Raphson finds the minimum in one iteration.
 \item In this contex, Newton-Raphson (with $\alpha=1$) is often called \alert{iterative least squares}.
 \item Note: Newtwn's method can be bad if problem is not convex, and can be slow if it is difficult to calculate/invert the Hessian. A large number of optimization algorithms exist which do not require the (complete) Hessian (quasi Newton/BFGS, etc..).
% \item Any (reasonable) optimization algorithm requires the gradient.
\end{itemize}
}

\frame{\frametitle{Visualizing the cost-function of logistic regression}

[on board]

}

\section{Bayesian Logistic Regression: Approximating the posterior distribution}
\frame{\frametitle{Bayesian inference for this model does not have a closed form solution}
\begin{itemize}
\item Typically use Gaussian prior on $\omega$.
\item For linear regression, posterior distribution was Gaussian, with closed-form solutions for the mean and covariance.
\item For logistic regression, the posterior distribution is non-Gaussian.
\item \pause Popular approximation: Approximate posterior by a Gaussian
\begin{align}
p(\omega|D) \approx \mathcal{N}(\mu_{post}, \Sigma_{post})
\end{align}
\item \pause Different methods exist for finding `good' $\mu_{post}$ and $\Sigma_{post}$: Expectation Propagation (EP), Laplace Approximation, Variational Inference
\end{itemize}

}

\frame{\frametitle{The Laplace-Approximation is a simple Gaussian approximation to the posterior}
\begin{itemize}
\item \alert{Laplace approximation:} $\mu_{post}=\omega_{MAP}$, $\Sigma_{post}=\left(\nabla \nabla_\omega L   \right)^{-1}$.
\item Take MAP as mean, and inverse hessian at MAP as covariance.
\item \pause Motivation: Curvature matching, Taylor-expansion [on board]
\item \pause Q: When will the Laplace approximation fail?
\end{itemize}
\includegraphics[width=.49\textwidth]{Figure414a.pdf}
\includegraphics[width=.49\textwidth]{Figure414b.pdf}

\tiny Figure from Bishop PRML Figures 414a and b
}

\frame{\frametitle{The posterior distribution can be used to calculate the predictive distribution and to optimze hyper-parameters}
[on board]

}

%\section{LR's popular little brother-- support vector machines}

%\section{The exam}

\frame{\frametitle{One last bit of business: The exam}

\begin{itemize}
\item Next Friday, 2pm \emph{sharp}.
\item You will have 90 minutes.
\item You are allowed to use a pen or other writing utensils and your brain, no other tools/materials/books/notes will be allowed.
\item All mobiles phones need to be switched off.
\item Master-Students: Graded
\item Everyone else: Pass/Fail. If you want a grade for whatever reason, let me know (but it might not have any official meaning).
\end{itemize}
}

\frame{\frametitle{This is the end.}

Have fun in the second half of the course!
\vspace{1cm}

\pause
If you did like (some bits) from these lectures ...

\vspace{1cm}
... and want to do a lab-rotation on using machine-learning methods to analyse neural data and to model neural population dynamics

\vspace{1cm}
... write an email to jakob\@tuebingen.mpg.de.

}

\end{document}


% Created 2018-11-27 mar 09:04
\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\newcommand{\tustin}{\frac{2}{h}\frac{z-1}{z+1}}
\author{Kjartan Halvorsen}
\date{2016-05-06}
\title{Computerized control - final exam}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 24.5.1 (Org mode 8.2.10)}}
\begin{document}

\maketitle

\section*{Problem 1}
\label{sec-1}
The definition of \emph{anaesthesia} (or unconsciousness) is being in a state in which the body does not sense pain or other stimulii. The level, or depth, of anaesthesia is usually controlled by administrating drugs to the air inhaled by the patient undergoing surgery. The \emph{Mean Arterial Pressure (MAP)} is an important indicator for how deep the anaesthesia is. Consider a system for automatized delivery of anaesthetics:
\begin{center}
\includegraphics[width=0.999\linewidth]{anaesthesia}
\end{center}
The controller sets the position of a valve that controls the flow $u$ of anaesthetics, based on the difference between the reference MAP, $y_{ref}$, and the measured MAP, $y$.  The effect of the inflow of drug on the rate of change in the MAP of the patient is identified experimentally, and is described by the transfer function
\[ G(s) = \frac{1}{1+120s}, \] where the time unit is seconds. The surgery involves an uncontrolled stimulus on the system, and is represented by the additive disturbance signal $v$.

\subsection*{(a)}
\label{sec-1-1}
In the figure below, plot the continuous-time poles of the patient model (plant, including integrator) on the left complex plane. Choose a reasonable sampling time $h$, and plot the discrete-time poles obtained with zero-order-hold sampling in the right complex plane.

\begin{center}
\includegraphics[width=0.4\linewidth]{imaginary-plane-empty-cartesian}
\includegraphics[width=0.4\linewidth]{imaginary-plane-empty}
\end{center}

\subsubsection*{Solution}
\label{sec-1-1-1}
The first-order system describing the response to the flow of drug has time constant $T=\unit{120}{\second}$, which corresponds to a rising time $T_r=2.2T$. The appropriate rule-of-thumb says 4-10 sampling periods per rise time, which gives
\[ h \approx \unit{26.4}{\second} - \unit{66.0}{\second}. \]
Choosing, for instance $h=40.0$ gives one discrete-time pole in \(\mexp{-\frac{40}{120}}=0.717\) and one in \(\mexp{0} = 1\) due to the integration .
\begin{center}
\includegraphics[width=0.4\linewidth]{imaginary-plane-ct-poles-final}
\includegraphics[width=0.4\linewidth]{imaginary-plane-dt-poles-final}
\end{center}

\subsection*{(b)}
\label{sec-1-2}
A continuous-time controller for the system has been designed and is given by
\[ F(s) = \frac{25.6(160s+1)}{100s+1}. \]

Discretize the controller using the backward difference approximation
\[ \operatorname{p} \approx \frac{\operatorname{q}-1}{\operatorname{q}h}. \]

\subsubsection*{Solution}
\label{sec-1-2-1}
Inserting \[s = \frac{z-1}{zh}\] into the expression for the controller gives
\[ H(z) = F(s)|_{s=\frac{z-1}{zh}} = 25.6\frac{(160+h)z -160}{(100+h)z - 100}. \]

\section*{Problem 2}
\label{sec-2}
An alternative, discrete-time version of the patient-model in Problem 1 is given by
\[ H(z) = \frac{0.6z + 0.5}{z(z^2 - 1.9z + 0.9)}. \]
Apart from being discrete, this model differs from the one in Problem 1 by also including a time-delay.  The system is to be controlled using an RST-controller as in the figure below.
\begin{center}
\includegraphics[width=\linewidth]{rst-block}
\end{center}

Choose the correct answer to each question below. \textbf{Motivate your answers briefly with 1-2 sentences.}

\subsection*{(a)}
\label{sec-2-1}
Which of the following pulse-transfer functions describes the closed-loop response of the system to the disturbance $v$, i.e. the pulse-transfer function from $v$ to $y$?
\begin{enumerate}
\item \( \frac{R(z) \left(0.6 z + 0.5\right)}{S(z) z \left(z^{2} - 1.9 z + 0.9\right) + R(z) \left(0.6 z + 0.5\right)} \)
\item \(\frac{S(z) \left(0.6 z + 0.5\right)}{R(z) z \left(z^{2} - 1.9 z + 0.9\right) + S(z) \left(0.6 z + 0.5\right)}\)
\item \( \frac{R(z) \left(0.6 z + 0.5\right)}{R(z) z \left(z^{2} - 1.9 z + 0.9\right) + S(z) \left(0.6 z + 0.5\right)} \)
\end{enumerate}

\subsubsection*{Solution}
\label{sec-2-1-1}
The correct answer is \textbf{3}. \(\frac{R(z) \left(0.6 z + 0.5\right)}{R(z) z \left(z^{2} - 1.9 z + 0.9\right) + S(z) \left(0.6 z + 0.5\right)}\). This can be found by calculation in the block-diagram. with $H(z) = \frac{B}{A}$, the pulse-transfer function from $v$ to $y$ is
\[ H_v(z) = \frac{\frac{B}{A}}{1 + \frac{B}{A}\frac{S}{R}} = \frac{R(z)B(z)}{A(z)R(z) + B(z)S(z)}. \]
We see that alternative 1 and 3 has the correct numerator. But only alternative 3 has also the correct denominator.

\subsection*{(b)}
\label{sec-2-2}
Assume that the desired closed-loop characteristic polynomial is
\[ A_{cl}(z) = (z^2 - 1.4z + 0.5)(z-0.6)(z-0.5)^2. \]

Which of the following pairs of $S(z)$ and $R(z)$ controller polynomials is appropriate in order to determine the controller parameters from the Diophantine equation?
\begin{enumerate}
\item \(R(z) = z + r_1, \quad S(z) = s_0z + s_1 \)
\item \(R(z) = z^2 + r_1z + r_2, \quad S(z) = s_1z + s_2 \)
\item \(R(z) = z^2 + r_1z + r_2, \quad S(z) = s_0z^2 + s_1z + s_2 \)
\item \(R(z) = z + r_1, \quad S(z) = s_1 \)
\end{enumerate}

\subsubsection*{Solution}
\label{sec-2-2-1}
The correct answer is \textbf{3}.  \(R(z) = z^2 + r_1z + r_2, \quad S(z) = s_0z^2 + s_1z + s_2 \). The desired closed-loop characteristic polynomial has order 5. On the left-hand side of the Diophantine equation
\[ R(z) z \left(z^{2} - 1.9 z + 0.9\right) + S(z) \left(0.6 z + 0.5\right) = A_{cl}(z) \]
we see that $A(z)$ has order 3. Then $R(z)$ should have order two and $S(z)$ likewise, since this gives five unknown controller parameters to be solved from the five equations that the fifth-order Diophantine equation gives.

\section*{Problem 3}
\label{sec-3}
Consider the discrete-time state-space model
 \begin{equation*}
 \begin{split}
  x(k+1) &= \bbm 0.9 & 0\\0 & 1\ebm x(k) + \bbm 1\\1 \ebm u(k)\\
  y(k) &= \bbm -10.4 & 11.0 \ebm.
 \end{split}
\end{equation*}

\subsection*{(a)}
\label{sec-3-1}
What are the poles of the system? Is the system stable?

\subsubsection*{Solution}
\label{sec-3-1-1}
The poles are the eigenvalues of the $\Phi$ matrix. Here the matrix is diagonal, so the eigenvalues are simply the diagonal elements $0.9$ and $1$. For stability, the poles should be strict \emph{inside} the unit circle. There is a pole in 1, corresponding to an integrator, so this system is \textbf{not stable}.

\subsection*{(b)}
\label{sec-3-2}
Show that the state-space model corresponds to the pulse-transfer function
\[ H(z) = -\frac{10.4}{z-0.9} + \frac{11.0}{z-1} = \frac{0.6z + 0.5}{z^2 - 1.9z + 0.9}. \]

\subsubsection*{Solution}
\label{sec-3-2-1}
The pulse-transfer function is found by calculating
\begin{equation*}
  \begin{split}
 H(z) &= C \left( zI - \Phi\right)^{-1} \Gamma\\
      &= C \bbm z-0.9 & 0\\0 & z-1 \ebm ^{-1} \Gamma \\
      &= C \bbm \frac{1}{z-0.9} & 0\\ 0 & \frac{1}{z-1} \ebm \Gamma \\
      &= \bbm -10.4 & 11.0 \ebm \bbm \frac{1}{z-0.9} & 0\\ 0 & \frac{1}{z-1} \ebm \bbm 1\\1\ebm \\
      &= - \frac{10.4}{z-0.9} + \frac{11.0}{z-1}.
  \end{split}
 \end{equation*}

\subsection*{(c)}
\label{sec-3-3}
We want to determine a linear state feedback $u(k) = -Lx(k) + u_c(k)$ such that the closed-loop system has poles in \[ 0.6 \pm i0.3 \] Describe in a few steps and 5-8 sentences, the procedure to determine the controller parameters in $L$. You do \textbf{not} need to do the calculations or solve the equations.

\subsubsection*{Solution}
\label{sec-3-3-1}
The procedure is as follows.
\begin{enumerate}
\item From the desired closed-loop poles, we calculate the desired close-loop characteristic polynomial
\[ A_{cl}(z) = (z-p_1)(z - p_2) = (z-0.6+0.3i)(z-0.6-0.3i) = z^2 -1.2z + 0.45.\]
\item With the linear state feedback we get the closed-loop system on state space form
\begin{equation*}
 \begin{split}
 x(k+1) &= \left(\Phi - \Gamma L\right)x(k) + \Gamma u_c(k)\\
 y(k) &= C x(k).
 \end{split}
\end{equation*}
The characteristic polynomial is given by
\[ \det \left(zI - (\Phi - \Gamma L)\right), \]
which is a polynomial of degree 2 in this case:
\begin{align*}
\det \left(zI - (\Phi - \Gamma L)\right) &= \det \left( \bbm z & 0 \\ 0 & z \ebm - \big( \bbm 0.9 & 0\\ 0 & 1 \ebm - \bbm l_1 & l_2\\ l_1 & l_2 \ebm \big) \right) \\
                       &= \det \bbm z - 0.9 + l_1 & l_2\\l_1 & z - 1 + l_2 \ebm \\
                       &= (z-0.9+l_1)(z-1+l_2) - l1_l2 = z^2 + (l_1 + l_2 -1.9)z + (0.9 - l_1 - 0.9l_2)
\end{align*}
\item Set this polynomial equal to the desired polynomial
\[ z^2 + (l_1 + l_2 -1.9)z + (0.9 - l_1 - 0.9l_2) = z^2 - 1.2z + 0.45. \]
Form a linear system of equations in the elements of $L$ by setting each coefficient equal. This gives 2 equations in the two unknowns $l_1$ and $l_2$.

\begin{align*}
l_1 + l_2 &= -1.2 + 1.9 = 0.7\\
l_1 + 0.9l_2 &= 0.9 - 0.45 = 0.45
\end{align*}

with solution
\[ L = \bbm l_1 & l_2 \ebm = \bbm -1.8 & 2.5 \ebm. \]
\end{enumerate}
% Emacs 24.5.1 (Org mode 8.2.10)
\end{document}


\documentclass[12pt]{cdblatex}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% =================================================================================================
% create checkpoint file

\bgroup
\CdbSetup{action=hide}
\begin{cadabra}
   import cdblib
   checkpoint_file = 'tests/semantic/output/dGamma.json'
   cdblib.create (checkpoint_file)
   checkpoint = []
\end{cadabra}
\egroup

% =================================================================================================
\section*{Symmetrized partial derivatives of the connection}

Here we calculate the recursive sequences
\begin{align*}
(n+3)\Gamma^a{}_{d(b,c\uen)}
   &= (n+1)\left(R^a{}_{(bc\Dot d,\uen)}
    - \left(\Gamma^a{}_{f(c}\Gamma^f{}_{b{\Dot d}}\right){\vphantom{\Gamma}}_{,\uen)}\right)
\end{align*}
for $n=1,2,3,\cdots$. Note that the (extended) index $\uen$ contains $n$ normal indices.

The result will be expressions for the $\Gamma^a{}_{d(b,c\uen)}$ in terms of the Riemann tensor and its
partial derivatives.

% =================================================================================================
\section*{Stage 1: Compute symmetrised derivatives}

In the first stage we simply apply the above recursive equation using a simple trick to impose
the symmetries. Start with the original equation and dot out the symmetric indices with $A^a$ then
factor out the partial derivatives. This leads to
\begin{equation}
(n+3)\Gamma^a{}_{db,c\uen} A^b A^c A^{\cdot\uen}
    = (n+1)\left(R^a{}_{bcd}
    - \Gamma^a{}_{fc}\Gamma^f{}_{bd}\right)_{,\uen} A^b A^c A^{\cdot\uen}
\end{equation}
Thus we also have (for the next iteration)
\begin{equation}
(n+4)\Gamma^a{}_{db,c\uenp} A^b A^c A^{\cdot\uenp}
    = (n+2)\left(R^a{}_{bcd}
    - \Gamma^a{}_{fc}\Gamma^f{}_{bd}\right)_{,\uenp} A^b A^c A^{\cdot\uenp}
\end{equation}
The $A^a$ can be freely chosen so choose $A^a$ to be a constant (i.e., zero derivative). Now
define $P_n$ by
\begin{equation}
   P_n = \Gamma^a{}_{db,c\uen} A^b A^c A^{\cdot\uen}
\end{equation}
then the above pair of equations can be combinded to give
\begin{equation}
   P_{n+1} = \frac{(n+2)(n+3)}{(n+4)(n+1)} A^f\partial_f\left(P_n\right)
\end{equation}
This is a very easy equation to compute as it just requires successive rounds of differentiation.

The first term in the sequence is $P_0$ given by
\begin{equation}
   P_0 = \cdb{dGamma01.101}
\end{equation}

The first few results are

\begin{dgroup*}
   \begin{dmath*} P_0 \hiderel{=} A^{b} A^{c} \Gamma^a{}_{d(b,c)} = \cdb{dGamma01.101} \end{dmath*}
   \begin{dmath*} P_1 \hiderel{=} A^{b} A^{c} A^{e} \Gamma^a{}_{d(b,ce)} = \cdb{dGamma02.105} \end{dmath*}
   \begin{dmath*} P_2 \hiderel{=} A^{b} A^{c} A^{e} A^{f} \Gamma^a{}_{d(b,cef)} = \cdb{dGamma03.105} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Stage 2: Impose Riemann normal coordinates}

Here we impose the RNC condition by setting the $\Gamma^{a}{}_{bc}$ to zero (but not their derivatives).

\begin{dgroup*}
   \begin{dmath*} A^{b} A^{c} \Gamma^a{}_{d(b,c)} = \cdb{dGamma01.201} \end{dmath*}
   \begin{dmath*} A^{b} A^{c} A^{e} \Gamma^a{}_{d(b,ce)} = \cdb{dGamma02.202} \end{dmath*}
   \begin{dmath*} A^{b} A^{c} A^{e} A^{f} \Gamma^a{}_{d(b,cef)} = \cdb{dGamma03.203} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Stage 3: Replace partial derivatives of $\Gamma$ with partial derivatives of $R$}

The key point to note is that the partial derivatives of $\Gamma$ on the right hand side are all
symmetrized in exactly the same manner as the partial derivatives on the left hand side. Thus
results from the lower order equations can be fed into the later equations to completely eliminate
the partial derivatives of $\Gamma$.

\begin{dgroup*}
   \begin{dmath*} A^{b} A^{c} \Gamma^a{}_{d(b,c)} = \cdb{dGamma01.201} \end{dmath*}
   \begin{dmath*} A^{b} A^{c} A^{e} \Gamma^a{}_{d(b,ce)} = \cdb{dGamma02.202} \end{dmath*}
   \begin{dmath*} A^{b} A^{c} A^{e} A^{f} \Gamma^a{}_{d(b,cef)} = \cdb{dGamma03.402} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Stage 4: Reformatting}

This is just simple reformatting.

\begin{dgroup*}
   \begin{dmath*}   3 A^b A^c\Gamma^a{}_{d(b,c)} = \cdb{scaled1.002} \end{dmath*}
   \begin{dmath*}   6 A^b A^c A^e \Gamma^a{}_{d(b,ce)} = \cdb{scaled2.002} \end{dmath*}
   \begin{dmath*}  15 A^b A^c A^e A^f \Gamma^a{}_{d(b,cef)} = \cdb{scaled3.002} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Stage 1: Compute symmetrised derivatives}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   \nabla{#}::Derivative.
   \partial{#}::PartialDerivative.

   g_{a b}::Metric.
   g^{a b}::InverseMetric.
   g_{a}^{b}::KroneckerDelta.
   g^{a}_{b}::KroneckerDelta.

   R_{a b c d}::RiemannTensor.
   R^{a}_{b c d}::RiemannTensor.
   R_{a b c}^{d}::RiemannTensor.

   \Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2}).

   g_{a b}::Depends(\partial{#}).
   R_{a b c d}::Depends(\partial{#}).
   R^{a}_{b c d}::Depends(\partial{#}).
   \Gamma^{a}_{b c}::Depends(\partial{#}).

   # symmetrized partial derivatives of \Gamma

   dGamma01:= (1/3) A^{b} A^{c} ( R^{a}_{b c d} - \Gamma^{a}_{c e}\Gamma^{e}_{b d} ).
                                                        # cdb (dGamma01.101,dGamma01)

   dGamma02:= (6/4) A^{a}\partial_{a}{ @(dGamma01) }.   # cdb (dGamma02.101,dGamma02)
   distribute   (dGamma02)                              # cdb (dGamma02.102,dGamma02)
   product_rule (dGamma02)                              # cdb (dGamma02.103,dGamma02)
   unwrap       (dGamma02)                              # cdb (dGamma02.104,dGamma02)
   distribute   (dGamma02)                              # cdb (dGamma02.105,dGamma02)

   dGamma03:= (12/10) A^{a}\partial_{a}{ @(dGamma02) }. # cdb (dGamma03.101,dGamma03)
   distribute   (dGamma03)                              # cdb (dGamma03.102,dGamma03)
   product_rule (dGamma03)                              # cdb (dGamma03.103,dGamma03)
   unwrap       (dGamma03)                              # cdb (dGamma03.104,dGamma03)
   distribute   (dGamma03)                              # cdb (dGamma03.105,dGamma03)

   dGamma04:= (20/18) A^{a}\partial_{a}{ @(dGamma03) }. # cdb (dGamma04.101,dGamma04)
   distribute   (dGamma04)                              # cdb (dGamma04.102,dGamma04)
   product_rule (dGamma04)                              # cdb (dGamma04.103,dGamma04)
   unwrap       (dGamma04)                              # cdb (dGamma04.104,dGamma04)
   distribute   (dGamma04)                              # cdb (dGamma04.105,dGamma04)

   dGamma05:= (30/28) A^{a}\partial_{a}{ @(dGamma04) }. # cdb (dGamma05.101,dGamma05)
   distribute   (dGamma05)                              # cdb (dGamma05.102,dGamma05)
   product_rule (dGamma05)                              # cdb (dGamma05.103,dGamma05)
   unwrap       (dGamma05)                              # cdb (dGamma05.104,dGamma05)
   distribute   (dGamma05)                              # cdb (dGamma05.105,dGamma05)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma01.101} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma02.101} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma02.102} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma02.103} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma02.104} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma02.105} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma03.101} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.102} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.103} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.104} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.105} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma04.101} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.102} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.103} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.104} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.105} \end{dmath*}
\end{dgroup*}

% too long for pdflatex

% \begin{dgroup*}
%    \begin{dmath*} \cdb*{dGamma05.101} \end{dmath*}
%    \begin{dmath*} \cdb*{dGamma05.102} \end{dmath*}
%    \begin{dmath*} \cdb*{dGamma05.103} \end{dmath*}
%    \begin{dmath*} \cdb*{dGamma05.104} \end{dmath*}
%    \begin{dmath*} \cdb*{dGamma05.105} \end{dmath*}
% \end{dgroup*}

\clearpage

% =================================================================================================
\section*{Stage 2: Impose Riemann normal coordinates}

\begin{cadabra}
   def impose_rnc (obj):
       # hide the derivatives of Gamma
       substitute (obj,$\partial_{d}{\Gamma^{a}_{b c}} -> zzz_{d}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e}{\Gamma^{a}_{b c}} -> zzz_{d e}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e f}{\Gamma^{a}_{b c}} -> zzz_{d e f}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e f g}{\Gamma^{a}_{b c}} -> zzz_{d e f g}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e f g h}{\Gamma^{a}_{b c}} -> zzz_{d e f g h}^{a}_{b c}$,repeat=True)
       # set Gamma to zero
       substitute (obj,$\Gamma^{a}_{b c} -> 0$,repeat=True)
       # recover the derivatives Gamma
       substitute (obj,$zzz_{d}^{a}_{b c} -> \partial_{d}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e}^{a}_{b c} -> \partial_{d e}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e f}^{a}_{b c} -> \partial_{d e f}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e f g}^{a}_{b c} -> \partial_{d e f g}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e f g h}^{a}_{b c} -> \partial_{d e f g h}{\Gamma^{a}_{b c}}$,repeat=True)
       return obj

   # switch to RNC

   dGamma01 = impose_rnc (dGamma01)   # cdb (dGamma01.201,dGamma01)
   dGamma02 = impose_rnc (dGamma02)   # cdb (dGamma02.202,dGamma02)
   dGamma03 = impose_rnc (dGamma03)   # cdb (dGamma03.203,dGamma03)
   dGamma04 = impose_rnc (dGamma04)   # cdb (dGamma04.204,dGamma04)
   dGamma05 = impose_rnc (dGamma05)   # cdb (dGamma05.205,dGamma05)

\end{cadabra}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma01.201} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma02.202} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.203} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.204} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.205} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Stage 3: Replace partial derivatives of $\Gamma$ with partial derivatives of $R$}

\begin{cadabra}
   # use lower equations to eliminate partial derivs of Gamma from rhs

   # this produces experssions for the partial derivs of the Gamma's in terms of the Rabcd and its partial derivs

   substitute (dGamma03,$A^{c}A^{b}\partial_{c}{\Gamma^{a}_{b d}} -> @(dGamma01)$,repeat=True)                 # cdb(dGamma03.301,dGamma03)
   substitute (dGamma03,$A^{c}A^{b}\partial_{c}{\Gamma^{a}_{d b}} -> @(dGamma01)$,repeat=True)                 # cdb(dGamma03.302,dGamma03)
   distribute (dGamma03)                                                                                # cdb(dGamma03.303,dGamma03)

   substitute (dGamma04,$A^{c}A^{b}A^{e}\partial_{c e}{\Gamma^{a}_{d b}} -> @(dGamma02)$,repeat=True)          # cdb(dGamma04.301,dGamma04)
   substitute (dGamma04,$A^{c}A^{b}A^{e}\partial_{c e}{\Gamma^{a}_{b d}} -> @(dGamma02)$,repeat=True)          # cdb(dGamma04.302,dGamma04)
   substitute (dGamma04,$A^{c}A^{b}\partial_{c}{\Gamma^{a}_{b d}} -> @(dGamma01)$,repeat=True)                 # cdb(dGamma04.303,dGamma04)
   substitute (dGamma04,$A^{c}A^{b}\partial_{c}{\Gamma^{a}_{d b}} -> @(dGamma01)$,repeat=True)                 # cdb(dGamma04.304,dGamma04)
   distribute (dGamma04)                                                                                # cdb(dGamma04.305,dGamma04)

   substitute (dGamma05,$A^{c}A^{b}A^{e}A^{f}\partial_{c e f}{\Gamma^{a}_{d b}} -> @(dGamma03)$,repeat=True)   # cdb(dGamma05.301,dGamma05)
   substitute (dGamma05,$A^{c}A^{b}A^{e}A^{f}\partial_{c e f}{\Gamma^{a}_{b d}} -> @(dGamma03)$,repeat=True)   # cdb(dGamma05.302,dGamma05)
   substitute (dGamma05,$A^{c}A^{b}A^{e}\partial_{c e}{\Gamma^{a}_{d b}} -> @(dGamma02)$,repeat=True)          # cdb(dGamma05.303,dGamma05)
   substitute (dGamma05,$A^{c}A^{b}A^{e}\partial_{c e}{\Gamma^{a}_{b d}} -> @(dGamma02)$,repeat=True)          # cdb(dGamma05.304,dGamma05)
   substitute (dGamma05,$A^{c}A^{b}\partial_{c}{\Gamma^{a}_{b d}} -> @(dGamma01)$,repeat=True)                 # cdb(dGamma05.305,dGamma05)
   substitute (dGamma05,$A^{c}A^{b}\partial_{c}{\Gamma^{a}_{d b}} -> @(dGamma01)$,repeat=True)                 # cdb(dGamma05.306,dGamma05)
   distribute (dGamma05)                                                                                # cdb(dGamma05.307,dGamma05)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma03.301} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.302} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.303} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma04.301} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.302} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.303} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.304} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.305} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma05.301} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.302} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.303} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.304} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.305} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.306} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.307} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{cadabra}
   # note:
   # canonicalise must not be used here because it may make changes like
   #    R^{a}_{b c d} -> - R_{b}^{a}_{c d}
   # these changes can not be applied inside a \partial, must defer use
   # of canocialise until we have \nabla acting on curvatures

   sort_product   (dGamma03) # cdb(dGamma03.401,dGamma03)
   rename_dummies (dGamma03) # cdb(dGamma03.402,dGamma03)
   # canonicalise   (dGamma03) # cdb(dGamma03.403,dGamma03)

   sort_product   (dGamma04) # cdb(dGamma04.401,dGamma04)
   rename_dummies (dGamma04) # cdb(dGamma04.402,dGamma04)
   # canonicalise   (dGamma04) # cdb(dGamma04.403,dGamma04)

   sort_product   (dGamma05) # cdb(dGamma05.401,dGamma05)
   rename_dummies (dGamma05) # cdb(dGamma05.402,dGamma05)
   # canonicalise   (dGamma05) # cdb(dGamma05.403,dGamma05)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma03.401} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma03.402} \end{dmath*}
   % \begin{dmath*} \cdb*{dGamma03.403} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma04.401} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma04.402} \end{dmath*}
   % \begin{dmath*} \cdb*{dGamma04.403} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{dGamma05.401} \end{dmath*}
   \begin{dmath*} \cdb*{dGamma05.402} \end{dmath*}
   % \begin{dmath*} \cdb*{dGamma05.403} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{cadabra}
   import cdblib

   cdblib.create ('dGamma.json')

   cdblib.put ('dGamma01',dGamma01,'dGamma.json')
   cdblib.put ('dGamma02',dGamma02,'dGamma.json')
   cdblib.put ('dGamma03',dGamma03,'dGamma.json')
   cdblib.put ('dGamma04',dGamma04,'dGamma.json')
   cdblib.put ('dGamma05',dGamma05,'dGamma.json')

\end{cadabra}

\clearpage

% =================================================================================================
\section*{Stage 4: Reformatting}

\begin{cadabra}
   # note: keeping numbering as is (out of order) to ensure R appears before \nabla R etc.
   def product_sort (obj):
       substitute (obj,$ A^{a}                              -> A001^{a}                 $)
       substitute (obj,$ x^{a}                              -> A002^{a}                 $)
       substitute (obj,$ g^{a b}                            -> A003^{a b}               $)
       substitute (obj,$ \partial_{e f g h}{R^{a}_{b c d}}  -> A008^{a}_{b c d e f g h} $)
       substitute (obj,$ \partial_{e f g}{R^{a}_{b c d}}    -> A007^{a}_{b c d e f g}   $)
       substitute (obj,$ \partial_{e f}{R^{a}_{b c d}}      -> A006^{a}_{b c d e f}     $)
       substitute (obj,$ \partial_{e}{R^{a}_{b c d}}        -> A005^{a}_{b c d e}       $)
       substitute (obj,$ R^{a}_{b c d}                      -> A004^{a}_{b c d}         $)
       sort_product   (obj)
       rename_dummies (obj)
       substitute (obj,$ A001^{a}                  -> A^{a}                             $)
       substitute (obj,$ A002^{a}                  -> x^{a}                             $)
       substitute (obj,$ A003^{a b}                -> g^{a b}                           $)
       substitute (obj,$ A004^{a}_{b c d}          -> R^{a}_{b c d}                     $)
       substitute (obj,$ A005^{a}_{b c d e}        -> \partial_{e}{R^{a}_{b c d}}       $)
       substitute (obj,$ A006^{a}_{b c d e f}      -> \partial_{e f}{R^{a}_{b c d}}     $)
       substitute (obj,$ A007^{a}_{b c d e f g}    -> \partial_{e f g}{R^{a}_{b c d}}   $)
       substitute (obj,$ A008^{a}_{b c d e f g h}  -> \partial_{e f g h}{R^{a}_{b c d}} $)

       return obj

   def reformat (obj,scale):
       bah  = Ex(str(scale))
       tmp := @(bah) @(obj).
       distribute     (tmp)
       tmp = product_sort (tmp)
       rename_dummies (tmp)
       factor_out     (tmp,$A^{a?}$)
       return tmp

   def get_term (obj,n):

       A^{a}::Weight(label=numA).

       foo := @(obj).
       bah  = Ex("numA = " + str(n))
       distribute  (foo)
       keep_weight (foo, bah)

       return foo

   Gterm01 := @(dGamma01).
   Gterm02 := @(dGamma02).
   Gterm03 := @(dGamma03).
   Gterm04 := @(dGamma04).
   Gterm05 := @(dGamma05).

   scaled1 = reformat (Gterm01,   3)   # cdb (scaled1.002,scaled1)
   scaled2 = reformat (Gterm02,   6)   # cdb (scaled2.002,scaled2)
   scaled3 = reformat (Gterm03,  15)   # cdb (scaled3.002,scaled3)
   scaled4 = reformat (Gterm04,   9)   # cdb (scaled4.002,scaled4)
   scaled5 = reformat (Gterm05, 252)   # cdb (scaled5.002,scaled5)

\end{cadabra}

\clearpage

% =================================================================================================
\section*{Symmetrised partial derivatives of the connection}

\begin{dgroup*}
   \begin{dmath*}   3 A^b A^c\Gamma^a{}_{d(b,c)} = \cdb{scaled1.002} \end{dmath*}
   \begin{dmath*}   6 A^b A^c A^e \Gamma^a{}_{d(b,ce)} = \cdb{scaled2.002} \end{dmath*}
   \begin{dmath*}  15 A^b A^c A^e A^f \Gamma^a{}_{d(b,cef)} = \cdb{scaled3.002} \end{dmath*}
   \begin{dmath*}   9 A^b A^c A^e A^f A^g \Gamma^a{}_{d(b,cefg)} = \cdb{scaled4.002} \end{dmath*}
   \begin{dmath*} 252 A^b A^c A^e A^f A^g A^h\Gamma^a{}_{d(b,cefgh)} = \cdb{scaled5.002} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
% export selected objects, these will later be imported into a library
% these are the objects that will appear in the paper

\begin{cadabra}
   substitute (scaled1,$A^{a}->1$)
   substitute (scaled2,$A^{a}->1$)
   substitute (scaled3,$A^{a}->1$)
   substitute (scaled4,$A^{a}->1$)
   substitute (scaled5,$A^{a}->1$)

   cdblib.create ('dGamma.export')

   # 6th order dGamma, scaled
   cdblib.put ('dGamma61scaled',scaled1,'dGamma.export')
   cdblib.put ('dGamma62scaled',scaled2,'dGamma.export')
   cdblib.put ('dGamma63scaled',scaled3,'dGamma.export')
   cdblib.put ('dGamma64scaled',scaled4,'dGamma.export')
   cdblib.put ('dGamma65scaled',scaled5,'dGamma.export')

   checkpoint.append (scaled1)
   checkpoint.append (scaled2)
   checkpoint.append (scaled3)
   checkpoint.append (scaled4)
   checkpoint.append (scaled5)

\end{cadabra}

% =================================================================================================
% export checkpoints in json format

\bgroup
\CdbSetup{action=hide}
\begin{cadabra}
   for i in range( len(checkpoint) ):
      cdblib.put ('check{:03d}'.format(i),checkpoint[i],checkpoint_file)
\end{cadabra}
\egroup

\end{document}


%-----------------------------------------------------------------------
% Beginning of article-template.tex
%-----------------------------------------------------------------------
%
%    This is a template file for proceedings articles prepared with AMS
%    author packages, for use with AMS-LaTeX.
%
%    Templates for various common text, math and figure elements are
%    given following the \end{document} line.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%    Remove any commented or uncommented macros you do not use.

%    Replace amsproc by the name of the author package.
\documentclass{amsproc}

%    If you need symbols beyond the basic set, uncomment this command.
%\usepackage{amssymb}

%    If your article includes graphics, uncomment this command.
%\usepackage{graphicx}

%    If the article includes commutative diagrams, ...
%\usepackage[cmtip,all]{xy}

%    Include other referenced packages here.
\usepackage{}

\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{amsmath}

%    Update the information and uncomment if AMS is not the copyright
%    holder.
%\copyrightinfo{2009}{American Mathematical Society}

\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}

\newcommand{\ben}{\begin{equation*}}
\newcommand{\een}{\end{equation*}}

\newcommand{\ba}{\begin{align}}
\newcommand{\ea}{\end{align}}

\newcommand{\ban}{\begin{align*}}
\newcommand{\ean}{\end{align*}}

\newcommand{\df}{\; \mathrm{d}}

\usepackage{color}
\definecolor{darkblue}{rgb}{0,0,0.5}
\definecolor{darkred}{rgb}{0.5,0,0}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\definecolor{orange}{rgb}{0.9,0.58,0}

\newcommand{\at}[1]{\textbf{\textcolor{orange}{(#1 --at)}}}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{xca}[theorem]{Exercise}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\numberwithin{equation}{section}

\begin{document}

% \title[short text for running head]{full title}
\title{Roots of the Zeta Function, Random Matrices and Quantum Mechanics}

%    Only \author and \address are required; other information is
%    optional.  Remove any unused author tags.

%    author one information
% \author[short version for running head]{name for top of paper}
\author{Aashish Tripathee}
\address{}
\curraddr{}
\email{aashisht@mit.edu}
\thanks{}

%    The 2010 edition of the Mathematics Subject Classification is
%    now available.  If you are citing a classification from the
%    new scheme, use the following input coding instead.
%\subjclass[2010]{Primary }

\date{}

\begin{abstract}
In this paper, we explore three different algorithms to numerically calculate the non-trivial zeros of the Riemann Zeta function, $\zeta(t)$, namely, the Euler-Maclaurin method, alternating series method and the Riemann-Siegel formula. We then introduce random matrices and investigate any possible connection between their eigenvalues and the non-trivial zeros of $\zeta(t)$. We introduce the Hilbert-Polya conjecture as an alternate approach to proving the Riemann hypotheis. We investigate some of the properties of the eigenvalues of the Berry-Keating Hamiltonian.
\end{abstract}

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%    Templates for common elements of an article; for additional
%    information, see the AMS-LaTeX instructions manual, instr-l.pdf,
%    included in every AMS author package, and the amsthm user's guide,
%    linked from http://www.ams.org/tex/amslatex.html .

%    Section headings

\section{The Riemann Zeta Function}
The Riemann Zeta function is a function of a complex variable $s$, that analytically continues the sum of the infinite series,
\be
\zeta(s) = \sum_{n = 1}^{\infty} \frac{1}{n^2} \;.
\ee
$\zeta(s)$ converges for $\mathrm{Re}(s) > 1$, so we will restrict ourself to that domain for this paper. The Zeta function was first studied by Euler in 1740 but his study was limited to real, positive, integer values of $s$ only. Riemann later extended the function to complex valued $s$ in his 1859 paper ``On the Number of Primes Less Than a Given Magnitude''. There are multiple ways of defining $\zeta(t)$. It can, for example, also be defined as the integral,
\be
\zeta(s) = \frac{1}{ \Gamma(s) } \int_0^{\infty} \frac{ x^{s -1} }{ e^x - 1} \df x \;,
\ee
where $\Gamma(s) = \int_0^{\infty} x^{s - 1} e^{-x} \df x$. A particularly important represntation of the zeta is using the Euler product formula,
\be
\zeta(s) = \prod_{\mathrm{p~prime}} \frac{1}{1 - p^{-s}}
\ee
This form was proved by Euler in 1737 and is important, for example, because it can be used to prove that there are infinitely many primes. Consider the case when $s = 1$. Then,
\begin{align*}
 1 &= \zeta(1) \left( 1 - \frac{1}{2} \right) \left( 1 - \frac{1}{3} \right) \left( 1 - \frac{1}{5} \right) \left( 1 - \frac{1}{7} \right) \ldots \\
 1 &= \zeta(1) \frac{1}{2} \cdot \frac{2}{3} \cdot \frac{4}{5} \cdot \frac{6}{7} \ldots \\
  1 &= \zeta(1) \frac{1 \cdot 2 \cdot 4 \cdot 6 \ldots}{2 \cdot 3 \cdot 5 \cdot 7 \ldots }
\end{align*}
But, $\zeta(1) = 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \frac{1}{5} + \frac{1}{7} + \ldots$, which gives,
\begin{equation*}
 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \frac{1}{5} + \frac{1}{7} + \ldots =  \frac{2 \cdot 3 \cdot 5 \cdot 7 \ldots }{1 \cdot 2 \cdot 4 \cdot 6 \ldots}
\end{equation*}
But the left hand side of this equation diverges, which means the numerator in the right hand side diverges too, which means there must be infinitely many primes.

Another important form of the zeta function is the functional equation, written as,
\be
\zeta(s) = 2^s \pi^{s - 1} \sin{ \left( \frac{\pi s}{2} \right) } \Gamma(1 - s) \zeta( 1 - s) \;.
\ee

\section{Numerical Determination of the Roots of the Zeta Function}
\subsection{Euler-Maclaurin Formula}
The Euler-Maclaurin formula is a very popular tool used in numerical analysis as a connection between integrals and sums. It can be used to reformulate an integral as a sum or vice versa and is very popular in analytical number theory where it is used to compute sums in terms of integrals. The formula was developed in the early eighteenth century and came as a result of trying to extend the sum $\sum_{k} n^k$ for $k$'s other than 1. It was developed independently by Leonhard Euler and Colin Maclaurin around 1735- Euler to extend the sum just mentuoned and Maclaurin to compute integrals. The formula can be written as,

\begin{align}
\sum_{n = M}^{N} f(n) = &\int_M^N f(x) \df x + \frac{1}{2} \left[ f(N) - f(M) \right] + \\
&\sum_{j = 1}^{\nu} \frac{B_{2j}}{ (2j)! } \left[ f^{( 2j - 1)}(N) - f^{(2j - 1)} (M) \right] + R
\end{align}

The remainder $R$ is given by,
\be
R_{2 \nu} = - \frac{ s (s + 1) \ldots (s + 2 \nu) }{ (2 \nu + 1)! } \int_N^{\infty} B_{2 \nu + 1}(x) x^{-s - 2\nu - 1} \df x \;.
\ee
It can be shown that R satisfies the inequality \cite{},
\be
\left| R_{2 \nu - 2} \right| \le \left| \frac{s + 2 \nu - 1}{ \mathrm{Re}(s) + 2\nu - 1 } \right|  \cdot \left| B_{2 \nu} \right| \;.
\ee
This means, if $B_{2 \nu}$ is the first term we ignore in our sum, the remainder will be at most $\left| \frac{s + 2 \nu - 1}{ \sigma + 2\nu - 1 } \right|  \cdot \left| B_{2 \nu} \right|$.

If we apply the Euler-Maclaurin formula to $\zeta(s) = \sum_{1}^{\infty} n^{-s}$, $R$ will not be small enough to be ignored \cite{}. So, we instead apply the formula to the sum, $\sum_{N}^{\infty} n^{-s}$. Notice that,
\begin{align*}
 \sum_{n = 1}^{\infty} n^{-s} - \sum_{n = 1}^{N - 1} n^{-s} &= \sum_{N}^{\infty} n^{-s} \\
 \zeta(s) - \sum_{n = 1}^{N - 1} n^{-s} &= \sum_{N}^{\infty} n^{-s}
\end{align*}

\be
\label{eqn:euler_main}
\zeta(s)  = \sum_{n = 1}^{N - 1} n^{-s} + \sum_{N}^{\infty} n^{-s} = \sum_{n = 1}^{N - 1} n^{-s} + \chi(s)
\ee

The first term is easy to compute and we can use the Euler-Maclaurin formula to compute $\chi(s)$. Applying the formula,

\begin{align*}
\chi(s) &= \int_N^{\infty} x^{-s} \df x + \frac{1}{2} N^{-s} + \sum_{j = 1}^{\nu} \frac{B_{2j}}{ (2j)! } \left[ - (n^{-s})^{(2j - 1)} (N) \right] + R \\
& \approx \frac{1}{s - 1} N^{1 - s}  + \frac{1}{2} N^{-s} + \frac{B_2}{2} s N^{-s - 1} + \ldots + \left[ \frac{B_{2 \nu}}{ (2\nu)! } s(s + 1)  \ldots (s + 2 \nu - 2) N^{( -s - 2\nu + 1)} \right]
\end{align*}

The sum we need to calculate can be divided into four different parts, defined as follows:
\begin{align*}
 A &= \sum_{n = 1}^{N - 1} n^{-s} \\
 B &= \frac{1}{s - 1} N^{1 - s} \\
 C &= \frac{1}{2} N^{-s} \\
 D &= \frac{B_2}{2} s N^{-s - 1} + \ldots + \left[ \frac{B_{2 \nu}}{ (2\nu)! } s(s + 1)  \ldots (s + 2 \nu - 2) N^{( -s - 2\nu + 1)} \right]
\end{align*}
Then,
\begin{equation*}
 \zeta(s) \approx A + B + C + D \;,
\end{equation*}
with the error at most $\left| \frac{s + 2 \nu - 1}{ \mathrm{Re}(s) + 2\nu - 1 } \right|  \cdot \left| B_{2 \nu} \right|$.

This formula can be now used to compute $\zeta(s)$ and is very easy to implement. A sample implementation can be found in Section \ref{}.

\subsection{Alternating Series (Dirichlet Eta Function)}
Consider the following sum:
\be
\label{eqn:alternating_series}
\eta(s) = \sum_{n = 1}^{\infty} \frac{ (-1)^{n - 1} }{n^s} = \frac{1}{1^s} - \frac{1}{2^s} + \frac{1}{3^s} - \frac{1}{4^s} + \ldots
\ee
Comparing this to,
\begin{equation*}
 \zeta(s) = \sum_{n = 1}^{\infty} n^{-s} = \frac{1}{1^s} + \frac{1}{2^s} + \frac{1}{3^s} + \frac{1}{4^s} + \ldots
\end{equation*}
it's clear that,
\be
\label{eqn:dir_zeta}
\eta(s) = \left( 1 - 2^{1 - s} \right) \zeta(s) \;.
\ee
$\eta(s)$ is called the Dirichlet eta function, sometimes also called the alternating zeta function as it's the same sum as zeta function except the sign of the terms alternates between + and -.

Equation \ref{eqn:dir_zeta} means that if we can find a way to evaluate $\eta(s)$, we can evaluate $\zeta(s)$ using that.

Consider using Euler's transformation of alternating series to the series defined in Equation \ref{eqn:alternating_series} to accelerate its convergence. Euler's transform of alternating series is defined as,
\be
\label{eqn:euler_transform}
\sum_{n = 0}^{\infty} (-1)^n a_n = \sum_{n = 0}^{\infty} (-1)^n a_0 \frac{ 1 }{2^{n + 1}} \Delta^n \;,
\ee
where $\Delta^n$ is the $n^{\mathrm{th}}$-order forward difference of the function $f(x)$ given by,
\begin{equation*}
 \Delta^n[f](x) = \sum_{k = 0}^{n} {n \choose k} (-1)^{n - k} f(x + k)
\end{equation*}
Comparing \ref{eqn:euler_transform} to $\eta(s) = \sum_{n = 1}^{\infty} \frac{ (-1)^{n - 1} }{n^s} = \sum_{n = 0}^{\infty} \frac{ (-1)^n }{ (n + 1)^s }$, it is clear that,
\begin{align*}
\eta(s) &= \sum_{n=0}^{\infty} (-1)^n 1^{-s} \frac{1}{ 2^{n + 1} } \Delta^n \\
        &= \sum_{n=0}^{\infty} (-1)^n 1^{-s} \frac{1}{ 2^{n + 1} } \sum_{k=0}^{n} {n \choose k} \frac{ (-1)^n }{ (-1)^k } \frac{1}{ (k + 1)^s } \\
        &= \sum_{n=0}^{\infty} \frac{1}{ 2^{n + 1} } \sum_{k=0}^{n} {n \choose k} \frac{ (-1)^k }{ (k + 1)^s }
\end{align*}
This sum converges much faster than the original sum as it is exponential in $n$ and so, is much more efficient. A Python implementation that calculates this sum and uses it to calculate the Zeta function can be found in Section. \ref{}.

\subsection{Riemann-Siegel Formula}
We won't consider the derivation of the Riemann-Siegel formula here but the formula can be expressed as,
\be
Z(t) = 2 \sum_{n^2 < (t / 2 \pi )} n^{-1/2} \cos{ \left[ \theta(t) - t \log{n} \right] } + R \;,
\ee
with
\begin{equation}
 \theta(t) = \Gamma\left[ \frac{ 2 i t + 1}{4} \right] - t \frac{\log{\pi}}{2}
\end{equation}
\begin{align}
R = \frac{ e^{-i\nu(t)} e^{-t \pi / 2} }{ (2 \pi)^{1/2} (2 \pi)^{it} e^{-i t / 4} \left( 1 - i e^{-t \pi} \right) } \int_{C_N} \frac{ (-x)^{-(1/2) + i t}  e^{-Nx}}{ e^x - 1} \df x,
\end{align}
where $C_n$ is a contour which descends the real axis from $\infty$ to $(2 N + 1) \pi$, circles the boundary of the disk $\left| s \right| \le (2N + 1) \pi$ once and goes back to $\infty$ \ref{}.

The reaminder $R$ can be simplified and expressed in the following form. The details are in Edwards book.
\be
R \sim (-1)^{N - 1} \left( \frac{t}{2 \pi} \right)^{-1/4} \left[ C_0 + C_1 \left( \frac{t}{2\pi} \right)^{-1/2} + C_3 \left( \frac{t}{2\pi} \right)^{-3/2} + C_4 \left( \frac{t}{2\pi} \right)^{-4/2}\right]
\ee
\begin{align*}
 C_0 &= \Psi(p) = \frac{ \cos{\left( p^2 - p - 1/16 \right)} }{\cos{2 \pi p}} \\
 C_1 &= - \frac{1}{2^5 \cdot 3 \cdot \pi^2} \Psi^{(3)}(p) \\
 C_2 &=  \frac{1}{2^{11} \cdot 3^4 \cdot \pi^4} \Psi^{(6)}(p) + \frac{1}{2^6 \cdot \pi^2} \Psi^{(2)}(p)\\
 C_3 &=  - \frac{1}{2^{16} \cdot 3^4 \cdot \pi^6} \Psi^{(9)}(p) - \frac{1}{2^8 \cdot 3 \cdot 5 \cdot \pi^4} \Psi^{(5)}(p) - \frac{1}{2^6 \cdot \pi^2} \Psi^{(1)}(p) \\
 C_4 &=  - \frac{1}{2^{23} \cdot 3^5 \cdot \pi^8} \Psi^{(12)}(p) - \frac{11}{2^17 \cdot 3^2 \cdot 5 \cdot \pi^6} \Psi^{(8)}(p) + \frac{19}{2^{13} \cdot 3 \cdot \pi^4} \Psi^{(4)}(p) + \frac{1}{2^{7} \cdot \pi^2} \Psi(p) \\
\end{align*}
where $N$ is the integer part of $(t/2\pi)^{1/2}$ and $p$ the fractional part.

The coefficients $C$'s are not hard to calculate. However, a more efficient approach would be to compute the Taylor series expansion of $\Psi(p)$ and then express all the $C$'s in terms of those coefficients. Consider the series expansion of $\Psi(p) = \sum_i a_i p^i$.
\begin{align*}
\Psi(p) &= a_0 + a_1 p^1 + a_2 p^2 + a_3 p^3 + a_4 + p^4 + a_5 p^5 + \ldots \\
\Psi'(p) &= a_1 + 2 a_2 p + 3 a_3 p^2 + 4 a_4 p^3 + 5 a_5 p^4 + \ldots \\
\Psi''(p) &= 2 a_2 + 3\cdot2 a_3 p + 4 \cdot 3 a_4 p^2 + 5 \cdot4 \cdot a_5 p^3 + \ldots \\
\Psi^{(3)}(p) &= 3\cdot2 a_3 + 4 \cdot 3 \cdot 2 a_4 p^1 + 5 \cdot 4 \cdot 3 \cdot a_5 p^2 + \ldots \\
\end{align*}
So, in general,
\begin{equation*}
 \Psi^{m}(p) = m! \cdot a_m + (1 + m)! \cdot a_{m + 1} + \frac{(2 + m)!}{2!} \cdot a_{m + 2} + \frac{(3 + m)!}{2!} a_{m + 3} + \ldots
\end{equation*}
So, the if the $i$-th coefficient of series expansion of a function $\Psi(x)$ is $a_i$, the coefficient of $\Psi^{(m)}(p)$ is given by,
\begin{equation*}
 a^{(m)}_i = a_{i + m} \frac{ (i + m)! }{ i! }
\end{equation*}
This means, once we calculate the seires coefficients of $C_0$, calculating the coefficients of other $C$'s does not take long. The code that does this can be found in Section. \ref{}. The code that implements the Riemann Siegel formula gives a choice between using exact coefficients or using a series coefficients.

\section{Root Finding}
Now that we have three different ways to numerically compute $\zeta(t)$, it's very straightfoward to compute the zeros. We use a simple, binary-search algorithm to compute the roots, with a choice of any of the three algorithms discussed above to calculate $\zeta(t)$. We select an interval and keep bisecting it until we find an interval inside which the real part of $\zeta(t)$ changes sign, and that's narrower than whatever precision we're calculating the roots to. The first 100 roots are listed in Table \ref{tab:first_100_roots}. These were computed using the alternating series method. While the Riemann-Siegel formula is faster as it sums a smaller number of terms, for small $t$'s, it's not as accurate as the Euler-Maclaurin or alternating series method, particularly because we don't consider the full remainder $R$.

If we take the roots of $\zeta(t)$ and compute the succesive differences and plot them, we get the plot in Figure \ref{fig:zeta_zeros_normalized_differences}. The sucessive differences have been normalized so that the mean is $1$.

\begin{center}
  \begin{tabular}{ | l | c || l | l || r | r || r | r | }
    \hline
    N & Root & N & Root & N & Root & N & Root \\ \hline \hline
    1 & 14.1347251417  & 26 & 92.4918992706  & 51 & 147.4227653426  & 76 & 202.4935945141  \\ \hline
    2 & 21.0220396388  & 27 & 94.6513440405  & 52 & 153.0246938112  & 77 & 204.1896718031  \\ \hline
    3 & 25.0108575801  & 28 & 95.8706342282  & 53 & 156.1129092942  & 78 & 205.3946972022  \\ \hline
    4 & 30.4248761259  & 29 & 98.8311942182  & 54 & 157.5975918176  & 79 & 207.9062588878  \\ \hline
    5 & 32.9350615877  & 30 & 101.3178510057  & 55 & 158.8499881714  & 80 & 209.5765097169  \\ \hline
    6 & 37.5861781588  & 31 & 103.7255380405  & 56 & 161.1889641376  & 81 & 211.6908625954  \\ \hline
    7 & 40.9187190121  & 32 & 105.4466230523  & 57 & 163.0307096872  & 82 & 213.3479193597  \\ \hline
    8 & 43.3270732809  & 33 & 107.1686111843  & 58 & 165.5370691879  & 83 & 214.5470447835  \\ \hline
    9 & 48.0051508812  & 34 & 111.0295355432  & 59 & 167.1844399782  & 84 & 216.1695385083  \\ \hline
    10 & 49.7738324777  & 35 & 114.3202209155  & 60 & 173.4115365196  & 85 & 219.0675963490  \\ \hline
    11 & 52.9703214777  & 36 & 116.2266803209  & 61 & 174.7541915234  & 86 & 220.7149188393  \\ \hline
    12 & 56.4462476971  & 37 & 118.7907828660  & 62 & 176.4414342977  & 87 & 221.4307055547  \\ \hline
    13 & 59.3470440026  & 38 & 121.3701250024  & 63 & 178.3774077761  & 88 & 227.4214442797  \\ \hline
    14 & 60.8317785246  & 39 & 122.9468292935  & 64 & 179.9164840203  & 89 & 229.3374133055  \\ \hline
    15 & 65.1125440481  & 40 & 124.2568185543  & 65 & 182.2070784844  & 90 & 233.6934041789  \\ \hline
    16 & 67.0798105295  & 41 & 127.5166838796  & 66 & 184.8744678484  & 91 & 236.5242296658  \\ \hline
    17 & 69.5464017112  & 42 & 129.5787042000  & 67 & 185.5987836777  & 92 & 237.7698204809  \\ \hline
    18 & 72.0671576745  & 43 & 131.0876885309  & 68 & 187.2289225835  & 93 & 239.5554775733  \\ \hline
    19 & 75.7046906991  & 44 & 133.4977372030  & 69 & 189.4161586560  & 94 & 241.0491577962  \\ \hline
    20 & 77.1448400689  & 45 & 134.7565097534  & 70 & 192.0266563607  & 95 & 242.8232719342  \\ \hline
    21 & 79.3373750203  & 46 & 138.1160420545  & 71 & 193.0797266038  & 96 & 244.0708984971  \\ \hline
    22 & 82.9103808541  & 47 & 139.7362089521  & 72 & 195.2653966795  & 97 & 247.1369900749  \\ \hline
    23 & 84.7354929805  & 48 & 141.1237074040  & 73 & 196.8764818410  & 98 & 248.1019900602  \\ \hline
    24 & 87.4252746131  & 49 & 143.1118458076  & 74 & 198.0153096763  & 99 & 249.5736896447  \\ \hline
    25 & 88.8091112076  & 50 & 146.0009824868  & 75 & 201.2647519437  & 100 & 251.0149477950  \\
    \hline
  \end{tabular}
  %\caption{First 100 roots of the Riemann zeta function, $\zeta(t)$.}
\label{tab:first_100_roots}
\end{center}

%    Figure insertion; default placement is top; if the figure occupies
%    more than 75% of a page, the [p] option should be specified.
\begin{figure}
\includegraphics[width=\columnwidth]{figures/zeta_zeros_normalized_differences.pdf}
\caption{Distribution of successive differences of the first 2 million non-trivial zeros of $\zeta(t)$. The differences have been normalized so that the mean is 1.}
\label{fig:zeta_zeros_normalized_differences}
\end{figure}

\section{Random Matrices}
A random matrix is a matrix whose elements are random variables. Two most commonly studied types of random matrices are Gaussian Orthogonal Ensemble (GOE) and Gaussian Unitary Ensemble (GUE).

\subsection{Gaussian Orthogonal Enseblme (GOE)}
A Gaussian Orthogonal Ensemble is a set of $n \times n$ real-valued symmetric matrices $H_n$ whose Gaussian measure has the density,
$$
\frac{1}{Z_{\mathrm{GOE}}} e^{ - \frac{n}{4} \mathrm{tr}(H^2) } \;.
$$
GOEs model Hamiltonians with time-reversal symmetry.

Consider the ordered sequence of eigenvalues of $H_n$, $\lambda_1 < \lambda_2 < \ldots \lambda_{n - 1} < \lambda_n$. Define $s = \frac{\lambda_{i + 1} - \lambda_{i}}{ \left< s \right> }$. Then, the probability distribution on $s$ is given by,
$$
p_{\mathrm{GOE}}(s) = \frac{\pi}{2} s e^{- \frac{\pi}{4} s^2 }
$$

\begin{figure}
\includegraphics[width=\columnwidth]{figures/random_matrices_eigenvalues_differences.pdf}
\caption{Succesive eigenvalue differences for Gaussian Orthogonal and Gaussian Unitary Ensembles of $100\;\mathrm{K}$ $25 \times 25$ matrices. Each difference corresponds to $\lambda_{\lceil N \rceil + 1} - \lambda_{ \lceil N \rceil}$.}
\label{fig:random_matrices_eigenvalues_differences}
\end{figure}

\subsection{Gaussian Unitary Enseblme (GUE)}
A Gaussian Unitary Ensemble is a set of $n \times n$ Hermitian matrices $H_n$ whose Gaussian measure has the density,
$$
\frac{1}{Z_{\mathrm{GUE}}} e^{ - \frac{n}{2} \mathrm{tr}(H^2) } \;,
$$
with $Z_{\mathrm{GUE}} = 2^{ \pi / 2} \pi^{n^2 / 2}$. GUEs model Hamiltonians lacking time-reversal symmetry.

For GUEs, the probability distribution on $s$, is given by,
$$
p_{\mathrm{GUE}}(s) = \frac{32}{\pi^2} s^2 e^{- \frac{4}{\pi} s^2 }
$$

\section{Riemann Hypothesis}
The Riemann hypothesis conjectures that all non-trivial roots of the zeta function have real-part $1/2$. It was proposed by Riemann in 1859 in the same paper where he introduced the zeta funciton, ``On the Number of Primes Less Than a Given Magnitude''.

The Riemann hypothesis is arguably one of the most important unsolved problems in mathematics. Several approaches to proving it has been attempted but none has succedded so far. Numerically, it has been tested to be true for the first $10^{13}$ roots by X. Gourdon and Patrick Demichel \cite{}. However, numerical verification, no matter to how large values of $t$, can not be considered to be a compelling argument for a mathematical hypothesis to be true. One notable example is related to Skewes' number where a related conjecture breaks down for the first time at a number around $10^{316}$.

\section{Hilbert-Polya Conjecture}
The Hilbert-Polya conjecture suggests that the Riemann hypothesis would be true if the imaginary parts of the zeros of the zeta function correspond to the eigenvalues of some unbounded Hermitian operator. This came out of a letter to Andrew Odlyzko, in 1982, in which Polya wrote that he was asked by Edmund Landau for a physical reason why the Riemann hypothesis must be true, to which he proposed the conjecture.

The eigenvalues of a physical quantum operator are all real values and Hermitian operators are guaranteed to have real eigenvalues. This means, a physical way of proving the Riemann hypothesis would be to try to find a quantum mechanical operator whose eigenvalues (which will be all real) coincide with the imaginary parts of the non-trivial zeros of the Riemann zeta function. Finding any such quantum mechanical operator would be a proof of the Hilber-Polya conjecture and the Riemann hypothesis both. So in a sense, the Hilbert-Polya conjecture is just an alternate formulation of the Riemann hypothesis that makes it possible to try to find a physical proof of the Riemann hypothesis.

It's important to note that there are infinitely many non-trivial zeros the $\zeta(t)$ \ref{} and so, if such a Hermitian matrix does exist, as conjectured by the Hilbert-Polya conjecture, that matrix would have to be infinite-dimensional. Of course, that's not a problem since most quantum mechanical operators, even the simplest ones like say the Hamiltonian corresponding the a simple harmonic oscillator, have matrix forms where the dimension is infinite-dimensional. But it's something that one needs to be aware of since, for example, because no numerical calculations can go until infinity, numerical methods of finding / testing such quantum systems must be careful, and certain properties, the most notable example being the commutation relationship, won't be valid when we arrest the matrix representation to a finite size for numerical computations. The first one of this will be particularly important in Section. \ref{} where we discuss one such possible quantum system.

Very broadly speaking, there are now two approaches to prove the Riemann hypothesis. Through the Hilber-Polya conjecture, we've reduced the problem to finding some quantum mechanical system with a specific property. Because the operator (most likely the Hamiltonian) needs to be Hermitian, it's reasonable to expect, though this certainly does not have to be true, would be some function of the most common physical quantum mechanical operators. Finiding such an operator and testing whether or not its eigenvalues corresponds to the imaginary part of the non-trivial zeros of $\zeta(t)$ could be done numerically or we could try to find an analytical expression for those eigenvalues of our operator, in which case the analytical form would probably reduce to essentially one of the already known forms for $\zeta(t)$ equated to 0. Of course, it's not unconceivable that this would lead to an alternate expression for $\zeta(t)$ but nevertheless, the Hilbert-Polya conjecture opens up the door for attempts to prove the Riemann hypothesis in an alternate way.

\section{$\zeta(t)$ and Random Matrices}
If we're to prove the Riemann hypothesis, a careful study of the distribution of the non-trivial zeros of $\zeta(t)$ is crucial. In 1973, Montgomery conjectured that there mught be some possible connection between those non-trivial zeros and random matrices. Of particular interest is to study the distribution of successive differences of eigenvalues of the Gaussian Unitary Ensemble (GUE) and compare it to the successive differences of the non-trivial zeros of the zeta function.

It's interesting to note that the Gaussian Unitary Ensemble is a realization of every possible Hermitian matrices (assuming the ensemble size goes to infinity). But, through the Hilbert-Polya conjecture, there seems to be at least some connection between the eigenvalues of some such Hermitian matrix and the non-trivial zeros of the zeta function.

We need to choose some variable that is well-defined for both the GUEs and the distribution of the zeros of $\zeta(t)$ and then we can compare that variable for the two cases. One such possible variable is to consider the 2-point correlation function $R_2(E_1, E_2)$ which gives the probability density function of finding an eigenvalue of $H$ at each of the values $E_1, E_2$.  Montogomery, in 1972, showed that the 2-point correlation function for GUEs is given by,
$$
R_2(r) = 1 - \left[ \frac{ \sin{\pi r} }{\pi r} \right]^2 \;,
$$
and the 2-point correlation function for the Riemann zeros is,
$$
R_{\zeta, 2}(r) = 1 - \left[ \frac{ \sin{\pi r} }{\pi r} \right]^2 \;.
$$
This is remarkable since this implies that \at{What does this imply?}

Another interesting variable to comapre is the level-spacing of the zeros and the eigenvalues. What this means is, we could compute the successive differences (after sorting the eigenvalues / zeros) and compare them, subject to appropriate normalization. This is exactly the probability distribution we defined in \ref{} as $p_{\mathrm{ensemble}}(s)$. We normalize both the distributions so that the mean is 1, as that makes it easy to compare them.

\begin{figure}
\includegraphics[width=\columnwidth]{figures/GUE_eigenvalues_and_zeros_differences.pdf}
\caption{Succesive eigenvalue differences for Gaussian Unitary Ensembles of $100\mathrm{K}$ $25 \times 25$ matrices and the first 2M non-trivial zeros of $\zeta(t)$. For GUE, each difference corresponds to $\lambda_{\lceil N \rceil + 1} - \lambda_{ \lceil N \rceil}$. Both distributions have been normalized so that their mean is 1. }
\label{fig:random_matrices_eigenvalues_differences}
\end{figure}

\section{Quantum Mechanics}
Michael Berry and Jonathan Keating have conjectured that the Hilbert-Polya Hamiltonian $H$ is some quantization of the Hamiltonian $xp$. We'll consider one such possible quantization and discuss it at length in this secion. Let's define:
\be
H = \frac{1}{2} \left( x p + p x \right) = -i \left( x\frac{ \partial}{\partial x} + \frac{1}{2} \right)
\ee
For a simple harmonic oscialltor, $x$ and $p$ can be written in terms of raising and lowering operators $a$ and $a^{\dagger}$ as,
\be
x = \sqrt{\frac{ \hbar }{ 2 m \omega }} (a + a^{\dagger} )\,;
p = i \sqrt{ \frac{m \omega \hbar }{ 2 } } ( a^{\dagger} - a )
\ee
Let's ignore the factors in the front and just consider the linear combination of $a$ and $a^{\dagger}$ along with the imaginary unit. Using this expansion, it's fairly straightfoward to see that,
\be
H = \frac{1}{2} \left( xp + px \right) = i \left[ ( a^{\dagger} )^2 - (a)^2 \right]
\ee

$a^{\dagger}$ and $a$ has infinite-dimensional matrix representations as follows:

\[
a^{\dagger}
=
\begin{bmatrix}
    0        & 0        & 0        &  0       & \dots  \\
    \sqrt{1} & 0        & 0        &  0       & \dots   \\
    0        & \sqrt{2} & 0        &  0       &\dots   \\
    0        & 0        & \sqrt{3} &  0       & \dots   \\
    0        & 0        & 0        & \sqrt{4} & \dots   \\
    \vdots & \vdots & \vdots & \ddots & \vdots \\
    \hdots & \hdots & \hdots & \hdots & \hdots \\
\end{bmatrix} \, ,
a
=
\begin{bmatrix}
    0        & \sqrt{1} & 0        &  0       & \dots  \\
    0        & 0        & \sqrt{2} &  0       & \dots   \\
    0        & 0        & 0        & \sqrt{3} &\dots   \\
    0        & 0        & 0        &  0       & \dots   \\
    0        & 0        & 0        &  0 & \dots   \\
    \vdots & \vdots & \vdots & \ddots & \vdots \\
    \hdots & \hdots & \hdots & \hdots & \hdots \\
\end{bmatrix}
\]
For our computation, we will consider $N$ dimensional matrices instead of infinite dimensional.

Let's study what the eigevalues of $H$ look like. Because $a$ and $a^{\dagger}$ are sparse matrices, computing their eigenvalues, even for large $N$, is not too bad.

We again have to make a choice of what properties of the operator $H$ (and its eigenvalues) we want to study. The obvious choice is to study the successive difference of eigenvalues like we did for random matrices and the non-trivial zeros of $\zeta(t)$. Figure \ref{fig:everything} shows a plot. It's interesting to note that \at{what?}

\begin{figure}
\includegraphics[width=\columnwidth]{figures/everything.pdf}
\caption{Succesive eigenvalue differences for Gaussian Orthogonal Ensembles of $100\mathrm{K}$ $25 \times 25$ matrices, the first 2M non-trivial zeros of $\zeta(t)$ and the Berry Hamiltonian, $H$. For $H$, we consider a $1000 \times 1000$ matrix representation. For GOE, each difference corresponds to $\lambda_{\lceil N \rceil + 1} - \lambda_{ \lceil N \rceil}$. All distributions have been normalized so that their mean is 1. }
\label{fig:everything}
\end{figure}

An interesting feature of the plot in Figure. \ref{fig:everything} is that, while the distributions for the non-trivial roots and GUE seems to go down all the way to 0, there seems to be a finite cut for the eigenvalue difference for Berry's Hamiltonian $H$. The existence of this finite cut isn't a remarkable property by itself since this just means that there is no degeneracy for the Hamiltonian we're considering. What's interesting though is that, this cut seems to depend on the size of the matrix representation we choose $N$.

\begin{figure}
\includegraphics[width=\columnwidth]{figures/qm_min_eigenvalues_differences.pdf}
\caption{A plot of how the minimum successive eigenvalue difference (minimum level spacing) varies with the size of the matrix we choose to represent our Hamiltonian $H$. }
\label{fig:qm_min_eigenvalues_differences}
\end{figure}

Figure \ref{fig:qm_min_eigenvalues_differences} shows a plot of how the minimum successive eigenvalue difference (minimum level spacing) varies with the size of the matrix we choose to represent our Hamiltonian $H$. Two immediately interesting things can be noticed here. First, there seems to be a very well-defined, very specific way in which the minimum difference (which corresponds to the left-cuttoff in Figure \ref{fig:everything}) varies with $N$. Second, that variation seems to be dependent on the parity of $N$. In particular, for odd values of $N$, the minimum difference seems to be larger than for what would otherwise be defined by whatever larger-scale model is applicable.

\begin{figure}
\includegraphics[width=\columnwidth]{figures/qm_eigenvalues.pdf}
\caption{A plot of how the minimum successive eigenvalue difference (minimum level spacing) varies with the size of the matrix we choose to represent our Hamiltonian $H$. }
\label{fig:qm_eigenvalues}
\end{figure}

Figure \ref{fig:qm_eigenvalues} shows a histogram of eigenvalues for a given $N \times N$ representation of $H$. The property we're particularly interested in is that the eigenvalues seem to be clustered around the origin. So, we conjecture, without proof, that the minimum eigenvalue difference is always going to be the difference of the two eigenvalues closest to the origin.

However, there is a slight technicality here. For odd values of $N$, the matrix representation of $H$ is not invertible. In particular, it's rank is always going to be $N - 1$, which means it will have at most $N - 1$ non-zero eigenvalues. Said in other words, there will be one or more $0$ eigenvalues for odd $N$. However, if there were more than one $0$ eigenvalues, the minimum eigenvalue difference would be $0$, which doesn't seem to be the case for finite $N$ according to Figure \ref{fig:qm_min_eigenvalues_differences}. This means, for odd $N$'s, there will always be one zero eigenvalue.

Because our matrix representation of $H$ only contains real entries, all its eigenvalues will occur as complex-conjugate pairs. These get divided by the $i$ factor outside to give real eigenvalues but this means that the eigenvalues will be symmetric about the origin, the only difference between odd and even $N$ being whether or not $0$ is one of those eigenvalues.

\begin{figure}
\includegraphics[width=\columnwidth]{figures/qm_min_eigenvalues.pdf}
\caption{A plot of how the minimum eigenvalues $\lambda_{+1}$ varies with the size of the matrix we choose to represent our Hamiltonian $H$. Note that for odd $N's$, the minimum would be $0$, so we choose the next largest minimum. In other words, we're plotting the minumum non-zero eigenvalues of $H$ against the size of its matrix representation $N$. }
\label{fig:qm_min_eigenvalues}
\end{figure}

For odd $N$'s, since we always have a $0$ eigenvalue, the min. difference would be just $\left| \lambda_{+1}^{\mathrm{odd}N} - \lambda_0^{\mathrm{odd}N} \right| = \left| \lambda_{+1}^{\mathrm{odd}N} - 0 \right| = \lambda_{+1}^{\mathrm{odd}N} $. However, for even values of $N$, since there is no zero eigenvalue, the minimum difference will be $\left| \lambda_{+1}^{\mathrm{even}N} - \lambda_{-1}^{\mathrm{even}N} \right| = \left|2 \lambda_{+1}^{\mathrm{even}N} \right| = 2 \lambda_{+1}^{\mathrm{even}N} $. Naively, it'd seem that therefore the minimum difference for even $N$'s would be larger than for odd $N$'s. However, as suggested by Figure \ref{fig:qm_min_eigenvalues_differences}, this is not true. It's important to note that $\lambda_{+1}^{\mathrm{even}N} \ne \lambda_{+1}^{\mathrm{odd}N}$, and so our argument breaks down. In fact, because the minimum  difference for odd $N$'s seems to always be larger than for even $N$'s, we can say that $ 2 \lambda_{+1}^{\mathrm{even}N} < \lambda_{+1}^{\mathrm{odd}N}$. Of course, this relation is not exactly well defined since $N$ will either be odd or will be even so there isn't a proper way to compare $\lambda_{+1}$ since the matrix size changes. So an implicit assumption in the relation is, ``what would normally be defined by the broader large-scale model''. Figure \ref{fig:qm_min_eigenvalues} demonstrates our claim.

Another important property of the plot in Figure \ref{fig:qm_min_eigenvalues_differences} we're interested in is the asymptotic behavior of the difference as $N \to \infty$. Ultimately, our aim is to find a Hilbert-Polya Hamiltonian and that would have an infinite-dimensional matrix representation (with infinitely many real eigenvalues which correspond to the imaginary parts of the infinitely many non-trivial roots of $\zeta(t)$) so, it's important to study the behavior of the matrix representation of $H$ as $N \to \infty$.

From Figure \ref{fig:qm_min_eigenvalues_differences}, it's not quite clear whether the difference approaches 0 or some finite value (that's very close to $0$) as $N \to \infty$. We conjecture that it does approach $0$. Here's a non-rigorous, hand-wavy reasoning. As seen in Figure \ref{fig:qm_eigenvalues}, the eigenvalues are symmetric about the origin. So when we compute the successive differences, consider approaching it from left and right i.e. moving from the most positive eigenvalue in the direction of decreasing eigenvalues and at the same time, moving from the most negative eigenvalue towards decreasingly negative eigenvalues. Because of the inherent symmetry in the eigenvalues, we must approach the same limiting value. However, if this limit positive, that would mean that we'd have to hit $0$ and move towards positive differences. But all the eigenvalues to the left of $0$ are negative so the differences can never be positive. Same with while moving from right to left, the differences can never be negative. But, since we have to approach the same limiting value for either case, this limit must be $0$.

But if the eigenvalue difference does hit $0$ when $H$ is infinite-dimensional, that would mean there is a degeneracy. However, because the eigenvalues of $H$ would correspond to the imaginary parts of the non-trivial roots of $\zeta(t)$ and so a degeneracy in the eigenvalues of $H$ implies a degeneracy in the non-trivial roots of $\zeta(t)$. Since no such degeneracy is known, any quantization of $H$ that would be a prospective Hilbert-Polya Hamiltonian would have to have something to break this degeneracy. Note that even though it seems like the difference in roots of $\zeta(t)$ in Figure \ref{fig:everything} seems to be going all the way down to 0, it does not. For the plot produced, which contains the first 2 million zeros, it goes all the way down to $\sim 0.0052$ (in normalized units).

\section{Conclusion}
So this is the conclusion. Haha

%    Ordinary theorem and proof
%\begin{theorem}[Optional addition to theorem head]
% text of theorem
%\end{theorem}

%\begin{proof}[Optional replacement proof heading]
% text of proof
%\end{proof}

%    Figure insertion; default placement is top; if the figure occupies
%    more than 75% of a page, the [p] option should be specified.
%\begin{figure}
%\includegraphics{filename}
%\caption{text of caption}
%\label{}
%\end{figure}

%    Text of article.

%    Bibliographies can be prepared with BibTeX using amsplain,
%    amsalpha, or (for "historical" overviews) natbib style.
\bibliographystyle{amsplain}
%    Insert the bibliography data here.

\end{document}

%-----------------------------------------------------------------------
% End of article-template.tex
%-----------------------------------------------------------------------