TITLE: Periodicity in iterated powers of sin, cos, exp
QUESTION [9 upvotes]: Given a complex number $z$, consider the sequence
\begin{align*}
a_0 & = 1\\
a_1 & = (cos(1))^z\\
a_n & = (cos(a_{n-1}))^z
\end{align*}
This question is about trying to understand periodicity in such
sequences.  For real $z < 2$, the sequence converges to a fixed point.
For larger real $z$, the sequence oscillates between two distinct
limit points.  This behavior can be explained by elementary dynamics,
and one can find that the transition point is around $2.188$.
I was surprised to find that the behavior for general complex $z$ is,
well, complex!  Define a function $P$ from the complex plane to
$\mathbb{N}$ as follows: 
$$P(z) =  \mathrm{number\ of\ limit\ points\ of\ the\ sequence}\ \{1, cos(1)^z, cos(cos(1)^z)^z, \ldots\}$$
Here is a picture of $P$: this is the region $[-8,8] \times [-8,8]$
and the pixel at $z$ is given color $n$ by some software that
estimates $P(z)$.

Black pixels are points where the software cannot detect periodicity.  The correspondence between colors and numbers is as follows, where 'Unk' means 'Unknown':

In particular, one can see the behavior along the positive real axis
matches the description above.  (Although there are no axes in this
picture, I have verified separately that the transition point in the
picture is correct.)  Unfortunately, I have no idea how to explain the
rest of the picture!  Although I have been careful writing the
software, I can't say with certainty that the picture is correct
anywhere other than the positive real axis.
This question is in danger of being too general, so here is one
specific question to answer:  Is the cardoid-shaped region colored 1
correct?
I would, of course, also be happy to hear any other verifications of features in this
picture, or other behavior of $P(z)$ not depicted.

Sin and exp
At the risk of going on too long, I think it's natural to also address
a similar question for the sine and exponential functions.  Here is
the picture for exp:

And the picture for sin is below:

This last one, for the sine function, is even more bewildering to
me.  There is something that looks very much like a Mandelbrot set
there.  Why?

Motivation
Two of my colleagues were discussing the behavior of cos along the
positive real axis on our department mailing list.  I was curious
about the complex behavior, but this is outside my field, so started
making pictures like the ones shown here.  I've been thinking about
these off and on for a little over a year, but not really made any progress or
had anyone give me a useful reference.  So I wanted to see what the
wider MO community has to say.
If you want some higher-resolution pictures for cos, see this G+ post:
https://plus.google.com/u/0/+NilesJohnson/posts/1JqWahhwGbh

Notes on the software
The software computes 500 iterates, and then looks at the next 30
iterates.  It returns the minimum $n$ such that there are two
successive subsequences of length $n$ whose corresponding terms are
within $\varepsilon = .001$.  If no such $n$ is found, it computes 500
more iterates and tries again.  This is repeated 6 times.  If no such
$n$ is found, the pixel is colored black.
Decreasing $\varepsilon$ by a factor of $10^4$ or so takes longer but does
not result in a substantially different picture.

REPLY [4 votes]: In spite of the potential issues arising from the fact that this function is not entire, there is a standard way to describe the components that you see in these types of pictures. Suppose that we are studying the iteration of a function $f_p(z)$ where $z$ is a complex variable and $p$ is a complex parameter. The cardioid-like figure that you see arises as the boundary of the set of $p$ parameters such that the corresponding function $f_p$ has an attractive fixed point. Symbolically:
\begin{align}
  f_p(z) &= z \\
  \left|\ f_p'(z)\right| &< 1
\end{align}
The equation $f_p(z)=z$ says that $z$ is a fixed point and the inequality $\left|\ f_p'(z)\right|<1$ says that the fixed point is attractive. On the boundary, we expect that $\left|\ f_p'(z)\right|=1$. Thus, the boundary may be described as 
\begin{align}
  f_p(z) &= z \\
  \ f_p'(z) &= e^{it},
\end{align}
for some $t\in[0,2\pi)$. If we can solve the equations for $z$ and (more importantly) $p$ in terms of $t$, we have an explicit description of the boundary. In the case of the Mandelbrot set, $f_p(z)=z^2+p$ and this pair of equations can be solved in closed form so we have a proof that the main cardioid is, in fact, a cardioid. This is a bit much to expect in the current case. Nonetheless, we can make some progress and finish it off numerically. To do so, write $f_p(z)=\cos^p(z)$. The equations of interest are then
\begin{align}
  \cos^p(z) &= z \\
  -p \sin (z) \cos ^{p-1}(z) &= e^{i t}
\end{align}
This second equation can be solved for $p$ in terms of $z$ and $t$ using Lambert's W function:
$$p(z,t) = \frac{W\left(-e^{i t} \cot (z) \log (\cos (z))\right)}{\log
   (\cos (z))}.$$
Note: there is certainly a potential branch cut issue here! Nonetheless, plugging that back into the first equation we get
$$\cos^{p(z,t)}(z) = z.$$
For a given $t$, this equation can be solved numerically to determine a specific $z$ value that is a neutral fixed point of $\cos^{p(z,t)}$. If we then plug that $z$ and $t$ value into $p(z,t)$ we get a point on the boundary of your cardioid-like domain.
Again, this procedure is certainly fraught with branch cut and numerical issues. proceeding undaunted, I implemented this in Mathematica together with the iteration scheme itself and came up with the following: