\documentclass[11pt]{article}
\usepackage{fixltx2e}
\usepackage{slashbox}
\usepackage{courier}
\usepackage{lmodern}
\usepackage{titlesec}
\usepackage{chngcntr}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{epstopdf}
\usepackage[table]{xcolor}
\usepackage[normalem]{ulem}
\usepackage[authoryear]{natbib}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}


\textwidth = 6.5 in
\textheight = 9 in
\oddsidemargin = 0.0 in
\evensidemargin = 0.0 in
\topmargin = 0.0 in
\headheight = 0.0 in
\headsep = 0.0 in
\parskip = 0.01in
\parindent = 0.0in

\bibliographystyle{gsabull}

\newcommand\tab[1][1cm]{\hspace*{#1}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}{Definition}

\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\alph{subsection}}
\renewcommand\thesubsubsection{\roman{subsubsection}.}
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

%\makeatletter
%\renewcommand\subsection{\@startsection{subsection}{3}{\z@}%
%                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
%                                     {-1.5ex \@plus -.2ex}% Formerly 1.5ex \@plus .2ex
%                                     {\normalfont\large\bfseries}}
%\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
%                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
%                                     {-1.5ex \@plus -.2ex}% Formerly 1.5ex \@plus .2ex
%                                     {\normalfont\large\bfseries}}
%\makeatother

\counterwithin{subsection}{section}
\counterwithin{subsubsection}{subsection}

\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{lightyellow}{rgb}{1,1,0.75}

\lstset{frame=tb,
  backgroundcolor = \color{lightyellow},
  language=C,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle=\ttfamily,
  numbers=left,
  numberstyle=\ttfamily,
  keywordstyle=\ttfamily,
  commentstyle=\color{red}\ttfamily,
  stringstyle=\ttfamily,
  emph={Strategy, Game, strat, function, int, bool, float, if, else, expected, cycle, default},
  emphstyle=\bf\ttfamily,
  breaklines=true,
  breakatwhitespace=true,
  tabsize=6,
  escapeinside={<@}{@>}
}

\begin{document}

% Title
\begin{center}
\huge {\ttfamily replay}

\includegraphics[width=1 cm]{replay_icon.pdf}

% Proposal
\large \textsc{Language Reference Manual}
\vspace{0.1 in}

% Name
\large Eric Bolton - edb2129
\vspace{0.1 in}

\end{center}

\tableofcontents

\newpage

\section{Introduction}

$~~~$ {\ttfamily replay} is an imperative programming language designed to make strategies in repeated games easier to represent and analyze. It draws inspiration from three papers in game theory, Abreu and Rubinstein (1988),  Miller (1987), and Rubinstein (1986), which first formalized the use of automata theory for the analysis of games, an idea that was first suggested by Aumann (1981). As such, {\ttfamily replay} provides a framework for defining strategies as finite automata (Moore machines). In addition, it enables game payoffs to be specified functionally, simplifying the process of defining complex games. Finally, it provides tools central to the genetic algorithm introduced by Holland (1975), which has proven instrumental in the analysis of strategies in repeated games.

\section{Lexical conventions}

\subsection{Tokens}
There are five different kinds of tokens in {\ttfamily replay} : identifiers, keywords, literals, operators, and punctuation.

\tocless\subsubsection{Variables}

Variables begin with a letter, followed by any number of letters, digits, or underscores '{\ttfamily \_}'.

The underscore '{\ttfamily \_}' by itself denotes a wildcard in the context of moves (see 3. Expressions).

\tocless\subsubsection{Keywords}

The following identifiers are reserved for use as keywords:

{\ttfamily 
\begin{tabular}{ll}
int & if\\
bool & else \\
float & for\\
string & in\\
void & return\\
 Game & true\\
Strategy & false\\
Player & strat\\
& rand
\end{tabular}
}

\tocless\subsubsection{Literals}

There are literals for each type, as follows:

