% Created 2016-02-05 Fri 09:42
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\providecommand{\alert}[1]{\textbf{#1}}

\title{Computerized control - homework 2}
\author{Kjartan Halvorsen}
\date{Due 2016-02-05}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs Org-mode version 7.9.3f}}

\begin{document}

\maketitle

\section*{Exercises}
\label{sec-1}
\subsection*{Sample the continuous-time transfer function}
\label{sec-1-1}

   Consider the harmonic oscillator with transfer function
   \begin{equation}
    G(s) = \frac{\omega^2}{s^2 + \omega^2}.
    \label{eq:contsys}
    \end{equation}

   \textbf{Compute the pulse-transfer function} by sampling the transfer function $G(s)$.
\subsection*{Simulation of the continuous- and discrete-time harmonic oscillator}
\label{sec-1-2}

Use matlab's control toolbox or the \href{http://python-control.sourceforge.net/}{python control module}  to simulate the system and verify your calculations.
\subsubsection*{Define systems}
\label{sec-1-2-1}

First, define the continuous-time system in \eqref{eq:contsys}

\begin{verbatim}
omega = 1; % Just a suggestion
h = 0.2/omega; % Completely undamped system. This gives about 30 samples per period
sys_c = tf([omega^2],[1 0 omega^2])
\end{verbatim}
Sample the system using the function \texttt{c2d}

\begin{verbatim}
sys_c2d = c2d(sys_c, h)
\end{verbatim}
Define the discrete-time system you calculated in the first part of the homework

\begin{verbatim}
den = [1 a1 a2];
num = [b1 b2];
sys_d = tf(num, den, h)
\end{verbatim}
\textbf{Verify that the two discrete-time systems} \texttt{sys\_c2d} \textbf{and} \texttt{sys\_d} \textbf{are identical.}
\subsubsection*{Simulate step responses}
\label{sec-1-2-2}

Simulate for 4 complete periods

\begin{verbatim}
Tc = linspace(0, 4*(2*pi/omega), 800);
[yc,tc] = step(sys_c, Tc);

Td = h*(0:120);
[yd,td] = step(sys_d, Td);

figure()
clf
plot(tc,yc)
hold on
plot(td,yd, 'r*')
\end{verbatim}

\textbf{Verify that the step response of the discrete-time system is exactly equal to that of the continuous-time system at the sampling instants. Explain why this is so!}
\subsubsection*{Compute the discrete step response yourself}
\label{sec-1-2-3}

    Write some lines of code that solves the difference equation
    \[ y(k+2) = -a_1y(k+1) - a_2y(k) + b_1u(k+1) + b_2u(k) \]
    for the harmonic oscillator.
   Use the initial state \(y(-1)=y(0)=0\) and compute the response to a step sequence
    \[ u(k) = \begin{cases} 1, & k \ge 0\\ 0, & \text{otherwise} \end{cases}.\]
    Verify that your solution is the same as when using the \texttt{step} function in the previous exercise in this homework.

\section*{Solutions}
\label{sec-2}
\subsection*{Sampling the transfer function}
\label{sec-2-1}

\begin{enumerate}
\item Calculate the step response
      \begin{equation*}
       \begin{split}
         Y(s) &= G(s)\frac{1}{s} = \frac{\omega^2}{(s^2 + \omega^2)s}\\
              &= \frac{1}{s} - \frac{s}{s^2 + \omega^2}.
       \end{split}
      \end{equation*}
\item Transform to time domain (using transform table)
      \[ y(t) = u(t) - u(t) \cos \omega t \]
\item Calculate z-transform of sampled output
      \begin{equation*}
       \begin{split}
        Y(z) &= \ztrf{y(kh)} = \ztrf{u(kh) - u(kh)\cos(\omega k h)}\\
             &= \ztrf{u(k)} - \ztrf{u(k)\cos(\omega hk)}\\
             &= \frac{z}{z-1} - \frac{z(z-\cos(\omega h))}{z^2 -2\cos(\omega h)z +1}
       \end{split}
      \end{equation*}
\item Divide by the z-transform of the step input
       \begin{equation*}
        \begin{split}
         H(z) &= \frac{Y(z)}{U(z)} = \frac{z-1}{z} \Big( \frac{z}{z-1} - \frac{z(z-\cos(\omega h))}{z^2 -2\cos(\omega h)z +1}\Big)\\
              &= 1 - \frac{(z-1)(z-\cos(\omega h))}{z^2 -2\cos(\omega h)z +1}\\
              &= \frac{z^2 - 2\cos(\omega h)z + 1 - z^2 +\cos(\omega h)z + z - \cos(\omega h)}{z^2 - 2\cos(\omega h)z + 1}\\
              &= \frac{\big(1-\cos(\omega H)\big)z + 1-\cos(\omega h)}{z^2 - 2\cos(\omega h)z + 1}.
        \end{split}
       \end{equation*}
\end{enumerate}
\subsection*{Simulations}
\label{sec-2-2}

   The code that is provided does most of the job. You just have to define the numerator and denominator of the discrete-time system from the sampled model you obtained:

\begin{verbatim}
a1 = -2*cos(omega*h);
a2 = 1;
b1 = 1-cos(omega*h);
b2 = b1;

den = [1 a1 a2];
num = [0 b1 b2];
sys_d = tf(num, den, h)
\end{verbatim}
\subsection*{Own code for simulating system response}
\label{sec-2-3}

   There are many ways to do this. Here is one

\begin{verbatim}
% Calculate the step response by hand
N = 120;
u = ones(N,1);
y = nan(N,1);
% Pad with two zeros at beginning, corresponding to u(-2), u(-1), y(-2) and
% y(-1)
u = [zeros(2,1); u];
y = [zeros(2,1); y];

for kplustwo = 3:N
    y(kplustwo) = -a1*y(kplustwo-1) -a2*y(kplustwo-2) + b1*u(kplustwo-1) + b2*u(kplustwo-2);
end

yd2 = y(3:end);
plot(td,yd2, 'ko', 'markersize', 14)
legend('Continous model', 'Discrete model', 'Own simulation')
\end{verbatim}

\begin{center}
\includegraphics[width=0.7\linewidth]{hw2-spring16-sim}
\end{center}

\end{document}


