Fractal eXtreme: Fractal Theory
Fractal eXtremeFractal Theory
Sample Code | Imaginary Numbers | Complex Numbers | The Mandelbrot Set | The Battle for Z's Destiny | Fractal Dimensions | Connectedness

Introduction

What is the Mandelbrot set? A mathematician might say it was the locus of points, C, for which the series Zn+1 = Zn * Zn + C, Z0 = (0,0) is bounded by a circle of radius two, centered on the origin.

But most of us aren't mathematicians.

  • It's a pretty picture.
  • It's a mathematical wonder that we can appreciate, and to some extent understand, even if we don't understand the first paragraph.
  • It's just one example of an amazing new science with applications as far ranging as weather forecasting, population biology, and computerized plant creation.
  • It's a floor wax and a dessert topping!
  • It's all of these and more.

One of the fascinating things about the Mandelbrot set is the seeming contradiction in it. It is said to be the most complex object in mathematics, perhaps the most complex object ever seen. But at the same time, it is generated by an almost absurdly simple formula. Multiply Z by itself. Add C. The answer is the new value for Z. Repeat until the absolute value of Z is greater than two, or until our counter expires. If abs(Z) ever exceeds two, then it will very quickly head off towards infinity which means that the point is not in the Mandelbrot set (that's the definition of the Mandelbrot set). These points are typically assigned a colour based on how many iterations were done before abs(Z) exceeded two. If abs(Z) doesn't exceed two after a large number of iterations, then we give up and assume that the initial point is in the Mandelbrot set. These points are typically coloured black. The black, barnacle covered pear is the Mandelbrot set proper - all the bands of colour outside of it are simply curious artifacts that help to expose the detail of the Mandelbrot set itself.

Back to top

Sample Code

To demonstrate just how simple it is to generate pictures of the Mandelbrot set, we have included a small program written in "C". If you have a C compiler, try it out. It is a complete working program.

#include "stdio.h"

#define MaxIters 200
#define SIZE     80
#define BLACK    -1
#define LEFT     -2.0
#define RIGHT    1.0
#define TOP      1.0
#define BOTTOM   -1.0

main(int argc, char *argv[])
{
    short   x, y, count;
    long double zr, zi, cr, ci;
    long double rsquared, isquared;

    for (y = 0; y < SIZE; y++)
    {
        for (x = 0; x < SIZE; x++)
        {
            zr = 0.0;
            zi = 0.0;
            cr = LEFT + x * (RIGHT - LEFT) / SIZE;

            ci = TOP + y * (BOTTOM - TOP) / SIZE;
            rsquared = zr * zr;
            isquared = zi * zi;

            for (count = 0; rsquared + isquared <= 4.0
                            && count < MaxIters; count++)
            {
                zi = zr * zi * 2;
                zi += ci;

                zr = rsquared - isquared;
                zr += cr;

                rsquared = zr * zr;
                isquared = zi * zi;
            }

            if (rsquared + isquared <= 4.0)
                printf("*");    
            else
                printf(" ");    
        }
        printf("\n");
    }
    return 0;
}
For those of you who aren't programmers, we have excerpted the code which actually does all of the calculations. Here it is, all eleven lines of it:
for (count = 0; rsquared + isquared <= 4.0
                && count < MaxIters; count++)
{
    zi = zr * zi * 2;
    zi += ci;

    zr = rsquared - isquared;
    zr += cr;

    rsquared = zr * zr;
    isquared = zi * zi;
}
That's all it takes to do a rudimentary exploration of the Mandelbrot set. Slowly.

But where did this magical sequence of instructions come from? It certainly looks very arbitrary, and very peculiar. It turns out that it is a computerized version of an even simpler formula.

Back to top

Imaginary Numbers

But first, a quick refresher math course. We should all remember that the square root of nine is three, of four is two and of one is one. But how many remember what the square root of negative one is? (Those who said "me" can skip to the next paragraph, those of us who once knew but have somehow forgotten, should probably read on.) Well one answer to what is the square root of -1 is that there isn't one. However another answer, which is equally valid, and perhaps far more interesting, is that since there isn't any number which multiplied by itself gives us -1, we'll create one. That's a handy way of plugging up all sorts of mathematical theories that would otherwise have special cases for when you need the square root of a negative number. How do we ‘create' a number which is the square root of -1? Simple. Just get enough mathematicians together in one room and get them to all agree that from then on, the letter 'i' represents the square root of -1. That's all it takes. That's all it took. A convention of mathematicians creates the convention of i. And i is subsequently recognized as being the square root of -1.

So if i is the square root of negative one, then, two times i is the square root of negative four, three times i is the square root of negative nine, etc. All these numbers that are multiplied by i are called imaginary numbers, a throwback to those early years when mathematicians weren't quite sure whether they were real or not.

Numbers that aren't multiplied by i, regular numbers, are called real numbers. Simple enough.

Back to top

Complex Numbers

Once you get into more complicated math you start coming across some equations where the answer is neither a real number nor an imaginary number, but the sum of both. An answer that looks like this: 1 + 2i, or 7 + 56i. There's no way of simplifying these equations. You can't reduce them so that there's only one term, you can't derive a sum, you just have to write them down as 1 + 2i. These numbers, part real, part imaginary, are called complex numbers.

If we want to add two complex numbers, say 7 + 4i and 3 + 9i, we simply add the real and imaginary components separately, i.e.; 7 + 3 is 10 and 4i + 9i is 13i. This gives us 10 + 13i. What about multiplying them? Do we have to learn brand new weird math to do that? Not really. We'll start with the easy part. 7 * 3 is 21. More complicated is 4i * 9i. Or is it? It's the same as saying 4 * 9 * i * i. 4 * 9 is 36, and we know (since we defined it as such) that i * i is -1. Therefore 4i * 9i is -36. That leaves us with 7 * 9i which is 63i, and 4i * 3 which is 12i. First we add up the real parts which gives us 21 + -36 which is -15. Then we add up the imaginary parts which gives us 63i + 12i which is 75i. So the answer is -15 + 75i. A bit cumbersome and error prone, but not too incomprehensible.

From all this the fractal is born. The fractal is a graphic representation of a whole bunch of these complex numbers. The numbers are plotted on a plane with the real number component representing the distance left or right of the centre, and the imaginary component representing the distance above or below the center.

Back to top

The Mandelbrot Set

So that brings us to today. The Mandelbrot set is found in the complex plane. Each point on that plane represents a single complex number of the form a + bi, where a is the distance left or right from centre line (negative when left, positive when right) and b is the distance above or below the centre line (negative when below, positive when above) and i is the root of -1.

With the understanding we now have of complex math, we can write out the Mandelbrot formula in a much more compact form. If we had a computer language that understood complex numbers (some do) we could even write a program in this form.

Complex Z = (0 + 0i)
Complex C = (a + bi)
for (count = 0; ABS(Z) <= 2.0 &&
                count < MaxIters; count++)
	Z = Z * Z + C;
That's it. The Mandelbrot set is REALLY simple. All the lines of code at the beginning of this discussion were just teaching the computer how to do the single line of math above. Multiply Z by itself. Add C. The answer is the new value for Z. Repeat until the absolute value of Z is greater than two, or until our counter expires.

The only unexplained feature above is the ABS(Z) part. ABS stands for absolute value. The absolute value of a complex number is simply its distance from the centre of the plane. If we think of the number as a point on the plane, we can measure the distance from the center with a ruler. Or that distance can be calculated using the Pythagorean theorem (since it's a piece of cake to create a right angle triangle on a plane) by determining the square root of ‘a' squared plus ‘b' squared. If the answer is less than or equal to two, you are looking at a point in a Mandelbrot set. If the answer is over two, the point is outside the set.

Back to top

The Battle for Z's Destiny

Z starts out being initialized to zero, that is, both the real and imaginary parts are set to zero. C is initialized to the complex number representing the point we want to calculate, its real portion is its horizontal distance from the centre of the plane, its imaginary portion is its vertical distance from the centre of the plane. We continue going through the loop above, squaring Z and adding C to it. What are we trying to find out by doing this? Whether Z will start getting large, or will stay a very small number, trapped around the centre of the complex plane.

After the first iteration, Z is equal to C, because zero squared is zero. Then, if Z is larger than one, when it is squared it will leap outwards, trying to break free. However if C is pointing in the opposite direction, then when C is added in it will pull Z back. If Z is smaller than one then squaring it makes it even smaller, but again, C is a wildcard - which way will it push Z - in or out? There is no shortcut way of finding out, we have to go through all of the calculations. But as we zoom in to the convoluted boundary of the Mandelbrot set we can see that Z and C have fought a mighty battle to see whether Z escapes or not. Constantly changing sides, teetering near the brink of two, only to fall back towards zero. It is a battle where a change of a millionth of a unit can be the difference between staying forever trapped or shooting off to infinity.

The Julia set is very similar to the Mandelbrot set in how it is calculated. The actual calculation loop is identical, but the initialization is slightly different. For the Julia set, Z is initialized to the current point, and C is initialized to a seed value, another complex number which is typically taken from the Mandelbrot set. For each different value of C, you get an entirely different Julia set. Since there are an infinite number of values for C, there are an infinite number of Julia sets, each of which can be zoomed into to any level level of magnification. That's why, a thousand years from now, you'll still be able to look around the Mandelbrot and Julia sets and know that you're almost certainly exploring an area that no human being has ever seen before.

Back to top

Fractal Dimensions

The Mandelbrot set and Julia sets are fractals. What this means is that the boundary between the black area that is the Mandelbrot set and the surrounding area that isn't the Mandelbrot set is not a simple line or a curve (one dimensional), but it also isn't a filled in circle or square (two dimensional). It is so convoluted, folded, and detailed, that it is considered to have fractional dimension.

When you double the magnification of a fractal, the length of the curve, and hence the area covered, does not merely double. All previously visible portions of the curve double in length, but new bumps, curves and fjords in the boundary become visible and add to the length.

The Mandelbrot set has been proven to have a fractal dimension of two. That means that each time you double the magnification, the length of the boundary increases four times. It also means that the Mandelbrot set is as complicated as a fractal can get. The length of the boundary of the Mandelbrot set is infinite - it can be any length you want, if you measure it with a small enough measuring stick.

Back to top

Connectedness

It's quite obvious that the outer bands around the Mandelbrot set form complete loops around the Mandelbrot set. The band representing two iterations for instance, travels smoothly around the outer edges and then connects back up to itself. There are no other points that have an iteration count of two except for on this band, and all the points on this band are connected by other points with an iteration count of two. This is less obvious but equally true for all other bands. If you zoom in to the band that represents ten iterations, you can drive all the way around the Mandelbrot set, following that band, and return to where you started. You could try it for the band representing one hundred, or one thousand iterations, but it would take a very long time.

This little idea, of all the bands being single bands going all the way around, doesn't seem too amazing when you look at the outside of the Mandelbrot set. But when you've zoomed in twenty times and are looking at a complex shape surrounded by spirals, it's quite amazing to think that each band you see somehow works it way around each of the individual nodes in the structure, into and out of all the arms in the spiral and then onwards around the Mandelbrot set, without ever crossing another band or ever quite disappearing.

The Mandelbrot set, the internal black area, itself is not excluded from this rule. Whenever you come across a miniature copy of the Mandelbrot set (and there are an infinite number of them scattered around), you can be sure that this tiny copy is connected to the main Mandelbrot set by one, and only one, infinitely thin filament that you will never see, but whose presence can be detected by seeing the constantly thinning bands of colour squeezing in on it from both sides.

Why Buy FX? | Download Area | How to Buy FX | The Gallery
Fractal Theory | Comments Area | Company Profile | Tips & Tricks
Main Page | Links | Send Mail
Copyright © 1997 Cygnus Software. All rights reserved.