\documentclass[class=report, float=false, crop=false]{standalone}
\usepackage[subpreambles=true]{standalone}

\input{preamble}

\graphicspath{{figures/images/}}

% \begin{cbunit}

\begin{document}

\chapter{Renormalisation group theory}
\label{appendix:rg}

The renormalisation group (RG) theory, attributed to Kenneth G. Wilson \cite{wilson1971renormalization,wilson1974renormalization,wilson1975renormalization}, relies on coarse-graining arguments near critical points and gives a genuine way of thinking about critical phenomena and provides a theoretical motivation for scaling assumptions. Moreover, this theory allows one to calculate critical exponent although being particularly technical.\\

In this appendix, we mean to present the renormalisation group theory and how it leads to the scaling hypothesis we made, focusing on its implications on numerical simulations scaling. All demonstrations and discussions are based on \cite{goldenfeld1992lectures} and unpublished documents by Peter Olsson.

\section{Coarse-graining argument}

\subsection{Block spins}
\label{block_spins}

We can easily illustrate the RG theory with the Ising model for spins with nearest neighbours interactions. In this model, a system of spins displays a ferromagnetic transition at the temperature $T=T_C$, where the correlation length diverges.\\

Consider a system $\Omega$ of spins on a $d$-dimensional hypercubic lattice, with spacing $a$. We have that the spins are correlated on lengths scales of order $\xi$, the basic idea is thus to consider that spins on a length scale $la$, with $l$ satisfying
\begin{align*}
a \ll la \ll \xi
\end{align*}
act as a single spin, which we will call a \textit{block spin}.\\

We can then make the assumptions that block spins interact with their nearest block spin neighbours, as do the single spins, with coupling constants -- between spins, and between spins and external field -- somewhat different. Our block spin system is then described by the same Hamiltonian than the single spin spin. However, the spacing between block spins is $l$ times larger than the spacing between single spins, leading to the correlation length
\begin{align*}
\xi_l = \frac{\xi}{l}
\end{align*}
smaller than the correlation length of the original system. This tells us that the latter system is further from criticality than the former, leading to a reduced temperature
\begin{align*}
t_l \equiv 1 - \frac{T}{T_{C,l}} = s(l) \underbrace{\left(1 - \frac{T}{T_C}\right)}_{t} < t
\end{align*}
with $s$ a function to determine.\\

Since two consecutive scale changes with the factors $l_1$ and $l_2$ are equivalent to a single scale change of factor $l_1l_2$, we have that
\begin{align*}
s(l_1l_2) = s(l_1)s(l_2)
\end{align*}
which is satisfied by
\begin{align*}
s(l) = l^y
\end{align*}
for any $y$, hence the scaling assumptions.\\

Furthermore, we realise that the critical temperature, characterising a state where the correlation length is infinite, is a fixed point of the scaling transformation.

\subsection{Renormalisation group transformations}

We need to formalise the scaling transformation we have introduced.\\

Consider a system $\Omega$ described by the general Hamiltonian
\begin{equation}
\mathcal{H} \equiv -\beta H_{\Omega} = \sum_n K_n \Theta_n\{S\}
\end{equation}
where $\beta = 1/kT$ with $k$ the Boltzmann constant and $T$ the temperature, $K_n$ are the coupling constants, and $\Theta\{S\}$ the local operators on the degrees of freedom $\{S\}$.\\

We introduce $\forall l>1$ the \textit{renormalisation group transformation} $R_l$ which acts on the coupling constants $[K] \equiv (K_n)_n$
\begin{equation}
R_l[K] \equiv [K']
\end{equation}
and which is most often complicated and non-linear. These transformations verify
\begin{equation}
\forall l_1, l_2 > 1,~ R_{l_1l_2}[K]=R_{l_2}\cdot R_{l_1}[K]
\label{semi_group}
\end{equation}
and do not admit inverses since $l$ has to be greater or equal to $1$, therefore RG transformations form a semi-group.\\

RG transformations are coarse-graining transformations which reduce the number $N$ of degrees of freedom by a factor $l^{-d}$ to $N'=Nl^{-d}$, where $d$ is the dimension of the system. Therefore, the degrees of freedom $\{S_i\}_{1\ldots N}$ and the Hamiltonian $\mathcal{H}$ are replaced by \textit{block variables} $\{S'_I\}_{1\ldots N'}$ and an effective Hamiltonian $\mathcal{H'}$ for these new degrees of freedom respectively.\\