\begin{itemize}
\item {\ttfamily int}: A sequence of digits.
\item {\ttfamily bool}: A '{\ttfamily true}' or a '{\ttfamily false}'
\item {\ttfamily float}: Two possibilities: \begin{itemize} 
	\item An integer part, a decimal point '{\ttfamily .}', a fraction part, and an exponent. The integer and fraction parts consist of a sequence of digits. The exponent consists of an {\ttfamily e}, followed by an optional sign {\ttfamily -} or {\ttfamily +}, and a sequence of digits. The integer and fraction parts are both optional, but at least one of the two must be present. Likewise, the decimal point and the exponent are both optional, but at least one must be present.
	\item A '{\ttfamily rand}' keyword, which gets interpreted as a random floating point number between 0 and 1 at compile time. \end{itemize}
\item {\ttfamily string}: Any number of characters, delimited by quotes '{\ttfamily " "}'.
\end{itemize}

\tocless\subsubsection{Operators}

There are 18 operators, as follows:

{\ttfamily 
\begin{tabular}{lll}
+$~~~$ & == $~~$ & \&\& \\
- & != & ||\\
* & > & !\\ 
/ & <\\
= & >=\\
-> & <=\\
\% & \\
\# & \\
\textasciitilde \\
\end{tabular}
}

\tocless\subsubsection{Punctuation}

The following characters are used as punctuation:

{\ttfamily 
\begin{tabular}{lll}
( & ) \\
\lbrack & \rbrack \\
\{ & \} \\
: & ; \\
. & , \\
| \\
\end{tabular}
}
$\\$
\subsection{Separators}
Comments and whitespace are ignored by the scanner, except to serve as separators.

\begin{itemize}
	\item Comments are delimited by {\ttfamily /*} and {\ttfamily */}.

	\item ' ' (space),  '{\ttfamily \textbackslash t}' (tab), '{\ttfamily \textbackslash r}' (carriage return), and  '{\ttfamily \textbackslash n}' (newline) are treated as whitespace.
\end{itemize}

\section{Expressions}

\subsection{Operations}
An expression can be an operation, which consists of parentheses, expressions, unary operators, and binary operators.

\tocless\subsubsection{Unary operators}
Unary operators group right-to-left and have higher precedence than binary operators. They behave as follows: \begin{itemize}

\item {\ttfamily -}\textit{expression}: Unary negation. The result is the negative of the expression, without changing its type. It is applicable only to expressions of type {\ttfamily int} or {\ttfamily float}.

\item {\ttfamily !}\textit{expression}: Logical negation. The result is {\ttfamily true} if the expression is {\ttfamily false}. Conversely, it is {\ttfamily false} if the expression is {\ttfamily true}. It is applicable only to expressions of type {\ttfamily bool}.
\end{itemize}

\tocless\subsubsection{Binary operators}
Binary operators group left-to-right. Here they are, sorted from highest to lowest by precedence:

{\ttfamily 
\begin{tabular}{llll}
* & / \\
+ & - \\
> & >= & < & <= \\
== & != \\
\&\& \\
||
\end{tabular}
}
$\\$

They behave as follows:
\subsubsection*{Arithmetic operators}

\begin{itemize}
\item \textit{expression}{\ttfamily *}\textit{expression}: Multiplication. The result is {\ttfamily float} if one of the two operands is {\ttfamily float}. The result is {\ttfamily int} if both operands are {\ttfamily int}. If one operand is {\ttfamily float} and the other is {\ttfamily int}, the {\ttfamily int} gets converted to {\ttfamily float}. Multiplication is applicable only to expressions of type {\ttfamily int} or {\ttfamily float}.

\item \textit{expression}{\ttfamily /}\textit{expression}: Division. Result and operand types behave the same way as with multiplication.

\item \textit{expression}{\ttfamily +}\textit{expression}: Addition. Types behave the same way.

\item \textit{expression}{\ttfamily -}\textit{expression}: Subtraction. Types behave the same way.
\end{itemize}

\subsubsection*{Relational operators}

\begin{itemize}
\item \textit{expression}{\ttfamily >}\textit{expression}: Greater than.
\item \textit{expression}{\ttfamily <}\textit{expression}: Less than.
\item \textit{expression}{\ttfamily >=}\textit{expression}: Greater than or equal to.
\item \textit{expression}{\ttfamily <=}\textit{expression}: Less than or equal to.
\end{itemize}

