\chapter{Explorations in games on networks}\label{ch:games-on-networks}
\section{Game theory}
\subsection{Prisoner's Dilemma}\label{subs:prisoners-dilemma}
The Prisoner's Dilemma is the canonical game of game theory finding its use in models for everything from how firms price goods\cite{p-d-goods} to sharing in vampire bats\cite{p-d-nature}. In any situation where there is the possibility of cooperation, the Prisoner's Dilemma can be a useful model in understanding the situation to a first approximation.\\
\\
%\paragraph{The Story}
The motivating story goes that two accomplices are caught at a crime scene, arrested and placed in separate cells with no contact. The police give them each a choice: they can confess their crimes to the authorities or they can stay silent. They learn that if they both stay silent, they only get one year in prison. If they both confess, they both get two years. However, if one of them confesses and the other stays silent, the snitch gets out immediately while the snitched-upon gets 3 years. As they are in separate cells, they cannot communicate.\\
\\
The smallest combined time in prison for the couple is if they both stay silent and take 1 year in jail each. But even if they could communicate and agree to the appealing option of both staying silent, it would still make sense to defect from the `contract' and confess. Just 1 year in jail is clearly better than 2. How should they work through this? As with most things in life, they should get mathematical.
\subsubsection{Making this mathematical}
%\paragraph{Key Concepts}
This story has all the features of a game-theoretic game. Let's go through it, pick out the key elements and name them.\\
\\
The four essential elements of a game have a useful acronym: \textit{PAPI}\cite{rasmusen_2010}. This stands for:
\begin{enumerate}[nosep]
\item \textbf{P}layers of the game,
\item \textbf{A}ctions available to each player,
\item \textbf{P}ayoffs for each outcome
\item \textbf{I}nformation available to each player.
\end{enumerate}
\par\null\par
In our story, there are two players: Lou and Avery. There are two actions available to them: stay silent or confess.  The payoffs are given by the years in jail, $-x$ for $x$ years in jail. As they cannot communicate, there is no information available about the other player's choice prior to choosing.\\
\\
Formally, we call staying silent a decision to \textit{cooperate} with the partner. We also say that to confess is to \textit{defect} from their partner. We usually notate actions as a single letter. Here we write $C$ for cooperate and $D$ for defect. An \textit{outcome} defines an action for each player. It can be written $(C,C)$ for two players both playing the action $C$.\\
\\
%\subsubsection{Representing games}
%\subsubsection{Payoff Matrix}
A payoff matrix is a way of defining two-player simultaneous games completely\cite{osborne}. This means that it tells you about every element of \textit{PAPI}. The payoff matrix for the Prisoner's Dilemma given in the story would be:\\
\setlength{\extrarowheight}{2pt}
\begin{tabular}{cc|c|c|}
	\centering
	& \multicolumn{1}{c}{} & \multicolumn{2}{c}{Avery}\\
	& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$C$}  & \multicolumn{1}{c}{$D$} \\\cline{3-4}
	\multirow{2}*{Lou}  & $C$ & $(-1,-1)$ & $(-3,0)$ \\\cline{3-4}
	& $D$ & $(0,-3)$ & $(-2,-2)$ \\\cline{3-4}
\end{tabular}
\\
\\
\\
The ordered pair $(x,y)$ in each matrix entry gives the payoffs for each outcome. $x$ gives the payoff for the horizontal player and $y$ gives the vertical player's. So outcome $(D,C)$ has payoff $(0,-3)$ meaning a payoff of $0$ for Lou for defecting and a payoff of $-3$ for Avery for cooperating. The players, actions and payoffs are defined. Also, in a simultaneous game there is no information available about the other player's action. So this matrix does indeed completely describe the game.\\
\\
The payoff matrix is an extremely useful representation, allowing concise, complete descriptions of games. Consider, for example:\\
\setlength{\extrarowheight}{2pt}
\begin{tabular}{cc|c|c|c|}
	& \multicolumn{1}{c}{} & \multicolumn{3}{c}{Avery} \\
	& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$R$}  & \multicolumn{1}{c}{$P$}  & \multicolumn{1}{c}{$S$} \\\cline{3-5}
	& $R$ & $(0,0)$ & $(-1,1)$ & $(1,-1)$ \\ \cline{3-5}
	Lou  & $P$ & $(1,-1)$ & $(0,0)$ & $(-1,1)$ \\\cline{3-5}
	& $S$ & $(-1,1)$ & $(1,-1)$ & $(0,0)$ \\\cline{3-5}
\end{tabular}
\\
\\
\\
This game might initially look foreign, but it is simply Rock, Paper, Scissors. You can create stories to motivate them but the payoff matrix completely defines all the relevant mathematical aspects of the game. This allows us to abstract from the messy details of the human world and find `solutions' to the game.
\subsubsection{Strategies and solution concepts}
A \textit{strategy} is a set of rules that determine which action a player will use at each point of the game. Note that as the Prisoner's Dilemma has only one point to make a decision, a strategy determines just one action. Further a strategy profile determines a strategy for each player in the game. There are various ways to discuss the effectiveness of strategies and strategy profiles in a game.\\
\\
%\subsubsection{Strategies}
%\paragraph{Socially Optimal Strategy}
The \textit{socially optimal strategy profile} is the strategy profile that leads to the highest joint payoff for all players. That is, the sum of the payoffs is the highest of all possibilities. In this game this is the easily identifiable and clearly optimal option of both players cooperating so that they get only 1 year each.\\
\\
%\paragraph{Nash Equilibrium}
However, the outcome with both defecting is the \textit{Nash Equilibrium}. Informally, the Nash Equilibrium is an outcome in which, even if all players knew almost telepathically what the other player's actions were going to be, none of them would choose to change their action as it would not improve their payoff. In this game, both players defecting, $(D,D)$, is the unique Nash Equilibrium. This is because if one player, say Lou, knew that Avery would play $D$ he would not change to $C$. Similarly for Avery.\\
\\
%\paragraph{Dominant Strategy}
The outcome of $(D, D)$ actually satisfies an even stronger condition as the action $D$ is a \textit{dominant strategy} for both players. This means that no matter what action the opponent plays, the player will always get the best payoff by defecting. This is how $(D,D)$ manages to `pull' players in, despite it having a worse payoff for both players than $(C,C)$.\\
\\
So we have described three solution concepts. Which one do we predict will happen? Game theory assumes that players are \textit{rational}. This means that the payoffs match the player's desires and they desire to increase their payoff. In other words the payoffs accurately describe their preferences. If Lou and Avery are rational, they will always end up both defecting, betraying each other and being rewarded with a longer jail term. So it goes.
\subsection{Repeated games}\label{subs:repeated-games}
%\subsubsection{Introduction}
The Prisoner's Dilemma is a \textit{one-shot game}. This means that no further games are played after the first game. It happens once and never again, with no possible repercussions that are not already described in the payoff matrix.\\
\\
Unlike one-shot games, repeated games have players play multiple games against each other. Whereas before a strategy determined just one action, in a repeated game a strategy can respond to the other player's actions. This means that it is harder or even impossible to `solve' these games to find the best actions and equilibria. However, this makes them more interesting, allowing for complex dynamics.
\subsubsection{Iterated Prisoner's Dilemma}
If we have two players playing the Prisoner's Dilemma repeatedly against each other we create the Iterated Prisoner's Dilemma. This no longer has a best strategy.\\
\\
In the absence of an analytically provable `best' strategy, we can pursue a more empirical approach. In football we cannot prove a-priori the best team. Indeed it would be a bit boring if we could. Instead, we create a tournament such as the Premier League and declare the winner of the tournament the `best' team. Inspired by this approach, we create a `tournament' of different strategies all playing several hundred games of the Prisoner's Dilemma against each other. The winner of the tournament will be the strategy with the highest payoff overall.\\
\\
This numerical experiment was famously first done by Robert Axelrod\cite{axelrod} in the 1980s. In Axelrod's first tournament, the winner was `Tit for Tat', a strategy that always cooperates on the first round and then copies the opponent's previous move forever after. Since then other researchers have repeated the tournament and Axelrod himself ran a second tournament with many more entries. A recent open-source collaboration makes it easy to replicate the Axelrod's original tournament as well as run similar ones\cite{axelrod-github}.\\
\\
For the tournament, we choose to enter five strategies: Tit for Tat, Defector, Cooperator, Alternator and Random. The names are descriptive: Defector always defects, Cooperator always cooperates, Alternator alternates between the two and Random chooses between the two actions with probability $0.5$ at each point. They play against every other strategy $10$ times. They also play against themselves $10$ times. The payoffs are also altered to fit Axelrod's first tournament. They are given by $1$ for two defectors, $3$ for two cooperators and $5$ and $0$ for the defector and cooperator respectively.\\
\setlength{\extrarowheight}{2pt}
\begin{tabular}{cc|c|c|}
	& \multicolumn{1}{c}{} & \multicolumn{2}{c}{Avery}\\
	& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$C$}  & \multicolumn{1}{c}{$D$} \\\cline{3-4}
	\multirow{2}*{Lou}  & $C$ & $(3,3)$ & $(0,5)$ \\\cline{3-4}
	& $D$ & $(5,0)$ & $(1,1)$ \\\cline{3-4}
\end{tabular}
\label{mmd}
\\
\\
Running the tournament reveals that `Defector' does best in this tournament (Fig. \ref{fig:iterated-p-d-tournament}). The key point is that there is no single strategy that dominates all the others. Whilst `Defector' does best in this tournament, with a different selection of strategies it probably would not. Indeed it was entered into Axelrod's first tournament and was beaten by Tit for Tat, a strategy it won against here. Whilst this may seem paradoxical it is no more paradoxical than a polar bear being better suited to Antarctica than a tiger but would struggle in Bali. That is, the strategies success is dependent on its environment. In it's extreme, a defector does well in a tournament full of unquestioning cooperators. However, in a tournament full of Tit For Tat strategies, the Tit for Tat strategies get consistently high payoffs through cooperation which the defector misses out on, instead getting the spoils of mutual defection.\label{mmd}
%\textit{Mark: This seems paradoxical - what is it about the tournament design that makes this possible?}
\begin{figure}
	\centering
	\begin{subfigure}{\textwidth}
		\centering
		\includegraphics[width=\linewidth]{axelrod/tournament-boxplot.png}
		\caption{The results of a tournament of the Prisoner's Dilemma between 5 strategies. The tournament was repeated 100 times. Due to the strategy `Random' the results were different each time. The plot shows the average payoff between all tournaments in the solid blue line and the shaded blue region represents the variance.
%		\textit{Mark: I don't understand this figure}
		\label{mmd}
		}
		\label{}
	\end{subfigure}%
\\
	\begin{subfigure}{\textwidth}
		\centering
		\includegraphics[width=0.95\linewidth]{axelrod/tournament-payoff-matrix.png}
		\caption{A payoff matrix showing how each strategy performed on average against the other strategies. The colour of the point $(X,Y)$ represents the score of strategy $X$ playing against strategy $Y$.}
		\label{}
	\end{subfigure}
	\caption{A tournament of the Iterated Prisoner's Dilemma between five strategies.}
	\label{fig:iterated-p-d-tournament}
\end{figure}\\
\\
We can create a grand competition with 222 different strategies. The strategies comprise every entry from a library of distinct strategies submitted to the Axelrod-Python project team\cite{axelrod-github}.\label{mmd} On this run the joint winners were: `Hard Prober', `Pun1' and `Tester'. For example Hard Prober's strategy is to play $D,D,C,C$ initially. This is to act as a test to see how cooperative its opponent is. If the opponent cooperated in moves 2 and 3, Hard Prober will defect forever. Otherwise, it will play Tit-For-Tat for the rest of time. The results of the tournament are messy to see as a plot, payoff matrix or indeed a table of the raw data. However, the alphabetically first 5 strategies are shown in Fig. \ref{fig:222}.
%\begin{tabular}{1|1}
%	\csvreader[head to column names]{images/csv/axelrod-tournament-222.csv}{}
%	{\\\hline\csvcoli&\csvcolii}
%\end{tabular}
\begin{figure}
\csvautotabular{../data/axelrod-tournament-222-short.csv}
\caption{A table of the alphabetically first 5 strategies in an iterated Prisoners Dilemma tournament of 222 different strategies.}
\label{fig:222}
\end{figure}
\subsubsection{Iterated games with evolution}
One natural extension to iterated games is to allow the possibility of `evolutionary' behaviour. For example, we can create simulations where strategies with higher payoffs are more likely to produce `offspring'. This means that the number of players using a successful strategy tends to increase.\\
\\
This can be imagined in the ordinary evolutionary sense of survival of the fittest. However, there is another useful interpretation. We can view the population as a constant group of players who are open to the possibility of changing their strategies. If they see a strategy that is working better, there is some probability that they use that strategy in the next iteration.\\
\\
We randomly select $7$ players using strategies from Axelrod's tournament. We play them off each other and themselves. After each round, they have some chance of `reproducing' proportional to the payoff they just received from playing every other player. Then the next round has a population that tends to have more of the successful strategies and less of the poorly adapted strategies. A graph describing this is given in Fig. \ref{fig:moran-100}.
\begin{figure}
	\centering
	\includegraphics[width=\linewidth,trim={0 0 0 2cm},clip]{axelrod/iterated-moran-7.png}
	\caption{A graph showing an evolutionary prisoner's dilemma tournament.\label{mmd}. At each iteration or tick one agent is chosen to reproduce and one agent is chosen to die. The probability that they are chosen to reproduce is proportional to their payoff in the previous round.}
	\label{fig:moran-100}
\end{figure}
\\
\\
%[Include replicator equations at some point here.]\\
%For example, we can also try it with different gamesbelow is a simulation of strategies playing Rock, Paper Scissors defined by the payoff matrix as above.\\
%(
%My simulation of Rock, Paper, Scissors
%)\\
%The effect is a self-balancing system. If the strategy \textit{rock} becomes more populous, \textit{paper} will start to get higher payoffs on average. This in turn brings the population back towards $\frac{1}{3}$ for each strategy.\\
%The same scenario works with the admittedly less well-known game Rock, Paper, Scissors, Spock\cite{for game}\cite{for code}.\\
%(
%My simulation of Rock, Paper Scissors, Spock
%)\\
%However, now with the different rules we can have the extinction of strategies.
We can explore the same evolutionary set-up but with the game of Rock, Paper, Scissors. Whereas evolutionary Prisoner's Dilemma resulted in one strategy eventually monopolising the population, the evolution of Rock, Paper, Scissors results in a self-balancing system (Fig. \ref{rock-paper-scissors-evo}). For example if the strategy Rock becomes more populous, Paper will start to get higher payoffs on average. This gives Paper a higher chance of reproducing resulting in Paper reproducing at a quicker rate. This holds for all three pairs. So the population has an inbuilt tendency to return the population demographic back towards $\frac{1}{3}$ for each strategy.\label{mmd}
\begin{figure}
	\centering
	\includegraphics[width=\linewidth]{axelrod/rock-paper-scissors.png}
	\caption{An evolutionary game of Rock, Paper, Scissors. The graph shows the percentage of players changing through time.}
	\label{rock-paper-scissors-evo}
\end{figure}
\section{Graph theory}\label{sec:graph-theory}
%motivation
The tools we have built so far are helping us move closer to a reasonable description of real, complex situations. In real life, games are not usually isolated situations that happen as if in a laboratory. They happen around lots of other players and allow the possibility of a change of strategy. They are also interdependent with games in some places effecting others. If a person was playing the Prisoner's Dilemma and played against several defectors consecutively, they are more likely to defect themselves. We have begun to model this.\\
\\
However, players are in general not connected to every other player. They exist in communities. To model this we need graphs.\\
\\
\subsection{Definitions}
A \textit{graph} $G=(V,E)$ is a set of vertices $V$ and a set of pairs of vertices $E$. Each pair of vertices is called an edge. For now we will consider only undirected graphs with no loops . \textit{Undirected} means that the edge $(u,v)$ is identical to the edge $(v,u)$. That is to say, the pairs constituting the edges are unordered\cite{graph-theory-reference}. The requirement of no loops means that no vertex has an edge from itself to itself. Formally, $\nexists v\textnormal{ such that } (v,v)\in E$. We can see visually what this means in Fig. \ref{fig:example-graphs}.
\begin{figure}
	\centering
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/graph-theory/directedGraph.png}
		\caption{Directed graph}
		\label{fig:dir}
	\end{subfigure}%
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/graph-theory/loopGraph.png}
		\caption{Graph with loops}
		\label{fig:loop}
	\end{subfigure}
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/graph-theory/graph.png}
		\caption{Undirected graph without loops}
		\label{fig:undirected}
	\end{subfigure}
	\caption{We will consider graphs of type \ref{fig:undirected} and ignore the others.}
	\label{fig:example-graphs}
\end{figure}
\\
\\
Two vertices $u,v$ are \textit{adjacent} if and only if $(u,v)\in E$. The neighbourhood of a vertex $v$ in a graph $G$ is the induced graph given by $v$ and all vertices adjacent to $v$. That is, it is the graph of vertex $v$ and all vertices adjacent to $v$ with edges given by the edges between any of these vertices in $G$. As such we also call the adjacent vertices \textit{neighbours}.\\
\\
%Some common graphs
A useful graph that comes up repeatedly is the \textit{complete graph, $K_n$}. This is the graph with $n$ vertices with an edge between all pairs of vertices. Formally $K_n=\{\{v_1,...,v_n\},\{(v_i,v_j):\forall i\neq j\}\}$.
\begin{figure}
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/K5.pdf}
		\caption{$K_5$}
		\label{fig:K5}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/K16.pdf}
		\caption{$K_{16}$}
		\label{fig:K16}
	\end{subfigure}
	\caption{The Complete Graphs $K_5$ and $K_{16}$}
	\label{fig:complete-graphs}
