Archive for the ‘maths’ Category

Algorithm for Mandelbrot cardioid

Tuesday, July 28th, 2009

A good way to speed up a Mandelbrot set plotter is to eliminate the main cardioid and the largest circle. It turns out that there are simple equations for these, which can be found if you know that the cardioid consists of all the points which converge to a single point and the largest circle consists of all the points which converge to a cycle of period 2.

First the main cardioid. For each c, we can find the fixed point of iteration z_f such that z_f^2+c = z_f. There are two solutions, \displaystyle \frac{1}{2}(1 \pm \sqrt{1-4c}). Then we can look at what happens when we iterate a nearby point (z_f+d)^2+c = z_f^2+c + 2dz_f. If |2z_f| < 1 then the fixed point is stable. It turns out that this only happens for the \displaystyle \frac{1}{2}(1 - \sqrt{1-4c}) solution, so points in the cardioid are |1 - \sqrt{1-4c}| <= 1, with equality for the boundary.

Having to compute a complex square root is a bit ugly, though - can we do better? It turns out that we can. It's a fiddly calculation but if you multiply out all the square roots and simplify, you can get the formula |c|^2(8|c|^2-3) <= 3/32 - Re(c).

For the period-2 circle, we solve (z_f^2+c)^2+c = z_f and eliminate the period-1 solutions to get \displaystyle \frac{1}{2}(-1 \pm \sqrt{-3-4c}). In this case, both solutions are equally valid, since the cycle consists of both. Picking one and doing the same derivative analysis (this time applying two iterations) gives us the circle with center at -1 and radius 1/4.

Marginal cost of a vote

Thursday, October 16th, 2008

Suppose you are in charge of a large political campaign (like, say, the ones for Obama and McCain that are going on the moment here in the US). You have a certain amount of money to spend and want to spend that money in a way that will make as many people vote for your candidate as possible. As always with such things, there are bound to be more things that you can conceive of doing than there is available money, so you have to choose only the things that meet a certain "expected number of voters swung per dollar" threshold. I wonder what that threshold is? I.e. if you give $100 to a political campaign, how many extra votes does that buy?

This isn't the same as the total number of votes cast for a candidate divided by the total amount that campaign spent, because some of those voters would have voted for that candidate anyway without the campaign spending any money. I'm interested in the marginal cost of a vote.

I'm sure the figure varies from day to day (if the other candidate makes a big gaffe, you can probably exploit that to swing a lot of voters relatively cheaply) and from state to state (votes in swing states are more valuable than votes in safe states, so it's worth spending more to swing them). I expect it also varies depending on how much the other campaign spends (since it costs money to undo their work). I'm sure the political campaigns do calculations to figure this stuff out - it would be interesting to see their statistics.

Gödel's incompleteness theorem

Tuesday, October 14th, 2008

Gödel's incompleteness theorem is an interesting little piece of mathematics but probably gets talked about more than it really deserves to be. I'm going to add to the problem here by talking about it.

It's a pretty simple idea really - if you have a formal system of mathematics F sufficiently rich to do anything interesting, you can write down a statement G that says, essentially, "statement G cannot be proved in formal system F". G must be true since if it was false it would be provable and therefore true, which is a contradiction. So given any formal system you can either use it to prove a contradiction (in which case it can be used to be prove anything, and is therefore useless) or you can find a true statement that cannot be proved within the formal system. Mathematics (being a non-contradictory formal system) can therefore never be used to prove all the statements that are true. "But hang on a minute," I hear you say, "that proof that G is true looked an awful lot like mathematics to me." Really all this means is that the kind of things we think about as being mathematical proofs can't be enumerated into some nice tidy finite set, since whatever you put in that set you can use to find another element that needs to be added.

There is an analogy here with Cantor's diagonal proof that the real numbers form a greater class of infinity than the integers. While they're both interesting proofs there is a fundamental "infinite-ness" and "strange loop-iness" about both of them. Infinite things are strange and non-intuitive, and also useless for describing the real universe (since we can never measure anything with infinite precision).