The result of these operators is {\ttfamily true} if the relation is true, and {\ttfamily false} if it is false.  If one operand is {\ttfamily float} and the other is {\ttfamily int}, the {\ttfamily int} gets converted to {\ttfamily float}. Relational operators are applicable only to expressions of type {\ttfamily int} or {\ttfamily float}.

\subsubsection*{Equality operators}

\begin{itemize}
\item \textit{expression}{\ttfamily ==}\textit{expression}: Equal to.
\item \textit{expression}{\ttfamily !=}\textit{expression}: Not equal to.
\end{itemize}

These behave the same as the relational operators, except that they are applicable to more types: any pair of operands that are of the same type. Additionally, if one operand is {\ttfamily float} and the other is {\ttfamily int}, the {\ttfamily int} gets converted to {\ttfamily float}.

\subsubsection*{Boolean operators}

\begin{itemize}
\item \textit{expression}{\ttfamily ||}\textit{expression}: Or. The result is {\ttfamily true} if either operand is {\ttfamily true}, and {\ttfamily false} otherwise. It is applicable only to operands of type {\ttfamily bool}.

\item \textit{expression}{\ttfamily \&\&}\textit{expression}: And. The result is {\ttfamily true} if both operands are {\ttfamily true}, and {\ttfamily false} otherwise. Like {\ttfamily ||}, it is applicable only to operands of type {\ttfamily bool}.
\end{itemize}

\tocless\subsubsection{Parentheses}
{\ttfamily (}\textit{expression}{\ttfamily )}: The result is simply that of the expression enclosed in parentheses.
$\\$
\subsubsection*{Note: special operators}
{\ttfamily \% \# \textasciitilde}: Play, cross, and mutate: Because these operators behave differently from the operators cited above, they are treated as statements. (See Section 5.2).

\subsection{Literals and identifiers}

\tocless\subsubsection{Literals}
An expression can be any of the literals specified in Section 2.1.3. The result is the type of the literal.

\tocless\subsubsection{Identifiers}
An expression can be an \textit{identifier}, which in turn can be any of the following:

\begin{itemize}
\item \textit{variable}: A variable, as specified in section 2.1.1.
\item \textit{variable}{\ttfamily (}\textit{actuals$_{opt}$}{\ttfamily )}: The result of calling the function \textit{variable} with parameters specified by the list of comma-separated values \textit{actuals$_{opt}$}.
\item \textit{identifier}{\ttfamily \lbrack}\textit{expression}{\ttfamily \rbrack}: The value at index \textit{expression} of the array \textit{identifier}. \textit{expression} must be an {\ttfamily int}, while \textit{expression} must be an array. (See Section 3.3 Non-primitive types)
\item \textit{variable}{\ttfamily .}\textit{identifier}: The attribute \textit{identifier} of \textit{variable}. (See Section 3.4 Attributes)
\end{itemize}

\subsection{Non-primitive types}

An expression can also be a {\ttfamily Strategy}, a {\ttfamily Game}, a {\ttfamily Player}, or an array, the non-primitive types of {\ttfamily replay}.

\tocless\subsubsection{Strategies}

An expression can be:

\begin{itemize}
\item {\ttfamily Strategy\lbrack}\textit{params}{\ttfamily \rbrack}: A Strategy. \textit{params} is a list of \textit{expression}s separated by {\ttfamily |}'s. In this case, it must consist of the number of states (an {\ttfamily int}), the number of moves the strategy is based on (an {\ttfamily int}), and a list of \textit{states} (see below). The numbers are needed to gauge memory requirements. This expression has type {\ttfamily Strategy}.
\item {\ttfamily \{}\textit{states}{\ttfamily \}}: A list of \textit{state}'s, enclosed by braces and separated by semicolons. This is the last \textit{expression} required by the {\ttfamily Strategy\lbrack}\textit{params}{\ttfamily \rbrack} constructor.
\end{itemize}

\subsubsection*{States}
A \textit{state} is specified as follows:

\begin{center}
\textit{variable}{\ttfamily :}\textit{expression}{\ttfamily ,}\textit{transitions}
\end{center}

\textit{variable} is the name of the state, and is set to be an {\ttfamily int}. \textit{expression} corresponds to the move the state outputs, which must be of type {\ttfamily int}. \textit{transitions} is a list of transitions, separated by bars.

\subsubsection*{Transitions}
A \textit{transition} is specified as follows:

\begin{center}
{\ttfamily (}\textit{moves}{\ttfamily )->}\textit{variable}
\end{center}

\textit{moves} is a comma-separated list of either {\ttfamily int}'s or wildcards '{\ttfamily \_}'. \textit{variable} corresponds to the name of the state, and must be an {\ttfamily int}.

To summarize, here is an example Strategy expression:
\begin{lstlisting}
Strategy[10 | 2 | {
  cooperate:   C, (_,D) -> defect
                | (_,C) -> cooperate;
  defect:      D, (_,_) -> defect; }]
\end{lstlisting}
This specifies a strategy with 10 states, and 2 possible moves.
States don't need to have every possible transition specified; a state will by default map back to itself. Furthermore, not all states need to be specified: states will by default output whatever move is denoted by 0, and map back to themselves.

\tocless\subsubsection{Games}

An expression can be:

\begin{itemize}
\item {\ttfamily Game\lbrack}\textit{params}{\ttfamily \rbrack}: A Game. In this case, \textit{params} must consist of the number of moves (an {\ttfamily int}) in the game and a list of \textit{outcomes} (see below). This expression has type {\ttfamily Game}.
\item {\ttfamily \{}\textit{outcomes}{\ttfamily \}}: A list of \textit{outcome}'s, enclosed by braces and separated by bars {\ttfamily |}.
\end{itemize}

\subsubsection*{Outcomes}
An \textit{outcome} is specified as follows:

\begin{center}
{\ttfamily (}\textit{moves}{\ttfamily )->(}\textit{payoffs}{\ttfamily )}
\end{center}

\textit{payoffs} is a comma-separated list of \textit{expression}'s, which must be of type {\ttfamily int}.

To summarize, here is an example Game expression:
\begin{lstlisting}
Game[2 | { (C,C) -> (-1,-1)
| (C,D) -> (-5,0)
| (D,C) -> (0,-5)
| (D,D) -> (-3,-3); }]
\end{lstlisting}
A game's payoffs can also be specified functionally:
\begin{lstlisting}
Game[2 | { (x,y) -> (x * y - 1,  x * y + 1)}]
\end{lstlisting}

\tocless\subsubsection{Players}

An expression can also be a Player, specified as follows:

\begin{center}
{\ttfamily Player\lbrack}\textit{params}{\ttfamily \rbrack}
\end{center}

In this case, the first element of \textit{params} must be a {\ttfamily Strategy}, corresponding to the Player's strategy. Then, the user can optionally specify additional parameters of type {\ttfamily float}. These correspond, in order, to:
\begin{itemize}
\item The Player's delta: how much value the player attributes to payoffs acquired in future rounds.
\item The Player's output noise: the probability that a move by the Player will be incorrectly reported.
\item The Player's input noise: the probability that the Player will receive an incorrect report of played moves.
\end{itemize}
This expression has type {\ttfamily Player}.

A Player tracks the state it is in, its accumulated payoff, and how many times it has played. Each time it "plays" in a Game, it adds the payoff it received, multiplied by its delta raised to the power of how many times it has played.

To summarize, here is an example Player expression:
\begin{lstlisting}
Player[grim | 0.5 | 0.01 | 0.01]
\end{lstlisting}

\tocless\subsubsection{Arrays}

Finally, an expression can be arrays, specified as follows:

\begin{itemize}
\item \textit{type}{\ttfamily \lbrack}\textit{params}{\ttfamily \rbrack}: A \textit{type} array. When \textit{params} has only one value of type {\ttfamily int}, this construction always specifies an array.
\item {\ttfamily [}\textit{expression$_1$}{\ttfamily :}\textit{expression$_2$}{\ttfamily ]}: An integer array of size \textit{expression$_2$} - \textit{expression$_1$}, whose values range from \textit{expression$_1$} to \textit{expression$_2$}. Both \textit{expression}'s are required to be {\ttfamily int}'s.
\end{itemize}

\subsection{Attributes}

{\ttfamily replay}'s non-primitive types have built-in attributes:

\begin{itemize}
\item {\ttfamily string}: \begin{itemize}
	\item {\ttfamily len}: The length of the string. \end{itemize}
\item Arrays: \begin{itemize}
	\item {\ttfamily len}: The length of the array.\end{itemize}
\item {\ttfamily Strategy}: \begin{itemize}
	\item {\ttfamily size}: The number of states in the Strategy. ({\ttfamily int})
	\item {\ttfamily moves}: The number of moves the Strategy can play. ({\ttfamily int})
	\item {\ttfamily term}:  The number of terminal states in the Strategy. ({\ttfamily int})
	\item {\ttfamily inacc()}: Counts the number of inaccessible states in the Strategy. ({\ttfamily int})
	\item {\ttfamily change(}\textit{actuals$_{opt}$}{\ttfamily )}: Changes the state at a specified address to a new one \textit{actuals$_{opt}$} must be a list consisting of one {\ttfamily int}, and a list of one state. ({\ttfamily void})\end{itemize}
\item {\ttfamily Game}: \begin{itemize}
	\item {\ttfamily players}: The number of players in the game. ({\ttfamily int})
	\item {\ttfamily moves}: The number of moves each player can play. ({\ttfamily int})
	\item {\ttfamily payoff(}\textit{actuals$_{opt}$}{\ttfamily)}: Returns the payoff of a specified player when a specified profile is played. \textit{actuals$_{opt}$} must be a list of one {\ttfamily int} and one {\ttfamily int} array, the {\ttfamily int} specifying the player, and the array specifying the moves in the profile. ({\ttfamily int})
	\item {\ttfamily change(}\textit{actuals$_{opt}$}{\ttfamily)}: Changes the payoffs resulting from a specified profile to a new specified set of payoffs. \textit{actuals$_{opt}$} must be a list of two {\ttfamily int\lbrack\rbrack} arrays, the first one specifying the profile, the second one specifying the payoffs. ({\ttfamily void})\end{itemize}
\item {\ttfamily Player}: \begin{itemize}
	\item {\ttfamily strategy}: The strategy of the Player. ({\ttfamily Strategy})
	\item{\ttfamily state}: The state of the Player's Strategy the Player is in. ({\ttfamily int})
	\item{\ttfamily rounds}: The number of rounds the Player has played. ({\ttfamily int})
	\item {\ttfamily output}: The output noise level of the Player. ({\ttfamily float})
	\item {\ttfamily input}: The input noise level of the Player. ({\ttfamily float})
	\item {\ttfamily delta}: The delta of the Player. ({\ttfamily float})
	\item {\ttfamily payoff}: The accumulated payoff of the Player. ({\ttfamily float})
	\item {\ttfamily reset()}: Resets the accumulated payoff and the number of moves to 0. ({\ttfamily void}) \end{itemize}
\end{itemize}

Each non-primitive type, with the exception of {\ttfamily string}, has a {\ttfamily string()} function as an attribute, which provides a string representation for the type.

Users cannot specify new attributes, nor can they change their value.

\section{Declarations}
There are three types of declarations: function declarations, variable declarations, and the {\ttfamily strat} enumerator.

\subsection{Functions}

A function declaration is specified as follows:

\begin{center}
\textit{type} \textit{variable} {\ttfamily (}\textit{formals$_{opt}$}{\ttfamily )\{}\textit{statements}{\ttfamily \}}
\end{center}

\textit{type} and \textit{variable} specify the type and name of the function. \textit{formals$_{opt}$} specify the arguments the function takes, just as \textit{actuals$_{opt}$} specify the arguments passed in a function call. Finally, \textit{statements} is a list of any number of \textit{statement}'s, corresponding to the body of the function. (See Section 5. Statements) A function's last statement must be {\ttfamily return} statement, whose return type must correspond to the type of the function. 

\tocless\subsubsection{Built-in functions}
Certain function names are reserved. They serve the following two purposes:
\subsubsection*{Printing}
\begin{itemize}
\item {\ttfamily print(}\textit{actuals$_{opt}$}{\ttfamily )}: Takes one argument, converts it to a {\ttfamily string} using its type's {\ttfamily string()} attribute, then prints it out. ({\ttfamily void})
\item {\ttfamily println(}\textit{actuals$_{opt}$}{\ttfamily )}: Does the same, then prints a newline character. ({\ttfamily void})
\end{itemize}
\subsubsection*{Type-casting}
\begin{itemize}
\item {\ttfamily tofloat(}\textit{actuals$_{opt}$}{\ttfamily )}: Takes an argument of type {\ttfamily int}, and returns a {\ttfamily float} corresponding to that {\ttfamily int}. ({\ttfamily float})
\item {\ttfamily toint(}\textit{actuals$_{opt}$}{\ttfamily )}: Takes an argument of type {\ttfamily float}, and returns an {\ttfamily int} corresponding to the floor of that {\ttfamily float}. ({\ttfamily int})
\end{itemize}

\subsection{Variables}

A variable declaration can take two forms:

\begin{itemize}
\item \textit{type} \textit{variable} {\ttfamily =} \textit{expression}: This declares a \textit{variable} of type \textit{type}, and initializes it with the value \textit{expression}. The types of the \textit{expression} and the \textit{variable} must match.
\item \textit{type} \textit{variable}: This declares a \textit{variable} of type \textit{type}, and initializes it to a default value.
\end{itemize}

\tocless\subsubsection{Arrays}

In the case of an array declaration, the \textit{type} is followed by {\ttfamily \lbrack\rbrack}:
\begin{itemize}
\item \textit{type}{\ttfamily \lbrack\rbrack}\textit{variable} {\ttfamily =} \textit{expression}
\item \textit{type}{\ttfamily \lbrack\rbrack}\textit{variable}
\end{itemize}

\subsection{{\ttfamily strat} enumerator}

Finally, a user can declare a set of moves using the {\ttfamily strat} enumerator:
\begin{center}
{\ttfamily strat \{}\textit{variables}{\ttfamily \}}
\end{center}
\textit{variables} is a comma-separated list of $n$ \textit{variable}'s, which get declared with type {\ttfamily int} by this construction. They are initialized with values 0 through $n$ depending on their position in the list.

\section{Statements}

There are many types of statements. A program consists of a list of statements and function declarations, in any order.

\subsection{Variable or strat declaration}
A statement can be either a variable or {\ttfamily strat} declaration, followed by a semicolon '{\ttfamily ;}'

\subsection{Play, Mutate, and Crossover}
A statement can be any of the operations on Players.

\begin{itemize}
\item \textit{identifiers}{\ttfamily \%}\textit{expression}{\ttfamily ;}: Play. \textit{identifiers} is a comma-separated list of \textit{identifier}'s, which must be {\ttfamily Player}'s. \textit{expression} must be a {\ttfamily Game}. This operator pits the Players against each other for a round of the Game, updating their payoffs and Strategy states.
\item \textit{identifier}{\ttfamily \textasciitilde}\textit{expression}{\ttfamily ;}: Mutate. \textit{identifier} must be a {\ttfamily Player}, and \textit{expression} must be a {\ttfamily float}. This operation acts on the bit representation of the {\ttfamily Player}'s strategy, changing each bit with a probability specified by the {\ttfamily float}.
\item \textit{identifier$_1$}{\ttfamily \#}\textit{expression}{\ttfamily \#}\textit{identifier$_2$}{\ttfamily ;}: Crossover. \textit{identifier$_1$} and \textit{identifier$_2$} must be {\ttfamily Player}'s, and \textit{expression} must be a {\ttfamily float}. This operation acts on the bit representations of the {\ttfamily Player}'s strategies, crossing the two representations at the position indicated by the {\ttfamily float}.
\end{itemize}

Now for an illustration of the effect of the following crossover statement's effect: {\ttfamily p1 \# 0.75 \# p2;}

Let $P_1$ be the bit representation of {\ttfamily p1}'s strategy, and $P_2$ be the bit representation of {\ttfamily p2}'s strategy.

Say before crossover, we have:

$P_1 = 11111111$ and $P_2 = 00000000$

After crossover, we would have:

$P_1 = 11111100$ and $P_2 = 00000011$.
The bits following the position $\frac{3}{4}$, or 0.75 of the way into the bit representation have been swapped.

\subsection{Assignment}
A statement can be an assignment statement.
\begin{center}
\textit{identifier}{\ttfamily =}\textit{expression}{\ttfamily ;}
\end{center}
The \textit{identifier} must be an array entry or a \textit{variable}; it cannot be an attribute or a function call. The \textit{expression} must be of the same type as the \textit{identifier}. The value of the \textit{expression} gets assigned to the \textit{identifier}.

\subsection{Return}
A statement can be a return statement.
\begin{center}
{\ttfamily return} \textit{expression$_{opt}$}{\ttfamily ;}
\end{center}
If \textit{expression$_{opt}$} is left empty, this returns a {\ttfamily void}. Otherwise, this returns an expression of type \textit{expression$_{opt}$}.

\subsection{If, else}
A statement can be an if-else statement.
\begin{itemize}
\item {\ttfamily if (}\textit{expression}{\ttfamily )}\textit{statement}: \textit{statement} is executed if and only if \textit{expression} evaluates to {\ttfamily true}. \textit{expression} must be a {\ttfamily bool}.
\item   {\ttfamily if (}\textit{expression}{\ttfamily )}\textit{statement$_1$} {\ttfamily else} \textit{statement$_2$}: If \textit{expression} evaluates to {\ttfamily false}, \textit{statement$_2$} is executed.
\end{itemize}

\subsection{For, in}
A statement can be a for-loop.
\begin{center}
{\ttfamily for} \textit{variable} {\ttfamily in} \textit{expression} \textit{statement}
\end{center}
\textit{expression} must be an array. For each iteration of the for-loop, \textit{statement} is executed and \textit{variable} takes on the next value of the array, until the end of the array is reached.

\subsection{List}
Finally, a statement can be a brace-enclosed list of statements:
\begin{center}
{\ttfamily \{}\textit{statements}{\ttfamily \}}
\end{center}

\section{Scope}

A \textit{variable}'s scope reaches any line following their declaration. If they are declared within braces {\ttfamily \{\}}, they have local scope and cannot be reached outside of the braces.

If a \textit{variable} is declared as part of a for-loop statement, its scope is limited to that for-loop's statement.

If an undeclared \textit{variable} is used in a set of moves to define payoffs functionally within a list of \textit{outcomes}, its scope reaches only the payoffs that directly follow the arrow of the \textit{outcome} it is used in.

Finally, when a \textit{variable} is used to name a state in a Strategy, its scope extends to all states in the strategy, whether they precede or follow it.

\section{References}

Abreu, D. and Rubinstein, A. "The Structure of Nash Equilibrium in Repeated Games with Finite Automata." \textit{Econometrica} 56 (November, 1988):1259-81.

Aumann, R. T. "Survey of Repeated Games." In R. T. Aumann et al., eds., \textit{Essays in Game Theory and Mathematical Economics in Honor of Oscar Morgenstern} (Bibliographisches Institut, Zurich: Mannheim), 1981:11-42.

Holland, T. H. \textit{Adaptation in Natural and Artificial Systems.} Ann Arbor, Michigan: The University of Michigan Press, 1975.

Ritchie, Dennis M. \textit{C Reference Manual} Bell Telephone Laboratories. 1978

Rubinstein, A. "Finite Automata Play the Repeated Prisoner's Dilemma." \textit{Journal·of Eco-
nomic Theory} 39 (June, 1986):83-96.

Miller, J. H. "The Coevolution of Automata in the Repeated Prisoner's Dilemma" SFI Working Paper: 1989--003


%\begin{center}
%\includegraphics[width=5 cm]{HW2_1_7e.pdf}
%\end{center}


%\begin{center}
%\begin{tabular}{|c|c|c|}
%\hline
%\multicolumn{3}{|c|}{Player 3 plays $D$} \\
%\hline
%\backslashbox{1}{2} & L & R \\
%\hline
%T & \cellcolor[HTML]{888888} \underline{2},1\underline{1} & \underline{3},\underline{3},1 \\
%\hline
%B & \cellcolor[HTML]{888888} 0,0,2 & 1,\underline{1},-3 \\
%\hline
%\end{tabular}
%\end{center}


\end{document}