\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[left=2cm, right=4cm, top=2cm]{geometry}
\usepackage{graphicx}
\graphicspath{ {../../../figures/snn/} }

\title{Convolutional Spiking Neural Networks}
\author{Daniel Saunders}

\begin{document}

\maketitle

This document tracks the progress of the BINDS lab on studying convolutional spiking neural networks (C-SNNs). No distinction is made between computational \textit{layers} and networks which use said layers; e.g., a \textit{convolutional SNN} is that which uses one or more \textit{convolutional layers}. \\

\textbf{Note}: All \texttt{code} is assumed to be Python + BindsNET syntax.

\section{Two layer locally connected SNNs}

An layer of \texttt{Input} neurons (layer \texttt{X}) equal to the size of the input data (e.g., MNIST or CIFAR-10) is connected via a \texttt{LocallyConnectedLayer} (\textbf{to be implemented}) with STDP-modifiable synapses to a layer of \texttt{AdaptiveLIFNodes} or \texttt{DiehlAndCook2015Nodes} (layer \texttt{Y}). Layer \texttt{Y} is recurrently connected to itself with inhibitory synapses via a \texttt{Connection}, the structure of which is a design choice (to be discussed in section \ref{ss:recurrent connectivity}).

\section{Two layer convolutional SNNs}

\subsection{Basic structure}

An layer of \texttt{Input} neurons (layer \texttt{X}) equal to the size of the input data (e.g., MNIST or CIFAR-10) is connected via a \texttt{Conv2dConnection} with STDP-modifiable synapses to a layer of \texttt{AdaptiveLIFNodes} or \texttt{DiehlAndCook2015Nodes} (layer \texttt{Y}). Layer \texttt{Y} is recurrently connected to itself with inhibitory synapses via a \texttt{Connection}.

Layer \texttt{Y} may be driven by \texttt{bernoulli()}- or \texttt{poisson()}-distributed spikes parametrized by the input data; since the networks are operating in an effectively rate-based regime, Bernoulli spikes may be preferred for efficiency reasons. \textbf{Note}: The implementation of \texttt{poisson()} may be slightly incorrect at this stage.

\begin{figure}[h]
	\centering
	\includegraphics[width=0.8\textwidth]{two_layer_convolutional_snn.png}
	\caption{Schematic diagram of the structure of a two-layer convolutional spiking neural network. For ease of presentation, all data, layers, and weight kernels are depicted as two-dimensional (as in the case of gray-scale image processing). Input data encoded into spike trains is used for the activity of an input layer. Weight kernels are ``slid'' across the input space, multiplied by the input activations, and projected to unique neurons in the corresponding sub-population in the convolutional layer (one per weight kernel). The convolutional layer has inhibitory, recurrent connections, establishing a competition for spiking activity.}
\end{figure}

The goal of the convolutional layer is to learn a (compact) set of weight kernels (filters) which reliably detect salient features in the input space. The weight kernels ``slide'' across the input space with a regular horizontal and vertical \textit{stride}, and are multiplied by the activations at each input location to produce an activation value for a unique neuron in the next layer.

This technique has been successful in convolutional neural networks (CNNs) of deep learning; however, the neural model is much simplified, and the network can be efficiently trained using optimization techniques (stochastic gradient descent (SGD)). In the case of SNNs, the input activations are converted into spike trains, and the output of the convolution can be interpreted as current to be injected into the post-synaptic layer.

\section{Modifications}

This section describes some algorithmic and architectural modifications to the above described networks. Some changes apply to all network structures; when possible, it will be noted when changes apply to certain structures and not others.

\subsection{Recurrent connectivity}
\label{ss:recurrent connectivity}

There are some variants of connectivity of the recurrent connection for layer \texttt{Y}.

\subsubsection{Inhibit all other neurons}

In the spirit of Diehl \& Cook 2015, each neuron in layer \texttt{Y} is connected with an inhibitory synapse to all other neurons in the layer. This creates a simple competitive mechanism: when a neuron fires, all other neurons are damped, allowing the ``winning'' neuron to continue firing and to update its weights in the direction of the current input pattern. This is similar to the idea of a \textit{winner-take-all (WTA) circuit}.

The result of this training is improved clarity of weight kernels. Since (typically) only one neuron is able to fire consistently, that neuron can significantly update the weights of the filter (using STDP) in the direction of the stimulus that is firing it; i.e., the input data.

\subsubsection{Inhibit all neurons with same spatial field}

This change applies only to the \textit{locally connected networks}.

Only neurons in layer \texttt{Y} which receive connections from the same neurons of the input layer are recurrently connected with inhibitory synapses. The result of this change is that only neurons with the same \textit{spatial field} are involved in a miniature competition akin to that of the Diehl and Cook 2015 network. Each spatial field \textit{sub-population} is involved in the WTA-like circuit, and thus, at most one neuron from each sub-population can be the ``winner'' of the spiking competition per input example.

\subsection{Architectural modifications}

\subsubsection{Duplicate layer \texttt{Y} without recurrent connectivity}

In the typical setup, the convolutional layer \texttt{Y} has recurrent inhibitory connections that cause competition to take place between neurons, thereby allowing ``winning'' neurons to change their weights in the direction of the stimulus firing them. However, this connectivity also causes sparse activation in the layer, implying that it may be difficult to use the layer's output as input to downstream network layers (depending on the degree of sparseness).