Getting rid of the branch cut

Monday, September 15th, 2008

The video I made for Saturday's post made me wonder what the picture would look like if you didn't have a branch cut at all - if you make the logarithm function generate all of its multiple values (or equivalently, choose a sheet of the Riemann surface at random). Computers can't count up to infinity so the random method must be used. We can't make all the sheets equally likely as their number is unbounded so we need to pick some distribution. I chose a method that's rather simple to implement - I just roll a (virtual) dice until a 1 or a 6 comes up, and subtract the number of 2s and 3s from the number of 4s and 5s (a 1D random walk). That makes positive and negative numbers equally likely, but makes small (positive or negative) numbers more likely than large ones.

Here is the result:

Square roots

The infinite tower is transformed into a fractal fern-like structure. I was surprised at how different this looked from the second image on this post - while the non-principal branches are not visited very often, they cover a lot of space so make a lot of difference to the image.

Adjusting the branch cut

Saturday, September 13th, 2008

The second image in this post was quite popular, so I decided to make a movie out of it.

There aren't really many parameters in the equations used to make this image, though - (the functions are just negative, exponential and logarithm). The colouring is arbitrary but modifying it wouldn't make a very interesting movie. The zoom factor is fairly arbitrary as well but zooming very much in or out would make the image take much longer to render (besides which, zooming movies have been done to death). About the only other arbitrary thing about the image is the choice of branch cut for the logarithm.

This describes a way of adjusting the branch cut in a continuous way, and this is the movie I made by adjusting theta from -4.5 to +4.5 radians:

High quality 640x480 11Mb DivX avi version.

This took about three days to render. I could have done it faster, but my laptop gets uncomfortably warm when both its cores are fully utilized. Also, a problem with Vista networking was causing the other machine I was using to keep getting disconnected from my laptop every few frames.

Triangular lattices

Monday, September 8th, 2008

A commenter wondered what the images on Saturday's post would look like using a sixth root of unity instead of a fourth. I am happy to oblige. With ω=eπi/3, this is the image with the operations z+ω, ωz, ωz:

w^z

And this is the image with the operations z+ω, ωz, zω:

z^w

Powers involving i

Saturday, September 6th, 2008

More variations:

Red: z->z+i
Green: z->iz
Blue: z->iz:

i^z

Same, but with blue: z->zi:

z^i

Reslicing

Friday, September 5th, 2008

A movie can be thought of as a three-dimensional array of pixels - horizontal, vertical and time. If you have such a three-dimensional array of pixels, there are three different ways of turning it into a movie - three different dimensions that you can pick as "time". For movies of real things this probably isn't a very interesting thing to do, but for movies of mathematical objects like the one I made yesterday, there may be mathematical insights to be gained from "reslicing" a movie.

So, here is yesterday's movie with the x and time coordinates swapped:

Higher resolution version (8Mb 640x480 DivX).

And here it is with the y and time coordinates swapped (and also rotated to landscape format):

Higher resolution version (8Mb 640x480 DivX).

I made a movie

Thursday, September 4th, 2008

Higher quality 10Mb 640x480 DivX version here.

This is a generalization of the second picture from yesterday's post, varying the coefficient of i from e-4.5 to e4.5. It also demonstrates how this picture is related to the third picture from Monday's post.

1.35 trillion points were calculated to make this movie, taking 4 CPUs with 6 cores most of a day (it was going to take nearly 4 days, but I decided to use most of the other computers in the house as a render farm).

Two more

Wednesday, September 3rd, 2008

Square roots

Generated by a program similar to the last two pictures on Monday's post, but the functions are +\sqrt{z}, -\sqrt{z} and 1+z. Don't plot a point if the last operation was 1+z, and colour points according to the operation used 5 iterations ago.

Golden ratio

Similar to the third image on Monday's post, but when we multiply by \i we also multiply by the golden ratio \displaystyle \frac{1}{2}(1+\sqrt{5}) = 1.618... Most the rectangles you see in this image are golden rectangles, which are supposedly the most aesthetically pleasing.