\documentclass[a0]{tumposter}

\usepackage[english]{babel}

\usepackage{blindtext}

\usepackage{multicol}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{natbib}

% for printing fontsizes
\usepackage{printlen}
\uselengthunit{mm}

\input{preamble.tex}

\usepackage[utf8]{inputenc}

\title{
	BreizhCrops: A Satellite Time Series Dataset \\ for Crop Type Identification
	}

\author{
	Marc Rußwurm\footnotemark[1],
	Sébastien Lefèvre\footnotemark[2],
	Marco Körner\footnotemark[1]
	}

\header{
	Remote Sensing Technology \\
	TUM Department of Civil, Geo and Environmental Engineering \\
	Technical University of Munich
	}

\begin{document}

%	\renewcommand{\subsection}[1]{\textbf{#1}}

	\tikzstyle{every picture}+=[remember picture]

\maketitle

%\newcommand{\satellitebox}{
%	\begin{tikzpicture}[node distance=1em]
%	\node(title){Satellite Data $\V{x}$};
%	\node[below=of title](s2){\includegraphics[width=15cm]{images/sentinel2}};
%	\node[below=of s2, text width=20cm]{
%	ESA Sentinel 2 Satellite
%	\begin{itemize}\setlength\itemsep{.1em}
%		\item 13 spectral bands
%		\item every 2-10 days
%		\item global coverage
%		\item free of charge
%	\end{itemize}
%};
%\end{tikzpicture}
%}

%\newcommand{\modelbox}{
%	\begin{tikzpicture}[node distance=1em]
%\node(title){classification model $f$};
%\node[below=of title](large){\includegraphics[width=15cm]{images/Large1954_cerial_growth_stages.png}};
%\node[below=of large](label){learning a phenological model};
%
%\node[below=3em of label, xshift=-5em, anchor=east]{?};
%\node[below=3em of label, anchor=center]{health};
%\node[below=3em of label, xshift=5em, anchor=west]{droughts};
%
%
%\end{tikzpicture}
%}

%\newcommand{\labelbox}{
%\begin{tikzpicture}[node distance=1em]
%\node(title){crop type labels $\V{y}$};
%\node[below=of title](large){\includegraphics[width=15cm]{images/map/parcels}};
%\node[below=of large, text width=20cm]{
%Crop Type Labels
%\begin{itemize}\setlength\itemsep{.1em}
%\item Europes Common Agricultural Policy (CAP)
%\item reported by respective farmer
%\item gathered by national institutions (IGN in France)
%\end{itemize}
%};
%\end{tikzpicture}
%}

%\vspace{-1em}
\begin{minipage}[t]{0.65\textwidth}

\section{Objective}

\begin{tikzpicture}[scale=16]
	\node[label={[name=sat,text height=1.5ex,text depth=.25ex]Satellite Data}, anchor=north](x) at (-1,0){$\M{X} = (\V{x}_0, \V{x}_1, \dots , \V{x}_T)$};
	\node[below=of x, label={[yshift=1.3em, xshift=1.8em, font=\tiny, text=white]below:ESA Sentinel 2 Satellite}](s2){\includegraphics[width=13cm]{images/sentinel2}};

	\node[below=of s2, text width=13cm](eqbox){
		\small surface reflectance \\
		\vspace{1em}
		\centering
		$
		\rho_\lambda =
		\frac{
			\pi L_\lambda d^2
		}
		{
			E_\text{sun} \cos(\varphi_\text{sun})
		}
		$

%		\begin{tikzpicture}[scale=3.5, anchor=center]
%
%%			\node at (0,0){};
%			\node(eq) at (0,0) {
%
%				};
%		\end{tikzpicture}
		\includegraphics[width=9cm]{images/reflectance}
%		\vspace{1em}

		{\small in 13 spectral bands\\
		\vspace{1em}
		$\V{x}_t = \left(\rho_{\text{red}},\rho_{\text{green}},\rho_{\text{nir}},\dots\right)^T$}
	};

	\node[label={[name=cm,text height=1.5ex,text depth=.25ex]Classification Model}, anchor=north](f) at (0,0){ $\V{y} = f(\M{x})$};
	\node[below=of f, label={[yshift=0em]below:\verytiny cereal vegetation model by \citet{Large1954}}, inner sep=0](large){\includegraphics[width=14.5cm]{images/Large1954_cerial_growth_stages.png}};
	\node[below=of large, circle, fill=tumbluedark, text=white, text width=10cm](label){learning a \\ \textbf{\Large\color{tumorange}vegetation} \color{tumwhite} model $f$};
	\node[below=of label, xshift=-2.3em, yshift=.5em, rotate=0, text=tumgraydark, font=\small](yield){crop yield?};
	\node[below=of label, text=tumgraydark, font=\small, yshift=-.5em](prod){production?};
	\node[below=of label, xshift=2.3em, yshift=.5em, text=tumgraydark, font=\small](health){crop health?};
	\node[fit=(yield)(prod)(health), draw=none, rounded corners, label={[anchor=north, font=\tiny, xshift=3.5em, yshift=.75em, text=tumblue]south:\#foodsecurity}](foodsec){};

	\node[label={[name=ctm,text height=1.5ex,text depth=.25ex]Crop Type Labels}, anchor=north](y) at (1,0){
		$\V{y} = \small (y_\text{corn}, y_\text{barley}, \dots) \in \mathbb{R}^{13}$
	};
	\node[below=of y, label=below:IGN crop type labels](labels){\includegraphics[width=13cm]{images/map/parcels}};
	\node[below=of labels, text width=12cm](lbls){
		\small
	\begin{itemize}\setlength\itemsep{.1em}
		\item European Common Agricultural Policy (CAP)
		\item collected yearly in entire Europe
		\item slowly made publicly available
		\item today, gathered on a national basis
		\item in future harmonized within Europe's INSPIRE directive
	\end{itemize}
	};

	\draw[-stealth, thick, tumblue] (x) -- (f);
	\draw[-stealth, thick, tumblue] (f) -- (y);

	\coordinate(bcenter) at (eqbox.south -| f);
	\coordinate(bright) at (eqbox.south -| y);

	\scoped[on background layer]
	{
		\node[fit=(sat)(eqbox), fill=tumbluelight!20, inner sep=1em, rounded corners]{};
		\node[fit=(cm)(foodsec)(bcenter), fill=tumorange!20, inner sep=1em, rounded corners]{};
		\node[fit=(ctm)(lbls)(bright), fill=tumbluelight!20, inner sep=1em, rounded corners]{};

	}

\end{tikzpicture}

\vspace{-.5em}
\section{Data}
Data gathered in Brittany, France (\textit{Breizh}) in 2017 covering 27,206 km².
%
%\vspace{1em}

\subsection{Labels}
\small 580k field parcels with 13 crop categories

\vspace{1em}
\begin{tikzpicture}[scale=16]
	\node[label={[name=label]Field Parcels}](fieldparcels) at (-1,0){\includegraphics[width=13cm]{images/map/breizh}};
%	\node[fit=(label)(a), draw=tumbluedark, rounded corners, minimum height=13cm]{};
%%	\node[above=of a, text width=14cm, font=\tiny]{field parcels in Brittany colored by crop type label};
	%
	\node[label={[name=label, text height=2ex]above: Administrative Divisions}](nuts2) at (0,0){\includegraphics[width=12.6cm]{images/map/regions}};
%	\node[fit=(label)(b), draw=tumbluedark, rounded corners, minimum height=13cm]{};

	\node[label={[name=label, text height=2ex]above: European Crop Data}](euro) at (1,0){\includegraphics[width=14cm]{images/map/europe_data2.png}};

	\coordinate[below=-1.25em of fieldparcels](labels);
	\coordinate(la) at (labels -| fieldparcels);
	\coordinate(lb) at (labels -| nuts2);
	\coordinate(ld) at (labels -| euro);

	\node[font=\verytiny, fill=tumbluelight!20] at (la){field parcels colored by crop type};
	\node[font=\verytiny, fill=tumbluelight!20] at (lb){NUTS-2 regions for train/test splits};
	\node[font=\verytiny, fill=tumbluelight!20] at (ld){{\color{tumorange} Brittany} and {\color{tumblue} more regions} providing crop  labels};

	\node[below=of nuts2, label={[yshift=-1em]above:Class Frequency in the Administrative Divisions}, yshift=1em](histogram){
	\input{images/partition_histograms.tikz}
	};

	\scoped[on background layer]
	{
		\node[fit=(fieldparcels)(nuts2)(euro)(histogram)(label), fill=tumbluelight!20, inner sep=0em, rounded corners]{};
	}

\end{tikzpicture}
\vspace{-1em}
% \small \textbf{Time Series}
\subsection{Satellite Reflectance Time Series}
\small 70-150 surface reflectance measurements in 13 spectral bands for each parcel of the season 2017

\begin{tikzpicture}[xscale=11.5, yscale=-4]
\input{images/example.tikz}
\node[label={[yshift=.75em]below:\tiny \textbf{\color{tumblue}corn} parcel}](examplecorn) at (-1,0){\examplecorn};
\node[label={[yshift=.75em]below:\tiny \textbf{\color{tumblue}temporary meadow} parcel}](examplemeadows) at (1,0){\examplemeadows};
\node(legend) at (0,1.2) {\includegraphics[width=.9\textwidth]{images/legend_x2.png}};

\scoped[on background layer]
{
	\node[fit=(examplecorn)(examplemeadows)(legend), fill=tumbluelight!20, inner sep=0em, rounded corners]{};
}
\end{tikzpicture}

\end{minipage}
\hfill
\begin{minipage}[t]{0.32\textwidth}

	\section{Results}

	We show the feasibility of classifying this dataset with \textbf{LSTM} \citep{hochreiter1997long} and \textbf{Tranformer} \citep{Vaswani:Transformer} baselines.

%	\input{images/lstmmodel.tikz}
%	\lstmmodel
%	\transformermodel

	\vspace{1em}

	\begin{tikzpicture}
		\node[label={[name=lab3]above:Comparison of baseline models}](a){
		\begin{tabular}{lccccccc}
		\toprule
		method & accuracy & $\kappa$ & $f_1$ & prec.  & rec. \\
		\cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7}
		\textbf{Transformer} & \textbf{.69}  &  \textbf{.63} & .57 & {.60} & .56 \\
		\textbf{LSTM} & .68 & .62 & \textbf{.59} & \textbf{.63} & \textbf{.58} \\
		\bottomrule
		\end{tabular}
		};
		\scoped[on background layer]
		{
			\node[fit=(a)(lab3), fill=tumgraylight!40, inner sep=0em, rounded corners]{};
		}
	\end{tikzpicture}

	\vspace{1em}

	\tikzstyle{crop} = [fill=tumbluelight, rounded corners]

	\begin{tikzpicture}[xscale=6, yscale=15]
		\node[label={[name=lab2]above:Class-wise results of the LSTM model}](table) at (0,0){{\small\input{images/data/BreizhCrops_rnn/npy/table.tex}}};
		\node[rounded corners, label={[name=lab]below:\small precision}](confmatprecision) at (-1,-1){\resizebox{12cm}{!}{\confmat{images/data/BreizhCrops_rnn/npy/confmat_flat.csv}{3}{1}}};
		\node[rounded corners, label=below:\small recall](confmatrecall) at (1,-1){\resizebox{12cm}{!}{\confmat{images/data/BreizhCrops_rnn/npy/confmat_flat.csv}{4}{1}}};

		\scoped[on background layer]
		{
			\node[fit=(table)(confmatprecision)(confmatrecall)(lab)(lab2), fill=tumbluelight!20, inner sep=0em, rounded corners](boxresults){};
		}

	\end{tikzpicture}

	 \section{Outlook and Next Steps}
%
%	 \begin{minipage}{\textwidth}
%
	 	\begin{itemize}
	 		\item test \textbf{generalization} over \textbf{changing environmental conditions}. Problem of domain adaptation?
%	 		\item Acquired \textit{\color{tumblue}Google Research Credits} for large-scale crop type mapping
	 		\item \textbf{pre-train} a vegetation model on crop type labels and \textbf{fine-tune} related tasks with less labels (e.g., crop yield regression)
	 		\item include additional modalities ({\small e.g., radar observations, precipitation, temperature, elevation})

	 	\end{itemize}

%	 \end{minipage}
%%	 \begin{minipage}{.38\textwidth}
%%	 	\includegraphics[width=\textwidth]{images/map/europe_data.pdf}
%	 	\tiny open crop data regions
%%	 \end{minipage}
%
%	 \section{Feedback}
%
%	 \begin{itemize}
%	 	\item suggestion of baseline models?
%%	 	\item general interest in this application?
%%	 	\item use of the dataset for TS community?
%	 	\item ideas to address the challenges?
%	 \end{itemize}

	\small
	\bibliographystyle{icml2019}
	\bibliography{bib/references.bib}

\end{minipage}

\input{challenges.tex}

% footer environment places \hfill and sets fontsize
\begin{footer}
	\begin{minipage}{.17\textwidth}
		\textbf{ICML 2019 \\ Time Series Workshop}\\
		\phantom{A} \\ \phantom{B}
%		roseyu.com/time-series-workshop/
	\end{minipage}
	\begin{minipage}{.25\textwidth}
		\textbf{Technical University of Munich}\footnotemark[1]\\
		TUM Department of Civil, Geo and Env. \\
		Remote Sensing Technology \\
		Arcisstr. 21, Munich, Germany
	\end{minipage}
	\begin{minipage}{.25\textwidth}
		\textbf{IRISA-Obelix}\footnotemark[2]\\
		Université Bretagne Sud \\
		IRISA, UMR 6074 CNRS \\
		Campus de Tohannic, Vannes, France

	\end{minipage}
	\begin{minipage}{.25\textwidth}
		\textbf{Data \& Code} \\
%		\vspace{1em}
		{github.com/TUM-LMF/BreizhCrops} \\
		{https://twitter.com/MarcCoru} \\
		www.lmf.bgu.tum.de/vision
	\end{minipage}
	\begin{minipage}{.05\textwidth}
		\hfill\includegraphics[width=5cm]{images/qrcode}
	\end{minipage}

\end{footer}

\end{document}


\documentclass{memoir}
\usepackage{notestemplate}

%\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}
%\institute{Rice University}
%\faculty{Faculty of Whatever Sciences}
%\department{Department of Mathematics}
%\title{Class Notes}
%\subtitle{Based on MATH xxx}
%\author{\textit{Author}\\Gabriel \textsc{Gress}}
%\supervisor{Linus \textsc{Torvalds}}
%\context{Well, I was bored...}
%\date{\today}

\begin{document}

% \maketitle

% Notes taken on 02/24/21

\section{Complete Reducibility}
\label{sec:complete_reducibility}

Recall that the \textbf{characteristic} of a field \(K\) is the smallest positive integer \(p\) such that \(p 1_K = 0\). If \(p\) exists, then it is prime; else we say \(K\) has characteristic 0.

\begin{thm}
	Let \((V,\rho)\) be a representation of a finite group \(G\) of finite degree \(n\) over a field \(K\) of characteristic \(p\) with \(p \not\mid \left| G \right| \). If \(W\) is a subrepresentation of \((V,\rho)\), then there exists another subrepresentation \(W'\) of \(V\) so that
	\begin{align*}
		V \cong W \bigoplus W'
	\end{align*}
	as \(K\)-vector spaces. We refer to \(W'\) as the \textbf{complement} of the subrepresentation \(W\) of \((V,\rho)\).
\end{thm}

\begin{cor}[Maschke's Theorem]
	Let \(V\) be a representation of a finite group \(G\) of finite degree over a field of characteristic \(p\) with \(p \not\mid \left| G \right| \). Then \(V\) is completely reducible.
\end{cor}

This can be proven by induction on \(\textrm{dim}V\). Note that this fails for infinite groups.

\end{document}

Abstract Algebra - Introductory/Algebra II/Notes/source/Lecture11 - CompleteReducibility.tex


\title{Composing Inferences}

{{navbar}}

\subsubsection{Composing Inferences}

Core to Edward's design is compositionality. Compositionality enables
fine control of inference, where we can write inference as a
collection of separate inference programs.

We outline how to write popular classes of compositional inferences
using Edward: hybrid algorithms and message passing algorithms.
We use the running example of a mixture model
with latent mixture assignments \texttt{z}, latent cluster means
\texttt{beta}, and observations \texttt{x}.

\subsubsection{Hybrid algorithms}

Hybrid algorithms leverage different inferences for each latent
variable in the posterior.
As an example, we demonstrate variational EM, with an approximate
E-step over local variables and an M-step over global variables.
We alternate with one update of each \citep{neal1993new}.

\begin{lstlisting}[language=Python]
from edward.models import Categorical, PointMass

qbeta = PointMass(params=tf.Variable(tf.zeros([K, D])))
qz = Categorical(logits=tf.Variable(tf.zeros[N, K]))

inference_e = ed.VariationalInference({z: qz}, data={x: x_data, beta: qbeta})
inference_m = ed.MAP({beta: qbeta}, data={x: x_data, z: qz})
...
for _ in range(10000):
  inference_e.update()
  inference_m.update()
\end{lstlisting}

In \texttt{data}, we include bindings of prior latent variables
(\texttt{z} or \texttt{beta}) to posterior latent variables
(\texttt{qz} or \texttt{qbeta}). This performs conditional inference,
where only a subset of the posterior is inferred while the rest are
fixed using other inferences.

This extends to many algorithms: for example,
exact EM for exponential families;
contrastive divergence \citep{hinton2002training};
pseudo-marginal and ABC methods \citep{andrieu2009pseudo};
Gibbs sampling within variational inference \citep{wang2012truncation};
Laplace variational inference \citep{wang2013variational};
and
structured variational auto-encoders \citep{johnson2016composing}.

\subsubsection{Message passing algorithms}

Message passing algorithms operate on the posterior distribution using
a collection of local inferences \citep{koller2009probabilistic}.
As an example, we demonstrate expectation propagation. We split a
mixture model to be over two random variables \texttt{x1} and
\texttt{x2} along with their latent mixture assignments \texttt{z1}
and \texttt{z2}.

\begin{lstlisting}[language=Python]
from edward.models import Categorical, Normal

N1 = 1000  # number of data points in first data set
N2 = 2000  # number of data points in second data set
D = 2  # data dimension
K = 5  # number of clusters

# MODEL
beta = Normal(loc=tf.zeros([K, D]), scale=tf.ones([K, D]))
z1 = Categorical(logits=tf.zeros([N1, K]))
z2 = Categorical(logits=tf.zeros([N2, K]))
x1 = Normal(loc=tf.gather(beta, z1), scale=tf.ones([N1, D]))
x2 = Normal(loc=tf.gather(beta, z2), scale=tf.ones([N2, D]))

# INFERENCE
qbeta = Normal(loc=tf.Variable(tf.zeros([K, D])),
               scale=tf.nn.softplus(tf.Variable(tf.zeros([K, D]))))
qz1 = Categorical(logits=tf.Variable(tf.zeros[N1, K]))
qz2 = Categorical(logits=tf.Variable(tf.zeros[N2, K]))

inference_z1 = ed.KLpq({beta: qbeta, z1: qz1}, {x1: x1_train})
inference_z2 = ed.KLpq({beta: qbeta, z2: qz2}, {x2: x2_train})
...
for _ in range(10000):
  inference_z1.update()
  inference_z2.update()
\end{lstlisting}

We alternate updates for each local inference, where the global
posterior factor $q(\beta)$ is shared across both inferences
\citep{gelman2017expectation}.

With TensorFlow's distributed training, compositionality
enables \emph{distributed} message passing over a cluster with many
workers. The computation can be further sped up with the use of GPUs
via data and model parallelism.

This extends to many algorithms: for example,
classical message passing, which performs exact local inferences;
Gibbs sampling, which draws samples from conditionally conjugate
inferences \citep{geman1984stochastic};
expectation propagation, which locally minimizes
$\text{KL}(p || q)$ over exponential families \citep{minka2001expectation};
integrated nested Laplace
approximation, which performs local Laplace approximations
\citep{rue2009approximate};
and
all the instantiations of EP-like algorithms in
\citet{gelman2017expectation}.

In the above, we perform local inferences split over individual random
variables. At the moment, Edward does not support local inferences
within a random variable itself. We cannot do local inferences when
representing the random variable for all data points and their cluster
membership as \texttt{x} and \texttt{z} rather than \texttt{x1},
\texttt{x2}, \texttt{z1}, and \texttt{z2}.

\subsubsection{References}\label{references}


\appendix
\chapter*{Derivations and proofs}
\section*{The two extremal problems}
%\addcontentsline{toc}{chapter}{The two extremal problems}
\subsection*{The extremal limit problem}
\subsubsection*{Introduction}
Hereafter are set forth the derivations for the part on the limiting distributions.
\paragraph{Our approach} We are here interested in proving a result of convergence in distribution $Y_n \xrightarrow[n \rightarrow + \infty]{d} Y$. Anyone who has dabbled in probability knows that one of the classic ways to prove such a result is to use the definition and show that $\forall x$ in which $F_Y$ is continuous, $F_{Y_n}(x) \xrightarrow[n \rightarrow + \infty]{} F_Y(x)$. Anyone who has dabbled in statistics knows that in the context of discrete random variables $(Y_n)_{n \ge 0}$, Y it is easier to show the convergence of the probability mass functions i.e. that $\forall x, f_{Y_n}(x) \xrightarrow[n \rightarrow + \infty]{} f_Y(x)$ and conclude by Scheffé's lemma that $(Y_n)_{n \ge 0}$ converges in distribution to Y. In the context of Extreme Value Theory, though, we will use a result based on the convergence of expectations. It is the \underline{Helly-Bray theorem} : \newline $Y_n \xrightarrow[n \rightarrow + \infty]{d} Y \iff \forall g$ continuous, bounded and real-valued functions, $\mathrm{E}(g(Y_n)) \xrightarrow[n \rightarrow + \infty]{} \mathrm{E}(g(Y))$.
\paragraph{Remark} Our approach here is based upon the notes taken while reading "Chapter 2 : The Probabilistic side of extreme Value Theory" of \underline{Statistics of Extremes, Theory and Applications} by Beirlant \textit{et alii}. \textbf{We thus want to underline that the approach here is not our own, and that we are not engaging in plagiarism but giving account of the work done on our bibliographic sources.}
\subsection*{Solving the problem - step 1}
\paragraph{The answer to the extremal limit problem} It turns out that all possible non-degenerate limiting distributions i.e. all extreme values distribution make up a one-parameter family $G_\gamma(x) = \exp(-(1 + \gamma x)^{-\frac{1}{\gamma}})$, where the support of G is the set $\{ x : 1 + \gamma x > 0}$ and $\gamma \in \mathbb{R}$ is the \textbf{E}xtreme \textbf{V}alue \textbf{I}nded or \textbf{EVI}. This is what we set out to show here.
\paragraph{In the context of our problem} $Y_n = M_n^{*} = \frac{M_n - b_n}{a_n}$ and $Y = Y_\gamma$. $Y_n \xrightarrow[n \rightarrow + \infty]{d} Y \iff \forall g$ continuous, bounded and real-valued functions, $\mathrm{E}(g(Y_n)) \xrightarrow[n \rightarrow + \infty]{} \int_{-\infty}^{+\infty} \! g(v) \, \mathrm{d}G_\gamma(v) $. \newline
\begin{equation}
\begin{alignat*}{2}
\Pr(\{M_n^* \le x\}) &= F_X(x)^n\\
\implies \mathrm{E}(g(\frac{M_n - b_n}{a_n})) &= n \int_{-\infty}^{+\infty} \! g(\frac{x - b_n}{a_n}) F_X(x)^{n - 1}\, \mathrm{d}F_X(x)  \\
\end{alignat*}
\end{equation} \newline
$F_X : \mathbb{R} \rightarrow [0,1]$, then if $F_X$ is assumed to be continuous\footnote{An assumption that will be satisfied in all what follows}, by the Intermediate Value Theorem there exists in particular a solution to the equation $F(x) = 1 - \frac{v}{n}$. This is equivalent to the equation $x = U(\frac{n}{v}) = Q(1 - \frac{v}{n})$ where $U$ is the tail quantile function of $F_X$ and $Q$ is the quantile function of $F_X$. \newline
\begin{equation}
\begin{alignat*}{2}
F_X(x) &= Q(1 - \frac{v}{n})\\
\implies \mathrm{d}F_X(x) &= -\frac{1}{n} \mathrm{d}v  \\
\implies n \int_{-\infty}^{+\infty} \! g(\frac{x - b_n}{a_n}) F_X(x)^{n - 1}\, \mathrm{d}F_X(x) &= n \int_n^0 \! g(\frac{U(\frac{n}{v}) - b_n}{a_n}) (1 - \frac{v}{n})^{n - 1} (-\frac{1}{n})\, \mathrm{d}v \\
\implies \mathrm{E}(g(\frac{M_n - b_n}{a_n})) &= \int_0^n \! g(\frac{U(\frac{n}{v}) - b_n}{a_n}) (1 - \frac{v}{n})^{n - 1}\, \mathrm{d}v
\end{alignat*}
\end{equation}\newline where $x = U(\frac{n}{v}) = Q(1 - \frac{v}{n})$ goes from $-\infty$ to $+\infty$. Indeed, \newline
\begin{itemize}
	\item for $v = n$, $x = U(1) = Q(0) = -\infty$
	\item for $v = 0^+$, $x = U(+\infty) = Q(1) = +\infty$
\end{itemize}\newline which explains the change of bounds in the integral in the third equation. We are now working on $\int_0^n \! g(\frac{U(\frac{n}{v}) - b_n}{a_n}) (1 - \frac{v}{n})^{n - 1}\, \mathrm{d}v$. If we take the limit $n \rightarrow +\infty$, in particular :
\begin{itemize}
	\item the integral will be taken between $0$ and $+\infty$
	\item $(1 - \frac{v}{n})^{n - 1} \xrightarrow[n \rightarrow + \infty]{} (\exp(v))^{-1} = exp(-v)$
\end{itemize}\newline A limit can be obtained for $\mathrm{E}(g(\frac{M_n - b_n}{a_n}))$ when for some sequence of positive numbers $(a_n)_{n \ge 0}$, $\frac{U(\frac{n}{v}) - b_n}{a_n}$ is convergent $\forall v \ge 0$\footnote{Beirlant underlines that if we take $v = 1$, we get the idea that taking $(b_n)_{n \ge 0} = (U(n))$ will guarantee it works.}
\paragraph{A preparatory phase} A condition that must be imposed is the condition $(\mathcal{C})$ : "For some positive function $a$ and $\forall u > 0$, $\frac{U(x u) - U(x)}{a(x)} \xrightarrow[x \rightarrow + \infty]{} h(u)$ where h is not identically equal to 0". \newline
\underline{Proposition :} The possible limits in $(\mathcal{C})$ are given by $c h_\gamma(u) = c \int_1^u \! v^{\gamma -1}\, \mathrm{d}v = c \frac{u^\gamma -1}{\gamma}$, where $c > 0$, $\gamma \ge 0$ and $h_0(u)$ is interpreted as $\log(u)$. \newline \textbf{The case c > 0 can be reduced to $c = 1$ by incorporating $c$ into $a$.}\newline $\forall u$, $v > 0$, \newline
\begin{equation}
\begin{alignat*}{2}
\frac{U(x u v) - U(x)}{a(x)} = \frac{U(x u v) - U(x u)}{a(x u)} \frac{a(x u)}{a(x)} + \frac{U(x u) - U(x)}{a(x)}
\end{alignat*}
\end{equation}\newline If $(\mathcal{C})$ holds then $\frac{a(x u)}{a(x)}$ converges to a $g(u)$.\newline $\forall u$, $v > 0$,
\begin{equation}
\begin{alignat*}{2}
\frac{a(x u v)}{a(x)} &= \frac{a(x u v)}{a(x v)} \frac{a(x v)}{a(x)}\\
\implies \frac{a(x u v)}{a(x)} &= \frac{a((x v) u )}{a(x v)} \frac{a(x v)}{a(x)}\\
\xrightarrow[x \rightarrow + \infty]{} g(u v)  &= g(u) g(v)
\end{alignat*}
\end{equation}\newline We recognize the Cauchy Functional Equation, if a function $g$ satisfies this equation, then $g : \mathbb{R}_+ \longrightarrow \mathbb{R}$ is of the form $u^\gamma$, where $\gamma$ is a real number. Now, if we write $a(x) = x^\gamma l(x)$, \newline
\begin{equation}
\begin{alignat*}{2}
\frac{a(x u v}{a(x)} &= \frac{(x u)^\gamma}{x^\gamma} \frac{l(x u)}{l(x)} \\
&= u^\gamma \frac{l(x u)}{l(x)}
\end{alignat*}
\end{equation} \newline For this quantity to converge to $u^\gamma$, $\frac{l(x u)}{l(x)}$ must converge to 1. $u$ being a positive number, this is equivalent to the fact that $l$ must be a \textit{slowly varying} function. Hence, $a(x) = x^\gamma l(x)$ is a \textit{regularly varying} function with index of regular variation $\gamma$.\newline
\begin{equation}
\begin{alignat*}{2}
\frac{U(x u v) - U(x)}{a(x)} &= \frac{U(x u v) - U(x u)}{a(x u)} \frac{a(x u)}{a(x)} + \frac{U(x u) - U(x)}{a(x)} \\
\xrightarrow[x \rightarrow + \infty]{} h_\gamma(u v) &= h_\gamma(v) u^\gamma + h_\gamma(u)
\end{alignat*}
\end{equation}
\begin{itemize}
	\item \underline{If $\gamma = 0$} \\
	\begin{equation}
	\begin{alignat*}{2}
	h_0(u v) &= h_0(u) + h_0(v) \\
	\implies \exists c \in \mathbb{R} : h_0(u) &= c \log(u)
	\end{alignat*}
	\end{equation}\newline
	\item \underline{If $\gamma \ne 0$}
	\begin{equation}
	\begin{alignat*}{2}
	h_\gamma(u v) &= h_\gamma(v) u^\gamma + h_\gamma(u)
	\end{alignat*}
	\end{equation} And by symmetry,
	\begin{equation}
	\begin{alignat*}{2}
	h_\gamma(u v) &= h_\gamma(u) v^\gamma + h_\gamma(v)
	\end{alignat*}
	\end{equation} Hence,
	\begin{equation}
	\begin{alignat*}{2}
	h_\gamma(u) v^\gamma + h_\gamma(v) &= h_\gamma(v) u^\gamma + h_\gamma(u) \\
	\iff h_\gamma(u) (v^\gamma - 1) &= h_\gamma(v) (u^\gamma - 1) \\
	\implies \exists d : h_\gamma(u) &= d (u^\gamma - 1)
	\end{alignat*}
	\end{equation} where $d$ is a constant, if we take $d = \frac{1}{c \gamma}$, we get $c h_\gamma(u) = \frac{u^\gamma - 1}{\gamma}$
\end{itemize}
To conclude,
\begin{equation}
\begin{alignat*}{2}
\frac{U(x u) - U(x)}{a(x)} \xrightarrow[x \rightarrow + \infty]{} h(u)
\implies h(u) = c h_\gamma(u)
\end{alignat*}
\end{equation} for some constant $c$, with the auxiliary function $a$ regularly varying with index $\gamma$.
\paragraph{Back to the search of an explicit form for the limiting distributions} Let us assume that the condition $(\mathcal{C})$ holds, with $b_n = U(n)$ and $a_n = a(n)$.
\begin{equation}
\begin{alignat*}{2}
\mathrm{E}(g(\frac{M_n - b_n}{a_n})) &= \int_0^n \! g(\frac{U(\frac{n}{v}) - b_n}{a_n}) (1 - \frac{v}{n})^{n - 1}\, \mathrm{d}v \\
&= \int_0^n \! g(\frac{U(n \frac{1}{v}) - U(n)}{a(n)}) (1 - \frac{v}{n})^{n - 1}\, \mathrm{d}v \\
&\xrightarrow[x \rightarrow + \infty]{} \int_0^{+ \infty} \! g(h_\gamma(\frac{1}{v})) \exp(- v)\, \mathrm{d}v
\end{alignat*}
\end{equation}The last integral must be equal to $\int_{- \infty}^{+ \infty} \! g(u) \, \mathrm{d}G_\gamma(u)$

\subsubsection*{Solving the problem - step 2 : expliciting the $G_\gamma$ in earnest}
\paragraph{Case $\gamma = 0$} We make the following change of variables : $u = h_0(\frac{1}{v}) = \log(\frac{1}{v}) = - \log(v)$. \newline
$u = \log(v) \iff v = \exp(-u)$, with $u \in \mathbb{R}$, $v \in ]0,+ \infty[$.
\begin{equation}
\begin{alignat*}{2}
\mathrm{d}u &= - \frac{1}{v} \mathrm{d}v \\
\implies \int_0^{+ \infty} \! g(u) \exp(- v)\, \mathrm{d}v &= \int_0^{+ \infty} \! g(u) \exp(- \exp(- u)) (- v)\, \mathrm{d}u \\
\implies \int_0^{+ \infty} \! g(u) \exp(- v)\, \mathrm{d}v &= \int_0^{+ \infty} \! g(u) \exp(- \exp(- u)) (- \exp(- u))\, \mathrm{d}u \\
\implies \int_0^{+ \infty} \! g(u) \exp(- v)\, \mathrm{d}v &= \int_{- \infty}^{+ \infty} \! g(u) ( - \exp(- u)\exp(- \exp(- u))) \, \mathrm{d}u \\
\implies \int_0^{+ \infty} \! g(u) \exp(- v)\, \mathrm{d}v &= \int_{- \infty}^{+ \infty} \! g(u) \, \mathrm{d}(\exp(- \exp(- u))) \\
\end{alignat*}
\end{equation}
Finally, \underline{$\gamma > 0 \implies G_\gamma(u) = \exp(- \exp(- u)) $}
\paragraph{Case $\gamma \ne 0$} We make the following change of variables :
\begin{equation}
\begin{alignat*}{2}
u &= h_\gamma(\frac{1}{v}) = \frac{(\frac{1}{v})^\gamma - 1}{\gamma}\\
\iff (\frac{1}{v})^\gamma &= \gamma u + 1\\
\iff \frac{1}{v} &= (\gamma u + 1)^{\frac{1}{\gamma}} \\
\iff v &= (\gamma u + 1)^{- \frac{1}{\gamma}} \\ \\
\mathrm{d}v &= - \frac{1}{\gamma} \gamma (\gamma u + 1)^{- \frac{1}{\gamma} - 1} \mathrm{d}u \\
\implies \mathrm{d}v &= - (\gamma u + 1)^{- \frac{\gamma + 1}{\gamma}} \mathrm{d}u
\end{alignat*}
\end{equation} $v$ varies from $0^+$ to $+ \infty$,
\begin{itemize}
	\item \underline{If $\gamma > 0$}, $u = \frac{(\frac{1}{v})^\gamma - 1}{\gamma}$, varying from $- \infty$ to $- \gamma^{-1}$.
	\item \underline{If $\gamma < 0$}, $u = - \frac{v^{- \gamma} + 1}{- \gamma}$, varying from $- \gamma^{-1}$ to $- \infty$.
\end{itemize}
\begin{equation}
\begin{alignat*}{2}
\int_0^{+ \infty} \! g(u) \exp(- v)\, \mathrm{d}v &=  \int_{+ \infty / - \gamma^{-1}}^{- \gamma^{-1} / - \infty} \! g(u) \exp(- (1 + \gamma u)^{- \frac{1}{\gamma}}) (- (1 + \gamma u)^{- \frac{\gamma + 1}{\gamma}})\, \mathrm{d}u \\
&=  \int_{ - \gamma^{-1} / - \infty}^{+ \infty / - \gamma^{-1}} \! g(u) (1 + \gamma u)^{- \frac{\gamma + 1}{\gamma}} \exp(- (1 + \gamma u)^{- \frac{1}{\gamma}})  \, \mathrm{d}u \\
\end{alignat*}
\end{equation}
\begin{equation}
\begin{alignat*}{2}
\mathrm{d}(\exp(- (1 + \gamma u)^{- \frac{1}{\gamma}})) &=  (1 + \gamma u)^{- \frac{\gamma + 1}{\gamma}} \exp(- (1 + \gamma u)^{- \frac{1}{\gamma}}) \mathrm{d}u
\end{alignat*}
\end{equation}
Finally, the last integral in $(2.15)$ is equal to,
\begin{itemize}
	\item \underline{If $\gamma > 0$},  $\int_{ - \gamma^{-1}}^{+ \infty} \! g(u) \, \mathrm{d}(\exp(- (1 + \gamma u)^{- \frac{1}{\gamma}}))$
	\item \underline{If $\gamma < 0$},  $\int_{ - \infty}^{ - \gamma^{-1}} \! g(u) \, \mathrm{d}(\exp(- (1 + \gamma u)^{- \frac{1}{\gamma}}))$
\end{itemize}
Finally, to sum it up :
\begin{itemize}
	\item \underline{$\gamma = 0$ :} \textbf{Gumbel distribution} \newline
	$G_\gamma(u) = \exp(- \exp(- u))$, $u \in \mathbb{R}$
	\item \underline{$\gamma > 0$ :} \textbf{Fréchet distribution} \newline
	$G_\gamma(u) = \exp(- (1 + \gamma u)^{- \frac{1}{\gamma}})$, $u \in ]- \gamma^{-1}, + \infty[$
	\item \underline{$\gamma > 0$ :} \textbf{Weibull distribution} \newline
	$G_\gamma(u) = \exp(- (1 + \gamma u)^{- \frac{1}{\gamma}})$, $u \in ]- \infty, - \gamma^{-1}[$
\end{itemize}


\documentclass[a4paper12pt,titlepage]{article}
\usepackage{titling}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\usepackage{amsmath}
\usepackage{breqn}
\usepackage{graphicx}
\usepackage{array}
\usepackage{xunicode}
\usepackage{unicode-math}
\usepackage{enumitem}
\usepackage[margin=2.0cm]{geometry}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\title{\textbf{MTH 264 Project III}}

\author{Kemal Ficici}

\setcounter{page}{1}
\begin{document}
\maketitle

\clearpage

\section{Problems}

Use the following methods to approximate definite integrals:
    \begin{enumerate}
        \item Bayesian Numerical Integral
        \item Monte Carlo Integration with Trig Distribution
    \end{enumerate}
\textbf{NOTE: } $N = 1000$, repeat 5 times.

\subsection{Functions}
    Integrate the following functions using the methods listed above.
    \LARGE{
        \begin{enumerate}[label=\roman*.]

            \item $\int_{0}^{\pi/2} \sin{x^2} dx$
            \item $\int_{0}^{\pi/2} \frac{x}{\sin{x}} dx$
            \item $\int_{0}^{\pi/2} \frac{e^x -1}{\sin{x}} dx$
        \end{enumerate}
    }
\clearpage

\section{Solutions}
    \subsection{Bayesian Numerical Integral}
        \normalsize{The Bayesian Numerical Integral method was used to approximate the integrals of the assigned functions. The table below lists the results of 5 runs on each function. The results are relatively consistent with each other, with small variations due to the randomness involved with Bayesian Numerical integration.}

        \begin{table}[h!]
          \begin{center}
            \label{tab:table1}
            \begin{tabular}{|c|c|c|}
              \toprule
              \large{\textbf{$\int_{0}^{\pi/2} \sin{x^2} dx$}} & \large{\textbf{$\int_{0}^{\pi/2} \frac{x}{\sin{x}} dx$}} & \large{\textbf{$\int_{0}^{\pi/2} \frac{e^x -1}{\sin{x}} dx$}}\\
              \hline
              \normalsize{0.84045118983470} &\normalsize{1.82519731136805} & \normalsize{2.92034205525110}\\
              \hline
              \normalsize{0.81300986203938} &\normalsize{1.82513807323085} & \normalsize{2.87723163838495}\\
              \hline
              \normalsize{0.80562048631475} &\normalsize{1.82775260493337} & \normalsize{2.85772229012692}\\
              \hline
              \normalsize{0.80003778520629} &\normalsize{1.82696575239499} & \normalsize{2.87493520874632}\\
              \hline
              \normalsize{0.83704060284947} &\normalsize{1.83013519198564} & \normalsize{2.82211105757757}\\
              \hline

            \end{tabular}
          \end{center}
        \end{table}

        \subsection{Monte Carlo Integration}
        \normalsize{
        Monte Carlo Integration was used to approximate the integrals of the assigned functions. Instead of using a random distribution, we used a trig distribution in the algorithm. The table below lists the results of 5 runs on each function. }

        \begin{table}[h!]
          \begin{center}
            \label{tab:table1}
            \begin{tabular}{|c|c|c|}
              \toprule
              \large{\textbf{$\int_{0}^{\pi/2} \sin{x^2} dx$}} & \large{\textbf{$\int_{0}^{\pi/2} \frac{x}{\sin{x}} dx$}} & \large{\textbf{$\int_{0}^{\pi/2} \frac{e^x -1}{\sin{x}} dx$}}\\
              \hline
              \normalsize{0.95969077502208} &\normalsize{1.93637690507613} & \normalsize{2.99868399929463}\\
              \hline
              \normalsize{0.96755709285013} &\normalsize{1.94625637908162} & \normalsize{3.19707021807748}\\
              \hline
              \normalsize{0.97699667424379} &\normalsize{2.00553322311456} & \normalsize{2.86896993316738}\\
              \hline
              \normalsize{0.97070361998135} &\normalsize{1.94625637908162} & \normalsize{3.14365854378979}\\
              \hline
              \normalsize{0.95969077502208} &\normalsize{1.96848519559397} & \normalsize{3.18943997889353}\\
              \hline

            \end{tabular}
          \end{center}
        \end{table}

\clearpage
\section{Code}
    \subsection{Bayesian Numerical Integral}
    \lstinputlisting[firstline=0]{problems/p3_a.m}
    \clearpage
    \subsection{Monte Carlo Integration with Trig Distribution}
    \lstinputlisting[firstline=0]{problems/p3_b.m}
\end{document}


\documentclass{article}

% - style template
\usepackage{base}
\geometry{a4paper, margin = 1in}

% - title, author, etc.
\title{PHYS4000 - Workshop 5}
\author{Tom Ross - 1834 2884}
\date{\today}

% - headers
\pagestyle{fancy}
\fancyhf{}
\rhead{\theauthor}
\chead{}
\lhead{\thetitle}
\rfoot{\thepage}
\cfoot{}
\lfoot{}

% - document
\begin{document}

\tableofcontents

\listoffigures

\listoftables

\clearpage

The entire code repository used to calculate the data for this report can be
found at \url{https://github.com/dgsaf/acqm-workshop-5}.
Note that \autoref{sec:reduced-ccc-code} has not yet been attempted - it may be
at a later date if time permits.

\section{e-H V-Matrix}
\label{sec:e-h-v-matrix}

\subsection{Implementation}
\label{sec:implementation}

We denote the hydrogen target states by $\ket{\phi_{i}}$, and we denote the
electron projectile states by $\ket{\vb{k}}$ corresponding to continuum waves
with energy $\tfrac{1}{2} k^{2}$, where $k = \lrnorm{\vb{k}}$.
We shall work in the s-wave model; that is, we only consider target states
with $\ell_{i} = 0$ and $m_{i} = 0$, and continuum states with
\begin{equation*}
  \braket{\vb{r}}{\vb{k}}
  =
  N_{k}
  \sin\lr{r k}
  .
\end{equation*}
Note that we shall neglect the normalisation constants $N_{k}$ henceforth.
We calculate potential matrix elements of the form
\begin{alignat*}{2}
  V_{f, i}^{\lr{S}}\lr{k', k}
  {}={}
  &
  \mel{k', \phi_{f}}{\hat{V}^{S}}{\phi_{i}, k}
  \\
  {}={}
  &
  \mel
  {k', \phi_{f}}
  {\hat{V} - \lr{-1}^{S}\lr{E- \hat{H}}\hat{P}_{r}}
  {\phi_{i}, k}
  \\
  {}={}
  &
  \mel{k', \phi_{f}}{\hat{V}_{1} + \hat{V}_{1, 2}}{\phi_{i}, k}
  -
  \lr{-1}^{S}
  \mel{k', \phi_{f}}{E - \hat{H}}{k, \phi_{i}}
  \\
  {}={}
  &
  D_{f, i}\lr{k', k}
  -
  \lr{-1}^{S}
  X_{f, i}\lr{k', k}
\end{alignat*}
where $D_{f, i}\lr{k', k}$ is the direct matrix element, $X_{f, i}\lr{k', k}$ is
the exchange matrix element, and where $\hat{V}_{1}$ is the electron-nuclear
potential of the form
\begin{equation*}
  \hat{V}_{1}
  =
  -
  \dfrac{1}{r_{1}}
  ,
\end{equation*}
and where $\hat{V}_{1, 2}$ is the electron-electron potential of the form
\begin{equation*}
  \hat{V}_{1, 2}
  =
  \dfrac{1}{\lrnorm{\vb{r}_{1} - \vb{r}_{2}}}
  =
  \sum_{\lambda = 0}^{\infty}
  \dfrac{4\pi}{2\lambda + 1}
  \dfrac{r_{<}^{\lambda}}{r_{>}^{\lambda + 1}}
  \sum_{\mu = -\lambda}^{\lambda}
  Y_{\lambda}^{\mu}\lr{\Omega_{1}}
  {Y_{\lambda}^{\mu}}^{*}\lr{\Omega_{2}}
\end{equation*}
where $r_{<} = \min\lr{r_{1}, r_{2}}$, $r_{>} = \max\lr{r_{1}, r_{2}}$,
and where $Y_{\lambda}^{\mu}$ are the spherical harmonics.
However, within the s-wave model this potential reduces to the form
\begin{equation*}
  \hat{V}_{1, 2}
  =
  \dfrac{1}{r_{>}}
  =
  \dfrac{1}{\max\lr{r_{1}, r_{2}}}
  .
\end{equation*}

\subsubsection{Calculation of Direct Matrix Elements $D_{f, i}\lr{k', k}$}
\label{sec:calc-dir-me}

The direct matrix elements are of the form
\begin{equation*}
  D_{f, i}\lr{k', k}
  =
  \mel{k', \phi_{f}}{\hat{V}_{1} + \hat{V}_{1, 2}}{\phi_{i}, k}
\end{equation*}
where
\begin{alignat*}{2}
  \mel{k', \phi_{f}}{\hat{V}_{1}}{\phi_{i}, k}
  {}={}
  &
  \mel{k'}{\hat{V}_{1}}{k}
  \braket{\phi_{f}}{\phi_{i}}
  \\
  {}={}
  &
  -
  \int_{0}^{\infty}
  {
    \dfrac{1}{r_{1}}
    \sin\lr{k' r_{1}}
    \sin\lr{k r_{1}}
  }
  \dd{r_{1}}
  \int_{0}^{\infty}
  {
    \phi_{f}\lr{r_{2}}
    \phi_{i}\lr{r_{2}}
  }
  \dd{r_{2}}
  \\
  {}={}
  &
  -
  \int_{0}^{\infty}
  {
    \dfrac{1}{r_{1}}
    \sin\lr{k' r_{1}}
    \sin\lr{k r_{1}}
  }
  \dd{r_{1}}
  \delta_{f, i}
\end{alignat*}
and where
\begin{alignat*}{2}
  \mel{k', \phi_{f}}{\hat{V}_{1, 2}}{\phi_{i}, k}
  {}={}
  &
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    \sin\lr{k' r_{1}}
    \phi_{f}\lr{r_{2}}
    \dfrac{1}{\max\lr{r_{1}, r_{2}}}
    \sin\lr{k r_{1}}
    \phi_{i}\lr{r_{2}}
  }
  \dd{r_{1}}
  \dd{r_{2}}
  \\
  {}={}
  &
  \int_{0}^{\infty}
  {
    \sin\lr{k' r_{1}}
    \sin\lr{k r_{1}}
    \lr[\bigg]
    {
      \int_{0}^{\infty}
      {
        \dfrac{1}{\max\lr{r_{1}, r_{2}}}
        \phi_{f}\lr{r_{2}}
        \phi_{i}\lr{r_{2}}
      }
      \dd{r_{2}}
    }
  }
  \dd{r_{1}}
  \\
  {}={}
  &
  \int_{0}^{\infty}
  {
    \sin\lr{k' r_{1}}
    \sin\lr{k r_{1}}
    \lr[\bigg]
    {
      \dfrac{1}{r_{1}}
      \int_{0}^{r_{1}}
      {
        \phi_{f}\lr{r_{2}}
        \phi_{i}\lr{r_{2}}
      }
      \dd{r_{2}}
      +
      \int_{r_{1}}^{\infty}
      {
        \dfrac{1}{r_{2}}
        \phi_{f}\lr{r_{2}}
        \phi_{i}\lr{r_{2}}
      }
      \dd{r_{2}}
    }
  }
  \dd{r_{1}}
  .
\end{alignat*}

\subsubsection{Calculation of Exchange Matrix Elements $X_{f, i}\lr{k', k}$}
\label{sec:calc-exc-me}

The exchange matrix elements are of the form
\begin{alignat*}{2}
  X_{f, i}\lr{k', k}
  {}={}
  &
  \mel{k', \phi_{f}}{E - \hat{H}}{k, \phi_{i}}
  \\
  {}={}
  &
  \lr
  {
    E
    -
    \tfrac{1}{2} k'^{2}
    -
    \tfrac{1}{2} k^{2}
  }
  \braket{k'}{\phi_{i}}
  \braket{\phi_{f}}{k}
  \\
  &
  {}-{}
  \mel{k'}{\hat{V}_{1}}{\phi_{i}}
  \braket{\phi_{f}}{k}
  -
  \braket{k'}{\phi_{i}}
  \mel{\phi_{f}}{\hat{V}_{2}}{k}
  \\
  &
  {}-{}
  \mel{k', \phi_{f}}{\hat{V}_{1, 2}}{k \phi_{i}}
\end{alignat*}
where the one-electron inner products are of the form
\begin{equation*}
  \braket{f}{g}
  =
  \int_{0}^{\infty}
  {
    f\lr{r}
    g\lr{r}
  }
  \dd{r}
\end{equation*}
and where the two-electron inner product is of the form
\begin{alignat*}{2}
  \mel{k', \phi_{f}}{\hat{V}_{1, 2}}{k \phi_{i}}
  {}={}
  &
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    \sin\lr{k' r_{1}}
    \phi_{f}\lr{r_{2}}
    \dfrac{1}{\max\lr{r_{1}, r_{2}}}
    \phi_{i}\lr{r_{1}}
    \sin\lr{k r_{2}}
  }
  \dd{r_{1}}
  \dd{r_{2}}
  \\
  {}={}
  &
  \int_{0}^{\infty}
  {
    \sin\lr{k' r_{1}}
    \phi_{i}\lr{r_{1}}
    \lr[\bigg]
    {
      \int_{0}^{\infty}
      {
        \dfrac{1}{\max\lr{r_{1}, r_{2}}}
        \phi_{f}\lr{r_{2}}
        \sin\lr{k r_{2}}
      }
      \dd{r_{2}}
    }
  }
  \dd{r_{1}}
  \\
  {}={}
  &
  \int_{0}^{\infty}
  {
    \sin\lr{k' r_{1}}
    \phi_{i}\lr{r_{1}}
    \lr[\bigg]
    {
      \dfrac{1}{r_{1}}
      \int_{0}^{r_{1}}
      {
        \phi_{f}\lr{r_{2}}
        \sin\lr{k r_{2}}
      }
      \dd{r_{2}}
      +
      \int_{r_{1}}^{\infty}
      {
        \dfrac{1}{r_{2}}
        \phi_{f}\lr{r_{2}}
        \sin\lr{k r_{2}}
      }
      \dd{r_{2}}
    }
  }
  \dd{r_{1}}
  \\
\end{alignat*}

\subsubsection{Evaluation of Integrals}
\label{sec:eval-int}

We suppose that the radial functions are to be plotted on a radial grid of the
form $\mathcal{R} = \lrset{k \delta_{r}}_{k = 1}^{n_{r}}$ for
$n_{r} > 0$ and small $\delta_{r} > 0$, and with a corresponding set of weights
$\mathcal{W} = \lrset{w_{k}}_{k = 1}^{n_{r}}$ such that
\begin{equation*}
  \int_{0}^{\infty}
  {
    f\lr{r}
  }
  \dd{r}
  =
  \lim_{n_{r} \to \infty}
  \sum_{k = 1}^{n_{r}}
  {
    w_{k}
    f\lr{r_{k}}
  }
  =
  \lim_{n_{r} \to \infty}
  \sum_{k = 1}^{n_{r}}
  {
    w_{k}
    f_{k}
  }
  \approx
  \sum_{k = 1}^{n_{r}}
  {
    w_{k}
    f_{k}
  }
  .
\end{equation*}
The one-electron integrals, of the form $\braket{f}{g}$, are then
evaluated in the following manner
\begin{equation*}
  \braket{f}{g}
  =
  \int_{0}^{\infty}
  {
    f\lr{r}
    g\lr{r}
  }
  \dd{r}
  \approx
  \sum_{k = 1}^{n_{r}}
  {
    w_{k}
    f_{k}
    g_{k}
  }
  .
\end{equation*}
The two electron integrals $\bra{F} {} \ket{G}$ where
\begin{equation*}
  \bra{F} {} \ket{G}
  =
  \int_{0}^{\infty}
  {
    F\lr{r_{1}}
    \lr[\bigg]
    {
      \dfrac{1}{r_{1}}
      \int_{0}^{r_{1}}
      {
        G\lr{r_{2}}
      }
      \dd{r_{2}}
      +
      \int_{r_{1}}^{\infty}
      {
        \dfrac{1}{r_{2}}
        G\lr{r_{2}}
      }
      \dd{r_{2}}
    }
  }
  \dd{r_{1}}
  ,
\end{equation*}
are evaluated in the following manner
\begin{equation*}
  \bra{F} {} \ket{G}
  \approx
  \sum_{k = 1}^{n_{r}}
  {
    w_{k}
    F_{k}
    \lr[\bigg]
    {
      \dfrac{1}{r_{k}}
      A_{k}
      +
      B_{k}
    }
  }
\end{equation*}
where
\begin{equation*}
  A_{k}
  =
  \sum_{m = 1}^{k}
  {
    w_{m}
    G_{m}
  }
  =
  \begin{cases}
    A_{k - 1}
    +
    w_{k}
    G_{k}
    &
    \qq{for}
    k = 2, \dotsc, n_{r}
    \\
    w_{k}
    G_{k}
    &
    \qq{for}
    k = 1
  \end{cases}
\end{equation*}
and
\begin{equation*}
  B_{k}
  =
  \sum_{m = k}^{n_{r}}
  {
    \dfrac{1}{r_{m}}
    w_{m}
    G_{m}
  }
  =
  \begin{cases}
    B_{k + 1}
    +
    \tfrac{1}{r_{k}}
    w_{k}
    G_{k}
    &
    \qq{for}
    k = 1, \dotsc, n_{r} - 1
    \\
    \tfrac{1}{r_{k}}
    w_{k}
    G_{k}
    &
    \qq{for}
    k = n_{r}
  \end{cases}
  .
\end{equation*}

\clearpage

For these calculations, we have used: a radial grid of the form
$\mathcal{R} = \lrset{i \delta_{r}}_{i = 1}^{n_{r}}$, with
$\delta_{r} = 0.01$ and $\max\lr{\mathcal{R}} = 100$,
and a momentum grid of the form
$\mathcal{K} = \lrset{i \delta_{k}}_{i = 1}^{n_{k}}$, with
$\delta_{k} = 0.025$ and $\max\lr{\mathcal{K}} = 5$.

\subsection{Direct Matrix Elements}
\label{sec:dir-me}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_1s_dir.tex}
  \end{center}
  \caption[Direct Matrix Elements 1s-1s]{
    The $D_{f, i}\lr{k', k}$ direct matrix elements (shown in red) are presented
    for the $1s \to 1s$ transition, with $E = \SI{10}{\eV}$.
  }
  \label{fig:dir-me-1s-1s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_2s_dir.tex}
  \end{center}
  \caption[Direct Matrix Elements 1s-2s]{
    The $D_{f, i}\lr{k', k}$ direct matrix elements (shown in red) are presented
    for the $1s \to 2s$ transition, with $E = \SI{10}{\eV}$.
  }
  \label{fig:dir-me-1s-2s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_3s_dir.tex}
  \end{center}
  \caption[Direct Matrix Elements 1s-3s]{
    The $D_{f, i}\lr{k', k}$ direct matrix elements (shown in red) are presented
    for the $1s \to 3s$ transition, with $E = \SI{10}{\eV}$.
  }
  \label{fig:dir-me-1s-3s}
\end{figure}

\clearpage

\subsection{Exchange Matrix Elements}
\label{sec:exc-me}

\subsubsection{$X_{f, i}\lr{k', k}$ for $E = \SI{10}{\eV}$}
\label{sec:exc-me-10}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_1s_exc.tex}
  \end{center}
  \caption[Exchange Matrix Elements 1s-1s]{
    The $X_{f, i}\lr{k', k}$ exchange matrix elements (shown in blue) are
    presented for the $1s \to 1s$ transition, with $E = \SI{10}{\eV}$.
  }
  \label{fig:exc-me-1s-1s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_2s_exc.tex}
  \end{center}
  \caption[Exchange Matrix Elements 1s-2s]{
    The $X_{f, i}\lr{k', k}$ exchange matrix elements (shown in blue) are
    presented for the $1s \to 2s$ transition, with $E = \SI{10}{\eV}$.
  }
  \label{fig:exc-me-1s-2s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_3s_exc.tex}
  \end{center}
  \caption[Exchange Matrix Elements 1s-3s]{
    The $X_{f, i}\lr{k', k}$ exchange matrix elements (shown in blue) are
    presented for the $1s \to 3s$ transition, with $E = \SI{10}{\eV}$.
  }
  \label{fig:exc-me-1s-3s}
\end{figure}

\clearpage

\subsubsection{$X_{f, i}\lr{k', k}$ for $E = \SI{1}{\eV}$}
\label{sec:exc-me-1}

\begin{figure}[h]
  \begin{center}
    \input{figure_1_1s_1s_exc.tex}
  \end{center}
  \caption[Exchange Matrix Elements 1s-1s]{
    The $X_{f, i}\lr{k', k}$ exchange matrix elements (shown in blue) are
    presented for the $1s \to 1s$ transition, with $E = \SI{1}{\eV}$.
  }
  \label{fig:exc-me-1s-1s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_1_1s_2s_exc.tex}
  \end{center}
  \caption[Exchange Matrix Elements 1s-2s]{
    The $X_{f, i}\lr{k', k}$ exchange matrix elements (shown in blue) are
    presented for the $1s \to 2s$ transition, with $E = \SI{1}{\eV}$.
  }
  \label{fig:exc-me-1s-2s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_1_1s_3s_exc.tex}
  \end{center}
  \caption[Exchange Matrix Elements 1s-3s]{
    The $X_{f, i}\lr{k', k}$ exchange matrix elements (shown in blue) are
    presented for the $1s \to 3s$ transition, with $E = \SI{1}{\eV}$.
  }
  \label{fig:exc-me-1s-3s}
\end{figure}

\clearpage

\subsection{On-Shell Matrix Elements}
\label{sec:on-me}

For the transisiton $[i \to f]$, the on-shell energy is of the form
\begin{equation*}
  \epsilon_{i}
  +
  \dfrac{1}{2}
  k^{2}
  =
  E
  =
  \epsilon_{f}
  +
  \dfrac{1}{2}
  k'^{2}
\end{equation*}
whence the on-shell value for $k'$ is defined by
\begin{equation*}
  \dfrac{1}{2}
  k'^{2}
  =
  E
  -
  \epsilon_{f}
  =
  \dfrac{1}{2}
  k^{2}
  +
  \epsilon_{i}
  -
  \epsilon_{f}
\end{equation*}
where for the case of a hydrogen target, with
$\epsilon_{n} = -\tfrac{1}{2n^{2}}$, and $i = 1$, we have have that
\begin{equation*}
  k'
  =
  \sqrt
  {
    k^{2}
    -
    \dfrac{f^{2} - 1}{f^{2}}
  }
  .
\end{equation*}
Note that transitions are forbidden for
\begin{equation*}
  k^{2}
  <
  \dfrac{f^{2} - 1}{f^{2}}
  =
  1
  -
  \dfrac{1}{f^{2}}
  .
\end{equation*}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_1s_on.tex}
  \end{center}
  \caption[On-Shell Matrix Elements 1s-1s]{
    The $D_{f, i}\lr{k', k}$ direct and $X_{f, i}\lr{k', k}$ exchange on-shell
    matrix elements (shown in red and blue respectively) are presented for the
    $1s \to 1s$ transition, and are compared with their respective analytic
    expressions (shown in black).
  }
  \label{fig:on-me-1s-1s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_2s_on.tex}
  \end{center}
  \caption[On-Shell Matrix Elements 1s-2s]{
    The $D_{f, i}\lr{k', k}$ direct and $X_{f, i}\lr{k', k}$ exchange on-shell
    matrix elements (shown in red and blue respectively) are presented for the
    $1s \to 2s$ transition, and are compared with their respective analytic
    expressions (shown in black).
  }
  \label{fig:on-me-1s-2s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{figure_10_1s_3s_on.tex}
  \end{center}
  \caption[On-Shell Matrix Elements 1s-3s]{
    The $D_{f, i}\lr{k', k}$ direct and $X_{f, i}\lr{k', k}$ exchange on-shell
    matrix elements (shown in red and blue respectively) are presented for the
    $1s \to 3s$ transition, and are compared with their respective analytic
    expressions (shown in black).
  }
  \label{fig:on-me-1s-3s}
\end{figure}

\clearpage

\section{$V_{1 2}$ Potential in S-Wave Model}
\label{sec:v12-swave}

We note that the general form for a continuum wave
$\ket{\vb{k}} = \ket{k, \ell, m}$ is
\begin{equation*}
  \braket{\vb{r}}{\vb{k}}
  =
  \dfrac{1}{r}
  u_{\ell}\lr{r; k}
  Y_{\ell}^{m}\lr{\Omega}
  ,
\end{equation*}
and that the general form for the hydrogen target states
$\ket{\phi_{i}} = \ket{\phi_{n_{i}, \ell_{i}, m_{i}}}$ is
\begin{equation*}
  \braket{\vb{r}}{\phi_{i}}
  =
  \dfrac{1}{r}
  \phi_{i}\lr{r}
  Y_{\ell_{i}}^{m_{i}}\lr{\Omega}
  .
\end{equation*}
Recall that the electron-electron potential is of the form
\begin{equation*}
  \hat{V}_{1, 2}
  =
  \dfrac{1}{\lrnorm{\vb{r}_{1} - \vb{r}_{2}}}
  =
  \sum_{\lambda = 0}^{\infty}
  \dfrac{4\pi}{2\lambda + 1}
  \dfrac{r_{<}^{\lambda}}{r_{>}^{\lambda + 1}}
  \sum_{\mu = -\lambda}^{\lambda}
  Y_{\lambda}^{\mu}\lr{\Omega_{1}}
  {Y_{\lambda}^{\mu}}^{*}\lr{\Omega_{2}}
\end{equation*}
where $r_{<} = \min\lr{r_{1}, r_{2}}$, $r_{>} = \max\lr{r_{1}, r_{2}}$,
and where $Y_{\lambda}^{\mu}$ are the spherical harmonics.
We now consider the form of the two-electron term in
$D_{f, i}\lr{\vb{k}', \vb{k}}$,
\begin{equation*}
  \mel{\vb{k}', \phi_{f}}{\hat{V}_{1, 2}}{\phi_{i}, \vb{k}}
  =
  \int
  \int
  {
    \braket{\vb{r}_{1}}{\vb{k}'}^{*}
    \braket{\vb{r}_{2}}{\phi_{f}}^{*}
    \dfrac{1}{\lrnorm{\vb{r}_{1} - \vb{r}_{2}}}
    \braket{\vb{r}_{1}}{\vb{k}}
    \braket{\vb{r}_{2}}{\phi_{i}}
  }
  \dd{\vb{r}_{1}}
  \dd{\vb{r}_{2}}
\end{equation*}
for which the partial wave expansion is of the form
\begin{alignat*}{3}
  &
  \mel{\vb{k}', \phi_{f}}{\hat{V}_{1, 2}}{\phi_{i}, \vb{k}}
  &{}={}&
  \sum_{\lambda = 0}^{\infty}
  \dfrac{4\pi}{2\lambda + 1}
  \sum_{\mu = -\lambda}^{\lambda}
  &&
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    \dfrac{u_{\ell'}\lr{r_{1}; k'}}{r_{1}}
    \dfrac{\phi_{f}\lr{r_{2}}}{r_{2}}
    \dfrac{r_{<}^{\lambda}}{r_{>}^{\lambda + 1}}
    \dfrac{\phi_{i}\lr{r_{2}}}{r_{2}}
    \dfrac{u_{\ell}\lr{r_{1}; k}}{r_{1}}
  }
  r_{1}^{2}
  r_{2}^{2}
  \dd{r_{1}}
  \dd{r_{2}}
  \\
  &
  {}
  &&
  {}
  &&
  {}\times{}
  \int_{S^{2}}
  {
    {Y_{\ell'}^{m'}}^{*}\lr{\Omega_{1}}
    Y_{\lambda}^{\mu}\lr{\Omega_{1}}
    Y_{\ell}^{m}\lr{\Omega_{1}}
  }
  \dd{\Omega_{1}}
  \\
  &
  {}
  &&
  {}
  &&
  {}\times{}
  \int_{S^{2}}
  {
    {Y_{\ell_{f}}^{m_{f}}}^{*}\lr{\Omega_{2}}
    {Y_{\lambda}^{\mu}}^{*}\lr{\Omega_{2}}
    Y_{\ell_{i}}^{m_{i}}\lr{\Omega_{2}}
  }
  \dd{\Omega_{2}}
  \\
  &
  {}
  &{}={}&
  \sum_{\lambda = 0}^{\infty}
  \dfrac{4\pi}{2\lambda + 1}
  \sum_{\mu = -\lambda}^{\lambda}
  &&
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    u_{\ell'}\lr{r_{1}; k'}
    \phi_{f}\lr{r_{2}}
    \dfrac{r_{<}^{\lambda}}{r_{>}^{\lambda + 1}}
    \phi_{i}\lr{r_{2}}
    u_{\ell}\lr{r_{1}; k}
  }
  \dd{r_{1}}
  \dd{r_{2}}
  \\
  &
  {}
  &&
  {}
  &&
  {}\times{}
  \int_{S^{2}}
  {
    {Y_{\ell'}^{m'}}^{*}\lr{\Omega_{1}}
    Y_{\lambda}^{\mu}\lr{\Omega_{1}}
    Y_{\ell}^{m}\lr{\Omega_{1}}
  }
  \dd{\Omega_{1}}
  \\
  &
  {}
  &&
  {}
  &&
  {}\times{}
  \int_{S^{2}}
  {
    {Y_{\ell_{f}}^{m_{f}}}^{*}\lr{\Omega_{2}}
    {Y_{\lambda}^{\mu}}^{*}\lr{\Omega_{2}}
    Y_{\ell_{i}}^{m_{i}}\lr{\Omega_{2}}
  }
  \dd{\Omega_{2}}
  .
\end{alignat*}
However, in the s-wave model, we have that that all $\ell, m$ terms (for the
continuum wave) are zero, where therefore all
$Y_{\ell}^{m}\lr{\Omega} = Y_{0}^{0}\lr{\Omega} = \tfrac{1}{\sqrt{4\pi}}$.
It then follows that
\begin{equation*}
  \int_{S^{2}}
  {
    {Y_{\ell'}^{m'}}^{*}\lr{\Omega_{1}}
    Y_{\lambda}^{\mu}\lr{\Omega_{1}}
    Y_{\ell}^{m}\lr{\Omega_{1}}
  }
  \dd{\Omega_{1}}
  =
  \dfrac{1}{\sqrt{4 \pi}}
  \int_{S^{2}}
  {
    {Y_{\ell'}^{m'}}^{*}\lr{\Omega_{1}}
    Y_{\lambda}^{\mu}\lr{\Omega_{1}}
  }
  \dd{\Omega_{1}}
  =
  \dfrac{1}{\sqrt{4 \pi}}
  \delta_{\ell', \lambda}
  \delta_{m', \mu}
\end{equation*}
and as $\ell', m' = 0$, the only non-zero term in the sum is where
$\lambda = \mu = 0$.
Whence, we have that
\begin{alignat*}{3}
  &
  \mel{\vb{k}', \phi_{f}}{\hat{V}_{1, 2}}{\phi_{i}, \vb{k}}
  &{}={}&
  \sqrt{4\pi}
  &&
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    u_{\ell'}\lr{r_{1}; k'}
    \phi_{f}\lr{r_{2}}
    \dfrac{r_{<}^{0}}{r_{>}^{1}}
    \phi_{i}\lr{r_{2}}
    u_{\ell}\lr{r_{1}; k}
  }
  \dd{r_{1}}
  \dd{r_{2}}
  \\
  &
  {}
  &&
  {}
  &&
  {}\times{}
  \int_{S^{2}}
  {
    {Y_{\ell_{f}}^{m_{f}}}^{*}\lr{\Omega_{2}}
    {Y_{0}^{0}}^{*}\lr{\Omega_{2}}
    Y_{\ell_{i}}^{m_{i}}\lr{\Omega_{2}}
  }
  \dd{\Omega_{2}}
  \\
  &
  {}
  &{}={}&
  &&
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    u_{\ell'}\lr{r_{1}; k'}
    \phi_{f}\lr{r_{2}}
    \dfrac{1}{r_{>}}
    \phi_{i}\lr{r_{2}}
    u_{\ell}\lr{r_{1}; k}
  }
  \dd{r_{1}}
  \dd{r_{2}}
  \\
  &
  {}
  &&
  {}
  &&
  {}\times{}
  \int_{S^{2}}
  {
    {Y_{\ell_{f}}^{m_{f}}}^{*}\lr{\Omega_{2}}
    Y_{\ell_{i}}^{m_{i}}\lr{\Omega_{2}}
  }
  \dd{\Omega_{2}}
  \\
  &
  {}
  &{}={}&
  &&
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    u_{\ell'}\lr{r_{1}; k'}
    \phi_{f}\lr{r_{2}}
    \dfrac{1}{r_{>}}
    \phi_{i}\lr{r_{2}}
    u_{\ell}\lr{r_{1}; k}
  }
  \dd{r_{1}}
  \dd{r_{2}}
  \\
  &
  {}
  &&
  {}
  &&
  {}\times{}
  \delta_{\ell_{f}, \ell_{i}}
  \delta_{m_{f}, m_{i}}
\end{alignat*}
and so we may restrict our attention to the case where
$\ell_{f} = \ell_{i}$ and $m_{f} = m_{i}$; that is, where the angular momentum
of the target is left unchanged.
Finally, we have that
\begin{equation*}
  \mel{\vb{k}', \phi_{f}}{\hat{V}_{1, 2}}{\phi_{i}, \vb{k}}
  =
  \mel{k', \phi_{f}}{\hat{V}_{1, 2}}{\phi_{i}, k}
  =
  \int_{0}^{\infty}
  \int_{0}^{\infty}
  {
    u_{\ell'}\lr{r_{1}; k'}
    \phi_{f}\lr{r_{2}}
    \dfrac{1}{r_{>}}
    \phi_{i}\lr{r_{2}}
    u_{\ell}\lr{r_{1}; k}
  }
  \dd{r_{1}}
  \dd{r_{2}}
\end{equation*}
yielding the result as required.

\clearpage

\section{Reduced CCC Code}
\label{sec:reduced-ccc-code}

\subsection{Triplet Half-on-Shell Matrix Elements}
\label{sec:triplet-me}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_triplet_0.tex}
  \end{center}
  \caption[Triplet $\theta = 0$]{
    The triplet half-on-shell direct matrix elements, $K\lr{k}$ (shown in solid
    lines) and $V\lr{k}$ (shown in dashed lines), are presented for the $1s \to
    1s$ transition, with $\theta = 0$, for both $k$-grids (shown in blue and
    red).
    Note that the $V\lr{k}$ matrix elements overlap for both grids, on their
    common domain.
  }
  \label{fig:triplet-me-0}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_triplet_1.tex}
  \end{center}
  \caption[Triplet $\theta = 1$]{
    The triplet half-on-shell direct matrix elements, $K\lr{k}$ (shown in solid
    lines) and $V\lr{k}$ (shown in dashed lines), are presented for the $1s \to
    1s$ transition, with $\theta = 1$, for both $k$-grids (shown in blue and
    red).
    Note that the $K\lr{k}$ and $V\lr{k}$ matrix elements overlap for both
    grids, on their common domain.
  }
  \label{fig:triplet-me-1}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_triplet_2.tex}
  \end{center}
  \caption[Triplet $\theta = 2$]{
    The triplet half-on-shell direct matrix elements, $K\lr{k}$ (shown in solid
    lines) and $V\lr{k}$ (shown in dashed lines), are presented for the $1s \to
    1s$ transition, with $\theta = 2$, for both $k$-grids (shown in blue and
    red).
    Note that the $K\lr{k}$ and $V\lr{k}$ matrix elements overlap for both
    grids, on their common domain.
    Note also that the $K\lr{k}$ matrix elements are essentially equivalent to
    those for $\theta = 1$, presented in \autoref{fig:triplet-me-1}, even though
    the $V\lr{k}$ matrix elements are different.
  }
  \label{fig:triplet-me-2}
\end{figure}

\clearpage

\subsection{Total Cross Sections}
\label{sec:tcs}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_tcs_1s.tex}
  \end{center}
  \caption[Total Cross Sections for $\lrsq{1s \to 1s}$]{
    The total cross sections, for $S = 0$ (shown in blue), $S = 1$ (shown in
    purple), and $S$ averaged (shown in red), are presented for the
    $\lrsq{1s \to 1s}$ transition, from \SIrange{1}{100}{\eV}.
    Note that this calculation was performed with $\rm{NPS} = 10$.
  }
  \label{fig:tcs-1s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_tcs_2s.tex}
  \end{center}
  \caption[Total Cross Sections for $\lrsq{1s \to 2s}$]{
    The total cross sections, for $S = 0$ (shown in blue), $S = 1$ (shown in
    purple), and $S$ averaged (shown in red), are presented for the
    $\lrsq{1s \to 2s}$ transition, from \SIrange{1}{100}{\eV}.
    Note that this calculation was performed with $\rm{NPS} = 10$.
  }
  \label{fig:tcs-2s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_tcs_3s.tex}
  \end{center}
  \caption[Total Cross Sections for $\lrsq{1s \to 3s}$]{
    The total cross sections, for $S = 0$ (shown in blue), $S = 1$ (shown in
    purple), and $S$ averaged (shown in red), are presented for the
    $\lrsq{1s \to 3s}$ transition, from \SIrange{1}{100}{\eV}.
    Note that this calculation was performed with $\rm{NPS} = 10$.
  }
  \label{fig:tcs-3s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_tcs_4s.tex}
  \end{center}
  \caption[Total Cross Sections for $\lrsq{1s \to 4s}$]{
    The total cross sections, for $S = 0$ (shown in blue), $S = 1$ (shown in
    purple), and $S$ averaged (shown in red), are presented for the
    $\lrsq{1s \to 4s}$ transition, from \SIrange{1}{100}{\eV}.
    Note that this calculation was performed with $\rm{NPS} = 10$.
  }
  \label{fig:tcs-4s}
\end{figure}

\begin{figure}[h]
  \begin{center}
    \input{ccc_figure_tcs_5s.tex}
  \end{center}
  \caption[Total Cross Sections for $\lrsq{1s \to 5s}$]{
    The total cross sections, for $S = 0$ (shown in blue), $S = 1$ (shown in
    purple), and $S$ averaged (shown in red), are presented for the
    $\lrsq{1s \to 5s}$ transition, from \SIrange{1}{100}{\eV}.
    Note that this calculation was performed with $\rm{NPS} = 10$.
  }
  \label{fig:tcs-5s}
\end{figure}

\end{document}


%!TEX root =  ../main.tex

\mychapters{Circles}{circle}{\chapdir/pics/Floating_Houses_Of_Malaysia}

Right triangles can be understood to a degree that is truly breath-taking.  With an
astoundingly low amount of information, the complete scenario can be flushed out.
This deep level of understanding is perhaps only known to cartographers and
video game designers, but angles and distances could enrich all our lives.

How can you know if I tree will fall on your house?  Armed with only how far away
it is, and the angle from your eye to the top (and your eye's height) you can tell
how high the tree is.

\newpage
\chapterminitoc

%									9 - 1
\newpage
\section{Angles}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch09/0901p.pdf}}
\input{ch09/0901}
\newpage
\subsection{Exercises}
in Kuta

%									9 - 2
\newpage
\section{Reference Triangles}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch09/0902p.pdf}}
\subsection{Special Triangles}
\input{ch09/0902}
~\vfill
\newpage
\subsection{Exercises}
in Kuta
~\vfill

%									9 - 3
%\newpage
\section{Radians}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch09/0903p.pdf}}
\newpage
\input{ch09/0903}
\newpage
\subsection{Exercises}
in Kuta in two parts
~\vfill

%									9 - 4
%\newpage
\invisiblesection{Graphs}
\subsection{Problems}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch09/0904p.pdf}}
\input{ch09/0904}
\newpage
\subsection{Exercises}
in Kuta

%									9 - 5
\newpage
\invisiblesection{Inverse Trigonometric Functions}
\subsection{Problems}
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{ch09/0905p.pdf}}
\input{ch09/0905}
\newpage
\subsection{Exercises}
in kuta in two parts

%									9 - 6
\newpage
\section{Review}
\subsection{Chapter Review}
\subsection{Chapter Test}


\part{part}
         part text
         part text
         \chapter{chapter long title}
          chapter text
          chapter text
          \[
          	f(x)=x^2
          \]
          \section[for the toc]{section}
           section text
           section text
          \section[for the toc]{section}
           section text
           section text
          \subsection[for the toc]{subsection}
          	subsection text
          	subsection text
          \subsection[for the toc]{subsection}
          	subsection text
          	subsection text
          \section[for the toc]{section}
           section text
           section text
         \chapter{chapter}
          chapter text
          chapter text
\part{part}
         part text
         part text
         \chapter[toc]{chapter title}
          chapter text
          chapter text
          \section[for the toc]{section}
           section text
           section text
           \subsubsection[for the toc]{subsubsection}
           	subsubsection text
           	subsubsection text
           	\paragraph{paragraph}
           		paragraph text
           		paragraph text
           		\subparagraph{subparagraph}
           			subparagraph text
           			subparagraph text
          \section[for the toc]{section}
           section text
           section text
           \subsubsection[for the toc]{subsubsection}
           	subsubsection text
           	subsubsection text
           	\paragraph{paragraph}
           		paragraph text
           		paragraph text
           		\subparagraph{subparagraph}
           			subparagraph text
           			subparagraph text
         \chapter[somethingelse]{goes here}


\chapter{Safety proof and formal specification}
\label{appendix:correctness}

This appendix includes a formal specification and a proof of safety for
the basic Raft algorithm presented in Chapter~\ref{basicraft}. The
specification and proof are introduced in Chapter~\ref{correctness}.

The formal specification makes the information summarized in
Figure~\ref{fig:basicraft:cheatsheet} completely precise using the TLA+
specification language~\cite{Lamport:2002}. It serves as the subject of
the proof and is a useful reference for implementing Raft.

The proof shows that the specification preserves the State Machine
Safety property. The main idea of the proof is summarized in
Section~\ref{basicraft:safety:argument}, but the detailed proof is much
more precise. We found the proof useful in understanding Raft's safety
at a deeper level, and others may find value in this as well. However,
the proof is fairly long and difficult for humans to verify and
maintain; we believe it to be basically correct, but it might include
errors or omissions. At this scale, only a machine-checked proof could
definitively be error-free.

\section{Conventions}
The specification uses the syntax and semantics of the TLA+ language
version~2~\cite{Lamport:2002}.
The proof uses the same syntax and semantics but
with the following minor allowances for convenience:
\begin{itemize}
\item As in TLA+, $foo'$ has a specific meaning: the value of variable
$foo$ in the next state of the system.

\item Define $\langle index, term \rangle \in log$ iff \\
      $Len(log) \geq index \sland log[index].term = term$.

\item The symbol $\cat$ is used for concatenation of logs and entries.

\item Values in log entries are not included, since a
value is attached to a particular $\langle index, term \rangle$, and
those uniquely identify a log entry.
\end{itemize}

\section{Specification}

This section provides a complete, formal description of the Raft
algorithm.
A copy of the TLA+ source file can is available at~\cite{raft.tla}.

\input{proof/rafttla}

\renewcommand\A{\forall\ }
\renewcommand\E{\exists\ }
\renewcommand\implies{\Rightarrow}

\section{Proof}

\begin{lemma} % currentTerm[i] monotonically increases
\label{appendix:correctness:currenttermmonotonic}
Each server's $currentTerm$ monotonically increases:
\begin{tabbing}
\tab\=\+
$\A i \in Server : $ \\
\tab\=\+
$currentTerm[i] \leq currentTerm'[i]$
\end{tabbing}
\end{lemma}

\begin{proof}
This follows immediately from the specification.
\end{proof}

\begin{lemma} % at most one leader per term
\label{appendix:correctness:olpt}
There is at most one leader per term:
\begin{tabbing}
\tab\=\+
$\A e,f \in elections : $ \\
\tab\=\+
$e.eterm = f.eterm \implies e.eleader = f.eleader$
\end{tabbing}
This is the Election Safety property of
Figure~\ref{fig:basicraft:properties}.
\end{lemma}

\begin{sketch}
It takes votes from a quorum to become leader, voters may only vote
once per term, and any two quorums overlap.
\end{sketch}

\begin{proof}\
\begin{enumerate}
\item Consider two elections, $e$ and $f$, both members of $elections$,
where $e.eterm = f.eterm$.
\item $e.evotes \in Quroum$ and $f.evotes \in Quorum$,
since this is a necessary condition for members of $elections$.
\item Let $voter$ be an arbitrary member of $e.evotes \cap
f.evotes$. Such a member must exist since any two quorums overlap.
\item Once $voter$ casts a vote for $e.eleader$ in $e.eterm$, it can not
cast a vote for a different server in $e.eterm$ (the specification ensures
this: once it increments its $currentTerm$, it can never vote again for
the same server (Lemma~\ref{appendix:correctness:currenttermmonotonic});
and until then, it safely retains its vote information).
\item $e.eleader = f.eleader$, since $voter$ voted for $e.eleader$ and
$voter$ voted for $f.eleader$ in $e.eterm=f.eterm$.
\end{enumerate}
\end{proof}

\begin{lemma} % leader only appends
\label{appendix:correctness:leaderlogmonotonic}
A leader's log monotonically grows during its term:
\begin{tabbing}
\tab\=\+
$\A e \in elections :$ \\
\tab\tab\=\+
$currentTerm[e.leader] = e.term \implies$ \\
\tab\tab\=\+
$\A index \in 1..Len(log[e.leader]) :$ \\
\tab\tab\=\+
$log'[e.leader][index] = log[e.leader][index]$
\end{tabbing}
This is the Leader Append-Only property of
Figure~\ref{fig:basicraft:properties}.
\end{lemma}

\begin{sketch}
As a leader, server $i$ only appends to its log; $i$ won't ever get an
AppendEntries request from some other server for the same term, since
there is at most one leader per term; and $i$ rejects AppendEntries
requests for other terms until increasing its own term.
\end{sketch}

\begin{proof}\
\begin{enumerate}
\item Three variables are involved in the goal: $elections$,
$currentTerm$, and $log$. We consider the transitions that change each
of these variables in turn; otherwise, the invariant trivially holds by the
inductive hypothesis.
\item When a new election is added to $elections$ (a history variable
which maintains information about all successful elections), the $log$
of the leader is not changed in the same step ($log'[e.leader] =
log[e.leader]$), so the invariant is maintained.
\item $currentTerm[e.leader]$ monotonically increases by
Lemma~\ref{appendix:correctness:currenttermmonotonic}, so once $e.leader$ moves to a new
term, it will trivially satisfy the invariant forever after.
\item \emph{log} changes either from client requests or AppendEntries
requests:
\begin{enumerate}
\item Case: client request:
\begin{enumerate}
\item By the specification, the leader only appends an entry to its log,
which maintains the invariant.
\end{enumerate}
\item Case: AppendEntries request:
\begin{enumerate}
\item Only servers with $state[i] = Leader$ can send AppendEntries
requests for their $currentTerm$.
\item By Lemma~\ref{appendix:correctness:olpt}, $e.leader$ is the only
server which can ever be leader for $e.term$.
\item Servers don't send themselves AppendEntries requests (see
specification).
\item $e.leader$ will process no AppendEntries requests while its term
is $e.term$.
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{proof}

\begin{lemma} % <index, term> identifies log prefix
\label{appendix:correctness:itip}
An $\langle index, term \rangle$ pair identifies a log prefix:
\begin{tabbing}
\tab\=\+
$\A l,m \in allLogs : $ \\
\tab\=\+
$\A \langle index, term \rangle \in l :$ \\
\tab\=\+
$\langle index, term \rangle \in m \implies$ \\
\tab\=\+
$\A pindex \in 1..index : $\\
\tab\tab\=\+
$l[pindex] = m[pindex]$
\end{tabbing}
This is the Log Matching property of
Figure~\ref{fig:basicraft:properties}.
\end{lemma}

\begin{sketch}
Only leaders create entries, and they assign the new entries term
numbers that will never be assigned again by other leaders (there's at
most one leader per term).
Moreover, the consistency check in AppendEntries guarantees that when
followers accept new entries, they do so in a way that's consistent with
the leader's log at the time it sent the entries.
\end{sketch}

\begin{assertion}
If $p$ is a prefix of some log $l \in allLogs$, then $allLogs' = allLogs
\cup \{p\}$ maintains the invariant (the statement in the lemma).
\begin{enumerate}
\item This follows immediately from the invariant, since $p$'s entries
match $l$'s entries, and $p$ contributes no additional entries.
\end{enumerate}
\end{assertion}
\vspace{-6ex}

\begin{proof}[Proof by induction on an execution]\
\begin{enumerate}
\item Initial state: all of the servers' logs are empty, so $allLogs =
{\langle \rangle}$, and the invariant trivially holds.
\item Inductive step: logs change in one of the following ways:
\begin{enumerate}
\item Case: a leader adds one entry (client request)
\begin{enumerate}
\item By the inductive hypothesis, $log[leader] \in allLogs$.
\item The $\langle index, term \rangle$ of the new entry cannot exist
in any other entry in any log in $allLogs$,
since there's only one leader per term
(Lemma~\ref{appendix:correctness:olpt}) and leaders
only append to their logs
(Lemma~\ref{appendix:correctness:leaderlogmonotonic}).
\item Then $allLogs' = allLogs \cup \{log[leader] \cat \langle index, term
\rangle\}$ maintains the invariant.
\end{enumerate}

\item Case: a follower removes one entry (AppendEntries request $m$)
\begin{enumerate}
\item The invariant still holds, since $log'[follower]$ is a
prefix of $log[follower]$ (by the Assertion above).
\end{enumerate}

\item Case: a follower adds one entry (AppendEntries request $m$)
\begin{enumerate}
\item $m.mlog$ is a copy of the leader's log at the time the
leader created the AppendEntries request.
\item $m.mlog \in allLogs$ by definition of $allLogs$.
\item In the two cases below, we show that $log'[follower]$ is a prefix
of $m.mlog$.
\item Case: $m.mprevLogIndex = 0$
\begin{enumerate}
\item $m.mentries$ is a prefix of $m.mlog$.
\item $log[follower]$ is empty, as a necessary condition for accepting
the request (the specification separates transitions for removing
a conflicting entry, replying when there is no longer any change to
make, and appending an entry).
\item $log'[follower] = m.mentries$ upon accepting the request,
which is a prefix of $m.mlog$.
\end{enumerate}
\item Case: $m.mprevLogIndex > 0$
\begin{enumerate}
\item
$start \cat \langle m.mprevLogIndex, m.mprevLogTerm \rangle
\cat m.mentries$
is a prefix of $m.mlog$,
where $start$ is some (possibly empty) log prefix.
\item The follower accepts the request by assumption, so its log
contains the entry \\$\langle m.mprevLogIndex, m.mprevLogTerm \rangle$.
\item By the inductive hypothesis, $log[follower]$
contains the prefix \\
$start \cat \langle m.mprevLogIndex, m.mprevLogTerm \rangle$.
\item $log'[follower] = start \cat \langle m.mprevLogIndex,
m.mprevLogTerm \rangle \cat m.mentries$ \\
upon accepting the request, which is a prefix of $m.mlog$.
\end{enumerate}
\item  Because $log'[follower]$ is a prefix of $m.mlog$, the invariant
is maintained (by the Assertion above).
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{proof}

\begin{lemma} % follower appends entry becomes prefix
\label{appendix:correctness:followerprefix}
When a follower appends an entry to its log, its log after
the append is a prefix of the
leader's log at the time the leader sent the AppendEntries request:
\begin{tabbing}
\tab\=\+
$\A i \in Server :$ \\
\tab\tab\=\+
$state[i] \neq Leader \land Len(log'[i]) > Len(log[i]) \implies $ \\
\tab\tab\=\+
$\E m \in \domain messages : $ \\
\tab\tab\=\+
$\sland m.mtype = AppendEntriesRequest $ \\
$\sland \A index \in 1..Len(log'[i]) : $ \\
\tab\tab\=\+
$log'[i][index] = m.mlog[index]$
\end{tabbing}
This restates an argument from the proof of
Lemma~\ref{appendix:correctness:itip} that is useful in the proofs of
other lemmas. (The argument is difficult to make before
Lemma~\ref{appendix:correctness:itip}, since that lemma's inductive
hypothesis is key; however, the proof for this lemma follows easily from
Lemma~\ref{appendix:correctness:itip}.)
\end{lemma}

\begin{sketch}
The new entry that the follower appends to its log was also present in
the leader's log. Thus, by Lemma~\ref{appendix:correctness:itip}, the
follower's new log is a prefix of what was the leader's log.
\end{sketch}

\begin{proof}
Logs change in one of the following ways:
\begin{enumerate}
\item Case: a leader adds one entry (client request). This invariant
only applies to non-leaders.
\item Case: a follower removes one entry (AppendEntries request).
This invariant only affects logs that grow in length.
\item Case: a follower adds one entry (AppendEntries request $m$):
\begin{enumerate}
\item $m.mlog$ is a copy of the leader's log at the time the
leader created the AppendEntries request.
\item Thus, $m.mlog \in allLogs$.
\item $log'[i] \in allLogs$ by definition of $allLogs$.
\item $m.mentries$, the entry being added, is the last entry in
$log'[i]$. (This extends to multiple entries for implementations that
batch entries together.)
\item $m.mentries \in m.mlog$
\item By Lemma~\ref{appendix:correctness:itip},
the index and term of $m.mentries$ uniquely identifies a prefix of
$m.mlog$ equal to $log'[i]$.
\end{enumerate}
\end{enumerate}
\end{proof}

\begin{lemma} % current term >= log terms
\label{appendix:correctness:currenttermmax}
A server's current term is always at least as large as the terms in
its log:
\begin{tabbing}
\tab\=\+
$\A i \in Server :$ \\
\tab\tab\=\+
$\A \langle index, term \rangle \in log[i] : $ \\
\tab\tab\=\+
$term \leq currentTerm[i]$
\end{tabbing}
\end{lemma}

\begin{sketch}
Servers' current terms monotonically increase.
When leaders create new entries, they assign them their current term.
And when followers accept new entries from a leader, their current term
agrees with the
leader's term at the time it sent the entries.
\end{sketch}

\begin{proof}[Proof by induction on an execution]\
\begin{enumerate}
\item Initial state: all logs are empty, so the invariant trivially holds.
\item Inductive step: $currentTerm[i]$ changes:
\begin{enumerate}
\item By Lemma~\ref{appendix:correctness:currenttermmonotonic},
$currentTerm'[i] \geq currentTerm[i]$, so the invariant is maintained.
\end{enumerate}
\item Inductive step: logs change in one of the following ways:
\begin{enumerate}
\item Case: a leader adds one entry (client request):
\begin{enumerate}
\item By the inductive hypothesis, all entries in $log[i]$
have \\ $term \leq currentTerm[i]$.
\item The new entry's term is $currentTerm[i]$.
\item Thus, all entries in $log'[i]$ satisfy the invariant.
\end{enumerate}
\item Case: a follower removes one entry (AppendEntries request)
\begin{enumerate}
\item The invariant still holds, since only the length of the log
decreased.
\end{enumerate}
\item Case: a follower adds one entry (AppendEntries request $m$):
\begin{enumerate}
\item By the inductive hypothesis, when the leader created the request,
its current term was at least as large as the term of every entry in
its log: \\
$\A \langle index, term \rangle \in m.mlog : term \leq m.mterm$
\item $log'[i]$ is a prefix of $m.mlog$ by
Lemma~\ref{appendix:correctness:followerprefix}.
\item As a necessary condition for accepting the request,
$currentTerm[i] = m.mterm$.
\item Then $currentTerm[i]$ is at least as large as the term in
every entry in $log'[i]$, and the invariant is maintained.
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{proof}

\begin{lemma} % Log terms are monotonic
\label{appendix:correctness:monotoniclogterms}
The terms of entries grow monotonically in each log:
\begin{tabbing}
\tab\=\+
$\A l \in allLogs :$ \\
\tab\tab\=\+
$\A index \in 1..(Len(l) - 1) : $ \\
\tab\tab\=\+
$l[index].term \leq l[index + 1].term$
\end{tabbing}
\end{lemma}

\begin{sketch}
A leader maintains this by assigning new entries its current term, which
is always at least as large as the terms in its log.
When followers accept new entries, they are consistent with the leader's
log at the time it sent the entries.
\end{sketch}

\begin{proof}[Proof by induction on an execution]\
\begin{enumerate}
\item Initial state: all logs are empty, so the invariant holds.
\item Inductive step: logs change in one of the following ways:
\begin{enumerate}
\item Case: a leader adds one entry (client request)
\begin{enumerate}
\item The new entry's term is $currentTerm[leader]$
\item $currentTerm[leader]$ is at least as large as the term of any
entry in $log[leader]$, by Lemma~\ref{appendix:correctness:currenttermmax}.
\end{enumerate}
\item Case: a follower removes one entry (AppendEntries request)
\begin{enumerate}
\item The invariant still holds, since only the length of the log
decreased.
\end{enumerate}
\item Case: a follower adds one entry (AppendEntries request $m$)
\begin{enumerate}
\item $log'[follower]$ is a prefix of $m.mlog$
(by Lemma~\ref{appendix:correctness:followerprefix}).
\item $m.mlog \in allLogs$
\item By the inductive hypothesis, the terms in $m.mlog$ monotonically
grow, so the terms in $log'[follower]$ monotonically grow.
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{proof}

\begin{definition} % committed at term t
An entry $\langle index, term \rangle$ is \textbf{committed at term $t$} if
it is present in every leader's log following $t$:
\begin{tabbing}
\tab\=\+
$committed(t) \is \{$\=\+$\langle index, term \rangle : $ \\
\tab\=\+
        $\A election \in elections :$\\
\tab\=\+
            $election.eterm > t \implies$ \\
\tab\=\+
                $\langle index, term \rangle \in election.elog \}$
\end{tabbing}
\end{definition}

\begin{definition} % immediately committed
An entry $\langle index, term \rangle$ is \textbf{immediately committed}
if it is acknowledged by a quorum (including the leader) during $term$.
Lemma~\ref{appendix:correctness:immcommittedlemma} shows that these
entries are committed at $term$.
\begin{tabbing}
\tab\=\+
$immediatelyCommitted \is \{$\=\+$\langle index, term \rangle \in anyLog : $ \\
$\sland anyLog \in allLogs $ \\
$\sland \E leader \in Server,\ subquorum \in \SUBSET Server: $ \\
\tab\tab\=\+
    $\sland subquorum \cup \{leader\} \in Quorum$ \\
    $\sland \A i \in subquorum :$ \\
\tab\tab\=\+
        $\E m \in messages :$ \\
\tab\=\+
             $\sland m.mtype = AppendEntriesResponse$ \\
             $\sland m.msource = i$ \\
             $\sland m.mdest = leader$ \\
             $\sland m.mterm = term$ \\
             $\sland m.mmatchIndex \geq index\}$ \\
\end{tabbing}
\end{definition}

\begin{lemma} % Immediately committed entries are committed
\label{appendix:correctness:immcommittedlemma}
{\em Immediately committed} entries are $committed$:
\begin{tabbing}
\tab\=\+
$\A \langle index, term \rangle \in immediatelyCommitted : $ \\
\tab\tab $\langle index, term \rangle \in committed(term)$
\end{tabbing}
Along with Lemma~\ref{appendix:correctness:prefixcommittedlemma},
this is the Leader Completeness property of
Figure~\ref{fig:basicraft:properties}.

\end{lemma}

\begin{sketch}
See Section~\ref{basicraft:safety:argument}.
\end{sketch}

\begin{proof} \

\begin{enumerate}
\item Consider an entry $\langle index, term \rangle$ that is {\em
immediately committed}.

\item Define
\begin{tabbing}
\tab\=\+
$Contradicting \is \{$\=\+$election \in elections : $\\
\tab\=\+
$\sland election.eterm > term $ \\
$\sland \langle index, term \rangle \notin election.elog\}$
\end{tabbing}

\item Let $election$ be an element in $Contradicting$ with a minimal $term$
field. That is, \\ $\A e \in Contradicting : election.eterm \leq e.eterm$.
\\
If more than one election has the same term, choose the earliest one.
(The specification does not allow this to happen, but it is safe for a
leader to step down and become leader again in the same term.)

\item It suffices to show a contradiction,
which implies $Contradicting = \phi$.

\item Let $voter$ be any server that both votes in $election$ and
contains $\langle index, term \rangle$ in its log during $term$ (either it
acknowledges the entry as a follower or it was leader).
Such a server must exist since:
\begin{enumerate}
\item A quorum of servers voted in $election$ for it to succeed.
\item A quorum contains $\langle index, term \rangle$ in its log during
$term$, since $\langle index, term \rangle$ is immediately committed.
\item Any two quorums overlap.
\end{enumerate}

\item Let $voterLog \be election.evoterLog[voter]$, the voter's log at
the time it cast its vote.

\item The voter contains the entry when it cast its vote during
$election.eterm$. That is, \\ $\langle index, term \rangle \in voterLog$:

\begin{enumerate}
\item $\langle index, term \rangle$ was in the voter's log during
$term$.
\item The voter must have stored the entry in $term$ before voting in
$election.eterm$, since:
\begin{enumerate}
\item $election.eterm > term$.
\item The voter rejects requests with terms smaller than its current
term, and its current term monotonically increases
(Lemma~\ref{appendix:correctness:currenttermmonotonic}).
\end{enumerate}
\item The voter couldn't have removed the entry before casting its
vote:
\begin{enumerate}
\item Case: No $AppendEntriesRequest$ with $mterm < term$ removes the entry from the
voter's log, since $currentTerm[voter] \geq term$ upon storing the
entry (by Lemma~\ref{appendix:correctness:currenttermmax}),
and the voter rejects requests with terms smaller than
\\
$currentTerm[voter]$.
\item Case: No $AppendEntriesRequest$ with $mterm = term$ removes the entry from the
voter's log, since:
\begin{enumerate}
\item There is only one leader of $term$.
\item The leader of $term$ created and therefore
contains the entry (Lemma~\ref{appendix:correctness:leaderlogmonotonic}).
\item The leader would not send any conflicting
requests to $voter$ during $term$.
\end{enumerate}
\item Case: No $AppendEntriesRequest$ with $mterm > term$ removes the entry from the
voter's log, since:
\begin{enumerate}
\item Case: $mterm > election.eterm$:\\
This can't happen, since
$currentTerm[voter] > election.eterm$ would have prevented the voter from
voting in $term$.
\item Case: $mterm = election.eterm$:\\
Since there is at most one leader per term
(Lemma~\ref{appendix:correctness:olpt}), this request would have to come
from $election.eleader$ as a result of an earlier election in the same
term ($election.eterm$).
\\
Because a leader's log grows monotonically during its term (by
Lemma~\ref{appendix:correctness:leaderlogmonotonic}),
the leader could not have had $\langle index, term \rangle$ in
its log at the start of its term.
\\
Then there exists an earlier election with the same term in $Contradicting$;
this is a contradiction.
\item Case $mterm < election.eterm$:\\
The leader of $mterm$ must have contained the entry (otherwise its
election would also be $Contradicting$ but have a smaller term than
$election$, which is a contradiction).
Thus, the leader of $mterm$ could not send any conflicting entries to
the voter for this index,
nor could it send
any conflicting entries for prior indexes: that it has this entry
implies that it has the entire prefix before it
(Lemma~\ref{appendix:correctness:itip}).
\end{enumerate}
\end{enumerate}
\end{enumerate}

\item The log comparison during elections states the following,
since $voter$ granted its vote during $election$:
\begin{tabbing}
\tab\=\+
$\slor LastTerm(election.elog) > LastTerm(voterLog)$ \\
$\slor$\=\+$\sland LastTerm(election.elog) = LastTerm(voterLog)$ \\
            $\sland Len(election.elog) \geq Len(voterLog)$
\end{tabbing}

In the following two steps, we take each of these cases in turn and show a
contradiction.

\item Case: $LastTerm(election.elog) = LastTerm(voterLog)$ and \\
            $Len(election.elog) \geq Len(voterLog)$
\begin{enumerate}
\item The leader of $LastTerm(voterLog)$ monotonically grew its log
during its term (by
Lemma~\ref{appendix:correctness:leaderlogmonotonic}).
\item The same leader must have had $election.elog$ as its log at some
point, since it created the last entry.
\item Thus, $voterLog$ is a prefix of $election.elog$.
\item Then $\langle index, term \rangle \in election.elog$,
since $\langle index, term \rangle \in voterLog$.
\item But $election \in Contradicting$ implies that
$\langle index, term \rangle \notin election.elog$.
\end{enumerate}

\item Case: $LastTerm(election.elog) > LastTerm(voterLog)$
\begin{enumerate}
\item $LastTerm(voterLog) \geq term$,
since $\langle index, term \rangle \in voterLog$
and terms in logs grow monotonically (Lemma~\ref{appendix:correctness:monotoniclogterms}).

\item $election.eterm > LastTerm(election.elog)$
since servers increment their $currentTerm$ when starting an election,
and Lemma~\ref{appendix:correctness:currenttermmax} states that a server's $currentTerm$ is
at least as large as the terms in its log.

\item Let $prior$ be the election in $elections$ with $prior.eterm =
LastTerm(election.elog)$.
Such an election must exist since $LastTerm(election.elog) > 0$
and a server must win an election before creating an entry.

\item By transitivity, we now have the following inequalities:
\begin{tabbing}
\tab\=\+
$term \leq$ \\
\tab\=\+
$LastTerm(voterLog) <$ \\
\tab\=\+
$LastTerm(election.elog) = prior.eterm <$ \\
\tab\=\+
$election.eterm$
\end{tabbing}

\item $\langle index, term \rangle \in prior.elog$, since $prior \notin
Contradicting$ ($election$ was assumed to have the lowest term of any
election in $Contradicting$, and $prior.eterm < election.eterm$).
\item $prior.elog$ is a prefix of $election.elog$ since:
\begin{enumerate}
\item $prior.eleader$ creates entries with $prior.eterm$ by appending them to
its log, which monotonically grows during $prior.eterm$ from $prior.elog$.
\item Thus, any entry with term $prior.eterm$ must follow $prior.elog$
in all logs (by Lemma~\ref{appendix:correctness:itip}).
\item $LastTerm(election.elog) = prior.eterm$
\end{enumerate}
\item $\langle index, term \rangle \in election.elog$
\item This is a contradiction, since $election.elog$ was assumed to not
contain the committed entry ($election \in Contradicting$).
\end{enumerate}
\end{enumerate}
\end{proof}

\begin{definition} % prefix committed at term t
An entry $\langle index, term \rangle$ is \textbf{prefix committed at term $t$}
if there is another entry that is {\em committed at term $t$} following it in some log.
Lemma~\ref{appendix:correctness:prefixcommittedlemma} shows that these entries are {\em
committed at term $t$}.
\begin{tabbing}
\tab\=\+
$prefixCommitted(t) \is \{$\=\+$\langle index, term \rangle \in anyLog : $ \\
$\sland anyLog \in allLogs$ \\
$\sland \E \langle rindex, rterm \rangle \in anyLog : $ \\
\tab\tab\=\+
        $\sland index < rindex$ \\
        $\sland \langle rindex, rterm \rangle \in committed(t)\}$ \\
\end{tabbing}
\end{definition}

\begin{lemma}
\label{appendix:correctness:prefixcommittedlemma}
{\em Prefix committed} entries are $committed$ in the same term:
\begin{tabbing}
\tab $\A t : prefixCommitted(t) \subseteq committed(t)$
\end{tabbing}
Along with Lemma~\ref{appendix:correctness:immcommittedlemma},
this is the Leader Completeness property of
Figure~\ref{fig:basicraft:properties}.
\end{lemma}

\begin{sketch}
If an entry is committed, it identifies a prefix of a log in which every
entry is committed, since those entries will also be present in every
future leader's log.
\end{sketch}

\begin{proof} \

\begin{enumerate}
\item Consider an arbitrary entry
$\langle index, term \rangle \in prefixCommitted(t)$.
\item There exists an entry $\langle rindex, rterm \rangle \in
committed(t)$ following $\langle index, term \rangle$ in some log,
by definition of $prefixCommitted(t)$.
\item $\langle rindex, rterm \rangle$ uniquely identifies the log prefix
containing $\langle index, term \rangle$
(Lemma~\ref{appendix:correctness:itip}).
\item Every leader following $t$ contains $\langle index, term \rangle$,
since every leader following $t$ contains $\langle rindex, rterm \rangle$.
\item $\langle index, term \rangle \in committed(t)$
by definition of $committed(t)$.

\end{enumerate}
\end{proof}

\begin{theorem}
\label{appendix:correctness:onlycommittedapplied}
Servers only apply entries that are $committed$ in their current term:
\begin{tabbing}
\tab\=\+
$\A i \in Server : $ \\
\tab\=\+
$\sland commitIndex[i] \leq Len(log[i])$ \\
$\sland \A \langle index, term \rangle \in log[i] : $ \\
\tab\tab\tab\=\+
$index \leq commitIndex[i] \implies $ \\
$\tab \langle index, term \rangle \in committed(currentTerm[i])$
\end{tabbing}
This is equivalent to the State Machine Safety property of
Figure~\ref{fig:basicraft:properties}. (The bound on the commit index is
needed to strengthen the inductive hypothesis.)
\end{theorem}

\begin{sketch}
A leader only advances its $commitIndex$ to cover entries that are
immediately committed or prefix committed. Followers update their
$commitIndex$ from the leader's only when they have a prefix of the
leader's log.
\end{sketch}

\begin{proof}[Proof by induction on an execution]\
\begin{enumerate}

\item Initial state: trivially holds for empty logs (and
$commitIndex[i]$ is initialized to 0).

\item Inductive step: the set of entries committed at $currentTerm[i]$
changes:
\begin{enumerate}
\item Once an entry is committed at $currentTerm[i]$, all leaders
of subsequent terms will have the entry (by the definition of $committed$).
\item Thus, the set of committed entries at $currentTerm[i]$
monotonically grows.
\end{enumerate}

\item Inductive step: $commitIndex[i]$ changes:
\begin{enumerate}
\item When $commitIndex[i]$ decreases (if implementations allow this to
happen), the inductive hypothesis suffices
to show the invariant holds.
\item When $commitIndex[i]$ increases, it covers entries present in
$i$'s log that are committed:
\begin{enumerate}
\item Case: follower completes accepting AppendEntries request $m$:
\begin{enumerate}
\item Upon processing the request, the follower's log is a prefix of a
prior version of the leader's log, $m.mlog$ (by
Lemma~\ref{appendix:correctness:followerprefix}).
\item Every entry up through $commitIndex'[i]$ in $m.mlog$ is committed
by the inductive hypothesis (they were marked committed in the leader's
log when it sent the request).
\end{enumerate}
\item Case: leader $i$ processes AppendEntries response:
\begin{enumerate}
\item If the leader sets a new $commitIndex$, the conditions in the
specification
ensure that $commitIndex'[i] \in immediatelyCommitted$.
\item Every entry in the leader's log with index up to $commitIndex'[i]$
is prefix committed at $currentTerm[i]$.
\end{enumerate}
\end{enumerate}
\end{enumerate}

\item Inductive step: $currentTerm[i]$ changes:
\begin{enumerate}
\item By Lemma~\ref{appendix:correctness:currenttermmonotonic},
$currentTerm'[i] > currentTerm[i]$.
\item $committed(currentTerm[i]) \subseteq
committed(currentTerm'[i])$ by the definition of \\ $committed$.
\item Thus, the inductive hypothesis suffices to show the invariant
holds.
\end{enumerate}

\item Inductive step: logs change in one of the following ways:
\begin{enumerate}
\item Case: a leader adds one entry (client request):
\begin{enumerate}
\item Newly created entries are not marked committed, so the invariant
holds.
\end{enumerate}
\item Case: a follower removes one entry (AppendEntries request $m$):
\begin{enumerate}
\item Case: the removed entry was not marked committed on the follower:
\\ The inductive hypothesis suffices to show the invariant holds.
\item Case: the removed entry was marked committed on the follower:
\begin{enumerate}
\item $m.mterm = currentTerm[i]$, since the follower accepted the
request.
\item The removed entry is not in $m.mlog$, since it conflicts with the
request.
\item The removed entry is not present in $m.msource$'s log at the start
of its term (by Lemma~\ref{appendix:correctness:leaderlogmonotonic}).
\item The election for $m.mterm$ did not contain the removed entry.
\item The removed entry is not committed at $currentTerm[i]$.
\item This contradicts the inductive hypothesis; this case cannot occur.
\end{enumerate}
\end{enumerate}
\item Case: a follower adds one entry (AppendEntries request $m$):
\begin{enumerate}
\item Case: the new entry is not marked committed on the follower:\\
The inductive hypothesis suffices to show the invariant holds.
\item Case: the new entry is marked committed on the follower:\\
$commitIndex[i]$ must increase (which was already handled above).
\end{enumerate}
\end{enumerate}
\end{enumerate}
\end{proof}


\chapter{Approach to Exploration}\label{methods}

In this chapter, we discuss the approach taken to reproducing results from previous work and exploring how using alternative flow operators changes these results.

\section{Objectives}

\subsection{Verify Many-Body Force Induction}

The first major goal of the project was to use the new, more flexible framework provided by the \texttt{srg1d} library to reproduce 2-body and 3-body results published in Ref.~\cite{Jurgenson:2008jp}. While the 2-body results do not give any insight into many-body force induction, they offer an intermediate point for us to look at and be certain of the correctness of our work so far. The 3-body results allow us to look at many-body force induction and reproducing the Jurgenson 3-body results gives us a good point to compare to when testing other flow operators.

\subsection{Test Alternative Flow Operators}

The second major goal after reproducing previous results was to use alternative flow operators and observe how the results of the SRG evolution change. With the framework of the \texttt{srg1d} library, changing the flow operator for existing an SRG calculation is as simple as changing two lines of code in most cases. With the ability to easily switch flow operators, we are able to easily take calculations reproducing previous results and use them with new flow operators to directly see the change caused by changing the flow operator.

\section{2-Particle Systems}
\begin{figure}[t]
\begin{center}
 \includegraphics*[height=1.4in]{V_srg_lam_40}
\includegraphics*[height=1.4in]{V_srg_lam_5}
 \includegraphics*[height=1.4in]{V_srg_lam_3}
 \includegraphics*[height=1.4in]{V_srg_lam_2}
\end{center}
\caption{Evolution from $\lambda=\infty$ to $\lambda=2$ of the even part of the $\hat{V}_\alpha$ potential in 2-body momentum space from Ref.~\cite{Jurgenson:2008jp}. Figure reproduced with permission of the author.}
\label{fig:jurg_2body_ev}
\end{figure}

We use the Negele 2-body potential adopted from Ref.~\cite{Alexandrou:1988jg}, which was also used in Ref.~\cite{Jurgenson:2008jp}:
\begin{equation}\label{eq:negele}
\hat{V}(p, p') = \frac{V_1}{2\pi\sqrt2}e^{-(p-p')^2\sigma_1^2/8} + \frac{V_2}{2\pi\sqrt2}e^{-(p-p')^2\sigma_2^2/8}.
\end{equation}
We use the same sets of parameters as used previously, detailed in Table \ref{table:negele_params}. The $\hat{V}_\alpha$ potential features a mid-range attraction and a strong short-range repulsion, similar in nature to real nucleon-nucleon potentials. The $\hat{V}_\beta$ potential is a purely attractive potential.

\begin{table}[t]
\begin{center}
\begin{tabularx}{\textwidth}{ X X X X X X X }
 \hline
 Name & $V_1$ & $\sigma_1$ & $V_2$ & $\sigma_2$ & $E_2$ & $E_3$ \\
 \hline
 $\hat{V}_\alpha$ & 12.0 & 0.2 & -12.0 & 0.8 & −0.920 & -2.567\\
 $\hat{V}_\beta$ & 0.0 & 0.0 & -2.0 & 0.8 & -0.474 & -1.708 \\
 \hline
\end{tabularx}
\end{center}
\caption{Parameters for two variants of the 2-body Negele potential from Eq. \ref{eq:negele} and their corresponding 2-body and 3-body ground state energies, denoted by $E_2$ and $E_3$ respectively.}
\label{table:negele_params}
\end{table}

We compute the 2-body Hamiltonian with this potential in momentum space and verify that the ground state energy eigenvalues match. We then run the SRG method on the 2-body momentum-space Hamiltonian and verify that it is truly unitary and behaves in the same way as in Fig.~\ref{fig:jurg_2body_ev}. We then perform the transformation to a symmetrized 2-body harmonic oscillator basis, checking that the ground state energy is unchanged by the unitary transformation. We perform an additional check on the correctness of the transformation by ensuring that the transformed kinetic energy operator is equal to the 2-body kinetic energy as calculated directly from the harmonic oscillator basis.

We then use the 2-body Hamiltonian to experiment with different flow operators. While the 2-body system does not give any insight into the many-body forces induced by SRG when using these flow operators, it does give an excellent way to visualize how the action of the SRG transformation on the operator changes because of the alternative flow operators.

\section{3-Particle Systems}

\begin{figure}[t]
\begin{center}
\subfloat[$\hat{V}_\alpha$\label{fig:jurg_va}]{\centering\includegraphics*[height=2.5in]{Ebind_3N_Va}}
\hfill
\subfloat[$\hat{V}_\beta$\label{fig:jurg_vb}]{\centering\includegraphics*[height=2.5in]{Ebind_3N_Vf}}
\end{center}
\caption{Demonstration of an induced 3-body force in (a) the 3-body $\hat{V}_\alpha$ ground state energy and (b) the 3-body $\hat{V}_\beta$ ground state energy from Ref.~\cite{Jurgenson:2008jp}. Figure reproduced with permission of the author.}
\label{fig:jurg_vfull}
\end{figure}

Moving to a 3-body system allows us to get our first results for 3-body force induction for Hamiltonians evolved in a 2-body system. To observe this, we first generate the 3-body symmetrized harmonic oscillator basis by generating all possible product states, computing and diagonalizing the symmetrizer, and keeping states with eigenvalue 1. With the symmetric 3-body basis, we are able to compute the 3-body kinetic energy and embed the 2-body potential from the 2-body basis in the 3-body basis. With these 3-body operators, we are able to compute the 3-body ground state energy and compare it to the previously published value for it given in Table \ref{table:negele_params}.

After properly embedding the 2-body potential in the 3-body basis, we are able to see how the 2-body SRG evolution with the standard kinetic energy flow operator induces a 3-body force in the 3-body ground state energy. We verify that this behavior matches that shown in Fig.~\ref{fig:jurg_vfull}. We then use the same approach to see the strength of 3-body forces induced by 2-body SRG evolution with alternative flow operators.