%%%%%%%%%%%%%%%%%%%%%definitions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{../header.tex}
\input{../newcommands.tex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DOCUMENT%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\title{DG methods on structured grids}
\author{M.~Wiesenberger}
\tableofcontents

\section{ Introduction to discontinuous Galerkin methods} \label{sec:discretization}
This writeup is based on Reference~\cite{WiesenbergerPhD}. A useful book to consult
is Reference~\cite{NodalDG}.

In recent years, discontinuous Galerkin (dG) methods have been investigated
as an excellent alternative to finite difference and finite volume schemes
in numerical simulations involving both parabolic as well as hyperbolic problems
(for the advection dominated case see, for example, the review article~\cite{Cockburn2001runge}).
Such methods combine many advantages of finite element methods (such as the ease of handling
complicated geometry) with properties more commonly associated with
finite difference approximations. Examples of the latter includes the absence
of a global mass matrix.
The main idea of a dG method is to approximate the solution
of a differential equation by a polynomial in each grid-cell.
Higher/lower
order methods can be constructed by simply increasing/decreasing the degree of
the polynomials used in each cell.
In classical finite element methods continuity is required across cell boundaries.
In contrast, dG methods allow discontinuities across cell boundaries, which adds to the flexibility of the method.

For the discretization of second derivatives we discuss the so-called local discontinuous Galerkin (LDG) method~\cite{Cockburn1998}.
The LDG method and its advantages can also be used for the discretization of
elliptic equations (including Poisson's equation).
Reference~\cite{Arnold2002} highlights the relation
of the method to interior penalty and other alternative methods.
A superconvergence result for the
LDG approach was proven on Cartesian grids~\cite{Cockburn2002},
where the order of convergence is $1/2$ better than on arbitrary meshes.
Reference~\cite{Yadav2013} later showed a similar result for general, nonlinear elliptic equations.

The downside of the dG methods is their rather complex and unintuitive notation
in the existing mathematical literature. Often, algorithms
are described in terms of arbitrary sets of polynomials and spatial grids.
We propose an adapted, simplified, and in our view more practical notation for orthogonal grids and Legendre polynomials, which can be implemented straightforwardly.
We reformulate the LDG method in terms of adjoint matrices and
 naturally develop the symmetry of the resulting discretization.
Doing so, we also propose a new discretization for the general elliptic equation.
Unfortunately, our discretization has a wider stencil than the existing ones, but
our numerical experiments indicate superconvergent properties and the resulting
matrix equation is better conditioned than the old one. To the knowledge
of the author these findings are unpublished to date.

\subsection{ The Legendre polynomials} \label{sec:legendre}
First, let us consider the one-dimensional case.
For simplicity and ease of implementation we choose an equidistant grid with $N$ cells $C_n = [x_{n-1/2},x_{n+1/2}]$ of size $h$;
with this choice we are able to construct basis functions of $P(C_n)$, the space of
polynomials of degree at most $P-1$ on $C_n$, by using orthogonal Legendre polynomials\footnote{ Often, in the literature the order of the polynomials is denoted by $k$.
Pay attention, that we use the number of polynomial coefficients $P$ instead. We have $P=k+1$}.
The Legendre polynomials can be recursively defined on $[-1,1]$ by setting
$p_0(x) = 1$, $p_1(x) = x$ and (see e.g.~\cite{AS})
\begin{align}
    (k+1)p_{k+1}(x) = (2k+1)xp_k(x) - kp_{k-1}(x).
    \label{eq:recursion}
\end{align}
The so constructed Legendre polynomials are orthogonal on $[-1,1]$.
We write
$x^a_j$ and $w_j$, $j=0,\dots,P-1$ denoting the abscissas and weights of
the Gauss--Legendre quadrature on the interval $[-1,1]$. Then we note that for $k,l=0, \dots, P-1$
\begin{align}
    \int_{-1}^1 p_k(x)p_l(x) \dx = \sum_{j=0}^{P-1} w_jp_k (x^a_j)p_l(x^a_j) = \frac{2}{2k+1}\delta_{kl},
    \label{}
\end{align}
 since Gauss--Legendre quadrature is exact for polynomials of degree at most $2P-1$.

The discrete completeness relation can then be written as
\begin{align}
    \sum_{k=0}^{P-1} \frac{2k+1}{2}w_j p_k(x^a_i)p_k(x^a_j) = \delta_{ij}.
    \label{eq:completeness}
\end{align}
Given a real function $f:[-1,1]\rightarrow \mathbb{R}$ we define $f_j:=f(x^a_j)$ and
\begin{align} \label{eq:ex2}
    \bar f^k := \frac{2k+1}{2}\sum_{j=0}^{P-1}w_j p_k(x^a_j) f_j
\end{align}
Now let us define the forward transformation matrix by $F^{kj}:=\frac{2k+1}{2}w_jp_k(x^a_j)$ and
the backward transformation matrix by $B_{kj}:= p_j(x^a_k)$.
\begin{tcolorbox}[title=Note]
Reference~\cite{NodalDG} identifies $B$ as the Vandermonde matrix and further denotes $f_i$ as the \textbf{nodal} representation and $\bar f^k$ as the \textbf{modal} representation of $f(x)$.
\end{tcolorbox}

Then, using Eq.~\eqref{eq:ex2}, we get
\begin{subequations}
\begin{align}
    \bar f^k = \sum_{j=0}^{P-1}F^{kj}f_j \\
    f_j = \sum_{k=0}^{P-1} B_{jk}\bar f^k,
\end{align}
\end{subequations}

Let us now consider an interval $[a,b]$ and an equidistant discretization
by $N$ cells with cell center $x_n$ and grid size $h=\frac{b-a}{N}$; in addition, we set $x_{nj}^a := x_n + \frac{h}{2}x^a_j$.
Given a function $f:[a,b]\rightarrow \mathbb{R}$ we then define
$f_{nj} := f(x^a_{nj})$ and note that
\begin{subequations}
\begin{align}
    \bar{ \vec f} &= (\Eins\otimes F) \vec f \\
    \vec f &= (\Eins\otimes B) \bar{\vec f},
    \label{}
\end{align}
\end{subequations}
where $f_{nj}$ are the elements of $\vec f$,
 $\Eins\in\mathbb{R}^{N\times N}$ is the identity matrix and $F,B\in\mathbb{R}^{P\times P}$. Furthermore, we use
$\otimes$ to denote the Kronecker product which is bilinear and associative.
The discontinuous Galerkin expansion $f_h$ of a function $f$ in the interval $[a,b]$ can
then readily be given as
\begin{align}
    f_h(x) = \sum_{n=1}^N \sum_{k=0}^{P-1} \bar f^{nk} p_{nk}(x),
    \label{eq:dgexpansion}
\end{align}
where
\begin{align}
    p_{nk}(x) := \begin{cases}
        p_k\left(  \frac{2}{h}(x-x_n)\right),& \ \text{for } x-x_n\in\left[ -\frac{h}{2}, \frac{h}{2} \right]\\
        0,& \ \text{else}.
    \end{cases}
    \label{}
\end{align}
As an example, we plot Eq.~\eqref{eq:dgexpansion} for $f(x)=\sin(2x)$ in Fig.~\ref{fig:discretization}.
\begin{figure}[htpb]
    \includegraphics[width= 0.9\textwidth]{discretization.pdf}
    \caption{
    Discretization of a sine function with second order polynomials, $P=3$,
    on $N=5$ grid cells. Dotted lines depict the cell boundaries.
    }
    \label{fig:discretization}
\end{figure}
Already with a very low resolution of $P=3$ and $N=5$
we get an acceptable function approximation. We clearly see the discontinuities
at the cell boundaries.

The use of Legendre polynomials yields a natural approximation of the integrals of $f$
via Gauss--Legendre quadrature
\begin{subequations}
\begin{align}
    \langle f_h,g_h\rangle:=\int_a^b f_hg_h \dx &= \sum_{n=1}^N\sum_{j=0}^{P-1} \frac{hw_j}{2} f_{nj} g_{nj}
    = \sum_{n=1}^N\sum_{k=0}^{P-1}\frac{h}{2k+1}\bar f^{nk}\bar g^{nk}  \\
    \|f_h\|^2_{L_2} := \int_a^b |f_h|^2 \dx &= \sum_{n=1}^N\sum_{j=0}^{P-1} \frac{h w_j}{2}f_{nj}^2
    = \sum_{n=1}^N\sum_{k=0}^{P-1} \frac{h}{2k+1}\left(\bar f^{nk}\right)^2.
    \label{eq:def_norm}
\end{align}
\label{eq:gausslegendre}
\end{subequations}
With these formulas we have a simple, accurate, and fast
method to evaluate integrals on the entire domain. This is applied, for example, to compute
errors in the $L_2$-norm.

We now define some useful quantities that simplify our notation (note that $i,j=0,\dots,P-1$)
\begin{subequations}
    \begin{align}
        S_{ij} &:= \int_{-h/2}^{h/2} p_i\left(\frac{2}{h} x\right)p_j\left(\frac{2}{h} x\right) \dx = \frac{h}{2i+1}\delta_{ij} \\%=: s_i \delta_{ij}\\
        T^{ij} &:= S^{-1}_{ij} = \frac{2i+1}{h}\delta_{ij} \\%=: t_i \delta_{ij}\\
        W^{ij} &:= \frac{h w_j}{2}\delta_{ij}\\
        V_{ij} &:= W_{ij}^{-1} = \frac{2}{hw_j}\delta_{ij}.
    \end{align}
    \label{eq:diagonal}
\end{subequations}
Employing these relations we can write
    \begin{align}
		\langle f_h,g_h\rangle =& \vec f^{\mathrm{T}}(\Eins\otimes W)\vec g
		= \bar{\vec f}^{\mathrm{T}}(\Eins\otimes S)\bar{\vec g}
    \end{align}
    and \begin{align}
        F = TB^{\mathrm{T}}W.
        \label{eq:transformation}
    \end{align}
Furthermore, we note that
\begin{subequations}
    \begin{align}
        M_{ij} &:= \int_{-h/2}^{h/2} p_i\left(\frac{2}{h} x\right)\partial_xp_j\left(\frac{2}{h} x\right) \dx\\
		R_{ij} &:= p_i(1)p_j(1) = 1 = R^{\mathrm{T}}_{ij}\\
		L_{ij} &:= p_i(-1)p_j(-1) = (-1)^{i+j} = L^{\mathrm{T}}_{ij}\\
        RL_{ij}&:= p_i(1)p_j(-1) = (-1)^j\\
		LR_{ij}&:= p_i(-1)p_j(1) = (-1)^i = RL^{\mathrm{T}}_{ij}.
    \end{align}
    \label{eq:legendre_operators}
\end{subequations}
In order to compute the elements of $M_{ij}$ we first note that $M_{ij} = 0$ for
$i > j-1$ as $\partial_x p_j(x)$ is a polynomial of degree $j-1$. Then
we use integration by parts to show that
\begin{align}
	(M+L) = (R-M)^{\mathrm{T}}.
    \label{eq:legendre_derivative}
\end{align}
Therefore, we conclude that $M_{ij} = 1 - (-1)^{i+j}$ for $i\le (j-1)$.

We introduce the notation~\eqref{eq:diagonal} and~\eqref{eq:legendre_operators} mainly for ease of implementation. If a block-matrix class is written and the
operations $+$, $-$ and $*$ are defined on it, the assembly of the derivative
matrices is simplified to a large extent.

%Note that $\forall n\in\mathbb{N}$ and $x\in[-1,1]$
%    $p_n(1) = 1$ and
%    $p_n(-x) = (-1)^np_n(x)$.
%For $P=4$ we have e.g.
%\begin{align}
%    D = \begin{pmatrix}
%        0 & 2 & 0 & 2 \\
%        0 & 0 & 2 & 0 \\
%        0 & 0 & 0 & 2 \\
%        0 & 0 & 0 & 0
%    \end{pmatrix}
%    \label{eq:example_derivative}
%\end{align}
%

\subsection{Indefinite Integrals}\label{sec:integrals}
The approximation of an indefinite integral $\int_a^x f_h(x')\dx'$ is a bit more involved since the integration
boundary $x$ does not need to coincide with a cell boundary.
First, integrating the Legendre differential equation
$\frac{\d}{\dx}\left[ (1-x^2) \frac{\d}{\dx}p_j(x) \right] + j(j+1)p_j(x) = 0$
and with the help of Eq.~\eqref{eq:recursion} and a second recursion for Legendre-Polynomials
$(x^2-1) \d p_j(x)/\dx = jxp_j(x) - j p_{j-1}(x)$
we compute
\begin{align}
\int_{-1}^{x} p_0(x')\dx' = p_1(x)+p_0(x) \quad \int_{-1}^{x} p_j(x') \dx'  = \frac{ p_{j+1}(x) - p_{j-1}(x)}{2j+1}\quad \forall\ j>0
\end{align}
Notice that the integral of a polynomial of order $P$ yields a polynomial of order $P+1$.
The projection integral onto a base polynomial $p_i(x)$ yields
\begin{align}
 N_{00} &:= \int_{-1}^{1} p_0(x) \int_{-1}^{x} p_0(x') \dx' \dx = 2\quad
 %N_{i0} := \int_{-1}^{1} p_i(x) \int_{-1}^{x} p_0(x') \dx' \dx = \frac{2}{2i+1}\delta_{i1}\quad
 \nonumber\\
 N_{ij} &:= \int_{-1}^{1} p_i(x) \int_{-1}^{x} p_j(x') \dx' \dx
= \frac{2}{(2i+1)(2j+1)}\left[\delta_{i(j+1)}-\delta_{i(j-1)}\right] \quad i,j\neq 0,0
\end{align}

Our idea is to split the integral $F_h(x) = \int_a^x f_h(x')\dx'$ into two parts:
\begin{align}
F_h(x):=\int_a^x f_h(x') \dx' = \int_a^{x_{n-1/2}} f_h(x')\dx' + \int_{x_{n-1/2}}^x f_h(x') \dx'
\end{align}
where $n$ is the cell number such that $x_{n-1/2}\leq x < x_{n+1/2}$.
Inserting $f_h(x) = \bar f_{nj} p_{nj}(x)$ and projecting onto a base polynomial $p_{ni}(x)$ yields
\begin{align}
\bar F_{nk} := T_{ki}\int_{x_{n-1/2}}^{x_{n+1/2}} p_{ni}(x) \int_a^x f_h(x') \dx'\dx
= \delta_{k0} \sum_{m=1}^{n-1} h\bar f_{m0} + \frac{h^2}{4}T_{ki}N_{ij} \bar f_{nj}
\end{align}
where we choose the proper normalization $h^2/4$ due to the double integrals in $N_{ij}$.
Notice that if $f_h(x)$ is discretized using $P$ polynomial coefficients $F_h(x)$ would in
principle need $P+1$ coefficients to be the exact integral.
However, we usually truncate the coefficients at $P$ to match the order of the discretization.
Numerical tests show that the corresponding truncation error is extremely small.

\subsection{ Discretization of first derivatives} \label{sec:firstderivatives}
From here on we write
$ f_h(x) = \bar f^{ni}p_{ni}(x)$ and imply the summation over cell index $n$ and polynomial
index $i$.
The first naive idea to get an approximation to the first derivative of $f_h(x)$
is to simply set $f_x(x) = \partial_x f_h(x) = \bar f^{ni}\partial_x p_{ni}(x)$ in
the interior of each cell $n$.
Unfortunately, in this approach we loose one polynomial order and the discretization for
$P=1$ is plain wrong. We would
like our discretization to become finite differences in the limit $P=1$.

On cell boundaries the derivative
of $p_{ni}(x)$ is actually not well defined, which is why we now retain to
a weak formulation of derivatives.
Consider
\begin{align}
    \int_{C_n} \partial_x f_h(x) p_{ni}(x) \dx = f_h p_{ni}|_{x_{n-1/2}}^{x_{n+1/2}}  -
    \int_{C_n} f_h(x) \partial_x p_{ni}(x) \dx.
    \label{}
\end{align}
The approximation $f_h(x)$ is double valued on the cell boundaries, which is why we replace
the boundary terms by
\begin{align}
    \int_{C_n} f_x p_{ni}(x) \dx
    = \hat f p_{ni}|_{x_{n-1/2}}^{x_{n+1/2}}  -
    \int_{C_n} \bar f^{nk} p_{nk} \partial_x p_{ni} \dx,
    \label{}
\end{align}
where $\hat f(x)$ is the numerical flux across cell boundaries and we call $f_x(x)$ the numerical approximation to the first derivative. We will use three different fluxes in this work.
\begin{subequations}
\begin{align}
	\hat{f_C}(x) &= \tfrac{1}{2}(\lim_{\eps\to 0,\eps>0}f_h(x+\eps)+\lim_{\eps\to 0,\eps>0}f_h(x-\eps)),\\
	\hat{f_F}(x) &= \lim_{\eps\to 0,\eps>0}f_h(x+\eps), \\
	\hat{f_B}(x) &= \lim_{\eps\to 0,\eps>0}f_h(x-\eps),
\end{align}
\end{subequations}
which we call the centered, the forward and the backward flux respectively.
For $f\colon [a,b]\to\mathbb{R}$ and periodic boundary conditions, we assume that
\begin{equation}
	\lim_{\eps\to 0,\eps>0} f(b+\eps) = \lim_{\eps\to 0,\eps>0} f(a+\eps), \qquad
	\lim_{\eps\to 0,\eps>0} f(a-\eps) = \lim_{\eps\to 0,\eps>0} f(b-\eps),
\end{equation}
for homogeneous Dirichlet boundary conditions we assume that
\begin{equation}
    \hat f(a) = \hat f(b) = 0,
\end{equation}
and for homogeneous Neumann boundaries we assume that
\begin{align}
    \hat f(a) = \lim_{\eps\to 0,\eps>0} f_h(a+\eps), \qquad
    \hat f(b) = \lim_{\eps\to 0,\eps>0} f_h(b-\eps).
\end{align}
As we see the choice
of $\hat f$ is not unique. It actually is the crucial ingredient in every dG method.
Depending on what flux we choose, we arrive at various
approximations to the derivative,
e.g. for $P=1$ (i.e. a piecewise constant approximation in each cell)
our scheme reduces to the classic centered, forward and backward finite difference
schemes respectively.
In a way all the ingenuity of a dG method lies in the choice of the numerical flux.

For the following discussion we choose the centered flux $\hat f_C$ and note
that the derivation is analogous for $\hat f_F$ and $\hat f_B$.
We arrive at
\begin{align}
    \bar f_x^{ni}= T^{ij}&\left[ \quad \frac{1}{2} \left(\bar f^{(n+1)k}p_k(-1)+ \bar f^{nk}p_k(1)\right)p_j(1)\right. \nonumber\\
        &\ \ - \left.\frac{1}{2} \left(\bar f^{nk}p_k(-1) + \bar f^{(n-1)k}p_k(1)\right)p_j(-1) - \bar f^{nk} M_{kj} \vphantom{\frac{1}{2}}\right]
    \label{}
\end{align}
where we used that $p_{nk}(x_{n+1/2})\equiv p_k(1)$ and $p_{nk}(x_{n-1/2}) \equiv p_k(-1)$ holds true for all $n$.
Together with the previously defined quantities in~\eqref{eq:legendre_operators} we can write
\begin{align}
	\bar{\mathbf f}_x  &= (\Eins\otimes T)\circ \left[ \frac{1}{2}(\Eins^+\otimes RL + \Eins \otimes (M-M^{\mathrm{T}}) - \Eins^-\otimes LR)\right] \bar{\mathbf f}\nonumber \\
    &=: (\Eins\otimes T) \circ \bar D^0_{x,per} \bar {\mathbf f},
    \label{eq:discrete_der}
\end{align}
using $M+M^{\mathrm{T}} = R-L$ from Eq.~\eqref{eq:legendre_derivative}
and
\begin{align}
    \Eins^{-}f^{n} &:= f^{n-1}\\
    \Eins^{+}f^{n} &:= f^{n+1}.
    \label{eq:operator_one}
\end{align}
We define
\begin{align*}
    D^0_{x,per} := (\Eins\otimes F^T)\circ \bar D^0_{x,per}\circ (\Eins\otimes F).
    \label{}
\end{align*}
If our coefficients are nodal values, we note with the help of Eq.~\eqref{eq:transformation}
\begin{align}
	\mathbf f_x %&= (\Eins\otimes V) (\Eins\otimes F^{\mathrm{T}})
    %\bar M_x^{per}
%\circ (\Eins\otimes F) \mathbf f%\nonumber\\
 = (\Eins\otimes V)\circ D^0_{x,per} \mathbf f,
    \label{eq:matrix_xspace}
\end{align}
where $\bar D_x^{per}$ and $D_x^{per}$ are skew-symmetric matrices.

From Eq.~\eqref{eq:discrete_der} we are now able to show the matrix representation of the one-dimensional discrete derivative for
periodic boundary conditions that can be used
in the implementation
\begin{align}
    \bar D^0_{x,per} = \frac{1}{2}\begin{pmatrix}
		(M-M^{\mathrm{T}}) & RL      &    &   & -LR \\
		-LR  & (M-M^{\mathrm{T}}) & RL &   &     \\
             &  -LR    & \dots   &   &     \\
             &         &    & \dots  & RL    \\
			 RL &         &    & -LR&(M-M^{\mathrm{T}})
    \end{pmatrix}
    \label{eq:dxcentered}
\end{align}
We also write down the expressions resulting from the forward and backward fluxes $\hat f_F$ and $\hat f_B$ respectively:
\begin{align}
    \bar D^+_{x,per} = \begin{pmatrix}
        -(M+L)^{\mathrm{T}} & RL      &    &   & 0 \\
		 0   & -(M+L)^{\mathrm{T}} & RL &   &     \\
             &    0   & \dots   &   &     \\
             &         &    & \dots  & RL    \\
			 RL  &         &    & 0 & -(M+L)^{\mathrm{T}}
    \end{pmatrix}
    \label{eq:dxplus}
\end{align}
and
\begin{align}
    \bar D^-_{x,per} = \begin{pmatrix}
		(M+L) & 0      &    &   & -LR \\
		-LR  & (M+L) & 0 &   &     \\
             &   -LR   & \dots   &   &     \\
             &         &    & \dots  & 0    \\
			 0  &         &    & -LR &(M+L)
    \end{pmatrix}.
    \label{eq:dxminus}
\end{align}
Note that for $P=1$ we recover the familiar finite difference approximations of the first derivative.
\input{boundary_terms.tex}
Finally we note the boundary terms for homogeneous Dirichlet and Neumann boundaries
in Table~\eqref{tab:boundary_terms} noticing that only the
corner entries of the matrices change.

Also note that the centered derivative can be viewed as the average of forward
and backward derivative
\begin{align}
    D^0_{x} = \frac{1}{2}\left( D^+_x + D^-_x\right)
\end{align}
This is true for any of the above displayed boundary conditions (periodic,
Dirichlet and Neumann) and can be shown directly from Eqs.~\eqref{eq:dxcentered},
\eqref{eq:dxplus}, \eqref{eq:dxminus}, Table~\eqref{tab:boundary_terms}
and Eq.~\eqref{eq:legendre_derivative}.

In our notation the local character of the dG method is apparent.
To compute the derivative in one cell we only use values of neighboring
cells. Therefore, the method is well suited for parallelization which we
will exploit in our implementation.

The generalization to higher dimensions is immediate.
All the
matrices derived above can readily be extended via the appropriate Kronecker products.
The space complexity of
the matrices derived is $\mathcal{O}(P^2 N)$ in one and $\mathcal{O}(P^3N^2)$ in two dimensions.

Finally, let us remark that we found it practical to always operate on nodal
coefficients, i.e.~we use Eq.~\eqref{eq:matrix_xspace}
for our implementations and thus use $\vec f$ rather than $\bar{\vec f}$ to represent the approximation. Function products are easily computed coefficient-wise, i.e.~we use
\begin{align}
    (fg)_{ni}=f_{ni}g_{ni}
    \label{}
\end{align}
to represent the corresponding products.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Discretization of elliptic equations} \label{sec:elliptic}
We are now ready to discretize the one-dimensional general elliptic equation
\begin{align}
    -\frac{\partial}{\partial x}\left( \chi(x)\frac{\partial \phi}{\partial x}(x)\right) = \rho(x)
    \label{eq:elliptic}
\end{align}
on the interval $[a,b]$. Here, $\chi(x)$ and $\rho(x)$ are given functions.

We either choose periodic, Dirichlet, or Von-Neumann boundary conditions on the
left and right border for $\phi$.
As a first step we rewrite Eq.~\eqref{eq:elliptic} into two first order differential equations and a function product:
\begin{subequations}
\begin{align}
    j'&= \partial_x \phi, \label{eq:polarisationa}\\
    j &= \chi j', \label{eq:polarisationb}\\
    \rho &= -\partial_x j. \label{eq:polarisationc}
\end{align}
\end{subequations}
%Our plan is to now simply use a forward discretization\footnote{
%The choice of forward discretizing the first equation is arbitrary. A backward discretization
%works equally well} for the first equation
Our plan is to simply use one of the discretizations developed in the last
section for the first equation~\eqref{eq:polarisationa}
and its negative adjoint for the third equation~\eqref{eq:polarisationc}.
Recall that the adjoint of a square matrix $A$ is defined by the scalar product, i.e.
\begin{align}
    \vec f^\mathrm{T} (\Eins\otimes W)\circ A\vec g =
    \vec g^\mathrm{T} (A^\mathrm{T}\circ(1\otimes W)) \vec f =:     \vec g^\mathrm{T} (\Eins\otimes W) A^\dagger \vec f. \nonumber
    \label{}
\end{align}
From here we immediately get the relation
\begin{align}
    A^\dagger \equiv (\Eins\otimes V)\circ A^\mathrm{T}\circ (\Eins\otimes W).
    \label{eq:adjoint}
\end{align}
There is a close connection between symmetric, $A=A^\mathrm{T}$, and self-adjoint, $A=A^\dagger$, matrices.
If and only if the matrix $A$ is symmetric, then $(\Eins\otimes V)\circ A$ is self-adjoint. Of course, we have $(AB)^\dagger = B^\dagger A^\dagger$ and $(A^\dagger)^\dagger = A$.

The function product in Eq.~\eqref{eq:polarisationb} is computed pointwisely on the Gaussian abscissas.
\begin{align}
    \vec j' &= (\Eins\otimes V)\circ D_x \vec \phi, \nonumber \\
    \vec j &= \vec \chi \vec j', \nonumber\\
    \vec \rho &= (\Eins\otimes V)\circ D_x^\mathrm{T}\vec j = (\Eins\otimes V) D_x^\mathrm{T}\circ\chi\circ (\Eins\otimes V)\circ D_x \vec \phi,
    \label{eq:naive}
\end{align}
where $D_x$ is either $D_x^+$, $D_x^-$, or $D_x^0$ with the correct boundary terms.
Note, that~\cite{Cockburn2002} originally only proposed to use the forward or backward discretization for $D_x$.
Equation~\eqref{eq:naive} is indeed a self-adjoint
discretization for the second derivative. However, it turns out that
Eq.~\eqref{eq:naive} is inconsistent for given $\rho(x)$. The solution does not converge.
This problem is solved according to~\cite{Cockburn2002} by adding a jump term
to the flux of $j$:
\begin{align}
    \hat j(x_{n+1/2}) \rightarrow \hat j(x_{n+1/2}) + [\phi(x_{n+1/2})],
\end{align}
where $[\phi(x_{n+1/2}]:=\phi^n(x_{n+1/2}) - \phi^{n+1}(x_{n+1/2})$ is the jump term of
$\phi$ at $x_{n+1/2}$. That means we have to alter our discretization~\eqref{eq:naive} according to
\begin{align}
    \rho =  (\Eins\otimes V)[D_x^\mathrm{T}\circ \chi\circ(\Eins\otimes V)\circ D_x  + J]\phi
    \label{eq:discreteelliptic}
\end{align}
where
\begin{align}
    \bar J = \begin{pmatrix}
		(L+R) & -RL      &    &   & -LR \\
		-LR  & (L+R) & -RL &   &     \\
             &   -LR   & \dots   &   &     \\
             &         &    & \dots  & -RL    \\
			 -RL  &         &    & -LR &(L+R)
    \end{pmatrix}.
\end{align}
for periodic boundaries. Again we give the correct boundary terms for Dirichlet
and Neumann boundary conditions in Table~\ref{tab:jump_terms}.
\input{jump_terms.tex}
Note that $J$ is symmetric, thus the overall discretization remains self-adjoint. Indeed, with $D_x = D_x^+$ Eq.~\eqref{eq:discreteelliptic} recovers
the discretization proposed by~\cite{Cockburn2002}.
In addition, we remark that the centered discretization in Eq.~\eqref{eq:discreteelliptic} is symmetric with respect to an inversion of the coordinate system $x\rightarrow -x$ even for double Dirichlet or Neumann boundaries, while the forward and backward discretization is not.

We note again that the generalization to two or more dimensions is straightforward
in a rectangular grid using Kronecker products.
\subsection{Numerical experiments} \label{sec:ellipticexperiments}
As an example we solve Eq.~\eqref{eq:elliptic} in two dimensions for
\begin{align*}
\chi(x,y) &= 1 + \sin(x)\sin(y)\\
\rho(x,y) &= 2\sin(x)\sin(y)\left[\sin(x)\sin(y)+1\right]-\sin^2(x)\cos^2(y)-\cos^2(x)\sin^2(y)
    \label{}
\end{align*}
on the domain $D=[ 0, \pi]\times[0,\pi]$ for double Dirichlet boundary conditions.
The analytical solution is given by $\phi(x,y) = \sin(x)\sin(y)$.

Do not try to insert $\phi$ into Eq.~\eqref{eq:discreteelliptic} directly. The result sub-optimally converges to the analytical $\rho$ or may not converge at all, a phenomenon that is called supraconvergence. Only as a discretization for
elliptic or parabolic equations the stencil~\eqref{eq:discreteelliptic} works fine.

We note that Eq.~\eqref{eq:discreteelliptic}, when multiplied by $(\Eins\otimes W)$, has the form of a symmetric matrix equation
$A\vec x=\vec b$.
This equation is solved by a conjugate gradient method with
$\Eins\otimes V$ as a diagonal preconditioner.
We use a truncation criterion based on the norm of the residuum
\begin{align}
    ||\vec r_k|| < \eps_{res}||\vec b||_{L_2} + \eps_{res}
    \label{}
\end{align}
where $\vec r_k=A\vec x_k - \vec b$ is the residuum of
the $k-th$ iteration. In Table~\ref{tab:polarisation} we summarize our results.
\input{table_polarisation.tex}
We observe that the forward and backward discretizations give the same results,
which is due to the symmetry of the sine functions. The order of the
relative error in the $L_2$-norm coincides with the predicted convergence of order $P$
for all $P$.

On the other side, the centered discretization needs significantly less iterations
to achieve the same error in the residuum. This indicates that the centered
discretization is better conditioned than the forward and backward discretizations.
Also, we observe a superconvergent error of order $P+1$ for $P=3$ and $P=5$. In order to exclude symmetry reasons for these
phenomena, we repeated the computations on the domain $D=[0, \pi/2]\times[0,\pi/2]$ using Dirichlet boundaries on the left
and Neumann boundaries on the right side. We find
equal results; only
the equality in the results for forward and
backward discretization is broken.
To the knowledge of the author this superconvergence has not yet been observed before.

\section{Interpolation and Projection}
Eq.~\eqref{eq:dgexpansion} provides a natural way to interpolate any
dg expanded function $f_h(x)$ on any point in the interval $[a,b]$.
The interpolation has the same order $P$ as the expansion and
can be formulated as a matrix vector multiplication
\begin{align}
f_h(x_0) = \sum_{n=1}^N\sum_{k=0}^{P-1} p_{nk}(x_0) \bar f^{nk} =: \sum_{n=1}^N\sum_{k=0}^{P-1}I_{nk} \bar f^{nk}
\label{eq:basic_interpolation}
\end{align}
where the sparse interpolation matrix $I$ has as many rows as there are
points to interpolate. $I$ has $P^d$ entries per line, where $d$ is the dimensionality of the grid.

\subsection{Interpolation and Projection}
A special case emerges when the list of points to interpolate is made up
by the Gaussian abscissas of another grid.
Suppose we want to divide each cell $C_n$ of the original grid into $M$ equidistant subcells.
We use the letter $c$ to denote the coarse grid and the letter $f$ to denote
the fine grid.
We denote $q_{ml}(x)$ the polynomials on the fine grid and $x^F_{mj}$ the
corresponding Gaussian abscissas.
If a vector $\vec f$ is given on the coarse grid, we can simply interpolate
it onto the fine grid analogous to Eq.~\eqref{eq:basic_interpolation} via
\begin{align}
  f^F_{mj} = f_h(x^F_{mj}) = p_{nk}(x^F_{mj})F^{ki} f^C_{ni}  =: {Q_{mj}}^{ni} f^C_{ni}
  \label{eq:interpolation}
\end{align}
where we denote the special interpolation matrix with $Q$ and implicitly assume the sum of repeated indices.
No information is lost in this process if the cells $C_n$ are divided by an
integer number $M$ and the number of polynomials is the same, i.e.
$f^F$ and $f^C$ represent exactly the same expansion $f_h(x)$.
\begin{align}
  f^C(x) = \bar f_C^{nk}p_{nk}(x) = f^F(x) = \bar f_F^{ml}q_{ml}(x)
  \label{eq:no_loss}
\end{align}

Vice versa, given an expansion $f^F(x)$ on the fine grid, we can compute the projection integrals from the fine grid to the coarse grid.
It can be shown that
\begin{align}
  \bar f_C^{nk} &:= T_C^{ks}\int \dx f^F(x)p_{ns}(x) = T_C^{ks}  W_m^{ij}p_{ns}(x_{mj}) f^F_{mi} \\
  f^C_{nt} &= B_{tk}\bar f_C^{nk} = V^c_{tk}  {{(Q^T)}^{nk}}_{mj}W_m^{ji} f^F_{mi} =: {P_{nt}}^{mi} f^F_{mi}
  %\bar f_C^{nk} = T_C^{ks}\int \dx f^F(x)p_{ns}(x) = T_C^{ks} \bar f_F^{ml} \int \dx q_{ml}(x)p_{ns}(x) \\
  %= T_C^{ks} F^{lo}f^F_{mo} \int \dx q_{ml}(x)p_{ns}(x)  \\
  %= T_C^{ks} F^{lo}f^F_{mo} W_F^{ij}q_{ml}(x_{mi})p_{ns}(x_{mj})  \\
  %= T_C^{ks} F^{lo}f^F_{mo} W_m^{ij}B_{il}p_{ns}(x_{mj})  \\
  %= T_C^{ks} f^F_{mi} W_m^{ij}p_{ns}(x_{mj})  \\
  %f^C_{nt} = B_{tk}\bar f_C^{nk} = B_{tk} T_C^{ks} W_m^{ij} p_{ns}(x_{mj}) f^F_{mi}\\
  %= V^c_{tk} F^{sk} W_m^{ij} p_{ns}(x_{mj}) f^F_{mi}\\
  %= V^c_{tk}  {Q_{mj}}^{nk}W_m^{ji} f^F_{mi}\\
  %= V^c_{tk}  {{(Q^T)}^{nk}}_{mj}W_m^{ji} f^F_{mi}\\
  %=: {P_{nt}}^{mi} f^F_{mi}
  \label{eq:basic_projection}
\end{align}
from where we directly conclude that
\begin{align}
  P = Q^\dagger = V^C Q^T W_F
  \label{eq:projection_adjoint}
\end{align}
i.e. the projection matrix is the adjoint of the interpolation matrix.
We can also proof that
\begin{align}
  P\circ Q = 1_C
  \label{}
\end{align}
which is a reformulation of Eq.~\eqref{eq:no_loss}.
Note that $Q\circ P \neq 1$.
The projection is not loss-free but it conserves the integral
value of the function on the fine grid and the error in the
$L_2$-norm between the vectors on fine and coarse grid is
minimal (proof?).
\subsection{Grid transformations}
The above transformation Eq.~\eqref{eq:projection_adjoint} is
valid only if the number of cells in the fine grid is an integer multiple of the number of cells in the coarse grid.
If this is not the case, the adjoint of the interpolation matrix
does not(!) give a valid projection matrix (tried this
out in the code).
However, what we can always do is to find the least common multiple grid (c) of two given grids (a) and (b). Then
we can interpolate loss-free from the given grid (a) to the
common grid (c) and then project back from (c) to (b).
In this way we get the forward and backward transformation matrices
\begin{align}
    \mathcal T &= P_{c2b}Q_{a2c}\\
    \mathcal T^\dagger &= P_{c2a} Q_{b2c}
    \label{}
\end{align}
If the least common grid reduces to either grid (a) or (b) the
transformation matrix reduces to either $P_{a2b}$ or $Q_{a2b}$ as expected.

\section{Relation to finite element space}
The list of nodal values $f_i$ gives a direct possibility to convert from dG to a finite element space (with linear elements):
\begin{align} \label{eq:fem}
    f_{\text{FE}}(x) = f_{i} v_{i}(x)
\end{align}
where the linear elements $v_i(x)$ are given by
\begin{align}\label{eq:linear_fem}
    v_0(x) &= \begin{cases}
        1 \text{ if } x_{a}\leq x<x_{0} \\
        \frac{x_{1} - x}{x_{1} - x_{0}} \text{ if } x_{0}\leq x<x_{1} \\
         0 \text{ else}
    \end{cases}
    \\
    v_{i}(x) &= \begin{cases}
        \frac{x - x_{i-1} }{x_{i} - x_{i-1}} \text{ if } x_{i-1}\leq x<x_{i} \\
        \frac{x_{i+1} - x}{x_{i+1} - x_{i}} \text{ if } x_{i}\leq x<x_{i+1} \\
         0 \text{ else}
    \end{cases}
    \\
    v_{N-1}(x) &= \begin{cases}
        \frac{x - x_{N-2} }{x_{N-1} - x_{N-2}} \text{ if } x_{N-2}\leq x<x_{N-1} \\
        1 \text{ if } x_{N-1}\leq x<x_{b} \\
         0 \text{ else}
    \end{cases}
\end{align}
The first and the last element begin/end in a constant rather than a linear function
seeing that these points have no left /right neighbor to interpolate towards.
We have $f_{\text{FE}}(x_{i}) = f_{i}$. Eq.~\eqref{eq:fem} gives an alternative
interpolation method, which amounts to linear interpolation between the two nearest
points. Unfortunately, the linear base functions~\eqref{eq:linear_fem} are not
orthogonal, that is the "mass" matrix of projection integrals $S_{ij} = \int \dx v_i(x)v_j(x)$ is a banded matrix with three diagonals.
We can compute the entries from a reference element $[-1,1]$
with the dG absicssas $x_j^a$, scaled by $h/2$
\begin{align}
    &S_{ij} := \int v_i(x)v_j(x)\dx\\
    &S_{0j} := \frac{h}{2} \frac{1}{6}\begin{pmatrix}
        6(x^a_0+1) + 2(x^a_1-x^a_0) & (x^a_1-x^a_0) & 0 \ldots
    \end{pmatrix}
    \nonumber\\
    S &:= \frac{h}{2}\frac{1}{6}\begin{pmatrix}
        (x^a_0-(x^a_{P-1}-2)) & 2(x^a_1 - (2-x^a_{P-1})) & (x^a_1 - x^a_0) & 0 & 0 \\
        0 & (x^a_{k} - x^a_{k-1}) & 2(x^a_{k+1}-x^a_{k-1}) & (x^a_{k+1} - x^a_k) & 0 \\
        0 & 0 & (x^a_{P-1} - x^a_{P-2}) & 2( (x^a_0+2) - x^a_{P-2}) & ((x^a_0+2)- x^a_{P-1})
    \end{pmatrix}
    \nonumber\\
    &S_{(N-1)j} := \frac{h}{2} \frac{1}{6}\begin{pmatrix}
        \ldots 0 &(x^a_{P-1} - x^a_{P-2}) & 2(x^a_{P-1} - x^a_{P-2}) + 6( 1 - x^a_{P-1})
    \end{pmatrix}
\end{align}
Note that $S$ is diagonally dominant (on an equidistant grid the diagonal entry is twice as large as the sum of the two entries on the same row).
%What to do for periodic boundaries? or Dirichlet?
Thus reference element consists of the $P\times(P+2)$ blocks $hS_{\text{ref}}/2$.
The weights of the finite element discretization consist of the base elements
$h_k = (x^a_{k+1}-x^a_{k-1})2$.
\begin{align} \label{eq:fem_weights}
    W_k &= \sum_j S_{kj}\leftarrow W = S\cdot \Eins \\
    W_k &= \frac{h}{4}\left( (x^a_1 - (x^a_{P-1}-2)),\ \ldots, (x^a_{k+1}-x^a_{k-1}),\ \ldots, ( (x^a_0+2) - x^a_{P-2})\right)
\end{align}
Note that the formula for the left and right internal cell boundaries hold for the domain boundaries as well
due to the equidistance in the dG cells $x^a_{P-1} = -x^a_0 $.
We here realize that $W^{-1}S$  is a smoothing kernel that represents the
integration $w_k^{-1} \int f(x) v_k(x)\dx$.
Also note that for an equidistant grid the stencil of $S$ reads $(1,4,1)$, which
corresponds to Simpson's integration formula.

\subsection{Interpolation and projection}
Eq.~\eqref{eq:fem} gives a direct interpolation formula. If we take the existing
nodes $x_i$, we can refine the grid by inserting points in between the existing points.
Let us call the resulting interpolation matrix $I$. Then
it can be shown that
\begin{align}
    I^\mathrm{T} W_f I = S
\end{align}
where $W_f$ are the integration weights (Simpson's 1/3 or 3/8 rule) on the fine grid.
Thus, the adjoint of the interpolation matrix yields a projection integral $\bar f_j = \int \dx v_j(x) g(x)$, which must be inverted with $f_i = S_{ij}^{-1} \bar f_j$.
This inversion is the main downside of the FEM method compared to the dG method
as it can take a significant amount of time.

\section{Spectral and modal filtering techniques}
It is well known from Godunov's theorem that linear high order schemes for hyperbolic (advection) problems
are prone to oscillations. Discontinuous Galerkin methods are no different in that regard
especially the higher order ones and if the numerical flux $f=nu$ is computed via pointwise multiplication
of the nodal representations of $n$ and $u$ via $f_{ni} = n_{ni} u_{ni}$~\cite{NodalDG}.
This is due to aliasing effects. Recall that pointwise multiplication is different from
actually multiplying the two polynomials $n_h$ and $u_h$ and projecting the result back onto the
lower polynomial space. The problem is also known in pure spectral methods like
Fourier representations.

In finite difference and Fourier codes what is often done is adding so-called hyperdiffusion
(or \textbf{spectral viscosity}) to stabilize a purely hyperbolic system.
\begin{align}
    \partial_t n + \partial_x( nu) = \nu (-1)^{s+1}\partial_x^{2s} n
\end{align}
Since Fourier modes are Eigenfunctions of the Laplace operator this equation reads in Fourier space (disregaring the convection term)
\begin{align}
    \partial_t n_k = -\nu k^{2s} n_k
\end{align}
which when discretized in time using the Euler method reads
\begin{align}
    n_k^{n+1} = (1-\nu\Delta t k^{2s}) n_k^{n}
\end{align}
Here we see that the damping of modes is highest for large wave-numbers and leaves small wave-numbers intact.
This can be read in a more general setting as applying a low-pass filter $\sigma(k)$ to the solution that acts on large wavenumbers
\begin{align}
    n_k^{n+1} = \sigma(k) n_k^{n}
\end{align}
where often $\sigma(k) = \exp( - \nu \Delta t k^{2s})$ is proposed. The above Euler discretization is
then obtained by Taylor-expanding the exponential
(an implicit Euler is obtained with the Pade approximation of the expontential).

It is now possible to also discretise the hyperdiffusion directly in a dG framework, however, this
has downsides regarding the performance since the Laplace operator is much more expensive than a
simple pointwise multiplication as done in Fourier codes and its solution likely needs to be done implicitly
in order to preserve the time-step restrictions.

The better solution in a dG framework is to apply \textbf{modal filtering} and is motivated in much the same
way as the spectral viscosity above.
First we consider that the Legendre polynomials satisfy a Sturm-Liouville type differential equation.
\begin{align}
    \frac{d}{\d x} \left[ (1-x^2) \frac{ d }{d x} \right]p_n(x) = -n(n+1) p_n(x) \quad x \in [-1,1]
\end{align}
This means that the Legendre polynomials are Eigenfunctions of the Sturm-Liouville operator. If we write
\begin{align}
    \partial_t n = \nu (-1)^{s+1}\left[\frac{d}{\d x}  m(x) \frac{ d }{d x} \right]^s  n
\end{align}
where $m(x)$ is $(1-x^2)$ properly scaled onto each discrete cell, and use a dG approach to discretize this equation we get for each mode
\begin{align}
    \partial_t n_k = -\nu (k(k+1))^s  n_k
\end{align}
or in a time-discreized way
\begin{align}
    n_k^{n+1} = (1-\nu \Delta t (k(k+1))^s ) n_k^n
\end{align}
which is entirely analogous to the derivation above.
In the same way we can read this as applying a filter function to the Legendre modes.
\begin{align}
    n_k^{n+1} = \sigma(k) n_k^n
\end{align}
with $\sigma(k) = \exp( - \nu \Delta t (k(k+1))^s)$.
Note that the modal filter, as the spectral filter, does not inhibit oscillations from happening (it is not shock-capturing) but it dampens grid-scale oscillations
and can stabilize the system.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bibliography{../references}
%..................................................................
\end{document}


\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage[margin=0.75in]{geometry}
\usepackage[numbers]{natbib}
\usepackage{physics}
\usepackage[hyphens]{url}
\usepackage[labelformat=simple,position=b]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{cosmiQ}
\lhead{Hackathon 2021}
\rfoot{Page \thepage}

\usepackage{graphicx}
\graphicspath{
	{figures}
}

\usepackage[hidelinks]{hyperref}

\renewcommand{\phi}{\varphi}

\title{Hackathon Docs}
\author{cosmiQ}
\date{\today}

\begin{document}

\maketitle

%\thispagestyle{empty}
\section*{Introduction}

The main problem of interest is of the form:
\begin{align}
\mathcal{H} &= \sum_{t_0}^{t_f} \sum_i -\mu(t,i) \hat{w}(t,i) + \sum_{t_0+1}^{t_f} \left(\sum_i \lambda(t,i) \hat{w}(t,i) - \hat{w}(t-1,i) \right)^2 +  \left(\sum_i \lambda(t_0,i) \hat{w}(t_0,i)\right)^2\nonumber\\
&+ \frac{\gamma}{2} \sum_{t_0}^{t_f} \sum_{ij} \hat{w}(t,i) \Sigma^t_{ij} \hat{w}(t,j) + \rho \left(\sum_i \hat{w}(t,i) - 1\right)^2
\end{align}

To further represent it on a quantum computer we use the following:
\begin{align}
\hat{w}(t,i) = \frac{1}{K}\sum_q^{N_q} d^q \hat{n}(t,i,q),
\end{align}
where utilize $N_q$ physical bits of local dimension $d$. For quitrits $d = 3$. We also use $N_t$ number of time samples and $N$ number of assets (indexed by $i$). Typically $K$ is used to control the precision or resolution. For normal circumstance $K = d^{N_q}$ is sufficient. Here $\mu(t,i)$ represents the profit over the incremental timer interval of assessment. The terms $\lambda(t,i)$ control the transactions and is written in this form to allowed time-dependence as well as asset class dependence. $\Sigma^t_{ij}$ are the terms in the covariance matrix and $\gamma$ controls the penalty for allowing volatile assets. $\rho$ is the Lagrange multiplier useful to control the constraint.

From which we obtain the following compact set of equations:
\begin{align}
\mathcal{H} &= \sum_{t_0}^{t_f} \sum_i \sum_q (-\mu(t,i) - 2\rho) \frac{d^q}{K} \hat{n}(t,i,q) \nonumber\\
&+  \sum_{t_0}^{t_f} \sum_{i<j} \sum_{q<p} 4(\frac{\gamma}{2} \Sigma^t_{ij} + \lambda(t,i)\lambda(t,j) + \rho)\frac{d^{p+q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,j,p) \nonumber\\
&+  \sum_{t_0}^{t_f} \sum_{i<j} \sum_{q} 2 (\frac{\gamma}{2} \Sigma^t_{ij} + \lambda(t,i)\lambda(t,j) + \rho)\frac{d^{2q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,j,q) \nonumber\\
&+  \sum_{t_0}^{t_f} \sum_{i} \sum_{q<p} 2 (\frac{\gamma}{2} \Sigma^t_{ij} + \lambda(t,i)^2 + \rho)\frac{d^{p+q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,i,p) \nonumber\\
&+  \sum_{t_0}^{t_f} \sum_{i} \sum_{q}  (\frac{\gamma}{2} \Sigma^t_{ii} + \lambda(t,i)^2 + \rho)\frac{d^{2q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,i,q) \nonumber\\
%%
&+  \sum_{t_0}^{t_f-1} \sum_{i<j} \sum_{q<p} 4(\lambda(t,i)\lambda(t,j))\frac{d^{p+q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,j,p) \nonumber\\
&+  \sum_{t_0}^{t_f-1} \sum_{i<j} \sum_{q} 2 (\lambda(t,i)\lambda(t,j))\frac{d^{2q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,j,q) \nonumber\\
&+  \sum_{t_0}^{t_f-1} \sum_{i} \sum_{q<p} 2 (\lambda(t,i)^2)\frac{d^{p+q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,i,p) \nonumber\\
&+  \sum_{t_0}^{t_f-1} \sum_{i} \sum_{q} 2 (\lambda(t,i)^2)\frac{d^{p+q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,i,q) \nonumber\\
%%
&+  \sum_{t_0}^{t_f-1} \sum_{i<j} \sum_{q<p} (-8)(\lambda(t+1,i)\lambda(t+1,j))\frac{d^{p+q}}{K^2} \hat{n}(t+1,i,q)\hat{n}(t,j,p) \nonumber\\
&+  \sum_{t_0}^{t_f-1} \sum_{i<j} \sum_{q} (-4)(\lambda(t+1,i)\lambda(t+1,j))\frac{d^{2q}}{K^2} \hat{n}(t+1,i,q)\hat{n}(t,j,q) \nonumber\\
&+  \sum_{t_0}^{t_f-1} \sum_{i} \sum_{q<p} (-4) (\lambda(t+1,i)^2)\frac{d^{p+q}}{K^2} \hat{n}(t+1,i,q)\hat{n}(t,i,p) \nonumber\\
&+  \sum_{t_0}^{t_f-1} \sum_{i} \sum_{q} (-2) (\lambda(t+1,i)^2)\frac{d^{p+q}}{K^2} \hat{n}(t+1,i,q)\hat{n}(t,i,q) \nonumber\\
&+ N_t
\end{align}

These equations have been encoded in the file flatnetwork.py. That file sets up our DMRG calculations, which we use to test the quality of more approximate solutions via quantum hardware or simulation. A simpler version of the equations above can be obtained if we ignore transaction costs and volatility. This serves a useful step towards testing solutions and assessing behaviour (not to mention debugging). These equations are given by:

\begin{align}
\mathcal{H} &= \sum_{t_0}^{t_f} \sum_i \sum_q (-\mu(t,i) - 2\rho) \frac{d^q}{K} \hat{n}(t,i,q)
+  \sum_{t_0}^{t_f} \sum_{i} \sum_{q}  (\rho)\frac{d^{2q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,i,q) \nonumber\\
&+  \sum_{t_0}^{t_f} \sum_{i} \sum_{q<p} 2 (\rho)\frac{d^{p+q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,i,p) \nonumber\\
&+  \sum_{t_0}^{t_f} \sum_{i<j} \sum_{q} 2 (\rho)\frac{d^{2q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,j,q) \nonumber\\
&+  \sum_{t_0}^{t_f} \sum_{i<j} \sum_{q<p} 4(\rho)\frac{d^{p+q}}{K^2} \hat{n}(t,i,q)\hat{n}(t,j,p) \nonumber\\
\end{align}

\end{document}


\subsection{Bonus: Gaussian Curvature and Pizza}
Choose a normal of a surface and consider planes containing that normal.
We can draw many curves on the surface now by considering the intersection of the planes and the surface and measure their curvatures at that particular point.
\begin{definition}
    The Gaussian curvature is defined as
    $$K_G=K_{\rm max} K_{\rm min}$$
    where $K_{\rm max}$ and $K_{\rm min}$ are the maximal and minimal curvatures of such curves.
\end{definition}
For example, a flat piece of paper has $K_G=0$.
Of course, we can define this much more rigorously, but that is out of the scope of this course.
For this definition of surface curvature, Gauss proved that:
\begin{theorem}[Theorema Egregium]
    The Gaussian curvature is invariant under isometries.
\end{theorem}
So it is like when you bend a pizza isometrically, since it still has Gaussian curvature $0$ as it had before, the pizza has to be flopped up so as to be eaten.


\section{Appendix A: Separation Distance from Second Moments}\label{sec:appA}

From the LSST catalogs the following {\tt Object} table elements are used to define the parameters needed to calculate the separation distance \citedsp{LSE-163}:

\begin{center}
\begin{tabular}{ccll}
\hline
Parameter & Unit & Table Element & Description \\
\hline
$x_{\rm trans},y_{\rm trans}$ & $\rm degrees$ & {\tt DIAObject} {\tt radec} & transient centroid  \\
$x_{\rm gal},y_{\rm gal}$       & $\rm degrees$ & {\tt Object} {\tt radec}       & galaxy centroid      \\
$\overline{x^2}$,$\overline{y^2}$,$\overline{xy}$ & $\rm arcsec^2$  & {\tt Object} {\tt Ixx}, {\tt Iyy}, {\tt Ixy} & galaxy second moments \\
\hline
\end{tabular}
\end{center}

There might be an issue with using the {\tt Object} catalog second moments: the {\tt Ixx}, {\tt Iyy}, and {\tt Ixy} are defined with with respect to the local tract/patch and not sky coordinates (Jira DM-19519).
Although the local tangent projection will probably work fine for this application of the second moments, this should be verified at the time of implementation.

As described in Section 10 of E. Bertin's Source Extractor manual\footnote{Version 2.3: \url{https://www.astromatic.net/pubsvn/software/sextractor/trunk/doc/sextractor.pdf}} (and presumably many other places), the unitless ellipse parameters $C_{xx},C_{yy},C_{xy}$ can be calculated from the second moments via:

\begin{equation}
C_{xx} = \frac{\overline{y^2}}{\sqrt{ \left( \frac{\overline{x^2}-\overline{y^2}}{2} \right)^2 + \overline{xy}^2}}
\end{equation}

\begin{equation}
C_{yy} = \frac{\overline{x^2}}{\sqrt{ \left( \frac{\overline{x^2}-\overline{y^2}}{2} \right)^2 + \overline{xy}^2}}
\end{equation}

\begin{equation}
C_{xy} = -2 \frac{\overline{xy}}{\sqrt{ \left( \frac{\overline{x^2}-\overline{y^2}}{2} \right)^2 + \overline{xy}^2}}
\end{equation}

The sky distances between the transient and galaxy centroids are calculated as follows, and include the $\cos(\delta)$ factor and a conversion from units of degrees to arcseconds:

\begin{equation}
x_r = 3600(x_{\rm SN} - x_{\rm gal})
\end{equation}

\begin{equation}
y_r = 3600(y_{\rm SN} - y_{\rm gal})\cos{y_{\rm gal}}
\end{equation}

Finally, the separation distance $R$ in arcseconds is given by:

\begin{equation}
R^2 = C_{xx} x_r^2 + C_{yy} y_r^2 + C_{xy} x_r y_r.
\end{equation}


% !TeX root = thoughts.tex
\section{\label{SEC:tom}Linear tomography}

In this section the \gls{HMC} sampler is applied to a linear two dimensional tomography problem. These kind of problems might be high dimensional, and I will eveluate two different sizes of models with varying velocity models. With the aid of model and data resolution matrices we are able to link the quality of the inversions to the actual models and measurement configurations.

\begin{figure}
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=\textwidth]{figures/tomography/tomography_1/model_3by7_3s_5r}
		\caption{Parameters of model}
		\label{fig:linear_tomography.model1.parameters}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=\textwidth]{figures/tomography/tomography_1/model_3by7_3s_5r_rays}
		\caption{Ray coverage of model}
		\label{fig:linear_tomography.model1.rays}
	\end{subfigure}
	\caption{Linear tomography model used in the first part of Section~\ref{SEC:tom}, with 21 dimensions. The ray coverage is variable per cell, and can be better analysed in Figure~\ref{fig:linear_tomography.resolution1}}
	\label{fig:linear_tomography.model1}
\end{figure}

\subsection{Straight ray tomography and a first model}
\index{Straight ray solver}In this part, extensive use is made of the MATLAB package written by Naiara Korta Martiartu and Christian B\"ohm (Computational Seismology Group (CSE), ETH Z\"urich). I will leave out the details of this algorithm, as it is perfectly explained in the accompanying manual. The important bit is that the algorithm produces the linear system matrix and synthetic data.

Straight ray tomography is especially suited to test \gls{HMC} for it's forward model is completely linear, and it usually encompasses some interesting correlated parameters and mixed-determined systems.

We'll start by looking at a relatively simple model of 21 dimensions. The region of interest is composed out of 7x3 blocks of 5 meters wide, as depicted in Figure~\ref{fig:linear_tomography.model1.parameters}. In this region, 3 sources and 5 receivers are present, set up as in Figure~\ref{fig:linear_tomography.model1.rays}. This results in $3 \cdot 5 = 15$ data points. The resulting forward matrix $\MatrixVariable{G}$ is therefore of size 15x21. Each block in the model has rays passing through it in a different way, and may be differently resolved then the next block.

\index{Resolution matrix}\textbf{Note, I actually started on this thinking these were resolution matrices, but I read Hansruedi's script wrong. Still, my analysis stands and I wonder what these matrices actually represent.} To visualize this, we employ the parameter (again, not really the) resolution matrix, for equal data covariance given by $\MatrixVariable{G}^T\MatrixVariable{G}$ (which, interestingly enough, is equal to the original proposal of the mass matrix in \gls{HMC}). In this matrix, the diagonal elements define how well resolved each parameter is relatively, while the rows (as well as the columns, the matrix is symmetric) define averaging kernels.

As seen in Figure~\ref{fig:linear_tomography.model1.parameter_resolution}, some parameters are properly resolved, while others are not. Well resolved parameters have higher indices (note that the matrix is normalized, so we can't say anything about absolutely quality). Some parameters also have high off-diagonal elements, which indicates correlation between parameters. This means that if one of these parameters is high, it influences our perception of the other parameter.

Figure~\ref{fig:linear_tomography.model1.data_resolution} shows the data resolution matrix, given by $\MatrixVariable{G}\,\MatrixVariable{R}\,\MatrixVariable{G}^T$ for equal data covariance. This matrix helps us identify which data is relatively important in the resolution of parameters, i.e. which have a large impact on the inversion. For example, data points 7 through 9 have the highest data importance; they relate the  parameter well to the observed value.

The actual resolution matrices for linear systems are identity matrices, providing not so much insight.

\begin{figure}
	\centering
	\begin{subfigure}{.48\textwidth}
		\centering
		\includegraphics[width=\textwidth]{figures/tomography/tomography_1/model_resolution}
		\caption{\index{Resolution matrix!Parameter}Parameter resolution matrix}
		\label{fig:linear_tomography.model1.parameter_resolution}
	\end{subfigure}\;
	\begin{subfigure}{.49\textwidth}
		\centering
		\includegraphics[width=\textwidth]{figures/tomography/tomography_1/data_resolution}
		\caption{\index{Resolution matrix!Data}Data resolution matrix}
		\label{fig:linear_tomography.model1.data_resolution}
	\end{subfigure}
	\caption{Normalized `half' resolution matrices for the model depicted in Figure~\ref{fig:linear_tomography.model1}.}
	\label{fig:linear_tomography.resolution1}
\end{figure}

\paragraph{Velocity model and inversions}
The velocity model used for the synthetic data is a simple homogeneous model with acoustic speed constant at $20000 m/s$. Inversion characteristics are given in Table~\ref{tab:inversion.tom1}. The parameter which is inverted for is slowness, and the prior means is taking as 1.0/1500.0, with a standard deviation of 0.00025 seconds per meter. A consequence of the system being underdetermined is that less resolved parameters will diverge from the real model in the sense that some will tend towards the prior information, which changes correlated parameters to higher values. The means after inversion are given in Figure~\ref{fig:linear_tomography.model1.means} and show this characteristic quite strongly.

\begin{table}[]
	\centering
	\begin{tabular}{r l}
		Number of Samples & 1,000,000 \\
		Number of timesteps & 10 \\
		Length of timestep & 0.1 \\ \hline
		Runtime & 118.324 s \\
		Accepted samples & 108215 \\
		Number of U-Turns & 0
	\end{tabular}
	\caption{Inversion parameters for first tomography inversions.}
	\label{tab:inversion.tom1}
\end{table}

\begin{figure}
	\centering

	\includegraphics[width=1\textwidth]{figures/tomography/tomography_1/tomographyMeans}

	\caption{Means after the initial inversion of approximately 100,000 accepted samples. The parameters at the very horizontal ends of the model are relatively low, probably due to the small entries in the pseudo-resolution matrix. These parameters are not influenced by actual data that much and therefor are pulled more towards the prior informations. At the same time, to compensate for relatively low speeds, parameters in other parts are excessively high. The actual speed in most elements (columns 5 through 20) is however close to the actual forward model of 2000 $m/s$.}
	\label{fig:linear_tomography.model1.means}
\end{figure}

\begin{figure}
	\centering

	\includegraphics[width=0.6\textwidth]{figures/tomography/tomography_1/tomographyCovariance}

	\caption{Parameter covariance of the approximately 100,000 inversion samples. The band of negative correlation of entries $\sigma_i,j$ and $\sigma_{i,j\pm3}$ or $\sigma_{i\pm3,j}$ is generated by blocks that lie next to each other; as one speed goes up, the next and previous horizontal blocks compensate by lowering their speed. This behaviour is upon close inspection also visible for the $\pm6$ bands. Entries in the same model column also experience a kind of grouping, but with positive correlation. The maximum covariance is $3.6 \cdot 10^{-8}$.}
	\label{fig:linear_tomography.model1.covariance}
\end{figure}

\paragraph{Influence of data dimension on performance}
Before we saw the influence of the amount of parameters on the inversion performance. Another possible detrimental factor might be the amount of data, which also alters some computational requirements. The predicted influence is not so big, as in the model propagation the dimension is not increase. The additional computational cost will be mostly present in evaluating misfits and their gradients, but as these numbers are definitely precomputed the influence might be weak.

To test this, we change the amount of receivers in the previously used homogeneous model. Specifically, we add 5 receivers centered in the model blocks starting from the column at $x=25$, working our way to the column $x=5$. This will add 15 data points each step, increasing all the way to 90. Other inversion characteristics remain unchanged.

After each data increase, the model parameters will be better retrieved. Only shown is the last covariance matrix, with 3240 data points. It has relatively less large entries with respect to the largest one. Also the maximum covariance ($2.2 \cdot 10^{-9}$) is lower than the original ($3.6 \cdot 10^{-8}$) for the inversion with 15 data points. The actual runtime is almost not influenced by the amount of data points (number of rows of the forward model).

\begin{figure}
	\centering

	\includegraphics[width=0.5\textwidth]{figures/tomography/tomography_1/increasing_data/performanceData}

	\caption{Algorithm runtime for increasing amount of datapoints. There seems to be no impact on the algorithm performance with an increasing amount of datapoints.}
	\label{fig:linear_tomography.model1.performanceData}
\end{figure}

\begin{figure}
	\centering

	\includegraphics[width=0.6\textwidth]{figures/tomography/tomography_1/increasing_data/tomographyLastCovariance}

	\caption{Normalized covariance matrix of the last inversion from Figure~\ref{fig:linear_tomography.model1.performanceData} with 3240 datapoints. Maximum parameter covariance is $2.2 \cdot 10^{-9}$.}
	\label{fig:linear_tomography.model1.performanceLastCovariance}
\end{figure}
%\begin{figure}
%	\centering
%
%	\includegraphics[width=1\textwidth]{figures/tomography/tomography_2/tomographyModel}
%
%	\caption{Velocity model used for the synthetics of the second tomography inversion. The values of the layer from small to large $y$ are 1800, 1600 and 1400 $m/s$ respectively.}
%	\label{fig:linear_tomography.model2.velocity}
%\end{figure}

\subsection{Generalized momentum}
At this point I wondered about the influence of implementing the generalized momentum. Implementing this however requires the development of some additional theory. To calculate the generalized momentum we need to invert the mass matrix, which is already an interesting problem. Additionally, we'd like to propose momenta that are correlated according to the mass matrix, so we need to sample from a multivariate correlated Gaussian. I'll start with the second problem, as the result of that simplifies our first problem as we'll see later.

\paragraph{Sampling from an $n$-dimensional Gaussian}
Up to now, we've proposed new momenta by regarding the diagonal of the mass matrix as the variance of each mass. By taking the square root of the inverse of the diagonal we obtained standard deviations of each mass, and by setting the mean to zero we drew new momenta using the Box-M\"uller transform.

An extension of this mass matrix interpretation is to regard the off diagonal elements as the covariance between parameters. This yields for an $n \times n$ matrix an $n$-dimensional correlated Gaussian.

\index{Affine transform}First we establish the definition of an affine transformation and it's effect on a normal distribution. The distribution $\mathbf{X} \sim \mathcal{N}_n \left( \bm{\mu}, \bm{\Sigma} \right)$ represent a normal distribution of means $\left[\bm{\mu}\right]_i = \mu_i$ and covariances $\left[ \bm{\Sigma} \right]_{ij} = \sigma_{ij} = \sigma_i \sigma_j \rho_{ij}$ (covariance $\sigma_{ij}$, standard deviation $\sigma_i$ and correlation $\rho_{ij}$). Now, if $\mathbf{Y} = \bm{L} \mathbf{X} + \bm{c}$ is an affine transformation (that is to say, the transform acts linearly on a vector, which it does for matrix-vector multiplication) then the resulting distribution $\mathbf{Y}$ has means $\bm{c} + \bm{L}\bm{\mu}$ and variance $\bm{L} \bm{\Sigma} \bm{L}^T$ (the proof is given in Appendix~\ref{APP:affinenormal}).

If we now sample $\mathbf{X} = \mathcal{N}_n \left( \mathbf{0},\mathbf{I} \right)$ and transform it using $\bm{L}\mathbf{X}$ such that $\bm{L}\bm{I}\bm{L}^T = \bm{L}\bm{L}^T = \bm{\Sigma}$ we have effectively sampled $\mathbf{Y} = \mathcal{N}_n \left( \mathbf{0},\mathbf{\Sigma} \right)$. Changing the means is as easy as adding the mean vector.

\index{Momenta!Drawing}Equipped with this we can now draw from a correlated Gaussian in the following way;
\begin{itemize}
	\item Draw $n$ uncorrelated samples with mean $\mu_i$ = 0 and standard deviation $\sigma_i$ = 1;
	\item Multiple this samples vector with a matrix $M$ ($n \times n$) which transforms $\mathbf{I}$ to $\mathbf{\Sigma}$ during the affine transform;
	\item Add the wanted mean.
\end{itemize}

\index{Cholesky decomposition}The second step, finding an appropriate matrix, is the most complicated part of the process. Luckily, we have proven already that our mass matrix is positive definite. These types of matrices, given that they are self adjoint/Hermitian, are representable by a Cholesky decomposition. The Hermitian property is easily validated; covariances are symmetric and real. The Cholesky decomposition produces a lower triangular matrix $\mathbf{L}$ from a positive definite Hermitian matrix $\mathbf{A}$ with the property:

\begin{align}
	\mathbf{A} = \mathbf{L} \mathbf{L}^\dagger.
\end{align}
Here, $\mathbf{L}^\dagger$ stands for the conjugate transpose of $\mathbf{L}$. For the real matrices we are working with, this simplifies to transposition only. Finding the appropriate affine transform is now reduced to finding the appropriate Cholesky decomposition of $\mathbf{\Sigma}$. To achieve this, the Cholesky-Banachiewicz algorithm is implemented.

\paragraph{Evaluating the generalized momentum}
\index{Momenta!Generalized}
The generalized kinetic energy, extended from Equation~\ref{eq:kineticsimple} according to \cite{neal2011mcmc}, is given as

\begin{gather}
	K(\mathbf{p}) = \frac{1}{2} \mathbf{p}^T \mathbf{M}^{-1} \mathbf{p}.
\end{gather}
\index{Mass matrix!inverse}
The difficulty in evaluating this expression is in calculating the matrix inverse of the mass matrix, which for large systems would result in quite some processing time. But since one already has acquired the Cholesky decomposition we can easily show that:
\begin{gather}
	\mathbf{A} ^{-1} = \left( \mathbf{L} \mathbf{L}^T \right)^{-1} = \left(\mathbf{L}^T\right)^{-1} \left( \mathbf{L} \right) ^{-1}.
\end{gather}
Now, we're still left with a matrix inverse, but inverting a lower triangular matrix is easily done by forward and back substitution algorithms
\footnote{https://en.wikipedia.org/wiki/Triangular\_matrix\#Forward\_and\_back\_substitution}
, obtaining every element of a column row by row when inverting $\mathbf{L} \mathbf{L}^{-1} = \mathbf{I}$. Following that we simply use $({\mathbf{L}^T})^{-1} =({\mathbf{L}^{-1}})^{T} $ and multiply the two inverse matrices to obtain $\mathbf{A}^{-1}$.


\chapter{The PID structure theorem}
The main point of this chapter is to discuss a classification
theorem for finitely generated abelian groups.
This won't take long to do, and if you like, you can read
just the first section and then move on.

However, since I'm here, I will go ahead and state the result as a
special case of the much more general \emph{structure theorem}.
Its corollaries include
\begin{itemize}
	\ii All finite-dimensional vector spaces are $k^{\oplus n}$.
	\ii The classification theorem for finitely generated abelian groups,
	\ii The Jordan decomposition of a matrix from before,
	\ii Another canonical form for a matrix: ``Frobenius normal form''.
\end{itemize}

\section{Finitely generated abelian groups}
\label{sec:FTFGAG}
\begin{remark}
	We talk about abelian groups in what follows, but really the
	morally correct way to think about these structures is as $\ZZ$-modules.
\end{remark}
\begin{definition}
	An abelian group $G = (G,+)$ is \vocab{finitely generated}
	if it is finitely generated as a $\ZZ$-module.
	(That is, there exists a finite collection $b_1, \dots, b_m \in G$,
	such that every $x \in G$ can be written in the form
	$c_1 b_1 + \dots + c_m b_m$ for some $c_1, \dots, c_m \in \ZZ$.)
\end{definition}
\begin{example}
	[Examples of finitely generated abelian groups]
	\listhack
	\begin{enumerate}[(a)]
		\ii $\ZZ$ is finitely generated (by $1$).
		\ii $\Zc n$ is finitely generated (by $1$).
		\ii $\ZZ^{\oplus 2}$ is finitely generated (by two elements $(1,0)$ and $(0,1)$).
		\ii $\ZZ^{\oplus 3} \oplus \Zc9 \oplus \Zc{2016}$ is
		finitely generated by five elements.
		\ii $\Zc3\oplus\Zc5$ is finitely generated by two elements.
	\end{enumerate}
\end{example}
\begin{exercise}
	In fact $\Zc3\oplus\Zc5$ is generated by \emph{one} element.
	What is it?
\end{exercise}
You might notice that these examples are not very diverse.
That's because they are actually the only examples:
\begin{theorem}
	[Fundamental theorem of finitely generated abelian groups]
	Let $G$ be a finitely generated abelian group.
	Then there exists an integer $r$,
	prime powers $q_1$, \dots, $q_m$ (not necessarily distinct) such that
	\[
		G \cong \ZZ^{\oplus r} \oplus \Zc{q_1} \oplus \Zc{q_2} \oplus
		\dots \oplus \Zc{q_m}. \]
	This decomposition is unique up to permutation of the $\Zc{q_i}$.
\end{theorem}
\begin{definition}
	The \vocab{rank} of a finitely generated abelian group $G$ is the integer $r$ above.
\end{definition}

Now, we could prove this theorem, but it is more interesting to go for the gold
and state and prove the entire structure theorem.

\section{Some ring theory prerequisites}
\prototype{$R = \ZZ$.}
Before I can state the main theorem, I need to define a few terms for UFD's,
which behave much like $\ZZ$:
\begin{moral}
	Our intuition from the case $R = \ZZ$ basically carries over verbatim.
\end{moral}
We don't even need to deal with prime ideals and can factor elements instead.

\begin{definition}
	If $R$ is a UFD, then $p \in R$ is a \vocab{prime element}
	if $(p)$ is a prime ideal and $p \neq 0$.
	For UFD's this is equivalent to:
	if $p = xy$ then either $x$ or $y$ is a unit.
\end{definition}
So for example in $\ZZ$ the set of prime elements is $\{\pm2, \pm3, \pm5, \dots\}$.
Now, since $R$ is a UFD, every element $r$ factors into a product of prime elements
\[ r = u p_1^{e_1} p_2^{e_2} \dots p_m^{e_m} \]

\begin{definition}
	We say $r$ \vocab{divides} $s$ if $s = r'r$
	for some $r' \in R$. This is written $r \mid s$.
\end{definition}
\begin{example}
	[Divisibility in $\ZZ$]
	The number $0$ is divisible by every element of $\ZZ$.
	All other divisibility as expected.
\end{example}
\begin{ques}
	Show that $r \mid s$ if and only if the exponent of each prime in $r$ is
	less than or equal to the corresponding exponent in $s$.
\end{ques}

Now, the case of interest is the even stronger case when $R$ is a PID:
\begin{proposition}
	[PID's are Noetherian UFD's]
	If $R$ is a PID, then it is Noetherian and also a UFD.
\end{proposition}
\begin{proof}
	The fact that $R$ is Noetherian is obvious.
	For $R$ to be a UFD we essentially repeat the proof for $\ZZ$,
	using the fact that $(a,b)$ is principal in order to extract
	$\gcd(a,b)$.
\end{proof}

In this case, we have a Chinese remainder theorem for elements.
\begin{theorem}
	[Chinese remainder theorem for rings]
	Let $m$ and $n$ be relatively prime elements, meaning $(m) + (n) = (1)$.
	Then \[ R / (mn) \cong R/(m) \times R/(n). \]
\end{theorem}
Here the ring product is as defined in \Cref{ex:product_ring}.
\begin{proof}
	This is the same as the proof of the usual Chinese remainder theorem.
	First, since $(m,n)=(1)$ we have $am+bn=1$ for some $a$ and $b$.
	Then we have a map
	\[ R/(m) \times R/(n) \to R/(mn) \quad\text{by}\quad
		(r,s) \mapsto r \cdot bn + s \cdot am. \]
	One can check that this map is well-defined and an isomorphism of rings.
	(Diligent readers invited to do so.)
\end{proof}

Finally, we need to introduce the concept of a Noetherian $R$-module.
\begin{definition}
	An $R$-module $M$ is \vocab{Noetherian}
	if it satisfies one of the two equivalent conditions:
	\begin{itemize}
		\ii Its submodules obey the ascending chain condition:
		there is no infinite sequence of modules
		$M_1 \subsetneq M_2 \subsetneq \dots$.
		\ii All submodules of $M$ (including $M$ itself) are finitely generated.
	\end{itemize}
\end{definition}
This generalizes the notion of a Noetherian ring:
a Noetherian ring $R$ is one for which $R$ is Noetherian as an $R$-module.
\begin{ques}
	Check these two conditions are equivalent. (Copy the proof for rings.)
\end{ques}

\section{The structure theorem}
Our structure theorem takes two forms:
\begin{theorem}
	[Structure theorem, invariant form]
	Let $R$ be a PID and let $M$ be any finitely generated $R$-module. Then
	\[ M \cong \bigoplus_{i=1}^m R/(s_i) \]
	for some $s_i$ (possibly zero)
	satisfying $s_1 \mid s_2 \mid \dots \mid s_m$.
	% These $s_i$ are unique up to multiplication by units.
\end{theorem}
\begin{corollary}
	[Structure theorem, primary form]
	Let $R$ be a PID and let $M$ be any finitely generated $R$-module. Then
	\[ M \cong R^{\oplus r}
		\oplus R/(q_1) \oplus R/(q_2) \oplus \dots \oplus R/(q_m) \]
	where $q_i = p_i^{e_i}$ for some prime element $p_i$ and integer $e_i \ge 1$.
	% The numbers $r$ and $q_i$ are unique up to permutation and multiplication by units.
\end{corollary}
\begin{proof}
	[Proof of corollary]
	Factor each $s_i$ into prime factors (since $R$ is a UFD),
	then use the Chinese remainder theorem.
\end{proof}
\begin{remark}
	In both theorems the decomposition is unique up to
	permutations of the summands; good to know, but
	I won't prove this.
\end{remark}

\section{Reduction to maps of free $R$-modules}
\begin{definition}
	A \vocab{free $R$-module} is a module of the form $R^{\oplus n}$
	(or more generally, $\bigoplus_I R$ for some indexing set $I$,
	just to allow an infinite basis).
\end{definition}
The proof of the structure theorem proceeds in two main steps.
First, we reduce the problem to a \emph{linear algebra} problem
involving free $R$-modules $R^{\oplus d}$.
Once that's done, we just have to play with matrices;
this is done in the next section.

Suppose $M$ is finitely generated by $d$ elements.
Then there is a surjective map of $R$-modules
\[ R^{\oplus d} \surjto M \]
whose image on the basis of $R^{\oplus d}$ are the generators of $M$.
Let $K$ denote the kernel.

We claim that $K$ is finitely generated as well.
To this end we prove that
\begin{lemma}[Direct sum of Noetherian modules is Noetherian]
	Let $M$ and $N$ be two Noetherian $R$-modules.
	Then the direct sum $M \oplus N$ is also a Noetherian $R$-module.
\end{lemma}
\begin{proof}
	It suffices to show that if $L \subseteq M \oplus N$,
	then $L$ is finitely generated.
	One guess is that $L = P \oplus Q$,
	where $P$ and $Q$ are the projections of $L$ onto $M$ and $N$.
	Unfortunately this is false
	(take $M = N = \ZZ$ and $L = \{(n,n) \mid n \in \ZZ\}$)
	so we will have to be more careful.

	Consider the submodules
	\begin{align*}
		A &= \left\{ x \in M \mid (x,0) \in L \right\} \subseteq M \\
		B &= \left\{ y \in N \mid \exists x \in M : (x,y) \in L \right\}
			\subseteq N.
	\end{align*}
	(Note the asymmetry for $A$ and $B$: the proof doesn't work otherwise.)
	Then $A$ is finitely generated by $a_1$, \dots, $a_k$,
	and $B$ is finitely generated by $b_1$, \dots, $b_\ell$.
	Let $x_i = (a_i, 0)$ and let $y_i = (\ast, b_i)$ be elements of $L$
	(where the $\ast$'s are arbitrary things we don't care about).
	Then $x_i$ and $y_i$ together generate $L$.
\end{proof}
\begin{ques}
	Deduce that for $R$ a PID, $R^{\oplus d}$ is Noetherian.
\end{ques}
Hence $K \subseteq R^{\oplus d}$ is finitely generated as claimed.
So we can find another surjective map $R^{\oplus f} \surjto K$.
Consequently, we have a composition
\begin{diagram}
	&& K && && \\
	R^{\oplus f} & \ruSurj(2,1) & \rTo_T & \rdInj(2,1)
		& R^{\oplus d} & \rSurj & M
\end{diagram}
Observe that $M$ is the \emph{cokernel} of the linear map $T$,
i.e.\ we have that
\[ M \cong R^{\oplus d} / \img(T). \]
So it suffices to understand the map $T$ well.

\section{Smith normal form}
The idea is now that we have reduced our problem to studying
linear maps $T : R^{\oplus m} \to R^{\oplus n}$,
which can be thought of as a generic matrix
\[ T = \begin{bmatrix}
		a_{11} & \dots & a_{1m} \\
		\vdots & \ddots & \vdots \\
		a_{n1} & \dots & a_{nm}
	\end{bmatrix} \]
for a basis $e_1$, \dots, $e_m$ of $R^{\oplus m}$
and $f_1$, \dots, $f_n$ of $N$.

Of course, as you might expect it ought to be possible to change the
given basis of $T$ such that $T$ has a nicer matrix form.
We already saw this in \emph{Jordan form},
where we had a map $T : V \to V$ and changed the basis
so that $T$ was ``almost diagonal''.
This time, we have \emph{two} sets of bases we can change,
so we would hope to get a diagonal basis, or even better.

Before proceeding let's think about how we might edit the matrix:
what operations are permitted?  Here are some examples:
\begin{itemize}
	\ii Swapping rows and columns, which just corresponds
	to re-ordering the basis.
	\ii Adding a multiple of a column to another column.
	For example, if we add $3$ times the first column to the second column,
	this is equivalent to replacing the basis
	\[ (e_1, e_2, e_3, \dots, e_m) \mapsto (e_1, e_2+3e_1, e_3, \dots, e_m). \]
	\ii Adding a multiple of a row to another row.
	One can see that adding $3$ times the first row to the second row
	is equivalent to replacing the basis
	\[ (f_1, f_2, f_3, \dots, f_n) \mapsto (f_1-3f_2, f_2, f_3, \dots, f_n). \]
\end{itemize}
More generally,
\begin{moral}
	If $A$ is an invertible $n \times n$ matrix we can
	replace $T$ with $AT$.
\end{moral}
This corresponds to replacing
\[ (f_1, \dots, f_n) \mapsto (A(f_1), \dots, A(f_n)) \]
(the ``invertible'' condition just guarantees the latter is a basis).
Of course similarly we can replace $X$ with $XB$
where $B$ is an invertible $m \times m$ matrix;
this corresponds to
\[ (e_1, \dots, e_m) \mapsto (B\inv(e_1), \dots, B\inv(e_m)) \]
Armed with this knowledge, we can now approach:
\begin{theorem}
	[Smith normal form]
	Let $R$ be a PID.
	Let $M = R^{\oplus m}$ and $N = R^{\oplus n}$ be free $R$-modules
	and let $T \colon M \to N$ be a linear map.
	Set $k = \min\{m,n\}$.

	Then we can select a pair of new bases for $M$ and $N$ such that
	$T$ has only diagonal entries $s_1$, $s_2$, \dots, $s_k$
	and $s_1 \mid s_2 \mid \dots \mid s_k$.
\end{theorem}
So if $m > n$, the matrix should take the form
\[
	\begin{bmatrix}
		s_1 & 0 & 0 & 0 & \dots & 0 \\
		0 & s_2 & 0 & 0 & \dots & 0 \\
		\vdots & \vdots & \ddots & \vdots & \dots & \vdots \\
		0 & 0 & 0 & s_n & \dots & 0
	\end{bmatrix}.
\]
and similarly when $m \le n$.
\begin{ques}
	Show that Smith normal form implies the structure theorem.
\end{ques}

\begin{remark}
	Note that this is not a generalization of Jordan form.
	\begin{itemize}
		\ii In Jordan form we consider maps $T : V \to V$;
		note that the source and target space are the \emph{same},
		and we are considering one basis for the space $V$.
		\ii In Smith form the maps $T : M \to N$ are between
		\emph{different} modules, and we pick \emph{two} sets of bases
		(one for $M$ and one for $N$).
	\end{itemize}
\end{remark}

\begin{example}
	[Example of Smith normal form]
	To give a flavor of the idea of the proof,
	let's work through a concrete example with the $\ZZ$-matrix
	\[ \begin{bmatrix}
			18 & 38 & 48 \\
			14 & 30 & 32
		\end{bmatrix}.  \]
	The GCD of all the entries is $2$, and so motivated by this,
	we perform the \textbf{Euclidean algorithm on the left column}:
	subtract the second row from the first row,
	then three times the first row from the second:
	\[
		\begin{bmatrix}
			18 & 38 & 48 \\
			14 & 30 & 32
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			4 & 8 & 10 \\
			14 & 30 & 32
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			4 & 8 & 10 \\
			2 & 6 & 2
		\end{bmatrix}.
	\]
	Now that the GCD of $2$ is present, we move it to the upper-left
	by switching the two rows,
	and then kill off all the entries in the same row/column;
	since $2$ was the GCD all along, we isolate $2$ completely:
	\[
		\begin{bmatrix}
			4 & 8 & 10 \\
			2 & 6 & 2
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			2 & 6 & 2 \\
			4 & 8 & 10
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			2 & 6 & 2 \\
			0 & -4 & 6 \\
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			2 & 0 & 0 \\
			0 & -4 & 6
		\end{bmatrix}.
	\]
	This reduces the problem to a $1 \times 2$ matrix.
	So we just apply the Euclidean algorithm again there:
	\[
		\begin{bmatrix}
			2 & 0 & 0 \\
			0 & -4 & 6
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			2 & 0 & 0 \\
			0 & -4 & 2
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			2 & 0 & 0 \\
			0 & 0 & 2
		\end{bmatrix}
		\mapsto
		\begin{bmatrix}
			2 & 0 & 0 \\
			0 & 2 & 0
		\end{bmatrix}.
	\]
\end{example}

Now all we have to do is generalize this proof to work
with any PID. It's intuitively clear how to do this:
the PID condition more or less lets you perform a Euclidean algorithm.

\begin{proof}
	[Proof of Smith normal form]
	Begin with a generic matrix
	\[ T = \begin{bmatrix}
		a_{11} & \dots & a_{1m} \\
		\vdots & \ddots & \vdots \\
		a_{n1} & \dots & a_{nm}
	\end{bmatrix} \]
	We want to show, by a series of operations (gradually changing the given basis)
	that we can rearrange the matrix into Smith normal form.

	Define $\gcd(x,y)$ to be any generator of the principal ideal $(x,y)$.
	\begin{claim}[``Euclidean algorithm'']
		If $a$ and $b$ are entries in the same row or column,
		we can change bases to replace $a$ with $\gcd(a,b)$
		and $b$ with something else.
	\end{claim}
	\begin{subproof}
		We do just the case of columns.
		By hypothesis, $\gcd(a,b) = xa+yb$ for some $x,y \in R$.
		We must have $(x,y) = (1)$ now (we're in a UFD).
		So there are $u$ and $v$ such that $xu + yv = 1$.
		Then
		\[
			\begin{bmatrix} x & y \\ -v & u \end{bmatrix}
			\begin{bmatrix} a \\ b  \end{bmatrix}
			= \begin{bmatrix} \gcd(a,b) \\ \text{something} \end{bmatrix}
		\]
		and the first matrix is invertible (check this!), as desired.
	\end{subproof}
	Let $s_1 = (a_{ij})_{i,j}$ be the GCD of all entries.
	Now by repeatedly applying this algorithm,
	we can cause $s$ to appear in the upper left hand corner.
	Then, we use it to kill off all the entries in the first
	row and the first column, thus arriving at a matrix
	\[ \begin{bmatrix}
		s_1 & 0 & 0 & \dots & 0 \\
		0 & a_{22}' & a_{23}' & \dots & a_{2n}' \\
		0 & a_{32}' & a_{33}' & \dots & a_{3n}' \\
		\vdots&\vdots&\vdots&\ddots&\vdots \\
		0 & a_{m2}' & a_{m3}' & \dots & a_{mn}' \\
	\end{bmatrix}. \]
	Now we repeat the same procedure with this lower-right
	$(m-1) \times (n-1)$ matrix, and so on.
	This gives the Smith normal form.
\end{proof}

With the Smith normal form, we have in the original situation that
\[ M \cong R^{\oplus d} / \img T \]
and applying the theorem to $T$ completes the proof of the structure theorem.

\section\problemhead
Now, we can apply our structure theorem!
\begin{dproblem}
	[Finite-dimensional vector spaces are all isomorphic]
	A vector space $V$ over a field $k$ has a finite spanning set of vectors.
	Show that $V \cong k^{\oplus n}$ for some $n$.
	\begin{hint}
		In the structure theorem, $k / (s_i) \in \{0,k\}$.
	\end{hint}
\end{dproblem}

\begin{dproblem}
	[Frobenius normal form]
	Let $T : V \to V$ where $V$ is a finite-dimensional vector space
	over an arbitrary field $k$ (not necessarily algebraically closed).
	Show that one can write $T$ as a block-diagonal matrix whose blocks
	are all of the form
	\[
		\begin{bmatrix}
			0 & 0 & 0 & \dots & 0 & \ast  \\
			1 & 0 & 0 & \dots & 0 & \ast  \\
			0 & 1 & 0 & \dots & 0 & \ast  \\
			\vdots&\vdots&\vdots&\ddots&\vdots&\vdots \\
			0 & 0 & 0 & \dots & 1 & \ast  \\
		\end{bmatrix}.
	\]
	(View $V$ as a $k[x]$-module with action $x \cdot v = T(v)$.)
	\begin{hint}
		By theorem $V \cong \bigoplus_i k[x] / (s_i)$ for some polynomials $s_i$.
		Write each block in the form described.
	\end{hint}
\end{dproblem}

\begin{dproblem}
	[Jordan normal form]
	Let $T : V \to V$ where $V$ is a finite-dimensional vector space
	over an arbitrary field $k$ which is algebraically closed.
	Prove that $T$ can be written in Jordan form.
	\begin{hint}
		Copy the previous proof, except using the other form of the structure theorem.
		Since $k[x]$ is algebraically closed each $p_i$ is a linear factor.
	\end{hint}
\end{dproblem}

\begin{problem}
	\gim
	Find two abelian groups $G$ and $H$ which are not isomorphic,
	but for which there are injective homomorphisms
	$G \injto H$ and $H \injto G$.
	\begin{hint}
		The structure theorem is an anti-result here:
		it more or less implies that finitely generated abelian groups won't work.
		So, look for an infinitely generated example.
	\end{hint}
	\begin{soln}
		Take $G = \Zc3 \oplus \Zc9 \oplus \Zc9 \oplus \Zc9 \oplus \dots$
		and $H = \Zc9 \oplus \Zc9 \oplus \Zc9 \oplus \Zc9 \oplus \dots$.
		Then there are maps $G \injto H$ and $H \injto G$,
		but the groups are not isomorphic since e.g.\
		$G$ has an element $g \in G$ of order $3$
		for which there's no $g' \in G$ with $g = 3g'$.
	\end{soln}
\end{problem}


\section[Nonlinear Boson Diffusion Equation]{Thermalization via a Nonlinear Boson Diffusion Equation}
The second part of our discussion of the thermalization process of gluons in relativistic heavy-ion collisions is based on a Nonlinear Boson Diffusion equation (NBDE) derived from the Boltzmann equation using a gradient expansion of the respective collision integral.
\subsection{Derivation of the NBDE}
Our central assumptions are spatial homogeneity of the boson distribution function $f(\mathbf{x},\mathbf{p},t)$ and spherical symmetry in the momentum dependence. These assumptions allow us to simplify the kinetic equations by performing the angular integration. We arrive at the following expression for the single-particle occupation numbers $n_j=n(\varepsilon_j,t)$ in a finite Bose system:
\begin{equation}
\begin{aligned}
\frac{\partial n_1}{\partial t} &= \sum_{\varepsilon_2,\varepsilon_3,\varepsilon_4}\langle V^{2}\rangle \cdot G(\varepsilon_1+\varepsilon_2,\varepsilon_3+\varepsilon_4)\\
&\times \left[(1+n_1)(1+n_2)n_3n_4 - (1+n_3)(1+n_4)n_1n_2\right]
\end{aligned}
\end{equation}
Here $\langle V^{2}\rangle$ is the second moment of the interaction potential and the function $G$ encodes energy conservation\footnote{For an infinite system this is simply a delta function $G(\varepsilon_1+\varepsilon_2,\varepsilon_3+\varepsilon_4)\rightarrow \pi\cdot\delta(\varepsilon_1 + \varepsilon_2 -\varepsilon_3 - \varepsilon_4)$ but in a finite system, as we want to have a look at here, the function may acquire a width due to off-shell scatterings between single-particle states which lie apart in the space of possible energies.}. The different indices $1$ to $4$ indicate the respective particles in the elastic $2\rightarrow 2$ scattering process.\\
\noindent
The collision term on the right hand side can be rewritten in the form of a Master equation (cf. Talha's talk):
\begin{equation}
\frac{\partial n_1}{\partial t} = (1+n_1)\sum_{\varepsilon_4}W_{4\rightarrow 1}n_4	- \sum_{\varepsilon_4}W_{1\rightarrow 4}(1+n_4),
\end{equation}
with the transition probability
\begin{equation}
W_{4\rightarrow 1}=  W_{41}g_1 = \sum_{\varepsilon_2, \varepsilon_3} \langle V^{\phantom{.}2}\rangle G(\varepsilon_1+\varepsilon_2,\varepsilon_3+\varepsilon_4)(1+n_2)n_3
\end{equation}
and $W_{1\rightarrow 4}$ analogously. Here we already introduced the density of states $g_j\equiv g(\varepsilon_j)$ which occur when taking the continuum limit. This also leads us to a replacement of the summations by integrations. Since bosons are interchangeable, $W_{14}=W_{41}$ and
\begin{equation}
		W_{14}=W_{41}=W\left[\frac{1}{2}(\varepsilon_4+\varepsilon_1),\underbrace{\abs{\varepsilon_4-\varepsilon_1}}_{=: x}\right]
	\end{equation}
for the case of a finite system where $G$ acquires a width (cf. footnote on the last page). This means that that the transition probabilities depend only on the absolute energy difference $x$ and they are peaked around $x\simeq 0$.\\
\noindent
Performing a gradient expansion of $n_4$ and $g_4n_4$ around $x\simeq 0$ and introducing the transport coefficients
\begin{align}
	D(\varepsilon,t) = \frac{g_1}{2}\int\limits_0^{\infty}\dd x\ W(\varepsilon_1,x) \ x^2
\end{align}
and
\begin{equation}
		v(\varepsilon,t) = g_1^{-1}\frac{d}{d\varepsilon_1}(g_1D)
\end{equation}
via moments of the transition probability we arrive at a nonlinear partial differential equation for the number density:
\begin{equation}
			\frac{\partial n}{\partial t} = -\frac{\partial}{\partial\varepsilon}\left[v\cdot n(1+n) + n\frac{\partial n}{\partial\varepsilon}\right] + \frac{\partial^2}{\partial\varepsilon^2}\left[Dn\right]\label{eqn:nbde1}.
\end{equation}
Here $D(\varepsilon,t)$ is referred to as diffusion term and $v(\varepsilon,t)$ as drift term taking dissipative effects into account. Their explicit values are important since they define the equilibrium temperature $T$ via the relation
\begin{equation}
	T = -\frac{D}{v}.
\end{equation}
The minus sign is explained by the fact that the drift is always towards the infrared i.\,e. the low-energy regime.\\
 For our case of relativistic heavy-ion collisions it is well motivated to assume constant transport coefficients which allows us to simplify our equation to
\begin{equation}
			\frac{\partial n}{\partial t} = -v\frac{\partial}{\partial\varepsilon}\left[n(1+n)\right] + D\frac{\partial^2 n}{\partial\varepsilon^2}\label{eqn:nbde2},
		\end{equation}
with the well-known Bose-Einstein distribution
\begin{equation}
	n_{\mathrm{eq}}(\varepsilon) = \frac{1}{\exp(\frac{\varepsilon-\mu}{T}) - 1}
\end{equation}
as a stationary solution.\\
At this point we need to discuss some general features of this model. It does not resolve the second order phase transition to the condensate discussed earlier explicitly but nevertheless the kinetics of Bose condensation before and after the transition are taken into account. After some time $t$ a certain fraction of bosons is pushed into the condensate which is a feature that may not be realized in nature. Of course it is based on particle-number conserving elastic scattering which may not provide the dominant contribution to the thermalization process as emphasized before. Another interesting feature of this certain model is that the particle number is only conserved when the integration is performed over the whole $x$-range opposed to the Boltzmann equation with energy-conserving delta function. We will see this in a moment when we analyze some plots of the solutions of the NBDE for different integration ranges. \\
To get a first analytical solution of the NBDE in the form of eqn. (\ref{eqn:nbde2}) we first want to study a linear approximation, the so-called linear relaxation ansatz (RTA).
\subsection{Linear Relaxation Ansatz}
For a given initial distribution $n_{\mathrm{t}}(\varepsilon)$  the linear relaxation-time ansatz reads
\begin{equation}
	\frac{\partial n_{\mathrm{rel}}}{\partial t} = \frac{(n_{\mathrm{eq}} - n_{\mathrm{
rel}})}{\tau_{\mathrm{eq}}},
\end{equation}
where we introduced the equilibration time $\tau_{\mathrm{eq}} = 4D/(9v^2)$ again as a certain ratio of the transport coefficients. General solutions to this simplified model are of the form of
\begin{equation}
	n_{\mathrm{rel}}(\varepsilon,t) = n_{\mathrm{i}}(\varepsilon)\cdot\exp\left(-\frac{t}{\tau_{\mathrm{eq}}}\right) +  n_{\mathrm{eq}}(\varepsilon)\left(1-\exp\left(-\frac{t}{\tau_{\mathrm{eq}}}\right)\right).
\end{equation}
Following ref. \cite{Mueller1999} we may use an initial distribution of the subsequent form in order to concentrate on a suitable distribution in the context of heavy-ion collisions, i.\,e.
\begin{equation}
	n_{\mathrm{i}}(\varepsilon) = N_{\mathrm{i}}\cdot\theta\left(1-\varepsilon/Q_{\mathrm{s}}\right)\cdot\theta(\varepsilon) \label{eqn:rta_initial}.
\end{equation}
Here we find again the dependency on the saturation $Q_{\mathrm{s}}\simeq 1$ GeV as upper limit of the box-shaped initial gluon distribution.\\
The results for the thermalization process from the NBDE following from the RTA are displayed in figure \ref{fig:rta1} at the beginning of the next page. We observe that the thermal equilibrium is reached fast after a time of approximately $t\simeq 2\tau_{\mathrm{eq}}$ approaching the Bose-Einstein limit from above in the IR and from below in the UV. At the boundary $p\simeq Q_{\mathrm{s}}$ we encounter unphysical discontinuities. Note that here the total gluon number is set to $N_{\mathrm{i}}=1$ to facilitate the comparison with the exact analytical solutions later on. Additionally we observe that we we are again dealing with an overoccupied system since
\begin{equation}
	N_{\mathrm{i}} = (4/3)\pi\cdot V\cdot Q_{\mathrm{s}}^3\cdot n_{\mathrm{i}}\quad >\quad N_{\mathrm{eq}} = 4\pi\cdot V \int_0^{\infty} n_{\mathrm{eq}}\cdot\varepsilon^2\ \dd\varepsilon
\end{equation}
If we would assume overall particle number conservation we would come again to the conclusion that the excess particles are driven into a condensate such that not only the gluon number in the thermal spectrum but rather the sum of the thermal gluons and the ones in the condensate is conserved.

\begin{figure}[t]
\centering
\includegraphics[width = 0.7\textwidth]{figures/rta}
\caption{Linear relaxation of a finite Bose system towards the equilibrium \cite{Wolschin2018}. \\ Here $T = -D/v \simeq 0.4\ \mathrm{GeV}$, $\tau_{\mathrm{eq}} = 4D/(9v^2) = 0.33\cdot 10^{-23} \mathrm{s} \simeq 1\ \mathrm{fm/c}$ and the timesteps are $\left\{0.1, 0.25, 0.5,\infty\right\}$ (in units of $10^{-23}s$) from top to bottom.}
\label{fig:rta1}
\end{figure}

\subsection{Exact solution of the NBDE}
To be able to find a solution to the full NBDE we perform the nonlinear transformation\footnote{Another possible solution is given by Burger's equation $\frac{\partial w}{\partial t} + w\frac{\partial w}{\partial\varepsilon} = D\frac{\partial^2 w}{\partial\varepsilon^2}$ following from the linear transformation $n(\varepsilon,t) = \frac{1}{2v}w(\varepsilon,t) - \frac{1}{2}$ but we will not discuss the details of this approach here.}
\begin{equation}
		n(\varepsilon,t) = -\frac{D}{v}\frac{\partial \ln \mathcal{Z}(\varepsilon,t)}{\partial\varepsilon}
\end{equation}
with the usual partition sum $ \mathcal{Z}(\varepsilon,t)$ reducing our problem to a linear diffusion equation for the partial sum, i.\,e.
\begin{equation}
		\frac{\partial  \mathcal{Z}}{\partial t} = -v\frac{\partial  \mathcal{Z}}{\partial \varepsilon} +  D\frac{\partial^2  \mathcal{Z}}{\partial \varepsilon^2}.
	\end{equation}
General solutions of the NBDE are then of the form
\begin{equation}
n(\varepsilon, t)=\frac{1}{2 v} \frac{\int_{-\infty}^{+\infty} \frac{\varepsilon-x}{t} F(x)\cdot G_{\mathrm{free}}(\varepsilon-x,t)\ \dd x}{\int_{-\infty}^{+\infty} F(x)\cdot G_{\mathrm{free}}(\varepsilon-x,t)\ \dd x}-\frac{1}{2},
\end{equation}
with the free Green's function, being an usual Gaussian,
\begin{align}
	G_{\mathrm{free}}(\varepsilon-x,t) = \exp\left[-\frac{(\varepsilon-x)^2}{4Dt}\right],
\end{align}
and the function $F(x)$ taking the initial conditions into account, i.\,e.
\begin{equation}
	    F(x)  = \exp\left[-\frac{1}{2D}(vx+2v\int_0^x n_{\mathrm{i}}(y) \dd y) \right].
\end{equation}
They define the partition sum via the relation
\begin{equation}
	\mathcal{Z}(\varepsilon,t) = a(t)\cdot\int_{-\infty}^{\infty} G_{\mathrm{free}}(\varepsilon,x,t)\cdot F(x)\ \dd x,
\end{equation}
with some energy-independent scaling factor $a(t)$ which is in our case not important since it drops out due to the $\operatorname{log}$-derivative. As already mentioned before one may check that the particle number is not conserved for an integration over only the positive $x$-range. With these definitions in mind we are now set to present the results of the NBDE. At this point I should mention that I will not display the full lengthy expressions for the full analytical solution but rather focus on the plots and the implications arising from these different solutions. In case the reader may be interested in the exact expressions I refer to ref. \cite{Wolschin2018} for the first part and to ref. \cite{Wolschin2020_1} for the second part.
\begin{figure}[H]
\begin{subfigure}[c]{0.49\textwidth}
\includegraphics[width=\textwidth]{figures/nbde_positive_range}
\subcaption{Integration range restricted to $x \geq 0$.\\ The timesteps are $\left\{0.005, 0.05, 0.15,0.5\right\}$ \\ (in units of $10^{-23}s$) from top to bottom.}
\end{subfigure}
\begin{subfigure}[c]{0.49\textwidth}
\includegraphics[width=\textwidth]{figures/nbde_full_range}
\subcaption{Integration range extended to $-\infty \leq x \leq \infty$. \\ The timesteps are $\left\{0.005, 0.05, 0.15,0.5\right\}$ \\ (in units of $10^{-23}s$) from top to bottom.}
\end{subfigure}
\caption{Equilibration of a finite Bose system from the NBDE for $T\simeq 0.4\ \mathrm{GeV}$ and \\ $\tau_{\mathrm{eq}} =  0.33\cdot 10^{-23} \mathrm{s}$ \cite{Wolschin2018}.}
\label{fig:full_sol_ranges}
\end{figure}
\noindent
In the above figure \ref{fig:full_sol_ranges} we present the results for the equilibration following from the exact solutions for different integration ranges to highlight the importance of integrating over the whole $x$-range. In the left figure we find the occupation rising above the thermal limit for very short times but due to redistribution into the condensate it depletes and we have $n(0,t)<1 \ \forall t >\tau_{\mathrm{eq}}$ which encodes the explicit violation of particle number conservation. In the right plot, representing the solution with integration over the whole range, we directly see the redistribution into the condensate in the IR already at early times and find a new thermal tail developed in the UV. We therefore conclude that these solutions do not reproduce the expected features of the Bose-Einstein equilibrium distribution, yet. This can be explained by the fact that we did not yet include  the singularity of the Bose-Einstein distribution at $\varepsilon=\mu <0$. We will see how to resolve this problem in the following.

\subsection{Including the Singularity}
To account for the singularity at $\varepsilon=\mu <0$ we have to modify the initial distribution (\ref{eqn:rta_initial}) in the following way:
\begin{equation}
		\tilde{n_{\mathrm{i}}}(\varepsilon) = n_{\mathrm{i}}(\varepsilon) + \frac{1}{\exp\left(\frac{\varepsilon-\mu}{T}\right)-1}.
	\end{equation}
For the subsequent analysis we treat the chemical potential $\mu$ as a fixed parameter and consider the asymptotics of 	our distribution at the singularity
\begin{equation}
	 \lim_{\varepsilon\rightarrow\mu^{+}}\ n(\varepsilon,t) = \infty\ \forall t
\end{equation}
yielding $\mathcal{Z}(\mu,t) = 0$. This results in a modified expression for the Green's function
 	\begin{equation}
		G(\varepsilon,x,t) = G_{\mathrm{free}}(\varepsilon-\mu,x,t) - G_{\mathrm{free}}(\varepsilon-\mu,-x,t).
\end{equation}
This means that in general our expressions for the partition sum and the function $F$ stay almost the same except in a shift in the respective argument by the chemical potential $\mu$. The techniques to solve the NBDE with this boundary condition remain the same and we can therefore have a look at the solutions displayed below in figure (\ref{fig:singularity}).
\begin{figure}[H]
\begin{subfigure}[c]{0.47\textwidth}
\includegraphics[width=\textwidth]{figures/rta_full}
\subcaption{Local thermalization of gluons in the linear RTA.
The timesteps are $\left\{0.02, 0.08, 0.15,0.3,0.6\right\}$ ($\mathrm{fm}/c$) for decreasing dash length.}
\end{subfigure}
\begin{subfigure}[c]{0.495\textwidth}
\includegraphics[width=\textwidth]{figures/nbde_full_result}
\subcaption{Local thermalization of gluons from the time-dependent solutions of the NBDE.\\ Here $\left\{6\cdot10^{-5}, 6\cdot10^{-4}, 6\cdot10^{-3},0.12,0.36\right\}$ ($\mathrm{fm}/c$) for decreasing dash length.}
\end{subfigure}
\caption{Results for the full solution of the NBDE including the singularity at $\varepsilon=\mu<0$ at $T \simeq 513\ \mathrm{MeV}$ \cite{Wolschin2020_1}. }
\label{fig:singularity}
\end{figure}
\noindent
In the left figure we see again the simplified solution arising from the RTA where we can already observe that the solution entails the correct physical properties of the Bose-Einstein equilibrium distribution in the UV and finally also in the IR except the discontinuities at $p\simeq Q_{\mathrm{s}}$. Note that here the thermalization occurs much slower than in the nonlinear case on the right hand side.\\
\noindent
The full nonlinear solution presented in the right figure now appropriately describes the thermalization process of a finite gluon system encoding all expected properties in the UV and also in the IR opposed to the first solutions omitting the important boundary condition at $\varepsilon=\mu$. Note that in our concrete example the numerical values of the transport coefficients have been chosen such that they represent the situation of a Pb-Pb collision at the LHC with a center-of-mass energy of $\sqrt{s}=5$ TeV leading to a thermalization with $T\simeq 513$ MeV.