%2multibyte Version: 5.50.0.2960 CodePage: 65001

\documentclass[12pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath}

\setcounter{MaxMatrixCols}{10}
%TCIDATA{OutputFilter=LATEX.DLL}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{Codepage=65001}
%TCIDATA{<META NAME="SaveForMode" CONTENT="1">}
%TCIDATA{BibliographyScheme=Manual}
%TCIDATA{Created=Monday, February 29, 2016 10:30:29}
%TCIDATA{LastRevised=Wednesday, March 16, 2016 08:53:36}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="DocumentShell" CONTENT="Standard LaTeX\Blank - Standard LaTeX Article">}
%TCIDATA{CSTFile=40 LaTeX article.cst}

\newtheorem{theorem}{Theorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Conclusion}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{solution}[theorem]{Solution}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\input{tcilatex}
\begin{document}

\subsection{}
Real import growth, as measured by the BLS:
\[
\frac
	{\sum p_{it}m_{it}}
	{\sum p_{i0}m_{i0}}
\frac
	{\sum p_{i0}w_{i}}
	{\sum p_{it}w_{i}}
\]
The first term is the nominal growth of imports. The second term is the inverse of the change in the import price index. The weights of the import price index are $w_i$. If (and only if?) $w_i\equiv m_{it}$ does this equal to a fixed-price import basket as assumed in Kehoe-Ruhl.
\[
\frac
	{\sum
	\frac
		{p_{it}m_{it}}
		{p_{i0}m_{i0}}
		\mu_{i0}}
	{\sum
	\frac
		{p_{it}}
		{p_{i0}}
		\alpha_{i0}}
\]
where $\mu_{i0}=p_{i0}m_{i0}/\sum p_{j0}m_{j0}$ is the base-period share of good $i$ in the import basket, and $\alpha_{i0}=p_{i0}w_{i}/\sum p_{j0}w_{j}$ is the weight assigned by the BLS.

Let $w_i = m_{it}$ if $m_{i0}>0$ and $w_i = 0$ if $m_{i0}=0$. Let
\[
\frac
	{\sum p_{it}m_{it}}
	{\sum p_{i0}m_{i0}}
\frac
	{\sum p_{i0}w_{i}}
	{\sum p_{it}w_{i}}
\]

\subsection{The Kehoe--Ruhl Critique}

Many scholars, including Kehoe and Ruhl (2008), have documented that
terms-of-trade improvements positively impact real GDP. This empirical
result is consistent with the intuitive and fairly old result that
international trade can generate real productivity gains, mediated by
changes in relative prices.

Kehoe and Ruhl (2008), however, argue that the empirical evidence, far from
intuitive, poses a challenge to standard models of international trade.
Specifically, they argue that if GDP is measured as a chain-weighted
quantity index of value added, then terms-of-trade changes (and in
particular, import price changes) should not affect real GDP up to a
first-order approximation. In what follows, we explain their reasoning---and
the solution to their puzzle. In particular, we explain why, contrary to
Kehoe and Ruhl's theoretical result, terms-of-trade changes lead to changes
in measured real GDP, both in practice and in a broad set of models.