\end{figure}
\subsection{Graphs and the 2D lattice}
A graph often used in models is an adaptation of the 2D lattice as it is both instructive, relatively easy to analyse and most importantly easy to visualise\cite{eq_of_life}. The 2D lattice can be made by imagining a square grid, rows and columns of squares.
%\begin{figure}
%	\centering
%	\includegraphics[width=.5\linewidth]{appendix/graph-theory/square-grid.png}
%	\caption{A square grid}
%\end{figure}
However, we want to convert this into a graph. We can deal with the vertices easily: we put a vertex at the centre of each square. However there are multiple ways to define the edges. Which squares should be considered neighbours of each other?\\
\\
One option is to define the von Neumann neighbourhood of the 2D lattice as in Fig. \ref{fig:vonneumann}. This makes each point a neighbour of the $4$ points vertically and horizontally next to it. An alternative is given by the Moore neighbourhood as seen in Fig. \ref{fig:moore}. This includes the nearest vertical and horizontal neighbours as well as the nearest diagonal points\cite{eq_of_life}.
\begin{figure}
	\centering
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/graph-theory/von-neumann-neighbourhood.png}
		\caption{The von Neumann Neighbourhood}
		\label{fig:vonneumann}
	\end{subfigure}%
	\begin{subfigure}{.5\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/graph-theory/moore-neighbourhood.png}
		\caption{The Moore neighbourhood}
		\label{fig:moore}
	\end{subfigure}
	\caption{Different definitions of `neighbourhood' on the 2D Lattice}
	\label{fig: lattice neighbourhoods}
\end{figure}\\
\\
The graphs given by these two definitions are given in Fig. \ref{fig:graph-neighbourhoods}. The graph induced by the von Neumann neighbourhood is often called the grid graph, lattice graph. The graph induced by the Moore neighbourhood is also called the King's Graph as it represents the legal moves of a king in a game of chess.
\begin{figure}
	\centering
	\begin{subfigure}{.47\textwidth}
		\centering
		\includegraphics[width=\linewidth]{appendix/graph-theory/grid-graph.png}
		\caption{}
		\label{fig:graph-v-n}
	\end{subfigure}
	\begin{subfigure}{.47\textwidth}
		\centering
		\includegraphics[width=\linewidth]{appendix/graph-theory/kings-graph.png}
		\caption{}
		\label{fig:graph-m}
	\end{subfigure}
	\caption{Graph representation of the 2D lattice with the von Neumann neighbourhood\ref{fig:graph-v-n} and the Moore neighbourhood \ref{fig:graph-m}}
	\label{fig:graph-neighbourhoods}
\end{figure}\\
\\
Typically to avoid boundary effects when playing games on these lattices we `wrap' the 2D lattice. This creates a torus. So each vertex displayed visually at the top of the lattice is joined to the neighbour in the same column at the bottom of the lattice. This avoids, for example, the side players having fewer opponents. However it makes it harder to visualise explicitly and so is normally drawn in two-dimensions with no visual representation of the wrapping.
\section{Games on networks}
%\subsubsection{Games on graphs we have already seen}
Having further built up our tool-kit, we can now consider games on graphs. We set each vertex to represent a player and only allow players to play a game against players they are adjacent to. In fact, we have sneakily been doing this the whole time but now we want to make this explicit.\\
\\
The basic Prisoner's Dilemma in \ref{subs:prisoners-dilemma} was a game on a trivial graph $G=(\{Lou,Avery\},\{(Lou,Avery)\})$, visualised in Fig. \ref{fig:p-d-graph}.
\begin{figure}[h]
	\centering
	\begin{tikzpicture}
	\draw
	(1,1) node[anchor=east,circle,draw]{Lou}--
	(3,1) node[anchor=west,circle,draw]{Avery};
	\end{tikzpicture}
	\caption{The trivial graph underlying the one-shot Prisoner's Dilemma}
	\label{fig:p-d-graph}
\end{figure}
Similarly, for the Iterated Prisoner's dilemma tournament if we call the players $p_1,...,p_n$, the tournament was a repeated game on a complete graph $K_n$.\\
\\
%\subsubsection{Some new Graphs}
So we were already playing games on graphs implicitly. Now we can try building games while noting the graphs we are playing on explicitly and seeing what effect this has.
\subsection{Prisoner's Dilemma on a torus}\label{p-d-torus}
%\subsubsection{Set-up}
We can extend the Iterated Prisoner's Dilemma to a tournament on a 2D lattice. Firstly, we make an $n \times n$ grid with wrapped ends to avoid boundary effects, creating a torus. Using the process seen in the previous section we make a graph out of this using the Moore neighbourhood. Then we let each vertex be a player of the Prisoner's Dilemma. They play against all other vertices in their neighbourhood\cite{eq_of_life}.\\
\\
To initialise the system, in the first round each player plays $C$ with probability $p$ and $D$ with probability $(1-p)$. They play this action simultaneously against every neighbour, using the same strategy against each of them.\\
\\
For every round after, each player looks at their neighbour's scores from the previous round. They adopt the action of the highest scoring neighbour as their action for the next round\footnote{For most parameter values chosen, ties are only possible between cells that use the same strategies and so this is well-defined. If there were to be a tie between two distinct strategies, the strategy adopted would arbitrarily be the strategy closest to the top left of the grid.}\label{mmd} They then play this action against every neighbour.\\
\\
The payoff matrix retains characteristics of the matrix originally given for the Prisoner's Dilemma and is given by:\\
\setlength{\extrarowheight}{2pt}
\begin{tabular}{cc|c|c|}
	& \multicolumn{1}{c}{} & \multicolumn{2}{c}{Avery}\\
	& \multicolumn{1}{c}{} & \multicolumn{1}{c}{$C$}  & \multicolumn{1}{c}{$D$} \\\cline{3-4}
	\multirow{2}*{Lou}  & $C$ & $(1,1)$ & $(\epsilon,b)$ \\\cline{3-4}
	& $D$ & $(b,\epsilon)$ & $(0,0)$ \\\cline{3-4}
\end{tabular}
\\
\\
where $\epsilon<1<b$.\\
\\
%\subsubsection{Example Runs}
To run this we simulate on a $100\times100$ grid and choose values $p=0.5$ and $\epsilon=0$. We can create a wide variety of dynamic behaviour, including chaos and bifurcations by adjusting the value of $b$. Note that $b$ is the payoff from defecting against a cooperative partner. Intuitively, it is the reward to true villains who defect against players who were hoping to cooperate.
\subsubsection{Qualitative analysis: equilibrium and chaos}
For $b>1.\bar{6}$, the board eventually tends to an equilibrium with mostly defectors (Fig. \ref{fig:p-d-torus-1.7}). Clearly the rewards of non-cooperation are too high to a sustain a more socially beneficial situation.
\begin{figure}
	\centering
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/1b=17.png}
		\caption{Early}
		\label{}
	\end{subfigure}%
%	\begin{subfigure}{.3\textwidth}
%		\centering
%		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/2b=17.png}
%		\caption{Developing}
%		\label{}
%	\end{subfigure}
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{/appendix/games-on-networks/pd-torus/3b=17.png}
		\caption{Equilibrium}
		\label{}
	\end{subfigure}
	\caption{The simulation running with $b=1.7$}
	\label{fig:p-d-torus-1.7}
\end{figure}
Conversely, for $b<1.6$, the simulation tends towards a static equilibrium of mainly cooperators (Fig. \ref{fig:p-d-torus-1.5}).
\begin{figure}
	\centering
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/1b=15.png}
		\caption{Early}
		\label{fig:dir}
	\end{subfigure}%
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/2b=15.png}
		\caption{Developing}
		\label{fig:loop}
	\end{subfigure}
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/3b=15.png}
		\caption{Equilibrium}
		\label{fig:undirected}
	\end{subfigure}
	\caption{The simulation running with $b=1.5$}
	\label{fig:p-d-torus-1.5}
\end{figure}
Between these two parameter regions, exists the third which exhibits the most interesting behaviour with chaotic dynamics between cooperation and defection (Fig. \ref{fig:p-d-torus-1.63}).
\begin{figure}
	\centering
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/1b=163.png}
		\caption{Early}
		\label{fig:dir}
	\end{subfigure}%
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/2b=163.png}
		\caption{Developing}
		\label{fig:loop}
	\end{subfigure}
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/3b=163.png}
		\caption{Dynamic equilibrium}
		\label{fig:undirected}
	\end{subfigure}
	\caption{The simulation running with $b=1.63$}
	\label{fig:p-d-torus-1.63}
