# The Riemann surface of arctan

Riemann surfaces. We all know and love them.

The
is easy enough, but until now I was in the dark about how the complex arctangent "looked".

Until I found
and was enlightened.

Tonight I will dream of infinite blue staircases.

I've been dwelling on the kinds of intuitions developed by anyone who studies mathematics. They're often simple rules of thumbs and ways of thinking about mathematical objects. In fact, they are
**
so
**
obvious that once you've internalized them, it often doesn't occur to you to articulate them again.

For example, one very basic component of real analysis is
**
function composition
**
, something that is probably taught early on in high school -- although
.

What does it mean to compose functions? How does one reason about a compound function? I got thinking about how one might go about helping a student to develop their intuition about these questions. It occurred to me that there is a simple visualization technique that answers this exact question
*
without any words at all
*
.

How does this work? Let's say you want to visualize the following compound function:

First, let's consider the syntax tree of this expression. This is a tree in which the
*
root
*
is the entire expression and the
*
leaves
*
are linear or constant functions like
*
x
*
and
*
1/3
*
. Luckily, with
*
Mathematica
*
it's pretty easy to present an arbitrary expression directly in this tree representation by using the formatting construct
TreeForm
:

My idea is to produce actual function plots for each
*
interesting
*
node in this tree. By moving up the tree we can show how these sub-expressions fit together to compose the entire expression
*
.
*
It turns out that it takes about 15 lines of
*
Mathematica
*
to compile the syntax tree, recognize and extract the interesting nodes, and synthesize the corresponding plots into a graphical diagram.

Wrapping this all up into a function called
**
FunctionTreePlot
**
, we can now visualize our example like so:

This technique seems to work quite well. You can easily chase visual features of the corresponding plots up and down the tree to answer questions like "why does this function have a pole here" or "what will be the effect of changing this co-efficient?" No doubt this functionality would be a great addittion to Wolfram|Alpha's already strong support for visualizing mathematical functions .

Here are a few more examples from my experiments:

The inventor of , probably also one of the greatest mathematicians of the 20th century, was a rather astounding character named . When he wasn't throwing fabulous parties in Princeton or working on the atomic bomb, Von Neumann was laying some of the groundwork for the science of the late 20th century. Among his many creations was one of the first electronic digital computers, and associated with it the stored-program architecture that still underlies computers today.

A slightly less well known creation of his was the so-called
*
.
*
Something of an
*
alter ego
*
to the digital computer, the cellular automaton is a distributed computational device composed of an array of many simple processors instead of
, as in the computer. Unlike Neumann's other ideas, which continued to flourish, cellular automata fell into obscurity until the late 70s, when they experienced something of a renaissance after the
of
(who happens to be the CEO of the
I work for).

More recently, a strange blend of these two ideas has arisen in the guise of rather long-winded
. Various academics have
what happens when, instead of the disembodied entities of traditional game theory (who one imagines lurking in imaginary war rooms plotting
), the game players are
*
embodied
*
agents situated in physical space on a grid or lattice, interacting with their neighbors.

It turns out that this can make a huge difference to the dynamics of such games. For example, in the traditional game of
Prisoner's Dilemma
, the only evolutionarily stable strategy (a strategy that a group of agents can play without being undermined by the appearance of mutants in their midst) is for every player to defect -- in other words, a lose-lose situation where everyone mistrusts everyone and we are all unhappy. This is nature red in tooth and claw, pre-
Leviathan
.

However, when we consider that these agents can be on a grid, and can, so to speak, huddle together for comfort, we notice that "tribes" of co-operators can form that offset the attacks from defectors on all sides by forming many positive relationships amongst themselves (see pictures below, the top panel is where the co-operators (blue) have successfully fought off invaders, in the bottom not so much). In fact, this point gets to the heart of one of the puzzles of evolutionary biology:
why altruism exists
and how it evolved.

This last result was discovered only recently with the help of computer experiments, and there are sure to be many such discoveries waiting to be made in the field of evolutionary spatial game theory. To this end (yup, all of this post so far has been background -- it links up too beautifully to not mention the history), I've been working on a software library to allow experiments in
*
ESGT
*
to be conducted elegantly and efficiently. To leave you with a taste of what such experiments to look like, here are some videos of the game of Rock Paper Scissors being played on grid (at various 'temperatures', or degrees of randomness):

I'll post more such videos in the future as I do further experiments, and hopefully delve a little more into the details of the science that is going on. If you're interested in the code and seeing some more examples, or even playing around with it yourself if you have a copy of
*
Mathematica
*
, you can visit the project page on GitHub:

Long live spatial game theory!