\chapter{Isotropic energy probability densities in the laboratory frame}
\label{Sec:isotropic-lab}
The \xendl\ library supports several formats for energy probability densities
which are isotropic in the
laboratory frame.  These data are typically used for equilibrium
reactions and for fission neutrons.  Because the outgoing
distribution is isotropic, the probability density
$\pi(\Elab', \mulab   \mid E)$ in Eq.~(\ref{def_pi}) takes the form
\begin{equation}
  \pi(\Elab', \mulab   \mid E) = \pi_0(\Elab' \mid E).
 \label{isotropic-pi}
\end{equation}
Consequently, for the number-conserving
matrices only the $\ell = 0$ Legendre order,
\begin{equation}
   \Inum_{g,h,0} =
     \int_{\calE_g} dE \, \sigma ( E ) M(E) w(E) \widetilde \phi_0(E)
   \int_{\calE_h'} d\Elab' \, \pi_0(\Elab' \mid E)
 \label{InumI4-0}
\end{equation}
needs to be computed,
and Eq.~(\ref{Ien}) for the energy-preserving transfer matrix becomes
\begin{equation}
   \Ien_{g,h,0} =
     \int_{\calE_g} dE \, \sigma ( E ) M(E) w(E) \widetilde \phi_0(E)
     \int_{\calE_h'} d\Elab' \, \pi_0(\Elab' \mid E) \Elab'.
 \label{IenI4-0}
\end{equation}

The data $\pi_0(\Elab' \mid E)$ may be given in \xendl\ either as
a table of values or as parameters in a function formula.
Because several of the function formulas for isotropic energy
probability densities are given in terms of incomplete gamma
functions, these are discussed first.  This is followed by a presentation
of the functional formulas for isotropic probability densities.  Then,
 the treatment of tables of~$\pi_0(\Elab' \mid E)$ for isotropic emission
 in the laboratory frame is discussed.  The section closes with
 the special treatment of the evaporation of delayed fission neutrons.

\section{Computational aspects of incomplete gamma functions}
Many
of the function formulas for $\pi_0(\Elab' \mid E)$ make use of the
lower incomplete gamma function
\begin{equation}
  \gamma(\kappa, x) =
   \int_0^x dt\, t^{\kappa - 1} e^{-t}
  \label{def-gamma}
\end{equation}
with $\kappa > 0$.  The upper incomplete gamma
function is
\begin{equation}
  \Gamma(\kappa, x) =
   \int_x^\infty dt\, t^{\kappa - 1} e^{-t},
  \label{def-Gamma}
\end{equation}
and they are related by
$$
  \gamma(\kappa, x) + \Gamma(\kappa, x) = \Gamma(\kappa) =
  \int_0^\infty dt\, t^{\kappa - 1} e^{-t}.
$$
In order to reduce the difficulties of computer round-off,
the formula
$$
  \int_a^b dt\, t^{\kappa - 1} e^{-t} =
  \gamma( \kappa, b ) - \gamma( \kappa, a )
$$
is used when $0 \le a < b \le 1$, and
$$
  \int_a^b dt\, t^{\kappa - 1} e^{-t} =
  \Gamma( \kappa, a ) - \Gamma( \kappa, b )
$$
is used when $1 \le a < b$.  Either form may be used when
$a < 1 < b$.

Note that even though it is possible to write down
exact formulas for $\gamma(\kappa, x)$ when $\kappa$ is a
positive integer, it is better not to use them in the computations.
For example, it is true that
$$
  \gamma(2, x) = 1 - (1 + x)e^{-x}.
$$
For values of $x$ near zero, this formula involves subtracting
from 1 a number very close to 1 to get a result close to~$x^2/2$.
This is may lead to bad round-off errors in the computer arithmetic,
and it is far better to
use the software for~$\gamma(2, x)$.

\section{Functional formulas for isotropic probability densities}
The functional formulas used in  \xendl\ for energy
probability densities~$\pi_0(\Elab' \mid E)$ are the evaporation model,
the Maxwell model, the Watt model, and the Madland-Nix model.
These models are discussed in turn.  For all of these models the
energy of the outgoing particle is in the laboratory frame.

\subsection{Evaporation model}
For the evaporation model the formula is
\begin{equation}
  \pi_0(\Elab' \mid E) = C \Elab' \expon{- \frac{\Elab'}{\Theta(E)}}
 \label{evaporationF}
\end{equation}
with $0 \le \Elab' \le E - U$.  The value of $C$ in Eq.~(\ref{evaporationF})
is chosen so that
$$
  \int_0^{E - U} d\Elab' \, \pi_0(\Elab' \mid E) = 1.
$$
That is,
$$
  C = \frac{1}{\Theta^2 \gamma(2, (E - U)/\Theta)}.
$$
The data consist of the energy of the reaction $U$ and pairs of
values $\{E, \Theta(E)\}$.  The 1-dimensional interpolation methods
of Section~\ref{Sec:1d-interp} are used to
determine the value of $\Theta$ for intermediate values of the
energy $E$ of the incident particle.

According to the comment on incomplete gamma functions above,
for the calculation of $\Inum_{g,h,0}$ on an outgoing energy bin,
$E_0 \le \Elab' \le E_1$ the expression
$$
  \int_{E_0}^{E_1} d\Elab' \, \pi_0(\Elab' \mid E) =
   C\Theta^2[\gamma(2, E_1/\Theta) - \gamma(2, E_0/\Theta)]
$$
is used when $E_0 \le \Theta$, and
$$
  \int_{E_0}^{E_1} d\Elab' \, \pi_0(\Elab' \mid E) =
   C\Theta^2[\Gamma(2, E_0/\Theta) - \Gamma(2, E_1/\Theta)]
$$
is used when $E_0 > \Theta$.  Analogously, for the
calculation of $\Ien_{g,h,0}$
$$
  \int_{E_0}^{E_1} d\Elab' \, \Elab' \pi_0(\Elab' \mid E) =
   C\Theta^3[\gamma(3, E_1/\Theta) - \gamma(3, E_0/ \Theta)]
$$
is used when $E_0 \le \Theta$, and
$$
  \int_{E_0}^{E_1} d\Elab' \, \Elab' \pi_0(\Elab'  \mid E) =
   C\Theta^3[\Gamma(3, E_0/\Theta) - \Gamma(3, E_1/\Theta)]
$$
is used otherwise.

\subsubsection{Input file data for the evaporation model}
The process identifier in Section~\ref{data-model} is\\
  \Input{Process: evaporation spectrum}{}\\
These data are always in the laboratory frame,\\
  \Input{Product Frame: lab}{}

One item of model-dependent data in Section~\ref{model-info}
is the value of $U$ used in defining the range of outgoing
energies $E$ in Eq.~(\ref{evaporationF}), and it is given by\\
  \Input{U:}{$U$}\\
The other input data are the values of $\Theta(E)$ in
Eq.~(\ref{evaporationF}) depending on the incident energy~$E$.
All of these energies, $U$, $E$, and $\Theta(E)$, must be in the same
units as the energy bins in Sections~\ref{Ein-bins} and~\ref{Eout-bins}.
The format for these data is\\
  \Input{Theta: n = $n$}{}\\
  \Input{Interpolation:}{interpolation flag}\\
with $n$ pairs of entries $\{E, \Theta(E)\}$.
The interpolation flag is one of those for simple lists as in
Section~\ref{interp-flags-list}.
For example, in units of MeV one may have\\
  \Input{U: 11.6890}{}\\
  \Input{Theta: n = 2}{}\\
  \Input{Interpolation: lin-lin}{}\\
  \Input{ 12.0 1.04135}{}\\
  \Input{ 20.0 1.04135}{}

\subsection{Maxwell model}
The formula for the Maxwell is
\begin{equation}
  \pi_0(\Elab'  \mid E) = C \sqrt{\Elab' } \, \expon{- \frac{\Elab' }{\Theta(E)}}
 \label{MaxwellF}
\end{equation}
for $0 \le \Elab'  \le E - U$.  This model is often used for fission neutrons.
The value of $C$ in Eq.~(\ref{MaxwellF}) is given by
$$
  C = \frac{1}{\Theta^{3/2} \gamma(3/2, (E - U)/\Theta)}.
$$
Because of round-off problems with small values of $x$,
it is unwise to use the mathematically equivalent formula
$$
  \gamma(3/2, x) =
  \frac{\sqrt{\pi}}{2}\, \erf{\sqrt{x}} - \sqrt{x}\,e^{-x}.
$$
The data consist of the energy of the reaction $U$ and pairs of
values $\{E, \Theta(E)\}$.  The parameter $\Theta$ is interpolated
by the methods of Section~\ref{Sec:1d-interp} to obtain intermediate values.

Depending on the value of $E_0/\Theta$,
the calculation of $\Inum_{g,h,0}$ on an outgoing energy bin
$E_0 \le \Elab'  \le E_1$ uses the expression
$$
  \int_{E_0}^{E_1} d\Elab'  \, \pi_0(\Elab'  \mid E) =
   C\Theta^{3/2}[\gamma({3/2}, E_1/\Theta) - \gamma({3/2}, E_0/\Theta)]
$$
or
$$
  \int_{E_0}^{E_1} d\Elab'  \, \pi_0(\Elab'  \mid E) =
   C\Theta^{3/2}[\Gamma({3/2}, E_0/\Theta) - \Gamma({3/2}, E_1/\Theta)].
$$
Analogously, the calculation of $\Ien_{g,h,0}$ uses either
$$
  \int_{E_0}^{E_1} d\Elab'  \, \Elab' \pi_0(\Elab'  \mid E) =
   C\Theta^{5/2}[\gamma({5/2}, E_1/\Theta) - \gamma({5/2}, E_0/\Theta)]
$$
or
$$
  \int_{E_0}^{E_1} d\Elab'  \, \Elab' \pi_0(\Elab'  \mid E) =
   C\Theta^{5/2}[\Gamma({5/2}, E_0/\Theta) - \Gamma({5/2}, E_1/\Theta)].
$$

\subsubsection{Input file data for the Maxwell model}
The process identifier in Section~\ref{data-model} is\\
  \Input{Process: Maxwell spectrum}{}\\
Again, this data is in the laboratory frame,\\
  \Input{Product Frame: lab}{}

One item of model-dependent data in Section~\ref{model-info}
is the value of $U$ used in defining the range of outgoing
energies $E$ in Eq.~(\ref{MaxwellF}), and it is given by\\
  \Input{U:}{$U$}\\
The other input data are the values of $\Theta(E)$ in
Eq.~(\ref{MaxwellF}) depending on the incident energy~$E$.
These energies, $U$, $E$, and $\Theta(E)$, must all be in the same
units as the energy bins in Sections~\ref{Ein-bins} and~\ref{Eout-bins}.
The format for such data is\\
  \Input{Theta: n = $n$}{}\\
  \Input{Interpolation:}{interpolation flag}\\
with $n$ pairs of entries $\{E, \Theta(E)\}$.
The interpolation flag is one of those for simple lists as in
Section~\ref{interp-flags-list}.
For example, in units of MeV one may have\\
  \Input{U: -20}{}\\
  \Input{Theta: n = 2}{}\\
  \Input{Interpolation: lin-lin}{}\\
  \Input{ 1.0e-11  1.28}{}\\
  \Input{ 20.0  1.28}{}

\subsection{Watt model}
Another model sometimes used for fission neutrons in \xendl\ is the Watt
formula
\begin{equation}
  \pi_0(\Elab'  \mid E) = C \sinh{\sqrt{b\Elab' }}\, \expon{- \frac{\Elab' }{a}}
 \label{WattF}
\end{equation}
for $0 \le \Elab'  \le E - U$.
The value of $C$ in Eq.~(\ref{WattF})
is given by
$$
  \frac{1}{C} =
  \frac{az\sqrt{\pi}}{2}\, \expon{z^2}
  \left(
    \erf{y - z} - \erf{y + z}
  \right) -
  a \expon{-y^2} \sinh{\sqrt{b(E - U)}}
$$
with $y = \sqrt{(E - U)/a}$ and $z = \sqrt{ab /4}$.
The data consist of the energy of the reaction $U$ and pairs of
values $\{E, a(E)\}$ and $\{E, b(E)\}$.  For intermediate incident
energies $E$, the parameters $b$ and~$a$ are interpolated by
the methods of Section~\ref{Sec:1d-interp}.

\subsubsection{Input file data for the Watt model}
The process identifier in Section~\ref{data-model} is\\
  \Input{Process: Watt spectrum}{}\\
This data is in the laboratory frame,\\
  \Input{Product Frame: lab}{}

One item of model-dependent data in Section~\ref{model-info}
is the value of $U$ used in defining the range of outgoing
energies $E$ in Eq.~(\ref{WattF}), and it is given by\\
  \Input{U:}{$U$}\\
The other input data are the values of $a(E)$ and $b(E)$ in
Eq.~(\ref{WattF}).
The energies, $U$, $E$, and $a(E)$, must be in the same
units as the energy bins in Sections~\ref{Ein-bins} and~\ref{Eout-bins},
and the units for $b(E)$ are the reciprocal of these units.
The format for these data is\\
  \Input{a: n = $n$}{}\\
  \Input{Interpolation:}{interpolation flag}\\
with $n$ pairs of entries $\{E, a(E)\}$ and\\
  \Input{b: n = $n$}{}\\
  \Input{Interpolation:}{interpolation flag}\\
with $n$ pairs of entries $\{E, b(E)\}$.
The interpolation flags for $a$ and $b$ are those for simple lists as in
Section~\ref{interp-flags-list}.
For example, with energies in MeV  one may have\\
  \Input{U: -10}{}\\
  \Input{a: n = 11}{}\\
  \Input{Interpolation: lin-lin}{}\\
  \Input{ 1.000000e-11    9.770000e-01}{}\\
  \Input{ 1.500000e+00   9.770000e-01}{}\\
  \Input{}{ $\cdots$}\\
     \Input{ 3.000000e+01 1.060000e+00}{}\\
  \Input{b: n = 11}{}\\
  \Input{Interpolation: lin-lin}{}\\
  \Input{ 1.000000e-11    2.546000e+00}{}\\
  \Input{ 1.500000e+00   2.546000e+00}{}\\
  \Input{}{ $\cdots$}\\
     \Input{ 3.000000e+01 2.620000e+00}{}

\subsection{Madland-Nix model}\label{Sec:Madland}

The Madland-Nix model~\cite{Madland} for prompt fission neutrons uses
the formula
\begin{equation}
  \pi_0(\Elab'  \mid E) = \frac{C}{2}\, [g(\Elab' , E_{FL}) + g(\Elab' , E_{FH})]
 \label{Madland-NixF}
\end{equation}
for
\begin{equation}
 0 \le \Elab' \le \texttt{maxEout},
 \label{Madland-Nix-E-range}
\end{equation}
where \texttt{maxEout} is one of the input parameters.
Note that the range of outgoing energies Eq.~(\ref{Madland-Nix-E-range})
is independent of the incident energy.
In fact, the \ENDF\ manual~\cite{ENDFB} gives no way for the data to specify the
maximum outgoing energy for the Madland-Nix model.

In Eq.~(\ref{Madland-NixF}) $E_{FL}$ is the average kinetic energy of the light fission
fragments, and $E_{FH}$ is the average kinetic energy of the heavy fission
fragments.  The function $g(\Elab' , E_F)$ in Eq.~(\ref{Madland-NixF}) is given in terms
of the parameters $T_m$ and
\begin{equation}
   u_1 = \frac{(\sqrt{\Elab' } - \sqrt{E_F})^2}{T_m}, \quad
   u_2 = \frac{(\sqrt{\Elab' } + \sqrt{E_F})^2}{T_m}
 \label{Madland-Nixu}
\end{equation}
by the formula
\begin{equation}
   g(\Elab' , E_F) = \frac{1}{3\sqrt{E_F T_m}}
   \left[
     u_2^{3/2}E_1(u_2) - u_1^{3/2}E_1(u_1) -
     \Gamma(3/2, u_2) + \Gamma(3/2, u_1)
   \right],
 \label{Madland-Nixg}
\end{equation}
where $E_1$ denotes the exponential integral
$$
  E_1(x) = \int_x^\infty dt\, \frac{1}{t}e^{-t}.
$$
It is clear from the definitions that
$$
  E_1(x) = \Gamma(0, x),
$$
but software to compute $\Gamma(\kappa, x)$ generally requires
that $\kappa$ be positive.
The data for the Madland-Nix model contains the average energies
$E_{FL}$ and $E_{FH}$ as well as pairs of values $\{E, T_m(E)\}$.
The interpolation rule for $T_m$ is also given.

If the range of outgoing energies is taken to be $0 \le \Elab'  < \infty$
in Eq.~(\ref{Madland-NixF}), then $C = 1$.  For other ranges of $\Elab' $
and for computation of $\Inum_{g,h,0}$, it follows from Eq.~(\ref{Madland-Nixg})
that it is necessary to compute integrals
\begin{equation}
 \calG_i( a, b ) =  \int_a^b d\Elab'  \, u_i^{3/2}E_1(u_i)
 \label{Madland-Nix-u-integral}
\end{equation}
and
\begin{equation}
 \calH_i( a, b ) =   \int_a^b d\Elab'  \, \Gamma(3/2, u_i)
 \label{Madland-Nix-Gamma-integral}
\end{equation}
with $i = 1$, 2.

The values of the integrals Eqs.~(\ref{Madland-Nix-u-integral})
and~(\ref{Madland-Nix-Gamma-integral}) are conveniently expressed
in terms of the parameters
\begin{equation}
  \alpha = \sqrt{T_m}, \quad
  \beta = \sqrt{E_F},
 \label{Madland-Nix-alpha-beta}
\end{equation}
\begin{equation}
  A = \frac{(\sqrt{a} + \beta)^2}{\alpha^2}, \quad
  B = \frac{(\sqrt{b} + \beta)^2}{\alpha^2},
 \label{Madland-Nix-A-B}
\end{equation}
and
\begin{equation}
  A' = \frac{( \beta - \sqrt{a})^2}{\alpha^2}, \quad
  B' = \frac{(\sqrt{b} - \beta)^2}{\alpha^2}.
 \label{Madland-Nix-A-B-prime}
\end{equation}

One might think it sufficient to calculate
$$
  \calG_i( 0, b )  \quad \text{and} \quad
  \calH_i( 0, b )
$$
in Eqs.~(\ref{Madland-Nix-u-integral}) and~(\ref{Madland-Nix-Gamma-integral})
and to use
\begin{equation*}
 \begin{split}
   \calG_i( a, b ) &= \calG_i( 0, b ) - \calG_i( 0, a ), \\
   \calH_i( a, b ) &= \calH_i( 0, b ) - \calH_i( 0, a )
 \end{split}
\end{equation*}
for $i = 1$, 2.  In fact, this approach is suitable only for $i = 2$.
The reason for the difficulty is seen from Eqs.~(\ref{Madland-Nixu})
and~(\ref{Madland-Nix-alpha-beta}), in that
\begin{equation}
  u_1^{3/2} = \begin{cases}
    (\beta - \sqrt{\Elab' })^3 / \alpha^3  \quad &\text{for $0 \le \Elab'  \le \beta^2$}, \\
    (\sqrt{\Elab' } - \beta)^3 / \alpha^3 \quad &\text{for $\Elab'  > \beta^2$}.
    \end{cases}
 \label{Madland-Nix-u1}
\end{equation}

Consequently, the integrals used to compute $\calG_i( a, b )$
and~$\calH_i( a, b )$ in Eqs.~(\ref{Madland-Nix-u-integral})
and (\ref{Madland-Nix-Gamma-integral}) are evaluated as
\begin{equation}
  \calG_1( a, \beta^2 ) =
    \frac{\alpha \beta}{2} \, \gamma \left( 2, A' \right)
       -\frac{2 \alpha^2}{5} \, \gamma \left( \frac{5}{2}, A' \right) +
       \left[
          \frac{2 \alpha \sqrt{A'}}{5} - \frac{\beta}{2}
        \right] \alpha {A'}^2 E_1( A' )
       \quad \text{for $0 \le a < \beta^2$},
\label{Madland-Nix-G1a}
\end{equation}
\begin{equation}
  \calG_1( \beta^2, b ) =
    \frac{\alpha \beta}{2} \, \gamma \left( 2, B' \right)
       + \frac{2 \alpha^2}{5} \, \gamma \left( \frac{5}{2}, B' \right) +
       \left[
          \frac{\beta}{2} + \frac{2 \alpha \sqrt{B'}}{5}
        \right] \alpha {B'}^2 E_1( B' )
       \quad \text{for $b > \beta^2$},
 \label{Madland-Nix-G1b}
\end{equation}
\begin{equation}
 \begin{split}
  \calG_2( 0, b )  = &
    \frac{2 \alpha^2}{5} \, \gamma \left( \frac{5}{2}, B \right) -
    \frac{\alpha \beta}{2} \, \gamma \left( 2, B \right) -
    \frac{\beta^5}{10 \alpha^3} \,e^{-B} + {}\\
      & \left[
        \frac{2 \alpha^2}{5} B^{5/2} - \frac{\alpha \beta}{2} {B}^2 +
          \frac{ \beta^5}{10 \alpha^3} \right]  E_1( B) - C_1
       \quad \text{for $b \ge 0$},
 \end{split}
\label{Madland-Nix-G2}
\end{equation}
\begin{equation}
  \calH_1(a, \beta^2) = 2 \alpha \beta \, \gamma \left( 2, A' \right) -
  \alpha^2 \, \gamma \left( \frac{5}{2}, A' \right) +
     (\beta^2 - a) \, \Gamma\left( \frac{3}{2}, A' \right)
     \quad \text{for $0 \le a < \beta^2$},
\label{Madland-Nix-H1a}
\end{equation}
\begin{equation}
  \calH_1(\beta^2, b) = 2 \alpha \beta \, \gamma \left( 2, B' \right) +
     \alpha^2 \, \gamma \left( \frac{5}{2}, B' \right) +
     (b - \beta^2) \, \Gamma\left( \frac{3}{2}, B' \right)
     \quad \text{for $b \ge \beta^2$},
\label{Madland-Nix-H1b}
\end{equation}
and
\begin{equation}
   \calH_2(0, b) = \alpha^2 \, \gamma \left( \frac{5}{2}, B \right) -
     2 \alpha\beta \, \gamma \left( 2, B \right) +
     \beta^2 \, \gamma \left( \frac{3}{2}, B \right) +
     b \, \Gamma \left( \frac{3}{2}, B \right) - C_2
     \quad \text{for $b > 0$}.
\label{Madland-Nix-H2}
\end{equation}
In the relations for $\calG_2(0, b)$ and $\calH_2(0, b)$ above, $C_1$
and~$C_2$ are constants of integration.

\begin{figure}
\input{fig5-1}
\end{figure}

In order to illustrate how the above integration formulas may be
derived, consider the case of Eq.~(\ref{Madland-Nix-G1b})
for $\calG_1( \beta^2, b )$ defined in
Eq.~(\ref{Madland-Nix-u-integral}) with $u_1$ as in
Eq.~(\ref{Madland-Nix-u1}) and with~$b > \beta^2$.  Substitution
of the definition of the exponential integral~$E_1$ gives the double
integral
$$
   \calG_1( \beta^2, b ) = \int_{\beta^2}^b d\Elab'  \,
      u_1^{3/2} \int_{u_1}^\infty dt \, \frac{1}{t} \, e^{-t}.
$$
The region of integration for this integral is the union of the
two shaded domains in Figure~\ref{Fig:Madland-Nix}.
The integral over the darker shaded region of Figure~\ref{Fig:Madland-Nix} is
$$
  J_{11} = \int_{\beta^2}^b d\Elab'  \, u_1^{3/2}\int_{u_1}^{B'} dt\, \frac { e^{-t}}{t}.
$$
Reversal of the order of integration transforms this integral to
$$
  J_{11} = \int_0^{B'} dt\, \frac{1}{t} \,e^{-t}
    \int_{\beta^2}^{(\alpha\sqrt{t} + \beta)^2}
       d\Elab' \, u_1^{3/2}.
$$
Under the substitution
\begin{equation*}
  \Elab'  = (\alpha \sqrt{u_1} + \beta)^2,
%  \label{u_for_E}
\end{equation*}
the inner integral takes the form
$$
  \int_{\beta^2}^{(\alpha\sqrt{t} + \beta)^2}
       d\Elab' \, u_1^{3/2} =
   \int_0^t du_1 \, u_1^{3/2}\left(
       \alpha^2 + \frac{\alpha\beta}{\sqrt{u_1}}
  \right) =
    \frac{2\alpha^2}{5}t^{5/2} + \frac{\alpha\beta}{2}t^2.
$$
Thus, it follows that the integral over the dark shaded region in
Figure~\ref{Fig:Madland-Nix} is
\begin{equation*}
  J_{11} =
    \frac{2\alpha^2}{5} \, \gamma(5/2, B') + \frac{ \alpha\beta}{2} \, \gamma(2, B').
%  \label{intJ11}
\end{equation*}
This relation gives the first two terms on the right-hand side
of Eq.~(\ref{Madland-Nix-G1b}).

The other terms on the right-hand side of Eq.~(\ref{Madland-Nix-G1b})
result from evaluation of the integral over the light shaded region in
Figure~\ref{Fig:Madland-Nix},
$$
J_{12} = \int_{\beta^2}^b d\Elab'  \, u_1^{3/2} \int_{B'}^\infty dt\, \frac {e^{-t}}{t}
 = \int_{B'}^\infty dt\, \frac{1}{t} \, e^{-t}
    \int_{\beta^2}^{b}
       d\Elab' \, u_1^{3/2}.
$$

\subsubsection{Input file data for the Madland-Nix model}
The process identifier in Section~\ref{data-model} is\\
  \Input{Process: Madland-Nix spectrum}{}\\
This data is in the laboratory frame,\\
  \Input{Product Frame: lab}{}

The model-dependent data in Section~\ref{model-info}
contains values of $E_{FL}$, the average kinetic energy of the
light fission fragment and $E_{FH}$, the average kinetic energy of the
heavy fission fragment.  These parameters are given by\\
  \Input{EFL:}{$E_{FL}$}\\
  \Input{EFH:}{$E_{FH}$}\\
The user must also specify a maximum outgoing energy
\texttt{maxEout} for use in Eq.~(\ref{Madland-Nix-E-range}).

The other input data are the values of $T_m$ as a function of
incident energy in
Eq.~(\ref{Madland-NixF}).  The format for these data is\\
  \Input{TM: n = $n$}{}\\
  \Input{Interpolation:}{interpolation flag}\\
with $n$ pairs of entries $\{E, T_m(E)\}$.
The interpolation flag is one of those for simple lists as in
Section~\ref{interp-flags-list}.
The energies, $E_{FL}$, $E_{FH}$, $E$, and $T_m(E)$, must be in the same
units as the energy bins in Sections~\ref{Ein-bins} and~\ref{Eout-bins}.
For example, in MeV units one may have\\
  \Input{EFL: 1.029979}{}\\
  \Input{EFH: 0.5467297}{}\\
  \Input{maxEout: 60}{}\\
  \Input{TM: n = 38}{}\\
  \Input{Interpolation: lin-lin}{}\\
  \Input{ 1.0000000e-11   1.0920640e+00}{}\\
  \Input{ 5.0000010e-01  1.1014830e+00}{}\\
  \Input{}{ $\cdots$}\\
  \Input{ 2.0000000e+01  1.1292690e+00}{}

\section{Energy probability density tables}\label{Sec:isotropicTables}
Another form of isotropic probability density data $\pi_0(\Elab'  \mid E)$
Eq.~(\ref{isotropic-pi}) in \xendl\ is in the form of tables.  The computation
of transfer matrices for such data given in the laboratory frame is
discussed here.  For data in the center-of-mass frame, this is a
special case of Legendre expansions discussed in Section~\ref{Ch:Legendre-cm}
with Legendre order zero.
For given
incident energies $E_i$, the data consist of pairs
$\{E_{k,j}', \pi_0(E_{k,j}' \mid E_k)\}$ as in Eq.~(\ref{EPtable}).
For such tabular data,
computation of the integrals $\Inum_{g,h,0}$ in Eq.~(\ref{InumI4-0})
and $\Ien_{g,h,0}$ in Eq.~(\ref{IenI4-0}) depends on the type
of interpolation used between
different incident energies.
The effects of the unit-base map Eq.~(\ref{unit-base-map}) are
discussed here.  The considerations are the same, whether the
unit-base map is used alone or as a component of interpolation
by cumulative points.

After the unit-base transformation Eq.~(\ref{unit-base-map})
the integrals Eqs.~(\ref{InumI4-0}) and~(\ref{IenI4-0}) take the form
\begin{equation}
   \Inum_{g,h,0} =
     \int_{\calE_g} dE \, \sigma ( E ) M(E) w(E) \widetilde \phi_0(E)
   \int_{\widehat\calE_h'} d\widehat \Elab'  \,
     \widehat\pi_0(\widehat \Elab'   \mid E)
 \label{InumhatI4-0}
\end{equation}
and
\begin{equation}
   \Ien_{g,h,0} =
     \int_{\calE_g} dE \, \sigma ( E ) M(E) w(E) \widetilde \phi_0(E)
   \int_{\widehat\calE_h'} d\widehat \Elab'   \,
     \widehat\pi_0(\widehat \Elab'   \mid E) \Elab'  .
 \label{IenhatI4-0}
\end{equation}
In these intergrals $\widehat\calE_h'$ denotes result of mapping the
outgoing energy bin $\calE_h'$ with the transformation Eq.~(\ref{unit-base-map}).
Furthermore, $\Elab'  $ in Eq.~(\ref{IenhatI4-0}) is to be obtained from $\widehat \Elab'  $
using the inverse unit-base mapping Eq.~(\ref{unitbaseInvert}).

\begin{figure}
\input{fig5-2}
\end{figure}

Figure~\ref{Fig:unit-base-region} illustrates the effect of
the unit-base map Eq.~(\ref{unit-base-map}).
For incident energies $E = E_{k-1}$ and~$E = E_k$,
1-dimensional interpolation is used
to produce data at a common set of unit-base outgoing energies
$\{\widehat E_j'\}$. In the left-hand
portion of Figure~\ref{Fig:unit-base-region}, suppose that
probability densities $\pi_0(\Elab'   \mid E)$ are given at incident energies
$E = E_{k-1}$ and~$E = E_k$ and at unit-base outgoing energies
 $\widehat E_{j-1}'$ and $\widehat E_j'$.
Then for this set of data, the range of
integration over $E$ in Eqs.~(\ref{InumhatI4-0}) or (\ref{IenhatI4-0}) requires
both that $E_{k-1} < E < E_k$ and that $E$ be in the bin~$\calE_g$.  The
outgoing energy~$\Elab'  $ is required to be in the bin~$\calE_h'$ and to satisfy
the constraint $\widehat E_{j-1}' < \widehat \Elab'   < \widehat E_j'$.

 The right-hand portion of Figure~\ref{Fig:unit-base-region}
shows a rectangle with vertices at $E = E_{k-1}$ and~$E = E_k$
and at $\widehat \Elab'   = \widehat E_{j-1}'$ and~$\widehat \Elab'   = \widehat E_j'$,
and data values $\widehat\pi_\ell(\widehat \Elab'   \mid E)$ are given at
these corners after any required interpolation in outgoing energy.
The values of $\widehat\pi_\ell(\widehat \Elab'   \mid E)$
interior to this rectangle are determined by interpolation.
The contribution of this potion of the data to the transfer matrix is obtained
by integrating Eqs.~(\ref{InumhatI4-0}) or (\ref{IenhatI4-0}) over the shaded
region in Figure~\ref{Fig:unit-base-region}.

\subsection{Input of isotropic energy probability tables}
\label{Sec:isotropic-table-lab}
The process identifier in Section~\ref{data-model} is\\
  \Input{Process: isotropic energy probability table}{}\\
This option permits either the center-of-mass or the laboratory frame.
For data in the laboratory frame, the command in
Section~\ref{Reference-frame} is\\
  \Input{Product Frame: lab}{}

The data as in Section~\ref{model-info}
for tables of isotropic energy probability densities is entered
in the format\\
  \Input{EEpPData: n = $K$}{}\\
  \Input{Incident energy interpolation:}{probability interpolation flag}\\
  \Input{Outgoing energy interpolation:}{list interpolation flag}\\
The interpolation flag for incident energy is one those used for
probability density tables in Section~\ref{interp-flags-probability},
and that for outgoing energy is one for simple lists.
This information is followed
by $K$ sections of the form\\
  \Input{Ein: $E$:}{$\texttt{n} = J$}\\
with $J$ pairs of values of $\Elab'$ and $\pi_E(\Elab'   \mid E)$.

An example with energies in eV of the model-dependent section of the input file for
isotropic energy probability density tables is\\
  \Input{EEpPData: n = 4}{}\\
  \Input{Incident energy interpolation: lin-lin unitbase}{}\\
  \Input{Outgoing energy interpolation: flat}{}\\
    \Input{ Ein:  1.722580000000e+07 : n = 34}{}\\
     \Input{\indent  0.000000000000e+00  0.000000000000e+00}{}\\
     \Input{\indent  1.000000000000e-08  0.000000000000e+00}{}\\
     \Input{\indent  1.778280000000e-08  2.766140000000e-07}{}\\
    \Input{\indent   3.162280000000e-08  4.918960000000e-07}{}\\
  \Input{\indent }{ $\cdots$}\\
     \Input{\indent  5.623410000000e-01  8.396540000000e-01}{}\\
     \Input{\indent  1.000000000000e+00  0.000000000000e+00}{}\\
  \Input{ $\cdots$}{}\\
  \Input{ Ein:  2.000000000000e+07 : n = 38}{}\\
     \Input{\indent  0.000000000000e+00  0.000000000000e+00}{}\\
     \Input{\indent  7.500000000000e-03  0.000000000000e+00}{}\\
     \Input{\indent  1.333710000000e-02  4.877750000000e-14}{}\\
    \Input{\indent   2.371710000000e-02  8.674000000000e-14}{}\\
  \Input{\indent  }{ $\cdots$}\\
   \Input{\indent  2.250000000000e+06  4.413810000000e-08}{}\\
    \Input{\indent   2.750000000000e+06  0.000000000000e+00}{}\\
Note that for these data it is not clear what should be used as the minimum outgoing energy.
In particular for incident energy $E_0 = 1.72258 \times 10^7$ eV,
it is not clear whether it is more reasonable to set $\Eminzero' = 0$ or $\Eminzero' = 1.77828
\times 10^{-8}$ eV in the unit-base interpolation.  The \gettransfer\ code uses $\Eminzero' = 0$,
to be consistent with Eq.~(\ref{Eout-ranges}).

\section{General evaporation of delayed fission neutrons}
For some fissionable targets, the energy spectra data for delayed
fission neutrons is represented in \xendl\ in the form
\begin{equation}
  \pi_0(\Elab'   \mid E) = g\left(\frac{\Elab'}{\Theta(E)}   \right).
 \label{general-evaporation}
\end{equation}
For this model, values of $\Theta$ are given as a function of~$E$,
and values of $g$ as a function of $x = \Elab'/\Theta(E)$.  In fact, all of the
general evaporation data in \xendl\ have $\Theta$ constant,
and the \gettransfer\ code requires that $\Theta$ be constant.
The isotropic probability density $\pi_0(\Elab'   \mid E)$ in
Eq.~(\ref{general-evaporation}) is then independent of~$E$.
In this case, the integrals
$\Inum_{g,h,0}$ in Eq.~(\ref{InumI4-0}) and $\Ien_{g,h,0}$ in Eq.~(\ref{IenI4-0})
needed for the transfer matrix become simply products of 1-dimensional
integrals
$$
   \Inum_{g,h,0} =
     \int_{\calE_g} dE \, \sigma ( E ) M(E) w(E) \widetilde \phi_0(E)
   \int_{\calE_h'} d\Elab'   \, g(\Elab' /\Theta  )
$$
and
$$
   \Ien_{g,h,0} =
     \int_{\calE_g} dE \, \sigma ( E ) M(E) w(E) \widetilde \phi_0(E)
     \int_{\calE_h'} d\Elab'   \, g(\Elab' /\Theta  ) \Elab'  .
$$

\subsection{Input of data for the general evaporation model}
For the general evaporation model, the process identifier in Section~\ref{data-model} is\\
  \Input{Process: general evaporation}{}\\
This data is in the laboratory frame,\\
  \Input{Product Frame: lab}{}

The model-dependent data in Section~\ref{model-info}
consist of pairs $\{E, \Theta(E)\}$ and of pairs
$\{x, g(x)\}$ with $x = \Elab'/\Theta$.  The format for these data is\\
  \Input{Theta: n = $n$}{}\\
  \Input{Interpolation:}{interpolation flag}\\
with $n$ pairs of entries $\{E, \Theta(E)\}$ and\\
  \Input{g: n = $n$}{}\\
  \Input{Interpolation:}{interpolation flag}\\
with $n$ pairs of entries $\{x, g(x)\}$.
In both cases, the interpolation flag is one of those for simple lists as in
Section~\ref{interp-flags-list}.
The $\Theta$ parameter is dimensionless, and the units for $E$ and~$x$
must be the same as those for the energy bins.
For example, in MeV one may have\\
  \Input{Theta: n = 2}{}\\
  \Input{Interpolation: lin-lin}{}\\
  \Input{1.0e-11   1.0}{}\\
  \Input{20.0      1.0}{}\\
  \Input{g: n = 185}{}\\
  \Input{Interpolation: lin-lin}{}\\
  \Input{ 0.0000000e+00   3.1433980e-01}{}\\
  \Input{ 1.0000000e-02   2.8124280e+00}{}\\
  \Input{ 2.0000000e-02   3.1373560e+00}{}\\
  \Input{ }{ $\cdots$}\\
  \Input{ 1.8400000e+00  0.0000000e+00}{}\


% Standard Article Definition
\documentclass[]{article}

% Page Formatting
\usepackage[margin=1in]{geometry}
\setlength\parindent{0pt}

% Graphics
\usepackage{graphicx}

% Math Packages
\usepackage{physics}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{mathtools}

% Code Def
\usepackage{listings}

% Section Heading Settings
\usepackage{enumitem}
\renewcommand{\theenumi}{\alph{enumi}}
\renewcommand*{\thesection}{Problem \arabic{section}}
\renewcommand*{\thesubsection}{\alph{subsection})}
\renewcommand*{\thesubsubsection}{\quad \quad \roman{subsubsection})}

%Custom Commands
\newcommand{\Rel}{\mathcal{R}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}

\newcommand{\toI}{\xrightarrow{\textsf{\tiny I}}}
\newcommand{\toS}{\xrightarrow{\textsf{\tiny S}}}
\newcommand{\toB}{\xrightarrow{\textsf{\tiny B}}}

\newcommand{\divisible}{ \ \vdots \ }
\newcommand{\st}{\ : \ }

% Theorem Definition
\newtheorem{definition}{Definition}
\newtheorem{assumption}{Assumption}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}

%opening

\title{MATH 5301 Elementary Analysis - Homework 9}

\author{Jonas Wagner}

\date{2021, November 5\textsuperscript{th}}

\begin{document}

\maketitle

% Problem 1 ----------------------------------------------
\section{}
Let $\norm{\cdot}_a$ and $\norm{\cdot}_b$ be two equivalent norms on $\R^n$.
\begin{definition}
    For $\norm{\cdot}_a, \norm{\cdot}_b$ on $S$,
    $\norm{\cdot}_a$ is said to be \underline{stronger} then $\norm{\cdot}_b$ if
    \[
        \forall \{x_n\} \subset S \st x_n \xrightarrow[d_a]{} x \implies x_n \xrightarrow[d_b]{} x
    \]
\end{definition}
\begin{definition}
    $\norm{\cdot}_a$ and $\norm{\cdot}_b$ are said to be \underline{equivalent},  $\norm{\cdot}_a \sim \norm{\cdot}_b$,
    if $\norm{\cdot}_a$ is stronger then $\norm{\cdot}_b$
    and $\norm{\cdot}_b$ is stronger then $\norm{\cdot}_a$.
    This means that
    \[
        \norm{\cdot}_a \sim \norm{\cdot}_b
            \iff \exists{\alpha,\beta \in \R_{>0}} :
            \forall_{x\in S} \alpha \norm{\cdot}_b \leq \norm{\cdot}_a \leq \beta \norm{x}_b
    \]
\end{definition}

%Part a
\subsection{Prove that if the set $A$ is closed in the $a$-norm, then it is closed in $b$-norm.}

\begin{definition}
    The set $A \subset V$ is called \underline{open} if
    $$\forall_{x\in A} \exists_{\epsilon>0} : B_\epsilon(x)\subset A$$
    or equivalently,
    \[\forall_{x \in A} \exists_{\epsilon>0} : \forall_{y \in V}\norm{x - y} < \epsilon \implies y \in A\]
\end{definition}
\begin{definition}
    The set $A \subset V$ is called \underline{closed} if $A^c$ is open.
\end{definition}

\begin{theorem}
    If the set $A$ is closed in the $a$-norm, then it is closed in $b$-norm.
    \begin{proof}
        Set $A$ being closed in $a$-norm implies $A^c$ is open in $a$-norm.
        \[\forall_{x \in A^c} \exists_{\epsilon_a>0} : \forall_{y \in S} \ \norm{x - y}_a < \epsilon_a \implies y \in A^c\]
        Additionally, since $\norm{\cdot}_a$ is equivalent to $\norm{\cdot}_b$ means thats
        \[\exists_{\alpha,\beta > 0} :
        \forall_{x\in S} \  \alpha \norm{\cdot}_b \leq \norm{\cdot}_a \leq \beta \norm{\cdot}_b\]
        Therefore, $\norm{x - y}_a \leq \beta \norm{x-y}_b$ and then
        \begin{align*}
            \forall_{x \in A^c} \exists_{\epsilon_a>0}
            &\st \forall_{y \in S} \ \norm{x - y}_a \leq \beta \norm{x - y}_b < \epsilon_a \implies y \in A^c\\
            \forall_{x \in A^c} \exists_{\epsilon_b>0} &\st \forall_{y \in S} \ \norm{x - y}_b < \epsilon_b \implies y \in A^c
        \end{align*}
        where $ \epsilon_b \geq \cfrac{\epsilon_a}{\beta}$
    \end{proof}
\end{theorem}

\newpage
%Part b
\subsection{Prove that if the set $A$ is compact in the $a-norm$ then it is compact in the $b$-norm.}
\begin{definition}
    Let $(S,d)$ be a metric space with $A \subset S$,
    \begin{enumerate}
        \item For $\{U_\alpha\}_{\alpha \in A}, \ U_\alpha \subset S$, is a \textbf{\underline{cover}} of the set $A$ if
        $$A \subset \bigcup_{\alpha\in A} U_\alpha$$
        \item A cover $\{U_\alpha\}_{\alpha \in A}$ of $A$ is an \textbf{\underline{open cover}} if $\forall_{\alpha \in A}$ $U_\alpha$ is an open set.
        \item $\{V_\beta\}_{\beta\in B}$ is called a \textbf{\underline{subcover}} of $\{U_\alpha\}_{\alpha \in A}$ if
        \begin{enumerate}
            \item $\{V_\beta\}_{\beta\in B}$ is a cover of $A$
            \item $\forall_{\beta \in B} \exists_{\alpha \in A} V_\beta = U_\alpha$
        \end{enumerate}
        \item A cover with a finite number of sets is called a \textbf{\underline{finite cover}}.
    \end{enumerate}
\end{definition}
\begin{definition}
    For $A \subset (S,d)$, $A$ is \textbf{\underline{compact}} if for every open cover of $A$ there exists a finite sub cover.
    Which is equivalent to saying all sequences within $A$ converge to a set point in $A$. (i.e)
    \[\forall_{{a_k}_{k\in \N}} \exists_{{a_{n_k}}} : a_{n_k} \to a \in A\]
\end{definition}
\begin{definition}
    A sequence $\{x_{n}\}$is called \underline{Cauchy} if
    \[
        \forall_{\epsilon>0} \ \exists_{N \in \N} \ \forall_{l_1,l_2 \geq N} \norm{x_{n_{l_1}} - x_{n_{l_2}}} < \epsilon
    \]
\end{definition}

\begin{theorem}
    If the set $A$ is compact in the $a$-norm, then it is compact in the $b$-norm.
    \begin{proof}
        Set $A$ being compact in $a$-norm means that every sequence in $A$ satisfies the Cauchy sequence property:
        \[
            \forall_{\epsilon>0} \ \exists_{N \in \N} \ \forall_{l_1,l_2 \geq N} \norm{x_{n_{l_1}} - x_{n_{l_2}}}_a < \epsilon
        \]
        Additionally, since $\norm{\cdot}_a$ is equivalent to $\norm{\cdot}_b$ means thats
        \[
            \exists_{\alpha,\beta > 0} : \forall_{x\in S} \ \alpha \norm{\cdot}_b \leq \norm{\cdot}_a \leq \beta \norm{\cdot}_b
        \]
        Therefore, $\norm{x - y}_a \leq \beta \norm{x-y}_b$ and then
        \begin{align*}
            \forall_{\epsilon_a>0} \ \exists_{N \in \N} \ \forall_{l_1,l_2 \geq N}
            &\norm{x_{n_{l_1}} - x_{n_{l_2}}}_a \leq \beta \norm{x_{n_{l_1}} - x_{n_{l_2}}}_b < \epsilon_a\\
            \forall_{\epsilon_b>0} \ \exists_{N \in \N} \ \forall_{l_1,l_2 \geq N}
            &\norm{x_{n_{l_1}} - x_{n_{l_2}}}_b < \epsilon_b
        \end{align*}
        where $ \epsilon_b \geq \cfrac{\epsilon_a}{\beta}$
    \end{proof}
\end{theorem}

% Problem 2
\newpage
\section{}
Consider the set $l^{\infty}$ of all real-valued sequences, endowed with the sup-norm: $\norm{l}_\infty = \sup_{n\in \N} \abs{l_n}$.

%Part a
\subsection{Prove that $l^\infty$ is complete.}

\begin{definition}
    A metric space is $(S,d)$ is a \underline{complete metric space} if every Cauchy sequence in $S$ converges.
\end{definition}
\begin{definition}
    The set $A$ in norm space is $(S,\norm{\cdot})$ is a \underline{complete} set if every Cauchy sequence in $A$ converges to a limit in $A$.
\end{definition}

\begin{definition}
    Let the set $l^\infty$ be the set of real-valued sequences:
    \[
        l^{\infty} := \qty{\{l_n\}_{n\in \N} \st l_n \in \R}
    \]
\end{definition}
\begin{definition}
    Let the norm space be defined as $(l^\infty, \norm{l}_\infty)$ where \[\norm{l}_\infty = \sup_{n\in\N} \abs{l_n}\]
\end{definition}

\begin{theorem}
    The set $l^\infty$ is complete.
    \begin{proof}
        Let $\{x_m\}$ denote any cauchy sequence in $l^\infty$, which is in $l^\infty$ by definition.
        For all $m\geq 1$, define
        \[
            l_m = \{x_1^{(m)}, x_2^{(m)}, \cdots\} \in l^\infty
        \]
        Clearly, $\forall_{j \in \R_{>0}}$ the sequence $\{x_j^{(m)}\}$ is a Cauchy sequence (in $\R$) therefore it converges to $x_j \in \R$.
        Since $\R$ is complete and $\forall {l_m \in l^\infty} \implies \lim_{m \to \infty} l_m = l$ where $l \in l^infty$, the set $l^\infty$ is complete (because all Cauchy sequences in $l^\infty$ converge within $l^\infty$).
    \end{proof}
\end{theorem}

%Part b
\subsection{Prove that $l^\infty$ is not compact.}

\begin{theorem}
    The set $l^\infty$ is not compact.
    \begin{proof}
        Set $l^\infty$ not being compact means that there exists an open cover $\{U_\alpha\}_{\alpha \in l^\infty}$ without a finite subcover.
        This can be proven by constructing an open cover that consists of an infinite set of subcovers.
        Let $l_m \in l^\infty$ be constructed with $m$ elements, i.e
        \[
            l_m = \{x_1^{(m)}, x_2^{(m)}, \cdots, x_m^{(m)}\} \in l^\infty
        \]
        An open cover $$\{U_\alpha\}_{\alpha \in A}$$ can then be constructed by an infinite number of sets
        \[
            V_\beta = \qty{l_m^{(\beta)}}_{m \in \{1, 2, \dots, \beta\}}
        \]
        Which can be constructed with each additional iteration with $\beta$ will increase the size of the $\{V_\beta\}_{\beta \in B}$ subcover, and will cover $l^\infty$ when taken to infinity, but is not finite.
        Therefore, the open cover $\{U_\alpha\}_{\alpha \in A}$ will not have an associated finite subcover; implying $l^\infty$ is not compact.
    \end{proof}
\end{theorem}

% Problem 3
\newpage
\section{}
Consider the set $\mathbb{B}([0,1],\R)$ of all bounded real-valued functions on the unit interval endowed with the sup-norm: $\norm{f}_\infty = \sup_{x \in [0,1]} \abs{f(x)}$. Denote the closed unit ball as $B_1 := \qty{f \in \mathbb{B}([0,1],\R) \st \norm{f}_\infty \leq 1}$.

%Part a
\subsection{Prove $B_1$ is closed.}
\begin{theorem}
    $B_1$ is the closed.
    \begin{proof}
        Set $B_1$ being closed implies $B_1^c$ is open.
        \begin{align*}
            \forall_{f \in B_1^c} \exists_{\epsilon>0} \st \forall_{g \in \mathbb{B}} \ \norm{f-g}_\infty < \epsilon &\implies g \in B_1^c\\
            \forall_{f \in \mathbb{B}} \norm{f}_\infty > 1 \exists_{\epsilon>0}\st \forall_{g \in \mathbb{B}} \ \norm{f-g}_\infty < \epsilon &\implies g \in \mathbb{B} \st \norm{g}_\infty > 1
        \end{align*}
        Additionally, since $\norm{f}_\infty > 1$ and $\norm{f-g}_\infty$ is bounded, the only way these are both true this must also be true: $\norm{g}_\infty > 1$.

        Alternatively, you can just recognize that and $f \in \mathbb{B}\st \norm{\cdot}_\infty > 1 \implies f \notin B_1 \implies f \in B_1^c$ which demonstrates $B_1^c$ is open, and therefore, $B_1$ is closed.
    \end{proof}
\end{theorem}

%Part b
\subsection{Prove that $B_1$ is bounded.}

\begin{theorem}
    $B_1$ is bounded, i.e.
    \[\exists_{N} \st \forall_{f \in B_1} \ \norm{f}_\infty < N\]
    \begin{proof}
        Since, by definition, $\norm{f} \leq 1$, $B_1$ is clearly bounded for any $N > 1$.
    \end{proof}
\end{theorem}

%Part c
\subsection{Prove that $B_1$ is not compact.}

\begin{theorem}
    $B_1$ is not compact.
    \begin{proof}
        $B_1$ not being compact is equivalent to saying
        \begin{align*}
            \lnot \qty(\forall_{{f_k}_{k\in \N}} f_k \in \mathbb{B} \st \exists_{{f_{n_k}}} : f_{n_k} \to f \in B_1)\\
            \exists_{{f_k}_{k\in \N}} f_k \in \mathbb{B} \st \forall_{{f_{n_k}}} : f_{n_k} \to f \notin B_1
        \end{align*}
    \end{proof}
\end{theorem}

% Problem 4
\newpage
\section{}
Let $\{V, \norm{\cdot}\}$ be a normed space.
Show that the function $f(x) = \norm{x} \st V \to \R$ is continuous on $V$.

\begin{definition}
    A function $f : (S_1,d_1) \to (S_2,d_2)$ is continuous on $S_1$ if
    \[
        \forall_{x\in S_1} \forall_{\epsilon>0} \exists_{\delta(x,\epsilon)>0} \forall_{y\in S_1} d_1(x,y) < \epsilon \implies d_2(f(x),f(y)) < \delta
    \]
\end{definition}

\begin{theorem}
    The function $f(x)$ is continuous on $V$, i.e.
    \[
        \forall_{x\in V} \forall_{\epsilon>0} \exists_{\delta(x,\epsilon)>0} \forall_{y\in V} \norm{x - y} < \epsilon \implies \abs{f(x) - f(y)} < \delta
    \]
    \begin{proof}
        \begin{align*}
            \forall_{x\in V} \forall_{\epsilon>0} \exists_{\delta(x,\epsilon)>0} \forall_{y\in V} \norm{x - y} < \epsilon
                &\implies \abs{\norm{x} - \norm{y}} < \delta\\
            \forall_{x\in V} \forall_{\epsilon_1>0} \exists_{\delta_2(x,\epsilon_1)>0} \forall_{y\in V} \norm{x - y} \leq \norm{x} + \norm{y} < \epsilon_1
                &\implies \abs{\norm{x} - \norm{y}}\leq \norm{x} + \norm{y} < \delta_2\\
            \forall_{x\in V} \forall_{\epsilon_1>0} \exists_{\delta_2(x,\epsilon_1)>0} \forall_{y\in V} \norm{x} + \norm{y} < \epsilon_1
                &\implies \norm{x} + \norm{y} < \delta_2\\
        \end{align*}
        which is clearly true, therefore $f(x) = \norm{x}$ is continuous on $V$.
    \end{proof}
\end{theorem}

% Problem 5
\newpage
\section{}
$(X,d_1)$ and $(Y,d_2)$ are two metric spaces.
Assume also that $Y$ is a vector space.
Construct and example of two continuous functions $f,g : X \to Y$ such that $f + g$ is discontinuous.

\begin{definition}
    Let $f : X \to Y$ be defined by
    \[
        f(x) :=
        \begin{cases}
            - x & x <0\\
            x & x > 0\\
            0 & x = 0
        \end{cases}
    \]
\end{definition}
\begin{definition}
    Let $g : X \to Y$ be defined by
    \[
        g(x) :=
        \begin{cases}
            x^2 & x \neq 0\\
            0 & x = 0
        \end{cases}
    \]
\end{definition}

\begin{theorem}
    Functions $f$ and $g$ are continuous, but $f + g$ is discontinuous.
    \begin{proof}

        \subsection{}
        \begin{lemma}
            $f$ is a continuous function.
            \begin{proof}
                \begin{align*}
                    \forall_{x \in X} \forall_{\epsilon > 0} \exists_{\delta(x, \epsilon)} \forall_{y \in X} \st d_1(x,y) < \epsilon
                        &\implies d_2(f(x), f(y)) < \delta\\
                        &\implies
                        \begin{cases}
                            d_2(-x, -y) < \delta &x < 0, y < 0\\
                            d_2(x, -y) < \delta & x > 0, y < 0\\
                            d_2(-x, y) < \delta & x < 0, y > 0\\
                            d_2(0, -y) < \delta & x= 0, y <0\\
                            d_2(0, y) < \delta & x = 0, y > 0\\
                            d_2(-x, 0) < \delta & x < 0, y = 0\\
                            d_2(x, 0) < \delta & x > 0, y = 0\\
                            d_2(0, 0) < \delta & x = 0, y = 0
                        \end{cases}
                \end{align*}
                All of which are clearly true for $d_2$ within a vector space.
            \end{proof}
        \end{lemma}

        \subsection{}
        \begin{lemma}
            $g$ is a continuous function.
            \begin{proof}
                \begin{align*}
                    \forall_{x \in X} \forall_{\epsilon > 0} \exists_{\delta(x, \epsilon)} \forall_{y \in X} \st d_1(x,y) < \epsilon
                        &\implies d_2(g(x), g(y)) < \delta\\
                        &\implies
                        \begin{cases}
                            d_2(x^2, y^2) < \delta &x \neq 0, y \neq 0\\
                            d_2(0, y^2) < \delta & x = 0, y \neq 0\\
                            d_2(x^2, 0) < \delta & x \neq 0, y = 0\\
                            d_2(0, 0) < \delta & x = 0, y = 0
                        \end{cases}
                \end{align*}
                All of which are clearly true for $d_2$ within a vector space.
            \end{proof}
        \end{lemma}

        \subsection{}
        \begin{lemma}
            $f + g$ is a discontinuous function.
            \begin{proof}
                Proof by contradiction, assume $f + g$ is continuous:
                \begin{align*}
                    \forall_{x \in X} \forall_{\epsilon > 0} \exists_{\delta(x, \epsilon)} \forall_{y \in X} \st d_1(x,y) < \epsilon
                        &\implies d_2(f(x) + g(x), f(y) + g(y)) < \delta\\
                        &\implies
                        \begin{cases}
                            d_2(-x + x^2, -y + y^2) < \delta &x < 0, y < 0\\
                            d_2(x + x^2, -y + y^2) < \delta & x > 0, y < 0\\
                            d_2(-x + x^2, y + y^2) < \delta & x < 0, y > 0\\
                            d_2(0, -y + y^2) < \delta & x= 0, y <0\\
                            d_2(0, y + y^2) < \delta & x = 0, y > 0\\
                            d_2(-x + x^2, 0) < \delta & x < 0, y = 0\\
                            d_2(x + x^2, 0) < \delta & x > 0, y = 0\\
                            d_2(0, 0) < \delta & x = 0, y = 0
                        \end{cases}
                \end{align*}
                however, in the cases when $x$ or $y$ are zero and the other is not, the statement of continuity is not always true due to a discontinuity immediately surrounding $x = 0$.
            \end{proof}
        \end{lemma}
    \end{proof}
\end{theorem}

% Problem 6
\newpage
\section{}
Construct an example of a sequence $\{f_n\}$ of nowhere continuous functions $[0,1] \to \R$ such that $f_n$ converge in the sup-norm to continuous functions.

\begin{definition}
    Let $\mathbb{NC}$ be defined as the sequence of all nowhere continuous functions from $[0,1] \to \R$, i.e
    \[
        \mathbb{NC} := \qty{
            f : [0,1] \to \R \st \forall_{x \in [0,1]} \exists_{\epsilon>0} \forall_{\delta(x,\epsilon)} \exists_{y \in [0,1]} \st 0 < \norm{x - y} < \delta \land \norm{f(x) - f(y)} \geq \epsilon
        }
    \]
\end{definition}
\begin{definition}
    Let $1_\Q : [0,1] \to \R$ be defined as the \underline{Dirichlet function} as the indicator for the set of rational numbers $\Q$, i.e
    \[
        1_\Q (x) :=
        \begin{cases}
            1 & x \in \Q\\
            0 & x \notin \Q
        \end{cases}
    \]
    which is a nowhere continuous function with the binary output of $1$ or $0$.
\end{definition}

\begin{definition}
    Let the sequence $\{f_n\} \in \mathbb{NC}$ be defined by
    \[
        \{f_n\}_{n\in\N} :=
        \qty{f_n \st f_n(x) = \qty(\frac{2}{n}) \qty(1_\Q (x) - 0.5)}
    \]
\end{definition}

\begin{theorem}
    Within the sup-norm, $\norm{l}_\infty = \sup_{n\in \N} \abs{f_n}$, the sequence of functions $\{f_n\}$ is continuous.
    \begin{proof}
        The definition of continuity for the sequence under the sup-norm is given as:
        \begin{align*}
            \forall_{x \in X} \forall_{\epsilon > 0} \exists_{\delta(x, \epsilon)} \forall_{y \in X} \st \norm{x - y} < \epsilon \
            &\implies \norm{f_n(x) - f_n(y)}_\infty < \delta\\
            &\implies \norm{f_n(x) - f_n(y)}_\infty \leq \norm{f_n(x)}_\infty + \norm{f_n(y)}_\infty < \delta_2\\
            &\implies \sup_{n\in \N} \abs{f_n(x)} + \sup_{n\in \N} \abs{f_n(y)} < \delta
        \end{align*}
        Since $\abs{f_n(x)}$ is clearly bounded from above by $frac{1}{n}$,
        $\sup_{n\in \N} \abs{f_n(x)} \leq \sup_{n\in \N} \frac{1}{n} = 1$,
        therefore, taking $\delta = 2$ results in the definition of continuity being satisfied for $f_n$ under the sup-norm.
    \end{proof}
\end{theorem}

\end{document}


\documentclass[../main.tex]{subfiles}

\begin{document}

\chapter{Background} \label{chapter:background}

This chapter describes the relevant theory behind software bug predictions and what the state of the art has been able to achieve.

\section{Machine Learning}

Machine learning can be defined as the study of algorithms that learn from a set of observed samples to predict values for unseen samples \cite{koza1996automated}. These algorithms have recently gained traction and become more applied in products and services due to the increase in computing power, availability of open source machine learning frameworks and vast amounts of data. Machine learning has become a popular approach for software defect prediction models as they eliminate the need for a programmer to explicitly set rules that identify a commit or file as being risky or not. Machine learning approaches can automatically spot patterns in data that may have been difficult for people to find, especially if the dimensionality of the input space is large. Some of the main challenges with these algorithms are to obtain substantial quantities of data and to ensure that the model's predictions are reliable.

In the context of software defect prediction, machine learning models are used to solve a binary classification problem. Classification involves taking samples of data and identifying their correct category (\textit{risky} or \textit{not risky}) given their features. There are various algorithms available for classification which differ by their mathematical formulations.

\subsection{Logistic Regression}

Logistic regression is a binary classification model that takes real valued inputs and returns their probability of belonging to one of two classes, 0 or 1. The logistic regression model makes predictions by applying the sigmoid function $\sigma(z) = \frac{1}{1+e^{-z}}$ upon a linear model $f(x) = x^T\theta$ (where $x$ is our input and $\theta$ is the model's parameters) \cite{bishop2006pattern}. When provided an input vector $x$, the function $\sigma(f(x))$ will predict the probability that $x$ belongs to the class 1 whereas $1-\sigma(f(x))$ computes the probability the class of $x$ is 0. The final label that is predicted is based on the most likely class, for example if the output of $\sigma(f(x)) > 0.5$, the predicted class is 1.

The optimal parameter for $\theta$ can be found using maximum likelihood estimation which aims to find the parameter $\theta$ that maximizes the likelihood $p(\textbf{t}|\theta)$ (where $\textbf{t}$ a vector containing output labels). Typically, this maximization problem is transformed into a minimization problem by taking the negative log of the likelihood. Then, iterative methods such as gradient descent can be used to obtain the optimal parameters.

\subsection{Decision Trees}

Decision trees are a type of tree-based model which classify inputs by using a set of conditional rules \cite{grzymala1993selected}. Every node in the decision tree represents a single conditional rule applied to an input feature, for example a dataset containing information about people could be split into two subsets by using the rule $Age < 30$. After a decision rule has been evaluated, the input is passed further down the tree along one of two possible branches. One heuristic algorithm used for creating a decision tree is ID3 which constructs a tree using a greedy, top-down approach \cite{quinlan1986induction}. Given a dataset $D$ and some features, ID3 chooses a feature that has not been included in the tree yet such that it provides the largest information gain. A decision rule is created upon this feature and this allows a dataset to be partitioned. The algorithm stops when all features are used up or when all elements of a partition have the same label.

\subsection{Ensemble Methods}

An issue with decision trees is that an individual tree can be very prone to overfitting the training data, resulting in a high variance model. In order to combat this, one can rely on ensemble techniques which involve combining multiple base models when training. One example of an ensemble learning technique is bagging which trains multiple classifiers independently and aggregates their outputs \cite{breiman1996bagging}. Given that we want to train $n$ models, bagging will randomly sample the training set and train a model on this sample so that each individual model has a different view of the data. A random forest model applies bagging by training $B$ decision trees. When a prediction has to be made for a classification task it aggregates the predictions by taking the majority value from each tree.

Boosting methods on the other hand involve sequential training of an ensemble of classifiers to convert weak classifiers (a model that does slightly better than random) into stronger ones \cite{sewell2008ensemble}. Unlike in bagging methods such as random forest, the classifiers are dependently trained on each other. When trained sequentially, subsequent models will attempt to correct upon previous learners by giving an increased weight to data points that the last model misclassified. Some examples of commonly used boosting methods applied upon decision trees are AdaBoost and XGBoost.

\subsection{K-Nearest Neighbours}

The K-nearest neighbours algorithm is another example of a non-parametric algorithm. To make a prediction for a new data point $x$, the algorithm must find the $k$ elements of the training set that are closest to $x$ \cite{cunningham2007k}. The proximity of points can be measured using distance metrics such as Euclidean distance or similarity metrics like the Pearson correlation \cite{jaskowiak2011comparing}. The predicted label for $x$ will then be the most frequent label among its k-nearest neighbours. In the case of a binary classification problem, $k$ should be chosen to be odd to guarantee that a majority label exists. When the labels of the dataset are imbalanced (such as in the case of defect prediction models), the algorithm might predict the dominant class more due to how frequently it occurs rather than because it is the correct label \cite{coomans1982alternative}. In this case, one can apply a weighted aggregation of the $k$ labels so that closer data points contribute more to the final prediction.

\subsection{Semi-Supervised Learning}

The majority of software defect prediction models are done using supervised learning where models are provided labelled datasets that they can learn from and make predictions for new data. Semi-supervised learning on the other hand relies on labelled and unlabelled data to train models. The motivation for semi-supervised approaches is that labelling data can be expensive, therefore, the idea is to use unlabelled data as much as possible together with limited labelled data.

According to \cite{chapelle2006semi}, in order for semi-supervised learning to be effective, there are several assumptions that have to be made. First of all, data points that are close to each other or form clusters should have a high probability of having the same label. This is because semi-supervised methods propagate labels from labelled instances to unlabelled instances. Also, it is required that points in higher dimensions need to be representable in lower dimensions in order for points to be able to considered close to each other.

\subsection{The Self-Training Algorithm} \label{section:selfTrain}

The self-training algorithm is a type of semi-supervised algorithm that can act as a wrapper method for any classifier \cite{triguero2015self}. When provided labelled and unlabelled data, the algorithm begins by training a classifier on the labelled data. It then makes predictions for the unlabelled data and if the classifier's prediction has a high probability, these predicted samples will be included in the training dataset. Then a model trains on this new dataset and these steps are repeated until the maximum number of iterations are reached or if the predictions for unlabelled data is identical to the previous iteration's predictions.

For the self-training algorithm, let us define the following. Let $X_L, y_L$ be our labelled inputs and outputs. $X_U$ is the unlabelled dataset and the model is defined as the function $f:X \rightarrow Y$. The parameters for the algorithm are $I \in \mathbb{N}$, the max number of iterations and $C \in \{c \in \mathbb{R} | 0 \leq c \leq 1\}$, the minimum confidence for a prediction on unlabelled data. The vairable $iter$ represents the current iteration and $y_{U\_old}$ is a local variable for storing the previous predictions. The variable $idx$ contains the indices of all unlabelled samples such that their probability of being either class is greater than the threshold $C$.

Some variations of this algorithm will move samples from $X_U$ and their predicted labels to the sets $X_L,y_L$. This version on the other hand samples does not remove entries from the unlabelled dataset.

\begin{algorithm} [H]
    \caption{Self-training algorithm \cite{zhu2007semi}}
    \label{algorithm:selfTrain}
    \begin{algorithmic}[H]
        \Procedure{Self-Train($X_{L}, y_{L}, X_{U}, I, C, ',f$)}{}
            \State $iter = 0$
            \State $f = f.fit(X_L, y_L)$
            \State $y_U = f.predict(X_U)$
            \State $y_{U\_old} =$ an empty array with same length as $y_U$

            \While{iter $<$ I and $|y_{U\_old}| == 0$ or $y_U \neq y_{U\_old}$}
                \State $y_{U\_old} = y_{U}$

                \State $idx = \{1 \leq i \leq len(y_U) | P(y_i=1) > C$  $\vee$ $P(y_i=0) > C\}$

                \State $X_{new} = \{x_i \in X_U | i \in idx\}$
                \State $y_{new} = \{y_i \in y_U | i \in idx\}$

                \State $f = f.fit(X_L.concat(X_{new}), y_L.concat(y_{new})$

                \State $y_U = f.predict(X_U)$

                \State iter = iter + 1

            \EndWhile
            \State return $f$
        \EndProcedure
    \end{algorithmic}
\end{algorithm}

One variation of this algorithm involves using no thresholds when adding the unlabelled data to the labelled data. One can also make predictions on a smaller batch of unlabelled rather than on all possible unlabeled data. As the algorithm works as a wrapper method to any base classifier, it is possible to make a direct comparison between a supervised learning algorithm and its self-trained counterpart. A risk with using this algorithm is that its performance could degraded if it spots an incorrect pattern early on and reinforces this on the unlabelled data.

\section{Evaluating Classification Models}

In order to verify that our models have performed well at a classification task, the models are evaluated on a test set and various performance measures are recorded. Below are metrics that describe the possible outcomes that can occur when making a prediction:

\begin{itemize}
    \item $TP=$ The number of true positives, instances belonging to the target class that were correctly identified

    \item $TN=$ The number of true negatives, instances belonging to the non-target class that were correctly identified

    \item $FP=$ The number of false positives, instances belonging to the non-target class that were misclassified as the target class

    \item $FN=$ The number of false negatives, instances belonging to the target class that were misclassified as the non-target class
\end{itemize}

In the context of software defect prediction, a false positive (FP) would describe a commit that was actually clean but predicted to be risky. A false negative (FN) would be a commit that was risky but classified as not risky. These four values can be used to reason about a model's performance and define further performance metrics.

\subsection{Accuracy, Precision, Recall and F1 score}

\vspace{20pt}

\begin{equation}
    Accuracy = \frac{TP+TN}{TP+TN+FP+FN}
\end{equation}

\vspace{10pt}

Accuracy represents the fraction of total data samples our model predicted correctly. However, if a dataset has a class imbalance (which software defect prediction datasets typically do), accuracy can be a misleading metric for performance. Since one of the classes would be underrepresented, the machine learning classifiers learn to simply predict the majority class label for every sample it sees. Take the following example, with a dataset of emails where 99\% are not spam and 1\% are spam, a classifier could achieve 99\% accuracy by labelling each email as not containing spam. However, this would lead to a very high number of false negatives and the classifier would not have actually learned what a spam email is. Therefore we rely on additional metrics such as precision and recall.

\begin{equation}
    Precision = \frac{TP}{TP+FP}
\end{equation}

\begin{equation}
    Recall = \frac{TP}{TP+FN}
\end{equation}

\vspace{20pt}

Precision in the context of software defect prediction is the fraction of instances that were correctly classified as defective relative to all instances that were deemed defective by the classifier. Recall is the fraction of correctly identified defects relative to the actual number of defective instances. Precision and recall are inversely proportional to each other, therefore as soon as a classifier aims to optimize recall, its precision will decrease and vice-versa.

\begin{equation}
    F1 = 2*\frac{precision*recall}{precision+recall}
\end{equation}

The F1 score aims to combine precision and recall into one metric using the harmonic mean so that one can optimize models towards having a good combination of both.

\begin{comment}
\subsection{Receiver Operating Characteristic Curves}

The Receiver Operating Characteristic (ROC) curve is an indication of how well the model can tell apart various classes at various thresholds. By default, a classifier such as logistic regression sets its threshold at 0.5, if the output is greater than 0.5 then we assign an instance to one class and if it is lower than 0.5 it gets assigned to the other class. However, one can vary this threshold in order to deal with situations where the cost behind a false negative is not equally weighted with the cost of a false positive (for example, letting a bug go unnoticed versus a developer spending time reviewing supposedly faulty code that is actually clean).

\begin{figure}[H]
\centering
\includegraphics[scale=0.45]{images/Background/roc_cases.png}
\label{fig:roc}
\caption{The possible cases for the ROC-AUC \cite{rocCases}}
\end{figure}

The ROC curve plots the false positive rate (FPR) and the true positive rate (TPR), also referred to as the recall. To quantify the performance of the classifier for various thresholds, the Area Under Curve (AUC) metric is used. As seen in figure \ref{fig:roc}, ideal classifiers have $AUC = 1$ because their true positive rate is 1 regardless of the false positive rate. In the worst case, the $AUC = 0.5$ and this indicates that model cannot distinguish between the two classes. When the $AUC$ is less than 0.5, this indicates that the model is able to distinguish between the two classes but the labels are swapped.

\subsection{Precision-Recall Curves}

According to Davis \cite{davis2006relationship}, an issue with ROC curves is that they are insensitive to class imbalance. Because of this, a high ROC-AUC value can be misleading when measuring the performance of software defect prediction models. Davis suggests that one should also rely on precision-recall curves which plot the precision and recall of a classifier for various thresholds. Similar to ROC curves, one can compute the AUC of these curves to get an aggregate measure of how well the model performs.

\end{comment}

\subsection{K-fold Cross Validation}

K-fold cross validation is a statistical method for generalizing a model's performance to unseen data \cite{kale2011cross}. Cross validation has two main roles, the first being for model selection during training and the second is for evaluating a model's final performance. K-fold cross validation involves splitting up a dataset into $k$ partitions such that a classifier trains on $k-1$ of the partitions and is evaluated on the remaining set (designated the test set). When performing model selection, a dataset will typically be split into a training, validation and test set. The validation set is used to tune the hyperparameters of a model whereas the test set is used for a final evaluation.

A benefit of using cross validation is that it reduces bias and error when estimating the classifier's true performance. However, there is criticism for using cross validation as an evaluation method for software defect predictions. This is because a model may end up using future knowledge by training on samples that occurred later in time than those in the test set \cite{tan2015online}.

\subsection{Metrics for Semi-Supervised Classifiers}

When evaluating the semi-supervised classifier, one can measure how well the model's predictions are for unlabelled data it used during training. One can define the reconstruction accuracy as the fraction of unlabelled instances from the training set that the self-training algorithm provided correct predictions for. Since the self-training algorithm runs for several iterations, this reconstruction accuracy is computed once the algorithm has terminated. Also, each iteration the algorithm can technically make a prediction for the same instance if the prediction never meets the confidence threshold, thus never being transferred from the unlabelled training set to the labelled training set. Therefore the predictions that will be considered in the reconstruction error are those that were added to the labelled training set. Similarly, one can define the reconstruction precision and reconstruction recall in order to investigate if there are discrepancies between the correctness of labels for the two classes.

\section{Related Work}

This section outlines some of the past achievements in the field of software defect prediction and the various techniques that were used.

\subsection{Software Defect Prediction}

The purpose of software defect prediction is to predict the likelihood of a defect within software. The proposed benefit of these models would be to assist software developers with bug detection and to prioritize testing efforts \cite{briski2008minimizing}. The general process for constructing software defect prediction models begins with obtaining a dataset that labels files or commits as \emph{risky} or \emph{not risky} (a risky commit is defined as a commit that will produce a bug). Then for each instance in the dataset (a commit or file), various features such as McCabe complexity or lines of code are computed \cite{zhang2007predicting}. The features and labels are then used to train a supervised machine learning classifier and finally, the model can be used to make predictions for new instances.

When building defect prediction models, there are various input features one could use. one could provide metadata concerning files or commits such as lines of code added or the number of developers working on a particular file. One could also use text based features such as commit messages or comments which can be encoded using a bag-of-words representation. One could also parse the source code itself with abstract syntax trees which can be encoded as vectors \cite{tan2015online}.

%TODO \subsubsection{File Level Defect Prediction}

\subsection{SZZ Algorithm}

In order to build defect prediction models, one requires labelled data that indicates whether or not a file or commit contains a bug or not. However in practice, this information may not always be available and manually labelling commits is time consuming. Research in defect prediction models have benefited greatly from the Sliwerski Zimmermann Zeller (SZZ) algorithm, originally described in the paper \textit{"When do changes induce fixes?"} \cite{sliwerski2005changes}. The focus of the paper was limited to identifying bug inducing commits rather than creating defect prediction models but their labelling algorithm is valuable for automatically labelling a large number of commits.

\begin{algorithm}
\caption{SZZ: labels commits as \textit{risky} or \textit{not risky} \cite{sliwerski2005changes}}
\label{algorithm:szz}
    \begin{algorithmic}[1]
    \Procedure{SZZ()}{}
        \State $\texttt{keywords}=\{"bug","fix"\}$
        \State \texttt{commits} = a list of all commits in a repository
        \State \texttt{bugFixCommits} = $\{\texttt{c :c} \in \texttt{commits}\texttt{ and }\texttt{containsKeyword(c.message)}\}$
        \State \texttt{result =} $\emptyset$
        \For{\texttt{i = 1 to length(bugFixCommits)}}
                \State \texttt{bugFixCommit = bugFixCommits[i]}
                \State \texttt{filesTouched = getFilesTouched(bugFixCommit)}
                \State \texttt{linesTouched = getLinesTouched(bugFixCommit, filesTouched)}
                \State \texttt{result = result $\cup$ getBlame(filesTouched, linesTouched)}
        \EndFor

        \State \texttt{return result}
    \EndProcedure
    \end{algorithmic}
\end{algorithm}

The algorithm works by initially locating commits that fix a bug. This can be done by filtering commits by their message or comments for keywords such as "bug" or "fix". Those commits are then cross referenced with a bug tracking database in order to confirm that these commits do resolve a bug. For each bug fixing commit, the files this commit touched as well as the exact lines changed within those files are computed using the \texttt{diff} command in a version control system (such as CVS or Git). One can then use the \texttt{blame} or \texttt{annotate} command to find the previous commit responsible for causing a patch to be created. This previous commit becomes labeled as a bug causing commit. A variant of this algorithm denoted Approximate SZZ follows the same essential steps but does not rely on a bug tracking database for identifying bug fixing commits. Since not all projects use a bug tracking database, using the ASZZ algorithm would allow defect prediction models to train on more data.

%SZZ revisited: verifying when changes induce fixes, Jaime Spacco (2008)) Claims that no one has previously verified the reliability of the SZZ algorithm. Outlines several improvements to SZZ, replace annotation graphs with line number maps, use DiffJ to ignore comments and formattinf changes in soure. Then finally verify that SZZ identified the correct changes. Manually select 25 bug fixing commits random commits from 37,000 commits of the Eclipse projects. These 25 commits changed 50 lines in total. Only 43 of the 50 changed lines actually fix a bug. (They evaluate reliability of finding bug-fix commits).

\subsection{File Level Defect Prediction }

In their work, Meng Yan et al. investigate the claim that unsupervised models may outperform supervised models for providing effort-aware defect predictions on the file level \cite{yan2017file}. They replicate a previous study upon the PROMISE dataset and their main finding was that unsupervised models can outperform supervised models for cross project prediction but not for within project predictions.

In Personalized Defect Prediction, the authors propose creating defect prediction models that are tailored to individual developers \cite{jiang2013personalized}. The motivation for this is the fact that developers exhibit varying coding patterns and styles and the number of bugs introduced can depend upon the experience the developer has. Results found that this method can improve a model's F1 score by 0.01-0.06.

Song Wang et al. apply a Deep Belief Network upon the file-level changes of software projects \cite{wang2016automatically}. Their deep learning models are trained upon vector representations of the programs' Abstract Syntax Trees and this approach was shown to improve within-project as well as cross-project defect prediction. The issue with non-semantic metrics (such as lines of code) is that programs performing different tasks may have the same values for these metrics. Their models were evaluated upon 10 open source Java projects from the PROMISE datasets. Their evaluation compares to two baselines, the first being non-semantic features that were available in the PROMISE datasets and the second being AST nodes that they provided to their models.

\subsection{Just-in-time Defect Prediction}

A method for providing software defect predictions that has gained traction recently is Just-in-time defect predictions. These models make predictions at the commit level rather than at the file level and utilize commit metadata for features rather than product metrics or by analyzing the source code \cite{kamei2013large}. The motivation for this approach is the fact that commits tend to be smaller and more manageable to review than files. Also, there is the fact that files can be edited by multiple developers which makes it challenging to assign an individual developer to resolve the bug whereas commits only have one author \cite{kamei2013large}. A proposed benefit of these models is having the ability to provide immediate feedback to a developer as soon as a change is made.

One of the earlier works on change-level defect prediction, \textit{"Classifying Software Changes: Clean or Buggy?"} suggested that one should train models on file changes rather than files or functions themselves \cite{kim2008classifying}. This paper differs from previous work in the sense that it used the SZZ algorithm to find the exact changes that cause a bug whereas previous work relied on bug-fix data which could only show roughly where a bug occurred. Also, due to the fact that they represent their features using a bag-of-words encoding, their technique could work independently of programming language.

In their paper, Kamei et al. \cite{kamei2013large} introduce the idea of Just-in-time prediction models where models attempt to predict risky commits rather than risky files. They also ensure that the bug-fixing commits that the SZZ finds are present in a bug-tracking database for each project they investigate. They evaluated their models on six open source projects as well as five commercial projects to obtain an average accuracy of 68\% and average recall of 64\%. They also evaluate if the model serves a useful purpose practically, i.e. will prioritizing commits by risk level reduce the amount of work required when reviewing code. This paper is considered to be the most related to the research undertaken within this thesis as the same datasets and similar modelling techniques are used.

A follow up work to the previous paper stated that predictions have to be feasible for projects that have little historical data available \cite{fukushima2014empirical}. This can be a challenge for defect prediction models where the model only trains on data from a single repository. Instead, they investigate the feasibility of cross project models, models that train on data from multiple projects. They find that within-project models do not perform well on cross-project performance. They also found that within project models can improve if the project they intend to predict on has similar correlations between predictor and dependent variables. It was shown that file level predictions seem to do better at cross project performance than commit level predictions. Finally, they also show that ensemble learning techniques benefit cross project performance.

In "Deep learning for just-in-time defect prediction", the authors propose a deep-learning based approach to detect risky commits \cite{yang2015deep}. They evaluate performance on the same 6 OSS projects that Kamei et al. used and showed that their approach outperformed previous models. They use a deep belief network algorithm for feature selection and then utilized deep neural networks to build the classifier. Their model named Deeper was able to find 39.96 \% more bugs and had statistically significant higher F1 scores. This paper was one of the first examples of applying deep learning to this field and they also investigate the effect that the quantity of data has on their model.

Yang et al. try a different approach to Just-In-Time (JIT) predictions that involves a 2-layer ensemble learning classifier named TLEL that combines stacking and bagging techniques with decision trees \cite{yang2017tlel}. The first layer consists of applying bagging to a decision tree to produce a random forest model. The second layer uses stacking and random undersampling to train multiple random forest models and combine them together. The motivation behind this two-layer approach according to them is that they observed that decision tree perform particularly well at this task as well as the fact that ensemble methods tend to produce better results over single models. They compare their approach to three previous models, Deeper, DNC and MKEL. For evaluating their models, they rely on F1 score and PofB20 which measures the cost effectiveness of the model (how well the model can find bugs by only reviewing 20\% of all lines of code).

In the paper "Supervised vs Unsupervised Models: A Holistic Look at Effort-Aware Just-in-Time Defect Prediction", they limit their focus on effort aware JIT defect prediction which tries to find risky commits while inspecting the code as minimally as possible \cite{huang2017supervised}. They state that one challenge in this field is obtaining labelled training data so they investigate the possibility of using unsupervised models. Their contribution is the CBS algorithm CBS (Classify Before Sorting) which makes predictions and then sorts the output by the size of the commit in ascending order. They focus on making their predictions effort aware because it takes time to inspect a commit and they want to minimize the time a developer would need to do a review after they receive predictions. They also observed that the distribution of lines of codes in commits is skewed, the majority of commits are small and very few are large, thus the need for applying logarithmic transformations to their features.

In his paper "Online Defect Prediction for Imbalanced Data", Ming Tan addresses the challenge of class imbalance in defect prediction \cite{tan2015online}. Usually, the minority of entries in datasets will have a label corresponding to a bug. The author tried out four resampling methods which alter the training set in order to deal with the imbalance in the dataset. Another issue that is brought up is that previous studies rely on cross validation to evaluate model performance which does not assess models in a realistic manner. The reason being that cross validation splits up the training and test sets in a way such that models can use future knowledge to make predictions. Instead, the author suggests that a time-sensitive classification should be used so that the test set only contains commits that occur later in time than the commits provided in the training set.

\subsection{Practical Implementations of JIT Prediction Models}

A recent open source implementation of a JIT risk prediction model would be Commit Guru which builds directly on top of the work presented in "A large-scale empirical study of just-in-time quality assurance" \cite{rosen2015commit}. Commit Guru is able to take a GitHub repository and returns statistics on which commits may have high risk. The associated paper outlines the architecture of the tool as well as the usage of the SZZ algorithm and the classification model they use. As \cite{nayrolles2018clever} points out, the limitation of this tool is that it cannot point out which exact code block caused a bug. Also, there has not been a formal study that investigates how useful the predictions are for developers and what performance we should expect in terms of precision and recall for developers to trust the tool.

The video games developer Ubisoft performed a study in collaboration with Concordia University in which they developed a tool named CLEVER which builds upon Commit Guru when performing predictions of risky commits \cite{nayrolles2018clever}. They rely on a two stage process, the first is similar to Commit Guru as it predicts commits that are risky. The second step then does a deeper analysis of those potentially risky commits by comparing code snippets with a database of known bugs to confirm that the commit does cause some sort of issue and is not a false positive.

\end{document}

\begin{comment}
\subsection{Challenges in defect prediction}

\subsubsection{Imbalanced data}

TODO

Due to the fact that the majority of changes to a codebase will function as intended, there will be an imbalance in the dataset between the two classes of risky and not risky. Machine learning algorithms tend to see a drop in performance when trained on imbalanced data.. For example, given a classifier tasked with diagnosing cancer in patients where the rate of having cancer is 5\%, the algorithm would be accurate 95\% of the time if it simply diagnosed every patient as not having cancer. Despite the high accuracy, this would be a very poor classifier in practice as it hasn't actually learned to spot the minority class. The classifier performs this way because the risky samples are underrepresented so it assumes that in most cases, a label would not be risky. There is also the fact that false positives and false negatives are by default weighted equally but in practice a false negative tends to be worse than a false positive. In our example of defect prediction, it is much worse if a bug is introduced and goes unnoticed as opposed to having a developer inspect some code and find no bugs.

https://medium.com/james-blogs/handling-imbalanced-data-in-classification-problems-7de598c1059f

Typical approaches to address this involve re-sampling methods such as over sampling and undersampling. These methods increse or decrease instances of a class in a dataset until there is a 50/50 split.
\subsubsection{Skew in data}
\subsubsection{Collinearality between features}
\subsubsection{Within project vs cross project models}

Within projects models are defined to be models trained on a single repository whereas cross project models learn from a mix of previous projects. The importance of making this distinction is because defect prediction models should be able to make predictions on new projects with little historical data available. However, machine learning models in practice require a large amount of data to perform well.
%http://posl.ait.kyushu-u.ac.jp/~kamei/publications/Fukushima_MSR2014.pdf

Their report found that having a high within-project performance can still lead to a low cross project performance. Kamei et al found that

\end{comment}


\section{Flux Corrected Transport scheme}
Equation (\ref{eq:tracer_int}) can be written as
\begin{eqnarray}
%%
\left(\rho q\right)^{n+1}_{i,j,k}
&=& \left(\rho q\right)^{n}_{i,j,k}
- \frac{1}{\Delta x \Delta y \Delta z}
\big[ \nonumber\\
&+&
\left[ C_{i+\frac{1}{2},j,k} F_{i+\frac{1}{2},j,k}^{high}
+ \left( 1 - C_{i+\frac{1}{2},j,k}\right) F_{i+\frac{1}{2},j,k}^{low}\right]\nonumber\\
&-&
\left[ C_{i-\frac{1}{2},j,k} F_{i-\frac{1}{2},j,k}^{high}
+ \left( 1 - C_{i-\frac{1}{2},j,k}\right) F_{i-\frac{1}{2},j,k}^{low}\right]\nonumber\\
&+&
\left[ C_{i,j+\frac{1}{2},k} F_{i,j+\frac{1}{2},k}^{high}
+ \left( 1 - C_{i,j+\frac{1}{2},k}\right) F_{i,j+\frac{1}{2},k}^{low}\right]\nonumber\\
&-&
\left[ C_{i,j-\frac{1}{2},k} F_{i,j-\frac{1}{2},k}^{high}
+ \left( 1 - C_{i,j-\frac{1}{2},k}\right) F_{i,j-\frac{1}{2},k}^{low}\right]\nonumber\\
&+&
\left[ C_{i,j,k+\frac{1}{2}} F_{i,j,k+\frac{1}{2}}^{high}
+ \left( 1 - C_{i,j,k+\frac{1}{2}}\right) F_{i,j,k+\frac{1}{2}}^{low}\right]\nonumber\\
&-&
\left[ C_{i,j,k-\frac{1}{2}} F_{i,j,k-\frac{1}{2}}^{high}
+ \left( 1 - C_{i,j,k-\frac{1}{2}}\right) F_{i,j,k-\frac{1}{2}}^{low}\right]\nonumber\\
\big]
\label{eq:1step_integ_tracer}
\end{eqnarray}
where
\begin{eqnarray}
  F_{i+\frac{1}{2},j,k}^{high,low} &=& \Delta t \Delta y \Delta z (\rho u)_{i+\frac{1}{2},j,k} q_{i+\frac{1}{2},j,k}^{high,low}\\
  F_{i,j+\frac{1}{2},k}^{high,low} &=& \Delta t \Delta z \Delta x (\rho u)_{i,j+\frac{1}{2},k} q_{i,j+\frac{1}{2},k}^{high,low}\\
  F_{i,j,k+\frac{1}{2}}^{high,low} &=& \Delta t \Delta x \Delta y (\rho u)_{i,j,k+\frac{1}{2}} q_{i,j,k+\frac{1}{2}}^{high,low}
\end{eqnarray}
The anti-diffusive flux are defined as
\begin{eqnarray}
  A_{i+\frac{1}{2},j,k} &=& F_{i+\frac{1}{2},j,k}^{high}-F_{i+\frac{1}{2},j,k}^{low}\\
  A_{i,j+\frac{1}{2},k} &=& F_{i,j+\frac{1}{2},k}^{high}-F_{i,j+\frac{1}{2},k}^{low}\\
  A_{i,j,k+\frac{1}{2}} &=& F_{i,j,k+\frac{1}{2}}^{high}-F_{i,j,k+\frac{1}{2}}^{low}
\end{eqnarray}

Equation (\ref{eq:1step_integ_tracer}) can be rewritten as
\begin{eqnarray}
%%
\left(\rho q\right)^{n+1}_{i,j,k}
&=& \left(\rho q\right)^{n}_{i,j,k}
- \frac{1}{\Delta x \Delta y \Delta z}
\big[ \nonumber\\
&+&
\left[ F_{i+\frac{1}{2},j,k}^{low}
+ C_{i+\frac{1}{2},j,k}  A_{i+\frac{1}{2},j,k}\right]\nonumber\\
&-&
\left[ F_{i-\frac{1}{2},j,k}^{low}
+ C_{i-\frac{1}{2},j,k}  A_{i-\frac{1}{2},j,k}\right]\nonumber\\
&+&
\left[ F_{i,j+\frac{1}{2},k}^{low}
+ C_{i,j+\frac{1}{2},k}  A_{i,j+\frac{1}{2},k}\right]\nonumber\\
&-&
\left[ F_{i,j-\frac{1}{2},k}^{low}
+ C_{i,j-\frac{1}{2},k}  A_{i,j-\frac{1}{2},k}\right]\nonumber\\
&+&
\left[ F_{i,j,k+\frac{1}{2}}^{low}
+ C_{i,j,k+\frac{1}{2}}  A_{i,j,k+\frac{1}{2}}\right]\nonumber\\
&-&
\left[ F_{i,j,k-\frac{1}{2}}^{low}
+ C_{i,j,k-\frac{1}{2}}  A_{i,j,k-\frac{1}{2}}\right]\nonumber\\
\big]
\label{eq:1step_integ_tracer2}
\end{eqnarray}
In practice, we calculate Eq.(\ref{eq:1step_integ_tracer2}) by the
following steps:
\begin{enumerate}
%
\item The tentative values are calculated by using the low order flux:
\begin{eqnarray}
\left(\rho q\right)^{\dagger}_{i,j,k}
&=& \left(\rho q\right)^{n}_{i,j,k}\nonumber\\
&-& \frac{1}{\Delta x \Delta y \Delta z}
\left[
+ F_{i+\frac{1}{2},j,k}^{low}-F_{i-\frac{1}{2},j,k}^{low}
+ F_{i,j+\frac{1}{2},k}^{low}-F_{i,j-\frac{1}{2},k}^{low}
+ F_{i,j,k+\frac{1}{2}}^{low}-F_{i,j,k-\frac{1}{2}}^{low}
\right]
\end{eqnarray}
%
\item Allowable maximum and minimum values are calculated:
\begin{eqnarray}
\left(\rho q\right)^{\max}_{i,j,k}
&=& \max [\nonumber\\
&&\max( \left(\rho q\right)^{\dagger}_{i,j,k},\left(\rho q\right)^{n}_{i,j,k} ),\nonumber\\
&&\max( \left(\rho q\right)^{\dagger}_{i-1,j,k},\left(\rho q\right)^{n}_{i-1,j,k} ),\nonumber\\
&&\max( \left(\rho q\right)^{\dagger}_{i+1,j,k},\left(\rho q\right)^{n}_{i+1,j,k} ),\nonumber\\
&&\max( \left(\rho q\right)^{\dagger}_{i,j-1,k},\left(\rho q\right)^{n}_{i,j-1,k} ),\nonumber\\
&&\max( \left(\rho q\right)^{\dagger}_{i,j+1,k},\left(\rho q\right)^{n}_{i,j+1,k} ),\nonumber\\
&&\max( \left(\rho q\right)^{\dagger}_{i,j,k-1},\left(\rho q\right)^{n}_{i,j,k-1} ),\nonumber\\
&&\max( \left(\rho q\right)^{\dagger}_{i,j,k+1},\left(\rho q\right)^{n}_{i,j,k+1} ) \nonumber\\
&&]\\
\left(\rho q\right)^{\min}_{i,j,k}
&=& \min [\nonumber\\
&&\min( \left(\rho q\right)^{\dagger}_{i,j,k},\left(\rho q\right)^{n}_{i,j,k} ),\nonumber\\
&&\min( \left(\rho q\right)^{\dagger}_{i-1,j,k},\left(\rho q\right)^{n}_{i-1,j,k} ),\nonumber\\
&&\min( \left(\rho q\right)^{\dagger}_{i+1,j,k},\left(\rho q\right)^{n}_{i+1,j,k} ),\nonumber\\
&&\min( \left(\rho q\right)^{\dagger}_{i,j-1,k},\left(\rho q\right)^{n}_{i,j-1,k} ),\nonumber\\
&&\min( \left(\rho q\right)^{\dagger}_{i,j+1,k},\left(\rho q\right)^{n}_{i,j+1,k} ),\nonumber\\
&&\min( \left(\rho q\right)^{\dagger}_{i,j,k-1},\left(\rho q\right)^{n}_{i,j,k-1} ),\nonumber\\
&&\min( \left(\rho q\right)^{\dagger}_{i,j,k+1},\left(\rho q\right)^{n}_{i,j,k+1} ) \nonumber\\
&&]
\end{eqnarray}
\item Several values for the flux limiter are calculated:
\begin{eqnarray}
P_{i,j,k}^{+} &=&
-\min ( 0, A_{i+\frac{1}{2},j,k} ) + \max( 0, A_{i-\frac{1}{2},j,k} )\nonumber\\
&&
-\min ( 0, A_{i,j+\frac{1}{2},k} ) + \max( 0, A_{i,j-\frac{1}{2},k} )\nonumber\\
&&
-\min ( 0, A_{i,j,k+\frac{1}{2}} ) + \max( 0, A_{i,j,k-\frac{1}{2}} )\\
P_{i,j,k}^{-} &=&
-\max ( 0, A_{i+\frac{1}{2},j,k} ) + \min( 0, A_{i-\frac{1}{2},j,k} )\nonumber\\
&&
-\max ( 0, A_{i,j+\frac{1}{2},k} ) + \min( 0, A_{i,j-\frac{1}{2},k} )\nonumber\\
&&
-\max ( 0, A_{i,j,k+\frac{1}{2}} ) + \min( 0, A_{i,j,k-\frac{1}{2}} )\\
\end{eqnarray}
\begin{eqnarray}
Q_{i,j,k}^{+} &=&
\left[\left(\rho q\right)^{\max}_{i,j,k} - \left(\rho q\right)^{\dagger}_{i,j,k} \right]
\Delta x \Delta y \Delta z\\
Q_{i,j,k}^{-} &=&
\left[\left(\rho q\right)^{\dagger}_{i,j,k}-\left(\rho q\right)^{\min}_{i,j,k} \right]
\Delta x \Delta y \Delta z
\end{eqnarray}
\begin{eqnarray}
R_{i,j,k}^{+} &=&
\begin{cases}
        \min( 1, Q_{i,j,k}^{+}/P_{i,j,k}^{+} ) & {\rm if~} P_{i,j,k}^{+}>0\\
        0 & {\rm if~} P_{i,j,k}^{+}=0\\
\end{cases}
\\
R_{i,j,k}^{-} &=&
\begin{cases}
        \min( 1, Q_{i,j,k}^{-}/P_{i,j,k}^{-} ) & {\rm if~} P_{i,j,k}^{-}>0\\
        0 & {\rm if~} P_{i,j,k}^{-}=0\\
\end{cases}
\end{eqnarray}
\item The flux limters at the cell wall are calculated:
\begin{eqnarray}
C_{i+\frac{1}{2},j,k} &=&
\begin{cases}
        \min( R_{i+1,j,k}^{+}, R_{i,j,k}^{-} ) & {\rm if~} A_{i+\frac{1}{2},j,k}^{-}\geq 0\\
        \min( R_{i,j,k}^{+}, R_{i+1,j,k}^{-} ) & {\rm if~} A_{i+\frac{1}{2},j,k}^{-}<0\\
\end{cases}
\\
C_{i,j+\frac{1}{2},k} &=&
\begin{cases}
        \min( R_{i,j+1,k}^{+}, R_{i,j,k}^{-} ) & {\rm if~} A_{i,j+\frac{1}{2},k}^{-}\geq 0\\
        \min( R_{i,j,k}^{+}, R_{i,j+1,k}^{-} ) & {\rm if~} A_{i,j+\frac{1}{2},k}^{-}<0\\
\end{cases}
\\
C_{i,j,k+\frac{1}{2}} &=&
\begin{cases}
        \min( R_{i,j,k+1}^{+}, R_{i,j,k}^{-} ) & {\rm if~} A_{i,j,k+\frac{1}{2}}^{-}\geq 0\\
        \min( R_{i,j,k}^{+}, R_{i,j,k+1}^{-} ) & {\rm if~} A_{i,j,k+\frac{1}{2}}^{-}<0\\
\end{cases}
\end{eqnarray}
\end{enumerate}


\section{The Counting Numbers}

\begin{frame}
  \begin{columns}
    \begin{column}{0.3\textwidth}
      \centering
      \begin{tikzpicture}
        \draw (0,0) ellipse (1.5 and 1);
        \draw (0,3) ellipse (1.5 and 1);
        \node () at (0,3.5) {\footnotesize vanilla};
        \node () at (0,3) {\footnotesize chocolate};
        \node () at (0,2.5) {\footnotesize strawberry};
        \node (A) at (0,0) {$1 \quad  2 \quad  3$};
      \end{tikzpicture}
    \end{column}
    {\color{gmitgrey!30}\vrule{}} \hspace{0.1\textwidth}
    \begin{column}{0.5\textwidth}
      $\mathbb{N} = \{1,2,3,\ldots\}$ \\[8mm]
      $1 \leftrightarrow $ vanilla \\[8mm]
      $2 \leftrightarrow $ chocolate \\[8mm]
      $3 \leftrightarrow $ strawberry \\[8mm]
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \begin{columns}
    \begin{column}{0.3\textwidth}
      \color{gmitblue} \fontsize{30}{10}
      \[2\mathbb{N}\]
    \end{column}
    {\color{gmitgrey!30}\vrule{}} \hspace{0.1\textwidth}
    \begin{column}{0.5\textwidth}
      $\mathbb{N} = \{1,2,3,\ldots\}$ \\[4mm]
      $2\mathbb{N} = \{2,4,6,\ldots\}$ \\[4mm]
      $\mathbb{N} \leftrightarrow 2 \mathbb{N}$ \\[8mm]
      $1 \leftrightarrow 2$ \\[4mm]
      $2 \leftrightarrow 4$ \\[4mm]
      $3 \leftrightarrow 6$ \\[4mm]
      $\ldots$ \\[4mm]
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}[standout]

\begin{quote}
  Computer programs are binary strings. \\[8mm]
  Treat them as integers. \\[8mm]
  They're countable. \\[8mm]
  (Slight issue with leading zeros.)
\end{quote}

\end{frame}