\end{figure}
\subsubsection{Quantitative analysis: invasion}
The usual approach for understanding evolutionary games is to find the conditions under which one type can `invade' a population. An invasion is when a small group of one type can grow in a population of other types. To do this with our game we must analyse the situation from the level of individual squares.\\
\\
Firstly, we need to find the minimal area that we can isolate to study. A single cell plays against it's surrounding neighbours and so we must consider at least the $3\times3$ grid surrounding a cell. However, the cell then adopts the strategy of all of its best performing neighbours. So it must look at its neighbour's payoffs. But it's neighbours payoffs depend on the games \textit{they} have just played against \textit{their} neighbours. So, to know what strategy our single cell will adopt we have to consider the surrounding $5\times5$ grid\cite{eq_of_life}.\\
\\
We will call the small population of potential invaders the \textit{cluster} and the rest of the population the \textit{sea}. Then we call the cells that are in the sea touching the cluster the \textit{boundary}. The general strategy we have will be to look at the boundary separating the small cluster of invaders from the rest of the population. If the boundary cells have a neighbour in the cluster with a better tactic than their neighbours in the sea, they will change and the cluster will grow.\\
\\
Let's first consider the conditions under which defectors can invade cooperators. Imagine a single defector in a sea of cooperators (Fig. (\ref{fig:1-d-i})). After the first game, the defector gets a payoff of $8b$, the boundary cells all get $7$ while all members of the sea get $8$. So the boundary members look to see if $8b>8$. As the game specifies that $b>1$, this is always true and so regardless of the value of $b$ it grows to a $3\times3$ grid.
\begin{figure}
	\centering
	\begin{subfigure}{.49\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/1-defector-invasion.png}
		\caption{1 defector invasion}
		\label{fig:1-d-i}
	\end{subfigure}%
	\begin{subfigure}{.49\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/9-defector-invasion.png}
		\caption{9 defector invasion}
		\label{fig:9-d-i}
	\end{subfigure}
	\caption{Defector invasion}
	\label{}
\end{figure}\\
\\
So now we consider a $3\times3$ grid of defectors (Fig. (\ref{fig:9-d-i})). The sea cells always have a higher payoff ($8$) than the boundary (either $5,6$ or $7$). The highest scoring cell in the cluster is the edge cell with a payoff of $5b$. Every cell of the boundary is a neighbour to an edge cell. Hence each cell looks to see if $5b>8$. If it is, they change and the cluster grows. Otherwise, it stays the same or shrinks. So to have the possibility of defector invasion we need $b>8/5=1.\dot6$.\\
\\
Now we consider cooperator invasion. We firstly note that a single cooperator cannot invade a population due to the constraints on the payoff matrix (Fig. (\ref{fig:1-c-i})). The defectors can simply feed off the foolishness of the sole cooperator and it will die off. Hence a cooperator invasion must start with some cluster.
\begin{figure}
	\centering
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/1-cooperator-invasion.png}
		\caption{1 cooperator invasion}
		\label{fig:1-c-i}
	\end{subfigure}%
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/4-cooperator-invasion.png}
		\caption{4 cooperator invasion}
		\label{fig:4-c-i}
	\end{subfigure}
	\begin{subfigure}{.3\textwidth}
		\centering
		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-torus/9-cooperator-invasion.png}
		\caption{9 cooperator invasion}
		\label{fig:9-c-i}
	\end{subfigure}
	\caption{Cooperator invasions}
	\label{}
\end{figure}
\\
\\
Looking at a $2\times2$ cluster of cooperators (Fig. (\ref{fig:4-c-i})), it is easy to see that if $b>3/2$ the cluster will grow uniformly. Otherwise it will be immediately destroyed.\\
\\
With a $3\times3$ cluster of cooperators there are different possibilities for growth (Fig. (\ref{fig:9-c-i})). Cell $A$ looks at the payoff of cell $B$ which is $2b$ against the payoff of it's only cluster neighbour which has a payoff of $3$. So if $3>2b$ it will change. If this is the case $B$ and $C$ will also both change.\\
\\
However, if $b>3/2$ there is still the possibility of $B$ and $C$ changing whilst $A$ stays the same. The highest scoring neighbour of cells $B,C$ will be either $C$ with payoff $3b$ or the cluster cell with payoff $5$. So they look to see if $5>3b$. If so they will change and the cluster will grow. This will create a cross structure.
\begin{figure}[h]
	\centering
	\caption{The payoffs of cells around a $3\times3$ cluster of cooperators in a sea of defectors.}
	\label{fig:p-d-graph}
\end{figure}
To summarise defector clusters can grow if $b>8/5=1.6$ and cooperator clusters can grow if $1.\dot6=5/3>b$. So there are three distinct parameter regions
\begin{enumerate}
	\item $b<1.6$ Only cooperator clusters can grow
	\item $1.6<b<1.\dot6$ Both cooperator and defector clusters can grow\label{chaos}
	\item $1.\dot 6<b$ Only defector clusters can grow
\end{enumerate}
This analytical approach justifies the conclusions we drew qualitatively earlier. In particular, region \ref{chaos}., where both defectors and cooperators can grow, represents the chaotic region.
%\subsubsection{Prisoner's Dilemma on a Scale Free Graph}
%\subsubsection{On Different Networks}
%We can adapt this to a hexagonal lattice.
%\begin{figure}
%	\centering
%	\begin{subfigure}{.3\textwidth}
%		\centering
%		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-hexagon/0005.png}
%		\caption{}
%		\label{fig:dir}
%	\end{subfigure}%
%	\begin{subfigure}{.3\textwidth}
%		\centering
%		\includegraphics[width=.9\linewidth]{appendix/games-on-networks/pd-hexagon/0012.png}
%		\caption{}
%		\label{fig:loop}
%	\end{subfigure}
%	\caption{Running the evolutionary Prisoner's Dilemma on a hexagonal lattice}
%	\label{fig:p-d-torus-1.63}
%\end{figure}


\section{Conclusions from obstruction theory}
The main result of obstruction theory, as discussed in the previous section, is
the following.
\begin{theorem}[Obstruction theory]
    Let $(X,A)$ be a relative CW-complex, and $Y$ a simple space. The map
    $[X,Y]\to [A,Y]$ is:
    \begin{enumerate}
	\item is onto if $H^n(X,A;\pi_{n-1}(Y)) = 0$ for all $n\geq 2$.
	\item is one-to-one if $H^n(X,A;\pi_n(Y)) = 0$ for all $n\geq 1$.
    \end{enumerate}
\end{theorem}
\begin{remark}
    The first statement implies the second. Indeed, suppose we have two maps
    $g_0,g_1:X\to Y$ and a homotopy $h:g_0|_{A}\simeq g_0|_{A}$. Assume the
    first statement. Consider the relative CW-complex $(X\times I,A\times I\cup
    X\times\partial I)$. Because $(X,A)$ is a relative CW-complex, the map
    $A\hookrightarrow X$ is a cofibration; this implies that the map $A\times
    I\cup X\times\partial I\to X\times I$ is also a cofibration.
    \begin{align*}
	H^n(X\times I,A\times I\cup X\times\partial I;\pi)\simeq
	\widetilde{H}^n(X\times I/(A\times I\cup X\times\partial I);\pi) \\
	= H^n(\Sigma X/A;\pi)\simeq \widetilde{H}^{n-1}(X/A;\pi).
    \end{align*}
    %More precisely, if I have $X_{n-1}\to Y$, we get $\theta\in
    %Z^n(X,A;\pi_{n-1}(Y))$, constructed by looking at the attaching map
    %$f_\alpha$ of some $\alpha\in\Sigma_n$, to define $\theta(g)$ via
    %$\theta(g)(\alpha) = [g\circ f_\alpha]$. This captures the obstruction to
    %extending $g$ over $\alpha$. We found that $d\theta = 0$.
\end{remark}
We proved the following statement in the previous section.
\begin{prop}
    Suppose $g:X_{n-1}\to Y$ is a map from the $(n-1)$-skeleton of $X$ to $Y$.
    Then $g|_{X_{n-2}}$ extends to $X_n\to Y$ iff $[\theta(g)] = 0$ in
    $H^n(X,A;\pi_{n-1}(Y))$.
\end{prop}
An immediate consequence is the following.
\begin{theorem}[CW-approximation]
    Any space admits a weak equivalence from a CW-complex.
\end{theorem}
This tells us that studying CW-complexes is not very restrictive, if we work up
to weak equivalence.

It is easy to see that if $W$ is a CW-complex and $f:X\to Y$ is a weak
equivalence, then $[W,X]\xrightarrow{\simeq}[W,Y]$. We can now finally conclude
the result of Theorem \ref{weakhtpyequiv}:
\begin{corollary}
    Let $X$ and $Y$ be CW-complexes. Then a weak equivalence $f:X\to Y$ is a
    homotopy equivalence.
\end{corollary}
\subsection{Postnikov and Whitehead towers}
Let $X$ be path connected. There is a space $X_{\leq n}$, and a map $X\to
X_{\leq n}$ such that $\pi_i(X_{\geq n}) = 0$ for $i>n$, and
$\pi_i(X)\xrightarrow{\simeq}\pi_i(X_{\leq n})$ for $i\leq n$. This pair
$(X,X_{\leq n})$ is essentially unique up to homotopy; the space $X_{\leq n}$
is called the \emph{$n$th Postnikov section} of $X$. Since Postnikov sections
have ``simpler'' homotopy groups, we can try to understand $X$ by studying each
of its Postnikov sections individually, and then gluing all the data together.

Suppose $A$ is some abelian group. We saw, in the first part\todo{provide a
link} that there is a space $M(A,n)$ with homology given by:
\begin{equation*}
    \widetilde{H}_i(M(A,n)) = \begin{cases}
	A & i = n\\
	0 & i\neq n.
    \end{cases}
\end{equation*}
This space was constructed from a free resolution $0\to F_1\to F_0\to A\to 0$
of $A$. We can construct a map $\bigvee S^n\to \bigvee S^n$ which realizes the
first two maps; coning this off gets $M(A,n)$. By Hurewicz, we have:
\begin{equation*}
    \pi_i(M(A,n)) = \begin{cases}
	0 & i<n\\
	A & i = n\\
	?? & i>n
    \end{cases}
\end{equation*}
It follows that, when we look at the $n$th Postnikov section of $M(A,n)$, we
have:
\begin{equation*}
    \pi_i(M(A,n)_{\leq n}) = \begin{cases}
	A & i = n\\
	0 & i\neq n.
    \end{cases}
\end{equation*}
In some sense, therefore, this Postnikov section is a ``designer homotopy
type''. It deserves a special name: $M(A,n)_{\leq n}$ is called an
\emph{Eilenberg-MacLane space}, and is denoted $K(A,n)$. By the fiber sequence
$\Omega X\to PX\to X$ with $PX\simeq \ast$, we find that $\Omega K(\pi,n)\simeq
K(\pi,n-1)$. Eilenberg-MacLane spaces are unique up to homotopy.

Note that $n=1$, $A$ does not have to be abelian, but you can still construct
$K(A,1)$. This is called the \emph{classifying space} of $G$; such spaces will
be discussed in more detail in the next chapter. Examples are in abundance: if
$\Sigma$ is a closed surface that is not $S^2$ or $\RR^2$, then $\Sigma \simeq
K(\pi_1(\Sigma),1)$. Perhaps simpler is the identification $S^1\simeq K(\Z,1)$.

\begin{example}
    We can identify $K(\Z,2)$ as $\CP^\infty$. To see this, observe that we
    have a fiber sequence $S^1\to S^{2n+1}\to \CP^n$. The long exact sequence
    in homotopy tells us that the homotopy groups of $\CP^n$ are the same as
    the homotopy groups of $S^1$, until $\pi_\ast S^{2n+1}$ starts to
    interfere. As $n$ grows, we obtain a fibration $S^1\to S^\infty\to
    \CP^\infty$. Since $S^\infty$ is weakly contractible (it has no nonzero
    homotopy groups), we get the desired result.
\end{example}
\begin{example}
    Similarly, we can identify $K(\Z/2\Z,1)$ as $\RP^\infty$.
\end{example}

Since $\pi_1(K(A,n)) = 0$ for $n>1$, it follows that $K(A,n)$ is automatically
a simple space. This means that
$$[S^k,K(A,n)] = \pi_k(K(A,n)) = H^n(S^k,A).$$
In fact, a more general result is true:
\begin{theorem}[Brown representability]\label{brown-rep}
    If $X$ is a CW-complex, then $[X,K(A,n)] = H^n(X;A)$.
\end{theorem}
We will not prove this here, but one can show this simply by showing that the
functor $[-,K(A,n)]$ satisfies the Eilenberg-Steenrod axioms. Somehow, these
Eilenberg-MacLane spaces $K(A,n)$ completely capture cohomology in dimension
$n$.

If $X$ is a CW-complex, then we may assume that $X_{\leq n}$ is also a
CW-complex. (Otherwise, we can use cellular approximation and then kill
homotopy groups.) Let us assume that $X$ is path connected; then $X_{\leq 1} =
K(\pi_1(X),1)$. We may then form a (commuting) tower:
\begin{equation*}
    \xymatrix{
	& \vdots\ar[d] & \cdots\ar[l]\\
	& X_{\leq 3}\ar[d]& K(\pi_3(X),3)\ar[l]\\
	& X_{\leq 2}\ar[d]& K(\pi_2(X),2)\ar[l]\\
	X\ar[r]\ar[ur]\ar[uur]\ar[uuur]& X_{\leq 1}\ar@{=}[r] & K(\pi_1(X),1),
    }
\end{equation*}
since $K(\pi_n(X),n)\to X_{\leq n}\to X_{\leq n-1}$ is a fiber sequence.
This decomposition of $X$ is called the \emph{Postnikov tower} of $X$.

Denote by $X_{>n}$ the fiber of the map $X\to X_{\leq n}$ (for instance,
$X_{>1}$ is the universal cover of $X$); then, we have
\begin{equation*}
    \xymatrix{
	\cdots\ar[r]\ar[d] & \cdots\ar[r]\ar@{=}[d] & \vdots\ar[d] &
	\cdots\ar[l]\\
	X_{>3}\ar[r]\ar[d] & X\ar[r]\ar@{=}[d] & X_{\leq 3}\ar[d]&
	K(\pi_3(X),3)\ar[l]\\
	X_{>2}\ar[r]\ar[d] & X\ar[r]\ar@{=}[d] & X_{\leq 2}\ar[d]&
	K(\pi_2(X),2)\ar[l]\\
	X_{>1}\ar[r]\ar[d] & X\ar[r]\ar@{=}[d] & X_{\leq 1}\ar@{=}[r]\ar[d] &
	K(\pi_1(X),1)\\
	X\ar@{=}[r] & X\ar[r] & \ast
    }
\end{equation*}
The leftmost tower is called the \emph{Whitehead tower} of $X$, named after
George Whitehead.

I can take the fiber of $X_{>1}\to X$, and I get $K(\pi_1(X),0)$; more
generally, the fiber of $X_{>n} \to X_{>n-1}$ is $K(\pi_n(X),n-1)$. This yields
the following diagram:
\begin{equation*}
    \xymatrix{
	\cdots & \vdots\ar[d] & \vdots\ar@{=}[d] & \vdots\ar[d] & \cdots\\
	K(\pi_3(X),2)\ar[r] & X_{>3}\ar[r]\ar[d] & X\ar[r]\ar@{=}[d] & X_{\leq
	3}\ar[d]& K(\pi_3(X),3)\ar[l]\\
	K(\pi_2(X),1)\ar[r] & X_{>2}\ar[r]\ar[d] & X\ar[r]\ar@{=}[d] & X_{\leq
	2}\ar[d]& K(\pi_2(X),2)\ar[l]\\
	K(\pi_1(X),0)\ar[r] & X_{>1}\ar[r]\ar[d] & X\ar[r]\ar@{=}[d] & X_{\leq
	1}\ar@{=}[r]\ar[d] & K(\pi_1(X),1)\\
	& X\ar@{=}[r] & X\ar[r] & \ast
    }
\end{equation*}

We can construct Eilenberg-MacLane spaces as cellular complexes by attaching
cells to the sphere to kill its higher homotopy groups. The complexity of
homotopy groups, though, shows us that attaching cells to compute the
cohomology of Eilenberg-MacLane spaces is not feasible.
%These constructions go back to the 50's, and they had voluminous computations in low dimensions. One day in 1950, they got a postcard from Serre, who said, ``here's a computation you might be interested in: $H^{23}(K(\Z,14)) = ...$''. Of course, Serre and Cartan had a different approach, that was much more effective. They observed that the fact $\Omega K(\pi,n)\simeq K(\pi,n-1)$ wasn't perceived to be useful by Eilenberg and Maclane. They didn't think about fiber sequences. Serre and Cartan did this by means of a spectral sequence. We'll do that later in the course.


\chapter{Functors and natural transformations}
\label{ch:functors}
Functors are maps between categories; natural transformations are maps between functors.

\section{Many examples of functors}
\prototype{Forgetful functors; fundamental groups; $-^\vee$.}
Here's the point of a functor:
\begin{moral}
	Pretty much any time you make an object out of another object,
	you get a functor.
\end{moral}
Before I give you a formal definition, let me list (informally) some examples.
(You'll notice some of them have opposite categories $\AA\op$ appearing in places.
Don't worry about those for now; you'll see why in a moment.)
\begin{itemize}
	\ii Given a group $G$ (or vector space, field, \dots), we can take its underlying set $S$;
	this is a functor from $\catname{Grp} \to \catname{Set}$.
	\ii Given a set $S$ we can consider a vector space with basis $S$;
	this is a functor from $\catname{Set} \to \catname{Vect}$.

	\ii Given a vector space $V$ we can consider its dual space $V^\vee$.
	This is a functor $\catname{Vect}_k\op \to \catname{Vect}_k$.
	\ii Tensor products give a functor from $\catname{Vect}_k \times \catname{Vect}_k \to \catname{Vect}_k$.
	\ii Given a set $S$, we can build its power set, giving a functor $\catname{Set} \to \catname{Set}$.
	\ii In algebraic topology, we take a topological space $X$ and build several groups $H_1(X)$, $\pi_1(X)$,
	etc.\ associated to it. All these group constructions are functors $\catname{Top} \to \catname{Grp}$.
	\ii Sets of homomorphisms: let $\AA$ be a category.
	\begin{itemize}
		\ii Given two vector spaces $V_1$ and $V_2$ over $k$,
		we construct the abelian group of linear maps $V_1 \to V_2$.
		This is a functor from $\catname{Vect}_k\op \times \catname{Vect}_k \to \catname{AbGrp}$.
		\ii More generally for any category $\AA$
		we can take pairs $(A_1, A_2)$ of objects and
		obtain a set $\Hom_{\AA}(A_1, A_2)$.
		This turns out to be a functor $\AA\op \times \AA \to \catname{Set}$.
		\ii The above operation has two ``slots''.
		If we ``pre-fill'' the first slots, then we get a functor $\AA \to \catname{Set}$.
		That is, by fixing $A \in \AA$, we obtain a functor (called $H^A$)
		from $\AA \to \catname{Set}$ by sending $A' \in \AA$ to $\Hom_{\AA} (A, A')$.
		This is called the covariant Yoneda functor (explained later).
		\ii As we saw above,
		for every $A \in \AA$ we obtain a functor $H^A : \AA \to \catname{Set}$.
		It turns out we can construct a category $[\AA, \catname{Set}]$
		whose elements are functors $\AA \to \catname{Set}$;
		in that case, we now have a functor $\AA\op \to [\AA, \catname{Set}]$.
	\end{itemize}
\end{itemize}

\section{Covariant functors}
\prototype{Forgetful/free functors, \dots}
Category theorists are always asking ``what are the maps?'',
and so we can now think about maps between categories.

\begin{definition}
	Let $\AA$ and $\BB$ be categories.
	Of course, a \vocab{functor} $F$ takes every object of $\AA$ to an object of $\BB$.
	In addition, though, it must take every arrow $A_1 \taking{f} A_2$
	to an arrow $F(A_1) \taking{F(f)} F(A_2)$.
	You can picture this as follows.
	\begin{diagram}
		& A_1 & & B_1 & = F(A_1) & \\
		\AA \ni & \dTo^f & \rDotted^F & \dTo_{F(f)} && \in \BB \\
		& A_2 & & B_2 & = F(A_2) &
	\end{diagram}
	(I'll try to use dotted arrows for functors, which cross different categories, for emphasis.)
	It needs to satisfy the ``naturality'' requirements:
	\begin{itemize}
		\ii Identity arrows get sent to identity arrows:
		for each identity arrow $\id_A$, we have $F(\id_A) = \id_{F(A)}$.
		\ii The functor respects composition:
		if $A_1 \taking f A_2 \taking g A_3$ are arrows in $\AA$,
		then $F(g \circ f) = F(g) \circ F(f)$.
	\end{itemize}
\end{definition}

So the idea is:
\begin{moral}
Whenever we naturally make an object $A \in \AA$ into an object of $B \in \BB$,
there should usually be a natural way to transform a map $A_1 \to A_2$ into a map $B_1 \to B_2$.
\end{moral}
Let's see some examples of this.

\begin{example}
	[Free and forgetful functors]
	Note that these are both informal terms,
	and don't have a rigid definition.
	\begin{enumerate}[(a)]
		\ii We talked about a \vocab{forgetful functor} earlier,
		which takes the underlying set of a category like $\catname{Vect}_k$.
		Let's call it $U : \catname{Vect}_k \to \catname{Set}$.

		Now, given a map $T : V_1 \to V_2$ in $\catname{Vect}_k$,
		there is an obvious $U(T) : U(V_1) \to U(V_2)$ which is just
		the set-theoretic map corresponding to $T$.

		Similarly there are forgetful functors from
		$\catname{Grp}$, $\catname{CRing}$, etc., to $\catname{Set}$.
		There is even a forgetful functor $\catname{CRing} \to \catname{Grp}$:
		send a ring $R$ to the abelian group $(R,+)$.
		The common theme is that we are ``forgetting'' structure
		from the original category.

		\ii We also talked about a \vocab{free functor} in the example.
		A free functor $F : \catname{Set} \to \catname{Vect}_k$ can be taken by considering
		$F(S)$ to be the vector space with basis $S$.
		Now, given a map $f : S \to T$, what is the obvious map $F(S) \to F(T)$?
		Simple: take each basis element $s \in S$ to the basis element $f(s) \in T$.

		Similarly, we can define $F : \catname{Set} \to \catname{Grp}$
		by taking the free group generated by a set $S$.
	\end{enumerate}
\end{example}

\begin{remark}
	There is also a notion of ``injective'' and ``surjective''
	for functors (on arrows) as follows.
	A functor $F \colon \AA \to \BB$ is \vocab{faithful}
	(resp.\ \vocab{full}) if for any $A_1, A_2$,
	$F \colon \Hom_\AA(A_1, A_2) \to \Hom_\BB(FA_1, FA_2)$
	is injective (resp.\ surjective).\footnote{Again,
		experts might object that $\Hom_\AA(A_1, A_2)$
		or $\Hom_\BB(FA_1, FA_2)$ may be proper classes instead of sets,
		but I am assuming everything is locally small.}

	We can use this to give an exact definition of concrete category:
	it's a category with a faithful (forgetful) functor
	$U \colon \AA \to \catname{Set}$.
\end{remark}

\begin{example}
	[Functors from $\mathcal G$]
	Let $G$ be a group and $\mathcal G = \{\ast\}$ be the associated one-object category.
	\begin{enumerate}[(a)]
		\ii Consider a functor $F : \mathcal G \to \catname{Set}$, and let $S = F(\ast)$.
		Then the data of $F$ corresponds to putting a \emph{group action} of $G$ on $S$.
		\ii Consider a functor $F : \mathcal G \to \catname{FDVect}_k$, and let $V = F(\ast)$ have dimension $n$.
		Then the data of $F$ corresponds to embedding $G$ as a subgroup of the $n \times n$ matrices
		(i.e.\ the linear maps $V \to V$).
		This is one way groups historically arose; the theory of viewing groups as matrices
		forms the field of representation theory.
		\ii Let $H$ be a group and construct $\mathcal H$ the same way.
		Then functors $\mathcal G \to \mathcal H$ correspond to homomorphisms $G \to H$.
	\end{enumerate}
\end{example}
\begin{exercise}
	Check the above group-based functors work as advertised.
\end{exercise}

Here's a more involved example.
If you find it confusing,
skip it and come back after reading about its contravariant version.
\begin{example}
	[Covariant Yoneda functor]
	\label{ex:covariant_yoneda}
	Fix an $A \in \AA$.
	For a category $\AA$, define the
	\vocab{covariant Yoneda functor} $H^A \colon \AA \to \catname{Set}$
	by defining \[ H^A(A_1) \defeq \Hom_\AA (A, A_1) \in \catname{Set}. \]
	Hence each $A_1$ is sent to the \emph{arrows from $A$ to $A_1$};
	so \textbf{$H^A$ describes how $A$ sees the world}.

	Now we want to specify how $H^A$ behaves on arrows.
	For each arrow $A_1 \taking{f} A_2$, we need
	to specify $\catname{Set}$-map $\Hom_\AA (A, A_1) \to \Hom(A, A_2)$;
	in other words, we need to send an arrow $A \taking{p} A_1$ to an arrow $A \to A_2$.
	There's only one reasonable way to do this: take the composition
	\[ A \taking{p} A_1 \taking{f} A_2. \]
	In other words, $H_A(f)$ is $p \mapsto f \circ p$.
	In still other words, $H_A(f) = f \circ -$;
	the $-$ is a slot for the input to go into.
\end{example}

As another example:
\begin{ques}
	If $\mathcal P$ and $\mathcal Q$ are posets interpreted as categories,
	what does a functor from $\mathcal P$ to $\mathcal Q$ represent?
\end{ques}

Now, let me explain why we might care.
Consider the following ``obvious'' fact:
if $G$ and $H$ are isomorphic groups, then they have the same size.
We can formalize it by saying: if $G \cong H$ in $\catname{Grp}$
and $U \colon \catname{Grp} \to \catname{Set}$ is the forgetful functor
(mapping each group to its underlying set), then $U(G) \cong U(H)$.
The beauty of category theory shows itself:
this in fact works \emph{for any functors and categories},
and the proof is done solely through arrows:

\begin{theorem}
	[Functors preserve isomorphism]
	\label{thm:functor_isom}
	If $A_1 \cong A_2$ are isomorphic objects in $\AA$
	and $F : \AA \to \BB$ is a functor
	then $F(A_1) \cong F(A_2)$.
\end{theorem}
\begin{proof}
	Try it yourself! The picture is:
	\begin{diagram}
		& A_1 & & B_1 & = F(A_1) & \\
		\AA \ni & \dTo^f \uTo_g & \rDotted^F & \dTo^{F(f)} \uTo_{F(g)} && \in \BB \\
		& A_2 & & B_2 & = F(A_2) &
	\end{diagram}
	You'll need to use both key properties of functors:
	they preserve composition and the identity map.
\end{proof}

This will give us a great intuition in the future, because
\begin{enumerate}[(i)]
	\ii Almost every operation we do in our lifetime will be a functor, and
	\ii We now know that functors take isomorphic objects to isomorphic objects.
\end{enumerate}
Thus, we now automatically know that basically any ``reasonable'' operation
we do will preserve isomorphism (where ``reasonable'' means that it's a functor).
This is super convenient in algebraic topology, for example;
see \Cref{thm:fundgrp_functor}, where we get for free that homotopic
spaces have isomorphic fundamental groups.

\begin{remark}
	This lets us construct a category $\catname{Cat}$
	whose objects are categories and arrows are functors.
\end{remark}
% wef why is this here?
%While I'm here:
%\begin{ques}
%	Verify this works; figure out the identity and compositions.
%\end{ques}

\section{Contravariant functors}
\prototype{Dual spaces, contravariant Yoneda functor, etc.}

Now I have to explain what the opposite categories were doing earlier.
In all the previous examples, we took an arrow $A_1 \to A_2$,
and it became an arrow $F(A_1) \to F(A_2)$.
Sometimes, however, the arrow in fact goes the other way:
we get an arrow $F(A_2) \to F(A_1)$ instead.
In other words, instead of just getting a functor $\AA \to \BB$
we ended up with a functor $\AA\op \to \BB$.

These functors have a name:
\begin{definition}
	A \vocab{contravariant functor} from $\AA$ to $\BB$
	is a functor $F : \AA\op \to \BB$.
	(Note that we do \emph{not} write ``contravariant functor $F: \AA \to \BB$'',
	since that would be confusing; the function notation will always
	use the correct domain and codomain.)
\end{definition}
Pictorially:
\begin{diagram}
	& A_1 & & B_1 & = F(A_1) & \\
	\AA \ni & \dTo^f & \rDotted^F & \uTo_{F(f)} && \in \BB \\
	& A_2 & & B_2 & = F(A_2) &
\end{diagram}
For emphasis, a usual functor is often called a \vocab{covariant functor}.
(The word ``functor'' with no adjective always refers to covariant.)

Let's see why this might happen.
\begin{example}[$V \mapsto V^\vee$ is contravariant]
	Consider the functor $\catname{Vect}_k \to \catname{Vect}_k$ by $V \mapsto V^\vee$.

	If we were trying to specify a covariant functor,
	we would need, for every linear map $T : V_1 \to V_2$,
	a linear map $T^\vee : V_1^\vee \to V_2^\vee$.
	But recall that $V_1^\vee = \Hom(V_1, k)$ and $V_2^\vee = \Hom(V_2, k)$:
	there's no easy way to get an obvious map from left to right.

	However, there \emph{is} an obvious map from right to left:
	given $\xi_2 : V_2 \to k$, we can easily give a map from $V_1 \to k$:
	just compose with $T$!
	In other words, there is a very natural map $V_2^\vee \to V_1^\vee$
	according to the composition
	\begin{diagram}
		V_1 & \rTo^T & V_2 & \rTo^{\xi_2} & k
	\end{diagram}
	In summary, a map $T : V_1 \to V_2$ induces naturally a map
	$T^\vee : V_2^\vee \to V_1^\vee$ in the opposite direction.
	So the contravariant functor looks like:
	\begin{diagram}
		V_1 & & V_1^\vee \\
		\dTo^T & \rDotted^{-^\vee} & \uTo_{T^\vee} \\
		V_2 & & V_2^\vee
	\end{diagram}
\end{example}

%Contravariant functors come up in a lot in geometric applications.
%Here's why.
%If $X$ is a geometric object, we'll often consider
%the \emph{set of functions} $X \taking\psi A$ for some particular $A$.
%For example, if $V$ was a vector space, we could consider the functions $V \to k$,
%giving the dual module $V^\vee$.
%Or if $X$ was a space, we might consider the continuous
%real functions $X \taking{p} \RR$.
%As a non-geometric example: for a set $S$,
%a function $S \to \{x,y\}$ corresponds to a subset of $S$.

We can generalize the example above in any category by
replacing the field $k$ with any chosen object $A \in \AA$.

\begin{example}[Contravariant Yoneda functor]
	The \vocab{contravariant Yoneda functor} on $\AA$,
	denoted $H_A : \AA\op \to \catname{Set}$,
	is used to describe how objects of $\AA$ see $A$.
	For each $X \in \AA$ it puts \[ H_A(X) \defeq \Hom_{\AA}(X, A) \in \catname{Set}. \]
	For $X \taking{f} Y$ in $\AA$,
	the map $H_A(f)$ sends each arrow $Y \taking{p} A \in \Hom_\AA(Y,A)$ to
	\[ X \taking{f} Y \taking{p} A \quad \in \Hom_\AA(X,A) \]
	as we did above.
	Thus $H_A(f)$ is an arrow from $\Hom_\AA(Y,A) \to \Hom_\AA(X,A)$.
	(Note the flipping!)
\end{example}

\begin{exercise}
	Check now the claim that $\AA\op \times \AA \to \catname{Set}$
	by $(A_1, A_2) \mapsto \Hom(A_1, A_2)$ is in fact a functor.
\end{exercise}

\section{Equivalence of categories}
\todo{fully faithful and essentially surjective}

\section{(Optional) Natural transformations}
We made categories to keep track of objects and maps, then went a little crazy and asked
``what are the maps between categories?'' to get functors.
Now we'll ask ``what are the maps between functors?'' to get natural transformations.

It might sound terrifying that we're drawing arrows between functors, but this is actually an old idea.
Recall that given two paths $\alpha, \beta : [0,1] \to X$,
we built a path-homotopy by ``continuously deforming'' the path $\alpha$ to $\beta$;
this could be viewed as a function $[0,1] \times [0,1] \to X$.
The definition of a natural transformation is similar: we want to pull $F$ to $G$
along a series of arrows in the target space $\BB$.

\begin{definition}
	Let $F, G : \AA \to \BB$ be two functors.
	A \vocab{natural transformation} $\alpha$ from $F$ to $G$, denoted
	\[ \nattfm{\AA}{F}{\alpha}{G}{\BB} \]
	consists of, for each $A \in \AA$ an arrow $\alpha_A \in \Hom_\BB(F(A), G(A))$, which is
	called the \vocab{component} of $\alpha$ at $A$.
	Pictorially, it looks like this:
	\begin{diagram}
		& & & F(A) \in \BB \\
		\AA \ni & A & \ruDotted(2,1)^F & \dTo_{\alpha_A} \\
		& & \rdDotted(2,1)^G & G(A) \in \BB
	\end{diagram}
	These $\alpha_A$ are subject to the ``naturality'' requirement that for any $A_1 \taking{f} A_2$,
	the diagram
	\begin{diagram}
		F(A_1) & \rTo^{F(f)} & F(A_2) \\
		\dTo_{\alpha_{A_1}} & & \dTo_{\alpha_{A_2}} \\
		G(A_1) & \rTo_{G(f)} & G(A_2)
	\end{diagram}
	commutes.
\end{definition}
The arrow $\alpha_A$ represents the path that $F(A)$ takes to get to $G(A)$
(just as in a path-homotopy from $\alpha$ to $\beta$
each \emph{point} $\alpha(t)$ gets deformed to the \emph{point} $\beta(t)$ continuously).
A picture might help: consider
\begin{center}
	\begin{asy}
		size(14cm);
		dotfactor *= 1.4;

		path sparrow(pair X, pair Y) {
			// Short for "spaced arrow"
			return (0.9*X+0.1*Y)--(0.1*X+0.9*Y);
		}

		pair A1 = Drawing("A_1", dir(210), dir(225));
		pair A2 = Drawing("A_2", origin, dir(90));
		pair A3 = Drawing("A_3", dir(-30), dir(-45));
		path f = Drawing(sparrow(A2, A1), EndArrow);
		label("$f$", f, dir(90));
		path g = Drawing(sparrow(A2, A3), EndArrow);
		label("$g$", g, dir(90));
		label("$\mathcal A$", 0.6*(A1+A3));

		pen p = blue;
		transform FF = shift( (3.5, 0.7) );
		dot("$F(A_1)$", FF*A1, dir(225), p);
		dot("$F(A_2)$", FF*A2, dir(90), p);
		dot("$F(A_3)$", FF*A3, dir(-45), p);
		draw(FF*f, p, EndArrow);
		draw(FF*g, p, EndArrow);
		label("$F(f)$", FF*f, dir(110), p);
		label("$F(g)$", FF*g, dir(70), p);
		draw(FF*f, p+1.4);
		draw(FF*g, p+1.4);

		p = deepcyan;
		transform GG = shift( (3.5, -0.7) );
		dot("$G(A_1)$", GG*A1, dir(225), p);
		dot("$G(A_2)$", GG*A2, 3*dir(-90), p);
		dot("$G(A_3)$", GG*A3, dir(-45), p);
		label("$G(f)$", Drawing(GG*f, p, EndArrow), dir(110), p);
		label("$G(g)$", Drawing(GG*g, p, EndArrow), dir(70), p);
		draw(GG*f, p+1.4);
		draw(GG*g, p+1.4);

		p = lightred;
		label("$\alpha_{A_1}$", Drawing(sparrow(FF*A1, GG*A1), p, EndArrow), dir(180), p);
		label("$\alpha_{A_2}$", Drawing(sparrow(FF*A2, GG*A2), p, EndArrow), dir(180), p);
		label("$\alpha_{A_3}$", Drawing(sparrow(FF*A3, GG*A3), p, EndArrow), dir(0), p);

		p = magenta + dotted + 0.7;
		path Fa = (0.5,0)--FF*(-1,-0.2);
		path Ga = (0.5,-0.6)--GG*(-1,-0.4);
		label("$F$", Drawing(Fa, p, EndArrow), dir(135), p);
		label("$G$", Drawing(Ga, p, EndArrow), dir(225), p);

		p = lightred + 0.7;
		label("$\alpha$", Drawing(sparrow(midpoint(Fa), midpoint(Ga)), p, EndArrow), dir(180), p);

		p = grey + dashed;
		pair B1 = Drawing(midpoint(FF*A2--GG*A1), p);
		pair B2 = Drawing(0.6 * (FF*A3) + 0.4 * (GG*A2), p);
		draw(sparrow(FF*A1, B1), p, EndArrow);
		draw(sparrow(GG*A2, B1), p, EndArrow);
		draw(sparrow(FF*A3, B2), p, EndArrow);
		pair B3 = Drawing(FF*A3 + 0.7*dir(100), p);
		draw(sparrow(B3, FF*A3), p, EndArrow);
		label("$\mathcal B$", GG*(0.6*(A1+A3)));
		draw(sparrow(FF*A2, GG*A3), p, EndArrow);
		pair B4 = Drawing(FF*A1 + 0.5*dir(90), p);
		draw(sparrow(FF*A1, B4), p, EndArrow);
	\end{asy}
\end{center}
Here $\AA$ is the small category with three elements and two non-identity arrows $f$, $g$
(I've omitted the identity arrows for simplicity).
The images of $\AA$ under $F$ and $G$ are the blue and green ``subcategories'' of $\BB$.
Note that $\BB$ could potentially have many more objects and arrows in it (grey).
The natural transformation $\alpha$ (red) selects an arrow of $\BB$ from each $F(A)$
to the corresponding $G(A)$, dragging the entire image of $F$ to the image of $G$.
Finally, we require that any diagram formed by the blue, red, and green arrows is commutative (naturality),
so the natural transformation is really ``natural''.

There is a second equivalent definition that looks much more like the homotopy.
\begin{definition}
	Let $\mathbf 2$ denote the category generated by a poset with two elements $0 \le 1$, that is,
	\begin{center}
	\begin{tikzpicture}[scale=2]
		\SetVertexMath
		\Vertices{circle}{1,0}
		\Edge[style={->}, label={$0 \le 1$}](0)(1)
		\Loop[dist=12, dir=NO, label={$\id_0$}, labelstyle={above=1pt}](0)
		\Loop[dist=12, dir=NO, label={$\id_1$}, labelstyle={above=1pt}](1)
	\end{tikzpicture}
	\end{center}
	Then a \emph{natural transformation}
	$ \nattfm{\AA}{F}{\alpha}{G}{\BB} $
	is just a functor $\alpha : \AA \times \mathbf 2 \to \BB$ satisfying
	\[ \alpha(A,0) = F(A), \;\; \alpha(f,0) = F(f)
		\quad\text{and}\quad
		\alpha(A,1) = G(A), \;\; \alpha(f,1) = G(f). \]
	More succinctly, $\alpha(-,0) = F$, $\alpha(-,1) = G$.
\end{definition}
The proof that these are equivalent is left as a practice problem.

Naturally, two natural transformations $\alpha : F \to G$ and $\beta : G \to H$ can get composed.
\begin{diagram}
	& & F(A) \\
	& \ruDotted^F & \dTo_{\alpha_A} \\
	\AA \ni A & \rDotted^G & G(A) \\
	& \rdDotted_H & \dTo_{\beta_A} \\
	&& H(A)
\end{diagram}

Now suppose $\alpha$ is a natural transformation such that $\alpha_A$ is an isomorphism for each $A$.
In this way, we can construct an inverse arrow $\beta_A$ to it.
\begin{diagram}
	& & F(A) \in \BB \\
	\AA \ni A & \ruDotted(2,1)^F & \dTo^{\alpha_A} \uTo_{\beta_A} \\
	& \rdDotted(2,1)^G & G(A) \in \BB
\end{diagram}
In this case, we say $\alpha$ is a \vocab{natural isomorphism}.
We can then say that $F(A) \cong G(A)$ \vocab{naturally} in $A$.
(And $\beta$ is an isomorphism too!)
This means that the functors $F$ and $G$ are ``really the same'':
not only are they isomorphic on the level of objects,
but these isomorphisms are ``natural''.
As a result of this, we also write $F \cong G$ to mean
that the functors are naturally isomorphic.

This is what it really means when we say that
``there is a natural / canonical isomorphism''.
For example, I claimed earlier (in \Cref{prob:double_dual})
that there was a canonical isomorphism $(V^\vee)^\vee \cong V$,
and mumbled something about ``not having to pick a basis'' and ``God-given''.
Category theory, amazingly, lets us formalize this:
it just says that $(V^\vee)^\vee \cong \id(V)$ naturally in $V \in \catname{FDVect}_k$.
Really, we have a natural transformation
\[ \nattfm{\catname{FDVect}_k}{\id}{\eps}{(-^\vee)^\vee}{\catname{FDVect}_k}. \]
where the component $\eps_V$ is given by $v \mapsto \opname{ev}_v$
(as discussed earlier,
the fact that it is an isomorphism follows from the fact that $V$ and $(V^\vee)^\vee$
have equal dimensions and $\eps_V$ is injective).

\section{(Optional) The Yoneda lemma}
Now that I have natural transformations, I can define:
\begin{definition}
	The \vocab{functor category} of two categories $\AA$ and $\BB$,
	denoted $[\AA, \BB]$, is defined as follows:
	\begin{itemize}
		\ii The objects of $[\AA, \BB]$ are (covariant) functors $F : \AA \to \BB$, and
		\ii The morphisms are natural transformations $\alpha : F \to G$.
	\end{itemize}
\end{definition}
\begin{ques}
	When are two objects in the functor category isomorphic?
\end{ques}

With this, I can make good on the last example I mentioned at the beginning:
\begin{exercise}
	Construct the following functors:
	\begin{itemize}
		\ii $\AA \to [\AA\op, \catname{Set}]$ by $A \mapsto H_A$, which we call $H_\bullet$.
		\ii $\AA\op \to [\AA, \catname{Set}]$ by $A \mapsto H^A$, which we call $H^\bullet$.
	\end{itemize}
\end{exercise}
Notice that we have opposite categories either way; even if you like $H^A$ because it is covariant,
the map $H^\bullet$ is contravariant.
So for what follows, we'll prefer to use $H_\bullet$.

The main observation now is that given a category $\AA$, $H_\bullet$ provides some \emph{special}
functors $\AA\op \to \catname{Set}$ which are already ``built'' in to the category $A$.
In light of this, we define:
\begin{definition}
	A \vocab{presheaf} $X$ is just a contravariant functor $\AA\op \to \catname{Set}$.
	It is called \vocab{representable} if $X \cong H_A$ for some $A$.
\end{definition}
In other words, when we think about representable, the question we're asking is:
\begin{quote}
	\itshape
	What kind of presheaves are already ``built in'' to the category $\AA$?
\end{quote}
One way to get at this question is: given a presheaf $X$ and a particular $H_A$,
we can look at the \emph{set} of natural transformations $\alpha : X \implies H_A$,
and see if we can learn anything about it.
In fact, this set can be written explicitly:

\begin{theorem}
	[Yoneda lemma]
	\label{thm:yoneda}
	Let $\AA$ be a category,
	pick $A \in \AA$, and let $H_A$ be the contravariant Yoneda functor.
	Let $X : \AA\op \to \catname{Set}$ be a contravariant functor.
	Then the map
	\[ \left\{ \text{Natural transformations }
		\nattfm{\AA\op}{H_A}{\alpha}{X}{\catname{Set}} \right\}
		\to X(A) \]
	defined by $\alpha \mapsto \alpha_A(\id_A) \in X(A)$
	is an isomorphism of $\catname{Set}$ (i.e.\ a bijection).
	Moreover, if we view both sides of the equality as functors
	\[ \AA\op \times [\AA\op, \catname{Set}] \to \catname{Set} \]
	then this isomorphism is natural.
\end{theorem}

This might be startling at first sight.
Here's an unsatisfying explanation why this might not be too crazy:
in category theory, a rule of thumb is that ``two objects of the same type
that are built naturally are probably the same''.
You can see this theme when we defined functors and natural transformations,
and even just compositions.
Now to look at the set of natural transformations, we took a pair of elements $A \in \AA$
and $X \in [\AA\op, \catname{Set}]$
and constructed a \emph{set} of natural transformations.
Is there another way we can get a set from these two pieces of information?
Yes: just look at $X(A)$.
The Yoneda lemma is telling us that our heuristic still holds true here.

Some consequences of the Yoneda lemma are recorded in \cite{ref:msci}.
Since this chapter is already a bit too long, I'll just write down the statements,
and refer you to \cite{ref:msci} for the proofs.

\begin{enumerate}
	\ii As we mentioned before, $H^\bullet$ provides a functor
	\[ \AA \to [\AA\op, \catname{Set}]. \]
	It turns out this functor is in fact \emph{fully faithful};
	it quite literally embeds the category $\AA$ into the functor category on the right
	(much like Cayley's theorem embeds every group into a permutation group).

	\ii If $X, Y \in \AA$ then
	\[ H_X \cong H_Y \iff X \cong Y \iff H^X \cong H^Y. \]
	To see why this is expected, consider $\AA = \catname{Grp}$ for concreteness.
	Suppose $A$, $X$, $Y$ are groups such that $H_X(A) \cong H_Y(A)$ for all $A$.
	For example,
	\begin{itemize}
		\ii If $A = \ZZ$, then $\left\lvert X \right\rvert = \left\lvert Y \right\rvert$.
		\ii If $A = \ZZ / 2\ZZ$, then $X$ and $Y$ have the same number of elements of order $2$.
		\ii \dots
	\end{itemize}
	Each $A$ gives us some information on how $X$ and $Y$ are similar,
	but the whole natural isomorphism is strong enough to imply $X \cong Y$.

	\ii Consider the functor $U : \catname{Grp} \to \catname{Set}$.
	It can be represented by $H^\ZZ$, in the sense that
	\[ \Hom_{\catname{Grp}}(\ZZ, G) \cong U(G)
		\qquad\text{ by }\qquad \phi \mapsto \phi(1). \]
	That is, elements of $G$ are in bijection with maps $\ZZ \to G$,
	determined by the image of $+1$ (or $-1$ if you prefer).
	So a representation of $U$ was determined by looking at $\ZZ$ and picking $+1 \in U(\ZZ)$.

	The generalization of this is a follows: let $\AA$ be a category
	and $X : \AA \to \catname{Set}$ a covariant functor.
	Then a representation $H^A \cong X$ consists of an object $A \in \AA$ and
	an element $u \in X(A)$ satisfying a certain condition.
	You can read this off the condition\footnote{%
		Just for completeness, the condition is:
		For all $A' \in \AA$ and $x \in X(A')$, there's a unique $f : A \to A'$ with $(Xf)(u) = x$.
	} if you know what the inverse map is in \Cref{thm:yoneda}.
	In the above situation, $X = U$, $A = \ZZ$ and $u = \pm 1$.
\end{enumerate}

\section\problemhead

\begin{problem}
	Show that the two definitions of natural transformation
	(one in terms of $\AA \times \mathbf 2 \to \BB$
	and one in terms of arrows $F(A) \taking{\alpha_A} G(A)$)
	are equivalent.
	\begin{hint}
		The category $\AA \times \mathbf 2$ has ``redundant arrows''.
	\end{hint}
	\begin{sol}
		The main observation is that in $\AA \times \mathbf 2$,
		you have the arrows in $\AA$ (of the form $(f, \id_{\mathbf 2})$),
		and then the arrows crossing the two copies of $\AA$ (of the form $(\id_A, 0 \le 1)$).
		But there are some more arrows $(f, 0 \le 1)$: nonetheless, they can be thought of as compositions
		\[ (f, 0 \le 1) = (f, \id_{\mathbf 2}) \circ (\id_A, 0 \le 1) = (\id_A, 0 \le 1) \circ (f, \id_{\mathbf 2}). \]
		Now we want to specify a functor $\alpha : \AA \times \mathbf 2$, we only have to specify
		where each of these two more basic things goes.
		The conditions on $\alpha$ already tells us that $(f, \id_{\mathbf 2})$ should be mapped to $F(f)$ or $G(f)$
		(depending on whether the arrow above is in $\AA \times \{0\}$ or $\AA \times \{1\}$),
		and specifying the arrow $(\id_A, 0 \le 1)$ amounts to specifying the $A$th component.
		Where does naturality come in?

		The above discussion transfers to products of categories in general:
		you really only have to think about $(f, \id)$ and $(\id, g)$ arrows
		to get the general arrow $(f,g) = (f, \id) \circ (\id, g) = (\id, g) \circ (f, \id)$.
	\end{sol}
\end{problem}

\begin{problem}
	Let $\AA$ be the category of finite sets whose arrows are bijections between sets.
	For $A \in \AA$,
		let $F(A)$ be the set of \emph{permutations} of $A$ and
		let $G(A)$ be the set of \emph{orderings} on $A$.\footnote{
			A permutation is a bijection $A \to A$,
			and an ordering is a bijection $\{1, \dots, n\} \to A$,
			where $n$ is the size of $A$.}
	\begin{enumerate}[(a)]
		\ii Extend $F$ and $G$ to functors $\AA \to \catname{Set}$.
		\ii Show that $F(A) \cong G(A)$ for every $A$, but this isomorphism is \emph{not} natural.
	\end{enumerate}
\end{problem}

\begin{problem}
	[Proving the Yoneda lemma]
	In the context of \Cref{thm:yoneda}:
	\begin{enumerate}[(a)]
	\ii Prove that the map described is in fact a bijection.
	(To do this, you will probably have to explicitly write down the inverse map.)

	\ii \yod Prove that the bijection is indeed natural.
	(This is long-winded, but not difficult; from start to finish,
	there is only one thing you can possibly do.)
	\end{enumerate}
\end{problem}

%	The bijection is defined as follows:
%	\begin{itemize}
%		\ii For $\alpha$ on the right-hand side, we take the element $\alpha_A(\id_A) \in X(A)$.
%		\ii For $x \in X(A)$, its image in the right-hand side is the $\alpha$
%		with $\alpha_{A'} : H_A(A') \to X(A')$ by $(A' \taking f A) \mapsto (Xf)(x)$.
%	\end{itemize}


\chapter{IMO Shortlist Algebra Problems A1-3 from year 1998-2017}

\newpage\section{A1}

\prob{}{}{}{Let $a_{1},a_{2},\ldots ,a_{n}$ be positive real numbers such that $a_{1}+a_{2}+\cdots +a_{n}<1$. Prove that

\[ \frac{a_{1} a_{2} \cdots a_{n} \left[ 1 - (a_{1} + a_{2} + \cdots + a_{n}) \right] }{(a_{1} + a_{2} + \cdots + a_{n})( 1 - a_{1})(1 - a_{2}) \cdots (1 - a_{n})} \leq \frac{1}{ n^{n+1}}. \]}

\prob{}{}{}{Let $n \geq 2$ be a fixed integer. Find the least constant $C$ such the inequality

\[\sum_{i<j} x_{i}x_{j} \left(x^{2}_{i}+x^{2}_{j} \right) \leq C \left(\sum_{i}x_{i} \right)^4\]

holds for any $x_{1}, \ldots ,x_{n} \geq 0$ (the sum on the left consists of $\binom{n}{2}$ summands). For this constant $C$, characterize the instances of equality.}

\prob{}{}{}{Let $ a, b, c$ be positive real numbers so that $ abc = 1$. Prove that
\[ \left( a - 1 + \frac 1b \right) \left( b - 1 + \frac 1c \right) \left( c - 1 + \frac 1a \right) \leq 1. \]}

\prob{}{}{}{Let $ T$ denote the set of all ordered triples $ (p,q,r)$ of nonnegative integers. Find all functions $ f: T \rightarrow \mathbb{R}$ satisfying
\[ f(p,q,r) = \begin{cases} 0 & \text{if} \; pqr = 0, \\ 1 + \frac{1}{6}\{f(p + 1,q - 1,r) + f(p - 1,q + 1,r) & \\ + f(p - 1,q,r + 1) + f(p + 1,q,r - 1) & \\ + f(p,q + 1,r - 1) + f(p,q - 1,r + 1)\} & \text{otherwise} \end{cases} \]
for all nonnegative integers $ p$, $ q$, $ r$.}

\prob{}{}{}{Find all functions $f$ from the reals to the reals such that

\[f\left(f(x)+y\right)=2x+f\left(f(y)-x\right)\]

for all real $x,y$.}

\prob{}{}{}{Let $a_{ij}$ $i=1,2,3$; $j=1,2,3$ be real numbers such that $a_{ij}$ is positive for $i=j$ and negative for $i\neq j$.

Prove the existence of positive real numbers $c_{1}$, $c_{2}$, $c_{3}$ such that the numbers \[a_{11}c_{1}+a_{12}c_{2}+a_{13}c_{3},\qquad a_{21}c_{1}+a_{22}c_{2}+a_{23}c_{3},\qquad a_{31}c_{1}+a_{32}c_{2}+a_{33}c_{3}\]are either all negative, all positive, or all zero.}

\prob{}{}{}{Let $n \geq 3$ be an integer. Let $t_1$, $t_2$, ..., $t_n$ be positive real numbers such that \[n^2 + 1 > \left( t_1 + t_2 + \cdots + t_n \right) \left( \frac{1}{t_1} + \frac{1}{t_2} + \cdots + \frac{1}{t_n} \right).\] Show that $t_i$, $t_j$, $t_k$ are side lengths of a triangle for all $i$, $j$, $k$ with $1 \leq i < j < k \leq n$.}

\prob{}{}{}{Find all pairs of integers $a,b$ for which there exists a polynomial $P(x) \in \mathbb{Z}[X]$ such that product $(x^2+ax+b)\cdot P(x)$ is a polynomial of a form \[ x^n+c_{n-1}x^{n-1}+\cdots+c_1x+c_0 \]}

\prob{}{}{}{A sequence of real numbers $ a_{0},\ a_{1},\ a_{2},\dots$ is defined by the formula
\[ a_{i + 1} = \left\lfloor a_{i}\right\rfloor\cdot \left\langle a_{i}\right\rangle\qquad\text{for}\quad i\geq 0; \]here $a_0$ is an arbitrary real number, $\lfloor a_i\rfloor$ denotes the greatest integer not exceeding $a_i$, and $\left\langle a_i\right\rangle=a_i-\lfloor a_i\rfloor$. Prove that $a_i=a_{i+2}$ for $i$ sufficiently large.}

\prob{}{}{}{Real numbers $ a_{1}$, $ a_{2}$, $ \ldots$, $ a_{n}$ are given. For each $ i$, $ (1 \leq i \leq n )$, define
\[ d_{i} = \max \{ a_{j}\mid 1 \leq j \leq i \} - \min \{ a_{j}\mid i \leq j \leq n \} \]
and let $ d = \max \{d_{i}\mid 1 \leq i \leq n \}$.

(a) Prove that, for any real numbers $ x_{1}\leq x_{2}\leq \cdots \leq x_{n}$,
\[ \max \{ |x_{i} - a_{i}| \mid 1 \leq i \leq n \}\geq \frac {d}{2}. \quad \quad (*) \]
(b) Show that there are real numbers $ x_{1}\leq x_{2}\leq \cdots \leq x_{n}$ such that the equality holds in (*).}

\prob{}{}{}{Find all functions $ f: (0, \infty) \mapsto (0, \infty)$ (so $ f$ is a function from the positive real numbers) such that
\[ \frac {\left( f(w) \right)^2 + \left( f(x) \right)^2}{f(y^2) + f(z^2) } = \frac {w^2 + x^2}{y^2 + z^2} \]
for all positive real numbers $ w,x,y,z,$ satisfying $ wx = yz.$}

\prob{}{}{}{Find the largest possible integer $k$, such that the following statement is true:
Let $2009$ arbitrary non-degenerated triangles be given. In every triangle the three sides are coloured, such that one is blue, one is red and one is white. Now, for every colour separately, let us sort the lengths of the sides. We obtain
\[ \left. \begin{array}{rcl} & b_1 \leq b_2\leq\ldots\leq b_{2009} & \textrm{the lengths of the blue sides }\\ & r_1 \leq r_2\leq\ldots\leq r_{2009} & \textrm{the lengths of the red sides }\\ \textrm{and } & w_1 \leq w_2\leq\ldots\leq w_{2009} & \textrm{the lengths of the white sides }\\ \end{array}\right.\]
Then there exist $k$ indices $j$ such that we can form a non-degenerated triangle with side lengths $b_j$, $r_j$, $w_j$.}

\prob{}{}{}{Find all function $f:\mathbb{R}\rightarrow\mathbb{R}$ such that for all $x,y\in\mathbb{R}$ the following equality holds \[ f(\left\lfloor x\right\rfloor y)=f(x)\left\lfloor f(y)\right\rfloor \] where $\left\lfloor a\right\rfloor $ is greatest integer not greater than $a.$}

\prob{}{}{}{Given any set $A = \{a_1, a_2, a_3, a_4\}$ of four distinct positive integers, we denote the sum $a_1 +a_2 +a_3 +a_4$ by $s_A$. Let $n_A$ denote the number of pairs $(i, j)$ with $1 \leq i < j \leq 4$ for which $a_i +a_j$ divides $s_A$. Find all sets $A$ of four distinct positive integers which achieve the largest possible value of $n_A$.}

\prob{}{}{}{Find all functions $f:\mathbb Z\rightarrow \mathbb Z$ such that, for all integers $a,b,c$ that satisfy $a+b+c=0$, the following equality holds:
\[f(a)^2+f(b)^2+f(c)^2=2f(a)f(b)+2f(b)f(c)+2f(c)f(a).\]
(Here $\mathbb{Z}$ denotes the set of integers.)}

\prob{}{}{}{Let $n$ be a positive integer and let $a_1, \ldots, a_{n-1} $ be arbitrary real numbers. Define the sequences $u_0, \ldots, u_n $ and $v_0, \ldots, v_n $ inductively by $u_0 = u_1 = v_0 = v_1 = 1$, and $u_{k+1} = u_k + a_k u_{k-1}$, $v_{k+1} = v_k + a_{n-k} v_{k-1}$ for $k=1, \ldots, n-1.$

Prove that $u_n = v_n.$}

\prob{}{}{}{Let $a_0 < a_1 < a_2 \ldots$ be an infinite sequence of positive integers. Prove that there exists a unique integer $n\geq 1$ such that
\[a_n < \frac{a_0+a_1+a_2+\cdots+a_n}{n} \leq a_{n+1}.\]}

\prob{}{}{}{Suppose that a sequence $a_1,a_2,\ldots$ of positive real numbers satisfies \[a_{k+1}\geq\frac{ka_k}{a_k^2+(k-1)}\]for every positive integer $k$. Prove that $a_1+a_2+\ldots+a_n\geq n$ for every $n\geq2$.}

\prob{}{}{}{Let $a$, $b$, $c$ be positive real numbers such that $\min(ab,bc,ca) \ge 1$. Prove that $$\sqrt[3]{(a^2+1)(b^2+1)(c^2+1)} \le \left(\frac{a+b+c}{3}\right)^2 + 1.$$}

\prob{}{}{}{Let $a_1,a_2,\ldots a_n,k$, and $M$ be positive integers such that
$$\frac{1}{a_1}+\frac{1}{a_2}+\cdots+\frac{1}{a_n}=k\quad\text{and}\quad a_1a_2\cdots a_n=M.$$If $M>1$, prove that the polynomial
$$P(x)=M(x+1)^k-(x+a_1)(x+a_2)\cdots (x+a_n)$$has no positive roots.}

\newpage\section{A2}

\prob{}{}{}{Let $r_{1},r_{2},\ldots ,r_{n}$ be real numbers greater than or equal to 1. Prove that

\[ \frac{1}{r_{1} + 1} + \frac{1}{r_{2} + 1} + \cdots +\frac{1}{r_{n}+1} \geq \frac{n}{ \sqrt[n]{r_{1}r_{2} \cdots r_{n}}+1}. \]
}
\prob{}{}{}{The numbers from 1 to $n^2$ are randomly arranged in the cells of a $n \times n$ square ($n \geq 2$). For any pair of numbers situated on the same row or on the same column the ratio of the greater number to the smaller number is calculated. Let us call the characteristic of the arrangement the smallest of these $n^2\left(n-1\right)$ fractions. What is the highest possible value of the characteristic ?
}

\prob{}{}{}{Let $ a, b, c$ be positive integers satisfying the conditions $ b > 2a$ and $ c > 2b.$ Show that there exists a real number $ \lambda$ with the property that all the three numbers $ \lambda a, \lambda b, \lambda c$ have their fractional parts lying in the interval $ \left(\frac {1}{3}, \frac {2}{3} \right].$

}
\prob{}{}{}{Let $a_0, a_1, a_2, \ldots$ be an arbitrary infinite sequence of positive numbers. Show that the inequality $1 + a_n > a_{n-1} \sqrt[n]{2}$ holds for infinitely many positive integers $n$.
}

\prob{}{}{}{Let $a_1,a_2,\ldots$ be an infinite sequence of real numbers, for which there exists a real number $c$ with $0\leq a_i\leq c$ for all $i$, such that \[\left\lvert a_i-a_j \right\rvert\geq \frac{1}{i+j} \quad \text{for all }i,\ j \text{ with } i \neq j. \] Prove that $c\geq1$.
}

\prob{}{}{}{Find all nondecreasing functions $f: \mathbb{R}\rightarrow\mathbb{R}$ such that
(i) $f(0) = 0, f(1) = 1;$
(ii) $f(a) + f(b) = f(a)f(b) + f(a + b - ab)$ for all real numbers $a, b$ such that $a < 1 < b$.
}

\prob{}{}{}{Let $a_0$, $a_1$, $a_2$, ... be an infinite sequence of real numbers satisfying the equation $a_n=\left|a_{n+1}-a_{n+2}\right|$ for all $n\geq 0$, where $a_0$ and $a_1$ are two different positive reals.

Can this sequence $a_0$, $a_1$, $a_2$, ... be bounded?
}

\prob{}{}{}{We denote by $\mathbb{R}^+$ the set of all positive real numbers.

Find all functions $f: \mathbb R^ + \rightarrow\mathbb R^ +$ which have the property:
\[f(x)f(y)=2f(x+yf(x))\]
for all positive real numbers $x$ and $y$.

}

\prob{}{}{}{The sequence of real numbers $a_0,a_1,a_2,\ldots$ is defined recursively by \[a_0=-1,\qquad\sum_{k=0}^n\dfrac{a_{n-k}}{k+1}=0\quad\text{for}\quad n\geq 1.\]Show that $ a_{n} > 0$ for all $ n\geq 1$.
}

\prob{}{}{}{Consider those functions $ f: \mathbb{N} \mapsto \mathbb{N}$ which satisfy the condition
\[ f(m + n) \geq f(m) + f(f(n)) - 1 \]
for all $ m,n \in \mathbb{N}.$ Find all possible values of $ f(2007).$
}

\prob{}{}{}{(a) Prove that
\[\frac {x^{2}}{\left(x - 1\right)^{2}} + \frac {y^{2}}{\left(y - 1\right)^{2}} + \frac {z^{2}}{\left(z - 1\right)^{2}} \geq 1\] for all real numbers $x$, $y$, $z$, each different from $1$, and satisfying $xyz=1$.

(b) Prove that equality holds above for infinitely many triples of rational numbers $x$, $y$, $z$, each different from $1$, and satisfying $xyz=1$.
}

\prob{}{}{}{Let $a$, $b$, $c$ be positive real numbers such that $\dfrac{1}{a} + \dfrac{1}{b} + \dfrac{1}{c} = a+b+c$. Prove that:
\[\frac{1}{(2a+b+c)^2}+\frac{1}{(a+2b+c)^2}+\frac{1}{(a+b+2c)^2}\leq \frac{3}{16}.\]
}

\prob{}{}{}{Let the real numbers $a,b,c,d$ satisfy the relations $a+b+c+d=6$ and $a^2+b^2+c^2+d^2=12.$ Prove that
\[36 \leq 4 \left(a^3+b^3+c^3+d^3\right) - \left(a^4+b^4+c^4+d^4 \right) \leq 48.\]
}

\prob{}{}{}{Determine all sequences $(x_1,x_2,\ldots,x_{2011})$ of positive integers, such that for every positive integer $n$ there exists an integer $a$ with \[\sum^{2011}_{j=1} j x^n_j = a^{n+1} + 1\]
}

\prob{}{}{}{Let $\mathbb{Z}$ and $\mathbb{Q}$ be the sets of integers and rationals respectively.
a) Does there exist a partition of $\mathbb{Z}$ into three non-empty subsets $A,B,C$ such that the sets $A+B, B+C, C+A$ are disjoint?
b) Does there exist a partition of $\mathbb{Q}$ into three non-empty subsets $A,B,C$ such that the sets $A+B, B+C, C+A$ are disjoint?

Here $X+Y$ denotes the set $\{ x+y : x \in X, y \in Y \}$, for $X,Y \subseteq \mathbb{Z}$ and for $X,Y \subseteq \mathbb{Q}$.
}

\prob{}{}{}{Prove that in any set of $2000$ distinct real numbers there exist two pairs $a>b$ and $c>d$ with $a \neq c$ or $b \neq d $, such that \[ \left| \frac{a-b}{c-d} - 1 \right|< \frac{1}{100000}. \]
}

\prob{}{}{}{Define the function $f:(0,1)\to (0,1)$ by \[\displaystyle f(x) = \left\{ \begin{array}{lr} x+\frac 12 & \text{if}\ \ x < \frac 12\\ x^2 & \text{if}\ \ x \ge \frac 12 \end{array} \right.\] Let $a$ and $b$ be two real numbers such that $0 < a < b < 1$. We define the sequences $a_n$ and $b_n$ by $a_0 = a, b_0 = b$, and $a_n = f( a_{n -1})$, $b_n = f (b_{n -1} )$ for $n > 0$. Show that there exists a positive integer $n$ such that \[(a_n - a_{n-1})(b_n-b_{n-1})<0.\]
}

\prob{}{}{}{Determine all functions $f:\mathbb{Z}\rightarrow\mathbb{Z}$ with the property that \[f(x-f(y))=f(f(x))-f(y)-1\]holds for all $x,y\in\mathbb{Z}$.
}

\prob{}{}{}{Find the smallest constant $C > 0$ for which the following statement holds: among any five positive real numbers $a_1,a_2,a_3,a_4,a_5$ (not necessarily distinct), one can always choose distinct subscripts $i,j,k,l$ such that
\[ \left| \frac{a_i}{a_j} - \frac {a_k}{a_l} \right| \le C. \]
}

\prob{}{}{}{Let $q$ be a real number. Gugu has a napkin with ten distinct real numbers written on it, and he writes the following three lines of real numbers on the blackboard:

    In the first line, Gugu writes down every number of the form $a-b$, where $a$ and $b$ are two (not necessarily distinct) numbers on his napkin.
    In the second line, Gugu writes down every number of the form $qab$, where $a$ and $b$ are
    two (not necessarily distinct) numbers from the first line.
    In the third line, Gugu writes down every number of the form $a^2+b^2-c^2-d^2$, where $a, b, c, d$ are four (not necessarily distinct) numbers from the first line.

Determine all values of $q$ such that, regardless of the numbers on Gugu's napkin, every number in the second line is also a number in the third line.
}

\newpage\section{A3}

\prob{}{}{}{Let $x,y$ and $z$ be positive real numbers such that $xyz=1$. Prove that

\[ \frac{x^{3}}{(1 + y)(1 + z)}+\frac{y^{3}}{(1 + z)(1 + x)}+\frac{z^{3}}{(1 + x)(1 + y)} \geq \frac{3}{4}. \]
}

\prob{}{}{}{A game is played by $n$ girls ($n \geq 2$), everybody having a ball. Each of the $\binom{n}{2}$ pairs of players, is an arbitrary order, exchange the balls they have at the moment. The game is called nice nice if at the end nobody has her own ball and it is called tiresome if at the end everybody has her initial ball. Determine the values of $n$ for which there exists a nice game and those for which there exists a tiresome game.}

\prob{}{}{}{Find all pairs of functions $ f : \mathbb R \to \mathbb R$, $g : \mathbb R \to \mathbb R$ such that \[f \left( x + g(y) \right) = xf(y) - y f(x) + g(x) \quad\text{for all } x, y\in\mathbb{R}.\]
}

\prob{}{}{}{Let $x_1,x_2,\ldots,x_n$ be arbitrary real numbers. Prove the inequality

\[ \frac{x_1}{1+x_1^2} + \frac{x_2}{1+x_1^2 + x_2^2} + \cdots + \frac{x_n}{1 + x_1^2 + \cdots + x_n^2} < \sqrt{n}. \]
}

\prob{}{}{}{Let $P$ be a cubic polynomial given by $P(x)=ax^3+bx^2+cx+d$, where $a,b,c,d$ are integers and $a\ne0$. Suppose that $xP(x)=yP(y)$ for infinitely many pairs $x,y$ of integers with $x\ne y$. Prove that the equation $P(x)=0$ has an integer root.
}

\prob{}{}{}{Consider pairs of the sequences of positive real numbers \[a_1\geq a_2\geq a_3\geq\cdots,\qquad b_1\geq b_2\geq b_3\geq\cdots\]and the sums \[A_n = a_1 + \cdots + a_n,\quad B_n = b_1 + \cdots + b_n;\qquad n = 1,2,\ldots.\]For any pair define $c_n = \min\{a_i,b_i\}$ and $C_n = c_1 + \cdots + c_n$, $n=1,2,\ldots$.

(1) Does there exist a pair $(a_i)_{i\geq 1}$, $(b_i)_{i\geq 1}$ such that the sequences $(A_n)_{n\geq 1}$ and $(B_n)_{n\geq 1}$ are unbounded while the sequence $(C_n)_{n\geq 1}$ is bounded?

(2) Does the answer to question (1) change by assuming additionally that $b_i = 1/i$, $i=1,2,\ldots$?

Justify your answer.
}

\prob{}{}{}{Does there exist a function $s\colon \mathbb{Q} \rightarrow \{-1,1\}$ such that if $x$ and $y$ are distinct rational numbers satisfying ${xy=1}$ or ${x+y\in \{0,1\}}$, then ${s(x)s(y)=-1}$? Justify your answer.
}

\prob{}{}{}{Four real numbers $ p$, $ q$, $ r$, $ s$ satisfy $ p+q+r+s = 9$ and $ p^{2}+q^{2}+r^{2}+s^{2}= 21$. Prove that there exists a permutation $ \left(a,b,c,d\right)$ of $ \left(p,q,r,s\right)$ such that $ ab-cd \geq 2$.}

\prob{}{}{}{The sequence $c_{0}, c_{1}, . . . , c_{n}, . . .$ is defined by $c_{0}= 1, c_{1}= 0$, and $c_{n+2}= c_{n+1}+c_{n}$ for $n \geq 0$. Consider the set $S$ of ordered pairs $(x, y)$ for which there is a finite set $J$ of positive integers such that $x=\textstyle\sum_{j \in J}{c_{j}}$, $y=\textstyle\sum_{j \in J}{c_{j-1}}$. Prove that there exist real numbers $\alpha$, $\beta$, and $M$ with the following property: An ordered pair of nonnegative integers $(x, y)$ satisfies the inequality \[m < \alpha x+\beta y < M\] if and only if $(x, y) \in S$.
}

\prob{}{}{}{Let $ n$ be a positive integer, and let $ x$ and $ y$ be a positive real number such that $ x^n + y^n = 1.$ Prove that
\[ \left(\sum^n_{k = 1} \frac {1 + x^{2k}}{1 + x^{4k}} \right) \cdot \left( \sum^n_{k = 1} \frac {1 + y^{2k}}{1 + y^{4k}} \right) < \frac {1}{(1 - x) \cdot (1 - y)}. \]
}

\prob{}{}{}{Let $ S\subseteq\mathbb{R}$ be a set of real numbers. We say that a pair $ (f, g)$ of functions from $ S$ into $ S$ is a Spanish Couple on $ S$, if they satisfy the following conditions:
(i) Both functions are strictly increasing, i.e. $ f(x) < f(y)$ and $ g(x) < g(y)$ for all $ x$, $ y\in S$ with $ x < y$;

(ii) The inequality $ f\left(g\left(g\left(x\right)\right)\right) < g\left(f\left(x\right)\right)$ holds for all $ x\in S$.

Decide whether there exists a Spanish Couple

    on the set $ S = \mathbb{N}$ of positive integers;
    on the set $ S = \{a - \frac {1}{b}: a, b\in\mathbb{N}\}$
}

\prob{}{}{}{Determine all functions $ f$ from the set of positive integers to the set of positive integers such that, for all positive integers $ a$ and $ b$, there exists a non-degenerate triangle with sides of lengths
\[ a, f(b) \text{ and } f(b + f(a) - 1).\]
(A triangle is non-degenerate if its vertices are not collinear.)
}

\prob{}{}{}{Let $x_1, \ldots , x_{100}$ be nonnegative real numbers such that $x_i + x_{i+1} + x_{i+2} \leq 1$ for all $i = 1, \ldots , 100$ (we put $x_{101 } = x_1, x_{102} = x_2).$ Find the maximal possible value of the sum $S = \sum^{100}_{i=1} x_i x_{i+2}.$
}

\prob{}{}{}{Determine all pairs $(f,g)$ of functions from the set of real numbers to itself that satisfy \[g(f(x+y)) = f(x) + (2x + y)g(y)\] for all real numbers $x$ and $y$.
}

\prob{}{}{}{Let $n\ge 3$ be an integer, and let $a_2,a_3,\ldots ,a_n$ be positive real numbers such that $a_{2}a_{3}\cdots a_{n}=1$. Prove that
\[(1 + a_2)^2 (1 + a_3)^3 \dotsm (1 + a_n)^n > n^n.\]
}

\prob{}{}{}{Let $\mathbb Q_{>0}$ be the set of all positive rational numbers. Let $f:\mathbb Q_{>0}\to\mathbb R$ be a function satisfying the following three conditions:

(i) for all $x,y\in\mathbb Q_{>0}$, we have $f(x)f(y)\geq f(xy)$;
(ii) for all $x,y\in\mathbb Q_{>0}$, we have $f(x+y)\geq f(x)+f(y)$;
(iii) there exists a rational number $a>1$ such that $f(a)=a$.

Prove that $f(x)=x$ for all $x\in\mathbb Q_{>0}$.
}

\prob{}{}{}{For a sequence $x_1,x_2,\ldots,x_n$ of real numbers, we define its $\textit{price}$ as \[\max_{1\le i\le n}|x_1+\cdots +x_i|.\] Given $n$ real numbers, Dave and George want to arrange them into a sequence with a low price. Diligent Dave checks all possible ways and finds the minimum possible price $D$. Greedy George, on the other hand, chooses $x_1$ such that $|x_1 |$ is as small as possible; among the remaining numbers, he chooses $x_2$ such that $|x_1 + x_2 |$ is as small as possible, and so on. Thus, in the $i$-th step he chooses $x_i$ among the remaining numbers so as to minimise the value of $|x_1 + x_2 + \cdots x_i |$. In each step, if several numbers provide the same value, George chooses one at random. Finally he gets a sequence with price $G$.

Find the least possible constant $c$ such that for every positive integer $n$, for every collection of $n$ real numbers, and for every possible sequence that George might obtain, the resulting values satisfy the inequality $G\le cD$.
}

\prob{}{}{}{Let $n$ be a fixed positive integer. Find the maximum possible value of \[ \sum_{1 \le r < s \le 2n} (s-r-n)x_rx_s, \]where $-1 \le x_i \le 1$ for all $i = 1, \cdots , 2n$.
}

\prob{}{}{}{Find all positive integers $n$ such that the following statement holds: Suppose real numbers $a_1$, $a_2$, $\dots$, $a_n$, $b_1$, $b_2$, $\dots$, $b_n$ satisfy $|a_k|+|b_k|=1$ for all $k=1,\dots,n$. Then there exists $\varepsilon_1$, $\varepsilon_2$, $\dots$, $\varepsilon_n$, each of which is either $-1$ or $1$, such that
\[ \left| \sum_{i=1}^n \varepsilon_i a_i \right| + \left| \sum_{i=1}^n \varepsilon_i b_i \right| \le 1. \]
}

\prob{}{}{}{Let $S$ be a finite set, and let $\mathcal{A}$ be the set of all functions from $S$ to $S$. Let $f$ be an element of $\mathcal{A}$, and let $T=f(S)$ be the image of $S$ under $f$. Suppose that $f\circ g\circ f\ne g\circ f\circ g$ for every $g$ in $\mathcal{A}$ with $g\ne f$. Show that $f(T)=T$.
}


\section{Power Series}\label{sec:powerseries}

Recall that the sum of a geometric series can be expressed using the simple formula:
\[\sum_{n=0}^\infty kx^n = {k\over 1-x},\]
if $|x|<1$, and that the series diverges when $|x|\ge 1$. At the time,
we thought of $x$ as an unspecified constant, but we could just as
well think of it as a variable, in which case the series
\[\sum_{n=0}^\infty kx^n\]
is a function, namely, the function $k/(1-x)$, as long as
$|x|<1$: Looking at this from the opposite perspective, this means that
the function $k/(1-x)$ can be represented as the sum of an infinite series. Why would this be useful?
While $k/(1-x)$ is a reasonably easy function to deal with,
the more complicated representation $\sum kx^n$ does have some advantages:
it appears to be an infinite version of one of the
simplest function types---a polynomial. Later on we will investigate some of the ways
we can take advantage of this `infinite polynomial' representation, but first
we should ask if other functions can even be represented this way.

