Wednesday, 19 March 2014

Magazine Articles

A magazine has expressed an interest in doing a 3-part series covering the same themes as the book.

This is great and I hope will widen the audience - more people appreciating the magic of the Mandelbrot set and it's quite exciting mathematics can only be a good thing.

The challenge will be change from the book's 3 part structure (maths, code, more ideas) into a different form which introduces the coding right from the start. Understandably this is needed to ensure the articles remain relevant to the primairly computing audience.

Thursday, 13 March 2014

Book Cover

Working on the book cover and have settled on a broad design. Click on it to enlarge.

All done with free opensource software -  the graphic was created using our own code using IPython, the rest of the cover with the GIMP image editting software.

Tuesday, 11 March 2014

3D Complex Numbers - Why Not?

The Mandelbrot and Julia fractals are flat 2-dimensional objects, because the are derived from 2-dimensional complex numbers.

It's natural to want to extend the complex numbers to 3-dimensions, to form hypercomplex numbers, to see what kinds of Mandelbrot-like objects might emerge.

How would we do this? Is it possible? Impossible?

The eminent mathematician William Rowan Hamilton tried to do exactly this for quite some time, and failed. The reasons why this fails are not well explained in many guides to mathematics, so we'll have a go here. Myself I struggled to find a convincing but easy to understand explanation until I found the venerable Numbers which has a good explanation at the start of Chapter 7, even if the style is a little old school.
 A key thing to realise about mathematics is that you're free to invent any kind of universe of objects and the rules that govern how they interact. You can play mathematics god. However, if you want others to be interested in your creations they have to be useful, or actually interesting, in some way.

We know the complex numbers are remarkably useful across many fields of real world science, as well as pure mathematics. They're useful because they behave in ways that conform to many norms of familiar number systems. For example, complex numbers are commutative. That means it doesn't matter which order you multiply two complex numbers together. Just like normal numbers 3 x 2 is the same as 2 x 3, for complex numbers (2+3i) x (3+5i) is the same as (3+5i) x (2+3i) = (-9 + 19i). For some invented schemes, or algebras, the assumption of commutativity is not safe.

So we'll proceed in small steps, and remain cautious about which behaviours of normal number systems we want to preserve, or can prove remain true.

Let's start by extending the complex numbers from the 2-dimensional form (a+bi) to 3-dimensional by adding a new "axis" or basis. Let's call it j, but keeping in mind it's not the j used by the engineering community to mean the imaginary i. So we have hypercomplex numbers of the form (a+bi+cj). The parameters a, b and c are simple normal real numbers, not complex numbers. Writing (a+bi) is an easy way of talking about all possible complex numbers because we're committing to any particular a or b.

Let's make a small step forward and see if a very common mathematical operation works as we expect. Remember that with complex numbers addition works by adding the real and imaginary parts of the complex numbers independently. This works because the real and imaginary parts are independent. If they weren't then such simple addition wouldn't work. If you think of complex numbers as being composed of apples and oranges, instead of real and imaginary parts, you can see that you can collect all the apples into a new sum pile, and the same for oranges, but you can't mix the apples with the oranges. It should be straightforward to see that for our hypercomplex numbers, addition works the same, with the real, i and j parts being added independently. The usual behaviours of commutativity (A+B = B+A) and associativity (A+(B+C) = (A+B)+C) work as expected. Importantly, no inconsistencies or incompleteness appears to arise from our addition rules for these hypercomplex numbers.

Addition for our invented hypercomplex numbers isn't problematic. Now let's consider multiplication.

Let's try multiplying a general hypercomplex number by itself, that is, squaring it.

(a + bi + cj)2 = (a2 + abi + acj + abi + b2ii + bcij + acj + bcji + c2jj)
= (a2 - b2 - c2) + (2ab)i + (2ac)j + bcij + bcji

We assumed j2 = -1 just as i2 = -1. Why? Because we want the j basis to behave as the i basis and not have an unnerving asymmetry. We collected similar terms but we were cautious about the ij and ji terms, taking care not to equate them because we don't yet know if they are commutative. That is, we don't equate ij with ji to collect the last two terms.

Great! It seems we now need to find a reasoned way to see if ij and ji can be decomposed or simplified into a combination of basis terms, real, i and j. Why? Because we want multiplication of these hypercomplex numbers to result in new hypercomplex numbers that stay within the same space and not break out, needing new dimensions to describe them.

How can we do this? Well let's apply another constraint derived from another desirable quality. That quality is this - that hypercomplex numbers, when multiplied, results in a new one whose Euclidean magnitude is the same as the Euclidean magnitudes of the factors multiplied. That is, |AB| = |A||B| as the illustrated by the following diagram. Note: this isn't vector multiplication, its multuplying complex or hypercomplex numbers.