To remedy this issue, we may \textit{duplicate} the layer \texttt{Y}, creating \texttt{Y'}, which receives connections from the input layer \texttt{X} with weights tied to those of the layer {Y}. The activation of layer \texttt{Y'} does not effect the modification of these connection weights, and there are no recurrent inhibitory connections in the layer. This allows \texttt{Y'} to activate much more than \texttt{Y}, and its output may therefore be more useful as input to downstream network components.

\end{document}


% !TEX root = ../../main.tex
% !TEX encoding = UTF-8 Unicode
%%%
\chapter{The Standard Model}
\label{ch:stdmodel}

% Inline fraction for text
%\newcommand{\slantfrac}[2]{\,^#1\!/_#2}

The Standard Model (SM) is a quantum field theory describing the elementary particles and fundamental forces (with the exception of gravity)
%\footnote{Except when stated otherwise, discussion of forces in the context of the SM will not refer to gravity.}
that govern the universe. At its core, the SM states that all matter is composed of fundamental particles called fermions, all forces are mediated by force carrying gauge bosons, and all massive fundamental particles acquire their mass through interactions with the Higgs boson.

The importance of the SM to our understanding of the physical world is reflected in the 17 Nobel Prizes in physics that have been awarded since 1957 for work relating to the development and verification of the SM~\cite{Nobel_Prizes}. That the current theory describes with remarkable accuracy nearly all observed phenomena of electromagnetic, weak, and strong interactions in a compact theory with rich symmetries can belie the tumultuous and often uncertain path that lead to it's development. In this chapter, a brief discussion of the content and formulation of the SM is presented.

%
\section{Particle Content}

In ~\Fig{\ref{fig:st_m_p}}, the particle content of the SM is succinctly summarized. The particles are elementary: they cannot be decomposed further into smaller constituents. There are two broad categories of particles: fermions (half integer spin) and bosons (integer spin). Spin is an intrinsic property of a particle, and is a form of angular momentum. Fermions and bosons necessarily behave differently according to the Spin-Statistics Theorem\footnote{
	An important consequence of the theorem is the Pauli exclusion principle for fermions: no two fermions can occupy the same quantum state. Bosons have no such restriction, and thus any number can occupy the same quantum state.
}~\cite{spin_stats}. The fermions in the SM are further subdivided into quarks and leptons, while the bosons are subdivided into gauge (spin 1) and scalar (spin 0) bosons.

\begin{figure}[htb]
\begin{center}
\includegraphics[width=0.7\textwidth]{figures/StandardModel/std_model}
\end{center}
\caption[Fundamental particles in the Standard Model]{A categorization of the fundamental particles in the Standard Model is shown: quarks and leptons together constitute all the matter particles, the gauge bosons mediate the electromagnetic, weak, and strong forces, and the Higgs boson generates mass for the fundamental particles.}
\label{fig:st_m_p}
\end{figure}

All matter is composed of quarks and leptons, which are divided into three generations of increasing mass\footnote{
	The exact mass hierarchy of the neutrinos has not been determined.
}. A generation includes two quarks, one with electric charge $+2/3$ (in units of the fundamental electric charge scale, $e$) and one with $-1/3$, one negatively charged lepton, and one neutral lepton called a neutrino. The particles in different generations mainly differ in their masses. Each fermion has an associated anti-particle with identical properties, with the exception of an inverted electric charge.

The three quarks with electric charge $+2/3$, known as up-type quarks, are called up, charm, and top, and are denoted by u, c, and t, respectively. The three quarks with electric charge $-1/3$, known as down-type quarks, are called down, strange, and bottom, and are denoted by d, s, and b, respectively. Due to the strong force, quarks do not exist in isolation, but rather combine to form hadrons like protons, neutrons, and pions. Hadrons are typically composed of either two quarks (meson) or three quarks (baryon), although a pentaquark state has been recently experimentally verified~\cite{pentaquark}.

In order of increasing mass, the charged leptons are the electron, muon, and tau and are denoted by $e,\mu$, and $\tau$, respectively. The neutrinos are labeled by the charged lepton in their generation: $\nu_e,\nu_{\mu}$, and $\nu_{\tau}$.
Leptons only interact with the electromagnetic and weak forces, and in contrast to quarks can exist in isolation. The heaviest charged leptons have a finite lifetime and decay to electrons which are stable. Neutrinos have an extremely small, non-zero mass, and oscillate as they propagate through space\footnote{
	The oscillation is a predictable, periodic transformation between the three neutrino generations. Neutrinos are produced in weak eigenstates, e.g. $\nu_e$, which, however, do not correspond to mass eigenstates.
}.

The gauge bosons mediate the electromagnetic, weak, and strong forces: particles that interact via a certain force do so through the exchange of gauge bosons. The photon has no mass or electric charge, and mediates the electromagnetic force. Since it has no mass, the photon is stable and can propagate through space indefinitely. The weak force is mediated by the $Z^0$, $W^+$, and $W^-$ bosons, where the superscript denotes the electric charge. All three weak bosons are massive, and have a finite lifetime. The gluon is responsible for mediating the strong force. Like the photon, it is massless and has no electric charge; however, it has an analogous ``color charge'' associated with the strong interaction.

Finally, the Higgs boson is a massive scalar (spin-0) particle with no electric charge. Through a process called the Higgs mechanism, it is responsible for generating masses of the fermions, weak gauge bosons, and itself.

%
%%%
\iffalse
%%%
\section{Arriving at the Standard Model}

Our current understanding of the fundamental interactions between elementary particles is derived from this astonishingly nascent theory. In the span of 13 years, the SM in its current form was developed. In 1961, Glashow first proposed a way to combine the electromagnetic and weak interactions~\cite{Glashow:1961tr}; in 1967, Weinberg and Salam independently incorporated the Higgs mechanism~\cite{Weinberg,Salam:1968rm}; and by 1974, quantum chromodynamics (QCD) with the inclusion of asymptotic freedom~\cite{Gross_Wilczek, Politzer} rendered the basic form of the current Standard Model\footnote{
	There would still be much to verify and refine, such as the number of leptons and quarks, but the pillars of the theory were formed.
}.

A mere 64 years prior to Glashow's electroweak proposal, the {\em first} fundamental particle was discovered by J.J. Thompson in 1897: the electron\footnote{
	The celerity with which this feat has been achieved is reminiscent of the 66 years separating the Wright brothers' initial flight (1903) and the Apollo 11 moon landing (1969), coincidentally transpiring nearly contemporaneously.
}. By 1911 Rutherford had discovered the nucleus and in 1913 the primitive Bohr model gave accurate predictions for Hydrogen energy levels. Even during this relatively simple period, there were hints of a coming quantum model: in 1905 Einstein's photoelectric effect unequivocally demonstrated the existence of the massless photon.

With the advent of quantum mechanics in 1925, the picture of fundamental particles began to expand. In 1928 Dirac postulated the existence of the positron\footnote{
	He recognized his equation permitted negative energy electron solutions.
}, in 1930 Pauli theorized the neutrino to conserve energy in $\beta$ decays, and in 1935 Yukawa theorized nuclei were held together by a nuclear force through the exchange of mesons.

In 1947, most of the predicted particles had been found\footnote{
	The muon was not predicted, but found nonetheless, while the neutrino would't be found until later.
}, however the discovery of a new meson, the kaon, would spark another revolution in the theory of elementary particles. In the following decade, a ``zoo'' of new mesons and baryons were discovered, and physicists struggled to find a way to neatly classify them. Finally in 1961, Gell-Mann introduced the Eightfold Way to describe the symmetries of mesons and baryons as representations of the group SU(3). The power of this classification of symmetries was immediately evident when the $\Omega^-$ baryon predicted by the theory was discovered in 1964. In the same year, Gell-Mann and Zweig proposed the quark model which codified the symmetries of the Eightfold Way with three quarks and anti-quarks that combined to form mesons and baryons. The use of group theory to classify the interactions of elementary particles in terms of symmetries would drive the development of the field, resulting eventually in the current theory of the SM.

%%%
\fi
%%%

%
\section{Formulation of Symmetries}
The principle of least action with a Lagrangian density is used to describe the propagation and interactions of quanta and fields: for an arbitrary field $\phi$, obeying the equations of motion described by the Lagrangian density, $\mathcal{L}(\phi,\partial\phi)$, the action is defined as:
 $$S[\phi] = \int d^4x \mathcal{L}(\phi(x),\partial\phi(x)); \quad\quad \delta S = 0$$
 According to Noether's Theorem, for every continuous global symmetry of the action, there is an associated conserved charge~\cite{noether}. For local gauge symmetries, an equation of motion for generated gauge fields is produced.

The group corresponding to all Poincar\'e transformations characterizes the 10 global continuous symmetries of special relativity; translations in space and time (four), rotations in space (three), and boosts in space (three)~\cite{Srednicki}. As a relativistic quantum field theory, the SM incorporates special relativity; hence, the Poincar\'e symmetry is a global continuous symmetry of the theory. Associated with this global symmetry are three conserved quantities: energy, momentum, and angular momentum.  In the SM, spin-0 particles are described by scalar fields, $\phi$, obeying the Klein-Gordon equation, spin-$1/2$ particles are described by spinor fields, $\psi$, obeying the Dirac equation, and spin-1 particles are described by vector fields, $A_{\mu}$, obeying the Proca equation.

To impose a specific symmetry on the theory, the goal is to derive a Lagrangian which is invariant under the corresponding transformations. Often these are continuous symmetries which can be thought of as abstract rotations of the fields. As an example, consider the free spinor field obeying the Dirac equation:
$$\mathcal{L}=\bar{\psi}(\gamma^{\mu}\partial_{\mu}-m)\psi$$
This is invariant under the global transformation $\psi(x)\ra\psi'(x)=e^{i\alpha}\psi(x)$. The continuous symmetry is characterized by its infinitesimal behavior near the identity transformation. In group theory, this symmetry is characterized by the Lie algebra of U(1), for which there is one generator, $\alpha$~\cite{wukitung}. If $\alpha$ is a function of space-time, the derivative in the Lagrangian produces an extra term. To retain invariance, a covariant derivative can be introduced:
$$\partial_{\mu}\rightarrow D_{\mu} = \partial_{\mu} - ieA_{\mu}$$
where $e$ describes a coupling, and the gauge field, $A_{\mu}(x)$, transforms as:
$$A_{\mu}(x)\ra A'_{\mu}(x)=A_{\mu}(x)+ \frac{1}{e}\partial_{\mu}\alpha(x)$$
Finally, a term corresponding the the free propagation of this new massless gauge field is added to the Lagrangian.

This process of identifying a global symmetry of free fields and requiring it to also be a local or gauge symmetry is the general process through which the interactions in the SM are constructed. For each underlying local symmetry there are generators which form a basis for the Lie algebra describing it, and for each generator a gauge field must be introduced to preserve the symmetry. The gauge fields couple to the original fields and determine the interactions of the theory. The resulting theory is known as a gauge theory which, as shown by 't Hooft, implies the theory is renormalizable~\cite{thooft}. The full local gauge symmetry of the SM is described by the group $SU(3)\times SU(2)_L\times U(1)_Y$ which describes the strong and electroweak interactions~\cite{Griffiths, Srednicki}.

%
\section{Electroweak Sector}
The electroweak interaction preserves the internal weak isospin and weak hypercharge symmetries corresponding to the group $SU(2)_L\times U(1)_Y$. The subscript $L$ indicates that the weak isospin $SU(2)$ symmetry is restricted to left-handed fields, while the subscript $Y$ corresponds to the weak hypercharge which generates the U(1) symmetry. The electroweak interaction is thus described by a chiral theory since it couples differently to left-handed and right-handed fields, which are defined by how they behave under Lorentz transformations.

The restricted Lorentz group is a subgroup of the Poincar\'e group corresponding to the generators of boosts and rotations. These six generators can be rearranged into a direct sum of two Lie algebras corresponding to the group $SU(2)\times SU(2)$~\cite{Srednicki}. A fermion field can be expressed as a Dirac spinor in the $(\frac{1}{2},0)\oplus(0,\frac{1}{2})$ representation of the restricted Lorentz group as $\Psi = \begin{pmatrix}\psi_L\\\psi_R\end{pmatrix}$, where $\psi_L$ and $\psi_R$ are left-handed and right-handed Weyl spinors. The left-handed and right-handed spinor components of the Dirac field do not mix under a Lorentz transformation.

The chiral, weak isospin symmetry is maximally parity violating: left handed fermion fields transform as $SU(2)_L$ doublets in the defining representation, while right-handed fermion fields are represented as $SU(2)_L$ singlets in the trivial representation. The lepton and quark fields can be grouped in terms of their chiral components as shown in~\Tab{\ref{tab:ew_rep}}.  There are three generators for the Lie algebra of $SU(2)$; thus, by requiring $SU(2)_L$ to be a local gauge symmetry, three vector gauge fields are introduced in the adjoint representation: $W_{\mu}^1,W_{\mu}^2$, and $W_{\mu}^3$.

The $U(1)_Y$ weak hypercharge symmetry is not chiral, as it couples to both left-handed and right-handed fields. The weak hypercharge of a field is chosen in a suggestive way: $Y=2(Q-I_3)$, where $Q$ is the electric charge and $I_3$ is the third component of the weak isospin. Corresponding to the single generator of the Lie algebra of $U(1)$, one vector gauge field, $B_{\mu}$, is introduced to ensure the local gauge invariance of the $U(1)_Y$ symmetry.

\begin{table}[tbp]
\begin{center}
\begin{tabular}{lccc}
\hline\hline
Particle type & SU(2)$_L$ Grouping & Isospin ($I_3$) & Hypercharge (Y) \\\hline
Left-handed leptons &$ \begin{pmatrix} \nu_L \\ e_L \end{pmatrix} $& $\pm\frac{1}{2}$ &$ -1$\\
Left-handed quarks &$ \begin{pmatrix} u_L \\ d_L \end{pmatrix} $& $\pm\frac{1}{2}$ &$ \frac{1}{3}$\\
Right-handed neutrino$^{\dagger}$& $\nu_R$ & 0 & 0 \\
Right-handed electron & $e_R$ & 0 & $-2$ \\
Right-handed up quark & $u_R$ & 0 & $\frac{4}{3}$\\
Right-handed down quark & $d_R$ & 0 &$-\frac{2}{3}$\\\hline\hline
\end{tabular}
\end{center}
\caption[Weak isospin and hypercharge groupings of the electroweak sector]{The weak isospin and hypercharge properties of the first generation of fermions is presented.\\\,$^{\dagger}$Right-handed neutrinos do not interact at all, if they exist. For this reason they are not usually included in the formulation of the SM.}
\label{tab:ew_rep}
\end{table}

The four vector gauge fields $W_{\mu}^i, B_{\mu}$ and all the fermion fields must be massless to preserve the imposed gauge invariance; however, experimentally all fermions have mass, and there are three massive weak bosons and one massless photon. The solution is to introduce a complex scalar field, $\Phi=\begin{pmatrix}\phi^+\\\phi^0\end{pmatrix}$, which is a weak isospin doublet with hypercharge $Y=1$, and a potential of the form $V(\Phi) = -\mu^2\Phi^{\dagger}\Phi + \lambda(\Phi^{\dagger}\Phi)^2$, which furthermore respects gauge invariance. By expanding the field about the minimum of the potential, known as the vacuum expectation value $v$, and choosing the unitary gauge so that it is real, the scalar field becomes $\Phi=\frac{1}{\sqrt{2}}\begin{pmatrix}0\\v+H(x)\end{pmatrix}$. The excitation field, $H$, is now interpreted as the physical Higgs field, and the constant, non-zero vacuum expectation value will introduce mass terms for the gauge fields.

The settling of the complex field into the non-zero minimum of the potential, $v$, is known as spontaneous symmetry breaking. By Goldstone's theorem, there should be three massless bosons corresponding to the generators of the spontaneously broken continuous global symmetry~\cite{Goldstone,gold_salam_wein}. By using gauge invariance to select the unitary gauge, however, the three degrees of freedom corresponding to the Goldstone bosons are recast as longitudinal polarizations of the now massive $W^{\pm}_{\mu}$ and $Z_{\mu}^0$ gauge bosons. The combination of spontaneous symmetry breaking with gauge invariance to endow mass to vector gauge fields is called the Higgs mechanism~\cite{brout_englert,higgs_mech,gur_hag_kib}. The fermions can now also acquire mass through added Yukawa couplings of the Dirac fermions to the scalar $\Phi$.

The mass eigenstates of the vector gauge fields can be expressed in terms of the original gauge fields as shown in~\Eqns{\ref{eq:az_mix}}{\ref{eq:w_mix}}.
\begin{equation}
\begin{pmatrix}A_{\mu}\\Z_{\mu}^0\end{pmatrix}  =  \begin{pmatrix}\cos\theta_W&\sin\theta_W\\-\sin\theta_W&\cos\theta_W\end{pmatrix}\begin{pmatrix}B^0_{\mu}\\W^3_{\mu}\end{pmatrix}
\label{eq:az_mix}
\end{equation}
\begin{equation}
\label{eq:w_mix}
W^{\pm}_{\mu} = \frac{1}{\sqrt{2}}\left(W^1_{\mu}\mp iW^2_{\mu}\right)
\end{equation}
The Weinberg weak mixing angle, $\theta_W$, also relates the masses of the neutral weak vector boson, $Z_{\mu}^0$, and the charged weak vector bosons, $W^{\pm}_{\mu}$: $M_W=\cos\theta_WM_Z$. The photon field, $A_{\mu}$, remains massless, corresponding to the unbroken $U(1)_{em}$ symmetry. The electroweak and Higgs bosons after electroweak symmetry breaking are summarized in~\Tab{\ref{tab:ew_bosons}}.

\begin{table}[tbp]
\begin{center}
\begin{tabular}{lcrrr}
\hline\hline
Boson & Type &Isospin ($I_3$) & Hypercharge (Y) & Mass [\GeV]\\\hline
$W^{\pm}_{\mu}$ & Vector Gauge&$\pm 1$ & 0 & 80.4 \\
$Z^0_{\mu}$ & Vector Gauge & 0 & 0 & 91.2\\
$A_{\mu}$ & Vector Gauge& 0 & 0 &  0\\
$H^0$ & Scalar &$-\frac{1}{2}$&1 & 125.1\\\hline\hline
\end{tabular}
\end{center}
\caption[Properties of electroweak and Higgs bosons]{Properties of the electroweak gauge bosons and scalar Higgs boson after electroweak symmetry breaking are shown. The three weak vector gauge bosons acquire mass, while the photon remains massless, corresponding to the unbroken $U(1)_{em}$ symmetry.}
\label{tab:ew_bosons}
\end{table}

The massless, force-mediating photon reproduces the infinite range of electromagnetism, and interacts with particles with electric charge. The short range of the weak force is reproduced by the massive, force-mediating weak bosons. The $Z^0_{\mu}$ boson is associated with fermion-antifermion annihilation or creation, while the $W^{\pm}_{\mu}$ bosons allow for fermions to change flavor, provided the net change in electric charge of the interaction is $\Delta Q = \pm1$. For leptons, the flavor changing must involve a charged lepton and a neutrino of the same type (e.g. $e$ and $\nu_e$); however, for quarks, there is a non-zero probability for intergenerational mixing\footnote{
	An analogous flavor changing neutral current does not exist at tree level, and is suppressed even in loop diagrams.
}. The intergenerational mixing in the quark sector is characterized by the unitary CKM matrix~\cite{Cabibbo, kob_mas}\footnote{
	Similar to the neutrinos, the weak interaction eigenstates of the quarks do not correspond to the freely propagating mass eigenstates.
}. The Higgs boson allows left chiral fermion states to mix with right chiral fermion states. The SM interactions of the electroweak bosons and the Higgs boson are shown in~\Figs{\ref{fig:feyn_weak}}{\ref{fig:feyn_higgs}}.
\begin{figure}[htbp]
\begin{center}
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle={\(\nu_L\)}] -- [fermion] b -- [fermion] c [particle={\(e_L\)}],
b -- [boson] d [particle=\(W^-\)], };
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle=\(d_L\)] -- [fermion] b -- [fermion] c [particle=\(u_L\)],
b -- [boson] d [particle=\(W^+\)], };
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle=\(f\)] -- [fermion] b -- [fermion] c [particle=\(f\)],
b -- [boson] d [particle=\(Z\)], };
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle=\(f^{\pm q}\)] -- [fermion] b -- [fermion] c [particle=\(f^{\pm q}\)],
b -- [boson] d [particle=\(\gamma\)], }; \\
\feynmandiagram [baseline=(d.base), horizontal=b to d] {
a[particle={\(W^+\)}] -- [boson] b -- [boson] c [particle={\(W^-\)}],
b -- [boson] d [particle={\(\gamma, Z\)}], };
\feynmandiagram [baseline=(c.base), horizontal=i1 to f2] {
  {i1[particle={\(W^-\)}] , i2 [particle={\(W^+\)}]} --[boson] c  --[boson] {f1 [particle=\(X\)], f2[particle=\(Y\)]},
};
\caption[Electroweak boson interactions]{The flavor changing $W$ interaction involving leptons must involve leptons from the same generation, while the interaction involving up-type and down-type quarks need not involve the same generation. The photon interaction requires the fermion to have a non-zero electric charge, $q$. In the quartic interaction, $X$ and  $Y$ are any combination of electroweak bosons with $\Delta q= 0$. For simplicity, diagrams with arrows and charges reversed are not shown.}
\label{fig:feyn_weak}
\end{center}
%\end{figure}
%\begin{figure}[htb]
\begin{center}
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle={\(f_L\)}] -- [fermion] b -- [fermion] c [particle={\(f_R\)}],
b -- [scalar] d [particle=\(H\)], };
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle={\(W, Z\)}] -- [boson] b -- [boson] c [particle={\(W, Z\)}],
b -- [scalar] d [particle=\(H\)], };
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle={\(H\)}] -- [scalar] b -- [scalar] c [particle={\(H\)}],
b -- [scalar] d [particle=\(H\)], };\\
\feynmandiagram [baseline=(c.base), horizontal=i1 to f2] {
  {i1[particle={\(H\)}] , i2 [particle={\(H\)}]} --[scalar] c  --[boson] {f1 [particle={\(W, Z\)}], f2[particle={\(W, Z\)}]},
};
\feynmandiagram [baseline=(c.base), horizontal=i1 to f2] {
  {i1[particle={\(H\)}] , i2 [particle={\(H\)}]} --[scalar] c  --[scalar] {f1 [particle={\(H\)}], f2[particle={\(H\)}]},
};
\caption[Higgs boson interactions]{The Higgs boson couples to all particles with mass, including self-interactions.}
\label{fig:feyn_higgs}
\end{center}
\end{figure}