The geometric series has a special feature that makes it unlike a
typical polynomial---the coefficients of the powers of $x$ are all the
same, namely $k$. We will need to allow more general coefficients if
we are to get anything other than the geometric series.

\begin{definition}{Power Series}{PowerSeriesDefinition}
A power series is a series of the form
$$\ds\sum_{n=0}^\infty a_nx^n,$$
where each $a_n$ is a real number.
\end{definition}

As we did in the section on sequences, we can think of the $a_n$ as being a function
$a(n)$ defined on the non-negative integers. Note, however, that the $a_n$ do not depend
on $x$.

\begin{example}{}{}
Determine whether the power series $\ds\sum_{n=1}^\infty {x^n\over n}$ converges.
\end{example}
\begin{solution}
We can investigate convergence using the ratio test:
\[
  \lim_{n\to\infty} {|x|^{n+1}\over n+1}{n\over |x|^n}
  =\lim_{n\to\infty} |x|{n\over n+1} =|x|.
\]

Thus when $|x|<1$ the series converges and when $|x|>1$ it diverges,
leaving only two values in doubt. When $x=1$ the series is the
harmonic series and diverges; when $x=-1$ it is the alternating
harmonic series (actually the negative of the usual alternating
harmonic series) and converges. Thus, we may think of
$\ds\sum_{n=1}^\infty {x^n\over n}$ as a function from the interval
$[-1,1)$ to the real numbers.
\end{solution}