We didn't have to ask for this but we want to because it is a normal behavior we do want to see in our invented hypercomplex numbers. So lets apply this to a hypercomplex number multiplied by itself:

| (a + bi + cj)| = | (a + bi + cj) | | (a + bi + cj) | = a2 + b2 + c2

That last expression is simple because the Euclidean magnitude is the square root of each component squared and summed, and the square roots cancel out. But we have that other longer expression for the hypercomplex number multiplied by itself, so we can apply the sum of each component squared to that expression, where each independent components is the scale of the real, i and j parts. also, we don't like square roots so square everything to get rid of them to the algebra clearer:

(a2 + b2 + c2)2 = (a2 - b2 - c2)2 + (2ab)2 + (2ac)2 + ... and the bits with ij and ji.

For the above expression to work, the ji and ij bits need to cancel out to zero. This means ji = -ij. That is, we don't have commutativity, ij does not equal ji.

That's not a bad result! We've shown that by insisting on a natural feature, we must lose commutativity.

Hang on! What if we set ij = 0 and ji = 0 that would seem to work. Hamilton did consider this. But it seems a little too harsh to get rid of terms like that - we don't really have a good reason to make them zero. In fact you could argue that neither ij nor ji can be zero because the magnitudes |ij| must be |i|x|j| which is 1x1 = 1, not zero!

Instead, let's say ij = -ji = k. Now, k can't be a normal number otherwise it would be absorbed into the real part we already have. It must be equivalent but different to the existing bases ... k is a new basis, alongside i and j.

This is what led Hamilton to conclude that you needed a 4th basis for a well behaved algebra of hypercomplex numbers. Three doesn't work, as we have shown. He called these 4-dimensional hypercomplex numbers, quaternions, and they have proved immensely well behaved and useful.

Wow - what a long stretch. But it's the best and most accessible explanation I've found for why naive extensions of complex numbers to 3 dimensions don't work, but 4-dimensional quaternions do.

Monday, 10 March 2014

Delicate Image

We looked earlier at filters applied to the array of values holding the colour information for the Mandelbrot or Julia fractals.

Instead of smoothing the image, we instead use a filter which highlights edges, called a Sobel filter.

I love this image that that results from applying the Sobel filter to a Julia set. I love how it is delicate, detailed and yet has it's own inherent coherent structure. Click on it to show a fuller image.

Amazing that this essentially comes from a very simple iterated function z2+c.  And it's generated by the simple code we develop in the book.

I love it so much it's going to be the cover of the book!

Friday, 7 March 2014

Mathigon Fractals

This is a beautifully presented site about mathematics and it's section on fractals is really very accessible.

Great work and it all aids wider understanding and appreciation of the beauty of mathematics.

Smoother Landscapes

The previous post described using the colour information in a Mandelbrot or Julia image to represent height and so create a surface.

I found some of the plots to be a little spiky or noisy. Applying smoothing takes some of the edges off the height values and makes for a smoother more pleasing landscape. In IPython it is really easy to apply Gaussian smoothing for example. See the following before and after.

Before smoothing:
2-dimensional plot:
3-dimensional plot:

After smoothing:
2-dimensional plot:
3-dimensional plot:

Mandelbrot Mountains

I've previously posted that I'm trying to find an easy way to explain why a naive extension of 2-dimensional complex numbers to 3-dimensional ones isn't possible, and that the answer needs to be 4-dimensional quaternions.

Anyway the underlying aim was to have some kind of 3-dimensional version of the flat Mandelbrot and Julia sets. I'm still working on the quaternion issue but in the meantime, I've written up an easier approach to making 3-dimensional images which produces pleasing results.

The idea is simple - use the colour information in the calculated arrays to represent height or altitude. In this way we have all we need to define a surface or landscape. Remember that the normal calculations determine a value which is the number of iterations reached for each point in the area of interest. This value could be one of two things; (i) the number of iterations reached before the orbit escapes a threshold indicating divergence, or (ii) the maximum iterations we'll allow before we get bored and say the point is unlikely to diverge. For the normal plots this value determines the colour we use to plot the point. This results in a flat coloured area for inside the Mandelbrot set, and a graduation of colours outside. Now we use this value for the height at each point.

Doing this in IPython is very easy. Simply import the mayavi extensions and use a very simple plotting instruction. You can't currently use the pure web remote IPython services as these 3-dimensional surface plots need to use real 3-d hardware, so local installs of IPython are needed (opengl is used).

Here are some examples.