\section{Decision Tree Classifiers}
\begin{itemize}
	\item Idea of a Tree:
	\begin{itemize}
		\item easy to read \& interpret
		\item robust, though lack of solid theoretical/statistical foundations
		\item can use with Ensemble-Methods
	\end{itemize}
\end{itemize}

\subsection{Setup of a Decision Tree}
\begin{itemize}
	\item internal node: test on a \textbf{attribute}
	\item branch: outcome of the test (eg: true/false, red/green)
	\item leaf node: the \textbf{classification label/result}
\end{itemize}

Building an \textbf{Optimal} Decision Tree:
\begin{itemize}
	\item Search Space: $2^{2^m}$ possible trees (m: \# attributes, 2 result classes)
	\item Complexity: \textbf{NP-complete}
	\item Solution: \textbf{Greedy Algorithm} in \textbf{top-down} approach
	\begin{itemize}
		\item All training data at the \textbf{root}.
		\item Partition data \textbf{recursively} by choosing \textbf{one attribute} at each level.
		\item Each split is assessed with a \textbf{measure}
		\item Attribute with \textbf{best split} is chosen.
		\item Repeat until all \textbf{leaf nodes} are pure (Not all attributes are necessary).
	\end{itemize}
\end{itemize}

\subsection{Quality Metrics of a Splitting Attribute}
\begin{itemize}
	\item Idea:
	\begin{itemize}
		\item the path to classification \textbf{as easy as possible}. $\rightarrow$ \textbf{smallest} tree
		\item good separation of classes $\rightarrow$ leaf nodes gives \textbf{one single class} $\rightarrow$ direct decision
		\item the separation shouldn't affect class distribution.
	\end{itemize}
	\item Evaluation function:
	\begin{itemize}
		\item \textbf{information gain (ID3/C4.5)}
		\item \textbf{information gain ratio}
		\item \textbf{gini index (CART)}
	\end{itemize}
\end{itemize}

\subsubsection{Information Gain}
\begin{itemize}
	\item Idea: choose the attribute that result in \textbf{smallest tree} $\rightarrow$ \textbf{purest} nodes (one class)

	$\rightarrow$ choose the attribute with \textbf{greatest information gain}

	$\rightarrow$ information gain $\uparrow$, subset average purity $\uparrow$

	\item Parameters:
	\begin{itemize}
		\item $c_i$: the \textbf{absolute frequency} of the training examples in the class $i$
		\item $C$: the \textbf{total number} of training example at the \textbf{current stage/attribute value}.
		\item $p_i$: the \textbf{relative frequency} of class $i$, $$p_i = \frac{c_i}{C}$$
		\item $N$: the \textbf{total number of training data}
	\end{itemize}
\end{itemize}

\paragraph{Process: }
\begin{enumerate} [label= \protect \circled{\arabic*} ]
	\item calculate \textbf{initial information} before any splits.
	\item calculate \textbf{information for each attribute value} using entropy
	\paragraph{Entropy} $\in [0,1]$, measures how much \textbf{additional information required} in \textbf{bits}
	$$\text{entropy}(p_1, \dots, p_n) = - \Sigma_{i=1} ^n p_i \cdot \log_{2} p_i$$
	\begin{itemize}
		\item entropy = 0: pure
		\item entropy = 1: maximum impurity (for boolean)
	\end{itemize}
	\paragraph{Information of Each Attribute Value}

	$$\text{info}([c_1, \dots, c_n]) = \text{entropy}(\frac{c_1}{C}, \dots, \frac{c_n}{C})$$
	\item calculate \textbf{information of the attribute}
	\paragraph{Information of the Attribute} the \textbf{weighted average} of the \textbf{information needed} from each attribute value.

	Say an attribute has $m$ attribute values/branches,

	$$\text{info}([c_1, \dots, c_n]_1, \dots, [c_1, \dots, c_n]_m) = \Sigma_{i=1}^m  \frac{C_m}{N} \cdot \text{info}([c_1, \dots, c_n])_m$$

	\item calculate the \textbf{information gain}

	\paragraph{Information Gain of the Attribute}

	$$\text{Information\_Gain(attribute)} = \text{info(before split by attribute)} - \text{info(after split by attribute)}$$

	\item choose the attribute with \textbf{maximum} information gain.
	\item continue to split.

	\textbf{Attention}: the info \textbf{before} the split is the \textbf{info(attribute value)}, the information gain of the attribute changes to

	eg: gain(Temperature) = \textbf{info(Outlook = sunny)} - info(high, mild, cool)
\end{enumerate}

\paragraph{Limitations}
\begin{itemize}
	\item \textbf{biased} against \textbf{highly-branching} attributes (eg: IDs)

	$\rightarrow$ overfitting

	$\rightarrow$ Alternative: \textbf{Gain Ratio}
\end{itemize}

\subsubsection{Gain Ratio}
\begin{itemize}
	\item Idea: modification of information gain, reduce bias on highly-branching attributes.

	$\rightarrow$ considers \textbf{number and size} of branches $\rightarrow$ \textbf{intrinsic information} of attribute

	\item \textbf{Intrinsic Information}, s: size of a leaf from each branch
	$$\text{intrinsic\_info}([s_1, \dots, s_n]) = \text{info}([s_1, \dots, s_n])$$
	eg: 14 IDs, intrinsic\_info([1,1,...,1]) = info([1,1,...,1]) = $14 \cdot (-\frac{1}{14} \cdot \log_{2} \frac{1}{14}) = 3.807$ bits

	\item \textbf{Gain Ratio}:

	$$\text{Gain\_Ratio(attribute)} = \dfrac{\text{Gain(attribute)}}{\text{Intrinsic\_Info(attribute)}}$$

	\item Process:
	\begin{itemize}
		\item calculate the \textbf{information gain} of the attribute
		\item calculate the \textbf{intrinsic information} of the attribute
		\item calculate the \textbf{gain ratio}
		\item choose the attribute that has \textbf{maximium} the gain ratio.
	\end{itemize}
\end{itemize}

\subsubsection{Gini Index}
\begin{itemize}
	\item Use-case: in Classification and Regression Tree (CART)
	\item Solution: select the split that \textbf{decreases} the Gini Index \textbf{the most}.
	\item \textbf{Gini Index}:
	$$Gini(S) = 1 - P^2 - N^2$$
	$$P = \frac{p}{p+n}, N = \frac{n}{p+n}$$
	\item a dataset S is split into $S_1, S_2$,
	$$Gini_{split} (S_1,S_2) = \frac{p_1 + n_1}{p+n} \cdot Gini(S_1) + \frac{p_2 + n_2}{p+n} \cdot Gini(S_2)$$

	$\rightarrow$ select the attribute with \textbf{lowest} Gini-Index after split.
\end{itemize}

\subsection{Evaluation of Decision Tree Algorithm}
\begin{itemize}
	\item Time Complexity: $\mathcal{O}(m\cdot n \log n)$

	(m: \# attributes, n: \# instances)
	\item Scalability for large data:
	\begin{itemize}
		\item number of attributes $\uparrow$, tree size $\uparrow$, computation time $\uparrow$.
		\item number of data instances $\uparrow$, memory $\uparrow$
	\end{itemize}
\end{itemize}

\subsection{Possible Problems in Prediction}
\subsubsection{Numeric Attributes in Dataset}
\begin{itemize}
	\item Solution: \textbf{binary split}
	\item Process:
	\begin{itemize}
		\item an \textbf{initial split point} is either given or the middle of the sorted numeric values.
		\item values are separated into 2 sections: \textbf{below(<)} and \textbf{above($\geq$)} the split point.
		\item calculate \textbf{information gain}
		\item repeat \textbf{binary split}, choose the split with \textbf{maiximum information gain}.
	\end{itemize}
\end{itemize}

\subsubsection{Missing Values in Dataset}
\begin{itemize}
	\item Possible solutions:
	\begin{itemize}
		\item \textbf{ignore} the instance/attribute with missing values.
		\item treat missing value as \textbf{another nominal value}.
		\item \textbf{estimate} missing values (regression, imputation)
		\item \textbf{follow the leader}: if an instance has missing attribute value, follow the the \textbf{branch with most instances}.
		\item \textbf{partition} the instance: send down instance \textbf{proportionally} to the number of instances.

		$\rightarrow$ classification result is \textbf{weighted}.
	\end{itemize}
\end{itemize}

\subsubsection{Overfitting of the Decision Tree}
\begin{itemize}
	\item Consequences in Overfitting:
	\begin{itemize}
		\item decision tree to \textbf{large \& complex}
		\item \textbf{low bias} on training set, \textbf{high variance} on test set.
		\item poor generalization to new data.
	\end{itemize}
	\item Solution: Pruning
\end{itemize}

\subsection{Pruning of Decision Trees}
\subsubsection{Prepruning}
Process:
\begin{itemize}
	\item define a \textbf{threshold} when to stop creating subtrees. This should be the same measure as determining attributes (eg: information gain)
	\item \textbf{stop} if the measure \textbf{no longer exceeds threshold}. (eg: infomation gain)
	\item leaf node: the \textbf{most frequent class}
\end{itemize}
Difficult to achieve high performance in practice.

\subsubsection{Postpruning}
\begin{itemize}

	\item Process:
	\begin{itemize}
		\item construct a \textbf{complete} decision tree.
		\item prune back by \textbf{subtree replacement}, replacing the subtree with \textbf{a single leaf node}.
		\item prune back criteria: \textbf{error rate} estimate for the \textbf{node} < \textbf{combined error rates} of the \textbf{children(weighted average)}

		\begin{figure}[H]
			\centering
			\includegraphics[width=0.65\textwidth]{prune.png}
		\end{figure}
		$\rightarrow$ error rate of the node = 0.28 < combined error rate of the children = 0.33

		$\rightarrow$ prune back, the leaf node is the \textbf{most frequent class}.
	\end{itemize}
	\item Use-case: C4.5, CART, however, computationally expensive
	\item Data for pruning:
	\begin{itemize}
		\item hold-out set: an \textbf{independent} dataset from the training data. Best, but not practical when data is scarce.
		\item training data: Used in C4.5, derive \textbf{outer bound of confidence interval} from data, use a \textbf{heuristic limit} for error rate. If the \textbf{error rate is outside the confidence interval} $\rightarrow$ \textbf{prune} back.

		$\rightarrow$ confidence limit c $\downarrow$ (25\% -> 10\%), the tree prunes \textbf{stronger}.
	\end{itemize}
\end{itemize}


\section*{Task 1}
Transform to $LL(1)$:
\begin{align*}
S \rightarrow sCT|sCTwB && \\
C \rightarrow c    && \\
T \rightarrow t|e  &&  \\
B \rightarrow Ba|a && \\
&& \\
B \rightarrow aB' && \textit{right-recursive} \\
B' \rightarrow \epsilon | aB' && \textit{right-recursive} \\
S' \rightarrow scT && \textit{factoring } \\
S{'}{'} \rightarrow \epsilon | wB && \textit{factoring} \\
S \rightarrow S'S'' && \textit{factoring}
\end{align*}

\subsection*{Task 1b}
$
FIRST(S) \rightarrow  FIRST(S') \rightarrow  \{'s'\} \\
FIRST(B) \rightarrow  {'a'} \\
FIRST(B') \rightarrow  \{\epsilon{'}, {'}a{'}\} \\
FIRST(T') \rightarrow  \{{'}sc{'}\}
$
\newline

$
FOLLOW(S) \rightarrow \{'\$'\} \\
FOLLOW(S{'}) \rightarrow \{'\$'\, w\} \\
FOLLOW(B) \rightarrow \{'\$'\} \\
FOLLOW(B{'}) \rightarrow \{'\epsilon'\} \\
FOLLOW(T) \rightarrow \{'\$'\}
$

\begin{tabular}{|l|l|l|l|l|l|l|}
    T &w &c &t &a & s & \$ \\
    \bottomrule
    S &  & S' & & & S $\rightarrow$ S'S''  & \\
    \bottomrule
    S' & & & & & S' $\rightarrow$ scT & \\
    \bottomrule
    S'' &S' $\rightarrow$ wB  & & & &  & \\
    \bottomrule
    C & & C $\rightarrow$ c & & & & \\
    \bottomrule
    T & T $\rightarrow $ w & & T $\rightarrow$ t & & & T $\rightarrow \epsilon $ \\
    \bottomrule
    B & & & & B $\rightarrow$ aB'  &&  \\
    \bottomrule
    B' & & & & B $\rightarrow$ aB' & & B' $\rightarrow \epsilon $ \\
    \bottomrule
\end{tabular}

\section*{Task 2}
Note: my VSL parse trees do not exactly match the expected output- an extra node
is added for the parenthesis. I hope this is okay and simply a trivial error.


In this section a background of the theory behind the combinatorial games studied for this thesis is provided. In addition to this, the notation introduced here is used throughout the thesis.

\subsection{Partially Ordered Sets}
This thesis is about a type of combinatorial games called \emph{poset games}. In order to be able to introduce the theory of these games, we must first define what a poset is.
\begin{defn}[Partially Ordered Sets{\cite[p.~278]{stanley2011}}]
A \emph{partially ordered set} (\emph{poset}) $(P,\le)$ is a set with a binary order relation $\le$ satisfying the following three axioms:
\begin{enumerate}
\item For all $t\in P$, $t\le t$ (reflexivity).
\item If $s\le t$ and $t\le s$,then $s=t$ (antisymmetry).
\item If $s\le t$ and $t\le u$,then $s\le u$ (transitivity).
\end{enumerate}
\end{defn}
~\\
We use the obvious notation $t\ge s$ to mean $s\le t$, $s<t$ to mean $s\le t$ and $s\ne t$, and $t>s$ to mean $s<t$. We say that two elements $s$ and $t$ of $P$ are \emph{comparable} if $s\le t$ or $t\le s$, otherwise $s$ and $t$ are \emph{incomparable}.
\\
We define an \emph{interval} $[p,q]$ of a poset to be $\{x\in P\;|\;p\le x\le q\}$. We say that $v$ covers $u$ if $[u,v]=\{u,v\}$, and we denote this by $u\lessdot v$.
\\\\
In a partizan element removal game, every element must have a color.
%\\
\begin{defn}[Colored Posets]
A \emph{colored poset} is a poset where each element has a color of either black or white.
\end{defn}
\begin{ex}{}
\label{ex:posets}
An example of a regular and a colored poset. %The elements higher up are greater than those lower down. The greatest element is comparable to all other elements, but the elements second highest up are not comparable to each other.
\\
\begin{minipage}[b]{0.495\textwidth}
%\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=.45]
  \draw[thick] (0,0) -- (-3,2) -- (-3,5) -- (0,7) -- (3,5) -- (3,2) -- (0,0);
  \draw[thick] (3,5) -- (0,2) -- (-3,5);
  \draw[thick] (0,0) -- (0,2);
  \draw[thick] (-3,2) -- (0,5) -- (3,2);
  \draw[thick] (0,5) -- (0,7);
  \node (zero) at (0,0) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (1) at (-3,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (2) at (0,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (3) at (3,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (4) at (-3,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (5) at (0,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (6) at (3,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (7) at (0,7) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
\end{tikzpicture}
\captionof{figure}{Example of a poset.}
%\end{figure}
\end{minipage}
\begin{minipage}{0.01\textwidth}
~
\end{minipage}
\begin{minipage}[b]{0.495\textwidth}
%\begin{figure}[H]
\centering
\begin{tikzpicture}[scale=.45]
  \draw[thick] (0,0) -- (-3,2) -- (-3,5) -- (0,7) -- (3,5) -- (3,2) -- (0,0);
  \draw[thick] (3,5) -- (0,2) -- (-3,5);
  \draw[thick] (0,0) -- (0,2);
  \draw[thick] (-3,2) -- (0,5) -- (3,2);
  \draw[thick] (0,5) -- (0,7);
  \node (zero) at (0,0) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (1) at (-3,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (2) at (0,2) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (3) at (3,2) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (4) at (-3,5) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (5) at (0,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (6) at (3,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (7) at (0,7) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
\end{tikzpicture}
\captionof{figure}{Example of a colored poset.}
%\end{figure}
\end{minipage}
\end{ex}
~\\%\newpage
In particular, this thesis focuses on poset games with a specific coloring called chess-coloring.
\\
\begin{minipage}[t]{0.40\textwidth}
\begin{defn}[Chess-Colored Posets]
A \emph{chess-colored poset} is a colored poset such that no element covers an element of the same color. Equivalently we may regard $P=W\cup B$ as a bipartite graph, with white vertices $W$ and black vertices $B$, with the cover relation as an edge relation.
\\
To avoid confusion, we will assume that the least element is colored white when there is only one smallest element.
\end{defn}
\end{minipage}
\begin{minipage}{0.04\textwidth}
~
\end{minipage}
%\begin{figure}[h]
\begin{minipage}[t]{0.55\textwidth}
\begin{ex}{}~
\\
\begin{center}
\begin{tikzpicture}[baseline=0.65ex,scale=.5]
  \draw[thick] (0,0) -- (-3,2) -- (-3,5) -- (0,7) -- (3,5) -- (3,2) -- (0,0);
  \draw[thick] (3,5) -- (0,2) -- (-3,5);
  \draw[thick] (0,0) -- (0,2);
  \draw[thick] (-3,2) -- (0,5) -- (3,2);
  \draw[thick] (0,5) -- (0,7);
  \node (zero) at (0,0) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (1) at (-3,2) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (2) at (0,2) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (3) at (3,2) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (4) at (-3,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (5) at (0,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (6) at (3,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (7) at (0,7) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
\end{tikzpicture}
%\caption{Example of a chess-colored poset.}
\captionof{figure}{Example of a chess-colored poset.}
\end{center}
\end{ex}
\end{minipage}
%\end{figure}
%\begin{minipage}{0.05\textwidth}
%~
%\end{minipage}
%\begin{minipage}[b]{0.475\textwidth}
%\centering
%\begin{tikzpicture}[scale=.5]
%  \node (zero) at (0,0) {\tikz\draw[black,fill=white] (0,0) circle (.5ex);};
%  \node (1) at (-3,2) {\tikz\draw[black,fill=black] (0,0) circle (.5ex);};
%  \node (2) at (0,2) {\tikz\draw[black,fill=black] (0,0) circle (.5ex);};
%  \node (3) at (3,2) {\tikz\draw[black,fill=black] (0,0) circle (.5ex);};
%  \node (4) at (-3,5) {\tikz\draw[black,fill=white] (0,0) circle (.5ex);};
%  \node (5) at (0,5) {\tikz\draw[black,fill=white] (0,0) circle (.5ex);};
%  \node (6) at (3,5) {\tikz\draw[black,fill=white] (0,0) circle (.5ex);};
%  \node (7) at (0,7) {\tikz\draw[black,fill=black] (0,0) circle (.5ex);};
%  \draw[thick] (zero) -- (1) -- (4);
%  \draw[thick] (6) -- (2) -- (zero);
%  \draw[thick] (5) -- (7);
%  \draw[thick] (1) -- (5) -- (7);
%  \draw[thick] (zero) -- (3);
%\end{tikzpicture}
%\captionof{figure}{Example of a (chess-colored) tree poset.}
%\end{minipage}
%%\end{figure}
%\\\\
%%\begin{minipage}[b]{0.5\textwidth}
%\begin{defn}[Tree Posets]
%A \emph{tree poset} is a poset that, when regarded as a graph with the cover relations as undirected edges, has no cycles. A forest poset is a poset where all components of the poset (when the poset is regarded as a graph with the cover relations as undirected edges) are tree posets.
%\end{defn}
%%\end{minipage}
%%\begin{minipage}{0.1\textwidth}
%%~
%%\end{minipage}
%%\begin{figure}[h]
%%
\subsubsection{Young Diagrams}
This thesis mainly focuses on an object called \emph{Young diagram}. We will formally define exactly what a Young diagram is in Definition \ref{def:lambda}, but before that we need the following definition:
\begin{defn}
\label{def:lambda}
Let $\lambda=(\lambda_1,\dots,\lambda_k)$ be a weakly decreasing sequence of positive integers, i.e., $\lambda_1\ge \lambda_2\ge\dots\ge \lambda_k$. We say that $\lambda$ partitions $n$, denoted by $\lambda\vdash n$, if $\sum_{i=1}^k\lambda_i =n$.
\end{defn}
%~
\begin{defn}[Young Diagrams%{\cite[p.~155]{hk2002}}
]
A \emph{Young diagram} is a collection of boxes arranged in left-justified rows with a weakly decreasing number of boxes in each row. If the number of boxes is $n$ and $\lambda\vdash n$, we say that $\lambda$ generate a Young diagram with $\lambda_1$ boxes in the first row, $\lambda_2$ boxes in the second row,$\dots$, $\lambda_k$ in the $k$'th row.
Moreover, a Young diagram can always be represented as a poset.
\end{defn}
~\\
This definition is best illustrated with an example.
\begin{ex}{}
With $\lambda=(7,5,2,2,1)$ we have the Young diagram in Figure \ref{fig:youngex} and the corresponding representation as a poset in Figure \ref{fig:youngposetex}.
\\
%\begin{picex}{}
\begin{minipage}[b]{0.45\textwidth}
%\begin{math}
\centering
\begin{tabular}{ | c | c | c | c | c | c | c |}
\hline
~&~&~&~&~&~&~\\
\hline
~&~&~&~&~\\
\cline{1-5}
~&~\\
\cline{1-2}
~&~\\
\cline{1-2}
~\\
\cline{1-1}
\end{tabular}
%\end{math}
\captionof{figure}{Young diagram generated by $\lambda=(7,5,2,2,1)$.}
\label{fig:youngex}
\end{minipage}
%\begin{center}
%\begin{figure}
%\begin{Young}
 %& & & & & & \cr
 %& & & & \cr
 %& \cr
 %& \cr
 %\cr
%\end{Young}
%\end{figure}
%\end{center}
\begin{minipage}{0.05\textwidth}
~%This Young diagram can also be represented as the following poset:
\end{minipage}
\begin{minipage}[b]{0.50\textwidth}
\centering
\begin{tikzpicture}[scale=.5]
  \draw[thick] (0,0) -- (-1,1) -- (-2,2) -- (-3,3) -- (-4,4) -- (-5,5) -- (-6,6);
  \draw[thick] (1,1) -- (0,2) -- (-1,3) -- (-2,4) -- (-3,5);
  \draw[thick] (2,2) -- (1,3);
  \draw[thick] (3,3) -- (2,4);
  \draw[thick] (0,0) -- (1,1) -- (2,2) -- (3,3) -- (4,4);
  \draw[thick] (-1,1) -- (0,2) -- (1,3) -- (2,4);
  \draw[thick] (-2,2) -- (-1,3);
  \draw[thick] (-3,3) -- (-2,4);
  \draw[thick] (-4,4) -- (-3,5);
  \node (zero) at (0,0) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (1) at (-1,1) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (2) at (-2,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (3) at (-3,3) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (4) at (-4,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (5) at (-5,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (6) at (-6,6) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (7) at (1,1) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (8) at (0,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (9) at (-1,3) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (10) at (-2,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (11) at (-3,5) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (12) at (2,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (13) at (1,3) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (14) at (3,3) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (15) at (2,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (16) at (4,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
\end{tikzpicture}
\captionof{figure}{Poset of the Young diagram generated by $\lambda=(7,5,2,2,1)$.}
\label{fig:youngposetex}
\end{minipage}
\end{ex}
In analogy with the previous definitions, a colored Young diagram is a Young diagram where each box has a color of either black or white, and a chess-colored Young diagram is a Young diagram where no adjacent boxes have the same color.
%\\
\begin{ex}{}
With $\lambda=(7,5,2,2,1)$ as before, we have the chess-colored Young diagram and the corresponding chess-colored poset in Figures \ref{fig:chessyoung} and \ref{fig:chessyoungposet} respectively.
\\
%\begin{picex}{}
\begin{minipage}[b]{0.45\textwidth}
%\begin{figure}[H]
\centering
\begin{tabular}{ | c | c | c | c | c | c | c |}
\hline
~&\cellcolor[gray]{0}&~&\cellcolor[gray]{0}&~&\cellcolor[gray]{0}&~\\
\hline
\cellcolor[gray]{0}&~&\cellcolor[gray]{0}&~&\cellcolor[gray]{0}\\
\cline{1-5}
~&\cellcolor[gray]{0}\\
\cline{1-2}
\cellcolor[gray]{0}&~\\
\cline{1-2}
~\\
\cline{1-1}
\end{tabular}
\captionof{figure}{Chess-colored Young diagram generated by $\lambda=(7,5,2,2,1)$.}
\label{fig:chessyoung}
%\end{figure}
\end{minipage}
\begin{minipage}{0.05\textwidth}
~
\end{minipage}
\begin{minipage}[b]{0.5\textwidth}
%\begin{figure}[H]
\centering
\begin{tikzpicture}[scale=.5]
  \draw[thick] (0,0) -- (-1,1) -- (-2,2) -- (-3,3) -- (-4,4) -- (-5,5) -- (-6,6);
  \draw[thick] (1,1) -- (0,2) -- (-1,3) -- (-2,4) -- (-3,5);
  \draw[thick] (2,2) -- (1,3);
  \draw[thick] (3,3) -- (2,4);
  \draw[thick] (0,0) -- (1,1) -- (2,2) -- (3,3) -- (4,4);
  \draw[thick] (-1,1) -- (0,2) -- (1,3) -- (2,4);
  \draw[thick] (-2,2) -- (-1,3);
  \draw[thick] (-3,3) -- (-2,4);
  \draw[thick] (-4,4) -- (-3,5);
  \node (zero) at (0,0) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (1) at (-1,1) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (2) at (-2,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (3) at (-3,3) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (4) at (-4,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (5) at (-5,5) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (6) at (-6,6) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (7) at (1,1) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (8) at (0,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (9) at (-1,3) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (10) at (-2,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (11) at (-3,5) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (12) at (2,2) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (13) at (1,3) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (14) at (3,3) {\tikz\draw[black,fill=black] (0,0) circle (1ex);};
  \node (15) at (2,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
  \node (16) at (4,4) {\tikz\draw[black,fill=white] (0,0) circle (1ex);};
\end{tikzpicture}
\captionof{figure}{Chess-colored poset of the Young diagram in figure \ref{fig:chessyoung}.}
\label{fig:chessyoungposet}
%\end{figure}
\end{minipage}
\end{ex}

\subsection{Combinatorial Game Theory}
This thesis deals with combinatorial game theory, an area which studies sequential games with perfect information, that is, games where the players play in turns and where they have complete knowledge of the game, i.e., know all possible game options for all players.
\\
In particular, the thesis will focus on two-player partizan combinatorial games, in which the game options of the two players can be different. Furthermore, we call the two players Left and Right (or White and Black or Blue and Red).
\\
In general, a combinatorial game has \emph{positions}, and at any given position every player has a set of \emph{options} of moving to a new position. Under normal play convention a player loses if they have no options available at their turn to move.
%\\
\begin{defn}[Partizan Game Position{\cite[p.~71]{onag}}]
A position in a partizan game is defined by its left and right options, and we denote it by $G=\{L|R\}$, where $L$ and $R$ are the sets of left and right options respectively.
\end{defn}
~\\
Since we will be using the notation used by Conway\cite{onag}, the notation above will not always be used, and we will instead often abuse it by writing $G=\{G_1,G_2,G_3|H_1,H_2\}$ as short for $G=\left\{\{G_1,G_2,G_3\}|\{H_1,H_2\}\right\}$, and in the general case $G=\{G^L|G^R\}$.
\\
Following this we will introduce some notation for the games depending on the winner and who starts.
%\\
\begin{defn}[Value Notation{\cite[p.~73]{onag}}]
\label{def:value}
~
\begin{itemize}
\item $G>0$ ($G$ is \emph{positive}) if there is a winning strategy for Left.
\item $G<0$ ($G$ is \emph{negative}) if there is a winning strategy for Right.
\item $G=0$ ($G$ is \emph{zero}) if there is a winning strategy for the second player to move.
\item $G\parallel0$ ($G$ is \emph{fuzzy} to zero) if there is a winning strategy for first player move.
\end{itemize}
\end{defn}
~\\
This notation is easy to understand with help of some examples.
%\\
\begin{ex}{}
Consider the simplest possible game, the game with no options for either player, i.e., $G_1=\{|\}$. We obviously have $G_1=0$, since the first player has no options to play and therefore loses. This game is denoted by $0:=\{|\}$.
\\
Now consider the game where Left has the option to move to $0$, but Right still has no options, i.e., $G_2=\{0|\}$. Here we have that $G_2>0$ since either Left starts and moves to $0$, and then Right has no option and loses, or Right starts and has no options and therefore loses, i.e., Left has a winning strategy. This game is denoted by $1:=\{0|\}$. Similarly we have that the game $-1<0$ where $-1$ is defined as $-1:=\{|0\}$.
\\
Finally, consider the game where both players have the option to move to $0$, i.e., $G_3=\{0|0\}$. We now have $G_3\parallel0$ since both players have the option to move to $0$, where the second player then will lose. This game is denoted as $*:=\{0|0\}$.
\end{ex}
%\newpage
~\\
The value notation of Definition \ref{def:value} can be combined and extended in the following way.
\begin{defn}[Extended Value Notation{\cite[p.~73]{onag}}]
\label{def:extvalue}~
\begin{itemize}
\item If $G\ge0$, then Left always wins if Left is the second player to move.
\item If $G\le0$, then Right always wins if Right is the player second to move.
\item If $G\rhd0$, then Left always wins if Left is the first player to move.
\item If $G\lhd0$, then Right always wins if Right is the first player to move.
\end{itemize}
\end{defn}
~\\
In addition to the value notations, it is also possible to add and subtract games.
\begin{defn}[Addition and Negation{\cite[p.~73]{onag}}]
\begin{align*}
G+H&=\left\{G^L+H,G+H^L\middle|G^R+H,G+H^R\right\}\\
-G&=\left\{-G^R\middle|-G^L\right\}
\end{align*}
\end{defn}
~\\
Informally, we can note that addition of two games is the same as playing in both games at the same time, and the negation of a game is the game with reversed roles of Left and Right. Combining these, it is possible to subtract games as $G-H=G+(-H)$.
\\
Using this, we define the following relations between games:
\begin{defn}[Game Relations{\cite[p.~78]{onag}}]
~
\begin{itemize}
\item $G>H$ iff $G-H>0$.
\item $G<H$ iff $G-H<0$.
\item $G=H$ iff $G-H=0$.
\item $G\parallel H$ iff $G-H\parallel0$.
\end{itemize}
\end{defn}
~\\
Using these relations, which can be combined and extended as the extended notation of Definition \ref{def:extvalue}, we can define what a \emph{dominated} option is.
\begin{defn}[Dominated Options{\cite[p.~110]{onag}}]
\label{def:dominate}
For a game we say that a left option $G^{L_1}$ is dominated by another left option option $G^{L_0}$ if $G^{L_1}\le G^{L_0}$. Similarly, a right option $G^{R_1}$ is dominated by another right option $G^{R_0}$ if $G^{R_1}\ge G^{R_0}$.
\end{defn}
~\\
In fact, an important property of a game is that you always can remove any dominated options{\cite[p.~110]{onag}}.
\begin{thm}
\label{thm:domopt}
Let $G=\left\{G^{L_0},G^{L_1},\dots|G^{R_0},G^{R_1}\dots,\right\}$.
\begin{itemize}
\item If $G^{L_0}\le G^{L_1}$, then $G=G'$, where $G'=\left\{G^{L_1},\dots|G^{R_0},G^{R_1}\dots,\right\}$.
\item If $G^{R_0}\ge G^{R_1}$, then $G=G''$, where $G''=\left\{G^{L_0},G^{L_1},\dots|G^{R_1}\dots,\right\}$.
\end{itemize}
\end{thm}
~\\
A significant class of games are the \emph{short} games.
\begin{defn}[Short Games{\cite[p.~3]{lip}\cite[p.97]{onag}}]
A game G is short if only a finite number of positions can be reached and a position may never be repeated.
\end{defn}
~\\
Moreover, every short game $G$ has a unique simplest form. This is called $G$'s canonical form{\cite[p.~78]{lip}}. It is possible to reduce any short game to its canonical form by just removing dominated and \emph{reversible} options{\cite[p.~111]{onag}}.
\\\\
A methodology that is extremely useful when proving properties of games is \emph{Conway induction}.
\begin{thm}[Conway Induction{\cite[p.~5]{onag}}]
\label{thm:conind}
Let $P$ be a property which games might have, such that any game $G$ has property $P$ whenever all left and right options of $G$ have this property. Then every game has property $P$.
\end{thm}
~\\
The methodology using Conway induction makes it possible to prove that a game has a property by assuming that all its options have this property, and from this proving that the game itself has it. This methodology is using that the definitions of games are inductive.
\subsubsection{Numbers}
\label{section:numbers}
Another important property and concept in combinatorial games is that of numbers, which is a class of games with some special characteristics.
%\\
\begin{defn}[Numbers{\cite[p.~91]{lip}}]
A number is any game $x$ such that all $x^L<x<x^R$ and $x^L$ and $x^R$ are numbers.
For short games, we can, equivalently, for $j>0$ and $m$ odd, define a number as
\begin{equation}
\frac{m}{2^j}=\left\{\frac{m-1}{2^j}\Bigg|\frac{m+1}{2^j}\right\}.
\label{eq:number}
\end{equation}
\label{def:number}
\end{defn}
~\\
It should also be noted that all games are not numbers. For $*=\{0|0\}$ we have $G^L=0=G^R$, and hence $G^L\not<G^R$, i.e., $*$ is not a number.
\\
Equation (\ref{eq:number}) can be generalized to recognize when $G$ is a number even if it is not in canonical form. For this, we need to define what the \emph{simplest number} is.
%\\
\begin{defn}[Simplest Number{\cite[p.~93]{lip}}]
\label{def:simpnum}
For $x^L<x^R$, the simplest number $x$ between $x^L$ and $x^R$ is given by the following:
\begin{itemize}
\item If there are integer(s) $n$ such that $x^L<n<x^R$, $x$ is the one that is smallest in absolute value.
\item Otherwise, $x$ is the number of the form $\frac{i}{2^j}$ between $x^L$ and $x^R$ for which $j$ is minimal.
\end{itemize}
\end{defn}
%~
\begin{thm}[Numbers{\cite[p.~93]{lip}}]
\label{thm:number}
If all options of a game $G$ are numbers and all $G^L<G^R$, then $G$ is the simplest number $x$ satisfying $G^L<x<G^R$.
\end{thm}
~\\
This, together with Definition \ref{def:dominate} and Theorem \ref{thm:domopt}, yields that a game that is equal to a number is equal to the game consisting of only its greatest left options and smallest right options, i.e.,
$G\equiv\left\{G^{L_0},G^{L_1},\dots|G^{R_0},G^{R_1}\dots,\right\}=\left\{G^{L_0}|G^{R_0}\right\}\equiv G'$ if $G^{L_0}\ge G^{L_i}$ and $G^{R_0}\le G^{R_j}$ for $i,j>0$.
\\
It should also be noted that equation (\ref{eq:number}) is a number for integers $j>0$ and $m$, regardless if $m$ is odd or not.

\subsubsection{Hackenbush}
A game with properties similar to the ones studied in this thesis is \emph{Blue-Red Hackenbush}. Hackenbush is a partizan two-player game that may be played on any configuration of colored line segments connected to one another by their endpoints and to a "ground" line. In the Blue-Red Hackenbush, the line segments are colored either blue or red. It is played by, in turns, removing a line segment of your color, by which all segments that are unconnected to the ground vanishes, until a player has no move left.
\begin{ex}{}
\label{ex:hack}
An example of a game of Blue-Red Hackenbush and gameplay on that game.
\begin{figure}[H]
\centering
{\Large
$
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-1,-1) -- (1,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (left)   at (-0.5,-1) {};
    \node[hackennode] (right)  at ( 0.5,-1) {};
    \node[hackennode] (top)    at ( 0,   1) {};
    \node[hackennode] (top2)   at ( 0,   2) {};

    \draw[hackenline,blue]
        (left) -- (middle) -- (right);
    \draw[hackenline,red!75]
        (middle) -- (top);
    \draw[hackenline,red!75]
        (top) -- (top2);
\end{tikzpicture}
=
\left\{
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-0.5,-1) -- (1,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (right)  at ( 0.5,-1) {};
    \node[hackennode] (top)    at ( 0,   1) {};
    \node[hackennode] (top2)   at ( 0,   2) {};

    \draw[hackenline,blue]
        (middle) -- (right);
    \draw[hackenline,red!75]
        (middle) -- (top);
    \draw[hackenline,red!75]
        (top) -- (top2);
\end{tikzpicture}
\tikz[baseline=-0.65ex,scale=0.5] \node[inner sep=0] at (0,-1) {,\,};
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-1,-1) -- (0.5,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (left)   at (-0.5,-1) {};
    \node[hackennode] (top)    at ( 0,   1) {};
    \node[hackennode] (top2)   at ( 0,   2) {};

    \draw[hackenline,blue]
        (middle) -- (left);
    \draw[hackenline,red!75]
        (middle) -- (top);
    \draw[hackenline,red!75]
        (top) -- (top2);
\end{tikzpicture}
\middle|
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-0.5,-1) -- (1,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (left)   at (-0.5,-1) {};
    \node[hackennode] (right)  at ( 0.5,-1) {};
    \node[hackennode] (top)    at ( 0,   1) {};

    \draw[hackenline,blue]
        (left) -- (middle) -- (right);
    \draw[hackenline,red!75]
        (middle) -- (top);
\end{tikzpicture}
\tikz[baseline=-0.65ex,scale=0.5] \node[inner sep=0] at (0,-1) {,\,};
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-1,-1) -- (0.5,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (left)   at (-0.5,-1) {};
    \node[hackennode] (right)  at ( 0.5,-1) {};

    \draw[hackenline,blue]
        (left) -- (middle) -- (right);
\end{tikzpicture}
\right\}
$
}% End group with \Large
\caption{A simple game of Blue-Red Hackenbush.}
\label{fig:hackenbush}
\end{figure}
\begin{figure}[H]
{\Large
\[
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-1,-1) -- (1,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (left)   at (-0.5,-1) {};
    \node[hackennode] (right)  at ( 0.5,-1) {};
    \node[hackennode] (top)    at ( 0,   1) {};
    \node[hackennode] (top2)   at ( 0,   2) {};

    \draw[hackenline,blue]
        (left) -- (middle) -- node[strike out,draw=black,line width=1,-]{}(right);
    \draw[hackenline,red!75]
        (middle) -- (top);
    \draw[hackenline,red!75]
        (top) -- (top2);
\end{tikzpicture}
\overset{L}{\longrightarrow}
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-1,-1) -- (0.5,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (left)   at (-0.5,-1) {};
    \node[hackennode] (top)    at ( 0,   1) {};
    \node[hackennode] (top2)   at ( 0,   2) {};

    \draw[hackenline,blue]
        (middle) -- (left);
    \draw[hackenline,red!75]
        (middle) -- (top);
    \draw[hackenline,red!75]
        (top) -- node[strike out,draw=black,line width=1,-]{}(top2);
\end{tikzpicture}
\overset{R}{\longrightarrow}
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-0.5,-1) -- (1,-1);
    \node[hackennode] (middle) at ( 0,   0) {};
    \node[hackennode] (left)   at (-0.5,-1) {};
    \node[hackennode] (top)    at ( 0,   1) {};

    \draw[hackenline,blue]
        (middle) -- node [sloped,strike out,draw=black,line width=1,-]{}(left);
    \draw[hackenline,red!75]
        (middle) -- (top);
\end{tikzpicture}
\overset{L}{\longrightarrow}
\begin{tikzpicture}[baseline=-0.65ex,scale=0.5]
    \draw[densely dashed] (-1,-1) -- (0.5,-1);
\end{tikzpicture}
\]
}% End group with \Large
\caption{Example of gameplay on the Blue-Red Hackenbush in Figure \ref{fig:hackenbush} where Left player wins.}
\end{figure}
\end{ex}
It is known that every game of Blue-Red Hackenbush is a surreal number, and in particular, any \emph{finite} game of Blue-Red Hackenbush is a dyadic rational number, i.e., on the form $\frac{m}{2^j}$ where $m$ and $j>0$ are integers.
\subsubsection{Chomp}
\label{section:chomp}
\begin{minipage}[b]{0.5\textwidth}
Another game closely related to that of this thesis is the game of \emph{Chomp}. Chomp is a impartial two-player game with the usual starting position consisting of a rectangle (possibly infinite) with one poison square in the lower-left corner. A move in Chomp is to choose a square and remove this and all other squares above or to the right of it, and a player loses if they has to choose the poison square.
\end{minipage}
\begin{minipage}{0.05\textwidth}
~
\end{minipage}
\begin{minipage}[b]{0.45\textwidth}
%\begin{figure}[H]
\centering
\begin{tabular}{ | c | c | c | c | c |}
\hline
~&~&~&~&~\\
\hline
~&~&~&~&~\\
\hline
~&~&~&~&~\\
\hline
~&~&~&~&~\\
\hline
~&~&~&~&~\\
\hline
~&~&~&~&~\\
\hline
\cellcolor{red}&~&~&~&~\\
\hline
\end{tabular}
\captionof{figure}{Example of a starting position of a game of Chomp.}
\label{fig:chompstart}
%\end{figure}
\end{minipage}
\begin{ex}{}
\label{ex:chompgame}
An example of gameplay on a game of Chomp with starting position as in Figure \ref{fig:chompstart}.
\begin{figure}[H]
\centering
$
\begin{tabular}{ | c | c | c | c | c |}
\hhline{-----}
~&~&~&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{-----}
~&~&~&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{-----}
~&~&~&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{-----}
~&~&~&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{-----}
~&~&~&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{-----}
~&~&~&\cellcolor[gray]{0.6}&\cellcolor[gray]{0.8}\\
\hhline{-----}
\cellcolor{red}&~&~&~&~\\
\hhline{-----}
\end{tabular}
\overset{L}{\longrightarrow}
\begin{tabular}{ | c | c | c | c | c |}
\hhline{---~~}
\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{---~~}
\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{---~~}
\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{---~~}
\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{---~~}
\cellcolor[gray]{0.6}&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{---~~}
~&~&~\\
\hhline{-----}
\cellcolor{red}&~&~&~&~\\
\hhline{-----}
\end{tabular}
\overset{R}{\longrightarrow}
\begin{tabular}{ | c | c | c | c | c |}
\hhline{---~~}
~&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{-----}
\cellcolor{red}&\cellcolor[gray]{0.6}&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}&\cellcolor[gray]{0.8}\\
\hhline{-----}
\end{tabular}
\overset{L}{\longrightarrow}
\begin{tabular}{ | c |}
\hhline{-}
\cellcolor[gray]{0.6}\\
\hhline{-}
\cellcolor{red}\\
\hhline{-}
\end{tabular}
\overset{R}{\longrightarrow}
\begin{tabular}{ | c |}
\hline
\cellcolor{red}\\
\hline
\end{tabular}
$
\captionof{figure}{Example of gameplay in the game of Chomp with starting position as in Figure \ref{fig:chompstart} where Right player wins.}
\end{figure}
\end{ex}


\chapter{Limits of Computability}
Every discipline of the sciences has its limits: Students of the medical sciences soon realize that
it is difficult to \href{http://www.wowhead.com/spell=61999}{raise the dead} and even religious zealots
have trouble \href{http://www.youtube.com/watch?v=RUMX_b_m3Js}{to walk on water}.  Similarly,
computer science has its limits.  We will discuss
these limits next.  First, we show that we cannot decide whether a computer program will eventually
terminate or whether it will run forever.
Second, we prove that it is impossible to automatically check whether two functions are equivalent.

\section{The Halting Problem}
In this subsection we prove that it is not possible for a computer program to decide whether
another computer program does terminate.  This problem is known as the
\href{http://en.wikipedia.org/wiki/Halting_problem}{\emph{halting problem}}.
\index{halting problem}
Before we give a formal proof that the halting problem is undecidable, let us
discuss one example that shows why it is indeed difficult to decide whether a program does always
terminate.  Consider the program shown in Figure \ref{fig:legendre.stlx} on page
\pageref{fig:legendre.stlx}.  This program contains a \texttt{while}-loop in line 18.
If there is a natural number $n \geq m$ such that the expression,
\\[0.2cm]
\hspace*{1.3cm}
$\mathtt{legendre}(n)$
\\[0.2cm]
in line 19 evaluates to \texttt{false}, then the program prints a message and terminates.   However, if
$\mathtt{legendre}(n)$ is true for all $n \geq m$, then the \texttt{while}-loop does not terminate.

Given a natural number \texttt{n}, the expression
$\texttt{legendre}(n)$ tests whether there is a prime number between $\texttt{n}^2$ and $(\texttt{n}+1)^2$.
If, however, the set
\\[0.2cm]
\hspace*{1.3cm}
$\{ k \in \mathbb{N} \mid n^2 \leq k \wedge k \leq (n+1)^2 \}$
\\[0.2cm]
does not contain a prime number, then $\texttt{legendre}(n)$ evaluates
to \texttt{False} for this value of $n$.  The function \texttt{legendre} is defined in line 7.
Given a natural number $n$, it returns \texttt{True} if and only if the formula
\\[0.2cm]
\hspace*{1.3cm}
$\exists k \in \mathbb{N}:\bigl( n^2 < k \wedge k < (n+1)^2 \wedge \textsl{isPrime}(k)\bigr)$
\\[0.2cm]
holds true.  The French mathematican
\href{http://en.wikipedia.org/wiki/Adrien-Marie_Legendre}{Adrien-Marie Legendre} (1752 -- 1833) conjectured that
for any natural number $n \in \mathbb{N}$ there is prime number $p$ such that
\\[0.2cm]
\hspace*{1.3cm}
$n^2 < p \wedge  p < (n+1)^2$
\\[0.2cm]
holds.  Although there are a number of arguments in support of Legendre's conjecture,  to this day
nobody has been able to prove it.  The answer to the question, whether the invocation of the function $f$ will
terminate for every user input is, therefore, unknown as it depends on the truth of
\href{http://en.wikipedia.org/wiki/Legendre's_conjecture}{Legendre's conjecture}:  If we
had some procedure that could check whether the function call $\texttt{find\_counter\_example}(1)$ does terminate,
then this procedure would be able to decide whether Legendre's theorem is true.  Therefore, it
should come as no surprise that such a procedure does not exist.

\begin{figure}[!ht]
\centering
\begin{minted}[ frame         = lines,
                framesep      = 0.3cm,
                firstnumber   = 1,
                numbers       = left,
                numbersep     = -0.2cm,
                bgcolor       = sepia,
                xleftmargin   = 0.0cm,
                xrightmargin  = 0.0cm,
              ]{python3}
    def divisors(k):
        return { t for t in range(1, k+1) if k % t == 0 }

    def is_prime(k):
        return divisors(k) == {1, k}

    def legendre(n):
        k = n * n + 1;
        while k < (n + 1) ** 2:
            if is_prime(k):
                print(f'{n}**2 < {k} < {n+1}**2')
                return True
            k += 1
        return False

    def find_counter_example(m):
        n = m
        while True:
           if legendre(n):
               n = n + 1
           else:
               print(f'Counter example found: No prime between {n}**2 and {n+1}**2!')
               return
\end{minted}
\vspace*{-0.3cm}
\caption{A program checking Legendre's conjecture.}
\label{fig:legendre.stlx}
\end{figure}

Let us proceed to prove formally that the halting problem is not solvable.  To this end, we need the
following definition.

\begin{Definition}[Test Function]
A string $t$ is a \blue{test function with name $f$}
\index{test function}
iff $t$ has the form \\[0.2cm]
\hspace*{1.3cm} \texttt{\symbol{34}\symbol{34}\symbol{34}}         \\
\hspace*{1.3cm} \texttt{def $f$(x):} \\
\hspace*{1.8cm} \textsl{body}        \\
\hspace*{1.3cm} \texttt{\symbol{34}\symbol{34}\symbol{34}}         \\[0.2cm]
and, furthermore, the string $t$ can be parsed as a \textsl{Python} function, that is the evaluation of
the expression
\\[0.2cm]
\hspace*{1.3cm}
$\texttt{exec}(t)$
\\[0.2cm]
does not yield an error.
The set of all test functions is denoted as $T\!F$.  If $t \in T\!F$ and $t$ has the name $f$, then
this is written as
\\[0.2cm]
\hspace*{1.3cm}
$\mathtt{name}(t) = f$. \hspace*{\fill} $\Box$
\end{Definition}

\examplesEng
\begin{enumerate}
\item We define the string $s_1$ as follows:
      \begin{verbatim}
      '''def simple(x):
             return 0
      '''
      \end{verbatim}
      \vspace*{-0.8cm}

      Then $s_1$ is a test function with the name \texttt{simple}.
\item We define the string $s_2$ as
      \begin{verbatim}
      '''def loop(x):
             while True:
                 x = x + 1
      '''
      \end{verbatim}
      \vspace*{-0.8cm}

      Then $s_2$ is a test function with the name \texttt{loop}.
\item We define the string $s_3$ as
      \begin{verbatim}
      '''def hugo(x):
             return ++x
      '''
      \end{verbatim}
      \vspace*{-0.8cm}

      Then $s_3$ is not a test function.  The reason is that \textsl{Python} does not support the operator
      ``\texttt{++}''.  Therefore,
      \\[0.2cm]
      \hspace*{1.3cm}
      \texttt{exec(s3)}
      \\[0.2cm]
      yields an error message complaining about the two ``\texttt{+}'' characters.
\end{enumerate}
In order to be able to formalize the halting problem succinctly, we introduce three additional
notations.

\begin{Notation}[$\leadsto$, $\downarrow$, $\uparrow$]
If $n$ is the name of a \textsl{Python} function that takes $k$ arguments $a_1$, $\cdots$, $a_k$,
then we write
\\[0.2cm]
\hspace*{1.3cm}
 $n(a_1, \cdots, a_k) \leadsto r$
\\[0.2cm]
iff the evaluation of the expression $n(a_1, \cdots, a_k)$ yields the result $r$.  If we are not
concerned with the result $r$ but only want to state that the evaluation terminates eventually,
then we will write
\\[0.2cm]
\hspace*{1.3cm} $n(a_1, \cdots, a_k) \,\downarrow$ \\[0.3cm]
and read this notation as ``\emph{evaluation of $n(a_1, \cdots, a_k)$ terminates}''.
If the evaluation of the expression $n(a_1, \cdots, a_k)$ does \underline{not} terminate, this is
written as \\[0.2cm]
\hspace*{1.3cm}
 $n(a_1, \cdots, a_k) \,\uparrow$.
\\[0.2cm]
This notation is read as ``\emph{evaluation of $n(a_1, \cdots, a_k)$ diverges}''.
\hspace*{\fill} $\Box$
\end{Notation}

\examplesEng  Using the test functions defined earlier, we have:
\begin{enumerate}
\item {\tt simple(\symbol{34}emil\symbol{34}) $\leadsto 0$},
\item {\tt simple(\symbol{34}emil\symbol{34}) $\downarrow$},
\item {\tt loop(2) $\uparrow$}.
\end{enumerate}

\noindent
The \blue{halting problem} \index{halting problem} for \textsl{Python} functions is the question whether there is a
\textsl{Python} function \\[0.2cm]
\hspace*{1.3cm} \texttt{def stops($t$,$\;a$): } \\
\hspace*{2.3cm} $\vdots$
\\[0.2cm]
that takes as input a test function $t$ and a string $a$ and that satisfies the following specification:
\begin{enumerate}
\item $t \not\in T\!F \quad\Leftrightarrow\quad \mathtt{stops}(t, a) \leadsto 2$.

      If the first argument of \texttt{stops} is not a test function, then
      \texttt{stops($t$, $a$)} returns the number $2$.

\item $t \in T\!F \,\wedge\, \mathtt{name}(t) = n \,\wedge\, n(a)\downarrow \quad\Leftrightarrow\quad
       \mathtt{stops}(t, a) \leadsto 1$.

      If the first argument of \texttt{stops} is a test function and, furthermore,
      the evaluation of $n(a)$ terminates, then \texttt{stops($t$, $a$)} returns the number $1$.

\item $t \in T\!F \,\wedge\, \mathtt{name}(t) = n \,\wedge\, n(a)\uparrow \quad\Leftrightarrow\quad
       \mathtt{stops}(t, a) \leadsto 0$.

      If the first argument of \texttt{stops} is a test function but the evaluation of $n(a)$
      diverges, then \linebreak
      \texttt{stops($t$, $a$)} returns the number $0$.
\end{enumerate}
If there was a \textsl{Python} function \texttt{stops} that did satisfy the specification given above,
then the halting problem for \textsl{Python} would be \blue{decidable}.
\index{decidable}

\begin{Theorem}[\href{http://en.wikipedia.org/wiki/Alan_Turing}{Alan Turing}, 1936]
  The halting problem is undecidable.
\end{Theorem}
\index{Turing, Alan}

\noindent
\textbf{Proof}:  In order to prove the undecidabilty of the halting problem we have to show that
there can be no function \texttt{stops} satisfying the specification given above.  This calls for an
indirect proof also known as a \href{http://en.wikipedia.org/wiki/Indirect_proof}{\emph{proof by contradiction}}.
We will therefore assume that a function \texttt{stops} solving the halting problem does
exist and we will then show that this assumption leads to a contradiction.  This contradiction will
leave us with the conclusion that there can be no function \texttt{stops} that satisfies
the specification given above and that, therefore, the halting problem is undecidable.

In order to proceed, let us assume that a \textsl{Python} function \texttt{stops}
satisfying the specification given above exists and let us define the string
\textsl{turing} as shown in Figure \ref{fig:turing-string} below.

\begin{figure}[!h]
  \centering
\begin{minted}[ frame         = lines,
                framesep      = 0.3cm,
                numbers       = left,
                numbersep     = -0.2cm,
                bgcolor       = sepia,
                xleftmargin   = 0.8cm,
                xrightmargin  = 0.8cm,
              ]{python3}
    turing = """def alan(x):
                    result = stops(x, x)
                    if result == 1:
                        while True:
                            print("... looping ...")
                    return result
             """
\end{minted}
  \vspace*{-0.3cm}
  \caption{Definition of the string \textsl{turing}.}
  \label{fig:turing-string}
\end{figure}

Given this definition it is easy to check that \textsl{turing} is, indeed, a test function with the name
``\texttt{alan}'', that is we have
\\[0.3cm]
\hspace*{1.3cm}
$\textsl{turing} \in T\!F \;\wedge\; \mathtt{name}(\textsl{turing}) = \mathtt{alan}$.
\\[0.2cm]
Therefore, we can use the string \textsl{turing} as the first argument of the function
\texttt{stops}.  Let us determine the value of the following expression:
\\[0.2cm]
\hspace*{1.3cm}
\texttt{stops(\textsl{turing}, \textsl{turing})}
\\[0.2cm]
Since we have already noted that \textsl{turing} is test function, according to the specification of
the function \texttt{stops} there are only two cases left:
\\[0.2cm]
\hspace*{1.3cm}
$\mathtt{stops}(\textsl{turing}, \textsl{turing}) \leadsto 0 \quad \vee\quad
 \mathtt{stops}(\textsl{turing}, \textsl{turing}) \leadsto 1$.
\\[0.2cm]
Let us consider these cases in turn.
\begin{enumerate}
\item $\mathtt{stops}(\textsl{turing}, \textsl{turing}) \leadsto 0$.

      According to the specification of \texttt{stops} we should then have
      \\[0.2cm]
      \hspace*{1.3cm}
      $\mathtt{alan}(\textsl{turing}) \uparrow$.
      \\[0.2cm]
      Let us check whether this is true.  In order to do this, we have to check what happens when
      the expression
      \\[0.2cm]
      \hspace*{1.3cm}
      \texttt{alan(\textsl{turing})}
      \\[0.2cm]
      is evaluated:
      \begin{enumerate}
      \item Since we have assumed for this case that the expression
            $\mathtt{stops}(\textsl{turing}, \textsl{turing})$ yields $0$,
            in line 2, the variable \texttt{result} is assigned the value 0.
      \item Line 3 now tests whether \texttt{result} is $1$.  Of course,
            this test fails.  Therefore, the block of the \texttt{if}-statement is not executed.
      \item Finally, in line 8 the value of the variable \texttt{result} is returned.
      \end{enumerate}
      All in all we see that the call of the function \texttt{alan} does terminate when given the argument
      \textsl{turing}.  However, this is the opposite of what the function \texttt{stops} has claimed.

      Therefore, this case has lead us to a contradiction.
\item  $\mathtt{stops}(\textsl{turing}, \textsl{turing}) \leadsto 1$.

      According to the specification of \texttt{stops} we should then have
      \\[0.2cm]
      \hspace*{1.3cm}
      $\mathtt{alan}(\textsl{turing}) \downarrow$,
      \\[0.2cm]
      i.e.~the evaluation of $\mathtt{alan}(\textsl{turing}) \downarrow$ should terminate.

      Again, let us check in detail whether this is true.
      \begin{enumerate}
      \item Since we have assumed for this case that the expression
            $\mathtt{stops}(\textsl{turing}, \textsl{turing})$ yields $1$,
            in line 2, the variable \texttt{result} is assigned the value $1$.
      \item Line 3 now tests whether \texttt{result} is $1$.  Of course,
            this time the test succeeds.
            Therefore, the block of the \texttt{if}-statement \underline{is} executed.
      \item However, this block contains an infinite loop.  Therefore, the
            evaluation of $\mathtt{alan}(\textsl{turing})$ \underline{diver}g\underline{es}.
            But this contradicts the specification of \texttt{stops}!
      \end{enumerate}
      Therefore, the second case also leads to a contradiction.
\end{enumerate}
As we have obtained contradictions in both cases, the assumption that there is a function
\texttt{stops} that solves the halting problem is refuted.
\hspace*{\fill} $\Box$
\vspace*{0.3cm}

\noindent
\textbf{Remark}:
The proof of the fact that the halting problem is undecidable was given 1936 by Alan Turing (1912 -- 1954)
\cite{turing:36}.  Of course, Turing did not solve the problem for \textsl{Python} but rather
for the so called
\href{http://en.wikipedia.org/wiki/Indirect_proof}{\emph{Turing machines}}.
A \blue{Turing maschine} \index{turing machine}
can be interpreted as a formal description of an algorithm.
Therefore, Turing has shown, that there is no algorithm that is able to decide whether some given
algorithm will always terminate.
\vspace*{0.3cm}

\noindent
\textbf{Remark}:
At this point you might wonder whether there might be another programming language
that is more powerful so that programming in this more powerful language it would be possible to
solve the halting problem.  However, if you check the proof given for \textsl{Python} you will easily
see that this proof can be adapted to any other programming language that is as least as powerful as
\textsl{Python}.

Of course, if a programming language is very restricted, then it might be possible to check the
halting problem for this weak programming language.  But for any programming language that supports
at least \texttt{while}-loops, \texttt{if}-statements, and the definition of procedures the argument
given above shows that the halting problem is not solvable.

\exerciseEng
Show that if the halting problem would be solvable, then it would be possible to write a program that checks
whether there are infinitely many \blue{twin primes}.
\index{twin prime}
A \blue{twin prime} is pair of natural numbers
$\langle p, p + 2 \rangle$ such that both $p$ and $p+2$ are prime numbers.
The \href{http://en.wikipedia.org/wiki/Twin_prime_conjecture}{\emph{twin prime conjecture}} is one
of the oldest unsolved mathematical problems.  \eox

\exerciseEng
A set $X$ is \blue{countably infinite}\index{countably infinite} iff $X$ is infinite and there is a function
\\[0.2cm]
\hspace*{1.3cm}
 $f: \mathbb{N} \rightarrow X$
\\[0.2cm]
such that for all $x\in X$ there is a $n \in \mathbb{N}$ such that $x$ is the image of
$n$ under $f$:
\\[0.2cm]
\hspace*{1.3cm} $\forall x \in X: \exists n \in \mathbb{N}: x = f(n)$.
\\[0.2cm]
(A function of this kind is called \blue{surjective}. \index{surjective}
Some authors define a set to be countably infinite iff
there is an \blue{injective} \index{injective} function $f:\mathbb{N} \rightarrow X$.  It can be shown that if there is a
surjective function $f:\mathbb{N} \rightarrow X$ and $X$ is infinite, then there also is an injective function
$f:\mathbb{N} \rightarrow X$.  Therefore, these definitions are equivalent.)
If a set is infinite, but not countably infinite, we call it \blue{uncountable}.
Prove that the set $2^\mathbb{N}$, which is the set of all subsets of $\mathbb{N}$ is \underline{not} countably
infinite.

\vspace*{0.2cm}

\noindent
\textbf{Hint}:  Your proof should be similar to the proof that the halting problem is undecidable.
Proceed as follows:
Assume that there is a function $f$ enumerating the subsets of $\mathbb{N}$, that is assume that
\\[0.2cm]
\hspace*{1.3cm}
$\forall x \in 2^\mathbb{N}: \exists n \in \mathbb{N}: x = f(n)$
\\[0.2cm]
holds.  Next, and this is the crucial step, define a set \texttt{Cantor} as follows:
\\[0.2cm]
\hspace*{1.3cm} $\mathtt{Cantor} := \bigl\{ n \in \mathbb{N} \mid n \notin f(n) \bigr\}$.
\\[0.2cm]
Now try to derive a contradiction.  \eox

\section[The Equivalence Problem]{Undecidability of the Equivalence Problem}
Unfortunately, the halting problem is not the only undecidable problem in computer science.  Another
important problem that is undecidable is the question whether two given functions always compute the
same result.  To state this more formally, we need the following definition.

\begin{Definition}[$\simeq$]
Assume $n_1$ and $n_2$ are the names of two \textsl{Python} functions that take arguments
  $a_1$, $\cdots$, $a_k$.  Let us define \\[0.2cm]
\hspace*{1.3cm}
$n_1(a_1,\cdots,a_k) \simeq n_2(a_1,\cdots,a_k)$
\\[0.2cm]
if and only if either of the following cases is true:
\begin{enumerate}
\item $n_1(a_1,\cdots,a_k)\uparrow \quad\wedge\quad n_2(a_1,\cdots,a_k)\uparrow$,

      that is both function calls diverge.
\item $\exists r: \Bigl(n_1(a_1,\cdots,a_k) \leadsto r \quad\wedge\quad n_2(a_1,\cdots,a_k) \leadsto
  r\Bigr)$

      that is both function calls terminate and compute the same result.
\end{enumerate}
If $n_1(a_1,\cdots,a_k) \simeq n_2(a_1,\cdots,a_k)$ holds, then the expressions $n_1(a_1,\cdots,a_k)$ and $n_2(a_1,\cdots,a_k)$ are
\blue{partially equivalent}.
\index{partially equivalent}
\hspace*{\fill} $\Box$
\end{Definition}

\noindent
We are now ready to state the \blue{equivalence problem}.  A \textsl{Python} function \texttt{equal} solves the
\emph{equivalence problem} \index{equivalence problem} if it is defined as
\\[0.2cm]
\hspace*{1.3cm} \texttt{def equal(p1, p2, a):}               \\
\hspace*{1.8cm} \textsl{body}                                \\[0.2cm]
and, furthermore, it satisfies the following specification:
\begin{enumerate}
\item $p_1 \not\in T\!F \;\vee\; p_2 \not\in T\!F \quad\Leftrightarrow\quad \mathtt{equal}(p_1, p_2, a) \leadsto 2$.
\item If
      \begin{enumerate}
      \item $p_1 \in T\!F \;\wedge\; \mathtt{name}(p_1) = n_1$,
      \item $p_2 \in T\!F \;\wedge\; \mathtt{name}(p_2) = n_2$ \quad and
      \item $n_1(a) \simeq n_2(a)$
      \end{enumerate}
      holds, then we must have:
      \\[0.2cm]
      \hspace*{1.3cm}
      $\mathtt{equal}(p_1, p_2, a) \leadsto 1$.
\item Otherwise we must have \\[0.2cm]
      \hspace*{1.3cm}
      $\mathtt{equal}(p_1, p_2, a) \leadsto 0$.
\end{enumerate}

\begin{Theorem}
The equivalence problem is undecidable.
\end{Theorem}

\noindent
\textbf{Proof}:
The proof is by contradiction.  Therefore, assume that there is a function \texttt{equal}
such that \texttt{equal} solves the equivalence problem.  Assuming \texttt{equal} exists, we will
then proceed to define a function \texttt{stops} that solves the halting problem.
Figure \ref{fig:stops} shows this construction of the function \texttt{stops}.

\begin{figure}[!h]
  \centering
\begin{minted}[ frame         = lines,
                framesep      = 0.3cm,
                numbers       = left,
                numbersep     = -0.2cm,
                bgcolor       = sepia,
                xleftmargin   = 0.3cm,
                xrightmargin  = 0.3cm
              ]{python3}
     def stops(t, a):
         l = """def loop(x):
                    while True:
                        x = 1
             """
         e = equal(l, t, a);
         if e == 2:
             return 2
         else:
             return 1 - e
\end{minted}
  \vspace*{-0.3cm}
  \caption{An implementation of the function \texttt{stops}.}
  \label{fig:stops}
\end{figure}

Notice that in line 6 the function \texttt{equal} is called with a string that is test function with
name \texttt{loop}.  This test function has the following form:
\begin{verbatim}
        def loop(x):
             while True:
                 x = 1
\end{verbatim}
Independent from the argument $x$, the function \texttt{loop} does not terminate.
Therefore, if the first argument $t$ of \texttt{stops} is a test function with name $n$,
the function \texttt{equal} will return $1$ if $n(a)$ diverges, and will return $0$ otherwise.
But this implementation of \texttt{stops} would then solve the halting problem as
for a given test function $t$ with name $n$ and argument $a$ the function \texttt{stops} would
return 1 if and only the evaluation of $n(a)$ terminates.  As we have already proven that the
halting problem is undecidable, there can be no function \texttt{equal} that solves the equivalence
problem either.
\qed

\remarkEng
The unsolvability of the equivalence problem has been proven by \href{http://en.wikipedia.org/wiki/Henry_Gordon_Rice}{Henry Gordon Rice} \cite{rice:1953} in 1953.
\eox

\section{Concluding Remarks}
Although, in general, we cannot decide whether a program terminates for a given input, this does not mean
that we should not attempt to do so.  After all, we only have proven that there is no procedure that
can \underline{alwa}y\underline{s} check whether a given program will terminate.  There might well exist a
procedure for termination checking that works most of the time.  Indeed, there are a number of
systems that try to check whether a program will terminate for every input.  For example, for
\href{https://en.wikipedia.org/wiki/Prolog}{Prolog}
programs, the paper
``\href{http://link.springer.com/chapter/10.1007%2F3-540-61739-6_44}{\emph{Automated Modular Termination Proofs for Real Prolog Programs}}''
\cite{mueller:1996} describes a successful approach.  The recent years have seen a lot of progress in
this area.  The article
``\href{http://dl.acm.org/citation.cfm?id=1941509}{{Proving Program Termination}}''
\cite{cook:2011} reviews these developments.  However, as the recently developed systems rely on both
\href{http://en.wikipedia.org/wiki/Automated_theorem_proving}{\emph{automatic theorem proving}} and
\href{http://en.wikipedia.org/wiki/Ramsey_theory}{\emph{Ramsey theory}} they are quite out of the
scope of this lecture.

\section{Chapter Review}
You should be able to solve the following exercises.
\begin{enumerate}
\item Define the halting problem.
\item Define the equivalence problem.
\item Define the notion of a countable set.
\item Prove that the set $2^{\mathbb{N}}$ is not countable.
\end{enumerate}

\section{Further Reading}
The book ``\emph{Introduction to the Theory of Computation}'' by Michael Sipser \cite{sipser:1996}
discusses the undecidability of the halting problem in section 4.2.  It also covers many related
undecidable problems.

Another good book discussing undecidability is the book
``\emph{Introduction to Automata Theory, Languages, and Computation}'' written by John E.~Hopcroft,
Rajeev Motwani and Jeffrey D.~Ullman \cite{hopcroft:06}.  This book is the third edition of a
classic text.  In this book, the topic of undecidability is discussed in chapter 9.

The exposition in these books is based on
\href{https://en.wikipedia.org/wiki/Turing_machine}{Turing machines} and is therefore more formal than the
exposition given here.  This increased formality seems necessary to prove that, for example, it is undecidable
whether two \href{https://en.wikipedia.org/wiki/Context-free_grammar}{context free grammars} are equivalent.

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "logic.tex"
%%% End:


\chapter{Proof by induction}

\begin{example}
    Prove that every term the sequence given by $a_1=3$ and $a_{n+1}=a_n+2$
    is odd.
    \par\noindent\hrulefill\par\par
    When $n=1$, $a_n=a_1=3$ which is odd. Therfor the theorem is true for $n=1$
    \par
    Assume the theorem is true for $n=k$. Therefor $a_k=2p+1$ where $p\in\mathbb{Z}$
    \par
    Now we need to show the theorem is true for $n=k+1$.
    Target statement: $a_{k+1}=2q+1$ where $q\in\mathbb{Z}$.
    \begin{align*}
        a_{k+1}&=a_k+2\\
        &=2p+1+2 &\text{ where } p\in\mathbb{Z}\\
        &= 2(p+1)+1 \\
        &= 2q+1 &\text{ where } q\in\mathbb{Z}
    \end{align*}
    Because it is true for $n=1$ and $n=k$ being true implys the theorem is
    true for $n=k+1$, so it is true for all $n\in\mathbb{N}^+$
\end{example}
\begin{example}

\end{example}


\subsection{Relations and equality}

\subsubsection{Relations}

A special type of predicates is a relation. These take two terms and can be written differently:
$P(x,y)\Leftrightarrow x\oplus y$

\subsubsection{Equality}

In preterite logic we define the relation for equality.

\(a=b\)

It is defined by the following:

\begin{itemize}
\item Reflexivity : \(x=x\)
\item Symmetry: \(x=y\leftrightarrow y=x\)
\item Transivity: \(x=y\land y=z \rightarrow x=z\)
\item Substitution for functions: \(x=y\rightarrow f(x)=f(y)\)
\item Substitution for formulae: \(x=y\land P(x)\rightarrow P(y)\)
\end{itemize}


\subsection{Consistency and efficiency of estimators}

\subsubsection{Consistency}

A statistic \(\hat \theta \) is a consistent estimator for \(\theta \) if its error tends to \(0\).

That is:

\(\hat \theta\rightarrow^p \theta \)

We can show that an estimator is consistent if we can write:

\(\hat \theta -\theta \) as a function of \(n\), causing it to tend to \(0\).

\subsubsection{Efficiency}

Efficiency measures the speed at which a consistent estimator tends towards the true value.

The speed of this convergence is the efficiency. could be fairly efficient plus biased too	p Measured as:

\(e(\hat \theta )=\dfrac{\dfrac{1}{I(\theta )}}{Var (\hat \theta )}\)

If an estimator as an efficiency of \(1\) and is unbiased, it is efficient.

\subsubsection{Relative efficiency}

We can measure the relative efficiency of two consistent estimators:

The relative efficiency is the variance of the first estimator, divided by the variance of the second.

\subsubsection{Root-n estimators}

An estimator is root-n consistent if it is consistent and its variance is:

\(O(\dfrac{1}{n})\)

\subsubsection{\(n^\delta \)-convergent}

A consistent estimator is \(n^\delta \)-consistent if its variance is:

\(O(\dfrac{1}{n^{2 \delta }})\)


\section{Vector Fields}
\noindent
Vector fields are a function $f : \mathbb{R}^n \to \mathbb{R}^n$. This is generally conceptualized as assigning an n-dimensional vector to every point in an n-dimensional space.\\
Many physics concepts can be thought of as vector fields. The electric field due to some point charge $Q$ as some distance $r$ from $Q$ is $\vec{E}(x,y,z) = \frac{\epsilon_{0}Q}{r^2}\hat{r}$ where $\epsilon_{0}$ is a constant and $\hat{r}$ is a radial unit vector pointing away from $Q$.

[INSERT IMAGE]

\noindent
A generic 2D vector field is
\begin{equation*}
	\vec{F}(x,y) = \langle P(x,y), Q(x,y) \rangle
\end{equation*}
Vector fields work similarly to VVFs in that they are added component-wise.