A bit of thought reveals that the ratio test applied to a power series
will always have the same nice form. In general, we will compute
\[
  \lim_{n\to\infty} {|a_{n+1}||x|^{n+1}\over |a_n||x|^n}
  =\lim_{n\to\infty} |x|{|a_{n+1}|\over |a_n|} =
  |x|\lim_{n\to\infty} {|a_{n+1}|\over |a_n|} =L|x|,
\]
assuming that $\ds \lim |a_{n+1}|/|a_n|$ exists. Then the series
converges if $L|x|<1$, that is, if $|x|<1/L$, and diverges if
$|x|>1/L$. Only the two values $x=\pm1/L$ require further
investigation. Thus the series will always define a function on
the interval $(-1/L,1/L)$, that perhaps will extend to one or both
endpoints as well. Two special cases deserve mention: if $L=0$ the
limit is $0$ no matter what value $x$ takes, so the series converges
for all $x$ and the function is defined for all real numbers. If
$L=\infty$, then no matter what value $x$ takes the limit is infinite
and the series converges only when $x=0$. The value $1/L$ is called
the \dfont{radius of convergence} of the series, and the
interval on which the series converges is the \dfont{interval of
convergence}.

We can  make these ideas a bit more general. Consider the series
\[\ds\sum_{n=0}^{\infty}\frac{(x+2)^n}{3^n}\]
This looks a lot like a power series, but with $(x+2)^n$ instead of $x^n$.
Let's try to determine the values of $x$ for which it converges.
This is just a geometric series, so it converges when
\begin{align*}
  |x+2|/3&<1	\\
  |x+2|&<3	\\
  -3 < x+2 &< 3	\\
  -5<x&<1.	\\
