The Simplicity of Complexity – The Mandelbrot Set
The MANDELBROT SET is the most complex object in mathematics, its admirers like to say. An eternity would not be enough time to see it all, its disks studded with prickly thorns, its spirals and filaments curling outward and around, bearing bulbous molecules that hang, infinitely variegated, like grapes on God’s personal vine – James Gleick in Chaos, Making a New Science.
This project was a brief exploration into the mind-boggling and beautiful world of mathematical complexity, by way of the most famous example of fractal geometry, called the Mandelbrot set. Because of the VisualBots built-in color graphics and user-defined coordinate system features, it is actually quite easy to explore this amazing object.
Above are various windows in the complex plane, rendering the Mandelbrot fractal using the built-in graphics capabilities of the VisualBots simulator.
Background
The Mandelbrot set was named after the work of mathematician Benoit Mandelbrot in the 1980′s, who was one of the early researchers in the field of dynamic complexity. The Mandelbrot set has a fractal-like geometry, which means that it exhibits self-similarity at multiple scales. However, the small-scale details are not identical to the whole, and in fact, the set is infinitely complex, revealing new geometric surprises at ever increasing magnification. Belying this mind-boggling complexity is the extremely simple mathematic process used to produce it.
The Mandelbrot set is a set of complex numbers (remember in algebra – the points in the 2D complex plane with real and imaginary axes?). Every complex number is either in the set, or outside of it. The set is generated by applying a simple iterative process to each complex number. In mathematical jargon, it is defined by all of the complex numbers C for which the number sequence
is bounded, or does not tend towards infinity.
In other words, to generate the set, take a complex number, multiply it by itself, and add it to the original number; take that result, multiply it by itself, and add it to the original number; and so on. If the resulting numbers generated during the iteration process grows ever and ever larger, then the original complex number C is not in the Mandelbrot set. If the sequence converges, drifts chaotically, or cycles periodically, then C is in the set. Of course in practice we cannot apply the iteration process an infinite number of times to be sure that C is a member of the set. So instead, the process is applied several hundred or several thousand times, and if the sequence remains relatively small during these iterations, then it is assumed that C is probably a member of the set. Fortunately, there is a very useful criteria for detecting divergence – it can be demonstrated mathematically that if during the iteration process the number sequence exceeds the absolute value of 2, then the sequence will diverge to infinity and the original number C is definitely outside of the set. Many points reach a value that exceeds 2 after only a few iterations.
The typical means of graphically rendering the Mandelbrot fractal is to color points in the complex plane that belong to the set as black, and all other points outside of the set according to how quickly they diverge towards infinity. The speed at which points outside of the set diverge, sometimes referred to as “escape speed”, is measured by how many iterations of the number sequence are required until divergence is detected.
It turns out that the Mandelbrot set lives very close to the origin of the complex plane, within a radius of 2. The most interesting regions are found near the boundaries of the set, where the escape speeds are relatively higher than those farther away. Zooming down into these regions exposes a remarkable variation of self-similar structures.
In the Mandelbrot set, nature (or is it mathematics) provides us with a powerful visual counterpart of the musical idea of ‘theme and variation’: the shapes are repeated everywhere, yet each repetition is somewhat different. It would have been impossible to discover this property of iteration if we had been reduced to hand calculation, and I think that no one would have been sufficiently bright or ingenious to ‘invent’ this rich and complicated theme and variations. It leaves us no way to become bored, because new things appear all the time, and no way to become lost, because familiar things come back time and time again. Because this constant novelty, this set is not truly fractal by most definitions; we may call it a borderline fractal, a limit fractal that contains many fractals. Compared to actual fractals, its structures are more numerous, its harmonies are richer, and its unexpectedness is more unexpected – Benoit Mandelbrot.
Above is the highest-elevation view of the Mandelbrot set (the portions colored black). The set does not extend beyond a radius of 2 in the complex plane.
One amazing aspect of the Mandelbrot set that was proved by Hubbard and Douady of the University of Paris, is that it is connected, meaning that there are no islands of points in the set that are isolated from the rest. Many apparently isolated “molecules” of the set can be observed at high magnification, but the appearance is deceiving, because each of these are connected to the rest of the set by very thin filaments. Other interesting aspects are that the perimeter of the set has an infinite length, and that its area is unknown.
VisualBots Implementation
The algorithm for generating the Mandelbrot fractal is very simple:
1. Cycle through all screen pixels, converting each to its respective complex plane coordinates
2. Determine whether or not the pixels are in the Mandelbrot set
3. If they are in the set, color black, otherwise color based on their escape speed
The following pseudo code renders a specified window in the complex plane:
Set the screen coordinate system to bracket the window of interest
Color the screen background black
maxiter=1000 (setting maxiter to smaller value trades-off resolution for computational speed)
For each screen pixel do the following:
R0 = calculate the real coordinate of pixel
I0 = calculate the imaginary coordinate of pixel
R = R0
I = I0
R2 = R * R
I2 = I * I
iter = 0
While (R2 + I2 < 4) And (iter < maxiter) Do:
I = 2 * R * I + I0
R = R2 – I2 + R0
R2 = R * R
I2 = I * I
iter = iter + 1
Loop
If iter < maxiter Then
color the pixel according to value of iter
End If
Next screen pixel
To assign color to each screen pixel, we created a single Bot object, gave it a point shape, and set its Footprint property to True. With this combination of settings, the Bot imparts a “footprint” of color as it is moved from pixel to pixel. The color of the footprint is calculated using the FillColorPick method of the Bot object, which selects a entry point into the assigned ColorTable based on a variable, in this case, “iter”.