201. The Mandelbrot

Recipe

Having learned how the complex numbers work we are now well-equipped to start drawing our own Mandelbrot fractals. Unlike fractal curves and chaos games that are generated by purely geometric replacement rules, the iconic shape of the Mandelbrot set arises from a deceptively simple mathematical function operating on complex numbers. Just as in the case of fractal curves the stunning complexity comes about because the generator function is being applied recursively — each iteration increasing the level of detail. While in theory we would need to apply the function an infinite number of times, a more modest number of iterations will offer us a good enough approximation for our purely visual purposes. The function in question looks like this.

In other words, to calculate the next value of z we square the previous value of z (multiply it by itself) and add c. This is the arithmetic counterpart of the geometric "replace each line with X" rule we used with fractal curves. While the value of z keeps changing as we iterate further – with n corresponding to the iteration "depth" – the value of c stays constant throughout. Which means that in order to begin the infinitely iterative process (from n=0) we only need two complex numbers: some constant c and some initial value for z₀. When working with the vanilla version of the Mandelbrot set the latter is always initialized to zero which lets us focus our efforts on c1. So how does this function behave under repeated iteration?

Real dynamics

More concretely, what kind of zₙ values do we expect to see for different values of c? To start off simple (as is often best) we first concentrate on the more familiar parts of the complex plane and see how the Mandelbrot function behaves for c values picked from just the real number line. The simplest case of c equals zero turns out to be completely static as all subsequent values of z also stay zero. Not very interesting, but something very different happens if we set c equal to one. This causes the values of z to start growing geometrically — 0, 1, 2, 5, 26, 677, 458330, and so on. Although at first the effect of adding 1 is instrumental in getting the sequence going, the effect of the addition is very quickly eclipsed by the effects of squaring the previous value of z. Growing without bound the value of z approaches infinity (ie. diverges) as n increases.

Yet another kind of behaviour arises if we negate c and set it equal to minus one. This causes the sequence of z values to get trapped in a periodical cycle between zero and minus one because the next value (of z₂) evaluates to (-1)²-1 — which is equal to zero. The value of c being constant means that whenever the value of z becomes exactly zero the sequence effectively starts over from the beginning. These repeating cycles can be arbitrarily long, but whenever z becomes exactly equal to some previously encountered value (which need not be zero) the sequence always necessarily repeats itself. We see another example of this behaviour a bit further out at c equals minus two where z goes from zero, to minus two, to two, and then gets trapped there because 2²-2 keeps reproducing the same value (ad infinitum). After a very brief preperiodic phase the perfectly static behaviour resembles that of c=0. Curiously, going even slightly more negative results in an unbounded sequence similar to what we saw with c=1.

Two more cases are of special interest, and those are c=¼ and c=-¾. The first instance is a kind of hybrid between the unbounded growth of c=1 and the eternal stability of c=0. At first, the values of z seem to grow quite consistently, but as we iterate further the growth rate slows down to a crawl. Indeed, no matter how many times we apply the function the value of z never grows past a certain point. At the limit, when n goes to infinity the value of z can be said to approach ½ — without ever reaching it in finite time. The latter case of c=-¾ which sits between the perfectly periodic behaviour of c=-1 and the eternally static c=0 produces arguably the weirdest behaviour we've seen thus far. Instead of converging on a single value, or getting trapped in a periodic cycle, or diverging towards infinity, the resulting z sequence just keeps bouncing around forever never quite reproducing any previous value of z. Should we move c the tiniest possible bit towards zero its z sequence would eventually converge to -½. Likewise, making c even slightly more negative would cause its z sequence to eventually get trapped between just two repeating values — one slightly smaller, one slightly larger than -½. The point exactly at -¾ is a kind of superposition of these two possibilities where attracting and repelling dynamics are in perfect equilibrium.

You can try all of this out for yourself using the demo above which visualizes the different values of zₙ generated by a specific value of c with n growing from left to right. The animation cycles through some points of interest, but you can choose a number of your own simply by dragging the red pin around. Notice how the region between approximately -1.401 and -2 is mostly chaos, but with some curious exceptions sprinkled into the mix. The cycling animation shows two most prominent exceptions — located at roughly -1.755 and -1.914. Visualizing these oscillation patterns in a different way would result in what is known as a bifurcation diagram. While the resolution of the demo is not nearly enough to pick up on the subtle instability of -¾ it is quite prominent in the context of these bifurcation diagrams.