Kehoe and Ruhl (2008) focus on a representative firm producing one final
good using a single\ imported material input, denoted by $m_{t}$, and
labour, $l$, the latter fixed over time (or at least not responding to the
material input's price). Production is characterized as%
\begin{equation}
q_{t}=f(l,m_{t})  \label{quant}
\end{equation}%
where $q_{t}$ is the quantity of the final good sold and $f$ is a concave,
continuously differentiable function with constant returns to scale. Nominal
value added is given by:
\begin{equation*}
y_{t}=p_{t}^{y}q_{t}-p_{t}^{m}m_{t}\text{,}
\end{equation*}%
where $p_{t}^{y}$ is the price of output and $p_{t}^{m}$ is the price of the
imported product. Real GDP in Kehoe and Ruhl (2008), is constructed as
output minus the cost of inputs, both evaluated at base year prices,
indicated here by $0$:
\begin{equation}
y_{t}^{\func{real}}=p_{0}^{y}q_{t}-p_{0}^{m}m_{t}.  \label{realgdp}
\end{equation}%
Chain-weighed real GDP growth in Kehoe Ruhl (2008) is defined as:\footnote{%
This formula is another simplification by Kehoe and Ruhl (2008). As
discussed later, the chain-weighted indexes produced by the BLS are actually
based on the Fisher formula, which is a combination of a Paasche and a
Laspeyres index.}%
\begin{equation}
\frac{p_{0}^{y}f(l,m_{t})-p_{0}^{m}m_{t}}{p_{0}^{y}f(l,m_{0})-p_{0}^{m}m_{0}}%
.  \label{chain}
\end{equation}%
As the authors argued, $m_{t}$ is chosen in response to $p_{t}$, so that
\begin{equation*}
f_{m}(l,m_{t})=\frac{p_{t}^{m}}{p_{t}^{y}}.
\end{equation*}%
Taking a first-order Taylor approximation of $q_{t}=f(l,m_{t})$ around $%
m_{0} $,
\begin{equation}
q_{t}=f(l,m_{t})\approx f(l,m_{0})+f_{m}(l,m_{0})(m_{t}-m_{0})=f(l,m_{0})+%
\frac{p_{0}^{m}}{p_{0}^{y}}(m_{t}-m_{0})  \label{result}
\end{equation}%
Substituting $q_{t}$ from (\ref{result}) into (\ref{realgdp}), period-$t$
real GDP (to a first-order approximation) is given by:
\begin{equation*}
y_{t}^{\func{real}}\approx p_{0}^{y}f(l,m_{0})-p_{0}^{m}m_{0},
\end{equation*}%
which is \emph{base-period's} quantities evaluated at base-period's prices.
Hence, the authors conclude that there is no first-order change in the
\textit{measured} chain-weighted quantity index, as can be easily seen by
replacing the latest expression into (\ref{chain}). In other words, any
change in $p_{t}^{m}$ from the base-period price $p_{0}^{m}$ will not affect
measured real GDP.

\subsubsection{Multiple goods}

Kehoe and Ruhl (2008)'s conclusion is correct in the one-good economy they
analyse, which cannot capture the nuisances of price index contruction in a
multiple-good setting. We explain next how in a setting with multiple goods,
their argument breaks down, given the way price indexes are computed in
practice. We focus on a very simple example to keep the parallel with Kehoe
and Ruhl (2008), but the argument goes through in a more complex setting.

Suppose that the input bundle consists of multiple goods indexed by $i$.
Different inputs $i$ are imperfect substitutes, but any single $i$ can be
sourced from either the home country, denoted by $H,$ or the foreign
country, $F$.\footnote{%
To illustrate the idea, consider an input bundle of the form $m_{t}=\left\{
\int_{0}^{1}[m_{Ft}(i)+m_{Ht}(i)]^{\alpha }di\right\} ^{1/\alpha },$ where
different inputs $i$ have a constant elasticity of substituion, and each
input $i$ can be supplied by a foreign or domestic producer.(This particular
functional form is not needed to make our point, which is more general.)
\par
In practice (as in our model), there will be multiple foreign countries
potentially supplying the good. This creates even more margins of supplier
substitution, and will reinfornce the result that changes in prices of
foreign inputs lead to changes in measured real GDP.} In equilibrium, good $i
$ is supplied by the lowest-cost producer. We assume as Kehoe-Ruhl, that
there is a single final good whose price is denoted by $p_{t}^{y}$ and whose
quantity produced is represented by $q_{t}$. Denoting by $p_{Ht}(i)$ the
domestic cost of input $i$ at time $t$; $p_{Ft}(i)$ the cost of good $i$
when bought from the foreign producer; and $m_{Ht}(i)$ and $m_{Ft}(i)$ the
corresponding quantities of the inputs, nominal GDP is given by:
\begin{equation}
y_{t}=p_{t}^{y}q_{t}-\sum\limits_{i\in \mathcal{\Psi }%
_{t}}p_{Ht}(i)m_{Ht}(i)-\sum\limits_{i\in \mathcal{M}_{t}}p_{Ft}(i)m_{Ft}(i)
\label{nominal}
\end{equation}%
where $\mathcal{M}_{t}$ denotes the set of products in which the foreign
supplier is cheaper, $p_{Ht}(i)>p_{Ft}(i),$ so that the goods are imported,
and $\mathcal{\Psi }_{t}$ denotes the set of products in which the domestic
supplier is cheaper: $p_{Ht}(i)\leq p_{Ft}(i)$.

\subsubsection{Real GDP}

What does real GDP look like in this setting? It would be tempting to
replace current-period prices in nominal GDP with base-period prices. This
direct-valuation method is how Kehohe and Ruhl (2008) construct real values
in their one-good economy, but this is not how NIPA series are constructed.
In NIPA, nominal quantities are deflated by \emph{price indices} to obtain
real quantities. More specifically, real GDP is obtained as:
\begin{equation}
y_{t}^{\func{real}}=\underset{\text{real domestic component}}{\underbrace{%
\frac{1}{P_{Ht}}\left[ p_{t}^{y}q_{t}-\sum\limits_{i\in \mathcal{\Psi }%
_{t}}p_{Ht}(i)m_{Ht}(i)\right] }}-\underset{\text{real imports}}{\underbrace{%
\frac{1}{P_{Ft}}\sum\limits_{i\in \mathcal{M}_{t}}p_{Ft}(i)m_{Ft}(i)}},
\label{real}
\end{equation}%
where $\left[ p_{t}^{y}q_{t}-\sum\limits_{i\in \mathcal{\Psi }%
_{t}}p_{Ht}(i)m_{Ht}(i)\right] $ is nominal gross output minus the value of
domestic inputs; $\sum\limits_{i\in \mathcal{M}_{t}}p_{Ft}(i)m_{Ft}(i)$ is
the nominal value of imports; $P_{Ht}$ is the (domestic price index based on
a Fisher formula) and $P_{Ft}$ is the import price index (also based on the
Fisher formula). Price indexes are prepared by the Bureau of Labour
Statistics, which deliberately does not mix up import prices with domestic
prices.\footnote{%
We could assume a different basket for exports and domestic sales, but to
keep matters simple, we maintain the assumption of a single final-use good.}

To understand how terms-of-trade affect measured productivity, note first
that nominal GDP in (\ref{nominal}) increases when the price of foreign
inputs $p_{Ft}(i)$ decrease, all else equal. The question we want to address
now is whether real GDP also increases, once the\ price-index adjustment is
carried out.

Price indexes in general, and $P_{Ft}$ in particular, only measure a subset
of goods, and, more importantly, a \emph{non-random} subset of goods. To be
included in the current price index, a product had to be transacted both in
the base period, as well as in the current period. Intuitively, this biases
the import price index $P_{Ft}$ in (\ref{real}) towards \emph{no change}.
This bias in the import price index is known in the pass-through literature
as the product-replacement bias (see for example Nakamura and Steinsson,
2012). With $P_{Ft}$ relatively unchanged, real GDP is clearly influenced by
the change in current import prices, $p_{Ft}(i)^{\prime }s.$

To illustrate the idea, consider a drop in the foreing price of a given
product $i,$ previously sourced from domestic suppliers. As the foreign
price drops, domestic expenditures switch to the foreign supplier. The
product is hence dropped from the domestic price index $P_{Ht}$ but it does
not enter in the import price index $P_{Ft},$ as this is a new entry for
that product in the index basket. (Recall that two price entries of the same
product are needed for a given product to make it to the index.) Hence,
effectively, the decline in the input price is not recorded in the import
price index $P_{Ft}$ (or the domestic index $P_{Ht}$ for that matter). $%
P_{Ft}$ remains unchanged, and as a consequences $y_{t}^{\func{real}}$
increases with the fall in product $i$'s price, as nominal value added
increases when input expenditures switch to the lower-cost supplier abroad.
(For simplicity, and to keep Kehoe-Ruhl first-order approximation exercise,
we assume here that the actual quantity of the input used in production does
not change, only the supplier changes, but the argument naturally goes
through with quantity adjustments). In what follows, we explain in more
detail the bias towards no change in $P_{Ft}$ and how in the Eaton-Kortum
mechanism, this bias implies that increases in productivity abroad (declines
in import prices), lead to domestic real productivity gains.

\subsubsection{What does the Bureau of Labor Statistics (BLS) measure?}

The price indexes produced by the BLS are weighted averages of price changes
for goods or services that are in the sample in both periods. They are based
on the Fisher formula. The indexes produced cover different components of
output; the import price index in particular is computed over the set of
goods imported in both the current and base period. Calling $0$ the base
period and $t$ the curent period, the actual formula is a weighted average
between the Laspeyres and the Paasche indexes:
\begin{equation*}
P_{Ft}\equiv \left[ \frac{\sum\limits_{i\in \mathcal{M}_{0}\cup \mathcal{M}%
_{t}}p_{Ft}(i)m_{F0}(i)}{\sum\limits_{i\in \mathcal{M}_{0}\cup \mathcal{M}%
_{t}}p_{F0}(i)m_{F0}(i)di}\right] ^{0.5}\left[ \frac{\sum\limits_{i\in
\mathcal{M}_{0}\cup \mathcal{M}_{t}}p_{Ft}(i)m_{Ft}(i)}{\sum\limits_{i\in
\mathcal{M}_{0}\cup \mathcal{M}_{t}}p_{F0}(i)m_{Ft}(i)di}\right] ^{0.5}
\end{equation*}%
As stressed earlier, BLS compares current import prices to the past prices
of the \emph{same good} from the \emph{same supplier}. If a firm switches
from a Mexican to a Chinese supplier, because the latter is cheaper, the BLS
will miss this price change in the index. Moreover, the BLS certainly does
not mix up import prices with domestic prices: it creates separate price
indices. So if the substitution is from an American supplier to a Chinese
supplier, the BLS's index will certainly miss this change in price. (There
is even a risk that a change within Chinese suppliers due to a price change
gets lost in translation.) This implies that both in practice as well as in
models in which price changes lead to a change in suppliers terms of trade
changes will affect measured real GDP.

In the EK model in particular, the switch in suppliers is at the heart of
the productivity gains from trade. In such model, the BLS procedure will not
record any of the price changes in its index, which will remain unchanged,
hence leading to measured productivity gains and increases in real GDP. Put
differently, the Kehoe--Ruhl's argument does not apply in this setting. The
intuition should now be clear. Suppose Chinese goods have become 10 percent
cheaper. Due to the winner-take-all nature of Ricardian competition, the
Chinese will be competitive in a wider range of goods. These goods are off
the radar from the BLS---they have been switched from an American or
higher-cost foreign supplier to Chinese firms. The goods that the BLS \emph{%
does} measure are not a random sample from all goods: they are the ones in
which China is still relatively expensive (otherwise, a switch would have
occurred). The BLS index will hence miss the price change and real value
added will be directly affected by the decline in Chinese input prices.

To sum up, the Eaton-Kortum mechanism can indeed account for the empirical
association between terms of trade and productivity in the data. Indeed,
there is no is no puzzle: changes in measured real GDP capture the foreign
gains in productivity transmitted through lower import prices.\footnote{%
While economists may view this result favourably---gains from trade should
be somehow reflected in real GDP!---it has generated some degree of
discomfort in other cirles. In particular, a series of articles in the
Business Week Review have lamented the fact that real GDP is reflecting
\textquotedblleft ghost\textquotedblright\ gains in productivity---gains
coming from other countries---due to substitution towards lower-cost
suppliers abroad.}

\bigskip

\bigskip

First order appoximation with multiple goods:$m_{t}=\left\{
\sum_{0}^{1}[m_{Ft}(i)+m_{Ht}(i)]^{\alpha }di\right\} ^{1/\alpha }$

\bigskip

\begin{equation}
q_{t}=f(l,m_{t})
\end{equation}%
\begin{equation}
y_{t}^{\func{real}}=\underset{\text{real domestic component}}{\underbrace{%
\frac{1}{P_{Ht}}\left[ p_{t}^{y}q_{t}-\sum\limits_{i\in \mathcal{\Psi }%
_{t}}p_{Ht}(i)m_{Ht}(i)\right] }}-\underset{\text{real imports}}{\underbrace{%
\frac{1}{P_{Ft}}\sum\limits_{i\in \mathcal{M}_{t}}p_{Ft}(i)m_{Ft}(i)}},
\end{equation}

\end{document}


\newpage
	\section*{}
	\textbf{Task}\\
	Prove that the number of pairs of paths of length $2n+2$ sarting at $(0,0)$, ending at the same point, having no other common points and going only up and to the right is equal to $c_n$.\\
	\begin{figure}[h]
		\includegraphics[width=0.5\linewidth]{pic1}
	\end{figure}
	\\
	\textbf{Solution}\\


\documentclass[12pt]{amsart}
\usepackage{geometry} % see geometry.pdf on how to lay out the page. There's lots.
\usepackage{booktabs}
\usepackage{topcapt}
% \geometry{landscape} % rotated page geometry

% See the ``Article customise'' template for come common customisations
\newcommand{\code}[1]{{\tt #1}}

\title{Model Grid Design and Programming Notes}
\author{Greg Tucker}
\date{June 2013} % delete this line to display the current date

%%% BEGIN DOCUMENT
\begin{document}

\maketitle
%\tableofcontents

\section{ModelGrid General}

\subsection{Data structures for grid elements and connectivity}

\begin{table}[htbp]
   \centering
   \topcaption{Grid data structures} % requires the topcapt package
   \begin{tabular}{@{} lccc @{}} % Column formatting, @{} suppresses leading/trailing space
      \toprule

      %\cmidrule(r){1-2} % Partial rule. (r) trims the line a little bit on the right; (l) & (lr) also possible
      Name & Type$^1$ & Indexed by & Description \\
      \midrule
      node\_activecell & list  & nodes & ID of active cell, or None \\
      node\_status 	& NP & nodes & Boundary code \\
      node\_numinlink  & NP & nodes & Number of incoming links  \\
      node\_numoutlink  & NP & nodes & Number of outgoing links  \\
      node\_numactiveinlink  & NP & nodes & Number of incoming active links  \\
      node\_numactiveoutlink  & NP & nodes & Number of outgoing active links  \\
      node\_x & NP & nodes & $x$-coordinate \\
      node\_y & NP & nodes & $y$-coordinate \\
      node\_z & NP & nodes & $z$-coordinate \\
      node\_inlink\_matrix & NP2D & (note 2) & IDs of incoming links, or -1 \\
      node\_outlink\_matrix & NP2D &  (note 2) & IDs of outgoing links, or -1 \\
      node\_active\_inlink\_matrix & NP2D &  (note 2) & IDs of incoming active links, or -1 \\
      node\_active\_outlink\_matrix & NP2D &  (note 2) & IDs of outgoing active links, or -1 \\
      cell\_node & list & cells & ID of associated node \\
      activecell\_node & list & active cells & ID of associated node \\
      active\_cell\_areas & ? & ? & Surface area of cell \\
      link\_fromnode & NP & links & ID of ``from'' node \\
      link\_tonode & NP & links & ID of ``to'' node \\
      link\_length & NP & links & Planview length \\
      link\_face & list & links & ID of face, or None \\
      activelink\_fromnode & NP & links & ID of ``from'' node \\
      activelink\_tonode & NP & links & ID of ``to'' node \\
      \bottomrule
      \multicolumn{4}{l}{$^1$ NP = 1D Numpy array; NP2D = 2D Numpy array} \\
      \multicolumn{4}{l}{$^2$ No.\ nodes by max no.\ in/out links (see text)} \\
   \end{tabular}
   %\caption{Remember, \emph{never} use vertical lines in tables.}
   \label{tab:formulas}
\end{table}

\section{RasterModelGrid}

\subsection{Grid Element Numbers and Numbering}

A basic raster model grid consists of a rectangular matrix of nodes with $R$ rows and $C$ columns. Here I list the numbers and numbering schemes for the various elements in the grid, for the default case in which all perimeter nodes are open boundaries, and all interior nodes and all cells are active. Note that grids with different boundary conditions will have different numbers of active links/edges and active faces.

As a template example, I also list the numbers of elements for a 5-column by 4-row grid in two cases: all open boundaries, and only bottom and right boundaries open.

% Requires the booktabs if the memoir class is not being used
\begin{table}[htbp]
   \centering
   \topcaption{Formulas for numbers of elements in a rectangular grid with $R$ rows and $C$ columns} % requires the topcapt package
   \begin{tabular}{@{} lccc @{}} % Column formatting, @{} suppresses leading/trailing space
      \toprule
      %\multicolumn{2}{c}{Item} \\
      %\cmidrule(r){1-2} % Partial rule. (r) trims the line a little bit on the right; (l) & (lr) also possible
      Element & Formula & $4\times 5$ Grid & $4\times 5$ Grid \\
       &  & (all open) & (right, bottom) \\
      \midrule
      Nodes         & $RC$ & 20 & 20 \\
      Cells           & $(R-2)(C-2)$ & 6 & 6 \\
      Active cells & $(R-2)(C-2)$ & 6 & 6 \\
      Links           & $C(R-1)+R(C-1)$ & 31 & 31 \\
      Active links & $(R-1)(C-2)+(R-2)(C-1)$ & 17 & 12 \\
      Corners      & $(R-1)(C-1)$ & 12 & 12 \\
      Faces         & $(R-1)(C-2)+(R-2)(C-1)$ & 17 & 17 \\
      Active faces & $(R-1)(C-2)+(R-2)(C-1)$ & 17 & 12 \\
      \bottomrule
   \end{tabular}
   %\caption{Remember, \emph{never} use vertical lines in tables.}
   \label{tab:formulas}
\end{table}

By default, the numbering scheme for a raster model grid works as follows. Nodes are numbered starting from the lower left and advancing by columns first, then rows. So, a five-column by four-row grid would have nodes numbered as follows:
\newpage
\begin{verbatim}
        # 15------16------17------18------19
        #  |       |       |       |       |
        #  |       |       |       |       |
        #  |       |       |       |       |
        # 10------11------12------13------14
        #  |       |       |       |       |
        #  |       |       |       |       |
        #  |       |       |       |       |
        #  5-------6-------7-------8-------9
        #  |       |       |       |       |
        #  |       |       |       |       |
        #  |       |       |       |       |
        #  0-------1-------2-------3-------4
\end{verbatim}

Cell numbering follows the same scheme. However, there are no cells associated with the perimeter nodes. In the four-row, five-column example, there are 20 nodes but only six cells. The numbering of the cells is as shown here:
\begin{verbatim}
        # |-------|-------|-------|
        # |       |       |       |
        # |   3   |   4   |   5   |
        # |       |       |       |
        # |-------|-------|-------|
        # |       |       |       |
        # |   0   |   1   |   2   |
        # |       |       |       |
        # |-------|-------|-------|
\end{verbatim}
Note that in this diagram, the lines represent faces and the numbers coincide with nodes.

Links are numbered in the same basic ordering, but starting with all vertical links first, and then proceeding through all horizontal links. Here is an example of link numbering for a five-column by four-row grid:
\newpage
\begin{verbatim}
        #  *--27-->*--28-->*--29-->*--30-->*
        #  ^       ^       ^       ^       ^
        # 10      11      12      13      14
        #  |       |       |       |       |
        #  *--23-->*--24-->*--25-->*--26-->*
        #  ^       ^       ^       ^       ^
        #  5       6       7       8       9
        #  |       |       |       |       |
        #  *--19-->*--20-->*--21-->*--22-->*
        #  ^       ^       ^       ^       ^
        #  0       1       2       3       4
        #  |       |       |       |       |
        #  *--15-->*--16-->*--17-->*--18-->*
\end{verbatim}
In the above diagram, the asterisks are nodes, the lines are links, and the \verb!^! and \verb!>! symbols are meant to indicate the direction of each link (up for vertical links, and to the right for horizontal links).

\subsection{Data structures for node-link connectivity}

There are two basic types of information we wish to store: information about the nodes connected to each link, and information about the links connected to each node.
The first of these is fairly straightforward.
The nodes that form the ``from'' and ``to'' nodes for each are stored in two lists: \code{link\_fromnode} and \code{link\_tonode}. For example, the ID of the ``from'' node of link number 7 is stored in \code{link\_fromnode[7]}.

Storing information about the links connected to ...

%\section{Time tests}
%
%Comparing diffusion code with and without giving gradient or flux as arguments to gradient and flux divergence functions:
%
%20 x 30 grid without: 5.1, 4.9, 4.8, 4.9, 5.0 sec (avg 4.92)
%
%20 x 30 grid with: 4.8, 4.8, 4.9, 4.8, 4.8 sec (avg 4.82)
%%%% notes
%
%Using this alternative to gradient:
%
%        alarray = array(self.active_links)
%        lfna = array(self.link_fromnode)
%        ltna = array(self.link_tonode)
%        fromnodes = lfna[alarray]
%        tonodes = ltna[alarray]
%        sto = s[tonodes]
%        sfrom = s[fromnodes]
%        gradient = (sto-sfrom)/self.dx
%
%        return gradient
%
%has timing: 3.3, 3.3, 3.4, 3.3, 3.3
%
%NOTES
%
%potential algos for activating/deactivating elements (changing boundary condition)
%
%(1) define based on nodes. an active link is one that connects either a pair of active cells, or an active and an open boundary cell.
%
%in this case, we'd have a function like:

%def makeListOfActiveLinks( active_link_list ):
%
%	active_link_list = []
%	for link in range( 0, self.num_links ):
%		fromnode_status = self.node_status[self.link_fromnode[link]]
%		tonode_status = self.node_status[self.link_fromnode[link]]
%		if fromnode_status==INTERIOR and
%		  ( tonode_status==INTERIOR
%		    or tonode_status==OPEN_BOUNDARY ):
%		     	add to list
%		elif tonode_status==INTERIOR and
%		  ( fromnode_status==INTERIOR
%		    or fromnode_status==OPEN_BOUNDARY ):
%			add to list

(2) know the ID numbering scheme for links and set the appropriate ones

\section{Reviewing needs and possible solutions for node-node and node-link connectivity (July 2014, GT)}

Things we need regarding node-link and node-neighbor connectivity:

\begin{enumerate}
\item
Number of neighbor nodes
\item
Number of neighbors connected by active link
\item
Raster: number of D8 neighbors via active link
\item
All neighbor node IDs
\item
All neighbor nodes connected via an active link
\item
Raster: all D8 neighbors connected via active link
\item
All links
\item
All active links
\item
Links / active links ordered CW or CCW
\item
All D8 active links?
\item
All incoming active links
\item
All outgoing active links
\end{enumerate}

\end{document}


\subsubsection{\stid{3.07} Factorization Based Sparse Solvers and Preconditioners for Exascale} \label{subsubsect:strumpack}

\paragraph{Overview}
% \textit{Provide an overview of your project.  You might find that the introductory text from your Fall 2017 Project Summary \url{https://confluence.exascaleproject.org/display/1ST/Fall+2017+ECP+ST+Project+Summaries} useful as a starting draft.}
In this project we will deliver factorization based sparse solvers
encompassing the two widely used algorithm variants: supernodal
(SuperLU library) and multifrontal (STRUMPACK library). STRUMPACK is
further enhanced with scalable preconditioning functionality using
hierarchical matrix algebra. Both libraries are purely algebraic,
applicable to a large variety of application domains. We will address
several challenges that arise in Exascale computing, with the following
focus areas:
(1) Develop novel approximation algorithms that have lower
arithmetic and communication complexity with respect to the input
problem size;
(2) Develop new parallelization strategies that reduce
inter-process communication and expose task parallelism and vectorization
for irregular computations involving sparse data structures to better
use on-node resources;
(3) Integrate our software into the higher level
algebraic solvers such as hypre, PETSc, Trilinos, and collaborate with
ECP application teams for application-specific and hardware-specific tuning
of the parameters space to achieve optimal efficiency of our solvers.

Our solver technology is essential for ECP, because many DOE simulation
and data analysis codes expected to run on the Exascale machines need
solutions of sparse algebraic systems, and many high fidelity simulations
involve large-scale multiphysics and multiscale modeling problems that
generate highly ill-conditioned and indefinite algebraic equations,
for which pure iterative methods such as Krylov and multigrid, albeit
readily parallelizable on large machines, cannot converge to the solution.
The factorization based algorithms being developed in our ECP project
represent an important class of methods that are indispensable building
blocks for solving those numerically challenging problems. Our software
can often be used as a reliable standalone solver, or as a preconditioner
for Krylov iterative methods, or as a coarse grid solver in multigrid
methods, just to name a few.

\paragraph{Key Challenges}
%\textit{Describe what is hard to do, why it is challenging.}
At Exascale we need to address several major challenges:
decreasing amount of memory per core, larger impact of communication
cost and load imbalance, more heterogeneous memory organization.
Our new design of algorithms and codes need to focus on
reducing communication and synchronization and task scheduling
instead of floating point operation throughput. In sparse factorization
methods, we expect new bottlenecks in parts of the code
that previously received little attention. For example, the preprocessing
step involves numerical pivoting for selecting stable pivots and
symbolic factorization, which do not yet parallelize well on manycore
architectures with fine-grained parallelism.
At Exascale, direct solvers are more likely to
be used in a preconditioning strategy, for example, in block Jacobi
preconditioning, in domain decomposition methods or as coarse-grid
solvers in algebraic multigrid, which requires repeated triangular
solves. The challenge here is to mitigate the low arithmetic intensity
and high degree of data dependency.

Compared to iterative methods, the primary bottleneck of direct solvers
is the asymptotically higher growth in memory need and floating point
operations, especially for problems from three-dimensional geometry.
It is imperative to develop novel factorization methods which require
much less memory footprint and data movement.

\paragraph{Solution Strategy}
%\textit{Describe your basic strategy for addressing the challenges.}
We will address these challenges in several thrust areas.
The new techniques will be implemented in the two software packages SuperLU
and STRUMPACK. The former is a widely used sparse direct solver based on
supernodal factorization and the latter is a newer direct
solver/preconditioner package based on multifrontal factorization
and hierarchical low-rank matrix structures.
% Parallel pre-pivoting for both packages.

The improvements for SuperLU will be mainly in two areas: (1) develop
a communication-avoiding 3D factorization code that have provably
lower communication complexity; (2) develop a synchronization-avoiding
triangular solve code to enable more overlap of communications of different
processes at different substitution steps.

In addition to exploiting structural sparsity as SuperLU does, STRUMPACK
also exploits data sparseness in the dense blocks of sparse factors using
low-rank representations, which leads to linear scaling $O(n)$ or $O(n \log n)$
memory and arithmetic complexity for PDEs with smooth kernels.
The developments for STRUMPACK will focus several areas:
(1) develop robust stopping criteria --- both absolute and relative --- for
    adaptive (incremental) randomized sampling scheme to reveal numerical
    ranks in the low-rank compression routine. The goal is to use
    enough samples for stability, but not too many for efficiency;
(2) add OpenMP support for both HSS compression and ULV factorization routines,
    especially use OpenMP task construct to support irregular parallelism.
(3) reduce MPI communication in all stages of the code, including HSS
    construction, ULV factorization and triangular solve;
(4) in addition to HSS, develop codes to support other simpler low-rank
    format, such as HOLDR. The HSS format has asymptotically lower complexity
    than HOLDR, but has larger prefactor constant. We expect HSS to be more
    useful for large-scale problems while HOLDR is more useful for mid-range
    problems;
(5) work with the ECP application teams to examine their specific problem
    characteristics and develop the best clustering/ordering methods to
    reveal low-rank structures.

\paragraph{Recent Progress}
%\textit{Describe what you have done recently.  It would be good to have some kind of figure or diagram in this section.}
We have made significant progress in the following areas:
\begin{enumerate}
\item We developed and evaluated a fully algebraic sparse preconditioner in
      STRUMPACK. On top of the baseline multifrontal direct solver, we use
      low-rank compression in dense frontal matrices to obtain approximate
      factorization. We showed that our MF+HSS preconditioner is more robust
      for numerically hard problems than many alternatives. Our code
      strong scales to over 6000 cores~\cite{ghysels2017-ipdps}
      (Fig.~\ref{fig:strumpack-scaling}).
\item We developed several strategies to enhance scalability of triangular
      solve in SuperLU\_DIST. One is an asynchronous tree-based
      broadcast/reduction scheme which reduces latency and improves
      communication load balance. Another is efficient threading implementation
      and BLAS operations. The new code is 4.4x and 6.1x faster on 4096 cores
      with one and 50 right-hand sides, respectively~\cite{LiuTriSolve2018}
      (Fig.~\ref{fig:superlu-trisolve}).
\item We developed a new communication-avoiding 3D sparse LU factorization
      (IPDPS) algorithm that has provably asymptotic lower communication
      complexity in both latency and volume. The prototype implementation
      in SuperLU\_DIST achieves up to 27x improvement over the baseline
      2D algorithm when run on 24,000 cores of Edison at
      NERSC~\cite{sao2018}.
\item In collaboration with ExaGraph ECP project, we evaluated the performance
      of a parallel pre-ordering algorithm called Approximate-Weight Perfect
      Matching (AWPM) for pivot selection in SuperLU\_DIST.
      For most practical problems (e.g.,DOE apps, and SuiteSparse) the
      weights of the perfect matchings generated by AWPM often within 99\%
      of the optimum. The MPI+OpenMP implementation on Cori at NERSC scales          up to 256 nodes –-- 2500x faster than serial MC64, and up to 114x
      speedup on 256 nodes (17,408 cores) Cori-KNL~\cite{AWPM2018}.
      The interface to AWPM are already implemented in both STRUMPACK and
      SuperLU and are released.
\end{enumerate}
\vspace{-.3in}
\begin{figure}[htb]
\begin{minipage}[b]{0.48\columnwidth}
\centering
\includegraphics[scale=0.45]{projects/2.3.3-MathLibs/2.3.3.07-STRUMPACK-SuperLU/strumpack-scaling.pdf}
\caption{STRUMPACK scaling of three phases.}
\label{fig:strumpack-scaling}
\end{minipage}
\begin{minipage}[b]{0.48\columnwidth}
\centering
\includegraphics[scale=0.45]{projects/2.3.3-MathLibs/2.3.3.07-STRUMPACK-SuperLU/superlu-trisolve-scaling}
\caption{SuperLU triangular solve scaling with 4 matrices.}
\label{fig:superlu-trisolve}
\end{minipage}
\end{figure}

\paragraph{Next Steps} Our future efforts will focus on the following areas:
%\textit{Describe what you are working on next.}
\begin{itemize}
\item For STRUMPACK, we will improve the performance of the HSS solve
      routine, add OpenMP and reduce communication. We will implement
      the HOLDR low-rank format.
\item For both STRUMPACK and SuperLU, we will build detailed performance
      models and performance specific code optimizations for the ECP
      applications that use our solvers.
\end{itemize}


\chapter{Nuclear force-solutions}
\begin{abox}
	Practice set 1 solutions
	\end{abox}
\begin{enumerate}
	\item The range of the nuclear force between two nucleons due to the exchange of pions is $1.40 \mathrm{fm}$. If the mass of pion is $140 \mathrm{MeV} / \mathrm{c}^{2}$ and the mass of the rho-meson is $770 \mathrm{MeV} / \mathrm{c}^{2}$, then the range of the force due to exchange of rho-mesons is
	{\exyear{NET JUNE 2017}}
	\begin{tasks}(2)
		\task[\textbf{A.}](a) $1.40 \mathrm{fm}$
		\task[\textbf{B.}]$7.70 \mathrm{fm}$
		\task[\textbf{C.}]$0.25 \mathrm{fm}$
		\task[\textbf{D.}]$0.18 \mathrm{fm}$
	\end{tasks}
\begin{answer}
	Range for nuclear force between nucleon will be $R=c \Delta t=\frac{\hbar c}{m c^{2}}$ and $\hbar c=199 \mathrm{MeVfm}$\\
	$\Rightarrow R=\frac{199 \mathrm{MeVfm}}{770 \frac{\mathrm{MeV}}{c^{2}} \times c^{2}} \approx 0.25 \mathrm{fm}$
\end{answer}
\end{enumerate}
\newpage
\begin{abox}
	Practice set 2 solutions
	\end{abox}
\begin{enumerate}
\item The ground state wavefunction of deuteron is in a superposition of $s$ and $d$ states. Which of the following is NOT true as a consequence?
{\exyear{GATE 2010}}
\begin{tasks}(2)
	\task[\textbf{A.}] It has a non-zero quadruple moment
	\task[\textbf{B.}]The neutron-proton potential is non-central
	\task[\textbf{C.}] The orbital wavefunction is not spherically symmetric
	\task[\textbf{D.}]The Hamiltonian does not conserve the total angular momentum
\end{tasks}
\begin{answer}
	The correct option is \textbf{(d)}
\end{answer}
\item Deuteron has only one bound state with spin parity $1^{+}$, isospin 0 and electric quadrupole moment $0.286 \mathrm{efm}^{2}$. These data suggest that the nuclear forces are having
{\exyear{GATE 2012}}
\begin{tasks}(2)
	\task[\textbf{A.}] only spin and isospin dependence
	\task[\textbf{B.}] no spin dependence and no tensor components
	\task[\textbf{C.}]spin dependence but no tensor components
	\task[\textbf{D.}]spin dependence along with tensor components
\end{tasks}
\begin{answer}
The correct option is \textbf{(d)}
\end{answer}
\item Which of the following statements is NOT correct?
{\exyear{GATE 2016}}
\begin{tasks}(2)
	\task[\textbf{A.}] A deuteron can be disintegrated by irradiating it with gamma rays of energy $4 \mathrm{MeV}$.
	\task[\textbf{B.}] A deuteron has no excited states.
	\task[\textbf{C.}] A deuteron has no electric quadrupole moment.
	\task[\textbf{D.}] The ${ }^{1} S_{0}$ state of deuteron cannot be formed.
\end{tasks}
\begin{answer}
	The correct option is \textbf{(c)}
\end{answer}
\end{enumerate}

Nuclear and particle properties/chapter/nuclear force solutions.tex


\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{a4wide}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\usepackage{hyperref}

\usepackage{graphicx}

\title{Swarm intelligence: Ant colony optimization project}
\author{Samuel Buchet: 000447808}
\date{June 2017}

\begin{document}

\maketitle

\section*{Introduction}

In this project, two ant colony optimization algorithms are implemented to solve the Closest String Problem.
The two algorithms implemented are the Max Min Ant System algorithm (MMAS) and the Ant Colony System algorithm (ACS).
In the following report, the two algorithms are first described.
After that, the two algorithms are compared.
Finally, a local search is used to improve the results.

\section{Implementation of the algorithms}

In this section, the Max Min Ant System and the Ant Colony System algorithms are described.
These two agorithms also use a heuristic information which is explained below.

\subsection{Heuristic information}

In \cite{aco_csp}, no heuristic information is used.
However, most of the ant colony algorithms use this kind of information.
In addition, it can be easily computed for a lot of problems.
It has been decided to define one for the closest string problem. \newline

The goal of the closest string problem is to minimize the maximum hamming distance between the solution and the set of strings.
To minimize the distance between the solution and the set of strings, a greedy decision consists in adding into the solution the character which appears the most in the set of strings at a given position.
Indeed, by using this character, the distance might be equal to 0 at this position.
For each character at each position of the string, a greedy score can be defined as the frequency of the character.\newline

However, the frequencies might be very close to each other.
As a result, if this score is used in the probabilities, the probabilities of getting the best greedy character would be very low.
To solve this problem, the exponential function is applied to the score after scaling it.
The final score of character $j$ at position $i$ is equal to: $score_{ij} = \frac{exp(5*frequency_{ij})*1.5}{max_j(frequency_{ij})}$ where $frequency_{ij}$ is the number of occurences of the character $j$ at position $i$ in the set of string of the problems.
The parameters have been chosen after testing different values.

\subsection{Basic ant system algorithm}

Both variants of the ant colony algorithms implemented in this project rely on the same basis.
At each iteration, the general algorithm builds $n$ solutions (with $n$ equal to the size of the population) and then updates the pheromones with the formula: $\tau_{ij}(t) = (1-\rho)*\tau(t-1) + \sum \limits_{k=1}^m \Delta \tau_{ij}^k$  where $\tau_{ij}(t)$ is the amount of pheromone at position $i$ for character $j$ after t iterations, $\rho$ is the evaporation rate and $\tau_{ij}^k$ is the quantity of pheromone deposited by ant $k$ if this ant have chosen character $j$ at position $i$. \newline

As seen in \cite{aco_csp}, the amount of pheromone deposited by the ants is equal to $1-\frac{HD}{m}$ where HD is the maximum hamming distance of the ant and $m$ is the length of the strings of the problem.
This quantity has been used in the two implementations of this project. \newline

To build a solution, each character is chosen according to a probabilty.
The probability of choosing the character $j$ at position $i$ is equal to $ \frac{greedyScore_{ij}^{\alpha} * \tau_{ij}^{\beta}}{\sum probas}$ where $greedyScore$ is the greedy score described previously and $\tau_{ij}$ is the amount of pheromone at position $i$ for the character $j$.

\subsection{Max Min Ant System}

In the Min Max Ant System algorithm, the pheromones are constrained with an upper and a lower bound.
At the begining of the algorithm, the pheromones are initialised to $+\infty$.
After each pheromone updates, the pheromones are checked.
If it exeeds the lower or the upper bound, the pheromone is re-assigned to this bound. \newline

In this implementation, the upper bound is equal to $1-\rho*\frac{D_{best}}{m}$ where $D_{best}$ is the value of the best solution found so far and $m$ is the length of the string.
The lower bound of the pheromones is equal to $\frac{up}{a}$ where $up$ is the upper bound and a is a parameter.
These two bound are updated each time a better solution is found.\newline

In this Max Min Ant System implementation, the best solution of a population generation is the only one which deposits pheromones.
An addition component is used to prevent the algorithm from converging.
If a convergence is detected, the pheromones are re-initialised to the upper bound.
The convergence is detected by a certain number of iterations without any improvements of the best solution found.
This number of iterations is equal to $iterations*convRate$ where $iterations$ is the maximum number of iterations allowed to the algorithm and $convRate$ is a parameter, between $0$ and $1$ which determines the percentage of the total time allowed to wait before pheromones re-initialisation.

\subsection{Ant Colony System}

The Ant Colony System algorithm is usefull to control the trade off between exploration and intensification.
In this variant, a additional rule is can be used to build a solution.
With probability $q_0$, the artificial ant chooses the character $j$ at position $i$ which maximizes $\tau_{ij}*\eta_{ij}^{\beta}$, where $\tau_{ij}$ is the amount of pheromones at position $i$ for the character $j$, $\eta_{ij}$ is the heuristic information for the same character and $q_0$ is a new parameter of the algorithm.
With probability $1-q_0$, the previous rule is applied (biased exploration).\newline

The pheromones update, which takes place after building the solutions of the population, is also modified.
Only the best ant so far deposits pheromones.
The amount of pheromones deposited is the same as before, but it is multiplied by the parameter $\rho$.
To finish, a new local update rule of the pheromones is used to introduce diversification.
During the construction of the solutions, for each decision chosen by the ants, the pheromones corresponding to that decision is updated as following: $\tau_{ij}=(1-\rho)*\tau_{ij}+\rho*\tau_0$, where $\tau_{ij}$ is the amount of pheromones for this decision and $\tau_0$ is the initial amount of pheromones.

\section{Parameter settings}

Parameter settings is a crucial step.
The ant colony optimization algorithms contain a lot of parameters and they are efficient only for a narrow range of values. \newline

\subsection{Process}

To make the tuning easier, the assumption that the parameters are not completely dependent is made.
This means that if a value which gives very good solutions is found for a parameter, the solution qualities will not change a lot by slightly modifying the other parameters.
With this assumption, a good setting can be found by modifying one parameter at a time.
If a significant improvement is found with a certain parameter, the other parameters can be re-tuned to continue improving the algorithm.
This process can be repeated with multiple instances until no significant changes are found anymore.\newline

To tune the parameters, it is also possible to display the informations of the algorithm during the execution of some instances.
For example, during the tuning phase of the algorihtms, the best solution found so far was displayed each time a better solution was found.
By doing this, it is possible to detect if the algorithm converges and if the total budget is used.
If no improvement occurs long before the end of the execution, this could mean that the algorithm has converged.
It can be checked by displaying the pheromones and it can be resolved by changing the $\rho$ value.\newline

To analyse the performance of the tuning, the solution returned by the algorithm can also be compared to a greedy solution.
The greedy solution can be generated by taking the character which maximizes the heuristic score described in section 1.
If the result of the ant colony algorithm is not better than the result of the greedy one, it could mean that the ant colony algorithm completely rely on the heuristic information and that the $\alpha$ and $\beta$ parameters should be modified.

\subsection{Max Min settings}

The number of ants has been set to $10$ in this algorithm, as done in \cite{aco_csp}.
With the same number of iterations, a higher value could give better results but it would require more evaluations.
The $\rho$ parameter should seem to be high comparing to \cite{aco_csp} (0.03).
However, the pheromones bounds and the pheromone re-initialisation prevent the algorithm form converging.
In order to properly use the pheromones, the $a$ parameter should be quite high.
However, higher values did not give better results, which can be caused by the very low value of the upper bound.
To finish, the $convRate$ parameter (percentage of the maximum number of iterations to wait before) has been adapted to keep enough time for intensification.\newline

\begin{tabular}{c|c}
    Parameter & Value \\ \hline
    $ants$    & 10    \\
    $\alpha$  & 1.8   \\
    $\beta$   & 2     \\
    $\rho$    & 0.12  \\
    $a$       & 60    \\
    $convRate$& 0.16  \\
\end{tabular}

\subsection{Ant Colony System settings}

In this algorithm, the number of ants is the same as before.
We can see that the value of $\rho$ is very low compared to the previous settings.
This can be explained by the fact that there is no bounds on the pheromones and no re-initialisation.
The initial amount of pheromone is also very low compared to the previous one ($+\infty$ for the max min ant system).
This value can be related to the percentage of the initial pheromone value deposited by all the ants during the construction of the solutions.
Finally, the $q_0$ parameter is greater than $0.5$ which means that the intensification rule is chosen more often. \newline

\begin{tabular}{c|c}
    Parameter        & Value \\ \hline
    $ants$           & 10    \\
    $\alpha$         & 1.2   \\
    $\beta$          & 2.5   \\
    $\rho$           & 0.015 \\
    $q_0$            & 0.6   \\
    $initPheromones$ & 0.026 \\
\end{tabular}

\section{Comparison of the algorithms}

To compare the algorithms, the relative percentage deviation has been computed with the mean of the 10 executions of each algorithm on each instance.

\subsection{Relative Precentage Deviations}

The table bellow shows the min, the max, the mean and the standard deviation of the relative percentage deviations.

As we can see, the value for the Min Max algorithm is always lower than the value of the Ant Colony System algorithm. \newline

To conclude that there is a statistically significant difference between the two algorithms, we can perform a Wilcoxon rank-sum test.
The test performed with a significance level equal to $0.05$ returns a p-value equal to $0.154$.
The p-value is greater than the significance level, which means that the null hypothesis is not rejected.
Thus, we cannot conclude that there is a statistically significant difference between the rpd of the two algorithms.
There is no algorithm which is statistically better than the other one.
However, regarding the results on the table bellow, we could recommend the Max Min algorithm, without any guarantee.

\subsection{Correlation of the rpd's}

The plot \ref{fig:corr} shows the correlation between the rpd's of the two algorithms for all instances.
Each color corresponds to the instances with a same number of characters in the alphabet. \newline

\begin{figure}
    \centering
        \includegraphics[scale=0.5]{correl}
    \caption{Correlation plot between the arpd's}
    \label{fig:corr}
\end{figure}

We can see that the rpd's of the rwo algorithms are correlated.
This can be confirmed with a spearman test.
With a significance level equal to $0.05$, the test returns a p-value equal to $8.085*10^{-6}$ which means that the results are correlated.
We can see on the graph that the instances with 20 characters are the most difficult.
The correlation shows that the more an instance is difficult for one algorithm, the more this instance will be difficult for the second algorithm.
This observation sows that the algorithm have a similar behaviour on the problem.

\subsection{Convergences of the algorithms}

The two plots \ref{fig:conv1} and \ref{fig:conv2} can be used to compare the convergence of the two algorithms.
These plots have been done using the same tuning with a number of iterations equal to 2000 to have enough time to observe the convergence.\newline

On both plots, we can see that the the Max Min algorithm is able to reach a better solution.
However, on the first plot, we can see that at the begining of the run, the Ant Colony System algorithm find better solutions than Max Min Ant System.
This result is not clear on the second plot but it could mean that for some instances, if the budget is very limited, it would be preferable to use the Ant Colony System Algorithm. \newline

On the first plot, we can see that the convergence of Ant Colony System is faster, which can be explained by the fact that it does not have a pheromone re-initialisation process like Max Min Ant System.
However, on the second plot, we can see that the convergence of the Ant Colony System algorithm is slower.

\begin{figure}
    \centering
        \includegraphics[scale=0.5]{conv-2-30}
    \caption{Convergence on 2-30-10000-1-9}
    \label{fig:conv1}
\end{figure}

\begin{figure}
    \centering
        \includegraphics[scale=0.5]{conv-20-10}
    \caption{Convergence on 20-10-10000-1-9}
    \label{fig:conv2}
\end{figure}

\section{Local search}

To improve the result of the algorithm, it is possible to execute a local search.
In this project, the local search is applied to the Max Min Ant System Algorithm.

\subsection{Principle}

The principle of a local search is to perform few modifications on a solution.
These modifications create new solutions which are calle neighbours.
These solution can be evaluated and hopefully replace the best solution found so far.
Once a better solution is found, the process can be executed again on this new solution.

\subsection{Application to the Closest String Problem}

The neighbourhood chosen is the set of solutions that differs with only one character from the initial solution.
The local search algorihtm implemented iterates over all the neighbours and select the best one. (best improvement rule)
If the best neighbour is better than the best solution found so far, the process is restarted with this new solution. \newline

To implement the local search efficiently, the evaluation of the solution needs to be fast.
In this problem, this is possible by keeping the distances of each strings in the memory and comparing the new character of the solution to the previous one to update the distance ifnecessary.
However, the execution of the local search after each improvement remains slow.
For this reason, the local search is only applied at the end of the algorithm, on the best solution found.

\subsection{Comparisons with the local search}

The Max Min variant with the local search executed at the and has been tested with 10 runs on each instances, the the same seed used for the previous tests. \newline

The table in \ref{app:rpd}, contains the relative percentage deviations from the upper bound.
In the table \ref{app:rpdsum}, we can see that the local search improves the results of the Max Min algorithm.
Once again, it is possible to execute a wilcoxon test to see if there is a statistically sifgnificant difference between the solution qualities of the Max Min algorithm and the Max Min + loca search. \newline

With a significance level equal to 0.05, the Wilcoxon test returns a p-value equal to 0.693.
So it is not possible to conclude that there is a significant difference between the solution qualities.
However, it is obvious that the local search cannot return worst result.
It can be preferable to use the local search if this step does not take too much time. \newline

To finish, it is also possible to apply the Wilcoxon test to compare the results between the solution qualities of the Max Min + local search and the Ant Colony System algorithm.
With the same significance level, the p-value returned is equal to 0.130, which does not give another conclusion.

\subsection{Parameter settings with the local search}

The parameter settings of the Max Min Ant System has been re-executed after the addition of the local search.
However, as said before, the local search is only applied at the end of the algorithm.
Then, the local search does not change the best tuning.
Nevertheless, we can observe that the bigger the deviation to the upper bound is, the more efficient the local search is.
Thus, if the tuning is not efficient, the local search can still make the result interesting.

\section*{Conclusion}

To conclude, we can see that the ant colony algorithms can be very efficient on combinatorial optimization problems like the Closest String one.
The comparison of the two algorithms shows that with good parameter settings, the different algorithms are very close in terms of quality.
However, the convergences comparison shows that they do not have exactly the same behaviours.
Thus some algorithms could be more interesting to obtain very high quality fast and others could be interesting to get very close to the optimal solution.
One of the main difficulty of the ant colony algorithms remains the parameter settings.
Multiple techniques have been used but the help of automatic parameter settings algorithms might be usefull to improve the results of the algorithms.

\section{Appendices}

\subsection{Appendix A}

The table bellow shows the relative percentage deviations of the solutions' means from the upper bound for all the algorithms implemented.
MMAS means Max Min Ant System, ACS means Ant Colony System and MMAS LS corresponds to The Max Min Ant System with the local search.\\

\label{app:rpd}

\begin{tabular}{c|c|c|c}
instance & MMAS rpd & ACS rpd & MMAS LS rpd \\
\hline
20-10-10000-1-9 & 0.005 & 0.051 & 0 \\
20-20-10000-1-7 & 0.134 & 0.220 & 0.119 \\
20-30-10000-1-5 & 0.150 & 0.211 & 0.139 \\
20-40-10000-1-3 & 0.209 & 0.266 & 0.183 \\
20-50-10000-1-1 & 0.308 & 0.357 & 0.294 \\
2-30-10000-1-9 & 0.327 & 0.605 & 0.281 \\
2-30-10000-2-8 & 0.356 & 0.611 & 0.304 \\
2-40-10000-1-7 & 0.766 & 1.034 & 0.755 \\
2-40-10000-2-6 & 0.546 & 0.724 & 0.480 \\
2-50-10000-1-5 & 0.583 & 0.810 & 0.607 \\
2-50-10000-2-4 & 0.696 & 0.914 & 0.653 \\
4-20-10000-1-2 & 0.208 & 0.396 & 0.174 \\
4-20-10000-2-3 & 0.073 & 0.109 & 0.081 \\
4-30-10000-1-1 & 0.205 & 0.334 & 0.199 \\
4-30-10000-2-0 & 0.198 & 0.262 & 0.180 \\
4-40-10000-1-9 & 0.394 & 0.498 & 0.375 \\
4-40-10000-2-8 & 0.130 & 0.164 & 0.140 \\
4-50-10000-1-7 & 0.419 & 0.542 & 0.400 \\
4-50-10000-2-6 & 0.040 & 0.056 & 0.040 \\
\end{tabular}

\subsection{Appendix B}

The table bellow shows the maximum, the minimum, the mean and the standard deviation of the relative percentage deviations for each algorithms.\\

\label{app:rpdsum}

\begin{tabular}{c|c|c|c|c}
    algorithm & min & max & mean & sd \\
    \hline
    MMAS & 0.005 & 0.766 & 0.303 & 0.219 \\
    ACS & 0.051 & 1.034 & 0.430  & 0.292 \\
    MMAS + LS & 0 & 0.755 & 0.284 & 0.213
\end{tabular}\\

\begin{thebibliography}{2}

\bibitem{aco_csp} Simone Faro and Elisa Pappalardo.
Ant-CSP: An Ant Colony Optimization Algorithm for the Closest String Problem, pages 370-381.
Springer Berlin
Heidelberg, Berlin, Heidelberg, 2010.

\end{thebibliography}

\end{document}


% This file contains the content for a main section
\regularsectionformat
%% Modify below this line %%
\chapter{Examples}
\label{sec:examples}

This section illustrates some of the typical forms of the LUT format. It should be noted that these are not real examples.

The simplest form is an XML file containing a single node:

\begin{lstlisting}[caption=Example of a ``LUT1D'']
<?xml version="1.0" encoding="UTF-8"?>
<ProcessList xmlns="urn:NATAS:ASC:LUT:v1.2" id="ex1" name="example 1 transform">
	<Description> Turn 4 grey levels into 4 inverted codes using a 1D </Description>
	<LUT1D id="lut-23" name="4valueLut" inBitDepth="12i" outBitDepth="12i">
		<Description> 1D LUT </Description>
		<Array dim="4 1">
			3
			2
			1
			0
		</Array>
	</LUT1D>
</ProcessList>
\end{lstlisting}

The \texttt{LUT1D} ProcessNode could be replaced with a 3D LUT (\autoref{ex:3dlut}) or a matrix (\autoref{ex:matrix}).

\begin{lstlisting}[caption=Example of a \texttt{LUT3D},label=ex:3dlut]
<LUT3D id="lut-24" name="green look" interpolation="trilinear"
	inBitDepth="12i" outBitDepth="16f">
	<Description> 3D LUT </Description>
	<Array dim="2 2 2 3">
		0.0 0.0 0.0
		0.0 0.0 1.0
		0.0 1.0 0.0
		0.0 1.0 1.0
		1.0 0.0 0.0
		1.0 0.0 1.0
		1.0 1.0 0.0
		1.0 1.0 1.0
	</Array>
</LUT3D>

\end{lstlisting}

\begin{lstlisting}[caption=Example of a \texttt{Matrix},label=ex:matrix]
<Matrix id="lut-25" name="colorspace conversion" inBitDepth="10i" outBitDepth="10i" >
	<Description> 3x4 Matrix , 4th column is offset </Description>
	<Array dim="3 4 3">
		1.2  	0.0  	0.0   	0.002
		0.0 	1.03 	0.001 	-0.005
		0.004 	-0.007 	1.004  	0.0
	</Array>
</Matrix>

\end{lstlisting}

``Shaper LUTs'' require a bit more of an explanation.  This is once again an illustration of the technique using an \texttt{IndexMap} and not a real world example. These can also be implemented with \texttt{1DLUT}s.

\begin{lstlisting}[caption=Example of a partially enumerated ``Shaper LUT'',label=ex:shaperlut]
<LUT1D id="lut-25" name="shaper LUT" inBitDepth="10i" outBitDepth="16f">
	<Description> 1D LUT with shaper </Description>
	<IndexMap dim=4>0@0 10@100 20@250 30@360 40@440 445@445
					700@600 800@700 900@850 950@1023</IndexMap>
	<Array dim="1024 1">
		0.00
		0.32
		0.50
		<1020 entries omitted>
		1.0
	</Array>
</LUT1D>
\end{lstlisting}

\begin{lstlisting}[caption=Example of an ASC CDL node,label=ex:asccdl]
<ASC_CDL id="cc01234" inBitDepth="16f" outBitDepth="16f" style="Fwd">
	<Description>scene 1 exterior look</Description>
	<SOPNode>
		<Slope>1.000000  1.000000  0.900000</Slope>
		<Offset>-0.030000  -0.020000  0.000000</Offset>
		<Power>1.2500000  1.000000  1.000000</Power>
	</SOPNode>
	<SatNode>
		<Saturation>1.700000</Saturation>
	</SatNode>
</ASC_CDL>

\end{lstlisting}

A full example of an XML file (\autoref{ex:fullexample}) shows three nodes in a ProcessList.

\begin{lstlisting}[caption=Full example of an XML LUT file,label=ex:fullexample]
<?xml version="1.0" encoding="UTF-8"?>
<ProcessList xmlns="urn:NATAS:ASC:LUT:v1.2" id="luts-23+24+25" name="lut chain 34">
	<Description> Turn 4 grey levels into 4 codes for a monitor using a 3by1D LUT
			into 3D LUT into 3x1D LUT </Description>
	<OutputDescriptor> Sony BVM CRT </OutputDescriptor>
	<LUT1D id="lut-23" name="input lut" inBitDepth="12i" outBitDepth="12i">
		<Description> 3by1D LUT </Description>
		<Array dim="4 3">
			1 1 1
			1 1 1
			2 2 2
			2 2 2
		</Array>
	</LUT1D>
	<LUT3D id="lut-24" name="green look output rendering" interpolation="trilinear"
				inBitDepth="12i" outBitDepth="16f">
		<Description> 3D LUT </Description>
		<Array dim="4 4 4 3">
			0.0 0.0 0.0
			0.0 0.0 1.0
			0.0 1.0 0.0
			0.0 1.0 1.0
			1.0 0.0 0.0
			1.0 0.0 1.0
			1.0 1.0 0.0
			1.0 1.0 1.0
			[ed:  ...abridged:   64 total entries...]
			1.0 1.0 1.0
		</Array>
	</LUT3D>
	<LUT1D id="lut-25" name="output conversion" inBitDepth="16f" outBitDepth="12i">
		<Description> 3x1D LUT </Description>
		<IndexMap dim=2>0.0@0 3.0@65504.0</IndexMap>
		<Array dim="4 3">
			0 0 0
			1 1 1
			2 2 2
			3 3 3
		</Array>
	</LUT1D>
</ProcessList>

\end{lstlisting}


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

\section{Classical Processes}
\label{sec:cp}
In this section, we will discuss a rudimentary subset of the typed process
calculus \cp~\parencite{wadler2012,lindley2015semantics}, which we will refer to as
\rcp.
We have chosen to discuss only a subset in order to keep the discussion of
\nodcap in \cref{sec:main} as simple as possible.
\rcp is the subset of \cp which corresponds to rudimentary linear
logic~\parencite[RLL]{girard1992}, also known as multiplicative-applicative linear
logic.
We foresee no problems in extending the proofs from \cref{sec:main} to
cover the remaining features of \cp, polymophism and the exponentials $\ty{!A}$
and $\ty{?A}$.

This chapter proceeds as follows.
In \cref{sec:cp-terms-and-types}, we introduce the terms, the structural
congruence, and the types of \rcp.
In \cref{sec:cp-multiplicatives,sec:cp-additives,sec:cp-duality,sec:cp-commuting-conversions},
we discuss the terms and their corresponding types, in small groups,
together with their typing and reduction rules.
In \cref{sec:cp-properties}, we prove preservation, progress and
termination for \rcp.

\subsection{Terms and types}
\label{sec:cp-terms-and-types}
The term language for \rcp is a variant of the
\textpi-calculus~\parencite{milner1992b}.
Its terms are defined by the following grammar:
\input{def-cp-terms}
The variables \tm{x}, \tm{y}, \tm{z} and \tm{w} range over channel names.
The construct \tm{\cpLink{x}{y}} links two
channels~\parencite{sangiorgi1996,boreale1998}, forwarding messages received on
\tm{x} to \tm{y} and vice versa.
The construct \tm{\cpCut{x}{P}{Q}} creates a new channel \tm{x}, and composes
two processes, \tm{P} and \tm{Q}, which communicate on \tm{x}, in parallel.
Therefore, in \tm{\cpCut{x}{P}{Q}} the name \tm{x} is bound in both \tm{P} and
\tm{Q}.
In \tm{\cpRecv{x}{y}{P}} and \tm{\cpSend{x}{y}{P}{Q}}, round brackets denote
input, square brackets denote output.
We use bound output~\parencite{sangiorgi1996}, meaning that both input and output
bind a new name.
In \tm{\cpRecv{x}{y}{P}} the new name \tm{y} is bound in \tm{P}.
In \tm{\cpSend{x}{y}{P}{Q}}, the new name \tm{y} is only bound in \tm{P}, while
\tm{x} is only bound in \tm{Q}.

Terms in \rcp are identified up to structural congruence, which states that
parallel compositions \tm{\cpCut{x}{P}{Q}} are associative and commutative.
It is defined as follows:
\input{def-cp-equiv}
We deviate from the original presentation of \cp here, as the structural
congruence defined by \textcite{wadler2012} does not include \cpEquivLinkComm.
We include it here because it fits well with our notion of links, and it
simplifies our reduction system and the proofs of meta-theoretical properties of
\cp.
We do not add an axiom for \cpEquivCutAss2, as it follows from
\cref{def:cp-equiv}.
Throughout this dissertation, we will leave uses of the transitivity and
congruence rules implicit.
\input{thm-cp-cut-assoc2}
Furthermore, structural congruence is a symmetric relation.
\input{thm-cp-symmetry}
%
Channels in \rcp are typed using a session type system which corresponds to RLL,
the multiplicative, additive fragment of linear logic.
The types are defined by the following grammar:
\input{def-cp-types}
Duality plays a crucial role in both linear logic and session types.
In \rcp, the two endpoints of a channel are assigned dual types.
This ensures that, for instance, whenever a process \emph{sends} across a
channel, the process on the other end of that channel is waiting to
\emph{receive}.
Each type \ty{A} has a dual, written \ty{A^\bot}.
\input{def-cp-negation}
Duality is an involutive function.
\input{thm-cp-negation-involutive}
%
Environments associate channels with types.
\input{def-cp-environments}
Typing judgements associate processes with collections of typed channels.
\input{def-cp-typing-judgement}
\input{fig-cp-typing-judgement}
Reductions relate processes with their reduced forms.
They are defined as follows:
\input{def-cp-term-reduction-1}
\input{fig-cp-term-reduction-1}
\input{fig-cp-term-reduction-2}
We will discuss the interpretations of each connective, together with their
typing and reduction rules, in \cref{sec:cp-multiplicatives,sec:cp-additives,sec:cp-duality}.

\subsection{Multiplicatives and in- and interdependence}
\label{sec:cp-multiplicatives}
The multiplicatives ($\ty{\tens}, \ty{\parr}$) deal with independence and
interdependence:
\begin{itemize}
\item
  A channel of type \ty{A \tens B} represents a pair of channels, which
  communicate with two independent processes---that is to say, two
  processes who share no channels.
  A process acting on a channel of type \ty{A \tens B} will send one endpoint of
  a fresh channel, and then split into a pair of independent processes.
  One of these processes will be responsible for an interaction of type \ty{A}
  over the fresh channel, while the other process continues to interact as
  \ty{B}.
\item
  A channel of type \ty{A \parr B} represents a pair of interdependent channels,
  which are used within a single process.
  A process acting on a channel of type \ty{A \parr B} will receive a channel to
  act on, and communicate on its channels in whatever order it pleases.
  This means that the usage of one channel can depend on that of
  another---e.g.\ the interaction of type \ty{B} could depend on the result of
  the interaction of type \ty{A}, or vise versa, and if \ty{A} and \ty{B} are
  complex types, their interactions could likewise interweave in complex ways.
\end{itemize}
While the rules for \ty{\tens} and \ty{\parr} introduce input and output
operations, these are inessential---the essential distinction lies two in the
fact that (\tens) composes two independent processes, and therefore \emph{must}
split the environment between them, whereas ($\parr$) uses a single process, which
then can---and must---use all the channels in the environment.
\begin{center}
  \cpInfTens
  \cpInfParr
\end{center}
The \textbeta-reduction rule for terms introduced by $(\tens)$ and $(\parr)$
implements the behaviour outlined above:
\[
  \tm{\cpCut{x}{\cpSend{x}{y}{P}{Q}}{\cpRecv{x}{z}{R}}}
  \Longrightarrow
  \tm{\cpCut{y}{P}{\cpCut{x}{Q}{\cpSub{y}{z}{R}}}}
\]
The function \tm{\cpSub{x}{y}{P}} denotes the substitution of the name \tm{x}
for the name \tm{y} in the term \tm{P}.
%
The rules for the multiplicative units ($\ty{\one}, \ty{\bot}$) follow the same
pattern, except for the nullary instead of the binary case:
\begin{itemize}
\item
  A term constructed by $(\one)$ must composes \emph{zero} independent
  processes, and thus must halt. Furthermore, it must be able to split its
  environment between zero processes, and thus its environment must be empty.
\item
  A term constructed by $(\bot)$, on the other hand, consists of a single
  process, which is not further restricted.
\end{itemize}
The rules for $\ty{\one}$ and $\ty{\bot}$ introduce a nullary send and receive
operation, such as those found in the polyadic \textpi-calculus~\parencite{milner1993}.
\begin{center}
  \cpInfOne
  \cpInfBot
\end{center}
The \textbeta-reduction rule for terms introduced by $(\one)$ and $(\bot)$
implements the behaviour outlined above:
\[
  \tm{\cpCut{x}{\cpHalt{x}}{\cpWait{x}{P}}}
  \Longrightarrow
  \tm{P}
\]

\subsection{Additives and choice}
\label{sec:cp-additives}
The additives ($\ty{\plus}, \ty{\with}$) deal with choice:
\begin{itemize}
\item
  A process acting on a channel of type \ty{A \plus B} either sends the value
  \tm{\text{inl}} to select an interaction of type \ty{A} or the value
  \tm{\text{inr}} to select one of type \ty{B}.
\item
  A process acting on a channel of type \ty{A \with B} receives such a value,
  and then offers an interaction of either type \ty{A} or \ty{B},
  correspondingly.
\end{itemize}
In essence, the additive operations implement sending and receiving of a single
bit of information (\tm{\text{inl}} or \tm{\text{inr}}) and branching based on
the value of that bit.
\begin{center}
  \cpInfPlus1
  \cpInfWith
\end{center}
The rule for constructing a process which sends \tm{\text{inr}}, $(\plus_2)$,
has been omitted, but can be found in~\cref{fig:cp-typing-judgement}.
The \textbeta-reduction rules for terms introduced by $(\plus_1)$, $(\plus_2)$
and $(\with)$ implement the behaviour outlined above.
\[
  \begin{array}{c}
    \tm{\cpCut{x}{\cpInl{x}{P}}{\cpCase{x}{Q}{R}}} \Longrightarrow \tm{\cpCut{x}{P}{Q}}
    \\
    \tm{\cpCut{x}{\cpInr{x}{P}}{\cpCase{x}{Q}{R}}} \Longrightarrow \tm{\cpCut{x}{P}{R}}
  \end{array}
\]
%
The rules for the additive units ($\ty{\nil}, \ty{\top}$) follow the same
pattern, except for a nullary choice:
\begin{itemize}
\item
  There is \emph{no} rule for \ty{\nil}, as a process acting on a channel of
  that type would have to select one of \emph{zero} options, which is clearly
  impossible.
\item
  A process acting on a channel of type \ty{\top} will wait to receive a choice
  of out \emph{zero} options. Since this will clearly never arrive, we have two
  options: either we block, waiting forever, or we simply crash.
\end{itemize}
It may seem odd at first to include a type for the process which cannot possibly
exist, and for the process which waits forever, but these make sensible units
for choice.
When offered a choice of type \ty{A \plus \nil}, one can either choose to
interact as \ty{A}, or choose to commit to doing the impossible.
Similarly, when offering a choice of type \ty{A \with \top}, one can safely
implement the right branch with a process which waits forever, as no sound
process will ever be able to select that branch anyway.
\begin{center}
  \cpInfNil
  \cpInfTop
\end{center}
As there is no way to construct a process of type \ty{\nil}, there is no
reduction rule for the additive units.

\subsection{Structural rules and duality}
\label{sec:cp-duality}
Duality plays a crucial role in session type systems.
In~\cref{sec:cp-additives}, we saw that duality ensures a process offering a choice
is always matched with a process making a choice.
In~\cref{sec:cp-multiplicatives}, we saw that it also ensures that, for instance
a process which uses communication on \tm{x} to decide what to send on \tm{y} is
matched with a pair of independent processes on \tm{x} and \tm{y}, a property
which is crucial to deadlock freedom, as it prevents circular dependencies.

Duality appears in the typing rules for two \rcp term constructs.
Forwarding, \tm{\cpLink{x}{y}}, connects two dual channels with dual endpoints,
while composition, \tm{\cpCut{x}{P}{Q}}, composes two processes \tm{P} and
\tm{Q} with a shared channel \tm{x}, requiring that they follow dual protocols
on \tm{x}.
\begin{center}
  \cpInfAx
  \cpInfCut
\end{center}
There are two reduction rules which deal with the interactions between
forwarding and compositions. These implement the intuition that if a process is
meant to communicate on \tm{x}, \tm{x} is forwarding to \tm{y}, and nobody else
is listening on \tm{x}, then the process might as well start communicating on
\tm{y}.
\[
  \tm{\cpCut{x}{\cpLink{w}{x}}{P}} \Longrightarrow \tm{\cpSub{w}{x}{P}}
\]
We can do this because \rcp implements a binary session type system, meaning
that each communication has only two participants, and therefore we know that no
other process is communicating on \tm{x}.

\textcite{wadler2012} has two reduction rules which deal with links. The first of
these can be seen above, and the second of these deals with the case in which
the link is flipped.
As we consider links commutative, this rule is derivable.

\subsection{Commuting conversions}
\label{sec:cp-commuting-conversions}
The commuting conversions are not reductions typically found in the
\textpi-calculus.
Instead, they are based on permutation cuts, which are commonly used in logic to
define a procedure for cut elimination.
These cut elimination steps push a cut deeper into a term, past unrelated
inference rules.
When viewed from the perspective of process calculus, they allow us to pull
actions upwards, past unrelated cuts.
The commuting conversion are defined in \cref{fig:cp-term-reduction-2}.

\subsection{Example}
\label{sec:cp-example}
The multiplicatives are responsible for structuring communication, and
it is this structure which rules out deadlocked interactions.
Let us go back to our example of a deadlocked interaction from
\cref{sec:introduction}:
\[
  \tm{(\piPar{%
      \piRecv{x}{z}{\piSend{y}{\sliceofcake}{\john}}
    }{%
      \piRecv{y}{w}{\piSend{x}{\bill}{\mary}}
    })}
\]

If we want to translate this interaction to \cp, we run into a problem: there is
no \emph{plain} sending construct in \cp---we only have \tm{\cpSend{x}{y}{P}{Q}},
which requires that the remainder of the interaction is split in two independent
processes.
This enforces a certain structure on the program. Either John will already have
to have the cake in his hands, or Mary will already have to have the money in
the bank.
We model the second scenario below, assuming \john, \mary and \bank are
processes modeling John, Mary, and Mary's bank, and \cake and \money are the
types of two channels which give access to a slice of cake and appropriate
payment.
\begin{prooftree}
  \AXC{$\seq[{ \john }]{ \Gamma, \tmty{y}{\money^\bot}, \tmty{x}{\cake}}$}
  \SYM{\parr}
  \UIC{$\seq[{ \cpRecv{x}{y}{\john} }]{ \Gamma, \tmty{x}{\money^\bot \parr \cake} }$}
  \AXC{$\seq[{ \bank }]{ \Delta, \tmty{z}{\money} }$}
  \AXC{$\seq[{ \mary }]{ \Theta, \tmty{x}{\cake^\bot} }$}
  \SYM{\tens}
  \BIC{$\seq[{\cpSend{x}{z}{\bank}{\mary} }]{ \Delta, \tmty{x}{\money \tens \cake^\bot} }$}
  \NOM{Cut}
  \BIC{$\seq[{ \cpCut{x}{\cpRecv{x}{y}{\john}}{\cpSend{x}{z}{\bank}{\mary}} }]{\Gamma, \Delta, \Theta }$}
\end{prooftree}
The resulting process reduces, as expected:
\[
  \reducesto
  {\cpCut{x}{\cpRecv{x}{y}{\john}}{\cpSend{x}{z}{\bank}{\mary}}}
  {\cpCut{y}{\bank}{\cpCut{x}{\john}{\mary}}}
\]

\subsection{Properties of \rcp}
\label{sec:cp-properties}
In this section, we will prove three important properties of \rcp, namely
preservation, progress and termination.

\subsubsection{Preservation}
Preservation is the fact that term reduction preserves typing. In order to prove
this, we will first need to prove that structural congruence preserves typing.
\input{thm-cp-preservation-equiv}
%
\input{fig-cp-preservation-equiv}
%
Then, we can prove preservation.
\input{thm-cp-preservation}
%
\input{fig-cp-preservation-1}
\input{fig-cp-preservation-2}

\subsubsection{Progress}
Progress is the fact that every term is either in some canonical form, or can be
reduced further. In order for a statement of progress to make sense, we need a
definition of canonical form. The canonical form used by \cp is ``any term which
is not a cut.'' We will refer to this canonical form as \emph{weak head normal
form}, for its relation to the eponymous \textlambda-calculus normal form.
\input{def-cp-weak-head-normal-form}
As \cp has a tight correspondence with classical linear logic, so does its proof
of progress have a tight correspondence with (part of) the procedure proof
normalisation for classical linear logic for classical linear
logic~\parencite{girard1987}.
\input{thm-cp-progress-1}
If we extend the reduction system with all congruence rules---not just
\cpRedGammaCut for reduction under cuts, but for reduction under any term
context---then we can strengthen our canonical form, and extend our proof for
progress to the \emph{full} proof normalisation procedure.
\input{def-cp-normal-form}
\input{thm-cp-progress-2}
\textcite{wadler2012} opts to leave these additional congruence rules out,
because ``such rules do not correspond well to our notion of computation on
processes'', and his choice is analogous to a common practice in the
\textlambda-calculus to not allow reduction under lambdas.

It might not be so odd to allow these reductions in the context of \cp.
If one conceives of the two sides of a parallel composition in
\tm{\cpRecv{y}{z}{\cpCut{x}{P}{Q}}} as separate processes, both waiting on an
external communication on \tm{y}, it does not seem odd to allow the
communication on \tm{x} to happen. It is simply eager a form of evaluation.

\subsubsection{Termination}
\label{sec:cp-termination}
Termination is the fact that if we iteratively apply progress to obtain a
reduction, and apply that reduction, we will eventually end up with a term in
canonical form.
Its proof is quite simple, owing to the fact that our reduction rules were all
inspired by cut reductions from classical linear logic.
\input{thm-cp-termination}

\section{Non-determinism, logic, and session types}
\label{sec:local-choice}
In recent work, we have seen the extension of \piDILL and \cp with operators for
non-deterministic behaviour~\parencite{atkey2016,caires2014,caires2017}.
These extensions all implement an operator known as non-deterministic local
choice.
While this operator is written as \tm{P+Q}, it should not be confused with
input-guarded choice~\parencite{milner1992b} from the \textpi-calculus.
Essentially, non-deterministic local choice can be summarised by the following
typing and reduction rules:
\begin{center}
  \begin{prooftree*}
    \AXC{$\seq[{ P }]{ \Gamma }$}
    \AXC{$\seq[{ Q }]{ \Gamma }$}
    \BIC{$\seq[{ P + Q }]{ \Gamma }$}
  \end{prooftree*}
  \hspace*{2cm}
  \(
  \begin{array}{c}
    \reducesto{P + Q}{P}\\
    \reducesto{P + Q}{Q}
  \end{array}
  \)
\end{center}
There are some problems with non-deterministic local choice. First of all, the
non-determinism arises from the fact that for any term \tm{P+Q}, two different
reduction rules apply simultaneously. These reduction rules are written
specifically to introduce non-determinism. This is unlike the \textpi-calculus,
where non-determinism arises due to multiple processes communicating on a
single, shared channel.
We can easily implement this operator in the \textpi-calculus, using a nullary
communication:
\[
  \begin{array}{c}
    \tm{( \piPar{\piPar{\piSend{x}{}{\piHalt}}{\piRecv{x}{}{P}}}{\piRecv{x}{}{Q}} )}
    \\[1ex]
    \rotatebox[origin=c]{270}{$\Longrightarrow^{\star}$}
    \\[1ex]
    \tm{( \piPar{P}{\piRecv{x}{}{Q}} )}
    \quad
    \text{or}
    \quad
    \tm{( \piPar{\piRecv{x}{}{P}}{Q} )}
  \end{array}
\]
In this implementation, the process \tm{\piSend{x}{}{0}} will ``unlock'' either
\tm{P} or \tm{Q}, leaving the other process deadlocked. Or we could use
input-guarded choice:
\[
  \tm{( \piPar{\piSend{x}{}{\piHalt}}{( \piRecv{x}{}{P} + \piRecv{x}{}{Q} )} )}
\]
However, there are many non-deterministic processes in the \textpi-calculus
which are awkward to encode using non-deterministic local choice.
Let us look at our example:
\[
  \begin{array}{c}
    \tm{(\piPar{%
    \piSend{x}{\sliceofcake}{\piSend{x}{\nope}{\store}}
    }{%
    \piPar{\piRecv{x}{y}{\john}}{\piRecv{x}{z}{\mary}}
    })}
    \\[1ex]
    \rotatebox[origin=c]{270}{$\Longrightarrow^{\star}$}
    \\[1ex]
    \tm{(\piPar{\store}{\piPar{\piSub{\sliceofcake}{y}{\john}}{\piSub{\nope}{z}{\mary}}})}
    \quad
    \text{or}
    \quad
    \tm{(\piPar{\store}{\piPar{\piSub{\nope}{y}{\john}}{\piSub{\sliceofcake}{z}{\mary}}})}
  \end{array}
\]
This non-deterministic interaction involves communication. If we wanted to write
down a process which reduced to the same result using non-deterministic local
choice, we would have to write the following process:
\[
  \begin{array}{c}
    \tm{
    (\piPar{\store}{\piPar{\piSub{\sliceofcake}{y}{\john}}{\piSub{\nope}{z}{\mary}}})
    +
    (\piPar{\store}{\piPar{\piSub{\nope}{y}{\john}}{\piSub{\sliceofcake}{z}{\mary}}})
    }
    \\[1ex]
    \rotatebox[origin=c]{270}{$\Longrightarrow^{\star}$}
    \\[1ex]
    \tm{(\piPar{\store}{\piPar{\piSub{\sliceofcake}{y}{\john}}{\piSub{\nope}{z}{\mary}}})}
    \quad
    \text{or}
    \quad
    \tm{(\piPar{\store}{\piPar{\piSub{\nope}{y}{\john}}{\piSub{\sliceofcake}{z}{\mary}}})}
  \end{array}
\]
In essence, instead of modelling a non-deterministic interaction, we are
enumerating the outcomes of such an interaction.
This means non-deterministic local choice does not adequately model
non-determinism in the way the \textpi-calculus does.
%
Enumerating all possible outcomes becomes worse the more processes are involved
in an interaction. Imagine a scenario the following scenario:
\begin{quote}
  Three customers, Alice, John and Mary, have a craving for cake. Should cake be
  sold out, however, well... a doughnut will do. They prepare to order their
  goods via an online store. Unfortunately, they all decide to use the
  same \emph{shockingly} under-stocked store, which has only one slice of cake,
  and a single doughnut. After that, all it can deliver is disappointment.
\end{quote}
We can model this scenario in the \textpi-calculus, assuming \alice, \john,
\mary, and \store are four processes modelling Alice, John, Mary and the store,
and \sliceofcake, \doughnut, and \nope are three channels giving access to a
slice of cake, a so-so doughnut, and disappointment, respectively.
\begin{center}
  \makebox[\textwidth][c]{\ensuremath{
      \begin{array}{c}
        \tm{(\piPar{%
        \piSend{x}{\sliceofcake}{\piSend{x}{\doughnut}{\piSend{x}{\nope}{\store}}}
        }{%
        \piPar{\piRecv{x}{y}{\alice}}{\piPar{\piRecv{x}{z}{\john}}{\piRecv{x}{w}{\mary}}
        })}}
        \\[1ex]
        \rotatebox[origin=c]{270}{$\Longrightarrow^{\star}$}
        \\[1ex]
        \tm{(\piPar{\store}{\piPar{\piSub{\sliceofcake}{y}{\alice}}{\piPar{\piSub{\doughnut}{z}{\john}}{\piSub{\nope}{w}{\mary}}}})}
        \;
        \text{or}
        \;
        \tm{(\piPar{\store}{\piPar{\piSub{\sliceofcake}{y}{\alice}}{\piPar{\piSub{\nope}{z}{\john}}{\piSub{\doughnut}{w}{\mary}}}})}
        \\[1ex]
        \tm{(\piPar{\store}{\piPar{\piSub{\doughnut}{y}{\alice}}{\piPar{\piSub{\nope}{z}{\john}}{\piSub{\sliceofcake}{w}{\mary}}}})}
        \;
        \text{or}
        \;
        \tm{(\piPar{\store}{\piPar{\piSub{\doughnut}{y}{\alice}}{\piPar{\piSub{\sliceofcake}{z}{\john}}{\piSub{\nope}{w}{\mary}}}})}
        \\[1ex]
        \tm{(\piPar{\store}{\piPar{\piSub{\nope}{y}{\alice}}{\piPar{\piSub{\sliceofcake}{z}{\john}}{\piSub{\doughnut}{w}{\mary}}}})}
        \;
        \text{or}
        \;
        \tm{(\piPar{\store}{\piPar{\piSub{\nope}{y}{\alice}}{\piPar{\piSub{\doughnut}{z}{\john}}{\piSub{\sliceofcake}{w}{\mary}}}})}
        \\[1ex]
      \end{array}
    }}
\end{center}
With the addition of one process, Alice, we have increased the number of possible
outcomes enormously! In general, the number of outcomes for these types of
scenarios is $n!$, where $n$ is the number of processes. This means that if we
wish to translate any non-deterministic process to one using non-deterministic
local choice, we can expect a factorial growth in the size of the term!
%%% Local Variables:
%%% TeX-master: "main"
%%% End:


\section{Generating learners with Bootstrapped AGGregation (bagging)}


    \filetitle{daysinyear}{Number of days in year}{dates/daysinyear}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
N = daysinyear(Year)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{Year} {[} numeric {]} - Year.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{N} {[} numeric {]} - Number of days in \texttt{Year}.
\end{itemize}

\paragraph{Description}\label{description}

\texttt{N} is \texttt{365} for non-leap years, and \texttt{366} for leap
years. Leap years either those divisible by \texttt{4} but not
\texttt{100}, or those divisible by \texttt{400}.

\paragraph{Example}\label{example}

\begin{verbatim}
daysinyear([2000,2200])
ans =
   366   365
\end{verbatim}


\section{Numeric and Mathematical Modules}
%     numbers -- Numeric abstract base classes
%     math -- Mathematical functions
%     cmath -- Mathematical functions for complex numbers
%     decimal -- Decimal fixed point and floating point arithmetic
%     fractions -- Rational numbers
\input{sections/random}
%     statistics -- Mathematical statistics functions

%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PREF.TEX						    July 1990      %
%                                                                          %
% This file is part of the AMS-LaTeX Version 1.0 distribution              %
%   American Mathematical Society, Technical Support Group,                %
%   P. O. Box 6248, Providence, RI 02940                                   %
%   800-321-4AMS (321-4267) or 401-455-4080                                %
%   Internet: Tech-Support@Math.AMS.com                                    %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter*{Preface}

This book is a study of polynomial operator pencils,
i.e., operator polynomials of the form
\begin{equation*}
A(\lambda)=A_0+\lambda A_1+\cdots+\lambda^nA_n,
\end{equation*}
where $\lambda$ is a spectral parameter and $A_0,\dots,A_n$ are linear
operators acting in a Hilbert space $\cal H$. In the simplest cases
$A(\lambda)=
A-\lambda I$ and $A(\lambda)=I-\lambda A$ we come to the usual (linear)
spectral problems.

Spectral problems for polynomial pencils arise naturally in diverse
areas of mathematical physics (differential equations and boundary value
problems, controllable systems, the theory of oscillations and waves,
elasticity theory, and hydromechanics). This explains the steady interest
in these problems over the last 35 years.

A consideration of the simplest model---a matrix pencil---enables us
to see the  essential differences between nonlinear and linear
spectral problems. If the coefficients of the pencil $A_k$
$(k=0,\dots,n)$ are matrices of order $m$, $\det A_n\neq 0$, and all
the roots $\{\lambda_k\}_1^{nm}$ of the characteristic equation $\det
A(\lambda) =0$ are distinct, then the pencil $A(\lambda)$ has $nm$
eigenvectors $\{\varphi _k\}_1^{nm}$ (i.e.,
$A(\lambda_k)\varphi_k=0$). One possible approach is to single out in
the system $\{\varphi_k\}_1^{nm}$ various subsystems
$\{\varphi_{k_j}\}_{j=1}^m$ forming bases in $\bold C^m$. Another
approach leads to the consideration of the system of vectors
$\{\varphi_k,\lambda_k \varphi_k,\dots,\lambda_k^{n-1}\varphi_k)$
$(k=1,\dots,nm)$, which forms a basis in the space $\bold C^{nm}$.
Both these approaches are fruitful and admit far-reaching
generalizations.

\endinput


\chapter{Proving via Transformation}
\label{ch:proving-via-transformation}

We give details of the constructions and establish the soundness of
Algorithm~\ref{algorithm:overview}. Our goal is to establish the
following theorem:

\begin{theorem}
  Let $G^\fun{main} = \langle V, E, \cmd{cmd}^\fun{main} , \overline{\mathtt{u}}^\fun{main}, \overline{\mathtt{r}}^\fun{main},s,e \rangle$ be a control flow
  graph in $P$. If Algorithm~\ref{algorithm:overview} returns
  $\mathit{Pass}$, there is an inductive invariant $\Pi (G^\fun{main}, \TT)$
  such that $I_{\ell} \implies B_{\ell}$ for every $(\ell, \ell') \in
  E$ with $\cmd{cmd}^\fun{main} (\ell, \ell') = \mathtt{assert\ } B_{\ell}$.
  \label{theorem:soundness}
\end{theorem}
By Proposition~\ref{proposition:inductive-invariant}, it follows that
all assertions in $G^\fun{main}$ are satisfied.
Moreover, by the semantics of the
$\mathtt{assert}$ command, all assertions in the program are satisfied.

\input{chap-proving/sec-unwinding}
\input{chap-proving/sec-under_approx}
\input{chap-proving/sec-computing_summary}
\input{chap-proving/sec-checking_summary}
\input{chap-proving/sec-correctness}