\end{align*}

So the interval of convergence for this series is $(-5,1)$. The center
of this interval is at $-2$, which is at distance 3 from the endpoints,
so the radius of convergence is 3, and we say that the series is centered at $-2$.

Interestingly, if we compute the sum of the series we get
\[\ds\sum_{n=0}^{\infty}\left(\frac{x+2}{3}\right)^n=\frac{1}{1-\frac{x+2}{3}}=\frac{3}{1-x}.\]
Multiplying both sides by 1/3 we obtain
\[\sum_{n=0}^\infty {(x+2)^n\over 3^{n+1}}={1\over 1-x},\]
which we recognize as being equal to
\[\sum_{n=0}^{\infty}x^n,\]
so we have two series with the same sum but different intervals of convergence.

This leads to the following definition:

\begin{definition}{Power Series}{PowerSeriesDefinition2}
A power series centered at $c$ has the form
$$\ds\sum_{n=0}^\infty a_n(x-c)^n,$$
where $c$ and each $a_n$ are real numbers.
\end{definition}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:powerseries}}

\begin{enumialphparenastyle}

\begin{ex}
Find the radius and interval of convergence for each series.  In
part c),
do not attempt to determine whether the endpoints are in the
interval of convergence.

\begin{multicols}{2}
\begin{enumerate}
	\item $\ds\sum_{n=0}^\infty n x^n$
	\item $\ds\sum_{n=0}^\infty {x^n\over n!}$
	\item $\ds\sum_{n=1}^\infty {n!\over n^n}(x-2)^n$
	\item $\ds\sum_{n=1}^\infty {(n!)^2\over n^n}(x-2)^n$
	\item $\ds\sum_{n=1}^\infty {(x+5)^n\over n(n+1)}$
\end{enumerate}
\end{multicols}
\begin{sol}
\begin{enumerate}
	\item $R=1$, $I=(-1,1)$
	\item $R=\infty$, $I=(-\infty,\infty)$
	\item $R=e$, $I=(2-e,2+e)$
	\item $R=0$, converges only when $x=2$
	\item $R=1$, $I=[-6,-4]$
\end{enumerate}
\end{sol}
\end{ex}

\begin{ex}
Find the radius of convergence for the series $\ds\sum_{n=1}^\infty {n!\over n^n}x^n$.
\begin{sol}
$R=e$
\end{sol}
\end{ex}

\end{enumialphparenastyle}

\clearpage