Complex dynamics

When we switch our view to the full domain of complex numbers we come to realize that the same dynamics still apply! Although there's now much more room to play around in there is still only four different ways the resulting values of z can behave: (1) diverge to infinity, (2) converge on a single value, (3) become trapped in a periodically repeating cycle (with or without a preperiodic lead-up phase), or (4) keep bouncing around forever without any repetition. Indeed, there can hardly be any other possibilities if you think about it. We can reduce the number of categories to three if we consider converging sequences to be periodical in the sense that their cycle consists of just a single value, ie. they have a period of one2.

By definition, all values of c which result in non-diverging dynamics are considered to be part of the Mandelbrot set. In the case of the real number line this includes all values contained within the closed interval from -2 to ¼. As shown in the earlier demo everything outside this interval quickly begins to creep towards infinity, and for this reason is not considered to be within the Mandelbrot set. When the entirety of the complex plane is considered the outline of the set becomes decidedly more complicated.

The demo below shows an approximation of the shape of the Mandelbrot set in black (as is customary). The partially visible boundary between the white outer region and the lightest grey is a perfect circle with a radius of two, and the different shades of grey are colored based on how quickly the enclosed values of c diverge beyond this radius. In the next post we will see why this is equivalent to eventually diverging to infinity.

Overlaid in color are the line-connected zₙ points generated by the current constant c whose value is displayed next to its location on the complex plane. The looping animation visualizes the behaviour of c values close to the main boundary, but you are free to drag the red pin around as you see fit.

Recall that complex multiplication and addition are analogous to linear transformations. The consequence in the context of Mandelbrot is that with each iteration we effectively rotate and scale z in proportion to itself and then translate that result based on c to produce the next value of z. When visualized in two dimensions the spiraling line bundles manage to make this transformational nature rather apparent. Perhaps partly due to these characteristics the sequences of z are also sometimes referred to as "orbits", which are entirely equivalent to the oscillating line graphs shown in the earlier demo3.

In my humble opinion, the most beautiful "orbit flowers" are to be found along the inside edge of the main boundary. In addition to these floral patterns a whole range of geometric shapes of varying periodicity can be found within the bulbous outgrowths lining the outside edge of the same boundary. To point out the obvious, notice how the orbit dynamics are entirely symmetric with respect to the horizontal imaginary axis — the left side is a clockwise mirror image of the counter-clockwise right. This video shows in more detail how these orbit bundles behave in larger groups.

In case you didn't already try it out, the slider on the bottom can be used to alter the maximum iteration depth (often referred to as the bailout) which is set to n=100 by default. Playing around with the bailout makes it is possible to see how the approximation of the Mandelbrot set outline improves with higher iteration depths. At our bird's eye view a hundred iterations is more than enough to generate all the detail that the limited resolution can display. Once we start looking more closely at the detailed structure of the set we will need to dramatically increase the bailout value.

Diving deeper

Now that we know how to build and visualize the Mandelbrot set we would perhaps like to know the what of it, followed by the inevitable why. The why is naturally the hardest question to answer if indeed it makes sense at all. In any case, in the next part we will take a closer look at the different parts that make up the overall shape of the set. All the different bits and pieces have certain common properties which allow us to build a higher level description of what we are seeing, which hopefully allows us to better understand what it is that we actually looking at. Having now dipped our toes in the fractal waters it is time to start our ► Mandelbrot deep dive.






1

Under these assumptions the successive iterations of the Mandelbrot function can be simplified into a set of complicated polynomials. The leading exponent keeps doubling with each iteration while the trailing coefficients stabilize in a linear fashion. The polynomial coefficients of the eventual infinite-degree polynomial are the Catalan numbers.

2

In an even more accommodating sense we could consider case (1) as converging on a point at infinity since it can be thought of as just another point. Furthermore, we can interpret the case (4) to represent a repeating cycle with an irrational periodicity — we can never observe the repetition since we are only working on integer values of n. The next post will discuss this latter point in more detail.

3

You can think of the earlier line graphs as existing in a third dimension which in this latter demo gets squished onto the two-dimensional surface of your display. In an attempt to compensate this missing dimension is instead visualized in color — red for "nearest" and yellow for "farthest".