%\clearpage

%
\section{Strong Sector}
Quantum chromodynamics (QCD) describes the strong interaction through an internal color symmetry corresponding to the group $SU(3)$. Unlike the electroweak interaction which couples to all fermions, the strong interaction only couples to quarks. With respect to the $SU(3)$ color symmetry, quarks transform in the defining representation as color triplets, while all other fermions, electroweak bosons, and the Higgs boson transform as color singlets. Since there are eight generators for $SU(3)$, eight vector gauge fields in the adjoint representation, called gluons, are required to ensure local gauge invariance of the $SU(3)$ color symmetry. The eight gluons are required to be massless to retain gauge invariance, and they carry linear combinations of color ($r$, $g$, or $b$) and anti-color ($\bar{r}$, $\bar{g}$, or $\bar{b}$). Since $SU(3)$ is non-abelian, the gluon gauge fields have self-interactions in addition to their interactions with the quarks~\cite{Srednicki}. The strong interaction vertices are shown in ~\Fig{\ref{fig:strong_feyn}}.

\begin{figure}[tb]
\begin{center}
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle={\(q\)}] -- [fermion] b -- [fermion] c [particle={\(q\)}],
b -- [gluon] d [particle=\(g\)], };
\feynmandiagram [baseline=(d.base), horizontal=d to b] {
a[particle={\(g\)}] -- [gluon] b -- [gluon] c [particle={\(g\)}],
b -- [gluon] d [particle=\(g\)], };
\feynmandiagram [baseline=(c.base), horizontal=i1 to f2] {
  {i1[particle={\(g\)}] , i2 [particle={\(g\)}]} --[gluon] c  --[gluon] {f1 [particle={\(g\)}], f2[particle={\(g\)}]},
};
\caption[Gluon interactions]{The gluons only have couplings to quarks and themselves, and they carry a linear combination of color and anti-color.}
\label{fig:strong_feyn}
\end{center}
\end{figure}

An observed property of QCD is color confinement: the only asymptotic states are those which are color neutral, SU(3) singlet states. Thus, hadrons such as mesons, $q\bar{q}$, and baryons, $qqq$, are allowed asymptotic states since they can form color singlets, while, for example, a two quark state, $qq$, which does not form a color singlet, is not observed.

The coupling strength of the strong force decreases as the energy scale increases: a property known as asymptotic freedom. In the high energy or short distance limit, that is to say that quarks move more freely. In this limit, perturbative calculations may be done; however, in the low energy limit, perturbative calculations are no longer possible as the coupling strength rises. As a quark is separated from a color neutral state, the strong force increases until a process called hadronization pairs the two separated states with quark-antiquark pairs until color neutral hadrons are formed. In the Large Hadron Collider (LHC), collisions involve two high energy protons ($uud$): processes involving the hard scattering of the quarks can be calculated perturbatively while soft processes (small transfer of momentum), like the ensuing hadronization, are non-perturbative and require other techniques to calculate.


\chapter{Results}\label{results}

In this chapter, we discuss the results found through the approach outlined in Chapter \ref{methods}. We see that our results match the results published in Ref.~\cite{Jurgenson:2008jp}. We also note the different behavior of the SRG method when used with alternate flow operators.

\section{2-Body}

For the 2-body momentum-space system, the key results for us to reproduce are the 2-body ground state energies in Table \ref{table:negele_params} and the behavior of the SRG using $\hat{G}_s=\hat{T}$ as shown in Fig.~\ref{fig:jurg_2body_ev}. After transforming to the symmetric 2-body harmonic oscillator basis, we can validate our implementation by showing that the 2-body ground state energies are unchanged and the transformed kinetic energy matches the kinetic energy computed directly from the harmonic oscillator basis.

\subsection{Momentum Space SRG}

\begin{figure}[th!]
\begin{center}
\subfloat[$\hat{G}_s=\hat{T}$\label{fig:2body_T_gen}]{\includegraphics[trim={0 3cm 0 0},clip,width=0.25\linewidth]{T_generator}}
\subfloat[Evolution of $\hat{V}_s$\label{fig:2body_T_ev}]{\includegraphics[trim={0 5cm 0 0},clip,width=0.75\linewidth]{T_evolution}}
\end{center}
\caption{Evolution from $\lambda=\infty$ to $\lambda=1$ of the even part of the $\hat{V}_\alpha$ potential in 2-body momentum space with $\hat{G}_s=\hat{T}$ as shown in (a).}
\label{fig:2body_T_full}
\end{figure}

\begin{figure}[th!]
\begin{center}
\subfloat[$\hat{G}_s=\hat{H}_{BD, s=0}$\label{fig:2body_BD_gen}]{\includegraphics[trim={0 3cm 0 0},clip,width=0.25\linewidth]{BD_1_generator}}
\subfloat[Evolution of $\hat{V}_s$\label{fig:2body_BD_ev}]{\includegraphics[trim={0 5cm 0 0},clip,width=0.75\linewidth]{BD_1_evolution}}
\end{center}
\caption{Evolution from $\lambda=\infty$ to $\lambda=1$ of the even part of the $\hat{V}_\alpha$ potential in 2-body momentum space with $\hat{G}_s=\hat{H}_{BD, s}$ as shown in (a).}
\label{fig:2body_BD_full}
\end{figure}

In computing the 2-body Hamiltonian from the Negele potential, we find the 2-body ground state energies to be $-0.920$ for $\hat{V}_\alpha$ and $-0.474$ for $\hat{V}_\beta$, consistent with previous results. Furthermore, the SRG evolution with $\hat{G}_s=\hat{T}$ of $\hat{V}_\alpha$ shown in Fig.~\ref{fig:2body_T_full} matches Fig.~\ref{fig:jurg_2body_ev}. The ground state energy eigenvalues are also preserved up to the error in the numerical solver used, confirming that the SRG method for a 2-body operator in a 2-body basis is unitary. In Fig.~\ref{fig:2body_BD_full}, we show the SRG evolution using a different flow operator, a block diagonal matrix with two blocks defined as
\begin{equation}\label{eq:H_bd_p}
\hat{G}_s = \hat{H}_{BD} = \hat{T} + \hat{V}_s \Theta(p - \Lambda) \Theta(p' - \Lambda) + \hat{V}_s \Theta(\Lambda - p) \Theta(\Lambda - p'),
\end{equation}
where $\Lambda$ is the cutoff momentum that defines the two blocks. For our purposes, we used $\Lambda=2 fm^{-1}$. The value of $\hat{H}_{BD}$ at $\lambda=\infty$ is shown in Fig.~\ref{fig:2body_BD_gen}.

The results of the SRG evolution with this flow operator are shown in Fig.~\ref{fig:2body_BD_ev}. This offers a good way to visualize how alternative generators change the form to which the SRG method evolves operators. The reason for applying SRG to an operator is to reduce the basis size required to accurately preserve low-energy eigenvalues. What this means is that we want the coupling between the low-energy sector we want to keep and the high-energy sector we want to discard to be zero. Applying SRG with $\hat{G}_s=\hat{T}$ does more than this, driving the entire operator toward the diagonal, even in the low-energy block. It is important to note that if all the low-energy physics is contained inside the low-energy block, we do not care if the matrix is diagonal or not in that block; we have already successfully reduced the size of the problem. Alternative flow operators can be chosen to better reflect these goals, and the intuition is that by avoiding doing unnecessary decoupling, SRG with these flow operators may induce smaller many-body forces. We want to put this intuition to the test when we reach the 3-body case.

% The reason for exploring such generators is that SRG with $\hat{G}_s=\hat{T}$ essentially fully diagonalizes the Hamiltonian. SRG with alternative generators that do not force decoupling of slightly off-diagonal elements may do less ``work" and therefore induce fewer many-body forces. We want to put this intuition to the test when we reach the 3-body case.

\subsection{Harmonic Oscillator Space Transformation}
\begin{figure}[t]
\begin{center}
\subfloat[$\hat{V}_\alpha$\label{fig:2body_a_nmax}]{\includegraphics[width=0.5\linewidth]{alpha_2body_nmax}}
\subfloat[$\hat{V}_\beta$\label{fig:2body_b_nmax}]{\includegraphics[width=0.5\linewidth]{beta_2body_nmax}}
\end{center}
\caption{2-body harmonic oscillator basis convergence patterns for (a) $\hat{V}_\alpha$ and (b) $\hat{V}_\beta$ with respect to $N_{max}$.}
\label{fig:2body_nmax}
\end{figure}

To lay the groundwork for exploring the 3-body system, we transform our 2-body operators into a symmetric harmonic oscillator basis. In practice, we truncate our harmonic oscillator basis at some maximum total harmonic oscillator number, $N_{max}$. We use $N_{max}=28$, and we show in Fig.~\ref{fig:2body_nmax} that by this value the 2-body ground state eigenvalue is converged to the value calculated in momentum space to within 0.1\%.

\begin{figure}[t]
\begin{center}
\subfloat[$\hat{T}$ transformed\label{fig:kin_e_transformed}]{\includegraphics[trim={0 0 4cm 0},clip,width=0.43\linewidth]{transform_kin_e}}
\subfloat[$\hat{T}$ from HO basis\label{fig:kin_e_ho}]{\includegraphics[trim={0 0cm 0 0},clip,width=0.57\linewidth]{pure_kin_e}}
\end{center}
\caption{The harmonic oscillator kinetic energy operator as computed (a) via a transformation from the momentum space operator and (b) directly from the harmonic oscillator basis.}
\label{fig:2body_kin_comp}
\end{figure}

As an additional check, we compare the kinetic energy calculated in momentum space and transformed to harmonic oscillator space to the kinetic energy operator computed directly from the symmetric harmonic oscillator basis. We find in Fig.~\ref{fig:2body_kin_comp} that they are the same at low harmonic oscillator number, which corresponds to low energies. At high energies, we see the transform kinetic energy operator stray from the true tridiagonal form of the kinetic energy in harmonic oscillator space. This is caused by ringing due to the truncation of the harmonic oscillator basis. However, this ringing does not affect the low-energy parts of the kinetic energy and thus has no effect on the lowest eigenvalues, the bound state energies we care about preserving. For the 3-body case we will be working with the transformed potential energy and the kinetic energy computed directly from the harmonic oscillator basis, as it is cleaner to calculate and does not have the ringing artifacts.%At high energies, we see the transform kinetic energy operator stray from the true tridiagonal form of the kinetic energy in harmonic oscillator space. This is caused by ringing due to the truncation of the harmonic oscillator basis. However, this ringing does not affect the low-energy parts of the kinetic energy and thus has no effect on the lowest eigenvalues, the bound state energies we care about preserving.

\section{3-Body}

\begin{figure}[t]
\begin{center}
\subfloat[$\hat{V}_\alpha$\label{fig:3body_a_nmax}]{\includegraphics[width=0.5\linewidth]{alpha_3body_nmax}}
\subfloat[$\hat{V}_\beta$\label{fig:3body_b_nmax}]{\includegraphics[width=0.5\linewidth]{beta_3body_nmax}}
\end{center}
\caption{3-body harmonic oscillator basis convergence patterns for (a) $\hat{V}_\alpha$ and (b) $\hat{V}_\beta$ with respect to $N_{max}$.}
\label{fig:3body_nmax}
\end{figure}

For the 3-body system, the key results for us to reproduce are the 3-body ground state energies in Table \ref{table:negele_params} and the induced 3-body force in Fig.~\ref{fig:jurg_vfull} for $\hat{G}_s=\hat{T}$.

\subsection{3-Particle Ground State}

For the 3-body symmetric harmonic oscillator basis, we stay with $N_{max}=28$ in order to replicate the same results as Ref.~\cite{Jurgenson:2008jp}. There is also a performance consideration here, because, while the basis size for a 2-body system scales linearly in $N_{max}$, the basis size for a 3-body system scales quadratically in $N_{max}$. Since at $N_{max}=28$ we are already converged to within 1\% in the 3-body system, as shown in Fig.~\ref{fig:3body_nmax}, by raising $N_{max}$ we would simply be slowing down our ability to test alternative flow generators without any substantial numerical gain. With $N_{max}=28$, we get the 3-body ground state energy to be $-2.563$ for $\hat{V}_\alpha$ and $-1.708$ for $\hat{V}_\beta$, matching the values listed in Table \ref{table:negele_params}.

\begin{figure}[t]
\begin{center}
\subfloat[2-body ground state energy\label{fig:2body_a_w}]{\includegraphics[width=0.5\linewidth]{alpha_2body_w}}
\subfloat[3-body ground state energy\label{fig:3body_a_w}]{\includegraphics[width=0.5\linewidth]{alpha_3body_w}}
\end{center}
\caption{Ground state energy is a smooth function of $\omega$ and thus easy to minimize.}
\label{fig:alpha_w}
\end{figure}

When going from momentum space to harmonic oscillator space, we must optimize $\omega$, the parameter for the harmonic oscillator basis. The optimal $\omega$ will minimize the ground state energy, which will be the best we can do to reproduce the low-energy eigenvalues for a given $N_{max}$. We find that roughly the same value for $\omega$ optimizes both the 2-body ground state energy and the 3-body ground state energy, as shown in Fig.~\ref{fig:alpha_w}.

\subsection{3-Body Force Induction for $\hat{G}_s=\hat{T}$}

We then compare the 3-body ground state values for a Hamiltonian evolved in 3-body systems and a Hamiltonian evolved in the 2-body system and embedded in the 3-body system at each intermediate point during the evolution. We see in Fig.~\ref{fig:heinz_vfull} the same trends as in Fig.~\ref{fig:jurg_vfull}. With this, we have verified the correctness of our framework up to the 3-body system and can now use it to test the 3-body force induction of SRG with alternative flow operators.

\begin{figure}[t]
\begin{center}
\subfloat[$\hat{V}_\alpha$\label{fig:heinz_va}]{\centering\includegraphics[width=0.5\linewidth]{manybody_T_alpha}}
\subfloat[$\hat{V}_\beta$\label{fig:heinz_vb}]{\centering\includegraphics[width=0.5\linewidth]{manybody_T_beta}}
\end{center}
\caption{3-body force induction with $\hat{G}_s=\hat{T}$ leading to error in the computed 3-body ground state energy.}
\label{fig:heinz_vfull}
\end{figure}

\subsection{3-Body Force Induction for Alternative Flow Operators}

