Wednesday, 19 February 2014

Creating an Ebook

I tried creating an ebook with the content that I have right now, which is about 95% done.

The whole thing is rather unsatisfactory.

The source content, created in Google docs, is exported as a zipped folder of html and images. This works fine in a browser, designed to view html. But transforming this to the epub format, the most common for ebooks, is not great. The transformation tool, Sigil, does it's best to guess what the author had in mind for formatting. Keeping in mind that epub like other ebook formats is primarily about formatting, but about reflowable content. Even so images come out at odd sizes, typefaces are different, text column margins are odd. Then you have to use Calibre to try to optimise for particular devices or services. Why? Surely a conformant epub is an epub is an epub that should work anywhere?

The root problem is that there are no good open source tools for authoring ebooks with an interface that is for normal people who don't want to know about html and css.

Right now my first attempt at loading the epub onto my Android phone is only a partial success. The book is there, I can navigate through the content, the table of contents works (with the wrong typeface), and the cover is there, albeit a huge bitmap (inefficient). But the formatting needs a lot of refinement.

Saturday, 8 February 2014

From Trivial to Noise via Fractals

Fractals are really interesting objects. They’re interesting because they bust the myth that mathematics and its objects are always boring, predictable, and certainly not beautiful or intricate. Certainly not like objects we see in nature; clouds, mountains, flowers, water streams, snowflakes.

Let’s look some of these so-called boring, predictable, flat objects. A square, a circle, and even a 3-dimensional cube or cylinder.

These objects are certainly simple compared to what we see in nature and find intricate or beautiful. Actually some people do find these objects really fascinating, but I suspect most people wouldn’t want to stare at these objects for a long time, exploring their nooks and crannies. This last bit is important - these objects don’t have nooks and crannies, they don’t reveal new details for us to explore the longer we look at them. If we looked at them with a magnifying glass we wouldn’t find anything new or surprising. In that sense, we can call them boring.

Now lets look at something totally unordered, noisy, following no rule or regulation, other than being totally random.

The picture is of the familiar white noise we used to see on old television sets when they weren’t tuned quite right to a broadcasting channel. It’s not that interesting either. Actually we humans have a tendency to try to project recognisable things onto noise, which is why we love finding faces and dragons in the clouds! If we set that human tendency aside, we’d find purely random objects boring.

Now look at the following objects; a snowflake, some clouds, river systems and a piece of cauliflower.


There is something about these objects that leads us to explore them a little longer. It’s not just that they are very detailed, but that there is some semi-regularity about them. There appears to be a theme that pervades them, a repeated pattern, but repeated not in that boring easily predictable way, but in a way that is somewhere between the two extremes of boring regularity, and total messy randomness. This is an important idea. The idea that objects that appeal to our human senses and minds are somewhere between total boring regularity and total randomness.

We’ll be coming back to this idea later, carefully treading a path between regularity and randomness where mathematics produces some really intricate beautiful objects.

If we zoomed into a bit of the above images with a microscope or a telescope, it would be difficult to guess at what scale we were looking at the object. Each little floret of the cauliflower looks like a collection of smaller ones, and you can’t guess whether the bit you’re looking at is 5 centimetres wide or 5 millimetres. Each bit of cloud fluff looks like a collections of smaller clouds fluffs - is it a metre wide or a kilometre? Each river network looks like it could have been taken from a height of 10 metres or equally at 1000 metres. This is called self-similarity at different scales.

The following objects are less organic and natural than clouds and plants, but they do have that self-similarity we talked about above. Their construction is much more regular. We include them here because when people talk about fractals they often think of these objects too. Personally I think they’re interesting to look at but the interest wears off quickly because they’re closer to the “regular” world than the more organically less predictable natural objects.

The first one is a Koch snowflake, and the second is a Sierpinski gasket. You can easily find out how to make them, but the basic idea is to take a simple regular shape such as a hexagon or triangle, and repeatedly add smaller versions of this shape at ever greater levels of detail.

The following summarises this spectrum of objects, from totally random to totally ordered, with the interesting objects between the two. It’s as if the tension, the constant battle, between total order and total randomness, produces the most natural organic intricate beautiful objects.

Sunday, 2 February 2014

Stopping at 4?

The Mandelbrot algorthm iterates z2+c many times and stops if either of the following two conditions are true:

  1. We've done lots of iterations and we can't keep going forever. We stop when we reach the maximum upper limit for iterations we've set outselves. 
  2. When the magnitude of the value popping out of the z2+c is greater than 4.
 The first conditions is understandable. What's the reason for the second?

Let's look at what the 4 means. The following diagram shows the regions marked out by this 4. The green circle contains all the points on the complex plane which have magnitude less than 4. Remember that magnitude is just the distance from the origin at (0+0i) to the point where the complex number is sat. The red area represents all the points with magnitude greater than 4.

We've also shown in grey a rough image of the Mandelbrot set. We've cheated and put it where we know others have calculated it to be. The usual box it sits inside has a bottom left at (-2.25-1.5i) and a top right of (0.75+1.5i).

We can see that the grey Mandelbrot set is entirely within the green zone. That means if the values popping out of the repeatedly iterative z2+c function ever stray outside the green zone we know they'll always diverge. Its just the same as if the starting point was outside the green zone - remember that the first value taken by z2+c is c itself, the point being tested.

So wht they value 4 and not 3 or 300? Well we need to balance two competing factors. One one hand we want to be really sure the points do diverge. If we wait until the values popping out of reach a distance of 300 we can be really sure they won't not diverge. But we don't want to waste time doing unnecessary calculations, and on slower computers this can really hurt how quickly we can draw the Mandelbrot set. It used to take hours back in the early 90s!

On the other hand if we choose to bail out when the magnitude is much smaller at 1.5 then, sure, we will have reduced unnecessary calculations but actually we can't be sure any value straying larger than magnitude 1.5 won't in fact ultimately not diverge. In fact we know that there are points outside the circle of radius 1.5 that are part of the Mandelbrot set.

So setting the threshold to 4 is a good balance between not doing too many unnecessary calculations and having high certainty about points which do ultimately diverge.

Saturday, 1 February 2014

Mandelbrot by Hand

Here's an easy to understand guide to calculating and plotting the Mandelbrot set by hand.

It's a laborious process but if you're really struggling to understand what's going on with all the mathematics underlying the set, doing it by hand is an excellent way to get a feel for it.

It reminds me of learning to program by typing in listings back in the 90s. Although not ideal, sometimes when you're struggling just applying practical action can help breakthroughs in understanding.