We introduce a \textit{projection operator} $P(S_i,S'_I)$ which satisfies
\begin{equation}
e^{\mathcal{H}'\{[K'],S'_I\}} = \text{Tr}_{\{S_i\}}P(S_i,S'_I)e^{\mathcal{H}\{[K],S_i\}}
\end{equation}
where $\text{Tr}_{\{S_i\}}$ denotes the sum over the degrees of freedom $\{S\}$, and must fulfil the following requirements
\begin{itemize}
\item[(i)] $P(S_i,S'_I) \ge 0$,
\item[(ii)] $P(S_i,S'_I)$ reflects the symmetries of the system,
\item[(iii)] $\sum_{\{S'_I\}} P(S_i,S'_I) = 1$.
\end{itemize}
In the context of part \ref{block_spins}, the projection operator $P$ is the function that associates an up or down spin to a block of spins.\\

% We can notice that RG transformations then leave the partition function, and therefore the free energy, of the system unchanged
% \begin{align*}
% Z[K'] &\equiv \text{Tr}_{\{S'_I\}}e^{\mathcal{H}'\{[K'],S'_I\}}\\
% &= \text{Tr}_{\{S'_I\}}\text{Tr}_{\{S_I\}}P(S_i,S'_I)e^{\mathcal{H}\{[K],S_i\}}\\
% &= \text{Tr}_{\{S_i\}}e^{\mathcal{H}\{[K],S_i\}}\cdot1\\
% &= Z[K]
% \end{align*}

% We define the free energy $Z$
% \begin{equation}
% Z[K]=\text{Tr}_{\{S\}}e^{\mathcal{H}\{[K],S_i\}}
% \end{equation}
% and the function $g$
% \begin{equation}
% g[K] \equiv \frac{1}{N}\ln Z[K]
% \end{equation}
% which is related to the free energy per degree of freedom.\\

% Condition (iii) ensures that the partition function, and thus the free energy, remains unchanged
% \begin{align*}
% Z[K'] &\equiv \text{Tr}_{\{S'_I\}}e^{\mathcal{H}'\{[K'],S'_I\}}\\
% &= \text{Tr}_{\{S'_I\}}\text{Tr}_{\{S_I\}}P(S_i,S'_I)e^{\mathcal{H}\{[K],S_i\}}\\
% &= \text{Tr}_{\{S_i\}}e^{\mathcal{H}\{[K],S_i\}}\cdot1\\
% &= Z[K]
% \end{align*}
% while the function $g$ is rescaled
% \begin{align*}
% \frac{1}{N}\ln Z[K] &= \frac{l^d}{l^dN}\ln Z[K']\\
% &= l^{-d} \frac{1}{N'} \ln Z[K']
% \end{align*}
% \textit{i.e.},
% \begin{equation}
% g[K] = l^{-d}g[K']
% \end{equation}

We define the free energy $Z$
\begin{equation}
Z[K]=\text{Tr}_{\{S\}}e^{\mathcal{H}\{[K],S_i\}}
\end{equation}
and the free energy density $f$
\begin{equation}
f[K] = \frac{1}{L^d} Z[K]
\end{equation}
where $L$ is the characteristic dimension of the system, which is the quotient of the free energy by the volume of the system.\\

Condition (iii) ensures that the partition function, and thus the free energy, remains unchanged
\begin{align*}
Z[K'] &\equiv \text{Tr}_{\{S'_I\}}e^{\mathcal{H}'\{[K'],S'_I\}}\\
&= \text{Tr}_{\{S'_I\}}\text{Tr}_{\{S_I\}}P(S_i,S'_I)e^{\mathcal{H}\{[K],S_i\}}\\
&= \text{Tr}_{\{S_i\}}e^{\mathcal{H}\{[K],S_i\}}\cdot1\\
&= Z[K]
\end{align*}
while the free energy density $f$ is rescaled
\begin{align*}
\frac{1}{L^d}\ln Z[K] &= \frac{l^{-d}}{(L/l)^d}\ln Z[K']\\
&= l^{-d} \frac{1}{L'} \ln Z[K']
\end{align*}
\textit{i.e.},
\begin{equation}
f[K] = l^{-d}f[K']
\label{free_energy_scaling}
\end{equation}

\section{Renormalisation group flows}

\subsection{Fixed points of the coupling constants space}

An infinite number of iterations of the RG transformations is required in order to eliminate all degrees of freedom of a thermodynamic system in the thermodynamic limit $N\rightarrow+\infty$. By doing so, singular behaviour may occur.\\

For any $l>1$, $R_l$ is a function from the coupling constants $[K]$ space to this same space, which we will denote $\mathcal{K}$. We will call \textit{renormalisation group flows} the trajectories in the coupling constants space which are obtained by iterating RG transformations. It is likely to find fixed points of the RG transformations in $\mathcal{K}$, we will then call the \textit{basin of attraction} of such a fixed point the set of points of $\mathcal{K}$ from which an infinite number of iterations of RG transformations inevitably lead.\\

We have $\forall l>1$ that the correlation length $\xi$ transforms under the RG transformation $R_l$ as
\begin{equation}
\xi[K'] = \xi[K]/l
\end{equation}
therefore, for a fixed point $[K^*]$
\begin{align*}
\xi[K*] = \xi[K*]/l
\end{align*}
which allows us to distinguishes two cases
\begin{itemize}
\item[(i)] $\xi[K^*] = 0$, for which we will call $[K^*]$ a \textit{"trivial" fixed point}, and
\item[(ii)] $\xi[K^*] = +\infty$, for which we will call $[K^*]$ a \textit{critical fixed point}.
\end{itemize}
We can then notice that since $n$ iterations of $R_l$ transform the correlation length as
\begin{align*}
\xi[K] = l^n \xi[K^{(n)}]
\end{align*}
we have that all points in the basin attraction of a critical fixed point $[K^*]$, which satisfy $\xi[K^{(n)}] \xrightarrow[n\rightarrow+\infty]{} \xi[K^*] = +\infty$, have infinite correlation length. This basin of attraction is called the \textit{critical manifold}.\\

We have implicitly that the critical points were isolated, however this is not necessarily the case. In fact, fixed points are classified according to their codimension, but this does not affect the validity of our demonstration.\\

We note that it is also possible for RG flows to describe limit cycles or strange attractors, but in practice it is almost never the case. We will then neglect these possibilities from now on.

\subsection{Relevance of variables}

We are interested in the behaviour of RG flows in the vicinity of a critical fixed point $[K^*]$.\\

Consider $[K]$ a point of $\mathcal{K}$ close to $[K^*]$
\begin{align*}
[K] = [K^*] + [\delta K]
\end{align*}
then $\forall l>1$, $[K]$ transforms under $R_l$ as $R_l[K]=[K']$ with
\begin{align*}
[K']\{[K^*]+[\delta K]\} &= \underbrace{[K']\{[K^*]\}}_{[K^*]} + [\delta K']\\
\text{\textit{i.e.}, } [K']\{[K^*]+[\delta K]\} &= [K^*] + \underbrace{\left(\left.\frac{\partial K'_n}{\partial K_m}\right|_{K_m = K^*_m} \right)_{n,m}}_{\textstyle M^{(l)}} [\delta K] + \mathcal{O}\left([\delta K]^2\right)
\end{align*}
according to Taylor's theorem, where $M^{(l)}$ is the linearised RG transformation in the vicinity of $[K^*]$ and is a real matrix.\\

In practice, $M^{(l)}$ is most often diagonalisable with real eigenvalues. For present purposes, we will assume for the rest of our presentation that it is symmetric without further notice. We advise the interested reader to read part 9.4.4 of \cite{goldenfeld1992lectures} for corrections to be brought to our theory in the case of a non-symmetric linearised RG transformation.\\

We will denote the eigenvalues and eigenvectors of $M^{(l)}$ by $\Lambda^{(\sigma)}_l$ and $\vec{e}^{\hspace{1pt}(\sigma)}$ respectively, where $(\vec{e}^{\hspace{1pt}(\sigma)})_{\sigma}$ is an orthonormal base of $\mathcal{K}$ according to the spectral theorem. We can then infer from the semi-group property of equation \ref{semi_group} that
\begin{align*}
\forall l,l' >1,~ M^{(l)}M^{(l')} &= M^{(ll')}\\
\Rightarrow \forall \sigma,~ \Lambda^{(\sigma)}_l\Lambda^{(\sigma)}_{l'} &= \Lambda^{(\sigma)}_{ll'}
\end{align*}
which we can differentiate with respect to $l'$
\begin{align*}
\frac{d}{dl'}\left(\Lambda^{(\sigma)}_l\Lambda^{(\sigma)}_{l'}\right) &= \frac{d}{dl'}\Lambda^{(\sigma)}_{ll'}\\
\Leftrightarrow \cancelto{0}{\frac{d\Lambda^{(\sigma)}_l}{dl'}}\Lambda^{(\sigma)}_{l'} + \Lambda^{(\sigma)}_l\frac{d\Lambda^{(\sigma)}_{l'}}{dl'} &= \frac{d}{dl'} \Lambda^{(\sigma)}_{ll'}\\
\Rightarrow \Lambda^{(\sigma)}_l\left.\frac{d\Lambda^{(\sigma)}_{l'}}{dl'}\right|_{l'=1} &= \frac{d\Lambda^{(\sigma)}_l}{dl}
\end{align*}
% i really have doubts concerning the resolution of this equation... that's how the book did though
and therefore write
\begin{equation}
\Lambda^{(\sigma)}_l = l^{y_{\sigma}}
\label{eigenvalues_scaling}
\end{equation}
where $y_{\sigma}$ is independent of l.\\

Finally, we have that
\begin{equation}
\begin{aligned}
[\delta K'] &= M^{(l)} [\delta K]\\
&= \sum_{\sigma} \Lambda^{(\sigma)}_l \underbrace{\left(\vec{e}^{\hspace{1pt}(\sigma)}\cdot[\delta K]\right)}_{a^{(\sigma)}} \vec{e}^{\hspace{1pt}(\sigma)}\\
&= \sum_{\sigma} \underbrace{l^{y_{\sigma}}a^{(\sigma)}}_{\textstyle a^{(\sigma)}\prime} \vec{e}^{\hspace{1pt}(\sigma)}
\end{aligned}
\end{equation}
for which we will distinguish 3 cases:
\begin{itemize}
\item[(i)] $y_{\sigma} > 0$, which implies that $a^{(\sigma)}\prime$ grows as $l$ increases, and for which we will describe the corresponding eigenvalue/direction/eigenvector as \textit{relevant},
\item[(ii)] $y_{\sigma} < 0$, which implies that $a^{(\sigma)}\prime$ shrinks as $l$ increases, and for which we will describe the corresponding eigenvalue/direction/eigenvector as \textit{irrelevant},
\item[(iii)] $y_{\sigma} = 0$, which implies that $a^{(\sigma)}\prime$ does not change as $l$ increases, and for which we will describe the corresponding eigenvalue/direction/eigenvector as \textit{marginal}.
\end{itemize}
Therefore, if we start at $[K]$ near $[K^*]$, but not in the critical manifold then the flow in directions out of the critical manifold in the vicinity of $[K^*]$ are associated with relevant eigenvalues. The irrelevant eigenvalues correspond to directions into the fixed point, and their corresponding eigenvectors span the critical manifold.

\subsection{Relation between RG flows and the phase diagram}

Starting from any point in $\mathcal{K}$, which is equivalent to the phase space, we can determine to which fixed point an infinite number of iterations of RG transformations leads to. The state of the system described by this fixed point then represents the phase at the original point.\\

RG theory therefore enables one to investigate the whole phase diagram. We will however focus on critical behaviours and advise the interested reader to read part 9.3.3 of \cite{goldenfeld1992lectures} about the global properties of RG flows and the different types of fixed points and their significance.\\

We have that points that are slightly off the critical manifolds are repelled from it in the relevant directions. Therefore, it is the same eigenvalues that drive all slightly off-critical systems away from the critical fixed point: this is the origin of universality. Furthermore, we have that the critical behaviour is not determined by the initial values of the coupling constants but only by the flow behaviour.

\section{Critical scaling}

\subsection{Scaling behaviour of the free energy density and its derivatives}

We have that the linearised RG transformation $R_l$ close to the critical fixed point $[K^*]$, $M^{(l)}$, is diagonal in the orthonormal base $(\vec{e}^{\hspace{1pt}(\sigma)})_{\sigma}$ of $\mathcal{K}$. We want to investigate the behaviour of the free energy density $f$ and its derivatives close to this critical fixed point, we will then denote $[K^*]\equiv \sum_{\sigma} K^*_{\sigma}\vec{e}^{\hspace{1pt}(\sigma)}$ and introduce $\tilde{f}$ such that
\begin{equation}
\begin{aligned}
f[K]=f(K_0,\ldots,K_m)&\equiv\tilde{f}(\tilde{K_0},\ldots,\tilde{K_m})=\tilde{f}[\tilde{K}]\\
\forall \sigma \in \llbracket0,m\rrbracket,~ \tilde{K_{\sigma}} &= \begin{cases} \frac{K_{\sigma}-K_{\sigma}^*}{K_{\sigma}^*} &\text{ if } K_{\sigma}^* \neq 0 \\ K_{\sigma} &\text{ if } K_{\sigma}^* = 0 \end{cases}
\end{aligned}
\end{equation}
and which verifies the following property
\begin{align*}
\forall \sigma \in \llbracket0,m\rrbracket,~ \frac{\partial}{\partial K_{\sigma}} f[K] = \begin{cases} \frac{1}{K_{\sigma}^*} \frac{\partial}{\partial \tilde{K}_{\sigma}} \tilde{f}[\tilde{K}] &\text{ if } K_{\sigma}^* \neq 0 \\ \frac{\partial}{\partial K_{\sigma}} \tilde{f}[\tilde{K}] &\text{ if } K_{\sigma}^* = 0 \end{cases}
\end{align*}
which implies
\begin{equation}
\forall \sigma \in \llbracket0,m\rrbracket,~ \frac{\partial}{\partial K_{\sigma}} f[K] \propto \frac{\partial}{\partial \tilde{K}_{\sigma}} \tilde{f}[\tilde{K}]
\end{equation}
this property being also easily demonstrated for cross-derivatives and higher order derivatives.\\

According to equations \ref{free_energy_scaling} and \ref{eigenvalues_scaling}, the free energy density transforms under $n$ iterations of the RG transformation $R_l$ as
\begin{equation}
f[K] = l^{-nd} f[K'] = l^{-nd} \tilde{f}[\tilde{K}'] = l^{-nd} \tilde{f}(l^{ny_0}\tilde{K}_0,\ldots,l^{ny_m}\tilde{K}_m)
\end{equation}
Besides that it has to be greater or equal to $1$, there is no restriction to the values $l$ can take, we then introduce $b$ such that
\begin{equation}
l^n = \left(\frac{b}{\tilde{K}_0}\right)^{1/y_0} \geq 1
\label{choice_of_l}
\end{equation}
therefore we have the free energy density and its derivatives
\begin{equation}
\begin{aligned}
f[K] &= \left(\frac{\tilde{K}_0}{b}\right)^{d/y_0}\tilde{f}\left(b,\left(\frac{b}{\tilde{K}_0}\right)^{y_1/y_0}\tilde{K}_1,\ldots,\left(\frac{b}{\tilde{K}_0}\right)^{y_m/y_0}\tilde{K}_m\right)\\
\forall \sigma \in \llbracket0,m\rrbracket,~ \frac{\partial}{\partial K_{\sigma}} f[K] &\propto \left(\frac{\tilde{K}_0}{b}\right)^{(d-y_{\sigma})/y_0}\frac{\partial}{\partial K_{\sigma}}\tilde{f}\left(b,\left(\frac{b}{\tilde{K}_0}\right)^{y_1/y_0}\tilde{K}_1,\ldots,\left(\frac{b}{\tilde{K}_0}\right)^{y_m/y_0}\tilde{K}_m\right)
\label{free_energy_der_scaling}
\end{aligned}
\end{equation}
for which we will distinguish 2 cases:
\begin{itemize}
\item[(i)] $\forall \sigma \in \llbracket0,m\rrbracket,~ \vec{e}^{\hspace{1pt}(\sigma)}$ is a relevant eigenvector, then if we take $\tilde{K}_{\sigma}=0,~\forall \sigma \in \llbracket1,m\rrbracket$, we can rewrite equation \ref{free_energy_der_scaling} as
\begin{equation}
\begin{aligned}
\begin{cases} &f[K] = \left(\frac{\tilde{K}_0}{b}\right)^{d/y_0}\tilde{f}\left(b,0,\ldots,0\right) \\
&\forall \sigma \in \llbracket0,m\rrbracket,~ \frac{\partial}{\partial K_{\sigma}} f[K] \propto \left(\frac{\tilde{K}_0}{b}\right)^{(d-y_{\sigma})/y_0}\frac{\partial}{\partial K_{\sigma}}\tilde{f}\left(b,0,\ldots,0\right) \end{cases} \Rightarrow\begin{cases} f[K] &\isEquivTo{\tilde{K}_0\rightarrow0} \tilde{K}_0^{c_0} \\ \frac{\partial}{\partial K_{\sigma}} f[K] &\isEquivTo{\tilde{K}_0\rightarrow0} \tilde{K}_0^{c_{0,\sigma}} \end{cases}
\end{aligned}
\label{critical_exponents_RG}
\end{equation}
where $c_0$ and $c_{0,\sigma}$ are constants, hence the power-law scaling of the thermodynamic constants close to criticality.\\

Therefore, RG theory gives a theoretical explanation of the power-law scaling at criticality, thus supporting our scaling assumptions, and furthermore provides a technique to calculate the corresponding critical exponents. However, as stated in the introduction to this appendix, this calculation remains particularly technical, "where the renormalization group approach has been successful a lot of ingenuity has been required: one cannot write a renormalization group cookbook" \cite{wilson1975renormalization}. We advise the interested reader to read part 9.6 of \cite{goldenfeld1992lectures} on the application of RG theory to the 2D Ising model.\\

\item[(ii)] $\exists~ \sigma \in \llbracket1,m-1\rrbracket,~ \vec{e}^{\hspace{1pt}(0)},\ldots,\vec{e}^{\hspace{1pt}(p-1)}$ are revelant eigenvectors -- which implies $y_0,\ldots,y_{p-1}>0$ -- and $\vec{e}^{\hspace{1pt}(p)},\ldots,\vec{e}^{\hspace{1pt}(m)}$ are irrelevant eigenvectors -- which implies $y_p,\ldots,y_m<0$ --, then we can notice that in equation \ref{free_energy_der_scaling}
\begin{align*}
\forall \sigma \in \llbracket p,m\rrbracket,~ \left(\frac{b}{\tilde{K}_0}\right)^{y_{\sigma}/y_0}\tilde{K}_{\sigma} \xrightarrow[\tilde{K}_0\rightarrow0]{} 0
\end{align*}
therefore if $\tilde{f}$ is analytic in the limit of the vanishing coupling constants in the irrelevant directions, then the results of equation \ref{critical_exponents_RG} still hold. However, this is often not the case. When $\tilde{f}$ is singular in the limit that a particular irrelevant variable vanishes, the irrelevant variable is termed a \textit{dangerous irrelevant variable}.\\
\end{itemize}

We want to draw attention to the fact that in the case of the free energy density depending solely on two relevant variables $K_0$ and $K_1$, or on a relevant variable $K_0$ and a non-dangerous irrelevant variable $K_1$, we have close to criticality
\begin{equation}
f[K] = \left(\frac{\tilde{K}_0}{b}\right)^{d/y_0}\tilde{f}\left(b,\left(\frac{b}{\tilde{K}_0}\right)^{y_1/y_0}\tilde{K}_1\right) \equiv \tilde{K}_0^{d/y_0}\tilde{f}_1\left(\tilde{K}_0^{-y_1/y_0}\tilde{K}_1\right)
\label{fitting_function}
\end{equation}
with a similar result for the derivatives of the free energy density, therefore in the context of numerical simulations of a system close to criticality with two relevant variables not equal to their critical values, it is still possible to determine from the data the fitting function $\tilde{f}_1$ and then the critical exponent.\\

In the case of $K_1$ being a relevant variable, we will call $\Delta \equiv y_1/y_0$ the \textit{crossover scaling critical exponent} and $z \equiv \tilde{K}_1/\tilde{K}_O^{\Delta}$ the \textit{crossover scaling variable} \cite{PRL99.178001}. What happens if $z$ is non-neglible is that this variable is able to drive the system from the neighbourhood of one fixed point to that of another. Therefore, we may not observe the correct assymptotic behaviour when neglecting the term associated with $K_1$, hence the importance of this correction.\\

Furthermore, what has been eluded in our demonstration is that to verify equation \ref{choice_of_l}, $b$ has to be of the same sign as $\tilde{K}_0$, therefore in equation \ref{critical_exponents_RG} the value and most importantly the sign of $\tilde{f}(b,0,\ldots,0)$ and its derivatives, and thus the sign of the asymptotic approximation, may change depending on the sign of $\tilde{K}_0$. What is most often observed is a scaling behaviour at criticality of the type
\begin{equation}
\begin{aligned}
f[K] &\operatorname*{~=~}_{\tilde{K}_0\rightarrow0} A^{(0)}_{\pm} |\tilde{K}_O|^{c_0} + \smallO{|\tilde{K}_O|^{c_0}}\\
\frac{\partial}{\partial K_{\sigma}}f[K] &\operatorname*{~=~}_{\tilde{K}_0\rightarrow0} A^{(0,\sigma)}_{\pm} |\tilde{K}_O|^{c_{0,\sigma}} + \smallO{|\tilde{K}_O|^{c_{0,\sigma}}}
\end{aligned}
\label{absolute_value_scaling}
\end{equation}
where the values of $A^{(0)}_{\pm}$ and $A^{(0,\sigma)}_{\pm}$ may change depending on the sign of $\tilde{K}_0$.

\subsection{Corrections to scaling}

Consider for a given Hamiltonian that the RG transformation $R_l$ close to the critical fixed point $[K^*]$ is diagonal in the orthonormal base $(\vec{e}^{\hspace{1pt}(0)},\vec{e}^{\hspace{1pt}(1)})$ with $\vec{e}^{\hspace{1pt}(0)}$ a relevant eigenvector and $\vec{e}^{\hspace{1pt}(1)}$ an irrelevant eigenvector. We then have, with the notation of equations \ref{free_energy_der_scaling} and \ref{fitting_function}, and in the framework of equation \ref{absolute_value_scaling}, the following relation
\begin{equation}
\begin{aligned}
f[K] &\equiv \left|\tilde{K}_0\right|^{d/y_0}\tilde{f}_1^{\pm}\left(\left|\tilde{K}_0\right|^{-y_1/y_0}\tilde{K}_1\right)\\
\forall \sigma \in \llbracket0,1\rrbracket,~ \frac{\partial}{\partial K_{\sigma}} f[K] &\equiv \left|\tilde{K}_0\right|^{(d-y_{\sigma})/y_0}\tilde{f}_{1,\sigma}^{\pm}\left(\left|\tilde{K}_0\right|^{-y_1/y_0}\tilde{K}_1\right)
\end{aligned}
\end{equation}
In practice, it is very difficult to access the asymptotic critical regime $\tilde{K_0}\rightarrow0$, therefore the irrelevant variable may not be negligible and corrections have to be brought to our scaling assumptions.\\

A solution is to assume that $\tilde{f}_1$ and/or $\tilde{f}_{1,\sigma}$ are analytic functions in the limit that their argument, which we will call $x$ for convenience, vanishes -- assumption which is valid if $\tilde{K}_1$ is not a dangerous irrelevant variable. Therefore, we have a new assymptotic behaviour
\begin{equation}
\begin{aligned}
f[K] &\operatorname*{~=~}_{\tilde{K}_0\rightarrow0} \left|\tilde{K}_0\right|^{d/y_0} \left( A_1 + B_1 \left|\tilde{K}_0\right|^{-y_1/y_0}\tilde{K}_1 + \mathcal{O}\left(x^2\right)\right)\\
\forall \sigma \in \llbracket0,1\rrbracket,~ \frac{\partial}{\partial K_{\sigma}} f[K] &\operatorname*{~=~}_{\tilde{K}_0\rightarrow0} \left|\tilde{K}_0\right|^{(d-y_{\sigma})/y_0} \left( A_{1,\sigma} + B_{1,\sigma} \left|\tilde{K}_0\right|^{-y_1/y_0}\tilde{K}_1 + \mathcal{O}\left(x^2\right)\right)
\label{scaling_corrections}
\end{aligned}
\end{equation}
according to Taylor's theorem, where $A_1$, $B_1$, $A_{1,\sigma}$ and $B_{1,\sigma}$ are -- non-universal -- constants.\\

As expected, the leading behaviour as $\tilde{K}_0\rightarrow0$ is a power-law in $\tilde{K}_0$. We may then distinguish 2 cases:
\begin{itemize}
\item[(i)] $|y_1|/y_0 > 1$, which implies that the correction becomes smaller as $\tilde{K}_0\rightarrow0$,
\item[(ii)] $|y_1|/y_0 < 1$, which implies that the correction may not be negligible for small but non-zero $\tilde{K}_0$. This first order correction is actually singular, since it gives rise to a cusp \cite{wiki:cusp} at $\tilde{K}_0 = 0$. Such a correlation is referred as a \textit{confluent singularity}.
\end{itemize}

\subsection{Finite-size scaling}

Numerical simulations use finite systems of which we will denote $L$ the characteristic length. As the system approaches a critical fixed point, its correlation length $\xi$ diverges, therefore when $L$ and $\xi$ are comparable, the thermodynamic properties of the system can not be considered as being those of an infinite system anymore. What is observed is that the transition associated with the critical fixed point appears less sharp.\\

To address this issue, one has to include the characteristic length of the system -- or rather its inverse $1/L$ which vanishes as the system approaches the critical fixed point associated with an infinite system -- in the variables of the free energy density, which will then transform under $n$ iteration of the RG transformation $R_l$ as
\begin{equation}
f[K] = l^{-nd} f[K'] = l^{-nd} \tilde{f}[\tilde{K}'] = l^{-nd} \tilde{f}(l^{ny_0}\tilde{K}_0,\ldots,l^{ny_m}\tilde{K}_m,l^nL^{-1})
\end{equation}
A crossover scaling analysis, as described in the discussion of equation \ref{fitting_function}, can then be performed.

% \input{references/biblio}

\end{document}

% \end{cbunit}


%
% CMPT 379: Principles of Compiler Design - A Course Overview
% Section: Parsing Algorithms: Bottom-Up
%
% Author: Jeffrey Leung
%

\section{Parsing Algorithms: Bottom-Up}
	\label{sec:parsing-algorithms-bottom-up}

\subsection{Introduction}
	\label{subsec:parsing-algorithms-bottom-up:introduction}
\begin{easylist}

& \textbf{Bottom-up parsing:} Reduction of a string of terminal symbols to the start symbol
	&& Simulates a reversed rightmost derivation (see \textit{shift-reduce parsing})

& \textbf{LR(k) parsing:} Bottom-up parsing derivation which parses \textbf{L}eft-to-right to create a \textbf{R}ightmost derivation with $k$ (usually 1) tokens of lookahead
	&& Actions:
		&&& Shift ($f: u \rightarrow a$)
		&&& Reduce ($f: \textrm{ lookup production  } x \rightarrow y_1 \dotsc y_n$)
		&&& Accept
		&&& Error

& \textbf{Dotted rule:} Parser state consisting of a single production rule and a dot ($\bullet$) where the parser currently is at
	&& Notation: $A \rightarrow B \bullet C$
	&& All symbols to the left of the dot have been read; all symbols to the right of the dot are predicted
	&& \textbf{Configuration/itemset/state:} Set of dotted rules which are all possible productions given an in-progress parse

		&&& E.g. Given a set of production rules and a dotted rule, the resulting configuration set is given in table~\ref{tab:config-set}

\end{easylist}
\begin{figure}[!htb]
	\caption{Configuration Set Example}
	\label{tab:config-set}
	\begin{center}
		\begin{tabular}{ r | l }
			Production Rules
			& $T \rightarrow F$ \\
			& $T \rightarrow T*F$ \\
			& $F \rightarrow id$ \\
			& $F \rightarrow (T)$ \\
			\hline
			Dotted Rule
			& $T \rightarrow T * \bullet F$ \\
			\hline
			\hline
			$closure(T \rightarrow T * \bullet F)$
			& $T \rightarrow T * \bullet F$ \\
			(Configuration set)
			& $F \rightarrow \bullet (T)$ \\
			& $F \rightarrow \bullet id$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

& \textbf{Action/Goto (parsing) table:} Set of states and transitions which provides a programmatic method to parse an input
	&& Notations:
		&&& $\textrm{action}[s, a]; a \in T$ where $T$ is the set of terminal states
		&&& $\textrm{goto}[s, X]; X \in N$ where $N$ is the set of non-terminal states

	&& Layout: See table~\ref{tab:layout-action-table}

\end{easylist}
\begin{figure}[!htb]
	\caption{Layout of an action/goto table}
	\label{tab:layout-action-table}
	\begin{center}
		\begin{tabular}{ l | l l | l }
			\textbf{State} & \textbf{Actions} (Terminal symbols) & \$ & \textbf{Gotos} (Non-terminal symbols) \\
			\hline
			\textit{Number} & \textit{Shift STATE or Reduce RULE} & & \textit{Change to STATE}
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

	&& To create a parsing table, create the layout, then for each itemset/state:
		&&& If the state transitions to a new state upon symbol $X$, then:
			&&&& If $X$ is a terminal symbol, then write S$\alpha$ (shift to state $\alpha$) in the action
			&&&& If $X$ is a non-terminal symbol, then write $\alpha$ (shift to state $\alpha$) in the goto
		&&& If the state results in a reduction to non-terminal symbol $X$, then for each symbol in the $FOLLOW$ set of $X$, write R$\beta$ (reduce by rule number $\beta$) in the action
		&&& If the itemset has an epsilon ($\epsilon$) rule for symbol $X$ (i.e. $X \rightarrow \epsilon$), then for each symbol in the $FOLLOW$ set of $X$, write R$\beta$ (reduce by rule number $\beta$) in the action
		&&& If multiple shifts or reduces are possible for a given input from a given state, then use a comma to separate the possibilities
		&&& If the itemset reaches the end of input, then in $\$$, write $acc$ (acceptance) instead of reducing

& \textbf{Closure:} Function to create a configuration set given a dotted rule, where the configuration set consists of the given dotted rule, all dotted rules where the symbol $X$ after the bullet is the input of a production rule (i.e. $f: X \rightarrow Y$), and all rules which recurse upon $Y_1$
	&& Mathematically: Given dotted rule $T \rightarrow X_1 \dotsc X_i \bullet X_{i+1} \dotsc X_n$, the configuration set consists of rule $T$ as well as all dotted rules $X_{i+1} \rightarrow \bullet Y_1 \dotsc Y_m$
	&& Notation: $closure(A \rightarrow B \bullet C) = \{\}$

& Example of a shift-reduce conflict: Rules $F \rightarrow id \bullet; F \rightarrow id \bullet T$
& Example of a reduce-reduce conflict: Rules $F \rightarrow id \bullet; T \rightarrow id \bullet$

& \textbf{Successor:} Function on a configuration set and a successive symbol which removes non-matching rules in the configuration set and computes a new closure on the remaining dotted rules
	&& Notation: $successor(I, X) = \{\}$ where $I$ is a configuration set and $X$ is a successive symbol
	&& E.g. Given a set of production rules and a configuration set, an example successor function is given in table~\ref{tab:successor-example}

\end{easylist}
\begin{figure}[!htb]
	\caption{Successor Example}
	\label{tab:successor-example}
	\begin{center}
		\begin{tabular}{ r | l }
			Production Rules
			& $S' \rightarrow T$ \\
			& $T \rightarrow F$ \\
			& $T \rightarrow T*F$ \\
			& $F \rightarrow id$ \\
			& $F \rightarrow (T)$ \\
			\hline
			Configuration set $I$
			& $S'\rightarrow \bullet T$ \\
			& $T \rightarrow \bullet F$ \\
			& $T \rightarrow \bullet T * F$ \\
			& $F \rightarrow \bullet id$ \\
			& $F \rightarrow \bullet (T)$ \\
			\hline
			\hline
			$successor(I, \textrm{``(''})$
			& $F \rightarrow (\bullet T)$ \\
			(Configuration set)
			& $T \rightarrow \bullet F$ \\
			& $T \rightarrow \bullet T * F$ \\
			& $F \rightarrow \bullet id$ \\
			& $F \rightarrow \bullet (T)$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

	&& For an example diagram of a set of production rules and the states generated using the successor function, see figure~\ref{fig:example-diagram-of-states}

\begin{figure}[!htb]
	\caption{Example Diagram of States}
	\label{fig:example-diagram-of-states}
	\begin{center}
		\includegraphics[width=\textwidth]{lrk-states-diagram}
	\end{center}
\end{figure}

	&& For an example diagram of a set of production rules (including epsilon rules) and the states generated using the successor function, see figure~\ref{fig:example-diagram-of-states-epsilon}

\begin{figure}[!htb]
	\caption{Example Diagram of States with Epsilon Rules}
	\label{fig:example-diagram-of-states-epsilon}
	\begin{center}
		\includegraphics[width=\textwidth]{lrk-states-epsilon-diagram}
	\end{center}
\end{figure}

& \textbf{Viable prefix:} Set of states representing the stack of a shift-reduce parser where combining it with the remaining symbols is a valid state
	&& Notation: $\gamma$ such that $\gamma | \omega$ is a valid state for some $\omega$

& Process of LR(k) parsing:
	&& Requires a set of production rules, an action/goto table, and an input string
	&& Begin with state $0$ on the stack.
	&& From the row number of the current state (given by the top of the stack) and the leftmost symbol in the input, continually take the given action in the action table, given by $\textrm{action}[]$.
		&&& If the action is $S\alpha$, then push state $\alpha$ onto the stack and consume the leftmost symbol of the input.
		&&& If the action is $Rr$, then:
			&&&& Find the production rule numbered $r$, with $r: X \rightarrow Y_1 \dotsc Y_k$.
			&&&& Pop $k$ states from the stack.
			&&&& Take the state $Z$ at the top of the stack and push state $\textrm{goto}[Z, X]$ onto the stack.
		&&& If the action is $\textrm{ACCEPT}$, then complete the parsing.
		&&& If no action exists, then return $\textrm{ERROR}$.

	&& Example: Given the production rules in figure~\ref{tab:lrk-productions} and action/goto table in figure~\ref{tab:lrk-ag-table}, the trace of the LR(0) parse is figure~\ref{tab:lrk-trace}

\end{easylist}
\begin{figure}[!htb]
	\caption{LR(k) Parsing Example: Production Rules}
	\label{tab:lrk-productions}
	\begin{center}
		\begin{tabular}{ r | l }
			& Production Rules \\
			\hline
			1 & $T \rightarrow F$ \\
			2 & $T \rightarrow T*F$ \\
			3 & $F \rightarrow id$ \\
			4 & $F \rightarrow (T)$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{LR(k) Parsing Example: Action/Goto Table}
	\label{tab:lrk-ag-table}
	\begin{center}
		\begin{tabular}{ r | c | c | c | c | c || c | c }
			\multirow{2}{*}{\textbf{States}} & \multicolumn{5}{ c || }{\textbf{Actions}} & \multicolumn{2}{c}{\textbf{Gotos}} \\
			& * & ( & ) & id & \$ & T & F \\
			\hline
			0 & & S5 & & S8 & 2 & 1 \\
			1 & R1 & R1 & R1 & R1 & R1 & \\
			2 & S3 & & & & ACC & \\
			3 & & S5 & & S8 & & 4 \\
			4 & R2 & R2 & R2 & R2 & R2 & \\
			5 & & S5 & & S8 & & 6 & 1 \\
			6 & S3 & & S7 & & & \\
			7 & R4 & R4 & R4 & R4 & R4 & \\
			8 & R3 & R3 & R3 & R3 & R3 &
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{LR(k) Parsing Example: Trace}
	\label{tab:lrk-trace}
	\begin{center}
		\begin{tabular}{ l | r | l }
			Stack & Input & Action \\
			\hline
			0 & (id)*id & Shift 5 \\
			0, 5 & id)*id & Shift 8 \\
			0, 5, 8 & )*id & Reduce using production rule 3: $F \rightarrow id$ \\
			&& Pop 1 symbol from the stack (8) \\
			&& Push $goto[5, F] = 1$ onto the stack \\
			0, 5, 1 & )*id & R1: $T \rightarrow F$ \\
			&& Pop 1 \\
			&& $goto[5, T] = 6$ \\
			0, 5, 6 & )*id & S7 \\
			0, 5, 6, 7 & *id & R4, $F \rightarrow (T)$ \\
			&& Pop 7, 6, 5 \\
			&& $goto[0, T] = 1$ \\
			0, 1 & *id & R1: $T \rightarrow F$ \\
			&& Pop 1 \\
			&& $goto[0, T] = 2$ \\
			0, 2 & *id & S3 \\
			0, 2, 3 & id & S8 \\
			0, 2, 3, 8 & \$ & R3: $F \rightarrow id$ \\
			&& Pop 8 \\
			&& $goto]3, F] = 4$ \\
			0, 2, 3, 4 & \$ & R2: $T \rightarrow T*F$ \\
			&& Pop 4, 3, 2 \\
			&& $goto[0, T] = 2$ \\
			0, 2 & \$ & ACCEPT
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\subsection{LR(0) Parsing}
	\label{subsec:parsing-algorithms-bottom-up:lr0}
\begin{easylist}

& \textbf{LR(0) parsing:} Form of LR(k) parsing where no tokens of lookahead are used, so a reduction is always executed whenever possible
	&& \textbf{LR(0) grammar:} Subset of CFGs where an LR(0) construction can be generated without shift-reduce or reduce-reduce conflicts (i.e. the generated pushdown automata is deterministic)

& Grammar validity:
	&& A grammar is LR(0) if and only if no shift-reduce or reduce-reduce conflicts exist in the itemsets
	&& A grammar is not LR(0) if and only if at least one shift-reduce or reduce-reduce conflict exists in the itemsets

\end{easylist}
\subsection{SLR(1) Parsing}
	\label{subsec:parsing-algorithms-bottom-up:slr1}
\begin{easylist}

& \textbf{LR(1) parsing:} Form of LR(k) parsing where 1 token of lookahead is available for use

& \textbf{SLR(1)/SLR/Simple LR parsing:} Subset of LR(0) parsing where each \textit{production rule} includes all possible $FOLLOW$ terminal symbols using 1 character of lookahead

& \textbf{SLR(1)/SLR/Simple LR grammar:} Subset of CFGs where an LR(1) construction can be generated without shift-reduce or reduce-reduce conflicts, or conflicts exist but can be resolved due to having a single $FOLLOW$ symbol
	&& First/follow:
		&&& \textbf{First:} Set of terminal symbols which are the beginning symbols of all strings which can be derived from a given symbol
			&&&& Notation: $FIRST(S) = \{a, b\}$ where $S$ is a given symbol and $a, b$ are terminal symbols
			&&&& Example: Given a set of production rules, the First sets of the non-terminal symbols are derived in table~\ref{tab:first-example}
		&&& \textbf{Follow:} Set of terminal symbols which can follow a given symbol
			&&&& Notation: $FOLLOW(S) = \{a, b\}$ where $S$ is a given symbol and $a, b$ are terminal symbols
			&&&& Example: Given a set of production rules, the Follow sets of the non-terminal symbols are derived in table~\ref{tab:follow-example}
		&&& Example: Given a set of production rules, the First and Follow sets of the non-terminal symbols can be derived as follows:
			&&&& See table~\ref{tab:first-follow-sets-example-1}
			&&&& See table~\ref{tab:first-follow-sets-example-2}

\end{easylist}
\begin{figure}[!htb]
	\caption{First Example}
	\label{tab:first-example}
	\begin{center}
		\begin{tabular}{ r l }
			Production Rules:
			& $A \rightarrow Bc | d$ \\
			& $B \rightarrow e$ \\
			\hline
			$FIRST(A) =$ & $\{d, e\}$ \\
			$FIRST(B) =$ & $\{e\}$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{Follow Example}
	\label{tab:follow-example}
	\begin{center}
		\begin{tabular}{ r l }
			Production Rules:
			& $A \rightarrow Bc$ \\
			& $B \rightarrow Bd | BC$ \\
			& $C \rightarrow e$ \\
			\hline
			$FOLLOW(A) =$ & $\{ \$ \}$ \\
			$FOLLOW(B) =$ & $\{c, d, e\}$ \\
			$FOLLOW(C) =$ & $\{c\}$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{First/Follow Sets Example 1}
	\label{tab:first-follow-sets-example-1}
	\begin{center}
		\begin{tabular}{ r | l }
			Production Rules
			& $S \rightarrow AB$ \\
			& $A \rightarrow c | \epsilon$ \\
			& $B \rightarrow cbB | a$ \\
			\hline
			First sets
			& $FIRST(A) = \{c, \epsilon\}$ \\
			& $FIRST(B) = \{c, a\}$ \\
			& $FIRST(S) = FIRST(A) = \{c, \epsilon\}$ \\
			\hline
			Follow sets
			& $FOLLOW(A) = FIRST(B) = \{c, a\}$ \\
			& $FOLLOW(B) = \{\$\}$ \\
			& $FOLLOW(S) = \{\$\}$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

\end{easylist}
\begin{figure}[!htb]
	\caption{First/Follow Sets Example 2}
	\label{tab:first-follow-sets-example-2}
	\begin{center}
		\begin{tabular}{ r | l }
			Production Rules
			& $S \rightarrow cAa$ \\
			& $A \rightarrow cB | B$ \\
			& $B \rightarrow bcB | \epsilon$ \\
			\hline
			First sets
			& $FIRST(A) = \{c, b, \epsilon\}$ \\
			& $FIRST(B) = \{b, \epsilon\}$ \\
			& $FIRST(S) = \{c\}$ \\
			\hline
			Follow sets
			& $FOLLOW(A) = \{a\}$ \\
			& $FOLLOW(B) = FOLLOW(A) = \{a\}$ \\
			& $FOLLOW(S) = \{\$\}$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

	&& Process to determine whether a shift-reduce conflict can be eliminated by a 1-token lookahead:
		&&& Find the $FOLLOW$ set of the reduce rule
		&&& Find the next accepted symbol of the shift rule
		&&& If the symbol is in the $FOLLOW$ set, then the conflict cannot be eliminated
		&&& Example: Given the set of production rules in table~\ref{tab:slr-shift-reduce}, the state $S \rightarrow A \bullet xB; B \rightarrow A \bullet$ has a shift-reduce conflict which cannot be resolved by 1 token of lookahead, as the parser can still shift or reduce on $x$ because the $FOLLOW$ set of $B$ is $\{ x, \$ \}$

\end{easylist}
\begin{figure}[!htb]
	\caption{SLR Shift-Reduce Conflict Example}
	\label{tab:slr-shift-reduce}
	\begin{center}
		\begin{tabular}{ l }
			$S \rightarrow Ax$ \\
			$S \rightarrow B$ \\
			$B \rightarrow A$ \\
			$A \rightarrow yB$
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

	&& Example: Given the set of production rules and transition diagram in figure~\ref{fig:slr-1-parsing-prod-rules-diagram}, the trace of the SLR(1) parse of $id * id$ is table~\ref{tab:slr-1-parsing-trace}

\begin{figure}[!htb]
	\caption{SLR(1) Parsing Example: Production Rules and Diagram}
	\label{fig:slr-1-parsing-prod-rules-diagram}
	\begin{center}
		\includegraphics[width=\textwidth]{slr-1-trace-diagram}
	\end{center}
\end{figure}

\end{easylist}
\begin{figure}[!htb]
	\caption{SLR(1) Parsing Example: Trace}
	\label{tab:slr-1-parsing-trace}
	\begin{center}
		\begin{tabular}{ l | r | l }
			Stack and Input & DFA Halt State & Action \\
			\hline
			$| id * id\$ $ & $1$ & Shift \\
			$id | * id\$ $ & $3 ( \* \not\in FOLLOW(T) )$ & Shift \\
			$id * | id\$ $ & $11$ & Shift \\
			$id * id |\$ $ & $3 (\$ \in FOLLOW(T) )$ & Reduce $T \rightarrow id$ \\
			$id * T | \$ $ & $4 (\$ \in FOLLOW(T) )$ & Reduce $T \rightarrow id * T$ \\
			$T | \$ $ & $5 (\$ \in FOLLOW(T) )$ & Reduce $E \rightarrow T$ \\
			$E | \$ $ & & Accept
		\end{tabular}
	\end{center}
\end{figure}
\begin{easylist}

& Grammar validity:
	&& A grammar is SLR(1) if and only if, for each shift-reduce or reduce-reduce conflict in the configuration sets, the $FOLLOW$ sets of the conflicting production rules (not dotted rules) do not intersect
	&& A grammar is not SLR(1) if and only if there exists at least one shift-reduce or reduce-reduce conflict in the configuration sets where the $FOLLOW$ sets of the conflicting production rules intersect

\end{easylist}
\subsection{Canonical LR(1) Parsing}
	\label{subsec:parsing-algorithms-bottom-up:canonical-lr1}
\begin{easylist}

& \textbf{LR(1)/Canonical LR(1) parsing:} Subset of LR(0) parsing where each \textit{dotted rule} includes a 1-character lookahead, rather than each production rule
	&& More accurate than SLR(1) parsing
	&& Notation: $\textrm{dotted rule, } \alpha / \beta$ where $\alpha, \beta$ are the potential $FOLLOW$ characters of the non-terminal symbol if the rule was parsed and reduced

& Grammar validity:
	&& A grammar is LR(1) if and only if, for each shift-reduce or reduce-reduce conflict, the $FOLLOW$ sets of the dotted rules do not conflict
	&& A grammar is not LR(1) if and only if there exists at least one itemset where conflicting dotted rules have intersecting $FOLLOW$ sets

\end{easylist}
\subsection{LALR(1) Parsing}
	\label{subsec:parsing-algorithms-bottom-up:lalr1}
\begin{easylist}

& \textbf{LALR(1) parsing:} Subset of LR(0) parsing which combines states when they share the same dotted rules but have different $FOLLOW$ sets
	&& More specific than SLR(1) (as resulting $FOLLOW$ sets may not always be the complete \\ $FOLLOW$ set)
	&& Simplified/compact version of canonical LR(1)

& Grammar validity:
	&& A grammar is LALR(1) if and only if, when states with matching dotted rules are merged, for each combination of states, for each matching dotted rule in the resulting configuration set, there are no conflicts in the 1-character lookaheads
	&& A grammar is not LALR(1) if and only if, when states with matching dotted rules are merged, the $FOLLOW$ sets contain shift-reduce or reduce-reduce conflicts

\end{easylist}
\clearpage


\section{Results and Discussion}
\label{sec:Results_and_Discussion}
\subsection{Speed of Sound}
\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{r l}
		\hline
		\textbf{Mean Value $\overline t$} & $(7.32\pm0.07)\cdot10^{-3}$\ s \\
		\textbf{Standard Deviation $s$} & $0.3\cdot10^{-3}$\ s \\
		\textbf{Speed of Sound $v$} & $(350\pm4)\ \,^\text{m}\!/_\text{s}$ \\ \hline
	\end{tabular}
	\caption{Speed of Sound Results}
	\label{tab:Speed_of_Sound_Results}
\end{table}
The results came out exactly the same way. The task of calculating the mean value, the error and standard deviation can easily be done in Excel or in QtiPlot. However, the advantage of QtiPlot is that a plot can easily be created with all the relevant data.
\subsection{Iron Content}
\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{r c}
		\hline
		\textbf{Mean Value} & $(20.6\pm0.5)\ \%$ \\
		\textbf{Weighted Mean Value} & $(20.4\pm0.4)\ \%$ \\ \hline
	\end{tabular}
	\caption{Iron Content Results}
	\label{tab:Iron_Content_Results}
\end{table}
The mean value and the weighted mean value were calculated with Excel and QtiPlot. Both values are exactly the same. The error bars in the exported plot from QtiPlot (see figure \ref{fig:Iron_Content}) are extremely helpful to understand the weighted mean value. Doing this in Excel would be pretty challenging.
\subsection{Spring Constant}
\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{r l}
		\hline
		\textbf{Spring Constant $k$} & $(22.5\pm0.9)\ \,^\text{N}\!/_\text{m}$ \\
		\textbf{Pretension Force $F_0$} & $(-0.8\pm0.5)$\ N \\ \hline
	\end{tabular}
	\caption{Spring Constant Results}
	\label{tab:Spring_Constant_Results}
\end{table}
The linear fitted curve (see figure \ref{fig:Spring_Constant}) was created with QtiPlot. Furthermore, the results have been calculated using QtiPlot.
\newpage
\subsection{Pendulum}
\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{r l}
		\hline
		\textbf{Amplitude $A$} & $(-1.22\pm0.03)$\ m \\
		\textbf{Damping Constant $\Gamma$} & $(52\pm2)\cdot10^{-3}\ \text{s}^{-1}$ \\
		\textbf{Frequency $f$} & $(55.0\pm0.2)\cdot10^{-3}$\ Hz \\
		\textbf{Phase $\delta$} & $(-2.63\pm0.02)$\ rad \\
		\textbf{Offset $y_0$} & $(49\pm5)\cdot10^{-3}$\ m \\ \hline
	\end{tabular}
	\caption{Damped Pendulum Results}
	\label{tab:Damped_Pendulum_Results}
\end{table}
Calculating the parameters of the damped pendulum with QtiPlot is easy and does not take a lot of time. Calculating all the parameters with Excel would take quite some time. Furthermore, it would be more prone to errors.
\subsection{RC Low-Pass Filter}
\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.2}
	\begin{tabular}{r l}
		\hline
		\textbf{Capacity $C$ (Output Voltage)} & $(216.9\pm0.9)\cdot10^{-9}$\ F \\
		\textbf{Capacity $C$ (Phase)} & $(197.5\pm3.1)\cdot10^{-9}$\ F \\ \hline
	\end{tabular}
	\caption{RC Low-Pass Filter Results}
	\label{tab:RC_Low-Pass_Filter_Results}
\end{table}
The calculated capacities from the output voltage and the phase do not match. Generally, voltage measurements with a cathode ray oscilloscope can be read off more accurately than phase shift measurements. Thus, the capacity value calculated from the output voltage is more trustworthy.


\chapter{$b$-hadron Lifetimes}\label{appendix:B_hadron_lifetimes}

$b$-hadrons (hadronically bound states containing at least one $b$-flavor quark) have what are viewed as long lived lifetimes before they decay.
Using the charged $B$ meson, $B^{-}$, as an example, with quark content of $B^{-} = \Ket{\bar{u}\, b}$, a decay mediated by the strong force is forbidden by electrical charge conservation.
Thus, the decay must proceed through a flavor-changing charged current mediated by a $W$ boson.
Thus, some possible decays are
\[
 \underbrace{\bar{u}\,b}_{B^{-}} \to \underbrace{u\bar{u}}_{\pi^0} \left(W^{-} \to\right) \ell^{-} \bar{\nu}_{\ell}, \qquad \underbrace{\bar{u}\,b}_{B^{-}} \to \underbrace{u\bar{u}}_{\pi^0} \left(W^{-} 	\to \right) \underbrace{\bar{u}d}_{\pi^-},
\]
%
\[
 \underbrace{\bar{u}\,b}_{B^{-}} \to \underbrace{c\bar{u}}_{D^0} \left(W^{-} \to \right) \ell^{-} \bar{\nu}_{\ell}, \qquad \underbrace{\bar{u}\,b}_{B^{-}} \to \underbrace{c\bar{u}}_{D^0} \left(W^{-} \to \right) \underbrace{\bar{u}d}_{\pi^-}.
\]
As the $b$-decay is cross generational, it is ``Cabibbo suppressed'' further increasing the lifetime~\cite{Vaandering}.
Cabibbo suppression is also relevant in the decays of kaons and charged $D$-mesons.

With the introduction of the ``strangness'' quantum number, it was observed that the decay rates of particles with nonzero strangness were different then non-strange particles.
Cabibbo suggested~\cite{Cabibbo:1963yz} that these decays were also mediated by weak interactions but that the participating states (weak eigenstates) were mixtures of the mass eigenstates,
\[
 \Ket{d'} = \alpha \Ket{d} + \beta \Ket{s},
\]
such that through normalization, $\Braket{d'|d'} = 1$, and absorbing phases, one free parameter remains.
The choices of
\[
 \alpha = \cos\theta_C, \qquad \beta = \sin\theta_C,
\]
are made and $\theta_C$ --- the free parameter --- is empirically determined from fits to data to be $\theta_C \approx 0.23~\mathrm{rad} \approx 13.15^{\circ}$.
With Glashow, Iliopoulos, and Maiani's (GIM) introduction of a fourth quark, $c$,~\cite{Glashow:1970gm} the Cabibbo-GIM scheme established the ``Cabibbo-rotated'' weak eigenstates
\[
 \Ket{d'} = \cos\theta_C \Ket{d} + \sin\theta_C \Ket{s}, \qquad \Ket{s'} = -\sin\theta_C \Ket{d} + \cos\theta_C \Ket{s}
\]
which comprised the flavor doublets
\[
 \begin{pmatrix}
  u \\d'
 \end{pmatrix}, \quad
 \begin{pmatrix}
  c \\s'
 \end{pmatrix}
\]
that the $W$ bosons couple to in the same manner as they couple to lepton flavor doublets.
The Cabibbo rotation matrix obviously follows,
\[
 \begin{pmatrix}
  d' \\ s'
 \end{pmatrix}
 =
 \begin{pmatrix}
  \cos\theta_C & \sin\theta_C \\ -\sin\theta_C & \cos\theta_C
 \end{pmatrix}
 \begin{pmatrix}
  d \\ s
 \end{pmatrix}
\]
With Kobayashi and Maskawa's generalization of the Cabibbo-GIM scheme to three generations~\cite{Kobayashi:1973fv} the CKM transformation matrix was formed,
\[
 \begin{pmatrix}
  d' \\ s'\\ b'
 \end{pmatrix}
 =
 \begin{pmatrix}
  V_{ud} & V_{us} & V_{ub} \\
  V_{cd} & V_{cs} & V_{cb} \\
  V_{td} & V_{ts} & V_{tb} \\
 \end{pmatrix}
 \begin{pmatrix}
  d \\ s\\ b
 \end{pmatrix}\,.
\]
Taking the third to first and second generational mixing elements to be small (i.e., in terms of the generalized Cabibbo angles $(\theta_{12},\theta_{23},\theta_{13})$ $\theta_{13} \approx \theta_{23} \sim 0$), it is seen that the Cabibbo-GIM mixing matrix is recovered.
It is seen from the CKM matrix (whose on-diagonal elements are close to unity) that cross-generational decays (off-diagonal elements) are ``Cabibbo suppressed'' while intragenerational decays (on-diagonal elements) are ``Cabibbo favored.''

Thus, noting that
\[
 \beta = \frac{\abs{\vec{p}}c}{E}, \qquad E = \gamma\, mc^2,
\]
it is seen that for a hadron with mass $m$, mean lifetime $\tau$, and 3-momentum $\abs{\vec{p}}$, the distance it travels, $x'$, in the lab frame, $O'$, before decaying is,
\[
 \begin{split}
  x'	&= v' t'	\\
  &= \left(\beta c\right) \left(\gamma \tau\right)	\\
  &= \frac{\abs{\vec{p}}c^2}{E} \gamma \tau	\\
  &= \frac{\abs{\vec{p}}c^2}{\gamma\, mc^2} \gamma \tau	\\
  &= \frac{\abs{\vec{p}}}{m}\, \tau.
 \end{split}
\]
It is also seen that the characteristic length scale of the particle, where $\beta\gamma=1$ and so $p=mc$, is equal to $c\tau$.
The boost of the particle then acts as a scale factor of this length, scaling it up and down.


\chapter{Transfer matrices}
\label{Sec:transfer}
Deterministic particle transport codes solve a
discrete version of the Boltzmann equation, and the
transfer matrix approximates the kernel of the integral
operator in this equation.
If $x$ denotes the position,
$t$ the time, $E'$ the particle energy, $\Omega'$ the
direction of motion, $v$ the magnitude of the velocity (speed), and
$n(x, t, E', \Omega')$ the number density, then the
flux $\phi = vn$ satisfies the Boltzmann
equation~\cite{Lewis}
\begin{equation}
  \frac{1}{v} \, \partial_t \phi(E', \Omega') +
  \Omega'\cdot \nabla \phi(E', \Omega') +
      \rho\sigma_t \phi(E', \Omega') =
  \frac{\rho}{4\pi}
   \int_{\Omega} d\Omega \, \int_0^\infty dE \,
      \calK(E', \Omega' \cdot \Omega \mid E) \phi(E, \Omega).
  \label{Boltzmann}
\end{equation}
The direction $\Omega'$ is relative to some given
``north pole''~$\Omega_0$, and $\rho$ is the density of the material.
The dependence on $x$ and $t$ is suppressed.
The first two terms in Eq.~(\ref{Boltzmann}) give the derivative
with respect to distance of
the flux in a coordinate system moving with the particles.
The parameter
$\sigma_t$ is the microscopic total cross section, so the term
$\rho\sigma_t \phi(E', \Omega')$ represents the rate of particle loss
per particle path length.

The kernel
$\calK(E', \Omega' \cdot \Omega \mid E)$ in Eq.~(\ref{Boltzmann}) gives the
rate of production of outgoing particles with energy $E'$ and
direction~$\Omega'$ corresponding to incident particles
at energy $E$ and direction~$\Omega$.
Here, the energies $E$ and $E'$ and the directions $\Omega$
and $\Omega'$ are in the laboratory coordinate system.
From here on,  the notation
$$
  \mu = \Omega' \cdot \Omega
$$
is used.
It is significant that the dependence of
$\calK(E', \mu \mid E)$ on $\mu$
is axisymmetric, because the orientation of the
target nucleus is unknown.  The primes are placed where they are in
Eq.~(\ref{Boltzmann}), because the emphasis in this document is on
approximation of the right-hand side of the equation.  In that setting, it is
natural that $E$ denote the energy of the incident particle and $E'$
the outgoing particle energy.

For a given target,
the nuclear data in \xendl\ is given reaction by reaction,
e.g., elastic scattering, neutron capture, fission, etc.
The transfer matrix approximating $\calK$ is built
up by summing over the reactions~$r$
$$
  \calK = \sum_r \calK_r.
$$
The reaction kernels $\calK_r$ themselves are not given in \xendl,
but their component factors are given instead, namely,
\begin{enumerate}
 \item $\sigma_r(E)$: the cross section for the $r$-th reaction,
 \item  $M_r(E)$: the multiplicity of the outgoing particle,
 \item $w_r(E)$: the model weight for these data,
 \item $\pi_r(E', \mu \mid E)$: the double-differential probability
density of the energy and direction cosine
for one outgoing particle.
\end{enumerate}
In terms of this notation, $\calK_r$ is the product
\begin{equation}
  \calK_r(E', \mu \mid E) = \sigma_r(E) M_r(E) w_r(E) \pi_r(E', \mu \mid E).
  \label{def_pi}
\end{equation}
The multiplicity $M_r(E)$ may be constant, e.g., 1 for elastic scattering
and 2 for $(n, 2n)$ reactions, but the number of fission neutrons
depends on the incident energy~$E$.  The default is $M_r(E) = 1$.

\paragraph{Model weight}\label{Sec:model-weight}
The model weight is usually $w_r(E) = 1$, and that is the
default.  One exception is that data for a single outgoing neutron in
an $(n, 2n)$ reaction may have $M_r(E) = 2$ and $w_r(E) = 0.5$.
The model weight is also used to handle the use of different interpolation
rules over different ranges of incident energy.  Thus, if the interpolation
for $E_1 < E < E_2$ is different from that for $E_2 < E < E_3$,
the data may be split into two sets, one with
$$
  w_r(E) = \begin{cases}
    1 & \text{for $E_1 \le E < E_2$,}\\
    0 & \text{for $E_2 \le E \le E_3$,}
  \end{cases}
$$
and the other with
$$
  w_r(E) = \begin{cases}
    0 & \text{for $E_1 \le E < E_2$,}\\
    1 & \text{for $E_2 \le E \le E_3$.}
  \end{cases}
$$

The \xendl\ nuclear data consist
of tables of $\sigma_r(E)$ and $\pi_r(E', \mu \mid E)$ and possibly
$M_r(E)$ and~$w_r(E)$.
The data for $\pi_r(E', \mu \mid E)$ take several forms, and
the various data representations are dealt with individually.

The discretization of Eq.~(\ref{Boltzmann}) is based, first,
on the specification of a set of energy groups $\{ \calE_g
\}$ for the incident particles and energy groups $\{ \calE'_h
\}$ for the emitted particles.  The energy groups for
neutrons are typically different from those for gammas,
and yet another set is usually used for charged particles.
The flux $\phi(E, \Omega)$ inside the integral in
Eq.~(\ref{Boltzmann}) is discretized according to the energy
groups of the incident particle, while $\phi(E', \Omega')$
on the left-hand side of Eq.~(\ref{Boltzmann}) is discretized
according the the energy groups of the outgoing particles.
These energy groups are also called energy bins.

According to the normalization for Legendre expansions used in \xendl,
the angular discretization of $\pi_r$ in Eq.~(\ref{def_pi}) is
given by
\begin{equation}
  \pi_r( E', \mu \mid E) =
   \sum_{\ell = 0}^{\Lmax}
   \left(
     \ell + \frac{1}{2}
   \right)
   \pi_{r\ell}( E' \mid E) P_\ell( \mu)
  \label{def_pi_r}
\end{equation}
with $P_\ell( \mu)$ denoting the $\ell$-th Legendre polynomial
and
\begin{equation}
  \pi_{r\ell}( E' \mid E) =
  \int_{-1}^1 d\mu \, \pi_r( E', \mu \mid E) P_\ell( \mu)
  \label{def_piell}
\end{equation}
for $\ell = 0,$ 1, \ldots,~$\Lmax$.
The user may specify the order~$\Lmax$ with the command
given in Section~\ref{Sec:LegendreOrder}.

The flux $\phi(E, \Omega)$ in Eq.~(\ref{Boltzmann}) is expanded
into spherical harmonics
\begin{equation}
  \phi(E, \Omega) =
  \sum_{\ell, m}
    C_{\ell, m} \phi_{\ell, m}(E) Y_{\ell, m} (\Omega)
 \label{sphHarmonics}
\end{equation}
with normalization
$$
  C_{\ell, m} = \frac{1}{\int d\Omega \, [Y_{\ell, m} (\Omega)]^2}.
$$

A discrete approximation to Eq.~(\ref{Boltzmann}) may be obtained
by expanding $\phi(E, \Omega)$ in spherical harmonics and integrating
over the outgoing energy group~$\calE'_h$.
This gives an
equation for the vector of values
$$
  \phi_{\ell, m}(E'_h).
$$
Note that $\phi_{\ell, m}(E'_h)$ is a histogram with respect to
the energy $E'$ of the outgoing particle, constant on each energy
group~$\calE'_h$.
Integration of the
right-hand side of Eq.~(\ref{Boltzmann}) over $\calE'_h$ gives
\begin{equation}
  \calI_{h,\ell} = \sum_r
  \int_0^\infty dE \, \phi_{\ell, 0}(E)
  \int_{\calE'_h } dE' \, \int_{-1}^1 d\mu \,
  \calK_r(E', \mu \mid E) P_\ell( \mu ).
  \label{binnedBoltzmann}
\end{equation}
The integral Eq.~(\ref{binnedBoltzmann}) contains only the spherical
harmonics with $m = 0$, because the kernel $\calK_r$ is axisymmetric.

The unknown flux $\phi$ appears in Eq.~(\ref{Boltzmann})
both on the left-hand side of the equation and under
the integral sign.  It is therefore convenient to
start the calculation using an assumed approximate value of
$\phi_{\ell, 0}(E)$ in the integral Eq.~(\ref{binnedBoltzmann}), namely,
\begin{equation}
  \phi_{\ell, 0}(E) \approx
    \widetilde\phi_{\ell}(E).
  \label{approx_phi}
\end{equation}

Upon inserting Eq.~(\ref{approx_phi}) into Eq.~(\ref{binnedBoltzmann})
and taking the incident energy groups $\calE_g$ one at a time,
it is found that Eq.~(\ref{binnedBoltzmann}) may be viewed as the product
of a matrix with a column vector.  Here, the column vector has the
components $\phi_{\ell, 0}(E'_h)$, and the components of the matrix
are given by
$$
  \calJ_{g,h,\ell} = \frac{ \calI_{g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }
$$
with
$$
    \calI_{g,h,\ell} = \sum_r
     \int_{\calE_g} dE \, \widetilde \phi_\ell(E)
    \int_{\calE'_h } dE' \, \int_\mu d\mu \,
     \calK_r(E', \mu \mid E) P_\ell( \mu ).
$$
The quantities $\calJ_{g,h,\ell}$ constitute the entries of the \textit{transfer matrix}.

The above discussion gives one way of defining the transfer matrix,
but the \xndfgen\ code has three
different representations, depending
on whether one wants to conserve the number of particles,
the energy, or both.  Traditionally, conservation of particle
number has been used for neutron transport, conservation of energy
for gammas, and conservation of both energy and number for
charged particles.  These cases are taken up in turn.

\section{Conservation of particle number}
With the approximate flux coefficient $\widetilde\phi_\ell$ in Eq.~(\ref{approx_phi})
and the representation Eq.~(\ref{def_pi}) of the kernel $\calK_r$, the
$\ell$-th Legendre coefficient of the contributions of energy
groups $\calE_g$ and $\calE'_h$ to the integral
in Eq.~(\ref{Boltzmann}) by reaction $r$ is given by
\begin{equation}
  \Inum_{r,g,h,\ell} =
     \int_{\calE_g} dE \, \sigma_r ( E ) M_r(E) w_r(E) \widetilde \phi_\ell(E)
    \int_{\calE'_h } dE' \, \int_\mu d\mu \,
     P_\ell( \mu )
     \pi_r(E', \mu \mid E).
  \label{Inum}
\end{equation}
For conservation of particle number the elements of the transfer matrix
are the sums over all reactions,
\begin{equation}
  \calJ_{g,h,\ell} = \frac{ \sum_r \Inum_{r,g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }.
  \label{cons_num}
\end{equation}
The \gettransfer\ code computes the integrals $\Inum_{r,g,h,\ell}$
reaction by reaction, and the operation Eq.~(\ref{cons_num}) is performed
by \xndfgen.

Note that the number-preserving transfer matrices offer a
simple check.  Because the probability density
$\pi_r(E', \mu \mid E)$ has the normalization
$$
  \int_0^\infty dE' \, \int_{-1}^1 d\mu \,
     \pi_r(E', \mu \mid E) = 1,
$$
it follows from Eq.~(\ref{Inum}) that
\begin{equation}
  \sum_h \Inum_{r,g,h,0} =
    \int_{\calE_g} dE \, \sigma_r ( E ) M_r(E) w_r(E) \widetilde \phi_0(E).
  \label{rowSum}
\end{equation}

\section{Conservation of energy}
When conservation of energy is desired, the integral
Eq.~(\ref{Inum}) is modified by insertion of $E'$ as a weight factor
\begin{equation}
  \Ien_{r,g,h,\ell} =
     \int_{\calE_g} dE \, \sigma_r ( E ) M_r(E) w_r(E) \widetilde \phi_\ell(E)
    \int_{\calE'_h } dE' \, E' \int_\mu d\mu  \,
     P_\ell ( \mu )
     \pi_r(E', \mu \mid E).
  \label{Ien}
\end{equation}
With the notation that $\overline {E'_h}$ denotes the midpoint of
energy group $\calE'_h$, the elements of the transfer matrix
for energy conservation are the sums over all reactions,
\begin{equation}
  \widehat \calJ_{g,h,\ell} = \frac{ \sum_r \Ien_{r,g,h,\ell} }
       { \overline {E'_h} \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }.
  \label{cons_en}
\end{equation}
The computation of $\widehat \calJ_{g,h,\ell}$ in Eq.~(\ref{cons_en})
is done by \xndfgen\ using the integrals $\Ien_{r,g,h,\ell} $ calculated
by \gettransfer.

\section{Conservation of both particles and energy}
The \xndfgen\ code also has an option to combine the
integrals $\Inum_{r,g,h,\ell}$ in Eq.~(\ref{Inum}) and $\Ien_{r,g,h,\ell}$ in Eq.~(\ref{Ien})
so as to construct a transfer matrix which conserves both energy
and particle number.  Energy conservation may be violated
in the lowest and highest outgoing energy groups, however.
The construction is based on the following ideas.

There are two ways to compute the average energy of particles
in the outgoing energy group~$\calE'_h$.  One such average is the midpoint
$\overline {E'_h}$ of this group.  Preferably, this value should be
the same as the average energy
derived from the the sums over the reactions~$r$ of the
integrals Eqs.~(\ref{Ien}) and~(\ref{Inum}),
\begin{equation}
  \langle E' \rangle_{g,h} =
  \frac{ \sum_r \Ien_{r,g,h,0}}{ \sum_r \Inum_{r,g,h,0}}.
  \label{av_E}
\end{equation}
This is accomplished, as much as possible, by properly defining
entries of the transfer matrix corresponding to adjacent outgoing
energy groups.

For each
incident energy group $\calE_g$ one iterates through the
outgoing energy groups~$\calE'_h$.
Note that the description of this process in
\cite{Omega} and \cite{ndfgen} assumes that the energy group
boundaries decrease with increasing index;  the energy
group boundaries are counted in increasing order here and in \xndfgen.

If $\langle E' \rangle_{g,h} < \overline {E'_h}$ and $\calE'_h$
is not the lowest energy group, make a fraction of the
sum
$$
\frac{ \sum_r \Ien_{r,g,h,\ell} }
       { \overline {E'_h} \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }
$$
contribute to the transfer matrix element $\calJ_{g,h,\ell}$, and
make the remainder contribute to~$\calJ_{g,h-1,\ell}$.
Specifically, it is desired to find $j_{g,h}$
and $j_{g,h-1}$ which conserve particle number
$$
  j_{g,h} + j_{g,h-1} =
  \frac{ \sum_r \Inum_{r,g,h,0} }
       { \int_{\calE_g} dE \, \widetilde \phi_0(E) }
$$
as well as average energy
$$
  \overline {E'_h}\, j_{g,h} + \overline {E'_{h-1}}\, j_{g,h-1} =
    \sum_r \Ien_{r,g,h,0}.
$$
Therefore, set
$$
  f_{g,h} =
   \frac{ \langle E' \rangle_{g,h} - \overline {E'_{h-1}} }
    { \overline {E'_h} - \overline {E'_{h-1}} }.
$$
For each Legendre coefficient $\ell$ take as contribution to
$\calJ_{g,h,\ell}$ the quantity
$$
  j_{g,h} = \frac{ f_{g,h} \sum_r \Inum_{r,g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E)  },
$$
and the contribution to $\calJ_{g,h-1,\ell}$ is
$$
  j_{g,h-1} = \frac{ (1 - f_{g,h}) \sum_r \Inum_{r,g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }.
$$

If $\langle E' \rangle_{g,h} < \overline {E'_h}$ and $\calE'_h$
is the lowest energy group, the contribution to $\calJ_{g,h,\ell}$
is simply
$$
  \frac{ \sum_r \Inum_{r,g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }.
$$
This maintains conservation of particle number.

If $\langle E' \rangle_{g,h} > \overline {E'_h}$ and $\calE'_h$
is not the highest energy group, these data are used to calculate
contributions to the components $\calJ_{g,h,\ell}$ and $\calJ_{g,h+1,\ell}$
of the transfer matrix.  Specifically, set
$$
  f_{g,h} =
   \frac{ \overline {E'_{h+1}} - \langle E' \rangle_{g,h} }
    { \overline {E'_{h+1}} - \overline {E'_h }}.
$$
For each Legendre coefficient $\ell$ take as contribution to
$\calJ_{g,h,\ell}$ the quantity
$$
  j_{g,h} = \frac{ f_{g,h} \sum_r \Inum_{r,g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E) },
$$
and the contribution to $\calJ_{g,h+1,\ell}$ is
$$
  j_{g,h+1} = \frac{ (1 - f_{g,h}) \sum_r \Inum_{r,g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }.
$$

If $\langle E' \rangle_{g,h} > \overline {E'_h}$ and $\calE'_h$
is the highest energy group, the contribution to $\calJ_{g,h,\ell}$
is
$$
  \frac{ \sum_r \Inum_{r,g,h,\ell} }
       { \int_{\calE_g} dE \, \widetilde \phi_\ell(E) }.
$$

The sum of all of these contributions produces the Legendre
coefficients $\calJ_{g,h,\ell}$ of a transfer matrix which conserves
particle number as well as usually conserving energy.

\section{Control of the conservation option}
The \gettransfer\ code computes the integrals Eq.~(\ref{Inum})
for the number-preserving transfer matrix or the
integrals Eq.~(\ref{Ien}) for the energy-preserving transfer matrix
or both, depending on the value of the \texttt{Conserve}
input parameter.  See Section~\ref{Sec:conserveFlag}.
 The default mode is to
compute both integrals.  The actual construction
of the transfer matrix is performed by \xndfgen.

\section{Numerical quadrature}
The integrals Eqs.~(\ref{Inum}) and~(\ref{Ien}) require some sort
of numerical quadrature, and the multiple integrals are computed as
a sequence of single integrals.  The user may specify Gaussian quadrature
of various orders, as explained in Section~\ref{Sec:QuadratureMethods}.
The reason for the use of Gaussian quadrature in place of, say, Simpson's
rule, is that in the calculations here,
one of the limits of integration may be a computed quantity
such as a threshold energy.  In such cases, computer arithmetic may
give rise to attempts to evaluate $\pi_r(E', \mu \mid E)$
where this function is undefined.

The user may also specify whether or not to employ an adaptive
version of one of these Gaussian methods, using
a modification of the
adaptive quadrature method proposed by Gander and Gautschi~\cite{Gander}.
The default is to use adaptive quadrature---the non-adaptive version
is intended for debugging.  For an explanation of the quadrature options,
see Sections~\ref{Sec:QuadratureMethods} and~\ref{Sec:adaptive-quadrature}.

Another adaptation of the adaptive quadrature of the reference~\cite{Gander}
is that in the integrals Eqs.~(\ref{Inum}) and~(\ref{Ien}).

\textbf{Remark.} In the rest of this document the
subscript~$r$ is omitted from each of the terms in the kernel
Eq.~(\ref{def_pi}) and from the integrals
$\Inum_{r,g,h,\ell}$ and $\Ien_{r,g,h,\ell}$, because from now on the discussion will be
about the treatment of the data, reaction by reaction.


\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{setspace}

% Geometry
\usepackage{geometry}
\geometry{letterpaper, left=15mm, top=20mm, right=15mm, bottom=20mm}

% Fancy Header
\usepackage{fancyhdr}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}
\fancyhf{}
\chead{MAT 381 - Calculus 3}
\lfoot{CALU Spring 2021}
\rfoot{RDK}

% Add vertical spacing to tables
\renewcommand{\arraystretch}{1.4}

\onehalfspacing

% Macros
\newcommand{\definition}[1]{\underline{\textbf{#1}}}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

% Begin Document
\begin{document}

\section*{8.9 Improper Intgerals}

There are typically two types of improper integrals:

\begin{enumerate}

    \item The interval of integration is infinite \\
    $ \int_{1}^{\infty} \frac{1}{x^2} \,dx $

    \item The integrand is unbounded on the interval of integration \\
    $ \int_{-1}^{1} \frac{1}{x} \,dx $

\end{enumerate}

How do you find the integral $\int_{1}^{\infty} \frac{1}{x^2} \,dx$?

Consider the integral $\int_{1}^{b} \frac{1}{x^2} \,dx$, where $b > 1$ is an arbitrary real number.

Then we can write $\lim_{b\to\infty} \int_{1}^{b} \frac{1}{x^2} \,dx $

Changing the infinity to a variable, and then taking the limit of the integral to infinity allows for a possible solution.

\subsubsection*{Examples}

\begin{itemize}

    \item $ \int_{0}^{\infty} \frac{sin(x)}{x} \,dx = \lim_{b\to\infty} \int_{0}^{b} \frac{sin(x)}{x} \,dx $

    \item $ \int_{-\infty}^{1} \frac{e^x}{x^2} \,dx = \lim{a\to\infty} \int_{a}^{1} \frac{e^x}{x^2} \,dx $

\end{itemize}

\subsubsection*{Example}

Find, if possible: $ \int_{1}^{\infty} \frac{1}{x^2} \,dx $

\begin{enumerate}

    \item Rewrite as a limit \\ $\lim_{b\to\infty} \int_{1}^{b} \frac{1}{x^2} \,dx$

    \item Solve the integral first: \\
    \begin{equation*}
        \int_{1}^{b} \frac{1}{x^2} \,dx \\
        = -\frac{1}{x} \bigg\rvert_{1}^{b} \\
        = -\frac{1}{b} + 1
    \end{equation*}

    \item Then use that to find the limit: \\
    \begin{equation*}
        \lim_{b\to\infty} -\frac{1}{b} + 1 = -\frac{1}{\infty} + 1 = 0 + 1 = 1
    \end{equation*}

    \item Thus $ \int_{1}^{\infty} \frac{1}{x^2} \,dx = 1 $

\end{enumerate}

\begin{itemize}
    \item An interval is said to \definition{converge} when it goes to a finite value, and \definition{diverge} when it evaluates to an infinite value.
\end{itemize}

\subsection*{Examples, Infinite Integrals}

Evaluate the following integrals, or state if they if diverge.

\begin{enumerate}

    \item \begin{flalign*}
        &\int_{2}^{\infty} \frac{1}{x} \,dx &&\\
        &= \lim_{b\to\infty} \int_{2}^{b} \frac{1}{x} \,dx &&\\
        &= \lim_{b\to\infty}( \ln(x) \bigg\rvert_{2}^{b} ) &&\\
        &= \lim_{b\to\infty}( \ln(b) - \ln(2) ) &&\\
        &= \ln(\infty) - \ln(2) = \infty &&
    \end{flalign*}
    Therefore, the integral diverges.

    \item \begin{flalign*}
        &\int_{-\infty}^{0} e^{2x} \,dx &&\\
        &= \lim_{a\to-\infty} \int_{-a}{0} e^{2x} \,dx &&\\
        &= \lim_{a\to-\infty} (\frac{1}{2} e^{2x} \bigg\rvert_{a}^{0}) &&\\
        &= \lim_{a\to-\infty} ( \frac{1}{2} - \frac{1}{2e^{2a}} ) &&\\
        &= \frac{1}{2} - \frac{1}{2e^{2\infty}} &&\\
        &= \frac{1}{2} &&
    \end{flalign*}
    Therefore, the integral converges.

    \item \begin{flalign*}
        & \int_{-\infty}^{\infty} e^{4x} \,dx &&\\
        & = \int_{-\infty}^{0} e^{4x} \,dx + \int_{0}^{\infty} e^{4x} \,dx &&\\
        & \int_{-\infty}^{0} e^{4x} \,dx = \lim_{a\to\-\infty} ( \frac{1}{4} e^{4x} \bigg\rvert_{a}^{0}) &&\\
        & = \lim_{a\to-\infty} (\frac{1}{4} - \frac{1}{4}e^{4a}) = \frac{1}{4} &&\\
        & \int_{0}^{\infty} e^{4x} \,dx = \lim_{b\to\infty} ( \frac{1}{4} e^{4x} \bigg\rvert_{0}^{b}) &&\\
        & = \lim_{b\to\infty} (\frac{1}{4}e^{4b} - \frac{1}{4}) = \infty &&\\
        & = \int_{-\infty}^{0} e^{4x} \,dx + \int_{0}^{\infty} e^{4x} \,dx = \frac{1}{4} + \infty = \infty&&\\
    \end{flalign*}
    Therefore, the integral diverges.

\end{enumerate}

\end{document}


\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{titling}
\usepackage[table]{xcolor}
\usepackage{amsmath}
\usepackage{graphicx}
\graphicspath{{img/}}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{multirow}
\usepackage{array}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{lscape}
\usepackage{wrapfig}
\usepackage{lipsum}  % generates filler text
\usepackage{subcaption}
\usepackage{float}
\usepackage{amssymb}
\usepackage{url}
\usepackage{listings}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\usepackage[toc,page]{appendix}

\pretitle{\begin{center}\Huge\bfseries}
\posttitle{\par\end{center}\vskip 0.5em}
\preauthor{\begin{center}\Large\ttfamily}
\postauthor{\end{center}}
\predate{\par\large\centering}
\postdate{\par}

\title{THE EQUATIONS OF PLANETARY MOTION AND THEIR NUMERICAL SOLUTION}
\author{Jonathan Njeunje, Dinuka Sewwandi de Silva}
% \date{\today}

\begin{document}
\maketitle

\thispagestyle{empty}

\begin{abstract}
Each day we ask ourselves questions about the big universe and how this great "mechanics" function in such an incredible stability over the centuries. Some great minds of Earth's history, such as Isaac Newton worked on the theory of gravitation presented in the Principia, this stood to be a major contribution in answering this question. By utilizing the theory we will focus in setting up the differential equations that describe planetary trajectories in our solar system, linearizing these equations and providing their solution with the help of numerical method implemented from scratch.
\end{abstract}

\section{Introduction}

In our solar system, all the planets have an elliptic trajectory around the sun and the sun is also non-static and describes a motion about a reference origin, like portrayed on the figure below.
\\
\begin{figure}[H]
\centering
\includegraphics[width=0.6\textwidth]{Solar.jpg}
\caption{Solar System}
\label{fig:SolarSystem}
\end{figure}

% Figure~\ref{fig:SolarSystem}

Those elliptical motions (orbits) can best be figured out by understanding the general equation of planetary motion in the Cartesian co-ordinates system. Let us consider the following figure to best picture our scenario.

\begin{figure}[H]
\centering
\includegraphics[width=.9\textwidth]{cs.png}
\caption{Representation of two bodies under gravitational attraction in Cartesian co-ordinates}
\label{fig:cs}
\end{figure}

In this project we are going to derive the equations of planetary motion based on the assumption that the masses of the planets can be approximated to point masses. This is reasonable cue to the vast distances between bodies in the solar system.

Then, according to the \textit{Newton's law of gravitational force} acting on each of the masses we obtain the following.

\[\textbf{F} = G\frac{mm'}{r^2}({\hat{\textbf{r}}})\]
\[\textbf{F'} = G\frac{mm'}{r^2}({-\hat{\textbf{r}}})\]
\\
The respective components F\textsubscript{x}, F\textsubscript{y} and F\textsubscript{z}  of the force \textbf{F}, are:

\[ F_x = F\frac{x'-x}{r}; \]
\[ F_y = F\frac{y'-y}{r}; \]
\[ F_z = F\frac{z'-z}{r}. \]
\\
Furthermore, following \textit{Newton’s second law of dynamics} we obtain:

\[ F_x = m\frac{d^2 x}{dt^2}; \]
\[ F_y = m\frac{d^2 y}{dt^2}; \]
\[ F_z = m\frac{d^2 z}{dt^2}.  \]

\pagebreak

Combining both set of equations, we finally get:

\[ \frac{d^2 x}{dt^2} = Gm'\frac{x'-x}{r^3}; \]
\[ \frac{d^2 y}{dt^2} = Gm'\frac{y'-y}{r^3}; \]
\[ \frac{d^2 z}{dt^2} = Gm'\frac{z'-z}{r^3}. \]

\begin{equation}
\text{Where \textbf{r}, is given by: \space\space\space} r = \sqrt{(x'-x)^2+(y'-y)^2+(z'-z)^2}
\end{equation}

Where $G$ is a gravitational force and $m$ and $M$ are masses of the given planet and Sun respectively, $r$ is the distance between the planet and the Sun and $F$ is the force.

\pagebreak

\section{IVP - Initial Value Problem}
By using the general second order ordinary differential equation system of planetary motion we will now be able to discuss the dynamics of such a motion for all the planets in our solar system including the Sun. In order to reach this realization we designed a global system of equations, accounting for all the interactions of \textit{j} bodies of masses $m_{1},m_{2}...,m_{j}$ on a given body, $\alpha$ of mass $m_{\alpha}$.

Then our system of equation is:\\

$$\dfrac{d^{2}x_{\alpha}}{dt^{2}}=\sum_{j=1;j\neq\alpha}^{nb}Gm_{j}\dfrac{x_{j}-x_{\alpha}}{(r_{j,\alpha})^{3}}$$
$$\dfrac{d^{2}y_{\alpha}}{dt^{2}}=\sum_{j=1;j\neq\alpha}^{nb}Gm_{j}\dfrac{y_{j}-y_{\alpha}}{(r_{j,\alpha})^{3}}$$
$$\dfrac{d^{2}z_{\alpha}}{dt^{2}}=\sum_{j=1;j\neq\alpha}^{nb}Gm_{j}\dfrac{z_{j}-z_{\alpha}}{(r_{j,\alpha})^{3}}$$
$$r_{j,\alpha}=\sqrt[]{(x_{j}-x_{\alpha})^{2}+(y_{j}-y_{\alpha})^{2}+(z_{j}-z_{\alpha})^{2}}$$\\
where,\\
$nb$ - Number of bodies which we consider\\
$G$ - Constant of universal gravitation\\
$m_{j}$ - Mass of body $j$\\
$r_{j,\alpha}$ - Distance between body $j$ and body $\alpha$\\
$x_{\alpha},y_{\alpha},z_{\alpha}$ - Cartesian coordinates of body $\alpha$\\
$x_{j},y_{j},z_{j}$ - Cartesian coordinates of body $j$\\\\
We can convert this system of equations into a standard initial value problem in the following way:\\
$$Y=\begin{bmatrix}
x\\y\\z\\v_{x}\\v_{y}\\v_{z}
\end{bmatrix}=\begin{bmatrix}
x\\y\\z\\\dfrac{dx}{dt}\\\dfrac{dy}{dt}\\\dfrac{dz}{dt}
\end{bmatrix}$$
thus,\\
$$\dfrac{dY}{dt}=F(t,Y)\Rightarrow\dfrac{d}{dt}\begin{bmatrix}
x\\y\\z\\v_{x}\\v_{y}\\v_{z}
\end{bmatrix}=\begin{bmatrix}
v_{x}\\v_{y}\\v_{z}\\\sum_{j=1;j\neq\alpha}^{nb}Gm_{j}\dfrac{x_{j}-x_{\alpha}}{(r_{j,\alpha})^{3}}\\\sum_{j=1;j\neq\alpha}^{nb}Gm_{j}\dfrac{y_{j}-y_{\alpha}}{(r_{j,\alpha})^{3}}\\\sum_{j=1;j\neq\alpha}^{nb}Gm_{j}\dfrac{z_{j}-z_{\alpha}}{(r_{j,\alpha})^{3}}
\end{bmatrix}$$\\
where,\\
$G=6.67E^{-11} m^{3}kg^{1}s^{-2}$  \\
$nb := \text{number of bodies} = 10 $\\

\pagebreak

\begin{landscape}
After converting our $2^{nd}$ order system of ODE's to a $1^{st}$ order system of ODE's, system of equations, we needed a set of initial values for our subsequent ODE Solver. This set of initial states is obtained from the JPL (Jet Propulsion Lab) ephemeris database using the HORIZION web interface. This comprised of the initial states positions (both x y z co-ordinates) and velocities (both x y z co-ordinates), masses and mean radius of all 10 major bodies involved in our solar system.\\

The following table summarizes this initial states corresponding to the solar system configuration on April 6th, 2018:
\\\\\\\\\\\\\\\\
% Table generated by Excel2LaTeX from sheet 'IVP (Sec)'
\begin{table}[htbp]
  \centering
  \caption{Initial States from JPL HORIZONS System}
    \begin{tabular}{|c|l|r|r|r|r|r|r|r|r|}
\cmidrule{3-10}    \multicolumn{1}{r}{} &            & \multicolumn{3}{c|}{\cellcolor[rgb]{ .788,  .788,  .788}\textbf{POSITION (m)}} & \multicolumn{3}{c|}{\cellcolor[rgb]{ .788,  .788,  .788}\textbf{VELOCITY (m/sec)}} & \multicolumn{1}{l|}{\cellcolor[rgb]{ .788,  .788,  .788}\textbf{(kg)}} & \multicolumn{1}{l|}{\cellcolor[rgb]{ .788,  .788,  .788}\textbf{(m)}} \\
    \midrule
    \multicolumn{1}{|l|}{\textbf{\#}} & \textbf{BODY} & \multicolumn{1}{l|}{\textbf{PX}} & \multicolumn{1}{l|}{\textbf{PY}} & \multicolumn{1}{l|}{\textbf{PZ}} & \multicolumn{1}{l|}{\textbf{VX}} & \multicolumn{1}{l|}{\textbf{VY}} & \multicolumn{1}{l|}{\textbf{VZ}} & \multicolumn{1}{l|}{\textbf{MASS}} & \multicolumn{1}{l|}{\textbf{RADIUS}} \\
    \midrule
    \rowcolor[rgb]{ .851,  .882,  .949} 1          & SUN        & 1.81899E+08 & 9.83630E+08 & -1.58778E+07 & -1.12474E+01 & 7.54876E+00 & 2.68723E-01 & 1.98854E+30 & 6.95500E+08 \\
    \midrule
    2          & MERCURY    & -5.67576E+10 & -2.73592E+10 & 2.89173E+09 & 1.16497E+04 & -4.14793E+04 & -4.45952E+03 & 3.30200E+23 & 2.44000E+06 \\
    \midrule
    \rowcolor[rgb]{ .851,  .882,  .949} 3          & VENUS      & 4.28480E+10 & 1.00073E+11 & -1.11872E+09 & -3.22930E+04 & 1.36960E+04 & 2.05091E+03 & 4.86850E+24 & 6.05180E+06 \\
    \midrule
    4          & EARTH      & -1.43778E+11 & -4.00067E+10 & -1.38875E+07 & 7.65151E+03 & -2.87514E+04 & 2.08354E+00 & 5.97219E+24 & 6.37101E+06 \\
    \midrule
    \rowcolor[rgb]{ .851,  .882,  .949} 5          & MARS       & -1.14746E+11 & -1.96294E+11 & -1.32908E+09 & 2.18369E+04 & -1.01132E+04 & -7.47957E+02 & 6.41850E+23 & 3.38990E+06 \\
    \midrule
    6          & JUPITER    & -5.66899E+11 & -5.77495E+11 & 1.50755E+10 & 9.16793E+03 & -8.53244E+03 & -1.69767E+02 & 1.89813E+27 & 6.99110E+07 \\
    \midrule
    \rowcolor[rgb]{ .851,  .882,  .949} 7          & SATURN     & 8.20513E+10 & -1.50241E+12 & 2.28565E+10 & 9.11312E+03 & 4.96372E+02 & -3.71643E+02 & 5.68319E+26 & 5.82320E+07 \\
    \midrule
    8          & URANUS     & 2.62506E+12 & 1.40273E+12 & -2.87982E+10 & -3.25937E+03 & 5.68878E+03 & 6.32569E+01 & 8.68103E+25 & 2.53620E+07 \\
    \midrule
    \rowcolor[rgb]{ .851,  .882,  .949} 9          & NEPTUNE    & 4.30300E+12 & -1.24223E+12 & -7.35857E+10 & 1.47132E+03 & 5.25363E+03 & -1.42701E+02 & 1.02410E+26 & 2.46240E+07 \\
    \midrule
    10          & PLUTO      & 1.65554E+12 & -4.73503E+12 & 2.77962E+10 & 5.24541E+03 & 6.38510E+02 & -1.60709E+03 & 1.30700E+22 & 1.19500E+06 \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%
\end{landscape}

\pagebreak

\section{Numerical method description}
Before diving into writing and implementing our own numerical method of ODE Solver we needed to verify our designed IVP model of the solar system by existing and certified ODE solvers such as "ode45" and "ode113". These two solvers amongst many others where chosen for particular reasons we will discuss in the next section.\\

After simulating our IVP with the above solvers, we obtained positive results (discussed in the next section) validating our designed IVP model for the solar system.\\

The next step was to implement from scratch our own ODE solver and apply the designed IVP to it. We made the choice of implementing an \textbf{Explicit Runge-Kutta method (ERK)}. But before we could used this numerical method, we first needed to define our RK-stages $(\nu)$, RK-nodes $(c_{i})$, RK-weights $(b_{i})$ and RK-matrix $(A=[a_{ij}])$. And, verify its order of convergence, exactness and stability.
\\\\The general equations of an ERK is:\\
$$y_{n+1}=y_{n}+h\sum_{j=1}^{\nu}b_{j}f(t_n+c_{j}h,\xi_{j})$$
\\where\\
\indent$\xi_{1}=y_{n}$\\
\indent$\xi_{2}=y_{n}+ha_{2,1}f(t_{n},\xi_{1})$\\
\indent$\xi_{3}=y_{n}+ha_{3,1}f(t_{n},\xi_{1})+ha_{3,2}f(t_{n}+c_{2}h,\xi_{2})$\\
\indent\;\;\;\;\;\vdots\\
\indent$\xi_{i}=y_{n}+h\sum_{j=1}^{i-1}a_{i,j}f(t_n+c_{j}h,\xi_{j}),\;\;\;\;i=1,\ldots,\nu$\\
\\and $h$ is the step size of our time span. According to our designed IVP, $\xi_{i}$ will be a vector of $6*nb = 6*10=60$ elements. Similarly, $y_{n+1}$ also will be a vector of 60 elements.

\subsection{Definition of our RK method}
The chosen ERK for our implementation has the following parameters:

\[ \nu = 4\\ \]
\[ c = \begin{bmatrix}
	0 & .5 & .5 & 1
\end{bmatrix} \]
\[ b = \begin{bmatrix}
	1/6 & 1/3 & 1/3 & 1/6
\end{bmatrix} \]
\[ A=
  \begin{bmatrix}
    0 & 0 & 0 & 0 \\
    .5 & 0 & 0 & 0 \\
    0 & .5 & 0 & 0 \\
    0 & 0 & 1 & 0
  \end{bmatrix} \]
This method is identified as an Explicit Runge-Kutta method due to its lower triangular matrix, A. Additionally, to the above definition, the $\xi_{i}$'s are as follows:\\
\indent$\xi_{1}=y_{n}$\\
\indent$\xi_{2}=y_{n}+.5hf(t_{n},\xi_{1})=y_{n}+.5hf(t_{n},y_{n})$\\
\indent$\xi_{3}=y_{n}+.5hf(t_{n}+c_{2}h,\xi_{2})=y_{n}+.5hf\Big(t_{n}+.5h,y_{n}+.5hf(t_{n},y_{n})\Big)$\\
\indent$\xi_{4}=y_{n}+hf(t_{n}+c_{3}h,\xi_{3})=y_{n}+hf\Big(t_{n}+.5h,y_{n}+.5hf\Big(t_{n}+.5h,y_{n}+.5hf(t_{n},y_{n})\Big)\Big)$\\\\
By applying these $\xi_{i}$'s on the general ERK formula, we can predict order of convergence of this method.

\subsection{Order of convergence of the chosen RK}
The chosen ERK method defined in the previous subsection is of stage, $\nu=4$ and thus of order 4. This claim can further be verified by applying the ERK on the following IVP; applied under different values of the step size and interpreting the resultant graphs.\\

IVP: \space $y'(t)=-y$; \space $y_{0}=1$ when $t=0$\\

The ERK will by applied with step sizes: $h=.1/2^k$, \space with $k=1,2,3,4. $ \\

The exact solution for this IVP is known to be: $y(t)=e^{-t}$ \\

After running the written MatLab codes for this text, the following graphs were obtained:

\begin{figure}[!ht]
\centering
\includegraphics[width=1\textwidth]{testeer.png}
\caption{Error/Error-ratio test}
\label{fig:testeer}
\end{figure}

By inspecting the error-ratio plot on the right of the above figure we observe a trend:  $$\textrm{error-ratio}\rightarrow 16 = 2^4 = 2^p$$

This interpretation let us conclude that the order of convergence, $p=4$.\\\\
According to the definition of exactness, a given method is exact for the polynomials of degree less than or equal to $d$ , where $d$ is the degree of the exactness and usually it is equal to the order of the method. Therefore, the chosen ERK method is exact for the polynomials of degree less than or equal to 4. Because, 4 is the order of convergence of this ERK method.

Additionally, it can be interpreted from the errors bar chart that the ERK method of oder 4 is exact, as the error is in a close neighborhood of zero.

\subsection{verification of stability of the chosen RK}
The stability of RK method can be define according to the general equation of RK and the following equations. Then apply RK method for the following IVP.\\
$$y'=\lambda y$$
$$y(t_{0})=y_{0}$$
Now consider the equations for the $\xi$'s. In general its given by:\\
$$\xi_{k}=y_{n}+h\lambda\sum_{i=1}^{k}a_{k,i}f(t_n+c_{i}h,\xi_{i})$$\\
In this equation, $\sum_{i=1}^{k}a_{k,i}f(t_n+c_{i}h,\xi_{i})$ is a dot product of the $k^{th}$ row of the matrix $A$ and a vector of $\xi$. Let's define some vectors as follows,\\
$$\xi=\begin{bmatrix}
\xi_{1}\\\xi_{2}\\\vdots\\\xi_{\nu}
\end{bmatrix},\;\; b=\begin{bmatrix}
b_{1}\\b_{2}\\\vdots\\b_{\nu}
\end{bmatrix},\;\;\textbf{1}=\begin{bmatrix}
1\\1\\\vdots\\1
\end{bmatrix}$$
Then, the system of equations for $\xi$'s can be represented as;
$$\xi=y_{n}.\textbf{1}+h\lambda A\xi\Rightarrow \xi=(I-h\lambda A)^{-1}.\textbf{1}.y_{n}$$
By using this $\xi$ in the general equation of RK, we can be obtain,
$$y_{n}=(1+zb^{T}(I-zA)^{-1}\textbf{1})^{n}y_{0}\;\;\;where\;\;z=h\lambda$$
Then the stability domain of RK can be find when $\left|r(z)\right|<1$ where $r(z)=1+zb^{T}(I-zA)^{-1}\textbf{1}$.\\\\
By using above condition, can be find the stability domain of the chosen ERK, which is mentioned in subsection $(3.1)$. Therefore,\\\\
$I-zA=
  \begin{bmatrix}
    1 & 0 & 0 & 0 \\
    -.5z & 1 & 0 & 0 \\
    0 & -.5z & 1 & 0 \\
    0 & 0 & -z & 1
  \end{bmatrix} $ and $(I-zA)^{-1}=
  \begin{bmatrix}
    1 & 0 & 0 & 0 \\
    .5z & 1 & 0 & 0 \\
    .25z^{2} & .5z & 1 & 0 \\
    .25z^{3} & .5z^{2} & z & 1
  \end{bmatrix} $\\\\\\
  $b^{T}(I-zA)^{-1}\textbf{1}=\begin{bmatrix}
  1/6 & 1/3 & 1/3 & 1/6
  \end{bmatrix}\begin{bmatrix}
    1 & 0 & 0 & 0 \\
    .5z & 1 & 0 & 0 \\
    .25z^{2} & .5z & 1 & 0 \\
    .25z^{3} & .5z^{2} & z & 1
  \end{bmatrix}\begin{bmatrix}
  1 \\ 1 \\ 1 \\ 1
  \end{bmatrix}=1+\dfrac{z}{2}+\dfrac{z^{2}}{6}+\dfrac{z^{3}}{24}$\\\\
  $\Rightarrow r(z)=1+z\Big(1+\dfrac{z}{2}+\dfrac{z^{2}}{6}+\dfrac{z^{3}}{24}\Big)=1+z+\dfrac{z^{2}}{2}+\dfrac{z^{3}}{6}+\dfrac{z^{4}}{24}$\\\\
  By using Mathematica codes for $r(z)$, the following stability (shaded) region was obtained:\\

\begin{figure}[!ht]
\centering
\includegraphics[width=0.5\textwidth]{StabilityDomain.png}
\caption{Stability domain}
\label{fig:stability_domain}
\end{figure}

According to this stability region it can be concluded that, the chosen ERK method is not A-stable. Because, for a method to be A-stable it must include $\mathbb{C}^{-}$ in its stability region. Despite the fact that an
A-stability wasn't reached, necessary stability domain could be achieved. This achieved stability will be useful the next section.

\pagebreak

\section{Numerical Results and Discussion}
After a repeated set of simulations we made some adjustments regarding the number of planets considered and the step size to use with the different ODE Solvers.\\

The adjustment made on the number of planet consider, dealt with the non-consideration of planet Pluto. This adjustment was made in order to reduce the computational intensity of our code and enhanced faster calculations.\\

The second adjustment made on the step size, mainly had to constrain the step size to a value of 1. This adjustment was done to obtain better stability with our set of non-stiff ODE Solvers. Mainly, due to the fact that our IVP is a Stiff IVP, and, thereby necessitated (for more appropriate circumstances) a stiff ODE Solver with an A-stability region.\\

Nonetheless, with the appropriate adjustments, the following satisfactory results were obtained and interpreted as follows: \\

\subsection{\textit{Build-in ode45}}

The first ODE used was the ode45. This build-in MatLab ODE Solver was chosen to test the IVP model and make sure it is designed correctly. The result obtained, Fig~\ref{fig:Solar_System_-_ode45}, showed great instability of this ODE Solver due to the stiffness of the IVP. And, the added adjustment couldn't lead to better results.

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode45.png}
\caption{Solar System Simulation - ode45}
\label{fig:Solar_System_-_ode45}
\end{figure}

In the next figure, Fig~\ref{fig:Solar_System_-_ode45_-_ipsim}, we can observe the instability as the parameters of Mercury tend to decay much faster than that of the other planets. This behavior generated an error caused by the lack of better accuracy.

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode45_-_ipsim.png}
\caption{Solar System Simulation - ode45 - Inner planets }
\label{fig:Solar_System_-_ode45_-_ipsim}
\end{figure}

This ODE Solver couldn't complete the solution and crashed. The following figures show the plot of the distance from the different bodies to the reference point which in this case is not the sun but the origin.

\begin{figure}[H]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode45_-_ip.png}
\caption{Distance from origin - ode45 - Inner planet}
\label{fig:Solar_System_-_ode45_-_ip}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode45_-_op.png}
\caption{Distance from origin - ode45 - Outer planet}
\label{fig:Solar_System_-_ode45_-_op}
\end{subfigure}
\begin{subfigure}{.7\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode45_-_sun.png}
\caption{Distance from origin - ode45 - Sun}
\label{fig:Solar_System_-_ode45_-_sun}
\end{subfigure}
\caption{Distance from origin}
\label{fig:Solar_System_-_ode45_-_all}
\end{figure}

\pagebreak

\subsection{\textit{Build-in ode113}}
By observing from the previous method that the modeled IVP had stringent error tolerances, it was necessary to retry the test of the IVP with higher accuracy ODE Solver as ode113. The ode113 is also a MatLab build-in Solver. The figure, Fig~\ref{fig:Solar_System_-_ode113}, depicts the result obtained.

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode113.png}
\caption{Solar System Simulation - ode113}
\label{fig:Solar_System_-_ode113}
\end{figure}

This result had better stability and calculated a complete solution for a time span corresponding to the period of revolution of the planet Neptune (165 earth years). The result lead to a validation of the IVP model.

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode113_-_ipsim.png}
\caption{Solar System Simulation - ode113 - Inner planets }
\label{fig:Solar_System_-_ode113_-_ipsim}
\end{figure}

\begin{figure}[H]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode113_-_ip.png}
\caption{Distance from origin - ode113 - Inner planet}
\label{fig:Solar_System_-_ode113_-_ip}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode113_-_op.png}
\caption{Distance from origin - ode113 - Outer planet}
\label{fig:Solar_System_-_ode113_-_op}
\end{subfigure}
\begin{subfigure}{.7\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode113_-_sun.png}
\caption{Distance from origin - ode113 - Sun}
\label{fig:Solar_System_-_ode113_-_sun}
\end{subfigure}
\caption{Distance from origin}
\label{fig:Solar_System_-_ode113_-_all}
\end{figure}

\subsection{\textit{Implemented ERK of order 4, ode652}}
The final step was to build from scratch an ODE Solver to attain better (or similar) results as those obtained with  ode113.\\

The ODE Solver, ode652, coded on MatLab implemented the ERK of order 4 earlier described in the Numerical method section of this paper. This implementation achieved better stability compared to ode113 and ode45. A complete simulation of a time span equivalent to the period of the planet Neptune was obtained. Fig~\ref{fig:Solar_System_-_ode652}, shows this result and Fig~\ref{fig:Solar_System_-_ode652_-_ipsim}, shows a bigger scale of the inner planets of the solar system.

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode652.png}
\caption{Solar System Simulation - ode652}
\label{fig:Solar_System_-_ode652}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode652_-_ipsim.png}
\caption{Solar System Simulation - ode652 - Inner planets }
\label{fig:Solar_System_-_ode652_-_ipsim}
\end{figure}

The above figure and of the distances from the reference point below, clearly shows a more stable revolution of Mercury. This result is obtained by a solution made with better accuracy compared to those of ode113 and ode45.

\begin{figure}[H]
\centering
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode652_-_ip.png}
\caption{Distance from origin - ode652 - Inner planet}
\label{fig:Solar_System_-_ode652_-_ip}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode652_-_op.png}
\caption{Distance from origin - ode652 - Outer planet}
\label{fig:Solar_System_-_ode652_-_op}
\end{subfigure}
\begin{subfigure}{.7\textwidth}
\centering
\includegraphics[width=1\textwidth]{Solar_System_-_ode652_-_sun.png}
\caption{Distance from origin - ode652 - Sun}
\label{fig:Solar_System_-_ode652_-_sun}
\end{subfigure}
\caption{Distance from origin}
\label{fig:Solar_System_-_ode652_-_all}
\end{figure}

With this implementation the stability domain portrait by the chosen ERK of order 4, showed to sufficient (under certain adjustments) for the obtained solution.

\pagebreak

\section{Conclusion}
As a summary, the implemented method discussed in this paper is a non A-stable method. Nonetheless, this method had a stability region necessary and sufficient for our implementation. The modeled IVP mentioned under section 2 was analyzed to be stiff due to the existence of some its parameters who tend to grow faster than others (Mercury's). Thereby, higher stability needed to be reached for satisfactory result.\\

After, attempting solutions of the IVP with build-in MatLab ODE Solvers, we realized a very high error dependency of the IVP model. Due to this condition, the choice of implementing the ERK of order 4 was made appropriate because of the better accuracy/stability it provided under certain adjustments.\\

Finally, we were able to implement a method, ode652, with much more better stability than certain build-in MatLab methods, ode45 and ode113 of quite similar non A-stability behavior, to solve the modeled IVP of solar system dynamics.\\

\pagebreak

\lstset{language=Matlab,%
    %basicstyle=\color{red},
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{blue},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{mylilas},
    commentstyle=\color{mygreen},%
    showstringspaces=false,%without this there will be a symbol in the places where there is a space
    numbers=left,%
    numberstyle={\tiny \color{black}},% size of the numbers
    numbersep=9pt, % this defines how far the numbers are from the text
    emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
    %emph=[2]{word1,word2}, emphstyle=[2]{style},
}

\pagebreak

\begin{thebibliography}{9}

\bibitem{latexcompanion}
ARIEH ISERLES, University of Cambridge, (1992),
A First Course in the Numerical Analysis
of Differential Equations

\bibitem{NAZA}
NAZA, (2018), HORIZONS Web-Interface,
\\\url{https://ssd.jpl.nasa.gov/horizons.cgi#top}

\bibitem{InfoPlease}
InfoPlease, (2018), Basic Planetary Data,
\\\url{https://www.infoplease.com/science-health/solar-system/basic-planetary-data}

\bibitem{MATLAB}
MATLAB, (2018), Choose an ODE Solver - MATLAB and Simulink,
\\\url{https://www.mathworks.com/help/matlab/math/choose-an-ode-solver.html}

\bibitem{Wikipedia1}
Wikipedia, (25 October 2017), List of Runge–Kutta methods,
\\\url{https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods}

\bibitem{Guido}
Guido Kanschat, (May 2, 2018), Numerical Analysis of Ordinary Differential Equations,
\\\url{https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_methods}

\bibitem{Kyriacos}
Kyriacos Papadatos, (Unknown), THE EQUATIONS OF PLANETARY MOTION AND THEIR SOLUTION,
\\\url{http://gsjournal.net/Science-Journals/Research%20Papers-Astrophysics/Download/3763}

% \bibitem{Wikipedia1}
% Author, (Date), Title,
% \\\url{url}

\end{thebibliography}

\pagebreak

\begin{appendices}
\lstinputlisting{codes/ode652.m}
\end{appendices}

\end{document}