We test two parametrizations for an alternative flow operator, $\hat{H}_{BDHO}$, that is block diagonal in harmonic oscillator space, defined as
\begin{equation}
\hat{G}_s = \hat{H}_{BDHO} = \hat{T} + \hat{V} \Theta(N - \Lambda) \Theta(N' - \Lambda),
\end{equation}
where $\Lambda$ is the block cutoff in harmonic oscillator space. We use $\Lambda=6$ and $\Lambda=10$ for our tests. We find that both parametrizations offer a substantial decrease in the induced 3-body force, as shown in Fig.~\ref{fig:heinz_newfull}. In particular, $\Lambda=10$ induces nearly no 3-body force, keeping the 3-body ground state energy within less than 1\% of its true value.

\begin{figure}[th!]
\begin{center}
\subfloat[$\hat{V}_\alpha$\label{fig:heinz_newa}]{\centering\includegraphics[width=0.5\linewidth]{new_alpha}}
\subfloat[$\hat{V}_\beta$\label{fig:heinz_newb}]{\centering\includegraphics[width=0.5\linewidth]{new_beta}}
\end{center}
\caption{3-body force induction for various different generators. We see $\hat{H}_{BDHO}$ leads to a generally smaller induced 3-body force.}
\label{fig:heinz_newfull}
\end{figure}

While these results show promise for $\hat{H}_{BDHO}$ as an improved flow operator, they are still preliminary. It may be the case case that $\hat{H}_{BDHO}$ and $\hat{T}$ decouple off-diagonal matrix elements at different rates with respect to $\lambda$, meaning that $\lambda=1$ for $\hat{T}$ evolutions does not correspond to $\lambda=1$ for $\hat{H}_{BDHO}$ evolutions. While some quick tests ``by eye" suggest this is not the case, it must still be verified more robustly. This can be done by imposing some cutoff on the 2-body space and checking that the $\lambda$ at which both evolutions reproduce the correct ground state energy is similar. If it is not similar, it will be necessary to figure out a mapping of corresponding values of $\lambda$ for the two evolutions.

Additionally, tests must be run that look at 4-body and 5-body forces, in order to ensure induced many-body forces remain strictly smaller than for $\hat{G}_s=\hat{T}$. The \texttt{srg1d} framework also allows us to easily test more flow operators, which we must do to get a more comprehensive idea of what features of the flow operators reduce or enhance many-body force induction.


\chapter{Conclusion}
\label{chap:conclusion}

\section{Future Work}
At this time, the IEEE-754 implementation is essentially complete for \code{float} and \code{double} values. Developers wishing to support cross-platform serialization of only those types may do so with minimal additional work. Support for \code{long double} values, however, is more complex.

Two primary issues affect the serialization of \code{long double} values. First, the detection of 10 byte \code{long double} values that are stored in 16 bytes of memory is somewhat frail. The algorithm proposed in Section~\ref{sec:challenges_ld_size} and implemented in Section~\ref{sec:framework_utilities} relies on the assumption that these implementations to not use the most significant bit of the storage for implementation-specific information. All of the systems tested as part of this thesis did not use that bit; however, implementations are free to use this space for whatever purpose it wishes. By definition, the extra six bytes of the memory location are not part of the IEEE-754 standard. An alternative mechanism of detecting this format would make the framework more robust.

The second issue is support for systems using the x86 Extended Precision format for \code{long double} values. Ideally a system should be implemented so that the usage of this type may be detected dynamically at runtime. The usage of this type is tied to the Intel x87 Hardware Floating-Point Unit. The x86 processor architecture provides the CPUID instruction, which may be used to query for the presence of an x87 FPU \cite{AMD:CPUID}. However, the physical presence of a FPU does not mean that the operating system and/or compiler has chosen to implement the x86 Extended Precision format. For example, a Lenovo X220 laptop was used to provide two of the testing platforms in this thesis. This laptop uses an Intel Core i7 Mobile processor, which includes an x87 FPU\footnote{\url{http://www.intel.com/content/www/us/en/processors/core/CoreTechnicalResources.html}}. When running the Windows operating system, \code{long double} is aliased to \code{double}; when using Linux, the x86 Extended Precision format is used. It seems unlikely that the CPUID instruction alone would be sufficient to detect this format, but perhaps that runtime information could be combined with compile time detection of common operating systems and compilers.

Additional work also remains to be done by implementing the framework for platforms that do not use some form of the IEEE-754 standard.

\section{Summary}
The framework described in this thesis lays the groundwork that developers may use to allow for the serialization of floating-point numbers in a portable manner.

Floating-point numbers that are serialized using this framework are saved to a standard format based on the IEEE-754 floating-point standard. This allows these values to be more easily converted into the format used by a specific target platform. Presented along with the framework is an implementation that supports serialization and de-serialization of floating-point numbers on platforms that support the IEEE-754 standard. In addition, numerous utility functions are provided to assist developers in creating additional implementations.

The variations in floating-point format mean that compromises are inherit in any serialization system. This framework minimizes those compromises by avoiding loss of precision, unless it is required by the target system, as well as maintaining IEEE-754 special values throughout the serialization process.


\subsection{Marginal propensity to consume}


%----------------------------------------------------------------------------
%  related_work.tex
%----------------------------------------------------------------------------

\subsubsection{Region-based memory management}
Tofte and Talpin \cite{8_7} present an inference system for classifying all allocated data of a program into regions and deducing a safe lifetime for each region, which enables provably memory-safe implementations of ML-like languages with-out a garbage collector. Crary et al.'s Capability Calculus \cite{8_6} extends this work by allowing explicit region allocation and deletes, while making sure that all data accesses to a region happen during its lifetime. The commonality of these systems is that only regions are treated linearly; all other objects are allocated within regions and have types akin to guarded types. Regions are not first-class values and cannot be stored in data structures.

\subsubsection{Linear type systems}
Starting with Wadler \cite{8_5}, linear types systems have been used in purely functional languages to enforce single threading on the state of the world or to implement operations like array updating without the cost of a full copy. Linear type systems enable resource management at the granularity of a single object. Every use of an object of linear type consumes the object, leading to a programming style where linear objects are threaded through the computation. Wadler's let! construct, or its variations, can be used to give a temporary nonlinear type to an object of linear type. Walker and Watkins \cite{8_8} study a type system with three kinds of objects: linear, reference counted, and region allocated. The kind of an object is fixed at allocation without a means to change kind. They provide let! only for regions.

\subsubsection{Lighweight static capabilities}
Static capabilities have been implemented by Kiselyov et al. \cite{5_3} in a lightweight fashion in modern functional languages such as OcaML and Haskell. They propose a "style" of programming with three ingredients:
\begin{itemize}
\item A compact kernel of trust that is specific  to the problem domain.
\item Unique names (capabilities) that confer rights and certify properties, so as to extend the trust from the kernel to the rest of the application.
\item Static (type) proxies for dynamic values.
\end{itemize}
The requirements imposed on the host language to implement this style are an expressive core language, higher-rank polymorphism and phantom types. Capabilities are represented as types; safety conditions are stored in types as in dependent-type programming. If a program type-checks, then the type system and the kernel of trust together verify that the safety conditions hold in any run of the program. In most cases, this static assurance costs us no run-time overhead.

\subsubsection{Lightweight Monadic Regions}
Kiselyov et al. \cite{5_1} also build a library that statically ensures the safe use of resources such as file handles. They statically prevent accessing an already closed handle or forgetting to close it. The libraries can be trivially extended to other resources such as database connections and graphic contexts. Their library supports region polymorphism and implicit region subtyping, along with higher-order functions, mutable state, recursion, and run-time exceptions. A program may allocate arbitrarily many resources and dispose of them in any order, not necessarily LIFO. These monadic regions are implemented in Haskell as monad transformers. For contrast, the authors also implement a Haskell library for manual resource management, where deallocation is explicit and safety is assured by a form of linear types. The linear typing is implemented in Haskell with the help of phantom types and a parameterized monad to statically track the type-state of resources.

\subsubsection{Strongly Typed Memory Areas}
Jones et al. \cite{5_4} discuss how to make Haskell suitable for systems programming tasks -including device driver and operating system construction. As a result of some gaps in functionality it often becomes necessary either to code some non-trivial components in more traditional but unsafe languages like C or assembler, or else to adopt aspects of the foreign function interface that compromise on strong typing and type safety. Some of these gaps may be filled by extending a Haskell-like language with facilities for working directly with low-level, memory-based data structures. The authors designed and implemented language features that allow programmers to de?ne strongly typed, high-level views, comparable to programming with algebraic datatypes, on the underlying bitdata structures. A critical detail in making this work is the ability to specify bitlevel layout and representation information precisely and explicitly; this is important because the encodings and representations that are used for bitdata are often determined by third-party speci?cations and standards that must be carefully followed by application programmers and language implementations.

Before Giuseppe's PhD/Functional Approach to Games/MonadicReferenceCounting/trunk/related_work.tex


\documentclass[draft]{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}

\include{macros}

% math fonts
\newcommand{\mbb}[1]{\mathbb{#1}}
\newcommand{\mbf}[1]{\mathbf{#1}}
\renewcommand{\mit}[1]{\mathit{#1}}
\newcommand{\mrm}[1]{\mathrm{#1}}
\newcommand{\mtt}[1]{\mathtt{#1}}
\newcommand{\mcal}[1]{\mathcal{#1}}
\newcommand{\msf}[1]{\mathsf{#1}}

% text fonts
\newcommand{\ttt}[1]{\texttt{#1}}

% formatting
\newenvironment{stackAux}[2]{%
\setlength{\arraycolsep}{0pt}
\begin{array}[#1]{#2}}{
\end{array}}
\newenvironment{stackCC}{
\begin{stackAux}{c}{c}}{\end{stackAux}}
\newenvironment{stackCL}{
\begin{stackAux}{c}{l}}{\end{stackAux}}
\newenvironment{stackTL}{
\begin{stackAux}{t}{l}}{\end{stackAux}}
\newenvironment{stackTR}{
\begin{stackAux}{t}{r}}{\end{stackAux}}
\newenvironment{stackBC}{
\begin{stackAux}{b}{c}}{\end{stackAux}}
\newenvironment{stackBL}{
\begin{stackAux}{b}{l}}{\end{stackAux}}

\newcommand{\stagger}[2]{%
\begin{array}{ccc}%
\multicolumn{2}{l}{#1}&\\%
&\multicolumn{2}{r}{#2}%
\end{array}}

\newcommand{\axiom}[1]{{\displaystyle\strut{#1}}}
\newcommand{\infrule}[2]{{\frac{\displaystyle\strut{#1}}{\displaystyle\strut{#2}}}}
\newcommand{\judge}[2]{\infrule{#1}{#2}}

\begin{document}

\title{Formal Specification of the ML Basis system}
\author{Copyright \copyright\ 2004\\
        Henry Cejtin, Matthew Fluet, Suresh Jagannathan, and Stephen Weeks}
\date{\today}
\maketitle
%
This document formally specifies the ML Basis system (MLB) in {\mlton}
used to program in the large.  The system has been designed to be a
natural extension of Standard ML, and the specification is given in
the style of The Definition of Standard ML~\cite{MTHM97} (henceforeth,
the Definition).  This section adopts (often silently) abbreviations,
conventions, definitions, and notation from the Definition.
%
\section{Syntax of MLB}
For MLB there are further reserved words, identifier classes and
derived forms.  There are no further special constants; comments and
lexical analysis are as for the Core and Modules.  The derived forms
appear in Appendix~\ref{sec:mlb:DerivedForms}.
%
\subsection{Reserved Words}
The following are the additional reserved words used in MLB.
\begin{displaymath}
\mtt{bas} \quad\quad \mtt{basis}
\end{displaymath}
Note that many of the reserved words from the Core and Modules are not
used by the grammar of MLB.  However, as the grammar includes
identifiers from the grammars of the Core and Modules, it is useful to
consider the reserved words from the Core and Modules to be reserved
in MLB as well.
%
\subsection{Identifiers}
The additional identifier class for MLB are $\mrm{BasId}$ (basis
identifiers).  Basis identifiers must be alphanumeric, not starting
with a prime.  The class of each identifier occurence is determined by
the grammatical rules which follow.  Henceforth, therefore, we
consider all identifier classes to be disjoint.
%
\subsection{Infixed operators}
The grammar of MLB does not directly admit fixity directives.
However, the static and dynamic semantics for MLB will import source
files that must be parsed in the scope of fixity directives and that
may introduce additional fixity directives into scope.
Figure~\ref{fig:mlb:S:FixityEnv} formalizes the Definition's notion of
\emph{infix status} as a \emph{fixity environment}.
\begin{figure}[h]
\begin{displaymath}
\begin{array}{rcl}
 & & \mrm{InfixStatus} = \{\mtt{nonfix}\} \cup \bigcup_{d \in \{0,\ldots,9\}} \{\mtt{infix}~d, \mtt{infixr}~d\} \\
\mit{FE} & \in & \mrm{FixEnv} = \mrm{VId} \xrightarrow{\mrm{fin}} \mrm{InfixStatus} \end{array}
\end{displaymath}
\caption{Fixity Environment}\label{fig:mlb:S:FixityEnv}
\end{figure}
%
\subsection{Grammar for MLB}
The phrase classes for MLB are shown in
Figure~\ref{fig:mlb:S:PhraseClasses}.
\begin{figure}[h]
\begin{displaymath}
\begin{array}{ll}
\mrm{BasExp} & \mbox{basis expressions} \\
\mrm{BasDec} & \mbox{basis-level declaration} \\
\mrm{BasBind} & \mbox{basis bindings} \\
\mrm{BStrBind} & \mbox{(basis) structure bindings} \\
\mrm{BSigBind} & \mbox{(basis) signature bindings} \\
\mrm{BFunBind} & \mbox{(basis) functor bindings}
\end{array}
\end{displaymath}
\caption{MLB Phrase Classes}\label{fig:mlb:S:PhraseClasses}
\end{figure}
We use the variable $\mit{basexp}$ to range over $\mrm{BasExp}$, etc.
The conventions adopted in presenting the grammatical rules for MLB
are the same as for the Core and Modules.  The grammatical rules are
shown in Figure~\ref{fig:mlb:S:GrammaticalRules}.
\begin{figure}[h]
\begin{displaymath}
\begin{array}{rcll}
\mit{basexp} & ::= &
\mtt{bas}~ \mit{basdec} ~\mtt{end}
& \mbox{basic} \\&&
\mit{basid}
& \mbox{basis identifier} \\&&
\mtt{let}~ \mit{basdec} ~\mtt{in}~ \mit{basexp} ~\mtt{end}
& \mbox{local declaration} \\

\mit{basdec} & ::= &
\mtt{basis}~ \mit{basbind}
& \mbox{basis} \\&&
\mtt{local}~ \mit{basdec}_1 ~\mtt{in}~ \mit{basdec}_2 ~\mtt{end}
& \mbox{local} \\&&
\mtt{open}~ \mit{basid}_1 \cdots \mit{basid}_n
& \mbox{open ($n \geq 1$)} \\&&
\mtt{structure}~ \mit{bstrbind}
& \mbox{(basis) structure binding} \\&&
\mtt{signature}~ \mit{bsigbind}
& \mbox{(basis) signature binding} \\&&
\mtt{functor}~ \mit{bfunbind}
& \mbox{(basis) functor binding} \\&&
\quad
& \mbox{empty} \\&&
\mit{basdec}_1~\langle\mtt{;}\rangle~\mit{basdec}_2
& \mbox{sequential} \\&&
\msf{path.mlb} &
\mbox{import ML basis} \\&&
\msf{path.sml}
& \mbox{import source} \\

\mit{basbind} & ::= &
\mit{basid} ~\mtt{=}~ \mit{basexp} ~\langle\mtt{and}~ \mit{basbind}\rangle \\
\mit{bstrbind} & ::= &
\mit{strid}_1 ~\mtt{=}~ \mit{strid}_2 ~\langle\mtt{and}~ \mit{bstrbind}\rangle \\
\mit{bsigbind} & ::= &
\mit{sigid}_1 ~\mtt{=}~ \mit{sigid}_2 ~\langle\mtt{and}~ \mit{bsigbind}\rangle \\
\mit{bfunbind} & ::= &
\mit{funid}_1 ~\mtt{=}~ \mit{funid}_2 ~\langle\mtt{and}~ \mit{bfunbind}\rangle
\end{array}
\end{displaymath}
\caption{Grammar: Basis Expressions, Declarations, and Bindings}\label{fig:mlb:S:GrammaticalRules}
\end{figure}
%
\subsection{Syntactic Restrictions}
\begin{itemize}
\item No binding $\mit{basbind}$ may bind the same identifier twice.
\item No binding $\mit{bstrbind}$, $\mit{bsigbind}$ or $\mit{bfunbind}$ may bind the same identifier twice.
\item MLB may not be cyclic; i.e., successively replacing
  $\msf{path.mlb}$ with its parsed $\mrm{BasDec}$ must terminate.
\end{itemize}
%
\subsection{Parsing}
The static and dynamic semantics for MLB will interpret
$\msf{path.sml}$ as a parsed $\mrm{TopDec}$ and
$\msf{path.mlb}$ as a parsed $\mrm{BasDec}$.  Parsing a $\mrm{TopDec}$
takes a fixity environment as input and returns a fixity environment
as output; the output fixity environment corresponds to fixity
directives introduced by and whose scope is not limited by the parsed
$\mrm{TopDec}$.

Paths and parsers are given in Figure~\ref{fig:mlb:S:PathsParser}.  A
(fixed) $\mrm{Parser}$ $\mcal{P}$ provides the interpretation of
$\msf{path.sml}$ and $\msf{path.mlb}$ imports.
\begin{figure}[h]
\begin{displaymath}
\begin{array}{c}
\begin{array}{rcl}
\msf{path.sml} & \in & \mrm{SourcePath} \\
\msf{path.mlb} & \in & \mrm{MLBasisPath}
\end{array} \\
\begin{array}{rcl}
\mcal{P} & \in & \mrm{Parser} =
((\mrm{FixEnv} \times \mrm{SourcePath})
 \xrightarrow{\mrm{fin}} (\mrm{FixEnv} \times \mrm{TopDec}))
\times
(\mrm{MLBasisPath} \xrightarrow{\mrm{fin}} \mrm{BasDec})
\end{array}
\end{array}
\end{displaymath}
\caption{Parser}\label{fig:mlb:S:PathsParser}
\end{figure}
%
For a file extension $\msf{.ext}$, $\msf{path.ext}$ denotes either an
absolute path or a relative path (relative to the $\mrm{BasDec}$ being
parsed) to a file in the underlying file system.  Paths that denote the same
file in the underlying file system are considered equal, though they may
have distinct textual representations.  An implementation
may allow additional extensions (e.g., $\mtt{.ML}$, $\mtt{.fun}$,
$\mtt{.sig}$) in elements of $\mrm{SourcePath}$.  An implementation
may additionally allow path variables to appear in
paths.  $\mrm{Parser}$ could be refined by a \emph{current working
directory}, to formally specify the interpretation of relative paths,
and an \emph{path map}, to formally specify the
interpretation of path variables, but the above suffices
for the development in the following sections.
%
\section{Static Semantics for MLB}
%
\subsection{Semantic Objects}
The simple objects for the MLB static semantics are exactly as for
Modules.  The compound objects are those for Modules, augmented by
those in Figure~\ref{fig:mlb:SS:CompoundObjects}.
\begin{figure}[h]
\begin{displaymath}
\begin{array}{rcl}
\mit{BE} & \in & \mrm{BasEnv} = \mrm{BasId} \xrightarrow{\mrm{fin}} \mrm{MBasis} \\
\mit{M} ~\mrm{or}~ \mit{FE},\mit{BE},\mit{B} & \in &
\mrm{MBasis} = \mrm{FixEnv} \times \mrm{BasEnv} \times \mrm{Basis} \\
\Psi & \in & \mrm{BasCache} = \mrm{MLBasisPath} \xrightarrow{\mrm{fin}} \mrm{MBasis}
\end{array}
\end{displaymath}
\caption{Compound Semantic Objects}\label{fig:mlb:SS:CompoundObjects}
\end{figure}
The operations of projection, injection and modification are as for
Modules.
%
\subsection{Inference Rules}
As for the Core and for Modules, the rules for MLB static semantics
allow sentences of the form
\begin{displaymath}
A \vdash \mit{phrase} \longrightarrow A'
\end{displaymath}
to be inferred.  Some hypotheses in rules are not of this form; they
are called \emph{side-conditions}.  The convention for options is as
in the Core and Modules semantics.

\vspace{2\parsep}
{\large\noindent
\textbf{Basis Expressions} \hfill
\fbox{$\mit{M}, \Psi \vdash \mit{basexp} \longrightarrow \mit{M}', \Psi'$}
}\nopagebreak

\begin{equation}
\judge{
\mit{M}, \Psi \vdash \mit{basdec} \longrightarrow \mit{M}', \Psi'
}{
\mit{M}, \Psi \vdash \mtt{bas}~ \mit{basdec} ~\mtt{end} \longrightarrow \mit{M}', \Psi'
}
\end{equation}

\begin{equation}
\judge{
\mit{M}(\mit{basid}) = \mit{M}'
}{
\mit{M}, \Psi \vdash \mit{basid} \longrightarrow \mit{M}', \Psi
}
\end{equation}

\begin{equation}
\label{eqn:mlb:SS:localDeclaration}
\judge{
\mit{M}, \Psi \vdash \mit{basdec} \longrightarrow \mit{M}_1, \Psi_1 \quad
\mit{M} \oplus \mit{M}_1, \Psi_1 \vdash \mit{basexp} \longrightarrow \mit{M}_2, \Psi_2
}{
\mit{M}, \Psi \vdash \mtt{let}~ \mit{basdec} ~\mtt{in}~ \mit{basexp} ~\mtt{end} \longrightarrow \mit{M}_2, \Psi_2
}
\end{equation}

\begin{samepage}
\noindent
\textit{Comments}:
\begin{itemize}
\item[(\ref{eqn:mlb:SS:localDeclaration})] The use of $\oplus$, here
  and elsewhere, ensures that the type names generated by the first
  sub-phrase are distinct from the names generated by the second sub-phrase.
\end{itemize}
\end{samepage}

\vspace{2\parsep}
{\large\noindent
\textbf{Basis-level Declarations} \hfill
\fbox{$\mit{M}, \Psi \vdash \mit{basdec} \longrightarrow \mit{M}', \Psi'$}
}\nopagebreak

\begin{equation}
\judge{
\mit{M}, \Psi  \vdash \mit{basbind} \longrightarrow \mit{BE}', \Psi'
}{
\mit{M}, \Psi  \vdash \msf{basis}~ \mit{basbind} \longrightarrow \mit{BE}' ~\mrm{in}~ \mrm{MBasis}, \Psi'
}
\end{equation}

\begin{equation}
\judge{
\mit{M}, \Psi  \vdash \mit{basdec}_1 \longrightarrow \mit{M}_1, \Psi_1 \quad
\mit{M} \oplus \mit{M}_1, \Psi_1  \vdash \mit{basdec}_2 \longrightarrow \mit{M}_2, \Psi_2 \quad
}{
\mit{M}, \Psi  \vdash \mtt{local}~ \mit{basdec}_1 ~\mtt{in}~ \mit{basdec}_2 ~\mtt{end} \longrightarrow \mit{M}_2, \Psi_2
}
\end{equation}

\begin{equation}
\judge{
\mit{M}(\mit{basid}_1) = \mit{M}_1 \quad \cdots \quad
\mit{M}(\mit{basid}_n) = \mit{M}_n
}{
\mit{M}, \Psi  \vdash \mtt{open}~ \mit{basid}_1 \cdots \mit{basid}_n \longrightarrow \mit{M}_1 \oplus \cdots \oplus \mit{M}_n, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{B}~\mrm{of}~\mit{M} \vdash \mit{bstrbind} \longrightarrow SE
}{
\mit{M}, \Psi  \vdash \mtt{structure}~ \mit{bstrbind}
\longrightarrow \mit{SE} ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{B}~\mrm{of}~\mit{M} \vdash \mit{bsigbind} \longrightarrow G
}{
\mit{M}, \Psi  \vdash \mtt{signature}~ \mit{bsigbind}
\longrightarrow \mit{G } ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{B}~\mrm{of}~\mit{M} \vdash \mit{bfunbind} \longrightarrow F
}{
\mit{M}, \Psi  \vdash \mtt{functor}~ \mit{bfunbind}
\longrightarrow \mit{F} ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
}{
\mit{M}, \Psi  \vdash \quad \longrightarrow \{\} ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{M}, \Psi  \vdash \mit{basdec}_1 \longrightarrow \mit{M}_1, \Psi_1 \quad
\mit{M} \oplus \mit{M}_1, \Psi_1  \vdash \mit{basdec}_2 \longrightarrow \mit{M}_2, \Psi_2
}{
\mit{M}, \Psi  \vdash \mit{basdec}_1 ~\langle\mtt{;}\rangle~ \mit{basdec}_2 \longrightarrow \mit{M}_1 \oplus \mit{M}_2, \Psi_2
}
\end{equation}

\begin{equation}
\label{eqn:mlb:SS:path.sml}
\judge{
\mcal{P}(\mit{FE}~\mrm{of}~\mit{M}, \msf{path.sml}) = (\mit{FE}', \mit{topdec}) \quad
\mit{B}~\mrm{of}~\mit{M} \vdash \mit{topdec} \Rightarrow \mit{B}'
}{
\mit{M}, \Psi  \vdash \msf{path.sml}  \longrightarrow (\mit{FE}',\{\},\mit{B}'), \Psi
}
\end{equation}

\begin{equation}
\judge{
\Psi(\msf{path.mlb}) = \mit{M}'
}{
\mit{M}, \Psi  \vdash \msf{path.mlb}  \longrightarrow \mit{M}', \Psi
}
\end{equation}

\begin{equation}
\judge{
\msf{path.mlb} \notin \mrm{Dom}~\Psi \quad
\mcal{P}(\msf{path.mlb}) = \mit{basdec} \quad
\{\} ~\mrm{in}~ \mrm{MBasis}, \Psi  \vdash \mit{basdec} \longrightarrow \mit{M}', \Psi'
}{
\mit{M}, \Psi  \vdash \msf{path.mlb}  \longrightarrow \mit{M}', \Psi' + \{\msf{path.mlb} \mapsto \mit{M}'\}
}
\end{equation}

\begin{samepage}
\noindent
\textit{Comments}:
\begin{itemize}
\item[(\ref{eqn:mlb:SS:path.sml})]
Note the use of the Definition's
$\mit{B} \vdash \mit{topdec} \Rightarrow \mit{B}'$.
\end{itemize}
\end{samepage}

\vspace{2\parsep}
{\large\noindent
\textbf{Basis Bindings} \hfill
\fbox{$\mit{M}, \Psi \vdash \mit{basbind} \longrightarrow \mit{BE}', \Psi'$}
}\nopagebreak

\begin{equation}
\judge{
\mit{M}, \Psi \vdash \mit{basexp} \longrightarrow \mit{M}', \Psi' \quad
\langle\mit{M} + \mrm{tynames}~\mit{M}', \Psi' \vdash \mit{basbind} \longrightarrow \mit{BE}'', \Psi''\rangle
}{
\mit{M}, \Psi  \vdash \mit{basid} ~\mtt{=}~ \mit{basexp} ~\langle\mtt{and}~\mit{basbind}\rangle \longrightarrow
\{\mit{basid} \mapsto \mit{M}'\} \langle+ \mit{BE}''\rangle, \Psi'\langle'\rangle
}
\end{equation}

\vspace{2\parsep}
{\large\noindent
\textbf{(Basis) Structure Bindings} \hfill
\fbox{$\mit{B} \vdash \mit{bstrbind} \longrightarrow \mit{SE}$}
}\nopagebreak

\begin{equation}
\label{eqn:mlb:SS:bstrbind}
\judge{
\mit{B}(\mit{strid}_2) = E \quad
\langle\mit{B} + \mrm{tynames}~\mit{E} \vdash \mit{bstrbind} \longrightarrow \mit{SE}\rangle
}{
\mit{B} \vdash \mit{strid}_1 ~\mtt{=}~ \mit{strid}_2 ~\langle\mtt{and}~\mit{bstrbind}\rangle \longrightarrow
\{\mit{strid}_1 \mapsto \mit{E}\} \langle+ \mit{SE}\rangle
}
\end{equation}

\begin{samepage}
\noindent
\textit{Comments}:
\begin{itemize}
\item[(\ref{eqn:mlb:SS:bstrbind})] Note that $\mit{bstrbind} \subset
\mit{strbind}$.  Hence, this rule can be derived from the
Definition's $\mit{B} \vdash \mit{strbind} \Rightarrow \mit{SE}$.
\end{itemize}
\end{samepage}

\vspace{2\parsep}
{\large\noindent
\textbf{(Basis) Signature Bindings} \hfill
\fbox{$\mit{B} \vdash \mit{bsigbind} \longrightarrow \mit{G}$}
}\nopagebreak

\begin{equation}
\label{eqn:mlb:SS:bsigbind}
\judge{
\begin{stackCC}
\mit{B}(\mit{sigid}_2) = \Sigma \quad \Sigma = (\mit{T})\mit{E} \quad
\mit{T} \cap (\mit{T}~\mrm{of}~\mit{B}) = \emptyset \\
\mit{T} = \mrm{tynames}~\mit{E} \setminus (\mit{T}~\mrm{of}~\mit{B}) \quad
\langle\mit{B} \vdash \mit{bsigbind} \longrightarrow \mit{G}\rangle
\end{stackCC}
}{
\mit{B} \vdash \mit{sigid}_1 ~\mtt{=}~ \mit{sigid}_2 ~\langle\mtt{and}~\mit{bsigbind}\rangle \longrightarrow
\{\mit{sigid}_1 \mapsto \Sigma\} \langle+ \mit{G}\rangle
}
\end{equation}

\begin{samepage}
\noindent
\textit{Comments}:
\begin{itemize}
\item[(\ref{eqn:mlb:SS:bsigbind})] Note that $\mit{bsigbind} \subset
\mit{sigbind}$.  Hence, this rule can be derived from the
Definition's $\mit{B} \vdash \mit{sigbind} \Rightarrow \mit{G}$.  As such, the
following comment from the Definition applies:
\begin{quote}
The bound names of $\mit{B}(\mit{sigid}_2)$ can always be renamed to
satisfy $\mit{T} \cap (\mit{T}~\mrm{of}~\mit{B}) = \emptyset$, if necessary.
\end{quote}
\end{itemize}
\end{samepage}

\vspace{2\parsep}
{\large\noindent
\textbf{(Basis) Functor Bindings} \hfill
\fbox{$\mit{B} \vdash \mit{bfunbind} \longrightarrow \mit{F}$}
}\nopagebreak

\begin{equation}
\judge{
\begin{stackCC}
\mit{B}(\mit{funid}_2) = \Phi \quad \Phi = (\mit{T})(\mit{E},(\mit{T}')\mit{E}') \quad
\mit{T} \cap (\mit{T}~\mrm{of}~\mit{B}) = \emptyset \\
\mit{T}' = \mrm{tynames}~\mit{E}' \setminus ((\mit{T}~\mrm{of}~\mit{B}) \cup \mit{T}) \quad
\langle\mit{B} \vdash \mit{bfunbind} \longrightarrow \mit{F}\rangle
\end{stackCC}
}{
\mit{B} \vdash \mit{funid}_1 ~\mtt{=}~ \mit{funid}_2 ~\langle\mtt{and}~\mit{bfunbind}\rangle \longrightarrow
\{\mit{funid}_1 \mapsto \Phi\} \langle+ \mit{F}\rangle
}
\end{equation}
%
\section{Dynamic Semantics for MLB}
%
\subsection{Reduced Syntax}
The syntax of MLB is unchanged for the purposes of the dynamic
semantics for MLB.  However, the $\mrm{Parser}$ $\mcal{P}$ returns a
$\mit{topdec}$ in the reduced syntax of Modules.
%
\subsection{Compound Objects}
The compound objects for the MLB dynamic semantics, extra to those
for the Modules dynamic semantics, are shown in Figure~\ref{fig:mlb:DS:CompoundObjects}.
\begin{figure}[h]
\begin{displaymath}
\begin{array}{rcl}
\mit{BE} & \in & \mrm{BasEnv} = \mrm{BasId} \xrightarrow{\mrm{fin}} \mrm{MBasis} \\
\mit{M} ~\mrm{or}~ \mit{FE},\mit{BE},\mit{B} & \in & \mrm{MBasis} =
\mrm{FixEnv} \times \mrm{BasEnv} \times \mrm{Basis} \\
\Psi & \in & \mrm{BasCache} = \mrm{MLBasisPath} \xrightarrow{\mrm{fin}} \mrm{MBasis}
\end{array}
\end{displaymath}
\caption{Compound Semantic Objects}\label{fig:mlb:DS:CompoundObjects}
\end{figure}
%
\subsection{Inference Rules}
The semantic rules allow sentences of the form
\begin{displaymath}
s, A \vdash \mit{phrase} \longrightarrow A', s'
\end{displaymath}
to be inferred, where $s$, $s'$ are the states before and after the
evaluation represented by the sentence.  Some hypotheses in rules are
not of this form; they are called \emph{side-conditions}. The
convention for options is as in the Core and Modules semantics.

The state and exception conventions are adopted as in the Core and
Modules dynamic semantics.  However, it can be shown that the only
MLB phrases whose evaluation may cause a side-effect or generate an
exception packet are of the form $\mit{basexp}$, $\mit{basdec}$ or
$\mit{basbind}$.

\vspace{2\parsep}
{\large\noindent
\textbf{Basis Expressions} \hfill
\fbox{$\mit{M}, \Psi \vdash \mit{basexp} \longrightarrow \mit{M}', \Psi' / p$}
}\nopagebreak

\begin{equation}
\judge{
\mit{M}, \Psi \vdash \mit{basdec} \longrightarrow \mit{M}', \Psi'
}{
\mit{M}, \Psi \vdash \mtt{bas}~ \mit{basdec} ~\mtt{end} \longrightarrow \mit{M}', \Psi'
}
\end{equation}

\begin{equation}
\judge{
\mit{M}(\mit{basid}) = \mit{M}'
}{
\mit{M}, \Psi \vdash \mit{basid} \longrightarrow \mit{M}', \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{M}, \Psi \vdash \mit{basdec} \longrightarrow \mit{M}_1, \Psi_1 \quad
\mit{M} \oplus \mit{M}_1, \Psi_1 \vdash \mit{basexp} \longrightarrow \mit{M}_2, \Psi_2
}{
\mit{M}, \Psi \vdash \mtt{let}~ \mit{basdec} ~\mtt{in}~ \mit{basexp} ~\mtt{end} \longrightarrow \mit{M}_2, \Psi_2
}
\end{equation}

\vspace{2\parsep}
{\large\noindent
\textbf{Basis-level Declarations} \hfill
\fbox{$\mit{M}, \Psi \vdash \mit{basdec} \longrightarrow \mit{M}', \Psi' / p$}
}\nopagebreak

\begin{equation}
\judge{
\mit{M}, \Psi  \vdash \mit{basbind} \longrightarrow \mit{BE}', \Psi'
}{
\mit{M}, \Psi  \vdash \msf{basis}~ \mit{basbind} \longrightarrow \mit{BE}' ~\mrm{in}~ \mrm{MBasis}, \Psi'
}
\end{equation}

\begin{equation}
\judge{
\mit{M}, \Psi  \vdash \mit{basdec}_1 \longrightarrow \mit{M}_1, \Psi_1 \quad
\mit{M} + \mit{M}_1, \Psi_1  \vdash \mit{basdec}_2 \longrightarrow \mit{M}_2, \Psi_2 \quad
}{
\mit{M}, \Psi  \vdash \mtt{local}~ \mit{basdec}_1 ~\mtt{in}~ \mit{basdec}_2 ~\mtt{end} \longrightarrow \mit{M}_2, \Psi_2
}
\end{equation}

\begin{equation}
\judge{
\mit{M}(\mit{basid}_1) = \mit{M}_1 \quad \cdots \quad
\mit{M}(\mit{basid}_n) = \mit{M}_n
}{
\mit{M}, \Psi  \vdash \mtt{open}~ \mit{basid}_1 \cdots \mit{basid}_n \longrightarrow \mit{M}_1 + \cdots + \mit{M}_n, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{B}~\mrm{of}~\mit{M} \vdash \mit{bstrbind} \longrightarrow SE
}{
\mit{M}, \Psi  \vdash \mtt{structure}~ \mit{bstrbind}
\longrightarrow \mit{SE} ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mrm{Inter}~(\mit{B}~\mrm{of}~\mit{M}) \vdash \mit{bsigbind} \longrightarrow G
}{
\mit{M}, \Psi  \vdash \mtt{signature}~ \mit{bsigbind}
\longrightarrow \mit{G } ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{B}~\mrm{of}~\mit{M} \vdash \mit{bfunbind} \longrightarrow F
}{
\mit{M}, \Psi  \vdash \mtt{functor}~ \mit{bfunbind}
\longrightarrow \mit{F} ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
}{
\mit{M}, \Psi  \vdash \quad \longrightarrow \{\} ~\mrm{in}~ \mrm{MBasis}, \Psi
}
\end{equation}

\begin{equation}
\judge{
\mit{M}, \Psi  \vdash \mit{basdec}_1 \longrightarrow \mit{M}_1, \Psi_1 \quad
\mit{M} + \mit{M}_1, \Psi_1  \vdash \mit{basdec}_2 \longrightarrow \mit{M}_2, \Psi_2
}{
\mit{M}, \Psi  \vdash \mit{basdec}_1 ~\langle\mtt{;}\rangle~ \mit{basdec}_2 \longrightarrow \mit{M}_1 \oplus \mit{M}_2, \Psi_2
}
\end{equation}

\begin{equation}
\label{eqn:mlb:DS:path.sml}
\judge{
\mcal{P}(\mit{FE}~\mrm{of}~\mit{M}, \msf{path.sml}) = (\mit{FE}', \mit{topdec}) \quad
\mit{B}~\mrm{of}~\mit{M} \vdash \mit{topdec} \Rightarrow \mit{B}'
}{
\mit{M}, \Psi  \vdash \msf{path.sml}  \longrightarrow (\mit{FE}',\{\},\mit{B}'), \Psi
}
\end{equation}

\begin{equation}
\judge{
\Psi(\msf{path.mlb}) = \mit{M}'
}{
\mit{M}, \Psi  \vdash \msf{path.mlb}  \longrightarrow \mit{M}', \Psi
}
\end{equation}

\begin{equation}
\judge{
\msf{path.mlb} \notin \mrm{Dom}~\Psi \quad
\mcal{P}(\msf{path.mlb}) = \mit{basdec} \quad
\{\} ~\mrm{in}~ \mrm{MBasis}, \Psi  \vdash \mit{basdec} \longrightarrow \mit{M}', \Psi'
}{
\mit{M}, \Psi  \vdash \msf{path.mlb}  \longrightarrow \mit{M}', \Psi' + \{\msf{path.mlb} \mapsto \mit{M}'\}
}
\end{equation}

\begin{samepage}
\noindent
\textit{Comments}:
\begin{itemize}
\item[(\ref{eqn:mlb:DS:path.sml})]
Note the use of the Definition's
$\mit{B} \vdash \mit{topdec} \Rightarrow \mit{B}'$.
\end{itemize}
\end{samepage}

\vspace{2\parsep}
{\large\noindent
\textbf{Basis Bindings} \hfill
\fbox{$\mit{M}, \Psi \vdash \mit{basbind} \longrightarrow \mit{BE}', \Psi' / p$}
}\nopagebreak

\begin{equation}
\judge{
\mit{M}, \Psi \vdash \mit{basexp} \longrightarrow \mit{M}', \Psi' \quad
\langle\mit{M}, \Psi' \vdash \mit{basbind} \longrightarrow \mit{BE}'', \Psi''\rangle
}{
\mit{M}, \Psi  \vdash \mit{basid} ~\mtt{=}~ \mit{basexp} ~\langle\mtt{and}~\mit{basbind}\rangle \longrightarrow
\{\mit{basid} \mapsto \mit{M}'\} \langle+ \mit{BE}''\rangle, \Psi'\langle'\rangle
}
\end{equation}

\vspace{2\parsep}
{\large\noindent
\textbf{(Basis) Structure Bindings} \hfill
\fbox{$\mit{B} \vdash \mit{bstrbind} \longrightarrow \mit{SE}$}
}\nopagebreak

\begin{equation}
\label{eqn:mlb:DS:bstrbind}
\judge{
\mit{B}(\mit{strid}_2) = E \quad
\langle\mit{B} \vdash \mit{bstrbind} \longrightarrow \mit{SE}\rangle
}{
\mit{B} \vdash \mit{strid}_1 ~\mtt{=}~ \mit{strid}_2 ~\langle\mtt{and}~\mit{bstrbind}\rangle \longrightarrow
\{\mit{strid}_1 \mapsto \mit{E}\} \langle+ \mit{SE}\rangle
}
\end{equation}

\begin{samepage}
\noindent
\textit{Comments}:
\begin{itemize}
\item[(\ref{eqn:mlb:DS:bstrbind})] Note that $\mit{bstrbind} \subset
\mit{strbind}$.  Hence, this rule can be derived from the
Definition's $\mit{B} \vdash \mit{strbind} \Rightarrow \mit{SE} / p$, noting that
the derivation may neither cause a side-effect nor generate an
exception packet.
\end{itemize}
\end{samepage}

\vspace{2\parsep}
{\large\noindent
\textbf{(Basis) Signature Bindings} \hfill
\fbox{$\mit{IB} \vdash \mit{bsigbind} \longrightarrow \mit{G}$}
}\nopagebreak

\begin{equation}
\label{eqn:mlb:DS:bsigbind}
\judge{
\mit{IB}(\mit{sigid}_2) = I \quad
\langle\mit{IB} \vdash \mit{bsigbind} \longrightarrow \mit{G}\rangle
}{
\mit{IB} \vdash \mit{sigid}_1 ~\mtt{=}~ \mit{sigid}_2 ~\langle\mtt{and}~\mit{bsigbind}\rangle \longrightarrow
\{\mit{sigid}_1 \mapsto I\} \langle+ \mit{G}\rangle
}
\end{equation}

\begin{samepage}
\noindent
\textit{Comments}:
\begin{itemize}
\item[(\ref{eqn:mlb:DS:bsigbind})] Note that $\mit{bsigbind} \subset
\mit{sigbind}$.  Hence, this rule can be derived from the
Definition's $\mit{IB} \vdash \mit{sigbind} \Rightarrow \mit{G}$, noting that
the derivation may neither cause a side-effect nor generate an
exception packet.
\end{itemize}
\end{samepage}

\vspace{2\parsep}
{\large\noindent
\textbf{(Basis) Functor Bindings} \hfill
\fbox{$\mit{B} \vdash \mit{bfunbind} \longrightarrow \mit{F}$}
}\nopagebreak

\begin{equation}
\judge{
\mit{B}(\mit{funid}_2) = (\mit{strid}:\mit{I},\mit{strexp},\mit{B}) \quad
\langle\mit{B} \vdash \mit{bfunbind} \longrightarrow \mit{F}\rangle
}{
\mit{B} \vdash \mit{funid}_1 ~\mtt{=}~ \mit{funid}_2 ~\langle\mtt{and}~\mit{bfunbind}\rangle \longrightarrow
\{\mit{funid}_1 \mapsto (\mit{strid}:\mit{I},\mit{strexp},\mit{B})\} \langle+ \mit{F}\rangle
}
\end{equation}

\appendix
\section{Derived Forms}
\label{sec:mlb:DerivedForms}
Figure~\ref{fig:mlb:DF:bindings} shows derived forms for structure,
signature, and functor bindings in MLB.  These derived forms are
a useful shorthand for specifying import and export filters.

\begin{figure}[h]
\begin{center}
\begin{tabular}{|l|l|}
\multicolumn{1}{c}{Derived Form} &
\multicolumn{1}{c}{Equivalent Form} \\
\multicolumn{2}{c}{} \\
\multicolumn{2}{l}{\textbf{(Basis) Structure Bindings} $\mit{bstrbind}$} \\
\hline
$\mit{strid} ~\langle\mtt{and}~ \mit{bstrbind}\rangle$ &
$\mit{strid} ~\mtt{=}~ \mit{strid} ~\langle\mtt{and}~ \mit{bstrbind}\rangle$ \\
\hline
\multicolumn{2}{c}{} \\
\multicolumn{2}{l}{\textbf{(Basis) Signature Bindings} $\mit{bsigbind}$} \\
\hline
$\mit{sigid} ~\langle\mtt{and}~ \mit{bsigbind}\rangle$ &
$\mit{sigid} ~\mtt{=}~ \mit{sigid} ~\langle\mtt{and}~ \mit{bsigbind}\rangle$ \\
\hline
\multicolumn{2}{c}{} \\
\multicolumn{2}{l}{\textbf{(Basis) Functor Bindings} $\mit{bfunbind}$} \\
\hline
$\mit{funid} ~\langle\mtt{and}~ \mit{bfunbind}\rangle$ &
$\mit{funid} ~\mtt{=}~ \mit{funid} ~\langle\mtt{and}~ \mit{bfunbind}\rangle$ \\
\hline
\end{tabular}
\end{center}
\caption{Derived forms of (Basis) Structure, Signature, and Functor Bindings}\label{fig:mlb:DF:bindings}
\end{figure}

\bibliographystyle{alpha}
\bibliography{bib}

\end{document}


%
% Chapter Four

\chapter{RECONSTRUCTION OF THE SPECTRUM}

At RCNP, the raw data  obtained with Grand Raiden was analyzed with  a general purpose analyzer program, Tamii Analyzer, developed by A.Tamii ~\citep{Tamii-ana}.
To extract  clean and optimized spectra with the best possible resolution, events consisting of reaction products of interests without any  unwanted particles, called background, were first selected through the GR spectrometer and were transported to the focal plane. In addition to the particle positions and angles,  data measured by the detectors in the focal plane gave the ToF and energy loss  which were used to further reduce the background.
Finally,  software corrections were applied to correct higher order aberrations to improve the resolution of the spectra. All analyzed results were  stored in the HBOOK file and were plotted using the PAW and ROOT program packages from the CERN library.

\section{Particle Identification and Background Reductions}

In the (d,p) reaction at small scattering angles, most of the particles detected in the focal plane counter were protons - the particles of interests. Any other ``contamination particles'' such as unreacted deuterons and other reaction products had to be prevented from  reaching the focal plane. Neutral particles such as neutrons and $\gamma$-rays produced at the target did not make it to the focal plane through the spectrometer and were not measured by the MWDCs. Therefore, the dominant background particles  measured in this experiment were deuterons. By setting the rigidity acceptance of the spectrometer to the desired proton rigidity, most of the undesirable reaction products including deuterons did not reach the focal plane.
At RCNP, the particle identification for proton events was realized by using time-of-flight (ToF) information and the energy loss difference between the PS1 and PS2 of the GR spectrometer.

The ToF was measured as the time difference between the timing trigger from the plastic scintillator PS1 and the RF signal from the AVF cyclotron. In order to reject deuterons effectively, the corrected  ToF (denoted as RF signals in the analyzer) spectrum was used to be independent of $x_{fp}$ and $\theta_{fp}$, defined as
\begin{equation}
    \label{eq:RFC}
    \begin{aligned}
    RFC = RF - 0.130 \times x_{fp} + 22.0 \times \theta_{fp}
    \end{aligned}
\end{equation}
where RFC is the corrected ToF in channel number (ch), and $x_{fp}$ and $\theta_{fp}$ are the horizontal position in mm and horizontal angle in degree measured in the focal plane, respectively. The position and angle independence of the corrected time RFC is shown in Fig.\ref{fig:RFC}.
\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.6]{graph/ch4/RFC}}
    \caption{The ToF (RF) in  the top panel and the corrected-ToF (RFC) in the bottom panel for horizontal position and horizontal angle measured at the focal plane. The corrected ToF spectra shows  the dependency on  $x_{fp}$ and $\theta_{fp}$.}
    \label{fig:RFC}
  \end{center}
\end{figure}

An independent method of particle identification is achieved by using the differences of energy losses in the two plastic scintillator detectors. When a charged particle passes through a scintillator, the energy loss depends on its charge and velocity given by the Bethe-Bloch formula:
\begin{equation}
    \label{eq:BB_formula}
    \begin{aligned}
    -\frac{dE}{dx} \propto \frac{az^2}{E}
    \end{aligned}
\end{equation}
where $z$, $a$ and $E$ refer to  the charge, mass and energy, respectively.  The energy loss of a charged particle is approximately proportional to the intensity of the light produced in the scintillator. The photons are collected by PMTs on each side of the scintillator. The number of photons arriving at each PMT depend on the position x and can be expressed in terms of the distance from the PMT $x$  as
\begin{equation}
    \label{eq:intensity}
    \begin{aligned}
    I(x) = I_0 \exp(-\frac{x}{l})
    \end{aligned}
\end{equation}
where $I_0$ is the initially produced light intensity and $l$ is the attenuation length of the scintillator. The mean intensity $I_{mean}$ measured at the left and right side of the PMTs is  expressed as
\begin{equation}
    \label{eq:intensity_mean}
    \begin{aligned}
    I_{mean} = \sqrt{I(x)I(L-x)} = I_0 \exp(-\frac{L}{2l}) \propto \Delta E
    \end{aligned}
\end{equation}
where $L$ is the length of the scintillator. As $I_{mean}$ is independent of the position of the ionization $x$, it is a useful method for particle identification. Fig. \ref{fig:PID} shows an example of particle identification using a cut in the  two-dimensional energy loss versus RFC display.

\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.7]{graph/ch4/PID}}
    \caption{Top-left: $\Delta E_1$ vs. ToF plot. Top-right: $\Delta E_2$ vs. ToF cut. Bottom: $\Delta E_1$ v.s. $\Delta E_2$ plot. The red solid lines in these plots were event cuts  used for identifying protons and reducing background particles such as deuterons scattered off the Faraday cups inside the Dipole 1 (D1FC).}
    \label{fig:PID}
  \end{center}
\end{figure}

\section{Track Reconstruction}
As mentioned in the previous chapter, the energy of particles detected in the focal plane is determined using the kinematic equations expressed by scattering positions and angles.
The positions and angles were measured by the MWDCs in  the focal plane, which allows to reconstruct the scattering angle at the target owing to the angular dispersion matching. A voltage of -5000 V was applied to the cathode planes and -500 V to the potential wires in order to optimize the efficiency. The 6 mm spacing of the sense wires for the X-plane and 4 mm spacing for the U-plane were set at ground voltage (Fig. \ref{fig:XUplane} shows the MWDC configuration). The MWDC is designed in such a way that  the electrons, which are produced along the trajectory of a charged particle passing through, drift at a constant velocity  towards the anode under the electric field  between the cathode planes and anode wires, except for the regions nearest to the sense wire. The electrons are collected at the anode wires, generating a negative signal. Particles pass through the MWDCs at about 45$^{\circ}$ and deposit charge on 3 or 4 sense wires, called hits, as shown in Fig. ~\ref{fig:MWDCs}. In the case of a hit with three wires, the focal plane position $p$ is given by
\begin{equation}
    \label{eq:position}
    \begin{aligned}
    p=p_i+d_{sw}\frac{d_{i-1}+d_{i+1}}{d_{i-1}-d_{i+1}}
    \end{aligned}
\end{equation}
where $|d_i|$ is the minimum drift length in a cluster (adjacent to hit wires) with three wires hits, $p_i$ is the position of the $i$-th wire, $d_{i-1}$ and $d_{i+1}$ are the drift lengths to the neighboring sense wires and $d_{SW}$ is the distance between sense wires. The vertical drift lengths $d_{i-1}$, $d_{i}$, $\cdots$ were determined from the drift time recorded by the Time-to-Digital Converter (TDC) and converted to the drift lengths by drift tables. To cover all the signal wires, these drift  tables were calibrated using a spectrum in a  continuum energy region so that the drift length histogram has a flat distribution (Fig.~\ref{fig:drift_time}).

%---
%\begin{figure}[tpb]
%  \begin{center}
%    \centerline{\includegraphics[scale=0.6]{graph/ch4/MWDCs_1}}
%    \caption{X-plane configuration of the MWDC. A sample of the charged particle track is shown together with the cathode planes and anode wires.}
%    \label{fig:MWDCs}
 % \end{center}
%\end{figure}
---%

\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.3]{graph/ch4/XUplane}}
    \caption{Wire configuration of the X-plane and U-plane of the MWDC.}
    \label{fig:XUplane}
  \end{center}
\end{figure}

\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.5]{graph/ch4/drift_time}}
    \caption{Conversion of the drift-time spectrum to the drift length for the position measurement with the MWDC. Example from the X-plane.}
    \label{fig:drift_time}
  \end{center}
\end{figure}

The efficiency of X1 wire plane was determined by
\begin{equation}
    \label{eq:efficiency}
    \begin{aligned}
    \eta_{X1} = \frac{N_{U1\cap X2\cap U2}}{N_{X1 \cap U1 \cap X2\cap U2}}
    \end{aligned}
\end{equation}
where $N_{X1 \cap U1 \cap X2\cap U2}$ refers to the number of events detected in all the four wire planes, and $N_{U1\cap X2\cap U2}$ is the number of events detected in the other three wire planes. The total MWDC efficiency is the product of the efficiencies of all anode wire planes:
\begin{equation}
    \label{eq:efficiency}
    \begin{aligned}
    \eta_{MWDC} = \eta_{X1} \times \eta_{X2} \times \eta_{U1} \times \eta_{U2}
    \end{aligned}
\end{equation}
In this experiment, the efficiencies for each wire plane was 96\% and the total efficiency was 85\%.

\section{Scattering Angle Reconstruction}

%%%%%%%%%%%%%
As mentioned in Section 3.3, the scattering angle of the reaction at the target $\Theta_{scatt}=\sqrt{\theta_{tgt}^2 + \phi_{tgt}^2}$ can be reconstructed from the measurement in the focal plane if the angular dispersion matching condition in horizontal direction and the off-focus mode in vertical direction  are realized, where $\theta_{tgt}$  and $\phi_{tgt}$ refer to the horizontal and vertical scattering angles, respectively. In order to calibrate the relationship between the scattering angle and the focal plane measurements, a multi-hole slit called the ``sieve-slit" (shown in Fig.\ref{fig:sieve_slits}) was placed 585 mm downstream of  the target  while the Grand Raiden spectrometer was set to 10$^{\circ}$. A gold target $^{197}Au$ with the thickness of 1.68 $mg/cm^2$ and a carbon target with a thickness of 1 $mg/cm^2$ were used in order to give spectra that cover the full range of the X-focal plane positions $x_{fp}$. The horizontal and vertical scattering angles were well defined by the geometry of the sieve-slit with respect to the target by the reactions $^{197}$Au(d,d')$^{197}$Au and $^{12}$C(d,p)$^{13}$C, respectively. As  shown in the left panel of Fig.\ref{fig:anglecalib}, the image of the sieve-slit can be seen in the focal plane by the vertical focal plane position ($y_{fp}$) versus horizontal focal plane angle ($\theta_{fp}$) for a given range of the X-focal plane position ($x_{fp}$). With the measured $x_{fp}$ and $\theta_{fp}$ from the 2-dimensional plots of images of the sieve-slit, the horizontal scattering angle $\theta_{tgt}$ was calibrated from the $x_{fp}$ and $\theta_{fp}$ dependent equation:
\begin{equation}
    \label{eq:theta_calib}
    \begin{aligned}
        \theta_{tgt} =  \sum_{i=0}^{2} \sum_{j=0}^{2}  a_{ij} \theta_{fp}^i  x_{fp}^j
    \end{aligned}
\end{equation}
The same method was used for  the vertical scattering angle $\phi_{tgt}$ calibration by the $x_{fp}$, $\theta_{fp}$ and $y_{fp}$ dependent equation:
\begin{equation}
    \label{eq:phi_calib}
    \begin{aligned}
        \phi_{tgt} = \sum_{i=0}^2 \sum_{j=0}^2 \sum_{k=0}^2 b_{ijk} \theta_{fp}^i x_{fp}^j y_{fp}^k
    \end{aligned}
\end{equation}
\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.65]{graph/ch4/sieveslits_1}}
    \caption{Drawing (left side) and photograph of the sieve-slit used to calibrate the scattering angles at the target as a function of the measured focal plane angles and vertical positions.}
    \label{fig:sieve_slits}
  \end{center}
\end{figure}
where the fitting parameters $a_{i}$, $b_{i}$ , $c_{ij}$ and $d_{ij}$ were determined by a multi-dimensional non-linear least squares fit. The calibrated scattering angle from the sieve-slit pattern is shown on the right of the Fig.\ref{fig:anglecalib} as the horizontal angle versus the vertical angle. By applying the calibration equations \ref{eq:theta_calib} and \ref{eq:phi_calib} to the measurements in the focal plane ($x_{fp}$, $\theta_{fp}$ and $y_{fp}$), the horizontal and vertical components of scattering angles of the reaction products can be correlated to the target coordinates, which allows for the determination of the excitation energies populated in the recoil nucleus (parameters listed in Table.~\ref{tb:sieve-slit}).

\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.8]{graph/ch4/angle_cal}}
    \caption{2D histogram of the angular calibration run with the sieve-slit. Left panel: measurement of the vertical focal plane position ($y_{fp}$) versus horizonal angle ($\theta_{fp}$). Each blob is associated with a hole of the sieve-slit. Right Panel: reconstructed pattern at the target position after the angular calibration. Data from $^{197}$Au(d,d��)$^{197}$Au at 10$^{\circ}$.}
    \label{fig:anglecalib}
  \end{center}
\end{figure}

\begin{table}[tpb]
    \setlength{\capwidth}{0.7\textwidth}
    \begin{center}
       \caption{TABLE OF THE PARAMETERS $a_{ij}$ AND $b_{ijk}$ DETERMINED IN EQS.\ref{eq:theta_calib} AND \ref{eq:phi_calib}, RESPECTIVELY.}
       \label{tb:sieve-slit}
       \begin{tabular}{cc||cc|cc|cc}
	\hline
    \hline

    $ij$ & $a_{ij}$     & $ijk$ & $b_{ijk}$ & $ijk$ & $b_{ijk}$  & $ijk$  & $b_{ijk}$  \\
    \hline
     00  &  -2.951E+00  & 000    & -2.085E+00    &  100  &  -6.087E-01     &  200   &    2.110E-02                    \\
     01  &  6.903E+00   & 001    &  1.400E+00    &  101  &  -1.806E-01     &  201   &    1.910E-02                      \\
     02  &  4.812E-02   & 002    &  8.200E-05    &  102  &  4.091E0-05     &  202   &    1.040E-07          \\
     10  &  -2.115E-02  & 010    &  5.009E-05    &  110  &   5.000E-04     &  210   &    -3.000E-04                   \\
     11  &   2.217E-04  & 011    &  -9.012E-04   &  111  &   -3.012E-4     &  211   &    2.000E-05                   \\
     12  &   7.200E-06  & 012    &  1.031E-08    &  112  &   2.001E-07     &  212   &    2.011E-08                 \\
     20  &  -4.524E-06  & 020    &  -1.030E-06   &  120  &   8.052E-07     &  220   &    -7.000E-07                 \\
     21  &  -9.142E-08  & 021    &  3.338E-07    &  121  &   -2.019E-07    &  221   &    6.039E-08             \\
     22  &  2.694E-10   & 022    &  1.100E-09    &  122  &   7.008E-08     &  222   &    -8.000E-09                \\

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

\section{Software Corrections  of Higher Order Aberrations}

Besides the energy spread of the incident beam  that were corrected for the full dispersion matching conditions, there are several additional effects (higher order aberration) that need to be corrected  in order to achieve the best possible resolution.
From the reaction kinematics, it is known that particles emitted from the target at the same excitation energy of residual nucleus with different scattering angles will have different momenta $p = B\rho$ and, therefore different  magnetic rigidities $B\rho$, along with the optical aberrations,  both together hindering the spectrum resolution, especially for large angular acceptances.
These effects can be seen in the $\theta_{tgt}$ versus $x_{fp}$ plot shown on the left two panels in Fig~\ref{fig:software}. Each discrete line with curvature indicates a  state of $^{13}$C populated by the $^{12}$C(d,p)$^{13}$C reaction at 0.5$^\circ$. If projecting each curved line of events down onto the x-position, it will affect the width of the corresponding states, which is the resolution of the spectrum. Scattering particles  with larger angles are transported to the focal plane away from the scattering angle.  This creates the higher order aberrations.

The multipole magnet (MP) of Grand Raiden can be used to correct these aberration, but this  is a time consuming procedure and requires precious beam time. Therefore, to correct the kinematic effect and other higher order aberrations, software corrections were performed by straightening each discrete curved state on the 2-dimensional plots $\theta_{tgt}$ versus $x_{fp}$ and  $\phi_{tgt}$ versus $x_{fp}$ around the value of the central ray ($x_{fp}(\theta_{tgt}=0,\phi_{tgt}=0)$ in this case) using mathematical functions. The correction parameters can be determined by employing the fourth-order polynomial function:
\begin{equation}
    \label{eq:software_theta}
    \begin{aligned}
  x_{fp}'=\sum_{i=0}^2 \sum_{j=0}^4 a_{ij} x^i_{fp} \theta^j_{tgt}
    \end{aligned}
\end{equation}
and
\begin{equation}
    \label{eq:software_phi}
    \begin{aligned}
  x_{fp}''=\sum_{i=0}^2 \sum_{j=0}^4 b_{ij} x'^i_{fp} \phi^j_{tgt}
    \end{aligned}
\end{equation}
The top right plot on Fig~\ref{fig:software} shows the 2-dimensional spectrum $\theta_{tgt}$ versus $x'_{fp}$ where $x'_{fp}$ is the corrected focal plane position given by Eq~\ref{eq:software_theta}. In the analysis the horizontal component of the scattering angle was first corrected with Eq~\ref{eq:software_theta}, followed by the vertical scattering angle correction with Eq~\ref{eq:software_phi}. This procedure allowed to improve the final resolution  from 32 keV to 23 keV at 0.5$^{\circ}$ measurements.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[tpb]
  \begin{center}
    \centerline{\includegraphics[scale=0.6]{graph/ch4/software}}
    \caption{Software corrections. Example of $^{12}$C(d,p)$^{13}$C at 0.5$^{\circ}$ (a) and (b): plots of the horizontal scattering angle $\theta_{scatt}$ and the vertical scattering angle $\phi_{scatt}$ versus the position in the focal plane before and after correction.}
    \label{fig:software}
  \end{center}
\end{figure}

% % uncomment the following lines,
% if using chapter-wise bibliography
%
% \bibliographystyle{ndnatbib}
% \bibliography{example}